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