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