blob: c382df0f82f60957efd73391cc69c17e1577e0b7 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/kdev_t.h>
37#include <asm/io.h>
38#include <linux/kernel.h>
39#include <linux/sched.h>
40#include <linux/ioport.h>
41#include <linux/interrupt.h>
42#include <linux/errno.h>
43#include <linux/tty.h>
44#include <linux/tty_flip.h>
45#include <linux/mm.h>
46#include <linux/serial.h>
47#include <linux/fcntl.h>
48#include <linux/major.h>
49#include <linux/delay.h>
50#include <linux/pci.h>
51#include <linux/slab.h>
52#include <linux/miscdevice.h>
53#include <linux/init.h>
54
55#include <linux/generic_serial.h>
56#include <asm/uaccess.h>
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#include "linux_compat.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#include "pkt.h"
60#include "daemon.h"
61#include "rio.h"
62#include "riospace.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#include "cmdpkt.h"
64#include "map.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#include "rup.h"
66#include "port.h"
67#include "riodrvr.h"
68#include "rioinfo.h"
69#include "func.h"
70#include "errors.h"
71#include "pci.h"
72
73#include "parmmap.h"
74#include "unixrup.h"
75#include "board.h"
76#include "host.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#include "phb.h"
78#include "link.h"
79#include "cmdblk.h"
80#include "route.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070081#include "cirrus.h"
82#include "rioioctl.h"
83#include "param.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#include "protsts.h"
85#include "rioboard.h"
86
87
88#include "rio_linux.h"
89
90/* I don't think that this driver can handle more than 512 ports on
91one machine. Specialix specifies max 4 boards in one machine. I don't
92know why. If you want to try anyway you'll have to increase the number
93of boards in rio.h. You'll have to allocate more majors if you need
94more than 512 ports.... */
95
96#ifndef RIO_NORMAL_MAJOR0
97/* This allows overriding on the compiler commandline, or in a "major.h"
98 include or something like that */
99#define RIO_NORMAL_MAJOR0 154
100#define RIO_NORMAL_MAJOR1 156
101#endif
102
103#ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8
104#define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
105#endif
106
Andrew Morton8d8706e2006-01-11 12:17:49 -0800107#ifndef RIO_WINDOW_LEN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108#define RIO_WINDOW_LEN 0x10000
109#endif
110
111
112/* Configurable options:
113 (Don't be too sure that it'll work if you toggle them) */
114
115/* Am I paranoid or not ? ;-) */
116#undef RIO_PARANOIA_CHECK
117
118
119/* 20 -> 2000 per second. The card should rate-limit interrupts at 1000
120 Hz, but it is user configurable. I don't recommend going above 1000
121 Hz. The interrupt ratelimit might trigger if the interrupt is
122 shared with a very active other device.
123 undef this if you want to disable the check....
124*/
125#define IRQ_RATE_LIMIT 200
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128/* These constants are derived from SCO Source */
129static struct Conf
Andrew Morton8d8706e2006-01-11 12:17:49 -0800130 RIOConf = {
131 /* locator */ "RIO Config here",
132 /* startuptime */ HZ * 2,
133 /* how long to wait for card to run */
134 /* slowcook */ 0,
135 /* TRUE -> always use line disc. */
136 /* intrpolltime */ 1,
137 /* The frequency of OUR polls */
138 /* breakinterval */ 25,
139 /* x10 mS XXX: units seem to be 1ms not 10! -- REW */
140 /* timer */ 10,
141 /* mS */
142 /* RtaLoadBase */ 0x7000,
143 /* HostLoadBase */ 0x7C00,
144 /* XpHz */ 5,
145 /* number of Xprint hits per second */
146 /* XpCps */ 120,
147 /* Xprint characters per second */
148 /* XpOn */ "\033d#",
149 /* start Xprint for a wyse 60 */
150 /* XpOff */ "\024",
151 /* end Xprint for a wyse 60 */
152 /* MaxXpCps */ 2000,
153 /* highest Xprint speed */
154 /* MinXpCps */ 10,
155 /* slowest Xprint speed */
156 /* SpinCmds */ 1,
157 /* non-zero for mega fast boots */
158 /* First Addr */ 0x0A0000,
159 /* First address to look at */
160 /* Last Addr */ 0xFF0000,
161 /* Last address looked at */
162 /* BufferSize */ 1024,
163 /* Bytes per port of buffering */
164 /* LowWater */ 256,
165 /* how much data left before wakeup */
166 /* LineLength */ 80,
167 /* how wide is the console? */
168 /* CmdTimeout */ HZ,
169 /* how long a close command may take */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170};
171
172
173
174
175/* Function prototypes */
176
Andrew Morton8d8706e2006-01-11 12:17:49 -0800177static void rio_disable_tx_interrupts(void *ptr);
178static void rio_enable_tx_interrupts(void *ptr);
179static void rio_disable_rx_interrupts(void *ptr);
180static void rio_enable_rx_interrupts(void *ptr);
181static int rio_get_CD(void *ptr);
182static void rio_shutdown_port(void *ptr);
183static int rio_set_real_termios(void *ptr);
184static void rio_hungup(void *ptr);
185static void rio_close(void *ptr);
186static int rio_chars_in_buffer(void *ptr);
187static int rio_fw_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188static int rio_init_drivers(void);
189
Andrew Morton8d8706e2006-01-11 12:17:49 -0800190static void my_hd(void *addr, int len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192static struct tty_driver *rio_driver, *rio_driver2;
193
194/* The name "p" is a bit non-descript. But that's what the rio-lynxos
195sources use all over the place. */
196struct rio_info *p;
197
198int rio_debug;
199
200
201/* You can have the driver poll your card.
202 - Set rio_poll to 1 to poll every timer tick (10ms on Intel).
203 This is used when the card cannot use an interrupt for some reason.
204*/
205static int rio_poll = 1;
206
207
208/* These are the only open spaces in my computer. Yours may have more
209 or less.... */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800210static int rio_probe_addrs[] = { 0xc0000, 0xd0000, 0xe0000 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Tobias Klauserfe971072006-01-09 20:54:02 -0800212#define NR_RIO_ADDRS ARRAY_SIZE(rio_probe_addrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214
215/* Set the mask to all-ones. This alas, only supports 32 interrupts.
216 Some architectures may need more. -- Changed to LONG to
217 support up to 64 bits on 64bit architectures. -- REW 20/06/99 */
Adrian Bunk408b6642005-05-01 08:59:29 -0700218static long rio_irqmask = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220MODULE_AUTHOR("Rogier Wolff <R.E.Wolff@bitwizard.nl>, Patrick van de Lageweg <patrick@bitwizard.nl>");
221MODULE_DESCRIPTION("RIO driver");
222MODULE_LICENSE("GPL");
223module_param(rio_poll, int, 0);
224module_param(rio_debug, int, 0644);
225module_param(rio_irqmask, long, 0);
226
227static struct real_driver rio_real_driver = {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800228 rio_disable_tx_interrupts,
229 rio_enable_tx_interrupts,
230 rio_disable_rx_interrupts,
231 rio_enable_rx_interrupts,
232 rio_get_CD,
233 rio_shutdown_port,
234 rio_set_real_termios,
235 rio_chars_in_buffer,
236 rio_close,
237 rio_hungup,
238 NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239};
240
241/*
242 * Firmware loader driver specific routines
243 *
244 */
245
Arjan van de Ven62322d22006-07-03 00:24:21 -0700246static const struct file_operations rio_fw_fops = {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800247 .owner = THIS_MODULE,
248 .ioctl = rio_fw_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249};
250
251static struct miscdevice rio_fw_device = {
252 RIOCTL_MISC_MINOR, "rioctl", &rio_fw_fops
253};
254
255
256
257
258
259#ifdef RIO_PARANOIA_CHECK
260
261/* This doesn't work. Who's paranoid around here? Not me! */
262
Andrew Morton8d8706e2006-01-11 12:17:49 -0800263static inline int rio_paranoia_check(struct rio_port const *port, char *name, const char *routine)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
265
Andrew Morton8d8706e2006-01-11 12:17:49 -0800266 static const char *badmagic = KERN_ERR "rio: Warning: bad rio port magic number for device %s in %s\n";
267 static const char *badinfo = KERN_ERR "rio: Warning: null rio port for device %s in %s\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Andrew Morton8d8706e2006-01-11 12:17:49 -0800269 if (!port) {
270 printk(badinfo, name, routine);
271 return 1;
272 }
273 if (port->magic != RIO_MAGIC) {
274 printk(badmagic, name, routine);
275 return 1;
276 }
277
278 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279}
280#else
281#define rio_paranoia_check(a,b,c) 0
282#endif
283
284
285#ifdef DEBUG
Andrew Morton8d8706e2006-01-11 12:17:49 -0800286static void my_hd(void *ad, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800288 int i, j, ch;
289 unsigned char *addr = ad;
290
291 for (i = 0; i < len; i += 16) {
Alan Cox00d83a52006-03-24 03:18:28 -0800292 rio_dprintk(RIO_DEBUG_PARAM, "%08lx ", (unsigned long) addr + i);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800293 for (j = 0; j < 16; j++) {
294 rio_dprintk(RIO_DEBUG_PARAM, "%02x %s", addr[j + i], (j == 7) ? " " : "");
295 }
296 for (j = 0; j < 16; j++) {
297 ch = addr[j + i];
298 rio_dprintk(RIO_DEBUG_PARAM, "%c", (ch < 0x20) ? '.' : ((ch > 0x7f) ? '.' : ch));
299 }
300 rio_dprintk(RIO_DEBUG_PARAM, "\n");
301 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302}
303#else
304#define my_hd(ad,len) do{/* nothing*/ } while (0)
305#endif
306
307
Andrew Morton8d8706e2006-01-11 12:17:49 -0800308/* Delay a number of jiffies, allowing a signal to interrupt */
309int RIODelay(struct Port *PortP, int njiffies)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800311 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Andrew Morton8d8706e2006-01-11 12:17:49 -0800313 rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies\n", njiffies);
314 msleep_interruptible(jiffies_to_msecs(njiffies));
315 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Andrew Morton8d8706e2006-01-11 12:17:49 -0800317 if (signal_pending(current))
318 return RIO_FAIL;
319 else
320 return !RIO_FAIL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321}
322
323
Andrew Morton8d8706e2006-01-11 12:17:49 -0800324/* Delay a number of jiffies, disallowing a signal to interrupt */
325int RIODelay_ni(struct Port *PortP, int njiffies)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800327 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Andrew Morton8d8706e2006-01-11 12:17:49 -0800329 rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies (ni)\n", njiffies);
330 msleep(jiffies_to_msecs(njiffies));
331 func_exit();
332 return !RIO_FAIL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333}
334
Al Viro38d0d002006-05-27 00:15:09 -0400335void rio_copy_to_card(void *from, void __iomem *to, int len)
Alan Cox00d83a52006-03-24 03:18:28 -0800336{
Al Viroae5b28a2006-05-27 01:48:08 -0400337 rio_copy_toio(to, from, len);
Alan Cox00d83a52006-03-24 03:18:28 -0800338}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340int rio_minor(struct tty_struct *tty)
341{
342 return tty->index + (tty->driver == rio_driver) ? 0 : 256;
343}
344
Andrew Morton8d8706e2006-01-11 12:17:49 -0800345static int rio_set_real_termios(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346{
Alan Cox554b7c82006-03-24 03:18:32 -0800347 return RIOParam((struct Port *) ptr, CONFIG, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348}
349
350
Andrew Morton8d8706e2006-01-11 12:17:49 -0800351static void rio_reset_interrupt(struct Host *HostP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800353 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Andrew Morton8d8706e2006-01-11 12:17:49 -0800355 switch (HostP->Type) {
356 case RIO_AT:
357 case RIO_MCA:
358 case RIO_PCI:
Alan Cox00d83a52006-03-24 03:18:28 -0800359 writeb(0xFF, &HostP->ResetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800360 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Andrew Morton8d8706e2006-01-11 12:17:49 -0800362 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363}
364
365
David Howells7d12e782006-10-05 14:55:46 +0100366static irqreturn_t rio_interrupt(int irq, void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800368 struct Host *HostP;
369 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Jeff Garzikc7bec5a2006-10-06 15:00:58 -0400371 HostP = ptr; /* &p->RIOHosts[(long)ptr]; */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800372 rio_dprintk(RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Andrew Morton8d8706e2006-01-11 12:17:49 -0800374 /* AAargh! The order in which to do these things is essential and
375 not trivial.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Andrew Morton8d8706e2006-01-11 12:17:49 -0800377 - hardware twiddling goes before "recursive". Otherwise when we
378 poll the card, and a recursive interrupt happens, we won't
379 ack the card, so it might keep on interrupting us. (especially
380 level sensitive interrupt systems like PCI).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Andrew Morton8d8706e2006-01-11 12:17:49 -0800382 - Rate limit goes before hardware twiddling. Otherwise we won't
383 catch a card that has gone bonkers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Andrew Morton8d8706e2006-01-11 12:17:49 -0800385 - The "initialized" test goes after the hardware twiddling. Otherwise
386 the card will stick us in the interrupt routine again.
387
388 - The initialized test goes before recursive.
389 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Andrew Morton8d8706e2006-01-11 12:17:49 -0800391 rio_dprintk(RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n");
392 if (HostP->Ivec == irq) {
393 /* Tell the card we've noticed the interrupt. */
394 rio_reset_interrupt(HostP);
395 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Andrew Morton8d8706e2006-01-11 12:17:49 -0800397 if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
398 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Andrew Morton8d8706e2006-01-11 12:17:49 -0800400 if (test_and_set_bit(RIO_BOARD_INTR_LOCK, &HostP->locks)) {
Alan Cox00d83a52006-03-24 03:18:28 -0800401 printk(KERN_ERR "Recursive interrupt! (host %p/irq%d)\n", ptr, HostP->Ivec);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800402 return IRQ_HANDLED;
403 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Jeff Garzikc7bec5a2006-10-06 15:00:58 -0400405 RIOServiceHost(p, HostP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Alan Cox00d83a52006-03-24 03:18:28 -0800407 rio_dprintk(RIO_DEBUG_IFLOW, "riointr() doing host %p type %d\n", ptr, HostP->Type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Andrew Morton8d8706e2006-01-11 12:17:49 -0800409 clear_bit(RIO_BOARD_INTR_LOCK, &HostP->locks);
410 rio_dprintk(RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
411 func_exit();
412 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413}
414
415
Andrew Morton8d8706e2006-01-11 12:17:49 -0800416static void rio_pollfunc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800418 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
David Howells7d12e782006-10-05 14:55:46 +0100420 rio_interrupt(0, &p->RIOHosts[data]);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800421 p->RIOHosts[data].timer.expires = jiffies + rio_poll;
422 add_timer(&p->RIOHosts[data].timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Andrew Morton8d8706e2006-01-11 12:17:49 -0800424 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425}
426
427
428/* ********************************************************************** *
429 * Here are the routines that actually *
430 * interface with the generic_serial driver *
431 * ********************************************************************** */
432
433/* Ehhm. I don't know how to fiddle with interrupts on the Specialix
434 cards. .... Hmm. Ok I figured it out. You don't. -- REW */
435
Andrew Morton8d8706e2006-01-11 12:17:49 -0800436static void rio_disable_tx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800438 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Andrew Morton8d8706e2006-01-11 12:17:49 -0800440 /* port->gs.flags &= ~GS_TX_INTEN; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
Andrew Morton8d8706e2006-01-11 12:17:49 -0800442 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443}
444
445
Andrew Morton8d8706e2006-01-11 12:17:49 -0800446static void rio_enable_tx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800448 struct Port *PortP = ptr;
449 /* int hn; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Andrew Morton8d8706e2006-01-11 12:17:49 -0800451 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Andrew Morton8d8706e2006-01-11 12:17:49 -0800453 /* hn = PortP->HostP - p->RIOHosts;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
Andrew Morton8d8706e2006-01-11 12:17:49 -0800455 rio_dprintk (RIO_DEBUG_TTY, "Pushing host %d\n", hn);
456 rio_interrupt (-1,(void *) hn, NULL); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
Andrew Morton8d8706e2006-01-11 12:17:49 -0800458 RIOTxEnable((char *) PortP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
Andrew Morton8d8706e2006-01-11 12:17:49 -0800460 /*
461 * In general we cannot count on "tx empty" interrupts, although
462 * the interrupt routine seems to be able to tell the difference.
463 */
464 PortP->gs.flags &= ~GS_TX_INTEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Andrew Morton8d8706e2006-01-11 12:17:49 -0800466 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467}
468
469
Andrew Morton8d8706e2006-01-11 12:17:49 -0800470static void rio_disable_rx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800472 func_enter();
473 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474}
475
Andrew Morton8d8706e2006-01-11 12:17:49 -0800476static void rio_enable_rx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800478 /* struct rio_port *port = ptr; */
479 func_enter();
480 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481}
482
483
484/* Jeez. Isn't this simple? */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800485static int rio_get_CD(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800487 struct Port *PortP = ptr;
488 int rv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
Andrew Morton8d8706e2006-01-11 12:17:49 -0800490 func_enter();
491 rv = (PortP->ModemState & MSVR1_CD) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Andrew Morton8d8706e2006-01-11 12:17:49 -0800493 rio_dprintk(RIO_DEBUG_INIT, "Getting CD status: %d\n", rv);
494
495 func_exit();
496 return rv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497}
498
499
500/* Jeez. Isn't this simple? Actually, we can sync with the actual port
501 by just pushing stuff into the queue going to the port... */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800502static int rio_chars_in_buffer(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800504 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
Andrew Morton8d8706e2006-01-11 12:17:49 -0800506 func_exit();
507 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508}
509
510
511/* Nothing special here... */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800512static void rio_shutdown_port(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800514 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Andrew Morton8d8706e2006-01-11 12:17:49 -0800516 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
Andrew Morton8d8706e2006-01-11 12:17:49 -0800518 PortP = (struct Port *) ptr;
519 PortP->gs.tty = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800520 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521}
522
523
524/* I haven't the foggiest why the decrement use count has to happen
525 here. The whole linux serial drivers stuff needs to be redesigned.
526 My guess is that this is a hack to minimize the impact of a bug
527 elsewhere. Thinking about it some more. (try it sometime) Try
528 running minicom on a serial port that is driven by a modularized
529 driver. Have the modem hangup. Then remove the driver module. Then
530 exit minicom. I expect an "oops". -- REW */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800531static void rio_hungup(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800533 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
Andrew Morton8d8706e2006-01-11 12:17:49 -0800535 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
Andrew Morton8d8706e2006-01-11 12:17:49 -0800537 PortP = (struct Port *) ptr;
538 PortP->gs.tty = NULL;
539
540 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541}
542
543
544/* The standard serial_close would become shorter if you'd wrap it like
545 this.
546 rs_close (...){save_flags;cli;real_close();dec_use_count;restore_flags;}
547 */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800548static void rio_close(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800550 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Andrew Morton8d8706e2006-01-11 12:17:49 -0800552 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
Andrew Morton8d8706e2006-01-11 12:17:49 -0800554 PortP = (struct Port *) ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Andrew Morton8d8706e2006-01-11 12:17:49 -0800556 riotclose(ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
Andrew Morton8d8706e2006-01-11 12:17:49 -0800558 if (PortP->gs.count) {
559 printk(KERN_ERR "WARNING port count:%d\n", PortP->gs.count);
560 PortP->gs.count = 0;
561 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Andrew Morton8d8706e2006-01-11 12:17:49 -0800563 PortP->gs.tty = NULL;
564 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565}
566
567
568
Andrew Morton8d8706e2006-01-11 12:17:49 -0800569static int rio_fw_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800571 int rc = 0;
572 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
Andrew Morton8d8706e2006-01-11 12:17:49 -0800574 /* The "dev" argument isn't used. */
Al Virod886cb52006-05-27 00:08:25 -0400575 rc = riocontrol(p, 0, cmd, arg, capable(CAP_SYS_ADMIN));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
Andrew Morton8d8706e2006-01-11 12:17:49 -0800577 func_exit();
578 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579}
580
Andrew Morton8d8706e2006-01-11 12:17:49 -0800581extern int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
Andrew Morton8d8706e2006-01-11 12:17:49 -0800583static int rio_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
Al Virod886cb52006-05-27 00:08:25 -0400585 void __user *argp = (void __user *)arg;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800586 int rc;
587 struct Port *PortP;
588 int ival;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Andrew Morton8d8706e2006-01-11 12:17:49 -0800590 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
Andrew Morton8d8706e2006-01-11 12:17:49 -0800592 PortP = (struct Port *) tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
Andrew Morton8d8706e2006-01-11 12:17:49 -0800594 rc = 0;
595 switch (cmd) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800596 case TIOCSSOFTCAR:
Al Virod886cb52006-05-27 00:08:25 -0400597 if ((rc = get_user(ival, (unsigned __user *) argp)) == 0) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800598 tty->termios->c_cflag = (tty->termios->c_cflag & ~CLOCAL) | (ival ? CLOCAL : 0);
599 }
600 break;
601 case TIOCGSERIAL:
602 rc = -EFAULT;
Al Virod886cb52006-05-27 00:08:25 -0400603 if (access_ok(VERIFY_WRITE, argp, sizeof(struct serial_struct)))
604 rc = gs_getserial(&PortP->gs, argp);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800605 break;
606 case TCSBRK:
607 if (PortP->State & RIO_DELETED) {
608 rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
609 rc = -EIO;
610 } else {
611 if (RIOShortCommand(p, PortP, SBREAK, 2, 250) == RIO_FAIL) {
612 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
613 rc = -EIO;
614 }
615 }
616 break;
617 case TCSBRKP:
618 if (PortP->State & RIO_DELETED) {
619 rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
620 rc = -EIO;
621 } else {
622 int l;
623 l = arg ? arg * 100 : 250;
624 if (l > 255)
625 l = 255;
626 if (RIOShortCommand(p, PortP, SBREAK, 2, arg ? arg * 100 : 250) == RIO_FAIL) {
627 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
628 rc = -EIO;
629 }
630 }
631 break;
632 case TIOCSSERIAL:
633 rc = -EFAULT;
Al Virod886cb52006-05-27 00:08:25 -0400634 if (access_ok(VERIFY_READ, argp, sizeof(struct serial_struct)))
635 rc = gs_setserial(&PortP->gs, argp);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800636 break;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800637 default:
638 rc = -ENOIOCTLCMD;
639 break;
640 }
641 func_exit();
642 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643}
644
645
646/* The throttle/unthrottle scheme for the Specialix card is different
647 * from other drivers and deserves some explanation.
648 * The Specialix hardware takes care of XON/XOFF
649 * and CTS/RTS flow control itself. This means that all we have to
650 * do when signalled by the upper tty layer to throttle/unthrottle is
651 * to make a note of it here. When we come to read characters from the
652 * rx buffers on the card (rio_receive_chars()) we look to see if the
653 * upper layer can accept more (as noted here in rio_rx_throt[]).
654 * If it can't we simply don't remove chars from the cards buffer.
655 * When the tty layer can accept chars, we again note that here and when
656 * rio_receive_chars() is called it will remove them from the cards buffer.
657 * The card will notice that a ports buffer has drained below some low
658 * water mark and will unflow control the line itself, using whatever
659 * flow control scheme is in use for that port. -- Simon Allen
660 */
661
Andrew Morton8d8706e2006-01-11 12:17:49 -0800662static void rio_throttle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800664 struct Port *port = (struct Port *) tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
Andrew Morton8d8706e2006-01-11 12:17:49 -0800666 func_enter();
667 /* If the port is using any type of input flow
668 * control then throttle the port.
669 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
Andrew Morton8d8706e2006-01-11 12:17:49 -0800671 if ((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty))) {
672 port->State |= RIO_THROTTLE_RX;
673 }
674
675 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676}
677
678
Andrew Morton8d8706e2006-01-11 12:17:49 -0800679static void rio_unthrottle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800681 struct Port *port = (struct Port *) tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
Andrew Morton8d8706e2006-01-11 12:17:49 -0800683 func_enter();
684 /* Always unthrottle even if flow control is not enabled on
685 * this port in case we disabled flow control while the port
686 * was throttled
687 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Andrew Morton8d8706e2006-01-11 12:17:49 -0800689 port->State &= ~RIO_THROTTLE_RX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
Andrew Morton8d8706e2006-01-11 12:17:49 -0800691 func_exit();
692 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693}
694
695
696
697
698
699/* ********************************************************************** *
700 * Here are the initialization routines. *
701 * ********************************************************************** */
702
703
Andrew Morton8d8706e2006-01-11 12:17:49 -0800704static struct vpd_prom *get_VPD_PROM(struct Host *hp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800706 static struct vpd_prom vpdp;
707 char *p;
708 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
Andrew Morton8d8706e2006-01-11 12:17:49 -0800710 func_enter();
711 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 -0700712
Andrew Morton8d8706e2006-01-11 12:17:49 -0800713 p = (char *) &vpdp;
714 for (i = 0; i < sizeof(struct vpd_prom); i++)
715 *p++ = readb(hp->Caddr + RIO_VPD_ROM + i * 2);
716 /* read_rio_byte (hp, RIO_VPD_ROM + i*2); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
Andrew Morton8d8706e2006-01-11 12:17:49 -0800718 /* Terminate the identifier string.
719 *** requires one extra byte in struct vpd_prom *** */
720 *p++ = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
Andrew Morton8d8706e2006-01-11 12:17:49 -0800722 if (rio_debug & RIO_DEBUG_PROBE)
723 my_hd((char *) &vpdp, 0x20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
Andrew Morton8d8706e2006-01-11 12:17:49 -0800725 func_exit();
726
727 return &vpdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728}
729
Jeff Dikeb68e31d2006-10-02 02:17:18 -0700730static const struct tty_operations rio_ops = {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800731 .open = riotopen,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 .close = gs_close,
733 .write = gs_write,
734 .put_char = gs_put_char,
735 .flush_chars = gs_flush_chars,
736 .write_room = gs_write_room,
737 .chars_in_buffer = gs_chars_in_buffer,
738 .flush_buffer = gs_flush_buffer,
739 .ioctl = rio_ioctl,
740 .throttle = rio_throttle,
741 .unthrottle = rio_unthrottle,
742 .set_termios = gs_set_termios,
743 .stop = gs_stop,
744 .start = gs_start,
745 .hangup = gs_hangup,
746};
747
748static int rio_init_drivers(void)
749{
750 int error = -ENOMEM;
751
752 rio_driver = alloc_tty_driver(256);
753 if (!rio_driver)
754 goto out;
755 rio_driver2 = alloc_tty_driver(256);
756 if (!rio_driver2)
757 goto out1;
758
759 func_enter();
760
761 rio_driver->owner = THIS_MODULE;
762 rio_driver->driver_name = "specialix_rio";
763 rio_driver->name = "ttySR";
764 rio_driver->major = RIO_NORMAL_MAJOR0;
765 rio_driver->type = TTY_DRIVER_TYPE_SERIAL;
766 rio_driver->subtype = SERIAL_TYPE_NORMAL;
767 rio_driver->init_termios = tty_std_termios;
768 rio_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
769 rio_driver->flags = TTY_DRIVER_REAL_RAW;
770 tty_set_operations(rio_driver, &rio_ops);
771
772 rio_driver2->owner = THIS_MODULE;
773 rio_driver2->driver_name = "specialix_rio";
774 rio_driver2->name = "ttySR";
775 rio_driver2->major = RIO_NORMAL_MAJOR1;
776 rio_driver2->type = TTY_DRIVER_TYPE_SERIAL;
777 rio_driver2->subtype = SERIAL_TYPE_NORMAL;
778 rio_driver2->init_termios = tty_std_termios;
779 rio_driver2->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
780 rio_driver2->flags = TTY_DRIVER_REAL_RAW;
781 tty_set_operations(rio_driver2, &rio_ops);
782
Andrew Morton8d8706e2006-01-11 12:17:49 -0800783 rio_dprintk(RIO_DEBUG_INIT, "set_termios = %p\n", gs_set_termios);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
785 if ((error = tty_register_driver(rio_driver)))
786 goto out2;
787 if ((error = tty_register_driver(rio_driver2)))
788 goto out3;
789 func_exit();
790 return 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800791 out3:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 tty_unregister_driver(rio_driver);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800793 out2:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 put_tty_driver(rio_driver2);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800795 out1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 put_tty_driver(rio_driver);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800797 out:
798 printk(KERN_ERR "rio: Couldn't register a rio driver, error = %d\n", error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 return 1;
800}
801
802
Andrew Morton8d8706e2006-01-11 12:17:49 -0800803static void *ckmalloc(int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800805 void *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
Andrew Morton8d8706e2006-01-11 12:17:49 -0800807 p = kmalloc(size, GFP_KERNEL);
808 if (p)
809 memset(p, 0, size);
810 return p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811}
812
813
814
Andrew Morton8d8706e2006-01-11 12:17:49 -0800815static int rio_init_datastructures(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800817 int i;
818 struct Port *port;
819 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
Andrew Morton8d8706e2006-01-11 12:17:49 -0800821 /* Many drivers statically allocate the maximum number of ports
822 There is no reason not to allocate them dynamically. Is there? -- REW */
823 /* However, the RIO driver allows users to configure their first
824 RTA as the ports numbered 504-511. We therefore need to allocate
825 the whole range. :-( -- REW */
826
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827#define RI_SZ sizeof(struct rio_info)
828#define HOST_SZ sizeof(struct Host)
829#define PORT_SZ sizeof(struct Port *)
830#define TMIO_SZ sizeof(struct termios *)
Alan Cox00d83a52006-03-24 03:18:28 -0800831 rio_dprintk(RIO_DEBUG_INIT, "getting : %Zd %Zd %Zd %Zd %Zd bytes\n", RI_SZ, RIO_HOSTS * HOST_SZ, RIO_PORTS * PORT_SZ, RIO_PORTS * TMIO_SZ, RIO_PORTS * TMIO_SZ);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800832
833 if (!(p = ckmalloc(RI_SZ)))
834 goto free0;
835 if (!(p->RIOHosts = ckmalloc(RIO_HOSTS * HOST_SZ)))
836 goto free1;
837 if (!(p->RIOPortp = ckmalloc(RIO_PORTS * PORT_SZ)))
838 goto free2;
839 p->RIOConf = RIOConf;
840 rio_dprintk(RIO_DEBUG_INIT, "Got : %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
842#if 1
Andrew Morton8d8706e2006-01-11 12:17:49 -0800843 for (i = 0; i < RIO_PORTS; i++) {
844 port = p->RIOPortp[i] = ckmalloc(sizeof(struct Port));
845 if (!port) {
846 goto free6;
847 }
848 rio_dprintk(RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped);
849 port->PortNum = i;
850 port->gs.magic = RIO_MAGIC;
851 port->gs.close_delay = HZ / 2;
852 port->gs.closing_wait = 30 * HZ;
853 port->gs.rd = &rio_real_driver;
854 spin_lock_init(&port->portSem);
855 /*
856 * Initializing wait queue
857 */
858 init_waitqueue_head(&port->gs.open_wait);
859 init_waitqueue_head(&port->gs.close_wait);
860 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861#else
Andrew Morton8d8706e2006-01-11 12:17:49 -0800862 /* We could postpone initializing them to when they are configured. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863#endif
864
865
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
Andrew Morton8d8706e2006-01-11 12:17:49 -0800867 if (rio_debug & RIO_DEBUG_INIT) {
868 my_hd(&rio_real_driver, sizeof(rio_real_driver));
869 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
Andrew Morton8d8706e2006-01-11 12:17:49 -0800871
872 func_exit();
873 return 0;
874
875 free6:for (i--; i >= 0; i--)
876 kfree(p->RIOPortp[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877/*free5:
878 free4:
Andrew Morton8d8706e2006-01-11 12:17:49 -0800879 free3:*/ kfree(p->RIOPortp);
880 free2:kfree(p->RIOHosts);
881 free1:
882 rio_dprintk(RIO_DEBUG_INIT, "Not enough memory! %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
883 kfree(p);
884 free0:
885 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886}
887
Andrew Morton8d8706e2006-01-11 12:17:49 -0800888static void __exit rio_release_drivers(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800890 func_enter();
891 tty_unregister_driver(rio_driver2);
892 tty_unregister_driver(rio_driver);
893 put_tty_driver(rio_driver2);
894 put_tty_driver(rio_driver);
895 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896}
897
898
899#ifdef CONFIG_PCI
900 /* This was written for SX, but applies to RIO too...
901 (including bugs....)
902
903 There is another bit besides Bit 17. Turning that bit off
904 (on boards shipped with the fix in the eeprom) results in a
905 hang on the next access to the card.
Andrew Morton8d8706e2006-01-11 12:17:49 -0800906 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
908 /********************************************************
909 * Setting bit 17 in the CNTRL register of the PLX 9050 *
910 * chip forces a retry on writes while a read is pending.*
911 * This is to prevent the card locking up on Intel Xeon *
912 * multiprocessor systems with the NX chipset. -- NV *
913 ********************************************************/
914
915/* Newer cards are produced with this bit set from the configuration
916 EEprom. As the bit is read/write for the CPU, we can fix it here,
917 if we detect that it isn't set correctly. -- REW */
918
Andrew Morton8d8706e2006-01-11 12:17:49 -0800919static void fix_rio_pci(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920{
Alan Cox00d83a52006-03-24 03:18:28 -0800921 unsigned long hwbase;
Al Virod886cb52006-05-27 00:08:25 -0400922 unsigned char __iomem *rebase;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800923 unsigned int t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
925#define CNTRL_REG_OFFSET 0x50
926#define CNTRL_REG_GOODVALUE 0x18260000
927
Alan Cox00d83a52006-03-24 03:18:28 -0800928 hwbase = pci_resource_start(pdev, 0);
929 rebase = ioremap(hwbase, 0x80);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800930 t = readl(rebase + CNTRL_REG_OFFSET);
931 if (t != CNTRL_REG_GOODVALUE) {
932 printk(KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n", t, CNTRL_REG_GOODVALUE);
933 writel(CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
934 }
Alan Cox00d83a52006-03-24 03:18:28 -0800935 iounmap(rebase);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936}
937#endif
938
939
Andrew Morton8d8706e2006-01-11 12:17:49 -0800940static int __init rio_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800942 int found = 0;
943 int i;
944 struct Host *hp;
945 int retval;
946 struct vpd_prom *vpdp;
947 int okboard;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
949#ifdef CONFIG_PCI
Andrew Morton8d8706e2006-01-11 12:17:49 -0800950 struct pci_dev *pdev = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800951 unsigned short tshort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952#endif
953
Andrew Morton8d8706e2006-01-11 12:17:49 -0800954 func_enter();
955 rio_dprintk(RIO_DEBUG_INIT, "Initing rio module... (rio_debug=%d)\n", rio_debug);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Andrew Morton8d8706e2006-01-11 12:17:49 -0800957 if (abs((long) (&rio_debug) - rio_debug) < 0x10000) {
958 printk(KERN_WARNING "rio: rio_debug is an address, instead of a value. " "Assuming -1. Was %x/%p.\n", rio_debug, &rio_debug);
959 rio_debug = -1;
960 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
Andrew Morton8d8706e2006-01-11 12:17:49 -0800962 if (misc_register(&rio_fw_device) < 0) {
963 printk(KERN_ERR "RIO: Unable to register firmware loader driver.\n");
964 return -EIO;
965 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
Andrew Morton8d8706e2006-01-11 12:17:49 -0800967 retval = rio_init_datastructures();
968 if (retval < 0) {
969 misc_deregister(&rio_fw_device);
970 return retval;
971 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972#ifdef CONFIG_PCI
Andrew Morton8d8706e2006-01-11 12:17:49 -0800973 /* First look for the JET devices: */
974 while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, pdev))) {
Alan Cox554b7c82006-03-24 03:18:32 -0800975 u32 tint;
976
Andrew Morton8d8706e2006-01-11 12:17:49 -0800977 if (pci_enable_device(pdev))
978 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
Andrew Morton8d8706e2006-01-11 12:17:49 -0800980 /* Specialix has a whole bunch of cards with
981 0x2000 as the device ID. They say its because
982 the standard requires it. Stupid standard. */
983 /* It seems that reading a word doesn't work reliably on 2.0.
984 Also, reading a non-aligned dword doesn't work. So we read the
985 whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
986 ourselves */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800987 pci_read_config_dword(pdev, 0x2c, &tint);
988 tshort = (tint >> 16) & 0xffff;
989 rio_dprintk(RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
990 if (tshort != 0x0100) {
991 rio_dprintk(RIO_DEBUG_PROBE, "But it's not a RIO card (%d)...\n", tshort);
992 continue;
993 }
994 rio_dprintk(RIO_DEBUG_PROBE, "cp1\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
Andrew Morton8d8706e2006-01-11 12:17:49 -0800996 hp = &p->RIOHosts[p->RIONumHosts];
Alan Cox554b7c82006-03-24 03:18:32 -0800997 hp->PaddrP = pci_resource_start(pdev, 2);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800998 hp->Ivec = pdev->irq;
999 if (((1 << hp->Ivec) & rio_irqmask) == 0)
1000 hp->Ivec = 0;
1001 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
Al Virod886cb52006-05-27 00:08:25 -04001002 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001003 hp->Type = RIO_PCI;
Alan Cox00d83a52006-03-24 03:18:28 -08001004 hp->Copy = rio_copy_to_card;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001005 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1006 spin_lock_init(&hp->HostLock);
1007 rio_reset_interrupt(hp);
1008 rio_start_card_running(hp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
Andrew Morton8d8706e2006-01-11 12:17:49 -08001010 rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr);
Alan Cox554b7c82006-03-24 03:18:32 -08001011 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001012 rio_dprintk(RIO_DEBUG_INIT, "Done RIOBoardTest\n");
Alan Cox00d83a52006-03-24 03:18:28 -08001013 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001014 p->RIOHosts[p->RIONumHosts].UniqueNum =
Alan Cox00d83a52006-03-24 03:18:28 -08001015 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
1016 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[1]) & 0xFF) << 8) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[2]) & 0xFF) << 16) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[3]) & 0xFF) << 24);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001017 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018
Andrew Morton8d8706e2006-01-11 12:17:49 -08001019 fix_rio_pci(pdev);
Alan Cox554b7c82006-03-24 03:18:32 -08001020 p->RIOLastPCISearch = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001021 p->RIONumHosts++;
1022 found++;
1023 } else {
Al Virod886cb52006-05-27 00:08:25 -04001024 iounmap(p->RIOHosts[p->RIONumHosts].Caddr);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001025 }
1026 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
Andrew Morton8d8706e2006-01-11 12:17:49 -08001028 /* Then look for the older PCI card.... : */
1029
1030 /* These older PCI cards have problems (only byte-mode access is
1031 supported), which makes them a bit awkward to support.
1032 They also have problems sharing interrupts. Be careful.
1033 (The driver now refuses to share interrupts for these
1034 cards. This should be sufficient).
1035 */
1036
1037 /* Then look for the older RIO/PCI devices: */
1038 while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_RIO, pdev))) {
1039 if (pci_enable_device(pdev))
1040 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041
1042#ifdef CONFIG_RIO_OLDPCI
Andrew Morton8d8706e2006-01-11 12:17:49 -08001043 hp = &p->RIOHosts[p->RIONumHosts];
Alan Cox554b7c82006-03-24 03:18:32 -08001044 hp->PaddrP = pci_resource_start(pdev, 0);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001045 hp->Ivec = pdev->irq;
1046 if (((1 << hp->Ivec) & rio_irqmask) == 0)
1047 hp->Ivec = 0;
1048 hp->Ivec |= 0x8000; /* Mark as non-sharable */
1049 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
Al Virod886cb52006-05-27 00:08:25 -04001050 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001051 hp->Type = RIO_PCI;
Alan Cox00d83a52006-03-24 03:18:28 -08001052 hp->Copy = rio_copy_to_card;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001053 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1054 spin_lock_init(&hp->HostLock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
Andrew Morton8d8706e2006-01-11 12:17:49 -08001056 rio_dprintk(RIO_DEBUG_PROBE, "Ivec: %x\n", hp->Ivec);
1057 rio_dprintk(RIO_DEBUG_PROBE, "Mode: %x\n", hp->Mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
Andrew Morton8d8706e2006-01-11 12:17:49 -08001059 rio_reset_interrupt(hp);
1060 rio_start_card_running(hp);
1061 rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr);
Alan Cox554b7c82006-03-24 03:18:32 -08001062 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) {
Alan Cox00d83a52006-03-24 03:18:28 -08001063 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001064 p->RIOHosts[p->RIONumHosts].UniqueNum =
Alan Cox00d83a52006-03-24 03:18:28 -08001065 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
1066 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[1]) & 0xFF) << 8) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[2]) & 0xFF) << 16) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[3]) & 0xFF) << 24);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001067 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
Alan Cox554b7c82006-03-24 03:18:32 -08001069 p->RIOLastPCISearch = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001070 p->RIONumHosts++;
1071 found++;
1072 } else {
Al Virod886cb52006-05-27 00:08:25 -04001073 iounmap(p->RIOHosts[p->RIONumHosts].Caddr);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001074 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075#else
Andrew Morton8d8706e2006-01-11 12:17:49 -08001076 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 -07001077#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -08001078 }
1079#endif /* PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
Andrew Morton8d8706e2006-01-11 12:17:49 -08001081 /* Now probe for ISA cards... */
1082 for (i = 0; i < NR_RIO_ADDRS; i++) {
1083 hp = &p->RIOHosts[p->RIONumHosts];
1084 hp->PaddrP = rio_probe_addrs[i];
1085 /* There was something about the IRQs of these cards. 'Forget what.--REW */
1086 hp->Ivec = 0;
1087 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
Al Virod886cb52006-05-27 00:08:25 -04001088 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001089 hp->Type = RIO_AT;
Alan Cox00d83a52006-03-24 03:18:28 -08001090 hp->Copy = rio_copy_to_card; /* AT card PCI???? - PVDL
1091 * -- YES! this is now a normal copy. Only the
Andrew Morton8d8706e2006-01-11 12:17:49 -08001092 * old PCI card uses the special PCI copy.
1093 * Moreover, the ISA card will work with the
1094 * special PCI copy anyway. -- REW */
1095 hp->Mode = 0;
1096 spin_lock_init(&hp->HostLock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
Andrew Morton8d8706e2006-01-11 12:17:49 -08001098 vpdp = get_VPD_PROM(hp);
1099 rio_dprintk(RIO_DEBUG_PROBE, "Got VPD ROM\n");
1100 okboard = 0;
1101 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)) {
1102 /* Board is present... */
Alan Cox554b7c82006-03-24 03:18:32 -08001103 if (RIOBoardTest(hp->PaddrP, hp->Caddr, RIO_AT, 0) == 0) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001104 /* ... and feeling fine!!!! */
1105 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1106 if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) {
1107 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, host%d uniqid = %x.\n", p->RIONumHosts, p->RIOHosts[p->RIONumHosts - 1].UniqueNum);
1108 okboard++;
1109 found++;
1110 }
1111 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112
Andrew Morton8d8706e2006-01-11 12:17:49 -08001113 if (!okboard)
Al Virod886cb52006-05-27 00:08:25 -04001114 iounmap(hp->Caddr);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001115 }
1116 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
1118
Andrew Morton8d8706e2006-01-11 12:17:49 -08001119 for (i = 0; i < p->RIONumHosts; i++) {
1120 hp = &p->RIOHosts[i];
1121 if (hp->Ivec) {
Thomas Gleixner5d8c8a22006-07-01 19:29:41 -07001122 int mode = IRQF_SHARED;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001123 if (hp->Ivec & 0x8000) {
1124 mode = 0;
1125 hp->Ivec &= 0x7fff;
1126 }
1127 rio_dprintk(RIO_DEBUG_INIT, "Requesting interrupt hp: %p rio_interrupt: %d Mode: %x\n", hp, hp->Ivec, hp->Mode);
1128 retval = request_irq(hp->Ivec, rio_interrupt, mode, "rio", hp);
1129 rio_dprintk(RIO_DEBUG_INIT, "Return value from request_irq: %d\n", retval);
1130 if (retval) {
1131 printk(KERN_ERR "rio: Cannot allocate irq %d.\n", hp->Ivec);
1132 hp->Ivec = 0;
1133 }
1134 rio_dprintk(RIO_DEBUG_INIT, "Got irq %d.\n", hp->Ivec);
1135 if (hp->Ivec != 0) {
1136 rio_dprintk(RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n");
1137 hp->Mode |= RIO_PCI_INT_ENABLE;
1138 } else
1139 hp->Mode &= !RIO_PCI_INT_ENABLE;
1140 rio_dprintk(RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode);
1141 rio_start_card_running(hp);
1142 }
1143 /* Init the timer "always" to make sure that it can safely be
1144 deleted when we unload... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
Andrew Morton8d8706e2006-01-11 12:17:49 -08001146 init_timer(&hp->timer);
1147 if (!hp->Ivec) {
1148 rio_dprintk(RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n", rio_poll);
1149 hp->timer.data = i;
1150 hp->timer.function = rio_pollfunc;
1151 hp->timer.expires = jiffies + rio_poll;
1152 add_timer(&hp->timer);
1153 }
1154 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
Andrew Morton8d8706e2006-01-11 12:17:49 -08001156 if (found) {
1157 rio_dprintk(RIO_DEBUG_INIT, "rio: total of %d boards detected.\n", found);
1158 rio_init_drivers();
1159 } else {
1160 /* deregister the misc device we created earlier */
1161 misc_deregister(&rio_fw_device);
1162 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163
Andrew Morton8d8706e2006-01-11 12:17:49 -08001164 func_exit();
1165 return found ? 0 : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166}
1167
1168
Andrew Morton8d8706e2006-01-11 12:17:49 -08001169static void __exit rio_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170{
Andrew Morton8d8706e2006-01-11 12:17:49 -08001171 int i;
1172 struct Host *hp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
Andrew Morton8d8706e2006-01-11 12:17:49 -08001174 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
Andrew Morton8d8706e2006-01-11 12:17:49 -08001176 for (i = 0, hp = p->RIOHosts; i < p->RIONumHosts; i++, hp++) {
1177 RIOHostReset(hp->Type, hp->CardP, hp->Slot);
1178 if (hp->Ivec) {
1179 free_irq(hp->Ivec, hp);
1180 rio_dprintk(RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec);
1181 }
1182 /* It is safe/allowed to del_timer a non-active timer */
1183 del_timer(&hp->timer);
1184 }
1185
1186 if (misc_deregister(&rio_fw_device) < 0) {
1187 printk(KERN_INFO "rio: couldn't deregister control-device\n");
1188 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
1190
Andrew Morton8d8706e2006-01-11 12:17:49 -08001191 rio_dprintk(RIO_DEBUG_CLEANUP, "Cleaning up drivers\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
Andrew Morton8d8706e2006-01-11 12:17:49 -08001193 rio_release_drivers();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
Andrew Morton8d8706e2006-01-11 12:17:49 -08001195 /* Release dynamically allocated memory */
1196 kfree(p->RIOPortp);
1197 kfree(p->RIOHosts);
1198 kfree(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
Andrew Morton8d8706e2006-01-11 12:17:49 -08001200 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201}
1202
1203module_init(rio_init);
1204module_exit(rio_exit);