/* * Adaptec AIC79xx device driver for Linux. * * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic79xx_osm.c#171 $ * * -------------------------------------------------------------------------- * Copyright (c) 1994-2000 Justin T. Gibbs. * Copyright (c) 1997-1999 Doug Ledford * Copyright (c) 2000-2003 Adaptec Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer * substantially similar to the "NO WARRANTY" disclaimer below * ("Disclaimer") and any redistribution must be conditioned upon * including a substantially similar Disclaimer requirement for further * binary redistribution. * 3. Neither the names of the above-listed copyright holders nor the names * of any contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES.
*/
#include <linux/init.h> /* __setup */ #include <linux/mm.h> /* For fetching system memory size */ #include <linux/blkdev.h> /* For block_size() */ #include <linux/delay.h> /* For ssleep/msleep */ #include <linux/device.h> #include <linux/slab.h>
/* * Bucket size for counting good commands in between bad ones.
*/ #define AHD_LINUX_ERR_THRESH 1000
/* * Set this to the delay in seconds after SCSI bus reset. * Note, we honor this only for the initial bus reset. * The scsi error recovery code performs its own bus settle * delay handling for error recovery actions.
*/ #ifdef CONFIG_AIC79XX_RESET_DELAY_MS #define AIC79XX_RESET_DELAY CONFIG_AIC79XX_RESET_DELAY_MS #else #define AIC79XX_RESET_DELAY 5000 #endif
/* * To change the default number of tagged transactions allowed per-device, * add a line to the lilo.conf file like: * append="aic79xx=verbose,tag_info:{{32,32,32,32},{32,32,32,32}}" * which will result in the first four devices on the first two * controllers being set to a tagged queue depth of 32. * * The tag_commands is an array of 16 to allow for wide and twin adapters. * Twin adapters will use indexes 0-7 for channel 0, and indexes 8-15 * for channel 1.
*/ typedefstruct {
uint16_t tag_commands[16]; /* Allow for wide/twin adapters. */
} adapter_tag_info_t;
/* * Modify this as you see fit for your system. * * 0 tagged queuing disabled * 1 <= n <= 253 n == max tags ever dispatched. * * The driver will throttle the number of commands dispatched to a * device if it returns queue full. For devices with a fixed maximum * queue depth, the driver will eventually determine this depth and * lock it in (a console message is printed to indicate that a lock * has occurred). On some devices, queue full is returned for a temporary * resource shortage. These devices will return queue full at varying * depths. The driver will throttle back when the queue fulls occur and * attempt to slowly increase the depth over time as the device recovers * from the resource shortage. * * In this example, the first line will disable tagged queueing for all * the devices on the first probed aic79xx adapter. * * The second line enables tagged queueing with 4 commands/LUN for IDs * (0, 2-11, 13-15), disables tagged queueing for ID 12, and tells the * driver to attempt to use up to 64 tags for ID 1. * * The third line is the same as the first line. * * The fourth line disables tagged queueing for devices 0 and 3. It * enables tagged queueing for the other IDs, with 16 commands/LUN * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for * IDs 2, 5-7, and 9-15.
*/
/* * NOTE: The below structure is for reference only, the actual structure * to modify in order to change things is just below this comment block. adapter_tag_info_t aic79xx_tag_info[] = { {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, {{4, 64, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4}}, {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, {{0, 16, 4, 0, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}} };
*/
/* * XXX - these options apply unilaterally to _all_ adapters * cards in the system. This should be fixed. Exceptions to this * rule are noted in the comments.
*/
/* * Skip the scsi bus reset. Non 0 make us skip the reset at startup. This * has no effect on any later resets that might occur due to things like * SCSI bus timeouts.
*/ static uint32_t aic79xx_no_reset;
/* * Should we force EXTENDED translation on a controller. * 0 == Use whatever is in the SEEPROM or default to off * 1 == Use whatever is in the SEEPROM or default to on
*/ static uint32_t aic79xx_extended;
/* * PCI bus parity checking of the Adaptec controllers. This is somewhat * dubious at best. To my knowledge, this option has never actually * solved a PCI parity problem, but on certain machines with broken PCI * chipset configurations, it can generate tons of false error messages. * It's included in the driver for completeness. * 0 = Shut off PCI parity check * non-0 = Enable PCI parity check * * NOTE: you can't actually pass -1 on the lilo prompt. So, to set this * variable to -1 you would actually want to simply pass the variable * name without a number. That will invert the 0 which will result in * -1.
*/ static uint32_t aic79xx_pci_parity = ~0;
/* * There are lots of broken chipsets in the world. Some of them will * violate the PCI spec when we issue byte sized memory writes to our * controller. I/O mapped register access, if allowed by the given * platform, will work in almost all cases.
*/
uint32_t aic79xx_allow_memio = ~0;
/* * So that we can set how long each device is given as a selection timeout. * The table of values goes like this: * 0 - 256ms * 1 - 128ms * 2 - 64ms * 3 - 32ms * We default to 256ms because some older devices need a longer time * to respond to initial selection.
*/ static uint32_t aic79xx_seltime;
/* * Certain devices do not perform any aging on commands. Should the * device be saturated by commands in one portion of the disk, it is * possible for transactions on far away sectors to never be serviced. * To handle these devices, we can periodically send an ordered tag to * force all outstanding transactions to be serviced prior to a new * transaction.
*/ static uint32_t aic79xx_periodic_otag;
/* Some storage boxes are using an LSI chip which has a bug making it * impossible to use aic79xx Rev B chip in 320 speeds. The following * storage boxes have been reported to be buggy: * EonStor 3U 16-Bay: U16U-G3A3 * EonStor 2U 12-Bay: U12U-G3A3 * SentinelRAID: 2500F R5 / R6 * SentinelRAID: 2500F R1 * SentinelRAID: 2500F/1500F * SentinelRAID: 150F * * To get around this LSI bug, you can set your board to 160 mode * or you can enable the SLOWCRC bit.
*/
uint32_t aic79xx_slowcrc;
/* * Module information and settable options.
*/ staticchar *aic79xx = NULL;
MODULE_AUTHOR("Maintainer: Hannes Reinecke <hare@suse.de>");
MODULE_DESCRIPTION("Adaptec AIC790X U320 SCSI Host Bus Adapter driver");
MODULE_LICENSE("Dual BSD/GPL");
MODULE_VERSION(AIC79XX_DRIVER_VERSION);
module_param(aic79xx, charp, 0444);
MODULE_PARM_DESC(aic79xx, "period-delimited options string:\n" " verbose Enable verbose/diagnostic logging\n" " allow_memio Allow device registers to be memory mapped\n" " debug Bitmask of debug values to enable\n" " no_reset Suppress initial bus resets\n" " extended Enable extended geometry on all controllers\n" " periodic_otag Send an ordered tagged transaction\n" " periodically to prevent tag starvation.\n" " This may be required by some older disk\n" " or drives/RAID arrays.\n" " tag_info:<tag_str> Set per-target tag depth\n" " global_tag_depth:<int> Global tag depth for all targets on all buses\n" " slewrate:<slewrate_list>Set the signal slew rate (0-15).\n" " precomp:<pcomp_list> Set the signal precompensation (0-7).\n" " amplitude:<int> Set the signal amplitude (0-7).\n" " seltime:<int> Selection Timeout:\n" " (0/256ms,1/128ms,2/64ms,3/32ms)\n" " slowcrc Turn on the SLOWCRC bit (Rev B only)\n" "\n" " Sample modprobe configuration file:\n" " # Enable verbose logging\n" " # Set tag depth on Controller 2/Target 2 to 10 tags\n" " # Shorten the selection timeout to 128ms\n" "\n" " options aic79xx 'aic79xx=verbose.tag_info:{{}.{}.{..10}}.seltime:1'\n"
);
/************************** OS Utility Wrappers *******************************/ void ahd_delay(long); void
ahd_delay(long usec)
{ /* * udelay on Linux can have problems for * multi-millisecond waits. Wait at most * 1024us per call.
*/ while (usec > 0) {
udelay(usec % 1024);
usec -= 1024;
}
}
/***************************** Low Level I/O **********************************/
uint8_t ahd_inb(struct ahd_softc * ahd, long port); void ahd_outb(struct ahd_softc * ahd, long port, uint8_t val); void ahd_outw_atomic(struct ahd_softc * ahd, long port, uint16_t val); void ahd_outsb(struct ahd_softc * ahd, long port,
uint8_t *, int count); void ahd_insb(struct ahd_softc * ahd, long port,
uint8_t *, int count);
uint8_t
ahd_inb(struct ahd_softc * ahd, long port)
{
uint8_t x;
if (ahd->tags[0] == BUS_SPACE_MEMIO) {
x = readb(ahd->bshs[0].maddr + port);
} else {
x = inb(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
}
mb(); return (x);
}
void
ahd_outsb(struct ahd_softc * ahd, long port, uint8_t *array, int count)
{ int i;
/* * There is probably a more efficient way to do this on Linux * but we don't use this for anything speed critical and this * should work.
*/ for (i = 0; i < count; i++)
ahd_outb(ahd, port, *array++);
}
void
ahd_insb(struct ahd_softc * ahd, long port, uint8_t *array, int count)
{ int i;
/* * There is probably a more efficient way to do this on Linux * but we don't use this for anything speed critical and this * should work.
*/ for (i = 0; i < count; i++)
*array++ = ahd_inb(ahd, port);
}
/******************************* PCI Routines *********************************/
uint32_t
ahd_pci_read_config(ahd_dev_softc_t pci, int reg, int width)
{ switch (width) { case 1:
{
uint8_t retval;
/* Initial Domain Validation */ if (!spi_initial_dv(sdev->sdev_target))
spi_dv_device(sdev);
return 0;
}
#ifdefined(__i386__) /* * Return the disk geometry for the given SCSI device.
*/ staticint
ahd_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
sector_t capacity, int geom[])
{ int heads; int sectors; int cylinders; int extended; struct ahd_softc *ahd;
ahd = *((struct ahd_softc **)sdev->host->hostdata);
if (scsi_partsize(bdev, capacity, geom)) return 0;
/* * Determine if we currently own this command.
*/
dev = scsi_transport_device_data(cmd->device);
if (dev == NULL) { /* * No target device for this command exists, * so we must not still own the command.
*/
scmd_printk(KERN_INFO, cmd, "Is not an active device\n"); return SUCCESS;
}
/* * Generate us a new SCB
*/
reset_scb = ahd_get_scb(ahd, AHD_NEVER_COL_IDX); if (!reset_scb) {
scmd_printk(KERN_INFO, cmd, "No SCB available\n"); return FAILED;
}
/* * Reset the SCSI bus.
*/ staticint
ahd_linux_bus_reset(struct scsi_cmnd *cmd)
{ struct ahd_softc *ahd; int found; unsignedlong flags;
ahd = *(struct ahd_softc **)cmd->device->host->hostdata; #ifdef AHD_DEBUG if ((ahd_debug & AHD_SHOW_RECOVERY) != 0)
printk("%s: Bus reset called for cmd %p\n",
ahd_name(ahd), cmd); #endif
ahd_lock(ahd, &flags);
found = ahd_reset_channel(ahd, scmd_channel(cmd) + 'A', /*initiate reset*/TRUE);
ahd_unlock(ahd, &flags);
if (bootverbose)
printk("%s: SCSI bus reset delivered. " "%d SCBs aborted.\n", ahd_name(ahd), found);
/******************************** Bus DMA *************************************/ int
ahd_dma_tag_create(struct ahd_softc *ahd, bus_dma_tag_t parent,
bus_size_t alignment, bus_size_t boundary,
dma_addr_t lowaddr, dma_addr_t highaddr,
bus_dma_filter_t *filter, void *filterarg,
bus_size_t maxsize, int nsegments,
bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag)
{
bus_dma_tag_t dmat;
dmat = kmalloc(sizeof(*dmat), GFP_ATOMIC); if (dmat == NULL) return (ENOMEM);
/* * Linux is very simplistic about DMA memory. For now don't * maintain all specification information. Once Linux supplies * better facilities for doing these operations, or the * needs of this particular driver change, we might need to do * more here.
*/
dmat->alignment = alignment;
dmat->boundary = boundary;
dmat->maxsize = maxsize;
*ret_tag = dmat; return (0);
}
int
ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map, void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb, void *cb_arg, int flags)
{ /* * Assume for now that this will only be used during * initialization and not for per-transaction buffer mapping.
*/
bus_dma_segment_t stack_sg;
staticchar *
ahd_parse_brace_option(char *opt_name, char *opt_arg, char *end, int depth, void (*callback)(u_long, int, int, int32_t),
u_long callback_arg)
{ char *tok_end; char *tok_end2; int i; int instance; int targ; int done; char tok_list[] = {'.', ',', '{', '}', '\0'};
/* All options use a ':' name/arg separator */ if (*opt_arg != ':') return (opt_arg);
opt_arg++;
instance = -1;
targ = -1;
done = FALSE; /* * Restore separator that may be in * the middle of our option argument.
*/
tok_end = strchr(opt_arg, '\0'); if (tok_end < end)
*tok_end = ','; while (!done) { switch (*opt_arg) { case'{': if (instance == -1) {
instance = 0;
} else { if (depth > 1) { if (targ == -1)
targ = 0;
} else {
printk("Malformed Option %s\n",
opt_name);
done = TRUE;
}
}
opt_arg++; break; case'}': if (targ != -1)
targ = -1; elseif (instance != -1)
instance = -1;
opt_arg++; break; case',': case'.': if (instance == -1)
done = TRUE; elseif (targ >= 0)
targ++; elseif (instance >= 0)
instance++;
opt_arg++; break; case'\0':
done = TRUE; break; default:
tok_end = end; for (i = 0; tok_list[i]; i++) {
tok_end2 = strchr(opt_arg, tok_list[i]); if ((tok_end2) && (tok_end2 < tok_end))
tok_end = tok_end2;
}
callback(callback_arg, instance, targ,
simple_strtol(opt_arg, NULL, 0));
opt_arg = tok_end; break;
}
} return (opt_arg);
}
/* * Handle Linux boot parameters. This routine allows for assigning a value * to a parameter with a ':' between the parameter and the value. * ie. aic79xx=stpwlev:1,extended
*/ staticint
aic79xx_setup(char *s)
{ int i, n; char *p; char *end;
/* * Place the SCSI bus into a known state by either resetting it, * or forcing transfer negotiations on the next command to any * target.
*/ staticvoid
ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd)
{
u_int target_id;
u_int numtarg; unsignedlong s;
target_id = 0;
numtarg = 0;
if (aic79xx_no_reset != 0)
ahd->flags &= ~AHD_RESET_BUS_A;
/* * Force negotiation to async for all targets that * will not see an initial bus reset.
*/ for (; target_id < numtarg; target_id++) { struct ahd_devinfo devinfo; struct ahd_initiator_tinfo *tinfo; struct ahd_tmode_tstate *tstate;
tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
target_id, &tstate);
ahd_compile_devinfo(&devinfo, ahd->our_id, target_id,
CAM_LUN_WILDCARD, 'A', ROLE_INITIATOR);
ahd_update_neg_request(ahd, &devinfo, tstate,
tinfo, AHD_NEG_ALWAYS);
}
ahd_unlock(ahd, &s); /* Give the bus some time to recover */ if ((ahd->flags & AHD_RESET_BUS_A) != 0) {
ahd_freeze_simq(ahd);
msleep(AIC79XX_RESET_DELAY);
ahd_release_simq(ahd);
}
}
void
ahd_platform_free(struct ahd_softc *ahd)
{ struct scsi_target *starget; int i;
if (ahd->platform_data != NULL) { /* destroy all of the device and target objects */ for (i = 0; i < AHD_NUM_TARGETS; i++) {
starget = ahd->platform_data->starget[i]; if (starget != NULL) {
ahd->platform_data->starget[i] = NULL;
}
}
if (ahd->platform_data->irq != AHD_LINUX_NOIRQ)
free_irq(ahd->platform_data->irq, ahd); if (ahd->tags[0] == BUS_SPACE_PIO
&& ahd->bshs[0].ioport != 0)
release_region(ahd->bshs[0].ioport, 256); if (ahd->tags[1] == BUS_SPACE_PIO
&& ahd->bshs[1].ioport != 0)
release_region(ahd->bshs[1].ioport, 256); if (ahd->tags[0] == BUS_SPACE_MEMIO
&& ahd->bshs[0].maddr != NULL) {
iounmap(ahd->bshs[0].maddr);
release_mem_region(ahd->platform_data->mem_busaddr,
0x1000);
} if (ahd->platform_data->host)
scsi_host_put(ahd->platform_data->host);
kfree(ahd->platform_data);
}
}
void
ahd_platform_init(struct ahd_softc *ahd)
{ /* * Lookup and commit any modified IO Cell options.
*/ if (ahd->unit < ARRAY_SIZE(aic79xx_iocell_info)) { conststruct ahd_linux_iocell_opts *iocell_opts;
iocell_opts = &aic79xx_iocell_info[ahd->unit]; if (iocell_opts->precomp != AIC79XX_DEFAULT_PRECOMP)
AHD_SET_PRECOMP(ahd, iocell_opts->precomp); if (iocell_opts->slewrate != AIC79XX_DEFAULT_SLEWRATE)
AHD_SET_SLEWRATE(ahd, iocell_opts->slewrate); if (iocell_opts->amplitude != AIC79XX_DEFAULT_AMPLITUDE)
AHD_SET_AMPLITUDE(ahd, iocell_opts->amplitude);
}
dev->flags &= ~(AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED|AHD_DEV_PERIODIC_OTAG); if (now_queuing) {
u_int usertags;
usertags = ahd_linux_user_tagdepth(ahd, devinfo); if (!was_queuing) { /* * Start out aggressively and allow our * dynamic queue depth algorithm to take * care of the rest.
*/
dev->maxtags = usertags;
dev->openings = dev->maxtags - dev->active;
} if (dev->maxtags == 0) { /* * Queueing is disabled by the user.
*/
dev->openings = 1;
} elseif (alg == AHD_QUEUE_TAGGED) {
dev->flags |= AHD_DEV_Q_TAGGED; if (aic79xx_periodic_otag != 0)
dev->flags |= AHD_DEV_PERIODIC_OTAG;
} else
dev->flags |= AHD_DEV_Q_BASIC;
} else { /* We can only have one opening. */
dev->maxtags = 0;
dev->openings = 1 - dev->active;
}
switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) { case AHD_DEV_Q_BASIC: case AHD_DEV_Q_TAGGED:
scsi_change_queue_depth(sdev,
dev->openings + dev->active); break; default: /* * We allow the OS to queue 2 untagged transactions to * us at any time even though we can only execute them * serially on the controller/device. This should * remove some latency.
*/
scsi_change_queue_depth(sdev, 1); break;
}
}
int
ahd_platform_abort_scbs(struct ahd_softc *ahd, int target, char channel, int lun, u_int tag, role_t role, uint32_t status)
{ return 0;
}
/* * Don't bother reporting results while * negotiations are still pending.
*/ if (tinfo->curr.period != tinfo->goal.period
|| tinfo->curr.width != tinfo->goal.width
|| tinfo->curr.offset != tinfo->goal.offset
|| tinfo->curr.ppr_options != tinfo->goal.ppr_options) if (bootverbose == 0) break;
/* * Don't bother reporting results that * are identical to those last reported.
*/
starget = ahd->platform_data->starget[target]; if (starget == NULL) break;
/* * Guard against stale sense data. * The Linux mid-layer assumes that sense * was retrieved anytime the first byte of * the sense buffer looks "sane".
*/
cmd->sense_buffer[0] = 0; if (ahd_get_transaction_status(scb) == CAM_REQ_INPROG) { #ifdef AHD_REPORT_UNDERFLOWS
uint32_t amount_xferred;
amount_xferred =
ahd_get_transfer_length(scb) - ahd_get_residual(scb); #endif if ((scb->flags & SCB_TRANSMISSION_ERROR) != 0) { #ifdef AHD_DEBUG if ((ahd_debug & AHD_SHOW_MISC) != 0) {
ahd_print_path(ahd, scb);
printk("Set CAM_UNCOR_PARITY\n");
} #endif
ahd_set_transaction_status(scb, CAM_UNCOR_PARITY); #ifdef AHD_REPORT_UNDERFLOWS /* * This code is disabled by default as some * clients of the SCSI system do not properly * initialize the underflow parameter. This * results in spurious termination of commands * that complete as expected (e.g. underflow is * allowed as command can return variable amounts * of data.
*/
} elseif (amount_xferred < scb->io_ctx->underflow) {
u_int i;
ahd_print_path(ahd, scb);
printk("CDB:"); for (i = 0; i < scb->io_ctx->cmd_len; i++)
printk(" 0x%x", scb->io_ctx->cmnd[i]);
printk("\n");
ahd_print_path(ahd, scb);
printk("Saw underflow (%ld of %ld bytes). " "Treated as error\n",
ahd_get_residual(scb),
ahd_get_transfer_length(scb));
ahd_set_transaction_status(scb, CAM_DATA_RUN_ERR); #endif
} else {
ahd_set_transaction_status(scb, CAM_REQ_CMP);
}
} elseif (cmd &&
ahd_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) {
ahd_linux_handle_scsi_status(ahd, cmd->device, scb);
}
if (dev->openings == 1
&& ahd_get_transaction_status(scb) == CAM_REQ_CMP
&& ahd_get_scsi_status(scb) != SAM_STAT_TASK_SET_FULL)
dev->tag_success_count++; /* * Some devices deal with temporary internal resource * shortages by returning queue full. When the queue * full occurrs, we throttle back. Slowly try to get * back to our previous queue depth.
*/ if ((dev->openings + dev->active) < dev->maxtags
&& dev->tag_success_count > AHD_TAG_SUCCESS_INTERVAL) {
dev->tag_success_count = 0;
dev->openings++;
}
if (dev->active == 0)
dev->commands_since_idle_or_otag = 0;
if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
printk("Recovery SCB completes\n"); if (ahd_get_transaction_status(scb) == CAM_BDR_SENT
|| ahd_get_transaction_status(scb) == CAM_REQ_ABORTED)
ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT);
if (ahd->platform_data->eh_done)
complete(ahd->platform_data->eh_done);
}
ahd_free_scb(ahd, scb); if (cmd)
ahd_linux_queue_cmd_complete(ahd, cmd);
}
/* * We don't currently trust the mid-layer to * properly deal with queue full or busy. So, * when one occurs, we tell the mid-layer to * unconditionally requeue the command to us * so that we can retry it ourselves. We also * implement our own throttling mechanism so * we don't clobber the device with too many * commands.
*/ switch (ahd_get_scsi_status(scb)) { default: break; case SAM_STAT_CHECK_CONDITION: case SAM_STAT_COMMAND_TERMINATED:
{ struct scsi_cmnd *cmd;
/* * Copy sense information to the OS's cmd * structure if it is available.
*/
cmd = scb->io_ctx; if ((scb->flags & (SCB_SENSE|SCB_PKT_SENSE)) != 0) { struct scsi_status_iu_header *siu;
u_int sense_size;
u_int sense_offset;
if (scb->flags & SCB_SENSE) {
sense_size = min(sizeof(struct scsi_sense_data)
- ahd_get_sense_residual(scb),
(u_long)SCSI_SENSE_BUFFERSIZE);
sense_offset = 0;
} else { /* * Copy only the sense data into the provided * buffer.
*/
siu = (struct scsi_status_iu_header *)
scb->sense_data;
sense_size = min_t(size_t,
scsi_4btoul(siu->sense_length),
SCSI_SENSE_BUFFERSIZE);
sense_offset = SIU_SENSE_OFFSET(siu);
}
#ifdef AHD_DEBUG if (ahd_debug & AHD_SHOW_SENSE) { int i;
printk("Copied %d bytes of sense data at %d:",
sense_size, sense_offset); for (i = 0; i < sense_size; i++) { if ((i & 0xF) == 0)
printk("\n");
printk("0x%x ", cmd->sense_buffer[i]);
}
printk("\n");
} #endif
} break;
} case SAM_STAT_TASK_SET_FULL: /* * By the time the core driver has returned this * command, all other commands that were queued * to us but not the device have been returned. * This ensures that dev->active is equal to * the number of commands actually queued to * the device.
*/
dev->tag_success_count = 0; if (dev->active != 0) { /* * Drop our opening count to the number * of commands currently outstanding.
*/
dev->openings = 0; #ifdef AHD_DEBUG if ((ahd_debug & AHD_SHOW_QFULL) != 0) {
ahd_print_path(ahd, scb);
printk("Dropping tag count to %d\n",
dev->active);
} #endif if (dev->active == dev->tags_on_last_queuefull) {
dev->last_queuefull_same_count++; /* * If we repeatedly see a queue full * at the same queue depth, this * device has a fixed number of tag * slots. Lock in this tag depth * so we stop seeing queue fulls from * this device.
*/ if (dev->last_queuefull_same_count
== AHD_LOCK_TAGS_COUNT) {
dev->maxtags = dev->active;
ahd_print_path(ahd, scb);
printk("Locking max tag count at %d\n",
dev->active);
}
} else {
dev->tags_on_last_queuefull = dev->active;
dev->last_queuefull_same_count = 0;
}
ahd_set_transaction_status(scb, CAM_REQUEUE_REQ);
ahd_set_scsi_status(scb, SAM_STAT_GOOD);
ahd_platform_set_tags(ahd, sdev, &devinfo,
(dev->flags & AHD_DEV_Q_BASIC)
? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED); break;
} /* * Drop down to a single opening, and treat this * as if the target returned BUSY SCSI status.
*/
dev->openings = 1;
ahd_platform_set_tags(ahd, sdev, &devinfo,
(dev->flags & AHD_DEV_Q_BASIC)
? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED);
ahd_set_scsi_status(scb, SAM_STAT_BUSY);
}
}
staticvoid
ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, struct scsi_cmnd *cmd)
{ int status; int new_status = DID_OK; int do_fallback = 0; int scsi_status; struct scsi_sense_data *sense;
/* * Map CAM error codes into Linux Error codes. We * avoid the conversion so that the DV code has the * full error information available when making * state change decisions.
*/
status = ahd_cmd_get_transaction_status(cmd); switch (status) { case CAM_REQ_INPROG: case CAM_REQ_CMP:
new_status = DID_OK; break; case CAM_AUTOSENSE_FAIL:
new_status = DID_ERROR;
fallthrough; case CAM_SCSI_STATUS_ERROR:
scsi_status = ahd_cmd_get_scsi_status(cmd);
switch(scsi_status) { case SAM_STAT_COMMAND_TERMINATED: case SAM_STAT_CHECK_CONDITION:
sense = (struct scsi_sense_data *)
cmd->sense_buffer; if (sense->extra_len >= 5 &&
(sense->add_sense_code == 0x47
|| sense->add_sense_code == 0x48))
do_fallback = 1; break; default: break;
} break; case CAM_REQ_ABORTED:
new_status = DID_ABORT; break; case CAM_BUSY:
new_status = DID_BUS_BUSY; break; case CAM_REQ_INVALID: case CAM_PATH_INVALID:
new_status = DID_BAD_TARGET; break; case CAM_SEL_TIMEOUT:
new_status = DID_NO_CONNECT; break; case CAM_SCSI_BUS_RESET: case CAM_BDR_SENT:
new_status = DID_RESET; break; case CAM_UNCOR_PARITY:
new_status = DID_PARITY;
do_fallback = 1; break; case CAM_CMD_TIMEOUT:
new_status = DID_TIME_OUT;
do_fallback = 1; break; case CAM_REQ_CMP_ERR: case CAM_UNEXP_BUSFREE: case CAM_DATA_RUN_ERR:
new_status = DID_ERROR;
do_fallback = 1; break; case CAM_UA_ABORT: case CAM_NO_HBA: case CAM_SEQUENCE_FAIL: case CAM_CCB_LEN_ERR: case CAM_PROVIDE_FAIL: case CAM_REQ_TERMIO: case CAM_UNREC_HBA_ERROR: case CAM_REQ_TOO_BIG:
new_status = DID_ERROR; break; case CAM_REQUEUE_REQ:
new_status = DID_REQUEUE; break; default: /* We should never get here */
new_status = DID_ERROR; break;
}
if (do_fallback) {
printk("%s: device overrun (status %x) on %d:%d:%d\n",
ahd_name(ahd), status, cmd->device->channel,
cmd->device->id, (u8)cmd->device->lun);
}
/* * First determine if we currently own this command. * Start by searching the device queue. If not found * there, check the pending_scb list. If not found * at all, and the system wanted us to just abort the * command, return success.
*/
dev = scsi_transport_device_data(cmd->device);
if (dev == NULL) { /* * No target device for this command exists, * so we must not still own the command.
*/
scmd_printk(KERN_INFO, cmd, "Is not an active device\n"); goto done;
}
/* * See if we can find a matching cmd in the pending list.
*/
LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) { if (pending_scb->io_ctx == cmd) break;
}
if (pending_scb == NULL) {
scmd_printk(KERN_INFO, cmd, "Command not found\n"); goto done;
}
if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) { /* * We can't queue two recovery actions using the same SCB
*/
retval = FAILED; goto done;
}
/* * Ensure that the card doesn't do anything * behind our back. Also make sure that we * didn't "just" miss an interrupt that would * affect this cmd.
*/
was_paused = ahd_is_paused(ahd);
ahd_pause_and_flushwork(ahd);
paused = TRUE;
/* * At this point, pending_scb is the scb associated with the * passed in command. That command is currently active on the * bus or is in the disconnected state.
*/
ahd_inb(ahd, SAVED_SCSIID); if (last_phase != P_BUSFREE
&& SCB_GET_TAG(pending_scb) == active_scbptr) {
/* * We're active on the bus, so assert ATN * and hope that the target responds.
*/
pending_scb = ahd_lookup_scb(ahd, active_scbptr);
pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT;
ahd_outb(ahd, MSG_OUT, HOST_MSG);
ahd_outb(ahd, SCSISIGO, last_phase|ATNO);
scmd_printk(KERN_INFO, cmd, "Device is active, asserting ATN\n");
wait = TRUE;
} elseif (disconnected) {
/* * Actually re-queue this SCB in an attempt * to select the device before it reconnects.
*/
pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT;
ahd_set_scbptr(ahd, SCB_GET_TAG(pending_scb));
pending_scb->hscb->cdb_len = 0;
pending_scb->hscb->task_attribute = 0;
pending_scb->hscb->task_management = SIU_TASKMGMT_ABORT_TASK;
if ((pending_scb->flags & SCB_PACKETIZED) != 0) { /* * Mark the SCB has having an outstanding * task management function. Should the command * complete normally before the task management * function can be sent, the host will be notified * to abort our requeued SCB.
*/
ahd_outb(ahd, SCB_TASK_MANAGEMENT,
pending_scb->hscb->task_management);
} else { /* * If non-packetized, set the MK_MESSAGE control * bit indicating that we desire to send a message. * We also set the disconnected flag since there is * no guarantee that our SCB control byte matches * the version on the card. We don't want the * sequencer to abort the command thinking an * unsolicited reselection occurred.
*/
pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED;
/* * The sequencer will never re-reference the * in-core SCB. To make sure we are notified * during reselection, set the MK_MESSAGE flag in * the card's copy of the SCB.
*/
ahd_outb(ahd, SCB_CONTROL,
ahd_inb(ahd, SCB_CONTROL)|MK_MESSAGE);
}
/* * Clear out any entries in the QINFIFO first * so we are the next SCB for this target * to run.
*/
ahd_search_qinfifo(ahd, cmd->device->id,
cmd->device->channel + 'A', cmd->device->lun,
SCB_LIST_NULL, ROLE_INITIATOR,
CAM_REQUEUE_REQ, SEARCH_COMPLETE);
ahd_qinfifo_requeue_tail(ahd, pending_scb);
ahd_set_scbptr(ahd, saved_scbptr);
ahd_print_path(ahd, pending_scb);
printk("Device is disconnected, re-queuing SCB\n");
wait = TRUE;
} else {
scmd_printk(KERN_INFO, cmd, "Unable to deliver message\n");
retval = FAILED;
}
ahd_restore_modes(ahd, saved_modes);
done: if (paused)
ahd_unpause(ahd); if (wait) {
DECLARE_COMPLETION_ONSTACK(done);
#ifdef AHD_DEBUG if ((ahd_debug & AHD_SHOW_DV) != 0)
printk("%s: set period to %d\n", ahd_name(ahd), period); #endif if (offset == 0)
offset = MAX_OFFSET;
if (period < 8)
period = 8; if (period < 10) { if (spi_max_width(starget)) {
ppr_options |= MSG_EXT_PPR_DT_REQ; if (period == 8)
ppr_options |= MSG_EXT_PPR_IU_REQ;
} else
period = 10;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.