// SPDX-License-Identifier: GPL-2.0-or-later /****************************************************************************** * QLOGIC LINUX SOFTWARE * * QLogic QLA1280 (Ultra2) and QLA12160 (Ultra3) SCSI driver * Copyright (C) 2000 Qlogic Corporation (www.qlogic.com) * Copyright (C) 2001-2004 Jes Sorensen, Wild Open Source Inc. * Copyright (C) 2003-2004 Christoph Hellwig * ******************************************************************************/ #define QLA1280_VERSION … /***************************************************************************** Revision History: Rev 3.27.1, February 8, 2010, Michael Reed - Retain firmware image for error recovery. Rev 3.27, February 10, 2009, Michael Reed - General code cleanup. - Improve error recovery. Rev 3.26, January 16, 2006 Jes Sorensen - Ditch all < 2.6 support Rev 3.25.1, February 10, 2005 Christoph Hellwig - use pci_map_single to map non-S/G requests - remove qla1280_proc_info Rev 3.25, September 28, 2004, Christoph Hellwig - add support for ISP1020/1040 - don't include "scsi.h" anymore for 2.6.x Rev 3.24.4 June 7, 2004 Christoph Hellwig - restructure firmware loading, cleanup initialization code - prepare support for ISP1020/1040 chips Rev 3.24.3 January 19, 2004, Jes Sorensen - Handle PCI DMA mask settings correctly - Correct order of error handling in probe_one, free_irq should not be called if request_irq failed Rev 3.24.2 January 19, 2004, James Bottomley & Andrew Vasquez - Big endian fixes (James) - Remove bogus IOCB content on zero data transfer commands (Andrew) Rev 3.24.1 January 5, 2004, Jes Sorensen - Initialize completion queue to avoid OOPS on probe - Handle interrupts during mailbox testing Rev 3.24 November 17, 2003, Christoph Hellwig - use struct list_head for completion queue - avoid old Scsi_FOO typedefs - cleanup 2.4 compat glue a bit - use <scsi/scsi_*.h> headers on 2.6 instead of "scsi.h" - make initialization for memory mapped vs port I/O more similar - remove broken pci config space manipulation - kill more cruft - this is an almost perfect 2.6 scsi driver now! ;) Rev 3.23.39 December 17, 2003, Jes Sorensen - Delete completion queue from srb if mailbox command failed to to avoid qla1280_done completeting qla1280_error_action's obsolete context - Reduce arguments for qla1280_done Rev 3.23.38 October 18, 2003, Christoph Hellwig - Convert to new-style hotplugable driver for 2.6 - Fix missing scsi_unregister/scsi_host_put on HBA removal - Kill some more cruft Rev 3.23.37 October 1, 2003, Jes Sorensen - Make MMIO depend on CONFIG_X86_VISWS instead of yet another random CONFIG option - Clean up locking in probe path Rev 3.23.36 October 1, 2003, Christoph Hellwig - queuecommand only ever receives new commands - clear flags - Reintegrate lost fixes from Linux 2.5 Rev 3.23.35 August 14, 2003, Jes Sorensen - Build against 2.6 Rev 3.23.34 July 23, 2003, Jes Sorensen - Remove pointless TRUE/FALSE macros - Clean up vchan handling Rev 3.23.33 July 3, 2003, Jes Sorensen - Don't define register access macros before define determining MMIO. This just happened to work out on ia64 but not elsewhere. - Don't try and read from the card while it is in reset as it won't respond and causes an MCA Rev 3.23.32 June 23, 2003, Jes Sorensen - Basic support for boot time arguments Rev 3.23.31 June 8, 2003, Jes Sorensen - Reduce boot time messages Rev 3.23.30 June 6, 2003, Jes Sorensen - Do not enable sync/wide/ppr before it has been determined that the target device actually supports it - Enable DMA arbitration for multi channel controllers Rev 3.23.29 June 3, 2003, Jes Sorensen - Port to 2.5.69 Rev 3.23.28 June 3, 2003, Jes Sorensen - Eliminate duplicate marker commands on bus resets - Handle outstanding commands appropriately on bus/device resets Rev 3.23.27 May 28, 2003, Jes Sorensen - Remove bogus input queue code, let the Linux SCSI layer do the work - Clean up NVRAM handling, only read it once from the card - Add a number of missing default nvram parameters Rev 3.23.26 Beta May 28, 2003, Jes Sorensen - Use completion queue for mailbox commands instead of busy wait Rev 3.23.25 Beta May 27, 2003, James Bottomley - Migrate to use new error handling code Rev 3.23.24 Beta May 21, 2003, James Bottomley - Big endian support - Cleanup data direction code Rev 3.23.23 Beta May 12, 2003, Jes Sorensen - Switch to using MMIO instead of PIO Rev 3.23.22 Beta April 15, 2003, Jes Sorensen - Fix PCI parity problem with 12160 during reset. Rev 3.23.21 Beta April 14, 2003, Jes Sorensen - Use pci_map_page()/pci_unmap_page() instead of map_single version. Rev 3.23.20 Beta April 9, 2003, Jes Sorensen - Remove < 2.4.x support - Introduce HOST_LOCK to make the spin lock changes portable. - Remove a bunch of idiotic and unnecessary typedef's - Kill all leftovers of target-mode support which never worked anyway Rev 3.23.19 Beta April 11, 2002, Linus Torvalds - Do qla1280_pci_config() before calling request_irq() and request_region() - Use pci_dma_hi32() to handle upper word of DMA addresses instead of large shifts - Hand correct arguments to free_irq() in case of failure Rev 3.23.18 Beta April 11, 2002, Jes Sorensen - Run source through Lindent and clean up the output Rev 3.23.17 Beta April 11, 2002, Jes Sorensen - Update SCSI firmware to qla1280 v8.15.00 and qla12160 v10.04.32 Rev 3.23.16 Beta March 19, 2002, Jes Sorensen - Rely on mailbox commands generating interrupts - do not run qla1280_isr() from ql1280_mailbox_command() - Remove device_reg_t - Integrate ql12160_set_target_parameters() with 1280 version - Make qla1280_setup() non static - Do not call qla1280_check_for_dead_scsi_bus() on every I/O request sent to the card - this command pauses the firmware!!! Rev 3.23.15 Beta March 19, 2002, Jes Sorensen - Clean up qla1280.h - remove obsolete QL_DEBUG_LEVEL_x definitions - Remove a pile of pointless and confusing (srb_t **) and (scsi_lu_t *) typecasts - Explicit mark that we do not use the new error handling (for now) - Remove scsi_qla_host_t and use 'struct' instead - Remove in_abort, watchdog_enabled, dpc, dpc_sched, bios_enabled, pci_64bit_slot flags which weren't used for anything anyway - Grab host->host_lock while calling qla1280_isr() from abort() - Use spin_lock()/spin_unlock() in qla1280_intr_handler() - we do not need to save/restore flags in the interrupt handler - Enable interrupts early (before any mailbox access) in preparation for cleaning up the mailbox handling Rev 3.23.14 Beta March 14, 2002, Jes Sorensen - Further cleanups. Remove all trace of QL_DEBUG_LEVEL_x and replace it with proper use of dprintk(). - Make qla1280_print_scsi_cmd() and qla1280_dump_buffer() both take a debug level argument to determine if data is to be printed - Add KERN_* info to printk() Rev 3.23.13 Beta March 14, 2002, Jes Sorensen - Significant cosmetic cleanups - Change debug code to use dprintk() and remove #if mess Rev 3.23.12 Beta March 13, 2002, Jes Sorensen - More cosmetic cleanups, fix places treating return as function - use cpu_relax() in qla1280_debounce_register() Rev 3.23.11 Beta March 13, 2002, Jes Sorensen - Make it compile under 2.5.5 Rev 3.23.10 Beta October 1, 2001, Jes Sorensen - Do no typecast short * to long * in QL1280BoardTbl, this broke miserably on big endian boxes Rev 3.23.9 Beta September 30, 2001, Jes Sorensen - Remove pre 2.2 hack for checking for reentrance in interrupt handler - Make data types used to receive from SCSI_{BUS,TCN,LUN}_32 unsigned int to match the types from struct scsi_cmnd Rev 3.23.8 Beta September 29, 2001, Jes Sorensen - Remove bogus timer_t typedef from qla1280.h - Remove obsolete pre 2.2 PCI setup code, use proper #define's for PCI_ values, call pci_set_master() - Fix memleak of qla1280_buffer on module unload - Only compile module parsing code #ifdef MODULE - should be changed to use individual MODULE_PARM's later - Remove dummy_buffer that was never modified nor printed - ENTER()/LEAVE() are noops unless QL_DEBUG_LEVEL_3, hence remove #ifdef QL_DEBUG_LEVEL_3/#endif around ENTER()/LEAVE() calls - Remove \r from print statements, this is Linux, not DOS - Remove obsolete QLA1280_{SCSILU,INTR,RING}_{LOCK,UNLOCK} dummy macros - Remove C++ compile hack in header file as Linux driver are not supposed to be compiled as C++ - Kill MS_64BITS macro as it makes the code more readable - Remove unnecessary flags.in_interrupts bit Rev 3.23.7 Beta August 20, 2001, Jes Sorensen - Dont' check for set flags on q->q_flag one by one in qla1280_next() - Check whether the interrupt was generated by the QLA1280 before doing any processing - qla1280_status_entry(): Only zero out part of sense_buffer that is not being copied into - Remove more superflouous typecasts - qla1280_32bit_start_scsi() replace home-brew memcpy() with memcpy() Rev 3.23.6 Beta August 20, 2001, Tony Luck, Intel - Don't walk the entire list in qla1280_putq_t() just to directly grab the pointer to the last element afterwards Rev 3.23.5 Beta August 9, 2001, Jes Sorensen - Don't use IRQF_DISABLED, it's use is deprecated for this kinda driver Rev 3.23.4 Beta August 8, 2001, Jes Sorensen - Set dev->max_sectors to 1024 Rev 3.23.3 Beta August 6, 2001, Jes Sorensen - Provide compat macros for pci_enable_device(), pci_find_subsys() and scsi_set_pci_device() - Call scsi_set_pci_device() for all devices - Reduce size of kernel version dependent device probe code - Move duplicate probe/init code to separate function - Handle error if qla1280_mem_alloc() fails - Kill OFFSET() macro and use Linux's PCI definitions instead - Kill private structure defining PCI config space (struct config_reg) - Only allocate I/O port region if not in MMIO mode - Remove duplicate (unused) sanity check of sife of srb_t Rev 3.23.2 Beta August 6, 2001, Jes Sorensen - Change home-brew memset() implementations to use memset() - Remove all references to COMTRACE() - accessing a PC's COM2 serial port directly is not legal under Linux. Rev 3.23.1 Beta April 24, 2001, Jes Sorensen - Remove pre 2.2 kernel support - clean up 64 bit DMA setting to use 2.4 API (provide backwards compat) - Fix MMIO access to use readl/writel instead of directly dereferencing pointers - Nuke MSDOS debugging code - Change true/false data types to int from uint8_t - Use int for counters instead of uint8_t etc. - Clean up size & byte order conversion macro usage Rev 3.23 Beta January 11, 2001 BN Qlogic - Added check of device_id when handling non QLA12160s during detect(). Rev 3.22 Beta January 5, 2001 BN Qlogic - Changed queue_task() to schedule_task() for kernels 2.4.0 and higher. Note: 2.4.0-testxx kernels released prior to the actual 2.4.0 kernel release on January 2001 will get compile/link errors with schedule_task(). Please update your kernel to released 2.4.0 level, or comment lines in this file flagged with 3.22 to resolve compile/link error of schedule_task(). - Added -DCONFIG_SMP in addition to -D__SMP__ in Makefile for 2.4.0 builds of driver as module. Rev 3.21 Beta January 4, 2001 BN Qlogic - Changed criteria of 64/32 Bit mode of HBA operation according to BITS_PER_LONG rather than HBA's NVRAM setting of >4Gig memory bit; so that the HBA auto-configures without the need to setup each system individually. Rev 3.20 Beta December 5, 2000 BN Qlogic - Added priority handling to IA-64 onboard SCSI ISP12160 chip for kernels greater than 2.3.18. - Added irqrestore for qla1280_intr_handler. - Enabled /proc/scsi/qla1280 interface. - Clear /proc/scsi/qla1280 counters in detect(). Rev 3.19 Beta October 13, 2000 BN Qlogic - Declare driver_template for new kernel (2.4.0 and greater) scsi initialization scheme. - Update /proc/scsi entry for 2.3.18 kernels and above as qla1280 Rev 3.18 Beta October 10, 2000 BN Qlogic - Changed scan order of adapters to map the QLA12160 followed by the QLA1280. Rev 3.17 Beta September 18, 2000 BN Qlogic - Removed warnings for 32 bit 2.4.x compiles - Corrected declared size for request and response DMA addresses that are kept in each ha Rev. 3.16 Beta August 25, 2000 BN Qlogic - Corrected 64 bit addressing issue on IA-64 where the upper 32 bits were not properly passed to the RISC engine. Rev. 3.15 Beta August 22, 2000 BN Qlogic - Modified qla1280_setup_chip to properly load ISP firmware for greater that 4 Gig memory on IA-64 Rev. 3.14 Beta August 16, 2000 BN Qlogic - Added setting of dma_mask to full 64 bit if flags.enable_64bit_addressing is set in NVRAM Rev. 3.13 Beta August 16, 2000 BN Qlogic - Use new PCI DMA mapping APIs for 2.4.x kernel Rev. 3.12 July 18, 2000 Redhat & BN Qlogic - Added check of pci_enable_device to detect() for 2.3.x - Use pci_resource_start() instead of pdev->resource[0].start in detect() for 2.3.x - Updated driver version Rev. 3.11 July 14, 2000 BN Qlogic - Updated SCSI Firmware to following versions: qla1x80: 8.13.08 qla1x160: 10.04.08 - Updated driver version to 3.11 Rev. 3.10 June 23, 2000 BN Qlogic - Added filtering of AMI SubSys Vendor ID devices Rev. 3.9 - DEBUG_QLA1280 undefined and new version BN Qlogic Rev. 3.08b May 9, 2000 MD Dell - Added logic to check against AMI subsystem vendor ID Rev. 3.08 May 4, 2000 DG Qlogic - Added logic to check for PCI subsystem ID. Rev. 3.07 Apr 24, 2000 DG & BN Qlogic - Updated SCSI Firmware to following versions: qla12160: 10.01.19 qla1280: 8.09.00 Rev. 3.06 Apr 12, 2000 DG & BN Qlogic - Internal revision; not released Rev. 3.05 Mar 28, 2000 DG & BN Qlogic - Edit correction for virt_to_bus and PROC. Rev. 3.04 Mar 28, 2000 DG & BN Qlogic - Merge changes from ia64 port. Rev. 3.03 Mar 28, 2000 BN Qlogic - Increase version to reflect new code drop with compile fix of issue with inclusion of linux/spinlock for 2.3 kernels Rev. 3.02 Mar 15, 2000 BN Qlogic - Merge qla1280_proc_info from 2.10 code base Rev. 3.01 Feb 10, 2000 BN Qlogic - Corrected code to compile on a 2.2.x kernel. Rev. 3.00 Jan 17, 2000 DG Qlogic - Added 64-bit support. Rev. 2.07 Nov 9, 1999 DG Qlogic - Added new routine to set target parameters for ISP12160. Rev. 2.06 Sept 10, 1999 DG Qlogic - Added support for ISP12160 Ultra 3 chip. Rev. 2.03 August 3, 1999 Fred Lewis, Intel DuPont - Modified code to remove errors generated when compiling with Cygnus IA64 Compiler. - Changed conversion of pointers to unsigned longs instead of integers. - Changed type of I/O port variables from uint32_t to unsigned long. - Modified OFFSET macro to work with 64-bit as well as 32-bit. - Changed sprintf and printk format specifiers for pointers to %p. - Changed some int to long type casts where needed in sprintf & printk. - Added l modifiers to sprintf and printk format specifiers for longs. - Removed unused local variables. Rev. 1.20 June 8, 1999 DG, Qlogic Changes to support RedHat release 6.0 (kernel 2.2.5). - Added SCSI exclusive access lock (io_request_lock) when accessing the adapter. - Added changes for the new LINUX interface template. Some new error handling routines have been added to the template, but for now we will use the old ones. - Initial Beta Release. *****************************************************************************/ #include <linux/module.h> #include <linux/types.h> #include <linux/string.h> #include <linux/errno.h> #include <linux/kernel.h> #include <linux/ioport.h> #include <linux/delay.h> #include <linux/timer.h> #include <linux/pci.h> #include <linux/proc_fs.h> #include <linux/stat.h> #include <linux/pci_ids.h> #include <linux/interrupt.h> #include <linux/init.h> #include <linux/dma-mapping.h> #include <linux/firmware.h> #include <asm/io.h> #include <asm/irq.h> #include <asm/byteorder.h> #include <asm/processor.h> #include <asm/types.h> #include <scsi/scsi.h> #include <scsi/scsi_cmnd.h> #include <scsi/scsi_device.h> #include <scsi/scsi_host.h> #include <scsi/scsi_tcq.h> /* * Compile time Options: * 0 - Disable and 1 - Enable */ #define DEBUG_QLA1280_INTR … #define DEBUG_PRINT_NVRAM … #define DEBUG_QLA1280 … #define MEMORY_MAPPED_IO … #include "qla1280.h" #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT #define QLA_64BIT_PTR … #endif #define NVRAM_DELAY() … #define IS_ISP1040(ha) … #define IS_ISP1x40(ha) … #define IS_ISP1x160(ha) … static int qla1280_probe_one(struct pci_dev *, const struct pci_device_id *); static void qla1280_remove_one(struct pci_dev *); /* * QLogic Driver Support Function Prototypes. */ static void qla1280_done(struct scsi_qla_host *); static int qla1280_get_token(char *); static int qla1280_setup(char *s) __init; /* * QLogic ISP1280 Hardware Support Function Prototypes. */ static int qla1280_load_firmware(struct scsi_qla_host *); static int qla1280_init_rings(struct scsi_qla_host *); static int qla1280_nvram_config(struct scsi_qla_host *); static int qla1280_mailbox_command(struct scsi_qla_host *, uint8_t, uint16_t *); static int qla1280_bus_reset(struct scsi_qla_host *, int); static int qla1280_device_reset(struct scsi_qla_host *, int, int); static int qla1280_abort_command(struct scsi_qla_host *, struct srb *, int); static int qla1280_abort_isp(struct scsi_qla_host *); #ifdef QLA_64BIT_PTR static int qla1280_64bit_start_scsi(struct scsi_qla_host *, struct srb *); #else static int qla1280_32bit_start_scsi(struct scsi_qla_host *, struct srb *); #endif static void qla1280_nv_write(struct scsi_qla_host *, uint16_t); static void qla1280_poll(struct scsi_qla_host *); static void qla1280_reset_adapter(struct scsi_qla_host *); static void qla1280_marker(struct scsi_qla_host *, int, int, int, u8); static void qla1280_isp_cmd(struct scsi_qla_host *); static void qla1280_isr(struct scsi_qla_host *, struct list_head *); static void qla1280_rst_aen(struct scsi_qla_host *); static void qla1280_status_entry(struct scsi_qla_host *, struct response *, struct list_head *); static void qla1280_error_entry(struct scsi_qla_host *, struct response *, struct list_head *); static uint16_t qla1280_get_nvram_word(struct scsi_qla_host *, uint32_t); static uint16_t qla1280_nvram_request(struct scsi_qla_host *, uint32_t); static uint16_t qla1280_debounce_register(volatile uint16_t __iomem *); static request_t *qla1280_req_pkt(struct scsi_qla_host *); static int qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *, unsigned int); static void qla1280_get_target_parameters(struct scsi_qla_host *, struct scsi_device *); static int qla1280_set_target_parameters(struct scsi_qla_host *, int, int); static struct qla_driver_setup driver_setup; /* * convert scsi data direction to request_t control flags */ static inline uint16_t qla1280_data_direction(struct scsi_cmnd *cmnd) { … } #if DEBUG_QLA1280 static void __qla1280_print_scsi_cmd(struct scsi_cmnd * cmd); static void __qla1280_dump_buffer(char *, int); #endif /* * insmod needs to find the variable and make it point to something */ #ifdef MODULE static char *qla1280; /* insmod qla1280 options=verbose" */ module_param(qla1280, charp, 0); #else __setup(…); #endif #define CMD_CDBLEN(Cmnd) … #define CMD_CDBP(Cmnd) … #define CMD_SNSP(Cmnd) … #define CMD_SNSLEN(Cmnd) … #define CMD_RESULT(Cmnd) … #define CMD_HANDLE(Cmnd) … #define CMD_HOST(Cmnd) … #define SCSI_BUS_32(Cmnd) … #define SCSI_TCN_32(Cmnd) … #define SCSI_LUN_32(Cmnd) … /*****************************************/ /* ISP Boards supported by this driver */ /*****************************************/ struct qla_boards { … }; /* NOTE: the last argument in each entry is used to index ql1280_board_tbl */ static struct pci_device_id qla1280_pci_tbl[] = …; MODULE_DEVICE_TABLE(pci, qla1280_pci_tbl); static DEFINE_MUTEX(qla1280_firmware_mutex); struct qla_fw { … }; #define QL_NUM_FW_IMAGES … static struct qla_fw qla1280_fw_tbl[QL_NUM_FW_IMAGES] = …; /* NOTE: Order of boards in this table must match order in qla1280_pci_tbl */ static struct qla_boards ql1280_board_tbl[] = …; static int qla1280_verbose = …; #if DEBUG_QLA1280 static int ql_debug_level = 1; #define dprintk … #define qla1280_dump_buffer … #define qla1280_print_scsi_cmd … #else #define ql_debug_level … #define dprintk(level, format, a...) … #define qla1280_dump_buffer(a, b, c) … #define qla1280_print_scsi_cmd(a, b) … #endif #define ENTER(x) … #define LEAVE(x) … #define ENTER_INTR(x) … #define LEAVE_INTR(x) … static int qla1280_read_nvram(struct scsi_qla_host *ha) { … } /************************************************************************** * qla1280_info * Return a string describing the driver. **************************************************************************/ static const char * qla1280_info(struct Scsi_Host *host) { … } /************************************************************************** * qla1280_queuecommand * Queue a command to the controller. * * Note: * The mid-level driver tries to ensures that queuecommand never gets invoked * concurrently with itself or the interrupt handler (although the * interrupt handler may call this routine as part of request-completion * handling). Unfortunately, it sometimes calls the scheduler in interrupt * context which is a big NO! NO!. **************************************************************************/ static int qla1280_queuecommand_lck(struct scsi_cmnd *cmd) { … } static DEF_SCSI_QCMD(qla1280_queuecommand) enum action { … }; static void qla1280_mailbox_timeout(struct timer_list *t) { … } static int _qla1280_wait_for_single_command(struct scsi_qla_host *ha, struct srb *sp, struct completion *wait) { … } static int qla1280_wait_for_single_command(struct scsi_qla_host *ha, struct srb *sp) { … } static int qla1280_wait_for_pending_commands(struct scsi_qla_host *ha, int bus, int target) { … } /************************************************************************** * qla1280_error_action * The function will attempt to perform a specified error action and * wait for the results (or time out). * * Input: * cmd = Linux SCSI command packet of the command that cause the * bus reset. * action = error action to take (see action_t) * * Returns: * SUCCESS or FAILED * **************************************************************************/ static int qla1280_error_action(struct scsi_cmnd *cmd, enum action action) { … } /************************************************************************** * qla1280_abort * Abort the specified SCSI command(s). **************************************************************************/ static int qla1280_eh_abort(struct scsi_cmnd * cmd) { … } /************************************************************************** * qla1280_device_reset * Reset the specified SCSI device **************************************************************************/ static int qla1280_eh_device_reset(struct scsi_cmnd *cmd) { … } /************************************************************************** * qla1280_bus_reset * Reset the specified bus. **************************************************************************/ static int qla1280_eh_bus_reset(struct scsi_cmnd *cmd) { … } /************************************************************************** * qla1280_adapter_reset * Reset the specified adapter (both channels) **************************************************************************/ static int qla1280_eh_adapter_reset(struct scsi_cmnd *cmd) { … } static int qla1280_biosparam(struct scsi_device *sdev, struct block_device *bdev, sector_t capacity, int geom[]) { … } /* disable risc and host interrupts */ static inline void qla1280_disable_intrs(struct scsi_qla_host *ha) { … } /* enable risc and host interrupts */ static inline void qla1280_enable_intrs(struct scsi_qla_host *ha) { … } /************************************************************************** * qla1280_intr_handler * Handles the H/W interrupt **************************************************************************/ static irqreturn_t qla1280_intr_handler(int irq, void *dev_id) { … } static int qla1280_set_target_parameters(struct scsi_qla_host *ha, int bus, int target) { … } /************************************************************************** * qla1280_slave_configure * * Description: * Determines the queue depth for a given device. There are two ways * a queue depth can be obtained for a tagged queueing device. One * way is the default queue depth which is determined by whether * If it is defined, then it is used * as the default queue depth. Otherwise, we use either 4 or 8 as the * default queue depth (dependent on the number of hardware SCBs). **************************************************************************/ static int qla1280_slave_configure(struct scsi_device *device) { … } /* * qla1280_done * Process completed commands. * * Input: * ha = adapter block pointer. */ static void qla1280_done(struct scsi_qla_host *ha) { … } /* * Translates a ISP error to a Linux SCSI error */ static int qla1280_return_status(struct response * sts, struct scsi_cmnd *cp) { … } /****************************************************************************/ /* QLogic ISP1280 Hardware Support Functions. */ /****************************************************************************/ /* * qla1280_initialize_adapter * Initialize board. * * Input: * ha = adapter block pointer. * * Returns: * 0 = success */ static int qla1280_initialize_adapter(struct scsi_qla_host *ha) { … } /* * qla1280_request_firmware * Acquire firmware for chip. Retain in memory * for error recovery. * * Input: * ha = adapter block pointer. * * Returns: * Pointer to firmware image or an error code * cast to pointer via ERR_PTR(). */ static const struct firmware * qla1280_request_firmware(struct scsi_qla_host *ha) { … } /* * Chip diagnostics * Test chip for proper operation. * * Input: * ha = adapter block pointer. * * Returns: * 0 = success. */ static int qla1280_chip_diag(struct scsi_qla_host *ha) { … } static int qla1280_load_firmware_pio(struct scsi_qla_host *ha) { … } #ifdef QLA_64BIT_PTR #define LOAD_CMD … #define DUMP_CMD … #define CMD_ARGS … #else #define LOAD_CMD … #define DUMP_CMD … #define CMD_ARGS … #endif #define DUMP_IT_BACK … static int qla1280_load_firmware_dma(struct scsi_qla_host *ha) { … } static int qla1280_start_firmware(struct scsi_qla_host *ha) { … } static int qla1280_load_firmware(struct scsi_qla_host *ha) { … } /* * Initialize rings * * Input: * ha = adapter block pointer. * ha->request_ring = request ring virtual address * ha->response_ring = response ring virtual address * ha->request_dma = request ring physical address * ha->response_dma = response ring physical address * * Returns: * 0 = success. */ static int qla1280_init_rings(struct scsi_qla_host *ha) { … } static void qla1280_print_settings(struct nvram *nv) { … } static void qla1280_set_target_defaults(struct scsi_qla_host *ha, int bus, int target) { … } static void qla1280_set_defaults(struct scsi_qla_host *ha) { … } static int qla1280_config_target(struct scsi_qla_host *ha, int bus, int target) { … } static int qla1280_config_bus(struct scsi_qla_host *ha, int bus) { … } static int qla1280_nvram_config(struct scsi_qla_host *ha) { … } /* * Get NVRAM data word * Calculates word position in NVRAM and calls request routine to * get the word from NVRAM. * * Input: * ha = adapter block pointer. * address = NVRAM word address. * * Returns: * data word. */ static uint16_t qla1280_get_nvram_word(struct scsi_qla_host *ha, uint32_t address) { … } /* * NVRAM request * Sends read command to NVRAM and gets data from NVRAM. * * Input: * ha = adapter block pointer. * nv_cmd = Bit 26 = start bit * Bit 25, 24 = opcode * Bit 23-16 = address * Bit 15-0 = write data * * Returns: * data word. */ static uint16_t qla1280_nvram_request(struct scsi_qla_host *ha, uint32_t nv_cmd) { … } static void qla1280_nv_write(struct scsi_qla_host *ha, uint16_t data) { … } /* * Mailbox Command * Issue mailbox command and waits for completion. * * Input: * ha = adapter block pointer. * mr = mailbox registers to load. * mb = data pointer for mailbox registers. * * Output: * mb[MAILBOX_REGISTER_COUNT] = returned mailbox data. * * Returns: * 0 = success */ static int qla1280_mailbox_command(struct scsi_qla_host *ha, uint8_t mr, uint16_t *mb) { … } /* * qla1280_poll * Polls ISP for interrupts. * * Input: * ha = adapter block pointer. */ static void qla1280_poll(struct scsi_qla_host *ha) { … } /* * qla1280_bus_reset * Issue SCSI bus reset. * * Input: * ha = adapter block pointer. * bus = SCSI bus number. * * Returns: * 0 = success */ static int qla1280_bus_reset(struct scsi_qla_host *ha, int bus) { … } /* * qla1280_device_reset * Issue bus device reset message to the target. * * Input: * ha = adapter block pointer. * bus = SCSI BUS number. * target = SCSI ID. * * Returns: * 0 = success */ static int qla1280_device_reset(struct scsi_qla_host *ha, int bus, int target) { … } /* * qla1280_abort_command * Abort command aborts a specified IOCB. * * Input: * ha = adapter block pointer. * sp = SB structure pointer. * * Returns: * 0 = success */ static int qla1280_abort_command(struct scsi_qla_host *ha, struct srb * sp, int handle) { … } /* * qla1280_reset_adapter * Reset adapter. * * Input: * ha = adapter block pointer. */ static void qla1280_reset_adapter(struct scsi_qla_host *ha) { … } /* * Issue marker command. * Function issues marker IOCB. * * Input: * ha = adapter block pointer. * bus = SCSI BUS number * id = SCSI ID * lun = SCSI LUN * type = marker modifier */ static void qla1280_marker(struct scsi_qla_host *ha, int bus, int id, int lun, u8 type) { … } /* * qla1280_64bit_start_scsi * The start SCSI is responsible for building request packets on * request ring and modifying ISP input pointer. * * Input: * ha = adapter block pointer. * sp = SB structure pointer. * * Returns: * 0 = success, was able to issue command. */ #ifdef QLA_64BIT_PTR static int qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp) { … } #else /* !QLA_64BIT_PTR */ /* * qla1280_32bit_start_scsi * The start SCSI is responsible for building request packets on * request ring and modifying ISP input pointer. * * The Qlogic firmware interface allows every queue slot to have a SCSI * command and up to 4 scatter/gather (SG) entries. If we need more * than 4 SG entries, then continuation entries are used that can * hold another 7 entries each. The start routine determines if there * is eought empty slots then build the combination of requests to * fulfill the OS request. * * Input: * ha = adapter block pointer. * sp = SCSI Request Block structure pointer. * * Returns: * 0 = success, was able to issue command. */ static int qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp) { struct device_reg __iomem *reg = ha->iobase; struct scsi_cmnd *cmd = sp->cmd; struct cmd_entry *pkt; __le32 *dword_ptr; int status = 0; int cnt; int req_cnt; int seg_cnt; u8 dir; ENTER("qla1280_32bit_start_scsi"); dprintk(1, "32bit_start: cmd=%p sp=%p CDB=%x\n", cmd, sp, cmd->cmnd[0]); /* Calculate number of entries and segments required. */ req_cnt = 1; seg_cnt = scsi_dma_map(cmd); if (seg_cnt) { /* * if greater than four sg entries then we need to allocate * continuation entries */ if (seg_cnt > 4) { req_cnt += (seg_cnt - 4) / 7; if ((seg_cnt - 4) % 7) req_cnt++; } dprintk(3, "S/G Transfer cmd=%p seg_cnt=0x%x, req_cnt=%x\n", cmd, seg_cnt, req_cnt); } else if (seg_cnt < 0) { status = 1; goto out; } if ((req_cnt + 2) >= ha->req_q_cnt) { /* Calculate number of free request entries. */ cnt = RD_REG_WORD(®->mailbox4); if (ha->req_ring_index < cnt) ha->req_q_cnt = cnt - ha->req_ring_index; else ha->req_q_cnt = REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt); } dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n", ha->req_q_cnt, seg_cnt); /* If room for request in request ring. */ if ((req_cnt + 2) >= ha->req_q_cnt) { status = SCSI_MLQUEUE_HOST_BUSY; dprintk(2, "qla1280_32bit_start_scsi: in-ptr=0x%x, " "req_q_cnt=0x%x, req_cnt=0x%x", ha->req_ring_index, ha->req_q_cnt, req_cnt); goto out; } /* Check for empty slot in outstanding command list. */ for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS && ha->outstanding_cmds[cnt]; cnt++); if (cnt >= MAX_OUTSTANDING_COMMANDS) { status = SCSI_MLQUEUE_HOST_BUSY; dprintk(2, "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING " "ARRAY, req_q_cnt=0x%x\n", ha->req_q_cnt); goto out; } CMD_HANDLE(sp->cmd) = (unsigned char *) (unsigned long)(cnt + 1); ha->outstanding_cmds[cnt] = sp; ha->req_q_cnt -= req_cnt; /* * Build command packet. */ pkt = (struct cmd_entry *) ha->request_ring_ptr; pkt->entry_type = COMMAND_TYPE; pkt->entry_count = (uint8_t) req_cnt; pkt->sys_define = (uint8_t) ha->req_ring_index; pkt->entry_status = 0; pkt->handle = cpu_to_le32(cnt); /* Zero out remaining portion of packet. */ memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8)); /* Set ISP command timeout. */ pkt->timeout = cpu_to_le16(scsi_cmd_to_rq(cmd)->timeout / HZ); /* Set device target ID and LUN */ pkt->lun = SCSI_LUN_32(cmd); pkt->target = SCSI_BUS_32(cmd) ? (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd); /* Enable simple tag queuing if device supports it. */ if (cmd->device->simple_tags) pkt->control_flags |= cpu_to_le16(BIT_3); /* Load SCSI command packet. */ pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd)); memcpy(pkt->scsi_cdb, CMD_CDBP(cmd), CMD_CDBLEN(cmd)); /*dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */ /* Set transfer direction. */ dir = qla1280_data_direction(cmd); pkt->control_flags |= cpu_to_le16(dir); /* Set total data segment count. */ pkt->dseg_count = cpu_to_le16(seg_cnt); /* * Load data segments. */ if (seg_cnt) { struct scatterlist *sg, *s; int remseg = seg_cnt; sg = scsi_sglist(cmd); /* Setup packet address segment pointer. */ dword_ptr = &pkt->dseg_0_address; dprintk(3, "Building S/G data segments..\n"); qla1280_dump_buffer(1, (char *)sg, 4 * 16); /* Load command entry data segments. */ for_each_sg(sg, s, seg_cnt, cnt) { if (cnt == 4) break; *dword_ptr++ = cpu_to_le32(lower_32_bits(sg_dma_address(s))); *dword_ptr++ = cpu_to_le32(sg_dma_len(s)); dprintk(3, "S/G Segment phys_addr=0x%lx, len=0x%x\n", (lower_32_bits(sg_dma_address(s))), (sg_dma_len(s))); remseg--; } /* * Build continuation packets. */ dprintk(3, "S/G Building Continuation" "...seg_cnt=0x%x remains\n", seg_cnt); while (remseg > 0) { /* Continue from end point */ sg = s; /* Adjust ring index. */ ha->req_ring_index++; if (ha->req_ring_index == REQUEST_ENTRY_CNT) { ha->req_ring_index = 0; ha->request_ring_ptr = ha->request_ring; } else ha->request_ring_ptr++; pkt = (struct cmd_entry *)ha->request_ring_ptr; /* Zero out packet. */ memset(pkt, 0, REQUEST_ENTRY_SIZE); /* Load packet defaults. */ ((struct cont_entry *) pkt)-> entry_type = CONTINUE_TYPE; ((struct cont_entry *) pkt)->entry_count = 1; ((struct cont_entry *) pkt)->sys_define = (uint8_t) ha->req_ring_index; /* Setup packet address segment pointer. */ dword_ptr = &((struct cont_entry *) pkt)->dseg_0_address; /* Load continuation entry data segments. */ for_each_sg(sg, s, remseg, cnt) { if (cnt == 7) break; *dword_ptr++ = cpu_to_le32(lower_32_bits(sg_dma_address(s))); *dword_ptr++ = cpu_to_le32(sg_dma_len(s)); dprintk(1, "S/G Segment Cont. phys_addr=0x%x, " "len=0x%x\n", cpu_to_le32(lower_32_bits(sg_dma_address(s))), cpu_to_le32(sg_dma_len(s))); } remseg -= cnt; dprintk(5, "qla1280_32bit_start_scsi: " "continuation packet data - " "scsi(%i:%i:%i)\n", SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd)); qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE); } } else { /* No data transfer at all */ dprintk(5, "qla1280_32bit_start_scsi: No data, command " "packet data - \n"); qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE); } dprintk(5, "qla1280_32bit_start_scsi: First IOCB block:\n"); qla1280_dump_buffer(5, (char *)ha->request_ring_ptr, REQUEST_ENTRY_SIZE); /* Adjust ring index. */ ha->req_ring_index++; if (ha->req_ring_index == REQUEST_ENTRY_CNT) { ha->req_ring_index = 0; ha->request_ring_ptr = ha->request_ring; } else ha->request_ring_ptr++; /* Set chip new ring index. */ dprintk(2, "qla1280_32bit_start_scsi: Wakeup RISC " "for pending command\n"); sp->flags |= SRB_SENT; ha->actthreads++; WRT_REG_WORD(®->mailbox4, ha->req_ring_index); out: if (status) dprintk(2, "qla1280_32bit_start_scsi: **** FAILED ****\n"); LEAVE("qla1280_32bit_start_scsi"); return status; } #endif /* * qla1280_req_pkt * Function is responsible for locking ring and * getting a zeroed out request packet. * * Input: * ha = adapter block pointer. * * Returns: * 0 = failed to get slot. */ static request_t * qla1280_req_pkt(struct scsi_qla_host *ha) { … } /* * qla1280_isp_cmd * Function is responsible for modifying ISP input pointer. * Releases ring lock. * * Input: * ha = adapter block pointer. */ static void qla1280_isp_cmd(struct scsi_qla_host *ha) { … } /****************************************************************************/ /* Interrupt Service Routine. */ /****************************************************************************/ /**************************************************************************** * qla1280_isr * Calls I/O done on command completion. * * Input: * ha = adapter block pointer. * done_q = done queue. ****************************************************************************/ static void qla1280_isr(struct scsi_qla_host *ha, struct list_head *done_q) { … } /* * qla1280_rst_aen * Processes asynchronous reset. * * Input: * ha = adapter block pointer. */ static void qla1280_rst_aen(struct scsi_qla_host *ha) { … } /* * qla1280_status_entry * Processes received ISP status entry. * * Input: * ha = adapter block pointer. * pkt = entry pointer. * done_q = done queue. */ static void qla1280_status_entry(struct scsi_qla_host *ha, struct response *pkt, struct list_head *done_q) { … } /* * qla1280_error_entry * Processes error entry. * * Input: * ha = adapter block pointer. * pkt = entry pointer. * done_q = done queue. */ static void qla1280_error_entry(struct scsi_qla_host *ha, struct response *pkt, struct list_head *done_q) { … } /* * qla1280_abort_isp * Resets ISP and aborts all outstanding commands. * * Input: * ha = adapter block pointer. * * Returns: * 0 = success */ static int qla1280_abort_isp(struct scsi_qla_host *ha) { … } /* * qla1280_debounce_register * Debounce register. * * Input: * port = register address. * * Returns: * register value. */ static u16 qla1280_debounce_register(volatile u16 __iomem * addr) { … } /************************************************************************ * qla1280_check_for_dead_scsi_bus * * * * This routine checks for a dead SCSI bus * ************************************************************************/ #define SET_SXP_BANK … #define SCSI_PHASE_INVALID … static int qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *ha, unsigned int bus) { … } static void qla1280_get_target_parameters(struct scsi_qla_host *ha, struct scsi_device *device) { … } #if DEBUG_QLA1280 static void __qla1280_dump_buffer(char *b, int size) { int cnt; u8 c; printk(KERN_DEBUG " 0 1 2 3 4 5 6 7 8 9 Ah " "Bh Ch Dh Eh Fh\n"); printk(KERN_DEBUG "---------------------------------------------" "------------------\n"); for (cnt = 0; cnt < size;) { c = *b++; printk("0x%02x", c); cnt++; if (!(cnt % 16)) printk("\n"); else printk(" "); } if (cnt % 16) printk("\n"); } /************************************************************************** * ql1280_print_scsi_cmd * **************************************************************************/ static void __qla1280_print_scsi_cmd(struct scsi_cmnd *cmd) { struct scsi_qla_host *ha; struct Scsi_Host *host = CMD_HOST(cmd); struct srb *sp; /* struct scatterlist *sg; */ int i; ha = (struct scsi_qla_host *)host->hostdata; sp = scsi_cmd_priv(cmd); printk("SCSI Command @= 0x%p, Handle=0x%p\n", cmd, CMD_HANDLE(cmd)); printk(" chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n", SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd), CMD_CDBLEN(cmd)); printk(" CDB = "); for (i = 0; i < cmd->cmd_len; i++) { printk("0x%02x ", cmd->cmnd[i]); } printk(" seg_cnt =%d\n", scsi_sg_count(cmd)); printk(" request buffer=0x%p, request buffer len=0x%x\n", scsi_sglist(cmd), scsi_bufflen(cmd)); /* if (cmd->use_sg) { sg = (struct scatterlist *) cmd->request_buffer; printk(" SG buffer: \n"); qla1280_dump_buffer(1, (char *)sg, (cmd->use_sg*sizeof(struct scatterlist))); } */ printk(" tag=%d, transfersize=0x%x \n", scsi_cmd_to_rq(cmd)->tag, cmd->transfersize); printk(" underflow size = 0x%x, direction=0x%x\n", cmd->underflow, cmd->sc_data_direction); } /************************************************************************** * ql1280_dump_device * **************************************************************************/ static void ql1280_dump_device(struct scsi_qla_host *ha) { struct scsi_cmnd *cp; struct srb *sp; int i; printk(KERN_DEBUG "Outstanding Commands on controller:\n"); for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) { if ((sp = ha->outstanding_cmds[i]) == NULL) continue; if ((cp = sp->cmd) == NULL) continue; qla1280_print_scsi_cmd(1, cp); } } #endif enum tokens { … }; struct setup_tokens { … }; static struct setup_tokens setup_token[] __initdata = …; /************************************************************************** * qla1280_setup * * Handle boot parameters. This really needs to be changed so one * can specify per adapter parameters. **************************************************************************/ static int __init qla1280_setup(char *s) { … } static int __init qla1280_get_token(char *str) { … } static const struct scsi_host_template qla1280_driver_template = …; static int qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) { … } static void qla1280_remove_one(struct pci_dev *pdev) { … } static struct pci_driver qla1280_pci_driver = …; static int __init qla1280_init(void) { … } static void __exit qla1280_exit(void) { … } module_init(…) …; module_exit(qla1280_exit); MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …; MODULE_FIRMWARE(…) …; MODULE_FIRMWARE(…) …; MODULE_FIRMWARE(…) …; MODULE_VERSION(…);