···3434 See drivers/scsi/BusLogic.c, comment before function3535 BusLogic_ParseDriverOptions().36363737- eata= [HW,SCSI]3838-3937 fdomain= [HW,SCSI]4038 See header of drivers/scsi/fdomain.c.4139
-6
MAINTAINERS
···50035003S: Maintained50045004F: drivers/media/tuners/e4000*5005500550065006-EATA ISA/EISA/PCI SCSI DRIVER50075007-M: Dario Ballabio <ballabio_dario@emc.com>50085008-L: linux-scsi@vger.kernel.org50095009-S: Maintained50105010-F: drivers/scsi/eata.c50115011-50125006EC100 MEDIA DRIVER50135007M: Antti Palosaari <crope@iki.fi>50145008L: linux-media@vger.kernel.org
-62
drivers/scsi/Kconfig
···640640 To compile this driver as a module, choose M here: the641641 module will be called dmx3191d.642642643643-config SCSI_EATA644644- tristate "EATA ISA/EISA/PCI (DPT and generic EATA/DMA-compliant boards) support"645645- depends on (ISA || EISA || PCI) && SCSI && ISA_DMA_API646646- ---help---647647- This driver supports all EATA/DMA-compliant SCSI host adapters. DPT648648- ISA and all EISA I/O addresses are probed looking for the "EATA"649649- signature. The addresses of all the PCI SCSI controllers reported650650- by the PCI subsystem are probed as well.651651-652652- You want to read the start of <file:drivers/scsi/eata.c> and the653653- SCSI-HOWTO, available from654654- <http://www.tldp.org/docs.html#howto>.655655-656656- To compile this driver as a module, choose M here: the657657- module will be called eata.658658-659659-config SCSI_EATA_TAGGED_QUEUE660660- bool "enable tagged command queueing"661661- depends on SCSI_EATA662662- help663663- This is a feature of SCSI-2 which improves performance: the host664664- adapter can send several SCSI commands to a device's queue even if665665- previous commands haven't finished yet.666666- This is equivalent to the "eata=tc:y" boot option.667667-668668-config SCSI_EATA_LINKED_COMMANDS669669- bool "enable elevator sorting"670670- depends on SCSI_EATA671671- help672672- This option enables elevator sorting for all probed SCSI disks and673673- CD-ROMs. It definitely reduces the average seek distance when doing674674- random seeks, but this does not necessarily result in a noticeable675675- performance improvement: your mileage may vary...676676- This is equivalent to the "eata=lc:y" boot option.677677-678678-config SCSI_EATA_MAX_TAGS679679- int "maximum number of queued commands"680680- depends on SCSI_EATA681681- default "16"682682- help683683- This specifies how many SCSI commands can be maximally queued for684684- each probed SCSI device. You should reduce the default value of 16685685- only if you have disks with buggy or limited tagged command support.686686- Minimum is 2 and maximum is 62. This value is also the window size687687- used by the elevator sorting option above. The effective value used688688- by the driver for each probed SCSI device is reported at boot time.689689- This is equivalent to the "eata=mq:8" boot option.690690-691691-config SCSI_EATA_PIO692692- tristate "EATA-PIO (old DPT PM2001, PM2012A) support"693693- depends on (ISA || EISA || PCI) && SCSI && BROKEN694694- ---help---695695- This driver supports all EATA-PIO protocol compliant SCSI Host696696- Adapters like the DPT PM2001 and the PM2012A. EATA-DMA compliant697697- host adapters could also use this driver but are discouraged from698698- doing so, since this driver only supports hard disks and lacks699699- numerous features. You might want to have a look at the SCSI-HOWTO,700700- available from <http://www.tldp.org/docs.html#howto>.701701-702702- To compile this driver as a module, choose M here: the703703- module will be called eata_pio.704704-705643config SCSI_FUTURE_DOMAIN706644 tristate "Future Domain 16xx SCSI/AHA-2920A support"707645 depends on (ISA || PCI) && SCSI
···11-/*22- * eata.c - Low-level driver for EATA/DMA SCSI host adapters.33- *44- * 03 Jun 2003 Rev. 8.10 for linux-2.5.7055- * + Update for new IRQ API.66- * + Use "goto" when appropriate.77- * + Drop eata.h.88- * + Update for new module_param API.99- * + Module parameters can now be specified only in the1010- * same format as the kernel boot options.1111- *1212- * boot option old module param 1313- * ----------- ------------------1414- * addr,... io_port=addr,...1515- * lc:[y|n] linked_comm=[1|0]1616- * mq:xx max_queue_depth=xx1717- * tm:[0|1|2] tag_mode=[0|1|2]1818- * et:[y|n] ext_tran=[1|0]1919- * rs:[y|n] rev_scan=[1|0]2020- * ip:[y|n] isa_probe=[1|0]2121- * ep:[y|n] eisa_probe=[1|0]2222- * pp:[y|n] pci_probe=[1|0]2323- *2424- * A valid example using the new parameter format is:2525- * modprobe eata "eata=0x7410,0x230,lc:y,tm:0,mq:4,ep:n"2626- *2727- * which is equivalent to the old format:2828- * modprobe eata io_port=0x7410,0x230 linked_comm=1 tag_mode=0 \2929- * max_queue_depth=4 eisa_probe=03030- *3131- * 12 Feb 2003 Rev. 8.04 for linux 2.5.603232- * + Release irq before calling scsi_register.3333- *3434- * 12 Nov 2002 Rev. 8.02 for linux 2.5.473535- * + Release driver_lock before calling scsi_register.3636- *3737- * 11 Nov 2002 Rev. 8.01 for linux 2.5.473838- * + Fixed bios_param and scsicam_bios_param calling parameters.3939- *4040- * 28 Oct 2002 Rev. 8.00 for linux 2.5.44-ac44141- * + Use new tcq and adjust_queue_depth api.4242- * + New command line option (tm:[0-2]) to choose the type of tags:4343- * 0 -> disable tagging ; 1 -> simple tags ; 2 -> ordered tags.4444- * Default is tm:0 (tagged commands disabled).4545- * For compatibility the "tc:" option is an alias of the "tm:"4646- * option; tc:n is equivalent to tm:0 and tc:y is equivalent to4747- * tm:1.4848- * + The tagged_comm module parameter has been removed, use tag_mode4949- * instead, equivalent to the "tm:" boot option.5050- *5151- * 10 Oct 2002 Rev. 7.70 for linux 2.5.425252- * + Foreport from revision 6.70.5353- *5454- * 25 Jun 2002 Rev. 6.70 for linux 2.4.195555- * + This release is the first one tested on a Big Endian platform:5656- * fixed endian-ness problem due to bitfields;5757- * fixed endian-ness problem in read_pio.5858- * + Added new options for selectively probing ISA, EISA and PCI bus:5959- *6060- * Boot option Parameter name Default according to6161- *6262- * ip:[y|n] isa_probe=[1|0] CONFIG_ISA defined6363- * ep:[y|n] eisa_probe=[1|0] CONFIG_EISA defined6464- * pp:[y|n] pci_probe=[1|0] CONFIG_PCI defined6565- *6666- * The default action is to perform probing if the corresponding6767- * bus is configured and to skip probing otherwise.6868- *6969- * + If pci_probe is in effect and a list of I/O ports is specified7070- * as parameter or boot option, pci_enable_device() is performed7171- * on all pci devices matching PCI_CLASS_STORAGE_SCSI.7272- *7373- * 21 Feb 2002 Rev. 6.52 for linux 2.4.187474- * + Backport from rev. 7.22 (use io_request_lock).7575- *7676- * 20 Feb 2002 Rev. 7.22 for linux 2.5.57777- * + Remove any reference to virt_to_bus().7878- * + Fix pio hang while detecting multiple HBAs.7979- * + Fixed a board detection bug: in a system with8080- * multiple ISA/EISA boards, all but the first one8181- * were erroneously detected as PCI.8282- *8383- * 01 Jan 2002 Rev. 7.20 for linux 2.5.18484- * + Use the dynamic DMA mapping API.8585- *8686- * 19 Dec 2001 Rev. 7.02 for linux 2.5.18787- * + Use SCpnt->sc_data_direction if set.8888- * + Use sglist.page instead of sglist.address.8989- *9090- * 11 Dec 2001 Rev. 7.00 for linux 2.5.19191- * + Use host->host_lock instead of io_request_lock.9292- *9393- * 1 May 2001 Rev. 6.05 for linux 2.4.49494- * + Clean up all pci related routines.9595- * + Fix data transfer direction for opcode SEND_CUE_SHEET (0x5d)9696- *9797- * 30 Jan 2001 Rev. 6.04 for linux 2.4.19898- * + Call pci_resource_start after pci_enable_device.9999- *100100- * 25 Jan 2001 Rev. 6.03 for linux 2.4.0101101- * + "check_region" call replaced by "request_region".102102- *103103- * 22 Nov 2000 Rev. 6.02 for linux 2.4.0-test11104104- * + Return code checked when calling pci_enable_device.105105- * + Removed old scsi error handling support.106106- * + The obsolete boot option flag eh:n is silently ignored.107107- * + Removed error messages while a disk drive is powered up at108108- * boot time.109109- * + Improved boot messages: all tagged capable device are110110- * indicated as "tagged" or "soft-tagged" :111111- * - "soft-tagged" means that the driver is trying to do its112112- * own tagging (i.e. the tc:y option is in effect);113113- * - "tagged" means that the device supports tagged commands,114114- * but the driver lets the HBA be responsible for tagging115115- * support.116116- *117117- * 16 Sep 1999 Rev. 5.11 for linux 2.2.12 and 2.3.18118118- * + Updated to the new __setup interface for boot command line options.119119- * + When loaded as a module, accepts the new parameter boot_options120120- * which value is a string with the same format of the kernel boot121121- * command line options. A valid example is:122122- * modprobe eata 'boot_options="0x7410,0x230,lc:y,tc:n,mq:4"'123123- *124124- * 9 Sep 1999 Rev. 5.10 for linux 2.2.12 and 2.3.17125125- * + 64bit cleanup for Linux/Alpha platform support126126- * (contribution from H.J. Lu).127127- *128128- * 22 Jul 1999 Rev. 5.00 for linux 2.2.10 and 2.3.11129129- * + Removed pre-2.2 source code compatibility.130130- * + Added call to pci_set_master.131131- *132132- * 26 Jul 1998 Rev. 4.33 for linux 2.0.35 and 2.1.111133133- * + Added command line option (rs:[y|n]) to reverse the scan order134134- * of PCI boards. The default is rs:y, which reverses the BIOS order135135- * while registering PCI boards. The default value rs:y generates136136- * the same order of all previous revisions of this driver.137137- * Pls. note that "BIOS order" might have been reversed itself138138- * after the 2.1.9x PCI modifications in the linux kernel.139139- * The rs value is ignored when the explicit list of addresses140140- * is used by the "eata=port0,port1,..." command line option.141141- * + Added command line option (et:[y|n]) to force use of extended142142- * translation (255 heads, 63 sectors) as disk geometry.143143- * The default is et:n, which uses the disk geometry returned144144- * by scsicam_bios_param. The default value et:n is compatible with145145- * all previous revisions of this driver.146146- *147147- * 28 May 1998 Rev. 4.32 for linux 2.0.33 and 2.1.104148148- * Increased busy timeout from 10 msec. to 200 msec. while149149- * processing interrupts.150150- *151151- * 16 May 1998 Rev. 4.31 for linux 2.0.33 and 2.1.102152152- * Improved abort handling during the eh recovery process.153153- *154154- * 13 May 1998 Rev. 4.30 for linux 2.0.33 and 2.1.101155155- * The driver is now fully SMP safe, including the156156- * abort and reset routines.157157- * Added command line options (eh:[y|n]) to choose between158158- * new_eh_code and the old scsi code.159159- * If linux version >= 2.1.101 the default is eh:y, while the eh160160- * option is ignored for previous releases and the old scsi code161161- * is used.162162- *163163- * 18 Apr 1998 Rev. 4.20 for linux 2.0.33 and 2.1.97164164- * Reworked interrupt handler.165165- *166166- * 11 Apr 1998 rev. 4.05 for linux 2.0.33 and 2.1.95167167- * Major reliability improvement: when a batch with overlapping168168- * requests is detected, requests are queued one at a time169169- * eliminating any possible board or drive reordering.170170- *171171- * 10 Apr 1998 rev. 4.04 for linux 2.0.33 and 2.1.95172172- * Improved SMP support (if linux version >= 2.1.95).173173- *174174- * 9 Apr 1998 rev. 4.03 for linux 2.0.33 and 2.1.94175175- * Added support for new PCI code and IO-APIC remapping of irqs.176176- * Performance improvement: when sequential i/o is detected,177177- * always use direct sort instead of reverse sort.178178- *179179- * 4 Apr 1998 rev. 4.02 for linux 2.0.33 and 2.1.92180180- * io_port is now unsigned long.181181- *182182- * 17 Mar 1998 rev. 4.01 for linux 2.0.33 and 2.1.88183183- * Use new scsi error handling code (if linux version >= 2.1.88).184184- * Use new interrupt code.185185- *186186- * 12 Sep 1997 rev. 3.11 for linux 2.0.30 and 2.1.55187187- * Use of udelay inside the wait loops to avoid timeout188188- * problems with fast cpus.189189- * Removed check about useless calls to the interrupt service190190- * routine (reported on SMP systems only).191191- * At initialization time "sorted/unsorted" is displayed instead192192- * of "linked/unlinked" to reinforce the fact that "linking" is193193- * nothing but "elevator sorting" in the actual implementation.194194- *195195- * 17 May 1997 rev. 3.10 for linux 2.0.30 and 2.1.38196196- * Use of serial_number_at_timeout in abort and reset processing.197197- * Use of the __initfunc and __initdata macro in setup code.198198- * Minor cleanups in the list_statistics code.199199- * Increased controller busy timeout in order to better support200200- * slow SCSI devices.201201- *202202- * 24 Feb 1997 rev. 3.00 for linux 2.0.29 and 2.1.26203203- * When loading as a module, parameter passing is now supported204204- * both in 2.0 and in 2.1 style.205205- * Fixed data transfer direction for some SCSI opcodes.206206- * Immediate acknowledge to request sense commands.207207- * Linked commands to each disk device are now reordered by elevator208208- * sorting. Rare cases in which reordering of write requests could209209- * cause wrong results are managed.210210- * Fixed spurious timeouts caused by long simple queue tag sequences.211211- * New command line option (tm:[0-3]) to choose the type of tags:212212- * 0 -> mixed (default); 1 -> simple; 2 -> head; 3 -> ordered.213213- *214214- * 18 Jan 1997 rev. 2.60 for linux 2.1.21 and 2.0.28215215- * Added command line options to enable/disable linked commands216216- * (lc:[y|n]), tagged commands (tc:[y|n]) and to set the max queue217217- * depth (mq:xx). Default is "eata=lc:n,tc:n,mq:16".218218- * Improved command linking.219219- * Documented how to setup RAID-0 with DPT SmartRAID boards.220220- *221221- * 8 Jan 1997 rev. 2.50 for linux 2.1.20 and 2.0.27222222- * Added linked command support.223223- * Improved detection of PCI boards using ISA base addresses.224224- *225225- * 3 Dec 1996 rev. 2.40 for linux 2.1.14 and 2.0.27226226- * Added support for tagged commands and queue depth adjustment.227227- *228228- * 22 Nov 1996 rev. 2.30 for linux 2.1.12 and 2.0.26229229- * When CONFIG_PCI is defined, BIOS32 is used to include in the230230- * list of i/o ports to be probed all the PCI SCSI controllers.231231- * The list of i/o ports to be probed can be overwritten by the232232- * "eata=port0,port1,...." boot command line option.233233- * Scatter/gather lists are now allocated by a number of kmalloc234234- * calls, in order to avoid the previous size limit of 64Kb.235235- *236236- * 16 Nov 1996 rev. 2.20 for linux 2.1.10 and 2.0.25237237- * Added support for EATA 2.0C, PCI, multichannel and wide SCSI.238238- *239239- * 27 Sep 1996 rev. 2.12 for linux 2.1.0240240- * Portability cleanups (virtual/bus addressing, little/big endian241241- * support).242242- *243243- * 09 Jul 1996 rev. 2.11 for linux 2.0.4244244- * Number of internal retries is now limited.245245- *246246- * 16 Apr 1996 rev. 2.10 for linux 1.3.90247247- * New argument "reset_flags" to the reset routine.248248- *249249- * 6 Jul 1995 rev. 2.01 for linux 1.3.7250250- * Update required by the new /proc/scsi support.251251- *252252- * 11 Mar 1995 rev. 2.00 for linux 1.2.0253253- * Fixed a bug which prevented media change detection for removable254254- * disk drives.255255- *256256- * 23 Feb 1995 rev. 1.18 for linux 1.1.94257257- * Added a check for scsi_register returning NULL.258258- *259259- * 11 Feb 1995 rev. 1.17 for linux 1.1.91260260- * Now DEBUG_RESET is disabled by default.261261- * Register a board even if it does not assert DMA protocol support262262- * (DPT SK2011B does not report correctly the dmasup bit).263263- *264264- * 9 Feb 1995 rev. 1.16 for linux 1.1.90265265- * Use host->wish_block instead of host->block.266266- * New list of Data Out SCSI commands.267267- *268268- * 8 Feb 1995 rev. 1.15 for linux 1.1.89269269- * Cleared target_time_out counter while performing a reset.270270- * All external symbols renamed to avoid possible name conflicts.271271- *272272- * 28 Jan 1995 rev. 1.14 for linux 1.1.86273273- * Added module support.274274- * Log and do a retry when a disk drive returns a target status275275- * different from zero on a recovered error.276276- *277277- * 24 Jan 1995 rev. 1.13 for linux 1.1.85278278- * Use optimized board configuration, with a measured performance279279- * increase in the range 10%-20% on i/o throughput.280280- *281281- * 16 Jan 1995 rev. 1.12 for linux 1.1.81282282- * Fix mscp structure comments (no functional change).283283- * Display a message if check_region detects a port address284284- * already in use.285285- *286286- * 17 Dec 1994 rev. 1.11 for linux 1.1.74287287- * Use the scsicam_bios_param routine. This allows an easy288288- * migration path from disk partition tables created using289289- * different SCSI drivers and non optimal disk geometry.290290- *291291- * 15 Dec 1994 rev. 1.10 for linux 1.1.74292292- * Added support for ISA EATA boards (DPT PM2011, DPT PM2021).293293- * The host->block flag is set for all the detected ISA boards.294294- * The detect routine no longer enforces LEVEL triggering295295- * for EISA boards, it just prints a warning message.296296- *297297- * 30 Nov 1994 rev. 1.09 for linux 1.1.68298298- * Redo i/o on target status CHECK_CONDITION for TYPE_DISK only.299299- * Added optional support for using a single board at a time.300300- *301301- * 18 Nov 1994 rev. 1.08 for linux 1.1.64302302- * Forces sg_tablesize = 64 and can_queue = 64 if these303303- * values are not correctly detected (DPT PM2012).304304- *305305- * 14 Nov 1994 rev. 1.07 for linux 1.1.63 Final BETA release.306306- * 04 Aug 1994 rev. 1.00 for linux 1.1.39 First BETA release.307307- *308308- *309309- * This driver is based on the CAM (Common Access Method Committee)310310- * EATA (Enhanced AT Bus Attachment) rev. 2.0A, using DMA protocol.311311- *312312- * Copyright (C) 1994-2003 Dario Ballabio (ballabio_dario@emc.com)313313- *314314- * Alternate email: dario.ballabio@inwind.it, dario.ballabio@tiscalinet.it315315- *316316- * Redistribution and use in source and binary forms, with or without317317- * modification, are permitted provided that redistributions of source318318- * code retain the above copyright notice and this comment without319319- * modification.320320- *321321- */322322-323323-/*324324- *325325- * Here is a brief description of the DPT SCSI host adapters.326326- * All these boards provide an EATA/DMA compatible programming interface327327- * and are fully supported by this driver in any configuration, including328328- * multiple SCSI channels:329329- *330330- * PM2011B/9X - Entry Level ISA331331- * PM2021A/9X - High Performance ISA332332- * PM2012A Old EISA333333- * PM2012B Old EISA334334- * PM2022A/9X - Entry Level EISA335335- * PM2122A/9X - High Performance EISA336336- * PM2322A/9X - Extra High Performance EISA337337- * PM3021 - SmartRAID Adapter for ISA338338- * PM3222 - SmartRAID Adapter for EISA (PM3222W is 16-bit wide SCSI)339339- * PM3224 - SmartRAID Adapter for PCI (PM3224W is 16-bit wide SCSI)340340- * PM33340UW - SmartRAID Adapter for PCI ultra wide multichannel341341- *342342- * The above list is just an indication: as a matter of fact all DPT343343- * boards using the EATA/DMA protocol are supported by this driver,344344- * since they use exactely the same programming interface.345345- *346346- * The DPT PM2001 provides only the EATA/PIO interface and hence is not347347- * supported by this driver.348348- *349349- * This code has been tested with up to 3 Distributed Processing Technology350350- * PM2122A/9X (DPT SCSI BIOS v002.D1, firmware v05E.0) EISA controllers,351351- * in any combination of private and shared IRQ.352352- * PCI support has been tested using up to 2 DPT PM3224W (DPT SCSI BIOS353353- * v003.D0, firmware v07G.0).354354- *355355- * DPT SmartRAID boards support "Hardware Array" - a group of disk drives356356- * which are all members of the same RAID-0, RAID-1 or RAID-5 array implemented357357- * in host adapter hardware. Hardware Arrays are fully compatible with this358358- * driver, since they look to it as a single disk drive.359359- *360360- * WARNING: to create a RAID-0 "Hardware Array" you must select "Other Unix"361361- * as the current OS in the DPTMGR "Initial System Installation" menu.362362- * Otherwise RAID-0 is generated as an "Array Group" (i.e. software RAID-0),363363- * which is not supported by the actual SCSI subsystem.364364- * To get the "Array Group" functionality, the Linux MD driver must be used365365- * instead of the DPT "Array Group" feature.366366- *367367- * Multiple ISA, EISA and PCI boards can be configured in the same system.368368- * It is suggested to put all the EISA boards on the same IRQ level, all369369- * the PCI boards on another IRQ level, while ISA boards cannot share370370- * interrupts.371371- *372372- * If you configure multiple boards on the same IRQ, the interrupt must373373- * be _level_ triggered (not _edge_ triggered).374374- *375375- * This driver detects EATA boards by probes at fixed port addresses,376376- * so no BIOS32 or PCI BIOS support is required.377377- * The suggested way to detect a generic EATA PCI board is to force on it378378- * any unused EISA address, even if there are other controllers on the EISA379379- * bus, or even if you system has no EISA bus at all.380380- * Do not force any ISA address on EATA PCI boards.381381- *382382- * If PCI bios support is configured into the kernel, BIOS32 is used to383383- * include in the list of i/o ports to be probed all the PCI SCSI controllers.384384- *385385- * Due to a DPT BIOS "feature", it might not be possible to force an EISA386386- * address on more than a single DPT PCI board, so in this case you have to387387- * let the PCI BIOS assign the addresses.388388- *389389- * The sequence of detection probes is:390390- *391391- * - ISA 0x1F0;392392- * - PCI SCSI controllers (only if BIOS32 is available);393393- * - EISA/PCI 0x1C88 through 0xFC88 (corresponding to EISA slots 1 to 15);394394- * - ISA 0x170, 0x230, 0x330.395395- *396396- * The above list of detection probes can be totally replaced by the397397- * boot command line option: "eata=port0,port1,port2,...", where the398398- * port0, port1... arguments are ISA/EISA/PCI addresses to be probed.399399- * For example using "eata=0x7410,0x7450,0x230", the driver probes400400- * only the two PCI addresses 0x7410 and 0x7450 and the ISA address 0x230,401401- * in this order; "eata=0" totally disables this driver.402402- *403403- * After the optional list of detection probes, other possible command line404404- * options are:405405- *406406- * et:y force use of extended translation (255 heads, 63 sectors);407407- * et:n use disk geometry detected by scsicam_bios_param;408408- * rs:y reverse scan order while detecting PCI boards;409409- * rs:n use BIOS order while detecting PCI boards;410410- * lc:y enables linked commands;411411- * lc:n disables linked commands;412412- * tm:0 disables tagged commands (same as tc:n);413413- * tm:1 use simple queue tags (same as tc:y);414414- * tm:2 use ordered queue tags (same as tc:2);415415- * mq:xx set the max queue depth to the value xx (2 <= xx <= 32).416416- *417417- * The default value is: "eata=lc:n,mq:16,tm:0,et:n,rs:n".418418- * An example using the list of detection probes could be:419419- * "eata=0x7410,0x230,lc:y,tm:2,mq:4,et:n".420420- *421421- * When loading as a module, parameters can be specified as well.422422- * The above example would be (use 1 in place of y and 0 in place of n):423423- *424424- * modprobe eata io_port=0x7410,0x230 linked_comm=1 \425425- * max_queue_depth=4 ext_tran=0 tag_mode=2 \426426- * rev_scan=1427427- *428428- * ----------------------------------------------------------------------------429429- * In this implementation, linked commands are designed to work with any DISK430430- * or CD-ROM, since this linking has only the intent of clustering (time-wise)431431- * and reordering by elevator sorting commands directed to each device,432432- * without any relation with the actual SCSI protocol between the controller433433- * and the device.434434- * If Q is the queue depth reported at boot time for each device (also named435435- * cmds/lun) and Q > 2, whenever there is already an active command to the436436- * device all other commands to the same device (up to Q-1) are kept waiting437437- * in the elevator sorting queue. When the active command completes, the438438- * commands in this queue are sorted by sector address. The sort is chosen439439- * between increasing or decreasing by minimizing the seek distance between440440- * the sector of the commands just completed and the sector of the first441441- * command in the list to be sorted.442442- * Trivial math assures that the unsorted average seek distance when doing443443- * random seeks over S sectors is S/3.444444- * When (Q-1) requests are uniformly distributed over S sectors, the average445445- * distance between two adjacent requests is S/((Q-1) + 1), so the sorted446446- * average seek distance for (Q-1) random requests over S sectors is S/Q.447447- * The elevator sorting hence divides the seek distance by a factor Q/3.448448- * The above pure geometric remarks are valid in all cases and the449449- * driver effectively reduces the seek distance by the predicted factor450450- * when there are Q concurrent read i/o operations on the device, but this451451- * does not necessarily results in a noticeable performance improvement:452452- * your mileage may vary....453453- *454454- * Note: command reordering inside a batch of queued commands could cause455455- * wrong results only if there is at least one write request and the456456- * intersection (sector-wise) of all requests is not empty.457457- * When the driver detects a batch including overlapping requests458458- * (a really rare event) strict serial (pid) order is enforced.459459- * ----------------------------------------------------------------------------460460- * The extended translation option (et:y) is useful when using large physical461461- * disks/arrays. It could also be useful when switching between Adaptec boards462462- * and DPT boards without reformatting the disk.463463- * When a boot disk is partitioned with extended translation, in order to464464- * be able to boot it with a DPT board is could be necessary to add to465465- * lilo.conf additional commands as in the following example:466466- *467467- * fix-table468468- * disk=/dev/sda bios=0x80 sectors=63 heads=128 cylindres=546469469- *470470- * where the above geometry should be replaced with the one reported at471471- * power up by the DPT controller.472472- * ----------------------------------------------------------------------------473473- *474474- * The boards are named EATA0, EATA1,... according to the detection order.475475- *476476- * In order to support multiple ISA boards in a reliable way,477477- * the driver sets host->wish_block = 1 for all ISA boards.478478- */479479-480480-#include <linux/string.h>481481-#include <linux/kernel.h>482482-#include <linux/ioport.h>483483-#include <linux/delay.h>484484-#include <linux/proc_fs.h>485485-#include <linux/blkdev.h>486486-#include <linux/interrupt.h>487487-#include <linux/stat.h>488488-#include <linux/pci.h>489489-#include <linux/init.h>490490-#include <linux/ctype.h>491491-#include <linux/spinlock.h>492492-#include <linux/dma-mapping.h>493493-#include <linux/slab.h>494494-#include <asm/byteorder.h>495495-#include <asm/dma.h>496496-#include <asm/io.h>497497-#include <asm/irq.h>498498-499499-#include <scsi/scsi.h>500500-#include <scsi/scsi_cmnd.h>501501-#include <scsi/scsi_device.h>502502-#include <scsi/scsi_host.h>503503-#include <scsi/scsi_tcq.h>504504-#include <scsi/scsicam.h>505505-506506-static int eata2x_detect(struct scsi_host_template *);507507-static int eata2x_release(struct Scsi_Host *);508508-static int eata2x_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);509509-static int eata2x_eh_abort(struct scsi_cmnd *);510510-static int eata2x_eh_host_reset(struct scsi_cmnd *);511511-static int eata2x_bios_param(struct scsi_device *, struct block_device *,512512- sector_t, int *);513513-static int eata2x_slave_configure(struct scsi_device *);514514-515515-static struct scsi_host_template driver_template = {516516- .name = "EATA/DMA 2.0x rev. 8.10.00 ",517517- .detect = eata2x_detect,518518- .release = eata2x_release,519519- .queuecommand = eata2x_queuecommand,520520- .eh_abort_handler = eata2x_eh_abort,521521- .eh_host_reset_handler = eata2x_eh_host_reset,522522- .bios_param = eata2x_bios_param,523523- .slave_configure = eata2x_slave_configure,524524- .this_id = 7,525525- .unchecked_isa_dma = 1,526526- .use_clustering = ENABLE_CLUSTERING,527527-};528528-529529-#if !defined(__BIG_ENDIAN_BITFIELD) && !defined(__LITTLE_ENDIAN_BITFIELD)530530-#error "Adjust your <asm/byteorder.h> defines"531531-#endif532532-533533-/* Subversion values */534534-#define ISA 0535535-#define ESA 1536536-537537-#undef FORCE_CONFIG538538-539539-#undef DEBUG_LINKED_COMMANDS540540-#undef DEBUG_DETECT541541-#undef DEBUG_PCI_DETECT542542-#undef DEBUG_INTERRUPT543543-#undef DEBUG_RESET544544-#undef DEBUG_GENERATE_ERRORS545545-#undef DEBUG_GENERATE_ABORTS546546-#undef DEBUG_GEOMETRY547547-548548-#define MAX_ISA 4549549-#define MAX_VESA 0550550-#define MAX_EISA 15551551-#define MAX_PCI 16552552-#define MAX_BOARDS (MAX_ISA + MAX_VESA + MAX_EISA + MAX_PCI)553553-#define MAX_CHANNEL 4554554-#define MAX_LUN 32555555-#define MAX_TARGET 32556556-#define MAX_MAILBOXES 64557557-#define MAX_SGLIST 64558558-#define MAX_LARGE_SGLIST 122559559-#define MAX_INTERNAL_RETRIES 64560560-#define MAX_CMD_PER_LUN 2561561-#define MAX_TAGGED_CMD_PER_LUN (MAX_MAILBOXES - MAX_CMD_PER_LUN)562562-563563-#define SKIP ULONG_MAX564564-#define FREE 0565565-#define IN_USE 1566566-#define LOCKED 2567567-#define IN_RESET 3568568-#define IGNORE 4569569-#define READY 5570570-#define ABORTING 6571571-#define NO_DMA 0xff572572-#define MAXLOOP 10000573573-#define TAG_DISABLED 0574574-#define TAG_SIMPLE 1575575-#define TAG_ORDERED 2576576-577577-#define REG_CMD 7578578-#define REG_STATUS 7579579-#define REG_AUX_STATUS 8580580-#define REG_DATA 0581581-#define REG_DATA2 1582582-#define REG_SEE 6583583-#define REG_LOW 2584584-#define REG_LM 3585585-#define REG_MID 4586586-#define REG_MSB 5587587-#define REGION_SIZE 9UL588588-#define MAX_ISA_ADDR 0x03ff589589-#define MIN_EISA_ADDR 0x1c88590590-#define MAX_EISA_ADDR 0xfc88591591-#define BSY_ASSERTED 0x80592592-#define DRQ_ASSERTED 0x08593593-#define ABSY_ASSERTED 0x01594594-#define IRQ_ASSERTED 0x02595595-#define READ_CONFIG_PIO 0xf0596596-#define SET_CONFIG_PIO 0xf1597597-#define SEND_CP_PIO 0xf2598598-#define RECEIVE_SP_PIO 0xf3599599-#define TRUNCATE_XFR_PIO 0xf4600600-#define RESET_PIO 0xf9601601-#define READ_CONFIG_DMA 0xfd602602-#define SET_CONFIG_DMA 0xfe603603-#define SEND_CP_DMA 0xff604604-#define ASOK 0x00605605-#define ASST 0x01606606-607607-#define YESNO(a) ((a) ? 'y' : 'n')608608-#define TLDEV(type) ((type) == TYPE_DISK || (type) == TYPE_ROM)609609-610610-/* "EATA", in Big Endian format */611611-#define EATA_SIG_BE 0x45415441612612-613613-/* Number of valid bytes in the board config structure for EATA 2.0x */614614-#define EATA_2_0A_SIZE 28615615-#define EATA_2_0B_SIZE 30616616-#define EATA_2_0C_SIZE 34617617-618618-/* Board info structure */619619-struct eata_info {620620- u_int32_t data_len; /* Number of valid bytes after this field */621621- u_int32_t sign; /* ASCII "EATA" signature */622622-623623-#if defined(__BIG_ENDIAN_BITFIELD)624624- unchar version : 4,625625- : 4;626626- unchar haaval : 1,627627- ata : 1,628628- drqvld : 1,629629- dmasup : 1,630630- morsup : 1,631631- trnxfr : 1,632632- tarsup : 1,633633- ocsena : 1;634634-#else635635- unchar : 4, /* unused low nibble */636636- version : 4; /* EATA version, should be 0x1 */637637- unchar ocsena : 1, /* Overlap Command Support Enabled */638638- tarsup : 1, /* Target Mode Supported */639639- trnxfr : 1, /* Truncate Transfer Cmd NOT Necessary */640640- morsup : 1, /* More Supported */641641- dmasup : 1, /* DMA Supported */642642- drqvld : 1, /* DRQ Index (DRQX) is valid */643643- ata : 1, /* This is an ATA device */644644- haaval : 1; /* Host Adapter Address Valid */645645-#endif646646-647647- ushort cp_pad_len; /* Number of pad bytes after cp_len */648648- unchar host_addr[4]; /* Host Adapter SCSI ID for channels 3, 2, 1, 0 */649649- u_int32_t cp_len; /* Number of valid bytes in cp */650650- u_int32_t sp_len; /* Number of valid bytes in sp */651651- ushort queue_size; /* Max number of cp that can be queued */652652- ushort unused;653653- ushort scatt_size; /* Max number of entries in scatter/gather table */654654-655655-#if defined(__BIG_ENDIAN_BITFIELD)656656- unchar drqx : 2,657657- second : 1,658658- irq_tr : 1,659659- irq : 4;660660- unchar sync;661661- unchar : 4,662662- res1 : 1,663663- large_sg : 1,664664- forcaddr : 1,665665- isaena : 1;666666- unchar max_chan : 3,667667- max_id : 5;668668- unchar max_lun;669669- unchar eisa : 1,670670- pci : 1,671671- idquest : 1,672672- m1 : 1,673673- : 4;674674-#else675675- unchar irq : 4, /* Interrupt Request assigned to this controller */676676- irq_tr : 1, /* 0 for edge triggered, 1 for level triggered */677677- second : 1, /* 1 if this is a secondary (not primary) controller */678678- drqx : 2; /* DRQ Index (0=DMA0, 1=DMA7, 2=DMA6, 3=DMA5) */679679- unchar sync; /* 1 if scsi target id 7...0 is running sync scsi */680680-681681- /* Structure extension defined in EATA 2.0B */682682- unchar isaena : 1, /* ISA i/o addressing is disabled/enabled */683683- forcaddr : 1, /* Port address has been forced */684684- large_sg : 1, /* 1 if large SG lists are supported */685685- res1 : 1,686686- : 4;687687- unchar max_id : 5, /* Max SCSI target ID number */688688- max_chan : 3; /* Max SCSI channel number on this board */689689-690690- /* Structure extension defined in EATA 2.0C */691691- unchar max_lun; /* Max SCSI LUN number */692692- unchar693693- : 4,694694- m1 : 1, /* This is a PCI with an M1 chip installed */695695- idquest : 1, /* RAIDNUM returned is questionable */696696- pci : 1, /* This board is PCI */697697- eisa : 1; /* This board is EISA */698698-#endif699699-700700- unchar raidnum; /* Uniquely identifies this HBA in a system */701701- unchar notused;702702-703703- ushort ipad[247];704704-};705705-706706-/* Board config structure */707707-struct eata_config {708708- ushort len; /* Number of bytes following this field */709709-710710-#if defined(__BIG_ENDIAN_BITFIELD)711711- unchar : 4,712712- tarena : 1,713713- mdpena : 1,714714- ocena : 1,715715- edis : 1;716716-#else717717- unchar edis : 1, /* Disable EATA interface after config command */718718- ocena : 1, /* Overlapped Commands Enabled */719719- mdpena : 1, /* Transfer all Modified Data Pointer Messages */720720- tarena : 1, /* Target Mode Enabled for this controller */721721- : 4;722722-#endif723723- unchar cpad[511];724724-};725725-726726-/* Returned status packet structure */727727-struct mssp {728728-#if defined(__BIG_ENDIAN_BITFIELD)729729- unchar eoc : 1,730730- adapter_status : 7;731731-#else732732- unchar adapter_status : 7, /* State related to current command */733733- eoc : 1; /* End Of Command (1 = command completed) */734734-#endif735735- unchar target_status; /* SCSI status received after data transfer */736736- unchar unused[2];737737- u_int32_t inv_res_len; /* Number of bytes not transferred */738738- u_int32_t cpp_index; /* Index of address set in cp */739739- char mess[12];740740-};741741-742742-struct sg_list {743743- unsigned int address; /* Segment Address */744744- unsigned int num_bytes; /* Segment Length */745745-};746746-747747-/* MailBox SCSI Command Packet */748748-struct mscp {749749-#if defined(__BIG_ENDIAN_BITFIELD)750750- unchar din : 1,751751- dout : 1,752752- interp : 1,753753- : 1,754754- sg : 1,755755- reqsen :1,756756- init : 1,757757- sreset : 1;758758- unchar sense_len;759759- unchar unused[3];760760- unchar : 7,761761- fwnest : 1;762762- unchar : 5,763763- hbaci : 1,764764- iat : 1,765765- phsunit : 1;766766- unchar channel : 3,767767- target : 5;768768- unchar one : 1,769769- dispri : 1,770770- luntar : 1,771771- lun : 5;772772-#else773773- unchar sreset :1, /* SCSI Bus Reset Signal should be asserted */774774- init :1, /* Re-initialize controller and self test */775775- reqsen :1, /* Transfer Request Sense Data to addr using DMA */776776- sg :1, /* Use Scatter/Gather */777777- :1,778778- interp :1, /* The controller interprets cp, not the target */779779- dout :1, /* Direction of Transfer is Out (Host to Target) */780780- din :1; /* Direction of Transfer is In (Target to Host) */781781- unchar sense_len; /* Request Sense Length */782782- unchar unused[3];783783- unchar fwnest : 1, /* Send command to a component of an Array Group */784784- : 7;785785- unchar phsunit : 1, /* Send to Target Physical Unit (bypass RAID) */786786- iat : 1, /* Inhibit Address Translation */787787- hbaci : 1, /* Inhibit HBA Caching for this command */788788- : 5;789789- unchar target : 5, /* SCSI target ID */790790- channel : 3; /* SCSI channel number */791791- unchar lun : 5, /* SCSI logical unit number */792792- luntar : 1, /* This cp is for Target (not LUN) */793793- dispri : 1, /* Disconnect Privilege granted */794794- one : 1; /* 1 */795795-#endif796796-797797- unchar mess[3]; /* Massage to/from Target */798798- unchar cdb[12]; /* Command Descriptor Block */799799- u_int32_t data_len; /* If sg=0 Data Length, if sg=1 sglist length */800800- u_int32_t cpp_index; /* Index of address to be returned in sp */801801- u_int32_t data_address; /* If sg=0 Data Address, if sg=1 sglist address */802802- u_int32_t sp_dma_addr; /* Address where sp is DMA'ed when cp completes */803803- u_int32_t sense_addr; /* Address where Sense Data is DMA'ed on error */804804-805805- /* Additional fields begin here. */806806- struct scsi_cmnd *SCpnt;807807-808808- /* All the cp structure is zero filled by queuecommand except the809809- following CP_TAIL_SIZE bytes, initialized by detect */810810- dma_addr_t cp_dma_addr; /* dma handle for this cp structure */811811- struct sg_list *sglist; /* pointer to the allocated SG list */812812-};813813-814814-#define CP_TAIL_SIZE (sizeof(struct sglist *) + sizeof(dma_addr_t))815815-816816-struct hostdata {817817- struct mscp cp[MAX_MAILBOXES]; /* Mailboxes for this board */818818- unsigned int cp_stat[MAX_MAILBOXES]; /* FREE, IN_USE, LOCKED, IN_RESET */819819- unsigned int last_cp_used; /* Index of last mailbox used */820820- unsigned int iocount; /* Total i/o done for this board */821821- int board_number; /* Number of this board */822822- char board_name[16]; /* Name of this board */823823- int in_reset; /* True if board is doing a reset */824824- int target_to[MAX_TARGET][MAX_CHANNEL]; /* N. of timeout errors on target */825825- int target_redo[MAX_TARGET][MAX_CHANNEL]; /* If 1 redo i/o on target */826826- unsigned int retries; /* Number of internal retries */827827- unsigned long last_retried_pid; /* Pid of last retried command */828828- unsigned char subversion; /* Bus type, either ISA or EISA/PCI */829829- unsigned char protocol_rev; /* EATA 2.0 rev., 'A' or 'B' or 'C' */830830- unsigned char is_pci; /* 1 is bus type is PCI */831831- struct pci_dev *pdev; /* pdev for PCI bus, NULL otherwise */832832- struct mssp *sp_cpu_addr; /* cpu addr for DMA buffer sp */833833- dma_addr_t sp_dma_addr; /* dma handle for DMA buffer sp */834834- struct mssp sp; /* Local copy of sp buffer */835835-};836836-837837-static struct Scsi_Host *sh[MAX_BOARDS];838838-static const char *driver_name = "EATA";839839-static char sha[MAX_BOARDS];840840-841841-/* Initialize num_boards so that ihdlr can work while detect is in progress */842842-static unsigned int num_boards = MAX_BOARDS;843843-844844-static unsigned long io_port[] = {845845-846846- /* Space for MAX_INT_PARAM ports usable while loading as a module */847847- SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP,848848- SKIP, SKIP,849849-850850- /* First ISA */851851- 0x1f0,852852-853853- /* Space for MAX_PCI ports possibly reported by PCI_BIOS */854854- SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP,855855- SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP,856856-857857- /* MAX_EISA ports */858858- 0x1c88, 0x2c88, 0x3c88, 0x4c88, 0x5c88, 0x6c88, 0x7c88, 0x8c88,859859- 0x9c88, 0xac88, 0xbc88, 0xcc88, 0xdc88, 0xec88, 0xfc88,860860-861861- /* Other (MAX_ISA - 1) ports */862862- 0x170, 0x230, 0x330,863863-864864- /* End of list */865865- 0x0866866-};867867-868868-/* Device is Big Endian */869869-#define H2DEV(x) cpu_to_be32(x)870870-#define DEV2H(x) be32_to_cpu(x)871871-#define H2DEV16(x) cpu_to_be16(x)872872-#define DEV2H16(x) be16_to_cpu(x)873873-874874-/* But transfer orientation from the 16 bit data register is Little Endian */875875-#define REG2H(x) le16_to_cpu(x)876876-877877-static irqreturn_t do_interrupt_handler(int, void *);878878-static void flush_dev(struct scsi_device *, unsigned long, struct hostdata *,879879- unsigned int);880880-static int do_trace = 0;881881-static int setup_done = 0;882882-static int link_statistics;883883-static int ext_tran = 0;884884-static int rev_scan = 1;885885-886886-#if defined(CONFIG_SCSI_EATA_TAGGED_QUEUE)887887-static int tag_mode = TAG_SIMPLE;888888-#else889889-static int tag_mode = TAG_DISABLED;890890-#endif891891-892892-#if defined(CONFIG_SCSI_EATA_LINKED_COMMANDS)893893-static int linked_comm = 1;894894-#else895895-static int linked_comm = 0;896896-#endif897897-898898-#if defined(CONFIG_SCSI_EATA_MAX_TAGS)899899-static int max_queue_depth = CONFIG_SCSI_EATA_MAX_TAGS;900900-#else901901-static int max_queue_depth = MAX_CMD_PER_LUN;902902-#endif903903-904904-#if defined(CONFIG_ISA)905905-static int isa_probe = 1;906906-#else907907-static int isa_probe = 0;908908-#endif909909-910910-#if defined(CONFIG_EISA)911911-static int eisa_probe = 1;912912-#else913913-static int eisa_probe = 0;914914-#endif915915-916916-#if defined(CONFIG_PCI)917917-static int pci_probe = 1;918918-#else919919-static int pci_probe = 0;920920-#endif921921-922922-#define MAX_INT_PARAM 10923923-#define MAX_BOOT_OPTIONS_SIZE 256924924-static char boot_options[MAX_BOOT_OPTIONS_SIZE];925925-926926-#if defined(MODULE)927927-#include <linux/module.h>928928-#include <linux/moduleparam.h>929929-930930-module_param_string(eata, boot_options, MAX_BOOT_OPTIONS_SIZE, 0);931931-MODULE_PARM_DESC(eata, " equivalent to the \"eata=...\" kernel boot option."932932- " Example: modprobe eata \"eata=0x7410,0x230,lc:y,tm:0,mq:4,ep:n\"");933933-MODULE_AUTHOR("Dario Ballabio");934934-MODULE_LICENSE("GPL");935935-MODULE_DESCRIPTION("EATA/DMA SCSI Driver");936936-937937-#endif938938-939939-static int eata2x_slave_configure(struct scsi_device *dev)940940-{941941- int tqd, utqd;942942- char *tag_suffix, *link_suffix;943943-944944- utqd = MAX_CMD_PER_LUN;945945- tqd = max_queue_depth;946946-947947- if (TLDEV(dev->type) && dev->tagged_supported) {948948- if (tag_mode == TAG_SIMPLE) {949949- tag_suffix = ", simple tags";950950- } else if (tag_mode == TAG_ORDERED) {951951- tag_suffix = ", ordered tags";952952- } else {953953- tag_suffix = ", no tags";954954- }955955- scsi_change_queue_depth(dev, tqd);956956- } else if (TLDEV(dev->type) && linked_comm) {957957- scsi_change_queue_depth(dev, tqd);958958- tag_suffix = ", untagged";959959- } else {960960- scsi_change_queue_depth(dev, utqd);961961- tag_suffix = "";962962- }963963-964964- if (TLDEV(dev->type) && linked_comm && dev->queue_depth > 2)965965- link_suffix = ", sorted";966966- else if (TLDEV(dev->type))967967- link_suffix = ", unsorted";968968- else969969- link_suffix = "";970970-971971- sdev_printk(KERN_INFO, dev,972972- "cmds/lun %d%s%s.\n",973973- dev->queue_depth, link_suffix, tag_suffix);974974-975975- return 0;976976-}977977-978978-static int wait_on_busy(unsigned long iobase, unsigned int loop)979979-{980980- while (inb(iobase + REG_AUX_STATUS) & ABSY_ASSERTED) {981981- udelay(1L);982982- if (--loop == 0)983983- return 1;984984- }985985- return 0;986986-}987987-988988-static int do_dma(unsigned long iobase, unsigned long addr, unchar cmd)989989-{990990- unsigned char *byaddr;991991- unsigned long devaddr;992992-993993- if (wait_on_busy(iobase, (addr ? MAXLOOP * 100 : MAXLOOP)))994994- return 1;995995-996996- if (addr) {997997- devaddr = H2DEV(addr);998998- byaddr = (unsigned char *)&devaddr;999999- outb(byaddr[3], iobase + REG_LOW);10001000- outb(byaddr[2], iobase + REG_LM);10011001- outb(byaddr[1], iobase + REG_MID);10021002- outb(byaddr[0], iobase + REG_MSB);10031003- }10041004-10051005- outb(cmd, iobase + REG_CMD);10061006- return 0;10071007-}10081008-10091009-static int read_pio(unsigned long iobase, ushort * start, ushort * end)10101010-{10111011- unsigned int loop = MAXLOOP;10121012- ushort *p;10131013-10141014- for (p = start; p <= end; p++) {10151015- while (!(inb(iobase + REG_STATUS) & DRQ_ASSERTED)) {10161016- udelay(1L);10171017- if (--loop == 0)10181018- return 1;10191019- }10201020- loop = MAXLOOP;10211021- *p = REG2H(inw(iobase));10221022- }10231023-10241024- return 0;10251025-}10261026-10271027-static struct pci_dev *get_pci_dev(unsigned long port_base)10281028-{10291029-#if defined(CONFIG_PCI)10301030- unsigned int addr;10311031- struct pci_dev *dev = NULL;10321032-10331033- while ((dev = pci_get_class(PCI_CLASS_STORAGE_SCSI << 8, dev))) {10341034- addr = pci_resource_start(dev, 0);10351035-10361036-#if defined(DEBUG_PCI_DETECT)10371037- printk("%s: get_pci_dev, bus %d, devfn 0x%x, addr 0x%x.\n",10381038- driver_name, dev->bus->number, dev->devfn, addr);10391039-#endif10401040-10411041- /* we are in so much trouble for a pci hotplug system with this driver10421042- * anyway, so doing this at least lets people unload the driver and not10431043- * cause memory problems, but in general this is a bad thing to do (this10441044- * driver needs to be converted to the proper PCI api someday... */10451045- pci_dev_put(dev);10461046- if (addr + PCI_BASE_ADDRESS_0 == port_base)10471047- return dev;10481048- }10491049-#endif /* end CONFIG_PCI */10501050- return NULL;10511051-}10521052-10531053-static void enable_pci_ports(void)10541054-{10551055-#if defined(CONFIG_PCI)10561056- struct pci_dev *dev = NULL;10571057-10581058- while ((dev = pci_get_class(PCI_CLASS_STORAGE_SCSI << 8, dev))) {10591059-#if defined(DEBUG_PCI_DETECT)10601060- printk("%s: enable_pci_ports, bus %d, devfn 0x%x.\n",10611061- driver_name, dev->bus->number, dev->devfn);10621062-#endif10631063-10641064- if (pci_enable_device(dev))10651065- printk10661066- ("%s: warning, pci_enable_device failed, bus %d devfn 0x%x.\n",10671067- driver_name, dev->bus->number, dev->devfn);10681068- }10691069-10701070-#endif /* end CONFIG_PCI */10711071-}10721072-10731073-static int port_detect(unsigned long port_base, unsigned int j,10741074- struct scsi_host_template *tpnt)10751075-{10761076- unsigned char irq, dma_channel, subversion, i, is_pci = 0;10771077- unsigned char protocol_rev;10781078- struct eata_info info;10791079- char *bus_type, dma_name[16];10801080- struct pci_dev *pdev;10811081- /* Allowed DMA channels for ISA (0 indicates reserved) */10821082- unsigned char dma_channel_table[4] = { 5, 6, 7, 0 };10831083- struct Scsi_Host *shost;10841084- struct hostdata *ha;10851085- char name[16];10861086-10871087- sprintf(name, "%s%d", driver_name, j);10881088-10891089- if (!request_region(port_base, REGION_SIZE, driver_name)) {10901090-#if defined(DEBUG_DETECT)10911091- printk("%s: address 0x%03lx in use, skipping probe.\n", name,10921092- port_base);10931093-#endif10941094- goto fail;10951095- }10961096-10971097- if (do_dma(port_base, 0, READ_CONFIG_PIO)) {10981098-#if defined(DEBUG_DETECT)10991099- printk("%s: detect, do_dma failed at 0x%03lx.\n", name,11001100- port_base);11011101-#endif11021102- goto freelock;11031103- }11041104-11051105- /* Read the info structure */11061106- if (read_pio(port_base, (ushort *) & info, (ushort *) & info.ipad[0])) {11071107-#if defined(DEBUG_DETECT)11081108- printk("%s: detect, read_pio failed at 0x%03lx.\n", name,11091109- port_base);11101110-#endif11111111- goto freelock;11121112- }11131113-11141114- info.data_len = DEV2H(info.data_len);11151115- info.sign = DEV2H(info.sign);11161116- info.cp_pad_len = DEV2H16(info.cp_pad_len);11171117- info.cp_len = DEV2H(info.cp_len);11181118- info.sp_len = DEV2H(info.sp_len);11191119- info.scatt_size = DEV2H16(info.scatt_size);11201120- info.queue_size = DEV2H16(info.queue_size);11211121-11221122- /* Check the controller "EATA" signature */11231123- if (info.sign != EATA_SIG_BE) {11241124-#if defined(DEBUG_DETECT)11251125- printk("%s: signature 0x%04x discarded.\n", name, info.sign);11261126-#endif11271127- goto freelock;11281128- }11291129-11301130- if (info.data_len < EATA_2_0A_SIZE) {11311131- printk11321132- ("%s: config structure size (%d bytes) too short, detaching.\n",11331133- name, info.data_len);11341134- goto freelock;11351135- } else if (info.data_len == EATA_2_0A_SIZE)11361136- protocol_rev = 'A';11371137- else if (info.data_len == EATA_2_0B_SIZE)11381138- protocol_rev = 'B';11391139- else11401140- protocol_rev = 'C';11411141-11421142- if (protocol_rev != 'A' && info.forcaddr) {11431143- printk("%s: warning, port address has been forced.\n", name);11441144- bus_type = "PCI";11451145- is_pci = 1;11461146- subversion = ESA;11471147- } else if (port_base > MAX_EISA_ADDR11481148- || (protocol_rev == 'C' && info.pci)) {11491149- bus_type = "PCI";11501150- is_pci = 1;11511151- subversion = ESA;11521152- } else if (port_base >= MIN_EISA_ADDR11531153- || (protocol_rev == 'C' && info.eisa)) {11541154- bus_type = "EISA";11551155- subversion = ESA;11561156- } else if (protocol_rev == 'C' && !info.eisa && !info.pci) {11571157- bus_type = "ISA";11581158- subversion = ISA;11591159- } else if (port_base > MAX_ISA_ADDR) {11601160- bus_type = "PCI";11611161- is_pci = 1;11621162- subversion = ESA;11631163- } else {11641164- bus_type = "ISA";11651165- subversion = ISA;11661166- }11671167-11681168- if (!info.haaval || info.ata) {11691169- printk11701170- ("%s: address 0x%03lx, unusable %s board (%d%d), detaching.\n",11711171- name, port_base, bus_type, info.haaval, info.ata);11721172- goto freelock;11731173- }11741174-11751175- if (info.drqvld) {11761176- if (subversion == ESA)11771177- printk("%s: warning, weird %s board using DMA.\n", name,11781178- bus_type);11791179-11801180- subversion = ISA;11811181- dma_channel = dma_channel_table[3 - info.drqx];11821182- } else {11831183- if (subversion == ISA)11841184- printk("%s: warning, weird %s board not using DMA.\n",11851185- name, bus_type);11861186-11871187- subversion = ESA;11881188- dma_channel = NO_DMA;11891189- }11901190-11911191- if (!info.dmasup)11921192- printk("%s: warning, DMA protocol support not asserted.\n",11931193- name);11941194-11951195- irq = info.irq;11961196-11971197- if (subversion == ESA && !info.irq_tr)11981198- printk11991199- ("%s: warning, LEVEL triggering is suggested for IRQ %u.\n",12001200- name, irq);12011201-12021202- if (is_pci) {12031203- pdev = get_pci_dev(port_base);12041204- if (!pdev)12051205- printk12061206- ("%s: warning, failed to get pci_dev structure.\n",12071207- name);12081208- } else12091209- pdev = NULL;12101210-12111211- if (pdev && (irq != pdev->irq)) {12121212- printk("%s: IRQ %u mapped to IO-APIC IRQ %u.\n", name, irq,12131213- pdev->irq);12141214- irq = pdev->irq;12151215- }12161216-12171217- /* Board detected, allocate its IRQ */12181218- if (request_irq(irq, do_interrupt_handler,12191219- (subversion == ESA) ? IRQF_SHARED : 0,12201220- driver_name, (void *)&sha[j])) {12211221- printk("%s: unable to allocate IRQ %u, detaching.\n", name,12221222- irq);12231223- goto freelock;12241224- }12251225-12261226- if (subversion == ISA && request_dma(dma_channel, driver_name)) {12271227- printk("%s: unable to allocate DMA channel %u, detaching.\n",12281228- name, dma_channel);12291229- goto freeirq;12301230- }12311231-#if defined(FORCE_CONFIG)12321232- {12331233- struct eata_config *cf;12341234- dma_addr_t cf_dma_addr;12351235-12361236- cf = pci_zalloc_consistent(pdev, sizeof(struct eata_config),12371237- &cf_dma_addr);12381238-12391239- if (!cf) {12401240- printk12411241- ("%s: config, pci_alloc_consistent failed, detaching.\n",12421242- name);12431243- goto freedma;12441244- }12451245-12461246- /* Set board configuration */12471247- cf->len = (ushort) H2DEV16((ushort) 510);12481248- cf->ocena = 1;12491249-12501250- if (do_dma(port_base, cf_dma_addr, SET_CONFIG_DMA)) {12511251- printk12521252- ("%s: busy timeout sending configuration, detaching.\n",12531253- name);12541254- pci_free_consistent(pdev, sizeof(struct eata_config),12551255- cf, cf_dma_addr);12561256- goto freedma;12571257- }12581258-12591259- }12601260-#endif12611261-12621262- sh[j] = shost = scsi_register(tpnt, sizeof(struct hostdata));12631263- if (shost == NULL) {12641264- printk("%s: unable to register host, detaching.\n", name);12651265- goto freedma;12661266- }12671267-12681268- shost->io_port = port_base;12691269- shost->unique_id = port_base;12701270- shost->n_io_port = REGION_SIZE;12711271- shost->dma_channel = dma_channel;12721272- shost->irq = irq;12731273- shost->sg_tablesize = (ushort) info.scatt_size;12741274- shost->this_id = (ushort) info.host_addr[3];12751275- shost->can_queue = (ushort) info.queue_size;12761276- shost->cmd_per_lun = MAX_CMD_PER_LUN;12771277-12781278- ha = (struct hostdata *)shost->hostdata;12791279-12801280- memset(ha, 0, sizeof(struct hostdata));12811281- ha->subversion = subversion;12821282- ha->protocol_rev = protocol_rev;12831283- ha->is_pci = is_pci;12841284- ha->pdev = pdev;12851285- ha->board_number = j;12861286-12871287- if (ha->subversion == ESA)12881288- shost->unchecked_isa_dma = 0;12891289- else {12901290- unsigned long flags;12911291- shost->unchecked_isa_dma = 1;12921292-12931293- flags = claim_dma_lock();12941294- disable_dma(dma_channel);12951295- clear_dma_ff(dma_channel);12961296- set_dma_mode(dma_channel, DMA_MODE_CASCADE);12971297- enable_dma(dma_channel);12981298- release_dma_lock(flags);12991299-13001300- }13011301-13021302- strcpy(ha->board_name, name);13031303-13041304- /* DPT PM2012 does not allow to detect sg_tablesize correctly */13051305- if (shost->sg_tablesize > MAX_SGLIST || shost->sg_tablesize < 2) {13061306- printk("%s: detect, wrong n. of SG lists %d, fixed.\n",13071307- ha->board_name, shost->sg_tablesize);13081308- shost->sg_tablesize = MAX_SGLIST;13091309- }13101310-13111311- /* DPT PM2012 does not allow to detect can_queue correctly */13121312- if (shost->can_queue > MAX_MAILBOXES || shost->can_queue < 2) {13131313- printk("%s: detect, wrong n. of mbox %d, fixed.\n",13141314- ha->board_name, shost->can_queue);13151315- shost->can_queue = MAX_MAILBOXES;13161316- }13171317-13181318- if (protocol_rev != 'A') {13191319- if (info.max_chan > 0 && info.max_chan < MAX_CHANNEL)13201320- shost->max_channel = info.max_chan;13211321-13221322- if (info.max_id > 7 && info.max_id < MAX_TARGET)13231323- shost->max_id = info.max_id + 1;13241324-13251325- if (info.large_sg && shost->sg_tablesize == MAX_SGLIST)13261326- shost->sg_tablesize = MAX_LARGE_SGLIST;13271327- }13281328-13291329- if (protocol_rev == 'C') {13301330- if (info.max_lun > 7 && info.max_lun < MAX_LUN)13311331- shost->max_lun = info.max_lun + 1;13321332- }13331333-13341334- if (dma_channel == NO_DMA)13351335- sprintf(dma_name, "%s", "BMST");13361336- else13371337- sprintf(dma_name, "DMA %u", dma_channel);13381338-13391339- for (i = 0; i < shost->can_queue; i++)13401340- ha->cp[i].cp_dma_addr = pci_map_single(ha->pdev,13411341- &ha->cp[i],13421342- sizeof(struct mscp),13431343- PCI_DMA_BIDIRECTIONAL);13441344-13451345- for (i = 0; i < shost->can_queue; i++) {13461346- size_t sz = shost->sg_tablesize *sizeof(struct sg_list);13471347- gfp_t gfp_mask = (shost->unchecked_isa_dma ? GFP_DMA : 0) | GFP_ATOMIC;13481348- ha->cp[i].sglist = kmalloc(sz, gfp_mask);13491349- if (!ha->cp[i].sglist) {13501350- printk13511351- ("%s: kmalloc SGlist failed, mbox %d, detaching.\n",13521352- ha->board_name, i);13531353- goto release;13541354- }13551355- }13561356-13571357- if (!(ha->sp_cpu_addr = pci_alloc_consistent(ha->pdev,13581358- sizeof(struct mssp),13591359- &ha->sp_dma_addr))) {13601360- printk("%s: pci_alloc_consistent failed, detaching.\n", ha->board_name);13611361- goto release;13621362- }13631363-13641364- if (max_queue_depth > MAX_TAGGED_CMD_PER_LUN)13651365- max_queue_depth = MAX_TAGGED_CMD_PER_LUN;13661366-13671367- if (max_queue_depth < MAX_CMD_PER_LUN)13681368- max_queue_depth = MAX_CMD_PER_LUN;13691369-13701370- if (tag_mode != TAG_DISABLED && tag_mode != TAG_SIMPLE)13711371- tag_mode = TAG_ORDERED;13721372-13731373- if (j == 0) {13741374- printk13751375- ("EATA/DMA 2.0x: Copyright (C) 1994-2003 Dario Ballabio.\n");13761376- printk13771377- ("%s config options -> tm:%d, lc:%c, mq:%d, rs:%c, et:%c, "13781378- "ip:%c, ep:%c, pp:%c.\n", driver_name, tag_mode,13791379- YESNO(linked_comm), max_queue_depth, YESNO(rev_scan),13801380- YESNO(ext_tran), YESNO(isa_probe), YESNO(eisa_probe),13811381- YESNO(pci_probe));13821382- }13831383-13841384- printk("%s: 2.0%c, %s 0x%03lx, IRQ %u, %s, SG %d, MB %d.\n",13851385- ha->board_name, ha->protocol_rev, bus_type,13861386- (unsigned long)shost->io_port, shost->irq, dma_name,13871387- shost->sg_tablesize, shost->can_queue);13881388-13891389- if (shost->max_id > 8 || shost->max_lun > 8)13901390- printk13911391- ("%s: wide SCSI support enabled, max_id %u, max_lun %llu.\n",13921392- ha->board_name, shost->max_id, shost->max_lun);13931393-13941394- for (i = 0; i <= shost->max_channel; i++)13951395- printk("%s: SCSI channel %u enabled, host target ID %d.\n",13961396- ha->board_name, i, info.host_addr[3 - i]);13971397-13981398-#if defined(DEBUG_DETECT)13991399- printk("%s: Vers. 0x%x, ocs %u, tar %u, trnxfr %u, more %u, SYNC 0x%x, "14001400- "sec. %u, infol %d, cpl %d spl %d.\n", name, info.version,14011401- info.ocsena, info.tarsup, info.trnxfr, info.morsup, info.sync,14021402- info.second, info.data_len, info.cp_len, info.sp_len);14031403-14041404- if (protocol_rev == 'B' || protocol_rev == 'C')14051405- printk("%s: isaena %u, forcaddr %u, max_id %u, max_chan %u, "14061406- "large_sg %u, res1 %u.\n", name, info.isaena,14071407- info.forcaddr, info.max_id, info.max_chan, info.large_sg,14081408- info.res1);14091409-14101410- if (protocol_rev == 'C')14111411- printk("%s: max_lun %u, m1 %u, idquest %u, pci %u, eisa %u, "14121412- "raidnum %u.\n", name, info.max_lun, info.m1,14131413- info.idquest, info.pci, info.eisa, info.raidnum);14141414-#endif14151415-14161416- if (ha->pdev) {14171417- pci_set_master(ha->pdev);14181418- if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32)))14191419- printk("%s: warning, pci_set_dma_mask failed.\n",14201420- ha->board_name);14211421- }14221422-14231423- return 1;14241424-14251425- freedma:14261426- if (subversion == ISA)14271427- free_dma(dma_channel);14281428- freeirq:14291429- free_irq(irq, &sha[j]);14301430- freelock:14311431- release_region(port_base, REGION_SIZE);14321432- fail:14331433- return 0;14341434-14351435- release:14361436- eata2x_release(shost);14371437- return 0;14381438-}14391439-14401440-static void internal_setup(char *str, int *ints)14411441-{14421442- int i, argc = ints[0];14431443- char *cur = str, *pc;14441444-14451445- if (argc > 0) {14461446- if (argc > MAX_INT_PARAM)14471447- argc = MAX_INT_PARAM;14481448-14491449- for (i = 0; i < argc; i++)14501450- io_port[i] = ints[i + 1];14511451-14521452- io_port[i] = 0;14531453- setup_done = 1;14541454- }14551455-14561456- while (cur && (pc = strchr(cur, ':'))) {14571457- int val = 0, c = *++pc;14581458-14591459- if (c == 'n' || c == 'N')14601460- val = 0;14611461- else if (c == 'y' || c == 'Y')14621462- val = 1;14631463- else14641464- val = (int)simple_strtoul(pc, NULL, 0);14651465-14661466- if (!strncmp(cur, "lc:", 3))14671467- linked_comm = val;14681468- else if (!strncmp(cur, "tm:", 3))14691469- tag_mode = val;14701470- else if (!strncmp(cur, "tc:", 3))14711471- tag_mode = val;14721472- else if (!strncmp(cur, "mq:", 3))14731473- max_queue_depth = val;14741474- else if (!strncmp(cur, "ls:", 3))14751475- link_statistics = val;14761476- else if (!strncmp(cur, "et:", 3))14771477- ext_tran = val;14781478- else if (!strncmp(cur, "rs:", 3))14791479- rev_scan = val;14801480- else if (!strncmp(cur, "ip:", 3))14811481- isa_probe = val;14821482- else if (!strncmp(cur, "ep:", 3))14831483- eisa_probe = val;14841484- else if (!strncmp(cur, "pp:", 3))14851485- pci_probe = val;14861486-14871487- if ((cur = strchr(cur, ',')))14881488- ++cur;14891489- }14901490-14911491- return;14921492-}14931493-14941494-static int option_setup(char *str)14951495-{14961496- int ints[MAX_INT_PARAM];14971497- char *cur = str;14981498- int i = 1;14991499-15001500- while (cur && isdigit(*cur) && i < MAX_INT_PARAM) {15011501- ints[i++] = simple_strtoul(cur, NULL, 0);15021502-15031503- if ((cur = strchr(cur, ',')) != NULL)15041504- cur++;15051505- }15061506-15071507- ints[0] = i - 1;15081508- internal_setup(cur, ints);15091509- return 1;15101510-}15111511-15121512-static void add_pci_ports(void)15131513-{15141514-#if defined(CONFIG_PCI)15151515- unsigned int addr, k;15161516- struct pci_dev *dev = NULL;15171517-15181518- for (k = 0; k < MAX_PCI; k++) {15191519-15201520- if (!(dev = pci_get_class(PCI_CLASS_STORAGE_SCSI << 8, dev)))15211521- break;15221522-15231523- if (pci_enable_device(dev)) {15241524-#if defined(DEBUG_PCI_DETECT)15251525- printk15261526- ("%s: detect, bus %d, devfn 0x%x, pci_enable_device failed.\n",15271527- driver_name, dev->bus->number, dev->devfn);15281528-#endif15291529-15301530- continue;15311531- }15321532-15331533- addr = pci_resource_start(dev, 0);15341534-15351535-#if defined(DEBUG_PCI_DETECT)15361536- printk("%s: detect, seq. %d, bus %d, devfn 0x%x, addr 0x%x.\n",15371537- driver_name, k, dev->bus->number, dev->devfn, addr);15381538-#endif15391539-15401540- /* Order addresses according to rev_scan value */15411541- io_port[MAX_INT_PARAM + (rev_scan ? (MAX_PCI - k) : (1 + k))] =15421542- addr + PCI_BASE_ADDRESS_0;15431543- }15441544-15451545- pci_dev_put(dev);15461546-#endif /* end CONFIG_PCI */15471547-}15481548-15491549-static int eata2x_detect(struct scsi_host_template *tpnt)15501550-{15511551- unsigned int j = 0, k;15521552-15531553- tpnt->proc_name = "eata2x";15541554-15551555- if (strlen(boot_options))15561556- option_setup(boot_options);15571557-15581558-#if defined(MODULE)15591559- /* io_port could have been modified when loading as a module */15601560- if (io_port[0] != SKIP) {15611561- setup_done = 1;15621562- io_port[MAX_INT_PARAM] = 0;15631563- }15641564-#endif15651565-15661566- for (k = MAX_INT_PARAM; io_port[k]; k++)15671567- if (io_port[k] == SKIP)15681568- continue;15691569- else if (io_port[k] <= MAX_ISA_ADDR) {15701570- if (!isa_probe)15711571- io_port[k] = SKIP;15721572- } else if (io_port[k] >= MIN_EISA_ADDR15731573- && io_port[k] <= MAX_EISA_ADDR) {15741574- if (!eisa_probe)15751575- io_port[k] = SKIP;15761576- }15771577-15781578- if (pci_probe) {15791579- if (!setup_done)15801580- add_pci_ports();15811581- else15821582- enable_pci_ports();15831583- }15841584-15851585- for (k = 0; io_port[k]; k++) {15861586-15871587- if (io_port[k] == SKIP)15881588- continue;15891589-15901590- if (j < MAX_BOARDS && port_detect(io_port[k], j, tpnt))15911591- j++;15921592- }15931593-15941594- num_boards = j;15951595- return j;15961596-}15971597-15981598-static void map_dma(unsigned int i, struct hostdata *ha)15991599-{16001600- unsigned int k, pci_dir;16011601- int count;16021602- struct scatterlist *sg;16031603- struct mscp *cpp;16041604- struct scsi_cmnd *SCpnt;16051605-16061606- cpp = &ha->cp[i];16071607- SCpnt = cpp->SCpnt;16081608- pci_dir = SCpnt->sc_data_direction;16091609-16101610- if (SCpnt->sense_buffer)16111611- cpp->sense_addr =16121612- H2DEV(pci_map_single(ha->pdev, SCpnt->sense_buffer,16131613- SCSI_SENSE_BUFFERSIZE, PCI_DMA_FROMDEVICE));16141614-16151615- cpp->sense_len = SCSI_SENSE_BUFFERSIZE;16161616-16171617- if (!scsi_sg_count(SCpnt)) {16181618- cpp->data_len = 0;16191619- return;16201620- }16211621-16221622- count = pci_map_sg(ha->pdev, scsi_sglist(SCpnt), scsi_sg_count(SCpnt),16231623- pci_dir);16241624- BUG_ON(!count);16251625-16261626- scsi_for_each_sg(SCpnt, sg, count, k) {16271627- cpp->sglist[k].address = H2DEV(sg_dma_address(sg));16281628- cpp->sglist[k].num_bytes = H2DEV(sg_dma_len(sg));16291629- }16301630-16311631- cpp->sg = 1;16321632- cpp->data_address = H2DEV(pci_map_single(ha->pdev, cpp->sglist,16331633- scsi_sg_count(SCpnt) *16341634- sizeof(struct sg_list),16351635- pci_dir));16361636- cpp->data_len = H2DEV((scsi_sg_count(SCpnt) * sizeof(struct sg_list)));16371637-}16381638-16391639-static void unmap_dma(unsigned int i, struct hostdata *ha)16401640-{16411641- unsigned int pci_dir;16421642- struct mscp *cpp;16431643- struct scsi_cmnd *SCpnt;16441644-16451645- cpp = &ha->cp[i];16461646- SCpnt = cpp->SCpnt;16471647- pci_dir = SCpnt->sc_data_direction;16481648-16491649- if (DEV2H(cpp->sense_addr))16501650- pci_unmap_single(ha->pdev, DEV2H(cpp->sense_addr),16511651- DEV2H(cpp->sense_len), PCI_DMA_FROMDEVICE);16521652-16531653- if (scsi_sg_count(SCpnt))16541654- pci_unmap_sg(ha->pdev, scsi_sglist(SCpnt), scsi_sg_count(SCpnt),16551655- pci_dir);16561656-16571657- if (!DEV2H(cpp->data_len))16581658- pci_dir = PCI_DMA_BIDIRECTIONAL;16591659-16601660- if (DEV2H(cpp->data_address))16611661- pci_unmap_single(ha->pdev, DEV2H(cpp->data_address),16621662- DEV2H(cpp->data_len), pci_dir);16631663-}16641664-16651665-static void sync_dma(unsigned int i, struct hostdata *ha)16661666-{16671667- unsigned int pci_dir;16681668- struct mscp *cpp;16691669- struct scsi_cmnd *SCpnt;16701670-16711671- cpp = &ha->cp[i];16721672- SCpnt = cpp->SCpnt;16731673- pci_dir = SCpnt->sc_data_direction;16741674-16751675- if (DEV2H(cpp->sense_addr))16761676- pci_dma_sync_single_for_cpu(ha->pdev, DEV2H(cpp->sense_addr),16771677- DEV2H(cpp->sense_len),16781678- PCI_DMA_FROMDEVICE);16791679-16801680- if (scsi_sg_count(SCpnt))16811681- pci_dma_sync_sg_for_cpu(ha->pdev, scsi_sglist(SCpnt),16821682- scsi_sg_count(SCpnt), pci_dir);16831683-16841684- if (!DEV2H(cpp->data_len))16851685- pci_dir = PCI_DMA_BIDIRECTIONAL;16861686-16871687- if (DEV2H(cpp->data_address))16881688- pci_dma_sync_single_for_cpu(ha->pdev,16891689- DEV2H(cpp->data_address),16901690- DEV2H(cpp->data_len), pci_dir);16911691-}16921692-16931693-static void scsi_to_dev_dir(unsigned int i, struct hostdata *ha)16941694-{16951695- unsigned int k;16961696-16971697- static const unsigned char data_out_cmds[] = {16981698- 0x0a, 0x2a, 0x15, 0x55, 0x04, 0x07, 0x18, 0x1d, 0x24, 0x2e,16991699- 0x30, 0x31, 0x32, 0x38, 0x39, 0x3a, 0x3b, 0x3d, 0x3f, 0x40,17001700- 0x41, 0x4c, 0xaa, 0xae, 0xb0, 0xb1, 0xb2, 0xb6, 0xea, 0x1b, 0x5d17011701- };17021702-17031703- static const unsigned char data_none_cmds[] = {17041704- 0x01, 0x0b, 0x10, 0x11, 0x13, 0x16, 0x17, 0x19, 0x2b, 0x1e,17051705- 0x2c, 0xac, 0x2f, 0xaf, 0x33, 0xb3, 0x35, 0x36, 0x45, 0x47,17061706- 0x48, 0x49, 0xa9, 0x4b, 0xa5, 0xa6, 0xb5, 0x0017071707- };17081708-17091709- struct mscp *cpp;17101710- struct scsi_cmnd *SCpnt;17111711-17121712- cpp = &ha->cp[i];17131713- SCpnt = cpp->SCpnt;17141714-17151715- if (SCpnt->sc_data_direction == DMA_FROM_DEVICE) {17161716- cpp->din = 1;17171717- cpp->dout = 0;17181718- return;17191719- } else if (SCpnt->sc_data_direction == DMA_TO_DEVICE) {17201720- cpp->din = 0;17211721- cpp->dout = 1;17221722- return;17231723- } else if (SCpnt->sc_data_direction == DMA_NONE) {17241724- cpp->din = 0;17251725- cpp->dout = 0;17261726- return;17271727- }17281728-17291729- if (SCpnt->sc_data_direction != DMA_BIDIRECTIONAL)17301730- panic("%s: qcomm, invalid SCpnt->sc_data_direction.\n",17311731- ha->board_name);17321732-17331733- for (k = 0; k < ARRAY_SIZE(data_out_cmds); k++)17341734- if (SCpnt->cmnd[0] == data_out_cmds[k]) {17351735- cpp->dout = 1;17361736- break;17371737- }17381738-17391739- if ((cpp->din = !cpp->dout))17401740- for (k = 0; k < ARRAY_SIZE(data_none_cmds); k++)17411741- if (SCpnt->cmnd[0] == data_none_cmds[k]) {17421742- cpp->din = 0;17431743- break;17441744- }17451745-17461746-}17471747-17481748-static int eata2x_queuecommand_lck(struct scsi_cmnd *SCpnt,17491749- void (*done) (struct scsi_cmnd *))17501750-{17511751- struct Scsi_Host *shost = SCpnt->device->host;17521752- struct hostdata *ha = (struct hostdata *)shost->hostdata;17531753- unsigned int i, k;17541754- struct mscp *cpp;17551755-17561756- if (SCpnt->host_scribble)17571757- panic("%s: qcomm, SCpnt %p already active.\n",17581758- ha->board_name, SCpnt);17591759-17601760- /* i is the mailbox number, look for the first free mailbox17611761- starting from last_cp_used */17621762- i = ha->last_cp_used + 1;17631763-17641764- for (k = 0; k < shost->can_queue; k++, i++) {17651765- if (i >= shost->can_queue)17661766- i = 0;17671767- if (ha->cp_stat[i] == FREE) {17681768- ha->last_cp_used = i;17691769- break;17701770- }17711771- }17721772-17731773- if (k == shost->can_queue) {17741774- printk("%s: qcomm, no free mailbox.\n", ha->board_name);17751775- return 1;17761776- }17771777-17781778- /* Set pointer to control packet structure */17791779- cpp = &ha->cp[i];17801780-17811781- memset(cpp, 0, sizeof(struct mscp) - CP_TAIL_SIZE);17821782-17831783- /* Set pointer to status packet structure, Big Endian format */17841784- cpp->sp_dma_addr = H2DEV(ha->sp_dma_addr);17851785-17861786- SCpnt->scsi_done = done;17871787- cpp->cpp_index = i;17881788- SCpnt->host_scribble = (unsigned char *)&cpp->cpp_index;17891789-17901790- if (do_trace)17911791- scmd_printk(KERN_INFO, SCpnt,17921792- "qcomm, mbox %d.\n", i);17931793-17941794- cpp->reqsen = 1;17951795- cpp->dispri = 1;17961796-#if 017971797- if (SCpnt->device->type == TYPE_TAPE)17981798- cpp->hbaci = 1;17991799-#endif18001800- cpp->one = 1;18011801- cpp->channel = SCpnt->device->channel;18021802- cpp->target = SCpnt->device->id;18031803- cpp->lun = SCpnt->device->lun;18041804- cpp->SCpnt = SCpnt;18051805- memcpy(cpp->cdb, SCpnt->cmnd, SCpnt->cmd_len);18061806-18071807- /* Use data transfer direction SCpnt->sc_data_direction */18081808- scsi_to_dev_dir(i, ha);18091809-18101810- /* Map DMA buffers and SG list */18111811- map_dma(i, ha);18121812-18131813- if (linked_comm && SCpnt->device->queue_depth > 218141814- && TLDEV(SCpnt->device->type)) {18151815- ha->cp_stat[i] = READY;18161816- flush_dev(SCpnt->device, blk_rq_pos(SCpnt->request), ha, 0);18171817- return 0;18181818- }18191819-18201820- /* Send control packet to the board */18211821- if (do_dma(shost->io_port, cpp->cp_dma_addr, SEND_CP_DMA)) {18221822- unmap_dma(i, ha);18231823- SCpnt->host_scribble = NULL;18241824- scmd_printk(KERN_INFO, SCpnt, "qcomm, adapter busy.\n");18251825- return 1;18261826- }18271827-18281828- ha->cp_stat[i] = IN_USE;18291829- return 0;18301830-}18311831-18321832-static DEF_SCSI_QCMD(eata2x_queuecommand)18331833-18341834-static int eata2x_eh_abort(struct scsi_cmnd *SCarg)18351835-{18361836- struct Scsi_Host *shost = SCarg->device->host;18371837- struct hostdata *ha = (struct hostdata *)shost->hostdata;18381838- unsigned int i;18391839-18401840- if (SCarg->host_scribble == NULL) {18411841- scmd_printk(KERN_INFO, SCarg, "abort, cmd inactive.\n");18421842- return SUCCESS;18431843- }18441844-18451845- i = *(unsigned int *)SCarg->host_scribble;18461846- scmd_printk(KERN_WARNING, SCarg, "abort, mbox %d.\n", i);18471847-18481848- if (i >= shost->can_queue)18491849- panic("%s: abort, invalid SCarg->host_scribble.\n", ha->board_name);18501850-18511851- if (wait_on_busy(shost->io_port, MAXLOOP)) {18521852- printk("%s: abort, timeout error.\n", ha->board_name);18531853- return FAILED;18541854- }18551855-18561856- if (ha->cp_stat[i] == FREE) {18571857- printk("%s: abort, mbox %d is free.\n", ha->board_name, i);18581858- return SUCCESS;18591859- }18601860-18611861- if (ha->cp_stat[i] == IN_USE) {18621862- printk("%s: abort, mbox %d is in use.\n", ha->board_name, i);18631863-18641864- if (SCarg != ha->cp[i].SCpnt)18651865- panic("%s: abort, mbox %d, SCarg %p, cp SCpnt %p.\n",18661866- ha->board_name, i, SCarg, ha->cp[i].SCpnt);18671867-18681868- if (inb(shost->io_port + REG_AUX_STATUS) & IRQ_ASSERTED)18691869- printk("%s: abort, mbox %d, interrupt pending.\n",18701870- ha->board_name, i);18711871-18721872- return FAILED;18731873- }18741874-18751875- if (ha->cp_stat[i] == IN_RESET) {18761876- printk("%s: abort, mbox %d is in reset.\n", ha->board_name, i);18771877- return FAILED;18781878- }18791879-18801880- if (ha->cp_stat[i] == LOCKED) {18811881- printk("%s: abort, mbox %d is locked.\n", ha->board_name, i);18821882- return SUCCESS;18831883- }18841884-18851885- if (ha->cp_stat[i] == READY || ha->cp_stat[i] == ABORTING) {18861886- unmap_dma(i, ha);18871887- SCarg->result = DID_ABORT << 16;18881888- SCarg->host_scribble = NULL;18891889- ha->cp_stat[i] = FREE;18901890- printk("%s, abort, mbox %d ready, DID_ABORT, done.\n",18911891- ha->board_name, i);18921892- SCarg->scsi_done(SCarg);18931893- return SUCCESS;18941894- }18951895-18961896- panic("%s: abort, mbox %d, invalid cp_stat.\n", ha->board_name, i);18971897-}18981898-18991899-static int eata2x_eh_host_reset(struct scsi_cmnd *SCarg)19001900-{19011901- unsigned int i, time, k, c, limit = 0;19021902- struct scsi_cmnd *SCpnt;19031903- struct Scsi_Host *shost = SCarg->device->host;19041904- struct hostdata *ha = (struct hostdata *)shost->hostdata;19051905-19061906- scmd_printk(KERN_INFO, SCarg, "reset, enter.\n");19071907-19081908- spin_lock_irq(shost->host_lock);19091909-19101910- if (SCarg->host_scribble == NULL)19111911- printk("%s: reset, inactive.\n", ha->board_name);19121912-19131913- if (ha->in_reset) {19141914- printk("%s: reset, exit, already in reset.\n", ha->board_name);19151915- spin_unlock_irq(shost->host_lock);19161916- return FAILED;19171917- }19181918-19191919- if (wait_on_busy(shost->io_port, MAXLOOP)) {19201920- printk("%s: reset, exit, timeout error.\n", ha->board_name);19211921- spin_unlock_irq(shost->host_lock);19221922- return FAILED;19231923- }19241924-19251925- ha->retries = 0;19261926-19271927- for (c = 0; c <= shost->max_channel; c++)19281928- for (k = 0; k < shost->max_id; k++) {19291929- ha->target_redo[k][c] = 1;19301930- ha->target_to[k][c] = 0;19311931- }19321932-19331933- for (i = 0; i < shost->can_queue; i++) {19341934-19351935- if (ha->cp_stat[i] == FREE)19361936- continue;19371937-19381938- if (ha->cp_stat[i] == LOCKED) {19391939- ha->cp_stat[i] = FREE;19401940- printk("%s: reset, locked mbox %d forced free.\n",19411941- ha->board_name, i);19421942- continue;19431943- }19441944-19451945- if (!(SCpnt = ha->cp[i].SCpnt))19461946- panic("%s: reset, mbox %d, SCpnt == NULL.\n", ha->board_name, i);19471947-19481948- if (ha->cp_stat[i] == READY || ha->cp_stat[i] == ABORTING) {19491949- ha->cp_stat[i] = ABORTING;19501950- printk("%s: reset, mbox %d aborting.\n",19511951- ha->board_name, i);19521952- }19531953-19541954- else {19551955- ha->cp_stat[i] = IN_RESET;19561956- printk("%s: reset, mbox %d in reset.\n",19571957- ha->board_name, i);19581958- }19591959-19601960- if (SCpnt->host_scribble == NULL)19611961- panic("%s: reset, mbox %d, garbled SCpnt.\n", ha->board_name, i);19621962-19631963- if (*(unsigned int *)SCpnt->host_scribble != i)19641964- panic("%s: reset, mbox %d, index mismatch.\n", ha->board_name, i);19651965-19661966- if (SCpnt->scsi_done == NULL)19671967- panic("%s: reset, mbox %d, SCpnt->scsi_done == NULL.\n",19681968- ha->board_name, i);19691969- }19701970-19711971- if (do_dma(shost->io_port, 0, RESET_PIO)) {19721972- printk("%s: reset, cannot reset, timeout error.\n", ha->board_name);19731973- spin_unlock_irq(shost->host_lock);19741974- return FAILED;19751975- }19761976-19771977- printk("%s: reset, board reset done, enabling interrupts.\n", ha->board_name);19781978-19791979-#if defined(DEBUG_RESET)19801980- do_trace = 1;19811981-#endif19821982-19831983- ha->in_reset = 1;19841984-19851985- spin_unlock_irq(shost->host_lock);19861986-19871987- /* FIXME: use a sleep instead */19881988- time = jiffies;19891989- while ((jiffies - time) < (10 * HZ) && limit++ < 200000)19901990- udelay(100L);19911991-19921992- spin_lock_irq(shost->host_lock);19931993-19941994- printk("%s: reset, interrupts disabled, loops %d.\n", ha->board_name, limit);19951995-19961996- for (i = 0; i < shost->can_queue; i++) {19971997-19981998- if (ha->cp_stat[i] == IN_RESET) {19991999- SCpnt = ha->cp[i].SCpnt;20002000- unmap_dma(i, ha);20012001- SCpnt->result = DID_RESET << 16;20022002- SCpnt->host_scribble = NULL;20032003-20042004- /* This mailbox is still waiting for its interrupt */20052005- ha->cp_stat[i] = LOCKED;20062006-20072007- printk20082008- ("%s, reset, mbox %d locked, DID_RESET, done.\n",20092009- ha->board_name, i);20102010- }20112011-20122012- else if (ha->cp_stat[i] == ABORTING) {20132013- SCpnt = ha->cp[i].SCpnt;20142014- unmap_dma(i, ha);20152015- SCpnt->result = DID_RESET << 16;20162016- SCpnt->host_scribble = NULL;20172017-20182018- /* This mailbox was never queued to the adapter */20192019- ha->cp_stat[i] = FREE;20202020-20212021- printk20222022- ("%s, reset, mbox %d aborting, DID_RESET, done.\n",20232023- ha->board_name, i);20242024- }20252025-20262026- else20272027- /* Any other mailbox has already been set free by interrupt */20282028- continue;20292029-20302030- SCpnt->scsi_done(SCpnt);20312031- }20322032-20332033- ha->in_reset = 0;20342034- do_trace = 0;20352035-20362036- printk("%s: reset, exit.\n", ha->board_name);20372037-20382038- spin_unlock_irq(shost->host_lock);20392039- return SUCCESS;20402040-}20412041-20422042-int eata2x_bios_param(struct scsi_device *sdev, struct block_device *bdev,20432043- sector_t capacity, int *dkinfo)20442044-{20452045- unsigned int size = capacity;20462046-20472047- if (ext_tran || (scsicam_bios_param(bdev, capacity, dkinfo) < 0)) {20482048- dkinfo[0] = 255;20492049- dkinfo[1] = 63;20502050- dkinfo[2] = size / (dkinfo[0] * dkinfo[1]);20512051- }20522052-#if defined (DEBUG_GEOMETRY)20532053- printk("%s: bios_param, head=%d, sec=%d, cyl=%d.\n", driver_name,20542054- dkinfo[0], dkinfo[1], dkinfo[2]);20552055-#endif20562056-20572057- return 0;20582058-}20592059-20602060-static void sort(unsigned long sk[], unsigned int da[], unsigned int n,20612061- unsigned int rev)20622062-{20632063- unsigned int i, j, k, y;20642064- unsigned long x;20652065-20662066- for (i = 0; i < n - 1; i++) {20672067- k = i;20682068-20692069- for (j = k + 1; j < n; j++)20702070- if (rev) {20712071- if (sk[j] > sk[k])20722072- k = j;20732073- } else {20742074- if (sk[j] < sk[k])20752075- k = j;20762076- }20772077-20782078- if (k != i) {20792079- x = sk[k];20802080- sk[k] = sk[i];20812081- sk[i] = x;20822082- y = da[k];20832083- da[k] = da[i];20842084- da[i] = y;20852085- }20862086- }20872087-20882088- return;20892089-}20902090-20912091-static int reorder(struct hostdata *ha, unsigned long cursec,20922092- unsigned int ihdlr, unsigned int il[], unsigned int n_ready)20932093-{20942094- struct scsi_cmnd *SCpnt;20952095- struct mscp *cpp;20962096- unsigned int k, n;20972097- unsigned int rev = 0, s = 1, r = 1;20982098- unsigned int input_only = 1, overlap = 0;20992099- unsigned long sl[n_ready], pl[n_ready], ll[n_ready];21002100- unsigned long maxsec = 0, minsec = ULONG_MAX, seek = 0, iseek = 0;21012101- unsigned long ioseek = 0;21022102-21032103- static unsigned int flushcount = 0, batchcount = 0, sortcount = 0;21042104- static unsigned int readycount = 0, ovlcount = 0, inputcount = 0;21052105- static unsigned int readysorted = 0, revcount = 0;21062106- static unsigned long seeksorted = 0, seeknosort = 0;21072107-21082108- if (link_statistics && !(++flushcount % link_statistics))21092109- printk("fc %d bc %d ic %d oc %d rc %d rs %d sc %d re %d"21102110- " av %ldK as %ldK.\n", flushcount, batchcount,21112111- inputcount, ovlcount, readycount, readysorted, sortcount,21122112- revcount, seeknosort / (readycount + 1),21132113- seeksorted / (readycount + 1));21142114-21152115- if (n_ready <= 1)21162116- return 0;21172117-21182118- for (n = 0; n < n_ready; n++) {21192119- k = il[n];21202120- cpp = &ha->cp[k];21212121- SCpnt = cpp->SCpnt;21222122-21232123- if (!cpp->din)21242124- input_only = 0;21252125-21262126- if (blk_rq_pos(SCpnt->request) < minsec)21272127- minsec = blk_rq_pos(SCpnt->request);21282128- if (blk_rq_pos(SCpnt->request) > maxsec)21292129- maxsec = blk_rq_pos(SCpnt->request);21302130-21312131- sl[n] = blk_rq_pos(SCpnt->request);21322132- ioseek += blk_rq_sectors(SCpnt->request);21332133-21342134- if (!n)21352135- continue;21362136-21372137- if (sl[n] < sl[n - 1])21382138- s = 0;21392139- if (sl[n] > sl[n - 1])21402140- r = 0;21412141-21422142- if (link_statistics) {21432143- if (sl[n] > sl[n - 1])21442144- seek += sl[n] - sl[n - 1];21452145- else21462146- seek += sl[n - 1] - sl[n];21472147- }21482148-21492149- }21502150-21512151- if (link_statistics) {21522152- if (cursec > sl[0])21532153- seek += cursec - sl[0];21542154- else21552155- seek += sl[0] - cursec;21562156- }21572157-21582158- if (cursec > ((maxsec + minsec) / 2))21592159- rev = 1;21602160-21612161- if (ioseek > ((maxsec - minsec) / 2))21622162- rev = 0;21632163-21642164- if (!((rev && r) || (!rev && s)))21652165- sort(sl, il, n_ready, rev);21662166-21672167- if (!input_only)21682168- for (n = 0; n < n_ready; n++) {21692169- k = il[n];21702170- cpp = &ha->cp[k];21712171- SCpnt = cpp->SCpnt;21722172- ll[n] = blk_rq_sectors(SCpnt->request);21732173- pl[n] = SCpnt->serial_number;21742174-21752175- if (!n)21762176- continue;21772177-21782178- if ((sl[n] == sl[n - 1])21792179- || (!rev && ((sl[n - 1] + ll[n - 1]) > sl[n]))21802180- || (rev && ((sl[n] + ll[n]) > sl[n - 1])))21812181- overlap = 1;21822182- }21832183-21842184- if (overlap)21852185- sort(pl, il, n_ready, 0);21862186-21872187- if (link_statistics) {21882188- if (cursec > sl[0])21892189- iseek = cursec - sl[0];21902190- else21912191- iseek = sl[0] - cursec;21922192- batchcount++;21932193- readycount += n_ready;21942194- seeknosort += seek / 1024;21952195- if (input_only)21962196- inputcount++;21972197- if (overlap) {21982198- ovlcount++;21992199- seeksorted += iseek / 1024;22002200- } else22012201- seeksorted += (iseek + maxsec - minsec) / 1024;22022202- if (rev && !r) {22032203- revcount++;22042204- readysorted += n_ready;22052205- }22062206- if (!rev && !s) {22072207- sortcount++;22082208- readysorted += n_ready;22092209- }22102210- }22112211-#if defined(DEBUG_LINKED_COMMANDS)22122212- if (link_statistics && (overlap || !(flushcount % link_statistics)))22132213- for (n = 0; n < n_ready; n++) {22142214- k = il[n];22152215- cpp = &ha->cp[k];22162216- SCpnt = cpp->SCpnt;22172217- scmd_printk(KERN_INFO, SCpnt,22182218- "%s mb %d fc %d nr %d sec %ld ns %u"22192219- " cur %ld s:%c r:%c rev:%c in:%c ov:%c xd %d.\n",22202220- (ihdlr ? "ihdlr" : "qcomm"),22212221- k, flushcount,22222222- n_ready, blk_rq_pos(SCpnt->request),22232223- blk_rq_sectors(SCpnt->request), cursec, YESNO(s),22242224- YESNO(r), YESNO(rev), YESNO(input_only),22252225- YESNO(overlap), cpp->din);22262226- }22272227-#endif22282228- return overlap;22292229-}22302230-22312231-static void flush_dev(struct scsi_device *dev, unsigned long cursec,22322232- struct hostdata *ha, unsigned int ihdlr)22332233-{22342234- struct scsi_cmnd *SCpnt;22352235- struct mscp *cpp;22362236- unsigned int k, n, n_ready = 0, il[MAX_MAILBOXES];22372237-22382238- for (k = 0; k < dev->host->can_queue; k++) {22392239-22402240- if (ha->cp_stat[k] != READY && ha->cp_stat[k] != IN_USE)22412241- continue;22422242-22432243- cpp = &ha->cp[k];22442244- SCpnt = cpp->SCpnt;22452245-22462246- if (SCpnt->device != dev)22472247- continue;22482248-22492249- if (ha->cp_stat[k] == IN_USE)22502250- return;22512251-22522252- il[n_ready++] = k;22532253- }22542254-22552255- if (reorder(ha, cursec, ihdlr, il, n_ready))22562256- n_ready = 1;22572257-22582258- for (n = 0; n < n_ready; n++) {22592259- k = il[n];22602260- cpp = &ha->cp[k];22612261- SCpnt = cpp->SCpnt;22622262-22632263- if (do_dma(dev->host->io_port, cpp->cp_dma_addr, SEND_CP_DMA)) {22642264- scmd_printk(KERN_INFO, SCpnt,22652265- "%s, mbox %d, adapter"22662266- " busy, will abort.\n",22672267- (ihdlr ? "ihdlr" : "qcomm"),22682268- k);22692269- ha->cp_stat[k] = ABORTING;22702270- continue;22712271- }22722272-22732273- ha->cp_stat[k] = IN_USE;22742274- }22752275-}22762276-22772277-static irqreturn_t ihdlr(struct Scsi_Host *shost)22782278-{22792279- struct scsi_cmnd *SCpnt;22802280- unsigned int i, k, c, status, tstatus, reg;22812281- struct mssp *spp;22822282- struct mscp *cpp;22832283- struct hostdata *ha = (struct hostdata *)shost->hostdata;22842284- int irq = shost->irq;22852285-22862286- /* Check if this board need to be serviced */22872287- if (!(inb(shost->io_port + REG_AUX_STATUS) & IRQ_ASSERTED))22882288- goto none;22892289-22902290- ha->iocount++;22912291-22922292- if (do_trace)22932293- printk("%s: ihdlr, enter, irq %d, count %d.\n", ha->board_name, irq,22942294- ha->iocount);22952295-22962296- /* Check if this board is still busy */22972297- if (wait_on_busy(shost->io_port, 20 * MAXLOOP)) {22982298- reg = inb(shost->io_port + REG_STATUS);22992299- printk23002300- ("%s: ihdlr, busy timeout error, irq %d, reg 0x%x, count %d.\n",23012301- ha->board_name, irq, reg, ha->iocount);23022302- goto none;23032303- }23042304-23052305- spp = &ha->sp;23062306-23072307- /* Make a local copy just before clearing the interrupt indication */23082308- memcpy(spp, ha->sp_cpu_addr, sizeof(struct mssp));23092309-23102310- /* Clear the completion flag and cp pointer on the dynamic copy of sp */23112311- memset(ha->sp_cpu_addr, 0, sizeof(struct mssp));23122312-23132313- /* Read the status register to clear the interrupt indication */23142314- reg = inb(shost->io_port + REG_STATUS);23152315-23162316-#if defined (DEBUG_INTERRUPT)23172317- {23182318- unsigned char *bytesp;23192319- int cnt;23202320- bytesp = (unsigned char *)spp;23212321- if (ha->iocount < 200) {23222322- printk("sp[] =");23232323- for (cnt = 0; cnt < 15; cnt++)23242324- printk(" 0x%x", bytesp[cnt]);23252325- printk("\n");23262326- }23272327- }23282328-#endif23292329-23302330- /* Reject any sp with supspect data */23312331- if (spp->eoc == 0 && ha->iocount > 1)23322332- printk23332333- ("%s: ihdlr, spp->eoc == 0, irq %d, reg 0x%x, count %d.\n",23342334- ha->board_name, irq, reg, ha->iocount);23352335- if (spp->cpp_index < 0 || spp->cpp_index >= shost->can_queue)23362336- printk23372337- ("%s: ihdlr, bad spp->cpp_index %d, irq %d, reg 0x%x, count %d.\n",23382338- ha->board_name, spp->cpp_index, irq, reg, ha->iocount);23392339- if (spp->eoc == 0 || spp->cpp_index < 023402340- || spp->cpp_index >= shost->can_queue)23412341- goto handled;23422342-23432343- /* Find the mailbox to be serviced on this board */23442344- i = spp->cpp_index;23452345-23462346- cpp = &(ha->cp[i]);23472347-23482348-#if defined(DEBUG_GENERATE_ABORTS)23492349- if ((ha->iocount > 500) && ((ha->iocount % 500) < 3))23502350- goto handled;23512351-#endif23522352-23532353- if (ha->cp_stat[i] == IGNORE) {23542354- ha->cp_stat[i] = FREE;23552355- goto handled;23562356- } else if (ha->cp_stat[i] == LOCKED) {23572357- ha->cp_stat[i] = FREE;23582358- printk("%s: ihdlr, mbox %d unlocked, count %d.\n", ha->board_name, i,23592359- ha->iocount);23602360- goto handled;23612361- } else if (ha->cp_stat[i] == FREE) {23622362- printk("%s: ihdlr, mbox %d is free, count %d.\n", ha->board_name, i,23632363- ha->iocount);23642364- goto handled;23652365- } else if (ha->cp_stat[i] == IN_RESET)23662366- printk("%s: ihdlr, mbox %d is in reset.\n", ha->board_name, i);23672367- else if (ha->cp_stat[i] != IN_USE)23682368- panic("%s: ihdlr, mbox %d, invalid cp_stat: %d.\n",23692369- ha->board_name, i, ha->cp_stat[i]);23702370-23712371- ha->cp_stat[i] = FREE;23722372- SCpnt = cpp->SCpnt;23732373-23742374- if (SCpnt == NULL)23752375- panic("%s: ihdlr, mbox %d, SCpnt == NULL.\n", ha->board_name, i);23762376-23772377- if (SCpnt->host_scribble == NULL)23782378- panic("%s: ihdlr, mbox %d, SCpnt %p garbled.\n", ha->board_name,23792379- i, SCpnt);23802380-23812381- if (*(unsigned int *)SCpnt->host_scribble != i)23822382- panic("%s: ihdlr, mbox %d, index mismatch %d.\n",23832383- ha->board_name, i,23842384- *(unsigned int *)SCpnt->host_scribble);23852385-23862386- sync_dma(i, ha);23872387-23882388- if (linked_comm && SCpnt->device->queue_depth > 223892389- && TLDEV(SCpnt->device->type))23902390- flush_dev(SCpnt->device, blk_rq_pos(SCpnt->request), ha, 1);23912391-23922392- tstatus = status_byte(spp->target_status);23932393-23942394-#if defined(DEBUG_GENERATE_ERRORS)23952395- if ((ha->iocount > 500) && ((ha->iocount % 200) < 2))23962396- spp->adapter_status = 0x01;23972397-#endif23982398-23992399- switch (spp->adapter_status) {24002400- case ASOK: /* status OK */24012401-24022402- /* Forces a reset if a disk drive keeps returning BUSY */24032403- if (tstatus == BUSY && SCpnt->device->type != TYPE_TAPE)24042404- status = DID_ERROR << 16;24052405-24062406- /* If there was a bus reset, redo operation on each target */24072407- else if (tstatus != GOOD && SCpnt->device->type == TYPE_DISK24082408- && ha->target_redo[SCpnt->device->id][SCpnt->24092409- device->24102410- channel])24112411- status = DID_BUS_BUSY << 16;24122412-24132413- /* Works around a flaw in scsi.c */24142414- else if (tstatus == CHECK_CONDITION24152415- && SCpnt->device->type == TYPE_DISK24162416- && (SCpnt->sense_buffer[2] & 0xf) == RECOVERED_ERROR)24172417- status = DID_BUS_BUSY << 16;24182418-24192419- else24202420- status = DID_OK << 16;24212421-24222422- if (tstatus == GOOD)24232423- ha->target_redo[SCpnt->device->id][SCpnt->device->24242424- channel] = 0;24252425-24262426- if (spp->target_status && SCpnt->device->type == TYPE_DISK &&24272427- (!(tstatus == CHECK_CONDITION && ha->iocount <= 1000 &&24282428- (SCpnt->sense_buffer[2] & 0xf) == NOT_READY)))24292429- printk("%s: ihdlr, target %d.%d:%d, "24302430- "target_status 0x%x, sense key 0x%x.\n",24312431- ha->board_name,24322432- SCpnt->device->channel, SCpnt->device->id,24332433- (u8)SCpnt->device->lun,24342434- spp->target_status, SCpnt->sense_buffer[2]);24352435-24362436- ha->target_to[SCpnt->device->id][SCpnt->device->channel] = 0;24372437-24382438- if (ha->last_retried_pid == SCpnt->serial_number)24392439- ha->retries = 0;24402440-24412441- break;24422442- case ASST: /* Selection Time Out */24432443- case 0x02: /* Command Time Out */24442444-24452445- if (ha->target_to[SCpnt->device->id][SCpnt->device->channel] > 1)24462446- status = DID_ERROR << 16;24472447- else {24482448- status = DID_TIME_OUT << 16;24492449- ha->target_to[SCpnt->device->id][SCpnt->device->24502450- channel]++;24512451- }24522452-24532453- break;24542454-24552455- /* Perform a limited number of internal retries */24562456- case 0x03: /* SCSI Bus Reset Received */24572457- case 0x04: /* Initial Controller Power-up */24582458-24592459- for (c = 0; c <= shost->max_channel; c++)24602460- for (k = 0; k < shost->max_id; k++)24612461- ha->target_redo[k][c] = 1;24622462-24632463- if (SCpnt->device->type != TYPE_TAPE24642464- && ha->retries < MAX_INTERNAL_RETRIES) {24652465-24662466-#if defined(DID_SOFT_ERROR)24672467- status = DID_SOFT_ERROR << 16;24682468-#else24692469- status = DID_BUS_BUSY << 16;24702470-#endif24712471-24722472- ha->retries++;24732473- ha->last_retried_pid = SCpnt->serial_number;24742474- } else24752475- status = DID_ERROR << 16;24762476-24772477- break;24782478- case 0x05: /* Unexpected Bus Phase */24792479- case 0x06: /* Unexpected Bus Free */24802480- case 0x07: /* Bus Parity Error */24812481- case 0x08: /* SCSI Hung */24822482- case 0x09: /* Unexpected Message Reject */24832483- case 0x0a: /* SCSI Bus Reset Stuck */24842484- case 0x0b: /* Auto Request-Sense Failed */24852485- case 0x0c: /* Controller Ram Parity Error */24862486- default:24872487- status = DID_ERROR << 16;24882488- break;24892489- }24902490-24912491- SCpnt->result = status | spp->target_status;24922492-24932493-#if defined(DEBUG_INTERRUPT)24942494- if (SCpnt->result || do_trace)24952495-#else24962496- if ((spp->adapter_status != ASOK && ha->iocount > 1000) ||24972497- (spp->adapter_status != ASOK &&24982498- spp->adapter_status != ASST && ha->iocount <= 1000) ||24992499- do_trace || msg_byte(spp->target_status))25002500-#endif25012501- scmd_printk(KERN_INFO, SCpnt, "ihdlr, mbox %2d, err 0x%x:%x,"25022502- " reg 0x%x, count %d.\n",25032503- i, spp->adapter_status, spp->target_status,25042504- reg, ha->iocount);25052505-25062506- unmap_dma(i, ha);25072507-25082508- /* Set the command state to inactive */25092509- SCpnt->host_scribble = NULL;25102510-25112511- SCpnt->scsi_done(SCpnt);25122512-25132513- if (do_trace)25142514- printk("%s: ihdlr, exit, irq %d, count %d.\n", ha->board_name,25152515- irq, ha->iocount);25162516-25172517- handled:25182518- return IRQ_HANDLED;25192519- none:25202520- return IRQ_NONE;25212521-}25222522-25232523-static irqreturn_t do_interrupt_handler(int dummy, void *shap)25242524-{25252525- struct Scsi_Host *shost;25262526- unsigned int j;25272527- unsigned long spin_flags;25282528- irqreturn_t ret;25292529-25302530- /* Check if the interrupt must be processed by this handler */25312531- if ((j = (unsigned int)((char *)shap - sha)) >= num_boards)25322532- return IRQ_NONE;25332533- shost = sh[j];25342534-25352535- spin_lock_irqsave(shost->host_lock, spin_flags);25362536- ret = ihdlr(shost);25372537- spin_unlock_irqrestore(shost->host_lock, spin_flags);25382538- return ret;25392539-}25402540-25412541-static int eata2x_release(struct Scsi_Host *shost)25422542-{25432543- struct hostdata *ha = (struct hostdata *)shost->hostdata;25442544- unsigned int i;25452545-25462546- for (i = 0; i < shost->can_queue; i++)25472547- kfree((&ha->cp[i])->sglist);25482548-25492549- for (i = 0; i < shost->can_queue; i++)25502550- pci_unmap_single(ha->pdev, ha->cp[i].cp_dma_addr,25512551- sizeof(struct mscp), PCI_DMA_BIDIRECTIONAL);25522552-25532553- if (ha->sp_cpu_addr)25542554- pci_free_consistent(ha->pdev, sizeof(struct mssp),25552555- ha->sp_cpu_addr, ha->sp_dma_addr);25562556-25572557- free_irq(shost->irq, &sha[ha->board_number]);25582558-25592559- if (shost->dma_channel != NO_DMA)25602560- free_dma(shost->dma_channel);25612561-25622562- release_region(shost->io_port, shost->n_io_port);25632563- scsi_unregister(shost);25642564- return 0;25652565-}25662566-25672567-#include "scsi_module.c"25682568-25692569-#ifndef MODULE25702570-__setup("eata=", option_setup);25712571-#endif /* end MODULE */
-401
drivers/scsi/eata_generic.h
···11-/* SPDX-License-Identifier: GPL-2.0 */22-/********************************************************33-* Header file for eata_dma.c and eata_pio.c *44-* Linux EATA SCSI drivers *55-* (c) 1993-96 Michael Neuffer *66-* mike@i-Connect.Net *77-* neuffer@mail.uni-mainz.de *88-*********************************************************99-* last change: 96/08/14 *1010-********************************************************/1111-1212-1313-#ifndef _EATA_GENERIC_H1414-#define _EATA_GENERIC_H1515-1616-1717-1818-/*********************************************1919- * Misc. definitions *2020- *********************************************/2121-2222-#define R_LIMIT 0x200002323-2424-#define MAXISA 42525-#define MAXEISA 16 2626-#define MAXPCI 162727-#define MAXIRQ 16 2828-#define MAXTARGET 162929-#define MAXCHANNEL 33030-3131-#define IS_ISA 'I'3232-#define IS_EISA 'E'3333-#define IS_PCI 'P'3434-3535-#define BROKEN_INQUIRY 13636-3737-#define BUSMASTER 0xff3838-#define PIO 0xfe3939-4040-#define EATA_SIGNATURE 0x45415441 /* BIG ENDIAN coded "EATA" sig. */4141-4242-#define DPT_ID1 0x124343-#define DPT_ID2 0x144444-4545-#define ATT_ID1 0x064646-#define ATT_ID2 0x944747-#define ATT_ID3 0x04848-4949-#define NEC_ID1 0x385050-#define NEC_ID2 0xa35151-#define NEC_ID3 0x825252-5353-5454-#define EATA_CP_SIZE 445555-5656-#define MAX_PCI_DEVICES 32 /* Maximum # Of Devices Per Bus */5757-#define MAX_METHOD_2 16 /* Max Devices For Method 2 */5858-#define MAX_PCI_BUS 16 /* Maximum # Of Busses Allowed */5959-6060-#define SG_SIZE 64 6161-#define SG_SIZE_BIG 252 /* max. 8096 elements, 64k */6262-6363-#define UPPER_DEVICE_QUEUE_LIMIT 64 /* The limit we have to set for the 6464- * device queue to keep the broken 6565- * midlevel SCSI code from producing6666- * bogus timeouts6767- */6868-6969-#define TYPE_DISK_QUEUE 167070-#define TYPE_TAPE_QUEUE 47171-#define TYPE_ROM_QUEUE 47272-#define TYPE_OTHER_QUEUE 27373-7474-#define FREE 07575-#define OK 07676-#define NO_TIMEOUT 07777-#define USED 17878-#define TIMEOUT 27979-#define RESET 48080-#define LOCKED 88181-#define ABORTED 168282-8383-#define READ 08484-#define WRITE 18585-#define OTHER 28686-8787-#define HD(cmd) ((hostdata *)&(cmd->device->host->hostdata))8888-#define CD(cmd) ((struct eata_ccb *)(cmd->host_scribble))8989-#define SD(host) ((hostdata *)&(host->hostdata))9090-9191-/***********************************************9292- * EATA Command & Register definitions *9393- ***********************************************/9494-#define PCI_REG_DPTconfig 0x40 9595-#define PCI_REG_PumpModeAddress 0x44 9696-#define PCI_REG_PumpModeData 0x48 9797-#define PCI_REG_ConfigParam1 0x50 9898-#define PCI_REG_ConfigParam2 0x54 9999-100100-101101-#define EATA_CMD_PIO_SETUPTEST 0xc6102102-#define EATA_CMD_PIO_READ_CONFIG 0xf0103103-#define EATA_CMD_PIO_SET_CONFIG 0xf1104104-#define EATA_CMD_PIO_SEND_CP 0xf2105105-#define EATA_CMD_PIO_RECEIVE_SP 0xf3106106-#define EATA_CMD_PIO_TRUNC 0xf4107107-108108-#define EATA_CMD_RESET 0xf9109109-#define EATA_CMD_IMMEDIATE 0xfa110110-111111-#define EATA_CMD_DMA_READ_CONFIG 0xfd112112-#define EATA_CMD_DMA_SET_CONFIG 0xfe113113-#define EATA_CMD_DMA_SEND_CP 0xff114114-115115-#define ECS_EMULATE_SENSE 0xd4116116-117117-#define EATA_GENERIC_ABORT 0x00 118118-#define EATA_SPECIFIC_RESET 0x01119119-#define EATA_BUS_RESET 0x02120120-#define EATA_SPECIFIC_ABORT 0x03121121-#define EATA_QUIET_INTR 0x04122122-#define EATA_COLD_BOOT_HBA 0x06 /* Only as a last resort */123123-#define EATA_FORCE_IO 0x07124124-125125-#define HA_CTRLREG 0x206 /* control register for HBA */126126-#define HA_CTRL_DISINT 0x02 /* CTRLREG: disable interrupts */127127-#define HA_CTRL_RESCPU 0x04 /* CTRLREG: reset processor */128128-#define HA_CTRL_8HEADS 0x08 /* CTRLREG: set for drives with* 129129- * >=8 heads (WD1003 rudimentary :-) */130130-131131-#define HA_WCOMMAND 0x07 /* command register offset */132132-#define HA_WIFC 0x06 /* immediate command offset */133133-#define HA_WCODE 0x05 134134-#define HA_WCODE2 0x04 135135-#define HA_WDMAADDR 0x02 /* DMA address LSB offset */ 136136-#define HA_RAUXSTAT 0x08 /* aux status register offset*/137137-#define HA_RSTATUS 0x07 /* status register offset */138138-#define HA_RDATA 0x00 /* data register (16bit) */139139-#define HA_WDATA 0x00 /* data register (16bit) */140140-141141-#define HA_ABUSY 0x01 /* aux busy bit */142142-#define HA_AIRQ 0x02 /* aux IRQ pending bit */143143-#define HA_SERROR 0x01 /* pr. command ended in error*/144144-#define HA_SMORE 0x02 /* more data soon to come */145145-#define HA_SCORR 0x04 /* data corrected */146146-#define HA_SDRQ 0x08 /* data request active */147147-#define HA_SSC 0x10 /* seek complete */148148-#define HA_SFAULT 0x20 /* write fault */149149-#define HA_SREADY 0x40 /* drive ready */150150-#define HA_SBUSY 0x80 /* drive busy */151151-#define HA_SDRDY HA_SSC+HA_SREADY+HA_SDRQ 152152-153153-/**********************************************154154- * Message definitions *155155- **********************************************/156156-157157-#define HA_NO_ERROR 0x00 /* No Error */158158-#define HA_ERR_SEL_TO 0x01 /* Selection Timeout */159159-#define HA_ERR_CMD_TO 0x02 /* Command Timeout */160160-#define HA_BUS_RESET 0x03 /* SCSI Bus Reset Received */161161-#define HA_INIT_POWERUP 0x04 /* Initial Controller Power-up */162162-#define HA_UNX_BUSPHASE 0x05 /* Unexpected Bus Phase */163163-#define HA_UNX_BUS_FREE 0x06 /* Unexpected Bus Free */164164-#define HA_BUS_PARITY 0x07 /* Bus Parity Error */165165-#define HA_SCSI_HUNG 0x08 /* SCSI Hung */166166-#define HA_UNX_MSGRJCT 0x09 /* Unexpected Message Rejected */167167-#define HA_RESET_STUCK 0x0a /* SCSI Bus Reset Stuck */168168-#define HA_RSENSE_FAIL 0x0b /* Auto Request-Sense Failed */169169-#define HA_PARITY_ERR 0x0c /* Controller Ram Parity Error */170170-#define HA_CP_ABORT_NA 0x0d /* Abort Message sent to non-active cmd */171171-#define HA_CP_ABORTED 0x0e /* Abort Message sent to active cmd */172172-#define HA_CP_RESET_NA 0x0f /* Reset Message sent to non-active cmd */173173-#define HA_CP_RESET 0x10 /* Reset Message sent to active cmd */174174-#define HA_ECC_ERR 0x11 /* Controller Ram ECC Error */175175-#define HA_PCI_PARITY 0x12 /* PCI Parity Error */176176-#define HA_PCI_MABORT 0x13 /* PCI Master Abort */177177-#define HA_PCI_TABORT 0x14 /* PCI Target Abort */178178-#define HA_PCI_STABORT 0x15 /* PCI Signaled Target Abort */179179-180180-/**********************************************181181- * Other definitions *182182- **********************************************/183183-184184-struct reg_bit { /* reading this one will clear the interrupt */185185- __u8 error:1; /* previous command ended in an error */186186- __u8 more:1; /* more DATA coming soon, poll BSY & DRQ (PIO) */187187- __u8 corr:1; /* data read was successfully corrected with ECC*/188188- __u8 drq:1; /* data request active */ 189189- __u8 sc:1; /* seek complete */190190- __u8 fault:1; /* write fault */191191- __u8 ready:1; /* drive ready */192192- __u8 busy:1; /* controller busy */193193-};194194-195195-struct reg_abit { /* reading this won't clear the interrupt */196196- __u8 abusy:1; /* auxiliary busy */197197- __u8 irq:1; /* set when drive interrupt is asserted */198198- __u8 dummy:6;199199-};200200-201201-struct eata_register { /* EATA register set */202202- __u8 data_reg[2]; /* R, couldn't figure this one out */203203- __u8 cp_addr[4]; /* W, CP address register */204204- union { 205205- __u8 command; /* W, command code: [read|set] conf, send CP*/206206- struct reg_bit status; /* R, see register_bit1 */207207- __u8 statusbyte;208208- } ovr; 209209- struct reg_abit aux_stat; /* R, see register_bit2 */210210-};211211-212212-struct get_conf { /* Read Configuration Array */213213- __u32 len; /* Should return 0x22, 0x24, etc */214214- __u32 signature; /* Signature MUST be "EATA" */215215- __u8 version2:4,216216- version:4; /* EATA Version level */217217- __u8 OCS_enabled:1, /* Overlap Command Support enabled */218218- TAR_support:1, /* SCSI Target Mode supported */219219- TRNXFR:1, /* Truncate Transfer Cmd not necessary *220220- * Only used in PIO Mode */221221- MORE_support:1, /* MORE supported (only PIO Mode) */222222- DMA_support:1, /* DMA supported Driver uses only *223223- * this mode */224224- DMA_valid:1, /* DRQ value in Byte 30 is valid */225225- ATA:1, /* ATA device connected (not supported) */226226- HAA_valid:1; /* Hostadapter Address is valid */227227-228228- __u16 cppadlen; /* Number of pad bytes send after CD data *229229- * set to zero for DMA commands */230230- __u8 scsi_id[4]; /* SCSI ID of controller 2-0 Byte 0 res. *231231- * if not, zero is returned */232232- __u32 cplen; /* CP length: number of valid cp bytes */233233- __u32 splen; /* Number of bytes returned after * 234234- * Receive SP command */235235- __u16 queuesiz; /* max number of queueable CPs */236236- __u16 dummy;237237- __u16 SGsiz; /* max number of SG table entries */238238- __u8 IRQ:4, /* IRQ used this HA */239239- IRQ_TR:1, /* IRQ Trigger: 0=edge, 1=level */240240- SECOND:1, /* This is a secondary controller */241241- DMA_channel:2; /* DRQ index, DRQ is 2comp of DRQX */242242- __u8 sync; /* device at ID 7 tru 0 is running in *243243- * synchronous mode, this will disappear */244244- __u8 DSBLE:1, /* ISA i/o addressing is disabled */245245- FORCADR:1, /* i/o address has been forced */246246- SG_64K:1,247247- SG_UAE:1,248248- :4;249249- __u8 MAX_ID:5, /* Max number of SCSI target IDs */250250- MAX_CHAN:3; /* Number of SCSI busses on HBA */251251- __u8 MAX_LUN; /* Max number of LUNs */252252- __u8 :3,253253- AUTOTRM:1,254254- M1_inst:1,255255- ID_qest:1, /* Raidnum ID is questionable */256256- is_PCI:1, /* HBA is PCI */257257- is_EISA:1; /* HBA is EISA */258258- __u8 RAIDNUM; /* unique HBA identifier */259259- __u8 unused[474]; 260260-};261261-262262-struct eata_sg_list263263-{264264- __u32 data;265265- __u32 len;266266-};267267-268268-struct eata_ccb { /* Send Command Packet structure */269269-270270- __u8 SCSI_Reset:1, /* Cause a SCSI Bus reset on the cmd */271271- HBA_Init:1, /* Cause Controller to reinitialize */272272- Auto_Req_Sen:1, /* Do Auto Request Sense on errors */273273- scatter:1, /* Data Ptr points to a SG Packet */274274- Resrvd:1, /* RFU */275275- Interpret:1, /* Interpret the SCSI cdb of own use */276276- DataOut:1, /* Data Out phase with command */277277- DataIn:1; /* Data In phase with command */278278- __u8 reqlen; /* Request Sense Length * 279279- * Valid if Auto_Req_Sen=1 */280280- __u8 unused[3];281281- __u8 FWNEST:1, /* send cmd to phys RAID component */282282- unused2:7;283283- __u8 Phsunit:1, /* physical unit on mirrored pair */284284- I_AT:1, /* inhibit address translation */285285- I_HBA_C:1, /* HBA inhibit caching */286286- unused3:5;287287-288288- __u8 cp_id:5, /* SCSI Device ID of target */ 289289- cp_channel:3; /* SCSI Channel # of HBA */290290- __u8 cp_lun:3,291291- :2,292292- cp_luntar:1, /* CP is for target ROUTINE */293293- cp_dispri:1, /* Grant disconnect privilege */294294- cp_identify:1; /* Always TRUE */295295- __u8 cp_msg1; /* Message bytes 0-3 */296296- __u8 cp_msg2;297297- __u8 cp_msg3;298298- __u8 cp_cdb[12]; /* Command Descriptor Block */299299- __u32 cp_datalen; /* Data Transfer Length *300300- * If scatter=1 len of sg package */301301- void *cp_viraddr; /* address of this ccb */302302- __u32 cp_dataDMA; /* Data Address, if scatter=1 *303303- * address of scatter packet */304304- __u32 cp_statDMA; /* address for Status Packet */ 305305- __u32 cp_reqDMA; /* Request Sense Address, used if *306306- * CP command ends with error */307307- /* Additional CP info begins here */308308- __u32 timestamp; /* Needed to measure command latency */309309- __u32 timeout;310310- __u8 sizeindex;311311- __u8 rw_latency;312312- __u8 retries;313313- __u8 status; /* status of this queueslot */314314- struct scsi_cmnd *cmd; /* address of cmd */315315- struct eata_sg_list *sg_list;316316-};317317-318318-319319-struct eata_sp {320320- __u8 hba_stat:7, /* HBA status */321321- EOC:1; /* True if command finished */322322- __u8 scsi_stat; /* Target SCSI status */323323- __u8 reserved[2];324324- __u32 residue_len; /* Number of bytes not transferred */325325- struct eata_ccb *ccb; /* Address set in COMMAND PACKET */326326- __u8 msg[12];327327-};328328-329329-typedef struct hstd {330330- __u8 vendor[9];331331- __u8 name[18];332332- __u8 revision[6];333333- __u8 EATA_revision;334334- __u32 firmware_revision;335335- __u8 HBA_number;336336- __u8 bustype; /* bustype of HBA */337337- __u8 channel; /* # of avail. scsi channels */338338- __u8 state; /* state of HBA */339339- __u8 primary; /* true if primary */340340- __u8 more_support:1, /* HBA supports MORE flag */341341- immediate_support:1, /* HBA supports IMMEDIATE CMDs*/342342- broken_INQUIRY:1; /* This is an EISA HBA with *343343- * broken INQUIRY */344344- __u8 do_latency; /* Latency measurement flag */345345- __u32 reads[13];346346- __u32 writes[13];347347- __u32 reads_lat[12][4];348348- __u32 writes_lat[12][4];349349- __u32 all_lat[4];350350- __u8 resetlevel[MAXCHANNEL]; 351351- __u32 last_ccb; /* Last used ccb */352352- __u32 cplen; /* size of CP in words */353353- __u16 cppadlen; /* pad length of cp in words */354354- __u16 queuesize;355355- __u16 sgsize; /* # of entries in the SG list*/356356- __u16 devflags; /* bits set for detected devices */357357- __u8 hostid; /* SCSI ID of HBA */358358- __u8 moresupport; /* HBA supports MORE flag */359359- struct Scsi_Host *next; 360360- struct Scsi_Host *prev;361361- struct pci_dev *pdev; /* PCI device or NULL for non PCI */362362- struct eata_sp sp; /* status packet */ 363363- struct eata_ccb ccb[0]; /* ccb array begins here */364364-}hostdata;365365-366366-/* structure for max. 2 emulated drives */367367-struct drive_geom_emul {368368- __u8 trans; /* translation flag 1=transl */369369- __u8 channel; /* SCSI channel number */370370- __u8 HBA; /* HBA number (prim/sec) */371371- __u8 id; /* drive id */372372- __u8 lun; /* drive lun */373373- __u32 heads; /* number of heads */374374- __u32 sectors; /* number of sectors */375375- __u32 cylinder; /* number of cylinders */376376-};377377-378378-struct geom_emul {379379- __u8 bios_drives; /* number of emulated drives */380380- struct drive_geom_emul drv[2]; /* drive structures */381381-};382382-383383-#endif /* _EATA_GENERIC_H */384384-385385-/*386386- * Overrides for Emacs so that we almost follow Linus's tabbing style.387387- * Emacs will notice this stuff at the end of the file and automatically388388- * adjust the settings for this buffer only. This must remain at the end389389- * of the file.390390- * ---------------------------------------------------------------------------391391- * Local variables:392392- * c-indent-level: 4393393- * c-brace-imaginary-offset: 0394394- * c-brace-offset: -4395395- * c-argdecl-indent: 4396396- * c-label-offset: -4397397- * c-continued-statement-offset: 4398398- * c-continued-brace-offset: 0399399- * tab-width: 8400400- * End:401401- */
-966
drivers/scsi/eata_pio.c
···11-/************************************************************22- * *33- * Linux EATA SCSI PIO driver *44- * *55- * based on the CAM document CAM/89-004 rev. 2.0c, *66- * DPT's driver kit, some internal documents and source, *77- * and several other Linux scsi drivers and kernel docs. *88- * *99- * The driver currently: *1010- * -supports all EATA-PIO boards *1111- * -only supports DASD devices *1212- * *1313- * (c)1993-96 Michael Neuffer, Alfred Arnold *1414- * neuffer@goofy.zdv.uni-mainz.de *1515- * a.arnold@kfa-juelich.de * 1616- * *1717- * Updated 2002 by Alan Cox <alan@lxorguk.ukuu.org.uk> for *1818- * Linux 2.5.x and the newer locking and error handling *1919- * *2020- * This program is free software; you can redistribute it *2121- * and/or modify it under the terms of the GNU General *2222- * Public License as published by the Free Software *2323- * Foundation; either version 2 of the License, or *2424- * (at your option) any later version. *2525- * *2626- * This program is distributed in the hope that it will be *2727- * useful, but WITHOUT ANY WARRANTY; without even the *2828- * implied warranty of MERCHANTABILITY or FITNESS FOR A *2929- * PARTICULAR PURPOSE. See the GNU General Public License *3030- * for more details. *3131- * *3232- * You should have received a copy of the GNU General *3333- * Public License along with this kernel; if not, write to *3434- * the Free Software Foundation, Inc., 675 Mass Ave, *3535- * Cambridge, MA 02139, USA. *3636- * *3737- * For the avoidance of doubt the "preferred form" of this *3838- * code is one which is in an open non patent encumbered *3939- * format. Where cryptographic key signing forms part of *4040- * the process of creating an executable the information *4141- * including keys needed to generate an equivalently *4242- * functional executable are deemed to be part of the *4343- * source code are deemed to be part of the source code. *4444- * *4545- ************************************************************4646- * last change: 2002/11/02 OS: Linux 2.5.45 *4747- ************************************************************/4848-4949-#include <linux/module.h>5050-#include <linux/kernel.h>5151-#include <linux/string.h>5252-#include <linux/ioport.h>5353-#include <linux/in.h>5454-#include <linux/pci.h>5555-#include <linux/proc_fs.h>5656-#include <linux/interrupt.h>5757-#include <linux/blkdev.h>5858-#include <linux/spinlock.h>5959-#include <linux/delay.h>6060-6161-#include <asm/io.h>6262-6363-#include <scsi/scsi.h>6464-#include <scsi/scsi_cmnd.h>6565-#include <scsi/scsi_device.h>6666-#include <scsi/scsi_host.h>6767-6868-#include "eata_generic.h"6969-#include "eata_pio.h"7070-7171-7272-static unsigned int ISAbases[MAXISA] = {7373- 0x1F0, 0x170, 0x330, 0x2307474-};7575-7676-static unsigned int ISAirqs[MAXISA] = {7777- 14, 12, 15, 117878-};7979-8080-static unsigned char EISAbases[] = { 8181- 1, 1, 1, 1, 1, 1, 1, 1,8282- 1, 1, 1, 1, 1, 1, 1, 1 8383-};8484-8585-static unsigned int registered_HBAs;8686-static struct Scsi_Host *last_HBA;8787-static struct Scsi_Host *first_HBA;8888-static unsigned char reg_IRQ[16];8989-static unsigned char reg_IRQL[16];9090-static unsigned long int_counter;9191-static unsigned long queue_counter;9292-9393-static struct scsi_host_template driver_template;9494-9595-static int eata_pio_show_info(struct seq_file *m, struct Scsi_Host *shost)9696-{9797- seq_printf(m, "EATA (Extended Attachment) PIO driver version: "9898- "%d.%d%s\n",VER_MAJOR, VER_MINOR, VER_SUB);9999- seq_printf(m, "queued commands: %10ld\n"100100- "processed interrupts:%10ld\n", queue_counter, int_counter);101101- seq_printf(m, "\nscsi%-2d: HBA %.10s\n",102102- shost->host_no, SD(shost)->name);103103- seq_printf(m, "Firmware revision: v%s\n",104104- SD(shost)->revision);105105- seq_puts(m, "IO: PIO\n");106106- seq_printf(m, "Base IO : %#.4x\n", (u32) shost->base);107107- seq_printf(m, "Host Bus: %s\n",108108- (SD(shost)->bustype == 'P')?"PCI ":109109- (SD(shost)->bustype == 'E')?"EISA":"ISA ");110110- return 0;111111-}112112-113113-static int eata_pio_release(struct Scsi_Host *sh)114114-{115115- hostdata *hd = SD(sh);116116- if (sh->irq && reg_IRQ[sh->irq] == 1)117117- free_irq(sh->irq, NULL);118118- else119119- reg_IRQ[sh->irq]--;120120- if (SD(sh)->channel == 0) {121121- if (sh->io_port && sh->n_io_port)122122- release_region(sh->io_port, sh->n_io_port);123123- }124124- /* At this point the PCI reference can go */125125- if (hd->pdev)126126- pci_dev_put(hd->pdev);127127- return 1;128128-}129129-130130-static void IncStat(struct scsi_pointer *SCp, unsigned int Increment)131131-{132132- SCp->ptr += Increment;133133- if ((SCp->this_residual -= Increment) == 0) {134134- if ((--SCp->buffers_residual) == 0)135135- SCp->Status = 0;136136- else {137137- SCp->buffer++;138138- SCp->ptr = sg_virt(SCp->buffer);139139- SCp->this_residual = SCp->buffer->length;140140- }141141- }142142-}143143-144144-static irqreturn_t eata_pio_int_handler(int irq, void *dev_id);145145-146146-static irqreturn_t do_eata_pio_int_handler(int irq, void *dev_id)147147-{148148- unsigned long flags;149149- struct Scsi_Host *dev = dev_id;150150- irqreturn_t ret;151151-152152- spin_lock_irqsave(dev->host_lock, flags);153153- ret = eata_pio_int_handler(irq, dev_id);154154- spin_unlock_irqrestore(dev->host_lock, flags);155155- return ret;156156-}157157-158158-static irqreturn_t eata_pio_int_handler(int irq, void *dev_id)159159-{160160- unsigned int eata_stat = 0xfffff;161161- struct scsi_cmnd *cmd;162162- hostdata *hd;163163- struct eata_ccb *cp;164164- unsigned long base;165165- unsigned int x, z;166166- struct Scsi_Host *sh;167167- unsigned short zwickel = 0;168168- unsigned char stat, odd;169169- irqreturn_t ret = IRQ_NONE;170170-171171- for (x = 1, sh = first_HBA; x <= registered_HBAs; x++, sh = SD(sh)->prev) 172172- {173173- if (sh->irq != irq)174174- continue;175175- if (inb(sh->base + HA_RSTATUS) & HA_SBUSY)176176- continue;177177-178178- int_counter++;179179- ret = IRQ_HANDLED;180180-181181- hd = SD(sh);182182-183183- cp = &hd->ccb[0];184184- cmd = cp->cmd;185185- base = cmd->device->host->base;186186-187187- do {188188- stat = inb(base + HA_RSTATUS);189189- if (stat & HA_SDRQ) {190190- if (cp->DataIn) {191191- z = 256;192192- odd = 0;193193- while ((cmd->SCp.Status) && ((z > 0) || (odd))) {194194- if (odd) {195195- *(cmd->SCp.ptr) = zwickel >> 8;196196- IncStat(&cmd->SCp, 1);197197- odd = 0;198198- }199199- x = min_t(unsigned int, z, cmd->SCp.this_residual / 2);200200- insw(base + HA_RDATA, cmd->SCp.ptr, x);201201- z -= x;202202- IncStat(&cmd->SCp, 2 * x);203203- if ((z > 0) && (cmd->SCp.this_residual == 1)) {204204- zwickel = inw(base + HA_RDATA);205205- *(cmd->SCp.ptr) = zwickel & 0xff;206206- IncStat(&cmd->SCp, 1);207207- z--;208208- odd = 1;209209- }210210- }211211- while (z > 0) {212212- zwickel = inw(base + HA_RDATA);213213- z--;214214- }215215- } else { /* cp->DataOut */216216-217217- odd = 0;218218- z = 256;219219- while ((cmd->SCp.Status) && ((z > 0) || (odd))) {220220- if (odd) {221221- zwickel += *(cmd->SCp.ptr) << 8;222222- IncStat(&cmd->SCp, 1);223223- outw(zwickel, base + HA_RDATA);224224- z--;225225- odd = 0;226226- }227227- x = min_t(unsigned int, z, cmd->SCp.this_residual / 2);228228- outsw(base + HA_RDATA, cmd->SCp.ptr, x);229229- z -= x;230230- IncStat(&cmd->SCp, 2 * x);231231- if ((z > 0) && (cmd->SCp.this_residual == 1)) {232232- zwickel = *(cmd->SCp.ptr);233233- zwickel &= 0xff;234234- IncStat(&cmd->SCp, 1);235235- odd = 1;236236- }237237- }238238- while (z > 0 || odd) {239239- outw(zwickel, base + HA_RDATA);240240- z--;241241- odd = 0;242242- }243243- }244244- }245245- }246246- while ((stat & HA_SDRQ) || ((stat & HA_SMORE) && hd->moresupport));247247-248248- /* terminate handler if HBA goes busy again, i.e. transfers249249- * more data */250250-251251- if (stat & HA_SBUSY)252252- break;253253-254254- /* OK, this is quite stupid, but I haven't found any correct255255- * way to get HBA&SCSI status so far */256256-257257- if (!(inb(base + HA_RSTATUS) & HA_SERROR)) {258258- cmd->result = (DID_OK << 16);259259- hd->devflags |= (1 << cp->cp_id);260260- } else if (hd->devflags & (1 << cp->cp_id))261261- cmd->result = (DID_OK << 16) + 0x02;262262- else263263- cmd->result = (DID_NO_CONNECT << 16);264264-265265- if (cp->status == LOCKED) {266266- cp->status = FREE;267267- eata_stat = inb(base + HA_RSTATUS);268268- printk(KERN_CRIT "eata_pio: int_handler, freeing locked " "queueslot\n");269269- return ret;270270- }271271-#if DBG_INTR2272272- if (stat != 0x50)273273- printk(KERN_DEBUG "stat: %#.2x, result: %#.8x\n", stat, cmd->result);274274-#endif275275-276276- cp->status = FREE; /* now we can release the slot */277277-278278- cmd->scsi_done(cmd);279279- }280280-281281- return ret;282282-}283283-284284-static inline unsigned int eata_pio_send_command(unsigned long base, unsigned char command)285285-{286286- unsigned int loop = 50;287287-288288- while (inb(base + HA_RSTATUS) & HA_SBUSY)289289- if (--loop == 0)290290- return 1;291291-292292- /* Enable interrupts for HBA. It is not the best way to do it at this293293- * place, but I hope that it doesn't interfere with the IDE driver 294294- * initialization this way */295295-296296- outb(HA_CTRL_8HEADS, base + HA_CTRLREG);297297-298298- outb(command, base + HA_WCOMMAND);299299- return 0;300300-}301301-302302-static int eata_pio_queue_lck(struct scsi_cmnd *cmd,303303- void (*done)(struct scsi_cmnd *))304304-{305305- unsigned int x, y;306306- unsigned long base;307307-308308- hostdata *hd;309309- struct Scsi_Host *sh;310310- struct eata_ccb *cp;311311-312312- queue_counter++;313313-314314- hd = HD(cmd);315315- sh = cmd->device->host;316316- base = sh->base;317317-318318- /* use only slot 0, as 2001 can handle only one cmd at a time */319319-320320- y = x = 0;321321-322322- if (hd->ccb[y].status != FREE) {323323-324324- DBG(DBG_QUEUE, printk(KERN_EMERG "can_queue %d, x %d, y %d\n", sh->can_queue, x, y));325325-#if DEBUG_EATA326326- panic(KERN_EMERG "eata_pio: run out of queue slots cmdno:%ld " "intrno: %ld\n", queue_counter, int_counter);327327-#else328328- panic(KERN_EMERG "eata_pio: run out of queue slots....\n");329329-#endif330330- }331331-332332- cp = &hd->ccb[y];333333-334334- memset(cp, 0, sizeof(struct eata_ccb));335335-336336- cp->status = USED; /* claim free slot */337337-338338- DBG(DBG_QUEUE, scmd_printk(KERN_DEBUG, cmd,339339- "eata_pio_queue 0x%p, y %d\n", cmd, y));340340-341341- cmd->scsi_done = (void *) done;342342-343343- if (cmd->sc_data_direction == DMA_TO_DEVICE)344344- cp->DataOut = 1; /* Output mode */345345- else346346- cp->DataIn = 0; /* Input mode */347347-348348- cp->Interpret = (cmd->device->id == hd->hostid);349349- cp->cp_datalen = cpu_to_be32(scsi_bufflen(cmd));350350- cp->Auto_Req_Sen = 0;351351- cp->cp_reqDMA = 0;352352- cp->reqlen = 0;353353-354354- cp->cp_id = cmd->device->id;355355- cp->cp_lun = cmd->device->lun;356356- cp->cp_dispri = 0;357357- cp->cp_identify = 1;358358- memcpy(cp->cp_cdb, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd));359359-360360- cp->cp_statDMA = 0;361361-362362- cp->cp_viraddr = cp;363363- cp->cmd = cmd;364364- cmd->host_scribble = (char *) &hd->ccb[y];365365-366366- if (!scsi_bufflen(cmd)) {367367- cmd->SCp.buffers_residual = 1;368368- cmd->SCp.ptr = NULL;369369- cmd->SCp.this_residual = 0;370370- cmd->SCp.buffer = NULL;371371- } else {372372- cmd->SCp.buffer = scsi_sglist(cmd);373373- cmd->SCp.buffers_residual = scsi_sg_count(cmd);374374- cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);375375- cmd->SCp.this_residual = cmd->SCp.buffer->length;376376- }377377- cmd->SCp.Status = (cmd->SCp.this_residual != 0); /* TRUE as long as bytes 378378- * are to transfer */379379-380380- if (eata_pio_send_command(base, EATA_CMD_PIO_SEND_CP)) {381381- cmd->result = DID_BUS_BUSY << 16;382382- scmd_printk(KERN_NOTICE, cmd,383383- "eata_pio_queue pid 0x%p, HBA busy, "384384- "returning DID_BUS_BUSY, done.\n", cmd);385385- done(cmd);386386- cp->status = FREE;387387- return 0;388388- }389389- /* FIXME: timeout */390390- while (!(inb(base + HA_RSTATUS) & HA_SDRQ))391391- cpu_relax();392392- outsw(base + HA_RDATA, cp, hd->cplen);393393- outb(EATA_CMD_PIO_TRUNC, base + HA_WCOMMAND);394394- for (x = 0; x < hd->cppadlen; x++)395395- outw(0, base + HA_RDATA);396396-397397- DBG(DBG_QUEUE, scmd_printk(KERN_DEBUG, cmd,398398- "Queued base %#.4lx cmd: 0x%p "399399- "slot %d irq %d\n", sh->base, cmd, y, sh->irq));400400-401401- return 0;402402-}403403-404404-static DEF_SCSI_QCMD(eata_pio_queue)405405-406406-static int eata_pio_abort(struct scsi_cmnd *cmd)407407-{408408- unsigned int loop = 100;409409-410410- DBG(DBG_ABNORM, scmd_printk(KERN_WARNING, cmd,411411- "eata_pio_abort called pid: 0x%p\n", cmd));412412-413413- while (inb(cmd->device->host->base + HA_RAUXSTAT) & HA_ABUSY)414414- if (--loop == 0) {415415- printk(KERN_WARNING "eata_pio: abort, timeout error.\n");416416- return FAILED;417417- }418418- if (CD(cmd)->status == FREE) {419419- DBG(DBG_ABNORM, printk(KERN_WARNING "Returning: SCSI_ABORT_NOT_RUNNING\n"));420420- return FAILED;421421- }422422- if (CD(cmd)->status == USED) {423423- DBG(DBG_ABNORM, printk(KERN_WARNING "Returning: SCSI_ABORT_BUSY\n"));424424- /* We want to sleep a bit more here */425425- return FAILED; /* SNOOZE */426426- }427427- if (CD(cmd)->status == RESET) {428428- printk(KERN_WARNING "eata_pio: abort, command reset error.\n");429429- return FAILED;430430- }431431- if (CD(cmd)->status == LOCKED) {432432- DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio: abort, queue slot " "locked.\n"));433433- return FAILED;434434- }435435- panic("eata_pio: abort: invalid slot status\n");436436-}437437-438438-static int eata_pio_host_reset(struct scsi_cmnd *cmd)439439-{440440- unsigned int x, limit = 0;441441- unsigned char success = 0;442442- struct scsi_cmnd *sp;443443- struct Scsi_Host *host = cmd->device->host;444444-445445- DBG(DBG_ABNORM, scmd_printk(KERN_WARNING, cmd,446446- "eata_pio_reset called\n"));447447-448448- spin_lock_irq(host->host_lock);449449-450450- if (HD(cmd)->state == RESET) {451451- printk(KERN_WARNING "eata_pio_reset: exit, already in reset.\n");452452- spin_unlock_irq(host->host_lock);453453- return FAILED;454454- }455455-456456- /* force all slots to be free */457457-458458- for (x = 0; x < cmd->device->host->can_queue; x++) {459459-460460- if (HD(cmd)->ccb[x].status == FREE)461461- continue;462462-463463- sp = HD(cmd)->ccb[x].cmd;464464- HD(cmd)->ccb[x].status = RESET;465465- printk(KERN_WARNING "eata_pio_reset: slot %d in reset.\n", x);466466-467467- if (sp == NULL)468468- panic("eata_pio_reset: slot %d, sp==NULL.\n", x);469469- }470470-471471- /* hard reset the HBA */472472- outb(EATA_CMD_RESET, cmd->device->host->base + HA_WCOMMAND);473473-474474- DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: board reset done.\n"));475475- HD(cmd)->state = RESET;476476-477477- spin_unlock_irq(host->host_lock);478478- msleep(3000);479479- spin_lock_irq(host->host_lock);480480-481481- DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: interrupts disabled, " "loops %d.\n", limit));482482-483483- for (x = 0; x < cmd->device->host->can_queue; x++) {484484-485485- /* Skip slots already set free by interrupt */486486- if (HD(cmd)->ccb[x].status != RESET)487487- continue;488488-489489- sp = HD(cmd)->ccb[x].cmd;490490- sp->result = DID_RESET << 16;491491-492492- /* This mailbox is terminated */493493- printk(KERN_WARNING "eata_pio_reset: reset ccb %d.\n", x);494494- HD(cmd)->ccb[x].status = FREE;495495-496496- sp->scsi_done(sp);497497- }498498-499499- HD(cmd)->state = 0;500500-501501- spin_unlock_irq(host->host_lock);502502-503503- if (success) { /* hmmm... */504504- DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: exit, success.\n"));505505- return SUCCESS;506506- } else {507507- DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: exit, wakeup.\n"));508508- return FAILED;509509- }510510-}511511-512512-static char *get_pio_board_data(unsigned long base, unsigned int irq, unsigned int id, unsigned long cplen, unsigned short cppadlen)513513-{514514- struct eata_ccb cp;515515- static char buff[256];516516- int z;517517-518518- memset(&cp, 0, sizeof(struct eata_ccb));519519- memset(buff, 0, sizeof(buff));520520-521521- cp.DataIn = 1;522522- cp.Interpret = 1; /* Interpret command */523523-524524- cp.cp_datalen = cpu_to_be32(254);525525- cp.cp_dataDMA = cpu_to_be32(0);526526-527527- cp.cp_id = id;528528- cp.cp_lun = 0;529529-530530- cp.cp_cdb[0] = INQUIRY;531531- cp.cp_cdb[1] = 0;532532- cp.cp_cdb[2] = 0;533533- cp.cp_cdb[3] = 0;534534- cp.cp_cdb[4] = 254;535535- cp.cp_cdb[5] = 0;536536-537537- if (eata_pio_send_command(base, EATA_CMD_PIO_SEND_CP))538538- return NULL;539539-540540- while (!(inb(base + HA_RSTATUS) & HA_SDRQ))541541- cpu_relax();542542-543543- outsw(base + HA_RDATA, &cp, cplen);544544- outb(EATA_CMD_PIO_TRUNC, base + HA_WCOMMAND);545545- for (z = 0; z < cppadlen; z++)546546- outw(0, base + HA_RDATA);547547-548548- while (inb(base + HA_RSTATUS) & HA_SBUSY)549549- cpu_relax();550550-551551- if (inb(base + HA_RSTATUS) & HA_SERROR)552552- return NULL;553553- else if (!(inb(base + HA_RSTATUS) & HA_SDRQ))554554- return NULL;555555- else {556556- insw(base + HA_RDATA, &buff, 127);557557- while (inb(base + HA_RSTATUS) & HA_SDRQ)558558- inw(base + HA_RDATA);559559- return buff;560560- }561561-}562562-563563-static int get_pio_conf_PIO(unsigned long base, struct get_conf *buf)564564-{565565- unsigned long loop = HZ / 2;566566- int z;567567- unsigned short *p;568568-569569- if (!request_region(base, 9, "eata_pio"))570570- return 0;571571-572572- memset(buf, 0, sizeof(struct get_conf));573573-574574- while (inb(base + HA_RSTATUS) & HA_SBUSY)575575- if (--loop == 0)576576- goto fail;577577-578578- DBG(DBG_PIO && DBG_PROBE, printk(KERN_DEBUG "Issuing PIO READ CONFIG to HBA at %#lx\n", base));579579- eata_pio_send_command(base, EATA_CMD_PIO_READ_CONFIG);580580-581581- loop = 50;582582- for (p = (unsigned short *) buf; (long) p <= ((long) buf + (sizeof(struct get_conf) / 2)); p++) {583583- while (!(inb(base + HA_RSTATUS) & HA_SDRQ))584584- if (--loop == 0)585585- goto fail;586586-587587- loop = 50;588588- *p = inw(base + HA_RDATA);589589- }590590- if (inb(base + HA_RSTATUS) & HA_SERROR) {591591- DBG(DBG_PROBE, printk("eata_dma: get_conf_PIO, error during "592592- "transfer for HBA at %lx\n", base));593593- goto fail;594594- }595595-596596- if (cpu_to_be32(EATA_SIGNATURE) != buf->signature)597597- goto fail;598598-599599- DBG(DBG_PIO && DBG_PROBE, printk(KERN_NOTICE "EATA Controller found "600600- "at %#4lx EATA Level: %x\n",601601- base, (unsigned int) (buf->version)));602602-603603- while (inb(base + HA_RSTATUS) & HA_SDRQ)604604- inw(base + HA_RDATA);605605-606606- if (!ALLOW_DMA_BOARDS) {607607- for (z = 0; z < MAXISA; z++)608608- if (base == ISAbases[z]) {609609- buf->IRQ = ISAirqs[z];610610- break;611611- }612612- }613613-614614- return 1;615615-616616- fail:617617- release_region(base, 9);618618- return 0;619619-}620620-621621-static void print_pio_config(struct get_conf *gc)622622-{623623- printk("Please check values: (read config data)\n");624624- printk("LEN: %d ver:%d OCS:%d TAR:%d TRNXFR:%d MORES:%d\n", be32_to_cpu(gc->len), gc->version, gc->OCS_enabled, gc->TAR_support, gc->TRNXFR, gc->MORE_support);625625- printk("HAAV:%d SCSIID0:%d ID1:%d ID2:%d QUEUE:%d SG:%d SEC:%d\n", gc->HAA_valid, gc->scsi_id[3], gc->scsi_id[2], gc->scsi_id[1], be16_to_cpu(gc->queuesiz), be16_to_cpu(gc->SGsiz), gc->SECOND);626626- printk("IRQ:%d IRQT:%d FORCADR:%d MCH:%d RIDQ:%d\n", gc->IRQ, gc->IRQ_TR, gc->FORCADR, gc->MAX_CHAN, gc->ID_qest);627627-}628628-629629-static unsigned int print_selftest(unsigned int base)630630-{631631- unsigned char buffer[512];632632-#ifdef VERBOSE_SETUP633633- int z;634634-#endif635635-636636- printk("eata_pio: executing controller self test & setup...\n");637637- while (inb(base + HA_RSTATUS) & HA_SBUSY);638638- outb(EATA_CMD_PIO_SETUPTEST, base + HA_WCOMMAND);639639- do {640640- while (inb(base + HA_RSTATUS) & HA_SBUSY)641641- /* nothing */ ;642642- if (inb(base + HA_RSTATUS) & HA_SDRQ) {643643- insw(base + HA_RDATA, &buffer, 256);644644-#ifdef VERBOSE_SETUP645645- /* no beeps please... */646646- for (z = 0; z < 511 && buffer[z]; z++)647647- if (buffer[z] != 7)648648- printk("%c", buffer[z]);649649-#endif650650- }651651- } while (inb(base + HA_RSTATUS) & (HA_SBUSY | HA_SDRQ));652652-653653- return (!(inb(base + HA_RSTATUS) & HA_SERROR));654654-}655655-656656-static int register_pio_HBA(long base, struct get_conf *gc, struct pci_dev *pdev)657657-{658658- unsigned long size = 0;659659- char *buff;660660- unsigned long cplen;661661- unsigned short cppadlen;662662- struct Scsi_Host *sh;663663- hostdata *hd;664664-665665- DBG(DBG_REGISTER, print_pio_config(gc));666666-667667- if (gc->DMA_support) {668668- printk("HBA at %#.4lx supports DMA. Please use EATA-DMA driver.\n", base);669669- if (!ALLOW_DMA_BOARDS)670670- return 0;671671- }672672-673673- if ((buff = get_pio_board_data(base, gc->IRQ, gc->scsi_id[3], cplen = (cpu_to_be32(gc->cplen) + 1) / 2, cppadlen = (cpu_to_be16(gc->cppadlen) + 1) / 2)) == NULL) {674674- printk("HBA at %#lx didn't react on INQUIRY. Sorry.\n", base);675675- return 0;676676- }677677-678678- if (!print_selftest(base) && !ALLOW_DMA_BOARDS) {679679- printk("HBA at %#lx failed while performing self test & setup.\n", base);680680- return 0;681681- }682682-683683- size = sizeof(hostdata) + (sizeof(struct eata_ccb) * be16_to_cpu(gc->queuesiz));684684-685685- sh = scsi_register(&driver_template, size);686686- if (sh == NULL)687687- return 0;688688-689689- if (!reg_IRQ[gc->IRQ]) { /* Interrupt already registered ? */690690- if (!request_irq(gc->IRQ, do_eata_pio_int_handler, 0, "EATA-PIO", sh)) {691691- reg_IRQ[gc->IRQ]++;692692- if (!gc->IRQ_TR)693693- reg_IRQL[gc->IRQ] = 1; /* IRQ is edge triggered */694694- } else {695695- printk("Couldn't allocate IRQ %d, Sorry.\n", gc->IRQ);696696- return 0;697697- }698698- } else { /* More than one HBA on this IRQ */699699- if (reg_IRQL[gc->IRQ]) {700700- printk("Can't support more than one HBA on this IRQ,\n" " if the IRQ is edge triggered. Sorry.\n");701701- return 0;702702- } else703703- reg_IRQ[gc->IRQ]++;704704- }705705-706706- hd = SD(sh);707707-708708- memset(hd->ccb, 0, (sizeof(struct eata_ccb) * be16_to_cpu(gc->queuesiz)));709709- memset(hd->reads, 0, sizeof(hd->reads));710710-711711- strlcpy(SD(sh)->vendor, &buff[8], sizeof(SD(sh)->vendor));712712- strlcpy(SD(sh)->name, &buff[16], sizeof(SD(sh)->name));713713- SD(sh)->revision[0] = buff[32];714714- SD(sh)->revision[1] = buff[33];715715- SD(sh)->revision[2] = buff[34];716716- SD(sh)->revision[3] = '.';717717- SD(sh)->revision[4] = buff[35];718718- SD(sh)->revision[5] = 0;719719-720720- switch (be32_to_cpu(gc->len)) {721721- case 0x1c:722722- SD(sh)->EATA_revision = 'a';723723- break;724724- case 0x1e:725725- SD(sh)->EATA_revision = 'b';726726- break;727727- case 0x22:728728- SD(sh)->EATA_revision = 'c';729729- break;730730- case 0x24:731731- SD(sh)->EATA_revision = 'z';732732- break;733733- default:734734- SD(sh)->EATA_revision = '?';735735- }736736-737737- if (be32_to_cpu(gc->len) >= 0x22) {738738- if (gc->is_PCI)739739- hd->bustype = IS_PCI;740740- else if (gc->is_EISA)741741- hd->bustype = IS_EISA;742742- else743743- hd->bustype = IS_ISA;744744- } else {745745- if (buff[21] == '4')746746- hd->bustype = IS_PCI;747747- else if (buff[21] == '2')748748- hd->bustype = IS_EISA;749749- else750750- hd->bustype = IS_ISA;751751- }752752-753753- SD(sh)->cplen = cplen;754754- SD(sh)->cppadlen = cppadlen;755755- SD(sh)->hostid = gc->scsi_id[3];756756- SD(sh)->devflags = 1 << gc->scsi_id[3];757757- SD(sh)->moresupport = gc->MORE_support;758758- sh->unique_id = base;759759- sh->base = base;760760- sh->io_port = base;761761- sh->n_io_port = 9;762762- sh->irq = gc->IRQ;763763- sh->dma_channel = PIO;764764- sh->this_id = gc->scsi_id[3];765765- sh->can_queue = 1;766766- sh->cmd_per_lun = 1;767767- sh->sg_tablesize = SG_ALL;768768-769769- hd->channel = 0;770770-771771- hd->pdev = pci_dev_get(pdev); /* Keep a PCI reference */772772-773773- sh->max_id = 8;774774- sh->max_lun = 8;775775-776776- if (gc->SECOND)777777- hd->primary = 0;778778- else779779- hd->primary = 1;780780-781781- hd->next = NULL; /* build a linked list of all HBAs */782782- hd->prev = last_HBA;783783- if (hd->prev != NULL)784784- SD(hd->prev)->next = sh;785785- last_HBA = sh;786786- if (first_HBA == NULL)787787- first_HBA = sh;788788- registered_HBAs++;789789- return (1);790790-}791791-792792-static void find_pio_ISA(struct get_conf *buf)793793-{794794- int i;795795-796796- for (i = 0; i < MAXISA; i++) {797797- if (!ISAbases[i])798798- continue;799799- if (!get_pio_conf_PIO(ISAbases[i], buf))800800- continue;801801- if (!register_pio_HBA(ISAbases[i], buf, NULL))802802- release_region(ISAbases[i], 9);803803- else804804- ISAbases[i] = 0;805805- }806806- return;807807-}808808-809809-static void find_pio_EISA(struct get_conf *buf)810810-{811811- u32 base;812812- int i;813813-814814-#ifdef CHECKPAL815815- u8 pal1, pal2, pal3;816816-#endif817817-818818- for (i = 0; i < MAXEISA; i++) {819819- if (EISAbases[i]) { /* Still a possibility ? */820820-821821- base = 0x1c88 + (i * 0x1000);822822-#ifdef CHECKPAL823823- pal1 = inb((u16) base - 8);824824- pal2 = inb((u16) base - 7);825825- pal3 = inb((u16) base - 6);826826-827827- if (((pal1 == 0x12) && (pal2 == 0x14)) || ((pal1 == 0x38) && (pal2 == 0xa3) && (pal3 == 0x82)) || ((pal1 == 0x06) && (pal2 == 0x94) && (pal3 == 0x24))) {828828- DBG(DBG_PROBE, printk(KERN_NOTICE "EISA EATA id tags found: " "%x %x %x \n", (int) pal1, (int) pal2, (int) pal3));829829-#endif830830- if (get_pio_conf_PIO(base, buf)) {831831- DBG(DBG_PROBE && DBG_EISA, print_pio_config(buf));832832- if (buf->IRQ) {833833- if (!register_pio_HBA(base, buf, NULL))834834- release_region(base, 9);835835- } else {836836- printk(KERN_NOTICE "eata_dma: No valid IRQ. HBA " "removed from list\n");837837- release_region(base, 9);838838- }839839- }840840- /* Nothing found here so we take it from the list */841841- EISAbases[i] = 0;842842-#ifdef CHECKPAL843843- }844844-#endif845845- }846846- }847847- return;848848-}849849-850850-static void find_pio_PCI(struct get_conf *buf)851851-{852852-#ifndef CONFIG_PCI853853- printk("eata_dma: kernel PCI support not enabled. Skipping scan for PCI HBAs.\n");854854-#else855855- struct pci_dev *dev = NULL;856856- unsigned long base, x;857857-858858- while ((dev = pci_get_device(PCI_VENDOR_ID_DPT, PCI_DEVICE_ID_DPT, dev)) != NULL) {859859- DBG(DBG_PROBE && DBG_PCI, printk("eata_pio: find_PCI, HBA at %s\n", pci_name(dev)));860860- if (pci_enable_device(dev))861861- continue;862862- pci_set_master(dev);863863- base = pci_resource_flags(dev, 0);864864- if (base & IORESOURCE_MEM) {865865- printk("eata_pio: invalid base address of device %s\n", pci_name(dev));866866- continue;867867- }868868- base = pci_resource_start(dev, 0);869869- /* EISA tag there ? */870870- if ((inb(base) == 0x12) && (inb(base + 1) == 0x14))871871- continue; /* Jep, it's forced, so move on */872872- base += 0x10; /* Now, THIS is the real address */873873- if (base != 0x1f8) {874874- /* We didn't find it in the primary search */875875- if (get_pio_conf_PIO(base, buf)) {876876- if (buf->FORCADR) { /* If the address is forced */877877- release_region(base, 9);878878- continue; /* we'll find it later */879879- }880880-881881- /* OK. We made it till here, so we can go now 882882- * and register it. We only have to check and 883883- * eventually remove it from the EISA and ISA list 884884- */885885-886886- if (!register_pio_HBA(base, buf, dev)) {887887- release_region(base, 9);888888- continue;889889- }890890-891891- if (base < 0x1000) {892892- for (x = 0; x < MAXISA; ++x) {893893- if (ISAbases[x] == base) {894894- ISAbases[x] = 0;895895- break;896896- }897897- }898898- } else if ((base & 0x0fff) == 0x0c88) {899899- x = (base >> 12) & 0x0f;900900- EISAbases[x] = 0;901901- }902902- }903903-#ifdef CHECK_BLINK904904- else if (check_blink_state(base)) {905905- printk("eata_pio: HBA is in BLINK state.\n" "Consult your HBAs manual to correct this.\n");906906- }907907-#endif908908- }909909- }910910-#endif /* #ifndef CONFIG_PCI */911911-}912912-913913-static int eata_pio_detect(struct scsi_host_template *tpnt)914914-{915915- struct Scsi_Host *HBA_ptr;916916- struct get_conf gc;917917- int i;918918-919919- find_pio_PCI(&gc);920920- find_pio_EISA(&gc);921921- find_pio_ISA(&gc);922922-923923- for (i = 0; i < MAXIRQ; i++)924924- if (reg_IRQ[i])925925- request_irq(i, do_eata_pio_int_handler, 0, "EATA-PIO", NULL);926926-927927- HBA_ptr = first_HBA;928928-929929- if (registered_HBAs != 0) {930930- printk("EATA (Extended Attachment) PIO driver version: %d.%d%s\n"931931- "(c) 1993-95 Michael Neuffer, neuffer@goofy.zdv.uni-mainz.de\n" " Alfred Arnold, a.arnold@kfa-juelich.de\n" "This release only supports DASD devices (harddisks)\n", VER_MAJOR, VER_MINOR, VER_SUB);932932-933933- printk("Registered HBAs:\n");934934- printk("HBA no. Boardtype: Revis: EATA: Bus: BaseIO: IRQ: Ch: ID: Pr:" " QS: SG: CPL:\n");935935- for (i = 1; i <= registered_HBAs; i++) {936936- printk("scsi%-2d: %.10s v%s 2.0%c %s %#.4lx %2d %d %d %c"937937- " %2d %2d %2d\n",938938- HBA_ptr->host_no, SD(HBA_ptr)->name, SD(HBA_ptr)->revision,939939- SD(HBA_ptr)->EATA_revision, (SD(HBA_ptr)->bustype == 'P') ?940940- "PCI " : (SD(HBA_ptr)->bustype == 'E') ? "EISA" : "ISA ",941941- HBA_ptr->base, HBA_ptr->irq, SD(HBA_ptr)->channel, HBA_ptr->this_id,942942- SD(HBA_ptr)->primary ? 'Y' : 'N', HBA_ptr->can_queue,943943- HBA_ptr->sg_tablesize, HBA_ptr->cmd_per_lun);944944- HBA_ptr = SD(HBA_ptr)->next;945945- }946946- }947947- return (registered_HBAs);948948-}949949-950950-static struct scsi_host_template driver_template = {951951- .proc_name = "eata_pio",952952- .name = "EATA (Extended Attachment) PIO driver",953953- .show_info = eata_pio_show_info,954954- .detect = eata_pio_detect,955955- .release = eata_pio_release,956956- .queuecommand = eata_pio_queue,957957- .eh_abort_handler = eata_pio_abort,958958- .eh_host_reset_handler = eata_pio_host_reset,959959- .use_clustering = ENABLE_CLUSTERING,960960-};961961-962962-MODULE_AUTHOR("Michael Neuffer, Alfred Arnold");963963-MODULE_DESCRIPTION("EATA SCSI PIO driver");964964-MODULE_LICENSE("GPL");965965-966966-#include "scsi_module.c"
-54
drivers/scsi/eata_pio.h
···11-/* SPDX-License-Identifier: GPL-2.0 */22-/********************************************************33-* Header file for eata_pio.c Linux EATA-PIO SCSI driver *44-* (c) 1993-96 Michael Neuffer *55-*********************************************************66-* last change: 2002/11/02 *77-********************************************************/88-99-1010-#ifndef _EATA_PIO_H1111-#define _EATA_PIO_H1212-1313-#define VER_MAJOR 01414-#define VER_MINOR 01515-#define VER_SUB "1b"1616-1717-/************************************************************************1818- * Here you can switch parts of the code on and of *1919- ************************************************************************/2020-2121-#define VERBOSE_SETUP /* show startup screen of 2001 */2222-#define ALLOW_DMA_BOARDS 12323-2424-/************************************************************************2525- * Debug options. * 2626- * Enable DEBUG and whichever options you require. *2727- ************************************************************************/2828-#define DEBUG_EATA 1 /* Enable debug code. */2929-#define DPT_DEBUG 0 /* Bobs special */3030-#define DBG_DELAY 0 /* Build in delays so debug messages can be3131- * be read before they vanish of the top of3232- * the screen!3333- */3434-#define DBG_PROBE 0 /* Debug probe routines. */3535-#define DBG_ISA 0 /* Trace ISA routines */3636-#define DBG_EISA 0 /* Trace EISA routines */3737-#define DBG_PCI 0 /* Trace PCI routines */3838-#define DBG_PIO 0 /* Trace get_config_PIO */3939-#define DBG_COM 0 /* Trace command call */4040-#define DBG_QUEUE 0 /* Trace command queueing. */4141-#define DBG_INTR 0 /* Trace interrupt service routine. */4242-#define DBG_INTR2 0 /* Trace interrupt service routine. */4343-#define DBG_PROC 0 /* Debug proc-fs related statistics */4444-#define DBG_PROC_WRITE 04545-#define DBG_REGISTER 0 /* */4646-#define DBG_ABNORM 1 /* Debug abnormal actions (reset, abort) */4747-4848-#if DEBUG_EATA4949-#define DBG(x, y) if ((x)) {y;}5050-#else5151-#define DBG(x, y)5252-#endif5353-5454-#endif /* _EATA_PIO_H */