📄 qlogicisp.c
字号:
/* * QLogic ISP1020 Intelligent SCSI Processor Driver (PCI) * Written by Erik H. Moe, ehm@cris.com * Copyright 1995, Erik H. Moe * Copyright 1996, 1997 Michael A. Griffith <grif@acm.org> * Copyright 2000, Jayson C. Vantuyl <vantuyl@csc.smsu.edu> * and Bryon W. Roche <bryon@csc.smsu.edu> * * 64-bit addressing added by Kanoj Sarcar <kanoj@sgi.com> * and Leo Dagum <dagum@sgi.com> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. */#include <linux/blk.h>#include <linux/config.h>#include <linux/kernel.h>#include <linux/string.h>#include <linux/ioport.h>#include <linux/sched.h>#include <linux/types.h>#include <linux/pci.h>#include <linux/delay.h>#include <linux/unistd.h>#include <linux/spinlock.h>#include <asm/io.h>#include <asm/irq.h>#include <asm/byteorder.h>#include "sd.h"#include "hosts.h"#include "qlogicisp.h"/* Configuration section *****************************************************//* Set the following macro to 1 to reload the ISP1020's firmware. This is the latest firmware provided by QLogic. This may be an earlier/later revision than supplied by your board. */#define RELOAD_FIRMWARE 1/* Set the following macro to 1 to reload the ISP1020's defaults from nvram. If you are not sure of your settings, leave this alone, the driver will use a set of 'safe' defaults */#define USE_NVRAM_DEFAULTS 0/* Macros used for debugging */#define DEBUG_ISP1020 0#define DEBUG_ISP1020_INTR 0#define DEBUG_ISP1020_SETUP 0#define TRACE_ISP 0#define DEFAULT_LOOP_COUNT 1000000#define LinuxVersionCode(v, p, s) (((v)<<16)+((p)<<8)+(s))/* End Configuration section *************************************************/#include <linux/module.h>#if TRACE_ISP# define TRACE_BUF_LEN (32*1024)struct { u_long next; struct { u_long time; u_int index; u_int addr; u_char * name; } buf[TRACE_BUF_LEN];} trace;#define TRACE(w, i, a) \{ \ unsigned long flags; \ \ save_flags(flags); \ cli(); \ trace.buf[trace.next].name = (w); \ trace.buf[trace.next].time = jiffies; \ trace.buf[trace.next].index = (i); \ trace.buf[trace.next].addr = (long) (a); \ trace.next = (trace.next + 1) & (TRACE_BUF_LEN - 1); \ restore_flags(flags); \}#else# define TRACE(w, i, a)#endif#if DEBUG_ISP1020#define ENTER(x) printk("isp1020 : entering %s()\n", x);#define LEAVE(x) printk("isp1020 : leaving %s()\n", x);#define DEBUG(x) x#else#define ENTER(x)#define LEAVE(x)#define DEBUG(x)#endif /* DEBUG_ISP1020 */#if DEBUG_ISP1020_INTR#define ENTER_INTR(x) printk("isp1020 : entering %s()\n", x);#define LEAVE_INTR(x) printk("isp1020 : leaving %s()\n", x);#define DEBUG_INTR(x) x#else#define ENTER_INTR(x)#define LEAVE_INTR(x)#define DEBUG_INTR(x)#endif /* DEBUG ISP1020_INTR */#define ISP1020_REV_ID 1#define MAX_TARGETS 16#define MAX_LUNS 8/* host configuration and control registers */#define HOST_HCCR 0xc0 /* host command and control *//* pci bus interface registers */#define PCI_ID_LOW 0x00 /* vendor id */#define PCI_ID_HIGH 0x02 /* device id */#define ISP_CFG0 0x04 /* configuration register #0 */#define ISP_CFG0_HWMSK 0x000f /* Hardware revision mask */#define ISP_CFG0_1020 0x0001 /* ISP1020 */#define ISP_CFG0_1020A 0x0002 /* ISP1020A */#define ISP_CFG0_1040 0x0003 /* ISP1040 */#define ISP_CFG0_1040A 0x0004 /* ISP1040A */#define ISP_CFG0_1040B 0x0005 /* ISP1040B */#define ISP_CFG0_1040C 0x0006 /* ISP1040C */#define ISP_CFG1 0x06 /* configuration register #1 */#define ISP_CFG1_F128 0x0040 /* 128-byte FIFO threshold */#define ISP_CFG1_F64 0x0030 /* 128-byte FIFO threshold */#define ISP_CFG1_F32 0x0020 /* 128-byte FIFO threshold */#define ISP_CFG1_F16 0x0010 /* 128-byte FIFO threshold */#define ISP_CFG1_BENAB 0x0004 /* Global Bus burst enable */#define ISP_CFG1_SXP 0x0001 /* SXP register select */#define PCI_INTF_CTL 0x08 /* pci interface control */#define PCI_INTF_STS 0x0a /* pci interface status */#define PCI_SEMAPHORE 0x0c /* pci semaphore */#define PCI_NVRAM 0x0e /* pci nvram interface */#define CDMA_CONF 0x20 /* Command DMA Config */#define DDMA_CONF 0x40 /* Data DMA Config */#define DMA_CONF_SENAB 0x0008 /* SXP to DMA Data enable */#define DMA_CONF_RIRQ 0x0004 /* RISC interrupt enable */#define DMA_CONF_BENAB 0x0002 /* Bus burst enable */#define DMA_CONF_DIR 0x0001 /* DMA direction (0=fifo->host 1=host->fifo) *//* mailbox registers */#define MBOX0 0x70 /* mailbox 0 */#define MBOX1 0x72 /* mailbox 1 */#define MBOX2 0x74 /* mailbox 2 */#define MBOX3 0x76 /* mailbox 3 */#define MBOX4 0x78 /* mailbox 4 */#define MBOX5 0x7a /* mailbox 5 */#define MBOX6 0x7c /* mailbox 6 */#define MBOX7 0x7e /* mailbox 7 *//* mailbox command complete status codes */#define MBOX_COMMAND_COMPLETE 0x4000#define INVALID_COMMAND 0x4001#define HOST_INTERFACE_ERROR 0x4002#define TEST_FAILED 0x4003#define COMMAND_ERROR 0x4005#define COMMAND_PARAM_ERROR 0x4006/* async event status codes */#define ASYNC_SCSI_BUS_RESET 0x8001#define SYSTEM_ERROR 0x8002#define REQUEST_TRANSFER_ERROR 0x8003#define RESPONSE_TRANSFER_ERROR 0x8004#define REQUEST_QUEUE_WAKEUP 0x8005#define EXECUTION_TIMEOUT_RESET 0x8006#ifdef CONFIG_QL_ISP_A64#define IOCB_SEGS 2#define CONTINUATION_SEGS 5#define MAX_CONTINUATION_ENTRIES 254#else#define IOCB_SEGS 4#define CONTINUATION_SEGS 7#endif /* CONFIG_QL_ISP_A64 */struct Entry_header { u_char entry_type; u_char entry_cnt; u_char sys_def_1; u_char flags;};/* entry header type commands */#ifdef CONFIG_QL_ISP_A64#define ENTRY_COMMAND 9#define ENTRY_CONTINUATION 0xa#else#define ENTRY_COMMAND 1#define ENTRY_CONTINUATION 2#endif /* CONFIG_QL_ISP_A64 */#define ENTRY_STATUS 3#define ENTRY_MARKER 4#define ENTRY_EXTENDED_COMMAND 5/* entry header flag definitions */#define EFLAG_CONTINUATION 1#define EFLAG_BUSY 2#define EFLAG_BAD_HEADER 4#define EFLAG_BAD_PAYLOAD 8struct dataseg { u_int d_base;#ifdef CONFIG_QL_ISP_A64 u_int d_base_hi;#endif u_int d_count;};struct Command_Entry { struct Entry_header hdr; u_int handle; u_char target_lun; u_char target_id; u_short cdb_length; u_short control_flags; u_short rsvd; u_short time_out; u_short segment_cnt; u_char cdb[12];#ifdef CONFIG_QL_ISP_A64 u_int rsvd1; u_int rsvd2;#endif struct dataseg dataseg[IOCB_SEGS];};/* command entry control flag definitions */#define CFLAG_NODISC 0x01#define CFLAG_HEAD_TAG 0x02#define CFLAG_ORDERED_TAG 0x04#define CFLAG_SIMPLE_TAG 0x08#define CFLAG_TAR_RTN 0x10#define CFLAG_READ 0x20#define CFLAG_WRITE 0x40struct Ext_Command_Entry { struct Entry_header hdr; u_int handle; u_char target_lun; u_char target_id; u_short cdb_length; u_short control_flags; u_short rsvd; u_short time_out; u_short segment_cnt; u_char cdb[44];};struct Continuation_Entry { struct Entry_header hdr;#ifndef CONFIG_QL_ISP_A64 u_int reserved;#endif struct dataseg dataseg[CONTINUATION_SEGS];};struct Marker_Entry { struct Entry_header hdr; u_int reserved; u_char target_lun; u_char target_id; u_char modifier; u_char rsvd; u_char rsvds[52];};/* marker entry modifier definitions */#define SYNC_DEVICE 0#define SYNC_TARGET 1#define SYNC_ALL 2struct Status_Entry { struct Entry_header hdr; u_int handle; u_short scsi_status; u_short completion_status; u_short state_flags; u_short status_flags; u_short time; u_short req_sense_len; u_int residual; u_char rsvd[8]; u_char req_sense_data[32];};/* status entry completion status definitions */#define CS_COMPLETE 0x0000#define CS_INCOMPLETE 0x0001#define CS_DMA_ERROR 0x0002#define CS_TRANSPORT_ERROR 0x0003#define CS_RESET_OCCURRED 0x0004#define CS_ABORTED 0x0005#define CS_TIMEOUT 0x0006#define CS_DATA_OVERRUN 0x0007#define CS_COMMAND_OVERRUN 0x0008#define CS_STATUS_OVERRUN 0x0009#define CS_BAD_MESSAGE 0x000a#define CS_NO_MESSAGE_OUT 0x000b#define CS_EXT_ID_FAILED 0x000c#define CS_IDE_MSG_FAILED 0x000d#define CS_ABORT_MSG_FAILED 0x000e#define CS_REJECT_MSG_FAILED 0x000f#define CS_NOP_MSG_FAILED 0x0010#define CS_PARITY_ERROR_MSG_FAILED 0x0011#define CS_DEVICE_RESET_MSG_FAILED 0x0012#define CS_ID_MSG_FAILED 0x0013#define CS_UNEXP_BUS_FREE 0x0014#define CS_DATA_UNDERRUN 0x0015/* status entry state flag definitions */#define SF_GOT_BUS 0x0100#define SF_GOT_TARGET 0x0200#define SF_SENT_CDB 0x0400#define SF_TRANSFERRED_DATA 0x0800#define SF_GOT_STATUS 0x1000#define SF_GOT_SENSE 0x2000/* status entry status flag definitions */#define STF_DISCONNECT 0x0001#define STF_SYNCHRONOUS 0x0002#define STF_PARITY_ERROR 0x0004#define STF_BUS_RESET 0x0008#define STF_DEVICE_RESET 0x0010#define STF_ABORTED 0x0020#define STF_TIMEOUT 0x0040#define STF_NEGOTIATION 0x0080/* interface control commands */#define ISP_RESET 0x0001#define ISP_EN_INT 0x0002#define ISP_EN_RISC 0x0004/* host control commands */#define HCCR_NOP 0x0000#define HCCR_RESET 0x1000#define HCCR_PAUSE 0x2000#define HCCR_RELEASE 0x3000#define HCCR_SINGLE_STEP 0x4000#define HCCR_SET_HOST_INTR 0x5000#define HCCR_CLEAR_HOST_INTR 0x6000#define HCCR_CLEAR_RISC_INTR 0x7000#define HCCR_BP_ENABLE 0x8000#define HCCR_BIOS_DISABLE 0x9000#define HCCR_TEST_MODE 0xf000#define RISC_BUSY 0x0004/* mailbox commands */#define MBOX_NO_OP 0x0000#define MBOX_LOAD_RAM 0x0001#define MBOX_EXEC_FIRMWARE 0x0002#define MBOX_DUMP_RAM 0x0003#define MBOX_WRITE_RAM_WORD 0x0004#define MBOX_READ_RAM_WORD 0x0005#define MBOX_MAILBOX_REG_TEST 0x0006#define MBOX_VERIFY_CHECKSUM 0x0007#define MBOX_ABOUT_FIRMWARE 0x0008#define MBOX_CHECK_FIRMWARE 0x000e#define MBOX_INIT_REQ_QUEUE 0x0010#define MBOX_INIT_RES_QUEUE 0x0011#define MBOX_EXECUTE_IOCB 0x0012#define MBOX_WAKE_UP 0x0013#define MBOX_STOP_FIRMWARE 0x0014#define MBOX_ABORT 0x0015#define MBOX_ABORT_DEVICE 0x0016#define MBOX_ABORT_TARGET 0x0017#define MBOX_BUS_RESET 0x0018#define MBOX_STOP_QUEUE 0x0019#define MBOX_START_QUEUE 0x001a#define MBOX_SINGLE_STEP_QUEUE 0x001b#define MBOX_ABORT_QUEUE 0x001c#define MBOX_GET_DEV_QUEUE_STATUS 0x001d#define MBOX_GET_FIRMWARE_STATUS 0x001f#define MBOX_GET_INIT_SCSI_ID 0x0020#define MBOX_GET_SELECT_TIMEOUT 0x0021#define MBOX_GET_RETRY_COUNT 0x0022#define MBOX_GET_TAG_AGE_LIMIT 0x0023#define MBOX_GET_CLOCK_RATE 0x0024#define MBOX_GET_ACT_NEG_STATE 0x0025#define MBOX_GET_ASYNC_DATA_SETUP_TIME 0x0026#define MBOX_GET_PCI_PARAMS 0x0027#define MBOX_GET_TARGET_PARAMS 0x0028#define MBOX_GET_DEV_QUEUE_PARAMS 0x0029#define MBOX_SET_INIT_SCSI_ID 0x0030#define MBOX_SET_SELECT_TIMEOUT 0x0031#define MBOX_SET_RETRY_COUNT 0x0032#define MBOX_SET_TAG_AGE_LIMIT 0x0033#define MBOX_SET_CLOCK_RATE 0x0034#define MBOX_SET_ACTIVE_NEG_STATE 0x0035#define MBOX_SET_ASYNC_DATA_SETUP_TIME 0x0036#define MBOX_SET_PCI_CONTROL_PARAMS 0x0037#define MBOX_SET_TARGET_PARAMS 0x0038#define MBOX_SET_DEV_QUEUE_PARAMS 0x0039#define MBOX_RETURN_BIOS_BLOCK_ADDR 0x0040#define MBOX_WRITE_FOUR_RAM_WORDS 0x0041#define MBOX_EXEC_BIOS_IOCB 0x0042#ifdef CONFIG_QL_ISP_A64#define MBOX_CMD_INIT_REQUEST_QUEUE_64 0x0052#define MBOX_CMD_INIT_RESPONSE_QUEUE_64 0x0053#endif /* CONFIG_QL_ISP_A64 */#include "qlogicisp_asm.c"#define PACKB(a, b) (((a)<<4)|(b))static const u_char mbox_param[] = { PACKB(1, 1), /* MBOX_NO_OP */ PACKB(5, 5), /* MBOX_LOAD_RAM */ PACKB(2, 0), /* MBOX_EXEC_FIRMWARE */ PACKB(5, 5), /* MBOX_DUMP_RAM */ PACKB(3, 3), /* MBOX_WRITE_RAM_WORD */ PACKB(2, 3), /* MBOX_READ_RAM_WORD */ PACKB(6, 6), /* MBOX_MAILBOX_REG_TEST */ PACKB(2, 3), /* MBOX_VERIFY_CHECKSUM */ PACKB(1, 3), /* MBOX_ABOUT_FIRMWARE */ PACKB(0, 0), /* 0x0009 */ PACKB(0, 0), /* 0x000a */ PACKB(0, 0), /* 0x000b */ PACKB(0, 0), /* 0x000c */ PACKB(0, 0), /* 0x000d */ PACKB(1, 2), /* MBOX_CHECK_FIRMWARE */ PACKB(0, 0), /* 0x000f */ PACKB(5, 5), /* MBOX_INIT_REQ_QUEUE */ PACKB(6, 6), /* MBOX_INIT_RES_QUEUE */ PACKB(4, 4), /* MBOX_EXECUTE_IOCB */ PACKB(2, 2), /* MBOX_WAKE_UP */ PACKB(1, 6), /* MBOX_STOP_FIRMWARE */ PACKB(4, 4), /* MBOX_ABORT */ PACKB(2, 2), /* MBOX_ABORT_DEVICE */ PACKB(3, 3), /* MBOX_ABORT_TARGET */ PACKB(2, 2), /* MBOX_BUS_RESET */ PACKB(2, 3), /* MBOX_STOP_QUEUE */ PACKB(2, 3), /* MBOX_START_QUEUE */ PACKB(2, 3), /* MBOX_SINGLE_STEP_QUEUE */ PACKB(2, 3), /* MBOX_ABORT_QUEUE */ PACKB(2, 4), /* MBOX_GET_DEV_QUEUE_STATUS */ PACKB(0, 0), /* 0x001e */ PACKB(1, 3), /* MBOX_GET_FIRMWARE_STATUS */ PACKB(1, 2), /* MBOX_GET_INIT_SCSI_ID */ PACKB(1, 2), /* MBOX_GET_SELECT_TIMEOUT */ PACKB(1, 3), /* MBOX_GET_RETRY_COUNT */ PACKB(1, 2), /* MBOX_GET_TAG_AGE_LIMIT */ PACKB(1, 2), /* MBOX_GET_CLOCK_RATE */ PACKB(1, 2), /* MBOX_GET_ACT_NEG_STATE */ PACKB(1, 2), /* MBOX_GET_ASYNC_DATA_SETUP_TIME */ PACKB(1, 3), /* MBOX_GET_PCI_PARAMS */ PACKB(2, 4), /* MBOX_GET_TARGET_PARAMS */ PACKB(2, 4), /* MBOX_GET_DEV_QUEUE_PARAMS */ PACKB(0, 0), /* 0x002a */ PACKB(0, 0), /* 0x002b */ PACKB(0, 0), /* 0x002c */ PACKB(0, 0), /* 0x002d */ PACKB(0, 0), /* 0x002e */ PACKB(0, 0), /* 0x002f */ PACKB(2, 2), /* MBOX_SET_INIT_SCSI_ID */ PACKB(2, 2), /* MBOX_SET_SELECT_TIMEOUT */ PACKB(3, 3), /* MBOX_SET_RETRY_COUNT */ PACKB(2, 2), /* MBOX_SET_TAG_AGE_LIMIT */ PACKB(2, 2), /* MBOX_SET_CLOCK_RATE */ PACKB(2, 2), /* MBOX_SET_ACTIVE_NEG_STATE */ PACKB(2, 2), /* MBOX_SET_ASYNC_DATA_SETUP_TIME */ PACKB(3, 3), /* MBOX_SET_PCI_CONTROL_PARAMS */ PACKB(4, 4), /* MBOX_SET_TARGET_PARAMS */ PACKB(4, 4), /* MBOX_SET_DEV_QUEUE_PARAMS */ PACKB(0, 0), /* 0x003a */ PACKB(0, 0), /* 0x003b */ PACKB(0, 0), /* 0x003c */ PACKB(0, 0), /* 0x003d */ PACKB(0, 0), /* 0x003e */ PACKB(0, 0), /* 0x003f */ PACKB(1, 2), /* MBOX_RETURN_BIOS_BLOCK_ADDR */ PACKB(6, 1), /* MBOX_WRITE_FOUR_RAM_WORDS */ PACKB(2, 3) /* MBOX_EXEC_BIOS_IOCB */#ifdef CONFIG_QL_ISP_A64 ,PACKB(0, 0), /* 0x0043 */ PACKB(0, 0), /* 0x0044 */ PACKB(0, 0), /* 0x0045 */ PACKB(0, 0), /* 0x0046 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -