blob: 6415f3f32a724b4549ccf492487a762be18af999 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/errno.h>
35#include <linux/tty.h>
36#include <asm/io.h>
37#include <asm/system.h>
38#include <asm/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <asm/uaccess.h>
40
41#include <linux/termios.h>
42#include <linux/serial.h>
43
44#include <linux/generic_serial.h>
45
46
47#include "linux_compat.h"
48#include "rio_linux.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include "pkt.h"
50#include "daemon.h"
51#include "rio.h"
52#include "riospace.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include "cmdpkt.h"
54#include "map.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include "rup.h"
56#include "port.h"
57#include "riodrvr.h"
58#include "rioinfo.h"
59#include "func.h"
60#include "errors.h"
61#include "pci.h"
62
63#include "parmmap.h"
64#include "unixrup.h"
65#include "board.h"
66#include "host.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#include "phb.h"
68#include "link.h"
69#include "cmdblk.h"
70#include "route.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070071#include "cirrus.h"
72#include "rioioctl.h"
73#include "param.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75
76
77/*
78** The Scam, based on email from jeremyr@bugs.specialix.co.uk....
79**
80** To send a command on a particular port, you put a packet with the
81** command bit set onto the port. The command bit is in the len field,
82** and gets ORed in with the actual byte count.
83**
Matt LaPlante0779bf22006-11-30 05:24:39 +010084** When you send a packet with the command bit set the first
85** data byte (data[0]) is interpreted as the command to execute.
Linus Torvalds1da177e2005-04-16 15:20:36 -070086** It also governs what data structure overlay should accompany the packet.
87** Commands are defined in cirrus/cirrus.h
88**
89** If you want the command to pre-emt data already on the queue for the
90** port, set the pre-emptive bit in conjunction with the command bit.
91** It is not defined what will happen if you set the preemptive bit
92** on a packet that is NOT a command.
93**
94** Pre-emptive commands should be queued at the head of the queue using
95** add_start(), whereas normal commands and data are enqueued using
96** add_end().
97**
98** Most commands do not use the remaining bytes in the data array. The
99** exceptions are OPEN MOPEN and CONFIG. (NB. As with the SI CONFIG and
Matt LaPlante0779bf22006-11-30 05:24:39 +0100100** OPEN are currently analogous). With these three commands the following
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101** 11 data bytes are all used to pass config information such as baud rate etc.
102** The fields are also defined in cirrus.h. Some contain straightforward
103** information such as the transmit XON character. Two contain the transmit and
104** receive baud rates respectively. For most baud rates there is a direct
105** mapping between the rates defined in <sys/termio.h> and the byte in the
106** packet. There are additional (non UNIX-standard) rates defined in
107** /u/dos/rio/cirrus/h/brates.h.
108**
109** The rest of the data fields contain approximations to the Cirrus registers
110** that are used to program number of bits etc. Each registers bit fields is
111** defined in cirrus.h.
112**
113** NB. Only use those bits that are defined as being driver specific
114** or common to the RTA and the driver.
115**
116** All commands going from RTA->Host will be dealt with by the Host code - you
117** will never see them. As with the SI there will be three fields to look out
118** for in each phb (not yet defined - needs defining a.s.a.p).
119**
120** modem_status - current state of handshake pins.
121**
122** port_status - current port status - equivalent to hi_stat for SI, indicates
123** if port is IDLE_OPEN, IDLE_CLOSED etc.
124**
125** break_status - bit X set if break has been received.
126**
127** Happy hacking.
128**
129*/
130
131/*
132** RIOParam is used to open or configure a port. You pass it a PortP,
133** which will have a tty struct attached to it. You also pass a command,
134** either OPEN or CONFIG. The port's setup is taken from the t_ fields
135** of the tty struct inside the PortP, and the port is either opened
136** or re-configured. You must also tell RIOParam if the device is a modem
137** device or not (i.e. top bit of minor number set or clear - take special
138** care when deciding on this!).
139** RIOParam neither flushes nor waits for drain, and is NOT preemptive.
140**
141** RIOParam assumes it will be called at splrio(), and also assumes
142** that CookMode is set correctly in the port structure.
143**
144** NB. for MPX
145** tty lock must NOT have been previously acquired.
146*/
Alan Coxe2b3afd2006-03-24 03:18:27 -0800147int RIOParam(struct Port *PortP, int cmd, int Modem, int SleepFlag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
Alan Coxe2b3afd2006-03-24 03:18:27 -0800149 struct tty_struct *TtyP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800150 int retval;
Al Virod886cb52006-05-27 00:08:25 -0400151 struct phb_param __iomem *phb_param_ptr;
152 struct PKT __iomem *PacketP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 int res;
Alan Coxe2b3afd2006-03-24 03:18:27 -0800154 u8 Cor1 = 0, Cor2 = 0, Cor4 = 0, Cor5 = 0;
155 u8 TxXon = 0, TxXoff = 0, RxXon = 0, RxXoff = 0;
156 u8 LNext = 0, TxBaud = 0, RxBaud = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800157 int retries = 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 unsigned long flags;
159
Andrew Morton8d8706e2006-01-11 12:17:49 -0800160 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Alan Coxb5391e22008-07-16 21:55:20 +0100162 TtyP = PortP->gs.port.tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Andrew Morton8d8706e2006-01-11 12:17:49 -0800164 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 Torvalds1da177e2005-04-16 15:20:36 -0700165
166 if (!TtyP) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800167 rio_dprintk(RIO_DEBUG_PARAM, "Can't call rioparam with null tty.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Andrew Morton8d8706e2006-01-11 12:17:49 -0800169 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Andrew Morton8d8706e2006-01-11 12:17:49 -0800171 return RIO_FAIL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800173 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Jiri Slabyd6f63412008-04-30 00:53:57 -0700175 if (cmd == RIOC_OPEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800177 ** If the port is set to store or lock the parameters, and it is
178 ** paramed with OPEN, we want to restore the saved port termio, but
179 ** only if StoredTermio has been saved, i.e. NOT 1st open after reboot.
180 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 }
182
183 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800184 ** wait for space
185 */
186 while (!(res = can_add_transmit(&PacketP, PortP)) || (PortP->InUse != NOT_INUSE)) {
187 if (retries-- <= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 break;
189 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800190 if (PortP->InUse != NOT_INUSE) {
191 rio_dprintk(RIO_DEBUG_PARAM, "Port IN_USE for pre-emptive command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 }
193
Andrew Morton8d8706e2006-01-11 12:17:49 -0800194 if (!res) {
195 rio_dprintk(RIO_DEBUG_PARAM, "Port has no space on transmit queue\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 }
197
Andrew Morton8d8706e2006-01-11 12:17:49 -0800198 if (SleepFlag != OK_TO_SLEEP) {
199 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 func_exit();
Andrew Morton8d8706e2006-01-11 12:17:49 -0800201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 return RIO_FAIL;
203 }
204
Andrew Morton8d8706e2006-01-11 12:17:49 -0800205 rio_dprintk(RIO_DEBUG_PARAM, "wait for can_add_transmit\n");
206 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 retval = RIODelay(PortP, HUNDRED_MS);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800208 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 if (retval == RIO_FAIL) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800210 rio_dprintk(RIO_DEBUG_PARAM, "wait for can_add_transmit broken by signal\n");
211 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 func_exit();
Alan Coxe2b3afd2006-03-24 03:18:27 -0800213 return -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800215 if (PortP->State & RIO_DELETED) {
216 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
217 func_exit();
Alan Cox554b7c82006-03-24 03:18:32 -0800218 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 }
220 }
221
222 if (!res) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800223 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
224 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226 return RIO_FAIL;
227 }
228
Andrew Morton8d8706e2006-01-11 12:17:49 -0800229 rio_dprintk(RIO_DEBUG_PARAM, "can_add_transmit() returns %x\n", res);
Alan Cox554b7c82006-03-24 03:18:32 -0800230 rio_dprintk(RIO_DEBUG_PARAM, "Packet is %p\n", PacketP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
Al Virod886cb52006-05-27 00:08:25 -0400232 phb_param_ptr = (struct phb_param __iomem *) PacketP->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
234
Andrew Morton8d8706e2006-01-11 12:17:49 -0800235 switch (TtyP->termios->c_cflag & CSIZE) {
236 case CS5:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800238 rio_dprintk(RIO_DEBUG_PARAM, "5 bit data\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700239 Cor1 |= RIOC_COR1_5BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 break;
241 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800242 case CS6:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800244 rio_dprintk(RIO_DEBUG_PARAM, "6 bit data\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700245 Cor1 |= RIOC_COR1_6BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 break;
247 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800248 case CS7:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800250 rio_dprintk(RIO_DEBUG_PARAM, "7 bit data\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700251 Cor1 |= RIOC_COR1_7BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 break;
253 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800254 case CS8:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800256 rio_dprintk(RIO_DEBUG_PARAM, "8 bit data\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700257 Cor1 |= RIOC_COR1_8BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 break;
259 }
260 }
261
Andrew Morton8d8706e2006-01-11 12:17:49 -0800262 if (TtyP->termios->c_cflag & CSTOPB) {
263 rio_dprintk(RIO_DEBUG_PARAM, "2 stop bits\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700264 Cor1 |= RIOC_COR1_2STOP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800265 } else {
266 rio_dprintk(RIO_DEBUG_PARAM, "1 stop bit\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700267 Cor1 |= RIOC_COR1_1STOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 }
269
Andrew Morton8d8706e2006-01-11 12:17:49 -0800270 if (TtyP->termios->c_cflag & PARENB) {
271 rio_dprintk(RIO_DEBUG_PARAM, "Enable parity\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700272 Cor1 |= RIOC_COR1_NORMAL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800273 } else {
274 rio_dprintk(RIO_DEBUG_PARAM, "Disable parity\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700275 Cor1 |= RIOC_COR1_NOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800277 if (TtyP->termios->c_cflag & PARODD) {
278 rio_dprintk(RIO_DEBUG_PARAM, "Odd parity\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700279 Cor1 |= RIOC_COR1_ODD;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800280 } else {
281 rio_dprintk(RIO_DEBUG_PARAM, "Even parity\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700282 Cor1 |= RIOC_COR1_EVEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 }
284
285 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800286 ** COR 2
287 */
288 if (TtyP->termios->c_iflag & IXON) {
289 rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop output control\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700290 Cor2 |= RIOC_COR2_IXON;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800291 } else {
292 if (PortP->Config & RIO_IXON) {
293 rio_dprintk(RIO_DEBUG_PARAM, "Force enable start/stop output control\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700294 Cor2 |= RIOC_COR2_IXON;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800295 } else
296 rio_dprintk(RIO_DEBUG_PARAM, "IXON has been disabled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 }
298
299 if (TtyP->termios->c_iflag & IXANY) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800300 if (PortP->Config & RIO_IXANY) {
301 rio_dprintk(RIO_DEBUG_PARAM, "Enable any key to restart output\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700302 Cor2 |= RIOC_COR2_IXANY;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800303 } else
304 rio_dprintk(RIO_DEBUG_PARAM, "IXANY has been disabled due to sanity reasons.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 }
306
Andrew Morton8d8706e2006-01-11 12:17:49 -0800307 if (TtyP->termios->c_iflag & IXOFF) {
308 rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop input control 2\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700309 Cor2 |= RIOC_COR2_IXOFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 }
311
Andrew Morton8d8706e2006-01-11 12:17:49 -0800312 if (TtyP->termios->c_cflag & HUPCL) {
313 rio_dprintk(RIO_DEBUG_PARAM, "Hangup on last close\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700314 Cor2 |= RIOC_COR2_HUPCL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 }
316
Andrew Morton8d8706e2006-01-11 12:17:49 -0800317 if (C_CRTSCTS(TtyP)) {
318 rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control enabled\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700319 Cor2 |= RIOC_COR2_CTSFLOW;
320 Cor2 |= RIOC_COR2_RTSFLOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 } else {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800322 rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control disabled\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700323 Cor2 &= ~RIOC_COR2_CTSFLOW;
324 Cor2 &= ~RIOC_COR2_RTSFLOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 }
326
327
Andrew Morton8d8706e2006-01-11 12:17:49 -0800328 if (TtyP->termios->c_cflag & CLOCAL) {
329 rio_dprintk(RIO_DEBUG_PARAM, "Local line\n");
330 } else {
331 rio_dprintk(RIO_DEBUG_PARAM, "Possible Modem line\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 }
333
334 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800335 ** COR 4 (there is no COR 3)
336 */
337 if (TtyP->termios->c_iflag & IGNBRK) {
338 rio_dprintk(RIO_DEBUG_PARAM, "Ignore break condition\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700339 Cor4 |= RIOC_COR4_IGNBRK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800341 if (!(TtyP->termios->c_iflag & BRKINT)) {
342 rio_dprintk(RIO_DEBUG_PARAM, "Break generates NULL condition\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700343 Cor4 |= RIOC_COR4_NBRKINT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 } else {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800345 rio_dprintk(RIO_DEBUG_PARAM, "Interrupt on break condition\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 }
347
Andrew Morton8d8706e2006-01-11 12:17:49 -0800348 if (TtyP->termios->c_iflag & INLCR) {
349 rio_dprintk(RIO_DEBUG_PARAM, "Map newline to carriage return on input\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700350 Cor4 |= RIOC_COR4_INLCR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 }
352
Andrew Morton8d8706e2006-01-11 12:17:49 -0800353 if (TtyP->termios->c_iflag & IGNCR) {
354 rio_dprintk(RIO_DEBUG_PARAM, "Ignore carriage return on input\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700355 Cor4 |= RIOC_COR4_IGNCR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 }
357
Andrew Morton8d8706e2006-01-11 12:17:49 -0800358 if (TtyP->termios->c_iflag & ICRNL) {
359 rio_dprintk(RIO_DEBUG_PARAM, "Map carriage return to newline on input\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700360 Cor4 |= RIOC_COR4_ICRNL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800362 if (TtyP->termios->c_iflag & IGNPAR) {
363 rio_dprintk(RIO_DEBUG_PARAM, "Ignore characters with parity errors\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700364 Cor4 |= RIOC_COR4_IGNPAR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800366 if (TtyP->termios->c_iflag & PARMRK) {
367 rio_dprintk(RIO_DEBUG_PARAM, "Mark parity errors\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700368 Cor4 |= RIOC_COR4_PARMRK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 }
370
371 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800372 ** Set the RAISEMOD flag to ensure that the modem lines are raised
373 ** on reception of a config packet.
374 ** The download code handles the zero baud condition.
375 */
Jiri Slabyd6f63412008-04-30 00:53:57 -0700376 Cor4 |= RIOC_COR4_RAISEMOD;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
378 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800379 ** COR 5
380 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Jiri Slabyd6f63412008-04-30 00:53:57 -0700382 Cor5 = RIOC_COR5_CMOE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
384 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800385 ** Set to monitor tbusy/tstop (or not).
386 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
388 if (PortP->MonitorTstate)
Jiri Slabyd6f63412008-04-30 00:53:57 -0700389 Cor5 |= RIOC_COR5_TSTATE_ON;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 else
Jiri Slabyd6f63412008-04-30 00:53:57 -0700391 Cor5 |= RIOC_COR5_TSTATE_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
393 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800394 ** Could set LNE here if you wanted LNext processing. SVR4 will use it.
395 */
396 if (TtyP->termios->c_iflag & ISTRIP) {
397 rio_dprintk(RIO_DEBUG_PARAM, "Strip input characters\n");
398 if (!(PortP->State & RIO_TRIAD_MODE)) {
Jiri Slabyd6f63412008-04-30 00:53:57 -0700399 Cor5 |= RIOC_COR5_ISTRIP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 }
401 }
402
Andrew Morton8d8706e2006-01-11 12:17:49 -0800403 if (TtyP->termios->c_oflag & ONLCR) {
404 rio_dprintk(RIO_DEBUG_PARAM, "Map newline to carriage-return, newline on output\n");
405 if (PortP->CookMode == COOK_MEDIUM)
Jiri Slabyd6f63412008-04-30 00:53:57 -0700406 Cor5 |= RIOC_COR5_ONLCR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800408 if (TtyP->termios->c_oflag & OCRNL) {
409 rio_dprintk(RIO_DEBUG_PARAM, "Map carriage return to newline on output\n");
410 if (PortP->CookMode == COOK_MEDIUM)
Jiri Slabyd6f63412008-04-30 00:53:57 -0700411 Cor5 |= RIOC_COR5_OCRNL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800413 if ((TtyP->termios->c_oflag & TABDLY) == TAB3) {
414 rio_dprintk(RIO_DEBUG_PARAM, "Tab delay 3 set\n");
415 if (PortP->CookMode == COOK_MEDIUM)
Jiri Slabyd6f63412008-04-30 00:53:57 -0700416 Cor5 |= RIOC_COR5_TAB3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 }
418
419 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800420 ** Flow control bytes.
421 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 TxXon = TtyP->termios->c_cc[VSTART];
423 TxXoff = TtyP->termios->c_cc[VSTOP];
424 RxXon = TtyP->termios->c_cc[VSTART];
425 RxXoff = TtyP->termios->c_cc[VSTOP];
426 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800427 ** LNEXT byte
428 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 LNext = 0;
430
431 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800432 ** Baud rate bytes
433 */
434 rio_dprintk(RIO_DEBUG_PARAM, "Mapping of rx/tx baud %x (%x)\n", TtyP->termios->c_cflag, CBAUD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
436 switch (TtyP->termios->c_cflag & CBAUD) {
437#define e(b) case B ## b : RxBaud = TxBaud = RIO_B ## b ;break
Andrew Morton8d8706e2006-01-11 12:17:49 -0800438 e(50);
439 e(75);
440 e(110);
441 e(134);
442 e(150);
443 e(200);
444 e(300);
445 e(600);
446 e(1200);
447 e(1800);
448 e(2400);
449 e(4800);
450 e(9600);
451 e(19200);
452 e(38400);
453 e(57600);
454 e(115200); /* e(230400);e(460800); e(921600); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 }
456
Andrew Morton8d8706e2006-01-11 12:17:49 -0800457 rio_dprintk(RIO_DEBUG_PARAM, "tx baud 0x%x, rx baud 0x%x\n", TxBaud, RxBaud);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
459
460 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800461 ** Leftovers
462 */
463 if (TtyP->termios->c_cflag & CREAD)
464 rio_dprintk(RIO_DEBUG_PARAM, "Enable receiver\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465#ifdef RCV1EN
Andrew Morton8d8706e2006-01-11 12:17:49 -0800466 if (TtyP->termios->c_cflag & RCV1EN)
467 rio_dprintk(RIO_DEBUG_PARAM, "RCV1EN (?)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468#endif
469#ifdef XMT1EN
Andrew Morton8d8706e2006-01-11 12:17:49 -0800470 if (TtyP->termios->c_cflag & XMT1EN)
471 rio_dprintk(RIO_DEBUG_PARAM, "XMT1EN (?)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -0800473 if (TtyP->termios->c_lflag & ISIG)
474 rio_dprintk(RIO_DEBUG_PARAM, "Input character signal generating enabled\n");
475 if (TtyP->termios->c_lflag & ICANON)
476 rio_dprintk(RIO_DEBUG_PARAM, "Canonical input: erase and kill enabled\n");
477 if (TtyP->termios->c_lflag & XCASE)
478 rio_dprintk(RIO_DEBUG_PARAM, "Canonical upper/lower presentation\n");
479 if (TtyP->termios->c_lflag & ECHO)
480 rio_dprintk(RIO_DEBUG_PARAM, "Enable input echo\n");
481 if (TtyP->termios->c_lflag & ECHOE)
482 rio_dprintk(RIO_DEBUG_PARAM, "Enable echo erase\n");
483 if (TtyP->termios->c_lflag & ECHOK)
484 rio_dprintk(RIO_DEBUG_PARAM, "Enable echo kill\n");
485 if (TtyP->termios->c_lflag & ECHONL)
486 rio_dprintk(RIO_DEBUG_PARAM, "Enable echo newline\n");
487 if (TtyP->termios->c_lflag & NOFLSH)
488 rio_dprintk(RIO_DEBUG_PARAM, "Disable flush after interrupt or quit\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489#ifdef TOSTOP
Andrew Morton8d8706e2006-01-11 12:17:49 -0800490 if (TtyP->termios->c_lflag & TOSTOP)
491 rio_dprintk(RIO_DEBUG_PARAM, "Send SIGTTOU for background output\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492#endif
493#ifdef XCLUDE
Andrew Morton8d8706e2006-01-11 12:17:49 -0800494 if (TtyP->termios->c_lflag & XCLUDE)
495 rio_dprintk(RIO_DEBUG_PARAM, "Exclusive use of this line\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -0800497 if (TtyP->termios->c_iflag & IUCLC)
498 rio_dprintk(RIO_DEBUG_PARAM, "Map uppercase to lowercase on input\n");
499 if (TtyP->termios->c_oflag & OPOST)
500 rio_dprintk(RIO_DEBUG_PARAM, "Enable output post-processing\n");
501 if (TtyP->termios->c_oflag & OLCUC)
502 rio_dprintk(RIO_DEBUG_PARAM, "Map lowercase to uppercase on output\n");
503 if (TtyP->termios->c_oflag & ONOCR)
504 rio_dprintk(RIO_DEBUG_PARAM, "No carriage return output at column 0\n");
505 if (TtyP->termios->c_oflag & ONLRET)
506 rio_dprintk(RIO_DEBUG_PARAM, "Newline performs carriage return function\n");
507 if (TtyP->termios->c_oflag & OFILL)
508 rio_dprintk(RIO_DEBUG_PARAM, "Use fill characters for delay\n");
509 if (TtyP->termios->c_oflag & OFDEL)
510 rio_dprintk(RIO_DEBUG_PARAM, "Fill character is DEL\n");
511 if (TtyP->termios->c_oflag & NLDLY)
512 rio_dprintk(RIO_DEBUG_PARAM, "Newline delay set\n");
513 if (TtyP->termios->c_oflag & CRDLY)
514 rio_dprintk(RIO_DEBUG_PARAM, "Carriage return delay set\n");
515 if (TtyP->termios->c_oflag & TABDLY)
516 rio_dprintk(RIO_DEBUG_PARAM, "Tab delay set\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800518 ** These things are kind of useful in a later life!
519 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 PortP->Cor2Copy = Cor2;
521
Andrew Morton8d8706e2006-01-11 12:17:49 -0800522 if (PortP->State & RIO_DELETED) {
523 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
524 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
526 return RIO_FAIL;
527 }
528
529 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800530 ** Actually write the info into the packet to be sent
531 */
Alan Coxe2b3afd2006-03-24 03:18:27 -0800532 writeb(cmd, &phb_param_ptr->Cmd);
533 writeb(Cor1, &phb_param_ptr->Cor1);
534 writeb(Cor2, &phb_param_ptr->Cor2);
535 writeb(Cor4, &phb_param_ptr->Cor4);
536 writeb(Cor5, &phb_param_ptr->Cor5);
537 writeb(TxXon, &phb_param_ptr->TxXon);
538 writeb(RxXon, &phb_param_ptr->RxXon);
539 writeb(TxXoff, &phb_param_ptr->TxXoff);
540 writeb(RxXoff, &phb_param_ptr->RxXoff);
541 writeb(LNext, &phb_param_ptr->LNext);
542 writeb(TxBaud, &phb_param_ptr->TxBaud);
543 writeb(RxBaud, &phb_param_ptr->RxBaud);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
545 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800546 ** Set the length/command field
547 */
Alan Coxe2b3afd2006-03-24 03:18:27 -0800548 writeb(12 | PKT_CMD_BIT, &PacketP->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
550 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800551 ** The packet is formed - now, whack it off
552 ** to its final destination:
553 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 add_transmit(PortP);
555 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800556 ** Count characters transmitted for port statistics reporting
557 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 if (PortP->statsGather)
559 PortP->txchars += 12;
560
Andrew Morton8d8706e2006-01-11 12:17:49 -0800561 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Andrew Morton8d8706e2006-01-11 12:17:49 -0800563 rio_dprintk(RIO_DEBUG_PARAM, "add_transmit returned.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800565 ** job done.
566 */
567 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Alan Cox554b7c82006-03-24 03:18:32 -0800569 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570}
571
572
573/*
574** We can add another packet to a transmit queue if the packet pointer pointed
575** to by the TxAdd pointer has PKT_IN_USE clear in its address.
576*/
Al Virod886cb52006-05-27 00:08:25 -0400577int can_add_transmit(struct PKT __iomem **PktP, struct Port *PortP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578{
Al Virod886cb52006-05-27 00:08:25 -0400579 struct PKT __iomem *tp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Al Virod886cb52006-05-27 00:08:25 -0400581 *PktP = tp = (struct PKT __iomem *) RIO_PTR(PortP->Caddr, readw(PortP->TxAdd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
Alan Coxe2b3afd2006-03-24 03:18:27 -0800583 return !((unsigned long) tp & PKT_IN_USE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584}
585
586/*
587** To add a packet to the queue, you set the PKT_IN_USE bit in the address,
588** and then move the TxAdd pointer along one position to point to the next
589** packet pointer. You must wrap the pointer from the end back to the start.
590*/
Alan Coxe2b3afd2006-03-24 03:18:27 -0800591void add_transmit(struct Port *PortP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592{
Alan Coxe2b3afd2006-03-24 03:18:27 -0800593 if (readw(PortP->TxAdd) & PKT_IN_USE) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800594 rio_dprintk(RIO_DEBUG_PARAM, "add_transmit: Packet has been stolen!");
595 }
Alan Coxe2b3afd2006-03-24 03:18:27 -0800596 writew(readw(PortP->TxAdd) | PKT_IN_USE, PortP->TxAdd);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800597 PortP->TxAdd = (PortP->TxAdd == PortP->TxEnd) ? PortP->TxStart : PortP->TxAdd + 1;
Alan Coxe2b3afd2006-03-24 03:18:27 -0800598 writew(RIO_OFF(PortP->Caddr, PortP->TxAdd), &PortP->PhbP->tx_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599}
600
601/****************************************
602 * Put a packet onto the end of the
603 * free list
604 ****************************************/
Al Virod886cb52006-05-27 00:08:25 -0400605void put_free_end(struct Host *HostP, struct PKT __iomem *PktP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606{
Al Virod886cb52006-05-27 00:08:25 -0400607 struct rio_free_list __iomem *tmp_pointer;
Alan Cox554b7c82006-03-24 03:18:32 -0800608 unsigned short old_end, new_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 unsigned long flags;
610
611 rio_spin_lock_irqsave(&HostP->HostLock, flags);
612
613 /*************************************************
614 * Put a packet back onto the back of the free list
615 *
616 ************************************************/
617
Alan Coxe2b3afd2006-03-24 03:18:27 -0800618 rio_dprintk(RIO_DEBUG_PFE, "put_free_end(PktP=%p)\n", PktP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Alan Coxe2b3afd2006-03-24 03:18:27 -0800620 if ((old_end = readw(&HostP->ParmMapP->free_list_end)) != TPNULL) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800621 new_end = RIO_OFF(HostP->Caddr, PktP);
Al Virod886cb52006-05-27 00:08:25 -0400622 tmp_pointer = (struct rio_free_list __iomem *) RIO_PTR(HostP->Caddr, old_end);
Alan Coxe2b3afd2006-03-24 03:18:27 -0800623 writew(new_end, &tmp_pointer->next);
Al Virod886cb52006-05-27 00:08:25 -0400624 writew(old_end, &((struct rio_free_list __iomem *) PktP)->prev);
625 writew(TPNULL, &((struct rio_free_list __iomem *) PktP)->next);
Alan Coxe2b3afd2006-03-24 03:18:27 -0800626 writew(new_end, &HostP->ParmMapP->free_list_end);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800627 } else { /* First packet on the free list this should never happen! */
628 rio_dprintk(RIO_DEBUG_PFE, "put_free_end(): This should never happen\n");
Alan Coxe2b3afd2006-03-24 03:18:27 -0800629 writew(RIO_OFF(HostP->Caddr, PktP), &HostP->ParmMapP->free_list_end);
Al Virod886cb52006-05-27 00:08:25 -0400630 tmp_pointer = (struct rio_free_list __iomem *) PktP;
Alan Coxe2b3afd2006-03-24 03:18:27 -0800631 writew(TPNULL, &tmp_pointer->prev);
632 writew(TPNULL, &tmp_pointer->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800634 rio_dprintk(RIO_DEBUG_CMD, "Before unlock: %p\n", &HostP->HostLock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
636}
637
638/*
639** can_remove_receive(PktP,P) returns non-zero if PKT_IN_USE is set
640** for the next packet on the queue. It will also set PktP to point to the
641** relevant packet, [having cleared the PKT_IN_USE bit]. If PKT_IN_USE is clear,
642** then can_remove_receive() returns 0.
643*/
Al Virod886cb52006-05-27 00:08:25 -0400644int can_remove_receive(struct PKT __iomem **PktP, struct Port *PortP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645{
Alan Coxe2b3afd2006-03-24 03:18:27 -0800646 if (readw(PortP->RxRemove) & PKT_IN_USE) {
Al Virod886cb52006-05-27 00:08:25 -0400647 *PktP = (struct PKT __iomem *) RIO_PTR(PortP->Caddr, readw(PortP->RxRemove) & ~PKT_IN_USE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 return 1;
649 }
650 return 0;
651}
652
653/*
654** To remove a packet from the receive queue you clear its PKT_IN_USE bit,
655** and then bump the pointers. Once the pointers get to the end, they must
656** be wrapped back to the start.
657*/
Alan Coxe2b3afd2006-03-24 03:18:27 -0800658void remove_receive(struct Port *PortP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659{
Alan Coxe2b3afd2006-03-24 03:18:27 -0800660 writew(readw(PortP->RxRemove) & ~PKT_IN_USE, PortP->RxRemove);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800661 PortP->RxRemove = (PortP->RxRemove == PortP->RxEnd) ? PortP->RxStart : PortP->RxRemove + 1;
Alan Coxe2b3afd2006-03-24 03:18:27 -0800662 writew(RIO_OFF(PortP->Caddr, PortP->RxRemove), &PortP->PhbP->rx_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663}