📄 aic79xx_osm.c
字号:
/* * Adaptec AIC79xx device driver for Linux. * * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic79xx_osm.c#36 $ * * -------------------------------------------------------------------------- * Copyright (c) 1994-2000 Justin T. Gibbs. * Copyright (c) 1997-1999 Doug Ledford * Copyright (c) 2000-2002 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. *//* * This is the only file where module.h should * embed module global version info. */#define AHD_MODVERSION_FILE#include "aic79xx_osm.h"#include "aic79xx_inline.h"#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)#include <linux/init.h> /* __setup */#endif#include "../sd.h" /* For geometry detection */#include <linux/mm.h> /* For fetching system memory size */#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)/* * Lock protecting manipulation of the ahd softc list. */spinlock_t ahd_list_spinlock;#endif#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)struct proc_dir_entry proc_scsi_aic79xx = { PROC_SCSI_AIC79XX, 7, "aic79xx", S_IFDIR | S_IRUGO | S_IXUGO, 2, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL};#endif/* * 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. */typedef struct { 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}}};*/#ifdef CONFIG_AIC79XX_CMDS_PER_DEVICE#define AIC79XX_CMDS_PER_DEVICE CONFIG_AIC79XX_CMDS_PER_DEVICE#else#define AIC79XX_CMDS_PER_DEVICE AHD_MAX_QUEUE#endif#define AIC79XX_CONFIGED_TAG_COMMANDS { \ AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \ AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \ AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \ AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \ AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \ AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \ AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \ AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE \}/* * By default, use the number of commands specified by * the users kernel configuration. */static adapter_tag_info_t aic79xx_tag_info[] ={ {AIC79XX_CONFIGED_TAG_COMMANDS}, {AIC79XX_CONFIGED_TAG_COMMANDS}, {AIC79XX_CONFIGED_TAG_COMMANDS}, {AIC79XX_CONFIGED_TAG_COMMANDS}, {AIC79XX_CONFIGED_TAG_COMMANDS}, {AIC79XX_CONFIGED_TAG_COMMANDS}, {AIC79XX_CONFIGED_TAG_COMMANDS}, {AIC79XX_CONFIGED_TAG_COMMANDS}, {AIC79XX_CONFIGED_TAG_COMMANDS}, {AIC79XX_CONFIGED_TAG_COMMANDS}, {AIC79XX_CONFIGED_TAG_COMMANDS}, {AIC79XX_CONFIGED_TAG_COMMANDS}, {AIC79XX_CONFIGED_TAG_COMMANDS}, {AIC79XX_CONFIGED_TAG_COMMANDS}, {AIC79XX_CONFIGED_TAG_COMMANDS}, {AIC79XX_CONFIGED_TAG_COMMANDS}};/* * By default, read streaming is disabled. In theory, * read streaming should enhance performance, but early * U320 drive firmware actually performs slower with * read streaming enabled. */#ifdef CONFIG_AIC79XX_ENABLE_RD_STRM#define AIC79XX_CONFIGED_RD_STRM 0xFFFF#else#define AIC79XX_CONFIGED_RD_STRM 0#endifstatic uint16_t aic79xx_rd_strm_info[] ={ AIC79XX_CONFIGED_RD_STRM, AIC79XX_CONFIGED_RD_STRM, AIC79XX_CONFIGED_RD_STRM, AIC79XX_CONFIGED_RD_STRM, AIC79XX_CONFIGED_RD_STRM, AIC79XX_CONFIGED_RD_STRM, AIC79XX_CONFIGED_RD_STRM, AIC79XX_CONFIGED_RD_STRM, AIC79XX_CONFIGED_RD_STRM, AIC79XX_CONFIGED_RD_STRM, AIC79XX_CONFIGED_RD_STRM, AIC79XX_CONFIGED_RD_STRM, AIC79XX_CONFIGED_RD_STRM, AIC79XX_CONFIGED_RD_STRM, AIC79XX_CONFIGED_RD_STRM, AIC79XX_CONFIGED_RD_STRM};/* * There should be a specific return value for this in scsi.h, but * it seems that most drivers ignore it. */#define DID_UNDERFLOW DID_ERRORvoidahd_print_path(struct ahd_softc *ahd, struct scb *scb){ printk("(scsi%d:%c:%d:%d): ", ahd->platform_data->host->host_no, scb != NULL ? SCB_GET_CHANNEL(ahd, scb) : 'X', scb != NULL ? SCB_GET_TARGET(ahd, scb) : -1, scb != NULL ? SCB_GET_LUN(scb) : -1);}/* * 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;/* * Certain PCI motherboards will scan PCI devices from highest to lowest, * others scan from lowest to highest, and they tend to do all kinds of * strange things when they come into contact with PCI bridge chips. The * net result of all this is that the PCI card that is actually used to boot * the machine is very hard to detect. Most motherboards go from lowest * PCI slot number to highest, and the first SCSI controller found is the * one you boot from. The only exceptions to this are when a controller * has its BIOS disabled. So, we by default sort all of our SCSI controllers * from lowest PCI slot number to highest PCI slot number. We also force * all controllers with their BIOS disabled to the end of the list. This * works on *almost* all computers. Where it doesn't work, we have this * option. Setting this option to non-0 will reverse the order of the sort * to highest first, then lowest, but will still leave cards with their BIOS * disabled at the very end. That should fix everyone up unless there are * really strange cirumstances. */static int aic79xx_reverse_scan = 0;/* * 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 = 0;/* * 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 * -1 = Normal polarity pci parity checking * 1 = reverse polarity pci parity checking * * 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 int aic79xx_pci_parity = 0;/* * aic79xx_detect() has been run, so register all device arrivals * immediately with the system rather than deferring to the sorted * attachment performed by aic79xx_detect(). */int aic79xx_detect_complete;/* * 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 int aic79xx_seltime = 0x00;/* * 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. */int aic79xx_periodic_otag;/* * Module information and settable options. */#ifdef MODULEstatic char *aic79xx = NULL;/* * Just in case someone uses commas to separate items on the insmod * command line, we define a dummy buffer here to avoid having insmod * write wild stuff into our code segment */static char dummy_buffer[60] = "Please don't trounce on me insmod!!\n";MODULE_AUTHOR("Maintainer: Justin T. Gibbs <gibbs@scsiguy.com>");MODULE_DESCRIPTION("Adaptec Aic77XX/78XX SCSI Host Bus Adapter driver");#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,10)MODULE_LICENSE("Dual BSD/GPL");#endifMODULE_PARM(aic79xx, "s");MODULE_PARM_DESC(aic79xx, "period delimited, options string. verbose Enable verbose/diagnostic logging debug Bitmask of debug values to enable no_reset Supress initial bus resets extended Enable extended geometry on all controllers periodic_otag Send an ordered tagged transaction periodically to prevent tag starvation. This may be required by some older disk drives/RAID arrays. reverse_scan Sort PCI devices highest Bus/Slot to lowest tag_info:<tag_str> Set per-target tag depth rd_strm:<rd_strm_masks> Set per-target read streaming setting. seltime:<int> Selection Timeout(0/256ms,1/128ms,2/64ms,3/32ms) Sample /etc/modules.conf line: Enable verbose logging Set tag depth on Controller 2/Target 2 to 10 tags Shorten the selection timeout to 128ms from its default of 256 options aic79xx='\"verbose.tag_info:{{}.{}.{..10}}.seltime:1\"' Sample /etc/modules.conf line: Change Read Streaming for Controller's 2 and 3 options aic79xx='\"rd_strm:{..0xFFF0.0xC0F0}\"'");#endifstatic void ahd_linux_handle_scsi_status(struct ahd_softc *, struct ahd_linux_device *, struct scb *);static void ahd_linux_filter_command(struct ahd_softc*, Scsi_Cmnd*, struct scb*);static void ahd_linux_dev_timed_unfreeze(u_long arg);#if NO_YETstatic void ahd_linux_sem_timeout(u_long arg);static int ahd_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag);#endif static void ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd);static void ahd_linux_select_queue_depth(struct Scsi_Host *host, Scsi_Device *scsi_devs);static u_int ahd_linux_user_tagdepth(struct ahd_softc *ahd, struct ahd_devinfo *devinfo);static void ahd_linux_device_queue_depth(struct ahd_softc *ahd, Scsi_Device *device);static struct ahd_linux_target* ahd_linux_alloc_target(struct ahd_softc*, u_int, u_int);static void ahd_linux_free_target(struct ahd_softc*, struct ahd_linux_target*);static struct ahd_linux_device* ahd_linux_alloc_device(struct ahd_softc*, struct ahd_linux_target*, u_int);static void ahd_linux_free_device(struct ahd_softc*, struct ahd_linux_device*);static void ahd_linux_run_device_queue(struct ahd_softc*, struct ahd_linux_device*);static void ahd_linux_setup_tag_info(char *p, char *end);static void ahd_linux_setup_rd_strm_info(char *p, char *end);static int ahd_linux_next_unit(void);static void ahd_runq_tasklet(unsigned long data);static int ahd_linux_halt(struct notifier_block *nb, u_long event, void *buf);static __inline struct ahd_linux_device* ahd_linux_get_device(struct ahd_softc *ahd, u_int channel, u_int target, u_int lun, int alloc);static __inline void ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, Scsi_Cmnd *cmd);static __inline void ahd_linux_run_complete_queue(struct ahd_softc *ahd, struct ahd_cmd *acmd);static __inline void ahd_linux_check_device_queue(struct ahd_softc *ahd, struct ahd_linux_device *dev);static __inline struct ahd_linux_device * ahd_linux_next_device_to_run(struct ahd_softc *ahd);static __inline void ahd_linux_run_device_queues(struct ahd_softc *ahd);static __inline void ahd_linux_sniff_command(struct ahd_softc*, Scsi_Cmnd*, struct scb*);static __inline void ahd_linux_unmap_scb(struct ahd_softc*, struct scb*);static __inline int ahd_linux_map_seg(struct ahd_softc *ahd, struct scb *scb, struct ahd_dma_seg *sg, bus_addr_t addr, bus_size_t len);static __inline struct ahd_linux_device*ahd_linux_get_device(struct ahd_softc *ahd, u_int channel, u_int target, u_int lun, int alloc){ struct ahd_linux_target *targ; struct ahd_linux_device *dev; u_int target_offset; target_offset = target; if (channel != 0) target_offset += 8; targ = ahd->platform_data->targets[target_offset]; if (targ == NULL) { if (alloc != 0) { targ = ahd_linux_alloc_target(ahd, channel, target); if (targ == NULL) return (NULL); } else return (NULL); } dev = targ->devices[lun]; if (dev == NULL && alloc != 0) dev = ahd_linux_alloc_device(ahd, targ, lun); return (dev);}static __inline voidahd_linux_queue_cmd_complete(struct ahd_softc *ahd, Scsi_Cmnd *cmd){ /* * Typically, the complete queue has very few entries * queued to it before the queue is emptied by * ahd_linux_run_complete_queue, so sorting the entries * by generation number should be inexpensive. * We perform the sort so that commands that complete * with an error are retuned in the order origionally * queued to the controller so that any subsequent retries * are performed in order. The underlying ahd routines do * not guarantee the order that aborted commands will be * returned to us. */ struct ahd_completeq *completeq; struct ahd_cmd *list_cmd; struct ahd_cmd *acmd; /* * If we want the request requeued, make sure there * are sufficent retries. In the old scsi error code, * we used to be able to specify a result code that * bypassed the retry count. Now we must use this
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -