Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1 | /* |
| 2 | * SuperTrak EX Series Storage Controller driver for Linux |
| 3 | * |
Charles | 1ec364e | 2016-02-22 20:02:02 +0800 | [diff] [blame] | 4 | * Copyright (C) 2005-2015 Promise Technology Inc. |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * Written By: |
| 12 | * Ed Lin <promise_linux@promise.com> |
| 13 | * |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 21 | #include <linux/time.h> |
| 22 | #include <linux/pci.h> |
| 23 | #include <linux/blkdev.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/types.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/spinlock.h> |
Tina Ruchandani | 0da3968 | 2015-10-30 01:30:40 -0700 | [diff] [blame] | 28 | #include <linux/ktime.h> |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 29 | #include <asm/io.h> |
| 30 | #include <asm/irq.h> |
| 31 | #include <asm/byteorder.h> |
| 32 | #include <scsi/scsi.h> |
| 33 | #include <scsi/scsi_device.h> |
| 34 | #include <scsi/scsi_cmnd.h> |
| 35 | #include <scsi/scsi_host.h> |
Ed Lin | cf35588 | 2006-09-01 14:31:51 +0800 | [diff] [blame] | 36 | #include <scsi/scsi_tcq.h> |
Ed Lin | c25da0a | 2007-05-09 20:50:42 -0800 | [diff] [blame] | 37 | #include <scsi/scsi_dbg.h> |
FUJITA Tomonori | 11002fb | 2008-03-25 09:26:52 +0900 | [diff] [blame] | 38 | #include <scsi/scsi_eh.h> |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 39 | |
| 40 | #define DRV_NAME "stex" |
Charles | 1ec364e | 2016-02-22 20:02:02 +0800 | [diff] [blame] | 41 | #define ST_DRIVER_VERSION "5.00.0000.01" |
| 42 | #define ST_VER_MAJOR 5 |
| 43 | #define ST_VER_MINOR 00 |
| 44 | #define ST_OEM 0000 |
| 45 | #define ST_BUILD_VER 01 |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 46 | |
| 47 | enum { |
| 48 | /* MU register offset */ |
| 49 | IMR0 = 0x10, /* MU_INBOUND_MESSAGE_REG0 */ |
| 50 | IMR1 = 0x14, /* MU_INBOUND_MESSAGE_REG1 */ |
| 51 | OMR0 = 0x18, /* MU_OUTBOUND_MESSAGE_REG0 */ |
| 52 | OMR1 = 0x1c, /* MU_OUTBOUND_MESSAGE_REG1 */ |
| 53 | IDBL = 0x20, /* MU_INBOUND_DOORBELL */ |
| 54 | IIS = 0x24, /* MU_INBOUND_INTERRUPT_STATUS */ |
| 55 | IIM = 0x28, /* MU_INBOUND_INTERRUPT_MASK */ |
| 56 | ODBL = 0x2c, /* MU_OUTBOUND_DOORBELL */ |
| 57 | OIS = 0x30, /* MU_OUTBOUND_INTERRUPT_STATUS */ |
| 58 | OIM = 0x3c, /* MU_OUTBOUND_INTERRUPT_MASK */ |
| 59 | |
Ed Lin | 69cb487 | 2009-08-18 12:15:14 -0700 | [diff] [blame] | 60 | YIOA_STATUS = 0x00, |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 61 | YH2I_INT = 0x20, |
| 62 | YINT_EN = 0x34, |
| 63 | YI2H_INT = 0x9c, |
| 64 | YI2H_INT_C = 0xa0, |
| 65 | YH2I_REQ = 0xc0, |
| 66 | YH2I_REQ_HI = 0xc4, |
| 67 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 68 | /* MU register value */ |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 69 | MU_INBOUND_DOORBELL_HANDSHAKE = (1 << 0), |
| 70 | MU_INBOUND_DOORBELL_REQHEADCHANGED = (1 << 1), |
| 71 | MU_INBOUND_DOORBELL_STATUSTAILCHANGED = (1 << 2), |
| 72 | MU_INBOUND_DOORBELL_HMUSTOPPED = (1 << 3), |
| 73 | MU_INBOUND_DOORBELL_RESET = (1 << 4), |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 74 | |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 75 | MU_OUTBOUND_DOORBELL_HANDSHAKE = (1 << 0), |
| 76 | MU_OUTBOUND_DOORBELL_REQUESTTAILCHANGED = (1 << 1), |
| 77 | MU_OUTBOUND_DOORBELL_STATUSHEADCHANGED = (1 << 2), |
| 78 | MU_OUTBOUND_DOORBELL_BUSCHANGE = (1 << 3), |
| 79 | MU_OUTBOUND_DOORBELL_HASEVENT = (1 << 4), |
| 80 | MU_OUTBOUND_DOORBELL_REQUEST_RESET = (1 << 27), |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 81 | |
| 82 | /* MU status code */ |
| 83 | MU_STATE_STARTING = 1, |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 84 | MU_STATE_STARTED = 2, |
| 85 | MU_STATE_RESETTING = 3, |
| 86 | MU_STATE_FAILED = 4, |
Charles | 45b42ad | 2016-02-22 20:04:25 +0800 | [diff] [blame^] | 87 | MU_STATE_STOP = 5, |
| 88 | MU_STATE_NOCONNECT = 6, |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 89 | |
Ed Lin | 76fbf96 | 2006-12-04 17:49:42 -0800 | [diff] [blame] | 90 | MU_MAX_DELAY = 120, |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 91 | MU_HANDSHAKE_SIGNATURE = 0x55aaaa55, |
Ed Lin | 529e7a6 | 2006-12-04 17:49:34 -0800 | [diff] [blame] | 92 | MU_HANDSHAKE_SIGNATURE_HALF = 0x5a5a0000, |
Ed Lin | 76fbf96 | 2006-12-04 17:49:42 -0800 | [diff] [blame] | 93 | MU_HARD_RESET_WAIT = 30000, |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 94 | HMU_PARTNER_TYPE = 2, |
| 95 | |
| 96 | /* firmware returned values */ |
| 97 | SRB_STATUS_SUCCESS = 0x01, |
| 98 | SRB_STATUS_ERROR = 0x04, |
| 99 | SRB_STATUS_BUSY = 0x05, |
| 100 | SRB_STATUS_INVALID_REQUEST = 0x06, |
| 101 | SRB_STATUS_SELECTION_TIMEOUT = 0x0A, |
| 102 | SRB_SEE_SENSE = 0x80, |
| 103 | |
| 104 | /* task attribute */ |
| 105 | TASK_ATTRIBUTE_SIMPLE = 0x0, |
| 106 | TASK_ATTRIBUTE_HEADOFQUEUE = 0x1, |
| 107 | TASK_ATTRIBUTE_ORDERED = 0x2, |
| 108 | TASK_ATTRIBUTE_ACA = 0x4, |
| 109 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 110 | SS_STS_NORMAL = 0x80000000, |
| 111 | SS_STS_DONE = 0x40000000, |
| 112 | SS_STS_HANDSHAKE = 0x20000000, |
| 113 | |
| 114 | SS_HEAD_HANDSHAKE = 0x80, |
| 115 | |
Ed Lin | 69cb487 | 2009-08-18 12:15:14 -0700 | [diff] [blame] | 116 | SS_H2I_INT_RESET = 0x100, |
| 117 | |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 118 | SS_I2H_REQUEST_RESET = 0x2000, |
| 119 | |
Ed Lin | 69cb487 | 2009-08-18 12:15:14 -0700 | [diff] [blame] | 120 | SS_MU_OPERATIONAL = 0x80000000, |
| 121 | |
Ed Lin - PTU | 7cfe99a | 2009-01-26 02:41:53 -0800 | [diff] [blame] | 122 | STEX_CDB_LENGTH = 16, |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 123 | STATUS_VAR_LEN = 128, |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 124 | |
| 125 | /* sg flags */ |
| 126 | SG_CF_EOT = 0x80, /* end of table */ |
| 127 | SG_CF_64B = 0x40, /* 64 bit item */ |
| 128 | SG_CF_HOST = 0x20, /* sg in host memory */ |
Ed Lin - PTU | 7cfe99a | 2009-01-26 02:41:53 -0800 | [diff] [blame] | 129 | MSG_DATA_DIR_ND = 0, |
| 130 | MSG_DATA_DIR_IN = 1, |
| 131 | MSG_DATA_DIR_OUT = 2, |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 132 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 133 | st_shasta = 0, |
| 134 | st_vsc = 1, |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 135 | st_yosemite = 2, |
| 136 | st_seq = 3, |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 137 | st_yel = 4, |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 138 | |
| 139 | PASSTHRU_REQ_TYPE = 0x00000001, |
| 140 | PASSTHRU_REQ_NO_WAKEUP = 0x00000100, |
Ed Lin - PTU | 7cfe99a | 2009-01-26 02:41:53 -0800 | [diff] [blame] | 141 | ST_INTERNAL_TIMEOUT = 180, |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 142 | |
Ed Lin | fb4f66b | 2006-09-27 19:23:41 +0800 | [diff] [blame] | 143 | ST_TO_CMD = 0, |
| 144 | ST_FROM_CMD = 1, |
| 145 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 146 | /* vendor specific commands of Promise */ |
Ed Lin | fb4f66b | 2006-09-27 19:23:41 +0800 | [diff] [blame] | 147 | MGT_CMD = 0xd8, |
| 148 | SINBAND_MGT_CMD = 0xd9, |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 149 | ARRAY_CMD = 0xe0, |
| 150 | CONTROLLER_CMD = 0xe1, |
| 151 | DEBUGGING_CMD = 0xe2, |
| 152 | PASSTHRU_CMD = 0xe3, |
| 153 | |
| 154 | PASSTHRU_GET_ADAPTER = 0x05, |
| 155 | PASSTHRU_GET_DRVVER = 0x10, |
Ed Lin | fb4f66b | 2006-09-27 19:23:41 +0800 | [diff] [blame] | 156 | |
| 157 | CTLR_CONFIG_CMD = 0x03, |
| 158 | CTLR_SHUTDOWN = 0x0d, |
| 159 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 160 | CTLR_POWER_STATE_CHANGE = 0x0e, |
| 161 | CTLR_POWER_SAVING = 0x01, |
| 162 | |
| 163 | PASSTHRU_SIGNATURE = 0x4e415041, |
Ed Lin | fb4f66b | 2006-09-27 19:23:41 +0800 | [diff] [blame] | 164 | MGT_CMD_SIGNATURE = 0xba, |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 165 | |
| 166 | INQUIRY_EVPD = 0x01, |
Ed Lin | 94e9108 | 2006-12-04 17:49:39 -0800 | [diff] [blame] | 167 | |
| 168 | ST_ADDITIONAL_MEM = 0x200000, |
Ed Lin | cbacfb5 | 2009-09-28 22:58:17 -0800 | [diff] [blame] | 169 | ST_ADDITIONAL_MEM_MIN = 0x80000, |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | struct st_sgitem { |
| 173 | u8 ctrl; /* SG_CF_xxx */ |
| 174 | u8 reserved[3]; |
| 175 | __le32 count; |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 176 | __le64 addr; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 177 | }; |
| 178 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 179 | struct st_ss_sgitem { |
| 180 | __le32 addr; |
| 181 | __le32 addr_hi; |
| 182 | __le32 count; |
| 183 | }; |
| 184 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 185 | struct st_sgtable { |
| 186 | __le16 sg_count; |
| 187 | __le16 max_sg_count; |
| 188 | __le32 sz_in_byte; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 189 | }; |
| 190 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 191 | struct st_msg_header { |
| 192 | __le64 handle; |
| 193 | u8 flag; |
| 194 | u8 channel; |
| 195 | __le16 timeout; |
| 196 | u32 reserved; |
| 197 | }; |
| 198 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 199 | struct handshake_frame { |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 200 | __le64 rb_phy; /* request payload queue physical address */ |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 201 | __le16 req_sz; /* size of each request payload */ |
| 202 | __le16 req_cnt; /* count of reqs the buffer can hold */ |
| 203 | __le16 status_sz; /* size of each status payload */ |
| 204 | __le16 status_cnt; /* count of status the buffer can hold */ |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 205 | __le64 hosttime; /* seconds from Jan 1, 1970 (GMT) */ |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 206 | u8 partner_type; /* who sends this frame */ |
| 207 | u8 reserved0[7]; |
| 208 | __le32 partner_ver_major; |
| 209 | __le32 partner_ver_minor; |
| 210 | __le32 partner_ver_oem; |
| 211 | __le32 partner_ver_build; |
Ed Lin | 94e9108 | 2006-12-04 17:49:39 -0800 | [diff] [blame] | 212 | __le32 extra_offset; /* NEW */ |
| 213 | __le32 extra_size; /* NEW */ |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 214 | __le32 scratch_size; |
| 215 | u32 reserved1; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 216 | }; |
| 217 | |
| 218 | struct req_msg { |
| 219 | __le16 tag; |
| 220 | u8 lun; |
| 221 | u8 target; |
| 222 | u8 task_attr; |
| 223 | u8 task_manage; |
Ed Lin - PTU | 7cfe99a | 2009-01-26 02:41:53 -0800 | [diff] [blame] | 224 | u8 data_dir; |
Ed Lin | f903d7b7 | 2006-09-27 19:23:33 +0800 | [diff] [blame] | 225 | u8 payload_sz; /* payload size in 4-byte, not used */ |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 226 | u8 cdb[STEX_CDB_LENGTH]; |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 227 | u32 variable[0]; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 228 | }; |
| 229 | |
| 230 | struct status_msg { |
| 231 | __le16 tag; |
| 232 | u8 lun; |
| 233 | u8 target; |
| 234 | u8 srb_status; |
| 235 | u8 scsi_status; |
| 236 | u8 reserved; |
| 237 | u8 payload_sz; /* payload size in 4-byte */ |
| 238 | u8 variable[STATUS_VAR_LEN]; |
| 239 | }; |
| 240 | |
| 241 | struct ver_info { |
| 242 | u32 major; |
| 243 | u32 minor; |
| 244 | u32 oem; |
| 245 | u32 build; |
| 246 | u32 reserved[2]; |
| 247 | }; |
| 248 | |
| 249 | struct st_frame { |
| 250 | u32 base[6]; |
| 251 | u32 rom_addr; |
| 252 | |
| 253 | struct ver_info drv_ver; |
| 254 | struct ver_info bios_ver; |
| 255 | |
| 256 | u32 bus; |
| 257 | u32 slot; |
| 258 | u32 irq_level; |
| 259 | u32 irq_vec; |
| 260 | u32 id; |
| 261 | u32 subid; |
| 262 | |
| 263 | u32 dimm_size; |
| 264 | u8 dimm_type; |
| 265 | u8 reserved[3]; |
| 266 | |
| 267 | u32 channel; |
| 268 | u32 reserved1; |
| 269 | }; |
| 270 | |
| 271 | struct st_drvver { |
| 272 | u32 major; |
| 273 | u32 minor; |
| 274 | u32 oem; |
| 275 | u32 build; |
| 276 | u32 signature[2]; |
| 277 | u8 console_id; |
| 278 | u8 host_no; |
| 279 | u8 reserved0[2]; |
| 280 | u32 reserved[3]; |
| 281 | }; |
| 282 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 283 | struct st_ccb { |
| 284 | struct req_msg *req; |
| 285 | struct scsi_cmnd *cmd; |
| 286 | |
| 287 | void *sense_buffer; |
| 288 | unsigned int sense_bufflen; |
| 289 | int sg_count; |
| 290 | |
| 291 | u32 req_type; |
| 292 | u8 srb_status; |
| 293 | u8 scsi_status; |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 294 | u8 reserved[2]; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 295 | }; |
| 296 | |
| 297 | struct st_hba { |
| 298 | void __iomem *mmio_base; /* iomapped PCI memory space */ |
| 299 | void *dma_mem; |
| 300 | dma_addr_t dma_handle; |
Ed Lin | 94e9108 | 2006-12-04 17:49:39 -0800 | [diff] [blame] | 301 | size_t dma_size; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 302 | |
| 303 | struct Scsi_Host *host; |
| 304 | struct pci_dev *pdev; |
| 305 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 306 | struct req_msg * (*alloc_rq) (struct st_hba *); |
| 307 | int (*map_sg)(struct st_hba *, struct req_msg *, struct st_ccb *); |
| 308 | void (*send) (struct st_hba *, struct req_msg *, u16); |
| 309 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 310 | u32 req_head; |
| 311 | u32 req_tail; |
| 312 | u32 status_head; |
| 313 | u32 status_tail; |
| 314 | |
| 315 | struct status_msg *status_buffer; |
| 316 | void *copy_buffer; /* temp buffer for driver-handled commands */ |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 317 | struct st_ccb *ccb; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 318 | struct st_ccb *wait_ccb; |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 319 | __le32 *scratch; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 320 | |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 321 | char work_q_name[20]; |
| 322 | struct workqueue_struct *work_q; |
| 323 | struct work_struct reset_work; |
| 324 | wait_queue_head_t reset_waitq; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 325 | unsigned int mu_status; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 326 | unsigned int cardtype; |
Ed Lin | 99946f8 | 2009-03-31 17:30:25 -0800 | [diff] [blame] | 327 | int msi_enabled; |
| 328 | int out_req_cnt; |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 329 | u32 extra_offset; |
| 330 | u16 rq_count; |
| 331 | u16 rq_size; |
| 332 | u16 sts_count; |
Charles | 1ec364e | 2016-02-22 20:02:02 +0800 | [diff] [blame] | 333 | u8 supports_pm; |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 334 | }; |
| 335 | |
| 336 | struct st_card_info { |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 337 | struct req_msg * (*alloc_rq) (struct st_hba *); |
| 338 | int (*map_sg)(struct st_hba *, struct req_msg *, struct st_ccb *); |
| 339 | void (*send) (struct st_hba *, struct req_msg *, u16); |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 340 | unsigned int max_id; |
| 341 | unsigned int max_lun; |
| 342 | unsigned int max_channel; |
| 343 | u16 rq_count; |
| 344 | u16 rq_size; |
| 345 | u16 sts_count; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 346 | }; |
| 347 | |
Ed Lin | 99946f8 | 2009-03-31 17:30:25 -0800 | [diff] [blame] | 348 | static int msi; |
| 349 | module_param(msi, int, 0); |
| 350 | MODULE_PARM_DESC(msi, "Enable Message Signaled Interrupts(0=off, 1=on)"); |
| 351 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 352 | static const char console_inq_page[] = |
| 353 | { |
| 354 | 0x03,0x00,0x03,0x03,0xFA,0x00,0x00,0x30, |
| 355 | 0x50,0x72,0x6F,0x6D,0x69,0x73,0x65,0x20, /* "Promise " */ |
| 356 | 0x52,0x41,0x49,0x44,0x20,0x43,0x6F,0x6E, /* "RAID Con" */ |
| 357 | 0x73,0x6F,0x6C,0x65,0x20,0x20,0x20,0x20, /* "sole " */ |
| 358 | 0x31,0x2E,0x30,0x30,0x20,0x20,0x20,0x20, /* "1.00 " */ |
| 359 | 0x53,0x58,0x2F,0x52,0x53,0x41,0x46,0x2D, /* "SX/RSAF-" */ |
| 360 | 0x54,0x45,0x31,0x2E,0x30,0x30,0x20,0x20, /* "TE1.00 " */ |
| 361 | 0x0C,0x20,0x20,0x20,0x20,0x20,0x20,0x20 |
| 362 | }; |
| 363 | |
| 364 | MODULE_AUTHOR("Ed Lin"); |
| 365 | MODULE_DESCRIPTION("Promise Technology SuperTrak EX Controllers"); |
| 366 | MODULE_LICENSE("GPL"); |
| 367 | MODULE_VERSION(ST_DRIVER_VERSION); |
| 368 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 369 | static struct status_msg *stex_get_status(struct st_hba *hba) |
| 370 | { |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 371 | struct status_msg *status = hba->status_buffer + hba->status_tail; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 372 | |
| 373 | ++hba->status_tail; |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 374 | hba->status_tail %= hba->sts_count+1; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 375 | |
| 376 | return status; |
| 377 | } |
| 378 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 379 | static void stex_invalid_field(struct scsi_cmnd *cmd, |
| 380 | void (*done)(struct scsi_cmnd *)) |
| 381 | { |
FUJITA Tomonori | 11002fb | 2008-03-25 09:26:52 +0900 | [diff] [blame] | 382 | cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; |
| 383 | |
Ed Lin - PTU | 7cfe99a | 2009-01-26 02:41:53 -0800 | [diff] [blame] | 384 | /* "Invalid field in cdb" */ |
FUJITA Tomonori | 11002fb | 2008-03-25 09:26:52 +0900 | [diff] [blame] | 385 | scsi_build_sense_buffer(0, cmd->sense_buffer, ILLEGAL_REQUEST, 0x24, |
| 386 | 0x0); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 387 | done(cmd); |
| 388 | } |
| 389 | |
| 390 | static struct req_msg *stex_alloc_req(struct st_hba *hba) |
| 391 | { |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 392 | struct req_msg *req = hba->dma_mem + hba->req_head * hba->rq_size; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 393 | |
| 394 | ++hba->req_head; |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 395 | hba->req_head %= hba->rq_count+1; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 396 | |
| 397 | return req; |
| 398 | } |
| 399 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 400 | static struct req_msg *stex_ss_alloc_req(struct st_hba *hba) |
| 401 | { |
| 402 | return (struct req_msg *)(hba->dma_mem + |
| 403 | hba->req_head * hba->rq_size + sizeof(struct st_msg_header)); |
| 404 | } |
| 405 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 406 | static int stex_map_sg(struct st_hba *hba, |
| 407 | struct req_msg *req, struct st_ccb *ccb) |
| 408 | { |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 409 | struct scsi_cmnd *cmd; |
FUJITA Tomonori | d5587d5 | 2007-05-26 10:01:24 +0900 | [diff] [blame] | 410 | struct scatterlist *sg; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 411 | struct st_sgtable *dst; |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 412 | struct st_sgitem *table; |
FUJITA Tomonori | d5587d5 | 2007-05-26 10:01:24 +0900 | [diff] [blame] | 413 | int i, nseg; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 414 | |
| 415 | cmd = ccb->cmd; |
FUJITA Tomonori | d5587d5 | 2007-05-26 10:01:24 +0900 | [diff] [blame] | 416 | nseg = scsi_dma_map(cmd); |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 417 | BUG_ON(nseg < 0); |
FUJITA Tomonori | d5587d5 | 2007-05-26 10:01:24 +0900 | [diff] [blame] | 418 | if (nseg) { |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 419 | dst = (struct st_sgtable *)req->variable; |
| 420 | |
FUJITA Tomonori | d5587d5 | 2007-05-26 10:01:24 +0900 | [diff] [blame] | 421 | ccb->sg_count = nseg; |
| 422 | dst->sg_count = cpu_to_le16((u16)nseg); |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 423 | dst->max_sg_count = cpu_to_le16(hba->host->sg_tablesize); |
| 424 | dst->sz_in_byte = cpu_to_le32(scsi_bufflen(cmd)); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 425 | |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 426 | table = (struct st_sgitem *)(dst + 1); |
FUJITA Tomonori | d5587d5 | 2007-05-26 10:01:24 +0900 | [diff] [blame] | 427 | scsi_for_each_sg(cmd, sg, nseg, i) { |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 428 | table[i].count = cpu_to_le32((u32)sg_dma_len(sg)); |
| 429 | table[i].addr = cpu_to_le64(sg_dma_address(sg)); |
| 430 | table[i].ctrl = SG_CF_64B | SG_CF_HOST; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 431 | } |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 432 | table[--i].ctrl |= SG_CF_EOT; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 433 | } |
| 434 | |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 435 | return nseg; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 436 | } |
| 437 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 438 | static int stex_ss_map_sg(struct st_hba *hba, |
| 439 | struct req_msg *req, struct st_ccb *ccb) |
| 440 | { |
| 441 | struct scsi_cmnd *cmd; |
| 442 | struct scatterlist *sg; |
| 443 | struct st_sgtable *dst; |
| 444 | struct st_ss_sgitem *table; |
| 445 | int i, nseg; |
| 446 | |
| 447 | cmd = ccb->cmd; |
| 448 | nseg = scsi_dma_map(cmd); |
| 449 | BUG_ON(nseg < 0); |
| 450 | if (nseg) { |
| 451 | dst = (struct st_sgtable *)req->variable; |
| 452 | |
| 453 | ccb->sg_count = nseg; |
| 454 | dst->sg_count = cpu_to_le16((u16)nseg); |
| 455 | dst->max_sg_count = cpu_to_le16(hba->host->sg_tablesize); |
| 456 | dst->sz_in_byte = cpu_to_le32(scsi_bufflen(cmd)); |
| 457 | |
| 458 | table = (struct st_ss_sgitem *)(dst + 1); |
| 459 | scsi_for_each_sg(cmd, sg, nseg, i) { |
| 460 | table[i].count = cpu_to_le32((u32)sg_dma_len(sg)); |
| 461 | table[i].addr = |
| 462 | cpu_to_le32(sg_dma_address(sg) & 0xffffffff); |
| 463 | table[i].addr_hi = |
| 464 | cpu_to_le32((sg_dma_address(sg) >> 16) >> 16); |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | return nseg; |
| 469 | } |
| 470 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 471 | static void stex_controller_info(struct st_hba *hba, struct st_ccb *ccb) |
| 472 | { |
| 473 | struct st_frame *p; |
| 474 | size_t count = sizeof(struct st_frame); |
| 475 | |
| 476 | p = hba->copy_buffer; |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 477 | scsi_sg_copy_to_buffer(ccb->cmd, p, count); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 478 | memset(p->base, 0, sizeof(u32)*6); |
| 479 | *(unsigned long *)(p->base) = pci_resource_start(hba->pdev, 0); |
| 480 | p->rom_addr = 0; |
| 481 | |
| 482 | p->drv_ver.major = ST_VER_MAJOR; |
| 483 | p->drv_ver.minor = ST_VER_MINOR; |
| 484 | p->drv_ver.oem = ST_OEM; |
| 485 | p->drv_ver.build = ST_BUILD_VER; |
| 486 | |
| 487 | p->bus = hba->pdev->bus->number; |
| 488 | p->slot = hba->pdev->devfn; |
| 489 | p->irq_level = 0; |
| 490 | p->irq_vec = hba->pdev->irq; |
| 491 | p->id = hba->pdev->vendor << 16 | hba->pdev->device; |
| 492 | p->subid = |
| 493 | hba->pdev->subsystem_vendor << 16 | hba->pdev->subsystem_device; |
| 494 | |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 495 | scsi_sg_copy_from_buffer(ccb->cmd, p, count); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | static void |
| 499 | stex_send_cmd(struct st_hba *hba, struct req_msg *req, u16 tag) |
| 500 | { |
| 501 | req->tag = cpu_to_le16(tag); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 502 | |
| 503 | hba->ccb[tag].req = req; |
| 504 | hba->out_req_cnt++; |
| 505 | |
| 506 | writel(hba->req_head, hba->mmio_base + IMR0); |
| 507 | writel(MU_INBOUND_DOORBELL_REQHEADCHANGED, hba->mmio_base + IDBL); |
| 508 | readl(hba->mmio_base + IDBL); /* flush */ |
| 509 | } |
| 510 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 511 | static void |
| 512 | stex_ss_send_cmd(struct st_hba *hba, struct req_msg *req, u16 tag) |
| 513 | { |
| 514 | struct scsi_cmnd *cmd; |
| 515 | struct st_msg_header *msg_h; |
| 516 | dma_addr_t addr; |
| 517 | |
| 518 | req->tag = cpu_to_le16(tag); |
| 519 | |
| 520 | hba->ccb[tag].req = req; |
| 521 | hba->out_req_cnt++; |
| 522 | |
| 523 | cmd = hba->ccb[tag].cmd; |
| 524 | msg_h = (struct st_msg_header *)req - 1; |
| 525 | if (likely(cmd)) { |
| 526 | msg_h->channel = (u8)cmd->device->channel; |
| 527 | msg_h->timeout = cpu_to_le16(cmd->request->timeout/HZ); |
| 528 | } |
| 529 | addr = hba->dma_handle + hba->req_head * hba->rq_size; |
| 530 | addr += (hba->ccb[tag].sg_count+4)/11; |
| 531 | msg_h->handle = cpu_to_le64(addr); |
| 532 | |
| 533 | ++hba->req_head; |
| 534 | hba->req_head %= hba->rq_count+1; |
| 535 | |
| 536 | writel((addr >> 16) >> 16, hba->mmio_base + YH2I_REQ_HI); |
| 537 | readl(hba->mmio_base + YH2I_REQ_HI); /* flush */ |
| 538 | writel(addr, hba->mmio_base + YH2I_REQ); |
| 539 | readl(hba->mmio_base + YH2I_REQ); /* flush */ |
| 540 | } |
| 541 | |
Charles | 45b42ad | 2016-02-22 20:04:25 +0800 | [diff] [blame^] | 542 | static void return_abnormal_state(struct st_hba *hba, int status) |
| 543 | { |
| 544 | struct st_ccb *ccb; |
| 545 | unsigned long flags; |
| 546 | u16 tag; |
| 547 | |
| 548 | spin_lock_irqsave(hba->host->host_lock, flags); |
| 549 | for (tag = 0; tag < hba->host->can_queue; tag++) { |
| 550 | ccb = &hba->ccb[tag]; |
| 551 | if (ccb->req == NULL) |
| 552 | continue; |
| 553 | ccb->req = NULL; |
| 554 | if (ccb->cmd) { |
| 555 | scsi_dma_unmap(ccb->cmd); |
| 556 | ccb->cmd->result = status << 16; |
| 557 | ccb->cmd->scsi_done(ccb->cmd); |
| 558 | ccb->cmd = NULL; |
| 559 | } |
| 560 | } |
| 561 | spin_unlock_irqrestore(hba->host->host_lock, flags); |
| 562 | } |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 563 | static int |
| 564 | stex_slave_config(struct scsi_device *sdev) |
| 565 | { |
| 566 | sdev->use_10_for_rw = 1; |
| 567 | sdev->use_10_for_ms = 1; |
James Bottomley | dc5c49b | 2008-11-30 10:38:08 -0600 | [diff] [blame] | 568 | blk_queue_rq_timeout(sdev->request_queue, 60 * HZ); |
Ed Lin | cf35588 | 2006-09-01 14:31:51 +0800 | [diff] [blame] | 569 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 570 | return 0; |
| 571 | } |
| 572 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 573 | static int |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 574 | stex_queuecommand_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 575 | { |
| 576 | struct st_hba *hba; |
| 577 | struct Scsi_Host *host; |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 578 | unsigned int id, lun; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 579 | struct req_msg *req; |
| 580 | u16 tag; |
Ed Lin - PTU | 7cfe99a | 2009-01-26 02:41:53 -0800 | [diff] [blame] | 581 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 582 | host = cmd->device->host; |
| 583 | id = cmd->device->id; |
Ed Lin | e0b2e59 | 2007-05-09 20:50:33 -0800 | [diff] [blame] | 584 | lun = cmd->device->lun; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 585 | hba = (struct st_hba *) &host->hostdata[0]; |
Charles | 45b42ad | 2016-02-22 20:04:25 +0800 | [diff] [blame^] | 586 | if (hba->mu_status == MU_STATE_NOCONNECT) { |
| 587 | cmd->result = DID_NO_CONNECT; |
| 588 | done(cmd); |
| 589 | return 0; |
| 590 | } |
| 591 | if (unlikely(hba->mu_status != MU_STATE_STARTED)) |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 592 | return SCSI_MLQUEUE_HOST_BUSY; |
| 593 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 594 | switch (cmd->cmnd[0]) { |
| 595 | case MODE_SENSE_10: |
| 596 | { |
| 597 | static char ms10_caching_page[12] = |
| 598 | { 0, 0x12, 0, 0, 0, 0, 0, 0, 0x8, 0xa, 0x4, 0 }; |
| 599 | unsigned char page; |
Ed Lin - PTU | 7cfe99a | 2009-01-26 02:41:53 -0800 | [diff] [blame] | 600 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 601 | page = cmd->cmnd[2] & 0x3f; |
| 602 | if (page == 0x8 || page == 0x3f) { |
FUJITA Tomonori | 31fe47d | 2008-03-09 13:44:35 +0900 | [diff] [blame] | 603 | scsi_sg_copy_from_buffer(cmd, ms10_caching_page, |
| 604 | sizeof(ms10_caching_page)); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 605 | cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8; |
| 606 | done(cmd); |
| 607 | } else |
| 608 | stex_invalid_field(cmd, done); |
| 609 | return 0; |
| 610 | } |
Ed Lin | e0b2e59 | 2007-05-09 20:50:33 -0800 | [diff] [blame] | 611 | case REPORT_LUNS: |
| 612 | /* |
| 613 | * The shasta firmware does not report actual luns in the |
| 614 | * target, so fail the command to force sequential lun scan. |
| 615 | * Also, the console device does not support this command. |
| 616 | */ |
| 617 | if (hba->cardtype == st_shasta || id == host->max_id - 1) { |
| 618 | stex_invalid_field(cmd, done); |
| 619 | return 0; |
| 620 | } |
| 621 | break; |
Ed Lin | d116a7b | 2007-05-09 20:50:40 -0800 | [diff] [blame] | 622 | case TEST_UNIT_READY: |
| 623 | if (id == host->max_id - 1) { |
| 624 | cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8; |
| 625 | done(cmd); |
| 626 | return 0; |
| 627 | } |
| 628 | break; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 629 | case INQUIRY: |
Ed Lin | 91e6eca | 2009-12-18 17:34:51 -0800 | [diff] [blame] | 630 | if (lun >= host->max_lun) { |
| 631 | cmd->result = DID_NO_CONNECT << 16; |
| 632 | done(cmd); |
| 633 | return 0; |
| 634 | } |
Ed Lin | e0b2e59 | 2007-05-09 20:50:33 -0800 | [diff] [blame] | 635 | if (id != host->max_id - 1) |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 636 | break; |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 637 | if (!lun && !cmd->device->channel && |
| 638 | (cmd->cmnd[1] & INQUIRY_EVPD) == 0) { |
FUJITA Tomonori | 31fe47d | 2008-03-09 13:44:35 +0900 | [diff] [blame] | 639 | scsi_sg_copy_from_buffer(cmd, (void *)console_inq_page, |
| 640 | sizeof(console_inq_page)); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 641 | cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8; |
| 642 | done(cmd); |
| 643 | } else |
| 644 | stex_invalid_field(cmd, done); |
| 645 | return 0; |
| 646 | case PASSTHRU_CMD: |
| 647 | if (cmd->cmnd[1] == PASSTHRU_GET_DRVVER) { |
| 648 | struct st_drvver ver; |
FUJITA Tomonori | 26106e3 | 2008-02-22 23:11:03 +0900 | [diff] [blame] | 649 | size_t cp_len = sizeof(ver); |
Ed Lin - PTU | 7cfe99a | 2009-01-26 02:41:53 -0800 | [diff] [blame] | 650 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 651 | ver.major = ST_VER_MAJOR; |
| 652 | ver.minor = ST_VER_MINOR; |
| 653 | ver.oem = ST_OEM; |
| 654 | ver.build = ST_BUILD_VER; |
| 655 | ver.signature[0] = PASSTHRU_SIGNATURE; |
Ed Lin | e0b2e59 | 2007-05-09 20:50:33 -0800 | [diff] [blame] | 656 | ver.console_id = host->max_id - 1; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 657 | ver.host_no = hba->host->host_no; |
FUJITA Tomonori | 31fe47d | 2008-03-09 13:44:35 +0900 | [diff] [blame] | 658 | cp_len = scsi_sg_copy_from_buffer(cmd, &ver, cp_len); |
FUJITA Tomonori | 26106e3 | 2008-02-22 23:11:03 +0900 | [diff] [blame] | 659 | cmd->result = sizeof(ver) == cp_len ? |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 660 | DID_OK << 16 | COMMAND_COMPLETE << 8 : |
| 661 | DID_ERROR << 16 | COMMAND_COMPLETE << 8; |
| 662 | done(cmd); |
| 663 | return 0; |
| 664 | } |
| 665 | default: |
| 666 | break; |
| 667 | } |
| 668 | |
| 669 | cmd->scsi_done = done; |
| 670 | |
Ed Lin | cf35588 | 2006-09-01 14:31:51 +0800 | [diff] [blame] | 671 | tag = cmd->request->tag; |
| 672 | |
| 673 | if (unlikely(tag >= host->can_queue)) |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 674 | return SCSI_MLQUEUE_HOST_BUSY; |
| 675 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 676 | req = hba->alloc_rq(hba); |
Ed Lin | fb4f66b | 2006-09-27 19:23:41 +0800 | [diff] [blame] | 677 | |
Ed Lin | e0b2e59 | 2007-05-09 20:50:33 -0800 | [diff] [blame] | 678 | req->lun = lun; |
| 679 | req->target = id; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 680 | |
| 681 | /* cdb */ |
| 682 | memcpy(req->cdb, cmd->cmnd, STEX_CDB_LENGTH); |
| 683 | |
Ed Lin - PTU | 7cfe99a | 2009-01-26 02:41:53 -0800 | [diff] [blame] | 684 | if (cmd->sc_data_direction == DMA_FROM_DEVICE) |
| 685 | req->data_dir = MSG_DATA_DIR_IN; |
| 686 | else if (cmd->sc_data_direction == DMA_TO_DEVICE) |
| 687 | req->data_dir = MSG_DATA_DIR_OUT; |
| 688 | else |
| 689 | req->data_dir = MSG_DATA_DIR_ND; |
| 690 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 691 | hba->ccb[tag].cmd = cmd; |
| 692 | hba->ccb[tag].sense_bufflen = SCSI_SENSE_BUFFERSIZE; |
| 693 | hba->ccb[tag].sense_buffer = cmd->sense_buffer; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 694 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 695 | if (!hba->map_sg(hba, req, &hba->ccb[tag])) { |
| 696 | hba->ccb[tag].sg_count = 0; |
| 697 | memset(&req->variable[0], 0, 8); |
| 698 | } |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 699 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 700 | hba->send(hba, req, tag); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 701 | return 0; |
| 702 | } |
| 703 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 704 | static DEF_SCSI_QCMD(stex_queuecommand) |
| 705 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 706 | static void stex_scsi_done(struct st_ccb *ccb) |
| 707 | { |
| 708 | struct scsi_cmnd *cmd = ccb->cmd; |
| 709 | int result; |
| 710 | |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 711 | if (ccb->srb_status == SRB_STATUS_SUCCESS || ccb->srb_status == 0) { |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 712 | result = ccb->scsi_status; |
| 713 | switch (ccb->scsi_status) { |
| 714 | case SAM_STAT_GOOD: |
| 715 | result |= DID_OK << 16 | COMMAND_COMPLETE << 8; |
| 716 | break; |
| 717 | case SAM_STAT_CHECK_CONDITION: |
| 718 | result |= DRIVER_SENSE << 24; |
| 719 | break; |
| 720 | case SAM_STAT_BUSY: |
| 721 | result |= DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8; |
| 722 | break; |
| 723 | default: |
| 724 | result |= DID_ERROR << 16 | COMMAND_COMPLETE << 8; |
| 725 | break; |
| 726 | } |
| 727 | } |
| 728 | else if (ccb->srb_status & SRB_SEE_SENSE) |
| 729 | result = DRIVER_SENSE << 24 | SAM_STAT_CHECK_CONDITION; |
| 730 | else switch (ccb->srb_status) { |
| 731 | case SRB_STATUS_SELECTION_TIMEOUT: |
| 732 | result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8; |
| 733 | break; |
| 734 | case SRB_STATUS_BUSY: |
| 735 | result = DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8; |
| 736 | break; |
| 737 | case SRB_STATUS_INVALID_REQUEST: |
| 738 | case SRB_STATUS_ERROR: |
| 739 | default: |
| 740 | result = DID_ERROR << 16 | COMMAND_COMPLETE << 8; |
| 741 | break; |
| 742 | } |
| 743 | |
| 744 | cmd->result = result; |
| 745 | cmd->scsi_done(cmd); |
| 746 | } |
| 747 | |
| 748 | static void stex_copy_data(struct st_ccb *ccb, |
| 749 | struct status_msg *resp, unsigned int variable) |
| 750 | { |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 751 | if (resp->scsi_status != SAM_STAT_GOOD) { |
| 752 | if (ccb->sense_buffer != NULL) |
| 753 | memcpy(ccb->sense_buffer, resp->variable, |
| 754 | min(variable, ccb->sense_bufflen)); |
| 755 | return; |
| 756 | } |
| 757 | |
| 758 | if (ccb->cmd == NULL) |
| 759 | return; |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 760 | scsi_sg_copy_from_buffer(ccb->cmd, resp->variable, variable); |
Ed Lin | fb4f66b | 2006-09-27 19:23:41 +0800 | [diff] [blame] | 761 | } |
| 762 | |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 763 | static void stex_check_cmd(struct st_hba *hba, |
Ed Lin | fb4f66b | 2006-09-27 19:23:41 +0800 | [diff] [blame] | 764 | struct st_ccb *ccb, struct status_msg *resp) |
| 765 | { |
Ed Lin | fb4f66b | 2006-09-27 19:23:41 +0800 | [diff] [blame] | 766 | if (ccb->cmd->cmnd[0] == MGT_CMD && |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 767 | resp->scsi_status != SAM_STAT_CHECK_CONDITION) |
Ed Lin | 968a576 | 2007-07-05 12:09:06 -0700 | [diff] [blame] | 768 | scsi_set_resid(ccb->cmd, scsi_bufflen(ccb->cmd) - |
| 769 | le32_to_cpu(*(__le32 *)&resp->variable[0])); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | static void stex_mu_intr(struct st_hba *hba, u32 doorbell) |
| 773 | { |
| 774 | void __iomem *base = hba->mmio_base; |
| 775 | struct status_msg *resp; |
| 776 | struct st_ccb *ccb; |
| 777 | unsigned int size; |
| 778 | u16 tag; |
| 779 | |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 780 | if (unlikely(!(doorbell & MU_OUTBOUND_DOORBELL_STATUSHEADCHANGED))) |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 781 | return; |
| 782 | |
| 783 | /* status payloads */ |
| 784 | hba->status_head = readl(base + OMR1); |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 785 | if (unlikely(hba->status_head > hba->sts_count)) { |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 786 | printk(KERN_WARNING DRV_NAME "(%s): invalid status head\n", |
| 787 | pci_name(hba->pdev)); |
| 788 | return; |
| 789 | } |
| 790 | |
Ed Lin | fb4f66b | 2006-09-27 19:23:41 +0800 | [diff] [blame] | 791 | /* |
| 792 | * it's not a valid status payload if: |
| 793 | * 1. there are no pending requests(e.g. during init stage) |
| 794 | * 2. there are some pending requests, but the controller is in |
| 795 | * reset status, and its type is not st_yosemite |
| 796 | * firmware of st_yosemite in reset status will return pending requests |
| 797 | * to driver, so we allow it to pass |
| 798 | */ |
| 799 | if (unlikely(hba->out_req_cnt <= 0 || |
| 800 | (hba->mu_status == MU_STATE_RESETTING && |
| 801 | hba->cardtype != st_yosemite))) { |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 802 | hba->status_tail = hba->status_head; |
| 803 | goto update_status; |
| 804 | } |
| 805 | |
| 806 | while (hba->status_tail != hba->status_head) { |
| 807 | resp = stex_get_status(hba); |
| 808 | tag = le16_to_cpu(resp->tag); |
Ed Lin | cf35588 | 2006-09-01 14:31:51 +0800 | [diff] [blame] | 809 | if (unlikely(tag >= hba->host->can_queue)) { |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 810 | printk(KERN_WARNING DRV_NAME |
| 811 | "(%s): invalid tag\n", pci_name(hba->pdev)); |
| 812 | continue; |
| 813 | } |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 814 | |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 815 | hba->out_req_cnt--; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 816 | ccb = &hba->ccb[tag]; |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 817 | if (unlikely(hba->wait_ccb == ccb)) |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 818 | hba->wait_ccb = NULL; |
| 819 | if (unlikely(ccb->req == NULL)) { |
| 820 | printk(KERN_WARNING DRV_NAME |
| 821 | "(%s): lagging req\n", pci_name(hba->pdev)); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 822 | continue; |
| 823 | } |
| 824 | |
| 825 | size = resp->payload_sz * sizeof(u32); /* payload size */ |
| 826 | if (unlikely(size < sizeof(*resp) - STATUS_VAR_LEN || |
| 827 | size > sizeof(*resp))) { |
| 828 | printk(KERN_WARNING DRV_NAME "(%s): bad status size\n", |
| 829 | pci_name(hba->pdev)); |
| 830 | } else { |
| 831 | size -= sizeof(*resp) - STATUS_VAR_LEN; /* copy size */ |
| 832 | if (size) |
| 833 | stex_copy_data(ccb, resp, size); |
| 834 | } |
| 835 | |
Ed Lin - PTU | dd48ebf | 2009-01-26 02:40:11 -0800 | [diff] [blame] | 836 | ccb->req = NULL; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 837 | ccb->srb_status = resp->srb_status; |
| 838 | ccb->scsi_status = resp->scsi_status; |
| 839 | |
Ed Lin | cf35588 | 2006-09-01 14:31:51 +0800 | [diff] [blame] | 840 | if (likely(ccb->cmd != NULL)) { |
Ed Lin | fb4f66b | 2006-09-27 19:23:41 +0800 | [diff] [blame] | 841 | if (hba->cardtype == st_yosemite) |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 842 | stex_check_cmd(hba, ccb, resp); |
Ed Lin | fb4f66b | 2006-09-27 19:23:41 +0800 | [diff] [blame] | 843 | |
Ed Lin | cf35588 | 2006-09-01 14:31:51 +0800 | [diff] [blame] | 844 | if (unlikely(ccb->cmd->cmnd[0] == PASSTHRU_CMD && |
| 845 | ccb->cmd->cmnd[1] == PASSTHRU_GET_ADAPTER)) |
| 846 | stex_controller_info(hba, ccb); |
Ed Lin | fb4f66b | 2006-09-27 19:23:41 +0800 | [diff] [blame] | 847 | |
FUJITA Tomonori | d5587d5 | 2007-05-26 10:01:24 +0900 | [diff] [blame] | 848 | scsi_dma_unmap(ccb->cmd); |
Ed Lin | cf35588 | 2006-09-01 14:31:51 +0800 | [diff] [blame] | 849 | stex_scsi_done(ccb); |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 850 | } else |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 851 | ccb->req_type = 0; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | update_status: |
| 855 | writel(hba->status_head, base + IMR1); |
| 856 | readl(base + IMR1); /* flush */ |
| 857 | } |
| 858 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 859 | static irqreturn_t stex_intr(int irq, void *__hba) |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 860 | { |
| 861 | struct st_hba *hba = __hba; |
| 862 | void __iomem *base = hba->mmio_base; |
| 863 | u32 data; |
| 864 | unsigned long flags; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 865 | |
| 866 | spin_lock_irqsave(hba->host->host_lock, flags); |
| 867 | |
| 868 | data = readl(base + ODBL); |
| 869 | |
| 870 | if (data && data != 0xffffffff) { |
| 871 | /* clear the interrupt */ |
| 872 | writel(data, base + ODBL); |
| 873 | readl(base + ODBL); /* flush */ |
| 874 | stex_mu_intr(hba, data); |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 875 | spin_unlock_irqrestore(hba->host->host_lock, flags); |
| 876 | if (unlikely(data & MU_OUTBOUND_DOORBELL_REQUEST_RESET && |
| 877 | hba->cardtype == st_shasta)) |
| 878 | queue_work(hba->work_q, &hba->reset_work); |
| 879 | return IRQ_HANDLED; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | spin_unlock_irqrestore(hba->host->host_lock, flags); |
| 883 | |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 884 | return IRQ_NONE; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 885 | } |
| 886 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 887 | static void stex_ss_mu_intr(struct st_hba *hba) |
| 888 | { |
| 889 | struct status_msg *resp; |
| 890 | struct st_ccb *ccb; |
| 891 | __le32 *scratch; |
| 892 | unsigned int size; |
| 893 | int count = 0; |
| 894 | u32 value; |
| 895 | u16 tag; |
| 896 | |
| 897 | if (unlikely(hba->out_req_cnt <= 0 || |
| 898 | hba->mu_status == MU_STATE_RESETTING)) |
| 899 | return; |
| 900 | |
| 901 | while (count < hba->sts_count) { |
| 902 | scratch = hba->scratch + hba->status_tail; |
| 903 | value = le32_to_cpu(*scratch); |
| 904 | if (unlikely(!(value & SS_STS_NORMAL))) |
| 905 | return; |
| 906 | |
| 907 | resp = hba->status_buffer + hba->status_tail; |
| 908 | *scratch = 0; |
| 909 | ++count; |
| 910 | ++hba->status_tail; |
| 911 | hba->status_tail %= hba->sts_count+1; |
| 912 | |
| 913 | tag = (u16)value; |
| 914 | if (unlikely(tag >= hba->host->can_queue)) { |
| 915 | printk(KERN_WARNING DRV_NAME |
Ed Lin | 69cb487 | 2009-08-18 12:15:14 -0700 | [diff] [blame] | 916 | "(%s): invalid tag\n", pci_name(hba->pdev)); |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 917 | continue; |
| 918 | } |
| 919 | |
| 920 | hba->out_req_cnt--; |
| 921 | ccb = &hba->ccb[tag]; |
| 922 | if (unlikely(hba->wait_ccb == ccb)) |
| 923 | hba->wait_ccb = NULL; |
| 924 | if (unlikely(ccb->req == NULL)) { |
| 925 | printk(KERN_WARNING DRV_NAME |
| 926 | "(%s): lagging req\n", pci_name(hba->pdev)); |
| 927 | continue; |
| 928 | } |
| 929 | |
| 930 | ccb->req = NULL; |
| 931 | if (likely(value & SS_STS_DONE)) { /* normal case */ |
| 932 | ccb->srb_status = SRB_STATUS_SUCCESS; |
| 933 | ccb->scsi_status = SAM_STAT_GOOD; |
| 934 | } else { |
| 935 | ccb->srb_status = resp->srb_status; |
| 936 | ccb->scsi_status = resp->scsi_status; |
| 937 | size = resp->payload_sz * sizeof(u32); |
| 938 | if (unlikely(size < sizeof(*resp) - STATUS_VAR_LEN || |
| 939 | size > sizeof(*resp))) { |
| 940 | printk(KERN_WARNING DRV_NAME |
| 941 | "(%s): bad status size\n", |
| 942 | pci_name(hba->pdev)); |
| 943 | } else { |
| 944 | size -= sizeof(*resp) - STATUS_VAR_LEN; |
| 945 | if (size) |
| 946 | stex_copy_data(ccb, resp, size); |
| 947 | } |
| 948 | if (likely(ccb->cmd != NULL)) |
| 949 | stex_check_cmd(hba, ccb, resp); |
| 950 | } |
| 951 | |
| 952 | if (likely(ccb->cmd != NULL)) { |
| 953 | scsi_dma_unmap(ccb->cmd); |
| 954 | stex_scsi_done(ccb); |
| 955 | } else |
| 956 | ccb->req_type = 0; |
| 957 | } |
| 958 | } |
| 959 | |
| 960 | static irqreturn_t stex_ss_intr(int irq, void *__hba) |
| 961 | { |
| 962 | struct st_hba *hba = __hba; |
| 963 | void __iomem *base = hba->mmio_base; |
| 964 | u32 data; |
| 965 | unsigned long flags; |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 966 | |
| 967 | spin_lock_irqsave(hba->host->host_lock, flags); |
| 968 | |
| 969 | data = readl(base + YI2H_INT); |
| 970 | if (data && data != 0xffffffff) { |
| 971 | /* clear the interrupt */ |
| 972 | writel(data, base + YI2H_INT_C); |
| 973 | stex_ss_mu_intr(hba); |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 974 | spin_unlock_irqrestore(hba->host->host_lock, flags); |
| 975 | if (unlikely(data & SS_I2H_REQUEST_RESET)) |
| 976 | queue_work(hba->work_q, &hba->reset_work); |
| 977 | return IRQ_HANDLED; |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | spin_unlock_irqrestore(hba->host->host_lock, flags); |
| 981 | |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 982 | return IRQ_NONE; |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | static int stex_common_handshake(struct st_hba *hba) |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 986 | { |
| 987 | void __iomem *base = hba->mmio_base; |
| 988 | struct handshake_frame *h; |
| 989 | dma_addr_t status_phys; |
Ed Lin | 529e7a6 | 2006-12-04 17:49:34 -0800 | [diff] [blame] | 990 | u32 data; |
Ed Lin | 76fbf96 | 2006-12-04 17:49:42 -0800 | [diff] [blame] | 991 | unsigned long before; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 992 | |
| 993 | if (readl(base + OMR0) != MU_HANDSHAKE_SIGNATURE) { |
| 994 | writel(MU_INBOUND_DOORBELL_HANDSHAKE, base + IDBL); |
| 995 | readl(base + IDBL); |
Ed Lin | 76fbf96 | 2006-12-04 17:49:42 -0800 | [diff] [blame] | 996 | before = jiffies; |
| 997 | while (readl(base + OMR0) != MU_HANDSHAKE_SIGNATURE) { |
| 998 | if (time_after(jiffies, before + MU_MAX_DELAY * HZ)) { |
| 999 | printk(KERN_ERR DRV_NAME |
| 1000 | "(%s): no handshake signature\n", |
| 1001 | pci_name(hba->pdev)); |
| 1002 | return -1; |
| 1003 | } |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1004 | rmb(); |
| 1005 | msleep(1); |
| 1006 | } |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | udelay(10); |
| 1010 | |
Ed Lin | 529e7a6 | 2006-12-04 17:49:34 -0800 | [diff] [blame] | 1011 | data = readl(base + OMR1); |
| 1012 | if ((data & 0xffff0000) == MU_HANDSHAKE_SIGNATURE_HALF) { |
| 1013 | data &= 0x0000ffff; |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 1014 | if (hba->host->can_queue > data) { |
Ed Lin | 529e7a6 | 2006-12-04 17:49:34 -0800 | [diff] [blame] | 1015 | hba->host->can_queue = data; |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 1016 | hba->host->cmd_per_lun = data; |
| 1017 | } |
Ed Lin | 529e7a6 | 2006-12-04 17:49:34 -0800 | [diff] [blame] | 1018 | } |
| 1019 | |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 1020 | h = (struct handshake_frame *)hba->status_buffer; |
| 1021 | h->rb_phy = cpu_to_le64(hba->dma_handle); |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 1022 | h->req_sz = cpu_to_le16(hba->rq_size); |
| 1023 | h->req_cnt = cpu_to_le16(hba->rq_count+1); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1024 | h->status_sz = cpu_to_le16(sizeof(struct status_msg)); |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 1025 | h->status_cnt = cpu_to_le16(hba->sts_count+1); |
Tina Ruchandani | 0da3968 | 2015-10-30 01:30:40 -0700 | [diff] [blame] | 1026 | h->hosttime = cpu_to_le64(ktime_get_real_seconds()); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1027 | h->partner_type = HMU_PARTNER_TYPE; |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 1028 | if (hba->extra_offset) { |
| 1029 | h->extra_offset = cpu_to_le32(hba->extra_offset); |
Ed Lin | cbacfb5 | 2009-09-28 22:58:17 -0800 | [diff] [blame] | 1030 | h->extra_size = cpu_to_le32(hba->dma_size - hba->extra_offset); |
Ed Lin | 94e9108 | 2006-12-04 17:49:39 -0800 | [diff] [blame] | 1031 | } else |
| 1032 | h->extra_offset = h->extra_size = 0; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1033 | |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 1034 | status_phys = hba->dma_handle + (hba->rq_count+1) * hba->rq_size; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1035 | writel(status_phys, base + IMR0); |
| 1036 | readl(base + IMR0); |
| 1037 | writel((status_phys >> 16) >> 16, base + IMR1); |
| 1038 | readl(base + IMR1); |
| 1039 | |
| 1040 | writel((status_phys >> 16) >> 16, base + OMR0); /* old fw compatible */ |
| 1041 | readl(base + OMR0); |
| 1042 | writel(MU_INBOUND_DOORBELL_HANDSHAKE, base + IDBL); |
| 1043 | readl(base + IDBL); /* flush */ |
| 1044 | |
| 1045 | udelay(10); |
Ed Lin | 76fbf96 | 2006-12-04 17:49:42 -0800 | [diff] [blame] | 1046 | before = jiffies; |
| 1047 | while (readl(base + OMR0) != MU_HANDSHAKE_SIGNATURE) { |
| 1048 | if (time_after(jiffies, before + MU_MAX_DELAY * HZ)) { |
| 1049 | printk(KERN_ERR DRV_NAME |
| 1050 | "(%s): no signature after handshake frame\n", |
| 1051 | pci_name(hba->pdev)); |
| 1052 | return -1; |
| 1053 | } |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1054 | rmb(); |
| 1055 | msleep(1); |
| 1056 | } |
| 1057 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1058 | writel(0, base + IMR0); |
| 1059 | readl(base + IMR0); |
| 1060 | writel(0, base + OMR0); |
| 1061 | readl(base + OMR0); |
| 1062 | writel(0, base + IMR1); |
| 1063 | readl(base + IMR1); |
| 1064 | writel(0, base + OMR1); |
| 1065 | readl(base + OMR1); /* flush */ |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1066 | return 0; |
| 1067 | } |
| 1068 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1069 | static int stex_ss_handshake(struct st_hba *hba) |
| 1070 | { |
| 1071 | void __iomem *base = hba->mmio_base; |
| 1072 | struct st_msg_header *msg_h; |
| 1073 | struct handshake_frame *h; |
Ed Lin | 69cb487 | 2009-08-18 12:15:14 -0700 | [diff] [blame] | 1074 | __le32 *scratch; |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1075 | u32 data, scratch_size; |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1076 | unsigned long before; |
| 1077 | int ret = 0; |
| 1078 | |
Ed Lin | 69cb487 | 2009-08-18 12:15:14 -0700 | [diff] [blame] | 1079 | before = jiffies; |
| 1080 | while ((readl(base + YIOA_STATUS) & SS_MU_OPERATIONAL) == 0) { |
| 1081 | if (time_after(jiffies, before + MU_MAX_DELAY * HZ)) { |
| 1082 | printk(KERN_ERR DRV_NAME |
| 1083 | "(%s): firmware not operational\n", |
| 1084 | pci_name(hba->pdev)); |
| 1085 | return -1; |
| 1086 | } |
| 1087 | msleep(1); |
| 1088 | } |
| 1089 | |
| 1090 | msg_h = (struct st_msg_header *)hba->dma_mem; |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1091 | msg_h->handle = cpu_to_le64(hba->dma_handle); |
| 1092 | msg_h->flag = SS_HEAD_HANDSHAKE; |
| 1093 | |
Ed Lin | 69cb487 | 2009-08-18 12:15:14 -0700 | [diff] [blame] | 1094 | h = (struct handshake_frame *)(msg_h + 1); |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1095 | h->rb_phy = cpu_to_le64(hba->dma_handle); |
| 1096 | h->req_sz = cpu_to_le16(hba->rq_size); |
| 1097 | h->req_cnt = cpu_to_le16(hba->rq_count+1); |
| 1098 | h->status_sz = cpu_to_le16(sizeof(struct status_msg)); |
| 1099 | h->status_cnt = cpu_to_le16(hba->sts_count+1); |
Tina Ruchandani | 0da3968 | 2015-10-30 01:30:40 -0700 | [diff] [blame] | 1100 | h->hosttime = cpu_to_le64(ktime_get_real_seconds()); |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1101 | h->partner_type = HMU_PARTNER_TYPE; |
| 1102 | h->extra_offset = h->extra_size = 0; |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1103 | scratch_size = (hba->sts_count+1)*sizeof(u32); |
| 1104 | h->scratch_size = cpu_to_le32(scratch_size); |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1105 | |
| 1106 | data = readl(base + YINT_EN); |
| 1107 | data &= ~4; |
| 1108 | writel(data, base + YINT_EN); |
| 1109 | writel((hba->dma_handle >> 16) >> 16, base + YH2I_REQ_HI); |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1110 | readl(base + YH2I_REQ_HI); |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1111 | writel(hba->dma_handle, base + YH2I_REQ); |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1112 | readl(base + YH2I_REQ); /* flush */ |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1113 | |
| 1114 | scratch = hba->scratch; |
| 1115 | before = jiffies; |
| 1116 | while (!(le32_to_cpu(*scratch) & SS_STS_HANDSHAKE)) { |
| 1117 | if (time_after(jiffies, before + MU_MAX_DELAY * HZ)) { |
| 1118 | printk(KERN_ERR DRV_NAME |
| 1119 | "(%s): no signature after handshake frame\n", |
| 1120 | pci_name(hba->pdev)); |
| 1121 | ret = -1; |
| 1122 | break; |
| 1123 | } |
| 1124 | rmb(); |
| 1125 | msleep(1); |
| 1126 | } |
| 1127 | |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1128 | memset(scratch, 0, scratch_size); |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1129 | msg_h->flag = 0; |
| 1130 | return ret; |
| 1131 | } |
| 1132 | |
| 1133 | static int stex_handshake(struct st_hba *hba) |
| 1134 | { |
| 1135 | int err; |
| 1136 | unsigned long flags; |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1137 | unsigned int mu_status; |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1138 | |
| 1139 | err = (hba->cardtype == st_yel) ? |
| 1140 | stex_ss_handshake(hba) : stex_common_handshake(hba); |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1141 | spin_lock_irqsave(hba->host->host_lock, flags); |
| 1142 | mu_status = hba->mu_status; |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1143 | if (err == 0) { |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1144 | hba->req_head = 0; |
| 1145 | hba->req_tail = 0; |
| 1146 | hba->status_head = 0; |
| 1147 | hba->status_tail = 0; |
| 1148 | hba->out_req_cnt = 0; |
| 1149 | hba->mu_status = MU_STATE_STARTED; |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1150 | } else |
| 1151 | hba->mu_status = MU_STATE_FAILED; |
| 1152 | if (mu_status == MU_STATE_RESETTING) |
| 1153 | wake_up_all(&hba->reset_waitq); |
| 1154 | spin_unlock_irqrestore(hba->host->host_lock, flags); |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1155 | return err; |
| 1156 | } |
| 1157 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1158 | static int stex_abort(struct scsi_cmnd *cmd) |
| 1159 | { |
| 1160 | struct Scsi_Host *host = cmd->device->host; |
| 1161 | struct st_hba *hba = (struct st_hba *)host->hostdata; |
Ed Lin | cf35588 | 2006-09-01 14:31:51 +0800 | [diff] [blame] | 1162 | u16 tag = cmd->request->tag; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1163 | void __iomem *base; |
| 1164 | u32 data; |
| 1165 | int result = SUCCESS; |
| 1166 | unsigned long flags; |
Ed Lin | c25da0a | 2007-05-09 20:50:42 -0800 | [diff] [blame] | 1167 | |
Hannes Reinecke | 1fa6b5f | 2014-10-24 14:26:58 +0200 | [diff] [blame] | 1168 | scmd_printk(KERN_INFO, cmd, "aborting command\n"); |
Ed Lin | c25da0a | 2007-05-09 20:50:42 -0800 | [diff] [blame] | 1169 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1170 | base = hba->mmio_base; |
| 1171 | spin_lock_irqsave(host->host_lock, flags); |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1172 | if (tag < host->can_queue && |
| 1173 | hba->ccb[tag].req && hba->ccb[tag].cmd == cmd) |
Ed Lin | cf35588 | 2006-09-01 14:31:51 +0800 | [diff] [blame] | 1174 | hba->wait_ccb = &hba->ccb[tag]; |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1175 | else |
| 1176 | goto out; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1177 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1178 | if (hba->cardtype == st_yel) { |
| 1179 | data = readl(base + YI2H_INT); |
| 1180 | if (data == 0 || data == 0xffffffff) |
| 1181 | goto fail_out; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1182 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1183 | writel(data, base + YI2H_INT_C); |
| 1184 | stex_ss_mu_intr(hba); |
| 1185 | } else { |
| 1186 | data = readl(base + ODBL); |
| 1187 | if (data == 0 || data == 0xffffffff) |
| 1188 | goto fail_out; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1189 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1190 | writel(data, base + ODBL); |
| 1191 | readl(base + ODBL); /* flush */ |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1192 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1193 | stex_mu_intr(hba, data); |
| 1194 | } |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1195 | if (hba->wait_ccb == NULL) { |
| 1196 | printk(KERN_WARNING DRV_NAME |
| 1197 | "(%s): lost interrupt\n", pci_name(hba->pdev)); |
| 1198 | goto out; |
| 1199 | } |
| 1200 | |
| 1201 | fail_out: |
FUJITA Tomonori | d5587d5 | 2007-05-26 10:01:24 +0900 | [diff] [blame] | 1202 | scsi_dma_unmap(cmd); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1203 | hba->wait_ccb->req = NULL; /* nullify the req's future return */ |
| 1204 | hba->wait_ccb = NULL; |
| 1205 | result = FAILED; |
| 1206 | out: |
| 1207 | spin_unlock_irqrestore(host->host_lock, flags); |
| 1208 | return result; |
| 1209 | } |
| 1210 | |
| 1211 | static void stex_hard_reset(struct st_hba *hba) |
| 1212 | { |
| 1213 | struct pci_bus *bus; |
| 1214 | int i; |
| 1215 | u16 pci_cmd; |
| 1216 | u8 pci_bctl; |
| 1217 | |
| 1218 | for (i = 0; i < 16; i++) |
| 1219 | pci_read_config_dword(hba->pdev, i * 4, |
| 1220 | &hba->pdev->saved_config_space[i]); |
| 1221 | |
| 1222 | /* Reset secondary bus. Our controller(MU/ATU) is the only device on |
| 1223 | secondary bus. Consult Intel 80331/3 developer's manual for detail */ |
| 1224 | bus = hba->pdev->bus; |
| 1225 | pci_read_config_byte(bus->self, PCI_BRIDGE_CONTROL, &pci_bctl); |
| 1226 | pci_bctl |= PCI_BRIDGE_CTL_BUS_RESET; |
| 1227 | pci_write_config_byte(bus->self, PCI_BRIDGE_CONTROL, pci_bctl); |
Ed Lin | 69f4a51 | 2007-05-09 20:50:37 -0800 | [diff] [blame] | 1228 | |
| 1229 | /* |
| 1230 | * 1 ms may be enough for 8-port controllers. But 16-port controllers |
| 1231 | * require more time to finish bus reset. Use 100 ms here for safety |
| 1232 | */ |
| 1233 | msleep(100); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1234 | pci_bctl &= ~PCI_BRIDGE_CTL_BUS_RESET; |
| 1235 | pci_write_config_byte(bus->self, PCI_BRIDGE_CONTROL, pci_bctl); |
| 1236 | |
Ed Lin | 76fbf96 | 2006-12-04 17:49:42 -0800 | [diff] [blame] | 1237 | for (i = 0; i < MU_HARD_RESET_WAIT; i++) { |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1238 | pci_read_config_word(hba->pdev, PCI_COMMAND, &pci_cmd); |
Ed Lin | 47c4f99 | 2006-12-04 17:49:31 -0800 | [diff] [blame] | 1239 | if (pci_cmd != 0xffff && (pci_cmd & PCI_COMMAND_MASTER)) |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1240 | break; |
| 1241 | msleep(1); |
| 1242 | } |
| 1243 | |
| 1244 | ssleep(5); |
| 1245 | for (i = 0; i < 16; i++) |
| 1246 | pci_write_config_dword(hba->pdev, i * 4, |
| 1247 | hba->pdev->saved_config_space[i]); |
| 1248 | } |
| 1249 | |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1250 | static int stex_yos_reset(struct st_hba *hba) |
| 1251 | { |
| 1252 | void __iomem *base; |
| 1253 | unsigned long flags, before; |
| 1254 | int ret = 0; |
| 1255 | |
| 1256 | base = hba->mmio_base; |
| 1257 | writel(MU_INBOUND_DOORBELL_RESET, base + IDBL); |
| 1258 | readl(base + IDBL); /* flush */ |
| 1259 | before = jiffies; |
| 1260 | while (hba->out_req_cnt > 0) { |
| 1261 | if (time_after(jiffies, before + ST_INTERNAL_TIMEOUT * HZ)) { |
| 1262 | printk(KERN_WARNING DRV_NAME |
| 1263 | "(%s): reset timeout\n", pci_name(hba->pdev)); |
| 1264 | ret = -1; |
| 1265 | break; |
| 1266 | } |
| 1267 | msleep(1); |
| 1268 | } |
| 1269 | |
| 1270 | spin_lock_irqsave(hba->host->host_lock, flags); |
| 1271 | if (ret == -1) |
| 1272 | hba->mu_status = MU_STATE_FAILED; |
| 1273 | else |
| 1274 | hba->mu_status = MU_STATE_STARTED; |
| 1275 | wake_up_all(&hba->reset_waitq); |
| 1276 | spin_unlock_irqrestore(hba->host->host_lock, flags); |
| 1277 | |
| 1278 | return ret; |
| 1279 | } |
| 1280 | |
Ed Lin | 69cb487 | 2009-08-18 12:15:14 -0700 | [diff] [blame] | 1281 | static void stex_ss_reset(struct st_hba *hba) |
| 1282 | { |
| 1283 | writel(SS_H2I_INT_RESET, hba->mmio_base + YH2I_INT); |
| 1284 | readl(hba->mmio_base + YH2I_INT); |
| 1285 | ssleep(5); |
| 1286 | } |
| 1287 | |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1288 | static int stex_do_reset(struct st_hba *hba) |
| 1289 | { |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1290 | unsigned long flags; |
| 1291 | unsigned int mu_status = MU_STATE_RESETTING; |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1292 | |
| 1293 | spin_lock_irqsave(hba->host->host_lock, flags); |
| 1294 | if (hba->mu_status == MU_STATE_STARTING) { |
| 1295 | spin_unlock_irqrestore(hba->host->host_lock, flags); |
| 1296 | printk(KERN_INFO DRV_NAME "(%s): request reset during init\n", |
| 1297 | pci_name(hba->pdev)); |
| 1298 | return 0; |
| 1299 | } |
| 1300 | while (hba->mu_status == MU_STATE_RESETTING) { |
| 1301 | spin_unlock_irqrestore(hba->host->host_lock, flags); |
| 1302 | wait_event_timeout(hba->reset_waitq, |
| 1303 | hba->mu_status != MU_STATE_RESETTING, |
| 1304 | MU_MAX_DELAY * HZ); |
| 1305 | spin_lock_irqsave(hba->host->host_lock, flags); |
| 1306 | mu_status = hba->mu_status; |
| 1307 | } |
| 1308 | |
| 1309 | if (mu_status != MU_STATE_RESETTING) { |
| 1310 | spin_unlock_irqrestore(hba->host->host_lock, flags); |
| 1311 | return (mu_status == MU_STATE_STARTED) ? 0 : -1; |
| 1312 | } |
| 1313 | |
| 1314 | hba->mu_status = MU_STATE_RESETTING; |
| 1315 | spin_unlock_irqrestore(hba->host->host_lock, flags); |
| 1316 | |
| 1317 | if (hba->cardtype == st_yosemite) |
| 1318 | return stex_yos_reset(hba); |
| 1319 | |
| 1320 | if (hba->cardtype == st_shasta) |
| 1321 | stex_hard_reset(hba); |
| 1322 | else if (hba->cardtype == st_yel) |
| 1323 | stex_ss_reset(hba); |
| 1324 | |
Charles | 45b42ad | 2016-02-22 20:04:25 +0800 | [diff] [blame^] | 1325 | |
| 1326 | return_abnormal_state(hba, DID_RESET); |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1327 | |
| 1328 | if (stex_handshake(hba) == 0) |
| 1329 | return 0; |
| 1330 | |
| 1331 | printk(KERN_WARNING DRV_NAME "(%s): resetting: handshake failed\n", |
| 1332 | pci_name(hba->pdev)); |
| 1333 | return -1; |
| 1334 | } |
| 1335 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1336 | static int stex_reset(struct scsi_cmnd *cmd) |
| 1337 | { |
| 1338 | struct st_hba *hba; |
Ed Lin - PTU | 7cfe99a | 2009-01-26 02:41:53 -0800 | [diff] [blame] | 1339 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1340 | hba = (struct st_hba *) &cmd->device->host->hostdata[0]; |
| 1341 | |
Hannes Reinecke | 1fa6b5f | 2014-10-24 14:26:58 +0200 | [diff] [blame] | 1342 | shost_printk(KERN_INFO, cmd->device->host, |
| 1343 | "resetting host\n"); |
Ed Lin | c25da0a | 2007-05-09 20:50:42 -0800 | [diff] [blame] | 1344 | |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1345 | return stex_do_reset(hba) ? FAILED : SUCCESS; |
| 1346 | } |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1347 | |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1348 | static void stex_reset_work(struct work_struct *work) |
| 1349 | { |
| 1350 | struct st_hba *hba = container_of(work, struct st_hba, reset_work); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1351 | |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1352 | stex_do_reset(hba); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | static int stex_biosparam(struct scsi_device *sdev, |
| 1356 | struct block_device *bdev, sector_t capacity, int geom[]) |
| 1357 | { |
Ed Lin | b4b8bed | 2006-12-04 17:49:24 -0800 | [diff] [blame] | 1358 | int heads = 255, sectors = 63; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1359 | |
| 1360 | if (capacity < 0x200000) { |
| 1361 | heads = 64; |
| 1362 | sectors = 32; |
| 1363 | } |
| 1364 | |
Ed Lin | b4b8bed | 2006-12-04 17:49:24 -0800 | [diff] [blame] | 1365 | sector_div(capacity, heads * sectors); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1366 | |
| 1367 | geom[0] = heads; |
| 1368 | geom[1] = sectors; |
Ed Lin | b4b8bed | 2006-12-04 17:49:24 -0800 | [diff] [blame] | 1369 | geom[2] = capacity; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1370 | |
| 1371 | return 0; |
| 1372 | } |
| 1373 | |
| 1374 | static struct scsi_host_template driver_template = { |
| 1375 | .module = THIS_MODULE, |
| 1376 | .name = DRV_NAME, |
| 1377 | .proc_name = DRV_NAME, |
| 1378 | .bios_param = stex_biosparam, |
| 1379 | .queuecommand = stex_queuecommand, |
| 1380 | .slave_configure = stex_slave_config, |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1381 | .eh_abort_handler = stex_abort, |
| 1382 | .eh_host_reset_handler = stex_reset, |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1383 | .this_id = -1, |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 1384 | }; |
| 1385 | |
| 1386 | static struct pci_device_id stex_pci_tbl[] = { |
| 1387 | /* st_shasta */ |
| 1388 | { 0x105a, 0x8350, PCI_ANY_ID, PCI_ANY_ID, 0, 0, |
| 1389 | st_shasta }, /* SuperTrak EX8350/8300/16350/16300 */ |
| 1390 | { 0x105a, 0xc350, PCI_ANY_ID, PCI_ANY_ID, 0, 0, |
| 1391 | st_shasta }, /* SuperTrak EX12350 */ |
| 1392 | { 0x105a, 0x4302, PCI_ANY_ID, PCI_ANY_ID, 0, 0, |
| 1393 | st_shasta }, /* SuperTrak EX4350 */ |
| 1394 | { 0x105a, 0xe350, PCI_ANY_ID, PCI_ANY_ID, 0, 0, |
| 1395 | st_shasta }, /* SuperTrak EX24350 */ |
| 1396 | |
| 1397 | /* st_vsc */ |
| 1398 | { 0x105a, 0x7250, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_vsc }, |
| 1399 | |
| 1400 | /* st_yosemite */ |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1401 | { 0x105a, 0x8650, 0x105a, PCI_ANY_ID, 0, 0, st_yosemite }, |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 1402 | |
| 1403 | /* st_seq */ |
| 1404 | { 0x105a, 0x3360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_seq }, |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1405 | |
| 1406 | /* st_yel */ |
| 1407 | { 0x105a, 0x8650, 0x1033, PCI_ANY_ID, 0, 0, st_yel }, |
| 1408 | { 0x105a, 0x8760, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_yel }, |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 1409 | { } /* terminate list */ |
| 1410 | }; |
| 1411 | |
| 1412 | static struct st_card_info stex_card_info[] = { |
| 1413 | /* st_shasta */ |
| 1414 | { |
| 1415 | .max_id = 17, |
| 1416 | .max_lun = 8, |
| 1417 | .max_channel = 0, |
| 1418 | .rq_count = 32, |
| 1419 | .rq_size = 1048, |
| 1420 | .sts_count = 32, |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1421 | .alloc_rq = stex_alloc_req, |
| 1422 | .map_sg = stex_map_sg, |
| 1423 | .send = stex_send_cmd, |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 1424 | }, |
| 1425 | |
| 1426 | /* st_vsc */ |
| 1427 | { |
| 1428 | .max_id = 129, |
| 1429 | .max_lun = 1, |
| 1430 | .max_channel = 0, |
| 1431 | .rq_count = 32, |
| 1432 | .rq_size = 1048, |
| 1433 | .sts_count = 32, |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1434 | .alloc_rq = stex_alloc_req, |
| 1435 | .map_sg = stex_map_sg, |
| 1436 | .send = stex_send_cmd, |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 1437 | }, |
| 1438 | |
| 1439 | /* st_yosemite */ |
| 1440 | { |
| 1441 | .max_id = 2, |
| 1442 | .max_lun = 256, |
| 1443 | .max_channel = 0, |
| 1444 | .rq_count = 256, |
| 1445 | .rq_size = 1048, |
| 1446 | .sts_count = 256, |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1447 | .alloc_rq = stex_alloc_req, |
| 1448 | .map_sg = stex_map_sg, |
| 1449 | .send = stex_send_cmd, |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 1450 | }, |
| 1451 | |
| 1452 | /* st_seq */ |
| 1453 | { |
| 1454 | .max_id = 129, |
| 1455 | .max_lun = 1, |
| 1456 | .max_channel = 0, |
| 1457 | .rq_count = 32, |
| 1458 | .rq_size = 1048, |
| 1459 | .sts_count = 32, |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1460 | .alloc_rq = stex_alloc_req, |
| 1461 | .map_sg = stex_map_sg, |
| 1462 | .send = stex_send_cmd, |
| 1463 | }, |
| 1464 | |
| 1465 | /* st_yel */ |
| 1466 | { |
| 1467 | .max_id = 129, |
| 1468 | .max_lun = 256, |
| 1469 | .max_channel = 3, |
| 1470 | .rq_count = 801, |
| 1471 | .rq_size = 512, |
| 1472 | .sts_count = 801, |
| 1473 | .alloc_rq = stex_ss_alloc_req, |
| 1474 | .map_sg = stex_ss_map_sg, |
| 1475 | .send = stex_ss_send_cmd, |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 1476 | }, |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1477 | }; |
| 1478 | |
| 1479 | static int stex_set_dma_mask(struct pci_dev * pdev) |
| 1480 | { |
| 1481 | int ret; |
Ed Lin - PTU | 7cfe99a | 2009-01-26 02:41:53 -0800 | [diff] [blame] | 1482 | |
Ed Lin | cce9c8a | 2009-09-28 22:58:36 -0800 | [diff] [blame] | 1483 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) |
| 1484 | && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1485 | return 0; |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1486 | ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1487 | if (!ret) |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1488 | ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1489 | return ret; |
| 1490 | } |
| 1491 | |
Ed Lin | 99946f8 | 2009-03-31 17:30:25 -0800 | [diff] [blame] | 1492 | static int stex_request_irq(struct st_hba *hba) |
| 1493 | { |
| 1494 | struct pci_dev *pdev = hba->pdev; |
| 1495 | int status; |
| 1496 | |
| 1497 | if (msi) { |
| 1498 | status = pci_enable_msi(pdev); |
| 1499 | if (status != 0) |
| 1500 | printk(KERN_ERR DRV_NAME |
| 1501 | "(%s): error %d setting up MSI\n", |
| 1502 | pci_name(pdev), status); |
| 1503 | else |
| 1504 | hba->msi_enabled = 1; |
| 1505 | } else |
| 1506 | hba->msi_enabled = 0; |
| 1507 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1508 | status = request_irq(pdev->irq, hba->cardtype == st_yel ? |
| 1509 | stex_ss_intr : stex_intr, IRQF_SHARED, DRV_NAME, hba); |
Ed Lin | 99946f8 | 2009-03-31 17:30:25 -0800 | [diff] [blame] | 1510 | |
| 1511 | if (status != 0) { |
| 1512 | if (hba->msi_enabled) |
| 1513 | pci_disable_msi(pdev); |
| 1514 | } |
| 1515 | return status; |
| 1516 | } |
| 1517 | |
| 1518 | static void stex_free_irq(struct st_hba *hba) |
| 1519 | { |
| 1520 | struct pci_dev *pdev = hba->pdev; |
| 1521 | |
| 1522 | free_irq(pdev->irq, hba); |
| 1523 | if (hba->msi_enabled) |
| 1524 | pci_disable_msi(pdev); |
| 1525 | } |
| 1526 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 1527 | static int stex_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1528 | { |
| 1529 | struct st_hba *hba; |
| 1530 | struct Scsi_Host *host; |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 1531 | const struct st_card_info *ci = NULL; |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1532 | u32 sts_offset, cp_offset, scratch_offset; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1533 | int err; |
| 1534 | |
| 1535 | err = pci_enable_device(pdev); |
| 1536 | if (err) |
| 1537 | return err; |
| 1538 | |
| 1539 | pci_set_master(pdev); |
| 1540 | |
| 1541 | host = scsi_host_alloc(&driver_template, sizeof(struct st_hba)); |
| 1542 | |
| 1543 | if (!host) { |
| 1544 | printk(KERN_ERR DRV_NAME "(%s): scsi_host_alloc failed\n", |
| 1545 | pci_name(pdev)); |
| 1546 | err = -ENOMEM; |
| 1547 | goto out_disable; |
| 1548 | } |
| 1549 | |
| 1550 | hba = (struct st_hba *)host->hostdata; |
| 1551 | memset(hba, 0, sizeof(struct st_hba)); |
| 1552 | |
| 1553 | err = pci_request_regions(pdev, DRV_NAME); |
| 1554 | if (err < 0) { |
| 1555 | printk(KERN_ERR DRV_NAME "(%s): request regions failed\n", |
| 1556 | pci_name(pdev)); |
| 1557 | goto out_scsi_host_put; |
| 1558 | } |
| 1559 | |
Arjan van de Ven | 25729a7 | 2008-09-28 16:18:02 -0700 | [diff] [blame] | 1560 | hba->mmio_base = pci_ioremap_bar(pdev, 0); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1561 | if ( !hba->mmio_base) { |
| 1562 | printk(KERN_ERR DRV_NAME "(%s): memory map failed\n", |
| 1563 | pci_name(pdev)); |
| 1564 | err = -ENOMEM; |
| 1565 | goto out_release_regions; |
| 1566 | } |
| 1567 | |
| 1568 | err = stex_set_dma_mask(pdev); |
| 1569 | if (err) { |
| 1570 | printk(KERN_ERR DRV_NAME "(%s): set dma mask failed\n", |
| 1571 | pci_name(pdev)); |
| 1572 | goto out_iounmap; |
| 1573 | } |
| 1574 | |
Ed Lin | 94e9108 | 2006-12-04 17:49:39 -0800 | [diff] [blame] | 1575 | hba->cardtype = (unsigned int) id->driver_data; |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 1576 | ci = &stex_card_info[hba->cardtype]; |
Charles | 1ec364e | 2016-02-22 20:02:02 +0800 | [diff] [blame] | 1577 | switch (id->subdevice) { |
| 1578 | case 0x4221: |
| 1579 | case 0x4222: |
| 1580 | case 0x4223: |
| 1581 | case 0x4224: |
| 1582 | case 0x4225: |
| 1583 | case 0x4226: |
| 1584 | case 0x4227: |
| 1585 | case 0x4261: |
| 1586 | case 0x4262: |
| 1587 | case 0x4263: |
| 1588 | case 0x4264: |
| 1589 | case 0x4265: |
| 1590 | break; |
| 1591 | default: |
| 1592 | if (hba->cardtype == st_yel) |
| 1593 | hba->supports_pm = 1; |
| 1594 | } |
| 1595 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1596 | sts_offset = scratch_offset = (ci->rq_count+1) * ci->rq_size; |
| 1597 | if (hba->cardtype == st_yel) |
| 1598 | sts_offset += (ci->sts_count+1) * sizeof(u32); |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 1599 | cp_offset = sts_offset + (ci->sts_count+1) * sizeof(struct status_msg); |
| 1600 | hba->dma_size = cp_offset + sizeof(struct st_frame); |
| 1601 | if (hba->cardtype == st_seq || |
| 1602 | (hba->cardtype == st_vsc && (pdev->subsystem_device & 1))) { |
| 1603 | hba->extra_offset = hba->dma_size; |
| 1604 | hba->dma_size += ST_ADDITIONAL_MEM; |
| 1605 | } |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1606 | hba->dma_mem = dma_alloc_coherent(&pdev->dev, |
Ed Lin | 94e9108 | 2006-12-04 17:49:39 -0800 | [diff] [blame] | 1607 | hba->dma_size, &hba->dma_handle, GFP_KERNEL); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1608 | if (!hba->dma_mem) { |
Ed Lin | cbacfb5 | 2009-09-28 22:58:17 -0800 | [diff] [blame] | 1609 | /* Retry minimum coherent mapping for st_seq and st_vsc */ |
| 1610 | if (hba->cardtype == st_seq || |
| 1611 | (hba->cardtype == st_vsc && (pdev->subsystem_device & 1))) { |
| 1612 | printk(KERN_WARNING DRV_NAME |
| 1613 | "(%s): allocating min buffer for controller\n", |
| 1614 | pci_name(pdev)); |
| 1615 | hba->dma_size = hba->extra_offset |
| 1616 | + ST_ADDITIONAL_MEM_MIN; |
| 1617 | hba->dma_mem = dma_alloc_coherent(&pdev->dev, |
| 1618 | hba->dma_size, &hba->dma_handle, GFP_KERNEL); |
| 1619 | } |
| 1620 | |
| 1621 | if (!hba->dma_mem) { |
| 1622 | err = -ENOMEM; |
| 1623 | printk(KERN_ERR DRV_NAME "(%s): dma mem alloc failed\n", |
| 1624 | pci_name(pdev)); |
| 1625 | goto out_iounmap; |
| 1626 | } |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1627 | } |
| 1628 | |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 1629 | hba->ccb = kcalloc(ci->rq_count, sizeof(struct st_ccb), GFP_KERNEL); |
| 1630 | if (!hba->ccb) { |
| 1631 | err = -ENOMEM; |
| 1632 | printk(KERN_ERR DRV_NAME "(%s): ccb alloc failed\n", |
| 1633 | pci_name(pdev)); |
| 1634 | goto out_pci_free; |
| 1635 | } |
| 1636 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1637 | if (hba->cardtype == st_yel) |
| 1638 | hba->scratch = (__le32 *)(hba->dma_mem + scratch_offset); |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 1639 | hba->status_buffer = (struct status_msg *)(hba->dma_mem + sts_offset); |
| 1640 | hba->copy_buffer = hba->dma_mem + cp_offset; |
| 1641 | hba->rq_count = ci->rq_count; |
| 1642 | hba->rq_size = ci->rq_size; |
| 1643 | hba->sts_count = ci->sts_count; |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1644 | hba->alloc_rq = ci->alloc_rq; |
| 1645 | hba->map_sg = ci->map_sg; |
| 1646 | hba->send = ci->send; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1647 | hba->mu_status = MU_STATE_STARTING; |
| 1648 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1649 | if (hba->cardtype == st_yel) |
| 1650 | host->sg_tablesize = 38; |
| 1651 | else |
| 1652 | host->sg_tablesize = 32; |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 1653 | host->can_queue = ci->rq_count; |
| 1654 | host->cmd_per_lun = ci->rq_count; |
| 1655 | host->max_id = ci->max_id; |
| 1656 | host->max_lun = ci->max_lun; |
| 1657 | host->max_channel = ci->max_channel; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1658 | host->unique_id = host->host_no; |
| 1659 | host->max_cmd_len = STEX_CDB_LENGTH; |
| 1660 | |
| 1661 | hba->host = host; |
| 1662 | hba->pdev = pdev; |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1663 | init_waitqueue_head(&hba->reset_waitq); |
| 1664 | |
| 1665 | snprintf(hba->work_q_name, sizeof(hba->work_q_name), |
| 1666 | "stex_wq_%d", host->host_no); |
| 1667 | hba->work_q = create_singlethread_workqueue(hba->work_q_name); |
| 1668 | if (!hba->work_q) { |
| 1669 | printk(KERN_ERR DRV_NAME "(%s): create workqueue failed\n", |
| 1670 | pci_name(pdev)); |
| 1671 | err = -ENOMEM; |
| 1672 | goto out_ccb_free; |
| 1673 | } |
| 1674 | INIT_WORK(&hba->reset_work, stex_reset_work); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1675 | |
Ed Lin | 99946f8 | 2009-03-31 17:30:25 -0800 | [diff] [blame] | 1676 | err = stex_request_irq(hba); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1677 | if (err) { |
| 1678 | printk(KERN_ERR DRV_NAME "(%s): request irq failed\n", |
| 1679 | pci_name(pdev)); |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1680 | goto out_free_wq; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | err = stex_handshake(hba); |
| 1684 | if (err) |
| 1685 | goto out_free_irq; |
| 1686 | |
| 1687 | pci_set_drvdata(pdev, hba); |
| 1688 | |
| 1689 | err = scsi_add_host(host, &pdev->dev); |
| 1690 | if (err) { |
| 1691 | printk(KERN_ERR DRV_NAME "(%s): scsi_add_host failed\n", |
| 1692 | pci_name(pdev)); |
| 1693 | goto out_free_irq; |
| 1694 | } |
| 1695 | |
| 1696 | scsi_scan_host(host); |
| 1697 | |
| 1698 | return 0; |
| 1699 | |
| 1700 | out_free_irq: |
Ed Lin | 99946f8 | 2009-03-31 17:30:25 -0800 | [diff] [blame] | 1701 | stex_free_irq(hba); |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1702 | out_free_wq: |
| 1703 | destroy_workqueue(hba->work_q); |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 1704 | out_ccb_free: |
| 1705 | kfree(hba->ccb); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1706 | out_pci_free: |
Ed Lin | 94e9108 | 2006-12-04 17:49:39 -0800 | [diff] [blame] | 1707 | dma_free_coherent(&pdev->dev, hba->dma_size, |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1708 | hba->dma_mem, hba->dma_handle); |
| 1709 | out_iounmap: |
| 1710 | iounmap(hba->mmio_base); |
| 1711 | out_release_regions: |
| 1712 | pci_release_regions(pdev); |
| 1713 | out_scsi_host_put: |
| 1714 | scsi_host_put(host); |
| 1715 | out_disable: |
| 1716 | pci_disable_device(pdev); |
| 1717 | |
| 1718 | return err; |
| 1719 | } |
| 1720 | |
| 1721 | static void stex_hba_stop(struct st_hba *hba) |
| 1722 | { |
| 1723 | struct req_msg *req; |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1724 | struct st_msg_header *msg_h; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1725 | unsigned long flags; |
| 1726 | unsigned long before; |
Ed Lin | cf35588 | 2006-09-01 14:31:51 +0800 | [diff] [blame] | 1727 | u16 tag = 0; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1728 | |
| 1729 | spin_lock_irqsave(hba->host->host_lock, flags); |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1730 | req = hba->alloc_rq(hba); |
| 1731 | if (hba->cardtype == st_yel) { |
| 1732 | msg_h = (struct st_msg_header *)req - 1; |
| 1733 | memset(msg_h, 0, hba->rq_size); |
| 1734 | } else |
| 1735 | memset(req, 0, hba->rq_size); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1736 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1737 | if (hba->cardtype == st_yosemite || hba->cardtype == st_yel) { |
Ed Lin | fb4f66b | 2006-09-27 19:23:41 +0800 | [diff] [blame] | 1738 | req->cdb[0] = MGT_CMD; |
| 1739 | req->cdb[1] = MGT_CMD_SIGNATURE; |
| 1740 | req->cdb[2] = CTLR_CONFIG_CMD; |
| 1741 | req->cdb[3] = CTLR_SHUTDOWN; |
| 1742 | } else { |
| 1743 | req->cdb[0] = CONTROLLER_CMD; |
| 1744 | req->cdb[1] = CTLR_POWER_STATE_CHANGE; |
| 1745 | req->cdb[2] = CTLR_POWER_SAVING; |
| 1746 | } |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1747 | |
| 1748 | hba->ccb[tag].cmd = NULL; |
| 1749 | hba->ccb[tag].sg_count = 0; |
| 1750 | hba->ccb[tag].sense_bufflen = 0; |
| 1751 | hba->ccb[tag].sense_buffer = NULL; |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 1752 | hba->ccb[tag].req_type = PASSTHRU_REQ_TYPE; |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1753 | |
Ed Lin | 0f3f6ee | 2009-03-31 17:30:36 -0800 | [diff] [blame] | 1754 | hba->send(hba, req, tag); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1755 | spin_unlock_irqrestore(hba->host->host_lock, flags); |
| 1756 | |
Ed Lin | cf35588 | 2006-09-01 14:31:51 +0800 | [diff] [blame] | 1757 | before = jiffies; |
| 1758 | while (hba->ccb[tag].req_type & PASSTHRU_REQ_TYPE) { |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 1759 | if (time_after(jiffies, before + ST_INTERNAL_TIMEOUT * HZ)) { |
| 1760 | hba->ccb[tag].req_type = 0; |
Ed Lin | cf35588 | 2006-09-01 14:31:51 +0800 | [diff] [blame] | 1761 | return; |
Ed Lin | f149816 | 2009-03-31 17:30:19 -0800 | [diff] [blame] | 1762 | } |
| 1763 | msleep(1); |
Ed Lin | cf35588 | 2006-09-01 14:31:51 +0800 | [diff] [blame] | 1764 | } |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | static void stex_hba_free(struct st_hba *hba) |
| 1768 | { |
Ed Lin | 99946f8 | 2009-03-31 17:30:25 -0800 | [diff] [blame] | 1769 | stex_free_irq(hba); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1770 | |
Ed Lin | 9eb46d2 | 2009-09-28 22:58:33 -0800 | [diff] [blame] | 1771 | destroy_workqueue(hba->work_q); |
| 1772 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1773 | iounmap(hba->mmio_base); |
| 1774 | |
| 1775 | pci_release_regions(hba->pdev); |
| 1776 | |
Ed Lin | 591a3a5 | 2009-03-31 17:30:31 -0800 | [diff] [blame] | 1777 | kfree(hba->ccb); |
| 1778 | |
Ed Lin | 94e9108 | 2006-12-04 17:49:39 -0800 | [diff] [blame] | 1779 | dma_free_coherent(&hba->pdev->dev, hba->dma_size, |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1780 | hba->dma_mem, hba->dma_handle); |
| 1781 | } |
| 1782 | |
| 1783 | static void stex_remove(struct pci_dev *pdev) |
| 1784 | { |
| 1785 | struct st_hba *hba = pci_get_drvdata(pdev); |
| 1786 | |
Charles | 45b42ad | 2016-02-22 20:04:25 +0800 | [diff] [blame^] | 1787 | hba->mu_status = MU_STATE_NOCONNECT; |
| 1788 | return_abnormal_state(hba, DID_NO_CONNECT); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1789 | scsi_remove_host(hba->host); |
| 1790 | |
Charles | 45b42ad | 2016-02-22 20:04:25 +0800 | [diff] [blame^] | 1791 | scsi_block_requests(hba->host); |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1792 | |
| 1793 | stex_hba_free(hba); |
| 1794 | |
| 1795 | scsi_host_put(hba->host); |
| 1796 | |
| 1797 | pci_disable_device(pdev); |
| 1798 | } |
| 1799 | |
| 1800 | static void stex_shutdown(struct pci_dev *pdev) |
| 1801 | { |
| 1802 | struct st_hba *hba = pci_get_drvdata(pdev); |
| 1803 | |
| 1804 | stex_hba_stop(hba); |
| 1805 | } |
| 1806 | |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1807 | MODULE_DEVICE_TABLE(pci, stex_pci_tbl); |
| 1808 | |
| 1809 | static struct pci_driver stex_pci_driver = { |
| 1810 | .name = DRV_NAME, |
| 1811 | .id_table = stex_pci_tbl, |
| 1812 | .probe = stex_probe, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 1813 | .remove = stex_remove, |
Jeff Garzik | 5a25ba1 | 2006-09-01 03:12:19 -0400 | [diff] [blame] | 1814 | .shutdown = stex_shutdown, |
| 1815 | }; |
| 1816 | |
| 1817 | static int __init stex_init(void) |
| 1818 | { |
| 1819 | printk(KERN_INFO DRV_NAME |
| 1820 | ": Promise SuperTrak EX Driver version: %s\n", |
| 1821 | ST_DRIVER_VERSION); |
| 1822 | |
| 1823 | return pci_register_driver(&stex_pci_driver); |
| 1824 | } |
| 1825 | |
| 1826 | static void __exit stex_exit(void) |
| 1827 | { |
| 1828 | pci_unregister_driver(&stex_pci_driver); |
| 1829 | } |
| 1830 | |
| 1831 | module_init(stex_init); |
| 1832 | module_exit(stex_exit); |