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