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 |
Giridhar Malavali | de7c5d0 | 2010-07-23 15:28:36 +0500 | [diff] [blame] | 3 | * Copyright (c) 2003-2010 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> |
Andrew Vasquez | 3420d36 | 2009-10-13 15:16:45 -0700 | [diff] [blame] | 14 | #include <linux/kobject.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | #include <scsi/scsi_tcq.h> |
| 18 | #include <scsi/scsicam.h> |
| 19 | #include <scsi/scsi_transport.h> |
| 20 | #include <scsi/scsi_transport_fc.h> |
| 21 | |
| 22 | /* |
| 23 | * Driver version |
| 24 | */ |
| 25 | char qla2x00_version_str[40]; |
| 26 | |
Harish Zunjarrao | 6a03b4c | 2010-05-04 15:01:24 -0700 | [diff] [blame] | 27 | static int apidev_major; |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | /* |
| 30 | * SRB allocation cache |
| 31 | */ |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 32 | static struct kmem_cache *srb_cachep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 34 | /* |
| 35 | * CT6 CTX allocation cache |
| 36 | */ |
| 37 | static struct kmem_cache *ctx_cachep; |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | int ql2xlogintimeout = 20; |
| 40 | module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR); |
| 41 | MODULE_PARM_DESC(ql2xlogintimeout, |
| 42 | "Login timeout value in seconds."); |
| 43 | |
Andrew Vasquez | a7b6184 | 2007-05-07 07:42:59 -0700 | [diff] [blame] | 44 | int qlport_down_retry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR); |
| 46 | MODULE_PARM_DESC(qlport_down_retry, |
Jesper Juhl | 900d9f9 | 2006-06-30 02:33:07 -0700 | [diff] [blame] | 47 | "Maximum number of command retries to a port that returns " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | "a PORT-DOWN status."); |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | int ql2xplogiabsentdevice; |
| 51 | module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR); |
| 52 | MODULE_PARM_DESC(ql2xplogiabsentdevice, |
| 53 | "Option to enable PLOGI to devices that are not present after " |
Jesper Juhl | 900d9f9 | 2006-06-30 02:33:07 -0700 | [diff] [blame] | 54 | "a Fabric scan. This is needed for several broken switches. " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | "Default is 0 - no PLOGI. 1 - perfom PLOGI."); |
| 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | int ql2xloginretrycount = 0; |
| 58 | module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR); |
| 59 | MODULE_PARM_DESC(ql2xloginretrycount, |
| 60 | "Specify an alternate value for the NVRAM login retry count."); |
| 61 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 62 | int ql2xallocfwdump = 1; |
| 63 | module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR); |
| 64 | MODULE_PARM_DESC(ql2xallocfwdump, |
| 65 | "Option to enable allocation of memory for a firmware dump " |
| 66 | "during HBA initialization. Memory allocation requirements " |
| 67 | "vary by ISP type. Default is 1 - allocate memory."); |
| 68 | |
Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 69 | int ql2xextended_error_logging; |
Andrew Vasquez | 27d9403 | 2007-03-12 10:41:30 -0700 | [diff] [blame] | 70 | module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR); |
Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 71 | MODULE_PARM_DESC(ql2xextended_error_logging, |
Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 72 | "Option to enable extended error logging, " |
| 73 | "Default is 0 - no logging. 1 - log errors."); |
| 74 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 75 | int ql2xshiftctondsd = 6; |
| 76 | module_param(ql2xshiftctondsd, int, S_IRUGO|S_IRUSR); |
| 77 | MODULE_PARM_DESC(ql2xshiftctondsd, |
| 78 | "Set to control shifting of command type processing " |
| 79 | "based on total number of SG elements."); |
| 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | static void qla2x00_free_device(scsi_qla_host_t *); |
| 82 | |
Andrew Vasquez | 7e47e5c | 2008-04-24 15:21:26 -0700 | [diff] [blame] | 83 | int ql2xfdmienable=1; |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 84 | module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR); |
| 85 | MODULE_PARM_DESC(ql2xfdmienable, |
Ferenc Wagner | 7794a5a | 2010-03-23 18:14:59 +0100 | [diff] [blame] | 86 | "Enables FDMI registrations. " |
| 87 | "0 - no FDMI. Default is 1 - perform FDMI."); |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 88 | |
Andrew Vasquez | df7baa5 | 2006-10-13 09:33:39 -0700 | [diff] [blame] | 89 | #define MAX_Q_DEPTH 32 |
| 90 | static int ql2xmaxqdepth = MAX_Q_DEPTH; |
| 91 | module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR); |
| 92 | MODULE_PARM_DESC(ql2xmaxqdepth, |
| 93 | "Maximum queue depth to report for target devices."); |
| 94 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 95 | /* Do not change the value of this after module load */ |
| 96 | int ql2xenabledif = 1; |
| 97 | module_param(ql2xenabledif, int, S_IRUGO|S_IWUSR); |
| 98 | MODULE_PARM_DESC(ql2xenabledif, |
| 99 | " Enable T10-CRC-DIF " |
| 100 | " Default is 0 - No DIF Support. 1 - Enable it"); |
| 101 | |
| 102 | int ql2xenablehba_err_chk; |
| 103 | module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR); |
| 104 | MODULE_PARM_DESC(ql2xenablehba_err_chk, |
| 105 | " Enable T10-CRC-DIF Error isolation by HBA" |
| 106 | " Default is 0 - Error isolation disabled, 1 - Enable it"); |
| 107 | |
Andrew Vasquez | e5896bd | 2008-07-10 16:55:52 -0700 | [diff] [blame] | 108 | int ql2xiidmaenable=1; |
| 109 | module_param(ql2xiidmaenable, int, S_IRUGO|S_IRUSR); |
| 110 | MODULE_PARM_DESC(ql2xiidmaenable, |
| 111 | "Enables iIDMA settings " |
| 112 | "Default is 1 - perform iIDMA. 0 - no iIDMA."); |
| 113 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 114 | int ql2xmaxqueues = 1; |
| 115 | module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR); |
| 116 | MODULE_PARM_DESC(ql2xmaxqueues, |
| 117 | "Enables MQ settings " |
Joe Perches | ae68230 | 2010-08-10 18:01:21 -0700 | [diff] [blame] | 118 | "Default is 1 for single queue. Set it to number " |
| 119 | "of queues in MQ mode."); |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 120 | |
| 121 | int ql2xmultique_tag; |
| 122 | module_param(ql2xmultique_tag, int, S_IRUGO|S_IRUSR); |
| 123 | MODULE_PARM_DESC(ql2xmultique_tag, |
| 124 | "Enables CPU affinity settings for the driver " |
| 125 | "Default is 0 for no affinity of request and response IO. " |
| 126 | "Set it to 1 to turn on the cpu affinity."); |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 127 | |
| 128 | int ql2xfwloadbin; |
| 129 | module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR); |
| 130 | MODULE_PARM_DESC(ql2xfwloadbin, |
| 131 | "Option to specify location from which to load ISP firmware:\n" |
| 132 | " 2 -- load firmware via the request_firmware() (hotplug)\n" |
| 133 | " interface.\n" |
| 134 | " 1 -- load firmware from flash.\n" |
| 135 | " 0 -- use default semantics.\n"); |
| 136 | |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 137 | int ql2xetsenable; |
| 138 | module_param(ql2xetsenable, int, S_IRUGO|S_IRUSR); |
| 139 | MODULE_PARM_DESC(ql2xetsenable, |
| 140 | "Enables firmware ETS burst." |
| 141 | "Default is 0 - skip ETS enablement."); |
| 142 | |
Giridhar Malavali | 6907869 | 2010-05-28 15:08:28 -0700 | [diff] [blame] | 143 | int ql2xdbwr = 1; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 144 | module_param(ql2xdbwr, int, S_IRUGO|S_IRUSR); |
| 145 | MODULE_PARM_DESC(ql2xdbwr, |
| 146 | "Option to specify scheme for request queue posting\n" |
| 147 | " 0 -- Regular doorbell.\n" |
| 148 | " 1 -- CAMRAM doorbell (faster).\n"); |
| 149 | |
| 150 | int ql2xdontresethba; |
| 151 | module_param(ql2xdontresethba, int, S_IRUGO|S_IRUSR); |
| 152 | MODULE_PARM_DESC(ql2xdontresethba, |
| 153 | "Option to specify reset behaviour\n" |
| 154 | " 0 (Default) -- Reset on failure.\n" |
| 155 | " 1 -- Do not reset on failure.\n"); |
| 156 | |
Giridhar Malavali | f4c496c | 2010-05-04 15:01:33 -0700 | [diff] [blame] | 157 | int ql2xtargetreset = 1; |
| 158 | module_param(ql2xtargetreset, int, S_IRUGO|S_IRUSR); |
| 159 | MODULE_PARM_DESC(ql2xtargetreset, |
| 160 | "Enable target reset." |
| 161 | "Default is 1 - use hw defaults."); |
| 162 | |
Chad Dupuis | 4da26e1 | 2010-10-15 11:27:40 -0700 | [diff] [blame] | 163 | int ql2xgffidenable; |
| 164 | module_param(ql2xgffidenable, int, S_IRUGO|S_IRUSR); |
| 165 | MODULE_PARM_DESC(ql2xgffidenable, |
| 166 | "Enables GFF_ID checks of port type. " |
| 167 | "Default is 0 - Do not use GFF_ID information."); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 168 | |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 169 | int ql2xasynctmfenable; |
| 170 | module_param(ql2xasynctmfenable, int, S_IRUGO|S_IRUSR); |
| 171 | MODULE_PARM_DESC(ql2xasynctmfenable, |
| 172 | "Enables issue of TM IOCBs asynchronously via IOCB mechanism" |
| 173 | "Default is 0 - Issue TM IOCBs via mailbox mechanism."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | /* |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 175 | * SCSI host template entry points |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | */ |
| 177 | static int qla2xxx_slave_configure(struct scsi_device * device); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 178 | static int qla2xxx_slave_alloc(struct scsi_device *); |
Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 179 | static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time); |
| 180 | static void qla2xxx_scan_start(struct Scsi_Host *); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 181 | static void qla2xxx_slave_destroy(struct scsi_device *); |
Giridhar Malavali | a5326f8 | 2009-03-24 09:07:56 -0700 | [diff] [blame] | 182 | static int qla2xxx_queuecommand(struct scsi_cmnd *cmd, |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 183 | void (*fn)(struct scsi_cmnd *)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | static int qla2xxx_eh_abort(struct scsi_cmnd *); |
| 185 | static int qla2xxx_eh_device_reset(struct scsi_cmnd *); |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 186 | static int qla2xxx_eh_target_reset(struct scsi_cmnd *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | static int qla2xxx_eh_bus_reset(struct scsi_cmnd *); |
| 188 | static int qla2xxx_eh_host_reset(struct scsi_cmnd *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 190 | static int qla2x00_change_queue_depth(struct scsi_device *, int, int); |
Andrew Vasquez | ce7e4af | 2005-08-26 19:09:30 -0700 | [diff] [blame] | 191 | static int qla2x00_change_queue_type(struct scsi_device *, int); |
| 192 | |
Giridhar Malavali | a5326f8 | 2009-03-24 09:07:56 -0700 | [diff] [blame] | 193 | struct scsi_host_template qla2xxx_driver_template = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | .module = THIS_MODULE, |
Andrew Vasquez | cb63067 | 2006-05-17 15:09:45 -0700 | [diff] [blame] | 195 | .name = QLA2XXX_DRIVER_NAME, |
Giridhar Malavali | a5326f8 | 2009-03-24 09:07:56 -0700 | [diff] [blame] | 196 | .queuecommand = qla2xxx_queuecommand, |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 197 | |
| 198 | .eh_abort_handler = qla2xxx_eh_abort, |
| 199 | .eh_device_reset_handler = qla2xxx_eh_device_reset, |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 200 | .eh_target_reset_handler = qla2xxx_eh_target_reset, |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 201 | .eh_bus_reset_handler = qla2xxx_eh_bus_reset, |
| 202 | .eh_host_reset_handler = qla2xxx_eh_host_reset, |
| 203 | |
| 204 | .slave_configure = qla2xxx_slave_configure, |
| 205 | |
| 206 | .slave_alloc = qla2xxx_slave_alloc, |
| 207 | .slave_destroy = qla2xxx_slave_destroy, |
Andrew Vasquez | ed67708 | 2007-03-12 10:41:27 -0700 | [diff] [blame] | 208 | .scan_finished = qla2xxx_scan_finished, |
| 209 | .scan_start = qla2xxx_scan_start, |
Andrew Vasquez | ce7e4af | 2005-08-26 19:09:30 -0700 | [diff] [blame] | 210 | .change_queue_depth = qla2x00_change_queue_depth, |
| 211 | .change_queue_type = qla2x00_change_queue_type, |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 212 | .this_id = -1, |
| 213 | .cmd_per_lun = 3, |
| 214 | .use_clustering = ENABLE_CLUSTERING, |
| 215 | .sg_tablesize = SG_ALL, |
| 216 | |
| 217 | .max_sectors = 0xFFFF, |
Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 218 | .shost_attrs = qla2x00_host_attrs, |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 219 | }; |
| 220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | static struct scsi_transport_template *qla2xxx_transport_template = NULL; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 222 | struct scsi_transport_template *qla2xxx_transport_vport_template = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | /* TODO Convert to inlines |
| 225 | * |
| 226 | * Timer routines |
| 227 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 229 | __inline__ void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 230 | 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] | 231 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 232 | init_timer(&vha->timer); |
| 233 | vha->timer.expires = jiffies + interval * HZ; |
| 234 | vha->timer.data = (unsigned long)vha; |
| 235 | vha->timer.function = (void (*)(unsigned long))func; |
| 236 | add_timer(&vha->timer); |
| 237 | vha->timer_active = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | static inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 241 | qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 243 | /* Currently used for 82XX only. */ |
| 244 | if (vha->device_flags & DFLG_DEV_FAILED) |
| 245 | return; |
| 246 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 247 | mod_timer(&vha->timer, jiffies + interval * HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Adrian Bunk | a824ebb | 2008-01-17 09:02:15 -0800 | [diff] [blame] | 250 | static __inline__ void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 251 | qla2x00_stop_timer(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 253 | del_timer_sync(&vha->timer); |
| 254 | vha->timer_active = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | static int qla2x00_do_dpc(void *data); |
| 258 | |
| 259 | static void qla2x00_rst_aen(scsi_qla_host_t *); |
| 260 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 261 | static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t, |
| 262 | struct req_que **, struct rsp_que **); |
Madhuranath Iyengar | e30d175 | 2010-10-15 11:27:46 -0700 | [diff] [blame] | 263 | static void qla2x00_free_fw_dump(struct qla_hw_data *); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 264 | static void qla2x00_mem_free(struct qla_hw_data *); |
| 265 | static void qla2x00_sp_free_dma(srb_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | /* -------------------------------------------------------------------------- */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 268 | static int qla2x00_alloc_queues(struct qla_hw_data *ha) |
| 269 | { |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 270 | ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues, |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 271 | GFP_KERNEL); |
| 272 | if (!ha->req_q_map) { |
| 273 | qla_printk(KERN_WARNING, ha, |
| 274 | "Unable to allocate memory for request queue ptrs\n"); |
| 275 | goto fail_req_map; |
| 276 | } |
| 277 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 278 | ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues, |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 279 | GFP_KERNEL); |
| 280 | if (!ha->rsp_q_map) { |
| 281 | qla_printk(KERN_WARNING, ha, |
| 282 | "Unable to allocate memory for response queue ptrs\n"); |
| 283 | goto fail_rsp_map; |
| 284 | } |
| 285 | set_bit(0, ha->rsp_qid_map); |
| 286 | set_bit(0, ha->req_qid_map); |
| 287 | return 1; |
| 288 | |
| 289 | fail_rsp_map: |
| 290 | kfree(ha->req_q_map); |
| 291 | ha->req_q_map = NULL; |
| 292 | fail_req_map: |
| 293 | return -ENOMEM; |
| 294 | } |
| 295 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 296 | static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req) |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 297 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 298 | if (req && req->ring) |
| 299 | dma_free_coherent(&ha->pdev->dev, |
| 300 | (req->length + 1) * sizeof(request_t), |
| 301 | req->ring, req->dma); |
| 302 | |
| 303 | kfree(req); |
| 304 | req = NULL; |
| 305 | } |
| 306 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 307 | static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp) |
| 308 | { |
| 309 | if (rsp && rsp->ring) |
| 310 | dma_free_coherent(&ha->pdev->dev, |
| 311 | (rsp->length + 1) * sizeof(response_t), |
| 312 | rsp->ring, rsp->dma); |
| 313 | |
| 314 | kfree(rsp); |
| 315 | rsp = NULL; |
| 316 | } |
| 317 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 318 | static void qla2x00_free_queues(struct qla_hw_data *ha) |
| 319 | { |
| 320 | struct req_que *req; |
| 321 | struct rsp_que *rsp; |
| 322 | int cnt; |
| 323 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 324 | for (cnt = 0; cnt < ha->max_req_queues; cnt++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 325 | req = ha->req_q_map[cnt]; |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 326 | qla2x00_free_req_que(ha, req); |
| 327 | } |
| 328 | kfree(ha->req_q_map); |
| 329 | ha->req_q_map = NULL; |
| 330 | |
| 331 | for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) { |
| 332 | rsp = ha->rsp_q_map[cnt]; |
| 333 | qla2x00_free_rsp_que(ha, rsp); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 334 | } |
| 335 | kfree(ha->rsp_q_map); |
| 336 | ha->rsp_q_map = NULL; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 337 | } |
| 338 | |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 339 | static int qla25xx_setup_mode(struct scsi_qla_host *vha) |
| 340 | { |
| 341 | uint16_t options = 0; |
| 342 | int ques, req, ret; |
| 343 | struct qla_hw_data *ha = vha->hw; |
| 344 | |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 345 | if (!(ha->fw_attributes & BIT_6)) { |
| 346 | qla_printk(KERN_INFO, ha, |
| 347 | "Firmware is not multi-queue capable\n"); |
| 348 | goto fail; |
| 349 | } |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 350 | if (ql2xmultique_tag) { |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 351 | /* create a request queue for IO */ |
| 352 | options |= BIT_7; |
| 353 | req = qla25xx_create_req_que(ha, options, 0, 0, -1, |
| 354 | QLA_DEFAULT_QUE_QOS); |
| 355 | if (!req) { |
| 356 | qla_printk(KERN_WARNING, ha, |
| 357 | "Can't create request queue\n"); |
| 358 | goto fail; |
| 359 | } |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 360 | ha->wq = create_workqueue("qla2xxx_wq"); |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 361 | vha->req = ha->req_q_map[req]; |
| 362 | options |= BIT_1; |
| 363 | for (ques = 1; ques < ha->max_rsp_queues; ques++) { |
| 364 | ret = qla25xx_create_rsp_que(ha, options, 0, 0, req); |
| 365 | if (!ret) { |
| 366 | qla_printk(KERN_WARNING, ha, |
| 367 | "Response Queue create failed\n"); |
| 368 | goto fail2; |
| 369 | } |
| 370 | } |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 371 | ha->flags.cpu_affinity_enabled = 1; |
| 372 | |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 373 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 374 | "CPU affinity mode enabled, no. of response" |
| 375 | " queues:%d, no. of request queues:%d\n", |
| 376 | ha->max_rsp_queues, ha->max_req_queues)); |
| 377 | } |
| 378 | return 0; |
| 379 | fail2: |
| 380 | qla25xx_delete_queues(vha); |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 381 | destroy_workqueue(ha->wq); |
| 382 | ha->wq = NULL; |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 383 | fail: |
| 384 | ha->mqenable = 0; |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 385 | kfree(ha->req_q_map); |
| 386 | kfree(ha->rsp_q_map); |
| 387 | ha->max_req_queues = ha->max_rsp_queues = 1; |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 388 | return 1; |
| 389 | } |
| 390 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | static char * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 392 | qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 394 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | static char *pci_bus_modes[] = { |
| 396 | "33", "66", "100", "133", |
| 397 | }; |
| 398 | uint16_t pci_bus; |
| 399 | |
| 400 | strcpy(str, "PCI"); |
| 401 | pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9; |
| 402 | if (pci_bus) { |
| 403 | strcat(str, "-X ("); |
| 404 | strcat(str, pci_bus_modes[pci_bus]); |
| 405 | } else { |
| 406 | pci_bus = (ha->pci_attr & BIT_8) >> 8; |
| 407 | strcat(str, " ("); |
| 408 | strcat(str, pci_bus_modes[pci_bus]); |
| 409 | } |
| 410 | strcat(str, " MHz)"); |
| 411 | |
| 412 | return (str); |
| 413 | } |
| 414 | |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 415 | static char * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 416 | qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str) |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 417 | { |
| 418 | static char *pci_bus_modes[] = { "33", "66", "100", "133", }; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 419 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 420 | uint32_t pci_bus; |
| 421 | int pcie_reg; |
| 422 | |
| 423 | pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP); |
| 424 | if (pcie_reg) { |
| 425 | char lwstr[6]; |
| 426 | uint16_t pcie_lstat, lspeed, lwidth; |
| 427 | |
| 428 | pcie_reg += 0x12; |
| 429 | pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat); |
| 430 | lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3); |
| 431 | lwidth = (pcie_lstat & |
| 432 | (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4; |
| 433 | |
| 434 | strcpy(str, "PCIe ("); |
| 435 | if (lspeed == 1) |
Andrew Vasquez | c87a0d8 | 2008-04-03 13:13:21 -0700 | [diff] [blame] | 436 | strcat(str, "2.5GT/s "); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 437 | else if (lspeed == 2) |
Andrew Vasquez | c87a0d8 | 2008-04-03 13:13:21 -0700 | [diff] [blame] | 438 | strcat(str, "5.0GT/s "); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 439 | else |
| 440 | strcat(str, "<unknown> "); |
| 441 | snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth); |
| 442 | strcat(str, lwstr); |
| 443 | |
| 444 | return str; |
| 445 | } |
| 446 | |
| 447 | strcpy(str, "PCI"); |
| 448 | pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8; |
| 449 | if (pci_bus == 0 || pci_bus == 8) { |
| 450 | strcat(str, " ("); |
| 451 | strcat(str, pci_bus_modes[pci_bus >> 3]); |
| 452 | } else { |
| 453 | strcat(str, "-X "); |
| 454 | if (pci_bus & BIT_2) |
| 455 | strcat(str, "Mode 2"); |
| 456 | else |
| 457 | strcat(str, "Mode 1"); |
| 458 | strcat(str, " ("); |
| 459 | strcat(str, pci_bus_modes[pci_bus & ~BIT_2]); |
| 460 | } |
| 461 | strcat(str, " MHz)"); |
| 462 | |
| 463 | return str; |
| 464 | } |
| 465 | |
Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 466 | static char * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 467 | qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | { |
| 469 | char un_str[10]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 470 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 471 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | sprintf(str, "%d.%02d.%02d ", ha->fw_major_version, |
| 473 | ha->fw_minor_version, |
| 474 | ha->fw_subminor_version); |
| 475 | |
| 476 | if (ha->fw_attributes & BIT_9) { |
| 477 | strcat(str, "FLX"); |
| 478 | return (str); |
| 479 | } |
| 480 | |
| 481 | switch (ha->fw_attributes & 0xFF) { |
| 482 | case 0x7: |
| 483 | strcat(str, "EF"); |
| 484 | break; |
| 485 | case 0x17: |
| 486 | strcat(str, "TP"); |
| 487 | break; |
| 488 | case 0x37: |
| 489 | strcat(str, "IP"); |
| 490 | break; |
| 491 | case 0x77: |
| 492 | strcat(str, "VI"); |
| 493 | break; |
| 494 | default: |
| 495 | sprintf(un_str, "(%x)", ha->fw_attributes); |
| 496 | strcat(str, un_str); |
| 497 | break; |
| 498 | } |
| 499 | if (ha->fw_attributes & 0x100) |
| 500 | strcat(str, "X"); |
| 501 | |
| 502 | return (str); |
| 503 | } |
| 504 | |
Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 505 | static char * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 506 | qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str) |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 507 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 508 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | f0883ac | 2005-07-08 17:58:43 -0700 | [diff] [blame] | 509 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 510 | sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version, |
| 511 | ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 512 | return str; |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | static inline srb_t * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 516 | 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] | 517 | struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) |
| 518 | { |
| 519 | srb_t *sp; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 520 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 521 | |
| 522 | sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC); |
| 523 | if (!sp) |
| 524 | return sp; |
| 525 | |
Giridhar Malavali | 083a469 | 2010-05-28 15:08:18 -0700 | [diff] [blame] | 526 | atomic_set(&sp->ref_count, 1); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 527 | sp->fcport = fcport; |
| 528 | sp->cmd = cmd; |
| 529 | sp->flags = 0; |
| 530 | CMD_SP(cmd) = (void *)sp; |
| 531 | cmd->scsi_done = done; |
Andrew Vasquez | cf53b06 | 2009-08-20 11:06:04 -0700 | [diff] [blame] | 532 | sp->ctx = NULL; |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 533 | |
| 534 | return sp; |
| 535 | } |
| 536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | static int |
Giridhar Malavali | a5326f8 | 2009-03-24 09:07:56 -0700 | [diff] [blame] | 538 | qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 539 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 540 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 541 | fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 542 | struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 543 | struct qla_hw_data *ha = vha->hw; |
| 544 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 545 | srb_t *sp; |
| 546 | int rval; |
| 547 | |
Giridhar Malavali | 38170fa | 2010-10-15 11:27:49 -0700 | [diff] [blame] | 548 | spin_unlock_irq(vha->host->host_lock); |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 549 | if (ha->flags.eeh_busy) { |
| 550 | if (ha->flags.pci_channel_io_perm_failure) |
Seokmann Ju | b9b12f7 | 2009-03-24 09:08:18 -0700 | [diff] [blame] | 551 | cmd->result = DID_NO_CONNECT << 16; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 552 | else |
| 553 | cmd->result = DID_REQUEUE << 16; |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 554 | goto qc24_fail_command; |
| 555 | } |
| 556 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 557 | rval = fc_remote_port_chkready(rport); |
| 558 | if (rval) { |
| 559 | cmd->result = rval; |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 560 | goto qc24_fail_command; |
| 561 | } |
| 562 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 563 | if (!vha->flags.difdix_supported && |
| 564 | scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) { |
| 565 | DEBUG2(qla_printk(KERN_ERR, ha, |
| 566 | "DIF Cap Not Reg, fail DIF capable cmd's:%x\n", |
| 567 | cmd->cmnd[0])); |
| 568 | cmd->result = DID_NO_CONNECT << 16; |
| 569 | goto qc24_fail_command; |
| 570 | } |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 571 | if (atomic_read(&fcport->state) != FCS_ONLINE) { |
| 572 | if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD || |
Giridhar Malavali | 38170fa | 2010-10-15 11:27:49 -0700 | [diff] [blame] | 573 | atomic_read(&fcport->state) == FCS_DEVICE_LOST || |
| 574 | atomic_read(&base_vha->loop_state) == LOOP_DEAD) { |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 575 | cmd->result = DID_NO_CONNECT << 16; |
| 576 | goto qc24_fail_command; |
| 577 | } |
Mike Christie | 7b59413 | 2008-08-17 15:24:40 -0500 | [diff] [blame] | 578 | goto qc24_target_busy; |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 579 | } |
| 580 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 581 | sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 582 | if (!sp) |
| 583 | goto qc24_host_busy_lock; |
| 584 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 585 | rval = ha->isp_ops->start_scsi(sp); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 586 | if (rval != QLA_SUCCESS) |
| 587 | goto qc24_host_busy_free_sp; |
| 588 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 589 | spin_lock_irq(vha->host->host_lock); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 590 | |
| 591 | return 0; |
| 592 | |
| 593 | qc24_host_busy_free_sp: |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 594 | qla2x00_sp_free_dma(sp); |
| 595 | mempool_free(sp, ha->srb_mempool); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 596 | |
| 597 | qc24_host_busy_lock: |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 598 | spin_lock_irq(vha->host->host_lock); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 599 | return SCSI_MLQUEUE_HOST_BUSY; |
| 600 | |
Mike Christie | 7b59413 | 2008-08-17 15:24:40 -0500 | [diff] [blame] | 601 | qc24_target_busy: |
Giridhar Malavali | 38170fa | 2010-10-15 11:27:49 -0700 | [diff] [blame] | 602 | spin_lock_irq(vha->host->host_lock); |
Mike Christie | 7b59413 | 2008-08-17 15:24:40 -0500 | [diff] [blame] | 603 | return SCSI_MLQUEUE_TARGET_BUSY; |
| 604 | |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 605 | qc24_fail_command: |
Giridhar Malavali | 38170fa | 2010-10-15 11:27:49 -0700 | [diff] [blame] | 606 | spin_lock_irq(vha->host->host_lock); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 607 | done(cmd); |
| 608 | |
| 609 | return 0; |
| 610 | } |
| 611 | |
| 612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | /* |
| 614 | * qla2x00_eh_wait_on_command |
| 615 | * Waits for the command to be returned by the Firmware for some |
| 616 | * max time. |
| 617 | * |
| 618 | * Input: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | * cmd = Scsi Command to wait on. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | * |
| 621 | * Return: |
| 622 | * Not Found : 0 |
| 623 | * Found : 1 |
| 624 | */ |
| 625 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 626 | qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | { |
Andrew Vasquez | fe74c71 | 2005-08-26 19:10:10 -0700 | [diff] [blame] | 628 | #define ABORT_POLLING_PERIOD 1000 |
| 629 | #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD)) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 630 | unsigned long wait_iter = ABORT_WAIT_ITER; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 631 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
| 632 | struct qla_hw_data *ha = vha->hw; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 633 | int ret = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 635 | if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) { |
| 636 | DEBUG17(qla_printk(KERN_WARNING, ha, "return:eh_wait\n")); |
| 637 | return ret; |
| 638 | } |
| 639 | |
Lalit Chandivade | d970432 | 2009-08-25 11:36:18 -0700 | [diff] [blame] | 640 | while (CMD_SP(cmd) && wait_iter--) { |
Andrew Vasquez | fe74c71 | 2005-08-26 19:10:10 -0700 | [diff] [blame] | 641 | msleep(ABORT_POLLING_PERIOD); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 642 | } |
| 643 | if (CMD_SP(cmd)) |
| 644 | ret = QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 646 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | /* |
| 650 | * qla2x00_wait_for_hba_online |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 651 | * Wait till the HBA is online after going through |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | * <= MAX_RETRIES_OF_ISP_ABORT or |
| 653 | * finally HBA is disabled ie marked offline |
| 654 | * |
| 655 | * Input: |
| 656 | * ha - pointer to host adapter structure |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 657 | * |
| 658 | * Note: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | * Does context switching-Release SPIN_LOCK |
| 660 | * (if any) before calling this routine. |
| 661 | * |
| 662 | * Return: |
| 663 | * Success (Adapter is online) : 0 |
| 664 | * Failed (Adapter is offline/disabled) : 1 |
| 665 | */ |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 666 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 667 | qla2x00_wait_for_hba_online(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | { |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 669 | int return_status; |
| 670 | unsigned long wait_online; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 671 | struct qla_hw_data *ha = vha->hw; |
| 672 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 674 | wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 675 | while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) || |
| 676 | test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) || |
| 677 | test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) || |
| 678 | ha->dpc_active) && time_before(jiffies, wait_online)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | |
| 680 | msleep(1000); |
| 681 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 682 | if (base_vha->flags.online) |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 683 | return_status = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | else |
| 685 | return_status = QLA_FUNCTION_FAILED; |
| 686 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | return (return_status); |
| 688 | } |
| 689 | |
Lalit Chandivade | 86fbee8 | 2010-05-04 15:01:32 -0700 | [diff] [blame] | 690 | /* |
| 691 | * qla2x00_wait_for_reset_ready |
| 692 | * Wait till the HBA is online after going through |
| 693 | * <= MAX_RETRIES_OF_ISP_ABORT or |
| 694 | * finally HBA is disabled ie marked offline or flash |
| 695 | * operations are in progress. |
| 696 | * |
| 697 | * Input: |
| 698 | * ha - pointer to host adapter structure |
| 699 | * |
| 700 | * Note: |
| 701 | * Does context switching-Release SPIN_LOCK |
| 702 | * (if any) before calling this routine. |
| 703 | * |
| 704 | * Return: |
| 705 | * Success (Adapter is online/no flash ops) : 0 |
| 706 | * Failed (Adapter is offline/disabled/flash ops in progress) : 1 |
| 707 | */ |
Andrew Vasquez | 3dbe756 | 2010-07-23 15:28:37 +0500 | [diff] [blame] | 708 | static int |
Lalit Chandivade | 86fbee8 | 2010-05-04 15:01:32 -0700 | [diff] [blame] | 709 | qla2x00_wait_for_reset_ready(scsi_qla_host_t *vha) |
| 710 | { |
| 711 | int return_status; |
| 712 | unsigned long wait_online; |
| 713 | struct qla_hw_data *ha = vha->hw; |
| 714 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
| 715 | |
| 716 | wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ); |
| 717 | while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) || |
| 718 | test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) || |
| 719 | test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) || |
| 720 | ha->optrom_state != QLA_SWAITING || |
| 721 | ha->dpc_active) && time_before(jiffies, wait_online)) |
| 722 | msleep(1000); |
| 723 | |
| 724 | if (base_vha->flags.online && ha->optrom_state == QLA_SWAITING) |
| 725 | return_status = QLA_SUCCESS; |
| 726 | else |
| 727 | return_status = QLA_FUNCTION_FAILED; |
| 728 | |
| 729 | DEBUG2(printk("%s return_status=%d\n", __func__, return_status)); |
| 730 | |
| 731 | return return_status; |
| 732 | } |
| 733 | |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 734 | int |
| 735 | qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha) |
| 736 | { |
| 737 | int return_status; |
| 738 | unsigned long wait_reset; |
| 739 | struct qla_hw_data *ha = vha->hw; |
| 740 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
| 741 | |
| 742 | wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ); |
| 743 | while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) || |
| 744 | test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) || |
| 745 | test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) || |
| 746 | ha->dpc_active) && time_before(jiffies, wait_reset)) { |
| 747 | |
| 748 | msleep(1000); |
| 749 | |
| 750 | if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) && |
| 751 | ha->flags.chip_reset_done) |
| 752 | break; |
| 753 | } |
| 754 | if (ha->flags.chip_reset_done) |
| 755 | return_status = QLA_SUCCESS; |
| 756 | else |
| 757 | return_status = QLA_FUNCTION_FAILED; |
| 758 | |
| 759 | return return_status; |
| 760 | } |
| 761 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | /* |
| 763 | * qla2x00_wait_for_loop_ready |
| 764 | * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 765 | * to be in LOOP_READY state. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | * Input: |
| 767 | * ha - pointer to host adapter structure |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 768 | * |
| 769 | * Note: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | * Does context switching-Release SPIN_LOCK |
| 771 | * (if any) before calling this routine. |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 772 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | * |
| 774 | * Return: |
| 775 | * Success (LOOP_READY) : 0 |
| 776 | * Failed (LOOP_NOT_READY) : 1 |
| 777 | */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 778 | static inline int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 779 | qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | { |
| 781 | int return_status = QLA_SUCCESS; |
| 782 | unsigned long loop_timeout ; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 783 | struct qla_hw_data *ha = vha->hw; |
| 784 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
| 786 | /* wait for 5 min at the max for loop to be ready */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 787 | loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 789 | while ((!atomic_read(&base_vha->loop_down_timer) && |
| 790 | atomic_read(&base_vha->loop_state) == LOOP_DOWN) || |
| 791 | atomic_read(&base_vha->loop_state) != LOOP_READY) { |
| 792 | if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) { |
Ravi Anand | 5768008 | 2006-05-17 15:08:44 -0700 | [diff] [blame] | 793 | return_status = QLA_FUNCTION_FAILED; |
| 794 | break; |
| 795 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | msleep(1000); |
| 797 | if (time_after_eq(jiffies, loop_timeout)) { |
| 798 | return_status = QLA_FUNCTION_FAILED; |
| 799 | break; |
| 800 | } |
| 801 | } |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 802 | return (return_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | } |
| 804 | |
Giridhar Malavali | 083a469 | 2010-05-28 15:08:18 -0700 | [diff] [blame] | 805 | static void |
| 806 | sp_get(struct srb *sp) |
| 807 | { |
| 808 | atomic_inc(&sp->ref_count); |
| 809 | } |
| 810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | /************************************************************************** |
| 812 | * qla2xxx_eh_abort |
| 813 | * |
| 814 | * Description: |
| 815 | * The abort function will abort the specified command. |
| 816 | * |
| 817 | * Input: |
| 818 | * cmd = Linux SCSI command packet to be aborted. |
| 819 | * |
| 820 | * Returns: |
| 821 | * Either SUCCESS or FAILED. |
| 822 | * |
| 823 | * Note: |
Michael Reed | 2ea0020 | 2006-04-27 16:25:30 -0700 | [diff] [blame] | 824 | * Only return FAILED if command not returned by firmware. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | **************************************************************************/ |
Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 826 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | qla2xxx_eh_abort(struct scsi_cmnd *cmd) |
| 828 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 829 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 830 | srb_t *sp; |
Mike Christie | 170babc | 2010-10-15 11:27:47 -0700 | [diff] [blame] | 831 | int ret; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 832 | unsigned int id, lun; |
Andrew Vasquez | 18e144d | 2005-05-27 15:04:47 -0700 | [diff] [blame] | 833 | unsigned long flags; |
Michael Reed | 2ea0020 | 2006-04-27 16:25:30 -0700 | [diff] [blame] | 834 | int wait = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 835 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | |
Christof Schmitt | 65d430f | 2009-10-30 17:59:29 +0100 | [diff] [blame] | 837 | fc_block_scsi_eh(cmd); |
Andrew Vasquez | 07db518 | 2006-10-02 12:00:49 -0700 | [diff] [blame] | 838 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 839 | if (!CMD_SP(cmd)) |
Michael Reed | 2ea0020 | 2006-04-27 16:25:30 -0700 | [diff] [blame] | 840 | return SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 842 | id = cmd->device->id; |
| 843 | lun = cmd->device->lun; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 844 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 845 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Mike Christie | 170babc | 2010-10-15 11:27:47 -0700 | [diff] [blame] | 846 | sp = (srb_t *) CMD_SP(cmd); |
| 847 | if (!sp) { |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 848 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Mike Christie | 170babc | 2010-10-15 11:27:47 -0700 | [diff] [blame] | 849 | return SUCCESS; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 850 | } |
Mike Christie | 170babc | 2010-10-15 11:27:47 -0700 | [diff] [blame] | 851 | |
| 852 | DEBUG2(printk("%s(%ld): aborting sp %p from RISC.", |
| 853 | __func__, vha->host_no, sp)); |
| 854 | |
| 855 | /* Get a reference to the sp and drop the lock.*/ |
| 856 | sp_get(sp); |
| 857 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 858 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Mike Christie | 170babc | 2010-10-15 11:27:47 -0700 | [diff] [blame] | 859 | if (ha->isp_ops->abort_command(sp)) { |
| 860 | DEBUG2(printk("%s(%ld): abort_command " |
| 861 | "mbx failed.\n", __func__, vha->host_no)); |
| 862 | ret = FAILED; |
| 863 | } else { |
| 864 | DEBUG3(printk("%s(%ld): abort_command " |
| 865 | "mbx success.\n", __func__, vha->host_no)); |
| 866 | wait = 1; |
| 867 | } |
| 868 | qla2x00_sp_compl(ha, sp); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 869 | |
| 870 | /* Wait for the command to be returned. */ |
Michael Reed | 2ea0020 | 2006-04-27 16:25:30 -0700 | [diff] [blame] | 871 | if (wait) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 872 | if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) { |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 873 | qla_printk(KERN_ERR, ha, |
Madhuranath Iyengar | 09d1dc2 | 2010-10-15 11:27:44 -0700 | [diff] [blame] | 874 | "scsi(%ld:%d:%d): Abort handler timed out -- %x.\n", |
| 875 | vha->host_no, id, lun, ret); |
Michael Reed | 2ea0020 | 2006-04-27 16:25:30 -0700 | [diff] [blame] | 876 | ret = FAILED; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 877 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 880 | qla_printk(KERN_INFO, ha, |
Madhuranath Iyengar | 09d1dc2 | 2010-10-15 11:27:44 -0700 | [diff] [blame] | 881 | "scsi(%ld:%d:%d): Abort command issued -- %d %x.\n", |
| 882 | vha->host_no, id, lun, wait, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 884 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | } |
| 886 | |
Giridhar Malavali | 4d78c97 | 2010-07-23 15:28:35 +0500 | [diff] [blame] | 887 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 888 | qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t, |
Giridhar Malavali | 4d78c97 | 2010-07-23 15:28:35 +0500 | [diff] [blame] | 889 | unsigned int l, enum nexus_wait_type type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | { |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 891 | int cnt, match, status; |
Andrew Vasquez | 18e144d | 2005-05-27 15:04:47 -0700 | [diff] [blame] | 892 | unsigned long flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 893 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 894 | struct req_que *req; |
Giridhar Malavali | 4d78c97 | 2010-07-23 15:28:35 +0500 | [diff] [blame] | 895 | srb_t *sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 897 | status = QLA_SUCCESS; |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 898 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 899 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 900 | req = vha->req; |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 901 | for (cnt = 1; status == QLA_SUCCESS && |
| 902 | cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { |
| 903 | sp = req->outstanding_cmds[cnt]; |
| 904 | if (!sp) |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 905 | continue; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 906 | if ((sp->ctx) && !IS_PROT_IO(sp)) |
Andrew Vasquez | cf53b06 | 2009-08-20 11:06:04 -0700 | [diff] [blame] | 907 | continue; |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 908 | if (vha->vp_idx != sp->fcport->vha->vp_idx) |
| 909 | continue; |
| 910 | match = 0; |
| 911 | switch (type) { |
| 912 | case WAIT_HOST: |
| 913 | match = 1; |
| 914 | break; |
| 915 | case WAIT_TARGET: |
| 916 | match = sp->cmd->device->id == t; |
| 917 | break; |
| 918 | case WAIT_LUN: |
| 919 | match = (sp->cmd->device->id == t && |
| 920 | sp->cmd->device->lun == l); |
| 921 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | } |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 923 | if (!match) |
| 924 | continue; |
| 925 | |
| 926 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 927 | status = qla2x00_eh_wait_on_command(sp->cmd); |
| 928 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 930 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 931 | |
| 932 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | } |
| 934 | |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 935 | static char *reset_errors[] = { |
| 936 | "HBA not online", |
| 937 | "HBA not ready", |
| 938 | "Task management failed", |
| 939 | "Waiting for command completions", |
| 940 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 942 | static int |
| 943 | __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type, |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 944 | struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int)) |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 945 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 946 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 947 | fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; |
| 948 | int err; |
| 949 | |
Christof Schmitt | 65d430f | 2009-10-30 17:59:29 +0100 | [diff] [blame] | 950 | fc_block_scsi_eh(cmd); |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 951 | |
| 952 | if (!fcport) |
| 953 | return FAILED; |
| 954 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 955 | qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n", |
| 956 | vha->host_no, cmd->device->id, cmd->device->lun, name); |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 957 | |
| 958 | err = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 959 | if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 960 | goto eh_reset_failed; |
| 961 | err = 1; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 962 | if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS) |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 963 | goto eh_reset_failed; |
| 964 | err = 2; |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 965 | if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1) |
| 966 | != QLA_SUCCESS) |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 967 | goto eh_reset_failed; |
| 968 | err = 3; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 969 | if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id, |
Giridhar Malavali | 4d78c97 | 2010-07-23 15:28:35 +0500 | [diff] [blame] | 970 | cmd->device->lun, type) != QLA_SUCCESS) |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 971 | goto eh_reset_failed; |
| 972 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 973 | qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n", |
| 974 | vha->host_no, cmd->device->id, cmd->device->lun, name); |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 975 | |
| 976 | return SUCCESS; |
| 977 | |
Giridhar Malavali | 4d78c97 | 2010-07-23 15:28:35 +0500 | [diff] [blame] | 978 | eh_reset_failed: |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 979 | qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n" |
| 980 | , vha->host_no, cmd->device->id, cmd->device->lun, name, |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 981 | reset_errors[err]); |
| 982 | return FAILED; |
| 983 | } |
| 984 | |
Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 985 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | qla2xxx_eh_device_reset(struct scsi_cmnd *cmd) |
| 987 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 988 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
| 989 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 991 | return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd, |
| 992 | ha->isp_ops->lun_reset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | } |
| 994 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | static int |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 996 | qla2xxx_eh_target_reset(struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 998 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
| 999 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 1001 | return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd, |
| 1002 | ha->isp_ops->target_reset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | /************************************************************************** |
| 1006 | * qla2xxx_eh_bus_reset |
| 1007 | * |
| 1008 | * Description: |
| 1009 | * The bus reset function will reset the bus and abort any executing |
| 1010 | * commands. |
| 1011 | * |
| 1012 | * Input: |
| 1013 | * cmd = Linux SCSI command packet of the command that cause the |
| 1014 | * bus reset. |
| 1015 | * |
| 1016 | * Returns: |
| 1017 | * SUCCESS/FAILURE (defined as macro in scsi.h). |
| 1018 | * |
| 1019 | **************************************************************************/ |
Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 1020 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd) |
| 1022 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1023 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1024 | fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1025 | int ret = FAILED; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1026 | unsigned int id, lun; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | |
Christof Schmitt | 65d430f | 2009-10-30 17:59:29 +0100 | [diff] [blame] | 1028 | fc_block_scsi_eh(cmd); |
Andrew Vasquez | 07db518 | 2006-10-02 12:00:49 -0700 | [diff] [blame] | 1029 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1030 | id = cmd->device->id; |
| 1031 | lun = cmd->device->lun; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1032 | |
Vladislav Bolkhovitin | b0328be | 2006-08-01 13:48:15 -0700 | [diff] [blame] | 1033 | if (!fcport) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1034 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1036 | qla_printk(KERN_INFO, vha->hw, |
Anirban Chakraborty | 749af3d | 2008-11-14 13:48:12 -0800 | [diff] [blame] | 1037 | "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1039 | if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | DEBUG2(printk("%s failed:board disabled\n",__func__)); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1041 | goto eh_bus_reset_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1044 | if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) { |
| 1045 | if (qla2x00_loop_reset(vha) == QLA_SUCCESS) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1046 | ret = SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | } |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1048 | if (ret == FAILED) |
| 1049 | goto eh_bus_reset_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | |
Andrew Vasquez | 9a41a62 | 2005-09-20 13:25:53 -0700 | [diff] [blame] | 1051 | /* Flush outstanding commands. */ |
Giridhar Malavali | 4d78c97 | 2010-07-23 15:28:35 +0500 | [diff] [blame] | 1052 | if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) != |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 1053 | QLA_SUCCESS) |
Andrew Vasquez | 9a41a62 | 2005-09-20 13:25:53 -0700 | [diff] [blame] | 1054 | ret = FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1056 | eh_bus_reset_done: |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1057 | qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__, |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1058 | (ret == FAILED) ? "failed" : "succeded"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1060 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | /************************************************************************** |
| 1064 | * qla2xxx_eh_host_reset |
| 1065 | * |
| 1066 | * Description: |
| 1067 | * The reset function will reset the Adapter. |
| 1068 | * |
| 1069 | * Input: |
| 1070 | * cmd = Linux SCSI command packet of the command that cause the |
| 1071 | * adapter reset. |
| 1072 | * |
| 1073 | * Returns: |
| 1074 | * Either SUCCESS or FAILED. |
| 1075 | * |
| 1076 | * Note: |
| 1077 | **************************************************************************/ |
Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 1078 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | qla2xxx_eh_host_reset(struct scsi_cmnd *cmd) |
| 1080 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1081 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1082 | fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1083 | struct qla_hw_data *ha = vha->hw; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1084 | int ret = FAILED; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1085 | unsigned int id, lun; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1086 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | |
Christof Schmitt | 65d430f | 2009-10-30 17:59:29 +0100 | [diff] [blame] | 1088 | fc_block_scsi_eh(cmd); |
Andrew Vasquez | 07db518 | 2006-10-02 12:00:49 -0700 | [diff] [blame] | 1089 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1090 | id = cmd->device->id; |
| 1091 | lun = cmd->device->lun; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1092 | |
Vladislav Bolkhovitin | b0328be | 2006-08-01 13:48:15 -0700 | [diff] [blame] | 1093 | if (!fcport) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1094 | return ret; |
| 1095 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | qla_printk(KERN_INFO, ha, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1097 | "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] | 1098 | |
Lalit Chandivade | 86fbee8 | 2010-05-04 15:01:32 -0700 | [diff] [blame] | 1099 | if (qla2x00_wait_for_reset_ready(vha) != QLA_SUCCESS) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1100 | goto eh_host_reset_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | |
| 1102 | /* |
| 1103 | * Fixme-may be dpc thread is active and processing |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1104 | * loop_resync,so wait a while for it to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | * be completed and then issue big hammer.Otherwise |
| 1106 | * it may cause I/O failure as big hammer marks the |
| 1107 | * devices as lost kicking of the port_down_timer |
| 1108 | * while dpc is stuck for the mailbox to complete. |
| 1109 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1110 | qla2x00_wait_for_loop_ready(vha); |
| 1111 | if (vha != base_vha) { |
| 1112 | if (qla2x00_vp_abort_isp(vha)) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1113 | goto eh_host_reset_lock; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1114 | } else { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1115 | if (IS_QLA82XX(vha->hw)) { |
| 1116 | if (!qla82xx_fcoe_ctx_reset(vha)) { |
| 1117 | /* Ctx reset success */ |
| 1118 | ret = SUCCESS; |
| 1119 | goto eh_host_reset_lock; |
| 1120 | } |
| 1121 | /* fall thru if ctx reset failed */ |
| 1122 | } |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 1123 | if (ha->wq) |
| 1124 | flush_workqueue(ha->wq); |
| 1125 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1126 | set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1127 | if (ha->isp_ops->abort_isp(base_vha)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1128 | clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); |
| 1129 | /* failed. schedule dpc to try */ |
| 1130 | set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); |
| 1131 | |
| 1132 | if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) |
| 1133 | goto eh_host_reset_lock; |
| 1134 | } |
| 1135 | clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1136 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1138 | /* Waiting for command to be returned to OS.*/ |
Giridhar Malavali | 4d78c97 | 2010-07-23 15:28:35 +0500 | [diff] [blame] | 1139 | if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) == |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1140 | QLA_SUCCESS) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1141 | ret = SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1143 | eh_host_reset_lock: |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1144 | qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__, |
| 1145 | (ret == FAILED) ? "failed" : "succeded"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1147 | return ret; |
| 1148 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | |
| 1150 | /* |
| 1151 | * qla2x00_loop_reset |
| 1152 | * Issue loop reset. |
| 1153 | * |
| 1154 | * Input: |
| 1155 | * ha = adapter block pointer. |
| 1156 | * |
| 1157 | * Returns: |
| 1158 | * 0 = success |
| 1159 | */ |
Andrew Vasquez | a4722cf | 2008-01-17 09:02:12 -0800 | [diff] [blame] | 1160 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1161 | qla2x00_loop_reset(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | { |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 1163 | int ret; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1164 | struct fc_port *fcport; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1165 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | |
Giridhar Malavali | f4c496c | 2010-05-04 15:01:33 -0700 | [diff] [blame] | 1167 | if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) { |
Andrew Vasquez | 55e5ed2 | 2010-02-18 10:07:25 -0800 | [diff] [blame] | 1168 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 1169 | if (fcport->port_type != FCT_TARGET) |
| 1170 | continue; |
| 1171 | |
| 1172 | ret = ha->isp_ops->target_reset(fcport, 0, 0); |
| 1173 | if (ret != QLA_SUCCESS) { |
| 1174 | DEBUG2_3(printk("%s(%ld): bus_reset failed: " |
| 1175 | "target_reset=%d d_id=%x.\n", __func__, |
| 1176 | vha->host_no, ret, fcport->d_id.b24)); |
| 1177 | } |
| 1178 | } |
| 1179 | } |
| 1180 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1181 | if (ha->flags.enable_lip_full_login && !IS_QLA8XXX_TYPE(ha)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1182 | ret = qla2x00_full_login_lip(vha); |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 1183 | if (ret != QLA_SUCCESS) { |
Anirban Chakraborty | 749af3d | 2008-11-14 13:48:12 -0800 | [diff] [blame] | 1184 | DEBUG2_3(printk("%s(%ld): failed: " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1185 | "full_login_lip=%d.\n", __func__, vha->host_no, |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 1186 | ret)); |
Anirban Chakraborty | 749af3d | 2008-11-14 13:48:12 -0800 | [diff] [blame] | 1187 | } |
| 1188 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 1189 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 1190 | qla2x00_mark_all_devices_lost(vha, 0); |
| 1191 | qla2x00_wait_for_loop_ready(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | } |
| 1193 | |
Andrew Vasquez | 0d6e61b | 2009-08-25 11:36:19 -0700 | [diff] [blame] | 1194 | if (ha->flags.enable_lip_reset) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1195 | ret = qla2x00_lip_reset(vha); |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 1196 | if (ret != QLA_SUCCESS) { |
Anirban Chakraborty | 749af3d | 2008-11-14 13:48:12 -0800 | [diff] [blame] | 1197 | DEBUG2_3(printk("%s(%ld): failed: " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1198 | "lip_reset=%d.\n", __func__, vha->host_no, ret)); |
| 1199 | } else |
| 1200 | qla2x00_wait_for_loop_ready(vha); |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 1201 | } |
| 1202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | /* 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] | 1204 | vha->marker_needed = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 1206 | return QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | } |
| 1208 | |
Andrew Vasquez | df4bf0b | 2008-01-31 12:33:46 -0800 | [diff] [blame] | 1209 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1210 | qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res) |
Andrew Vasquez | df4bf0b | 2008-01-31 12:33:46 -0800 | [diff] [blame] | 1211 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1212 | int que, cnt; |
Andrew Vasquez | df4bf0b | 2008-01-31 12:33:46 -0800 | [diff] [blame] | 1213 | unsigned long flags; |
| 1214 | srb_t *sp; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1215 | struct srb_ctx *ctx; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1216 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1217 | struct req_que *req; |
Andrew Vasquez | df4bf0b | 2008-01-31 12:33:46 -0800 | [diff] [blame] | 1218 | |
| 1219 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1220 | for (que = 0; que < ha->max_req_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1221 | req = ha->req_q_map[que]; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1222 | if (!req) |
| 1223 | continue; |
| 1224 | for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { |
| 1225 | sp = req->outstanding_cmds[cnt]; |
Andrew Vasquez | e612d46 | 2009-03-24 09:08:04 -0700 | [diff] [blame] | 1226 | if (sp) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1227 | req->outstanding_cmds[cnt] = NULL; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1228 | if (!sp->ctx || |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1229 | (sp->flags & SRB_FCP_CMND_DMA_VALID) || |
| 1230 | IS_PROT_IO(sp)) { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1231 | sp->cmd->result = res; |
| 1232 | qla2x00_sp_compl(ha, sp); |
| 1233 | } else { |
| 1234 | ctx = sp->ctx; |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 1235 | if (ctx->type == SRB_LOGIN_CMD || |
| 1236 | ctx->type == SRB_LOGOUT_CMD) { |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1237 | ctx->u.iocb_cmd->free(sp); |
Giridhar Malavali | db3ad7f | 2010-02-18 10:07:24 -0800 | [diff] [blame] | 1238 | } else { |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 1239 | struct fc_bsg_job *bsg_job = |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1240 | ctx->u.bsg_job; |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 1241 | if (bsg_job->request->msgcode |
| 1242 | == FC_BSG_HST_CT) |
Giridhar Malavali | db3ad7f | 2010-02-18 10:07:24 -0800 | [diff] [blame] | 1243 | kfree(sp->fcport); |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 1244 | bsg_job->req->errors = 0; |
| 1245 | bsg_job->reply->result = res; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1246 | bsg_job->job_done(bsg_job); |
Giridhar Malavali | db3ad7f | 2010-02-18 10:07:24 -0800 | [diff] [blame] | 1247 | kfree(sp->ctx); |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 1248 | mempool_free(sp, |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1249 | ha->srb_mempool); |
Giridhar Malavali | db3ad7f | 2010-02-18 10:07:24 -0800 | [diff] [blame] | 1250 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1251 | } |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1252 | } |
Andrew Vasquez | df4bf0b | 2008-01-31 12:33:46 -0800 | [diff] [blame] | 1253 | } |
| 1254 | } |
| 1255 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1256 | } |
| 1257 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1258 | static int |
| 1259 | qla2xxx_slave_alloc(struct scsi_device *sdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | { |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1261 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1263 | if (!rport || fc_remote_port_chkready(rport)) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1264 | return -ENXIO; |
| 1265 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1266 | sdev->hostdata = *(fc_port_t **)rport->dd_data; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1267 | |
| 1268 | return 0; |
| 1269 | } |
| 1270 | |
| 1271 | static int |
| 1272 | qla2xxx_slave_configure(struct scsi_device *sdev) |
| 1273 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1274 | scsi_qla_host_t *vha = shost_priv(sdev->host); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1275 | struct req_que *req = vha->req; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1276 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1277 | if (sdev->tagged_supported) |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1278 | scsi_activate_tcq(sdev, req->max_q_depth); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | else |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1280 | scsi_deactivate_tcq(sdev, req->max_q_depth); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1281 | return 0; |
| 1282 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1284 | static void |
| 1285 | qla2xxx_slave_destroy(struct scsi_device *sdev) |
| 1286 | { |
| 1287 | sdev->hostdata = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
Giridhar Malavali | c45dd30 | 2009-12-02 10:36:54 -0800 | [diff] [blame] | 1290 | static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth) |
| 1291 | { |
| 1292 | fc_port_t *fcport = (struct fc_port *) sdev->hostdata; |
| 1293 | |
| 1294 | if (!scsi_track_queue_full(sdev, qdepth)) |
| 1295 | return; |
| 1296 | |
| 1297 | DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw, |
| 1298 | "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n", |
| 1299 | fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun, |
| 1300 | sdev->queue_depth)); |
| 1301 | } |
| 1302 | |
| 1303 | static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth) |
| 1304 | { |
| 1305 | fc_port_t *fcport = sdev->hostdata; |
| 1306 | struct scsi_qla_host *vha = fcport->vha; |
| 1307 | struct qla_hw_data *ha = vha->hw; |
| 1308 | struct req_que *req = NULL; |
| 1309 | |
| 1310 | req = vha->req; |
| 1311 | if (!req) |
| 1312 | return; |
| 1313 | |
| 1314 | if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth) |
| 1315 | return; |
| 1316 | |
| 1317 | if (sdev->ordered_tags) |
| 1318 | scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth); |
| 1319 | else |
| 1320 | scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth); |
| 1321 | |
| 1322 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 1323 | "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n", |
| 1324 | fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun, |
| 1325 | sdev->queue_depth)); |
| 1326 | } |
| 1327 | |
Andrew Vasquez | ce7e4af | 2005-08-26 19:09:30 -0700 | [diff] [blame] | 1328 | static int |
Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 1329 | qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason) |
Andrew Vasquez | ce7e4af | 2005-08-26 19:09:30 -0700 | [diff] [blame] | 1330 | { |
Giridhar Malavali | c45dd30 | 2009-12-02 10:36:54 -0800 | [diff] [blame] | 1331 | switch (reason) { |
| 1332 | case SCSI_QDEPTH_DEFAULT: |
| 1333 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); |
| 1334 | break; |
| 1335 | case SCSI_QDEPTH_QFULL: |
| 1336 | qla2x00_handle_queue_full(sdev, qdepth); |
| 1337 | break; |
| 1338 | case SCSI_QDEPTH_RAMP_UP: |
| 1339 | qla2x00_adjust_sdev_qdepth_up(sdev, qdepth); |
| 1340 | break; |
| 1341 | default: |
Roel Kluin | 08002af | 2010-01-29 11:25:19 +0100 | [diff] [blame] | 1342 | return -EOPNOTSUPP; |
Giridhar Malavali | c45dd30 | 2009-12-02 10:36:54 -0800 | [diff] [blame] | 1343 | } |
Mike Christie | e881a17 | 2009-10-15 17:46:39 -0700 | [diff] [blame] | 1344 | |
Andrew Vasquez | ce7e4af | 2005-08-26 19:09:30 -0700 | [diff] [blame] | 1345 | return sdev->queue_depth; |
| 1346 | } |
| 1347 | |
| 1348 | static int |
| 1349 | qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type) |
| 1350 | { |
| 1351 | if (sdev->tagged_supported) { |
| 1352 | scsi_set_tag_type(sdev, tag_type); |
| 1353 | if (tag_type) |
| 1354 | scsi_activate_tcq(sdev, sdev->queue_depth); |
| 1355 | else |
| 1356 | scsi_deactivate_tcq(sdev, sdev->queue_depth); |
| 1357 | } else |
| 1358 | tag_type = 0; |
| 1359 | |
| 1360 | return tag_type; |
| 1361 | } |
| 1362 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | /** |
| 1364 | * qla2x00_config_dma_addressing() - Configure OS DMA addressing method. |
| 1365 | * @ha: HA context |
| 1366 | * |
| 1367 | * At exit, the @ha's flags.enable_64bit_addressing set to indicated |
| 1368 | * supported addressing method. |
| 1369 | */ |
| 1370 | static void |
Andrew Vasquez | 53303c4 | 2009-01-22 09:45:37 -0800 | [diff] [blame] | 1371 | qla2x00_config_dma_addressing(struct qla_hw_data *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | { |
Andrew Vasquez | 7524f9b | 2005-08-26 19:08:00 -0700 | [diff] [blame] | 1373 | /* Assume a 32bit DMA mask. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | ha->flags.enable_64bit_addressing = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 1376 | if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) { |
Andrew Vasquez | 7524f9b | 2005-08-26 19:08:00 -0700 | [diff] [blame] | 1377 | /* Any upper-dword bits set? */ |
| 1378 | if (MSD(dma_get_required_mask(&ha->pdev->dev)) && |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 1379 | !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) { |
Andrew Vasquez | 7524f9b | 2005-08-26 19:08:00 -0700 | [diff] [blame] | 1380 | /* Ok, a 64bit DMA mask is applicable. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | ha->flags.enable_64bit_addressing = 1; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1382 | ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64; |
| 1383 | ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64; |
Andrew Vasquez | 7524f9b | 2005-08-26 19:08:00 -0700 | [diff] [blame] | 1384 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | } |
Andrew Vasquez | 7524f9b | 2005-08-26 19:08:00 -0700 | [diff] [blame] | 1387 | |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1388 | dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32)); |
| 1389 | pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | } |
| 1391 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1392 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1393 | qla2x00_enable_intrs(struct qla_hw_data *ha) |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1394 | { |
| 1395 | unsigned long flags = 0; |
| 1396 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 1397 | |
| 1398 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1399 | ha->interrupts_on = 1; |
| 1400 | /* enable risc and host interrupts */ |
| 1401 | WRT_REG_WORD(®->ictrl, ICR_EN_INT | ICR_EN_RISC); |
| 1402 | RD_REG_WORD(®->ictrl); |
| 1403 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1404 | |
| 1405 | } |
| 1406 | |
| 1407 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1408 | qla2x00_disable_intrs(struct qla_hw_data *ha) |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1409 | { |
| 1410 | unsigned long flags = 0; |
| 1411 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 1412 | |
| 1413 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1414 | ha->interrupts_on = 0; |
| 1415 | /* disable risc and host interrupts */ |
| 1416 | WRT_REG_WORD(®->ictrl, 0); |
| 1417 | RD_REG_WORD(®->ictrl); |
| 1418 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1419 | } |
| 1420 | |
| 1421 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1422 | qla24xx_enable_intrs(struct qla_hw_data *ha) |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1423 | { |
| 1424 | unsigned long flags = 0; |
| 1425 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 1426 | |
| 1427 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1428 | ha->interrupts_on = 1; |
| 1429 | WRT_REG_DWORD(®->ictrl, ICRX_EN_RISC_INT); |
| 1430 | RD_REG_DWORD(®->ictrl); |
| 1431 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1432 | } |
| 1433 | |
| 1434 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1435 | qla24xx_disable_intrs(struct qla_hw_data *ha) |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1436 | { |
| 1437 | unsigned long flags = 0; |
| 1438 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 1439 | |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 1440 | if (IS_NOPOLLING_TYPE(ha)) |
| 1441 | return; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1442 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1443 | ha->interrupts_on = 0; |
| 1444 | WRT_REG_DWORD(®->ictrl, 0); |
| 1445 | RD_REG_DWORD(®->ictrl); |
| 1446 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1447 | } |
| 1448 | |
| 1449 | static struct isp_operations qla2100_isp_ops = { |
| 1450 | .pci_config = qla2100_pci_config, |
| 1451 | .reset_chip = qla2x00_reset_chip, |
| 1452 | .chip_diag = qla2x00_chip_diag, |
| 1453 | .config_rings = qla2x00_config_rings, |
| 1454 | .reset_adapter = qla2x00_reset_adapter, |
| 1455 | .nvram_config = qla2x00_nvram_config, |
| 1456 | .update_fw_options = qla2x00_update_fw_options, |
| 1457 | .load_risc = qla2x00_load_risc, |
| 1458 | .pci_info_str = qla2x00_pci_info_str, |
| 1459 | .fw_version_str = qla2x00_fw_version_str, |
| 1460 | .intr_handler = qla2100_intr_handler, |
| 1461 | .enable_intrs = qla2x00_enable_intrs, |
| 1462 | .disable_intrs = qla2x00_disable_intrs, |
| 1463 | .abort_command = qla2x00_abort_command, |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 1464 | .target_reset = qla2x00_abort_target, |
| 1465 | .lun_reset = qla2x00_lun_reset, |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1466 | .fabric_login = qla2x00_login_fabric, |
| 1467 | .fabric_logout = qla2x00_fabric_logout, |
| 1468 | .calc_req_entries = qla2x00_calc_iocbs_32, |
| 1469 | .build_iocbs = qla2x00_build_scsi_iocbs_32, |
| 1470 | .prep_ms_iocb = qla2x00_prep_ms_iocb, |
| 1471 | .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb, |
| 1472 | .read_nvram = qla2x00_read_nvram_data, |
| 1473 | .write_nvram = qla2x00_write_nvram_data, |
| 1474 | .fw_dump = qla2100_fw_dump, |
| 1475 | .beacon_on = NULL, |
| 1476 | .beacon_off = NULL, |
| 1477 | .beacon_blink = NULL, |
| 1478 | .read_optrom = qla2x00_read_optrom_data, |
| 1479 | .write_optrom = qla2x00_write_optrom_data, |
| 1480 | .get_flash_version = qla2x00_get_flash_version, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1481 | .start_scsi = qla2x00_start_scsi, |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1482 | .abort_isp = qla2x00_abort_isp, |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1483 | }; |
| 1484 | |
| 1485 | static struct isp_operations qla2300_isp_ops = { |
| 1486 | .pci_config = qla2300_pci_config, |
| 1487 | .reset_chip = qla2x00_reset_chip, |
| 1488 | .chip_diag = qla2x00_chip_diag, |
| 1489 | .config_rings = qla2x00_config_rings, |
| 1490 | .reset_adapter = qla2x00_reset_adapter, |
| 1491 | .nvram_config = qla2x00_nvram_config, |
| 1492 | .update_fw_options = qla2x00_update_fw_options, |
| 1493 | .load_risc = qla2x00_load_risc, |
| 1494 | .pci_info_str = qla2x00_pci_info_str, |
| 1495 | .fw_version_str = qla2x00_fw_version_str, |
| 1496 | .intr_handler = qla2300_intr_handler, |
| 1497 | .enable_intrs = qla2x00_enable_intrs, |
| 1498 | .disable_intrs = qla2x00_disable_intrs, |
| 1499 | .abort_command = qla2x00_abort_command, |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 1500 | .target_reset = qla2x00_abort_target, |
| 1501 | .lun_reset = qla2x00_lun_reset, |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1502 | .fabric_login = qla2x00_login_fabric, |
| 1503 | .fabric_logout = qla2x00_fabric_logout, |
| 1504 | .calc_req_entries = qla2x00_calc_iocbs_32, |
| 1505 | .build_iocbs = qla2x00_build_scsi_iocbs_32, |
| 1506 | .prep_ms_iocb = qla2x00_prep_ms_iocb, |
| 1507 | .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb, |
| 1508 | .read_nvram = qla2x00_read_nvram_data, |
| 1509 | .write_nvram = qla2x00_write_nvram_data, |
| 1510 | .fw_dump = qla2300_fw_dump, |
| 1511 | .beacon_on = qla2x00_beacon_on, |
| 1512 | .beacon_off = qla2x00_beacon_off, |
| 1513 | .beacon_blink = qla2x00_beacon_blink, |
| 1514 | .read_optrom = qla2x00_read_optrom_data, |
| 1515 | .write_optrom = qla2x00_write_optrom_data, |
| 1516 | .get_flash_version = qla2x00_get_flash_version, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1517 | .start_scsi = qla2x00_start_scsi, |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1518 | .abort_isp = qla2x00_abort_isp, |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1519 | }; |
| 1520 | |
| 1521 | static struct isp_operations qla24xx_isp_ops = { |
| 1522 | .pci_config = qla24xx_pci_config, |
| 1523 | .reset_chip = qla24xx_reset_chip, |
| 1524 | .chip_diag = qla24xx_chip_diag, |
| 1525 | .config_rings = qla24xx_config_rings, |
| 1526 | .reset_adapter = qla24xx_reset_adapter, |
| 1527 | .nvram_config = qla24xx_nvram_config, |
| 1528 | .update_fw_options = qla24xx_update_fw_options, |
| 1529 | .load_risc = qla24xx_load_risc, |
| 1530 | .pci_info_str = qla24xx_pci_info_str, |
| 1531 | .fw_version_str = qla24xx_fw_version_str, |
| 1532 | .intr_handler = qla24xx_intr_handler, |
| 1533 | .enable_intrs = qla24xx_enable_intrs, |
| 1534 | .disable_intrs = qla24xx_disable_intrs, |
| 1535 | .abort_command = qla24xx_abort_command, |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 1536 | .target_reset = qla24xx_abort_target, |
| 1537 | .lun_reset = qla24xx_lun_reset, |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1538 | .fabric_login = qla24xx_login_fabric, |
| 1539 | .fabric_logout = qla24xx_fabric_logout, |
| 1540 | .calc_req_entries = NULL, |
| 1541 | .build_iocbs = NULL, |
| 1542 | .prep_ms_iocb = qla24xx_prep_ms_iocb, |
| 1543 | .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb, |
| 1544 | .read_nvram = qla24xx_read_nvram_data, |
| 1545 | .write_nvram = qla24xx_write_nvram_data, |
| 1546 | .fw_dump = qla24xx_fw_dump, |
| 1547 | .beacon_on = qla24xx_beacon_on, |
| 1548 | .beacon_off = qla24xx_beacon_off, |
| 1549 | .beacon_blink = qla24xx_beacon_blink, |
| 1550 | .read_optrom = qla24xx_read_optrom_data, |
| 1551 | .write_optrom = qla24xx_write_optrom_data, |
| 1552 | .get_flash_version = qla24xx_get_flash_version, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1553 | .start_scsi = qla24xx_start_scsi, |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1554 | .abort_isp = qla2x00_abort_isp, |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1555 | }; |
| 1556 | |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1557 | static struct isp_operations qla25xx_isp_ops = { |
| 1558 | .pci_config = qla25xx_pci_config, |
| 1559 | .reset_chip = qla24xx_reset_chip, |
| 1560 | .chip_diag = qla24xx_chip_diag, |
| 1561 | .config_rings = qla24xx_config_rings, |
| 1562 | .reset_adapter = qla24xx_reset_adapter, |
| 1563 | .nvram_config = qla24xx_nvram_config, |
| 1564 | .update_fw_options = qla24xx_update_fw_options, |
| 1565 | .load_risc = qla24xx_load_risc, |
| 1566 | .pci_info_str = qla24xx_pci_info_str, |
| 1567 | .fw_version_str = qla24xx_fw_version_str, |
| 1568 | .intr_handler = qla24xx_intr_handler, |
| 1569 | .enable_intrs = qla24xx_enable_intrs, |
| 1570 | .disable_intrs = qla24xx_disable_intrs, |
| 1571 | .abort_command = qla24xx_abort_command, |
Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 1572 | .target_reset = qla24xx_abort_target, |
| 1573 | .lun_reset = qla24xx_lun_reset, |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1574 | .fabric_login = qla24xx_login_fabric, |
| 1575 | .fabric_logout = qla24xx_fabric_logout, |
| 1576 | .calc_req_entries = NULL, |
| 1577 | .build_iocbs = NULL, |
| 1578 | .prep_ms_iocb = qla24xx_prep_ms_iocb, |
| 1579 | .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb, |
| 1580 | .read_nvram = qla25xx_read_nvram_data, |
| 1581 | .write_nvram = qla25xx_write_nvram_data, |
| 1582 | .fw_dump = qla25xx_fw_dump, |
| 1583 | .beacon_on = qla24xx_beacon_on, |
| 1584 | .beacon_off = qla24xx_beacon_off, |
| 1585 | .beacon_blink = qla24xx_beacon_blink, |
Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1586 | .read_optrom = qla25xx_read_optrom_data, |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1587 | .write_optrom = qla24xx_write_optrom_data, |
| 1588 | .get_flash_version = qla24xx_get_flash_version, |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1589 | .start_scsi = qla24xx_dif_start_scsi, |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1590 | .abort_isp = qla2x00_abort_isp, |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1591 | }; |
| 1592 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1593 | static struct isp_operations qla81xx_isp_ops = { |
| 1594 | .pci_config = qla25xx_pci_config, |
| 1595 | .reset_chip = qla24xx_reset_chip, |
| 1596 | .chip_diag = qla24xx_chip_diag, |
| 1597 | .config_rings = qla24xx_config_rings, |
| 1598 | .reset_adapter = qla24xx_reset_adapter, |
| 1599 | .nvram_config = qla81xx_nvram_config, |
| 1600 | .update_fw_options = qla81xx_update_fw_options, |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 1601 | .load_risc = qla81xx_load_risc, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1602 | .pci_info_str = qla24xx_pci_info_str, |
| 1603 | .fw_version_str = qla24xx_fw_version_str, |
| 1604 | .intr_handler = qla24xx_intr_handler, |
| 1605 | .enable_intrs = qla24xx_enable_intrs, |
| 1606 | .disable_intrs = qla24xx_disable_intrs, |
| 1607 | .abort_command = qla24xx_abort_command, |
| 1608 | .target_reset = qla24xx_abort_target, |
| 1609 | .lun_reset = qla24xx_lun_reset, |
| 1610 | .fabric_login = qla24xx_login_fabric, |
| 1611 | .fabric_logout = qla24xx_fabric_logout, |
| 1612 | .calc_req_entries = NULL, |
| 1613 | .build_iocbs = NULL, |
| 1614 | .prep_ms_iocb = qla24xx_prep_ms_iocb, |
| 1615 | .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb, |
Andrew Vasquez | 3d79038 | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 1616 | .read_nvram = NULL, |
| 1617 | .write_nvram = NULL, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1618 | .fw_dump = qla81xx_fw_dump, |
| 1619 | .beacon_on = qla24xx_beacon_on, |
| 1620 | .beacon_off = qla24xx_beacon_off, |
| 1621 | .beacon_blink = qla24xx_beacon_blink, |
| 1622 | .read_optrom = qla25xx_read_optrom_data, |
| 1623 | .write_optrom = qla24xx_write_optrom_data, |
| 1624 | .get_flash_version = qla24xx_get_flash_version, |
Arun Easi | ba77ef5 | 2010-05-28 15:08:27 -0700 | [diff] [blame] | 1625 | .start_scsi = qla24xx_dif_start_scsi, |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1626 | .abort_isp = qla2x00_abort_isp, |
| 1627 | }; |
| 1628 | |
| 1629 | static struct isp_operations qla82xx_isp_ops = { |
| 1630 | .pci_config = qla82xx_pci_config, |
| 1631 | .reset_chip = qla82xx_reset_chip, |
| 1632 | .chip_diag = qla24xx_chip_diag, |
| 1633 | .config_rings = qla82xx_config_rings, |
| 1634 | .reset_adapter = qla24xx_reset_adapter, |
| 1635 | .nvram_config = qla81xx_nvram_config, |
| 1636 | .update_fw_options = qla24xx_update_fw_options, |
| 1637 | .load_risc = qla82xx_load_risc, |
| 1638 | .pci_info_str = qla82xx_pci_info_str, |
| 1639 | .fw_version_str = qla24xx_fw_version_str, |
| 1640 | .intr_handler = qla82xx_intr_handler, |
| 1641 | .enable_intrs = qla82xx_enable_intrs, |
| 1642 | .disable_intrs = qla82xx_disable_intrs, |
| 1643 | .abort_command = qla24xx_abort_command, |
| 1644 | .target_reset = qla24xx_abort_target, |
| 1645 | .lun_reset = qla24xx_lun_reset, |
| 1646 | .fabric_login = qla24xx_login_fabric, |
| 1647 | .fabric_logout = qla24xx_fabric_logout, |
| 1648 | .calc_req_entries = NULL, |
| 1649 | .build_iocbs = NULL, |
| 1650 | .prep_ms_iocb = qla24xx_prep_ms_iocb, |
| 1651 | .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb, |
| 1652 | .read_nvram = qla24xx_read_nvram_data, |
| 1653 | .write_nvram = qla24xx_write_nvram_data, |
| 1654 | .fw_dump = qla24xx_fw_dump, |
| 1655 | .beacon_on = qla24xx_beacon_on, |
| 1656 | .beacon_off = qla24xx_beacon_off, |
| 1657 | .beacon_blink = qla24xx_beacon_blink, |
| 1658 | .read_optrom = qla82xx_read_optrom_data, |
| 1659 | .write_optrom = qla82xx_write_optrom_data, |
| 1660 | .get_flash_version = qla24xx_get_flash_version, |
| 1661 | .start_scsi = qla82xx_start_scsi, |
| 1662 | .abort_isp = qla82xx_abort_isp, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1663 | }; |
| 1664 | |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1665 | static inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1666 | qla2x00_set_isp_flags(struct qla_hw_data *ha) |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1667 | { |
| 1668 | ha->device_type = DT_EXTENDED_IDS; |
| 1669 | switch (ha->pdev->device) { |
| 1670 | case PCI_DEVICE_ID_QLOGIC_ISP2100: |
| 1671 | ha->device_type |= DT_ISP2100; |
| 1672 | ha->device_type &= ~DT_EXTENDED_IDS; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1673 | ha->fw_srisc_address = RISC_START_ADDRESS_2100; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1674 | break; |
| 1675 | case PCI_DEVICE_ID_QLOGIC_ISP2200: |
| 1676 | ha->device_type |= DT_ISP2200; |
| 1677 | ha->device_type &= ~DT_EXTENDED_IDS; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1678 | ha->fw_srisc_address = RISC_START_ADDRESS_2100; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1679 | break; |
| 1680 | case PCI_DEVICE_ID_QLOGIC_ISP2300: |
| 1681 | ha->device_type |= DT_ISP2300; |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 1682 | ha->device_type |= DT_ZIO_SUPPORTED; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1683 | ha->fw_srisc_address = RISC_START_ADDRESS_2300; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1684 | break; |
| 1685 | case PCI_DEVICE_ID_QLOGIC_ISP2312: |
| 1686 | ha->device_type |= DT_ISP2312; |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 1687 | ha->device_type |= DT_ZIO_SUPPORTED; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1688 | ha->fw_srisc_address = RISC_START_ADDRESS_2300; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1689 | break; |
| 1690 | case PCI_DEVICE_ID_QLOGIC_ISP2322: |
| 1691 | ha->device_type |= DT_ISP2322; |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 1692 | ha->device_type |= DT_ZIO_SUPPORTED; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1693 | if (ha->pdev->subsystem_vendor == 0x1028 && |
| 1694 | ha->pdev->subsystem_device == 0x0170) |
| 1695 | ha->device_type |= DT_OEM_001; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1696 | ha->fw_srisc_address = RISC_START_ADDRESS_2300; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1697 | break; |
| 1698 | case PCI_DEVICE_ID_QLOGIC_ISP6312: |
| 1699 | ha->device_type |= DT_ISP6312; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1700 | ha->fw_srisc_address = RISC_START_ADDRESS_2300; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1701 | break; |
| 1702 | case PCI_DEVICE_ID_QLOGIC_ISP6322: |
| 1703 | ha->device_type |= DT_ISP6322; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1704 | ha->fw_srisc_address = RISC_START_ADDRESS_2300; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1705 | break; |
| 1706 | case PCI_DEVICE_ID_QLOGIC_ISP2422: |
| 1707 | ha->device_type |= DT_ISP2422; |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 1708 | ha->device_type |= DT_ZIO_SUPPORTED; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1709 | ha->device_type |= DT_FWI2; |
Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 1710 | ha->device_type |= DT_IIDMA; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1711 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1712 | break; |
| 1713 | case PCI_DEVICE_ID_QLOGIC_ISP2432: |
| 1714 | ha->device_type |= DT_ISP2432; |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 1715 | ha->device_type |= DT_ZIO_SUPPORTED; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1716 | ha->device_type |= DT_FWI2; |
Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 1717 | ha->device_type |= DT_IIDMA; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1718 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1719 | break; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1720 | case PCI_DEVICE_ID_QLOGIC_ISP8432: |
| 1721 | ha->device_type |= DT_ISP8432; |
| 1722 | ha->device_type |= DT_ZIO_SUPPORTED; |
| 1723 | ha->device_type |= DT_FWI2; |
| 1724 | ha->device_type |= DT_IIDMA; |
| 1725 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
| 1726 | break; |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 1727 | case PCI_DEVICE_ID_QLOGIC_ISP5422: |
| 1728 | ha->device_type |= DT_ISP5422; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1729 | ha->device_type |= DT_FWI2; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1730 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1731 | break; |
andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 1732 | case PCI_DEVICE_ID_QLOGIC_ISP5432: |
| 1733 | ha->device_type |= DT_ISP5432; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1734 | ha->device_type |= DT_FWI2; |
Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1735 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1736 | break; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1737 | case PCI_DEVICE_ID_QLOGIC_ISP2532: |
| 1738 | ha->device_type |= DT_ISP2532; |
| 1739 | ha->device_type |= DT_ZIO_SUPPORTED; |
| 1740 | ha->device_type |= DT_FWI2; |
| 1741 | ha->device_type |= DT_IIDMA; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1742 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
| 1743 | break; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1744 | case PCI_DEVICE_ID_QLOGIC_ISP8001: |
| 1745 | ha->device_type |= DT_ISP8001; |
| 1746 | ha->device_type |= DT_ZIO_SUPPORTED; |
| 1747 | ha->device_type |= DT_FWI2; |
| 1748 | ha->device_type |= DT_IIDMA; |
| 1749 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
| 1750 | break; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1751 | case PCI_DEVICE_ID_QLOGIC_ISP8021: |
| 1752 | ha->device_type |= DT_ISP8021; |
| 1753 | ha->device_type |= DT_ZIO_SUPPORTED; |
| 1754 | ha->device_type |= DT_FWI2; |
| 1755 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
| 1756 | /* Initialize 82XX ISP flags */ |
| 1757 | qla82xx_init_flags(ha); |
| 1758 | break; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1759 | } |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 1760 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1761 | if (IS_QLA82XX(ha)) |
| 1762 | ha->port_no = !(ha->portnum & 1); |
| 1763 | else |
| 1764 | /* Get adapter physical port no from interrupt pin register. */ |
| 1765 | pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no); |
| 1766 | |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 1767 | if (ha->port_no & 1) |
| 1768 | ha->flags.port0 = 1; |
| 1769 | else |
| 1770 | ha->flags.port0 = 0; |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1771 | } |
| 1772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1774 | qla2x00_iospace_config(struct qla_hw_data *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | { |
Andrew Vasquez | 3776541 | 2008-01-17 09:02:09 -0800 | [diff] [blame] | 1776 | resource_size_t pio; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1777 | uint16_t msix; |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 1778 | int cpus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1780 | if (IS_QLA82XX(ha)) |
| 1781 | return qla82xx_iospace_config(ha); |
| 1782 | |
Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1783 | if (pci_request_selected_regions(ha->pdev, ha->bars, |
| 1784 | QLA2XXX_DRIVER_NAME)) { |
| 1785 | qla_printk(KERN_WARNING, ha, |
| 1786 | "Failed to reserve PIO/MMIO regions (%s)\n", |
| 1787 | pci_name(ha->pdev)); |
| 1788 | |
| 1789 | goto iospace_error_exit; |
| 1790 | } |
| 1791 | if (!(ha->bars & 1)) |
| 1792 | goto skip_pio; |
| 1793 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1794 | /* We only need PIO for Flash operations on ISP2312 v2 chips. */ |
| 1795 | pio = pci_resource_start(ha->pdev, 0); |
Andrew Vasquez | 3776541 | 2008-01-17 09:02:09 -0800 | [diff] [blame] | 1796 | if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) { |
| 1797 | if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | qla_printk(KERN_WARNING, ha, |
| 1799 | "Invalid PCI I/O region size (%s)...\n", |
| 1800 | pci_name(ha->pdev)); |
| 1801 | pio = 0; |
| 1802 | } |
| 1803 | } else { |
| 1804 | qla_printk(KERN_WARNING, ha, |
| 1805 | "region #0 not a PIO resource (%s)...\n", |
| 1806 | pci_name(ha->pdev)); |
| 1807 | pio = 0; |
| 1808 | } |
Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1809 | ha->pio_address = pio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | |
Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1811 | skip_pio: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | /* Use MMIO operations for all accesses. */ |
Andrew Vasquez | 3776541 | 2008-01-17 09:02:09 -0800 | [diff] [blame] | 1813 | if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | qla_printk(KERN_ERR, ha, |
Andrew Vasquez | 3776541 | 2008-01-17 09:02:09 -0800 | [diff] [blame] | 1815 | "region #1 not an MMIO resource (%s), aborting\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | pci_name(ha->pdev)); |
| 1817 | goto iospace_error_exit; |
| 1818 | } |
Andrew Vasquez | 3776541 | 2008-01-17 09:02:09 -0800 | [diff] [blame] | 1819 | if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | qla_printk(KERN_ERR, ha, |
| 1821 | "Invalid PCI mem region size (%s), aborting\n", |
| 1822 | pci_name(ha->pdev)); |
| 1823 | goto iospace_error_exit; |
| 1824 | } |
| 1825 | |
Andrew Vasquez | 3776541 | 2008-01-17 09:02:09 -0800 | [diff] [blame] | 1826 | ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | if (!ha->iobase) { |
| 1828 | qla_printk(KERN_ERR, ha, |
| 1829 | "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev)); |
| 1830 | |
| 1831 | goto iospace_error_exit; |
| 1832 | } |
| 1833 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1834 | /* Determine queue resources */ |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1835 | ha->max_req_queues = ha->max_rsp_queues = 1; |
Michael Hernandez | d84a47c | 2010-03-19 16:59:18 -0700 | [diff] [blame] | 1836 | if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) || |
| 1837 | (ql2xmaxqueues > 1 && ql2xmultique_tag) || |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1838 | (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))) |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1839 | goto mqiobase_exit; |
Michael Hernandez | d84a47c | 2010-03-19 16:59:18 -0700 | [diff] [blame] | 1840 | |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1841 | ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3), |
| 1842 | pci_resource_len(ha->pdev, 3)); |
| 1843 | if (ha->mqiobase) { |
| 1844 | /* Read MSIX vector size of the board */ |
| 1845 | pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix); |
| 1846 | ha->msix_count = msix; |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 1847 | /* Max queues are bounded by available msix vectors */ |
| 1848 | /* queue 0 uses two msix vectors */ |
| 1849 | if (ql2xmultique_tag) { |
| 1850 | cpus = num_online_cpus(); |
Anirban Chakraborty | 27dc9c5 | 2009-06-17 10:30:28 -0700 | [diff] [blame] | 1851 | ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ? |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 1852 | (cpus + 1) : (ha->msix_count - 1); |
| 1853 | ha->max_req_queues = 2; |
| 1854 | } else if (ql2xmaxqueues > 1) { |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1855 | ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ? |
| 1856 | QLA_MQ_SIZE : ql2xmaxqueues; |
| 1857 | DEBUG2(qla_printk(KERN_INFO, ha, "QoS mode set, max no" |
| 1858 | " of request queues:%d\n", ha->max_req_queues)); |
| 1859 | } |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 1860 | qla_printk(KERN_INFO, ha, |
| 1861 | "MSI-X vector count: %d\n", msix); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1862 | } else |
| 1863 | qla_printk(KERN_INFO, ha, "BAR 3 not enabled\n"); |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1864 | |
| 1865 | mqiobase_exit: |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1866 | ha->msix_count = ha->max_rsp_queues + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | return (0); |
| 1868 | |
| 1869 | iospace_error_exit: |
| 1870 | return (-ENOMEM); |
| 1871 | } |
| 1872 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1873 | static void |
Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 1874 | qla2xxx_scan_start(struct Scsi_Host *shost) |
| 1875 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1876 | scsi_qla_host_t *vha = shost_priv(shost); |
Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 1877 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 1878 | if (vha->hw->flags.running_gold_fw) |
| 1879 | return; |
| 1880 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1881 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 1882 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 1883 | set_bit(RSCN_UPDATE, &vha->dpc_flags); |
| 1884 | set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags); |
Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | static int |
| 1888 | qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 1889 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1890 | scsi_qla_host_t *vha = shost_priv(shost); |
Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 1891 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1892 | if (!vha->host) |
Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 1893 | return 1; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1894 | if (time > vha->hw->loop_reset_delay * HZ) |
Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 1895 | return 1; |
| 1896 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1897 | return atomic_read(&vha->loop_state) == LOOP_READY; |
Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 1898 | } |
| 1899 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | /* |
| 1901 | * PCI driver interface |
| 1902 | */ |
Andrew Vasquez | 7ee6139 | 2006-06-23 16:11:22 -0700 | [diff] [blame] | 1903 | static int __devinit |
| 1904 | 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] | 1905 | { |
Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1906 | int ret = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | struct Scsi_Host *host; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1908 | scsi_qla_host_t *base_vha = NULL; |
| 1909 | struct qla_hw_data *ha; |
Andrew Vasquez | 29856e2 | 2007-08-12 18:22:52 -0700 | [diff] [blame] | 1910 | char pci_info[30]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | char fw_str[30]; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 1912 | struct scsi_host_template *sht; |
Anirban Chakraborty | c51da4e | 2008-11-10 15:53:20 -0800 | [diff] [blame] | 1913 | int bars, max_id, mem_only = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1914 | uint16_t req_length = 0, rsp_length = 0; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1915 | struct req_que *req = NULL; |
| 1916 | struct rsp_que *rsp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | |
Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1918 | bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO); |
Giridhar Malavali | a5326f8 | 2009-03-24 09:07:56 -0700 | [diff] [blame] | 1919 | sht = &qla2xxx_driver_template; |
Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1920 | if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 || |
| 1921 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 || |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1922 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 || |
Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1923 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 || |
| 1924 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 || |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1925 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 || |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1926 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 || |
| 1927 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021) { |
Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1928 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 1929 | mem_only = 1; |
Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1930 | } |
| 1931 | |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 1932 | if (mem_only) { |
| 1933 | if (pci_enable_device_mem(pdev)) |
| 1934 | goto probe_out; |
| 1935 | } else { |
| 1936 | if (pci_enable_device(pdev)) |
| 1937 | goto probe_out; |
| 1938 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | |
Jesse Barnes | 0927678 | 2008-10-18 17:33:19 -0700 | [diff] [blame] | 1940 | /* This may fail but that's ok */ |
| 1941 | pci_enable_pcie_error_reporting(pdev); |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 1942 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1943 | ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL); |
| 1944 | if (!ha) { |
| 1945 | DEBUG(printk("Unable to allocate memory for ha\n")); |
| 1946 | goto probe_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1948 | ha->pdev = pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | |
| 1950 | /* Clear our data area */ |
Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1951 | ha->bars = bars; |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 1952 | ha->mem_only = mem_only; |
Andrew Vasquez | df4bf0b | 2008-01-31 12:33:46 -0800 | [diff] [blame] | 1953 | spin_lock_init(&ha->hardware_lock); |
Andrew Vasquez | 339aa70 | 2010-10-15 11:27:45 -0700 | [diff] [blame] | 1954 | spin_lock_init(&ha->vport_slock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1956 | /* Set ISP-type information. */ |
| 1957 | qla2x00_set_isp_flags(ha); |
Duane Grigsby | ca79cf6 | 2009-12-15 21:29:47 -0800 | [diff] [blame] | 1958 | |
| 1959 | /* Set EEH reset type to fundamental if required by hba */ |
| 1960 | if ( IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha)) { |
| 1961 | pdev->needs_freset = 1; |
Duane Grigsby | ca79cf6 | 2009-12-15 21:29:47 -0800 | [diff] [blame] | 1962 | } |
| 1963 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | /* Configure PCI I/O space */ |
| 1965 | ret = qla2x00_iospace_config(ha); |
Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1966 | if (ret) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1967 | goto probe_hw_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | qla_printk(KERN_INFO, ha, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 1970 | "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq, |
| 1971 | ha->iobase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | ha->prev_topology = 0; |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 1974 | ha->init_cb_size = sizeof(init_cb_t); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 1975 | ha->link_data_rate = PORT_SPEED_UNKNOWN; |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 1976 | ha->optrom_size = OPTROM_SIZE_2300; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1978 | /* Assign ISP specific operations. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1979 | max_id = MAX_TARGETS_2200; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | if (IS_QLA2100(ha)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1981 | max_id = MAX_TARGETS_2100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | ha->mbx_count = MAILBOX_REGISTER_COUNT_2100; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1983 | req_length = REQUEST_ENTRY_CNT_2100; |
| 1984 | rsp_length = RESPONSE_ENTRY_CNT_2100; |
| 1985 | ha->max_loop_id = SNS_LAST_LOOP_ID_2100; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1986 | ha->gid_list_info_size = 4; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1987 | ha->flash_conf_off = ~0; |
| 1988 | ha->flash_data_off = ~0; |
| 1989 | ha->nvram_conf_off = ~0; |
| 1990 | ha->nvram_data_off = ~0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1991 | ha->isp_ops = &qla2100_isp_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | } else if (IS_QLA2200(ha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1994 | req_length = REQUEST_ENTRY_CNT_2200; |
| 1995 | rsp_length = RESPONSE_ENTRY_CNT_2100; |
| 1996 | ha->max_loop_id = SNS_LAST_LOOP_ID_2100; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1997 | ha->gid_list_info_size = 4; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1998 | ha->flash_conf_off = ~0; |
| 1999 | ha->flash_data_off = ~0; |
| 2000 | ha->nvram_conf_off = ~0; |
| 2001 | ha->nvram_data_off = ~0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2002 | ha->isp_ops = &qla2100_isp_ops; |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 2003 | } else if (IS_QLA23XX(ha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2005 | req_length = REQUEST_ENTRY_CNT_2200; |
| 2006 | rsp_length = RESPONSE_ENTRY_CNT_2300; |
| 2007 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2008 | ha->gid_list_info_size = 6; |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2009 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 2010 | ha->optrom_size = OPTROM_SIZE_2322; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 2011 | ha->flash_conf_off = ~0; |
| 2012 | ha->flash_data_off = ~0; |
| 2013 | ha->nvram_conf_off = ~0; |
| 2014 | ha->nvram_data_off = ~0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2015 | ha->isp_ops = &qla2300_isp_ops; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2016 | } else if (IS_QLA24XX_TYPE(ha)) { |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 2017 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2018 | req_length = REQUEST_ENTRY_CNT_24XX; |
| 2019 | rsp_length = RESPONSE_ENTRY_CNT_2300; |
| 2020 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2021 | ha->init_cb_size = sizeof(struct mid_init_cb_24xx); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 2022 | ha->gid_list_info_size = 8; |
andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 2023 | ha->optrom_size = OPTROM_SIZE_24XX; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2024 | ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2025 | ha->isp_ops = &qla24xx_isp_ops; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 2026 | ha->flash_conf_off = FARX_ACCESS_FLASH_CONF; |
| 2027 | ha->flash_data_off = FARX_ACCESS_FLASH_DATA; |
| 2028 | ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF; |
| 2029 | ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2030 | } else if (IS_QLA25XX(ha)) { |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2031 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2032 | req_length = REQUEST_ENTRY_CNT_24XX; |
| 2033 | rsp_length = RESPONSE_ENTRY_CNT_2300; |
| 2034 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2035 | ha->init_cb_size = sizeof(struct mid_init_cb_24xx); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2036 | ha->gid_list_info_size = 8; |
| 2037 | ha->optrom_size = OPTROM_SIZE_25XX; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2038 | ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2039 | ha->isp_ops = &qla25xx_isp_ops; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 2040 | ha->flash_conf_off = FARX_ACCESS_FLASH_CONF; |
| 2041 | ha->flash_data_off = FARX_ACCESS_FLASH_DATA; |
| 2042 | ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF; |
| 2043 | ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA; |
| 2044 | } else if (IS_QLA81XX(ha)) { |
| 2045 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
| 2046 | req_length = REQUEST_ENTRY_CNT_24XX; |
| 2047 | rsp_length = RESPONSE_ENTRY_CNT_2300; |
| 2048 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; |
| 2049 | ha->init_cb_size = sizeof(struct mid_init_cb_81xx); |
| 2050 | ha->gid_list_info_size = 8; |
| 2051 | ha->optrom_size = OPTROM_SIZE_81XX; |
Anirban Chakraborty | 40859ae | 2009-06-03 09:55:16 -0700 | [diff] [blame] | 2052 | ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 2053 | ha->isp_ops = &qla81xx_isp_ops; |
| 2054 | ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX; |
| 2055 | ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX; |
| 2056 | ha->nvram_conf_off = ~0; |
| 2057 | ha->nvram_data_off = ~0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2058 | } else if (IS_QLA82XX(ha)) { |
| 2059 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
| 2060 | req_length = REQUEST_ENTRY_CNT_82XX; |
| 2061 | rsp_length = RESPONSE_ENTRY_CNT_82XX; |
| 2062 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; |
| 2063 | ha->init_cb_size = sizeof(struct mid_init_cb_81xx); |
| 2064 | ha->gid_list_info_size = 8; |
| 2065 | ha->optrom_size = OPTROM_SIZE_82XX; |
| 2066 | ha->isp_ops = &qla82xx_isp_ops; |
| 2067 | ha->flash_conf_off = FARX_ACCESS_FLASH_CONF; |
| 2068 | ha->flash_data_off = FARX_ACCESS_FLASH_DATA; |
| 2069 | ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF; |
| 2070 | ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | |
matthias@kaehlcke.net | 6c2f527 | 2008-05-12 22:21:11 -0700 | [diff] [blame] | 2073 | mutex_init(&ha->vport_lock); |
Marcus Barrow | 0b05a1f | 2008-01-17 09:02:13 -0800 | [diff] [blame] | 2074 | init_completion(&ha->mbx_cmd_comp); |
| 2075 | complete(&ha->mbx_cmd_comp); |
| 2076 | init_completion(&ha->mbx_intr_comp); |
Sarang Radke | 23f2ebd | 2010-05-28 15:08:21 -0700 | [diff] [blame] | 2077 | init_completion(&ha->dcbx_comp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2079 | set_bit(0, (unsigned long *) ha->vp_idx_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | |
Andrew Vasquez | 53303c4 | 2009-01-22 09:45:37 -0800 | [diff] [blame] | 2081 | qla2x00_config_dma_addressing(ha); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2082 | ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2083 | if (!ret) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | qla_printk(KERN_WARNING, ha, |
| 2085 | "[ERROR] Failed to allocate memory for adapter\n"); |
| 2086 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2087 | goto probe_hw_failed; |
| 2088 | } |
| 2089 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2090 | req->max_q_depth = MAX_Q_DEPTH; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2091 | if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU) |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2092 | req->max_q_depth = ql2xmaxqdepth; |
| 2093 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2094 | |
| 2095 | base_vha = qla2x00_create_host(sht, ha); |
| 2096 | if (!base_vha) { |
| 2097 | qla_printk(KERN_WARNING, ha, |
| 2098 | "[ERROR] Failed to allocate memory for scsi_host\n"); |
| 2099 | |
Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 2100 | ret = -ENOMEM; |
Anirban Chakraborty | 6e9f21f | 2009-01-22 09:45:28 -0800 | [diff] [blame] | 2101 | qla2x00_mem_free(ha); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2102 | qla2x00_free_req_que(ha, req); |
| 2103 | qla2x00_free_rsp_que(ha, rsp); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2104 | goto probe_hw_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2107 | pci_set_drvdata(pdev, base_vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2109 | host = base_vha->host; |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2110 | base_vha->req = req; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2111 | host->can_queue = req->length + 128; |
| 2112 | if (IS_QLA2XXX_MIDTYPE(ha)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2113 | base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2114 | else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2115 | base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER + |
| 2116 | base_vha->vp_idx; |
Giridhar Malavali | 58548cb | 2010-09-03 15:20:56 -0700 | [diff] [blame] | 2117 | |
| 2118 | /* Set the SG table size based on ISP type */ |
| 2119 | if (!IS_FWI2_CAPABLE(ha)) { |
| 2120 | if (IS_QLA2100(ha)) |
| 2121 | host->sg_tablesize = 32; |
| 2122 | } else { |
| 2123 | if (!IS_QLA82XX(ha)) |
| 2124 | host->sg_tablesize = QLA_SG_ALL; |
| 2125 | } |
| 2126 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2127 | host->max_id = max_id; |
Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 2128 | host->this_id = 255; |
| 2129 | host->cmd_per_lun = 3; |
Seokmann Ju | 711c1d9 | 2008-07-10 16:55:51 -0700 | [diff] [blame] | 2130 | host->unique_id = host->host_no; |
Arun Easi | 0c47087 | 2010-07-23 15:28:38 +0500 | [diff] [blame] | 2131 | if ((IS_QLA25XX(ha) || IS_QLA81XX(ha)) && ql2xenabledif) |
| 2132 | host->max_cmd_len = 32; |
| 2133 | else |
| 2134 | host->max_cmd_len = MAX_CMDSZ; |
Andrew Vasquez | 75bc419 | 2006-05-17 15:09:22 -0700 | [diff] [blame] | 2135 | host->max_channel = MAX_BUSES - 1; |
Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 2136 | host->max_lun = MAX_LUNS; |
| 2137 | host->transportt = qla2xxx_transport_template; |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2138 | sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC); |
Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 2139 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2140 | /* Set up the irqs */ |
| 2141 | ret = qla2x00_request_irqs(ha, rsp); |
| 2142 | if (ret) |
Anirban Chakraborty | 6e9f21f | 2009-01-22 09:45:28 -0800 | [diff] [blame] | 2143 | goto probe_init_failed; |
Joe Carnuccio | 90a86fc | 2010-01-12 13:02:46 -0800 | [diff] [blame] | 2144 | |
| 2145 | pci_save_state(pdev); |
| 2146 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2147 | /* Alloc arrays of request and response ring ptrs */ |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 2148 | que_init: |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2149 | if (!qla2x00_alloc_queues(ha)) { |
| 2150 | qla_printk(KERN_WARNING, ha, |
| 2151 | "[ERROR] Failed to allocate memory for queue" |
| 2152 | " pointers\n"); |
Anirban Chakraborty | 6e9f21f | 2009-01-22 09:45:28 -0800 | [diff] [blame] | 2153 | goto probe_init_failed; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2154 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2155 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2156 | ha->rsp_q_map[0] = rsp; |
| 2157 | ha->req_q_map[0] = req; |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2158 | rsp->req = req; |
| 2159 | req->rsp = rsp; |
| 2160 | set_bit(0, ha->req_qid_map); |
| 2161 | set_bit(0, ha->rsp_qid_map); |
Andrew Vasquez | 0802999 | 2009-03-24 09:07:55 -0700 | [diff] [blame] | 2162 | /* FWI2-capable only. */ |
| 2163 | req->req_q_in = &ha->iobase->isp24.req_q_in; |
| 2164 | req->req_q_out = &ha->iobase->isp24.req_q_out; |
| 2165 | rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in; |
| 2166 | rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out; |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 2167 | if (ha->mqenable) { |
Andrew Vasquez | 0802999 | 2009-03-24 09:07:55 -0700 | [diff] [blame] | 2168 | req->req_q_in = &ha->mqiobase->isp25mq.req_q_in; |
| 2169 | req->req_q_out = &ha->mqiobase->isp25mq.req_q_out; |
| 2170 | rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in; |
| 2171 | rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out; |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 2172 | } |
| 2173 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2174 | if (IS_QLA82XX(ha)) { |
| 2175 | req->req_q_out = &ha->iobase->isp82.req_q_out[0]; |
| 2176 | rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0]; |
| 2177 | rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0]; |
| 2178 | } |
| 2179 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2180 | if (qla2x00_initialize_adapter(base_vha)) { |
| 2181 | qla_printk(KERN_WARNING, ha, |
| 2182 | "Failed to initialize adapter\n"); |
| 2183 | |
| 2184 | DEBUG2(printk("scsi(%ld): Failed to initialize adapter - " |
| 2185 | "Adapter flags %x.\n", |
| 2186 | base_vha->host_no, base_vha->device_flags)); |
| 2187 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2188 | if (IS_QLA82XX(ha)) { |
| 2189 | qla82xx_idc_lock(ha); |
| 2190 | qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE, |
| 2191 | QLA82XX_DEV_FAILED); |
| 2192 | qla82xx_idc_unlock(ha); |
| 2193 | qla_printk(KERN_INFO, ha, "HW State: FAILED\n"); |
| 2194 | } |
| 2195 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2196 | ret = -ENODEV; |
| 2197 | goto probe_failed; |
| 2198 | } |
| 2199 | |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 2200 | if (ha->mqenable) { |
| 2201 | if (qla25xx_setup_mode(base_vha)) { |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 2202 | qla_printk(KERN_WARNING, ha, |
| 2203 | "Can't create queues, falling back to single" |
| 2204 | " queue mode\n"); |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 2205 | goto que_init; |
| 2206 | } |
| 2207 | } |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 2208 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 2209 | if (ha->flags.running_gold_fw) |
| 2210 | goto skip_dpc; |
| 2211 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2212 | /* |
| 2213 | * Startup the kernel thread for this host adapter |
| 2214 | */ |
| 2215 | ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha, |
| 2216 | "%s_dpc", base_vha->host_str); |
| 2217 | if (IS_ERR(ha->dpc_thread)) { |
| 2218 | qla_printk(KERN_WARNING, ha, |
| 2219 | "Unable to start DPC thread!\n"); |
| 2220 | ret = PTR_ERR(ha->dpc_thread); |
| 2221 | goto probe_failed; |
| 2222 | } |
| 2223 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 2224 | skip_dpc: |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2225 | list_add_tail(&base_vha->list, &ha->vp_list); |
| 2226 | base_vha->host->irq = ha->pdev->irq; |
| 2227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | /* Initialized the timer */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2229 | qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | |
| 2231 | DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2232 | base_vha->host_no, ha)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2233 | |
Arun Easi | ba77ef5 | 2010-05-28 15:08:27 -0700 | [diff] [blame] | 2234 | if ((IS_QLA25XX(ha) || IS_QLA81XX(ha)) && ql2xenabledif) { |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 2235 | if (ha->fw_attributes & BIT_4) { |
| 2236 | base_vha->flags.difdix_supported = 1; |
| 2237 | DEBUG18(qla_printk(KERN_INFO, ha, |
| 2238 | "Registering for DIF/DIX type 1 and 3" |
| 2239 | " protection.\n")); |
| 2240 | scsi_host_set_prot(host, |
| 2241 | SHOST_DIF_TYPE1_PROTECTION |
Arun Easi | 0c47087 | 2010-07-23 15:28:38 +0500 | [diff] [blame] | 2242 | | SHOST_DIF_TYPE2_PROTECTION |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 2243 | | SHOST_DIF_TYPE3_PROTECTION |
| 2244 | | SHOST_DIX_TYPE1_PROTECTION |
Arun Easi | 0c47087 | 2010-07-23 15:28:38 +0500 | [diff] [blame] | 2245 | | SHOST_DIX_TYPE2_PROTECTION |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 2246 | | SHOST_DIX_TYPE3_PROTECTION); |
| 2247 | scsi_host_set_guard(host, SHOST_DIX_GUARD_CRC); |
| 2248 | } else |
| 2249 | base_vha->flags.difdix_supported = 0; |
| 2250 | } |
| 2251 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2252 | ha->isp_ops->enable_intrs(ha); |
| 2253 | |
Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 2254 | ret = scsi_add_host(host, &pdev->dev); |
| 2255 | if (ret) |
| 2256 | goto probe_failed; |
| 2257 | |
Michael Reed | 1486400 | 2009-12-02 09:11:16 -0600 | [diff] [blame] | 2258 | base_vha->flags.init_done = 1; |
| 2259 | base_vha->flags.online = 1; |
| 2260 | |
Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 2261 | scsi_scan_host(host); |
| 2262 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2263 | qla2x00_alloc_sysfs_attr(base_vha); |
Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 2264 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2265 | qla2x00_init_host_attr(base_vha); |
Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 2266 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2267 | qla2x00_dfs_setup(base_vha); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2268 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | qla_printk(KERN_INFO, ha, "\n" |
| 2270 | " QLogic Fibre Channel HBA Driver: %s\n" |
| 2271 | " QLogic %s - %s\n" |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2272 | " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n", |
| 2273 | qla2x00_version_str, ha->model_number, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2274 | ha->model_desc ? ha->model_desc : "", pdev->device, |
| 2275 | ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev), |
| 2276 | ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no, |
| 2277 | ha->isp_ops->fw_version_str(base_vha, fw_str)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | return 0; |
| 2280 | |
Anirban Chakraborty | 6e9f21f | 2009-01-22 09:45:28 -0800 | [diff] [blame] | 2281 | probe_init_failed: |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2282 | qla2x00_free_req_que(ha, req); |
| 2283 | qla2x00_free_rsp_que(ha, rsp); |
| 2284 | ha->max_req_queues = ha->max_rsp_queues = 0; |
Anirban Chakraborty | 6e9f21f | 2009-01-22 09:45:28 -0800 | [diff] [blame] | 2285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | probe_failed: |
Andrew Vasquez | b997876 | 2009-03-24 09:08:05 -0700 | [diff] [blame] | 2287 | if (base_vha->timer_active) |
| 2288 | qla2x00_stop_timer(base_vha); |
| 2289 | base_vha->flags.online = 0; |
| 2290 | if (ha->dpc_thread) { |
| 2291 | struct task_struct *t = ha->dpc_thread; |
| 2292 | |
| 2293 | ha->dpc_thread = NULL; |
| 2294 | kthread_stop(t); |
| 2295 | } |
| 2296 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2297 | qla2x00_free_device(base_vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2299 | scsi_host_put(base_vha->host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2301 | probe_hw_failed: |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2302 | if (IS_QLA82XX(ha)) { |
| 2303 | qla82xx_idc_lock(ha); |
| 2304 | qla82xx_clear_drv_active(ha); |
| 2305 | qla82xx_idc_unlock(ha); |
| 2306 | iounmap((device_reg_t __iomem *)ha->nx_pcibase); |
| 2307 | if (!ql2xdbwr) |
| 2308 | iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr); |
| 2309 | } else { |
| 2310 | if (ha->iobase) |
| 2311 | iounmap(ha->iobase); |
| 2312 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2313 | pci_release_selected_regions(ha->pdev, ha->bars); |
| 2314 | kfree(ha); |
| 2315 | ha = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | |
Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 2317 | probe_out: |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2318 | pci_disable_device(pdev); |
Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 2319 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | |
Adrian Bunk | 4c993f7 | 2008-01-14 00:55:16 -0800 | [diff] [blame] | 2322 | static void |
Madhuranath Iyengar | e30d175 | 2010-10-15 11:27:46 -0700 | [diff] [blame] | 2323 | qla2x00_shutdown(struct pci_dev *pdev) |
| 2324 | { |
| 2325 | scsi_qla_host_t *vha; |
| 2326 | struct qla_hw_data *ha; |
| 2327 | |
| 2328 | vha = pci_get_drvdata(pdev); |
| 2329 | ha = vha->hw; |
| 2330 | |
| 2331 | /* Turn-off FCE trace */ |
| 2332 | if (ha->flags.fce_enabled) { |
| 2333 | qla2x00_disable_fce_trace(vha, NULL, NULL); |
| 2334 | ha->flags.fce_enabled = 0; |
| 2335 | } |
| 2336 | |
| 2337 | /* Turn-off EFT trace */ |
| 2338 | if (ha->eft) |
| 2339 | qla2x00_disable_eft_trace(vha); |
| 2340 | |
| 2341 | /* Stop currently executing firmware. */ |
| 2342 | qla2x00_try_to_stop_firmware(vha); |
| 2343 | |
| 2344 | /* Turn adapter off line */ |
| 2345 | vha->flags.online = 0; |
| 2346 | |
| 2347 | /* turn-off interrupts on the card */ |
| 2348 | if (ha->interrupts_on) { |
| 2349 | vha->flags.init_done = 0; |
| 2350 | ha->isp_ops->disable_intrs(ha); |
| 2351 | } |
| 2352 | |
| 2353 | qla2x00_free_irqs(vha); |
| 2354 | |
| 2355 | qla2x00_free_fw_dump(ha); |
| 2356 | } |
| 2357 | |
| 2358 | static void |
Andrew Vasquez | 7ee6139 | 2006-06-23 16:11:22 -0700 | [diff] [blame] | 2359 | qla2x00_remove_one(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 2361 | scsi_qla_host_t *base_vha, *vha; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2362 | struct qla_hw_data *ha; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 2363 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2365 | base_vha = pci_get_drvdata(pdev); |
| 2366 | ha = base_vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 2368 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 2369 | list_for_each_entry(vha, &ha->vp_list, list) { |
| 2370 | atomic_inc(&vha->vref_count); |
| 2371 | |
| 2372 | if (vha && vha->fc_vport) { |
| 2373 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 2374 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2375 | fc_vport_terminate(vha->fc_vport); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 2376 | |
| 2377 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 2378 | } |
| 2379 | |
| 2380 | atomic_dec(&vha->vref_count); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2381 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 2382 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Andrew Vasquez | c795c1e | 2008-08-13 21:37:01 -0700 | [diff] [blame] | 2383 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2384 | set_bit(UNLOADING, &base_vha->dpc_flags); |
Andrew Vasquez | c795c1e | 2008-08-13 21:37:01 -0700 | [diff] [blame] | 2385 | |
Andrew Vasquez | b997876 | 2009-03-24 09:08:05 -0700 | [diff] [blame] | 2386 | qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16); |
| 2387 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2388 | qla2x00_dfs_remove(base_vha); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2389 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2390 | qla84xx_put_chip(base_vha); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2391 | |
Andrew Vasquez | b997876 | 2009-03-24 09:08:05 -0700 | [diff] [blame] | 2392 | /* Disable timer */ |
| 2393 | if (base_vha->timer_active) |
| 2394 | qla2x00_stop_timer(base_vha); |
| 2395 | |
| 2396 | base_vha->flags.online = 0; |
| 2397 | |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 2398 | /* Flush the work queue and remove it */ |
| 2399 | if (ha->wq) { |
| 2400 | flush_workqueue(ha->wq); |
| 2401 | destroy_workqueue(ha->wq); |
| 2402 | ha->wq = NULL; |
| 2403 | } |
| 2404 | |
Andrew Vasquez | b997876 | 2009-03-24 09:08:05 -0700 | [diff] [blame] | 2405 | /* Kill the kernel thread for this host */ |
| 2406 | if (ha->dpc_thread) { |
| 2407 | struct task_struct *t = ha->dpc_thread; |
| 2408 | |
| 2409 | /* |
| 2410 | * qla2xxx_wake_dpc checks for ->dpc_thread |
| 2411 | * so we need to zero it out. |
| 2412 | */ |
| 2413 | ha->dpc_thread = NULL; |
| 2414 | kthread_stop(t); |
| 2415 | } |
| 2416 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2417 | qla2x00_free_sysfs_attr(base_vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2419 | fc_remove_host(base_vha->host); |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 2420 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2421 | scsi_remove_host(base_vha->host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2423 | qla2x00_free_device(base_vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2425 | scsi_host_put(base_vha->host); |
| 2426 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2427 | if (IS_QLA82XX(ha)) { |
Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 2428 | qla82xx_idc_lock(ha); |
| 2429 | qla82xx_clear_drv_active(ha); |
| 2430 | qla82xx_idc_unlock(ha); |
| 2431 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2432 | iounmap((device_reg_t __iomem *)ha->nx_pcibase); |
| 2433 | if (!ql2xdbwr) |
| 2434 | iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr); |
| 2435 | } else { |
| 2436 | if (ha->iobase) |
| 2437 | iounmap(ha->iobase); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2438 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2439 | if (ha->mqiobase) |
| 2440 | iounmap(ha->mqiobase); |
| 2441 | } |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2442 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2443 | pci_release_selected_regions(ha->pdev, ha->bars); |
| 2444 | kfree(ha); |
| 2445 | ha = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | |
Joe Carnuccio | 90a86fc | 2010-01-12 13:02:46 -0800 | [diff] [blame] | 2447 | pci_disable_pcie_error_reporting(pdev); |
| 2448 | |
Bernhard Walle | 665db93 | 2007-03-28 00:49:49 +0200 | [diff] [blame] | 2449 | pci_disable_device(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2450 | pci_set_drvdata(pdev, NULL); |
| 2451 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2452 | |
| 2453 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2454 | qla2x00_free_device(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2455 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2456 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2457 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 2458 | qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16); |
| 2459 | |
| 2460 | /* Disable timer */ |
| 2461 | if (vha->timer_active) |
| 2462 | qla2x00_stop_timer(vha); |
| 2463 | |
| 2464 | /* Kill the kernel thread for this host */ |
| 2465 | if (ha->dpc_thread) { |
| 2466 | struct task_struct *t = ha->dpc_thread; |
| 2467 | |
| 2468 | /* |
| 2469 | * qla2xxx_wake_dpc checks for ->dpc_thread |
| 2470 | * so we need to zero it out. |
| 2471 | */ |
| 2472 | ha->dpc_thread = NULL; |
| 2473 | kthread_stop(t); |
| 2474 | } |
| 2475 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2476 | qla25xx_delete_queues(vha); |
| 2477 | |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2478 | if (ha->flags.fce_enabled) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2479 | qla2x00_disable_fce_trace(vha, NULL, NULL); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2480 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2481 | if (ha->eft) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2482 | qla2x00_disable_eft_trace(vha); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2483 | |
Andrew Vasquez | f6ef3b1 | 2005-08-26 19:10:20 -0700 | [diff] [blame] | 2484 | /* Stop currently executing firmware. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2485 | qla2x00_try_to_stop_firmware(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2486 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 2487 | vha->flags.online = 0; |
| 2488 | |
Andrew Vasquez | f6ef3b1 | 2005-08-26 19:10:20 -0700 | [diff] [blame] | 2489 | /* turn-off interrupts on the card */ |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2490 | if (ha->interrupts_on) { |
| 2491 | vha->flags.init_done = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2492 | ha->isp_ops->disable_intrs(ha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2493 | } |
Andrew Vasquez | f6ef3b1 | 2005-08-26 19:10:20 -0700 | [diff] [blame] | 2494 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2495 | qla2x00_free_irqs(vha); |
| 2496 | |
Chad Dupuis | 8867048 | 2010-07-23 15:28:30 +0500 | [diff] [blame] | 2497 | qla2x00_free_fcports(vha); |
| 2498 | |
Andrew Vasquez | f6ef3b1 | 2005-08-26 19:10:20 -0700 | [diff] [blame] | 2499 | qla2x00_mem_free(ha); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2500 | |
| 2501 | qla2x00_free_queues(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2502 | } |
| 2503 | |
Chad Dupuis | 8867048 | 2010-07-23 15:28:30 +0500 | [diff] [blame] | 2504 | void qla2x00_free_fcports(struct scsi_qla_host *vha) |
| 2505 | { |
| 2506 | fc_port_t *fcport, *tfcport; |
| 2507 | |
| 2508 | list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) { |
| 2509 | list_del(&fcport->list); |
| 2510 | kfree(fcport); |
| 2511 | fcport = NULL; |
| 2512 | } |
| 2513 | } |
| 2514 | |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2515 | static inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2516 | 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] | 2517 | int defer) |
| 2518 | { |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2519 | struct fc_rport *rport; |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 2520 | scsi_qla_host_t *base_vha; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2521 | |
| 2522 | if (!fcport->rport) |
| 2523 | return; |
| 2524 | |
| 2525 | rport = fcport->rport; |
| 2526 | if (defer) { |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 2527 | base_vha = pci_get_drvdata(vha->hw->pdev); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2528 | spin_lock_irq(vha->host->host_lock); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2529 | fcport->drport = rport; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2530 | spin_unlock_irq(vha->host->host_lock); |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 2531 | set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags); |
| 2532 | qla2xxx_wake_dpc(base_vha); |
Seokmann Ju | 5f3a9a2 | 2008-07-10 16:55:47 -0700 | [diff] [blame] | 2533 | } else |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2534 | fc_remote_port_delete(rport); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2535 | } |
| 2536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | * qla2x00_mark_device_lost Updates fcport state when device goes offline. |
| 2539 | * |
| 2540 | * Input: ha = adapter block pointer. fcport = port structure pointer. |
| 2541 | * |
| 2542 | * Return: None. |
| 2543 | * |
| 2544 | * Context: |
| 2545 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2546 | 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] | 2547 | int do_login, int defer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2549 | if (atomic_read(&fcport->state) == FCS_ONLINE && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2550 | vha->vp_idx == fcport->vp_idx) { |
| 2551 | atomic_set(&fcport->state, FCS_DEVICE_LOST); |
| 2552 | qla2x00_schedule_rport_del(vha, fcport, defer); |
| 2553 | } |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2554 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2555 | * We may need to retry the login, so don't change the state of the |
| 2556 | * port but do the retries. |
| 2557 | */ |
| 2558 | if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD) |
| 2559 | atomic_set(&fcport->state, FCS_DEVICE_LOST); |
| 2560 | |
| 2561 | if (!do_login) |
| 2562 | return; |
| 2563 | |
| 2564 | if (fcport->login_retry == 0) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2565 | fcport->login_retry = vha->hw->login_retry_count; |
| 2566 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2567 | |
| 2568 | DEBUG(printk("scsi(%ld): Port login retry: " |
| 2569 | "%02x%02x%02x%02x%02x%02x%02x%02x, " |
| 2570 | "id = 0x%04x retry cnt=%d\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2571 | vha->host_no, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 | fcport->port_name[0], |
| 2573 | fcport->port_name[1], |
| 2574 | fcport->port_name[2], |
| 2575 | fcport->port_name[3], |
| 2576 | fcport->port_name[4], |
| 2577 | fcport->port_name[5], |
| 2578 | fcport->port_name[6], |
| 2579 | fcport->port_name[7], |
| 2580 | fcport->loop_id, |
| 2581 | fcport->login_retry)); |
| 2582 | } |
| 2583 | } |
| 2584 | |
| 2585 | /* |
| 2586 | * qla2x00_mark_all_devices_lost |
| 2587 | * Updates fcport state when device goes offline. |
| 2588 | * |
| 2589 | * Input: |
| 2590 | * ha = adapter block pointer. |
| 2591 | * fcport = port structure pointer. |
| 2592 | * |
| 2593 | * Return: |
| 2594 | * None. |
| 2595 | * |
| 2596 | * Context: |
| 2597 | */ |
| 2598 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2599 | qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | { |
| 2601 | fc_port_t *fcport; |
| 2602 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2603 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Andrew Vasquez | 0d6e61b | 2009-08-25 11:36:19 -0700 | [diff] [blame] | 2604 | if (vha->vp_idx != 0 && vha->vp_idx != fcport->vp_idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2605 | continue; |
Andrew Vasquez | 0d6e61b | 2009-08-25 11:36:19 -0700 | [diff] [blame] | 2606 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | /* |
| 2608 | * No point in marking the device as lost, if the device is |
| 2609 | * already DEAD. |
| 2610 | */ |
| 2611 | if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD) |
| 2612 | continue; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2613 | if (atomic_read(&fcport->state) == FCS_ONLINE) { |
Giridhar Malavali | 38170fa | 2010-10-15 11:27:49 -0700 | [diff] [blame] | 2614 | atomic_set(&fcport->state, FCS_DEVICE_LOST); |
Andrew Vasquez | 0d6e61b | 2009-08-25 11:36:19 -0700 | [diff] [blame] | 2615 | if (defer) |
| 2616 | qla2x00_schedule_rport_del(vha, fcport, defer); |
| 2617 | else if (vha->vp_idx == fcport->vp_idx) |
| 2618 | qla2x00_schedule_rport_del(vha, fcport, defer); |
| 2619 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2620 | } |
| 2621 | } |
| 2622 | |
| 2623 | /* |
| 2624 | * qla2x00_mem_alloc |
| 2625 | * Allocates adapter memory. |
| 2626 | * |
| 2627 | * Returns: |
| 2628 | * 0 = success. |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2629 | * !0 = failure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2630 | */ |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2631 | static int |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2632 | qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len, |
| 2633 | struct req_que **req, struct rsp_que **rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2634 | { |
| 2635 | char name[16]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2636 | |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2637 | 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] | 2638 | &ha->init_cb_dma, GFP_KERNEL); |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2639 | if (!ha->init_cb) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2640 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2642 | ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE, |
| 2643 | &ha->gid_list_dma, GFP_KERNEL); |
| 2644 | if (!ha->gid_list) |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2645 | goto fail_free_init_cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2647 | ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep); |
| 2648 | if (!ha->srb_mempool) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2649 | goto fail_free_gid_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2650 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2651 | if (IS_QLA82XX(ha)) { |
| 2652 | /* Allocate cache for CT6 Ctx. */ |
| 2653 | if (!ctx_cachep) { |
| 2654 | ctx_cachep = kmem_cache_create("qla2xxx_ctx", |
| 2655 | sizeof(struct ct6_dsd), 0, |
| 2656 | SLAB_HWCACHE_ALIGN, NULL); |
| 2657 | if (!ctx_cachep) |
| 2658 | goto fail_free_gid_list; |
| 2659 | } |
| 2660 | ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ, |
| 2661 | ctx_cachep); |
| 2662 | if (!ha->ctx_mempool) |
| 2663 | goto fail_free_srb_mempool; |
| 2664 | } |
| 2665 | |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2666 | /* Get memory for cached NVRAM */ |
| 2667 | ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL); |
| 2668 | if (!ha->nvram) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2669 | goto fail_free_ctx_mempool; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2671 | snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME, |
| 2672 | ha->pdev->device); |
| 2673 | ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev, |
| 2674 | DMA_POOL_SIZE, 8, 0); |
| 2675 | if (!ha->s_dma_pool) |
| 2676 | goto fail_free_nvram; |
| 2677 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 2678 | if (IS_QLA82XX(ha) || ql2xenabledif) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2679 | ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev, |
| 2680 | DSD_LIST_DMA_POOL_SIZE, 8, 0); |
| 2681 | if (!ha->dl_dma_pool) { |
| 2682 | qla_printk(KERN_WARNING, ha, |
| 2683 | "Memory Allocation failed - dl_dma_pool\n"); |
| 2684 | goto fail_s_dma_pool; |
| 2685 | } |
| 2686 | |
| 2687 | ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev, |
| 2688 | FCP_CMND_DMA_POOL_SIZE, 8, 0); |
| 2689 | if (!ha->fcp_cmnd_dma_pool) { |
| 2690 | qla_printk(KERN_WARNING, ha, |
| 2691 | "Memory Allocation failed - fcp_cmnd_dma_pool\n"); |
| 2692 | goto fail_dl_dma_pool; |
| 2693 | } |
| 2694 | } |
| 2695 | |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2696 | /* Allocate memory for SNS commands */ |
| 2697 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2698 | /* Get consistent memory allocated for SNS commands */ |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2699 | ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2700 | sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL); |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2701 | if (!ha->sns_cmd) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2702 | goto fail_dma_pool; |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2703 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2704 | /* Get consistent memory allocated for MS IOCB */ |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2705 | ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2706 | &ha->ms_iocb_dma); |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2707 | if (!ha->ms_iocb) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2708 | goto fail_dma_pool; |
| 2709 | /* Get consistent memory allocated for CT SNS commands */ |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2710 | ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2711 | sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL); |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2712 | if (!ha->ct_sns) |
| 2713 | goto fail_free_ms_iocb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | } |
| 2715 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2716 | /* Allocate memory for request ring */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2717 | *req = kzalloc(sizeof(struct req_que), GFP_KERNEL); |
| 2718 | if (!*req) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2719 | DEBUG(printk("Unable to allocate memory for req\n")); |
| 2720 | goto fail_req; |
| 2721 | } |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2722 | (*req)->length = req_len; |
| 2723 | (*req)->ring = dma_alloc_coherent(&ha->pdev->dev, |
| 2724 | ((*req)->length + 1) * sizeof(request_t), |
| 2725 | &(*req)->dma, GFP_KERNEL); |
| 2726 | if (!(*req)->ring) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2727 | DEBUG(printk("Unable to allocate memory for req_ring\n")); |
| 2728 | goto fail_req_ring; |
| 2729 | } |
| 2730 | /* Allocate memory for response ring */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2731 | *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL); |
| 2732 | if (!*rsp) { |
| 2733 | qla_printk(KERN_WARNING, ha, |
| 2734 | "Unable to allocate memory for rsp\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2735 | goto fail_rsp; |
| 2736 | } |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2737 | (*rsp)->hw = ha; |
| 2738 | (*rsp)->length = rsp_len; |
| 2739 | (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev, |
| 2740 | ((*rsp)->length + 1) * sizeof(response_t), |
| 2741 | &(*rsp)->dma, GFP_KERNEL); |
| 2742 | if (!(*rsp)->ring) { |
| 2743 | qla_printk(KERN_WARNING, ha, |
| 2744 | "Unable to allocate memory for rsp_ring\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2745 | goto fail_rsp_ring; |
| 2746 | } |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2747 | (*req)->rsp = *rsp; |
| 2748 | (*rsp)->req = *req; |
| 2749 | /* Allocate memory for NVRAM data for vports */ |
| 2750 | if (ha->nvram_npiv_size) { |
| 2751 | ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) * |
| 2752 | ha->nvram_npiv_size, GFP_KERNEL); |
| 2753 | if (!ha->npiv_info) { |
| 2754 | qla_printk(KERN_WARNING, ha, |
| 2755 | "Unable to allocate memory for npiv info\n"); |
| 2756 | goto fail_npiv_info; |
| 2757 | } |
| 2758 | } else |
| 2759 | ha->npiv_info = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2760 | |
Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 2761 | /* Get consistent memory allocated for EX-INIT-CB. */ |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2762 | if (IS_QLA8XXX_TYPE(ha)) { |
Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 2763 | ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, |
| 2764 | &ha->ex_init_cb_dma); |
| 2765 | if (!ha->ex_init_cb) |
| 2766 | goto fail_ex_init_cb; |
| 2767 | } |
| 2768 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2769 | INIT_LIST_HEAD(&ha->gbl_dsd_list); |
| 2770 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 2771 | /* Get consistent memory allocated for Async Port-Database. */ |
| 2772 | if (!IS_FWI2_CAPABLE(ha)) { |
| 2773 | ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, |
| 2774 | &ha->async_pd_dma); |
| 2775 | if (!ha->async_pd) |
| 2776 | goto fail_async_pd; |
| 2777 | } |
| 2778 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2779 | INIT_LIST_HEAD(&ha->vp_list); |
| 2780 | return 1; |
| 2781 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 2782 | fail_async_pd: |
| 2783 | dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma); |
Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 2784 | fail_ex_init_cb: |
| 2785 | kfree(ha->npiv_info); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2786 | fail_npiv_info: |
| 2787 | dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) * |
| 2788 | sizeof(response_t), (*rsp)->ring, (*rsp)->dma); |
| 2789 | (*rsp)->ring = NULL; |
| 2790 | (*rsp)->dma = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2791 | fail_rsp_ring: |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2792 | kfree(*rsp); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2793 | fail_rsp: |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2794 | dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) * |
| 2795 | sizeof(request_t), (*req)->ring, (*req)->dma); |
| 2796 | (*req)->ring = NULL; |
| 2797 | (*req)->dma = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2798 | fail_req_ring: |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2799 | kfree(*req); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2800 | fail_req: |
| 2801 | dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt), |
| 2802 | ha->ct_sns, ha->ct_sns_dma); |
| 2803 | ha->ct_sns = NULL; |
| 2804 | ha->ct_sns_dma = 0; |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2805 | fail_free_ms_iocb: |
| 2806 | dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma); |
| 2807 | ha->ms_iocb = NULL; |
| 2808 | ha->ms_iocb_dma = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2809 | fail_dma_pool: |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 2810 | if (IS_QLA82XX(ha) || ql2xenabledif) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2811 | dma_pool_destroy(ha->fcp_cmnd_dma_pool); |
| 2812 | ha->fcp_cmnd_dma_pool = NULL; |
| 2813 | } |
| 2814 | fail_dl_dma_pool: |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 2815 | if (IS_QLA82XX(ha) || ql2xenabledif) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2816 | dma_pool_destroy(ha->dl_dma_pool); |
| 2817 | ha->dl_dma_pool = NULL; |
| 2818 | } |
| 2819 | fail_s_dma_pool: |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2820 | dma_pool_destroy(ha->s_dma_pool); |
| 2821 | ha->s_dma_pool = NULL; |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2822 | fail_free_nvram: |
| 2823 | kfree(ha->nvram); |
| 2824 | ha->nvram = NULL; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2825 | fail_free_ctx_mempool: |
| 2826 | mempool_destroy(ha->ctx_mempool); |
| 2827 | ha->ctx_mempool = NULL; |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2828 | fail_free_srb_mempool: |
| 2829 | mempool_destroy(ha->srb_mempool); |
| 2830 | ha->srb_mempool = NULL; |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2831 | fail_free_gid_list: |
| 2832 | dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2833 | ha->gid_list_dma); |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2834 | ha->gid_list = NULL; |
| 2835 | ha->gid_list_dma = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2836 | fail_free_init_cb: |
| 2837 | dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb, |
| 2838 | ha->init_cb_dma); |
| 2839 | ha->init_cb = NULL; |
| 2840 | ha->init_cb_dma = 0; |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2841 | fail: |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2842 | DEBUG(printk("%s: Memory allocation failure\n", __func__)); |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2843 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | /* |
Madhuranath Iyengar | e30d175 | 2010-10-15 11:27:46 -0700 | [diff] [blame] | 2847 | * qla2x00_free_fw_dump |
| 2848 | * Frees fw dump stuff. |
| 2849 | * |
| 2850 | * Input: |
| 2851 | * ha = adapter block pointer. |
| 2852 | */ |
| 2853 | static void |
| 2854 | qla2x00_free_fw_dump(struct qla_hw_data *ha) |
| 2855 | { |
| 2856 | if (ha->fce) |
| 2857 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, |
| 2858 | ha->fce_dma); |
| 2859 | |
| 2860 | if (ha->fw_dump) { |
| 2861 | if (ha->eft) |
| 2862 | dma_free_coherent(&ha->pdev->dev, |
| 2863 | ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma); |
| 2864 | vfree(ha->fw_dump); |
| 2865 | } |
| 2866 | ha->fce = NULL; |
| 2867 | ha->fce_dma = 0; |
| 2868 | ha->eft = NULL; |
| 2869 | ha->eft_dma = 0; |
| 2870 | ha->fw_dump = NULL; |
| 2871 | ha->fw_dumped = 0; |
| 2872 | ha->fw_dump_reading = 0; |
| 2873 | } |
| 2874 | |
| 2875 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | * qla2x00_mem_free |
| 2877 | * Frees all adapter allocated memory. |
| 2878 | * |
| 2879 | * Input: |
| 2880 | * ha = adapter block pointer. |
| 2881 | */ |
Adrian Bunk | a824ebb | 2008-01-17 09:02:15 -0800 | [diff] [blame] | 2882 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2883 | qla2x00_mem_free(struct qla_hw_data *ha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | { |
Madhuranath Iyengar | e30d175 | 2010-10-15 11:27:46 -0700 | [diff] [blame] | 2885 | qla2x00_free_fw_dump(ha); |
| 2886 | |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2887 | if (ha->srb_mempool) |
| 2888 | mempool_destroy(ha->srb_mempool); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | |
Andrew Vasquez | 11bbc1d | 2009-06-03 09:55:14 -0700 | [diff] [blame] | 2890 | if (ha->dcbx_tlv) |
| 2891 | dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE, |
| 2892 | ha->dcbx_tlv, ha->dcbx_tlv_dma); |
| 2893 | |
Andrew Vasquez | ce0423f | 2009-06-03 09:55:13 -0700 | [diff] [blame] | 2894 | if (ha->xgmac_data) |
| 2895 | dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE, |
| 2896 | ha->xgmac_data, ha->xgmac_data_dma); |
| 2897 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | if (ha->sns_cmd) |
| 2899 | dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt), |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2900 | ha->sns_cmd, ha->sns_cmd_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | |
| 2902 | if (ha->ct_sns) |
| 2903 | dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt), |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2904 | ha->ct_sns, ha->ct_sns_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2905 | |
Andrew Vasquez | 88729e5 | 2006-06-23 16:10:50 -0700 | [diff] [blame] | 2906 | if (ha->sfp_data) |
| 2907 | dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma); |
| 2908 | |
Joe Carnuccio | ad0ecd6 | 2009-03-24 09:08:12 -0700 | [diff] [blame] | 2909 | if (ha->edc_data) |
| 2910 | dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma); |
| 2911 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2912 | if (ha->ms_iocb) |
| 2913 | dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma); |
| 2914 | |
Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 2915 | if (ha->ex_init_cb) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2916 | dma_pool_free(ha->s_dma_pool, |
| 2917 | ha->ex_init_cb, ha->ex_init_cb_dma); |
Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 2918 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 2919 | if (ha->async_pd) |
| 2920 | dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma); |
| 2921 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | if (ha->s_dma_pool) |
| 2923 | dma_pool_destroy(ha->s_dma_pool); |
| 2924 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | if (ha->gid_list) |
| 2926 | dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2927 | ha->gid_list_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2929 | if (IS_QLA82XX(ha)) { |
| 2930 | if (!list_empty(&ha->gbl_dsd_list)) { |
| 2931 | struct dsd_dma *dsd_ptr, *tdsd_ptr; |
| 2932 | |
| 2933 | /* clean up allocated prev pool */ |
| 2934 | list_for_each_entry_safe(dsd_ptr, |
| 2935 | tdsd_ptr, &ha->gbl_dsd_list, list) { |
| 2936 | dma_pool_free(ha->dl_dma_pool, |
| 2937 | dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma); |
| 2938 | list_del(&dsd_ptr->list); |
| 2939 | kfree(dsd_ptr); |
| 2940 | } |
| 2941 | } |
| 2942 | } |
| 2943 | |
| 2944 | if (ha->dl_dma_pool) |
| 2945 | dma_pool_destroy(ha->dl_dma_pool); |
| 2946 | |
| 2947 | if (ha->fcp_cmnd_dma_pool) |
| 2948 | dma_pool_destroy(ha->fcp_cmnd_dma_pool); |
| 2949 | |
| 2950 | if (ha->ctx_mempool) |
| 2951 | mempool_destroy(ha->ctx_mempool); |
| 2952 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2953 | if (ha->init_cb) |
| 2954 | dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2955 | ha->init_cb, ha->init_cb_dma); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2956 | vfree(ha->optrom_buffer); |
| 2957 | kfree(ha->nvram); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2958 | kfree(ha->npiv_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2959 | |
Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2960 | ha->srb_mempool = NULL; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2961 | ha->ctx_mempool = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | ha->sns_cmd = NULL; |
| 2963 | ha->sns_cmd_dma = 0; |
| 2964 | ha->ct_sns = NULL; |
| 2965 | ha->ct_sns_dma = 0; |
| 2966 | ha->ms_iocb = NULL; |
| 2967 | ha->ms_iocb_dma = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | ha->init_cb = NULL; |
| 2969 | ha->init_cb_dma = 0; |
Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 2970 | ha->ex_init_cb = NULL; |
| 2971 | ha->ex_init_cb_dma = 0; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 2972 | ha->async_pd = NULL; |
| 2973 | ha->async_pd_dma = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | |
| 2975 | ha->s_dma_pool = NULL; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2976 | ha->dl_dma_pool = NULL; |
| 2977 | ha->fcp_cmnd_dma_pool = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | ha->gid_list = NULL; |
| 2980 | ha->gid_list_dma = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2981 | } |
| 2982 | |
| 2983 | struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht, |
| 2984 | struct qla_hw_data *ha) |
| 2985 | { |
| 2986 | struct Scsi_Host *host; |
| 2987 | struct scsi_qla_host *vha = NULL; |
| 2988 | |
| 2989 | host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t)); |
| 2990 | if (host == NULL) { |
| 2991 | printk(KERN_WARNING |
| 2992 | "qla2xxx: Couldn't allocate host from scsi layer!\n"); |
| 2993 | goto fail; |
| 2994 | } |
| 2995 | |
| 2996 | /* Clear our data area */ |
| 2997 | vha = shost_priv(host); |
| 2998 | memset(vha, 0, sizeof(scsi_qla_host_t)); |
| 2999 | |
| 3000 | vha->host = host; |
| 3001 | vha->host_no = host->host_no; |
| 3002 | vha->hw = ha; |
| 3003 | |
| 3004 | INIT_LIST_HEAD(&vha->vp_fcports); |
| 3005 | INIT_LIST_HEAD(&vha->work_list); |
| 3006 | INIT_LIST_HEAD(&vha->list); |
| 3007 | |
Andrew Vasquez | f999f4c | 2009-06-03 09:55:28 -0700 | [diff] [blame] | 3008 | spin_lock_init(&vha->work_lock); |
| 3009 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3010 | sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no); |
| 3011 | return vha; |
| 3012 | |
| 3013 | fail: |
| 3014 | return vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | } |
| 3016 | |
Adrian Bunk | 01ef66b | 2008-04-24 15:21:27 -0700 | [diff] [blame] | 3017 | static struct qla_work_evt * |
Andrew Vasquez | f999f4c | 2009-06-03 09:55:28 -0700 | [diff] [blame] | 3018 | 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] | 3019 | { |
| 3020 | struct qla_work_evt *e; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3021 | uint8_t bail; |
| 3022 | |
| 3023 | QLA_VHA_MARK_BUSY(vha, bail); |
| 3024 | if (bail) |
| 3025 | return NULL; |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 3026 | |
Andrew Vasquez | f999f4c | 2009-06-03 09:55:28 -0700 | [diff] [blame] | 3027 | e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3028 | if (!e) { |
| 3029 | QLA_VHA_MARK_NOT_BUSY(vha); |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 3030 | return NULL; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3031 | } |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 3032 | |
| 3033 | INIT_LIST_HEAD(&e->list); |
| 3034 | e->type = type; |
| 3035 | e->flags = QLA_EVT_FLAG_FREE; |
| 3036 | return e; |
| 3037 | } |
| 3038 | |
Adrian Bunk | 01ef66b | 2008-04-24 15:21:27 -0700 | [diff] [blame] | 3039 | static int |
Andrew Vasquez | f999f4c | 2009-06-03 09:55:28 -0700 | [diff] [blame] | 3040 | qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e) |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 3041 | { |
Andrew Vasquez | f999f4c | 2009-06-03 09:55:28 -0700 | [diff] [blame] | 3042 | unsigned long flags; |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 3043 | |
Andrew Vasquez | f999f4c | 2009-06-03 09:55:28 -0700 | [diff] [blame] | 3044 | spin_lock_irqsave(&vha->work_lock, flags); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3045 | list_add_tail(&e->list, &vha->work_list); |
Andrew Vasquez | f999f4c | 2009-06-03 09:55:28 -0700 | [diff] [blame] | 3046 | spin_unlock_irqrestore(&vha->work_lock, flags); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3047 | qla2xxx_wake_dpc(vha); |
Andrew Vasquez | f999f4c | 2009-06-03 09:55:28 -0700 | [diff] [blame] | 3048 | |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 3049 | return QLA_SUCCESS; |
| 3050 | } |
| 3051 | |
| 3052 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3053 | 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] | 3054 | u32 data) |
| 3055 | { |
| 3056 | struct qla_work_evt *e; |
| 3057 | |
Andrew Vasquez | f999f4c | 2009-06-03 09:55:28 -0700 | [diff] [blame] | 3058 | e = qla2x00_alloc_work(vha, QLA_EVT_AEN); |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 3059 | if (!e) |
| 3060 | return QLA_FUNCTION_FAILED; |
| 3061 | |
| 3062 | e->u.aen.code = code; |
| 3063 | e->u.aen.data = data; |
Andrew Vasquez | f999f4c | 2009-06-03 09:55:28 -0700 | [diff] [blame] | 3064 | return qla2x00_post_work(vha, e); |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 3065 | } |
| 3066 | |
Andrew Vasquez | 8a65957 | 2009-02-08 20:50:12 -0800 | [diff] [blame] | 3067 | int |
| 3068 | qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb) |
| 3069 | { |
| 3070 | struct qla_work_evt *e; |
| 3071 | |
Andrew Vasquez | f999f4c | 2009-06-03 09:55:28 -0700 | [diff] [blame] | 3072 | e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK); |
Andrew Vasquez | 8a65957 | 2009-02-08 20:50:12 -0800 | [diff] [blame] | 3073 | if (!e) |
| 3074 | return QLA_FUNCTION_FAILED; |
| 3075 | |
| 3076 | memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t)); |
Andrew Vasquez | f999f4c | 2009-06-03 09:55:28 -0700 | [diff] [blame] | 3077 | return qla2x00_post_work(vha, e); |
Andrew Vasquez | 8a65957 | 2009-02-08 20:50:12 -0800 | [diff] [blame] | 3078 | } |
| 3079 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3080 | #define qla2x00_post_async_work(name, type) \ |
| 3081 | int qla2x00_post_async_##name##_work( \ |
| 3082 | struct scsi_qla_host *vha, \ |
| 3083 | fc_port_t *fcport, uint16_t *data) \ |
| 3084 | { \ |
| 3085 | struct qla_work_evt *e; \ |
| 3086 | \ |
| 3087 | e = qla2x00_alloc_work(vha, type); \ |
| 3088 | if (!e) \ |
| 3089 | return QLA_FUNCTION_FAILED; \ |
| 3090 | \ |
| 3091 | e->u.logio.fcport = fcport; \ |
| 3092 | if (data) { \ |
| 3093 | e->u.logio.data[0] = data[0]; \ |
| 3094 | e->u.logio.data[1] = data[1]; \ |
| 3095 | } \ |
| 3096 | return qla2x00_post_work(vha, e); \ |
| 3097 | } |
| 3098 | |
| 3099 | qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN); |
| 3100 | qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE); |
| 3101 | qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT); |
| 3102 | qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3103 | qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC); |
| 3104 | qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3105 | |
Andrew Vasquez | 3420d36 | 2009-10-13 15:16:45 -0700 | [diff] [blame] | 3106 | int |
| 3107 | qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code) |
| 3108 | { |
| 3109 | struct qla_work_evt *e; |
| 3110 | |
| 3111 | e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT); |
| 3112 | if (!e) |
| 3113 | return QLA_FUNCTION_FAILED; |
| 3114 | |
| 3115 | e->u.uevent.code = code; |
| 3116 | return qla2x00_post_work(vha, e); |
| 3117 | } |
| 3118 | |
| 3119 | static void |
| 3120 | qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code) |
| 3121 | { |
| 3122 | char event_string[40]; |
| 3123 | char *envp[] = { event_string, NULL }; |
| 3124 | |
| 3125 | switch (code) { |
| 3126 | case QLA_UEVENT_CODE_FW_DUMP: |
| 3127 | snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld", |
| 3128 | vha->host_no); |
| 3129 | break; |
| 3130 | default: |
| 3131 | /* do nothing */ |
| 3132 | break; |
| 3133 | } |
| 3134 | kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp); |
| 3135 | } |
| 3136 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3137 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3138 | qla2x00_do_work(struct scsi_qla_host *vha) |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 3139 | { |
Andrew Vasquez | f999f4c | 2009-06-03 09:55:28 -0700 | [diff] [blame] | 3140 | struct qla_work_evt *e, *tmp; |
| 3141 | unsigned long flags; |
| 3142 | LIST_HEAD(work); |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 3143 | |
Andrew Vasquez | f999f4c | 2009-06-03 09:55:28 -0700 | [diff] [blame] | 3144 | spin_lock_irqsave(&vha->work_lock, flags); |
| 3145 | list_splice_init(&vha->work_list, &work); |
| 3146 | spin_unlock_irqrestore(&vha->work_lock, flags); |
| 3147 | |
| 3148 | list_for_each_entry_safe(e, tmp, &work, list) { |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 3149 | list_del_init(&e->list); |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 3150 | |
| 3151 | switch (e->type) { |
| 3152 | case QLA_EVT_AEN: |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3153 | fc_host_post_event(vha->host, fc_get_event_number(), |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 3154 | e->u.aen.code, e->u.aen.data); |
| 3155 | break; |
Andrew Vasquez | 8a65957 | 2009-02-08 20:50:12 -0800 | [diff] [blame] | 3156 | case QLA_EVT_IDC_ACK: |
| 3157 | qla81xx_idc_ack(vha, e->u.idc_ack.mb); |
| 3158 | break; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3159 | case QLA_EVT_ASYNC_LOGIN: |
| 3160 | qla2x00_async_login(vha, e->u.logio.fcport, |
| 3161 | e->u.logio.data); |
| 3162 | break; |
| 3163 | case QLA_EVT_ASYNC_LOGIN_DONE: |
| 3164 | qla2x00_async_login_done(vha, e->u.logio.fcport, |
| 3165 | e->u.logio.data); |
| 3166 | break; |
| 3167 | case QLA_EVT_ASYNC_LOGOUT: |
| 3168 | qla2x00_async_logout(vha, e->u.logio.fcport); |
| 3169 | break; |
| 3170 | case QLA_EVT_ASYNC_LOGOUT_DONE: |
| 3171 | qla2x00_async_logout_done(vha, e->u.logio.fcport, |
| 3172 | e->u.logio.data); |
| 3173 | break; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3174 | case QLA_EVT_ASYNC_ADISC: |
| 3175 | qla2x00_async_adisc(vha, e->u.logio.fcport, |
| 3176 | e->u.logio.data); |
| 3177 | break; |
| 3178 | case QLA_EVT_ASYNC_ADISC_DONE: |
| 3179 | qla2x00_async_adisc_done(vha, e->u.logio.fcport, |
| 3180 | e->u.logio.data); |
| 3181 | break; |
Andrew Vasquez | 3420d36 | 2009-10-13 15:16:45 -0700 | [diff] [blame] | 3182 | case QLA_EVT_UEVENT: |
| 3183 | qla2x00_uevent_emit(vha, e->u.uevent.code); |
| 3184 | break; |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 3185 | } |
| 3186 | if (e->flags & QLA_EVT_FLAG_FREE) |
| 3187 | kfree(e); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3188 | |
| 3189 | /* For each work completed decrement vha ref count */ |
| 3190 | QLA_VHA_MARK_NOT_BUSY(vha); |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 3191 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3192 | } |
Andrew Vasquez | f999f4c | 2009-06-03 09:55:28 -0700 | [diff] [blame] | 3193 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3194 | /* Relogins all the fcports of a vport |
| 3195 | * Context: dpc thread |
| 3196 | */ |
| 3197 | void qla2x00_relogin(struct scsi_qla_host *vha) |
| 3198 | { |
| 3199 | fc_port_t *fcport; |
Andrew Vasquez | c6b2fca | 2009-03-05 11:07:03 -0800 | [diff] [blame] | 3200 | int status; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3201 | uint16_t next_loopid = 0; |
| 3202 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3203 | uint16_t data[2]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3204 | |
| 3205 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 3206 | /* |
| 3207 | * If the port is not ONLINE then try to login |
| 3208 | * to it if we haven't run out of retries. |
| 3209 | */ |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3210 | if (atomic_read(&fcport->state) != FCS_ONLINE && |
| 3211 | fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3212 | fcport->login_retry--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3213 | if (fcport->flags & FCF_FABRIC_DEVICE) { |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3214 | if (fcport->flags & FCF_FCP2_DEVICE) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3215 | ha->isp_ops->fabric_logout(vha, |
| 3216 | fcport->loop_id, |
| 3217 | fcport->d_id.b.domain, |
| 3218 | fcport->d_id.b.area, |
| 3219 | fcport->d_id.b.al_pa); |
| 3220 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3221 | if (IS_ALOGIO_CAPABLE(ha)) { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3222 | fcport->flags |= FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3223 | data[0] = 0; |
| 3224 | data[1] = QLA_LOGIO_LOGIN_RETRIED; |
| 3225 | status = qla2x00_post_async_login_work( |
| 3226 | vha, fcport, data); |
| 3227 | if (status == QLA_SUCCESS) |
| 3228 | continue; |
| 3229 | /* Attempt a retry. */ |
| 3230 | status = 1; |
| 3231 | } else |
| 3232 | status = qla2x00_fabric_login(vha, |
| 3233 | fcport, &next_loopid); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3234 | } else |
| 3235 | status = qla2x00_local_device_login(vha, |
| 3236 | fcport); |
| 3237 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3238 | if (status == QLA_SUCCESS) { |
| 3239 | fcport->old_loop_id = fcport->loop_id; |
| 3240 | |
| 3241 | DEBUG(printk("scsi(%ld): port login OK: logged " |
| 3242 | "in ID 0x%x\n", vha->host_no, fcport->loop_id)); |
| 3243 | |
| 3244 | qla2x00_update_fcport(vha, fcport); |
| 3245 | |
| 3246 | } else if (status == 1) { |
| 3247 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 3248 | /* retry the login again */ |
| 3249 | DEBUG(printk("scsi(%ld): Retrying" |
| 3250 | " %d login again loop_id 0x%x\n", |
| 3251 | vha->host_no, fcport->login_retry, |
| 3252 | fcport->loop_id)); |
| 3253 | } else { |
| 3254 | fcport->login_retry = 0; |
| 3255 | } |
| 3256 | |
| 3257 | if (fcport->login_retry == 0 && status != QLA_SUCCESS) |
| 3258 | fcport->loop_id = FC_NO_LOOP_ID; |
| 3259 | } |
| 3260 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 3261 | break; |
| 3262 | } |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 3263 | } |
| 3264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | /************************************************************************** |
| 3266 | * qla2x00_do_dpc |
| 3267 | * This kernel thread is a task that is schedule by the interrupt handler |
| 3268 | * to perform the background processing for interrupts. |
| 3269 | * |
| 3270 | * Notes: |
| 3271 | * This task always run in the context of a kernel thread. It |
| 3272 | * is kick-off by the driver's detect code and starts up |
| 3273 | * up one per adapter. It immediately goes to sleep and waits for |
| 3274 | * some fibre event. When either the interrupt handler or |
| 3275 | * the timer routine detects a event it will one of the task |
| 3276 | * bits then wake us up. |
| 3277 | **************************************************************************/ |
| 3278 | static int |
| 3279 | qla2x00_do_dpc(void *data) |
| 3280 | { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3281 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3282 | scsi_qla_host_t *base_vha; |
| 3283 | struct qla_hw_data *ha; |
Seokmann Ju | 99363ef | 2008-01-31 12:33:51 -0800 | [diff] [blame] | 3284 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3285 | ha = (struct qla_hw_data *)data; |
| 3286 | base_vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | set_user_nice(current, -20); |
| 3289 | |
Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 3290 | while (!kthread_should_stop()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3291 | DEBUG3(printk("qla2x00: DPC handler sleeping\n")); |
| 3292 | |
Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 3293 | set_current_state(TASK_INTERRUPTIBLE); |
| 3294 | schedule(); |
| 3295 | __set_current_state(TASK_RUNNING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | |
| 3297 | DEBUG3(printk("qla2x00: DPC handler waking up\n")); |
| 3298 | |
| 3299 | /* Initialization not yet finished. Don't do anything yet. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3300 | if (!base_vha->flags.init_done) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3301 | continue; |
| 3302 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 3303 | if (ha->flags.eeh_busy) { |
| 3304 | DEBUG17(qla_printk(KERN_WARNING, ha, |
| 3305 | "qla2x00_do_dpc: dpc_flags: %lx\n", |
| 3306 | base_vha->dpc_flags)); |
| 3307 | continue; |
| 3308 | } |
| 3309 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3310 | DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | |
| 3312 | ha->dpc_active = 1; |
| 3313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3314 | if (ha->flags.mbox_busy) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | ha->dpc_active = 0; |
| 3316 | continue; |
| 3317 | } |
| 3318 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3319 | qla2x00_do_work(base_vha); |
Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 3320 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3321 | if (IS_QLA82XX(ha)) { |
| 3322 | if (test_and_clear_bit(ISP_UNRECOVERABLE, |
| 3323 | &base_vha->dpc_flags)) { |
| 3324 | qla82xx_idc_lock(ha); |
| 3325 | qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE, |
| 3326 | QLA82XX_DEV_FAILED); |
| 3327 | qla82xx_idc_unlock(ha); |
| 3328 | qla_printk(KERN_INFO, ha, |
| 3329 | "HW State: FAILED\n"); |
| 3330 | qla82xx_device_state_handler(base_vha); |
| 3331 | continue; |
| 3332 | } |
| 3333 | |
| 3334 | if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED, |
| 3335 | &base_vha->dpc_flags)) { |
| 3336 | |
| 3337 | DEBUG(printk(KERN_INFO |
| 3338 | "scsi(%ld): dpc: sched " |
| 3339 | "qla82xx_fcoe_ctx_reset ha = %p\n", |
| 3340 | base_vha->host_no, ha)); |
| 3341 | if (!(test_and_set_bit(ABORT_ISP_ACTIVE, |
| 3342 | &base_vha->dpc_flags))) { |
| 3343 | if (qla82xx_fcoe_ctx_reset(base_vha)) { |
| 3344 | /* FCoE-ctx reset failed. |
| 3345 | * Escalate to chip-reset |
| 3346 | */ |
| 3347 | set_bit(ISP_ABORT_NEEDED, |
| 3348 | &base_vha->dpc_flags); |
| 3349 | } |
| 3350 | clear_bit(ABORT_ISP_ACTIVE, |
| 3351 | &base_vha->dpc_flags); |
| 3352 | } |
| 3353 | |
| 3354 | DEBUG(printk("scsi(%ld): dpc:" |
| 3355 | " qla82xx_fcoe_ctx_reset end\n", |
| 3356 | base_vha->host_no)); |
| 3357 | } |
| 3358 | } |
| 3359 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3360 | if (test_and_clear_bit(ISP_ABORT_NEEDED, |
| 3361 | &base_vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3362 | |
| 3363 | DEBUG(printk("scsi(%ld): dpc: sched " |
| 3364 | "qla2x00_abort_isp ha = %p\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3365 | base_vha->host_no, ha)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3366 | if (!(test_and_set_bit(ABORT_ISP_ACTIVE, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3367 | &base_vha->dpc_flags))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3369 | if (ha->isp_ops->abort_isp(base_vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3370 | /* failed. retry later */ |
| 3371 | set_bit(ISP_ABORT_NEEDED, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3372 | &base_vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3374 | clear_bit(ABORT_ISP_ACTIVE, |
| 3375 | &base_vha->dpc_flags); |
Seokmann Ju | 99363ef | 2008-01-31 12:33:51 -0800 | [diff] [blame] | 3376 | } |
| 3377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3378 | DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3379 | base_vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3380 | } |
| 3381 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3382 | if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) { |
| 3383 | qla2x00_update_fcports(base_vha); |
| 3384 | clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags); |
Andrew Vasquez | c9c5ced | 2008-07-24 08:31:49 -0700 | [diff] [blame] | 3385 | } |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3386 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3387 | if (test_and_clear_bit(RESET_MARKER_NEEDED, |
| 3388 | &base_vha->dpc_flags) && |
| 3389 | (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | |
| 3391 | DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3392 | base_vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3394 | qla2x00_rst_aen(base_vha); |
| 3395 | clear_bit(RESET_ACTIVE, &base_vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | } |
| 3397 | |
| 3398 | /* Retry each device up to login retry count */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3399 | if ((test_and_clear_bit(RELOGIN_NEEDED, |
| 3400 | &base_vha->dpc_flags)) && |
| 3401 | !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) && |
| 3402 | atomic_read(&base_vha->loop_state) != LOOP_DOWN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3403 | |
| 3404 | DEBUG(printk("scsi(%ld): qla2x00_port_login()\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3405 | base_vha->host_no)); |
| 3406 | qla2x00_relogin(base_vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3408 | DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3409 | base_vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3410 | } |
| 3411 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3412 | if (test_and_clear_bit(LOOP_RESYNC_NEEDED, |
| 3413 | &base_vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3414 | |
| 3415 | DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3416 | base_vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | |
| 3418 | if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3419 | &base_vha->dpc_flags))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3421 | rval = qla2x00_loop_resync(base_vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3423 | clear_bit(LOOP_RESYNC_ACTIVE, |
| 3424 | &base_vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3425 | } |
| 3426 | |
| 3427 | DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3428 | base_vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3429 | } |
| 3430 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3431 | if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) && |
| 3432 | atomic_read(&base_vha->loop_state) == LOOP_READY) { |
| 3433 | clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags); |
| 3434 | qla2xxx_flash_npiv_conf(base_vha); |
Andrew Vasquez | 272976c | 2008-09-11 21:22:50 -0700 | [diff] [blame] | 3435 | } |
| 3436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3437 | if (!ha->interrupts_on) |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 3438 | ha->isp_ops->enable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3439 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3440 | if (test_and_clear_bit(BEACON_BLINK_NEEDED, |
| 3441 | &base_vha->dpc_flags)) |
| 3442 | ha->isp_ops->beacon_blink(base_vha); |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 3443 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3444 | qla2x00_do_dpc_all_vps(base_vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3445 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3446 | ha->dpc_active = 0; |
| 3447 | } /* End of while(1) */ |
| 3448 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3449 | DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | |
| 3451 | /* |
| 3452 | * Make sure that nobody tries to wake us up again. |
| 3453 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3454 | ha->dpc_active = 0; |
| 3455 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3456 | /* Cleanup any residual CTX SRBs. */ |
| 3457 | qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16); |
| 3458 | |
Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 3459 | return 0; |
| 3460 | } |
| 3461 | |
| 3462 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3463 | qla2xxx_wake_dpc(struct scsi_qla_host *vha) |
Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 3464 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3465 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | c795c1e | 2008-08-13 21:37:01 -0700 | [diff] [blame] | 3466 | struct task_struct *t = ha->dpc_thread; |
| 3467 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3468 | if (!test_bit(UNLOADING, &vha->dpc_flags) && t) |
Andrew Vasquez | c795c1e | 2008-08-13 21:37:01 -0700 | [diff] [blame] | 3469 | wake_up_process(t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3470 | } |
| 3471 | |
| 3472 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3473 | * qla2x00_rst_aen |
| 3474 | * Processes asynchronous reset. |
| 3475 | * |
| 3476 | * Input: |
| 3477 | * ha = adapter block pointer. |
| 3478 | */ |
| 3479 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3480 | qla2x00_rst_aen(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3481 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3482 | if (vha->flags.online && !vha->flags.reset_active && |
| 3483 | !atomic_read(&vha->loop_down_timer) && |
| 3484 | !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3485 | do { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3486 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3487 | |
| 3488 | /* |
| 3489 | * Issue marker command only when we are going to start |
| 3490 | * the I/O. |
| 3491 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3492 | vha->marker_needed = 1; |
| 3493 | } while (!atomic_read(&vha->loop_down_timer) && |
| 3494 | (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3495 | } |
| 3496 | } |
| 3497 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 3498 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3499 | qla2x00_sp_free_dma(srb_t *sp) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 3500 | { |
| 3501 | struct scsi_cmnd *cmd = sp->cmd; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 3502 | struct qla_hw_data *ha = sp->fcport->vha->hw; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 3503 | |
| 3504 | if (sp->flags & SRB_DMA_VALID) { |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 3505 | scsi_dma_unmap(cmd); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 3506 | sp->flags &= ~SRB_DMA_VALID; |
| 3507 | } |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 3508 | |
| 3509 | if (sp->flags & SRB_CRC_PROT_DMA_VALID) { |
| 3510 | dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd), |
| 3511 | scsi_prot_sg_count(cmd), cmd->sc_data_direction); |
| 3512 | sp->flags &= ~SRB_CRC_PROT_DMA_VALID; |
| 3513 | } |
| 3514 | |
| 3515 | if (sp->flags & SRB_CRC_CTX_DSD_VALID) { |
| 3516 | /* List assured to be having elements */ |
| 3517 | qla2x00_clean_dsd_pool(ha, sp); |
| 3518 | sp->flags &= ~SRB_CRC_CTX_DSD_VALID; |
| 3519 | } |
| 3520 | |
| 3521 | if (sp->flags & SRB_CRC_CTX_DMA_VALID) { |
| 3522 | dma_pool_free(ha->dl_dma_pool, sp->ctx, |
| 3523 | ((struct crc_context *)sp->ctx)->crc_ctx_dma); |
| 3524 | sp->flags &= ~SRB_CRC_CTX_DMA_VALID; |
| 3525 | } |
| 3526 | |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 3527 | CMD_SP(cmd) = NULL; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 3528 | } |
| 3529 | |
Andrew Vasquez | 3dbe756 | 2010-07-23 15:28:37 +0500 | [diff] [blame] | 3530 | static void |
Giridhar Malavali | 083a469 | 2010-05-28 15:08:18 -0700 | [diff] [blame] | 3531 | qla2x00_sp_final_compl(struct qla_hw_data *ha, srb_t *sp) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 3532 | { |
| 3533 | struct scsi_cmnd *cmd = sp->cmd; |
| 3534 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3535 | qla2x00_sp_free_dma(sp); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 3536 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3537 | if (sp->flags & SRB_FCP_CMND_DMA_VALID) { |
| 3538 | struct ct6_dsd *ctx = sp->ctx; |
| 3539 | dma_pool_free(ha->fcp_cmnd_dma_pool, ctx->fcp_cmnd, |
| 3540 | ctx->fcp_cmnd_dma); |
| 3541 | list_splice(&ctx->dsd_list, &ha->gbl_dsd_list); |
| 3542 | ha->gbl_dsd_inuse -= ctx->dsd_use_cnt; |
| 3543 | ha->gbl_dsd_avail += ctx->dsd_use_cnt; |
| 3544 | mempool_free(sp->ctx, ha->ctx_mempool); |
| 3545 | sp->ctx = NULL; |
| 3546 | } |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 3547 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3548 | mempool_free(sp, ha->srb_mempool); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 3549 | cmd->scsi_done(cmd); |
| 3550 | } |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 3551 | |
Giridhar Malavali | 083a469 | 2010-05-28 15:08:18 -0700 | [diff] [blame] | 3552 | void |
| 3553 | qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp) |
| 3554 | { |
| 3555 | if (atomic_read(&sp->ref_count) == 0) { |
| 3556 | DEBUG2(qla_printk(KERN_WARNING, ha, |
| 3557 | "SP reference-count to ZERO -- sp=%p\n", sp)); |
| 3558 | DEBUG2(BUG()); |
| 3559 | return; |
| 3560 | } |
| 3561 | if (!atomic_dec_and_test(&sp->ref_count)) |
| 3562 | return; |
| 3563 | qla2x00_sp_final_compl(ha, sp); |
| 3564 | } |
| 3565 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3566 | /************************************************************************** |
| 3567 | * qla2x00_timer |
| 3568 | * |
| 3569 | * Description: |
| 3570 | * One second timer |
| 3571 | * |
| 3572 | * Context: Interrupt |
| 3573 | ***************************************************************************/ |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3574 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3575 | qla2x00_timer(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3576 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | unsigned long cpu_flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3578 | int start_dpc = 0; |
| 3579 | int index; |
| 3580 | srb_t *sp; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 3581 | uint16_t w; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3582 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3583 | struct req_que *req; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 3584 | |
Lalit Chandivade | a5b3632 | 2010-09-03 15:20:50 -0700 | [diff] [blame] | 3585 | if (ha->flags.eeh_busy) { |
| 3586 | qla2x00_restart_timer(vha, WATCH_INTERVAL); |
| 3587 | return; |
| 3588 | } |
| 3589 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3590 | if (IS_QLA82XX(ha)) |
| 3591 | qla82xx_watchdog(vha); |
| 3592 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 3593 | /* Hardware read to raise pending EEH errors during mailbox waits. */ |
| 3594 | if (!pci_channel_offline(ha->pdev)) |
| 3595 | pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3596 | |
| 3597 | /* Loop down handler. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3598 | if (atomic_read(&vha->loop_down_timer) > 0 && |
| 3599 | !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) |
| 3600 | && vha->flags.online) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3602 | if (atomic_read(&vha->loop_down_timer) == |
| 3603 | vha->loop_down_abort_time) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3604 | |
| 3605 | DEBUG(printk("scsi(%ld): Loop Down - aborting the " |
| 3606 | "queues before time expire\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3607 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3608 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3609 | if (!IS_QLA2100(ha) && vha->link_down_timeout) |
| 3610 | atomic_set(&vha->loop_state, LOOP_DEAD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3611 | |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3612 | /* |
| 3613 | * Schedule an ISP abort to return any FCP2-device |
| 3614 | * commands. |
| 3615 | */ |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3616 | /* NPIV - scan physical port only */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3617 | if (!vha->vp_idx) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3618 | spin_lock_irqsave(&ha->hardware_lock, |
| 3619 | cpu_flags); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3620 | req = ha->req_q_map[0]; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3621 | for (index = 1; |
| 3622 | index < MAX_OUTSTANDING_COMMANDS; |
| 3623 | index++) { |
| 3624 | fc_port_t *sfcp; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 3625 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3626 | sp = req->outstanding_cmds[index]; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3627 | if (!sp) |
| 3628 | continue; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 3629 | if (sp->ctx && !IS_PROT_IO(sp)) |
Andrew Vasquez | cf53b06 | 2009-08-20 11:06:04 -0700 | [diff] [blame] | 3630 | continue; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3631 | sfcp = sp->fcport; |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3632 | if (!(sfcp->flags & FCF_FCP2_DEVICE)) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3633 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3634 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3635 | set_bit(ISP_ABORT_NEEDED, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3636 | &vha->dpc_flags); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3637 | break; |
| 3638 | } |
| 3639 | spin_unlock_irqrestore(&ha->hardware_lock, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3640 | cpu_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3641 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3642 | start_dpc++; |
| 3643 | } |
| 3644 | |
| 3645 | /* if the loop has been down for 4 minutes, reinit adapter */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3646 | if (atomic_dec_and_test(&vha->loop_down_timer) != 0) { |
Andrew Vasquez | 0d6e61b | 2009-08-25 11:36:19 -0700 | [diff] [blame] | 3647 | if (!(vha->device_flags & DFLG_NO_CABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3648 | DEBUG(printk("scsi(%ld): Loop down - " |
| 3649 | "aborting ISP.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3650 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3651 | qla_printk(KERN_WARNING, ha, |
| 3652 | "Loop down - aborting ISP.\n"); |
| 3653 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3654 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3655 | } |
| 3656 | } |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 3657 | DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3658 | vha->host_no, |
| 3659 | atomic_read(&vha->loop_down_timer))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | } |
| 3661 | |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 3662 | /* Check if beacon LED needs to be blinked */ |
| 3663 | if (ha->beacon_blink_led == 1) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3664 | set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags); |
andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 3665 | start_dpc++; |
| 3666 | } |
| 3667 | |
Andrew Vasquez | 550bf57 | 2008-04-24 15:21:23 -0700 | [diff] [blame] | 3668 | /* Process any deferred work. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3669 | if (!list_empty(&vha->work_list)) |
Andrew Vasquez | 550bf57 | 2008-04-24 15:21:23 -0700 | [diff] [blame] | 3670 | start_dpc++; |
| 3671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3672 | /* Schedule the DPC routine if needed */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3673 | if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) || |
| 3674 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) || |
| 3675 | test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3676 | start_dpc || |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3677 | test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) || |
| 3678 | test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) || |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3679 | test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) || |
| 3680 | test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) || |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3681 | test_bit(VP_DPC_NEEDED, &vha->dpc_flags) || |
| 3682 | test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) |
| 3683 | qla2xxx_wake_dpc(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3684 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3685 | qla2x00_restart_timer(vha, WATCH_INTERVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 | } |
| 3687 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3688 | /* Firmware interface routines. */ |
| 3689 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3690 | #define FW_BLOBS 8 |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3691 | #define FW_ISP21XX 0 |
| 3692 | #define FW_ISP22XX 1 |
| 3693 | #define FW_ISP2300 2 |
| 3694 | #define FW_ISP2322 3 |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 3695 | #define FW_ISP24XX 4 |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 3696 | #define FW_ISP25XX 5 |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 3697 | #define FW_ISP81XX 6 |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3698 | #define FW_ISP82XX 7 |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3699 | |
Andrew Vasquez | bb8ee49 | 2006-10-02 12:00:48 -0700 | [diff] [blame] | 3700 | #define FW_FILE_ISP21XX "ql2100_fw.bin" |
| 3701 | #define FW_FILE_ISP22XX "ql2200_fw.bin" |
| 3702 | #define FW_FILE_ISP2300 "ql2300_fw.bin" |
| 3703 | #define FW_FILE_ISP2322 "ql2322_fw.bin" |
| 3704 | #define FW_FILE_ISP24XX "ql2400_fw.bin" |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 3705 | #define FW_FILE_ISP25XX "ql2500_fw.bin" |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 3706 | #define FW_FILE_ISP81XX "ql8100_fw.bin" |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3707 | #define FW_FILE_ISP82XX "ql8200_fw.bin" |
Andrew Vasquez | bb8ee49 | 2006-10-02 12:00:48 -0700 | [diff] [blame] | 3708 | |
Daniel Walker | e1e82b6 | 2008-05-12 22:21:10 -0700 | [diff] [blame] | 3709 | static DEFINE_MUTEX(qla_fw_lock); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3710 | |
| 3711 | static struct fw_blob qla_fw_blobs[FW_BLOBS] = { |
Andrew Vasquez | bb8ee49 | 2006-10-02 12:00:48 -0700 | [diff] [blame] | 3712 | { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, }, |
| 3713 | { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, }, |
| 3714 | { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, }, |
| 3715 | { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, }, |
| 3716 | { .name = FW_FILE_ISP24XX, }, |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 3717 | { .name = FW_FILE_ISP25XX, }, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 3718 | { .name = FW_FILE_ISP81XX, }, |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3719 | { .name = FW_FILE_ISP82XX, }, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3720 | }; |
| 3721 | |
| 3722 | struct fw_blob * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3723 | qla2x00_request_firmware(scsi_qla_host_t *vha) |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3724 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3725 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3726 | struct fw_blob *blob; |
| 3727 | |
| 3728 | blob = NULL; |
| 3729 | if (IS_QLA2100(ha)) { |
| 3730 | blob = &qla_fw_blobs[FW_ISP21XX]; |
| 3731 | } else if (IS_QLA2200(ha)) { |
| 3732 | blob = &qla_fw_blobs[FW_ISP22XX]; |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 3733 | } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3734 | blob = &qla_fw_blobs[FW_ISP2300]; |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 3735 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) { |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3736 | blob = &qla_fw_blobs[FW_ISP2322]; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3737 | } else if (IS_QLA24XX_TYPE(ha)) { |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3738 | blob = &qla_fw_blobs[FW_ISP24XX]; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 3739 | } else if (IS_QLA25XX(ha)) { |
| 3740 | blob = &qla_fw_blobs[FW_ISP25XX]; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 3741 | } else if (IS_QLA81XX(ha)) { |
| 3742 | blob = &qla_fw_blobs[FW_ISP81XX]; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3743 | } else if (IS_QLA82XX(ha)) { |
| 3744 | blob = &qla_fw_blobs[FW_ISP82XX]; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3745 | } |
| 3746 | |
Daniel Walker | e1e82b6 | 2008-05-12 22:21:10 -0700 | [diff] [blame] | 3747 | mutex_lock(&qla_fw_lock); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3748 | if (blob->fw) |
| 3749 | goto out; |
| 3750 | |
| 3751 | if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) { |
| 3752 | DEBUG2(printk("scsi(%ld): Failed to load firmware image " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3753 | "(%s).\n", vha->host_no, blob->name)); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3754 | blob->fw = NULL; |
| 3755 | blob = NULL; |
| 3756 | goto out; |
| 3757 | } |
| 3758 | |
| 3759 | out: |
Daniel Walker | e1e82b6 | 2008-05-12 22:21:10 -0700 | [diff] [blame] | 3760 | mutex_unlock(&qla_fw_lock); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3761 | return blob; |
| 3762 | } |
| 3763 | |
| 3764 | static void |
| 3765 | qla2x00_release_firmware(void) |
| 3766 | { |
| 3767 | int idx; |
| 3768 | |
Daniel Walker | e1e82b6 | 2008-05-12 22:21:10 -0700 | [diff] [blame] | 3769 | mutex_lock(&qla_fw_lock); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3770 | for (idx = 0; idx < FW_BLOBS; idx++) |
| 3771 | if (qla_fw_blobs[idx].fw) |
| 3772 | release_firmware(qla_fw_blobs[idx].fw); |
Daniel Walker | e1e82b6 | 2008-05-12 22:21:10 -0700 | [diff] [blame] | 3773 | mutex_unlock(&qla_fw_lock); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3774 | } |
| 3775 | |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3776 | static pci_ers_result_t |
| 3777 | qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 3778 | { |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 3779 | scsi_qla_host_t *vha = pci_get_drvdata(pdev); |
| 3780 | struct qla_hw_data *ha = vha->hw; |
| 3781 | |
| 3782 | DEBUG2(qla_printk(KERN_WARNING, ha, "error_detected:state %x\n", |
| 3783 | state)); |
Seokmann Ju | b9b12f7 | 2009-03-24 09:08:18 -0700 | [diff] [blame] | 3784 | |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3785 | switch (state) { |
| 3786 | case pci_channel_io_normal: |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 3787 | ha->flags.eeh_busy = 0; |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3788 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 3789 | case pci_channel_io_frozen: |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 3790 | ha->flags.eeh_busy = 1; |
Lalit Chandivade | a5b3632 | 2010-09-03 15:20:50 -0700 | [diff] [blame] | 3791 | /* For ISP82XX complete any pending mailbox cmd */ |
| 3792 | if (IS_QLA82XX(ha)) { |
| 3793 | ha->flags.fw_hung = 1; |
| 3794 | if (ha->flags.mbox_busy) { |
| 3795 | ha->flags.mbox_int = 1; |
| 3796 | DEBUG2(qla_printk(KERN_ERR, ha, |
| 3797 | "Due to pci channel io frozen, doing premature " |
| 3798 | "completion of mbx command\n")); |
| 3799 | complete(&ha->mbx_intr_comp); |
| 3800 | } |
| 3801 | } |
Joe Carnuccio | 90a86fc | 2010-01-12 13:02:46 -0800 | [diff] [blame] | 3802 | qla2x00_free_irqs(vha); |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3803 | pci_disable_device(pdev); |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 3804 | /* Return back all IOs */ |
| 3805 | qla2x00_abort_all_cmds(vha, DID_RESET << 16); |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3806 | return PCI_ERS_RESULT_NEED_RESET; |
| 3807 | case pci_channel_io_perm_failure: |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 3808 | ha->flags.pci_channel_io_perm_failure = 1; |
| 3809 | qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16); |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3810 | return PCI_ERS_RESULT_DISCONNECT; |
| 3811 | } |
| 3812 | return PCI_ERS_RESULT_NEED_RESET; |
| 3813 | } |
| 3814 | |
| 3815 | static pci_ers_result_t |
| 3816 | qla2xxx_pci_mmio_enabled(struct pci_dev *pdev) |
| 3817 | { |
| 3818 | int risc_paused = 0; |
| 3819 | uint32_t stat; |
| 3820 | unsigned long flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3821 | scsi_qla_host_t *base_vha = pci_get_drvdata(pdev); |
| 3822 | struct qla_hw_data *ha = base_vha->hw; |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3823 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 3824 | struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24; |
| 3825 | |
Saurav Kashyap | bcc5b6d | 2010-09-03 15:20:57 -0700 | [diff] [blame] | 3826 | if (IS_QLA82XX(ha)) |
| 3827 | return PCI_ERS_RESULT_RECOVERED; |
| 3828 | |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3829 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3830 | if (IS_QLA2100(ha) || IS_QLA2200(ha)){ |
| 3831 | stat = RD_REG_DWORD(®->hccr); |
| 3832 | if (stat & HCCR_RISC_PAUSE) |
| 3833 | risc_paused = 1; |
| 3834 | } else if (IS_QLA23XX(ha)) { |
| 3835 | stat = RD_REG_DWORD(®->u.isp2300.host_status); |
| 3836 | if (stat & HSR_RISC_PAUSED) |
| 3837 | risc_paused = 1; |
| 3838 | } else if (IS_FWI2_CAPABLE(ha)) { |
| 3839 | stat = RD_REG_DWORD(®24->host_status); |
| 3840 | if (stat & HSRX_RISC_PAUSED) |
| 3841 | risc_paused = 1; |
| 3842 | } |
| 3843 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3844 | |
| 3845 | if (risc_paused) { |
| 3846 | qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, " |
| 3847 | "Dumping firmware!\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3848 | ha->isp_ops->fw_dump(base_vha, 0); |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3849 | |
| 3850 | return PCI_ERS_RESULT_NEED_RESET; |
| 3851 | } else |
| 3852 | return PCI_ERS_RESULT_RECOVERED; |
| 3853 | } |
| 3854 | |
Lalit Chandivade | a5b3632 | 2010-09-03 15:20:50 -0700 | [diff] [blame] | 3855 | uint32_t qla82xx_error_recovery(scsi_qla_host_t *base_vha) |
| 3856 | { |
| 3857 | uint32_t rval = QLA_FUNCTION_FAILED; |
| 3858 | uint32_t drv_active = 0; |
| 3859 | struct qla_hw_data *ha = base_vha->hw; |
| 3860 | int fn; |
| 3861 | struct pci_dev *other_pdev = NULL; |
| 3862 | |
| 3863 | DEBUG17(qla_printk(KERN_INFO, ha, |
| 3864 | "scsi(%ld): In qla82xx_error_recovery\n", base_vha->host_no)); |
| 3865 | |
| 3866 | set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); |
| 3867 | |
| 3868 | if (base_vha->flags.online) { |
| 3869 | /* Abort all outstanding commands, |
| 3870 | * so as to be requeued later */ |
| 3871 | qla2x00_abort_isp_cleanup(base_vha); |
| 3872 | } |
| 3873 | |
| 3874 | |
| 3875 | fn = PCI_FUNC(ha->pdev->devfn); |
| 3876 | while (fn > 0) { |
| 3877 | fn--; |
| 3878 | DEBUG17(qla_printk(KERN_INFO, ha, |
| 3879 | "Finding pci device at function = 0x%x\n", fn)); |
| 3880 | other_pdev = |
| 3881 | pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus), |
| 3882 | ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn), |
| 3883 | fn)); |
| 3884 | |
| 3885 | if (!other_pdev) |
| 3886 | continue; |
| 3887 | if (atomic_read(&other_pdev->enable_cnt)) { |
| 3888 | DEBUG17(qla_printk(KERN_INFO, ha, |
| 3889 | "Found PCI func availabe and enabled at 0x%x\n", |
| 3890 | fn)); |
| 3891 | pci_dev_put(other_pdev); |
| 3892 | break; |
| 3893 | } |
| 3894 | pci_dev_put(other_pdev); |
| 3895 | } |
| 3896 | |
| 3897 | if (!fn) { |
| 3898 | /* Reset owner */ |
| 3899 | DEBUG17(qla_printk(KERN_INFO, ha, |
| 3900 | "This devfn is reset owner = 0x%x\n", ha->pdev->devfn)); |
| 3901 | qla82xx_idc_lock(ha); |
| 3902 | |
| 3903 | qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE, |
| 3904 | QLA82XX_DEV_INITIALIZING); |
| 3905 | |
| 3906 | qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION, |
| 3907 | QLA82XX_IDC_VERSION); |
| 3908 | |
| 3909 | drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE); |
| 3910 | DEBUG17(qla_printk(KERN_INFO, ha, |
| 3911 | "drv_active = 0x%x\n", drv_active)); |
| 3912 | |
| 3913 | qla82xx_idc_unlock(ha); |
| 3914 | /* Reset if device is not already reset |
| 3915 | * drv_active would be 0 if a reset has already been done |
| 3916 | */ |
| 3917 | if (drv_active) |
| 3918 | rval = qla82xx_start_firmware(base_vha); |
| 3919 | else |
| 3920 | rval = QLA_SUCCESS; |
| 3921 | qla82xx_idc_lock(ha); |
| 3922 | |
| 3923 | if (rval != QLA_SUCCESS) { |
| 3924 | qla_printk(KERN_INFO, ha, "HW State: FAILED\n"); |
| 3925 | qla82xx_clear_drv_active(ha); |
| 3926 | qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE, |
| 3927 | QLA82XX_DEV_FAILED); |
| 3928 | } else { |
| 3929 | qla_printk(KERN_INFO, ha, "HW State: READY\n"); |
| 3930 | qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE, |
| 3931 | QLA82XX_DEV_READY); |
| 3932 | qla82xx_idc_unlock(ha); |
| 3933 | ha->flags.fw_hung = 0; |
| 3934 | rval = qla82xx_restart_isp(base_vha); |
| 3935 | qla82xx_idc_lock(ha); |
| 3936 | /* Clear driver state register */ |
| 3937 | qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0); |
| 3938 | qla82xx_set_drv_active(base_vha); |
| 3939 | } |
| 3940 | qla82xx_idc_unlock(ha); |
| 3941 | } else { |
| 3942 | DEBUG17(qla_printk(KERN_INFO, ha, |
| 3943 | "This devfn is not reset owner = 0x%x\n", ha->pdev->devfn)); |
| 3944 | if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) == |
| 3945 | QLA82XX_DEV_READY)) { |
| 3946 | ha->flags.fw_hung = 0; |
| 3947 | rval = qla82xx_restart_isp(base_vha); |
| 3948 | qla82xx_idc_lock(ha); |
| 3949 | qla82xx_set_drv_active(base_vha); |
| 3950 | qla82xx_idc_unlock(ha); |
| 3951 | } |
| 3952 | } |
| 3953 | clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); |
| 3954 | |
| 3955 | return rval; |
| 3956 | } |
| 3957 | |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3958 | static pci_ers_result_t |
| 3959 | qla2xxx_pci_slot_reset(struct pci_dev *pdev) |
| 3960 | { |
| 3961 | pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3962 | scsi_qla_host_t *base_vha = pci_get_drvdata(pdev); |
| 3963 | struct qla_hw_data *ha = base_vha->hw; |
Joe Carnuccio | 90a86fc | 2010-01-12 13:02:46 -0800 | [diff] [blame] | 3964 | struct rsp_que *rsp; |
| 3965 | int rc, retries = 10; |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3966 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 3967 | DEBUG17(qla_printk(KERN_WARNING, ha, "slot_reset\n")); |
| 3968 | |
Joe Carnuccio | 90a86fc | 2010-01-12 13:02:46 -0800 | [diff] [blame] | 3969 | /* Workaround: qla2xxx driver which access hardware earlier |
| 3970 | * needs error state to be pci_channel_io_online. |
| 3971 | * Otherwise mailbox command timesout. |
| 3972 | */ |
| 3973 | pdev->error_state = pci_channel_io_normal; |
| 3974 | |
| 3975 | pci_restore_state(pdev); |
| 3976 | |
Richard Lary | 8c1496b | 2010-02-18 10:07:29 -0800 | [diff] [blame] | 3977 | /* pci_restore_state() clears the saved_state flag of the device |
| 3978 | * save restored state which resets saved_state flag |
| 3979 | */ |
| 3980 | pci_save_state(pdev); |
| 3981 | |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 3982 | if (ha->mem_only) |
| 3983 | rc = pci_enable_device_mem(pdev); |
| 3984 | else |
| 3985 | rc = pci_enable_device(pdev); |
| 3986 | |
| 3987 | if (rc) { |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3988 | qla_printk(KERN_WARNING, ha, |
| 3989 | "Can't re-enable PCI device after reset.\n"); |
Lalit Chandivade | a5b3632 | 2010-09-03 15:20:50 -0700 | [diff] [blame] | 3990 | goto exit_slot_reset; |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3991 | } |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3992 | |
Joe Carnuccio | 90a86fc | 2010-01-12 13:02:46 -0800 | [diff] [blame] | 3993 | rsp = ha->rsp_q_map[0]; |
| 3994 | if (qla2x00_request_irqs(ha, rsp)) |
Lalit Chandivade | a5b3632 | 2010-09-03 15:20:50 -0700 | [diff] [blame] | 3995 | goto exit_slot_reset; |
Joe Carnuccio | 90a86fc | 2010-01-12 13:02:46 -0800 | [diff] [blame] | 3996 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3997 | if (ha->isp_ops->pci_config(base_vha)) |
Lalit Chandivade | a5b3632 | 2010-09-03 15:20:50 -0700 | [diff] [blame] | 3998 | goto exit_slot_reset; |
| 3999 | |
| 4000 | if (IS_QLA82XX(ha)) { |
| 4001 | if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) { |
| 4002 | ret = PCI_ERS_RESULT_RECOVERED; |
| 4003 | goto exit_slot_reset; |
| 4004 | } else |
| 4005 | goto exit_slot_reset; |
| 4006 | } |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 4007 | |
Joe Carnuccio | 90a86fc | 2010-01-12 13:02:46 -0800 | [diff] [blame] | 4008 | while (ha->flags.mbox_busy && retries--) |
| 4009 | msleep(1000); |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 4010 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4011 | set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4012 | if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS) |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 4013 | ret = PCI_ERS_RESULT_RECOVERED; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4014 | clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 4015 | |
Joe Carnuccio | 90a86fc | 2010-01-12 13:02:46 -0800 | [diff] [blame] | 4016 | |
Lalit Chandivade | a5b3632 | 2010-09-03 15:20:50 -0700 | [diff] [blame] | 4017 | exit_slot_reset: |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 4018 | DEBUG17(qla_printk(KERN_WARNING, ha, |
| 4019 | "slot_reset-return:ret=%x\n", ret)); |
| 4020 | |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 4021 | return ret; |
| 4022 | } |
| 4023 | |
| 4024 | static void |
| 4025 | qla2xxx_pci_resume(struct pci_dev *pdev) |
| 4026 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4027 | scsi_qla_host_t *base_vha = pci_get_drvdata(pdev); |
| 4028 | struct qla_hw_data *ha = base_vha->hw; |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 4029 | int ret; |
| 4030 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 4031 | DEBUG17(qla_printk(KERN_WARNING, ha, "pci_resume\n")); |
| 4032 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4033 | ret = qla2x00_wait_for_hba_online(base_vha); |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 4034 | if (ret != QLA_SUCCESS) { |
| 4035 | qla_printk(KERN_ERR, ha, |
| 4036 | "the device failed to resume I/O " |
| 4037 | "from slot/link_reset"); |
| 4038 | } |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 4039 | |
Lalit Chandivade | 3e46f03 | 2010-05-04 15:01:23 -0700 | [diff] [blame] | 4040 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 4041 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 4042 | ha->flags.eeh_busy = 0; |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 4043 | } |
| 4044 | |
| 4045 | static struct pci_error_handlers qla2xxx_err_handler = { |
| 4046 | .error_detected = qla2xxx_pci_error_detected, |
| 4047 | .mmio_enabled = qla2xxx_pci_mmio_enabled, |
| 4048 | .slot_reset = qla2xxx_pci_slot_reset, |
| 4049 | .resume = qla2xxx_pci_resume, |
| 4050 | }; |
| 4051 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4052 | static struct pci_device_id qla2xxx_pci_tbl[] = { |
Andrew Vasquez | 47f5e06 | 2006-05-17 15:09:39 -0700 | [diff] [blame] | 4053 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) }, |
| 4054 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) }, |
| 4055 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) }, |
| 4056 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) }, |
| 4057 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) }, |
| 4058 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) }, |
| 4059 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) }, |
| 4060 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) }, |
| 4061 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) }, |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 4062 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) }, |
Andrew Vasquez | 47f5e06 | 2006-05-17 15:09:39 -0700 | [diff] [blame] | 4063 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) }, |
| 4064 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) }, |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 4065 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) }, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 4066 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) }, |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4067 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) }, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4068 | { 0 }, |
| 4069 | }; |
| 4070 | MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl); |
| 4071 | |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 4072 | static struct pci_driver qla2xxx_pci_driver = { |
Andrew Vasquez | cb63067 | 2006-05-17 15:09:45 -0700 | [diff] [blame] | 4073 | .name = QLA2XXX_DRIVER_NAME, |
James Bottomley | 0a21ef1 | 2005-12-01 12:51:50 -0600 | [diff] [blame] | 4074 | .driver = { |
| 4075 | .owner = THIS_MODULE, |
| 4076 | }, |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 4077 | .id_table = qla2xxx_pci_tbl, |
Andrew Vasquez | 7ee6139 | 2006-06-23 16:11:22 -0700 | [diff] [blame] | 4078 | .probe = qla2x00_probe_one, |
Adrian Bunk | 4c993f7 | 2008-01-14 00:55:16 -0800 | [diff] [blame] | 4079 | .remove = qla2x00_remove_one, |
Madhuranath Iyengar | e30d175 | 2010-10-15 11:27:46 -0700 | [diff] [blame] | 4080 | .shutdown = qla2x00_shutdown, |
Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 4081 | .err_handler = &qla2xxx_err_handler, |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 4082 | }; |
| 4083 | |
Harish Zunjarrao | 6a03b4c | 2010-05-04 15:01:24 -0700 | [diff] [blame] | 4084 | static struct file_operations apidev_fops = { |
| 4085 | .owner = THIS_MODULE, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 4086 | .llseek = noop_llseek, |
Harish Zunjarrao | 6a03b4c | 2010-05-04 15:01:24 -0700 | [diff] [blame] | 4087 | }; |
| 4088 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4089 | /** |
| 4090 | * qla2x00_module_init - Module initialization. |
| 4091 | **/ |
| 4092 | static int __init |
| 4093 | qla2x00_module_init(void) |
| 4094 | { |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 4095 | int ret = 0; |
| 4096 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4097 | /* Allocate cache for SRBs. */ |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 4098 | srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 4099 | SLAB_HWCACHE_ALIGN, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4100 | if (srb_cachep == NULL) { |
| 4101 | printk(KERN_ERR |
| 4102 | "qla2xxx: Unable to allocate SRB cache...Failing load!\n"); |
| 4103 | return -ENOMEM; |
| 4104 | } |
| 4105 | |
| 4106 | /* Derive version string. */ |
| 4107 | strcpy(qla2x00_version_str, QLA2XXX_VERSION); |
Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 4108 | if (ql2xextended_error_logging) |
Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 4109 | strcat(qla2x00_version_str, "-debug"); |
| 4110 | |
Andrew Vasquez | 1c97a12 | 2005-04-21 16:13:36 -0400 | [diff] [blame] | 4111 | qla2xxx_transport_template = |
| 4112 | fc_attach_transport(&qla2xxx_transport_functions); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4113 | if (!qla2xxx_transport_template) { |
| 4114 | kmem_cache_destroy(srb_cachep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4115 | return -ENODEV; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4116 | } |
Harish Zunjarrao | 6a03b4c | 2010-05-04 15:01:24 -0700 | [diff] [blame] | 4117 | |
| 4118 | apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops); |
| 4119 | if (apidev_major < 0) { |
| 4120 | printk(KERN_WARNING "qla2xxx: Unable to register char device " |
| 4121 | "%s\n", QLA2XXX_APIDEV); |
| 4122 | } |
| 4123 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4124 | qla2xxx_transport_vport_template = |
| 4125 | fc_attach_transport(&qla2xxx_transport_vport_functions); |
| 4126 | if (!qla2xxx_transport_vport_template) { |
| 4127 | kmem_cache_destroy(srb_cachep); |
| 4128 | fc_release_transport(qla2xxx_transport_template); |
| 4129 | return -ENODEV; |
| 4130 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | |
Andrew Vasquez | fd9a29f | 2008-05-12 22:21:08 -0700 | [diff] [blame] | 4132 | printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n", |
| 4133 | qla2x00_version_str); |
Andrew Vasquez | 7ee6139 | 2006-06-23 16:11:22 -0700 | [diff] [blame] | 4134 | ret = pci_register_driver(&qla2xxx_pci_driver); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 4135 | if (ret) { |
| 4136 | kmem_cache_destroy(srb_cachep); |
| 4137 | fc_release_transport(qla2xxx_transport_template); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4138 | fc_release_transport(qla2xxx_transport_vport_template); |
Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 4139 | } |
| 4140 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | } |
| 4142 | |
| 4143 | /** |
| 4144 | * qla2x00_module_exit - Module cleanup. |
| 4145 | **/ |
| 4146 | static void __exit |
| 4147 | qla2x00_module_exit(void) |
| 4148 | { |
Harish Zunjarrao | 6a03b4c | 2010-05-04 15:01:24 -0700 | [diff] [blame] | 4149 | unregister_chrdev(apidev_major, QLA2XXX_APIDEV); |
Andrew Vasquez | 7ee6139 | 2006-06-23 16:11:22 -0700 | [diff] [blame] | 4150 | pci_unregister_driver(&qla2xxx_pci_driver); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4151 | qla2x00_release_firmware(); |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 4152 | kmem_cache_destroy(srb_cachep); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4153 | if (ctx_cachep) |
| 4154 | kmem_cache_destroy(ctx_cachep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4155 | fc_release_transport(qla2xxx_transport_template); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4156 | fc_release_transport(qla2xxx_transport_vport_template); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4157 | } |
| 4158 | |
| 4159 | module_init(qla2x00_module_init); |
| 4160 | module_exit(qla2x00_module_exit); |
| 4161 | |
| 4162 | MODULE_AUTHOR("QLogic Corporation"); |
| 4163 | MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver"); |
| 4164 | MODULE_LICENSE("GPL"); |
| 4165 | MODULE_VERSION(QLA2XXX_VERSION); |
Andrew Vasquez | bb8ee49 | 2006-10-02 12:00:48 -0700 | [diff] [blame] | 4166 | MODULE_FIRMWARE(FW_FILE_ISP21XX); |
| 4167 | MODULE_FIRMWARE(FW_FILE_ISP22XX); |
| 4168 | MODULE_FIRMWARE(FW_FILE_ISP2300); |
| 4169 | MODULE_FIRMWARE(FW_FILE_ISP2322); |
| 4170 | MODULE_FIRMWARE(FW_FILE_ISP24XX); |
Andrew Vasquez | 61623fc | 2008-01-31 12:33:45 -0800 | [diff] [blame] | 4171 | MODULE_FIRMWARE(FW_FILE_ISP25XX); |