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