blob: 4810b845cc21074f49fc72aba3c0e7aa5637bee6 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <asm/uaccess.h>
45
46#include <linux/termios.h>
47#include <linux/serial.h>
48
49#include <linux/generic_serial.h>
50
51
52#include "linux_compat.h"
53#include "rio_linux.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#include "pkt.h"
55#include "daemon.h"
56#include "rio.h"
57#include "riospace.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#include "cmdpkt.h"
59#include "map.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#include "rup.h"
61#include "port.h"
62#include "riodrvr.h"
63#include "rioinfo.h"
64#include "func.h"
65#include "errors.h"
66#include "pci.h"
67
68#include "parmmap.h"
69#include "unixrup.h"
70#include "board.h"
71#include "host.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#include "phb.h"
73#include "link.h"
74#include "cmdblk.h"
75#include "route.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#include "cirrus.h"
77#include "rioioctl.h"
78#include "param.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80
81
82/*
83** The Scam, based on email from jeremyr@bugs.specialix.co.uk....
84**
85** To send a command on a particular port, you put a packet with the
86** command bit set onto the port. The command bit is in the len field,
87** and gets ORed in with the actual byte count.
88**
Matt LaPlante0779bf22006-11-30 05:24:39 +010089** When you send a packet with the command bit set the first
90** data byte (data[0]) is interpreted as the command to execute.
Linus Torvalds1da177e2005-04-16 15:20:36 -070091** It also governs what data structure overlay should accompany the packet.
92** Commands are defined in cirrus/cirrus.h
93**
94** If you want the command to pre-emt data already on the queue for the
95** port, set the pre-emptive bit in conjunction with the command bit.
96** It is not defined what will happen if you set the preemptive bit
97** on a packet that is NOT a command.
98**
99** Pre-emptive commands should be queued at the head of the queue using
100** add_start(), whereas normal commands and data are enqueued using
101** add_end().
102**
103** Most commands do not use the remaining bytes in the data array. The
104** exceptions are OPEN MOPEN and CONFIG. (NB. As with the SI CONFIG and
Matt LaPlante0779bf22006-11-30 05:24:39 +0100105** OPEN are currently analogous). With these three commands the following
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106** 11 data bytes are all used to pass config information such as baud rate etc.
107** The fields are also defined in cirrus.h. Some contain straightforward
108** information such as the transmit XON character. Two contain the transmit and
109** receive baud rates respectively. For most baud rates there is a direct
110** mapping between the rates defined in <sys/termio.h> and the byte in the
111** packet. There are additional (non UNIX-standard) rates defined in
112** /u/dos/rio/cirrus/h/brates.h.
113**
114** The rest of the data fields contain approximations to the Cirrus registers
115** that are used to program number of bits etc. Each registers bit fields is
116** defined in cirrus.h.
117**
118** NB. Only use those bits that are defined as being driver specific
119** or common to the RTA and the driver.
120**
121** All commands going from RTA->Host will be dealt with by the Host code - you
122** will never see them. As with the SI there will be three fields to look out
123** for in each phb (not yet defined - needs defining a.s.a.p).
124**
125** modem_status - current state of handshake pins.
126**
127** port_status - current port status - equivalent to hi_stat for SI, indicates
128** if port is IDLE_OPEN, IDLE_CLOSED etc.
129**
130** break_status - bit X set if break has been received.
131**
132** Happy hacking.
133**
134*/
135
136/*
137** RIOParam is used to open or configure a port. You pass it a PortP,
138** which will have a tty struct attached to it. You also pass a command,
139** either OPEN or CONFIG. The port's setup is taken from the t_ fields
140** of the tty struct inside the PortP, and the port is either opened
141** or re-configured. You must also tell RIOParam if the device is a modem
142** device or not (i.e. top bit of minor number set or clear - take special
143** care when deciding on this!).
144** RIOParam neither flushes nor waits for drain, and is NOT preemptive.
145**
146** RIOParam assumes it will be called at splrio(), and also assumes
147** that CookMode is set correctly in the port structure.
148**
149** NB. for MPX
150** tty lock must NOT have been previously acquired.
151*/
Alan Coxe2b3afd2006-03-24 03:18:27 -0800152int RIOParam(struct Port *PortP, int cmd, int Modem, int SleepFlag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153{
Alan Coxe2b3afd2006-03-24 03:18:27 -0800154 struct tty_struct *TtyP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800155 int retval;
Al Virod886cb52006-05-27 00:08:25 -0400156 struct phb_param __iomem *phb_param_ptr;
157 struct PKT __iomem *PacketP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 int res;
Alan Coxe2b3afd2006-03-24 03:18:27 -0800159 u8 Cor1 = 0, Cor2 = 0, Cor4 = 0, Cor5 = 0;
160 u8 TxXon = 0, TxXoff = 0, RxXon = 0, RxXoff = 0;
161 u8 LNext = 0, TxBaud = 0, RxBaud = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800162 int retries = 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 unsigned long flags;
164
Andrew Morton8d8706e2006-01-11 12:17:49 -0800165 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 TtyP = PortP->gs.tty;
168
Andrew Morton8d8706e2006-01-11 12:17:49 -0800169 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 -0700170
171 if (!TtyP) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800172 rio_dprintk(RIO_DEBUG_PARAM, "Can't call rioparam with null tty.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Andrew Morton8d8706e2006-01-11 12:17:49 -0800174 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Andrew Morton8d8706e2006-01-11 12:17:49 -0800176 return RIO_FAIL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800178 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Jiri Slabyd6f63412008-04-30 00:53:57 -0700180 if (cmd == RIOC_OPEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800182 ** If the port is set to store or lock the parameters, and it is
183 ** paramed with OPEN, we want to restore the saved port termio, but
184 ** only if StoredTermio has been saved, i.e. NOT 1st open after reboot.
185 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 }
187
188 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800189 ** wait for space
190 */
191 while (!(res = can_add_transmit(&PacketP, PortP)) || (PortP->InUse != NOT_INUSE)) {
192 if (retries-- <= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 break;
194 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800195 if (PortP->InUse != NOT_INUSE) {
196 rio_dprintk(RIO_DEBUG_PARAM, "Port IN_USE for pre-emptive command\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 }
198
Andrew Morton8d8706e2006-01-11 12:17:49 -0800199 if (!res) {
200 rio_dprintk(RIO_DEBUG_PARAM, "Port has no space on transmit queue\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 }
202
Andrew Morton8d8706e2006-01-11 12:17:49 -0800203 if (SleepFlag != OK_TO_SLEEP) {
204 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 func_exit();
Andrew Morton8d8706e2006-01-11 12:17:49 -0800206
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 return RIO_FAIL;
208 }
209
Andrew Morton8d8706e2006-01-11 12:17:49 -0800210 rio_dprintk(RIO_DEBUG_PARAM, "wait for can_add_transmit\n");
211 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 retval = RIODelay(PortP, HUNDRED_MS);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800213 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 if (retval == RIO_FAIL) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800215 rio_dprintk(RIO_DEBUG_PARAM, "wait for can_add_transmit broken by signal\n");
216 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 func_exit();
Alan Coxe2b3afd2006-03-24 03:18:27 -0800218 return -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800220 if (PortP->State & RIO_DELETED) {
221 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
222 func_exit();
Alan Cox554b7c82006-03-24 03:18:32 -0800223 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 }
225 }
226
227 if (!res) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800228 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
229 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231 return RIO_FAIL;
232 }
233
Andrew Morton8d8706e2006-01-11 12:17:49 -0800234 rio_dprintk(RIO_DEBUG_PARAM, "can_add_transmit() returns %x\n", res);
Alan Cox554b7c82006-03-24 03:18:32 -0800235 rio_dprintk(RIO_DEBUG_PARAM, "Packet is %p\n", PacketP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Al Virod886cb52006-05-27 00:08:25 -0400237 phb_param_ptr = (struct phb_param __iomem *) PacketP->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
239
Andrew Morton8d8706e2006-01-11 12:17:49 -0800240 switch (TtyP->termios->c_cflag & CSIZE) {
241 case CS5:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800243 rio_dprintk(RIO_DEBUG_PARAM, "5 bit data\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700244 Cor1 |= RIOC_COR1_5BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 break;
246 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800247 case CS6:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800249 rio_dprintk(RIO_DEBUG_PARAM, "6 bit data\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700250 Cor1 |= RIOC_COR1_6BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 break;
252 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800253 case CS7:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800255 rio_dprintk(RIO_DEBUG_PARAM, "7 bit data\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700256 Cor1 |= RIOC_COR1_7BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 break;
258 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800259 case CS8:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800261 rio_dprintk(RIO_DEBUG_PARAM, "8 bit data\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700262 Cor1 |= RIOC_COR1_8BITS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 break;
264 }
265 }
266
Andrew Morton8d8706e2006-01-11 12:17:49 -0800267 if (TtyP->termios->c_cflag & CSTOPB) {
268 rio_dprintk(RIO_DEBUG_PARAM, "2 stop bits\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700269 Cor1 |= RIOC_COR1_2STOP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800270 } else {
271 rio_dprintk(RIO_DEBUG_PARAM, "1 stop bit\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700272 Cor1 |= RIOC_COR1_1STOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 }
274
Andrew Morton8d8706e2006-01-11 12:17:49 -0800275 if (TtyP->termios->c_cflag & PARENB) {
276 rio_dprintk(RIO_DEBUG_PARAM, "Enable parity\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700277 Cor1 |= RIOC_COR1_NORMAL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800278 } else {
279 rio_dprintk(RIO_DEBUG_PARAM, "Disable parity\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700280 Cor1 |= RIOC_COR1_NOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800282 if (TtyP->termios->c_cflag & PARODD) {
283 rio_dprintk(RIO_DEBUG_PARAM, "Odd parity\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700284 Cor1 |= RIOC_COR1_ODD;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800285 } else {
286 rio_dprintk(RIO_DEBUG_PARAM, "Even parity\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700287 Cor1 |= RIOC_COR1_EVEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 }
289
290 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800291 ** COR 2
292 */
293 if (TtyP->termios->c_iflag & IXON) {
294 rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop output control\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700295 Cor2 |= RIOC_COR2_IXON;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800296 } else {
297 if (PortP->Config & RIO_IXON) {
298 rio_dprintk(RIO_DEBUG_PARAM, "Force enable start/stop output control\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700299 Cor2 |= RIOC_COR2_IXON;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800300 } else
301 rio_dprintk(RIO_DEBUG_PARAM, "IXON has been disabled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 }
303
304 if (TtyP->termios->c_iflag & IXANY) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800305 if (PortP->Config & RIO_IXANY) {
306 rio_dprintk(RIO_DEBUG_PARAM, "Enable any key to restart output\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700307 Cor2 |= RIOC_COR2_IXANY;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800308 } else
309 rio_dprintk(RIO_DEBUG_PARAM, "IXANY has been disabled due to sanity reasons.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 }
311
Andrew Morton8d8706e2006-01-11 12:17:49 -0800312 if (TtyP->termios->c_iflag & IXOFF) {
313 rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop input control 2\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700314 Cor2 |= RIOC_COR2_IXOFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 }
316
Andrew Morton8d8706e2006-01-11 12:17:49 -0800317 if (TtyP->termios->c_cflag & HUPCL) {
318 rio_dprintk(RIO_DEBUG_PARAM, "Hangup on last close\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700319 Cor2 |= RIOC_COR2_HUPCL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 }
321
Andrew Morton8d8706e2006-01-11 12:17:49 -0800322 if (C_CRTSCTS(TtyP)) {
323 rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control enabled\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700324 Cor2 |= RIOC_COR2_CTSFLOW;
325 Cor2 |= RIOC_COR2_RTSFLOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 } else {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800327 rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control disabled\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700328 Cor2 &= ~RIOC_COR2_CTSFLOW;
329 Cor2 &= ~RIOC_COR2_RTSFLOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 }
331
332
Andrew Morton8d8706e2006-01-11 12:17:49 -0800333 if (TtyP->termios->c_cflag & CLOCAL) {
334 rio_dprintk(RIO_DEBUG_PARAM, "Local line\n");
335 } else {
336 rio_dprintk(RIO_DEBUG_PARAM, "Possible Modem line\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 }
338
339 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800340 ** COR 4 (there is no COR 3)
341 */
342 if (TtyP->termios->c_iflag & IGNBRK) {
343 rio_dprintk(RIO_DEBUG_PARAM, "Ignore break condition\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700344 Cor4 |= RIOC_COR4_IGNBRK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800346 if (!(TtyP->termios->c_iflag & BRKINT)) {
347 rio_dprintk(RIO_DEBUG_PARAM, "Break generates NULL condition\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700348 Cor4 |= RIOC_COR4_NBRKINT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 } else {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800350 rio_dprintk(RIO_DEBUG_PARAM, "Interrupt on break condition\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 }
352
Andrew Morton8d8706e2006-01-11 12:17:49 -0800353 if (TtyP->termios->c_iflag & INLCR) {
354 rio_dprintk(RIO_DEBUG_PARAM, "Map newline to carriage return on input\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700355 Cor4 |= RIOC_COR4_INLCR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 }
357
Andrew Morton8d8706e2006-01-11 12:17:49 -0800358 if (TtyP->termios->c_iflag & IGNCR) {
359 rio_dprintk(RIO_DEBUG_PARAM, "Ignore carriage return on input\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700360 Cor4 |= RIOC_COR4_IGNCR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 }
362
Andrew Morton8d8706e2006-01-11 12:17:49 -0800363 if (TtyP->termios->c_iflag & ICRNL) {
364 rio_dprintk(RIO_DEBUG_PARAM, "Map carriage return to newline on input\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700365 Cor4 |= RIOC_COR4_ICRNL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800367 if (TtyP->termios->c_iflag & IGNPAR) {
368 rio_dprintk(RIO_DEBUG_PARAM, "Ignore characters with parity errors\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700369 Cor4 |= RIOC_COR4_IGNPAR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800371 if (TtyP->termios->c_iflag & PARMRK) {
372 rio_dprintk(RIO_DEBUG_PARAM, "Mark parity errors\n");
Jiri Slabyd6f63412008-04-30 00:53:57 -0700373 Cor4 |= RIOC_COR4_PARMRK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 }
375
376 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800377 ** Set the RAISEMOD flag to ensure that the modem lines are raised
378 ** on reception of a config packet.
379 ** The download code handles the zero baud condition.
380 */
Jiri Slabyd6f63412008-04-30 00:53:57 -0700381 Cor4 |= RIOC_COR4_RAISEMOD;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
383 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800384 ** COR 5
385 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Jiri Slabyd6f63412008-04-30 00:53:57 -0700387 Cor5 = RIOC_COR5_CMOE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
389 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800390 ** Set to monitor tbusy/tstop (or not).
391 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
393 if (PortP->MonitorTstate)
Jiri Slabyd6f63412008-04-30 00:53:57 -0700394 Cor5 |= RIOC_COR5_TSTATE_ON;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 else
Jiri Slabyd6f63412008-04-30 00:53:57 -0700396 Cor5 |= RIOC_COR5_TSTATE_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800399 ** Could set LNE here if you wanted LNext processing. SVR4 will use it.
400 */
401 if (TtyP->termios->c_iflag & ISTRIP) {
402 rio_dprintk(RIO_DEBUG_PARAM, "Strip input characters\n");
403 if (!(PortP->State & RIO_TRIAD_MODE)) {
Jiri Slabyd6f63412008-04-30 00:53:57 -0700404 Cor5 |= RIOC_COR5_ISTRIP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 }
406 }
407
Andrew Morton8d8706e2006-01-11 12:17:49 -0800408 if (TtyP->termios->c_oflag & ONLCR) {
409 rio_dprintk(RIO_DEBUG_PARAM, "Map newline to carriage-return, newline on output\n");
410 if (PortP->CookMode == COOK_MEDIUM)
Jiri Slabyd6f63412008-04-30 00:53:57 -0700411 Cor5 |= RIOC_COR5_ONLCR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800413 if (TtyP->termios->c_oflag & OCRNL) {
414 rio_dprintk(RIO_DEBUG_PARAM, "Map carriage return to newline on output\n");
415 if (PortP->CookMode == COOK_MEDIUM)
Jiri Slabyd6f63412008-04-30 00:53:57 -0700416 Cor5 |= RIOC_COR5_OCRNL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800418 if ((TtyP->termios->c_oflag & TABDLY) == TAB3) {
419 rio_dprintk(RIO_DEBUG_PARAM, "Tab delay 3 set\n");
420 if (PortP->CookMode == COOK_MEDIUM)
Jiri Slabyd6f63412008-04-30 00:53:57 -0700421 Cor5 |= RIOC_COR5_TAB3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 }
423
424 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800425 ** Flow control bytes.
426 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 TxXon = TtyP->termios->c_cc[VSTART];
428 TxXoff = TtyP->termios->c_cc[VSTOP];
429 RxXon = TtyP->termios->c_cc[VSTART];
430 RxXoff = TtyP->termios->c_cc[VSTOP];
431 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800432 ** LNEXT byte
433 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 LNext = 0;
435
436 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800437 ** Baud rate bytes
438 */
439 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 -0700440
441 switch (TtyP->termios->c_cflag & CBAUD) {
442#define e(b) case B ## b : RxBaud = TxBaud = RIO_B ## b ;break
Andrew Morton8d8706e2006-01-11 12:17:49 -0800443 e(50);
444 e(75);
445 e(110);
446 e(134);
447 e(150);
448 e(200);
449 e(300);
450 e(600);
451 e(1200);
452 e(1800);
453 e(2400);
454 e(4800);
455 e(9600);
456 e(19200);
457 e(38400);
458 e(57600);
459 e(115200); /* e(230400);e(460800); e(921600); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 }
461
Andrew Morton8d8706e2006-01-11 12:17:49 -0800462 rio_dprintk(RIO_DEBUG_PARAM, "tx baud 0x%x, rx baud 0x%x\n", TxBaud, RxBaud);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
464
465 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800466 ** Leftovers
467 */
468 if (TtyP->termios->c_cflag & CREAD)
469 rio_dprintk(RIO_DEBUG_PARAM, "Enable receiver\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470#ifdef RCV1EN
Andrew Morton8d8706e2006-01-11 12:17:49 -0800471 if (TtyP->termios->c_cflag & RCV1EN)
472 rio_dprintk(RIO_DEBUG_PARAM, "RCV1EN (?)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473#endif
474#ifdef XMT1EN
Andrew Morton8d8706e2006-01-11 12:17:49 -0800475 if (TtyP->termios->c_cflag & XMT1EN)
476 rio_dprintk(RIO_DEBUG_PARAM, "XMT1EN (?)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -0800478 if (TtyP->termios->c_lflag & ISIG)
479 rio_dprintk(RIO_DEBUG_PARAM, "Input character signal generating enabled\n");
480 if (TtyP->termios->c_lflag & ICANON)
481 rio_dprintk(RIO_DEBUG_PARAM, "Canonical input: erase and kill enabled\n");
482 if (TtyP->termios->c_lflag & XCASE)
483 rio_dprintk(RIO_DEBUG_PARAM, "Canonical upper/lower presentation\n");
484 if (TtyP->termios->c_lflag & ECHO)
485 rio_dprintk(RIO_DEBUG_PARAM, "Enable input echo\n");
486 if (TtyP->termios->c_lflag & ECHOE)
487 rio_dprintk(RIO_DEBUG_PARAM, "Enable echo erase\n");
488 if (TtyP->termios->c_lflag & ECHOK)
489 rio_dprintk(RIO_DEBUG_PARAM, "Enable echo kill\n");
490 if (TtyP->termios->c_lflag & ECHONL)
491 rio_dprintk(RIO_DEBUG_PARAM, "Enable echo newline\n");
492 if (TtyP->termios->c_lflag & NOFLSH)
493 rio_dprintk(RIO_DEBUG_PARAM, "Disable flush after interrupt or quit\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494#ifdef TOSTOP
Andrew Morton8d8706e2006-01-11 12:17:49 -0800495 if (TtyP->termios->c_lflag & TOSTOP)
496 rio_dprintk(RIO_DEBUG_PARAM, "Send SIGTTOU for background output\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497#endif
498#ifdef XCLUDE
Andrew Morton8d8706e2006-01-11 12:17:49 -0800499 if (TtyP->termios->c_lflag & XCLUDE)
500 rio_dprintk(RIO_DEBUG_PARAM, "Exclusive use of this line\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -0800502 if (TtyP->termios->c_iflag & IUCLC)
503 rio_dprintk(RIO_DEBUG_PARAM, "Map uppercase to lowercase on input\n");
504 if (TtyP->termios->c_oflag & OPOST)
505 rio_dprintk(RIO_DEBUG_PARAM, "Enable output post-processing\n");
506 if (TtyP->termios->c_oflag & OLCUC)
507 rio_dprintk(RIO_DEBUG_PARAM, "Map lowercase to uppercase on output\n");
508 if (TtyP->termios->c_oflag & ONOCR)
509 rio_dprintk(RIO_DEBUG_PARAM, "No carriage return output at column 0\n");
510 if (TtyP->termios->c_oflag & ONLRET)
511 rio_dprintk(RIO_DEBUG_PARAM, "Newline performs carriage return function\n");
512 if (TtyP->termios->c_oflag & OFILL)
513 rio_dprintk(RIO_DEBUG_PARAM, "Use fill characters for delay\n");
514 if (TtyP->termios->c_oflag & OFDEL)
515 rio_dprintk(RIO_DEBUG_PARAM, "Fill character is DEL\n");
516 if (TtyP->termios->c_oflag & NLDLY)
517 rio_dprintk(RIO_DEBUG_PARAM, "Newline delay set\n");
518 if (TtyP->termios->c_oflag & CRDLY)
519 rio_dprintk(RIO_DEBUG_PARAM, "Carriage return delay set\n");
520 if (TtyP->termios->c_oflag & TABDLY)
521 rio_dprintk(RIO_DEBUG_PARAM, "Tab delay set\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800523 ** These things are kind of useful in a later life!
524 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 PortP->Cor2Copy = Cor2;
526
Andrew Morton8d8706e2006-01-11 12:17:49 -0800527 if (PortP->State & RIO_DELETED) {
528 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
529 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
531 return RIO_FAIL;
532 }
533
534 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800535 ** Actually write the info into the packet to be sent
536 */
Alan Coxe2b3afd2006-03-24 03:18:27 -0800537 writeb(cmd, &phb_param_ptr->Cmd);
538 writeb(Cor1, &phb_param_ptr->Cor1);
539 writeb(Cor2, &phb_param_ptr->Cor2);
540 writeb(Cor4, &phb_param_ptr->Cor4);
541 writeb(Cor5, &phb_param_ptr->Cor5);
542 writeb(TxXon, &phb_param_ptr->TxXon);
543 writeb(RxXon, &phb_param_ptr->RxXon);
544 writeb(TxXoff, &phb_param_ptr->TxXoff);
545 writeb(RxXoff, &phb_param_ptr->RxXoff);
546 writeb(LNext, &phb_param_ptr->LNext);
547 writeb(TxBaud, &phb_param_ptr->TxBaud);
548 writeb(RxBaud, &phb_param_ptr->RxBaud);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
550 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800551 ** Set the length/command field
552 */
Alan Coxe2b3afd2006-03-24 03:18:27 -0800553 writeb(12 | PKT_CMD_BIT, &PacketP->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
555 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800556 ** The packet is formed - now, whack it off
557 ** to its final destination:
558 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 add_transmit(PortP);
560 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800561 ** Count characters transmitted for port statistics reporting
562 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 if (PortP->statsGather)
564 PortP->txchars += 12;
565
Andrew Morton8d8706e2006-01-11 12:17:49 -0800566 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Andrew Morton8d8706e2006-01-11 12:17:49 -0800568 rio_dprintk(RIO_DEBUG_PARAM, "add_transmit returned.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800570 ** job done.
571 */
572 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
Alan Cox554b7c82006-03-24 03:18:32 -0800574 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575}
576
577
578/*
579** We can add another packet to a transmit queue if the packet pointer pointed
580** to by the TxAdd pointer has PKT_IN_USE clear in its address.
581*/
Al Virod886cb52006-05-27 00:08:25 -0400582int can_add_transmit(struct PKT __iomem **PktP, struct Port *PortP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583{
Al Virod886cb52006-05-27 00:08:25 -0400584 struct PKT __iomem *tp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Al Virod886cb52006-05-27 00:08:25 -0400586 *PktP = tp = (struct PKT __iomem *) RIO_PTR(PortP->Caddr, readw(PortP->TxAdd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
Alan Coxe2b3afd2006-03-24 03:18:27 -0800588 return !((unsigned long) tp & PKT_IN_USE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589}
590
591/*
592** To add a packet to the queue, you set the PKT_IN_USE bit in the address,
593** and then move the TxAdd pointer along one position to point to the next
594** packet pointer. You must wrap the pointer from the end back to the start.
595*/
Alan Coxe2b3afd2006-03-24 03:18:27 -0800596void add_transmit(struct Port *PortP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597{
Alan Coxe2b3afd2006-03-24 03:18:27 -0800598 if (readw(PortP->TxAdd) & PKT_IN_USE) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800599 rio_dprintk(RIO_DEBUG_PARAM, "add_transmit: Packet has been stolen!");
600 }
Alan Coxe2b3afd2006-03-24 03:18:27 -0800601 writew(readw(PortP->TxAdd) | PKT_IN_USE, PortP->TxAdd);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800602 PortP->TxAdd = (PortP->TxAdd == PortP->TxEnd) ? PortP->TxStart : PortP->TxAdd + 1;
Alan Coxe2b3afd2006-03-24 03:18:27 -0800603 writew(RIO_OFF(PortP->Caddr, PortP->TxAdd), &PortP->PhbP->tx_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604}
605
606/****************************************
607 * Put a packet onto the end of the
608 * free list
609 ****************************************/
Al Virod886cb52006-05-27 00:08:25 -0400610void put_free_end(struct Host *HostP, struct PKT __iomem *PktP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611{
Al Virod886cb52006-05-27 00:08:25 -0400612 struct rio_free_list __iomem *tmp_pointer;
Alan Cox554b7c82006-03-24 03:18:32 -0800613 unsigned short old_end, new_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 unsigned long flags;
615
616 rio_spin_lock_irqsave(&HostP->HostLock, flags);
617
618 /*************************************************
619 * Put a packet back onto the back of the free list
620 *
621 ************************************************/
622
Alan Coxe2b3afd2006-03-24 03:18:27 -0800623 rio_dprintk(RIO_DEBUG_PFE, "put_free_end(PktP=%p)\n", PktP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Alan Coxe2b3afd2006-03-24 03:18:27 -0800625 if ((old_end = readw(&HostP->ParmMapP->free_list_end)) != TPNULL) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800626 new_end = RIO_OFF(HostP->Caddr, PktP);
Al Virod886cb52006-05-27 00:08:25 -0400627 tmp_pointer = (struct rio_free_list __iomem *) RIO_PTR(HostP->Caddr, old_end);
Alan Coxe2b3afd2006-03-24 03:18:27 -0800628 writew(new_end, &tmp_pointer->next);
Al Virod886cb52006-05-27 00:08:25 -0400629 writew(old_end, &((struct rio_free_list __iomem *) PktP)->prev);
630 writew(TPNULL, &((struct rio_free_list __iomem *) PktP)->next);
Alan Coxe2b3afd2006-03-24 03:18:27 -0800631 writew(new_end, &HostP->ParmMapP->free_list_end);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800632 } else { /* First packet on the free list this should never happen! */
633 rio_dprintk(RIO_DEBUG_PFE, "put_free_end(): This should never happen\n");
Alan Coxe2b3afd2006-03-24 03:18:27 -0800634 writew(RIO_OFF(HostP->Caddr, PktP), &HostP->ParmMapP->free_list_end);
Al Virod886cb52006-05-27 00:08:25 -0400635 tmp_pointer = (struct rio_free_list __iomem *) PktP;
Alan Coxe2b3afd2006-03-24 03:18:27 -0800636 writew(TPNULL, &tmp_pointer->prev);
637 writew(TPNULL, &tmp_pointer->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800639 rio_dprintk(RIO_DEBUG_CMD, "Before unlock: %p\n", &HostP->HostLock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
641}
642
643/*
644** can_remove_receive(PktP,P) returns non-zero if PKT_IN_USE is set
645** for the next packet on the queue. It will also set PktP to point to the
646** relevant packet, [having cleared the PKT_IN_USE bit]. If PKT_IN_USE is clear,
647** then can_remove_receive() returns 0.
648*/
Al Virod886cb52006-05-27 00:08:25 -0400649int can_remove_receive(struct PKT __iomem **PktP, struct Port *PortP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650{
Alan Coxe2b3afd2006-03-24 03:18:27 -0800651 if (readw(PortP->RxRemove) & PKT_IN_USE) {
Al Virod886cb52006-05-27 00:08:25 -0400652 *PktP = (struct PKT __iomem *) RIO_PTR(PortP->Caddr, readw(PortP->RxRemove) & ~PKT_IN_USE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 return 1;
654 }
655 return 0;
656}
657
658/*
659** To remove a packet from the receive queue you clear its PKT_IN_USE bit,
660** and then bump the pointers. Once the pointers get to the end, they must
661** be wrapped back to the start.
662*/
Alan Coxe2b3afd2006-03-24 03:18:27 -0800663void remove_receive(struct Port *PortP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664{
Alan Coxe2b3afd2006-03-24 03:18:27 -0800665 writew(readw(PortP->RxRemove) & ~PKT_IN_USE, PortP->RxRemove);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800666 PortP->RxRemove = (PortP->RxRemove == PortP->RxEnd) ? PortP->RxStart : PortP->RxRemove + 1;
Alan Coxe2b3afd2006-03-24 03:18:27 -0800667 writew(RIO_OFF(PortP->Caddr, PortP->RxRemove), &PortP->PhbP->rx_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668}