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