blob: c9af283a811dc2c84f6153637df2c30d14ba8463 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2/* rio_linux.c -- Linux driver for the Specialix RIO series cards.
3 *
4 *
5 * (C) 1999 R.E.Wolff@BitWizard.nl
6 *
7 * Specialix pays for the development and support of this driver.
8 * Please DO contact support@specialix.co.uk if you require
9 * support. But please read the documentation (rio.txt) first.
10 *
11 *
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be
19 * useful, but WITHOUT ANY WARRANTY; without even the implied
20 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
21 * PURPOSE. See the GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public
24 * License along with this program; if not, write to the Free
25 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
26 * USA.
27 *
28 * Revision history:
29 * $Log: rio.c,v $
30 * Revision 1.1 1999/07/11 10:13:54 wolff
31 * Initial revision
32 *
33 * */
34
35#include <linux/module.h>
Andrew Morton8d8706e2006-01-11 12:17:49 -080036#include <linux/config.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/kdev_t.h>
38#include <asm/io.h>
39#include <linux/kernel.h>
40#include <linux/sched.h>
41#include <linux/ioport.h>
42#include <linux/interrupt.h>
43#include <linux/errno.h>
44#include <linux/tty.h>
45#include <linux/tty_flip.h>
46#include <linux/mm.h>
47#include <linux/serial.h>
48#include <linux/fcntl.h>
49#include <linux/major.h>
50#include <linux/delay.h>
51#include <linux/pci.h>
52#include <linux/slab.h>
53#include <linux/miscdevice.h>
54#include <linux/init.h>
55
56#include <linux/generic_serial.h>
57#include <asm/uaccess.h>
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#include "linux_compat.h"
60#include "typdef.h"
61#include "pkt.h"
62#include "daemon.h"
63#include "rio.h"
64#include "riospace.h"
65#include "top.h"
66#include "cmdpkt.h"
67#include "map.h"
68#include "riotypes.h"
69#include "rup.h"
70#include "port.h"
71#include "riodrvr.h"
72#include "rioinfo.h"
73#include "func.h"
74#include "errors.h"
75#include "pci.h"
76
77#include "parmmap.h"
78#include "unixrup.h"
79#include "board.h"
80#include "host.h"
81#include "error.h"
82#include "phb.h"
83#include "link.h"
84#include "cmdblk.h"
85#include "route.h"
86#include "control.h"
87#include "cirrus.h"
88#include "rioioctl.h"
89#include "param.h"
90#include "list.h"
91#include "sam.h"
92#include "protsts.h"
93#include "rioboard.h"
94
95
96#include "rio_linux.h"
97
98/* I don't think that this driver can handle more than 512 ports on
99one machine. Specialix specifies max 4 boards in one machine. I don't
100know why. If you want to try anyway you'll have to increase the number
101of boards in rio.h. You'll have to allocate more majors if you need
102more than 512 ports.... */
103
104#ifndef RIO_NORMAL_MAJOR0
105/* This allows overriding on the compiler commandline, or in a "major.h"
106 include or something like that */
107#define RIO_NORMAL_MAJOR0 154
108#define RIO_NORMAL_MAJOR1 156
109#endif
110
111#ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8
112#define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
113#endif
114
Andrew Morton8d8706e2006-01-11 12:17:49 -0800115#ifndef RIO_WINDOW_LEN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116#define RIO_WINDOW_LEN 0x10000
117#endif
118
119
120/* Configurable options:
121 (Don't be too sure that it'll work if you toggle them) */
122
123/* Am I paranoid or not ? ;-) */
124#undef RIO_PARANOIA_CHECK
125
126
127/* 20 -> 2000 per second. The card should rate-limit interrupts at 1000
128 Hz, but it is user configurable. I don't recommend going above 1000
129 Hz. The interrupt ratelimit might trigger if the interrupt is
130 shared with a very active other device.
131 undef this if you want to disable the check....
132*/
133#define IRQ_RATE_LIMIT 200
134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136/* These constants are derived from SCO Source */
137static struct Conf
Andrew Morton8d8706e2006-01-11 12:17:49 -0800138 RIOConf = {
139 /* locator */ "RIO Config here",
140 /* startuptime */ HZ * 2,
141 /* how long to wait for card to run */
142 /* slowcook */ 0,
143 /* TRUE -> always use line disc. */
144 /* intrpolltime */ 1,
145 /* The frequency of OUR polls */
146 /* breakinterval */ 25,
147 /* x10 mS XXX: units seem to be 1ms not 10! -- REW */
148 /* timer */ 10,
149 /* mS */
150 /* RtaLoadBase */ 0x7000,
151 /* HostLoadBase */ 0x7C00,
152 /* XpHz */ 5,
153 /* number of Xprint hits per second */
154 /* XpCps */ 120,
155 /* Xprint characters per second */
156 /* XpOn */ "\033d#",
157 /* start Xprint for a wyse 60 */
158 /* XpOff */ "\024",
159 /* end Xprint for a wyse 60 */
160 /* MaxXpCps */ 2000,
161 /* highest Xprint speed */
162 /* MinXpCps */ 10,
163 /* slowest Xprint speed */
164 /* SpinCmds */ 1,
165 /* non-zero for mega fast boots */
166 /* First Addr */ 0x0A0000,
167 /* First address to look at */
168 /* Last Addr */ 0xFF0000,
169 /* Last address looked at */
170 /* BufferSize */ 1024,
171 /* Bytes per port of buffering */
172 /* LowWater */ 256,
173 /* how much data left before wakeup */
174 /* LineLength */ 80,
175 /* how wide is the console? */
176 /* CmdTimeout */ HZ,
177 /* how long a close command may take */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178};
179
180
181
182
183/* Function prototypes */
184
Andrew Morton8d8706e2006-01-11 12:17:49 -0800185static void rio_disable_tx_interrupts(void *ptr);
186static void rio_enable_tx_interrupts(void *ptr);
187static void rio_disable_rx_interrupts(void *ptr);
188static void rio_enable_rx_interrupts(void *ptr);
189static int rio_get_CD(void *ptr);
190static void rio_shutdown_port(void *ptr);
191static int rio_set_real_termios(void *ptr);
192static void rio_hungup(void *ptr);
193static void rio_close(void *ptr);
194static int rio_chars_in_buffer(void *ptr);
195static int rio_fw_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196static int rio_init_drivers(void);
197
Andrew Morton8d8706e2006-01-11 12:17:49 -0800198static void my_hd(void *addr, int len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200static struct tty_driver *rio_driver, *rio_driver2;
201
202/* The name "p" is a bit non-descript. But that's what the rio-lynxos
203sources use all over the place. */
204struct rio_info *p;
205
206int rio_debug;
207
208
209/* You can have the driver poll your card.
210 - Set rio_poll to 1 to poll every timer tick (10ms on Intel).
211 This is used when the card cannot use an interrupt for some reason.
212*/
213static int rio_poll = 1;
214
215
216/* These are the only open spaces in my computer. Yours may have more
217 or less.... */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800218static int rio_probe_addrs[] = { 0xc0000, 0xd0000, 0xe0000 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Tobias Klauserfe971072006-01-09 20:54:02 -0800220#define NR_RIO_ADDRS ARRAY_SIZE(rio_probe_addrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222
223/* Set the mask to all-ones. This alas, only supports 32 interrupts.
224 Some architectures may need more. -- Changed to LONG to
225 support up to 64 bits on 64bit architectures. -- REW 20/06/99 */
Adrian Bunk408b6642005-05-01 08:59:29 -0700226static long rio_irqmask = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228MODULE_AUTHOR("Rogier Wolff <R.E.Wolff@bitwizard.nl>, Patrick van de Lageweg <patrick@bitwizard.nl>");
229MODULE_DESCRIPTION("RIO driver");
230MODULE_LICENSE("GPL");
231module_param(rio_poll, int, 0);
232module_param(rio_debug, int, 0644);
233module_param(rio_irqmask, long, 0);
234
235static struct real_driver rio_real_driver = {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800236 rio_disable_tx_interrupts,
237 rio_enable_tx_interrupts,
238 rio_disable_rx_interrupts,
239 rio_enable_rx_interrupts,
240 rio_get_CD,
241 rio_shutdown_port,
242 rio_set_real_termios,
243 rio_chars_in_buffer,
244 rio_close,
245 rio_hungup,
246 NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247};
248
249/*
250 * Firmware loader driver specific routines
251 *
252 */
253
254static struct file_operations rio_fw_fops = {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800255 .owner = THIS_MODULE,
256 .ioctl = rio_fw_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257};
258
259static struct miscdevice rio_fw_device = {
260 RIOCTL_MISC_MINOR, "rioctl", &rio_fw_fops
261};
262
263
264
265
266
267#ifdef RIO_PARANOIA_CHECK
268
269/* This doesn't work. Who's paranoid around here? Not me! */
270
Andrew Morton8d8706e2006-01-11 12:17:49 -0800271static inline int rio_paranoia_check(struct rio_port const *port, char *name, const char *routine)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272{
273
Andrew Morton8d8706e2006-01-11 12:17:49 -0800274 static const char *badmagic = KERN_ERR "rio: Warning: bad rio port magic number for device %s in %s\n";
275 static const char *badinfo = KERN_ERR "rio: Warning: null rio port for device %s in %s\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Andrew Morton8d8706e2006-01-11 12:17:49 -0800277 if (!port) {
278 printk(badinfo, name, routine);
279 return 1;
280 }
281 if (port->magic != RIO_MAGIC) {
282 printk(badmagic, name, routine);
283 return 1;
284 }
285
286 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287}
288#else
289#define rio_paranoia_check(a,b,c) 0
290#endif
291
292
293#ifdef DEBUG
Andrew Morton8d8706e2006-01-11 12:17:49 -0800294static void my_hd(void *ad, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800296 int i, j, ch;
297 unsigned char *addr = ad;
298
299 for (i = 0; i < len; i += 16) {
300 rio_dprintk(RIO_DEBUG_PARAM, "%08x ", (int) addr + i);
301 for (j = 0; j < 16; j++) {
302 rio_dprintk(RIO_DEBUG_PARAM, "%02x %s", addr[j + i], (j == 7) ? " " : "");
303 }
304 for (j = 0; j < 16; j++) {
305 ch = addr[j + i];
306 rio_dprintk(RIO_DEBUG_PARAM, "%c", (ch < 0x20) ? '.' : ((ch > 0x7f) ? '.' : ch));
307 }
308 rio_dprintk(RIO_DEBUG_PARAM, "\n");
309 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310}
311#else
312#define my_hd(ad,len) do{/* nothing*/ } while (0)
313#endif
314
315
Andrew Morton8d8706e2006-01-11 12:17:49 -0800316/* Delay a number of jiffies, allowing a signal to interrupt */
317int RIODelay(struct Port *PortP, int njiffies)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800319 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Andrew Morton8d8706e2006-01-11 12:17:49 -0800321 rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies\n", njiffies);
322 msleep_interruptible(jiffies_to_msecs(njiffies));
323 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
Andrew Morton8d8706e2006-01-11 12:17:49 -0800325 if (signal_pending(current))
326 return RIO_FAIL;
327 else
328 return !RIO_FAIL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329}
330
331
Andrew Morton8d8706e2006-01-11 12:17:49 -0800332/* Delay a number of jiffies, disallowing a signal to interrupt */
333int RIODelay_ni(struct Port *PortP, int njiffies)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800335 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
Andrew Morton8d8706e2006-01-11 12:17:49 -0800337 rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies (ni)\n", njiffies);
338 msleep(jiffies_to_msecs(njiffies));
339 func_exit();
340 return !RIO_FAIL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341}
342
343
344int rio_minor(struct tty_struct *tty)
345{
346 return tty->index + (tty->driver == rio_driver) ? 0 : 256;
347}
348
349
350int rio_ismodem(struct tty_struct *tty)
351{
352 return 1;
353}
354
355
Andrew Morton8d8706e2006-01-11 12:17:49 -0800356static int rio_set_real_termios(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800358 int rv, modem;
359 struct tty_struct *tty;
360 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Andrew Morton8d8706e2006-01-11 12:17:49 -0800362 tty = ((struct Port *) ptr)->gs.tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Andrew Morton8d8706e2006-01-11 12:17:49 -0800364 modem = rio_ismodem(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Andrew Morton8d8706e2006-01-11 12:17:49 -0800366 rv = RIOParam((struct Port *) ptr, CONFIG, modem, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Andrew Morton8d8706e2006-01-11 12:17:49 -0800368 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Andrew Morton8d8706e2006-01-11 12:17:49 -0800370 return rv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371}
372
373
Andrew Morton8d8706e2006-01-11 12:17:49 -0800374static void rio_reset_interrupt(struct Host *HostP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800376 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Andrew Morton8d8706e2006-01-11 12:17:49 -0800378 switch (HostP->Type) {
379 case RIO_AT:
380 case RIO_MCA:
381 case RIO_PCI:
382 WBYTE(HostP->ResetInt, 0xff);
383 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Andrew Morton8d8706e2006-01-11 12:17:49 -0800385 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386}
387
388
Andrew Morton8d8706e2006-01-11 12:17:49 -0800389static irqreturn_t rio_interrupt(int irq, void *ptr, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800391 struct Host *HostP;
392 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Andrew Morton8d8706e2006-01-11 12:17:49 -0800394 HostP = (struct Host *) ptr; /* &p->RIOHosts[(long)ptr]; */
395 rio_dprintk(RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Andrew Morton8d8706e2006-01-11 12:17:49 -0800397 /* AAargh! The order in which to do these things is essential and
398 not trivial.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Andrew Morton8d8706e2006-01-11 12:17:49 -0800400 - Rate limit goes before "recursive". Otherwise a series of
401 recursive calls will hang the machine in the interrupt routine.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Andrew Morton8d8706e2006-01-11 12:17:49 -0800403 - hardware twiddling goes before "recursive". Otherwise when we
404 poll the card, and a recursive interrupt happens, we won't
405 ack the card, so it might keep on interrupting us. (especially
406 level sensitive interrupt systems like PCI).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Andrew Morton8d8706e2006-01-11 12:17:49 -0800408 - Rate limit goes before hardware twiddling. Otherwise we won't
409 catch a card that has gone bonkers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Andrew Morton8d8706e2006-01-11 12:17:49 -0800411 - The "initialized" test goes after the hardware twiddling. Otherwise
412 the card will stick us in the interrupt routine again.
413
414 - The initialized test goes before recursive.
415 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
417
418
419#ifdef IRQ_RATE_LIMIT
Andrew Morton8d8706e2006-01-11 12:17:49 -0800420 /* Aaargh! I'm ashamed. This costs more lines-of-code than the
421 actual interrupt routine!. (Well, used to when I wrote that comment) */
422 {
423 static int lastjif;
424 static int nintr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Andrew Morton8d8706e2006-01-11 12:17:49 -0800426 if (lastjif == jiffies) {
427 if (++nintr > IRQ_RATE_LIMIT) {
428 free_irq(HostP->Ivec, ptr);
429 printk(KERN_ERR "rio: Too many interrupts. Turning off interrupt %d.\n", HostP->Ivec);
430 }
431 } else {
432 lastjif = jiffies;
433 nintr = 0;
434 }
435 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -0800437 rio_dprintk(RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n");
438 if (HostP->Ivec == irq) {
439 /* Tell the card we've noticed the interrupt. */
440 rio_reset_interrupt(HostP);
441 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
Andrew Morton8d8706e2006-01-11 12:17:49 -0800443 if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
444 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Andrew Morton8d8706e2006-01-11 12:17:49 -0800446 if (test_and_set_bit(RIO_BOARD_INTR_LOCK, &HostP->locks)) {
447 printk(KERN_ERR "Recursive interrupt! (host %d/irq%d)\n", (int) ptr, HostP->Ivec);
448 return IRQ_HANDLED;
449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Andrew Morton8d8706e2006-01-11 12:17:49 -0800451 RIOServiceHost(p, HostP, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Andrew Morton8d8706e2006-01-11 12:17:49 -0800453 rio_dprintk(RIO_DEBUG_IFLOW, "riointr() doing host %d type %d\n", (int) ptr, HostP->Type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
Andrew Morton8d8706e2006-01-11 12:17:49 -0800455 clear_bit(RIO_BOARD_INTR_LOCK, &HostP->locks);
456 rio_dprintk(RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
457 func_exit();
458 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459}
460
461
Andrew Morton8d8706e2006-01-11 12:17:49 -0800462static void rio_pollfunc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800464 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Andrew Morton8d8706e2006-01-11 12:17:49 -0800466 rio_interrupt(0, &p->RIOHosts[data], NULL);
467 p->RIOHosts[data].timer.expires = jiffies + rio_poll;
468 add_timer(&p->RIOHosts[data].timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Andrew Morton8d8706e2006-01-11 12:17:49 -0800470 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471}
472
473
474/* ********************************************************************** *
475 * Here are the routines that actually *
476 * interface with the generic_serial driver *
477 * ********************************************************************** */
478
479/* Ehhm. I don't know how to fiddle with interrupts on the Specialix
480 cards. .... Hmm. Ok I figured it out. You don't. -- REW */
481
Andrew Morton8d8706e2006-01-11 12:17:49 -0800482static void rio_disable_tx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800484 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Andrew Morton8d8706e2006-01-11 12:17:49 -0800486 /* port->gs.flags &= ~GS_TX_INTEN; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Andrew Morton8d8706e2006-01-11 12:17:49 -0800488 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489}
490
491
Andrew Morton8d8706e2006-01-11 12:17:49 -0800492static void rio_enable_tx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800494 struct Port *PortP = ptr;
495 /* int hn; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
Andrew Morton8d8706e2006-01-11 12:17:49 -0800497 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
Andrew Morton8d8706e2006-01-11 12:17:49 -0800499 /* hn = PortP->HostP - p->RIOHosts;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
Andrew Morton8d8706e2006-01-11 12:17:49 -0800501 rio_dprintk (RIO_DEBUG_TTY, "Pushing host %d\n", hn);
502 rio_interrupt (-1,(void *) hn, NULL); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Andrew Morton8d8706e2006-01-11 12:17:49 -0800504 RIOTxEnable((char *) PortP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
Andrew Morton8d8706e2006-01-11 12:17:49 -0800506 /*
507 * In general we cannot count on "tx empty" interrupts, although
508 * the interrupt routine seems to be able to tell the difference.
509 */
510 PortP->gs.flags &= ~GS_TX_INTEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
Andrew Morton8d8706e2006-01-11 12:17:49 -0800512 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513}
514
515
Andrew Morton8d8706e2006-01-11 12:17:49 -0800516static void rio_disable_rx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800518 func_enter();
519 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520}
521
Andrew Morton8d8706e2006-01-11 12:17:49 -0800522static void rio_enable_rx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800524 /* struct rio_port *port = ptr; */
525 func_enter();
526 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527}
528
529
530/* Jeez. Isn't this simple? */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800531static int rio_get_CD(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800533 struct Port *PortP = ptr;
534 int rv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
Andrew Morton8d8706e2006-01-11 12:17:49 -0800536 func_enter();
537 rv = (PortP->ModemState & MSVR1_CD) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Andrew Morton8d8706e2006-01-11 12:17:49 -0800539 rio_dprintk(RIO_DEBUG_INIT, "Getting CD status: %d\n", rv);
540
541 func_exit();
542 return rv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543}
544
545
546/* Jeez. Isn't this simple? Actually, we can sync with the actual port
547 by just pushing stuff into the queue going to the port... */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800548static int rio_chars_in_buffer(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800550 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Andrew Morton8d8706e2006-01-11 12:17:49 -0800552 func_exit();
553 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554}
555
556
557/* Nothing special here... */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800558static void rio_shutdown_port(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800560 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
Andrew Morton8d8706e2006-01-11 12:17:49 -0800562 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
Andrew Morton8d8706e2006-01-11 12:17:49 -0800564 PortP = (struct Port *) ptr;
565 PortP->gs.tty = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800566 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567}
568
569
570/* I haven't the foggiest why the decrement use count has to happen
571 here. The whole linux serial drivers stuff needs to be redesigned.
572 My guess is that this is a hack to minimize the impact of a bug
573 elsewhere. Thinking about it some more. (try it sometime) Try
574 running minicom on a serial port that is driven by a modularized
575 driver. Have the modem hangup. Then remove the driver module. Then
576 exit minicom. I expect an "oops". -- REW */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800577static void rio_hungup(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800579 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Andrew Morton8d8706e2006-01-11 12:17:49 -0800581 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
Andrew Morton8d8706e2006-01-11 12:17:49 -0800583 PortP = (struct Port *) ptr;
584 PortP->gs.tty = NULL;
585
586 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587}
588
589
590/* The standard serial_close would become shorter if you'd wrap it like
591 this.
592 rs_close (...){save_flags;cli;real_close();dec_use_count;restore_flags;}
593 */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800594static void rio_close(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800596 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Andrew Morton8d8706e2006-01-11 12:17:49 -0800598 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
Andrew Morton8d8706e2006-01-11 12:17:49 -0800600 PortP = (struct Port *) ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Andrew Morton8d8706e2006-01-11 12:17:49 -0800602 riotclose(ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
Andrew Morton8d8706e2006-01-11 12:17:49 -0800604 if (PortP->gs.count) {
605 printk(KERN_ERR "WARNING port count:%d\n", PortP->gs.count);
606 PortP->gs.count = 0;
607 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Andrew Morton8d8706e2006-01-11 12:17:49 -0800609 PortP->gs.tty = NULL;
610 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611}
612
613
614
Andrew Morton8d8706e2006-01-11 12:17:49 -0800615static int rio_fw_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800617 int rc = 0;
618 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Andrew Morton8d8706e2006-01-11 12:17:49 -0800620 /* The "dev" argument isn't used. */
621 rc = riocontrol(p, 0, cmd, (void *) arg, capable(CAP_SYS_ADMIN));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
Andrew Morton8d8706e2006-01-11 12:17:49 -0800623 func_exit();
624 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625}
626
Andrew Morton8d8706e2006-01-11 12:17:49 -0800627extern int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
Andrew Morton8d8706e2006-01-11 12:17:49 -0800629static int rio_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800631 int rc;
632 struct Port *PortP;
633 int ival;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Andrew Morton8d8706e2006-01-11 12:17:49 -0800635 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
Andrew Morton8d8706e2006-01-11 12:17:49 -0800637 PortP = (struct Port *) tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Andrew Morton8d8706e2006-01-11 12:17:49 -0800639 rc = 0;
640 switch (cmd) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800641 case TIOCSSOFTCAR:
642 if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
643 tty->termios->c_cflag = (tty->termios->c_cflag & ~CLOCAL) | (ival ? CLOCAL : 0);
644 }
645 break;
646 case TIOCGSERIAL:
647 rc = -EFAULT;
648 if (access_ok(VERIFY_WRITE, (void *) arg, sizeof(struct serial_struct)))
649 rc = gs_getserial(&PortP->gs, (struct serial_struct *) arg);
650 break;
651 case TCSBRK:
652 if (PortP->State & RIO_DELETED) {
653 rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
654 rc = -EIO;
655 } else {
656 if (RIOShortCommand(p, PortP, SBREAK, 2, 250) == RIO_FAIL) {
657 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
658 rc = -EIO;
659 }
660 }
661 break;
662 case TCSBRKP:
663 if (PortP->State & RIO_DELETED) {
664 rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
665 rc = -EIO;
666 } else {
667 int l;
668 l = arg ? arg * 100 : 250;
669 if (l > 255)
670 l = 255;
671 if (RIOShortCommand(p, PortP, SBREAK, 2, arg ? arg * 100 : 250) == RIO_FAIL) {
672 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
673 rc = -EIO;
674 }
675 }
676 break;
677 case TIOCSSERIAL:
678 rc = -EFAULT;
679 if (access_ok(VERIFY_READ, (void *) arg, sizeof(struct serial_struct)))
680 rc = gs_setserial(&PortP->gs, (struct serial_struct *) arg);
681 break;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800682 default:
683 rc = -ENOIOCTLCMD;
684 break;
685 }
686 func_exit();
687 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688}
689
690
691/* The throttle/unthrottle scheme for the Specialix card is different
692 * from other drivers and deserves some explanation.
693 * The Specialix hardware takes care of XON/XOFF
694 * and CTS/RTS flow control itself. This means that all we have to
695 * do when signalled by the upper tty layer to throttle/unthrottle is
696 * to make a note of it here. When we come to read characters from the
697 * rx buffers on the card (rio_receive_chars()) we look to see if the
698 * upper layer can accept more (as noted here in rio_rx_throt[]).
699 * If it can't we simply don't remove chars from the cards buffer.
700 * When the tty layer can accept chars, we again note that here and when
701 * rio_receive_chars() is called it will remove them from the cards buffer.
702 * The card will notice that a ports buffer has drained below some low
703 * water mark and will unflow control the line itself, using whatever
704 * flow control scheme is in use for that port. -- Simon Allen
705 */
706
Andrew Morton8d8706e2006-01-11 12:17:49 -0800707static void rio_throttle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800709 struct Port *port = (struct Port *) tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Andrew Morton8d8706e2006-01-11 12:17:49 -0800711 func_enter();
712 /* If the port is using any type of input flow
713 * control then throttle the port.
714 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Andrew Morton8d8706e2006-01-11 12:17:49 -0800716 if ((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty))) {
717 port->State |= RIO_THROTTLE_RX;
718 }
719
720 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721}
722
723
Andrew Morton8d8706e2006-01-11 12:17:49 -0800724static void rio_unthrottle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800726 struct Port *port = (struct Port *) tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
Andrew Morton8d8706e2006-01-11 12:17:49 -0800728 func_enter();
729 /* Always unthrottle even if flow control is not enabled on
730 * this port in case we disabled flow control while the port
731 * was throttled
732 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
Andrew Morton8d8706e2006-01-11 12:17:49 -0800734 port->State &= ~RIO_THROTTLE_RX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
Andrew Morton8d8706e2006-01-11 12:17:49 -0800736 func_exit();
737 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738}
739
740
741
742
743
744/* ********************************************************************** *
745 * Here are the initialization routines. *
746 * ********************************************************************** */
747
748
Andrew Morton8d8706e2006-01-11 12:17:49 -0800749static struct vpd_prom *get_VPD_PROM(struct Host *hp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800751 static struct vpd_prom vpdp;
752 char *p;
753 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Andrew Morton8d8706e2006-01-11 12:17:49 -0800755 func_enter();
756 rio_dprintk(RIO_DEBUG_PROBE, "Going to verify vpd prom at %p.\n", hp->Caddr + RIO_VPD_ROM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
Andrew Morton8d8706e2006-01-11 12:17:49 -0800758 p = (char *) &vpdp;
759 for (i = 0; i < sizeof(struct vpd_prom); i++)
760 *p++ = readb(hp->Caddr + RIO_VPD_ROM + i * 2);
761 /* read_rio_byte (hp, RIO_VPD_ROM + i*2); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
Andrew Morton8d8706e2006-01-11 12:17:49 -0800763 /* Terminate the identifier string.
764 *** requires one extra byte in struct vpd_prom *** */
765 *p++ = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766
Andrew Morton8d8706e2006-01-11 12:17:49 -0800767 if (rio_debug & RIO_DEBUG_PROBE)
768 my_hd((char *) &vpdp, 0x20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
Andrew Morton8d8706e2006-01-11 12:17:49 -0800770 func_exit();
771
772 return &vpdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773}
774
775static struct tty_operations rio_ops = {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800776 .open = riotopen,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 .close = gs_close,
778 .write = gs_write,
779 .put_char = gs_put_char,
780 .flush_chars = gs_flush_chars,
781 .write_room = gs_write_room,
782 .chars_in_buffer = gs_chars_in_buffer,
783 .flush_buffer = gs_flush_buffer,
784 .ioctl = rio_ioctl,
785 .throttle = rio_throttle,
786 .unthrottle = rio_unthrottle,
787 .set_termios = gs_set_termios,
788 .stop = gs_stop,
789 .start = gs_start,
790 .hangup = gs_hangup,
791};
792
793static int rio_init_drivers(void)
794{
795 int error = -ENOMEM;
796
797 rio_driver = alloc_tty_driver(256);
798 if (!rio_driver)
799 goto out;
800 rio_driver2 = alloc_tty_driver(256);
801 if (!rio_driver2)
802 goto out1;
803
804 func_enter();
805
806 rio_driver->owner = THIS_MODULE;
807 rio_driver->driver_name = "specialix_rio";
808 rio_driver->name = "ttySR";
809 rio_driver->major = RIO_NORMAL_MAJOR0;
810 rio_driver->type = TTY_DRIVER_TYPE_SERIAL;
811 rio_driver->subtype = SERIAL_TYPE_NORMAL;
812 rio_driver->init_termios = tty_std_termios;
813 rio_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
814 rio_driver->flags = TTY_DRIVER_REAL_RAW;
815 tty_set_operations(rio_driver, &rio_ops);
816
817 rio_driver2->owner = THIS_MODULE;
818 rio_driver2->driver_name = "specialix_rio";
819 rio_driver2->name = "ttySR";
820 rio_driver2->major = RIO_NORMAL_MAJOR1;
821 rio_driver2->type = TTY_DRIVER_TYPE_SERIAL;
822 rio_driver2->subtype = SERIAL_TYPE_NORMAL;
823 rio_driver2->init_termios = tty_std_termios;
824 rio_driver2->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
825 rio_driver2->flags = TTY_DRIVER_REAL_RAW;
826 tty_set_operations(rio_driver2, &rio_ops);
827
Andrew Morton8d8706e2006-01-11 12:17:49 -0800828 rio_dprintk(RIO_DEBUG_INIT, "set_termios = %p\n", gs_set_termios);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 if ((error = tty_register_driver(rio_driver)))
831 goto out2;
832 if ((error = tty_register_driver(rio_driver2)))
833 goto out3;
834 func_exit();
835 return 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800836 out3:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 tty_unregister_driver(rio_driver);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800838 out2:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 put_tty_driver(rio_driver2);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800840 out1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 put_tty_driver(rio_driver);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800842 out:
843 printk(KERN_ERR "rio: Couldn't register a rio driver, error = %d\n", error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 return 1;
845}
846
847
Andrew Morton8d8706e2006-01-11 12:17:49 -0800848static void *ckmalloc(int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800850 void *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Andrew Morton8d8706e2006-01-11 12:17:49 -0800852 p = kmalloc(size, GFP_KERNEL);
853 if (p)
854 memset(p, 0, size);
855 return p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856}
857
858
859
Andrew Morton8d8706e2006-01-11 12:17:49 -0800860static int rio_init_datastructures(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800862 int i;
863 struct Port *port;
864 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
Andrew Morton8d8706e2006-01-11 12:17:49 -0800866 /* Many drivers statically allocate the maximum number of ports
867 There is no reason not to allocate them dynamically. Is there? -- REW */
868 /* However, the RIO driver allows users to configure their first
869 RTA as the ports numbered 504-511. We therefore need to allocate
870 the whole range. :-( -- REW */
871
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872#define RI_SZ sizeof(struct rio_info)
873#define HOST_SZ sizeof(struct Host)
874#define PORT_SZ sizeof(struct Port *)
875#define TMIO_SZ sizeof(struct termios *)
Andrew Morton8d8706e2006-01-11 12:17:49 -0800876 rio_dprintk(RIO_DEBUG_INIT, "getting : %d %d %d %d %d bytes\n", RI_SZ, RIO_HOSTS * HOST_SZ, RIO_PORTS * PORT_SZ, RIO_PORTS * TMIO_SZ, RIO_PORTS * TMIO_SZ);
877
878 if (!(p = ckmalloc(RI_SZ)))
879 goto free0;
880 if (!(p->RIOHosts = ckmalloc(RIO_HOSTS * HOST_SZ)))
881 goto free1;
882 if (!(p->RIOPortp = ckmalloc(RIO_PORTS * PORT_SZ)))
883 goto free2;
884 p->RIOConf = RIOConf;
885 rio_dprintk(RIO_DEBUG_INIT, "Got : %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
887#if 1
Andrew Morton8d8706e2006-01-11 12:17:49 -0800888 for (i = 0; i < RIO_PORTS; i++) {
889 port = p->RIOPortp[i] = ckmalloc(sizeof(struct Port));
890 if (!port) {
891 goto free6;
892 }
893 rio_dprintk(RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped);
894 port->PortNum = i;
895 port->gs.magic = RIO_MAGIC;
896 port->gs.close_delay = HZ / 2;
897 port->gs.closing_wait = 30 * HZ;
898 port->gs.rd = &rio_real_driver;
899 spin_lock_init(&port->portSem);
900 /*
901 * Initializing wait queue
902 */
903 init_waitqueue_head(&port->gs.open_wait);
904 init_waitqueue_head(&port->gs.close_wait);
905 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906#else
Andrew Morton8d8706e2006-01-11 12:17:49 -0800907 /* We could postpone initializing them to when they are configured. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908#endif
909
910
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
Andrew Morton8d8706e2006-01-11 12:17:49 -0800912 if (rio_debug & RIO_DEBUG_INIT) {
913 my_hd(&rio_real_driver, sizeof(rio_real_driver));
914 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Andrew Morton8d8706e2006-01-11 12:17:49 -0800916
917 func_exit();
918 return 0;
919
920 free6:for (i--; i >= 0; i--)
921 kfree(p->RIOPortp[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922/*free5:
923 free4:
Andrew Morton8d8706e2006-01-11 12:17:49 -0800924 free3:*/ kfree(p->RIOPortp);
925 free2:kfree(p->RIOHosts);
926 free1:
927 rio_dprintk(RIO_DEBUG_INIT, "Not enough memory! %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
928 kfree(p);
929 free0:
930 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931}
932
Andrew Morton8d8706e2006-01-11 12:17:49 -0800933static void __exit rio_release_drivers(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800935 func_enter();
936 tty_unregister_driver(rio_driver2);
937 tty_unregister_driver(rio_driver);
938 put_tty_driver(rio_driver2);
939 put_tty_driver(rio_driver);
940 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941}
942
943
944#ifdef CONFIG_PCI
945 /* This was written for SX, but applies to RIO too...
946 (including bugs....)
947
948 There is another bit besides Bit 17. Turning that bit off
949 (on boards shipped with the fix in the eeprom) results in a
950 hang on the next access to the card.
Andrew Morton8d8706e2006-01-11 12:17:49 -0800951 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
953 /********************************************************
954 * Setting bit 17 in the CNTRL register of the PLX 9050 *
955 * chip forces a retry on writes while a read is pending.*
956 * This is to prevent the card locking up on Intel Xeon *
957 * multiprocessor systems with the NX chipset. -- NV *
958 ********************************************************/
959
960/* Newer cards are produced with this bit set from the configuration
961 EEprom. As the bit is read/write for the CPU, we can fix it here,
962 if we detect that it isn't set correctly. -- REW */
963
Andrew Morton8d8706e2006-01-11 12:17:49 -0800964static void fix_rio_pci(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800966 unsigned int hwbase;
967 unsigned long rebase;
968 unsigned int t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
970#define CNTRL_REG_OFFSET 0x50
971#define CNTRL_REG_GOODVALUE 0x18260000
972
Andrew Morton8d8706e2006-01-11 12:17:49 -0800973 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase);
974 hwbase &= PCI_BASE_ADDRESS_MEM_MASK;
975 rebase = (ulong) ioremap(hwbase, 0x80);
976 t = readl(rebase + CNTRL_REG_OFFSET);
977 if (t != CNTRL_REG_GOODVALUE) {
978 printk(KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n", t, CNTRL_REG_GOODVALUE);
979 writel(CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
980 }
981 iounmap((char *) rebase);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982}
983#endif
984
985
Andrew Morton8d8706e2006-01-11 12:17:49 -0800986static int __init rio_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800988 int found = 0;
989 int i;
990 struct Host *hp;
991 int retval;
992 struct vpd_prom *vpdp;
993 int okboard;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
995#ifdef CONFIG_PCI
Andrew Morton8d8706e2006-01-11 12:17:49 -0800996 struct pci_dev *pdev = NULL;
997 unsigned int tint;
998 unsigned short tshort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999#endif
1000
Andrew Morton8d8706e2006-01-11 12:17:49 -08001001 func_enter();
1002 rio_dprintk(RIO_DEBUG_INIT, "Initing rio module... (rio_debug=%d)\n", rio_debug);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
Andrew Morton8d8706e2006-01-11 12:17:49 -08001004 if (abs((long) (&rio_debug) - rio_debug) < 0x10000) {
1005 printk(KERN_WARNING "rio: rio_debug is an address, instead of a value. " "Assuming -1. Was %x/%p.\n", rio_debug, &rio_debug);
1006 rio_debug = -1;
1007 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
Andrew Morton8d8706e2006-01-11 12:17:49 -08001009 if (misc_register(&rio_fw_device) < 0) {
1010 printk(KERN_ERR "RIO: Unable to register firmware loader driver.\n");
1011 return -EIO;
1012 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
Andrew Morton8d8706e2006-01-11 12:17:49 -08001014 retval = rio_init_datastructures();
1015 if (retval < 0) {
1016 misc_deregister(&rio_fw_device);
1017 return retval;
1018 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019#ifdef CONFIG_PCI
Andrew Morton8d8706e2006-01-11 12:17:49 -08001020 /* First look for the JET devices: */
1021 while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, pdev))) {
1022 if (pci_enable_device(pdev))
1023 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
Andrew Morton8d8706e2006-01-11 12:17:49 -08001025 /* Specialix has a whole bunch of cards with
1026 0x2000 as the device ID. They say its because
1027 the standard requires it. Stupid standard. */
1028 /* It seems that reading a word doesn't work reliably on 2.0.
1029 Also, reading a non-aligned dword doesn't work. So we read the
1030 whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
1031 ourselves */
1032 /* I don't know why the define doesn't work, constant 0x2c does --REW */
1033 pci_read_config_dword(pdev, 0x2c, &tint);
1034 tshort = (tint >> 16) & 0xffff;
1035 rio_dprintk(RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
1036 if (tshort != 0x0100) {
1037 rio_dprintk(RIO_DEBUG_PROBE, "But it's not a RIO card (%d)...\n", tshort);
1038 continue;
1039 }
1040 rio_dprintk(RIO_DEBUG_PROBE, "cp1\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041
Andrew Morton8d8706e2006-01-11 12:17:49 -08001042 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_2, &tint);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
Andrew Morton8d8706e2006-01-11 12:17:49 -08001044 hp = &p->RIOHosts[p->RIONumHosts];
1045 hp->PaddrP = tint & PCI_BASE_ADDRESS_MEM_MASK;
1046 hp->Ivec = pdev->irq;
1047 if (((1 << hp->Ivec) & rio_irqmask) == 0)
1048 hp->Ivec = 0;
1049 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1050 hp->CardP = (struct DpRam *) hp->Caddr;
1051 hp->Type = RIO_PCI;
1052 hp->Copy = rio_pcicopy;
1053 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1054 spin_lock_init(&hp->HostLock);
1055 rio_reset_interrupt(hp);
1056 rio_start_card_running(hp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
Andrew Morton8d8706e2006-01-11 12:17:49 -08001058 rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr);
1059 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == RIO_SUCCESS) {
1060 rio_dprintk(RIO_DEBUG_INIT, "Done RIOBoardTest\n");
1061 WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff);
1062 p->RIOHosts[p->RIONumHosts].UniqueNum =
1063 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
1064 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) & 0xFF) << 8) | ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) & 0xFF) << 16) | ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) & 0xFF) << 24);
1065 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
Andrew Morton8d8706e2006-01-11 12:17:49 -08001067 fix_rio_pci(pdev);
1068 p->RIOLastPCISearch = RIO_SUCCESS;
1069 p->RIONumHosts++;
1070 found++;
1071 } else {
1072 iounmap((char *) (p->RIOHosts[p->RIONumHosts].Caddr));
1073 }
1074 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
Andrew Morton8d8706e2006-01-11 12:17:49 -08001076 /* Then look for the older PCI card.... : */
1077
1078 /* These older PCI cards have problems (only byte-mode access is
1079 supported), which makes them a bit awkward to support.
1080 They also have problems sharing interrupts. Be careful.
1081 (The driver now refuses to share interrupts for these
1082 cards. This should be sufficient).
1083 */
1084
1085 /* Then look for the older RIO/PCI devices: */
1086 while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_RIO, pdev))) {
1087 if (pci_enable_device(pdev))
1088 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
1090#ifdef CONFIG_RIO_OLDPCI
Andrew Morton8d8706e2006-01-11 12:17:49 -08001091 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &tint);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
Andrew Morton8d8706e2006-01-11 12:17:49 -08001093 hp = &p->RIOHosts[p->RIONumHosts];
1094 hp->PaddrP = tint & PCI_BASE_ADDRESS_MEM_MASK;
1095 hp->Ivec = pdev->irq;
1096 if (((1 << hp->Ivec) & rio_irqmask) == 0)
1097 hp->Ivec = 0;
1098 hp->Ivec |= 0x8000; /* Mark as non-sharable */
1099 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1100 hp->CardP = (struct DpRam *) hp->Caddr;
1101 hp->Type = RIO_PCI;
1102 hp->Copy = rio_pcicopy;
1103 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1104 spin_lock_init(&hp->HostLock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
Andrew Morton8d8706e2006-01-11 12:17:49 -08001106 rio_dprintk(RIO_DEBUG_PROBE, "Ivec: %x\n", hp->Ivec);
1107 rio_dprintk(RIO_DEBUG_PROBE, "Mode: %x\n", hp->Mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
Andrew Morton8d8706e2006-01-11 12:17:49 -08001109 rio_reset_interrupt(hp);
1110 rio_start_card_running(hp);
1111 rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr);
1112 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == RIO_SUCCESS) {
1113 WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff);
1114 p->RIOHosts[p->RIONumHosts].UniqueNum =
1115 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
1116 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) & 0xFF) << 8) | ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) & 0xFF) << 16) | ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) & 0xFF) << 24);
1117 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118
Andrew Morton8d8706e2006-01-11 12:17:49 -08001119 p->RIOLastPCISearch = RIO_SUCCESS;
1120 p->RIONumHosts++;
1121 found++;
1122 } else {
1123 iounmap((char *) (p->RIOHosts[p->RIONumHosts].Caddr));
1124 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125#else
Andrew Morton8d8706e2006-01-11 12:17:49 -08001126 printk(KERN_ERR "Found an older RIO PCI card, but the driver is not " "compiled to support it.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -08001128 }
1129#endif /* PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130
Andrew Morton8d8706e2006-01-11 12:17:49 -08001131 /* Now probe for ISA cards... */
1132 for (i = 0; i < NR_RIO_ADDRS; i++) {
1133 hp = &p->RIOHosts[p->RIONumHosts];
1134 hp->PaddrP = rio_probe_addrs[i];
1135 /* There was something about the IRQs of these cards. 'Forget what.--REW */
1136 hp->Ivec = 0;
1137 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1138 hp->CardP = (struct DpRam *) hp->Caddr;
1139 hp->Type = RIO_AT;
1140 hp->Copy = rio_pcicopy; /* AT card PCI???? - PVDL
1141 * -- YES! this is now a normal copy. Only the
1142 * old PCI card uses the special PCI copy.
1143 * Moreover, the ISA card will work with the
1144 * special PCI copy anyway. -- REW */
1145 hp->Mode = 0;
1146 spin_lock_init(&hp->HostLock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
Andrew Morton8d8706e2006-01-11 12:17:49 -08001148 vpdp = get_VPD_PROM(hp);
1149 rio_dprintk(RIO_DEBUG_PROBE, "Got VPD ROM\n");
1150 okboard = 0;
1151 if ((strncmp(vpdp->identifier, RIO_ISA_IDENT, 16) == 0) || (strncmp(vpdp->identifier, RIO_ISA2_IDENT, 16) == 0) || (strncmp(vpdp->identifier, RIO_ISA3_IDENT, 16) == 0)) {
1152 /* Board is present... */
1153 if (RIOBoardTest(hp->PaddrP, hp->Caddr, RIO_AT, 0) == RIO_SUCCESS) {
1154 /* ... and feeling fine!!!! */
1155 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1156 if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) {
1157 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, host%d uniqid = %x.\n", p->RIONumHosts, p->RIOHosts[p->RIONumHosts - 1].UniqueNum);
1158 okboard++;
1159 found++;
1160 }
1161 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
Andrew Morton8d8706e2006-01-11 12:17:49 -08001163 if (!okboard)
1164 iounmap((char *) (hp->Caddr));
1165 }
1166 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
1168
Andrew Morton8d8706e2006-01-11 12:17:49 -08001169 for (i = 0; i < p->RIONumHosts; i++) {
1170 hp = &p->RIOHosts[i];
1171 if (hp->Ivec) {
1172 int mode = SA_SHIRQ;
1173 if (hp->Ivec & 0x8000) {
1174 mode = 0;
1175 hp->Ivec &= 0x7fff;
1176 }
1177 rio_dprintk(RIO_DEBUG_INIT, "Requesting interrupt hp: %p rio_interrupt: %d Mode: %x\n", hp, hp->Ivec, hp->Mode);
1178 retval = request_irq(hp->Ivec, rio_interrupt, mode, "rio", hp);
1179 rio_dprintk(RIO_DEBUG_INIT, "Return value from request_irq: %d\n", retval);
1180 if (retval) {
1181 printk(KERN_ERR "rio: Cannot allocate irq %d.\n", hp->Ivec);
1182 hp->Ivec = 0;
1183 }
1184 rio_dprintk(RIO_DEBUG_INIT, "Got irq %d.\n", hp->Ivec);
1185 if (hp->Ivec != 0) {
1186 rio_dprintk(RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n");
1187 hp->Mode |= RIO_PCI_INT_ENABLE;
1188 } else
1189 hp->Mode &= !RIO_PCI_INT_ENABLE;
1190 rio_dprintk(RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode);
1191 rio_start_card_running(hp);
1192 }
1193 /* Init the timer "always" to make sure that it can safely be
1194 deleted when we unload... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
Andrew Morton8d8706e2006-01-11 12:17:49 -08001196 init_timer(&hp->timer);
1197 if (!hp->Ivec) {
1198 rio_dprintk(RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n", rio_poll);
1199 hp->timer.data = i;
1200 hp->timer.function = rio_pollfunc;
1201 hp->timer.expires = jiffies + rio_poll;
1202 add_timer(&hp->timer);
1203 }
1204 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205
Andrew Morton8d8706e2006-01-11 12:17:49 -08001206 if (found) {
1207 rio_dprintk(RIO_DEBUG_INIT, "rio: total of %d boards detected.\n", found);
1208 rio_init_drivers();
1209 } else {
1210 /* deregister the misc device we created earlier */
1211 misc_deregister(&rio_fw_device);
1212 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213
Andrew Morton8d8706e2006-01-11 12:17:49 -08001214 func_exit();
1215 return found ? 0 : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216}
1217
1218
Andrew Morton8d8706e2006-01-11 12:17:49 -08001219static void __exit rio_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220{
Andrew Morton8d8706e2006-01-11 12:17:49 -08001221 int i;
1222 struct Host *hp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223
Andrew Morton8d8706e2006-01-11 12:17:49 -08001224 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225
Andrew Morton8d8706e2006-01-11 12:17:49 -08001226 for (i = 0, hp = p->RIOHosts; i < p->RIONumHosts; i++, hp++) {
1227 RIOHostReset(hp->Type, hp->CardP, hp->Slot);
1228 if (hp->Ivec) {
1229 free_irq(hp->Ivec, hp);
1230 rio_dprintk(RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec);
1231 }
1232 /* It is safe/allowed to del_timer a non-active timer */
1233 del_timer(&hp->timer);
1234 }
1235
1236 if (misc_deregister(&rio_fw_device) < 0) {
1237 printk(KERN_INFO "rio: couldn't deregister control-device\n");
1238 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
1240
Andrew Morton8d8706e2006-01-11 12:17:49 -08001241 rio_dprintk(RIO_DEBUG_CLEANUP, "Cleaning up drivers\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
Andrew Morton8d8706e2006-01-11 12:17:49 -08001243 rio_release_drivers();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244
Andrew Morton8d8706e2006-01-11 12:17:49 -08001245 /* Release dynamically allocated memory */
1246 kfree(p->RIOPortp);
1247 kfree(p->RIOHosts);
1248 kfree(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
Andrew Morton8d8706e2006-01-11 12:17:49 -08001250 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251}
1252
1253module_init(rio_init);
1254module_exit(rio_exit);
1255
1256/*
1257 * Anybody who knows why this doesn't work for me, please tell me -- REW.
1258 * Snatched from scsi.c (fixed one spelling error):
1259 * Overrides for Emacs so that we follow Linus' tabbing style.
1260 * Emacs will notice this stuff at the end of the file and automatically
1261 * adjust the settings for this buffer only. This must remain at the end
1262 * of the file.
1263 * ---------------------------------------------------------------------------
1264 * Local Variables:
1265 * c-indent-level: 4
1266 * c-brace-imaginary-offset: 0
1267 * c-brace-offset: -4
1268 * c-argdecl-indent: 4
1269 * c-label-offset: -4
1270 * c-continued-statement-offset: 4
1271 * c-continued-brace-offset: 0
1272 * indent-tabs-mode: nil
1273 * tab-width: 8
1274 * End:
1275 */