|
|
1.1 ! root 1: /* ! 2: * eata.c - Low-level driver for EATA/DMA SCSI host adapters. ! 3: * ! 4: * 26 Jul 1998 Rev. 4.33 for linux 2.0.35 and 2.1.111 ! 5: * + Added command line option (rs:[y|n]) to reverse the scan order ! 6: * of PCI boards. The default is rs:y, which reverses the BIOS order ! 7: * while registering PCI boards. The default value rs:y generates ! 8: * the same order of all previous revisions of this driver. ! 9: * Pls. note that "BIOS order" might have been reversed itself ! 10: * after the 2.1.9x PCI modifications in the linux kernel. ! 11: * The rs value is ignored when the explicit list of addresses ! 12: * is used by the "eata=port0,port1,..." command line option. ! 13: * + Added command line option (et:[y|n]) to force use of extended ! 14: * translation (255 heads, 63 sectors) as disk geometry. ! 15: * The default is et:n, which uses the disk geometry returned ! 16: * by scsicam_bios_param. The default value et:n is compatible with ! 17: * all previous revisions of this driver. ! 18: * ! 19: * 28 May 1998 Rev. 4.32 for linux 2.0.33 and 2.1.104 ! 20: * Increased busy timeout from 10 msec. to 200 msec. while ! 21: * processing interrupts. ! 22: * ! 23: * 16 May 1998 Rev. 4.31 for linux 2.0.33 and 2.1.102 ! 24: * Improved abort handling during the eh recovery process. ! 25: * ! 26: * 13 May 1998 Rev. 4.30 for linux 2.0.33 and 2.1.101 ! 27: * The driver is now fully SMP safe, including the ! 28: * abort and reset routines. ! 29: * Added command line options (eh:[y|n]) to choose between ! 30: * new_eh_code and the old scsi code. ! 31: * If linux version >= 2.1.101 the default is eh:y, while the eh ! 32: * option is ignored for previous releases and the old scsi code ! 33: * is used. ! 34: * ! 35: * 18 Apr 1998 Rev. 4.20 for linux 2.0.33 and 2.1.97 ! 36: * Reworked interrupt handler. ! 37: * ! 38: * 11 Apr 1998 rev. 4.05 for linux 2.0.33 and 2.1.95 ! 39: * Major reliability improvement: when a batch with overlapping ! 40: * requests is detected, requests are queued one at a time ! 41: * eliminating any possible board or drive reordering. ! 42: * ! 43: * 10 Apr 1998 rev. 4.04 for linux 2.0.33 and 2.1.95 ! 44: * Improved SMP support (if linux version >= 2.1.95). ! 45: * ! 46: * 9 Apr 1998 rev. 4.03 for linux 2.0.33 and 2.1.94 ! 47: * Added support for new PCI code and IO-APIC remapping of irqs. ! 48: * Performance improvement: when sequential i/o is detected, ! 49: * always use direct sort instead of reverse sort. ! 50: * ! 51: * 4 Apr 1998 rev. 4.02 for linux 2.0.33 and 2.1.92 ! 52: * io_port is now unsigned long. ! 53: * ! 54: * 17 Mar 1998 rev. 4.01 for linux 2.0.33 and 2.1.88 ! 55: * Use new scsi error handling code (if linux version >= 2.1.88). ! 56: * Use new interrupt code. ! 57: * ! 58: * 12 Sep 1997 rev. 3.11 for linux 2.0.30 and 2.1.55 ! 59: * Use of udelay inside the wait loops to avoid timeout ! 60: * problems with fast cpus. ! 61: * Removed check about useless calls to the interrupt service ! 62: * routine (reported on SMP systems only). ! 63: * At initialization time "sorted/unsorted" is displayed instead ! 64: * of "linked/unlinked" to reinforce the fact that "linking" is ! 65: * nothing but "elevator sorting" in the actual implementation. ! 66: * ! 67: * 17 May 1997 rev. 3.10 for linux 2.0.30 and 2.1.38 ! 68: * Use of serial_number_at_timeout in abort and reset processing. ! 69: * Use of the __initfunc and __initdata macro in setup code. ! 70: * Minor cleanups in the list_statistics code. ! 71: * Increased controller busy timeout in order to better support ! 72: * slow SCSI devices. ! 73: * ! 74: * 24 Feb 1997 rev. 3.00 for linux 2.0.29 and 2.1.26 ! 75: * When loading as a module, parameter passing is now supported ! 76: * both in 2.0 and in 2.1 style. ! 77: * Fixed data transfer direction for some SCSI opcodes. ! 78: * Immediate acknowledge to request sense commands. ! 79: * Linked commands to each disk device are now reordered by elevator ! 80: * sorting. Rare cases in which reordering of write requests could ! 81: * cause wrong results are managed. ! 82: * Fixed spurious timeouts caused by long simple queue tag sequences. ! 83: * New command line option (tm:[0-3]) to choose the type of tags: ! 84: * 0 -> mixed (default); 1 -> simple; 2 -> head; 3 -> ordered. ! 85: * ! 86: * 18 Jan 1997 rev. 2.60 for linux 2.1.21 and 2.0.28 ! 87: * Added command line options to enable/disable linked commands ! 88: * (lc:[y|n]), tagged commands (tc:[y|n]) and to set the max queue ! 89: * depth (mq:xx). Default is "eata=lc:n,tc:n,mq:16". ! 90: * Improved command linking. ! 91: * Documented how to setup RAID-0 with DPT SmartRAID boards. ! 92: * ! 93: * 8 Jan 1997 rev. 2.50 for linux 2.1.20 and 2.0.27 ! 94: * Added linked command support. ! 95: * Improved detection of PCI boards using ISA base addresses. ! 96: * ! 97: * 3 Dec 1996 rev. 2.40 for linux 2.1.14 and 2.0.27 ! 98: * Added support for tagged commands and queue depth adjustment. ! 99: * ! 100: * 22 Nov 1996 rev. 2.30 for linux 2.1.12 and 2.0.26 ! 101: * When CONFIG_PCI is defined, BIOS32 is used to include in the ! 102: * list of i/o ports to be probed all the PCI SCSI controllers. ! 103: * The list of i/o ports to be probed can be overwritten by the ! 104: * "eata=port0,port1,...." boot command line option. ! 105: * Scatter/gather lists are now allocated by a number of kmalloc ! 106: * calls, in order to avoid the previous size limit of 64Kb. ! 107: * ! 108: * 16 Nov 1996 rev. 2.20 for linux 2.1.10 and 2.0.25 ! 109: * Added support for EATA 2.0C, PCI, multichannel and wide SCSI. ! 110: * ! 111: * 27 Sep 1996 rev. 2.12 for linux 2.1.0 ! 112: * Portability cleanups (virtual/bus addressing, little/big endian ! 113: * support). ! 114: * ! 115: * 09 Jul 1996 rev. 2.11 for linux 2.0.4 ! 116: * Number of internal retries is now limited. ! 117: * ! 118: * 16 Apr 1996 rev. 2.10 for linux 1.3.90 ! 119: * New argument "reset_flags" to the reset routine. ! 120: * ! 121: * 6 Jul 1995 rev. 2.01 for linux 1.3.7 ! 122: * Update required by the new /proc/scsi support. ! 123: * ! 124: * 11 Mar 1995 rev. 2.00 for linux 1.2.0 ! 125: * Fixed a bug which prevented media change detection for removable ! 126: * disk drives. ! 127: * ! 128: * 23 Feb 1995 rev. 1.18 for linux 1.1.94 ! 129: * Added a check for scsi_register returning NULL. ! 130: * ! 131: * 11 Feb 1995 rev. 1.17 for linux 1.1.91 ! 132: * Now DEBUG_RESET is disabled by default. ! 133: * Register a board even if it does not assert DMA protocol support ! 134: * (DPT SK2011B does not report correctly the dmasup bit). ! 135: * ! 136: * 9 Feb 1995 rev. 1.16 for linux 1.1.90 ! 137: * Use host->wish_block instead of host->block. ! 138: * New list of Data Out SCSI commands. ! 139: * ! 140: * 8 Feb 1995 rev. 1.15 for linux 1.1.89 ! 141: * Cleared target_time_out counter while performing a reset. ! 142: * All external symbols renamed to avoid possible name conflicts. ! 143: * ! 144: * 28 Jan 1995 rev. 1.14 for linux 1.1.86 ! 145: * Added module support. ! 146: * Log and do a retry when a disk drive returns a target status ! 147: * different from zero on a recovered error. ! 148: * ! 149: * 24 Jan 1995 rev. 1.13 for linux 1.1.85 ! 150: * Use optimized board configuration, with a measured performance ! 151: * increase in the range 10%-20% on i/o throughput. ! 152: * ! 153: * 16 Jan 1995 rev. 1.12 for linux 1.1.81 ! 154: * Fix mscp structure comments (no functional change). ! 155: * Display a message if check_region detects a port address ! 156: * already in use. ! 157: * ! 158: * 17 Dec 1994 rev. 1.11 for linux 1.1.74 ! 159: * Use the scsicam_bios_param routine. This allows an easy ! 160: * migration path from disk partition tables created using ! 161: * different SCSI drivers and non optimal disk geometry. ! 162: * ! 163: * 15 Dec 1994 rev. 1.10 for linux 1.1.74 ! 164: * Added support for ISA EATA boards (DPT PM2011, DPT PM2021). ! 165: * The host->block flag is set for all the detected ISA boards. ! 166: * The detect routine no longer enforces LEVEL triggering ! 167: * for EISA boards, it just prints a warning message. ! 168: * ! 169: * 30 Nov 1994 rev. 1.09 for linux 1.1.68 ! 170: * Redo i/o on target status CHECK_CONDITION for TYPE_DISK only. ! 171: * Added optional support for using a single board at a time. ! 172: * ! 173: * 18 Nov 1994 rev. 1.08 for linux 1.1.64 ! 174: * Forces sg_tablesize = 64 and can_queue = 64 if these ! 175: * values are not correctly detected (DPT PM2012). ! 176: * ! 177: * 14 Nov 1994 rev. 1.07 for linux 1.1.63 Final BETA release. ! 178: * 04 Aug 1994 rev. 1.00 for linux 1.1.39 First BETA release. ! 179: * ! 180: * ! 181: * This driver is based on the CAM (Common Access Method Committee) ! 182: * EATA (Enhanced AT Bus Attachment) rev. 2.0A, using DMA protocol. ! 183: * ! 184: * Copyright (C) 1994-1998 Dario Ballabio ([email protected]) ! 185: * ! 186: * Redistribution and use in source and binary forms, with or without ! 187: * modification, are permitted provided that redistributions of source ! 188: * code retain the above copyright notice and this comment without ! 189: * modification. ! 190: * ! 191: */ ! 192: ! 193: /* ! 194: * ! 195: * Here is a brief description of the DPT SCSI host adapters. ! 196: * All these boards provide an EATA/DMA compatible programming interface ! 197: * and are fully supported by this driver in any configuration, including ! 198: * multiple SCSI channels: ! 199: * ! 200: * PM2011B/9X - Entry Level ISA ! 201: * PM2021A/9X - High Performance ISA ! 202: * PM2012A Old EISA ! 203: * PM2012B Old EISA ! 204: * PM2022A/9X - Entry Level EISA ! 205: * PM2122A/9X - High Performance EISA ! 206: * PM2322A/9X - Extra High Performance EISA ! 207: * PM3021 - SmartRAID Adapter for ISA ! 208: * PM3222 - SmartRAID Adapter for EISA (PM3222W is 16-bit wide SCSI) ! 209: * PM3224 - SmartRAID Adapter for PCI (PM3224W is 16-bit wide SCSI) ! 210: * ! 211: * The above list is just an indication: as a matter of fact all DPT ! 212: * boards using the EATA/DMA protocol are supported by this driver, ! 213: * since they use exactely the same programming interface. ! 214: * ! 215: * The DPT PM2001 provides only the EATA/PIO interface and hence is not ! 216: * supported by this driver. ! 217: * ! 218: * This code has been tested with up to 3 Distributed Processing Technology ! 219: * PM2122A/9X (DPT SCSI BIOS v002.D1, firmware v05E.0) EISA controllers, ! 220: * in any combination of private and shared IRQ. ! 221: * PCI support has been tested using up to 2 DPT PM3224W (DPT SCSI BIOS ! 222: * v003.D0, firmware v07G.0). ! 223: * ! 224: * DPT SmartRAID boards support "Hardware Array" - a group of disk drives ! 225: * which are all members of the same RAID-0, RAID-1 or RAID-5 array implemented ! 226: * in host adapter hardware. Hardware Arrays are fully compatible with this ! 227: * driver, since they look to it as a single disk drive. ! 228: * ! 229: * WARNING: to create a RAID-0 "Hardware Array" you must select "Other Unix" ! 230: * as the current OS in the DPTMGR "Initial System Installation" menu. ! 231: * Otherwise RAID-0 is generated as an "Array Group" (i.e. software RAID-0), ! 232: * which is not supported by the actual SCSI subsystem. ! 233: * To get the "Array Group" functionality, the Linux MD driver must be used ! 234: * instead of the DPT "Array Group" feature. ! 235: * ! 236: * Multiple ISA, EISA and PCI boards can be configured in the same system. ! 237: * It is suggested to put all the EISA boards on the same IRQ level, all ! 238: * the PCI boards on another IRQ level, while ISA boards cannot share ! 239: * interrupts. ! 240: * ! 241: * If you configure multiple boards on the same IRQ, the interrupt must ! 242: * be _level_ triggered (not _edge_ triggered). ! 243: * ! 244: * This driver detects EATA boards by probes at fixed port addresses, ! 245: * so no BIOS32 or PCI BIOS support is required. ! 246: * The suggested way to detect a generic EATA PCI board is to force on it ! 247: * any unused EISA address, even if there are other controllers on the EISA ! 248: * bus, or even if you system has no EISA bus at all. ! 249: * Do not force any ISA address on EATA PCI boards. ! 250: * ! 251: * If PCI bios support is configured into the kernel, BIOS32 is used to ! 252: * include in the list of i/o ports to be probed all the PCI SCSI controllers. ! 253: * ! 254: * Due to a DPT BIOS "feature", it might not be possible to force an EISA ! 255: * address on more then a single DPT PCI board, so in this case you have to ! 256: * let the PCI BIOS assign the addresses. ! 257: * ! 258: * The sequence of detection probes is: ! 259: * ! 260: * - ISA 0x1F0; ! 261: * - PCI SCSI controllers (only if BIOS32 is available); ! 262: * - EISA/PCI 0x1C88 through 0xFC88 (corresponding to EISA slots 1 to 15); ! 263: * - ISA 0x170, 0x230, 0x330. ! 264: * ! 265: * The above list of detection probes can be totally replaced by the ! 266: * boot command line option: "eata=port0,port1,port2,...", where the ! 267: * port0, port1... arguments are ISA/EISA/PCI addresses to be probed. ! 268: * For example using "eata=0x7410,0x7450,0x230", the driver probes ! 269: * only the two PCI addresses 0x7410 and 0x7450 and the ISA address 0x230, ! 270: * in this order; "eata=0" totally disables this driver. ! 271: * ! 272: * After the optional list of detection probes, other possible command line ! 273: * options are: ! 274: * ! 275: * eh:y use new scsi code (linux 2.2 only); ! 276: * eh:n use old scsi code; ! 277: * et:y force use of extended translation (255 heads, 63 sectors); ! 278: * et:n use disk geometry detected by scsicam_bios_param; ! 279: * rs:y reverse scan order while detecting PCI boards; ! 280: * rs:n use BIOS order while detecting PCI boards; ! 281: * lc:y enables linked commands; ! 282: * lc:n disables linked commands; ! 283: * tc:y enables tagged commands; ! 284: * tc:n disables tagged commands; ! 285: * tm:0 use head/simple/ordered queue tag sequences; ! 286: * tm:1 use only simple queue tags; ! 287: * tm:2 use only head of queue tags; ! 288: * tm:3 use only ordered queue tags; ! 289: * mq:xx set the max queue depth to the value xx (2 <= xx <= 32). ! 290: * ! 291: * The default value is: "eata=lc:n,tc:n,mq:16,tm:0,et:n,rs:n". ! 292: * An example using the list of detection probes could be: ! 293: * "eata=0x7410,0x230,lc:y,tc:n,mq:4,eh:n,et:n". ! 294: * ! 295: * When loading as a module, parameters can be specified as well. ! 296: * The above example would be (use 1 in place of y and 0 in place of n): ! 297: * ! 298: * modprobe eata io_port=0x7410,0x230 linked_comm=1 tagged_comm=0 \ ! 299: * max_queue_depth=4 tag_mode=0 use_new_eh_code=0 \ ! 300: * ext_tran=0 rev_scan=1 ! 301: * ! 302: * ---------------------------------------------------------------------------- ! 303: * In this implementation, linked commands are designed to work with any DISK ! 304: * or CD-ROM, since this linking has only the intent of clustering (time-wise) ! 305: * and reordering by elevator sorting commands directed to each device, ! 306: * without any relation with the actual SCSI protocol between the controller ! 307: * and the device. ! 308: * If Q is the queue depth reported at boot time for each device (also named ! 309: * cmds/lun) and Q > 2, whenever there is already an active command to the ! 310: * device all other commands to the same device (up to Q-1) are kept waiting ! 311: * in the elevator sorting queue. When the active command completes, the ! 312: * commands in this queue are sorted by sector address. The sort is chosen ! 313: * between increasing or decreasing by minimizing the seek distance between ! 314: * the sector of the commands just completed and the sector of the first ! 315: * command in the list to be sorted. ! 316: * Trivial math assures that the unsorted average seek distance when doing ! 317: * random seeks over S sectors is S/3. ! 318: * When (Q-1) requests are uniformly distributed over S sectors, the average ! 319: * distance between two adjacent requests is S/((Q-1) + 1), so the sorted ! 320: * average seek distance for (Q-1) random requests over S sectors is S/Q. ! 321: * The elevator sorting hence divides the seek distance by a factor Q/3. ! 322: * The above pure geometric remarks are valid in all cases and the ! 323: * driver effectively reduces the seek distance by the predicted factor ! 324: * when there are Q concurrent read i/o operations on the device, but this ! 325: * does not necessarily results in a noticeable performance improvement: ! 326: * your mileage may vary.... ! 327: * ! 328: * Note: command reordering inside a batch of queued commands could cause ! 329: * wrong results only if there is at least one write request and the ! 330: * intersection (sector-wise) of all requests is not empty. ! 331: * When the driver detects a batch including overlapping requests ! 332: * (a really rare event) strict serial (pid) order is enforced. ! 333: * ---------------------------------------------------------------------------- ! 334: * The extended translation option (et:y) is useful when using large physical ! 335: * disks/arrays. It could also be useful when switching between Adaptec boards ! 336: * and DPT boards without reformatting the disk. ! 337: * When a boot disk is partitioned with extended translation, in order to ! 338: * be able to boot it with a DPT board is could be necessary to add to ! 339: * lilo.conf additional commands as in the following example: ! 340: * ! 341: * fix-table ! 342: * disk=/dev/sda bios=0x80 sectors=63 heads=128 cylindres=546 ! 343: * ! 344: * where the above geometry should be replaced with the one reported at ! 345: * power up by the DPT controller. ! 346: * ---------------------------------------------------------------------------- ! 347: * ! 348: * The boards are named EATA0, EATA1,... according to the detection order. ! 349: * ! 350: * In order to support multiple ISA boards in a reliable way, ! 351: * the driver sets host->wish_block = TRUE for all ISA boards. ! 352: */ ! 353: ! 354: #include <linux/version.h> ! 355: ! 356: #define LinuxVersionCode(v, p, s) (((v)<<16)+((p)<<8)+(s)) ! 357: #define MAX_INT_PARAM 10 ! 358: ! 359: #if defined(MODULE) ! 360: #include <linux/module.h> ! 361: ! 362: #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,26) ! 363: MODULE_PARM(io_port, "1-" __MODULE_STRING(MAX_INT_PARAM) "i"); ! 364: MODULE_PARM(linked_comm, "i"); ! 365: MODULE_PARM(tagged_comm, "i"); ! 366: MODULE_PARM(link_statistics, "i"); ! 367: MODULE_PARM(max_queue_depth, "i"); ! 368: MODULE_PARM(tag_mode, "i"); ! 369: MODULE_PARM(use_new_eh_code, "i"); ! 370: MODULE_PARM(ext_tran, "i"); ! 371: MODULE_PARM(rev_scan, "i"); ! 372: MODULE_AUTHOR("Dario Ballabio"); ! 373: #endif ! 374: ! 375: #endif ! 376: ! 377: #include <linux/string.h> ! 378: #include <linux/sched.h> ! 379: #include <linux/kernel.h> ! 380: #include <linux/ioport.h> ! 381: #include <linux/delay.h> ! 382: #include <asm/io.h> ! 383: #include <asm/system.h> ! 384: #include <asm/byteorder.h> ! 385: #include <linux/proc_fs.h> ! 386: #include <linux/blk.h> ! 387: #include "scsi.h" ! 388: #include "hosts.h" ! 389: #include "sd.h" ! 390: #include <asm/dma.h> ! 391: #include <asm/irq.h> ! 392: #include "eata.h" ! 393: #include <linux/stat.h> ! 394: #include <linux/config.h> ! 395: #include <linux/pci.h> ! 396: ! 397: #if LINUX_VERSION_CODE < LinuxVersionCode(2,1,93) ! 398: #include <linux/bios32.h> ! 399: #endif ! 400: ! 401: #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,36) ! 402: #include <linux/init.h> ! 403: #else ! 404: #define __initfunc(A) A ! 405: #define __initdata ! 406: #define __init ! 407: #endif ! 408: ! 409: #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,101) ! 410: #include <asm/spinlock.h> ! 411: #define IRQ_FLAGS ! 412: #define IRQ_LOCK ! 413: #define IRQ_LOCK_SAVE ! 414: #define IRQ_UNLOCK ! 415: #define IRQ_UNLOCK_RESTORE ! 416: #define SPIN_FLAGS unsigned long spin_flags; ! 417: #define SPIN_LOCK spin_lock_irq(&io_request_lock); ! 418: #define SPIN_LOCK_SAVE spin_lock_irqsave(&io_request_lock, spin_flags); ! 419: #define SPIN_UNLOCK spin_unlock_irq(&io_request_lock); ! 420: #define SPIN_UNLOCK_RESTORE \ ! 421: spin_unlock_irqrestore(&io_request_lock, spin_flags); ! 422: static int use_new_eh_code = TRUE; ! 423: #else ! 424: #define IRQ_FLAGS unsigned long irq_flags; ! 425: #define IRQ_LOCK cli(); ! 426: #define IRQ_LOCK_SAVE do {save_flags(irq_flags); cli();} while (0); ! 427: #define IRQ_UNLOCK sti(); ! 428: #define IRQ_UNLOCK_RESTORE do {restore_flags(irq_flags);} while (0); ! 429: #define SPIN_FLAGS ! 430: #define SPIN_LOCK ! 431: #define SPIN_LOCK_SAVE ! 432: #define SPIN_UNLOCK ! 433: #define SPIN_UNLOCK_RESTORE ! 434: static int use_new_eh_code = FALSE; ! 435: #endif ! 436: ! 437: struct proc_dir_entry proc_scsi_eata2x = { ! 438: PROC_SCSI_EATA2X, 6, "eata2x", ! 439: S_IFDIR | S_IRUGO | S_IXUGO, 2 ! 440: }; ! 441: ! 442: /* Subversion values */ ! 443: #define ISA 0 ! 444: #define ESA 1 ! 445: ! 446: #undef FORCE_CONFIG ! 447: ! 448: #undef DEBUG_LINKED_COMMANDS ! 449: #undef DEBUG_DETECT ! 450: #undef DEBUG_PCI_DETECT ! 451: #undef DEBUG_INTERRUPT ! 452: #undef DEBUG_RESET ! 453: #undef DEBUG_GENERATE_ERRORS ! 454: #undef DEBUG_GENERATE_ABORTS ! 455: #undef DEBUG_GEOMETRY ! 456: ! 457: #define MAX_ISA 4 ! 458: #define MAX_VESA 0 ! 459: #define MAX_EISA 15 ! 460: #define MAX_PCI 16 ! 461: #define MAX_BOARDS (MAX_ISA + MAX_VESA + MAX_EISA + MAX_PCI) ! 462: #define MAX_CHANNEL 4 ! 463: #define MAX_LUN 32 ! 464: #define MAX_TARGET 32 ! 465: #define MAX_MAILBOXES 64 ! 466: #define MAX_SGLIST 64 ! 467: #define MAX_LARGE_SGLIST 122 ! 468: #define MAX_INTERNAL_RETRIES 64 ! 469: #define MAX_CMD_PER_LUN 2 ! 470: #define MAX_TAGGED_CMD_PER_LUN (MAX_MAILBOXES - MAX_CMD_PER_LUN) ! 471: ! 472: #define SKIP ULONG_MAX ! 473: #define FALSE 0 ! 474: #define TRUE 1 ! 475: #define FREE 0 ! 476: #define IN_USE 1 ! 477: #define LOCKED 2 ! 478: #define IN_RESET 3 ! 479: #define IGNORE 4 ! 480: #define READY 5 ! 481: #define ABORTING 6 ! 482: #define NO_DMA 0xff ! 483: #define MAXLOOP 10000 ! 484: #define TAG_MIXED 0 ! 485: #define TAG_SIMPLE 1 ! 486: #define TAG_HEAD 2 ! 487: #define TAG_ORDERED 3 ! 488: ! 489: #define REG_CMD 7 ! 490: #define REG_STATUS 7 ! 491: #define REG_AUX_STATUS 8 ! 492: #define REG_DATA 0 ! 493: #define REG_DATA2 1 ! 494: #define REG_SEE 6 ! 495: #define REG_LOW 2 ! 496: #define REG_LM 3 ! 497: #define REG_MID 4 ! 498: #define REG_MSB 5 ! 499: #define REGION_SIZE 9 ! 500: #define MAX_ISA_ADDR 0x03ff ! 501: #define MIN_EISA_ADDR 0x1c88 ! 502: #define MAX_EISA_ADDR 0xfc88 ! 503: #define BSY_ASSERTED 0x80 ! 504: #define DRQ_ASSERTED 0x08 ! 505: #define ABSY_ASSERTED 0x01 ! 506: #define IRQ_ASSERTED 0x02 ! 507: #define READ_CONFIG_PIO 0xf0 ! 508: #define SET_CONFIG_PIO 0xf1 ! 509: #define SEND_CP_PIO 0xf2 ! 510: #define RECEIVE_SP_PIO 0xf3 ! 511: #define TRUNCATE_XFR_PIO 0xf4 ! 512: #define RESET_PIO 0xf9 ! 513: #define READ_CONFIG_DMA 0xfd ! 514: #define SET_CONFIG_DMA 0xfe ! 515: #define SEND_CP_DMA 0xff ! 516: #define ASOK 0x00 ! 517: #define ASST 0x01 ! 518: ! 519: #define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr)[0]) ! 520: #define YESNO(a) ((a) ? 'y' : 'n') ! 521: #define TLDEV(type) ((type) == TYPE_DISK || (type) == TYPE_ROM) ! 522: ! 523: /* "EATA", in Big Endian format */ ! 524: #define EATA_SIGNATURE 0x41544145 ! 525: ! 526: /* Number of valid bytes in the board config structure for EATA 2.0x */ ! 527: #define EATA_2_0A_SIZE 28 ! 528: #define EATA_2_0B_SIZE 30 ! 529: #define EATA_2_0C_SIZE 34 ! 530: ! 531: /* Board info structure */ ! 532: struct eata_info { ! 533: ulong data_len; /* Number of valid bytes after this field */ ! 534: ulong sign; /* ASCII "EATA" signature */ ! 535: unchar :4, /* unused low nibble */ ! 536: version:4; /* EATA version, should be 0x1 */ ! 537: unchar ocsena:1, /* Overlap Command Support Enabled */ ! 538: tarsup:1, /* Target Mode Supported */ ! 539: trnxfr:1, /* Truncate Transfer Cmd NOT Necessary */ ! 540: morsup:1, /* More Supported */ ! 541: dmasup:1, /* DMA Supported */ ! 542: drqvld:1, /* DRQ Index (DRQX) is valid */ ! 543: ata:1, /* This is an ATA device */ ! 544: haaval:1; /* Host Adapter Address Valid */ ! 545: ushort cp_pad_len; /* Number of pad bytes after cp_len */ ! 546: unchar host_addr[4]; /* Host Adapter SCSI ID for channels 3, 2, 1, 0 */ ! 547: ulong cp_len; /* Number of valid bytes in cp */ ! 548: ulong sp_len; /* Number of valid bytes in sp */ ! 549: ushort queue_size; /* Max number of cp that can be queued */ ! 550: ushort unused; ! 551: ushort scatt_size; /* Max number of entries in scatter/gather table */ ! 552: unchar irq:4, /* Interrupt Request assigned to this controller */ ! 553: irq_tr:1, /* 0 for edge triggered, 1 for level triggered */ ! 554: second:1, /* 1 if this is a secondary (not primary) controller */ ! 555: drqx:2; /* DRQ Index (0=DMA0, 1=DMA7, 2=DMA6, 3=DMA5) */ ! 556: unchar sync; /* 1 if scsi target id 7...0 is running sync scsi */ ! 557: ! 558: /* Structure extension defined in EATA 2.0B */ ! 559: unchar isaena:1, /* ISA i/o addressing is disabled/enabled */ ! 560: forcaddr:1, /* Port address has been forced */ ! 561: large_sg:1, /* 1 if large SG lists are supported */ ! 562: res1:1, ! 563: :4; ! 564: unchar max_id:5, /* Max SCSI target ID number */ ! 565: max_chan:3; /* Max SCSI channel number on this board */ ! 566: ! 567: /* Structure extension defined in EATA 2.0C */ ! 568: unchar max_lun; /* Max SCSI LUN number */ ! 569: unchar :4, ! 570: m1:1, /* This is a PCI with an M1 chip installed */ ! 571: idquest:1, /* RAIDNUM returned is questionable */ ! 572: pci:1, /* This board is PCI */ ! 573: eisa:1; /* This board is EISA */ ! 574: unchar raidnum; /* Uniquely identifies this HBA in a system */ ! 575: unchar notused; ! 576: ! 577: ushort ipad[247]; ! 578: }; ! 579: ! 580: /* Board config structure */ ! 581: struct eata_config { ! 582: ushort len; /* Number of bytes following this field */ ! 583: unchar edis:1, /* Disable EATA interface after config command */ ! 584: ocena:1, /* Overlapped Commands Enabled */ ! 585: mdpena:1, /* Transfer all Modified Data Pointer Messages */ ! 586: tarena:1, /* Target Mode Enabled for this controller */ ! 587: :4; ! 588: unchar cpad[511]; ! 589: }; ! 590: ! 591: /* Returned status packet structure */ ! 592: struct mssp { ! 593: unchar adapter_status:7, /* State related to current command */ ! 594: eoc:1; /* End Of Command (1 = command completed) */ ! 595: unchar target_status; /* SCSI status received after data transfer */ ! 596: unchar unused[2]; ! 597: ulong inv_res_len; /* Number of bytes not transferred */ ! 598: struct mscp *cpp; /* Address set in cp */ ! 599: char mess[12]; ! 600: }; ! 601: ! 602: struct sg_list { ! 603: unsigned int address; /* Segment Address */ ! 604: unsigned int num_bytes; /* Segment Length */ ! 605: }; ! 606: ! 607: /* MailBox SCSI Command Packet */ ! 608: struct mscp { ! 609: unchar sreset:1, /* SCSI Bus Reset Signal should be asserted */ ! 610: init:1, /* Re-initialize controller and self test */ ! 611: reqsen:1, /* Transfer Request Sense Data to addr using DMA */ ! 612: sg:1, /* Use Scatter/Gather */ ! 613: :1, ! 614: interp:1, /* The controller interprets cp, not the target */ ! 615: dout:1, /* Direction of Transfer is Out (Host to Target) */ ! 616: din:1; /* Direction of Transfer is In (Target to Host) */ ! 617: unchar sense_len; /* Request Sense Length */ ! 618: unchar unused[3]; ! 619: unchar fwnest:1, /* Send command to a component of an Array Group */ ! 620: :7; ! 621: unchar phsunit:1, /* Send to Target Physical Unit (bypass RAID) */ ! 622: iat:1, /* Inhibit Address Translation */ ! 623: hbaci:1, /* Inhibit HBA Caching for this command */ ! 624: :5; ! 625: unchar target:5, /* SCSI target ID */ ! 626: channel:3; /* SCSI channel number */ ! 627: unchar lun:5, /* SCSI logical unit number */ ! 628: luntar:1, /* This cp is for Target (not LUN) */ ! 629: dispri:1, /* Disconnect Privilege granted */ ! 630: one:1; /* 1 */ ! 631: unchar mess[3]; /* Massage to/from Target */ ! 632: unchar cdb[12]; /* Command Descriptor Block */ ! 633: ulong data_len; /* If sg=0 Data Length, if sg=1 sglist length */ ! 634: struct mscp *cpp; /* Address to be returned in sp */ ! 635: ulong data_address; /* If sg=0 Data Address, if sg=1 sglist address */ ! 636: ulong sp_addr; /* Address where sp is DMA'ed when cp completes */ ! 637: ulong sense_addr; /* Address where Sense Data is DMA'ed on error */ ! 638: Scsi_Cmnd *SCpnt; ! 639: unsigned int index; /* cp index */ ! 640: struct sg_list *sglist; ! 641: }; ! 642: ! 643: struct hostdata { ! 644: struct mscp cp[MAX_MAILBOXES]; /* Mailboxes for this board */ ! 645: unsigned int cp_stat[MAX_MAILBOXES]; /* FREE, IN_USE, LOCKED, IN_RESET */ ! 646: unsigned int last_cp_used; /* Index of last mailbox used */ ! 647: unsigned int iocount; /* Total i/o done for this board */ ! 648: int board_number; /* Number of this board */ ! 649: char board_name[16]; /* Name of this board */ ! 650: char board_id[256]; /* data from INQUIRY on this board */ ! 651: int in_reset; /* True if board is doing a reset */ ! 652: int target_to[MAX_TARGET][MAX_CHANNEL]; /* N. of timeout errors on target */ ! 653: int target_redo[MAX_TARGET][MAX_CHANNEL]; /* If TRUE redo i/o on target */ ! 654: unsigned int retries; /* Number of internal retries */ ! 655: unsigned long last_retried_pid; /* Pid of last retried command */ ! 656: unsigned char subversion; /* Bus type, either ISA or EISA/PCI */ ! 657: unsigned char protocol_rev; /* EATA 2.0 rev., 'A' or 'B' or 'C' */ ! 658: struct mssp sp[2]; /* Returned status for this board */ ! 659: }; ! 660: ! 661: static struct Scsi_Host *sh[MAX_BOARDS + 1]; ! 662: static const char *driver_name = "EATA"; ! 663: static char sha[MAX_BOARDS]; ! 664: ! 665: /* Initialize num_boards so that ihdlr can work while detect is in progress */ ! 666: static unsigned int num_boards = MAX_BOARDS; ! 667: ! 668: static unsigned long io_port[] __initdata = { ! 669: ! 670: /* Space for MAX_INT_PARAM ports usable while loading as a module */ ! 671: SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, ! 672: SKIP, SKIP, ! 673: ! 674: /* First ISA */ ! 675: 0x1f0, ! 676: ! 677: /* Space for MAX_PCI ports possibly reported by PCI_BIOS */ ! 678: SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, ! 679: SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, ! 680: ! 681: /* MAX_EISA ports */ ! 682: 0x1c88, 0x2c88, 0x3c88, 0x4c88, 0x5c88, 0x6c88, 0x7c88, 0x8c88, ! 683: 0x9c88, 0xac88, 0xbc88, 0xcc88, 0xdc88, 0xec88, 0xfc88, ! 684: ! 685: /* Other (MAX_ISA - 1) ports */ ! 686: 0x170, 0x230, 0x330, ! 687: ! 688: /* End of list */ ! 689: 0x0 ! 690: }; ! 691: ! 692: #define HD(board) ((struct hostdata *) &sh[board]->hostdata) ! 693: #define BN(board) (HD(board)->board_name) ! 694: ! 695: #define H2DEV(x) htonl(x) ! 696: #define DEV2H(x) H2DEV(x) ! 697: #define V2DEV(addr) ((addr) ? H2DEV(virt_to_bus((void *)addr)) : 0) ! 698: #define DEV2V(addr) ((addr) ? DEV2H(bus_to_virt((unsigned long)addr)) : 0) ! 699: ! 700: static void do_interrupt_handler(int, void *, struct pt_regs *); ! 701: static void flush_dev(Scsi_Device *, unsigned long, unsigned int, unsigned int); ! 702: static int do_trace = FALSE; ! 703: static int setup_done = FALSE; ! 704: static int link_statistics = 0; ! 705: static int tag_mode = TAG_MIXED; ! 706: static int ext_tran = FALSE; ! 707: static int rev_scan = TRUE; ! 708: ! 709: #if defined(CONFIG_SCSI_EATA_TAGGED_QUEUE) ! 710: static int tagged_comm = TRUE; ! 711: #else ! 712: static int tagged_comm = FALSE; ! 713: #endif ! 714: ! 715: #if defined(CONFIG_SCSI_EATA_LINKED_COMMANDS) ! 716: static int linked_comm = TRUE; ! 717: #else ! 718: static int linked_comm = FALSE; ! 719: #endif ! 720: ! 721: #if defined(CONFIG_SCSI_EATA_MAX_TAGS) ! 722: static int max_queue_depth = CONFIG_SCSI_EATA_MAX_TAGS; ! 723: #else ! 724: static int max_queue_depth = MAX_CMD_PER_LUN; ! 725: #endif ! 726: ! 727: static void select_queue_depths(struct Scsi_Host *host, Scsi_Device *devlist) { ! 728: Scsi_Device *dev; ! 729: int j, ntag = 0, nuntag = 0, tqd, utqd; ! 730: IRQ_FLAGS ! 731: ! 732: IRQ_LOCK_SAVE ! 733: j = ((struct hostdata *) host->hostdata)->board_number; ! 734: ! 735: for(dev = devlist; dev; dev = dev->next) { ! 736: ! 737: if (dev->host != host) continue; ! 738: ! 739: if (TLDEV(dev->type) && (dev->tagged_supported || linked_comm)) ! 740: ntag++; ! 741: else ! 742: nuntag++; ! 743: } ! 744: ! 745: utqd = MAX_CMD_PER_LUN; ! 746: ! 747: tqd = (host->can_queue - utqd * nuntag) / (ntag ? ntag : 1); ! 748: ! 749: if (tqd > max_queue_depth) tqd = max_queue_depth; ! 750: ! 751: if (tqd < MAX_CMD_PER_LUN) tqd = MAX_CMD_PER_LUN; ! 752: ! 753: for(dev = devlist; dev; dev = dev->next) { ! 754: char *tag_suffix = "", *link_suffix = ""; ! 755: ! 756: if (dev->host != host) continue; ! 757: ! 758: if (TLDEV(dev->type) && (dev->tagged_supported || linked_comm)) ! 759: dev->queue_depth = tqd; ! 760: else ! 761: dev->queue_depth = utqd; ! 762: ! 763: if (TLDEV(dev->type)) { ! 764: if (linked_comm && dev->queue_depth > 2) ! 765: link_suffix = ", sorted"; ! 766: else ! 767: link_suffix = ", unsorted"; ! 768: } ! 769: ! 770: if (tagged_comm && dev->tagged_supported && TLDEV(dev->type)) { ! 771: dev->tagged_queue = 1; ! 772: dev->current_tag = 1; ! 773: } ! 774: ! 775: if (dev->tagged_supported && TLDEV(dev->type) && dev->tagged_queue) ! 776: tag_suffix = ", tagged"; ! 777: else if (dev->tagged_supported && TLDEV(dev->type)) ! 778: tag_suffix = ", untagged"; ! 779: ! 780: printk("%s: scsi%d, channel %d, id %d, lun %d, cmds/lun %d%s%s.\n", ! 781: BN(j), host->host_no, dev->channel, dev->id, dev->lun, ! 782: dev->queue_depth, link_suffix, tag_suffix); ! 783: } ! 784: ! 785: IRQ_UNLOCK_RESTORE ! 786: return; ! 787: } ! 788: ! 789: static inline int wait_on_busy(unsigned long iobase, unsigned int loop) { ! 790: ! 791: while (inb(iobase + REG_AUX_STATUS) & ABSY_ASSERTED) { ! 792: udelay(1L); ! 793: if (--loop == 0) return TRUE; ! 794: } ! 795: ! 796: return FALSE; ! 797: } ! 798: ! 799: static inline int do_dma(unsigned long iobase, unsigned int addr, unchar cmd) { ! 800: ! 801: if (wait_on_busy(iobase, (addr ? MAXLOOP * 100 : MAXLOOP))) return TRUE; ! 802: ! 803: if ((addr = V2DEV(addr))) { ! 804: outb((char) (addr >> 24), iobase + REG_LOW); ! 805: outb((char) (addr >> 16), iobase + REG_LM); ! 806: outb((char) (addr >> 8), iobase + REG_MID); ! 807: outb((char) addr, iobase + REG_MSB); ! 808: } ! 809: ! 810: outb(cmd, iobase + REG_CMD); ! 811: return FALSE; ! 812: } ! 813: ! 814: static inline int read_pio(unsigned long iobase, ushort *start, ushort *end) { ! 815: unsigned int loop = MAXLOOP; ! 816: ushort *p; ! 817: ! 818: for (p = start; p <= end; p++) { ! 819: ! 820: while (!(inb(iobase + REG_STATUS) & DRQ_ASSERTED)) { ! 821: udelay(1L); ! 822: if (--loop == 0) return TRUE; ! 823: } ! 824: ! 825: loop = MAXLOOP; ! 826: *p = inw(iobase); ! 827: } ! 828: ! 829: return FALSE; ! 830: } ! 831: ! 832: __initfunc (static inline int ! 833: get_pci_irq(unsigned long port_base, unsigned char *apic_irq)) { ! 834: ! 835: #if defined(CONFIG_PCI) ! 836: ! 837: #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,93) ! 838: ! 839: unsigned int addr; ! 840: struct pci_dev *dev = NULL; ! 841: ! 842: if (!pci_present()) return FALSE; ! 843: ! 844: while((dev = pci_find_class(PCI_CLASS_STORAGE_SCSI << 8, dev))) { ! 845: ! 846: if (pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &addr)) continue; ! 847: ! 848: #if defined(DEBUG_PCI_DETECT) ! 849: printk("%s: get_pci_irq, bus %d, devfn 0x%x, addr 0x%x, apic_irq %u.\n", ! 850: driver_name, dev->bus->number, dev->devfn, addr, dev->irq); ! 851: #endif ! 852: ! 853: if ((addr & PCI_BASE_ADDRESS_SPACE) != PCI_BASE_ADDRESS_SPACE_IO) ! 854: continue; ! 855: ! 856: if ((addr & PCI_BASE_ADDRESS_IO_MASK) + PCI_BASE_ADDRESS_0 == port_base) { ! 857: *apic_irq = dev->irq; ! 858: return TRUE; ! 859: } ! 860: ! 861: } ! 862: ! 863: #endif /* end new style PCI code */ ! 864: ! 865: #endif /* end CONFIG_PCI */ ! 866: ! 867: return FALSE; ! 868: } ! 869: ! 870: __initfunc (static inline int port_detect \ ! 871: (unsigned long port_base, unsigned int j, Scsi_Host_Template *tpnt)) { ! 872: unsigned char irq, dma_channel, subversion, i; ! 873: unsigned char protocol_rev, apic_irq; ! 874: struct eata_info info; ! 875: char *bus_type, dma_name[16], tag_type; ! 876: ! 877: /* Allowed DMA channels for ISA (0 indicates reserved) */ ! 878: unsigned char dma_channel_table[4] = { 5, 6, 7, 0 }; ! 879: ! 880: char name[16]; ! 881: ! 882: sprintf(name, "%s%d", driver_name, j); ! 883: ! 884: if(check_region(port_base, REGION_SIZE)) { ! 885: printk("%s: address 0x%03lx in use, skipping probe.\n", name, port_base); ! 886: return FALSE; ! 887: } ! 888: ! 889: if (do_dma(port_base, 0, READ_CONFIG_PIO)) return FALSE; ! 890: ! 891: /* Read the info structure */ ! 892: if (read_pio(port_base, (ushort *)&info, (ushort *)&info.ipad[0])) ! 893: return FALSE; ! 894: ! 895: /* Check the controller "EATA" signature */ ! 896: if (info.sign != EATA_SIGNATURE) return FALSE; ! 897: ! 898: if (DEV2H(info.data_len) < EATA_2_0A_SIZE) { ! 899: printk("%s: config structure size (%ld bytes) too short, detaching.\n", ! 900: name, DEV2H(info.data_len)); ! 901: return FALSE; ! 902: } ! 903: else if (DEV2H(info.data_len) == EATA_2_0A_SIZE) ! 904: protocol_rev = 'A'; ! 905: else if (DEV2H(info.data_len) == EATA_2_0B_SIZE) ! 906: protocol_rev = 'B'; ! 907: else ! 908: protocol_rev = 'C'; ! 909: ! 910: if (!setup_done && j > 0 && j <= MAX_PCI) { ! 911: bus_type = "PCI"; ! 912: subversion = ESA; ! 913: } ! 914: else if (port_base > MAX_EISA_ADDR || (protocol_rev == 'C' && info.pci)) { ! 915: bus_type = "PCI"; ! 916: subversion = ESA; ! 917: } ! 918: else if (port_base >= MIN_EISA_ADDR || (protocol_rev == 'C' && info.eisa)) { ! 919: bus_type = "EISA"; ! 920: subversion = ESA; ! 921: } ! 922: else if (protocol_rev == 'C' && !info.eisa && !info.pci) { ! 923: bus_type = "ISA"; ! 924: subversion = ISA; ! 925: } ! 926: else if (port_base > MAX_ISA_ADDR) { ! 927: bus_type = "PCI"; ! 928: subversion = ESA; ! 929: } ! 930: else { ! 931: bus_type = "ISA"; ! 932: subversion = ISA; ! 933: } ! 934: ! 935: if (!info.haaval || info.ata) { ! 936: printk("%s: address 0x%03lx, unusable %s board (%d%d), detaching.\n", ! 937: name, port_base, bus_type, info.haaval, info.ata); ! 938: return FALSE; ! 939: } ! 940: ! 941: if (info.drqvld) { ! 942: ! 943: if (subversion == ESA) ! 944: printk("%s: warning, weird %s board using DMA.\n", name, bus_type); ! 945: ! 946: subversion = ISA; ! 947: dma_channel = dma_channel_table[3 - info.drqx]; ! 948: } ! 949: else { ! 950: ! 951: if (subversion == ISA) ! 952: printk("%s: warning, weird %s board not using DMA.\n", name, bus_type); ! 953: ! 954: subversion = ESA; ! 955: dma_channel = NO_DMA; ! 956: } ! 957: ! 958: if (!info.dmasup) ! 959: printk("%s: warning, DMA protocol support not asserted.\n", name); ! 960: ! 961: irq = info.irq; ! 962: ! 963: if (subversion == ESA && !info.irq_tr) ! 964: printk("%s: warning, LEVEL triggering is suggested for IRQ %u.\n", ! 965: name, irq); ! 966: ! 967: if (get_pci_irq(port_base, &apic_irq) && (irq != apic_irq)) { ! 968: printk("%s: IRQ %u mapped to IO-APIC IRQ %u.\n", name, irq, apic_irq); ! 969: irq = apic_irq; ! 970: } ! 971: ! 972: /* Board detected, allocate its IRQ */ ! 973: if (request_irq(irq, do_interrupt_handler, ! 974: SA_INTERRUPT | ((subversion == ESA) ? SA_SHIRQ : 0), ! 975: driver_name, (void *) &sha[j])) { ! 976: printk("%s: unable to allocate IRQ %u, detaching.\n", name, irq); ! 977: return FALSE; ! 978: } ! 979: ! 980: if (subversion == ISA && request_dma(dma_channel, driver_name)) { ! 981: printk("%s: unable to allocate DMA channel %u, detaching.\n", ! 982: name, dma_channel); ! 983: free_irq(irq, &sha[j]); ! 984: return FALSE; ! 985: } ! 986: ! 987: #if defined(FORCE_CONFIG) ! 988: { ! 989: struct eata_config config; ! 990: ! 991: /* Set board configuration */ ! 992: memset((char *)&config, 0, sizeof(struct eata_config)); ! 993: config.len = (ushort) htons((ushort)510); ! 994: config.ocena = TRUE; ! 995: ! 996: if (do_dma(port_base, (unsigned int)&config, SET_CONFIG_DMA)) { ! 997: printk("%s: busy timeout sending configuration, detaching.\n", name); ! 998: return FALSE; ! 999: } ! 1000: } ! 1001: #endif ! 1002: ! 1003: sh[j] = scsi_register(tpnt, sizeof(struct hostdata)); ! 1004: ! 1005: if (sh[j] == NULL) { ! 1006: printk("%s: unable to register host, detaching.\n", name); ! 1007: ! 1008: free_irq(irq, &sha[j]); ! 1009: ! 1010: if (subversion == ISA) free_dma(dma_channel); ! 1011: ! 1012: return FALSE; ! 1013: } ! 1014: ! 1015: sh[j]->io_port = port_base; ! 1016: sh[j]->unique_id = port_base; ! 1017: sh[j]->n_io_port = REGION_SIZE; ! 1018: sh[j]->dma_channel = dma_channel; ! 1019: sh[j]->irq = irq; ! 1020: sh[j]->sg_tablesize = (ushort) ntohs(info.scatt_size); ! 1021: sh[j]->this_id = (ushort) info.host_addr[3]; ! 1022: sh[j]->can_queue = (ushort) ntohs(info.queue_size); ! 1023: sh[j]->cmd_per_lun = MAX_CMD_PER_LUN; ! 1024: sh[j]->select_queue_depths = select_queue_depths; ! 1025: ! 1026: /* Register the I/O space that we use */ ! 1027: request_region(sh[j]->io_port, sh[j]->n_io_port, driver_name); ! 1028: ! 1029: memset(HD(j), 0, sizeof(struct hostdata)); ! 1030: HD(j)->subversion = subversion; ! 1031: HD(j)->protocol_rev = protocol_rev; ! 1032: HD(j)->board_number = j; ! 1033: ! 1034: if (HD(j)->subversion == ESA) ! 1035: sh[j]->unchecked_isa_dma = FALSE; ! 1036: else { ! 1037: sh[j]->wish_block = TRUE; ! 1038: sh[j]->unchecked_isa_dma = TRUE; ! 1039: disable_dma(dma_channel); ! 1040: clear_dma_ff(dma_channel); ! 1041: set_dma_mode(dma_channel, DMA_MODE_CASCADE); ! 1042: enable_dma(dma_channel); ! 1043: } ! 1044: ! 1045: strcpy(BN(j), name); ! 1046: ! 1047: /* DPT PM2012 does not allow to detect sg_tablesize correctly */ ! 1048: if (sh[j]->sg_tablesize > MAX_SGLIST || sh[j]->sg_tablesize < 2) { ! 1049: printk("%s: detect, wrong n. of SG lists %d, fixed.\n", ! 1050: BN(j), sh[j]->sg_tablesize); ! 1051: sh[j]->sg_tablesize = MAX_SGLIST; ! 1052: } ! 1053: ! 1054: /* DPT PM2012 does not allow to detect can_queue correctly */ ! 1055: if (sh[j]->can_queue > MAX_MAILBOXES || sh[j]->can_queue < 2) { ! 1056: printk("%s: detect, wrong n. of mbox %d, fixed.\n", ! 1057: BN(j), sh[j]->can_queue); ! 1058: sh[j]->can_queue = MAX_MAILBOXES; ! 1059: } ! 1060: ! 1061: if (protocol_rev != 'A') { ! 1062: ! 1063: if (info.max_chan > 0 && info.max_chan < MAX_CHANNEL) ! 1064: sh[j]->max_channel = info.max_chan; ! 1065: ! 1066: if (info.max_id > 7 && info.max_id < MAX_TARGET) ! 1067: sh[j]->max_id = info.max_id + 1; ! 1068: ! 1069: if (info.large_sg && sh[j]->sg_tablesize == MAX_SGLIST) ! 1070: sh[j]->sg_tablesize = MAX_LARGE_SGLIST; ! 1071: } ! 1072: ! 1073: if (protocol_rev == 'C') { ! 1074: ! 1075: if (info.max_lun > 7 && info.max_lun < MAX_LUN) ! 1076: sh[j]->max_lun = info.max_lun + 1; ! 1077: } ! 1078: ! 1079: if (dma_channel == NO_DMA) sprintf(dma_name, "%s", "BMST"); ! 1080: else sprintf(dma_name, "DMA %u", dma_channel); ! 1081: ! 1082: for (i = 0; i < sh[j]->can_queue; i++) ! 1083: if (! ((&HD(j)->cp[i])->sglist = kmalloc( ! 1084: sh[j]->sg_tablesize * sizeof(struct sg_list), ! 1085: (sh[j]->unchecked_isa_dma ? GFP_DMA : 0) | GFP_ATOMIC))) { ! 1086: printk("%s: kmalloc SGlist failed, mbox %d, detaching.\n", BN(j), i); ! 1087: eata2x_release(sh[j]); ! 1088: return FALSE; ! 1089: } ! 1090: ! 1091: if (max_queue_depth > MAX_TAGGED_CMD_PER_LUN) ! 1092: max_queue_depth = MAX_TAGGED_CMD_PER_LUN; ! 1093: ! 1094: if (max_queue_depth < MAX_CMD_PER_LUN) max_queue_depth = MAX_CMD_PER_LUN; ! 1095: ! 1096: if (tagged_comm) { ! 1097: if (tag_mode == TAG_SIMPLE) tag_type = '1'; ! 1098: else if (tag_mode == TAG_HEAD) tag_type = '2'; ! 1099: else if (tag_mode == TAG_ORDERED) tag_type = '3'; ! 1100: else tag_type = 'y'; ! 1101: } ! 1102: else tag_type = 'n'; ! 1103: ! 1104: #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,101) ! 1105: sh[j]->hostt->use_new_eh_code = use_new_eh_code; ! 1106: #else ! 1107: use_new_eh_code = FALSE; ! 1108: #endif ! 1109: ! 1110: if (j == 0) { ! 1111: printk("EATA/DMA 2.0x: Copyright (C) 1994-1998 Dario Ballabio.\n"); ! 1112: printk("%s config options -> tc:%c, lc:%c, mq:%d, eh:%c, rs:%c, et:%c.\n", ! 1113: driver_name, tag_type, YESNO(linked_comm), max_queue_depth, ! 1114: YESNO(use_new_eh_code), YESNO(rev_scan), YESNO(ext_tran)); ! 1115: } ! 1116: ! 1117: printk("%s: 2.0%c, %s 0x%03lx, IRQ %u, %s, SG %d, MB %d.\n", ! 1118: BN(j), HD(j)->protocol_rev, bus_type, (unsigned long)sh[j]->io_port, ! 1119: sh[j]->irq, dma_name, sh[j]->sg_tablesize, sh[j]->can_queue); ! 1120: ! 1121: if (sh[j]->max_id > 8 || sh[j]->max_lun > 8) ! 1122: printk("%s: wide SCSI support enabled, max_id %u, max_lun %u.\n", ! 1123: BN(j), sh[j]->max_id, sh[j]->max_lun); ! 1124: ! 1125: for (i = 0; i <= sh[j]->max_channel; i++) ! 1126: printk("%s: SCSI channel %u enabled, host target ID %d.\n", ! 1127: BN(j), i, info.host_addr[3 - i]); ! 1128: ! 1129: #if defined(DEBUG_DETECT) ! 1130: printk("%s: Vers. 0x%x, ocs %u, tar %u, trnxfr %u, more %u, SYNC 0x%x, "\ ! 1131: "sec. %u, infol %ld, cpl %ld spl %ld.\n", name, info.version, ! 1132: info.ocsena, info.tarsup, info.trnxfr, info.morsup, info.sync, ! 1133: info.second, DEV2H(info.data_len), DEV2H(info.cp_len), ! 1134: DEV2H(info.sp_len)); ! 1135: ! 1136: if (protocol_rev == 'B' || protocol_rev == 'C') ! 1137: printk("%s: isaena %u, forcaddr %u, max_id %u, max_chan %u, "\ ! 1138: "large_sg %u, res1 %u.\n", name, info.isaena, info.forcaddr, ! 1139: info.max_id, info.max_chan, info.large_sg, info.res1); ! 1140: ! 1141: if (protocol_rev == 'C') ! 1142: printk("%s: max_lun %u, m1 %u, idquest %u, pci %u, eisa %u, "\ ! 1143: "raidnum %u.\n", name, info.max_lun, info.m1, info.idquest, ! 1144: info.pci, info.eisa, info.raidnum); ! 1145: #endif ! 1146: ! 1147: return TRUE; ! 1148: } ! 1149: ! 1150: __initfunc (void eata2x_setup(char *str, int *ints)) { ! 1151: int i, argc = ints[0]; ! 1152: char *cur = str, *pc; ! 1153: ! 1154: if (argc > 0) { ! 1155: ! 1156: if (argc > MAX_INT_PARAM) argc = MAX_INT_PARAM; ! 1157: ! 1158: for (i = 0; i < argc; i++) io_port[i] = ints[i + 1]; ! 1159: ! 1160: io_port[i] = 0; ! 1161: setup_done = TRUE; ! 1162: } ! 1163: ! 1164: while (cur && (pc = strchr(cur, ':'))) { ! 1165: int val = 0, c = *++pc; ! 1166: ! 1167: if (c == 'n' || c == 'N') val = FALSE; ! 1168: else if (c == 'y' || c == 'Y') val = TRUE; ! 1169: else val = (int) simple_strtoul(pc, NULL, 0); ! 1170: ! 1171: if (!strncmp(cur, "lc:", 3)) linked_comm = val; ! 1172: else if (!strncmp(cur, "tc:", 3)) tagged_comm = val; ! 1173: else if (!strncmp(cur, "tm:", 3)) tag_mode = val; ! 1174: else if (!strncmp(cur, "mq:", 3)) max_queue_depth = val; ! 1175: else if (!strncmp(cur, "ls:", 3)) link_statistics = val; ! 1176: else if (!strncmp(cur, "eh:", 3)) use_new_eh_code = val; ! 1177: else if (!strncmp(cur, "et:", 3)) ext_tran = val; ! 1178: else if (!strncmp(cur, "rs:", 3)) rev_scan = val; ! 1179: ! 1180: if ((cur = strchr(cur, ','))) ++cur; ! 1181: } ! 1182: ! 1183: return; ! 1184: } ! 1185: ! 1186: __initfunc (static void add_pci_ports(void)) { ! 1187: ! 1188: #if defined(CONFIG_PCI) ! 1189: ! 1190: unsigned int addr, k; ! 1191: ! 1192: #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,93) ! 1193: ! 1194: struct pci_dev *dev = NULL; ! 1195: ! 1196: if (!pci_present()) return; ! 1197: ! 1198: for (k = 0; k < MAX_PCI; k++) { ! 1199: ! 1200: if (!(dev = pci_find_class(PCI_CLASS_STORAGE_SCSI << 8, dev))) break; ! 1201: ! 1202: if (pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, &addr)) continue; ! 1203: ! 1204: #if defined(DEBUG_PCI_DETECT) ! 1205: printk("%s: detect, seq. %d, bus %d, devfn 0x%x, addr 0x%x.\n", ! 1206: driver_name, k, dev->bus->number, dev->devfn, addr); ! 1207: #endif ! 1208: ! 1209: if ((addr & PCI_BASE_ADDRESS_SPACE) != PCI_BASE_ADDRESS_SPACE_IO) ! 1210: continue; ! 1211: ! 1212: /* Order addresses according to rev_scan value */ ! 1213: io_port[MAX_INT_PARAM + (rev_scan ? (MAX_PCI - k) : (1 + k))] = ! 1214: (addr & PCI_BASE_ADDRESS_IO_MASK) + PCI_BASE_ADDRESS_0; ! 1215: } ! 1216: ! 1217: #else /* else old style PCI code */ ! 1218: ! 1219: unsigned short i = 0; ! 1220: unsigned char bus, devfn; ! 1221: ! 1222: if (!pcibios_present()) return; ! 1223: ! 1224: for (k = 0; k < MAX_PCI; k++) { ! 1225: ! 1226: if (pcibios_find_class(PCI_CLASS_STORAGE_SCSI << 8, i++, &bus, &devfn) ! 1227: != PCIBIOS_SUCCESSFUL) break; ! 1228: ! 1229: if (pcibios_read_config_dword(bus, devfn, PCI_BASE_ADDRESS_0, &addr) ! 1230: != PCIBIOS_SUCCESSFUL) continue; ! 1231: ! 1232: #if defined(DEBUG_PCI_DETECT) ! 1233: printk("%s: detect, seq. %d, bus %d, devfn 0x%x, addr 0x%x.\n", ! 1234: driver_name, k, bus, devfn, addr); ! 1235: #endif ! 1236: ! 1237: if ((addr & PCI_BASE_ADDRESS_SPACE) != PCI_BASE_ADDRESS_SPACE_IO) ! 1238: continue; ! 1239: ! 1240: /* Order addresses according to rev_scan value */ ! 1241: io_port[MAX_INT_PARAM + (rev_scan ? (MAX_PCI - k) : (1 + k))] = ! 1242: (addr & PCI_BASE_ADDRESS_IO_MASK) + PCI_BASE_ADDRESS_0; ! 1243: } ! 1244: ! 1245: #endif /* end old style PCI code */ ! 1246: ! 1247: #endif /* end CONFIG_PCI */ ! 1248: ! 1249: return; ! 1250: } ! 1251: ! 1252: __initfunc (int eata2x_detect(Scsi_Host_Template *tpnt)) { ! 1253: unsigned int j = 0, k; ! 1254: IRQ_FLAGS ! 1255: ! 1256: IRQ_LOCK_SAVE ! 1257: tpnt->proc_dir = &proc_scsi_eata2x; ! 1258: ! 1259: #if defined(MODULE) ! 1260: /* io_port could have been modified when loading as a module */ ! 1261: if(io_port[0] != SKIP) { ! 1262: setup_done = TRUE; ! 1263: io_port[MAX_INT_PARAM] = 0; ! 1264: } ! 1265: #endif ! 1266: ! 1267: for (k = 0; k < MAX_BOARDS + 1; k++) sh[k] = NULL; ! 1268: ! 1269: if (!setup_done) add_pci_ports(); ! 1270: ! 1271: for (k = 0; io_port[k]; k++) { ! 1272: ! 1273: if (io_port[k] == SKIP) continue; ! 1274: ! 1275: if (j < MAX_BOARDS && port_detect(io_port[k], j, tpnt)) j++; ! 1276: } ! 1277: ! 1278: num_boards = j; ! 1279: IRQ_UNLOCK_RESTORE ! 1280: return j; ! 1281: } ! 1282: ! 1283: static inline void build_sg_list(struct mscp *cpp, Scsi_Cmnd *SCpnt) { ! 1284: unsigned int k; ! 1285: struct scatterlist *sgpnt; ! 1286: ! 1287: sgpnt = (struct scatterlist *) SCpnt->request_buffer; ! 1288: ! 1289: for (k = 0; k < SCpnt->use_sg; k++) { ! 1290: cpp->sglist[k].address = V2DEV(sgpnt[k].address); ! 1291: cpp->sglist[k].num_bytes = H2DEV(sgpnt[k].length); ! 1292: } ! 1293: ! 1294: cpp->data_address = V2DEV(cpp->sglist); ! 1295: cpp->data_len = H2DEV((SCpnt->use_sg * sizeof(struct sg_list))); ! 1296: } ! 1297: ! 1298: static inline int do_qcomm(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) { ! 1299: unsigned int i, j, k; ! 1300: struct mscp *cpp; ! 1301: struct mssp *spp; ! 1302: ! 1303: static const unsigned char data_out_cmds[] = { ! 1304: 0x0a, 0x2a, 0x15, 0x55, 0x04, 0x07, 0x18, 0x1d, 0x24, 0x2e, ! 1305: 0x30, 0x31, 0x32, 0x38, 0x39, 0x3a, 0x3b, 0x3d, 0x3f, 0x40, ! 1306: 0x41, 0x4c, 0xaa, 0xae, 0xb0, 0xb1, 0xb2, 0xb6, 0xea, 0x1b ! 1307: }; ! 1308: ! 1309: static const unsigned char data_none_cmds[] = { ! 1310: 0x01, 0x0b, 0x10, 0x11, 0x13, 0x16, 0x17, 0x19, 0x2b, 0x1e, ! 1311: 0x2c, 0xac, 0x2f, 0xaf, 0x33, 0xb3, 0x35, 0x36, 0x45, 0x47, ! 1312: 0x48, 0x49, 0xa9, 0x4b, 0xa5, 0xa6, 0xb5 ! 1313: }; ! 1314: ! 1315: /* j is the board number */ ! 1316: j = ((struct hostdata *) SCpnt->host->hostdata)->board_number; ! 1317: ! 1318: if (SCpnt->host_scribble) ! 1319: panic("%s: qcomm, pid %ld, SCpnt %p already active.\n", ! 1320: BN(j), SCpnt->pid, SCpnt); ! 1321: ! 1322: /* i is the mailbox number, look for the first free mailbox ! 1323: starting from last_cp_used */ ! 1324: i = HD(j)->last_cp_used + 1; ! 1325: ! 1326: for (k = 0; k < sh[j]->can_queue; k++, i++) { ! 1327: ! 1328: if (i >= sh[j]->can_queue) i = 0; ! 1329: ! 1330: if (HD(j)->cp_stat[i] == FREE) { ! 1331: HD(j)->last_cp_used = i; ! 1332: break; ! 1333: } ! 1334: } ! 1335: ! 1336: if (k == sh[j]->can_queue) { ! 1337: printk("%s: qcomm, no free mailbox.\n", BN(j)); ! 1338: return 1; ! 1339: } ! 1340: ! 1341: /* Set pointer to control packet structure */ ! 1342: cpp = &HD(j)->cp[i]; ! 1343: ! 1344: memset(cpp, 0, sizeof(struct mscp) - sizeof(struct sg_list *)); ! 1345: ! 1346: /* Set pointer to status packet structure */ ! 1347: spp = &HD(j)->sp[0]; ! 1348: ! 1349: /* The EATA protocol uses Big Endian format */ ! 1350: cpp->sp_addr = V2DEV(spp); ! 1351: ! 1352: cpp->cpp = cpp; ! 1353: SCpnt->scsi_done = done; ! 1354: cpp->index = i; ! 1355: SCpnt->host_scribble = (unsigned char *) &cpp->index; ! 1356: ! 1357: if (do_trace) printk("%s: qcomm, mbox %d, target %d.%d:%d, pid %ld.\n", ! 1358: BN(j), i, SCpnt->channel, SCpnt->target, ! 1359: SCpnt->lun, SCpnt->pid); ! 1360: ! 1361: for (k = 0; k < ARRAY_SIZE(data_out_cmds); k++) ! 1362: if (SCpnt->cmnd[0] == data_out_cmds[k]) { ! 1363: cpp->dout = TRUE; ! 1364: break; ! 1365: } ! 1366: ! 1367: if ((cpp->din = !cpp->dout)) ! 1368: for (k = 0; k < ARRAY_SIZE(data_none_cmds); k++) ! 1369: if (SCpnt->cmnd[0] == data_none_cmds[k]) { ! 1370: cpp->din = FALSE; ! 1371: break; ! 1372: } ! 1373: ! 1374: cpp->reqsen = TRUE; ! 1375: cpp->dispri = TRUE; ! 1376: #if 0 ! 1377: if (SCpnt->device->type == TYPE_TAPE) cpp->hbaci = TRUE; ! 1378: #endif ! 1379: cpp->one = TRUE; ! 1380: cpp->channel = SCpnt->channel; ! 1381: cpp->target = SCpnt->target; ! 1382: cpp->lun = SCpnt->lun; ! 1383: cpp->SCpnt = SCpnt; ! 1384: cpp->sense_addr = V2DEV(SCpnt->sense_buffer); ! 1385: cpp->sense_len = sizeof SCpnt->sense_buffer; ! 1386: ! 1387: if (SCpnt->device->tagged_queue) { ! 1388: ! 1389: if (HD(j)->target_redo[SCpnt->target][SCpnt->channel] || ! 1390: HD(j)->target_to[SCpnt->target][SCpnt->channel]) ! 1391: cpp->mess[0] = ORDERED_QUEUE_TAG; ! 1392: else if (tag_mode == TAG_SIMPLE) cpp->mess[0] = SIMPLE_QUEUE_TAG; ! 1393: else if (tag_mode == TAG_HEAD) cpp->mess[0] = HEAD_OF_QUEUE_TAG; ! 1394: else if (tag_mode == TAG_ORDERED) cpp->mess[0] = ORDERED_QUEUE_TAG; ! 1395: else if (SCpnt->device->current_tag == 0) ! 1396: cpp->mess[0] = ORDERED_QUEUE_TAG; ! 1397: else if (SCpnt->device->current_tag == 1) ! 1398: cpp->mess[0] = HEAD_OF_QUEUE_TAG; ! 1399: else ! 1400: cpp->mess[0] = SIMPLE_QUEUE_TAG; ! 1401: ! 1402: cpp->mess[1] = SCpnt->device->current_tag++; ! 1403: } ! 1404: ! 1405: if (SCpnt->use_sg) { ! 1406: cpp->sg = TRUE; ! 1407: build_sg_list(cpp, SCpnt); ! 1408: } ! 1409: else { ! 1410: cpp->data_address = V2DEV(SCpnt->request_buffer); ! 1411: cpp->data_len = H2DEV(SCpnt->request_bufflen); ! 1412: } ! 1413: ! 1414: memcpy(cpp->cdb, SCpnt->cmnd, SCpnt->cmd_len); ! 1415: ! 1416: if (linked_comm && SCpnt->device->queue_depth > 2 ! 1417: && TLDEV(SCpnt->device->type)) { ! 1418: HD(j)->cp_stat[i] = READY; ! 1419: flush_dev(SCpnt->device, SCpnt->request.sector, j, FALSE); ! 1420: return 0; ! 1421: } ! 1422: ! 1423: /* Send control packet to the board */ ! 1424: if (do_dma(sh[j]->io_port, (unsigned int) cpp, SEND_CP_DMA)) { ! 1425: SCpnt->host_scribble = NULL; ! 1426: printk("%s: qcomm, target %d.%d:%d, pid %ld, adapter busy.\n", ! 1427: BN(j), SCpnt->channel, SCpnt->target, SCpnt->lun, SCpnt->pid); ! 1428: return 1; ! 1429: } ! 1430: ! 1431: HD(j)->cp_stat[i] = IN_USE; ! 1432: return 0; ! 1433: } ! 1434: ! 1435: int eata2x_queuecommand(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) { ! 1436: int rtn; ! 1437: IRQ_FLAGS ! 1438: ! 1439: IRQ_LOCK_SAVE ! 1440: rtn = do_qcomm(SCpnt, done); ! 1441: IRQ_UNLOCK_RESTORE ! 1442: return rtn; ! 1443: } ! 1444: ! 1445: static inline int do_old_abort(Scsi_Cmnd *SCarg) { ! 1446: unsigned int i, j; ! 1447: ! 1448: j = ((struct hostdata *) SCarg->host->hostdata)->board_number; ! 1449: ! 1450: if (SCarg->host_scribble == NULL || ! 1451: (SCarg->serial_number_at_timeout && ! 1452: (SCarg->serial_number != SCarg->serial_number_at_timeout))) { ! 1453: printk("%s: abort, target %d.%d:%d, pid %ld inactive.\n", ! 1454: BN(j), SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid); ! 1455: return SCSI_ABORT_NOT_RUNNING; ! 1456: } ! 1457: ! 1458: i = *(unsigned int *)SCarg->host_scribble; ! 1459: printk("%s: abort, mbox %d, target %d.%d:%d, pid %ld.\n", ! 1460: BN(j), i, SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid); ! 1461: ! 1462: if (i >= sh[j]->can_queue) ! 1463: panic("%s: abort, invalid SCarg->host_scribble.\n", BN(j)); ! 1464: ! 1465: if (wait_on_busy(sh[j]->io_port, MAXLOOP)) { ! 1466: printk("%s: abort, timeout error.\n", BN(j)); ! 1467: return SCSI_ABORT_ERROR; ! 1468: } ! 1469: ! 1470: if (HD(j)->cp_stat[i] == FREE) { ! 1471: printk("%s: abort, mbox %d is free.\n", BN(j), i); ! 1472: return SCSI_ABORT_NOT_RUNNING; ! 1473: } ! 1474: ! 1475: if (HD(j)->cp_stat[i] == IN_USE) { ! 1476: printk("%s: abort, mbox %d is in use.\n", BN(j), i); ! 1477: ! 1478: if (SCarg != HD(j)->cp[i].SCpnt) ! 1479: panic("%s: abort, mbox %d, SCarg %p, cp SCpnt %p.\n", ! 1480: BN(j), i, SCarg, HD(j)->cp[i].SCpnt); ! 1481: ! 1482: if (inb(sh[j]->io_port + REG_AUX_STATUS) & IRQ_ASSERTED) ! 1483: printk("%s: abort, mbox %d, interrupt pending.\n", BN(j), i); ! 1484: ! 1485: return SCSI_ABORT_SNOOZE; ! 1486: } ! 1487: ! 1488: if (HD(j)->cp_stat[i] == IN_RESET) { ! 1489: printk("%s: abort, mbox %d is in reset.\n", BN(j), i); ! 1490: return SCSI_ABORT_ERROR; ! 1491: } ! 1492: ! 1493: if (HD(j)->cp_stat[i] == LOCKED) { ! 1494: printk("%s: abort, mbox %d is locked.\n", BN(j), i); ! 1495: return SCSI_ABORT_NOT_RUNNING; ! 1496: } ! 1497: ! 1498: if (HD(j)->cp_stat[i] == READY || HD(j)->cp_stat[i] == ABORTING) { ! 1499: SCarg->result = DID_ABORT << 16; ! 1500: SCarg->host_scribble = NULL; ! 1501: HD(j)->cp_stat[i] = FREE; ! 1502: printk("%s, abort, mbox %d ready, DID_ABORT, pid %ld done.\n", ! 1503: BN(j), i, SCarg->pid); ! 1504: SCarg->scsi_done(SCarg); ! 1505: return SCSI_ABORT_SUCCESS; ! 1506: } ! 1507: ! 1508: panic("%s: abort, mbox %d, invalid cp_stat.\n", BN(j), i); ! 1509: } ! 1510: ! 1511: int eata2x_old_abort(Scsi_Cmnd *SCarg) { ! 1512: int rtn; ! 1513: IRQ_FLAGS ! 1514: ! 1515: IRQ_LOCK_SAVE ! 1516: rtn = do_old_abort(SCarg); ! 1517: IRQ_UNLOCK_RESTORE ! 1518: return rtn; ! 1519: } ! 1520: ! 1521: #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,101) ! 1522: ! 1523: static inline int do_abort(Scsi_Cmnd *SCarg) { ! 1524: unsigned int i, j; ! 1525: ! 1526: j = ((struct hostdata *) SCarg->host->hostdata)->board_number; ! 1527: ! 1528: if (SCarg->host_scribble == NULL) { ! 1529: printk("%s: abort, target %d.%d:%d, pid %ld inactive.\n", ! 1530: BN(j), SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid); ! 1531: return SUCCESS; ! 1532: } ! 1533: ! 1534: i = *(unsigned int *)SCarg->host_scribble; ! 1535: printk("%s: abort, mbox %d, target %d.%d:%d, pid %ld.\n", ! 1536: BN(j), i, SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid); ! 1537: ! 1538: if (i >= sh[j]->can_queue) ! 1539: panic("%s: abort, invalid SCarg->host_scribble.\n", BN(j)); ! 1540: ! 1541: if (wait_on_busy(sh[j]->io_port, MAXLOOP)) { ! 1542: printk("%s: abort, timeout error.\n", BN(j)); ! 1543: return FAILED; ! 1544: } ! 1545: ! 1546: if (HD(j)->cp_stat[i] == FREE) { ! 1547: printk("%s: abort, mbox %d is free.\n", BN(j), i); ! 1548: return SUCCESS; ! 1549: } ! 1550: ! 1551: if (HD(j)->cp_stat[i] == IN_USE) { ! 1552: printk("%s: abort, mbox %d is in use.\n", BN(j), i); ! 1553: ! 1554: if (SCarg != HD(j)->cp[i].SCpnt) ! 1555: panic("%s: abort, mbox %d, SCarg %p, cp SCpnt %p.\n", ! 1556: BN(j), i, SCarg, HD(j)->cp[i].SCpnt); ! 1557: ! 1558: if (inb(sh[j]->io_port + REG_AUX_STATUS) & IRQ_ASSERTED) ! 1559: printk("%s: abort, mbox %d, interrupt pending.\n", BN(j), i); ! 1560: ! 1561: if (SCarg->eh_state == SCSI_STATE_TIMEOUT) { ! 1562: SCarg->host_scribble = NULL; ! 1563: HD(j)->cp_stat[i] = FREE; ! 1564: printk("%s, abort, mbox %d, eh_state timeout, pid %ld.\n", ! 1565: BN(j), i, SCarg->pid); ! 1566: return SUCCESS; ! 1567: } ! 1568: ! 1569: return FAILED; ! 1570: } ! 1571: ! 1572: if (HD(j)->cp_stat[i] == IN_RESET) { ! 1573: printk("%s: abort, mbox %d is in reset.\n", BN(j), i); ! 1574: return FAILED; ! 1575: } ! 1576: ! 1577: if (HD(j)->cp_stat[i] == LOCKED) { ! 1578: printk("%s: abort, mbox %d is locked.\n", BN(j), i); ! 1579: return SUCCESS; ! 1580: } ! 1581: ! 1582: if (HD(j)->cp_stat[i] == READY || HD(j)->cp_stat[i] == ABORTING) { ! 1583: SCarg->result = DID_ABORT << 16; ! 1584: SCarg->host_scribble = NULL; ! 1585: HD(j)->cp_stat[i] = FREE; ! 1586: printk("%s, abort, mbox %d ready, DID_ABORT, pid %ld done.\n", ! 1587: BN(j), i, SCarg->pid); ! 1588: SCarg->scsi_done(SCarg); ! 1589: return SUCCESS; ! 1590: } ! 1591: ! 1592: panic("%s: abort, mbox %d, invalid cp_stat.\n", BN(j), i); ! 1593: } ! 1594: ! 1595: int eata2x_abort(Scsi_Cmnd *SCarg) { ! 1596: ! 1597: return do_abort(SCarg); ! 1598: } ! 1599: ! 1600: #endif /* new_eh_code */ ! 1601: ! 1602: static inline int do_old_reset(Scsi_Cmnd *SCarg) { ! 1603: unsigned int i, j, time, k, c, limit = 0; ! 1604: int arg_done = FALSE; ! 1605: Scsi_Cmnd *SCpnt; ! 1606: ! 1607: j = ((struct hostdata *) SCarg->host->hostdata)->board_number; ! 1608: printk("%s: reset, enter, target %d.%d:%d, pid %ld.\n", ! 1609: BN(j), SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid); ! 1610: ! 1611: if (SCarg->host_scribble == NULL) ! 1612: printk("%s: reset, pid %ld inactive.\n", BN(j), SCarg->pid); ! 1613: ! 1614: if (SCarg->serial_number_at_timeout && ! 1615: (SCarg->serial_number != SCarg->serial_number_at_timeout)) { ! 1616: printk("%s: reset, pid %ld, reset not running.\n", BN(j), SCarg->pid); ! 1617: return SCSI_RESET_NOT_RUNNING; ! 1618: } ! 1619: ! 1620: if (HD(j)->in_reset) { ! 1621: printk("%s: reset, exit, already in reset.\n", BN(j)); ! 1622: return SCSI_RESET_ERROR; ! 1623: } ! 1624: ! 1625: if (wait_on_busy(sh[j]->io_port, MAXLOOP)) { ! 1626: printk("%s: reset, exit, timeout error.\n", BN(j)); ! 1627: return SCSI_RESET_ERROR; ! 1628: } ! 1629: ! 1630: HD(j)->retries = 0; ! 1631: ! 1632: for (c = 0; c <= sh[j]->max_channel; c++) ! 1633: for (k = 0; k < sh[j]->max_id; k++) { ! 1634: HD(j)->target_redo[k][c] = TRUE; ! 1635: HD(j)->target_to[k][c] = 0; ! 1636: } ! 1637: ! 1638: for (i = 0; i < sh[j]->can_queue; i++) { ! 1639: ! 1640: if (HD(j)->cp_stat[i] == FREE) continue; ! 1641: ! 1642: if (HD(j)->cp_stat[i] == LOCKED) { ! 1643: HD(j)->cp_stat[i] = FREE; ! 1644: printk("%s: reset, locked mbox %d forced free.\n", BN(j), i); ! 1645: continue; ! 1646: } ! 1647: ! 1648: if (!(SCpnt = HD(j)->cp[i].SCpnt)) ! 1649: panic("%s: reset, mbox %d, SCpnt == NULL.\n", BN(j), i); ! 1650: ! 1651: if (HD(j)->cp_stat[i] == READY || HD(j)->cp_stat[i] == ABORTING) { ! 1652: HD(j)->cp_stat[i] = ABORTING; ! 1653: printk("%s: reset, mbox %d aborting, pid %ld.\n", ! 1654: BN(j), i, SCpnt->pid); ! 1655: } ! 1656: ! 1657: else { ! 1658: HD(j)->cp_stat[i] = IN_RESET; ! 1659: printk("%s: reset, mbox %d in reset, pid %ld.\n", ! 1660: BN(j), i, SCpnt->pid); ! 1661: } ! 1662: ! 1663: if (SCpnt->host_scribble == NULL) ! 1664: panic("%s: reset, mbox %d, garbled SCpnt.\n", BN(j), i); ! 1665: ! 1666: if (*(unsigned int *)SCpnt->host_scribble != i) ! 1667: panic("%s: reset, mbox %d, index mismatch.\n", BN(j), i); ! 1668: ! 1669: if (SCpnt->scsi_done == NULL) ! 1670: panic("%s: reset, mbox %d, SCpnt->scsi_done == NULL.\n", BN(j), i); ! 1671: ! 1672: if (SCpnt == SCarg) arg_done = TRUE; ! 1673: } ! 1674: ! 1675: if (do_dma(sh[j]->io_port, 0, RESET_PIO)) { ! 1676: printk("%s: reset, cannot reset, timeout error.\n", BN(j)); ! 1677: return SCSI_RESET_ERROR; ! 1678: } ! 1679: ! 1680: printk("%s: reset, board reset done, enabling interrupts.\n", BN(j)); ! 1681: ! 1682: #if defined(DEBUG_RESET) ! 1683: do_trace = TRUE; ! 1684: #endif ! 1685: ! 1686: HD(j)->in_reset = TRUE; ! 1687: SPIN_UNLOCK ! 1688: IRQ_UNLOCK ! 1689: time = jiffies; ! 1690: while ((jiffies - time) < (10 * HZ) && limit++ < 200000) udelay(100L); ! 1691: IRQ_LOCK ! 1692: SPIN_LOCK ! 1693: printk("%s: reset, interrupts disabled, loops %d.\n", BN(j), limit); ! 1694: ! 1695: for (i = 0; i < sh[j]->can_queue; i++) { ! 1696: ! 1697: if (HD(j)->cp_stat[i] == IN_RESET) { ! 1698: SCpnt = HD(j)->cp[i].SCpnt; ! 1699: SCpnt->result = DID_RESET << 16; ! 1700: SCpnt->host_scribble = NULL; ! 1701: ! 1702: /* This mailbox is still waiting for its interrupt */ ! 1703: HD(j)->cp_stat[i] = LOCKED; ! 1704: ! 1705: printk("%s, reset, mbox %d locked, DID_RESET, pid %ld done.\n", ! 1706: BN(j), i, SCpnt->pid); ! 1707: } ! 1708: ! 1709: else if (HD(j)->cp_stat[i] == ABORTING) { ! 1710: SCpnt = HD(j)->cp[i].SCpnt; ! 1711: SCpnt->result = DID_RESET << 16; ! 1712: SCpnt->host_scribble = NULL; ! 1713: ! 1714: /* This mailbox was never queued to the adapter */ ! 1715: HD(j)->cp_stat[i] = FREE; ! 1716: ! 1717: printk("%s, reset, mbox %d aborting, DID_RESET, pid %ld done.\n", ! 1718: BN(j), i, SCpnt->pid); ! 1719: } ! 1720: ! 1721: else ! 1722: ! 1723: /* Any other mailbox has already been set free by interrupt */ ! 1724: continue; ! 1725: ! 1726: SCpnt->scsi_done(SCpnt); ! 1727: IRQ_LOCK ! 1728: } ! 1729: ! 1730: HD(j)->in_reset = FALSE; ! 1731: do_trace = FALSE; ! 1732: ! 1733: if (arg_done) { ! 1734: printk("%s: reset, exit, success.\n", BN(j)); ! 1735: return SCSI_RESET_SUCCESS; ! 1736: } ! 1737: else { ! 1738: printk("%s: reset, exit, wakeup.\n", BN(j)); ! 1739: return SCSI_RESET_PUNT; ! 1740: } ! 1741: } ! 1742: ! 1743: int eata2x_old_reset(Scsi_Cmnd *SCarg, unsigned int reset_flags) { ! 1744: int rtn; ! 1745: IRQ_FLAGS ! 1746: ! 1747: IRQ_LOCK_SAVE ! 1748: rtn = do_old_reset(SCarg); ! 1749: IRQ_UNLOCK_RESTORE ! 1750: return rtn; ! 1751: } ! 1752: ! 1753: #if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,101) ! 1754: ! 1755: static inline int do_reset(Scsi_Cmnd *SCarg) { ! 1756: unsigned int i, j, time, k, c, limit = 0; ! 1757: int arg_done = FALSE; ! 1758: Scsi_Cmnd *SCpnt; ! 1759: ! 1760: j = ((struct hostdata *) SCarg->host->hostdata)->board_number; ! 1761: printk("%s: reset, enter, target %d.%d:%d, pid %ld.\n", ! 1762: BN(j), SCarg->channel, SCarg->target, SCarg->lun, SCarg->pid); ! 1763: ! 1764: if (SCarg->host_scribble == NULL) ! 1765: printk("%s: reset, pid %ld inactive.\n", BN(j), SCarg->pid); ! 1766: ! 1767: if (HD(j)->in_reset) { ! 1768: printk("%s: reset, exit, already in reset.\n", BN(j)); ! 1769: return FAILED; ! 1770: } ! 1771: ! 1772: if (wait_on_busy(sh[j]->io_port, MAXLOOP)) { ! 1773: printk("%s: reset, exit, timeout error.\n", BN(j)); ! 1774: return FAILED; ! 1775: } ! 1776: ! 1777: HD(j)->retries = 0; ! 1778: ! 1779: for (c = 0; c <= sh[j]->max_channel; c++) ! 1780: for (k = 0; k < sh[j]->max_id; k++) { ! 1781: HD(j)->target_redo[k][c] = TRUE; ! 1782: HD(j)->target_to[k][c] = 0; ! 1783: } ! 1784: ! 1785: for (i = 0; i < sh[j]->can_queue; i++) { ! 1786: ! 1787: if (HD(j)->cp_stat[i] == FREE) continue; ! 1788: ! 1789: if (HD(j)->cp_stat[i] == LOCKED) { ! 1790: HD(j)->cp_stat[i] = FREE; ! 1791: printk("%s: reset, locked mbox %d forced free.\n", BN(j), i); ! 1792: continue; ! 1793: } ! 1794: ! 1795: if (!(SCpnt = HD(j)->cp[i].SCpnt)) ! 1796: panic("%s: reset, mbox %d, SCpnt == NULL.\n", BN(j), i); ! 1797: ! 1798: if (HD(j)->cp_stat[i] == READY || HD(j)->cp_stat[i] == ABORTING) { ! 1799: HD(j)->cp_stat[i] = ABORTING; ! 1800: printk("%s: reset, mbox %d aborting, pid %ld.\n", ! 1801: BN(j), i, SCpnt->pid); ! 1802: } ! 1803: ! 1804: else { ! 1805: HD(j)->cp_stat[i] = IN_RESET; ! 1806: printk("%s: reset, mbox %d in reset, pid %ld.\n", ! 1807: BN(j), i, SCpnt->pid); ! 1808: } ! 1809: ! 1810: if (SCpnt->host_scribble == NULL) ! 1811: panic("%s: reset, mbox %d, garbled SCpnt.\n", BN(j), i); ! 1812: ! 1813: if (*(unsigned int *)SCpnt->host_scribble != i) ! 1814: panic("%s: reset, mbox %d, index mismatch.\n", BN(j), i); ! 1815: ! 1816: if (SCpnt->scsi_done == NULL) ! 1817: panic("%s: reset, mbox %d, SCpnt->scsi_done == NULL.\n", BN(j), i); ! 1818: ! 1819: if (SCpnt == SCarg) arg_done = TRUE; ! 1820: } ! 1821: ! 1822: if (do_dma(sh[j]->io_port, 0, RESET_PIO)) { ! 1823: printk("%s: reset, cannot reset, timeout error.\n", BN(j)); ! 1824: return FAILED; ! 1825: } ! 1826: ! 1827: printk("%s: reset, board reset done, enabling interrupts.\n", BN(j)); ! 1828: ! 1829: #if defined(DEBUG_RESET) ! 1830: do_trace = TRUE; ! 1831: #endif ! 1832: ! 1833: HD(j)->in_reset = TRUE; ! 1834: SPIN_UNLOCK ! 1835: IRQ_UNLOCK ! 1836: time = jiffies; ! 1837: while ((jiffies - time) < (10 * HZ) && limit++ < 200000) udelay(100L); ! 1838: IRQ_LOCK ! 1839: SPIN_LOCK ! 1840: printk("%s: reset, interrupts disabled, loops %d.\n", BN(j), limit); ! 1841: ! 1842: for (i = 0; i < sh[j]->can_queue; i++) { ! 1843: ! 1844: if (HD(j)->cp_stat[i] == IN_RESET) { ! 1845: SCpnt = HD(j)->cp[i].SCpnt; ! 1846: SCpnt->result = DID_RESET << 16; ! 1847: SCpnt->host_scribble = NULL; ! 1848: ! 1849: /* This mailbox is still waiting for its interrupt */ ! 1850: HD(j)->cp_stat[i] = LOCKED; ! 1851: ! 1852: printk("%s, reset, mbox %d locked, DID_RESET, pid %ld done.\n", ! 1853: BN(j), i, SCpnt->pid); ! 1854: } ! 1855: ! 1856: else if (HD(j)->cp_stat[i] == ABORTING) { ! 1857: SCpnt = HD(j)->cp[i].SCpnt; ! 1858: SCpnt->result = DID_RESET << 16; ! 1859: SCpnt->host_scribble = NULL; ! 1860: ! 1861: /* This mailbox was never queued to the adapter */ ! 1862: HD(j)->cp_stat[i] = FREE; ! 1863: ! 1864: printk("%s, reset, mbox %d aborting, DID_RESET, pid %ld done.\n", ! 1865: BN(j), i, SCpnt->pid); ! 1866: } ! 1867: ! 1868: else ! 1869: ! 1870: /* Any other mailbox has already been set free by interrupt */ ! 1871: continue; ! 1872: ! 1873: SCpnt->scsi_done(SCpnt); ! 1874: IRQ_LOCK ! 1875: } ! 1876: ! 1877: HD(j)->in_reset = FALSE; ! 1878: do_trace = FALSE; ! 1879: ! 1880: if (arg_done) printk("%s: reset, exit, pid %ld done.\n", BN(j), SCarg->pid); ! 1881: else printk("%s: reset, exit.\n", BN(j)); ! 1882: ! 1883: return SUCCESS; ! 1884: } ! 1885: ! 1886: int eata2x_reset(Scsi_Cmnd *SCarg) { ! 1887: ! 1888: return do_reset(SCarg); ! 1889: } ! 1890: ! 1891: #endif /* new_eh_code */ ! 1892: ! 1893: int eata2x_biosparam(Disk *disk, kdev_t dev, int *dkinfo) { ! 1894: int size = disk->capacity; ! 1895: ! 1896: if (ext_tran || (scsicam_bios_param(disk, dev, dkinfo) < 0)) { ! 1897: dkinfo[0] = 255; ! 1898: dkinfo[1] = 63; ! 1899: dkinfo[2] = size / (dkinfo[0] * dkinfo[1]); ! 1900: } ! 1901: ! 1902: #if defined (DEBUG_GEOMETRY) ! 1903: printk ("%s: biosparam, head=%d, sec=%d, cyl=%d.\n", driver_name, ! 1904: dkinfo[0], dkinfo[1], dkinfo[2]); ! 1905: #endif ! 1906: ! 1907: return FALSE; ! 1908: } ! 1909: ! 1910: static void sort(unsigned long sk[], unsigned int da[], unsigned int n, ! 1911: unsigned int rev) { ! 1912: unsigned int i, j, k, y; ! 1913: unsigned long x; ! 1914: ! 1915: for (i = 0; i < n - 1; i++) { ! 1916: k = i; ! 1917: ! 1918: for (j = k + 1; j < n; j++) ! 1919: if (rev) { ! 1920: if (sk[j] > sk[k]) k = j; ! 1921: } ! 1922: else { ! 1923: if (sk[j] < sk[k]) k = j; ! 1924: } ! 1925: ! 1926: if (k != i) { ! 1927: x = sk[k]; sk[k] = sk[i]; sk[i] = x; ! 1928: y = da[k]; da[k] = da[i]; da[i] = y; ! 1929: } ! 1930: } ! 1931: ! 1932: return; ! 1933: } ! 1934: ! 1935: static inline int reorder(unsigned int j, unsigned long cursec, ! 1936: unsigned int ihdlr, unsigned int il[], unsigned int n_ready) { ! 1937: Scsi_Cmnd *SCpnt; ! 1938: struct mscp *cpp; ! 1939: unsigned int k, n; ! 1940: unsigned int rev = FALSE, s = TRUE, r = TRUE; ! 1941: unsigned int input_only = TRUE, overlap = FALSE; ! 1942: unsigned long sl[n_ready], pl[n_ready], ll[n_ready]; ! 1943: unsigned long maxsec = 0, minsec = ULONG_MAX, seek = 0, iseek = 0; ! 1944: unsigned long ioseek = 0; ! 1945: ! 1946: static unsigned int flushcount = 0, batchcount = 0, sortcount = 0; ! 1947: static unsigned int readycount = 0, ovlcount = 0, inputcount = 0; ! 1948: static unsigned int readysorted = 0, revcount = 0; ! 1949: static unsigned long seeksorted = 0, seeknosort = 0; ! 1950: ! 1951: if (link_statistics && !(++flushcount % link_statistics)) ! 1952: printk("fc %d bc %d ic %d oc %d rc %d rs %d sc %d re %d"\ ! 1953: " av %ldK as %ldK.\n", flushcount, batchcount, inputcount, ! 1954: ovlcount, readycount, readysorted, sortcount, revcount, ! 1955: seeknosort / (readycount + 1), ! 1956: seeksorted / (readycount + 1)); ! 1957: ! 1958: if (n_ready <= 1) return FALSE; ! 1959: ! 1960: for (n = 0; n < n_ready; n++) { ! 1961: k = il[n]; cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt; ! 1962: ! 1963: if (!cpp->din) input_only = FALSE; ! 1964: ! 1965: if (SCpnt->request.sector < minsec) minsec = SCpnt->request.sector; ! 1966: if (SCpnt->request.sector > maxsec) maxsec = SCpnt->request.sector; ! 1967: ! 1968: sl[n] = SCpnt->request.sector; ! 1969: ioseek += SCpnt->request.nr_sectors; ! 1970: ! 1971: if (!n) continue; ! 1972: ! 1973: if (sl[n] < sl[n - 1]) s = FALSE; ! 1974: if (sl[n] > sl[n - 1]) r = FALSE; ! 1975: ! 1976: if (link_statistics) { ! 1977: if (sl[n] > sl[n - 1]) ! 1978: seek += sl[n] - sl[n - 1]; ! 1979: else ! 1980: seek += sl[n - 1] - sl[n]; ! 1981: } ! 1982: ! 1983: } ! 1984: ! 1985: if (link_statistics) { ! 1986: if (cursec > sl[0]) seek += cursec - sl[0]; else seek += sl[0] - cursec; ! 1987: } ! 1988: ! 1989: if (cursec > ((maxsec + minsec) / 2)) rev = TRUE; ! 1990: ! 1991: if (ioseek > ((maxsec - minsec) / 2)) rev = FALSE; ! 1992: ! 1993: if (!((rev && r) || (!rev && s))) sort(sl, il, n_ready, rev); ! 1994: ! 1995: if (!input_only) for (n = 0; n < n_ready; n++) { ! 1996: k = il[n]; cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt; ! 1997: ll[n] = SCpnt->request.nr_sectors; pl[n] = SCpnt->pid; ! 1998: ! 1999: if (!n) continue; ! 2000: ! 2001: if ((sl[n] == sl[n - 1]) || (!rev && ((sl[n - 1] + ll[n - 1]) > sl[n])) ! 2002: || (rev && ((sl[n] + ll[n]) > sl[n - 1]))) overlap = TRUE; ! 2003: } ! 2004: ! 2005: if (overlap) sort(pl, il, n_ready, FALSE); ! 2006: ! 2007: if (link_statistics) { ! 2008: if (cursec > sl[0]) iseek = cursec - sl[0]; else iseek = sl[0] - cursec; ! 2009: batchcount++; readycount += n_ready, seeknosort += seek / 1024; ! 2010: if (input_only) inputcount++; ! 2011: if (overlap) { ovlcount++; seeksorted += iseek / 1024; } ! 2012: else seeksorted += (iseek + maxsec - minsec) / 1024; ! 2013: if (rev && !r) { revcount++; readysorted += n_ready; } ! 2014: if (!rev && !s) { sortcount++; readysorted += n_ready; } ! 2015: } ! 2016: ! 2017: #if defined(DEBUG_LINKED_COMMANDS) ! 2018: if (link_statistics && (overlap || !(flushcount % link_statistics))) ! 2019: for (n = 0; n < n_ready; n++) { ! 2020: k = il[n]; cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt; ! 2021: printk("%s %d.%d:%d pid %ld mb %d fc %d nr %d sec %ld ns %ld"\ ! 2022: " cur %ld s:%c r:%c rev:%c in:%c ov:%c xd %d.\n", ! 2023: (ihdlr ? "ihdlr" : "qcomm"), SCpnt->channel, SCpnt->target, ! 2024: SCpnt->lun, SCpnt->pid, k, flushcount, n_ready, ! 2025: SCpnt->request.sector, SCpnt->request.nr_sectors, cursec, ! 2026: YESNO(s), YESNO(r), YESNO(rev), YESNO(input_only), ! 2027: YESNO(overlap), cpp->din); ! 2028: } ! 2029: #endif ! 2030: return overlap; ! 2031: } ! 2032: ! 2033: static void flush_dev(Scsi_Device *dev, unsigned long cursec, unsigned int j, ! 2034: unsigned int ihdlr) { ! 2035: Scsi_Cmnd *SCpnt; ! 2036: struct mscp *cpp; ! 2037: unsigned int k, n, n_ready = 0, il[MAX_MAILBOXES]; ! 2038: ! 2039: for (k = 0; k < sh[j]->can_queue; k++) { ! 2040: ! 2041: if (HD(j)->cp_stat[k] != READY && HD(j)->cp_stat[k] != IN_USE) continue; ! 2042: ! 2043: cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt; ! 2044: ! 2045: if (SCpnt->device != dev) continue; ! 2046: ! 2047: if (HD(j)->cp_stat[k] == IN_USE) return; ! 2048: ! 2049: il[n_ready++] = k; ! 2050: } ! 2051: ! 2052: if (reorder(j, cursec, ihdlr, il, n_ready)) n_ready = 1; ! 2053: ! 2054: for (n = 0; n < n_ready; n++) { ! 2055: k = il[n]; cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt; ! 2056: ! 2057: if (do_dma(sh[j]->io_port, (unsigned int) cpp, SEND_CP_DMA)) { ! 2058: printk("%s: %s, target %d.%d:%d, pid %ld, mbox %d, adapter"\ ! 2059: " busy, will abort.\n", BN(j), (ihdlr ? "ihdlr" : "qcomm"), ! 2060: SCpnt->channel, SCpnt->target, SCpnt->lun, SCpnt->pid, k); ! 2061: HD(j)->cp_stat[k] = ABORTING; ! 2062: continue; ! 2063: } ! 2064: ! 2065: HD(j)->cp_stat[k] = IN_USE; ! 2066: } ! 2067: ! 2068: } ! 2069: ! 2070: static inline void ihdlr(int irq, unsigned int j) { ! 2071: Scsi_Cmnd *SCpnt; ! 2072: unsigned int i, k, c, status, tstatus, reg; ! 2073: struct mssp *dspp, *spp; ! 2074: struct mscp *cpp; ! 2075: ! 2076: if (sh[j]->irq != irq) ! 2077: panic("%s: ihdlr, irq %d, sh[j]->irq %d.\n", BN(j), irq, sh[j]->irq); ! 2078: ! 2079: /* Check if this board need to be serviced */ ! 2080: if (!(inb(sh[j]->io_port + REG_AUX_STATUS) & IRQ_ASSERTED)) return; ! 2081: ! 2082: HD(j)->iocount++; ! 2083: ! 2084: if (do_trace) printk("%s: ihdlr, enter, irq %d, count %d.\n", BN(j), irq, ! 2085: HD(j)->iocount); ! 2086: ! 2087: /* Check if this board is still busy */ ! 2088: if (wait_on_busy(sh[j]->io_port, 20 * MAXLOOP)) { ! 2089: reg = inb(sh[j]->io_port + REG_STATUS); ! 2090: printk("%s: ihdlr, busy timeout error, irq %d, reg 0x%x, count %d.\n", ! 2091: BN(j), irq, reg, HD(j)->iocount); ! 2092: return; ! 2093: } ! 2094: ! 2095: dspp = &HD(j)->sp[0]; ! 2096: spp = &HD(j)->sp[1]; ! 2097: ! 2098: /* Make a local copy just before clearing the interrupt indication */ ! 2099: memcpy(spp, dspp, sizeof(struct mssp)); ! 2100: ! 2101: /* Clear the completion flag and cp pointer on the dynamic copy of sp */ ! 2102: memset(dspp, 0, sizeof(struct mssp)); ! 2103: ! 2104: /* Read the status register to clear the interrupt indication */ ! 2105: reg = inb(sh[j]->io_port + REG_STATUS); ! 2106: ! 2107: /* Reject any sp with supspect data */ ! 2108: if (spp->eoc == FALSE) ! 2109: printk("%s: ihdlr, spp->eoc == FALSE, irq %d, reg 0x%x, count %d.\n", ! 2110: BN(j), irq, reg, HD(j)->iocount); ! 2111: if (spp->cpp == NULL) ! 2112: printk("%s: ihdlr, spp->cpp == NULL, irq %d, reg 0x%x, count %d.\n", ! 2113: BN(j), irq, reg, HD(j)->iocount); ! 2114: if (spp->eoc == FALSE || spp->cpp == NULL) return; ! 2115: ! 2116: cpp = spp->cpp; ! 2117: ! 2118: #if defined(DEBUG_GENERATE_ABORTS) ! 2119: if ((HD(j)->iocount > 500) && ((HD(j)->iocount % 500) < 3)) return; ! 2120: #endif ! 2121: ! 2122: /* Find the mailbox to be serviced on this board */ ! 2123: i = cpp - HD(j)->cp; ! 2124: ! 2125: if (cpp < HD(j)->cp || cpp >= HD(j)->cp + sh[j]->can_queue ! 2126: || i >= sh[j]->can_queue) ! 2127: panic("%s: ihdlr, invalid mscp bus address %p, cp0 %p.\n", BN(j), ! 2128: cpp, HD(j)->cp); ! 2129: ! 2130: if (HD(j)->cp_stat[i] == IGNORE) { ! 2131: HD(j)->cp_stat[i] = FREE; ! 2132: return; ! 2133: } ! 2134: else if (HD(j)->cp_stat[i] == LOCKED) { ! 2135: HD(j)->cp_stat[i] = FREE; ! 2136: printk("%s: ihdlr, mbox %d unlocked, count %d.\n", BN(j), i, ! 2137: HD(j)->iocount); ! 2138: return; ! 2139: } ! 2140: else if (HD(j)->cp_stat[i] == FREE) { ! 2141: printk("%s: ihdlr, mbox %d is free, count %d.\n", BN(j), i, ! 2142: HD(j)->iocount); ! 2143: return; ! 2144: } ! 2145: else if (HD(j)->cp_stat[i] == IN_RESET) ! 2146: printk("%s: ihdlr, mbox %d is in reset.\n", BN(j), i); ! 2147: else if (HD(j)->cp_stat[i] != IN_USE) ! 2148: panic("%s: ihdlr, mbox %d, invalid cp_stat: %d.\n", ! 2149: BN(j), i, HD(j)->cp_stat[i]); ! 2150: ! 2151: HD(j)->cp_stat[i] = FREE; ! 2152: SCpnt = cpp->SCpnt; ! 2153: ! 2154: if (SCpnt == NULL) panic("%s: ihdlr, mbox %d, SCpnt == NULL.\n", BN(j), i); ! 2155: ! 2156: if (SCpnt->host_scribble == NULL) ! 2157: panic("%s: ihdlr, mbox %d, pid %ld, SCpnt %p garbled.\n", BN(j), i, ! 2158: SCpnt->pid, SCpnt); ! 2159: ! 2160: if (*(unsigned int *)SCpnt->host_scribble != i) ! 2161: panic("%s: ihdlr, mbox %d, pid %ld, index mismatch %d.\n", ! 2162: BN(j), i, SCpnt->pid, *(unsigned int *)SCpnt->host_scribble); ! 2163: ! 2164: if (linked_comm && SCpnt->device->queue_depth > 2 ! 2165: && TLDEV(SCpnt->device->type)) ! 2166: flush_dev(SCpnt->device, SCpnt->request.sector, j, TRUE); ! 2167: ! 2168: tstatus = status_byte(spp->target_status); ! 2169: ! 2170: #if defined(DEBUG_GENERATE_ERRORS) ! 2171: if ((HD(j)->iocount > 500) && ((HD(j)->iocount % 200) < 2)) ! 2172: spp->adapter_status = 0x01; ! 2173: #endif ! 2174: ! 2175: switch (spp->adapter_status) { ! 2176: case ASOK: /* status OK */ ! 2177: ! 2178: /* Forces a reset if a disk drive keeps returning BUSY */ ! 2179: if (tstatus == BUSY && SCpnt->device->type != TYPE_TAPE) ! 2180: status = DID_ERROR << 16; ! 2181: ! 2182: /* If there was a bus reset, redo operation on each target */ ! 2183: else if (tstatus != GOOD && SCpnt->device->type == TYPE_DISK ! 2184: && HD(j)->target_redo[SCpnt->target][SCpnt->channel]) ! 2185: status = DID_BUS_BUSY << 16; ! 2186: ! 2187: /* Works around a flaw in scsi.c */ ! 2188: else if (tstatus == CHECK_CONDITION ! 2189: && SCpnt->device->type == TYPE_DISK ! 2190: && (SCpnt->sense_buffer[2] & 0xf) == RECOVERED_ERROR) ! 2191: status = DID_BUS_BUSY << 16; ! 2192: ! 2193: else ! 2194: status = DID_OK << 16; ! 2195: ! 2196: if (tstatus == GOOD) ! 2197: HD(j)->target_redo[SCpnt->target][SCpnt->channel] = FALSE; ! 2198: ! 2199: if (spp->target_status && SCpnt->device->type == TYPE_DISK) ! 2200: printk("%s: ihdlr, target %d.%d:%d, pid %ld, "\ ! 2201: "target_status 0x%x, sense key 0x%x.\n", BN(j), ! 2202: SCpnt->channel, SCpnt->target, SCpnt->lun, ! 2203: SCpnt->pid, spp->target_status, ! 2204: SCpnt->sense_buffer[2]); ! 2205: ! 2206: HD(j)->target_to[SCpnt->target][SCpnt->channel] = 0; ! 2207: ! 2208: if (HD(j)->last_retried_pid == SCpnt->pid) HD(j)->retries = 0; ! 2209: ! 2210: break; ! 2211: case ASST: /* Selection Time Out */ ! 2212: case 0x02: /* Command Time Out */ ! 2213: ! 2214: if (HD(j)->target_to[SCpnt->target][SCpnt->channel] > 1) ! 2215: status = DID_ERROR << 16; ! 2216: else { ! 2217: status = DID_TIME_OUT << 16; ! 2218: HD(j)->target_to[SCpnt->target][SCpnt->channel]++; ! 2219: } ! 2220: ! 2221: break; ! 2222: ! 2223: /* Perform a limited number of internal retries */ ! 2224: case 0x03: /* SCSI Bus Reset Received */ ! 2225: case 0x04: /* Initial Controller Power-up */ ! 2226: ! 2227: for (c = 0; c <= sh[j]->max_channel; c++) ! 2228: for (k = 0; k < sh[j]->max_id; k++) ! 2229: HD(j)->target_redo[k][c] = TRUE; ! 2230: ! 2231: if (SCpnt->device->type != TYPE_TAPE ! 2232: && HD(j)->retries < MAX_INTERNAL_RETRIES) { ! 2233: ! 2234: #if defined(DID_SOFT_ERROR) ! 2235: status = DID_SOFT_ERROR << 16; ! 2236: #else ! 2237: status = DID_BUS_BUSY << 16; ! 2238: #endif ! 2239: HD(j)->retries++; ! 2240: HD(j)->last_retried_pid = SCpnt->pid; ! 2241: } ! 2242: else ! 2243: status = DID_ERROR << 16; ! 2244: ! 2245: break; ! 2246: case 0x05: /* Unexpected Bus Phase */ ! 2247: case 0x06: /* Unexpected Bus Free */ ! 2248: case 0x07: /* Bus Parity Error */ ! 2249: case 0x08: /* SCSI Hung */ ! 2250: case 0x09: /* Unexpected Message Reject */ ! 2251: case 0x0a: /* SCSI Bus Reset Stuck */ ! 2252: case 0x0b: /* Auto Request-Sense Failed */ ! 2253: case 0x0c: /* Controller Ram Parity Error */ ! 2254: default: ! 2255: status = DID_ERROR << 16; ! 2256: break; ! 2257: } ! 2258: ! 2259: SCpnt->result = status | spp->target_status; ! 2260: ! 2261: #if defined(DEBUG_INTERRUPT) ! 2262: if (SCpnt->result || do_trace) ! 2263: #else ! 2264: if ((spp->adapter_status != ASOK && HD(j)->iocount > 1000) || ! 2265: (spp->adapter_status != ASOK && ! 2266: spp->adapter_status != ASST && HD(j)->iocount <= 1000) || ! 2267: do_trace || msg_byte(spp->target_status)) ! 2268: #endif ! 2269: printk("%s: ihdlr, mbox %2d, err 0x%x:%x,"\ ! 2270: " target %d.%d:%d, pid %ld, reg 0x%x, count %d.\n", ! 2271: BN(j), i, spp->adapter_status, spp->target_status, ! 2272: SCpnt->channel, SCpnt->target, SCpnt->lun, SCpnt->pid, ! 2273: reg, HD(j)->iocount); ! 2274: ! 2275: /* Set the command state to inactive */ ! 2276: SCpnt->host_scribble = NULL; ! 2277: ! 2278: SCpnt->scsi_done(SCpnt); ! 2279: ! 2280: if (do_trace) printk("%s: ihdlr, exit, irq %d, count %d.\n", BN(j), irq, ! 2281: HD(j)->iocount); ! 2282: ! 2283: return; ! 2284: } ! 2285: ! 2286: static void do_interrupt_handler(int irq, void *shap, struct pt_regs *regs) { ! 2287: unsigned int j; ! 2288: IRQ_FLAGS ! 2289: SPIN_FLAGS ! 2290: ! 2291: /* Check if the interrupt must be processed by this handler */ ! 2292: if ((j = (unsigned int)((char *)shap - sha)) >= num_boards) return; ! 2293: ! 2294: SPIN_LOCK_SAVE ! 2295: IRQ_LOCK_SAVE ! 2296: ihdlr(irq, j); ! 2297: IRQ_UNLOCK_RESTORE ! 2298: SPIN_UNLOCK_RESTORE ! 2299: } ! 2300: ! 2301: int eata2x_release(struct Scsi_Host *shpnt) { ! 2302: unsigned int i, j; ! 2303: IRQ_FLAGS ! 2304: ! 2305: IRQ_LOCK_SAVE ! 2306: ! 2307: for (j = 0; sh[j] != NULL && sh[j] != shpnt; j++); ! 2308: ! 2309: if (sh[j] == NULL) panic("%s: release, invalid Scsi_Host pointer.\n", ! 2310: driver_name); ! 2311: ! 2312: for (i = 0; i < sh[j]->can_queue; i++) ! 2313: if ((&HD(j)->cp[i])->sglist) kfree((&HD(j)->cp[i])->sglist); ! 2314: ! 2315: free_irq(sh[j]->irq, &sha[j]); ! 2316: ! 2317: if (sh[j]->dma_channel != NO_DMA) free_dma(sh[j]->dma_channel); ! 2318: ! 2319: release_region(sh[j]->io_port, sh[j]->n_io_port); ! 2320: scsi_unregister(sh[j]); ! 2321: IRQ_UNLOCK_RESTORE ! 2322: return FALSE; ! 2323: } ! 2324: ! 2325: #if defined(MODULE) ! 2326: Scsi_Host_Template driver_template = EATA; ! 2327: ! 2328: #include "scsi_module.c" ! 2329: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.