Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2)  * Adaptec AIC79xx device driver for Linux.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic79xx_osm.c#171 $
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * --------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * Copyright (c) 1994-2000 Justin T. Gibbs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * Copyright (c) 1997-1999 Doug Ledford
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  * Copyright (c) 2000-2003 Adaptec Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  * All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  * Redistribution and use in source and binary forms, with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  * modification, are permitted provided that the following conditions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  * are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  * 1. Redistributions of source code must retain the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  *    notice, this list of conditions, and the following disclaimer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  *    without modification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  *    substantially similar to the "NO WARRANTY" disclaimer below
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  *    ("Disclaimer") and any redistribution must be conditioned upon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  *    including a substantially similar Disclaimer requirement for further
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  *    binary redistribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  * 3. Neither the names of the above-listed copyright holders nor the names
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  *    of any contributors may be used to endorse or promote products derived
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  *    from this software without specific prior written permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  * Alternatively, this software may be distributed under the terms of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  * GNU General Public License ("GPL") version 2 as published by the Free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  * Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  * NO WARRANTY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32)  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35)  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36)  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37)  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38)  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39)  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40)  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41)  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42)  * POSSIBILITY OF SUCH DAMAGES.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include "aic79xx_osm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #include "aic79xx_inline.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #include <scsi/scsicam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) static struct scsi_transport_template *ahd_linux_transport_template = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #include <linux/init.h>		/* __setup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #include <linux/mm.h>		/* For fetching system memory size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #include <linux/blkdev.h>		/* For block_size() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #include <linux/delay.h>	/* For ssleep/msleep */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59)  * Bucket size for counting good commands in between bad ones.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) #define AHD_LINUX_ERR_THRESH	1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64)  * Set this to the delay in seconds after SCSI bus reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65)  * Note, we honor this only for the initial bus reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66)  * The scsi error recovery code performs its own bus settle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67)  * delay handling for error recovery actions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) #ifdef CONFIG_AIC79XX_RESET_DELAY_MS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) #define AIC79XX_RESET_DELAY CONFIG_AIC79XX_RESET_DELAY_MS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) #define AIC79XX_RESET_DELAY 5000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76)  * To change the default number of tagged transactions allowed per-device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77)  * add a line to the lilo.conf file like:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78)  * append="aic79xx=verbose,tag_info:{{32,32,32,32},{32,32,32,32}}"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79)  * which will result in the first four devices on the first two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80)  * controllers being set to a tagged queue depth of 32.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82)  * The tag_commands is an array of 16 to allow for wide and twin adapters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83)  * Twin adapters will use indexes 0-7 for channel 0, and indexes 8-15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84)  * for channel 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	uint16_t tag_commands[16];	/* Allow for wide/twin adapters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) } adapter_tag_info_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91)  * Modify this as you see fit for your system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93)  * 0			tagged queuing disabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94)  * 1 <= n <= 253	n == max tags ever dispatched.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96)  * The driver will throttle the number of commands dispatched to a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97)  * device if it returns queue full.  For devices with a fixed maximum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98)  * queue depth, the driver will eventually determine this depth and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99)  * lock it in (a console message is printed to indicate that a lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100)  * has occurred).  On some devices, queue full is returned for a temporary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101)  * resource shortage.  These devices will return queue full at varying
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102)  * depths.  The driver will throttle back when the queue fulls occur and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103)  * attempt to slowly increase the depth over time as the device recovers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104)  * from the resource shortage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106)  * In this example, the first line will disable tagged queueing for all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107)  * the devices on the first probed aic79xx adapter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109)  * The second line enables tagged queueing with 4 commands/LUN for IDs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110)  * (0, 2-11, 13-15), disables tagged queueing for ID 12, and tells the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111)  * driver to attempt to use up to 64 tags for ID 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113)  * The third line is the same as the first line.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115)  * The fourth line disables tagged queueing for devices 0 and 3.  It
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116)  * enables tagged queueing for the other IDs, with 16 commands/LUN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117)  * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118)  * IDs 2, 5-7, and 9-15.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122)  * NOTE: The below structure is for reference only, the actual structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123)  *       to modify in order to change things is just below this comment block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) adapter_tag_info_t aic79xx_tag_info[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	{{4, 64, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4}},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	{{0, 16, 4, 0, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) #ifdef CONFIG_AIC79XX_CMDS_PER_DEVICE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) #define AIC79XX_CMDS_PER_DEVICE CONFIG_AIC79XX_CMDS_PER_DEVICE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) #define AIC79XX_CMDS_PER_DEVICE AHD_MAX_QUEUE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) #define AIC79XX_CONFIGED_TAG_COMMANDS {					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151)  * By default, use the number of commands specified by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152)  * the users kernel configuration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) static adapter_tag_info_t aic79xx_tag_info[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	{AIC79XX_CONFIGED_TAG_COMMANDS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	{AIC79XX_CONFIGED_TAG_COMMANDS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	{AIC79XX_CONFIGED_TAG_COMMANDS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	{AIC79XX_CONFIGED_TAG_COMMANDS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	{AIC79XX_CONFIGED_TAG_COMMANDS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	{AIC79XX_CONFIGED_TAG_COMMANDS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	{AIC79XX_CONFIGED_TAG_COMMANDS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	{AIC79XX_CONFIGED_TAG_COMMANDS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	{AIC79XX_CONFIGED_TAG_COMMANDS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	{AIC79XX_CONFIGED_TAG_COMMANDS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	{AIC79XX_CONFIGED_TAG_COMMANDS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	{AIC79XX_CONFIGED_TAG_COMMANDS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	{AIC79XX_CONFIGED_TAG_COMMANDS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	{AIC79XX_CONFIGED_TAG_COMMANDS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	{AIC79XX_CONFIGED_TAG_COMMANDS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	{AIC79XX_CONFIGED_TAG_COMMANDS}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175)  * The I/O cell on the chip is very configurable in respect to its analog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176)  * characteristics.  Set the defaults here; they can be overriden with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177)  * the proper insmod parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) struct ahd_linux_iocell_opts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	uint8_t	precomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	uint8_t	slewrate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	uint8_t amplitude;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) #define AIC79XX_DEFAULT_PRECOMP		0xFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) #define AIC79XX_DEFAULT_SLEWRATE	0xFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) #define AIC79XX_DEFAULT_AMPLITUDE	0xFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) #define AIC79XX_DEFAULT_IOOPTS			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	AIC79XX_DEFAULT_PRECOMP,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	AIC79XX_DEFAULT_SLEWRATE,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	AIC79XX_DEFAULT_AMPLITUDE		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) #define AIC79XX_PRECOMP_INDEX	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) #define AIC79XX_SLEWRATE_INDEX	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) #define AIC79XX_AMPLITUDE_INDEX	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) static const struct ahd_linux_iocell_opts aic79xx_iocell_info[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	AIC79XX_DEFAULT_IOOPTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	AIC79XX_DEFAULT_IOOPTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	AIC79XX_DEFAULT_IOOPTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	AIC79XX_DEFAULT_IOOPTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	AIC79XX_DEFAULT_IOOPTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	AIC79XX_DEFAULT_IOOPTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	AIC79XX_DEFAULT_IOOPTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	AIC79XX_DEFAULT_IOOPTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	AIC79XX_DEFAULT_IOOPTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	AIC79XX_DEFAULT_IOOPTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	AIC79XX_DEFAULT_IOOPTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	AIC79XX_DEFAULT_IOOPTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	AIC79XX_DEFAULT_IOOPTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	AIC79XX_DEFAULT_IOOPTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	AIC79XX_DEFAULT_IOOPTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	AIC79XX_DEFAULT_IOOPTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218)  * There should be a specific return value for this in scsi.h, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219)  * it seems that most drivers ignore it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) #define DID_UNDERFLOW   DID_ERROR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) ahd_print_path(struct ahd_softc *ahd, struct scb *scb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	printk("(scsi%d:%c:%d:%d): ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	       ahd->platform_data->host->host_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	       scb != NULL ? SCB_GET_CHANNEL(ahd, scb) : 'X',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	       scb != NULL ? SCB_GET_TARGET(ahd, scb) : -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	       scb != NULL ? SCB_GET_LUN(scb) : -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234)  * XXX - these options apply unilaterally to _all_ adapters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235)  *       cards in the system.  This should be fixed.  Exceptions to this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236)  *       rule are noted in the comments.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240)  * Skip the scsi bus reset.  Non 0 make us skip the reset at startup.  This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241)  * has no effect on any later resets that might occur due to things like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242)  * SCSI bus timeouts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) static uint32_t aic79xx_no_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247)  * Should we force EXTENDED translation on a controller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248)  *     0 == Use whatever is in the SEEPROM or default to off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249)  *     1 == Use whatever is in the SEEPROM or default to on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) static uint32_t aic79xx_extended;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254)  * PCI bus parity checking of the Adaptec controllers.  This is somewhat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255)  * dubious at best.  To my knowledge, this option has never actually
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256)  * solved a PCI parity problem, but on certain machines with broken PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257)  * chipset configurations, it can generate tons of false error messages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258)  * It's included in the driver for completeness.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259)  *   0	   = Shut off PCI parity check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260)  *   non-0 = Enable PCI parity check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262)  * NOTE: you can't actually pass -1 on the lilo prompt.  So, to set this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263)  * variable to -1 you would actually want to simply pass the variable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264)  * name without a number.  That will invert the 0 which will result in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265)  * -1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) static uint32_t aic79xx_pci_parity = ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270)  * There are lots of broken chipsets in the world.  Some of them will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271)  * violate the PCI spec when we issue byte sized memory writes to our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272)  * controller.  I/O mapped register access, if allowed by the given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273)  * platform, will work in almost all cases.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) uint32_t aic79xx_allow_memio = ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278)  * So that we can set how long each device is given as a selection timeout.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279)  * The table of values goes like this:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280)  *   0 - 256ms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281)  *   1 - 128ms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282)  *   2 - 64ms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283)  *   3 - 32ms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284)  * We default to 256ms because some older devices need a longer time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285)  * to respond to initial selection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) static uint32_t aic79xx_seltime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290)  * Certain devices do not perform any aging on commands.  Should the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291)  * device be saturated by commands in one portion of the disk, it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292)  * possible for transactions on far away sectors to never be serviced.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293)  * To handle these devices, we can periodically send an ordered tag to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294)  * force all outstanding transactions to be serviced prior to a new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295)  * transaction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) static uint32_t aic79xx_periodic_otag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) /* Some storage boxes are using an LSI chip which has a bug making it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300)  * impossible to use aic79xx Rev B chip in 320 speeds.  The following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301)  * storage boxes have been reported to be buggy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302)  * EonStor 3U 16-Bay: U16U-G3A3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303)  * EonStor 2U 12-Bay: U12U-G3A3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304)  * SentinelRAID: 2500F R5 / R6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305)  * SentinelRAID: 2500F R1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306)  * SentinelRAID: 2500F/1500F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307)  * SentinelRAID: 150F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308)  * 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309)  * To get around this LSI bug, you can set your board to 160 mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310)  * or you can enable the SLOWCRC bit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) uint32_t aic79xx_slowcrc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315)  * Module information and settable options.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) static char *aic79xx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) MODULE_AUTHOR("Maintainer: Hannes Reinecke <hare@suse.de>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) MODULE_DESCRIPTION("Adaptec AIC790X U320 SCSI Host Bus Adapter driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) MODULE_LICENSE("Dual BSD/GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) MODULE_VERSION(AIC79XX_DRIVER_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) module_param(aic79xx, charp, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) MODULE_PARM_DESC(aic79xx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) "period-delimited options string:\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) "	verbose			Enable verbose/diagnostic logging\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) "	allow_memio		Allow device registers to be memory mapped\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) "	debug			Bitmask of debug values to enable\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) "	no_reset		Suppress initial bus resets\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) "	extended		Enable extended geometry on all controllers\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) "	periodic_otag		Send an ordered tagged transaction\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) "				periodically to prevent tag starvation.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) "				This may be required by some older disk\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) "				or drives/RAID arrays.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) "	tag_info:<tag_str>	Set per-target tag depth\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) "	global_tag_depth:<int>	Global tag depth for all targets on all buses\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) "	slewrate:<slewrate_list>Set the signal slew rate (0-15).\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) "	precomp:<pcomp_list>	Set the signal precompensation (0-7).\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) "	amplitude:<int>		Set the signal amplitude (0-7).\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) "	seltime:<int>		Selection Timeout:\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) "				(0/256ms,1/128ms,2/64ms,3/32ms)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) "	slowcrc			Turn on the SLOWCRC bit (Rev B only)\n"		 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) "\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) "	Sample modprobe configuration file:\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) "	#	Enable verbose logging\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) "	#	Set tag depth on Controller 2/Target 2 to 10 tags\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) "	#	Shorten the selection timeout to 128ms\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) "\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) "	options aic79xx 'aic79xx=verbose.tag_info:{{}.{}.{..10}}.seltime:1'\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) static void ahd_linux_handle_scsi_status(struct ahd_softc *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 					 struct scsi_device *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 					 struct scb *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) static void ahd_linux_queue_cmd_complete(struct ahd_softc *ahd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 					 struct scsi_cmnd *cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) static int ahd_linux_queue_abort_cmd(struct scsi_cmnd *cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) static void ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) static u_int ahd_linux_user_tagdepth(struct ahd_softc *ahd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 				     struct ahd_devinfo *devinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) static void ahd_linux_device_queue_depth(struct scsi_device *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) static int ahd_linux_run_command(struct ahd_softc*,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 				 struct ahd_linux_device *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 				 struct scsi_cmnd *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) static void ahd_linux_setup_tag_info_global(char *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) static int  aic79xx_setup(char *c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) static void ahd_freeze_simq(struct ahd_softc *ahd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) static void ahd_release_simq(struct ahd_softc *ahd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) static int ahd_linux_unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) /************************** OS Utility Wrappers *******************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) void ahd_delay(long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) ahd_delay(long usec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	 * udelay on Linux can have problems for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	 * multi-millisecond waits.  Wait at most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	 * 1024us per call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	while (usec > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		udelay(usec % 1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 		usec -= 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) /***************************** Low Level I/O **********************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) uint8_t ahd_inb(struct ahd_softc * ahd, long port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) void ahd_outb(struct ahd_softc * ahd, long port, uint8_t val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) void ahd_outw_atomic(struct ahd_softc * ahd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 				     long port, uint16_t val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) void ahd_outsb(struct ahd_softc * ahd, long port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 			       uint8_t *, int count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) void ahd_insb(struct ahd_softc * ahd, long port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 			       uint8_t *, int count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) uint8_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) ahd_inb(struct ahd_softc * ahd, long port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	uint8_t x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	if (ahd->tags[0] == BUS_SPACE_MEMIO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		x = readb(ahd->bshs[0].maddr + port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		x = inb(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	return (x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) #if 0 /* unused */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) static uint16_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) ahd_inw_atomic(struct ahd_softc * ahd, long port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	uint8_t x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	if (ahd->tags[0] == BUS_SPACE_MEMIO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 		x = readw(ahd->bshs[0].maddr + port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 		x = inw(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	return (x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) ahd_outb(struct ahd_softc * ahd, long port, uint8_t val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	if (ahd->tags[0] == BUS_SPACE_MEMIO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 		writeb(val, ahd->bshs[0].maddr + port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		outb(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) ahd_outw_atomic(struct ahd_softc * ahd, long port, uint16_t val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	if (ahd->tags[0] == BUS_SPACE_MEMIO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		writew(val, ahd->bshs[0].maddr + port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 		outw(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) ahd_outsb(struct ahd_softc * ahd, long port, uint8_t *array, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	 * There is probably a more efficient way to do this on Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	 * but we don't use this for anything speed critical and this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	 * should work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	for (i = 0; i < count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 		ahd_outb(ahd, port, *array++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) ahd_insb(struct ahd_softc * ahd, long port, uint8_t *array, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	 * There is probably a more efficient way to do this on Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	 * but we don't use this for anything speed critical and this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	 * should work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	for (i = 0; i < count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 		*array++ = ahd_inb(ahd, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) /******************************* PCI Routines *********************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) uint32_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) ahd_pci_read_config(ahd_dev_softc_t pci, int reg, int width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	switch (width) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		uint8_t retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		pci_read_config_byte(pci, reg, &retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 		return (retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 		uint16_t retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		pci_read_config_word(pci, reg, &retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		return (retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 		uint32_t retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 		pci_read_config_dword(pci, reg, &retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 		return (retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 		panic("ahd_pci_read_config: Read size too big");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		/* NOTREACHED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 		return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) ahd_pci_write_config(ahd_dev_softc_t pci, int reg, uint32_t value, int width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	switch (width) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 		pci_write_config_byte(pci, reg, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 		pci_write_config_word(pci, reg, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 		pci_write_config_dword(pci, reg, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 		panic("ahd_pci_write_config: Write size too big");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 		/* NOTREACHED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) /****************************** Inlines ***************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) static void ahd_linux_unmap_scb(struct ahd_softc*, struct scb*);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) ahd_linux_unmap_scb(struct ahd_softc *ahd, struct scb *scb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	struct scsi_cmnd *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	cmd = scb->io_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	ahd_sync_sglist(ahd, scb, BUS_DMASYNC_POSTWRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	scsi_dma_unmap(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) /******************************** Macros **************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) #define BUILD_SCSIID(ahd, cmd)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	(((scmd_id(cmd) << TID_SHIFT) & TID) | (ahd)->our_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548)  * Return a string describing the driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) static const char *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) ahd_linux_info(struct Scsi_Host *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	static char buffer[512];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	char	ahd_info[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	char   *bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	struct ahd_softc *ahd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	bp = &buffer[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	ahd = *(struct ahd_softc **)host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	memset(bp, 0, sizeof(buffer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	strcpy(bp, "Adaptec AIC79XX PCI-X SCSI HBA DRIVER, Rev " AIC79XX_DRIVER_VERSION "\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 			"        <");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	strcat(bp, ahd->description);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	strcat(bp, ">\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 			"        ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	ahd_controller_info(ahd, ahd_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	strcat(bp, ahd_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	return (bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573)  * Queue an SCB to the controller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) ahd_linux_queue_lck(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	struct	 ahd_softc *ahd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	struct	 ahd_linux_device *dev = scsi_transport_device_data(cmd->device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	int rtn = SCSI_MLQUEUE_HOST_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	cmd->scsi_done = scsi_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	cmd->result = CAM_REQ_INPROG << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	rtn = ahd_linux_run_command(ahd, dev, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	return rtn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) static DEF_SCSI_QCMD(ahd_linux_queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) static struct scsi_target **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) ahd_linux_target_in_softc(struct scsi_target *starget)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	struct	ahd_softc *ahd =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 		*((struct ahd_softc **)dev_to_shost(&starget->dev)->hostdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	unsigned int target_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	target_offset = starget->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	if (starget->channel != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 		target_offset += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	return &ahd->platform_data->starget[target_offset];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) ahd_linux_target_alloc(struct scsi_target *starget)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	struct	ahd_softc *ahd =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 		*((struct ahd_softc **)dev_to_shost(&starget->dev)->hostdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	struct seeprom_config *sc = ahd->seep_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	struct ahd_devinfo devinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	struct ahd_initiator_tinfo *tinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	struct ahd_tmode_tstate *tstate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	char channel = starget->channel + 'A';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	ahd_lock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	BUG_ON(*ahd_targp != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	*ahd_targp = starget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	if (sc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 		int flags = sc->device_flags[starget->id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 		tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 					    starget->id, &tstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		if ((flags  & CFPACKETIZED) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 			/* don't negotiate packetized (IU) transfers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 			spi_max_iu(starget) = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 			if ((ahd->features & AHD_RTI) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 				spi_rti(starget) = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 		if ((flags & CFQAS) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 			spi_max_qas(starget) = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		/* Transinfo values have been set to BIOS settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 		spi_max_width(starget) = (flags & CFWIDEB) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		spi_min_period(starget) = tinfo->user.period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 		spi_max_offset(starget) = tinfo->user.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	tinfo = ahd_fetch_transinfo(ahd, channel, ahd->our_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 				    starget->id, &tstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	ahd_compile_devinfo(&devinfo, ahd->our_id, starget->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 			    CAM_LUN_WILDCARD, channel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 			    ROLE_INITIATOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	ahd_set_syncrate(ahd, &devinfo, 0, 0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 			 AHD_TRANS_GOAL, /*paused*/FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 		      AHD_TRANS_GOAL, /*paused*/FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) ahd_linux_target_destroy(struct scsi_target *starget)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	*ahd_targp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) ahd_linux_slave_alloc(struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	struct	ahd_softc *ahd =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 		*((struct ahd_softc **)sdev->host->hostdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	struct ahd_linux_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	if (bootverbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		printk("%s: Slave Alloc %d\n", ahd_name(ahd), sdev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	dev = scsi_transport_device_data(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	memset(dev, 0, sizeof(*dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	 * We start out life using untagged
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	 * transactions of which we allow one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	dev->openings = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	 * Set maxtags to 0.  This will be changed if we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	 * later determine that we are dealing with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	 * a tagged queuing capable device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	dev->maxtags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) ahd_linux_slave_configure(struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	if (bootverbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 		sdev_printk(KERN_INFO, sdev, "Slave Configure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	ahd_linux_device_queue_depth(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	/* Initial Domain Validation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	if (!spi_initial_dv(sdev->sdev_target))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 		spi_dv_device(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) #if defined(__i386__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717)  * Return the disk geometry for the given SCSI device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) ahd_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		    sector_t capacity, int geom[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	int	 heads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	int	 sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	int	 cylinders;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	int	 extended;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	struct	 ahd_softc *ahd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	ahd = *((struct ahd_softc **)sdev->host->hostdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	if (scsi_partsize(bdev, capacity, geom))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	heads = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	sectors = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	cylinders = aic_sector_div(capacity, heads, sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	if (aic79xx_extended != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		extended = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 		extended = (ahd->flags & AHD_EXTENDED_TRANS_A) != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	if (extended && cylinders >= 1024) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 		heads = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		sectors = 63;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 		cylinders = aic_sector_div(capacity, heads, sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	geom[0] = heads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	geom[1] = sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	geom[2] = cylinders;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755)  * Abort the current SCSI command(s).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) ahd_linux_abort(struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	error = ahd_linux_queue_abort_cmd(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768)  * Attempt to send a target reset message to the device that timed out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) ahd_linux_dev_reset(struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	struct ahd_softc *ahd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	struct ahd_linux_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	struct scb *reset_scb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	u_int  cdb_byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	int    retval = SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	struct	ahd_initiator_tinfo *tinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	struct	ahd_tmode_tstate *tstate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	DECLARE_COMPLETION_ONSTACK(done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	reset_scb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	scmd_printk(KERN_INFO, cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 		    "Attempting to queue a TARGET RESET message:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	printk("CDB:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 		printk(" 0x%x", cmd->cmnd[cdb_byte]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	printk("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	 * Determine if we currently own this command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	dev = scsi_transport_device_data(cmd->device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	if (dev == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 		 * No target device for this command exists,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 		 * so we must not still own the command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 		scmd_printk(KERN_INFO, cmd, "Is not an active device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 		return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	 * Generate us a new SCB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	reset_scb = ahd_get_scb(ahd, AHD_NEVER_COL_IDX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	if (!reset_scb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 		scmd_printk(KERN_INFO, cmd, "No SCB available\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 		return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 				    cmd->device->id, &tstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	reset_scb->io_ctx = cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	reset_scb->platform_data->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	reset_scb->sg_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	ahd_set_residual(reset_scb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	ahd_set_sense_residual(reset_scb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	reset_scb->platform_data->xfer_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	reset_scb->hscb->control = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	reset_scb->hscb->scsiid = BUILD_SCSIID(ahd,cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	reset_scb->hscb->lun = cmd->device->lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	reset_scb->hscb->cdb_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	reset_scb->hscb->task_management = SIU_TASKMGMT_LUN_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	reset_scb->flags |= SCB_DEVICE_RESET|SCB_RECOVERY_SCB|SCB_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		reset_scb->flags |= SCB_PACKETIZED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 		reset_scb->hscb->control |= MK_MESSAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	dev->openings--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	dev->active++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	dev->commands_issued++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	ahd_lock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	LIST_INSERT_HEAD(&ahd->pending_scbs, reset_scb, pending_links);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	ahd_queue_scb(ahd, reset_scb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	ahd->platform_data->eh_done = &done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	printk("%s: Device reset code sleeping\n", ahd_name(ahd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	if (!wait_for_completion_timeout(&done, 5 * HZ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 		ahd_lock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 		ahd->platform_data->eh_done = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 		printk("%s: Device reset timer expired (active %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 		       ahd_name(ahd), dev->active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 		retval = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	printk("%s: Device reset returning 0x%x\n", ahd_name(ahd), retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	return (retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864)  * Reset the SCSI bus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) ahd_linux_bus_reset(struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	struct ahd_softc *ahd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	int    found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) #ifdef AHD_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	if ((ahd_debug & AHD_SHOW_RECOVERY) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 		printk("%s: Bus reset called for cmd %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 		       ahd_name(ahd), cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	ahd_lock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	found = ahd_reset_channel(ahd, scmd_channel(cmd) + 'A',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 				  /*initiate reset*/TRUE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	if (bootverbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		printk("%s: SCSI bus reset delivered. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 		       "%d SCBs aborted.\n", ahd_name(ahd), found);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	return (SUCCESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) struct scsi_host_template aic79xx_driver_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	.module			= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	.name			= "aic79xx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	.proc_name		= "aic79xx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	.show_info		= ahd_linux_show_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	.write_info	 	= ahd_proc_write_seeprom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	.info			= ahd_linux_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	.queuecommand		= ahd_linux_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	.eh_abort_handler	= ahd_linux_abort,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	.eh_device_reset_handler = ahd_linux_dev_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	.eh_bus_reset_handler	= ahd_linux_bus_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) #if defined(__i386__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	.bios_param		= ahd_linux_biosparam,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	.can_queue		= AHD_MAX_QUEUE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	.this_id		= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	.max_sectors		= 8192,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	.cmd_per_lun		= 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	.slave_alloc		= ahd_linux_slave_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	.slave_configure	= ahd_linux_slave_configure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	.target_alloc		= ahd_linux_target_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	.target_destroy		= ahd_linux_target_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) /******************************** Bus DMA *************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) ahd_dma_tag_create(struct ahd_softc *ahd, bus_dma_tag_t parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 		   bus_size_t alignment, bus_size_t boundary,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 		   dma_addr_t lowaddr, dma_addr_t highaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 		   bus_dma_filter_t *filter, void *filterarg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 		   bus_size_t maxsize, int nsegments,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		   bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	bus_dma_tag_t dmat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	dmat = kmalloc(sizeof(*dmat), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	if (dmat == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 		return (ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	 * Linux is very simplistic about DMA memory.  For now don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	 * maintain all specification information.  Once Linux supplies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	 * better facilities for doing these operations, or the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	 * needs of this particular driver change, we might need to do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	 * more here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	dmat->alignment = alignment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	dmat->boundary = boundary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	dmat->maxsize = maxsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	*ret_tag = dmat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) ahd_dma_tag_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	kfree(dmat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) ahd_dmamem_alloc(struct ahd_softc *ahd, bus_dma_tag_t dmat, void** vaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		 int flags, bus_dmamap_t *mapp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	*vaddr = dma_alloc_coherent(&ahd->dev_softc->dev, dmat->maxsize, mapp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 				    GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	if (*vaddr == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 		return (ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	return(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) ahd_dmamem_free(struct ahd_softc *ahd, bus_dma_tag_t dmat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 		void* vaddr, bus_dmamap_t map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	dma_free_coherent(&ahd->dev_softc->dev, dmat->maxsize, vaddr, map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 		void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 		void *cb_arg, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	 * Assume for now that this will only be used during
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	 * initialization and not for per-transaction buffer mapping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	bus_dma_segment_t stack_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	stack_sg.ds_addr = map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	stack_sg.ds_len = dmat->maxsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) ahd_dmamap_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) ahd_dmamap_unload(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	/* Nothing to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) /********************* Platform Dependent Functions ***************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) ahd_linux_setup_iocell_info(u_long index, int instance, int targ, int32_t value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	if ((instance >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	 && (instance < ARRAY_SIZE(aic79xx_iocell_info))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 		uint8_t *iocell_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 		iocell_info = (uint8_t*)&aic79xx_iocell_info[instance];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 		iocell_info[index] = value & 0xFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 		if (bootverbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 			printk("iocell[%d:%ld] = %d\n", instance, index, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) ahd_linux_setup_tag_info_global(char *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	int tags, i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	tags = simple_strtoul(p + 1, NULL, 0) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	printk("Setting Global Tags= %d\n", tags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	for (i = 0; i < ARRAY_SIZE(aic79xx_tag_info); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 		for (j = 0; j < AHD_NUM_TARGETS; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 			aic79xx_tag_info[i].tag_commands[j] = tags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) ahd_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	if ((instance >= 0) && (targ >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	 && (instance < ARRAY_SIZE(aic79xx_tag_info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	 && (targ < AHD_NUM_TARGETS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		aic79xx_tag_info[instance].tag_commands[targ] = value & 0x1FF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 		if (bootverbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 			printk("tag_info[%d:%d] = %d\n", instance, targ, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) static char *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) ahd_parse_brace_option(char *opt_name, char *opt_arg, char *end, int depth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 		       void (*callback)(u_long, int, int, int32_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		       u_long callback_arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	char	*tok_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	char	*tok_end2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	int      i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	int      instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	int	 targ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	int	 done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	char	 tok_list[] = {'.', ',', '{', '}', '\0'};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	/* All options use a ':' name/arg separator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	if (*opt_arg != ':')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 		return (opt_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	opt_arg++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	instance = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	targ = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	done = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	 * Restore separator that may be in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	 * the middle of our option argument.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	tok_end = strchr(opt_arg, '\0');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	if (tok_end < end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 		*tok_end = ',';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	while (!done) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 		switch (*opt_arg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 		case '{':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 			if (instance == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 				instance = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 				if (depth > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 					if (targ == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 						targ = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 					printk("Malformed Option %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 					       opt_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 					done = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 			opt_arg++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 		case '}':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 			if (targ != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 				targ = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 			else if (instance != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 				instance = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 			opt_arg++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 		case ',':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 		case '.':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 			if (instance == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 				done = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 			else if (targ >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 				targ++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 			else if (instance >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 				instance++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 			opt_arg++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 		case '\0':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 			done = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 			tok_end = end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 			for (i = 0; tok_list[i]; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 				tok_end2 = strchr(opt_arg, tok_list[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 				if ((tok_end2) && (tok_end2 < tok_end))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 					tok_end = tok_end2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 			callback(callback_arg, instance, targ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 				 simple_strtol(opt_arg, NULL, 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 			opt_arg = tok_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	return (opt_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)  * Handle Linux boot parameters. This routine allows for assigning a value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)  * to a parameter with a ':' between the parameter and the value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)  * ie. aic79xx=stpwlev:1,extended
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) aic79xx_setup(char *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	int	i, n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	char   *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	char   *end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	static const struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 		const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 		uint32_t *flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	} options[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 		{ "extended", &aic79xx_extended },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 		{ "no_reset", &aic79xx_no_reset },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 		{ "verbose", &aic79xx_verbose },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 		{ "allow_memio", &aic79xx_allow_memio},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) #ifdef AHD_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 		{ "debug", &ahd_debug },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 		{ "periodic_otag", &aic79xx_periodic_otag },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 		{ "pci_parity", &aic79xx_pci_parity },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 		{ "seltime", &aic79xx_seltime },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 		{ "tag_info", NULL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 		{ "global_tag_depth", NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 		{ "slewrate", NULL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 		{ "precomp", NULL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 		{ "amplitude", NULL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 		{ "slowcrc", &aic79xx_slowcrc },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	end = strchr(s, '\0');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	 * XXX ia64 gcc isn't smart enough to know that ARRAY_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	 * will never be 0 in this case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	while ((p = strsep(&s, ",.")) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 		if (*p == '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 		for (i = 0; i < ARRAY_SIZE(options); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 			n = strlen(options[i].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 			if (strncmp(options[i].name, p, n) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 		if (i == ARRAY_SIZE(options))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 		if (strncmp(p, "global_tag_depth", n) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 			ahd_linux_setup_tag_info_global(p + n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 		} else if (strncmp(p, "tag_info", n) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 			s = ahd_parse_brace_option("tag_info", p + n, end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 			    2, ahd_linux_setup_tag_info, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 		} else if (strncmp(p, "slewrate", n) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 			s = ahd_parse_brace_option("slewrate",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 			    p + n, end, 1, ahd_linux_setup_iocell_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 			    AIC79XX_SLEWRATE_INDEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 		} else if (strncmp(p, "precomp", n) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 			s = ahd_parse_brace_option("precomp",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 			    p + n, end, 1, ahd_linux_setup_iocell_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 			    AIC79XX_PRECOMP_INDEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 		} else if (strncmp(p, "amplitude", n) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 			s = ahd_parse_brace_option("amplitude",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 			    p + n, end, 1, ahd_linux_setup_iocell_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 			    AIC79XX_AMPLITUDE_INDEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 		} else if (p[n] == ':') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 			*(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 		} else if (!strncmp(p, "verbose", n)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 			*(options[i].flag) = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 			*(options[i].flag) ^= 0xFFFFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) __setup("aic79xx=", aic79xx_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) uint32_t aic79xx_verbose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) ahd_linux_register_host(struct ahd_softc *ahd, struct scsi_host_template *template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 	char	buf[80];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	struct	Scsi_Host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 	char	*new_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	u_long	s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	int	retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	template->name = ahd->description;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	host = scsi_host_alloc(template, sizeof(struct ahd_softc *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	if (host == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 		return (ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	*((struct ahd_softc **)host->hostdata) = ahd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	ahd->platform_data->host = host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	host->can_queue = AHD_MAX_QUEUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	host->cmd_per_lun = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	host->sg_tablesize = AHD_NSEG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	host->this_id = ahd->our_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	host->irq = ahd->platform_data->irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	host->max_id = (ahd->features & AHD_WIDE) ? 16 : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	host->max_lun = AHD_NUM_LUNS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 	host->max_channel = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	host->sg_tablesize = AHD_NSEG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	ahd_lock(ahd, &s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	ahd_set_unit(ahd, ahd_linux_unit++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	ahd_unlock(ahd, &s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	sprintf(buf, "scsi%d", host->host_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	new_name = kmalloc(strlen(buf) + 1, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 	if (new_name != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 		strcpy(new_name, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 		ahd_set_name(ahd, new_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 	host->unique_id = ahd->unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	ahd_linux_initialize_scsi_bus(ahd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	ahd_intr_enable(ahd, TRUE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	host->transportt = ahd_linux_transport_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	retval = scsi_add_host(host, &ahd->dev_softc->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 		printk(KERN_WARNING "aic79xx: scsi_add_host failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 		scsi_host_put(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	scsi_scan_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260)  * Place the SCSI bus into a known state by either resetting it,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261)  * or forcing transfer negotiations on the next command to any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262)  * target.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	u_int target_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	u_int numtarg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	unsigned long s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	target_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	numtarg = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 	if (aic79xx_no_reset != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 		ahd->flags &= ~AHD_RESET_BUS_A;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 	if ((ahd->flags & AHD_RESET_BUS_A) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 		ahd_reset_channel(ahd, 'A', /*initiate_reset*/TRUE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 		numtarg = (ahd->features & AHD_WIDE) ? 16 : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	ahd_lock(ahd, &s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	 * Force negotiation to async for all targets that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	 * will not see an initial bus reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 	for (; target_id < numtarg; target_id++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 		struct ahd_devinfo devinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 		struct ahd_initiator_tinfo *tinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 		struct ahd_tmode_tstate *tstate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 		tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 					    target_id, &tstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 		ahd_compile_devinfo(&devinfo, ahd->our_id, target_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 				    CAM_LUN_WILDCARD, 'A', ROLE_INITIATOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 		ahd_update_neg_request(ahd, &devinfo, tstate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 				       tinfo, AHD_NEG_ALWAYS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	ahd_unlock(ahd, &s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	/* Give the bus some time to recover */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	if ((ahd->flags & AHD_RESET_BUS_A) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 		ahd_freeze_simq(ahd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 		msleep(AIC79XX_RESET_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 		ahd_release_simq(ahd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	ahd->platform_data =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 	    kzalloc(sizeof(struct ahd_platform_data), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	if (ahd->platform_data == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 		return (ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	ahd->platform_data->irq = AHD_LINUX_NOIRQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	ahd_lockinit(ahd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	ahd->seltime = (aic79xx_seltime & 0x3) << 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) ahd_platform_free(struct ahd_softc *ahd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	struct scsi_target *starget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 	if (ahd->platform_data != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 		/* destroy all of the device and target objects */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 		for (i = 0; i < AHD_NUM_TARGETS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 			starget = ahd->platform_data->starget[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 			if (starget != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 				ahd->platform_data->starget[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 		if (ahd->platform_data->irq != AHD_LINUX_NOIRQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 			free_irq(ahd->platform_data->irq, ahd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 		if (ahd->tags[0] == BUS_SPACE_PIO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 		 && ahd->bshs[0].ioport != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 			release_region(ahd->bshs[0].ioport, 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 		if (ahd->tags[1] == BUS_SPACE_PIO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 		 && ahd->bshs[1].ioport != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 			release_region(ahd->bshs[1].ioport, 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 		if (ahd->tags[0] == BUS_SPACE_MEMIO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 		 && ahd->bshs[0].maddr != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 			iounmap(ahd->bshs[0].maddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 			release_mem_region(ahd->platform_data->mem_busaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 					   0x1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 		if (ahd->platform_data->host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 			scsi_host_put(ahd->platform_data->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 		kfree(ahd->platform_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) ahd_platform_init(struct ahd_softc *ahd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 	 * Lookup and commit any modified IO Cell options.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 	if (ahd->unit < ARRAY_SIZE(aic79xx_iocell_info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 		const struct ahd_linux_iocell_opts *iocell_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 		iocell_opts = &aic79xx_iocell_info[ahd->unit];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 		if (iocell_opts->precomp != AIC79XX_DEFAULT_PRECOMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 			AHD_SET_PRECOMP(ahd, iocell_opts->precomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 		if (iocell_opts->slewrate != AIC79XX_DEFAULT_SLEWRATE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 			AHD_SET_SLEWRATE(ahd, iocell_opts->slewrate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 		if (iocell_opts->amplitude != AIC79XX_DEFAULT_AMPLITUDE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 			AHD_SET_AMPLITUDE(ahd, iocell_opts->amplitude);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	ahd_platform_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 				SCB_GET_CHANNEL(ahd, scb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 				SCB_GET_LUN(scb), SCB_LIST_NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 				ROLE_UNKNOWN, CAM_REQUEUE_REQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) ahd_platform_set_tags(struct ahd_softc *ahd, struct scsi_device *sdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 		      struct ahd_devinfo *devinfo, ahd_queue_alg alg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 	struct ahd_linux_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 	int was_queuing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 	int now_queuing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 	if (sdev == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 	dev = scsi_transport_device_data(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 	if (dev == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 	was_queuing = dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 	switch (alg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 	case AHD_QUEUE_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 		now_queuing = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 		break; 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 	case AHD_QUEUE_BASIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 		now_queuing = AHD_DEV_Q_BASIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 	case AHD_QUEUE_TAGGED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 		now_queuing = AHD_DEV_Q_TAGGED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 	if ((dev->flags & AHD_DEV_FREEZE_TIL_EMPTY) == 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 	 && (was_queuing != now_queuing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 	 && (dev->active != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 		dev->flags |= AHD_DEV_FREEZE_TIL_EMPTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 		dev->qfrozen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 	dev->flags &= ~(AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED|AHD_DEV_PERIODIC_OTAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 	if (now_queuing) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 		u_int usertags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 		usertags = ahd_linux_user_tagdepth(ahd, devinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 		if (!was_queuing) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 			 * Start out aggressively and allow our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 			 * dynamic queue depth algorithm to take
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 			 * care of the rest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 			dev->maxtags = usertags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 			dev->openings = dev->maxtags - dev->active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 		if (dev->maxtags == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 			 * Queueing is disabled by the user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 			dev->openings = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 		} else if (alg == AHD_QUEUE_TAGGED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 			dev->flags |= AHD_DEV_Q_TAGGED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 			if (aic79xx_periodic_otag != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 				dev->flags |= AHD_DEV_PERIODIC_OTAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 			dev->flags |= AHD_DEV_Q_BASIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 		/* We can only have one opening. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 		dev->maxtags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 		dev->openings =  1 - dev->active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 	switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 	case AHD_DEV_Q_BASIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 	case AHD_DEV_Q_TAGGED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 		scsi_change_queue_depth(sdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 				dev->openings + dev->active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 		 * We allow the OS to queue 2 untagged transactions to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 		 * us at any time even though we can only execute them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 		 * serially on the controller/device.  This should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 		 * remove some latency.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 		scsi_change_queue_depth(sdev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) ahd_platform_abort_scbs(struct ahd_softc *ahd, int target, char channel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 			int lun, u_int tag, role_t role, uint32_t status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) static u_int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) ahd_linux_user_tagdepth(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 	static int warned_user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	u_int tags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	tags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 	if ((ahd->user_discenable & devinfo->target_mask) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 		if (ahd->unit >= ARRAY_SIZE(aic79xx_tag_info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 			if (warned_user == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 				printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) "aic79xx: WARNING: Insufficient tag_info instances\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) "aic79xx: for installed controllers.  Using defaults\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) "aic79xx: Please update the aic79xx_tag_info array in\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) "aic79xx: the aic79xx_osm.c source file.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 				warned_user++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 			tags = AHD_MAX_QUEUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 			adapter_tag_info_t *tag_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 			tag_info = &aic79xx_tag_info[ahd->unit];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 			tags = tag_info->tag_commands[devinfo->target_offset];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 			if (tags > AHD_MAX_QUEUE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 				tags = AHD_MAX_QUEUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 	return (tags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510)  * Determines the queue depth for a given device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) ahd_linux_device_queue_depth(struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 	struct	ahd_devinfo devinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 	u_int	tags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 	struct ahd_softc *ahd = *((struct ahd_softc **)sdev->host->hostdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 	ahd_compile_devinfo(&devinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 			    ahd->our_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 			    sdev->sdev_target->id, sdev->lun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 			    sdev->sdev_target->channel == 0 ? 'A' : 'B',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 			    ROLE_INITIATOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 	tags = ahd_linux_user_tagdepth(ahd, &devinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 	if (tags != 0 && sdev->tagged_supported != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 		ahd_platform_set_tags(ahd, sdev, &devinfo, AHD_QUEUE_TAGGED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 		ahd_send_async(ahd, devinfo.channel, devinfo.target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 			       devinfo.lun, AC_TRANSFER_NEG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 		ahd_print_devinfo(ahd, &devinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 		printk("Tagged Queuing enabled.  Depth %d\n", tags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 		ahd_platform_set_tags(ahd, sdev, &devinfo, AHD_QUEUE_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 		ahd_send_async(ahd, devinfo.channel, devinfo.target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 			       devinfo.lun, AC_TRANSFER_NEG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) ahd_linux_run_command(struct ahd_softc *ahd, struct ahd_linux_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 		      struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 	struct	 scb *scb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 	struct	 hardware_scb *hscb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 	struct	 ahd_initiator_tinfo *tinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 	struct	 ahd_tmode_tstate *tstate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 	u_int	 col_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 	uint16_t mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 	int nseg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 	nseg = scsi_dma_map(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 	if (nseg < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 		return SCSI_MLQUEUE_HOST_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 	ahd_lock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 	 * Get an scb to use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 	tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 				    cmd->device->id, &tstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 	if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) == 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 	 || (tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 		col_idx = AHD_NEVER_COL_IDX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 		col_idx = AHD_BUILD_COL_IDX(cmd->device->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 					    cmd->device->lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 	if ((scb = ahd_get_scb(ahd, col_idx)) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 		ahd->flags |= AHD_RESOURCE_SHORTAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 		ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 		scsi_dma_unmap(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 		return SCSI_MLQUEUE_HOST_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 	scb->io_ctx = cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 	scb->platform_data->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 	hscb = scb->hscb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 	cmd->host_scribble = (char *)scb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	 * Fill out basics of the HSCB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 	hscb->control = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 	hscb->scsiid = BUILD_SCSIID(ahd, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 	hscb->lun = cmd->device->lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 	scb->hscb->task_management = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 	mask = SCB_GET_TARGET_MASK(ahd, scb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 	if ((ahd->user_discenable & mask) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 		hscb->control |= DISCENB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 	if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 		scb->flags |= SCB_PACKETIZED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 	if ((tstate->auto_negotiate & mask) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 		scb->flags |= SCB_AUTO_NEGOTIATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 		scb->hscb->control |= MK_MESSAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 	if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 		if (dev->commands_since_idle_or_otag == AHD_OTAG_THRESH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 		 && (dev->flags & AHD_DEV_Q_TAGGED) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 			hscb->control |= MSG_ORDERED_TASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 			dev->commands_since_idle_or_otag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 			hscb->control |= MSG_SIMPLE_TASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 	hscb->cdb_len = cmd->cmd_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 	memcpy(hscb->shared_data.idata.cdb, cmd->cmnd, hscb->cdb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 	scb->platform_data->xfer_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 	ahd_set_residual(scb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 	ahd_set_sense_residual(scb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 	scb->sg_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 	if (nseg > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 		void *sg = scb->sg_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 		struct scatterlist *cur_seg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 		scb->platform_data->xfer_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 		scsi_for_each_sg(cmd, cur_seg, nseg, i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 			dma_addr_t addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 			bus_size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 			addr = sg_dma_address(cur_seg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 			len = sg_dma_len(cur_seg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 			scb->platform_data->xfer_len += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 			sg = ahd_sg_setup(ahd, scb, sg, addr, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 					  i == (nseg - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 	LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 	dev->openings--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 	dev->active++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 	dev->commands_issued++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 	if ((dev->flags & AHD_DEV_PERIODIC_OTAG) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 		dev->commands_since_idle_or_otag++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 	scb->flags |= SCB_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 	ahd_queue_scb(ahd, scb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 	ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655)  * SCSI controller interrupt handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) irqreturn_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) ahd_linux_isr(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 	struct	ahd_softc *ahd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 	u_long	flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 	int	ours;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 	ahd = (struct ahd_softc *) dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 	ahd_lock(ahd, &flags); 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 	ours = ahd_intr(ahd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 	ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 	return IRQ_RETVAL(ours);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) ahd_send_async(struct ahd_softc *ahd, char channel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 	       u_int target, u_int lun, ac_code code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 	switch (code) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 	case AC_TRANSFER_NEG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 		struct  scsi_target *starget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 		struct	ahd_initiator_tinfo *tinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 		struct	ahd_tmode_tstate *tstate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 		unsigned int target_ppr_options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 		BUG_ON(target == CAM_TARGET_WILDCARD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 		tinfo = ahd_fetch_transinfo(ahd, channel, ahd->our_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 					    target, &tstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 		 * Don't bother reporting results while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 		 * negotiations are still pending.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 		if (tinfo->curr.period != tinfo->goal.period
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 		 || tinfo->curr.width != tinfo->goal.width
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 		 || tinfo->curr.offset != tinfo->goal.offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 		 || tinfo->curr.ppr_options != tinfo->goal.ppr_options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 			if (bootverbose == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 		 * Don't bother reporting results that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 		 * are identical to those last reported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 		starget = ahd->platform_data->starget[target];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 		if (starget == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 		target_ppr_options =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 			(spi_dt(starget) ? MSG_EXT_PPR_DT_REQ : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 			+ (spi_qas(starget) ? MSG_EXT_PPR_QAS_REQ : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 			+ (spi_iu(starget) ?  MSG_EXT_PPR_IU_REQ : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 			+ (spi_rd_strm(starget) ? MSG_EXT_PPR_RD_STRM : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 			+ (spi_pcomp_en(starget) ? MSG_EXT_PPR_PCOMP_EN : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 			+ (spi_rti(starget) ? MSG_EXT_PPR_RTI : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 			+ (spi_wr_flow(starget) ? MSG_EXT_PPR_WR_FLOW : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 			+ (spi_hold_mcs(starget) ? MSG_EXT_PPR_HOLD_MCS : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 		if (tinfo->curr.period == spi_period(starget)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 		    && tinfo->curr.width == spi_width(starget)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 		    && tinfo->curr.offset == spi_offset(starget)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 		 && tinfo->curr.ppr_options == target_ppr_options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 			if (bootverbose == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 		spi_period(starget) = tinfo->curr.period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 		spi_width(starget) = tinfo->curr.width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 		spi_offset(starget) = tinfo->curr.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 		spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 		spi_qas(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_QAS_REQ ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 		spi_iu(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 		spi_rd_strm(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_RD_STRM ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 		spi_pcomp_en(starget) =  tinfo->curr.ppr_options & MSG_EXT_PPR_PCOMP_EN ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 		spi_rti(starget) =  tinfo->curr.ppr_options &  MSG_EXT_PPR_RTI ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 		spi_wr_flow(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_WR_FLOW ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 		spi_hold_mcs(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_HOLD_MCS ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 		spi_display_xfer_agreement(starget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738)         case AC_SENT_BDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 		WARN_ON(lun != CAM_LUN_WILDCARD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 		scsi_report_device_reset(ahd->platform_data->host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 					 channel - 'A', target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745)         case AC_BUS_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 		if (ahd->platform_data->host != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 			scsi_report_bus_reset(ahd->platform_data->host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 					      channel - 'A');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750)                 break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751)         default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752)                 panic("ahd_send_async: Unexpected async event");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757)  * Calls the higher level scsi done function and frees the scb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) ahd_done(struct ahd_softc *ahd, struct scb *scb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 	struct scsi_cmnd *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 	struct	  ahd_linux_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 	if ((scb->flags & SCB_ACTIVE) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 		printk("SCB %d done'd twice\n", SCB_GET_TAG(scb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 		ahd_dump_card_state(ahd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 		panic("Stopping for safety");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 	LIST_REMOVE(scb, pending_links);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 	cmd = scb->io_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 	dev = scb->platform_data->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 	dev->active--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 	dev->openings++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 	if ((cmd->result & (CAM_DEV_QFRZN << 16)) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 		cmd->result &= ~(CAM_DEV_QFRZN << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 		dev->qfrozen--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 	ahd_linux_unmap_scb(ahd, scb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 	 * Guard against stale sense data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 	 * The Linux mid-layer assumes that sense
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 	 * was retrieved anytime the first byte of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 	 * the sense buffer looks "sane".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 	cmd->sense_buffer[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 	if (ahd_get_transaction_status(scb) == CAM_REQ_INPROG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) #ifdef AHD_REPORT_UNDERFLOWS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 		uint32_t amount_xferred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 		amount_xferred =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 		    ahd_get_transfer_length(scb) - ahd_get_residual(scb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 		if ((scb->flags & SCB_TRANSMISSION_ERROR) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) #ifdef AHD_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 			if ((ahd_debug & AHD_SHOW_MISC) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 				ahd_print_path(ahd, scb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 				printk("Set CAM_UNCOR_PARITY\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 			ahd_set_transaction_status(scb, CAM_UNCOR_PARITY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) #ifdef AHD_REPORT_UNDERFLOWS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 		 * This code is disabled by default as some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 		 * clients of the SCSI system do not properly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 		 * initialize the underflow parameter.  This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 		 * results in spurious termination of commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 		 * that complete as expected (e.g. underflow is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 		 * allowed as command can return variable amounts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 		 * of data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 		} else if (amount_xferred < scb->io_ctx->underflow) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 			u_int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 			ahd_print_path(ahd, scb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 			printk("CDB:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 			for (i = 0; i < scb->io_ctx->cmd_len; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 				printk(" 0x%x", scb->io_ctx->cmnd[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 			printk("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 			ahd_print_path(ahd, scb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 			printk("Saw underflow (%ld of %ld bytes). "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 			       "Treated as error\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 				ahd_get_residual(scb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 				ahd_get_transfer_length(scb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 			ahd_set_transaction_status(scb, CAM_DATA_RUN_ERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 			ahd_set_transaction_status(scb, CAM_REQ_CMP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 	} else if (ahd_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 		ahd_linux_handle_scsi_status(ahd, cmd->device, scb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 	if (dev->openings == 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 	 && ahd_get_transaction_status(scb) == CAM_REQ_CMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	 && ahd_get_scsi_status(scb) != SCSI_STATUS_QUEUE_FULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 		dev->tag_success_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 	 * Some devices deal with temporary internal resource
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 	 * shortages by returning queue full.  When the queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 	 * full occurrs, we throttle back.  Slowly try to get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 	 * back to our previous queue depth.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 	if ((dev->openings + dev->active) < dev->maxtags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 	 && dev->tag_success_count > AHD_TAG_SUCCESS_INTERVAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 		dev->tag_success_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 		dev->openings++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 	if (dev->active == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 		dev->commands_since_idle_or_otag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 	if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 		printk("Recovery SCB completes\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 		if (ahd_get_transaction_status(scb) == CAM_BDR_SENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 		 || ahd_get_transaction_status(scb) == CAM_REQ_ABORTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 			ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 		if (ahd->platform_data->eh_done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 			complete(ahd->platform_data->eh_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 	ahd_free_scb(ahd, scb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 	ahd_linux_queue_cmd_complete(ahd, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 			     struct scsi_device *sdev, struct scb *scb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 	struct	ahd_devinfo devinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 	struct ahd_linux_device *dev = scsi_transport_device_data(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 	ahd_compile_devinfo(&devinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 			    ahd->our_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 			    sdev->sdev_target->id, sdev->lun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 			    sdev->sdev_target->channel == 0 ? 'A' : 'B',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 			    ROLE_INITIATOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 	 * We don't currently trust the mid-layer to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 	 * properly deal with queue full or busy.  So,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 	 * when one occurs, we tell the mid-layer to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 	 * unconditionally requeue the command to us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 	 * so that we can retry it ourselves.  We also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 	 * implement our own throttling mechanism so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 	 * we don't clobber the device with too many
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 	 * commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 	switch (ahd_get_scsi_status(scb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 	case SCSI_STATUS_CHECK_COND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 	case SCSI_STATUS_CMD_TERMINATED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 		struct scsi_cmnd *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 		 * Copy sense information to the OS's cmd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 		 * structure if it is available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 		cmd = scb->io_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 		if ((scb->flags & (SCB_SENSE|SCB_PKT_SENSE)) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 			struct scsi_status_iu_header *siu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 			u_int sense_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 			u_int sense_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 			if (scb->flags & SCB_SENSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 				sense_size = min(sizeof(struct scsi_sense_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 					       - ahd_get_sense_residual(scb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 						 (u_long)SCSI_SENSE_BUFFERSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 				sense_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 				 * Copy only the sense data into the provided
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 				 * buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 				siu = (struct scsi_status_iu_header *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 				    scb->sense_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 				sense_size = min_t(size_t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 						scsi_4btoul(siu->sense_length),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 						SCSI_SENSE_BUFFERSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 				sense_offset = SIU_SENSE_OFFSET(siu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 			memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 			memcpy(cmd->sense_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 			       ahd_get_sense_buf(ahd, scb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 			       + sense_offset, sense_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 			cmd->result |= (DRIVER_SENSE << 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) #ifdef AHD_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 			if (ahd_debug & AHD_SHOW_SENSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 				int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 				printk("Copied %d bytes of sense data at %d:",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 				       sense_size, sense_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 				for (i = 0; i < sense_size; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 					if ((i & 0xF) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 						printk("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 					printk("0x%x ", cmd->sense_buffer[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 				printk("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 	case SCSI_STATUS_QUEUE_FULL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 		 * By the time the core driver has returned this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 		 * command, all other commands that were queued
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 		 * to us but not the device have been returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 		 * This ensures that dev->active is equal to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 		 * the number of commands actually queued to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 		 * the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 		dev->tag_success_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 		if (dev->active != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 			 * Drop our opening count to the number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 			 * of commands currently outstanding.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 			dev->openings = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) #ifdef AHD_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 			if ((ahd_debug & AHD_SHOW_QFULL) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 				ahd_print_path(ahd, scb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 				printk("Dropping tag count to %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 				       dev->active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 			if (dev->active == dev->tags_on_last_queuefull) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 				dev->last_queuefull_same_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 				 * If we repeatedly see a queue full
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 				 * at the same queue depth, this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 				 * device has a fixed number of tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 				 * slots.  Lock in this tag depth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 				 * so we stop seeing queue fulls from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 				 * this device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 				if (dev->last_queuefull_same_count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 				 == AHD_LOCK_TAGS_COUNT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 					dev->maxtags = dev->active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 					ahd_print_path(ahd, scb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 					printk("Locking max tag count at %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 					       dev->active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 				dev->tags_on_last_queuefull = dev->active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 				dev->last_queuefull_same_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 			ahd_set_transaction_status(scb, CAM_REQUEUE_REQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 			ahd_set_scsi_status(scb, SCSI_STATUS_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) 			ahd_platform_set_tags(ahd, sdev, &devinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 				     (dev->flags & AHD_DEV_Q_BASIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 				   ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 		 * Drop down to a single opening, and treat this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) 		 * as if the target returned BUSY SCSI status.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 		dev->openings = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 		ahd_platform_set_tags(ahd, sdev, &devinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 			     (dev->flags & AHD_DEV_Q_BASIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 			   ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 		ahd_set_scsi_status(scb, SCSI_STATUS_BUSY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) 	int new_status = DID_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 	int do_fallback = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 	int scsi_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 	 * Map CAM error codes into Linux Error codes.  We
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 	 * avoid the conversion so that the DV code has the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 	 * full error information available when making
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 	 * state change decisions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) 	status = ahd_cmd_get_transaction_status(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 	switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 	case CAM_REQ_INPROG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) 	case CAM_REQ_CMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 		new_status = DID_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 	case CAM_AUTOSENSE_FAIL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 		new_status = DID_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) 	case CAM_SCSI_STATUS_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 		scsi_status = ahd_cmd_get_scsi_status(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 		switch(scsi_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 		case SCSI_STATUS_CMD_TERMINATED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 		case SCSI_STATUS_CHECK_COND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 			if ((cmd->result >> 24) != DRIVER_SENSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 				do_fallback = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) 				struct scsi_sense_data *sense;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 				
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 				sense = (struct scsi_sense_data *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 					cmd->sense_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 				if (sense->extra_len >= 5 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 				    (sense->add_sense_code == 0x47
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 				     || sense->add_sense_code == 0x48))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 					do_fallback = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 	case CAM_REQ_ABORTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 		new_status = DID_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 	case CAM_BUSY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 		new_status = DID_BUS_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 	case CAM_REQ_INVALID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 	case CAM_PATH_INVALID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 		new_status = DID_BAD_TARGET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 	case CAM_SEL_TIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) 		new_status = DID_NO_CONNECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) 	case CAM_SCSI_BUS_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 	case CAM_BDR_SENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 		new_status = DID_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 	case CAM_UNCOR_PARITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 		new_status = DID_PARITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 		do_fallback = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 	case CAM_CMD_TIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 		new_status = DID_TIME_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) 		do_fallback = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) 	case CAM_REQ_CMP_ERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) 	case CAM_UNEXP_BUSFREE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) 	case CAM_DATA_RUN_ERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) 		new_status = DID_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 		do_fallback = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 	case CAM_UA_ABORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) 	case CAM_NO_HBA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 	case CAM_SEQUENCE_FAIL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) 	case CAM_CCB_LEN_ERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 	case CAM_PROVIDE_FAIL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) 	case CAM_REQ_TERMIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 	case CAM_UNREC_HBA_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 	case CAM_REQ_TOO_BIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) 		new_status = DID_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 	case CAM_REQUEUE_REQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 		new_status = DID_REQUEUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 		/* We should never get here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) 		new_status = DID_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) 	if (do_fallback) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) 		printk("%s: device overrun (status %x) on %d:%d:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) 		       ahd_name(ahd), status, cmd->device->channel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) 		       cmd->device->id, (u8)cmd->device->lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) 	ahd_cmd_set_transaction_status(cmd, new_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 	cmd->scsi_done(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) ahd_freeze_simq(struct ahd_softc *ahd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) 	scsi_block_requests(ahd->platform_data->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) ahd_release_simq(struct ahd_softc *ahd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 	scsi_unblock_requests(ahd->platform_data->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) ahd_linux_queue_abort_cmd(struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) 	struct ahd_softc *ahd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 	struct ahd_linux_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) 	struct scb *pending_scb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 	u_int  saved_scbptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 	u_int  active_scbptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) 	u_int  last_phase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 	u_int  saved_scsiid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 	u_int  cdb_byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 	int    retval = SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 	int    was_paused;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 	int    paused;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) 	int    wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) 	int    disconnected;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) 	ahd_mode_state saved_modes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 	pending_scb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 	paused = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 	wait = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 	ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 	scmd_printk(KERN_INFO, cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) 		    "Attempting to queue an ABORT message:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) 	printk("CDB:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) 	for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) 		printk(" 0x%x", cmd->cmnd[cdb_byte]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 	printk("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 	ahd_lock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 	 * First determine if we currently own this command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 	 * Start by searching the device queue.  If not found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 	 * there, check the pending_scb list.  If not found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 	 * at all, and the system wanted us to just abort the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) 	 * command, return success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) 	dev = scsi_transport_device_data(cmd->device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 	if (dev == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 		 * No target device for this command exists,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 		 * so we must not still own the command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 		scmd_printk(KERN_INFO, cmd, "Is not an active device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 	 * See if we can find a matching cmd in the pending list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) 	LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 		if (pending_scb->io_ctx == cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) 	if (pending_scb == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) 		scmd_printk(KERN_INFO, cmd, "Command not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) 	if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) 		 * We can't queue two recovery actions using the same SCB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) 		retval = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) 	 * Ensure that the card doesn't do anything
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) 	 * behind our back.  Also make sure that we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) 	 * didn't "just" miss an interrupt that would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) 	 * affect this cmd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) 	was_paused = ahd_is_paused(ahd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) 	ahd_pause_and_flushwork(ahd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) 	paused = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) 	if ((pending_scb->flags & SCB_ACTIVE) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) 		scmd_printk(KERN_INFO, cmd, "Command already completed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) 	printk("%s: At time of recovery, card was %spaused\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) 	       ahd_name(ahd), was_paused ? "" : "not ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 	ahd_dump_card_state(ahd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) 	disconnected = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) 	if (ahd_search_qinfifo(ahd, cmd->device->id, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 			       cmd->device->channel + 'A',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) 			       cmd->device->lun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) 			       pending_scb->hscb->tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) 			       ROLE_INITIATOR, CAM_REQ_ABORTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) 			       SEARCH_COMPLETE) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 		printk("%s:%d:%d:%d: Cmd aborted from QINFIFO\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 		       ahd_name(ahd), cmd->device->channel, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 		       cmd->device->id, (u8)cmd->device->lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 	saved_modes = ahd_save_modes(ahd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) 	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 	last_phase = ahd_inb(ahd, LASTPHASE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) 	saved_scbptr = ahd_get_scbptr(ahd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 	active_scbptr = saved_scbptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) 	if (disconnected && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) 		struct scb *bus_scb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) 		bus_scb = ahd_lookup_scb(ahd, active_scbptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) 		if (bus_scb == pending_scb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) 			disconnected = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) 	 * At this point, pending_scb is the scb associated with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) 	 * passed in command.  That command is currently active on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) 	 * bus or is in the disconnected state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) 	saved_scsiid = ahd_inb(ahd, SAVED_SCSIID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) 	if (last_phase != P_BUSFREE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) 	    && SCB_GET_TAG(pending_scb) == active_scbptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) 		 * We're active on the bus, so assert ATN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) 		 * and hope that the target responds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) 		pending_scb = ahd_lookup_scb(ahd, active_scbptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) 		pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) 		ahd_outb(ahd, MSG_OUT, HOST_MSG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) 		ahd_outb(ahd, SCSISIGO, last_phase|ATNO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) 		scmd_printk(KERN_INFO, cmd, "Device is active, asserting ATN\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) 		wait = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) 	} else if (disconnected) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) 		 * Actually re-queue this SCB in an attempt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) 		 * to select the device before it reconnects.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) 		pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) 		ahd_set_scbptr(ahd, SCB_GET_TAG(pending_scb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) 		pending_scb->hscb->cdb_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) 		pending_scb->hscb->task_attribute = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) 		pending_scb->hscb->task_management = SIU_TASKMGMT_ABORT_TASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) 		if ((pending_scb->flags & SCB_PACKETIZED) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) 			 * Mark the SCB has having an outstanding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) 			 * task management function.  Should the command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) 			 * complete normally before the task management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) 			 * function can be sent, the host will be notified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) 			 * to abort our requeued SCB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) 			ahd_outb(ahd, SCB_TASK_MANAGEMENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) 				 pending_scb->hscb->task_management);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) 			 * If non-packetized, set the MK_MESSAGE control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) 			 * bit indicating that we desire to send a message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) 			 * We also set the disconnected flag since there is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) 			 * no guarantee that our SCB control byte matches
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) 			 * the version on the card.  We don't want the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) 			 * sequencer to abort the command thinking an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) 			 * unsolicited reselection occurred.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) 			pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) 			 * The sequencer will never re-reference the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) 			 * in-core SCB.  To make sure we are notified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) 			 * during reselection, set the MK_MESSAGE flag in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) 			 * the card's copy of the SCB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) 			ahd_outb(ahd, SCB_CONTROL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) 				 ahd_inb(ahd, SCB_CONTROL)|MK_MESSAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) 		 * Clear out any entries in the QINFIFO first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) 		 * so we are the next SCB for this target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) 		 * to run.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) 		ahd_search_qinfifo(ahd, cmd->device->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) 				   cmd->device->channel + 'A', cmd->device->lun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) 				   SCB_LIST_NULL, ROLE_INITIATOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) 				   CAM_REQUEUE_REQ, SEARCH_COMPLETE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) 		ahd_qinfifo_requeue_tail(ahd, pending_scb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) 		ahd_set_scbptr(ahd, saved_scbptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) 		ahd_print_path(ahd, pending_scb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) 		printk("Device is disconnected, re-queuing SCB\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 		wait = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) 		scmd_printk(KERN_INFO, cmd, "Unable to deliver message\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) 		retval = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) 	ahd_restore_modes(ahd, saved_modes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) 	if (paused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) 		ahd_unpause(ahd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) 	if (wait) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) 		DECLARE_COMPLETION_ONSTACK(done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) 		ahd->platform_data->eh_done = &done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) 		ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) 		printk("%s: Recovery code sleeping\n", ahd_name(ahd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) 		if (!wait_for_completion_timeout(&done, 5 * HZ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) 			ahd_lock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) 			ahd->platform_data->eh_done = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) 			ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) 			printk("%s: Timer Expired (active %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) 			       ahd_name(ahd), dev->active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) 			retval = FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) 		printk("Recovery code awake\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) 		ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) 	if (retval != SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) 		printk("%s: Command abort returning 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) 		       ahd_name(ahd), retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) static void ahd_linux_set_width(struct scsi_target *starget, int width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) 	struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) 	struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) 	struct ahd_devinfo devinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) 	ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) 			    starget->channel + 'A', ROLE_INITIATOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) 	ahd_lock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) 	ahd_set_width(ahd, &devinfo, width, AHD_TRANS_GOAL, FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) 	ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) static void ahd_linux_set_period(struct scsi_target *starget, int period)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) 	struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) 	struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) 	struct ahd_tmode_tstate *tstate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) 	struct ahd_initiator_tinfo *tinfo 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) 		= ahd_fetch_transinfo(ahd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) 				      starget->channel + 'A',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) 				      shost->this_id, starget->id, &tstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) 	struct ahd_devinfo devinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) 	unsigned int ppr_options = tinfo->goal.ppr_options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) 	unsigned int dt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) 	unsigned long offset = tinfo->goal.offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) #ifdef AHD_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) 	if ((ahd_debug & AHD_SHOW_DV) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) 		printk("%s: set period to %d\n", ahd_name(ahd), period);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) 	if (offset == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) 		offset = MAX_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) 	if (period < 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) 		period = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) 	if (period < 10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) 		if (spi_max_width(starget)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) 			ppr_options |= MSG_EXT_PPR_DT_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) 			if (period == 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) 				ppr_options |= MSG_EXT_PPR_IU_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) 			period = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) 	dt = ppr_options & MSG_EXT_PPR_DT_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) 	ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) 			    starget->channel + 'A', ROLE_INITIATOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) 	/* all PPR requests apart from QAS require wide transfers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) 	if (ppr_options & ~MSG_EXT_PPR_QAS_REQ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) 		if (spi_width(starget) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) 			ppr_options &= MSG_EXT_PPR_QAS_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) 	ahd_find_syncrate(ahd, &period, &ppr_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) 			  dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) 	ahd_lock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) 	ahd_set_syncrate(ahd, &devinfo, period, offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) 			 ppr_options, AHD_TRANS_GOAL, FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) 	ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) static void ahd_linux_set_offset(struct scsi_target *starget, int offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) 	struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) 	struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) 	struct ahd_tmode_tstate *tstate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) 	struct ahd_initiator_tinfo *tinfo 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) 		= ahd_fetch_transinfo(ahd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) 				      starget->channel + 'A',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) 				      shost->this_id, starget->id, &tstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) 	struct ahd_devinfo devinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) 	unsigned int ppr_options = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) 	unsigned int period = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) 	unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) #ifdef AHD_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) 	if ((ahd_debug & AHD_SHOW_DV) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) 		printk("%s: set offset to %d\n", ahd_name(ahd), offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) 	ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) 			    starget->channel + 'A', ROLE_INITIATOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) 	if (offset != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) 		period = tinfo->goal.period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) 		ppr_options = tinfo->goal.ppr_options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) 		ahd_find_syncrate(ahd, &period, &ppr_options, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) 				  dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) 	ahd_lock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) 	ahd_set_syncrate(ahd, &devinfo, period, offset, ppr_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) 			 AHD_TRANS_GOAL, FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) 	ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) static void ahd_linux_set_dt(struct scsi_target *starget, int dt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) 	struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) 	struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) 	struct ahd_tmode_tstate *tstate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) 	struct ahd_initiator_tinfo *tinfo 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) 		= ahd_fetch_transinfo(ahd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) 				      starget->channel + 'A',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) 				      shost->this_id, starget->id, &tstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) 	struct ahd_devinfo devinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) 	unsigned int ppr_options = tinfo->goal.ppr_options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) 		& ~MSG_EXT_PPR_DT_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) 	unsigned int period = tinfo->goal.period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) 	unsigned int width = tinfo->goal.width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) #ifdef AHD_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) 	if ((ahd_debug & AHD_SHOW_DV) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) 		printk("%s: %s DT\n", ahd_name(ahd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) 		       dt ? "enabling" : "disabling");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) 	if (dt && spi_max_width(starget)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) 		ppr_options |= MSG_EXT_PPR_DT_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) 		if (!width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) 			ahd_linux_set_width(starget, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) 		if (period <= 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) 			period = 10; /* If resetting DT, period must be >= 25ns */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) 		/* IU is invalid without DT set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) 		ppr_options &= ~MSG_EXT_PPR_IU_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) 	ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) 			    starget->channel + 'A', ROLE_INITIATOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) 	ahd_find_syncrate(ahd, &period, &ppr_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) 			  dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) 	ahd_lock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) 	ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) 			 ppr_options, AHD_TRANS_GOAL, FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) 	ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) static void ahd_linux_set_qas(struct scsi_target *starget, int qas)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) 	struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) 	struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) 	struct ahd_tmode_tstate *tstate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) 	struct ahd_initiator_tinfo *tinfo 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) 		= ahd_fetch_transinfo(ahd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) 				      starget->channel + 'A',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) 				      shost->this_id, starget->id, &tstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) 	struct ahd_devinfo devinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) 	unsigned int ppr_options = tinfo->goal.ppr_options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) 		& ~MSG_EXT_PPR_QAS_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) 	unsigned int period = tinfo->goal.period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) 	unsigned int dt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) #ifdef AHD_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) 	if ((ahd_debug & AHD_SHOW_DV) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) 		printk("%s: %s QAS\n", ahd_name(ahd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) 		       qas ? "enabling" : "disabling");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) 	if (qas) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) 		ppr_options |= MSG_EXT_PPR_QAS_REQ; 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) 	dt = ppr_options & MSG_EXT_PPR_DT_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) 	ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) 			    starget->channel + 'A', ROLE_INITIATOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) 	ahd_find_syncrate(ahd, &period, &ppr_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) 			  dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) 	ahd_lock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) 	ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) 			 ppr_options, AHD_TRANS_GOAL, FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) 	ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) static void ahd_linux_set_iu(struct scsi_target *starget, int iu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) 	struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) 	struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) 	struct ahd_tmode_tstate *tstate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) 	struct ahd_initiator_tinfo *tinfo 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) 		= ahd_fetch_transinfo(ahd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) 				      starget->channel + 'A',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) 				      shost->this_id, starget->id, &tstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) 	struct ahd_devinfo devinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) 	unsigned int ppr_options = tinfo->goal.ppr_options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) 		& ~MSG_EXT_PPR_IU_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) 	unsigned int period = tinfo->goal.period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) 	unsigned int dt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) #ifdef AHD_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) 	if ((ahd_debug & AHD_SHOW_DV) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) 		printk("%s: %s IU\n", ahd_name(ahd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) 		       iu ? "enabling" : "disabling");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) 	if (iu && spi_max_width(starget)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) 		ppr_options |= MSG_EXT_PPR_IU_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) 		ppr_options |= MSG_EXT_PPR_DT_REQ; /* IU requires DT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) 	dt = ppr_options & MSG_EXT_PPR_DT_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) 	ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) 			    starget->channel + 'A', ROLE_INITIATOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) 	ahd_find_syncrate(ahd, &period, &ppr_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) 			  dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) 	ahd_lock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) 	ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) 			 ppr_options, AHD_TRANS_GOAL, FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) 	ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) static void ahd_linux_set_rd_strm(struct scsi_target *starget, int rdstrm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) 	struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) 	struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) 	struct ahd_tmode_tstate *tstate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) 	struct ahd_initiator_tinfo *tinfo 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) 		= ahd_fetch_transinfo(ahd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) 				      starget->channel + 'A',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) 				      shost->this_id, starget->id, &tstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) 	struct ahd_devinfo devinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) 	unsigned int ppr_options = tinfo->goal.ppr_options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) 		& ~MSG_EXT_PPR_RD_STRM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) 	unsigned int period = tinfo->goal.period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) 	unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) #ifdef AHD_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) 	if ((ahd_debug & AHD_SHOW_DV) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) 		printk("%s: %s Read Streaming\n", ahd_name(ahd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) 		       rdstrm  ? "enabling" : "disabling");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) 	if (rdstrm && spi_max_width(starget))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) 		ppr_options |= MSG_EXT_PPR_RD_STRM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) 	ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) 			    starget->channel + 'A', ROLE_INITIATOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) 	ahd_find_syncrate(ahd, &period, &ppr_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) 			  dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) 	ahd_lock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) 	ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) 			 ppr_options, AHD_TRANS_GOAL, FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) 	ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) static void ahd_linux_set_wr_flow(struct scsi_target *starget, int wrflow)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) 	struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) 	struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) 	struct ahd_tmode_tstate *tstate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) 	struct ahd_initiator_tinfo *tinfo 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) 		= ahd_fetch_transinfo(ahd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) 				      starget->channel + 'A',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) 				      shost->this_id, starget->id, &tstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) 	struct ahd_devinfo devinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) 	unsigned int ppr_options = tinfo->goal.ppr_options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) 		& ~MSG_EXT_PPR_WR_FLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) 	unsigned int period = tinfo->goal.period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) 	unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) #ifdef AHD_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) 	if ((ahd_debug & AHD_SHOW_DV) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) 		printk("%s: %s Write Flow Control\n", ahd_name(ahd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) 		       wrflow ? "enabling" : "disabling");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) 	if (wrflow && spi_max_width(starget))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) 		ppr_options |= MSG_EXT_PPR_WR_FLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) 	ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) 			    starget->channel + 'A', ROLE_INITIATOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) 	ahd_find_syncrate(ahd, &period, &ppr_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) 			  dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) 	ahd_lock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) 	ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) 			 ppr_options, AHD_TRANS_GOAL, FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) 	ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) static void ahd_linux_set_rti(struct scsi_target *starget, int rti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) 	struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) 	struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) 	struct ahd_tmode_tstate *tstate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) 	struct ahd_initiator_tinfo *tinfo 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) 		= ahd_fetch_transinfo(ahd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) 				      starget->channel + 'A',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) 				      shost->this_id, starget->id, &tstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) 	struct ahd_devinfo devinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) 	unsigned int ppr_options = tinfo->goal.ppr_options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) 		& ~MSG_EXT_PPR_RTI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) 	unsigned int period = tinfo->goal.period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) 	unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) 	if ((ahd->features & AHD_RTI) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) #ifdef AHD_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) 		if ((ahd_debug & AHD_SHOW_DV) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) 			printk("%s: RTI not available\n", ahd_name(ahd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) #ifdef AHD_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) 	if ((ahd_debug & AHD_SHOW_DV) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) 		printk("%s: %s RTI\n", ahd_name(ahd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) 		       rti ? "enabling" : "disabling");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) 	if (rti && spi_max_width(starget))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) 		ppr_options |= MSG_EXT_PPR_RTI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) 	ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) 			    starget->channel + 'A', ROLE_INITIATOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) 	ahd_find_syncrate(ahd, &period, &ppr_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) 			  dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) 	ahd_lock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) 	ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) 			 ppr_options, AHD_TRANS_GOAL, FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) 	ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) static void ahd_linux_set_pcomp_en(struct scsi_target *starget, int pcomp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) 	struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) 	struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) 	struct ahd_tmode_tstate *tstate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) 	struct ahd_initiator_tinfo *tinfo 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) 		= ahd_fetch_transinfo(ahd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) 				      starget->channel + 'A',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) 				      shost->this_id, starget->id, &tstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) 	struct ahd_devinfo devinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) 	unsigned int ppr_options = tinfo->goal.ppr_options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) 		& ~MSG_EXT_PPR_PCOMP_EN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) 	unsigned int period = tinfo->goal.period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) 	unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) #ifdef AHD_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) 	if ((ahd_debug & AHD_SHOW_DV) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) 		printk("%s: %s Precompensation\n", ahd_name(ahd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) 		       pcomp ? "Enable" : "Disable");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) 	if (pcomp && spi_max_width(starget)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) 		uint8_t precomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) 		if (ahd->unit < ARRAY_SIZE(aic79xx_iocell_info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) 			const struct ahd_linux_iocell_opts *iocell_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) 			iocell_opts = &aic79xx_iocell_info[ahd->unit];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) 			precomp = iocell_opts->precomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) 			precomp = AIC79XX_DEFAULT_PRECOMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) 		ppr_options |= MSG_EXT_PPR_PCOMP_EN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) 		AHD_SET_PRECOMP(ahd, precomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) 		AHD_SET_PRECOMP(ahd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) 	ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) 			    starget->channel + 'A', ROLE_INITIATOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) 	ahd_find_syncrate(ahd, &period, &ppr_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) 			  dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) 	ahd_lock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) 	ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) 			 ppr_options, AHD_TRANS_GOAL, FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) 	ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) static void ahd_linux_set_hold_mcs(struct scsi_target *starget, int hold)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) 	struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) 	struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) 	struct ahd_tmode_tstate *tstate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) 	struct ahd_initiator_tinfo *tinfo 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) 		= ahd_fetch_transinfo(ahd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) 				      starget->channel + 'A',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) 				      shost->this_id, starget->id, &tstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) 	struct ahd_devinfo devinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) 	unsigned int ppr_options = tinfo->goal.ppr_options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) 		& ~MSG_EXT_PPR_HOLD_MCS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) 	unsigned int period = tinfo->goal.period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) 	unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) 	if (hold && spi_max_width(starget))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) 		ppr_options |= MSG_EXT_PPR_HOLD_MCS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) 	ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) 			    starget->channel + 'A', ROLE_INITIATOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) 	ahd_find_syncrate(ahd, &period, &ppr_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) 			  dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) 	ahd_lock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) 	ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) 			 ppr_options, AHD_TRANS_GOAL, FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) 	ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) static void ahd_linux_get_signalling(struct Scsi_Host *shost)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) 	struct ahd_softc *ahd = *(struct ahd_softc **)shost->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) 	u8 mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) 	ahd_lock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) 	ahd_pause(ahd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) 	mode = ahd_inb(ahd, SBLKCTL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) 	ahd_unpause(ahd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) 	ahd_unlock(ahd, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) 	if (mode & ENAB40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) 		spi_signalling(shost) = SPI_SIGNAL_LVD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) 	else if (mode & ENAB20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) 		spi_signalling(shost) = SPI_SIGNAL_SE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) 		spi_signalling(shost) = SPI_SIGNAL_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) static struct spi_function_template ahd_linux_transport_functions = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) 	.set_offset	= ahd_linux_set_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) 	.show_offset	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) 	.set_period	= ahd_linux_set_period,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) 	.show_period	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) 	.set_width	= ahd_linux_set_width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) 	.show_width	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) 	.set_dt		= ahd_linux_set_dt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) 	.show_dt	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) 	.set_iu		= ahd_linux_set_iu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) 	.show_iu	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) 	.set_qas	= ahd_linux_set_qas,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) 	.show_qas	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) 	.set_rd_strm	= ahd_linux_set_rd_strm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) 	.show_rd_strm	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) 	.set_wr_flow	= ahd_linux_set_wr_flow,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) 	.show_wr_flow	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) 	.set_rti	= ahd_linux_set_rti,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) 	.show_rti	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) 	.set_pcomp_en	= ahd_linux_set_pcomp_en,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) 	.show_pcomp_en	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) 	.set_hold_mcs	= ahd_linux_set_hold_mcs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) 	.show_hold_mcs	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) 	.get_signalling = ahd_linux_get_signalling,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) ahd_linux_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) 	int	error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) 	 * If we've been passed any parameters, process them now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) 	if (aic79xx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) 		aic79xx_setup(aic79xx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) 	ahd_linux_transport_template =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) 		spi_attach_transport(&ahd_linux_transport_functions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) 	if (!ahd_linux_transport_template)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) 	scsi_transport_reserve_device(ahd_linux_transport_template,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) 				      sizeof(struct ahd_linux_device));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) 	error = ahd_linux_pci_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) 		spi_release_transport(ahd_linux_transport_template);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) static void __exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) ahd_linux_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) 	ahd_linux_pci_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) 	spi_release_transport(ahd_linux_transport_template);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) module_init(ahd_linux_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) module_exit(ahd_linux_exit);