2 /* rio_linux.c -- Linux driver for the Specialix RIO series cards.
5 * (C) 1999 R.E.Wolff@BitWizard.nl
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.
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.
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.
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,
30 * Revision 1.1 1999/07/11 10:13:54 wolff
35 #include <linux/module.h>
36 #include <linux/config.h>
37 #include <linux/kdev_t.h>
39 #include <linux/kernel.h>
40 #include <linux/sched.h>
41 #include <linux/ioport.h>
42 #include <linux/interrupt.h>
43 #include <linux/errno.h>
44 #include <linux/tty.h>
45 #include <linux/tty_flip.h>
47 #include <linux/serial.h>
48 #include <linux/fcntl.h>
49 #include <linux/major.h>
50 #include <linux/delay.h>
51 #include <linux/pci.h>
52 #include <linux/slab.h>
53 #include <linux/miscdevice.h>
54 #include <linux/init.h>
56 #include <linux/generic_serial.h>
57 #include <asm/uaccess.h>
59 #if BITS_PER_LONG != 32
60 # error FIXME: this driver only works on 32-bit platforms
63 #include "linux_compat.h"
100 #include "rio_linux.h"
102 /* I don't think that this driver can handle more than 512 ports on
103 one machine. Specialix specifies max 4 boards in one machine. I don't
104 know why. If you want to try anyway you'll have to increase the number
105 of boards in rio.h. You'll have to allocate more majors if you need
106 more than 512 ports.... */
108 #ifndef RIO_NORMAL_MAJOR0
109 /* This allows overriding on the compiler commandline, or in a "major.h"
110 include or something like that */
111 #define RIO_NORMAL_MAJOR0 154
112 #define RIO_NORMAL_MAJOR1 156
115 #ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8
116 #define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
119 #ifndef RIO_WINDOW_LEN
120 #define RIO_WINDOW_LEN 0x10000
124 /* Configurable options:
125 (Don't be too sure that it'll work if you toggle them) */
127 /* Am I paranoid or not ? ;-) */
128 #undef RIO_PARANOIA_CHECK
131 /* 20 -> 2000 per second. The card should rate-limit interrupts at 1000
132 Hz, but it is user configurable. I don't recommend going above 1000
133 Hz. The interrupt ratelimit might trigger if the interrupt is
134 shared with a very active other device.
135 undef this if you want to disable the check....
137 #define IRQ_RATE_LIMIT 200
140 /* Not implemented */
142 * The following defines are mostly for testing purposes. But if you need
143 * some nice reporting in your syslog, you can define them also.
145 #define RIO_REPORT_FIFO
146 #define RIO_REPORT_OVERRUN
150 /* These constants are derived from SCO Source */
154 /* locator */ "RIO Config here",
155 /* startuptime */ HZ*2, /* how long to wait for card to run */
156 /* slowcook */ 0, /* TRUE -> always use line disc. */
157 /* intrpolltime */ 1, /* The frequency of OUR polls */
158 /* breakinterval */ 25, /* x10 mS XXX: units seem to be 1ms not 10! -- REW*/
159 /* timer */ 10, /* mS */
160 /* RtaLoadBase */ 0x7000,
161 /* HostLoadBase */ 0x7C00,
162 /* XpHz */ 5, /* number of Xprint hits per second */
163 /* XpCps */ 120, /* Xprint characters per second */
164 /* XpOn */ "\033d#", /* start Xprint for a wyse 60 */
165 /* XpOff */ "\024", /* end Xprint for a wyse 60 */
166 /* MaxXpCps */ 2000, /* highest Xprint speed */
167 /* MinXpCps */ 10, /* slowest Xprint speed */
168 /* SpinCmds */ 1, /* non-zero for mega fast boots */
169 /* First Addr */ 0x0A0000, /* First address to look at */
170 /* Last Addr */ 0xFF0000, /* Last address looked at */
171 /* BufferSize */ 1024, /* Bytes per port of buffering */
172 /* LowWater */ 256, /* how much data left before wakeup */
173 /* LineLength */ 80, /* how wide is the console? */
174 /* CmdTimeout */ HZ, /* how long a close command may take */
180 /* Function prototypes */
182 static void rio_disable_tx_interrupts (void * ptr);
183 static void rio_enable_tx_interrupts (void * ptr);
184 static void rio_disable_rx_interrupts (void * ptr);
185 static void rio_enable_rx_interrupts (void * ptr);
186 static int rio_get_CD (void * ptr);
187 static void rio_shutdown_port (void * ptr);
188 static int rio_set_real_termios (void *ptr);
189 static void rio_hungup (void *ptr);
190 static void rio_close (void *ptr);
191 static int rio_chars_in_buffer (void * ptr);
192 static int rio_fw_ioctl (struct inode *inode, struct file *filp,
193 unsigned int cmd, unsigned long arg);
194 static int rio_init_drivers(void);
196 static void my_hd (void *addr, int len);
198 static struct tty_driver *rio_driver, *rio_driver2;
200 /* The name "p" is a bit non-descript. But that's what the rio-lynxos
201 sources use all over the place. */
207 /* You can have the driver poll your card.
208 - Set rio_poll to 1 to poll every timer tick (10ms on Intel).
209 This is used when the card cannot use an interrupt for some reason.
211 static int rio_poll = 1;
214 /* These are the only open spaces in my computer. Yours may have more
216 static int rio_probe_addrs[]= {0xc0000, 0xd0000, 0xe0000};
218 #define NR_RIO_ADDRS (sizeof(rio_probe_addrs)/sizeof (int))
221 /* Set the mask to all-ones. This alas, only supports 32 interrupts.
222 Some architectures may need more. -- Changed to LONG to
223 support up to 64 bits on 64bit architectures. -- REW 20/06/99 */
224 static long rio_irqmask = -1;
226 MODULE_AUTHOR("Rogier Wolff <R.E.Wolff@bitwizard.nl>, Patrick van de Lageweg <patrick@bitwizard.nl>");
227 MODULE_DESCRIPTION("RIO driver");
228 MODULE_LICENSE("GPL");
229 module_param(rio_poll, int, 0);
230 module_param(rio_debug, int, 0644);
231 module_param(rio_irqmask, long, 0);
233 static struct real_driver rio_real_driver = {
234 rio_disable_tx_interrupts,
235 rio_enable_tx_interrupts,
236 rio_disable_rx_interrupts,
237 rio_enable_rx_interrupts,
240 rio_set_real_termios,
248 * Firmware loader driver specific routines
252 static struct file_operations rio_fw_fops = {
253 .owner = THIS_MODULE,
254 .ioctl = rio_fw_ioctl,
257 static struct miscdevice rio_fw_device = {
258 RIOCTL_MISC_MINOR, "rioctl", &rio_fw_fops
265 #ifdef RIO_PARANOIA_CHECK
267 /* This doesn't work. Who's paranoid around here? Not me! */
269 static inline int rio_paranoia_check(struct rio_port const * port,
270 char *name, const char *routine)
273 static const char *badmagic =
274 KERN_ERR "rio: Warning: bad rio port magic number for device %s in %s\n";
275 static const char *badinfo =
276 KERN_ERR "rio: Warning: null rio port for device %s in %s\n";
279 printk (badinfo, name, routine);
282 if (port->magic != RIO_MAGIC) {
283 printk (badmagic, name, routine);
290 #define rio_paranoia_check(a,b,c) 0
295 static void my_hd (void *ad, int len)
298 unsigned char *addr = ad;
300 for (i=0;i<len;i+=16) {
301 rio_dprintk (RIO_DEBUG_PARAM, "%08x ", (int) addr+i);
303 rio_dprintk (RIO_DEBUG_PARAM, "%02x %s", addr[j+i], (j==7)?" ":"");
307 rio_dprintk (RIO_DEBUG_PARAM, "%c", (ch < 0x20)?'.':((ch > 0x7f)?'.':ch));
309 rio_dprintk (RIO_DEBUG_PARAM, "\n");
313 #define my_hd(ad,len) do{/* nothing*/ } while (0)
317 /* Delay a number of jiffies, allowing a signal to interrupt */
318 int RIODelay (struct Port *PortP, int njiffies)
322 rio_dprintk (RIO_DEBUG_DELAY, "delaying %d jiffies\n", njiffies);
323 msleep_interruptible(jiffies_to_msecs(njiffies));
326 if (signal_pending(current))
333 /* Delay a number of jiffies, disallowing a signal to interrupt */
334 int RIODelay_ni (struct Port *PortP, int njiffies)
338 rio_dprintk (RIO_DEBUG_DELAY, "delaying %d jiffies (ni)\n", njiffies);
339 msleep(jiffies_to_msecs(njiffies));
345 int rio_minor(struct tty_struct *tty)
347 return tty->index + (tty->driver == rio_driver) ? 0 : 256;
351 int rio_ismodem(struct tty_struct *tty)
357 static int rio_set_real_termios (void *ptr)
360 struct tty_struct *tty;
363 tty = ((struct Port *)ptr)->gs.tty;
365 modem = rio_ismodem(tty);
367 rv = RIOParam( (struct Port *) ptr, CONFIG, modem, 1);
375 static void rio_reset_interrupt (struct Host *HostP)
379 switch( HostP->Type ) {
383 WBYTE(HostP->ResetInt , 0xff);
390 static irqreturn_t rio_interrupt (int irq, void *ptr, struct pt_regs *regs)
395 HostP = (struct Host*)ptr; /* &p->RIOHosts[(long)ptr]; */
396 rio_dprintk (RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n",
399 /* AAargh! The order in which to do these things is essential and
402 - Rate limit goes before "recursive". Otherwise a series of
403 recursive calls will hang the machine in the interrupt routine.
405 - hardware twiddling goes before "recursive". Otherwise when we
406 poll the card, and a recursive interrupt happens, we won't
407 ack the card, so it might keep on interrupting us. (especially
408 level sensitive interrupt systems like PCI).
410 - Rate limit goes before hardware twiddling. Otherwise we won't
411 catch a card that has gone bonkers.
413 - The "initialized" test goes after the hardware twiddling. Otherwise
414 the card will stick us in the interrupt routine again.
416 - The initialized test goes before recursive.
421 #ifdef IRQ_RATE_LIMIT
422 /* Aaargh! I'm ashamed. This costs more lines-of-code than the
423 actual interrupt routine!. (Well, used to when I wrote that comment) */
428 if (lastjif == jiffies) {
429 if (++nintr > IRQ_RATE_LIMIT) {
430 free_irq (HostP->Ivec, ptr);
431 printk (KERN_ERR "rio: Too many interrupts. Turning off interrupt %d.\n",
440 rio_dprintk (RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n");
441 if (HostP->Ivec == irq) {
442 /* Tell the card we've noticed the interrupt. */
443 rio_reset_interrupt (HostP);
446 if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
449 if (test_and_set_bit (RIO_BOARD_INTR_LOCK, &HostP->locks)) {
450 printk (KERN_ERR "Recursive interrupt! (host %d/irq%d)\n",
451 (int) ptr, HostP->Ivec);
455 RIOServiceHost(p, HostP, irq);
457 rio_dprintk ( RIO_DEBUG_IFLOW, "riointr() doing host %d type %d\n",
458 (int) ptr, HostP->Type);
460 clear_bit (RIO_BOARD_INTR_LOCK, &HostP->locks);
461 rio_dprintk (RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n",
468 static void rio_pollfunc (unsigned long data)
472 rio_interrupt (0, &p->RIOHosts[data], NULL);
473 p->RIOHosts[data].timer.expires = jiffies + rio_poll;
474 add_timer (&p->RIOHosts[data].timer);
480 /* ********************************************************************** *
481 * Here are the routines that actually *
482 * interface with the generic_serial driver *
483 * ********************************************************************** */
485 /* Ehhm. I don't know how to fiddle with interrupts on the Specialix
486 cards. .... Hmm. Ok I figured it out. You don't. -- REW */
488 static void rio_disable_tx_interrupts (void * ptr)
492 /* port->gs.flags &= ~GS_TX_INTEN; */
498 static void rio_enable_tx_interrupts (void * ptr)
500 struct Port *PortP = ptr;
505 /* hn = PortP->HostP - p->RIOHosts;
507 rio_dprintk (RIO_DEBUG_TTY, "Pushing host %d\n", hn);
508 rio_interrupt (-1,(void *) hn, NULL); */
510 RIOTxEnable((char *) PortP);
513 * In general we cannot count on "tx empty" interrupts, although
514 * the interrupt routine seems to be able to tell the difference.
516 PortP->gs.flags &= ~GS_TX_INTEN;
522 static void rio_disable_rx_interrupts (void * ptr)
528 static void rio_enable_rx_interrupts (void * ptr)
530 /* struct rio_port *port = ptr; */
536 /* Jeez. Isn't this simple? */
537 static int rio_get_CD (void * ptr)
539 struct Port *PortP = ptr;
543 rv = (PortP->ModemState & MSVR1_CD) != 0;
545 rio_dprintk (RIO_DEBUG_INIT, "Getting CD status: %d\n", rv);
552 /* Jeez. Isn't this simple? Actually, we can sync with the actual port
553 by just pushing stuff into the queue going to the port... */
554 static int rio_chars_in_buffer (void * ptr)
563 /* Nothing special here... */
564 static void rio_shutdown_port (void * ptr)
570 PortP = (struct Port *)ptr;
571 PortP->gs.tty = NULL;
573 port->gs.flags &= ~ GS_ACTIVE;
575 rio_dprintk (RIO_DBUG_TTY, "No tty.\n");
578 if (!port->gs.tty->termios) {
579 rio_dprintk (RIO_DEBUG_TTY, "No termios.\n");
582 if (port->gs.tty->termios->c_cflag & HUPCL) {
583 rio_setsignals (port, 0, 0);
591 /* I haven't the foggiest why the decrement use count has to happen
592 here. The whole linux serial drivers stuff needs to be redesigned.
593 My guess is that this is a hack to minimize the impact of a bug
594 elsewhere. Thinking about it some more. (try it sometime) Try
595 running minicom on a serial port that is driven by a modularized
596 driver. Have the modem hangup. Then remove the driver module. Then
597 exit minicom. I expect an "oops". -- REW */
598 static void rio_hungup (void *ptr)
604 PortP = (struct Port *)ptr;
605 PortP->gs.tty = NULL;
611 /* The standard serial_close would become shorter if you'd wrap it like
613 rs_close (...){save_flags;cli;real_close();dec_use_count;restore_flags;}
615 static void rio_close (void *ptr)
621 PortP = (struct Port *)ptr;
625 if(PortP->gs.count) {
626 printk (KERN_ERR "WARNING port count:%d\n", PortP->gs.count);
630 PortP->gs.tty = NULL;
636 static int rio_fw_ioctl (struct inode *inode, struct file *filp,
637 unsigned int cmd, unsigned long arg)
642 /* The "dev" argument isn't used. */
643 rc = riocontrol (p, 0, cmd, (void *)arg, capable(CAP_SYS_ADMIN));
649 extern int RIOShortCommand(struct rio_info *p, struct Port *PortP,
650 int command, int len, int arg);
652 static int rio_ioctl (struct tty_struct * tty, struct file * filp,
653 unsigned int cmd, unsigned long arg)
661 PortP = (struct Port *)tty->driver_data;
667 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
668 (unsigned int *) arg);
672 if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
673 tty->termios->c_cflag =
674 (tty->termios->c_cflag & ~CLOCAL) |
680 if (access_ok(VERIFY_WRITE, (void *) arg,
681 sizeof(struct serial_struct)))
682 rc = gs_getserial(&PortP->gs, (struct serial_struct *) arg);
685 if ( PortP->State & RIO_DELETED ) {
686 rio_dprintk (RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
689 if (RIOShortCommand(p, PortP, SBREAK, 2, 250) == RIO_FAIL) {
690 rio_dprintk (RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
696 if ( PortP->State & RIO_DELETED ) {
697 rio_dprintk (RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
702 if (l > 255) l = 255;
703 if (RIOShortCommand(p, PortP, SBREAK, 2, arg?arg*100:250) == RIO_FAIL) {
704 rio_dprintk (RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
711 if (access_ok(VERIFY_READ, (void *) arg,
712 sizeof(struct serial_struct)))
713 rc = gs_setserial(&PortP->gs, (struct serial_struct *) arg);
717 * note: these IOCTLs no longer reach here. Use
718 * tiocmset/tiocmget driver methods instead. The
719 * #if 0 disablement predates this comment.
723 if (access_ok(VERIFY_WRITE, (void *) arg,
724 sizeof(unsigned int))) {
726 ival = rio_getsignals(port);
727 put_user(ival, (unsigned int *) arg);
731 if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
732 rio_setsignals(port, ((ival & TIOCM_DTR) ? 1 : -1),
733 ((ival & TIOCM_RTS) ? 1 : -1));
737 if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
738 rio_setsignals(port, ((ival & TIOCM_DTR) ? 0 : -1),
739 ((ival & TIOCM_RTS) ? 0 : -1));
743 if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
744 rio_setsignals(port, ((ival & TIOCM_DTR) ? 1 : 0),
745 ((ival & TIOCM_RTS) ? 1 : 0));
758 /* The throttle/unthrottle scheme for the Specialix card is different
759 * from other drivers and deserves some explanation.
760 * The Specialix hardware takes care of XON/XOFF
761 * and CTS/RTS flow control itself. This means that all we have to
762 * do when signalled by the upper tty layer to throttle/unthrottle is
763 * to make a note of it here. When we come to read characters from the
764 * rx buffers on the card (rio_receive_chars()) we look to see if the
765 * upper layer can accept more (as noted here in rio_rx_throt[]).
766 * If it can't we simply don't remove chars from the cards buffer.
767 * When the tty layer can accept chars, we again note that here and when
768 * rio_receive_chars() is called it will remove them from the cards buffer.
769 * The card will notice that a ports buffer has drained below some low
770 * water mark and will unflow control the line itself, using whatever
771 * flow control scheme is in use for that port. -- Simon Allen
774 static void rio_throttle (struct tty_struct * tty)
776 struct Port *port = (struct Port *)tty->driver_data;
779 /* If the port is using any type of input flow
780 * control then throttle the port.
783 if((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty)) ) {
784 port->State |= RIO_THROTTLE_RX;
791 static void rio_unthrottle (struct tty_struct * tty)
793 struct Port *port = (struct Port *)tty->driver_data;
796 /* Always unthrottle even if flow control is not enabled on
797 * this port in case we disabled flow control while the port
801 port->State &= ~RIO_THROTTLE_RX;
811 /* ********************************************************************** *
812 * Here are the initialization routines. *
813 * ********************************************************************** */
816 static struct vpd_prom *get_VPD_PROM (struct Host *hp)
818 static struct vpd_prom vpdp;
823 rio_dprintk (RIO_DEBUG_PROBE, "Going to verify vpd prom at %p.\n",
824 hp->Caddr + RIO_VPD_ROM);
827 for (i=0;i< sizeof (struct vpd_prom);i++)
828 *p++ = readb (hp->Caddr+RIO_VPD_ROM + i*2);
829 /* read_rio_byte (hp, RIO_VPD_ROM + i*2); */
831 /* Terminate the identifier string.
832 *** requires one extra byte in struct vpd_prom *** */
835 if (rio_debug & RIO_DEBUG_PROBE)
836 my_hd ((char *)&vpdp, 0x20);
843 static struct tty_operations rio_ops = {
847 .put_char = gs_put_char,
848 .flush_chars = gs_flush_chars,
849 .write_room = gs_write_room,
850 .chars_in_buffer = gs_chars_in_buffer,
851 .flush_buffer = gs_flush_buffer,
853 .throttle = rio_throttle,
854 .unthrottle = rio_unthrottle,
855 .set_termios = gs_set_termios,
861 static int rio_init_drivers(void)
865 rio_driver = alloc_tty_driver(256);
868 rio_driver2 = alloc_tty_driver(256);
874 rio_driver->owner = THIS_MODULE;
875 rio_driver->driver_name = "specialix_rio";
876 rio_driver->name = "ttySR";
877 rio_driver->major = RIO_NORMAL_MAJOR0;
878 rio_driver->type = TTY_DRIVER_TYPE_SERIAL;
879 rio_driver->subtype = SERIAL_TYPE_NORMAL;
880 rio_driver->init_termios = tty_std_termios;
881 rio_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
882 rio_driver->flags = TTY_DRIVER_REAL_RAW;
883 tty_set_operations(rio_driver, &rio_ops);
885 rio_driver2->owner = THIS_MODULE;
886 rio_driver2->driver_name = "specialix_rio";
887 rio_driver2->name = "ttySR";
888 rio_driver2->major = RIO_NORMAL_MAJOR1;
889 rio_driver2->type = TTY_DRIVER_TYPE_SERIAL;
890 rio_driver2->subtype = SERIAL_TYPE_NORMAL;
891 rio_driver2->init_termios = tty_std_termios;
892 rio_driver2->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
893 rio_driver2->flags = TTY_DRIVER_REAL_RAW;
894 tty_set_operations(rio_driver2, &rio_ops);
896 rio_dprintk (RIO_DEBUG_INIT, "set_termios = %p\n", gs_set_termios);
898 if ((error = tty_register_driver(rio_driver)))
900 if ((error = tty_register_driver(rio_driver2)))
905 tty_unregister_driver(rio_driver);
907 put_tty_driver(rio_driver2);
909 put_tty_driver(rio_driver);
911 printk(KERN_ERR "rio: Couldn't register a rio driver, error = %d\n",
917 static void * ckmalloc (int size)
921 p = kmalloc(size, GFP_KERNEL);
929 static int rio_init_datastructures (void)
935 /* Many drivers statically allocate the maximum number of ports
936 There is no reason not to allocate them dynamically. Is there? -- REW */
937 /* However, the RIO driver allows users to configure their first
938 RTA as the ports numbered 504-511. We therefore need to allocate
939 the whole range. :-( -- REW */
941 #define RI_SZ sizeof(struct rio_info)
942 #define HOST_SZ sizeof(struct Host)
943 #define PORT_SZ sizeof(struct Port *)
944 #define TMIO_SZ sizeof(struct termios *)
945 rio_dprintk (RIO_DEBUG_INIT, "getting : %d %d %d %d %d bytes\n",
950 RIO_PORTS * TMIO_SZ);
952 if (!(p = ckmalloc ( RI_SZ))) goto free0;
953 if (!(p->RIOHosts = ckmalloc (RIO_HOSTS * HOST_SZ))) goto free1;
954 if (!(p->RIOPortp = ckmalloc (RIO_PORTS * PORT_SZ))) goto free2;
955 p->RIOConf = RIOConf;
956 rio_dprintk (RIO_DEBUG_INIT, "Got : %p %p %p\n",
957 p, p->RIOHosts, p->RIOPortp);
960 for (i = 0; i < RIO_PORTS; i++) {
961 port = p->RIOPortp[i] = ckmalloc (sizeof (struct Port));
965 rio_dprintk (RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped);
967 port->gs.magic = RIO_MAGIC;
968 port->gs.close_delay = HZ/2;
969 port->gs.closing_wait = 30 * HZ;
970 port->gs.rd = &rio_real_driver;
971 spin_lock_init(&port->portSem);
973 * Initializing wait queue
975 init_waitqueue_head(&port->gs.open_wait);
976 init_waitqueue_head(&port->gs.close_wait);
979 /* We could postpone initializing them to when they are configured. */
984 if (rio_debug & RIO_DEBUG_INIT) {
985 my_hd (&rio_real_driver, sizeof (rio_real_driver));
992 free6:for (i--;i>=0;i--)
993 kfree (p->RIOPortp[i]);
996 free3:*/kfree (p->RIOPortp);
997 free2:kfree (p->RIOHosts);
999 rio_dprintk (RIO_DEBUG_INIT, "Not enough memory! %p %p %p\n",
1000 p, p->RIOHosts, p->RIOPortp);
1006 static void __exit rio_release_drivers(void)
1009 tty_unregister_driver(rio_driver2);
1010 tty_unregister_driver(rio_driver);
1011 put_tty_driver(rio_driver2);
1012 put_tty_driver(rio_driver);
1018 /* This was written for SX, but applies to RIO too...
1019 (including bugs....)
1021 There is another bit besides Bit 17. Turning that bit off
1022 (on boards shipped with the fix in the eeprom) results in a
1023 hang on the next access to the card.
1026 /********************************************************
1027 * Setting bit 17 in the CNTRL register of the PLX 9050 *
1028 * chip forces a retry on writes while a read is pending.*
1029 * This is to prevent the card locking up on Intel Xeon *
1030 * multiprocessor systems with the NX chipset. -- NV *
1031 ********************************************************/
1033 /* Newer cards are produced with this bit set from the configuration
1034 EEprom. As the bit is read/write for the CPU, we can fix it here,
1035 if we detect that it isn't set correctly. -- REW */
1037 static void fix_rio_pci (struct pci_dev *pdev)
1039 unsigned int hwbase;
1040 unsigned long rebase;
1043 #define CNTRL_REG_OFFSET 0x50
1044 #define CNTRL_REG_GOODVALUE 0x18260000
1046 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase);
1047 hwbase &= PCI_BASE_ADDRESS_MEM_MASK;
1048 rebase = (ulong) ioremap(hwbase, 0x80);
1049 t = readl (rebase + CNTRL_REG_OFFSET);
1050 if (t != CNTRL_REG_GOODVALUE) {
1051 printk (KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n",
1052 t, CNTRL_REG_GOODVALUE);
1053 writel (CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
1055 iounmap((char*) rebase);
1060 static int __init rio_init(void)
1066 struct vpd_prom *vpdp;
1070 struct pci_dev *pdev = NULL;
1072 unsigned short tshort;
1076 rio_dprintk (RIO_DEBUG_INIT, "Initing rio module... (rio_debug=%d)\n",
1079 if (abs ((long) (&rio_debug) - rio_debug) < 0x10000) {
1080 printk (KERN_WARNING "rio: rio_debug is an address, instead of a value. "
1081 "Assuming -1. Was %x/%p.\n", rio_debug, &rio_debug);
1085 if (misc_register(&rio_fw_device) < 0) {
1086 printk(KERN_ERR "RIO: Unable to register firmware loader driver.\n");
1090 retval = rio_init_datastructures ();
1092 misc_deregister(&rio_fw_device);
1097 /* First look for the JET devices: */
1098 while ((pdev = pci_get_device (PCI_VENDOR_ID_SPECIALIX,
1099 PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
1101 if (pci_enable_device(pdev)) continue;
1103 /* Specialix has a whole bunch of cards with
1104 0x2000 as the device ID. They say its because
1105 the standard requires it. Stupid standard. */
1106 /* It seems that reading a word doesn't work reliably on 2.0.
1107 Also, reading a non-aligned dword doesn't work. So we read the
1108 whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
1110 /* I don't know why the define doesn't work, constant 0x2c does --REW */
1111 pci_read_config_dword (pdev, 0x2c, &tint);
1112 tshort = (tint >> 16) & 0xffff;
1113 rio_dprintk (RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
1114 if (tshort != 0x0100) {
1115 rio_dprintk (RIO_DEBUG_PROBE, "But it's not a RIO card (%d)...\n",
1119 rio_dprintk (RIO_DEBUG_PROBE, "cp1\n");
1121 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_2, &tint);
1123 hp = &p->RIOHosts[p->RIONumHosts];
1124 hp->PaddrP = tint & PCI_BASE_ADDRESS_MEM_MASK;
1125 hp->Ivec = pdev->irq;
1126 if (((1 << hp->Ivec) & rio_irqmask) == 0)
1128 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1129 hp->CardP = (struct DpRam *) hp->Caddr;
1131 hp->Copy = rio_pcicopy;
1132 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1133 spin_lock_init(&hp->HostLock);
1134 rio_reset_interrupt (hp);
1135 rio_start_card_running (hp);
1137 rio_dprintk (RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n",
1138 (void *)p->RIOHosts[p->RIONumHosts].PaddrP,
1139 p->RIOHosts[p->RIONumHosts].Caddr);
1140 if (RIOBoardTest( p->RIOHosts[p->RIONumHosts].PaddrP,
1141 p->RIOHosts[p->RIONumHosts].Caddr,
1142 RIO_PCI, 0 ) == RIO_SUCCESS) {
1143 rio_dprintk (RIO_DEBUG_INIT, "Done RIOBoardTest\n");
1144 WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff);
1145 p->RIOHosts[p->RIONumHosts].UniqueNum =
1146 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) &0xFF)<< 0)|
1147 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) &0xFF)<< 8)|
1148 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) &0xFF)<<16)|
1149 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) &0xFF)<<24);
1150 rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n",
1151 p->RIOHosts[p->RIONumHosts].UniqueNum);
1154 p->RIOLastPCISearch = RIO_SUCCESS;
1158 iounmap((char*) (p->RIOHosts[p->RIONumHosts].Caddr));
1162 /* Then look for the older PCI card.... : */
1164 /* These older PCI cards have problems (only byte-mode access is
1165 supported), which makes them a bit awkward to support.
1166 They also have problems sharing interrupts. Be careful.
1167 (The driver now refuses to share interrupts for these
1168 cards. This should be sufficient).
1171 /* Then look for the older RIO/PCI devices: */
1172 while ((pdev = pci_get_device (PCI_VENDOR_ID_SPECIALIX,
1173 PCI_DEVICE_ID_SPECIALIX_RIO,
1175 if (pci_enable_device(pdev)) continue;
1177 #ifdef CONFIG_RIO_OLDPCI
1178 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &tint);
1180 hp = &p->RIOHosts[p->RIONumHosts];
1181 hp->PaddrP = tint & PCI_BASE_ADDRESS_MEM_MASK;
1182 hp->Ivec = pdev->irq;
1183 if (((1 << hp->Ivec) & rio_irqmask) == 0)
1185 hp->Ivec |= 0x8000; /* Mark as non-sharable */
1186 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1187 hp->CardP = (struct DpRam *) hp->Caddr;
1189 hp->Copy = rio_pcicopy;
1190 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1191 spin_lock_init(&hp->HostLock);
1193 rio_dprintk (RIO_DEBUG_PROBE, "Ivec: %x\n", hp->Ivec);
1194 rio_dprintk (RIO_DEBUG_PROBE, "Mode: %x\n", hp->Mode);
1196 rio_reset_interrupt (hp);
1197 rio_start_card_running (hp);
1198 rio_dprintk (RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n",
1199 (void *)p->RIOHosts[p->RIONumHosts].PaddrP,
1200 p->RIOHosts[p->RIONumHosts].Caddr);
1201 if (RIOBoardTest( p->RIOHosts[p->RIONumHosts].PaddrP,
1202 p->RIOHosts[p->RIONumHosts].Caddr,
1203 RIO_PCI, 0 ) == RIO_SUCCESS) {
1204 WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff);
1205 p->RIOHosts[p->RIONumHosts].UniqueNum =
1206 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) &0xFF)<< 0)|
1207 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) &0xFF)<< 8)|
1208 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) &0xFF)<<16)|
1209 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) &0xFF)<<24);
1210 rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n",
1211 p->RIOHosts[p->RIONumHosts].UniqueNum);
1213 p->RIOLastPCISearch = RIO_SUCCESS;
1217 iounmap((char*) (p->RIOHosts[p->RIONumHosts].Caddr));
1220 printk (KERN_ERR "Found an older RIO PCI card, but the driver is not "
1221 "compiled to support it.\n");
1226 /* Now probe for ISA cards... */
1227 for (i=0;i<NR_RIO_ADDRS;i++) {
1228 hp = &p->RIOHosts[p->RIONumHosts];
1229 hp->PaddrP = rio_probe_addrs[i];
1230 /* There was something about the IRQs of these cards. 'Forget what.--REW */
1232 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1233 hp->CardP = (struct DpRam *) hp->Caddr;
1235 hp->Copy = rio_pcicopy; /* AT card PCI???? - PVDL
1236 * -- YES! this is now a normal copy. Only the
1237 * old PCI card uses the special PCI copy.
1238 * Moreover, the ISA card will work with the
1239 * special PCI copy anyway. -- REW */
1241 spin_lock_init(&hp->HostLock);
1243 vpdp = get_VPD_PROM (hp);
1244 rio_dprintk (RIO_DEBUG_PROBE, "Got VPD ROM\n");
1246 if ((strncmp (vpdp->identifier, RIO_ISA_IDENT, 16) == 0) ||
1247 (strncmp (vpdp->identifier, RIO_ISA2_IDENT, 16) == 0) ||
1248 (strncmp (vpdp->identifier, RIO_ISA3_IDENT, 16) == 0)) {
1249 /* Board is present... */
1250 if (RIOBoardTest (hp->PaddrP,
1251 hp->Caddr, RIO_AT, 0) == RIO_SUCCESS) {
1252 /* ... and feeling fine!!!! */
1253 rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n",
1254 p->RIOHosts[p->RIONumHosts].UniqueNum);
1255 if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) {
1256 rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, host%d uniqid = %x.\n",
1258 p->RIOHosts[p->RIONumHosts-1].UniqueNum);
1265 iounmap ((char*) (hp->Caddr));
1270 for (i=0;i<p->RIONumHosts;i++) {
1271 hp = &p->RIOHosts[i];
1273 int mode = SA_SHIRQ;
1274 if (hp->Ivec & 0x8000) {mode = 0; hp->Ivec &= 0x7fff;}
1275 rio_dprintk (RIO_DEBUG_INIT, "Requesting interrupt hp: %p rio_interrupt: %d Mode: %x\n", hp,hp->Ivec, hp->Mode);
1276 retval = request_irq (hp->Ivec, rio_interrupt, mode, "rio", hp);
1277 rio_dprintk (RIO_DEBUG_INIT, "Return value from request_irq: %d\n", retval);
1279 printk(KERN_ERR "rio: Cannot allocate irq %d.\n", hp->Ivec);
1282 rio_dprintk (RIO_DEBUG_INIT, "Got irq %d.\n", hp->Ivec);
1284 rio_dprintk (RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n");
1285 hp->Mode |= RIO_PCI_INT_ENABLE;
1287 hp->Mode &= !RIO_PCI_INT_ENABLE;
1288 rio_dprintk (RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode);
1289 rio_start_card_running (hp);
1291 /* Init the timer "always" to make sure that it can safely be
1292 deleted when we unload... */
1294 init_timer (&hp->timer);
1296 rio_dprintk (RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n",
1299 hp->timer.function = rio_pollfunc;
1300 hp->timer.expires = jiffies + rio_poll;
1301 add_timer (&hp->timer);
1306 rio_dprintk (RIO_DEBUG_INIT, "rio: total of %d boards detected.\n", found);
1307 rio_init_drivers ();
1309 /* deregister the misc device we created earlier */
1310 misc_deregister(&rio_fw_device);
1314 return found?0:-EIO;
1318 static void __exit rio_exit (void)
1325 for (i=0,hp=p->RIOHosts;i<p->RIONumHosts;i++, hp++) {
1326 RIOHostReset (hp->Type, hp->CardP, hp->Slot);
1328 free_irq (hp->Ivec, hp);
1329 rio_dprintk (RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec);
1331 /* It is safe/allowed to del_timer a non-active timer */
1332 del_timer (&hp->timer);
1335 if (misc_deregister(&rio_fw_device) < 0) {
1336 printk (KERN_INFO "rio: couldn't deregister control-device\n");
1340 rio_dprintk (RIO_DEBUG_CLEANUP, "Cleaning up drivers\n");
1342 rio_release_drivers ();
1344 /* Release dynamically allocated memory */
1345 kfree (p->RIOPortp);
1346 kfree (p->RIOHosts);
1352 module_init(rio_init);
1353 module_exit(rio_exit);
1356 * Anybody who knows why this doesn't work for me, please tell me -- REW.
1357 * Snatched from scsi.c (fixed one spelling error):
1358 * Overrides for Emacs so that we follow Linus' tabbing style.
1359 * Emacs will notice this stuff at the end of the file and automatically
1360 * adjust the settings for this buffer only. This must remain at the end
1362 * ---------------------------------------------------------------------------
1365 * c-brace-imaginary-offset: 0
1366 * c-brace-offset: -4
1367 * c-argdecl-indent: 4
1368 * c-label-offset: -4
1369 * c-continued-statement-offset: 4
1370 * c-continued-brace-offset: 0
1371 * indent-tabs-mode: nil