ia64/linux-2.6.18-xen.hg

view drivers/char/rio/rioparam.c @ 893:f994bfe9b93b

linux/blktap2: reduce TLB flush scope

c/s 885 added very coarse TLB flushing. Since these flushes always
follow single page updates, single page flushes (when available) are
sufficient.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 04 10:32:57 2009 +0100 (2009-06-04)
parents 831230e53067
children
line source
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 */
33 #ifdef SCCS_LABELS
34 static char *_rioparam_c_sccs_ = "@(#)rioparam.c 1.3";
35 #endif
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>
47 #include <linux/termios.h>
48 #include <linux/serial.h>
50 #include <linux/generic_serial.h>
53 #include "linux_compat.h"
54 #include "rio_linux.h"
55 #include "pkt.h"
56 #include "daemon.h"
57 #include "rio.h"
58 #include "riospace.h"
59 #include "cmdpkt.h"
60 #include "map.h"
61 #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"
69 #include "parmmap.h"
70 #include "unixrup.h"
71 #include "board.h"
72 #include "host.h"
73 #include "phb.h"
74 #include "link.h"
75 #include "cmdblk.h"
76 #include "route.h"
77 #include "cirrus.h"
78 #include "rioioctl.h"
79 #include "param.h"
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 */
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 */
153 int RIOParam(struct Port *PortP, int cmd, int Modem, int SleepFlag)
154 {
155 struct tty_struct *TtyP;
156 int retval;
157 struct phb_param __iomem *phb_param_ptr;
158 struct PKT __iomem *PacketP;
159 int res;
160 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;
163 int retries = 0xff;
164 unsigned long flags;
166 func_enter();
168 TtyP = PortP->gs.tty;
170 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);
172 if (!TtyP) {
173 rio_dprintk(RIO_DEBUG_PARAM, "Can't call rioparam with null tty.\n");
175 func_exit();
177 return RIO_FAIL;
178 }
179 rio_spin_lock_irqsave(&PortP->portSem, flags);
181 if (cmd == OPEN) {
182 /*
183 ** 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 */
187 }
189 /*
190 ** wait for space
191 */
192 while (!(res = can_add_transmit(&PacketP, PortP)) || (PortP->InUse != NOT_INUSE)) {
193 if (retries-- <= 0) {
194 break;
195 }
196 if (PortP->InUse != NOT_INUSE) {
197 rio_dprintk(RIO_DEBUG_PARAM, "Port IN_USE for pre-emptive command\n");
198 }
200 if (!res) {
201 rio_dprintk(RIO_DEBUG_PARAM, "Port has no space on transmit queue\n");
202 }
204 if (SleepFlag != OK_TO_SLEEP) {
205 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
206 func_exit();
208 return RIO_FAIL;
209 }
211 rio_dprintk(RIO_DEBUG_PARAM, "wait for can_add_transmit\n");
212 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
213 retval = RIODelay(PortP, HUNDRED_MS);
214 rio_spin_lock_irqsave(&PortP->portSem, flags);
215 if (retval == RIO_FAIL) {
216 rio_dprintk(RIO_DEBUG_PARAM, "wait for can_add_transmit broken by signal\n");
217 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
218 func_exit();
219 return -EINTR;
220 }
221 if (PortP->State & RIO_DELETED) {
222 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
223 func_exit();
224 return 0;
225 }
226 }
228 if (!res) {
229 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
230 func_exit();
232 return RIO_FAIL;
233 }
235 rio_dprintk(RIO_DEBUG_PARAM, "can_add_transmit() returns %x\n", res);
236 rio_dprintk(RIO_DEBUG_PARAM, "Packet is %p\n", PacketP);
238 phb_param_ptr = (struct phb_param __iomem *) PacketP->data;
241 switch (TtyP->termios->c_cflag & CSIZE) {
242 case CS5:
243 {
244 rio_dprintk(RIO_DEBUG_PARAM, "5 bit data\n");
245 Cor1 |= COR1_5BITS;
246 break;
247 }
248 case CS6:
249 {
250 rio_dprintk(RIO_DEBUG_PARAM, "6 bit data\n");
251 Cor1 |= COR1_6BITS;
252 break;
253 }
254 case CS7:
255 {
256 rio_dprintk(RIO_DEBUG_PARAM, "7 bit data\n");
257 Cor1 |= COR1_7BITS;
258 break;
259 }
260 case CS8:
261 {
262 rio_dprintk(RIO_DEBUG_PARAM, "8 bit data\n");
263 Cor1 |= COR1_8BITS;
264 break;
265 }
266 }
268 if (TtyP->termios->c_cflag & CSTOPB) {
269 rio_dprintk(RIO_DEBUG_PARAM, "2 stop bits\n");
270 Cor1 |= COR1_2STOP;
271 } else {
272 rio_dprintk(RIO_DEBUG_PARAM, "1 stop bit\n");
273 Cor1 |= COR1_1STOP;
274 }
276 if (TtyP->termios->c_cflag & PARENB) {
277 rio_dprintk(RIO_DEBUG_PARAM, "Enable parity\n");
278 Cor1 |= COR1_NORMAL;
279 } else {
280 rio_dprintk(RIO_DEBUG_PARAM, "Disable parity\n");
281 Cor1 |= COR1_NOP;
282 }
283 if (TtyP->termios->c_cflag & PARODD) {
284 rio_dprintk(RIO_DEBUG_PARAM, "Odd parity\n");
285 Cor1 |= COR1_ODD;
286 } else {
287 rio_dprintk(RIO_DEBUG_PARAM, "Even parity\n");
288 Cor1 |= COR1_EVEN;
289 }
291 /*
292 ** COR 2
293 */
294 if (TtyP->termios->c_iflag & IXON) {
295 rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop output control\n");
296 Cor2 |= COR2_IXON;
297 } else {
298 if (PortP->Config & RIO_IXON) {
299 rio_dprintk(RIO_DEBUG_PARAM, "Force enable start/stop output control\n");
300 Cor2 |= COR2_IXON;
301 } else
302 rio_dprintk(RIO_DEBUG_PARAM, "IXON has been disabled.\n");
303 }
305 if (TtyP->termios->c_iflag & IXANY) {
306 if (PortP->Config & RIO_IXANY) {
307 rio_dprintk(RIO_DEBUG_PARAM, "Enable any key to restart output\n");
308 Cor2 |= COR2_IXANY;
309 } else
310 rio_dprintk(RIO_DEBUG_PARAM, "IXANY has been disabled due to sanity reasons.\n");
311 }
313 if (TtyP->termios->c_iflag & IXOFF) {
314 rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop input control 2\n");
315 Cor2 |= COR2_IXOFF;
316 }
318 if (TtyP->termios->c_cflag & HUPCL) {
319 rio_dprintk(RIO_DEBUG_PARAM, "Hangup on last close\n");
320 Cor2 |= COR2_HUPCL;
321 }
323 if (C_CRTSCTS(TtyP)) {
324 rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control enabled\n");
325 Cor2 |= COR2_CTSFLOW;
326 Cor2 |= COR2_RTSFLOW;
327 } else {
328 rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control disabled\n");
329 Cor2 &= ~COR2_CTSFLOW;
330 Cor2 &= ~COR2_RTSFLOW;
331 }
334 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");
338 }
340 /*
341 ** 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");
345 Cor4 |= COR4_IGNBRK;
346 }
347 if (!(TtyP->termios->c_iflag & BRKINT)) {
348 rio_dprintk(RIO_DEBUG_PARAM, "Break generates NULL condition\n");
349 Cor4 |= COR4_NBRKINT;
350 } else {
351 rio_dprintk(RIO_DEBUG_PARAM, "Interrupt on break condition\n");
352 }
354 if (TtyP->termios->c_iflag & INLCR) {
355 rio_dprintk(RIO_DEBUG_PARAM, "Map newline to carriage return on input\n");
356 Cor4 |= COR4_INLCR;
357 }
359 if (TtyP->termios->c_iflag & IGNCR) {
360 rio_dprintk(RIO_DEBUG_PARAM, "Ignore carriage return on input\n");
361 Cor4 |= COR4_IGNCR;
362 }
364 if (TtyP->termios->c_iflag & ICRNL) {
365 rio_dprintk(RIO_DEBUG_PARAM, "Map carriage return to newline on input\n");
366 Cor4 |= COR4_ICRNL;
367 }
368 if (TtyP->termios->c_iflag & IGNPAR) {
369 rio_dprintk(RIO_DEBUG_PARAM, "Ignore characters with parity errors\n");
370 Cor4 |= COR4_IGNPAR;
371 }
372 if (TtyP->termios->c_iflag & PARMRK) {
373 rio_dprintk(RIO_DEBUG_PARAM, "Mark parity errors\n");
374 Cor4 |= COR4_PARMRK;
375 }
377 /*
378 ** 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 */
382 Cor4 |= COR4_RAISEMOD;
384 /*
385 ** COR 5
386 */
388 Cor5 = COR5_CMOE;
390 /*
391 ** Set to monitor tbusy/tstop (or not).
392 */
394 if (PortP->MonitorTstate)
395 Cor5 |= COR5_TSTATE_ON;
396 else
397 Cor5 |= COR5_TSTATE_OFF;
399 /*
400 ** 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)) {
405 Cor5 |= COR5_ISTRIP;
406 }
407 }
409 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)
412 Cor5 |= COR5_ONLCR;
413 }
414 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)
417 Cor5 |= COR5_OCRNL;
418 }
419 if ((TtyP->termios->c_oflag & TABDLY) == TAB3) {
420 rio_dprintk(RIO_DEBUG_PARAM, "Tab delay 3 set\n");
421 if (PortP->CookMode == COOK_MEDIUM)
422 Cor5 |= COR5_TAB3;
423 }
425 /*
426 ** Flow control bytes.
427 */
428 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 /*
433 ** LNEXT byte
434 */
435 LNext = 0;
437 /*
438 ** Baud rate bytes
439 */
440 rio_dprintk(RIO_DEBUG_PARAM, "Mapping of rx/tx baud %x (%x)\n", TtyP->termios->c_cflag, CBAUD);
442 switch (TtyP->termios->c_cflag & CBAUD) {
443 #define e(b) case B ## b : RxBaud = TxBaud = RIO_B ## b ;break
444 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); */
461 }
463 rio_dprintk(RIO_DEBUG_PARAM, "tx baud 0x%x, rx baud 0x%x\n", TxBaud, RxBaud);
466 /*
467 ** Leftovers
468 */
469 if (TtyP->termios->c_cflag & CREAD)
470 rio_dprintk(RIO_DEBUG_PARAM, "Enable receiver\n");
471 #ifdef RCV1EN
472 if (TtyP->termios->c_cflag & RCV1EN)
473 rio_dprintk(RIO_DEBUG_PARAM, "RCV1EN (?)\n");
474 #endif
475 #ifdef XMT1EN
476 if (TtyP->termios->c_cflag & XMT1EN)
477 rio_dprintk(RIO_DEBUG_PARAM, "XMT1EN (?)\n");
478 #endif
479 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");
495 #ifdef TOSTOP
496 if (TtyP->termios->c_lflag & TOSTOP)
497 rio_dprintk(RIO_DEBUG_PARAM, "Send SIGTTOU for background output\n");
498 #endif
499 #ifdef XCLUDE
500 if (TtyP->termios->c_lflag & XCLUDE)
501 rio_dprintk(RIO_DEBUG_PARAM, "Exclusive use of this line\n");
502 #endif
503 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");
523 /*
524 ** These things are kind of useful in a later life!
525 */
526 PortP->Cor2Copy = Cor2;
528 if (PortP->State & RIO_DELETED) {
529 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
530 func_exit();
532 return RIO_FAIL;
533 }
535 /*
536 ** Actually write the info into the packet to be sent
537 */
538 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);
551 /*
552 ** Set the length/command field
553 */
554 writeb(12 | PKT_CMD_BIT, &PacketP->len);
556 /*
557 ** The packet is formed - now, whack it off
558 ** to its final destination:
559 */
560 add_transmit(PortP);
561 /*
562 ** Count characters transmitted for port statistics reporting
563 */
564 if (PortP->statsGather)
565 PortP->txchars += 12;
567 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
569 rio_dprintk(RIO_DEBUG_PARAM, "add_transmit returned.\n");
570 /*
571 ** job done.
572 */
573 func_exit();
575 return 0;
576 }
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 */
583 int can_add_transmit(struct PKT __iomem **PktP, struct Port *PortP)
584 {
585 struct PKT __iomem *tp;
587 *PktP = tp = (struct PKT __iomem *) RIO_PTR(PortP->Caddr, readw(PortP->TxAdd));
589 return !((unsigned long) tp & PKT_IN_USE);
590 }
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 */
597 void add_transmit(struct Port *PortP)
598 {
599 if (readw(PortP->TxAdd) & PKT_IN_USE) {
600 rio_dprintk(RIO_DEBUG_PARAM, "add_transmit: Packet has been stolen!");
601 }
602 writew(readw(PortP->TxAdd) | PKT_IN_USE, PortP->TxAdd);
603 PortP->TxAdd = (PortP->TxAdd == PortP->TxEnd) ? PortP->TxStart : PortP->TxAdd + 1;
604 writew(RIO_OFF(PortP->Caddr, PortP->TxAdd), &PortP->PhbP->tx_add);
605 }
607 /****************************************
608 * Put a packet onto the end of the
609 * free list
610 ****************************************/
611 void put_free_end(struct Host *HostP, struct PKT __iomem *PktP)
612 {
613 struct rio_free_list __iomem *tmp_pointer;
614 unsigned short old_end, new_end;
615 unsigned long flags;
617 rio_spin_lock_irqsave(&HostP->HostLock, flags);
619 /*************************************************
620 * Put a packet back onto the back of the free list
621 *
622 ************************************************/
624 rio_dprintk(RIO_DEBUG_PFE, "put_free_end(PktP=%p)\n", PktP);
626 if ((old_end = readw(&HostP->ParmMapP->free_list_end)) != TPNULL) {
627 new_end = RIO_OFF(HostP->Caddr, PktP);
628 tmp_pointer = (struct rio_free_list __iomem *) RIO_PTR(HostP->Caddr, old_end);
629 writew(new_end, &tmp_pointer->next);
630 writew(old_end, &((struct rio_free_list __iomem *) PktP)->prev);
631 writew(TPNULL, &((struct rio_free_list __iomem *) PktP)->next);
632 writew(new_end, &HostP->ParmMapP->free_list_end);
633 } 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");
635 writew(RIO_OFF(HostP->Caddr, PktP), &HostP->ParmMapP->free_list_end);
636 tmp_pointer = (struct rio_free_list __iomem *) PktP;
637 writew(TPNULL, &tmp_pointer->prev);
638 writew(TPNULL, &tmp_pointer->next);
639 }
640 rio_dprintk(RIO_DEBUG_CMD, "Before unlock: %p\n", &HostP->HostLock);
641 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
642 }
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 */
650 int can_remove_receive(struct PKT __iomem **PktP, struct Port *PortP)
651 {
652 if (readw(PortP->RxRemove) & PKT_IN_USE) {
653 *PktP = (struct PKT __iomem *) RIO_PTR(PortP->Caddr, readw(PortP->RxRemove) & ~PKT_IN_USE);
654 return 1;
655 }
656 return 0;
657 }
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 */
664 void remove_receive(struct Port *PortP)
665 {
666 writew(readw(PortP->RxRemove) & ~PKT_IN_USE, PortP->RxRemove);
667 PortP->RxRemove = (PortP->RxRemove == PortP->RxEnd) ? PortP->RxStart : PortP->RxRemove + 1;
668 writew(RIO_OFF(PortP->Caddr, PortP->RxRemove), &PortP->PhbP->rx_remove);
669 }