[PATCH] rio driver rework continued #1
[linux-2.6-block.git] / drivers / char / rio / rioparam.c
CommitLineData
1da177e4
LT
1/*
2** -----------------------------------------------------------------------------
3**
4** Perle Specialix driver for Linux
5** Ported from existing RIO Driver for SCO sources.
6 *
7 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22**
23** Module : rioparam.c
24** SID : 1.3
25** Last Modified : 11/6/98 10:33:45
26** Retrieved : 11/6/98 10:33:50
27**
28** ident @(#)rioparam.c 1.3
29**
30** -----------------------------------------------------------------------------
31*/
32
33#ifdef SCCS_LABELS
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*/
8d8706e2 160int RIOParam(PortP, cmd, Modem, SleepFlag)
1da177e4
LT
161struct Port *PortP;
162int cmd;
163int Modem;
8d8706e2 164int SleepFlag;
1da177e4
LT
165{
166 register struct tty_struct *TtyP;
8d8706e2 167 int retval;
1da177e4
LT
168 register struct phb_param *phb_param_ptr;
169 PKT *PacketP;
170 int res;
8d8706e2
AM
171 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;
1da177e4
LT
175 unsigned long flags;
176
8d8706e2 177 func_enter();
1da177e4
LT
178
179 TtyP = PortP->gs.tty;
180
8d8706e2 181 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);
1da177e4
LT
182
183 if (!TtyP) {
8d8706e2 184 rio_dprintk(RIO_DEBUG_PARAM, "Can't call rioparam with null tty.\n");
1da177e4 185
8d8706e2 186 func_exit();
1da177e4 187
8d8706e2 188 return RIO_FAIL;
1da177e4 189 }
8d8706e2 190 rio_spin_lock_irqsave(&PortP->portSem, flags);
1da177e4
LT
191
192 if (cmd == OPEN) {
193 /*
8d8706e2
AM
194 ** 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 */
1da177e4
LT
198 }
199
200 /*
8d8706e2
AM
201 ** wait for space
202 */
203 while (!(res = can_add_transmit(&PacketP, PortP)) || (PortP->InUse != NOT_INUSE)) {
204 if (retries-- <= 0) {
1da177e4
LT
205 break;
206 }
8d8706e2
AM
207 if (PortP->InUse != NOT_INUSE) {
208 rio_dprintk(RIO_DEBUG_PARAM, "Port IN_USE for pre-emptive command\n");
1da177e4
LT
209 }
210
8d8706e2
AM
211 if (!res) {
212 rio_dprintk(RIO_DEBUG_PARAM, "Port has no space on transmit queue\n");
1da177e4
LT
213 }
214
8d8706e2
AM
215 if (SleepFlag != OK_TO_SLEEP) {
216 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1da177e4 217 func_exit();
8d8706e2 218
1da177e4
LT
219 return RIO_FAIL;
220 }
221
8d8706e2
AM
222 rio_dprintk(RIO_DEBUG_PARAM, "wait for can_add_transmit\n");
223 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1da177e4 224 retval = RIODelay(PortP, HUNDRED_MS);
8d8706e2 225 rio_spin_lock_irqsave(&PortP->portSem, flags);
1da177e4 226 if (retval == RIO_FAIL) {
8d8706e2
AM
227 rio_dprintk(RIO_DEBUG_PARAM, "wait for can_add_transmit broken by signal\n");
228 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1da177e4
LT
229 pseterr(EINTR);
230 func_exit();
231
232 return RIO_FAIL;
233 }
8d8706e2
AM
234 if (PortP->State & RIO_DELETED) {
235 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
236 func_exit();
1da177e4
LT
237
238 return RIO_SUCCESS;
239 }
240 }
241
242 if (!res) {
8d8706e2
AM
243 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
244 func_exit();
1da177e4
LT
245
246 return RIO_FAIL;
247 }
248
8d8706e2
AM
249 rio_dprintk(RIO_DEBUG_PARAM, "can_add_transmit() returns %x\n", res);
250 rio_dprintk(RIO_DEBUG_PARAM, "Packet is 0x%x\n", (int) PacketP);
1da177e4 251
8d8706e2 252 phb_param_ptr = (struct phb_param *) PacketP->data;
1da177e4
LT
253
254
8d8706e2
AM
255 switch (TtyP->termios->c_cflag & CSIZE) {
256 case CS5:
1da177e4 257 {
8d8706e2 258 rio_dprintk(RIO_DEBUG_PARAM, "5 bit data\n");
1da177e4
LT
259 Cor1 |= COR1_5BITS;
260 break;
261 }
8d8706e2 262 case CS6:
1da177e4 263 {
8d8706e2 264 rio_dprintk(RIO_DEBUG_PARAM, "6 bit data\n");
1da177e4
LT
265 Cor1 |= COR1_6BITS;
266 break;
267 }
8d8706e2 268 case CS7:
1da177e4 269 {
8d8706e2 270 rio_dprintk(RIO_DEBUG_PARAM, "7 bit data\n");
1da177e4
LT
271 Cor1 |= COR1_7BITS;
272 break;
273 }
8d8706e2 274 case CS8:
1da177e4 275 {
8d8706e2 276 rio_dprintk(RIO_DEBUG_PARAM, "8 bit data\n");
1da177e4
LT
277 Cor1 |= COR1_8BITS;
278 break;
279 }
280 }
281
8d8706e2
AM
282 if (TtyP->termios->c_cflag & CSTOPB) {
283 rio_dprintk(RIO_DEBUG_PARAM, "2 stop bits\n");
1da177e4 284 Cor1 |= COR1_2STOP;
8d8706e2
AM
285 } else {
286 rio_dprintk(RIO_DEBUG_PARAM, "1 stop bit\n");
1da177e4
LT
287 Cor1 |= COR1_1STOP;
288 }
289
8d8706e2
AM
290 if (TtyP->termios->c_cflag & PARENB) {
291 rio_dprintk(RIO_DEBUG_PARAM, "Enable parity\n");
1da177e4 292 Cor1 |= COR1_NORMAL;
8d8706e2
AM
293 } else {
294 rio_dprintk(RIO_DEBUG_PARAM, "Disable parity\n");
1da177e4
LT
295 Cor1 |= COR1_NOP;
296 }
8d8706e2
AM
297 if (TtyP->termios->c_cflag & PARODD) {
298 rio_dprintk(RIO_DEBUG_PARAM, "Odd parity\n");
1da177e4 299 Cor1 |= COR1_ODD;
8d8706e2
AM
300 } else {
301 rio_dprintk(RIO_DEBUG_PARAM, "Even parity\n");
302 Cor1 |= COR1_EVEN;
1da177e4
LT
303 }
304
305 /*
8d8706e2
AM
306 ** COR 2
307 */
308 if (TtyP->termios->c_iflag & IXON) {
309 rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop output control\n");
1da177e4 310 Cor2 |= COR2_IXON;
8d8706e2
AM
311 } else {
312 if (PortP->Config & RIO_IXON) {
313 rio_dprintk(RIO_DEBUG_PARAM, "Force enable start/stop output control\n");
1da177e4 314 Cor2 |= COR2_IXON;
8d8706e2
AM
315 } else
316 rio_dprintk(RIO_DEBUG_PARAM, "IXON has been disabled.\n");
1da177e4
LT
317 }
318
319 if (TtyP->termios->c_iflag & IXANY) {
8d8706e2
AM
320 if (PortP->Config & RIO_IXANY) {
321 rio_dprintk(RIO_DEBUG_PARAM, "Enable any key to restart output\n");
1da177e4 322 Cor2 |= COR2_IXANY;
8d8706e2
AM
323 } else
324 rio_dprintk(RIO_DEBUG_PARAM, "IXANY has been disabled due to sanity reasons.\n");
1da177e4
LT
325 }
326
8d8706e2
AM
327 if (TtyP->termios->c_iflag & IXOFF) {
328 rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop input control 2\n");
1da177e4
LT
329 Cor2 |= COR2_IXOFF;
330 }
331
8d8706e2
AM
332 if (TtyP->termios->c_cflag & HUPCL) {
333 rio_dprintk(RIO_DEBUG_PARAM, "Hangup on last close\n");
1da177e4
LT
334 Cor2 |= COR2_HUPCL;
335 }
336
8d8706e2
AM
337 if (C_CRTSCTS(TtyP)) {
338 rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control enabled\n");
1da177e4
LT
339 Cor2 |= COR2_CTSFLOW;
340 Cor2 |= COR2_RTSFLOW;
341 } else {
8d8706e2 342 rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control disabled\n");
1da177e4
LT
343 Cor2 &= ~COR2_CTSFLOW;
344 Cor2 &= ~COR2_RTSFLOW;
345 }
346
347
8d8706e2
AM
348 if (TtyP->termios->c_cflag & CLOCAL) {
349 rio_dprintk(RIO_DEBUG_PARAM, "Local line\n");
350 } else {
351 rio_dprintk(RIO_DEBUG_PARAM, "Possible Modem line\n");
1da177e4
LT
352 }
353
354 /*
8d8706e2
AM
355 ** COR 4 (there is no COR 3)
356 */
357 if (TtyP->termios->c_iflag & IGNBRK) {
358 rio_dprintk(RIO_DEBUG_PARAM, "Ignore break condition\n");
1da177e4
LT
359 Cor4 |= COR4_IGNBRK;
360 }
8d8706e2
AM
361 if (!(TtyP->termios->c_iflag & BRKINT)) {
362 rio_dprintk(RIO_DEBUG_PARAM, "Break generates NULL condition\n");
1da177e4
LT
363 Cor4 |= COR4_NBRKINT;
364 } else {
8d8706e2 365 rio_dprintk(RIO_DEBUG_PARAM, "Interrupt on break condition\n");
1da177e4
LT
366 }
367
8d8706e2
AM
368 if (TtyP->termios->c_iflag & INLCR) {
369 rio_dprintk(RIO_DEBUG_PARAM, "Map newline to carriage return on input\n");
1da177e4
LT
370 Cor4 |= COR4_INLCR;
371 }
372
8d8706e2
AM
373 if (TtyP->termios->c_iflag & IGNCR) {
374 rio_dprintk(RIO_DEBUG_PARAM, "Ignore carriage return on input\n");
1da177e4
LT
375 Cor4 |= COR4_IGNCR;
376 }
377
8d8706e2
AM
378 if (TtyP->termios->c_iflag & ICRNL) {
379 rio_dprintk(RIO_DEBUG_PARAM, "Map carriage return to newline on input\n");
1da177e4
LT
380 Cor4 |= COR4_ICRNL;
381 }
8d8706e2
AM
382 if (TtyP->termios->c_iflag & IGNPAR) {
383 rio_dprintk(RIO_DEBUG_PARAM, "Ignore characters with parity errors\n");
1da177e4
LT
384 Cor4 |= COR4_IGNPAR;
385 }
8d8706e2
AM
386 if (TtyP->termios->c_iflag & PARMRK) {
387 rio_dprintk(RIO_DEBUG_PARAM, "Mark parity errors\n");
1da177e4
LT
388 Cor4 |= COR4_PARMRK;
389 }
390
391 /*
8d8706e2
AM
392 ** Set the RAISEMOD flag to ensure that the modem lines are raised
393 ** on reception of a config packet.
394 ** The download code handles the zero baud condition.
395 */
1da177e4
LT
396 Cor4 |= COR4_RAISEMOD;
397
398 /*
8d8706e2
AM
399 ** COR 5
400 */
1da177e4
LT
401
402 Cor5 = COR5_CMOE;
403
404 /*
8d8706e2
AM
405 ** Set to monitor tbusy/tstop (or not).
406 */
1da177e4
LT
407
408 if (PortP->MonitorTstate)
409 Cor5 |= COR5_TSTATE_ON;
410 else
411 Cor5 |= COR5_TSTATE_OFF;
412
413 /*
8d8706e2
AM
414 ** Could set LNE here if you wanted LNext processing. SVR4 will use it.
415 */
416 if (TtyP->termios->c_iflag & ISTRIP) {
417 rio_dprintk(RIO_DEBUG_PARAM, "Strip input characters\n");
418 if (!(PortP->State & RIO_TRIAD_MODE)) {
1da177e4
LT
419 Cor5 |= COR5_ISTRIP;
420 }
421 }
422
8d8706e2
AM
423 if (TtyP->termios->c_oflag & ONLCR) {
424 rio_dprintk(RIO_DEBUG_PARAM, "Map newline to carriage-return, newline on output\n");
425 if (PortP->CookMode == COOK_MEDIUM)
1da177e4
LT
426 Cor5 |= COR5_ONLCR;
427 }
8d8706e2
AM
428 if (TtyP->termios->c_oflag & OCRNL) {
429 rio_dprintk(RIO_DEBUG_PARAM, "Map carriage return to newline on output\n");
430 if (PortP->CookMode == COOK_MEDIUM)
1da177e4
LT
431 Cor5 |= COR5_OCRNL;
432 }
8d8706e2
AM
433 if ((TtyP->termios->c_oflag & TABDLY) == TAB3) {
434 rio_dprintk(RIO_DEBUG_PARAM, "Tab delay 3 set\n");
435 if (PortP->CookMode == COOK_MEDIUM)
1da177e4
LT
436 Cor5 |= COR5_TAB3;
437 }
438
439 /*
8d8706e2
AM
440 ** Flow control bytes.
441 */
1da177e4
LT
442 TxXon = TtyP->termios->c_cc[VSTART];
443 TxXoff = TtyP->termios->c_cc[VSTOP];
444 RxXon = TtyP->termios->c_cc[VSTART];
445 RxXoff = TtyP->termios->c_cc[VSTOP];
446 /*
8d8706e2
AM
447 ** LNEXT byte
448 */
1da177e4
LT
449 LNext = 0;
450
451 /*
8d8706e2
AM
452 ** Baud rate bytes
453 */
454 rio_dprintk(RIO_DEBUG_PARAM, "Mapping of rx/tx baud %x (%x)\n", TtyP->termios->c_cflag, CBAUD);
1da177e4
LT
455
456 switch (TtyP->termios->c_cflag & CBAUD) {
457#define e(b) case B ## b : RxBaud = TxBaud = RIO_B ## b ;break
8d8706e2
AM
458 e(50);
459 e(75);
460 e(110);
461 e(134);
462 e(150);
463 e(200);
464 e(300);
465 e(600);
466 e(1200);
467 e(1800);
468 e(2400);
469 e(4800);
470 e(9600);
471 e(19200);
472 e(38400);
473 e(57600);
474 e(115200); /* e(230400);e(460800); e(921600); */
1da177e4
LT
475 }
476
477 /* XXX MIssing conversion table. XXX */
8d8706e2 478 /* (TtyP->termios->c_cflag & V_CBAUD); */
1da177e4 479
8d8706e2 480 rio_dprintk(RIO_DEBUG_PARAM, "tx baud 0x%x, rx baud 0x%x\n", TxBaud, RxBaud);
1da177e4
LT
481
482
483 /*
8d8706e2
AM
484 ** Leftovers
485 */
486 if (TtyP->termios->c_cflag & CREAD)
487 rio_dprintk(RIO_DEBUG_PARAM, "Enable receiver\n");
1da177e4 488#ifdef RCV1EN
8d8706e2
AM
489 if (TtyP->termios->c_cflag & RCV1EN)
490 rio_dprintk(RIO_DEBUG_PARAM, "RCV1EN (?)\n");
1da177e4
LT
491#endif
492#ifdef XMT1EN
8d8706e2
AM
493 if (TtyP->termios->c_cflag & XMT1EN)
494 rio_dprintk(RIO_DEBUG_PARAM, "XMT1EN (?)\n");
1da177e4 495#endif
8d8706e2
AM
496 if (TtyP->termios->c_lflag & ISIG)
497 rio_dprintk(RIO_DEBUG_PARAM, "Input character signal generating enabled\n");
498 if (TtyP->termios->c_lflag & ICANON)
499 rio_dprintk(RIO_DEBUG_PARAM, "Canonical input: erase and kill enabled\n");
500 if (TtyP->termios->c_lflag & XCASE)
501 rio_dprintk(RIO_DEBUG_PARAM, "Canonical upper/lower presentation\n");
502 if (TtyP->termios->c_lflag & ECHO)
503 rio_dprintk(RIO_DEBUG_PARAM, "Enable input echo\n");
504 if (TtyP->termios->c_lflag & ECHOE)
505 rio_dprintk(RIO_DEBUG_PARAM, "Enable echo erase\n");
506 if (TtyP->termios->c_lflag & ECHOK)
507 rio_dprintk(RIO_DEBUG_PARAM, "Enable echo kill\n");
508 if (TtyP->termios->c_lflag & ECHONL)
509 rio_dprintk(RIO_DEBUG_PARAM, "Enable echo newline\n");
510 if (TtyP->termios->c_lflag & NOFLSH)
511 rio_dprintk(RIO_DEBUG_PARAM, "Disable flush after interrupt or quit\n");
1da177e4 512#ifdef TOSTOP
8d8706e2
AM
513 if (TtyP->termios->c_lflag & TOSTOP)
514 rio_dprintk(RIO_DEBUG_PARAM, "Send SIGTTOU for background output\n");
1da177e4
LT
515#endif
516#ifdef XCLUDE
8d8706e2
AM
517 if (TtyP->termios->c_lflag & XCLUDE)
518 rio_dprintk(RIO_DEBUG_PARAM, "Exclusive use of this line\n");
1da177e4 519#endif
8d8706e2
AM
520 if (TtyP->termios->c_iflag & IUCLC)
521 rio_dprintk(RIO_DEBUG_PARAM, "Map uppercase to lowercase on input\n");
522 if (TtyP->termios->c_oflag & OPOST)
523 rio_dprintk(RIO_DEBUG_PARAM, "Enable output post-processing\n");
524 if (TtyP->termios->c_oflag & OLCUC)
525 rio_dprintk(RIO_DEBUG_PARAM, "Map lowercase to uppercase on output\n");
526 if (TtyP->termios->c_oflag & ONOCR)
527 rio_dprintk(RIO_DEBUG_PARAM, "No carriage return output at column 0\n");
528 if (TtyP->termios->c_oflag & ONLRET)
529 rio_dprintk(RIO_DEBUG_PARAM, "Newline performs carriage return function\n");
530 if (TtyP->termios->c_oflag & OFILL)
531 rio_dprintk(RIO_DEBUG_PARAM, "Use fill characters for delay\n");
532 if (TtyP->termios->c_oflag & OFDEL)
533 rio_dprintk(RIO_DEBUG_PARAM, "Fill character is DEL\n");
534 if (TtyP->termios->c_oflag & NLDLY)
535 rio_dprintk(RIO_DEBUG_PARAM, "Newline delay set\n");
536 if (TtyP->termios->c_oflag & CRDLY)
537 rio_dprintk(RIO_DEBUG_PARAM, "Carriage return delay set\n");
538 if (TtyP->termios->c_oflag & TABDLY)
539 rio_dprintk(RIO_DEBUG_PARAM, "Tab delay set\n");
1da177e4 540 /*
8d8706e2
AM
541 ** These things are kind of useful in a later life!
542 */
1da177e4
LT
543 PortP->Cor2Copy = Cor2;
544
8d8706e2
AM
545 if (PortP->State & RIO_DELETED) {
546 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
547 func_exit();
1da177e4
LT
548
549 return RIO_FAIL;
550 }
551
552 /*
8d8706e2
AM
553 ** Actually write the info into the packet to be sent
554 */
555 WBYTE(phb_param_ptr->Cmd, cmd);
556 WBYTE(phb_param_ptr->Cor1, Cor1);
557 WBYTE(phb_param_ptr->Cor2, Cor2);
558 WBYTE(phb_param_ptr->Cor4, Cor4);
559 WBYTE(phb_param_ptr->Cor5, Cor5);
560 WBYTE(phb_param_ptr->TxXon, TxXon);
561 WBYTE(phb_param_ptr->RxXon, RxXon);
1da177e4
LT
562 WBYTE(phb_param_ptr->TxXoff, TxXoff);
563 WBYTE(phb_param_ptr->RxXoff, RxXoff);
8d8706e2 564 WBYTE(phb_param_ptr->LNext, LNext);
1da177e4
LT
565 WBYTE(phb_param_ptr->TxBaud, TxBaud);
566 WBYTE(phb_param_ptr->RxBaud, RxBaud);
567
568 /*
8d8706e2
AM
569 ** Set the length/command field
570 */
571 WBYTE(PacketP->len, 12 | PKT_CMD_BIT);
1da177e4
LT
572
573 /*
8d8706e2
AM
574 ** The packet is formed - now, whack it off
575 ** to its final destination:
576 */
1da177e4
LT
577 add_transmit(PortP);
578 /*
8d8706e2
AM
579 ** Count characters transmitted for port statistics reporting
580 */
1da177e4
LT
581 if (PortP->statsGather)
582 PortP->txchars += 12;
583
8d8706e2 584 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1da177e4 585
8d8706e2 586 rio_dprintk(RIO_DEBUG_PARAM, "add_transmit returned.\n");
1da177e4 587 /*
8d8706e2
AM
588 ** job done.
589 */
590 func_exit();
1da177e4
LT
591
592 return RIO_SUCCESS;
593}
594
595
596/*
597** We can add another packet to a transmit queue if the packet pointer pointed
598** to by the TxAdd pointer has PKT_IN_USE clear in its address.
599*/
8d8706e2 600int can_add_transmit(PktP, PortP)
1da177e4 601PKT **PktP;
8d8706e2 602struct Port *PortP;
1da177e4
LT
603{
604 register PKT *tp;
605
8d8706e2 606 *PktP = tp = (PKT *) RIO_PTR(PortP->Caddr, RWORD(*PortP->TxAdd));
1da177e4 607
8d8706e2 608 return !((uint) tp & PKT_IN_USE);
1da177e4
LT
609}
610
611/*
612** To add a packet to the queue, you set the PKT_IN_USE bit in the address,
613** and then move the TxAdd pointer along one position to point to the next
614** packet pointer. You must wrap the pointer from the end back to the start.
615*/
8d8706e2
AM
616void add_transmit(PortP)
617struct Port *PortP;
1da177e4 618{
8d8706e2
AM
619 if (RWORD(*PortP->TxAdd) & PKT_IN_USE) {
620 rio_dprintk(RIO_DEBUG_PARAM, "add_transmit: Packet has been stolen!");
621 }
622 WWORD(*(ushort *) PortP->TxAdd, RWORD(*PortP->TxAdd) | PKT_IN_USE);
623 PortP->TxAdd = (PortP->TxAdd == PortP->TxEnd) ? PortP->TxStart : PortP->TxAdd + 1;
624 WWORD(PortP->PhbP->tx_add, RIO_OFF(PortP->Caddr, PortP->TxAdd));
1da177e4
LT
625}
626
627/****************************************
628 * Put a packet onto the end of the
629 * free list
630 ****************************************/
8d8706e2 631void put_free_end(HostP, PktP)
1da177e4
LT
632struct Host *HostP;
633PKT *PktP;
634{
635 FREE_LIST *tmp_pointer;
636 ushort old_end, new_end;
637 unsigned long flags;
638
639 rio_spin_lock_irqsave(&HostP->HostLock, flags);
640
641 /*************************************************
642 * Put a packet back onto the back of the free list
643 *
644 ************************************************/
645
8d8706e2 646 rio_dprintk(RIO_DEBUG_PFE, "put_free_end(PktP=%x)\n", (int) PktP);
1da177e4 647
8d8706e2
AM
648 if ((old_end = RWORD(HostP->ParmMapP->free_list_end)) != TPNULL) {
649 new_end = RIO_OFF(HostP->Caddr, PktP);
650 tmp_pointer = (FREE_LIST *) RIO_PTR(HostP->Caddr, old_end);
651 WWORD(tmp_pointer->next, new_end);
652 WWORD(((FREE_LIST *) PktP)->prev, old_end);
653 WWORD(((FREE_LIST *) PktP)->next, TPNULL);
1da177e4 654 WWORD(HostP->ParmMapP->free_list_end, new_end);
8d8706e2
AM
655 } else { /* First packet on the free list this should never happen! */
656 rio_dprintk(RIO_DEBUG_PFE, "put_free_end(): This should never happen\n");
657 WWORD(HostP->ParmMapP->free_list_end, RIO_OFF(HostP->Caddr, PktP));
658 tmp_pointer = (FREE_LIST *) PktP;
659 WWORD(tmp_pointer->prev, TPNULL);
660 WWORD(tmp_pointer->next, TPNULL);
661 }
662 rio_dprintk(RIO_DEBUG_CMD, "Before unlock: %p\n", &HostP->HostLock);
1da177e4
LT
663 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
664}
665
666/*
667** can_remove_receive(PktP,P) returns non-zero if PKT_IN_USE is set
668** for the next packet on the queue. It will also set PktP to point to the
669** relevant packet, [having cleared the PKT_IN_USE bit]. If PKT_IN_USE is clear,
670** then can_remove_receive() returns 0.
671*/
8d8706e2 672int can_remove_receive(PktP, PortP)
1da177e4
LT
673PKT **PktP;
674struct Port *PortP;
675{
8d8706e2
AM
676 if (RWORD(*PortP->RxRemove) & PKT_IN_USE) {
677 *PktP = (PKT *) RIO_PTR(PortP->Caddr, RWORD(*PortP->RxRemove) & ~PKT_IN_USE);
1da177e4
LT
678 return 1;
679 }
680 return 0;
681}
682
683/*
684** To remove a packet from the receive queue you clear its PKT_IN_USE bit,
685** and then bump the pointers. Once the pointers get to the end, they must
686** be wrapped back to the start.
687*/
8d8706e2
AM
688void remove_receive(PortP)
689struct Port *PortP;
1da177e4 690{
8d8706e2
AM
691 WWORD(*PortP->RxRemove, RWORD(*PortP->RxRemove) & ~PKT_IN_USE);
692 PortP->RxRemove = (PortP->RxRemove == PortP->RxEnd) ? PortP->RxStart : PortP->RxRemove + 1;
693 WWORD(PortP->PhbP->rx_remove, RIO_OFF(PortP->Caddr, PortP->RxRemove));
1da177e4 694}