1 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_linux.c,v $ 30 * Revision 1.1.1.1 2008/10/15 03:26:32 james26_jang 31 * Initial. 32 * 33 * Revision 1.1.1.1 2008/07/21 09:15:00 james26_jang 34 * New UI, New QoS, New wireless driver(4.151.10.29), ipmonitor. 35 * 36 * Revision 1.1.1.1 2008/07/02 14:39:21 james26_jang 37 * 4.100.10.29, New QoS and New UI. 38 * 39 * Revision 1.1.1.1 2007/02/15 12:11:22 jiahao 40 * initial update 41 * 42 * Revision 1.1.1.1 2007/01/25 12:51:53 jiahao_jhou 43 * 44 * 45 * Revision 1.1.1.1 2003/02/03 22:37:40 mhuang 46 * LINUX_2_4 branch snapshot from linux-mips.org CVS 47 * 48 * Revision 1.1 1999/07/11 10:13:54 wolff 49 * Initial revision 50 * 51 * */ 52 53 54#define RCS_ID "$Id: rio_linux.c,v 1.1.1.1 2008/10/15 03:26:32 james26_jang Exp $" 55#define RCS_REV "$Revision: 1.1.1.1 $" 56 57 58#include <linux/module.h> 59#include <linux/config.h> 60#include <linux/kdev_t.h> 61#include <asm/io.h> 62#include <linux/kernel.h> 63#include <linux/sched.h> 64#include <linux/ioport.h> 65#include <linux/interrupt.h> 66#include <linux/errno.h> 67#include <linux/tty.h> 68#include <linux/tty_flip.h> 69#include <linux/mm.h> 70#include <linux/serial.h> 71#include <linux/fcntl.h> 72#include <linux/major.h> 73#include <linux/delay.h> 74#include <linux/tqueue.h> 75#include <linux/version.h> 76#include <linux/pci.h> 77#include <linux/slab.h> 78#include <linux/miscdevice.h> 79#include <linux/init.h> 80 81#include <linux/compatmac.h> 82#include <linux/generic_serial.h> 83 84#if BITS_PER_LONG != 32 85# error FIXME: this driver only works on 32-bit platforms 86#endif 87 88#include "linux_compat.h" 89#include "typdef.h" 90#include "pkt.h" 91#include "daemon.h" 92#include "rio.h" 93#include "riospace.h" 94#include "top.h" 95#include "cmdpkt.h" 96#include "map.h" 97#include "riotypes.h" 98#include "rup.h" 99#include "port.h" 100#include "riodrvr.h" 101#include "rioinfo.h" 102#include "func.h" 103#include "errors.h" 104#include "pci.h" 105 106#include "parmmap.h" 107#include "unixrup.h" 108#include "board.h" 109#include "host.h" 110#include "error.h" 111#include "phb.h" 112#include "link.h" 113#include "cmdblk.h" 114#include "route.h" 115#include "control.h" 116#include "cirrus.h" 117#include "rioioctl.h" 118#include "param.h" 119#include "list.h" 120#include "sam.h" 121#include "protsts.h" 122#include "rioboard.h" 123 124 125#include "rio_linux.h" 126 127/* I don't think that this driver can handle more than 512 ports on 128one machine. Specialix specifies max 4 boards in one machine. I don't 129know why. If you want to try anyway you'll have to increase the number 130of boards in rio.h. You'll have to allocate more majors if you need 131more than 512 ports.... */ 132 133 134/* Why the hell am I defining these here? */ 135#define RIO_TYPE_NORMAL 1 136#define RIO_TYPE_CALLOUT 2 137 138#ifndef RIO_NORMAL_MAJOR0 139/* This allows overriding on the compiler commandline, or in a "major.h" 140 include or something like that */ 141#define RIO_NORMAL_MAJOR0 154 142#define RIO_CALLOUT_MAJOR0 155 143#define RIO_NORMAL_MAJOR1 156 144#define RIO_CALLOUT_MAJOR1 157 145#endif 146 147#ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 148#define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000 149#endif 150 151#ifndef RIO_WINDOW_LEN 152#define RIO_WINDOW_LEN 0x10000 153#endif 154 155 156/* Configurable options: 157 (Don't be too sure that it'll work if you toggle them) */ 158 159/* Am I paranoid or not ? ;-) */ 160#undef RIO_PARANOIA_CHECK 161 162 163/* 20 -> 2000 per second. The card should rate-limit interrupts at 1000 164 Hz, but it is user configurable. I don't recommend going above 1000 165 Hz. The interrupt ratelimit might trigger if the interrupt is 166 shared with a very active other device. 167 undef this if you want to disable the check.... 168*/ 169#define IRQ_RATE_LIMIT 200 170 171 172 173/* These constants are derived from SCO Source */ 174static struct Conf 175RIOConf = 176{ 177 /* locator */ "RIO Config here", 178 /* startuptime */ HZ*2, /* how long to wait for card to run */ 179 /* slowcook */ 0, /* TRUE -> always use line disc. */ 180 /* intrpolltime */ 1, /* The frequency of OUR polls */ 181 /* breakinterval */ 25, 182 /* timer */ 10, /* mS */ 183 /* RtaLoadBase */ 0x7000, 184 /* HostLoadBase */ 0x7C00, 185 /* XpHz */ 5, /* number of Xprint hits per second */ 186 /* XpCps */ 120, /* Xprint characters per second */ 187 /* XpOn */ "\033d#", /* start Xprint for a wyse 60 */ 188 /* XpOff */ "\024", /* end Xprint for a wyse 60 */ 189 /* MaxXpCps */ 2000, /* highest Xprint speed */ 190 /* MinXpCps */ 10, /* slowest Xprint speed */ 191 /* SpinCmds */ 1, /* non-zero for mega fast boots */ 192 /* First Addr */ 0x0A0000, /* First address to look at */ 193 /* Last Addr */ 0xFF0000, /* Last address looked at */ 194 /* BufferSize */ 1024, /* Bytes per port of buffering */ 195 /* LowWater */ 256, /* how much data left before wakeup */ 196 /* LineLength */ 80, /* how wide is the console? */ 197 /* CmdTimeout */ HZ, /* how long a close command may take */ 198}; 199 200 201 202 203/* Function prototypes */ 204 205static void rio_disable_tx_interrupts (void * ptr); 206static void rio_enable_tx_interrupts (void * ptr); 207static void rio_disable_rx_interrupts (void * ptr); 208static void rio_enable_rx_interrupts (void * ptr); 209static int rio_get_CD (void * ptr); 210static void rio_shutdown_port (void * ptr); 211static int rio_set_real_termios (void *ptr); 212static void rio_hungup (void *ptr); 213static void rio_close (void *ptr); 214static int rio_chars_in_buffer (void * ptr); 215static int rio_fw_ioctl (struct inode *inode, struct file *filp, 216 unsigned int cmd, unsigned long arg); 217static int rio_init_drivers(void); 218 219void my_hd (void *addr, int len); 220 221static struct tty_driver rio_driver, rio_callout_driver; 222static struct tty_driver rio_driver2, rio_callout_driver2; 223 224static struct tty_struct * rio_table[RIO_NPORTS]; 225static struct termios ** rio_termios; 226static struct termios ** rio_termios_locked; 227 228/* The name "p" is a bit non-descript. But that's what the rio-lynxos 229sources use all over the place. */ 230struct rio_info *p; 231 232/* struct rio_board boards[RIO_HOSTS]; */ 233struct rio_port *rio_ports; 234 235int rio_refcount; 236int rio_initialized; 237int rio_nports; 238int rio_debug; 239 240 241/* You can have the driver poll your card. 242 - Set rio_poll to 1 to poll every timer tick (10ms on Intel). 243 This is used when the card cannot use an interrupt for some reason. 244*/ 245int rio_poll = 1; 246 247 248/* These are the only open spaces in my computer. Yours may have more 249 or less.... */ 250int rio_probe_addrs[]= {0xc0000, 0xd0000, 0xe0000}; 251 252#define NR_RIO_ADDRS (sizeof(rio_probe_addrs)/sizeof (int)) 253 254 255/* Set the mask to all-ones. This alas, only supports 32 interrupts. 256 Some architectures may need more. -- Changed to LONG to 257 support up to 64 bits on 64bit architectures. -- REW 20/06/99 */ 258long rio_irqmask = -1; 259 260#ifndef TWO_ZERO 261MODULE_AUTHOR("Rogier Wolff <R.E.Wolff@bitwizard.nl>, Patrick van de Lageweg <patrick@bitwizard.nl>"); 262MODULE_DESCRIPTION("RIO driver"); 263MODULE_LICENSE("GPL"); 264MODULE_PARM(rio_poll, "i"); 265MODULE_PARM(rio_debug, "i"); 266MODULE_PARM(rio_irqmask, "i"); 267#endif 268 269static struct real_driver rio_real_driver = { 270 rio_disable_tx_interrupts, 271 rio_enable_tx_interrupts, 272 rio_disable_rx_interrupts, 273 rio_enable_rx_interrupts, 274 rio_get_CD, 275 rio_shutdown_port, 276 rio_set_real_termios, 277 rio_chars_in_buffer, 278 rio_close, 279 rio_hungup, 280 NULL 281}; 282 283/* 284 * Firmware loader driver specific routines 285 * 286 */ 287 288static struct file_operations rio_fw_fops = { 289 owner: THIS_MODULE, 290 ioctl: rio_fw_ioctl, 291}; 292 293struct miscdevice rio_fw_device = { 294 RIOCTL_MISC_MINOR, "rioctl", &rio_fw_fops 295}; 296 297 298 299 300 301#ifdef RIO_PARANOIA_CHECK 302 303/* This doesn't work. Who's paranoid around here? Not me! */ 304 305static inline int rio_paranoia_check(struct rio_port const * port, 306 kdev_t device, const char *routine) 307{ 308 309 static const char *badmagic = 310 KERN_ERR "rio: Warning: bad rio port magic number for device %s in %s\n"; 311 static const char *badinfo = 312 KERN_ERR "rio: Warning: null rio port for device %s in %s\n"; 313 314 if (!port) { 315 printk (badinfo, kdevname(device), routine); 316 return 1; 317 } 318 if (port->magic != RIO_MAGIC) { 319 printk (badmagic, kdevname(device), routine); 320 return 1; 321 } 322 323 return 0; 324} 325#else 326#define rio_paranoia_check(a,b,c) 0 327#endif 328 329 330#ifdef DEBUG 331void my_hd (void *ad, int len) 332{ 333 int i, j, ch; 334 unsigned char *addr = ad; 335 336 for (i=0;i<len;i+=16) { 337 rio_dprintk (RIO_DEBUG_PARAM, "%08x ", (int) addr+i); 338 for (j=0;j<16;j++) { 339 rio_dprintk (RIO_DEBUG_PARAM, "%02x %s", addr[j+i], (j==7)?" ":""); 340 } 341 for (j=0;j<16;j++) { 342 ch = addr[j+i]; 343 rio_dprintk (RIO_DEBUG_PARAM, "%c", (ch < 0x20)?'.':((ch > 0x7f)?'.':ch)); 344 } 345 rio_dprintk (RIO_DEBUG_PARAM, "\n"); 346 } 347} 348#else 349#define my_hd(ad,len) do{/* nothing*/ } while (0) 350#endif 351 352 353/* Delay a number of jiffies, allowing a signal to interrupt */ 354int RIODelay (struct Port *PortP, int njiffies) 355{ 356 func_enter (); 357 358 rio_dprintk (RIO_DEBUG_DELAY, "delaying %d jiffies\n", njiffies); 359 current->state = TASK_INTERRUPTIBLE; 360 schedule_timeout(njiffies); 361 current->state = TASK_RUNNING; 362 func_exit(); 363 364 if (signal_pending(current)) 365 return RIO_FAIL; 366 else 367 return !RIO_FAIL; 368} 369 370 371/* Delay a number of jiffies, disallowing a signal to interrupt */ 372int RIODelay_ni (struct Port *PortP, int njiffies) 373{ 374 func_enter (); 375 376 rio_dprintk (RIO_DEBUG_DELAY, "delaying %d jiffies (ni)\n", njiffies); 377 current->state = TASK_UNINTERRUPTIBLE; 378 schedule_timeout(njiffies); 379 current->state = TASK_RUNNING; 380 func_exit(); 381 return !RIO_FAIL; 382} 383 384 385int rio_minor (kdev_t device) 386{ 387 return MINOR (device) + 388 256 * ((MAJOR (device) == RIO_NORMAL_MAJOR1) || 389 (MAJOR (device) == RIO_CALLOUT_MAJOR1)); 390} 391 392 393int rio_ismodem (kdev_t device) 394{ 395 return (MAJOR (device) == RIO_NORMAL_MAJOR0) || 396 (MAJOR (device) == RIO_NORMAL_MAJOR1); 397} 398 399 400void rio_udelay (int usecs) 401{ 402 udelay (usecs); 403} 404 405 406void rio_inc_mod_count (void) 407{ 408#ifdef MODULE 409 func_enter (); 410 rio_dprintk (RIO_DEBUG_MOD_COUNT, "rio_inc_mod_count\n"); 411 MOD_INC_USE_COUNT; 412 func_exit (); 413#endif 414} 415 416 417void rio_dec_mod_count (void) 418{ 419#ifdef MODULE 420 func_enter (); 421 rio_dprintk (RIO_DEBUG_MOD_COUNT, "rio_dec_mod_count\n"); 422 MOD_DEC_USE_COUNT; 423 func_exit (); 424#endif 425} 426 427 428static int rio_set_real_termios (void *ptr) 429{ 430 int rv, modem; 431 struct tty_struct *tty; 432 func_enter(); 433 434 tty = ((struct Port *)ptr)->gs.tty; 435 436 modem = (MAJOR(tty->device) == RIO_NORMAL_MAJOR0) || (MAJOR(tty->device) == RIO_NORMAL_MAJOR1); 437 438 rv = RIOParam( (struct Port *) ptr, CONFIG, modem, 1); 439 440 func_exit (); 441 442 return rv; 443} 444 445 446void rio_reset_interrupt (struct Host *HostP) 447{ 448 func_enter(); 449 450 switch( HostP->Type ) { 451 case RIO_AT: 452 case RIO_MCA: 453 case RIO_PCI: 454 WBYTE(HostP->ResetInt , 0xff); 455 } 456 457 func_exit(); 458} 459 460 461static void rio_interrupt (int irq, void *ptr, struct pt_regs *regs) 462{ 463 struct Host *HostP; 464 func_enter (); 465 466 HostP = (struct Host*)ptr; /* &p->RIOHosts[(long)ptr]; */ 467 rio_dprintk (RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n", 468 irq, HostP->Ivec); 469 470 /* AAargh! The order in which to do these things is essential and 471 not trivial. 472 473 - Rate limit goes before "recursive". Otherwise a series of 474 recursive calls will hang the machine in the interrupt routine. 475 476 - hardware twiddling goes before "recursive". Otherwise when we 477 poll the card, and a recursive interrupt happens, we wont 478 ack the card, so it might keep on interrupting us. (especially 479 level sensitive interrupt systems like PCI). 480 481 - Rate limit goes before hardware twiddling. Otherwise we won't 482 catch a card that has gone bonkers. 483 484 - The "initialized" test goes after the hardware twiddling. Otherwise 485 the card will stick us in the interrupt routine again. 486 487 - The initialized test goes before recursive. 488 */ 489 490 491 492#ifdef IRQ_RATE_LIMIT 493 /* Aaargh! I'm ashamed. This costs more lines-of-code than the 494 actual interrupt routine!. (Well, used to when I wrote that comment) */ 495 { 496 static int lastjif; 497 static int nintr=0; 498 499 if (lastjif == jiffies) { 500 if (++nintr > IRQ_RATE_LIMIT) { 501 free_irq (HostP->Ivec, ptr); 502 printk (KERN_ERR "rio: Too many interrupts. Turning off interrupt %d.\n", 503 HostP->Ivec); 504 } 505 } else { 506 lastjif = jiffies; 507 nintr = 0; 508 } 509 } 510#endif 511 rio_dprintk (RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n"); 512 if (HostP->Ivec == irq) { 513 /* Tell the card we've noticed the interrupt. */ 514 rio_reset_interrupt (HostP); 515 } 516 517 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) return; 518 519 if (test_and_set_bit (RIO_BOARD_INTR_LOCK, &HostP->locks)) { 520 printk (KERN_ERR "Recursive interrupt! (host %d/irq%d)\n", 521 (int) ptr, HostP->Ivec); 522 return; 523 } 524 525 RIOServiceHost(p, HostP, irq); 526 527 rio_dprintk ( RIO_DEBUG_IFLOW, "riointr() doing host %d type %d\n", 528 (int) ptr, HostP->Type); 529 530 clear_bit (RIO_BOARD_INTR_LOCK, &HostP->locks); 531 rio_dprintk (RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n", 532 irq, HostP->Ivec); 533 func_exit (); 534} 535 536 537static void rio_pollfunc (unsigned long data) 538{ 539 func_enter (); 540 541 rio_interrupt (0, &p->RIOHosts[data], NULL); 542 p->RIOHosts[data].timer.expires = jiffies + rio_poll; 543 add_timer (&p->RIOHosts[data].timer); 544 545 func_exit (); 546} 547 548 549/* ********************************************************************** * 550 * Here are the routines that actually * 551 * interface with the generic_serial driver * 552 * ********************************************************************** */ 553 554/* Ehhm. I don't know how to fiddle with interrupts on the Specialix 555 cards. .... Hmm. Ok I figured it out. You don't. -- REW */ 556 557static void rio_disable_tx_interrupts (void * ptr) 558{ 559 func_enter(); 560 561 /* port->gs.flags &= ~GS_TX_INTEN; */ 562 563 func_exit(); 564} 565 566 567static void rio_enable_tx_interrupts (void * ptr) 568{ 569 struct Port *PortP = ptr; 570 /* int hn; */ 571 572 func_enter(); 573 574 /* hn = PortP->HostP - p->RIOHosts; 575 576 rio_dprintk (RIO_DEBUG_TTY, "Pushing host %d\n", hn); 577 rio_interrupt (-1,(void *) hn, NULL); */ 578 579 RIOTxEnable((char *) PortP); 580 581 /* 582 * In general we cannot count on "tx empty" interrupts, although 583 * the interrupt routine seems to be able to tell the difference. 584 */ 585 PortP->gs.flags &= ~GS_TX_INTEN; 586 587 func_exit(); 588} 589 590 591static void rio_disable_rx_interrupts (void * ptr) 592{ 593 func_enter(); 594 func_exit(); 595} 596 597static void rio_enable_rx_interrupts (void * ptr) 598{ 599 /* struct rio_port *port = ptr; */ 600 func_enter(); 601 func_exit(); 602} 603 604 605/* Jeez. Isn't this simple? */ 606static int rio_get_CD (void * ptr) 607{ 608 struct Port *PortP = ptr; 609 int rv; 610 611 func_enter(); 612 rv = (PortP->ModemState & MSVR1_CD) != 0; 613 614 rio_dprintk (RIO_DEBUG_INIT, "Getting CD status: %d\n", rv); 615 616 func_exit(); 617 return rv; 618} 619 620 621/* Jeez. Isn't this simple? Actually, we can sync with the actual port 622 by just pushing stuff into the queue going to the port... */ 623static int rio_chars_in_buffer (void * ptr) 624{ 625 func_enter(); 626 627 func_exit(); 628 return 0; 629} 630 631 632/* Nothing special here... */ 633static void rio_shutdown_port (void * ptr) 634{ 635 struct Port *PortP; 636 637 func_enter(); 638 639 PortP = (struct Port *)ptr; 640 PortP->gs.tty = NULL; 641 642 func_exit(); 643} 644 645 646/* I haven't the foggiest why the decrement use count has to happen 647 here. The whole linux serial drivers stuff needs to be redesigned. 648 My guess is that this is a hack to minimize the impact of a bug 649 elsewhere. Thinking about it some more. (try it sometime) Try 650 running minicom on a serial port that is driven by a modularized 651 driver. Have the modem hangup. Then remove the driver module. Then 652 exit minicom. I expect an "oops". -- REW */ 653static void rio_hungup (void *ptr) 654{ 655 struct Port *PortP; 656 657 func_enter(); 658 659 PortP = (struct Port *)ptr; 660 PortP->gs.tty = NULL; 661 rio_dec_mod_count (); 662 663 func_exit (); 664} 665 666 667/* The standard serial_close would become shorter if you'd wrap it like 668 this. 669 rs_close (...){save_flags;cli;real_close();dec_use_count;restore_flags;} 670 */ 671static void rio_close (void *ptr) 672{ 673 struct Port *PortP; 674 675 func_enter (); 676 677 PortP = (struct Port *)ptr; 678 679 riotclose (ptr); 680 681 if(PortP->gs.count) { 682 printk (KERN_ERR "WARNING port count:%d\n", PortP->gs.count); 683 PortP->gs.count = 0; 684 } 685 686 PortP->gs.tty = NULL; 687 rio_dec_mod_count (); 688 func_exit (); 689} 690 691 692 693static int rio_fw_ioctl (struct inode *inode, struct file *filp, 694 unsigned int cmd, unsigned long arg) 695{ 696 int rc = 0; 697 func_enter(); 698 699 /* The "dev" argument isn't used. */ 700 rc = -riocontrol (p, 0, cmd, (void *)arg, suser ()); 701 702 func_exit (); 703 return rc; 704} 705 706extern int RIOShortCommand(struct rio_info *p, struct Port *PortP, 707 int command, int len, int arg); 708 709static int rio_ioctl (struct tty_struct * tty, struct file * filp, 710 unsigned int cmd, unsigned long arg) 711{ 712 int rc; 713 struct Port *PortP; 714 int ival; 715 716 func_enter(); 717 718 PortP = (struct Port *)tty->driver_data; 719 720 rc = 0; 721 switch (cmd) { 722 case TIOCSSOFTCAR: 723 if ((rc = verify_area(VERIFY_READ, (void *) arg, 724 sizeof(int))) == 0) { 725 Get_user(ival, (unsigned int *) arg); 726 tty->termios->c_cflag = 727 (tty->termios->c_cflag & ~CLOCAL) | 728 (ival ? CLOCAL : 0); 729 } 730 break; 731 case TIOCGSERIAL: 732 if ((rc = verify_area(VERIFY_WRITE, (void *) arg, 733 sizeof(struct serial_struct))) == 0) 734 rc = gs_getserial(&PortP->gs, (struct serial_struct *) arg); 735 break; 736 case TCSBRK: 737 if ( PortP->State & RIO_DELETED ) { 738 rio_dprintk (RIO_DEBUG_TTY, "BREAK on deleted RTA\n"); 739 rc = -EIO; 740 } else { 741 if (RIOShortCommand(p, PortP, SBREAK, 2, 250) == RIO_FAIL) { 742 rio_dprintk (RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n"); 743 rc = -EIO; 744 } 745 } 746 break; 747 case TCSBRKP: 748 if ( PortP->State & RIO_DELETED ) { 749 rio_dprintk (RIO_DEBUG_TTY, "BREAK on deleted RTA\n"); 750 rc = -EIO; 751 } else { 752 int l; 753 l = arg?arg*100:250; 754 if (l > 255) l = 255; 755 if (RIOShortCommand(p, PortP, SBREAK, 2, arg?arg*100:250) == RIO_FAIL) { 756 rio_dprintk (RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n"); 757 rc = -EIO; 758 } 759 } 760 break; 761 case TIOCSSERIAL: 762 if ((rc = verify_area(VERIFY_READ, (void *) arg, 763 sizeof(struct serial_struct))) == 0) 764 rc = gs_setserial(&PortP->gs, (struct serial_struct *) arg); 765 break; 766 default: 767 rc = -ENOIOCTLCMD; 768 break; 769 } 770 func_exit(); 771 return rc; 772} 773 774 775/* The throttle/unthrottle scheme for the Specialix card is different 776 * from other drivers and deserves some explanation. 777 * The Specialix hardware takes care of XON/XOFF 778 * and CTS/RTS flow control itself. This means that all we have to 779 * do when signalled by the upper tty layer to throttle/unthrottle is 780 * to make a note of it here. When we come to read characters from the 781 * rx buffers on the card (rio_receive_chars()) we look to see if the 782 * upper layer can accept more (as noted here in rio_rx_throt[]). 783 * If it can't we simply don't remove chars from the cards buffer. 784 * When the tty layer can accept chars, we again note that here and when 785 * rio_receive_chars() is called it will remove them from the cards buffer. 786 * The card will notice that a ports buffer has drained below some low 787 * water mark and will unflow control the line itself, using whatever 788 * flow control scheme is in use for that port. -- Simon Allen 789 */ 790 791static void rio_throttle (struct tty_struct * tty) 792{ 793 struct Port *port = (struct Port *)tty->driver_data; 794 795 func_enter(); 796 /* If the port is using any type of input flow 797 * control then throttle the port. 798 */ 799 800 if((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty)) ) { 801 port->State |= RIO_THROTTLE_RX; 802 } 803 804 func_exit(); 805} 806 807 808static void rio_unthrottle (struct tty_struct * tty) 809{ 810 struct Port *port = (struct Port *)tty->driver_data; 811 812 func_enter(); 813 /* Always unthrottle even if flow control is not enabled on 814 * this port in case we disabled flow control while the port 815 * was throttled 816 */ 817 818 port->State &= ~RIO_THROTTLE_RX; 819 820 func_exit(); 821 return; 822} 823 824 825 826 827 828/* ********************************************************************** * 829 * Here are the initialization routines. * 830 * ********************************************************************** */ 831 832 833struct vpd_prom *get_VPD_PROM (struct Host *hp) 834{ 835 static struct vpd_prom vpdp; 836 char *p; 837 int i; 838 839 func_enter(); 840 rio_dprintk (RIO_DEBUG_PROBE, "Going to verify vpd prom at %p.\n", 841 hp->Caddr + RIO_VPD_ROM); 842 843 p = (char *) &vpdp; 844 for (i=0;i< sizeof (struct vpd_prom);i++) 845 *p++ = readb (hp->Caddr+RIO_VPD_ROM + i*2); 846 /* read_rio_byte (hp, RIO_VPD_ROM + i*2); */ 847 848 /* Terminate the identifier string. 849 *** requires one extra byte in struct vpd_prom *** */ 850 *p++=0; 851 852 if (rio_debug & RIO_DEBUG_PROBE) 853 my_hd ((char *)&vpdp, 0x20); 854 855 func_exit(); 856 857 return &vpdp; 858} 859 860 861 862static int rio_init_drivers(void) 863{ 864 int error; 865 866 func_enter(); 867 868 memset(&rio_driver, 0, sizeof(rio_driver)); 869 rio_driver.magic = TTY_DRIVER_MAGIC; 870 rio_driver.driver_name = "specialix_rio"; 871 rio_driver.name = "ttySR"; 872 rio_driver.major = RIO_NORMAL_MAJOR0; 873 rio_driver.num = 256; 874 rio_driver.type = TTY_DRIVER_TYPE_SERIAL; 875 rio_driver.subtype = RIO_TYPE_NORMAL; 876 rio_driver.init_termios = tty_std_termios; 877 rio_driver.init_termios.c_cflag = 878 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 879 rio_driver.flags = TTY_DRIVER_REAL_RAW; 880 rio_driver.refcount = &rio_refcount; 881 rio_driver.table = rio_table; 882 rio_driver.termios = rio_termios; 883 rio_driver.termios_locked = rio_termios_locked; 884 885 rio_driver.open = riotopen; 886 rio_driver.close = gs_close; 887 rio_driver.write = gs_write; 888 rio_driver.put_char = gs_put_char; 889 rio_driver.flush_chars = gs_flush_chars; 890 rio_driver.write_room = gs_write_room; 891 rio_driver.chars_in_buffer = gs_chars_in_buffer; 892 rio_driver.flush_buffer = gs_flush_buffer; 893 rio_driver.ioctl = rio_ioctl; 894 rio_driver.throttle = rio_throttle; 895 rio_driver.unthrottle = rio_unthrottle; 896 rio_driver.set_termios = gs_set_termios; 897 rio_driver.stop = gs_stop; 898 rio_driver.start = gs_start; 899 rio_driver.hangup = gs_hangup; 900 901 rio_driver2 = rio_driver; 902 rio_driver.major = RIO_NORMAL_MAJOR1; 903 904 rio_callout_driver = rio_driver; 905 rio_callout_driver.name = "cusr"; 906 rio_callout_driver.major = RIO_CALLOUT_MAJOR0; 907 rio_callout_driver.subtype = RIO_TYPE_CALLOUT; 908 909 rio_callout_driver2 = rio_callout_driver; 910 rio_callout_driver2.major = RIO_CALLOUT_MAJOR1; 911 912 rio_dprintk (RIO_DEBUG_INIT, "set_termios = %p\n", gs_set_termios); 913 914 if ((error = tty_register_driver(&rio_driver))) goto bad1; 915 if ((error = tty_register_driver(&rio_driver2))) goto bad2; 916 if ((error = tty_register_driver(&rio_callout_driver))) goto bad3; 917 if ((error = tty_register_driver(&rio_callout_driver2))) goto bad4; 918 919 func_exit(); 920 return 0; 921 /* 922 bad5:tty_unregister_driver (&rio_callout_driver2); */ 923 bad4:tty_unregister_driver (&rio_callout_driver); 924 bad3:tty_unregister_driver (&rio_driver2); 925 bad2:tty_unregister_driver (&rio_driver); 926 bad1:printk(KERN_ERR "rio: Couldn't register a rio driver, error = %d\n", 927 error); 928 return 1; 929} 930 931 932static void * ckmalloc (int size) 933{ 934 void *p; 935 936 p = kmalloc(size, GFP_KERNEL); 937 if (p) 938 memset(p, 0, size); 939 return p; 940} 941 942 943 944static int rio_init_datastructures (void) 945{ 946 int i; 947 struct Port *port; 948 func_enter(); 949 950 /* Many drivers statically allocate the maximum number of ports 951 There is no reason not to allocate them dynamically. Is there? -- REW */ 952 /* However, the RIO driver allows users to configure their first 953 RTA as the ports numbered 504-511. We therefore need to allocate 954 the whole range. :-( -- REW */ 955 956#define RI_SZ sizeof(struct rio_info) 957#define HOST_SZ sizeof(struct Host) 958#define PORT_SZ sizeof(struct Port *) 959#define TMIO_SZ sizeof(struct termios *) 960 rio_dprintk (RIO_DEBUG_INIT, "getting : %d %d %d %d %d bytes\n", 961 RI_SZ, 962 RIO_HOSTS * HOST_SZ, 963 RIO_PORTS * PORT_SZ, 964 RIO_PORTS * TMIO_SZ, 965 RIO_PORTS * TMIO_SZ); 966 967 if (!(p = ckmalloc ( RI_SZ))) goto free0; 968 if (!(p->RIOHosts = ckmalloc (RIO_HOSTS * HOST_SZ))) goto free1; 969 if (!(p->RIOPortp = ckmalloc (RIO_PORTS * PORT_SZ))) goto free2; 970 if (!(rio_termios = ckmalloc (RIO_PORTS * TMIO_SZ))) goto free3; 971 if (!(rio_termios_locked = ckmalloc (RIO_PORTS * TMIO_SZ))) goto free4; 972 p->RIOConf = RIOConf; 973 rio_dprintk (RIO_DEBUG_INIT, "Got : %p %p %p %p %p\n", 974 p, p->RIOHosts, p->RIOPortp, rio_termios, rio_termios); 975 976 /* Adjust the values in the "driver" */ 977 rio_driver.termios = rio_termios; 978 rio_driver.termios_locked = rio_termios_locked; 979 980 for (i = 0; i < RIO_PORTS; i++) { 981 port = p->RIOPortp[i] = ckmalloc (sizeof (struct Port)); 982 if (!port) { 983 goto free6; 984 } 985 rio_dprintk (RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped); 986 port->PortNum = i; 987 port->gs.callout_termios = tty_std_termios; 988 port->gs.normal_termios = tty_std_termios; 989 port->gs.magic = RIO_MAGIC; 990 port->gs.close_delay = HZ/2; 991 port->gs.closing_wait = 30 * HZ; 992 port->gs.rd = &rio_real_driver; 993 port->portSem = SPIN_LOCK_UNLOCKED; 994 /* 995 * Initializing wait queue 996 */ 997 init_waitqueue_head(&port->gs.open_wait); 998 init_waitqueue_head(&port->gs.close_wait); 999 } 1000 1001 1002 1003 if (rio_debug & RIO_DEBUG_INIT) { 1004 my_hd (&rio_real_driver, sizeof (rio_real_driver)); 1005 } 1006 1007 1008 func_exit(); 1009 return 0; 1010 1011 free6:for (i--;i>=0;i--) 1012 kfree (p->RIOPortp[i]); 1013/*free5: */ 1014 kfree (rio_termios_locked); 1015 free4:kfree (rio_termios); 1016 free3:kfree (p->RIOPortp); 1017 free2:kfree (p->RIOHosts); 1018 free1: 1019 rio_dprintk (RIO_DEBUG_INIT, "Not enough memory! %p %p %p %p %p\n", 1020 p, p->RIOHosts, p->RIOPortp, rio_termios, rio_termios); 1021 kfree(p); 1022 free0: 1023 return -ENOMEM; 1024} 1025 1026static void __exit rio_release_drivers(void) 1027{ 1028 func_enter(); 1029 tty_unregister_driver (&rio_callout_driver2); 1030 tty_unregister_driver (&rio_callout_driver); 1031 tty_unregister_driver (&rio_driver2); 1032 tty_unregister_driver (&rio_driver); 1033 func_exit(); 1034} 1035 1036#ifdef TWO_ZERO 1037#define PDEV unsigned char pci_bus, unsigned pci_fun 1038#define pdev pci_bus, pci_fun 1039#else 1040#define PDEV struct pci_dev *pdev 1041#endif 1042 1043 1044#ifdef CONFIG_PCI 1045 /* This was written for SX, but applies to RIO too... 1046 (including bugs....) 1047 1048 There is another bit besides Bit 17. Turning that bit off 1049 (on boards shipped with the fix in the eeprom) results in a 1050 hang on the next access to the card. 1051 */ 1052 1053 /******************************************************** 1054 * Setting bit 17 in the CNTRL register of the PLX 9050 * 1055 * chip forces a retry on writes while a read is pending.* 1056 * This is to prevent the card locking up on Intel Xeon * 1057 * multiprocessor systems with the NX chipset. -- NV * 1058 ********************************************************/ 1059 1060/* Newer cards are produced with this bit set from the configuration 1061 EEprom. As the bit is read/write for the CPU, we can fix it here, 1062 if we detect that it isn't set correctly. -- REW */ 1063 1064void fix_rio_pci (PDEV) 1065{ 1066 unsigned int hwbase; 1067 unsigned long rebase; 1068 unsigned int t; 1069 1070#define CNTRL_REG_OFFSET 0x50 1071#define CNTRL_REG_GOODVALUE 0x18260000 1072 1073 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase); 1074 hwbase &= PCI_BASE_ADDRESS_MEM_MASK; 1075 rebase = (ulong) ioremap(hwbase, 0x80); 1076 t = readl (rebase + CNTRL_REG_OFFSET); 1077 if (t != CNTRL_REG_GOODVALUE) { 1078 printk (KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n", 1079 t, CNTRL_REG_GOODVALUE); 1080 writel (CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET); 1081 } 1082 my_iounmap (hwbase, rebase); 1083} 1084#endif 1085 1086 1087static int __init rio_init(void) 1088{ 1089 int found = 0; 1090 int i; 1091 struct Host *hp; 1092 int retval; 1093 struct vpd_prom *vpdp; 1094 int okboard; 1095 1096 1097#ifdef CONFIG_PCI 1098#ifndef TWO_ZERO 1099 struct pci_dev *pdev = NULL; 1100#else 1101 unsigned char pci_bus, pci_fun; 1102 /* in 2.2.x pdev is a pointer defining a PCI device. In 2.0 its the bus/fn */ 1103#endif 1104 unsigned int tint; 1105 unsigned short tshort; 1106#endif 1107 1108 func_enter(); 1109 rio_dprintk (RIO_DEBUG_INIT, "Initing rio module... (rio_debug=%d)\n", 1110 rio_debug); 1111 1112 if (abs ((long) (&rio_debug) - rio_debug) < 0x10000) { 1113 printk (KERN_WARNING "rio: rio_debug is an address, instead of a value. " 1114 "Assuming -1. Was %x/%p.\n", rio_debug, &rio_debug); 1115 rio_debug=-1; 1116 } 1117 1118 retval = rio_init_datastructures (); 1119 if (retval < 0) return retval; 1120 1121#ifdef CONFIG_PCI 1122 if (pci_present ()) { 1123 /* First look for the JET devices: */ 1124#ifndef TWO_ZERO 1125 while ((pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX, 1126 PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, 1127 pdev))) { 1128 if (pci_enable_device(pdev)) continue; 1129#else 1130 for (i=0;i< RIO_NBOARDS;i++) { 1131 if (pcibios_find_device (PCI_VENDOR_ID_SPECIALIX, 1132 PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, i, 1133 &pci_bus, &pci_fun)) break; 1134#endif 1135 /* Specialix has a whole bunch of cards with 1136 0x2000 as the device ID. They say its because 1137 the standard requires it. Stupid standard. */ 1138 /* It seems that reading a word doesn't work reliably on 2.0. 1139 Also, reading a non-aligned dword doesn't work. So we read the 1140 whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID) 1141 ourselves */ 1142 /* I don't know why the define doesn't work, constant 0x2c does --REW */ 1143 pci_read_config_dword (pdev, 0x2c, &tint); 1144 tshort = (tint >> 16) & 0xffff; 1145 rio_dprintk (RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint); 1146 if (tshort != 0x0100) { 1147 rio_dprintk (RIO_DEBUG_PROBE, "But it's not a RIO card (%d)...\n", 1148 tshort); 1149 continue; 1150 } 1151 rio_dprintk (RIO_DEBUG_PROBE, "cp1\n"); 1152 1153 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_2, &tint); 1154 1155 hp = &p->RIOHosts[p->RIONumHosts]; 1156 hp->PaddrP = tint & PCI_BASE_ADDRESS_MEM_MASK; 1157 hp->Ivec = get_irq (pdev); 1158 if (((1 << hp->Ivec) & rio_irqmask) == 0) 1159 hp->Ivec = 0; 1160 hp->CardP = (struct DpRam *) 1161 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN); 1162 hp->Type = RIO_PCI; 1163 hp->Copy = rio_pcicopy; 1164 hp->Mode = RIO_PCI_BOOT_FROM_RAM; 1165 hp->HostLock = SPIN_LOCK_UNLOCKED; 1166 rio_reset_interrupt (hp); 1167 rio_start_card_running (hp); 1168 1169 rio_dprintk (RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", 1170 (void *)p->RIOHosts[p->RIONumHosts].PaddrP, 1171 p->RIOHosts[p->RIONumHosts].Caddr); 1172 if (RIOBoardTest( p->RIOHosts[p->RIONumHosts].PaddrP, 1173 p->RIOHosts[p->RIONumHosts].Caddr, 1174 RIO_PCI, 0 ) == RIO_SUCCESS) { 1175 rio_dprintk (RIO_DEBUG_INIT, "Done RIOBoardTest\n"); 1176 WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff); 1177 p->RIOHosts[p->RIONumHosts].UniqueNum = 1178 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) &0xFF)<< 0)| 1179 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) &0xFF)<< 8)| 1180 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) &0xFF)<<16)| 1181 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) &0xFF)<<24); 1182 rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", 1183 p->RIOHosts[p->RIONumHosts].UniqueNum); 1184 1185 fix_rio_pci (pdev); 1186 p->RIOLastPCISearch = RIO_SUCCESS; 1187 p->RIONumHosts++; 1188 found++; 1189 } else { 1190 my_iounmap (p->RIOHosts[p->RIONumHosts].PaddrP, 1191 p->RIOHosts[p->RIONumHosts].Caddr); 1192 } 1193 1194#ifdef TWO_ZERO 1195 } /* We have two variants with the opening brace, so to prevent */ 1196#else 1197 } /* Emacs from getting confused we have two closing braces too. */ 1198#endif 1199 1200 /* Then look for the older PCI card.... : */ 1201#ifndef TWO_ZERO 1202 1203 1204 /* These older PCI cards have problems (only byte-mode access is 1205 supported), which makes them a bit awkward to support. 1206 They also have problems sharing interrupts. Be careful. 1207 (The driver now refuses to share interrupts for these 1208 cards. This should be sufficient). 1209 */ 1210 1211 /* Then look for the older RIO/PCI devices: */ 1212 while ((pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX, 1213 PCI_DEVICE_ID_SPECIALIX_RIO, 1214 pdev))) { 1215 if (pci_enable_device(pdev)) continue; 1216#else 1217 for (i=0;i< RIO_NBOARDS;i++) { 1218 if (pcibios_find_device (PCI_VENDOR_ID_SPECIALIX, 1219 PCI_DEVICE_ID_SPECIALIX_RIO, i, 1220 &pci_bus, &pci_fun)) break; 1221#endif 1222 1223#ifdef CONFIG_RIO_OLDPCI 1224 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &tint); 1225 1226 hp = &p->RIOHosts[p->RIONumHosts]; 1227 hp->PaddrP = tint & PCI_BASE_ADDRESS_MEM_MASK; 1228 hp->Ivec = get_irq (pdev); 1229 if (((1 << hp->Ivec) & rio_irqmask) == 0) 1230 hp->Ivec = 0; 1231 hp->Ivec |= 0x8000; /* Mark as non-sharable */ 1232 hp->CardP = (struct DpRam *) 1233 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN); 1234 hp->Type = RIO_PCI; 1235 hp->Copy = rio_pcicopy; 1236 hp->Mode = RIO_PCI_BOOT_FROM_RAM; 1237 hp->HostLock = SPIN_LOCK_UNLOCKED; 1238 1239 rio_dprintk (RIO_DEBUG_PROBE, "Ivec: %x\n", hp->Ivec); 1240 rio_dprintk (RIO_DEBUG_PROBE, "Mode: %x\n", hp->Mode); 1241 1242 rio_reset_interrupt (hp); 1243 rio_start_card_running (hp); 1244 rio_dprintk (RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", 1245 (void *)p->RIOHosts[p->RIONumHosts].PaddrP, 1246 p->RIOHosts[p->RIONumHosts].Caddr); 1247 if (RIOBoardTest( p->RIOHosts[p->RIONumHosts].PaddrP, 1248 p->RIOHosts[p->RIONumHosts].Caddr, 1249 RIO_PCI, 0 ) == RIO_SUCCESS) { 1250 WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff); 1251 p->RIOHosts[p->RIONumHosts].UniqueNum = 1252 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) &0xFF)<< 0)| 1253 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) &0xFF)<< 8)| 1254 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) &0xFF)<<16)| 1255 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) &0xFF)<<24); 1256 rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", 1257 p->RIOHosts[p->RIONumHosts].UniqueNum); 1258 1259 p->RIOLastPCISearch = RIO_SUCCESS; 1260 p->RIONumHosts++; 1261 found++; 1262 } else { 1263 my_iounmap (p->RIOHosts[p->RIONumHosts].PaddrP, 1264 p->RIOHosts[p->RIONumHosts].Caddr); 1265 } 1266#else 1267 printk (KERN_ERR "Found an older RIO PCI card, but the driver is not " 1268 "compiled to support it.\n"); 1269#endif 1270#ifdef TWO_ZERO 1271 } /* We have two variants with the opening brace, so to prevent */ 1272#else 1273 } /* Emacs from getting confused we have two closing braces too. */ 1274#endif 1275 } 1276#endif /* PCI */ 1277 1278 /* Now probe for ISA cards... */ 1279 for (i=0;i<NR_RIO_ADDRS;i++) { 1280 hp = &p->RIOHosts[p->RIONumHosts]; 1281 hp->PaddrP = rio_probe_addrs[i]; 1282 /* There was something about the IRQs of these cards. 'Forget what.--REW */ 1283 hp->Ivec = 0; 1284 hp->CardP = (struct DpRam *) 1285 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN); 1286 hp->Type = RIO_AT; 1287 hp->Copy = rio_pcicopy; /* AT card PCI???? - PVDL 1288 * -- YES! this is now a normal copy. Only the 1289 * old PCI card uses the special PCI copy. 1290 * Moreover, the ISA card will work with the 1291 * special PCI copy anyway. -- REW */ 1292 hp->Mode = 0; 1293 hp->HostLock = SPIN_LOCK_UNLOCKED; 1294 1295 vpdp = get_VPD_PROM (hp); 1296 rio_dprintk (RIO_DEBUG_PROBE, "Got VPD ROM\n"); 1297 okboard = 0; 1298 if ((strncmp (vpdp->identifier, RIO_ISA_IDENT, 16) == 0) || 1299 (strncmp (vpdp->identifier, RIO_ISA2_IDENT, 16) == 0) || 1300 (strncmp (vpdp->identifier, RIO_ISA3_IDENT, 16) == 0)) { 1301 /* Board is present... */ 1302 if (RIOBoardTest (hp->PaddrP, 1303 hp->Caddr, RIO_AT, 0) == RIO_SUCCESS) { 1304 /* ... and feeling fine!!!! */ 1305 rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", 1306 p->RIOHosts[p->RIONumHosts].UniqueNum); 1307 if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) { 1308 rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, host%d uniqid = %x.\n", 1309 p->RIONumHosts, 1310 p->RIOHosts[p->RIONumHosts-1].UniqueNum); 1311 okboard++; 1312 found++; 1313 } 1314 } 1315 1316 if (!okboard) 1317 my_iounmap (hp->PaddrP, hp->Caddr); 1318 } 1319 } 1320 1321 1322 for (i=0;i<p->RIONumHosts;i++) { 1323 hp = &p->RIOHosts[i]; 1324 if (hp->Ivec) { 1325 int mode = SA_SHIRQ; 1326 if (hp->Ivec & 0x8000) {mode = 0; hp->Ivec &= 0x7fff;} 1327 rio_dprintk (RIO_DEBUG_INIT, "Requesting interrupt hp: %p rio_interrupt: %d Mode: %x\n", hp,hp->Ivec, hp->Mode); 1328 retval = request_irq (hp->Ivec, rio_interrupt, mode, "rio", hp); 1329 rio_dprintk (RIO_DEBUG_INIT, "Return value from request_irq: %d\n", retval); 1330 if (retval) { 1331 printk(KERN_ERR "rio: Cannot allocate irq %d.\n", hp->Ivec); 1332 hp->Ivec = 0; 1333 } 1334 rio_dprintk (RIO_DEBUG_INIT, "Got irq %d.\n", hp->Ivec); 1335 if (hp->Ivec != 0){ 1336 rio_dprintk (RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n"); 1337 hp->Mode |= RIO_PCI_INT_ENABLE; 1338 } else 1339 hp->Mode &= !RIO_PCI_INT_ENABLE; 1340 rio_dprintk (RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode); 1341 rio_start_card_running (hp); 1342 } 1343 /* Init the timer "always" to make sure that it can safely be 1344 deleted when we unload... */ 1345 1346 init_timer (&hp->timer); 1347 if (!hp->Ivec) { 1348 rio_dprintk (RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n", 1349 rio_poll); 1350 hp->timer.data = i; 1351 hp->timer.function = rio_pollfunc; 1352 hp->timer.expires = jiffies + rio_poll; 1353 add_timer (&hp->timer); 1354 } 1355 } 1356 1357 if (found) { 1358 rio_dprintk (RIO_DEBUG_INIT, "rio: total of %d boards detected.\n", found); 1359 1360 if (misc_register(&rio_fw_device) < 0) { 1361 printk(KERN_ERR "RIO: Unable to register firmware loader driver.\n"); 1362 return -EIO; 1363 } 1364 rio_init_drivers (); 1365 } 1366 1367 func_exit(); 1368 return found?0:-EIO; 1369} 1370 1371 1372static void __exit rio_exit (void) 1373{ 1374 int i; 1375 struct Host *hp; 1376 1377 func_enter(); 1378 1379 for (i=0,hp=p->RIOHosts;i<p->RIONumHosts;i++, hp++) { 1380 RIOHostReset (hp->Type, hp->CardP, hp->Slot); 1381 if (hp->Ivec) { 1382 free_irq (hp->Ivec, hp); 1383 rio_dprintk (RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec); 1384 } 1385 /* It is safe/allowed to del_timer a non-active timer */ 1386 del_timer (&hp->timer); 1387 } 1388 1389 if (misc_deregister(&rio_fw_device) < 0) { 1390 printk (KERN_INFO "rio: couldn't deregister control-device\n"); 1391 } 1392 1393 1394 rio_dprintk (RIO_DEBUG_CLEANUP, "Cleaning up drivers\n"); 1395 1396 rio_release_drivers (); 1397 1398 /* Release dynamically allocated memory */ 1399 kfree (rio_termios_locked); 1400 kfree (rio_termios); 1401 kfree (p->RIOPortp); 1402 kfree (p->RIOHosts); 1403 kfree (p); 1404 1405 func_exit(); 1406} 1407 1408module_init(rio_init); 1409module_exit(rio_exit); 1410 1411/* 1412 * Anybody who knows why this doesn't work for me, please tell me -- REW. 1413 * Snatched from scsi.c (fixed one spelling error): 1414 * Overrides for Emacs so that we follow Linus' tabbing style. 1415 * Emacs will notice this stuff at the end of the file and automatically 1416 * adjust the settings for this buffer only. This must remain at the end 1417 * of the file. 1418 * --------------------------------------------------------------------------- 1419 * Local Variables: 1420 * c-indent-level: 4 1421 * c-brace-imaginary-offset: 0 1422 * c-brace-offset: -4 1423 * c-argdecl-indent: 4 1424 * c-label-offset: -4 1425 * c-continued-statement-offset: 4 1426 * c-continued-brace-offset: 0 1427 * indent-tabs-mode: nil 1428 * tab-width: 8 1429 * End: 1430 */ 1431