18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Adaptec AIC7xxx device driver for Linux. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_osm.c#235 $ 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright (c) 1994 John Aycock 78c2ecf20Sopenharmony_ci * The University of Calgary Department of Computer Science. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify 108c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by 118c2ecf20Sopenharmony_ci * the Free Software Foundation; either version 2, or (at your option) 128c2ecf20Sopenharmony_ci * any later version. 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful, 158c2ecf20Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 168c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 178c2ecf20Sopenharmony_ci * GNU General Public License for more details. 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * You should have received a copy of the GNU General Public License 208c2ecf20Sopenharmony_ci * along with this program; see the file COPYING. If not, write to 218c2ecf20Sopenharmony_ci * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * Sources include the Adaptec 1740 driver (aha1740.c), the Ultrastor 24F 248c2ecf20Sopenharmony_ci * driver (ultrastor.c), various Linux kernel source, the Adaptec EISA 258c2ecf20Sopenharmony_ci * config file (!adp7771.cfg), the Adaptec AHA-2740A Series User's Guide, 268c2ecf20Sopenharmony_ci * the Linux Kernel Hacker's Guide, Writing a SCSI Device Driver for Linux, 278c2ecf20Sopenharmony_ci * the Adaptec 1542 driver (aha1542.c), the Adaptec EISA overlay file 288c2ecf20Sopenharmony_ci * (adp7770.ovl), the Adaptec AHA-2740 Series Technical Reference Manual, 298c2ecf20Sopenharmony_ci * the Adaptec AIC-7770 Data Book, the ANSI SCSI specification, the 308c2ecf20Sopenharmony_ci * ANSI SCSI-2 specification (draft 10c), ... 318c2ecf20Sopenharmony_ci * 328c2ecf20Sopenharmony_ci * -------------------------------------------------------------------------- 338c2ecf20Sopenharmony_ci * 348c2ecf20Sopenharmony_ci * Modifications by Daniel M. Eischen (deischen@iworks.InterWorks.org): 358c2ecf20Sopenharmony_ci * 368c2ecf20Sopenharmony_ci * Substantially modified to include support for wide and twin bus 378c2ecf20Sopenharmony_ci * adapters, DMAing of SCBs, tagged queueing, IRQ sharing, bug fixes, 388c2ecf20Sopenharmony_ci * SCB paging, and other rework of the code. 398c2ecf20Sopenharmony_ci * 408c2ecf20Sopenharmony_ci * -------------------------------------------------------------------------- 418c2ecf20Sopenharmony_ci * Copyright (c) 1994-2000 Justin T. Gibbs. 428c2ecf20Sopenharmony_ci * Copyright (c) 2000-2001 Adaptec Inc. 438c2ecf20Sopenharmony_ci * All rights reserved. 448c2ecf20Sopenharmony_ci * 458c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 468c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions 478c2ecf20Sopenharmony_ci * are met: 488c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright 498c2ecf20Sopenharmony_ci * notice, this list of conditions, and the following disclaimer, 508c2ecf20Sopenharmony_ci * without modification. 518c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce at minimum a disclaimer 528c2ecf20Sopenharmony_ci * substantially similar to the "NO WARRANTY" disclaimer below 538c2ecf20Sopenharmony_ci * ("Disclaimer") and any redistribution must be conditioned upon 548c2ecf20Sopenharmony_ci * including a substantially similar Disclaimer requirement for further 558c2ecf20Sopenharmony_ci * binary redistribution. 568c2ecf20Sopenharmony_ci * 3. Neither the names of the above-listed copyright holders nor the names 578c2ecf20Sopenharmony_ci * of any contributors may be used to endorse or promote products derived 588c2ecf20Sopenharmony_ci * from this software without specific prior written permission. 598c2ecf20Sopenharmony_ci * 608c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the 618c2ecf20Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free 628c2ecf20Sopenharmony_ci * Software Foundation. 638c2ecf20Sopenharmony_ci * 648c2ecf20Sopenharmony_ci * NO WARRANTY 658c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 668c2ecf20Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 678c2ecf20Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 688c2ecf20Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 698c2ecf20Sopenharmony_ci * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 708c2ecf20Sopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 718c2ecf20Sopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 728c2ecf20Sopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 738c2ecf20Sopenharmony_ci * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 748c2ecf20Sopenharmony_ci * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 758c2ecf20Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGES. 768c2ecf20Sopenharmony_ci * 778c2ecf20Sopenharmony_ci *--------------------------------------------------------------------------- 788c2ecf20Sopenharmony_ci * 798c2ecf20Sopenharmony_ci * Thanks also go to (in alphabetical order) the following: 808c2ecf20Sopenharmony_ci * 818c2ecf20Sopenharmony_ci * Rory Bolt - Sequencer bug fixes 828c2ecf20Sopenharmony_ci * Jay Estabrook - Initial DEC Alpha support 838c2ecf20Sopenharmony_ci * Doug Ledford - Much needed abort/reset bug fixes 848c2ecf20Sopenharmony_ci * Kai Makisara - DMAing of SCBs 858c2ecf20Sopenharmony_ci * 868c2ecf20Sopenharmony_ci * A Boot time option was also added for not resetting the scsi bus. 878c2ecf20Sopenharmony_ci * 888c2ecf20Sopenharmony_ci * Form: aic7xxx=extended 898c2ecf20Sopenharmony_ci * aic7xxx=no_reset 908c2ecf20Sopenharmony_ci * aic7xxx=verbose 918c2ecf20Sopenharmony_ci * 928c2ecf20Sopenharmony_ci * Daniel M. Eischen, deischen@iworks.InterWorks.org, 1/23/97 938c2ecf20Sopenharmony_ci * 948c2ecf20Sopenharmony_ci * Id: aic7xxx.c,v 4.1 1997/06/12 08:23:42 deang Exp 958c2ecf20Sopenharmony_ci */ 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci/* 988c2ecf20Sopenharmony_ci * Further driver modifications made by Doug Ledford <dledford@redhat.com> 998c2ecf20Sopenharmony_ci * 1008c2ecf20Sopenharmony_ci * Copyright (c) 1997-1999 Doug Ledford 1018c2ecf20Sopenharmony_ci * 1028c2ecf20Sopenharmony_ci * These changes are released under the same licensing terms as the FreeBSD 1038c2ecf20Sopenharmony_ci * driver written by Justin Gibbs. Please see his Copyright notice above 1048c2ecf20Sopenharmony_ci * for the exact terms and conditions covering my changes as well as the 1058c2ecf20Sopenharmony_ci * warranty statement. 1068c2ecf20Sopenharmony_ci * 1078c2ecf20Sopenharmony_ci * Modifications made to the aic7xxx.c,v 4.1 driver from Dan Eischen include 1088c2ecf20Sopenharmony_ci * but are not limited to: 1098c2ecf20Sopenharmony_ci * 1108c2ecf20Sopenharmony_ci * 1: Import of the latest FreeBSD sequencer code for this driver 1118c2ecf20Sopenharmony_ci * 2: Modification of kernel code to accommodate different sequencer semantics 1128c2ecf20Sopenharmony_ci * 3: Extensive changes throughout kernel portion of driver to improve 1138c2ecf20Sopenharmony_ci * abort/reset processing and error hanndling 1148c2ecf20Sopenharmony_ci * 4: Other work contributed by various people on the Internet 1158c2ecf20Sopenharmony_ci * 5: Changes to printk information and verbosity selection code 1168c2ecf20Sopenharmony_ci * 6: General reliability related changes, especially in IRQ management 1178c2ecf20Sopenharmony_ci * 7: Modifications to the default probe/attach order for supported cards 1188c2ecf20Sopenharmony_ci * 8: SMP friendliness has been improved 1198c2ecf20Sopenharmony_ci * 1208c2ecf20Sopenharmony_ci */ 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci#include "aic7xxx_osm.h" 1238c2ecf20Sopenharmony_ci#include "aic7xxx_inline.h" 1248c2ecf20Sopenharmony_ci#include <scsi/scsicam.h> 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_cistatic struct scsi_transport_template *ahc_linux_transport_template = NULL; 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci#include <linux/init.h> /* __setup */ 1298c2ecf20Sopenharmony_ci#include <linux/mm.h> /* For fetching system memory size */ 1308c2ecf20Sopenharmony_ci#include <linux/blkdev.h> /* For block_size() */ 1318c2ecf20Sopenharmony_ci#include <linux/delay.h> /* For ssleep/msleep */ 1328c2ecf20Sopenharmony_ci#include <linux/slab.h> 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci/* 1368c2ecf20Sopenharmony_ci * Set this to the delay in seconds after SCSI bus reset. 1378c2ecf20Sopenharmony_ci * Note, we honor this only for the initial bus reset. 1388c2ecf20Sopenharmony_ci * The scsi error recovery code performs its own bus settle 1398c2ecf20Sopenharmony_ci * delay handling for error recovery actions. 1408c2ecf20Sopenharmony_ci */ 1418c2ecf20Sopenharmony_ci#ifdef CONFIG_AIC7XXX_RESET_DELAY_MS 1428c2ecf20Sopenharmony_ci#define AIC7XXX_RESET_DELAY CONFIG_AIC7XXX_RESET_DELAY_MS 1438c2ecf20Sopenharmony_ci#else 1448c2ecf20Sopenharmony_ci#define AIC7XXX_RESET_DELAY 5000 1458c2ecf20Sopenharmony_ci#endif 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci/* 1488c2ecf20Sopenharmony_ci * To change the default number of tagged transactions allowed per-device, 1498c2ecf20Sopenharmony_ci * add a line to the lilo.conf file like: 1508c2ecf20Sopenharmony_ci * append="aic7xxx=verbose,tag_info:{{32,32,32,32},{32,32,32,32}}" 1518c2ecf20Sopenharmony_ci * which will result in the first four devices on the first two 1528c2ecf20Sopenharmony_ci * controllers being set to a tagged queue depth of 32. 1538c2ecf20Sopenharmony_ci * 1548c2ecf20Sopenharmony_ci * The tag_commands is an array of 16 to allow for wide and twin adapters. 1558c2ecf20Sopenharmony_ci * Twin adapters will use indexes 0-7 for channel 0, and indexes 8-15 1568c2ecf20Sopenharmony_ci * for channel 1. 1578c2ecf20Sopenharmony_ci */ 1588c2ecf20Sopenharmony_citypedef struct { 1598c2ecf20Sopenharmony_ci uint8_t tag_commands[16]; /* Allow for wide/twin adapters. */ 1608c2ecf20Sopenharmony_ci} adapter_tag_info_t; 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci/* 1638c2ecf20Sopenharmony_ci * Modify this as you see fit for your system. 1648c2ecf20Sopenharmony_ci * 1658c2ecf20Sopenharmony_ci * 0 tagged queuing disabled 1668c2ecf20Sopenharmony_ci * 1 <= n <= 253 n == max tags ever dispatched. 1678c2ecf20Sopenharmony_ci * 1688c2ecf20Sopenharmony_ci * The driver will throttle the number of commands dispatched to a 1698c2ecf20Sopenharmony_ci * device if it returns queue full. For devices with a fixed maximum 1708c2ecf20Sopenharmony_ci * queue depth, the driver will eventually determine this depth and 1718c2ecf20Sopenharmony_ci * lock it in (a console message is printed to indicate that a lock 1728c2ecf20Sopenharmony_ci * has occurred). On some devices, queue full is returned for a temporary 1738c2ecf20Sopenharmony_ci * resource shortage. These devices will return queue full at varying 1748c2ecf20Sopenharmony_ci * depths. The driver will throttle back when the queue fulls occur and 1758c2ecf20Sopenharmony_ci * attempt to slowly increase the depth over time as the device recovers 1768c2ecf20Sopenharmony_ci * from the resource shortage. 1778c2ecf20Sopenharmony_ci * 1788c2ecf20Sopenharmony_ci * In this example, the first line will disable tagged queueing for all 1798c2ecf20Sopenharmony_ci * the devices on the first probed aic7xxx adapter. 1808c2ecf20Sopenharmony_ci * 1818c2ecf20Sopenharmony_ci * The second line enables tagged queueing with 4 commands/LUN for IDs 1828c2ecf20Sopenharmony_ci * (0, 2-11, 13-15), disables tagged queueing for ID 12, and tells the 1838c2ecf20Sopenharmony_ci * driver to attempt to use up to 64 tags for ID 1. 1848c2ecf20Sopenharmony_ci * 1858c2ecf20Sopenharmony_ci * The third line is the same as the first line. 1868c2ecf20Sopenharmony_ci * 1878c2ecf20Sopenharmony_ci * The fourth line disables tagged queueing for devices 0 and 3. It 1888c2ecf20Sopenharmony_ci * enables tagged queueing for the other IDs, with 16 commands/LUN 1898c2ecf20Sopenharmony_ci * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for 1908c2ecf20Sopenharmony_ci * IDs 2, 5-7, and 9-15. 1918c2ecf20Sopenharmony_ci */ 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci/* 1948c2ecf20Sopenharmony_ci * NOTE: The below structure is for reference only, the actual structure 1958c2ecf20Sopenharmony_ci * to modify in order to change things is just below this comment block. 1968c2ecf20Sopenharmony_ciadapter_tag_info_t aic7xxx_tag_info[] = 1978c2ecf20Sopenharmony_ci{ 1988c2ecf20Sopenharmony_ci {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, 1998c2ecf20Sopenharmony_ci {{4, 64, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4}}, 2008c2ecf20Sopenharmony_ci {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, 2018c2ecf20Sopenharmony_ci {{0, 16, 4, 0, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}} 2028c2ecf20Sopenharmony_ci}; 2038c2ecf20Sopenharmony_ci*/ 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci#ifdef CONFIG_AIC7XXX_CMDS_PER_DEVICE 2068c2ecf20Sopenharmony_ci#define AIC7XXX_CMDS_PER_DEVICE CONFIG_AIC7XXX_CMDS_PER_DEVICE 2078c2ecf20Sopenharmony_ci#else 2088c2ecf20Sopenharmony_ci#define AIC7XXX_CMDS_PER_DEVICE AHC_MAX_QUEUE 2098c2ecf20Sopenharmony_ci#endif 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci#define AIC7XXX_CONFIGED_TAG_COMMANDS { \ 2128c2ecf20Sopenharmony_ci AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \ 2138c2ecf20Sopenharmony_ci AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \ 2148c2ecf20Sopenharmony_ci AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \ 2158c2ecf20Sopenharmony_ci AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \ 2168c2ecf20Sopenharmony_ci AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \ 2178c2ecf20Sopenharmony_ci AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \ 2188c2ecf20Sopenharmony_ci AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \ 2198c2ecf20Sopenharmony_ci AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE \ 2208c2ecf20Sopenharmony_ci} 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ci/* 2238c2ecf20Sopenharmony_ci * By default, use the number of commands specified by 2248c2ecf20Sopenharmony_ci * the users kernel configuration. 2258c2ecf20Sopenharmony_ci */ 2268c2ecf20Sopenharmony_cistatic adapter_tag_info_t aic7xxx_tag_info[] = 2278c2ecf20Sopenharmony_ci{ 2288c2ecf20Sopenharmony_ci {AIC7XXX_CONFIGED_TAG_COMMANDS}, 2298c2ecf20Sopenharmony_ci {AIC7XXX_CONFIGED_TAG_COMMANDS}, 2308c2ecf20Sopenharmony_ci {AIC7XXX_CONFIGED_TAG_COMMANDS}, 2318c2ecf20Sopenharmony_ci {AIC7XXX_CONFIGED_TAG_COMMANDS}, 2328c2ecf20Sopenharmony_ci {AIC7XXX_CONFIGED_TAG_COMMANDS}, 2338c2ecf20Sopenharmony_ci {AIC7XXX_CONFIGED_TAG_COMMANDS}, 2348c2ecf20Sopenharmony_ci {AIC7XXX_CONFIGED_TAG_COMMANDS}, 2358c2ecf20Sopenharmony_ci {AIC7XXX_CONFIGED_TAG_COMMANDS}, 2368c2ecf20Sopenharmony_ci {AIC7XXX_CONFIGED_TAG_COMMANDS}, 2378c2ecf20Sopenharmony_ci {AIC7XXX_CONFIGED_TAG_COMMANDS}, 2388c2ecf20Sopenharmony_ci {AIC7XXX_CONFIGED_TAG_COMMANDS}, 2398c2ecf20Sopenharmony_ci {AIC7XXX_CONFIGED_TAG_COMMANDS}, 2408c2ecf20Sopenharmony_ci {AIC7XXX_CONFIGED_TAG_COMMANDS}, 2418c2ecf20Sopenharmony_ci {AIC7XXX_CONFIGED_TAG_COMMANDS}, 2428c2ecf20Sopenharmony_ci {AIC7XXX_CONFIGED_TAG_COMMANDS}, 2438c2ecf20Sopenharmony_ci {AIC7XXX_CONFIGED_TAG_COMMANDS} 2448c2ecf20Sopenharmony_ci}; 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_ci/* 2478c2ecf20Sopenharmony_ci * There should be a specific return value for this in scsi.h, but 2488c2ecf20Sopenharmony_ci * it seems that most drivers ignore it. 2498c2ecf20Sopenharmony_ci */ 2508c2ecf20Sopenharmony_ci#define DID_UNDERFLOW DID_ERROR 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_civoid 2538c2ecf20Sopenharmony_ciahc_print_path(struct ahc_softc *ahc, struct scb *scb) 2548c2ecf20Sopenharmony_ci{ 2558c2ecf20Sopenharmony_ci printk("(scsi%d:%c:%d:%d): ", 2568c2ecf20Sopenharmony_ci ahc->platform_data->host->host_no, 2578c2ecf20Sopenharmony_ci scb != NULL ? SCB_GET_CHANNEL(ahc, scb) : 'X', 2588c2ecf20Sopenharmony_ci scb != NULL ? SCB_GET_TARGET(ahc, scb) : -1, 2598c2ecf20Sopenharmony_ci scb != NULL ? SCB_GET_LUN(scb) : -1); 2608c2ecf20Sopenharmony_ci} 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_ci/* 2638c2ecf20Sopenharmony_ci * XXX - these options apply unilaterally to _all_ 274x/284x/294x 2648c2ecf20Sopenharmony_ci * cards in the system. This should be fixed. Exceptions to this 2658c2ecf20Sopenharmony_ci * rule are noted in the comments. 2668c2ecf20Sopenharmony_ci */ 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci/* 2698c2ecf20Sopenharmony_ci * Skip the scsi bus reset. Non 0 make us skip the reset at startup. This 2708c2ecf20Sopenharmony_ci * has no effect on any later resets that might occur due to things like 2718c2ecf20Sopenharmony_ci * SCSI bus timeouts. 2728c2ecf20Sopenharmony_ci */ 2738c2ecf20Sopenharmony_cistatic uint32_t aic7xxx_no_reset; 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci/* 2768c2ecf20Sopenharmony_ci * Should we force EXTENDED translation on a controller. 2778c2ecf20Sopenharmony_ci * 0 == Use whatever is in the SEEPROM or default to off 2788c2ecf20Sopenharmony_ci * 1 == Use whatever is in the SEEPROM or default to on 2798c2ecf20Sopenharmony_ci */ 2808c2ecf20Sopenharmony_cistatic uint32_t aic7xxx_extended; 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci/* 2838c2ecf20Sopenharmony_ci * PCI bus parity checking of the Adaptec controllers. This is somewhat 2848c2ecf20Sopenharmony_ci * dubious at best. To my knowledge, this option has never actually 2858c2ecf20Sopenharmony_ci * solved a PCI parity problem, but on certain machines with broken PCI 2868c2ecf20Sopenharmony_ci * chipset configurations where stray PCI transactions with bad parity are 2878c2ecf20Sopenharmony_ci * the norm rather than the exception, the error messages can be overwhelming. 2888c2ecf20Sopenharmony_ci * It's included in the driver for completeness. 2898c2ecf20Sopenharmony_ci * 0 = Shut off PCI parity check 2908c2ecf20Sopenharmony_ci * non-0 = reverse polarity pci parity checking 2918c2ecf20Sopenharmony_ci */ 2928c2ecf20Sopenharmony_cistatic uint32_t aic7xxx_pci_parity = ~0; 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ci/* 2958c2ecf20Sopenharmony_ci * There are lots of broken chipsets in the world. Some of them will 2968c2ecf20Sopenharmony_ci * violate the PCI spec when we issue byte sized memory writes to our 2978c2ecf20Sopenharmony_ci * controller. I/O mapped register access, if allowed by the given 2988c2ecf20Sopenharmony_ci * platform, will work in almost all cases. 2998c2ecf20Sopenharmony_ci */ 3008c2ecf20Sopenharmony_ciuint32_t aic7xxx_allow_memio = ~0; 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ci/* 3038c2ecf20Sopenharmony_ci * So that we can set how long each device is given as a selection timeout. 3048c2ecf20Sopenharmony_ci * The table of values goes like this: 3058c2ecf20Sopenharmony_ci * 0 - 256ms 3068c2ecf20Sopenharmony_ci * 1 - 128ms 3078c2ecf20Sopenharmony_ci * 2 - 64ms 3088c2ecf20Sopenharmony_ci * 3 - 32ms 3098c2ecf20Sopenharmony_ci * We default to 256ms because some older devices need a longer time 3108c2ecf20Sopenharmony_ci * to respond to initial selection. 3118c2ecf20Sopenharmony_ci */ 3128c2ecf20Sopenharmony_cistatic uint32_t aic7xxx_seltime; 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci/* 3158c2ecf20Sopenharmony_ci * Certain devices do not perform any aging on commands. Should the 3168c2ecf20Sopenharmony_ci * device be saturated by commands in one portion of the disk, it is 3178c2ecf20Sopenharmony_ci * possible for transactions on far away sectors to never be serviced. 3188c2ecf20Sopenharmony_ci * To handle these devices, we can periodically send an ordered tag to 3198c2ecf20Sopenharmony_ci * force all outstanding transactions to be serviced prior to a new 3208c2ecf20Sopenharmony_ci * transaction. 3218c2ecf20Sopenharmony_ci */ 3228c2ecf20Sopenharmony_cistatic uint32_t aic7xxx_periodic_otag; 3238c2ecf20Sopenharmony_ci 3248c2ecf20Sopenharmony_ci/* 3258c2ecf20Sopenharmony_ci * Module information and settable options. 3268c2ecf20Sopenharmony_ci */ 3278c2ecf20Sopenharmony_cistatic char *aic7xxx = NULL; 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_ciMODULE_AUTHOR("Maintainer: Hannes Reinecke <hare@suse.de>"); 3308c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Adaptec AIC77XX/78XX SCSI Host Bus Adapter driver"); 3318c2ecf20Sopenharmony_ciMODULE_LICENSE("Dual BSD/GPL"); 3328c2ecf20Sopenharmony_ciMODULE_VERSION(AIC7XXX_DRIVER_VERSION); 3338c2ecf20Sopenharmony_cimodule_param(aic7xxx, charp, 0444); 3348c2ecf20Sopenharmony_ciMODULE_PARM_DESC(aic7xxx, 3358c2ecf20Sopenharmony_ci"period-delimited options string:\n" 3368c2ecf20Sopenharmony_ci" verbose Enable verbose/diagnostic logging\n" 3378c2ecf20Sopenharmony_ci" allow_memio Allow device registers to be memory mapped\n" 3388c2ecf20Sopenharmony_ci" debug Bitmask of debug values to enable\n" 3398c2ecf20Sopenharmony_ci" no_probe Toggle EISA/VLB controller probing\n" 3408c2ecf20Sopenharmony_ci" probe_eisa_vl Toggle EISA/VLB controller probing\n" 3418c2ecf20Sopenharmony_ci" no_reset Suppress initial bus resets\n" 3428c2ecf20Sopenharmony_ci" extended Enable extended geometry on all controllers\n" 3438c2ecf20Sopenharmony_ci" periodic_otag Send an ordered tagged transaction\n" 3448c2ecf20Sopenharmony_ci" periodically to prevent tag starvation.\n" 3458c2ecf20Sopenharmony_ci" This may be required by some older disk\n" 3468c2ecf20Sopenharmony_ci" drives or RAID arrays.\n" 3478c2ecf20Sopenharmony_ci" tag_info:<tag_str> Set per-target tag depth\n" 3488c2ecf20Sopenharmony_ci" global_tag_depth:<int> Global tag depth for every target\n" 3498c2ecf20Sopenharmony_ci" on every bus\n" 3508c2ecf20Sopenharmony_ci" seltime:<int> Selection Timeout\n" 3518c2ecf20Sopenharmony_ci" (0/256ms,1/128ms,2/64ms,3/32ms)\n" 3528c2ecf20Sopenharmony_ci"\n" 3538c2ecf20Sopenharmony_ci" Sample modprobe configuration file:\n" 3548c2ecf20Sopenharmony_ci" # Toggle EISA/VLB probing\n" 3558c2ecf20Sopenharmony_ci" # Set tag depth on Controller 1/Target 1 to 10 tags\n" 3568c2ecf20Sopenharmony_ci" # Shorten the selection timeout to 128ms\n" 3578c2ecf20Sopenharmony_ci"\n" 3588c2ecf20Sopenharmony_ci" options aic7xxx 'aic7xxx=probe_eisa_vl.tag_info:{{}.{.10}}.seltime:1'\n" 3598c2ecf20Sopenharmony_ci); 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_cistatic void ahc_linux_handle_scsi_status(struct ahc_softc *, 3628c2ecf20Sopenharmony_ci struct scsi_device *, 3638c2ecf20Sopenharmony_ci struct scb *); 3648c2ecf20Sopenharmony_cistatic void ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, 3658c2ecf20Sopenharmony_ci struct scsi_cmnd *cmd); 3668c2ecf20Sopenharmony_cistatic void ahc_linux_freeze_simq(struct ahc_softc *ahc); 3678c2ecf20Sopenharmony_cistatic void ahc_linux_release_simq(struct ahc_softc *ahc); 3688c2ecf20Sopenharmony_cistatic int ahc_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag); 3698c2ecf20Sopenharmony_cistatic void ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc); 3708c2ecf20Sopenharmony_cistatic u_int ahc_linux_user_tagdepth(struct ahc_softc *ahc, 3718c2ecf20Sopenharmony_ci struct ahc_devinfo *devinfo); 3728c2ecf20Sopenharmony_cistatic void ahc_linux_device_queue_depth(struct scsi_device *); 3738c2ecf20Sopenharmony_cistatic int ahc_linux_run_command(struct ahc_softc*, 3748c2ecf20Sopenharmony_ci struct ahc_linux_device *, 3758c2ecf20Sopenharmony_ci struct scsi_cmnd *); 3768c2ecf20Sopenharmony_cistatic void ahc_linux_setup_tag_info_global(char *p); 3778c2ecf20Sopenharmony_cistatic int aic7xxx_setup(char *s); 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_cistatic int ahc_linux_unit; 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci 3828c2ecf20Sopenharmony_ci/************************** OS Utility Wrappers *******************************/ 3838c2ecf20Sopenharmony_civoid 3848c2ecf20Sopenharmony_ciahc_delay(long usec) 3858c2ecf20Sopenharmony_ci{ 3868c2ecf20Sopenharmony_ci /* 3878c2ecf20Sopenharmony_ci * udelay on Linux can have problems for 3888c2ecf20Sopenharmony_ci * multi-millisecond waits. Wait at most 3898c2ecf20Sopenharmony_ci * 1024us per call. 3908c2ecf20Sopenharmony_ci */ 3918c2ecf20Sopenharmony_ci while (usec > 0) { 3928c2ecf20Sopenharmony_ci udelay(usec % 1024); 3938c2ecf20Sopenharmony_ci usec -= 1024; 3948c2ecf20Sopenharmony_ci } 3958c2ecf20Sopenharmony_ci} 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_ci/***************************** Low Level I/O **********************************/ 3988c2ecf20Sopenharmony_ciuint8_t 3998c2ecf20Sopenharmony_ciahc_inb(struct ahc_softc * ahc, long port) 4008c2ecf20Sopenharmony_ci{ 4018c2ecf20Sopenharmony_ci uint8_t x; 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ci if (ahc->tag == BUS_SPACE_MEMIO) { 4048c2ecf20Sopenharmony_ci x = readb(ahc->bsh.maddr + port); 4058c2ecf20Sopenharmony_ci } else { 4068c2ecf20Sopenharmony_ci x = inb(ahc->bsh.ioport + port); 4078c2ecf20Sopenharmony_ci } 4088c2ecf20Sopenharmony_ci mb(); 4098c2ecf20Sopenharmony_ci return (x); 4108c2ecf20Sopenharmony_ci} 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_civoid 4138c2ecf20Sopenharmony_ciahc_outb(struct ahc_softc * ahc, long port, uint8_t val) 4148c2ecf20Sopenharmony_ci{ 4158c2ecf20Sopenharmony_ci if (ahc->tag == BUS_SPACE_MEMIO) { 4168c2ecf20Sopenharmony_ci writeb(val, ahc->bsh.maddr + port); 4178c2ecf20Sopenharmony_ci } else { 4188c2ecf20Sopenharmony_ci outb(val, ahc->bsh.ioport + port); 4198c2ecf20Sopenharmony_ci } 4208c2ecf20Sopenharmony_ci mb(); 4218c2ecf20Sopenharmony_ci} 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_civoid 4248c2ecf20Sopenharmony_ciahc_outsb(struct ahc_softc * ahc, long port, uint8_t *array, int count) 4258c2ecf20Sopenharmony_ci{ 4268c2ecf20Sopenharmony_ci int i; 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci /* 4298c2ecf20Sopenharmony_ci * There is probably a more efficient way to do this on Linux 4308c2ecf20Sopenharmony_ci * but we don't use this for anything speed critical and this 4318c2ecf20Sopenharmony_ci * should work. 4328c2ecf20Sopenharmony_ci */ 4338c2ecf20Sopenharmony_ci for (i = 0; i < count; i++) 4348c2ecf20Sopenharmony_ci ahc_outb(ahc, port, *array++); 4358c2ecf20Sopenharmony_ci} 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_civoid 4388c2ecf20Sopenharmony_ciahc_insb(struct ahc_softc * ahc, long port, uint8_t *array, int count) 4398c2ecf20Sopenharmony_ci{ 4408c2ecf20Sopenharmony_ci int i; 4418c2ecf20Sopenharmony_ci 4428c2ecf20Sopenharmony_ci /* 4438c2ecf20Sopenharmony_ci * There is probably a more efficient way to do this on Linux 4448c2ecf20Sopenharmony_ci * but we don't use this for anything speed critical and this 4458c2ecf20Sopenharmony_ci * should work. 4468c2ecf20Sopenharmony_ci */ 4478c2ecf20Sopenharmony_ci for (i = 0; i < count; i++) 4488c2ecf20Sopenharmony_ci *array++ = ahc_inb(ahc, port); 4498c2ecf20Sopenharmony_ci} 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_ci/********************************* Inlines ************************************/ 4528c2ecf20Sopenharmony_cistatic void ahc_linux_unmap_scb(struct ahc_softc*, struct scb*); 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_cistatic int ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb, 4558c2ecf20Sopenharmony_ci struct ahc_dma_seg *sg, 4568c2ecf20Sopenharmony_ci dma_addr_t addr, bus_size_t len); 4578c2ecf20Sopenharmony_ci 4588c2ecf20Sopenharmony_cistatic void 4598c2ecf20Sopenharmony_ciahc_linux_unmap_scb(struct ahc_softc *ahc, struct scb *scb) 4608c2ecf20Sopenharmony_ci{ 4618c2ecf20Sopenharmony_ci struct scsi_cmnd *cmd; 4628c2ecf20Sopenharmony_ci 4638c2ecf20Sopenharmony_ci cmd = scb->io_ctx; 4648c2ecf20Sopenharmony_ci ahc_sync_sglist(ahc, scb, BUS_DMASYNC_POSTWRITE); 4658c2ecf20Sopenharmony_ci 4668c2ecf20Sopenharmony_ci scsi_dma_unmap(cmd); 4678c2ecf20Sopenharmony_ci} 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_cistatic int 4708c2ecf20Sopenharmony_ciahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb, 4718c2ecf20Sopenharmony_ci struct ahc_dma_seg *sg, dma_addr_t addr, bus_size_t len) 4728c2ecf20Sopenharmony_ci{ 4738c2ecf20Sopenharmony_ci int consumed; 4748c2ecf20Sopenharmony_ci 4758c2ecf20Sopenharmony_ci if ((scb->sg_count + 1) > AHC_NSEG) 4768c2ecf20Sopenharmony_ci panic("Too few segs for dma mapping. " 4778c2ecf20Sopenharmony_ci "Increase AHC_NSEG\n"); 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ci consumed = 1; 4808c2ecf20Sopenharmony_ci sg->addr = ahc_htole32(addr & 0xFFFFFFFF); 4818c2ecf20Sopenharmony_ci scb->platform_data->xfer_len += len; 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_ci if (sizeof(dma_addr_t) > 4 4848c2ecf20Sopenharmony_ci && (ahc->flags & AHC_39BIT_ADDRESSING) != 0) 4858c2ecf20Sopenharmony_ci len |= (addr >> 8) & AHC_SG_HIGH_ADDR_MASK; 4868c2ecf20Sopenharmony_ci 4878c2ecf20Sopenharmony_ci sg->len = ahc_htole32(len); 4888c2ecf20Sopenharmony_ci return (consumed); 4898c2ecf20Sopenharmony_ci} 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_ci/* 4928c2ecf20Sopenharmony_ci * Return a string describing the driver. 4938c2ecf20Sopenharmony_ci */ 4948c2ecf20Sopenharmony_cistatic const char * 4958c2ecf20Sopenharmony_ciahc_linux_info(struct Scsi_Host *host) 4968c2ecf20Sopenharmony_ci{ 4978c2ecf20Sopenharmony_ci static char buffer[512]; 4988c2ecf20Sopenharmony_ci char ahc_info[256]; 4998c2ecf20Sopenharmony_ci char *bp; 5008c2ecf20Sopenharmony_ci struct ahc_softc *ahc; 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_ci bp = &buffer[0]; 5038c2ecf20Sopenharmony_ci ahc = *(struct ahc_softc **)host->hostdata; 5048c2ecf20Sopenharmony_ci memset(bp, 0, sizeof(buffer)); 5058c2ecf20Sopenharmony_ci strcpy(bp, "Adaptec AIC7XXX EISA/VLB/PCI SCSI HBA DRIVER, Rev " AIC7XXX_DRIVER_VERSION "\n" 5068c2ecf20Sopenharmony_ci " <"); 5078c2ecf20Sopenharmony_ci strcat(bp, ahc->description); 5088c2ecf20Sopenharmony_ci strcat(bp, ">\n" 5098c2ecf20Sopenharmony_ci " "); 5108c2ecf20Sopenharmony_ci ahc_controller_info(ahc, ahc_info); 5118c2ecf20Sopenharmony_ci strcat(bp, ahc_info); 5128c2ecf20Sopenharmony_ci strcat(bp, "\n"); 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_ci return (bp); 5158c2ecf20Sopenharmony_ci} 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci/* 5188c2ecf20Sopenharmony_ci * Queue an SCB to the controller. 5198c2ecf20Sopenharmony_ci */ 5208c2ecf20Sopenharmony_cistatic int 5218c2ecf20Sopenharmony_ciahc_linux_queue_lck(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *)) 5228c2ecf20Sopenharmony_ci{ 5238c2ecf20Sopenharmony_ci struct ahc_softc *ahc; 5248c2ecf20Sopenharmony_ci struct ahc_linux_device *dev = scsi_transport_device_data(cmd->device); 5258c2ecf20Sopenharmony_ci int rtn = SCSI_MLQUEUE_HOST_BUSY; 5268c2ecf20Sopenharmony_ci unsigned long flags; 5278c2ecf20Sopenharmony_ci 5288c2ecf20Sopenharmony_ci ahc = *(struct ahc_softc **)cmd->device->host->hostdata; 5298c2ecf20Sopenharmony_ci 5308c2ecf20Sopenharmony_ci ahc_lock(ahc, &flags); 5318c2ecf20Sopenharmony_ci if (ahc->platform_data->qfrozen == 0) { 5328c2ecf20Sopenharmony_ci cmd->scsi_done = scsi_done; 5338c2ecf20Sopenharmony_ci cmd->result = CAM_REQ_INPROG << 16; 5348c2ecf20Sopenharmony_ci rtn = ahc_linux_run_command(ahc, dev, cmd); 5358c2ecf20Sopenharmony_ci } 5368c2ecf20Sopenharmony_ci ahc_unlock(ahc, &flags); 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_ci return rtn; 5398c2ecf20Sopenharmony_ci} 5408c2ecf20Sopenharmony_ci 5418c2ecf20Sopenharmony_cistatic DEF_SCSI_QCMD(ahc_linux_queue) 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_cistatic inline struct scsi_target ** 5448c2ecf20Sopenharmony_ciahc_linux_target_in_softc(struct scsi_target *starget) 5458c2ecf20Sopenharmony_ci{ 5468c2ecf20Sopenharmony_ci struct ahc_softc *ahc = 5478c2ecf20Sopenharmony_ci *((struct ahc_softc **)dev_to_shost(&starget->dev)->hostdata); 5488c2ecf20Sopenharmony_ci unsigned int target_offset; 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_ci target_offset = starget->id; 5518c2ecf20Sopenharmony_ci if (starget->channel != 0) 5528c2ecf20Sopenharmony_ci target_offset += 8; 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_ci return &ahc->platform_data->starget[target_offset]; 5558c2ecf20Sopenharmony_ci} 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_cistatic int 5588c2ecf20Sopenharmony_ciahc_linux_target_alloc(struct scsi_target *starget) 5598c2ecf20Sopenharmony_ci{ 5608c2ecf20Sopenharmony_ci struct ahc_softc *ahc = 5618c2ecf20Sopenharmony_ci *((struct ahc_softc **)dev_to_shost(&starget->dev)->hostdata); 5628c2ecf20Sopenharmony_ci struct seeprom_config *sc = ahc->seep_config; 5638c2ecf20Sopenharmony_ci unsigned long flags; 5648c2ecf20Sopenharmony_ci struct scsi_target **ahc_targp = ahc_linux_target_in_softc(starget); 5658c2ecf20Sopenharmony_ci unsigned short scsirate; 5668c2ecf20Sopenharmony_ci struct ahc_devinfo devinfo; 5678c2ecf20Sopenharmony_ci char channel = starget->channel + 'A'; 5688c2ecf20Sopenharmony_ci unsigned int our_id = ahc->our_id; 5698c2ecf20Sopenharmony_ci unsigned int target_offset; 5708c2ecf20Sopenharmony_ci 5718c2ecf20Sopenharmony_ci target_offset = starget->id; 5728c2ecf20Sopenharmony_ci if (starget->channel != 0) 5738c2ecf20Sopenharmony_ci target_offset += 8; 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_ci if (starget->channel) 5768c2ecf20Sopenharmony_ci our_id = ahc->our_id_b; 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_ci ahc_lock(ahc, &flags); 5798c2ecf20Sopenharmony_ci 5808c2ecf20Sopenharmony_ci BUG_ON(*ahc_targp != NULL); 5818c2ecf20Sopenharmony_ci 5828c2ecf20Sopenharmony_ci *ahc_targp = starget; 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci if (sc) { 5858c2ecf20Sopenharmony_ci int maxsync = AHC_SYNCRATE_DT; 5868c2ecf20Sopenharmony_ci int ultra = 0; 5878c2ecf20Sopenharmony_ci int flags = sc->device_flags[target_offset]; 5888c2ecf20Sopenharmony_ci 5898c2ecf20Sopenharmony_ci if (ahc->flags & AHC_NEWEEPROM_FMT) { 5908c2ecf20Sopenharmony_ci if (flags & CFSYNCHISULTRA) 5918c2ecf20Sopenharmony_ci ultra = 1; 5928c2ecf20Sopenharmony_ci } else if (flags & CFULTRAEN) 5938c2ecf20Sopenharmony_ci ultra = 1; 5948c2ecf20Sopenharmony_ci /* AIC nutcase; 10MHz appears as ultra = 1, CFXFER = 0x04 5958c2ecf20Sopenharmony_ci * change it to ultra=0, CFXFER = 0 */ 5968c2ecf20Sopenharmony_ci if(ultra && (flags & CFXFER) == 0x04) { 5978c2ecf20Sopenharmony_ci ultra = 0; 5988c2ecf20Sopenharmony_ci flags &= ~CFXFER; 5998c2ecf20Sopenharmony_ci } 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_ci if ((ahc->features & AHC_ULTRA2) != 0) { 6028c2ecf20Sopenharmony_ci scsirate = (flags & CFXFER) | (ultra ? 0x8 : 0); 6038c2ecf20Sopenharmony_ci } else { 6048c2ecf20Sopenharmony_ci scsirate = (flags & CFXFER) << 4; 6058c2ecf20Sopenharmony_ci maxsync = ultra ? AHC_SYNCRATE_ULTRA : 6068c2ecf20Sopenharmony_ci AHC_SYNCRATE_FAST; 6078c2ecf20Sopenharmony_ci } 6088c2ecf20Sopenharmony_ci spi_max_width(starget) = (flags & CFWIDEB) ? 1 : 0; 6098c2ecf20Sopenharmony_ci if (!(flags & CFSYNCH)) 6108c2ecf20Sopenharmony_ci spi_max_offset(starget) = 0; 6118c2ecf20Sopenharmony_ci spi_min_period(starget) = 6128c2ecf20Sopenharmony_ci ahc_find_period(ahc, scsirate, maxsync); 6138c2ecf20Sopenharmony_ci } 6148c2ecf20Sopenharmony_ci ahc_compile_devinfo(&devinfo, our_id, starget->id, 6158c2ecf20Sopenharmony_ci CAM_LUN_WILDCARD, channel, 6168c2ecf20Sopenharmony_ci ROLE_INITIATOR); 6178c2ecf20Sopenharmony_ci ahc_set_syncrate(ahc, &devinfo, NULL, 0, 0, 0, 6188c2ecf20Sopenharmony_ci AHC_TRANS_GOAL, /*paused*/FALSE); 6198c2ecf20Sopenharmony_ci ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT, 6208c2ecf20Sopenharmony_ci AHC_TRANS_GOAL, /*paused*/FALSE); 6218c2ecf20Sopenharmony_ci ahc_unlock(ahc, &flags); 6228c2ecf20Sopenharmony_ci 6238c2ecf20Sopenharmony_ci return 0; 6248c2ecf20Sopenharmony_ci} 6258c2ecf20Sopenharmony_ci 6268c2ecf20Sopenharmony_cistatic void 6278c2ecf20Sopenharmony_ciahc_linux_target_destroy(struct scsi_target *starget) 6288c2ecf20Sopenharmony_ci{ 6298c2ecf20Sopenharmony_ci struct scsi_target **ahc_targp = ahc_linux_target_in_softc(starget); 6308c2ecf20Sopenharmony_ci 6318c2ecf20Sopenharmony_ci *ahc_targp = NULL; 6328c2ecf20Sopenharmony_ci} 6338c2ecf20Sopenharmony_ci 6348c2ecf20Sopenharmony_cistatic int 6358c2ecf20Sopenharmony_ciahc_linux_slave_alloc(struct scsi_device *sdev) 6368c2ecf20Sopenharmony_ci{ 6378c2ecf20Sopenharmony_ci struct ahc_softc *ahc = 6388c2ecf20Sopenharmony_ci *((struct ahc_softc **)sdev->host->hostdata); 6398c2ecf20Sopenharmony_ci struct scsi_target *starget = sdev->sdev_target; 6408c2ecf20Sopenharmony_ci struct ahc_linux_device *dev; 6418c2ecf20Sopenharmony_ci 6428c2ecf20Sopenharmony_ci if (bootverbose) 6438c2ecf20Sopenharmony_ci printk("%s: Slave Alloc %d\n", ahc_name(ahc), sdev->id); 6448c2ecf20Sopenharmony_ci 6458c2ecf20Sopenharmony_ci dev = scsi_transport_device_data(sdev); 6468c2ecf20Sopenharmony_ci memset(dev, 0, sizeof(*dev)); 6478c2ecf20Sopenharmony_ci 6488c2ecf20Sopenharmony_ci /* 6498c2ecf20Sopenharmony_ci * We start out life using untagged 6508c2ecf20Sopenharmony_ci * transactions of which we allow one. 6518c2ecf20Sopenharmony_ci */ 6528c2ecf20Sopenharmony_ci dev->openings = 1; 6538c2ecf20Sopenharmony_ci 6548c2ecf20Sopenharmony_ci /* 6558c2ecf20Sopenharmony_ci * Set maxtags to 0. This will be changed if we 6568c2ecf20Sopenharmony_ci * later determine that we are dealing with 6578c2ecf20Sopenharmony_ci * a tagged queuing capable device. 6588c2ecf20Sopenharmony_ci */ 6598c2ecf20Sopenharmony_ci dev->maxtags = 0; 6608c2ecf20Sopenharmony_ci 6618c2ecf20Sopenharmony_ci spi_period(starget) = 0; 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_ci return 0; 6648c2ecf20Sopenharmony_ci} 6658c2ecf20Sopenharmony_ci 6668c2ecf20Sopenharmony_cistatic int 6678c2ecf20Sopenharmony_ciahc_linux_slave_configure(struct scsi_device *sdev) 6688c2ecf20Sopenharmony_ci{ 6698c2ecf20Sopenharmony_ci if (bootverbose) 6708c2ecf20Sopenharmony_ci sdev_printk(KERN_INFO, sdev, "Slave Configure\n"); 6718c2ecf20Sopenharmony_ci 6728c2ecf20Sopenharmony_ci ahc_linux_device_queue_depth(sdev); 6738c2ecf20Sopenharmony_ci 6748c2ecf20Sopenharmony_ci /* Initial Domain Validation */ 6758c2ecf20Sopenharmony_ci if (!spi_initial_dv(sdev->sdev_target)) 6768c2ecf20Sopenharmony_ci spi_dv_device(sdev); 6778c2ecf20Sopenharmony_ci 6788c2ecf20Sopenharmony_ci return 0; 6798c2ecf20Sopenharmony_ci} 6808c2ecf20Sopenharmony_ci 6818c2ecf20Sopenharmony_ci#if defined(__i386__) 6828c2ecf20Sopenharmony_ci/* 6838c2ecf20Sopenharmony_ci * Return the disk geometry for the given SCSI device. 6848c2ecf20Sopenharmony_ci */ 6858c2ecf20Sopenharmony_cistatic int 6868c2ecf20Sopenharmony_ciahc_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev, 6878c2ecf20Sopenharmony_ci sector_t capacity, int geom[]) 6888c2ecf20Sopenharmony_ci{ 6898c2ecf20Sopenharmony_ci int heads; 6908c2ecf20Sopenharmony_ci int sectors; 6918c2ecf20Sopenharmony_ci int cylinders; 6928c2ecf20Sopenharmony_ci int extended; 6938c2ecf20Sopenharmony_ci struct ahc_softc *ahc; 6948c2ecf20Sopenharmony_ci u_int channel; 6958c2ecf20Sopenharmony_ci 6968c2ecf20Sopenharmony_ci ahc = *((struct ahc_softc **)sdev->host->hostdata); 6978c2ecf20Sopenharmony_ci channel = sdev_channel(sdev); 6988c2ecf20Sopenharmony_ci 6998c2ecf20Sopenharmony_ci if (scsi_partsize(bdev, capacity, geom)) 7008c2ecf20Sopenharmony_ci return 0; 7018c2ecf20Sopenharmony_ci 7028c2ecf20Sopenharmony_ci heads = 64; 7038c2ecf20Sopenharmony_ci sectors = 32; 7048c2ecf20Sopenharmony_ci cylinders = aic_sector_div(capacity, heads, sectors); 7058c2ecf20Sopenharmony_ci 7068c2ecf20Sopenharmony_ci if (aic7xxx_extended != 0) 7078c2ecf20Sopenharmony_ci extended = 1; 7088c2ecf20Sopenharmony_ci else if (channel == 0) 7098c2ecf20Sopenharmony_ci extended = (ahc->flags & AHC_EXTENDED_TRANS_A) != 0; 7108c2ecf20Sopenharmony_ci else 7118c2ecf20Sopenharmony_ci extended = (ahc->flags & AHC_EXTENDED_TRANS_B) != 0; 7128c2ecf20Sopenharmony_ci if (extended && cylinders >= 1024) { 7138c2ecf20Sopenharmony_ci heads = 255; 7148c2ecf20Sopenharmony_ci sectors = 63; 7158c2ecf20Sopenharmony_ci cylinders = aic_sector_div(capacity, heads, sectors); 7168c2ecf20Sopenharmony_ci } 7178c2ecf20Sopenharmony_ci geom[0] = heads; 7188c2ecf20Sopenharmony_ci geom[1] = sectors; 7198c2ecf20Sopenharmony_ci geom[2] = cylinders; 7208c2ecf20Sopenharmony_ci return (0); 7218c2ecf20Sopenharmony_ci} 7228c2ecf20Sopenharmony_ci#endif 7238c2ecf20Sopenharmony_ci 7248c2ecf20Sopenharmony_ci/* 7258c2ecf20Sopenharmony_ci * Abort the current SCSI command(s). 7268c2ecf20Sopenharmony_ci */ 7278c2ecf20Sopenharmony_cistatic int 7288c2ecf20Sopenharmony_ciahc_linux_abort(struct scsi_cmnd *cmd) 7298c2ecf20Sopenharmony_ci{ 7308c2ecf20Sopenharmony_ci int error; 7318c2ecf20Sopenharmony_ci 7328c2ecf20Sopenharmony_ci error = ahc_linux_queue_recovery_cmd(cmd, SCB_ABORT); 7338c2ecf20Sopenharmony_ci if (error != SUCCESS) 7348c2ecf20Sopenharmony_ci printk("aic7xxx_abort returns 0x%x\n", error); 7358c2ecf20Sopenharmony_ci return (error); 7368c2ecf20Sopenharmony_ci} 7378c2ecf20Sopenharmony_ci 7388c2ecf20Sopenharmony_ci/* 7398c2ecf20Sopenharmony_ci * Attempt to send a target reset message to the device that timed out. 7408c2ecf20Sopenharmony_ci */ 7418c2ecf20Sopenharmony_cistatic int 7428c2ecf20Sopenharmony_ciahc_linux_dev_reset(struct scsi_cmnd *cmd) 7438c2ecf20Sopenharmony_ci{ 7448c2ecf20Sopenharmony_ci int error; 7458c2ecf20Sopenharmony_ci 7468c2ecf20Sopenharmony_ci error = ahc_linux_queue_recovery_cmd(cmd, SCB_DEVICE_RESET); 7478c2ecf20Sopenharmony_ci if (error != SUCCESS) 7488c2ecf20Sopenharmony_ci printk("aic7xxx_dev_reset returns 0x%x\n", error); 7498c2ecf20Sopenharmony_ci return (error); 7508c2ecf20Sopenharmony_ci} 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_ci/* 7538c2ecf20Sopenharmony_ci * Reset the SCSI bus. 7548c2ecf20Sopenharmony_ci */ 7558c2ecf20Sopenharmony_cistatic int 7568c2ecf20Sopenharmony_ciahc_linux_bus_reset(struct scsi_cmnd *cmd) 7578c2ecf20Sopenharmony_ci{ 7588c2ecf20Sopenharmony_ci struct ahc_softc *ahc; 7598c2ecf20Sopenharmony_ci int found; 7608c2ecf20Sopenharmony_ci unsigned long flags; 7618c2ecf20Sopenharmony_ci 7628c2ecf20Sopenharmony_ci ahc = *(struct ahc_softc **)cmd->device->host->hostdata; 7638c2ecf20Sopenharmony_ci 7648c2ecf20Sopenharmony_ci ahc_lock(ahc, &flags); 7658c2ecf20Sopenharmony_ci found = ahc_reset_channel(ahc, scmd_channel(cmd) + 'A', 7668c2ecf20Sopenharmony_ci /*initiate reset*/TRUE); 7678c2ecf20Sopenharmony_ci ahc_unlock(ahc, &flags); 7688c2ecf20Sopenharmony_ci 7698c2ecf20Sopenharmony_ci if (bootverbose) 7708c2ecf20Sopenharmony_ci printk("%s: SCSI bus reset delivered. " 7718c2ecf20Sopenharmony_ci "%d SCBs aborted.\n", ahc_name(ahc), found); 7728c2ecf20Sopenharmony_ci 7738c2ecf20Sopenharmony_ci return SUCCESS; 7748c2ecf20Sopenharmony_ci} 7758c2ecf20Sopenharmony_ci 7768c2ecf20Sopenharmony_cistruct scsi_host_template aic7xxx_driver_template = { 7778c2ecf20Sopenharmony_ci .module = THIS_MODULE, 7788c2ecf20Sopenharmony_ci .name = "aic7xxx", 7798c2ecf20Sopenharmony_ci .proc_name = "aic7xxx", 7808c2ecf20Sopenharmony_ci .show_info = ahc_linux_show_info, 7818c2ecf20Sopenharmony_ci .write_info = ahc_proc_write_seeprom, 7828c2ecf20Sopenharmony_ci .info = ahc_linux_info, 7838c2ecf20Sopenharmony_ci .queuecommand = ahc_linux_queue, 7848c2ecf20Sopenharmony_ci .eh_abort_handler = ahc_linux_abort, 7858c2ecf20Sopenharmony_ci .eh_device_reset_handler = ahc_linux_dev_reset, 7868c2ecf20Sopenharmony_ci .eh_bus_reset_handler = ahc_linux_bus_reset, 7878c2ecf20Sopenharmony_ci#if defined(__i386__) 7888c2ecf20Sopenharmony_ci .bios_param = ahc_linux_biosparam, 7898c2ecf20Sopenharmony_ci#endif 7908c2ecf20Sopenharmony_ci .can_queue = AHC_MAX_QUEUE, 7918c2ecf20Sopenharmony_ci .this_id = -1, 7928c2ecf20Sopenharmony_ci .max_sectors = 8192, 7938c2ecf20Sopenharmony_ci .cmd_per_lun = 2, 7948c2ecf20Sopenharmony_ci .slave_alloc = ahc_linux_slave_alloc, 7958c2ecf20Sopenharmony_ci .slave_configure = ahc_linux_slave_configure, 7968c2ecf20Sopenharmony_ci .target_alloc = ahc_linux_target_alloc, 7978c2ecf20Sopenharmony_ci .target_destroy = ahc_linux_target_destroy, 7988c2ecf20Sopenharmony_ci}; 7998c2ecf20Sopenharmony_ci 8008c2ecf20Sopenharmony_ci/**************************** Tasklet Handler *********************************/ 8018c2ecf20Sopenharmony_ci 8028c2ecf20Sopenharmony_ci/******************************** Macros **************************************/ 8038c2ecf20Sopenharmony_ci#define BUILD_SCSIID(ahc, cmd) \ 8048c2ecf20Sopenharmony_ci ((((cmd)->device->id << TID_SHIFT) & TID) \ 8058c2ecf20Sopenharmony_ci | (((cmd)->device->channel == 0) ? (ahc)->our_id : (ahc)->our_id_b) \ 8068c2ecf20Sopenharmony_ci | (((cmd)->device->channel == 0) ? 0 : TWIN_CHNLB)) 8078c2ecf20Sopenharmony_ci 8088c2ecf20Sopenharmony_ci/******************************** Bus DMA *************************************/ 8098c2ecf20Sopenharmony_ciint 8108c2ecf20Sopenharmony_ciahc_dma_tag_create(struct ahc_softc *ahc, bus_dma_tag_t parent, 8118c2ecf20Sopenharmony_ci bus_size_t alignment, bus_size_t boundary, 8128c2ecf20Sopenharmony_ci dma_addr_t lowaddr, dma_addr_t highaddr, 8138c2ecf20Sopenharmony_ci bus_dma_filter_t *filter, void *filterarg, 8148c2ecf20Sopenharmony_ci bus_size_t maxsize, int nsegments, 8158c2ecf20Sopenharmony_ci bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag) 8168c2ecf20Sopenharmony_ci{ 8178c2ecf20Sopenharmony_ci bus_dma_tag_t dmat; 8188c2ecf20Sopenharmony_ci 8198c2ecf20Sopenharmony_ci dmat = kmalloc(sizeof(*dmat), GFP_ATOMIC); 8208c2ecf20Sopenharmony_ci if (dmat == NULL) 8218c2ecf20Sopenharmony_ci return (ENOMEM); 8228c2ecf20Sopenharmony_ci 8238c2ecf20Sopenharmony_ci /* 8248c2ecf20Sopenharmony_ci * Linux is very simplistic about DMA memory. For now don't 8258c2ecf20Sopenharmony_ci * maintain all specification information. Once Linux supplies 8268c2ecf20Sopenharmony_ci * better facilities for doing these operations, or the 8278c2ecf20Sopenharmony_ci * needs of this particular driver change, we might need to do 8288c2ecf20Sopenharmony_ci * more here. 8298c2ecf20Sopenharmony_ci */ 8308c2ecf20Sopenharmony_ci dmat->alignment = alignment; 8318c2ecf20Sopenharmony_ci dmat->boundary = boundary; 8328c2ecf20Sopenharmony_ci dmat->maxsize = maxsize; 8338c2ecf20Sopenharmony_ci *ret_tag = dmat; 8348c2ecf20Sopenharmony_ci return (0); 8358c2ecf20Sopenharmony_ci} 8368c2ecf20Sopenharmony_ci 8378c2ecf20Sopenharmony_civoid 8388c2ecf20Sopenharmony_ciahc_dma_tag_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat) 8398c2ecf20Sopenharmony_ci{ 8408c2ecf20Sopenharmony_ci kfree(dmat); 8418c2ecf20Sopenharmony_ci} 8428c2ecf20Sopenharmony_ci 8438c2ecf20Sopenharmony_ciint 8448c2ecf20Sopenharmony_ciahc_dmamem_alloc(struct ahc_softc *ahc, bus_dma_tag_t dmat, void** vaddr, 8458c2ecf20Sopenharmony_ci int flags, bus_dmamap_t *mapp) 8468c2ecf20Sopenharmony_ci{ 8478c2ecf20Sopenharmony_ci /* XXX: check if we really need the GFP_ATOMIC and unwind this mess! */ 8488c2ecf20Sopenharmony_ci *vaddr = dma_alloc_coherent(ahc->dev, dmat->maxsize, mapp, GFP_ATOMIC); 8498c2ecf20Sopenharmony_ci if (*vaddr == NULL) 8508c2ecf20Sopenharmony_ci return ENOMEM; 8518c2ecf20Sopenharmony_ci return 0; 8528c2ecf20Sopenharmony_ci} 8538c2ecf20Sopenharmony_ci 8548c2ecf20Sopenharmony_civoid 8558c2ecf20Sopenharmony_ciahc_dmamem_free(struct ahc_softc *ahc, bus_dma_tag_t dmat, 8568c2ecf20Sopenharmony_ci void* vaddr, bus_dmamap_t map) 8578c2ecf20Sopenharmony_ci{ 8588c2ecf20Sopenharmony_ci dma_free_coherent(ahc->dev, dmat->maxsize, vaddr, map); 8598c2ecf20Sopenharmony_ci} 8608c2ecf20Sopenharmony_ci 8618c2ecf20Sopenharmony_ciint 8628c2ecf20Sopenharmony_ciahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map, 8638c2ecf20Sopenharmony_ci void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb, 8648c2ecf20Sopenharmony_ci void *cb_arg, int flags) 8658c2ecf20Sopenharmony_ci{ 8668c2ecf20Sopenharmony_ci /* 8678c2ecf20Sopenharmony_ci * Assume for now that this will only be used during 8688c2ecf20Sopenharmony_ci * initialization and not for per-transaction buffer mapping. 8698c2ecf20Sopenharmony_ci */ 8708c2ecf20Sopenharmony_ci bus_dma_segment_t stack_sg; 8718c2ecf20Sopenharmony_ci 8728c2ecf20Sopenharmony_ci stack_sg.ds_addr = map; 8738c2ecf20Sopenharmony_ci stack_sg.ds_len = dmat->maxsize; 8748c2ecf20Sopenharmony_ci cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0); 8758c2ecf20Sopenharmony_ci return (0); 8768c2ecf20Sopenharmony_ci} 8778c2ecf20Sopenharmony_ci 8788c2ecf20Sopenharmony_civoid 8798c2ecf20Sopenharmony_ciahc_dmamap_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map) 8808c2ecf20Sopenharmony_ci{ 8818c2ecf20Sopenharmony_ci} 8828c2ecf20Sopenharmony_ci 8838c2ecf20Sopenharmony_ciint 8848c2ecf20Sopenharmony_ciahc_dmamap_unload(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map) 8858c2ecf20Sopenharmony_ci{ 8868c2ecf20Sopenharmony_ci /* Nothing to do */ 8878c2ecf20Sopenharmony_ci return (0); 8888c2ecf20Sopenharmony_ci} 8898c2ecf20Sopenharmony_ci 8908c2ecf20Sopenharmony_cistatic void 8918c2ecf20Sopenharmony_ciahc_linux_setup_tag_info_global(char *p) 8928c2ecf20Sopenharmony_ci{ 8938c2ecf20Sopenharmony_ci int tags, i, j; 8948c2ecf20Sopenharmony_ci 8958c2ecf20Sopenharmony_ci tags = simple_strtoul(p + 1, NULL, 0) & 0xff; 8968c2ecf20Sopenharmony_ci printk("Setting Global Tags= %d\n", tags); 8978c2ecf20Sopenharmony_ci 8988c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(aic7xxx_tag_info); i++) { 8998c2ecf20Sopenharmony_ci for (j = 0; j < AHC_NUM_TARGETS; j++) { 9008c2ecf20Sopenharmony_ci aic7xxx_tag_info[i].tag_commands[j] = tags; 9018c2ecf20Sopenharmony_ci } 9028c2ecf20Sopenharmony_ci } 9038c2ecf20Sopenharmony_ci} 9048c2ecf20Sopenharmony_ci 9058c2ecf20Sopenharmony_cistatic void 9068c2ecf20Sopenharmony_ciahc_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value) 9078c2ecf20Sopenharmony_ci{ 9088c2ecf20Sopenharmony_ci 9098c2ecf20Sopenharmony_ci if ((instance >= 0) && (targ >= 0) 9108c2ecf20Sopenharmony_ci && (instance < ARRAY_SIZE(aic7xxx_tag_info)) 9118c2ecf20Sopenharmony_ci && (targ < AHC_NUM_TARGETS)) { 9128c2ecf20Sopenharmony_ci aic7xxx_tag_info[instance].tag_commands[targ] = value & 0xff; 9138c2ecf20Sopenharmony_ci if (bootverbose) 9148c2ecf20Sopenharmony_ci printk("tag_info[%d:%d] = %d\n", instance, targ, value); 9158c2ecf20Sopenharmony_ci } 9168c2ecf20Sopenharmony_ci} 9178c2ecf20Sopenharmony_ci 9188c2ecf20Sopenharmony_cistatic char * 9198c2ecf20Sopenharmony_ciahc_parse_brace_option(char *opt_name, char *opt_arg, char *end, int depth, 9208c2ecf20Sopenharmony_ci void (*callback)(u_long, int, int, int32_t), 9218c2ecf20Sopenharmony_ci u_long callback_arg) 9228c2ecf20Sopenharmony_ci{ 9238c2ecf20Sopenharmony_ci char *tok_end; 9248c2ecf20Sopenharmony_ci char *tok_end2; 9258c2ecf20Sopenharmony_ci int i; 9268c2ecf20Sopenharmony_ci int instance; 9278c2ecf20Sopenharmony_ci int targ; 9288c2ecf20Sopenharmony_ci int done; 9298c2ecf20Sopenharmony_ci char tok_list[] = {'.', ',', '{', '}', '\0'}; 9308c2ecf20Sopenharmony_ci 9318c2ecf20Sopenharmony_ci /* All options use a ':' name/arg separator */ 9328c2ecf20Sopenharmony_ci if (*opt_arg != ':') 9338c2ecf20Sopenharmony_ci return (opt_arg); 9348c2ecf20Sopenharmony_ci opt_arg++; 9358c2ecf20Sopenharmony_ci instance = -1; 9368c2ecf20Sopenharmony_ci targ = -1; 9378c2ecf20Sopenharmony_ci done = FALSE; 9388c2ecf20Sopenharmony_ci /* 9398c2ecf20Sopenharmony_ci * Restore separator that may be in 9408c2ecf20Sopenharmony_ci * the middle of our option argument. 9418c2ecf20Sopenharmony_ci */ 9428c2ecf20Sopenharmony_ci tok_end = strchr(opt_arg, '\0'); 9438c2ecf20Sopenharmony_ci if (tok_end < end) 9448c2ecf20Sopenharmony_ci *tok_end = ','; 9458c2ecf20Sopenharmony_ci while (!done) { 9468c2ecf20Sopenharmony_ci switch (*opt_arg) { 9478c2ecf20Sopenharmony_ci case '{': 9488c2ecf20Sopenharmony_ci if (instance == -1) { 9498c2ecf20Sopenharmony_ci instance = 0; 9508c2ecf20Sopenharmony_ci } else { 9518c2ecf20Sopenharmony_ci if (depth > 1) { 9528c2ecf20Sopenharmony_ci if (targ == -1) 9538c2ecf20Sopenharmony_ci targ = 0; 9548c2ecf20Sopenharmony_ci } else { 9558c2ecf20Sopenharmony_ci printk("Malformed Option %s\n", 9568c2ecf20Sopenharmony_ci opt_name); 9578c2ecf20Sopenharmony_ci done = TRUE; 9588c2ecf20Sopenharmony_ci } 9598c2ecf20Sopenharmony_ci } 9608c2ecf20Sopenharmony_ci opt_arg++; 9618c2ecf20Sopenharmony_ci break; 9628c2ecf20Sopenharmony_ci case '}': 9638c2ecf20Sopenharmony_ci if (targ != -1) 9648c2ecf20Sopenharmony_ci targ = -1; 9658c2ecf20Sopenharmony_ci else if (instance != -1) 9668c2ecf20Sopenharmony_ci instance = -1; 9678c2ecf20Sopenharmony_ci opt_arg++; 9688c2ecf20Sopenharmony_ci break; 9698c2ecf20Sopenharmony_ci case ',': 9708c2ecf20Sopenharmony_ci case '.': 9718c2ecf20Sopenharmony_ci if (instance == -1) 9728c2ecf20Sopenharmony_ci done = TRUE; 9738c2ecf20Sopenharmony_ci else if (targ >= 0) 9748c2ecf20Sopenharmony_ci targ++; 9758c2ecf20Sopenharmony_ci else if (instance >= 0) 9768c2ecf20Sopenharmony_ci instance++; 9778c2ecf20Sopenharmony_ci opt_arg++; 9788c2ecf20Sopenharmony_ci break; 9798c2ecf20Sopenharmony_ci case '\0': 9808c2ecf20Sopenharmony_ci done = TRUE; 9818c2ecf20Sopenharmony_ci break; 9828c2ecf20Sopenharmony_ci default: 9838c2ecf20Sopenharmony_ci tok_end = end; 9848c2ecf20Sopenharmony_ci for (i = 0; tok_list[i]; i++) { 9858c2ecf20Sopenharmony_ci tok_end2 = strchr(opt_arg, tok_list[i]); 9868c2ecf20Sopenharmony_ci if ((tok_end2) && (tok_end2 < tok_end)) 9878c2ecf20Sopenharmony_ci tok_end = tok_end2; 9888c2ecf20Sopenharmony_ci } 9898c2ecf20Sopenharmony_ci callback(callback_arg, instance, targ, 9908c2ecf20Sopenharmony_ci simple_strtol(opt_arg, NULL, 0)); 9918c2ecf20Sopenharmony_ci opt_arg = tok_end; 9928c2ecf20Sopenharmony_ci break; 9938c2ecf20Sopenharmony_ci } 9948c2ecf20Sopenharmony_ci } 9958c2ecf20Sopenharmony_ci return (opt_arg); 9968c2ecf20Sopenharmony_ci} 9978c2ecf20Sopenharmony_ci 9988c2ecf20Sopenharmony_ci/* 9998c2ecf20Sopenharmony_ci * Handle Linux boot parameters. This routine allows for assigning a value 10008c2ecf20Sopenharmony_ci * to a parameter with a ':' between the parameter and the value. 10018c2ecf20Sopenharmony_ci * ie. aic7xxx=stpwlev:1,extended 10028c2ecf20Sopenharmony_ci */ 10038c2ecf20Sopenharmony_cistatic int 10048c2ecf20Sopenharmony_ciaic7xxx_setup(char *s) 10058c2ecf20Sopenharmony_ci{ 10068c2ecf20Sopenharmony_ci int i, n; 10078c2ecf20Sopenharmony_ci char *p; 10088c2ecf20Sopenharmony_ci char *end; 10098c2ecf20Sopenharmony_ci 10108c2ecf20Sopenharmony_ci static const struct { 10118c2ecf20Sopenharmony_ci const char *name; 10128c2ecf20Sopenharmony_ci uint32_t *flag; 10138c2ecf20Sopenharmony_ci } options[] = { 10148c2ecf20Sopenharmony_ci { "extended", &aic7xxx_extended }, 10158c2ecf20Sopenharmony_ci { "no_reset", &aic7xxx_no_reset }, 10168c2ecf20Sopenharmony_ci { "verbose", &aic7xxx_verbose }, 10178c2ecf20Sopenharmony_ci { "allow_memio", &aic7xxx_allow_memio}, 10188c2ecf20Sopenharmony_ci#ifdef AHC_DEBUG 10198c2ecf20Sopenharmony_ci { "debug", &ahc_debug }, 10208c2ecf20Sopenharmony_ci#endif 10218c2ecf20Sopenharmony_ci { "periodic_otag", &aic7xxx_periodic_otag }, 10228c2ecf20Sopenharmony_ci { "pci_parity", &aic7xxx_pci_parity }, 10238c2ecf20Sopenharmony_ci { "seltime", &aic7xxx_seltime }, 10248c2ecf20Sopenharmony_ci { "tag_info", NULL }, 10258c2ecf20Sopenharmony_ci { "global_tag_depth", NULL }, 10268c2ecf20Sopenharmony_ci { "dv", NULL } 10278c2ecf20Sopenharmony_ci }; 10288c2ecf20Sopenharmony_ci 10298c2ecf20Sopenharmony_ci end = strchr(s, '\0'); 10308c2ecf20Sopenharmony_ci 10318c2ecf20Sopenharmony_ci /* 10328c2ecf20Sopenharmony_ci * XXX ia64 gcc isn't smart enough to know that ARRAY_SIZE 10338c2ecf20Sopenharmony_ci * will never be 0 in this case. 10348c2ecf20Sopenharmony_ci */ 10358c2ecf20Sopenharmony_ci n = 0; 10368c2ecf20Sopenharmony_ci 10378c2ecf20Sopenharmony_ci while ((p = strsep(&s, ",.")) != NULL) { 10388c2ecf20Sopenharmony_ci if (*p == '\0') 10398c2ecf20Sopenharmony_ci continue; 10408c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(options); i++) { 10418c2ecf20Sopenharmony_ci 10428c2ecf20Sopenharmony_ci n = strlen(options[i].name); 10438c2ecf20Sopenharmony_ci if (strncmp(options[i].name, p, n) == 0) 10448c2ecf20Sopenharmony_ci break; 10458c2ecf20Sopenharmony_ci } 10468c2ecf20Sopenharmony_ci if (i == ARRAY_SIZE(options)) 10478c2ecf20Sopenharmony_ci continue; 10488c2ecf20Sopenharmony_ci 10498c2ecf20Sopenharmony_ci if (strncmp(p, "global_tag_depth", n) == 0) { 10508c2ecf20Sopenharmony_ci ahc_linux_setup_tag_info_global(p + n); 10518c2ecf20Sopenharmony_ci } else if (strncmp(p, "tag_info", n) == 0) { 10528c2ecf20Sopenharmony_ci s = ahc_parse_brace_option("tag_info", p + n, end, 10538c2ecf20Sopenharmony_ci 2, ahc_linux_setup_tag_info, 0); 10548c2ecf20Sopenharmony_ci } else if (p[n] == ':') { 10558c2ecf20Sopenharmony_ci *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0); 10568c2ecf20Sopenharmony_ci } else if (strncmp(p, "verbose", n) == 0) { 10578c2ecf20Sopenharmony_ci *(options[i].flag) = 1; 10588c2ecf20Sopenharmony_ci } else { 10598c2ecf20Sopenharmony_ci *(options[i].flag) ^= 0xFFFFFFFF; 10608c2ecf20Sopenharmony_ci } 10618c2ecf20Sopenharmony_ci } 10628c2ecf20Sopenharmony_ci return 1; 10638c2ecf20Sopenharmony_ci} 10648c2ecf20Sopenharmony_ci 10658c2ecf20Sopenharmony_ci__setup("aic7xxx=", aic7xxx_setup); 10668c2ecf20Sopenharmony_ci 10678c2ecf20Sopenharmony_ciuint32_t aic7xxx_verbose; 10688c2ecf20Sopenharmony_ci 10698c2ecf20Sopenharmony_ciint 10708c2ecf20Sopenharmony_ciahc_linux_register_host(struct ahc_softc *ahc, struct scsi_host_template *template) 10718c2ecf20Sopenharmony_ci{ 10728c2ecf20Sopenharmony_ci char buf[80]; 10738c2ecf20Sopenharmony_ci struct Scsi_Host *host; 10748c2ecf20Sopenharmony_ci char *new_name; 10758c2ecf20Sopenharmony_ci u_long s; 10768c2ecf20Sopenharmony_ci int retval; 10778c2ecf20Sopenharmony_ci 10788c2ecf20Sopenharmony_ci template->name = ahc->description; 10798c2ecf20Sopenharmony_ci host = scsi_host_alloc(template, sizeof(struct ahc_softc *)); 10808c2ecf20Sopenharmony_ci if (host == NULL) 10818c2ecf20Sopenharmony_ci return (ENOMEM); 10828c2ecf20Sopenharmony_ci 10838c2ecf20Sopenharmony_ci *((struct ahc_softc **)host->hostdata) = ahc; 10848c2ecf20Sopenharmony_ci ahc->platform_data->host = host; 10858c2ecf20Sopenharmony_ci host->can_queue = AHC_MAX_QUEUE; 10868c2ecf20Sopenharmony_ci host->cmd_per_lun = 2; 10878c2ecf20Sopenharmony_ci /* XXX No way to communicate the ID for multiple channels */ 10888c2ecf20Sopenharmony_ci host->this_id = ahc->our_id; 10898c2ecf20Sopenharmony_ci host->irq = ahc->platform_data->irq; 10908c2ecf20Sopenharmony_ci host->max_id = (ahc->features & AHC_WIDE) ? 16 : 8; 10918c2ecf20Sopenharmony_ci host->max_lun = AHC_NUM_LUNS; 10928c2ecf20Sopenharmony_ci host->max_channel = (ahc->features & AHC_TWIN) ? 1 : 0; 10938c2ecf20Sopenharmony_ci host->sg_tablesize = AHC_NSEG; 10948c2ecf20Sopenharmony_ci ahc_lock(ahc, &s); 10958c2ecf20Sopenharmony_ci ahc_set_unit(ahc, ahc_linux_unit++); 10968c2ecf20Sopenharmony_ci ahc_unlock(ahc, &s); 10978c2ecf20Sopenharmony_ci sprintf(buf, "scsi%d", host->host_no); 10988c2ecf20Sopenharmony_ci new_name = kmalloc(strlen(buf) + 1, GFP_ATOMIC); 10998c2ecf20Sopenharmony_ci if (new_name != NULL) { 11008c2ecf20Sopenharmony_ci strcpy(new_name, buf); 11018c2ecf20Sopenharmony_ci ahc_set_name(ahc, new_name); 11028c2ecf20Sopenharmony_ci } 11038c2ecf20Sopenharmony_ci host->unique_id = ahc->unit; 11048c2ecf20Sopenharmony_ci ahc_linux_initialize_scsi_bus(ahc); 11058c2ecf20Sopenharmony_ci ahc_intr_enable(ahc, TRUE); 11068c2ecf20Sopenharmony_ci 11078c2ecf20Sopenharmony_ci host->transportt = ahc_linux_transport_template; 11088c2ecf20Sopenharmony_ci 11098c2ecf20Sopenharmony_ci retval = scsi_add_host(host, ahc->dev); 11108c2ecf20Sopenharmony_ci if (retval) { 11118c2ecf20Sopenharmony_ci printk(KERN_WARNING "aic7xxx: scsi_add_host failed\n"); 11128c2ecf20Sopenharmony_ci scsi_host_put(host); 11138c2ecf20Sopenharmony_ci return retval; 11148c2ecf20Sopenharmony_ci } 11158c2ecf20Sopenharmony_ci 11168c2ecf20Sopenharmony_ci scsi_scan_host(host); 11178c2ecf20Sopenharmony_ci return 0; 11188c2ecf20Sopenharmony_ci} 11198c2ecf20Sopenharmony_ci 11208c2ecf20Sopenharmony_ci/* 11218c2ecf20Sopenharmony_ci * Place the SCSI bus into a known state by either resetting it, 11228c2ecf20Sopenharmony_ci * or forcing transfer negotiations on the next command to any 11238c2ecf20Sopenharmony_ci * target. 11248c2ecf20Sopenharmony_ci */ 11258c2ecf20Sopenharmony_cistatic void 11268c2ecf20Sopenharmony_ciahc_linux_initialize_scsi_bus(struct ahc_softc *ahc) 11278c2ecf20Sopenharmony_ci{ 11288c2ecf20Sopenharmony_ci int i; 11298c2ecf20Sopenharmony_ci int numtarg; 11308c2ecf20Sopenharmony_ci unsigned long s; 11318c2ecf20Sopenharmony_ci 11328c2ecf20Sopenharmony_ci i = 0; 11338c2ecf20Sopenharmony_ci numtarg = 0; 11348c2ecf20Sopenharmony_ci 11358c2ecf20Sopenharmony_ci ahc_lock(ahc, &s); 11368c2ecf20Sopenharmony_ci 11378c2ecf20Sopenharmony_ci if (aic7xxx_no_reset != 0) 11388c2ecf20Sopenharmony_ci ahc->flags &= ~(AHC_RESET_BUS_A|AHC_RESET_BUS_B); 11398c2ecf20Sopenharmony_ci 11408c2ecf20Sopenharmony_ci if ((ahc->flags & AHC_RESET_BUS_A) != 0) 11418c2ecf20Sopenharmony_ci ahc_reset_channel(ahc, 'A', /*initiate_reset*/TRUE); 11428c2ecf20Sopenharmony_ci else 11438c2ecf20Sopenharmony_ci numtarg = (ahc->features & AHC_WIDE) ? 16 : 8; 11448c2ecf20Sopenharmony_ci 11458c2ecf20Sopenharmony_ci if ((ahc->features & AHC_TWIN) != 0) { 11468c2ecf20Sopenharmony_ci 11478c2ecf20Sopenharmony_ci if ((ahc->flags & AHC_RESET_BUS_B) != 0) { 11488c2ecf20Sopenharmony_ci ahc_reset_channel(ahc, 'B', /*initiate_reset*/TRUE); 11498c2ecf20Sopenharmony_ci } else { 11508c2ecf20Sopenharmony_ci if (numtarg == 0) 11518c2ecf20Sopenharmony_ci i = 8; 11528c2ecf20Sopenharmony_ci numtarg += 8; 11538c2ecf20Sopenharmony_ci } 11548c2ecf20Sopenharmony_ci } 11558c2ecf20Sopenharmony_ci 11568c2ecf20Sopenharmony_ci /* 11578c2ecf20Sopenharmony_ci * Force negotiation to async for all targets that 11588c2ecf20Sopenharmony_ci * will not see an initial bus reset. 11598c2ecf20Sopenharmony_ci */ 11608c2ecf20Sopenharmony_ci for (; i < numtarg; i++) { 11618c2ecf20Sopenharmony_ci struct ahc_devinfo devinfo; 11628c2ecf20Sopenharmony_ci struct ahc_initiator_tinfo *tinfo; 11638c2ecf20Sopenharmony_ci struct ahc_tmode_tstate *tstate; 11648c2ecf20Sopenharmony_ci u_int our_id; 11658c2ecf20Sopenharmony_ci u_int target_id; 11668c2ecf20Sopenharmony_ci char channel; 11678c2ecf20Sopenharmony_ci 11688c2ecf20Sopenharmony_ci channel = 'A'; 11698c2ecf20Sopenharmony_ci our_id = ahc->our_id; 11708c2ecf20Sopenharmony_ci target_id = i; 11718c2ecf20Sopenharmony_ci if (i > 7 && (ahc->features & AHC_TWIN) != 0) { 11728c2ecf20Sopenharmony_ci channel = 'B'; 11738c2ecf20Sopenharmony_ci our_id = ahc->our_id_b; 11748c2ecf20Sopenharmony_ci target_id = i % 8; 11758c2ecf20Sopenharmony_ci } 11768c2ecf20Sopenharmony_ci tinfo = ahc_fetch_transinfo(ahc, channel, our_id, 11778c2ecf20Sopenharmony_ci target_id, &tstate); 11788c2ecf20Sopenharmony_ci ahc_compile_devinfo(&devinfo, our_id, target_id, 11798c2ecf20Sopenharmony_ci CAM_LUN_WILDCARD, channel, ROLE_INITIATOR); 11808c2ecf20Sopenharmony_ci ahc_update_neg_request(ahc, &devinfo, tstate, 11818c2ecf20Sopenharmony_ci tinfo, AHC_NEG_ALWAYS); 11828c2ecf20Sopenharmony_ci } 11838c2ecf20Sopenharmony_ci ahc_unlock(ahc, &s); 11848c2ecf20Sopenharmony_ci /* Give the bus some time to recover */ 11858c2ecf20Sopenharmony_ci if ((ahc->flags & (AHC_RESET_BUS_A|AHC_RESET_BUS_B)) != 0) { 11868c2ecf20Sopenharmony_ci ahc_linux_freeze_simq(ahc); 11878c2ecf20Sopenharmony_ci msleep(AIC7XXX_RESET_DELAY); 11888c2ecf20Sopenharmony_ci ahc_linux_release_simq(ahc); 11898c2ecf20Sopenharmony_ci } 11908c2ecf20Sopenharmony_ci} 11918c2ecf20Sopenharmony_ci 11928c2ecf20Sopenharmony_ciint 11938c2ecf20Sopenharmony_ciahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg) 11948c2ecf20Sopenharmony_ci{ 11958c2ecf20Sopenharmony_ci 11968c2ecf20Sopenharmony_ci ahc->platform_data = 11978c2ecf20Sopenharmony_ci kzalloc(sizeof(struct ahc_platform_data), GFP_ATOMIC); 11988c2ecf20Sopenharmony_ci if (ahc->platform_data == NULL) 11998c2ecf20Sopenharmony_ci return (ENOMEM); 12008c2ecf20Sopenharmony_ci ahc->platform_data->irq = AHC_LINUX_NOIRQ; 12018c2ecf20Sopenharmony_ci ahc_lockinit(ahc); 12028c2ecf20Sopenharmony_ci ahc->seltime = (aic7xxx_seltime & 0x3) << 4; 12038c2ecf20Sopenharmony_ci ahc->seltime_b = (aic7xxx_seltime & 0x3) << 4; 12048c2ecf20Sopenharmony_ci if (aic7xxx_pci_parity == 0) 12058c2ecf20Sopenharmony_ci ahc->flags |= AHC_DISABLE_PCI_PERR; 12068c2ecf20Sopenharmony_ci 12078c2ecf20Sopenharmony_ci return (0); 12088c2ecf20Sopenharmony_ci} 12098c2ecf20Sopenharmony_ci 12108c2ecf20Sopenharmony_civoid 12118c2ecf20Sopenharmony_ciahc_platform_free(struct ahc_softc *ahc) 12128c2ecf20Sopenharmony_ci{ 12138c2ecf20Sopenharmony_ci struct scsi_target *starget; 12148c2ecf20Sopenharmony_ci int i; 12158c2ecf20Sopenharmony_ci 12168c2ecf20Sopenharmony_ci if (ahc->platform_data != NULL) { 12178c2ecf20Sopenharmony_ci /* destroy all of the device and target objects */ 12188c2ecf20Sopenharmony_ci for (i = 0; i < AHC_NUM_TARGETS; i++) { 12198c2ecf20Sopenharmony_ci starget = ahc->platform_data->starget[i]; 12208c2ecf20Sopenharmony_ci if (starget != NULL) { 12218c2ecf20Sopenharmony_ci ahc->platform_data->starget[i] = NULL; 12228c2ecf20Sopenharmony_ci } 12238c2ecf20Sopenharmony_ci } 12248c2ecf20Sopenharmony_ci 12258c2ecf20Sopenharmony_ci if (ahc->platform_data->irq != AHC_LINUX_NOIRQ) 12268c2ecf20Sopenharmony_ci free_irq(ahc->platform_data->irq, ahc); 12278c2ecf20Sopenharmony_ci if (ahc->tag == BUS_SPACE_PIO 12288c2ecf20Sopenharmony_ci && ahc->bsh.ioport != 0) 12298c2ecf20Sopenharmony_ci release_region(ahc->bsh.ioport, 256); 12308c2ecf20Sopenharmony_ci if (ahc->tag == BUS_SPACE_MEMIO 12318c2ecf20Sopenharmony_ci && ahc->bsh.maddr != NULL) { 12328c2ecf20Sopenharmony_ci iounmap(ahc->bsh.maddr); 12338c2ecf20Sopenharmony_ci release_mem_region(ahc->platform_data->mem_busaddr, 12348c2ecf20Sopenharmony_ci 0x1000); 12358c2ecf20Sopenharmony_ci } 12368c2ecf20Sopenharmony_ci 12378c2ecf20Sopenharmony_ci if (ahc->platform_data->host) 12388c2ecf20Sopenharmony_ci scsi_host_put(ahc->platform_data->host); 12398c2ecf20Sopenharmony_ci 12408c2ecf20Sopenharmony_ci kfree(ahc->platform_data); 12418c2ecf20Sopenharmony_ci } 12428c2ecf20Sopenharmony_ci} 12438c2ecf20Sopenharmony_ci 12448c2ecf20Sopenharmony_civoid 12458c2ecf20Sopenharmony_ciahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb) 12468c2ecf20Sopenharmony_ci{ 12478c2ecf20Sopenharmony_ci ahc_platform_abort_scbs(ahc, SCB_GET_TARGET(ahc, scb), 12488c2ecf20Sopenharmony_ci SCB_GET_CHANNEL(ahc, scb), 12498c2ecf20Sopenharmony_ci SCB_GET_LUN(scb), SCB_LIST_NULL, 12508c2ecf20Sopenharmony_ci ROLE_UNKNOWN, CAM_REQUEUE_REQ); 12518c2ecf20Sopenharmony_ci} 12528c2ecf20Sopenharmony_ci 12538c2ecf20Sopenharmony_civoid 12548c2ecf20Sopenharmony_ciahc_platform_set_tags(struct ahc_softc *ahc, struct scsi_device *sdev, 12558c2ecf20Sopenharmony_ci struct ahc_devinfo *devinfo, ahc_queue_alg alg) 12568c2ecf20Sopenharmony_ci{ 12578c2ecf20Sopenharmony_ci struct ahc_linux_device *dev; 12588c2ecf20Sopenharmony_ci int was_queuing; 12598c2ecf20Sopenharmony_ci int now_queuing; 12608c2ecf20Sopenharmony_ci 12618c2ecf20Sopenharmony_ci if (sdev == NULL) 12628c2ecf20Sopenharmony_ci return; 12638c2ecf20Sopenharmony_ci dev = scsi_transport_device_data(sdev); 12648c2ecf20Sopenharmony_ci 12658c2ecf20Sopenharmony_ci was_queuing = dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED); 12668c2ecf20Sopenharmony_ci switch (alg) { 12678c2ecf20Sopenharmony_ci default: 12688c2ecf20Sopenharmony_ci case AHC_QUEUE_NONE: 12698c2ecf20Sopenharmony_ci now_queuing = 0; 12708c2ecf20Sopenharmony_ci break; 12718c2ecf20Sopenharmony_ci case AHC_QUEUE_BASIC: 12728c2ecf20Sopenharmony_ci now_queuing = AHC_DEV_Q_BASIC; 12738c2ecf20Sopenharmony_ci break; 12748c2ecf20Sopenharmony_ci case AHC_QUEUE_TAGGED: 12758c2ecf20Sopenharmony_ci now_queuing = AHC_DEV_Q_TAGGED; 12768c2ecf20Sopenharmony_ci break; 12778c2ecf20Sopenharmony_ci } 12788c2ecf20Sopenharmony_ci if ((dev->flags & AHC_DEV_FREEZE_TIL_EMPTY) == 0 12798c2ecf20Sopenharmony_ci && (was_queuing != now_queuing) 12808c2ecf20Sopenharmony_ci && (dev->active != 0)) { 12818c2ecf20Sopenharmony_ci dev->flags |= AHC_DEV_FREEZE_TIL_EMPTY; 12828c2ecf20Sopenharmony_ci dev->qfrozen++; 12838c2ecf20Sopenharmony_ci } 12848c2ecf20Sopenharmony_ci 12858c2ecf20Sopenharmony_ci dev->flags &= ~(AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED|AHC_DEV_PERIODIC_OTAG); 12868c2ecf20Sopenharmony_ci if (now_queuing) { 12878c2ecf20Sopenharmony_ci u_int usertags; 12888c2ecf20Sopenharmony_ci 12898c2ecf20Sopenharmony_ci usertags = ahc_linux_user_tagdepth(ahc, devinfo); 12908c2ecf20Sopenharmony_ci if (!was_queuing) { 12918c2ecf20Sopenharmony_ci /* 12928c2ecf20Sopenharmony_ci * Start out aggressively and allow our 12938c2ecf20Sopenharmony_ci * dynamic queue depth algorithm to take 12948c2ecf20Sopenharmony_ci * care of the rest. 12958c2ecf20Sopenharmony_ci */ 12968c2ecf20Sopenharmony_ci dev->maxtags = usertags; 12978c2ecf20Sopenharmony_ci dev->openings = dev->maxtags - dev->active; 12988c2ecf20Sopenharmony_ci } 12998c2ecf20Sopenharmony_ci if (dev->maxtags == 0) { 13008c2ecf20Sopenharmony_ci /* 13018c2ecf20Sopenharmony_ci * Queueing is disabled by the user. 13028c2ecf20Sopenharmony_ci */ 13038c2ecf20Sopenharmony_ci dev->openings = 1; 13048c2ecf20Sopenharmony_ci } else if (alg == AHC_QUEUE_TAGGED) { 13058c2ecf20Sopenharmony_ci dev->flags |= AHC_DEV_Q_TAGGED; 13068c2ecf20Sopenharmony_ci if (aic7xxx_periodic_otag != 0) 13078c2ecf20Sopenharmony_ci dev->flags |= AHC_DEV_PERIODIC_OTAG; 13088c2ecf20Sopenharmony_ci } else 13098c2ecf20Sopenharmony_ci dev->flags |= AHC_DEV_Q_BASIC; 13108c2ecf20Sopenharmony_ci } else { 13118c2ecf20Sopenharmony_ci /* We can only have one opening. */ 13128c2ecf20Sopenharmony_ci dev->maxtags = 0; 13138c2ecf20Sopenharmony_ci dev->openings = 1 - dev->active; 13148c2ecf20Sopenharmony_ci } 13158c2ecf20Sopenharmony_ci switch ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) { 13168c2ecf20Sopenharmony_ci case AHC_DEV_Q_BASIC: 13178c2ecf20Sopenharmony_ci case AHC_DEV_Q_TAGGED: 13188c2ecf20Sopenharmony_ci scsi_change_queue_depth(sdev, 13198c2ecf20Sopenharmony_ci dev->openings + dev->active); 13208c2ecf20Sopenharmony_ci break; 13218c2ecf20Sopenharmony_ci default: 13228c2ecf20Sopenharmony_ci /* 13238c2ecf20Sopenharmony_ci * We allow the OS to queue 2 untagged transactions to 13248c2ecf20Sopenharmony_ci * us at any time even though we can only execute them 13258c2ecf20Sopenharmony_ci * serially on the controller/device. This should 13268c2ecf20Sopenharmony_ci * remove some latency. 13278c2ecf20Sopenharmony_ci */ 13288c2ecf20Sopenharmony_ci scsi_change_queue_depth(sdev, 2); 13298c2ecf20Sopenharmony_ci break; 13308c2ecf20Sopenharmony_ci } 13318c2ecf20Sopenharmony_ci} 13328c2ecf20Sopenharmony_ci 13338c2ecf20Sopenharmony_ciint 13348c2ecf20Sopenharmony_ciahc_platform_abort_scbs(struct ahc_softc *ahc, int target, char channel, 13358c2ecf20Sopenharmony_ci int lun, u_int tag, role_t role, uint32_t status) 13368c2ecf20Sopenharmony_ci{ 13378c2ecf20Sopenharmony_ci return 0; 13388c2ecf20Sopenharmony_ci} 13398c2ecf20Sopenharmony_ci 13408c2ecf20Sopenharmony_cistatic u_int 13418c2ecf20Sopenharmony_ciahc_linux_user_tagdepth(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) 13428c2ecf20Sopenharmony_ci{ 13438c2ecf20Sopenharmony_ci static int warned_user; 13448c2ecf20Sopenharmony_ci u_int tags; 13458c2ecf20Sopenharmony_ci 13468c2ecf20Sopenharmony_ci tags = 0; 13478c2ecf20Sopenharmony_ci if ((ahc->user_discenable & devinfo->target_mask) != 0) { 13488c2ecf20Sopenharmony_ci if (ahc->unit >= ARRAY_SIZE(aic7xxx_tag_info)) { 13498c2ecf20Sopenharmony_ci if (warned_user == 0) { 13508c2ecf20Sopenharmony_ci 13518c2ecf20Sopenharmony_ci printk(KERN_WARNING 13528c2ecf20Sopenharmony_ci"aic7xxx: WARNING: Insufficient tag_info instances\n" 13538c2ecf20Sopenharmony_ci"aic7xxx: for installed controllers. Using defaults\n" 13548c2ecf20Sopenharmony_ci"aic7xxx: Please update the aic7xxx_tag_info array in\n" 13558c2ecf20Sopenharmony_ci"aic7xxx: the aic7xxx_osm..c source file.\n"); 13568c2ecf20Sopenharmony_ci warned_user++; 13578c2ecf20Sopenharmony_ci } 13588c2ecf20Sopenharmony_ci tags = AHC_MAX_QUEUE; 13598c2ecf20Sopenharmony_ci } else { 13608c2ecf20Sopenharmony_ci adapter_tag_info_t *tag_info; 13618c2ecf20Sopenharmony_ci 13628c2ecf20Sopenharmony_ci tag_info = &aic7xxx_tag_info[ahc->unit]; 13638c2ecf20Sopenharmony_ci tags = tag_info->tag_commands[devinfo->target_offset]; 13648c2ecf20Sopenharmony_ci if (tags > AHC_MAX_QUEUE) 13658c2ecf20Sopenharmony_ci tags = AHC_MAX_QUEUE; 13668c2ecf20Sopenharmony_ci } 13678c2ecf20Sopenharmony_ci } 13688c2ecf20Sopenharmony_ci return (tags); 13698c2ecf20Sopenharmony_ci} 13708c2ecf20Sopenharmony_ci 13718c2ecf20Sopenharmony_ci/* 13728c2ecf20Sopenharmony_ci * Determines the queue depth for a given device. 13738c2ecf20Sopenharmony_ci */ 13748c2ecf20Sopenharmony_cistatic void 13758c2ecf20Sopenharmony_ciahc_linux_device_queue_depth(struct scsi_device *sdev) 13768c2ecf20Sopenharmony_ci{ 13778c2ecf20Sopenharmony_ci struct ahc_devinfo devinfo; 13788c2ecf20Sopenharmony_ci u_int tags; 13798c2ecf20Sopenharmony_ci struct ahc_softc *ahc = *((struct ahc_softc **)sdev->host->hostdata); 13808c2ecf20Sopenharmony_ci 13818c2ecf20Sopenharmony_ci ahc_compile_devinfo(&devinfo, 13828c2ecf20Sopenharmony_ci sdev->sdev_target->channel == 0 13838c2ecf20Sopenharmony_ci ? ahc->our_id : ahc->our_id_b, 13848c2ecf20Sopenharmony_ci sdev->sdev_target->id, sdev->lun, 13858c2ecf20Sopenharmony_ci sdev->sdev_target->channel == 0 ? 'A' : 'B', 13868c2ecf20Sopenharmony_ci ROLE_INITIATOR); 13878c2ecf20Sopenharmony_ci tags = ahc_linux_user_tagdepth(ahc, &devinfo); 13888c2ecf20Sopenharmony_ci if (tags != 0 && sdev->tagged_supported != 0) { 13898c2ecf20Sopenharmony_ci 13908c2ecf20Sopenharmony_ci ahc_platform_set_tags(ahc, sdev, &devinfo, AHC_QUEUE_TAGGED); 13918c2ecf20Sopenharmony_ci ahc_send_async(ahc, devinfo.channel, devinfo.target, 13928c2ecf20Sopenharmony_ci devinfo.lun, AC_TRANSFER_NEG); 13938c2ecf20Sopenharmony_ci ahc_print_devinfo(ahc, &devinfo); 13948c2ecf20Sopenharmony_ci printk("Tagged Queuing enabled. Depth %d\n", tags); 13958c2ecf20Sopenharmony_ci } else { 13968c2ecf20Sopenharmony_ci ahc_platform_set_tags(ahc, sdev, &devinfo, AHC_QUEUE_NONE); 13978c2ecf20Sopenharmony_ci ahc_send_async(ahc, devinfo.channel, devinfo.target, 13988c2ecf20Sopenharmony_ci devinfo.lun, AC_TRANSFER_NEG); 13998c2ecf20Sopenharmony_ci } 14008c2ecf20Sopenharmony_ci} 14018c2ecf20Sopenharmony_ci 14028c2ecf20Sopenharmony_cistatic int 14038c2ecf20Sopenharmony_ciahc_linux_run_command(struct ahc_softc *ahc, struct ahc_linux_device *dev, 14048c2ecf20Sopenharmony_ci struct scsi_cmnd *cmd) 14058c2ecf20Sopenharmony_ci{ 14068c2ecf20Sopenharmony_ci struct scb *scb; 14078c2ecf20Sopenharmony_ci struct hardware_scb *hscb; 14088c2ecf20Sopenharmony_ci struct ahc_initiator_tinfo *tinfo; 14098c2ecf20Sopenharmony_ci struct ahc_tmode_tstate *tstate; 14108c2ecf20Sopenharmony_ci uint16_t mask; 14118c2ecf20Sopenharmony_ci struct scb_tailq *untagged_q = NULL; 14128c2ecf20Sopenharmony_ci int nseg; 14138c2ecf20Sopenharmony_ci 14148c2ecf20Sopenharmony_ci /* 14158c2ecf20Sopenharmony_ci * Schedule us to run later. The only reason we are not 14168c2ecf20Sopenharmony_ci * running is because the whole controller Q is frozen. 14178c2ecf20Sopenharmony_ci */ 14188c2ecf20Sopenharmony_ci if (ahc->platform_data->qfrozen != 0) 14198c2ecf20Sopenharmony_ci return SCSI_MLQUEUE_HOST_BUSY; 14208c2ecf20Sopenharmony_ci 14218c2ecf20Sopenharmony_ci /* 14228c2ecf20Sopenharmony_ci * We only allow one untagged transaction 14238c2ecf20Sopenharmony_ci * per target in the initiator role unless 14248c2ecf20Sopenharmony_ci * we are storing a full busy target *lun* 14258c2ecf20Sopenharmony_ci * table in SCB space. 14268c2ecf20Sopenharmony_ci */ 14278c2ecf20Sopenharmony_ci if (!(cmd->flags & SCMD_TAGGED) 14288c2ecf20Sopenharmony_ci && (ahc->features & AHC_SCB_BTT) == 0) { 14298c2ecf20Sopenharmony_ci int target_offset; 14308c2ecf20Sopenharmony_ci 14318c2ecf20Sopenharmony_ci target_offset = cmd->device->id + cmd->device->channel * 8; 14328c2ecf20Sopenharmony_ci untagged_q = &(ahc->untagged_queues[target_offset]); 14338c2ecf20Sopenharmony_ci if (!TAILQ_EMPTY(untagged_q)) 14348c2ecf20Sopenharmony_ci /* if we're already executing an untagged command 14358c2ecf20Sopenharmony_ci * we're busy to another */ 14368c2ecf20Sopenharmony_ci return SCSI_MLQUEUE_DEVICE_BUSY; 14378c2ecf20Sopenharmony_ci } 14388c2ecf20Sopenharmony_ci 14398c2ecf20Sopenharmony_ci nseg = scsi_dma_map(cmd); 14408c2ecf20Sopenharmony_ci if (nseg < 0) 14418c2ecf20Sopenharmony_ci return SCSI_MLQUEUE_HOST_BUSY; 14428c2ecf20Sopenharmony_ci 14438c2ecf20Sopenharmony_ci /* 14448c2ecf20Sopenharmony_ci * Get an scb to use. 14458c2ecf20Sopenharmony_ci */ 14468c2ecf20Sopenharmony_ci scb = ahc_get_scb(ahc); 14478c2ecf20Sopenharmony_ci if (!scb) { 14488c2ecf20Sopenharmony_ci scsi_dma_unmap(cmd); 14498c2ecf20Sopenharmony_ci return SCSI_MLQUEUE_HOST_BUSY; 14508c2ecf20Sopenharmony_ci } 14518c2ecf20Sopenharmony_ci 14528c2ecf20Sopenharmony_ci scb->io_ctx = cmd; 14538c2ecf20Sopenharmony_ci scb->platform_data->dev = dev; 14548c2ecf20Sopenharmony_ci hscb = scb->hscb; 14558c2ecf20Sopenharmony_ci cmd->host_scribble = (char *)scb; 14568c2ecf20Sopenharmony_ci 14578c2ecf20Sopenharmony_ci /* 14588c2ecf20Sopenharmony_ci * Fill out basics of the HSCB. 14598c2ecf20Sopenharmony_ci */ 14608c2ecf20Sopenharmony_ci hscb->control = 0; 14618c2ecf20Sopenharmony_ci hscb->scsiid = BUILD_SCSIID(ahc, cmd); 14628c2ecf20Sopenharmony_ci hscb->lun = cmd->device->lun; 14638c2ecf20Sopenharmony_ci mask = SCB_GET_TARGET_MASK(ahc, scb); 14648c2ecf20Sopenharmony_ci tinfo = ahc_fetch_transinfo(ahc, SCB_GET_CHANNEL(ahc, scb), 14658c2ecf20Sopenharmony_ci SCB_GET_OUR_ID(scb), 14668c2ecf20Sopenharmony_ci SCB_GET_TARGET(ahc, scb), &tstate); 14678c2ecf20Sopenharmony_ci hscb->scsirate = tinfo->scsirate; 14688c2ecf20Sopenharmony_ci hscb->scsioffset = tinfo->curr.offset; 14698c2ecf20Sopenharmony_ci if ((tstate->ultraenb & mask) != 0) 14708c2ecf20Sopenharmony_ci hscb->control |= ULTRAENB; 14718c2ecf20Sopenharmony_ci 14728c2ecf20Sopenharmony_ci if ((ahc->user_discenable & mask) != 0) 14738c2ecf20Sopenharmony_ci hscb->control |= DISCENB; 14748c2ecf20Sopenharmony_ci 14758c2ecf20Sopenharmony_ci if ((tstate->auto_negotiate & mask) != 0) { 14768c2ecf20Sopenharmony_ci scb->flags |= SCB_AUTO_NEGOTIATE; 14778c2ecf20Sopenharmony_ci scb->hscb->control |= MK_MESSAGE; 14788c2ecf20Sopenharmony_ci } 14798c2ecf20Sopenharmony_ci 14808c2ecf20Sopenharmony_ci if ((dev->flags & (AHC_DEV_Q_TAGGED|AHC_DEV_Q_BASIC)) != 0) { 14818c2ecf20Sopenharmony_ci if (dev->commands_since_idle_or_otag == AHC_OTAG_THRESH 14828c2ecf20Sopenharmony_ci && (dev->flags & AHC_DEV_Q_TAGGED) != 0) { 14838c2ecf20Sopenharmony_ci hscb->control |= MSG_ORDERED_TASK; 14848c2ecf20Sopenharmony_ci dev->commands_since_idle_or_otag = 0; 14858c2ecf20Sopenharmony_ci } else { 14868c2ecf20Sopenharmony_ci hscb->control |= MSG_SIMPLE_TASK; 14878c2ecf20Sopenharmony_ci } 14888c2ecf20Sopenharmony_ci } 14898c2ecf20Sopenharmony_ci 14908c2ecf20Sopenharmony_ci hscb->cdb_len = cmd->cmd_len; 14918c2ecf20Sopenharmony_ci if (hscb->cdb_len <= 12) { 14928c2ecf20Sopenharmony_ci memcpy(hscb->shared_data.cdb, cmd->cmnd, hscb->cdb_len); 14938c2ecf20Sopenharmony_ci } else { 14948c2ecf20Sopenharmony_ci memcpy(hscb->cdb32, cmd->cmnd, hscb->cdb_len); 14958c2ecf20Sopenharmony_ci scb->flags |= SCB_CDB32_PTR; 14968c2ecf20Sopenharmony_ci } 14978c2ecf20Sopenharmony_ci 14988c2ecf20Sopenharmony_ci scb->platform_data->xfer_len = 0; 14998c2ecf20Sopenharmony_ci ahc_set_residual(scb, 0); 15008c2ecf20Sopenharmony_ci ahc_set_sense_residual(scb, 0); 15018c2ecf20Sopenharmony_ci scb->sg_count = 0; 15028c2ecf20Sopenharmony_ci 15038c2ecf20Sopenharmony_ci if (nseg > 0) { 15048c2ecf20Sopenharmony_ci struct ahc_dma_seg *sg; 15058c2ecf20Sopenharmony_ci struct scatterlist *cur_seg; 15068c2ecf20Sopenharmony_ci int i; 15078c2ecf20Sopenharmony_ci 15088c2ecf20Sopenharmony_ci /* Copy the segments into the SG list. */ 15098c2ecf20Sopenharmony_ci sg = scb->sg_list; 15108c2ecf20Sopenharmony_ci /* 15118c2ecf20Sopenharmony_ci * The sg_count may be larger than nseg if 15128c2ecf20Sopenharmony_ci * a transfer crosses a 32bit page. 15138c2ecf20Sopenharmony_ci */ 15148c2ecf20Sopenharmony_ci scsi_for_each_sg(cmd, cur_seg, nseg, i) { 15158c2ecf20Sopenharmony_ci dma_addr_t addr; 15168c2ecf20Sopenharmony_ci bus_size_t len; 15178c2ecf20Sopenharmony_ci int consumed; 15188c2ecf20Sopenharmony_ci 15198c2ecf20Sopenharmony_ci addr = sg_dma_address(cur_seg); 15208c2ecf20Sopenharmony_ci len = sg_dma_len(cur_seg); 15218c2ecf20Sopenharmony_ci consumed = ahc_linux_map_seg(ahc, scb, 15228c2ecf20Sopenharmony_ci sg, addr, len); 15238c2ecf20Sopenharmony_ci sg += consumed; 15248c2ecf20Sopenharmony_ci scb->sg_count += consumed; 15258c2ecf20Sopenharmony_ci } 15268c2ecf20Sopenharmony_ci sg--; 15278c2ecf20Sopenharmony_ci sg->len |= ahc_htole32(AHC_DMA_LAST_SEG); 15288c2ecf20Sopenharmony_ci 15298c2ecf20Sopenharmony_ci /* 15308c2ecf20Sopenharmony_ci * Reset the sg list pointer. 15318c2ecf20Sopenharmony_ci */ 15328c2ecf20Sopenharmony_ci scb->hscb->sgptr = 15338c2ecf20Sopenharmony_ci ahc_htole32(scb->sg_list_phys | SG_FULL_RESID); 15348c2ecf20Sopenharmony_ci 15358c2ecf20Sopenharmony_ci /* 15368c2ecf20Sopenharmony_ci * Copy the first SG into the "current" 15378c2ecf20Sopenharmony_ci * data pointer area. 15388c2ecf20Sopenharmony_ci */ 15398c2ecf20Sopenharmony_ci scb->hscb->dataptr = scb->sg_list->addr; 15408c2ecf20Sopenharmony_ci scb->hscb->datacnt = scb->sg_list->len; 15418c2ecf20Sopenharmony_ci } else { 15428c2ecf20Sopenharmony_ci scb->hscb->sgptr = ahc_htole32(SG_LIST_NULL); 15438c2ecf20Sopenharmony_ci scb->hscb->dataptr = 0; 15448c2ecf20Sopenharmony_ci scb->hscb->datacnt = 0; 15458c2ecf20Sopenharmony_ci scb->sg_count = 0; 15468c2ecf20Sopenharmony_ci } 15478c2ecf20Sopenharmony_ci 15488c2ecf20Sopenharmony_ci LIST_INSERT_HEAD(&ahc->pending_scbs, scb, pending_links); 15498c2ecf20Sopenharmony_ci dev->openings--; 15508c2ecf20Sopenharmony_ci dev->active++; 15518c2ecf20Sopenharmony_ci dev->commands_issued++; 15528c2ecf20Sopenharmony_ci if ((dev->flags & AHC_DEV_PERIODIC_OTAG) != 0) 15538c2ecf20Sopenharmony_ci dev->commands_since_idle_or_otag++; 15548c2ecf20Sopenharmony_ci 15558c2ecf20Sopenharmony_ci scb->flags |= SCB_ACTIVE; 15568c2ecf20Sopenharmony_ci if (untagged_q) { 15578c2ecf20Sopenharmony_ci TAILQ_INSERT_TAIL(untagged_q, scb, links.tqe); 15588c2ecf20Sopenharmony_ci scb->flags |= SCB_UNTAGGEDQ; 15598c2ecf20Sopenharmony_ci } 15608c2ecf20Sopenharmony_ci ahc_queue_scb(ahc, scb); 15618c2ecf20Sopenharmony_ci return 0; 15628c2ecf20Sopenharmony_ci} 15638c2ecf20Sopenharmony_ci 15648c2ecf20Sopenharmony_ci/* 15658c2ecf20Sopenharmony_ci * SCSI controller interrupt handler. 15668c2ecf20Sopenharmony_ci */ 15678c2ecf20Sopenharmony_ciirqreturn_t 15688c2ecf20Sopenharmony_ciahc_linux_isr(int irq, void *dev_id) 15698c2ecf20Sopenharmony_ci{ 15708c2ecf20Sopenharmony_ci struct ahc_softc *ahc; 15718c2ecf20Sopenharmony_ci u_long flags; 15728c2ecf20Sopenharmony_ci int ours; 15738c2ecf20Sopenharmony_ci 15748c2ecf20Sopenharmony_ci ahc = (struct ahc_softc *) dev_id; 15758c2ecf20Sopenharmony_ci ahc_lock(ahc, &flags); 15768c2ecf20Sopenharmony_ci ours = ahc_intr(ahc); 15778c2ecf20Sopenharmony_ci ahc_unlock(ahc, &flags); 15788c2ecf20Sopenharmony_ci return IRQ_RETVAL(ours); 15798c2ecf20Sopenharmony_ci} 15808c2ecf20Sopenharmony_ci 15818c2ecf20Sopenharmony_civoid 15828c2ecf20Sopenharmony_ciahc_platform_flushwork(struct ahc_softc *ahc) 15838c2ecf20Sopenharmony_ci{ 15848c2ecf20Sopenharmony_ci 15858c2ecf20Sopenharmony_ci} 15868c2ecf20Sopenharmony_ci 15878c2ecf20Sopenharmony_civoid 15888c2ecf20Sopenharmony_ciahc_send_async(struct ahc_softc *ahc, char channel, 15898c2ecf20Sopenharmony_ci u_int target, u_int lun, ac_code code) 15908c2ecf20Sopenharmony_ci{ 15918c2ecf20Sopenharmony_ci switch (code) { 15928c2ecf20Sopenharmony_ci case AC_TRANSFER_NEG: 15938c2ecf20Sopenharmony_ci { 15948c2ecf20Sopenharmony_ci struct scsi_target *starget; 15958c2ecf20Sopenharmony_ci struct ahc_initiator_tinfo *tinfo; 15968c2ecf20Sopenharmony_ci struct ahc_tmode_tstate *tstate; 15978c2ecf20Sopenharmony_ci int target_offset; 15988c2ecf20Sopenharmony_ci unsigned int target_ppr_options; 15998c2ecf20Sopenharmony_ci 16008c2ecf20Sopenharmony_ci BUG_ON(target == CAM_TARGET_WILDCARD); 16018c2ecf20Sopenharmony_ci 16028c2ecf20Sopenharmony_ci tinfo = ahc_fetch_transinfo(ahc, channel, 16038c2ecf20Sopenharmony_ci channel == 'A' ? ahc->our_id 16048c2ecf20Sopenharmony_ci : ahc->our_id_b, 16058c2ecf20Sopenharmony_ci target, &tstate); 16068c2ecf20Sopenharmony_ci 16078c2ecf20Sopenharmony_ci /* 16088c2ecf20Sopenharmony_ci * Don't bother reporting results while 16098c2ecf20Sopenharmony_ci * negotiations are still pending. 16108c2ecf20Sopenharmony_ci */ 16118c2ecf20Sopenharmony_ci if (tinfo->curr.period != tinfo->goal.period 16128c2ecf20Sopenharmony_ci || tinfo->curr.width != tinfo->goal.width 16138c2ecf20Sopenharmony_ci || tinfo->curr.offset != tinfo->goal.offset 16148c2ecf20Sopenharmony_ci || tinfo->curr.ppr_options != tinfo->goal.ppr_options) 16158c2ecf20Sopenharmony_ci if (bootverbose == 0) 16168c2ecf20Sopenharmony_ci break; 16178c2ecf20Sopenharmony_ci 16188c2ecf20Sopenharmony_ci /* 16198c2ecf20Sopenharmony_ci * Don't bother reporting results that 16208c2ecf20Sopenharmony_ci * are identical to those last reported. 16218c2ecf20Sopenharmony_ci */ 16228c2ecf20Sopenharmony_ci target_offset = target; 16238c2ecf20Sopenharmony_ci if (channel == 'B') 16248c2ecf20Sopenharmony_ci target_offset += 8; 16258c2ecf20Sopenharmony_ci starget = ahc->platform_data->starget[target_offset]; 16268c2ecf20Sopenharmony_ci if (starget == NULL) 16278c2ecf20Sopenharmony_ci break; 16288c2ecf20Sopenharmony_ci 16298c2ecf20Sopenharmony_ci target_ppr_options = 16308c2ecf20Sopenharmony_ci (spi_dt(starget) ? MSG_EXT_PPR_DT_REQ : 0) 16318c2ecf20Sopenharmony_ci + (spi_qas(starget) ? MSG_EXT_PPR_QAS_REQ : 0) 16328c2ecf20Sopenharmony_ci + (spi_iu(starget) ? MSG_EXT_PPR_IU_REQ : 0); 16338c2ecf20Sopenharmony_ci 16348c2ecf20Sopenharmony_ci if (tinfo->curr.period == spi_period(starget) 16358c2ecf20Sopenharmony_ci && tinfo->curr.width == spi_width(starget) 16368c2ecf20Sopenharmony_ci && tinfo->curr.offset == spi_offset(starget) 16378c2ecf20Sopenharmony_ci && tinfo->curr.ppr_options == target_ppr_options) 16388c2ecf20Sopenharmony_ci if (bootverbose == 0) 16398c2ecf20Sopenharmony_ci break; 16408c2ecf20Sopenharmony_ci 16418c2ecf20Sopenharmony_ci spi_period(starget) = tinfo->curr.period; 16428c2ecf20Sopenharmony_ci spi_width(starget) = tinfo->curr.width; 16438c2ecf20Sopenharmony_ci spi_offset(starget) = tinfo->curr.offset; 16448c2ecf20Sopenharmony_ci spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ ? 1 : 0; 16458c2ecf20Sopenharmony_ci spi_qas(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_QAS_REQ ? 1 : 0; 16468c2ecf20Sopenharmony_ci spi_iu(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ ? 1 : 0; 16478c2ecf20Sopenharmony_ci spi_display_xfer_agreement(starget); 16488c2ecf20Sopenharmony_ci break; 16498c2ecf20Sopenharmony_ci } 16508c2ecf20Sopenharmony_ci case AC_SENT_BDR: 16518c2ecf20Sopenharmony_ci { 16528c2ecf20Sopenharmony_ci WARN_ON(lun != CAM_LUN_WILDCARD); 16538c2ecf20Sopenharmony_ci scsi_report_device_reset(ahc->platform_data->host, 16548c2ecf20Sopenharmony_ci channel - 'A', target); 16558c2ecf20Sopenharmony_ci break; 16568c2ecf20Sopenharmony_ci } 16578c2ecf20Sopenharmony_ci case AC_BUS_RESET: 16588c2ecf20Sopenharmony_ci if (ahc->platform_data->host != NULL) { 16598c2ecf20Sopenharmony_ci scsi_report_bus_reset(ahc->platform_data->host, 16608c2ecf20Sopenharmony_ci channel - 'A'); 16618c2ecf20Sopenharmony_ci } 16628c2ecf20Sopenharmony_ci break; 16638c2ecf20Sopenharmony_ci default: 16648c2ecf20Sopenharmony_ci panic("ahc_send_async: Unexpected async event"); 16658c2ecf20Sopenharmony_ci } 16668c2ecf20Sopenharmony_ci} 16678c2ecf20Sopenharmony_ci 16688c2ecf20Sopenharmony_ci/* 16698c2ecf20Sopenharmony_ci * Calls the higher level scsi done function and frees the scb. 16708c2ecf20Sopenharmony_ci */ 16718c2ecf20Sopenharmony_civoid 16728c2ecf20Sopenharmony_ciahc_done(struct ahc_softc *ahc, struct scb *scb) 16738c2ecf20Sopenharmony_ci{ 16748c2ecf20Sopenharmony_ci struct scsi_cmnd *cmd; 16758c2ecf20Sopenharmony_ci struct ahc_linux_device *dev; 16768c2ecf20Sopenharmony_ci 16778c2ecf20Sopenharmony_ci LIST_REMOVE(scb, pending_links); 16788c2ecf20Sopenharmony_ci if ((scb->flags & SCB_UNTAGGEDQ) != 0) { 16798c2ecf20Sopenharmony_ci struct scb_tailq *untagged_q; 16808c2ecf20Sopenharmony_ci int target_offset; 16818c2ecf20Sopenharmony_ci 16828c2ecf20Sopenharmony_ci target_offset = SCB_GET_TARGET_OFFSET(ahc, scb); 16838c2ecf20Sopenharmony_ci untagged_q = &(ahc->untagged_queues[target_offset]); 16848c2ecf20Sopenharmony_ci TAILQ_REMOVE(untagged_q, scb, links.tqe); 16858c2ecf20Sopenharmony_ci BUG_ON(!TAILQ_EMPTY(untagged_q)); 16868c2ecf20Sopenharmony_ci } else if ((scb->flags & SCB_ACTIVE) == 0) { 16878c2ecf20Sopenharmony_ci /* 16888c2ecf20Sopenharmony_ci * Transactions aborted from the untagged queue may 16898c2ecf20Sopenharmony_ci * not have been dispatched to the controller, so 16908c2ecf20Sopenharmony_ci * only check the SCB_ACTIVE flag for tagged transactions. 16918c2ecf20Sopenharmony_ci */ 16928c2ecf20Sopenharmony_ci printk("SCB %d done'd twice\n", scb->hscb->tag); 16938c2ecf20Sopenharmony_ci ahc_dump_card_state(ahc); 16948c2ecf20Sopenharmony_ci panic("Stopping for safety"); 16958c2ecf20Sopenharmony_ci } 16968c2ecf20Sopenharmony_ci cmd = scb->io_ctx; 16978c2ecf20Sopenharmony_ci dev = scb->platform_data->dev; 16988c2ecf20Sopenharmony_ci dev->active--; 16998c2ecf20Sopenharmony_ci dev->openings++; 17008c2ecf20Sopenharmony_ci if ((cmd->result & (CAM_DEV_QFRZN << 16)) != 0) { 17018c2ecf20Sopenharmony_ci cmd->result &= ~(CAM_DEV_QFRZN << 16); 17028c2ecf20Sopenharmony_ci dev->qfrozen--; 17038c2ecf20Sopenharmony_ci } 17048c2ecf20Sopenharmony_ci ahc_linux_unmap_scb(ahc, scb); 17058c2ecf20Sopenharmony_ci 17068c2ecf20Sopenharmony_ci /* 17078c2ecf20Sopenharmony_ci * Guard against stale sense data. 17088c2ecf20Sopenharmony_ci * The Linux mid-layer assumes that sense 17098c2ecf20Sopenharmony_ci * was retrieved anytime the first byte of 17108c2ecf20Sopenharmony_ci * the sense buffer looks "sane". 17118c2ecf20Sopenharmony_ci */ 17128c2ecf20Sopenharmony_ci cmd->sense_buffer[0] = 0; 17138c2ecf20Sopenharmony_ci if (ahc_get_transaction_status(scb) == CAM_REQ_INPROG) { 17148c2ecf20Sopenharmony_ci#ifdef AHC_REPORT_UNDERFLOWS 17158c2ecf20Sopenharmony_ci uint32_t amount_xferred; 17168c2ecf20Sopenharmony_ci 17178c2ecf20Sopenharmony_ci amount_xferred = 17188c2ecf20Sopenharmony_ci ahc_get_transfer_length(scb) - ahc_get_residual(scb); 17198c2ecf20Sopenharmony_ci#endif 17208c2ecf20Sopenharmony_ci if ((scb->flags & SCB_TRANSMISSION_ERROR) != 0) { 17218c2ecf20Sopenharmony_ci#ifdef AHC_DEBUG 17228c2ecf20Sopenharmony_ci if ((ahc_debug & AHC_SHOW_MISC) != 0) { 17238c2ecf20Sopenharmony_ci ahc_print_path(ahc, scb); 17248c2ecf20Sopenharmony_ci printk("Set CAM_UNCOR_PARITY\n"); 17258c2ecf20Sopenharmony_ci } 17268c2ecf20Sopenharmony_ci#endif 17278c2ecf20Sopenharmony_ci ahc_set_transaction_status(scb, CAM_UNCOR_PARITY); 17288c2ecf20Sopenharmony_ci#ifdef AHC_REPORT_UNDERFLOWS 17298c2ecf20Sopenharmony_ci /* 17308c2ecf20Sopenharmony_ci * This code is disabled by default as some 17318c2ecf20Sopenharmony_ci * clients of the SCSI system do not properly 17328c2ecf20Sopenharmony_ci * initialize the underflow parameter. This 17338c2ecf20Sopenharmony_ci * results in spurious termination of commands 17348c2ecf20Sopenharmony_ci * that complete as expected (e.g. underflow is 17358c2ecf20Sopenharmony_ci * allowed as command can return variable amounts 17368c2ecf20Sopenharmony_ci * of data. 17378c2ecf20Sopenharmony_ci */ 17388c2ecf20Sopenharmony_ci } else if (amount_xferred < scb->io_ctx->underflow) { 17398c2ecf20Sopenharmony_ci u_int i; 17408c2ecf20Sopenharmony_ci 17418c2ecf20Sopenharmony_ci ahc_print_path(ahc, scb); 17428c2ecf20Sopenharmony_ci printk("CDB:"); 17438c2ecf20Sopenharmony_ci for (i = 0; i < scb->io_ctx->cmd_len; i++) 17448c2ecf20Sopenharmony_ci printk(" 0x%x", scb->io_ctx->cmnd[i]); 17458c2ecf20Sopenharmony_ci printk("\n"); 17468c2ecf20Sopenharmony_ci ahc_print_path(ahc, scb); 17478c2ecf20Sopenharmony_ci printk("Saw underflow (%ld of %ld bytes). " 17488c2ecf20Sopenharmony_ci "Treated as error\n", 17498c2ecf20Sopenharmony_ci ahc_get_residual(scb), 17508c2ecf20Sopenharmony_ci ahc_get_transfer_length(scb)); 17518c2ecf20Sopenharmony_ci ahc_set_transaction_status(scb, CAM_DATA_RUN_ERR); 17528c2ecf20Sopenharmony_ci#endif 17538c2ecf20Sopenharmony_ci } else { 17548c2ecf20Sopenharmony_ci ahc_set_transaction_status(scb, CAM_REQ_CMP); 17558c2ecf20Sopenharmony_ci } 17568c2ecf20Sopenharmony_ci } else if (ahc_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) { 17578c2ecf20Sopenharmony_ci ahc_linux_handle_scsi_status(ahc, cmd->device, scb); 17588c2ecf20Sopenharmony_ci } 17598c2ecf20Sopenharmony_ci 17608c2ecf20Sopenharmony_ci if (dev->openings == 1 17618c2ecf20Sopenharmony_ci && ahc_get_transaction_status(scb) == CAM_REQ_CMP 17628c2ecf20Sopenharmony_ci && ahc_get_scsi_status(scb) != SCSI_STATUS_QUEUE_FULL) 17638c2ecf20Sopenharmony_ci dev->tag_success_count++; 17648c2ecf20Sopenharmony_ci /* 17658c2ecf20Sopenharmony_ci * Some devices deal with temporary internal resource 17668c2ecf20Sopenharmony_ci * shortages by returning queue full. When the queue 17678c2ecf20Sopenharmony_ci * full occurrs, we throttle back. Slowly try to get 17688c2ecf20Sopenharmony_ci * back to our previous queue depth. 17698c2ecf20Sopenharmony_ci */ 17708c2ecf20Sopenharmony_ci if ((dev->openings + dev->active) < dev->maxtags 17718c2ecf20Sopenharmony_ci && dev->tag_success_count > AHC_TAG_SUCCESS_INTERVAL) { 17728c2ecf20Sopenharmony_ci dev->tag_success_count = 0; 17738c2ecf20Sopenharmony_ci dev->openings++; 17748c2ecf20Sopenharmony_ci } 17758c2ecf20Sopenharmony_ci 17768c2ecf20Sopenharmony_ci if (dev->active == 0) 17778c2ecf20Sopenharmony_ci dev->commands_since_idle_or_otag = 0; 17788c2ecf20Sopenharmony_ci 17798c2ecf20Sopenharmony_ci if ((scb->flags & SCB_RECOVERY_SCB) != 0) { 17808c2ecf20Sopenharmony_ci printk("Recovery SCB completes\n"); 17818c2ecf20Sopenharmony_ci if (ahc_get_transaction_status(scb) == CAM_BDR_SENT 17828c2ecf20Sopenharmony_ci || ahc_get_transaction_status(scb) == CAM_REQ_ABORTED) 17838c2ecf20Sopenharmony_ci ahc_set_transaction_status(scb, CAM_CMD_TIMEOUT); 17848c2ecf20Sopenharmony_ci 17858c2ecf20Sopenharmony_ci if (ahc->platform_data->eh_done) 17868c2ecf20Sopenharmony_ci complete(ahc->platform_data->eh_done); 17878c2ecf20Sopenharmony_ci } 17888c2ecf20Sopenharmony_ci 17898c2ecf20Sopenharmony_ci ahc_free_scb(ahc, scb); 17908c2ecf20Sopenharmony_ci ahc_linux_queue_cmd_complete(ahc, cmd); 17918c2ecf20Sopenharmony_ci} 17928c2ecf20Sopenharmony_ci 17938c2ecf20Sopenharmony_cistatic void 17948c2ecf20Sopenharmony_ciahc_linux_handle_scsi_status(struct ahc_softc *ahc, 17958c2ecf20Sopenharmony_ci struct scsi_device *sdev, struct scb *scb) 17968c2ecf20Sopenharmony_ci{ 17978c2ecf20Sopenharmony_ci struct ahc_devinfo devinfo; 17988c2ecf20Sopenharmony_ci struct ahc_linux_device *dev = scsi_transport_device_data(sdev); 17998c2ecf20Sopenharmony_ci 18008c2ecf20Sopenharmony_ci ahc_compile_devinfo(&devinfo, 18018c2ecf20Sopenharmony_ci ahc->our_id, 18028c2ecf20Sopenharmony_ci sdev->sdev_target->id, sdev->lun, 18038c2ecf20Sopenharmony_ci sdev->sdev_target->channel == 0 ? 'A' : 'B', 18048c2ecf20Sopenharmony_ci ROLE_INITIATOR); 18058c2ecf20Sopenharmony_ci 18068c2ecf20Sopenharmony_ci /* 18078c2ecf20Sopenharmony_ci * We don't currently trust the mid-layer to 18088c2ecf20Sopenharmony_ci * properly deal with queue full or busy. So, 18098c2ecf20Sopenharmony_ci * when one occurs, we tell the mid-layer to 18108c2ecf20Sopenharmony_ci * unconditionally requeue the command to us 18118c2ecf20Sopenharmony_ci * so that we can retry it ourselves. We also 18128c2ecf20Sopenharmony_ci * implement our own throttling mechanism so 18138c2ecf20Sopenharmony_ci * we don't clobber the device with too many 18148c2ecf20Sopenharmony_ci * commands. 18158c2ecf20Sopenharmony_ci */ 18168c2ecf20Sopenharmony_ci switch (ahc_get_scsi_status(scb)) { 18178c2ecf20Sopenharmony_ci default: 18188c2ecf20Sopenharmony_ci break; 18198c2ecf20Sopenharmony_ci case SCSI_STATUS_CHECK_COND: 18208c2ecf20Sopenharmony_ci case SCSI_STATUS_CMD_TERMINATED: 18218c2ecf20Sopenharmony_ci { 18228c2ecf20Sopenharmony_ci struct scsi_cmnd *cmd; 18238c2ecf20Sopenharmony_ci 18248c2ecf20Sopenharmony_ci /* 18258c2ecf20Sopenharmony_ci * Copy sense information to the OS's cmd 18268c2ecf20Sopenharmony_ci * structure if it is available. 18278c2ecf20Sopenharmony_ci */ 18288c2ecf20Sopenharmony_ci cmd = scb->io_ctx; 18298c2ecf20Sopenharmony_ci if (scb->flags & SCB_SENSE) { 18308c2ecf20Sopenharmony_ci u_int sense_size; 18318c2ecf20Sopenharmony_ci 18328c2ecf20Sopenharmony_ci sense_size = min(sizeof(struct scsi_sense_data) 18338c2ecf20Sopenharmony_ci - ahc_get_sense_residual(scb), 18348c2ecf20Sopenharmony_ci (u_long)SCSI_SENSE_BUFFERSIZE); 18358c2ecf20Sopenharmony_ci memcpy(cmd->sense_buffer, 18368c2ecf20Sopenharmony_ci ahc_get_sense_buf(ahc, scb), sense_size); 18378c2ecf20Sopenharmony_ci if (sense_size < SCSI_SENSE_BUFFERSIZE) 18388c2ecf20Sopenharmony_ci memset(&cmd->sense_buffer[sense_size], 0, 18398c2ecf20Sopenharmony_ci SCSI_SENSE_BUFFERSIZE - sense_size); 18408c2ecf20Sopenharmony_ci cmd->result |= (DRIVER_SENSE << 24); 18418c2ecf20Sopenharmony_ci#ifdef AHC_DEBUG 18428c2ecf20Sopenharmony_ci if (ahc_debug & AHC_SHOW_SENSE) { 18438c2ecf20Sopenharmony_ci int i; 18448c2ecf20Sopenharmony_ci 18458c2ecf20Sopenharmony_ci printk("Copied %d bytes of sense data:", 18468c2ecf20Sopenharmony_ci sense_size); 18478c2ecf20Sopenharmony_ci for (i = 0; i < sense_size; i++) { 18488c2ecf20Sopenharmony_ci if ((i & 0xF) == 0) 18498c2ecf20Sopenharmony_ci printk("\n"); 18508c2ecf20Sopenharmony_ci printk("0x%x ", cmd->sense_buffer[i]); 18518c2ecf20Sopenharmony_ci } 18528c2ecf20Sopenharmony_ci printk("\n"); 18538c2ecf20Sopenharmony_ci } 18548c2ecf20Sopenharmony_ci#endif 18558c2ecf20Sopenharmony_ci } 18568c2ecf20Sopenharmony_ci break; 18578c2ecf20Sopenharmony_ci } 18588c2ecf20Sopenharmony_ci case SCSI_STATUS_QUEUE_FULL: 18598c2ecf20Sopenharmony_ci { 18608c2ecf20Sopenharmony_ci /* 18618c2ecf20Sopenharmony_ci * By the time the core driver has returned this 18628c2ecf20Sopenharmony_ci * command, all other commands that were queued 18638c2ecf20Sopenharmony_ci * to us but not the device have been returned. 18648c2ecf20Sopenharmony_ci * This ensures that dev->active is equal to 18658c2ecf20Sopenharmony_ci * the number of commands actually queued to 18668c2ecf20Sopenharmony_ci * the device. 18678c2ecf20Sopenharmony_ci */ 18688c2ecf20Sopenharmony_ci dev->tag_success_count = 0; 18698c2ecf20Sopenharmony_ci if (dev->active != 0) { 18708c2ecf20Sopenharmony_ci /* 18718c2ecf20Sopenharmony_ci * Drop our opening count to the number 18728c2ecf20Sopenharmony_ci * of commands currently outstanding. 18738c2ecf20Sopenharmony_ci */ 18748c2ecf20Sopenharmony_ci dev->openings = 0; 18758c2ecf20Sopenharmony_ci/* 18768c2ecf20Sopenharmony_ci ahc_print_path(ahc, scb); 18778c2ecf20Sopenharmony_ci printk("Dropping tag count to %d\n", dev->active); 18788c2ecf20Sopenharmony_ci */ 18798c2ecf20Sopenharmony_ci if (dev->active == dev->tags_on_last_queuefull) { 18808c2ecf20Sopenharmony_ci 18818c2ecf20Sopenharmony_ci dev->last_queuefull_same_count++; 18828c2ecf20Sopenharmony_ci /* 18838c2ecf20Sopenharmony_ci * If we repeatedly see a queue full 18848c2ecf20Sopenharmony_ci * at the same queue depth, this 18858c2ecf20Sopenharmony_ci * device has a fixed number of tag 18868c2ecf20Sopenharmony_ci * slots. Lock in this tag depth 18878c2ecf20Sopenharmony_ci * so we stop seeing queue fulls from 18888c2ecf20Sopenharmony_ci * this device. 18898c2ecf20Sopenharmony_ci */ 18908c2ecf20Sopenharmony_ci if (dev->last_queuefull_same_count 18918c2ecf20Sopenharmony_ci == AHC_LOCK_TAGS_COUNT) { 18928c2ecf20Sopenharmony_ci dev->maxtags = dev->active; 18938c2ecf20Sopenharmony_ci ahc_print_path(ahc, scb); 18948c2ecf20Sopenharmony_ci printk("Locking max tag count at %d\n", 18958c2ecf20Sopenharmony_ci dev->active); 18968c2ecf20Sopenharmony_ci } 18978c2ecf20Sopenharmony_ci } else { 18988c2ecf20Sopenharmony_ci dev->tags_on_last_queuefull = dev->active; 18998c2ecf20Sopenharmony_ci dev->last_queuefull_same_count = 0; 19008c2ecf20Sopenharmony_ci } 19018c2ecf20Sopenharmony_ci ahc_set_transaction_status(scb, CAM_REQUEUE_REQ); 19028c2ecf20Sopenharmony_ci ahc_set_scsi_status(scb, SCSI_STATUS_OK); 19038c2ecf20Sopenharmony_ci ahc_platform_set_tags(ahc, sdev, &devinfo, 19048c2ecf20Sopenharmony_ci (dev->flags & AHC_DEV_Q_BASIC) 19058c2ecf20Sopenharmony_ci ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED); 19068c2ecf20Sopenharmony_ci break; 19078c2ecf20Sopenharmony_ci } 19088c2ecf20Sopenharmony_ci /* 19098c2ecf20Sopenharmony_ci * Drop down to a single opening, and treat this 19108c2ecf20Sopenharmony_ci * as if the target returned BUSY SCSI status. 19118c2ecf20Sopenharmony_ci */ 19128c2ecf20Sopenharmony_ci dev->openings = 1; 19138c2ecf20Sopenharmony_ci ahc_set_scsi_status(scb, SCSI_STATUS_BUSY); 19148c2ecf20Sopenharmony_ci ahc_platform_set_tags(ahc, sdev, &devinfo, 19158c2ecf20Sopenharmony_ci (dev->flags & AHC_DEV_Q_BASIC) 19168c2ecf20Sopenharmony_ci ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED); 19178c2ecf20Sopenharmony_ci break; 19188c2ecf20Sopenharmony_ci } 19198c2ecf20Sopenharmony_ci } 19208c2ecf20Sopenharmony_ci} 19218c2ecf20Sopenharmony_ci 19228c2ecf20Sopenharmony_cistatic void 19238c2ecf20Sopenharmony_ciahc_linux_queue_cmd_complete(struct ahc_softc *ahc, struct scsi_cmnd *cmd) 19248c2ecf20Sopenharmony_ci{ 19258c2ecf20Sopenharmony_ci /* 19268c2ecf20Sopenharmony_ci * Map CAM error codes into Linux Error codes. We 19278c2ecf20Sopenharmony_ci * avoid the conversion so that the DV code has the 19288c2ecf20Sopenharmony_ci * full error information available when making 19298c2ecf20Sopenharmony_ci * state change decisions. 19308c2ecf20Sopenharmony_ci */ 19318c2ecf20Sopenharmony_ci { 19328c2ecf20Sopenharmony_ci u_int new_status; 19338c2ecf20Sopenharmony_ci 19348c2ecf20Sopenharmony_ci switch (ahc_cmd_get_transaction_status(cmd)) { 19358c2ecf20Sopenharmony_ci case CAM_REQ_INPROG: 19368c2ecf20Sopenharmony_ci case CAM_REQ_CMP: 19378c2ecf20Sopenharmony_ci case CAM_SCSI_STATUS_ERROR: 19388c2ecf20Sopenharmony_ci new_status = DID_OK; 19398c2ecf20Sopenharmony_ci break; 19408c2ecf20Sopenharmony_ci case CAM_REQ_ABORTED: 19418c2ecf20Sopenharmony_ci new_status = DID_ABORT; 19428c2ecf20Sopenharmony_ci break; 19438c2ecf20Sopenharmony_ci case CAM_BUSY: 19448c2ecf20Sopenharmony_ci new_status = DID_BUS_BUSY; 19458c2ecf20Sopenharmony_ci break; 19468c2ecf20Sopenharmony_ci case CAM_REQ_INVALID: 19478c2ecf20Sopenharmony_ci case CAM_PATH_INVALID: 19488c2ecf20Sopenharmony_ci new_status = DID_BAD_TARGET; 19498c2ecf20Sopenharmony_ci break; 19508c2ecf20Sopenharmony_ci case CAM_SEL_TIMEOUT: 19518c2ecf20Sopenharmony_ci new_status = DID_NO_CONNECT; 19528c2ecf20Sopenharmony_ci break; 19538c2ecf20Sopenharmony_ci case CAM_SCSI_BUS_RESET: 19548c2ecf20Sopenharmony_ci case CAM_BDR_SENT: 19558c2ecf20Sopenharmony_ci new_status = DID_RESET; 19568c2ecf20Sopenharmony_ci break; 19578c2ecf20Sopenharmony_ci case CAM_UNCOR_PARITY: 19588c2ecf20Sopenharmony_ci new_status = DID_PARITY; 19598c2ecf20Sopenharmony_ci break; 19608c2ecf20Sopenharmony_ci case CAM_CMD_TIMEOUT: 19618c2ecf20Sopenharmony_ci new_status = DID_TIME_OUT; 19628c2ecf20Sopenharmony_ci break; 19638c2ecf20Sopenharmony_ci case CAM_UA_ABORT: 19648c2ecf20Sopenharmony_ci case CAM_REQ_CMP_ERR: 19658c2ecf20Sopenharmony_ci case CAM_AUTOSENSE_FAIL: 19668c2ecf20Sopenharmony_ci case CAM_NO_HBA: 19678c2ecf20Sopenharmony_ci case CAM_DATA_RUN_ERR: 19688c2ecf20Sopenharmony_ci case CAM_UNEXP_BUSFREE: 19698c2ecf20Sopenharmony_ci case CAM_SEQUENCE_FAIL: 19708c2ecf20Sopenharmony_ci case CAM_CCB_LEN_ERR: 19718c2ecf20Sopenharmony_ci case CAM_PROVIDE_FAIL: 19728c2ecf20Sopenharmony_ci case CAM_REQ_TERMIO: 19738c2ecf20Sopenharmony_ci case CAM_UNREC_HBA_ERROR: 19748c2ecf20Sopenharmony_ci case CAM_REQ_TOO_BIG: 19758c2ecf20Sopenharmony_ci new_status = DID_ERROR; 19768c2ecf20Sopenharmony_ci break; 19778c2ecf20Sopenharmony_ci case CAM_REQUEUE_REQ: 19788c2ecf20Sopenharmony_ci new_status = DID_REQUEUE; 19798c2ecf20Sopenharmony_ci break; 19808c2ecf20Sopenharmony_ci default: 19818c2ecf20Sopenharmony_ci /* We should never get here */ 19828c2ecf20Sopenharmony_ci new_status = DID_ERROR; 19838c2ecf20Sopenharmony_ci break; 19848c2ecf20Sopenharmony_ci } 19858c2ecf20Sopenharmony_ci 19868c2ecf20Sopenharmony_ci ahc_cmd_set_transaction_status(cmd, new_status); 19878c2ecf20Sopenharmony_ci } 19888c2ecf20Sopenharmony_ci 19898c2ecf20Sopenharmony_ci cmd->scsi_done(cmd); 19908c2ecf20Sopenharmony_ci} 19918c2ecf20Sopenharmony_ci 19928c2ecf20Sopenharmony_cistatic void 19938c2ecf20Sopenharmony_ciahc_linux_freeze_simq(struct ahc_softc *ahc) 19948c2ecf20Sopenharmony_ci{ 19958c2ecf20Sopenharmony_ci unsigned long s; 19968c2ecf20Sopenharmony_ci 19978c2ecf20Sopenharmony_ci ahc_lock(ahc, &s); 19988c2ecf20Sopenharmony_ci ahc->platform_data->qfrozen++; 19998c2ecf20Sopenharmony_ci if (ahc->platform_data->qfrozen == 1) { 20008c2ecf20Sopenharmony_ci scsi_block_requests(ahc->platform_data->host); 20018c2ecf20Sopenharmony_ci 20028c2ecf20Sopenharmony_ci /* XXX What about Twin channels? */ 20038c2ecf20Sopenharmony_ci ahc_platform_abort_scbs(ahc, CAM_TARGET_WILDCARD, ALL_CHANNELS, 20048c2ecf20Sopenharmony_ci CAM_LUN_WILDCARD, SCB_LIST_NULL, 20058c2ecf20Sopenharmony_ci ROLE_INITIATOR, CAM_REQUEUE_REQ); 20068c2ecf20Sopenharmony_ci } 20078c2ecf20Sopenharmony_ci ahc_unlock(ahc, &s); 20088c2ecf20Sopenharmony_ci} 20098c2ecf20Sopenharmony_ci 20108c2ecf20Sopenharmony_cistatic void 20118c2ecf20Sopenharmony_ciahc_linux_release_simq(struct ahc_softc *ahc) 20128c2ecf20Sopenharmony_ci{ 20138c2ecf20Sopenharmony_ci u_long s; 20148c2ecf20Sopenharmony_ci int unblock_reqs; 20158c2ecf20Sopenharmony_ci 20168c2ecf20Sopenharmony_ci unblock_reqs = 0; 20178c2ecf20Sopenharmony_ci ahc_lock(ahc, &s); 20188c2ecf20Sopenharmony_ci if (ahc->platform_data->qfrozen > 0) 20198c2ecf20Sopenharmony_ci ahc->platform_data->qfrozen--; 20208c2ecf20Sopenharmony_ci if (ahc->platform_data->qfrozen == 0) 20218c2ecf20Sopenharmony_ci unblock_reqs = 1; 20228c2ecf20Sopenharmony_ci ahc_unlock(ahc, &s); 20238c2ecf20Sopenharmony_ci /* 20248c2ecf20Sopenharmony_ci * There is still a race here. The mid-layer 20258c2ecf20Sopenharmony_ci * should keep its own freeze count and use 20268c2ecf20Sopenharmony_ci * a bottom half handler to run the queues 20278c2ecf20Sopenharmony_ci * so we can unblock with our own lock held. 20288c2ecf20Sopenharmony_ci */ 20298c2ecf20Sopenharmony_ci if (unblock_reqs) 20308c2ecf20Sopenharmony_ci scsi_unblock_requests(ahc->platform_data->host); 20318c2ecf20Sopenharmony_ci} 20328c2ecf20Sopenharmony_ci 20338c2ecf20Sopenharmony_cistatic int 20348c2ecf20Sopenharmony_ciahc_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag) 20358c2ecf20Sopenharmony_ci{ 20368c2ecf20Sopenharmony_ci struct ahc_softc *ahc; 20378c2ecf20Sopenharmony_ci struct ahc_linux_device *dev; 20388c2ecf20Sopenharmony_ci struct scb *pending_scb; 20398c2ecf20Sopenharmony_ci u_int saved_scbptr; 20408c2ecf20Sopenharmony_ci u_int active_scb_index; 20418c2ecf20Sopenharmony_ci u_int last_phase; 20428c2ecf20Sopenharmony_ci u_int saved_scsiid; 20438c2ecf20Sopenharmony_ci u_int cdb_byte; 20448c2ecf20Sopenharmony_ci int retval; 20458c2ecf20Sopenharmony_ci int was_paused; 20468c2ecf20Sopenharmony_ci int paused; 20478c2ecf20Sopenharmony_ci int wait; 20488c2ecf20Sopenharmony_ci int disconnected; 20498c2ecf20Sopenharmony_ci unsigned long flags; 20508c2ecf20Sopenharmony_ci 20518c2ecf20Sopenharmony_ci pending_scb = NULL; 20528c2ecf20Sopenharmony_ci paused = FALSE; 20538c2ecf20Sopenharmony_ci wait = FALSE; 20548c2ecf20Sopenharmony_ci ahc = *(struct ahc_softc **)cmd->device->host->hostdata; 20558c2ecf20Sopenharmony_ci 20568c2ecf20Sopenharmony_ci scmd_printk(KERN_INFO, cmd, "Attempting to queue a%s message\n", 20578c2ecf20Sopenharmony_ci flag == SCB_ABORT ? "n ABORT" : " TARGET RESET"); 20588c2ecf20Sopenharmony_ci 20598c2ecf20Sopenharmony_ci printk("CDB:"); 20608c2ecf20Sopenharmony_ci for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++) 20618c2ecf20Sopenharmony_ci printk(" 0x%x", cmd->cmnd[cdb_byte]); 20628c2ecf20Sopenharmony_ci printk("\n"); 20638c2ecf20Sopenharmony_ci 20648c2ecf20Sopenharmony_ci ahc_lock(ahc, &flags); 20658c2ecf20Sopenharmony_ci 20668c2ecf20Sopenharmony_ci /* 20678c2ecf20Sopenharmony_ci * First determine if we currently own this command. 20688c2ecf20Sopenharmony_ci * Start by searching the device queue. If not found 20698c2ecf20Sopenharmony_ci * there, check the pending_scb list. If not found 20708c2ecf20Sopenharmony_ci * at all, and the system wanted us to just abort the 20718c2ecf20Sopenharmony_ci * command, return success. 20728c2ecf20Sopenharmony_ci */ 20738c2ecf20Sopenharmony_ci dev = scsi_transport_device_data(cmd->device); 20748c2ecf20Sopenharmony_ci 20758c2ecf20Sopenharmony_ci if (dev == NULL) { 20768c2ecf20Sopenharmony_ci /* 20778c2ecf20Sopenharmony_ci * No target device for this command exists, 20788c2ecf20Sopenharmony_ci * so we must not still own the command. 20798c2ecf20Sopenharmony_ci */ 20808c2ecf20Sopenharmony_ci printk("%s:%d:%d:%d: Is not an active device\n", 20818c2ecf20Sopenharmony_ci ahc_name(ahc), cmd->device->channel, cmd->device->id, 20828c2ecf20Sopenharmony_ci (u8)cmd->device->lun); 20838c2ecf20Sopenharmony_ci retval = SUCCESS; 20848c2ecf20Sopenharmony_ci goto no_cmd; 20858c2ecf20Sopenharmony_ci } 20868c2ecf20Sopenharmony_ci 20878c2ecf20Sopenharmony_ci if ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED)) == 0 20888c2ecf20Sopenharmony_ci && ahc_search_untagged_queues(ahc, cmd, cmd->device->id, 20898c2ecf20Sopenharmony_ci cmd->device->channel + 'A', 20908c2ecf20Sopenharmony_ci (u8)cmd->device->lun, 20918c2ecf20Sopenharmony_ci CAM_REQ_ABORTED, SEARCH_COMPLETE) != 0) { 20928c2ecf20Sopenharmony_ci printk("%s:%d:%d:%d: Command found on untagged queue\n", 20938c2ecf20Sopenharmony_ci ahc_name(ahc), cmd->device->channel, cmd->device->id, 20948c2ecf20Sopenharmony_ci (u8)cmd->device->lun); 20958c2ecf20Sopenharmony_ci retval = SUCCESS; 20968c2ecf20Sopenharmony_ci goto done; 20978c2ecf20Sopenharmony_ci } 20988c2ecf20Sopenharmony_ci 20998c2ecf20Sopenharmony_ci /* 21008c2ecf20Sopenharmony_ci * See if we can find a matching cmd in the pending list. 21018c2ecf20Sopenharmony_ci */ 21028c2ecf20Sopenharmony_ci LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) { 21038c2ecf20Sopenharmony_ci if (pending_scb->io_ctx == cmd) 21048c2ecf20Sopenharmony_ci break; 21058c2ecf20Sopenharmony_ci } 21068c2ecf20Sopenharmony_ci 21078c2ecf20Sopenharmony_ci if (pending_scb == NULL && flag == SCB_DEVICE_RESET) { 21088c2ecf20Sopenharmony_ci 21098c2ecf20Sopenharmony_ci /* Any SCB for this device will do for a target reset */ 21108c2ecf20Sopenharmony_ci LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) { 21118c2ecf20Sopenharmony_ci if (ahc_match_scb(ahc, pending_scb, scmd_id(cmd), 21128c2ecf20Sopenharmony_ci scmd_channel(cmd) + 'A', 21138c2ecf20Sopenharmony_ci CAM_LUN_WILDCARD, 21148c2ecf20Sopenharmony_ci SCB_LIST_NULL, ROLE_INITIATOR)) 21158c2ecf20Sopenharmony_ci break; 21168c2ecf20Sopenharmony_ci } 21178c2ecf20Sopenharmony_ci } 21188c2ecf20Sopenharmony_ci 21198c2ecf20Sopenharmony_ci if (pending_scb == NULL) { 21208c2ecf20Sopenharmony_ci scmd_printk(KERN_INFO, cmd, "Command not found\n"); 21218c2ecf20Sopenharmony_ci goto no_cmd; 21228c2ecf20Sopenharmony_ci } 21238c2ecf20Sopenharmony_ci 21248c2ecf20Sopenharmony_ci if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) { 21258c2ecf20Sopenharmony_ci /* 21268c2ecf20Sopenharmony_ci * We can't queue two recovery actions using the same SCB 21278c2ecf20Sopenharmony_ci */ 21288c2ecf20Sopenharmony_ci retval = FAILED; 21298c2ecf20Sopenharmony_ci goto done; 21308c2ecf20Sopenharmony_ci } 21318c2ecf20Sopenharmony_ci 21328c2ecf20Sopenharmony_ci /* 21338c2ecf20Sopenharmony_ci * Ensure that the card doesn't do anything 21348c2ecf20Sopenharmony_ci * behind our back and that we didn't "just" miss 21358c2ecf20Sopenharmony_ci * an interrupt that would affect this cmd. 21368c2ecf20Sopenharmony_ci */ 21378c2ecf20Sopenharmony_ci was_paused = ahc_is_paused(ahc); 21388c2ecf20Sopenharmony_ci ahc_pause_and_flushwork(ahc); 21398c2ecf20Sopenharmony_ci paused = TRUE; 21408c2ecf20Sopenharmony_ci 21418c2ecf20Sopenharmony_ci if ((pending_scb->flags & SCB_ACTIVE) == 0) { 21428c2ecf20Sopenharmony_ci scmd_printk(KERN_INFO, cmd, "Command already completed\n"); 21438c2ecf20Sopenharmony_ci goto no_cmd; 21448c2ecf20Sopenharmony_ci } 21458c2ecf20Sopenharmony_ci 21468c2ecf20Sopenharmony_ci printk("%s: At time of recovery, card was %spaused\n", 21478c2ecf20Sopenharmony_ci ahc_name(ahc), was_paused ? "" : "not "); 21488c2ecf20Sopenharmony_ci ahc_dump_card_state(ahc); 21498c2ecf20Sopenharmony_ci 21508c2ecf20Sopenharmony_ci disconnected = TRUE; 21518c2ecf20Sopenharmony_ci if (flag == SCB_ABORT) { 21528c2ecf20Sopenharmony_ci if (ahc_search_qinfifo(ahc, cmd->device->id, 21538c2ecf20Sopenharmony_ci cmd->device->channel + 'A', 21548c2ecf20Sopenharmony_ci cmd->device->lun, 21558c2ecf20Sopenharmony_ci pending_scb->hscb->tag, 21568c2ecf20Sopenharmony_ci ROLE_INITIATOR, CAM_REQ_ABORTED, 21578c2ecf20Sopenharmony_ci SEARCH_COMPLETE) > 0) { 21588c2ecf20Sopenharmony_ci printk("%s:%d:%d:%d: Cmd aborted from QINFIFO\n", 21598c2ecf20Sopenharmony_ci ahc_name(ahc), cmd->device->channel, 21608c2ecf20Sopenharmony_ci cmd->device->id, (u8)cmd->device->lun); 21618c2ecf20Sopenharmony_ci retval = SUCCESS; 21628c2ecf20Sopenharmony_ci goto done; 21638c2ecf20Sopenharmony_ci } 21648c2ecf20Sopenharmony_ci } else if (ahc_search_qinfifo(ahc, cmd->device->id, 21658c2ecf20Sopenharmony_ci cmd->device->channel + 'A', 21668c2ecf20Sopenharmony_ci cmd->device->lun, 21678c2ecf20Sopenharmony_ci pending_scb->hscb->tag, 21688c2ecf20Sopenharmony_ci ROLE_INITIATOR, /*status*/0, 21698c2ecf20Sopenharmony_ci SEARCH_COUNT) > 0) { 21708c2ecf20Sopenharmony_ci disconnected = FALSE; 21718c2ecf20Sopenharmony_ci } 21728c2ecf20Sopenharmony_ci 21738c2ecf20Sopenharmony_ci if (disconnected && (ahc_inb(ahc, SEQ_FLAGS) & NOT_IDENTIFIED) == 0) { 21748c2ecf20Sopenharmony_ci struct scb *bus_scb; 21758c2ecf20Sopenharmony_ci 21768c2ecf20Sopenharmony_ci bus_scb = ahc_lookup_scb(ahc, ahc_inb(ahc, SCB_TAG)); 21778c2ecf20Sopenharmony_ci if (bus_scb == pending_scb) 21788c2ecf20Sopenharmony_ci disconnected = FALSE; 21798c2ecf20Sopenharmony_ci else if (flag != SCB_ABORT 21808c2ecf20Sopenharmony_ci && ahc_inb(ahc, SAVED_SCSIID) == pending_scb->hscb->scsiid 21818c2ecf20Sopenharmony_ci && ahc_inb(ahc, SAVED_LUN) == SCB_GET_LUN(pending_scb)) 21828c2ecf20Sopenharmony_ci disconnected = FALSE; 21838c2ecf20Sopenharmony_ci } 21848c2ecf20Sopenharmony_ci 21858c2ecf20Sopenharmony_ci /* 21868c2ecf20Sopenharmony_ci * At this point, pending_scb is the scb associated with the 21878c2ecf20Sopenharmony_ci * passed in command. That command is currently active on the 21888c2ecf20Sopenharmony_ci * bus, is in the disconnected state, or we're hoping to find 21898c2ecf20Sopenharmony_ci * a command for the same target active on the bus to abuse to 21908c2ecf20Sopenharmony_ci * send a BDR. Queue the appropriate message based on which of 21918c2ecf20Sopenharmony_ci * these states we are in. 21928c2ecf20Sopenharmony_ci */ 21938c2ecf20Sopenharmony_ci last_phase = ahc_inb(ahc, LASTPHASE); 21948c2ecf20Sopenharmony_ci saved_scbptr = ahc_inb(ahc, SCBPTR); 21958c2ecf20Sopenharmony_ci active_scb_index = ahc_inb(ahc, SCB_TAG); 21968c2ecf20Sopenharmony_ci saved_scsiid = ahc_inb(ahc, SAVED_SCSIID); 21978c2ecf20Sopenharmony_ci if (last_phase != P_BUSFREE 21988c2ecf20Sopenharmony_ci && (pending_scb->hscb->tag == active_scb_index 21998c2ecf20Sopenharmony_ci || (flag == SCB_DEVICE_RESET 22008c2ecf20Sopenharmony_ci && SCSIID_TARGET(ahc, saved_scsiid) == scmd_id(cmd)))) { 22018c2ecf20Sopenharmony_ci 22028c2ecf20Sopenharmony_ci /* 22038c2ecf20Sopenharmony_ci * We're active on the bus, so assert ATN 22048c2ecf20Sopenharmony_ci * and hope that the target responds. 22058c2ecf20Sopenharmony_ci */ 22068c2ecf20Sopenharmony_ci pending_scb = ahc_lookup_scb(ahc, active_scb_index); 22078c2ecf20Sopenharmony_ci pending_scb->flags |= SCB_RECOVERY_SCB|flag; 22088c2ecf20Sopenharmony_ci ahc_outb(ahc, MSG_OUT, HOST_MSG); 22098c2ecf20Sopenharmony_ci ahc_outb(ahc, SCSISIGO, last_phase|ATNO); 22108c2ecf20Sopenharmony_ci scmd_printk(KERN_INFO, cmd, "Device is active, asserting ATN\n"); 22118c2ecf20Sopenharmony_ci wait = TRUE; 22128c2ecf20Sopenharmony_ci } else if (disconnected) { 22138c2ecf20Sopenharmony_ci 22148c2ecf20Sopenharmony_ci /* 22158c2ecf20Sopenharmony_ci * Actually re-queue this SCB in an attempt 22168c2ecf20Sopenharmony_ci * to select the device before it reconnects. 22178c2ecf20Sopenharmony_ci * In either case (selection or reselection), 22188c2ecf20Sopenharmony_ci * we will now issue the approprate message 22198c2ecf20Sopenharmony_ci * to the timed-out device. 22208c2ecf20Sopenharmony_ci * 22218c2ecf20Sopenharmony_ci * Set the MK_MESSAGE control bit indicating 22228c2ecf20Sopenharmony_ci * that we desire to send a message. We 22238c2ecf20Sopenharmony_ci * also set the disconnected flag since 22248c2ecf20Sopenharmony_ci * in the paging case there is no guarantee 22258c2ecf20Sopenharmony_ci * that our SCB control byte matches the 22268c2ecf20Sopenharmony_ci * version on the card. We don't want the 22278c2ecf20Sopenharmony_ci * sequencer to abort the command thinking 22288c2ecf20Sopenharmony_ci * an unsolicited reselection occurred. 22298c2ecf20Sopenharmony_ci */ 22308c2ecf20Sopenharmony_ci pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED; 22318c2ecf20Sopenharmony_ci pending_scb->flags |= SCB_RECOVERY_SCB|flag; 22328c2ecf20Sopenharmony_ci 22338c2ecf20Sopenharmony_ci /* 22348c2ecf20Sopenharmony_ci * Remove any cached copy of this SCB in the 22358c2ecf20Sopenharmony_ci * disconnected list in preparation for the 22368c2ecf20Sopenharmony_ci * queuing of our abort SCB. We use the 22378c2ecf20Sopenharmony_ci * same element in the SCB, SCB_NEXT, for 22388c2ecf20Sopenharmony_ci * both the qinfifo and the disconnected list. 22398c2ecf20Sopenharmony_ci */ 22408c2ecf20Sopenharmony_ci ahc_search_disc_list(ahc, cmd->device->id, 22418c2ecf20Sopenharmony_ci cmd->device->channel + 'A', 22428c2ecf20Sopenharmony_ci cmd->device->lun, pending_scb->hscb->tag, 22438c2ecf20Sopenharmony_ci /*stop_on_first*/TRUE, 22448c2ecf20Sopenharmony_ci /*remove*/TRUE, 22458c2ecf20Sopenharmony_ci /*save_state*/FALSE); 22468c2ecf20Sopenharmony_ci 22478c2ecf20Sopenharmony_ci /* 22488c2ecf20Sopenharmony_ci * In the non-paging case, the sequencer will 22498c2ecf20Sopenharmony_ci * never re-reference the in-core SCB. 22508c2ecf20Sopenharmony_ci * To make sure we are notified during 22518c2ecf20Sopenharmony_ci * reselection, set the MK_MESSAGE flag in 22528c2ecf20Sopenharmony_ci * the card's copy of the SCB. 22538c2ecf20Sopenharmony_ci */ 22548c2ecf20Sopenharmony_ci if ((ahc->flags & AHC_PAGESCBS) == 0) { 22558c2ecf20Sopenharmony_ci ahc_outb(ahc, SCBPTR, pending_scb->hscb->tag); 22568c2ecf20Sopenharmony_ci ahc_outb(ahc, SCB_CONTROL, 22578c2ecf20Sopenharmony_ci ahc_inb(ahc, SCB_CONTROL)|MK_MESSAGE); 22588c2ecf20Sopenharmony_ci } 22598c2ecf20Sopenharmony_ci 22608c2ecf20Sopenharmony_ci /* 22618c2ecf20Sopenharmony_ci * Clear out any entries in the QINFIFO first 22628c2ecf20Sopenharmony_ci * so we are the next SCB for this target 22638c2ecf20Sopenharmony_ci * to run. 22648c2ecf20Sopenharmony_ci */ 22658c2ecf20Sopenharmony_ci ahc_search_qinfifo(ahc, cmd->device->id, 22668c2ecf20Sopenharmony_ci cmd->device->channel + 'A', 22678c2ecf20Sopenharmony_ci cmd->device->lun, SCB_LIST_NULL, 22688c2ecf20Sopenharmony_ci ROLE_INITIATOR, CAM_REQUEUE_REQ, 22698c2ecf20Sopenharmony_ci SEARCH_COMPLETE); 22708c2ecf20Sopenharmony_ci ahc_qinfifo_requeue_tail(ahc, pending_scb); 22718c2ecf20Sopenharmony_ci ahc_outb(ahc, SCBPTR, saved_scbptr); 22728c2ecf20Sopenharmony_ci ahc_print_path(ahc, pending_scb); 22738c2ecf20Sopenharmony_ci printk("Device is disconnected, re-queuing SCB\n"); 22748c2ecf20Sopenharmony_ci wait = TRUE; 22758c2ecf20Sopenharmony_ci } else { 22768c2ecf20Sopenharmony_ci scmd_printk(KERN_INFO, cmd, "Unable to deliver message\n"); 22778c2ecf20Sopenharmony_ci retval = FAILED; 22788c2ecf20Sopenharmony_ci goto done; 22798c2ecf20Sopenharmony_ci } 22808c2ecf20Sopenharmony_ci 22818c2ecf20Sopenharmony_cino_cmd: 22828c2ecf20Sopenharmony_ci /* 22838c2ecf20Sopenharmony_ci * Our assumption is that if we don't have the command, no 22848c2ecf20Sopenharmony_ci * recovery action was required, so we return success. Again, 22858c2ecf20Sopenharmony_ci * the semantics of the mid-layer recovery engine are not 22868c2ecf20Sopenharmony_ci * well defined, so this may change in time. 22878c2ecf20Sopenharmony_ci */ 22888c2ecf20Sopenharmony_ci retval = SUCCESS; 22898c2ecf20Sopenharmony_cidone: 22908c2ecf20Sopenharmony_ci if (paused) 22918c2ecf20Sopenharmony_ci ahc_unpause(ahc); 22928c2ecf20Sopenharmony_ci if (wait) { 22938c2ecf20Sopenharmony_ci DECLARE_COMPLETION_ONSTACK(done); 22948c2ecf20Sopenharmony_ci 22958c2ecf20Sopenharmony_ci ahc->platform_data->eh_done = &done; 22968c2ecf20Sopenharmony_ci ahc_unlock(ahc, &flags); 22978c2ecf20Sopenharmony_ci 22988c2ecf20Sopenharmony_ci printk("Recovery code sleeping\n"); 22998c2ecf20Sopenharmony_ci if (!wait_for_completion_timeout(&done, 5 * HZ)) { 23008c2ecf20Sopenharmony_ci ahc_lock(ahc, &flags); 23018c2ecf20Sopenharmony_ci ahc->platform_data->eh_done = NULL; 23028c2ecf20Sopenharmony_ci ahc_unlock(ahc, &flags); 23038c2ecf20Sopenharmony_ci 23048c2ecf20Sopenharmony_ci printk("Timer Expired\n"); 23058c2ecf20Sopenharmony_ci retval = FAILED; 23068c2ecf20Sopenharmony_ci } 23078c2ecf20Sopenharmony_ci printk("Recovery code awake\n"); 23088c2ecf20Sopenharmony_ci } else 23098c2ecf20Sopenharmony_ci ahc_unlock(ahc, &flags); 23108c2ecf20Sopenharmony_ci return (retval); 23118c2ecf20Sopenharmony_ci} 23128c2ecf20Sopenharmony_ci 23138c2ecf20Sopenharmony_cistatic void ahc_linux_set_width(struct scsi_target *starget, int width) 23148c2ecf20Sopenharmony_ci{ 23158c2ecf20Sopenharmony_ci struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 23168c2ecf20Sopenharmony_ci struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata); 23178c2ecf20Sopenharmony_ci struct ahc_devinfo devinfo; 23188c2ecf20Sopenharmony_ci unsigned long flags; 23198c2ecf20Sopenharmony_ci 23208c2ecf20Sopenharmony_ci ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, 23218c2ecf20Sopenharmony_ci starget->channel + 'A', ROLE_INITIATOR); 23228c2ecf20Sopenharmony_ci ahc_lock(ahc, &flags); 23238c2ecf20Sopenharmony_ci ahc_set_width(ahc, &devinfo, width, AHC_TRANS_GOAL, FALSE); 23248c2ecf20Sopenharmony_ci ahc_unlock(ahc, &flags); 23258c2ecf20Sopenharmony_ci} 23268c2ecf20Sopenharmony_ci 23278c2ecf20Sopenharmony_cistatic void ahc_linux_set_period(struct scsi_target *starget, int period) 23288c2ecf20Sopenharmony_ci{ 23298c2ecf20Sopenharmony_ci struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 23308c2ecf20Sopenharmony_ci struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata); 23318c2ecf20Sopenharmony_ci struct ahc_tmode_tstate *tstate; 23328c2ecf20Sopenharmony_ci struct ahc_initiator_tinfo *tinfo 23338c2ecf20Sopenharmony_ci = ahc_fetch_transinfo(ahc, 23348c2ecf20Sopenharmony_ci starget->channel + 'A', 23358c2ecf20Sopenharmony_ci shost->this_id, starget->id, &tstate); 23368c2ecf20Sopenharmony_ci struct ahc_devinfo devinfo; 23378c2ecf20Sopenharmony_ci unsigned int ppr_options = tinfo->goal.ppr_options; 23388c2ecf20Sopenharmony_ci unsigned long flags; 23398c2ecf20Sopenharmony_ci unsigned long offset = tinfo->goal.offset; 23408c2ecf20Sopenharmony_ci const struct ahc_syncrate *syncrate; 23418c2ecf20Sopenharmony_ci 23428c2ecf20Sopenharmony_ci if (offset == 0) 23438c2ecf20Sopenharmony_ci offset = MAX_OFFSET; 23448c2ecf20Sopenharmony_ci 23458c2ecf20Sopenharmony_ci if (period < 9) 23468c2ecf20Sopenharmony_ci period = 9; /* 12.5ns is our minimum */ 23478c2ecf20Sopenharmony_ci if (period == 9) { 23488c2ecf20Sopenharmony_ci if (spi_max_width(starget)) 23498c2ecf20Sopenharmony_ci ppr_options |= MSG_EXT_PPR_DT_REQ; 23508c2ecf20Sopenharmony_ci else 23518c2ecf20Sopenharmony_ci /* need wide for DT and need DT for 12.5 ns */ 23528c2ecf20Sopenharmony_ci period = 10; 23538c2ecf20Sopenharmony_ci } 23548c2ecf20Sopenharmony_ci 23558c2ecf20Sopenharmony_ci ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, 23568c2ecf20Sopenharmony_ci starget->channel + 'A', ROLE_INITIATOR); 23578c2ecf20Sopenharmony_ci 23588c2ecf20Sopenharmony_ci /* all PPR requests apart from QAS require wide transfers */ 23598c2ecf20Sopenharmony_ci if (ppr_options & ~MSG_EXT_PPR_QAS_REQ) { 23608c2ecf20Sopenharmony_ci if (spi_width(starget) == 0) 23618c2ecf20Sopenharmony_ci ppr_options &= MSG_EXT_PPR_QAS_REQ; 23628c2ecf20Sopenharmony_ci } 23638c2ecf20Sopenharmony_ci 23648c2ecf20Sopenharmony_ci syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT); 23658c2ecf20Sopenharmony_ci ahc_lock(ahc, &flags); 23668c2ecf20Sopenharmony_ci ahc_set_syncrate(ahc, &devinfo, syncrate, period, offset, 23678c2ecf20Sopenharmony_ci ppr_options, AHC_TRANS_GOAL, FALSE); 23688c2ecf20Sopenharmony_ci ahc_unlock(ahc, &flags); 23698c2ecf20Sopenharmony_ci} 23708c2ecf20Sopenharmony_ci 23718c2ecf20Sopenharmony_cistatic void ahc_linux_set_offset(struct scsi_target *starget, int offset) 23728c2ecf20Sopenharmony_ci{ 23738c2ecf20Sopenharmony_ci struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 23748c2ecf20Sopenharmony_ci struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata); 23758c2ecf20Sopenharmony_ci struct ahc_tmode_tstate *tstate; 23768c2ecf20Sopenharmony_ci struct ahc_initiator_tinfo *tinfo 23778c2ecf20Sopenharmony_ci = ahc_fetch_transinfo(ahc, 23788c2ecf20Sopenharmony_ci starget->channel + 'A', 23798c2ecf20Sopenharmony_ci shost->this_id, starget->id, &tstate); 23808c2ecf20Sopenharmony_ci struct ahc_devinfo devinfo; 23818c2ecf20Sopenharmony_ci unsigned int ppr_options = 0; 23828c2ecf20Sopenharmony_ci unsigned int period = 0; 23838c2ecf20Sopenharmony_ci unsigned long flags; 23848c2ecf20Sopenharmony_ci const struct ahc_syncrate *syncrate = NULL; 23858c2ecf20Sopenharmony_ci 23868c2ecf20Sopenharmony_ci ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, 23878c2ecf20Sopenharmony_ci starget->channel + 'A', ROLE_INITIATOR); 23888c2ecf20Sopenharmony_ci if (offset != 0) { 23898c2ecf20Sopenharmony_ci syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT); 23908c2ecf20Sopenharmony_ci period = tinfo->goal.period; 23918c2ecf20Sopenharmony_ci ppr_options = tinfo->goal.ppr_options; 23928c2ecf20Sopenharmony_ci } 23938c2ecf20Sopenharmony_ci ahc_lock(ahc, &flags); 23948c2ecf20Sopenharmony_ci ahc_set_syncrate(ahc, &devinfo, syncrate, period, offset, 23958c2ecf20Sopenharmony_ci ppr_options, AHC_TRANS_GOAL, FALSE); 23968c2ecf20Sopenharmony_ci ahc_unlock(ahc, &flags); 23978c2ecf20Sopenharmony_ci} 23988c2ecf20Sopenharmony_ci 23998c2ecf20Sopenharmony_cistatic void ahc_linux_set_dt(struct scsi_target *starget, int dt) 24008c2ecf20Sopenharmony_ci{ 24018c2ecf20Sopenharmony_ci struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 24028c2ecf20Sopenharmony_ci struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata); 24038c2ecf20Sopenharmony_ci struct ahc_tmode_tstate *tstate; 24048c2ecf20Sopenharmony_ci struct ahc_initiator_tinfo *tinfo 24058c2ecf20Sopenharmony_ci = ahc_fetch_transinfo(ahc, 24068c2ecf20Sopenharmony_ci starget->channel + 'A', 24078c2ecf20Sopenharmony_ci shost->this_id, starget->id, &tstate); 24088c2ecf20Sopenharmony_ci struct ahc_devinfo devinfo; 24098c2ecf20Sopenharmony_ci unsigned int ppr_options = tinfo->goal.ppr_options 24108c2ecf20Sopenharmony_ci & ~MSG_EXT_PPR_DT_REQ; 24118c2ecf20Sopenharmony_ci unsigned int period = tinfo->goal.period; 24128c2ecf20Sopenharmony_ci unsigned int width = tinfo->goal.width; 24138c2ecf20Sopenharmony_ci unsigned long flags; 24148c2ecf20Sopenharmony_ci const struct ahc_syncrate *syncrate; 24158c2ecf20Sopenharmony_ci 24168c2ecf20Sopenharmony_ci if (dt && spi_max_width(starget)) { 24178c2ecf20Sopenharmony_ci ppr_options |= MSG_EXT_PPR_DT_REQ; 24188c2ecf20Sopenharmony_ci if (!width) 24198c2ecf20Sopenharmony_ci ahc_linux_set_width(starget, 1); 24208c2ecf20Sopenharmony_ci } else if (period == 9) 24218c2ecf20Sopenharmony_ci period = 10; /* if resetting DT, period must be >= 25ns */ 24228c2ecf20Sopenharmony_ci 24238c2ecf20Sopenharmony_ci ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, 24248c2ecf20Sopenharmony_ci starget->channel + 'A', ROLE_INITIATOR); 24258c2ecf20Sopenharmony_ci syncrate = ahc_find_syncrate(ahc, &period, &ppr_options,AHC_SYNCRATE_DT); 24268c2ecf20Sopenharmony_ci ahc_lock(ahc, &flags); 24278c2ecf20Sopenharmony_ci ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->goal.offset, 24288c2ecf20Sopenharmony_ci ppr_options, AHC_TRANS_GOAL, FALSE); 24298c2ecf20Sopenharmony_ci ahc_unlock(ahc, &flags); 24308c2ecf20Sopenharmony_ci} 24318c2ecf20Sopenharmony_ci 24328c2ecf20Sopenharmony_ci#if 0 24338c2ecf20Sopenharmony_ci/* FIXME: This code claims to support IU and QAS. However, the actual 24348c2ecf20Sopenharmony_ci * sequencer code and aic7xxx_core have no support for these parameters and 24358c2ecf20Sopenharmony_ci * will get into a bad state if they're negotiated. Do not enable this 24368c2ecf20Sopenharmony_ci * unless you know what you're doing */ 24378c2ecf20Sopenharmony_cistatic void ahc_linux_set_qas(struct scsi_target *starget, int qas) 24388c2ecf20Sopenharmony_ci{ 24398c2ecf20Sopenharmony_ci struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 24408c2ecf20Sopenharmony_ci struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata); 24418c2ecf20Sopenharmony_ci struct ahc_tmode_tstate *tstate; 24428c2ecf20Sopenharmony_ci struct ahc_initiator_tinfo *tinfo 24438c2ecf20Sopenharmony_ci = ahc_fetch_transinfo(ahc, 24448c2ecf20Sopenharmony_ci starget->channel + 'A', 24458c2ecf20Sopenharmony_ci shost->this_id, starget->id, &tstate); 24468c2ecf20Sopenharmony_ci struct ahc_devinfo devinfo; 24478c2ecf20Sopenharmony_ci unsigned int ppr_options = tinfo->goal.ppr_options 24488c2ecf20Sopenharmony_ci & ~MSG_EXT_PPR_QAS_REQ; 24498c2ecf20Sopenharmony_ci unsigned int period = tinfo->goal.period; 24508c2ecf20Sopenharmony_ci unsigned long flags; 24518c2ecf20Sopenharmony_ci struct ahc_syncrate *syncrate; 24528c2ecf20Sopenharmony_ci 24538c2ecf20Sopenharmony_ci if (qas) 24548c2ecf20Sopenharmony_ci ppr_options |= MSG_EXT_PPR_QAS_REQ; 24558c2ecf20Sopenharmony_ci 24568c2ecf20Sopenharmony_ci ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, 24578c2ecf20Sopenharmony_ci starget->channel + 'A', ROLE_INITIATOR); 24588c2ecf20Sopenharmony_ci syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT); 24598c2ecf20Sopenharmony_ci ahc_lock(ahc, &flags); 24608c2ecf20Sopenharmony_ci ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->goal.offset, 24618c2ecf20Sopenharmony_ci ppr_options, AHC_TRANS_GOAL, FALSE); 24628c2ecf20Sopenharmony_ci ahc_unlock(ahc, &flags); 24638c2ecf20Sopenharmony_ci} 24648c2ecf20Sopenharmony_ci 24658c2ecf20Sopenharmony_cistatic void ahc_linux_set_iu(struct scsi_target *starget, int iu) 24668c2ecf20Sopenharmony_ci{ 24678c2ecf20Sopenharmony_ci struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 24688c2ecf20Sopenharmony_ci struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata); 24698c2ecf20Sopenharmony_ci struct ahc_tmode_tstate *tstate; 24708c2ecf20Sopenharmony_ci struct ahc_initiator_tinfo *tinfo 24718c2ecf20Sopenharmony_ci = ahc_fetch_transinfo(ahc, 24728c2ecf20Sopenharmony_ci starget->channel + 'A', 24738c2ecf20Sopenharmony_ci shost->this_id, starget->id, &tstate); 24748c2ecf20Sopenharmony_ci struct ahc_devinfo devinfo; 24758c2ecf20Sopenharmony_ci unsigned int ppr_options = tinfo->goal.ppr_options 24768c2ecf20Sopenharmony_ci & ~MSG_EXT_PPR_IU_REQ; 24778c2ecf20Sopenharmony_ci unsigned int period = tinfo->goal.period; 24788c2ecf20Sopenharmony_ci unsigned long flags; 24798c2ecf20Sopenharmony_ci struct ahc_syncrate *syncrate; 24808c2ecf20Sopenharmony_ci 24818c2ecf20Sopenharmony_ci if (iu) 24828c2ecf20Sopenharmony_ci ppr_options |= MSG_EXT_PPR_IU_REQ; 24838c2ecf20Sopenharmony_ci 24848c2ecf20Sopenharmony_ci ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0, 24858c2ecf20Sopenharmony_ci starget->channel + 'A', ROLE_INITIATOR); 24868c2ecf20Sopenharmony_ci syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT); 24878c2ecf20Sopenharmony_ci ahc_lock(ahc, &flags); 24888c2ecf20Sopenharmony_ci ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->goal.offset, 24898c2ecf20Sopenharmony_ci ppr_options, AHC_TRANS_GOAL, FALSE); 24908c2ecf20Sopenharmony_ci ahc_unlock(ahc, &flags); 24918c2ecf20Sopenharmony_ci} 24928c2ecf20Sopenharmony_ci#endif 24938c2ecf20Sopenharmony_ci 24948c2ecf20Sopenharmony_cistatic void ahc_linux_get_signalling(struct Scsi_Host *shost) 24958c2ecf20Sopenharmony_ci{ 24968c2ecf20Sopenharmony_ci struct ahc_softc *ahc = *(struct ahc_softc **)shost->hostdata; 24978c2ecf20Sopenharmony_ci unsigned long flags; 24988c2ecf20Sopenharmony_ci u8 mode; 24998c2ecf20Sopenharmony_ci 25008c2ecf20Sopenharmony_ci if (!(ahc->features & AHC_ULTRA2)) { 25018c2ecf20Sopenharmony_ci /* non-LVD chipset, may not have SBLKCTL reg */ 25028c2ecf20Sopenharmony_ci spi_signalling(shost) = 25038c2ecf20Sopenharmony_ci ahc->features & AHC_HVD ? 25048c2ecf20Sopenharmony_ci SPI_SIGNAL_HVD : 25058c2ecf20Sopenharmony_ci SPI_SIGNAL_SE; 25068c2ecf20Sopenharmony_ci return; 25078c2ecf20Sopenharmony_ci } 25088c2ecf20Sopenharmony_ci 25098c2ecf20Sopenharmony_ci ahc_lock(ahc, &flags); 25108c2ecf20Sopenharmony_ci ahc_pause(ahc); 25118c2ecf20Sopenharmony_ci mode = ahc_inb(ahc, SBLKCTL); 25128c2ecf20Sopenharmony_ci ahc_unpause(ahc); 25138c2ecf20Sopenharmony_ci ahc_unlock(ahc, &flags); 25148c2ecf20Sopenharmony_ci 25158c2ecf20Sopenharmony_ci if (mode & ENAB40) 25168c2ecf20Sopenharmony_ci spi_signalling(shost) = SPI_SIGNAL_LVD; 25178c2ecf20Sopenharmony_ci else if (mode & ENAB20) 25188c2ecf20Sopenharmony_ci spi_signalling(shost) = SPI_SIGNAL_SE; 25198c2ecf20Sopenharmony_ci else 25208c2ecf20Sopenharmony_ci spi_signalling(shost) = SPI_SIGNAL_UNKNOWN; 25218c2ecf20Sopenharmony_ci} 25228c2ecf20Sopenharmony_ci 25238c2ecf20Sopenharmony_cistatic struct spi_function_template ahc_linux_transport_functions = { 25248c2ecf20Sopenharmony_ci .set_offset = ahc_linux_set_offset, 25258c2ecf20Sopenharmony_ci .show_offset = 1, 25268c2ecf20Sopenharmony_ci .set_period = ahc_linux_set_period, 25278c2ecf20Sopenharmony_ci .show_period = 1, 25288c2ecf20Sopenharmony_ci .set_width = ahc_linux_set_width, 25298c2ecf20Sopenharmony_ci .show_width = 1, 25308c2ecf20Sopenharmony_ci .set_dt = ahc_linux_set_dt, 25318c2ecf20Sopenharmony_ci .show_dt = 1, 25328c2ecf20Sopenharmony_ci#if 0 25338c2ecf20Sopenharmony_ci .set_iu = ahc_linux_set_iu, 25348c2ecf20Sopenharmony_ci .show_iu = 1, 25358c2ecf20Sopenharmony_ci .set_qas = ahc_linux_set_qas, 25368c2ecf20Sopenharmony_ci .show_qas = 1, 25378c2ecf20Sopenharmony_ci#endif 25388c2ecf20Sopenharmony_ci .get_signalling = ahc_linux_get_signalling, 25398c2ecf20Sopenharmony_ci}; 25408c2ecf20Sopenharmony_ci 25418c2ecf20Sopenharmony_ci 25428c2ecf20Sopenharmony_ci 25438c2ecf20Sopenharmony_cistatic int __init 25448c2ecf20Sopenharmony_ciahc_linux_init(void) 25458c2ecf20Sopenharmony_ci{ 25468c2ecf20Sopenharmony_ci /* 25478c2ecf20Sopenharmony_ci * If we've been passed any parameters, process them now. 25488c2ecf20Sopenharmony_ci */ 25498c2ecf20Sopenharmony_ci if (aic7xxx) 25508c2ecf20Sopenharmony_ci aic7xxx_setup(aic7xxx); 25518c2ecf20Sopenharmony_ci 25528c2ecf20Sopenharmony_ci ahc_linux_transport_template = 25538c2ecf20Sopenharmony_ci spi_attach_transport(&ahc_linux_transport_functions); 25548c2ecf20Sopenharmony_ci if (!ahc_linux_transport_template) 25558c2ecf20Sopenharmony_ci return -ENODEV; 25568c2ecf20Sopenharmony_ci 25578c2ecf20Sopenharmony_ci scsi_transport_reserve_device(ahc_linux_transport_template, 25588c2ecf20Sopenharmony_ci sizeof(struct ahc_linux_device)); 25598c2ecf20Sopenharmony_ci 25608c2ecf20Sopenharmony_ci ahc_linux_pci_init(); 25618c2ecf20Sopenharmony_ci ahc_linux_eisa_init(); 25628c2ecf20Sopenharmony_ci return 0; 25638c2ecf20Sopenharmony_ci} 25648c2ecf20Sopenharmony_ci 25658c2ecf20Sopenharmony_cistatic void 25668c2ecf20Sopenharmony_ciahc_linux_exit(void) 25678c2ecf20Sopenharmony_ci{ 25688c2ecf20Sopenharmony_ci ahc_linux_pci_exit(); 25698c2ecf20Sopenharmony_ci ahc_linux_eisa_exit(); 25708c2ecf20Sopenharmony_ci spi_release_transport(ahc_linux_transport_template); 25718c2ecf20Sopenharmony_ci} 25728c2ecf20Sopenharmony_ci 25738c2ecf20Sopenharmony_cimodule_init(ahc_linux_init); 25748c2ecf20Sopenharmony_cimodule_exit(ahc_linux_exit); 2575