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 : rioparam.c |
| 24 | ** SID : 1.3 |
| 25 | ** Last Modified : 11/6/98 10:33:45 |
| 26 | ** Retrieved : 11/6/98 10:33:50 |
| 27 | ** |
| 28 | ** ident @(#)rioparam.c 1.3 |
| 29 | ** |
| 30 | ** ----------------------------------------------------------------------------- |
| 31 | */ |
| 32 | |
| 33 | #ifdef SCCS_LABELS |
| 34 | static char *_rioparam_c_sccs_ = "@(#)rioparam.c 1.3"; |
| 35 | #endif |
| 36 | |
| 37 | #include <linux/module.h> |
| 38 | #include <linux/slab.h> |
| 39 | #include <linux/errno.h> |
| 40 | #include <linux/tty.h> |
| 41 | #include <asm/io.h> |
| 42 | #include <asm/system.h> |
| 43 | #include <asm/string.h> |
| 44 | #include <asm/semaphore.h> |
| 45 | #include <asm/uaccess.h> |
| 46 | |
| 47 | #include <linux/termios.h> |
| 48 | #include <linux/serial.h> |
| 49 | |
| 50 | #include <linux/generic_serial.h> |
| 51 | |
| 52 | |
| 53 | #include "linux_compat.h" |
| 54 | #include "rio_linux.h" |
| 55 | #include "typdef.h" |
| 56 | #include "pkt.h" |
| 57 | #include "daemon.h" |
| 58 | #include "rio.h" |
| 59 | #include "riospace.h" |
| 60 | #include "top.h" |
| 61 | #include "cmdpkt.h" |
| 62 | #include "map.h" |
| 63 | #include "riotypes.h" |
| 64 | #include "rup.h" |
| 65 | #include "port.h" |
| 66 | #include "riodrvr.h" |
| 67 | #include "rioinfo.h" |
| 68 | #include "func.h" |
| 69 | #include "errors.h" |
| 70 | #include "pci.h" |
| 71 | |
| 72 | #include "parmmap.h" |
| 73 | #include "unixrup.h" |
| 74 | #include "board.h" |
| 75 | #include "host.h" |
| 76 | #include "error.h" |
| 77 | #include "phb.h" |
| 78 | #include "link.h" |
| 79 | #include "cmdblk.h" |
| 80 | #include "route.h" |
| 81 | #include "control.h" |
| 82 | #include "cirrus.h" |
| 83 | #include "rioioctl.h" |
| 84 | #include "param.h" |
| 85 | #include "list.h" |
| 86 | #include "sam.h" |
| 87 | |
| 88 | |
| 89 | |
| 90 | /* |
| 91 | ** The Scam, based on email from jeremyr@bugs.specialix.co.uk.... |
| 92 | ** |
| 93 | ** To send a command on a particular port, you put a packet with the |
| 94 | ** command bit set onto the port. The command bit is in the len field, |
| 95 | ** and gets ORed in with the actual byte count. |
| 96 | ** |
| 97 | ** When you send a packet with the command bit set, then the first |
| 98 | ** data byte ( data[0] ) is interpretted as the command to execute. |
| 99 | ** It also governs what data structure overlay should accompany the packet. |
| 100 | ** Commands are defined in cirrus/cirrus.h |
| 101 | ** |
| 102 | ** If you want the command to pre-emt data already on the queue for the |
| 103 | ** port, set the pre-emptive bit in conjunction with the command bit. |
| 104 | ** It is not defined what will happen if you set the preemptive bit |
| 105 | ** on a packet that is NOT a command. |
| 106 | ** |
| 107 | ** Pre-emptive commands should be queued at the head of the queue using |
| 108 | ** add_start(), whereas normal commands and data are enqueued using |
| 109 | ** add_end(). |
| 110 | ** |
| 111 | ** Most commands do not use the remaining bytes in the data array. The |
| 112 | ** exceptions are OPEN MOPEN and CONFIG. (NB. As with the SI CONFIG and |
| 113 | ** OPEN are currently analagous). With these three commands the following |
| 114 | ** 11 data bytes are all used to pass config information such as baud rate etc. |
| 115 | ** The fields are also defined in cirrus.h. Some contain straightforward |
| 116 | ** information such as the transmit XON character. Two contain the transmit and |
| 117 | ** receive baud rates respectively. For most baud rates there is a direct |
| 118 | ** mapping between the rates defined in <sys/termio.h> and the byte in the |
| 119 | ** packet. There are additional (non UNIX-standard) rates defined in |
| 120 | ** /u/dos/rio/cirrus/h/brates.h. |
| 121 | ** |
| 122 | ** The rest of the data fields contain approximations to the Cirrus registers |
| 123 | ** that are used to program number of bits etc. Each registers bit fields is |
| 124 | ** defined in cirrus.h. |
| 125 | ** |
| 126 | ** NB. Only use those bits that are defined as being driver specific |
| 127 | ** or common to the RTA and the driver. |
| 128 | ** |
| 129 | ** All commands going from RTA->Host will be dealt with by the Host code - you |
| 130 | ** will never see them. As with the SI there will be three fields to look out |
| 131 | ** for in each phb (not yet defined - needs defining a.s.a.p). |
| 132 | ** |
| 133 | ** modem_status - current state of handshake pins. |
| 134 | ** |
| 135 | ** port_status - current port status - equivalent to hi_stat for SI, indicates |
| 136 | ** if port is IDLE_OPEN, IDLE_CLOSED etc. |
| 137 | ** |
| 138 | ** break_status - bit X set if break has been received. |
| 139 | ** |
| 140 | ** Happy hacking. |
| 141 | ** |
| 142 | */ |
| 143 | |
| 144 | /* |
| 145 | ** RIOParam is used to open or configure a port. You pass it a PortP, |
| 146 | ** which will have a tty struct attached to it. You also pass a command, |
| 147 | ** either OPEN or CONFIG. The port's setup is taken from the t_ fields |
| 148 | ** of the tty struct inside the PortP, and the port is either opened |
| 149 | ** or re-configured. You must also tell RIOParam if the device is a modem |
| 150 | ** device or not (i.e. top bit of minor number set or clear - take special |
| 151 | ** care when deciding on this!). |
| 152 | ** RIOParam neither flushes nor waits for drain, and is NOT preemptive. |
| 153 | ** |
| 154 | ** RIOParam assumes it will be called at splrio(), and also assumes |
| 155 | ** that CookMode is set correctly in the port structure. |
| 156 | ** |
| 157 | ** NB. for MPX |
| 158 | ** tty lock must NOT have been previously acquired. |
| 159 | */ |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 160 | int RIOParam(struct Port *PortP, int cmd, int Modem, int SleepFlag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | { |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 162 | struct tty_struct *TtyP; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 163 | int retval; |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 164 | struct phb_param *phb_param_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | PKT *PacketP; |
| 166 | int res; |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 167 | u8 Cor1 = 0, Cor2 = 0, Cor4 = 0, Cor5 = 0; |
| 168 | u8 TxXon = 0, TxXoff = 0, RxXon = 0, RxXoff = 0; |
| 169 | u8 LNext = 0, TxBaud = 0, RxBaud = 0; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 170 | int retries = 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | unsigned long flags; |
| 172 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 173 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
| 175 | TtyP = PortP->gs.tty; |
| 176 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 177 | rio_dprintk(RIO_DEBUG_PARAM, "RIOParam: Port:%d cmd:%d Modem:%d SleepFlag:%d Mapped: %d, tty=%p\n", PortP->PortNum, cmd, Modem, SleepFlag, PortP->Mapped, TtyP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
| 179 | if (!TtyP) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 180 | rio_dprintk(RIO_DEBUG_PARAM, "Can't call rioparam with null tty.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 182 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 184 | return RIO_FAIL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 186 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 188 | if (cmd == OPEN) { |
| 189 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 190 | ** If the port is set to store or lock the parameters, and it is |
| 191 | ** paramed with OPEN, we want to restore the saved port termio, but |
| 192 | ** only if StoredTermio has been saved, i.e. NOT 1st open after reboot. |
| 193 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 197 | ** wait for space |
| 198 | */ |
| 199 | while (!(res = can_add_transmit(&PacketP, PortP)) || (PortP->InUse != NOT_INUSE)) { |
| 200 | if (retries-- <= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | break; |
| 202 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 203 | if (PortP->InUse != NOT_INUSE) { |
| 204 | rio_dprintk(RIO_DEBUG_PARAM, "Port IN_USE for pre-emptive command\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 207 | if (!res) { |
| 208 | rio_dprintk(RIO_DEBUG_PARAM, "Port has no space on transmit queue\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 211 | if (SleepFlag != OK_TO_SLEEP) { |
| 212 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | func_exit(); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 214 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | return RIO_FAIL; |
| 216 | } |
| 217 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 218 | rio_dprintk(RIO_DEBUG_PARAM, "wait for can_add_transmit\n"); |
| 219 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | retval = RIODelay(PortP, HUNDRED_MS); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 221 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | if (retval == RIO_FAIL) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 223 | rio_dprintk(RIO_DEBUG_PARAM, "wait for can_add_transmit broken by signal\n"); |
| 224 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | func_exit(); |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 226 | return -EINTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 228 | if (PortP->State & RIO_DELETED) { |
| 229 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 230 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | return RIO_SUCCESS; |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | if (!res) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 236 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 237 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
| 239 | return RIO_FAIL; |
| 240 | } |
| 241 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 242 | rio_dprintk(RIO_DEBUG_PARAM, "can_add_transmit() returns %x\n", res); |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 243 | rio_dprintk(RIO_DEBUG_PARAM, "Packet is 0x%p\n", PacketP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 245 | phb_param_ptr = (struct phb_param *) PacketP->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
| 247 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 248 | switch (TtyP->termios->c_cflag & CSIZE) { |
| 249 | case CS5: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 251 | rio_dprintk(RIO_DEBUG_PARAM, "5 bit data\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | Cor1 |= COR1_5BITS; |
| 253 | break; |
| 254 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 255 | case CS6: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 257 | rio_dprintk(RIO_DEBUG_PARAM, "6 bit data\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | Cor1 |= COR1_6BITS; |
| 259 | break; |
| 260 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 261 | case CS7: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 263 | rio_dprintk(RIO_DEBUG_PARAM, "7 bit data\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | Cor1 |= COR1_7BITS; |
| 265 | break; |
| 266 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 267 | case CS8: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 269 | rio_dprintk(RIO_DEBUG_PARAM, "8 bit data\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | Cor1 |= COR1_8BITS; |
| 271 | break; |
| 272 | } |
| 273 | } |
| 274 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 275 | if (TtyP->termios->c_cflag & CSTOPB) { |
| 276 | rio_dprintk(RIO_DEBUG_PARAM, "2 stop bits\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | Cor1 |= COR1_2STOP; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 278 | } else { |
| 279 | rio_dprintk(RIO_DEBUG_PARAM, "1 stop bit\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | Cor1 |= COR1_1STOP; |
| 281 | } |
| 282 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 283 | if (TtyP->termios->c_cflag & PARENB) { |
| 284 | rio_dprintk(RIO_DEBUG_PARAM, "Enable parity\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | Cor1 |= COR1_NORMAL; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 286 | } else { |
| 287 | rio_dprintk(RIO_DEBUG_PARAM, "Disable parity\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | Cor1 |= COR1_NOP; |
| 289 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 290 | if (TtyP->termios->c_cflag & PARODD) { |
| 291 | rio_dprintk(RIO_DEBUG_PARAM, "Odd parity\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | Cor1 |= COR1_ODD; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 293 | } else { |
| 294 | rio_dprintk(RIO_DEBUG_PARAM, "Even parity\n"); |
| 295 | Cor1 |= COR1_EVEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 299 | ** COR 2 |
| 300 | */ |
| 301 | if (TtyP->termios->c_iflag & IXON) { |
| 302 | rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop output control\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | Cor2 |= COR2_IXON; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 304 | } else { |
| 305 | if (PortP->Config & RIO_IXON) { |
| 306 | rio_dprintk(RIO_DEBUG_PARAM, "Force enable start/stop output control\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | Cor2 |= COR2_IXON; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 308 | } else |
| 309 | rio_dprintk(RIO_DEBUG_PARAM, "IXON has been disabled.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | if (TtyP->termios->c_iflag & IXANY) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 313 | if (PortP->Config & RIO_IXANY) { |
| 314 | rio_dprintk(RIO_DEBUG_PARAM, "Enable any key to restart output\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | Cor2 |= COR2_IXANY; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 316 | } else |
| 317 | rio_dprintk(RIO_DEBUG_PARAM, "IXANY has been disabled due to sanity reasons.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 320 | if (TtyP->termios->c_iflag & IXOFF) { |
| 321 | rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop input control 2\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | Cor2 |= COR2_IXOFF; |
| 323 | } |
| 324 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 325 | if (TtyP->termios->c_cflag & HUPCL) { |
| 326 | rio_dprintk(RIO_DEBUG_PARAM, "Hangup on last close\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | Cor2 |= COR2_HUPCL; |
| 328 | } |
| 329 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 330 | if (C_CRTSCTS(TtyP)) { |
| 331 | rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control enabled\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | Cor2 |= COR2_CTSFLOW; |
| 333 | Cor2 |= COR2_RTSFLOW; |
| 334 | } else { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 335 | rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control disabled\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | Cor2 &= ~COR2_CTSFLOW; |
| 337 | Cor2 &= ~COR2_RTSFLOW; |
| 338 | } |
| 339 | |
| 340 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 341 | if (TtyP->termios->c_cflag & CLOCAL) { |
| 342 | rio_dprintk(RIO_DEBUG_PARAM, "Local line\n"); |
| 343 | } else { |
| 344 | rio_dprintk(RIO_DEBUG_PARAM, "Possible Modem line\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 348 | ** COR 4 (there is no COR 3) |
| 349 | */ |
| 350 | if (TtyP->termios->c_iflag & IGNBRK) { |
| 351 | rio_dprintk(RIO_DEBUG_PARAM, "Ignore break condition\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | Cor4 |= COR4_IGNBRK; |
| 353 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 354 | if (!(TtyP->termios->c_iflag & BRKINT)) { |
| 355 | rio_dprintk(RIO_DEBUG_PARAM, "Break generates NULL condition\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | Cor4 |= COR4_NBRKINT; |
| 357 | } else { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 358 | rio_dprintk(RIO_DEBUG_PARAM, "Interrupt on break condition\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 361 | if (TtyP->termios->c_iflag & INLCR) { |
| 362 | rio_dprintk(RIO_DEBUG_PARAM, "Map newline to carriage return on input\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | Cor4 |= COR4_INLCR; |
| 364 | } |
| 365 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 366 | if (TtyP->termios->c_iflag & IGNCR) { |
| 367 | rio_dprintk(RIO_DEBUG_PARAM, "Ignore carriage return on input\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | Cor4 |= COR4_IGNCR; |
| 369 | } |
| 370 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 371 | if (TtyP->termios->c_iflag & ICRNL) { |
| 372 | rio_dprintk(RIO_DEBUG_PARAM, "Map carriage return to newline on input\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | Cor4 |= COR4_ICRNL; |
| 374 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 375 | if (TtyP->termios->c_iflag & IGNPAR) { |
| 376 | rio_dprintk(RIO_DEBUG_PARAM, "Ignore characters with parity errors\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | Cor4 |= COR4_IGNPAR; |
| 378 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 379 | if (TtyP->termios->c_iflag & PARMRK) { |
| 380 | rio_dprintk(RIO_DEBUG_PARAM, "Mark parity errors\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | Cor4 |= COR4_PARMRK; |
| 382 | } |
| 383 | |
| 384 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 385 | ** Set the RAISEMOD flag to ensure that the modem lines are raised |
| 386 | ** on reception of a config packet. |
| 387 | ** The download code handles the zero baud condition. |
| 388 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | Cor4 |= COR4_RAISEMOD; |
| 390 | |
| 391 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 392 | ** COR 5 |
| 393 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
| 395 | Cor5 = COR5_CMOE; |
| 396 | |
| 397 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 398 | ** Set to monitor tbusy/tstop (or not). |
| 399 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
| 401 | if (PortP->MonitorTstate) |
| 402 | Cor5 |= COR5_TSTATE_ON; |
| 403 | else |
| 404 | Cor5 |= COR5_TSTATE_OFF; |
| 405 | |
| 406 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 407 | ** Could set LNE here if you wanted LNext processing. SVR4 will use it. |
| 408 | */ |
| 409 | if (TtyP->termios->c_iflag & ISTRIP) { |
| 410 | rio_dprintk(RIO_DEBUG_PARAM, "Strip input characters\n"); |
| 411 | if (!(PortP->State & RIO_TRIAD_MODE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | Cor5 |= COR5_ISTRIP; |
| 413 | } |
| 414 | } |
| 415 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 416 | if (TtyP->termios->c_oflag & ONLCR) { |
| 417 | rio_dprintk(RIO_DEBUG_PARAM, "Map newline to carriage-return, newline on output\n"); |
| 418 | if (PortP->CookMode == COOK_MEDIUM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | Cor5 |= COR5_ONLCR; |
| 420 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 421 | if (TtyP->termios->c_oflag & OCRNL) { |
| 422 | rio_dprintk(RIO_DEBUG_PARAM, "Map carriage return to newline on output\n"); |
| 423 | if (PortP->CookMode == COOK_MEDIUM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | Cor5 |= COR5_OCRNL; |
| 425 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 426 | if ((TtyP->termios->c_oflag & TABDLY) == TAB3) { |
| 427 | rio_dprintk(RIO_DEBUG_PARAM, "Tab delay 3 set\n"); |
| 428 | if (PortP->CookMode == COOK_MEDIUM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | Cor5 |= COR5_TAB3; |
| 430 | } |
| 431 | |
| 432 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 433 | ** Flow control bytes. |
| 434 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | TxXon = TtyP->termios->c_cc[VSTART]; |
| 436 | TxXoff = TtyP->termios->c_cc[VSTOP]; |
| 437 | RxXon = TtyP->termios->c_cc[VSTART]; |
| 438 | RxXoff = TtyP->termios->c_cc[VSTOP]; |
| 439 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 440 | ** LNEXT byte |
| 441 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | LNext = 0; |
| 443 | |
| 444 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 445 | ** Baud rate bytes |
| 446 | */ |
| 447 | rio_dprintk(RIO_DEBUG_PARAM, "Mapping of rx/tx baud %x (%x)\n", TtyP->termios->c_cflag, CBAUD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
| 449 | switch (TtyP->termios->c_cflag & CBAUD) { |
| 450 | #define e(b) case B ## b : RxBaud = TxBaud = RIO_B ## b ;break |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 451 | e(50); |
| 452 | e(75); |
| 453 | e(110); |
| 454 | e(134); |
| 455 | e(150); |
| 456 | e(200); |
| 457 | e(300); |
| 458 | e(600); |
| 459 | e(1200); |
| 460 | e(1800); |
| 461 | e(2400); |
| 462 | e(4800); |
| 463 | e(9600); |
| 464 | e(19200); |
| 465 | e(38400); |
| 466 | e(57600); |
| 467 | e(115200); /* e(230400);e(460800); e(921600); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 470 | rio_dprintk(RIO_DEBUG_PARAM, "tx baud 0x%x, rx baud 0x%x\n", TxBaud, RxBaud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | |
| 472 | |
| 473 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 474 | ** Leftovers |
| 475 | */ |
| 476 | if (TtyP->termios->c_cflag & CREAD) |
| 477 | rio_dprintk(RIO_DEBUG_PARAM, "Enable receiver\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | #ifdef RCV1EN |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 479 | if (TtyP->termios->c_cflag & RCV1EN) |
| 480 | rio_dprintk(RIO_DEBUG_PARAM, "RCV1EN (?)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | #endif |
| 482 | #ifdef XMT1EN |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 483 | if (TtyP->termios->c_cflag & XMT1EN) |
| 484 | rio_dprintk(RIO_DEBUG_PARAM, "XMT1EN (?)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | #endif |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 486 | if (TtyP->termios->c_lflag & ISIG) |
| 487 | rio_dprintk(RIO_DEBUG_PARAM, "Input character signal generating enabled\n"); |
| 488 | if (TtyP->termios->c_lflag & ICANON) |
| 489 | rio_dprintk(RIO_DEBUG_PARAM, "Canonical input: erase and kill enabled\n"); |
| 490 | if (TtyP->termios->c_lflag & XCASE) |
| 491 | rio_dprintk(RIO_DEBUG_PARAM, "Canonical upper/lower presentation\n"); |
| 492 | if (TtyP->termios->c_lflag & ECHO) |
| 493 | rio_dprintk(RIO_DEBUG_PARAM, "Enable input echo\n"); |
| 494 | if (TtyP->termios->c_lflag & ECHOE) |
| 495 | rio_dprintk(RIO_DEBUG_PARAM, "Enable echo erase\n"); |
| 496 | if (TtyP->termios->c_lflag & ECHOK) |
| 497 | rio_dprintk(RIO_DEBUG_PARAM, "Enable echo kill\n"); |
| 498 | if (TtyP->termios->c_lflag & ECHONL) |
| 499 | rio_dprintk(RIO_DEBUG_PARAM, "Enable echo newline\n"); |
| 500 | if (TtyP->termios->c_lflag & NOFLSH) |
| 501 | rio_dprintk(RIO_DEBUG_PARAM, "Disable flush after interrupt or quit\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | #ifdef TOSTOP |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 503 | if (TtyP->termios->c_lflag & TOSTOP) |
| 504 | rio_dprintk(RIO_DEBUG_PARAM, "Send SIGTTOU for background output\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | #endif |
| 506 | #ifdef XCLUDE |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 507 | if (TtyP->termios->c_lflag & XCLUDE) |
| 508 | rio_dprintk(RIO_DEBUG_PARAM, "Exclusive use of this line\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | #endif |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 510 | if (TtyP->termios->c_iflag & IUCLC) |
| 511 | rio_dprintk(RIO_DEBUG_PARAM, "Map uppercase to lowercase on input\n"); |
| 512 | if (TtyP->termios->c_oflag & OPOST) |
| 513 | rio_dprintk(RIO_DEBUG_PARAM, "Enable output post-processing\n"); |
| 514 | if (TtyP->termios->c_oflag & OLCUC) |
| 515 | rio_dprintk(RIO_DEBUG_PARAM, "Map lowercase to uppercase on output\n"); |
| 516 | if (TtyP->termios->c_oflag & ONOCR) |
| 517 | rio_dprintk(RIO_DEBUG_PARAM, "No carriage return output at column 0\n"); |
| 518 | if (TtyP->termios->c_oflag & ONLRET) |
| 519 | rio_dprintk(RIO_DEBUG_PARAM, "Newline performs carriage return function\n"); |
| 520 | if (TtyP->termios->c_oflag & OFILL) |
| 521 | rio_dprintk(RIO_DEBUG_PARAM, "Use fill characters for delay\n"); |
| 522 | if (TtyP->termios->c_oflag & OFDEL) |
| 523 | rio_dprintk(RIO_DEBUG_PARAM, "Fill character is DEL\n"); |
| 524 | if (TtyP->termios->c_oflag & NLDLY) |
| 525 | rio_dprintk(RIO_DEBUG_PARAM, "Newline delay set\n"); |
| 526 | if (TtyP->termios->c_oflag & CRDLY) |
| 527 | rio_dprintk(RIO_DEBUG_PARAM, "Carriage return delay set\n"); |
| 528 | if (TtyP->termios->c_oflag & TABDLY) |
| 529 | rio_dprintk(RIO_DEBUG_PARAM, "Tab delay set\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 531 | ** These things are kind of useful in a later life! |
| 532 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | PortP->Cor2Copy = Cor2; |
| 534 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 535 | if (PortP->State & RIO_DELETED) { |
| 536 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 537 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | |
| 539 | return RIO_FAIL; |
| 540 | } |
| 541 | |
| 542 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 543 | ** Actually write the info into the packet to be sent |
| 544 | */ |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 545 | writeb(cmd, &phb_param_ptr->Cmd); |
| 546 | writeb(Cor1, &phb_param_ptr->Cor1); |
| 547 | writeb(Cor2, &phb_param_ptr->Cor2); |
| 548 | writeb(Cor4, &phb_param_ptr->Cor4); |
| 549 | writeb(Cor5, &phb_param_ptr->Cor5); |
| 550 | writeb(TxXon, &phb_param_ptr->TxXon); |
| 551 | writeb(RxXon, &phb_param_ptr->RxXon); |
| 552 | writeb(TxXoff, &phb_param_ptr->TxXoff); |
| 553 | writeb(RxXoff, &phb_param_ptr->RxXoff); |
| 554 | writeb(LNext, &phb_param_ptr->LNext); |
| 555 | writeb(TxBaud, &phb_param_ptr->TxBaud); |
| 556 | writeb(RxBaud, &phb_param_ptr->RxBaud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
| 558 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 559 | ** Set the length/command field |
| 560 | */ |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 561 | writeb(12 | PKT_CMD_BIT, &PacketP->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | |
| 563 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 564 | ** The packet is formed - now, whack it off |
| 565 | ** to its final destination: |
| 566 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | add_transmit(PortP); |
| 568 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 569 | ** Count characters transmitted for port statistics reporting |
| 570 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | if (PortP->statsGather) |
| 572 | PortP->txchars += 12; |
| 573 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 574 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 576 | rio_dprintk(RIO_DEBUG_PARAM, "add_transmit returned.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 578 | ** job done. |
| 579 | */ |
| 580 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
| 582 | return RIO_SUCCESS; |
| 583 | } |
| 584 | |
| 585 | |
| 586 | /* |
| 587 | ** We can add another packet to a transmit queue if the packet pointer pointed |
| 588 | ** to by the TxAdd pointer has PKT_IN_USE clear in its address. |
| 589 | */ |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 590 | int can_add_transmit(PKT **PktP, struct Port *PortP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | { |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 592 | PKT *tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 594 | *PktP = tp = (PKT *) RIO_PTR(PortP->Caddr, readw(PortP->TxAdd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 596 | return !((unsigned long) tp & PKT_IN_USE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | /* |
| 600 | ** To add a packet to the queue, you set the PKT_IN_USE bit in the address, |
| 601 | ** and then move the TxAdd pointer along one position to point to the next |
| 602 | ** packet pointer. You must wrap the pointer from the end back to the start. |
| 603 | */ |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 604 | void add_transmit(struct Port *PortP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | { |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 606 | if (readw(PortP->TxAdd) & PKT_IN_USE) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 607 | rio_dprintk(RIO_DEBUG_PARAM, "add_transmit: Packet has been stolen!"); |
| 608 | } |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 609 | writew(readw(PortP->TxAdd) | PKT_IN_USE, PortP->TxAdd); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 610 | PortP->TxAdd = (PortP->TxAdd == PortP->TxEnd) ? PortP->TxStart : PortP->TxAdd + 1; |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 611 | writew(RIO_OFF(PortP->Caddr, PortP->TxAdd), &PortP->PhbP->tx_add); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | /**************************************** |
| 615 | * Put a packet onto the end of the |
| 616 | * free list |
| 617 | ****************************************/ |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 618 | void put_free_end(struct Host *HostP, PKT *PktP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | { |
| 620 | FREE_LIST *tmp_pointer; |
| 621 | ushort old_end, new_end; |
| 622 | unsigned long flags; |
| 623 | |
| 624 | rio_spin_lock_irqsave(&HostP->HostLock, flags); |
| 625 | |
| 626 | /************************************************* |
| 627 | * Put a packet back onto the back of the free list |
| 628 | * |
| 629 | ************************************************/ |
| 630 | |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 631 | rio_dprintk(RIO_DEBUG_PFE, "put_free_end(PktP=%p)\n", PktP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 633 | if ((old_end = readw(&HostP->ParmMapP->free_list_end)) != TPNULL) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 634 | new_end = RIO_OFF(HostP->Caddr, PktP); |
| 635 | tmp_pointer = (FREE_LIST *) RIO_PTR(HostP->Caddr, old_end); |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 636 | writew(new_end, &tmp_pointer->next); |
| 637 | writew(old_end, &((FREE_LIST *) PktP)->prev); |
| 638 | writew(TPNULL, &((FREE_LIST *) PktP)->next); |
| 639 | writew(new_end, &HostP->ParmMapP->free_list_end); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 640 | } else { /* First packet on the free list this should never happen! */ |
| 641 | rio_dprintk(RIO_DEBUG_PFE, "put_free_end(): This should never happen\n"); |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 642 | writew(RIO_OFF(HostP->Caddr, PktP), &HostP->ParmMapP->free_list_end); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 643 | tmp_pointer = (FREE_LIST *) PktP; |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 644 | writew(TPNULL, &tmp_pointer->prev); |
| 645 | writew(TPNULL, &tmp_pointer->next); |
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 | rio_dprintk(RIO_DEBUG_CMD, "Before unlock: %p\n", &HostP->HostLock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | rio_spin_unlock_irqrestore(&HostP->HostLock, flags); |
| 649 | } |
| 650 | |
| 651 | /* |
| 652 | ** can_remove_receive(PktP,P) returns non-zero if PKT_IN_USE is set |
| 653 | ** for the next packet on the queue. It will also set PktP to point to the |
| 654 | ** relevant packet, [having cleared the PKT_IN_USE bit]. If PKT_IN_USE is clear, |
| 655 | ** then can_remove_receive() returns 0. |
| 656 | */ |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 657 | int can_remove_receive(PKT **PktP, struct Port *PortP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | { |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 659 | if (readw(PortP->RxRemove) & PKT_IN_USE) { |
| 660 | *PktP = (PKT *) RIO_PTR(PortP->Caddr, readw(PortP->RxRemove) & ~PKT_IN_USE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | return 1; |
| 662 | } |
| 663 | return 0; |
| 664 | } |
| 665 | |
| 666 | /* |
| 667 | ** To remove a packet from the receive queue you clear its PKT_IN_USE bit, |
| 668 | ** and then bump the pointers. Once the pointers get to the end, they must |
| 669 | ** be wrapped back to the start. |
| 670 | */ |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 671 | void remove_receive(struct Port *PortP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | { |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 673 | writew(readw(PortP->RxRemove) & ~PKT_IN_USE, PortP->RxRemove); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 674 | PortP->RxRemove = (PortP->RxRemove == PortP->RxEnd) ? PortP->RxStart : PortP->RxRemove + 1; |
Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame^] | 675 | writew(RIO_OFF(PortP->Caddr, PortP->RxRemove), &PortP->PhbP->rx_remove); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | } |