blob: 4cc7f4942bfc969e2c4031fc7526fac365c08c55 [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"
55#include "typdef.h"
56#include "pkt.h"
57#include "daemon.h"
58#include "rio.h"
59#include "riospace.h"
60#include "top.h"
61#include "cmdpkt.h"
62#include "map.h"
63#include "riotypes.h"
64#include "rup.h"
65#include "port.h"
66#include "riodrvr.h"
67#include "rioinfo.h"
68#include "func.h"
69#include "errors.h"
70#include "pci.h"
71
72#include "parmmap.h"
73#include "unixrup.h"
74#include "board.h"
75#include "host.h"
76#include "error.h"
77#include "phb.h"
78#include "link.h"
79#include "cmdblk.h"
80#include "route.h"
81#include "control.h"
82#include "cirrus.h"
83#include "rioioctl.h"
84#include "param.h"
85#include "list.h"
86#include "sam.h"
87
88
89
90/*
91** The Scam, based on email from jeremyr@bugs.specialix.co.uk....
92**
93** To send a command on a particular port, you put a packet with the
94** command bit set onto the port. The command bit is in the len field,
95** and gets ORed in with the actual byte count.
96**
97** When you send a packet with the command bit set, then the first
98** data byte ( data[0] ) is interpretted as the command to execute.
99** It also governs what data structure overlay should accompany the packet.
100** Commands are defined in cirrus/cirrus.h
101**
102** If you want the command to pre-emt data already on the queue for the
103** port, set the pre-emptive bit in conjunction with the command bit.
104** It is not defined what will happen if you set the preemptive bit
105** on a packet that is NOT a command.
106**
107** Pre-emptive commands should be queued at the head of the queue using
108** add_start(), whereas normal commands and data are enqueued using
109** add_end().
110**
111** Most commands do not use the remaining bytes in the data array. The
112** exceptions are OPEN MOPEN and CONFIG. (NB. As with the SI CONFIG and
113** OPEN are currently analagous). With these three commands the following
114** 11 data bytes are all used to pass config information such as baud rate etc.
115** The fields are also defined in cirrus.h. Some contain straightforward
116** information such as the transmit XON character. Two contain the transmit and
117** receive baud rates respectively. For most baud rates there is a direct
118** mapping between the rates defined in <sys/termio.h> and the byte in the
119** packet. There are additional (non UNIX-standard) rates defined in
120** /u/dos/rio/cirrus/h/brates.h.
121**
122** The rest of the data fields contain approximations to the Cirrus registers
123** that are used to program number of bits etc. Each registers bit fields is
124** defined in cirrus.h.
125**
126** NB. Only use those bits that are defined as being driver specific
127** or common to the RTA and the driver.
128**
129** All commands going from RTA->Host will be dealt with by the Host code - you
130** will never see them. As with the SI there will be three fields to look out
131** for in each phb (not yet defined - needs defining a.s.a.p).
132**
133** modem_status - current state of handshake pins.
134**
135** port_status - current port status - equivalent to hi_stat for SI, indicates
136** if port is IDLE_OPEN, IDLE_CLOSED etc.
137**
138** break_status - bit X set if break has been received.
139**
140** Happy hacking.
141**
142*/
143
144/*
145** RIOParam is used to open or configure a port. You pass it a PortP,
146** which will have a tty struct attached to it. You also pass a command,
147** either OPEN or CONFIG. The port's setup is taken from the t_ fields
148** of the tty struct inside the PortP, and the port is either opened
149** or re-configured. You must also tell RIOParam if the device is a modem
150** device or not (i.e. top bit of minor number set or clear - take special
151** care when deciding on this!).
152** RIOParam neither flushes nor waits for drain, and is NOT preemptive.
153**
154** RIOParam assumes it will be called at splrio(), and also assumes
155** that CookMode is set correctly in the port structure.
156**
157** NB. for MPX
158** tty lock must NOT have been previously acquired.
159*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800160int RIOParam(PortP, cmd, Modem, SleepFlag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161struct Port *PortP;
162int cmd;
163int Modem;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800164int SleepFlag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
166 register struct tty_struct *TtyP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800167 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 register struct phb_param *phb_param_ptr;
169 PKT *PacketP;
170 int res;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800171 uchar Cor1 = 0, Cor2 = 0, Cor4 = 0, Cor5 = 0;
172 uchar TxXon = 0, TxXoff = 0, RxXon = 0, RxXoff = 0;
173 uchar LNext = 0, TxBaud = 0, RxBaud = 0;
174 int retries = 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 unsigned long flags;
176
Andrew Morton8d8706e2006-01-11 12:17:49 -0800177 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
179 TtyP = PortP->gs.tty;
180
Andrew Morton8d8706e2006-01-11 12:17:49 -0800181 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 -0700182
183 if (!TtyP) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800184 rio_dprintk(RIO_DEBUG_PARAM, "Can't call rioparam with null tty.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
Andrew Morton8d8706e2006-01-11 12:17:49 -0800186 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Andrew Morton8d8706e2006-01-11 12:17:49 -0800188 return RIO_FAIL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800190 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192 if (cmd == OPEN) {
193 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800194 ** If the port is set to store or lock the parameters, and it is
195 ** paramed with OPEN, we want to restore the saved port termio, but
196 ** only if StoredTermio has been saved, i.e. NOT 1st open after reboot.
197 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198#if 0
199 if (PortP->FirstOpen) {
200 PortP->StoredTty.iflag = TtyP->tm.c_iflag;
201 PortP->StoredTty.oflag = TtyP->tm.c_oflag;
202 PortP->StoredTty.cflag = TtyP->tm.c_cflag;
203 PortP->StoredTty.lflag = TtyP->tm.c_lflag;
204 PortP->StoredTty.line = TtyP->tm.c_line;
205 for (i = 0; i < NCC + 5; i++)
206 PortP->StoredTty.cc[i] = TtyP->tm.c_cc[i];
207 PortP->FirstOpen = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800208 } else if (PortP->Store || PortP->Lock) {
209 rio_dprintk(RIO_DEBUG_PARAM, "OPEN: Restoring stored/locked params\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 TtyP->tm.c_iflag = PortP->StoredTty.iflag;
211 TtyP->tm.c_oflag = PortP->StoredTty.oflag;
212 TtyP->tm.c_cflag = PortP->StoredTty.cflag;
213 TtyP->tm.c_lflag = PortP->StoredTty.lflag;
214 TtyP->tm.c_line = PortP->StoredTty.line;
215 for (i = 0; i < NCC + 5; i++)
216 TtyP->tm.c_cc[i] = PortP->StoredTty.cc[i];
217 }
218#endif
219 }
220
221 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800222 ** wait for space
223 */
224 while (!(res = can_add_transmit(&PacketP, PortP)) || (PortP->InUse != NOT_INUSE)) {
225 if (retries-- <= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 break;
227 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800228 if (PortP->InUse != NOT_INUSE) {
229 rio_dprintk(RIO_DEBUG_PARAM, "Port IN_USE for pre-emptive command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 }
231
Andrew Morton8d8706e2006-01-11 12:17:49 -0800232 if (!res) {
233 rio_dprintk(RIO_DEBUG_PARAM, "Port has no space on transmit queue\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 }
235
Andrew Morton8d8706e2006-01-11 12:17:49 -0800236 if (SleepFlag != OK_TO_SLEEP) {
237 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 func_exit();
Andrew Morton8d8706e2006-01-11 12:17:49 -0800239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 return RIO_FAIL;
241 }
242
Andrew Morton8d8706e2006-01-11 12:17:49 -0800243 rio_dprintk(RIO_DEBUG_PARAM, "wait for can_add_transmit\n");
244 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 retval = RIODelay(PortP, HUNDRED_MS);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800246 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 if (retval == RIO_FAIL) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800248 rio_dprintk(RIO_DEBUG_PARAM, "wait for can_add_transmit broken by signal\n");
249 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 pseterr(EINTR);
251 func_exit();
252
253 return RIO_FAIL;
254 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800255 if (PortP->State & RIO_DELETED) {
256 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
257 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
259 return RIO_SUCCESS;
260 }
261 }
262
263 if (!res) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800264 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
265 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267 return RIO_FAIL;
268 }
269
Andrew Morton8d8706e2006-01-11 12:17:49 -0800270 rio_dprintk(RIO_DEBUG_PARAM, "can_add_transmit() returns %x\n", res);
271 rio_dprintk(RIO_DEBUG_PARAM, "Packet is 0x%x\n", (int) PacketP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Andrew Morton8d8706e2006-01-11 12:17:49 -0800273 phb_param_ptr = (struct phb_param *) PacketP->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
275
276#if 0
277 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800278 ** COR 1
279 */
280 if (TtyP->tm.c_iflag & INPCK) {
281 rio_dprintk(RIO_DEBUG_PARAM, "Parity checking on input enabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 Cor1 |= COR1_INPCK;
283 }
284#endif
285
Andrew Morton8d8706e2006-01-11 12:17:49 -0800286 switch (TtyP->termios->c_cflag & CSIZE) {
287 case CS5:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800289 rio_dprintk(RIO_DEBUG_PARAM, "5 bit data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 Cor1 |= COR1_5BITS;
291 break;
292 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800293 case CS6:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800295 rio_dprintk(RIO_DEBUG_PARAM, "6 bit data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 Cor1 |= COR1_6BITS;
297 break;
298 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800299 case CS7:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800301 rio_dprintk(RIO_DEBUG_PARAM, "7 bit data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 Cor1 |= COR1_7BITS;
303 break;
304 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800305 case CS8:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800307 rio_dprintk(RIO_DEBUG_PARAM, "8 bit data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 Cor1 |= COR1_8BITS;
309 break;
310 }
311 }
312
Andrew Morton8d8706e2006-01-11 12:17:49 -0800313 if (TtyP->termios->c_cflag & CSTOPB) {
314 rio_dprintk(RIO_DEBUG_PARAM, "2 stop bits\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 Cor1 |= COR1_2STOP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800316 } else {
317 rio_dprintk(RIO_DEBUG_PARAM, "1 stop bit\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 Cor1 |= COR1_1STOP;
319 }
320
Andrew Morton8d8706e2006-01-11 12:17:49 -0800321 if (TtyP->termios->c_cflag & PARENB) {
322 rio_dprintk(RIO_DEBUG_PARAM, "Enable parity\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 Cor1 |= COR1_NORMAL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800324 } else {
325 rio_dprintk(RIO_DEBUG_PARAM, "Disable parity\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 Cor1 |= COR1_NOP;
327 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800328 if (TtyP->termios->c_cflag & PARODD) {
329 rio_dprintk(RIO_DEBUG_PARAM, "Odd parity\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 Cor1 |= COR1_ODD;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800331 } else {
332 rio_dprintk(RIO_DEBUG_PARAM, "Even parity\n");
333 Cor1 |= COR1_EVEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 }
335
336 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800337 ** COR 2
338 */
339 if (TtyP->termios->c_iflag & IXON) {
340 rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop output control\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 Cor2 |= COR2_IXON;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800342 } else {
343 if (PortP->Config & RIO_IXON) {
344 rio_dprintk(RIO_DEBUG_PARAM, "Force enable start/stop output control\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 Cor2 |= COR2_IXON;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800346 } else
347 rio_dprintk(RIO_DEBUG_PARAM, "IXON has been disabled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 }
349
350 if (TtyP->termios->c_iflag & IXANY) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800351 if (PortP->Config & RIO_IXANY) {
352 rio_dprintk(RIO_DEBUG_PARAM, "Enable any key to restart output\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 Cor2 |= COR2_IXANY;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800354 } else
355 rio_dprintk(RIO_DEBUG_PARAM, "IXANY has been disabled due to sanity reasons.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 }
357
Andrew Morton8d8706e2006-01-11 12:17:49 -0800358 if (TtyP->termios->c_iflag & IXOFF) {
359 rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop input control 2\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 Cor2 |= COR2_IXOFF;
361 }
362
Andrew Morton8d8706e2006-01-11 12:17:49 -0800363 if (TtyP->termios->c_cflag & HUPCL) {
364 rio_dprintk(RIO_DEBUG_PARAM, "Hangup on last close\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 Cor2 |= COR2_HUPCL;
366 }
367
Andrew Morton8d8706e2006-01-11 12:17:49 -0800368 if (C_CRTSCTS(TtyP)) {
369 rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control enabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 Cor2 |= COR2_CTSFLOW;
371 Cor2 |= COR2_RTSFLOW;
372 } else {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800373 rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control disabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 Cor2 &= ~COR2_CTSFLOW;
375 Cor2 &= ~COR2_RTSFLOW;
376 }
377
378
Andrew Morton8d8706e2006-01-11 12:17:49 -0800379 if (TtyP->termios->c_cflag & CLOCAL) {
380 rio_dprintk(RIO_DEBUG_PARAM, "Local line\n");
381 } else {
382 rio_dprintk(RIO_DEBUG_PARAM, "Possible Modem line\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 }
384
385 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800386 ** COR 4 (there is no COR 3)
387 */
388 if (TtyP->termios->c_iflag & IGNBRK) {
389 rio_dprintk(RIO_DEBUG_PARAM, "Ignore break condition\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 Cor4 |= COR4_IGNBRK;
391 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800392 if (!(TtyP->termios->c_iflag & BRKINT)) {
393 rio_dprintk(RIO_DEBUG_PARAM, "Break generates NULL condition\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 Cor4 |= COR4_NBRKINT;
395 } else {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800396 rio_dprintk(RIO_DEBUG_PARAM, "Interrupt on break condition\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 }
398
Andrew Morton8d8706e2006-01-11 12:17:49 -0800399 if (TtyP->termios->c_iflag & INLCR) {
400 rio_dprintk(RIO_DEBUG_PARAM, "Map newline to carriage return on input\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 Cor4 |= COR4_INLCR;
402 }
403
Andrew Morton8d8706e2006-01-11 12:17:49 -0800404 if (TtyP->termios->c_iflag & IGNCR) {
405 rio_dprintk(RIO_DEBUG_PARAM, "Ignore carriage return on input\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 Cor4 |= COR4_IGNCR;
407 }
408
Andrew Morton8d8706e2006-01-11 12:17:49 -0800409 if (TtyP->termios->c_iflag & ICRNL) {
410 rio_dprintk(RIO_DEBUG_PARAM, "Map carriage return to newline on input\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 Cor4 |= COR4_ICRNL;
412 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800413 if (TtyP->termios->c_iflag & IGNPAR) {
414 rio_dprintk(RIO_DEBUG_PARAM, "Ignore characters with parity errors\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 Cor4 |= COR4_IGNPAR;
416 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800417 if (TtyP->termios->c_iflag & PARMRK) {
418 rio_dprintk(RIO_DEBUG_PARAM, "Mark parity errors\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 Cor4 |= COR4_PARMRK;
420 }
421
422 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800423 ** Set the RAISEMOD flag to ensure that the modem lines are raised
424 ** on reception of a config packet.
425 ** The download code handles the zero baud condition.
426 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 Cor4 |= COR4_RAISEMOD;
428
429 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800430 ** COR 5
431 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
433 Cor5 = COR5_CMOE;
434
435 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800436 ** Set to monitor tbusy/tstop (or not).
437 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
439 if (PortP->MonitorTstate)
440 Cor5 |= COR5_TSTATE_ON;
441 else
442 Cor5 |= COR5_TSTATE_OFF;
443
444 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800445 ** Could set LNE here if you wanted LNext processing. SVR4 will use it.
446 */
447 if (TtyP->termios->c_iflag & ISTRIP) {
448 rio_dprintk(RIO_DEBUG_PARAM, "Strip input characters\n");
449 if (!(PortP->State & RIO_TRIAD_MODE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 Cor5 |= COR5_ISTRIP;
451 }
452 }
453
Andrew Morton8d8706e2006-01-11 12:17:49 -0800454 if (TtyP->termios->c_oflag & ONLCR) {
455 rio_dprintk(RIO_DEBUG_PARAM, "Map newline to carriage-return, newline on output\n");
456 if (PortP->CookMode == COOK_MEDIUM)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 Cor5 |= COR5_ONLCR;
458 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800459 if (TtyP->termios->c_oflag & OCRNL) {
460 rio_dprintk(RIO_DEBUG_PARAM, "Map carriage return to newline on output\n");
461 if (PortP->CookMode == COOK_MEDIUM)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 Cor5 |= COR5_OCRNL;
463 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800464 if ((TtyP->termios->c_oflag & TABDLY) == TAB3) {
465 rio_dprintk(RIO_DEBUG_PARAM, "Tab delay 3 set\n");
466 if (PortP->CookMode == COOK_MEDIUM)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 Cor5 |= COR5_TAB3;
468 }
469
470 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800471 ** Flow control bytes.
472 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 TxXon = TtyP->termios->c_cc[VSTART];
474 TxXoff = TtyP->termios->c_cc[VSTOP];
475 RxXon = TtyP->termios->c_cc[VSTART];
476 RxXoff = TtyP->termios->c_cc[VSTOP];
477 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800478 ** LNEXT byte
479 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 LNext = 0;
481
482 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800483 ** Baud rate bytes
484 */
485 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 -0700486
487 switch (TtyP->termios->c_cflag & CBAUD) {
488#define e(b) case B ## b : RxBaud = TxBaud = RIO_B ## b ;break
Andrew Morton8d8706e2006-01-11 12:17:49 -0800489 e(50);
490 e(75);
491 e(110);
492 e(134);
493 e(150);
494 e(200);
495 e(300);
496 e(600);
497 e(1200);
498 e(1800);
499 e(2400);
500 e(4800);
501 e(9600);
502 e(19200);
503 e(38400);
504 e(57600);
505 e(115200); /* e(230400);e(460800); e(921600); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 }
507
508 /* XXX MIssing conversion table. XXX */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800509 /* (TtyP->termios->c_cflag & V_CBAUD); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
Andrew Morton8d8706e2006-01-11 12:17:49 -0800511 rio_dprintk(RIO_DEBUG_PARAM, "tx baud 0x%x, rx baud 0x%x\n", TxBaud, RxBaud);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
513
514 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800515 ** Leftovers
516 */
517 if (TtyP->termios->c_cflag & CREAD)
518 rio_dprintk(RIO_DEBUG_PARAM, "Enable receiver\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519#ifdef RCV1EN
Andrew Morton8d8706e2006-01-11 12:17:49 -0800520 if (TtyP->termios->c_cflag & RCV1EN)
521 rio_dprintk(RIO_DEBUG_PARAM, "RCV1EN (?)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522#endif
523#ifdef XMT1EN
Andrew Morton8d8706e2006-01-11 12:17:49 -0800524 if (TtyP->termios->c_cflag & XMT1EN)
525 rio_dprintk(RIO_DEBUG_PARAM, "XMT1EN (?)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526#endif
527#if 0
Andrew Morton8d8706e2006-01-11 12:17:49 -0800528 if (TtyP->termios->c_cflag & LOBLK)
529 rio_dprintk(RIO_DEBUG_PARAM, "LOBLK - JCL output blocks when not current\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -0800531 if (TtyP->termios->c_lflag & ISIG)
532 rio_dprintk(RIO_DEBUG_PARAM, "Input character signal generating enabled\n");
533 if (TtyP->termios->c_lflag & ICANON)
534 rio_dprintk(RIO_DEBUG_PARAM, "Canonical input: erase and kill enabled\n");
535 if (TtyP->termios->c_lflag & XCASE)
536 rio_dprintk(RIO_DEBUG_PARAM, "Canonical upper/lower presentation\n");
537 if (TtyP->termios->c_lflag & ECHO)
538 rio_dprintk(RIO_DEBUG_PARAM, "Enable input echo\n");
539 if (TtyP->termios->c_lflag & ECHOE)
540 rio_dprintk(RIO_DEBUG_PARAM, "Enable echo erase\n");
541 if (TtyP->termios->c_lflag & ECHOK)
542 rio_dprintk(RIO_DEBUG_PARAM, "Enable echo kill\n");
543 if (TtyP->termios->c_lflag & ECHONL)
544 rio_dprintk(RIO_DEBUG_PARAM, "Enable echo newline\n");
545 if (TtyP->termios->c_lflag & NOFLSH)
546 rio_dprintk(RIO_DEBUG_PARAM, "Disable flush after interrupt or quit\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547#ifdef TOSTOP
Andrew Morton8d8706e2006-01-11 12:17:49 -0800548 if (TtyP->termios->c_lflag & TOSTOP)
549 rio_dprintk(RIO_DEBUG_PARAM, "Send SIGTTOU for background output\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550#endif
551#ifdef XCLUDE
Andrew Morton8d8706e2006-01-11 12:17:49 -0800552 if (TtyP->termios->c_lflag & XCLUDE)
553 rio_dprintk(RIO_DEBUG_PARAM, "Exclusive use of this line\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -0800555 if (TtyP->termios->c_iflag & IUCLC)
556 rio_dprintk(RIO_DEBUG_PARAM, "Map uppercase to lowercase on input\n");
557 if (TtyP->termios->c_oflag & OPOST)
558 rio_dprintk(RIO_DEBUG_PARAM, "Enable output post-processing\n");
559 if (TtyP->termios->c_oflag & OLCUC)
560 rio_dprintk(RIO_DEBUG_PARAM, "Map lowercase to uppercase on output\n");
561 if (TtyP->termios->c_oflag & ONOCR)
562 rio_dprintk(RIO_DEBUG_PARAM, "No carriage return output at column 0\n");
563 if (TtyP->termios->c_oflag & ONLRET)
564 rio_dprintk(RIO_DEBUG_PARAM, "Newline performs carriage return function\n");
565 if (TtyP->termios->c_oflag & OFILL)
566 rio_dprintk(RIO_DEBUG_PARAM, "Use fill characters for delay\n");
567 if (TtyP->termios->c_oflag & OFDEL)
568 rio_dprintk(RIO_DEBUG_PARAM, "Fill character is DEL\n");
569 if (TtyP->termios->c_oflag & NLDLY)
570 rio_dprintk(RIO_DEBUG_PARAM, "Newline delay set\n");
571 if (TtyP->termios->c_oflag & CRDLY)
572 rio_dprintk(RIO_DEBUG_PARAM, "Carriage return delay set\n");
573 if (TtyP->termios->c_oflag & TABDLY)
574 rio_dprintk(RIO_DEBUG_PARAM, "Tab delay set\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575#if 0
Andrew Morton8d8706e2006-01-11 12:17:49 -0800576 if (TtyP->termios->c_oflag & BSDLY)
577 rio_dprintk(RIO_DEBUG_PARAM, "Back-space delay set\n");
578 if (TtyP->termios->c_oflag & VTDLY)
579 rio_dprintk(RIO_DEBUG_PARAM, "Vertical tab delay set\n");
580 if (TtyP->termios->c_oflag & FFDLY)
581 rio_dprintk(RIO_DEBUG_PARAM, "Form-feed delay set\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582#endif
583 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800584 ** These things are kind of useful in a later life!
585 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 PortP->Cor2Copy = Cor2;
587
Andrew Morton8d8706e2006-01-11 12:17:49 -0800588 if (PortP->State & RIO_DELETED) {
589 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
590 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
592 return RIO_FAIL;
593 }
594
595 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800596 ** Actually write the info into the packet to be sent
597 */
598 WBYTE(phb_param_ptr->Cmd, cmd);
599 WBYTE(phb_param_ptr->Cor1, Cor1);
600 WBYTE(phb_param_ptr->Cor2, Cor2);
601 WBYTE(phb_param_ptr->Cor4, Cor4);
602 WBYTE(phb_param_ptr->Cor5, Cor5);
603 WBYTE(phb_param_ptr->TxXon, TxXon);
604 WBYTE(phb_param_ptr->RxXon, RxXon);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 WBYTE(phb_param_ptr->TxXoff, TxXoff);
606 WBYTE(phb_param_ptr->RxXoff, RxXoff);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800607 WBYTE(phb_param_ptr->LNext, LNext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 WBYTE(phb_param_ptr->TxBaud, TxBaud);
609 WBYTE(phb_param_ptr->RxBaud, RxBaud);
610
611 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800612 ** Set the length/command field
613 */
614 WBYTE(PacketP->len, 12 | PKT_CMD_BIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
616 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800617 ** The packet is formed - now, whack it off
618 ** to its final destination:
619 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 add_transmit(PortP);
621 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800622 ** Count characters transmitted for port statistics reporting
623 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 if (PortP->statsGather)
625 PortP->txchars += 12;
626
Andrew Morton8d8706e2006-01-11 12:17:49 -0800627 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
Andrew Morton8d8706e2006-01-11 12:17:49 -0800629 rio_dprintk(RIO_DEBUG_PARAM, "add_transmit returned.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800631 ** job done.
632 */
633 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
635 return RIO_SUCCESS;
636}
637
638
639/*
640** We can add another packet to a transmit queue if the packet pointer pointed
641** to by the TxAdd pointer has PKT_IN_USE clear in its address.
642*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800643int can_add_transmit(PktP, PortP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644PKT **PktP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800645struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646{
647 register PKT *tp;
648
Andrew Morton8d8706e2006-01-11 12:17:49 -0800649 *PktP = tp = (PKT *) RIO_PTR(PortP->Caddr, RWORD(*PortP->TxAdd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Andrew Morton8d8706e2006-01-11 12:17:49 -0800651 return !((uint) tp & PKT_IN_USE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652}
653
654/*
655** To add a packet to the queue, you set the PKT_IN_USE bit in the address,
656** and then move the TxAdd pointer along one position to point to the next
657** packet pointer. You must wrap the pointer from the end back to the start.
658*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800659void add_transmit(PortP)
660struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800662 if (RWORD(*PortP->TxAdd) & PKT_IN_USE) {
663 rio_dprintk(RIO_DEBUG_PARAM, "add_transmit: Packet has been stolen!");
664 }
665 WWORD(*(ushort *) PortP->TxAdd, RWORD(*PortP->TxAdd) | PKT_IN_USE);
666 PortP->TxAdd = (PortP->TxAdd == PortP->TxEnd) ? PortP->TxStart : PortP->TxAdd + 1;
667 WWORD(PortP->PhbP->tx_add, RIO_OFF(PortP->Caddr, PortP->TxAdd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668}
669
670/****************************************
671 * Put a packet onto the end of the
672 * free list
673 ****************************************/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800674void put_free_end(HostP, PktP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675struct Host *HostP;
676PKT *PktP;
677{
678 FREE_LIST *tmp_pointer;
679 ushort old_end, new_end;
680 unsigned long flags;
681
682 rio_spin_lock_irqsave(&HostP->HostLock, flags);
683
684 /*************************************************
685 * Put a packet back onto the back of the free list
686 *
687 ************************************************/
688
Andrew Morton8d8706e2006-01-11 12:17:49 -0800689 rio_dprintk(RIO_DEBUG_PFE, "put_free_end(PktP=%x)\n", (int) PktP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
Andrew Morton8d8706e2006-01-11 12:17:49 -0800691 if ((old_end = RWORD(HostP->ParmMapP->free_list_end)) != TPNULL) {
692 new_end = RIO_OFF(HostP->Caddr, PktP);
693 tmp_pointer = (FREE_LIST *) RIO_PTR(HostP->Caddr, old_end);
694 WWORD(tmp_pointer->next, new_end);
695 WWORD(((FREE_LIST *) PktP)->prev, old_end);
696 WWORD(((FREE_LIST *) PktP)->next, TPNULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 WWORD(HostP->ParmMapP->free_list_end, new_end);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800698 } else { /* First packet on the free list this should never happen! */
699 rio_dprintk(RIO_DEBUG_PFE, "put_free_end(): This should never happen\n");
700 WWORD(HostP->ParmMapP->free_list_end, RIO_OFF(HostP->Caddr, PktP));
701 tmp_pointer = (FREE_LIST *) PktP;
702 WWORD(tmp_pointer->prev, TPNULL);
703 WWORD(tmp_pointer->next, TPNULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800705 rio_dprintk(RIO_DEBUG_CMD, "Before unlock: %p\n", &HostP->HostLock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
707}
708
709/*
710** can_remove_receive(PktP,P) returns non-zero if PKT_IN_USE is set
711** for the next packet on the queue. It will also set PktP to point to the
712** relevant packet, [having cleared the PKT_IN_USE bit]. If PKT_IN_USE is clear,
713** then can_remove_receive() returns 0.
714*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800715int can_remove_receive(PktP, PortP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716PKT **PktP;
717struct Port *PortP;
718{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800719 if (RWORD(*PortP->RxRemove) & PKT_IN_USE) {
720 *PktP = (PKT *) RIO_PTR(PortP->Caddr, RWORD(*PortP->RxRemove) & ~PKT_IN_USE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 return 1;
722 }
723 return 0;
724}
725
726/*
727** To remove a packet from the receive queue you clear its PKT_IN_USE bit,
728** and then bump the pointers. Once the pointers get to the end, they must
729** be wrapped back to the start.
730*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800731void remove_receive(PortP)
732struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800734 WWORD(*PortP->RxRemove, RWORD(*PortP->RxRemove) & ~PKT_IN_USE);
735 PortP->RxRemove = (PortP->RxRemove == PortP->RxEnd) ? PortP->RxStart : PortP->RxRemove + 1;
736 WWORD(PortP->PhbP->rx_remove, RIO_OFF(PortP->Caddr, PortP->RxRemove));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737}