Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 2 | * QLogic Fibre Channel HBA Driver |
Andrew Vasquez | 01e58d8 | 2008-04-03 13:13:13 -0700 | [diff] [blame] | 3 | * Copyright (c) 2003-2008 QLogic Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | #include "qla_def.h" |
| 8 | |
| 9 | #include <linux/moduleparam.h> |
| 10 | #include <linux/vmalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/delay.h> |
Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 12 | #include <linux/kthread.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
| 14 | #include <scsi/scsi_tcq.h> |
| 15 | #include <scsi/scsicam.h> |
| 16 | #include <scsi/scsi_transport.h> |
| 17 | #include <scsi/scsi_transport_fc.h> |
| 18 | |
| 19 | /* |
| 20 | * Driver version |
| 21 | */ |
| 22 | char qla2x00_version_str[40]; |
| 23 | |
| 24 | /* |
| 25 | * SRB allocation cache |
| 26 | */ |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 27 | static struct kmem_cache *srb_cachep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 29 | int num_hosts; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | int ql2xlogintimeout = 20; |
| 31 | module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR); |
| 32 | MODULE_PARM_DESC(ql2xlogintimeout, |
| 33 | "Login timeout value in seconds."); |
| 34 | |
Andrew Vasquez | a7b6184 | 2007-05-07 07:42:59 -0700 | [diff] [blame] | 35 | int qlport_down_retry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR); |
| 37 | MODULE_PARM_DESC(qlport_down_retry, |
Jesper Juhl | 900d9f9 | 2006-06-30 02:33:07 -0700 | [diff] [blame] | 38 | "Maximum number of command retries to a port that returns " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | "a PORT-DOWN status."); |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | int ql2xplogiabsentdevice; |
| 42 | module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR); |
| 43 | MODULE_PARM_DESC(ql2xplogiabsentdevice, |
| 44 | "Option to enable PLOGI to devices that are not present after " |
Jesper Juhl | 900d9f9 | 2006-06-30 02:33:07 -0700 | [diff] [blame] | 45 | "a Fabric scan. This is needed for several broken switches. " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | "Default is 0 - no PLOGI. 1 - perfom PLOGI."); |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | int ql2xloginretrycount = 0; |
| 49 | module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR); |
| 50 | MODULE_PARM_DESC(ql2xloginretrycount, |
| 51 | "Specify an alternate value for the NVRAM login retry count."); |
| 52 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 53 | int ql2xallocfwdump = 1; |
| 54 | module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR); |
| 55 | MODULE_PARM_DESC(ql2xallocfwdump, |
| 56 | "Option to enable allocation of memory for a firmware dump " |
| 57 | "during HBA initialization. Memory allocation requirements " |
| 58 | "vary by ISP type. Default is 1 - allocate memory."); |
| 59 | |
Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 60 | int ql2xextended_error_logging; |
Andrew Vasquez | 27d9403 | 2007-03-12 10:41:30 -0700 | [diff] [blame] | 61 | module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR); |
Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 62 | MODULE_PARM_DESC(ql2xextended_error_logging, |
Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 63 | "Option to enable extended error logging, " |
| 64 | "Default is 0 - no logging. 1 - log errors."); |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | static void qla2x00_free_device(scsi_qla_host_t *); |
| 67 | |
| 68 | static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha); |
| 69 | |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 70 | int ql2xfdmienable; |
| 71 | module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR); |
| 72 | MODULE_PARM_DESC(ql2xfdmienable, |
| 73 | "Enables FDMI registratons " |
| 74 | "Default is 0 - no FDMI. 1 - perfom FDMI."); |
| 75 | |
Andrew Vasquez | df7baa5 | 2006-10-13 09:33:39 -0700 | [diff] [blame] | 76 | #define MAX_Q_DEPTH 32 |
| 77 | static int ql2xmaxqdepth = MAX_Q_DEPTH; |
| 78 | module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR); |
| 79 | MODULE_PARM_DESC(ql2xmaxqdepth, |
| 80 | "Maximum queue depth to report for target devices."); |
| 81 | |
| 82 | int ql2xqfullrampup = 120; |
| 83 | module_param(ql2xqfullrampup, int, S_IRUGO|S_IWUSR); |
| 84 | MODULE_PARM_DESC(ql2xqfullrampup, |
| 85 | "Number of seconds to wait to begin to ramp-up the queue " |
| 86 | "depth for a device after a queue-full condition has been " |
| 87 | "detected. Default is 120 seconds."); |
| 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | /* |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 90 | * SCSI host template entry points |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | */ |
| 92 | static int qla2xxx_slave_configure(struct scsi_device * device); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 93 | static int qla2xxx_slave_alloc(struct scsi_device *); |
Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 94 | static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time); |
| 95 | static void qla2xxx_scan_start(struct Scsi_Host *); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 96 | static void qla2xxx_slave_destroy(struct scsi_device *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | static int qla2x00_queuecommand(struct scsi_cmnd *cmd, |
| 98 | void (*fn)(struct scsi_cmnd *)); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 99 | static int qla24xx_queuecommand(struct scsi_cmnd *cmd, |
| 100 | void (*fn)(struct scsi_cmnd *)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | static int qla2xxx_eh_abort(struct scsi_cmnd *); |
| 102 | static int qla2xxx_eh_device_reset(struct scsi_cmnd *); |
| 103 | static int qla2xxx_eh_bus_reset(struct scsi_cmnd *); |
| 104 | static int qla2xxx_eh_host_reset(struct scsi_cmnd *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
Andrew Vasquez | ce7e4af | 2005-08-26 19:09:30 -0700 | [diff] [blame] | 106 | static int qla2x00_change_queue_depth(struct scsi_device *, int); |
| 107 | static int qla2x00_change_queue_type(struct scsi_device *, int); |
| 108 | |
Adrian Bunk | a824ebb | 2008-01-17 09:02:15 -0800 | [diff] [blame] | 109 | static struct scsi_host_template qla2x00_driver_template = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | .module = THIS_MODULE, |
Andrew Vasquez | cb63067 | 2006-05-17 15:09:45 -0700 | [diff] [blame] | 111 | .name = QLA2XXX_DRIVER_NAME, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | .queuecommand = qla2x00_queuecommand, |
| 113 | |
| 114 | .eh_abort_handler = qla2xxx_eh_abort, |
| 115 | .eh_device_reset_handler = qla2xxx_eh_device_reset, |
| 116 | .eh_bus_reset_handler = qla2xxx_eh_bus_reset, |
| 117 | .eh_host_reset_handler = qla2xxx_eh_host_reset, |
| 118 | |
| 119 | .slave_configure = qla2xxx_slave_configure, |
| 120 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 121 | .slave_alloc = qla2xxx_slave_alloc, |
| 122 | .slave_destroy = qla2xxx_slave_destroy, |
Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 123 | .scan_finished = qla2xxx_scan_finished, |
| 124 | .scan_start = qla2xxx_scan_start, |
Andrew Vasquez | ce7e4af | 2005-08-26 19:09:30 -0700 | [diff] [blame] | 125 | .change_queue_depth = qla2x00_change_queue_depth, |
| 126 | .change_queue_type = qla2x00_change_queue_type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | .this_id = -1, |
| 128 | .cmd_per_lun = 3, |
| 129 | .use_clustering = ENABLE_CLUSTERING, |
| 130 | .sg_tablesize = SG_ALL, |
| 131 | |
| 132 | /* |
| 133 | * The RISC allows for each command to transfer (2^32-1) bytes of data, |
| 134 | * which equates to 0x800000 sectors. |
| 135 | */ |
| 136 | .max_sectors = 0xFFFF, |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 137 | .shost_attrs = qla2x00_host_attrs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | }; |
| 139 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 140 | struct scsi_host_template qla24xx_driver_template = { |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 141 | .module = THIS_MODULE, |
Andrew Vasquez | cb63067 | 2006-05-17 15:09:45 -0700 | [diff] [blame] | 142 | .name = QLA2XXX_DRIVER_NAME, |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 143 | .queuecommand = qla24xx_queuecommand, |
| 144 | |
| 145 | .eh_abort_handler = qla2xxx_eh_abort, |
| 146 | .eh_device_reset_handler = qla2xxx_eh_device_reset, |
| 147 | .eh_bus_reset_handler = qla2xxx_eh_bus_reset, |
| 148 | .eh_host_reset_handler = qla2xxx_eh_host_reset, |
| 149 | |
| 150 | .slave_configure = qla2xxx_slave_configure, |
| 151 | |
| 152 | .slave_alloc = qla2xxx_slave_alloc, |
| 153 | .slave_destroy = qla2xxx_slave_destroy, |
Andrew Vasquez | ed67708 | 2007-03-12 10:41:27 -0700 | [diff] [blame] | 154 | .scan_finished = qla2xxx_scan_finished, |
| 155 | .scan_start = qla2xxx_scan_start, |
Andrew Vasquez | ce7e4af | 2005-08-26 19:09:30 -0700 | [diff] [blame] | 156 | .change_queue_depth = qla2x00_change_queue_depth, |
| 157 | .change_queue_type = qla2x00_change_queue_type, |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 158 | .this_id = -1, |
| 159 | .cmd_per_lun = 3, |
| 160 | .use_clustering = ENABLE_CLUSTERING, |
| 161 | .sg_tablesize = SG_ALL, |
| 162 | |
| 163 | .max_sectors = 0xFFFF, |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 164 | .shost_attrs = qla2x00_host_attrs, |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 165 | }; |
| 166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | static struct scsi_transport_template *qla2xxx_transport_template = NULL; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 168 | struct scsi_transport_template *qla2xxx_transport_vport_template = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | /* TODO Convert to inlines |
| 171 | * |
| 172 | * Timer routines |
| 173 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 175 | __inline__ void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval) |
| 177 | { |
| 178 | init_timer(&ha->timer); |
| 179 | ha->timer.expires = jiffies + interval * HZ; |
| 180 | ha->timer.data = (unsigned long)ha; |
| 181 | ha->timer.function = (void (*)(unsigned long))func; |
| 182 | add_timer(&ha->timer); |
| 183 | ha->timer_active = 1; |
| 184 | } |
| 185 | |
| 186 | static inline void |
| 187 | qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval) |
| 188 | { |
| 189 | mod_timer(&ha->timer, jiffies + interval * HZ); |
| 190 | } |
| 191 | |
Adrian Bunk | a824ebb | 2008-01-17 09:02:15 -0800 | [diff] [blame] | 192 | static __inline__ void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | qla2x00_stop_timer(scsi_qla_host_t *ha) |
| 194 | { |
| 195 | del_timer_sync(&ha->timer); |
| 196 | ha->timer_active = 0; |
| 197 | } |
| 198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | static int qla2x00_do_dpc(void *data); |
| 200 | |
| 201 | static void qla2x00_rst_aen(scsi_qla_host_t *); |
| 202 | |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 203 | static int qla2x00_mem_alloc(scsi_qla_host_t *); |
Adrian Bunk | a824ebb | 2008-01-17 09:02:15 -0800 | [diff] [blame] | 204 | static void qla2x00_mem_free(scsi_qla_host_t *ha); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 205 | static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | /* -------------------------------------------------------------------------- */ |
| 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | static char * |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 210 | qla2x00_pci_info_str(struct scsi_qla_host *ha, char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | { |
| 212 | static char *pci_bus_modes[] = { |
| 213 | "33", "66", "100", "133", |
| 214 | }; |
| 215 | uint16_t pci_bus; |
| 216 | |
| 217 | strcpy(str, "PCI"); |
| 218 | pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9; |
| 219 | if (pci_bus) { |
| 220 | strcat(str, "-X ("); |
| 221 | strcat(str, pci_bus_modes[pci_bus]); |
| 222 | } else { |
| 223 | pci_bus = (ha->pci_attr & BIT_8) >> 8; |
| 224 | strcat(str, " ("); |
| 225 | strcat(str, pci_bus_modes[pci_bus]); |
| 226 | } |
| 227 | strcat(str, " MHz)"); |
| 228 | |
| 229 | return (str); |
| 230 | } |
| 231 | |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 232 | static char * |
| 233 | qla24xx_pci_info_str(struct scsi_qla_host *ha, char *str) |
| 234 | { |
| 235 | static char *pci_bus_modes[] = { "33", "66", "100", "133", }; |
| 236 | uint32_t pci_bus; |
| 237 | int pcie_reg; |
| 238 | |
| 239 | pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP); |
| 240 | if (pcie_reg) { |
| 241 | char lwstr[6]; |
| 242 | uint16_t pcie_lstat, lspeed, lwidth; |
| 243 | |
| 244 | pcie_reg += 0x12; |
| 245 | pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat); |
| 246 | lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3); |
| 247 | lwidth = (pcie_lstat & |
| 248 | (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4; |
| 249 | |
| 250 | strcpy(str, "PCIe ("); |
| 251 | if (lspeed == 1) |
Andrew Vasquez | c87a0d8 | 2008-04-03 13:13:21 -0700 | [diff] [blame^] | 252 | strcat(str, "2.5GT/s "); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 253 | else if (lspeed == 2) |
Andrew Vasquez | c87a0d8 | 2008-04-03 13:13:21 -0700 | [diff] [blame^] | 254 | strcat(str, "5.0GT/s "); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 255 | else |
| 256 | strcat(str, "<unknown> "); |
| 257 | snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth); |
| 258 | strcat(str, lwstr); |
| 259 | |
| 260 | return str; |
| 261 | } |
| 262 | |
| 263 | strcpy(str, "PCI"); |
| 264 | pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8; |
| 265 | if (pci_bus == 0 || pci_bus == 8) { |
| 266 | strcat(str, " ("); |
| 267 | strcat(str, pci_bus_modes[pci_bus >> 3]); |
| 268 | } else { |
| 269 | strcat(str, "-X "); |
| 270 | if (pci_bus & BIT_2) |
| 271 | strcat(str, "Mode 2"); |
| 272 | else |
| 273 | strcat(str, "Mode 1"); |
| 274 | strcat(str, " ("); |
| 275 | strcat(str, pci_bus_modes[pci_bus & ~BIT_2]); |
| 276 | } |
| 277 | strcat(str, " MHz)"); |
| 278 | |
| 279 | return str; |
| 280 | } |
| 281 | |
Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 282 | static char * |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 283 | qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | { |
| 285 | char un_str[10]; |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 286 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | sprintf(str, "%d.%02d.%02d ", ha->fw_major_version, |
| 288 | ha->fw_minor_version, |
| 289 | ha->fw_subminor_version); |
| 290 | |
| 291 | if (ha->fw_attributes & BIT_9) { |
| 292 | strcat(str, "FLX"); |
| 293 | return (str); |
| 294 | } |
| 295 | |
| 296 | switch (ha->fw_attributes & 0xFF) { |
| 297 | case 0x7: |
| 298 | strcat(str, "EF"); |
| 299 | break; |
| 300 | case 0x17: |
| 301 | strcat(str, "TP"); |
| 302 | break; |
| 303 | case 0x37: |
| 304 | strcat(str, "IP"); |
| 305 | break; |
| 306 | case 0x77: |
| 307 | strcat(str, "VI"); |
| 308 | break; |
| 309 | default: |
| 310 | sprintf(un_str, "(%x)", ha->fw_attributes); |
| 311 | strcat(str, un_str); |
| 312 | break; |
| 313 | } |
| 314 | if (ha->fw_attributes & 0x100) |
| 315 | strcat(str, "X"); |
| 316 | |
| 317 | return (str); |
| 318 | } |
| 319 | |
Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 320 | static char * |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 321 | qla24xx_fw_version_str(struct scsi_qla_host *ha, char *str) |
| 322 | { |
Andrew Vasquez | f0883ac | 2005-07-08 17:58:43 -0700 | [diff] [blame] | 323 | sprintf(str, "%d.%02d.%02d ", ha->fw_major_version, |
| 324 | ha->fw_minor_version, |
| 325 | ha->fw_subminor_version); |
| 326 | |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 327 | if (ha->fw_attributes & BIT_0) |
| 328 | strcat(str, "[Class 2] "); |
| 329 | if (ha->fw_attributes & BIT_1) |
| 330 | strcat(str, "[IP] "); |
| 331 | if (ha->fw_attributes & BIT_2) |
| 332 | strcat(str, "[Multi-ID] "); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 333 | if (ha->fw_attributes & BIT_3) |
| 334 | strcat(str, "[SB-2] "); |
| 335 | if (ha->fw_attributes & BIT_4) |
| 336 | strcat(str, "[T10 CRC] "); |
| 337 | if (ha->fw_attributes & BIT_5) |
| 338 | strcat(str, "[VI] "); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 339 | if (ha->fw_attributes & BIT_13) |
| 340 | strcat(str, "[Experimental]"); |
| 341 | return str; |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | static inline srb_t * |
| 345 | qla2x00_get_new_sp(scsi_qla_host_t *ha, fc_port_t *fcport, |
| 346 | struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) |
| 347 | { |
| 348 | srb_t *sp; |
| 349 | |
| 350 | sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC); |
| 351 | if (!sp) |
| 352 | return sp; |
| 353 | |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 354 | sp->ha = ha; |
| 355 | sp->fcport = fcport; |
| 356 | sp->cmd = cmd; |
| 357 | sp->flags = 0; |
| 358 | CMD_SP(cmd) = (void *)sp; |
| 359 | cmd->scsi_done = done; |
| 360 | |
| 361 | return sp; |
| 362 | } |
| 363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | static int |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 365 | qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | { |
Andrew Vasquez | f363b94 | 2007-09-20 14:07:45 -0700 | [diff] [blame] | 367 | scsi_qla_host_t *ha = shost_priv(cmd->device->host); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 368 | fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 369 | struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device)); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 370 | srb_t *sp; |
| 371 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 373 | if (unlikely(pci_channel_offline(ha->pdev))) { |
| 374 | cmd->result = DID_REQUEUE << 16; |
| 375 | goto qc_fail_command; |
| 376 | } |
| 377 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 378 | rval = fc_remote_port_chkready(rport); |
| 379 | if (rval) { |
| 380 | cmd->result = rval; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 381 | goto qc_fail_command; |
| 382 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
andrew.vasquez@qlogic.com | 387f96b | 2006-02-07 08:45:45 -0800 | [diff] [blame] | 384 | /* Close window on fcport/rport state-transitioning. */ |
| 385 | if (!*(fc_port_t **)rport->dd_data) { |
| 386 | cmd->result = DID_IMM_RETRY << 16; |
| 387 | goto qc_fail_command; |
| 388 | } |
| 389 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 390 | if (atomic_read(&fcport->state) != FCS_ONLINE) { |
| 391 | if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD || |
| 392 | atomic_read(&ha->loop_state) == LOOP_DEAD) { |
| 393 | cmd->result = DID_NO_CONNECT << 16; |
| 394 | goto qc_fail_command; |
| 395 | } |
| 396 | goto qc_host_busy; |
| 397 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
| 399 | spin_unlock_irq(ha->host->host_lock); |
| 400 | |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 401 | sp = qla2x00_get_new_sp(ha, fcport, cmd, done); |
| 402 | if (!sp) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 403 | goto qc_host_busy_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 405 | rval = qla2x00_start_scsi(sp); |
| 406 | if (rval != QLA_SUCCESS) |
| 407 | goto qc_host_busy_free_sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | spin_lock_irq(ha->host->host_lock); |
| 410 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 411 | return 0; |
| 412 | |
| 413 | qc_host_busy_free_sp: |
| 414 | qla2x00_sp_free_dma(ha, sp); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 415 | mempool_free(sp, ha->srb_mempool); |
| 416 | |
| 417 | qc_host_busy_lock: |
| 418 | spin_lock_irq(ha->host->host_lock); |
| 419 | |
| 420 | qc_host_busy: |
| 421 | return SCSI_MLQUEUE_HOST_BUSY; |
| 422 | |
| 423 | qc_fail_command: |
| 424 | done(cmd); |
| 425 | |
| 426 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | } |
| 428 | |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 429 | |
| 430 | static int |
| 431 | qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) |
| 432 | { |
Andrew Vasquez | f363b94 | 2007-09-20 14:07:45 -0700 | [diff] [blame] | 433 | scsi_qla_host_t *ha = shost_priv(cmd->device->host); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 434 | fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 435 | struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device)); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 436 | srb_t *sp; |
| 437 | int rval; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 438 | scsi_qla_host_t *pha = to_qla_parent(ha); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 439 | |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 440 | if (unlikely(pci_channel_offline(ha->pdev))) { |
| 441 | cmd->result = DID_REQUEUE << 16; |
| 442 | goto qc24_fail_command; |
| 443 | } |
| 444 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 445 | rval = fc_remote_port_chkready(rport); |
| 446 | if (rval) { |
| 447 | cmd->result = rval; |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 448 | goto qc24_fail_command; |
| 449 | } |
| 450 | |
andrew.vasquez@qlogic.com | 387f96b | 2006-02-07 08:45:45 -0800 | [diff] [blame] | 451 | /* Close window on fcport/rport state-transitioning. */ |
| 452 | if (!*(fc_port_t **)rport->dd_data) { |
| 453 | cmd->result = DID_IMM_RETRY << 16; |
| 454 | goto qc24_fail_command; |
| 455 | } |
| 456 | |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 457 | if (atomic_read(&fcport->state) != FCS_ONLINE) { |
| 458 | if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD || |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 459 | atomic_read(&pha->loop_state) == LOOP_DEAD) { |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 460 | cmd->result = DID_NO_CONNECT << 16; |
| 461 | goto qc24_fail_command; |
| 462 | } |
| 463 | goto qc24_host_busy; |
| 464 | } |
| 465 | |
| 466 | spin_unlock_irq(ha->host->host_lock); |
| 467 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 468 | sp = qla2x00_get_new_sp(pha, fcport, cmd, done); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 469 | if (!sp) |
| 470 | goto qc24_host_busy_lock; |
| 471 | |
| 472 | rval = qla24xx_start_scsi(sp); |
| 473 | if (rval != QLA_SUCCESS) |
| 474 | goto qc24_host_busy_free_sp; |
| 475 | |
| 476 | spin_lock_irq(ha->host->host_lock); |
| 477 | |
| 478 | return 0; |
| 479 | |
| 480 | qc24_host_busy_free_sp: |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 481 | qla2x00_sp_free_dma(pha, sp); |
| 482 | mempool_free(sp, pha->srb_mempool); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 483 | |
| 484 | qc24_host_busy_lock: |
| 485 | spin_lock_irq(ha->host->host_lock); |
| 486 | |
| 487 | qc24_host_busy: |
| 488 | return SCSI_MLQUEUE_HOST_BUSY; |
| 489 | |
| 490 | qc24_fail_command: |
| 491 | done(cmd); |
| 492 | |
| 493 | return 0; |
| 494 | } |
| 495 | |
| 496 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | /* |
| 498 | * qla2x00_eh_wait_on_command |
| 499 | * Waits for the command to be returned by the Firmware for some |
| 500 | * max time. |
| 501 | * |
| 502 | * Input: |
| 503 | * ha = actual ha whose done queue will contain the command |
| 504 | * returned by firmware. |
| 505 | * cmd = Scsi Command to wait on. |
| 506 | * flag = Abort/Reset(Bus or Device Reset) |
| 507 | * |
| 508 | * Return: |
| 509 | * Not Found : 0 |
| 510 | * Found : 1 |
| 511 | */ |
| 512 | static int |
| 513 | qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd) |
| 514 | { |
Andrew Vasquez | fe74c71 | 2005-08-26 19:10:10 -0700 | [diff] [blame] | 515 | #define ABORT_POLLING_PERIOD 1000 |
| 516 | #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD)) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 517 | unsigned long wait_iter = ABORT_WAIT_ITER; |
| 518 | int ret = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 520 | while (CMD_SP(cmd)) { |
Andrew Vasquez | fe74c71 | 2005-08-26 19:10:10 -0700 | [diff] [blame] | 521 | msleep(ABORT_POLLING_PERIOD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 523 | if (--wait_iter) |
| 524 | break; |
| 525 | } |
| 526 | if (CMD_SP(cmd)) |
| 527 | ret = QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 529 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | /* |
| 533 | * qla2x00_wait_for_hba_online |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 534 | * Wait till the HBA is online after going through |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | * <= MAX_RETRIES_OF_ISP_ABORT or |
| 536 | * finally HBA is disabled ie marked offline |
| 537 | * |
| 538 | * Input: |
| 539 | * ha - pointer to host adapter structure |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 540 | * |
| 541 | * Note: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | * Does context switching-Release SPIN_LOCK |
| 543 | * (if any) before calling this routine. |
| 544 | * |
| 545 | * Return: |
| 546 | * Success (Adapter is online) : 0 |
| 547 | * Failed (Adapter is offline/disabled) : 1 |
| 548 | */ |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 549 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | qla2x00_wait_for_hba_online(scsi_qla_host_t *ha) |
| 551 | { |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 552 | int return_status; |
| 553 | unsigned long wait_online; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 554 | scsi_qla_host_t *pha = to_qla_parent(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 556 | wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 557 | while (((test_bit(ISP_ABORT_NEEDED, &pha->dpc_flags)) || |
| 558 | test_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags) || |
| 559 | test_bit(ISP_ABORT_RETRY, &pha->dpc_flags) || |
| 560 | pha->dpc_active) && time_before(jiffies, wait_online)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | |
| 562 | msleep(1000); |
| 563 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 564 | if (pha->flags.online) |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 565 | return_status = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | else |
| 567 | return_status = QLA_FUNCTION_FAILED; |
| 568 | |
| 569 | DEBUG2(printk("%s return_status=%d\n",__func__,return_status)); |
| 570 | |
| 571 | return (return_status); |
| 572 | } |
| 573 | |
| 574 | /* |
| 575 | * qla2x00_wait_for_loop_ready |
| 576 | * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 577 | * to be in LOOP_READY state. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | * Input: |
| 579 | * ha - pointer to host adapter structure |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 580 | * |
| 581 | * Note: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | * Does context switching-Release SPIN_LOCK |
| 583 | * (if any) before calling this routine. |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 584 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | * |
| 586 | * Return: |
| 587 | * Success (LOOP_READY) : 0 |
| 588 | * Failed (LOOP_NOT_READY) : 1 |
| 589 | */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 590 | static inline int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha) |
| 592 | { |
| 593 | int return_status = QLA_SUCCESS; |
| 594 | unsigned long loop_timeout ; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 595 | scsi_qla_host_t *pha = to_qla_parent(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | |
| 597 | /* wait for 5 min at the max for loop to be ready */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 598 | loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 600 | while ((!atomic_read(&pha->loop_down_timer) && |
| 601 | atomic_read(&pha->loop_state) == LOOP_DOWN) || |
| 602 | atomic_read(&pha->loop_state) != LOOP_READY) { |
| 603 | if (atomic_read(&pha->loop_state) == LOOP_DEAD) { |
Ravi Anand | 5768008 | 2006-05-17 15:08:44 -0700 | [diff] [blame] | 604 | return_status = QLA_FUNCTION_FAILED; |
| 605 | break; |
| 606 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | msleep(1000); |
| 608 | if (time_after_eq(jiffies, loop_timeout)) { |
| 609 | return_status = QLA_FUNCTION_FAILED; |
| 610 | break; |
| 611 | } |
| 612 | } |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 613 | return (return_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Andrew Vasquez | 07db518 | 2006-10-02 12:00:49 -0700 | [diff] [blame] | 616 | static void |
| 617 | qla2x00_block_error_handler(struct scsi_cmnd *cmnd) |
| 618 | { |
| 619 | struct Scsi_Host *shost = cmnd->device->host; |
| 620 | struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); |
| 621 | unsigned long flags; |
| 622 | |
| 623 | spin_lock_irqsave(shost->host_lock, flags); |
| 624 | while (rport->port_state == FC_PORTSTATE_BLOCKED) { |
| 625 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 626 | msleep(1000); |
| 627 | spin_lock_irqsave(shost->host_lock, flags); |
| 628 | } |
| 629 | spin_unlock_irqrestore(shost->host_lock, flags); |
| 630 | return; |
| 631 | } |
| 632 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | /************************************************************************** |
| 634 | * qla2xxx_eh_abort |
| 635 | * |
| 636 | * Description: |
| 637 | * The abort function will abort the specified command. |
| 638 | * |
| 639 | * Input: |
| 640 | * cmd = Linux SCSI command packet to be aborted. |
| 641 | * |
| 642 | * Returns: |
| 643 | * Either SUCCESS or FAILED. |
| 644 | * |
| 645 | * Note: |
Michael Reed | 2ea0020 | 2006-04-27 16:25:30 -0700 | [diff] [blame] | 646 | * Only return FAILED if command not returned by firmware. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | **************************************************************************/ |
Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 648 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | qla2xxx_eh_abort(struct scsi_cmnd *cmd) |
| 650 | { |
Andrew Vasquez | f363b94 | 2007-09-20 14:07:45 -0700 | [diff] [blame] | 651 | scsi_qla_host_t *ha = shost_priv(cmd->device->host); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 652 | srb_t *sp; |
| 653 | int ret, i; |
| 654 | unsigned int id, lun; |
| 655 | unsigned long serial; |
Andrew Vasquez | 18e144d | 2005-05-27 15:04:47 -0700 | [diff] [blame] | 656 | unsigned long flags; |
Michael Reed | 2ea0020 | 2006-04-27 16:25:30 -0700 | [diff] [blame] | 657 | int wait = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 658 | scsi_qla_host_t *pha = to_qla_parent(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
Andrew Vasquez | 07db518 | 2006-10-02 12:00:49 -0700 | [diff] [blame] | 660 | qla2x00_block_error_handler(cmd); |
| 661 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 662 | if (!CMD_SP(cmd)) |
Michael Reed | 2ea0020 | 2006-04-27 16:25:30 -0700 | [diff] [blame] | 663 | return SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | |
Michael Reed | 2ea0020 | 2006-04-27 16:25:30 -0700 | [diff] [blame] | 665 | ret = SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 667 | id = cmd->device->id; |
| 668 | lun = cmd->device->lun; |
| 669 | serial = cmd->serial_number; |
| 670 | |
| 671 | /* Check active list for command command. */ |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 672 | spin_lock_irqsave(&pha->hardware_lock, flags); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 673 | for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 674 | sp = pha->outstanding_cmds[i]; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 675 | |
| 676 | if (sp == NULL) |
| 677 | continue; |
| 678 | |
| 679 | if (sp->cmd != cmd) |
| 680 | continue; |
| 681 | |
Andrew Vasquez | 75bc419 | 2006-05-17 15:09:22 -0700 | [diff] [blame] | 682 | DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld.\n", |
| 683 | __func__, ha->host_no, sp, serial)); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 684 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 685 | spin_unlock_irqrestore(&pha->hardware_lock, flags); |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 686 | if (ha->isp_ops->abort_command(ha, sp)) { |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 687 | DEBUG2(printk("%s(%ld): abort_command " |
| 688 | "mbx failed.\n", __func__, ha->host_no)); |
| 689 | } else { |
| 690 | DEBUG3(printk("%s(%ld): abort_command " |
| 691 | "mbx success.\n", __func__, ha->host_no)); |
Michael Reed | 2ea0020 | 2006-04-27 16:25:30 -0700 | [diff] [blame] | 692 | wait = 1; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 693 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 694 | spin_lock_irqsave(&pha->hardware_lock, flags); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 695 | |
| 696 | break; |
| 697 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 698 | spin_unlock_irqrestore(&pha->hardware_lock, flags); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 699 | |
| 700 | /* Wait for the command to be returned. */ |
Michael Reed | 2ea0020 | 2006-04-27 16:25:30 -0700 | [diff] [blame] | 701 | if (wait) { |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 702 | if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) { |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 703 | qla_printk(KERN_ERR, ha, |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 704 | "scsi(%ld:%d:%d): Abort handler timed out -- %lx " |
| 705 | "%x.\n", ha->host_no, id, lun, serial, ret); |
Michael Reed | 2ea0020 | 2006-04-27 16:25:30 -0700 | [diff] [blame] | 706 | ret = FAILED; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 707 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 710 | qla_printk(KERN_INFO, ha, |
Michael Reed | 2ea0020 | 2006-04-27 16:25:30 -0700 | [diff] [blame] | 711 | "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n", |
| 712 | ha->host_no, id, lun, wait, serial, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 714 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | /************************************************************************** |
| 718 | * qla2x00_eh_wait_for_pending_target_commands |
| 719 | * |
| 720 | * Description: |
| 721 | * Waits for all the commands to come back from the specified target. |
| 722 | * |
| 723 | * Input: |
| 724 | * ha - pointer to scsi_qla_host structure. |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 725 | * t - target |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | * Returns: |
| 727 | * Either SUCCESS or FAILED. |
| 728 | * |
| 729 | * Note: |
| 730 | **************************************************************************/ |
| 731 | static int |
| 732 | qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t) |
| 733 | { |
| 734 | int cnt; |
| 735 | int status; |
| 736 | srb_t *sp; |
| 737 | struct scsi_cmnd *cmd; |
Andrew Vasquez | 18e144d | 2005-05-27 15:04:47 -0700 | [diff] [blame] | 738 | unsigned long flags; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 739 | scsi_qla_host_t *pha = to_qla_parent(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | |
| 741 | status = 0; |
| 742 | |
| 743 | /* |
| 744 | * Waiting for all commands for the designated target in the active |
| 745 | * array |
| 746 | */ |
| 747 | for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 748 | spin_lock_irqsave(&pha->hardware_lock, flags); |
| 749 | sp = pha->outstanding_cmds[cnt]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | if (sp) { |
| 751 | cmd = sp->cmd; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 752 | spin_unlock_irqrestore(&pha->hardware_lock, flags); |
| 753 | if (cmd->device->id == t && |
| 754 | ha->vp_idx == sp->ha->vp_idx) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | if (!qla2x00_eh_wait_on_command(ha, cmd)) { |
| 756 | status = 1; |
| 757 | break; |
| 758 | } |
| 759 | } |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 760 | } else { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 761 | spin_unlock_irqrestore(&pha->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | } |
| 763 | } |
| 764 | return (status); |
| 765 | } |
| 766 | |
| 767 | |
| 768 | /************************************************************************** |
| 769 | * qla2xxx_eh_device_reset |
| 770 | * |
| 771 | * Description: |
| 772 | * The device reset function will reset the target and abort any |
| 773 | * executing commands. |
| 774 | * |
| 775 | * NOTE: The use of SP is undefined within this context. Do *NOT* |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 776 | * attempt to use this value, even if you determine it is |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | * non-null. |
| 778 | * |
| 779 | * Input: |
| 780 | * cmd = Linux SCSI command packet of the command that cause the |
| 781 | * bus device reset. |
| 782 | * |
| 783 | * Returns: |
| 784 | * SUCCESS/FAILURE (defined as macro in scsi.h). |
| 785 | * |
| 786 | **************************************************************************/ |
Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 787 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | qla2xxx_eh_device_reset(struct scsi_cmnd *cmd) |
| 789 | { |
Andrew Vasquez | f363b94 | 2007-09-20 14:07:45 -0700 | [diff] [blame] | 790 | scsi_qla_host_t *ha = shost_priv(cmd->device->host); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 791 | fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 792 | int ret = FAILED; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 793 | unsigned int id, lun; |
| 794 | unsigned long serial; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
Andrew Vasquez | 07db518 | 2006-10-02 12:00:49 -0700 | [diff] [blame] | 796 | qla2x00_block_error_handler(cmd); |
| 797 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 798 | id = cmd->device->id; |
| 799 | lun = cmd->device->lun; |
| 800 | serial = cmd->serial_number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | |
Vladislav Bolkhovitin | b0328be | 2006-08-01 13:48:15 -0700 | [diff] [blame] | 802 | if (!fcport) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 803 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | |
| 805 | qla_printk(KERN_INFO, ha, |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 806 | "scsi(%ld:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, id, lun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | |
Jeff Garzik | 94d0e7b8 | 2005-05-28 07:55:48 -0400 | [diff] [blame] | 808 | if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | goto eh_dev_reset_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | |
| 811 | if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) { |
Andrew Vasquez | 587f4ca | 2008-04-03 13:13:20 -0700 | [diff] [blame] | 812 | if (ha->isp_ops->abort_target(fcport) == 0) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 813 | ret = SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | } else { |
| 815 | DEBUG2(printk(KERN_INFO |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 816 | "%s failed: loop not ready\n",__func__)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | } |
| 818 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 819 | if (ret == FAILED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | DEBUG3(printk("%s(%ld): device reset failed\n", |
| 821 | __func__, ha->host_no)); |
| 822 | qla_printk(KERN_INFO, ha, "%s: device reset failed\n", |
| 823 | __func__); |
| 824 | |
| 825 | goto eh_dev_reset_done; |
| 826 | } |
| 827 | |
Andrew Vasquez | 9a41a62 | 2005-09-20 13:25:53 -0700 | [diff] [blame] | 828 | /* Flush outstanding commands. */ |
| 829 | if (qla2x00_eh_wait_for_pending_target_commands(ha, id)) |
| 830 | ret = FAILED; |
| 831 | if (ret == FAILED) { |
| 832 | DEBUG3(printk("%s(%ld): failed while waiting for commands\n", |
| 833 | __func__, ha->host_no)); |
| 834 | qla_printk(KERN_INFO, ha, |
| 835 | "%s: failed while waiting for commands\n", __func__); |
| 836 | } else |
| 837 | qla_printk(KERN_INFO, ha, |
| 838 | "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha->host_no, |
| 839 | id, lun); |
James Bottomley | 28f22b0 | 2005-10-28 17:22:18 -0500 | [diff] [blame] | 840 | eh_dev_reset_done: |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 841 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | /************************************************************************** |
| 845 | * qla2x00_eh_wait_for_pending_commands |
| 846 | * |
| 847 | * Description: |
| 848 | * Waits for all the commands to come back from the specified host. |
| 849 | * |
| 850 | * Input: |
| 851 | * ha - pointer to scsi_qla_host structure. |
| 852 | * |
| 853 | * Returns: |
| 854 | * 1 : SUCCESS |
| 855 | * 0 : FAILED |
| 856 | * |
| 857 | * Note: |
| 858 | **************************************************************************/ |
| 859 | static int |
| 860 | qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha) |
| 861 | { |
| 862 | int cnt; |
| 863 | int status; |
| 864 | srb_t *sp; |
| 865 | struct scsi_cmnd *cmd; |
Andrew Vasquez | 18e144d | 2005-05-27 15:04:47 -0700 | [diff] [blame] | 866 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | |
| 868 | status = 1; |
| 869 | |
| 870 | /* |
| 871 | * Waiting for all commands for the designated target in the active |
| 872 | * array |
| 873 | */ |
| 874 | for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { |
Andrew Vasquez | 18e144d | 2005-05-27 15:04:47 -0700 | [diff] [blame] | 875 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | sp = ha->outstanding_cmds[cnt]; |
| 877 | if (sp) { |
| 878 | cmd = sp->cmd; |
Andrew Vasquez | 18e144d | 2005-05-27 15:04:47 -0700 | [diff] [blame] | 879 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | status = qla2x00_eh_wait_on_command(ha, cmd); |
| 881 | if (status == 0) |
| 882 | break; |
| 883 | } |
| 884 | else { |
Andrew Vasquez | 18e144d | 2005-05-27 15:04:47 -0700 | [diff] [blame] | 885 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | } |
| 887 | } |
| 888 | return (status); |
| 889 | } |
| 890 | |
| 891 | |
| 892 | /************************************************************************** |
| 893 | * qla2xxx_eh_bus_reset |
| 894 | * |
| 895 | * Description: |
| 896 | * The bus reset function will reset the bus and abort any executing |
| 897 | * commands. |
| 898 | * |
| 899 | * Input: |
| 900 | * cmd = Linux SCSI command packet of the command that cause the |
| 901 | * bus reset. |
| 902 | * |
| 903 | * Returns: |
| 904 | * SUCCESS/FAILURE (defined as macro in scsi.h). |
| 905 | * |
| 906 | **************************************************************************/ |
Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 907 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd) |
| 909 | { |
Andrew Vasquez | f363b94 | 2007-09-20 14:07:45 -0700 | [diff] [blame] | 910 | scsi_qla_host_t *ha = shost_priv(cmd->device->host); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 911 | scsi_qla_host_t *pha = to_qla_parent(ha); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 912 | fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 913 | int ret = FAILED; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 914 | unsigned int id, lun; |
| 915 | unsigned long serial; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | |
Andrew Vasquez | 07db518 | 2006-10-02 12:00:49 -0700 | [diff] [blame] | 917 | qla2x00_block_error_handler(cmd); |
| 918 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 919 | id = cmd->device->id; |
| 920 | lun = cmd->device->lun; |
| 921 | serial = cmd->serial_number; |
| 922 | |
Vladislav Bolkhovitin | b0328be | 2006-08-01 13:48:15 -0700 | [diff] [blame] | 923 | if (!fcport) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 924 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
| 926 | qla_printk(KERN_INFO, ha, |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 927 | "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) { |
| 930 | DEBUG2(printk("%s failed:board disabled\n",__func__)); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 931 | goto eh_bus_reset_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) { |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 935 | if (qla2x00_loop_reset(ha) == QLA_SUCCESS) |
| 936 | ret = SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | } |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 938 | if (ret == FAILED) |
| 939 | goto eh_bus_reset_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | |
Andrew Vasquez | 9a41a62 | 2005-09-20 13:25:53 -0700 | [diff] [blame] | 941 | /* Flush outstanding commands. */ |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 942 | if (!qla2x00_eh_wait_for_pending_commands(pha)) |
Andrew Vasquez | 9a41a62 | 2005-09-20 13:25:53 -0700 | [diff] [blame] | 943 | ret = FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 945 | eh_bus_reset_done: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__, |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 947 | (ret == FAILED) ? "failed" : "succeded"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 949 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | /************************************************************************** |
| 953 | * qla2xxx_eh_host_reset |
| 954 | * |
| 955 | * Description: |
| 956 | * The reset function will reset the Adapter. |
| 957 | * |
| 958 | * Input: |
| 959 | * cmd = Linux SCSI command packet of the command that cause the |
| 960 | * adapter reset. |
| 961 | * |
| 962 | * Returns: |
| 963 | * Either SUCCESS or FAILED. |
| 964 | * |
| 965 | * Note: |
| 966 | **************************************************************************/ |
Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 967 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | qla2xxx_eh_host_reset(struct scsi_cmnd *cmd) |
| 969 | { |
Andrew Vasquez | f363b94 | 2007-09-20 14:07:45 -0700 | [diff] [blame] | 970 | scsi_qla_host_t *ha = shost_priv(cmd->device->host); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 971 | fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 972 | int ret = FAILED; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 973 | unsigned int id, lun; |
| 974 | unsigned long serial; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 975 | scsi_qla_host_t *pha = to_qla_parent(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | |
Andrew Vasquez | 07db518 | 2006-10-02 12:00:49 -0700 | [diff] [blame] | 977 | qla2x00_block_error_handler(cmd); |
| 978 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 979 | id = cmd->device->id; |
| 980 | lun = cmd->device->lun; |
| 981 | serial = cmd->serial_number; |
| 982 | |
Vladislav Bolkhovitin | b0328be | 2006-08-01 13:48:15 -0700 | [diff] [blame] | 983 | if (!fcport) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 984 | return ret; |
| 985 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | qla_printk(KERN_INFO, ha, |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 987 | "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 990 | goto eh_host_reset_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | |
| 992 | /* |
| 993 | * Fixme-may be dpc thread is active and processing |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 994 | * loop_resync,so wait a while for it to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | * be completed and then issue big hammer.Otherwise |
| 996 | * it may cause I/O failure as big hammer marks the |
| 997 | * devices as lost kicking of the port_down_timer |
| 998 | * while dpc is stuck for the mailbox to complete. |
| 999 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | qla2x00_wait_for_loop_ready(ha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1001 | set_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags); |
| 1002 | if (qla2x00_abort_isp(pha)) { |
| 1003 | clear_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | /* failed. schedule dpc to try */ |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1005 | set_bit(ISP_ABORT_NEEDED, &pha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | |
| 1007 | if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1008 | goto eh_host_reset_lock; |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1009 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1010 | clear_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | /* Waiting for our command in done_queue to be returned to OS.*/ |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1013 | if (qla2x00_eh_wait_for_pending_commands(pha)) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1014 | ret = SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1016 | if (ha->parent) |
| 1017 | qla2x00_vp_abort_isp(ha); |
| 1018 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1019 | eh_host_reset_lock: |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1020 | qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__, |
| 1021 | (ret == FAILED) ? "failed" : "succeded"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1023 | return ret; |
| 1024 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | |
| 1026 | /* |
| 1027 | * qla2x00_loop_reset |
| 1028 | * Issue loop reset. |
| 1029 | * |
| 1030 | * Input: |
| 1031 | * ha = adapter block pointer. |
| 1032 | * |
| 1033 | * Returns: |
| 1034 | * 0 = success |
| 1035 | */ |
Andrew Vasquez | a4722cf | 2008-01-17 09:02:12 -0800 | [diff] [blame] | 1036 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | qla2x00_loop_reset(scsi_qla_host_t *ha) |
| 1038 | { |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 1039 | int ret; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1040 | struct fc_port *fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 1042 | if (ha->flags.enable_lip_full_login) { |
| 1043 | ret = qla2x00_full_login_lip(ha); |
| 1044 | if (ret != QLA_SUCCESS) { |
| 1045 | DEBUG2_3(printk("%s(%ld): bus_reset failed: " |
| 1046 | "full_login_lip=%d.\n", __func__, ha->host_no, |
| 1047 | ret)); |
| 1048 | } |
| 1049 | atomic_set(&ha->loop_state, LOOP_DOWN); |
| 1050 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
| 1051 | qla2x00_mark_all_devices_lost(ha, 0); |
| 1052 | qla2x00_wait_for_loop_ready(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | } |
| 1054 | |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 1055 | if (ha->flags.enable_lip_reset) { |
| 1056 | ret = qla2x00_lip_reset(ha); |
| 1057 | if (ret != QLA_SUCCESS) { |
| 1058 | DEBUG2_3(printk("%s(%ld): bus_reset failed: " |
| 1059 | "lip_reset=%d.\n", __func__, ha->host_no, ret)); |
| 1060 | } |
| 1061 | qla2x00_wait_for_loop_ready(ha); |
| 1062 | } |
| 1063 | |
| 1064 | if (ha->flags.enable_target_reset) { |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1065 | list_for_each_entry(fcport, &ha->fcports, list) { |
| 1066 | if (fcport->port_type != FCT_TARGET) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | continue; |
| 1068 | |
Andrew Vasquez | 587f4ca | 2008-04-03 13:13:20 -0700 | [diff] [blame] | 1069 | ret = ha->isp_ops->abort_target(fcport); |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 1070 | if (ret != QLA_SUCCESS) { |
| 1071 | DEBUG2_3(printk("%s(%ld): bus_reset failed: " |
| 1072 | "target_reset=%d d_id=%x.\n", __func__, |
| 1073 | ha->host_no, ret, fcport->d_id.b24)); |
| 1074 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | } |
| 1076 | } |
| 1077 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | /* Issue marker command only when we are going to start the I/O */ |
| 1079 | ha->marker_needed = 1; |
| 1080 | |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 1081 | return QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | } |
| 1083 | |
Andrew Vasquez | df4bf0b | 2008-01-31 12:33:46 -0800 | [diff] [blame] | 1084 | void |
| 1085 | qla2x00_abort_all_cmds(scsi_qla_host_t *ha, int res) |
| 1086 | { |
| 1087 | int cnt; |
| 1088 | unsigned long flags; |
| 1089 | srb_t *sp; |
| 1090 | |
| 1091 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1092 | for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { |
| 1093 | sp = ha->outstanding_cmds[cnt]; |
| 1094 | if (sp) { |
| 1095 | ha->outstanding_cmds[cnt] = NULL; |
| 1096 | sp->flags = 0; |
| 1097 | sp->cmd->result = res; |
| 1098 | sp->cmd->host_scribble = (unsigned char *)NULL; |
| 1099 | qla2x00_sp_compl(ha, sp); |
| 1100 | } |
| 1101 | } |
| 1102 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1103 | } |
| 1104 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1105 | static int |
| 1106 | qla2xxx_slave_alloc(struct scsi_device *sdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | { |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1108 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1110 | if (!rport || fc_remote_port_chkready(rport)) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1111 | return -ENXIO; |
| 1112 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1113 | sdev->hostdata = *(fc_port_t **)rport->dd_data; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1114 | |
| 1115 | return 0; |
| 1116 | } |
| 1117 | |
| 1118 | static int |
| 1119 | qla2xxx_slave_configure(struct scsi_device *sdev) |
| 1120 | { |
Andrew Vasquez | f363b94 | 2007-09-20 14:07:45 -0700 | [diff] [blame] | 1121 | scsi_qla_host_t *ha = shost_priv(sdev->host); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1122 | struct fc_rport *rport = starget_to_rport(sdev->sdev_target); |
| 1123 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1124 | if (sdev->tagged_supported) |
Andrew Vasquez | df7baa5 | 2006-10-13 09:33:39 -0700 | [diff] [blame] | 1125 | scsi_activate_tcq(sdev, ha->max_q_depth); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | else |
Andrew Vasquez | df7baa5 | 2006-10-13 09:33:39 -0700 | [diff] [blame] | 1127 | scsi_deactivate_tcq(sdev, ha->max_q_depth); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1129 | rport->dev_loss_tmo = ha->port_down_retry_count + 5; |
| 1130 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1131 | return 0; |
| 1132 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1134 | static void |
| 1135 | qla2xxx_slave_destroy(struct scsi_device *sdev) |
| 1136 | { |
| 1137 | sdev->hostdata = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | } |
| 1139 | |
Andrew Vasquez | ce7e4af | 2005-08-26 19:09:30 -0700 | [diff] [blame] | 1140 | static int |
| 1141 | qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth) |
| 1142 | { |
| 1143 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); |
| 1144 | return sdev->queue_depth; |
| 1145 | } |
| 1146 | |
| 1147 | static int |
| 1148 | qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type) |
| 1149 | { |
| 1150 | if (sdev->tagged_supported) { |
| 1151 | scsi_set_tag_type(sdev, tag_type); |
| 1152 | if (tag_type) |
| 1153 | scsi_activate_tcq(sdev, sdev->queue_depth); |
| 1154 | else |
| 1155 | scsi_deactivate_tcq(sdev, sdev->queue_depth); |
| 1156 | } else |
| 1157 | tag_type = 0; |
| 1158 | |
| 1159 | return tag_type; |
| 1160 | } |
| 1161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | /** |
| 1163 | * qla2x00_config_dma_addressing() - Configure OS DMA addressing method. |
| 1164 | * @ha: HA context |
| 1165 | * |
| 1166 | * At exit, the @ha's flags.enable_64bit_addressing set to indicated |
| 1167 | * supported addressing method. |
| 1168 | */ |
| 1169 | static void |
| 1170 | qla2x00_config_dma_addressing(scsi_qla_host_t *ha) |
| 1171 | { |
Andrew Vasquez | 7524f9b | 2005-08-26 19:08:00 -0700 | [diff] [blame] | 1172 | /* Assume a 32bit DMA mask. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | ha->flags.enable_64bit_addressing = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | |
Andrew Vasquez | 7524f9b | 2005-08-26 19:08:00 -0700 | [diff] [blame] | 1175 | if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) { |
| 1176 | /* Any upper-dword bits set? */ |
| 1177 | if (MSD(dma_get_required_mask(&ha->pdev->dev)) && |
| 1178 | !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) { |
| 1179 | /* Ok, a 64bit DMA mask is applicable. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | ha->flags.enable_64bit_addressing = 1; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1181 | ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64; |
| 1182 | ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64; |
Andrew Vasquez | 7524f9b | 2005-08-26 19:08:00 -0700 | [diff] [blame] | 1183 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | } |
Andrew Vasquez | 7524f9b | 2005-08-26 19:08:00 -0700 | [diff] [blame] | 1186 | |
| 1187 | dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK); |
| 1188 | pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | } |
| 1190 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1191 | static void |
| 1192 | qla2x00_enable_intrs(scsi_qla_host_t *ha) |
| 1193 | { |
| 1194 | unsigned long flags = 0; |
| 1195 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 1196 | |
| 1197 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1198 | ha->interrupts_on = 1; |
| 1199 | /* enable risc and host interrupts */ |
| 1200 | WRT_REG_WORD(®->ictrl, ICR_EN_INT | ICR_EN_RISC); |
| 1201 | RD_REG_WORD(®->ictrl); |
| 1202 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1203 | |
| 1204 | } |
| 1205 | |
| 1206 | static void |
| 1207 | qla2x00_disable_intrs(scsi_qla_host_t *ha) |
| 1208 | { |
| 1209 | unsigned long flags = 0; |
| 1210 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 1211 | |
| 1212 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1213 | ha->interrupts_on = 0; |
| 1214 | /* disable risc and host interrupts */ |
| 1215 | WRT_REG_WORD(®->ictrl, 0); |
| 1216 | RD_REG_WORD(®->ictrl); |
| 1217 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1218 | } |
| 1219 | |
| 1220 | static void |
| 1221 | qla24xx_enable_intrs(scsi_qla_host_t *ha) |
| 1222 | { |
| 1223 | unsigned long flags = 0; |
| 1224 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 1225 | |
| 1226 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1227 | ha->interrupts_on = 1; |
| 1228 | WRT_REG_DWORD(®->ictrl, ICRX_EN_RISC_INT); |
| 1229 | RD_REG_DWORD(®->ictrl); |
| 1230 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1231 | } |
| 1232 | |
| 1233 | static void |
| 1234 | qla24xx_disable_intrs(scsi_qla_host_t *ha) |
| 1235 | { |
| 1236 | unsigned long flags = 0; |
| 1237 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 1238 | |
| 1239 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1240 | ha->interrupts_on = 0; |
| 1241 | WRT_REG_DWORD(®->ictrl, 0); |
| 1242 | RD_REG_DWORD(®->ictrl); |
| 1243 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1244 | } |
| 1245 | |
| 1246 | static struct isp_operations qla2100_isp_ops = { |
| 1247 | .pci_config = qla2100_pci_config, |
| 1248 | .reset_chip = qla2x00_reset_chip, |
| 1249 | .chip_diag = qla2x00_chip_diag, |
| 1250 | .config_rings = qla2x00_config_rings, |
| 1251 | .reset_adapter = qla2x00_reset_adapter, |
| 1252 | .nvram_config = qla2x00_nvram_config, |
| 1253 | .update_fw_options = qla2x00_update_fw_options, |
| 1254 | .load_risc = qla2x00_load_risc, |
| 1255 | .pci_info_str = qla2x00_pci_info_str, |
| 1256 | .fw_version_str = qla2x00_fw_version_str, |
| 1257 | .intr_handler = qla2100_intr_handler, |
| 1258 | .enable_intrs = qla2x00_enable_intrs, |
| 1259 | .disable_intrs = qla2x00_disable_intrs, |
| 1260 | .abort_command = qla2x00_abort_command, |
| 1261 | .abort_target = qla2x00_abort_target, |
| 1262 | .fabric_login = qla2x00_login_fabric, |
| 1263 | .fabric_logout = qla2x00_fabric_logout, |
| 1264 | .calc_req_entries = qla2x00_calc_iocbs_32, |
| 1265 | .build_iocbs = qla2x00_build_scsi_iocbs_32, |
| 1266 | .prep_ms_iocb = qla2x00_prep_ms_iocb, |
| 1267 | .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb, |
| 1268 | .read_nvram = qla2x00_read_nvram_data, |
| 1269 | .write_nvram = qla2x00_write_nvram_data, |
| 1270 | .fw_dump = qla2100_fw_dump, |
| 1271 | .beacon_on = NULL, |
| 1272 | .beacon_off = NULL, |
| 1273 | .beacon_blink = NULL, |
| 1274 | .read_optrom = qla2x00_read_optrom_data, |
| 1275 | .write_optrom = qla2x00_write_optrom_data, |
| 1276 | .get_flash_version = qla2x00_get_flash_version, |
| 1277 | }; |
| 1278 | |
| 1279 | static struct isp_operations qla2300_isp_ops = { |
| 1280 | .pci_config = qla2300_pci_config, |
| 1281 | .reset_chip = qla2x00_reset_chip, |
| 1282 | .chip_diag = qla2x00_chip_diag, |
| 1283 | .config_rings = qla2x00_config_rings, |
| 1284 | .reset_adapter = qla2x00_reset_adapter, |
| 1285 | .nvram_config = qla2x00_nvram_config, |
| 1286 | .update_fw_options = qla2x00_update_fw_options, |
| 1287 | .load_risc = qla2x00_load_risc, |
| 1288 | .pci_info_str = qla2x00_pci_info_str, |
| 1289 | .fw_version_str = qla2x00_fw_version_str, |
| 1290 | .intr_handler = qla2300_intr_handler, |
| 1291 | .enable_intrs = qla2x00_enable_intrs, |
| 1292 | .disable_intrs = qla2x00_disable_intrs, |
| 1293 | .abort_command = qla2x00_abort_command, |
| 1294 | .abort_target = qla2x00_abort_target, |
| 1295 | .fabric_login = qla2x00_login_fabric, |
| 1296 | .fabric_logout = qla2x00_fabric_logout, |
| 1297 | .calc_req_entries = qla2x00_calc_iocbs_32, |
| 1298 | .build_iocbs = qla2x00_build_scsi_iocbs_32, |
| 1299 | .prep_ms_iocb = qla2x00_prep_ms_iocb, |
| 1300 | .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb, |
| 1301 | .read_nvram = qla2x00_read_nvram_data, |
| 1302 | .write_nvram = qla2x00_write_nvram_data, |
| 1303 | .fw_dump = qla2300_fw_dump, |
| 1304 | .beacon_on = qla2x00_beacon_on, |
| 1305 | .beacon_off = qla2x00_beacon_off, |
| 1306 | .beacon_blink = qla2x00_beacon_blink, |
| 1307 | .read_optrom = qla2x00_read_optrom_data, |
| 1308 | .write_optrom = qla2x00_write_optrom_data, |
| 1309 | .get_flash_version = qla2x00_get_flash_version, |
| 1310 | }; |
| 1311 | |
| 1312 | static struct isp_operations qla24xx_isp_ops = { |
| 1313 | .pci_config = qla24xx_pci_config, |
| 1314 | .reset_chip = qla24xx_reset_chip, |
| 1315 | .chip_diag = qla24xx_chip_diag, |
| 1316 | .config_rings = qla24xx_config_rings, |
| 1317 | .reset_adapter = qla24xx_reset_adapter, |
| 1318 | .nvram_config = qla24xx_nvram_config, |
| 1319 | .update_fw_options = qla24xx_update_fw_options, |
| 1320 | .load_risc = qla24xx_load_risc, |
| 1321 | .pci_info_str = qla24xx_pci_info_str, |
| 1322 | .fw_version_str = qla24xx_fw_version_str, |
| 1323 | .intr_handler = qla24xx_intr_handler, |
| 1324 | .enable_intrs = qla24xx_enable_intrs, |
| 1325 | .disable_intrs = qla24xx_disable_intrs, |
| 1326 | .abort_command = qla24xx_abort_command, |
| 1327 | .abort_target = qla24xx_abort_target, |
| 1328 | .fabric_login = qla24xx_login_fabric, |
| 1329 | .fabric_logout = qla24xx_fabric_logout, |
| 1330 | .calc_req_entries = NULL, |
| 1331 | .build_iocbs = NULL, |
| 1332 | .prep_ms_iocb = qla24xx_prep_ms_iocb, |
| 1333 | .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb, |
| 1334 | .read_nvram = qla24xx_read_nvram_data, |
| 1335 | .write_nvram = qla24xx_write_nvram_data, |
| 1336 | .fw_dump = qla24xx_fw_dump, |
| 1337 | .beacon_on = qla24xx_beacon_on, |
| 1338 | .beacon_off = qla24xx_beacon_off, |
| 1339 | .beacon_blink = qla24xx_beacon_blink, |
| 1340 | .read_optrom = qla24xx_read_optrom_data, |
| 1341 | .write_optrom = qla24xx_write_optrom_data, |
| 1342 | .get_flash_version = qla24xx_get_flash_version, |
| 1343 | }; |
| 1344 | |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1345 | static struct isp_operations qla25xx_isp_ops = { |
| 1346 | .pci_config = qla25xx_pci_config, |
| 1347 | .reset_chip = qla24xx_reset_chip, |
| 1348 | .chip_diag = qla24xx_chip_diag, |
| 1349 | .config_rings = qla24xx_config_rings, |
| 1350 | .reset_adapter = qla24xx_reset_adapter, |
| 1351 | .nvram_config = qla24xx_nvram_config, |
| 1352 | .update_fw_options = qla24xx_update_fw_options, |
| 1353 | .load_risc = qla24xx_load_risc, |
| 1354 | .pci_info_str = qla24xx_pci_info_str, |
| 1355 | .fw_version_str = qla24xx_fw_version_str, |
| 1356 | .intr_handler = qla24xx_intr_handler, |
| 1357 | .enable_intrs = qla24xx_enable_intrs, |
| 1358 | .disable_intrs = qla24xx_disable_intrs, |
| 1359 | .abort_command = qla24xx_abort_command, |
| 1360 | .abort_target = qla24xx_abort_target, |
| 1361 | .fabric_login = qla24xx_login_fabric, |
| 1362 | .fabric_logout = qla24xx_fabric_logout, |
| 1363 | .calc_req_entries = NULL, |
| 1364 | .build_iocbs = NULL, |
| 1365 | .prep_ms_iocb = qla24xx_prep_ms_iocb, |
| 1366 | .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb, |
| 1367 | .read_nvram = qla25xx_read_nvram_data, |
| 1368 | .write_nvram = qla25xx_write_nvram_data, |
| 1369 | .fw_dump = qla25xx_fw_dump, |
| 1370 | .beacon_on = qla24xx_beacon_on, |
| 1371 | .beacon_off = qla24xx_beacon_off, |
| 1372 | .beacon_blink = qla24xx_beacon_blink, |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1373 | .read_optrom = qla25xx_read_optrom_data, |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1374 | .write_optrom = qla24xx_write_optrom_data, |
| 1375 | .get_flash_version = qla24xx_get_flash_version, |
| 1376 | }; |
| 1377 | |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1378 | static inline void |
| 1379 | qla2x00_set_isp_flags(scsi_qla_host_t *ha) |
| 1380 | { |
| 1381 | ha->device_type = DT_EXTENDED_IDS; |
| 1382 | switch (ha->pdev->device) { |
| 1383 | case PCI_DEVICE_ID_QLOGIC_ISP2100: |
| 1384 | ha->device_type |= DT_ISP2100; |
| 1385 | ha->device_type &= ~DT_EXTENDED_IDS; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1386 | ha->fw_srisc_address = RISC_START_ADDRESS_2100; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1387 | break; |
| 1388 | case PCI_DEVICE_ID_QLOGIC_ISP2200: |
| 1389 | ha->device_type |= DT_ISP2200; |
| 1390 | ha->device_type &= ~DT_EXTENDED_IDS; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1391 | ha->fw_srisc_address = RISC_START_ADDRESS_2100; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1392 | break; |
| 1393 | case PCI_DEVICE_ID_QLOGIC_ISP2300: |
| 1394 | ha->device_type |= DT_ISP2300; |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 1395 | ha->device_type |= DT_ZIO_SUPPORTED; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1396 | ha->fw_srisc_address = RISC_START_ADDRESS_2300; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1397 | break; |
| 1398 | case PCI_DEVICE_ID_QLOGIC_ISP2312: |
| 1399 | ha->device_type |= DT_ISP2312; |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 1400 | ha->device_type |= DT_ZIO_SUPPORTED; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1401 | ha->fw_srisc_address = RISC_START_ADDRESS_2300; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1402 | break; |
| 1403 | case PCI_DEVICE_ID_QLOGIC_ISP2322: |
| 1404 | ha->device_type |= DT_ISP2322; |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 1405 | ha->device_type |= DT_ZIO_SUPPORTED; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1406 | if (ha->pdev->subsystem_vendor == 0x1028 && |
| 1407 | ha->pdev->subsystem_device == 0x0170) |
| 1408 | ha->device_type |= DT_OEM_001; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1409 | ha->fw_srisc_address = RISC_START_ADDRESS_2300; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1410 | break; |
| 1411 | case PCI_DEVICE_ID_QLOGIC_ISP6312: |
| 1412 | ha->device_type |= DT_ISP6312; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1413 | ha->fw_srisc_address = RISC_START_ADDRESS_2300; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1414 | break; |
| 1415 | case PCI_DEVICE_ID_QLOGIC_ISP6322: |
| 1416 | ha->device_type |= DT_ISP6322; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1417 | ha->fw_srisc_address = RISC_START_ADDRESS_2300; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1418 | break; |
| 1419 | case PCI_DEVICE_ID_QLOGIC_ISP2422: |
| 1420 | ha->device_type |= DT_ISP2422; |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 1421 | ha->device_type |= DT_ZIO_SUPPORTED; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1422 | ha->device_type |= DT_FWI2; |
Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 1423 | ha->device_type |= DT_IIDMA; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1424 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1425 | break; |
| 1426 | case PCI_DEVICE_ID_QLOGIC_ISP2432: |
| 1427 | ha->device_type |= DT_ISP2432; |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 1428 | ha->device_type |= DT_ZIO_SUPPORTED; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1429 | ha->device_type |= DT_FWI2; |
Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 1430 | ha->device_type |= DT_IIDMA; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1431 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1432 | break; |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 1433 | case PCI_DEVICE_ID_QLOGIC_ISP5422: |
| 1434 | ha->device_type |= DT_ISP5422; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1435 | ha->device_type |= DT_FWI2; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1436 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1437 | break; |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 1438 | case PCI_DEVICE_ID_QLOGIC_ISP5432: |
| 1439 | ha->device_type |= DT_ISP5432; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1440 | ha->device_type |= DT_FWI2; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1441 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1442 | break; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1443 | case PCI_DEVICE_ID_QLOGIC_ISP2532: |
| 1444 | ha->device_type |= DT_ISP2532; |
| 1445 | ha->device_type |= DT_ZIO_SUPPORTED; |
| 1446 | ha->device_type |= DT_FWI2; |
| 1447 | ha->device_type |= DT_IIDMA; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1448 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
| 1449 | break; |
| 1450 | } |
| 1451 | } |
| 1452 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | static int |
| 1454 | qla2x00_iospace_config(scsi_qla_host_t *ha) |
| 1455 | { |
Andrew Vasquez | 3776541 | 2008-01-17 09:02:09 -0800 | [diff] [blame] | 1456 | resource_size_t pio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | |
Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1458 | if (pci_request_selected_regions(ha->pdev, ha->bars, |
| 1459 | QLA2XXX_DRIVER_NAME)) { |
| 1460 | qla_printk(KERN_WARNING, ha, |
| 1461 | "Failed to reserve PIO/MMIO regions (%s)\n", |
| 1462 | pci_name(ha->pdev)); |
| 1463 | |
| 1464 | goto iospace_error_exit; |
| 1465 | } |
| 1466 | if (!(ha->bars & 1)) |
| 1467 | goto skip_pio; |
| 1468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | /* We only need PIO for Flash operations on ISP2312 v2 chips. */ |
| 1470 | pio = pci_resource_start(ha->pdev, 0); |
Andrew Vasquez | 3776541 | 2008-01-17 09:02:09 -0800 | [diff] [blame] | 1471 | if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) { |
| 1472 | if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | qla_printk(KERN_WARNING, ha, |
| 1474 | "Invalid PCI I/O region size (%s)...\n", |
| 1475 | pci_name(ha->pdev)); |
| 1476 | pio = 0; |
| 1477 | } |
| 1478 | } else { |
| 1479 | qla_printk(KERN_WARNING, ha, |
| 1480 | "region #0 not a PIO resource (%s)...\n", |
| 1481 | pci_name(ha->pdev)); |
| 1482 | pio = 0; |
| 1483 | } |
Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1484 | ha->pio_address = pio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | |
Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1486 | skip_pio: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | /* Use MMIO operations for all accesses. */ |
Andrew Vasquez | 3776541 | 2008-01-17 09:02:09 -0800 | [diff] [blame] | 1488 | if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | qla_printk(KERN_ERR, ha, |
Andrew Vasquez | 3776541 | 2008-01-17 09:02:09 -0800 | [diff] [blame] | 1490 | "region #1 not an MMIO resource (%s), aborting\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | pci_name(ha->pdev)); |
| 1492 | goto iospace_error_exit; |
| 1493 | } |
Andrew Vasquez | 3776541 | 2008-01-17 09:02:09 -0800 | [diff] [blame] | 1494 | if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | qla_printk(KERN_ERR, ha, |
| 1496 | "Invalid PCI mem region size (%s), aborting\n", |
| 1497 | pci_name(ha->pdev)); |
| 1498 | goto iospace_error_exit; |
| 1499 | } |
| 1500 | |
Andrew Vasquez | 3776541 | 2008-01-17 09:02:09 -0800 | [diff] [blame] | 1501 | ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | if (!ha->iobase) { |
| 1503 | qla_printk(KERN_ERR, ha, |
| 1504 | "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev)); |
| 1505 | |
| 1506 | goto iospace_error_exit; |
| 1507 | } |
| 1508 | |
| 1509 | return (0); |
| 1510 | |
| 1511 | iospace_error_exit: |
| 1512 | return (-ENOMEM); |
| 1513 | } |
| 1514 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1515 | static void |
Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 1516 | qla2xxx_scan_start(struct Scsi_Host *shost) |
| 1517 | { |
Andrew Vasquez | f363b94 | 2007-09-20 14:07:45 -0700 | [diff] [blame] | 1518 | scsi_qla_host_t *ha = shost_priv(shost); |
Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 1519 | |
| 1520 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 1521 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
| 1522 | set_bit(RSCN_UPDATE, &ha->dpc_flags); |
| 1523 | } |
| 1524 | |
| 1525 | static int |
| 1526 | qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 1527 | { |
Andrew Vasquez | f363b94 | 2007-09-20 14:07:45 -0700 | [diff] [blame] | 1528 | scsi_qla_host_t *ha = shost_priv(shost); |
Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 1529 | |
| 1530 | if (!ha->host) |
| 1531 | return 1; |
| 1532 | if (time > ha->loop_reset_delay * HZ) |
| 1533 | return 1; |
| 1534 | |
| 1535 | return atomic_read(&ha->loop_state) == LOOP_READY; |
| 1536 | } |
| 1537 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | /* |
| 1539 | * PCI driver interface |
| 1540 | */ |
Andrew Vasquez | 7ee6139 | 2006-06-23 16:11:22 -0700 | [diff] [blame] | 1541 | static int __devinit |
| 1542 | qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | { |
Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1544 | int ret = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | struct Scsi_Host *host; |
| 1546 | scsi_qla_host_t *ha; |
Andrew Vasquez | 29856e2 | 2007-08-12 18:22:52 -0700 | [diff] [blame] | 1547 | char pci_info[30]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | char fw_str[30]; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 1549 | struct scsi_host_template *sht; |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 1550 | int bars, mem_only = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | |
Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1552 | bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO); |
| 1553 | sht = &qla2x00_driver_template; |
| 1554 | if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 || |
| 1555 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 || |
| 1556 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 || |
| 1557 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 || |
| 1558 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532) { |
| 1559 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 1560 | sht = &qla24xx_driver_template; |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 1561 | mem_only = 1; |
Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1562 | } |
| 1563 | |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 1564 | if (mem_only) { |
| 1565 | if (pci_enable_device_mem(pdev)) |
| 1566 | goto probe_out; |
| 1567 | } else { |
| 1568 | if (pci_enable_device(pdev)) |
| 1569 | goto probe_out; |
| 1570 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 1572 | if (pci_find_aer_capability(pdev)) |
| 1573 | if (pci_enable_pcie_error_reporting(pdev)) |
| 1574 | goto probe_out; |
| 1575 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 1576 | host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | if (host == NULL) { |
| 1578 | printk(KERN_WARNING |
| 1579 | "qla2xxx: Couldn't allocate host from scsi layer!\n"); |
| 1580 | goto probe_disable_device; |
| 1581 | } |
| 1582 | |
| 1583 | /* Clear our data area */ |
Andrew Vasquez | f363b94 | 2007-09-20 14:07:45 -0700 | [diff] [blame] | 1584 | ha = shost_priv(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | memset(ha, 0, sizeof(scsi_qla_host_t)); |
| 1586 | |
| 1587 | ha->pdev = pdev; |
| 1588 | ha->host = host; |
| 1589 | ha->host_no = host->host_no; |
Andrew Vasquez | cb63067 | 2006-05-17 15:09:45 -0700 | [diff] [blame] | 1590 | sprintf(ha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, ha->host_no); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1591 | ha->parent = NULL; |
Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1592 | ha->bars = bars; |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 1593 | ha->mem_only = mem_only; |
Andrew Vasquez | df4bf0b | 2008-01-31 12:33:46 -0800 | [diff] [blame] | 1594 | spin_lock_init(&ha->hardware_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1596 | /* Set ISP-type information. */ |
| 1597 | qla2x00_set_isp_flags(ha); |
| 1598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | /* Configure PCI I/O space */ |
| 1600 | ret = qla2x00_iospace_config(ha); |
Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1601 | if (ret) |
| 1602 | goto probe_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | qla_printk(KERN_INFO, ha, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 1605 | "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq, |
| 1606 | ha->iobase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | ha->prev_topology = 0; |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 1609 | ha->init_cb_size = sizeof(init_cb_t); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1610 | ha->mgmt_svr_loop_id = MANAGEMENT_SERVER + ha->vp_idx; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 1611 | ha->link_data_rate = PORT_SPEED_UNKNOWN; |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 1612 | ha->optrom_size = OPTROM_SIZE_2300; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | |
Andrew Vasquez | df7baa5 | 2006-10-13 09:33:39 -0700 | [diff] [blame] | 1614 | ha->max_q_depth = MAX_Q_DEPTH; |
| 1615 | if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU) |
| 1616 | ha->max_q_depth = ql2xmaxqdepth; |
| 1617 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1618 | /* Assign ISP specific operations. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | if (IS_QLA2100(ha)) { |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 1620 | host->max_id = MAX_TARGETS_2100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | ha->mbx_count = MAILBOX_REGISTER_COUNT_2100; |
| 1622 | ha->request_q_length = REQUEST_ENTRY_CNT_2100; |
| 1623 | ha->response_q_length = RESPONSE_ENTRY_CNT_2100; |
| 1624 | ha->last_loop_id = SNS_LAST_LOOP_ID_2100; |
| 1625 | host->sg_tablesize = 32; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1626 | ha->gid_list_info_size = 4; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1627 | ha->isp_ops = &qla2100_isp_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | } else if (IS_QLA2200(ha)) { |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 1629 | host->max_id = MAX_TARGETS_2200; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
| 1631 | ha->request_q_length = REQUEST_ENTRY_CNT_2200; |
| 1632 | ha->response_q_length = RESPONSE_ENTRY_CNT_2100; |
| 1633 | ha->last_loop_id = SNS_LAST_LOOP_ID_2100; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1634 | ha->gid_list_info_size = 4; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1635 | ha->isp_ops = &qla2100_isp_ops; |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 1636 | } else if (IS_QLA23XX(ha)) { |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 1637 | host->max_id = MAX_TARGETS_2200; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
| 1639 | ha->request_q_length = REQUEST_ENTRY_CNT_2200; |
| 1640 | ha->response_q_length = RESPONSE_ENTRY_CNT_2300; |
| 1641 | ha->last_loop_id = SNS_LAST_LOOP_ID_2300; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1642 | ha->gid_list_info_size = 6; |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 1643 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1644 | ha->optrom_size = OPTROM_SIZE_2322; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1645 | ha->isp_ops = &qla2300_isp_ops; |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 1646 | } else if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 1647 | host->max_id = MAX_TARGETS_2200; |
| 1648 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
| 1649 | ha->request_q_length = REQUEST_ENTRY_CNT_24XX; |
| 1650 | ha->response_q_length = RESPONSE_ENTRY_CNT_2300; |
| 1651 | ha->last_loop_id = SNS_LAST_LOOP_ID_2300; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1652 | ha->init_cb_size = sizeof(struct mid_init_cb_24xx); |
| 1653 | ha->mgmt_svr_loop_id = 10 + ha->vp_idx; |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 1654 | ha->gid_list_info_size = 8; |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 1655 | ha->optrom_size = OPTROM_SIZE_24XX; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1656 | ha->isp_ops = &qla24xx_isp_ops; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1657 | } else if (IS_QLA25XX(ha)) { |
| 1658 | host->max_id = MAX_TARGETS_2200; |
| 1659 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
| 1660 | ha->request_q_length = REQUEST_ENTRY_CNT_24XX; |
| 1661 | ha->response_q_length = RESPONSE_ENTRY_CNT_2300; |
| 1662 | ha->last_loop_id = SNS_LAST_LOOP_ID_2300; |
| 1663 | ha->init_cb_size = sizeof(struct mid_init_cb_24xx); |
| 1664 | ha->mgmt_svr_loop_id = 10 + ha->vp_idx; |
| 1665 | ha->gid_list_info_size = 8; |
| 1666 | ha->optrom_size = OPTROM_SIZE_25XX; |
| 1667 | ha->isp_ops = &qla25xx_isp_ops; |
Andrew Vasquez | cb8dacb | 2008-04-03 13:13:19 -0700 | [diff] [blame] | 1668 | ha->hw_event_start = PCI_FUNC(pdev->devfn) ? |
| 1669 | FA_HW_EVENT1_ADDR: FA_HW_EVENT0_ADDR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | } |
| 1671 | host->can_queue = ha->request_q_length + 128; |
| 1672 | |
| 1673 | /* load the F/W, read paramaters, and init the H/W */ |
| 1674 | ha->instance = num_hosts; |
| 1675 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1676 | init_MUTEX(&ha->vport_sem); |
Marcus Barrow | 0b05a1f | 2008-01-17 09:02:13 -0800 | [diff] [blame] | 1677 | init_completion(&ha->mbx_cmd_comp); |
| 1678 | complete(&ha->mbx_cmd_comp); |
| 1679 | init_completion(&ha->mbx_intr_comp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | |
| 1681 | INIT_LIST_HEAD(&ha->list); |
| 1682 | INIT_LIST_HEAD(&ha->fcports); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1683 | INIT_LIST_HEAD(&ha->vp_list); |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 1684 | INIT_LIST_HEAD(&ha->work_list); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1685 | |
| 1686 | set_bit(0, (unsigned long *) ha->vp_idx_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | qla2x00_config_dma_addressing(ha); |
| 1689 | if (qla2x00_mem_alloc(ha)) { |
| 1690 | qla_printk(KERN_WARNING, ha, |
| 1691 | "[ERROR] Failed to allocate memory for adapter\n"); |
| 1692 | |
Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1693 | ret = -ENOMEM; |
| 1694 | goto probe_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
Andrew Vasquez | 765140b | 2007-05-07 07:42:58 -0700 | [diff] [blame] | 1697 | if (qla2x00_initialize_adapter(ha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | qla_printk(KERN_WARNING, ha, |
| 1699 | "Failed to initialize adapter\n"); |
| 1700 | |
| 1701 | DEBUG2(printk("scsi(%ld): Failed to initialize adapter - " |
| 1702 | "Adapter flags %x.\n", |
| 1703 | ha->host_no, ha->device_flags)); |
| 1704 | |
Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1705 | ret = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | goto probe_failed; |
| 1707 | } |
| 1708 | |
| 1709 | /* |
| 1710 | * Startup the kernel thread for this host adapter |
| 1711 | */ |
Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 1712 | ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha, |
| 1713 | "%s_dpc", ha->host_str); |
| 1714 | if (IS_ERR(ha->dpc_thread)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | qla_printk(KERN_WARNING, ha, |
| 1716 | "Unable to start DPC thread!\n"); |
Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 1717 | ret = PTR_ERR(ha->dpc_thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | goto probe_failed; |
| 1719 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | |
Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1721 | host->this_id = 255; |
| 1722 | host->cmd_per_lun = 3; |
| 1723 | host->unique_id = ha->instance; |
| 1724 | host->max_cmd_len = MAX_CMDSZ; |
Andrew Vasquez | 75bc419 | 2006-05-17 15:09:22 -0700 | [diff] [blame] | 1725 | host->max_channel = MAX_BUSES - 1; |
Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1726 | host->max_lun = MAX_LUNS; |
| 1727 | host->transportt = qla2xxx_transport_template; |
| 1728 | |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1729 | ret = qla2x00_request_irqs(ha); |
| 1730 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | goto probe_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | |
| 1733 | /* Initialized the timer */ |
| 1734 | qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL); |
| 1735 | |
| 1736 | DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n", |
| 1737 | ha->host_no, ha)); |
| 1738 | |
Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1739 | pci_set_drvdata(pdev, ha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 1740 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | ha->flags.init_done = 1; |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 1742 | ha->flags.online = 1; |
| 1743 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | num_hosts++; |
| 1745 | |
Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1746 | ret = scsi_add_host(host, &pdev->dev); |
| 1747 | if (ret) |
| 1748 | goto probe_failed; |
| 1749 | |
Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 1750 | scsi_scan_host(host); |
| 1751 | |
Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1752 | qla2x00_alloc_sysfs_attr(ha); |
| 1753 | |
| 1754 | qla2x00_init_host_attr(ha); |
| 1755 | |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1756 | qla2x00_dfs_setup(ha); |
| 1757 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | qla_printk(KERN_INFO, ha, "\n" |
| 1759 | " QLogic Fibre Channel HBA Driver: %s\n" |
| 1760 | " QLogic %s - %s\n" |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 1761 | " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n", |
| 1762 | qla2x00_version_str, ha->model_number, |
| 1763 | ha->model_desc ? ha->model_desc: "", pdev->device, |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1764 | ha->isp_ops->pci_info_str(ha, pci_info), pci_name(pdev), |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 1765 | ha->flags.enable_64bit_addressing ? '+': '-', ha->host_no, |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1766 | ha->isp_ops->fw_version_str(ha, fw_str)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | return 0; |
| 1769 | |
| 1770 | probe_failed: |
| 1771 | qla2x00_free_device(ha); |
| 1772 | |
| 1773 | scsi_host_put(host); |
| 1774 | |
| 1775 | probe_disable_device: |
| 1776 | pci_disable_device(pdev); |
| 1777 | |
Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1778 | probe_out: |
| 1779 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | |
Adrian Bunk | 4c993f7 | 2008-01-14 00:55:16 -0800 | [diff] [blame] | 1782 | static void |
Andrew Vasquez | 7ee6139 | 2006-06-23 16:11:22 -0700 | [diff] [blame] | 1783 | qla2x00_remove_one(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | { |
| 1785 | scsi_qla_host_t *ha; |
| 1786 | |
| 1787 | ha = pci_get_drvdata(pdev); |
| 1788 | |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1789 | qla2x00_dfs_remove(ha); |
| 1790 | |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1791 | qla2x00_free_sysfs_attr(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1793 | fc_remove_host(ha->host); |
| 1794 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | scsi_remove_host(ha->host); |
| 1796 | |
| 1797 | qla2x00_free_device(ha); |
| 1798 | |
| 1799 | scsi_host_put(ha->host); |
| 1800 | |
Bernhard Walle | 665db93 | 2007-03-28 00:49:49 +0200 | [diff] [blame] | 1801 | pci_disable_device(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | pci_set_drvdata(pdev, NULL); |
| 1803 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | |
| 1805 | static void |
| 1806 | qla2x00_free_device(scsi_qla_host_t *ha) |
| 1807 | { |
Andrew Vasquez | df4bf0b | 2008-01-31 12:33:46 -0800 | [diff] [blame] | 1808 | qla2x00_abort_all_cmds(ha, DID_NO_CONNECT << 16); |
| 1809 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | /* Disable timer */ |
| 1811 | if (ha->timer_active) |
| 1812 | qla2x00_stop_timer(ha); |
| 1813 | |
Andrew Vasquez | df4bf0b | 2008-01-31 12:33:46 -0800 | [diff] [blame] | 1814 | ha->flags.online = 0; |
| 1815 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | /* Kill the kernel thread for this host */ |
Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 1817 | if (ha->dpc_thread) { |
| 1818 | struct task_struct *t = ha->dpc_thread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | |
Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 1820 | /* |
| 1821 | * qla2xxx_wake_dpc checks for ->dpc_thread |
| 1822 | * so we need to zero it out. |
| 1823 | */ |
| 1824 | ha->dpc_thread = NULL; |
| 1825 | kthread_stop(t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1828 | if (ha->flags.fce_enabled) |
| 1829 | qla2x00_disable_fce_trace(ha, NULL, NULL); |
| 1830 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1831 | if (ha->eft) |
Andrew Vasquez | 00b6bd2 | 2008-01-17 09:02:16 -0800 | [diff] [blame] | 1832 | qla2x00_disable_eft_trace(ha); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1833 | |
Andrew Vasquez | f6ef3b1 | 2005-08-26 19:10:20 -0700 | [diff] [blame] | 1834 | /* Stop currently executing firmware. */ |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 1835 | qla2x00_try_to_stop_firmware(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | |
Andrew Vasquez | f6ef3b1 | 2005-08-26 19:10:20 -0700 | [diff] [blame] | 1837 | /* turn-off interrupts on the card */ |
| 1838 | if (ha->interrupts_on) |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1839 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | f6ef3b1 | 2005-08-26 19:10:20 -0700 | [diff] [blame] | 1840 | |
| 1841 | qla2x00_mem_free(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1843 | qla2x00_free_irqs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | |
| 1845 | /* release io space registers */ |
| 1846 | if (ha->iobase) |
| 1847 | iounmap(ha->iobase); |
Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1848 | pci_release_selected_regions(ha->pdev, ha->bars); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | } |
| 1850 | |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 1851 | static inline void |
| 1852 | qla2x00_schedule_rport_del(struct scsi_qla_host *ha, fc_port_t *fcport, |
| 1853 | int defer) |
| 1854 | { |
| 1855 | unsigned long flags; |
| 1856 | struct fc_rport *rport; |
| 1857 | |
| 1858 | if (!fcport->rport) |
| 1859 | return; |
| 1860 | |
| 1861 | rport = fcport->rport; |
| 1862 | if (defer) { |
| 1863 | spin_lock_irqsave(&fcport->rport_lock, flags); |
| 1864 | fcport->drport = rport; |
| 1865 | fcport->rport = NULL; |
andrew.vasquez@qlogic.com | 387f96b | 2006-02-07 08:45:45 -0800 | [diff] [blame] | 1866 | *(fc_port_t **)rport->dd_data = NULL; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 1867 | spin_unlock_irqrestore(&fcport->rport_lock, flags); |
| 1868 | set_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags); |
| 1869 | } else { |
| 1870 | spin_lock_irqsave(&fcport->rport_lock, flags); |
| 1871 | fcport->rport = NULL; |
andrew.vasquez@qlogic.com | 387f96b | 2006-02-07 08:45:45 -0800 | [diff] [blame] | 1872 | *(fc_port_t **)rport->dd_data = NULL; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 1873 | spin_unlock_irqrestore(&fcport->rport_lock, flags); |
| 1874 | fc_remote_port_delete(rport); |
| 1875 | } |
| 1876 | } |
| 1877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | * qla2x00_mark_device_lost Updates fcport state when device goes offline. |
| 1880 | * |
| 1881 | * Input: ha = adapter block pointer. fcport = port structure pointer. |
| 1882 | * |
| 1883 | * Return: None. |
| 1884 | * |
| 1885 | * Context: |
| 1886 | */ |
| 1887 | void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport, |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 1888 | int do_login, int defer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1890 | if (atomic_read(&fcport->state) == FCS_ONLINE && |
| 1891 | ha->vp_idx == fcport->vp_idx) |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 1892 | qla2x00_schedule_rport_del(ha, fcport, defer); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1893 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1894 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | * We may need to retry the login, so don't change the state of the |
| 1896 | * port but do the retries. |
| 1897 | */ |
| 1898 | if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD) |
| 1899 | atomic_set(&fcport->state, FCS_DEVICE_LOST); |
| 1900 | |
| 1901 | if (!do_login) |
| 1902 | return; |
| 1903 | |
| 1904 | if (fcport->login_retry == 0) { |
| 1905 | fcport->login_retry = ha->login_retry_count; |
| 1906 | set_bit(RELOGIN_NEEDED, &ha->dpc_flags); |
| 1907 | |
| 1908 | DEBUG(printk("scsi(%ld): Port login retry: " |
| 1909 | "%02x%02x%02x%02x%02x%02x%02x%02x, " |
| 1910 | "id = 0x%04x retry cnt=%d\n", |
| 1911 | ha->host_no, |
| 1912 | fcport->port_name[0], |
| 1913 | fcport->port_name[1], |
| 1914 | fcport->port_name[2], |
| 1915 | fcport->port_name[3], |
| 1916 | fcport->port_name[4], |
| 1917 | fcport->port_name[5], |
| 1918 | fcport->port_name[6], |
| 1919 | fcport->port_name[7], |
| 1920 | fcport->loop_id, |
| 1921 | fcport->login_retry)); |
| 1922 | } |
| 1923 | } |
| 1924 | |
| 1925 | /* |
| 1926 | * qla2x00_mark_all_devices_lost |
| 1927 | * Updates fcport state when device goes offline. |
| 1928 | * |
| 1929 | * Input: |
| 1930 | * ha = adapter block pointer. |
| 1931 | * fcport = port structure pointer. |
| 1932 | * |
| 1933 | * Return: |
| 1934 | * None. |
| 1935 | * |
| 1936 | * Context: |
| 1937 | */ |
| 1938 | void |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 1939 | qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha, int defer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | { |
| 1941 | fc_port_t *fcport; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1942 | scsi_qla_host_t *pha = to_qla_parent(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1944 | list_for_each_entry(fcport, &pha->fcports, list) { |
| 1945 | if (ha->vp_idx != 0 && ha->vp_idx != fcport->vp_idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | /* |
| 1948 | * No point in marking the device as lost, if the device is |
| 1949 | * already DEAD. |
| 1950 | */ |
| 1951 | if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD) |
| 1952 | continue; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1953 | if (atomic_read(&fcport->state) == FCS_ONLINE) { |
| 1954 | if (defer) |
| 1955 | qla2x00_schedule_rport_del(ha, fcport, defer); |
| 1956 | else if (ha->vp_idx == fcport->vp_idx) |
| 1957 | qla2x00_schedule_rport_del(ha, fcport, defer); |
| 1958 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1959 | atomic_set(&fcport->state, FCS_DEVICE_LOST); |
| 1960 | } |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 1961 | |
Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 1962 | if (defer) |
| 1963 | qla2xxx_wake_dpc(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
| 1966 | /* |
| 1967 | * qla2x00_mem_alloc |
| 1968 | * Allocates adapter memory. |
| 1969 | * |
| 1970 | * Returns: |
| 1971 | * 0 = success. |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 1972 | * !0 = failure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | */ |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 1974 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | qla2x00_mem_alloc(scsi_qla_host_t *ha) |
| 1976 | { |
| 1977 | char name[16]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 1979 | ha->request_ring = dma_alloc_coherent(&ha->pdev->dev, |
| 1980 | (ha->request_q_length + 1) * sizeof(request_t), &ha->request_dma, |
| 1981 | GFP_KERNEL); |
| 1982 | if (!ha->request_ring) |
| 1983 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 1985 | ha->response_ring = dma_alloc_coherent(&ha->pdev->dev, |
| 1986 | (ha->response_q_length + 1) * sizeof(response_t), |
| 1987 | &ha->response_dma, GFP_KERNEL); |
| 1988 | if (!ha->response_ring) |
| 1989 | goto fail_free_request_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 1991 | ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE, |
| 1992 | &ha->gid_list_dma, GFP_KERNEL); |
| 1993 | if (!ha->gid_list) |
| 1994 | goto fail_free_response_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 1996 | ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size, |
| 1997 | &ha->init_cb_dma, GFP_KERNEL); |
| 1998 | if (!ha->init_cb) |
| 1999 | goto fail_free_gid_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2001 | snprintf(name, sizeof(name), "%s_%ld", QLA2XXX_DRIVER_NAME, |
| 2002 | ha->host_no); |
| 2003 | ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev, |
| 2004 | DMA_POOL_SIZE, 8, 0); |
| 2005 | if (!ha->s_dma_pool) |
| 2006 | goto fail_free_init_cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2008 | ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep); |
| 2009 | if (!ha->srb_mempool) |
| 2010 | goto fail_free_s_dma_pool; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2012 | /* Get memory for cached NVRAM */ |
| 2013 | ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL); |
| 2014 | if (!ha->nvram) |
| 2015 | goto fail_free_srb_mempool; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2017 | /* Allocate memory for SNS commands */ |
| 2018 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 2019 | /* Get consistent memory allocated for SNS commands */ |
| 2020 | ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev, |
| 2021 | sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL); |
| 2022 | if (!ha->sns_cmd) |
| 2023 | goto fail_free_nvram; |
| 2024 | } else { |
| 2025 | /* Get consistent memory allocated for MS IOCB */ |
| 2026 | ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, |
| 2027 | &ha->ms_iocb_dma); |
| 2028 | if (!ha->ms_iocb) |
| 2029 | goto fail_free_nvram; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2031 | /* Get consistent memory allocated for CT SNS commands */ |
| 2032 | ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev, |
| 2033 | sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL); |
| 2034 | if (!ha->ct_sns) |
| 2035 | goto fail_free_ms_iocb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | } |
| 2037 | |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2038 | return 0; |
| 2039 | |
| 2040 | fail_free_ms_iocb: |
| 2041 | dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma); |
| 2042 | ha->ms_iocb = NULL; |
| 2043 | ha->ms_iocb_dma = 0; |
| 2044 | fail_free_nvram: |
| 2045 | kfree(ha->nvram); |
| 2046 | ha->nvram = NULL; |
| 2047 | fail_free_srb_mempool: |
| 2048 | mempool_destroy(ha->srb_mempool); |
| 2049 | ha->srb_mempool = NULL; |
| 2050 | fail_free_s_dma_pool: |
| 2051 | dma_pool_destroy(ha->s_dma_pool); |
| 2052 | ha->s_dma_pool = NULL; |
| 2053 | fail_free_init_cb: |
| 2054 | dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb, |
| 2055 | ha->init_cb_dma); |
| 2056 | ha->init_cb = NULL; |
| 2057 | ha->init_cb_dma = 0; |
| 2058 | fail_free_gid_list: |
| 2059 | dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list, |
| 2060 | ha->gid_list_dma); |
| 2061 | ha->gid_list = NULL; |
| 2062 | ha->gid_list_dma = 0; |
| 2063 | fail_free_response_ring: |
| 2064 | dma_free_coherent(&ha->pdev->dev, (ha->response_q_length + 1) * |
| 2065 | sizeof(response_t), ha->response_ring, ha->response_dma); |
| 2066 | ha->response_ring = NULL; |
| 2067 | ha->response_dma = 0; |
| 2068 | fail_free_request_ring: |
| 2069 | dma_free_coherent(&ha->pdev->dev, (ha->request_q_length + 1) * |
| 2070 | sizeof(request_t), ha->request_ring, ha->request_dma); |
| 2071 | ha->request_ring = NULL; |
| 2072 | ha->request_dma = 0; |
| 2073 | fail: |
| 2074 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | } |
| 2076 | |
| 2077 | /* |
| 2078 | * qla2x00_mem_free |
| 2079 | * Frees all adapter allocated memory. |
| 2080 | * |
| 2081 | * Input: |
| 2082 | * ha = adapter block pointer. |
| 2083 | */ |
Adrian Bunk | a824ebb | 2008-01-17 09:02:15 -0800 | [diff] [blame] | 2084 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | qla2x00_mem_free(scsi_qla_host_t *ha) |
| 2086 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | struct list_head *fcpl, *fcptemp; |
| 2088 | fc_port_t *fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2090 | if (ha->srb_mempool) |
| 2091 | mempool_destroy(ha->srb_mempool); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2093 | if (ha->fce) |
| 2094 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, |
| 2095 | ha->fce_dma); |
| 2096 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2097 | if (ha->fw_dump) { |
| 2098 | if (ha->eft) |
| 2099 | dma_free_coherent(&ha->pdev->dev, |
| 2100 | ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma); |
| 2101 | vfree(ha->fw_dump); |
| 2102 | } |
| 2103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | if (ha->sns_cmd) |
| 2105 | dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt), |
| 2106 | ha->sns_cmd, ha->sns_cmd_dma); |
| 2107 | |
| 2108 | if (ha->ct_sns) |
| 2109 | dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt), |
| 2110 | ha->ct_sns, ha->ct_sns_dma); |
| 2111 | |
Andrew Vasquez | 88729e5 | 2006-06-23 16:10:50 -0700 | [diff] [blame] | 2112 | if (ha->sfp_data) |
| 2113 | dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma); |
| 2114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | if (ha->ms_iocb) |
| 2116 | dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma); |
| 2117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | if (ha->s_dma_pool) |
| 2119 | dma_pool_destroy(ha->s_dma_pool); |
| 2120 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2121 | if (ha->init_cb) |
| 2122 | dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, |
| 2123 | ha->init_cb, ha->init_cb_dma); |
| 2124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | if (ha->gid_list) |
| 2126 | dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list, |
| 2127 | ha->gid_list_dma); |
| 2128 | |
| 2129 | if (ha->response_ring) |
| 2130 | dma_free_coherent(&ha->pdev->dev, |
| 2131 | (ha->response_q_length + 1) * sizeof(response_t), |
| 2132 | ha->response_ring, ha->response_dma); |
| 2133 | |
| 2134 | if (ha->request_ring) |
| 2135 | dma_free_coherent(&ha->pdev->dev, |
| 2136 | (ha->request_q_length + 1) * sizeof(request_t), |
| 2137 | ha->request_ring, ha->request_dma); |
| 2138 | |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2139 | ha->srb_mempool = NULL; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2140 | ha->eft = NULL; |
| 2141 | ha->eft_dma = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | ha->sns_cmd = NULL; |
| 2143 | ha->sns_cmd_dma = 0; |
| 2144 | ha->ct_sns = NULL; |
| 2145 | ha->ct_sns_dma = 0; |
| 2146 | ha->ms_iocb = NULL; |
| 2147 | ha->ms_iocb_dma = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | ha->init_cb = NULL; |
| 2149 | ha->init_cb_dma = 0; |
| 2150 | |
| 2151 | ha->s_dma_pool = NULL; |
| 2152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | ha->gid_list = NULL; |
| 2154 | ha->gid_list_dma = 0; |
| 2155 | |
| 2156 | ha->response_ring = NULL; |
| 2157 | ha->response_dma = 0; |
| 2158 | ha->request_ring = NULL; |
| 2159 | ha->request_dma = 0; |
| 2160 | |
| 2161 | list_for_each_safe(fcpl, fcptemp, &ha->fcports) { |
| 2162 | fcport = list_entry(fcpl, fc_port_t, list); |
| 2163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | /* fc ports */ |
| 2165 | list_del_init(&fcport->list); |
| 2166 | kfree(fcport); |
| 2167 | } |
| 2168 | INIT_LIST_HEAD(&ha->fcports); |
| 2169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | ha->fw_dump = NULL; |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 2171 | ha->fw_dumped = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | ha->fw_dump_reading = 0; |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2173 | |
| 2174 | vfree(ha->optrom_buffer); |
Seokmann Ju | 53772a2 | 2007-07-30 11:01:07 -0700 | [diff] [blame] | 2175 | kfree(ha->nvram); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | } |
| 2177 | |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2178 | struct qla_work_evt * |
| 2179 | qla2x00_alloc_work(struct scsi_qla_host *ha, enum qla_work_type type, |
| 2180 | int locked) |
| 2181 | { |
| 2182 | struct qla_work_evt *e; |
| 2183 | |
| 2184 | e = kzalloc(sizeof(struct qla_work_evt), locked ? GFP_ATOMIC: |
| 2185 | GFP_KERNEL); |
| 2186 | if (!e) |
| 2187 | return NULL; |
| 2188 | |
| 2189 | INIT_LIST_HEAD(&e->list); |
| 2190 | e->type = type; |
| 2191 | e->flags = QLA_EVT_FLAG_FREE; |
| 2192 | return e; |
| 2193 | } |
| 2194 | |
| 2195 | int |
| 2196 | qla2x00_post_work(struct scsi_qla_host *ha, struct qla_work_evt *e, int locked) |
| 2197 | { |
| 2198 | unsigned long flags; |
| 2199 | |
| 2200 | if (!locked) |
| 2201 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2202 | list_add_tail(&e->list, &ha->work_list); |
| 2203 | qla2xxx_wake_dpc(ha); |
| 2204 | if (!locked) |
| 2205 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2206 | return QLA_SUCCESS; |
| 2207 | } |
| 2208 | |
| 2209 | int |
| 2210 | qla2x00_post_aen_work(struct scsi_qla_host *ha, enum fc_host_event_code code, |
| 2211 | u32 data) |
| 2212 | { |
| 2213 | struct qla_work_evt *e; |
| 2214 | |
| 2215 | e = qla2x00_alloc_work(ha, QLA_EVT_AEN, 1); |
| 2216 | if (!e) |
| 2217 | return QLA_FUNCTION_FAILED; |
| 2218 | |
| 2219 | e->u.aen.code = code; |
| 2220 | e->u.aen.data = data; |
| 2221 | return qla2x00_post_work(ha, e, 1); |
| 2222 | } |
| 2223 | |
Andrew Vasquez | cb8dacb | 2008-04-03 13:13:19 -0700 | [diff] [blame] | 2224 | int |
| 2225 | qla2x00_post_hwe_work(struct scsi_qla_host *ha, uint16_t code, uint16_t d1, |
| 2226 | uint16_t d2, uint16_t d3) |
| 2227 | { |
| 2228 | struct qla_work_evt *e; |
| 2229 | |
| 2230 | e = qla2x00_alloc_work(ha, QLA_EVT_HWE_LOG, 1); |
| 2231 | if (!e) |
| 2232 | return QLA_FUNCTION_FAILED; |
| 2233 | |
| 2234 | e->u.hwe.code = code; |
| 2235 | e->u.hwe.d1 = d1; |
| 2236 | e->u.hwe.d2 = d2; |
| 2237 | e->u.hwe.d3 = d3; |
| 2238 | return qla2x00_post_work(ha, e, 1); |
| 2239 | } |
| 2240 | |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2241 | static void |
| 2242 | qla2x00_do_work(struct scsi_qla_host *ha) |
| 2243 | { |
| 2244 | struct qla_work_evt *e; |
| 2245 | |
| 2246 | spin_lock_irq(&ha->hardware_lock); |
| 2247 | while (!list_empty(&ha->work_list)) { |
| 2248 | e = list_entry(ha->work_list.next, struct qla_work_evt, list); |
| 2249 | list_del_init(&e->list); |
| 2250 | spin_unlock_irq(&ha->hardware_lock); |
| 2251 | |
| 2252 | switch (e->type) { |
| 2253 | case QLA_EVT_AEN: |
| 2254 | fc_host_post_event(ha->host, fc_get_event_number(), |
| 2255 | e->u.aen.code, e->u.aen.data); |
| 2256 | break; |
Andrew Vasquez | cb8dacb | 2008-04-03 13:13:19 -0700 | [diff] [blame] | 2257 | case QLA_EVT_HWE_LOG: |
| 2258 | qla2xxx_hw_event_log(ha, e->u.hwe.code, e->u.hwe.d1, |
| 2259 | e->u.hwe.d2, e->u.hwe.d3); |
| 2260 | break; |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2261 | } |
| 2262 | if (e->flags & QLA_EVT_FLAG_FREE) |
| 2263 | kfree(e); |
| 2264 | spin_lock_irq(&ha->hardware_lock); |
| 2265 | } |
| 2266 | spin_unlock_irq(&ha->hardware_lock); |
| 2267 | } |
| 2268 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | /************************************************************************** |
| 2270 | * qla2x00_do_dpc |
| 2271 | * This kernel thread is a task that is schedule by the interrupt handler |
| 2272 | * to perform the background processing for interrupts. |
| 2273 | * |
| 2274 | * Notes: |
| 2275 | * This task always run in the context of a kernel thread. It |
| 2276 | * is kick-off by the driver's detect code and starts up |
| 2277 | * up one per adapter. It immediately goes to sleep and waits for |
| 2278 | * some fibre event. When either the interrupt handler or |
| 2279 | * the timer routine detects a event it will one of the task |
| 2280 | * bits then wake us up. |
| 2281 | **************************************************************************/ |
| 2282 | static int |
| 2283 | qla2x00_do_dpc(void *data) |
| 2284 | { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2285 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | scsi_qla_host_t *ha; |
| 2287 | fc_port_t *fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2288 | uint8_t status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | uint16_t next_loopid; |
Seokmann Ju | 99363ef | 2008-01-31 12:33:51 -0800 | [diff] [blame] | 2290 | struct scsi_qla_host *vha; |
| 2291 | int i; |
| 2292 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | |
| 2294 | ha = (scsi_qla_host_t *)data; |
| 2295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | set_user_nice(current, -20); |
| 2297 | |
Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 2298 | while (!kthread_should_stop()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | DEBUG3(printk("qla2x00: DPC handler sleeping\n")); |
| 2300 | |
Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 2301 | set_current_state(TASK_INTERRUPTIBLE); |
| 2302 | schedule(); |
| 2303 | __set_current_state(TASK_RUNNING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | |
| 2305 | DEBUG3(printk("qla2x00: DPC handler waking up\n")); |
| 2306 | |
| 2307 | /* Initialization not yet finished. Don't do anything yet. */ |
Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 2308 | if (!ha->flags.init_done) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | continue; |
| 2310 | |
| 2311 | DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no)); |
| 2312 | |
| 2313 | ha->dpc_active = 1; |
| 2314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | if (ha->flags.mbox_busy) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | ha->dpc_active = 0; |
| 2317 | continue; |
| 2318 | } |
| 2319 | |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2320 | qla2x00_do_work(ha); |
| 2321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) { |
| 2323 | |
| 2324 | DEBUG(printk("scsi(%ld): dpc: sched " |
| 2325 | "qla2x00_abort_isp ha = %p\n", |
| 2326 | ha->host_no, ha)); |
| 2327 | if (!(test_and_set_bit(ABORT_ISP_ACTIVE, |
| 2328 | &ha->dpc_flags))) { |
| 2329 | |
| 2330 | if (qla2x00_abort_isp(ha)) { |
| 2331 | /* failed. retry later */ |
| 2332 | set_bit(ISP_ABORT_NEEDED, |
| 2333 | &ha->dpc_flags); |
| 2334 | } |
| 2335 | clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); |
| 2336 | } |
Seokmann Ju | 99363ef | 2008-01-31 12:33:51 -0800 | [diff] [blame] | 2337 | |
| 2338 | for_each_mapped_vp_idx(ha, i) { |
| 2339 | list_for_each_entry(vha, &ha->vp_list, |
| 2340 | vp_list) { |
| 2341 | if (i == vha->vp_idx) { |
| 2342 | set_bit(ISP_ABORT_NEEDED, |
| 2343 | &vha->dpc_flags); |
| 2344 | break; |
| 2345 | } |
| 2346 | } |
| 2347 | } |
| 2348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n", |
| 2350 | ha->host_no)); |
| 2351 | } |
| 2352 | |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2353 | if (test_and_clear_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags)) |
| 2354 | qla2x00_update_fcports(ha); |
| 2355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) && |
| 2357 | (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) { |
| 2358 | |
| 2359 | DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n", |
| 2360 | ha->host_no)); |
| 2361 | |
| 2362 | qla2x00_rst_aen(ha); |
| 2363 | clear_bit(RESET_ACTIVE, &ha->dpc_flags); |
| 2364 | } |
| 2365 | |
| 2366 | /* Retry each device up to login retry count */ |
| 2367 | if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) && |
| 2368 | !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) && |
| 2369 | atomic_read(&ha->loop_state) != LOOP_DOWN) { |
| 2370 | |
| 2371 | DEBUG(printk("scsi(%ld): qla2x00_port_login()\n", |
| 2372 | ha->host_no)); |
| 2373 | |
| 2374 | next_loopid = 0; |
| 2375 | list_for_each_entry(fcport, &ha->fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | /* |
| 2377 | * If the port is not ONLINE then try to login |
| 2378 | * to it if we haven't run out of retries. |
| 2379 | */ |
| 2380 | if (atomic_read(&fcport->state) != FCS_ONLINE && |
| 2381 | fcport->login_retry) { |
| 2382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | if (fcport->flags & FCF_FABRIC_DEVICE) { |
| 2384 | if (fcport->flags & |
| 2385 | FCF_TAPE_PRESENT) |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2386 | ha->isp_ops->fabric_logout( |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2387 | ha, fcport->loop_id, |
| 2388 | fcport->d_id.b.domain, |
| 2389 | fcport->d_id.b.area, |
| 2390 | fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | status = qla2x00_fabric_login( |
| 2392 | ha, fcport, &next_loopid); |
| 2393 | } else |
| 2394 | status = |
| 2395 | qla2x00_local_device_login( |
andrew.vasquez@qlogic.com | 9a52a57 | 2006-03-09 14:27:44 -0800 | [diff] [blame] | 2396 | ha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | |
Ravi Anand | 63a8651 | 2007-09-20 14:07:40 -0700 | [diff] [blame] | 2398 | fcport->login_retry--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | if (status == QLA_SUCCESS) { |
| 2400 | fcport->old_loop_id = fcport->loop_id; |
| 2401 | |
| 2402 | DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n", |
| 2403 | ha->host_no, fcport->loop_id)); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2404 | |
andrew.vasquez@qlogic.com | 052c40c | 2006-01-20 14:53:19 -0800 | [diff] [blame] | 2405 | qla2x00_update_fcport(ha, |
| 2406 | fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2407 | } else if (status == 1) { |
| 2408 | set_bit(RELOGIN_NEEDED, &ha->dpc_flags); |
| 2409 | /* retry the login again */ |
| 2410 | DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n", |
| 2411 | ha->host_no, |
| 2412 | fcport->login_retry, fcport->loop_id)); |
| 2413 | } else { |
| 2414 | fcport->login_retry = 0; |
| 2415 | } |
Ravi Anand | 63a8651 | 2007-09-20 14:07:40 -0700 | [diff] [blame] | 2416 | if (fcport->login_retry == 0) |
| 2417 | fcport->loop_id = FC_NO_LOOP_ID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | } |
| 2419 | if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) |
| 2420 | break; |
| 2421 | } |
| 2422 | DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n", |
| 2423 | ha->host_no)); |
| 2424 | } |
| 2425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) { |
| 2427 | |
| 2428 | DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n", |
| 2429 | ha->host_no)); |
| 2430 | |
| 2431 | if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE, |
| 2432 | &ha->dpc_flags))) { |
| 2433 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2434 | rval = qla2x00_loop_resync(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2435 | |
| 2436 | clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags); |
| 2437 | } |
| 2438 | |
| 2439 | DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n", |
| 2440 | ha->host_no)); |
| 2441 | } |
| 2442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2443 | if (!ha->interrupts_on) |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2444 | ha->isp_ops->enable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 2446 | if (test_and_clear_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags)) |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2447 | ha->isp_ops->beacon_blink(ha); |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 2448 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2449 | qla2x00_do_dpc_all_vps(ha); |
| 2450 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | ha->dpc_active = 0; |
| 2452 | } /* End of while(1) */ |
| 2453 | |
| 2454 | DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no)); |
| 2455 | |
| 2456 | /* |
| 2457 | * Make sure that nobody tries to wake us up again. |
| 2458 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | ha->dpc_active = 0; |
| 2460 | |
Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 2461 | return 0; |
| 2462 | } |
| 2463 | |
| 2464 | void |
| 2465 | qla2xxx_wake_dpc(scsi_qla_host_t *ha) |
| 2466 | { |
| 2467 | if (ha->dpc_thread) |
| 2468 | wake_up_process(ha->dpc_thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | } |
| 2470 | |
| 2471 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2472 | * qla2x00_rst_aen |
| 2473 | * Processes asynchronous reset. |
| 2474 | * |
| 2475 | * Input: |
| 2476 | * ha = adapter block pointer. |
| 2477 | */ |
| 2478 | static void |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2479 | qla2x00_rst_aen(scsi_qla_host_t *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | { |
| 2481 | if (ha->flags.online && !ha->flags.reset_active && |
| 2482 | !atomic_read(&ha->loop_down_timer) && |
| 2483 | !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) { |
| 2484 | do { |
| 2485 | clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags); |
| 2486 | |
| 2487 | /* |
| 2488 | * Issue marker command only when we are going to start |
| 2489 | * the I/O. |
| 2490 | */ |
| 2491 | ha->marker_needed = 1; |
| 2492 | } while (!atomic_read(&ha->loop_down_timer) && |
| 2493 | (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags))); |
| 2494 | } |
| 2495 | } |
| 2496 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 2497 | static void |
| 2498 | qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp) |
| 2499 | { |
| 2500 | struct scsi_cmnd *cmd = sp->cmd; |
| 2501 | |
| 2502 | if (sp->flags & SRB_DMA_VALID) { |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 2503 | scsi_dma_unmap(cmd); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 2504 | sp->flags &= ~SRB_DMA_VALID; |
| 2505 | } |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 2506 | CMD_SP(cmd) = NULL; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 2507 | } |
| 2508 | |
| 2509 | void |
| 2510 | qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp) |
| 2511 | { |
| 2512 | struct scsi_cmnd *cmd = sp->cmd; |
| 2513 | |
| 2514 | qla2x00_sp_free_dma(ha, sp); |
| 2515 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 2516 | mempool_free(sp, ha->srb_mempool); |
| 2517 | |
| 2518 | cmd->scsi_done(cmd); |
| 2519 | } |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 2520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | /************************************************************************** |
| 2522 | * qla2x00_timer |
| 2523 | * |
| 2524 | * Description: |
| 2525 | * One second timer |
| 2526 | * |
| 2527 | * Context: Interrupt |
| 2528 | ***************************************************************************/ |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2529 | void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | qla2x00_timer(scsi_qla_host_t *ha) |
| 2531 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2532 | unsigned long cpu_flags = 0; |
| 2533 | fc_port_t *fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | int start_dpc = 0; |
| 2535 | int index; |
| 2536 | srb_t *sp; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 2537 | int t; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2538 | scsi_qla_host_t *pha = to_qla_parent(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2539 | |
| 2540 | /* |
| 2541 | * Ports - Port down timer. |
| 2542 | * |
| 2543 | * Whenever, a port is in the LOST state we start decrementing its port |
| 2544 | * down timer every second until it reaches zero. Once it reaches zero |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2545 | * the port it marked DEAD. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2546 | */ |
| 2547 | t = 0; |
| 2548 | list_for_each_entry(fcport, &ha->fcports, list) { |
| 2549 | if (fcport->port_type != FCT_TARGET) |
| 2550 | continue; |
| 2551 | |
| 2552 | if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) { |
| 2553 | |
| 2554 | if (atomic_read(&fcport->port_down_timer) == 0) |
| 2555 | continue; |
| 2556 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2557 | if (atomic_dec_and_test(&fcport->port_down_timer) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | atomic_set(&fcport->state, FCS_DEVICE_DEAD); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2560 | DEBUG(printk("scsi(%ld): fcport-%d - port retry count: " |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 2561 | "%d remaining\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | ha->host_no, |
| 2563 | t, atomic_read(&fcport->port_down_timer))); |
| 2564 | } |
| 2565 | t++; |
| 2566 | } /* End of for fcport */ |
| 2567 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2568 | |
| 2569 | /* Loop down handler. */ |
| 2570 | if (atomic_read(&ha->loop_down_timer) > 0 && |
| 2571 | !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) { |
| 2572 | |
| 2573 | if (atomic_read(&ha->loop_down_timer) == |
| 2574 | ha->loop_down_abort_time) { |
| 2575 | |
| 2576 | DEBUG(printk("scsi(%ld): Loop Down - aborting the " |
| 2577 | "queues before time expire\n", |
| 2578 | ha->host_no)); |
| 2579 | |
| 2580 | if (!IS_QLA2100(ha) && ha->link_down_timeout) |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2581 | atomic_set(&ha->loop_state, LOOP_DEAD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | |
| 2583 | /* Schedule an ISP abort to return any tape commands. */ |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2584 | /* NPIV - scan physical port only */ |
| 2585 | if (!ha->parent) { |
| 2586 | spin_lock_irqsave(&ha->hardware_lock, |
| 2587 | cpu_flags); |
| 2588 | for (index = 1; |
| 2589 | index < MAX_OUTSTANDING_COMMANDS; |
| 2590 | index++) { |
| 2591 | fc_port_t *sfcp; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 2592 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2593 | sp = ha->outstanding_cmds[index]; |
| 2594 | if (!sp) |
| 2595 | continue; |
| 2596 | sfcp = sp->fcport; |
| 2597 | if (!(sfcp->flags & FCF_TAPE_PRESENT)) |
| 2598 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2600 | set_bit(ISP_ABORT_NEEDED, |
| 2601 | &ha->dpc_flags); |
| 2602 | break; |
| 2603 | } |
| 2604 | spin_unlock_irqrestore(&ha->hardware_lock, |
| 2605 | cpu_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags); |
| 2608 | start_dpc++; |
| 2609 | } |
| 2610 | |
| 2611 | /* if the loop has been down for 4 minutes, reinit adapter */ |
| 2612 | if (atomic_dec_and_test(&ha->loop_down_timer) != 0) { |
| 2613 | DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - " |
| 2614 | "restarting queues.\n", |
| 2615 | ha->host_no)); |
| 2616 | |
| 2617 | set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags); |
| 2618 | start_dpc++; |
| 2619 | |
| 2620 | if (!(ha->device_flags & DFLG_NO_CABLE)) { |
| 2621 | DEBUG(printk("scsi(%ld): Loop down - " |
| 2622 | "aborting ISP.\n", |
| 2623 | ha->host_no)); |
| 2624 | qla_printk(KERN_WARNING, ha, |
| 2625 | "Loop down - aborting ISP.\n"); |
| 2626 | |
| 2627 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 2628 | } |
| 2629 | } |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 2630 | DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | ha->host_no, |
| 2632 | atomic_read(&ha->loop_down_timer))); |
| 2633 | } |
| 2634 | |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 2635 | /* Check if beacon LED needs to be blinked */ |
| 2636 | if (ha->beacon_blink_led == 1) { |
| 2637 | set_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags); |
| 2638 | start_dpc++; |
| 2639 | } |
| 2640 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | /* Schedule the DPC routine if needed */ |
| 2642 | if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) || |
| 2643 | test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) || |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2644 | test_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | start_dpc || |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 2646 | test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) || |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 2647 | test_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags) || |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2648 | test_bit(VP_DPC_NEEDED, &ha->dpc_flags) || |
Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 2649 | test_bit(RELOGIN_NEEDED, &ha->dpc_flags))) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2650 | qla2xxx_wake_dpc(pha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 | |
| 2652 | qla2x00_restart_timer(ha, WATCH_INTERVAL); |
| 2653 | } |
| 2654 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2655 | /* Firmware interface routines. */ |
| 2656 | |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2657 | #define FW_BLOBS 6 |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2658 | #define FW_ISP21XX 0 |
| 2659 | #define FW_ISP22XX 1 |
| 2660 | #define FW_ISP2300 2 |
| 2661 | #define FW_ISP2322 3 |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 2662 | #define FW_ISP24XX 4 |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2663 | #define FW_ISP25XX 5 |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2664 | |
Andrew Vasquez | bb8ee49 | 2006-10-02 12:00:48 -0700 | [diff] [blame] | 2665 | #define FW_FILE_ISP21XX "ql2100_fw.bin" |
| 2666 | #define FW_FILE_ISP22XX "ql2200_fw.bin" |
| 2667 | #define FW_FILE_ISP2300 "ql2300_fw.bin" |
| 2668 | #define FW_FILE_ISP2322 "ql2322_fw.bin" |
| 2669 | #define FW_FILE_ISP24XX "ql2400_fw.bin" |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2670 | #define FW_FILE_ISP25XX "ql2500_fw.bin" |
Andrew Vasquez | bb8ee49 | 2006-10-02 12:00:48 -0700 | [diff] [blame] | 2671 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2672 | static DECLARE_MUTEX(qla_fw_lock); |
| 2673 | |
| 2674 | static struct fw_blob qla_fw_blobs[FW_BLOBS] = { |
Andrew Vasquez | bb8ee49 | 2006-10-02 12:00:48 -0700 | [diff] [blame] | 2675 | { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, }, |
| 2676 | { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, }, |
| 2677 | { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, }, |
| 2678 | { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, }, |
| 2679 | { .name = FW_FILE_ISP24XX, }, |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2680 | { .name = FW_FILE_ISP25XX, }, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2681 | }; |
| 2682 | |
| 2683 | struct fw_blob * |
| 2684 | qla2x00_request_firmware(scsi_qla_host_t *ha) |
| 2685 | { |
| 2686 | struct fw_blob *blob; |
| 2687 | |
| 2688 | blob = NULL; |
| 2689 | if (IS_QLA2100(ha)) { |
| 2690 | blob = &qla_fw_blobs[FW_ISP21XX]; |
| 2691 | } else if (IS_QLA2200(ha)) { |
| 2692 | blob = &qla_fw_blobs[FW_ISP22XX]; |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 2693 | } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2694 | blob = &qla_fw_blobs[FW_ISP2300]; |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 2695 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) { |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2696 | blob = &qla_fw_blobs[FW_ISP2322]; |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 2697 | } else if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2698 | blob = &qla_fw_blobs[FW_ISP24XX]; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2699 | } else if (IS_QLA25XX(ha)) { |
| 2700 | blob = &qla_fw_blobs[FW_ISP25XX]; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2701 | } |
| 2702 | |
| 2703 | down(&qla_fw_lock); |
| 2704 | if (blob->fw) |
| 2705 | goto out; |
| 2706 | |
| 2707 | if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) { |
| 2708 | DEBUG2(printk("scsi(%ld): Failed to load firmware image " |
| 2709 | "(%s).\n", ha->host_no, blob->name)); |
| 2710 | blob->fw = NULL; |
| 2711 | blob = NULL; |
| 2712 | goto out; |
| 2713 | } |
| 2714 | |
| 2715 | out: |
| 2716 | up(&qla_fw_lock); |
| 2717 | return blob; |
| 2718 | } |
| 2719 | |
| 2720 | static void |
| 2721 | qla2x00_release_firmware(void) |
| 2722 | { |
| 2723 | int idx; |
| 2724 | |
| 2725 | down(&qla_fw_lock); |
| 2726 | for (idx = 0; idx < FW_BLOBS; idx++) |
| 2727 | if (qla_fw_blobs[idx].fw) |
| 2728 | release_firmware(qla_fw_blobs[idx].fw); |
| 2729 | up(&qla_fw_lock); |
| 2730 | } |
| 2731 | |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 2732 | static pci_ers_result_t |
| 2733 | qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 2734 | { |
| 2735 | switch (state) { |
| 2736 | case pci_channel_io_normal: |
| 2737 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 2738 | case pci_channel_io_frozen: |
| 2739 | pci_disable_device(pdev); |
| 2740 | return PCI_ERS_RESULT_NEED_RESET; |
| 2741 | case pci_channel_io_perm_failure: |
| 2742 | qla2x00_remove_one(pdev); |
| 2743 | return PCI_ERS_RESULT_DISCONNECT; |
| 2744 | } |
| 2745 | return PCI_ERS_RESULT_NEED_RESET; |
| 2746 | } |
| 2747 | |
| 2748 | static pci_ers_result_t |
| 2749 | qla2xxx_pci_mmio_enabled(struct pci_dev *pdev) |
| 2750 | { |
| 2751 | int risc_paused = 0; |
| 2752 | uint32_t stat; |
| 2753 | unsigned long flags; |
| 2754 | scsi_qla_host_t *ha = pci_get_drvdata(pdev); |
| 2755 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 2756 | struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24; |
| 2757 | |
| 2758 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2759 | if (IS_QLA2100(ha) || IS_QLA2200(ha)){ |
| 2760 | stat = RD_REG_DWORD(®->hccr); |
| 2761 | if (stat & HCCR_RISC_PAUSE) |
| 2762 | risc_paused = 1; |
| 2763 | } else if (IS_QLA23XX(ha)) { |
| 2764 | stat = RD_REG_DWORD(®->u.isp2300.host_status); |
| 2765 | if (stat & HSR_RISC_PAUSED) |
| 2766 | risc_paused = 1; |
| 2767 | } else if (IS_FWI2_CAPABLE(ha)) { |
| 2768 | stat = RD_REG_DWORD(®24->host_status); |
| 2769 | if (stat & HSRX_RISC_PAUSED) |
| 2770 | risc_paused = 1; |
| 2771 | } |
| 2772 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2773 | |
| 2774 | if (risc_paused) { |
| 2775 | qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, " |
| 2776 | "Dumping firmware!\n"); |
| 2777 | ha->isp_ops->fw_dump(ha, 0); |
| 2778 | |
| 2779 | return PCI_ERS_RESULT_NEED_RESET; |
| 2780 | } else |
| 2781 | return PCI_ERS_RESULT_RECOVERED; |
| 2782 | } |
| 2783 | |
| 2784 | static pci_ers_result_t |
| 2785 | qla2xxx_pci_slot_reset(struct pci_dev *pdev) |
| 2786 | { |
| 2787 | pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT; |
| 2788 | scsi_qla_host_t *ha = pci_get_drvdata(pdev); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 2789 | int rc; |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 2790 | |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 2791 | if (ha->mem_only) |
| 2792 | rc = pci_enable_device_mem(pdev); |
| 2793 | else |
| 2794 | rc = pci_enable_device(pdev); |
| 2795 | |
| 2796 | if (rc) { |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 2797 | qla_printk(KERN_WARNING, ha, |
| 2798 | "Can't re-enable PCI device after reset.\n"); |
| 2799 | |
| 2800 | return ret; |
| 2801 | } |
| 2802 | pci_set_master(pdev); |
| 2803 | |
| 2804 | if (ha->isp_ops->pci_config(ha)) |
| 2805 | return ret; |
| 2806 | |
| 2807 | set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); |
| 2808 | if (qla2x00_abort_isp(ha)== QLA_SUCCESS) |
| 2809 | ret = PCI_ERS_RESULT_RECOVERED; |
| 2810 | clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); |
| 2811 | |
| 2812 | return ret; |
| 2813 | } |
| 2814 | |
| 2815 | static void |
| 2816 | qla2xxx_pci_resume(struct pci_dev *pdev) |
| 2817 | { |
| 2818 | scsi_qla_host_t *ha = pci_get_drvdata(pdev); |
| 2819 | int ret; |
| 2820 | |
| 2821 | ret = qla2x00_wait_for_hba_online(ha); |
| 2822 | if (ret != QLA_SUCCESS) { |
| 2823 | qla_printk(KERN_ERR, ha, |
| 2824 | "the device failed to resume I/O " |
| 2825 | "from slot/link_reset"); |
| 2826 | } |
| 2827 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 2828 | } |
| 2829 | |
| 2830 | static struct pci_error_handlers qla2xxx_err_handler = { |
| 2831 | .error_detected = qla2xxx_pci_error_detected, |
| 2832 | .mmio_enabled = qla2xxx_pci_mmio_enabled, |
| 2833 | .slot_reset = qla2xxx_pci_slot_reset, |
| 2834 | .resume = qla2xxx_pci_resume, |
| 2835 | }; |
| 2836 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2837 | static struct pci_device_id qla2xxx_pci_tbl[] = { |
Andrew Vasquez | 47f5e06 | 2006-05-17 15:09:39 -0700 | [diff] [blame] | 2838 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) }, |
| 2839 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) }, |
| 2840 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) }, |
| 2841 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) }, |
| 2842 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) }, |
| 2843 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) }, |
| 2844 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) }, |
| 2845 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) }, |
| 2846 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) }, |
| 2847 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) }, |
| 2848 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) }, |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2849 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) }, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2850 | { 0 }, |
| 2851 | }; |
| 2852 | MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl); |
| 2853 | |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 2854 | static struct pci_driver qla2xxx_pci_driver = { |
Andrew Vasquez | cb63067 | 2006-05-17 15:09:45 -0700 | [diff] [blame] | 2855 | .name = QLA2XXX_DRIVER_NAME, |
James Bottomley | 0a21ef1 | 2005-12-01 12:51:50 -0600 | [diff] [blame] | 2856 | .driver = { |
| 2857 | .owner = THIS_MODULE, |
| 2858 | }, |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 2859 | .id_table = qla2xxx_pci_tbl, |
Andrew Vasquez | 7ee6139 | 2006-06-23 16:11:22 -0700 | [diff] [blame] | 2860 | .probe = qla2x00_probe_one, |
Adrian Bunk | 4c993f7 | 2008-01-14 00:55:16 -0800 | [diff] [blame] | 2861 | .remove = qla2x00_remove_one, |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 2862 | .err_handler = &qla2xxx_err_handler, |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 2863 | }; |
| 2864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | /** |
| 2866 | * qla2x00_module_init - Module initialization. |
| 2867 | **/ |
| 2868 | static int __init |
| 2869 | qla2x00_module_init(void) |
| 2870 | { |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 2871 | int ret = 0; |
| 2872 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2873 | /* Allocate cache for SRBs. */ |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 2874 | srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 2875 | SLAB_HWCACHE_ALIGN, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | if (srb_cachep == NULL) { |
| 2877 | printk(KERN_ERR |
| 2878 | "qla2xxx: Unable to allocate SRB cache...Failing load!\n"); |
| 2879 | return -ENOMEM; |
| 2880 | } |
| 2881 | |
| 2882 | /* Derive version string. */ |
| 2883 | strcpy(qla2x00_version_str, QLA2XXX_VERSION); |
Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 2884 | if (ql2xextended_error_logging) |
Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 2885 | strcat(qla2x00_version_str, "-debug"); |
| 2886 | |
Andrew Vasquez | 1c97a12 | 2005-04-21 16:13:36 -0400 | [diff] [blame] | 2887 | qla2xxx_transport_template = |
| 2888 | fc_attach_transport(&qla2xxx_transport_functions); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2889 | if (!qla2xxx_transport_template) { |
| 2890 | kmem_cache_destroy(srb_cachep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2891 | return -ENODEV; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2892 | } |
| 2893 | qla2xxx_transport_vport_template = |
| 2894 | fc_attach_transport(&qla2xxx_transport_vport_functions); |
| 2895 | if (!qla2xxx_transport_vport_template) { |
| 2896 | kmem_cache_destroy(srb_cachep); |
| 2897 | fc_release_transport(qla2xxx_transport_template); |
| 2898 | return -ENODEV; |
| 2899 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | |
| 2901 | printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n"); |
Andrew Vasquez | 7ee6139 | 2006-06-23 16:11:22 -0700 | [diff] [blame] | 2902 | ret = pci_register_driver(&qla2xxx_pci_driver); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 2903 | if (ret) { |
| 2904 | kmem_cache_destroy(srb_cachep); |
| 2905 | fc_release_transport(qla2xxx_transport_template); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2906 | fc_release_transport(qla2xxx_transport_vport_template); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 2907 | } |
| 2908 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | } |
| 2910 | |
| 2911 | /** |
| 2912 | * qla2x00_module_exit - Module cleanup. |
| 2913 | **/ |
| 2914 | static void __exit |
| 2915 | qla2x00_module_exit(void) |
| 2916 | { |
Andrew Vasquez | 7ee6139 | 2006-06-23 16:11:22 -0700 | [diff] [blame] | 2917 | pci_unregister_driver(&qla2xxx_pci_driver); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2918 | qla2x00_release_firmware(); |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 2919 | kmem_cache_destroy(srb_cachep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | fc_release_transport(qla2xxx_transport_template); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2921 | fc_release_transport(qla2xxx_transport_vport_template); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | } |
| 2923 | |
| 2924 | module_init(qla2x00_module_init); |
| 2925 | module_exit(qla2x00_module_exit); |
| 2926 | |
| 2927 | MODULE_AUTHOR("QLogic Corporation"); |
| 2928 | MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver"); |
| 2929 | MODULE_LICENSE("GPL"); |
| 2930 | MODULE_VERSION(QLA2XXX_VERSION); |
Andrew Vasquez | bb8ee49 | 2006-10-02 12:00:48 -0700 | [diff] [blame] | 2931 | MODULE_FIRMWARE(FW_FILE_ISP21XX); |
| 2932 | MODULE_FIRMWARE(FW_FILE_ISP22XX); |
| 2933 | MODULE_FIRMWARE(FW_FILE_ISP2300); |
| 2934 | MODULE_FIRMWARE(FW_FILE_ISP2322); |
| 2935 | MODULE_FIRMWARE(FW_FILE_ISP24XX); |
Andrew Vasquez | 61623fc | 2008-01-31 12:33:45 -0800 | [diff] [blame] | 2936 | MODULE_FIRMWARE(FW_FILE_ISP25XX); |