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