blob: d2e8092cdb294dafa7b16435342d8bb8b8c58ffd [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
33#ifdef SCCS_LABELS
34static 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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include "pkt.h"
56#include "daemon.h"
57#include "rio.h"
58#include "riospace.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#include "cmdpkt.h"
60#include "map.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#include "rup.h"
62#include "port.h"
63#include "riodrvr.h"
64#include "rioinfo.h"
65#include "func.h"
66#include "errors.h"
67#include "pci.h"
68
69#include "parmmap.h"
70#include "unixrup.h"
71#include "board.h"
72#include "host.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#include "phb.h"
74#include "link.h"
75#include "cmdblk.h"
76#include "route.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#include "cirrus.h"
78#include "rioioctl.h"
79#include "param.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81
82
83/*
84** The Scam, based on email from jeremyr@bugs.specialix.co.uk....
85**
86** To send a command on a particular port, you put a packet with the
87** command bit set onto the port. The command bit is in the len field,
88** and gets ORed in with the actual byte count.
89**
90** When you send a packet with the command bit set, then the first
91** data byte ( data[0] ) is interpretted as the command to execute.
92** It also governs what data structure overlay should accompany the packet.
93** Commands are defined in cirrus/cirrus.h
94**
95** If you want the command to pre-emt data already on the queue for the
96** port, set the pre-emptive bit in conjunction with the command bit.
97** It is not defined what will happen if you set the preemptive bit
98** on a packet that is NOT a command.
99**
100** Pre-emptive commands should be queued at the head of the queue using
101** add_start(), whereas normal commands and data are enqueued using
102** add_end().
103**
104** Most commands do not use the remaining bytes in the data array. The
105** exceptions are OPEN MOPEN and CONFIG. (NB. As with the SI CONFIG and
106** OPEN are currently analagous). With these three commands the following
107** 11 data bytes are all used to pass config information such as baud rate etc.
108** The fields are also defined in cirrus.h. Some contain straightforward
109** information such as the transmit XON character. Two contain the transmit and
110** receive baud rates respectively. For most baud rates there is a direct
111** mapping between the rates defined in <sys/termio.h> and the byte in the
112** packet. There are additional (non UNIX-standard) rates defined in
113** /u/dos/rio/cirrus/h/brates.h.
114**
115** The rest of the data fields contain approximations to the Cirrus registers
116** that are used to program number of bits etc. Each registers bit fields is
117** defined in cirrus.h.
118**
119** NB. Only use those bits that are defined as being driver specific
120** or common to the RTA and the driver.
121**
122** All commands going from RTA->Host will be dealt with by the Host code - you
123** will never see them. As with the SI there will be three fields to look out
124** for in each phb (not yet defined - needs defining a.s.a.p).
125**
126** modem_status - current state of handshake pins.
127**
128** port_status - current port status - equivalent to hi_stat for SI, indicates
129** if port is IDLE_OPEN, IDLE_CLOSED etc.
130**
131** break_status - bit X set if break has been received.
132**
133** Happy hacking.
134**
135*/
136
137/*
138** RIOParam is used to open or configure a port. You pass it a PortP,
139** which will have a tty struct attached to it. You also pass a command,
140** either OPEN or CONFIG. The port's setup is taken from the t_ fields
141** of the tty struct inside the PortP, and the port is either opened
142** or re-configured. You must also tell RIOParam if the device is a modem
143** device or not (i.e. top bit of minor number set or clear - take special
144** care when deciding on this!).
145** RIOParam neither flushes nor waits for drain, and is NOT preemptive.
146**
147** RIOParam assumes it will be called at splrio(), and also assumes
148** that CookMode is set correctly in the port structure.
149**
150** NB. for MPX
151** tty lock must NOT have been previously acquired.
152*/
Alan Coxe2b3afd2006-03-24 03:18:27 -0800153int RIOParam(struct Port *PortP, int cmd, int Modem, int SleepFlag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Alan Coxe2b3afd2006-03-24 03:18:27 -0800155 struct tty_struct *TtyP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800156 int retval;
Alan Coxe2b3afd2006-03-24 03:18:27 -0800157 struct phb_param *phb_param_ptr;
Alan Cox554b7c82006-03-24 03:18:32 -0800158 struct PKT *PacketP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 int res;
Alan Coxe2b3afd2006-03-24 03:18:27 -0800160 u8 Cor1 = 0, Cor2 = 0, Cor4 = 0, Cor5 = 0;
161 u8 TxXon = 0, TxXoff = 0, RxXon = 0, RxXoff = 0;
162 u8 LNext = 0, TxBaud = 0, RxBaud = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800163 int retries = 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 unsigned long flags;
165
Andrew Morton8d8706e2006-01-11 12:17:49 -0800166 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168 TtyP = PortP->gs.tty;
169
Andrew Morton8d8706e2006-01-11 12:17:49 -0800170 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 -0700171
172 if (!TtyP) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800173 rio_dprintk(RIO_DEBUG_PARAM, "Can't call rioparam with null tty.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Andrew Morton8d8706e2006-01-11 12:17:49 -0800175 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Andrew Morton8d8706e2006-01-11 12:17:49 -0800177 return RIO_FAIL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800179 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181 if (cmd == OPEN) {
182 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800183 ** If the port is set to store or lock the parameters, and it is
184 ** paramed with OPEN, we want to restore the saved port termio, but
185 ** only if StoredTermio has been saved, i.e. NOT 1st open after reboot.
186 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 }
188
189 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800190 ** wait for space
191 */
192 while (!(res = can_add_transmit(&PacketP, PortP)) || (PortP->InUse != NOT_INUSE)) {
193 if (retries-- <= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 break;
195 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800196 if (PortP->InUse != NOT_INUSE) {
197 rio_dprintk(RIO_DEBUG_PARAM, "Port IN_USE for pre-emptive command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 }
199
Andrew Morton8d8706e2006-01-11 12:17:49 -0800200 if (!res) {
201 rio_dprintk(RIO_DEBUG_PARAM, "Port has no space on transmit queue\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 }
203
Andrew Morton8d8706e2006-01-11 12:17:49 -0800204 if (SleepFlag != OK_TO_SLEEP) {
205 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 func_exit();
Andrew Morton8d8706e2006-01-11 12:17:49 -0800207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 return RIO_FAIL;
209 }
210
Andrew Morton8d8706e2006-01-11 12:17:49 -0800211 rio_dprintk(RIO_DEBUG_PARAM, "wait for can_add_transmit\n");
212 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 retval = RIODelay(PortP, HUNDRED_MS);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800214 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 if (retval == RIO_FAIL) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800216 rio_dprintk(RIO_DEBUG_PARAM, "wait for can_add_transmit broken by signal\n");
217 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 func_exit();
Alan Coxe2b3afd2006-03-24 03:18:27 -0800219 return -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800221 if (PortP->State & RIO_DELETED) {
222 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
223 func_exit();
Alan Cox554b7c82006-03-24 03:18:32 -0800224 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 }
226 }
227
228 if (!res) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800229 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
230 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 return RIO_FAIL;
233 }
234
Andrew Morton8d8706e2006-01-11 12:17:49 -0800235 rio_dprintk(RIO_DEBUG_PARAM, "can_add_transmit() returns %x\n", res);
Alan Cox554b7c82006-03-24 03:18:32 -0800236 rio_dprintk(RIO_DEBUG_PARAM, "Packet is %p\n", PacketP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Andrew Morton8d8706e2006-01-11 12:17:49 -0800238 phb_param_ptr = (struct phb_param *) PacketP->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240
Andrew Morton8d8706e2006-01-11 12:17:49 -0800241 switch (TtyP->termios->c_cflag & CSIZE) {
242 case CS5:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800244 rio_dprintk(RIO_DEBUG_PARAM, "5 bit data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 Cor1 |= COR1_5BITS;
246 break;
247 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800248 case CS6:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800250 rio_dprintk(RIO_DEBUG_PARAM, "6 bit data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 Cor1 |= COR1_6BITS;
252 break;
253 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800254 case CS7:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800256 rio_dprintk(RIO_DEBUG_PARAM, "7 bit data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 Cor1 |= COR1_7BITS;
258 break;
259 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800260 case CS8:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800262 rio_dprintk(RIO_DEBUG_PARAM, "8 bit data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 Cor1 |= COR1_8BITS;
264 break;
265 }
266 }
267
Andrew Morton8d8706e2006-01-11 12:17:49 -0800268 if (TtyP->termios->c_cflag & CSTOPB) {
269 rio_dprintk(RIO_DEBUG_PARAM, "2 stop bits\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 Cor1 |= COR1_2STOP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800271 } else {
272 rio_dprintk(RIO_DEBUG_PARAM, "1 stop bit\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 Cor1 |= COR1_1STOP;
274 }
275
Andrew Morton8d8706e2006-01-11 12:17:49 -0800276 if (TtyP->termios->c_cflag & PARENB) {
277 rio_dprintk(RIO_DEBUG_PARAM, "Enable parity\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 Cor1 |= COR1_NORMAL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800279 } else {
280 rio_dprintk(RIO_DEBUG_PARAM, "Disable parity\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 Cor1 |= COR1_NOP;
282 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800283 if (TtyP->termios->c_cflag & PARODD) {
284 rio_dprintk(RIO_DEBUG_PARAM, "Odd parity\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 Cor1 |= COR1_ODD;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800286 } else {
287 rio_dprintk(RIO_DEBUG_PARAM, "Even parity\n");
288 Cor1 |= COR1_EVEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 }
290
291 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800292 ** COR 2
293 */
294 if (TtyP->termios->c_iflag & IXON) {
295 rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop output control\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 Cor2 |= COR2_IXON;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800297 } else {
298 if (PortP->Config & RIO_IXON) {
299 rio_dprintk(RIO_DEBUG_PARAM, "Force enable start/stop output control\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 Cor2 |= COR2_IXON;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800301 } else
302 rio_dprintk(RIO_DEBUG_PARAM, "IXON has been disabled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 }
304
305 if (TtyP->termios->c_iflag & IXANY) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800306 if (PortP->Config & RIO_IXANY) {
307 rio_dprintk(RIO_DEBUG_PARAM, "Enable any key to restart output\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 Cor2 |= COR2_IXANY;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800309 } else
310 rio_dprintk(RIO_DEBUG_PARAM, "IXANY has been disabled due to sanity reasons.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 }
312
Andrew Morton8d8706e2006-01-11 12:17:49 -0800313 if (TtyP->termios->c_iflag & IXOFF) {
314 rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop input control 2\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 Cor2 |= COR2_IXOFF;
316 }
317
Andrew Morton8d8706e2006-01-11 12:17:49 -0800318 if (TtyP->termios->c_cflag & HUPCL) {
319 rio_dprintk(RIO_DEBUG_PARAM, "Hangup on last close\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 Cor2 |= COR2_HUPCL;
321 }
322
Andrew Morton8d8706e2006-01-11 12:17:49 -0800323 if (C_CRTSCTS(TtyP)) {
324 rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control enabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 Cor2 |= COR2_CTSFLOW;
326 Cor2 |= COR2_RTSFLOW;
327 } else {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800328 rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control disabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 Cor2 &= ~COR2_CTSFLOW;
330 Cor2 &= ~COR2_RTSFLOW;
331 }
332
333
Andrew Morton8d8706e2006-01-11 12:17:49 -0800334 if (TtyP->termios->c_cflag & CLOCAL) {
335 rio_dprintk(RIO_DEBUG_PARAM, "Local line\n");
336 } else {
337 rio_dprintk(RIO_DEBUG_PARAM, "Possible Modem line\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 }
339
340 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800341 ** COR 4 (there is no COR 3)
342 */
343 if (TtyP->termios->c_iflag & IGNBRK) {
344 rio_dprintk(RIO_DEBUG_PARAM, "Ignore break condition\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 Cor4 |= COR4_IGNBRK;
346 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800347 if (!(TtyP->termios->c_iflag & BRKINT)) {
348 rio_dprintk(RIO_DEBUG_PARAM, "Break generates NULL condition\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 Cor4 |= COR4_NBRKINT;
350 } else {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800351 rio_dprintk(RIO_DEBUG_PARAM, "Interrupt on break condition\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 }
353
Andrew Morton8d8706e2006-01-11 12:17:49 -0800354 if (TtyP->termios->c_iflag & INLCR) {
355 rio_dprintk(RIO_DEBUG_PARAM, "Map newline to carriage return on input\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 Cor4 |= COR4_INLCR;
357 }
358
Andrew Morton8d8706e2006-01-11 12:17:49 -0800359 if (TtyP->termios->c_iflag & IGNCR) {
360 rio_dprintk(RIO_DEBUG_PARAM, "Ignore carriage return on input\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 Cor4 |= COR4_IGNCR;
362 }
363
Andrew Morton8d8706e2006-01-11 12:17:49 -0800364 if (TtyP->termios->c_iflag & ICRNL) {
365 rio_dprintk(RIO_DEBUG_PARAM, "Map carriage return to newline on input\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 Cor4 |= COR4_ICRNL;
367 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800368 if (TtyP->termios->c_iflag & IGNPAR) {
369 rio_dprintk(RIO_DEBUG_PARAM, "Ignore characters with parity errors\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 Cor4 |= COR4_IGNPAR;
371 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800372 if (TtyP->termios->c_iflag & PARMRK) {
373 rio_dprintk(RIO_DEBUG_PARAM, "Mark parity errors\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 Cor4 |= COR4_PARMRK;
375 }
376
377 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800378 ** Set the RAISEMOD flag to ensure that the modem lines are raised
379 ** on reception of a config packet.
380 ** The download code handles the zero baud condition.
381 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 Cor4 |= COR4_RAISEMOD;
383
384 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800385 ** COR 5
386 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
388 Cor5 = COR5_CMOE;
389
390 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800391 ** Set to monitor tbusy/tstop (or not).
392 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
394 if (PortP->MonitorTstate)
395 Cor5 |= COR5_TSTATE_ON;
396 else
397 Cor5 |= COR5_TSTATE_OFF;
398
399 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800400 ** Could set LNE here if you wanted LNext processing. SVR4 will use it.
401 */
402 if (TtyP->termios->c_iflag & ISTRIP) {
403 rio_dprintk(RIO_DEBUG_PARAM, "Strip input characters\n");
404 if (!(PortP->State & RIO_TRIAD_MODE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 Cor5 |= COR5_ISTRIP;
406 }
407 }
408
Andrew Morton8d8706e2006-01-11 12:17:49 -0800409 if (TtyP->termios->c_oflag & ONLCR) {
410 rio_dprintk(RIO_DEBUG_PARAM, "Map newline to carriage-return, newline on output\n");
411 if (PortP->CookMode == COOK_MEDIUM)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 Cor5 |= COR5_ONLCR;
413 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800414 if (TtyP->termios->c_oflag & OCRNL) {
415 rio_dprintk(RIO_DEBUG_PARAM, "Map carriage return to newline on output\n");
416 if (PortP->CookMode == COOK_MEDIUM)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 Cor5 |= COR5_OCRNL;
418 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800419 if ((TtyP->termios->c_oflag & TABDLY) == TAB3) {
420 rio_dprintk(RIO_DEBUG_PARAM, "Tab delay 3 set\n");
421 if (PortP->CookMode == COOK_MEDIUM)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 Cor5 |= COR5_TAB3;
423 }
424
425 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800426 ** Flow control bytes.
427 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 TxXon = TtyP->termios->c_cc[VSTART];
429 TxXoff = TtyP->termios->c_cc[VSTOP];
430 RxXon = TtyP->termios->c_cc[VSTART];
431 RxXoff = TtyP->termios->c_cc[VSTOP];
432 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800433 ** LNEXT byte
434 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 LNext = 0;
436
437 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800438 ** Baud rate bytes
439 */
440 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 -0700441
442 switch (TtyP->termios->c_cflag & CBAUD) {
443#define e(b) case B ## b : RxBaud = TxBaud = RIO_B ## b ;break
Andrew Morton8d8706e2006-01-11 12:17:49 -0800444 e(50);
445 e(75);
446 e(110);
447 e(134);
448 e(150);
449 e(200);
450 e(300);
451 e(600);
452 e(1200);
453 e(1800);
454 e(2400);
455 e(4800);
456 e(9600);
457 e(19200);
458 e(38400);
459 e(57600);
460 e(115200); /* e(230400);e(460800); e(921600); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 }
462
Andrew Morton8d8706e2006-01-11 12:17:49 -0800463 rio_dprintk(RIO_DEBUG_PARAM, "tx baud 0x%x, rx baud 0x%x\n", TxBaud, RxBaud);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
465
466 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800467 ** Leftovers
468 */
469 if (TtyP->termios->c_cflag & CREAD)
470 rio_dprintk(RIO_DEBUG_PARAM, "Enable receiver\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471#ifdef RCV1EN
Andrew Morton8d8706e2006-01-11 12:17:49 -0800472 if (TtyP->termios->c_cflag & RCV1EN)
473 rio_dprintk(RIO_DEBUG_PARAM, "RCV1EN (?)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474#endif
475#ifdef XMT1EN
Andrew Morton8d8706e2006-01-11 12:17:49 -0800476 if (TtyP->termios->c_cflag & XMT1EN)
477 rio_dprintk(RIO_DEBUG_PARAM, "XMT1EN (?)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -0800479 if (TtyP->termios->c_lflag & ISIG)
480 rio_dprintk(RIO_DEBUG_PARAM, "Input character signal generating enabled\n");
481 if (TtyP->termios->c_lflag & ICANON)
482 rio_dprintk(RIO_DEBUG_PARAM, "Canonical input: erase and kill enabled\n");
483 if (TtyP->termios->c_lflag & XCASE)
484 rio_dprintk(RIO_DEBUG_PARAM, "Canonical upper/lower presentation\n");
485 if (TtyP->termios->c_lflag & ECHO)
486 rio_dprintk(RIO_DEBUG_PARAM, "Enable input echo\n");
487 if (TtyP->termios->c_lflag & ECHOE)
488 rio_dprintk(RIO_DEBUG_PARAM, "Enable echo erase\n");
489 if (TtyP->termios->c_lflag & ECHOK)
490 rio_dprintk(RIO_DEBUG_PARAM, "Enable echo kill\n");
491 if (TtyP->termios->c_lflag & ECHONL)
492 rio_dprintk(RIO_DEBUG_PARAM, "Enable echo newline\n");
493 if (TtyP->termios->c_lflag & NOFLSH)
494 rio_dprintk(RIO_DEBUG_PARAM, "Disable flush after interrupt or quit\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495#ifdef TOSTOP
Andrew Morton8d8706e2006-01-11 12:17:49 -0800496 if (TtyP->termios->c_lflag & TOSTOP)
497 rio_dprintk(RIO_DEBUG_PARAM, "Send SIGTTOU for background output\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498#endif
499#ifdef XCLUDE
Andrew Morton8d8706e2006-01-11 12:17:49 -0800500 if (TtyP->termios->c_lflag & XCLUDE)
501 rio_dprintk(RIO_DEBUG_PARAM, "Exclusive use of this line\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -0800503 if (TtyP->termios->c_iflag & IUCLC)
504 rio_dprintk(RIO_DEBUG_PARAM, "Map uppercase to lowercase on input\n");
505 if (TtyP->termios->c_oflag & OPOST)
506 rio_dprintk(RIO_DEBUG_PARAM, "Enable output post-processing\n");
507 if (TtyP->termios->c_oflag & OLCUC)
508 rio_dprintk(RIO_DEBUG_PARAM, "Map lowercase to uppercase on output\n");
509 if (TtyP->termios->c_oflag & ONOCR)
510 rio_dprintk(RIO_DEBUG_PARAM, "No carriage return output at column 0\n");
511 if (TtyP->termios->c_oflag & ONLRET)
512 rio_dprintk(RIO_DEBUG_PARAM, "Newline performs carriage return function\n");
513 if (TtyP->termios->c_oflag & OFILL)
514 rio_dprintk(RIO_DEBUG_PARAM, "Use fill characters for delay\n");
515 if (TtyP->termios->c_oflag & OFDEL)
516 rio_dprintk(RIO_DEBUG_PARAM, "Fill character is DEL\n");
517 if (TtyP->termios->c_oflag & NLDLY)
518 rio_dprintk(RIO_DEBUG_PARAM, "Newline delay set\n");
519 if (TtyP->termios->c_oflag & CRDLY)
520 rio_dprintk(RIO_DEBUG_PARAM, "Carriage return delay set\n");
521 if (TtyP->termios->c_oflag & TABDLY)
522 rio_dprintk(RIO_DEBUG_PARAM, "Tab delay set\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800524 ** These things are kind of useful in a later life!
525 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 PortP->Cor2Copy = Cor2;
527
Andrew Morton8d8706e2006-01-11 12:17:49 -0800528 if (PortP->State & RIO_DELETED) {
529 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
530 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
532 return RIO_FAIL;
533 }
534
535 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800536 ** Actually write the info into the packet to be sent
537 */
Alan Coxe2b3afd2006-03-24 03:18:27 -0800538 writeb(cmd, &phb_param_ptr->Cmd);
539 writeb(Cor1, &phb_param_ptr->Cor1);
540 writeb(Cor2, &phb_param_ptr->Cor2);
541 writeb(Cor4, &phb_param_ptr->Cor4);
542 writeb(Cor5, &phb_param_ptr->Cor5);
543 writeb(TxXon, &phb_param_ptr->TxXon);
544 writeb(RxXon, &phb_param_ptr->RxXon);
545 writeb(TxXoff, &phb_param_ptr->TxXoff);
546 writeb(RxXoff, &phb_param_ptr->RxXoff);
547 writeb(LNext, &phb_param_ptr->LNext);
548 writeb(TxBaud, &phb_param_ptr->TxBaud);
549 writeb(RxBaud, &phb_param_ptr->RxBaud);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
551 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800552 ** Set the length/command field
553 */
Alan Coxe2b3afd2006-03-24 03:18:27 -0800554 writeb(12 | PKT_CMD_BIT, &PacketP->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
556 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800557 ** The packet is formed - now, whack it off
558 ** to its final destination:
559 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 add_transmit(PortP);
561 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800562 ** Count characters transmitted for port statistics reporting
563 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 if (PortP->statsGather)
565 PortP->txchars += 12;
566
Andrew Morton8d8706e2006-01-11 12:17:49 -0800567 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Andrew Morton8d8706e2006-01-11 12:17:49 -0800569 rio_dprintk(RIO_DEBUG_PARAM, "add_transmit returned.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800571 ** job done.
572 */
573 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
Alan Cox554b7c82006-03-24 03:18:32 -0800575 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576}
577
578
579/*
580** We can add another packet to a transmit queue if the packet pointer pointed
581** to by the TxAdd pointer has PKT_IN_USE clear in its address.
582*/
Alan Cox554b7c82006-03-24 03:18:32 -0800583int can_add_transmit(struct PKT **PktP, struct Port *PortP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
Alan Cox554b7c82006-03-24 03:18:32 -0800585 struct PKT *tp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
Alan Cox554b7c82006-03-24 03:18:32 -0800587 *PktP = tp = (struct PKT *) RIO_PTR(PortP->Caddr, readw(PortP->TxAdd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Alan Coxe2b3afd2006-03-24 03:18:27 -0800589 return !((unsigned long) tp & PKT_IN_USE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590}
591
592/*
593** To add a packet to the queue, you set the PKT_IN_USE bit in the address,
594** and then move the TxAdd pointer along one position to point to the next
595** packet pointer. You must wrap the pointer from the end back to the start.
596*/
Alan Coxe2b3afd2006-03-24 03:18:27 -0800597void add_transmit(struct Port *PortP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598{
Alan Coxe2b3afd2006-03-24 03:18:27 -0800599 if (readw(PortP->TxAdd) & PKT_IN_USE) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800600 rio_dprintk(RIO_DEBUG_PARAM, "add_transmit: Packet has been stolen!");
601 }
Alan Coxe2b3afd2006-03-24 03:18:27 -0800602 writew(readw(PortP->TxAdd) | PKT_IN_USE, PortP->TxAdd);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800603 PortP->TxAdd = (PortP->TxAdd == PortP->TxEnd) ? PortP->TxStart : PortP->TxAdd + 1;
Alan Coxe2b3afd2006-03-24 03:18:27 -0800604 writew(RIO_OFF(PortP->Caddr, PortP->TxAdd), &PortP->PhbP->tx_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605}
606
607/****************************************
608 * Put a packet onto the end of the
609 * free list
610 ****************************************/
Alan Cox554b7c82006-03-24 03:18:32 -0800611void put_free_end(struct Host *HostP, struct PKT *PktP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612{
Alan Cox554b7c82006-03-24 03:18:32 -0800613 struct rio_free_list *tmp_pointer;
614 unsigned short old_end, new_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 unsigned long flags;
616
617 rio_spin_lock_irqsave(&HostP->HostLock, flags);
618
619 /*************************************************
620 * Put a packet back onto the back of the free list
621 *
622 ************************************************/
623
Alan Coxe2b3afd2006-03-24 03:18:27 -0800624 rio_dprintk(RIO_DEBUG_PFE, "put_free_end(PktP=%p)\n", PktP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
Alan Coxe2b3afd2006-03-24 03:18:27 -0800626 if ((old_end = readw(&HostP->ParmMapP->free_list_end)) != TPNULL) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800627 new_end = RIO_OFF(HostP->Caddr, PktP);
Alan Cox554b7c82006-03-24 03:18:32 -0800628 tmp_pointer = (struct rio_free_list *) RIO_PTR(HostP->Caddr, old_end);
Alan Coxe2b3afd2006-03-24 03:18:27 -0800629 writew(new_end, &tmp_pointer->next);
Alan Cox554b7c82006-03-24 03:18:32 -0800630 writew(old_end, &((struct rio_free_list *) PktP)->prev);
631 writew(TPNULL, &((struct rio_free_list *) PktP)->next);
Alan Coxe2b3afd2006-03-24 03:18:27 -0800632 writew(new_end, &HostP->ParmMapP->free_list_end);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800633 } else { /* First packet on the free list this should never happen! */
634 rio_dprintk(RIO_DEBUG_PFE, "put_free_end(): This should never happen\n");
Alan Coxe2b3afd2006-03-24 03:18:27 -0800635 writew(RIO_OFF(HostP->Caddr, PktP), &HostP->ParmMapP->free_list_end);
Alan Cox554b7c82006-03-24 03:18:32 -0800636 tmp_pointer = (struct rio_free_list *) PktP;
Alan Coxe2b3afd2006-03-24 03:18:27 -0800637 writew(TPNULL, &tmp_pointer->prev);
638 writew(TPNULL, &tmp_pointer->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800640 rio_dprintk(RIO_DEBUG_CMD, "Before unlock: %p\n", &HostP->HostLock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
642}
643
644/*
645** can_remove_receive(PktP,P) returns non-zero if PKT_IN_USE is set
646** for the next packet on the queue. It will also set PktP to point to the
647** relevant packet, [having cleared the PKT_IN_USE bit]. If PKT_IN_USE is clear,
648** then can_remove_receive() returns 0.
649*/
Alan Cox554b7c82006-03-24 03:18:32 -0800650int can_remove_receive(struct PKT **PktP, struct Port *PortP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651{
Alan Coxe2b3afd2006-03-24 03:18:27 -0800652 if (readw(PortP->RxRemove) & PKT_IN_USE) {
Alan Cox554b7c82006-03-24 03:18:32 -0800653 *PktP = (struct PKT *) RIO_PTR(PortP->Caddr, readw(PortP->RxRemove) & ~PKT_IN_USE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 return 1;
655 }
656 return 0;
657}
658
659/*
660** To remove a packet from the receive queue you clear its PKT_IN_USE bit,
661** and then bump the pointers. Once the pointers get to the end, they must
662** be wrapped back to the start.
663*/
Alan Coxe2b3afd2006-03-24 03:18:27 -0800664void remove_receive(struct Port *PortP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665{
Alan Coxe2b3afd2006-03-24 03:18:27 -0800666 writew(readw(PortP->RxRemove) & ~PKT_IN_USE, PortP->RxRemove);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800667 PortP->RxRemove = (PortP->RxRemove == PortP->RxEnd) ? PortP->RxStart : PortP->RxRemove + 1;
Alan Coxe2b3afd2006-03-24 03:18:27 -0800668 writew(RIO_OFF(PortP->Caddr, PortP->RxRemove), &PortP->PhbP->rx_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669}