Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** ----------------------------------------------------------------------------- |
| 3 | ** |
| 4 | ** Perle Specialix driver for Linux |
| 5 | ** Ported from existing RIO Driver for SCO sources. |
| 6 | * |
| 7 | * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | ** |
| 23 | ** Module : riointr.c |
| 24 | ** SID : 1.2 |
| 25 | ** Last Modified : 11/6/98 10:33:44 |
| 26 | ** Retrieved : 11/6/98 10:33:49 |
| 27 | ** |
| 28 | ** ident @(#)riointr.c 1.2 |
| 29 | ** |
| 30 | ** ----------------------------------------------------------------------------- |
| 31 | */ |
| 32 | #ifdef SCCS_LABELS |
| 33 | static char *_riointr_c_sccs_ = "@(#)riointr.c 1.2"; |
| 34 | #endif |
| 35 | |
| 36 | |
| 37 | #include <linux/module.h> |
| 38 | #include <linux/slab.h> |
| 39 | #include <linux/errno.h> |
| 40 | #include <linux/tty.h> |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 41 | #include <linux/tty_flip.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <asm/io.h> |
| 43 | #include <asm/system.h> |
| 44 | #include <asm/string.h> |
| 45 | #include <asm/semaphore.h> |
| 46 | #include <asm/uaccess.h> |
| 47 | |
| 48 | #include <linux/termios.h> |
| 49 | #include <linux/serial.h> |
| 50 | |
| 51 | #include <linux/generic_serial.h> |
| 52 | |
| 53 | #include <linux/delay.h> |
| 54 | |
| 55 | #include "linux_compat.h" |
| 56 | #include "rio_linux.h" |
| 57 | #include "typdef.h" |
| 58 | #include "pkt.h" |
| 59 | #include "daemon.h" |
| 60 | #include "rio.h" |
| 61 | #include "riospace.h" |
| 62 | #include "top.h" |
| 63 | #include "cmdpkt.h" |
| 64 | #include "map.h" |
| 65 | #include "riotypes.h" |
| 66 | #include "rup.h" |
| 67 | #include "port.h" |
| 68 | #include "riodrvr.h" |
| 69 | #include "rioinfo.h" |
| 70 | #include "func.h" |
| 71 | #include "errors.h" |
| 72 | #include "pci.h" |
| 73 | |
| 74 | #include "parmmap.h" |
| 75 | #include "unixrup.h" |
| 76 | #include "board.h" |
| 77 | #include "host.h" |
| 78 | #include "error.h" |
| 79 | #include "phb.h" |
| 80 | #include "link.h" |
| 81 | #include "cmdblk.h" |
| 82 | #include "route.h" |
| 83 | #include "control.h" |
| 84 | #include "cirrus.h" |
| 85 | #include "rioioctl.h" |
| 86 | |
| 87 | |
| 88 | static void RIOReceive(struct rio_info *, struct Port *); |
| 89 | |
| 90 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 91 | static char *firstchars(char *p, int nch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 93 | static char buf[2][128]; |
| 94 | static int t = 0; |
| 95 | t = !t; |
| 96 | memcpy(buf[t], p, nch); |
| 97 | buf[t][nch] = 0; |
| 98 | return buf[t]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | |
| 102 | #define INCR( P, I ) ((P) = (((P)+(I)) & p->RIOBufferMask)) |
| 103 | /* Enable and start the transmission of packets */ |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 104 | void RIOTxEnable(char *en) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 106 | struct Port *PortP; |
| 107 | struct rio_info *p; |
| 108 | struct tty_struct *tty; |
| 109 | int c; |
| 110 | struct PKT *PacketP; |
| 111 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 113 | PortP = (struct Port *) en; |
| 114 | p = (struct rio_info *) PortP->p; |
| 115 | tty = PortP->gs.tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
| 117 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 118 | rio_dprintk(RIO_DEBUG_INTR, "tx port %d: %d chars queued.\n", PortP->PortNum, PortP->gs.xmit_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 120 | if (!PortP->gs.xmit_cnt) |
| 121 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 124 | /* This routine is an order of magnitude simpler than the specialix |
| 125 | version. One of the disadvantages is that this version will send |
| 126 | an incomplete packet (usually 64 bytes instead of 72) once for |
| 127 | every 4k worth of data. Let's just say that this won't influence |
| 128 | performance significantly..... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 130 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 132 | while (can_add_transmit(&PacketP, PortP)) { |
| 133 | c = PortP->gs.xmit_cnt; |
| 134 | if (c > PKT_MAX_DATA_LEN) |
| 135 | c = PKT_MAX_DATA_LEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 137 | /* Don't copy past the end of the source buffer */ |
| 138 | if (c > SERIAL_XMIT_SIZE - PortP->gs.xmit_tail) |
| 139 | c = SERIAL_XMIT_SIZE - PortP->gs.xmit_tail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 141 | { |
| 142 | int t; |
| 143 | t = (c > 10) ? 10 : c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 145 | rio_dprintk(RIO_DEBUG_INTR, "rio: tx port %d: copying %d chars: %s - %s\n", PortP->PortNum, c, firstchars(PortP->gs.xmit_buf + PortP->gs.xmit_tail, t), firstchars(PortP->gs.xmit_buf + PortP->gs.xmit_tail + c - t, t)); |
| 146 | } |
| 147 | /* If for one reason or another, we can't copy more data, |
| 148 | we're done! */ |
| 149 | if (c == 0) |
| 150 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 152 | rio_memcpy_toio(PortP->HostP->Caddr, (caddr_t) PacketP->data, PortP->gs.xmit_buf + PortP->gs.xmit_tail, c); |
| 153 | /* udelay (1); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 155 | writeb(c, &(PacketP->len)); |
| 156 | if (!(PortP->State & RIO_DELETED)) { |
| 157 | add_transmit(PortP); |
| 158 | /* |
| 159 | ** Count chars tx'd for port statistics reporting |
| 160 | */ |
| 161 | if (PortP->statsGather) |
| 162 | PortP->txchars += c; |
| 163 | } |
| 164 | PortP->gs.xmit_tail = (PortP->gs.xmit_tail + c) & (SERIAL_XMIT_SIZE - 1); |
| 165 | PortP->gs.xmit_cnt -= c; |
| 166 | } |
| 167 | |
| 168 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 169 | |
| 170 | if (PortP->gs.xmit_cnt <= (PortP->gs.wakeup_chars + 2 * PKT_MAX_DATA_LEN)) { |
| 171 | rio_dprintk(RIO_DEBUG_INTR, "Waking up.... ldisc:%d (%d/%d)....", (int) (PortP->gs.tty->flags & (1 << TTY_DO_WRITE_WAKEUP)), PortP->gs.wakeup_chars, PortP->gs.xmit_cnt); |
| 172 | if ((PortP->gs.tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && PortP->gs.tty->ldisc.write_wakeup) |
| 173 | (PortP->gs.tty->ldisc.write_wakeup) (PortP->gs.tty); |
| 174 | rio_dprintk(RIO_DEBUG_INTR, "(%d/%d)\n", PortP->gs.wakeup_chars, PortP->gs.xmit_cnt); |
| 175 | wake_up_interruptible(&PortP->gs.tty->write_wait); |
| 176 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
| 178 | } |
| 179 | |
| 180 | |
| 181 | /* |
| 182 | ** RIO Host Service routine. Does all the work traditionally associated with an |
| 183 | ** interrupt. |
| 184 | */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 185 | static int RupIntr; |
| 186 | static int RxIntr; |
| 187 | static int TxIntr; |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 188 | |
| 189 | void RIOServiceHost(struct rio_info *p, struct Host *HostP, int From) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 191 | rio_spin_lock(&HostP->HostLock); |
| 192 | if ((HostP->Flags & RUN_STATE) != RC_RUNNING) { |
| 193 | static int t = 0; |
| 194 | rio_spin_unlock(&HostP->HostLock); |
| 195 | if ((t++ % 200) == 0) |
| 196 | rio_dprintk(RIO_DEBUG_INTR, "Interrupt but host not running. flags=%x.\n", (int) HostP->Flags); |
| 197 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 199 | rio_spin_unlock(&HostP->HostLock); |
| 200 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 201 | if (readw(&HostP->ParmMapP->rup_intr)) { |
| 202 | writew(0, &HostP->ParmMapP->rup_intr); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 203 | p->RIORupCount++; |
| 204 | RupIntr++; |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 205 | rio_dprintk(RIO_DEBUG_INTR, "rio: RUP interrupt on host %Zd\n", HostP - p->RIOHosts); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 206 | RIOPollHostCommands(p, HostP); |
| 207 | } |
| 208 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 209 | if (readw(&HostP->ParmMapP->rx_intr)) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 210 | int port; |
| 211 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 212 | writew(0, &HostP->ParmMapP->rx_intr); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 213 | p->RIORxCount++; |
| 214 | RxIntr++; |
| 215 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 216 | rio_dprintk(RIO_DEBUG_INTR, "rio: RX interrupt on host %Zd\n", HostP - p->RIOHosts); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 217 | /* |
| 218 | ** Loop through every port. If the port is mapped into |
| 219 | ** the system ( i.e. has /dev/ttyXXXX associated ) then it is |
| 220 | ** worth checking. If the port isn't open, grab any packets |
| 221 | ** hanging on its receive queue and stuff them on the free |
| 222 | ** list; check for commands on the way. |
| 223 | */ |
| 224 | for (port = p->RIOFirstPortsBooted; port < p->RIOLastPortsBooted + PORTS_PER_RTA; port++) { |
| 225 | struct Port *PortP = p->RIOPortp[port]; |
| 226 | struct tty_struct *ttyP; |
| 227 | struct PKT *PacketP; |
| 228 | |
| 229 | /* |
| 230 | ** not mapped in - most of the RIOPortp[] information |
| 231 | ** has not been set up! |
| 232 | ** Optimise: ports come in bundles of eight. |
| 233 | */ |
| 234 | if (!PortP->Mapped) { |
| 235 | port += 7; |
| 236 | continue; /* with the next port */ |
| 237 | } |
| 238 | |
| 239 | /* |
| 240 | ** If the host board isn't THIS host board, check the next one. |
| 241 | ** optimise: ports come in bundles of eight. |
| 242 | */ |
| 243 | if (PortP->HostP != HostP) { |
| 244 | port += 7; |
| 245 | continue; |
| 246 | } |
| 247 | |
| 248 | /* |
| 249 | ** Let us see - is the port open? If not, then don't service it. |
| 250 | */ |
| 251 | if (!(PortP->PortState & PORT_ISOPEN)) { |
| 252 | continue; |
| 253 | } |
| 254 | |
| 255 | /* |
| 256 | ** find corresponding tty structure. The process of mapping |
| 257 | ** the ports puts these here. |
| 258 | */ |
| 259 | ttyP = PortP->gs.tty; |
| 260 | |
| 261 | /* |
| 262 | ** Lock the port before we begin working on it. |
| 263 | */ |
| 264 | rio_spin_lock(&PortP->portSem); |
| 265 | |
| 266 | /* |
| 267 | ** Process received data if there is any. |
| 268 | */ |
| 269 | if (can_remove_receive(&PacketP, PortP)) |
| 270 | RIOReceive(p, PortP); |
| 271 | |
| 272 | /* |
| 273 | ** If there is no data left to be read from the port, and |
| 274 | ** it's handshake bit is set, then we must clear the handshake, |
| 275 | ** so that that downstream RTA is re-enabled. |
| 276 | */ |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 277 | if (!can_remove_receive(&PacketP, PortP) && (readw(&PortP->PhbP->handshake) == PHB_HANDSHAKE_SET)) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 278 | /* |
| 279 | ** MAGIC! ( Basically, handshake the RX buffer, so that |
| 280 | ** the RTAs upstream can be re-enabled. ) |
| 281 | */ |
| 282 | rio_dprintk(RIO_DEBUG_INTR, "Set RX handshake bit\n"); |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 283 | writew(PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET, &PortP->PhbP->handshake); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 284 | } |
| 285 | rio_spin_unlock(&PortP->portSem); |
| 286 | } |
| 287 | } |
| 288 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 289 | if (readw(&HostP->ParmMapP->tx_intr)) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 290 | int port; |
| 291 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 292 | writew(0, &HostP->ParmMapP->tx_intr); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 293 | |
| 294 | p->RIOTxCount++; |
| 295 | TxIntr++; |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 296 | rio_dprintk(RIO_DEBUG_INTR, "rio: TX interrupt on host %Zd\n", HostP - p->RIOHosts); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 297 | |
| 298 | /* |
| 299 | ** Loop through every port. |
| 300 | ** If the port is mapped into the system ( i.e. has /dev/ttyXXXX |
| 301 | ** associated ) then it is worth checking. |
| 302 | */ |
| 303 | for (port = p->RIOFirstPortsBooted; port < p->RIOLastPortsBooted + PORTS_PER_RTA; port++) { |
| 304 | struct Port *PortP = p->RIOPortp[port]; |
| 305 | struct tty_struct *ttyP; |
| 306 | struct PKT *PacketP; |
| 307 | |
| 308 | /* |
| 309 | ** not mapped in - most of the RIOPortp[] information |
| 310 | ** has not been set up! |
| 311 | */ |
| 312 | if (!PortP->Mapped) { |
| 313 | port += 7; |
| 314 | continue; /* with the next port */ |
| 315 | } |
| 316 | |
| 317 | /* |
| 318 | ** If the host board isn't running, then its data structures |
| 319 | ** are no use to us - continue quietly. |
| 320 | */ |
| 321 | if (PortP->HostP != HostP) { |
| 322 | port += 7; |
| 323 | continue; /* with the next port */ |
| 324 | } |
| 325 | |
| 326 | /* |
| 327 | ** Let us see - is the port open? If not, then don't service it. |
| 328 | */ |
| 329 | if (!(PortP->PortState & PORT_ISOPEN)) { |
| 330 | continue; |
| 331 | } |
| 332 | |
| 333 | rio_dprintk(RIO_DEBUG_INTR, "rio: Looking into port %d.\n", port); |
| 334 | /* |
| 335 | ** Lock the port before we begin working on it. |
| 336 | */ |
| 337 | rio_spin_lock(&PortP->portSem); |
| 338 | |
| 339 | /* |
| 340 | ** If we can't add anything to the transmit queue, then |
| 341 | ** we need do none of this processing. |
| 342 | */ |
| 343 | if (!can_add_transmit(&PacketP, PortP)) { |
| 344 | rio_dprintk(RIO_DEBUG_INTR, "Can't add to port, so skipping.\n"); |
| 345 | rio_spin_unlock(&PortP->portSem); |
| 346 | continue; |
| 347 | } |
| 348 | |
| 349 | /* |
| 350 | ** find corresponding tty structure. The process of mapping |
| 351 | ** the ports puts these here. |
| 352 | */ |
| 353 | ttyP = PortP->gs.tty; |
| 354 | /* If ttyP is NULL, the port is getting closed. Forget about it. */ |
| 355 | if (!ttyP) { |
| 356 | rio_dprintk(RIO_DEBUG_INTR, "no tty, so skipping.\n"); |
| 357 | rio_spin_unlock(&PortP->portSem); |
| 358 | continue; |
| 359 | } |
| 360 | /* |
| 361 | ** If there is more room available we start up the transmit |
| 362 | ** data process again. This can be direct I/O, if the cookmode |
| 363 | ** is set to COOK_RAW or COOK_MEDIUM, or will be a call to the |
| 364 | ** riotproc( T_OUTPUT ) if we are in COOK_WELL mode, to fetch |
| 365 | ** characters via the line discipline. We must always call |
| 366 | ** the line discipline, |
| 367 | ** so that user input characters can be echoed correctly. |
| 368 | ** |
| 369 | ** ++++ Update +++++ |
| 370 | ** With the advent of double buffering, we now see if |
| 371 | ** TxBufferOut-In is non-zero. If so, then we copy a packet |
| 372 | ** to the output place, and set it going. If this empties |
| 373 | ** the buffer, then we must issue a wakeup( ) on OUT. |
| 374 | ** If it frees space in the buffer then we must issue |
| 375 | ** a wakeup( ) on IN. |
| 376 | ** |
| 377 | ** ++++ Extra! Extra! If PortP->WflushFlag is set, then we |
| 378 | ** have to send a WFLUSH command down the PHB, to mark the |
| 379 | ** end point of a WFLUSH. We also need to clear out any |
| 380 | ** data from the double buffer! ( note that WflushFlag is a |
| 381 | ** *count* of the number of WFLUSH commands outstanding! ) |
| 382 | ** |
| 383 | ** ++++ And there's more! |
| 384 | ** If an RTA is powered off, then on again, and rebooted, |
| 385 | ** whilst it has ports open, then we need to re-open the ports. |
| 386 | ** ( reasonable enough ). We can't do this when we spot the |
| 387 | ** re-boot, in interrupt time, because the queue is probably |
| 388 | ** full. So, when we come in here, we need to test if any |
| 389 | ** ports are in this condition, and re-open the port before |
| 390 | ** we try to send any more data to it. Now, the re-booted |
| 391 | ** RTA will be discarding packets from the PHB until it |
| 392 | ** receives this open packet, but don't worry tooo much |
| 393 | ** about that. The one thing that is interesting is the |
| 394 | ** combination of this effect and the WFLUSH effect! |
| 395 | */ |
| 396 | /* For now don't handle RTA reboots. -- REW. |
| 397 | Reenabled. Otherwise RTA reboots didn't work. Duh. -- REW */ |
| 398 | if (PortP->MagicFlags) { |
| 399 | #if 1 |
| 400 | if (PortP->MagicFlags & MAGIC_REBOOT) { |
| 401 | /* |
| 402 | ** well, the RTA has been rebooted, and there is room |
| 403 | ** on its queue to add the open packet that is required. |
| 404 | ** |
| 405 | ** The messy part of this line is trying to decide if |
| 406 | ** we need to call the Param function as a tty or as |
| 407 | ** a modem. |
| 408 | ** DONT USE CLOCAL AS A TEST FOR THIS! |
| 409 | ** |
| 410 | ** If we can't param the port, then move on to the |
| 411 | ** next port. |
| 412 | */ |
| 413 | PortP->InUse = NOT_INUSE; |
| 414 | |
| 415 | rio_spin_unlock(&PortP->portSem); |
| 416 | if (RIOParam(PortP, OPEN, ((PortP->Cor2Copy & (COR2_RTSFLOW | COR2_CTSFLOW)) == (COR2_RTSFLOW | COR2_CTSFLOW)) ? TRUE : FALSE, DONT_SLEEP) == RIO_FAIL) { |
| 417 | continue; /* with next port */ |
| 418 | } |
| 419 | rio_spin_lock(&PortP->portSem); |
| 420 | PortP->MagicFlags &= ~MAGIC_REBOOT; |
| 421 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | #endif |
| 423 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 424 | /* |
| 425 | ** As mentioned above, this is a tacky hack to cope |
| 426 | ** with WFLUSH |
| 427 | */ |
| 428 | if (PortP->WflushFlag) { |
| 429 | rio_dprintk(RIO_DEBUG_INTR, "Want to WFLUSH mark this port\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 431 | if (PortP->InUse) |
| 432 | rio_dprintk(RIO_DEBUG_INTR, "FAILS - PORT IS IN USE\n"); |
| 433 | } |
| 434 | |
| 435 | while (PortP->WflushFlag && can_add_transmit(&PacketP, PortP) && (PortP->InUse == NOT_INUSE)) { |
| 436 | int p; |
| 437 | struct PktCmd *PktCmdP; |
| 438 | |
| 439 | rio_dprintk(RIO_DEBUG_INTR, "Add WFLUSH marker to data queue\n"); |
| 440 | /* |
| 441 | ** make it look just like a WFLUSH command |
| 442 | */ |
| 443 | PktCmdP = (struct PktCmd *) &PacketP->data[0]; |
| 444 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 445 | writeb(WFLUSH, &PktCmdP->Command); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 446 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 447 | p = PortP->HostPort % (u16) PORTS_PER_RTA; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 448 | |
| 449 | /* |
| 450 | ** If second block of ports for 16 port RTA, add 8 |
| 451 | ** to index 8-15. |
| 452 | */ |
| 453 | if (PortP->SecondBlock) |
| 454 | p += PORTS_PER_RTA; |
| 455 | |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 456 | writeb(p, &PktCmdP->PhbNum); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 457 | |
| 458 | /* |
| 459 | ** to make debuggery easier |
| 460 | */ |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 461 | writeb('W', &PacketP->data[2]); |
| 462 | writeb('F', &PacketP->data[3]); |
| 463 | writeb('L', &PacketP->data[4]); |
| 464 | writeb('U', &PacketP->data[5]); |
| 465 | writeb('S', &PacketP->data[6]); |
| 466 | writeb('H', &PacketP->data[7]); |
| 467 | writeb(' ', &PacketP->data[8]); |
| 468 | writeb('0' + PortP->WflushFlag, &PacketP->data[9]); |
| 469 | writeb(' ', &PacketP->data[10]); |
| 470 | writeb(' ', &PacketP->data[11]); |
| 471 | writeb('\0', &PacketP->data[12]); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 472 | |
| 473 | /* |
| 474 | ** its two bytes long! |
| 475 | */ |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 476 | writeb(PKT_CMD_BIT | 2, &PacketP->len); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 477 | |
| 478 | /* |
| 479 | ** queue it! |
| 480 | */ |
| 481 | if (!(PortP->State & RIO_DELETED)) { |
| 482 | add_transmit(PortP); |
| 483 | /* |
| 484 | ** Count chars tx'd for port statistics reporting |
| 485 | */ |
| 486 | if (PortP->statsGather) |
| 487 | PortP->txchars += 2; |
| 488 | } |
| 489 | |
| 490 | if (--(PortP->WflushFlag) == 0) { |
| 491 | PortP->MagicFlags &= ~MAGIC_FLUSH; |
| 492 | } |
| 493 | |
| 494 | rio_dprintk(RIO_DEBUG_INTR, "Wflush count now stands at %d\n", PortP->WflushFlag); |
| 495 | } |
| 496 | if (PortP->MagicFlags & MORE_OUTPUT_EYGOR) { |
| 497 | if (PortP->MagicFlags & MAGIC_FLUSH) { |
| 498 | PortP->MagicFlags |= MORE_OUTPUT_EYGOR; |
| 499 | } else { |
| 500 | if (!can_add_transmit(&PacketP, PortP)) { |
| 501 | rio_spin_unlock(&PortP->portSem); |
| 502 | continue; |
| 503 | } |
| 504 | rio_spin_unlock(&PortP->portSem); |
| 505 | RIOTxEnable((char *) PortP); |
| 506 | rio_spin_lock(&PortP->portSem); |
| 507 | PortP->MagicFlags &= ~MORE_OUTPUT_EYGOR; |
| 508 | } |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | |
| 513 | /* |
| 514 | ** If we can't add anything to the transmit queue, then |
| 515 | ** we need do none of the remaining processing. |
| 516 | */ |
| 517 | if (!can_add_transmit(&PacketP, PortP)) { |
| 518 | rio_spin_unlock(&PortP->portSem); |
| 519 | continue; |
| 520 | } |
| 521 | |
| 522 | rio_spin_unlock(&PortP->portSem); |
| 523 | RIOTxEnable((char *) PortP); |
| 524 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | /* |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 529 | ** Routine for handling received data for tty drivers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | */ |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 531 | static void RIOReceive(struct rio_info *p, struct Port *PortP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 533 | struct tty_struct *TtyP; |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 534 | unsigned short transCount; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 535 | struct PKT *PacketP; |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 536 | register unsigned int DataCnt; |
| 537 | unsigned char *ptr; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 538 | unsigned char *buf; |
| 539 | int copied = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 541 | static int intCount, RxIntCnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 543 | /* |
| 544 | ** The receive data process is to remove packets from the |
| 545 | ** PHB until there aren't any more or the current cblock |
| 546 | ** is full. When this occurs, there will be some left over |
| 547 | ** data in the packet, that we must do something with. |
| 548 | ** As we haven't unhooked the packet from the read list |
| 549 | ** yet, we can just leave the packet there, having first |
| 550 | ** made a note of how far we got. This means that we need |
| 551 | ** a pointer per port saying where we start taking the |
| 552 | ** data from - this will normally be zero, but when we |
| 553 | ** run out of space it will be set to the offset of the |
| 554 | ** next byte to copy from the packet data area. The packet |
| 555 | ** length field is decremented by the number of bytes that |
| 556 | ** we succesfully removed from the packet. When this reaches |
| 557 | ** zero, we reset the offset pointer to be zero, and free |
| 558 | ** the packet from the front of the queue. |
| 559 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 561 | intCount++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 563 | TtyP = PortP->gs.tty; |
| 564 | if (!TtyP) { |
| 565 | rio_dprintk(RIO_DEBUG_INTR, "RIOReceive: tty is null. \n"); |
| 566 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 568 | |
| 569 | if (PortP->State & RIO_THROTTLE_RX) { |
| 570 | rio_dprintk(RIO_DEBUG_INTR, "RIOReceive: Throttled. Can't handle more input.\n"); |
| 571 | return; |
| 572 | } |
| 573 | |
| 574 | if (PortP->State & RIO_DELETED) { |
| 575 | while (can_remove_receive(&PacketP, PortP)) { |
| 576 | remove_receive(PortP); |
| 577 | put_free_end(PortP->HostP, PacketP); |
| 578 | } |
| 579 | } else { |
| 580 | /* |
| 581 | ** loop, just so long as: |
| 582 | ** i ) there's some data ( i.e. can_remove_receive ) |
| 583 | ** ii ) we haven't been blocked |
| 584 | ** iii ) there's somewhere to put the data |
| 585 | ** iv ) we haven't outstayed our welcome |
| 586 | */ |
| 587 | transCount = 1; |
| 588 | while (can_remove_receive(&PacketP, PortP) |
| 589 | && transCount) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 590 | RxIntCnt++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 592 | /* |
| 593 | ** check that it is not a command! |
| 594 | */ |
| 595 | if (PacketP->len & PKT_CMD_BIT) { |
| 596 | rio_dprintk(RIO_DEBUG_INTR, "RIO: unexpected command packet received on PHB\n"); |
| 597 | /* rio_dprint(RIO_DEBUG_INTR, (" sysport = %d\n", p->RIOPortp->PortNum)); */ |
| 598 | rio_dprintk(RIO_DEBUG_INTR, " dest_unit = %d\n", PacketP->dest_unit); |
| 599 | rio_dprintk(RIO_DEBUG_INTR, " dest_port = %d\n", PacketP->dest_port); |
| 600 | rio_dprintk(RIO_DEBUG_INTR, " src_unit = %d\n", PacketP->src_unit); |
| 601 | rio_dprintk(RIO_DEBUG_INTR, " src_port = %d\n", PacketP->src_port); |
| 602 | rio_dprintk(RIO_DEBUG_INTR, " len = %d\n", PacketP->len); |
| 603 | rio_dprintk(RIO_DEBUG_INTR, " control = %d\n", PacketP->control); |
| 604 | rio_dprintk(RIO_DEBUG_INTR, " csum = %d\n", PacketP->csum); |
| 605 | rio_dprintk(RIO_DEBUG_INTR, " data bytes: "); |
| 606 | for (DataCnt = 0; DataCnt < PKT_MAX_DATA_LEN; DataCnt++) |
| 607 | rio_dprintk(RIO_DEBUG_INTR, "%d\n", PacketP->data[DataCnt]); |
| 608 | remove_receive(PortP); |
| 609 | put_free_end(PortP->HostP, PacketP); |
| 610 | continue; /* with next packet */ |
| 611 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 613 | /* |
| 614 | ** How many characters can we move 'upstream' ? |
| 615 | ** |
| 616 | ** Determine the minimum of the amount of data |
| 617 | ** available and the amount of space in which to |
| 618 | ** put it. |
| 619 | ** |
| 620 | ** 1. Get the packet length by masking 'len' |
| 621 | ** for only the length bits. |
| 622 | ** 2. Available space is [buffer size] - [space used] |
| 623 | ** |
| 624 | ** Transfer count is the minimum of packet length |
| 625 | ** and available space. |
| 626 | */ |
| 627 | |
| 628 | transCount = tty_buffer_request_room(TtyP, PacketP->len & PKT_LEN_MASK); |
| 629 | rio_dprintk(RIO_DEBUG_REC, "port %d: Copy %d bytes\n", PortP->PortNum, transCount); |
| 630 | /* |
| 631 | ** To use the following 'kkprintfs' for debugging - change the '#undef' |
| 632 | ** to '#define', (this is the only place ___DEBUG_IT___ occurs in the |
| 633 | ** driver). |
| 634 | */ |
Alan Cox | 00d83a5 | 2006-03-24 03:18:28 -0800 | [diff] [blame^] | 635 | ptr = (unsigned char *) PacketP->data + PortP->RxDataStart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 637 | tty_prepare_flip_string(TtyP, &buf, transCount); |
| 638 | rio_memcpy_fromio(buf, ptr, transCount); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 639 | PortP->RxDataStart += transCount; |
| 640 | PacketP->len -= transCount; |
| 641 | copied += transCount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
| 643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 645 | if (PacketP->len == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 647 | ** If we have emptied the packet, then we can |
| 648 | ** free it, and reset the start pointer for |
| 649 | ** the next packet. |
| 650 | */ |
| 651 | remove_receive(PortP); |
| 652 | put_free_end(PortP->HostP, PacketP); |
| 653 | PortP->RxDataStart = 0; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 654 | } |
| 655 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 657 | if (copied) { |
| 658 | rio_dprintk(RIO_DEBUG_REC, "port %d: pushing tty flip buffer: %d total bytes copied.\n", PortP->PortNum, copied); |
| 659 | tty_flip_buffer_push(TtyP); |
| 660 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 662 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | } |
| 664 | |