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