advansys.c

来自「linux 内核源代码」· C语言 代码 · 共 1,713 行 · 第 1/5 页

C
1,713
字号
#define DRV_NAME "advansys"#define ASC_VERSION "3.4"	/* AdvanSys Driver Version *//* * advansys.c - Linux Host Driver for AdvanSys SCSI Adapters * * Copyright (c) 1995-2000 Advanced System Products, Inc. * Copyright (c) 2000-2001 ConnectCom Solutions, Inc. * Copyright (c) 2007 Matthew Wilcox <matthew@wil.cx> * All Rights Reserved. * * 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 of the License, or * (at your option) any later version. *//* * As of March 8, 2000 Advanced System Products, Inc. (AdvanSys) * changed its name to ConnectCom Solutions, Inc. * On June 18, 2001 Initio Corp. acquired ConnectCom's SCSI assets */#include <linux/module.h>#include <linux/string.h>#include <linux/kernel.h>#include <linux/types.h>#include <linux/ioport.h>#include <linux/interrupt.h>#include <linux/delay.h>#include <linux/slab.h>#include <linux/mm.h>#include <linux/proc_fs.h>#include <linux/init.h>#include <linux/blkdev.h>#include <linux/isa.h>#include <linux/eisa.h>#include <linux/pci.h>#include <linux/spinlock.h>#include <linux/dma-mapping.h>#include <asm/io.h>#include <asm/system.h>#include <asm/dma.h>#include <scsi/scsi_cmnd.h>#include <scsi/scsi_device.h>#include <scsi/scsi_tcq.h>#include <scsi/scsi.h>#include <scsi/scsi_host.h>/* FIXME: * *  1. Although all of the necessary command mapping places have the *     appropriate dma_map.. APIs, the driver still processes its internal *     queue using bus_to_virt() and virt_to_bus() which are illegal under *     the API.  The entire queue processing structure will need to be *     altered to fix this. *  2. Need to add memory mapping workaround. Test the memory mapping. *     If it doesn't work revert to I/O port access. Can a test be done *     safely? *  3. Handle an interrupt not working. Keep an interrupt counter in *     the interrupt handler. In the timeout function if the interrupt *     has not occurred then print a message and run in polled mode. *  4. Need to add support for target mode commands, cf. CAM XPT. *  5. check DMA mapping functions for failure *  6. Use scsi_transport_spi *  7. advansys_info is not safe against multiple simultaneous callers *  8. Add module_param to override ISA/VLB ioport array */#warning this driver is still not properly converted to the DMA API/* Enable driver /proc statistics. */#define ADVANSYS_STATS/* Enable driver tracing. */#undef ADVANSYS_DEBUG/* * Portable Data Types * * Any instance where a 32-bit long or pointer type is assumed * for precision or HW defined structures, the following define * types must be used. In Linux the char, short, and int types * are all consistent at 8, 16, and 32 bits respectively. Pointers * and long types are 64 bits on Alpha and UltraSPARC. */#define ASC_PADDR __u32		/* Physical/Bus address data type. */#define ASC_VADDR __u32		/* Virtual address data type. */#define ASC_DCNT  __u32		/* Unsigned Data count type. */#define ASC_SDCNT __s32		/* Signed Data count type. */typedef unsigned char uchar;#ifndef TRUE#define TRUE     (1)#endif#ifndef FALSE#define FALSE    (0)#endif#define ERR      (-1)#define UW_ERR   (uint)(0xFFFF)#define isodd_word(val)   ((((uint)val) & (uint)0x0001) != 0)#define PCI_VENDOR_ID_ASP		0x10cd#define PCI_DEVICE_ID_ASP_1200A		0x1100#define PCI_DEVICE_ID_ASP_ABP940	0x1200#define PCI_DEVICE_ID_ASP_ABP940U	0x1300#define PCI_DEVICE_ID_ASP_ABP940UW	0x2300#define PCI_DEVICE_ID_38C0800_REV1	0x2500#define PCI_DEVICE_ID_38C1600_REV1	0x2700/* * Enable CC_VERY_LONG_SG_LIST to support up to 64K element SG lists. * The SRB structure will have to be changed and the ASC_SRB2SCSIQ() * macro re-defined to be able to obtain a ASC_SCSI_Q pointer from the * SRB structure. */#define CC_VERY_LONG_SG_LIST 0#define ASC_SRB2SCSIQ(srb_ptr)  (srb_ptr)#define PortAddr                 unsigned int	/* port address size  */#define inp(port)                inb(port)#define outp(port, byte)         outb((byte), (port))#define inpw(port)               inw(port)#define outpw(port, word)        outw((word), (port))#define ASC_MAX_SG_QUEUE    7#define ASC_MAX_SG_LIST     255#define ASC_CS_TYPE  unsigned short#define ASC_IS_ISA          (0x0001)#define ASC_IS_ISAPNP       (0x0081)#define ASC_IS_EISA         (0x0002)#define ASC_IS_PCI          (0x0004)#define ASC_IS_PCI_ULTRA    (0x0104)#define ASC_IS_PCMCIA       (0x0008)#define ASC_IS_MCA          (0x0020)#define ASC_IS_VL           (0x0040)#define ASC_IS_WIDESCSI_16  (0x0100)#define ASC_IS_WIDESCSI_32  (0x0200)#define ASC_IS_BIG_ENDIAN   (0x8000)#define ASC_CHIP_MIN_VER_VL      (0x01)#define ASC_CHIP_MAX_VER_VL      (0x07)#define ASC_CHIP_MIN_VER_PCI     (0x09)#define ASC_CHIP_MAX_VER_PCI     (0x0F)#define ASC_CHIP_VER_PCI_BIT     (0x08)#define ASC_CHIP_MIN_VER_ISA     (0x11)#define ASC_CHIP_MIN_VER_ISA_PNP (0x21)#define ASC_CHIP_MAX_VER_ISA     (0x27)#define ASC_CHIP_VER_ISA_BIT     (0x30)#define ASC_CHIP_VER_ISAPNP_BIT  (0x20)#define ASC_CHIP_VER_ASYN_BUG    (0x21)#define ASC_CHIP_VER_PCI             0x08#define ASC_CHIP_VER_PCI_ULTRA_3150  (ASC_CHIP_VER_PCI | 0x02)#define ASC_CHIP_VER_PCI_ULTRA_3050  (ASC_CHIP_VER_PCI | 0x03)#define ASC_CHIP_MIN_VER_EISA (0x41)#define ASC_CHIP_MAX_VER_EISA (0x47)#define ASC_CHIP_VER_EISA_BIT (0x40)#define ASC_CHIP_LATEST_VER_EISA   ((ASC_CHIP_MIN_VER_EISA - 1) + 3)#define ASC_MAX_VL_DMA_COUNT    (0x07FFFFFFL)#define ASC_MAX_PCI_DMA_COUNT   (0xFFFFFFFFL)#define ASC_MAX_ISA_DMA_COUNT   (0x00FFFFFFL)#define ASC_SCSI_ID_BITS  3#define ASC_SCSI_TIX_TYPE     uchar#define ASC_ALL_DEVICE_BIT_SET  0xFF#define ASC_SCSI_BIT_ID_TYPE  uchar#define ASC_MAX_TID       7#define ASC_MAX_LUN       7#define ASC_SCSI_WIDTH_BIT_SET  0xFF#define ASC_MAX_SENSE_LEN   32#define ASC_MIN_SENSE_LEN   14#define ASC_SCSI_RESET_HOLD_TIME_US  60/* * Narrow boards only support 12-byte commands, while wide boards * extend to 16-byte commands. */#define ASC_MAX_CDB_LEN     12#define ADV_MAX_CDB_LEN     16#define MS_SDTR_LEN    0x03#define MS_WDTR_LEN    0x02#define ASC_SG_LIST_PER_Q   7#define QS_FREE        0x00#define QS_READY       0x01#define QS_DISC1       0x02#define QS_DISC2       0x04#define QS_BUSY        0x08#define QS_ABORTED     0x40#define QS_DONE        0x80#define QC_NO_CALLBACK   0x01#define QC_SG_SWAP_QUEUE 0x02#define QC_SG_HEAD       0x04#define QC_DATA_IN       0x08#define QC_DATA_OUT      0x10#define QC_URGENT        0x20#define QC_MSG_OUT       0x40#define QC_REQ_SENSE     0x80#define QCSG_SG_XFER_LIST  0x02#define QCSG_SG_XFER_MORE  0x04#define QCSG_SG_XFER_END   0x08#define QD_IN_PROGRESS       0x00#define QD_NO_ERROR          0x01#define QD_ABORTED_BY_HOST   0x02#define QD_WITH_ERROR        0x04#define QD_INVALID_REQUEST   0x80#define QD_INVALID_HOST_NUM  0x81#define QD_INVALID_DEVICE    0x82#define QD_ERR_INTERNAL      0xFF#define QHSTA_NO_ERROR               0x00#define QHSTA_M_SEL_TIMEOUT          0x11#define QHSTA_M_DATA_OVER_RUN        0x12#define QHSTA_M_DATA_UNDER_RUN       0x12#define QHSTA_M_UNEXPECTED_BUS_FREE  0x13#define QHSTA_M_BAD_BUS_PHASE_SEQ    0x14#define QHSTA_D_QDONE_SG_LIST_CORRUPTED 0x21#define QHSTA_D_ASC_DVC_ERROR_CODE_SET  0x22#define QHSTA_D_HOST_ABORT_FAILED       0x23#define QHSTA_D_EXE_SCSI_Q_FAILED       0x24#define QHSTA_D_EXE_SCSI_Q_BUSY_TIMEOUT 0x25#define QHSTA_D_ASPI_NO_BUF_POOL        0x26#define QHSTA_M_WTM_TIMEOUT         0x41#define QHSTA_M_BAD_CMPL_STATUS_IN  0x42#define QHSTA_M_NO_AUTO_REQ_SENSE   0x43#define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44#define QHSTA_M_TARGET_STATUS_BUSY  0x45#define QHSTA_M_BAD_TAG_CODE        0x46#define QHSTA_M_BAD_QUEUE_FULL_OR_BUSY  0x47#define QHSTA_M_HUNG_REQ_SCSI_BUS_RESET 0x48#define QHSTA_D_LRAM_CMP_ERROR        0x81#define QHSTA_M_MICRO_CODE_ERROR_HALT 0xA1#define ASC_FLAG_SCSIQ_REQ        0x01#define ASC_FLAG_BIOS_SCSIQ_REQ   0x02#define ASC_FLAG_BIOS_ASYNC_IO    0x04#define ASC_FLAG_SRB_LINEAR_ADDR  0x08#define ASC_FLAG_WIN16            0x10#define ASC_FLAG_WIN32            0x20#define ASC_FLAG_ISA_OVER_16MB    0x40#define ASC_FLAG_DOS_VM_CALLBACK  0x80#define ASC_TAG_FLAG_EXTRA_BYTES               0x10#define ASC_TAG_FLAG_DISABLE_DISCONNECT        0x04#define ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX  0x08#define ASC_TAG_FLAG_DISABLE_CHK_COND_INT_HOST 0x40#define ASC_SCSIQ_CPY_BEG              4#define ASC_SCSIQ_SGHD_CPY_BEG         2#define ASC_SCSIQ_B_FWD                0#define ASC_SCSIQ_B_BWD                1#define ASC_SCSIQ_B_STATUS             2#define ASC_SCSIQ_B_QNO                3#define ASC_SCSIQ_B_CNTL               4#define ASC_SCSIQ_B_SG_QUEUE_CNT       5#define ASC_SCSIQ_D_DATA_ADDR          8#define ASC_SCSIQ_D_DATA_CNT          12#define ASC_SCSIQ_B_SENSE_LEN         20#define ASC_SCSIQ_DONE_INFO_BEG       22#define ASC_SCSIQ_D_SRBPTR            22#define ASC_SCSIQ_B_TARGET_IX         26#define ASC_SCSIQ_B_CDB_LEN           28#define ASC_SCSIQ_B_TAG_CODE          29#define ASC_SCSIQ_W_VM_ID             30#define ASC_SCSIQ_DONE_STATUS         32#define ASC_SCSIQ_HOST_STATUS         33#define ASC_SCSIQ_SCSI_STATUS         34#define ASC_SCSIQ_CDB_BEG             36#define ASC_SCSIQ_DW_REMAIN_XFER_ADDR 56#define ASC_SCSIQ_DW_REMAIN_XFER_CNT  60#define ASC_SCSIQ_B_FIRST_SG_WK_QP    48#define ASC_SCSIQ_B_SG_WK_QP          49#define ASC_SCSIQ_B_SG_WK_IX          50#define ASC_SCSIQ_W_ALT_DC1           52#define ASC_SCSIQ_B_LIST_CNT          6#define ASC_SCSIQ_B_CUR_LIST_CNT      7#define ASC_SGQ_B_SG_CNTL             4#define ASC_SGQ_B_SG_HEAD_QP          5#define ASC_SGQ_B_SG_LIST_CNT         6#define ASC_SGQ_B_SG_CUR_LIST_CNT     7#define ASC_SGQ_LIST_BEG              8#define ASC_DEF_SCSI1_QNG    4#define ASC_MAX_SCSI1_QNG    4#define ASC_DEF_SCSI2_QNG    16#define ASC_MAX_SCSI2_QNG    32#define ASC_TAG_CODE_MASK    0x23#define ASC_STOP_REQ_RISC_STOP      0x01#define ASC_STOP_ACK_RISC_STOP      0x03#define ASC_STOP_CLEAN_UP_BUSY_Q    0x10#define ASC_STOP_CLEAN_UP_DISC_Q    0x20#define ASC_STOP_HOST_REQ_RISC_HALT 0x40#define ASC_TIDLUN_TO_IX(tid, lun)  (ASC_SCSI_TIX_TYPE)((tid) + ((lun)<<ASC_SCSI_ID_BITS))#define ASC_TID_TO_TARGET_ID(tid)   (ASC_SCSI_BIT_ID_TYPE)(0x01 << (tid))#define ASC_TIX_TO_TARGET_ID(tix)   (0x01 << ((tix) & ASC_MAX_TID))#define ASC_TIX_TO_TID(tix)         ((tix) & ASC_MAX_TID)#define ASC_TID_TO_TIX(tid)         ((tid) & ASC_MAX_TID)#define ASC_TIX_TO_LUN(tix)         (((tix) >> ASC_SCSI_ID_BITS) & ASC_MAX_LUN)#define ASC_QNO_TO_QADDR(q_no)      ((ASC_QADR_BEG)+((int)(q_no) << 6))typedef struct asc_scsiq_1 {	uchar status;	uchar q_no;	uchar cntl;	uchar sg_queue_cnt;	uchar target_id;	uchar target_lun;	ASC_PADDR data_addr;	ASC_DCNT data_cnt;	ASC_PADDR sense_addr;	uchar sense_len;	uchar extra_bytes;} ASC_SCSIQ_1;typedef struct asc_scsiq_2 {	ASC_VADDR srb_ptr;	uchar target_ix;	uchar flag;	uchar cdb_len;	uchar tag_code;	ushort vm_id;} ASC_SCSIQ_2;typedef struct asc_scsiq_3 {	uchar done_stat;	uchar host_stat;	uchar scsi_stat;	uchar scsi_msg;} ASC_SCSIQ_3;typedef struct asc_scsiq_4 {	uchar cdb[ASC_MAX_CDB_LEN];	uchar y_first_sg_list_qp;	uchar y_working_sg_qp;	uchar y_working_sg_ix;	uchar y_res;	ushort x_req_count;	ushort x_reconnect_rtn;	ASC_PADDR x_saved_data_addr;	ASC_DCNT x_saved_data_cnt;} ASC_SCSIQ_4;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?