blob: 1e87a93164bfcd18db17c0a1dda111e9e5eeb36c [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 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 * */
29
30#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/kdev_t.h>
32#include <asm/io.h>
33#include <linux/kernel.h>
34#include <linux/sched.h>
35#include <linux/ioport.h>
36#include <linux/interrupt.h>
37#include <linux/errno.h>
38#include <linux/tty.h>
39#include <linux/tty_flip.h>
40#include <linux/mm.h>
41#include <linux/serial.h>
42#include <linux/fcntl.h>
43#include <linux/major.h>
44#include <linux/delay.h>
45#include <linux/pci.h>
46#include <linux/slab.h>
Alexey Dobriyan405f5572009-07-11 22:08:37 +040047#include <linux/smp_lock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/miscdevice.h>
49#include <linux/init.h>
50
51#include <linux/generic_serial.h>
52#include <asm/uaccess.h>
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#include "linux_compat.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include "pkt.h"
56#include "daemon.h"
57#include "rio.h"
58#include "riospace.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#include "cmdpkt.h"
60#include "map.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#include "rup.h"
62#include "port.h"
63#include "riodrvr.h"
64#include "rioinfo.h"
65#include "func.h"
66#include "errors.h"
67#include "pci.h"
68
69#include "parmmap.h"
70#include "unixrup.h"
71#include "board.h"
72#include "host.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#include "phb.h"
74#include "link.h"
75#include "cmdblk.h"
76#include "route.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#include "cirrus.h"
78#include "rioioctl.h"
79#include "param.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#include "protsts.h"
81#include "rioboard.h"
82
83
84#include "rio_linux.h"
85
86/* I don't think that this driver can handle more than 512 ports on
87one machine. Specialix specifies max 4 boards in one machine. I don't
88know why. If you want to try anyway you'll have to increase the number
89of boards in rio.h. You'll have to allocate more majors if you need
90more than 512 ports.... */
91
92#ifndef RIO_NORMAL_MAJOR0
93/* This allows overriding on the compiler commandline, or in a "major.h"
94 include or something like that */
95#define RIO_NORMAL_MAJOR0 154
96#define RIO_NORMAL_MAJOR1 156
97#endif
98
99#ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8
100#define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
101#endif
102
Andrew Morton8d8706e2006-01-11 12:17:49 -0800103#ifndef RIO_WINDOW_LEN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104#define RIO_WINDOW_LEN 0x10000
105#endif
106
107
108/* Configurable options:
109 (Don't be too sure that it'll work if you toggle them) */
110
111/* Am I paranoid or not ? ;-) */
112#undef RIO_PARANOIA_CHECK
113
114
115/* 20 -> 2000 per second. The card should rate-limit interrupts at 1000
116 Hz, but it is user configurable. I don't recommend going above 1000
117 Hz. The interrupt ratelimit might trigger if the interrupt is
118 shared with a very active other device.
119 undef this if you want to disable the check....
120*/
121#define IRQ_RATE_LIMIT 200
122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124/* These constants are derived from SCO Source */
125static struct Conf
Andrew Morton8d8706e2006-01-11 12:17:49 -0800126 RIOConf = {
127 /* locator */ "RIO Config here",
128 /* startuptime */ HZ * 2,
129 /* how long to wait for card to run */
130 /* slowcook */ 0,
131 /* TRUE -> always use line disc. */
132 /* intrpolltime */ 1,
133 /* The frequency of OUR polls */
134 /* breakinterval */ 25,
135 /* x10 mS XXX: units seem to be 1ms not 10! -- REW */
136 /* timer */ 10,
137 /* mS */
138 /* RtaLoadBase */ 0x7000,
139 /* HostLoadBase */ 0x7C00,
140 /* XpHz */ 5,
141 /* number of Xprint hits per second */
142 /* XpCps */ 120,
143 /* Xprint characters per second */
144 /* XpOn */ "\033d#",
145 /* start Xprint for a wyse 60 */
146 /* XpOff */ "\024",
147 /* end Xprint for a wyse 60 */
148 /* MaxXpCps */ 2000,
149 /* highest Xprint speed */
150 /* MinXpCps */ 10,
151 /* slowest Xprint speed */
152 /* SpinCmds */ 1,
153 /* non-zero for mega fast boots */
154 /* First Addr */ 0x0A0000,
155 /* First address to look at */
156 /* Last Addr */ 0xFF0000,
157 /* Last address looked at */
158 /* BufferSize */ 1024,
159 /* Bytes per port of buffering */
160 /* LowWater */ 256,
161 /* how much data left before wakeup */
162 /* LineLength */ 80,
163 /* how wide is the console? */
164 /* CmdTimeout */ HZ,
165 /* how long a close command may take */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166};
167
168
169
170
171/* Function prototypes */
172
Andrew Morton8d8706e2006-01-11 12:17:49 -0800173static void rio_disable_tx_interrupts(void *ptr);
174static void rio_enable_tx_interrupts(void *ptr);
175static void rio_disable_rx_interrupts(void *ptr);
176static void rio_enable_rx_interrupts(void *ptr);
Alan Cox31f35932009-01-02 13:45:05 +0000177static int rio_carrier_raised(struct tty_port *port);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800178static void rio_shutdown_port(void *ptr);
179static int rio_set_real_termios(void *ptr);
180static void rio_hungup(void *ptr);
181static void rio_close(void *ptr);
182static int rio_chars_in_buffer(void *ptr);
Alan Coxf6759fd2008-07-25 01:48:14 -0700183static long rio_fw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184static int rio_init_drivers(void);
185
Andrew Morton8d8706e2006-01-11 12:17:49 -0800186static void my_hd(void *addr, int len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188static struct tty_driver *rio_driver, *rio_driver2;
189
190/* The name "p" is a bit non-descript. But that's what the rio-lynxos
191sources use all over the place. */
192struct rio_info *p;
193
194int rio_debug;
195
196
197/* You can have the driver poll your card.
198 - Set rio_poll to 1 to poll every timer tick (10ms on Intel).
199 This is used when the card cannot use an interrupt for some reason.
200*/
201static int rio_poll = 1;
202
203
204/* These are the only open spaces in my computer. Yours may have more
205 or less.... */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800206static int rio_probe_addrs[] = { 0xc0000, 0xd0000, 0xe0000 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Tobias Klauserfe971072006-01-09 20:54:02 -0800208#define NR_RIO_ADDRS ARRAY_SIZE(rio_probe_addrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210
211/* Set the mask to all-ones. This alas, only supports 32 interrupts.
212 Some architectures may need more. -- Changed to LONG to
213 support up to 64 bits on 64bit architectures. -- REW 20/06/99 */
Adrian Bunk408b6642005-05-01 08:59:29 -0700214static long rio_irqmask = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216MODULE_AUTHOR("Rogier Wolff <R.E.Wolff@bitwizard.nl>, Patrick van de Lageweg <patrick@bitwizard.nl>");
217MODULE_DESCRIPTION("RIO driver");
218MODULE_LICENSE("GPL");
219module_param(rio_poll, int, 0);
220module_param(rio_debug, int, 0644);
221module_param(rio_irqmask, long, 0);
222
223static struct real_driver rio_real_driver = {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800224 rio_disable_tx_interrupts,
225 rio_enable_tx_interrupts,
226 rio_disable_rx_interrupts,
227 rio_enable_rx_interrupts,
Andrew Morton8d8706e2006-01-11 12:17:49 -0800228 rio_shutdown_port,
229 rio_set_real_termios,
230 rio_chars_in_buffer,
231 rio_close,
232 rio_hungup,
233 NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234};
235
236/*
237 * Firmware loader driver specific routines
238 *
239 */
240
Arjan van de Ven62322d22006-07-03 00:24:21 -0700241static const struct file_operations rio_fw_fops = {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800242 .owner = THIS_MODULE,
Alan Coxf6759fd2008-07-25 01:48:14 -0700243 .unlocked_ioctl = rio_fw_ioctl,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200244 .llseek = noop_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245};
246
247static struct miscdevice rio_fw_device = {
248 RIOCTL_MISC_MINOR, "rioctl", &rio_fw_fops
249};
250
251
252
253
254
255#ifdef RIO_PARANOIA_CHECK
256
257/* This doesn't work. Who's paranoid around here? Not me! */
258
Andrew Morton8d8706e2006-01-11 12:17:49 -0800259static inline int rio_paranoia_check(struct rio_port const *port, char *name, const char *routine)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
261
Andrew Morton8d8706e2006-01-11 12:17:49 -0800262 static const char *badmagic = KERN_ERR "rio: Warning: bad rio port magic number for device %s in %s\n";
263 static const char *badinfo = KERN_ERR "rio: Warning: null rio port for device %s in %s\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Andrew Morton8d8706e2006-01-11 12:17:49 -0800265 if (!port) {
266 printk(badinfo, name, routine);
267 return 1;
268 }
269 if (port->magic != RIO_MAGIC) {
270 printk(badmagic, name, routine);
271 return 1;
272 }
273
274 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275}
276#else
277#define rio_paranoia_check(a,b,c) 0
278#endif
279
280
281#ifdef DEBUG
Andrew Morton8d8706e2006-01-11 12:17:49 -0800282static void my_hd(void *ad, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800284 int i, j, ch;
285 unsigned char *addr = ad;
286
287 for (i = 0; i < len; i += 16) {
Alan Cox00d83a52006-03-24 03:18:28 -0800288 rio_dprintk(RIO_DEBUG_PARAM, "%08lx ", (unsigned long) addr + i);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800289 for (j = 0; j < 16; j++) {
290 rio_dprintk(RIO_DEBUG_PARAM, "%02x %s", addr[j + i], (j == 7) ? " " : "");
291 }
292 for (j = 0; j < 16; j++) {
293 ch = addr[j + i];
294 rio_dprintk(RIO_DEBUG_PARAM, "%c", (ch < 0x20) ? '.' : ((ch > 0x7f) ? '.' : ch));
295 }
296 rio_dprintk(RIO_DEBUG_PARAM, "\n");
297 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}
299#else
300#define my_hd(ad,len) do{/* nothing*/ } while (0)
301#endif
302
303
Andrew Morton8d8706e2006-01-11 12:17:49 -0800304/* Delay a number of jiffies, allowing a signal to interrupt */
305int RIODelay(struct Port *PortP, int njiffies)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800307 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Andrew Morton8d8706e2006-01-11 12:17:49 -0800309 rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies\n", njiffies);
310 msleep_interruptible(jiffies_to_msecs(njiffies));
311 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Andrew Morton8d8706e2006-01-11 12:17:49 -0800313 if (signal_pending(current))
314 return RIO_FAIL;
315 else
316 return !RIO_FAIL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317}
318
319
Andrew Morton8d8706e2006-01-11 12:17:49 -0800320/* Delay a number of jiffies, disallowing a signal to interrupt */
321int RIODelay_ni(struct Port *PortP, int njiffies)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800323 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
Andrew Morton8d8706e2006-01-11 12:17:49 -0800325 rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies (ni)\n", njiffies);
326 msleep(jiffies_to_msecs(njiffies));
327 func_exit();
328 return !RIO_FAIL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329}
330
Al Viro38d0d002006-05-27 00:15:09 -0400331void rio_copy_to_card(void *from, void __iomem *to, int len)
Alan Cox00d83a52006-03-24 03:18:28 -0800332{
Al Viroae5b28a2006-05-27 01:48:08 -0400333 rio_copy_toio(to, from, len);
Alan Cox00d83a52006-03-24 03:18:28 -0800334}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
336int rio_minor(struct tty_struct *tty)
337{
Roel Kluin1f854492009-04-06 17:35:34 +0100338 return tty->index + ((tty->driver == rio_driver) ? 0 : 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339}
340
Andrew Morton8d8706e2006-01-11 12:17:49 -0800341static int rio_set_real_termios(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342{
Jiri Slabyd6f63412008-04-30 00:53:57 -0700343 return RIOParam((struct Port *) ptr, RIOC_CONFIG, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344}
345
346
Andrew Morton8d8706e2006-01-11 12:17:49 -0800347static void rio_reset_interrupt(struct Host *HostP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800349 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
Andrew Morton8d8706e2006-01-11 12:17:49 -0800351 switch (HostP->Type) {
352 case RIO_AT:
353 case RIO_MCA:
354 case RIO_PCI:
Alan Cox00d83a52006-03-24 03:18:28 -0800355 writeb(0xFF, &HostP->ResetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800356 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Andrew Morton8d8706e2006-01-11 12:17:49 -0800358 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359}
360
361
David Howells7d12e782006-10-05 14:55:46 +0100362static irqreturn_t rio_interrupt(int irq, void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800364 struct Host *HostP;
365 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Jeff Garzikc7bec5a2006-10-06 15:00:58 -0400367 HostP = ptr; /* &p->RIOHosts[(long)ptr]; */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800368 rio_dprintk(RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Andrew Morton8d8706e2006-01-11 12:17:49 -0800370 /* AAargh! The order in which to do these things is essential and
371 not trivial.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Andrew Morton8d8706e2006-01-11 12:17:49 -0800373 - hardware twiddling goes before "recursive". Otherwise when we
374 poll the card, and a recursive interrupt happens, we won't
375 ack the card, so it might keep on interrupting us. (especially
376 level sensitive interrupt systems like PCI).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Andrew Morton8d8706e2006-01-11 12:17:49 -0800378 - Rate limit goes before hardware twiddling. Otherwise we won't
379 catch a card that has gone bonkers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
Andrew Morton8d8706e2006-01-11 12:17:49 -0800381 - The "initialized" test goes after the hardware twiddling. Otherwise
382 the card will stick us in the interrupt routine again.
383
384 - The initialized test goes before recursive.
385 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Andrew Morton8d8706e2006-01-11 12:17:49 -0800387 rio_dprintk(RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n");
388 if (HostP->Ivec == irq) {
389 /* Tell the card we've noticed the interrupt. */
390 rio_reset_interrupt(HostP);
391 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Andrew Morton8d8706e2006-01-11 12:17:49 -0800393 if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
394 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Andrew Morton8d8706e2006-01-11 12:17:49 -0800396 if (test_and_set_bit(RIO_BOARD_INTR_LOCK, &HostP->locks)) {
Alan Cox00d83a52006-03-24 03:18:28 -0800397 printk(KERN_ERR "Recursive interrupt! (host %p/irq%d)\n", ptr, HostP->Ivec);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800398 return IRQ_HANDLED;
399 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Jeff Garzikc7bec5a2006-10-06 15:00:58 -0400401 RIOServiceHost(p, HostP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Alan Cox00d83a52006-03-24 03:18:28 -0800403 rio_dprintk(RIO_DEBUG_IFLOW, "riointr() doing host %p type %d\n", ptr, HostP->Type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Andrew Morton8d8706e2006-01-11 12:17:49 -0800405 clear_bit(RIO_BOARD_INTR_LOCK, &HostP->locks);
406 rio_dprintk(RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
407 func_exit();
408 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409}
410
411
Andrew Morton8d8706e2006-01-11 12:17:49 -0800412static void rio_pollfunc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800414 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
David Howells7d12e782006-10-05 14:55:46 +0100416 rio_interrupt(0, &p->RIOHosts[data]);
Jiri Slaby40565f12007-02-12 00:52:31 -0800417 mod_timer(&p->RIOHosts[data].timer, jiffies + rio_poll);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Andrew Morton8d8706e2006-01-11 12:17:49 -0800419 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}
421
422
423/* ********************************************************************** *
424 * Here are the routines that actually *
425 * interface with the generic_serial driver *
426 * ********************************************************************** */
427
428/* Ehhm. I don't know how to fiddle with interrupts on the Specialix
429 cards. .... Hmm. Ok I figured it out. You don't. -- REW */
430
Andrew Morton8d8706e2006-01-11 12:17:49 -0800431static void rio_disable_tx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800433 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Alan Coxb5391e22008-07-16 21:55:20 +0100435 /* port->gs.port.flags &= ~GS_TX_INTEN; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Andrew Morton8d8706e2006-01-11 12:17:49 -0800437 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438}
439
440
Andrew Morton8d8706e2006-01-11 12:17:49 -0800441static void rio_enable_tx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800443 struct Port *PortP = ptr;
444 /* int hn; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Andrew Morton8d8706e2006-01-11 12:17:49 -0800446 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Andrew Morton8d8706e2006-01-11 12:17:49 -0800448 /* hn = PortP->HostP - p->RIOHosts;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Andrew Morton8d8706e2006-01-11 12:17:49 -0800450 rio_dprintk (RIO_DEBUG_TTY, "Pushing host %d\n", hn);
451 rio_interrupt (-1,(void *) hn, NULL); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Andrew Morton8d8706e2006-01-11 12:17:49 -0800453 RIOTxEnable((char *) PortP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
Andrew Morton8d8706e2006-01-11 12:17:49 -0800455 /*
456 * In general we cannot count on "tx empty" interrupts, although
457 * the interrupt routine seems to be able to tell the difference.
458 */
Alan Coxb5391e22008-07-16 21:55:20 +0100459 PortP->gs.port.flags &= ~GS_TX_INTEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Andrew Morton8d8706e2006-01-11 12:17:49 -0800461 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462}
463
464
Andrew Morton8d8706e2006-01-11 12:17:49 -0800465static void rio_disable_rx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800467 func_enter();
468 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469}
470
Andrew Morton8d8706e2006-01-11 12:17:49 -0800471static void rio_enable_rx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800473 /* struct rio_port *port = ptr; */
474 func_enter();
475 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476}
477
478
479/* Jeez. Isn't this simple? */
Alan Cox31f35932009-01-02 13:45:05 +0000480static int rio_carrier_raised(struct tty_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481{
Alan Cox31f35932009-01-02 13:45:05 +0000482 struct Port *PortP = container_of(port, struct Port, gs.port);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800483 int rv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Andrew Morton8d8706e2006-01-11 12:17:49 -0800485 func_enter();
Jiri Slabyd6f63412008-04-30 00:53:57 -0700486 rv = (PortP->ModemState & RIOC_MSVR1_CD) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Andrew Morton8d8706e2006-01-11 12:17:49 -0800488 rio_dprintk(RIO_DEBUG_INIT, "Getting CD status: %d\n", rv);
489
490 func_exit();
491 return rv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492}
493
494
495/* Jeez. Isn't this simple? Actually, we can sync with the actual port
496 by just pushing stuff into the queue going to the port... */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800497static int rio_chars_in_buffer(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800499 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
Andrew Morton8d8706e2006-01-11 12:17:49 -0800501 func_exit();
502 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503}
504
505
506/* Nothing special here... */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800507static void rio_shutdown_port(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800509 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
Andrew Morton8d8706e2006-01-11 12:17:49 -0800511 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
Andrew Morton8d8706e2006-01-11 12:17:49 -0800513 PortP = (struct Port *) ptr;
Alan Coxb5391e22008-07-16 21:55:20 +0100514 PortP->gs.port.tty = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800515 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516}
517
518
519/* I haven't the foggiest why the decrement use count has to happen
520 here. The whole linux serial drivers stuff needs to be redesigned.
521 My guess is that this is a hack to minimize the impact of a bug
522 elsewhere. Thinking about it some more. (try it sometime) Try
523 running minicom on a serial port that is driven by a modularized
524 driver. Have the modem hangup. Then remove the driver module. Then
525 exit minicom. I expect an "oops". -- REW */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800526static void rio_hungup(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800528 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
Andrew Morton8d8706e2006-01-11 12:17:49 -0800530 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
Andrew Morton8d8706e2006-01-11 12:17:49 -0800532 PortP = (struct Port *) ptr;
Alan Coxb5391e22008-07-16 21:55:20 +0100533 PortP->gs.port.tty = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800534
535 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536}
537
538
539/* The standard serial_close would become shorter if you'd wrap it like
540 this.
541 rs_close (...){save_flags;cli;real_close();dec_use_count;restore_flags;}
542 */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800543static void rio_close(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800545 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Andrew Morton8d8706e2006-01-11 12:17:49 -0800547 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
Andrew Morton8d8706e2006-01-11 12:17:49 -0800549 PortP = (struct Port *) ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Andrew Morton8d8706e2006-01-11 12:17:49 -0800551 riotclose(ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
Alan Coxb5391e22008-07-16 21:55:20 +0100553 if (PortP->gs.port.count) {
554 printk(KERN_ERR "WARNING port count:%d\n", PortP->gs.port.count);
555 PortP->gs.port.count = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800556 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
Alan Coxb5391e22008-07-16 21:55:20 +0100558 PortP->gs.port.tty = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800559 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560}
561
562
563
Alan Coxf6759fd2008-07-25 01:48:14 -0700564static long rio_fw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800566 int rc = 0;
567 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Andrew Morton8d8706e2006-01-11 12:17:49 -0800569 /* The "dev" argument isn't used. */
Alan Coxf6759fd2008-07-25 01:48:14 -0700570 lock_kernel();
Al Virod886cb52006-05-27 00:08:25 -0400571 rc = riocontrol(p, 0, cmd, arg, capable(CAP_SYS_ADMIN));
Alan Coxf6759fd2008-07-25 01:48:14 -0700572 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
Andrew Morton8d8706e2006-01-11 12:17:49 -0800574 func_exit();
575 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576}
577
Andrew Morton8d8706e2006-01-11 12:17:49 -0800578extern int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
Andrew Morton8d8706e2006-01-11 12:17:49 -0800580static int rio_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
Al Virod886cb52006-05-27 00:08:25 -0400582 void __user *argp = (void __user *)arg;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800583 int rc;
584 struct Port *PortP;
585 int ival;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
Andrew Morton8d8706e2006-01-11 12:17:49 -0800587 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Andrew Morton8d8706e2006-01-11 12:17:49 -0800589 PortP = (struct Port *) tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Andrew Morton8d8706e2006-01-11 12:17:49 -0800591 rc = 0;
592 switch (cmd) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800593 case TIOCSSOFTCAR:
Al Virod886cb52006-05-27 00:08:25 -0400594 if ((rc = get_user(ival, (unsigned __user *) argp)) == 0) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800595 tty->termios->c_cflag = (tty->termios->c_cflag & ~CLOCAL) | (ival ? CLOCAL : 0);
596 }
597 break;
598 case TIOCGSERIAL:
599 rc = -EFAULT;
Al Virod886cb52006-05-27 00:08:25 -0400600 if (access_ok(VERIFY_WRITE, argp, sizeof(struct serial_struct)))
601 rc = gs_getserial(&PortP->gs, argp);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800602 break;
603 case TCSBRK:
604 if (PortP->State & RIO_DELETED) {
605 rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
606 rc = -EIO;
607 } else {
Jiri Slabyd6f63412008-04-30 00:53:57 -0700608 if (RIOShortCommand(p, PortP, RIOC_SBREAK, 2, 250) ==
609 RIO_FAIL) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800610 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
611 rc = -EIO;
612 }
613 }
614 break;
615 case TCSBRKP:
616 if (PortP->State & RIO_DELETED) {
617 rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
618 rc = -EIO;
619 } else {
620 int l;
621 l = arg ? arg * 100 : 250;
622 if (l > 255)
623 l = 255;
Jiri Slabyd6f63412008-04-30 00:53:57 -0700624 if (RIOShortCommand(p, PortP, RIOC_SBREAK, 2,
625 arg ? arg * 100 : 250) == RIO_FAIL) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800626 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
627 rc = -EIO;
628 }
629 }
630 break;
631 case TIOCSSERIAL:
632 rc = -EFAULT;
Al Virod886cb52006-05-27 00:08:25 -0400633 if (access_ok(VERIFY_READ, argp, sizeof(struct serial_struct)))
634 rc = gs_setserial(&PortP->gs, argp);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800635 break;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800636 default:
637 rc = -ENOIOCTLCMD;
638 break;
639 }
640 func_exit();
641 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642}
643
644
645/* The throttle/unthrottle scheme for the Specialix card is different
646 * from other drivers and deserves some explanation.
647 * The Specialix hardware takes care of XON/XOFF
648 * and CTS/RTS flow control itself. This means that all we have to
649 * do when signalled by the upper tty layer to throttle/unthrottle is
650 * to make a note of it here. When we come to read characters from the
651 * rx buffers on the card (rio_receive_chars()) we look to see if the
652 * upper layer can accept more (as noted here in rio_rx_throt[]).
653 * If it can't we simply don't remove chars from the cards buffer.
654 * When the tty layer can accept chars, we again note that here and when
655 * rio_receive_chars() is called it will remove them from the cards buffer.
656 * The card will notice that a ports buffer has drained below some low
657 * water mark and will unflow control the line itself, using whatever
658 * flow control scheme is in use for that port. -- Simon Allen
659 */
660
Andrew Morton8d8706e2006-01-11 12:17:49 -0800661static void rio_throttle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800663 struct Port *port = (struct Port *) tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
Andrew Morton8d8706e2006-01-11 12:17:49 -0800665 func_enter();
666 /* If the port is using any type of input flow
667 * control then throttle the port.
668 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
Andrew Morton8d8706e2006-01-11 12:17:49 -0800670 if ((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty))) {
671 port->State |= RIO_THROTTLE_RX;
672 }
673
674 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675}
676
677
Andrew Morton8d8706e2006-01-11 12:17:49 -0800678static void rio_unthrottle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800680 struct Port *port = (struct Port *) tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
Andrew Morton8d8706e2006-01-11 12:17:49 -0800682 func_enter();
683 /* Always unthrottle even if flow control is not enabled on
684 * this port in case we disabled flow control while the port
685 * was throttled
686 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
Andrew Morton8d8706e2006-01-11 12:17:49 -0800688 port->State &= ~RIO_THROTTLE_RX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
Andrew Morton8d8706e2006-01-11 12:17:49 -0800690 func_exit();
691 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692}
693
694
695
696
697
698/* ********************************************************************** *
699 * Here are the initialization routines. *
700 * ********************************************************************** */
701
702
Andrew Morton8d8706e2006-01-11 12:17:49 -0800703static struct vpd_prom *get_VPD_PROM(struct Host *hp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800705 static struct vpd_prom vpdp;
706 char *p;
707 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
Andrew Morton8d8706e2006-01-11 12:17:49 -0800709 func_enter();
710 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 -0700711
Andrew Morton8d8706e2006-01-11 12:17:49 -0800712 p = (char *) &vpdp;
713 for (i = 0; i < sizeof(struct vpd_prom); i++)
714 *p++ = readb(hp->Caddr + RIO_VPD_ROM + i * 2);
715 /* read_rio_byte (hp, RIO_VPD_ROM + i*2); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
Andrew Morton8d8706e2006-01-11 12:17:49 -0800717 /* Terminate the identifier string.
718 *** requires one extra byte in struct vpd_prom *** */
719 *p++ = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
Andrew Morton8d8706e2006-01-11 12:17:49 -0800721 if (rio_debug & RIO_DEBUG_PROBE)
722 my_hd((char *) &vpdp, 0x20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
Andrew Morton8d8706e2006-01-11 12:17:49 -0800724 func_exit();
725
726 return &vpdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727}
728
Jeff Dikeb68e31d2006-10-02 02:17:18 -0700729static const struct tty_operations rio_ops = {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800730 .open = riotopen,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 .close = gs_close,
732 .write = gs_write,
733 .put_char = gs_put_char,
734 .flush_chars = gs_flush_chars,
735 .write_room = gs_write_room,
736 .chars_in_buffer = gs_chars_in_buffer,
737 .flush_buffer = gs_flush_buffer,
738 .ioctl = rio_ioctl,
739 .throttle = rio_throttle,
740 .unthrottle = rio_unthrottle,
741 .set_termios = gs_set_termios,
742 .stop = gs_stop,
743 .start = gs_start,
744 .hangup = gs_hangup,
745};
746
747static int rio_init_drivers(void)
748{
749 int error = -ENOMEM;
750
751 rio_driver = alloc_tty_driver(256);
752 if (!rio_driver)
753 goto out;
754 rio_driver2 = alloc_tty_driver(256);
755 if (!rio_driver2)
756 goto out1;
757
758 func_enter();
759
760 rio_driver->owner = THIS_MODULE;
761 rio_driver->driver_name = "specialix_rio";
762 rio_driver->name = "ttySR";
763 rio_driver->major = RIO_NORMAL_MAJOR0;
764 rio_driver->type = TTY_DRIVER_TYPE_SERIAL;
765 rio_driver->subtype = SERIAL_TYPE_NORMAL;
766 rio_driver->init_termios = tty_std_termios;
767 rio_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
768 rio_driver->flags = TTY_DRIVER_REAL_RAW;
769 tty_set_operations(rio_driver, &rio_ops);
770
771 rio_driver2->owner = THIS_MODULE;
772 rio_driver2->driver_name = "specialix_rio";
773 rio_driver2->name = "ttySR";
774 rio_driver2->major = RIO_NORMAL_MAJOR1;
775 rio_driver2->type = TTY_DRIVER_TYPE_SERIAL;
776 rio_driver2->subtype = SERIAL_TYPE_NORMAL;
777 rio_driver2->init_termios = tty_std_termios;
778 rio_driver2->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
779 rio_driver2->flags = TTY_DRIVER_REAL_RAW;
780 tty_set_operations(rio_driver2, &rio_ops);
781
Andrew Morton8d8706e2006-01-11 12:17:49 -0800782 rio_dprintk(RIO_DEBUG_INIT, "set_termios = %p\n", gs_set_termios);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
784 if ((error = tty_register_driver(rio_driver)))
785 goto out2;
786 if ((error = tty_register_driver(rio_driver2)))
787 goto out3;
788 func_exit();
789 return 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800790 out3:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 tty_unregister_driver(rio_driver);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800792 out2:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 put_tty_driver(rio_driver2);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800794 out1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 put_tty_driver(rio_driver);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800796 out:
797 printk(KERN_ERR "rio: Couldn't register a rio driver, error = %d\n", error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 return 1;
799}
800
Alan Cox31f35932009-01-02 13:45:05 +0000801static const struct tty_port_operations rio_port_ops = {
802 .carrier_raised = rio_carrier_raised,
803};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
Andrew Morton8d8706e2006-01-11 12:17:49 -0800805static int rio_init_datastructures(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800807 int i;
808 struct Port *port;
809 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
Andrew Morton8d8706e2006-01-11 12:17:49 -0800811 /* Many drivers statically allocate the maximum number of ports
812 There is no reason not to allocate them dynamically. Is there? -- REW */
813 /* However, the RIO driver allows users to configure their first
814 RTA as the ports numbered 504-511. We therefore need to allocate
815 the whole range. :-( -- REW */
816
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817#define RI_SZ sizeof(struct rio_info)
818#define HOST_SZ sizeof(struct Host)
819#define PORT_SZ sizeof(struct Port *)
820#define TMIO_SZ sizeof(struct termios *)
Alan Cox00d83a52006-03-24 03:18:28 -0800821 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 -0800822
Alan Coxd0c98732009-01-02 13:45:12 +0000823 if (!(p = kzalloc(RI_SZ, GFP_KERNEL)))
Andrew Morton8d8706e2006-01-11 12:17:49 -0800824 goto free0;
Alan Coxd0c98732009-01-02 13:45:12 +0000825 if (!(p->RIOHosts = kzalloc(RIO_HOSTS * HOST_SZ, GFP_KERNEL)))
Andrew Morton8d8706e2006-01-11 12:17:49 -0800826 goto free1;
Alan Coxd0c98732009-01-02 13:45:12 +0000827 if (!(p->RIOPortp = kzalloc(RIO_PORTS * PORT_SZ, GFP_KERNEL)))
Andrew Morton8d8706e2006-01-11 12:17:49 -0800828 goto free2;
829 p->RIOConf = RIOConf;
830 rio_dprintk(RIO_DEBUG_INIT, "Got : %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
832#if 1
Andrew Morton8d8706e2006-01-11 12:17:49 -0800833 for (i = 0; i < RIO_PORTS; i++) {
Alan Coxd0c98732009-01-02 13:45:12 +0000834 port = p->RIOPortp[i] = kzalloc(sizeof(struct Port), GFP_KERNEL);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800835 if (!port) {
836 goto free6;
837 }
838 rio_dprintk(RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped);
Alan Cox31f35932009-01-02 13:45:05 +0000839 tty_port_init(&port->gs.port);
840 port->gs.port.ops = &rio_port_ops;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800841 port->PortNum = i;
842 port->gs.magic = RIO_MAGIC;
843 port->gs.close_delay = HZ / 2;
844 port->gs.closing_wait = 30 * HZ;
845 port->gs.rd = &rio_real_driver;
846 spin_lock_init(&port->portSem);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800847 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848#else
Andrew Morton8d8706e2006-01-11 12:17:49 -0800849 /* We could postpone initializing them to when they are configured. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850#endif
851
852
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
Andrew Morton8d8706e2006-01-11 12:17:49 -0800854 if (rio_debug & RIO_DEBUG_INIT) {
855 my_hd(&rio_real_driver, sizeof(rio_real_driver));
856 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
Andrew Morton8d8706e2006-01-11 12:17:49 -0800858
859 func_exit();
860 return 0;
861
862 free6:for (i--; i >= 0; i--)
863 kfree(p->RIOPortp[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864/*free5:
865 free4:
Andrew Morton8d8706e2006-01-11 12:17:49 -0800866 free3:*/ kfree(p->RIOPortp);
867 free2:kfree(p->RIOHosts);
868 free1:
869 rio_dprintk(RIO_DEBUG_INIT, "Not enough memory! %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
870 kfree(p);
871 free0:
872 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873}
874
Andrew Morton8d8706e2006-01-11 12:17:49 -0800875static void __exit rio_release_drivers(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800877 func_enter();
878 tty_unregister_driver(rio_driver2);
879 tty_unregister_driver(rio_driver);
880 put_tty_driver(rio_driver2);
881 put_tty_driver(rio_driver);
882 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883}
884
885
886#ifdef CONFIG_PCI
887 /* This was written for SX, but applies to RIO too...
888 (including bugs....)
889
890 There is another bit besides Bit 17. Turning that bit off
891 (on boards shipped with the fix in the eeprom) results in a
892 hang on the next access to the card.
Andrew Morton8d8706e2006-01-11 12:17:49 -0800893 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
895 /********************************************************
896 * Setting bit 17 in the CNTRL register of the PLX 9050 *
897 * chip forces a retry on writes while a read is pending.*
898 * This is to prevent the card locking up on Intel Xeon *
899 * multiprocessor systems with the NX chipset. -- NV *
900 ********************************************************/
901
902/* Newer cards are produced with this bit set from the configuration
903 EEprom. As the bit is read/write for the CPU, we can fix it here,
904 if we detect that it isn't set correctly. -- REW */
905
Andrew Morton8d8706e2006-01-11 12:17:49 -0800906static void fix_rio_pci(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907{
Alan Cox00d83a52006-03-24 03:18:28 -0800908 unsigned long hwbase;
Al Virod886cb52006-05-27 00:08:25 -0400909 unsigned char __iomem *rebase;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800910 unsigned int t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
912#define CNTRL_REG_OFFSET 0x50
913#define CNTRL_REG_GOODVALUE 0x18260000
914
Alan Cox00d83a52006-03-24 03:18:28 -0800915 hwbase = pci_resource_start(pdev, 0);
916 rebase = ioremap(hwbase, 0x80);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800917 t = readl(rebase + CNTRL_REG_OFFSET);
918 if (t != CNTRL_REG_GOODVALUE) {
919 printk(KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n", t, CNTRL_REG_GOODVALUE);
920 writel(CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
921 }
Alan Cox00d83a52006-03-24 03:18:28 -0800922 iounmap(rebase);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923}
924#endif
925
926
Andrew Morton8d8706e2006-01-11 12:17:49 -0800927static int __init rio_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800929 int found = 0;
930 int i;
931 struct Host *hp;
932 int retval;
933 struct vpd_prom *vpdp;
934 int okboard;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
936#ifdef CONFIG_PCI
Andrew Morton8d8706e2006-01-11 12:17:49 -0800937 struct pci_dev *pdev = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800938 unsigned short tshort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939#endif
940
Andrew Morton8d8706e2006-01-11 12:17:49 -0800941 func_enter();
942 rio_dprintk(RIO_DEBUG_INIT, "Initing rio module... (rio_debug=%d)\n", rio_debug);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
Andrew Morton8d8706e2006-01-11 12:17:49 -0800944 if (abs((long) (&rio_debug) - rio_debug) < 0x10000) {
945 printk(KERN_WARNING "rio: rio_debug is an address, instead of a value. " "Assuming -1. Was %x/%p.\n", rio_debug, &rio_debug);
946 rio_debug = -1;
947 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
Andrew Morton8d8706e2006-01-11 12:17:49 -0800949 if (misc_register(&rio_fw_device) < 0) {
950 printk(KERN_ERR "RIO: Unable to register firmware loader driver.\n");
951 return -EIO;
952 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
Andrew Morton8d8706e2006-01-11 12:17:49 -0800954 retval = rio_init_datastructures();
955 if (retval < 0) {
956 misc_deregister(&rio_fw_device);
957 return retval;
958 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959#ifdef CONFIG_PCI
Andrew Morton8d8706e2006-01-11 12:17:49 -0800960 /* First look for the JET devices: */
961 while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, pdev))) {
Alan Cox554b7c82006-03-24 03:18:32 -0800962 u32 tint;
963
Andrew Morton8d8706e2006-01-11 12:17:49 -0800964 if (pci_enable_device(pdev))
965 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
Andrew Morton8d8706e2006-01-11 12:17:49 -0800967 /* Specialix has a whole bunch of cards with
968 0x2000 as the device ID. They say its because
969 the standard requires it. Stupid standard. */
970 /* It seems that reading a word doesn't work reliably on 2.0.
971 Also, reading a non-aligned dword doesn't work. So we read the
972 whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
973 ourselves */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800974 pci_read_config_dword(pdev, 0x2c, &tint);
975 tshort = (tint >> 16) & 0xffff;
976 rio_dprintk(RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
977 if (tshort != 0x0100) {
978 rio_dprintk(RIO_DEBUG_PROBE, "But it's not a RIO card (%d)...\n", tshort);
979 continue;
980 }
981 rio_dprintk(RIO_DEBUG_PROBE, "cp1\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
Andrew Morton8d8706e2006-01-11 12:17:49 -0800983 hp = &p->RIOHosts[p->RIONumHosts];
Alan Cox554b7c82006-03-24 03:18:32 -0800984 hp->PaddrP = pci_resource_start(pdev, 2);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800985 hp->Ivec = pdev->irq;
986 if (((1 << hp->Ivec) & rio_irqmask) == 0)
987 hp->Ivec = 0;
988 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
Al Virod886cb52006-05-27 00:08:25 -0400989 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800990 hp->Type = RIO_PCI;
Alan Cox00d83a52006-03-24 03:18:28 -0800991 hp->Copy = rio_copy_to_card;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800992 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
993 spin_lock_init(&hp->HostLock);
994 rio_reset_interrupt(hp);
995 rio_start_card_running(hp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
Andrew Morton8d8706e2006-01-11 12:17:49 -0800997 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 -0800998 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800999 rio_dprintk(RIO_DEBUG_INIT, "Done RIOBoardTest\n");
Alan Cox00d83a52006-03-24 03:18:28 -08001000 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001001 p->RIOHosts[p->RIONumHosts].UniqueNum =
Alan Cox00d83a52006-03-24 03:18:28 -08001002 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
1003 ((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 -08001004 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
Andrew Morton8d8706e2006-01-11 12:17:49 -08001006 fix_rio_pci(pdev);
Jiri Slaby86fbf142006-10-21 10:24:01 -07001007
1008 p->RIOHosts[p->RIONumHosts].pdev = pdev;
1009 pci_dev_get(pdev);
1010
Alan Cox554b7c82006-03-24 03:18:32 -08001011 p->RIOLastPCISearch = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001012 p->RIONumHosts++;
1013 found++;
1014 } else {
Al Virod886cb52006-05-27 00:08:25 -04001015 iounmap(p->RIOHosts[p->RIONumHosts].Caddr);
Amol Lad86842652006-12-06 20:35:19 -08001016 p->RIOHosts[p->RIONumHosts].Caddr = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001017 }
1018 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019
Andrew Morton8d8706e2006-01-11 12:17:49 -08001020 /* Then look for the older PCI card.... : */
1021
1022 /* These older PCI cards have problems (only byte-mode access is
1023 supported), which makes them a bit awkward to support.
1024 They also have problems sharing interrupts. Be careful.
1025 (The driver now refuses to share interrupts for these
1026 cards. This should be sufficient).
1027 */
1028
1029 /* Then look for the older RIO/PCI devices: */
1030 while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_RIO, pdev))) {
1031 if (pci_enable_device(pdev))
1032 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033
1034#ifdef CONFIG_RIO_OLDPCI
Andrew Morton8d8706e2006-01-11 12:17:49 -08001035 hp = &p->RIOHosts[p->RIONumHosts];
Alan Cox554b7c82006-03-24 03:18:32 -08001036 hp->PaddrP = pci_resource_start(pdev, 0);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001037 hp->Ivec = pdev->irq;
1038 if (((1 << hp->Ivec) & rio_irqmask) == 0)
1039 hp->Ivec = 0;
1040 hp->Ivec |= 0x8000; /* Mark as non-sharable */
1041 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
Al Virod886cb52006-05-27 00:08:25 -04001042 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001043 hp->Type = RIO_PCI;
Alan Cox00d83a52006-03-24 03:18:28 -08001044 hp->Copy = rio_copy_to_card;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001045 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1046 spin_lock_init(&hp->HostLock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
Andrew Morton8d8706e2006-01-11 12:17:49 -08001048 rio_dprintk(RIO_DEBUG_PROBE, "Ivec: %x\n", hp->Ivec);
1049 rio_dprintk(RIO_DEBUG_PROBE, "Mode: %x\n", hp->Mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
Andrew Morton8d8706e2006-01-11 12:17:49 -08001051 rio_reset_interrupt(hp);
1052 rio_start_card_running(hp);
1053 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 -08001054 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) {
Alan Cox00d83a52006-03-24 03:18:28 -08001055 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001056 p->RIOHosts[p->RIONumHosts].UniqueNum =
Alan Cox00d83a52006-03-24 03:18:28 -08001057 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
1058 ((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 -08001059 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
Jiri Slaby86fbf142006-10-21 10:24:01 -07001061 p->RIOHosts[p->RIONumHosts].pdev = pdev;
1062 pci_dev_get(pdev);
1063
Alan Cox554b7c82006-03-24 03:18:32 -08001064 p->RIOLastPCISearch = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001065 p->RIONumHosts++;
1066 found++;
1067 } else {
Al Virod886cb52006-05-27 00:08:25 -04001068 iounmap(p->RIOHosts[p->RIONumHosts].Caddr);
Amol Lad86842652006-12-06 20:35:19 -08001069 p->RIOHosts[p->RIONumHosts].Caddr = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001070 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071#else
Andrew Morton8d8706e2006-01-11 12:17:49 -08001072 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 -07001073#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -08001074 }
1075#endif /* PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
Andrew Morton8d8706e2006-01-11 12:17:49 -08001077 /* Now probe for ISA cards... */
1078 for (i = 0; i < NR_RIO_ADDRS; i++) {
1079 hp = &p->RIOHosts[p->RIONumHosts];
1080 hp->PaddrP = rio_probe_addrs[i];
1081 /* There was something about the IRQs of these cards. 'Forget what.--REW */
1082 hp->Ivec = 0;
1083 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
Al Virod886cb52006-05-27 00:08:25 -04001084 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001085 hp->Type = RIO_AT;
Alan Cox00d83a52006-03-24 03:18:28 -08001086 hp->Copy = rio_copy_to_card; /* AT card PCI???? - PVDL
1087 * -- YES! this is now a normal copy. Only the
Andrew Morton8d8706e2006-01-11 12:17:49 -08001088 * old PCI card uses the special PCI copy.
1089 * Moreover, the ISA card will work with the
1090 * special PCI copy anyway. -- REW */
1091 hp->Mode = 0;
1092 spin_lock_init(&hp->HostLock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
Andrew Morton8d8706e2006-01-11 12:17:49 -08001094 vpdp = get_VPD_PROM(hp);
1095 rio_dprintk(RIO_DEBUG_PROBE, "Got VPD ROM\n");
1096 okboard = 0;
1097 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)) {
1098 /* Board is present... */
Alan Cox554b7c82006-03-24 03:18:32 -08001099 if (RIOBoardTest(hp->PaddrP, hp->Caddr, RIO_AT, 0) == 0) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001100 /* ... and feeling fine!!!! */
1101 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1102 if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) {
1103 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, host%d uniqid = %x.\n", p->RIONumHosts, p->RIOHosts[p->RIONumHosts - 1].UniqueNum);
1104 okboard++;
1105 found++;
1106 }
1107 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
Amol Lad86842652006-12-06 20:35:19 -08001109 if (!okboard) {
Al Virod886cb52006-05-27 00:08:25 -04001110 iounmap(hp->Caddr);
Amol Lad86842652006-12-06 20:35:19 -08001111 hp->Caddr = NULL;
1112 }
Andrew Morton8d8706e2006-01-11 12:17:49 -08001113 }
1114 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
1116
Andrew Morton8d8706e2006-01-11 12:17:49 -08001117 for (i = 0; i < p->RIONumHosts; i++) {
1118 hp = &p->RIOHosts[i];
1119 if (hp->Ivec) {
Thomas Gleixner5d8c8a22006-07-01 19:29:41 -07001120 int mode = IRQF_SHARED;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001121 if (hp->Ivec & 0x8000) {
1122 mode = 0;
1123 hp->Ivec &= 0x7fff;
1124 }
1125 rio_dprintk(RIO_DEBUG_INIT, "Requesting interrupt hp: %p rio_interrupt: %d Mode: %x\n", hp, hp->Ivec, hp->Mode);
1126 retval = request_irq(hp->Ivec, rio_interrupt, mode, "rio", hp);
1127 rio_dprintk(RIO_DEBUG_INIT, "Return value from request_irq: %d\n", retval);
1128 if (retval) {
1129 printk(KERN_ERR "rio: Cannot allocate irq %d.\n", hp->Ivec);
1130 hp->Ivec = 0;
1131 }
1132 rio_dprintk(RIO_DEBUG_INIT, "Got irq %d.\n", hp->Ivec);
1133 if (hp->Ivec != 0) {
1134 rio_dprintk(RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n");
1135 hp->Mode |= RIO_PCI_INT_ENABLE;
1136 } else
Willy Tarreau88dacbe2007-02-17 18:57:09 +01001137 hp->Mode &= ~RIO_PCI_INT_ENABLE;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001138 rio_dprintk(RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode);
1139 rio_start_card_running(hp);
1140 }
1141 /* Init the timer "always" to make sure that it can safely be
1142 deleted when we unload... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
Jiri Slaby40565f12007-02-12 00:52:31 -08001144 setup_timer(&hp->timer, rio_pollfunc, i);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001145 if (!hp->Ivec) {
1146 rio_dprintk(RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n", rio_poll);
Jiri Slaby40565f12007-02-12 00:52:31 -08001147 mod_timer(&hp->timer, jiffies + rio_poll);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001148 }
1149 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
Andrew Morton8d8706e2006-01-11 12:17:49 -08001151 if (found) {
1152 rio_dprintk(RIO_DEBUG_INIT, "rio: total of %d boards detected.\n", found);
1153 rio_init_drivers();
1154 } else {
1155 /* deregister the misc device we created earlier */
1156 misc_deregister(&rio_fw_device);
1157 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
Andrew Morton8d8706e2006-01-11 12:17:49 -08001159 func_exit();
1160 return found ? 0 : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161}
1162
1163
Andrew Morton8d8706e2006-01-11 12:17:49 -08001164static void __exit rio_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165{
Andrew Morton8d8706e2006-01-11 12:17:49 -08001166 int i;
1167 struct Host *hp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
Andrew Morton8d8706e2006-01-11 12:17:49 -08001169 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
Andrew Morton8d8706e2006-01-11 12:17:49 -08001171 for (i = 0, hp = p->RIOHosts; i < p->RIONumHosts; i++, hp++) {
1172 RIOHostReset(hp->Type, hp->CardP, hp->Slot);
1173 if (hp->Ivec) {
1174 free_irq(hp->Ivec, hp);
1175 rio_dprintk(RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec);
1176 }
1177 /* It is safe/allowed to del_timer a non-active timer */
Jiri Slaby40565f12007-02-12 00:52:31 -08001178 del_timer_sync(&hp->timer);
Amol Lad86842652006-12-06 20:35:19 -08001179 if (hp->Caddr)
1180 iounmap(hp->Caddr);
Jiri Slaby86fbf142006-10-21 10:24:01 -07001181 if (hp->Type == RIO_PCI)
1182 pci_dev_put(hp->pdev);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001183 }
1184
1185 if (misc_deregister(&rio_fw_device) < 0) {
1186 printk(KERN_INFO "rio: couldn't deregister control-device\n");
1187 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188
1189
Andrew Morton8d8706e2006-01-11 12:17:49 -08001190 rio_dprintk(RIO_DEBUG_CLEANUP, "Cleaning up drivers\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191
Andrew Morton8d8706e2006-01-11 12:17:49 -08001192 rio_release_drivers();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193
Andrew Morton8d8706e2006-01-11 12:17:49 -08001194 /* Release dynamically allocated memory */
1195 kfree(p->RIOPortp);
1196 kfree(p->RIOHosts);
1197 kfree(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
Andrew Morton8d8706e2006-01-11 12:17:49 -08001199 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200}
1201
1202module_init(rio_init);
1203module_exit(rio_exit);