Matthew Wilcox | 01fbfe0 | 2007-09-09 08:56:40 -0600 | [diff] [blame] | 1 | #define DRV_NAME "advansys" |
Matthew Wilcox | 8c6af9e | 2007-07-26 11:03:19 -0400 | [diff] [blame] | 2 | #define ASC_VERSION "3.4" /* AdvanSys Driver Version */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | |
| 4 | /* |
| 5 | * advansys.c - Linux Host Driver for AdvanSys SCSI Adapters |
| 6 | * |
| 7 | * Copyright (c) 1995-2000 Advanced System Products, Inc. |
| 8 | * Copyright (c) 2000-2001 ConnectCom Solutions, Inc. |
Matthew Wilcox | 8c6af9e | 2007-07-26 11:03:19 -0400 | [diff] [blame] | 9 | * Copyright (c) 2007 Matthew Wilcox <matthew@wil.cx> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * All Rights Reserved. |
| 11 | * |
Matthew Wilcox | 8c6af9e | 2007-07-26 11:03:19 -0400 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | */ |
| 17 | |
| 18 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * As of March 8, 2000 Advanced System Products, Inc. (AdvanSys) |
| 20 | * changed its name to ConnectCom Solutions, Inc. |
Matthew Wilcox | 8c6af9e | 2007-07-26 11:03:19 -0400 | [diff] [blame] | 21 | * On June 18, 2001 Initio Corp. acquired ConnectCom's SCSI assets |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | */ |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/string.h> |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/types.h> |
| 28 | #include <linux/ioport.h> |
| 29 | #include <linux/interrupt.h> |
| 30 | #include <linux/delay.h> |
| 31 | #include <linux/slab.h> |
| 32 | #include <linux/mm.h> |
| 33 | #include <linux/proc_fs.h> |
| 34 | #include <linux/init.h> |
| 35 | #include <linux/blkdev.h> |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 36 | #include <linux/isa.h> |
Matthew Wilcox | b09e05a | 2007-07-30 09:14:52 -0600 | [diff] [blame] | 37 | #include <linux/eisa.h> |
Matthew Wilcox | 8c6af9e | 2007-07-26 11:03:19 -0400 | [diff] [blame] | 38 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/spinlock.h> |
| 40 | #include <linux/dma-mapping.h> |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 41 | #include <linux/firmware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <asm/dma.h> |
| 45 | |
Matthew Wilcox | 8c6af9e | 2007-07-26 11:03:19 -0400 | [diff] [blame] | 46 | #include <scsi/scsi_cmnd.h> |
| 47 | #include <scsi/scsi_device.h> |
| 48 | #include <scsi/scsi_tcq.h> |
| 49 | #include <scsi/scsi.h> |
| 50 | #include <scsi/scsi_host.h> |
| 51 | |
Matthew Wilcox | 4bd6d7f | 2007-07-30 08:41:03 -0600 | [diff] [blame] | 52 | /* FIXME: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | * |
Matthew Wilcox | 4bd6d7f | 2007-07-30 08:41:03 -0600 | [diff] [blame] | 54 | * 1. Although all of the necessary command mapping places have the |
| 55 | * appropriate dma_map.. APIs, the driver still processes its internal |
| 56 | * queue using bus_to_virt() and virt_to_bus() which are illegal under |
| 57 | * the API. The entire queue processing structure will need to be |
| 58 | * altered to fix this. |
| 59 | * 2. Need to add memory mapping workaround. Test the memory mapping. |
| 60 | * If it doesn't work revert to I/O port access. Can a test be done |
| 61 | * safely? |
| 62 | * 3. Handle an interrupt not working. Keep an interrupt counter in |
| 63 | * the interrupt handler. In the timeout function if the interrupt |
| 64 | * has not occurred then print a message and run in polled mode. |
| 65 | * 4. Need to add support for target mode commands, cf. CAM XPT. |
| 66 | * 5. check DMA mapping functions for failure |
Matthew Wilcox | 349d2c4 | 2007-09-09 08:56:34 -0600 | [diff] [blame] | 67 | * 6. Use scsi_transport_spi |
| 68 | * 7. advansys_info is not safe against multiple simultaneous callers |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 69 | * 8. Add module_param to override ISA/VLB ioport array |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | */ |
| 71 | #warning this driver is still not properly converted to the DMA API |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | /* Enable driver /proc statistics. */ |
| 74 | #define ADVANSYS_STATS |
| 75 | |
| 76 | /* Enable driver tracing. */ |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 77 | #undef ADVANSYS_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | /* |
| 80 | * Portable Data Types |
| 81 | * |
| 82 | * Any instance where a 32-bit long or pointer type is assumed |
| 83 | * for precision or HW defined structures, the following define |
| 84 | * types must be used. In Linux the char, short, and int types |
| 85 | * are all consistent at 8, 16, and 32 bits respectively. Pointers |
| 86 | * and long types are 64 bits on Alpha and UltraSPARC. |
| 87 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 88 | #define ASC_PADDR __u32 /* Physical/Bus address data type. */ |
| 89 | #define ASC_VADDR __u32 /* Virtual address data type. */ |
| 90 | #define ASC_DCNT __u32 /* Unsigned Data count type. */ |
| 91 | #define ASC_SDCNT __s32 /* Signed Data count type. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | typedef unsigned char uchar; |
| 94 | |
| 95 | #ifndef TRUE |
| 96 | #define TRUE (1) |
| 97 | #endif |
| 98 | #ifndef FALSE |
| 99 | #define FALSE (0) |
| 100 | #endif |
| 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | #define ERR (-1) |
| 103 | #define UW_ERR (uint)(0xFFFF) |
| 104 | #define isodd_word(val) ((((uint)val) & (uint)0x0001) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
Dave Jones | 2672ea8 | 2006-08-02 17:11:49 -0400 | [diff] [blame] | 106 | #define PCI_VENDOR_ID_ASP 0x10cd |
| 107 | #define PCI_DEVICE_ID_ASP_1200A 0x1100 |
| 108 | #define PCI_DEVICE_ID_ASP_ABP940 0x1200 |
| 109 | #define PCI_DEVICE_ID_ASP_ABP940U 0x1300 |
| 110 | #define PCI_DEVICE_ID_ASP_ABP940UW 0x2300 |
| 111 | #define PCI_DEVICE_ID_38C0800_REV1 0x2500 |
| 112 | #define PCI_DEVICE_ID_38C1600_REV1 0x2700 |
| 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | /* |
| 115 | * Enable CC_VERY_LONG_SG_LIST to support up to 64K element SG lists. |
| 116 | * The SRB structure will have to be changed and the ASC_SRB2SCSIQ() |
| 117 | * macro re-defined to be able to obtain a ASC_SCSI_Q pointer from the |
| 118 | * SRB structure. |
| 119 | */ |
| 120 | #define CC_VERY_LONG_SG_LIST 0 |
| 121 | #define ASC_SRB2SCSIQ(srb_ptr) (srb_ptr) |
| 122 | |
Matthew Wilcox | 9d511a4 | 2007-10-02 21:55:42 -0400 | [diff] [blame] | 123 | #define PortAddr unsigned int /* port address size */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | #define inp(port) inb(port) |
| 125 | #define outp(port, byte) outb((byte), (port)) |
| 126 | |
| 127 | #define inpw(port) inw(port) |
| 128 | #define outpw(port, word) outw((word), (port)) |
| 129 | |
| 130 | #define ASC_MAX_SG_QUEUE 7 |
| 131 | #define ASC_MAX_SG_LIST 255 |
| 132 | |
| 133 | #define ASC_CS_TYPE unsigned short |
| 134 | |
| 135 | #define ASC_IS_ISA (0x0001) |
| 136 | #define ASC_IS_ISAPNP (0x0081) |
| 137 | #define ASC_IS_EISA (0x0002) |
| 138 | #define ASC_IS_PCI (0x0004) |
| 139 | #define ASC_IS_PCI_ULTRA (0x0104) |
| 140 | #define ASC_IS_PCMCIA (0x0008) |
| 141 | #define ASC_IS_MCA (0x0020) |
| 142 | #define ASC_IS_VL (0x0040) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | #define ASC_IS_WIDESCSI_16 (0x0100) |
| 144 | #define ASC_IS_WIDESCSI_32 (0x0200) |
| 145 | #define ASC_IS_BIG_ENDIAN (0x8000) |
Matthew Wilcox | 95c9f16 | 2007-09-09 08:56:39 -0600 | [diff] [blame] | 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | #define ASC_CHIP_MIN_VER_VL (0x01) |
| 148 | #define ASC_CHIP_MAX_VER_VL (0x07) |
| 149 | #define ASC_CHIP_MIN_VER_PCI (0x09) |
| 150 | #define ASC_CHIP_MAX_VER_PCI (0x0F) |
| 151 | #define ASC_CHIP_VER_PCI_BIT (0x08) |
| 152 | #define ASC_CHIP_MIN_VER_ISA (0x11) |
| 153 | #define ASC_CHIP_MIN_VER_ISA_PNP (0x21) |
| 154 | #define ASC_CHIP_MAX_VER_ISA (0x27) |
| 155 | #define ASC_CHIP_VER_ISA_BIT (0x30) |
| 156 | #define ASC_CHIP_VER_ISAPNP_BIT (0x20) |
| 157 | #define ASC_CHIP_VER_ASYN_BUG (0x21) |
| 158 | #define ASC_CHIP_VER_PCI 0x08 |
| 159 | #define ASC_CHIP_VER_PCI_ULTRA_3150 (ASC_CHIP_VER_PCI | 0x02) |
| 160 | #define ASC_CHIP_VER_PCI_ULTRA_3050 (ASC_CHIP_VER_PCI | 0x03) |
| 161 | #define ASC_CHIP_MIN_VER_EISA (0x41) |
| 162 | #define ASC_CHIP_MAX_VER_EISA (0x47) |
| 163 | #define ASC_CHIP_VER_EISA_BIT (0x40) |
| 164 | #define ASC_CHIP_LATEST_VER_EISA ((ASC_CHIP_MIN_VER_EISA - 1) + 3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | #define ASC_MAX_VL_DMA_COUNT (0x07FFFFFFL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | #define ASC_MAX_PCI_DMA_COUNT (0xFFFFFFFFL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | #define ASC_MAX_ISA_DMA_COUNT (0x00FFFFFFL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
| 169 | #define ASC_SCSI_ID_BITS 3 |
| 170 | #define ASC_SCSI_TIX_TYPE uchar |
| 171 | #define ASC_ALL_DEVICE_BIT_SET 0xFF |
| 172 | #define ASC_SCSI_BIT_ID_TYPE uchar |
| 173 | #define ASC_MAX_TID 7 |
| 174 | #define ASC_MAX_LUN 7 |
| 175 | #define ASC_SCSI_WIDTH_BIT_SET 0xFF |
| 176 | #define ASC_MAX_SENSE_LEN 32 |
| 177 | #define ASC_MIN_SENSE_LEN 14 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | #define ASC_SCSI_RESET_HOLD_TIME_US 60 |
| 179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | /* |
Matthew Wilcox | f05ec59 | 2007-09-09 08:56:36 -0600 | [diff] [blame] | 181 | * Narrow boards only support 12-byte commands, while wide boards |
| 182 | * extend to 16-byte commands. |
| 183 | */ |
| 184 | #define ASC_MAX_CDB_LEN 12 |
| 185 | #define ADV_MAX_CDB_LEN 16 |
| 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | #define MS_SDTR_LEN 0x03 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | #define MS_WDTR_LEN 0x02 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
| 190 | #define ASC_SG_LIST_PER_Q 7 |
| 191 | #define QS_FREE 0x00 |
| 192 | #define QS_READY 0x01 |
| 193 | #define QS_DISC1 0x02 |
| 194 | #define QS_DISC2 0x04 |
| 195 | #define QS_BUSY 0x08 |
| 196 | #define QS_ABORTED 0x40 |
| 197 | #define QS_DONE 0x80 |
| 198 | #define QC_NO_CALLBACK 0x01 |
| 199 | #define QC_SG_SWAP_QUEUE 0x02 |
| 200 | #define QC_SG_HEAD 0x04 |
| 201 | #define QC_DATA_IN 0x08 |
| 202 | #define QC_DATA_OUT 0x10 |
| 203 | #define QC_URGENT 0x20 |
| 204 | #define QC_MSG_OUT 0x40 |
| 205 | #define QC_REQ_SENSE 0x80 |
| 206 | #define QCSG_SG_XFER_LIST 0x02 |
| 207 | #define QCSG_SG_XFER_MORE 0x04 |
| 208 | #define QCSG_SG_XFER_END 0x08 |
| 209 | #define QD_IN_PROGRESS 0x00 |
| 210 | #define QD_NO_ERROR 0x01 |
| 211 | #define QD_ABORTED_BY_HOST 0x02 |
| 212 | #define QD_WITH_ERROR 0x04 |
| 213 | #define QD_INVALID_REQUEST 0x80 |
| 214 | #define QD_INVALID_HOST_NUM 0x81 |
| 215 | #define QD_INVALID_DEVICE 0x82 |
| 216 | #define QD_ERR_INTERNAL 0xFF |
| 217 | #define QHSTA_NO_ERROR 0x00 |
| 218 | #define QHSTA_M_SEL_TIMEOUT 0x11 |
| 219 | #define QHSTA_M_DATA_OVER_RUN 0x12 |
| 220 | #define QHSTA_M_DATA_UNDER_RUN 0x12 |
| 221 | #define QHSTA_M_UNEXPECTED_BUS_FREE 0x13 |
| 222 | #define QHSTA_M_BAD_BUS_PHASE_SEQ 0x14 |
| 223 | #define QHSTA_D_QDONE_SG_LIST_CORRUPTED 0x21 |
| 224 | #define QHSTA_D_ASC_DVC_ERROR_CODE_SET 0x22 |
| 225 | #define QHSTA_D_HOST_ABORT_FAILED 0x23 |
| 226 | #define QHSTA_D_EXE_SCSI_Q_FAILED 0x24 |
| 227 | #define QHSTA_D_EXE_SCSI_Q_BUSY_TIMEOUT 0x25 |
| 228 | #define QHSTA_D_ASPI_NO_BUF_POOL 0x26 |
| 229 | #define QHSTA_M_WTM_TIMEOUT 0x41 |
| 230 | #define QHSTA_M_BAD_CMPL_STATUS_IN 0x42 |
| 231 | #define QHSTA_M_NO_AUTO_REQ_SENSE 0x43 |
| 232 | #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44 |
| 233 | #define QHSTA_M_TARGET_STATUS_BUSY 0x45 |
| 234 | #define QHSTA_M_BAD_TAG_CODE 0x46 |
| 235 | #define QHSTA_M_BAD_QUEUE_FULL_OR_BUSY 0x47 |
| 236 | #define QHSTA_M_HUNG_REQ_SCSI_BUS_RESET 0x48 |
| 237 | #define QHSTA_D_LRAM_CMP_ERROR 0x81 |
| 238 | #define QHSTA_M_MICRO_CODE_ERROR_HALT 0xA1 |
| 239 | #define ASC_FLAG_SCSIQ_REQ 0x01 |
| 240 | #define ASC_FLAG_BIOS_SCSIQ_REQ 0x02 |
| 241 | #define ASC_FLAG_BIOS_ASYNC_IO 0x04 |
| 242 | #define ASC_FLAG_SRB_LINEAR_ADDR 0x08 |
| 243 | #define ASC_FLAG_WIN16 0x10 |
| 244 | #define ASC_FLAG_WIN32 0x20 |
| 245 | #define ASC_FLAG_ISA_OVER_16MB 0x40 |
| 246 | #define ASC_FLAG_DOS_VM_CALLBACK 0x80 |
| 247 | #define ASC_TAG_FLAG_EXTRA_BYTES 0x10 |
| 248 | #define ASC_TAG_FLAG_DISABLE_DISCONNECT 0x04 |
| 249 | #define ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX 0x08 |
| 250 | #define ASC_TAG_FLAG_DISABLE_CHK_COND_INT_HOST 0x40 |
| 251 | #define ASC_SCSIQ_CPY_BEG 4 |
| 252 | #define ASC_SCSIQ_SGHD_CPY_BEG 2 |
| 253 | #define ASC_SCSIQ_B_FWD 0 |
| 254 | #define ASC_SCSIQ_B_BWD 1 |
| 255 | #define ASC_SCSIQ_B_STATUS 2 |
| 256 | #define ASC_SCSIQ_B_QNO 3 |
| 257 | #define ASC_SCSIQ_B_CNTL 4 |
| 258 | #define ASC_SCSIQ_B_SG_QUEUE_CNT 5 |
| 259 | #define ASC_SCSIQ_D_DATA_ADDR 8 |
| 260 | #define ASC_SCSIQ_D_DATA_CNT 12 |
| 261 | #define ASC_SCSIQ_B_SENSE_LEN 20 |
| 262 | #define ASC_SCSIQ_DONE_INFO_BEG 22 |
| 263 | #define ASC_SCSIQ_D_SRBPTR 22 |
| 264 | #define ASC_SCSIQ_B_TARGET_IX 26 |
| 265 | #define ASC_SCSIQ_B_CDB_LEN 28 |
| 266 | #define ASC_SCSIQ_B_TAG_CODE 29 |
| 267 | #define ASC_SCSIQ_W_VM_ID 30 |
| 268 | #define ASC_SCSIQ_DONE_STATUS 32 |
| 269 | #define ASC_SCSIQ_HOST_STATUS 33 |
| 270 | #define ASC_SCSIQ_SCSI_STATUS 34 |
| 271 | #define ASC_SCSIQ_CDB_BEG 36 |
| 272 | #define ASC_SCSIQ_DW_REMAIN_XFER_ADDR 56 |
| 273 | #define ASC_SCSIQ_DW_REMAIN_XFER_CNT 60 |
| 274 | #define ASC_SCSIQ_B_FIRST_SG_WK_QP 48 |
| 275 | #define ASC_SCSIQ_B_SG_WK_QP 49 |
| 276 | #define ASC_SCSIQ_B_SG_WK_IX 50 |
| 277 | #define ASC_SCSIQ_W_ALT_DC1 52 |
| 278 | #define ASC_SCSIQ_B_LIST_CNT 6 |
| 279 | #define ASC_SCSIQ_B_CUR_LIST_CNT 7 |
| 280 | #define ASC_SGQ_B_SG_CNTL 4 |
| 281 | #define ASC_SGQ_B_SG_HEAD_QP 5 |
| 282 | #define ASC_SGQ_B_SG_LIST_CNT 6 |
| 283 | #define ASC_SGQ_B_SG_CUR_LIST_CNT 7 |
| 284 | #define ASC_SGQ_LIST_BEG 8 |
| 285 | #define ASC_DEF_SCSI1_QNG 4 |
| 286 | #define ASC_MAX_SCSI1_QNG 4 |
| 287 | #define ASC_DEF_SCSI2_QNG 16 |
| 288 | #define ASC_MAX_SCSI2_QNG 32 |
| 289 | #define ASC_TAG_CODE_MASK 0x23 |
| 290 | #define ASC_STOP_REQ_RISC_STOP 0x01 |
| 291 | #define ASC_STOP_ACK_RISC_STOP 0x03 |
| 292 | #define ASC_STOP_CLEAN_UP_BUSY_Q 0x10 |
| 293 | #define ASC_STOP_CLEAN_UP_DISC_Q 0x20 |
| 294 | #define ASC_STOP_HOST_REQ_RISC_HALT 0x40 |
| 295 | #define ASC_TIDLUN_TO_IX(tid, lun) (ASC_SCSI_TIX_TYPE)((tid) + ((lun)<<ASC_SCSI_ID_BITS)) |
| 296 | #define ASC_TID_TO_TARGET_ID(tid) (ASC_SCSI_BIT_ID_TYPE)(0x01 << (tid)) |
| 297 | #define ASC_TIX_TO_TARGET_ID(tix) (0x01 << ((tix) & ASC_MAX_TID)) |
| 298 | #define ASC_TIX_TO_TID(tix) ((tix) & ASC_MAX_TID) |
| 299 | #define ASC_TID_TO_TIX(tid) ((tid) & ASC_MAX_TID) |
| 300 | #define ASC_TIX_TO_LUN(tix) (((tix) >> ASC_SCSI_ID_BITS) & ASC_MAX_LUN) |
| 301 | #define ASC_QNO_TO_QADDR(q_no) ((ASC_QADR_BEG)+((int)(q_no) << 6)) |
| 302 | |
| 303 | typedef struct asc_scsiq_1 { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 304 | uchar status; |
| 305 | uchar q_no; |
| 306 | uchar cntl; |
| 307 | uchar sg_queue_cnt; |
| 308 | uchar target_id; |
| 309 | uchar target_lun; |
| 310 | ASC_PADDR data_addr; |
| 311 | ASC_DCNT data_cnt; |
| 312 | ASC_PADDR sense_addr; |
| 313 | uchar sense_len; |
| 314 | uchar extra_bytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | } ASC_SCSIQ_1; |
| 316 | |
| 317 | typedef struct asc_scsiq_2 { |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 318 | u32 srb_tag; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 319 | uchar target_ix; |
| 320 | uchar flag; |
| 321 | uchar cdb_len; |
| 322 | uchar tag_code; |
| 323 | ushort vm_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | } ASC_SCSIQ_2; |
| 325 | |
| 326 | typedef struct asc_scsiq_3 { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 327 | uchar done_stat; |
| 328 | uchar host_stat; |
| 329 | uchar scsi_stat; |
| 330 | uchar scsi_msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | } ASC_SCSIQ_3; |
| 332 | |
| 333 | typedef struct asc_scsiq_4 { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 334 | uchar cdb[ASC_MAX_CDB_LEN]; |
| 335 | uchar y_first_sg_list_qp; |
| 336 | uchar y_working_sg_qp; |
| 337 | uchar y_working_sg_ix; |
| 338 | uchar y_res; |
| 339 | ushort x_req_count; |
| 340 | ushort x_reconnect_rtn; |
| 341 | ASC_PADDR x_saved_data_addr; |
| 342 | ASC_DCNT x_saved_data_cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } ASC_SCSIQ_4; |
| 344 | |
| 345 | typedef struct asc_q_done_info { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 346 | ASC_SCSIQ_2 d2; |
| 347 | ASC_SCSIQ_3 d3; |
| 348 | uchar q_status; |
| 349 | uchar q_no; |
| 350 | uchar cntl; |
| 351 | uchar sense_len; |
| 352 | uchar extra_bytes; |
| 353 | uchar res; |
| 354 | ASC_DCNT remain_bytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } ASC_QDONE_INFO; |
| 356 | |
| 357 | typedef struct asc_sg_list { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 358 | ASC_PADDR addr; |
| 359 | ASC_DCNT bytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | } ASC_SG_LIST; |
| 361 | |
| 362 | typedef struct asc_sg_head { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 363 | ushort entry_cnt; |
| 364 | ushort queue_cnt; |
| 365 | ushort entry_to_copy; |
| 366 | ushort res; |
Matthew Wilcox | 05848b6 | 2007-10-02 21:55:25 -0400 | [diff] [blame] | 367 | ASC_SG_LIST sg_list[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | } ASC_SG_HEAD; |
| 369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | typedef struct asc_scsi_q { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 371 | ASC_SCSIQ_1 q1; |
| 372 | ASC_SCSIQ_2 q2; |
| 373 | uchar *cdbptr; |
| 374 | ASC_SG_HEAD *sg_head; |
| 375 | ushort remain_sg_entry_cnt; |
| 376 | ushort next_sg_index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | } ASC_SCSI_Q; |
| 378 | |
| 379 | typedef struct asc_scsi_req_q { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 380 | ASC_SCSIQ_1 r1; |
| 381 | ASC_SCSIQ_2 r2; |
| 382 | uchar *cdbptr; |
| 383 | ASC_SG_HEAD *sg_head; |
| 384 | uchar *sense_ptr; |
| 385 | ASC_SCSIQ_3 r3; |
| 386 | uchar cdb[ASC_MAX_CDB_LEN]; |
| 387 | uchar sense[ASC_MIN_SENSE_LEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | } ASC_SCSI_REQ_Q; |
| 389 | |
| 390 | typedef struct asc_scsi_bios_req_q { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 391 | ASC_SCSIQ_1 r1; |
| 392 | ASC_SCSIQ_2 r2; |
| 393 | uchar *cdbptr; |
| 394 | ASC_SG_HEAD *sg_head; |
| 395 | uchar *sense_ptr; |
| 396 | ASC_SCSIQ_3 r3; |
| 397 | uchar cdb[ASC_MAX_CDB_LEN]; |
| 398 | uchar sense[ASC_MIN_SENSE_LEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } ASC_SCSI_BIOS_REQ_Q; |
| 400 | |
| 401 | typedef struct asc_risc_q { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 402 | uchar fwd; |
| 403 | uchar bwd; |
| 404 | ASC_SCSIQ_1 i1; |
| 405 | ASC_SCSIQ_2 i2; |
| 406 | ASC_SCSIQ_3 i3; |
| 407 | ASC_SCSIQ_4 i4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | } ASC_RISC_Q; |
| 409 | |
| 410 | typedef struct asc_sg_list_q { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 411 | uchar seq_no; |
| 412 | uchar q_no; |
| 413 | uchar cntl; |
| 414 | uchar sg_head_qp; |
| 415 | uchar sg_list_cnt; |
| 416 | uchar sg_cur_list_cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } ASC_SG_LIST_Q; |
| 418 | |
| 419 | typedef struct asc_risc_sg_list_q { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 420 | uchar fwd; |
| 421 | uchar bwd; |
| 422 | ASC_SG_LIST_Q sg; |
| 423 | ASC_SG_LIST sg_list[7]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | } ASC_RISC_SG_LIST_Q; |
| 425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | #define ASCQ_ERR_Q_STATUS 0x0D |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | #define ASCQ_ERR_CUR_QNG 0x17 |
| 428 | #define ASCQ_ERR_SG_Q_LINKS 0x18 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | #define ASCQ_ERR_ISR_RE_ENTRY 0x1A |
| 430 | #define ASCQ_ERR_CRITICAL_RE_ENTRY 0x1B |
| 431 | #define ASCQ_ERR_ISR_ON_CRITICAL 0x1C |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
| 433 | /* |
| 434 | * Warning code values are set in ASC_DVC_VAR 'warn_code'. |
| 435 | */ |
| 436 | #define ASC_WARN_NO_ERROR 0x0000 |
| 437 | #define ASC_WARN_IO_PORT_ROTATE 0x0001 |
| 438 | #define ASC_WARN_EEPROM_CHKSUM 0x0002 |
| 439 | #define ASC_WARN_IRQ_MODIFIED 0x0004 |
| 440 | #define ASC_WARN_AUTO_CONFIG 0x0008 |
| 441 | #define ASC_WARN_CMD_QNG_CONFLICT 0x0010 |
| 442 | #define ASC_WARN_EEPROM_RECOVER 0x0020 |
| 443 | #define ASC_WARN_CFG_MSW_RECOVER 0x0040 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
| 445 | /* |
Matthew Wilcox | 720349a | 2007-10-02 21:55:30 -0400 | [diff] [blame] | 446 | * Error code values are set in {ASC/ADV}_DVC_VAR 'err_code'. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | */ |
Matthew Wilcox | 720349a | 2007-10-02 21:55:30 -0400 | [diff] [blame] | 448 | #define ASC_IERR_NO_CARRIER 0x0001 /* No more carrier memory */ |
| 449 | #define ASC_IERR_MCODE_CHKSUM 0x0002 /* micro code check sum error */ |
| 450 | #define ASC_IERR_SET_PC_ADDR 0x0004 |
| 451 | #define ASC_IERR_START_STOP_CHIP 0x0008 /* start/stop chip failed */ |
| 452 | #define ASC_IERR_ILLEGAL_CONNECTION 0x0010 /* Illegal cable connection */ |
| 453 | #define ASC_IERR_SINGLE_END_DEVICE 0x0020 /* SE device on DIFF bus */ |
| 454 | #define ASC_IERR_REVERSED_CABLE 0x0040 /* Narrow flat cable reversed */ |
| 455 | #define ASC_IERR_SET_SCSI_ID 0x0080 /* set SCSI ID failed */ |
| 456 | #define ASC_IERR_HVD_DEVICE 0x0100 /* HVD device on LVD port */ |
| 457 | #define ASC_IERR_BAD_SIGNATURE 0x0200 /* signature not found */ |
| 458 | #define ASC_IERR_NO_BUS_TYPE 0x0400 |
| 459 | #define ASC_IERR_BIST_PRE_TEST 0x0800 /* BIST pre-test error */ |
| 460 | #define ASC_IERR_BIST_RAM_TEST 0x1000 /* BIST RAM test error */ |
| 461 | #define ASC_IERR_BAD_CHIPTYPE 0x2000 /* Invalid chip_type setting */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | #define ASC_DEF_MAX_TOTAL_QNG (0xF0) |
| 464 | #define ASC_MIN_TAG_Q_PER_DVC (0x04) |
Matthew Wilcox | 95c9f16 | 2007-09-09 08:56:39 -0600 | [diff] [blame] | 465 | #define ASC_MIN_FREE_Q (0x02) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | #define ASC_MIN_TOTAL_QNG ((ASC_MAX_SG_QUEUE)+(ASC_MIN_FREE_Q)) |
| 467 | #define ASC_MAX_TOTAL_QNG 240 |
| 468 | #define ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG 16 |
| 469 | #define ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG 8 |
| 470 | #define ASC_MAX_PCI_INRAM_TOTAL_QNG 20 |
| 471 | #define ASC_MAX_INRAM_TAG_QNG 16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | #define ASC_IOADR_GAP 0x10 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | #define ASC_SYN_MAX_OFFSET 0x0F |
| 474 | #define ASC_DEF_SDTR_OFFSET 0x0F |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | #define ASC_SDTR_ULTRA_PCI_10MB_INDEX 0x02 |
Matthew Wilcox | afbb68c | 2007-10-02 21:55:36 -0400 | [diff] [blame] | 476 | #define ASYN_SDTR_DATA_FIX_PCI_REV_AB 0x41 |
| 477 | |
| 478 | /* The narrow chip only supports a limited selection of transfer rates. |
| 479 | * These are encoded in the range 0..7 or 0..15 depending whether the chip |
| 480 | * is Ultra-capable or not. These tables let us convert from one to the other. |
| 481 | */ |
| 482 | static const unsigned char asc_syn_xfer_period[8] = { |
| 483 | 25, 30, 35, 40, 50, 60, 70, 85 |
| 484 | }; |
| 485 | |
| 486 | static const unsigned char asc_syn_ultra_xfer_period[16] = { |
| 487 | 12, 19, 25, 32, 38, 44, 50, 57, 63, 69, 75, 82, 88, 94, 100, 107 |
| 488 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
| 490 | typedef struct ext_msg { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 491 | uchar msg_type; |
| 492 | uchar msg_len; |
| 493 | uchar msg_req; |
| 494 | union { |
| 495 | struct { |
| 496 | uchar sdtr_xfer_period; |
| 497 | uchar sdtr_req_ack_offset; |
| 498 | } sdtr; |
| 499 | struct { |
| 500 | uchar wdtr_width; |
| 501 | } wdtr; |
| 502 | struct { |
| 503 | uchar mdp_b3; |
| 504 | uchar mdp_b2; |
| 505 | uchar mdp_b1; |
| 506 | uchar mdp_b0; |
| 507 | } mdp; |
| 508 | } u_ext_msg; |
| 509 | uchar res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | } EXT_MSG; |
| 511 | |
| 512 | #define xfer_period u_ext_msg.sdtr.sdtr_xfer_period |
| 513 | #define req_ack_offset u_ext_msg.sdtr.sdtr_req_ack_offset |
| 514 | #define wdtr_width u_ext_msg.wdtr.wdtr_width |
| 515 | #define mdp_b3 u_ext_msg.mdp_b3 |
| 516 | #define mdp_b2 u_ext_msg.mdp_b2 |
| 517 | #define mdp_b1 u_ext_msg.mdp_b1 |
| 518 | #define mdp_b0 u_ext_msg.mdp_b0 |
| 519 | |
| 520 | typedef struct asc_dvc_cfg { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 521 | ASC_SCSI_BIT_ID_TYPE can_tagged_qng; |
| 522 | ASC_SCSI_BIT_ID_TYPE cmd_qng_enabled; |
| 523 | ASC_SCSI_BIT_ID_TYPE disc_enable; |
| 524 | ASC_SCSI_BIT_ID_TYPE sdtr_enable; |
| 525 | uchar chip_scsi_id; |
| 526 | uchar isa_dma_speed; |
| 527 | uchar isa_dma_channel; |
| 528 | uchar chip_version; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 529 | ushort mcode_date; |
| 530 | ushort mcode_version; |
| 531 | uchar max_tag_qng[ASC_MAX_TID + 1]; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 532 | uchar sdtr_period_offset[ASC_MAX_TID + 1]; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 533 | uchar adapter_info[6]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | } ASC_DVC_CFG; |
| 535 | |
| 536 | #define ASC_DEF_DVC_CNTL 0xFFFF |
| 537 | #define ASC_DEF_CHIP_SCSI_ID 7 |
| 538 | #define ASC_DEF_ISA_DMA_SPEED 4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | #define ASC_INIT_STATE_BEG_GET_CFG 0x0001 |
| 540 | #define ASC_INIT_STATE_END_GET_CFG 0x0002 |
| 541 | #define ASC_INIT_STATE_BEG_SET_CFG 0x0004 |
| 542 | #define ASC_INIT_STATE_END_SET_CFG 0x0008 |
| 543 | #define ASC_INIT_STATE_BEG_LOAD_MC 0x0010 |
| 544 | #define ASC_INIT_STATE_END_LOAD_MC 0x0020 |
| 545 | #define ASC_INIT_STATE_BEG_INQUIRY 0x0040 |
| 546 | #define ASC_INIT_STATE_END_INQUIRY 0x0080 |
| 547 | #define ASC_INIT_RESET_SCSI_DONE 0x0100 |
| 548 | #define ASC_INIT_STATE_WITHOUT_EEP 0x8000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | #define ASC_BUG_FIX_IF_NOT_DWB 0x0001 |
| 550 | #define ASC_BUG_FIX_ASYN_USE_SYN 0x0002 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | #define ASC_MIN_TAGGED_CMD 7 |
| 552 | #define ASC_MAX_SCSI_RESET_WAIT 30 |
Matthew Wilcox | d10fb2c | 2007-10-02 21:55:41 -0400 | [diff] [blame] | 553 | #define ASC_OVERRUN_BSIZE 64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 555 | struct asc_dvc_var; /* Forward Declaration. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | typedef struct asc_dvc_var { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 558 | PortAddr iop_base; |
| 559 | ushort err_code; |
| 560 | ushort dvc_cntl; |
| 561 | ushort bug_fix_cntl; |
| 562 | ushort bus_type; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 563 | ASC_SCSI_BIT_ID_TYPE init_sdtr; |
| 564 | ASC_SCSI_BIT_ID_TYPE sdtr_done; |
| 565 | ASC_SCSI_BIT_ID_TYPE use_tagged_qng; |
| 566 | ASC_SCSI_BIT_ID_TYPE unit_not_ready; |
| 567 | ASC_SCSI_BIT_ID_TYPE queue_full_or_busy; |
| 568 | ASC_SCSI_BIT_ID_TYPE start_motor; |
FUJITA Tomonori | 7d5d408 | 2008-02-08 09:50:08 +0900 | [diff] [blame] | 569 | uchar *overrun_buf; |
Matthew Wilcox | d10fb2c | 2007-10-02 21:55:41 -0400 | [diff] [blame] | 570 | dma_addr_t overrun_dma; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 571 | uchar scsi_reset_wait; |
| 572 | uchar chip_no; |
| 573 | char is_in_int; |
| 574 | uchar max_total_qng; |
| 575 | uchar cur_total_qng; |
| 576 | uchar in_critical_cnt; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 577 | uchar last_q_shortage; |
| 578 | ushort init_state; |
| 579 | uchar cur_dvc_qng[ASC_MAX_TID + 1]; |
| 580 | uchar max_dvc_qng[ASC_MAX_TID + 1]; |
| 581 | ASC_SCSI_Q *scsiq_busy_head[ASC_MAX_TID + 1]; |
| 582 | ASC_SCSI_Q *scsiq_busy_tail[ASC_MAX_TID + 1]; |
Matthew Wilcox | afbb68c | 2007-10-02 21:55:36 -0400 | [diff] [blame] | 583 | const uchar *sdtr_period_tbl; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 584 | ASC_DVC_CFG *cfg; |
| 585 | ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer_always; |
| 586 | char redo_scam; |
| 587 | ushort res2; |
| 588 | uchar dos_int13_table[ASC_MAX_TID + 1]; |
| 589 | ASC_DCNT max_dma_count; |
| 590 | ASC_SCSI_BIT_ID_TYPE no_scam; |
| 591 | ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer; |
Matthew Wilcox | afbb68c | 2007-10-02 21:55:36 -0400 | [diff] [blame] | 592 | uchar min_sdtr_index; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 593 | uchar max_sdtr_index; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 594 | struct asc_board *drv_ptr; |
| 595 | ASC_DCNT uc_break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | } ASC_DVC_VAR; |
| 597 | |
| 598 | typedef struct asc_dvc_inq_info { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 599 | uchar type[ASC_MAX_TID + 1][ASC_MAX_LUN + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | } ASC_DVC_INQ_INFO; |
| 601 | |
| 602 | typedef struct asc_cap_info { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 603 | ASC_DCNT lba; |
| 604 | ASC_DCNT blk_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | } ASC_CAP_INFO; |
| 606 | |
| 607 | typedef struct asc_cap_info_array { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 608 | ASC_CAP_INFO cap_info[ASC_MAX_TID + 1][ASC_MAX_LUN + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | } ASC_CAP_INFO_ARRAY; |
| 610 | |
| 611 | #define ASC_MCNTL_NO_SEL_TIMEOUT (ushort)0x0001 |
| 612 | #define ASC_MCNTL_NULL_TARGET (ushort)0x0002 |
| 613 | #define ASC_CNTL_INITIATOR (ushort)0x0001 |
| 614 | #define ASC_CNTL_BIOS_GT_1GB (ushort)0x0002 |
| 615 | #define ASC_CNTL_BIOS_GT_2_DISK (ushort)0x0004 |
| 616 | #define ASC_CNTL_BIOS_REMOVABLE (ushort)0x0008 |
| 617 | #define ASC_CNTL_NO_SCAM (ushort)0x0010 |
| 618 | #define ASC_CNTL_INT_MULTI_Q (ushort)0x0080 |
| 619 | #define ASC_CNTL_NO_LUN_SUPPORT (ushort)0x0040 |
| 620 | #define ASC_CNTL_NO_VERIFY_COPY (ushort)0x0100 |
| 621 | #define ASC_CNTL_RESET_SCSI (ushort)0x0200 |
| 622 | #define ASC_CNTL_INIT_INQUIRY (ushort)0x0400 |
| 623 | #define ASC_CNTL_INIT_VERBOSE (ushort)0x0800 |
| 624 | #define ASC_CNTL_SCSI_PARITY (ushort)0x1000 |
| 625 | #define ASC_CNTL_BURST_MODE (ushort)0x2000 |
| 626 | #define ASC_CNTL_SDTR_ENABLE_ULTRA (ushort)0x4000 |
| 627 | #define ASC_EEP_DVC_CFG_BEG_VL 2 |
| 628 | #define ASC_EEP_MAX_DVC_ADDR_VL 15 |
| 629 | #define ASC_EEP_DVC_CFG_BEG 32 |
| 630 | #define ASC_EEP_MAX_DVC_ADDR 45 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | #define ASC_EEP_MAX_RETRY 20 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
| 633 | /* |
| 634 | * These macros keep the chip SCSI id and ISA DMA speed |
| 635 | * bitfields in board order. C bitfields aren't portable |
| 636 | * between big and little-endian platforms so they are |
| 637 | * not used. |
| 638 | */ |
| 639 | |
| 640 | #define ASC_EEP_GET_CHIP_ID(cfg) ((cfg)->id_speed & 0x0f) |
| 641 | #define ASC_EEP_GET_DMA_SPD(cfg) (((cfg)->id_speed & 0xf0) >> 4) |
| 642 | #define ASC_EEP_SET_CHIP_ID(cfg, sid) \ |
| 643 | ((cfg)->id_speed = ((cfg)->id_speed & 0xf0) | ((sid) & ASC_MAX_TID)) |
| 644 | #define ASC_EEP_SET_DMA_SPD(cfg, spd) \ |
| 645 | ((cfg)->id_speed = ((cfg)->id_speed & 0x0f) | ((spd) & 0x0f) << 4) |
| 646 | |
| 647 | typedef struct asceep_config { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 648 | ushort cfg_lsw; |
| 649 | ushort cfg_msw; |
| 650 | uchar init_sdtr; |
| 651 | uchar disc_enable; |
| 652 | uchar use_cmd_qng; |
| 653 | uchar start_motor; |
| 654 | uchar max_total_qng; |
| 655 | uchar max_tag_qng; |
| 656 | uchar bios_scan; |
| 657 | uchar power_up_wait; |
| 658 | uchar no_scam; |
| 659 | uchar id_speed; /* low order 4 bits is chip scsi id */ |
| 660 | /* high order 4 bits is isa dma speed */ |
| 661 | uchar dos_int13_table[ASC_MAX_TID + 1]; |
| 662 | uchar adapter_info[6]; |
| 663 | ushort cntl; |
| 664 | ushort chksum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | } ASCEEP_CONFIG; |
| 666 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | #define ASC_EEP_CMD_READ 0x80 |
| 668 | #define ASC_EEP_CMD_WRITE 0x40 |
| 669 | #define ASC_EEP_CMD_WRITE_ABLE 0x30 |
| 670 | #define ASC_EEP_CMD_WRITE_DISABLE 0x00 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | #define ASCV_MSGOUT_BEG 0x0000 |
| 672 | #define ASCV_MSGOUT_SDTR_PERIOD (ASCV_MSGOUT_BEG+3) |
| 673 | #define ASCV_MSGOUT_SDTR_OFFSET (ASCV_MSGOUT_BEG+4) |
| 674 | #define ASCV_BREAK_SAVED_CODE (ushort)0x0006 |
| 675 | #define ASCV_MSGIN_BEG (ASCV_MSGOUT_BEG+8) |
| 676 | #define ASCV_MSGIN_SDTR_PERIOD (ASCV_MSGIN_BEG+3) |
| 677 | #define ASCV_MSGIN_SDTR_OFFSET (ASCV_MSGIN_BEG+4) |
| 678 | #define ASCV_SDTR_DATA_BEG (ASCV_MSGIN_BEG+8) |
| 679 | #define ASCV_SDTR_DONE_BEG (ASCV_SDTR_DATA_BEG+8) |
| 680 | #define ASCV_MAX_DVC_QNG_BEG (ushort)0x0020 |
| 681 | #define ASCV_BREAK_ADDR (ushort)0x0028 |
| 682 | #define ASCV_BREAK_NOTIFY_COUNT (ushort)0x002A |
| 683 | #define ASCV_BREAK_CONTROL (ushort)0x002C |
| 684 | #define ASCV_BREAK_HIT_COUNT (ushort)0x002E |
| 685 | |
| 686 | #define ASCV_ASCDVC_ERR_CODE_W (ushort)0x0030 |
| 687 | #define ASCV_MCODE_CHKSUM_W (ushort)0x0032 |
| 688 | #define ASCV_MCODE_SIZE_W (ushort)0x0034 |
| 689 | #define ASCV_STOP_CODE_B (ushort)0x0036 |
| 690 | #define ASCV_DVC_ERR_CODE_B (ushort)0x0037 |
| 691 | #define ASCV_OVERRUN_PADDR_D (ushort)0x0038 |
| 692 | #define ASCV_OVERRUN_BSIZE_D (ushort)0x003C |
| 693 | #define ASCV_HALTCODE_W (ushort)0x0040 |
| 694 | #define ASCV_CHKSUM_W (ushort)0x0042 |
| 695 | #define ASCV_MC_DATE_W (ushort)0x0044 |
| 696 | #define ASCV_MC_VER_W (ushort)0x0046 |
| 697 | #define ASCV_NEXTRDY_B (ushort)0x0048 |
| 698 | #define ASCV_DONENEXT_B (ushort)0x0049 |
| 699 | #define ASCV_USE_TAGGED_QNG_B (ushort)0x004A |
| 700 | #define ASCV_SCSIBUSY_B (ushort)0x004B |
| 701 | #define ASCV_Q_DONE_IN_PROGRESS_B (ushort)0x004C |
| 702 | #define ASCV_CURCDB_B (ushort)0x004D |
| 703 | #define ASCV_RCLUN_B (ushort)0x004E |
| 704 | #define ASCV_BUSY_QHEAD_B (ushort)0x004F |
| 705 | #define ASCV_DISC1_QHEAD_B (ushort)0x0050 |
| 706 | #define ASCV_DISC_ENABLE_B (ushort)0x0052 |
| 707 | #define ASCV_CAN_TAGGED_QNG_B (ushort)0x0053 |
| 708 | #define ASCV_HOSTSCSI_ID_B (ushort)0x0055 |
| 709 | #define ASCV_MCODE_CNTL_B (ushort)0x0056 |
| 710 | #define ASCV_NULL_TARGET_B (ushort)0x0057 |
| 711 | #define ASCV_FREE_Q_HEAD_W (ushort)0x0058 |
| 712 | #define ASCV_DONE_Q_TAIL_W (ushort)0x005A |
| 713 | #define ASCV_FREE_Q_HEAD_B (ushort)(ASCV_FREE_Q_HEAD_W+1) |
| 714 | #define ASCV_DONE_Q_TAIL_B (ushort)(ASCV_DONE_Q_TAIL_W+1) |
| 715 | #define ASCV_HOST_FLAG_B (ushort)0x005D |
| 716 | #define ASCV_TOTAL_READY_Q_B (ushort)0x0064 |
| 717 | #define ASCV_VER_SERIAL_B (ushort)0x0065 |
| 718 | #define ASCV_HALTCODE_SAVED_W (ushort)0x0066 |
| 719 | #define ASCV_WTM_FLAG_B (ushort)0x0068 |
| 720 | #define ASCV_RISC_FLAG_B (ushort)0x006A |
| 721 | #define ASCV_REQ_SG_LIST_QP (ushort)0x006B |
| 722 | #define ASC_HOST_FLAG_IN_ISR 0x01 |
| 723 | #define ASC_HOST_FLAG_ACK_INT 0x02 |
| 724 | #define ASC_RISC_FLAG_GEN_INT 0x01 |
| 725 | #define ASC_RISC_FLAG_REQ_SG_LIST 0x02 |
| 726 | #define IOP_CTRL (0x0F) |
| 727 | #define IOP_STATUS (0x0E) |
| 728 | #define IOP_INT_ACK IOP_STATUS |
| 729 | #define IOP_REG_IFC (0x0D) |
| 730 | #define IOP_SYN_OFFSET (0x0B) |
| 731 | #define IOP_EXTRA_CONTROL (0x0D) |
| 732 | #define IOP_REG_PC (0x0C) |
| 733 | #define IOP_RAM_ADDR (0x0A) |
| 734 | #define IOP_RAM_DATA (0x08) |
| 735 | #define IOP_EEP_DATA (0x06) |
| 736 | #define IOP_EEP_CMD (0x07) |
| 737 | #define IOP_VERSION (0x03) |
| 738 | #define IOP_CONFIG_HIGH (0x04) |
| 739 | #define IOP_CONFIG_LOW (0x02) |
| 740 | #define IOP_SIG_BYTE (0x01) |
| 741 | #define IOP_SIG_WORD (0x00) |
| 742 | #define IOP_REG_DC1 (0x0E) |
| 743 | #define IOP_REG_DC0 (0x0C) |
| 744 | #define IOP_REG_SB (0x0B) |
| 745 | #define IOP_REG_DA1 (0x0A) |
| 746 | #define IOP_REG_DA0 (0x08) |
| 747 | #define IOP_REG_SC (0x09) |
| 748 | #define IOP_DMA_SPEED (0x07) |
| 749 | #define IOP_REG_FLAG (0x07) |
| 750 | #define IOP_FIFO_H (0x06) |
| 751 | #define IOP_FIFO_L (0x04) |
| 752 | #define IOP_REG_ID (0x05) |
| 753 | #define IOP_REG_QP (0x03) |
| 754 | #define IOP_REG_IH (0x02) |
| 755 | #define IOP_REG_IX (0x01) |
| 756 | #define IOP_REG_AX (0x00) |
| 757 | #define IFC_REG_LOCK (0x00) |
| 758 | #define IFC_REG_UNLOCK (0x09) |
| 759 | #define IFC_WR_EN_FILTER (0x10) |
| 760 | #define IFC_RD_NO_EEPROM (0x10) |
| 761 | #define IFC_SLEW_RATE (0x20) |
| 762 | #define IFC_ACT_NEG (0x40) |
| 763 | #define IFC_INP_FILTER (0x80) |
| 764 | #define IFC_INIT_DEFAULT (IFC_ACT_NEG | IFC_REG_UNLOCK) |
| 765 | #define SC_SEL (uchar)(0x80) |
| 766 | #define SC_BSY (uchar)(0x40) |
| 767 | #define SC_ACK (uchar)(0x20) |
| 768 | #define SC_REQ (uchar)(0x10) |
| 769 | #define SC_ATN (uchar)(0x08) |
| 770 | #define SC_IO (uchar)(0x04) |
| 771 | #define SC_CD (uchar)(0x02) |
| 772 | #define SC_MSG (uchar)(0x01) |
| 773 | #define SEC_SCSI_CTL (uchar)(0x80) |
| 774 | #define SEC_ACTIVE_NEGATE (uchar)(0x40) |
| 775 | #define SEC_SLEW_RATE (uchar)(0x20) |
| 776 | #define SEC_ENABLE_FILTER (uchar)(0x10) |
| 777 | #define ASC_HALT_EXTMSG_IN (ushort)0x8000 |
| 778 | #define ASC_HALT_CHK_CONDITION (ushort)0x8100 |
| 779 | #define ASC_HALT_SS_QUEUE_FULL (ushort)0x8200 |
| 780 | #define ASC_HALT_DISABLE_ASYN_USE_SYN_FIX (ushort)0x8300 |
| 781 | #define ASC_HALT_ENABLE_ASYN_USE_SYN_FIX (ushort)0x8400 |
| 782 | #define ASC_HALT_SDTR_REJECTED (ushort)0x4000 |
| 783 | #define ASC_HALT_HOST_COPY_SG_LIST_TO_RISC ( ushort )0x2000 |
| 784 | #define ASC_MAX_QNO 0xF8 |
| 785 | #define ASC_DATA_SEC_BEG (ushort)0x0080 |
| 786 | #define ASC_DATA_SEC_END (ushort)0x0080 |
| 787 | #define ASC_CODE_SEC_BEG (ushort)0x0080 |
| 788 | #define ASC_CODE_SEC_END (ushort)0x0080 |
| 789 | #define ASC_QADR_BEG (0x4000) |
| 790 | #define ASC_QADR_USED (ushort)(ASC_MAX_QNO * 64) |
| 791 | #define ASC_QADR_END (ushort)0x7FFF |
| 792 | #define ASC_QLAST_ADR (ushort)0x7FC0 |
| 793 | #define ASC_QBLK_SIZE 0x40 |
| 794 | #define ASC_BIOS_DATA_QBEG 0xF8 |
| 795 | #define ASC_MIN_ACTIVE_QNO 0x01 |
| 796 | #define ASC_QLINK_END 0xFF |
| 797 | #define ASC_EEPROM_WORDS 0x10 |
| 798 | #define ASC_MAX_MGS_LEN 0x10 |
| 799 | #define ASC_BIOS_ADDR_DEF 0xDC00 |
| 800 | #define ASC_BIOS_SIZE 0x3800 |
| 801 | #define ASC_BIOS_RAM_OFF 0x3800 |
| 802 | #define ASC_BIOS_RAM_SIZE 0x800 |
| 803 | #define ASC_BIOS_MIN_ADDR 0xC000 |
| 804 | #define ASC_BIOS_MAX_ADDR 0xEC00 |
| 805 | #define ASC_BIOS_BANK_SIZE 0x0400 |
| 806 | #define ASC_MCODE_START_ADDR 0x0080 |
| 807 | #define ASC_CFG0_HOST_INT_ON 0x0020 |
| 808 | #define ASC_CFG0_BIOS_ON 0x0040 |
| 809 | #define ASC_CFG0_VERA_BURST_ON 0x0080 |
| 810 | #define ASC_CFG0_SCSI_PARITY_ON 0x0800 |
| 811 | #define ASC_CFG1_SCSI_TARGET_ON 0x0080 |
| 812 | #define ASC_CFG1_LRAM_8BITS_ON 0x0800 |
| 813 | #define ASC_CFG_MSW_CLR_MASK 0x3080 |
| 814 | #define CSW_TEST1 (ASC_CS_TYPE)0x8000 |
| 815 | #define CSW_AUTO_CONFIG (ASC_CS_TYPE)0x4000 |
| 816 | #define CSW_RESERVED1 (ASC_CS_TYPE)0x2000 |
| 817 | #define CSW_IRQ_WRITTEN (ASC_CS_TYPE)0x1000 |
| 818 | #define CSW_33MHZ_SELECTED (ASC_CS_TYPE)0x0800 |
| 819 | #define CSW_TEST2 (ASC_CS_TYPE)0x0400 |
| 820 | #define CSW_TEST3 (ASC_CS_TYPE)0x0200 |
| 821 | #define CSW_RESERVED2 (ASC_CS_TYPE)0x0100 |
| 822 | #define CSW_DMA_DONE (ASC_CS_TYPE)0x0080 |
| 823 | #define CSW_FIFO_RDY (ASC_CS_TYPE)0x0040 |
| 824 | #define CSW_EEP_READ_DONE (ASC_CS_TYPE)0x0020 |
| 825 | #define CSW_HALTED (ASC_CS_TYPE)0x0010 |
| 826 | #define CSW_SCSI_RESET_ACTIVE (ASC_CS_TYPE)0x0008 |
| 827 | #define CSW_PARITY_ERR (ASC_CS_TYPE)0x0004 |
| 828 | #define CSW_SCSI_RESET_LATCH (ASC_CS_TYPE)0x0002 |
| 829 | #define CSW_INT_PENDING (ASC_CS_TYPE)0x0001 |
| 830 | #define CIW_CLR_SCSI_RESET_INT (ASC_CS_TYPE)0x1000 |
| 831 | #define CIW_INT_ACK (ASC_CS_TYPE)0x0100 |
| 832 | #define CIW_TEST1 (ASC_CS_TYPE)0x0200 |
| 833 | #define CIW_TEST2 (ASC_CS_TYPE)0x0400 |
| 834 | #define CIW_SEL_33MHZ (ASC_CS_TYPE)0x0800 |
| 835 | #define CIW_IRQ_ACT (ASC_CS_TYPE)0x1000 |
| 836 | #define CC_CHIP_RESET (uchar)0x80 |
| 837 | #define CC_SCSI_RESET (uchar)0x40 |
| 838 | #define CC_HALT (uchar)0x20 |
| 839 | #define CC_SINGLE_STEP (uchar)0x10 |
| 840 | #define CC_DMA_ABLE (uchar)0x08 |
| 841 | #define CC_TEST (uchar)0x04 |
| 842 | #define CC_BANK_ONE (uchar)0x02 |
| 843 | #define CC_DIAG (uchar)0x01 |
| 844 | #define ASC_1000_ID0W 0x04C1 |
| 845 | #define ASC_1000_ID0W_FIX 0x00C1 |
| 846 | #define ASC_1000_ID1B 0x25 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | #define ASC_EISA_REV_IOP_MASK (0x0C83) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | #define ASC_EISA_CFG_IOP_MASK (0x0C86) |
| 849 | #define ASC_GET_EISA_SLOT(iop) (PortAddr)((iop) & 0xF000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | #define INS_HALTINT (ushort)0x6281 |
| 851 | #define INS_HALT (ushort)0x6280 |
| 852 | #define INS_SINT (ushort)0x6200 |
| 853 | #define INS_RFLAG_WTM (ushort)0x7380 |
| 854 | #define ASC_MC_SAVE_CODE_WSIZE 0x500 |
| 855 | #define ASC_MC_SAVE_DATA_WSIZE 0x40 |
| 856 | |
| 857 | typedef struct asc_mc_saved { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 858 | ushort data[ASC_MC_SAVE_DATA_WSIZE]; |
| 859 | ushort code[ASC_MC_SAVE_CODE_WSIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | } ASC_MC_SAVED; |
| 861 | |
| 862 | #define AscGetQDoneInProgress(port) AscReadLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B) |
| 863 | #define AscPutQDoneInProgress(port, val) AscWriteLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B, val) |
| 864 | #define AscGetVarFreeQHead(port) AscReadLramWord((port), ASCV_FREE_Q_HEAD_W) |
| 865 | #define AscGetVarDoneQTail(port) AscReadLramWord((port), ASCV_DONE_Q_TAIL_W) |
| 866 | #define AscPutVarFreeQHead(port, val) AscWriteLramWord((port), ASCV_FREE_Q_HEAD_W, val) |
| 867 | #define AscPutVarDoneQTail(port, val) AscWriteLramWord((port), ASCV_DONE_Q_TAIL_W, val) |
| 868 | #define AscGetRiscVarFreeQHead(port) AscReadLramByte((port), ASCV_NEXTRDY_B) |
| 869 | #define AscGetRiscVarDoneQTail(port) AscReadLramByte((port), ASCV_DONENEXT_B) |
| 870 | #define AscPutRiscVarFreeQHead(port, val) AscWriteLramByte((port), ASCV_NEXTRDY_B, val) |
| 871 | #define AscPutRiscVarDoneQTail(port, val) AscWriteLramByte((port), ASCV_DONENEXT_B, val) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 872 | #define AscPutMCodeSDTRDoneAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id), (data)) |
| 873 | #define AscGetMCodeSDTRDoneAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id)) |
| 874 | #define AscPutMCodeInitSDTRAtID(port, id, data) AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id), data) |
| 875 | #define AscGetMCodeInitSDTRAtID(port, id) AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | #define AscGetChipSignatureByte(port) (uchar)inp((port)+IOP_SIG_BYTE) |
| 877 | #define AscGetChipSignatureWord(port) (ushort)inpw((port)+IOP_SIG_WORD) |
| 878 | #define AscGetChipVerNo(port) (uchar)inp((port)+IOP_VERSION) |
| 879 | #define AscGetChipCfgLsw(port) (ushort)inpw((port)+IOP_CONFIG_LOW) |
| 880 | #define AscGetChipCfgMsw(port) (ushort)inpw((port)+IOP_CONFIG_HIGH) |
| 881 | #define AscSetChipCfgLsw(port, data) outpw((port)+IOP_CONFIG_LOW, data) |
| 882 | #define AscSetChipCfgMsw(port, data) outpw((port)+IOP_CONFIG_HIGH, data) |
| 883 | #define AscGetChipEEPCmd(port) (uchar)inp((port)+IOP_EEP_CMD) |
| 884 | #define AscSetChipEEPCmd(port, data) outp((port)+IOP_EEP_CMD, data) |
| 885 | #define AscGetChipEEPData(port) (ushort)inpw((port)+IOP_EEP_DATA) |
| 886 | #define AscSetChipEEPData(port, data) outpw((port)+IOP_EEP_DATA, data) |
| 887 | #define AscGetChipLramAddr(port) (ushort)inpw((PortAddr)((port)+IOP_RAM_ADDR)) |
| 888 | #define AscSetChipLramAddr(port, addr) outpw((PortAddr)((port)+IOP_RAM_ADDR), addr) |
| 889 | #define AscGetChipLramData(port) (ushort)inpw((port)+IOP_RAM_DATA) |
| 890 | #define AscSetChipLramData(port, data) outpw((port)+IOP_RAM_DATA, data) |
| 891 | #define AscGetChipIFC(port) (uchar)inp((port)+IOP_REG_IFC) |
| 892 | #define AscSetChipIFC(port, data) outp((port)+IOP_REG_IFC, data) |
| 893 | #define AscGetChipStatus(port) (ASC_CS_TYPE)inpw((port)+IOP_STATUS) |
| 894 | #define AscSetChipStatus(port, cs_val) outpw((port)+IOP_STATUS, cs_val) |
| 895 | #define AscGetChipControl(port) (uchar)inp((port)+IOP_CTRL) |
| 896 | #define AscSetChipControl(port, cc_val) outp((port)+IOP_CTRL, cc_val) |
| 897 | #define AscGetChipSyn(port) (uchar)inp((port)+IOP_SYN_OFFSET) |
| 898 | #define AscSetChipSyn(port, data) outp((port)+IOP_SYN_OFFSET, data) |
| 899 | #define AscSetPCAddr(port, data) outpw((port)+IOP_REG_PC, data) |
| 900 | #define AscGetPCAddr(port) (ushort)inpw((port)+IOP_REG_PC) |
| 901 | #define AscIsIntPending(port) (AscGetChipStatus(port) & (CSW_INT_PENDING | CSW_SCSI_RESET_LATCH)) |
| 902 | #define AscGetChipScsiID(port) ((AscGetChipCfgLsw(port) >> 8) & ASC_MAX_TID) |
| 903 | #define AscGetExtraControl(port) (uchar)inp((port)+IOP_EXTRA_CONTROL) |
| 904 | #define AscSetExtraControl(port, data) outp((port)+IOP_EXTRA_CONTROL, data) |
| 905 | #define AscReadChipAX(port) (ushort)inpw((port)+IOP_REG_AX) |
| 906 | #define AscWriteChipAX(port, data) outpw((port)+IOP_REG_AX, data) |
| 907 | #define AscReadChipIX(port) (uchar)inp((port)+IOP_REG_IX) |
| 908 | #define AscWriteChipIX(port, data) outp((port)+IOP_REG_IX, data) |
| 909 | #define AscReadChipIH(port) (ushort)inpw((port)+IOP_REG_IH) |
| 910 | #define AscWriteChipIH(port, data) outpw((port)+IOP_REG_IH, data) |
| 911 | #define AscReadChipQP(port) (uchar)inp((port)+IOP_REG_QP) |
| 912 | #define AscWriteChipQP(port, data) outp((port)+IOP_REG_QP, data) |
| 913 | #define AscReadChipFIFO_L(port) (ushort)inpw((port)+IOP_REG_FIFO_L) |
| 914 | #define AscWriteChipFIFO_L(port, data) outpw((port)+IOP_REG_FIFO_L, data) |
| 915 | #define AscReadChipFIFO_H(port) (ushort)inpw((port)+IOP_REG_FIFO_H) |
| 916 | #define AscWriteChipFIFO_H(port, data) outpw((port)+IOP_REG_FIFO_H, data) |
| 917 | #define AscReadChipDmaSpeed(port) (uchar)inp((port)+IOP_DMA_SPEED) |
| 918 | #define AscWriteChipDmaSpeed(port, data) outp((port)+IOP_DMA_SPEED, data) |
| 919 | #define AscReadChipDA0(port) (ushort)inpw((port)+IOP_REG_DA0) |
| 920 | #define AscWriteChipDA0(port) outpw((port)+IOP_REG_DA0, data) |
| 921 | #define AscReadChipDA1(port) (ushort)inpw((port)+IOP_REG_DA1) |
| 922 | #define AscWriteChipDA1(port) outpw((port)+IOP_REG_DA1, data) |
| 923 | #define AscReadChipDC0(port) (ushort)inpw((port)+IOP_REG_DC0) |
| 924 | #define AscWriteChipDC0(port) outpw((port)+IOP_REG_DC0, data) |
| 925 | #define AscReadChipDC1(port) (ushort)inpw((port)+IOP_REG_DC1) |
| 926 | #define AscWriteChipDC1(port) outpw((port)+IOP_REG_DC1, data) |
| 927 | #define AscReadChipDvcID(port) (uchar)inp((port)+IOP_REG_ID) |
| 928 | #define AscWriteChipDvcID(port, data) outp((port)+IOP_REG_ID, data) |
| 929 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | /* |
| 931 | * Portable Data Types |
| 932 | * |
| 933 | * Any instance where a 32-bit long or pointer type is assumed |
| 934 | * for precision or HW defined structures, the following define |
| 935 | * types must be used. In Linux the char, short, and int types |
| 936 | * are all consistent at 8, 16, and 32 bits respectively. Pointers |
| 937 | * and long types are 64 bits on Alpha and UltraSPARC. |
| 938 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 939 | #define ADV_PADDR __u32 /* Physical address data type. */ |
| 940 | #define ADV_VADDR __u32 /* Virtual address data type. */ |
| 941 | #define ADV_DCNT __u32 /* Unsigned Data count type. */ |
| 942 | #define ADV_SDCNT __s32 /* Signed Data count type. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | |
| 944 | /* |
| 945 | * These macros are used to convert a virtual address to a |
| 946 | * 32-bit value. This currently can be used on Linux Alpha |
| 947 | * which uses 64-bit virtual address but a 32-bit bus address. |
| 948 | * This is likely to break in the future, but doing this now |
| 949 | * will give us time to change the HW and FW to handle 64-bit |
| 950 | * addresses. |
| 951 | */ |
| 952 | #define ADV_VADDR_TO_U32 virt_to_bus |
| 953 | #define ADV_U32_TO_VADDR bus_to_virt |
| 954 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 955 | #define AdvPortAddr void __iomem * /* Virtual memory address size */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | |
| 957 | /* |
| 958 | * Define Adv Library required memory access macros. |
| 959 | */ |
| 960 | #define ADV_MEM_READB(addr) readb(addr) |
| 961 | #define ADV_MEM_READW(addr) readw(addr) |
| 962 | #define ADV_MEM_WRITEB(addr, byte) writeb(byte, addr) |
| 963 | #define ADV_MEM_WRITEW(addr, word) writew(word, addr) |
| 964 | #define ADV_MEM_WRITEDW(addr, dword) writel(dword, addr) |
| 965 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | * Define total number of simultaneous maximum element scatter-gather |
| 968 | * request blocks per wide adapter. ASC_DEF_MAX_HOST_QNG (253) is the |
| 969 | * maximum number of outstanding commands per wide host adapter. Each |
| 970 | * command uses one or more ADV_SG_BLOCK each with 15 scatter-gather |
| 971 | * elements. Allow each command to have at least one ADV_SG_BLOCK structure. |
| 972 | * This allows about 15 commands to have the maximum 17 ADV_SG_BLOCK |
| 973 | * structures or 255 scatter-gather elements. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | */ |
| 975 | #define ADV_TOT_SG_BLOCK ASC_DEF_MAX_HOST_QNG |
| 976 | |
| 977 | /* |
Matthew Wilcox | 98d41c2 | 2007-10-02 21:55:37 -0400 | [diff] [blame] | 978 | * Define maximum number of scatter-gather elements per request. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | */ |
| 980 | #define ADV_MAX_SG_LIST 255 |
Matthew Wilcox | 98d41c2 | 2007-10-02 21:55:37 -0400 | [diff] [blame] | 981 | #define NO_OF_SG_PER_BLOCK 15 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | #define ADV_EEP_DVC_CFG_BEGIN (0x00) |
| 984 | #define ADV_EEP_DVC_CFG_END (0x15) |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 985 | #define ADV_EEP_DVC_CTL_BEGIN (0x16) /* location of OEM name */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | #define ADV_EEP_MAX_WORD_ADDR (0x1E) |
| 987 | |
| 988 | #define ADV_EEP_DELAY_MS 100 |
| 989 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 990 | #define ADV_EEPROM_BIG_ENDIAN 0x8000 /* EEPROM Bit 15 */ |
| 991 | #define ADV_EEPROM_BIOS_ENABLE 0x4000 /* EEPROM Bit 14 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | /* |
| 993 | * For the ASC3550 Bit 13 is Termination Polarity control bit. |
| 994 | * For later ICs Bit 13 controls whether the CIS (Card Information |
| 995 | * Service Section) is loaded from EEPROM. |
| 996 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 997 | #define ADV_EEPROM_TERM_POL 0x2000 /* EEPROM Bit 13 */ |
| 998 | #define ADV_EEPROM_CIS_LD 0x2000 /* EEPROM Bit 13 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | /* |
| 1000 | * ASC38C1600 Bit 11 |
| 1001 | * |
| 1002 | * If EEPROM Bit 11 is 0 for Function 0, then Function 0 will specify |
| 1003 | * INT A in the PCI Configuration Space Int Pin field. If it is 1, then |
| 1004 | * Function 0 will specify INT B. |
| 1005 | * |
| 1006 | * If EEPROM Bit 11 is 0 for Function 1, then Function 1 will specify |
| 1007 | * INT B in the PCI Configuration Space Int Pin field. If it is 1, then |
| 1008 | * Function 1 will specify INT A. |
| 1009 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1010 | #define ADV_EEPROM_INTAB 0x0800 /* EEPROM Bit 11 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1012 | typedef struct adveep_3550_config { |
| 1013 | /* Word Offset, Description */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1015 | ushort cfg_lsw; /* 00 power up initialization */ |
| 1016 | /* bit 13 set - Term Polarity Control */ |
| 1017 | /* bit 14 set - BIOS Enable */ |
| 1018 | /* bit 15 set - Big Endian Mode */ |
| 1019 | ushort cfg_msw; /* 01 unused */ |
| 1020 | ushort disc_enable; /* 02 disconnect enable */ |
| 1021 | ushort wdtr_able; /* 03 Wide DTR able */ |
| 1022 | ushort sdtr_able; /* 04 Synchronous DTR able */ |
| 1023 | ushort start_motor; /* 05 send start up motor */ |
| 1024 | ushort tagqng_able; /* 06 tag queuing able */ |
| 1025 | ushort bios_scan; /* 07 BIOS device control */ |
| 1026 | ushort scam_tolerant; /* 08 no scam */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1028 | uchar adapter_scsi_id; /* 09 Host Adapter ID */ |
| 1029 | uchar bios_boot_delay; /* power up wait */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1031 | uchar scsi_reset_delay; /* 10 reset delay */ |
| 1032 | uchar bios_id_lun; /* first boot device scsi id & lun */ |
| 1033 | /* high nibble is lun */ |
| 1034 | /* low nibble is scsi id */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1036 | uchar termination; /* 11 0 - automatic */ |
| 1037 | /* 1 - low off / high off */ |
| 1038 | /* 2 - low off / high on */ |
| 1039 | /* 3 - low on / high on */ |
| 1040 | /* There is no low on / high off */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1042 | uchar reserved1; /* reserved byte (not used) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1044 | ushort bios_ctrl; /* 12 BIOS control bits */ |
| 1045 | /* bit 0 BIOS don't act as initiator. */ |
| 1046 | /* bit 1 BIOS > 1 GB support */ |
| 1047 | /* bit 2 BIOS > 2 Disk Support */ |
| 1048 | /* bit 3 BIOS don't support removables */ |
| 1049 | /* bit 4 BIOS support bootable CD */ |
| 1050 | /* bit 5 BIOS scan enabled */ |
| 1051 | /* bit 6 BIOS support multiple LUNs */ |
| 1052 | /* bit 7 BIOS display of message */ |
| 1053 | /* bit 8 SCAM disabled */ |
| 1054 | /* bit 9 Reset SCSI bus during init. */ |
| 1055 | /* bit 10 */ |
| 1056 | /* bit 11 No verbose initialization. */ |
| 1057 | /* bit 12 SCSI parity enabled */ |
| 1058 | /* bit 13 */ |
| 1059 | /* bit 14 */ |
| 1060 | /* bit 15 */ |
| 1061 | ushort ultra_able; /* 13 ULTRA speed able */ |
| 1062 | ushort reserved2; /* 14 reserved */ |
| 1063 | uchar max_host_qng; /* 15 maximum host queuing */ |
| 1064 | uchar max_dvc_qng; /* maximum per device queuing */ |
| 1065 | ushort dvc_cntl; /* 16 control bit for driver */ |
| 1066 | ushort bug_fix; /* 17 control bit for bug fix */ |
| 1067 | ushort serial_number_word1; /* 18 Board serial number word 1 */ |
| 1068 | ushort serial_number_word2; /* 19 Board serial number word 2 */ |
| 1069 | ushort serial_number_word3; /* 20 Board serial number word 3 */ |
| 1070 | ushort check_sum; /* 21 EEP check sum */ |
| 1071 | uchar oem_name[16]; /* 22 OEM name */ |
| 1072 | ushort dvc_err_code; /* 30 last device driver error code */ |
| 1073 | ushort adv_err_code; /* 31 last uc and Adv Lib error code */ |
| 1074 | ushort adv_err_addr; /* 32 last uc error address */ |
| 1075 | ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */ |
| 1076 | ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */ |
| 1077 | ushort saved_adv_err_addr; /* 35 saved last uc error address */ |
| 1078 | ushort num_of_err; /* 36 number of error */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | } ADVEEP_3550_CONFIG; |
| 1080 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1081 | typedef struct adveep_38C0800_config { |
| 1082 | /* Word Offset, Description */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1084 | ushort cfg_lsw; /* 00 power up initialization */ |
| 1085 | /* bit 13 set - Load CIS */ |
| 1086 | /* bit 14 set - BIOS Enable */ |
| 1087 | /* bit 15 set - Big Endian Mode */ |
| 1088 | ushort cfg_msw; /* 01 unused */ |
| 1089 | ushort disc_enable; /* 02 disconnect enable */ |
| 1090 | ushort wdtr_able; /* 03 Wide DTR able */ |
| 1091 | ushort sdtr_speed1; /* 04 SDTR Speed TID 0-3 */ |
| 1092 | ushort start_motor; /* 05 send start up motor */ |
| 1093 | ushort tagqng_able; /* 06 tag queuing able */ |
| 1094 | ushort bios_scan; /* 07 BIOS device control */ |
| 1095 | ushort scam_tolerant; /* 08 no scam */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1097 | uchar adapter_scsi_id; /* 09 Host Adapter ID */ |
| 1098 | uchar bios_boot_delay; /* power up wait */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1100 | uchar scsi_reset_delay; /* 10 reset delay */ |
| 1101 | uchar bios_id_lun; /* first boot device scsi id & lun */ |
| 1102 | /* high nibble is lun */ |
| 1103 | /* low nibble is scsi id */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1105 | uchar termination_se; /* 11 0 - automatic */ |
| 1106 | /* 1 - low off / high off */ |
| 1107 | /* 2 - low off / high on */ |
| 1108 | /* 3 - low on / high on */ |
| 1109 | /* There is no low on / high off */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1111 | uchar termination_lvd; /* 11 0 - automatic */ |
| 1112 | /* 1 - low off / high off */ |
| 1113 | /* 2 - low off / high on */ |
| 1114 | /* 3 - low on / high on */ |
| 1115 | /* There is no low on / high off */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1117 | ushort bios_ctrl; /* 12 BIOS control bits */ |
| 1118 | /* bit 0 BIOS don't act as initiator. */ |
| 1119 | /* bit 1 BIOS > 1 GB support */ |
| 1120 | /* bit 2 BIOS > 2 Disk Support */ |
| 1121 | /* bit 3 BIOS don't support removables */ |
| 1122 | /* bit 4 BIOS support bootable CD */ |
| 1123 | /* bit 5 BIOS scan enabled */ |
| 1124 | /* bit 6 BIOS support multiple LUNs */ |
| 1125 | /* bit 7 BIOS display of message */ |
| 1126 | /* bit 8 SCAM disabled */ |
| 1127 | /* bit 9 Reset SCSI bus during init. */ |
| 1128 | /* bit 10 */ |
| 1129 | /* bit 11 No verbose initialization. */ |
| 1130 | /* bit 12 SCSI parity enabled */ |
| 1131 | /* bit 13 */ |
| 1132 | /* bit 14 */ |
| 1133 | /* bit 15 */ |
| 1134 | ushort sdtr_speed2; /* 13 SDTR speed TID 4-7 */ |
| 1135 | ushort sdtr_speed3; /* 14 SDTR speed TID 8-11 */ |
| 1136 | uchar max_host_qng; /* 15 maximum host queueing */ |
| 1137 | uchar max_dvc_qng; /* maximum per device queuing */ |
| 1138 | ushort dvc_cntl; /* 16 control bit for driver */ |
| 1139 | ushort sdtr_speed4; /* 17 SDTR speed 4 TID 12-15 */ |
| 1140 | ushort serial_number_word1; /* 18 Board serial number word 1 */ |
| 1141 | ushort serial_number_word2; /* 19 Board serial number word 2 */ |
| 1142 | ushort serial_number_word3; /* 20 Board serial number word 3 */ |
| 1143 | ushort check_sum; /* 21 EEP check sum */ |
| 1144 | uchar oem_name[16]; /* 22 OEM name */ |
| 1145 | ushort dvc_err_code; /* 30 last device driver error code */ |
| 1146 | ushort adv_err_code; /* 31 last uc and Adv Lib error code */ |
| 1147 | ushort adv_err_addr; /* 32 last uc error address */ |
| 1148 | ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */ |
| 1149 | ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */ |
| 1150 | ushort saved_adv_err_addr; /* 35 saved last uc error address */ |
| 1151 | ushort reserved36; /* 36 reserved */ |
| 1152 | ushort reserved37; /* 37 reserved */ |
| 1153 | ushort reserved38; /* 38 reserved */ |
| 1154 | ushort reserved39; /* 39 reserved */ |
| 1155 | ushort reserved40; /* 40 reserved */ |
| 1156 | ushort reserved41; /* 41 reserved */ |
| 1157 | ushort reserved42; /* 42 reserved */ |
| 1158 | ushort reserved43; /* 43 reserved */ |
| 1159 | ushort reserved44; /* 44 reserved */ |
| 1160 | ushort reserved45; /* 45 reserved */ |
| 1161 | ushort reserved46; /* 46 reserved */ |
| 1162 | ushort reserved47; /* 47 reserved */ |
| 1163 | ushort reserved48; /* 48 reserved */ |
| 1164 | ushort reserved49; /* 49 reserved */ |
| 1165 | ushort reserved50; /* 50 reserved */ |
| 1166 | ushort reserved51; /* 51 reserved */ |
| 1167 | ushort reserved52; /* 52 reserved */ |
| 1168 | ushort reserved53; /* 53 reserved */ |
| 1169 | ushort reserved54; /* 54 reserved */ |
| 1170 | ushort reserved55; /* 55 reserved */ |
| 1171 | ushort cisptr_lsw; /* 56 CIS PTR LSW */ |
| 1172 | ushort cisprt_msw; /* 57 CIS PTR MSW */ |
| 1173 | ushort subsysvid; /* 58 SubSystem Vendor ID */ |
| 1174 | ushort subsysid; /* 59 SubSystem ID */ |
| 1175 | ushort reserved60; /* 60 reserved */ |
| 1176 | ushort reserved61; /* 61 reserved */ |
| 1177 | ushort reserved62; /* 62 reserved */ |
| 1178 | ushort reserved63; /* 63 reserved */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | } ADVEEP_38C0800_CONFIG; |
| 1180 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1181 | typedef struct adveep_38C1600_config { |
| 1182 | /* Word Offset, Description */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1184 | ushort cfg_lsw; /* 00 power up initialization */ |
| 1185 | /* bit 11 set - Func. 0 INTB, Func. 1 INTA */ |
| 1186 | /* clear - Func. 0 INTA, Func. 1 INTB */ |
| 1187 | /* bit 13 set - Load CIS */ |
| 1188 | /* bit 14 set - BIOS Enable */ |
| 1189 | /* bit 15 set - Big Endian Mode */ |
| 1190 | ushort cfg_msw; /* 01 unused */ |
| 1191 | ushort disc_enable; /* 02 disconnect enable */ |
| 1192 | ushort wdtr_able; /* 03 Wide DTR able */ |
| 1193 | ushort sdtr_speed1; /* 04 SDTR Speed TID 0-3 */ |
| 1194 | ushort start_motor; /* 05 send start up motor */ |
| 1195 | ushort tagqng_able; /* 06 tag queuing able */ |
| 1196 | ushort bios_scan; /* 07 BIOS device control */ |
| 1197 | ushort scam_tolerant; /* 08 no scam */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1199 | uchar adapter_scsi_id; /* 09 Host Adapter ID */ |
| 1200 | uchar bios_boot_delay; /* power up wait */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1202 | uchar scsi_reset_delay; /* 10 reset delay */ |
| 1203 | uchar bios_id_lun; /* first boot device scsi id & lun */ |
| 1204 | /* high nibble is lun */ |
| 1205 | /* low nibble is scsi id */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1207 | uchar termination_se; /* 11 0 - automatic */ |
| 1208 | /* 1 - low off / high off */ |
| 1209 | /* 2 - low off / high on */ |
| 1210 | /* 3 - low on / high on */ |
| 1211 | /* There is no low on / high off */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1213 | uchar termination_lvd; /* 11 0 - automatic */ |
| 1214 | /* 1 - low off / high off */ |
| 1215 | /* 2 - low off / high on */ |
| 1216 | /* 3 - low on / high on */ |
| 1217 | /* There is no low on / high off */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1219 | ushort bios_ctrl; /* 12 BIOS control bits */ |
| 1220 | /* bit 0 BIOS don't act as initiator. */ |
| 1221 | /* bit 1 BIOS > 1 GB support */ |
| 1222 | /* bit 2 BIOS > 2 Disk Support */ |
| 1223 | /* bit 3 BIOS don't support removables */ |
| 1224 | /* bit 4 BIOS support bootable CD */ |
| 1225 | /* bit 5 BIOS scan enabled */ |
| 1226 | /* bit 6 BIOS support multiple LUNs */ |
| 1227 | /* bit 7 BIOS display of message */ |
| 1228 | /* bit 8 SCAM disabled */ |
| 1229 | /* bit 9 Reset SCSI bus during init. */ |
| 1230 | /* bit 10 Basic Integrity Checking disabled */ |
| 1231 | /* bit 11 No verbose initialization. */ |
| 1232 | /* bit 12 SCSI parity enabled */ |
| 1233 | /* bit 13 AIPP (Asyn. Info. Ph. Prot.) dis. */ |
| 1234 | /* bit 14 */ |
| 1235 | /* bit 15 */ |
| 1236 | ushort sdtr_speed2; /* 13 SDTR speed TID 4-7 */ |
| 1237 | ushort sdtr_speed3; /* 14 SDTR speed TID 8-11 */ |
| 1238 | uchar max_host_qng; /* 15 maximum host queueing */ |
| 1239 | uchar max_dvc_qng; /* maximum per device queuing */ |
| 1240 | ushort dvc_cntl; /* 16 control bit for driver */ |
| 1241 | ushort sdtr_speed4; /* 17 SDTR speed 4 TID 12-15 */ |
| 1242 | ushort serial_number_word1; /* 18 Board serial number word 1 */ |
| 1243 | ushort serial_number_word2; /* 19 Board serial number word 2 */ |
| 1244 | ushort serial_number_word3; /* 20 Board serial number word 3 */ |
| 1245 | ushort check_sum; /* 21 EEP check sum */ |
| 1246 | uchar oem_name[16]; /* 22 OEM name */ |
| 1247 | ushort dvc_err_code; /* 30 last device driver error code */ |
| 1248 | ushort adv_err_code; /* 31 last uc and Adv Lib error code */ |
| 1249 | ushort adv_err_addr; /* 32 last uc error address */ |
| 1250 | ushort saved_dvc_err_code; /* 33 saved last dev. driver error code */ |
| 1251 | ushort saved_adv_err_code; /* 34 saved last uc and Adv Lib error code */ |
| 1252 | ushort saved_adv_err_addr; /* 35 saved last uc error address */ |
| 1253 | ushort reserved36; /* 36 reserved */ |
| 1254 | ushort reserved37; /* 37 reserved */ |
| 1255 | ushort reserved38; /* 38 reserved */ |
| 1256 | ushort reserved39; /* 39 reserved */ |
| 1257 | ushort reserved40; /* 40 reserved */ |
| 1258 | ushort reserved41; /* 41 reserved */ |
| 1259 | ushort reserved42; /* 42 reserved */ |
| 1260 | ushort reserved43; /* 43 reserved */ |
| 1261 | ushort reserved44; /* 44 reserved */ |
| 1262 | ushort reserved45; /* 45 reserved */ |
| 1263 | ushort reserved46; /* 46 reserved */ |
| 1264 | ushort reserved47; /* 47 reserved */ |
| 1265 | ushort reserved48; /* 48 reserved */ |
| 1266 | ushort reserved49; /* 49 reserved */ |
| 1267 | ushort reserved50; /* 50 reserved */ |
| 1268 | ushort reserved51; /* 51 reserved */ |
| 1269 | ushort reserved52; /* 52 reserved */ |
| 1270 | ushort reserved53; /* 53 reserved */ |
| 1271 | ushort reserved54; /* 54 reserved */ |
| 1272 | ushort reserved55; /* 55 reserved */ |
| 1273 | ushort cisptr_lsw; /* 56 CIS PTR LSW */ |
| 1274 | ushort cisprt_msw; /* 57 CIS PTR MSW */ |
| 1275 | ushort subsysvid; /* 58 SubSystem Vendor ID */ |
| 1276 | ushort subsysid; /* 59 SubSystem ID */ |
| 1277 | ushort reserved60; /* 60 reserved */ |
| 1278 | ushort reserved61; /* 61 reserved */ |
| 1279 | ushort reserved62; /* 62 reserved */ |
| 1280 | ushort reserved63; /* 63 reserved */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | } ADVEEP_38C1600_CONFIG; |
| 1282 | |
| 1283 | /* |
| 1284 | * EEPROM Commands |
| 1285 | */ |
| 1286 | #define ASC_EEP_CMD_DONE 0x0200 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | |
| 1288 | /* bios_ctrl */ |
| 1289 | #define BIOS_CTRL_BIOS 0x0001 |
| 1290 | #define BIOS_CTRL_EXTENDED_XLAT 0x0002 |
| 1291 | #define BIOS_CTRL_GT_2_DISK 0x0004 |
| 1292 | #define BIOS_CTRL_BIOS_REMOVABLE 0x0008 |
| 1293 | #define BIOS_CTRL_BOOTABLE_CD 0x0010 |
| 1294 | #define BIOS_CTRL_MULTIPLE_LUN 0x0040 |
| 1295 | #define BIOS_CTRL_DISPLAY_MSG 0x0080 |
| 1296 | #define BIOS_CTRL_NO_SCAM 0x0100 |
| 1297 | #define BIOS_CTRL_RESET_SCSI_BUS 0x0200 |
| 1298 | #define BIOS_CTRL_INIT_VERBOSE 0x0800 |
| 1299 | #define BIOS_CTRL_SCSI_PARITY 0x1000 |
| 1300 | #define BIOS_CTRL_AIPP_DIS 0x2000 |
| 1301 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1302 | #define ADV_3550_MEMSIZE 0x2000 /* 8 KB Internal Memory */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1304 | #define ADV_38C0800_MEMSIZE 0x4000 /* 16 KB Internal Memory */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | |
| 1306 | /* |
| 1307 | * XXX - Since ASC38C1600 Rev.3 has a local RAM failure issue, there is |
| 1308 | * a special 16K Adv Library and Microcode version. After the issue is |
| 1309 | * resolved, should restore 32K support. |
| 1310 | * |
| 1311 | * #define ADV_38C1600_MEMSIZE 0x8000L * 32 KB Internal Memory * |
| 1312 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1313 | #define ADV_38C1600_MEMSIZE 0x4000 /* 16 KB Internal Memory */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | |
| 1315 | /* |
| 1316 | * Byte I/O register address from base of 'iop_base'. |
| 1317 | */ |
| 1318 | #define IOPB_INTR_STATUS_REG 0x00 |
| 1319 | #define IOPB_CHIP_ID_1 0x01 |
| 1320 | #define IOPB_INTR_ENABLES 0x02 |
| 1321 | #define IOPB_CHIP_TYPE_REV 0x03 |
| 1322 | #define IOPB_RES_ADDR_4 0x04 |
| 1323 | #define IOPB_RES_ADDR_5 0x05 |
| 1324 | #define IOPB_RAM_DATA 0x06 |
| 1325 | #define IOPB_RES_ADDR_7 0x07 |
| 1326 | #define IOPB_FLAG_REG 0x08 |
| 1327 | #define IOPB_RES_ADDR_9 0x09 |
| 1328 | #define IOPB_RISC_CSR 0x0A |
| 1329 | #define IOPB_RES_ADDR_B 0x0B |
| 1330 | #define IOPB_RES_ADDR_C 0x0C |
| 1331 | #define IOPB_RES_ADDR_D 0x0D |
| 1332 | #define IOPB_SOFT_OVER_WR 0x0E |
| 1333 | #define IOPB_RES_ADDR_F 0x0F |
| 1334 | #define IOPB_MEM_CFG 0x10 |
| 1335 | #define IOPB_RES_ADDR_11 0x11 |
| 1336 | #define IOPB_GPIO_DATA 0x12 |
| 1337 | #define IOPB_RES_ADDR_13 0x13 |
| 1338 | #define IOPB_FLASH_PAGE 0x14 |
| 1339 | #define IOPB_RES_ADDR_15 0x15 |
| 1340 | #define IOPB_GPIO_CNTL 0x16 |
| 1341 | #define IOPB_RES_ADDR_17 0x17 |
| 1342 | #define IOPB_FLASH_DATA 0x18 |
| 1343 | #define IOPB_RES_ADDR_19 0x19 |
| 1344 | #define IOPB_RES_ADDR_1A 0x1A |
| 1345 | #define IOPB_RES_ADDR_1B 0x1B |
| 1346 | #define IOPB_RES_ADDR_1C 0x1C |
| 1347 | #define IOPB_RES_ADDR_1D 0x1D |
| 1348 | #define IOPB_RES_ADDR_1E 0x1E |
| 1349 | #define IOPB_RES_ADDR_1F 0x1F |
| 1350 | #define IOPB_DMA_CFG0 0x20 |
| 1351 | #define IOPB_DMA_CFG1 0x21 |
| 1352 | #define IOPB_TICKLE 0x22 |
| 1353 | #define IOPB_DMA_REG_WR 0x23 |
| 1354 | #define IOPB_SDMA_STATUS 0x24 |
| 1355 | #define IOPB_SCSI_BYTE_CNT 0x25 |
| 1356 | #define IOPB_HOST_BYTE_CNT 0x26 |
| 1357 | #define IOPB_BYTE_LEFT_TO_XFER 0x27 |
| 1358 | #define IOPB_BYTE_TO_XFER_0 0x28 |
| 1359 | #define IOPB_BYTE_TO_XFER_1 0x29 |
| 1360 | #define IOPB_BYTE_TO_XFER_2 0x2A |
| 1361 | #define IOPB_BYTE_TO_XFER_3 0x2B |
| 1362 | #define IOPB_ACC_GRP 0x2C |
| 1363 | #define IOPB_RES_ADDR_2D 0x2D |
| 1364 | #define IOPB_DEV_ID 0x2E |
| 1365 | #define IOPB_RES_ADDR_2F 0x2F |
| 1366 | #define IOPB_SCSI_DATA 0x30 |
| 1367 | #define IOPB_RES_ADDR_31 0x31 |
| 1368 | #define IOPB_RES_ADDR_32 0x32 |
| 1369 | #define IOPB_SCSI_DATA_HSHK 0x33 |
| 1370 | #define IOPB_SCSI_CTRL 0x34 |
| 1371 | #define IOPB_RES_ADDR_35 0x35 |
| 1372 | #define IOPB_RES_ADDR_36 0x36 |
| 1373 | #define IOPB_RES_ADDR_37 0x37 |
| 1374 | #define IOPB_RAM_BIST 0x38 |
| 1375 | #define IOPB_PLL_TEST 0x39 |
| 1376 | #define IOPB_PCI_INT_CFG 0x3A |
| 1377 | #define IOPB_RES_ADDR_3B 0x3B |
| 1378 | #define IOPB_RFIFO_CNT 0x3C |
| 1379 | #define IOPB_RES_ADDR_3D 0x3D |
| 1380 | #define IOPB_RES_ADDR_3E 0x3E |
| 1381 | #define IOPB_RES_ADDR_3F 0x3F |
| 1382 | |
| 1383 | /* |
| 1384 | * Word I/O register address from base of 'iop_base'. |
| 1385 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1386 | #define IOPW_CHIP_ID_0 0x00 /* CID0 */ |
| 1387 | #define IOPW_CTRL_REG 0x02 /* CC */ |
| 1388 | #define IOPW_RAM_ADDR 0x04 /* LA */ |
| 1389 | #define IOPW_RAM_DATA 0x06 /* LD */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | #define IOPW_RES_ADDR_08 0x08 |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1391 | #define IOPW_RISC_CSR 0x0A /* CSR */ |
| 1392 | #define IOPW_SCSI_CFG0 0x0C /* CFG0 */ |
| 1393 | #define IOPW_SCSI_CFG1 0x0E /* CFG1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | #define IOPW_RES_ADDR_10 0x10 |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1395 | #define IOPW_SEL_MASK 0x12 /* SM */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | #define IOPW_RES_ADDR_14 0x14 |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1397 | #define IOPW_FLASH_ADDR 0x16 /* FA */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | #define IOPW_RES_ADDR_18 0x18 |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1399 | #define IOPW_EE_CMD 0x1A /* EC */ |
| 1400 | #define IOPW_EE_DATA 0x1C /* ED */ |
| 1401 | #define IOPW_SFIFO_CNT 0x1E /* SFC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | #define IOPW_RES_ADDR_20 0x20 |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1403 | #define IOPW_Q_BASE 0x22 /* QB */ |
| 1404 | #define IOPW_QP 0x24 /* QP */ |
| 1405 | #define IOPW_IX 0x26 /* IX */ |
| 1406 | #define IOPW_SP 0x28 /* SP */ |
| 1407 | #define IOPW_PC 0x2A /* PC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | #define IOPW_RES_ADDR_2C 0x2C |
| 1409 | #define IOPW_RES_ADDR_2E 0x2E |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1410 | #define IOPW_SCSI_DATA 0x30 /* SD */ |
| 1411 | #define IOPW_SCSI_DATA_HSHK 0x32 /* SDH */ |
| 1412 | #define IOPW_SCSI_CTRL 0x34 /* SC */ |
| 1413 | #define IOPW_HSHK_CFG 0x36 /* HCFG */ |
| 1414 | #define IOPW_SXFR_STATUS 0x36 /* SXS */ |
| 1415 | #define IOPW_SXFR_CNTL 0x38 /* SXL */ |
| 1416 | #define IOPW_SXFR_CNTH 0x3A /* SXH */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | #define IOPW_RES_ADDR_3C 0x3C |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1418 | #define IOPW_RFIFO_DATA 0x3E /* RFD */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | |
| 1420 | /* |
| 1421 | * Doubleword I/O register address from base of 'iop_base'. |
| 1422 | */ |
| 1423 | #define IOPDW_RES_ADDR_0 0x00 |
| 1424 | #define IOPDW_RAM_DATA 0x04 |
| 1425 | #define IOPDW_RES_ADDR_8 0x08 |
| 1426 | #define IOPDW_RES_ADDR_C 0x0C |
| 1427 | #define IOPDW_RES_ADDR_10 0x10 |
| 1428 | #define IOPDW_COMMA 0x14 |
| 1429 | #define IOPDW_COMMB 0x18 |
| 1430 | #define IOPDW_RES_ADDR_1C 0x1C |
| 1431 | #define IOPDW_SDMA_ADDR0 0x20 |
| 1432 | #define IOPDW_SDMA_ADDR1 0x24 |
| 1433 | #define IOPDW_SDMA_COUNT 0x28 |
| 1434 | #define IOPDW_SDMA_ERROR 0x2C |
| 1435 | #define IOPDW_RDMA_ADDR0 0x30 |
| 1436 | #define IOPDW_RDMA_ADDR1 0x34 |
| 1437 | #define IOPDW_RDMA_COUNT 0x38 |
| 1438 | #define IOPDW_RDMA_ERROR 0x3C |
| 1439 | |
| 1440 | #define ADV_CHIP_ID_BYTE 0x25 |
| 1441 | #define ADV_CHIP_ID_WORD 0x04C1 |
| 1442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | #define ADV_INTR_ENABLE_HOST_INTR 0x01 |
| 1444 | #define ADV_INTR_ENABLE_SEL_INTR 0x02 |
| 1445 | #define ADV_INTR_ENABLE_DPR_INTR 0x04 |
| 1446 | #define ADV_INTR_ENABLE_RTA_INTR 0x08 |
| 1447 | #define ADV_INTR_ENABLE_RMA_INTR 0x10 |
| 1448 | #define ADV_INTR_ENABLE_RST_INTR 0x20 |
| 1449 | #define ADV_INTR_ENABLE_DPE_INTR 0x40 |
| 1450 | #define ADV_INTR_ENABLE_GLOBAL_INTR 0x80 |
| 1451 | |
| 1452 | #define ADV_INTR_STATUS_INTRA 0x01 |
| 1453 | #define ADV_INTR_STATUS_INTRB 0x02 |
| 1454 | #define ADV_INTR_STATUS_INTRC 0x04 |
| 1455 | |
| 1456 | #define ADV_RISC_CSR_STOP (0x0000) |
| 1457 | #define ADV_RISC_TEST_COND (0x2000) |
| 1458 | #define ADV_RISC_CSR_RUN (0x4000) |
| 1459 | #define ADV_RISC_CSR_SINGLE_STEP (0x8000) |
| 1460 | |
| 1461 | #define ADV_CTRL_REG_HOST_INTR 0x0100 |
| 1462 | #define ADV_CTRL_REG_SEL_INTR 0x0200 |
| 1463 | #define ADV_CTRL_REG_DPR_INTR 0x0400 |
| 1464 | #define ADV_CTRL_REG_RTA_INTR 0x0800 |
| 1465 | #define ADV_CTRL_REG_RMA_INTR 0x1000 |
| 1466 | #define ADV_CTRL_REG_RES_BIT14 0x2000 |
| 1467 | #define ADV_CTRL_REG_DPE_INTR 0x4000 |
| 1468 | #define ADV_CTRL_REG_POWER_DONE 0x8000 |
| 1469 | #define ADV_CTRL_REG_ANY_INTR 0xFF00 |
| 1470 | |
| 1471 | #define ADV_CTRL_REG_CMD_RESET 0x00C6 |
| 1472 | #define ADV_CTRL_REG_CMD_WR_IO_REG 0x00C5 |
| 1473 | #define ADV_CTRL_REG_CMD_RD_IO_REG 0x00C4 |
| 1474 | #define ADV_CTRL_REG_CMD_WR_PCI_CFG_SPACE 0x00C3 |
| 1475 | #define ADV_CTRL_REG_CMD_RD_PCI_CFG_SPACE 0x00C2 |
| 1476 | |
| 1477 | #define ADV_TICKLE_NOP 0x00 |
| 1478 | #define ADV_TICKLE_A 0x01 |
| 1479 | #define ADV_TICKLE_B 0x02 |
| 1480 | #define ADV_TICKLE_C 0x03 |
| 1481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | #define AdvIsIntPending(port) \ |
| 1483 | (AdvReadWordRegister(port, IOPW_CTRL_REG) & ADV_CTRL_REG_HOST_INTR) |
| 1484 | |
| 1485 | /* |
| 1486 | * SCSI_CFG0 Register bit definitions |
| 1487 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1488 | #define TIMER_MODEAB 0xC000 /* Watchdog, Second, and Select. Timer Ctrl. */ |
| 1489 | #define PARITY_EN 0x2000 /* Enable SCSI Parity Error detection */ |
| 1490 | #define EVEN_PARITY 0x1000 /* Select Even Parity */ |
| 1491 | #define WD_LONG 0x0800 /* Watchdog Interval, 1: 57 min, 0: 13 sec */ |
| 1492 | #define QUEUE_128 0x0400 /* Queue Size, 1: 128 byte, 0: 64 byte */ |
| 1493 | #define PRIM_MODE 0x0100 /* Primitive SCSI mode */ |
| 1494 | #define SCAM_EN 0x0080 /* Enable SCAM selection */ |
| 1495 | #define SEL_TMO_LONG 0x0040 /* Sel/Resel Timeout, 1: 400 ms, 0: 1.6 ms */ |
| 1496 | #define CFRM_ID 0x0020 /* SCAM id sel. confirm., 1: fast, 0: 6.4 ms */ |
| 1497 | #define OUR_ID_EN 0x0010 /* Enable OUR_ID bits */ |
| 1498 | #define OUR_ID 0x000F /* SCSI ID */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | |
| 1500 | /* |
| 1501 | * SCSI_CFG1 Register bit definitions |
| 1502 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1503 | #define BIG_ENDIAN 0x8000 /* Enable Big Endian Mode MIO:15, EEP:15 */ |
| 1504 | #define TERM_POL 0x2000 /* Terminator Polarity Ctrl. MIO:13, EEP:13 */ |
| 1505 | #define SLEW_RATE 0x1000 /* SCSI output buffer slew rate */ |
| 1506 | #define FILTER_SEL 0x0C00 /* Filter Period Selection */ |
| 1507 | #define FLTR_DISABLE 0x0000 /* Input Filtering Disabled */ |
| 1508 | #define FLTR_11_TO_20NS 0x0800 /* Input Filtering 11ns to 20ns */ |
| 1509 | #define FLTR_21_TO_39NS 0x0C00 /* Input Filtering 21ns to 39ns */ |
| 1510 | #define ACTIVE_DBL 0x0200 /* Disable Active Negation */ |
| 1511 | #define DIFF_MODE 0x0100 /* SCSI differential Mode (Read-Only) */ |
| 1512 | #define DIFF_SENSE 0x0080 /* 1: No SE cables, 0: SE cable (Read-Only) */ |
| 1513 | #define TERM_CTL_SEL 0x0040 /* Enable TERM_CTL_H and TERM_CTL_L */ |
| 1514 | #define TERM_CTL 0x0030 /* External SCSI Termination Bits */ |
| 1515 | #define TERM_CTL_H 0x0020 /* Enable External SCSI Upper Termination */ |
| 1516 | #define TERM_CTL_L 0x0010 /* Enable External SCSI Lower Termination */ |
| 1517 | #define CABLE_DETECT 0x000F /* External SCSI Cable Connection Status */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | |
| 1519 | /* |
| 1520 | * Addendum for ASC-38C0800 Chip |
| 1521 | * |
| 1522 | * The ASC-38C1600 Chip uses the same definitions except that the |
| 1523 | * bus mode override bits [12:10] have been moved to byte register |
| 1524 | * offset 0xE (IOPB_SOFT_OVER_WR) bits [12:10]. The [12:10] bits in |
| 1525 | * SCSI_CFG1 are read-only and always available. Bit 14 (DIS_TERM_DRV) |
| 1526 | * is not needed. The [12:10] bits in IOPB_SOFT_OVER_WR are write-only. |
| 1527 | * Also each ASC-38C1600 function or channel uses only cable bits [5:4] |
| 1528 | * and [1:0]. Bits [14], [7:6], [3:2] are unused. |
| 1529 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1530 | #define DIS_TERM_DRV 0x4000 /* 1: Read c_det[3:0], 0: cannot read */ |
| 1531 | #define HVD_LVD_SE 0x1C00 /* Device Detect Bits */ |
| 1532 | #define HVD 0x1000 /* HVD Device Detect */ |
| 1533 | #define LVD 0x0800 /* LVD Device Detect */ |
| 1534 | #define SE 0x0400 /* SE Device Detect */ |
| 1535 | #define TERM_LVD 0x00C0 /* LVD Termination Bits */ |
| 1536 | #define TERM_LVD_HI 0x0080 /* Enable LVD Upper Termination */ |
| 1537 | #define TERM_LVD_LO 0x0040 /* Enable LVD Lower Termination */ |
| 1538 | #define TERM_SE 0x0030 /* SE Termination Bits */ |
| 1539 | #define TERM_SE_HI 0x0020 /* Enable SE Upper Termination */ |
| 1540 | #define TERM_SE_LO 0x0010 /* Enable SE Lower Termination */ |
| 1541 | #define C_DET_LVD 0x000C /* LVD Cable Detect Bits */ |
| 1542 | #define C_DET3 0x0008 /* Cable Detect for LVD External Wide */ |
| 1543 | #define C_DET2 0x0004 /* Cable Detect for LVD Internal Wide */ |
| 1544 | #define C_DET_SE 0x0003 /* SE Cable Detect Bits */ |
| 1545 | #define C_DET1 0x0002 /* Cable Detect for SE Internal Wide */ |
| 1546 | #define C_DET0 0x0001 /* Cable Detect for SE Internal Narrow */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | |
| 1548 | #define CABLE_ILLEGAL_A 0x7 |
| 1549 | /* x 0 0 0 | on on | Illegal (all 3 connectors are used) */ |
| 1550 | |
| 1551 | #define CABLE_ILLEGAL_B 0xB |
| 1552 | /* 0 x 0 0 | on on | Illegal (all 3 connectors are used) */ |
| 1553 | |
| 1554 | /* |
| 1555 | * MEM_CFG Register bit definitions |
| 1556 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1557 | #define BIOS_EN 0x40 /* BIOS Enable MIO:14,EEP:14 */ |
| 1558 | #define FAST_EE_CLK 0x20 /* Diagnostic Bit */ |
| 1559 | #define RAM_SZ 0x1C /* Specify size of RAM to RISC */ |
| 1560 | #define RAM_SZ_2KB 0x00 /* 2 KB */ |
| 1561 | #define RAM_SZ_4KB 0x04 /* 4 KB */ |
| 1562 | #define RAM_SZ_8KB 0x08 /* 8 KB */ |
| 1563 | #define RAM_SZ_16KB 0x0C /* 16 KB */ |
| 1564 | #define RAM_SZ_32KB 0x10 /* 32 KB */ |
| 1565 | #define RAM_SZ_64KB 0x14 /* 64 KB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | |
| 1567 | /* |
| 1568 | * DMA_CFG0 Register bit definitions |
| 1569 | * |
| 1570 | * This register is only accessible to the host. |
| 1571 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1572 | #define BC_THRESH_ENB 0x80 /* PCI DMA Start Conditions */ |
| 1573 | #define FIFO_THRESH 0x70 /* PCI DMA FIFO Threshold */ |
| 1574 | #define FIFO_THRESH_16B 0x00 /* 16 bytes */ |
| 1575 | #define FIFO_THRESH_32B 0x20 /* 32 bytes */ |
| 1576 | #define FIFO_THRESH_48B 0x30 /* 48 bytes */ |
| 1577 | #define FIFO_THRESH_64B 0x40 /* 64 bytes */ |
| 1578 | #define FIFO_THRESH_80B 0x50 /* 80 bytes (default) */ |
| 1579 | #define FIFO_THRESH_96B 0x60 /* 96 bytes */ |
| 1580 | #define FIFO_THRESH_112B 0x70 /* 112 bytes */ |
| 1581 | #define START_CTL 0x0C /* DMA start conditions */ |
| 1582 | #define START_CTL_TH 0x00 /* Wait threshold level (default) */ |
| 1583 | #define START_CTL_ID 0x04 /* Wait SDMA/SBUS idle */ |
| 1584 | #define START_CTL_THID 0x08 /* Wait threshold and SDMA/SBUS idle */ |
| 1585 | #define START_CTL_EMFU 0x0C /* Wait SDMA FIFO empty/full */ |
| 1586 | #define READ_CMD 0x03 /* Memory Read Method */ |
| 1587 | #define READ_CMD_MR 0x00 /* Memory Read */ |
| 1588 | #define READ_CMD_MRL 0x02 /* Memory Read Long */ |
| 1589 | #define READ_CMD_MRM 0x03 /* Memory Read Multiple (default) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | |
| 1591 | /* |
| 1592 | * ASC-38C0800 RAM BIST Register bit definitions |
| 1593 | */ |
| 1594 | #define RAM_TEST_MODE 0x80 |
| 1595 | #define PRE_TEST_MODE 0x40 |
| 1596 | #define NORMAL_MODE 0x00 |
| 1597 | #define RAM_TEST_DONE 0x10 |
| 1598 | #define RAM_TEST_STATUS 0x0F |
| 1599 | #define RAM_TEST_HOST_ERROR 0x08 |
| 1600 | #define RAM_TEST_INTRAM_ERROR 0x04 |
| 1601 | #define RAM_TEST_RISC_ERROR 0x02 |
| 1602 | #define RAM_TEST_SCSI_ERROR 0x01 |
| 1603 | #define RAM_TEST_SUCCESS 0x00 |
| 1604 | #define PRE_TEST_VALUE 0x05 |
| 1605 | #define NORMAL_VALUE 0x00 |
| 1606 | |
| 1607 | /* |
| 1608 | * ASC38C1600 Definitions |
| 1609 | * |
| 1610 | * IOPB_PCI_INT_CFG Bit Field Definitions |
| 1611 | */ |
| 1612 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1613 | #define INTAB_LD 0x80 /* Value loaded from EEPROM Bit 11. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | |
| 1615 | /* |
| 1616 | * Bit 1 can be set to change the interrupt for the Function to operate in |
| 1617 | * Totem Pole mode. By default Bit 1 is 0 and the interrupt operates in |
| 1618 | * Open Drain mode. Both functions of the ASC38C1600 must be set to the same |
| 1619 | * mode, otherwise the operating mode is undefined. |
| 1620 | */ |
| 1621 | #define TOTEMPOLE 0x02 |
| 1622 | |
| 1623 | /* |
| 1624 | * Bit 0 can be used to change the Int Pin for the Function. The value is |
| 1625 | * 0 by default for both Functions with Function 0 using INT A and Function |
| 1626 | * B using INT B. For Function 0 if set, INT B is used. For Function 1 if set, |
| 1627 | * INT A is used. |
| 1628 | * |
| 1629 | * EEPROM Word 0 Bit 11 for each Function may change the initial Int Pin |
| 1630 | * value specified in the PCI Configuration Space. |
| 1631 | */ |
| 1632 | #define INTAB 0x01 |
| 1633 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | /* |
| 1635 | * Adv Library Status Definitions |
| 1636 | */ |
| 1637 | #define ADV_TRUE 1 |
| 1638 | #define ADV_FALSE 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | #define ADV_SUCCESS 1 |
| 1640 | #define ADV_BUSY 0 |
| 1641 | #define ADV_ERROR (-1) |
| 1642 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | /* |
| 1644 | * ADV_DVC_VAR 'warn_code' values |
| 1645 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1646 | #define ASC_WARN_BUSRESET_ERROR 0x0001 /* SCSI Bus Reset error */ |
| 1647 | #define ASC_WARN_EEPROM_CHKSUM 0x0002 /* EEP check sum error */ |
| 1648 | #define ASC_WARN_EEPROM_TERMINATION 0x0004 /* EEP termination bad field */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1649 | #define ASC_WARN_ERROR 0xFFFF /* ADV_ERROR return */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1651 | #define ADV_MAX_TID 15 /* max. target identifier */ |
| 1652 | #define ADV_MAX_LUN 7 /* max. logical unit number */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | |
| 1654 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | * Fixed locations of microcode operating variables. |
| 1656 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1657 | #define ASC_MC_CODE_BEGIN_ADDR 0x0028 /* microcode start address */ |
| 1658 | #define ASC_MC_CODE_END_ADDR 0x002A /* microcode end address */ |
| 1659 | #define ASC_MC_CODE_CHK_SUM 0x002C /* microcode code checksum */ |
| 1660 | #define ASC_MC_VERSION_DATE 0x0038 /* microcode version */ |
| 1661 | #define ASC_MC_VERSION_NUM 0x003A /* microcode number */ |
| 1662 | #define ASC_MC_BIOSMEM 0x0040 /* BIOS RISC Memory Start */ |
| 1663 | #define ASC_MC_BIOSLEN 0x0050 /* BIOS RISC Memory Length */ |
| 1664 | #define ASC_MC_BIOS_SIGNATURE 0x0058 /* BIOS Signature 0x55AA */ |
| 1665 | #define ASC_MC_BIOS_VERSION 0x005A /* BIOS Version (2 bytes) */ |
| 1666 | #define ASC_MC_SDTR_SPEED1 0x0090 /* SDTR Speed for TID 0-3 */ |
| 1667 | #define ASC_MC_SDTR_SPEED2 0x0092 /* SDTR Speed for TID 4-7 */ |
| 1668 | #define ASC_MC_SDTR_SPEED3 0x0094 /* SDTR Speed for TID 8-11 */ |
| 1669 | #define ASC_MC_SDTR_SPEED4 0x0096 /* SDTR Speed for TID 12-15 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | #define ASC_MC_CHIP_TYPE 0x009A |
| 1671 | #define ASC_MC_INTRB_CODE 0x009B |
| 1672 | #define ASC_MC_WDTR_ABLE 0x009C |
| 1673 | #define ASC_MC_SDTR_ABLE 0x009E |
| 1674 | #define ASC_MC_TAGQNG_ABLE 0x00A0 |
| 1675 | #define ASC_MC_DISC_ENABLE 0x00A2 |
| 1676 | #define ASC_MC_IDLE_CMD_STATUS 0x00A4 |
| 1677 | #define ASC_MC_IDLE_CMD 0x00A6 |
| 1678 | #define ASC_MC_IDLE_CMD_PARAMETER 0x00A8 |
| 1679 | #define ASC_MC_DEFAULT_SCSI_CFG0 0x00AC |
| 1680 | #define ASC_MC_DEFAULT_SCSI_CFG1 0x00AE |
| 1681 | #define ASC_MC_DEFAULT_MEM_CFG 0x00B0 |
| 1682 | #define ASC_MC_DEFAULT_SEL_MASK 0x00B2 |
| 1683 | #define ASC_MC_SDTR_DONE 0x00B6 |
| 1684 | #define ASC_MC_NUMBER_OF_QUEUED_CMD 0x00C0 |
| 1685 | #define ASC_MC_NUMBER_OF_MAX_CMD 0x00D0 |
| 1686 | #define ASC_MC_DEVICE_HSHK_CFG_TABLE 0x0100 |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1687 | #define ASC_MC_CONTROL_FLAG 0x0122 /* Microcode control flag. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | #define ASC_MC_WDTR_DONE 0x0124 |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1689 | #define ASC_MC_CAM_MODE_MASK 0x015E /* CAM mode TID bitmask. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | #define ASC_MC_ICQ 0x0160 |
| 1691 | #define ASC_MC_IRQ 0x0164 |
| 1692 | #define ASC_MC_PPR_ABLE 0x017A |
| 1693 | |
| 1694 | /* |
| 1695 | * BIOS LRAM variable absolute offsets. |
| 1696 | */ |
| 1697 | #define BIOS_CODESEG 0x54 |
| 1698 | #define BIOS_CODELEN 0x56 |
| 1699 | #define BIOS_SIGNATURE 0x58 |
| 1700 | #define BIOS_VERSION 0x5A |
| 1701 | |
| 1702 | /* |
| 1703 | * Microcode Control Flags |
| 1704 | * |
| 1705 | * Flags set by the Adv Library in RISC variable 'control_flag' (0x122) |
| 1706 | * and handled by the microcode. |
| 1707 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1708 | #define CONTROL_FLAG_IGNORE_PERR 0x0001 /* Ignore DMA Parity Errors */ |
| 1709 | #define CONTROL_FLAG_ENABLE_AIPP 0x0002 /* Enabled AIPP checking. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | |
| 1711 | /* |
| 1712 | * ASC_MC_DEVICE_HSHK_CFG_TABLE microcode table or HSHK_CFG register format |
| 1713 | */ |
| 1714 | #define HSHK_CFG_WIDE_XFR 0x8000 |
| 1715 | #define HSHK_CFG_RATE 0x0F00 |
| 1716 | #define HSHK_CFG_OFFSET 0x001F |
| 1717 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1718 | #define ASC_DEF_MAX_HOST_QNG 0xFD /* Max. number of host commands (253) */ |
| 1719 | #define ASC_DEF_MIN_HOST_QNG 0x10 /* Min. number of host commands (16) */ |
| 1720 | #define ASC_DEF_MAX_DVC_QNG 0x3F /* Max. number commands per device (63) */ |
| 1721 | #define ASC_DEF_MIN_DVC_QNG 0x04 /* Min. number commands per device (4) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1723 | #define ASC_QC_DATA_CHECK 0x01 /* Require ASC_QC_DATA_OUT set or clear. */ |
| 1724 | #define ASC_QC_DATA_OUT 0x02 /* Data out DMA transfer. */ |
| 1725 | #define ASC_QC_START_MOTOR 0x04 /* Send auto-start motor before request. */ |
| 1726 | #define ASC_QC_NO_OVERRUN 0x08 /* Don't report overrun. */ |
| 1727 | #define ASC_QC_FREEZE_TIDQ 0x10 /* Freeze TID queue after request. XXX TBD */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1729 | #define ASC_QSC_NO_DISC 0x01 /* Don't allow disconnect for request. */ |
| 1730 | #define ASC_QSC_NO_TAGMSG 0x02 /* Don't allow tag queuing for request. */ |
| 1731 | #define ASC_QSC_NO_SYNC 0x04 /* Don't use Synch. transfer on request. */ |
| 1732 | #define ASC_QSC_NO_WIDE 0x08 /* Don't use Wide transfer on request. */ |
| 1733 | #define ASC_QSC_REDO_DTR 0x10 /* Renegotiate WDTR/SDTR before request. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | /* |
| 1735 | * Note: If a Tag Message is to be sent and neither ASC_QSC_HEAD_TAG or |
| 1736 | * ASC_QSC_ORDERED_TAG is set, then a Simple Tag Message (0x20) is used. |
| 1737 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1738 | #define ASC_QSC_HEAD_TAG 0x40 /* Use Head Tag Message (0x21). */ |
| 1739 | #define ASC_QSC_ORDERED_TAG 0x80 /* Use Ordered Tag Message (0x22). */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | |
| 1741 | /* |
| 1742 | * All fields here are accessed by the board microcode and need to be |
| 1743 | * little-endian. |
| 1744 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1745 | typedef struct adv_carr_t { |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 1746 | __le32 carr_va; /* Carrier Virtual Address */ |
| 1747 | __le32 carr_pa; /* Carrier Physical Address */ |
| 1748 | __le32 areq_vpa; /* ASC_SCSI_REQ_Q Virtual or Physical Address */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1749 | /* |
| 1750 | * next_vpa [31:4] Carrier Virtual or Physical Next Pointer |
| 1751 | * |
| 1752 | * next_vpa [3:1] Reserved Bits |
| 1753 | * next_vpa [0] Done Flag set in Response Queue. |
| 1754 | */ |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 1755 | __le32 next_vpa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | } ADV_CARR_T; |
| 1757 | |
| 1758 | /* |
| 1759 | * Mask used to eliminate low 4 bits of carrier 'next_vpa' field. |
| 1760 | */ |
| 1761 | #define ASC_NEXT_VPA_MASK 0xFFFFFFF0 |
| 1762 | |
| 1763 | #define ASC_RQ_DONE 0x00000001 |
| 1764 | #define ASC_RQ_GOOD 0x00000002 |
| 1765 | #define ASC_CQ_STOPPER 0x00000000 |
| 1766 | |
| 1767 | #define ASC_GET_CARRP(carrp) ((carrp) & ASC_NEXT_VPA_MASK) |
| 1768 | |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 1769 | /* |
| 1770 | * Each carrier is 64 bytes, and we need three additional |
| 1771 | * carrier for icq, irq, and the termination carrier. |
| 1772 | */ |
| 1773 | #define ADV_CARRIER_COUNT (ASC_DEF_MAX_HOST_QNG + 3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | |
| 1775 | #define ADV_CARRIER_BUFSIZE \ |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 1776 | (ADV_CARRIER_COUNT * sizeof(ADV_CARR_T)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | |
| 1778 | /* |
| 1779 | * ASC_SCSI_REQ_Q 'a_flag' definitions |
| 1780 | * |
| 1781 | * The Adv Library should limit use to the lower nibble (4 bits) of |
| 1782 | * a_flag. Drivers are free to use the upper nibble (4 bits) of a_flag. |
| 1783 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1784 | #define ADV_POLL_REQUEST 0x01 /* poll for request completion */ |
| 1785 | #define ADV_SCSIQ_DONE 0x02 /* request done */ |
| 1786 | #define ADV_DONT_RETRY 0x08 /* don't do retry */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1788 | #define ADV_CHIP_ASC3550 0x01 /* Ultra-Wide IC */ |
| 1789 | #define ADV_CHIP_ASC38C0800 0x02 /* Ultra2-Wide/LVD IC */ |
| 1790 | #define ADV_CHIP_ASC38C1600 0x03 /* Ultra3-Wide/LVD2 IC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | |
| 1792 | /* |
| 1793 | * Adapter temporary configuration structure |
| 1794 | * |
| 1795 | * This structure can be discarded after initialization. Don't add |
| 1796 | * fields here needed after initialization. |
| 1797 | * |
| 1798 | * Field naming convention: |
| 1799 | * |
| 1800 | * *_enable indicates the field enables or disables a feature. The |
| 1801 | * value of the field is never reset. |
| 1802 | */ |
| 1803 | typedef struct adv_dvc_cfg { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1804 | ushort disc_enable; /* enable disconnection */ |
| 1805 | uchar chip_version; /* chip version */ |
| 1806 | uchar termination; /* Term. Ctrl. bits 6-5 of SCSI_CFG1 register */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1807 | ushort control_flag; /* Microcode Control Flag */ |
| 1808 | ushort mcode_date; /* Microcode date */ |
| 1809 | ushort mcode_version; /* Microcode version */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1810 | ushort serial1; /* EEPROM serial number word 1 */ |
| 1811 | ushort serial2; /* EEPROM serial number word 2 */ |
| 1812 | ushort serial3; /* EEPROM serial number word 3 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | } ADV_DVC_CFG; |
| 1814 | |
| 1815 | struct adv_dvc_var; |
| 1816 | struct adv_scsi_req_q; |
| 1817 | |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 1818 | typedef struct adv_sg_block { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1819 | uchar reserved1; |
| 1820 | uchar reserved2; |
| 1821 | uchar reserved3; |
| 1822 | uchar sg_cnt; /* Valid entries in block. */ |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 1823 | __le32 sg_ptr; /* Pointer to next sg block. */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1824 | struct { |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 1825 | __le32 sg_addr; /* SG element address. */ |
| 1826 | __le32 sg_count; /* SG element count. */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1827 | } sg_list[NO_OF_SG_PER_BLOCK]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | } ADV_SG_BLOCK; |
| 1829 | |
| 1830 | /* |
| 1831 | * ADV_SCSI_REQ_Q - microcode request structure |
| 1832 | * |
| 1833 | * All fields in this structure up to byte 60 are used by the microcode. |
| 1834 | * The microcode makes assumptions about the size and ordering of fields |
| 1835 | * in this structure. Do not change the structure definition here without |
| 1836 | * coordinating the change with the microcode. |
| 1837 | * |
| 1838 | * All fields accessed by microcode must be maintained in little_endian |
| 1839 | * order. |
| 1840 | */ |
| 1841 | typedef struct adv_scsi_req_q { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1842 | uchar cntl; /* Ucode flags and state (ASC_MC_QC_*). */ |
| 1843 | uchar target_cmd; |
| 1844 | uchar target_id; /* Device target identifier. */ |
| 1845 | uchar target_lun; /* Device target logical unit number. */ |
| 1846 | ADV_PADDR data_addr; /* Data buffer physical address. */ |
| 1847 | ADV_DCNT data_cnt; /* Data count. Ucode sets to residual. */ |
Hannes Reinecke | 811ddc0 | 2015-04-24 13:18:22 +0200 | [diff] [blame] | 1848 | __le32 sense_addr; |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 1849 | __le32 carr_pa; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1850 | uchar mflag; |
| 1851 | uchar sense_len; |
| 1852 | uchar cdb_len; /* SCSI CDB length. Must <= 16 bytes. */ |
| 1853 | uchar scsi_cntl; |
| 1854 | uchar done_status; /* Completion status. */ |
| 1855 | uchar scsi_status; /* SCSI status byte. */ |
| 1856 | uchar host_status; /* Ucode host status. */ |
| 1857 | uchar sg_working_ix; |
| 1858 | uchar cdb[12]; /* SCSI CDB bytes 0-11. */ |
| 1859 | ADV_PADDR sg_real_addr; /* SG list physical address. */ |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 1860 | __le32 scsiq_rptr; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1861 | uchar cdb16[4]; /* SCSI CDB bytes 12-15. */ |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 1862 | __le32 scsiq_ptr; |
| 1863 | __le32 carr_va; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1864 | /* |
| 1865 | * End of microcode structure - 60 bytes. The rest of the structure |
| 1866 | * is used by the Adv Library and ignored by the microcode. |
| 1867 | */ |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 1868 | u32 srb_tag; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1869 | uchar a_flag; |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 1870 | uchar pad[3]; /* Pad out to a word boundary. */ |
| 1871 | ADV_SG_BLOCK *sg_list_ptr; /* SG list virtual address. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | } ADV_SCSI_REQ_Q; |
| 1873 | |
| 1874 | /* |
Matthew Wilcox | 98d41c2 | 2007-10-02 21:55:37 -0400 | [diff] [blame] | 1875 | * The following two structures are used to process Wide Board requests. |
| 1876 | * |
| 1877 | * The ADV_SCSI_REQ_Q structure in adv_req_t is passed to the Adv Library |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 1878 | * and microcode with the ADV_SCSI_REQ_Q field 'srb_tag' set to the |
| 1879 | * SCSI request tag. The adv_req_t structure 'cmndp' field in turn points |
| 1880 | * to the Mid-Level SCSI request structure. |
Matthew Wilcox | 98d41c2 | 2007-10-02 21:55:37 -0400 | [diff] [blame] | 1881 | * |
| 1882 | * Zero or more ADV_SG_BLOCK are used with each ADV_SCSI_REQ_Q. Each |
| 1883 | * ADV_SG_BLOCK structure holds 15 scatter-gather elements. Under Linux |
| 1884 | * up to 255 scatter-gather elements may be used per request or |
| 1885 | * ADV_SCSI_REQ_Q. |
| 1886 | * |
| 1887 | * Both structures must be 32 byte aligned. |
| 1888 | */ |
| 1889 | typedef struct adv_sgblk { |
| 1890 | ADV_SG_BLOCK sg_block; /* Sgblock structure. */ |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 1891 | dma_addr_t sg_addr; /* Physical address */ |
Matthew Wilcox | 98d41c2 | 2007-10-02 21:55:37 -0400 | [diff] [blame] | 1892 | struct adv_sgblk *next_sgblkp; /* Next scatter-gather structure. */ |
| 1893 | } adv_sgblk_t; |
| 1894 | |
| 1895 | typedef struct adv_req { |
| 1896 | ADV_SCSI_REQ_Q scsi_req_q; /* Adv Library request structure. */ |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 1897 | uchar align[24]; /* Request structure padding. */ |
Matthew Wilcox | 98d41c2 | 2007-10-02 21:55:37 -0400 | [diff] [blame] | 1898 | struct scsi_cmnd *cmndp; /* Mid-Level SCSI command pointer. */ |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 1899 | dma_addr_t req_addr; |
Matthew Wilcox | 98d41c2 | 2007-10-02 21:55:37 -0400 | [diff] [blame] | 1900 | adv_sgblk_t *sgblkp; /* Adv Library scatter-gather pointer. */ |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 1901 | } adv_req_t __aligned(32); |
Matthew Wilcox | 98d41c2 | 2007-10-02 21:55:37 -0400 | [diff] [blame] | 1902 | |
| 1903 | /* |
| 1904 | * Adapter operation variable structure. |
| 1905 | * |
| 1906 | * One structure is required per host adapter. |
| 1907 | * |
| 1908 | * Field naming convention: |
| 1909 | * |
| 1910 | * *_able indicates both whether a feature should be enabled or disabled |
| 1911 | * and whether a device isi capable of the feature. At initialization |
| 1912 | * this field may be set, but later if a device is found to be incapable |
| 1913 | * of the feature, the field is cleared. |
| 1914 | */ |
| 1915 | typedef struct adv_dvc_var { |
| 1916 | AdvPortAddr iop_base; /* I/O port address */ |
| 1917 | ushort err_code; /* fatal error code */ |
| 1918 | ushort bios_ctrl; /* BIOS control word, EEPROM word 12 */ |
| 1919 | ushort wdtr_able; /* try WDTR for a device */ |
| 1920 | ushort sdtr_able; /* try SDTR for a device */ |
| 1921 | ushort ultra_able; /* try SDTR Ultra speed for a device */ |
| 1922 | ushort sdtr_speed1; /* EEPROM SDTR Speed for TID 0-3 */ |
| 1923 | ushort sdtr_speed2; /* EEPROM SDTR Speed for TID 4-7 */ |
| 1924 | ushort sdtr_speed3; /* EEPROM SDTR Speed for TID 8-11 */ |
| 1925 | ushort sdtr_speed4; /* EEPROM SDTR Speed for TID 12-15 */ |
| 1926 | ushort tagqng_able; /* try tagged queuing with a device */ |
| 1927 | ushort ppr_able; /* PPR message capable per TID bitmask. */ |
| 1928 | uchar max_dvc_qng; /* maximum number of tagged commands per device */ |
| 1929 | ushort start_motor; /* start motor command allowed */ |
| 1930 | uchar scsi_reset_wait; /* delay in seconds after scsi bus reset */ |
| 1931 | uchar chip_no; /* should be assigned by caller */ |
| 1932 | uchar max_host_qng; /* maximum number of Q'ed command allowed */ |
| 1933 | ushort no_scam; /* scam_tolerant of EEPROM */ |
| 1934 | struct asc_board *drv_ptr; /* driver pointer to private structure */ |
| 1935 | uchar chip_scsi_id; /* chip SCSI target ID */ |
| 1936 | uchar chip_type; |
| 1937 | uchar bist_err_code; |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 1938 | ADV_CARR_T *carrier; |
Matthew Wilcox | 98d41c2 | 2007-10-02 21:55:37 -0400 | [diff] [blame] | 1939 | ADV_CARR_T *carr_freelist; /* Carrier free list. */ |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 1940 | dma_addr_t carrier_addr; |
Matthew Wilcox | 98d41c2 | 2007-10-02 21:55:37 -0400 | [diff] [blame] | 1941 | ADV_CARR_T *icq_sp; /* Initiator command queue stopper pointer. */ |
| 1942 | ADV_CARR_T *irq_sp; /* Initiator response queue stopper pointer. */ |
| 1943 | ushort carr_pending_cnt; /* Count of pending carriers. */ |
Matthew Wilcox | 98d41c2 | 2007-10-02 21:55:37 -0400 | [diff] [blame] | 1944 | /* |
| 1945 | * Note: The following fields will not be used after initialization. The |
| 1946 | * driver may discard the buffer after initialization is done. |
| 1947 | */ |
| 1948 | ADV_DVC_CFG *cfg; /* temporary configuration structure */ |
| 1949 | } ADV_DVC_VAR; |
| 1950 | |
| 1951 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | * Microcode idle loop commands |
| 1953 | */ |
| 1954 | #define IDLE_CMD_COMPLETED 0 |
| 1955 | #define IDLE_CMD_STOP_CHIP 0x0001 |
| 1956 | #define IDLE_CMD_STOP_CHIP_SEND_INT 0x0002 |
| 1957 | #define IDLE_CMD_SEND_INT 0x0004 |
| 1958 | #define IDLE_CMD_ABORT 0x0008 |
| 1959 | #define IDLE_CMD_DEVICE_RESET 0x0010 |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1960 | #define IDLE_CMD_SCSI_RESET_START 0x0020 /* Assert SCSI Bus Reset */ |
| 1961 | #define IDLE_CMD_SCSI_RESET_END 0x0040 /* Deassert SCSI Bus Reset */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | #define IDLE_CMD_SCSIREQ 0x0080 |
| 1963 | |
| 1964 | #define IDLE_CMD_STATUS_SUCCESS 0x0001 |
| 1965 | #define IDLE_CMD_STATUS_FAILURE 0x0002 |
| 1966 | |
| 1967 | /* |
| 1968 | * AdvSendIdleCmd() flag definitions. |
| 1969 | */ |
| 1970 | #define ADV_NOWAIT 0x01 |
| 1971 | |
| 1972 | /* |
| 1973 | * Wait loop time out values. |
| 1974 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1975 | #define SCSI_WAIT_100_MSEC 100UL /* 100 milliseconds */ |
| 1976 | #define SCSI_US_PER_MSEC 1000 /* microseconds per millisecond */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1977 | #define SCSI_MAX_RETRY 10 /* retry count */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1979 | #define ADV_ASYNC_RDMA_FAILURE 0x01 /* Fatal RDMA failure. */ |
| 1980 | #define ADV_ASYNC_SCSI_BUS_RESET_DET 0x02 /* Detected SCSI Bus Reset. */ |
| 1981 | #define ADV_ASYNC_CARRIER_READY_FAILURE 0x03 /* Carrier Ready failure. */ |
| 1982 | #define ADV_RDMA_IN_CARR_AND_Q_INVALID 0x04 /* RDMAed-in data invalid. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 1984 | #define ADV_HOST_SCSI_BUS_RESET 0x80 /* Host Initiated SCSI Bus Reset. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | /* Read byte from a register. */ |
| 1987 | #define AdvReadByteRegister(iop_base, reg_off) \ |
| 1988 | (ADV_MEM_READB((iop_base) + (reg_off))) |
| 1989 | |
| 1990 | /* Write byte to a register. */ |
| 1991 | #define AdvWriteByteRegister(iop_base, reg_off, byte) \ |
| 1992 | (ADV_MEM_WRITEB((iop_base) + (reg_off), (byte))) |
| 1993 | |
| 1994 | /* Read word (2 bytes) from a register. */ |
| 1995 | #define AdvReadWordRegister(iop_base, reg_off) \ |
| 1996 | (ADV_MEM_READW((iop_base) + (reg_off))) |
| 1997 | |
| 1998 | /* Write word (2 bytes) to a register. */ |
| 1999 | #define AdvWriteWordRegister(iop_base, reg_off, word) \ |
| 2000 | (ADV_MEM_WRITEW((iop_base) + (reg_off), (word))) |
| 2001 | |
| 2002 | /* Write dword (4 bytes) to a register. */ |
| 2003 | #define AdvWriteDWordRegister(iop_base, reg_off, dword) \ |
| 2004 | (ADV_MEM_WRITEDW((iop_base) + (reg_off), (dword))) |
| 2005 | |
| 2006 | /* Read byte from LRAM. */ |
| 2007 | #define AdvReadByteLram(iop_base, addr, byte) \ |
| 2008 | do { \ |
| 2009 | ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \ |
| 2010 | (byte) = ADV_MEM_READB((iop_base) + IOPB_RAM_DATA); \ |
| 2011 | } while (0) |
| 2012 | |
| 2013 | /* Write byte to LRAM. */ |
| 2014 | #define AdvWriteByteLram(iop_base, addr, byte) \ |
| 2015 | (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \ |
| 2016 | ADV_MEM_WRITEB((iop_base) + IOPB_RAM_DATA, (byte))) |
| 2017 | |
| 2018 | /* Read word (2 bytes) from LRAM. */ |
| 2019 | #define AdvReadWordLram(iop_base, addr, word) \ |
| 2020 | do { \ |
| 2021 | ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \ |
| 2022 | (word) = (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA)); \ |
| 2023 | } while (0) |
| 2024 | |
| 2025 | /* Write word (2 bytes) to LRAM. */ |
| 2026 | #define AdvWriteWordLram(iop_base, addr, word) \ |
| 2027 | (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \ |
| 2028 | ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word))) |
| 2029 | |
| 2030 | /* Write little-endian double word (4 bytes) to LRAM */ |
| 2031 | /* Because of unspecified C language ordering don't use auto-increment. */ |
| 2032 | #define AdvWriteDWordLramNoSwap(iop_base, addr, dword) \ |
| 2033 | ((ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \ |
| 2034 | ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \ |
| 2035 | cpu_to_le16((ushort) ((dword) & 0xFFFF)))), \ |
| 2036 | (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr) + 2), \ |
| 2037 | ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \ |
| 2038 | cpu_to_le16((ushort) ((dword >> 16) & 0xFFFF))))) |
| 2039 | |
| 2040 | /* Read word (2 bytes) from LRAM assuming that the address is already set. */ |
| 2041 | #define AdvReadWordAutoIncLram(iop_base) \ |
| 2042 | (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA)) |
| 2043 | |
| 2044 | /* Write word (2 bytes) to LRAM assuming that the address is already set. */ |
| 2045 | #define AdvWriteWordAutoIncLram(iop_base, word) \ |
| 2046 | (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word))) |
| 2047 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | /* |
| 2049 | * Define macro to check for Condor signature. |
| 2050 | * |
| 2051 | * Evaluate to ADV_TRUE if a Condor chip is found the specified port |
| 2052 | * address 'iop_base'. Otherwise evalue to ADV_FALSE. |
| 2053 | */ |
| 2054 | #define AdvFindSignature(iop_base) \ |
| 2055 | (((AdvReadByteRegister((iop_base), IOPB_CHIP_ID_1) == \ |
| 2056 | ADV_CHIP_ID_BYTE) && \ |
| 2057 | (AdvReadWordRegister((iop_base), IOPW_CHIP_ID_0) == \ |
| 2058 | ADV_CHIP_ID_WORD)) ? ADV_TRUE : ADV_FALSE) |
| 2059 | |
| 2060 | /* |
| 2061 | * Define macro to Return the version number of the chip at 'iop_base'. |
| 2062 | * |
| 2063 | * The second parameter 'bus_type' is currently unused. |
| 2064 | */ |
| 2065 | #define AdvGetChipVersion(iop_base, bus_type) \ |
| 2066 | AdvReadByteRegister((iop_base), IOPB_CHIP_TYPE_REV) |
| 2067 | |
| 2068 | /* |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 2069 | * Abort an SRB in the chip's RISC Memory. The 'srb_tag' argument must |
| 2070 | * match the ASC_SCSI_REQ_Q 'srb_tag' field. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | * |
| 2072 | * If the request has not yet been sent to the device it will simply be |
| 2073 | * aborted from RISC memory. If the request is disconnected it will be |
| 2074 | * aborted on reselection by sending an Abort Message to the target ID. |
| 2075 | * |
| 2076 | * Return value: |
| 2077 | * ADV_TRUE(1) - Queue was successfully aborted. |
| 2078 | * ADV_FALSE(0) - Queue was not found on the active queue list. |
| 2079 | */ |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 2080 | #define AdvAbortQueue(asc_dvc, srb_tag) \ |
| 2081 | AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_ABORT, \ |
| 2082 | (ADV_DCNT) (srb_tag)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | |
| 2084 | /* |
| 2085 | * Send a Bus Device Reset Message to the specified target ID. |
| 2086 | * |
| 2087 | * All outstanding commands will be purged if sending the |
| 2088 | * Bus Device Reset Message is successful. |
| 2089 | * |
| 2090 | * Return Value: |
| 2091 | * ADV_TRUE(1) - All requests on the target are purged. |
| 2092 | * ADV_FALSE(0) - Couldn't issue Bus Device Reset Message; Requests |
| 2093 | * are not purged. |
| 2094 | */ |
| 2095 | #define AdvResetDevice(asc_dvc, target_id) \ |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 2096 | AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_DEVICE_RESET, \ |
| 2097 | (ADV_DCNT) (target_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2098 | |
| 2099 | /* |
| 2100 | * SCSI Wide Type definition. |
| 2101 | */ |
| 2102 | #define ADV_SCSI_BIT_ID_TYPE ushort |
| 2103 | |
| 2104 | /* |
| 2105 | * AdvInitScsiTarget() 'cntl_flag' options. |
| 2106 | */ |
| 2107 | #define ADV_SCAN_LUN 0x01 |
| 2108 | #define ADV_CAPINFO_NOLUN 0x02 |
| 2109 | |
| 2110 | /* |
| 2111 | * Convert target id to target id bit mask. |
| 2112 | */ |
| 2113 | #define ADV_TID_TO_TIDMASK(tid) (0x01 << ((tid) & ADV_MAX_TID)) |
| 2114 | |
| 2115 | /* |
| 2116 | * ASC_SCSI_REQ_Q 'done_status' and 'host_status' return values. |
| 2117 | */ |
| 2118 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2119 | #define QD_NO_STATUS 0x00 /* Request not completed yet. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | #define QD_NO_ERROR 0x01 |
| 2121 | #define QD_ABORTED_BY_HOST 0x02 |
| 2122 | #define QD_WITH_ERROR 0x04 |
| 2123 | |
| 2124 | #define QHSTA_NO_ERROR 0x00 |
| 2125 | #define QHSTA_M_SEL_TIMEOUT 0x11 |
| 2126 | #define QHSTA_M_DATA_OVER_RUN 0x12 |
| 2127 | #define QHSTA_M_UNEXPECTED_BUS_FREE 0x13 |
| 2128 | #define QHSTA_M_QUEUE_ABORTED 0x15 |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2129 | #define QHSTA_M_SXFR_SDMA_ERR 0x16 /* SXFR_STATUS SCSI DMA Error */ |
| 2130 | #define QHSTA_M_SXFR_SXFR_PERR 0x17 /* SXFR_STATUS SCSI Bus Parity Error */ |
| 2131 | #define QHSTA_M_RDMA_PERR 0x18 /* RISC PCI DMA parity error */ |
| 2132 | #define QHSTA_M_SXFR_OFF_UFLW 0x19 /* SXFR_STATUS Offset Underflow */ |
| 2133 | #define QHSTA_M_SXFR_OFF_OFLW 0x20 /* SXFR_STATUS Offset Overflow */ |
| 2134 | #define QHSTA_M_SXFR_WD_TMO 0x21 /* SXFR_STATUS Watchdog Timeout */ |
| 2135 | #define QHSTA_M_SXFR_DESELECTED 0x22 /* SXFR_STATUS Deselected */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | /* Note: QHSTA_M_SXFR_XFR_OFLW is identical to QHSTA_M_DATA_OVER_RUN. */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2137 | #define QHSTA_M_SXFR_XFR_OFLW 0x12 /* SXFR_STATUS Transfer Overflow */ |
| 2138 | #define QHSTA_M_SXFR_XFR_PH_ERR 0x24 /* SXFR_STATUS Transfer Phase Error */ |
| 2139 | #define QHSTA_M_SXFR_UNKNOWN_ERROR 0x25 /* SXFR_STATUS Unknown Error */ |
| 2140 | #define QHSTA_M_SCSI_BUS_RESET 0x30 /* Request aborted from SBR */ |
| 2141 | #define QHSTA_M_SCSI_BUS_RESET_UNSOL 0x31 /* Request aborted from unsol. SBR */ |
| 2142 | #define QHSTA_M_BUS_DEVICE_RESET 0x32 /* Request aborted from BDR */ |
| 2143 | #define QHSTA_M_DIRECTION_ERR 0x35 /* Data Phase mismatch */ |
| 2144 | #define QHSTA_M_DIRECTION_ERR_HUNG 0x36 /* Data Phase mismatch and bus hang */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2145 | #define QHSTA_M_WTM_TIMEOUT 0x41 |
| 2146 | #define QHSTA_M_BAD_CMPL_STATUS_IN 0x42 |
| 2147 | #define QHSTA_M_NO_AUTO_REQ_SENSE 0x43 |
| 2148 | #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44 |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2149 | #define QHSTA_M_INVALID_DEVICE 0x45 /* Bad target ID */ |
| 2150 | #define QHSTA_M_FROZEN_TIDQ 0x46 /* TID Queue frozen. */ |
| 2151 | #define QHSTA_M_SGBACKUP_ERROR 0x47 /* Scatter-Gather backup error */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | /* Return the address that is aligned at the next doubleword >= to 'addr'. */ |
| 2154 | #define ADV_8BALIGN(addr) (((ulong) (addr) + 0x7) & ~0x7) |
| 2155 | #define ADV_16BALIGN(addr) (((ulong) (addr) + 0xF) & ~0xF) |
| 2156 | #define ADV_32BALIGN(addr) (((ulong) (addr) + 0x1F) & ~0x1F) |
| 2157 | |
| 2158 | /* |
| 2159 | * Total contiguous memory needed for driver SG blocks. |
| 2160 | * |
| 2161 | * ADV_MAX_SG_LIST must be defined by a driver. It is the maximum |
| 2162 | * number of scatter-gather elements the driver supports in a |
| 2163 | * single request. |
| 2164 | */ |
| 2165 | |
| 2166 | #define ADV_SG_LIST_MAX_BYTE_SIZE \ |
| 2167 | (sizeof(ADV_SG_BLOCK) * \ |
| 2168 | ((ADV_MAX_SG_LIST + (NO_OF_SG_PER_BLOCK - 1))/NO_OF_SG_PER_BLOCK)) |
| 2169 | |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 2170 | /* struct asc_board flags */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2171 | #define ASC_IS_WIDE_BOARD 0x04 /* AdvanSys Wide Board */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | |
| 2173 | #define ASC_NARROW_BOARD(boardp) (((boardp)->flags & ASC_IS_WIDE_BOARD) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2175 | #define NO_ISA_DMA 0xff /* No ISA DMA Channel Used */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2177 | #define ASC_INFO_SIZE 128 /* advansys_info() line size */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | /* Asc Library return codes */ |
| 2180 | #define ASC_TRUE 1 |
| 2181 | #define ASC_FALSE 0 |
| 2182 | #define ASC_NOERROR 1 |
| 2183 | #define ASC_BUSY 0 |
| 2184 | #define ASC_ERROR (-1) |
| 2185 | |
| 2186 | /* struct scsi_cmnd function return codes */ |
| 2187 | #define STATUS_BYTE(byte) (byte) |
| 2188 | #define MSG_BYTE(byte) ((byte) << 8) |
| 2189 | #define HOST_BYTE(byte) ((byte) << 16) |
| 2190 | #define DRIVER_BYTE(byte) ((byte) << 24) |
| 2191 | |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 2192 | #define ASC_STATS(shost, counter) ASC_STATS_ADD(shost, counter, 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | #ifndef ADVANSYS_STATS |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2194 | #define ASC_STATS_ADD(shost, counter, count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | #else /* ADVANSYS_STATS */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2196 | #define ASC_STATS_ADD(shost, counter, count) \ |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 2197 | (((struct asc_board *) shost_priv(shost))->asc_stats.counter += (count)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | #endif /* ADVANSYS_STATS */ |
| 2199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | /* If the result wraps when calculating tenths, return 0. */ |
| 2201 | #define ASC_TENTHS(num, den) \ |
| 2202 | (((10 * ((num)/(den))) > (((num) * 10)/(den))) ? \ |
| 2203 | 0 : ((((num) * 10)/(den)) - (10 * ((num)/(den))))) |
| 2204 | |
| 2205 | /* |
| 2206 | * Display a message to the console. |
| 2207 | */ |
| 2208 | #define ASC_PRINT(s) \ |
| 2209 | { \ |
| 2210 | printk("advansys: "); \ |
| 2211 | printk(s); \ |
| 2212 | } |
| 2213 | |
| 2214 | #define ASC_PRINT1(s, a1) \ |
| 2215 | { \ |
| 2216 | printk("advansys: "); \ |
| 2217 | printk((s), (a1)); \ |
| 2218 | } |
| 2219 | |
| 2220 | #define ASC_PRINT2(s, a1, a2) \ |
| 2221 | { \ |
| 2222 | printk("advansys: "); \ |
| 2223 | printk((s), (a1), (a2)); \ |
| 2224 | } |
| 2225 | |
| 2226 | #define ASC_PRINT3(s, a1, a2, a3) \ |
| 2227 | { \ |
| 2228 | printk("advansys: "); \ |
| 2229 | printk((s), (a1), (a2), (a3)); \ |
| 2230 | } |
| 2231 | |
| 2232 | #define ASC_PRINT4(s, a1, a2, a3, a4) \ |
| 2233 | { \ |
| 2234 | printk("advansys: "); \ |
| 2235 | printk((s), (a1), (a2), (a3), (a4)); \ |
| 2236 | } |
| 2237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | #ifndef ADVANSYS_DEBUG |
| 2239 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2240 | #define ASC_DBG(lvl, s...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2241 | #define ASC_DBG_PRT_SCSI_HOST(lvl, s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp) |
| 2243 | #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp) |
| 2244 | #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone) |
| 2245 | #define ADV_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp) |
| 2246 | #define ASC_DBG_PRT_HEX(lvl, name, start, length) |
| 2247 | #define ASC_DBG_PRT_CDB(lvl, cdb, len) |
| 2248 | #define ASC_DBG_PRT_SENSE(lvl, sense, len) |
| 2249 | #define ASC_DBG_PRT_INQUIRY(lvl, inq, len) |
| 2250 | |
| 2251 | #else /* ADVANSYS_DEBUG */ |
| 2252 | |
| 2253 | /* |
| 2254 | * Debugging Message Levels: |
| 2255 | * 0: Errors Only |
| 2256 | * 1: High-Level Tracing |
| 2257 | * 2-N: Verbose Tracing |
| 2258 | */ |
| 2259 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2260 | #define ASC_DBG(lvl, format, arg...) { \ |
| 2261 | if (asc_dbglvl >= (lvl)) \ |
| 2262 | printk(KERN_DEBUG "%s: %s: " format, DRV_NAME, \ |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2263 | __func__ , ## arg); \ |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2264 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | |
| 2266 | #define ASC_DBG_PRT_SCSI_HOST(lvl, s) \ |
| 2267 | { \ |
| 2268 | if (asc_dbglvl >= (lvl)) { \ |
| 2269 | asc_prt_scsi_host(s); \ |
| 2270 | } \ |
| 2271 | } |
| 2272 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp) \ |
| 2274 | { \ |
| 2275 | if (asc_dbglvl >= (lvl)) { \ |
| 2276 | asc_prt_asc_scsi_q(scsiqp); \ |
| 2277 | } \ |
| 2278 | } |
| 2279 | |
| 2280 | #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone) \ |
| 2281 | { \ |
| 2282 | if (asc_dbglvl >= (lvl)) { \ |
| 2283 | asc_prt_asc_qdone_info(qdone); \ |
| 2284 | } \ |
| 2285 | } |
| 2286 | |
| 2287 | #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp) \ |
| 2288 | { \ |
| 2289 | if (asc_dbglvl >= (lvl)) { \ |
| 2290 | asc_prt_adv_scsi_req_q(scsiqp); \ |
| 2291 | } \ |
| 2292 | } |
| 2293 | |
| 2294 | #define ASC_DBG_PRT_HEX(lvl, name, start, length) \ |
| 2295 | { \ |
| 2296 | if (asc_dbglvl >= (lvl)) { \ |
| 2297 | asc_prt_hex((name), (start), (length)); \ |
| 2298 | } \ |
| 2299 | } |
| 2300 | |
| 2301 | #define ASC_DBG_PRT_CDB(lvl, cdb, len) \ |
| 2302 | ASC_DBG_PRT_HEX((lvl), "CDB", (uchar *) (cdb), (len)); |
| 2303 | |
| 2304 | #define ASC_DBG_PRT_SENSE(lvl, sense, len) \ |
| 2305 | ASC_DBG_PRT_HEX((lvl), "SENSE", (uchar *) (sense), (len)); |
| 2306 | |
| 2307 | #define ASC_DBG_PRT_INQUIRY(lvl, inq, len) \ |
| 2308 | ASC_DBG_PRT_HEX((lvl), "INQUIRY", (uchar *) (inq), (len)); |
| 2309 | #endif /* ADVANSYS_DEBUG */ |
| 2310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | #ifdef ADVANSYS_STATS |
| 2312 | |
| 2313 | /* Per board statistics structure */ |
| 2314 | struct asc_stats { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2315 | /* Driver Entrypoint Statistics */ |
| 2316 | ADV_DCNT queuecommand; /* # calls to advansys_queuecommand() */ |
| 2317 | ADV_DCNT reset; /* # calls to advansys_eh_bus_reset() */ |
| 2318 | ADV_DCNT biosparam; /* # calls to advansys_biosparam() */ |
| 2319 | ADV_DCNT interrupt; /* # advansys_interrupt() calls */ |
| 2320 | ADV_DCNT callback; /* # calls to asc/adv_isr_callback() */ |
| 2321 | ADV_DCNT done; /* # calls to request's scsi_done function */ |
| 2322 | ADV_DCNT build_error; /* # asc/adv_build_req() ASC_ERROR returns. */ |
| 2323 | ADV_DCNT adv_build_noreq; /* # adv_build_req() adv_req_t alloc. fail. */ |
| 2324 | ADV_DCNT adv_build_nosg; /* # adv_build_req() adv_sgblk_t alloc. fail. */ |
| 2325 | /* AscExeScsiQueue()/AdvExeScsiQueue() Statistics */ |
| 2326 | ADV_DCNT exe_noerror; /* # ASC_NOERROR returns. */ |
| 2327 | ADV_DCNT exe_busy; /* # ASC_BUSY returns. */ |
| 2328 | ADV_DCNT exe_error; /* # ASC_ERROR returns. */ |
| 2329 | ADV_DCNT exe_unknown; /* # unknown returns. */ |
| 2330 | /* Data Transfer Statistics */ |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 2331 | ADV_DCNT xfer_cnt; /* # I/O requests received */ |
| 2332 | ADV_DCNT xfer_elem; /* # scatter-gather elements */ |
| 2333 | ADV_DCNT xfer_sect; /* # 512-byte blocks */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | }; |
| 2335 | #endif /* ADVANSYS_STATS */ |
| 2336 | |
| 2337 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | * Structure allocated for each board. |
| 2339 | * |
Matthew Wilcox | 8dfb537 | 2007-07-30 09:08:34 -0600 | [diff] [blame] | 2340 | * This structure is allocated by scsi_host_alloc() at the end |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2341 | * of the 'Scsi_Host' structure starting at the 'hostdata' |
| 2342 | * field. It is guaranteed to be allocated from DMA-able memory. |
| 2343 | */ |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 2344 | struct asc_board { |
Matthew Wilcox | 394dbf3 | 2007-07-26 11:56:40 -0400 | [diff] [blame] | 2345 | struct device *dev; |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 2346 | struct Scsi_Host *shost; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2347 | uint flags; /* Board flags */ |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 2348 | unsigned int irq; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2349 | union { |
| 2350 | ASC_DVC_VAR asc_dvc_var; /* Narrow board */ |
| 2351 | ADV_DVC_VAR adv_dvc_var; /* Wide board */ |
| 2352 | } dvc_var; |
| 2353 | union { |
| 2354 | ASC_DVC_CFG asc_dvc_cfg; /* Narrow board */ |
| 2355 | ADV_DVC_CFG adv_dvc_cfg; /* Wide board */ |
| 2356 | } dvc_cfg; |
| 2357 | ushort asc_n_io_port; /* Number I/O ports. */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2358 | ADV_SCSI_BIT_ID_TYPE init_tidmask; /* Target init./valid mask */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2359 | ushort reqcnt[ADV_MAX_TID + 1]; /* Starvation request count */ |
| 2360 | ADV_SCSI_BIT_ID_TYPE queue_full; /* Queue full mask */ |
| 2361 | ushort queue_full_cnt[ADV_MAX_TID + 1]; /* Queue full count */ |
| 2362 | union { |
| 2363 | ASCEEP_CONFIG asc_eep; /* Narrow EEPROM config. */ |
| 2364 | ADVEEP_3550_CONFIG adv_3550_eep; /* 3550 EEPROM config. */ |
| 2365 | ADVEEP_38C0800_CONFIG adv_38C0800_eep; /* 38C0800 EEPROM config. */ |
| 2366 | ADVEEP_38C1600_CONFIG adv_38C1600_eep; /* 38C1600 EEPROM config. */ |
| 2367 | } eep_config; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2368 | /* /proc/scsi/advansys/[0...] */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | #ifdef ADVANSYS_STATS |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2370 | struct asc_stats asc_stats; /* Board statistics */ |
| 2371 | #endif /* ADVANSYS_STATS */ |
| 2372 | /* |
| 2373 | * The following fields are used only for Narrow Boards. |
| 2374 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2375 | uchar sdtr_data[ASC_MAX_TID + 1]; /* SDTR information */ |
| 2376 | /* |
| 2377 | * The following fields are used only for Wide Boards. |
| 2378 | */ |
| 2379 | void __iomem *ioremap_addr; /* I/O Memory remap address. */ |
| 2380 | ushort ioport; /* I/O Port address. */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2381 | adv_req_t *adv_reqp; /* Request structures. */ |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 2382 | dma_addr_t adv_reqp_addr; |
| 2383 | size_t adv_reqp_size; |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 2384 | struct dma_pool *adv_sgblk_pool; /* Scatter-gather structures. */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2385 | ushort bios_signature; /* BIOS Signature. */ |
| 2386 | ushort bios_version; /* BIOS Version. */ |
| 2387 | ushort bios_codeseg; /* BIOS Code Segment. */ |
| 2388 | ushort bios_codelen; /* BIOS Code Segment Length. */ |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 2389 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | |
Matthew Wilcox | d10fb2c | 2007-10-02 21:55:41 -0400 | [diff] [blame] | 2391 | #define asc_dvc_to_board(asc_dvc) container_of(asc_dvc, struct asc_board, \ |
| 2392 | dvc_var.asc_dvc_var) |
Matthew Wilcox | 13ac2d9 | 2007-07-30 08:10:23 -0600 | [diff] [blame] | 2393 | #define adv_dvc_to_board(adv_dvc) container_of(adv_dvc, struct asc_board, \ |
| 2394 | dvc_var.adv_dvc_var) |
| 2395 | #define adv_dvc_to_pdev(adv_dvc) to_pci_dev(adv_dvc_to_board(adv_dvc)->dev) |
| 2396 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | #ifdef ADVANSYS_DEBUG |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2398 | static int asc_dbglvl = 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2400 | /* |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 2401 | * asc_prt_asc_dvc_var() |
| 2402 | */ |
| 2403 | static void asc_prt_asc_dvc_var(ASC_DVC_VAR *h) |
| 2404 | { |
| 2405 | printk("ASC_DVC_VAR at addr 0x%lx\n", (ulong)h); |
| 2406 | |
| 2407 | printk(" iop_base 0x%x, err_code 0x%x, dvc_cntl 0x%x, bug_fix_cntl " |
| 2408 | "%d,\n", h->iop_base, h->err_code, h->dvc_cntl, h->bug_fix_cntl); |
| 2409 | |
| 2410 | printk(" bus_type %d, init_sdtr 0x%x,\n", h->bus_type, |
| 2411 | (unsigned)h->init_sdtr); |
| 2412 | |
| 2413 | printk(" sdtr_done 0x%x, use_tagged_qng 0x%x, unit_not_ready 0x%x, " |
| 2414 | "chip_no 0x%x,\n", (unsigned)h->sdtr_done, |
| 2415 | (unsigned)h->use_tagged_qng, (unsigned)h->unit_not_ready, |
| 2416 | (unsigned)h->chip_no); |
| 2417 | |
| 2418 | printk(" queue_full_or_busy 0x%x, start_motor 0x%x, scsi_reset_wait " |
| 2419 | "%u,\n", (unsigned)h->queue_full_or_busy, |
| 2420 | (unsigned)h->start_motor, (unsigned)h->scsi_reset_wait); |
| 2421 | |
| 2422 | printk(" is_in_int %u, max_total_qng %u, cur_total_qng %u, " |
| 2423 | "in_critical_cnt %u,\n", (unsigned)h->is_in_int, |
| 2424 | (unsigned)h->max_total_qng, (unsigned)h->cur_total_qng, |
| 2425 | (unsigned)h->in_critical_cnt); |
| 2426 | |
| 2427 | printk(" last_q_shortage %u, init_state 0x%x, no_scam 0x%x, " |
| 2428 | "pci_fix_asyn_xfer 0x%x,\n", (unsigned)h->last_q_shortage, |
| 2429 | (unsigned)h->init_state, (unsigned)h->no_scam, |
| 2430 | (unsigned)h->pci_fix_asyn_xfer); |
| 2431 | |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 2432 | printk(" cfg 0x%lx\n", (ulong)h->cfg); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 2433 | } |
| 2434 | |
| 2435 | /* |
| 2436 | * asc_prt_asc_dvc_cfg() |
| 2437 | */ |
| 2438 | static void asc_prt_asc_dvc_cfg(ASC_DVC_CFG *h) |
| 2439 | { |
| 2440 | printk("ASC_DVC_CFG at addr 0x%lx\n", (ulong)h); |
| 2441 | |
| 2442 | printk(" can_tagged_qng 0x%x, cmd_qng_enabled 0x%x,\n", |
| 2443 | h->can_tagged_qng, h->cmd_qng_enabled); |
| 2444 | printk(" disc_enable 0x%x, sdtr_enable 0x%x,\n", |
| 2445 | h->disc_enable, h->sdtr_enable); |
| 2446 | |
Matthew Wilcox | b08fc56 | 2007-10-02 21:55:32 -0400 | [diff] [blame] | 2447 | printk(" chip_scsi_id %d, isa_dma_speed %d, isa_dma_channel %d, " |
| 2448 | "chip_version %d,\n", h->chip_scsi_id, h->isa_dma_speed, |
| 2449 | h->isa_dma_channel, h->chip_version); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 2450 | |
Matthew Wilcox | d10fb2c | 2007-10-02 21:55:41 -0400 | [diff] [blame] | 2451 | printk(" mcode_date 0x%x, mcode_version %d\n", |
| 2452 | h->mcode_date, h->mcode_version); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 2453 | } |
| 2454 | |
| 2455 | /* |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 2456 | * asc_prt_adv_dvc_var() |
| 2457 | * |
| 2458 | * Display an ADV_DVC_VAR structure. |
| 2459 | */ |
| 2460 | static void asc_prt_adv_dvc_var(ADV_DVC_VAR *h) |
| 2461 | { |
| 2462 | printk(" ADV_DVC_VAR at addr 0x%lx\n", (ulong)h); |
| 2463 | |
| 2464 | printk(" iop_base 0x%lx, err_code 0x%x, ultra_able 0x%x\n", |
| 2465 | (ulong)h->iop_base, h->err_code, (unsigned)h->ultra_able); |
| 2466 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2467 | printk(" sdtr_able 0x%x, wdtr_able 0x%x\n", |
| 2468 | (unsigned)h->sdtr_able, (unsigned)h->wdtr_able); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 2469 | |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 2470 | printk(" start_motor 0x%x, scsi_reset_wait 0x%x\n", |
| 2471 | (unsigned)h->start_motor, (unsigned)h->scsi_reset_wait); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 2472 | |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 2473 | printk(" max_host_qng %u, max_dvc_qng %u, carr_freelist 0x%p\n", |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 2474 | (unsigned)h->max_host_qng, (unsigned)h->max_dvc_qng, |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 2475 | h->carr_freelist); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 2476 | |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 2477 | printk(" icq_sp 0x%p, irq_sp 0x%p\n", h->icq_sp, h->irq_sp); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 2478 | |
| 2479 | printk(" no_scam 0x%x, tagqng_able 0x%x\n", |
| 2480 | (unsigned)h->no_scam, (unsigned)h->tagqng_able); |
| 2481 | |
| 2482 | printk(" chip_scsi_id 0x%x, cfg 0x%lx\n", |
| 2483 | (unsigned)h->chip_scsi_id, (ulong)h->cfg); |
| 2484 | } |
| 2485 | |
| 2486 | /* |
| 2487 | * asc_prt_adv_dvc_cfg() |
| 2488 | * |
| 2489 | * Display an ADV_DVC_CFG structure. |
| 2490 | */ |
| 2491 | static void asc_prt_adv_dvc_cfg(ADV_DVC_CFG *h) |
| 2492 | { |
| 2493 | printk(" ADV_DVC_CFG at addr 0x%lx\n", (ulong)h); |
| 2494 | |
| 2495 | printk(" disc_enable 0x%x, termination 0x%x\n", |
| 2496 | h->disc_enable, h->termination); |
| 2497 | |
| 2498 | printk(" chip_version 0x%x, mcode_date 0x%x\n", |
| 2499 | h->chip_version, h->mcode_date); |
| 2500 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2501 | printk(" mcode_version 0x%x, control_flag 0x%x\n", |
| 2502 | h->mcode_version, h->control_flag); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 2503 | } |
| 2504 | |
| 2505 | /* |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2506 | * asc_prt_scsi_host() |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 2507 | */ |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2508 | static void asc_prt_scsi_host(struct Scsi_Host *s) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 2509 | { |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2510 | struct asc_board *boardp = shost_priv(s); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 2511 | |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 2512 | printk("Scsi_Host at addr 0x%p, device %s\n", s, dev_name(boardp->dev)); |
Hannes Reinecke | 50d14a7 | 2013-10-23 10:51:17 +0200 | [diff] [blame] | 2513 | printk(" host_busy %u, host_no %d,\n", |
Christoph Hellwig | 7466501 | 2014-01-22 15:29:29 +0100 | [diff] [blame] | 2514 | atomic_read(&s->host_busy), s->host_no); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 2515 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2516 | printk(" base 0x%lx, io_port 0x%lx, irq %d,\n", |
| 2517 | (ulong)s->base, (ulong)s->io_port, boardp->irq); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 2518 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2519 | printk(" dma_channel %d, this_id %d, can_queue %d,\n", |
| 2520 | s->dma_channel, s->this_id, s->can_queue); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 2521 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2522 | printk(" cmd_per_lun %d, sg_tablesize %d, unchecked_isa_dma %d\n", |
| 2523 | s->cmd_per_lun, s->sg_tablesize, s->unchecked_isa_dma); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 2524 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2525 | if (ASC_NARROW_BOARD(boardp)) { |
| 2526 | asc_prt_asc_dvc_var(&boardp->dvc_var.asc_dvc_var); |
| 2527 | asc_prt_asc_dvc_cfg(&boardp->dvc_cfg.asc_dvc_cfg); |
| 2528 | } else { |
| 2529 | asc_prt_adv_dvc_var(&boardp->dvc_var.adv_dvc_var); |
| 2530 | asc_prt_adv_dvc_cfg(&boardp->dvc_cfg.adv_dvc_cfg); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 2531 | } |
| 2532 | } |
| 2533 | |
| 2534 | /* |
| 2535 | * asc_prt_hex() |
| 2536 | * |
| 2537 | * Print hexadecimal output in 4 byte groupings 32 bytes |
| 2538 | * or 8 double-words per line. |
| 2539 | */ |
| 2540 | static void asc_prt_hex(char *f, uchar *s, int l) |
| 2541 | { |
| 2542 | int i; |
| 2543 | int j; |
| 2544 | int k; |
| 2545 | int m; |
| 2546 | |
| 2547 | printk("%s: (%d bytes)\n", f, l); |
| 2548 | |
| 2549 | for (i = 0; i < l; i += 32) { |
| 2550 | |
| 2551 | /* Display a maximum of 8 double-words per line. */ |
| 2552 | if ((k = (l - i) / 4) >= 8) { |
| 2553 | k = 8; |
| 2554 | m = 0; |
| 2555 | } else { |
| 2556 | m = (l - i) % 4; |
| 2557 | } |
| 2558 | |
| 2559 | for (j = 0; j < k; j++) { |
| 2560 | printk(" %2.2X%2.2X%2.2X%2.2X", |
| 2561 | (unsigned)s[i + (j * 4)], |
| 2562 | (unsigned)s[i + (j * 4) + 1], |
| 2563 | (unsigned)s[i + (j * 4) + 2], |
| 2564 | (unsigned)s[i + (j * 4) + 3]); |
| 2565 | } |
| 2566 | |
| 2567 | switch (m) { |
| 2568 | case 0: |
| 2569 | default: |
| 2570 | break; |
| 2571 | case 1: |
| 2572 | printk(" %2.2X", (unsigned)s[i + (j * 4)]); |
| 2573 | break; |
| 2574 | case 2: |
| 2575 | printk(" %2.2X%2.2X", |
| 2576 | (unsigned)s[i + (j * 4)], |
| 2577 | (unsigned)s[i + (j * 4) + 1]); |
| 2578 | break; |
| 2579 | case 3: |
| 2580 | printk(" %2.2X%2.2X%2.2X", |
| 2581 | (unsigned)s[i + (j * 4) + 1], |
| 2582 | (unsigned)s[i + (j * 4) + 2], |
| 2583 | (unsigned)s[i + (j * 4) + 3]); |
| 2584 | break; |
| 2585 | } |
| 2586 | |
| 2587 | printk("\n"); |
| 2588 | } |
| 2589 | } |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2590 | |
| 2591 | /* |
| 2592 | * asc_prt_asc_scsi_q() |
| 2593 | */ |
| 2594 | static void asc_prt_asc_scsi_q(ASC_SCSI_Q *q) |
| 2595 | { |
| 2596 | ASC_SG_HEAD *sgp; |
| 2597 | int i; |
| 2598 | |
| 2599 | printk("ASC_SCSI_Q at addr 0x%lx\n", (ulong)q); |
| 2600 | |
| 2601 | printk |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 2602 | (" target_ix 0x%x, target_lun %u, srb_tag 0x%x, tag_code 0x%x,\n", |
| 2603 | q->q2.target_ix, q->q1.target_lun, q->q2.srb_tag, |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2604 | q->q2.tag_code); |
| 2605 | |
| 2606 | printk |
| 2607 | (" data_addr 0x%lx, data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n", |
| 2608 | (ulong)le32_to_cpu(q->q1.data_addr), |
| 2609 | (ulong)le32_to_cpu(q->q1.data_cnt), |
| 2610 | (ulong)le32_to_cpu(q->q1.sense_addr), q->q1.sense_len); |
| 2611 | |
| 2612 | printk(" cdbptr 0x%lx, cdb_len %u, sg_head 0x%lx, sg_queue_cnt %u\n", |
| 2613 | (ulong)q->cdbptr, q->q2.cdb_len, |
| 2614 | (ulong)q->sg_head, q->q1.sg_queue_cnt); |
| 2615 | |
| 2616 | if (q->sg_head) { |
| 2617 | sgp = q->sg_head; |
| 2618 | printk("ASC_SG_HEAD at addr 0x%lx\n", (ulong)sgp); |
| 2619 | printk(" entry_cnt %u, queue_cnt %u\n", sgp->entry_cnt, |
| 2620 | sgp->queue_cnt); |
| 2621 | for (i = 0; i < sgp->entry_cnt; i++) { |
| 2622 | printk(" [%u]: addr 0x%lx, bytes %lu\n", |
| 2623 | i, (ulong)le32_to_cpu(sgp->sg_list[i].addr), |
| 2624 | (ulong)le32_to_cpu(sgp->sg_list[i].bytes)); |
| 2625 | } |
| 2626 | |
| 2627 | } |
| 2628 | } |
| 2629 | |
| 2630 | /* |
| 2631 | * asc_prt_asc_qdone_info() |
| 2632 | */ |
| 2633 | static void asc_prt_asc_qdone_info(ASC_QDONE_INFO *q) |
| 2634 | { |
| 2635 | printk("ASC_QDONE_INFO at addr 0x%lx\n", (ulong)q); |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 2636 | printk(" srb_tag 0x%x, target_ix %u, cdb_len %u, tag_code %u,\n", |
| 2637 | q->d2.srb_tag, q->d2.target_ix, q->d2.cdb_len, |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2638 | q->d2.tag_code); |
| 2639 | printk |
| 2640 | (" done_stat 0x%x, host_stat 0x%x, scsi_stat 0x%x, scsi_msg 0x%x\n", |
| 2641 | q->d3.done_stat, q->d3.host_stat, q->d3.scsi_stat, q->d3.scsi_msg); |
| 2642 | } |
| 2643 | |
| 2644 | /* |
| 2645 | * asc_prt_adv_sgblock() |
| 2646 | * |
| 2647 | * Display an ADV_SG_BLOCK structure. |
| 2648 | */ |
| 2649 | static void asc_prt_adv_sgblock(int sgblockno, ADV_SG_BLOCK *b) |
| 2650 | { |
| 2651 | int i; |
| 2652 | |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 2653 | printk(" ADV_SG_BLOCK at addr 0x%lx (sgblockno %d)\n", |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2654 | (ulong)b, sgblockno); |
| 2655 | printk(" sg_cnt %u, sg_ptr 0x%lx\n", |
| 2656 | b->sg_cnt, (ulong)le32_to_cpu(b->sg_ptr)); |
| 2657 | BUG_ON(b->sg_cnt > NO_OF_SG_PER_BLOCK); |
| 2658 | if (b->sg_ptr != 0) |
| 2659 | BUG_ON(b->sg_cnt != NO_OF_SG_PER_BLOCK); |
| 2660 | for (i = 0; i < b->sg_cnt; i++) { |
| 2661 | printk(" [%u]: sg_addr 0x%lx, sg_count 0x%lx\n", |
| 2662 | i, (ulong)b->sg_list[i].sg_addr, |
| 2663 | (ulong)b->sg_list[i].sg_count); |
| 2664 | } |
| 2665 | } |
| 2666 | |
| 2667 | /* |
| 2668 | * asc_prt_adv_scsi_req_q() |
| 2669 | * |
| 2670 | * Display an ADV_SCSI_REQ_Q structure. |
| 2671 | */ |
| 2672 | static void asc_prt_adv_scsi_req_q(ADV_SCSI_REQ_Q *q) |
| 2673 | { |
| 2674 | int sg_blk_cnt; |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 2675 | struct adv_sg_block *sg_ptr; |
| 2676 | adv_sgblk_t *sgblkp; |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2677 | |
| 2678 | printk("ADV_SCSI_REQ_Q at addr 0x%lx\n", (ulong)q); |
| 2679 | |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 2680 | printk(" target_id %u, target_lun %u, srb_tag 0x%x, a_flag 0x%x\n", |
| 2681 | q->target_id, q->target_lun, q->srb_tag, q->a_flag); |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2682 | |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 2683 | printk(" cntl 0x%x, data_addr 0x%lx\n", |
| 2684 | q->cntl, (ulong)le32_to_cpu(q->data_addr)); |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2685 | |
| 2686 | printk(" data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n", |
| 2687 | (ulong)le32_to_cpu(q->data_cnt), |
| 2688 | (ulong)le32_to_cpu(q->sense_addr), q->sense_len); |
| 2689 | |
| 2690 | printk |
| 2691 | (" cdb_len %u, done_status 0x%x, host_status 0x%x, scsi_status 0x%x\n", |
| 2692 | q->cdb_len, q->done_status, q->host_status, q->scsi_status); |
| 2693 | |
| 2694 | printk(" sg_working_ix 0x%x, target_cmd %u\n", |
| 2695 | q->sg_working_ix, q->target_cmd); |
| 2696 | |
| 2697 | printk(" scsiq_rptr 0x%lx, sg_real_addr 0x%lx, sg_list_ptr 0x%lx\n", |
| 2698 | (ulong)le32_to_cpu(q->scsiq_rptr), |
| 2699 | (ulong)le32_to_cpu(q->sg_real_addr), (ulong)q->sg_list_ptr); |
| 2700 | |
| 2701 | /* Display the request's ADV_SG_BLOCK structures. */ |
| 2702 | if (q->sg_list_ptr != NULL) { |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 2703 | sgblkp = container_of(q->sg_list_ptr, adv_sgblk_t, sg_block); |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2704 | sg_blk_cnt = 0; |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 2705 | while (sgblkp) { |
| 2706 | sg_ptr = &sgblkp->sg_block; |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2707 | asc_prt_adv_sgblock(sg_blk_cnt, sg_ptr); |
| 2708 | if (sg_ptr->sg_ptr == 0) { |
| 2709 | break; |
| 2710 | } |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 2711 | sgblkp = sgblkp->next_sgblkp; |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2712 | sg_blk_cnt++; |
| 2713 | } |
| 2714 | } |
| 2715 | } |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 2716 | #endif /* ADVANSYS_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | |
| 2718 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2719 | * advansys_info() |
| 2720 | * |
| 2721 | * Return suitable for printing on the console with the argument |
| 2722 | * adapter's configuration information. |
| 2723 | * |
| 2724 | * Note: The information line should not exceed ASC_INFO_SIZE bytes, |
| 2725 | * otherwise the static 'info' array will be overrun. |
| 2726 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2727 | static const char *advansys_info(struct Scsi_Host *shost) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2729 | static char info[ASC_INFO_SIZE]; |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 2730 | struct asc_board *boardp = shost_priv(shost); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2731 | ASC_DVC_VAR *asc_dvc_varp; |
| 2732 | ADV_DVC_VAR *adv_dvc_varp; |
| 2733 | char *busname; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2734 | char *widename = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2736 | if (ASC_NARROW_BOARD(boardp)) { |
| 2737 | asc_dvc_varp = &boardp->dvc_var.asc_dvc_var; |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2738 | ASC_DBG(1, "begin\n"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2739 | if (asc_dvc_varp->bus_type & ASC_IS_ISA) { |
| 2740 | if ((asc_dvc_varp->bus_type & ASC_IS_ISAPNP) == |
| 2741 | ASC_IS_ISAPNP) { |
| 2742 | busname = "ISA PnP"; |
| 2743 | } else { |
| 2744 | busname = "ISA"; |
| 2745 | } |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2746 | sprintf(info, |
| 2747 | "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X, DMA 0x%X", |
| 2748 | ASC_VERSION, busname, |
| 2749 | (ulong)shost->io_port, |
Matthew Wilcox | 4a2d31c | 2007-07-26 11:55:34 -0400 | [diff] [blame] | 2750 | (ulong)shost->io_port + ASC_IOADR_GAP - 1, |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 2751 | boardp->irq, shost->dma_channel); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2752 | } else { |
| 2753 | if (asc_dvc_varp->bus_type & ASC_IS_VL) { |
| 2754 | busname = "VL"; |
| 2755 | } else if (asc_dvc_varp->bus_type & ASC_IS_EISA) { |
| 2756 | busname = "EISA"; |
| 2757 | } else if (asc_dvc_varp->bus_type & ASC_IS_PCI) { |
| 2758 | if ((asc_dvc_varp->bus_type & ASC_IS_PCI_ULTRA) |
| 2759 | == ASC_IS_PCI_ULTRA) { |
| 2760 | busname = "PCI Ultra"; |
| 2761 | } else { |
| 2762 | busname = "PCI"; |
| 2763 | } |
| 2764 | } else { |
| 2765 | busname = "?"; |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 2766 | shost_printk(KERN_ERR, shost, "unknown bus " |
| 2767 | "type %d\n", asc_dvc_varp->bus_type); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2768 | } |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2769 | sprintf(info, |
| 2770 | "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X", |
Matthew Wilcox | ecec194 | 2007-07-30 08:08:22 -0600 | [diff] [blame] | 2771 | ASC_VERSION, busname, (ulong)shost->io_port, |
Matthew Wilcox | 4a2d31c | 2007-07-26 11:55:34 -0400 | [diff] [blame] | 2772 | (ulong)shost->io_port + ASC_IOADR_GAP - 1, |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 2773 | boardp->irq); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2774 | } |
| 2775 | } else { |
| 2776 | /* |
| 2777 | * Wide Adapter Information |
| 2778 | * |
| 2779 | * Memory-mapped I/O is used instead of I/O space to access |
| 2780 | * the adapter, but display the I/O Port range. The Memory |
| 2781 | * I/O address is displayed through the driver /proc file. |
| 2782 | */ |
| 2783 | adv_dvc_varp = &boardp->dvc_var.adv_dvc_var; |
| 2784 | if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2785 | widename = "Ultra-Wide"; |
| 2786 | } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2787 | widename = "Ultra2-Wide"; |
| 2788 | } else { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2789 | widename = "Ultra3-Wide"; |
| 2790 | } |
| 2791 | sprintf(info, |
| 2792 | "AdvanSys SCSI %s: PCI %s: PCIMEM 0x%lX-0x%lX, IRQ 0x%X", |
| 2793 | ASC_VERSION, widename, (ulong)adv_dvc_varp->iop_base, |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 2794 | (ulong)adv_dvc_varp->iop_base + boardp->asc_n_io_port - 1, boardp->irq); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2795 | } |
Matthew Wilcox | b009bef | 2007-09-09 08:56:38 -0600 | [diff] [blame] | 2796 | BUG_ON(strlen(info) >= ASC_INFO_SIZE); |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 2797 | ASC_DBG(1, "end\n"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2798 | return info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | } |
| 2800 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 2801 | #ifdef CONFIG_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | |
| 2803 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | * asc_prt_board_devices() |
| 2805 | * |
| 2806 | * Print driver information for devices attached to the board. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2807 | */ |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 2808 | static void asc_prt_board_devices(struct seq_file *m, struct Scsi_Host *shost) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2809 | { |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 2810 | struct asc_board *boardp = shost_priv(shost); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2811 | int chip_scsi_id; |
| 2812 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2813 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 2814 | seq_printf(m, |
| 2815 | "\nDevice Information for AdvanSys SCSI Host %d:\n", |
| 2816 | shost->host_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2818 | if (ASC_NARROW_BOARD(boardp)) { |
| 2819 | chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id; |
| 2820 | } else { |
| 2821 | chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id; |
| 2822 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 2824 | seq_puts(m, "Target IDs Detected:"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2825 | for (i = 0; i <= ADV_MAX_TID; i++) { |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 2826 | if (boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) |
| 2827 | seq_printf(m, " %X,", i); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2828 | } |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 2829 | seq_printf(m, " (%X=Host Adapter)\n", chip_scsi_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | } |
| 2831 | |
| 2832 | /* |
| 2833 | * Display Wide Board BIOS Information. |
| 2834 | */ |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 2835 | static void asc_prt_adv_bios(struct seq_file *m, struct Scsi_Host *shost) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | { |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 2837 | struct asc_board *boardp = shost_priv(shost); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2838 | ushort major, minor, letter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2839 | |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 2840 | seq_puts(m, "\nROM BIOS Version: "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2842 | /* |
| 2843 | * If the BIOS saved a valid signature, then fill in |
| 2844 | * the BIOS code segment base address. |
| 2845 | */ |
| 2846 | if (boardp->bios_signature != 0x55AA) { |
Rasmus Villemoes | 3d30079 | 2014-12-03 00:10:53 +0100 | [diff] [blame] | 2847 | seq_puts(m, "Disabled or Pre-3.1\n" |
| 2848 | "BIOS either disabled or Pre-3.1. If it is pre-3.1, then a newer version\n" |
| 2849 | "can be found at the ConnectCom FTP site: ftp://ftp.connectcom.net/pub\n"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2850 | } else { |
| 2851 | major = (boardp->bios_version >> 12) & 0xF; |
| 2852 | minor = (boardp->bios_version >> 8) & 0xF; |
| 2853 | letter = (boardp->bios_version & 0xFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 2855 | seq_printf(m, "%d.%d%c\n", |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2856 | major, minor, |
| 2857 | letter >= 26 ? '?' : letter + 'A'); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2858 | /* |
| 2859 | * Current available ROM BIOS release is 3.1I for UW |
| 2860 | * and 3.2I for U2W. This code doesn't differentiate |
| 2861 | * UW and U2W boards. |
| 2862 | */ |
| 2863 | if (major < 3 || (major <= 3 && minor < 1) || |
| 2864 | (major <= 3 && minor <= 1 && letter < ('I' - 'A'))) { |
Rasmus Villemoes | 3d30079 | 2014-12-03 00:10:53 +0100 | [diff] [blame] | 2865 | seq_puts(m, "Newer version of ROM BIOS is available at the ConnectCom FTP site:\n" |
| 2866 | "ftp://ftp.connectcom.net/pub\n"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2867 | } |
| 2868 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | } |
| 2870 | |
| 2871 | /* |
| 2872 | * Add serial number to information bar if signature AAh |
| 2873 | * is found in at bit 15-9 (7 bits) of word 1. |
| 2874 | * |
| 2875 | * Serial Number consists fo 12 alpha-numeric digits. |
| 2876 | * |
| 2877 | * 1 - Product type (A,B,C,D..) Word0: 15-13 (3 bits) |
| 2878 | * 2 - MFG Location (A,B,C,D..) Word0: 12-10 (3 bits) |
| 2879 | * 3-4 - Product ID (0-99) Word0: 9-0 (10 bits) |
| 2880 | * 5 - Product revision (A-J) Word0: " " |
| 2881 | * |
| 2882 | * Signature Word1: 15-9 (7 bits) |
| 2883 | * 6 - Year (0-9) Word1: 8-6 (3 bits) & Word2: 15 (1 bit) |
| 2884 | * 7-8 - Week of the year (1-52) Word1: 5-0 (6 bits) |
| 2885 | * |
| 2886 | * 9-12 - Serial Number (A001-Z999) Word2: 14-0 (15 bits) |
| 2887 | * |
| 2888 | * Note 1: Only production cards will have a serial number. |
| 2889 | * |
| 2890 | * Note 2: Signature is most significant 7 bits (0xFE). |
| 2891 | * |
| 2892 | * Returns ASC_TRUE if serial number found, otherwise returns ASC_FALSE. |
| 2893 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2894 | static int asc_get_eeprom_string(ushort *serialnum, uchar *cp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2896 | ushort w, num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2898 | if ((serialnum[1] & 0xFE00) != ((ushort)0xAA << 8)) { |
| 2899 | return ASC_FALSE; |
| 2900 | } else { |
| 2901 | /* |
| 2902 | * First word - 6 digits. |
| 2903 | */ |
| 2904 | w = serialnum[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2905 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2906 | /* Product type - 1st digit. */ |
| 2907 | if ((*cp = 'A' + ((w & 0xE000) >> 13)) == 'H') { |
| 2908 | /* Product type is P=Prototype */ |
| 2909 | *cp += 0x8; |
| 2910 | } |
| 2911 | cp++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2912 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2913 | /* Manufacturing location - 2nd digit. */ |
| 2914 | *cp++ = 'A' + ((w & 0x1C00) >> 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2915 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2916 | /* Product ID - 3rd, 4th digits. */ |
| 2917 | num = w & 0x3FF; |
| 2918 | *cp++ = '0' + (num / 100); |
| 2919 | num %= 100; |
| 2920 | *cp++ = '0' + (num / 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2922 | /* Product revision - 5th digit. */ |
| 2923 | *cp++ = 'A' + (num % 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2924 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2925 | /* |
| 2926 | * Second word |
| 2927 | */ |
| 2928 | w = serialnum[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2930 | /* |
| 2931 | * Year - 6th digit. |
| 2932 | * |
| 2933 | * If bit 15 of third word is set, then the |
| 2934 | * last digit of the year is greater than 7. |
| 2935 | */ |
| 2936 | if (serialnum[2] & 0x8000) { |
| 2937 | *cp++ = '8' + ((w & 0x1C0) >> 6); |
| 2938 | } else { |
| 2939 | *cp++ = '0' + ((w & 0x1C0) >> 6); |
| 2940 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2942 | /* Week of year - 7th, 8th digits. */ |
| 2943 | num = w & 0x003F; |
| 2944 | *cp++ = '0' + num / 10; |
| 2945 | num %= 10; |
| 2946 | *cp++ = '0' + num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2948 | /* |
| 2949 | * Third word |
| 2950 | */ |
| 2951 | w = serialnum[2] & 0x7FFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2952 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2953 | /* Serial number - 9th digit. */ |
| 2954 | *cp++ = 'A' + (w / 1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2956 | /* 10th, 11th, 12th digits. */ |
| 2957 | num = w % 1000; |
| 2958 | *cp++ = '0' + num / 100; |
| 2959 | num %= 100; |
| 2960 | *cp++ = '0' + num / 10; |
| 2961 | num %= 10; |
| 2962 | *cp++ = '0' + num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2964 | *cp = '\0'; /* Null Terminate the string. */ |
| 2965 | return ASC_TRUE; |
| 2966 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | /* |
| 2970 | * asc_prt_asc_board_eeprom() |
| 2971 | * |
| 2972 | * Print board EEPROM configuration. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | */ |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 2974 | static void asc_prt_asc_board_eeprom(struct seq_file *m, struct Scsi_Host *shost) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | { |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 2976 | struct asc_board *boardp = shost_priv(shost); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2977 | ASC_DVC_VAR *asc_dvc_varp; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2978 | ASCEEP_CONFIG *ep; |
| 2979 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | #ifdef CONFIG_ISA |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2981 | int isa_dma_speed[] = { 10, 8, 7, 6, 5, 4, 3, 2 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | #endif /* CONFIG_ISA */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2983 | uchar serialstr[13]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2985 | asc_dvc_varp = &boardp->dvc_var.asc_dvc_var; |
| 2986 | ep = &boardp->eep_config.asc_eep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2987 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 2988 | seq_printf(m, |
| 2989 | "\nEEPROM Settings for AdvanSys SCSI Host %d:\n", |
| 2990 | shost->host_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 2992 | if (asc_get_eeprom_string((ushort *)&ep->adapter_info[0], serialstr) |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 2993 | == ASC_TRUE) |
| 2994 | seq_printf(m, " Serial Number: %s\n", serialstr); |
| 2995 | else if (ep->adapter_info[5] == 0xBB) |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 2996 | seq_puts(m, |
| 2997 | " Default Settings Used for EEPROM-less Adapter.\n"); |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 2998 | else |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 2999 | seq_puts(m, " Serial Number Signature Not Present.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3001 | seq_printf(m, |
| 3002 | " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n", |
| 3003 | ASC_EEP_GET_CHIP_ID(ep), ep->max_total_qng, |
| 3004 | ep->max_tag_qng); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3005 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3006 | seq_printf(m, |
| 3007 | " cntl 0x%x, no_scam 0x%x\n", ep->cntl, ep->no_scam); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3009 | seq_puts(m, " Target ID: "); |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3010 | for (i = 0; i <= ASC_MAX_TID; i++) |
| 3011 | seq_printf(m, " %d", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 | |
Rasmus Villemoes | 3d30079 | 2014-12-03 00:10:53 +0100 | [diff] [blame] | 3013 | seq_puts(m, "\n Disconnects: "); |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3014 | for (i = 0; i <= ASC_MAX_TID; i++) |
| 3015 | seq_printf(m, " %c", |
| 3016 | (ep->disc_enable & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | |
Rasmus Villemoes | 3d30079 | 2014-12-03 00:10:53 +0100 | [diff] [blame] | 3018 | seq_puts(m, "\n Command Queuing: "); |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3019 | for (i = 0; i <= ASC_MAX_TID; i++) |
| 3020 | seq_printf(m, " %c", |
| 3021 | (ep->use_cmd_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | |
Rasmus Villemoes | 3d30079 | 2014-12-03 00:10:53 +0100 | [diff] [blame] | 3023 | seq_puts(m, "\n Start Motor: "); |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3024 | for (i = 0; i <= ASC_MAX_TID; i++) |
| 3025 | seq_printf(m, " %c", |
| 3026 | (ep->start_motor & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3027 | |
Rasmus Villemoes | 3d30079 | 2014-12-03 00:10:53 +0100 | [diff] [blame] | 3028 | seq_puts(m, "\n Synchronous Transfer:"); |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3029 | for (i = 0; i <= ASC_MAX_TID; i++) |
| 3030 | seq_printf(m, " %c", |
| 3031 | (ep->init_sdtr & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N'); |
Rasmus Villemoes | f50332f | 2014-12-03 00:10:54 +0100 | [diff] [blame] | 3032 | seq_putc(m, '\n'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | |
| 3034 | #ifdef CONFIG_ISA |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3035 | if (asc_dvc_varp->bus_type & ASC_IS_ISA) { |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3036 | seq_printf(m, |
| 3037 | " Host ISA DMA speed: %d MB/S\n", |
| 3038 | isa_dma_speed[ASC_EEP_GET_DMA_SPD(ep)]); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3039 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | #endif /* CONFIG_ISA */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3041 | } |
| 3042 | |
| 3043 | /* |
| 3044 | * asc_prt_adv_board_eeprom() |
| 3045 | * |
| 3046 | * Print board EEPROM configuration. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | */ |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3048 | static void asc_prt_adv_board_eeprom(struct seq_file *m, struct Scsi_Host *shost) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3049 | { |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 3050 | struct asc_board *boardp = shost_priv(shost); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3051 | ADV_DVC_VAR *adv_dvc_varp; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3052 | int i; |
| 3053 | char *termstr; |
| 3054 | uchar serialstr[13]; |
| 3055 | ADVEEP_3550_CONFIG *ep_3550 = NULL; |
| 3056 | ADVEEP_38C0800_CONFIG *ep_38C0800 = NULL; |
| 3057 | ADVEEP_38C1600_CONFIG *ep_38C1600 = NULL; |
| 3058 | ushort word; |
| 3059 | ushort *wordp; |
| 3060 | ushort sdtr_speed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3062 | adv_dvc_varp = &boardp->dvc_var.adv_dvc_var; |
| 3063 | if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) { |
| 3064 | ep_3550 = &boardp->eep_config.adv_3550_eep; |
| 3065 | } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) { |
| 3066 | ep_38C0800 = &boardp->eep_config.adv_38C0800_eep; |
| 3067 | } else { |
| 3068 | ep_38C1600 = &boardp->eep_config.adv_38C1600_eep; |
| 3069 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3071 | seq_printf(m, |
| 3072 | "\nEEPROM Settings for AdvanSys SCSI Host %d:\n", |
| 3073 | shost->host_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3074 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3075 | if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) { |
| 3076 | wordp = &ep_3550->serial_number_word1; |
| 3077 | } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) { |
| 3078 | wordp = &ep_38C0800->serial_number_word1; |
| 3079 | } else { |
| 3080 | wordp = &ep_38C1600->serial_number_word1; |
| 3081 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3082 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3083 | if (asc_get_eeprom_string(wordp, serialstr) == ASC_TRUE) |
| 3084 | seq_printf(m, " Serial Number: %s\n", serialstr); |
| 3085 | else |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3086 | seq_puts(m, " Serial Number Signature Not Present.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3087 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3088 | if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) |
| 3089 | seq_printf(m, |
| 3090 | " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n", |
| 3091 | ep_3550->adapter_scsi_id, |
| 3092 | ep_3550->max_host_qng, ep_3550->max_dvc_qng); |
| 3093 | else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) |
| 3094 | seq_printf(m, |
| 3095 | " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n", |
| 3096 | ep_38C0800->adapter_scsi_id, |
| 3097 | ep_38C0800->max_host_qng, |
| 3098 | ep_38C0800->max_dvc_qng); |
| 3099 | else |
| 3100 | seq_printf(m, |
| 3101 | " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n", |
| 3102 | ep_38C1600->adapter_scsi_id, |
| 3103 | ep_38C1600->max_host_qng, |
| 3104 | ep_38C1600->max_dvc_qng); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3105 | if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) { |
| 3106 | word = ep_3550->termination; |
| 3107 | } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) { |
| 3108 | word = ep_38C0800->termination_lvd; |
| 3109 | } else { |
| 3110 | word = ep_38C1600->termination_lvd; |
| 3111 | } |
| 3112 | switch (word) { |
| 3113 | case 1: |
| 3114 | termstr = "Low Off/High Off"; |
| 3115 | break; |
| 3116 | case 2: |
| 3117 | termstr = "Low Off/High On"; |
| 3118 | break; |
| 3119 | case 3: |
| 3120 | termstr = "Low On/High On"; |
| 3121 | break; |
| 3122 | default: |
| 3123 | case 0: |
| 3124 | termstr = "Automatic"; |
| 3125 | break; |
| 3126 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3128 | if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) |
| 3129 | seq_printf(m, |
| 3130 | " termination: %u (%s), bios_ctrl: 0x%x\n", |
| 3131 | ep_3550->termination, termstr, |
| 3132 | ep_3550->bios_ctrl); |
| 3133 | else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) |
| 3134 | seq_printf(m, |
| 3135 | " termination: %u (%s), bios_ctrl: 0x%x\n", |
| 3136 | ep_38C0800->termination_lvd, termstr, |
| 3137 | ep_38C0800->bios_ctrl); |
| 3138 | else |
| 3139 | seq_printf(m, |
| 3140 | " termination: %u (%s), bios_ctrl: 0x%x\n", |
| 3141 | ep_38C1600->termination_lvd, termstr, |
| 3142 | ep_38C1600->bios_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3143 | |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3144 | seq_puts(m, " Target ID: "); |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3145 | for (i = 0; i <= ADV_MAX_TID; i++) |
| 3146 | seq_printf(m, " %X", i); |
Rasmus Villemoes | f50332f | 2014-12-03 00:10:54 +0100 | [diff] [blame] | 3147 | seq_putc(m, '\n'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3149 | if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) { |
| 3150 | word = ep_3550->disc_enable; |
| 3151 | } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) { |
| 3152 | word = ep_38C0800->disc_enable; |
| 3153 | } else { |
| 3154 | word = ep_38C1600->disc_enable; |
| 3155 | } |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3156 | seq_puts(m, " Disconnects: "); |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3157 | for (i = 0; i <= ADV_MAX_TID; i++) |
| 3158 | seq_printf(m, " %c", |
| 3159 | (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N'); |
Rasmus Villemoes | f50332f | 2014-12-03 00:10:54 +0100 | [diff] [blame] | 3160 | seq_putc(m, '\n'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3162 | if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) { |
| 3163 | word = ep_3550->tagqng_able; |
| 3164 | } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) { |
| 3165 | word = ep_38C0800->tagqng_able; |
| 3166 | } else { |
| 3167 | word = ep_38C1600->tagqng_able; |
| 3168 | } |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3169 | seq_puts(m, " Command Queuing: "); |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3170 | for (i = 0; i <= ADV_MAX_TID; i++) |
| 3171 | seq_printf(m, " %c", |
| 3172 | (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N'); |
Rasmus Villemoes | f50332f | 2014-12-03 00:10:54 +0100 | [diff] [blame] | 3173 | seq_putc(m, '\n'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3174 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3175 | if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) { |
| 3176 | word = ep_3550->start_motor; |
| 3177 | } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) { |
| 3178 | word = ep_38C0800->start_motor; |
| 3179 | } else { |
| 3180 | word = ep_38C1600->start_motor; |
| 3181 | } |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3182 | seq_puts(m, " Start Motor: "); |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3183 | for (i = 0; i <= ADV_MAX_TID; i++) |
| 3184 | seq_printf(m, " %c", |
| 3185 | (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N'); |
Rasmus Villemoes | f50332f | 2014-12-03 00:10:54 +0100 | [diff] [blame] | 3186 | seq_putc(m, '\n'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3187 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3188 | if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) { |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3189 | seq_puts(m, " Synchronous Transfer:"); |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3190 | for (i = 0; i <= ADV_MAX_TID; i++) |
| 3191 | seq_printf(m, " %c", |
| 3192 | (ep_3550->sdtr_able & ADV_TID_TO_TIDMASK(i)) ? |
| 3193 | 'Y' : 'N'); |
Rasmus Villemoes | f50332f | 2014-12-03 00:10:54 +0100 | [diff] [blame] | 3194 | seq_putc(m, '\n'); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3195 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3197 | if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) { |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3198 | seq_puts(m, " Ultra Transfer: "); |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3199 | for (i = 0; i <= ADV_MAX_TID; i++) |
| 3200 | seq_printf(m, " %c", |
| 3201 | (ep_3550->ultra_able & ADV_TID_TO_TIDMASK(i)) |
| 3202 | ? 'Y' : 'N'); |
Rasmus Villemoes | f50332f | 2014-12-03 00:10:54 +0100 | [diff] [blame] | 3203 | seq_putc(m, '\n'); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3204 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3205 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3206 | if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) { |
| 3207 | word = ep_3550->wdtr_able; |
| 3208 | } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) { |
| 3209 | word = ep_38C0800->wdtr_able; |
| 3210 | } else { |
| 3211 | word = ep_38C1600->wdtr_able; |
| 3212 | } |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3213 | seq_puts(m, " Wide Transfer: "); |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3214 | for (i = 0; i <= ADV_MAX_TID; i++) |
| 3215 | seq_printf(m, " %c", |
| 3216 | (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N'); |
Rasmus Villemoes | f50332f | 2014-12-03 00:10:54 +0100 | [diff] [blame] | 3217 | seq_putc(m, '\n'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3219 | if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800 || |
| 3220 | adv_dvc_varp->chip_type == ADV_CHIP_ASC38C1600) { |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3221 | seq_puts(m, " Synchronous Transfer Speed (Mhz):\n "); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3222 | for (i = 0; i <= ADV_MAX_TID; i++) { |
| 3223 | char *speed_str; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3224 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3225 | if (i == 0) { |
| 3226 | sdtr_speed = adv_dvc_varp->sdtr_speed1; |
| 3227 | } else if (i == 4) { |
| 3228 | sdtr_speed = adv_dvc_varp->sdtr_speed2; |
| 3229 | } else if (i == 8) { |
| 3230 | sdtr_speed = adv_dvc_varp->sdtr_speed3; |
| 3231 | } else if (i == 12) { |
| 3232 | sdtr_speed = adv_dvc_varp->sdtr_speed4; |
| 3233 | } |
| 3234 | switch (sdtr_speed & ADV_MAX_TID) { |
| 3235 | case 0: |
| 3236 | speed_str = "Off"; |
| 3237 | break; |
| 3238 | case 1: |
| 3239 | speed_str = " 5"; |
| 3240 | break; |
| 3241 | case 2: |
| 3242 | speed_str = " 10"; |
| 3243 | break; |
| 3244 | case 3: |
| 3245 | speed_str = " 20"; |
| 3246 | break; |
| 3247 | case 4: |
| 3248 | speed_str = " 40"; |
| 3249 | break; |
| 3250 | case 5: |
| 3251 | speed_str = " 80"; |
| 3252 | break; |
| 3253 | default: |
| 3254 | speed_str = "Unk"; |
| 3255 | break; |
| 3256 | } |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3257 | seq_printf(m, "%X:%s ", i, speed_str); |
| 3258 | if (i == 7) |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3259 | seq_puts(m, "\n "); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3260 | sdtr_speed >>= 4; |
| 3261 | } |
Rasmus Villemoes | f50332f | 2014-12-03 00:10:54 +0100 | [diff] [blame] | 3262 | seq_putc(m, '\n'); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3263 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3264 | } |
| 3265 | |
| 3266 | /* |
| 3267 | * asc_prt_driver_conf() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | */ |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3269 | static void asc_prt_driver_conf(struct seq_file *m, struct Scsi_Host *shost) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | { |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 3271 | struct asc_board *boardp = shost_priv(shost); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3272 | int chip_scsi_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3273 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3274 | seq_printf(m, |
| 3275 | "\nLinux Driver Configuration and Information for AdvanSys SCSI Host %d:\n", |
| 3276 | shost->host_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3277 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3278 | seq_printf(m, |
Hannes Reinecke | 1abf635 | 2014-06-25 15:27:38 +0200 | [diff] [blame] | 3279 | " host_busy %u, max_id %u, max_lun %llu, max_channel %u\n", |
Christoph Hellwig | 7466501 | 2014-01-22 15:29:29 +0100 | [diff] [blame] | 3280 | atomic_read(&shost->host_busy), shost->max_id, |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3281 | shost->max_lun, shost->max_channel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3283 | seq_printf(m, |
| 3284 | " unique_id %d, can_queue %d, this_id %d, sg_tablesize %u, cmd_per_lun %u\n", |
| 3285 | shost->unique_id, shost->can_queue, shost->this_id, |
| 3286 | shost->sg_tablesize, shost->cmd_per_lun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3287 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3288 | seq_printf(m, |
| 3289 | " unchecked_isa_dma %d, use_clustering %d\n", |
| 3290 | shost->unchecked_isa_dma, shost->use_clustering); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3291 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3292 | seq_printf(m, |
Al Viro | 31491e1 | 2013-03-31 03:04:13 -0400 | [diff] [blame] | 3293 | " flags 0x%x, last_reset 0x%lx, jiffies 0x%lx, asc_n_io_port 0x%x\n", |
Hannes Reinecke | eac0b0c | 2015-04-24 13:18:20 +0200 | [diff] [blame] | 3294 | boardp->flags, shost->last_reset, jiffies, |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3295 | boardp->asc_n_io_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | |
Al Viro | 31491e1 | 2013-03-31 03:04:13 -0400 | [diff] [blame] | 3297 | seq_printf(m, " io_port 0x%lx\n", shost->io_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3298 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3299 | if (ASC_NARROW_BOARD(boardp)) { |
| 3300 | chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id; |
| 3301 | } else { |
| 3302 | chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id; |
| 3303 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3304 | } |
| 3305 | |
| 3306 | /* |
| 3307 | * asc_prt_asc_board_info() |
| 3308 | * |
| 3309 | * Print dynamic board configuration information. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3310 | */ |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3311 | static void asc_prt_asc_board_info(struct seq_file *m, struct Scsi_Host *shost) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3312 | { |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 3313 | struct asc_board *boardp = shost_priv(shost); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3314 | int chip_scsi_id; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3315 | ASC_DVC_VAR *v; |
| 3316 | ASC_DVC_CFG *c; |
| 3317 | int i; |
| 3318 | int renegotiate = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3319 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3320 | v = &boardp->dvc_var.asc_dvc_var; |
| 3321 | c = &boardp->dvc_cfg.asc_dvc_cfg; |
| 3322 | chip_scsi_id = c->chip_scsi_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3324 | seq_printf(m, |
| 3325 | "\nAsc Library Configuration and Statistics for AdvanSys SCSI Host %d:\n", |
| 3326 | shost->host_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3327 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3328 | seq_printf(m, " chip_version %u, mcode_date 0x%x, " |
| 3329 | "mcode_version 0x%x, err_code %u\n", |
| 3330 | c->chip_version, c->mcode_date, c->mcode_version, |
| 3331 | v->err_code); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3332 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3333 | /* Current number of commands waiting for the host. */ |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3334 | seq_printf(m, |
| 3335 | " Total Command Pending: %d\n", v->cur_total_qng); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3336 | |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3337 | seq_puts(m, " Command Queuing:"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3338 | for (i = 0; i <= ASC_MAX_TID; i++) { |
| 3339 | if ((chip_scsi_id == i) || |
| 3340 | ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) { |
| 3341 | continue; |
| 3342 | } |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3343 | seq_printf(m, " %X:%c", |
| 3344 | i, |
| 3345 | (v->use_tagged_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N'); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3346 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3347 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3348 | /* Current number of commands waiting for a device. */ |
Rasmus Villemoes | 3d30079 | 2014-12-03 00:10:53 +0100 | [diff] [blame] | 3349 | seq_puts(m, "\n Command Queue Pending:"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3350 | for (i = 0; i <= ASC_MAX_TID; i++) { |
| 3351 | if ((chip_scsi_id == i) || |
| 3352 | ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) { |
| 3353 | continue; |
| 3354 | } |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3355 | seq_printf(m, " %X:%u", i, v->cur_dvc_qng[i]); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3356 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3357 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3358 | /* Current limit on number of commands that can be sent to a device. */ |
Rasmus Villemoes | 3d30079 | 2014-12-03 00:10:53 +0100 | [diff] [blame] | 3359 | seq_puts(m, "\n Command Queue Limit:"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3360 | for (i = 0; i <= ASC_MAX_TID; i++) { |
| 3361 | if ((chip_scsi_id == i) || |
| 3362 | ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) { |
| 3363 | continue; |
| 3364 | } |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3365 | seq_printf(m, " %X:%u", i, v->max_dvc_qng[i]); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3366 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3368 | /* Indicate whether the device has returned queue full status. */ |
Rasmus Villemoes | 3d30079 | 2014-12-03 00:10:53 +0100 | [diff] [blame] | 3369 | seq_puts(m, "\n Command Queue Full:"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3370 | for (i = 0; i <= ASC_MAX_TID; i++) { |
| 3371 | if ((chip_scsi_id == i) || |
| 3372 | ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) { |
| 3373 | continue; |
| 3374 | } |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3375 | if (boardp->queue_full & ADV_TID_TO_TIDMASK(i)) |
| 3376 | seq_printf(m, " %X:Y-%d", |
| 3377 | i, boardp->queue_full_cnt[i]); |
| 3378 | else |
| 3379 | seq_printf(m, " %X:N", i); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3380 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | |
Rasmus Villemoes | 3d30079 | 2014-12-03 00:10:53 +0100 | [diff] [blame] | 3382 | seq_puts(m, "\n Synchronous Transfer:"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3383 | for (i = 0; i <= ASC_MAX_TID; i++) { |
| 3384 | if ((chip_scsi_id == i) || |
| 3385 | ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) { |
| 3386 | continue; |
| 3387 | } |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3388 | seq_printf(m, " %X:%c", |
| 3389 | i, |
| 3390 | (v->sdtr_done & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N'); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3391 | } |
Rasmus Villemoes | f50332f | 2014-12-03 00:10:54 +0100 | [diff] [blame] | 3392 | seq_putc(m, '\n'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3394 | for (i = 0; i <= ASC_MAX_TID; i++) { |
| 3395 | uchar syn_period_ix; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3397 | if ((chip_scsi_id == i) || |
| 3398 | ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) || |
| 3399 | ((v->init_sdtr & ADV_TID_TO_TIDMASK(i)) == 0)) { |
| 3400 | continue; |
| 3401 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3402 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3403 | seq_printf(m, " %X:", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3404 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3405 | if ((boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET) == 0) { |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3406 | seq_puts(m, " Asynchronous"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3407 | } else { |
| 3408 | syn_period_ix = |
| 3409 | (boardp->sdtr_data[i] >> 4) & (v->max_sdtr_index - |
| 3410 | 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3411 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3412 | seq_printf(m, |
| 3413 | " Transfer Period Factor: %d (%d.%d Mhz),", |
| 3414 | v->sdtr_period_tbl[syn_period_ix], |
| 3415 | 250 / v->sdtr_period_tbl[syn_period_ix], |
| 3416 | ASC_TENTHS(250, |
| 3417 | v->sdtr_period_tbl[syn_period_ix])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3419 | seq_printf(m, " REQ/ACK Offset: %d", |
| 3420 | boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3421 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3423 | if ((v->sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) { |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3424 | seq_puts(m, "*\n"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3425 | renegotiate = 1; |
| 3426 | } else { |
Rasmus Villemoes | f50332f | 2014-12-03 00:10:54 +0100 | [diff] [blame] | 3427 | seq_putc(m, '\n'); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3428 | } |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3429 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3430 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3431 | if (renegotiate) { |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3432 | seq_puts(m, " * = Re-negotiation pending before next command.\n"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3433 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3434 | } |
| 3435 | |
| 3436 | /* |
| 3437 | * asc_prt_adv_board_info() |
| 3438 | * |
| 3439 | * Print dynamic board configuration information. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | */ |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3441 | static void asc_prt_adv_board_info(struct seq_file *m, struct Scsi_Host *shost) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3442 | { |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 3443 | struct asc_board *boardp = shost_priv(shost); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3444 | int i; |
| 3445 | ADV_DVC_VAR *v; |
| 3446 | ADV_DVC_CFG *c; |
| 3447 | AdvPortAddr iop_base; |
| 3448 | ushort chip_scsi_id; |
| 3449 | ushort lramword; |
| 3450 | uchar lrambyte; |
| 3451 | ushort tagqng_able; |
| 3452 | ushort sdtr_able, wdtr_able; |
| 3453 | ushort wdtr_done, sdtr_done; |
| 3454 | ushort period = 0; |
| 3455 | int renegotiate = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3456 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3457 | v = &boardp->dvc_var.adv_dvc_var; |
| 3458 | c = &boardp->dvc_cfg.adv_dvc_cfg; |
| 3459 | iop_base = v->iop_base; |
| 3460 | chip_scsi_id = v->chip_scsi_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3461 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3462 | seq_printf(m, |
| 3463 | "\nAdv Library Configuration and Statistics for AdvanSys SCSI Host %d:\n", |
| 3464 | shost->host_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3465 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3466 | seq_printf(m, |
| 3467 | " iop_base 0x%lx, cable_detect: %X, err_code %u\n", |
Al Viro | 31491e1 | 2013-03-31 03:04:13 -0400 | [diff] [blame] | 3468 | (unsigned long)v->iop_base, |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3469 | AdvReadWordRegister(iop_base,IOPW_SCSI_CFG1) & CABLE_DETECT, |
| 3470 | v->err_code); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3471 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3472 | seq_printf(m, " chip_version %u, mcode_date 0x%x, " |
| 3473 | "mcode_version 0x%x\n", c->chip_version, |
| 3474 | c->mcode_date, c->mcode_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3475 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3476 | AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able); |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3477 | seq_puts(m, " Queuing Enabled:"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3478 | for (i = 0; i <= ADV_MAX_TID; i++) { |
| 3479 | if ((chip_scsi_id == i) || |
| 3480 | ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) { |
| 3481 | continue; |
| 3482 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3484 | seq_printf(m, " %X:%c", |
| 3485 | i, |
| 3486 | (tagqng_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N'); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3487 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3488 | |
Rasmus Villemoes | 3d30079 | 2014-12-03 00:10:53 +0100 | [diff] [blame] | 3489 | seq_puts(m, "\n Queue Limit:"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3490 | for (i = 0; i <= ADV_MAX_TID; i++) { |
| 3491 | if ((chip_scsi_id == i) || |
| 3492 | ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) { |
| 3493 | continue; |
| 3494 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3495 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3496 | AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + i, |
| 3497 | lrambyte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3498 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3499 | seq_printf(m, " %X:%d", i, lrambyte); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3500 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3501 | |
Rasmus Villemoes | 3d30079 | 2014-12-03 00:10:53 +0100 | [diff] [blame] | 3502 | seq_puts(m, "\n Command Pending:"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3503 | for (i = 0; i <= ADV_MAX_TID; i++) { |
| 3504 | if ((chip_scsi_id == i) || |
| 3505 | ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) { |
| 3506 | continue; |
| 3507 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3508 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3509 | AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_QUEUED_CMD + i, |
| 3510 | lrambyte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3511 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3512 | seq_printf(m, " %X:%d", i, lrambyte); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3513 | } |
Rasmus Villemoes | f50332f | 2014-12-03 00:10:54 +0100 | [diff] [blame] | 3514 | seq_putc(m, '\n'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3515 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3516 | AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able); |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3517 | seq_puts(m, " Wide Enabled:"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3518 | for (i = 0; i <= ADV_MAX_TID; i++) { |
| 3519 | if ((chip_scsi_id == i) || |
| 3520 | ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) { |
| 3521 | continue; |
| 3522 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3523 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3524 | seq_printf(m, " %X:%c", |
| 3525 | i, |
| 3526 | (wdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N'); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3527 | } |
Rasmus Villemoes | f50332f | 2014-12-03 00:10:54 +0100 | [diff] [blame] | 3528 | seq_putc(m, '\n'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3530 | AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, wdtr_done); |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3531 | seq_puts(m, " Transfer Bit Width:"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3532 | for (i = 0; i <= ADV_MAX_TID; i++) { |
| 3533 | if ((chip_scsi_id == i) || |
| 3534 | ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) { |
| 3535 | continue; |
| 3536 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3537 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3538 | AdvReadWordLram(iop_base, |
| 3539 | ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i), |
| 3540 | lramword); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3542 | seq_printf(m, " %X:%d", |
| 3543 | i, (lramword & 0x8000) ? 16 : 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3544 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3545 | if ((wdtr_able & ADV_TID_TO_TIDMASK(i)) && |
| 3546 | (wdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) { |
Rasmus Villemoes | f50332f | 2014-12-03 00:10:54 +0100 | [diff] [blame] | 3547 | seq_putc(m, '*'); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3548 | renegotiate = 1; |
| 3549 | } |
| 3550 | } |
Rasmus Villemoes | f50332f | 2014-12-03 00:10:54 +0100 | [diff] [blame] | 3551 | seq_putc(m, '\n'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3552 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3553 | AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able); |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3554 | seq_puts(m, " Synchronous Enabled:"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3555 | for (i = 0; i <= ADV_MAX_TID; i++) { |
| 3556 | if ((chip_scsi_id == i) || |
| 3557 | ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) { |
| 3558 | continue; |
| 3559 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3560 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3561 | seq_printf(m, " %X:%c", |
| 3562 | i, |
| 3563 | (sdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N'); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3564 | } |
Rasmus Villemoes | f50332f | 2014-12-03 00:10:54 +0100 | [diff] [blame] | 3565 | seq_putc(m, '\n'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3566 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3567 | AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, sdtr_done); |
| 3568 | for (i = 0; i <= ADV_MAX_TID; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3569 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3570 | AdvReadWordLram(iop_base, |
| 3571 | ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i), |
| 3572 | lramword); |
| 3573 | lramword &= ~0x8000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3574 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3575 | if ((chip_scsi_id == i) || |
| 3576 | ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) || |
| 3577 | ((sdtr_able & ADV_TID_TO_TIDMASK(i)) == 0)) { |
| 3578 | continue; |
| 3579 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3581 | seq_printf(m, " %X:", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3582 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3583 | if ((lramword & 0x1F) == 0) { /* Check for REQ/ACK Offset 0. */ |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3584 | seq_puts(m, " Asynchronous"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3585 | } else { |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3586 | seq_puts(m, " Transfer Period Factor: "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3587 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3588 | if ((lramword & 0x1F00) == 0x1100) { /* 80 Mhz */ |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3589 | seq_puts(m, "9 (80.0 Mhz),"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3590 | } else if ((lramword & 0x1F00) == 0x1000) { /* 40 Mhz */ |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3591 | seq_puts(m, "10 (40.0 Mhz),"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3592 | } else { /* 20 Mhz or below. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3594 | period = (((lramword >> 8) * 25) + 50) / 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3596 | if (period == 0) { /* Should never happen. */ |
Al Viro | 31491e1 | 2013-03-31 03:04:13 -0400 | [diff] [blame] | 3597 | seq_printf(m, "%d (? Mhz), ", period); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3598 | } else { |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3599 | seq_printf(m, |
| 3600 | "%d (%d.%d Mhz),", |
| 3601 | period, 250 / period, |
| 3602 | ASC_TENTHS(250, period)); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3603 | } |
| 3604 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3605 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3606 | seq_printf(m, " REQ/ACK Offset: %d", |
| 3607 | lramword & 0x1F); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3608 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3609 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3610 | if ((sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) { |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3611 | seq_puts(m, "*\n"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3612 | renegotiate = 1; |
| 3613 | } else { |
Rasmus Villemoes | f50332f | 2014-12-03 00:10:54 +0100 | [diff] [blame] | 3614 | seq_putc(m, '\n'); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3615 | } |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3616 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3617 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3618 | if (renegotiate) { |
Rasmus Villemoes | 2f97942 | 2014-12-03 00:10:50 +0100 | [diff] [blame] | 3619 | seq_puts(m, " * = Re-negotiation pending before next command.\n"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3620 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 | } |
| 3622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3623 | #ifdef ADVANSYS_STATS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3624 | /* |
| 3625 | * asc_prt_board_stats() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3626 | */ |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3627 | static void asc_prt_board_stats(struct seq_file *m, struct Scsi_Host *shost) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3628 | { |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 3629 | struct asc_board *boardp = shost_priv(shost); |
| 3630 | struct asc_stats *s = &boardp->asc_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3631 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3632 | seq_printf(m, |
| 3633 | "\nLinux Driver Statistics for AdvanSys SCSI Host %d:\n", |
| 3634 | shost->host_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3635 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3636 | seq_printf(m, |
Al Viro | 31491e1 | 2013-03-31 03:04:13 -0400 | [diff] [blame] | 3637 | " queuecommand %u, reset %u, biosparam %u, interrupt %u\n", |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3638 | s->queuecommand, s->reset, s->biosparam, |
| 3639 | s->interrupt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3640 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3641 | seq_printf(m, |
Al Viro | 31491e1 | 2013-03-31 03:04:13 -0400 | [diff] [blame] | 3642 | " callback %u, done %u, build_error %u, build_noreq %u, build_nosg %u\n", |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3643 | s->callback, s->done, s->build_error, |
| 3644 | s->adv_build_noreq, s->adv_build_nosg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3645 | |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3646 | seq_printf(m, |
Al Viro | 31491e1 | 2013-03-31 03:04:13 -0400 | [diff] [blame] | 3647 | " exe_noerror %u, exe_busy %u, exe_error %u, exe_unknown %u\n", |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3648 | s->exe_noerror, s->exe_busy, s->exe_error, |
| 3649 | s->exe_unknown); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3651 | /* |
| 3652 | * Display data transfer statistics. |
| 3653 | */ |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 3654 | if (s->xfer_cnt > 0) { |
Al Viro | 31491e1 | 2013-03-31 03:04:13 -0400 | [diff] [blame] | 3655 | seq_printf(m, " xfer_cnt %u, xfer_elem %u, ", |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3656 | s->xfer_cnt, s->xfer_elem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 | |
Al Viro | 31491e1 | 2013-03-31 03:04:13 -0400 | [diff] [blame] | 3658 | seq_printf(m, "xfer_bytes %u.%01u kb\n", |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3659 | s->xfer_sect / 2, ASC_TENTHS(s->xfer_sect, 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3661 | /* Scatter gather transfer statistics */ |
Al Viro | 31491e1 | 2013-03-31 03:04:13 -0400 | [diff] [blame] | 3662 | seq_printf(m, " avg_num_elem %u.%01u, ", |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3663 | s->xfer_elem / s->xfer_cnt, |
| 3664 | ASC_TENTHS(s->xfer_elem, s->xfer_cnt)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3665 | |
Al Viro | 31491e1 | 2013-03-31 03:04:13 -0400 | [diff] [blame] | 3666 | seq_printf(m, "avg_elem_size %u.%01u kb, ", |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3667 | (s->xfer_sect / 2) / s->xfer_elem, |
| 3668 | ASC_TENTHS((s->xfer_sect / 2), s->xfer_elem)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3669 | |
Al Viro | 31491e1 | 2013-03-31 03:04:13 -0400 | [diff] [blame] | 3670 | seq_printf(m, "avg_xfer_size %u.%01u kb\n", |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3671 | (s->xfer_sect / 2) / s->xfer_cnt, |
| 3672 | ASC_TENTHS((s->xfer_sect / 2), s->xfer_cnt)); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3673 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3674 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3675 | #endif /* ADVANSYS_STATS */ |
| 3676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3677 | /* |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3678 | * advansys_show_info() - /proc/scsi/advansys/{0,1,2,3,...} |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3679 | * |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3680 | * m: seq_file to print into |
| 3681 | * shost: Scsi_Host |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3682 | * |
| 3683 | * Return the number of bytes read from or written to a |
| 3684 | * /proc/scsi/advansys/[0...] file. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3685 | */ |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3686 | static int |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3687 | advansys_show_info(struct seq_file *m, struct Scsi_Host *shost) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | { |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 3689 | struct asc_board *boardp = shost_priv(shost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3690 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 3691 | ASC_DBG(1, "begin\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3692 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3693 | /* |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3694 | * User read of /proc/scsi/advansys/[0...] file. |
| 3695 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3697 | /* |
| 3698 | * Get board configuration information. |
| 3699 | * |
| 3700 | * advansys_info() returns the board string from its own static buffer. |
| 3701 | */ |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3702 | /* Copy board information. */ |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3703 | seq_printf(m, "%s\n", (char *)advansys_info(shost)); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3704 | /* |
| 3705 | * Display Wide Board BIOS Information. |
| 3706 | */ |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3707 | if (!ASC_NARROW_BOARD(boardp)) |
| 3708 | asc_prt_adv_bios(m, shost); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3709 | |
| 3710 | /* |
| 3711 | * Display driver information for each device attached to the board. |
| 3712 | */ |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3713 | asc_prt_board_devices(m, shost); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3714 | |
| 3715 | /* |
| 3716 | * Display EEPROM configuration for the board. |
| 3717 | */ |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3718 | if (ASC_NARROW_BOARD(boardp)) |
| 3719 | asc_prt_asc_board_eeprom(m, shost); |
| 3720 | else |
| 3721 | asc_prt_adv_board_eeprom(m, shost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3722 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3723 | /* |
| 3724 | * Display driver configuration and information for the board. |
| 3725 | */ |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3726 | asc_prt_driver_conf(m, shost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3727 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3728 | #ifdef ADVANSYS_STATS |
| 3729 | /* |
| 3730 | * Display driver statistics for the board. |
| 3731 | */ |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3732 | asc_prt_board_stats(m, shost); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3733 | #endif /* ADVANSYS_STATS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3734 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3735 | /* |
| 3736 | * Display Asc Library dynamic configuration information |
| 3737 | * for the board. |
| 3738 | */ |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 3739 | if (ASC_NARROW_BOARD(boardp)) |
| 3740 | asc_prt_asc_board_info(m, shost); |
| 3741 | else |
| 3742 | asc_prt_adv_board_info(m, shost); |
| 3743 | return 0; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3744 | } |
| 3745 | #endif /* CONFIG_PROC_FS */ |
| 3746 | |
| 3747 | static void asc_scsi_done(struct scsi_cmnd *scp) |
| 3748 | { |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 3749 | scsi_dma_unmap(scp); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3750 | ASC_STATS(scp->device->host, done); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3751 | scp->scsi_done(scp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3752 | } |
| 3753 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3754 | static void AscSetBank(PortAddr iop_base, uchar bank) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | { |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3756 | uchar val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3757 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3758 | val = AscGetChipControl(iop_base) & |
| 3759 | (~ |
| 3760 | (CC_SINGLE_STEP | CC_TEST | CC_DIAG | CC_SCSI_RESET | |
| 3761 | CC_CHIP_RESET)); |
| 3762 | if (bank == 1) { |
| 3763 | val |= CC_BANK_ONE; |
| 3764 | } else if (bank == 2) { |
| 3765 | val |= CC_DIAG | CC_BANK_ONE; |
| 3766 | } else { |
| 3767 | val &= ~CC_BANK_ONE; |
| 3768 | } |
| 3769 | AscSetChipControl(iop_base, val); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3770 | } |
| 3771 | |
| 3772 | static void AscSetChipIH(PortAddr iop_base, ushort ins_code) |
| 3773 | { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3774 | AscSetBank(iop_base, 1); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3775 | AscWriteChipIH(iop_base, ins_code); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3776 | AscSetBank(iop_base, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3777 | } |
| 3778 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3779 | static int AscStartChip(PortAddr iop_base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3780 | { |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3781 | AscSetChipControl(iop_base, 0); |
| 3782 | if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) { |
| 3783 | return (0); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 3784 | } |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3785 | return (1); |
| 3786 | } |
| 3787 | |
| 3788 | static int AscStopChip(PortAddr iop_base) |
| 3789 | { |
| 3790 | uchar cc_val; |
| 3791 | |
| 3792 | cc_val = |
| 3793 | AscGetChipControl(iop_base) & |
| 3794 | (~(CC_SINGLE_STEP | CC_TEST | CC_DIAG)); |
| 3795 | AscSetChipControl(iop_base, (uchar)(cc_val | CC_HALT)); |
| 3796 | AscSetChipIH(iop_base, INS_HALT); |
| 3797 | AscSetChipIH(iop_base, INS_RFLAG_WTM); |
| 3798 | if ((AscGetChipStatus(iop_base) & CSW_HALTED) == 0) { |
| 3799 | return (0); |
| 3800 | } |
| 3801 | return (1); |
| 3802 | } |
| 3803 | |
Hannes Reinecke | d647c78 | 2015-04-24 13:18:26 +0200 | [diff] [blame^] | 3804 | static bool AscIsChipHalted(PortAddr iop_base) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3805 | { |
| 3806 | if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) { |
| 3807 | if ((AscGetChipControl(iop_base) & CC_HALT) != 0) { |
Hannes Reinecke | d647c78 | 2015-04-24 13:18:26 +0200 | [diff] [blame^] | 3808 | return true; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3809 | } |
| 3810 | } |
Hannes Reinecke | d647c78 | 2015-04-24 13:18:26 +0200 | [diff] [blame^] | 3811 | return false; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3812 | } |
| 3813 | |
Hannes Reinecke | d647c78 | 2015-04-24 13:18:26 +0200 | [diff] [blame^] | 3814 | static bool AscResetChipAndScsiBus(ASC_DVC_VAR *asc_dvc) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3815 | { |
| 3816 | PortAddr iop_base; |
| 3817 | int i = 10; |
| 3818 | |
| 3819 | iop_base = asc_dvc->iop_base; |
| 3820 | while ((AscGetChipStatus(iop_base) & CSW_SCSI_RESET_ACTIVE) |
| 3821 | && (i-- > 0)) { |
| 3822 | mdelay(100); |
| 3823 | } |
| 3824 | AscStopChip(iop_base); |
| 3825 | AscSetChipControl(iop_base, CC_CHIP_RESET | CC_SCSI_RESET | CC_HALT); |
| 3826 | udelay(60); |
| 3827 | AscSetChipIH(iop_base, INS_RFLAG_WTM); |
| 3828 | AscSetChipIH(iop_base, INS_HALT); |
| 3829 | AscSetChipControl(iop_base, CC_CHIP_RESET | CC_HALT); |
| 3830 | AscSetChipControl(iop_base, CC_HALT); |
| 3831 | mdelay(200); |
| 3832 | AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT); |
| 3833 | AscSetChipStatus(iop_base, 0); |
| 3834 | return (AscIsChipHalted(iop_base)); |
| 3835 | } |
| 3836 | |
| 3837 | static int AscFindSignature(PortAddr iop_base) |
| 3838 | { |
| 3839 | ushort sig_word; |
| 3840 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 3841 | ASC_DBG(1, "AscGetChipSignatureByte(0x%x) 0x%x\n", |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3842 | iop_base, AscGetChipSignatureByte(iop_base)); |
| 3843 | if (AscGetChipSignatureByte(iop_base) == (uchar)ASC_1000_ID1B) { |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 3844 | ASC_DBG(1, "AscGetChipSignatureWord(0x%x) 0x%x\n", |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3845 | iop_base, AscGetChipSignatureWord(iop_base)); |
| 3846 | sig_word = AscGetChipSignatureWord(iop_base); |
| 3847 | if ((sig_word == (ushort)ASC_1000_ID0W) || |
| 3848 | (sig_word == (ushort)ASC_1000_ID0W_FIX)) { |
| 3849 | return (1); |
| 3850 | } |
| 3851 | } |
| 3852 | return (0); |
| 3853 | } |
| 3854 | |
| 3855 | static void AscEnableInterrupt(PortAddr iop_base) |
| 3856 | { |
| 3857 | ushort cfg; |
| 3858 | |
| 3859 | cfg = AscGetChipCfgLsw(iop_base); |
| 3860 | AscSetChipCfgLsw(iop_base, cfg | ASC_CFG0_HOST_INT_ON); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3861 | } |
| 3862 | |
| 3863 | static void AscDisableInterrupt(PortAddr iop_base) |
| 3864 | { |
| 3865 | ushort cfg; |
| 3866 | |
| 3867 | cfg = AscGetChipCfgLsw(iop_base); |
| 3868 | AscSetChipCfgLsw(iop_base, cfg & (~ASC_CFG0_HOST_INT_ON)); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3869 | } |
| 3870 | |
| 3871 | static uchar AscReadLramByte(PortAddr iop_base, ushort addr) |
| 3872 | { |
| 3873 | unsigned char byte_data; |
| 3874 | unsigned short word_data; |
| 3875 | |
| 3876 | if (isodd_word(addr)) { |
| 3877 | AscSetChipLramAddr(iop_base, addr - 1); |
| 3878 | word_data = AscGetChipLramData(iop_base); |
| 3879 | byte_data = (word_data >> 8) & 0xFF; |
| 3880 | } else { |
| 3881 | AscSetChipLramAddr(iop_base, addr); |
| 3882 | word_data = AscGetChipLramData(iop_base); |
| 3883 | byte_data = word_data & 0xFF; |
| 3884 | } |
| 3885 | return byte_data; |
| 3886 | } |
| 3887 | |
| 3888 | static ushort AscReadLramWord(PortAddr iop_base, ushort addr) |
| 3889 | { |
| 3890 | ushort word_data; |
| 3891 | |
| 3892 | AscSetChipLramAddr(iop_base, addr); |
| 3893 | word_data = AscGetChipLramData(iop_base); |
| 3894 | return (word_data); |
| 3895 | } |
| 3896 | |
| 3897 | #if CC_VERY_LONG_SG_LIST |
| 3898 | static ASC_DCNT AscReadLramDWord(PortAddr iop_base, ushort addr) |
| 3899 | { |
| 3900 | ushort val_low, val_high; |
| 3901 | ASC_DCNT dword_data; |
| 3902 | |
| 3903 | AscSetChipLramAddr(iop_base, addr); |
| 3904 | val_low = AscGetChipLramData(iop_base); |
| 3905 | val_high = AscGetChipLramData(iop_base); |
| 3906 | dword_data = ((ASC_DCNT) val_high << 16) | (ASC_DCNT) val_low; |
| 3907 | return (dword_data); |
| 3908 | } |
| 3909 | #endif /* CC_VERY_LONG_SG_LIST */ |
| 3910 | |
| 3911 | static void |
| 3912 | AscMemWordSetLram(PortAddr iop_base, ushort s_addr, ushort set_wval, int words) |
| 3913 | { |
| 3914 | int i; |
| 3915 | |
| 3916 | AscSetChipLramAddr(iop_base, s_addr); |
| 3917 | for (i = 0; i < words; i++) { |
| 3918 | AscSetChipLramData(iop_base, set_wval); |
| 3919 | } |
| 3920 | } |
| 3921 | |
| 3922 | static void AscWriteLramWord(PortAddr iop_base, ushort addr, ushort word_val) |
| 3923 | { |
| 3924 | AscSetChipLramAddr(iop_base, addr); |
| 3925 | AscSetChipLramData(iop_base, word_val); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3926 | } |
| 3927 | |
| 3928 | static void AscWriteLramByte(PortAddr iop_base, ushort addr, uchar byte_val) |
| 3929 | { |
| 3930 | ushort word_data; |
| 3931 | |
| 3932 | if (isodd_word(addr)) { |
| 3933 | addr--; |
| 3934 | word_data = AscReadLramWord(iop_base, addr); |
| 3935 | word_data &= 0x00FF; |
| 3936 | word_data |= (((ushort)byte_val << 8) & 0xFF00); |
| 3937 | } else { |
| 3938 | word_data = AscReadLramWord(iop_base, addr); |
| 3939 | word_data &= 0xFF00; |
| 3940 | word_data |= ((ushort)byte_val & 0x00FF); |
| 3941 | } |
| 3942 | AscWriteLramWord(iop_base, addr, word_data); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3943 | } |
| 3944 | |
| 3945 | /* |
| 3946 | * Copy 2 bytes to LRAM. |
| 3947 | * |
| 3948 | * The source data is assumed to be in little-endian order in memory |
| 3949 | * and is maintained in little-endian order when written to LRAM. |
| 3950 | */ |
| 3951 | static void |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 3952 | AscMemWordCopyPtrToLram(PortAddr iop_base, ushort s_addr, |
| 3953 | const uchar *s_buffer, int words) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3954 | { |
| 3955 | int i; |
| 3956 | |
| 3957 | AscSetChipLramAddr(iop_base, s_addr); |
| 3958 | for (i = 0; i < 2 * words; i += 2) { |
| 3959 | /* |
| 3960 | * On a little-endian system the second argument below |
| 3961 | * produces a little-endian ushort which is written to |
| 3962 | * LRAM in little-endian order. On a big-endian system |
| 3963 | * the second argument produces a big-endian ushort which |
| 3964 | * is "transparently" byte-swapped by outpw() and written |
| 3965 | * in little-endian order to LRAM. |
| 3966 | */ |
| 3967 | outpw(iop_base + IOP_RAM_DATA, |
| 3968 | ((ushort)s_buffer[i + 1] << 8) | s_buffer[i]); |
| 3969 | } |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3970 | } |
| 3971 | |
| 3972 | /* |
| 3973 | * Copy 4 bytes to LRAM. |
| 3974 | * |
| 3975 | * The source data is assumed to be in little-endian order in memory |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3976 | * and is maintained in little-endian order when written to LRAM. |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3977 | */ |
| 3978 | static void |
| 3979 | AscMemDWordCopyPtrToLram(PortAddr iop_base, |
| 3980 | ushort s_addr, uchar *s_buffer, int dwords) |
| 3981 | { |
| 3982 | int i; |
| 3983 | |
| 3984 | AscSetChipLramAddr(iop_base, s_addr); |
| 3985 | for (i = 0; i < 4 * dwords; i += 4) { |
| 3986 | outpw(iop_base + IOP_RAM_DATA, ((ushort)s_buffer[i + 1] << 8) | s_buffer[i]); /* LSW */ |
| 3987 | outpw(iop_base + IOP_RAM_DATA, ((ushort)s_buffer[i + 3] << 8) | s_buffer[i + 2]); /* MSW */ |
| 3988 | } |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 3989 | } |
| 3990 | |
| 3991 | /* |
| 3992 | * Copy 2 bytes from LRAM. |
| 3993 | * |
| 3994 | * The source data is assumed to be in little-endian order in LRAM |
| 3995 | * and is maintained in little-endian order when written to memory. |
| 3996 | */ |
| 3997 | static void |
| 3998 | AscMemWordCopyPtrFromLram(PortAddr iop_base, |
| 3999 | ushort s_addr, uchar *d_buffer, int words) |
| 4000 | { |
| 4001 | int i; |
| 4002 | ushort word; |
| 4003 | |
| 4004 | AscSetChipLramAddr(iop_base, s_addr); |
| 4005 | for (i = 0; i < 2 * words; i += 2) { |
| 4006 | word = inpw(iop_base + IOP_RAM_DATA); |
| 4007 | d_buffer[i] = word & 0xff; |
| 4008 | d_buffer[i + 1] = (word >> 8) & 0xff; |
| 4009 | } |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4010 | } |
| 4011 | |
| 4012 | static ASC_DCNT AscMemSumLramWord(PortAddr iop_base, ushort s_addr, int words) |
| 4013 | { |
| 4014 | ASC_DCNT sum; |
| 4015 | int i; |
| 4016 | |
| 4017 | sum = 0L; |
| 4018 | for (i = 0; i < words; i++, s_addr += 2) { |
| 4019 | sum += AscReadLramWord(iop_base, s_addr); |
| 4020 | } |
| 4021 | return (sum); |
| 4022 | } |
| 4023 | |
| 4024 | static ushort AscInitLram(ASC_DVC_VAR *asc_dvc) |
| 4025 | { |
| 4026 | uchar i; |
| 4027 | ushort s_addr; |
| 4028 | PortAddr iop_base; |
| 4029 | ushort warn_code; |
| 4030 | |
| 4031 | iop_base = asc_dvc->iop_base; |
| 4032 | warn_code = 0; |
| 4033 | AscMemWordSetLram(iop_base, ASC_QADR_BEG, 0, |
| 4034 | (ushort)(((int)(asc_dvc->max_total_qng + 2 + 1) * |
| 4035 | 64) >> 1)); |
| 4036 | i = ASC_MIN_ACTIVE_QNO; |
| 4037 | s_addr = ASC_QADR_BEG + ASC_QBLK_SIZE; |
| 4038 | AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD), |
| 4039 | (uchar)(i + 1)); |
| 4040 | AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD), |
| 4041 | (uchar)(asc_dvc->max_total_qng)); |
| 4042 | AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO), |
| 4043 | (uchar)i); |
| 4044 | i++; |
| 4045 | s_addr += ASC_QBLK_SIZE; |
| 4046 | for (; i < asc_dvc->max_total_qng; i++, s_addr += ASC_QBLK_SIZE) { |
| 4047 | AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD), |
| 4048 | (uchar)(i + 1)); |
| 4049 | AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD), |
| 4050 | (uchar)(i - 1)); |
| 4051 | AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO), |
| 4052 | (uchar)i); |
| 4053 | } |
| 4054 | AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_FWD), |
| 4055 | (uchar)ASC_QLINK_END); |
| 4056 | AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_BWD), |
| 4057 | (uchar)(asc_dvc->max_total_qng - 1)); |
| 4058 | AscWriteLramByte(iop_base, (ushort)(s_addr + ASC_SCSIQ_B_QNO), |
| 4059 | (uchar)asc_dvc->max_total_qng); |
| 4060 | i++; |
| 4061 | s_addr += ASC_QBLK_SIZE; |
| 4062 | for (; i <= (uchar)(asc_dvc->max_total_qng + 3); |
| 4063 | i++, s_addr += ASC_QBLK_SIZE) { |
| 4064 | AscWriteLramByte(iop_base, |
| 4065 | (ushort)(s_addr + (ushort)ASC_SCSIQ_B_FWD), i); |
| 4066 | AscWriteLramByte(iop_base, |
| 4067 | (ushort)(s_addr + (ushort)ASC_SCSIQ_B_BWD), i); |
| 4068 | AscWriteLramByte(iop_base, |
| 4069 | (ushort)(s_addr + (ushort)ASC_SCSIQ_B_QNO), i); |
| 4070 | } |
| 4071 | return warn_code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4072 | } |
| 4073 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4074 | static ASC_DCNT |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 4075 | AscLoadMicroCode(PortAddr iop_base, ushort s_addr, |
| 4076 | const uchar *mcode_buf, ushort mcode_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4078 | ASC_DCNT chksum; |
| 4079 | ushort mcode_word_size; |
| 4080 | ushort mcode_chksum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4082 | /* Write the microcode buffer starting at LRAM address 0. */ |
| 4083 | mcode_word_size = (ushort)(mcode_size >> 1); |
| 4084 | AscMemWordSetLram(iop_base, s_addr, 0, mcode_word_size); |
| 4085 | AscMemWordCopyPtrToLram(iop_base, s_addr, mcode_buf, mcode_word_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4086 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4087 | chksum = AscMemSumLramWord(iop_base, s_addr, mcode_word_size); |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 4088 | ASC_DBG(1, "chksum 0x%lx\n", (ulong)chksum); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4089 | mcode_chksum = (ushort)AscMemSumLramWord(iop_base, |
| 4090 | (ushort)ASC_CODE_SEC_BEG, |
| 4091 | (ushort)((mcode_size - |
| 4092 | s_addr - (ushort) |
| 4093 | ASC_CODE_SEC_BEG) / |
| 4094 | 2)); |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 4095 | ASC_DBG(1, "mcode_chksum 0x%lx\n", (ulong)mcode_chksum); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4096 | AscWriteLramWord(iop_base, ASCV_MCODE_CHKSUM_W, mcode_chksum); |
| 4097 | AscWriteLramWord(iop_base, ASCV_MCODE_SIZE_W, mcode_size); |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 4098 | return chksum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4099 | } |
| 4100 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4101 | static void AscInitQLinkVar(ASC_DVC_VAR *asc_dvc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4102 | { |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4103 | PortAddr iop_base; |
| 4104 | int i; |
| 4105 | ushort lram_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4106 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4107 | iop_base = asc_dvc->iop_base; |
| 4108 | AscPutRiscVarFreeQHead(iop_base, 1); |
| 4109 | AscPutRiscVarDoneQTail(iop_base, asc_dvc->max_total_qng); |
| 4110 | AscPutVarFreeQHead(iop_base, 1); |
| 4111 | AscPutVarDoneQTail(iop_base, asc_dvc->max_total_qng); |
| 4112 | AscWriteLramByte(iop_base, ASCV_BUSY_QHEAD_B, |
| 4113 | (uchar)((int)asc_dvc->max_total_qng + 1)); |
| 4114 | AscWriteLramByte(iop_base, ASCV_DISC1_QHEAD_B, |
| 4115 | (uchar)((int)asc_dvc->max_total_qng + 2)); |
| 4116 | AscWriteLramByte(iop_base, (ushort)ASCV_TOTAL_READY_Q_B, |
| 4117 | asc_dvc->max_total_qng); |
| 4118 | AscWriteLramWord(iop_base, ASCV_ASCDVC_ERR_CODE_W, 0); |
| 4119 | AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0); |
| 4120 | AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, 0); |
| 4121 | AscWriteLramByte(iop_base, ASCV_SCSIBUSY_B, 0); |
| 4122 | AscWriteLramByte(iop_base, ASCV_WTM_FLAG_B, 0); |
| 4123 | AscPutQDoneInProgress(iop_base, 0); |
| 4124 | lram_addr = ASC_QADR_BEG; |
| 4125 | for (i = 0; i < 32; i++, lram_addr += 2) { |
| 4126 | AscWriteLramWord(iop_base, lram_addr, 0); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4127 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4128 | } |
| 4129 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4130 | static ushort AscInitMicroCodeVar(ASC_DVC_VAR *asc_dvc) |
Matthew Wilcox | a9f4a59 | 2007-09-09 08:56:27 -0600 | [diff] [blame] | 4131 | { |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4132 | int i; |
| 4133 | ushort warn_code; |
| 4134 | PortAddr iop_base; |
| 4135 | ASC_PADDR phy_addr; |
| 4136 | ASC_DCNT phy_size; |
Matthew Wilcox | d10fb2c | 2007-10-02 21:55:41 -0400 | [diff] [blame] | 4137 | struct asc_board *board = asc_dvc_to_board(asc_dvc); |
Matthew Wilcox | a9f4a59 | 2007-09-09 08:56:27 -0600 | [diff] [blame] | 4138 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4139 | iop_base = asc_dvc->iop_base; |
| 4140 | warn_code = 0; |
| 4141 | for (i = 0; i <= ASC_MAX_TID; i++) { |
| 4142 | AscPutMCodeInitSDTRAtID(iop_base, i, |
| 4143 | asc_dvc->cfg->sdtr_period_offset[i]); |
Matthew Wilcox | a9f4a59 | 2007-09-09 08:56:27 -0600 | [diff] [blame] | 4144 | } |
| 4145 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4146 | AscInitQLinkVar(asc_dvc); |
| 4147 | AscWriteLramByte(iop_base, ASCV_DISC_ENABLE_B, |
| 4148 | asc_dvc->cfg->disc_enable); |
| 4149 | AscWriteLramByte(iop_base, ASCV_HOSTSCSI_ID_B, |
| 4150 | ASC_TID_TO_TARGET_ID(asc_dvc->cfg->chip_scsi_id)); |
Matthew Wilcox | a9f4a59 | 2007-09-09 08:56:27 -0600 | [diff] [blame] | 4151 | |
Matthew Wilcox | d10fb2c | 2007-10-02 21:55:41 -0400 | [diff] [blame] | 4152 | /* Ensure overrun buffer is aligned on an 8 byte boundary. */ |
| 4153 | BUG_ON((unsigned long)asc_dvc->overrun_buf & 7); |
| 4154 | asc_dvc->overrun_dma = dma_map_single(board->dev, asc_dvc->overrun_buf, |
| 4155 | ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE); |
Herton Ronaldo Krzesinski | 9a908c1 | 2010-03-30 13:35:38 -0300 | [diff] [blame] | 4156 | if (dma_mapping_error(board->dev, asc_dvc->overrun_dma)) { |
| 4157 | warn_code = -ENOMEM; |
| 4158 | goto err_dma_map; |
| 4159 | } |
Matthew Wilcox | d10fb2c | 2007-10-02 21:55:41 -0400 | [diff] [blame] | 4160 | phy_addr = cpu_to_le32(asc_dvc->overrun_dma); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4161 | AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_PADDR_D, |
| 4162 | (uchar *)&phy_addr, 1); |
Matthew Wilcox | d10fb2c | 2007-10-02 21:55:41 -0400 | [diff] [blame] | 4163 | phy_size = cpu_to_le32(ASC_OVERRUN_BSIZE); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4164 | AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_BSIZE_D, |
| 4165 | (uchar *)&phy_size, 1); |
Matthew Wilcox | a9f4a59 | 2007-09-09 08:56:27 -0600 | [diff] [blame] | 4166 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4167 | asc_dvc->cfg->mcode_date = |
| 4168 | AscReadLramWord(iop_base, (ushort)ASCV_MC_DATE_W); |
| 4169 | asc_dvc->cfg->mcode_version = |
| 4170 | AscReadLramWord(iop_base, (ushort)ASCV_MC_VER_W); |
Matthew Wilcox | a9f4a59 | 2007-09-09 08:56:27 -0600 | [diff] [blame] | 4171 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4172 | AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR); |
| 4173 | if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) { |
| 4174 | asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR; |
Herton Ronaldo Krzesinski | 9a908c1 | 2010-03-30 13:35:38 -0300 | [diff] [blame] | 4175 | warn_code = UW_ERR; |
| 4176 | goto err_mcode_start; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4177 | } |
| 4178 | if (AscStartChip(iop_base) != 1) { |
| 4179 | asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP; |
Herton Ronaldo Krzesinski | 9a908c1 | 2010-03-30 13:35:38 -0300 | [diff] [blame] | 4180 | warn_code = UW_ERR; |
| 4181 | goto err_mcode_start; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4182 | } |
Matthew Wilcox | a9f4a59 | 2007-09-09 08:56:27 -0600 | [diff] [blame] | 4183 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4184 | return warn_code; |
Herton Ronaldo Krzesinski | 9a908c1 | 2010-03-30 13:35:38 -0300 | [diff] [blame] | 4185 | |
| 4186 | err_mcode_start: |
| 4187 | dma_unmap_single(board->dev, asc_dvc->overrun_dma, |
| 4188 | ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE); |
| 4189 | err_dma_map: |
| 4190 | asc_dvc->overrun_dma = 0; |
| 4191 | return warn_code; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4192 | } |
Matthew Wilcox | a9f4a59 | 2007-09-09 08:56:27 -0600 | [diff] [blame] | 4193 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4194 | static ushort AscInitAsc1000Driver(ASC_DVC_VAR *asc_dvc) |
| 4195 | { |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 4196 | const struct firmware *fw; |
| 4197 | const char fwname[] = "advansys/mcode.bin"; |
| 4198 | int err; |
| 4199 | unsigned long chksum; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4200 | ushort warn_code; |
| 4201 | PortAddr iop_base; |
| 4202 | |
| 4203 | iop_base = asc_dvc->iop_base; |
| 4204 | warn_code = 0; |
| 4205 | if ((asc_dvc->dvc_cntl & ASC_CNTL_RESET_SCSI) && |
| 4206 | !(asc_dvc->init_state & ASC_INIT_RESET_SCSI_DONE)) { |
| 4207 | AscResetChipAndScsiBus(asc_dvc); |
| 4208 | mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */ |
| 4209 | } |
| 4210 | asc_dvc->init_state |= ASC_INIT_STATE_BEG_LOAD_MC; |
| 4211 | if (asc_dvc->err_code != 0) |
| 4212 | return UW_ERR; |
| 4213 | if (!AscFindSignature(asc_dvc->iop_base)) { |
| 4214 | asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE; |
| 4215 | return warn_code; |
| 4216 | } |
| 4217 | AscDisableInterrupt(iop_base); |
| 4218 | warn_code |= AscInitLram(asc_dvc); |
| 4219 | if (asc_dvc->err_code != 0) |
| 4220 | return UW_ERR; |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 4221 | |
| 4222 | err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev); |
| 4223 | if (err) { |
| 4224 | printk(KERN_ERR "Failed to load image \"%s\" err %d\n", |
| 4225 | fwname, err); |
Herton Ronaldo Krzesinski | cf74744 | 2010-03-19 19:37:26 -0300 | [diff] [blame] | 4226 | asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM; |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 4227 | return err; |
| 4228 | } |
| 4229 | if (fw->size < 4) { |
| 4230 | printk(KERN_ERR "Bogus length %zu in image \"%s\"\n", |
| 4231 | fw->size, fwname); |
| 4232 | release_firmware(fw); |
Herton Ronaldo Krzesinski | cf74744 | 2010-03-19 19:37:26 -0300 | [diff] [blame] | 4233 | asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM; |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 4234 | return -EINVAL; |
| 4235 | } |
| 4236 | chksum = (fw->data[3] << 24) | (fw->data[2] << 16) | |
| 4237 | (fw->data[1] << 8) | fw->data[0]; |
| 4238 | ASC_DBG(1, "_asc_mcode_chksum 0x%lx\n", (ulong)chksum); |
| 4239 | if (AscLoadMicroCode(iop_base, 0, &fw->data[4], |
| 4240 | fw->size - 4) != chksum) { |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4241 | asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM; |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 4242 | release_firmware(fw); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4243 | return warn_code; |
| 4244 | } |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 4245 | release_firmware(fw); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4246 | warn_code |= AscInitMicroCodeVar(asc_dvc); |
Herton Ronaldo Krzesinski | 9a908c1 | 2010-03-30 13:35:38 -0300 | [diff] [blame] | 4247 | if (!asc_dvc->overrun_dma) |
| 4248 | return warn_code; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4249 | asc_dvc->init_state |= ASC_INIT_STATE_END_LOAD_MC; |
| 4250 | AscEnableInterrupt(iop_base); |
| 4251 | return warn_code; |
Matthew Wilcox | a9f4a59 | 2007-09-09 08:56:27 -0600 | [diff] [blame] | 4252 | } |
| 4253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4254 | /* |
Matthew Wilcox | b9d9661 | 2007-09-09 08:56:28 -0600 | [diff] [blame] | 4255 | * Load the Microcode |
| 4256 | * |
| 4257 | * Write the microcode image to RISC memory starting at address 0. |
| 4258 | * |
| 4259 | * The microcode is stored compressed in the following format: |
| 4260 | * |
| 4261 | * 254 word (508 byte) table indexed by byte code followed |
| 4262 | * by the following byte codes: |
| 4263 | * |
| 4264 | * 1-Byte Code: |
| 4265 | * 00: Emit word 0 in table. |
| 4266 | * 01: Emit word 1 in table. |
| 4267 | * . |
| 4268 | * FD: Emit word 253 in table. |
| 4269 | * |
| 4270 | * Multi-Byte Code: |
| 4271 | * FE WW WW: (3 byte code) Word to emit is the next word WW WW. |
| 4272 | * FF BB WW WW: (4 byte code) Emit BB count times next word WW WW. |
| 4273 | * |
| 4274 | * Returns 0 or an error if the checksum doesn't match |
| 4275 | */ |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 4276 | static int AdvLoadMicrocode(AdvPortAddr iop_base, const unsigned char *buf, |
| 4277 | int size, int memsize, int chksum) |
Matthew Wilcox | b9d9661 | 2007-09-09 08:56:28 -0600 | [diff] [blame] | 4278 | { |
| 4279 | int i, j, end, len = 0; |
| 4280 | ADV_DCNT sum; |
| 4281 | |
| 4282 | AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0); |
| 4283 | |
| 4284 | for (i = 253 * 2; i < size; i++) { |
| 4285 | if (buf[i] == 0xff) { |
| 4286 | unsigned short word = (buf[i + 3] << 8) | buf[i + 2]; |
| 4287 | for (j = 0; j < buf[i + 1]; j++) { |
| 4288 | AdvWriteWordAutoIncLram(iop_base, word); |
| 4289 | len += 2; |
| 4290 | } |
| 4291 | i += 3; |
| 4292 | } else if (buf[i] == 0xfe) { |
| 4293 | unsigned short word = (buf[i + 2] << 8) | buf[i + 1]; |
| 4294 | AdvWriteWordAutoIncLram(iop_base, word); |
| 4295 | i += 2; |
| 4296 | len += 2; |
| 4297 | } else { |
Matthew Wilcox | 951b62c | 2007-10-05 15:57:06 -0400 | [diff] [blame] | 4298 | unsigned int off = buf[i] * 2; |
Matthew Wilcox | b9d9661 | 2007-09-09 08:56:28 -0600 | [diff] [blame] | 4299 | unsigned short word = (buf[off + 1] << 8) | buf[off]; |
| 4300 | AdvWriteWordAutoIncLram(iop_base, word); |
| 4301 | len += 2; |
| 4302 | } |
| 4303 | } |
| 4304 | |
| 4305 | end = len; |
| 4306 | |
| 4307 | while (len < memsize) { |
| 4308 | AdvWriteWordAutoIncLram(iop_base, 0); |
| 4309 | len += 2; |
| 4310 | } |
| 4311 | |
| 4312 | /* Verify the microcode checksum. */ |
| 4313 | sum = 0; |
| 4314 | AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0); |
| 4315 | |
| 4316 | for (len = 0; len < end; len += 2) { |
| 4317 | sum += AdvReadWordAutoIncLram(iop_base); |
| 4318 | } |
| 4319 | |
| 4320 | if (sum != chksum) |
| 4321 | return ASC_IERR_MCODE_CHKSUM; |
| 4322 | |
| 4323 | return 0; |
| 4324 | } |
| 4325 | |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 4326 | static void AdvBuildCarrierFreelist(struct adv_dvc_var *adv_dvc) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4327 | { |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 4328 | off_t carr_offset = 0, next_offset; |
| 4329 | dma_addr_t carr_paddr; |
| 4330 | int carr_num = ADV_CARRIER_BUFSIZE / sizeof(ADV_CARR_T), i; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4331 | |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 4332 | for (i = 0; i < carr_num; i++) { |
| 4333 | carr_offset = i * sizeof(ADV_CARR_T); |
| 4334 | /* Get physical address of the carrier 'carrp'. */ |
| 4335 | carr_paddr = adv_dvc->carrier_addr + carr_offset; |
| 4336 | |
| 4337 | adv_dvc->carrier[i].carr_pa = cpu_to_le32(carr_paddr); |
| 4338 | adv_dvc->carrier[i].carr_va = cpu_to_le32(carr_offset); |
| 4339 | adv_dvc->carrier[i].areq_vpa = 0; |
| 4340 | next_offset = carr_offset + sizeof(ADV_CARR_T); |
| 4341 | if (i == carr_num) |
| 4342 | next_offset = ~0; |
| 4343 | adv_dvc->carrier[i].next_vpa = cpu_to_le32(next_offset); |
| 4344 | } |
| 4345 | /* |
| 4346 | * We cannot have a carrier with 'carr_va' of '0', as |
| 4347 | * a reference to this carrier would be interpreted as |
| 4348 | * list termination. |
| 4349 | * So start at carrier 1 with the freelist. |
| 4350 | */ |
| 4351 | adv_dvc->carr_freelist = &adv_dvc->carrier[1]; |
| 4352 | } |
| 4353 | |
| 4354 | static ADV_CARR_T *adv_get_carrier(struct adv_dvc_var *adv_dvc, u32 offset) |
| 4355 | { |
| 4356 | int index; |
| 4357 | |
| 4358 | BUG_ON(offset > ADV_CARRIER_BUFSIZE); |
| 4359 | |
| 4360 | index = offset / sizeof(ADV_CARR_T); |
| 4361 | return &adv_dvc->carrier[index]; |
| 4362 | } |
| 4363 | |
| 4364 | static ADV_CARR_T *adv_get_next_carrier(struct adv_dvc_var *adv_dvc) |
| 4365 | { |
| 4366 | ADV_CARR_T *carrp = adv_dvc->carr_freelist; |
| 4367 | u32 next_vpa = le32_to_cpu(carrp->next_vpa); |
| 4368 | |
| 4369 | if (next_vpa == 0 || next_vpa == ~0) { |
| 4370 | ASC_DBG(1, "invalid vpa offset 0x%x\n", next_vpa); |
| 4371 | return NULL; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4372 | } |
| 4373 | |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 4374 | adv_dvc->carr_freelist = adv_get_carrier(adv_dvc, next_vpa); |
| 4375 | /* |
| 4376 | * insert stopper carrier to terminate list |
| 4377 | */ |
| 4378 | carrp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4379 | |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 4380 | return carrp; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4381 | } |
| 4382 | |
| 4383 | /* |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 4384 | * 'offset' is the index in the request pointer array |
| 4385 | */ |
| 4386 | static adv_req_t * adv_get_reqp(struct adv_dvc_var *adv_dvc, u32 offset) |
| 4387 | { |
| 4388 | struct asc_board *boardp = adv_dvc->drv_ptr; |
| 4389 | |
| 4390 | BUG_ON(offset > adv_dvc->max_host_qng); |
| 4391 | return &boardp->adv_reqp[offset]; |
| 4392 | } |
| 4393 | |
| 4394 | /* |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 4395 | * Send an idle command to the chip and wait for completion. |
| 4396 | * |
| 4397 | * Command completion is polled for once per microsecond. |
| 4398 | * |
| 4399 | * The function can be called from anywhere including an interrupt handler. |
| 4400 | * But the function is not re-entrant, so it uses the DvcEnter/LeaveCritical() |
| 4401 | * functions to prevent reentrancy. |
| 4402 | * |
| 4403 | * Return Values: |
| 4404 | * ADV_TRUE - command completed successfully |
| 4405 | * ADV_FALSE - command failed |
| 4406 | * ADV_ERROR - command timed out |
| 4407 | */ |
| 4408 | static int |
| 4409 | AdvSendIdleCmd(ADV_DVC_VAR *asc_dvc, |
| 4410 | ushort idle_cmd, ADV_DCNT idle_cmd_parameter) |
| 4411 | { |
| 4412 | int result; |
| 4413 | ADV_DCNT i, j; |
| 4414 | AdvPortAddr iop_base; |
| 4415 | |
| 4416 | iop_base = asc_dvc->iop_base; |
| 4417 | |
| 4418 | /* |
| 4419 | * Clear the idle command status which is set by the microcode |
| 4420 | * to a non-zero value to indicate when the command is completed. |
| 4421 | * The non-zero result is one of the IDLE_CMD_STATUS_* values |
| 4422 | */ |
| 4423 | AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS, (ushort)0); |
| 4424 | |
| 4425 | /* |
| 4426 | * Write the idle command value after the idle command parameter |
| 4427 | * has been written to avoid a race condition. If the order is not |
| 4428 | * followed, the microcode may process the idle command before the |
| 4429 | * parameters have been written to LRAM. |
| 4430 | */ |
| 4431 | AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IDLE_CMD_PARAMETER, |
| 4432 | cpu_to_le32(idle_cmd_parameter)); |
| 4433 | AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD, idle_cmd); |
| 4434 | |
| 4435 | /* |
| 4436 | * Tickle the RISC to tell it to process the idle command. |
| 4437 | */ |
| 4438 | AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_B); |
| 4439 | if (asc_dvc->chip_type == ADV_CHIP_ASC3550) { |
| 4440 | /* |
| 4441 | * Clear the tickle value. In the ASC-3550 the RISC flag |
| 4442 | * command 'clr_tickle_b' does not work unless the host |
| 4443 | * value is cleared. |
| 4444 | */ |
| 4445 | AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_NOP); |
| 4446 | } |
| 4447 | |
| 4448 | /* Wait for up to 100 millisecond for the idle command to timeout. */ |
| 4449 | for (i = 0; i < SCSI_WAIT_100_MSEC; i++) { |
| 4450 | /* Poll once each microsecond for command completion. */ |
| 4451 | for (j = 0; j < SCSI_US_PER_MSEC; j++) { |
| 4452 | AdvReadWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS, |
| 4453 | result); |
| 4454 | if (result != 0) |
| 4455 | return result; |
| 4456 | udelay(1); |
| 4457 | } |
| 4458 | } |
| 4459 | |
| 4460 | BUG(); /* The idle command should never timeout. */ |
| 4461 | return ADV_ERROR; |
| 4462 | } |
| 4463 | |
| 4464 | /* |
| 4465 | * Reset SCSI Bus and purge all outstanding requests. |
| 4466 | * |
| 4467 | * Return Value: |
| 4468 | * ADV_TRUE(1) - All requests are purged and SCSI Bus is reset. |
| 4469 | * ADV_FALSE(0) - Microcode command failed. |
| 4470 | * ADV_ERROR(-1) - Microcode command timed-out. Microcode or IC |
| 4471 | * may be hung which requires driver recovery. |
| 4472 | */ |
| 4473 | static int AdvResetSB(ADV_DVC_VAR *asc_dvc) |
| 4474 | { |
| 4475 | int status; |
| 4476 | |
| 4477 | /* |
| 4478 | * Send the SCSI Bus Reset idle start idle command which asserts |
| 4479 | * the SCSI Bus Reset signal. |
| 4480 | */ |
| 4481 | status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_START, 0L); |
| 4482 | if (status != ADV_TRUE) { |
| 4483 | return status; |
| 4484 | } |
| 4485 | |
| 4486 | /* |
| 4487 | * Delay for the specified SCSI Bus Reset hold time. |
| 4488 | * |
| 4489 | * The hold time delay is done on the host because the RISC has no |
| 4490 | * microsecond accurate timer. |
| 4491 | */ |
| 4492 | udelay(ASC_SCSI_RESET_HOLD_TIME_US); |
| 4493 | |
| 4494 | /* |
| 4495 | * Send the SCSI Bus Reset end idle command which de-asserts |
| 4496 | * the SCSI Bus Reset signal and purges any pending requests. |
| 4497 | */ |
| 4498 | status = AdvSendIdleCmd(asc_dvc, (ushort)IDLE_CMD_SCSI_RESET_END, 0L); |
| 4499 | if (status != ADV_TRUE) { |
| 4500 | return status; |
| 4501 | } |
| 4502 | |
| 4503 | mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */ |
| 4504 | |
| 4505 | return status; |
| 4506 | } |
| 4507 | |
| 4508 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4509 | * Initialize the ASC-3550. |
| 4510 | * |
| 4511 | * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR. |
| 4512 | * |
| 4513 | * For a non-fatal error return a warning code. If there are no warnings |
| 4514 | * then 0 is returned. |
| 4515 | * |
| 4516 | * Needed after initialization for error recovery. |
| 4517 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4518 | static int AdvInitAsc3550Driver(ADV_DVC_VAR *asc_dvc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4519 | { |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 4520 | const struct firmware *fw; |
| 4521 | const char fwname[] = "advansys/3550.bin"; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4522 | AdvPortAddr iop_base; |
| 4523 | ushort warn_code; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4524 | int begin_addr; |
| 4525 | int end_addr; |
| 4526 | ushort code_sum; |
| 4527 | int word; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4528 | int i; |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 4529 | int err; |
| 4530 | unsigned long chksum; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4531 | ushort scsi_cfg1; |
| 4532 | uchar tid; |
| 4533 | ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */ |
| 4534 | ushort wdtr_able = 0, sdtr_able, tagqng_able; |
| 4535 | uchar max_cmd[ADV_MAX_TID + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4537 | /* If there is already an error, don't continue. */ |
Matthew Wilcox | b9d9661 | 2007-09-09 08:56:28 -0600 | [diff] [blame] | 4538 | if (asc_dvc->err_code != 0) |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4539 | return ADV_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4540 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4541 | /* |
| 4542 | * The caller must set 'chip_type' to ADV_CHIP_ASC3550. |
| 4543 | */ |
| 4544 | if (asc_dvc->chip_type != ADV_CHIP_ASC3550) { |
Matthew Wilcox | b9d9661 | 2007-09-09 08:56:28 -0600 | [diff] [blame] | 4545 | asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4546 | return ADV_ERROR; |
| 4547 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4548 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4549 | warn_code = 0; |
| 4550 | iop_base = asc_dvc->iop_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4551 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4552 | /* |
| 4553 | * Save the RISC memory BIOS region before writing the microcode. |
| 4554 | * The BIOS may already be loaded and using its RISC LRAM region |
| 4555 | * so its region must be saved and restored. |
| 4556 | * |
| 4557 | * Note: This code makes the assumption, which is currently true, |
| 4558 | * that a chip reset does not clear RISC LRAM. |
| 4559 | */ |
| 4560 | for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) { |
| 4561 | AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), |
| 4562 | bios_mem[i]); |
| 4563 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4564 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4565 | /* |
| 4566 | * Save current per TID negotiated values. |
| 4567 | */ |
| 4568 | if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] == 0x55AA) { |
| 4569 | ushort bios_version, major, minor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4570 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4571 | bios_version = |
| 4572 | bios_mem[(ASC_MC_BIOS_VERSION - ASC_MC_BIOSMEM) / 2]; |
| 4573 | major = (bios_version >> 12) & 0xF; |
| 4574 | minor = (bios_version >> 8) & 0xF; |
| 4575 | if (major < 3 || (major == 3 && minor == 1)) { |
| 4576 | /* BIOS 3.1 and earlier location of 'wdtr_able' variable. */ |
| 4577 | AdvReadWordLram(iop_base, 0x120, wdtr_able); |
| 4578 | } else { |
| 4579 | AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able); |
| 4580 | } |
| 4581 | } |
| 4582 | AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able); |
| 4583 | AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able); |
| 4584 | for (tid = 0; tid <= ADV_MAX_TID; tid++) { |
| 4585 | AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid, |
| 4586 | max_cmd[tid]); |
| 4587 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4588 | |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 4589 | err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev); |
| 4590 | if (err) { |
| 4591 | printk(KERN_ERR "Failed to load image \"%s\" err %d\n", |
| 4592 | fwname, err); |
Herton Ronaldo Krzesinski | cf74744 | 2010-03-19 19:37:26 -0300 | [diff] [blame] | 4593 | asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM; |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 4594 | return err; |
| 4595 | } |
| 4596 | if (fw->size < 4) { |
| 4597 | printk(KERN_ERR "Bogus length %zu in image \"%s\"\n", |
| 4598 | fw->size, fwname); |
| 4599 | release_firmware(fw); |
Herton Ronaldo Krzesinski | cf74744 | 2010-03-19 19:37:26 -0300 | [diff] [blame] | 4600 | asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM; |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 4601 | return -EINVAL; |
| 4602 | } |
| 4603 | chksum = (fw->data[3] << 24) | (fw->data[2] << 16) | |
| 4604 | (fw->data[1] << 8) | fw->data[0]; |
| 4605 | asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4], |
| 4606 | fw->size - 4, ADV_3550_MEMSIZE, |
| 4607 | chksum); |
| 4608 | release_firmware(fw); |
Matthew Wilcox | b9d9661 | 2007-09-09 08:56:28 -0600 | [diff] [blame] | 4609 | if (asc_dvc->err_code) |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4610 | return ADV_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4611 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4612 | /* |
| 4613 | * Restore the RISC memory BIOS region. |
| 4614 | */ |
| 4615 | for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) { |
| 4616 | AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), |
| 4617 | bios_mem[i]); |
| 4618 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4619 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4620 | /* |
| 4621 | * Calculate and write the microcode code checksum to the microcode |
| 4622 | * code checksum location ASC_MC_CODE_CHK_SUM (0x2C). |
| 4623 | */ |
| 4624 | AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr); |
| 4625 | AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr); |
| 4626 | code_sum = 0; |
| 4627 | AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr); |
| 4628 | for (word = begin_addr; word < end_addr; word += 2) { |
| 4629 | code_sum += AdvReadWordAutoIncLram(iop_base); |
| 4630 | } |
| 4631 | AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4632 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4633 | /* |
| 4634 | * Read and save microcode version and date. |
| 4635 | */ |
| 4636 | AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE, |
| 4637 | asc_dvc->cfg->mcode_date); |
| 4638 | AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM, |
| 4639 | asc_dvc->cfg->mcode_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4640 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4641 | /* |
| 4642 | * Set the chip type to indicate the ASC3550. |
| 4643 | */ |
| 4644 | AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC3550); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4645 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4646 | /* |
| 4647 | * If the PCI Configuration Command Register "Parity Error Response |
| 4648 | * Control" Bit was clear (0), then set the microcode variable |
| 4649 | * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode |
| 4650 | * to ignore DMA parity errors. |
| 4651 | */ |
| 4652 | if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) { |
| 4653 | AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word); |
| 4654 | word |= CONTROL_FLAG_IGNORE_PERR; |
| 4655 | AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word); |
| 4656 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4657 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4658 | /* |
| 4659 | * For ASC-3550, setting the START_CTL_EMFU [3:2] bits sets a FIFO |
| 4660 | * threshold of 128 bytes. This register is only accessible to the host. |
| 4661 | */ |
| 4662 | AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0, |
| 4663 | START_CTL_EMFU | READ_CMD_MRM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4664 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4665 | /* |
| 4666 | * Microcode operating variables for WDTR, SDTR, and command tag |
Matthew Wilcox | 47d853c | 2007-07-26 11:41:33 -0400 | [diff] [blame] | 4667 | * queuing will be set in slave_configure() based on what a |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4668 | * device reports it is capable of in Inquiry byte 7. |
| 4669 | * |
| 4670 | * If SCSI Bus Resets have been disabled, then directly set |
| 4671 | * SDTR and WDTR from the EEPROM configuration. This will allow |
| 4672 | * the BIOS and warm boot to work without a SCSI bus hang on |
| 4673 | * the Inquiry caused by host and target mismatched DTR values. |
| 4674 | * Without the SCSI Bus Reset, before an Inquiry a device can't |
| 4675 | * be assumed to be in Asynchronous, Narrow mode. |
| 4676 | */ |
| 4677 | if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) { |
| 4678 | AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, |
| 4679 | asc_dvc->wdtr_able); |
| 4680 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, |
| 4681 | asc_dvc->sdtr_able); |
| 4682 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4683 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4684 | /* |
| 4685 | * Set microcode operating variables for SDTR_SPEED1, SDTR_SPEED2, |
| 4686 | * SDTR_SPEED3, and SDTR_SPEED4 based on the ULTRA EEPROM per TID |
| 4687 | * bitmask. These values determine the maximum SDTR speed negotiated |
| 4688 | * with a device. |
| 4689 | * |
| 4690 | * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2, |
| 4691 | * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them |
| 4692 | * without determining here whether the device supports SDTR. |
| 4693 | * |
| 4694 | * 4-bit speed SDTR speed name |
| 4695 | * =========== =============== |
| 4696 | * 0000b (0x0) SDTR disabled |
| 4697 | * 0001b (0x1) 5 Mhz |
| 4698 | * 0010b (0x2) 10 Mhz |
| 4699 | * 0011b (0x3) 20 Mhz (Ultra) |
| 4700 | * 0100b (0x4) 40 Mhz (LVD/Ultra2) |
| 4701 | * 0101b (0x5) 80 Mhz (LVD2/Ultra3) |
| 4702 | * 0110b (0x6) Undefined |
| 4703 | * . |
| 4704 | * 1111b (0xF) Undefined |
| 4705 | */ |
| 4706 | word = 0; |
| 4707 | for (tid = 0; tid <= ADV_MAX_TID; tid++) { |
| 4708 | if (ADV_TID_TO_TIDMASK(tid) & asc_dvc->ultra_able) { |
| 4709 | /* Set Ultra speed for TID 'tid'. */ |
| 4710 | word |= (0x3 << (4 * (tid % 4))); |
| 4711 | } else { |
| 4712 | /* Set Fast speed for TID 'tid'. */ |
| 4713 | word |= (0x2 << (4 * (tid % 4))); |
| 4714 | } |
| 4715 | if (tid == 3) { /* Check if done with sdtr_speed1. */ |
| 4716 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, word); |
| 4717 | word = 0; |
| 4718 | } else if (tid == 7) { /* Check if done with sdtr_speed2. */ |
| 4719 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, word); |
| 4720 | word = 0; |
| 4721 | } else if (tid == 11) { /* Check if done with sdtr_speed3. */ |
| 4722 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, word); |
| 4723 | word = 0; |
| 4724 | } else if (tid == 15) { /* Check if done with sdtr_speed4. */ |
| 4725 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, word); |
| 4726 | /* End of loop. */ |
| 4727 | } |
| 4728 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4729 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4730 | /* |
| 4731 | * Set microcode operating variable for the disconnect per TID bitmask. |
| 4732 | */ |
| 4733 | AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE, |
| 4734 | asc_dvc->cfg->disc_enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4735 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4736 | /* |
| 4737 | * Set SCSI_CFG0 Microcode Default Value. |
| 4738 | * |
| 4739 | * The microcode will set the SCSI_CFG0 register using this value |
| 4740 | * after it is started below. |
| 4741 | */ |
| 4742 | AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0, |
| 4743 | PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN | |
| 4744 | asc_dvc->chip_scsi_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4745 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4746 | /* |
| 4747 | * Determine SCSI_CFG1 Microcode Default Value. |
| 4748 | * |
| 4749 | * The microcode will set the SCSI_CFG1 register using this value |
| 4750 | * after it is started below. |
| 4751 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4752 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4753 | /* Read current SCSI_CFG1 Register value. */ |
| 4754 | scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4755 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4756 | /* |
| 4757 | * If all three connectors are in use, return an error. |
| 4758 | */ |
| 4759 | if ((scsi_cfg1 & CABLE_ILLEGAL_A) == 0 || |
| 4760 | (scsi_cfg1 & CABLE_ILLEGAL_B) == 0) { |
| 4761 | asc_dvc->err_code |= ASC_IERR_ILLEGAL_CONNECTION; |
| 4762 | return ADV_ERROR; |
| 4763 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4764 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4765 | /* |
| 4766 | * If the internal narrow cable is reversed all of the SCSI_CTRL |
| 4767 | * register signals will be set. Check for and return an error if |
| 4768 | * this condition is found. |
| 4769 | */ |
| 4770 | if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) { |
| 4771 | asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE; |
| 4772 | return ADV_ERROR; |
| 4773 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4774 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4775 | /* |
| 4776 | * If this is a differential board and a single-ended device |
| 4777 | * is attached to one of the connectors, return an error. |
| 4778 | */ |
| 4779 | if ((scsi_cfg1 & DIFF_MODE) && (scsi_cfg1 & DIFF_SENSE) == 0) { |
| 4780 | asc_dvc->err_code |= ASC_IERR_SINGLE_END_DEVICE; |
| 4781 | return ADV_ERROR; |
| 4782 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4783 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4784 | /* |
| 4785 | * If automatic termination control is enabled, then set the |
| 4786 | * termination value based on a table listed in a_condor.h. |
| 4787 | * |
| 4788 | * If manual termination was specified with an EEPROM setting |
| 4789 | * then 'termination' was set-up in AdvInitFrom3550EEPROM() and |
| 4790 | * is ready to be 'ored' into SCSI_CFG1. |
| 4791 | */ |
| 4792 | if (asc_dvc->cfg->termination == 0) { |
| 4793 | /* |
| 4794 | * The software always controls termination by setting TERM_CTL_SEL. |
| 4795 | * If TERM_CTL_SEL were set to 0, the hardware would set termination. |
| 4796 | */ |
| 4797 | asc_dvc->cfg->termination |= TERM_CTL_SEL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4798 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4799 | switch (scsi_cfg1 & CABLE_DETECT) { |
| 4800 | /* TERM_CTL_H: on, TERM_CTL_L: on */ |
| 4801 | case 0x3: |
| 4802 | case 0x7: |
| 4803 | case 0xB: |
| 4804 | case 0xD: |
| 4805 | case 0xE: |
| 4806 | case 0xF: |
| 4807 | asc_dvc->cfg->termination |= (TERM_CTL_H | TERM_CTL_L); |
| 4808 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4809 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4810 | /* TERM_CTL_H: on, TERM_CTL_L: off */ |
| 4811 | case 0x1: |
| 4812 | case 0x5: |
| 4813 | case 0x9: |
| 4814 | case 0xA: |
| 4815 | case 0xC: |
| 4816 | asc_dvc->cfg->termination |= TERM_CTL_H; |
| 4817 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4818 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4819 | /* TERM_CTL_H: off, TERM_CTL_L: off */ |
| 4820 | case 0x2: |
| 4821 | case 0x6: |
| 4822 | break; |
| 4823 | } |
| 4824 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4825 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4826 | /* |
| 4827 | * Clear any set TERM_CTL_H and TERM_CTL_L bits. |
| 4828 | */ |
| 4829 | scsi_cfg1 &= ~TERM_CTL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4830 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4831 | /* |
| 4832 | * Invert the TERM_CTL_H and TERM_CTL_L bits and then |
| 4833 | * set 'scsi_cfg1'. The TERM_POL bit does not need to be |
| 4834 | * referenced, because the hardware internally inverts |
| 4835 | * the Termination High and Low bits if TERM_POL is set. |
| 4836 | */ |
| 4837 | scsi_cfg1 |= (TERM_CTL_SEL | (~asc_dvc->cfg->termination & TERM_CTL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4838 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4839 | /* |
| 4840 | * Set SCSI_CFG1 Microcode Default Value |
| 4841 | * |
| 4842 | * Set filter value and possibly modified termination control |
| 4843 | * bits in the Microcode SCSI_CFG1 Register Value. |
| 4844 | * |
| 4845 | * The microcode will set the SCSI_CFG1 register using this value |
| 4846 | * after it is started below. |
| 4847 | */ |
| 4848 | AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, |
| 4849 | FLTR_DISABLE | scsi_cfg1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4850 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4851 | /* |
| 4852 | * Set MEM_CFG Microcode Default Value |
| 4853 | * |
| 4854 | * The microcode will set the MEM_CFG register using this value |
| 4855 | * after it is started below. |
| 4856 | * |
| 4857 | * MEM_CFG may be accessed as a word or byte, but only bits 0-7 |
| 4858 | * are defined. |
| 4859 | * |
| 4860 | * ASC-3550 has 8KB internal memory. |
| 4861 | */ |
| 4862 | AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG, |
| 4863 | BIOS_EN | RAM_SZ_8KB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4864 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4865 | /* |
| 4866 | * Set SEL_MASK Microcode Default Value |
| 4867 | * |
| 4868 | * The microcode will set the SEL_MASK register using this value |
| 4869 | * after it is started below. |
| 4870 | */ |
| 4871 | AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK, |
| 4872 | ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4873 | |
Matthew Wilcox | a9f4a59 | 2007-09-09 08:56:27 -0600 | [diff] [blame] | 4874 | AdvBuildCarrierFreelist(asc_dvc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4875 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4876 | /* |
| 4877 | * Set-up the Host->RISC Initiator Command Queue (ICQ). |
| 4878 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4879 | |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 4880 | asc_dvc->icq_sp = adv_get_next_carrier(asc_dvc); |
| 4881 | if (!asc_dvc->icq_sp) { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4882 | asc_dvc->err_code |= ASC_IERR_NO_CARRIER; |
| 4883 | return ADV_ERROR; |
| 4884 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4885 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4886 | /* |
| 4887 | * Set RISC ICQ physical address start value. |
| 4888 | */ |
| 4889 | AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4890 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4891 | /* |
| 4892 | * Set-up the RISC->Host Initiator Response Queue (IRQ). |
| 4893 | */ |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 4894 | asc_dvc->irq_sp = adv_get_next_carrier(asc_dvc); |
| 4895 | if (!asc_dvc->irq_sp) { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4896 | asc_dvc->err_code |= ASC_IERR_NO_CARRIER; |
| 4897 | return ADV_ERROR; |
| 4898 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4899 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4900 | /* |
| 4901 | * Set RISC IRQ physical address start value. |
| 4902 | */ |
| 4903 | AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa); |
| 4904 | asc_dvc->carr_pending_cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4905 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4906 | AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES, |
| 4907 | (ADV_INTR_ENABLE_HOST_INTR | |
| 4908 | ADV_INTR_ENABLE_GLOBAL_INTR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4909 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4910 | AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word); |
| 4911 | AdvWriteWordRegister(iop_base, IOPW_PC, word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4912 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4913 | /* finally, finally, gentlemen, start your engine */ |
| 4914 | AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4915 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4916 | /* |
| 4917 | * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus |
| 4918 | * Resets should be performed. The RISC has to be running |
| 4919 | * to issue a SCSI Bus Reset. |
| 4920 | */ |
| 4921 | if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) { |
| 4922 | /* |
| 4923 | * If the BIOS Signature is present in memory, restore the |
| 4924 | * BIOS Handshake Configuration Table and do not perform |
| 4925 | * a SCSI Bus Reset. |
| 4926 | */ |
| 4927 | if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] == |
| 4928 | 0x55AA) { |
| 4929 | /* |
| 4930 | * Restore per TID negotiated values. |
| 4931 | */ |
| 4932 | AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able); |
| 4933 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able); |
| 4934 | AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, |
| 4935 | tagqng_able); |
| 4936 | for (tid = 0; tid <= ADV_MAX_TID; tid++) { |
| 4937 | AdvWriteByteLram(iop_base, |
| 4938 | ASC_MC_NUMBER_OF_MAX_CMD + tid, |
| 4939 | max_cmd[tid]); |
| 4940 | } |
| 4941 | } else { |
| 4942 | if (AdvResetSB(asc_dvc) != ADV_TRUE) { |
| 4943 | warn_code = ASC_WARN_BUSRESET_ERROR; |
| 4944 | } |
| 4945 | } |
| 4946 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4947 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4948 | return warn_code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4949 | } |
| 4950 | |
| 4951 | /* |
| 4952 | * Initialize the ASC-38C0800. |
| 4953 | * |
| 4954 | * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR. |
| 4955 | * |
| 4956 | * For a non-fatal error return a warning code. If there are no warnings |
| 4957 | * then 0 is returned. |
| 4958 | * |
| 4959 | * Needed after initialization for error recovery. |
| 4960 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4961 | static int AdvInitAsc38C0800Driver(ADV_DVC_VAR *asc_dvc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4962 | { |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 4963 | const struct firmware *fw; |
| 4964 | const char fwname[] = "advansys/38C0800.bin"; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4965 | AdvPortAddr iop_base; |
| 4966 | ushort warn_code; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4967 | int begin_addr; |
| 4968 | int end_addr; |
| 4969 | ushort code_sum; |
| 4970 | int word; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4971 | int i; |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 4972 | int err; |
| 4973 | unsigned long chksum; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4974 | ushort scsi_cfg1; |
| 4975 | uchar byte; |
| 4976 | uchar tid; |
| 4977 | ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */ |
| 4978 | ushort wdtr_able, sdtr_able, tagqng_able; |
| 4979 | uchar max_cmd[ADV_MAX_TID + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4980 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4981 | /* If there is already an error, don't continue. */ |
Matthew Wilcox | b9d9661 | 2007-09-09 08:56:28 -0600 | [diff] [blame] | 4982 | if (asc_dvc->err_code != 0) |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4983 | return ADV_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4984 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4985 | /* |
| 4986 | * The caller must set 'chip_type' to ADV_CHIP_ASC38C0800. |
| 4987 | */ |
| 4988 | if (asc_dvc->chip_type != ADV_CHIP_ASC38C0800) { |
| 4989 | asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE; |
| 4990 | return ADV_ERROR; |
| 4991 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4992 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4993 | warn_code = 0; |
| 4994 | iop_base = asc_dvc->iop_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4995 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 4996 | /* |
| 4997 | * Save the RISC memory BIOS region before writing the microcode. |
| 4998 | * The BIOS may already be loaded and using its RISC LRAM region |
| 4999 | * so its region must be saved and restored. |
| 5000 | * |
| 5001 | * Note: This code makes the assumption, which is currently true, |
| 5002 | * that a chip reset does not clear RISC LRAM. |
| 5003 | */ |
| 5004 | for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) { |
| 5005 | AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), |
| 5006 | bios_mem[i]); |
| 5007 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5008 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5009 | /* |
| 5010 | * Save current per TID negotiated values. |
| 5011 | */ |
| 5012 | AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able); |
| 5013 | AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able); |
| 5014 | AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able); |
| 5015 | for (tid = 0; tid <= ADV_MAX_TID; tid++) { |
| 5016 | AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid, |
| 5017 | max_cmd[tid]); |
| 5018 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5019 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5020 | /* |
| 5021 | * RAM BIST (RAM Built-In Self Test) |
| 5022 | * |
| 5023 | * Address : I/O base + offset 0x38h register (byte). |
| 5024 | * Function: Bit 7-6(RW) : RAM mode |
| 5025 | * Normal Mode : 0x00 |
| 5026 | * Pre-test Mode : 0x40 |
| 5027 | * RAM Test Mode : 0x80 |
| 5028 | * Bit 5 : unused |
| 5029 | * Bit 4(RO) : Done bit |
| 5030 | * Bit 3-0(RO) : Status |
| 5031 | * Host Error : 0x08 |
| 5032 | * Int_RAM Error : 0x04 |
| 5033 | * RISC Error : 0x02 |
| 5034 | * SCSI Error : 0x01 |
| 5035 | * No Error : 0x00 |
| 5036 | * |
| 5037 | * Note: RAM BIST code should be put right here, before loading the |
| 5038 | * microcode and after saving the RISC memory BIOS region. |
| 5039 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5040 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5041 | /* |
| 5042 | * LRAM Pre-test |
| 5043 | * |
| 5044 | * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds. |
| 5045 | * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return |
| 5046 | * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset |
| 5047 | * to NORMAL_MODE, return an error too. |
| 5048 | */ |
| 5049 | for (i = 0; i < 2; i++) { |
| 5050 | AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE); |
Matthew Wilcox | b009bef | 2007-09-09 08:56:38 -0600 | [diff] [blame] | 5051 | mdelay(10); /* Wait for 10ms before reading back. */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5052 | byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST); |
| 5053 | if ((byte & RAM_TEST_DONE) == 0 |
| 5054 | || (byte & 0x0F) != PRE_TEST_VALUE) { |
Matthew Wilcox | b9d9661 | 2007-09-09 08:56:28 -0600 | [diff] [blame] | 5055 | asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5056 | return ADV_ERROR; |
| 5057 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5058 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5059 | AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE); |
Matthew Wilcox | b009bef | 2007-09-09 08:56:38 -0600 | [diff] [blame] | 5060 | mdelay(10); /* Wait for 10ms before reading back. */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5061 | if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST) |
| 5062 | != NORMAL_VALUE) { |
Matthew Wilcox | b9d9661 | 2007-09-09 08:56:28 -0600 | [diff] [blame] | 5063 | asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5064 | return ADV_ERROR; |
| 5065 | } |
| 5066 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5067 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5068 | /* |
| 5069 | * LRAM Test - It takes about 1.5 ms to run through the test. |
| 5070 | * |
| 5071 | * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds. |
| 5072 | * If Done bit not set or Status not 0, save register byte, set the |
| 5073 | * err_code, and return an error. |
| 5074 | */ |
| 5075 | AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE); |
Matthew Wilcox | b009bef | 2007-09-09 08:56:38 -0600 | [diff] [blame] | 5076 | mdelay(10); /* Wait for 10ms before checking status. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5077 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5078 | byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST); |
| 5079 | if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) { |
| 5080 | /* Get here if Done bit not set or Status not 0. */ |
| 5081 | asc_dvc->bist_err_code = byte; /* for BIOS display message */ |
Matthew Wilcox | b9d9661 | 2007-09-09 08:56:28 -0600 | [diff] [blame] | 5082 | asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5083 | return ADV_ERROR; |
| 5084 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5085 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5086 | /* We need to reset back to normal mode after LRAM test passes. */ |
| 5087 | AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5088 | |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 5089 | err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev); |
| 5090 | if (err) { |
| 5091 | printk(KERN_ERR "Failed to load image \"%s\" err %d\n", |
| 5092 | fwname, err); |
Herton Ronaldo Krzesinski | cf74744 | 2010-03-19 19:37:26 -0300 | [diff] [blame] | 5093 | asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM; |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 5094 | return err; |
| 5095 | } |
| 5096 | if (fw->size < 4) { |
| 5097 | printk(KERN_ERR "Bogus length %zu in image \"%s\"\n", |
| 5098 | fw->size, fwname); |
| 5099 | release_firmware(fw); |
Herton Ronaldo Krzesinski | cf74744 | 2010-03-19 19:37:26 -0300 | [diff] [blame] | 5100 | asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM; |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 5101 | return -EINVAL; |
| 5102 | } |
| 5103 | chksum = (fw->data[3] << 24) | (fw->data[2] << 16) | |
| 5104 | (fw->data[1] << 8) | fw->data[0]; |
| 5105 | asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4], |
| 5106 | fw->size - 4, ADV_38C0800_MEMSIZE, |
| 5107 | chksum); |
| 5108 | release_firmware(fw); |
Matthew Wilcox | b9d9661 | 2007-09-09 08:56:28 -0600 | [diff] [blame] | 5109 | if (asc_dvc->err_code) |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5110 | return ADV_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5111 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5112 | /* |
| 5113 | * Restore the RISC memory BIOS region. |
| 5114 | */ |
| 5115 | for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) { |
| 5116 | AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), |
| 5117 | bios_mem[i]); |
| 5118 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5119 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5120 | /* |
| 5121 | * Calculate and write the microcode code checksum to the microcode |
| 5122 | * code checksum location ASC_MC_CODE_CHK_SUM (0x2C). |
| 5123 | */ |
| 5124 | AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr); |
| 5125 | AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr); |
| 5126 | code_sum = 0; |
| 5127 | AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr); |
| 5128 | for (word = begin_addr; word < end_addr; word += 2) { |
| 5129 | code_sum += AdvReadWordAutoIncLram(iop_base); |
| 5130 | } |
| 5131 | AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5132 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5133 | /* |
| 5134 | * Read microcode version and date. |
| 5135 | */ |
| 5136 | AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE, |
| 5137 | asc_dvc->cfg->mcode_date); |
| 5138 | AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM, |
| 5139 | asc_dvc->cfg->mcode_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5140 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5141 | /* |
| 5142 | * Set the chip type to indicate the ASC38C0800. |
| 5143 | */ |
| 5144 | AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C0800); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5145 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5146 | /* |
| 5147 | * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register. |
| 5148 | * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current |
| 5149 | * cable detection and then we are able to read C_DET[3:0]. |
| 5150 | * |
| 5151 | * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1 |
| 5152 | * Microcode Default Value' section below. |
| 5153 | */ |
| 5154 | scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1); |
| 5155 | AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1, |
| 5156 | scsi_cfg1 | DIS_TERM_DRV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5157 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5158 | /* |
| 5159 | * If the PCI Configuration Command Register "Parity Error Response |
| 5160 | * Control" Bit was clear (0), then set the microcode variable |
| 5161 | * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode |
| 5162 | * to ignore DMA parity errors. |
| 5163 | */ |
| 5164 | if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) { |
| 5165 | AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word); |
| 5166 | word |= CONTROL_FLAG_IGNORE_PERR; |
| 5167 | AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word); |
| 5168 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5169 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5170 | /* |
| 5171 | * For ASC-38C0800, set FIFO_THRESH_80B [6:4] bits and START_CTL_TH [3:2] |
| 5172 | * bits for the default FIFO threshold. |
| 5173 | * |
| 5174 | * Note: ASC-38C0800 FIFO threshold has been changed to 256 bytes. |
| 5175 | * |
| 5176 | * For DMA Errata #4 set the BC_THRESH_ENB bit. |
| 5177 | */ |
| 5178 | AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0, |
| 5179 | BC_THRESH_ENB | FIFO_THRESH_80B | START_CTL_TH | |
| 5180 | READ_CMD_MRM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5181 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5182 | /* |
| 5183 | * Microcode operating variables for WDTR, SDTR, and command tag |
Matthew Wilcox | 47d853c | 2007-07-26 11:41:33 -0400 | [diff] [blame] | 5184 | * queuing will be set in slave_configure() based on what a |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5185 | * device reports it is capable of in Inquiry byte 7. |
| 5186 | * |
| 5187 | * If SCSI Bus Resets have been disabled, then directly set |
| 5188 | * SDTR and WDTR from the EEPROM configuration. This will allow |
| 5189 | * the BIOS and warm boot to work without a SCSI bus hang on |
| 5190 | * the Inquiry caused by host and target mismatched DTR values. |
| 5191 | * Without the SCSI Bus Reset, before an Inquiry a device can't |
| 5192 | * be assumed to be in Asynchronous, Narrow mode. |
| 5193 | */ |
| 5194 | if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) { |
| 5195 | AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, |
| 5196 | asc_dvc->wdtr_able); |
| 5197 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, |
| 5198 | asc_dvc->sdtr_able); |
| 5199 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5200 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5201 | /* |
| 5202 | * Set microcode operating variables for DISC and SDTR_SPEED1, |
| 5203 | * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM |
| 5204 | * configuration values. |
| 5205 | * |
| 5206 | * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2, |
| 5207 | * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them |
| 5208 | * without determining here whether the device supports SDTR. |
| 5209 | */ |
| 5210 | AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE, |
| 5211 | asc_dvc->cfg->disc_enable); |
| 5212 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1); |
| 5213 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2); |
| 5214 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3); |
| 5215 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5216 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5217 | /* |
| 5218 | * Set SCSI_CFG0 Microcode Default Value. |
| 5219 | * |
| 5220 | * The microcode will set the SCSI_CFG0 register using this value |
| 5221 | * after it is started below. |
| 5222 | */ |
| 5223 | AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0, |
| 5224 | PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN | |
| 5225 | asc_dvc->chip_scsi_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5226 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5227 | /* |
| 5228 | * Determine SCSI_CFG1 Microcode Default Value. |
| 5229 | * |
| 5230 | * The microcode will set the SCSI_CFG1 register using this value |
| 5231 | * after it is started below. |
| 5232 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5233 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5234 | /* Read current SCSI_CFG1 Register value. */ |
| 5235 | scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5236 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5237 | /* |
| 5238 | * If the internal narrow cable is reversed all of the SCSI_CTRL |
| 5239 | * register signals will be set. Check for and return an error if |
| 5240 | * this condition is found. |
| 5241 | */ |
| 5242 | if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) { |
| 5243 | asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE; |
| 5244 | return ADV_ERROR; |
| 5245 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5246 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5247 | /* |
Matthew Wilcox | b9d9661 | 2007-09-09 08:56:28 -0600 | [diff] [blame] | 5248 | * All kind of combinations of devices attached to one of four |
| 5249 | * connectors are acceptable except HVD device attached. For example, |
| 5250 | * LVD device can be attached to SE connector while SE device attached |
| 5251 | * to LVD connector. If LVD device attached to SE connector, it only |
| 5252 | * runs up to Ultra speed. |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5253 | * |
Matthew Wilcox | b9d9661 | 2007-09-09 08:56:28 -0600 | [diff] [blame] | 5254 | * If an HVD device is attached to one of LVD connectors, return an |
| 5255 | * error. However, there is no way to detect HVD device attached to |
| 5256 | * SE connectors. |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5257 | */ |
| 5258 | if (scsi_cfg1 & HVD) { |
Matthew Wilcox | b9d9661 | 2007-09-09 08:56:28 -0600 | [diff] [blame] | 5259 | asc_dvc->err_code = ASC_IERR_HVD_DEVICE; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5260 | return ADV_ERROR; |
| 5261 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5262 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5263 | /* |
| 5264 | * If either SE or LVD automatic termination control is enabled, then |
| 5265 | * set the termination value based on a table listed in a_condor.h. |
| 5266 | * |
| 5267 | * If manual termination was specified with an EEPROM setting then |
Matthew Wilcox | b9d9661 | 2007-09-09 08:56:28 -0600 | [diff] [blame] | 5268 | * 'termination' was set-up in AdvInitFrom38C0800EEPROM() and is ready |
| 5269 | * to be 'ored' into SCSI_CFG1. |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5270 | */ |
| 5271 | if ((asc_dvc->cfg->termination & TERM_SE) == 0) { |
| 5272 | /* SE automatic termination control is enabled. */ |
| 5273 | switch (scsi_cfg1 & C_DET_SE) { |
| 5274 | /* TERM_SE_HI: on, TERM_SE_LO: on */ |
| 5275 | case 0x1: |
| 5276 | case 0x2: |
| 5277 | case 0x3: |
| 5278 | asc_dvc->cfg->termination |= TERM_SE; |
| 5279 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5280 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5281 | /* TERM_SE_HI: on, TERM_SE_LO: off */ |
| 5282 | case 0x0: |
| 5283 | asc_dvc->cfg->termination |= TERM_SE_HI; |
| 5284 | break; |
| 5285 | } |
| 5286 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5287 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5288 | if ((asc_dvc->cfg->termination & TERM_LVD) == 0) { |
| 5289 | /* LVD automatic termination control is enabled. */ |
| 5290 | switch (scsi_cfg1 & C_DET_LVD) { |
| 5291 | /* TERM_LVD_HI: on, TERM_LVD_LO: on */ |
| 5292 | case 0x4: |
| 5293 | case 0x8: |
| 5294 | case 0xC: |
| 5295 | asc_dvc->cfg->termination |= TERM_LVD; |
| 5296 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5297 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5298 | /* TERM_LVD_HI: off, TERM_LVD_LO: off */ |
| 5299 | case 0x0: |
| 5300 | break; |
| 5301 | } |
| 5302 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5303 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5304 | /* |
| 5305 | * Clear any set TERM_SE and TERM_LVD bits. |
| 5306 | */ |
| 5307 | scsi_cfg1 &= (~TERM_SE & ~TERM_LVD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5308 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5309 | /* |
| 5310 | * Invert the TERM_SE and TERM_LVD bits and then set 'scsi_cfg1'. |
| 5311 | */ |
| 5312 | scsi_cfg1 |= (~asc_dvc->cfg->termination & 0xF0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5313 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5314 | /* |
Matthew Wilcox | b9d9661 | 2007-09-09 08:56:28 -0600 | [diff] [blame] | 5315 | * Clear BIG_ENDIAN, DIS_TERM_DRV, Terminator Polarity and HVD/LVD/SE |
| 5316 | * bits and set possibly modified termination control bits in the |
| 5317 | * Microcode SCSI_CFG1 Register Value. |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5318 | */ |
| 5319 | scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL & ~HVD_LVD_SE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5320 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5321 | /* |
| 5322 | * Set SCSI_CFG1 Microcode Default Value |
| 5323 | * |
| 5324 | * Set possibly modified termination control and reset DIS_TERM_DRV |
| 5325 | * bits in the Microcode SCSI_CFG1 Register Value. |
| 5326 | * |
| 5327 | * The microcode will set the SCSI_CFG1 register using this value |
| 5328 | * after it is started below. |
| 5329 | */ |
| 5330 | AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5331 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5332 | /* |
| 5333 | * Set MEM_CFG Microcode Default Value |
| 5334 | * |
| 5335 | * The microcode will set the MEM_CFG register using this value |
| 5336 | * after it is started below. |
| 5337 | * |
| 5338 | * MEM_CFG may be accessed as a word or byte, but only bits 0-7 |
| 5339 | * are defined. |
| 5340 | * |
| 5341 | * ASC-38C0800 has 16KB internal memory. |
| 5342 | */ |
| 5343 | AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG, |
| 5344 | BIOS_EN | RAM_SZ_16KB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5345 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5346 | /* |
| 5347 | * Set SEL_MASK Microcode Default Value |
| 5348 | * |
| 5349 | * The microcode will set the SEL_MASK register using this value |
| 5350 | * after it is started below. |
| 5351 | */ |
| 5352 | AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK, |
| 5353 | ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5354 | |
Matthew Wilcox | a9f4a59 | 2007-09-09 08:56:27 -0600 | [diff] [blame] | 5355 | AdvBuildCarrierFreelist(asc_dvc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5356 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5357 | /* |
| 5358 | * Set-up the Host->RISC Initiator Command Queue (ICQ). |
| 5359 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5360 | |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 5361 | asc_dvc->icq_sp = adv_get_next_carrier(asc_dvc); |
| 5362 | if (!asc_dvc->icq_sp) { |
| 5363 | ASC_DBG(0, "Failed to get ICQ carrier\n"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5364 | asc_dvc->err_code |= ASC_IERR_NO_CARRIER; |
| 5365 | return ADV_ERROR; |
| 5366 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5367 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5368 | /* |
| 5369 | * Set RISC ICQ physical address start value. |
| 5370 | * carr_pa is LE, must be native before write |
| 5371 | */ |
| 5372 | AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5373 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5374 | /* |
| 5375 | * Set-up the RISC->Host Initiator Response Queue (IRQ). |
| 5376 | */ |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 5377 | asc_dvc->irq_sp = adv_get_next_carrier(asc_dvc); |
| 5378 | if (!asc_dvc->irq_sp) { |
| 5379 | ASC_DBG(0, "Failed to get IRQ carrier\n"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5380 | asc_dvc->err_code |= ASC_IERR_NO_CARRIER; |
| 5381 | return ADV_ERROR; |
| 5382 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5383 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5384 | /* |
| 5385 | * Set RISC IRQ physical address start value. |
| 5386 | * |
| 5387 | * carr_pa is LE, must be native before write * |
| 5388 | */ |
| 5389 | AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa); |
| 5390 | asc_dvc->carr_pending_cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5391 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5392 | AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES, |
| 5393 | (ADV_INTR_ENABLE_HOST_INTR | |
| 5394 | ADV_INTR_ENABLE_GLOBAL_INTR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5395 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5396 | AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word); |
| 5397 | AdvWriteWordRegister(iop_base, IOPW_PC, word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5398 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5399 | /* finally, finally, gentlemen, start your engine */ |
| 5400 | AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5401 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5402 | /* |
| 5403 | * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus |
| 5404 | * Resets should be performed. The RISC has to be running |
| 5405 | * to issue a SCSI Bus Reset. |
| 5406 | */ |
| 5407 | if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) { |
| 5408 | /* |
| 5409 | * If the BIOS Signature is present in memory, restore the |
| 5410 | * BIOS Handshake Configuration Table and do not perform |
| 5411 | * a SCSI Bus Reset. |
| 5412 | */ |
| 5413 | if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] == |
| 5414 | 0x55AA) { |
| 5415 | /* |
| 5416 | * Restore per TID negotiated values. |
| 5417 | */ |
| 5418 | AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able); |
| 5419 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able); |
| 5420 | AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, |
| 5421 | tagqng_able); |
| 5422 | for (tid = 0; tid <= ADV_MAX_TID; tid++) { |
| 5423 | AdvWriteByteLram(iop_base, |
| 5424 | ASC_MC_NUMBER_OF_MAX_CMD + tid, |
| 5425 | max_cmd[tid]); |
| 5426 | } |
| 5427 | } else { |
| 5428 | if (AdvResetSB(asc_dvc) != ADV_TRUE) { |
| 5429 | warn_code = ASC_WARN_BUSRESET_ERROR; |
| 5430 | } |
| 5431 | } |
| 5432 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5433 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5434 | return warn_code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5435 | } |
| 5436 | |
| 5437 | /* |
| 5438 | * Initialize the ASC-38C1600. |
| 5439 | * |
| 5440 | * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR. |
| 5441 | * |
| 5442 | * For a non-fatal error return a warning code. If there are no warnings |
| 5443 | * then 0 is returned. |
| 5444 | * |
| 5445 | * Needed after initialization for error recovery. |
| 5446 | */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5447 | static int AdvInitAsc38C1600Driver(ADV_DVC_VAR *asc_dvc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5448 | { |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 5449 | const struct firmware *fw; |
| 5450 | const char fwname[] = "advansys/38C1600.bin"; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5451 | AdvPortAddr iop_base; |
| 5452 | ushort warn_code; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5453 | int begin_addr; |
| 5454 | int end_addr; |
| 5455 | ushort code_sum; |
| 5456 | long word; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5457 | int i; |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 5458 | int err; |
| 5459 | unsigned long chksum; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5460 | ushort scsi_cfg1; |
| 5461 | uchar byte; |
| 5462 | uchar tid; |
| 5463 | ushort bios_mem[ASC_MC_BIOSLEN / 2]; /* BIOS RISC Memory 0x40-0x8F. */ |
| 5464 | ushort wdtr_able, sdtr_able, ppr_able, tagqng_able; |
| 5465 | uchar max_cmd[ASC_MAX_TID + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5466 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5467 | /* If there is already an error, don't continue. */ |
| 5468 | if (asc_dvc->err_code != 0) { |
| 5469 | return ADV_ERROR; |
| 5470 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5471 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5472 | /* |
| 5473 | * The caller must set 'chip_type' to ADV_CHIP_ASC38C1600. |
| 5474 | */ |
| 5475 | if (asc_dvc->chip_type != ADV_CHIP_ASC38C1600) { |
| 5476 | asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE; |
| 5477 | return ADV_ERROR; |
| 5478 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5479 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5480 | warn_code = 0; |
| 5481 | iop_base = asc_dvc->iop_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5482 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5483 | /* |
| 5484 | * Save the RISC memory BIOS region before writing the microcode. |
| 5485 | * The BIOS may already be loaded and using its RISC LRAM region |
| 5486 | * so its region must be saved and restored. |
| 5487 | * |
| 5488 | * Note: This code makes the assumption, which is currently true, |
| 5489 | * that a chip reset does not clear RISC LRAM. |
| 5490 | */ |
| 5491 | for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) { |
| 5492 | AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), |
| 5493 | bios_mem[i]); |
| 5494 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5495 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5496 | /* |
| 5497 | * Save current per TID negotiated values. |
| 5498 | */ |
| 5499 | AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able); |
| 5500 | AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able); |
| 5501 | AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able); |
| 5502 | AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able); |
| 5503 | for (tid = 0; tid <= ASC_MAX_TID; tid++) { |
| 5504 | AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid, |
| 5505 | max_cmd[tid]); |
| 5506 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5507 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5508 | /* |
| 5509 | * RAM BIST (Built-In Self Test) |
| 5510 | * |
| 5511 | * Address : I/O base + offset 0x38h register (byte). |
| 5512 | * Function: Bit 7-6(RW) : RAM mode |
| 5513 | * Normal Mode : 0x00 |
| 5514 | * Pre-test Mode : 0x40 |
| 5515 | * RAM Test Mode : 0x80 |
| 5516 | * Bit 5 : unused |
| 5517 | * Bit 4(RO) : Done bit |
| 5518 | * Bit 3-0(RO) : Status |
| 5519 | * Host Error : 0x08 |
| 5520 | * Int_RAM Error : 0x04 |
| 5521 | * RISC Error : 0x02 |
| 5522 | * SCSI Error : 0x01 |
| 5523 | * No Error : 0x00 |
| 5524 | * |
| 5525 | * Note: RAM BIST code should be put right here, before loading the |
| 5526 | * microcode and after saving the RISC memory BIOS region. |
| 5527 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5528 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5529 | /* |
| 5530 | * LRAM Pre-test |
| 5531 | * |
| 5532 | * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds. |
| 5533 | * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return |
| 5534 | * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset |
| 5535 | * to NORMAL_MODE, return an error too. |
| 5536 | */ |
| 5537 | for (i = 0; i < 2; i++) { |
| 5538 | AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE); |
Matthew Wilcox | b009bef | 2007-09-09 08:56:38 -0600 | [diff] [blame] | 5539 | mdelay(10); /* Wait for 10ms before reading back. */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5540 | byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST); |
| 5541 | if ((byte & RAM_TEST_DONE) == 0 |
| 5542 | || (byte & 0x0F) != PRE_TEST_VALUE) { |
Matthew Wilcox | b9d9661 | 2007-09-09 08:56:28 -0600 | [diff] [blame] | 5543 | asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5544 | return ADV_ERROR; |
| 5545 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5546 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5547 | AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE); |
Matthew Wilcox | b009bef | 2007-09-09 08:56:38 -0600 | [diff] [blame] | 5548 | mdelay(10); /* Wait for 10ms before reading back. */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5549 | if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST) |
| 5550 | != NORMAL_VALUE) { |
Matthew Wilcox | b9d9661 | 2007-09-09 08:56:28 -0600 | [diff] [blame] | 5551 | asc_dvc->err_code = ASC_IERR_BIST_PRE_TEST; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5552 | return ADV_ERROR; |
| 5553 | } |
| 5554 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5555 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5556 | /* |
| 5557 | * LRAM Test - It takes about 1.5 ms to run through the test. |
| 5558 | * |
| 5559 | * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds. |
| 5560 | * If Done bit not set or Status not 0, save register byte, set the |
| 5561 | * err_code, and return an error. |
| 5562 | */ |
| 5563 | AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE); |
Matthew Wilcox | b009bef | 2007-09-09 08:56:38 -0600 | [diff] [blame] | 5564 | mdelay(10); /* Wait for 10ms before checking status. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5565 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5566 | byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST); |
| 5567 | if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) { |
| 5568 | /* Get here if Done bit not set or Status not 0. */ |
| 5569 | asc_dvc->bist_err_code = byte; /* for BIOS display message */ |
Matthew Wilcox | b9d9661 | 2007-09-09 08:56:28 -0600 | [diff] [blame] | 5570 | asc_dvc->err_code = ASC_IERR_BIST_RAM_TEST; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5571 | return ADV_ERROR; |
| 5572 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5573 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5574 | /* We need to reset back to normal mode after LRAM test passes. */ |
| 5575 | AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5576 | |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 5577 | err = request_firmware(&fw, fwname, asc_dvc->drv_ptr->dev); |
| 5578 | if (err) { |
| 5579 | printk(KERN_ERR "Failed to load image \"%s\" err %d\n", |
| 5580 | fwname, err); |
Herton Ronaldo Krzesinski | cf74744 | 2010-03-19 19:37:26 -0300 | [diff] [blame] | 5581 | asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM; |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 5582 | return err; |
| 5583 | } |
| 5584 | if (fw->size < 4) { |
| 5585 | printk(KERN_ERR "Bogus length %zu in image \"%s\"\n", |
| 5586 | fw->size, fwname); |
| 5587 | release_firmware(fw); |
Herton Ronaldo Krzesinski | cf74744 | 2010-03-19 19:37:26 -0300 | [diff] [blame] | 5588 | asc_dvc->err_code = ASC_IERR_MCODE_CHKSUM; |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 5589 | return -EINVAL; |
| 5590 | } |
| 5591 | chksum = (fw->data[3] << 24) | (fw->data[2] << 16) | |
| 5592 | (fw->data[1] << 8) | fw->data[0]; |
| 5593 | asc_dvc->err_code = AdvLoadMicrocode(iop_base, &fw->data[4], |
| 5594 | fw->size - 4, ADV_38C1600_MEMSIZE, |
| 5595 | chksum); |
| 5596 | release_firmware(fw); |
Matthew Wilcox | b9d9661 | 2007-09-09 08:56:28 -0600 | [diff] [blame] | 5597 | if (asc_dvc->err_code) |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5598 | return ADV_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5599 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5600 | /* |
| 5601 | * Restore the RISC memory BIOS region. |
| 5602 | */ |
| 5603 | for (i = 0; i < ASC_MC_BIOSLEN / 2; i++) { |
| 5604 | AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), |
| 5605 | bios_mem[i]); |
| 5606 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5607 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5608 | /* |
| 5609 | * Calculate and write the microcode code checksum to the microcode |
| 5610 | * code checksum location ASC_MC_CODE_CHK_SUM (0x2C). |
| 5611 | */ |
| 5612 | AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr); |
| 5613 | AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr); |
| 5614 | code_sum = 0; |
| 5615 | AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr); |
| 5616 | for (word = begin_addr; word < end_addr; word += 2) { |
| 5617 | code_sum += AdvReadWordAutoIncLram(iop_base); |
| 5618 | } |
| 5619 | AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5620 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5621 | /* |
| 5622 | * Read microcode version and date. |
| 5623 | */ |
| 5624 | AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE, |
| 5625 | asc_dvc->cfg->mcode_date); |
| 5626 | AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM, |
| 5627 | asc_dvc->cfg->mcode_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5628 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5629 | /* |
| 5630 | * Set the chip type to indicate the ASC38C1600. |
| 5631 | */ |
| 5632 | AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C1600); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5633 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5634 | /* |
| 5635 | * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register. |
| 5636 | * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current |
| 5637 | * cable detection and then we are able to read C_DET[3:0]. |
| 5638 | * |
| 5639 | * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1 |
| 5640 | * Microcode Default Value' section below. |
| 5641 | */ |
| 5642 | scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1); |
| 5643 | AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1, |
| 5644 | scsi_cfg1 | DIS_TERM_DRV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5645 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5646 | /* |
| 5647 | * If the PCI Configuration Command Register "Parity Error Response |
| 5648 | * Control" Bit was clear (0), then set the microcode variable |
| 5649 | * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode |
| 5650 | * to ignore DMA parity errors. |
| 5651 | */ |
| 5652 | if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR) { |
| 5653 | AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word); |
| 5654 | word |= CONTROL_FLAG_IGNORE_PERR; |
| 5655 | AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word); |
| 5656 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5657 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5658 | /* |
| 5659 | * If the BIOS control flag AIPP (Asynchronous Information |
| 5660 | * Phase Protection) disable bit is not set, then set the firmware |
| 5661 | * 'control_flag' CONTROL_FLAG_ENABLE_AIPP bit to enable |
| 5662 | * AIPP checking and encoding. |
| 5663 | */ |
| 5664 | if ((asc_dvc->bios_ctrl & BIOS_CTRL_AIPP_DIS) == 0) { |
| 5665 | AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word); |
| 5666 | word |= CONTROL_FLAG_ENABLE_AIPP; |
| 5667 | AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word); |
| 5668 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5669 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5670 | /* |
| 5671 | * For ASC-38C1600 use DMA_CFG0 default values: FIFO_THRESH_80B [6:4], |
| 5672 | * and START_CTL_TH [3:2]. |
| 5673 | */ |
| 5674 | AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0, |
| 5675 | FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5676 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5677 | /* |
| 5678 | * Microcode operating variables for WDTR, SDTR, and command tag |
Matthew Wilcox | 47d853c | 2007-07-26 11:41:33 -0400 | [diff] [blame] | 5679 | * queuing will be set in slave_configure() based on what a |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5680 | * device reports it is capable of in Inquiry byte 7. |
| 5681 | * |
| 5682 | * If SCSI Bus Resets have been disabled, then directly set |
| 5683 | * SDTR and WDTR from the EEPROM configuration. This will allow |
| 5684 | * the BIOS and warm boot to work without a SCSI bus hang on |
| 5685 | * the Inquiry caused by host and target mismatched DTR values. |
| 5686 | * Without the SCSI Bus Reset, before an Inquiry a device can't |
| 5687 | * be assumed to be in Asynchronous, Narrow mode. |
| 5688 | */ |
| 5689 | if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) { |
| 5690 | AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, |
| 5691 | asc_dvc->wdtr_able); |
| 5692 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, |
| 5693 | asc_dvc->sdtr_able); |
| 5694 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5695 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5696 | /* |
| 5697 | * Set microcode operating variables for DISC and SDTR_SPEED1, |
| 5698 | * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM |
| 5699 | * configuration values. |
| 5700 | * |
| 5701 | * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2, |
| 5702 | * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them |
| 5703 | * without determining here whether the device supports SDTR. |
| 5704 | */ |
| 5705 | AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE, |
| 5706 | asc_dvc->cfg->disc_enable); |
| 5707 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1); |
| 5708 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2); |
| 5709 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3); |
| 5710 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5711 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5712 | /* |
| 5713 | * Set SCSI_CFG0 Microcode Default Value. |
| 5714 | * |
| 5715 | * The microcode will set the SCSI_CFG0 register using this value |
| 5716 | * after it is started below. |
| 5717 | */ |
| 5718 | AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0, |
| 5719 | PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN | |
| 5720 | asc_dvc->chip_scsi_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5721 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5722 | /* |
| 5723 | * Calculate SCSI_CFG1 Microcode Default Value. |
| 5724 | * |
| 5725 | * The microcode will set the SCSI_CFG1 register using this value |
| 5726 | * after it is started below. |
| 5727 | * |
| 5728 | * Each ASC-38C1600 function has only two cable detect bits. |
| 5729 | * The bus mode override bits are in IOPB_SOFT_OVER_WR. |
| 5730 | */ |
| 5731 | scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5732 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5733 | /* |
| 5734 | * If the cable is reversed all of the SCSI_CTRL register signals |
| 5735 | * will be set. Check for and return an error if this condition is |
| 5736 | * found. |
| 5737 | */ |
| 5738 | if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07) { |
| 5739 | asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE; |
| 5740 | return ADV_ERROR; |
| 5741 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5742 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5743 | /* |
| 5744 | * Each ASC-38C1600 function has two connectors. Only an HVD device |
| 5745 | * can not be connected to either connector. An LVD device or SE device |
| 5746 | * may be connected to either connecor. If an SE device is connected, |
| 5747 | * then at most Ultra speed (20 Mhz) can be used on both connectors. |
| 5748 | * |
| 5749 | * If an HVD device is attached, return an error. |
| 5750 | */ |
| 5751 | if (scsi_cfg1 & HVD) { |
| 5752 | asc_dvc->err_code |= ASC_IERR_HVD_DEVICE; |
| 5753 | return ADV_ERROR; |
| 5754 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5755 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5756 | /* |
| 5757 | * Each function in the ASC-38C1600 uses only the SE cable detect and |
| 5758 | * termination because there are two connectors for each function. Each |
| 5759 | * function may use either LVD or SE mode. Corresponding the SE automatic |
| 5760 | * termination control EEPROM bits are used for each function. Each |
| 5761 | * function has its own EEPROM. If SE automatic control is enabled for |
| 5762 | * the function, then set the termination value based on a table listed |
| 5763 | * in a_condor.h. |
| 5764 | * |
| 5765 | * If manual termination is specified in the EEPROM for the function, |
| 5766 | * then 'termination' was set-up in AscInitFrom38C1600EEPROM() and is |
| 5767 | * ready to be 'ored' into SCSI_CFG1. |
| 5768 | */ |
| 5769 | if ((asc_dvc->cfg->termination & TERM_SE) == 0) { |
Matthew Wilcox | 13ac2d9 | 2007-07-30 08:10:23 -0600 | [diff] [blame] | 5770 | struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5771 | /* SE automatic termination control is enabled. */ |
| 5772 | switch (scsi_cfg1 & C_DET_SE) { |
| 5773 | /* TERM_SE_HI: on, TERM_SE_LO: on */ |
| 5774 | case 0x1: |
| 5775 | case 0x2: |
| 5776 | case 0x3: |
| 5777 | asc_dvc->cfg->termination |= TERM_SE; |
| 5778 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5779 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5780 | case 0x0: |
Matthew Wilcox | 13ac2d9 | 2007-07-30 08:10:23 -0600 | [diff] [blame] | 5781 | if (PCI_FUNC(pdev->devfn) == 0) { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5782 | /* Function 0 - TERM_SE_HI: off, TERM_SE_LO: off */ |
| 5783 | } else { |
| 5784 | /* Function 1 - TERM_SE_HI: on, TERM_SE_LO: off */ |
| 5785 | asc_dvc->cfg->termination |= TERM_SE_HI; |
| 5786 | } |
| 5787 | break; |
| 5788 | } |
| 5789 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5790 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5791 | /* |
| 5792 | * Clear any set TERM_SE bits. |
| 5793 | */ |
| 5794 | scsi_cfg1 &= ~TERM_SE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5795 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5796 | /* |
| 5797 | * Invert the TERM_SE bits and then set 'scsi_cfg1'. |
| 5798 | */ |
| 5799 | scsi_cfg1 |= (~asc_dvc->cfg->termination & TERM_SE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5800 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5801 | /* |
| 5802 | * Clear Big Endian and Terminator Polarity bits and set possibly |
| 5803 | * modified termination control bits in the Microcode SCSI_CFG1 |
| 5804 | * Register Value. |
| 5805 | * |
| 5806 | * Big Endian bit is not used even on big endian machines. |
| 5807 | */ |
| 5808 | scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5809 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5810 | /* |
| 5811 | * Set SCSI_CFG1 Microcode Default Value |
| 5812 | * |
| 5813 | * Set possibly modified termination control bits in the Microcode |
| 5814 | * SCSI_CFG1 Register Value. |
| 5815 | * |
| 5816 | * The microcode will set the SCSI_CFG1 register using this value |
| 5817 | * after it is started below. |
| 5818 | */ |
| 5819 | AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5820 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5821 | /* |
| 5822 | * Set MEM_CFG Microcode Default Value |
| 5823 | * |
| 5824 | * The microcode will set the MEM_CFG register using this value |
| 5825 | * after it is started below. |
| 5826 | * |
| 5827 | * MEM_CFG may be accessed as a word or byte, but only bits 0-7 |
| 5828 | * are defined. |
| 5829 | * |
| 5830 | * ASC-38C1600 has 32KB internal memory. |
| 5831 | * |
| 5832 | * XXX - Since ASC38C1600 Rev.3 has a Local RAM failure issue, we come |
| 5833 | * out a special 16K Adv Library and Microcode version. After the issue |
| 5834 | * resolved, we should turn back to the 32K support. Both a_condor.h and |
| 5835 | * mcode.sas files also need to be updated. |
| 5836 | * |
| 5837 | * AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG, |
| 5838 | * BIOS_EN | RAM_SZ_32KB); |
| 5839 | */ |
| 5840 | AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG, |
| 5841 | BIOS_EN | RAM_SZ_16KB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5842 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5843 | /* |
| 5844 | * Set SEL_MASK Microcode Default Value |
| 5845 | * |
| 5846 | * The microcode will set the SEL_MASK register using this value |
| 5847 | * after it is started below. |
| 5848 | */ |
| 5849 | AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK, |
| 5850 | ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5851 | |
Matthew Wilcox | a9f4a59 | 2007-09-09 08:56:27 -0600 | [diff] [blame] | 5852 | AdvBuildCarrierFreelist(asc_dvc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5853 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5854 | /* |
| 5855 | * Set-up the Host->RISC Initiator Command Queue (ICQ). |
| 5856 | */ |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 5857 | asc_dvc->icq_sp = adv_get_next_carrier(asc_dvc); |
| 5858 | if (!asc_dvc->icq_sp) { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5859 | asc_dvc->err_code |= ASC_IERR_NO_CARRIER; |
| 5860 | return ADV_ERROR; |
| 5861 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5862 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5863 | /* |
| 5864 | * Set RISC ICQ physical address start value. Initialize the |
| 5865 | * COMMA register to the same value otherwise the RISC will |
| 5866 | * prematurely detect a command is available. |
| 5867 | */ |
| 5868 | AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa); |
| 5869 | AdvWriteDWordRegister(iop_base, IOPDW_COMMA, |
| 5870 | le32_to_cpu(asc_dvc->icq_sp->carr_pa)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5871 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5872 | /* |
| 5873 | * Set-up the RISC->Host Initiator Response Queue (IRQ). |
| 5874 | */ |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 5875 | asc_dvc->irq_sp = adv_get_next_carrier(asc_dvc); |
| 5876 | if (!asc_dvc->irq_sp) { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5877 | asc_dvc->err_code |= ASC_IERR_NO_CARRIER; |
| 5878 | return ADV_ERROR; |
| 5879 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5880 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5881 | /* |
| 5882 | * Set RISC IRQ physical address start value. |
| 5883 | */ |
| 5884 | AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa); |
| 5885 | asc_dvc->carr_pending_cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5886 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5887 | AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES, |
| 5888 | (ADV_INTR_ENABLE_HOST_INTR | |
| 5889 | ADV_INTR_ENABLE_GLOBAL_INTR)); |
| 5890 | AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word); |
| 5891 | AdvWriteWordRegister(iop_base, IOPW_PC, word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5892 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5893 | /* finally, finally, gentlemen, start your engine */ |
| 5894 | AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5895 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5896 | /* |
| 5897 | * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus |
| 5898 | * Resets should be performed. The RISC has to be running |
| 5899 | * to issue a SCSI Bus Reset. |
| 5900 | */ |
| 5901 | if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) { |
| 5902 | /* |
| 5903 | * If the BIOS Signature is present in memory, restore the |
| 5904 | * per TID microcode operating variables. |
| 5905 | */ |
| 5906 | if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM) / 2] == |
| 5907 | 0x55AA) { |
| 5908 | /* |
| 5909 | * Restore per TID negotiated values. |
| 5910 | */ |
| 5911 | AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able); |
| 5912 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able); |
| 5913 | AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able); |
| 5914 | AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, |
| 5915 | tagqng_able); |
| 5916 | for (tid = 0; tid <= ASC_MAX_TID; tid++) { |
| 5917 | AdvWriteByteLram(iop_base, |
| 5918 | ASC_MC_NUMBER_OF_MAX_CMD + tid, |
| 5919 | max_cmd[tid]); |
| 5920 | } |
| 5921 | } else { |
| 5922 | if (AdvResetSB(asc_dvc) != ADV_TRUE) { |
| 5923 | warn_code = ASC_WARN_BUSRESET_ERROR; |
| 5924 | } |
| 5925 | } |
| 5926 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5927 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 5928 | return warn_code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5929 | } |
| 5930 | |
| 5931 | /* |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 5932 | * Reset chip and SCSI Bus. |
| 5933 | * |
| 5934 | * Return Value: |
| 5935 | * ADV_TRUE(1) - Chip re-initialization and SCSI Bus Reset successful. |
| 5936 | * ADV_FALSE(0) - Chip re-initialization and SCSI Bus Reset failure. |
| 5937 | */ |
| 5938 | static int AdvResetChipAndSB(ADV_DVC_VAR *asc_dvc) |
| 5939 | { |
| 5940 | int status; |
| 5941 | ushort wdtr_able, sdtr_able, tagqng_able; |
| 5942 | ushort ppr_able = 0; |
| 5943 | uchar tid, max_cmd[ADV_MAX_TID + 1]; |
| 5944 | AdvPortAddr iop_base; |
| 5945 | ushort bios_sig; |
| 5946 | |
| 5947 | iop_base = asc_dvc->iop_base; |
| 5948 | |
| 5949 | /* |
| 5950 | * Save current per TID negotiated values. |
| 5951 | */ |
| 5952 | AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able); |
| 5953 | AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able); |
| 5954 | if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) { |
| 5955 | AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able); |
| 5956 | } |
| 5957 | AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able); |
| 5958 | for (tid = 0; tid <= ADV_MAX_TID; tid++) { |
| 5959 | AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid, |
| 5960 | max_cmd[tid]); |
| 5961 | } |
| 5962 | |
| 5963 | /* |
| 5964 | * Force the AdvInitAsc3550/38C0800Driver() function to |
| 5965 | * perform a SCSI Bus Reset by clearing the BIOS signature word. |
| 5966 | * The initialization functions assumes a SCSI Bus Reset is not |
| 5967 | * needed if the BIOS signature word is present. |
| 5968 | */ |
| 5969 | AdvReadWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig); |
| 5970 | AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, 0); |
| 5971 | |
| 5972 | /* |
| 5973 | * Stop chip and reset it. |
| 5974 | */ |
| 5975 | AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_STOP); |
| 5976 | AdvWriteWordRegister(iop_base, IOPW_CTRL_REG, ADV_CTRL_REG_CMD_RESET); |
| 5977 | mdelay(100); |
| 5978 | AdvWriteWordRegister(iop_base, IOPW_CTRL_REG, |
| 5979 | ADV_CTRL_REG_CMD_WR_IO_REG); |
| 5980 | |
| 5981 | /* |
| 5982 | * Reset Adv Library error code, if any, and try |
| 5983 | * re-initializing the chip. |
| 5984 | */ |
| 5985 | asc_dvc->err_code = 0; |
| 5986 | if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) { |
| 5987 | status = AdvInitAsc38C1600Driver(asc_dvc); |
| 5988 | } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) { |
| 5989 | status = AdvInitAsc38C0800Driver(asc_dvc); |
| 5990 | } else { |
| 5991 | status = AdvInitAsc3550Driver(asc_dvc); |
| 5992 | } |
| 5993 | |
| 5994 | /* Translate initialization return value to status value. */ |
| 5995 | if (status == 0) { |
| 5996 | status = ADV_TRUE; |
| 5997 | } else { |
| 5998 | status = ADV_FALSE; |
| 5999 | } |
| 6000 | |
| 6001 | /* |
| 6002 | * Restore the BIOS signature word. |
| 6003 | */ |
| 6004 | AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig); |
| 6005 | |
| 6006 | /* |
| 6007 | * Restore per TID negotiated values. |
| 6008 | */ |
| 6009 | AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able); |
| 6010 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able); |
| 6011 | if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) { |
| 6012 | AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able); |
| 6013 | } |
| 6014 | AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able); |
| 6015 | for (tid = 0; tid <= ADV_MAX_TID; tid++) { |
| 6016 | AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid, |
| 6017 | max_cmd[tid]); |
| 6018 | } |
| 6019 | |
| 6020 | return status; |
| 6021 | } |
| 6022 | |
| 6023 | /* |
| 6024 | * adv_async_callback() - Adv Library asynchronous event callback function. |
| 6025 | */ |
| 6026 | static void adv_async_callback(ADV_DVC_VAR *adv_dvc_varp, uchar code) |
| 6027 | { |
| 6028 | switch (code) { |
| 6029 | case ADV_ASYNC_SCSI_BUS_RESET_DET: |
| 6030 | /* |
| 6031 | * The firmware detected a SCSI Bus reset. |
| 6032 | */ |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 6033 | ASC_DBG(0, "ADV_ASYNC_SCSI_BUS_RESET_DET\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6034 | break; |
| 6035 | |
| 6036 | case ADV_ASYNC_RDMA_FAILURE: |
| 6037 | /* |
| 6038 | * Handle RDMA failure by resetting the SCSI Bus and |
| 6039 | * possibly the chip if it is unresponsive. Log the error |
| 6040 | * with a unique code. |
| 6041 | */ |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 6042 | ASC_DBG(0, "ADV_ASYNC_RDMA_FAILURE\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6043 | AdvResetChipAndSB(adv_dvc_varp); |
| 6044 | break; |
| 6045 | |
| 6046 | case ADV_HOST_SCSI_BUS_RESET: |
| 6047 | /* |
| 6048 | * Host generated SCSI bus reset occurred. |
| 6049 | */ |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 6050 | ASC_DBG(0, "ADV_HOST_SCSI_BUS_RESET\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6051 | break; |
| 6052 | |
| 6053 | default: |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 6054 | ASC_DBG(0, "unknown code 0x%x\n", code); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6055 | break; |
| 6056 | } |
| 6057 | } |
| 6058 | |
| 6059 | /* |
| 6060 | * adv_isr_callback() - Second Level Interrupt Handler called by AdvISR(). |
| 6061 | * |
| 6062 | * Callback function for the Wide SCSI Adv Library. |
| 6063 | */ |
| 6064 | static void adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp) |
| 6065 | { |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 6066 | struct asc_board *boardp = adv_dvc_varp->drv_ptr; |
| 6067 | u32 srb_tag; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6068 | adv_req_t *reqp; |
| 6069 | adv_sgblk_t *sgblkp; |
| 6070 | struct scsi_cmnd *scp; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6071 | ADV_DCNT resid_cnt; |
Hannes Reinecke | 811ddc0 | 2015-04-24 13:18:22 +0200 | [diff] [blame] | 6072 | dma_addr_t sense_addr; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6073 | |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 6074 | ASC_DBG(1, "adv_dvc_varp 0x%p, scsiqp 0x%p\n", |
| 6075 | adv_dvc_varp, scsiqp); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6076 | ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp); |
| 6077 | |
| 6078 | /* |
| 6079 | * Get the adv_req_t structure for the command that has been |
| 6080 | * completed. The adv_req_t structure actually contains the |
| 6081 | * completed ADV_SCSI_REQ_Q structure. |
| 6082 | */ |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 6083 | srb_tag = le32_to_cpu(scsiqp->srb_tag); |
| 6084 | scp = scsi_host_find_tag(boardp->shost, scsiqp->srb_tag); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6085 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 6086 | ASC_DBG(1, "scp 0x%p\n", scp); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6087 | if (scp == NULL) { |
| 6088 | ASC_PRINT |
| 6089 | ("adv_isr_callback: scp is NULL; adv_req_t dropped.\n"); |
| 6090 | return; |
| 6091 | } |
| 6092 | ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len); |
| 6093 | |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 6094 | reqp = (adv_req_t *)scp->host_scribble; |
| 6095 | ASC_DBG(1, "reqp 0x%lx\n", (ulong)reqp); |
| 6096 | if (reqp == NULL) { |
| 6097 | ASC_PRINT("adv_isr_callback: reqp is NULL\n"); |
| 6098 | return; |
| 6099 | } |
| 6100 | /* |
| 6101 | * Remove backreferences to avoid duplicate |
| 6102 | * command completions. |
| 6103 | */ |
| 6104 | scp->host_scribble = NULL; |
| 6105 | reqp->cmndp = NULL; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6106 | |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 6107 | ASC_STATS(boardp->shost, callback); |
| 6108 | ASC_DBG(1, "shost 0x%p\n", boardp->shost); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6109 | |
Hannes Reinecke | 811ddc0 | 2015-04-24 13:18:22 +0200 | [diff] [blame] | 6110 | sense_addr = le32_to_cpu(scsiqp->sense_addr); |
| 6111 | dma_unmap_single(boardp->dev, sense_addr, |
| 6112 | SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE); |
| 6113 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6114 | /* |
| 6115 | * 'done_status' contains the command's ending status. |
| 6116 | */ |
| 6117 | switch (scsiqp->done_status) { |
| 6118 | case QD_NO_ERROR: |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 6119 | ASC_DBG(2, "QD_NO_ERROR\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6120 | scp->result = 0; |
| 6121 | |
| 6122 | /* |
| 6123 | * Check for an underrun condition. |
| 6124 | * |
| 6125 | * If there was no error and an underrun condition, then |
| 6126 | * then return the number of underrun bytes. |
| 6127 | */ |
| 6128 | resid_cnt = le32_to_cpu(scsiqp->data_cnt); |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 6129 | if (scsi_bufflen(scp) != 0 && resid_cnt != 0 && |
| 6130 | resid_cnt <= scsi_bufflen(scp)) { |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 6131 | ASC_DBG(1, "underrun condition %lu bytes\n", |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6132 | (ulong)resid_cnt); |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 6133 | scsi_set_resid(scp, resid_cnt); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6134 | } |
| 6135 | break; |
| 6136 | |
| 6137 | case QD_WITH_ERROR: |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 6138 | ASC_DBG(2, "QD_WITH_ERROR\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6139 | switch (scsiqp->host_status) { |
| 6140 | case QHSTA_NO_ERROR: |
| 6141 | if (scsiqp->scsi_status == SAM_STAT_CHECK_CONDITION) { |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 6142 | ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6143 | ASC_DBG_PRT_SENSE(2, scp->sense_buffer, |
FUJITA Tomonori | b80ca4f | 2008-01-13 15:46:13 +0900 | [diff] [blame] | 6144 | SCSI_SENSE_BUFFERSIZE); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6145 | /* |
| 6146 | * Note: The 'status_byte()' macro used by |
| 6147 | * target drivers defined in scsi.h shifts the |
| 6148 | * status byte returned by host drivers right |
| 6149 | * by 1 bit. This is why target drivers also |
| 6150 | * use right shifted status byte definitions. |
| 6151 | * For instance target drivers use |
| 6152 | * CHECK_CONDITION, defined to 0x1, instead of |
| 6153 | * the SCSI defined check condition value of |
| 6154 | * 0x2. Host drivers are supposed to return |
| 6155 | * the status byte as it is defined by SCSI. |
| 6156 | */ |
| 6157 | scp->result = DRIVER_BYTE(DRIVER_SENSE) | |
| 6158 | STATUS_BYTE(scsiqp->scsi_status); |
| 6159 | } else { |
| 6160 | scp->result = STATUS_BYTE(scsiqp->scsi_status); |
| 6161 | } |
| 6162 | break; |
| 6163 | |
| 6164 | default: |
| 6165 | /* Some other QHSTA error occurred. */ |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 6166 | ASC_DBG(1, "host_status 0x%x\n", scsiqp->host_status); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6167 | scp->result = HOST_BYTE(DID_BAD_TARGET); |
| 6168 | break; |
| 6169 | } |
| 6170 | break; |
| 6171 | |
| 6172 | case QD_ABORTED_BY_HOST: |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 6173 | ASC_DBG(1, "QD_ABORTED_BY_HOST\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6174 | scp->result = |
| 6175 | HOST_BYTE(DID_ABORT) | STATUS_BYTE(scsiqp->scsi_status); |
| 6176 | break; |
| 6177 | |
| 6178 | default: |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 6179 | ASC_DBG(1, "done_status 0x%x\n", scsiqp->done_status); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6180 | scp->result = |
| 6181 | HOST_BYTE(DID_ERROR) | STATUS_BYTE(scsiqp->scsi_status); |
| 6182 | break; |
| 6183 | } |
| 6184 | |
| 6185 | /* |
| 6186 | * If the 'init_tidmask' bit isn't already set for the target and the |
| 6187 | * current request finished normally, then set the bit for the target |
| 6188 | * to indicate that a device is present. |
| 6189 | */ |
| 6190 | if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 && |
| 6191 | scsiqp->done_status == QD_NO_ERROR && |
| 6192 | scsiqp->host_status == QHSTA_NO_ERROR) { |
| 6193 | boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id); |
| 6194 | } |
| 6195 | |
| 6196 | asc_scsi_done(scp); |
| 6197 | |
| 6198 | /* |
| 6199 | * Free all 'adv_sgblk_t' structures allocated for the request. |
| 6200 | */ |
| 6201 | while ((sgblkp = reqp->sgblkp) != NULL) { |
| 6202 | /* Remove 'sgblkp' from the request list. */ |
| 6203 | reqp->sgblkp = sgblkp->next_sgblkp; |
| 6204 | |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 6205 | dma_pool_free(boardp->adv_sgblk_pool, sgblkp, |
| 6206 | sgblkp->sg_addr); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6207 | } |
| 6208 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 6209 | ASC_DBG(1, "done\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6210 | } |
| 6211 | |
| 6212 | /* |
| 6213 | * Adv Library Interrupt Service Routine |
| 6214 | * |
| 6215 | * This function is called by a driver's interrupt service routine. |
| 6216 | * The function disables and re-enables interrupts. |
| 6217 | * |
| 6218 | * When a microcode idle command is completed, the ADV_DVC_VAR |
| 6219 | * 'idle_cmd_done' field is set to ADV_TRUE. |
| 6220 | * |
| 6221 | * Note: AdvISR() can be called when interrupts are disabled or even |
| 6222 | * when there is no hardware interrupt condition present. It will |
| 6223 | * always check for completed idle commands and microcode requests. |
| 6224 | * This is an important feature that shouldn't be changed because it |
| 6225 | * allows commands to be completed from polling mode loops. |
| 6226 | * |
| 6227 | * Return: |
| 6228 | * ADV_TRUE(1) - interrupt was pending |
| 6229 | * ADV_FALSE(0) - no interrupt was pending |
| 6230 | */ |
| 6231 | static int AdvISR(ADV_DVC_VAR *asc_dvc) |
| 6232 | { |
| 6233 | AdvPortAddr iop_base; |
| 6234 | uchar int_stat; |
| 6235 | ushort target_bit; |
| 6236 | ADV_CARR_T *free_carrp; |
| 6237 | ADV_VADDR irq_next_vpa; |
| 6238 | ADV_SCSI_REQ_Q *scsiq; |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 6239 | adv_req_t *reqp; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6240 | |
| 6241 | iop_base = asc_dvc->iop_base; |
| 6242 | |
| 6243 | /* Reading the register clears the interrupt. */ |
| 6244 | int_stat = AdvReadByteRegister(iop_base, IOPB_INTR_STATUS_REG); |
| 6245 | |
| 6246 | if ((int_stat & (ADV_INTR_STATUS_INTRA | ADV_INTR_STATUS_INTRB | |
| 6247 | ADV_INTR_STATUS_INTRC)) == 0) { |
| 6248 | return ADV_FALSE; |
| 6249 | } |
| 6250 | |
| 6251 | /* |
| 6252 | * Notify the driver of an asynchronous microcode condition by |
| 6253 | * calling the adv_async_callback function. The function |
| 6254 | * is passed the microcode ASC_MC_INTRB_CODE byte value. |
| 6255 | */ |
| 6256 | if (int_stat & ADV_INTR_STATUS_INTRB) { |
| 6257 | uchar intrb_code; |
| 6258 | |
| 6259 | AdvReadByteLram(iop_base, ASC_MC_INTRB_CODE, intrb_code); |
| 6260 | |
| 6261 | if (asc_dvc->chip_type == ADV_CHIP_ASC3550 || |
| 6262 | asc_dvc->chip_type == ADV_CHIP_ASC38C0800) { |
| 6263 | if (intrb_code == ADV_ASYNC_CARRIER_READY_FAILURE && |
| 6264 | asc_dvc->carr_pending_cnt != 0) { |
| 6265 | AdvWriteByteRegister(iop_base, IOPB_TICKLE, |
| 6266 | ADV_TICKLE_A); |
| 6267 | if (asc_dvc->chip_type == ADV_CHIP_ASC3550) { |
| 6268 | AdvWriteByteRegister(iop_base, |
| 6269 | IOPB_TICKLE, |
| 6270 | ADV_TICKLE_NOP); |
| 6271 | } |
| 6272 | } |
| 6273 | } |
| 6274 | |
| 6275 | adv_async_callback(asc_dvc, intrb_code); |
| 6276 | } |
| 6277 | |
| 6278 | /* |
| 6279 | * Check if the IRQ stopper carrier contains a completed request. |
| 6280 | */ |
| 6281 | while (((irq_next_vpa = |
| 6282 | le32_to_cpu(asc_dvc->irq_sp->next_vpa)) & ASC_RQ_DONE) != 0) { |
| 6283 | /* |
| 6284 | * Get a pointer to the newly completed ADV_SCSI_REQ_Q structure. |
| 6285 | * The RISC will have set 'areq_vpa' to a virtual address. |
| 6286 | * |
| 6287 | * The firmware will have copied the ASC_SCSI_REQ_Q.scsiq_ptr |
| 6288 | * field to the carrier ADV_CARR_T.areq_vpa field. The conversion |
| 6289 | * below complements the conversion of ASC_SCSI_REQ_Q.scsiq_ptr' |
| 6290 | * in AdvExeScsiQueue(). |
| 6291 | */ |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 6292 | u32 pa_offset = le32_to_cpu(asc_dvc->irq_sp->areq_vpa); |
| 6293 | ASC_DBG(1, "irq_sp %p areq_vpa %u\n", |
| 6294 | asc_dvc->irq_sp, pa_offset); |
| 6295 | reqp = adv_get_reqp(asc_dvc, pa_offset); |
| 6296 | scsiq = &reqp->scsi_req_q; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6297 | |
| 6298 | /* |
| 6299 | * Request finished with good status and the queue was not |
| 6300 | * DMAed to host memory by the firmware. Set all status fields |
| 6301 | * to indicate good status. |
| 6302 | */ |
| 6303 | if ((irq_next_vpa & ASC_RQ_GOOD) != 0) { |
| 6304 | scsiq->done_status = QD_NO_ERROR; |
| 6305 | scsiq->host_status = scsiq->scsi_status = 0; |
| 6306 | scsiq->data_cnt = 0L; |
| 6307 | } |
| 6308 | |
| 6309 | /* |
| 6310 | * Advance the stopper pointer to the next carrier |
| 6311 | * ignoring the lower four bits. Free the previous |
| 6312 | * stopper carrier. |
| 6313 | */ |
| 6314 | free_carrp = asc_dvc->irq_sp; |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 6315 | asc_dvc->irq_sp = adv_get_carrier(asc_dvc, |
| 6316 | ASC_GET_CARRP(irq_next_vpa)); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6317 | |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 6318 | free_carrp->next_vpa = asc_dvc->carr_freelist->carr_va; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6319 | asc_dvc->carr_freelist = free_carrp; |
| 6320 | asc_dvc->carr_pending_cnt--; |
| 6321 | |
| 6322 | target_bit = ADV_TID_TO_TIDMASK(scsiq->target_id); |
| 6323 | |
| 6324 | /* |
| 6325 | * Clear request microcode control flag. |
| 6326 | */ |
| 6327 | scsiq->cntl = 0; |
| 6328 | |
| 6329 | /* |
| 6330 | * Notify the driver of the completed request by passing |
| 6331 | * the ADV_SCSI_REQ_Q pointer to its callback function. |
| 6332 | */ |
| 6333 | scsiq->a_flag |= ADV_SCSIQ_DONE; |
| 6334 | adv_isr_callback(asc_dvc, scsiq); |
| 6335 | /* |
| 6336 | * Note: After the driver callback function is called, 'scsiq' |
| 6337 | * can no longer be referenced. |
| 6338 | * |
| 6339 | * Fall through and continue processing other completed |
| 6340 | * requests... |
| 6341 | */ |
| 6342 | } |
| 6343 | return ADV_TRUE; |
| 6344 | } |
| 6345 | |
| 6346 | static int AscSetLibErrorCode(ASC_DVC_VAR *asc_dvc, ushort err_code) |
| 6347 | { |
| 6348 | if (asc_dvc->err_code == 0) { |
| 6349 | asc_dvc->err_code = err_code; |
| 6350 | AscWriteLramWord(asc_dvc->iop_base, ASCV_ASCDVC_ERR_CODE_W, |
| 6351 | err_code); |
| 6352 | } |
| 6353 | return err_code; |
| 6354 | } |
| 6355 | |
| 6356 | static void AscAckInterrupt(PortAddr iop_base) |
| 6357 | { |
| 6358 | uchar host_flag; |
| 6359 | uchar risc_flag; |
| 6360 | ushort loop; |
| 6361 | |
| 6362 | loop = 0; |
| 6363 | do { |
| 6364 | risc_flag = AscReadLramByte(iop_base, ASCV_RISC_FLAG_B); |
| 6365 | if (loop++ > 0x7FFF) { |
| 6366 | break; |
| 6367 | } |
| 6368 | } while ((risc_flag & ASC_RISC_FLAG_GEN_INT) != 0); |
| 6369 | host_flag = |
| 6370 | AscReadLramByte(iop_base, |
| 6371 | ASCV_HOST_FLAG_B) & (~ASC_HOST_FLAG_ACK_INT); |
| 6372 | AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, |
| 6373 | (uchar)(host_flag | ASC_HOST_FLAG_ACK_INT)); |
| 6374 | AscSetChipStatus(iop_base, CIW_INT_ACK); |
| 6375 | loop = 0; |
| 6376 | while (AscGetChipStatus(iop_base) & CSW_INT_PENDING) { |
| 6377 | AscSetChipStatus(iop_base, CIW_INT_ACK); |
| 6378 | if (loop++ > 3) { |
| 6379 | break; |
| 6380 | } |
| 6381 | } |
| 6382 | AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6383 | } |
| 6384 | |
| 6385 | static uchar AscGetSynPeriodIndex(ASC_DVC_VAR *asc_dvc, uchar syn_time) |
| 6386 | { |
Matthew Wilcox | afbb68c | 2007-10-02 21:55:36 -0400 | [diff] [blame] | 6387 | const uchar *period_table; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6388 | int max_index; |
| 6389 | int min_index; |
| 6390 | int i; |
| 6391 | |
| 6392 | period_table = asc_dvc->sdtr_period_tbl; |
| 6393 | max_index = (int)asc_dvc->max_sdtr_index; |
Matthew Wilcox | afbb68c | 2007-10-02 21:55:36 -0400 | [diff] [blame] | 6394 | min_index = (int)asc_dvc->min_sdtr_index; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6395 | if ((syn_time <= period_table[max_index])) { |
| 6396 | for (i = min_index; i < (max_index - 1); i++) { |
| 6397 | if (syn_time <= period_table[i]) { |
| 6398 | return (uchar)i; |
| 6399 | } |
| 6400 | } |
| 6401 | return (uchar)max_index; |
| 6402 | } else { |
| 6403 | return (uchar)(max_index + 1); |
| 6404 | } |
| 6405 | } |
| 6406 | |
| 6407 | static uchar |
| 6408 | AscMsgOutSDTR(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar sdtr_offset) |
| 6409 | { |
| 6410 | EXT_MSG sdtr_buf; |
| 6411 | uchar sdtr_period_index; |
| 6412 | PortAddr iop_base; |
| 6413 | |
| 6414 | iop_base = asc_dvc->iop_base; |
| 6415 | sdtr_buf.msg_type = EXTENDED_MESSAGE; |
| 6416 | sdtr_buf.msg_len = MS_SDTR_LEN; |
| 6417 | sdtr_buf.msg_req = EXTENDED_SDTR; |
| 6418 | sdtr_buf.xfer_period = sdtr_period; |
| 6419 | sdtr_offset &= ASC_SYN_MAX_OFFSET; |
| 6420 | sdtr_buf.req_ack_offset = sdtr_offset; |
| 6421 | sdtr_period_index = AscGetSynPeriodIndex(asc_dvc, sdtr_period); |
| 6422 | if (sdtr_period_index <= asc_dvc->max_sdtr_index) { |
| 6423 | AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG, |
| 6424 | (uchar *)&sdtr_buf, |
| 6425 | sizeof(EXT_MSG) >> 1); |
| 6426 | return ((sdtr_period_index << 4) | sdtr_offset); |
| 6427 | } else { |
| 6428 | sdtr_buf.req_ack_offset = 0; |
| 6429 | AscMemWordCopyPtrToLram(iop_base, ASCV_MSGOUT_BEG, |
| 6430 | (uchar *)&sdtr_buf, |
| 6431 | sizeof(EXT_MSG) >> 1); |
| 6432 | return 0; |
| 6433 | } |
| 6434 | } |
| 6435 | |
| 6436 | static uchar |
| 6437 | AscCalSDTRData(ASC_DVC_VAR *asc_dvc, uchar sdtr_period, uchar syn_offset) |
| 6438 | { |
| 6439 | uchar byte; |
| 6440 | uchar sdtr_period_ix; |
| 6441 | |
| 6442 | sdtr_period_ix = AscGetSynPeriodIndex(asc_dvc, sdtr_period); |
Matthew Wilcox | afbb68c | 2007-10-02 21:55:36 -0400 | [diff] [blame] | 6443 | if (sdtr_period_ix > asc_dvc->max_sdtr_index) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6444 | return 0xFF; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6445 | byte = (sdtr_period_ix << 4) | (syn_offset & ASC_SYN_MAX_OFFSET); |
| 6446 | return byte; |
| 6447 | } |
| 6448 | |
Hannes Reinecke | d647c78 | 2015-04-24 13:18:26 +0200 | [diff] [blame^] | 6449 | static bool AscSetChipSynRegAtID(PortAddr iop_base, uchar id, uchar sdtr_data) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6450 | { |
| 6451 | ASC_SCSI_BIT_ID_TYPE org_id; |
| 6452 | int i; |
Hannes Reinecke | d647c78 | 2015-04-24 13:18:26 +0200 | [diff] [blame^] | 6453 | bool sta = true; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6454 | |
| 6455 | AscSetBank(iop_base, 1); |
| 6456 | org_id = AscReadChipDvcID(iop_base); |
| 6457 | for (i = 0; i <= ASC_MAX_TID; i++) { |
| 6458 | if (org_id == (0x01 << i)) |
| 6459 | break; |
| 6460 | } |
| 6461 | org_id = (ASC_SCSI_BIT_ID_TYPE) i; |
| 6462 | AscWriteChipDvcID(iop_base, id); |
| 6463 | if (AscReadChipDvcID(iop_base) == (0x01 << id)) { |
| 6464 | AscSetBank(iop_base, 0); |
| 6465 | AscSetChipSyn(iop_base, sdtr_data); |
| 6466 | if (AscGetChipSyn(iop_base) != sdtr_data) { |
Hannes Reinecke | d647c78 | 2015-04-24 13:18:26 +0200 | [diff] [blame^] | 6467 | sta = false; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6468 | } |
| 6469 | } else { |
Hannes Reinecke | d647c78 | 2015-04-24 13:18:26 +0200 | [diff] [blame^] | 6470 | sta = false; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6471 | } |
| 6472 | AscSetBank(iop_base, 1); |
| 6473 | AscWriteChipDvcID(iop_base, org_id); |
| 6474 | AscSetBank(iop_base, 0); |
| 6475 | return (sta); |
| 6476 | } |
| 6477 | |
| 6478 | static void AscSetChipSDTR(PortAddr iop_base, uchar sdtr_data, uchar tid_no) |
| 6479 | { |
| 6480 | AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data); |
| 6481 | AscPutMCodeSDTRDoneAtID(iop_base, tid_no, sdtr_data); |
| 6482 | } |
| 6483 | |
| 6484 | static int AscIsrChipHalted(ASC_DVC_VAR *asc_dvc) |
| 6485 | { |
| 6486 | EXT_MSG ext_msg; |
| 6487 | EXT_MSG out_msg; |
| 6488 | ushort halt_q_addr; |
| 6489 | int sdtr_accept; |
| 6490 | ushort int_halt_code; |
| 6491 | ASC_SCSI_BIT_ID_TYPE scsi_busy; |
| 6492 | ASC_SCSI_BIT_ID_TYPE target_id; |
| 6493 | PortAddr iop_base; |
| 6494 | uchar tag_code; |
| 6495 | uchar q_status; |
| 6496 | uchar halt_qp; |
| 6497 | uchar sdtr_data; |
| 6498 | uchar target_ix; |
| 6499 | uchar q_cntl, tid_no; |
| 6500 | uchar cur_dvc_qng; |
| 6501 | uchar asyn_sdtr; |
| 6502 | uchar scsi_status; |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 6503 | struct asc_board *boardp; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6504 | |
| 6505 | BUG_ON(!asc_dvc->drv_ptr); |
| 6506 | boardp = asc_dvc->drv_ptr; |
| 6507 | |
| 6508 | iop_base = asc_dvc->iop_base; |
| 6509 | int_halt_code = AscReadLramWord(iop_base, ASCV_HALTCODE_W); |
| 6510 | |
| 6511 | halt_qp = AscReadLramByte(iop_base, ASCV_CURCDB_B); |
| 6512 | halt_q_addr = ASC_QNO_TO_QADDR(halt_qp); |
| 6513 | target_ix = AscReadLramByte(iop_base, |
| 6514 | (ushort)(halt_q_addr + |
| 6515 | (ushort)ASC_SCSIQ_B_TARGET_IX)); |
| 6516 | q_cntl = AscReadLramByte(iop_base, |
| 6517 | (ushort)(halt_q_addr + (ushort)ASC_SCSIQ_B_CNTL)); |
| 6518 | tid_no = ASC_TIX_TO_TID(target_ix); |
| 6519 | target_id = (uchar)ASC_TID_TO_TARGET_ID(tid_no); |
| 6520 | if (asc_dvc->pci_fix_asyn_xfer & target_id) { |
| 6521 | asyn_sdtr = ASYN_SDTR_DATA_FIX_PCI_REV_AB; |
| 6522 | } else { |
| 6523 | asyn_sdtr = 0; |
| 6524 | } |
| 6525 | if (int_halt_code == ASC_HALT_DISABLE_ASYN_USE_SYN_FIX) { |
| 6526 | if (asc_dvc->pci_fix_asyn_xfer & target_id) { |
| 6527 | AscSetChipSDTR(iop_base, 0, tid_no); |
| 6528 | boardp->sdtr_data[tid_no] = 0; |
| 6529 | } |
| 6530 | AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0); |
| 6531 | return (0); |
| 6532 | } else if (int_halt_code == ASC_HALT_ENABLE_ASYN_USE_SYN_FIX) { |
| 6533 | if (asc_dvc->pci_fix_asyn_xfer & target_id) { |
| 6534 | AscSetChipSDTR(iop_base, asyn_sdtr, tid_no); |
| 6535 | boardp->sdtr_data[tid_no] = asyn_sdtr; |
| 6536 | } |
| 6537 | AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0); |
| 6538 | return (0); |
| 6539 | } else if (int_halt_code == ASC_HALT_EXTMSG_IN) { |
| 6540 | AscMemWordCopyPtrFromLram(iop_base, |
| 6541 | ASCV_MSGIN_BEG, |
| 6542 | (uchar *)&ext_msg, |
| 6543 | sizeof(EXT_MSG) >> 1); |
| 6544 | |
| 6545 | if (ext_msg.msg_type == EXTENDED_MESSAGE && |
| 6546 | ext_msg.msg_req == EXTENDED_SDTR && |
| 6547 | ext_msg.msg_len == MS_SDTR_LEN) { |
| 6548 | sdtr_accept = TRUE; |
| 6549 | if ((ext_msg.req_ack_offset > ASC_SYN_MAX_OFFSET)) { |
| 6550 | |
| 6551 | sdtr_accept = FALSE; |
| 6552 | ext_msg.req_ack_offset = ASC_SYN_MAX_OFFSET; |
| 6553 | } |
| 6554 | if ((ext_msg.xfer_period < |
Matthew Wilcox | afbb68c | 2007-10-02 21:55:36 -0400 | [diff] [blame] | 6555 | asc_dvc->sdtr_period_tbl[asc_dvc->min_sdtr_index]) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6556 | || (ext_msg.xfer_period > |
| 6557 | asc_dvc->sdtr_period_tbl[asc_dvc-> |
| 6558 | max_sdtr_index])) { |
| 6559 | sdtr_accept = FALSE; |
| 6560 | ext_msg.xfer_period = |
| 6561 | asc_dvc->sdtr_period_tbl[asc_dvc-> |
Matthew Wilcox | afbb68c | 2007-10-02 21:55:36 -0400 | [diff] [blame] | 6562 | min_sdtr_index]; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6563 | } |
| 6564 | if (sdtr_accept) { |
| 6565 | sdtr_data = |
| 6566 | AscCalSDTRData(asc_dvc, ext_msg.xfer_period, |
| 6567 | ext_msg.req_ack_offset); |
| 6568 | if ((sdtr_data == 0xFF)) { |
| 6569 | |
| 6570 | q_cntl |= QC_MSG_OUT; |
| 6571 | asc_dvc->init_sdtr &= ~target_id; |
| 6572 | asc_dvc->sdtr_done &= ~target_id; |
| 6573 | AscSetChipSDTR(iop_base, asyn_sdtr, |
| 6574 | tid_no); |
| 6575 | boardp->sdtr_data[tid_no] = asyn_sdtr; |
| 6576 | } |
| 6577 | } |
| 6578 | if (ext_msg.req_ack_offset == 0) { |
| 6579 | |
| 6580 | q_cntl &= ~QC_MSG_OUT; |
| 6581 | asc_dvc->init_sdtr &= ~target_id; |
| 6582 | asc_dvc->sdtr_done &= ~target_id; |
| 6583 | AscSetChipSDTR(iop_base, asyn_sdtr, tid_no); |
| 6584 | } else { |
| 6585 | if (sdtr_accept && (q_cntl & QC_MSG_OUT)) { |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6586 | q_cntl &= ~QC_MSG_OUT; |
| 6587 | asc_dvc->sdtr_done |= target_id; |
| 6588 | asc_dvc->init_sdtr |= target_id; |
| 6589 | asc_dvc->pci_fix_asyn_xfer &= |
| 6590 | ~target_id; |
| 6591 | sdtr_data = |
| 6592 | AscCalSDTRData(asc_dvc, |
| 6593 | ext_msg.xfer_period, |
| 6594 | ext_msg. |
| 6595 | req_ack_offset); |
| 6596 | AscSetChipSDTR(iop_base, sdtr_data, |
| 6597 | tid_no); |
| 6598 | boardp->sdtr_data[tid_no] = sdtr_data; |
| 6599 | } else { |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 6600 | q_cntl |= QC_MSG_OUT; |
| 6601 | AscMsgOutSDTR(asc_dvc, |
| 6602 | ext_msg.xfer_period, |
| 6603 | ext_msg.req_ack_offset); |
| 6604 | asc_dvc->pci_fix_asyn_xfer &= |
| 6605 | ~target_id; |
| 6606 | sdtr_data = |
| 6607 | AscCalSDTRData(asc_dvc, |
| 6608 | ext_msg.xfer_period, |
| 6609 | ext_msg. |
| 6610 | req_ack_offset); |
| 6611 | AscSetChipSDTR(iop_base, sdtr_data, |
| 6612 | tid_no); |
| 6613 | boardp->sdtr_data[tid_no] = sdtr_data; |
| 6614 | asc_dvc->sdtr_done |= target_id; |
| 6615 | asc_dvc->init_sdtr |= target_id; |
| 6616 | } |
| 6617 | } |
| 6618 | |
| 6619 | AscWriteLramByte(iop_base, |
| 6620 | (ushort)(halt_q_addr + |
| 6621 | (ushort)ASC_SCSIQ_B_CNTL), |
| 6622 | q_cntl); |
| 6623 | AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0); |
| 6624 | return (0); |
| 6625 | } else if (ext_msg.msg_type == EXTENDED_MESSAGE && |
| 6626 | ext_msg.msg_req == EXTENDED_WDTR && |
| 6627 | ext_msg.msg_len == MS_WDTR_LEN) { |
| 6628 | |
| 6629 | ext_msg.wdtr_width = 0; |
| 6630 | AscMemWordCopyPtrToLram(iop_base, |
| 6631 | ASCV_MSGOUT_BEG, |
| 6632 | (uchar *)&ext_msg, |
| 6633 | sizeof(EXT_MSG) >> 1); |
| 6634 | q_cntl |= QC_MSG_OUT; |
| 6635 | AscWriteLramByte(iop_base, |
| 6636 | (ushort)(halt_q_addr + |
| 6637 | (ushort)ASC_SCSIQ_B_CNTL), |
| 6638 | q_cntl); |
| 6639 | AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0); |
| 6640 | return (0); |
| 6641 | } else { |
| 6642 | |
| 6643 | ext_msg.msg_type = MESSAGE_REJECT; |
| 6644 | AscMemWordCopyPtrToLram(iop_base, |
| 6645 | ASCV_MSGOUT_BEG, |
| 6646 | (uchar *)&ext_msg, |
| 6647 | sizeof(EXT_MSG) >> 1); |
| 6648 | q_cntl |= QC_MSG_OUT; |
| 6649 | AscWriteLramByte(iop_base, |
| 6650 | (ushort)(halt_q_addr + |
| 6651 | (ushort)ASC_SCSIQ_B_CNTL), |
| 6652 | q_cntl); |
| 6653 | AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0); |
| 6654 | return (0); |
| 6655 | } |
| 6656 | } else if (int_halt_code == ASC_HALT_CHK_CONDITION) { |
| 6657 | |
| 6658 | q_cntl |= QC_REQ_SENSE; |
| 6659 | |
| 6660 | if ((asc_dvc->init_sdtr & target_id) != 0) { |
| 6661 | |
| 6662 | asc_dvc->sdtr_done &= ~target_id; |
| 6663 | |
| 6664 | sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no); |
| 6665 | q_cntl |= QC_MSG_OUT; |
| 6666 | AscMsgOutSDTR(asc_dvc, |
| 6667 | asc_dvc-> |
| 6668 | sdtr_period_tbl[(sdtr_data >> 4) & |
| 6669 | (uchar)(asc_dvc-> |
| 6670 | max_sdtr_index - |
| 6671 | 1)], |
| 6672 | (uchar)(sdtr_data & (uchar) |
| 6673 | ASC_SYN_MAX_OFFSET)); |
| 6674 | } |
| 6675 | |
| 6676 | AscWriteLramByte(iop_base, |
| 6677 | (ushort)(halt_q_addr + |
| 6678 | (ushort)ASC_SCSIQ_B_CNTL), q_cntl); |
| 6679 | |
| 6680 | tag_code = AscReadLramByte(iop_base, |
| 6681 | (ushort)(halt_q_addr + (ushort) |
| 6682 | ASC_SCSIQ_B_TAG_CODE)); |
| 6683 | tag_code &= 0xDC; |
| 6684 | if ((asc_dvc->pci_fix_asyn_xfer & target_id) |
| 6685 | && !(asc_dvc->pci_fix_asyn_xfer_always & target_id) |
| 6686 | ) { |
| 6687 | |
| 6688 | tag_code |= (ASC_TAG_FLAG_DISABLE_DISCONNECT |
| 6689 | | ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX); |
| 6690 | |
| 6691 | } |
| 6692 | AscWriteLramByte(iop_base, |
| 6693 | (ushort)(halt_q_addr + |
| 6694 | (ushort)ASC_SCSIQ_B_TAG_CODE), |
| 6695 | tag_code); |
| 6696 | |
| 6697 | q_status = AscReadLramByte(iop_base, |
| 6698 | (ushort)(halt_q_addr + (ushort) |
| 6699 | ASC_SCSIQ_B_STATUS)); |
| 6700 | q_status |= (QS_READY | QS_BUSY); |
| 6701 | AscWriteLramByte(iop_base, |
| 6702 | (ushort)(halt_q_addr + |
| 6703 | (ushort)ASC_SCSIQ_B_STATUS), |
| 6704 | q_status); |
| 6705 | |
| 6706 | scsi_busy = AscReadLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B); |
| 6707 | scsi_busy &= ~target_id; |
| 6708 | AscWriteLramByte(iop_base, (ushort)ASCV_SCSIBUSY_B, scsi_busy); |
| 6709 | |
| 6710 | AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0); |
| 6711 | return (0); |
| 6712 | } else if (int_halt_code == ASC_HALT_SDTR_REJECTED) { |
| 6713 | |
| 6714 | AscMemWordCopyPtrFromLram(iop_base, |
| 6715 | ASCV_MSGOUT_BEG, |
| 6716 | (uchar *)&out_msg, |
| 6717 | sizeof(EXT_MSG) >> 1); |
| 6718 | |
| 6719 | if ((out_msg.msg_type == EXTENDED_MESSAGE) && |
| 6720 | (out_msg.msg_len == MS_SDTR_LEN) && |
| 6721 | (out_msg.msg_req == EXTENDED_SDTR)) { |
| 6722 | |
| 6723 | asc_dvc->init_sdtr &= ~target_id; |
| 6724 | asc_dvc->sdtr_done &= ~target_id; |
| 6725 | AscSetChipSDTR(iop_base, asyn_sdtr, tid_no); |
| 6726 | boardp->sdtr_data[tid_no] = asyn_sdtr; |
| 6727 | } |
| 6728 | q_cntl &= ~QC_MSG_OUT; |
| 6729 | AscWriteLramByte(iop_base, |
| 6730 | (ushort)(halt_q_addr + |
| 6731 | (ushort)ASC_SCSIQ_B_CNTL), q_cntl); |
| 6732 | AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0); |
| 6733 | return (0); |
| 6734 | } else if (int_halt_code == ASC_HALT_SS_QUEUE_FULL) { |
| 6735 | |
| 6736 | scsi_status = AscReadLramByte(iop_base, |
| 6737 | (ushort)((ushort)halt_q_addr + |
| 6738 | (ushort) |
| 6739 | ASC_SCSIQ_SCSI_STATUS)); |
| 6740 | cur_dvc_qng = |
| 6741 | AscReadLramByte(iop_base, |
| 6742 | (ushort)((ushort)ASC_QADR_BEG + |
| 6743 | (ushort)target_ix)); |
| 6744 | if ((cur_dvc_qng > 0) && (asc_dvc->cur_dvc_qng[tid_no] > 0)) { |
| 6745 | |
| 6746 | scsi_busy = AscReadLramByte(iop_base, |
| 6747 | (ushort)ASCV_SCSIBUSY_B); |
| 6748 | scsi_busy |= target_id; |
| 6749 | AscWriteLramByte(iop_base, |
| 6750 | (ushort)ASCV_SCSIBUSY_B, scsi_busy); |
| 6751 | asc_dvc->queue_full_or_busy |= target_id; |
| 6752 | |
| 6753 | if (scsi_status == SAM_STAT_TASK_SET_FULL) { |
| 6754 | if (cur_dvc_qng > ASC_MIN_TAGGED_CMD) { |
| 6755 | cur_dvc_qng -= 1; |
| 6756 | asc_dvc->max_dvc_qng[tid_no] = |
| 6757 | cur_dvc_qng; |
| 6758 | |
| 6759 | AscWriteLramByte(iop_base, |
| 6760 | (ushort)((ushort) |
| 6761 | ASCV_MAX_DVC_QNG_BEG |
| 6762 | + (ushort) |
| 6763 | tid_no), |
| 6764 | cur_dvc_qng); |
| 6765 | |
| 6766 | /* |
| 6767 | * Set the device queue depth to the |
| 6768 | * number of active requests when the |
| 6769 | * QUEUE FULL condition was encountered. |
| 6770 | */ |
| 6771 | boardp->queue_full |= target_id; |
| 6772 | boardp->queue_full_cnt[tid_no] = |
| 6773 | cur_dvc_qng; |
| 6774 | } |
| 6775 | } |
| 6776 | } |
| 6777 | AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0); |
| 6778 | return (0); |
| 6779 | } |
| 6780 | #if CC_VERY_LONG_SG_LIST |
| 6781 | else if (int_halt_code == ASC_HALT_HOST_COPY_SG_LIST_TO_RISC) { |
| 6782 | uchar q_no; |
| 6783 | ushort q_addr; |
| 6784 | uchar sg_wk_q_no; |
| 6785 | uchar first_sg_wk_q_no; |
| 6786 | ASC_SCSI_Q *scsiq; /* Ptr to driver request. */ |
| 6787 | ASC_SG_HEAD *sg_head; /* Ptr to driver SG request. */ |
| 6788 | ASC_SG_LIST_Q scsi_sg_q; /* Structure written to queue. */ |
| 6789 | ushort sg_list_dwords; |
| 6790 | ushort sg_entry_cnt; |
| 6791 | uchar next_qp; |
| 6792 | int i; |
| 6793 | |
| 6794 | q_no = AscReadLramByte(iop_base, (ushort)ASCV_REQ_SG_LIST_QP); |
| 6795 | if (q_no == ASC_QLINK_END) |
| 6796 | return 0; |
| 6797 | |
| 6798 | q_addr = ASC_QNO_TO_QADDR(q_no); |
| 6799 | |
| 6800 | /* |
| 6801 | * Convert the request's SRB pointer to a host ASC_SCSI_REQ |
| 6802 | * structure pointer using a macro provided by the driver. |
| 6803 | * The ASC_SCSI_REQ pointer provides a pointer to the |
| 6804 | * host ASC_SG_HEAD structure. |
| 6805 | */ |
| 6806 | /* Read request's SRB pointer. */ |
| 6807 | scsiq = (ASC_SCSI_Q *) |
| 6808 | ASC_SRB2SCSIQ(ASC_U32_TO_VADDR(AscReadLramDWord(iop_base, |
| 6809 | (ushort) |
| 6810 | (q_addr + |
| 6811 | ASC_SCSIQ_D_SRBPTR)))); |
| 6812 | |
| 6813 | /* |
| 6814 | * Get request's first and working SG queue. |
| 6815 | */ |
| 6816 | sg_wk_q_no = AscReadLramByte(iop_base, |
| 6817 | (ushort)(q_addr + |
| 6818 | ASC_SCSIQ_B_SG_WK_QP)); |
| 6819 | |
| 6820 | first_sg_wk_q_no = AscReadLramByte(iop_base, |
| 6821 | (ushort)(q_addr + |
| 6822 | ASC_SCSIQ_B_FIRST_SG_WK_QP)); |
| 6823 | |
| 6824 | /* |
| 6825 | * Reset request's working SG queue back to the |
| 6826 | * first SG queue. |
| 6827 | */ |
| 6828 | AscWriteLramByte(iop_base, |
| 6829 | (ushort)(q_addr + |
| 6830 | (ushort)ASC_SCSIQ_B_SG_WK_QP), |
| 6831 | first_sg_wk_q_no); |
| 6832 | |
| 6833 | sg_head = scsiq->sg_head; |
| 6834 | |
| 6835 | /* |
| 6836 | * Set sg_entry_cnt to the number of SG elements |
| 6837 | * that will be completed on this interrupt. |
| 6838 | * |
| 6839 | * Note: The allocated SG queues contain ASC_MAX_SG_LIST - 1 |
| 6840 | * SG elements. The data_cnt and data_addr fields which |
| 6841 | * add 1 to the SG element capacity are not used when |
| 6842 | * restarting SG handling after a halt. |
| 6843 | */ |
| 6844 | if (scsiq->remain_sg_entry_cnt > (ASC_MAX_SG_LIST - 1)) { |
| 6845 | sg_entry_cnt = ASC_MAX_SG_LIST - 1; |
| 6846 | |
| 6847 | /* |
| 6848 | * Keep track of remaining number of SG elements that |
| 6849 | * will need to be handled on the next interrupt. |
| 6850 | */ |
| 6851 | scsiq->remain_sg_entry_cnt -= (ASC_MAX_SG_LIST - 1); |
| 6852 | } else { |
| 6853 | sg_entry_cnt = scsiq->remain_sg_entry_cnt; |
| 6854 | scsiq->remain_sg_entry_cnt = 0; |
| 6855 | } |
| 6856 | |
| 6857 | /* |
| 6858 | * Copy SG elements into the list of allocated SG queues. |
| 6859 | * |
| 6860 | * Last index completed is saved in scsiq->next_sg_index. |
| 6861 | */ |
| 6862 | next_qp = first_sg_wk_q_no; |
| 6863 | q_addr = ASC_QNO_TO_QADDR(next_qp); |
| 6864 | scsi_sg_q.sg_head_qp = q_no; |
| 6865 | scsi_sg_q.cntl = QCSG_SG_XFER_LIST; |
| 6866 | for (i = 0; i < sg_head->queue_cnt; i++) { |
| 6867 | scsi_sg_q.seq_no = i + 1; |
| 6868 | if (sg_entry_cnt > ASC_SG_LIST_PER_Q) { |
| 6869 | sg_list_dwords = (uchar)(ASC_SG_LIST_PER_Q * 2); |
| 6870 | sg_entry_cnt -= ASC_SG_LIST_PER_Q; |
| 6871 | /* |
| 6872 | * After very first SG queue RISC FW uses next |
| 6873 | * SG queue first element then checks sg_list_cnt |
| 6874 | * against zero and then decrements, so set |
| 6875 | * sg_list_cnt 1 less than number of SG elements |
| 6876 | * in each SG queue. |
| 6877 | */ |
| 6878 | scsi_sg_q.sg_list_cnt = ASC_SG_LIST_PER_Q - 1; |
| 6879 | scsi_sg_q.sg_cur_list_cnt = |
| 6880 | ASC_SG_LIST_PER_Q - 1; |
| 6881 | } else { |
| 6882 | /* |
| 6883 | * This is the last SG queue in the list of |
| 6884 | * allocated SG queues. If there are more |
| 6885 | * SG elements than will fit in the allocated |
| 6886 | * queues, then set the QCSG_SG_XFER_MORE flag. |
| 6887 | */ |
| 6888 | if (scsiq->remain_sg_entry_cnt != 0) { |
| 6889 | scsi_sg_q.cntl |= QCSG_SG_XFER_MORE; |
| 6890 | } else { |
| 6891 | scsi_sg_q.cntl |= QCSG_SG_XFER_END; |
| 6892 | } |
| 6893 | /* equals sg_entry_cnt * 2 */ |
| 6894 | sg_list_dwords = sg_entry_cnt << 1; |
| 6895 | scsi_sg_q.sg_list_cnt = sg_entry_cnt - 1; |
| 6896 | scsi_sg_q.sg_cur_list_cnt = sg_entry_cnt - 1; |
| 6897 | sg_entry_cnt = 0; |
| 6898 | } |
| 6899 | |
| 6900 | scsi_sg_q.q_no = next_qp; |
| 6901 | AscMemWordCopyPtrToLram(iop_base, |
| 6902 | q_addr + ASC_SCSIQ_SGHD_CPY_BEG, |
| 6903 | (uchar *)&scsi_sg_q, |
| 6904 | sizeof(ASC_SG_LIST_Q) >> 1); |
| 6905 | |
| 6906 | AscMemDWordCopyPtrToLram(iop_base, |
| 6907 | q_addr + ASC_SGQ_LIST_BEG, |
| 6908 | (uchar *)&sg_head-> |
| 6909 | sg_list[scsiq->next_sg_index], |
| 6910 | sg_list_dwords); |
| 6911 | |
| 6912 | scsiq->next_sg_index += ASC_SG_LIST_PER_Q; |
| 6913 | |
| 6914 | /* |
| 6915 | * If the just completed SG queue contained the |
| 6916 | * last SG element, then no more SG queues need |
| 6917 | * to be written. |
| 6918 | */ |
| 6919 | if (scsi_sg_q.cntl & QCSG_SG_XFER_END) { |
| 6920 | break; |
| 6921 | } |
| 6922 | |
| 6923 | next_qp = AscReadLramByte(iop_base, |
| 6924 | (ushort)(q_addr + |
| 6925 | ASC_SCSIQ_B_FWD)); |
| 6926 | q_addr = ASC_QNO_TO_QADDR(next_qp); |
| 6927 | } |
| 6928 | |
| 6929 | /* |
| 6930 | * Clear the halt condition so the RISC will be restarted |
| 6931 | * after the return. |
| 6932 | */ |
| 6933 | AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0); |
| 6934 | return (0); |
| 6935 | } |
| 6936 | #endif /* CC_VERY_LONG_SG_LIST */ |
| 6937 | return (0); |
| 6938 | } |
| 6939 | |
| 6940 | /* |
| 6941 | * void |
| 6942 | * DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words) |
| 6943 | * |
| 6944 | * Calling/Exit State: |
| 6945 | * none |
| 6946 | * |
| 6947 | * Description: |
| 6948 | * Input an ASC_QDONE_INFO structure from the chip |
| 6949 | */ |
| 6950 | static void |
| 6951 | DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words) |
| 6952 | { |
| 6953 | int i; |
| 6954 | ushort word; |
| 6955 | |
| 6956 | AscSetChipLramAddr(iop_base, s_addr); |
| 6957 | for (i = 0; i < 2 * words; i += 2) { |
| 6958 | if (i == 10) { |
| 6959 | continue; |
| 6960 | } |
| 6961 | word = inpw(iop_base + IOP_RAM_DATA); |
| 6962 | inbuf[i] = word & 0xff; |
| 6963 | inbuf[i + 1] = (word >> 8) & 0xff; |
| 6964 | } |
| 6965 | ASC_DBG_PRT_HEX(2, "DvcGetQinfo", inbuf, 2 * words); |
| 6966 | } |
| 6967 | |
| 6968 | static uchar |
| 6969 | _AscCopyLramScsiDoneQ(PortAddr iop_base, |
| 6970 | ushort q_addr, |
| 6971 | ASC_QDONE_INFO *scsiq, ASC_DCNT max_dma_count) |
| 6972 | { |
| 6973 | ushort _val; |
| 6974 | uchar sg_queue_cnt; |
| 6975 | |
| 6976 | DvcGetQinfo(iop_base, |
| 6977 | q_addr + ASC_SCSIQ_DONE_INFO_BEG, |
| 6978 | (uchar *)scsiq, |
| 6979 | (sizeof(ASC_SCSIQ_2) + sizeof(ASC_SCSIQ_3)) / 2); |
| 6980 | |
| 6981 | _val = AscReadLramWord(iop_base, |
| 6982 | (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS)); |
| 6983 | scsiq->q_status = (uchar)_val; |
| 6984 | scsiq->q_no = (uchar)(_val >> 8); |
| 6985 | _val = AscReadLramWord(iop_base, |
| 6986 | (ushort)(q_addr + (ushort)ASC_SCSIQ_B_CNTL)); |
| 6987 | scsiq->cntl = (uchar)_val; |
| 6988 | sg_queue_cnt = (uchar)(_val >> 8); |
| 6989 | _val = AscReadLramWord(iop_base, |
| 6990 | (ushort)(q_addr + |
| 6991 | (ushort)ASC_SCSIQ_B_SENSE_LEN)); |
| 6992 | scsiq->sense_len = (uchar)_val; |
| 6993 | scsiq->extra_bytes = (uchar)(_val >> 8); |
| 6994 | |
| 6995 | /* |
| 6996 | * Read high word of remain bytes from alternate location. |
| 6997 | */ |
| 6998 | scsiq->remain_bytes = (((ADV_DCNT)AscReadLramWord(iop_base, |
| 6999 | (ushort)(q_addr + |
| 7000 | (ushort) |
| 7001 | ASC_SCSIQ_W_ALT_DC1))) |
| 7002 | << 16); |
| 7003 | /* |
| 7004 | * Read low word of remain bytes from original location. |
| 7005 | */ |
| 7006 | scsiq->remain_bytes += AscReadLramWord(iop_base, |
| 7007 | (ushort)(q_addr + (ushort) |
| 7008 | ASC_SCSIQ_DW_REMAIN_XFER_CNT)); |
| 7009 | |
| 7010 | scsiq->remain_bytes &= max_dma_count; |
| 7011 | return sg_queue_cnt; |
| 7012 | } |
| 7013 | |
| 7014 | /* |
| 7015 | * asc_isr_callback() - Second Level Interrupt Handler called by AscISR(). |
| 7016 | * |
| 7017 | * Interrupt callback function for the Narrow SCSI Asc Library. |
| 7018 | */ |
| 7019 | static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep) |
| 7020 | { |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 7021 | struct asc_board *boardp = asc_dvc_varp->drv_ptr; |
| 7022 | u32 srb_tag; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7023 | struct scsi_cmnd *scp; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7024 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 7025 | ASC_DBG(1, "asc_dvc_varp 0x%p, qdonep 0x%p\n", asc_dvc_varp, qdonep); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7026 | ASC_DBG_PRT_ASC_QDONE_INFO(2, qdonep); |
| 7027 | |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 7028 | /* |
| 7029 | * Decrease the srb_tag by 1 to find the SCSI command |
| 7030 | */ |
| 7031 | srb_tag = qdonep->d2.srb_tag - 1; |
| 7032 | scp = scsi_host_find_tag(boardp->shost, srb_tag); |
Matthew Wilcox | b249c7f | 2007-10-02 21:55:40 -0400 | [diff] [blame] | 7033 | if (!scp) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7034 | return; |
Matthew Wilcox | b249c7f | 2007-10-02 21:55:40 -0400 | [diff] [blame] | 7035 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7036 | ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len); |
| 7037 | |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 7038 | ASC_STATS(boardp->shost, callback); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7039 | |
Matthew Wilcox | b249c7f | 2007-10-02 21:55:40 -0400 | [diff] [blame] | 7040 | dma_unmap_single(boardp->dev, scp->SCp.dma_handle, |
FUJITA Tomonori | b80ca4f | 2008-01-13 15:46:13 +0900 | [diff] [blame] | 7041 | SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7042 | /* |
| 7043 | * 'qdonep' contains the command's ending status. |
| 7044 | */ |
| 7045 | switch (qdonep->d3.done_stat) { |
| 7046 | case QD_NO_ERROR: |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 7047 | ASC_DBG(2, "QD_NO_ERROR\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7048 | scp->result = 0; |
| 7049 | |
| 7050 | /* |
| 7051 | * Check for an underrun condition. |
| 7052 | * |
| 7053 | * If there was no error and an underrun condition, then |
| 7054 | * return the number of underrun bytes. |
| 7055 | */ |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 7056 | if (scsi_bufflen(scp) != 0 && qdonep->remain_bytes != 0 && |
| 7057 | qdonep->remain_bytes <= scsi_bufflen(scp)) { |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 7058 | ASC_DBG(1, "underrun condition %u bytes\n", |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7059 | (unsigned)qdonep->remain_bytes); |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 7060 | scsi_set_resid(scp, qdonep->remain_bytes); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7061 | } |
| 7062 | break; |
| 7063 | |
| 7064 | case QD_WITH_ERROR: |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 7065 | ASC_DBG(2, "QD_WITH_ERROR\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7066 | switch (qdonep->d3.host_stat) { |
| 7067 | case QHSTA_NO_ERROR: |
| 7068 | if (qdonep->d3.scsi_stat == SAM_STAT_CHECK_CONDITION) { |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 7069 | ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7070 | ASC_DBG_PRT_SENSE(2, scp->sense_buffer, |
FUJITA Tomonori | b80ca4f | 2008-01-13 15:46:13 +0900 | [diff] [blame] | 7071 | SCSI_SENSE_BUFFERSIZE); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7072 | /* |
| 7073 | * Note: The 'status_byte()' macro used by |
| 7074 | * target drivers defined in scsi.h shifts the |
| 7075 | * status byte returned by host drivers right |
| 7076 | * by 1 bit. This is why target drivers also |
| 7077 | * use right shifted status byte definitions. |
| 7078 | * For instance target drivers use |
| 7079 | * CHECK_CONDITION, defined to 0x1, instead of |
| 7080 | * the SCSI defined check condition value of |
| 7081 | * 0x2. Host drivers are supposed to return |
| 7082 | * the status byte as it is defined by SCSI. |
| 7083 | */ |
| 7084 | scp->result = DRIVER_BYTE(DRIVER_SENSE) | |
| 7085 | STATUS_BYTE(qdonep->d3.scsi_stat); |
| 7086 | } else { |
| 7087 | scp->result = STATUS_BYTE(qdonep->d3.scsi_stat); |
| 7088 | } |
| 7089 | break; |
| 7090 | |
| 7091 | default: |
| 7092 | /* QHSTA error occurred */ |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 7093 | ASC_DBG(1, "host_stat 0x%x\n", qdonep->d3.host_stat); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7094 | scp->result = HOST_BYTE(DID_BAD_TARGET); |
| 7095 | break; |
| 7096 | } |
| 7097 | break; |
| 7098 | |
| 7099 | case QD_ABORTED_BY_HOST: |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 7100 | ASC_DBG(1, "QD_ABORTED_BY_HOST\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7101 | scp->result = |
| 7102 | HOST_BYTE(DID_ABORT) | MSG_BYTE(qdonep->d3. |
| 7103 | scsi_msg) | |
| 7104 | STATUS_BYTE(qdonep->d3.scsi_stat); |
| 7105 | break; |
| 7106 | |
| 7107 | default: |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 7108 | ASC_DBG(1, "done_stat 0x%x\n", qdonep->d3.done_stat); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7109 | scp->result = |
| 7110 | HOST_BYTE(DID_ERROR) | MSG_BYTE(qdonep->d3. |
| 7111 | scsi_msg) | |
| 7112 | STATUS_BYTE(qdonep->d3.scsi_stat); |
| 7113 | break; |
| 7114 | } |
| 7115 | |
| 7116 | /* |
| 7117 | * If the 'init_tidmask' bit isn't already set for the target and the |
| 7118 | * current request finished normally, then set the bit for the target |
| 7119 | * to indicate that a device is present. |
| 7120 | */ |
| 7121 | if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 && |
| 7122 | qdonep->d3.done_stat == QD_NO_ERROR && |
| 7123 | qdonep->d3.host_stat == QHSTA_NO_ERROR) { |
| 7124 | boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id); |
| 7125 | } |
| 7126 | |
| 7127 | asc_scsi_done(scp); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7128 | } |
| 7129 | |
| 7130 | static int AscIsrQDone(ASC_DVC_VAR *asc_dvc) |
| 7131 | { |
| 7132 | uchar next_qp; |
| 7133 | uchar n_q_used; |
| 7134 | uchar sg_list_qp; |
| 7135 | uchar sg_queue_cnt; |
| 7136 | uchar q_cnt; |
| 7137 | uchar done_q_tail; |
| 7138 | uchar tid_no; |
| 7139 | ASC_SCSI_BIT_ID_TYPE scsi_busy; |
| 7140 | ASC_SCSI_BIT_ID_TYPE target_id; |
| 7141 | PortAddr iop_base; |
| 7142 | ushort q_addr; |
| 7143 | ushort sg_q_addr; |
| 7144 | uchar cur_target_qng; |
| 7145 | ASC_QDONE_INFO scsiq_buf; |
| 7146 | ASC_QDONE_INFO *scsiq; |
| 7147 | int false_overrun; |
| 7148 | |
| 7149 | iop_base = asc_dvc->iop_base; |
| 7150 | n_q_used = 1; |
| 7151 | scsiq = (ASC_QDONE_INFO *)&scsiq_buf; |
| 7152 | done_q_tail = (uchar)AscGetVarDoneQTail(iop_base); |
| 7153 | q_addr = ASC_QNO_TO_QADDR(done_q_tail); |
| 7154 | next_qp = AscReadLramByte(iop_base, |
| 7155 | (ushort)(q_addr + (ushort)ASC_SCSIQ_B_FWD)); |
| 7156 | if (next_qp != ASC_QLINK_END) { |
| 7157 | AscPutVarDoneQTail(iop_base, next_qp); |
| 7158 | q_addr = ASC_QNO_TO_QADDR(next_qp); |
| 7159 | sg_queue_cnt = _AscCopyLramScsiDoneQ(iop_base, q_addr, scsiq, |
| 7160 | asc_dvc->max_dma_count); |
| 7161 | AscWriteLramByte(iop_base, |
| 7162 | (ushort)(q_addr + |
| 7163 | (ushort)ASC_SCSIQ_B_STATUS), |
| 7164 | (uchar)(scsiq-> |
| 7165 | q_status & (uchar)~(QS_READY | |
| 7166 | QS_ABORTED))); |
| 7167 | tid_no = ASC_TIX_TO_TID(scsiq->d2.target_ix); |
| 7168 | target_id = ASC_TIX_TO_TARGET_ID(scsiq->d2.target_ix); |
| 7169 | if ((scsiq->cntl & QC_SG_HEAD) != 0) { |
| 7170 | sg_q_addr = q_addr; |
| 7171 | sg_list_qp = next_qp; |
| 7172 | for (q_cnt = 0; q_cnt < sg_queue_cnt; q_cnt++) { |
| 7173 | sg_list_qp = AscReadLramByte(iop_base, |
| 7174 | (ushort)(sg_q_addr |
| 7175 | + (ushort) |
| 7176 | ASC_SCSIQ_B_FWD)); |
| 7177 | sg_q_addr = ASC_QNO_TO_QADDR(sg_list_qp); |
| 7178 | if (sg_list_qp == ASC_QLINK_END) { |
| 7179 | AscSetLibErrorCode(asc_dvc, |
| 7180 | ASCQ_ERR_SG_Q_LINKS); |
| 7181 | scsiq->d3.done_stat = QD_WITH_ERROR; |
| 7182 | scsiq->d3.host_stat = |
| 7183 | QHSTA_D_QDONE_SG_LIST_CORRUPTED; |
| 7184 | goto FATAL_ERR_QDONE; |
| 7185 | } |
| 7186 | AscWriteLramByte(iop_base, |
| 7187 | (ushort)(sg_q_addr + (ushort) |
| 7188 | ASC_SCSIQ_B_STATUS), |
| 7189 | QS_FREE); |
| 7190 | } |
| 7191 | n_q_used = sg_queue_cnt + 1; |
| 7192 | AscPutVarDoneQTail(iop_base, sg_list_qp); |
| 7193 | } |
| 7194 | if (asc_dvc->queue_full_or_busy & target_id) { |
| 7195 | cur_target_qng = AscReadLramByte(iop_base, |
| 7196 | (ushort)((ushort) |
| 7197 | ASC_QADR_BEG |
| 7198 | + (ushort) |
| 7199 | scsiq->d2. |
| 7200 | target_ix)); |
| 7201 | if (cur_target_qng < asc_dvc->max_dvc_qng[tid_no]) { |
| 7202 | scsi_busy = AscReadLramByte(iop_base, (ushort) |
| 7203 | ASCV_SCSIBUSY_B); |
| 7204 | scsi_busy &= ~target_id; |
| 7205 | AscWriteLramByte(iop_base, |
| 7206 | (ushort)ASCV_SCSIBUSY_B, |
| 7207 | scsi_busy); |
| 7208 | asc_dvc->queue_full_or_busy &= ~target_id; |
| 7209 | } |
| 7210 | } |
| 7211 | if (asc_dvc->cur_total_qng >= n_q_used) { |
| 7212 | asc_dvc->cur_total_qng -= n_q_used; |
| 7213 | if (asc_dvc->cur_dvc_qng[tid_no] != 0) { |
| 7214 | asc_dvc->cur_dvc_qng[tid_no]--; |
| 7215 | } |
| 7216 | } else { |
| 7217 | AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CUR_QNG); |
| 7218 | scsiq->d3.done_stat = QD_WITH_ERROR; |
| 7219 | goto FATAL_ERR_QDONE; |
| 7220 | } |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 7221 | if ((scsiq->d2.srb_tag == 0UL) || |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7222 | ((scsiq->q_status & QS_ABORTED) != 0)) { |
| 7223 | return (0x11); |
| 7224 | } else if (scsiq->q_status == QS_DONE) { |
| 7225 | false_overrun = FALSE; |
| 7226 | if (scsiq->extra_bytes != 0) { |
| 7227 | scsiq->remain_bytes += |
| 7228 | (ADV_DCNT)scsiq->extra_bytes; |
| 7229 | } |
| 7230 | if (scsiq->d3.done_stat == QD_WITH_ERROR) { |
| 7231 | if (scsiq->d3.host_stat == |
| 7232 | QHSTA_M_DATA_OVER_RUN) { |
| 7233 | if ((scsiq-> |
| 7234 | cntl & (QC_DATA_IN | QC_DATA_OUT)) |
| 7235 | == 0) { |
| 7236 | scsiq->d3.done_stat = |
| 7237 | QD_NO_ERROR; |
| 7238 | scsiq->d3.host_stat = |
| 7239 | QHSTA_NO_ERROR; |
| 7240 | } else if (false_overrun) { |
| 7241 | scsiq->d3.done_stat = |
| 7242 | QD_NO_ERROR; |
| 7243 | scsiq->d3.host_stat = |
| 7244 | QHSTA_NO_ERROR; |
| 7245 | } |
| 7246 | } else if (scsiq->d3.host_stat == |
| 7247 | QHSTA_M_HUNG_REQ_SCSI_BUS_RESET) { |
| 7248 | AscStopChip(iop_base); |
| 7249 | AscSetChipControl(iop_base, |
| 7250 | (uchar)(CC_SCSI_RESET |
| 7251 | | CC_HALT)); |
| 7252 | udelay(60); |
| 7253 | AscSetChipControl(iop_base, CC_HALT); |
| 7254 | AscSetChipStatus(iop_base, |
| 7255 | CIW_CLR_SCSI_RESET_INT); |
| 7256 | AscSetChipStatus(iop_base, 0); |
| 7257 | AscSetChipControl(iop_base, 0); |
| 7258 | } |
| 7259 | } |
| 7260 | if ((scsiq->cntl & QC_NO_CALLBACK) == 0) { |
| 7261 | asc_isr_callback(asc_dvc, scsiq); |
| 7262 | } else { |
| 7263 | if ((AscReadLramByte(iop_base, |
| 7264 | (ushort)(q_addr + (ushort) |
| 7265 | ASC_SCSIQ_CDB_BEG)) |
| 7266 | == START_STOP)) { |
| 7267 | asc_dvc->unit_not_ready &= ~target_id; |
| 7268 | if (scsiq->d3.done_stat != QD_NO_ERROR) { |
| 7269 | asc_dvc->start_motor &= |
| 7270 | ~target_id; |
| 7271 | } |
| 7272 | } |
| 7273 | } |
| 7274 | return (1); |
| 7275 | } else { |
| 7276 | AscSetLibErrorCode(asc_dvc, ASCQ_ERR_Q_STATUS); |
| 7277 | FATAL_ERR_QDONE: |
| 7278 | if ((scsiq->cntl & QC_NO_CALLBACK) == 0) { |
| 7279 | asc_isr_callback(asc_dvc, scsiq); |
| 7280 | } |
| 7281 | return (0x80); |
| 7282 | } |
| 7283 | } |
| 7284 | return (0); |
| 7285 | } |
| 7286 | |
| 7287 | static int AscISR(ASC_DVC_VAR *asc_dvc) |
| 7288 | { |
| 7289 | ASC_CS_TYPE chipstat; |
| 7290 | PortAddr iop_base; |
| 7291 | ushort saved_ram_addr; |
| 7292 | uchar ctrl_reg; |
| 7293 | uchar saved_ctrl_reg; |
| 7294 | int int_pending; |
| 7295 | int status; |
| 7296 | uchar host_flag; |
| 7297 | |
| 7298 | iop_base = asc_dvc->iop_base; |
| 7299 | int_pending = FALSE; |
| 7300 | |
| 7301 | if (AscIsIntPending(iop_base) == 0) |
| 7302 | return int_pending; |
| 7303 | |
| 7304 | if ((asc_dvc->init_state & ASC_INIT_STATE_END_LOAD_MC) == 0) { |
| 7305 | return ERR; |
| 7306 | } |
| 7307 | if (asc_dvc->in_critical_cnt != 0) { |
| 7308 | AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_ON_CRITICAL); |
| 7309 | return ERR; |
| 7310 | } |
| 7311 | if (asc_dvc->is_in_int) { |
| 7312 | AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_RE_ENTRY); |
| 7313 | return ERR; |
| 7314 | } |
| 7315 | asc_dvc->is_in_int = TRUE; |
| 7316 | ctrl_reg = AscGetChipControl(iop_base); |
| 7317 | saved_ctrl_reg = ctrl_reg & (~(CC_SCSI_RESET | CC_CHIP_RESET | |
| 7318 | CC_SINGLE_STEP | CC_DIAG | CC_TEST)); |
| 7319 | chipstat = AscGetChipStatus(iop_base); |
| 7320 | if (chipstat & CSW_SCSI_RESET_LATCH) { |
| 7321 | if (!(asc_dvc->bus_type & (ASC_IS_VL | ASC_IS_EISA))) { |
| 7322 | int i = 10; |
| 7323 | int_pending = TRUE; |
| 7324 | asc_dvc->sdtr_done = 0; |
| 7325 | saved_ctrl_reg &= (uchar)(~CC_HALT); |
| 7326 | while ((AscGetChipStatus(iop_base) & |
| 7327 | CSW_SCSI_RESET_ACTIVE) && (i-- > 0)) { |
| 7328 | mdelay(100); |
| 7329 | } |
| 7330 | AscSetChipControl(iop_base, (CC_CHIP_RESET | CC_HALT)); |
| 7331 | AscSetChipControl(iop_base, CC_HALT); |
| 7332 | AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT); |
| 7333 | AscSetChipStatus(iop_base, 0); |
| 7334 | chipstat = AscGetChipStatus(iop_base); |
| 7335 | } |
| 7336 | } |
| 7337 | saved_ram_addr = AscGetChipLramAddr(iop_base); |
| 7338 | host_flag = AscReadLramByte(iop_base, |
| 7339 | ASCV_HOST_FLAG_B) & |
| 7340 | (uchar)(~ASC_HOST_FLAG_IN_ISR); |
| 7341 | AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, |
| 7342 | (uchar)(host_flag | (uchar)ASC_HOST_FLAG_IN_ISR)); |
| 7343 | if ((chipstat & CSW_INT_PENDING) || (int_pending)) { |
| 7344 | AscAckInterrupt(iop_base); |
| 7345 | int_pending = TRUE; |
| 7346 | if ((chipstat & CSW_HALTED) && (ctrl_reg & CC_SINGLE_STEP)) { |
| 7347 | if (AscIsrChipHalted(asc_dvc) == ERR) { |
| 7348 | goto ISR_REPORT_QDONE_FATAL_ERROR; |
| 7349 | } else { |
| 7350 | saved_ctrl_reg &= (uchar)(~CC_HALT); |
| 7351 | } |
| 7352 | } else { |
| 7353 | ISR_REPORT_QDONE_FATAL_ERROR: |
| 7354 | if ((asc_dvc->dvc_cntl & ASC_CNTL_INT_MULTI_Q) != 0) { |
| 7355 | while (((status = |
| 7356 | AscIsrQDone(asc_dvc)) & 0x01) != 0) { |
| 7357 | } |
| 7358 | } else { |
| 7359 | do { |
| 7360 | if ((status = |
| 7361 | AscIsrQDone(asc_dvc)) == 1) { |
| 7362 | break; |
| 7363 | } |
| 7364 | } while (status == 0x11); |
| 7365 | } |
| 7366 | if ((status & 0x80) != 0) |
| 7367 | int_pending = ERR; |
| 7368 | } |
| 7369 | } |
| 7370 | AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag); |
| 7371 | AscSetChipLramAddr(iop_base, saved_ram_addr); |
| 7372 | AscSetChipControl(iop_base, saved_ctrl_reg); |
| 7373 | asc_dvc->is_in_int = FALSE; |
| 7374 | return int_pending; |
| 7375 | } |
| 7376 | |
| 7377 | /* |
| 7378 | * advansys_reset() |
| 7379 | * |
Hannes Reinecke | eac0b0c | 2015-04-24 13:18:20 +0200 | [diff] [blame] | 7380 | * Reset the host associated with the command 'scp'. |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7381 | * |
| 7382 | * This function runs its own thread. Interrupts must be blocked but |
| 7383 | * sleeping is allowed and no locking other than for host structures is |
| 7384 | * required. Returns SUCCESS or FAILED. |
| 7385 | */ |
| 7386 | static int advansys_reset(struct scsi_cmnd *scp) |
| 7387 | { |
Matthew Wilcox | 52fa077 | 2007-10-02 21:55:26 -0400 | [diff] [blame] | 7388 | struct Scsi_Host *shost = scp->device->host; |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 7389 | struct asc_board *boardp = shost_priv(shost); |
Matthew Wilcox | 52fa077 | 2007-10-02 21:55:26 -0400 | [diff] [blame] | 7390 | unsigned long flags; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7391 | int status; |
| 7392 | int ret = SUCCESS; |
| 7393 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 7394 | ASC_DBG(1, "0x%p\n", scp); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7395 | |
Matthew Wilcox | 52fa077 | 2007-10-02 21:55:26 -0400 | [diff] [blame] | 7396 | ASC_STATS(shost, reset); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7397 | |
Hannes Reinecke | eac0b0c | 2015-04-24 13:18:20 +0200 | [diff] [blame] | 7398 | scmd_printk(KERN_INFO, scp, "SCSI host reset started...\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7399 | |
| 7400 | if (ASC_NARROW_BOARD(boardp)) { |
Matthew Wilcox | 52fa077 | 2007-10-02 21:55:26 -0400 | [diff] [blame] | 7401 | ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7402 | |
Matthew Wilcox | 52fa077 | 2007-10-02 21:55:26 -0400 | [diff] [blame] | 7403 | /* Reset the chip and SCSI bus. */ |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 7404 | ASC_DBG(1, "before AscInitAsc1000Driver()\n"); |
Matthew Wilcox | 52fa077 | 2007-10-02 21:55:26 -0400 | [diff] [blame] | 7405 | status = AscInitAsc1000Driver(asc_dvc); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7406 | |
Adam Buchbinder | 6070d81 | 2009-12-04 15:47:01 -0500 | [diff] [blame] | 7407 | /* Refer to ASC_IERR_* definitions for meaning of 'err_code'. */ |
Herton Ronaldo Krzesinski | 9a908c1 | 2010-03-30 13:35:38 -0300 | [diff] [blame] | 7408 | if (asc_dvc->err_code || !asc_dvc->overrun_dma) { |
Hannes Reinecke | eac0b0c | 2015-04-24 13:18:20 +0200 | [diff] [blame] | 7409 | scmd_printk(KERN_INFO, scp, "SCSI host reset error: " |
Herton Ronaldo Krzesinski | 9a908c1 | 2010-03-30 13:35:38 -0300 | [diff] [blame] | 7410 | "0x%x, status: 0x%x\n", asc_dvc->err_code, |
| 7411 | status); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7412 | ret = FAILED; |
| 7413 | } else if (status) { |
Hannes Reinecke | eac0b0c | 2015-04-24 13:18:20 +0200 | [diff] [blame] | 7414 | scmd_printk(KERN_INFO, scp, "SCSI host reset warning: " |
Matthew Wilcox | 52fa077 | 2007-10-02 21:55:26 -0400 | [diff] [blame] | 7415 | "0x%x\n", status); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7416 | } else { |
Hannes Reinecke | eac0b0c | 2015-04-24 13:18:20 +0200 | [diff] [blame] | 7417 | scmd_printk(KERN_INFO, scp, "SCSI host reset " |
Matthew Wilcox | 52fa077 | 2007-10-02 21:55:26 -0400 | [diff] [blame] | 7418 | "successful\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7419 | } |
| 7420 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 7421 | ASC_DBG(1, "after AscInitAsc1000Driver()\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7422 | } else { |
| 7423 | /* |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7424 | * If the suggest reset bus flags are set, then reset the bus. |
| 7425 | * Otherwise only reset the device. |
| 7426 | */ |
Matthew Wilcox | 52fa077 | 2007-10-02 21:55:26 -0400 | [diff] [blame] | 7427 | ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7428 | |
| 7429 | /* |
Hannes Reinecke | eac0b0c | 2015-04-24 13:18:20 +0200 | [diff] [blame] | 7430 | * Reset the chip and SCSI bus. |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7431 | */ |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 7432 | ASC_DBG(1, "before AdvResetChipAndSB()\n"); |
Matthew Wilcox | 52fa077 | 2007-10-02 21:55:26 -0400 | [diff] [blame] | 7433 | switch (AdvResetChipAndSB(adv_dvc)) { |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7434 | case ASC_TRUE: |
Hannes Reinecke | eac0b0c | 2015-04-24 13:18:20 +0200 | [diff] [blame] | 7435 | scmd_printk(KERN_INFO, scp, "SCSI host reset " |
Matthew Wilcox | 52fa077 | 2007-10-02 21:55:26 -0400 | [diff] [blame] | 7436 | "successful\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7437 | break; |
| 7438 | case ASC_FALSE: |
| 7439 | default: |
Hannes Reinecke | eac0b0c | 2015-04-24 13:18:20 +0200 | [diff] [blame] | 7440 | scmd_printk(KERN_INFO, scp, "SCSI host reset error\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7441 | ret = FAILED; |
| 7442 | break; |
| 7443 | } |
Matthew Wilcox | f092d22 | 2007-10-02 21:55:34 -0400 | [diff] [blame] | 7444 | spin_lock_irqsave(shost->host_lock, flags); |
Matthew Wilcox | 52fa077 | 2007-10-02 21:55:26 -0400 | [diff] [blame] | 7445 | AdvISR(adv_dvc); |
Hannes Reinecke | eac0b0c | 2015-04-24 13:18:20 +0200 | [diff] [blame] | 7446 | spin_unlock_irqrestore(shost->host_lock, flags); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7447 | } |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7448 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 7449 | ASC_DBG(1, "ret %d\n", ret); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7450 | |
| 7451 | return ret; |
| 7452 | } |
| 7453 | |
| 7454 | /* |
| 7455 | * advansys_biosparam() |
| 7456 | * |
| 7457 | * Translate disk drive geometry if the "BIOS greater than 1 GB" |
| 7458 | * support is enabled for a drive. |
| 7459 | * |
| 7460 | * ip (information pointer) is an int array with the following definition: |
| 7461 | * ip[0]: heads |
| 7462 | * ip[1]: sectors |
| 7463 | * ip[2]: cylinders |
| 7464 | */ |
| 7465 | static int |
| 7466 | advansys_biosparam(struct scsi_device *sdev, struct block_device *bdev, |
| 7467 | sector_t capacity, int ip[]) |
| 7468 | { |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 7469 | struct asc_board *boardp = shost_priv(sdev->host); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7470 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 7471 | ASC_DBG(1, "begin\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7472 | ASC_STATS(sdev->host, biosparam); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7473 | if (ASC_NARROW_BOARD(boardp)) { |
| 7474 | if ((boardp->dvc_var.asc_dvc_var.dvc_cntl & |
| 7475 | ASC_CNTL_BIOS_GT_1GB) && capacity > 0x200000) { |
| 7476 | ip[0] = 255; |
| 7477 | ip[1] = 63; |
| 7478 | } else { |
| 7479 | ip[0] = 64; |
| 7480 | ip[1] = 32; |
| 7481 | } |
| 7482 | } else { |
| 7483 | if ((boardp->dvc_var.adv_dvc_var.bios_ctrl & |
| 7484 | BIOS_CTRL_EXTENDED_XLAT) && capacity > 0x200000) { |
| 7485 | ip[0] = 255; |
| 7486 | ip[1] = 63; |
| 7487 | } else { |
| 7488 | ip[0] = 64; |
| 7489 | ip[1] = 32; |
| 7490 | } |
| 7491 | } |
| 7492 | ip[2] = (unsigned long)capacity / (ip[0] * ip[1]); |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 7493 | ASC_DBG(1, "end\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7494 | return 0; |
| 7495 | } |
| 7496 | |
| 7497 | /* |
| 7498 | * First-level interrupt handler. |
| 7499 | * |
| 7500 | * 'dev_id' is a pointer to the interrupting adapter's Scsi_Host. |
| 7501 | */ |
| 7502 | static irqreturn_t advansys_interrupt(int irq, void *dev_id) |
| 7503 | { |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7504 | struct Scsi_Host *shost = dev_id; |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 7505 | struct asc_board *boardp = shost_priv(shost); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7506 | irqreturn_t result = IRQ_NONE; |
| 7507 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 7508 | ASC_DBG(2, "boardp 0x%p\n", boardp); |
Matthew Wilcox | f092d22 | 2007-10-02 21:55:34 -0400 | [diff] [blame] | 7509 | spin_lock(shost->host_lock); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7510 | if (ASC_NARROW_BOARD(boardp)) { |
| 7511 | if (AscIsIntPending(shost->io_port)) { |
| 7512 | result = IRQ_HANDLED; |
| 7513 | ASC_STATS(shost, interrupt); |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 7514 | ASC_DBG(1, "before AscISR()\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7515 | AscISR(&boardp->dvc_var.asc_dvc_var); |
| 7516 | } |
| 7517 | } else { |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 7518 | ASC_DBG(1, "before AdvISR()\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7519 | if (AdvISR(&boardp->dvc_var.adv_dvc_var)) { |
| 7520 | result = IRQ_HANDLED; |
| 7521 | ASC_STATS(shost, interrupt); |
| 7522 | } |
| 7523 | } |
Matthew Wilcox | f092d22 | 2007-10-02 21:55:34 -0400 | [diff] [blame] | 7524 | spin_unlock(shost->host_lock); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7525 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 7526 | ASC_DBG(1, "end\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7527 | return result; |
| 7528 | } |
| 7529 | |
Hannes Reinecke | d647c78 | 2015-04-24 13:18:26 +0200 | [diff] [blame^] | 7530 | static bool AscHostReqRiscHalt(PortAddr iop_base) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7531 | { |
| 7532 | int count = 0; |
Hannes Reinecke | d647c78 | 2015-04-24 13:18:26 +0200 | [diff] [blame^] | 7533 | bool sta = false; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7534 | uchar saved_stop_code; |
| 7535 | |
| 7536 | if (AscIsChipHalted(iop_base)) |
Hannes Reinecke | d647c78 | 2015-04-24 13:18:26 +0200 | [diff] [blame^] | 7537 | return true; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7538 | saved_stop_code = AscReadLramByte(iop_base, ASCV_STOP_CODE_B); |
| 7539 | AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, |
| 7540 | ASC_STOP_HOST_REQ_RISC_HALT | ASC_STOP_REQ_RISC_STOP); |
| 7541 | do { |
| 7542 | if (AscIsChipHalted(iop_base)) { |
Hannes Reinecke | d647c78 | 2015-04-24 13:18:26 +0200 | [diff] [blame^] | 7543 | sta = true; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7544 | break; |
| 7545 | } |
| 7546 | mdelay(100); |
| 7547 | } while (count++ < 20); |
| 7548 | AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, saved_stop_code); |
Hannes Reinecke | d647c78 | 2015-04-24 13:18:26 +0200 | [diff] [blame^] | 7549 | return sta; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7550 | } |
| 7551 | |
Hannes Reinecke | d647c78 | 2015-04-24 13:18:26 +0200 | [diff] [blame^] | 7552 | static bool |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7553 | AscSetRunChipSynRegAtID(PortAddr iop_base, uchar tid_no, uchar sdtr_data) |
| 7554 | { |
Hannes Reinecke | d647c78 | 2015-04-24 13:18:26 +0200 | [diff] [blame^] | 7555 | bool sta = false; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7556 | |
| 7557 | if (AscHostReqRiscHalt(iop_base)) { |
| 7558 | sta = AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data); |
| 7559 | AscStartChip(iop_base); |
| 7560 | } |
| 7561 | return sta; |
| 7562 | } |
| 7563 | |
| 7564 | static void AscAsyncFix(ASC_DVC_VAR *asc_dvc, struct scsi_device *sdev) |
| 7565 | { |
| 7566 | char type = sdev->type; |
| 7567 | ASC_SCSI_BIT_ID_TYPE tid_bits = 1 << sdev->id; |
| 7568 | |
| 7569 | if (!(asc_dvc->bug_fix_cntl & ASC_BUG_FIX_ASYN_USE_SYN)) |
| 7570 | return; |
| 7571 | if (asc_dvc->init_sdtr & tid_bits) |
| 7572 | return; |
| 7573 | |
| 7574 | if ((type == TYPE_ROM) && (strncmp(sdev->vendor, "HP ", 3) == 0)) |
| 7575 | asc_dvc->pci_fix_asyn_xfer_always |= tid_bits; |
| 7576 | |
| 7577 | asc_dvc->pci_fix_asyn_xfer |= tid_bits; |
| 7578 | if ((type == TYPE_PROCESSOR) || (type == TYPE_SCANNER) || |
| 7579 | (type == TYPE_ROM) || (type == TYPE_TAPE)) |
| 7580 | asc_dvc->pci_fix_asyn_xfer &= ~tid_bits; |
| 7581 | |
| 7582 | if (asc_dvc->pci_fix_asyn_xfer & tid_bits) |
| 7583 | AscSetRunChipSynRegAtID(asc_dvc->iop_base, sdev->id, |
| 7584 | ASYN_SDTR_DATA_FIX_PCI_REV_AB); |
| 7585 | } |
| 7586 | |
| 7587 | static void |
| 7588 | advansys_narrow_slave_configure(struct scsi_device *sdev, ASC_DVC_VAR *asc_dvc) |
| 7589 | { |
| 7590 | ASC_SCSI_BIT_ID_TYPE tid_bit = 1 << sdev->id; |
| 7591 | ASC_SCSI_BIT_ID_TYPE orig_use_tagged_qng = asc_dvc->use_tagged_qng; |
| 7592 | |
| 7593 | if (sdev->lun == 0) { |
| 7594 | ASC_SCSI_BIT_ID_TYPE orig_init_sdtr = asc_dvc->init_sdtr; |
| 7595 | if ((asc_dvc->cfg->sdtr_enable & tid_bit) && sdev->sdtr) { |
| 7596 | asc_dvc->init_sdtr |= tid_bit; |
| 7597 | } else { |
| 7598 | asc_dvc->init_sdtr &= ~tid_bit; |
| 7599 | } |
| 7600 | |
| 7601 | if (orig_init_sdtr != asc_dvc->init_sdtr) |
| 7602 | AscAsyncFix(asc_dvc, sdev); |
| 7603 | } |
| 7604 | |
| 7605 | if (sdev->tagged_supported) { |
| 7606 | if (asc_dvc->cfg->cmd_qng_enabled & tid_bit) { |
| 7607 | if (sdev->lun == 0) { |
| 7608 | asc_dvc->cfg->can_tagged_qng |= tid_bit; |
| 7609 | asc_dvc->use_tagged_qng |= tid_bit; |
| 7610 | } |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 7611 | scsi_change_queue_depth(sdev, |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7612 | asc_dvc->max_dvc_qng[sdev->id]); |
| 7613 | } |
| 7614 | } else { |
| 7615 | if (sdev->lun == 0) { |
| 7616 | asc_dvc->cfg->can_tagged_qng &= ~tid_bit; |
| 7617 | asc_dvc->use_tagged_qng &= ~tid_bit; |
| 7618 | } |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7619 | } |
| 7620 | |
| 7621 | if ((sdev->lun == 0) && |
| 7622 | (orig_use_tagged_qng != asc_dvc->use_tagged_qng)) { |
| 7623 | AscWriteLramByte(asc_dvc->iop_base, ASCV_DISC_ENABLE_B, |
| 7624 | asc_dvc->cfg->disc_enable); |
| 7625 | AscWriteLramByte(asc_dvc->iop_base, ASCV_USE_TAGGED_QNG_B, |
| 7626 | asc_dvc->use_tagged_qng); |
| 7627 | AscWriteLramByte(asc_dvc->iop_base, ASCV_CAN_TAGGED_QNG_B, |
| 7628 | asc_dvc->cfg->can_tagged_qng); |
| 7629 | |
| 7630 | asc_dvc->max_dvc_qng[sdev->id] = |
| 7631 | asc_dvc->cfg->max_tag_qng[sdev->id]; |
| 7632 | AscWriteLramByte(asc_dvc->iop_base, |
| 7633 | (ushort)(ASCV_MAX_DVC_QNG_BEG + sdev->id), |
| 7634 | asc_dvc->max_dvc_qng[sdev->id]); |
| 7635 | } |
| 7636 | } |
| 7637 | |
| 7638 | /* |
| 7639 | * Wide Transfers |
| 7640 | * |
| 7641 | * If the EEPROM enabled WDTR for the device and the device supports wide |
| 7642 | * bus (16 bit) transfers, then turn on the device's 'wdtr_able' bit and |
| 7643 | * write the new value to the microcode. |
| 7644 | */ |
| 7645 | static void |
| 7646 | advansys_wide_enable_wdtr(AdvPortAddr iop_base, unsigned short tidmask) |
| 7647 | { |
| 7648 | unsigned short cfg_word; |
| 7649 | AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word); |
| 7650 | if ((cfg_word & tidmask) != 0) |
| 7651 | return; |
| 7652 | |
| 7653 | cfg_word |= tidmask; |
| 7654 | AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word); |
| 7655 | |
| 7656 | /* |
| 7657 | * Clear the microcode SDTR and WDTR negotiation done indicators for |
| 7658 | * the target to cause it to negotiate with the new setting set above. |
| 7659 | * WDTR when accepted causes the target to enter asynchronous mode, so |
| 7660 | * SDTR must be negotiated. |
| 7661 | */ |
| 7662 | AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word); |
| 7663 | cfg_word &= ~tidmask; |
| 7664 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word); |
| 7665 | AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word); |
| 7666 | cfg_word &= ~tidmask; |
| 7667 | AdvWriteWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word); |
| 7668 | } |
| 7669 | |
| 7670 | /* |
| 7671 | * Synchronous Transfers |
| 7672 | * |
| 7673 | * If the EEPROM enabled SDTR for the device and the device |
| 7674 | * supports synchronous transfers, then turn on the device's |
| 7675 | * 'sdtr_able' bit. Write the new value to the microcode. |
| 7676 | */ |
| 7677 | static void |
| 7678 | advansys_wide_enable_sdtr(AdvPortAddr iop_base, unsigned short tidmask) |
| 7679 | { |
| 7680 | unsigned short cfg_word; |
| 7681 | AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word); |
| 7682 | if ((cfg_word & tidmask) != 0) |
| 7683 | return; |
| 7684 | |
| 7685 | cfg_word |= tidmask; |
| 7686 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word); |
| 7687 | |
| 7688 | /* |
| 7689 | * Clear the microcode "SDTR negotiation" done indicator for the |
| 7690 | * target to cause it to negotiate with the new setting set above. |
| 7691 | */ |
| 7692 | AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word); |
| 7693 | cfg_word &= ~tidmask; |
| 7694 | AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word); |
| 7695 | } |
| 7696 | |
| 7697 | /* |
| 7698 | * PPR (Parallel Protocol Request) Capable |
| 7699 | * |
| 7700 | * If the device supports DT mode, then it must be PPR capable. |
| 7701 | * The PPR message will be used in place of the SDTR and WDTR |
| 7702 | * messages to negotiate synchronous speed and offset, transfer |
| 7703 | * width, and protocol options. |
| 7704 | */ |
| 7705 | static void advansys_wide_enable_ppr(ADV_DVC_VAR *adv_dvc, |
| 7706 | AdvPortAddr iop_base, unsigned short tidmask) |
| 7707 | { |
| 7708 | AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able); |
| 7709 | adv_dvc->ppr_able |= tidmask; |
| 7710 | AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, adv_dvc->ppr_able); |
| 7711 | } |
| 7712 | |
| 7713 | static void |
| 7714 | advansys_wide_slave_configure(struct scsi_device *sdev, ADV_DVC_VAR *adv_dvc) |
| 7715 | { |
| 7716 | AdvPortAddr iop_base = adv_dvc->iop_base; |
| 7717 | unsigned short tidmask = 1 << sdev->id; |
| 7718 | |
| 7719 | if (sdev->lun == 0) { |
| 7720 | /* |
| 7721 | * Handle WDTR, SDTR, and Tag Queuing. If the feature |
| 7722 | * is enabled in the EEPROM and the device supports the |
| 7723 | * feature, then enable it in the microcode. |
| 7724 | */ |
| 7725 | |
| 7726 | if ((adv_dvc->wdtr_able & tidmask) && sdev->wdtr) |
| 7727 | advansys_wide_enable_wdtr(iop_base, tidmask); |
| 7728 | if ((adv_dvc->sdtr_able & tidmask) && sdev->sdtr) |
| 7729 | advansys_wide_enable_sdtr(iop_base, tidmask); |
| 7730 | if (adv_dvc->chip_type == ADV_CHIP_ASC38C1600 && sdev->ppr) |
| 7731 | advansys_wide_enable_ppr(adv_dvc, iop_base, tidmask); |
| 7732 | |
| 7733 | /* |
| 7734 | * Tag Queuing is disabled for the BIOS which runs in polled |
| 7735 | * mode and would see no benefit from Tag Queuing. Also by |
| 7736 | * disabling Tag Queuing in the BIOS devices with Tag Queuing |
| 7737 | * bugs will at least work with the BIOS. |
| 7738 | */ |
| 7739 | if ((adv_dvc->tagqng_able & tidmask) && |
| 7740 | sdev->tagged_supported) { |
| 7741 | unsigned short cfg_word; |
| 7742 | AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, cfg_word); |
| 7743 | cfg_word |= tidmask; |
| 7744 | AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, |
| 7745 | cfg_word); |
| 7746 | AdvWriteByteLram(iop_base, |
| 7747 | ASC_MC_NUMBER_OF_MAX_CMD + sdev->id, |
| 7748 | adv_dvc->max_dvc_qng); |
| 7749 | } |
| 7750 | } |
| 7751 | |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 7752 | if ((adv_dvc->tagqng_able & tidmask) && sdev->tagged_supported) |
| 7753 | scsi_change_queue_depth(sdev, adv_dvc->max_dvc_qng); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7754 | } |
| 7755 | |
| 7756 | /* |
| 7757 | * Set the number of commands to queue per device for the |
| 7758 | * specified host adapter. |
| 7759 | */ |
| 7760 | static int advansys_slave_configure(struct scsi_device *sdev) |
| 7761 | { |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 7762 | struct asc_board *boardp = shost_priv(sdev->host); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7763 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7764 | if (ASC_NARROW_BOARD(boardp)) |
| 7765 | advansys_narrow_slave_configure(sdev, |
| 7766 | &boardp->dvc_var.asc_dvc_var); |
| 7767 | else |
| 7768 | advansys_wide_slave_configure(sdev, |
| 7769 | &boardp->dvc_var.adv_dvc_var); |
| 7770 | |
| 7771 | return 0; |
| 7772 | } |
| 7773 | |
Matthew Wilcox | b249c7f | 2007-10-02 21:55:40 -0400 | [diff] [blame] | 7774 | static __le32 advansys_get_sense_buffer_dma(struct scsi_cmnd *scp) |
| 7775 | { |
| 7776 | struct asc_board *board = shost_priv(scp->device->host); |
| 7777 | scp->SCp.dma_handle = dma_map_single(board->dev, scp->sense_buffer, |
FUJITA Tomonori | b80ca4f | 2008-01-13 15:46:13 +0900 | [diff] [blame] | 7778 | SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE); |
Matthew Wilcox | b249c7f | 2007-10-02 21:55:40 -0400 | [diff] [blame] | 7779 | dma_cache_sync(board->dev, scp->sense_buffer, |
FUJITA Tomonori | b80ca4f | 2008-01-13 15:46:13 +0900 | [diff] [blame] | 7780 | SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE); |
Matthew Wilcox | b249c7f | 2007-10-02 21:55:40 -0400 | [diff] [blame] | 7781 | return cpu_to_le32(scp->SCp.dma_handle); |
| 7782 | } |
| 7783 | |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 7784 | static int asc_build_req(struct asc_board *boardp, struct scsi_cmnd *scp, |
Matthew Wilcox | 05848b6 | 2007-10-02 21:55:25 -0400 | [diff] [blame] | 7785 | struct asc_scsi_q *asc_scsi_q) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7786 | { |
Matthew Wilcox | b249c7f | 2007-10-02 21:55:40 -0400 | [diff] [blame] | 7787 | struct asc_dvc_var *asc_dvc = &boardp->dvc_var.asc_dvc_var; |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 7788 | int use_sg; |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 7789 | u32 srb_tag; |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 7790 | |
Matthew Wilcox | 05848b6 | 2007-10-02 21:55:25 -0400 | [diff] [blame] | 7791 | memset(asc_scsi_q, 0, sizeof(*asc_scsi_q)); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7792 | |
| 7793 | /* |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 7794 | * Set the srb_tag to the command tag + 1, as |
| 7795 | * srb_tag '0' is used internally by the chip. |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7796 | */ |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 7797 | srb_tag = scp->request->tag + 1; |
| 7798 | asc_scsi_q->q2.srb_tag = srb_tag; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7799 | |
| 7800 | /* |
| 7801 | * Build the ASC_SCSI_Q request. |
| 7802 | */ |
Matthew Wilcox | 05848b6 | 2007-10-02 21:55:25 -0400 | [diff] [blame] | 7803 | asc_scsi_q->cdbptr = &scp->cmnd[0]; |
| 7804 | asc_scsi_q->q2.cdb_len = scp->cmd_len; |
| 7805 | asc_scsi_q->q1.target_id = ASC_TID_TO_TARGET_ID(scp->device->id); |
| 7806 | asc_scsi_q->q1.target_lun = scp->device->lun; |
| 7807 | asc_scsi_q->q2.target_ix = |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7808 | ASC_TIDLUN_TO_IX(scp->device->id, scp->device->lun); |
Matthew Wilcox | b249c7f | 2007-10-02 21:55:40 -0400 | [diff] [blame] | 7809 | asc_scsi_q->q1.sense_addr = advansys_get_sense_buffer_dma(scp); |
FUJITA Tomonori | b80ca4f | 2008-01-13 15:46:13 +0900 | [diff] [blame] | 7810 | asc_scsi_q->q1.sense_len = SCSI_SENSE_BUFFERSIZE; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7811 | |
| 7812 | /* |
| 7813 | * If there are any outstanding requests for the current target, |
| 7814 | * then every 255th request send an ORDERED request. This heuristic |
| 7815 | * tries to retain the benefit of request sorting while preventing |
| 7816 | * request starvation. 255 is the max number of tags or pending commands |
| 7817 | * a device may have outstanding. |
| 7818 | * |
| 7819 | * The request count is incremented below for every successfully |
| 7820 | * started request. |
| 7821 | * |
| 7822 | */ |
Matthew Wilcox | b249c7f | 2007-10-02 21:55:40 -0400 | [diff] [blame] | 7823 | if ((asc_dvc->cur_dvc_qng[scp->device->id] > 0) && |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7824 | (boardp->reqcnt[scp->device->id] % 255) == 0) { |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 7825 | asc_scsi_q->q2.tag_code = ORDERED_QUEUE_TAG; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7826 | } else { |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 7827 | asc_scsi_q->q2.tag_code = SIMPLE_QUEUE_TAG; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7828 | } |
| 7829 | |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 7830 | /* Build ASC_SCSI_Q */ |
| 7831 | use_sg = scsi_dma_map(scp); |
| 7832 | if (use_sg != 0) { |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7833 | int sgcnt; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7834 | struct scatterlist *slp; |
Matthew Wilcox | 05848b6 | 2007-10-02 21:55:25 -0400 | [diff] [blame] | 7835 | struct asc_sg_head *asc_sg_head; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7836 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7837 | if (use_sg > scp->device->host->sg_tablesize) { |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 7838 | scmd_printk(KERN_ERR, scp, "use_sg %d > " |
| 7839 | "sg_tablesize %d\n", use_sg, |
| 7840 | scp->device->host->sg_tablesize); |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 7841 | scsi_dma_unmap(scp); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7842 | scp->result = HOST_BYTE(DID_ERROR); |
| 7843 | return ASC_ERROR; |
| 7844 | } |
| 7845 | |
Matthew Wilcox | 05848b6 | 2007-10-02 21:55:25 -0400 | [diff] [blame] | 7846 | asc_sg_head = kzalloc(sizeof(asc_scsi_q->sg_head) + |
| 7847 | use_sg * sizeof(struct asc_sg_list), GFP_ATOMIC); |
| 7848 | if (!asc_sg_head) { |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 7849 | scsi_dma_unmap(scp); |
Matthew Wilcox | 05848b6 | 2007-10-02 21:55:25 -0400 | [diff] [blame] | 7850 | scp->result = HOST_BYTE(DID_SOFT_ERROR); |
| 7851 | return ASC_ERROR; |
| 7852 | } |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7853 | |
Matthew Wilcox | 05848b6 | 2007-10-02 21:55:25 -0400 | [diff] [blame] | 7854 | asc_scsi_q->q1.cntl |= QC_SG_HEAD; |
| 7855 | asc_scsi_q->sg_head = asc_sg_head; |
| 7856 | asc_scsi_q->q1.data_cnt = 0; |
| 7857 | asc_scsi_q->q1.data_addr = 0; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7858 | /* This is a byte value, otherwise it would need to be swapped. */ |
Matthew Wilcox | 05848b6 | 2007-10-02 21:55:25 -0400 | [diff] [blame] | 7859 | asc_sg_head->entry_cnt = asc_scsi_q->q1.sg_queue_cnt = use_sg; |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 7860 | ASC_STATS_ADD(scp->device->host, xfer_elem, |
Matthew Wilcox | 05848b6 | 2007-10-02 21:55:25 -0400 | [diff] [blame] | 7861 | asc_sg_head->entry_cnt); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7862 | |
| 7863 | /* |
| 7864 | * Convert scatter-gather list into ASC_SG_HEAD list. |
| 7865 | */ |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 7866 | scsi_for_each_sg(scp, slp, use_sg, sgcnt) { |
Matthew Wilcox | 05848b6 | 2007-10-02 21:55:25 -0400 | [diff] [blame] | 7867 | asc_sg_head->sg_list[sgcnt].addr = |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7868 | cpu_to_le32(sg_dma_address(slp)); |
Matthew Wilcox | 05848b6 | 2007-10-02 21:55:25 -0400 | [diff] [blame] | 7869 | asc_sg_head->sg_list[sgcnt].bytes = |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7870 | cpu_to_le32(sg_dma_len(slp)); |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 7871 | ASC_STATS_ADD(scp->device->host, xfer_sect, |
| 7872 | DIV_ROUND_UP(sg_dma_len(slp), 512)); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7873 | } |
| 7874 | } |
| 7875 | |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 7876 | ASC_STATS(scp->device->host, xfer_cnt); |
| 7877 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 7878 | ASC_DBG_PRT_ASC_SCSI_Q(2, asc_scsi_q); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7879 | ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len); |
| 7880 | |
| 7881 | return ASC_NOERROR; |
| 7882 | } |
| 7883 | |
| 7884 | /* |
| 7885 | * Build scatter-gather list for Adv Library (Wide Board). |
| 7886 | * |
| 7887 | * Additional ADV_SG_BLOCK structures will need to be allocated |
| 7888 | * if the total number of scatter-gather elements exceeds |
| 7889 | * NO_OF_SG_PER_BLOCK (15). The ADV_SG_BLOCK structures are |
| 7890 | * assumed to be physically contiguous. |
| 7891 | * |
| 7892 | * Return: |
| 7893 | * ADV_SUCCESS(1) - SG List successfully created |
| 7894 | * ADV_ERROR(-1) - SG List creation failed |
| 7895 | */ |
| 7896 | static int |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 7897 | adv_get_sglist(struct asc_board *boardp, adv_req_t *reqp, |
| 7898 | ADV_SCSI_REQ_Q *scsiqp, struct scsi_cmnd *scp, int use_sg) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7899 | { |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 7900 | adv_sgblk_t *sgblkp, *prev_sgblkp; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7901 | struct scatterlist *slp; |
| 7902 | int sg_elem_cnt; |
| 7903 | ADV_SG_BLOCK *sg_block, *prev_sg_block; |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 7904 | dma_addr_t sgblk_paddr; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7905 | int i; |
| 7906 | |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 7907 | slp = scsi_sglist(scp); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7908 | sg_elem_cnt = use_sg; |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 7909 | prev_sgblkp = NULL; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7910 | prev_sg_block = NULL; |
| 7911 | reqp->sgblkp = NULL; |
| 7912 | |
| 7913 | for (;;) { |
| 7914 | /* |
| 7915 | * Allocate a 'adv_sgblk_t' structure from the board free |
| 7916 | * list. One 'adv_sgblk_t' structure holds NO_OF_SG_PER_BLOCK |
| 7917 | * (15) scatter-gather elements. |
| 7918 | */ |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 7919 | sgblkp = dma_pool_alloc(boardp->adv_sgblk_pool, GFP_ATOMIC, |
| 7920 | &sgblk_paddr); |
| 7921 | if (!sgblkp) { |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 7922 | ASC_DBG(1, "no free adv_sgblk_t\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7923 | ASC_STATS(scp->device->host, adv_build_nosg); |
| 7924 | |
| 7925 | /* |
| 7926 | * Allocation failed. Free 'adv_sgblk_t' structures |
| 7927 | * already allocated for the request. |
| 7928 | */ |
| 7929 | while ((sgblkp = reqp->sgblkp) != NULL) { |
| 7930 | /* Remove 'sgblkp' from the request list. */ |
| 7931 | reqp->sgblkp = sgblkp->next_sgblkp; |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 7932 | sgblkp->next_sgblkp = NULL; |
| 7933 | dma_pool_free(boardp->adv_sgblk_pool, sgblkp, |
| 7934 | sgblkp->sg_addr); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7935 | } |
| 7936 | return ASC_BUSY; |
| 7937 | } |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7938 | /* Complete 'adv_sgblk_t' board allocation. */ |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 7939 | sgblkp->sg_addr = sgblk_paddr; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7940 | sgblkp->next_sgblkp = NULL; |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 7941 | sg_block = &sgblkp->sg_block; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7942 | |
| 7943 | /* |
| 7944 | * Check if this is the first 'adv_sgblk_t' for the |
| 7945 | * request. |
| 7946 | */ |
| 7947 | if (reqp->sgblkp == NULL) { |
| 7948 | /* Request's first scatter-gather block. */ |
| 7949 | reqp->sgblkp = sgblkp; |
| 7950 | |
| 7951 | /* |
| 7952 | * Set ADV_SCSI_REQ_T ADV_SG_BLOCK virtual and physical |
| 7953 | * address pointers. |
| 7954 | */ |
| 7955 | scsiqp->sg_list_ptr = sg_block; |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 7956 | scsiqp->sg_real_addr = cpu_to_le32(sgblk_paddr); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7957 | } else { |
| 7958 | /* Request's second or later scatter-gather block. */ |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 7959 | prev_sgblkp->next_sgblkp = sgblkp; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7960 | |
| 7961 | /* |
| 7962 | * Point the previous ADV_SG_BLOCK structure to |
| 7963 | * the newly allocated ADV_SG_BLOCK structure. |
| 7964 | */ |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 7965 | prev_sg_block->sg_ptr = cpu_to_le32(sgblk_paddr); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7966 | } |
| 7967 | |
| 7968 | for (i = 0; i < NO_OF_SG_PER_BLOCK; i++) { |
| 7969 | sg_block->sg_list[i].sg_addr = |
| 7970 | cpu_to_le32(sg_dma_address(slp)); |
| 7971 | sg_block->sg_list[i].sg_count = |
| 7972 | cpu_to_le32(sg_dma_len(slp)); |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 7973 | ASC_STATS_ADD(scp->device->host, xfer_sect, |
| 7974 | DIV_ROUND_UP(sg_dma_len(slp), 512)); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7975 | |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 7976 | if (--sg_elem_cnt == 0) { |
| 7977 | /* |
| 7978 | * Last ADV_SG_BLOCK and scatter-gather entry. |
| 7979 | */ |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7980 | sg_block->sg_cnt = i + 1; |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 7981 | sg_block->sg_ptr = 0L; /* Last ADV_SG_BLOCK in list. */ |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7982 | return ADV_SUCCESS; |
| 7983 | } |
| 7984 | slp++; |
| 7985 | } |
| 7986 | sg_block->sg_cnt = NO_OF_SG_PER_BLOCK; |
| 7987 | prev_sg_block = sg_block; |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 7988 | prev_sgblkp = sgblkp; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 7989 | } |
| 7990 | } |
| 7991 | |
| 7992 | /* |
| 7993 | * Build a request structure for the Adv Library (Wide Board). |
| 7994 | * |
| 7995 | * If an adv_req_t can not be allocated to issue the request, |
| 7996 | * then return ASC_BUSY. If an error occurs, then return ASC_ERROR. |
| 7997 | * |
| 7998 | * Multi-byte fields in the ASC_SCSI_REQ_Q that are used by the |
| 7999 | * microcode for DMA addresses or math operations are byte swapped |
| 8000 | * to little-endian order. |
| 8001 | */ |
| 8002 | static int |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 8003 | adv_build_req(struct asc_board *boardp, struct scsi_cmnd *scp, |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 8004 | adv_req_t **adv_reqpp) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8005 | { |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 8006 | u32 srb_tag = scp->request->tag; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8007 | adv_req_t *reqp; |
| 8008 | ADV_SCSI_REQ_Q *scsiqp; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8009 | int ret; |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 8010 | int use_sg; |
Hannes Reinecke | 811ddc0 | 2015-04-24 13:18:22 +0200 | [diff] [blame] | 8011 | dma_addr_t sense_addr; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8012 | |
| 8013 | /* |
| 8014 | * Allocate an adv_req_t structure from the board to execute |
| 8015 | * the command. |
| 8016 | */ |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 8017 | reqp = &boardp->adv_reqp[srb_tag]; |
| 8018 | if (reqp->cmndp && reqp->cmndp != scp ) { |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 8019 | ASC_DBG(1, "no free adv_req_t\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8020 | ASC_STATS(scp->device->host, adv_build_noreq); |
| 8021 | return ASC_BUSY; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8022 | } |
| 8023 | |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 8024 | reqp->req_addr = boardp->adv_reqp_addr + (srb_tag * sizeof(adv_req_t)); |
| 8025 | |
| 8026 | scsiqp = &reqp->scsi_req_q; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8027 | |
| 8028 | /* |
| 8029 | * Initialize the structure. |
| 8030 | */ |
| 8031 | scsiqp->cntl = scsiqp->scsi_cntl = scsiqp->done_status = 0; |
| 8032 | |
| 8033 | /* |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 8034 | * Set the srb_tag to the command tag. |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8035 | */ |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 8036 | scsiqp->srb_tag = srb_tag; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8037 | |
| 8038 | /* |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 8039 | * Set 'host_scribble' to point to the adv_req_t structure. |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8040 | */ |
| 8041 | reqp->cmndp = scp; |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 8042 | scp->host_scribble = (void *)reqp; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8043 | |
| 8044 | /* |
| 8045 | * Build the ADV_SCSI_REQ_Q request. |
| 8046 | */ |
| 8047 | |
| 8048 | /* Set CDB length and copy it to the request structure. */ |
| 8049 | scsiqp->cdb_len = scp->cmd_len; |
| 8050 | /* Copy first 12 CDB bytes to cdb[]. */ |
Hannes Reinecke | 811ddc0 | 2015-04-24 13:18:22 +0200 | [diff] [blame] | 8051 | memcpy(scsiqp->cdb, scp->cmnd, scp->cmd_len < 12 ? scp->cmd_len : 12); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8052 | /* Copy last 4 CDB bytes, if present, to cdb16[]. */ |
Hannes Reinecke | 811ddc0 | 2015-04-24 13:18:22 +0200 | [diff] [blame] | 8053 | if (scp->cmd_len > 12) { |
| 8054 | int cdb16_len = scp->cmd_len - 12; |
| 8055 | |
| 8056 | memcpy(scsiqp->cdb16, &scp->cmnd[12], cdb16_len); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8057 | } |
| 8058 | |
| 8059 | scsiqp->target_id = scp->device->id; |
| 8060 | scsiqp->target_lun = scp->device->lun; |
| 8061 | |
Hannes Reinecke | 811ddc0 | 2015-04-24 13:18:22 +0200 | [diff] [blame] | 8062 | sense_addr = dma_map_single(boardp->dev, scp->sense_buffer, |
| 8063 | SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE); |
| 8064 | scsiqp->sense_addr = cpu_to_le32(sense_addr); |
| 8065 | scsiqp->sense_len = cpu_to_le32(SCSI_SENSE_BUFFERSIZE); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8066 | |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 8067 | /* Build ADV_SCSI_REQ_Q */ |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8068 | |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 8069 | use_sg = scsi_dma_map(scp); |
| 8070 | if (use_sg == 0) { |
| 8071 | /* Zero-length transfer */ |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8072 | reqp->sgblkp = NULL; |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 8073 | scsiqp->data_cnt = 0; |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 8074 | |
| 8075 | scsiqp->data_addr = 0; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8076 | scsiqp->sg_list_ptr = NULL; |
| 8077 | scsiqp->sg_real_addr = 0; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8078 | } else { |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8079 | if (use_sg > ADV_MAX_SG_LIST) { |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 8080 | scmd_printk(KERN_ERR, scp, "use_sg %d > " |
| 8081 | "ADV_MAX_SG_LIST %d\n", use_sg, |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8082 | scp->device->host->sg_tablesize); |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 8083 | scsi_dma_unmap(scp); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8084 | scp->result = HOST_BYTE(DID_ERROR); |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 8085 | reqp->cmndp = NULL; |
| 8086 | scp->host_scribble = NULL; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8087 | |
| 8088 | return ASC_ERROR; |
| 8089 | } |
| 8090 | |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 8091 | scsiqp->data_cnt = cpu_to_le32(scsi_bufflen(scp)); |
| 8092 | |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 8093 | ret = adv_get_sglist(boardp, reqp, scsiqp, scp, use_sg); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8094 | if (ret != ADV_SUCCESS) { |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 8095 | scsi_dma_unmap(scp); |
| 8096 | scp->result = HOST_BYTE(DID_ERROR); |
| 8097 | reqp->cmndp = NULL; |
| 8098 | scp->host_scribble = NULL; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8099 | |
| 8100 | return ret; |
| 8101 | } |
| 8102 | |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 8103 | ASC_STATS_ADD(scp->device->host, xfer_elem, use_sg); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8104 | } |
| 8105 | |
Matthew Wilcox | 52c334e | 2007-10-02 21:55:39 -0400 | [diff] [blame] | 8106 | ASC_STATS(scp->device->host, xfer_cnt); |
| 8107 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8108 | ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp); |
| 8109 | ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len); |
| 8110 | |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 8111 | *adv_reqpp = reqp; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8112 | |
| 8113 | return ASC_NOERROR; |
| 8114 | } |
| 8115 | |
| 8116 | static int AscSgListToQueue(int sg_list) |
| 8117 | { |
| 8118 | int n_sg_list_qs; |
| 8119 | |
| 8120 | n_sg_list_qs = ((sg_list - 1) / ASC_SG_LIST_PER_Q); |
| 8121 | if (((sg_list - 1) % ASC_SG_LIST_PER_Q) != 0) |
| 8122 | n_sg_list_qs++; |
| 8123 | return n_sg_list_qs + 1; |
| 8124 | } |
| 8125 | |
| 8126 | static uint |
| 8127 | AscGetNumOfFreeQueue(ASC_DVC_VAR *asc_dvc, uchar target_ix, uchar n_qs) |
| 8128 | { |
| 8129 | uint cur_used_qs; |
| 8130 | uint cur_free_qs; |
| 8131 | ASC_SCSI_BIT_ID_TYPE target_id; |
| 8132 | uchar tid_no; |
| 8133 | |
| 8134 | target_id = ASC_TIX_TO_TARGET_ID(target_ix); |
| 8135 | tid_no = ASC_TIX_TO_TID(target_ix); |
| 8136 | if ((asc_dvc->unit_not_ready & target_id) || |
| 8137 | (asc_dvc->queue_full_or_busy & target_id)) { |
| 8138 | return 0; |
| 8139 | } |
| 8140 | if (n_qs == 1) { |
| 8141 | cur_used_qs = (uint) asc_dvc->cur_total_qng + |
| 8142 | (uint) asc_dvc->last_q_shortage + (uint) ASC_MIN_FREE_Q; |
| 8143 | } else { |
| 8144 | cur_used_qs = (uint) asc_dvc->cur_total_qng + |
| 8145 | (uint) ASC_MIN_FREE_Q; |
| 8146 | } |
| 8147 | if ((uint) (cur_used_qs + n_qs) <= (uint) asc_dvc->max_total_qng) { |
| 8148 | cur_free_qs = (uint) asc_dvc->max_total_qng - cur_used_qs; |
| 8149 | if (asc_dvc->cur_dvc_qng[tid_no] >= |
| 8150 | asc_dvc->max_dvc_qng[tid_no]) { |
| 8151 | return 0; |
| 8152 | } |
| 8153 | return cur_free_qs; |
| 8154 | } |
| 8155 | if (n_qs > 1) { |
| 8156 | if ((n_qs > asc_dvc->last_q_shortage) |
| 8157 | && (n_qs <= (asc_dvc->max_total_qng - ASC_MIN_FREE_Q))) { |
| 8158 | asc_dvc->last_q_shortage = n_qs; |
| 8159 | } |
| 8160 | } |
| 8161 | return 0; |
| 8162 | } |
| 8163 | |
| 8164 | static uchar AscAllocFreeQueue(PortAddr iop_base, uchar free_q_head) |
| 8165 | { |
| 8166 | ushort q_addr; |
| 8167 | uchar next_qp; |
| 8168 | uchar q_status; |
| 8169 | |
| 8170 | q_addr = ASC_QNO_TO_QADDR(free_q_head); |
| 8171 | q_status = (uchar)AscReadLramByte(iop_base, |
| 8172 | (ushort)(q_addr + |
| 8173 | ASC_SCSIQ_B_STATUS)); |
| 8174 | next_qp = AscReadLramByte(iop_base, (ushort)(q_addr + ASC_SCSIQ_B_FWD)); |
| 8175 | if (((q_status & QS_READY) == 0) && (next_qp != ASC_QLINK_END)) |
| 8176 | return next_qp; |
| 8177 | return ASC_QLINK_END; |
| 8178 | } |
| 8179 | |
| 8180 | static uchar |
| 8181 | AscAllocMultipleFreeQueue(PortAddr iop_base, uchar free_q_head, uchar n_free_q) |
| 8182 | { |
| 8183 | uchar i; |
| 8184 | |
| 8185 | for (i = 0; i < n_free_q; i++) { |
| 8186 | free_q_head = AscAllocFreeQueue(iop_base, free_q_head); |
| 8187 | if (free_q_head == ASC_QLINK_END) |
| 8188 | break; |
| 8189 | } |
| 8190 | return free_q_head; |
| 8191 | } |
| 8192 | |
| 8193 | /* |
| 8194 | * void |
| 8195 | * DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words) |
| 8196 | * |
| 8197 | * Calling/Exit State: |
| 8198 | * none |
| 8199 | * |
| 8200 | * Description: |
| 8201 | * Output an ASC_SCSI_Q structure to the chip |
| 8202 | */ |
| 8203 | static void |
| 8204 | DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words) |
| 8205 | { |
| 8206 | int i; |
| 8207 | |
| 8208 | ASC_DBG_PRT_HEX(2, "DvcPutScsiQ", outbuf, 2 * words); |
| 8209 | AscSetChipLramAddr(iop_base, s_addr); |
| 8210 | for (i = 0; i < 2 * words; i += 2) { |
| 8211 | if (i == 4 || i == 20) { |
| 8212 | continue; |
| 8213 | } |
| 8214 | outpw(iop_base + IOP_RAM_DATA, |
| 8215 | ((ushort)outbuf[i + 1] << 8) | outbuf[i]); |
| 8216 | } |
| 8217 | } |
| 8218 | |
| 8219 | static int AscPutReadyQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no) |
| 8220 | { |
| 8221 | ushort q_addr; |
| 8222 | uchar tid_no; |
| 8223 | uchar sdtr_data; |
| 8224 | uchar syn_period_ix; |
| 8225 | uchar syn_offset; |
| 8226 | PortAddr iop_base; |
| 8227 | |
| 8228 | iop_base = asc_dvc->iop_base; |
| 8229 | if (((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) && |
| 8230 | ((asc_dvc->sdtr_done & scsiq->q1.target_id) == 0)) { |
| 8231 | tid_no = ASC_TIX_TO_TID(scsiq->q2.target_ix); |
| 8232 | sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no); |
| 8233 | syn_period_ix = |
| 8234 | (sdtr_data >> 4) & (asc_dvc->max_sdtr_index - 1); |
| 8235 | syn_offset = sdtr_data & ASC_SYN_MAX_OFFSET; |
| 8236 | AscMsgOutSDTR(asc_dvc, |
| 8237 | asc_dvc->sdtr_period_tbl[syn_period_ix], |
| 8238 | syn_offset); |
| 8239 | scsiq->q1.cntl |= QC_MSG_OUT; |
| 8240 | } |
| 8241 | q_addr = ASC_QNO_TO_QADDR(q_no); |
| 8242 | if ((scsiq->q1.target_id & asc_dvc->use_tagged_qng) == 0) { |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 8243 | scsiq->q2.tag_code &= ~SIMPLE_QUEUE_TAG; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8244 | } |
| 8245 | scsiq->q1.status = QS_FREE; |
| 8246 | AscMemWordCopyPtrToLram(iop_base, |
| 8247 | q_addr + ASC_SCSIQ_CDB_BEG, |
| 8248 | (uchar *)scsiq->cdbptr, scsiq->q2.cdb_len >> 1); |
| 8249 | |
| 8250 | DvcPutScsiQ(iop_base, |
| 8251 | q_addr + ASC_SCSIQ_CPY_BEG, |
| 8252 | (uchar *)&scsiq->q1.cntl, |
| 8253 | ((sizeof(ASC_SCSIQ_1) + sizeof(ASC_SCSIQ_2)) / 2) - 1); |
| 8254 | AscWriteLramWord(iop_base, |
| 8255 | (ushort)(q_addr + (ushort)ASC_SCSIQ_B_STATUS), |
| 8256 | (ushort)(((ushort)scsiq->q1. |
| 8257 | q_no << 8) | (ushort)QS_READY)); |
| 8258 | return 1; |
| 8259 | } |
| 8260 | |
| 8261 | static int |
| 8262 | AscPutReadySgListQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar q_no) |
| 8263 | { |
| 8264 | int sta; |
| 8265 | int i; |
| 8266 | ASC_SG_HEAD *sg_head; |
| 8267 | ASC_SG_LIST_Q scsi_sg_q; |
| 8268 | ASC_DCNT saved_data_addr; |
| 8269 | ASC_DCNT saved_data_cnt; |
| 8270 | PortAddr iop_base; |
| 8271 | ushort sg_list_dwords; |
| 8272 | ushort sg_index; |
| 8273 | ushort sg_entry_cnt; |
| 8274 | ushort q_addr; |
| 8275 | uchar next_qp; |
| 8276 | |
| 8277 | iop_base = asc_dvc->iop_base; |
| 8278 | sg_head = scsiq->sg_head; |
| 8279 | saved_data_addr = scsiq->q1.data_addr; |
| 8280 | saved_data_cnt = scsiq->q1.data_cnt; |
| 8281 | scsiq->q1.data_addr = (ASC_PADDR) sg_head->sg_list[0].addr; |
| 8282 | scsiq->q1.data_cnt = (ASC_DCNT) sg_head->sg_list[0].bytes; |
| 8283 | #if CC_VERY_LONG_SG_LIST |
| 8284 | /* |
| 8285 | * If sg_head->entry_cnt is greater than ASC_MAX_SG_LIST |
| 8286 | * then not all SG elements will fit in the allocated queues. |
| 8287 | * The rest of the SG elements will be copied when the RISC |
| 8288 | * completes the SG elements that fit and halts. |
| 8289 | */ |
| 8290 | if (sg_head->entry_cnt > ASC_MAX_SG_LIST) { |
| 8291 | /* |
| 8292 | * Set sg_entry_cnt to be the number of SG elements that |
| 8293 | * will fit in the allocated SG queues. It is minus 1, because |
| 8294 | * the first SG element is handled above. ASC_MAX_SG_LIST is |
| 8295 | * already inflated by 1 to account for this. For example it |
| 8296 | * may be 50 which is 1 + 7 queues * 7 SG elements. |
| 8297 | */ |
| 8298 | sg_entry_cnt = ASC_MAX_SG_LIST - 1; |
| 8299 | |
| 8300 | /* |
| 8301 | * Keep track of remaining number of SG elements that will |
| 8302 | * need to be handled from a_isr.c. |
| 8303 | */ |
| 8304 | scsiq->remain_sg_entry_cnt = |
| 8305 | sg_head->entry_cnt - ASC_MAX_SG_LIST; |
| 8306 | } else { |
| 8307 | #endif /* CC_VERY_LONG_SG_LIST */ |
| 8308 | /* |
| 8309 | * Set sg_entry_cnt to be the number of SG elements that |
| 8310 | * will fit in the allocated SG queues. It is minus 1, because |
| 8311 | * the first SG element is handled above. |
| 8312 | */ |
| 8313 | sg_entry_cnt = sg_head->entry_cnt - 1; |
| 8314 | #if CC_VERY_LONG_SG_LIST |
| 8315 | } |
| 8316 | #endif /* CC_VERY_LONG_SG_LIST */ |
| 8317 | if (sg_entry_cnt != 0) { |
| 8318 | scsiq->q1.cntl |= QC_SG_HEAD; |
| 8319 | q_addr = ASC_QNO_TO_QADDR(q_no); |
| 8320 | sg_index = 1; |
| 8321 | scsiq->q1.sg_queue_cnt = sg_head->queue_cnt; |
| 8322 | scsi_sg_q.sg_head_qp = q_no; |
| 8323 | scsi_sg_q.cntl = QCSG_SG_XFER_LIST; |
| 8324 | for (i = 0; i < sg_head->queue_cnt; i++) { |
| 8325 | scsi_sg_q.seq_no = i + 1; |
| 8326 | if (sg_entry_cnt > ASC_SG_LIST_PER_Q) { |
| 8327 | sg_list_dwords = (uchar)(ASC_SG_LIST_PER_Q * 2); |
| 8328 | sg_entry_cnt -= ASC_SG_LIST_PER_Q; |
| 8329 | if (i == 0) { |
| 8330 | scsi_sg_q.sg_list_cnt = |
| 8331 | ASC_SG_LIST_PER_Q; |
| 8332 | scsi_sg_q.sg_cur_list_cnt = |
| 8333 | ASC_SG_LIST_PER_Q; |
| 8334 | } else { |
| 8335 | scsi_sg_q.sg_list_cnt = |
| 8336 | ASC_SG_LIST_PER_Q - 1; |
| 8337 | scsi_sg_q.sg_cur_list_cnt = |
| 8338 | ASC_SG_LIST_PER_Q - 1; |
| 8339 | } |
| 8340 | } else { |
| 8341 | #if CC_VERY_LONG_SG_LIST |
| 8342 | /* |
| 8343 | * This is the last SG queue in the list of |
| 8344 | * allocated SG queues. If there are more |
| 8345 | * SG elements than will fit in the allocated |
| 8346 | * queues, then set the QCSG_SG_XFER_MORE flag. |
| 8347 | */ |
| 8348 | if (sg_head->entry_cnt > ASC_MAX_SG_LIST) { |
| 8349 | scsi_sg_q.cntl |= QCSG_SG_XFER_MORE; |
| 8350 | } else { |
| 8351 | #endif /* CC_VERY_LONG_SG_LIST */ |
| 8352 | scsi_sg_q.cntl |= QCSG_SG_XFER_END; |
| 8353 | #if CC_VERY_LONG_SG_LIST |
| 8354 | } |
| 8355 | #endif /* CC_VERY_LONG_SG_LIST */ |
| 8356 | sg_list_dwords = sg_entry_cnt << 1; |
| 8357 | if (i == 0) { |
| 8358 | scsi_sg_q.sg_list_cnt = sg_entry_cnt; |
| 8359 | scsi_sg_q.sg_cur_list_cnt = |
| 8360 | sg_entry_cnt; |
| 8361 | } else { |
| 8362 | scsi_sg_q.sg_list_cnt = |
| 8363 | sg_entry_cnt - 1; |
| 8364 | scsi_sg_q.sg_cur_list_cnt = |
| 8365 | sg_entry_cnt - 1; |
| 8366 | } |
| 8367 | sg_entry_cnt = 0; |
| 8368 | } |
| 8369 | next_qp = AscReadLramByte(iop_base, |
| 8370 | (ushort)(q_addr + |
| 8371 | ASC_SCSIQ_B_FWD)); |
| 8372 | scsi_sg_q.q_no = next_qp; |
| 8373 | q_addr = ASC_QNO_TO_QADDR(next_qp); |
| 8374 | AscMemWordCopyPtrToLram(iop_base, |
| 8375 | q_addr + ASC_SCSIQ_SGHD_CPY_BEG, |
| 8376 | (uchar *)&scsi_sg_q, |
| 8377 | sizeof(ASC_SG_LIST_Q) >> 1); |
| 8378 | AscMemDWordCopyPtrToLram(iop_base, |
| 8379 | q_addr + ASC_SGQ_LIST_BEG, |
| 8380 | (uchar *)&sg_head-> |
| 8381 | sg_list[sg_index], |
| 8382 | sg_list_dwords); |
| 8383 | sg_index += ASC_SG_LIST_PER_Q; |
| 8384 | scsiq->next_sg_index = sg_index; |
| 8385 | } |
| 8386 | } else { |
| 8387 | scsiq->q1.cntl &= ~QC_SG_HEAD; |
| 8388 | } |
| 8389 | sta = AscPutReadyQueue(asc_dvc, scsiq, q_no); |
| 8390 | scsiq->q1.data_addr = saved_data_addr; |
| 8391 | scsiq->q1.data_cnt = saved_data_cnt; |
| 8392 | return (sta); |
| 8393 | } |
| 8394 | |
| 8395 | static int |
| 8396 | AscSendScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq, uchar n_q_required) |
| 8397 | { |
| 8398 | PortAddr iop_base; |
| 8399 | uchar free_q_head; |
| 8400 | uchar next_qp; |
| 8401 | uchar tid_no; |
| 8402 | uchar target_ix; |
| 8403 | int sta; |
| 8404 | |
| 8405 | iop_base = asc_dvc->iop_base; |
| 8406 | target_ix = scsiq->q2.target_ix; |
| 8407 | tid_no = ASC_TIX_TO_TID(target_ix); |
| 8408 | sta = 0; |
| 8409 | free_q_head = (uchar)AscGetVarFreeQHead(iop_base); |
| 8410 | if (n_q_required > 1) { |
| 8411 | next_qp = AscAllocMultipleFreeQueue(iop_base, free_q_head, |
| 8412 | (uchar)n_q_required); |
| 8413 | if (next_qp != ASC_QLINK_END) { |
| 8414 | asc_dvc->last_q_shortage = 0; |
| 8415 | scsiq->sg_head->queue_cnt = n_q_required - 1; |
| 8416 | scsiq->q1.q_no = free_q_head; |
| 8417 | sta = AscPutReadySgListQueue(asc_dvc, scsiq, |
| 8418 | free_q_head); |
| 8419 | } |
| 8420 | } else if (n_q_required == 1) { |
| 8421 | next_qp = AscAllocFreeQueue(iop_base, free_q_head); |
| 8422 | if (next_qp != ASC_QLINK_END) { |
| 8423 | scsiq->q1.q_no = free_q_head; |
| 8424 | sta = AscPutReadyQueue(asc_dvc, scsiq, free_q_head); |
| 8425 | } |
| 8426 | } |
| 8427 | if (sta == 1) { |
| 8428 | AscPutVarFreeQHead(iop_base, next_qp); |
| 8429 | asc_dvc->cur_total_qng += n_q_required; |
| 8430 | asc_dvc->cur_dvc_qng[tid_no]++; |
| 8431 | } |
| 8432 | return sta; |
| 8433 | } |
| 8434 | |
| 8435 | #define ASC_SYN_OFFSET_ONE_DISABLE_LIST 16 |
| 8436 | static uchar _syn_offset_one_disable_cmd[ASC_SYN_OFFSET_ONE_DISABLE_LIST] = { |
| 8437 | INQUIRY, |
| 8438 | REQUEST_SENSE, |
| 8439 | READ_CAPACITY, |
| 8440 | READ_TOC, |
| 8441 | MODE_SELECT, |
| 8442 | MODE_SENSE, |
| 8443 | MODE_SELECT_10, |
| 8444 | MODE_SENSE_10, |
| 8445 | 0xFF, |
| 8446 | 0xFF, |
| 8447 | 0xFF, |
| 8448 | 0xFF, |
| 8449 | 0xFF, |
| 8450 | 0xFF, |
| 8451 | 0xFF, |
| 8452 | 0xFF |
| 8453 | }; |
| 8454 | |
| 8455 | static int AscExeScsiQueue(ASC_DVC_VAR *asc_dvc, ASC_SCSI_Q *scsiq) |
| 8456 | { |
| 8457 | PortAddr iop_base; |
| 8458 | int sta; |
| 8459 | int n_q_required; |
| 8460 | int disable_syn_offset_one_fix; |
| 8461 | int i; |
| 8462 | ASC_PADDR addr; |
| 8463 | ushort sg_entry_cnt = 0; |
| 8464 | ushort sg_entry_cnt_minus_one = 0; |
| 8465 | uchar target_ix; |
| 8466 | uchar tid_no; |
| 8467 | uchar sdtr_data; |
| 8468 | uchar extra_bytes; |
| 8469 | uchar scsi_cmd; |
| 8470 | uchar disable_cmd; |
| 8471 | ASC_SG_HEAD *sg_head; |
| 8472 | ASC_DCNT data_cnt; |
| 8473 | |
| 8474 | iop_base = asc_dvc->iop_base; |
| 8475 | sg_head = scsiq->sg_head; |
| 8476 | if (asc_dvc->err_code != 0) |
| 8477 | return (ERR); |
| 8478 | scsiq->q1.q_no = 0; |
| 8479 | if ((scsiq->q2.tag_code & ASC_TAG_FLAG_EXTRA_BYTES) == 0) { |
| 8480 | scsiq->q1.extra_bytes = 0; |
| 8481 | } |
| 8482 | sta = 0; |
| 8483 | target_ix = scsiq->q2.target_ix; |
| 8484 | tid_no = ASC_TIX_TO_TID(target_ix); |
| 8485 | n_q_required = 1; |
| 8486 | if (scsiq->cdbptr[0] == REQUEST_SENSE) { |
| 8487 | if ((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) { |
| 8488 | asc_dvc->sdtr_done &= ~scsiq->q1.target_id; |
| 8489 | sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no); |
| 8490 | AscMsgOutSDTR(asc_dvc, |
| 8491 | asc_dvc-> |
| 8492 | sdtr_period_tbl[(sdtr_data >> 4) & |
| 8493 | (uchar)(asc_dvc-> |
| 8494 | max_sdtr_index - |
| 8495 | 1)], |
| 8496 | (uchar)(sdtr_data & (uchar) |
| 8497 | ASC_SYN_MAX_OFFSET)); |
| 8498 | scsiq->q1.cntl |= (QC_MSG_OUT | QC_URGENT); |
| 8499 | } |
| 8500 | } |
| 8501 | if (asc_dvc->in_critical_cnt != 0) { |
| 8502 | AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CRITICAL_RE_ENTRY); |
| 8503 | return (ERR); |
| 8504 | } |
| 8505 | asc_dvc->in_critical_cnt++; |
| 8506 | if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) { |
| 8507 | if ((sg_entry_cnt = sg_head->entry_cnt) == 0) { |
| 8508 | asc_dvc->in_critical_cnt--; |
| 8509 | return (ERR); |
| 8510 | } |
| 8511 | #if !CC_VERY_LONG_SG_LIST |
| 8512 | if (sg_entry_cnt > ASC_MAX_SG_LIST) { |
| 8513 | asc_dvc->in_critical_cnt--; |
| 8514 | return (ERR); |
| 8515 | } |
| 8516 | #endif /* !CC_VERY_LONG_SG_LIST */ |
| 8517 | if (sg_entry_cnt == 1) { |
| 8518 | scsiq->q1.data_addr = |
| 8519 | (ADV_PADDR)sg_head->sg_list[0].addr; |
| 8520 | scsiq->q1.data_cnt = |
| 8521 | (ADV_DCNT)sg_head->sg_list[0].bytes; |
| 8522 | scsiq->q1.cntl &= ~(QC_SG_HEAD | QC_SG_SWAP_QUEUE); |
| 8523 | } |
| 8524 | sg_entry_cnt_minus_one = sg_entry_cnt - 1; |
| 8525 | } |
| 8526 | scsi_cmd = scsiq->cdbptr[0]; |
| 8527 | disable_syn_offset_one_fix = FALSE; |
| 8528 | if ((asc_dvc->pci_fix_asyn_xfer & scsiq->q1.target_id) && |
| 8529 | !(asc_dvc->pci_fix_asyn_xfer_always & scsiq->q1.target_id)) { |
| 8530 | if (scsiq->q1.cntl & QC_SG_HEAD) { |
| 8531 | data_cnt = 0; |
| 8532 | for (i = 0; i < sg_entry_cnt; i++) { |
| 8533 | data_cnt += |
| 8534 | (ADV_DCNT)le32_to_cpu(sg_head->sg_list[i]. |
| 8535 | bytes); |
| 8536 | } |
| 8537 | } else { |
| 8538 | data_cnt = le32_to_cpu(scsiq->q1.data_cnt); |
| 8539 | } |
| 8540 | if (data_cnt != 0UL) { |
| 8541 | if (data_cnt < 512UL) { |
| 8542 | disable_syn_offset_one_fix = TRUE; |
| 8543 | } else { |
| 8544 | for (i = 0; i < ASC_SYN_OFFSET_ONE_DISABLE_LIST; |
| 8545 | i++) { |
| 8546 | disable_cmd = |
| 8547 | _syn_offset_one_disable_cmd[i]; |
| 8548 | if (disable_cmd == 0xFF) { |
| 8549 | break; |
| 8550 | } |
| 8551 | if (scsi_cmd == disable_cmd) { |
| 8552 | disable_syn_offset_one_fix = |
| 8553 | TRUE; |
| 8554 | break; |
| 8555 | } |
| 8556 | } |
| 8557 | } |
| 8558 | } |
| 8559 | } |
| 8560 | if (disable_syn_offset_one_fix) { |
Christoph Hellwig | 68d81f4 | 2014-11-24 07:07:25 -0800 | [diff] [blame] | 8561 | scsiq->q2.tag_code &= ~SIMPLE_QUEUE_TAG; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8562 | scsiq->q2.tag_code |= (ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX | |
| 8563 | ASC_TAG_FLAG_DISABLE_DISCONNECT); |
| 8564 | } else { |
| 8565 | scsiq->q2.tag_code &= 0x27; |
| 8566 | } |
| 8567 | if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) { |
| 8568 | if (asc_dvc->bug_fix_cntl) { |
| 8569 | if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) { |
| 8570 | if ((scsi_cmd == READ_6) || |
| 8571 | (scsi_cmd == READ_10)) { |
| 8572 | addr = |
| 8573 | (ADV_PADDR)le32_to_cpu(sg_head-> |
| 8574 | sg_list |
| 8575 | [sg_entry_cnt_minus_one]. |
| 8576 | addr) + |
| 8577 | (ADV_DCNT)le32_to_cpu(sg_head-> |
| 8578 | sg_list |
| 8579 | [sg_entry_cnt_minus_one]. |
| 8580 | bytes); |
| 8581 | extra_bytes = |
| 8582 | (uchar)((ushort)addr & 0x0003); |
| 8583 | if ((extra_bytes != 0) |
| 8584 | && |
| 8585 | ((scsiq->q2. |
| 8586 | tag_code & |
| 8587 | ASC_TAG_FLAG_EXTRA_BYTES) |
| 8588 | == 0)) { |
| 8589 | scsiq->q2.tag_code |= |
| 8590 | ASC_TAG_FLAG_EXTRA_BYTES; |
| 8591 | scsiq->q1.extra_bytes = |
| 8592 | extra_bytes; |
| 8593 | data_cnt = |
| 8594 | le32_to_cpu(sg_head-> |
| 8595 | sg_list |
| 8596 | [sg_entry_cnt_minus_one]. |
| 8597 | bytes); |
| 8598 | data_cnt -= |
| 8599 | (ASC_DCNT) extra_bytes; |
| 8600 | sg_head-> |
| 8601 | sg_list |
| 8602 | [sg_entry_cnt_minus_one]. |
| 8603 | bytes = |
| 8604 | cpu_to_le32(data_cnt); |
| 8605 | } |
| 8606 | } |
| 8607 | } |
| 8608 | } |
| 8609 | sg_head->entry_to_copy = sg_head->entry_cnt; |
| 8610 | #if CC_VERY_LONG_SG_LIST |
| 8611 | /* |
| 8612 | * Set the sg_entry_cnt to the maximum possible. The rest of |
| 8613 | * the SG elements will be copied when the RISC completes the |
| 8614 | * SG elements that fit and halts. |
| 8615 | */ |
| 8616 | if (sg_entry_cnt > ASC_MAX_SG_LIST) { |
| 8617 | sg_entry_cnt = ASC_MAX_SG_LIST; |
| 8618 | } |
| 8619 | #endif /* CC_VERY_LONG_SG_LIST */ |
| 8620 | n_q_required = AscSgListToQueue(sg_entry_cnt); |
| 8621 | if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, n_q_required) >= |
| 8622 | (uint) n_q_required) |
| 8623 | || ((scsiq->q1.cntl & QC_URGENT) != 0)) { |
| 8624 | if ((sta = |
| 8625 | AscSendScsiQueue(asc_dvc, scsiq, |
| 8626 | n_q_required)) == 1) { |
| 8627 | asc_dvc->in_critical_cnt--; |
| 8628 | return (sta); |
| 8629 | } |
| 8630 | } |
| 8631 | } else { |
| 8632 | if (asc_dvc->bug_fix_cntl) { |
| 8633 | if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) { |
| 8634 | if ((scsi_cmd == READ_6) || |
| 8635 | (scsi_cmd == READ_10)) { |
| 8636 | addr = |
| 8637 | le32_to_cpu(scsiq->q1.data_addr) + |
| 8638 | le32_to_cpu(scsiq->q1.data_cnt); |
| 8639 | extra_bytes = |
| 8640 | (uchar)((ushort)addr & 0x0003); |
| 8641 | if ((extra_bytes != 0) |
| 8642 | && |
| 8643 | ((scsiq->q2. |
| 8644 | tag_code & |
| 8645 | ASC_TAG_FLAG_EXTRA_BYTES) |
| 8646 | == 0)) { |
| 8647 | data_cnt = |
| 8648 | le32_to_cpu(scsiq->q1. |
| 8649 | data_cnt); |
| 8650 | if (((ushort)data_cnt & 0x01FF) |
| 8651 | == 0) { |
| 8652 | scsiq->q2.tag_code |= |
| 8653 | ASC_TAG_FLAG_EXTRA_BYTES; |
| 8654 | data_cnt -= (ASC_DCNT) |
| 8655 | extra_bytes; |
| 8656 | scsiq->q1.data_cnt = |
| 8657 | cpu_to_le32 |
| 8658 | (data_cnt); |
| 8659 | scsiq->q1.extra_bytes = |
| 8660 | extra_bytes; |
| 8661 | } |
| 8662 | } |
| 8663 | } |
| 8664 | } |
| 8665 | } |
| 8666 | n_q_required = 1; |
| 8667 | if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, 1) >= 1) || |
| 8668 | ((scsiq->q1.cntl & QC_URGENT) != 0)) { |
| 8669 | if ((sta = AscSendScsiQueue(asc_dvc, scsiq, |
| 8670 | n_q_required)) == 1) { |
| 8671 | asc_dvc->in_critical_cnt--; |
| 8672 | return (sta); |
| 8673 | } |
| 8674 | } |
| 8675 | } |
| 8676 | asc_dvc->in_critical_cnt--; |
| 8677 | return (sta); |
| 8678 | } |
| 8679 | |
| 8680 | /* |
| 8681 | * AdvExeScsiQueue() - Send a request to the RISC microcode program. |
| 8682 | * |
| 8683 | * Allocate a carrier structure, point the carrier to the ADV_SCSI_REQ_Q, |
| 8684 | * add the carrier to the ICQ (Initiator Command Queue), and tickle the |
| 8685 | * RISC to notify it a new command is ready to be executed. |
| 8686 | * |
| 8687 | * If 'done_status' is not set to QD_DO_RETRY, then 'error_retry' will be |
| 8688 | * set to SCSI_MAX_RETRY. |
| 8689 | * |
| 8690 | * Multi-byte fields in the ASC_SCSI_REQ_Q that are used by the microcode |
| 8691 | * for DMA addresses or math operations are byte swapped to little-endian |
| 8692 | * order. |
| 8693 | * |
| 8694 | * Return: |
| 8695 | * ADV_SUCCESS(1) - The request was successfully queued. |
| 8696 | * ADV_BUSY(0) - Resource unavailable; Retry again after pending |
| 8697 | * request completes. |
| 8698 | * ADV_ERROR(-1) - Invalid ADV_SCSI_REQ_Q request structure |
| 8699 | * host IC error. |
| 8700 | */ |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 8701 | static int AdvExeScsiQueue(ADV_DVC_VAR *asc_dvc, adv_req_t *reqp) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8702 | { |
| 8703 | AdvPortAddr iop_base; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8704 | ADV_CARR_T *new_carrp; |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 8705 | ADV_SCSI_REQ_Q *scsiq = &reqp->scsi_req_q; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8706 | |
| 8707 | /* |
| 8708 | * The ADV_SCSI_REQ_Q 'target_id' field should never exceed ADV_MAX_TID. |
| 8709 | */ |
| 8710 | if (scsiq->target_id > ADV_MAX_TID) { |
| 8711 | scsiq->host_status = QHSTA_M_INVALID_DEVICE; |
| 8712 | scsiq->done_status = QD_WITH_ERROR; |
| 8713 | return ADV_ERROR; |
| 8714 | } |
| 8715 | |
| 8716 | iop_base = asc_dvc->iop_base; |
| 8717 | |
| 8718 | /* |
| 8719 | * Allocate a carrier ensuring at least one carrier always |
| 8720 | * remains on the freelist and initialize fields. |
| 8721 | */ |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 8722 | new_carrp = adv_get_next_carrier(asc_dvc); |
| 8723 | if (!new_carrp) { |
| 8724 | ASC_DBG(1, "No free carriers\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8725 | return ADV_BUSY; |
| 8726 | } |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8727 | |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 8728 | asc_dvc->carr_pending_cnt++; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8729 | |
| 8730 | /* |
| 8731 | * Clear the ADV_SCSI_REQ_Q done flag. |
| 8732 | */ |
| 8733 | scsiq->a_flag &= ~ADV_SCSIQ_DONE; |
| 8734 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8735 | /* Save virtual and physical address of ADV_SCSI_REQ_Q and carrier. */ |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 8736 | scsiq->scsiq_ptr = cpu_to_le32(scsiq->srb_tag); |
| 8737 | scsiq->scsiq_rptr = cpu_to_le32(reqp->req_addr); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8738 | |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 8739 | scsiq->carr_va = asc_dvc->icq_sp->carr_va; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8740 | scsiq->carr_pa = asc_dvc->icq_sp->carr_pa; |
| 8741 | |
| 8742 | /* |
| 8743 | * Use the current stopper to send the ADV_SCSI_REQ_Q command to |
| 8744 | * the microcode. The newly allocated stopper will become the new |
| 8745 | * stopper. |
| 8746 | */ |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 8747 | asc_dvc->icq_sp->areq_vpa = scsiq->scsiq_rptr; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8748 | |
| 8749 | /* |
| 8750 | * Set the 'next_vpa' pointer for the old stopper to be the |
| 8751 | * physical address of the new stopper. The RISC can only |
| 8752 | * follow physical addresses. |
| 8753 | */ |
| 8754 | asc_dvc->icq_sp->next_vpa = new_carrp->carr_pa; |
| 8755 | |
| 8756 | /* |
| 8757 | * Set the host adapter stopper pointer to point to the new carrier. |
| 8758 | */ |
| 8759 | asc_dvc->icq_sp = new_carrp; |
| 8760 | |
| 8761 | if (asc_dvc->chip_type == ADV_CHIP_ASC3550 || |
| 8762 | asc_dvc->chip_type == ADV_CHIP_ASC38C0800) { |
| 8763 | /* |
| 8764 | * Tickle the RISC to tell it to read its Command Queue Head pointer. |
| 8765 | */ |
| 8766 | AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_A); |
| 8767 | if (asc_dvc->chip_type == ADV_CHIP_ASC3550) { |
| 8768 | /* |
| 8769 | * Clear the tickle value. In the ASC-3550 the RISC flag |
| 8770 | * command 'clr_tickle_a' does not work unless the host |
| 8771 | * value is cleared. |
| 8772 | */ |
| 8773 | AdvWriteByteRegister(iop_base, IOPB_TICKLE, |
| 8774 | ADV_TICKLE_NOP); |
| 8775 | } |
| 8776 | } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) { |
| 8777 | /* |
| 8778 | * Notify the RISC a carrier is ready by writing the physical |
| 8779 | * address of the new carrier stopper to the COMMA register. |
| 8780 | */ |
| 8781 | AdvWriteDWordRegister(iop_base, IOPDW_COMMA, |
| 8782 | le32_to_cpu(new_carrp->carr_pa)); |
| 8783 | } |
| 8784 | |
| 8785 | return ADV_SUCCESS; |
| 8786 | } |
| 8787 | |
| 8788 | /* |
| 8789 | * Execute a single 'Scsi_Cmnd'. |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8790 | */ |
| 8791 | static int asc_execute_scsi_cmnd(struct scsi_cmnd *scp) |
| 8792 | { |
Matthew Wilcox | 41d2493 | 2007-10-02 21:55:24 -0400 | [diff] [blame] | 8793 | int ret, err_code; |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 8794 | struct asc_board *boardp = shost_priv(scp->device->host); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8795 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 8796 | ASC_DBG(1, "scp 0x%p\n", scp); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8797 | |
| 8798 | if (ASC_NARROW_BOARD(boardp)) { |
Matthew Wilcox | 41d2493 | 2007-10-02 21:55:24 -0400 | [diff] [blame] | 8799 | ASC_DVC_VAR *asc_dvc = &boardp->dvc_var.asc_dvc_var; |
Matthew Wilcox | 05848b6 | 2007-10-02 21:55:25 -0400 | [diff] [blame] | 8800 | struct asc_scsi_q asc_scsi_q; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8801 | |
Matthew Wilcox | 41d2493 | 2007-10-02 21:55:24 -0400 | [diff] [blame] | 8802 | /* asc_build_req() can not return ASC_BUSY. */ |
Matthew Wilcox | 05848b6 | 2007-10-02 21:55:25 -0400 | [diff] [blame] | 8803 | ret = asc_build_req(boardp, scp, &asc_scsi_q); |
| 8804 | if (ret == ASC_ERROR) { |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8805 | ASC_STATS(scp->device->host, build_error); |
| 8806 | return ASC_ERROR; |
| 8807 | } |
| 8808 | |
Matthew Wilcox | 41d2493 | 2007-10-02 21:55:24 -0400 | [diff] [blame] | 8809 | ret = AscExeScsiQueue(asc_dvc, &asc_scsi_q); |
Matthew Wilcox | 05848b6 | 2007-10-02 21:55:25 -0400 | [diff] [blame] | 8810 | kfree(asc_scsi_q.sg_head); |
Matthew Wilcox | 41d2493 | 2007-10-02 21:55:24 -0400 | [diff] [blame] | 8811 | err_code = asc_dvc->err_code; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8812 | } else { |
Matthew Wilcox | 41d2493 | 2007-10-02 21:55:24 -0400 | [diff] [blame] | 8813 | ADV_DVC_VAR *adv_dvc = &boardp->dvc_var.adv_dvc_var; |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 8814 | adv_req_t *adv_reqp; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8815 | |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 8816 | switch (adv_build_req(boardp, scp, &adv_reqp)) { |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8817 | case ASC_NOERROR: |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 8818 | ASC_DBG(3, "adv_build_req ASC_NOERROR\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8819 | break; |
| 8820 | case ASC_BUSY: |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 8821 | ASC_DBG(1, "adv_build_req ASC_BUSY\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8822 | /* |
| 8823 | * The asc_stats fields 'adv_build_noreq' and |
| 8824 | * 'adv_build_nosg' count wide board busy conditions. |
| 8825 | * They are updated in adv_build_req and |
| 8826 | * adv_get_sglist, respectively. |
| 8827 | */ |
| 8828 | return ASC_BUSY; |
| 8829 | case ASC_ERROR: |
| 8830 | default: |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 8831 | ASC_DBG(1, "adv_build_req ASC_ERROR\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8832 | ASC_STATS(scp->device->host, build_error); |
| 8833 | return ASC_ERROR; |
| 8834 | } |
| 8835 | |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 8836 | ret = AdvExeScsiQueue(adv_dvc, adv_reqp); |
Matthew Wilcox | 41d2493 | 2007-10-02 21:55:24 -0400 | [diff] [blame] | 8837 | err_code = adv_dvc->err_code; |
| 8838 | } |
| 8839 | |
| 8840 | switch (ret) { |
| 8841 | case ASC_NOERROR: |
| 8842 | ASC_STATS(scp->device->host, exe_noerror); |
| 8843 | /* |
| 8844 | * Increment monotonically increasing per device |
| 8845 | * successful request counter. Wrapping doesn't matter. |
| 8846 | */ |
| 8847 | boardp->reqcnt[scp->device->id]++; |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 8848 | ASC_DBG(1, "ExeScsiQueue() ASC_NOERROR\n"); |
Matthew Wilcox | 41d2493 | 2007-10-02 21:55:24 -0400 | [diff] [blame] | 8849 | break; |
| 8850 | case ASC_BUSY: |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 8851 | ASC_DBG(1, "ExeScsiQueue() ASC_BUSY\n"); |
Matthew Wilcox | 41d2493 | 2007-10-02 21:55:24 -0400 | [diff] [blame] | 8852 | ASC_STATS(scp->device->host, exe_busy); |
| 8853 | break; |
| 8854 | case ASC_ERROR: |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 8855 | scmd_printk(KERN_ERR, scp, "ExeScsiQueue() ASC_ERROR, " |
| 8856 | "err_code 0x%x\n", err_code); |
Matthew Wilcox | 41d2493 | 2007-10-02 21:55:24 -0400 | [diff] [blame] | 8857 | ASC_STATS(scp->device->host, exe_error); |
| 8858 | scp->result = HOST_BYTE(DID_ERROR); |
| 8859 | break; |
| 8860 | default: |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 8861 | scmd_printk(KERN_ERR, scp, "ExeScsiQueue() unknown, " |
| 8862 | "err_code 0x%x\n", err_code); |
Matthew Wilcox | 41d2493 | 2007-10-02 21:55:24 -0400 | [diff] [blame] | 8863 | ASC_STATS(scp->device->host, exe_unknown); |
| 8864 | scp->result = HOST_BYTE(DID_ERROR); |
| 8865 | break; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8866 | } |
| 8867 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 8868 | ASC_DBG(1, "end\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8869 | return ret; |
| 8870 | } |
| 8871 | |
| 8872 | /* |
| 8873 | * advansys_queuecommand() - interrupt-driven I/O entrypoint. |
| 8874 | * |
| 8875 | * This function always returns 0. Command return status is saved |
| 8876 | * in the 'scp' result field. |
| 8877 | */ |
| 8878 | static int |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 8879 | advansys_queuecommand_lck(struct scsi_cmnd *scp, void (*done)(struct scsi_cmnd *)) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8880 | { |
| 8881 | struct Scsi_Host *shost = scp->device->host; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8882 | int asc_res, result = 0; |
| 8883 | |
| 8884 | ASC_STATS(shost, queuecommand); |
| 8885 | scp->scsi_done = done; |
| 8886 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8887 | asc_res = asc_execute_scsi_cmnd(scp); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8888 | |
| 8889 | switch (asc_res) { |
| 8890 | case ASC_NOERROR: |
| 8891 | break; |
| 8892 | case ASC_BUSY: |
| 8893 | result = SCSI_MLQUEUE_HOST_BUSY; |
| 8894 | break; |
| 8895 | case ASC_ERROR: |
| 8896 | default: |
| 8897 | asc_scsi_done(scp); |
| 8898 | break; |
| 8899 | } |
| 8900 | |
| 8901 | return result; |
| 8902 | } |
| 8903 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 8904 | static DEF_SCSI_QCMD(advansys_queuecommand) |
| 8905 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8906 | static ushort AscGetEisaChipCfg(PortAddr iop_base) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8907 | { |
| 8908 | PortAddr eisa_cfg_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) | |
| 8909 | (PortAddr) (ASC_EISA_CFG_IOP_MASK); |
| 8910 | return inpw(eisa_cfg_iop); |
| 8911 | } |
| 8912 | |
| 8913 | /* |
| 8914 | * Return the BIOS address of the adapter at the specified |
| 8915 | * I/O port and with the specified bus type. |
| 8916 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8917 | static unsigned short AscGetChipBiosAddress(PortAddr iop_base, |
| 8918 | unsigned short bus_type) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8919 | { |
| 8920 | unsigned short cfg_lsw; |
| 8921 | unsigned short bios_addr; |
| 8922 | |
| 8923 | /* |
| 8924 | * The PCI BIOS is re-located by the motherboard BIOS. Because |
| 8925 | * of this the driver can not determine where a PCI BIOS is |
| 8926 | * loaded and executes. |
| 8927 | */ |
| 8928 | if (bus_type & ASC_IS_PCI) |
| 8929 | return 0; |
| 8930 | |
| 8931 | if ((bus_type & ASC_IS_EISA) != 0) { |
| 8932 | cfg_lsw = AscGetEisaChipCfg(iop_base); |
| 8933 | cfg_lsw &= 0x000F; |
| 8934 | bios_addr = ASC_BIOS_MIN_ADDR + cfg_lsw * ASC_BIOS_BANK_SIZE; |
| 8935 | return bios_addr; |
| 8936 | } |
| 8937 | |
| 8938 | cfg_lsw = AscGetChipCfgLsw(iop_base); |
| 8939 | |
| 8940 | /* |
| 8941 | * ISA PnP uses the top bit as the 32K BIOS flag |
| 8942 | */ |
| 8943 | if (bus_type == ASC_IS_ISAPNP) |
| 8944 | cfg_lsw &= 0x7FFF; |
| 8945 | bios_addr = ASC_BIOS_MIN_ADDR + (cfg_lsw >> 12) * ASC_BIOS_BANK_SIZE; |
| 8946 | return bios_addr; |
| 8947 | } |
| 8948 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8949 | static uchar AscSetChipScsiID(PortAddr iop_base, uchar new_host_id) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8950 | { |
| 8951 | ushort cfg_lsw; |
| 8952 | |
| 8953 | if (AscGetChipScsiID(iop_base) == new_host_id) { |
| 8954 | return (new_host_id); |
| 8955 | } |
| 8956 | cfg_lsw = AscGetChipCfgLsw(iop_base); |
| 8957 | cfg_lsw &= 0xF8FF; |
| 8958 | cfg_lsw |= (ushort)((new_host_id & ASC_MAX_TID) << 8); |
| 8959 | AscSetChipCfgLsw(iop_base, cfg_lsw); |
| 8960 | return (AscGetChipScsiID(iop_base)); |
| 8961 | } |
| 8962 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8963 | static unsigned char AscGetChipScsiCtrl(PortAddr iop_base) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8964 | { |
| 8965 | unsigned char sc; |
| 8966 | |
| 8967 | AscSetBank(iop_base, 1); |
| 8968 | sc = inp(iop_base + IOP_REG_SC); |
| 8969 | AscSetBank(iop_base, 0); |
| 8970 | return sc; |
| 8971 | } |
| 8972 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8973 | static unsigned char AscGetChipVersion(PortAddr iop_base, |
| 8974 | unsigned short bus_type) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8975 | { |
| 8976 | if (bus_type & ASC_IS_EISA) { |
| 8977 | PortAddr eisa_iop; |
| 8978 | unsigned char revision; |
| 8979 | eisa_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) | |
| 8980 | (PortAddr) ASC_EISA_REV_IOP_MASK; |
| 8981 | revision = inp(eisa_iop); |
| 8982 | return ASC_CHIP_MIN_VER_EISA - 1 + revision; |
| 8983 | } |
| 8984 | return AscGetChipVerNo(iop_base); |
| 8985 | } |
| 8986 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8987 | #ifdef CONFIG_ISA |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8988 | static void AscEnableIsaDma(uchar dma_channel) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8989 | { |
| 8990 | if (dma_channel < 4) { |
| 8991 | outp(0x000B, (ushort)(0xC0 | dma_channel)); |
| 8992 | outp(0x000A, dma_channel); |
| 8993 | } else if (dma_channel < 8) { |
| 8994 | outp(0x00D6, (ushort)(0xC0 | (dma_channel - 4))); |
| 8995 | outp(0x00D4, (ushort)(dma_channel - 4)); |
| 8996 | } |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 8997 | } |
| 8998 | #endif /* CONFIG_ISA */ |
| 8999 | |
| 9000 | static int AscStopQueueExe(PortAddr iop_base) |
| 9001 | { |
| 9002 | int count = 0; |
| 9003 | |
| 9004 | if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) == 0) { |
| 9005 | AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, |
| 9006 | ASC_STOP_REQ_RISC_STOP); |
| 9007 | do { |
| 9008 | if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) & |
| 9009 | ASC_STOP_ACK_RISC_STOP) { |
| 9010 | return (1); |
| 9011 | } |
| 9012 | mdelay(100); |
| 9013 | } while (count++ < 20); |
| 9014 | } |
| 9015 | return (0); |
| 9016 | } |
| 9017 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9018 | static ASC_DCNT AscGetMaxDmaCount(ushort bus_type) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9019 | { |
| 9020 | if (bus_type & ASC_IS_ISA) |
| 9021 | return ASC_MAX_ISA_DMA_COUNT; |
| 9022 | else if (bus_type & (ASC_IS_EISA | ASC_IS_VL)) |
| 9023 | return ASC_MAX_VL_DMA_COUNT; |
| 9024 | return ASC_MAX_PCI_DMA_COUNT; |
| 9025 | } |
| 9026 | |
| 9027 | #ifdef CONFIG_ISA |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9028 | static ushort AscGetIsaDmaChannel(PortAddr iop_base) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9029 | { |
| 9030 | ushort channel; |
| 9031 | |
| 9032 | channel = AscGetChipCfgLsw(iop_base) & 0x0003; |
| 9033 | if (channel == 0x03) |
| 9034 | return (0); |
| 9035 | else if (channel == 0x00) |
| 9036 | return (7); |
| 9037 | return (channel + 4); |
| 9038 | } |
| 9039 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9040 | static ushort AscSetIsaDmaChannel(PortAddr iop_base, ushort dma_channel) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9041 | { |
| 9042 | ushort cfg_lsw; |
| 9043 | uchar value; |
| 9044 | |
| 9045 | if ((dma_channel >= 5) && (dma_channel <= 7)) { |
| 9046 | if (dma_channel == 7) |
| 9047 | value = 0x00; |
| 9048 | else |
| 9049 | value = dma_channel - 4; |
| 9050 | cfg_lsw = AscGetChipCfgLsw(iop_base) & 0xFFFC; |
| 9051 | cfg_lsw |= value; |
| 9052 | AscSetChipCfgLsw(iop_base, cfg_lsw); |
| 9053 | return (AscGetIsaDmaChannel(iop_base)); |
| 9054 | } |
| 9055 | return 0; |
| 9056 | } |
| 9057 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9058 | static uchar AscGetIsaDmaSpeed(PortAddr iop_base) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9059 | { |
| 9060 | uchar speed_value; |
| 9061 | |
| 9062 | AscSetBank(iop_base, 1); |
| 9063 | speed_value = AscReadChipDmaSpeed(iop_base); |
| 9064 | speed_value &= 0x07; |
| 9065 | AscSetBank(iop_base, 0); |
| 9066 | return speed_value; |
| 9067 | } |
| 9068 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9069 | static uchar AscSetIsaDmaSpeed(PortAddr iop_base, uchar speed_value) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9070 | { |
| 9071 | speed_value &= 0x07; |
| 9072 | AscSetBank(iop_base, 1); |
| 9073 | AscWriteChipDmaSpeed(iop_base, speed_value); |
| 9074 | AscSetBank(iop_base, 0); |
| 9075 | return AscGetIsaDmaSpeed(iop_base); |
| 9076 | } |
| 9077 | #endif /* CONFIG_ISA */ |
| 9078 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9079 | static ushort AscInitAscDvcVar(ASC_DVC_VAR *asc_dvc) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9080 | { |
| 9081 | int i; |
| 9082 | PortAddr iop_base; |
| 9083 | ushort warn_code; |
| 9084 | uchar chip_version; |
| 9085 | |
| 9086 | iop_base = asc_dvc->iop_base; |
| 9087 | warn_code = 0; |
| 9088 | asc_dvc->err_code = 0; |
| 9089 | if ((asc_dvc->bus_type & |
| 9090 | (ASC_IS_ISA | ASC_IS_PCI | ASC_IS_EISA | ASC_IS_VL)) == 0) { |
| 9091 | asc_dvc->err_code |= ASC_IERR_NO_BUS_TYPE; |
| 9092 | } |
| 9093 | AscSetChipControl(iop_base, CC_HALT); |
| 9094 | AscSetChipStatus(iop_base, 0); |
| 9095 | asc_dvc->bug_fix_cntl = 0; |
| 9096 | asc_dvc->pci_fix_asyn_xfer = 0; |
| 9097 | asc_dvc->pci_fix_asyn_xfer_always = 0; |
Uwe Kleine-König | 421f91d | 2010-06-11 12:17:00 +0200 | [diff] [blame] | 9098 | /* asc_dvc->init_state initialized in AscInitGetConfig(). */ |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9099 | asc_dvc->sdtr_done = 0; |
| 9100 | asc_dvc->cur_total_qng = 0; |
| 9101 | asc_dvc->is_in_int = 0; |
| 9102 | asc_dvc->in_critical_cnt = 0; |
| 9103 | asc_dvc->last_q_shortage = 0; |
| 9104 | asc_dvc->use_tagged_qng = 0; |
| 9105 | asc_dvc->no_scam = 0; |
| 9106 | asc_dvc->unit_not_ready = 0; |
| 9107 | asc_dvc->queue_full_or_busy = 0; |
| 9108 | asc_dvc->redo_scam = 0; |
| 9109 | asc_dvc->res2 = 0; |
Matthew Wilcox | afbb68c | 2007-10-02 21:55:36 -0400 | [diff] [blame] | 9110 | asc_dvc->min_sdtr_index = 0; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9111 | asc_dvc->cfg->can_tagged_qng = 0; |
| 9112 | asc_dvc->cfg->cmd_qng_enabled = 0; |
| 9113 | asc_dvc->dvc_cntl = ASC_DEF_DVC_CNTL; |
| 9114 | asc_dvc->init_sdtr = 0; |
| 9115 | asc_dvc->max_total_qng = ASC_DEF_MAX_TOTAL_QNG; |
| 9116 | asc_dvc->scsi_reset_wait = 3; |
| 9117 | asc_dvc->start_motor = ASC_SCSI_WIDTH_BIT_SET; |
| 9118 | asc_dvc->max_dma_count = AscGetMaxDmaCount(asc_dvc->bus_type); |
| 9119 | asc_dvc->cfg->sdtr_enable = ASC_SCSI_WIDTH_BIT_SET; |
| 9120 | asc_dvc->cfg->disc_enable = ASC_SCSI_WIDTH_BIT_SET; |
| 9121 | asc_dvc->cfg->chip_scsi_id = ASC_DEF_CHIP_SCSI_ID; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9122 | chip_version = AscGetChipVersion(iop_base, asc_dvc->bus_type); |
| 9123 | asc_dvc->cfg->chip_version = chip_version; |
Matthew Wilcox | afbb68c | 2007-10-02 21:55:36 -0400 | [diff] [blame] | 9124 | asc_dvc->sdtr_period_tbl = asc_syn_xfer_period; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9125 | asc_dvc->max_sdtr_index = 7; |
| 9126 | if ((asc_dvc->bus_type & ASC_IS_PCI) && |
| 9127 | (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3150)) { |
| 9128 | asc_dvc->bus_type = ASC_IS_PCI_ULTRA; |
Matthew Wilcox | afbb68c | 2007-10-02 21:55:36 -0400 | [diff] [blame] | 9129 | asc_dvc->sdtr_period_tbl = asc_syn_ultra_xfer_period; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9130 | asc_dvc->max_sdtr_index = 15; |
| 9131 | if (chip_version == ASC_CHIP_VER_PCI_ULTRA_3150) { |
| 9132 | AscSetExtraControl(iop_base, |
| 9133 | (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE)); |
| 9134 | } else if (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3050) { |
| 9135 | AscSetExtraControl(iop_base, |
| 9136 | (SEC_ACTIVE_NEGATE | |
| 9137 | SEC_ENABLE_FILTER)); |
| 9138 | } |
| 9139 | } |
| 9140 | if (asc_dvc->bus_type == ASC_IS_PCI) { |
| 9141 | AscSetExtraControl(iop_base, |
| 9142 | (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE)); |
| 9143 | } |
| 9144 | |
| 9145 | asc_dvc->cfg->isa_dma_speed = ASC_DEF_ISA_DMA_SPEED; |
| 9146 | #ifdef CONFIG_ISA |
| 9147 | if ((asc_dvc->bus_type & ASC_IS_ISA) != 0) { |
| 9148 | if (chip_version >= ASC_CHIP_MIN_VER_ISA_PNP) { |
| 9149 | AscSetChipIFC(iop_base, IFC_INIT_DEFAULT); |
| 9150 | asc_dvc->bus_type = ASC_IS_ISAPNP; |
| 9151 | } |
| 9152 | asc_dvc->cfg->isa_dma_channel = |
| 9153 | (uchar)AscGetIsaDmaChannel(iop_base); |
| 9154 | } |
| 9155 | #endif /* CONFIG_ISA */ |
| 9156 | for (i = 0; i <= ASC_MAX_TID; i++) { |
| 9157 | asc_dvc->cur_dvc_qng[i] = 0; |
| 9158 | asc_dvc->max_dvc_qng[i] = ASC_MAX_SCSI1_QNG; |
| 9159 | asc_dvc->scsiq_busy_head[i] = (ASC_SCSI_Q *)0L; |
| 9160 | asc_dvc->scsiq_busy_tail[i] = (ASC_SCSI_Q *)0L; |
| 9161 | asc_dvc->cfg->max_tag_qng[i] = ASC_MAX_INRAM_TAG_QNG; |
| 9162 | } |
| 9163 | return warn_code; |
| 9164 | } |
| 9165 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9166 | static int AscWriteEEPCmdReg(PortAddr iop_base, uchar cmd_reg) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9167 | { |
| 9168 | int retry; |
| 9169 | |
| 9170 | for (retry = 0; retry < ASC_EEP_MAX_RETRY; retry++) { |
| 9171 | unsigned char read_back; |
| 9172 | AscSetChipEEPCmd(iop_base, cmd_reg); |
| 9173 | mdelay(1); |
| 9174 | read_back = AscGetChipEEPCmd(iop_base); |
| 9175 | if (read_back == cmd_reg) |
| 9176 | return 1; |
| 9177 | } |
| 9178 | return 0; |
| 9179 | } |
| 9180 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9181 | static void AscWaitEEPRead(void) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9182 | { |
| 9183 | mdelay(1); |
| 9184 | } |
| 9185 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9186 | static ushort AscReadEEPWord(PortAddr iop_base, uchar addr) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9187 | { |
| 9188 | ushort read_wval; |
| 9189 | uchar cmd_reg; |
| 9190 | |
| 9191 | AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE); |
| 9192 | AscWaitEEPRead(); |
| 9193 | cmd_reg = addr | ASC_EEP_CMD_READ; |
| 9194 | AscWriteEEPCmdReg(iop_base, cmd_reg); |
| 9195 | AscWaitEEPRead(); |
| 9196 | read_wval = AscGetChipEEPData(iop_base); |
| 9197 | AscWaitEEPRead(); |
| 9198 | return read_wval; |
| 9199 | } |
| 9200 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9201 | static ushort AscGetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf, |
| 9202 | ushort bus_type) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9203 | { |
| 9204 | ushort wval; |
| 9205 | ushort sum; |
| 9206 | ushort *wbuf; |
| 9207 | int cfg_beg; |
| 9208 | int cfg_end; |
| 9209 | int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2; |
| 9210 | int s_addr; |
| 9211 | |
| 9212 | wbuf = (ushort *)cfg_buf; |
| 9213 | sum = 0; |
| 9214 | /* Read two config words; Byte-swapping done by AscReadEEPWord(). */ |
| 9215 | for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) { |
| 9216 | *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr); |
| 9217 | sum += *wbuf; |
| 9218 | } |
| 9219 | if (bus_type & ASC_IS_VL) { |
| 9220 | cfg_beg = ASC_EEP_DVC_CFG_BEG_VL; |
| 9221 | cfg_end = ASC_EEP_MAX_DVC_ADDR_VL; |
| 9222 | } else { |
| 9223 | cfg_beg = ASC_EEP_DVC_CFG_BEG; |
| 9224 | cfg_end = ASC_EEP_MAX_DVC_ADDR; |
| 9225 | } |
| 9226 | for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) { |
| 9227 | wval = AscReadEEPWord(iop_base, (uchar)s_addr); |
| 9228 | if (s_addr <= uchar_end_in_config) { |
| 9229 | /* |
| 9230 | * Swap all char fields - must unswap bytes already swapped |
| 9231 | * by AscReadEEPWord(). |
| 9232 | */ |
| 9233 | *wbuf = le16_to_cpu(wval); |
| 9234 | } else { |
| 9235 | /* Don't swap word field at the end - cntl field. */ |
| 9236 | *wbuf = wval; |
| 9237 | } |
| 9238 | sum += wval; /* Checksum treats all EEPROM data as words. */ |
| 9239 | } |
| 9240 | /* |
| 9241 | * Read the checksum word which will be compared against 'sum' |
| 9242 | * by the caller. Word field already swapped. |
| 9243 | */ |
| 9244 | *wbuf = AscReadEEPWord(iop_base, (uchar)s_addr); |
| 9245 | return sum; |
| 9246 | } |
| 9247 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9248 | static int AscTestExternalLram(ASC_DVC_VAR *asc_dvc) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9249 | { |
| 9250 | PortAddr iop_base; |
| 9251 | ushort q_addr; |
| 9252 | ushort saved_word; |
| 9253 | int sta; |
| 9254 | |
| 9255 | iop_base = asc_dvc->iop_base; |
| 9256 | sta = 0; |
| 9257 | q_addr = ASC_QNO_TO_QADDR(241); |
| 9258 | saved_word = AscReadLramWord(iop_base, q_addr); |
| 9259 | AscSetChipLramAddr(iop_base, q_addr); |
| 9260 | AscSetChipLramData(iop_base, 0x55AA); |
| 9261 | mdelay(10); |
| 9262 | AscSetChipLramAddr(iop_base, q_addr); |
| 9263 | if (AscGetChipLramData(iop_base) == 0x55AA) { |
| 9264 | sta = 1; |
| 9265 | AscWriteLramWord(iop_base, q_addr, saved_word); |
| 9266 | } |
| 9267 | return (sta); |
| 9268 | } |
| 9269 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9270 | static void AscWaitEEPWrite(void) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9271 | { |
| 9272 | mdelay(20); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9273 | } |
| 9274 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9275 | static int AscWriteEEPDataReg(PortAddr iop_base, ushort data_reg) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9276 | { |
| 9277 | ushort read_back; |
| 9278 | int retry; |
| 9279 | |
| 9280 | retry = 0; |
| 9281 | while (TRUE) { |
| 9282 | AscSetChipEEPData(iop_base, data_reg); |
| 9283 | mdelay(1); |
| 9284 | read_back = AscGetChipEEPData(iop_base); |
| 9285 | if (read_back == data_reg) { |
| 9286 | return (1); |
| 9287 | } |
| 9288 | if (retry++ > ASC_EEP_MAX_RETRY) { |
| 9289 | return (0); |
| 9290 | } |
| 9291 | } |
| 9292 | } |
| 9293 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9294 | static ushort AscWriteEEPWord(PortAddr iop_base, uchar addr, ushort word_val) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9295 | { |
| 9296 | ushort read_wval; |
| 9297 | |
| 9298 | read_wval = AscReadEEPWord(iop_base, addr); |
| 9299 | if (read_wval != word_val) { |
| 9300 | AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_ABLE); |
| 9301 | AscWaitEEPRead(); |
| 9302 | AscWriteEEPDataReg(iop_base, word_val); |
| 9303 | AscWaitEEPRead(); |
| 9304 | AscWriteEEPCmdReg(iop_base, |
| 9305 | (uchar)((uchar)ASC_EEP_CMD_WRITE | addr)); |
| 9306 | AscWaitEEPWrite(); |
| 9307 | AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE); |
| 9308 | AscWaitEEPRead(); |
| 9309 | return (AscReadEEPWord(iop_base, addr)); |
| 9310 | } |
| 9311 | return (read_wval); |
| 9312 | } |
| 9313 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9314 | static int AscSetEEPConfigOnce(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf, |
| 9315 | ushort bus_type) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9316 | { |
| 9317 | int n_error; |
| 9318 | ushort *wbuf; |
| 9319 | ushort word; |
| 9320 | ushort sum; |
| 9321 | int s_addr; |
| 9322 | int cfg_beg; |
| 9323 | int cfg_end; |
| 9324 | int uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2; |
| 9325 | |
| 9326 | wbuf = (ushort *)cfg_buf; |
| 9327 | n_error = 0; |
| 9328 | sum = 0; |
| 9329 | /* Write two config words; AscWriteEEPWord() will swap bytes. */ |
| 9330 | for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) { |
| 9331 | sum += *wbuf; |
| 9332 | if (*wbuf != AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) { |
| 9333 | n_error++; |
| 9334 | } |
| 9335 | } |
| 9336 | if (bus_type & ASC_IS_VL) { |
| 9337 | cfg_beg = ASC_EEP_DVC_CFG_BEG_VL; |
| 9338 | cfg_end = ASC_EEP_MAX_DVC_ADDR_VL; |
| 9339 | } else { |
| 9340 | cfg_beg = ASC_EEP_DVC_CFG_BEG; |
| 9341 | cfg_end = ASC_EEP_MAX_DVC_ADDR; |
| 9342 | } |
| 9343 | for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) { |
| 9344 | if (s_addr <= uchar_end_in_config) { |
| 9345 | /* |
| 9346 | * This is a char field. Swap char fields before they are |
| 9347 | * swapped again by AscWriteEEPWord(). |
| 9348 | */ |
| 9349 | word = cpu_to_le16(*wbuf); |
| 9350 | if (word != |
| 9351 | AscWriteEEPWord(iop_base, (uchar)s_addr, word)) { |
| 9352 | n_error++; |
| 9353 | } |
| 9354 | } else { |
| 9355 | /* Don't swap word field at the end - cntl field. */ |
| 9356 | if (*wbuf != |
| 9357 | AscWriteEEPWord(iop_base, (uchar)s_addr, *wbuf)) { |
| 9358 | n_error++; |
| 9359 | } |
| 9360 | } |
| 9361 | sum += *wbuf; /* Checksum calculated from word values. */ |
| 9362 | } |
| 9363 | /* Write checksum word. It will be swapped by AscWriteEEPWord(). */ |
| 9364 | *wbuf = sum; |
| 9365 | if (sum != AscWriteEEPWord(iop_base, (uchar)s_addr, sum)) { |
| 9366 | n_error++; |
| 9367 | } |
| 9368 | |
| 9369 | /* Read EEPROM back again. */ |
| 9370 | wbuf = (ushort *)cfg_buf; |
| 9371 | /* |
| 9372 | * Read two config words; Byte-swapping done by AscReadEEPWord(). |
| 9373 | */ |
| 9374 | for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) { |
| 9375 | if (*wbuf != AscReadEEPWord(iop_base, (uchar)s_addr)) { |
| 9376 | n_error++; |
| 9377 | } |
| 9378 | } |
| 9379 | if (bus_type & ASC_IS_VL) { |
| 9380 | cfg_beg = ASC_EEP_DVC_CFG_BEG_VL; |
| 9381 | cfg_end = ASC_EEP_MAX_DVC_ADDR_VL; |
| 9382 | } else { |
| 9383 | cfg_beg = ASC_EEP_DVC_CFG_BEG; |
| 9384 | cfg_end = ASC_EEP_MAX_DVC_ADDR; |
| 9385 | } |
| 9386 | for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) { |
| 9387 | if (s_addr <= uchar_end_in_config) { |
| 9388 | /* |
| 9389 | * Swap all char fields. Must unswap bytes already swapped |
| 9390 | * by AscReadEEPWord(). |
| 9391 | */ |
| 9392 | word = |
| 9393 | le16_to_cpu(AscReadEEPWord |
| 9394 | (iop_base, (uchar)s_addr)); |
| 9395 | } else { |
| 9396 | /* Don't swap word field at the end - cntl field. */ |
| 9397 | word = AscReadEEPWord(iop_base, (uchar)s_addr); |
| 9398 | } |
| 9399 | if (*wbuf != word) { |
| 9400 | n_error++; |
| 9401 | } |
| 9402 | } |
| 9403 | /* Read checksum; Byte swapping not needed. */ |
| 9404 | if (AscReadEEPWord(iop_base, (uchar)s_addr) != sum) { |
| 9405 | n_error++; |
| 9406 | } |
| 9407 | return n_error; |
| 9408 | } |
| 9409 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9410 | static int AscSetEEPConfig(PortAddr iop_base, ASCEEP_CONFIG *cfg_buf, |
| 9411 | ushort bus_type) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9412 | { |
| 9413 | int retry; |
| 9414 | int n_error; |
| 9415 | |
| 9416 | retry = 0; |
| 9417 | while (TRUE) { |
| 9418 | if ((n_error = AscSetEEPConfigOnce(iop_base, cfg_buf, |
| 9419 | bus_type)) == 0) { |
| 9420 | break; |
| 9421 | } |
| 9422 | if (++retry > ASC_EEP_MAX_RETRY) { |
| 9423 | break; |
| 9424 | } |
| 9425 | } |
| 9426 | return n_error; |
| 9427 | } |
| 9428 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9429 | static ushort AscInitFromEEP(ASC_DVC_VAR *asc_dvc) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9430 | { |
| 9431 | ASCEEP_CONFIG eep_config_buf; |
| 9432 | ASCEEP_CONFIG *eep_config; |
| 9433 | PortAddr iop_base; |
| 9434 | ushort chksum; |
| 9435 | ushort warn_code; |
| 9436 | ushort cfg_msw, cfg_lsw; |
| 9437 | int i; |
| 9438 | int write_eep = 0; |
| 9439 | |
| 9440 | iop_base = asc_dvc->iop_base; |
| 9441 | warn_code = 0; |
| 9442 | AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0x00FE); |
| 9443 | AscStopQueueExe(iop_base); |
| 9444 | if ((AscStopChip(iop_base) == FALSE) || |
| 9445 | (AscGetChipScsiCtrl(iop_base) != 0)) { |
| 9446 | asc_dvc->init_state |= ASC_INIT_RESET_SCSI_DONE; |
| 9447 | AscResetChipAndScsiBus(asc_dvc); |
| 9448 | mdelay(asc_dvc->scsi_reset_wait * 1000); /* XXX: msleep? */ |
| 9449 | } |
Hannes Reinecke | d647c78 | 2015-04-24 13:18:26 +0200 | [diff] [blame^] | 9450 | if (!AscIsChipHalted(iop_base)) { |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9451 | asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP; |
| 9452 | return (warn_code); |
| 9453 | } |
| 9454 | AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR); |
| 9455 | if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) { |
| 9456 | asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR; |
| 9457 | return (warn_code); |
| 9458 | } |
| 9459 | eep_config = (ASCEEP_CONFIG *)&eep_config_buf; |
| 9460 | cfg_msw = AscGetChipCfgMsw(iop_base); |
| 9461 | cfg_lsw = AscGetChipCfgLsw(iop_base); |
| 9462 | if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) { |
| 9463 | cfg_msw &= ~ASC_CFG_MSW_CLR_MASK; |
| 9464 | warn_code |= ASC_WARN_CFG_MSW_RECOVER; |
| 9465 | AscSetChipCfgMsw(iop_base, cfg_msw); |
| 9466 | } |
| 9467 | chksum = AscGetEEPConfig(iop_base, eep_config, asc_dvc->bus_type); |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 9468 | ASC_DBG(1, "chksum 0x%x\n", chksum); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9469 | if (chksum == 0) { |
| 9470 | chksum = 0xaa55; |
| 9471 | } |
| 9472 | if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) { |
| 9473 | warn_code |= ASC_WARN_AUTO_CONFIG; |
| 9474 | if (asc_dvc->cfg->chip_version == 3) { |
| 9475 | if (eep_config->cfg_lsw != cfg_lsw) { |
| 9476 | warn_code |= ASC_WARN_EEPROM_RECOVER; |
| 9477 | eep_config->cfg_lsw = |
| 9478 | AscGetChipCfgLsw(iop_base); |
| 9479 | } |
| 9480 | if (eep_config->cfg_msw != cfg_msw) { |
| 9481 | warn_code |= ASC_WARN_EEPROM_RECOVER; |
| 9482 | eep_config->cfg_msw = |
| 9483 | AscGetChipCfgMsw(iop_base); |
| 9484 | } |
| 9485 | } |
| 9486 | } |
| 9487 | eep_config->cfg_msw &= ~ASC_CFG_MSW_CLR_MASK; |
| 9488 | eep_config->cfg_lsw |= ASC_CFG0_HOST_INT_ON; |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 9489 | ASC_DBG(1, "eep_config->chksum 0x%x\n", eep_config->chksum); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9490 | if (chksum != eep_config->chksum) { |
| 9491 | if (AscGetChipVersion(iop_base, asc_dvc->bus_type) == |
| 9492 | ASC_CHIP_VER_PCI_ULTRA_3050) { |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 9493 | ASC_DBG(1, "chksum error ignored; EEPROM-less board\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9494 | eep_config->init_sdtr = 0xFF; |
| 9495 | eep_config->disc_enable = 0xFF; |
| 9496 | eep_config->start_motor = 0xFF; |
| 9497 | eep_config->use_cmd_qng = 0; |
| 9498 | eep_config->max_total_qng = 0xF0; |
| 9499 | eep_config->max_tag_qng = 0x20; |
| 9500 | eep_config->cntl = 0xBFFF; |
| 9501 | ASC_EEP_SET_CHIP_ID(eep_config, 7); |
| 9502 | eep_config->no_scam = 0; |
| 9503 | eep_config->adapter_info[0] = 0; |
| 9504 | eep_config->adapter_info[1] = 0; |
| 9505 | eep_config->adapter_info[2] = 0; |
| 9506 | eep_config->adapter_info[3] = 0; |
| 9507 | eep_config->adapter_info[4] = 0; |
| 9508 | /* Indicate EEPROM-less board. */ |
| 9509 | eep_config->adapter_info[5] = 0xBB; |
| 9510 | } else { |
| 9511 | ASC_PRINT |
| 9512 | ("AscInitFromEEP: EEPROM checksum error; Will try to re-write EEPROM.\n"); |
| 9513 | write_eep = 1; |
| 9514 | warn_code |= ASC_WARN_EEPROM_CHKSUM; |
| 9515 | } |
| 9516 | } |
| 9517 | asc_dvc->cfg->sdtr_enable = eep_config->init_sdtr; |
| 9518 | asc_dvc->cfg->disc_enable = eep_config->disc_enable; |
| 9519 | asc_dvc->cfg->cmd_qng_enabled = eep_config->use_cmd_qng; |
| 9520 | asc_dvc->cfg->isa_dma_speed = ASC_EEP_GET_DMA_SPD(eep_config); |
| 9521 | asc_dvc->start_motor = eep_config->start_motor; |
| 9522 | asc_dvc->dvc_cntl = eep_config->cntl; |
| 9523 | asc_dvc->no_scam = eep_config->no_scam; |
| 9524 | asc_dvc->cfg->adapter_info[0] = eep_config->adapter_info[0]; |
| 9525 | asc_dvc->cfg->adapter_info[1] = eep_config->adapter_info[1]; |
| 9526 | asc_dvc->cfg->adapter_info[2] = eep_config->adapter_info[2]; |
| 9527 | asc_dvc->cfg->adapter_info[3] = eep_config->adapter_info[3]; |
| 9528 | asc_dvc->cfg->adapter_info[4] = eep_config->adapter_info[4]; |
| 9529 | asc_dvc->cfg->adapter_info[5] = eep_config->adapter_info[5]; |
| 9530 | if (!AscTestExternalLram(asc_dvc)) { |
| 9531 | if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == |
| 9532 | ASC_IS_PCI_ULTRA)) { |
| 9533 | eep_config->max_total_qng = |
| 9534 | ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG; |
| 9535 | eep_config->max_tag_qng = |
| 9536 | ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG; |
| 9537 | } else { |
| 9538 | eep_config->cfg_msw |= 0x0800; |
| 9539 | cfg_msw |= 0x0800; |
| 9540 | AscSetChipCfgMsw(iop_base, cfg_msw); |
| 9541 | eep_config->max_total_qng = ASC_MAX_PCI_INRAM_TOTAL_QNG; |
| 9542 | eep_config->max_tag_qng = ASC_MAX_INRAM_TAG_QNG; |
| 9543 | } |
| 9544 | } else { |
| 9545 | } |
| 9546 | if (eep_config->max_total_qng < ASC_MIN_TOTAL_QNG) { |
| 9547 | eep_config->max_total_qng = ASC_MIN_TOTAL_QNG; |
| 9548 | } |
| 9549 | if (eep_config->max_total_qng > ASC_MAX_TOTAL_QNG) { |
| 9550 | eep_config->max_total_qng = ASC_MAX_TOTAL_QNG; |
| 9551 | } |
| 9552 | if (eep_config->max_tag_qng > eep_config->max_total_qng) { |
| 9553 | eep_config->max_tag_qng = eep_config->max_total_qng; |
| 9554 | } |
| 9555 | if (eep_config->max_tag_qng < ASC_MIN_TAG_Q_PER_DVC) { |
| 9556 | eep_config->max_tag_qng = ASC_MIN_TAG_Q_PER_DVC; |
| 9557 | } |
| 9558 | asc_dvc->max_total_qng = eep_config->max_total_qng; |
| 9559 | if ((eep_config->use_cmd_qng & eep_config->disc_enable) != |
| 9560 | eep_config->use_cmd_qng) { |
| 9561 | eep_config->disc_enable = eep_config->use_cmd_qng; |
| 9562 | warn_code |= ASC_WARN_CMD_QNG_CONFLICT; |
| 9563 | } |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9564 | ASC_EEP_SET_CHIP_ID(eep_config, |
| 9565 | ASC_EEP_GET_CHIP_ID(eep_config) & ASC_MAX_TID); |
| 9566 | asc_dvc->cfg->chip_scsi_id = ASC_EEP_GET_CHIP_ID(eep_config); |
| 9567 | if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) && |
| 9568 | !(asc_dvc->dvc_cntl & ASC_CNTL_SDTR_ENABLE_ULTRA)) { |
Matthew Wilcox | afbb68c | 2007-10-02 21:55:36 -0400 | [diff] [blame] | 9569 | asc_dvc->min_sdtr_index = ASC_SDTR_ULTRA_PCI_10MB_INDEX; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9570 | } |
| 9571 | |
| 9572 | for (i = 0; i <= ASC_MAX_TID; i++) { |
| 9573 | asc_dvc->dos_int13_table[i] = eep_config->dos_int13_table[i]; |
| 9574 | asc_dvc->cfg->max_tag_qng[i] = eep_config->max_tag_qng; |
| 9575 | asc_dvc->cfg->sdtr_period_offset[i] = |
| 9576 | (uchar)(ASC_DEF_SDTR_OFFSET | |
Matthew Wilcox | afbb68c | 2007-10-02 21:55:36 -0400 | [diff] [blame] | 9577 | (asc_dvc->min_sdtr_index << 4)); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9578 | } |
| 9579 | eep_config->cfg_msw = AscGetChipCfgMsw(iop_base); |
| 9580 | if (write_eep) { |
| 9581 | if ((i = AscSetEEPConfig(iop_base, eep_config, |
| 9582 | asc_dvc->bus_type)) != 0) { |
| 9583 | ASC_PRINT1 |
| 9584 | ("AscInitFromEEP: Failed to re-write EEPROM with %d errors.\n", |
| 9585 | i); |
| 9586 | } else { |
| 9587 | ASC_PRINT |
| 9588 | ("AscInitFromEEP: Successfully re-wrote EEPROM.\n"); |
| 9589 | } |
| 9590 | } |
| 9591 | return (warn_code); |
| 9592 | } |
| 9593 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9594 | static int AscInitGetConfig(struct Scsi_Host *shost) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9595 | { |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 9596 | struct asc_board *board = shost_priv(shost); |
| 9597 | ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9598 | unsigned short warn_code = 0; |
| 9599 | |
| 9600 | asc_dvc->init_state = ASC_INIT_STATE_BEG_GET_CFG; |
| 9601 | if (asc_dvc->err_code != 0) |
| 9602 | return asc_dvc->err_code; |
| 9603 | |
| 9604 | if (AscFindSignature(asc_dvc->iop_base)) { |
| 9605 | warn_code |= AscInitAscDvcVar(asc_dvc); |
| 9606 | warn_code |= AscInitFromEEP(asc_dvc); |
| 9607 | asc_dvc->init_state |= ASC_INIT_STATE_END_GET_CFG; |
| 9608 | if (asc_dvc->scsi_reset_wait > ASC_MAX_SCSI_RESET_WAIT) |
| 9609 | asc_dvc->scsi_reset_wait = ASC_MAX_SCSI_RESET_WAIT; |
| 9610 | } else { |
| 9611 | asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE; |
| 9612 | } |
| 9613 | |
| 9614 | switch (warn_code) { |
| 9615 | case 0: /* No error */ |
| 9616 | break; |
| 9617 | case ASC_WARN_IO_PORT_ROTATE: |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 9618 | shost_printk(KERN_WARNING, shost, "I/O port address " |
| 9619 | "modified\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9620 | break; |
| 9621 | case ASC_WARN_AUTO_CONFIG: |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 9622 | shost_printk(KERN_WARNING, shost, "I/O port increment switch " |
| 9623 | "enabled\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9624 | break; |
| 9625 | case ASC_WARN_EEPROM_CHKSUM: |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 9626 | shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9627 | break; |
| 9628 | case ASC_WARN_IRQ_MODIFIED: |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 9629 | shost_printk(KERN_WARNING, shost, "IRQ modified\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9630 | break; |
| 9631 | case ASC_WARN_CMD_QNG_CONFLICT: |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 9632 | shost_printk(KERN_WARNING, shost, "tag queuing enabled w/o " |
| 9633 | "disconnects\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9634 | break; |
| 9635 | default: |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 9636 | shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n", |
| 9637 | warn_code); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9638 | break; |
| 9639 | } |
| 9640 | |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 9641 | if (asc_dvc->err_code != 0) |
| 9642 | shost_printk(KERN_ERR, shost, "error 0x%x at init_state " |
| 9643 | "0x%x\n", asc_dvc->err_code, asc_dvc->init_state); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9644 | |
| 9645 | return asc_dvc->err_code; |
| 9646 | } |
| 9647 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9648 | static int AscInitSetConfig(struct pci_dev *pdev, struct Scsi_Host *shost) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9649 | { |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 9650 | struct asc_board *board = shost_priv(shost); |
| 9651 | ASC_DVC_VAR *asc_dvc = &board->dvc_var.asc_dvc_var; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9652 | PortAddr iop_base = asc_dvc->iop_base; |
| 9653 | unsigned short cfg_msw; |
| 9654 | unsigned short warn_code = 0; |
| 9655 | |
| 9656 | asc_dvc->init_state |= ASC_INIT_STATE_BEG_SET_CFG; |
| 9657 | if (asc_dvc->err_code != 0) |
| 9658 | return asc_dvc->err_code; |
| 9659 | if (!AscFindSignature(asc_dvc->iop_base)) { |
| 9660 | asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE; |
| 9661 | return asc_dvc->err_code; |
| 9662 | } |
| 9663 | |
| 9664 | cfg_msw = AscGetChipCfgMsw(iop_base); |
| 9665 | if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) { |
| 9666 | cfg_msw &= ~ASC_CFG_MSW_CLR_MASK; |
| 9667 | warn_code |= ASC_WARN_CFG_MSW_RECOVER; |
| 9668 | AscSetChipCfgMsw(iop_base, cfg_msw); |
| 9669 | } |
| 9670 | if ((asc_dvc->cfg->cmd_qng_enabled & asc_dvc->cfg->disc_enable) != |
| 9671 | asc_dvc->cfg->cmd_qng_enabled) { |
| 9672 | asc_dvc->cfg->disc_enable = asc_dvc->cfg->cmd_qng_enabled; |
| 9673 | warn_code |= ASC_WARN_CMD_QNG_CONFLICT; |
| 9674 | } |
| 9675 | if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) { |
| 9676 | warn_code |= ASC_WARN_AUTO_CONFIG; |
| 9677 | } |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9678 | #ifdef CONFIG_PCI |
| 9679 | if (asc_dvc->bus_type & ASC_IS_PCI) { |
| 9680 | cfg_msw &= 0xFFC0; |
| 9681 | AscSetChipCfgMsw(iop_base, cfg_msw); |
| 9682 | if ((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) { |
| 9683 | } else { |
| 9684 | if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) || |
| 9685 | (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) { |
| 9686 | asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_IF_NOT_DWB; |
| 9687 | asc_dvc->bug_fix_cntl |= |
| 9688 | ASC_BUG_FIX_ASYN_USE_SYN; |
| 9689 | } |
| 9690 | } |
| 9691 | } else |
| 9692 | #endif /* CONFIG_PCI */ |
| 9693 | if (asc_dvc->bus_type == ASC_IS_ISAPNP) { |
| 9694 | if (AscGetChipVersion(iop_base, asc_dvc->bus_type) |
| 9695 | == ASC_CHIP_VER_ASYN_BUG) { |
| 9696 | asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_ASYN_USE_SYN; |
| 9697 | } |
| 9698 | } |
| 9699 | if (AscSetChipScsiID(iop_base, asc_dvc->cfg->chip_scsi_id) != |
| 9700 | asc_dvc->cfg->chip_scsi_id) { |
| 9701 | asc_dvc->err_code |= ASC_IERR_SET_SCSI_ID; |
| 9702 | } |
| 9703 | #ifdef CONFIG_ISA |
| 9704 | if (asc_dvc->bus_type & ASC_IS_ISA) { |
| 9705 | AscSetIsaDmaChannel(iop_base, asc_dvc->cfg->isa_dma_channel); |
| 9706 | AscSetIsaDmaSpeed(iop_base, asc_dvc->cfg->isa_dma_speed); |
| 9707 | } |
| 9708 | #endif /* CONFIG_ISA */ |
| 9709 | |
| 9710 | asc_dvc->init_state |= ASC_INIT_STATE_END_SET_CFG; |
| 9711 | |
| 9712 | switch (warn_code) { |
| 9713 | case 0: /* No error. */ |
| 9714 | break; |
| 9715 | case ASC_WARN_IO_PORT_ROTATE: |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 9716 | shost_printk(KERN_WARNING, shost, "I/O port address " |
| 9717 | "modified\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9718 | break; |
| 9719 | case ASC_WARN_AUTO_CONFIG: |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 9720 | shost_printk(KERN_WARNING, shost, "I/O port increment switch " |
| 9721 | "enabled\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9722 | break; |
| 9723 | case ASC_WARN_EEPROM_CHKSUM: |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 9724 | shost_printk(KERN_WARNING, shost, "EEPROM checksum error\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9725 | break; |
| 9726 | case ASC_WARN_IRQ_MODIFIED: |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 9727 | shost_printk(KERN_WARNING, shost, "IRQ modified\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9728 | break; |
| 9729 | case ASC_WARN_CMD_QNG_CONFLICT: |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 9730 | shost_printk(KERN_WARNING, shost, "tag queuing w/o " |
| 9731 | "disconnects\n"); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9732 | break; |
| 9733 | default: |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 9734 | shost_printk(KERN_WARNING, shost, "unknown warning: 0x%x\n", |
| 9735 | warn_code); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9736 | break; |
| 9737 | } |
| 9738 | |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 9739 | if (asc_dvc->err_code != 0) |
| 9740 | shost_printk(KERN_ERR, shost, "error 0x%x at init_state " |
| 9741 | "0x%x\n", asc_dvc->err_code, asc_dvc->init_state); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9742 | |
| 9743 | return asc_dvc->err_code; |
| 9744 | } |
| 9745 | |
| 9746 | /* |
| 9747 | * EEPROM Configuration. |
| 9748 | * |
| 9749 | * All drivers should use this structure to set the default EEPROM |
| 9750 | * configuration. The BIOS now uses this structure when it is built. |
| 9751 | * Additional structure information can be found in a_condor.h where |
| 9752 | * the structure is defined. |
| 9753 | * |
| 9754 | * The *_Field_IsChar structs are needed to correct for endianness. |
| 9755 | * These values are read from the board 16 bits at a time directly |
| 9756 | * into the structs. Because some fields are char, the values will be |
| 9757 | * in the wrong order. The *_Field_IsChar tells when to flip the |
| 9758 | * bytes. Data read and written to PCI memory is automatically swapped |
| 9759 | * on big-endian platforms so char fields read as words are actually being |
| 9760 | * unswapped on big-endian platforms. |
| 9761 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9762 | static ADVEEP_3550_CONFIG Default_3550_EEPROM_Config = { |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9763 | ADV_EEPROM_BIOS_ENABLE, /* cfg_lsw */ |
| 9764 | 0x0000, /* cfg_msw */ |
| 9765 | 0xFFFF, /* disc_enable */ |
| 9766 | 0xFFFF, /* wdtr_able */ |
| 9767 | 0xFFFF, /* sdtr_able */ |
| 9768 | 0xFFFF, /* start_motor */ |
| 9769 | 0xFFFF, /* tagqng_able */ |
| 9770 | 0xFFFF, /* bios_scan */ |
| 9771 | 0, /* scam_tolerant */ |
| 9772 | 7, /* adapter_scsi_id */ |
| 9773 | 0, /* bios_boot_delay */ |
| 9774 | 3, /* scsi_reset_delay */ |
| 9775 | 0, /* bios_id_lun */ |
| 9776 | 0, /* termination */ |
| 9777 | 0, /* reserved1 */ |
| 9778 | 0xFFE7, /* bios_ctrl */ |
| 9779 | 0xFFFF, /* ultra_able */ |
| 9780 | 0, /* reserved2 */ |
| 9781 | ASC_DEF_MAX_HOST_QNG, /* max_host_qng */ |
| 9782 | ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */ |
| 9783 | 0, /* dvc_cntl */ |
| 9784 | 0, /* bug_fix */ |
| 9785 | 0, /* serial_number_word1 */ |
| 9786 | 0, /* serial_number_word2 */ |
| 9787 | 0, /* serial_number_word3 */ |
| 9788 | 0, /* check_sum */ |
| 9789 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} |
| 9790 | , /* oem_name[16] */ |
| 9791 | 0, /* dvc_err_code */ |
| 9792 | 0, /* adv_err_code */ |
| 9793 | 0, /* adv_err_addr */ |
| 9794 | 0, /* saved_dvc_err_code */ |
| 9795 | 0, /* saved_adv_err_code */ |
| 9796 | 0, /* saved_adv_err_addr */ |
| 9797 | 0 /* num_of_err */ |
| 9798 | }; |
| 9799 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9800 | static ADVEEP_3550_CONFIG ADVEEP_3550_Config_Field_IsChar = { |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9801 | 0, /* cfg_lsw */ |
| 9802 | 0, /* cfg_msw */ |
| 9803 | 0, /* -disc_enable */ |
| 9804 | 0, /* wdtr_able */ |
| 9805 | 0, /* sdtr_able */ |
| 9806 | 0, /* start_motor */ |
| 9807 | 0, /* tagqng_able */ |
| 9808 | 0, /* bios_scan */ |
| 9809 | 0, /* scam_tolerant */ |
| 9810 | 1, /* adapter_scsi_id */ |
| 9811 | 1, /* bios_boot_delay */ |
| 9812 | 1, /* scsi_reset_delay */ |
| 9813 | 1, /* bios_id_lun */ |
| 9814 | 1, /* termination */ |
| 9815 | 1, /* reserved1 */ |
| 9816 | 0, /* bios_ctrl */ |
| 9817 | 0, /* ultra_able */ |
| 9818 | 0, /* reserved2 */ |
| 9819 | 1, /* max_host_qng */ |
| 9820 | 1, /* max_dvc_qng */ |
| 9821 | 0, /* dvc_cntl */ |
| 9822 | 0, /* bug_fix */ |
| 9823 | 0, /* serial_number_word1 */ |
| 9824 | 0, /* serial_number_word2 */ |
| 9825 | 0, /* serial_number_word3 */ |
| 9826 | 0, /* check_sum */ |
| 9827 | {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} |
| 9828 | , /* oem_name[16] */ |
| 9829 | 0, /* dvc_err_code */ |
| 9830 | 0, /* adv_err_code */ |
| 9831 | 0, /* adv_err_addr */ |
| 9832 | 0, /* saved_dvc_err_code */ |
| 9833 | 0, /* saved_adv_err_code */ |
| 9834 | 0, /* saved_adv_err_addr */ |
| 9835 | 0 /* num_of_err */ |
| 9836 | }; |
| 9837 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9838 | static ADVEEP_38C0800_CONFIG Default_38C0800_EEPROM_Config = { |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9839 | ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */ |
| 9840 | 0x0000, /* 01 cfg_msw */ |
| 9841 | 0xFFFF, /* 02 disc_enable */ |
| 9842 | 0xFFFF, /* 03 wdtr_able */ |
| 9843 | 0x4444, /* 04 sdtr_speed1 */ |
| 9844 | 0xFFFF, /* 05 start_motor */ |
| 9845 | 0xFFFF, /* 06 tagqng_able */ |
| 9846 | 0xFFFF, /* 07 bios_scan */ |
| 9847 | 0, /* 08 scam_tolerant */ |
| 9848 | 7, /* 09 adapter_scsi_id */ |
| 9849 | 0, /* bios_boot_delay */ |
| 9850 | 3, /* 10 scsi_reset_delay */ |
| 9851 | 0, /* bios_id_lun */ |
| 9852 | 0, /* 11 termination_se */ |
| 9853 | 0, /* termination_lvd */ |
| 9854 | 0xFFE7, /* 12 bios_ctrl */ |
| 9855 | 0x4444, /* 13 sdtr_speed2 */ |
| 9856 | 0x4444, /* 14 sdtr_speed3 */ |
| 9857 | ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */ |
| 9858 | ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */ |
| 9859 | 0, /* 16 dvc_cntl */ |
| 9860 | 0x4444, /* 17 sdtr_speed4 */ |
| 9861 | 0, /* 18 serial_number_word1 */ |
| 9862 | 0, /* 19 serial_number_word2 */ |
| 9863 | 0, /* 20 serial_number_word3 */ |
| 9864 | 0, /* 21 check_sum */ |
| 9865 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} |
| 9866 | , /* 22-29 oem_name[16] */ |
| 9867 | 0, /* 30 dvc_err_code */ |
| 9868 | 0, /* 31 adv_err_code */ |
| 9869 | 0, /* 32 adv_err_addr */ |
| 9870 | 0, /* 33 saved_dvc_err_code */ |
| 9871 | 0, /* 34 saved_adv_err_code */ |
| 9872 | 0, /* 35 saved_adv_err_addr */ |
| 9873 | 0, /* 36 reserved */ |
| 9874 | 0, /* 37 reserved */ |
| 9875 | 0, /* 38 reserved */ |
| 9876 | 0, /* 39 reserved */ |
| 9877 | 0, /* 40 reserved */ |
| 9878 | 0, /* 41 reserved */ |
| 9879 | 0, /* 42 reserved */ |
| 9880 | 0, /* 43 reserved */ |
| 9881 | 0, /* 44 reserved */ |
| 9882 | 0, /* 45 reserved */ |
| 9883 | 0, /* 46 reserved */ |
| 9884 | 0, /* 47 reserved */ |
| 9885 | 0, /* 48 reserved */ |
| 9886 | 0, /* 49 reserved */ |
| 9887 | 0, /* 50 reserved */ |
| 9888 | 0, /* 51 reserved */ |
| 9889 | 0, /* 52 reserved */ |
| 9890 | 0, /* 53 reserved */ |
| 9891 | 0, /* 54 reserved */ |
| 9892 | 0, /* 55 reserved */ |
| 9893 | 0, /* 56 cisptr_lsw */ |
| 9894 | 0, /* 57 cisprt_msw */ |
| 9895 | PCI_VENDOR_ID_ASP, /* 58 subsysvid */ |
| 9896 | PCI_DEVICE_ID_38C0800_REV1, /* 59 subsysid */ |
| 9897 | 0, /* 60 reserved */ |
| 9898 | 0, /* 61 reserved */ |
| 9899 | 0, /* 62 reserved */ |
| 9900 | 0 /* 63 reserved */ |
| 9901 | }; |
| 9902 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9903 | static ADVEEP_38C0800_CONFIG ADVEEP_38C0800_Config_Field_IsChar = { |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9904 | 0, /* 00 cfg_lsw */ |
| 9905 | 0, /* 01 cfg_msw */ |
| 9906 | 0, /* 02 disc_enable */ |
| 9907 | 0, /* 03 wdtr_able */ |
| 9908 | 0, /* 04 sdtr_speed1 */ |
| 9909 | 0, /* 05 start_motor */ |
| 9910 | 0, /* 06 tagqng_able */ |
| 9911 | 0, /* 07 bios_scan */ |
| 9912 | 0, /* 08 scam_tolerant */ |
| 9913 | 1, /* 09 adapter_scsi_id */ |
| 9914 | 1, /* bios_boot_delay */ |
| 9915 | 1, /* 10 scsi_reset_delay */ |
| 9916 | 1, /* bios_id_lun */ |
| 9917 | 1, /* 11 termination_se */ |
| 9918 | 1, /* termination_lvd */ |
| 9919 | 0, /* 12 bios_ctrl */ |
| 9920 | 0, /* 13 sdtr_speed2 */ |
| 9921 | 0, /* 14 sdtr_speed3 */ |
| 9922 | 1, /* 15 max_host_qng */ |
| 9923 | 1, /* max_dvc_qng */ |
| 9924 | 0, /* 16 dvc_cntl */ |
| 9925 | 0, /* 17 sdtr_speed4 */ |
| 9926 | 0, /* 18 serial_number_word1 */ |
| 9927 | 0, /* 19 serial_number_word2 */ |
| 9928 | 0, /* 20 serial_number_word3 */ |
| 9929 | 0, /* 21 check_sum */ |
| 9930 | {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} |
| 9931 | , /* 22-29 oem_name[16] */ |
| 9932 | 0, /* 30 dvc_err_code */ |
| 9933 | 0, /* 31 adv_err_code */ |
| 9934 | 0, /* 32 adv_err_addr */ |
| 9935 | 0, /* 33 saved_dvc_err_code */ |
| 9936 | 0, /* 34 saved_adv_err_code */ |
| 9937 | 0, /* 35 saved_adv_err_addr */ |
| 9938 | 0, /* 36 reserved */ |
| 9939 | 0, /* 37 reserved */ |
| 9940 | 0, /* 38 reserved */ |
| 9941 | 0, /* 39 reserved */ |
| 9942 | 0, /* 40 reserved */ |
| 9943 | 0, /* 41 reserved */ |
| 9944 | 0, /* 42 reserved */ |
| 9945 | 0, /* 43 reserved */ |
| 9946 | 0, /* 44 reserved */ |
| 9947 | 0, /* 45 reserved */ |
| 9948 | 0, /* 46 reserved */ |
| 9949 | 0, /* 47 reserved */ |
| 9950 | 0, /* 48 reserved */ |
| 9951 | 0, /* 49 reserved */ |
| 9952 | 0, /* 50 reserved */ |
| 9953 | 0, /* 51 reserved */ |
| 9954 | 0, /* 52 reserved */ |
| 9955 | 0, /* 53 reserved */ |
| 9956 | 0, /* 54 reserved */ |
| 9957 | 0, /* 55 reserved */ |
| 9958 | 0, /* 56 cisptr_lsw */ |
| 9959 | 0, /* 57 cisprt_msw */ |
| 9960 | 0, /* 58 subsysvid */ |
| 9961 | 0, /* 59 subsysid */ |
| 9962 | 0, /* 60 reserved */ |
| 9963 | 0, /* 61 reserved */ |
| 9964 | 0, /* 62 reserved */ |
| 9965 | 0 /* 63 reserved */ |
| 9966 | }; |
| 9967 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 9968 | static ADVEEP_38C1600_CONFIG Default_38C1600_EEPROM_Config = { |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 9969 | ADV_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */ |
| 9970 | 0x0000, /* 01 cfg_msw */ |
| 9971 | 0xFFFF, /* 02 disc_enable */ |
| 9972 | 0xFFFF, /* 03 wdtr_able */ |
| 9973 | 0x5555, /* 04 sdtr_speed1 */ |
| 9974 | 0xFFFF, /* 05 start_motor */ |
| 9975 | 0xFFFF, /* 06 tagqng_able */ |
| 9976 | 0xFFFF, /* 07 bios_scan */ |
| 9977 | 0, /* 08 scam_tolerant */ |
| 9978 | 7, /* 09 adapter_scsi_id */ |
| 9979 | 0, /* bios_boot_delay */ |
| 9980 | 3, /* 10 scsi_reset_delay */ |
| 9981 | 0, /* bios_id_lun */ |
| 9982 | 0, /* 11 termination_se */ |
| 9983 | 0, /* termination_lvd */ |
| 9984 | 0xFFE7, /* 12 bios_ctrl */ |
| 9985 | 0x5555, /* 13 sdtr_speed2 */ |
| 9986 | 0x5555, /* 14 sdtr_speed3 */ |
| 9987 | ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */ |
| 9988 | ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */ |
| 9989 | 0, /* 16 dvc_cntl */ |
| 9990 | 0x5555, /* 17 sdtr_speed4 */ |
| 9991 | 0, /* 18 serial_number_word1 */ |
| 9992 | 0, /* 19 serial_number_word2 */ |
| 9993 | 0, /* 20 serial_number_word3 */ |
| 9994 | 0, /* 21 check_sum */ |
| 9995 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} |
| 9996 | , /* 22-29 oem_name[16] */ |
| 9997 | 0, /* 30 dvc_err_code */ |
| 9998 | 0, /* 31 adv_err_code */ |
| 9999 | 0, /* 32 adv_err_addr */ |
| 10000 | 0, /* 33 saved_dvc_err_code */ |
| 10001 | 0, /* 34 saved_adv_err_code */ |
| 10002 | 0, /* 35 saved_adv_err_addr */ |
| 10003 | 0, /* 36 reserved */ |
| 10004 | 0, /* 37 reserved */ |
| 10005 | 0, /* 38 reserved */ |
| 10006 | 0, /* 39 reserved */ |
| 10007 | 0, /* 40 reserved */ |
| 10008 | 0, /* 41 reserved */ |
| 10009 | 0, /* 42 reserved */ |
| 10010 | 0, /* 43 reserved */ |
| 10011 | 0, /* 44 reserved */ |
| 10012 | 0, /* 45 reserved */ |
| 10013 | 0, /* 46 reserved */ |
| 10014 | 0, /* 47 reserved */ |
| 10015 | 0, /* 48 reserved */ |
| 10016 | 0, /* 49 reserved */ |
| 10017 | 0, /* 50 reserved */ |
| 10018 | 0, /* 51 reserved */ |
| 10019 | 0, /* 52 reserved */ |
| 10020 | 0, /* 53 reserved */ |
| 10021 | 0, /* 54 reserved */ |
| 10022 | 0, /* 55 reserved */ |
| 10023 | 0, /* 56 cisptr_lsw */ |
| 10024 | 0, /* 57 cisprt_msw */ |
| 10025 | PCI_VENDOR_ID_ASP, /* 58 subsysvid */ |
| 10026 | PCI_DEVICE_ID_38C1600_REV1, /* 59 subsysid */ |
| 10027 | 0, /* 60 reserved */ |
| 10028 | 0, /* 61 reserved */ |
| 10029 | 0, /* 62 reserved */ |
| 10030 | 0 /* 63 reserved */ |
| 10031 | }; |
| 10032 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10033 | static ADVEEP_38C1600_CONFIG ADVEEP_38C1600_Config_Field_IsChar = { |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 10034 | 0, /* 00 cfg_lsw */ |
| 10035 | 0, /* 01 cfg_msw */ |
| 10036 | 0, /* 02 disc_enable */ |
| 10037 | 0, /* 03 wdtr_able */ |
| 10038 | 0, /* 04 sdtr_speed1 */ |
| 10039 | 0, /* 05 start_motor */ |
| 10040 | 0, /* 06 tagqng_able */ |
| 10041 | 0, /* 07 bios_scan */ |
| 10042 | 0, /* 08 scam_tolerant */ |
| 10043 | 1, /* 09 adapter_scsi_id */ |
| 10044 | 1, /* bios_boot_delay */ |
| 10045 | 1, /* 10 scsi_reset_delay */ |
| 10046 | 1, /* bios_id_lun */ |
| 10047 | 1, /* 11 termination_se */ |
| 10048 | 1, /* termination_lvd */ |
| 10049 | 0, /* 12 bios_ctrl */ |
| 10050 | 0, /* 13 sdtr_speed2 */ |
| 10051 | 0, /* 14 sdtr_speed3 */ |
| 10052 | 1, /* 15 max_host_qng */ |
| 10053 | 1, /* max_dvc_qng */ |
| 10054 | 0, /* 16 dvc_cntl */ |
| 10055 | 0, /* 17 sdtr_speed4 */ |
| 10056 | 0, /* 18 serial_number_word1 */ |
| 10057 | 0, /* 19 serial_number_word2 */ |
| 10058 | 0, /* 20 serial_number_word3 */ |
| 10059 | 0, /* 21 check_sum */ |
| 10060 | {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} |
| 10061 | , /* 22-29 oem_name[16] */ |
| 10062 | 0, /* 30 dvc_err_code */ |
| 10063 | 0, /* 31 adv_err_code */ |
| 10064 | 0, /* 32 adv_err_addr */ |
| 10065 | 0, /* 33 saved_dvc_err_code */ |
| 10066 | 0, /* 34 saved_adv_err_code */ |
| 10067 | 0, /* 35 saved_adv_err_addr */ |
| 10068 | 0, /* 36 reserved */ |
| 10069 | 0, /* 37 reserved */ |
| 10070 | 0, /* 38 reserved */ |
| 10071 | 0, /* 39 reserved */ |
| 10072 | 0, /* 40 reserved */ |
| 10073 | 0, /* 41 reserved */ |
| 10074 | 0, /* 42 reserved */ |
| 10075 | 0, /* 43 reserved */ |
| 10076 | 0, /* 44 reserved */ |
| 10077 | 0, /* 45 reserved */ |
| 10078 | 0, /* 46 reserved */ |
| 10079 | 0, /* 47 reserved */ |
| 10080 | 0, /* 48 reserved */ |
| 10081 | 0, /* 49 reserved */ |
| 10082 | 0, /* 50 reserved */ |
| 10083 | 0, /* 51 reserved */ |
| 10084 | 0, /* 52 reserved */ |
| 10085 | 0, /* 53 reserved */ |
| 10086 | 0, /* 54 reserved */ |
| 10087 | 0, /* 55 reserved */ |
| 10088 | 0, /* 56 cisptr_lsw */ |
| 10089 | 0, /* 57 cisprt_msw */ |
| 10090 | 0, /* 58 subsysvid */ |
| 10091 | 0, /* 59 subsysid */ |
| 10092 | 0, /* 60 reserved */ |
| 10093 | 0, /* 61 reserved */ |
| 10094 | 0, /* 62 reserved */ |
| 10095 | 0 /* 63 reserved */ |
| 10096 | }; |
| 10097 | |
| 10098 | #ifdef CONFIG_PCI |
| 10099 | /* |
| 10100 | * Wait for EEPROM command to complete |
| 10101 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10102 | static void AdvWaitEEPCmd(AdvPortAddr iop_base) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 10103 | { |
| 10104 | int eep_delay_ms; |
| 10105 | |
| 10106 | for (eep_delay_ms = 0; eep_delay_ms < ADV_EEP_DELAY_MS; eep_delay_ms++) { |
| 10107 | if (AdvReadWordRegister(iop_base, IOPW_EE_CMD) & |
| 10108 | ASC_EEP_CMD_DONE) { |
| 10109 | break; |
| 10110 | } |
| 10111 | mdelay(1); |
| 10112 | } |
| 10113 | if ((AdvReadWordRegister(iop_base, IOPW_EE_CMD) & ASC_EEP_CMD_DONE) == |
| 10114 | 0) |
| 10115 | BUG(); |
| 10116 | } |
| 10117 | |
| 10118 | /* |
| 10119 | * Read the EEPROM from specified location |
| 10120 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10121 | static ushort AdvReadEEPWord(AdvPortAddr iop_base, int eep_word_addr) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 10122 | { |
| 10123 | AdvWriteWordRegister(iop_base, IOPW_EE_CMD, |
| 10124 | ASC_EEP_CMD_READ | eep_word_addr); |
| 10125 | AdvWaitEEPCmd(iop_base); |
| 10126 | return AdvReadWordRegister(iop_base, IOPW_EE_DATA); |
| 10127 | } |
| 10128 | |
| 10129 | /* |
| 10130 | * Write the EEPROM from 'cfg_buf'. |
| 10131 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10132 | static void AdvSet3550EEPConfig(AdvPortAddr iop_base, |
| 10133 | ADVEEP_3550_CONFIG *cfg_buf) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 10134 | { |
| 10135 | ushort *wbuf; |
| 10136 | ushort addr, chksum; |
| 10137 | ushort *charfields; |
| 10138 | |
| 10139 | wbuf = (ushort *)cfg_buf; |
| 10140 | charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar; |
| 10141 | chksum = 0; |
| 10142 | |
| 10143 | AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE); |
| 10144 | AdvWaitEEPCmd(iop_base); |
| 10145 | |
| 10146 | /* |
| 10147 | * Write EEPROM from word 0 to word 20. |
| 10148 | */ |
| 10149 | for (addr = ADV_EEP_DVC_CFG_BEGIN; |
| 10150 | addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) { |
| 10151 | ushort word; |
| 10152 | |
| 10153 | if (*charfields++) { |
| 10154 | word = cpu_to_le16(*wbuf); |
| 10155 | } else { |
| 10156 | word = *wbuf; |
| 10157 | } |
| 10158 | chksum += *wbuf; /* Checksum is calculated from word values. */ |
| 10159 | AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word); |
| 10160 | AdvWriteWordRegister(iop_base, IOPW_EE_CMD, |
| 10161 | ASC_EEP_CMD_WRITE | addr); |
| 10162 | AdvWaitEEPCmd(iop_base); |
| 10163 | mdelay(ADV_EEP_DELAY_MS); |
| 10164 | } |
| 10165 | |
| 10166 | /* |
| 10167 | * Write EEPROM checksum at word 21. |
| 10168 | */ |
| 10169 | AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum); |
| 10170 | AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr); |
| 10171 | AdvWaitEEPCmd(iop_base); |
| 10172 | wbuf++; |
| 10173 | charfields++; |
| 10174 | |
| 10175 | /* |
| 10176 | * Write EEPROM OEM name at words 22 to 29. |
| 10177 | */ |
| 10178 | for (addr = ADV_EEP_DVC_CTL_BEGIN; |
| 10179 | addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) { |
| 10180 | ushort word; |
| 10181 | |
| 10182 | if (*charfields++) { |
| 10183 | word = cpu_to_le16(*wbuf); |
| 10184 | } else { |
| 10185 | word = *wbuf; |
| 10186 | } |
| 10187 | AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word); |
| 10188 | AdvWriteWordRegister(iop_base, IOPW_EE_CMD, |
| 10189 | ASC_EEP_CMD_WRITE | addr); |
| 10190 | AdvWaitEEPCmd(iop_base); |
| 10191 | } |
| 10192 | AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE); |
| 10193 | AdvWaitEEPCmd(iop_base); |
| 10194 | } |
| 10195 | |
| 10196 | /* |
| 10197 | * Write the EEPROM from 'cfg_buf'. |
| 10198 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10199 | static void AdvSet38C0800EEPConfig(AdvPortAddr iop_base, |
| 10200 | ADVEEP_38C0800_CONFIG *cfg_buf) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 10201 | { |
| 10202 | ushort *wbuf; |
| 10203 | ushort *charfields; |
| 10204 | ushort addr, chksum; |
| 10205 | |
| 10206 | wbuf = (ushort *)cfg_buf; |
| 10207 | charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar; |
| 10208 | chksum = 0; |
| 10209 | |
| 10210 | AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE); |
| 10211 | AdvWaitEEPCmd(iop_base); |
| 10212 | |
| 10213 | /* |
| 10214 | * Write EEPROM from word 0 to word 20. |
| 10215 | */ |
| 10216 | for (addr = ADV_EEP_DVC_CFG_BEGIN; |
| 10217 | addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) { |
| 10218 | ushort word; |
| 10219 | |
| 10220 | if (*charfields++) { |
| 10221 | word = cpu_to_le16(*wbuf); |
| 10222 | } else { |
| 10223 | word = *wbuf; |
| 10224 | } |
| 10225 | chksum += *wbuf; /* Checksum is calculated from word values. */ |
| 10226 | AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word); |
| 10227 | AdvWriteWordRegister(iop_base, IOPW_EE_CMD, |
| 10228 | ASC_EEP_CMD_WRITE | addr); |
| 10229 | AdvWaitEEPCmd(iop_base); |
| 10230 | mdelay(ADV_EEP_DELAY_MS); |
| 10231 | } |
| 10232 | |
| 10233 | /* |
| 10234 | * Write EEPROM checksum at word 21. |
| 10235 | */ |
| 10236 | AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum); |
| 10237 | AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr); |
| 10238 | AdvWaitEEPCmd(iop_base); |
| 10239 | wbuf++; |
| 10240 | charfields++; |
| 10241 | |
| 10242 | /* |
| 10243 | * Write EEPROM OEM name at words 22 to 29. |
| 10244 | */ |
| 10245 | for (addr = ADV_EEP_DVC_CTL_BEGIN; |
| 10246 | addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) { |
| 10247 | ushort word; |
| 10248 | |
| 10249 | if (*charfields++) { |
| 10250 | word = cpu_to_le16(*wbuf); |
| 10251 | } else { |
| 10252 | word = *wbuf; |
| 10253 | } |
| 10254 | AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word); |
| 10255 | AdvWriteWordRegister(iop_base, IOPW_EE_CMD, |
| 10256 | ASC_EEP_CMD_WRITE | addr); |
| 10257 | AdvWaitEEPCmd(iop_base); |
| 10258 | } |
| 10259 | AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE); |
| 10260 | AdvWaitEEPCmd(iop_base); |
| 10261 | } |
| 10262 | |
| 10263 | /* |
| 10264 | * Write the EEPROM from 'cfg_buf'. |
| 10265 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10266 | static void AdvSet38C1600EEPConfig(AdvPortAddr iop_base, |
| 10267 | ADVEEP_38C1600_CONFIG *cfg_buf) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 10268 | { |
| 10269 | ushort *wbuf; |
| 10270 | ushort *charfields; |
| 10271 | ushort addr, chksum; |
| 10272 | |
| 10273 | wbuf = (ushort *)cfg_buf; |
| 10274 | charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar; |
| 10275 | chksum = 0; |
| 10276 | |
| 10277 | AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE); |
| 10278 | AdvWaitEEPCmd(iop_base); |
| 10279 | |
| 10280 | /* |
| 10281 | * Write EEPROM from word 0 to word 20. |
| 10282 | */ |
| 10283 | for (addr = ADV_EEP_DVC_CFG_BEGIN; |
| 10284 | addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++) { |
| 10285 | ushort word; |
| 10286 | |
| 10287 | if (*charfields++) { |
| 10288 | word = cpu_to_le16(*wbuf); |
| 10289 | } else { |
| 10290 | word = *wbuf; |
| 10291 | } |
| 10292 | chksum += *wbuf; /* Checksum is calculated from word values. */ |
| 10293 | AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word); |
| 10294 | AdvWriteWordRegister(iop_base, IOPW_EE_CMD, |
| 10295 | ASC_EEP_CMD_WRITE | addr); |
| 10296 | AdvWaitEEPCmd(iop_base); |
| 10297 | mdelay(ADV_EEP_DELAY_MS); |
| 10298 | } |
| 10299 | |
| 10300 | /* |
| 10301 | * Write EEPROM checksum at word 21. |
| 10302 | */ |
| 10303 | AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum); |
| 10304 | AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr); |
| 10305 | AdvWaitEEPCmd(iop_base); |
| 10306 | wbuf++; |
| 10307 | charfields++; |
| 10308 | |
| 10309 | /* |
| 10310 | * Write EEPROM OEM name at words 22 to 29. |
| 10311 | */ |
| 10312 | for (addr = ADV_EEP_DVC_CTL_BEGIN; |
| 10313 | addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++) { |
| 10314 | ushort word; |
| 10315 | |
| 10316 | if (*charfields++) { |
| 10317 | word = cpu_to_le16(*wbuf); |
| 10318 | } else { |
| 10319 | word = *wbuf; |
| 10320 | } |
| 10321 | AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word); |
| 10322 | AdvWriteWordRegister(iop_base, IOPW_EE_CMD, |
| 10323 | ASC_EEP_CMD_WRITE | addr); |
| 10324 | AdvWaitEEPCmd(iop_base); |
| 10325 | } |
| 10326 | AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE); |
| 10327 | AdvWaitEEPCmd(iop_base); |
| 10328 | } |
| 10329 | |
| 10330 | /* |
| 10331 | * Read EEPROM configuration into the specified buffer. |
| 10332 | * |
| 10333 | * Return a checksum based on the EEPROM configuration read. |
| 10334 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10335 | static ushort AdvGet3550EEPConfig(AdvPortAddr iop_base, |
| 10336 | ADVEEP_3550_CONFIG *cfg_buf) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 10337 | { |
| 10338 | ushort wval, chksum; |
| 10339 | ushort *wbuf; |
| 10340 | int eep_addr; |
| 10341 | ushort *charfields; |
| 10342 | |
| 10343 | charfields = (ushort *)&ADVEEP_3550_Config_Field_IsChar; |
| 10344 | wbuf = (ushort *)cfg_buf; |
| 10345 | chksum = 0; |
| 10346 | |
| 10347 | for (eep_addr = ADV_EEP_DVC_CFG_BEGIN; |
| 10348 | eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) { |
| 10349 | wval = AdvReadEEPWord(iop_base, eep_addr); |
| 10350 | chksum += wval; /* Checksum is calculated from word values. */ |
| 10351 | if (*charfields++) { |
| 10352 | *wbuf = le16_to_cpu(wval); |
| 10353 | } else { |
| 10354 | *wbuf = wval; |
| 10355 | } |
| 10356 | } |
| 10357 | /* Read checksum word. */ |
| 10358 | *wbuf = AdvReadEEPWord(iop_base, eep_addr); |
| 10359 | wbuf++; |
| 10360 | charfields++; |
| 10361 | |
| 10362 | /* Read rest of EEPROM not covered by the checksum. */ |
| 10363 | for (eep_addr = ADV_EEP_DVC_CTL_BEGIN; |
| 10364 | eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) { |
| 10365 | *wbuf = AdvReadEEPWord(iop_base, eep_addr); |
| 10366 | if (*charfields++) { |
| 10367 | *wbuf = le16_to_cpu(*wbuf); |
| 10368 | } |
| 10369 | } |
| 10370 | return chksum; |
| 10371 | } |
| 10372 | |
| 10373 | /* |
| 10374 | * Read EEPROM configuration into the specified buffer. |
| 10375 | * |
| 10376 | * Return a checksum based on the EEPROM configuration read. |
| 10377 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10378 | static ushort AdvGet38C0800EEPConfig(AdvPortAddr iop_base, |
| 10379 | ADVEEP_38C0800_CONFIG *cfg_buf) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 10380 | { |
| 10381 | ushort wval, chksum; |
| 10382 | ushort *wbuf; |
| 10383 | int eep_addr; |
| 10384 | ushort *charfields; |
| 10385 | |
| 10386 | charfields = (ushort *)&ADVEEP_38C0800_Config_Field_IsChar; |
| 10387 | wbuf = (ushort *)cfg_buf; |
| 10388 | chksum = 0; |
| 10389 | |
| 10390 | for (eep_addr = ADV_EEP_DVC_CFG_BEGIN; |
| 10391 | eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) { |
| 10392 | wval = AdvReadEEPWord(iop_base, eep_addr); |
| 10393 | chksum += wval; /* Checksum is calculated from word values. */ |
| 10394 | if (*charfields++) { |
| 10395 | *wbuf = le16_to_cpu(wval); |
| 10396 | } else { |
| 10397 | *wbuf = wval; |
| 10398 | } |
| 10399 | } |
| 10400 | /* Read checksum word. */ |
| 10401 | *wbuf = AdvReadEEPWord(iop_base, eep_addr); |
| 10402 | wbuf++; |
| 10403 | charfields++; |
| 10404 | |
| 10405 | /* Read rest of EEPROM not covered by the checksum. */ |
| 10406 | for (eep_addr = ADV_EEP_DVC_CTL_BEGIN; |
| 10407 | eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) { |
| 10408 | *wbuf = AdvReadEEPWord(iop_base, eep_addr); |
| 10409 | if (*charfields++) { |
| 10410 | *wbuf = le16_to_cpu(*wbuf); |
| 10411 | } |
| 10412 | } |
| 10413 | return chksum; |
| 10414 | } |
| 10415 | |
| 10416 | /* |
| 10417 | * Read EEPROM configuration into the specified buffer. |
| 10418 | * |
| 10419 | * Return a checksum based on the EEPROM configuration read. |
| 10420 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10421 | static ushort AdvGet38C1600EEPConfig(AdvPortAddr iop_base, |
| 10422 | ADVEEP_38C1600_CONFIG *cfg_buf) |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 10423 | { |
| 10424 | ushort wval, chksum; |
| 10425 | ushort *wbuf; |
| 10426 | int eep_addr; |
| 10427 | ushort *charfields; |
| 10428 | |
| 10429 | charfields = (ushort *)&ADVEEP_38C1600_Config_Field_IsChar; |
| 10430 | wbuf = (ushort *)cfg_buf; |
| 10431 | chksum = 0; |
| 10432 | |
| 10433 | for (eep_addr = ADV_EEP_DVC_CFG_BEGIN; |
| 10434 | eep_addr < ADV_EEP_DVC_CFG_END; eep_addr++, wbuf++) { |
| 10435 | wval = AdvReadEEPWord(iop_base, eep_addr); |
| 10436 | chksum += wval; /* Checksum is calculated from word values. */ |
| 10437 | if (*charfields++) { |
| 10438 | *wbuf = le16_to_cpu(wval); |
| 10439 | } else { |
| 10440 | *wbuf = wval; |
| 10441 | } |
| 10442 | } |
| 10443 | /* Read checksum word. */ |
| 10444 | *wbuf = AdvReadEEPWord(iop_base, eep_addr); |
| 10445 | wbuf++; |
| 10446 | charfields++; |
| 10447 | |
| 10448 | /* Read rest of EEPROM not covered by the checksum. */ |
| 10449 | for (eep_addr = ADV_EEP_DVC_CTL_BEGIN; |
| 10450 | eep_addr < ADV_EEP_MAX_WORD_ADDR; eep_addr++, wbuf++) { |
| 10451 | *wbuf = AdvReadEEPWord(iop_base, eep_addr); |
| 10452 | if (*charfields++) { |
| 10453 | *wbuf = le16_to_cpu(*wbuf); |
| 10454 | } |
| 10455 | } |
| 10456 | return chksum; |
| 10457 | } |
| 10458 | |
| 10459 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10460 | * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and |
| 10461 | * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while |
| 10462 | * all of this is done. |
| 10463 | * |
| 10464 | * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR. |
| 10465 | * |
| 10466 | * For a non-fatal error return a warning code. If there are no warnings |
| 10467 | * then 0 is returned. |
| 10468 | * |
| 10469 | * Note: Chip is stopped on entry. |
| 10470 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10471 | static int AdvInitFrom3550EEP(ADV_DVC_VAR *asc_dvc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10472 | { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10473 | AdvPortAddr iop_base; |
| 10474 | ushort warn_code; |
| 10475 | ADVEEP_3550_CONFIG eep_config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10476 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10477 | iop_base = asc_dvc->iop_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10478 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10479 | warn_code = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10480 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10481 | /* |
| 10482 | * Read the board's EEPROM configuration. |
| 10483 | * |
| 10484 | * Set default values if a bad checksum is found. |
| 10485 | */ |
| 10486 | if (AdvGet3550EEPConfig(iop_base, &eep_config) != eep_config.check_sum) { |
| 10487 | warn_code |= ASC_WARN_EEPROM_CHKSUM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10488 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10489 | /* |
| 10490 | * Set EEPROM default values. |
| 10491 | */ |
Matthew Wilcox | d68f432 | 2007-07-26 11:58:12 -0400 | [diff] [blame] | 10492 | memcpy(&eep_config, &Default_3550_EEPROM_Config, |
| 10493 | sizeof(ADVEEP_3550_CONFIG)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10494 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10495 | /* |
Matthew Wilcox | d68f432 | 2007-07-26 11:58:12 -0400 | [diff] [blame] | 10496 | * Assume the 6 byte board serial number that was read from |
| 10497 | * EEPROM is correct even if the EEPROM checksum failed. |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10498 | */ |
| 10499 | eep_config.serial_number_word3 = |
| 10500 | AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10501 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10502 | eep_config.serial_number_word2 = |
| 10503 | AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10504 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10505 | eep_config.serial_number_word1 = |
| 10506 | AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10507 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10508 | AdvSet3550EEPConfig(iop_base, &eep_config); |
| 10509 | } |
| 10510 | /* |
| 10511 | * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the |
| 10512 | * EEPROM configuration that was read. |
| 10513 | * |
| 10514 | * This is the mapping of EEPROM fields to Adv Library fields. |
| 10515 | */ |
| 10516 | asc_dvc->wdtr_able = eep_config.wdtr_able; |
| 10517 | asc_dvc->sdtr_able = eep_config.sdtr_able; |
| 10518 | asc_dvc->ultra_able = eep_config.ultra_able; |
| 10519 | asc_dvc->tagqng_able = eep_config.tagqng_able; |
| 10520 | asc_dvc->cfg->disc_enable = eep_config.disc_enable; |
| 10521 | asc_dvc->max_host_qng = eep_config.max_host_qng; |
| 10522 | asc_dvc->max_dvc_qng = eep_config.max_dvc_qng; |
| 10523 | asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID); |
| 10524 | asc_dvc->start_motor = eep_config.start_motor; |
| 10525 | asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay; |
| 10526 | asc_dvc->bios_ctrl = eep_config.bios_ctrl; |
| 10527 | asc_dvc->no_scam = eep_config.scam_tolerant; |
| 10528 | asc_dvc->cfg->serial1 = eep_config.serial_number_word1; |
| 10529 | asc_dvc->cfg->serial2 = eep_config.serial_number_word2; |
| 10530 | asc_dvc->cfg->serial3 = eep_config.serial_number_word3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10531 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10532 | /* |
| 10533 | * Set the host maximum queuing (max. 253, min. 16) and the per device |
| 10534 | * maximum queuing (max. 63, min. 4). |
| 10535 | */ |
| 10536 | if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) { |
| 10537 | eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG; |
| 10538 | } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) { |
| 10539 | /* If the value is zero, assume it is uninitialized. */ |
| 10540 | if (eep_config.max_host_qng == 0) { |
| 10541 | eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG; |
| 10542 | } else { |
| 10543 | eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG; |
| 10544 | } |
| 10545 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10546 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10547 | if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) { |
| 10548 | eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG; |
| 10549 | } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) { |
| 10550 | /* If the value is zero, assume it is uninitialized. */ |
| 10551 | if (eep_config.max_dvc_qng == 0) { |
| 10552 | eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG; |
| 10553 | } else { |
| 10554 | eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG; |
| 10555 | } |
| 10556 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10557 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10558 | /* |
| 10559 | * If 'max_dvc_qng' is greater than 'max_host_qng', then |
| 10560 | * set 'max_dvc_qng' to 'max_host_qng'. |
| 10561 | */ |
| 10562 | if (eep_config.max_dvc_qng > eep_config.max_host_qng) { |
| 10563 | eep_config.max_dvc_qng = eep_config.max_host_qng; |
| 10564 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10565 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10566 | /* |
| 10567 | * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng' |
| 10568 | * values based on possibly adjusted EEPROM values. |
| 10569 | */ |
| 10570 | asc_dvc->max_host_qng = eep_config.max_host_qng; |
| 10571 | asc_dvc->max_dvc_qng = eep_config.max_dvc_qng; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10572 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10573 | /* |
| 10574 | * If the EEPROM 'termination' field is set to automatic (0), then set |
| 10575 | * the ADV_DVC_CFG 'termination' field to automatic also. |
| 10576 | * |
| 10577 | * If the termination is specified with a non-zero 'termination' |
| 10578 | * value check that a legal value is set and set the ADV_DVC_CFG |
| 10579 | * 'termination' field appropriately. |
| 10580 | */ |
| 10581 | if (eep_config.termination == 0) { |
| 10582 | asc_dvc->cfg->termination = 0; /* auto termination */ |
| 10583 | } else { |
| 10584 | /* Enable manual control with low off / high off. */ |
| 10585 | if (eep_config.termination == 1) { |
| 10586 | asc_dvc->cfg->termination = TERM_CTL_SEL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10587 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10588 | /* Enable manual control with low off / high on. */ |
| 10589 | } else if (eep_config.termination == 2) { |
| 10590 | asc_dvc->cfg->termination = TERM_CTL_SEL | TERM_CTL_H; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10591 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10592 | /* Enable manual control with low on / high on. */ |
| 10593 | } else if (eep_config.termination == 3) { |
| 10594 | asc_dvc->cfg->termination = |
| 10595 | TERM_CTL_SEL | TERM_CTL_H | TERM_CTL_L; |
| 10596 | } else { |
| 10597 | /* |
| 10598 | * The EEPROM 'termination' field contains a bad value. Use |
| 10599 | * automatic termination instead. |
| 10600 | */ |
| 10601 | asc_dvc->cfg->termination = 0; |
| 10602 | warn_code |= ASC_WARN_EEPROM_TERMINATION; |
| 10603 | } |
| 10604 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10605 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10606 | return warn_code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10607 | } |
| 10608 | |
| 10609 | /* |
| 10610 | * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and |
| 10611 | * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while |
| 10612 | * all of this is done. |
| 10613 | * |
| 10614 | * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR. |
| 10615 | * |
| 10616 | * For a non-fatal error return a warning code. If there are no warnings |
| 10617 | * then 0 is returned. |
| 10618 | * |
| 10619 | * Note: Chip is stopped on entry. |
| 10620 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10621 | static int AdvInitFrom38C0800EEP(ADV_DVC_VAR *asc_dvc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10622 | { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10623 | AdvPortAddr iop_base; |
| 10624 | ushort warn_code; |
| 10625 | ADVEEP_38C0800_CONFIG eep_config; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10626 | uchar tid, termination; |
| 10627 | ushort sdtr_speed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10628 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10629 | iop_base = asc_dvc->iop_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10630 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10631 | warn_code = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10632 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10633 | /* |
| 10634 | * Read the board's EEPROM configuration. |
| 10635 | * |
| 10636 | * Set default values if a bad checksum is found. |
| 10637 | */ |
| 10638 | if (AdvGet38C0800EEPConfig(iop_base, &eep_config) != |
| 10639 | eep_config.check_sum) { |
| 10640 | warn_code |= ASC_WARN_EEPROM_CHKSUM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10641 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10642 | /* |
| 10643 | * Set EEPROM default values. |
| 10644 | */ |
Matthew Wilcox | d68f432 | 2007-07-26 11:58:12 -0400 | [diff] [blame] | 10645 | memcpy(&eep_config, &Default_38C0800_EEPROM_Config, |
| 10646 | sizeof(ADVEEP_38C0800_CONFIG)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10647 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10648 | /* |
Matthew Wilcox | d68f432 | 2007-07-26 11:58:12 -0400 | [diff] [blame] | 10649 | * Assume the 6 byte board serial number that was read from |
| 10650 | * EEPROM is correct even if the EEPROM checksum failed. |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10651 | */ |
| 10652 | eep_config.serial_number_word3 = |
| 10653 | AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10654 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10655 | eep_config.serial_number_word2 = |
| 10656 | AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10657 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10658 | eep_config.serial_number_word1 = |
| 10659 | AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10660 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10661 | AdvSet38C0800EEPConfig(iop_base, &eep_config); |
| 10662 | } |
| 10663 | /* |
| 10664 | * Set ADV_DVC_VAR and ADV_DVC_CFG variables from the |
| 10665 | * EEPROM configuration that was read. |
| 10666 | * |
| 10667 | * This is the mapping of EEPROM fields to Adv Library fields. |
| 10668 | */ |
| 10669 | asc_dvc->wdtr_able = eep_config.wdtr_able; |
| 10670 | asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1; |
| 10671 | asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2; |
| 10672 | asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3; |
| 10673 | asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4; |
| 10674 | asc_dvc->tagqng_able = eep_config.tagqng_able; |
| 10675 | asc_dvc->cfg->disc_enable = eep_config.disc_enable; |
| 10676 | asc_dvc->max_host_qng = eep_config.max_host_qng; |
| 10677 | asc_dvc->max_dvc_qng = eep_config.max_dvc_qng; |
| 10678 | asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID); |
| 10679 | asc_dvc->start_motor = eep_config.start_motor; |
| 10680 | asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay; |
| 10681 | asc_dvc->bios_ctrl = eep_config.bios_ctrl; |
| 10682 | asc_dvc->no_scam = eep_config.scam_tolerant; |
| 10683 | asc_dvc->cfg->serial1 = eep_config.serial_number_word1; |
| 10684 | asc_dvc->cfg->serial2 = eep_config.serial_number_word2; |
| 10685 | asc_dvc->cfg->serial3 = eep_config.serial_number_word3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10686 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10687 | /* |
| 10688 | * For every Target ID if any of its 'sdtr_speed[1234]' bits |
| 10689 | * are set, then set an 'sdtr_able' bit for it. |
| 10690 | */ |
| 10691 | asc_dvc->sdtr_able = 0; |
| 10692 | for (tid = 0; tid <= ADV_MAX_TID; tid++) { |
| 10693 | if (tid == 0) { |
| 10694 | sdtr_speed = asc_dvc->sdtr_speed1; |
| 10695 | } else if (tid == 4) { |
| 10696 | sdtr_speed = asc_dvc->sdtr_speed2; |
| 10697 | } else if (tid == 8) { |
| 10698 | sdtr_speed = asc_dvc->sdtr_speed3; |
| 10699 | } else if (tid == 12) { |
| 10700 | sdtr_speed = asc_dvc->sdtr_speed4; |
| 10701 | } |
| 10702 | if (sdtr_speed & ADV_MAX_TID) { |
| 10703 | asc_dvc->sdtr_able |= (1 << tid); |
| 10704 | } |
| 10705 | sdtr_speed >>= 4; |
| 10706 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10707 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10708 | /* |
| 10709 | * Set the host maximum queuing (max. 253, min. 16) and the per device |
| 10710 | * maximum queuing (max. 63, min. 4). |
| 10711 | */ |
| 10712 | if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) { |
| 10713 | eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG; |
| 10714 | } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) { |
| 10715 | /* If the value is zero, assume it is uninitialized. */ |
| 10716 | if (eep_config.max_host_qng == 0) { |
| 10717 | eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG; |
| 10718 | } else { |
| 10719 | eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG; |
| 10720 | } |
| 10721 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10722 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10723 | if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) { |
| 10724 | eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG; |
| 10725 | } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) { |
| 10726 | /* If the value is zero, assume it is uninitialized. */ |
| 10727 | if (eep_config.max_dvc_qng == 0) { |
| 10728 | eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG; |
| 10729 | } else { |
| 10730 | eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG; |
| 10731 | } |
| 10732 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10733 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10734 | /* |
| 10735 | * If 'max_dvc_qng' is greater than 'max_host_qng', then |
| 10736 | * set 'max_dvc_qng' to 'max_host_qng'. |
| 10737 | */ |
| 10738 | if (eep_config.max_dvc_qng > eep_config.max_host_qng) { |
| 10739 | eep_config.max_dvc_qng = eep_config.max_host_qng; |
| 10740 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10741 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10742 | /* |
| 10743 | * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng' |
| 10744 | * values based on possibly adjusted EEPROM values. |
| 10745 | */ |
| 10746 | asc_dvc->max_host_qng = eep_config.max_host_qng; |
| 10747 | asc_dvc->max_dvc_qng = eep_config.max_dvc_qng; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10748 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10749 | /* |
| 10750 | * If the EEPROM 'termination' field is set to automatic (0), then set |
| 10751 | * the ADV_DVC_CFG 'termination' field to automatic also. |
| 10752 | * |
| 10753 | * If the termination is specified with a non-zero 'termination' |
| 10754 | * value check that a legal value is set and set the ADV_DVC_CFG |
| 10755 | * 'termination' field appropriately. |
| 10756 | */ |
| 10757 | if (eep_config.termination_se == 0) { |
| 10758 | termination = 0; /* auto termination for SE */ |
| 10759 | } else { |
| 10760 | /* Enable manual control with low off / high off. */ |
| 10761 | if (eep_config.termination_se == 1) { |
| 10762 | termination = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10763 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10764 | /* Enable manual control with low off / high on. */ |
| 10765 | } else if (eep_config.termination_se == 2) { |
| 10766 | termination = TERM_SE_HI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10767 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10768 | /* Enable manual control with low on / high on. */ |
| 10769 | } else if (eep_config.termination_se == 3) { |
| 10770 | termination = TERM_SE; |
| 10771 | } else { |
| 10772 | /* |
| 10773 | * The EEPROM 'termination_se' field contains a bad value. |
| 10774 | * Use automatic termination instead. |
| 10775 | */ |
| 10776 | termination = 0; |
| 10777 | warn_code |= ASC_WARN_EEPROM_TERMINATION; |
| 10778 | } |
| 10779 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10780 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10781 | if (eep_config.termination_lvd == 0) { |
| 10782 | asc_dvc->cfg->termination = termination; /* auto termination for LVD */ |
| 10783 | } else { |
| 10784 | /* Enable manual control with low off / high off. */ |
| 10785 | if (eep_config.termination_lvd == 1) { |
| 10786 | asc_dvc->cfg->termination = termination; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10787 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10788 | /* Enable manual control with low off / high on. */ |
| 10789 | } else if (eep_config.termination_lvd == 2) { |
| 10790 | asc_dvc->cfg->termination = termination | TERM_LVD_HI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10791 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10792 | /* Enable manual control with low on / high on. */ |
| 10793 | } else if (eep_config.termination_lvd == 3) { |
| 10794 | asc_dvc->cfg->termination = termination | TERM_LVD; |
| 10795 | } else { |
| 10796 | /* |
| 10797 | * The EEPROM 'termination_lvd' field contains a bad value. |
| 10798 | * Use automatic termination instead. |
| 10799 | */ |
| 10800 | asc_dvc->cfg->termination = termination; |
| 10801 | warn_code |= ASC_WARN_EEPROM_TERMINATION; |
| 10802 | } |
| 10803 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10804 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10805 | return warn_code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10806 | } |
| 10807 | |
| 10808 | /* |
| 10809 | * Read the board's EEPROM configuration. Set fields in ASC_DVC_VAR and |
| 10810 | * ASC_DVC_CFG based on the EEPROM settings. The chip is stopped while |
| 10811 | * all of this is done. |
| 10812 | * |
| 10813 | * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR. |
| 10814 | * |
| 10815 | * For a non-fatal error return a warning code. If there are no warnings |
| 10816 | * then 0 is returned. |
| 10817 | * |
| 10818 | * Note: Chip is stopped on entry. |
| 10819 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10820 | static int AdvInitFrom38C1600EEP(ADV_DVC_VAR *asc_dvc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10821 | { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10822 | AdvPortAddr iop_base; |
| 10823 | ushort warn_code; |
| 10824 | ADVEEP_38C1600_CONFIG eep_config; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10825 | uchar tid, termination; |
| 10826 | ushort sdtr_speed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10827 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10828 | iop_base = asc_dvc->iop_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10829 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10830 | warn_code = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10831 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10832 | /* |
| 10833 | * Read the board's EEPROM configuration. |
| 10834 | * |
| 10835 | * Set default values if a bad checksum is found. |
| 10836 | */ |
| 10837 | if (AdvGet38C1600EEPConfig(iop_base, &eep_config) != |
| 10838 | eep_config.check_sum) { |
Matthew Wilcox | 13ac2d9 | 2007-07-30 08:10:23 -0600 | [diff] [blame] | 10839 | struct pci_dev *pdev = adv_dvc_to_pdev(asc_dvc); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10840 | warn_code |= ASC_WARN_EEPROM_CHKSUM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10841 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10842 | /* |
| 10843 | * Set EEPROM default values. |
| 10844 | */ |
Matthew Wilcox | d68f432 | 2007-07-26 11:58:12 -0400 | [diff] [blame] | 10845 | memcpy(&eep_config, &Default_38C1600_EEPROM_Config, |
| 10846 | sizeof(ADVEEP_38C1600_CONFIG)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10847 | |
Matthew Wilcox | d68f432 | 2007-07-26 11:58:12 -0400 | [diff] [blame] | 10848 | if (PCI_FUNC(pdev->devfn) != 0) { |
| 10849 | u8 ints; |
| 10850 | /* |
| 10851 | * Disable Bit 14 (BIOS_ENABLE) to fix SPARC Ultra 60 |
| 10852 | * and old Mac system booting problem. The Expansion |
| 10853 | * ROM must be disabled in Function 1 for these systems |
| 10854 | */ |
| 10855 | eep_config.cfg_lsw &= ~ADV_EEPROM_BIOS_ENABLE; |
| 10856 | /* |
| 10857 | * Clear the INTAB (bit 11) if the GPIO 0 input |
| 10858 | * indicates the Function 1 interrupt line is wired |
| 10859 | * to INTB. |
| 10860 | * |
| 10861 | * Set/Clear Bit 11 (INTAB) from the GPIO bit 0 input: |
| 10862 | * 1 - Function 1 interrupt line wired to INT A. |
| 10863 | * 0 - Function 1 interrupt line wired to INT B. |
| 10864 | * |
| 10865 | * Note: Function 0 is always wired to INTA. |
| 10866 | * Put all 5 GPIO bits in input mode and then read |
| 10867 | * their input values. |
| 10868 | */ |
| 10869 | AdvWriteByteRegister(iop_base, IOPB_GPIO_CNTL, 0); |
| 10870 | ints = AdvReadByteRegister(iop_base, IOPB_GPIO_DATA); |
| 10871 | if ((ints & 0x01) == 0) |
| 10872 | eep_config.cfg_lsw &= ~ADV_EEPROM_INTAB; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10873 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10874 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10875 | /* |
Matthew Wilcox | d68f432 | 2007-07-26 11:58:12 -0400 | [diff] [blame] | 10876 | * Assume the 6 byte board serial number that was read from |
| 10877 | * EEPROM is correct even if the EEPROM checksum failed. |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10878 | */ |
| 10879 | eep_config.serial_number_word3 = |
Matthew Wilcox | d68f432 | 2007-07-26 11:58:12 -0400 | [diff] [blame] | 10880 | AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10881 | eep_config.serial_number_word2 = |
Matthew Wilcox | d68f432 | 2007-07-26 11:58:12 -0400 | [diff] [blame] | 10882 | AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10883 | eep_config.serial_number_word1 = |
Matthew Wilcox | d68f432 | 2007-07-26 11:58:12 -0400 | [diff] [blame] | 10884 | AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10885 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10886 | AdvSet38C1600EEPConfig(iop_base, &eep_config); |
| 10887 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10888 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10889 | /* |
| 10890 | * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the |
| 10891 | * EEPROM configuration that was read. |
| 10892 | * |
| 10893 | * This is the mapping of EEPROM fields to Adv Library fields. |
| 10894 | */ |
| 10895 | asc_dvc->wdtr_able = eep_config.wdtr_able; |
| 10896 | asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1; |
| 10897 | asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2; |
| 10898 | asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3; |
| 10899 | asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4; |
| 10900 | asc_dvc->ppr_able = 0; |
| 10901 | asc_dvc->tagqng_able = eep_config.tagqng_able; |
| 10902 | asc_dvc->cfg->disc_enable = eep_config.disc_enable; |
| 10903 | asc_dvc->max_host_qng = eep_config.max_host_qng; |
| 10904 | asc_dvc->max_dvc_qng = eep_config.max_dvc_qng; |
| 10905 | asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ASC_MAX_TID); |
| 10906 | asc_dvc->start_motor = eep_config.start_motor; |
| 10907 | asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay; |
| 10908 | asc_dvc->bios_ctrl = eep_config.bios_ctrl; |
| 10909 | asc_dvc->no_scam = eep_config.scam_tolerant; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10910 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10911 | /* |
| 10912 | * For every Target ID if any of its 'sdtr_speed[1234]' bits |
| 10913 | * are set, then set an 'sdtr_able' bit for it. |
| 10914 | */ |
| 10915 | asc_dvc->sdtr_able = 0; |
| 10916 | for (tid = 0; tid <= ASC_MAX_TID; tid++) { |
| 10917 | if (tid == 0) { |
| 10918 | sdtr_speed = asc_dvc->sdtr_speed1; |
| 10919 | } else if (tid == 4) { |
| 10920 | sdtr_speed = asc_dvc->sdtr_speed2; |
| 10921 | } else if (tid == 8) { |
| 10922 | sdtr_speed = asc_dvc->sdtr_speed3; |
| 10923 | } else if (tid == 12) { |
| 10924 | sdtr_speed = asc_dvc->sdtr_speed4; |
| 10925 | } |
| 10926 | if (sdtr_speed & ASC_MAX_TID) { |
| 10927 | asc_dvc->sdtr_able |= (1 << tid); |
| 10928 | } |
| 10929 | sdtr_speed >>= 4; |
| 10930 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10931 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10932 | /* |
| 10933 | * Set the host maximum queuing (max. 253, min. 16) and the per device |
| 10934 | * maximum queuing (max. 63, min. 4). |
| 10935 | */ |
| 10936 | if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) { |
| 10937 | eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG; |
| 10938 | } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) { |
| 10939 | /* If the value is zero, assume it is uninitialized. */ |
| 10940 | if (eep_config.max_host_qng == 0) { |
| 10941 | eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG; |
| 10942 | } else { |
| 10943 | eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG; |
| 10944 | } |
| 10945 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10946 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10947 | if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) { |
| 10948 | eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG; |
| 10949 | } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) { |
| 10950 | /* If the value is zero, assume it is uninitialized. */ |
| 10951 | if (eep_config.max_dvc_qng == 0) { |
| 10952 | eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG; |
| 10953 | } else { |
| 10954 | eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG; |
| 10955 | } |
| 10956 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10957 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10958 | /* |
| 10959 | * If 'max_dvc_qng' is greater than 'max_host_qng', then |
| 10960 | * set 'max_dvc_qng' to 'max_host_qng'. |
| 10961 | */ |
| 10962 | if (eep_config.max_dvc_qng > eep_config.max_host_qng) { |
| 10963 | eep_config.max_dvc_qng = eep_config.max_host_qng; |
| 10964 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10965 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10966 | /* |
| 10967 | * Set ASC_DVC_VAR 'max_host_qng' and ASC_DVC_VAR 'max_dvc_qng' |
| 10968 | * values based on possibly adjusted EEPROM values. |
| 10969 | */ |
| 10970 | asc_dvc->max_host_qng = eep_config.max_host_qng; |
| 10971 | asc_dvc->max_dvc_qng = eep_config.max_dvc_qng; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10972 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10973 | /* |
| 10974 | * If the EEPROM 'termination' field is set to automatic (0), then set |
| 10975 | * the ASC_DVC_CFG 'termination' field to automatic also. |
| 10976 | * |
| 10977 | * If the termination is specified with a non-zero 'termination' |
| 10978 | * value check that a legal value is set and set the ASC_DVC_CFG |
| 10979 | * 'termination' field appropriately. |
| 10980 | */ |
| 10981 | if (eep_config.termination_se == 0) { |
| 10982 | termination = 0; /* auto termination for SE */ |
| 10983 | } else { |
| 10984 | /* Enable manual control with low off / high off. */ |
| 10985 | if (eep_config.termination_se == 1) { |
| 10986 | termination = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10987 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10988 | /* Enable manual control with low off / high on. */ |
| 10989 | } else if (eep_config.termination_se == 2) { |
| 10990 | termination = TERM_SE_HI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10991 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 10992 | /* Enable manual control with low on / high on. */ |
| 10993 | } else if (eep_config.termination_se == 3) { |
| 10994 | termination = TERM_SE; |
| 10995 | } else { |
| 10996 | /* |
| 10997 | * The EEPROM 'termination_se' field contains a bad value. |
| 10998 | * Use automatic termination instead. |
| 10999 | */ |
| 11000 | termination = 0; |
| 11001 | warn_code |= ASC_WARN_EEPROM_TERMINATION; |
| 11002 | } |
| 11003 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11004 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11005 | if (eep_config.termination_lvd == 0) { |
| 11006 | asc_dvc->cfg->termination = termination; /* auto termination for LVD */ |
| 11007 | } else { |
| 11008 | /* Enable manual control with low off / high off. */ |
| 11009 | if (eep_config.termination_lvd == 1) { |
| 11010 | asc_dvc->cfg->termination = termination; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11011 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11012 | /* Enable manual control with low off / high on. */ |
| 11013 | } else if (eep_config.termination_lvd == 2) { |
| 11014 | asc_dvc->cfg->termination = termination | TERM_LVD_HI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11015 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11016 | /* Enable manual control with low on / high on. */ |
| 11017 | } else if (eep_config.termination_lvd == 3) { |
| 11018 | asc_dvc->cfg->termination = termination | TERM_LVD; |
| 11019 | } else { |
| 11020 | /* |
| 11021 | * The EEPROM 'termination_lvd' field contains a bad value. |
| 11022 | * Use automatic termination instead. |
| 11023 | */ |
| 11024 | asc_dvc->cfg->termination = termination; |
| 11025 | warn_code |= ASC_WARN_EEPROM_TERMINATION; |
| 11026 | } |
| 11027 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11028 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11029 | return warn_code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11030 | } |
| 11031 | |
| 11032 | /* |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 11033 | * Initialize the ADV_DVC_VAR structure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11034 | * |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 11035 | * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11036 | * |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 11037 | * For a non-fatal error return a warning code. If there are no warnings |
| 11038 | * then 0 is returned. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11039 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11040 | static int AdvInitGetConfig(struct pci_dev *pdev, struct Scsi_Host *shost) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11041 | { |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11042 | struct asc_board *board = shost_priv(shost); |
| 11043 | ADV_DVC_VAR *asc_dvc = &board->dvc_var.adv_dvc_var; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 11044 | unsigned short warn_code = 0; |
| 11045 | AdvPortAddr iop_base = asc_dvc->iop_base; |
| 11046 | u16 cmd; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11047 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11048 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11049 | asc_dvc->err_code = 0; |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 11050 | |
| 11051 | /* |
| 11052 | * Save the state of the PCI Configuration Command Register |
| 11053 | * "Parity Error Response Control" Bit. If the bit is clear (0), |
| 11054 | * in AdvInitAsc3550/38C0800Driver() tell the microcode to ignore |
| 11055 | * DMA parity errors. |
| 11056 | */ |
| 11057 | asc_dvc->cfg->control_flag = 0; |
| 11058 | pci_read_config_word(pdev, PCI_COMMAND, &cmd); |
| 11059 | if ((cmd & PCI_COMMAND_PARITY) == 0) |
| 11060 | asc_dvc->cfg->control_flag |= CONTROL_FLAG_IGNORE_PERR; |
| 11061 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 11062 | asc_dvc->cfg->chip_version = |
| 11063 | AdvGetChipVersion(iop_base, asc_dvc->bus_type); |
| 11064 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11065 | ASC_DBG(1, "iopb_chip_id_1: 0x%x 0x%x\n", |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 11066 | (ushort)AdvReadByteRegister(iop_base, IOPB_CHIP_ID_1), |
| 11067 | (ushort)ADV_CHIP_ID_BYTE); |
| 11068 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11069 | ASC_DBG(1, "iopw_chip_id_0: 0x%x 0x%x\n", |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 11070 | (ushort)AdvReadWordRegister(iop_base, IOPW_CHIP_ID_0), |
| 11071 | (ushort)ADV_CHIP_ID_WORD); |
| 11072 | |
| 11073 | /* |
| 11074 | * Reset the chip to start and allow register writes. |
| 11075 | */ |
| 11076 | if (AdvFindSignature(iop_base) == 0) { |
| 11077 | asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE; |
| 11078 | return ADV_ERROR; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11079 | } else { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11080 | /* |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 11081 | * The caller must set 'chip_type' to a valid setting. |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11082 | */ |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 11083 | if (asc_dvc->chip_type != ADV_CHIP_ASC3550 && |
| 11084 | asc_dvc->chip_type != ADV_CHIP_ASC38C0800 && |
| 11085 | asc_dvc->chip_type != ADV_CHIP_ASC38C1600) { |
| 11086 | asc_dvc->err_code |= ASC_IERR_BAD_CHIPTYPE; |
| 11087 | return ADV_ERROR; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11088 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11089 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11090 | /* |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 11091 | * Reset Chip. |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11092 | */ |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 11093 | AdvWriteWordRegister(iop_base, IOPW_CTRL_REG, |
| 11094 | ADV_CTRL_REG_CMD_RESET); |
| 11095 | mdelay(100); |
| 11096 | AdvWriteWordRegister(iop_base, IOPW_CTRL_REG, |
| 11097 | ADV_CTRL_REG_CMD_WR_IO_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11098 | |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 11099 | if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600) { |
| 11100 | status = AdvInitFrom38C1600EEP(asc_dvc); |
| 11101 | } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800) { |
| 11102 | status = AdvInitFrom38C0800EEP(asc_dvc); |
| 11103 | } else { |
| 11104 | status = AdvInitFrom3550EEP(asc_dvc); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11105 | } |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 11106 | warn_code |= status; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11107 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11108 | |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11109 | if (warn_code != 0) |
| 11110 | shost_printk(KERN_WARNING, shost, "warning: 0x%x\n", warn_code); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 11111 | |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11112 | if (asc_dvc->err_code) |
| 11113 | shost_printk(KERN_ERR, shost, "error code 0x%x\n", |
| 11114 | asc_dvc->err_code); |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 11115 | |
| 11116 | return asc_dvc->err_code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11117 | } |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 11118 | #endif |
| 11119 | |
| 11120 | static struct scsi_host_template advansys_template = { |
| 11121 | .proc_name = DRV_NAME, |
| 11122 | #ifdef CONFIG_PROC_FS |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 11123 | .show_info = advansys_show_info, |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 11124 | #endif |
| 11125 | .name = DRV_NAME, |
| 11126 | .info = advansys_info, |
| 11127 | .queuecommand = advansys_queuecommand, |
Hannes Reinecke | eac0b0c | 2015-04-24 13:18:20 +0200 | [diff] [blame] | 11128 | .eh_host_reset_handler = advansys_reset, |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 11129 | .bios_param = advansys_biosparam, |
| 11130 | .slave_configure = advansys_slave_configure, |
| 11131 | /* |
| 11132 | * Because the driver may control an ISA adapter 'unchecked_isa_dma' |
| 11133 | * must be set. The flag will be cleared in advansys_board_found |
| 11134 | * for non-ISA adapters. |
| 11135 | */ |
| 11136 | .unchecked_isa_dma = 1, |
| 11137 | /* |
| 11138 | * All adapters controlled by this driver are capable of large |
| 11139 | * scatter-gather lists. According to the mid-level SCSI documentation |
| 11140 | * this obviates any performance gain provided by setting |
| 11141 | * 'use_clustering'. But empirically while CPU utilization is increased |
| 11142 | * by enabling clustering, I/O throughput increases as well. |
| 11143 | */ |
| 11144 | .use_clustering = ENABLE_CLUSTERING, |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 11145 | .use_blk_tags = 1, |
Matthew Wilcox | 5121935 | 2007-10-02 21:55:22 -0400 | [diff] [blame] | 11146 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11147 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11148 | static int advansys_wide_init_chip(struct Scsi_Host *shost) |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11149 | { |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11150 | struct asc_board *board = shost_priv(shost); |
| 11151 | struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var; |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 11152 | size_t sgblk_pool_size; |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11153 | int warn_code, err_code; |
| 11154 | |
| 11155 | /* |
| 11156 | * Allocate buffer carrier structures. The total size |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 11157 | * is about 8 KB, so allocate all at once. |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11158 | */ |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 11159 | adv_dvc->carrier = dma_alloc_coherent(board->dev, |
| 11160 | ADV_CARRIER_BUFSIZE, &adv_dvc->carrier_addr, GFP_KERNEL); |
| 11161 | ASC_DBG(1, "carrier 0x%p\n", adv_dvc->carrier); |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11162 | |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 11163 | if (!adv_dvc->carrier) |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11164 | goto kmalloc_failed; |
| 11165 | |
| 11166 | /* |
| 11167 | * Allocate up to 'max_host_qng' request structures for the Wide |
| 11168 | * board. The total size is about 16 KB, so allocate all at once. |
| 11169 | * If the allocation fails decrement and try again. |
| 11170 | */ |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 11171 | board->adv_reqp_size = adv_dvc->max_host_qng * sizeof(adv_req_t); |
| 11172 | if (board->adv_reqp_size & 0x1f) { |
| 11173 | ASC_DBG(1, "unaligned reqp %lu bytes\n", sizeof(adv_req_t)); |
| 11174 | board->adv_reqp_size = ADV_32BALIGN(board->adv_reqp_size); |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11175 | } |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 11176 | board->adv_reqp = dma_alloc_coherent(board->dev, board->adv_reqp_size, |
| 11177 | &board->adv_reqp_addr, GFP_KERNEL); |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11178 | |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 11179 | if (!board->adv_reqp) |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11180 | goto kmalloc_failed; |
| 11181 | |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 11182 | ASC_DBG(1, "reqp 0x%p, req_cnt %d, bytes %lu\n", board->adv_reqp, |
| 11183 | adv_dvc->max_host_qng, board->adv_reqp_size); |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11184 | |
| 11185 | /* |
| 11186 | * Allocate up to ADV_TOT_SG_BLOCK request structures for |
| 11187 | * the Wide board. Each structure is about 136 bytes. |
| 11188 | */ |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 11189 | sgblk_pool_size = sizeof(adv_sgblk_t) * ADV_TOT_SG_BLOCK; |
| 11190 | board->adv_sgblk_pool = dma_pool_create("adv_sgblk", board->dev, |
| 11191 | sgblk_pool_size, 32, 0); |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11192 | |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 11193 | ASC_DBG(1, "sg_cnt %d * %lu = %lu bytes\n", ADV_TOT_SG_BLOCK, |
| 11194 | sizeof(adv_sgblk_t), sgblk_pool_size); |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11195 | |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 11196 | if (!board->adv_sgblk_pool) |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11197 | goto kmalloc_failed; |
| 11198 | |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11199 | if (adv_dvc->chip_type == ADV_CHIP_ASC3550) { |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11200 | ASC_DBG(2, "AdvInitAsc3550Driver()\n"); |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11201 | warn_code = AdvInitAsc3550Driver(adv_dvc); |
| 11202 | } else if (adv_dvc->chip_type == ADV_CHIP_ASC38C0800) { |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11203 | ASC_DBG(2, "AdvInitAsc38C0800Driver()\n"); |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11204 | warn_code = AdvInitAsc38C0800Driver(adv_dvc); |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11205 | } else { |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11206 | ASC_DBG(2, "AdvInitAsc38C1600Driver()\n"); |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11207 | warn_code = AdvInitAsc38C1600Driver(adv_dvc); |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11208 | } |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11209 | err_code = adv_dvc->err_code; |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11210 | |
| 11211 | if (warn_code || err_code) { |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11212 | shost_printk(KERN_WARNING, shost, "error: warn 0x%x, error " |
| 11213 | "0x%x\n", warn_code, err_code); |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11214 | } |
| 11215 | |
| 11216 | goto exit; |
| 11217 | |
| 11218 | kmalloc_failed: |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11219 | shost_printk(KERN_ERR, shost, "error: kmalloc() failed\n"); |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11220 | err_code = ADV_ERROR; |
| 11221 | exit: |
| 11222 | return err_code; |
| 11223 | } |
| 11224 | |
Matthew Wilcox | 98d41c2 | 2007-10-02 21:55:37 -0400 | [diff] [blame] | 11225 | static void advansys_wide_free_mem(struct asc_board *board) |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11226 | { |
Matthew Wilcox | 98d41c2 | 2007-10-02 21:55:37 -0400 | [diff] [blame] | 11227 | struct adv_dvc_var *adv_dvc = &board->dvc_var.adv_dvc_var; |
Hannes Reinecke | 98b96a7 | 2015-04-24 13:18:23 +0200 | [diff] [blame] | 11228 | |
| 11229 | if (adv_dvc->carrier) { |
| 11230 | dma_free_coherent(board->dev, ADV_CARRIER_BUFSIZE, |
| 11231 | adv_dvc->carrier, adv_dvc->carrier_addr); |
| 11232 | adv_dvc->carrier = NULL; |
| 11233 | } |
Hannes Reinecke | 4b47e46 | 2015-04-24 13:18:24 +0200 | [diff] [blame] | 11234 | if (board->adv_reqp) { |
| 11235 | dma_free_coherent(board->dev, board->adv_reqp_size, |
| 11236 | board->adv_reqp, board->adv_reqp_addr); |
| 11237 | board->adv_reqp = NULL; |
| 11238 | } |
Hannes Reinecke | 0ce5382 | 2015-04-24 13:18:25 +0200 | [diff] [blame] | 11239 | if (board->adv_sgblk_pool) { |
| 11240 | dma_pool_destroy(board->adv_sgblk_pool); |
| 11241 | board->adv_sgblk_pool = NULL; |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11242 | } |
| 11243 | } |
| 11244 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11245 | static int advansys_board_found(struct Scsi_Host *shost, unsigned int iop, |
| 11246 | int bus_type) |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11247 | { |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11248 | struct pci_dev *pdev; |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 11249 | struct asc_board *boardp = shost_priv(shost); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11250 | ASC_DVC_VAR *asc_dvc_varp = NULL; |
| 11251 | ADV_DVC_VAR *adv_dvc_varp = NULL; |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11252 | int share_irq, warn_code, ret; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11253 | |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11254 | pdev = (bus_type == ASC_IS_PCI) ? to_pci_dev(boardp->dev) : NULL; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11255 | |
| 11256 | if (ASC_NARROW_BOARD(boardp)) { |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11257 | ASC_DBG(1, "narrow board\n"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11258 | asc_dvc_varp = &boardp->dvc_var.asc_dvc_var; |
| 11259 | asc_dvc_varp->bus_type = bus_type; |
| 11260 | asc_dvc_varp->drv_ptr = boardp; |
| 11261 | asc_dvc_varp->cfg = &boardp->dvc_cfg.asc_dvc_cfg; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11262 | asc_dvc_varp->iop_base = iop; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11263 | } else { |
Matthew Wilcox | 57ba5fe | 2007-07-26 11:55:07 -0400 | [diff] [blame] | 11264 | #ifdef CONFIG_PCI |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11265 | adv_dvc_varp = &boardp->dvc_var.adv_dvc_var; |
| 11266 | adv_dvc_varp->drv_ptr = boardp; |
| 11267 | adv_dvc_varp->cfg = &boardp->dvc_cfg.adv_dvc_cfg; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11268 | if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW) { |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11269 | ASC_DBG(1, "wide board ASC-3550\n"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11270 | adv_dvc_varp->chip_type = ADV_CHIP_ASC3550; |
| 11271 | } else if (pdev->device == PCI_DEVICE_ID_38C0800_REV1) { |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11272 | ASC_DBG(1, "wide board ASC-38C0800\n"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11273 | adv_dvc_varp->chip_type = ADV_CHIP_ASC38C0800; |
| 11274 | } else { |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11275 | ASC_DBG(1, "wide board ASC-38C1600\n"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11276 | adv_dvc_varp->chip_type = ADV_CHIP_ASC38C1600; |
| 11277 | } |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11278 | |
Matthew Wilcox | 57ba5fe | 2007-07-26 11:55:07 -0400 | [diff] [blame] | 11279 | boardp->asc_n_io_port = pci_resource_len(pdev, 1); |
Arjan van de Ven | 25729a7 | 2008-09-28 16:18:02 -0700 | [diff] [blame] | 11280 | boardp->ioremap_addr = pci_ioremap_bar(pdev, 1); |
Matthew Wilcox | 57ba5fe | 2007-07-26 11:55:07 -0400 | [diff] [blame] | 11281 | if (!boardp->ioremap_addr) { |
Matthew Wilcox | 9d511a4 | 2007-10-02 21:55:42 -0400 | [diff] [blame] | 11282 | shost_printk(KERN_ERR, shost, "ioremap(%lx, %d) " |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11283 | "returned NULL\n", |
Matthew Wilcox | 9d511a4 | 2007-10-02 21:55:42 -0400 | [diff] [blame] | 11284 | (long)pci_resource_start(pdev, 1), |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11285 | boardp->asc_n_io_port); |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11286 | ret = -ENODEV; |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11287 | goto err_shost; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11288 | } |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11289 | adv_dvc_varp->iop_base = (AdvPortAddr)boardp->ioremap_addr; |
| 11290 | ASC_DBG(1, "iop_base: 0x%p\n", adv_dvc_varp->iop_base); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11291 | |
| 11292 | /* |
| 11293 | * Even though it isn't used to access wide boards, other |
| 11294 | * than for the debug line below, save I/O Port address so |
| 11295 | * that it can be reported. |
| 11296 | */ |
| 11297 | boardp->ioport = iop; |
| 11298 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11299 | ASC_DBG(1, "iopb_chip_id_1 0x%x, iopw_chip_id_0 0x%x\n", |
| 11300 | (ushort)inp(iop + 1), (ushort)inpw(iop)); |
Matthew Wilcox | 57ba5fe | 2007-07-26 11:55:07 -0400 | [diff] [blame] | 11301 | #endif /* CONFIG_PCI */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11302 | } |
| 11303 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11304 | if (ASC_NARROW_BOARD(boardp)) { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11305 | /* |
| 11306 | * Set the board bus type and PCI IRQ before |
| 11307 | * calling AscInitGetConfig(). |
| 11308 | */ |
| 11309 | switch (asc_dvc_varp->bus_type) { |
| 11310 | #ifdef CONFIG_ISA |
| 11311 | case ASC_IS_ISA: |
| 11312 | shost->unchecked_isa_dma = TRUE; |
Matthew Wilcox | 074c8fe | 2007-07-28 23:11:05 -0600 | [diff] [blame] | 11313 | share_irq = 0; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11314 | break; |
| 11315 | case ASC_IS_VL: |
| 11316 | shost->unchecked_isa_dma = FALSE; |
Matthew Wilcox | 074c8fe | 2007-07-28 23:11:05 -0600 | [diff] [blame] | 11317 | share_irq = 0; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11318 | break; |
| 11319 | case ASC_IS_EISA: |
| 11320 | shost->unchecked_isa_dma = FALSE; |
Matthew Wilcox | 074c8fe | 2007-07-28 23:11:05 -0600 | [diff] [blame] | 11321 | share_irq = IRQF_SHARED; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11322 | break; |
| 11323 | #endif /* CONFIG_ISA */ |
| 11324 | #ifdef CONFIG_PCI |
| 11325 | case ASC_IS_PCI: |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11326 | shost->unchecked_isa_dma = FALSE; |
Matthew Wilcox | 074c8fe | 2007-07-28 23:11:05 -0600 | [diff] [blame] | 11327 | share_irq = IRQF_SHARED; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11328 | break; |
| 11329 | #endif /* CONFIG_PCI */ |
| 11330 | default: |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11331 | shost_printk(KERN_ERR, shost, "unknown adapter type: " |
| 11332 | "%d\n", asc_dvc_varp->bus_type); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11333 | shost->unchecked_isa_dma = TRUE; |
Matthew Wilcox | 074c8fe | 2007-07-28 23:11:05 -0600 | [diff] [blame] | 11334 | share_irq = 0; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11335 | break; |
| 11336 | } |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11337 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11338 | /* |
| 11339 | * NOTE: AscInitGetConfig() may change the board's |
| 11340 | * bus_type value. The bus_type value should no |
| 11341 | * longer be used. If the bus_type field must be |
| 11342 | * referenced only use the bit-wise AND operator "&". |
| 11343 | */ |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11344 | ASC_DBG(2, "AscInitGetConfig()\n"); |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11345 | ret = AscInitGetConfig(shost) ? -ENODEV : 0; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11346 | } else { |
Matthew Wilcox | c2dce2f | 2007-09-09 08:56:30 -0600 | [diff] [blame] | 11347 | #ifdef CONFIG_PCI |
| 11348 | /* |
| 11349 | * For Wide boards set PCI information before calling |
| 11350 | * AdvInitGetConfig(). |
| 11351 | */ |
Matthew Wilcox | c2dce2f | 2007-09-09 08:56:30 -0600 | [diff] [blame] | 11352 | shost->unchecked_isa_dma = FALSE; |
| 11353 | share_irq = IRQF_SHARED; |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11354 | ASC_DBG(2, "AdvInitGetConfig()\n"); |
Matthew Wilcox | 394dbf3 | 2007-07-26 11:56:40 -0400 | [diff] [blame] | 11355 | |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11356 | ret = AdvInitGetConfig(pdev, shost) ? -ENODEV : 0; |
Matthew Wilcox | c2dce2f | 2007-09-09 08:56:30 -0600 | [diff] [blame] | 11357 | #endif /* CONFIG_PCI */ |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11358 | } |
| 11359 | |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11360 | if (ret) |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 11361 | goto err_unmap; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11362 | |
| 11363 | /* |
| 11364 | * Save the EEPROM configuration so that it can be displayed |
| 11365 | * from /proc/scsi/advansys/[0...]. |
| 11366 | */ |
| 11367 | if (ASC_NARROW_BOARD(boardp)) { |
| 11368 | |
| 11369 | ASCEEP_CONFIG *ep; |
| 11370 | |
| 11371 | /* |
| 11372 | * Set the adapter's target id bit in the 'init_tidmask' field. |
| 11373 | */ |
| 11374 | boardp->init_tidmask |= |
| 11375 | ADV_TID_TO_TIDMASK(asc_dvc_varp->cfg->chip_scsi_id); |
| 11376 | |
| 11377 | /* |
| 11378 | * Save EEPROM settings for the board. |
| 11379 | */ |
| 11380 | ep = &boardp->eep_config.asc_eep; |
| 11381 | |
| 11382 | ep->init_sdtr = asc_dvc_varp->cfg->sdtr_enable; |
| 11383 | ep->disc_enable = asc_dvc_varp->cfg->disc_enable; |
| 11384 | ep->use_cmd_qng = asc_dvc_varp->cfg->cmd_qng_enabled; |
| 11385 | ASC_EEP_SET_DMA_SPD(ep, asc_dvc_varp->cfg->isa_dma_speed); |
| 11386 | ep->start_motor = asc_dvc_varp->start_motor; |
| 11387 | ep->cntl = asc_dvc_varp->dvc_cntl; |
| 11388 | ep->no_scam = asc_dvc_varp->no_scam; |
| 11389 | ep->max_total_qng = asc_dvc_varp->max_total_qng; |
| 11390 | ASC_EEP_SET_CHIP_ID(ep, asc_dvc_varp->cfg->chip_scsi_id); |
| 11391 | /* 'max_tag_qng' is set to the same value for every device. */ |
| 11392 | ep->max_tag_qng = asc_dvc_varp->cfg->max_tag_qng[0]; |
| 11393 | ep->adapter_info[0] = asc_dvc_varp->cfg->adapter_info[0]; |
| 11394 | ep->adapter_info[1] = asc_dvc_varp->cfg->adapter_info[1]; |
| 11395 | ep->adapter_info[2] = asc_dvc_varp->cfg->adapter_info[2]; |
| 11396 | ep->adapter_info[3] = asc_dvc_varp->cfg->adapter_info[3]; |
| 11397 | ep->adapter_info[4] = asc_dvc_varp->cfg->adapter_info[4]; |
| 11398 | ep->adapter_info[5] = asc_dvc_varp->cfg->adapter_info[5]; |
| 11399 | |
| 11400 | /* |
| 11401 | * Modify board configuration. |
| 11402 | */ |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11403 | ASC_DBG(2, "AscInitSetConfig()\n"); |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11404 | ret = AscInitSetConfig(pdev, shost) ? -ENODEV : 0; |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11405 | if (ret) |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 11406 | goto err_unmap; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11407 | } else { |
| 11408 | ADVEEP_3550_CONFIG *ep_3550; |
| 11409 | ADVEEP_38C0800_CONFIG *ep_38C0800; |
| 11410 | ADVEEP_38C1600_CONFIG *ep_38C1600; |
| 11411 | |
| 11412 | /* |
| 11413 | * Save Wide EEP Configuration Information. |
| 11414 | */ |
| 11415 | if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550) { |
| 11416 | ep_3550 = &boardp->eep_config.adv_3550_eep; |
| 11417 | |
| 11418 | ep_3550->adapter_scsi_id = adv_dvc_varp->chip_scsi_id; |
| 11419 | ep_3550->max_host_qng = adv_dvc_varp->max_host_qng; |
| 11420 | ep_3550->max_dvc_qng = adv_dvc_varp->max_dvc_qng; |
| 11421 | ep_3550->termination = adv_dvc_varp->cfg->termination; |
| 11422 | ep_3550->disc_enable = adv_dvc_varp->cfg->disc_enable; |
| 11423 | ep_3550->bios_ctrl = adv_dvc_varp->bios_ctrl; |
| 11424 | ep_3550->wdtr_able = adv_dvc_varp->wdtr_able; |
| 11425 | ep_3550->sdtr_able = adv_dvc_varp->sdtr_able; |
| 11426 | ep_3550->ultra_able = adv_dvc_varp->ultra_able; |
| 11427 | ep_3550->tagqng_able = adv_dvc_varp->tagqng_able; |
| 11428 | ep_3550->start_motor = adv_dvc_varp->start_motor; |
| 11429 | ep_3550->scsi_reset_delay = |
| 11430 | adv_dvc_varp->scsi_reset_wait; |
| 11431 | ep_3550->serial_number_word1 = |
| 11432 | adv_dvc_varp->cfg->serial1; |
| 11433 | ep_3550->serial_number_word2 = |
| 11434 | adv_dvc_varp->cfg->serial2; |
| 11435 | ep_3550->serial_number_word3 = |
| 11436 | adv_dvc_varp->cfg->serial3; |
| 11437 | } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) { |
| 11438 | ep_38C0800 = &boardp->eep_config.adv_38C0800_eep; |
| 11439 | |
| 11440 | ep_38C0800->adapter_scsi_id = |
| 11441 | adv_dvc_varp->chip_scsi_id; |
| 11442 | ep_38C0800->max_host_qng = adv_dvc_varp->max_host_qng; |
| 11443 | ep_38C0800->max_dvc_qng = adv_dvc_varp->max_dvc_qng; |
| 11444 | ep_38C0800->termination_lvd = |
| 11445 | adv_dvc_varp->cfg->termination; |
| 11446 | ep_38C0800->disc_enable = |
| 11447 | adv_dvc_varp->cfg->disc_enable; |
| 11448 | ep_38C0800->bios_ctrl = adv_dvc_varp->bios_ctrl; |
| 11449 | ep_38C0800->wdtr_able = adv_dvc_varp->wdtr_able; |
| 11450 | ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able; |
| 11451 | ep_38C0800->sdtr_speed1 = adv_dvc_varp->sdtr_speed1; |
| 11452 | ep_38C0800->sdtr_speed2 = adv_dvc_varp->sdtr_speed2; |
| 11453 | ep_38C0800->sdtr_speed3 = adv_dvc_varp->sdtr_speed3; |
| 11454 | ep_38C0800->sdtr_speed4 = adv_dvc_varp->sdtr_speed4; |
| 11455 | ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able; |
| 11456 | ep_38C0800->start_motor = adv_dvc_varp->start_motor; |
| 11457 | ep_38C0800->scsi_reset_delay = |
| 11458 | adv_dvc_varp->scsi_reset_wait; |
| 11459 | ep_38C0800->serial_number_word1 = |
| 11460 | adv_dvc_varp->cfg->serial1; |
| 11461 | ep_38C0800->serial_number_word2 = |
| 11462 | adv_dvc_varp->cfg->serial2; |
| 11463 | ep_38C0800->serial_number_word3 = |
| 11464 | adv_dvc_varp->cfg->serial3; |
| 11465 | } else { |
| 11466 | ep_38C1600 = &boardp->eep_config.adv_38C1600_eep; |
| 11467 | |
| 11468 | ep_38C1600->adapter_scsi_id = |
| 11469 | adv_dvc_varp->chip_scsi_id; |
| 11470 | ep_38C1600->max_host_qng = adv_dvc_varp->max_host_qng; |
| 11471 | ep_38C1600->max_dvc_qng = adv_dvc_varp->max_dvc_qng; |
| 11472 | ep_38C1600->termination_lvd = |
| 11473 | adv_dvc_varp->cfg->termination; |
| 11474 | ep_38C1600->disc_enable = |
| 11475 | adv_dvc_varp->cfg->disc_enable; |
| 11476 | ep_38C1600->bios_ctrl = adv_dvc_varp->bios_ctrl; |
| 11477 | ep_38C1600->wdtr_able = adv_dvc_varp->wdtr_able; |
| 11478 | ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able; |
| 11479 | ep_38C1600->sdtr_speed1 = adv_dvc_varp->sdtr_speed1; |
| 11480 | ep_38C1600->sdtr_speed2 = adv_dvc_varp->sdtr_speed2; |
| 11481 | ep_38C1600->sdtr_speed3 = adv_dvc_varp->sdtr_speed3; |
| 11482 | ep_38C1600->sdtr_speed4 = adv_dvc_varp->sdtr_speed4; |
| 11483 | ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able; |
| 11484 | ep_38C1600->start_motor = adv_dvc_varp->start_motor; |
| 11485 | ep_38C1600->scsi_reset_delay = |
| 11486 | adv_dvc_varp->scsi_reset_wait; |
| 11487 | ep_38C1600->serial_number_word1 = |
| 11488 | adv_dvc_varp->cfg->serial1; |
| 11489 | ep_38C1600->serial_number_word2 = |
| 11490 | adv_dvc_varp->cfg->serial2; |
| 11491 | ep_38C1600->serial_number_word3 = |
| 11492 | adv_dvc_varp->cfg->serial3; |
| 11493 | } |
| 11494 | |
| 11495 | /* |
| 11496 | * Set the adapter's target id bit in the 'init_tidmask' field. |
| 11497 | */ |
| 11498 | boardp->init_tidmask |= |
| 11499 | ADV_TID_TO_TIDMASK(adv_dvc_varp->chip_scsi_id); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11500 | } |
| 11501 | |
| 11502 | /* |
| 11503 | * Channels are numbered beginning with 0. For AdvanSys one host |
| 11504 | * structure supports one channel. Multi-channel boards have a |
| 11505 | * separate host structure for each channel. |
| 11506 | */ |
| 11507 | shost->max_channel = 0; |
| 11508 | if (ASC_NARROW_BOARD(boardp)) { |
| 11509 | shost->max_id = ASC_MAX_TID + 1; |
| 11510 | shost->max_lun = ASC_MAX_LUN + 1; |
Matthew Wilcox | f05ec59 | 2007-09-09 08:56:36 -0600 | [diff] [blame] | 11511 | shost->max_cmd_len = ASC_MAX_CDB_LEN; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11512 | |
| 11513 | shost->io_port = asc_dvc_varp->iop_base; |
| 11514 | boardp->asc_n_io_port = ASC_IOADR_GAP; |
| 11515 | shost->this_id = asc_dvc_varp->cfg->chip_scsi_id; |
| 11516 | |
| 11517 | /* Set maximum number of queues the adapter can handle. */ |
| 11518 | shost->can_queue = asc_dvc_varp->max_total_qng; |
| 11519 | } else { |
| 11520 | shost->max_id = ADV_MAX_TID + 1; |
| 11521 | shost->max_lun = ADV_MAX_LUN + 1; |
Matthew Wilcox | f05ec59 | 2007-09-09 08:56:36 -0600 | [diff] [blame] | 11522 | shost->max_cmd_len = ADV_MAX_CDB_LEN; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11523 | |
| 11524 | /* |
| 11525 | * Save the I/O Port address and length even though |
| 11526 | * I/O ports are not used to access Wide boards. |
| 11527 | * Instead the Wide boards are accessed with |
| 11528 | * PCI Memory Mapped I/O. |
| 11529 | */ |
| 11530 | shost->io_port = iop; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11531 | |
| 11532 | shost->this_id = adv_dvc_varp->chip_scsi_id; |
| 11533 | |
| 11534 | /* Set maximum number of queues the adapter can handle. */ |
| 11535 | shost->can_queue = adv_dvc_varp->max_host_qng; |
| 11536 | } |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 11537 | ret = scsi_init_shared_tag_map(shost, shost->can_queue); |
| 11538 | if (ret) { |
| 11539 | shost_printk(KERN_ERR, shost, "init tag map failed\n"); |
| 11540 | goto err_free_dma; |
| 11541 | } |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11542 | |
| 11543 | /* |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11544 | * Following v1.3.89, 'cmd_per_lun' is no longer needed |
| 11545 | * and should be set to zero. |
| 11546 | * |
| 11547 | * But because of a bug introduced in v1.3.89 if the driver is |
| 11548 | * compiled as a module and 'cmd_per_lun' is zero, the Mid-Level |
| 11549 | * SCSI function 'allocate_device' will panic. To allow the driver |
| 11550 | * to work as a module in these kernels set 'cmd_per_lun' to 1. |
| 11551 | * |
| 11552 | * Note: This is wrong. cmd_per_lun should be set to the depth |
| 11553 | * you want on untagged devices always. |
| 11554 | #ifdef MODULE |
| 11555 | */ |
| 11556 | shost->cmd_per_lun = 1; |
| 11557 | /* #else |
| 11558 | shost->cmd_per_lun = 0; |
| 11559 | #endif */ |
| 11560 | |
| 11561 | /* |
| 11562 | * Set the maximum number of scatter-gather elements the |
| 11563 | * adapter can handle. |
| 11564 | */ |
| 11565 | if (ASC_NARROW_BOARD(boardp)) { |
| 11566 | /* |
| 11567 | * Allow two commands with 'sg_tablesize' scatter-gather |
| 11568 | * elements to be executed simultaneously. This value is |
| 11569 | * the theoretical hardware limit. It may be decreased |
| 11570 | * below. |
| 11571 | */ |
| 11572 | shost->sg_tablesize = |
| 11573 | (((asc_dvc_varp->max_total_qng - 2) / 2) * |
| 11574 | ASC_SG_LIST_PER_Q) + 1; |
| 11575 | } else { |
| 11576 | shost->sg_tablesize = ADV_MAX_SG_LIST; |
| 11577 | } |
| 11578 | |
| 11579 | /* |
| 11580 | * The value of 'sg_tablesize' can not exceed the SCSI |
| 11581 | * mid-level driver definition of SG_ALL. SG_ALL also |
| 11582 | * must not be exceeded, because it is used to define the |
| 11583 | * size of the scatter-gather table in 'struct asc_sg_head'. |
| 11584 | */ |
| 11585 | if (shost->sg_tablesize > SG_ALL) { |
| 11586 | shost->sg_tablesize = SG_ALL; |
| 11587 | } |
| 11588 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11589 | ASC_DBG(1, "sg_tablesize: %d\n", shost->sg_tablesize); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11590 | |
| 11591 | /* BIOS start address. */ |
| 11592 | if (ASC_NARROW_BOARD(boardp)) { |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11593 | shost->base = AscGetChipBiosAddress(asc_dvc_varp->iop_base, |
| 11594 | asc_dvc_varp->bus_type); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11595 | } else { |
| 11596 | /* |
| 11597 | * Fill-in BIOS board variables. The Wide BIOS saves |
| 11598 | * information in LRAM that is used by the driver. |
| 11599 | */ |
| 11600 | AdvReadWordLram(adv_dvc_varp->iop_base, |
| 11601 | BIOS_SIGNATURE, boardp->bios_signature); |
| 11602 | AdvReadWordLram(adv_dvc_varp->iop_base, |
| 11603 | BIOS_VERSION, boardp->bios_version); |
| 11604 | AdvReadWordLram(adv_dvc_varp->iop_base, |
| 11605 | BIOS_CODESEG, boardp->bios_codeseg); |
| 11606 | AdvReadWordLram(adv_dvc_varp->iop_base, |
| 11607 | BIOS_CODELEN, boardp->bios_codelen); |
| 11608 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11609 | ASC_DBG(1, "bios_signature 0x%x, bios_version 0x%x\n", |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11610 | boardp->bios_signature, boardp->bios_version); |
| 11611 | |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11612 | ASC_DBG(1, "bios_codeseg 0x%x, bios_codelen 0x%x\n", |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11613 | boardp->bios_codeseg, boardp->bios_codelen); |
| 11614 | |
| 11615 | /* |
| 11616 | * If the BIOS saved a valid signature, then fill in |
| 11617 | * the BIOS code segment base address. |
| 11618 | */ |
| 11619 | if (boardp->bios_signature == 0x55AA) { |
| 11620 | /* |
| 11621 | * Convert x86 realmode code segment to a linear |
| 11622 | * address by shifting left 4. |
| 11623 | */ |
| 11624 | shost->base = ((ulong)boardp->bios_codeseg << 4); |
| 11625 | } else { |
| 11626 | shost->base = 0; |
| 11627 | } |
| 11628 | } |
| 11629 | |
| 11630 | /* |
| 11631 | * Register Board Resources - I/O Port, DMA, IRQ |
| 11632 | */ |
| 11633 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11634 | /* Register DMA Channel for Narrow boards. */ |
| 11635 | shost->dma_channel = NO_ISA_DMA; /* Default to no ISA DMA. */ |
| 11636 | #ifdef CONFIG_ISA |
| 11637 | if (ASC_NARROW_BOARD(boardp)) { |
| 11638 | /* Register DMA channel for ISA bus. */ |
| 11639 | if (asc_dvc_varp->bus_type & ASC_IS_ISA) { |
| 11640 | shost->dma_channel = asc_dvc_varp->cfg->isa_dma_channel; |
Matthew Wilcox | 01fbfe0 | 2007-09-09 08:56:40 -0600 | [diff] [blame] | 11641 | ret = request_dma(shost->dma_channel, DRV_NAME); |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11642 | if (ret) { |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11643 | shost_printk(KERN_ERR, shost, "request_dma() " |
| 11644 | "%d failed %d\n", |
| 11645 | shost->dma_channel, ret); |
Al Viro | b59fb6f | 2013-03-31 02:59:55 -0400 | [diff] [blame] | 11646 | goto err_unmap; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11647 | } |
| 11648 | AscEnableIsaDma(shost->dma_channel); |
| 11649 | } |
| 11650 | } |
| 11651 | #endif /* CONFIG_ISA */ |
| 11652 | |
| 11653 | /* Register IRQ Number. */ |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11654 | ASC_DBG(2, "request_irq(%d, %p)\n", boardp->irq, shost); |
Matthew Wilcox | 074c8fe | 2007-07-28 23:11:05 -0600 | [diff] [blame] | 11655 | |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11656 | ret = request_irq(boardp->irq, advansys_interrupt, share_irq, |
Matthew Wilcox | 01fbfe0 | 2007-09-09 08:56:40 -0600 | [diff] [blame] | 11657 | DRV_NAME, shost); |
Matthew Wilcox | 074c8fe | 2007-07-28 23:11:05 -0600 | [diff] [blame] | 11658 | |
| 11659 | if (ret) { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11660 | if (ret == -EBUSY) { |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11661 | shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x " |
| 11662 | "already in use\n", boardp->irq); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11663 | } else if (ret == -EINVAL) { |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11664 | shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x " |
| 11665 | "not valid\n", boardp->irq); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11666 | } else { |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11667 | shost_printk(KERN_ERR, shost, "request_irq(): IRQ 0x%x " |
| 11668 | "failed with %d\n", boardp->irq, ret); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11669 | } |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11670 | goto err_free_dma; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11671 | } |
| 11672 | |
| 11673 | /* |
| 11674 | * Initialize board RISC chip and enable interrupts. |
| 11675 | */ |
| 11676 | if (ASC_NARROW_BOARD(boardp)) { |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11677 | ASC_DBG(2, "AscInitAsc1000Driver()\n"); |
FUJITA Tomonori | 7d5d408 | 2008-02-08 09:50:08 +0900 | [diff] [blame] | 11678 | |
| 11679 | asc_dvc_varp->overrun_buf = kzalloc(ASC_OVERRUN_BSIZE, GFP_KERNEL); |
| 11680 | if (!asc_dvc_varp->overrun_buf) { |
| 11681 | ret = -ENOMEM; |
Herton Ronaldo Krzesinski | 9a908c1 | 2010-03-30 13:35:38 -0300 | [diff] [blame] | 11682 | goto err_free_irq; |
FUJITA Tomonori | 7d5d408 | 2008-02-08 09:50:08 +0900 | [diff] [blame] | 11683 | } |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11684 | warn_code = AscInitAsc1000Driver(asc_dvc_varp); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11685 | |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11686 | if (warn_code || asc_dvc_varp->err_code) { |
Matthew Wilcox | 9d0e96e | 2007-10-02 21:55:35 -0400 | [diff] [blame] | 11687 | shost_printk(KERN_ERR, shost, "error: init_state 0x%x, " |
| 11688 | "warn 0x%x, error 0x%x\n", |
| 11689 | asc_dvc_varp->init_state, warn_code, |
| 11690 | asc_dvc_varp->err_code); |
Herton Ronaldo Krzesinski | 9a908c1 | 2010-03-30 13:35:38 -0300 | [diff] [blame] | 11691 | if (!asc_dvc_varp->overrun_dma) { |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11692 | ret = -ENODEV; |
Herton Ronaldo Krzesinski | 9a908c1 | 2010-03-30 13:35:38 -0300 | [diff] [blame] | 11693 | goto err_free_mem; |
FUJITA Tomonori | 7d5d408 | 2008-02-08 09:50:08 +0900 | [diff] [blame] | 11694 | } |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11695 | } |
| 11696 | } else { |
Herton Ronaldo Krzesinski | 9a908c1 | 2010-03-30 13:35:38 -0300 | [diff] [blame] | 11697 | if (advansys_wide_init_chip(shost)) { |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11698 | ret = -ENODEV; |
Herton Ronaldo Krzesinski | 9a908c1 | 2010-03-30 13:35:38 -0300 | [diff] [blame] | 11699 | goto err_free_mem; |
| 11700 | } |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11701 | } |
| 11702 | |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11703 | ASC_DBG_PRT_SCSI_HOST(2, shost); |
| 11704 | |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11705 | ret = scsi_add_host(shost, boardp->dev); |
Matthew Wilcox | 8dfb537 | 2007-07-30 09:08:34 -0600 | [diff] [blame] | 11706 | if (ret) |
Herton Ronaldo Krzesinski | 9a908c1 | 2010-03-30 13:35:38 -0300 | [diff] [blame] | 11707 | goto err_free_mem; |
Matthew Wilcox | 8dfb537 | 2007-07-30 09:08:34 -0600 | [diff] [blame] | 11708 | |
| 11709 | scsi_scan_host(shost); |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11710 | return 0; |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11711 | |
Herton Ronaldo Krzesinski | 9a908c1 | 2010-03-30 13:35:38 -0300 | [diff] [blame] | 11712 | err_free_mem: |
| 11713 | if (ASC_NARROW_BOARD(boardp)) { |
| 11714 | if (asc_dvc_varp->overrun_dma) |
| 11715 | dma_unmap_single(boardp->dev, asc_dvc_varp->overrun_dma, |
| 11716 | ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE); |
| 11717 | kfree(asc_dvc_varp->overrun_buf); |
| 11718 | } else |
| 11719 | advansys_wide_free_mem(boardp); |
| 11720 | err_free_irq: |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11721 | free_irq(boardp->irq, shost); |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11722 | err_free_dma: |
Al Viro | 3003781 | 2008-11-22 17:34:54 +0000 | [diff] [blame] | 11723 | #ifdef CONFIG_ISA |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11724 | if (shost->dma_channel != NO_ISA_DMA) |
| 11725 | free_dma(shost->dma_channel); |
Al Viro | 3003781 | 2008-11-22 17:34:54 +0000 | [diff] [blame] | 11726 | #endif |
Matthew Wilcox | b2c16f5 | 2007-07-29 17:30:28 -0600 | [diff] [blame] | 11727 | err_unmap: |
| 11728 | if (boardp->ioremap_addr) |
| 11729 | iounmap(boardp->ioremap_addr); |
| 11730 | err_shost: |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11731 | return ret; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11732 | } |
| 11733 | |
| 11734 | /* |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11735 | * advansys_release() |
| 11736 | * |
| 11737 | * Release resources allocated for a single AdvanSys adapter. |
| 11738 | */ |
| 11739 | static int advansys_release(struct Scsi_Host *shost) |
| 11740 | { |
Matthew Wilcox | d10fb2c | 2007-10-02 21:55:41 -0400 | [diff] [blame] | 11741 | struct asc_board *board = shost_priv(shost); |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11742 | ASC_DBG(1, "begin\n"); |
Matthew Wilcox | 8dfb537 | 2007-07-30 09:08:34 -0600 | [diff] [blame] | 11743 | scsi_remove_host(shost); |
Matthew Wilcox | d10fb2c | 2007-10-02 21:55:41 -0400 | [diff] [blame] | 11744 | free_irq(board->irq, shost); |
Al Viro | 3003781 | 2008-11-22 17:34:54 +0000 | [diff] [blame] | 11745 | #ifdef CONFIG_ISA |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11746 | if (shost->dma_channel != NO_ISA_DMA) { |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11747 | ASC_DBG(1, "free_dma()\n"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11748 | free_dma(shost->dma_channel); |
| 11749 | } |
Al Viro | 3003781 | 2008-11-22 17:34:54 +0000 | [diff] [blame] | 11750 | #endif |
Matthew Wilcox | d10fb2c | 2007-10-02 21:55:41 -0400 | [diff] [blame] | 11751 | if (ASC_NARROW_BOARD(board)) { |
| 11752 | dma_unmap_single(board->dev, |
| 11753 | board->dvc_var.asc_dvc_var.overrun_dma, |
| 11754 | ASC_OVERRUN_BSIZE, DMA_FROM_DEVICE); |
FUJITA Tomonori | 7d5d408 | 2008-02-08 09:50:08 +0900 | [diff] [blame] | 11755 | kfree(board->dvc_var.asc_dvc_var.overrun_buf); |
Matthew Wilcox | d10fb2c | 2007-10-02 21:55:41 -0400 | [diff] [blame] | 11756 | } else { |
| 11757 | iounmap(board->ioremap_addr); |
| 11758 | advansys_wide_free_mem(board); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11759 | } |
Matthew Wilcox | 8dfb537 | 2007-07-30 09:08:34 -0600 | [diff] [blame] | 11760 | scsi_host_put(shost); |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11761 | ASC_DBG(1, "end\n"); |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 11762 | return 0; |
| 11763 | } |
| 11764 | |
Matthew Wilcox | 95c9f16 | 2007-09-09 08:56:39 -0600 | [diff] [blame] | 11765 | #define ASC_IOADR_TABLE_MAX_IX 11 |
| 11766 | |
Randy Dunlap | 747d016 | 2008-01-14 00:55:18 -0800 | [diff] [blame] | 11767 | static PortAddr _asc_def_iop_base[ASC_IOADR_TABLE_MAX_IX] = { |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11768 | 0x100, 0x0110, 0x120, 0x0130, 0x140, 0x0150, 0x0190, |
| 11769 | 0x0210, 0x0230, 0x0250, 0x0330 |
| 11770 | }; |
| 11771 | |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11772 | /* |
| 11773 | * The ISA IRQ number is found in bits 2 and 3 of the CfgLsw. It decodes as: |
| 11774 | * 00: 10 |
| 11775 | * 01: 11 |
| 11776 | * 10: 12 |
| 11777 | * 11: 15 |
| 11778 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11779 | static unsigned int advansys_isa_irq_no(PortAddr iop_base) |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11780 | { |
| 11781 | unsigned short cfg_lsw = AscGetChipCfgLsw(iop_base); |
| 11782 | unsigned int chip_irq = ((cfg_lsw >> 2) & 0x03) + 10; |
| 11783 | if (chip_irq == 13) |
| 11784 | chip_irq = 15; |
| 11785 | return chip_irq; |
| 11786 | } |
| 11787 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11788 | static int advansys_isa_probe(struct device *dev, unsigned int id) |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11789 | { |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11790 | int err = -ENODEV; |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11791 | PortAddr iop_base = _asc_def_iop_base[id]; |
| 11792 | struct Scsi_Host *shost; |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11793 | struct asc_board *board; |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11794 | |
Matthew Wilcox | 01fbfe0 | 2007-09-09 08:56:40 -0600 | [diff] [blame] | 11795 | if (!request_region(iop_base, ASC_IOADR_GAP, DRV_NAME)) { |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11796 | ASC_DBG(1, "I/O port 0x%x busy\n", iop_base); |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11797 | return -ENODEV; |
| 11798 | } |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11799 | ASC_DBG(1, "probing I/O port 0x%x\n", iop_base); |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11800 | if (!AscFindSignature(iop_base)) |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11801 | goto release_region; |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11802 | if (!(AscGetChipVersion(iop_base, ASC_IS_ISA) & ASC_CHIP_VER_ISA_BIT)) |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11803 | goto release_region; |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11804 | |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11805 | err = -ENOMEM; |
| 11806 | shost = scsi_host_alloc(&advansys_template, sizeof(*board)); |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11807 | if (!shost) |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11808 | goto release_region; |
| 11809 | |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 11810 | board = shost_priv(shost); |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11811 | board->irq = advansys_isa_irq_no(iop_base); |
| 11812 | board->dev = dev; |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 11813 | board->shost = shost; |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11814 | |
| 11815 | err = advansys_board_found(shost, iop_base, ASC_IS_ISA); |
| 11816 | if (err) |
| 11817 | goto free_host; |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11818 | |
| 11819 | dev_set_drvdata(dev, shost); |
| 11820 | return 0; |
| 11821 | |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11822 | free_host: |
| 11823 | scsi_host_put(shost); |
| 11824 | release_region: |
Matthew Wilcox | 71f3611 | 2007-07-30 08:04:53 -0600 | [diff] [blame] | 11825 | release_region(iop_base, ASC_IOADR_GAP); |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11826 | return err; |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11827 | } |
| 11828 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11829 | static int advansys_isa_remove(struct device *dev, unsigned int id) |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11830 | { |
Matthew Wilcox | 71f3611 | 2007-07-30 08:04:53 -0600 | [diff] [blame] | 11831 | int ioport = _asc_def_iop_base[id]; |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11832 | advansys_release(dev_get_drvdata(dev)); |
Matthew Wilcox | 71f3611 | 2007-07-30 08:04:53 -0600 | [diff] [blame] | 11833 | release_region(ioport, ASC_IOADR_GAP); |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11834 | return 0; |
| 11835 | } |
| 11836 | |
| 11837 | static struct isa_driver advansys_isa_driver = { |
| 11838 | .probe = advansys_isa_probe, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11839 | .remove = advansys_isa_remove, |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11840 | .driver = { |
| 11841 | .owner = THIS_MODULE, |
Matthew Wilcox | 01fbfe0 | 2007-09-09 08:56:40 -0600 | [diff] [blame] | 11842 | .name = DRV_NAME, |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11843 | }, |
| 11844 | }; |
| 11845 | |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11846 | /* |
| 11847 | * The VLB IRQ number is found in bits 2 to 4 of the CfgLsw. It decodes as: |
| 11848 | * 000: invalid |
| 11849 | * 001: 10 |
| 11850 | * 010: 11 |
| 11851 | * 011: 12 |
| 11852 | * 100: invalid |
| 11853 | * 101: 14 |
| 11854 | * 110: 15 |
| 11855 | * 111: invalid |
| 11856 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11857 | static unsigned int advansys_vlb_irq_no(PortAddr iop_base) |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11858 | { |
| 11859 | unsigned short cfg_lsw = AscGetChipCfgLsw(iop_base); |
| 11860 | unsigned int chip_irq = ((cfg_lsw >> 2) & 0x07) + 9; |
| 11861 | if ((chip_irq < 10) || (chip_irq == 13) || (chip_irq > 15)) |
| 11862 | return 0; |
| 11863 | return chip_irq; |
| 11864 | } |
| 11865 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11866 | static int advansys_vlb_probe(struct device *dev, unsigned int id) |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11867 | { |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11868 | int err = -ENODEV; |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11869 | PortAddr iop_base = _asc_def_iop_base[id]; |
| 11870 | struct Scsi_Host *shost; |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11871 | struct asc_board *board; |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11872 | |
Matthew Wilcox | 01fbfe0 | 2007-09-09 08:56:40 -0600 | [diff] [blame] | 11873 | if (!request_region(iop_base, ASC_IOADR_GAP, DRV_NAME)) { |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11874 | ASC_DBG(1, "I/O port 0x%x busy\n", iop_base); |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11875 | return -ENODEV; |
| 11876 | } |
Matthew Wilcox | b352f92 | 2007-10-02 21:55:33 -0400 | [diff] [blame] | 11877 | ASC_DBG(1, "probing I/O port 0x%x\n", iop_base); |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11878 | if (!AscFindSignature(iop_base)) |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11879 | goto release_region; |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11880 | /* |
| 11881 | * I don't think this condition can actually happen, but the old |
| 11882 | * driver did it, and the chances of finding a VLB setup in 2007 |
| 11883 | * to do testing with is slight to none. |
| 11884 | */ |
| 11885 | if (AscGetChipVersion(iop_base, ASC_IS_VL) > ASC_CHIP_MAX_VER_VL) |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11886 | goto release_region; |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11887 | |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11888 | err = -ENOMEM; |
| 11889 | shost = scsi_host_alloc(&advansys_template, sizeof(*board)); |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11890 | if (!shost) |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11891 | goto release_region; |
| 11892 | |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 11893 | board = shost_priv(shost); |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11894 | board->irq = advansys_vlb_irq_no(iop_base); |
| 11895 | board->dev = dev; |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 11896 | board->shost = shost; |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11897 | |
| 11898 | err = advansys_board_found(shost, iop_base, ASC_IS_VL); |
| 11899 | if (err) |
| 11900 | goto free_host; |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11901 | |
| 11902 | dev_set_drvdata(dev, shost); |
| 11903 | return 0; |
| 11904 | |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11905 | free_host: |
| 11906 | scsi_host_put(shost); |
| 11907 | release_region: |
Matthew Wilcox | 71f3611 | 2007-07-30 08:04:53 -0600 | [diff] [blame] | 11908 | release_region(iop_base, ASC_IOADR_GAP); |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11909 | return -ENODEV; |
| 11910 | } |
| 11911 | |
| 11912 | static struct isa_driver advansys_vlb_driver = { |
| 11913 | .probe = advansys_vlb_probe, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11914 | .remove = advansys_isa_remove, |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11915 | .driver = { |
| 11916 | .owner = THIS_MODULE, |
Matthew Wilcox | b8e5152b | 2007-09-09 08:56:26 -0600 | [diff] [blame] | 11917 | .name = "advansys_vlb", |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 11918 | }, |
| 11919 | }; |
| 11920 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11921 | static struct eisa_device_id advansys_eisa_table[] = { |
Matthew Wilcox | b09e05a | 2007-07-30 09:14:52 -0600 | [diff] [blame] | 11922 | { "ABP7401" }, |
| 11923 | { "ABP7501" }, |
| 11924 | { "" } |
| 11925 | }; |
| 11926 | |
| 11927 | MODULE_DEVICE_TABLE(eisa, advansys_eisa_table); |
| 11928 | |
| 11929 | /* |
| 11930 | * EISA is a little more tricky than PCI; each EISA device may have two |
| 11931 | * channels, and this driver is written to make each channel its own Scsi_Host |
| 11932 | */ |
| 11933 | struct eisa_scsi_data { |
| 11934 | struct Scsi_Host *host[2]; |
| 11935 | }; |
| 11936 | |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11937 | /* |
| 11938 | * The EISA IRQ number is found in bits 8 to 10 of the CfgLsw. It decodes as: |
| 11939 | * 000: 10 |
| 11940 | * 001: 11 |
| 11941 | * 010: 12 |
| 11942 | * 011: invalid |
| 11943 | * 100: 14 |
| 11944 | * 101: 15 |
| 11945 | * 110: invalid |
| 11946 | * 111: invalid |
| 11947 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11948 | static unsigned int advansys_eisa_irq_no(struct eisa_device *edev) |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11949 | { |
| 11950 | unsigned short cfg_lsw = inw(edev->base_addr + 0xc86); |
| 11951 | unsigned int chip_irq = ((cfg_lsw >> 8) & 0x07) + 10; |
| 11952 | if ((chip_irq == 13) || (chip_irq > 15)) |
| 11953 | return 0; |
| 11954 | return chip_irq; |
| 11955 | } |
| 11956 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11957 | static int advansys_eisa_probe(struct device *dev) |
Matthew Wilcox | b09e05a | 2007-07-30 09:14:52 -0600 | [diff] [blame] | 11958 | { |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11959 | int i, ioport, irq = 0; |
Matthew Wilcox | b09e05a | 2007-07-30 09:14:52 -0600 | [diff] [blame] | 11960 | int err; |
| 11961 | struct eisa_device *edev = to_eisa_device(dev); |
| 11962 | struct eisa_scsi_data *data; |
| 11963 | |
| 11964 | err = -ENOMEM; |
| 11965 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 11966 | if (!data) |
| 11967 | goto fail; |
| 11968 | ioport = edev->base_addr + 0xc30; |
| 11969 | |
| 11970 | err = -ENODEV; |
| 11971 | for (i = 0; i < 2; i++, ioport += 0x20) { |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11972 | struct asc_board *board; |
| 11973 | struct Scsi_Host *shost; |
Matthew Wilcox | 01fbfe0 | 2007-09-09 08:56:40 -0600 | [diff] [blame] | 11974 | if (!request_region(ioport, ASC_IOADR_GAP, DRV_NAME)) { |
Matthew Wilcox | 71f3611 | 2007-07-30 08:04:53 -0600 | [diff] [blame] | 11975 | printk(KERN_WARNING "Region %x-%x busy\n", ioport, |
| 11976 | ioport + ASC_IOADR_GAP - 1); |
Matthew Wilcox | b09e05a | 2007-07-30 09:14:52 -0600 | [diff] [blame] | 11977 | continue; |
Matthew Wilcox | 71f3611 | 2007-07-30 08:04:53 -0600 | [diff] [blame] | 11978 | } |
| 11979 | if (!AscFindSignature(ioport)) { |
| 11980 | release_region(ioport, ASC_IOADR_GAP); |
| 11981 | continue; |
| 11982 | } |
| 11983 | |
Matthew Wilcox | b09e05a | 2007-07-30 09:14:52 -0600 | [diff] [blame] | 11984 | /* |
| 11985 | * I don't know why we need to do this for EISA chips, but |
| 11986 | * not for any others. It looks to be equivalent to |
| 11987 | * AscGetChipCfgMsw, but I may have overlooked something, |
| 11988 | * so I'm not converting it until I get an EISA board to |
| 11989 | * test with. |
| 11990 | */ |
| 11991 | inw(ioport + 4); |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 11992 | |
| 11993 | if (!irq) |
| 11994 | irq = advansys_eisa_irq_no(edev); |
| 11995 | |
| 11996 | err = -ENOMEM; |
| 11997 | shost = scsi_host_alloc(&advansys_template, sizeof(*board)); |
| 11998 | if (!shost) |
| 11999 | goto release_region; |
| 12000 | |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 12001 | board = shost_priv(shost); |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 12002 | board->irq = irq; |
| 12003 | board->dev = dev; |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 12004 | board->shost = shost; |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 12005 | |
| 12006 | err = advansys_board_found(shost, ioport, ASC_IS_EISA); |
| 12007 | if (!err) { |
| 12008 | data->host[i] = shost; |
| 12009 | continue; |
Matthew Wilcox | 71f3611 | 2007-07-30 08:04:53 -0600 | [diff] [blame] | 12010 | } |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 12011 | |
| 12012 | scsi_host_put(shost); |
| 12013 | release_region: |
| 12014 | release_region(ioport, ASC_IOADR_GAP); |
| 12015 | break; |
Matthew Wilcox | b09e05a | 2007-07-30 09:14:52 -0600 | [diff] [blame] | 12016 | } |
| 12017 | |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 12018 | if (err) |
| 12019 | goto free_data; |
| 12020 | dev_set_drvdata(dev, data); |
| 12021 | return 0; |
Matthew Wilcox | b09e05a | 2007-07-30 09:14:52 -0600 | [diff] [blame] | 12022 | |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 12023 | free_data: |
| 12024 | kfree(data->host[0]); |
| 12025 | kfree(data->host[1]); |
| 12026 | kfree(data); |
Matthew Wilcox | b09e05a | 2007-07-30 09:14:52 -0600 | [diff] [blame] | 12027 | fail: |
| 12028 | return err; |
| 12029 | } |
| 12030 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12031 | static int advansys_eisa_remove(struct device *dev) |
Matthew Wilcox | b09e05a | 2007-07-30 09:14:52 -0600 | [diff] [blame] | 12032 | { |
| 12033 | int i; |
| 12034 | struct eisa_scsi_data *data = dev_get_drvdata(dev); |
| 12035 | |
| 12036 | for (i = 0; i < 2; i++) { |
Matthew Wilcox | 71f3611 | 2007-07-30 08:04:53 -0600 | [diff] [blame] | 12037 | int ioport; |
Matthew Wilcox | b09e05a | 2007-07-30 09:14:52 -0600 | [diff] [blame] | 12038 | struct Scsi_Host *shost = data->host[i]; |
| 12039 | if (!shost) |
| 12040 | continue; |
Matthew Wilcox | 71f3611 | 2007-07-30 08:04:53 -0600 | [diff] [blame] | 12041 | ioport = shost->io_port; |
Matthew Wilcox | b09e05a | 2007-07-30 09:14:52 -0600 | [diff] [blame] | 12042 | advansys_release(shost); |
Matthew Wilcox | 71f3611 | 2007-07-30 08:04:53 -0600 | [diff] [blame] | 12043 | release_region(ioport, ASC_IOADR_GAP); |
Matthew Wilcox | b09e05a | 2007-07-30 09:14:52 -0600 | [diff] [blame] | 12044 | } |
| 12045 | |
| 12046 | kfree(data); |
| 12047 | return 0; |
| 12048 | } |
| 12049 | |
| 12050 | static struct eisa_driver advansys_eisa_driver = { |
| 12051 | .id_table = advansys_eisa_table, |
| 12052 | .driver = { |
Matthew Wilcox | 01fbfe0 | 2007-09-09 08:56:40 -0600 | [diff] [blame] | 12053 | .name = DRV_NAME, |
Matthew Wilcox | b09e05a | 2007-07-30 09:14:52 -0600 | [diff] [blame] | 12054 | .probe = advansys_eisa_probe, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12055 | .remove = advansys_eisa_remove, |
Matthew Wilcox | b09e05a | 2007-07-30 09:14:52 -0600 | [diff] [blame] | 12056 | } |
| 12057 | }; |
| 12058 | |
Dave Jones | 2672ea8 | 2006-08-02 17:11:49 -0400 | [diff] [blame] | 12059 | /* PCI Devices supported by this driver */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12060 | static struct pci_device_id advansys_pci_tbl[] = { |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 12061 | {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_1200A, |
| 12062 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 12063 | {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940, |
| 12064 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 12065 | {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940U, |
| 12066 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 12067 | {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940UW, |
| 12068 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 12069 | {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C0800_REV1, |
| 12070 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 12071 | {PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C1600_REV1, |
| 12072 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 12073 | {} |
Dave Jones | 2672ea8 | 2006-08-02 17:11:49 -0400 | [diff] [blame] | 12074 | }; |
Matthew Wilcox | 27c868c | 2007-07-26 10:56:23 -0400 | [diff] [blame] | 12075 | |
Dave Jones | 2672ea8 | 2006-08-02 17:11:49 -0400 | [diff] [blame] | 12076 | MODULE_DEVICE_TABLE(pci, advansys_pci_tbl); |
Matthew Wilcox | 78e77d8 | 2007-07-29 21:46:15 -0600 | [diff] [blame] | 12077 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12078 | static void advansys_set_latency(struct pci_dev *pdev) |
Matthew Wilcox | 9649af3 | 2007-07-26 21:51:47 -0600 | [diff] [blame] | 12079 | { |
| 12080 | if ((pdev->device == PCI_DEVICE_ID_ASP_1200A) || |
| 12081 | (pdev->device == PCI_DEVICE_ID_ASP_ABP940)) { |
| 12082 | pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0); |
| 12083 | } else { |
| 12084 | u8 latency; |
| 12085 | pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency); |
| 12086 | if (latency < 0x20) |
| 12087 | pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x20); |
| 12088 | } |
| 12089 | } |
| 12090 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12091 | static int advansys_pci_probe(struct pci_dev *pdev, |
| 12092 | const struct pci_device_id *ent) |
Matthew Wilcox | 78e77d8 | 2007-07-29 21:46:15 -0600 | [diff] [blame] | 12093 | { |
| 12094 | int err, ioport; |
| 12095 | struct Scsi_Host *shost; |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 12096 | struct asc_board *board; |
Matthew Wilcox | 78e77d8 | 2007-07-29 21:46:15 -0600 | [diff] [blame] | 12097 | |
| 12098 | err = pci_enable_device(pdev); |
| 12099 | if (err) |
| 12100 | goto fail; |
Matthew Wilcox | 01fbfe0 | 2007-09-09 08:56:40 -0600 | [diff] [blame] | 12101 | err = pci_request_regions(pdev, DRV_NAME); |
Matthew Wilcox | 71f3611 | 2007-07-30 08:04:53 -0600 | [diff] [blame] | 12102 | if (err) |
| 12103 | goto disable_device; |
Matthew Wilcox | 9649af3 | 2007-07-26 21:51:47 -0600 | [diff] [blame] | 12104 | pci_set_master(pdev); |
| 12105 | advansys_set_latency(pdev); |
Matthew Wilcox | 78e77d8 | 2007-07-29 21:46:15 -0600 | [diff] [blame] | 12106 | |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 12107 | err = -ENODEV; |
Matthew Wilcox | 78e77d8 | 2007-07-29 21:46:15 -0600 | [diff] [blame] | 12108 | if (pci_resource_len(pdev, 0) == 0) |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 12109 | goto release_region; |
Matthew Wilcox | 78e77d8 | 2007-07-29 21:46:15 -0600 | [diff] [blame] | 12110 | |
| 12111 | ioport = pci_resource_start(pdev, 0); |
Matthew Wilcox | 78e77d8 | 2007-07-29 21:46:15 -0600 | [diff] [blame] | 12112 | |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 12113 | err = -ENOMEM; |
| 12114 | shost = scsi_host_alloc(&advansys_template, sizeof(*board)); |
Matthew Wilcox | 78e77d8 | 2007-07-29 21:46:15 -0600 | [diff] [blame] | 12115 | if (!shost) |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 12116 | goto release_region; |
| 12117 | |
Matthew Wilcox | d241149 | 2007-10-02 21:55:31 -0400 | [diff] [blame] | 12118 | board = shost_priv(shost); |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 12119 | board->irq = pdev->irq; |
| 12120 | board->dev = &pdev->dev; |
Hannes Reinecke | 9c17c62 | 2015-04-24 13:18:21 +0200 | [diff] [blame] | 12121 | board->shost = shost; |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 12122 | |
| 12123 | if (pdev->device == PCI_DEVICE_ID_ASP_ABP940UW || |
| 12124 | pdev->device == PCI_DEVICE_ID_38C0800_REV1 || |
| 12125 | pdev->device == PCI_DEVICE_ID_38C1600_REV1) { |
| 12126 | board->flags |= ASC_IS_WIDE_BOARD; |
| 12127 | } |
| 12128 | |
| 12129 | err = advansys_board_found(shost, ioport, ASC_IS_PCI); |
| 12130 | if (err) |
| 12131 | goto free_host; |
Matthew Wilcox | 78e77d8 | 2007-07-29 21:46:15 -0600 | [diff] [blame] | 12132 | |
| 12133 | pci_set_drvdata(pdev, shost); |
| 12134 | return 0; |
| 12135 | |
Matthew Wilcox | d361db4 | 2007-10-02 21:55:29 -0400 | [diff] [blame] | 12136 | free_host: |
| 12137 | scsi_host_put(shost); |
| 12138 | release_region: |
Matthew Wilcox | 71f3611 | 2007-07-30 08:04:53 -0600 | [diff] [blame] | 12139 | pci_release_regions(pdev); |
| 12140 | disable_device: |
Matthew Wilcox | 78e77d8 | 2007-07-29 21:46:15 -0600 | [diff] [blame] | 12141 | pci_disable_device(pdev); |
| 12142 | fail: |
| 12143 | return err; |
| 12144 | } |
| 12145 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12146 | static void advansys_pci_remove(struct pci_dev *pdev) |
Matthew Wilcox | 78e77d8 | 2007-07-29 21:46:15 -0600 | [diff] [blame] | 12147 | { |
| 12148 | advansys_release(pci_get_drvdata(pdev)); |
Matthew Wilcox | 71f3611 | 2007-07-30 08:04:53 -0600 | [diff] [blame] | 12149 | pci_release_regions(pdev); |
Matthew Wilcox | 78e77d8 | 2007-07-29 21:46:15 -0600 | [diff] [blame] | 12150 | pci_disable_device(pdev); |
| 12151 | } |
| 12152 | |
| 12153 | static struct pci_driver advansys_pci_driver = { |
Matthew Wilcox | 01fbfe0 | 2007-09-09 08:56:40 -0600 | [diff] [blame] | 12154 | .name = DRV_NAME, |
Matthew Wilcox | 78e77d8 | 2007-07-29 21:46:15 -0600 | [diff] [blame] | 12155 | .id_table = advansys_pci_tbl, |
| 12156 | .probe = advansys_pci_probe, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12157 | .remove = advansys_pci_remove, |
Matthew Wilcox | 78e77d8 | 2007-07-29 21:46:15 -0600 | [diff] [blame] | 12158 | }; |
Matthew Wilcox | 8c6af9e | 2007-07-26 11:03:19 -0400 | [diff] [blame] | 12159 | |
Matthew Wilcox | 8dfb537 | 2007-07-30 09:08:34 -0600 | [diff] [blame] | 12160 | static int __init advansys_init(void) |
| 12161 | { |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 12162 | int error; |
| 12163 | |
| 12164 | error = isa_register_driver(&advansys_isa_driver, |
| 12165 | ASC_IOADR_TABLE_MAX_IX); |
| 12166 | if (error) |
| 12167 | goto fail; |
| 12168 | |
| 12169 | error = isa_register_driver(&advansys_vlb_driver, |
| 12170 | ASC_IOADR_TABLE_MAX_IX); |
| 12171 | if (error) |
| 12172 | goto unregister_isa; |
Matthew Wilcox | b09e05a | 2007-07-30 09:14:52 -0600 | [diff] [blame] | 12173 | |
| 12174 | error = eisa_driver_register(&advansys_eisa_driver); |
Matthew Wilcox | 78e77d8 | 2007-07-29 21:46:15 -0600 | [diff] [blame] | 12175 | if (error) |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 12176 | goto unregister_vlb; |
Matthew Wilcox | 8dfb537 | 2007-07-30 09:08:34 -0600 | [diff] [blame] | 12177 | |
Matthew Wilcox | b09e05a | 2007-07-30 09:14:52 -0600 | [diff] [blame] | 12178 | error = pci_register_driver(&advansys_pci_driver); |
| 12179 | if (error) |
| 12180 | goto unregister_eisa; |
| 12181 | |
Matthew Wilcox | 8dfb537 | 2007-07-30 09:08:34 -0600 | [diff] [blame] | 12182 | return 0; |
Matthew Wilcox | 78e77d8 | 2007-07-29 21:46:15 -0600 | [diff] [blame] | 12183 | |
Matthew Wilcox | b09e05a | 2007-07-30 09:14:52 -0600 | [diff] [blame] | 12184 | unregister_eisa: |
| 12185 | eisa_driver_unregister(&advansys_eisa_driver); |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 12186 | unregister_vlb: |
| 12187 | isa_unregister_driver(&advansys_vlb_driver); |
| 12188 | unregister_isa: |
| 12189 | isa_unregister_driver(&advansys_isa_driver); |
Matthew Wilcox | 78e77d8 | 2007-07-29 21:46:15 -0600 | [diff] [blame] | 12190 | fail: |
Matthew Wilcox | 78e77d8 | 2007-07-29 21:46:15 -0600 | [diff] [blame] | 12191 | return error; |
Matthew Wilcox | 8dfb537 | 2007-07-30 09:08:34 -0600 | [diff] [blame] | 12192 | } |
| 12193 | |
| 12194 | static void __exit advansys_exit(void) |
| 12195 | { |
Matthew Wilcox | 78e77d8 | 2007-07-29 21:46:15 -0600 | [diff] [blame] | 12196 | pci_unregister_driver(&advansys_pci_driver); |
Matthew Wilcox | b09e05a | 2007-07-30 09:14:52 -0600 | [diff] [blame] | 12197 | eisa_driver_unregister(&advansys_eisa_driver); |
Matthew Wilcox | c304ec9 | 2007-07-30 09:18:45 -0600 | [diff] [blame] | 12198 | isa_unregister_driver(&advansys_vlb_driver); |
| 12199 | isa_unregister_driver(&advansys_isa_driver); |
Matthew Wilcox | 8dfb537 | 2007-07-30 09:08:34 -0600 | [diff] [blame] | 12200 | } |
| 12201 | |
| 12202 | module_init(advansys_init); |
| 12203 | module_exit(advansys_exit); |
| 12204 | |
Matthew Wilcox | 8c6af9e | 2007-07-26 11:03:19 -0400 | [diff] [blame] | 12205 | MODULE_LICENSE("GPL"); |
Jaswinder Singh Rajput | 989bb5f | 2009-04-02 11:28:06 +0530 | [diff] [blame] | 12206 | MODULE_FIRMWARE("advansys/mcode.bin"); |
| 12207 | MODULE_FIRMWARE("advansys/3550.bin"); |
| 12208 | MODULE_FIRMWARE("advansys/38C0800.bin"); |
| 12209 | MODULE_FIRMWARE("advansys/38C1600.bin"); |