blob: bc35ecfbc28fbdaf5cbdd2c4bf81765ed1834c1e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
8
9#include <linux/moduleparam.h>
10#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/delay.h>
Christoph Hellwig39a11242006-02-14 18:46:22 +010012#include <linux/kthread.h>
Daniel Walkere1e82b62008-05-12 22:21:10 -070013#include <linux/mutex.h>
Andrew Vasquez3420d362009-10-13 15:16:45 -070014#include <linux/kobject.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17#include <scsi/scsi_tcq.h>
18#include <scsi/scsicam.h>
19#include <scsi/scsi_transport.h>
20#include <scsi/scsi_transport_fc.h>
21
22/*
23 * Driver version
24 */
25char qla2x00_version_str[40];
26
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -070027static int apidev_major;
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029/*
30 * SRB allocation cache
31 */
Christoph Lametere18b8902006-12-06 20:33:20 -080032static struct kmem_cache *srb_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Giridhar Malavalia9083012010-04-12 17:59:55 -070034/*
35 * CT6 CTX allocation cache
36 */
37static struct kmem_cache *ctx_cachep;
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039int ql2xlogintimeout = 20;
40module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
41MODULE_PARM_DESC(ql2xlogintimeout,
42 "Login timeout value in seconds.");
43
Andrew Vasqueza7b61842007-05-07 07:42:59 -070044int qlport_down_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
46MODULE_PARM_DESC(qlport_down_retry,
Jesper Juhl900d9f92006-06-30 02:33:07 -070047 "Maximum number of command retries to a port that returns "
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 "a PORT-DOWN status.");
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050int ql2xplogiabsentdevice;
51module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
52MODULE_PARM_DESC(ql2xplogiabsentdevice,
53 "Option to enable PLOGI to devices that are not present after "
Jesper Juhl900d9f92006-06-30 02:33:07 -070054 "a Fabric scan. This is needed for several broken switches. "
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057int ql2xloginretrycount = 0;
58module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
59MODULE_PARM_DESC(ql2xloginretrycount,
60 "Specify an alternate value for the NVRAM login retry count.");
61
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070062int ql2xallocfwdump = 1;
63module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR);
64MODULE_PARM_DESC(ql2xallocfwdump,
65 "Option to enable allocation of memory for a firmware dump "
66 "during HBA initialization. Memory allocation requirements "
67 "vary by ISP type. Default is 1 - allocate memory.");
68
Andrew Vasquez11010fe2006-10-06 09:54:59 -070069int ql2xextended_error_logging;
Andrew Vasquez27d94032007-03-12 10:41:30 -070070module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
Andrew Vasquez11010fe2006-10-06 09:54:59 -070071MODULE_PARM_DESC(ql2xextended_error_logging,
Andrew Vasquez01819442006-06-23 16:11:10 -070072 "Option to enable extended error logging, "
73 "Default is 0 - no logging. 1 - log errors.");
74
Giridhar Malavalia9083012010-04-12 17:59:55 -070075int ql2xshiftctondsd = 6;
76module_param(ql2xshiftctondsd, int, S_IRUGO|S_IRUSR);
77MODULE_PARM_DESC(ql2xshiftctondsd,
78 "Set to control shifting of command type processing "
79 "based on total number of SG elements.");
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081static void qla2x00_free_device(scsi_qla_host_t *);
82
Andrew Vasquez7e47e5c2008-04-24 15:21:26 -070083int ql2xfdmienable=1;
Andrew Vasquezcca53352005-08-26 19:08:30 -070084module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
85MODULE_PARM_DESC(ql2xfdmienable,
Ferenc Wagner7794a5a2010-03-23 18:14:59 +010086 "Enables FDMI registrations. "
87 "0 - no FDMI. Default is 1 - perform FDMI.");
Andrew Vasquezcca53352005-08-26 19:08:30 -070088
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070089#define MAX_Q_DEPTH 32
90static int ql2xmaxqdepth = MAX_Q_DEPTH;
91module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
92MODULE_PARM_DESC(ql2xmaxqdepth,
93 "Maximum queue depth to report for target devices.");
94
Arun Easibad75002010-05-04 15:01:30 -070095/* Do not change the value of this after module load */
96int ql2xenabledif = 1;
97module_param(ql2xenabledif, int, S_IRUGO|S_IWUSR);
98MODULE_PARM_DESC(ql2xenabledif,
99 " Enable T10-CRC-DIF "
100 " Default is 0 - No DIF Support. 1 - Enable it");
101
102int ql2xenablehba_err_chk;
103module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
104MODULE_PARM_DESC(ql2xenablehba_err_chk,
105 " Enable T10-CRC-DIF Error isolation by HBA"
106 " Default is 0 - Error isolation disabled, 1 - Enable it");
107
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700108int ql2xiidmaenable=1;
109module_param(ql2xiidmaenable, int, S_IRUGO|S_IRUSR);
110MODULE_PARM_DESC(ql2xiidmaenable,
111 "Enables iIDMA settings "
112 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
113
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800114int ql2xmaxqueues = 1;
115module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR);
116MODULE_PARM_DESC(ql2xmaxqueues,
117 "Enables MQ settings "
118 "Default is 1 for single queue. Set it to number \
119 of queues in MQ mode.");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700120
121int ql2xmultique_tag;
122module_param(ql2xmultique_tag, int, S_IRUGO|S_IRUSR);
123MODULE_PARM_DESC(ql2xmultique_tag,
124 "Enables CPU affinity settings for the driver "
125 "Default is 0 for no affinity of request and response IO. "
126 "Set it to 1 to turn on the cpu affinity.");
Andrew Vasqueze337d902009-04-06 22:33:49 -0700127
128int ql2xfwloadbin;
129module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR);
130MODULE_PARM_DESC(ql2xfwloadbin,
131 "Option to specify location from which to load ISP firmware:\n"
132 " 2 -- load firmware via the request_firmware() (hotplug)\n"
133 " interface.\n"
134 " 1 -- load firmware from flash.\n"
135 " 0 -- use default semantics.\n");
136
Andrew Vasquezae97c912010-02-18 10:07:28 -0800137int ql2xetsenable;
138module_param(ql2xetsenable, int, S_IRUGO|S_IRUSR);
139MODULE_PARM_DESC(ql2xetsenable,
140 "Enables firmware ETS burst."
141 "Default is 0 - skip ETS enablement.");
142
Giridhar Malavalia9083012010-04-12 17:59:55 -0700143int ql2xdbwr;
144module_param(ql2xdbwr, int, S_IRUGO|S_IRUSR);
145MODULE_PARM_DESC(ql2xdbwr,
146 "Option to specify scheme for request queue posting\n"
147 " 0 -- Regular doorbell.\n"
148 " 1 -- CAMRAM doorbell (faster).\n");
149
150int ql2xdontresethba;
151module_param(ql2xdontresethba, int, S_IRUGO|S_IRUSR);
152MODULE_PARM_DESC(ql2xdontresethba,
153 "Option to specify reset behaviour\n"
154 " 0 (Default) -- Reset on failure.\n"
155 " 1 -- Do not reset on failure.\n");
156
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700157int ql2xtargetreset = 1;
158module_param(ql2xtargetreset, int, S_IRUGO|S_IRUSR);
159MODULE_PARM_DESC(ql2xtargetreset,
160 "Enable target reset."
161 "Default is 1 - use hw defaults.");
162
Giridhar Malavalia9083012010-04-12 17:59:55 -0700163
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700164int ql2xasynctmfenable;
165module_param(ql2xasynctmfenable, int, S_IRUGO|S_IRUSR);
166MODULE_PARM_DESC(ql2xasynctmfenable,
167 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
168 "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700170 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 */
172static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500173static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800174static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
175static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500176static void qla2xxx_slave_destroy(struct scsi_device *);
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700177static int qla2xxx_queuecommand(struct scsi_cmnd *cmd,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700178 void (*fn)(struct scsi_cmnd *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179static int qla2xxx_eh_abort(struct scsi_cmnd *);
180static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700181static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
183static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Mike Christiee881a172009-10-15 17:46:39 -0700185static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700186static int qla2x00_change_queue_type(struct scsi_device *, int);
187
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700188struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700190 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700191 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700192
193 .eh_abort_handler = qla2xxx_eh_abort,
194 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700195 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700196 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
197 .eh_host_reset_handler = qla2xxx_eh_host_reset,
198
199 .slave_configure = qla2xxx_slave_configure,
200
201 .slave_alloc = qla2xxx_slave_alloc,
202 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700203 .scan_finished = qla2xxx_scan_finished,
204 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700205 .change_queue_depth = qla2x00_change_queue_depth,
206 .change_queue_type = qla2x00_change_queue_type,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700207 .this_id = -1,
208 .cmd_per_lun = 3,
209 .use_clustering = ENABLE_CLUSTERING,
210 .sg_tablesize = SG_ALL,
211
212 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700213 .shost_attrs = qla2x00_host_attrs,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700214};
215
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700217struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219/* TODO Convert to inlines
220 *
221 * Timer routines
222 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700224__inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800225qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800227 init_timer(&vha->timer);
228 vha->timer.expires = jiffies + interval * HZ;
229 vha->timer.data = (unsigned long)vha;
230 vha->timer.function = (void (*)(unsigned long))func;
231 add_timer(&vha->timer);
232 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233}
234
235static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800236qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
Giridhar Malavalia9083012010-04-12 17:59:55 -0700238 /* Currently used for 82XX only. */
239 if (vha->device_flags & DFLG_DEV_FAILED)
240 return;
241
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800242 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243}
244
Adrian Bunka824ebb2008-01-17 09:02:15 -0800245static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800246qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800248 del_timer_sync(&vha->timer);
249 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250}
251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252static int qla2x00_do_dpc(void *data);
253
254static void qla2x00_rst_aen(scsi_qla_host_t *);
255
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800256static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
257 struct req_que **, struct rsp_que **);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800258static void qla2x00_mem_free(struct qla_hw_data *);
259static void qla2x00_sp_free_dma(srb_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261/* -------------------------------------------------------------------------- */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800262static int qla2x00_alloc_queues(struct qla_hw_data *ha)
263{
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700264 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800265 GFP_KERNEL);
266 if (!ha->req_q_map) {
267 qla_printk(KERN_WARNING, ha,
268 "Unable to allocate memory for request queue ptrs\n");
269 goto fail_req_map;
270 }
271
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700272 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800273 GFP_KERNEL);
274 if (!ha->rsp_q_map) {
275 qla_printk(KERN_WARNING, ha,
276 "Unable to allocate memory for response queue ptrs\n");
277 goto fail_rsp_map;
278 }
279 set_bit(0, ha->rsp_qid_map);
280 set_bit(0, ha->req_qid_map);
281 return 1;
282
283fail_rsp_map:
284 kfree(ha->req_q_map);
285 ha->req_q_map = NULL;
286fail_req_map:
287 return -ENOMEM;
288}
289
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700290static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800291{
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800292 if (req && req->ring)
293 dma_free_coherent(&ha->pdev->dev,
294 (req->length + 1) * sizeof(request_t),
295 req->ring, req->dma);
296
297 kfree(req);
298 req = NULL;
299}
300
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700301static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
302{
303 if (rsp && rsp->ring)
304 dma_free_coherent(&ha->pdev->dev,
305 (rsp->length + 1) * sizeof(response_t),
306 rsp->ring, rsp->dma);
307
308 kfree(rsp);
309 rsp = NULL;
310}
311
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800312static void qla2x00_free_queues(struct qla_hw_data *ha)
313{
314 struct req_que *req;
315 struct rsp_que *rsp;
316 int cnt;
317
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700318 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800319 req = ha->req_q_map[cnt];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700320 qla2x00_free_req_que(ha, req);
321 }
322 kfree(ha->req_q_map);
323 ha->req_q_map = NULL;
324
325 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
326 rsp = ha->rsp_q_map[cnt];
327 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800328 }
329 kfree(ha->rsp_q_map);
330 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800331}
332
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700333static int qla25xx_setup_mode(struct scsi_qla_host *vha)
334{
335 uint16_t options = 0;
336 int ques, req, ret;
337 struct qla_hw_data *ha = vha->hw;
338
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700339 if (!(ha->fw_attributes & BIT_6)) {
340 qla_printk(KERN_INFO, ha,
341 "Firmware is not multi-queue capable\n");
342 goto fail;
343 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700344 if (ql2xmultique_tag) {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700345 /* create a request queue for IO */
346 options |= BIT_7;
347 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
348 QLA_DEFAULT_QUE_QOS);
349 if (!req) {
350 qla_printk(KERN_WARNING, ha,
351 "Can't create request queue\n");
352 goto fail;
353 }
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700354 ha->wq = create_workqueue("qla2xxx_wq");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700355 vha->req = ha->req_q_map[req];
356 options |= BIT_1;
357 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
358 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
359 if (!ret) {
360 qla_printk(KERN_WARNING, ha,
361 "Response Queue create failed\n");
362 goto fail2;
363 }
364 }
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700365 ha->flags.cpu_affinity_enabled = 1;
366
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700367 DEBUG2(qla_printk(KERN_INFO, ha,
368 "CPU affinity mode enabled, no. of response"
369 " queues:%d, no. of request queues:%d\n",
370 ha->max_rsp_queues, ha->max_req_queues));
371 }
372 return 0;
373fail2:
374 qla25xx_delete_queues(vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700375 destroy_workqueue(ha->wq);
376 ha->wq = NULL;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700377fail:
378 ha->mqenable = 0;
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700379 kfree(ha->req_q_map);
380 kfree(ha->rsp_q_map);
381 ha->max_req_queues = ha->max_rsp_queues = 1;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700382 return 1;
383}
384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800386qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800388 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 static char *pci_bus_modes[] = {
390 "33", "66", "100", "133",
391 };
392 uint16_t pci_bus;
393
394 strcpy(str, "PCI");
395 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
396 if (pci_bus) {
397 strcat(str, "-X (");
398 strcat(str, pci_bus_modes[pci_bus]);
399 } else {
400 pci_bus = (ha->pci_attr & BIT_8) >> 8;
401 strcat(str, " (");
402 strcat(str, pci_bus_modes[pci_bus]);
403 }
404 strcat(str, " MHz)");
405
406 return (str);
407}
408
Andrew Vasquezfca29702005-07-06 10:31:47 -0700409static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800410qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700411{
412 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800413 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700414 uint32_t pci_bus;
415 int pcie_reg;
416
417 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
418 if (pcie_reg) {
419 char lwstr[6];
420 uint16_t pcie_lstat, lspeed, lwidth;
421
422 pcie_reg += 0x12;
423 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
424 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
425 lwidth = (pcie_lstat &
426 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
427
428 strcpy(str, "PCIe (");
429 if (lspeed == 1)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700430 strcat(str, "2.5GT/s ");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700431 else if (lspeed == 2)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700432 strcat(str, "5.0GT/s ");
Andrew Vasquezfca29702005-07-06 10:31:47 -0700433 else
434 strcat(str, "<unknown> ");
435 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
436 strcat(str, lwstr);
437
438 return str;
439 }
440
441 strcpy(str, "PCI");
442 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
443 if (pci_bus == 0 || pci_bus == 8) {
444 strcat(str, " (");
445 strcat(str, pci_bus_modes[pci_bus >> 3]);
446 } else {
447 strcat(str, "-X ");
448 if (pci_bus & BIT_2)
449 strcat(str, "Mode 2");
450 else
451 strcat(str, "Mode 1");
452 strcat(str, " (");
453 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
454 }
455 strcat(str, " MHz)");
456
457 return str;
458}
459
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800460static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800461qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462{
463 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800464 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
467 ha->fw_minor_version,
468 ha->fw_subminor_version);
469
470 if (ha->fw_attributes & BIT_9) {
471 strcat(str, "FLX");
472 return (str);
473 }
474
475 switch (ha->fw_attributes & 0xFF) {
476 case 0x7:
477 strcat(str, "EF");
478 break;
479 case 0x17:
480 strcat(str, "TP");
481 break;
482 case 0x37:
483 strcat(str, "IP");
484 break;
485 case 0x77:
486 strcat(str, "VI");
487 break;
488 default:
489 sprintf(un_str, "(%x)", ha->fw_attributes);
490 strcat(str, un_str);
491 break;
492 }
493 if (ha->fw_attributes & 0x100)
494 strcat(str, "X");
495
496 return (str);
497}
498
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800499static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800500qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700501{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800502 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700503
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800504 sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
505 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700506 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700507}
508
509static inline srb_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800510qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700511 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
512{
513 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800514 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700515
516 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
517 if (!sp)
518 return sp;
519
Giridhar Malavali083a4692010-05-28 15:08:18 -0700520 atomic_set(&sp->ref_count, 1);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700521 sp->fcport = fcport;
522 sp->cmd = cmd;
523 sp->flags = 0;
524 CMD_SP(cmd) = (void *)sp;
525 cmd->scsi_done = done;
Andrew Vasquezcf53b062009-08-20 11:06:04 -0700526 sp->ctx = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700527
528 return sp;
529}
530
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531static int
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700532qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
Andrew Vasquezfca29702005-07-06 10:31:47 -0700533{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800534 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700535 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400536 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800537 struct qla_hw_data *ha = vha->hw;
538 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700539 srb_t *sp;
540 int rval;
541
Andrew Vasquez85880802009-12-15 21:29:46 -0800542 if (ha->flags.eeh_busy) {
543 if (ha->flags.pci_channel_io_perm_failure)
Seokmann Jub9b12f72009-03-24 09:08:18 -0700544 cmd->result = DID_NO_CONNECT << 16;
Andrew Vasquez85880802009-12-15 21:29:46 -0800545 else
546 cmd->result = DID_REQUEUE << 16;
Seokmann Ju14e660e2007-09-20 14:07:36 -0700547 goto qc24_fail_command;
548 }
549
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400550 rval = fc_remote_port_chkready(rport);
551 if (rval) {
552 cmd->result = rval;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700553 goto qc24_fail_command;
554 }
555
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800556 /* Close window on fcport/rport state-transitioning. */
Mike Christie7b594132008-08-17 15:24:40 -0500557 if (fcport->drport)
558 goto qc24_target_busy;
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800559
Arun Easibad75002010-05-04 15:01:30 -0700560 if (!vha->flags.difdix_supported &&
561 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
562 DEBUG2(qla_printk(KERN_ERR, ha,
563 "DIF Cap Not Reg, fail DIF capable cmd's:%x\n",
564 cmd->cmnd[0]));
565 cmd->result = DID_NO_CONNECT << 16;
566 goto qc24_fail_command;
567 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700568 if (atomic_read(&fcport->state) != FCS_ONLINE) {
569 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800570 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700571 cmd->result = DID_NO_CONNECT << 16;
572 goto qc24_fail_command;
573 }
Mike Christie7b594132008-08-17 15:24:40 -0500574 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700575 }
576
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800577 spin_unlock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700578
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800579 sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700580 if (!sp)
581 goto qc24_host_busy_lock;
582
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800583 rval = ha->isp_ops->start_scsi(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700584 if (rval != QLA_SUCCESS)
585 goto qc24_host_busy_free_sp;
586
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800587 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700588
589 return 0;
590
591qc24_host_busy_free_sp:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800592 qla2x00_sp_free_dma(sp);
593 mempool_free(sp, ha->srb_mempool);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700594
595qc24_host_busy_lock:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800596 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700597 return SCSI_MLQUEUE_HOST_BUSY;
598
Mike Christie7b594132008-08-17 15:24:40 -0500599qc24_target_busy:
600 return SCSI_MLQUEUE_TARGET_BUSY;
601
Andrew Vasquezfca29702005-07-06 10:31:47 -0700602qc24_fail_command:
603 done(cmd);
604
605 return 0;
606}
607
608
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609/*
610 * qla2x00_eh_wait_on_command
611 * Waits for the command to be returned by the Firmware for some
612 * max time.
613 *
614 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 *
617 * Return:
618 * Not Found : 0
619 * Found : 1
620 */
621static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800622qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700624#define ABORT_POLLING_PERIOD 1000
625#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500626 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -0800627 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
628 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -0500629 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
Andrew Vasquez85880802009-12-15 21:29:46 -0800631 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
632 DEBUG17(qla_printk(KERN_WARNING, ha, "return:eh_wait\n"));
633 return ret;
634 }
635
Lalit Chandivaded9704322009-08-25 11:36:18 -0700636 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700637 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -0500638 }
639 if (CMD_SP(cmd))
640 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
f4f051e2005-04-17 15:02:26 -0500642 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643}
644
645/*
646 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700647 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 * <= MAX_RETRIES_OF_ISP_ABORT or
649 * finally HBA is disabled ie marked offline
650 *
651 * Input:
652 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700653 *
654 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 * Does context switching-Release SPIN_LOCK
656 * (if any) before calling this routine.
657 *
658 * Return:
659 * Success (Adapter is online) : 0
660 * Failed (Adapter is offline/disabled) : 1
661 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800662int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800663qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700665 int return_status;
666 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800667 struct qla_hw_data *ha = vha->hw;
668 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700670 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800671 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
672 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
673 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
674 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
676 msleep(1000);
677 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800678 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700679 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 else
681 return_status = QLA_FUNCTION_FAILED;
682
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 return (return_status);
684}
685
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700686/*
687 * qla2x00_wait_for_reset_ready
688 * Wait till the HBA is online after going through
689 * <= MAX_RETRIES_OF_ISP_ABORT or
690 * finally HBA is disabled ie marked offline or flash
691 * operations are in progress.
692 *
693 * Input:
694 * ha - pointer to host adapter structure
695 *
696 * Note:
697 * Does context switching-Release SPIN_LOCK
698 * (if any) before calling this routine.
699 *
700 * Return:
701 * Success (Adapter is online/no flash ops) : 0
702 * Failed (Adapter is offline/disabled/flash ops in progress) : 1
703 */
704int
705qla2x00_wait_for_reset_ready(scsi_qla_host_t *vha)
706{
707 int return_status;
708 unsigned long wait_online;
709 struct qla_hw_data *ha = vha->hw;
710 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
711
712 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
713 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
714 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
715 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
716 ha->optrom_state != QLA_SWAITING ||
717 ha->dpc_active) && time_before(jiffies, wait_online))
718 msleep(1000);
719
720 if (base_vha->flags.online && ha->optrom_state == QLA_SWAITING)
721 return_status = QLA_SUCCESS;
722 else
723 return_status = QLA_FUNCTION_FAILED;
724
725 DEBUG2(printk("%s return_status=%d\n", __func__, return_status));
726
727 return return_status;
728}
729
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700730int
731qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
732{
733 int return_status;
734 unsigned long wait_reset;
735 struct qla_hw_data *ha = vha->hw;
736 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
737
738 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
739 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
740 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
741 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
742 ha->dpc_active) && time_before(jiffies, wait_reset)) {
743
744 msleep(1000);
745
746 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
747 ha->flags.chip_reset_done)
748 break;
749 }
750 if (ha->flags.chip_reset_done)
751 return_status = QLA_SUCCESS;
752 else
753 return_status = QLA_FUNCTION_FAILED;
754
755 return return_status;
756}
757
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758/*
759 * qla2x00_wait_for_loop_ready
760 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700761 * to be in LOOP_READY state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 * Input:
763 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700764 *
765 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 * Does context switching-Release SPIN_LOCK
767 * (if any) before calling this routine.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700768 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 *
770 * Return:
771 * Success (LOOP_READY) : 0
772 * Failed (LOOP_NOT_READY) : 1
773 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700774static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800775qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776{
777 int return_status = QLA_SUCCESS;
778 unsigned long loop_timeout ;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800779 struct qla_hw_data *ha = vha->hw;
780 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
782 /* wait for 5 min at the max for loop to be ready */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700783 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800785 while ((!atomic_read(&base_vha->loop_down_timer) &&
786 atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
787 atomic_read(&base_vha->loop_state) != LOOP_READY) {
788 if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Ravi Anand57680082006-05-17 15:08:44 -0700789 return_status = QLA_FUNCTION_FAILED;
790 break;
791 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 msleep(1000);
793 if (time_after_eq(jiffies, loop_timeout)) {
794 return_status = QLA_FUNCTION_FAILED;
795 break;
796 }
797 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700798 return (return_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799}
800
Giridhar Malavali083a4692010-05-28 15:08:18 -0700801static void
802sp_get(struct srb *sp)
803{
804 atomic_inc(&sp->ref_count);
805}
806
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807/**************************************************************************
808* qla2xxx_eh_abort
809*
810* Description:
811* The abort function will abort the specified command.
812*
813* Input:
814* cmd = Linux SCSI command packet to be aborted.
815*
816* Returns:
817* Either SUCCESS or FAILED.
818*
819* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700820* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800822static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823qla2xxx_eh_abort(struct scsi_cmnd *cmd)
824{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800825 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500826 srb_t *sp;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800827 int ret, i;
f4f051e2005-04-17 15:02:26 -0500828 unsigned int id, lun;
829 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700830 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700831 int wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800832 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700833 struct req_que *req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800834 srb_t *spt;
Giridhar Malavali083a4692010-05-28 15:08:18 -0700835 int got_ref = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
Christof Schmitt65d430f2009-10-30 17:59:29 +0100837 fc_block_scsi_eh(cmd);
Andrew Vasquez07db5182006-10-02 12:00:49 -0700838
f4f051e2005-04-17 15:02:26 -0500839 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700840 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
Michael Reed2ea00202006-04-27 16:25:30 -0700842 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843
f4f051e2005-04-17 15:02:26 -0500844 id = cmd->device->id;
845 lun = cmd->device->lun;
846 serial = cmd->serial_number;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800847 spt = (srb_t *) CMD_SP(cmd);
848 if (!spt)
849 return SUCCESS;
f4f051e2005-04-17 15:02:26 -0500850
851 /* Check active list for command command. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800852 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800853 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
854 sp = req->outstanding_cmds[i];
855
856 if (sp == NULL)
f4f051e2005-04-17 15:02:26 -0500857 continue;
Arun Easibad75002010-05-04 15:01:30 -0700858 if ((sp->ctx) && !(sp->flags & SRB_FCP_CMND_DMA_VALID) &&
859 !IS_PROT_IO(sp))
Andrew Vasquezcf53b062009-08-20 11:06:04 -0700860 continue;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800861 if (sp->cmd != cmd)
862 continue;
f4f051e2005-04-17 15:02:26 -0500863
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800864 DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
865 " pid=%ld.\n", __func__, vha->host_no, sp, serial));
f4f051e2005-04-17 15:02:26 -0500866
Giridhar Malavali083a4692010-05-28 15:08:18 -0700867 /* Get a reference to the sp and drop the lock.*/
868 sp_get(sp);
869 got_ref++;
870
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800871 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700872 if (ha->isp_ops->abort_command(sp)) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800873 DEBUG2(printk("%s(%ld): abort_command "
874 "mbx failed.\n", __func__, vha->host_no));
Andrew Vasquez2ac4b642009-01-22 09:45:35 -0800875 ret = FAILED;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800876 } else {
877 DEBUG3(printk("%s(%ld): abort_command "
878 "mbx success.\n", __func__, vha->host_no));
879 wait = 1;
f4f051e2005-04-17 15:02:26 -0500880 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800881 spin_lock_irqsave(&ha->hardware_lock, flags);
882 break;
f4f051e2005-04-17 15:02:26 -0500883 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800884 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500885
886 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700887 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800888 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700889 qla_printk(KERN_ERR, ha,
f4f051e2005-04-17 15:02:26 -0500890 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800891 "%x.\n", vha->host_no, id, lun, serial, ret);
Michael Reed2ea00202006-04-27 16:25:30 -0700892 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500893 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
Giridhar Malavali083a4692010-05-28 15:08:18 -0700896 if (got_ref)
897 qla2x00_sp_compl(ha, sp);
898
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700899 qla_printk(KERN_INFO, ha,
Michael Reed2ea00202006-04-27 16:25:30 -0700900 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800901 vha->host_no, id, lun, wait, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
f4f051e2005-04-17 15:02:26 -0500903 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904}
905
Andrew Vasquez523ec772008-04-03 13:13:24 -0700906enum nexus_wait_type {
907 WAIT_HOST = 0,
908 WAIT_TARGET,
909 WAIT_LUN,
910};
911
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800913qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800914 unsigned int l, srb_t *sp, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915{
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800916 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700917 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800918 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800919 struct req_que *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
Andrew Vasquez523ec772008-04-03 13:13:24 -0700921 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800922 if (!sp)
923 return status;
924
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800925 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700926 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800927 for (cnt = 1; status == QLA_SUCCESS &&
928 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
929 sp = req->outstanding_cmds[cnt];
930 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700931 continue;
Arun Easibad75002010-05-04 15:01:30 -0700932 if ((sp->ctx) && !IS_PROT_IO(sp))
Andrew Vasquezcf53b062009-08-20 11:06:04 -0700933 continue;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800934 if (vha->vp_idx != sp->fcport->vha->vp_idx)
935 continue;
936 match = 0;
937 switch (type) {
938 case WAIT_HOST:
939 match = 1;
940 break;
941 case WAIT_TARGET:
942 match = sp->cmd->device->id == t;
943 break;
944 case WAIT_LUN:
945 match = (sp->cmd->device->id == t &&
946 sp->cmd->device->lun == l);
947 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800949 if (!match)
950 continue;
951
952 spin_unlock_irqrestore(&ha->hardware_lock, flags);
953 status = qla2x00_eh_wait_on_command(sp->cmd);
954 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800956 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700957
958 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959}
960
Giridhar Malavalia9083012010-04-12 17:59:55 -0700961void qla82xx_wait_for_pending_commands(scsi_qla_host_t *vha)
962{
963 int cnt;
964 srb_t *sp;
965 struct req_que *req = vha->req;
966
967 DEBUG2(qla_printk(KERN_INFO, vha->hw,
968 "Waiting for pending commands\n"));
969 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
970 sp = req->outstanding_cmds[cnt];
971 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0,
972 sp, WAIT_HOST) == QLA_SUCCESS) {
973 DEBUG2(qla_printk(KERN_INFO, vha->hw,
974 "Done wait for pending commands\n"));
975 }
976 }
977}
978
Andrew Vasquez523ec772008-04-03 13:13:24 -0700979static char *reset_errors[] = {
980 "HBA not online",
981 "HBA not ready",
982 "Task management failed",
983 "Waiting for command completions",
984};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
Andrew Vasquez523ec772008-04-03 13:13:24 -0700986static int
987__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700988 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -0700989{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800990 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700991 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
992 int err;
993
Christof Schmitt65d430f2009-10-30 17:59:29 +0100994 fc_block_scsi_eh(cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700995
996 if (!fcport)
997 return FAILED;
998
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800999 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
1000 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001001
1002 err = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001003 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001004 goto eh_reset_failed;
1005 err = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001006 if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001007 goto eh_reset_failed;
1008 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001009 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
1010 != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001011 goto eh_reset_failed;
1012 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001013 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001014 cmd->device->lun, (srb_t *) CMD_SP(cmd), type) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001015 goto eh_reset_failed;
1016
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001017 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
1018 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001019
1020 return SUCCESS;
1021
1022 eh_reset_failed:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001023 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
1024 , vha->host_no, cmd->device->id, cmd->device->lun, name,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001025 reset_errors[err]);
1026 return FAILED;
1027}
1028
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001029static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1031{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001032 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1033 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034
Andrew Vasquez523ec772008-04-03 13:13:24 -07001035 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1036 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037}
1038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001040qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001042 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1043 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
Andrew Vasquez523ec772008-04-03 13:13:24 -07001045 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1046 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047}
1048
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049/**************************************************************************
1050* qla2xxx_eh_bus_reset
1051*
1052* Description:
1053* The bus reset function will reset the bus and abort any executing
1054* commands.
1055*
1056* Input:
1057* cmd = Linux SCSI command packet of the command that cause the
1058* bus reset.
1059*
1060* Returns:
1061* SUCCESS/FAILURE (defined as macro in scsi.h).
1062*
1063**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001064static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1066{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001067 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001068 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001069 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001070 unsigned int id, lun;
1071 unsigned long serial;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001072 srb_t *sp = (srb_t *) CMD_SP(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
Christof Schmitt65d430f2009-10-30 17:59:29 +01001074 fc_block_scsi_eh(cmd);
Andrew Vasquez07db5182006-10-02 12:00:49 -07001075
f4f051e2005-04-17 15:02:26 -05001076 id = cmd->device->id;
1077 lun = cmd->device->lun;
1078 serial = cmd->serial_number;
1079
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -07001080 if (!fcport)
f4f051e2005-04-17 15:02:26 -05001081 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001083 qla_printk(KERN_INFO, vha->hw,
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001084 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001086 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -05001088 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 }
1090
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001091 if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
1092 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001093 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 }
f4f051e2005-04-17 15:02:26 -05001095 if (ret == FAILED)
1096 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001098 /* Flush outstanding commands. */
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001099 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) !=
Andrew Vasquez523ec772008-04-03 13:13:24 -07001100 QLA_SUCCESS)
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001101 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
f4f051e2005-04-17 15:02:26 -05001103eh_bus_reset_done:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001104 qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -05001105 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
f4f051e2005-04-17 15:02:26 -05001107 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108}
1109
1110/**************************************************************************
1111* qla2xxx_eh_host_reset
1112*
1113* Description:
1114* The reset function will reset the Adapter.
1115*
1116* Input:
1117* cmd = Linux SCSI command packet of the command that cause the
1118* adapter reset.
1119*
1120* Returns:
1121* Either SUCCESS or FAILED.
1122*
1123* Note:
1124**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001125static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1127{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001128 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001129 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001130 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001131 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001132 unsigned int id, lun;
1133 unsigned long serial;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001134 srb_t *sp = (srb_t *) CMD_SP(cmd);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001135 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
Christof Schmitt65d430f2009-10-30 17:59:29 +01001137 fc_block_scsi_eh(cmd);
Andrew Vasquez07db5182006-10-02 12:00:49 -07001138
f4f051e2005-04-17 15:02:26 -05001139 id = cmd->device->id;
1140 lun = cmd->device->lun;
1141 serial = cmd->serial_number;
1142
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -07001143 if (!fcport)
f4f051e2005-04-17 15:02:26 -05001144 return ret;
1145
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 qla_printk(KERN_INFO, ha,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001147 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001149 if (qla2x00_wait_for_reset_ready(vha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001150 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
1152 /*
1153 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001154 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 * be completed and then issue big hammer.Otherwise
1156 * it may cause I/O failure as big hammer marks the
1157 * devices as lost kicking of the port_down_timer
1158 * while dpc is stuck for the mailbox to complete.
1159 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001160 qla2x00_wait_for_loop_ready(vha);
1161 if (vha != base_vha) {
1162 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001163 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001164 } else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001165 if (IS_QLA82XX(vha->hw)) {
1166 if (!qla82xx_fcoe_ctx_reset(vha)) {
1167 /* Ctx reset success */
1168 ret = SUCCESS;
1169 goto eh_host_reset_lock;
1170 }
1171 /* fall thru if ctx reset failed */
1172 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001173 if (ha->wq)
1174 flush_workqueue(ha->wq);
1175
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001176 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001177 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001178 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1179 /* failed. schedule dpc to try */
1180 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1181
1182 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1183 goto eh_host_reset_lock;
1184 }
1185 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001186 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001188 /* Waiting for command to be returned to OS.*/
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001189 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001190 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001191 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
f4f051e2005-04-17 15:02:26 -05001193eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -05001194 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1195 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
f4f051e2005-04-17 15:02:26 -05001197 return ret;
1198}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
1200/*
1201* qla2x00_loop_reset
1202* Issue loop reset.
1203*
1204* Input:
1205* ha = adapter block pointer.
1206*
1207* Returns:
1208* 0 = success
1209*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001210int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001211qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001213 int ret;
bdf79622005-04-17 15:06:53 -05001214 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001215 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001217 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001218 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1219 if (fcport->port_type != FCT_TARGET)
1220 continue;
1221
1222 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1223 if (ret != QLA_SUCCESS) {
1224 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1225 "target_reset=%d d_id=%x.\n", __func__,
1226 vha->host_no, ret, fcport->d_id.b24));
1227 }
1228 }
1229 }
1230
Giridhar Malavalia9083012010-04-12 17:59:55 -07001231 if (ha->flags.enable_lip_full_login && !IS_QLA8XXX_TYPE(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001232 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001233 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001234 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001235 "full_login_lip=%d.\n", __func__, vha->host_no,
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001236 ret));
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001237 }
1238 atomic_set(&vha->loop_state, LOOP_DOWN);
1239 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1240 qla2x00_mark_all_devices_lost(vha, 0);
1241 qla2x00_wait_for_loop_ready(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 }
1243
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001244 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001245 ret = qla2x00_lip_reset(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001246 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001247 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001248 "lip_reset=%d.\n", __func__, vha->host_no, ret));
1249 } else
1250 qla2x00_wait_for_loop_ready(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001251 }
1252
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001254 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001256 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257}
1258
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001259void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001260qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001261{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001262 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001263 unsigned long flags;
1264 srb_t *sp;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001265 struct srb_ctx *ctx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001266 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001267 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001268
1269 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001270 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001271 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001272 if (!req)
1273 continue;
1274 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1275 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001276 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001277 req->outstanding_cmds[cnt] = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001278 if (!sp->ctx ||
Arun Easibad75002010-05-04 15:01:30 -07001279 (sp->flags & SRB_FCP_CMND_DMA_VALID) ||
1280 IS_PROT_IO(sp)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07001281 sp->cmd->result = res;
1282 qla2x00_sp_compl(ha, sp);
1283 } else {
1284 ctx = sp->ctx;
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001285 if (ctx->type == SRB_LOGIN_CMD ||
1286 ctx->type == SRB_LOGOUT_CMD) {
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001287 ctx->u.iocb_cmd->free(sp);
Giridhar Malavalidb3ad7f2010-02-18 10:07:24 -08001288 } else {
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001289 struct fc_bsg_job *bsg_job =
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001290 ctx->u.bsg_job;
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001291 if (bsg_job->request->msgcode
1292 == FC_BSG_HST_CT)
Giridhar Malavalidb3ad7f2010-02-18 10:07:24 -08001293 kfree(sp->fcport);
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001294 bsg_job->req->errors = 0;
1295 bsg_job->reply->result = res;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001296 bsg_job->job_done(bsg_job);
Giridhar Malavalidb3ad7f2010-02-18 10:07:24 -08001297 kfree(sp->ctx);
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001298 mempool_free(sp,
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001299 ha->srb_mempool);
Giridhar Malavalidb3ad7f2010-02-18 10:07:24 -08001300 }
Andrew Vasquezac280b62009-08-20 11:06:05 -07001301 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001302 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001303 }
1304 }
1305 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1306}
1307
f4f051e2005-04-17 15:02:26 -05001308static int
1309qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310{
bdf79622005-04-17 15:06:53 -05001311 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001313 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001314 return -ENXIO;
1315
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001316 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001317
1318 return 0;
1319}
1320
1321static int
1322qla2xxx_slave_configure(struct scsi_device *sdev)
1323{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001324 scsi_qla_host_t *vha = shost_priv(sdev->host);
1325 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05001326 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001327 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001328
f4f051e2005-04-17 15:02:26 -05001329 if (sdev->tagged_supported)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001330 scsi_activate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001332 scsi_deactivate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
Andrew Vasquez85821c92008-07-10 16:55:48 -07001334 rport->dev_loss_tmo = ha->port_down_retry_count;
8482e1182005-04-17 15:04:54 -05001335
f4f051e2005-04-17 15:02:26 -05001336 return 0;
1337}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
f4f051e2005-04-17 15:02:26 -05001339static void
1340qla2xxx_slave_destroy(struct scsi_device *sdev)
1341{
1342 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343}
1344
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001345static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
1346{
1347 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1348
1349 if (!scsi_track_queue_full(sdev, qdepth))
1350 return;
1351
1352 DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw,
1353 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
1354 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
1355 sdev->queue_depth));
1356}
1357
1358static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
1359{
1360 fc_port_t *fcport = sdev->hostdata;
1361 struct scsi_qla_host *vha = fcport->vha;
1362 struct qla_hw_data *ha = vha->hw;
1363 struct req_que *req = NULL;
1364
1365 req = vha->req;
1366 if (!req)
1367 return;
1368
1369 if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
1370 return;
1371
1372 if (sdev->ordered_tags)
1373 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
1374 else
1375 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
1376
1377 DEBUG2(qla_printk(KERN_INFO, ha,
1378 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
1379 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
1380 sdev->queue_depth));
1381}
1382
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001383static int
Mike Christiee881a172009-10-15 17:46:39 -07001384qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001385{
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001386 switch (reason) {
1387 case SCSI_QDEPTH_DEFAULT:
1388 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1389 break;
1390 case SCSI_QDEPTH_QFULL:
1391 qla2x00_handle_queue_full(sdev, qdepth);
1392 break;
1393 case SCSI_QDEPTH_RAMP_UP:
1394 qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
1395 break;
1396 default:
Roel Kluin08002af2010-01-29 11:25:19 +01001397 return -EOPNOTSUPP;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001398 }
Mike Christiee881a172009-10-15 17:46:39 -07001399
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001400 return sdev->queue_depth;
1401}
1402
1403static int
1404qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1405{
1406 if (sdev->tagged_supported) {
1407 scsi_set_tag_type(sdev, tag_type);
1408 if (tag_type)
1409 scsi_activate_tcq(sdev, sdev->queue_depth);
1410 else
1411 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1412 } else
1413 tag_type = 0;
1414
1415 return tag_type;
1416}
1417
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418/**
1419 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1420 * @ha: HA context
1421 *
1422 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1423 * supported addressing method.
1424 */
1425static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001426qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001428 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
Yang Hongyang6a355282009-04-06 19:01:13 -07001431 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001432 /* Any upper-dword bits set? */
1433 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001434 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001435 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001437 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1438 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001439 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001442
Yang Hongyang284901a2009-04-06 19:01:15 -07001443 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1444 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445}
1446
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001447static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001448qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001449{
1450 unsigned long flags = 0;
1451 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1452
1453 spin_lock_irqsave(&ha->hardware_lock, flags);
1454 ha->interrupts_on = 1;
1455 /* enable risc and host interrupts */
1456 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1457 RD_REG_WORD(&reg->ictrl);
1458 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1459
1460}
1461
1462static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001463qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001464{
1465 unsigned long flags = 0;
1466 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1467
1468 spin_lock_irqsave(&ha->hardware_lock, flags);
1469 ha->interrupts_on = 0;
1470 /* disable risc and host interrupts */
1471 WRT_REG_WORD(&reg->ictrl, 0);
1472 RD_REG_WORD(&reg->ictrl);
1473 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1474}
1475
1476static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001477qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001478{
1479 unsigned long flags = 0;
1480 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1481
1482 spin_lock_irqsave(&ha->hardware_lock, flags);
1483 ha->interrupts_on = 1;
1484 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1485 RD_REG_DWORD(&reg->ictrl);
1486 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1487}
1488
1489static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001490qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001491{
1492 unsigned long flags = 0;
1493 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1494
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001495 if (IS_NOPOLLING_TYPE(ha))
1496 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001497 spin_lock_irqsave(&ha->hardware_lock, flags);
1498 ha->interrupts_on = 0;
1499 WRT_REG_DWORD(&reg->ictrl, 0);
1500 RD_REG_DWORD(&reg->ictrl);
1501 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1502}
1503
1504static struct isp_operations qla2100_isp_ops = {
1505 .pci_config = qla2100_pci_config,
1506 .reset_chip = qla2x00_reset_chip,
1507 .chip_diag = qla2x00_chip_diag,
1508 .config_rings = qla2x00_config_rings,
1509 .reset_adapter = qla2x00_reset_adapter,
1510 .nvram_config = qla2x00_nvram_config,
1511 .update_fw_options = qla2x00_update_fw_options,
1512 .load_risc = qla2x00_load_risc,
1513 .pci_info_str = qla2x00_pci_info_str,
1514 .fw_version_str = qla2x00_fw_version_str,
1515 .intr_handler = qla2100_intr_handler,
1516 .enable_intrs = qla2x00_enable_intrs,
1517 .disable_intrs = qla2x00_disable_intrs,
1518 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001519 .target_reset = qla2x00_abort_target,
1520 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001521 .fabric_login = qla2x00_login_fabric,
1522 .fabric_logout = qla2x00_fabric_logout,
1523 .calc_req_entries = qla2x00_calc_iocbs_32,
1524 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1525 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1526 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1527 .read_nvram = qla2x00_read_nvram_data,
1528 .write_nvram = qla2x00_write_nvram_data,
1529 .fw_dump = qla2100_fw_dump,
1530 .beacon_on = NULL,
1531 .beacon_off = NULL,
1532 .beacon_blink = NULL,
1533 .read_optrom = qla2x00_read_optrom_data,
1534 .write_optrom = qla2x00_write_optrom_data,
1535 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001536 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001537 .abort_isp = qla2x00_abort_isp,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001538};
1539
1540static struct isp_operations qla2300_isp_ops = {
1541 .pci_config = qla2300_pci_config,
1542 .reset_chip = qla2x00_reset_chip,
1543 .chip_diag = qla2x00_chip_diag,
1544 .config_rings = qla2x00_config_rings,
1545 .reset_adapter = qla2x00_reset_adapter,
1546 .nvram_config = qla2x00_nvram_config,
1547 .update_fw_options = qla2x00_update_fw_options,
1548 .load_risc = qla2x00_load_risc,
1549 .pci_info_str = qla2x00_pci_info_str,
1550 .fw_version_str = qla2x00_fw_version_str,
1551 .intr_handler = qla2300_intr_handler,
1552 .enable_intrs = qla2x00_enable_intrs,
1553 .disable_intrs = qla2x00_disable_intrs,
1554 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001555 .target_reset = qla2x00_abort_target,
1556 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001557 .fabric_login = qla2x00_login_fabric,
1558 .fabric_logout = qla2x00_fabric_logout,
1559 .calc_req_entries = qla2x00_calc_iocbs_32,
1560 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1561 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1562 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1563 .read_nvram = qla2x00_read_nvram_data,
1564 .write_nvram = qla2x00_write_nvram_data,
1565 .fw_dump = qla2300_fw_dump,
1566 .beacon_on = qla2x00_beacon_on,
1567 .beacon_off = qla2x00_beacon_off,
1568 .beacon_blink = qla2x00_beacon_blink,
1569 .read_optrom = qla2x00_read_optrom_data,
1570 .write_optrom = qla2x00_write_optrom_data,
1571 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001572 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001573 .abort_isp = qla2x00_abort_isp,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001574};
1575
1576static struct isp_operations qla24xx_isp_ops = {
1577 .pci_config = qla24xx_pci_config,
1578 .reset_chip = qla24xx_reset_chip,
1579 .chip_diag = qla24xx_chip_diag,
1580 .config_rings = qla24xx_config_rings,
1581 .reset_adapter = qla24xx_reset_adapter,
1582 .nvram_config = qla24xx_nvram_config,
1583 .update_fw_options = qla24xx_update_fw_options,
1584 .load_risc = qla24xx_load_risc,
1585 .pci_info_str = qla24xx_pci_info_str,
1586 .fw_version_str = qla24xx_fw_version_str,
1587 .intr_handler = qla24xx_intr_handler,
1588 .enable_intrs = qla24xx_enable_intrs,
1589 .disable_intrs = qla24xx_disable_intrs,
1590 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001591 .target_reset = qla24xx_abort_target,
1592 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001593 .fabric_login = qla24xx_login_fabric,
1594 .fabric_logout = qla24xx_fabric_logout,
1595 .calc_req_entries = NULL,
1596 .build_iocbs = NULL,
1597 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1598 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1599 .read_nvram = qla24xx_read_nvram_data,
1600 .write_nvram = qla24xx_write_nvram_data,
1601 .fw_dump = qla24xx_fw_dump,
1602 .beacon_on = qla24xx_beacon_on,
1603 .beacon_off = qla24xx_beacon_off,
1604 .beacon_blink = qla24xx_beacon_blink,
1605 .read_optrom = qla24xx_read_optrom_data,
1606 .write_optrom = qla24xx_write_optrom_data,
1607 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001608 .start_scsi = qla24xx_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001609 .abort_isp = qla2x00_abort_isp,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001610};
1611
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001612static struct isp_operations qla25xx_isp_ops = {
1613 .pci_config = qla25xx_pci_config,
1614 .reset_chip = qla24xx_reset_chip,
1615 .chip_diag = qla24xx_chip_diag,
1616 .config_rings = qla24xx_config_rings,
1617 .reset_adapter = qla24xx_reset_adapter,
1618 .nvram_config = qla24xx_nvram_config,
1619 .update_fw_options = qla24xx_update_fw_options,
1620 .load_risc = qla24xx_load_risc,
1621 .pci_info_str = qla24xx_pci_info_str,
1622 .fw_version_str = qla24xx_fw_version_str,
1623 .intr_handler = qla24xx_intr_handler,
1624 .enable_intrs = qla24xx_enable_intrs,
1625 .disable_intrs = qla24xx_disable_intrs,
1626 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001627 .target_reset = qla24xx_abort_target,
1628 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001629 .fabric_login = qla24xx_login_fabric,
1630 .fabric_logout = qla24xx_fabric_logout,
1631 .calc_req_entries = NULL,
1632 .build_iocbs = NULL,
1633 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1634 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1635 .read_nvram = qla25xx_read_nvram_data,
1636 .write_nvram = qla25xx_write_nvram_data,
1637 .fw_dump = qla25xx_fw_dump,
1638 .beacon_on = qla24xx_beacon_on,
1639 .beacon_off = qla24xx_beacon_off,
1640 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001641 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001642 .write_optrom = qla24xx_write_optrom_data,
1643 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07001644 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001645 .abort_isp = qla2x00_abort_isp,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001646};
1647
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001648static struct isp_operations qla81xx_isp_ops = {
1649 .pci_config = qla25xx_pci_config,
1650 .reset_chip = qla24xx_reset_chip,
1651 .chip_diag = qla24xx_chip_diag,
1652 .config_rings = qla24xx_config_rings,
1653 .reset_adapter = qla24xx_reset_adapter,
1654 .nvram_config = qla81xx_nvram_config,
1655 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001656 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001657 .pci_info_str = qla24xx_pci_info_str,
1658 .fw_version_str = qla24xx_fw_version_str,
1659 .intr_handler = qla24xx_intr_handler,
1660 .enable_intrs = qla24xx_enable_intrs,
1661 .disable_intrs = qla24xx_disable_intrs,
1662 .abort_command = qla24xx_abort_command,
1663 .target_reset = qla24xx_abort_target,
1664 .lun_reset = qla24xx_lun_reset,
1665 .fabric_login = qla24xx_login_fabric,
1666 .fabric_logout = qla24xx_fabric_logout,
1667 .calc_req_entries = NULL,
1668 .build_iocbs = NULL,
1669 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1670 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07001671 .read_nvram = NULL,
1672 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001673 .fw_dump = qla81xx_fw_dump,
1674 .beacon_on = qla24xx_beacon_on,
1675 .beacon_off = qla24xx_beacon_off,
1676 .beacon_blink = qla24xx_beacon_blink,
1677 .read_optrom = qla25xx_read_optrom_data,
1678 .write_optrom = qla24xx_write_optrom_data,
1679 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07001680 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001681 .abort_isp = qla2x00_abort_isp,
1682};
1683
1684static struct isp_operations qla82xx_isp_ops = {
1685 .pci_config = qla82xx_pci_config,
1686 .reset_chip = qla82xx_reset_chip,
1687 .chip_diag = qla24xx_chip_diag,
1688 .config_rings = qla82xx_config_rings,
1689 .reset_adapter = qla24xx_reset_adapter,
1690 .nvram_config = qla81xx_nvram_config,
1691 .update_fw_options = qla24xx_update_fw_options,
1692 .load_risc = qla82xx_load_risc,
1693 .pci_info_str = qla82xx_pci_info_str,
1694 .fw_version_str = qla24xx_fw_version_str,
1695 .intr_handler = qla82xx_intr_handler,
1696 .enable_intrs = qla82xx_enable_intrs,
1697 .disable_intrs = qla82xx_disable_intrs,
1698 .abort_command = qla24xx_abort_command,
1699 .target_reset = qla24xx_abort_target,
1700 .lun_reset = qla24xx_lun_reset,
1701 .fabric_login = qla24xx_login_fabric,
1702 .fabric_logout = qla24xx_fabric_logout,
1703 .calc_req_entries = NULL,
1704 .build_iocbs = NULL,
1705 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1706 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1707 .read_nvram = qla24xx_read_nvram_data,
1708 .write_nvram = qla24xx_write_nvram_data,
1709 .fw_dump = qla24xx_fw_dump,
1710 .beacon_on = qla24xx_beacon_on,
1711 .beacon_off = qla24xx_beacon_off,
1712 .beacon_blink = qla24xx_beacon_blink,
1713 .read_optrom = qla82xx_read_optrom_data,
1714 .write_optrom = qla82xx_write_optrom_data,
1715 .get_flash_version = qla24xx_get_flash_version,
1716 .start_scsi = qla82xx_start_scsi,
1717 .abort_isp = qla82xx_abort_isp,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001718};
1719
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001720static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001721qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001722{
1723 ha->device_type = DT_EXTENDED_IDS;
1724 switch (ha->pdev->device) {
1725 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1726 ha->device_type |= DT_ISP2100;
1727 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001728 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001729 break;
1730 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1731 ha->device_type |= DT_ISP2200;
1732 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001733 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001734 break;
1735 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1736 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001737 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001738 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001739 break;
1740 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1741 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001742 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001743 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001744 break;
1745 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1746 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001747 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001748 if (ha->pdev->subsystem_vendor == 0x1028 &&
1749 ha->pdev->subsystem_device == 0x0170)
1750 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001751 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001752 break;
1753 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1754 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001755 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001756 break;
1757 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1758 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001759 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001760 break;
1761 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1762 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001763 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001764 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001765 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001766 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001767 break;
1768 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1769 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001770 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001771 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001772 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001773 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001774 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001775 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1776 ha->device_type |= DT_ISP8432;
1777 ha->device_type |= DT_ZIO_SUPPORTED;
1778 ha->device_type |= DT_FWI2;
1779 ha->device_type |= DT_IIDMA;
1780 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1781 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001782 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1783 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001784 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001785 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001786 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001787 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1788 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001789 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001790 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001791 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001792 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1793 ha->device_type |= DT_ISP2532;
1794 ha->device_type |= DT_ZIO_SUPPORTED;
1795 ha->device_type |= DT_FWI2;
1796 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001797 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1798 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001799 case PCI_DEVICE_ID_QLOGIC_ISP8001:
1800 ha->device_type |= DT_ISP8001;
1801 ha->device_type |= DT_ZIO_SUPPORTED;
1802 ha->device_type |= DT_FWI2;
1803 ha->device_type |= DT_IIDMA;
1804 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1805 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001806 case PCI_DEVICE_ID_QLOGIC_ISP8021:
1807 ha->device_type |= DT_ISP8021;
1808 ha->device_type |= DT_ZIO_SUPPORTED;
1809 ha->device_type |= DT_FWI2;
1810 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1811 /* Initialize 82XX ISP flags */
1812 qla82xx_init_flags(ha);
1813 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001814 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07001815
Giridhar Malavalia9083012010-04-12 17:59:55 -07001816 if (IS_QLA82XX(ha))
1817 ha->port_no = !(ha->portnum & 1);
1818 else
1819 /* Get adapter physical port no from interrupt pin register. */
1820 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
1821
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07001822 if (ha->port_no & 1)
1823 ha->flags.port0 = 1;
1824 else
1825 ha->flags.port0 = 0;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001826}
1827
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001829qla2x00_iospace_config(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830{
Andrew Vasquez37765412008-01-17 09:02:09 -08001831 resource_size_t pio;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001832 uint16_t msix;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001833 int cpus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834
Giridhar Malavalia9083012010-04-12 17:59:55 -07001835 if (IS_QLA82XX(ha))
1836 return qla82xx_iospace_config(ha);
1837
Andrew Vasquez285d0322007-10-19 15:59:17 -07001838 if (pci_request_selected_regions(ha->pdev, ha->bars,
1839 QLA2XXX_DRIVER_NAME)) {
1840 qla_printk(KERN_WARNING, ha,
1841 "Failed to reserve PIO/MMIO regions (%s)\n",
1842 pci_name(ha->pdev));
1843
1844 goto iospace_error_exit;
1845 }
1846 if (!(ha->bars & 1))
1847 goto skip_pio;
1848
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1850 pio = pci_resource_start(ha->pdev, 0);
Andrew Vasquez37765412008-01-17 09:02:09 -08001851 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1852 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 qla_printk(KERN_WARNING, ha,
1854 "Invalid PCI I/O region size (%s)...\n",
1855 pci_name(ha->pdev));
1856 pio = 0;
1857 }
1858 } else {
1859 qla_printk(KERN_WARNING, ha,
1860 "region #0 not a PIO resource (%s)...\n",
1861 pci_name(ha->pdev));
1862 pio = 0;
1863 }
Andrew Vasquez285d0322007-10-19 15:59:17 -07001864 ha->pio_address = pio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865
Andrew Vasquez285d0322007-10-19 15:59:17 -07001866skip_pio:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 /* Use MMIO operations for all accesses. */
Andrew Vasquez37765412008-01-17 09:02:09 -08001868 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 qla_printk(KERN_ERR, ha,
Andrew Vasquez37765412008-01-17 09:02:09 -08001870 "region #1 not an MMIO resource (%s), aborting\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 pci_name(ha->pdev));
1872 goto iospace_error_exit;
1873 }
Andrew Vasquez37765412008-01-17 09:02:09 -08001874 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 qla_printk(KERN_ERR, ha,
1876 "Invalid PCI mem region size (%s), aborting\n",
1877 pci_name(ha->pdev));
1878 goto iospace_error_exit;
1879 }
1880
Andrew Vasquez37765412008-01-17 09:02:09 -08001881 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 if (!ha->iobase) {
1883 qla_printk(KERN_ERR, ha,
1884 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1885
1886 goto iospace_error_exit;
1887 }
1888
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001889 /* Determine queue resources */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001890 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezd84a47c2010-03-19 16:59:18 -07001891 if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
1892 (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001893 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001894 goto mqiobase_exit;
Michael Hernandezd84a47c2010-03-19 16:59:18 -07001895
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001896 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1897 pci_resource_len(ha->pdev, 3));
1898 if (ha->mqiobase) {
1899 /* Read MSIX vector size of the board */
1900 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1901 ha->msix_count = msix;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001902 /* Max queues are bounded by available msix vectors */
1903 /* queue 0 uses two msix vectors */
1904 if (ql2xmultique_tag) {
1905 cpus = num_online_cpus();
Anirban Chakraborty27dc9c52009-06-17 10:30:28 -07001906 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001907 (cpus + 1) : (ha->msix_count - 1);
1908 ha->max_req_queues = 2;
1909 } else if (ql2xmaxqueues > 1) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001910 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1911 QLA_MQ_SIZE : ql2xmaxqueues;
1912 DEBUG2(qla_printk(KERN_INFO, ha, "QoS mode set, max no"
1913 " of request queues:%d\n", ha->max_req_queues));
1914 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001915 qla_printk(KERN_INFO, ha,
1916 "MSI-X vector count: %d\n", msix);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001917 } else
1918 qla_printk(KERN_INFO, ha, "BAR 3 not enabled\n");
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001919
1920mqiobase_exit:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001921 ha->msix_count = ha->max_rsp_queues + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 return (0);
1923
1924iospace_error_exit:
1925 return (-ENOMEM);
1926}
1927
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001928static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001929qla2xxx_scan_start(struct Scsi_Host *shost)
1930{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001931 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001932
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07001933 if (vha->hw->flags.running_gold_fw)
1934 return;
1935
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001936 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1937 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1938 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1939 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001940}
1941
1942static int
1943qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1944{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001945 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001946
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001947 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001948 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001949 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001950 return 1;
1951
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001952 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001953}
1954
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955/*
1956 * PCI driver interface
1957 */
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001958static int __devinit
1959qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001961 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001963 scsi_qla_host_t *base_vha = NULL;
1964 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07001965 char pci_info[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 char fw_str[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08001967 struct scsi_host_template *sht;
Anirban Chakrabortyc51da4e2008-11-10 15:53:20 -08001968 int bars, max_id, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001969 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001970 struct req_que *req = NULL;
1971 struct rsp_que *rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
Andrew Vasquez285d0322007-10-19 15:59:17 -07001973 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07001974 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001975 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1976 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001977 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07001978 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1979 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001980 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07001981 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
1982 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07001983 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001984 mem_only = 1;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001985 }
1986
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001987 if (mem_only) {
1988 if (pci_enable_device_mem(pdev))
1989 goto probe_out;
1990 } else {
1991 if (pci_enable_device(pdev))
1992 goto probe_out;
1993 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994
Jesse Barnes09276782008-10-18 17:33:19 -07001995 /* This may fail but that's ok */
1996 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07001997
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001998 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
1999 if (!ha) {
2000 DEBUG(printk("Unable to allocate memory for ha\n"));
2001 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002003 ha->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004
2005 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002006 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002007 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002008 spin_lock_init(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002010 /* Set ISP-type information. */
2011 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002012
2013 /* Set EEH reset type to fundamental if required by hba */
2014 if ( IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha)) {
2015 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002016 }
2017
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 /* Configure PCI I/O space */
2019 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002020 if (ret)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002021 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 qla_printk(KERN_INFO, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08002024 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
2025 ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 ha->prev_topology = 0;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002028 ha->init_cb_size = sizeof(init_cb_t);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002029 ha->link_data_rate = PORT_SPEED_UNKNOWN;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002030 ha->optrom_size = OPTROM_SIZE_2300;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002032 /* Assign ISP specific operations. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002033 max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 if (IS_QLA2100(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002035 max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002037 req_length = REQUEST_ENTRY_CNT_2100;
2038 rsp_length = RESPONSE_ENTRY_CNT_2100;
2039 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002040 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002041 ha->flash_conf_off = ~0;
2042 ha->flash_data_off = ~0;
2043 ha->nvram_conf_off = ~0;
2044 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002045 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 } else if (IS_QLA2200(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002048 req_length = REQUEST_ENTRY_CNT_2200;
2049 rsp_length = RESPONSE_ENTRY_CNT_2100;
2050 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002051 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002052 ha->flash_conf_off = ~0;
2053 ha->flash_data_off = ~0;
2054 ha->nvram_conf_off = ~0;
2055 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002056 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002057 } else if (IS_QLA23XX(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002059 req_length = REQUEST_ENTRY_CNT_2200;
2060 rsp_length = RESPONSE_ENTRY_CNT_2300;
2061 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002062 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002063 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2064 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002065 ha->flash_conf_off = ~0;
2066 ha->flash_data_off = ~0;
2067 ha->nvram_conf_off = ~0;
2068 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002069 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002070 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -07002071 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002072 req_length = REQUEST_ENTRY_CNT_24XX;
2073 rsp_length = RESPONSE_ENTRY_CNT_2300;
2074 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002075 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002076 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002077 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002078 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002079 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002080 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2081 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2082 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2083 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002084 } else if (IS_QLA25XX(ha)) {
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002085 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002086 req_length = REQUEST_ENTRY_CNT_24XX;
2087 rsp_length = RESPONSE_ENTRY_CNT_2300;
2088 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002089 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002090 ha->gid_list_info_size = 8;
2091 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002092 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002093 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002094 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2095 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2096 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2097 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2098 } else if (IS_QLA81XX(ha)) {
2099 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2100 req_length = REQUEST_ENTRY_CNT_24XX;
2101 rsp_length = RESPONSE_ENTRY_CNT_2300;
2102 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2103 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2104 ha->gid_list_info_size = 8;
2105 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002106 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002107 ha->isp_ops = &qla81xx_isp_ops;
2108 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2109 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2110 ha->nvram_conf_off = ~0;
2111 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002112 } else if (IS_QLA82XX(ha)) {
2113 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2114 req_length = REQUEST_ENTRY_CNT_82XX;
2115 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2116 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2117 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2118 ha->gid_list_info_size = 8;
2119 ha->optrom_size = OPTROM_SIZE_82XX;
2120 ha->isp_ops = &qla82xx_isp_ops;
2121 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2122 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2123 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2124 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002127 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002128 init_completion(&ha->mbx_cmd_comp);
2129 complete(&ha->mbx_cmd_comp);
2130 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07002131 init_completion(&ha->dcbx_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002133 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134
Andrew Vasquez53303c42009-01-22 09:45:37 -08002135 qla2x00_config_dma_addressing(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002136 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002137 if (!ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 qla_printk(KERN_WARNING, ha,
2139 "[ERROR] Failed to allocate memory for adapter\n");
2140
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002141 goto probe_hw_failed;
2142 }
2143
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002144 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002145 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002146 req->max_q_depth = ql2xmaxqdepth;
2147
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002148
2149 base_vha = qla2x00_create_host(sht, ha);
2150 if (!base_vha) {
2151 qla_printk(KERN_WARNING, ha,
2152 "[ERROR] Failed to allocate memory for scsi_host\n");
2153
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002154 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002155 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002156 qla2x00_free_req_que(ha, req);
2157 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002158 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 }
2160
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002161 pci_set_drvdata(pdev, base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002163 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002164 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002165 host->can_queue = req->length + 128;
2166 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002167 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002168 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002169 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2170 base_vha->vp_idx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002171 if (IS_QLA2100(ha))
2172 host->sg_tablesize = 32;
2173 host->max_id = max_id;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002174 host->this_id = 255;
2175 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07002176 host->unique_id = host->host_no;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002177 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07002178 host->max_channel = MAX_BUSES - 1;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002179 host->max_lun = MAX_LUNS;
2180 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002181 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002182
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002183 /* Set up the irqs */
2184 ret = qla2x00_request_irqs(ha, rsp);
2185 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002186 goto probe_init_failed;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002187
2188 pci_save_state(pdev);
2189
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002190 /* Alloc arrays of request and response ring ptrs */
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002191que_init:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002192 if (!qla2x00_alloc_queues(ha)) {
2193 qla_printk(KERN_WARNING, ha,
2194 "[ERROR] Failed to allocate memory for queue"
2195 " pointers\n");
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002196 goto probe_init_failed;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002197 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002198
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002199 ha->rsp_q_map[0] = rsp;
2200 ha->req_q_map[0] = req;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002201 rsp->req = req;
2202 req->rsp = rsp;
2203 set_bit(0, ha->req_qid_map);
2204 set_bit(0, ha->rsp_qid_map);
Andrew Vasquez08029992009-03-24 09:07:55 -07002205 /* FWI2-capable only. */
2206 req->req_q_in = &ha->iobase->isp24.req_q_in;
2207 req->req_q_out = &ha->iobase->isp24.req_q_out;
2208 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
2209 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002210 if (ha->mqenable) {
Andrew Vasquez08029992009-03-24 09:07:55 -07002211 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2212 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2213 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2214 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002215 }
2216
Giridhar Malavalia9083012010-04-12 17:59:55 -07002217 if (IS_QLA82XX(ha)) {
2218 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
2219 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
2220 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
2221 }
2222
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002223 if (qla2x00_initialize_adapter(base_vha)) {
2224 qla_printk(KERN_WARNING, ha,
2225 "Failed to initialize adapter\n");
2226
2227 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
2228 "Adapter flags %x.\n",
2229 base_vha->host_no, base_vha->device_flags));
2230
Giridhar Malavalia9083012010-04-12 17:59:55 -07002231 if (IS_QLA82XX(ha)) {
2232 qla82xx_idc_lock(ha);
2233 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2234 QLA82XX_DEV_FAILED);
2235 qla82xx_idc_unlock(ha);
2236 qla_printk(KERN_INFO, ha, "HW State: FAILED\n");
2237 }
2238
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002239 ret = -ENODEV;
2240 goto probe_failed;
2241 }
2242
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002243 if (ha->mqenable) {
2244 if (qla25xx_setup_mode(base_vha)) {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002245 qla_printk(KERN_WARNING, ha,
2246 "Can't create queues, falling back to single"
2247 " queue mode\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002248 goto que_init;
2249 }
2250 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002251
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002252 if (ha->flags.running_gold_fw)
2253 goto skip_dpc;
2254
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002255 /*
2256 * Startup the kernel thread for this host adapter
2257 */
2258 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
2259 "%s_dpc", base_vha->host_str);
2260 if (IS_ERR(ha->dpc_thread)) {
2261 qla_printk(KERN_WARNING, ha,
2262 "Unable to start DPC thread!\n");
2263 ret = PTR_ERR(ha->dpc_thread);
2264 goto probe_failed;
2265 }
2266
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002267skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002268 list_add_tail(&base_vha->list, &ha->vp_list);
2269 base_vha->host->irq = ha->pdev->irq;
2270
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002272 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273
2274 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002275 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276
Arun Easiba77ef52010-05-28 15:08:27 -07002277 if ((IS_QLA25XX(ha) || IS_QLA81XX(ha)) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07002278 if (ha->fw_attributes & BIT_4) {
2279 base_vha->flags.difdix_supported = 1;
2280 DEBUG18(qla_printk(KERN_INFO, ha,
2281 "Registering for DIF/DIX type 1 and 3"
2282 " protection.\n"));
2283 scsi_host_set_prot(host,
2284 SHOST_DIF_TYPE1_PROTECTION
2285 | SHOST_DIF_TYPE3_PROTECTION
2286 | SHOST_DIX_TYPE1_PROTECTION
2287 | SHOST_DIX_TYPE3_PROTECTION);
2288 scsi_host_set_guard(host, SHOST_DIX_GUARD_CRC);
2289 } else
2290 base_vha->flags.difdix_supported = 0;
2291 }
2292
Giridhar Malavalia9083012010-04-12 17:59:55 -07002293 ha->isp_ops->enable_intrs(ha);
2294
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002295 ret = scsi_add_host(host, &pdev->dev);
2296 if (ret)
2297 goto probe_failed;
2298
Michael Reed14864002009-12-02 09:11:16 -06002299 base_vha->flags.init_done = 1;
2300 base_vha->flags.online = 1;
2301
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002302 scsi_scan_host(host);
2303
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002304 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002305
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002306 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002307
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002308 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002309
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 qla_printk(KERN_INFO, ha, "\n"
2311 " QLogic Fibre Channel HBA Driver: %s\n"
2312 " QLogic %s - %s\n"
Andrew Vasquez54333832005-11-09 15:49:04 -08002313 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
2314 qla2x00_version_str, ha->model_number,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002315 ha->model_desc ? ha->model_desc : "", pdev->device,
2316 ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
2317 ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
2318 ha->isp_ops->fw_version_str(base_vha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 return 0;
2321
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002322probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002323 qla2x00_free_req_que(ha, req);
2324 qla2x00_free_rsp_que(ha, rsp);
2325 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002326
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07002328 if (base_vha->timer_active)
2329 qla2x00_stop_timer(base_vha);
2330 base_vha->flags.online = 0;
2331 if (ha->dpc_thread) {
2332 struct task_struct *t = ha->dpc_thread;
2333
2334 ha->dpc_thread = NULL;
2335 kthread_stop(t);
2336 }
2337
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002338 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002340 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002342probe_hw_failed:
Giridhar Malavalia9083012010-04-12 17:59:55 -07002343 if (IS_QLA82XX(ha)) {
2344 qla82xx_idc_lock(ha);
2345 qla82xx_clear_drv_active(ha);
2346 qla82xx_idc_unlock(ha);
2347 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
2348 if (!ql2xdbwr)
2349 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2350 } else {
2351 if (ha->iobase)
2352 iounmap(ha->iobase);
2353 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002354 pci_release_selected_regions(ha->pdev, ha->bars);
2355 kfree(ha);
2356 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002358probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002359 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002360 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
Adrian Bunk4c993f72008-01-14 00:55:16 -08002363static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002364qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002366 scsi_qla_host_t *base_vha, *vha, *temp;
2367 struct qla_hw_data *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002369 base_vha = pci_get_drvdata(pdev);
2370 ha = base_vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002372 list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
2373 if (vha && vha->fc_vport)
2374 fc_vport_terminate(vha->fc_vport);
2375 }
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002376
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002377 set_bit(UNLOADING, &base_vha->dpc_flags);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002378
Andrew Vasquezb9978762009-03-24 09:08:05 -07002379 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2380
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002381 qla2x00_dfs_remove(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002382
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002383 qla84xx_put_chip(base_vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002384
Andrew Vasquezb9978762009-03-24 09:08:05 -07002385 /* Disable timer */
2386 if (base_vha->timer_active)
2387 qla2x00_stop_timer(base_vha);
2388
2389 base_vha->flags.online = 0;
2390
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002391 /* Flush the work queue and remove it */
2392 if (ha->wq) {
2393 flush_workqueue(ha->wq);
2394 destroy_workqueue(ha->wq);
2395 ha->wq = NULL;
2396 }
2397
Andrew Vasquezb9978762009-03-24 09:08:05 -07002398 /* Kill the kernel thread for this host */
2399 if (ha->dpc_thread) {
2400 struct task_struct *t = ha->dpc_thread;
2401
2402 /*
2403 * qla2xxx_wake_dpc checks for ->dpc_thread
2404 * so we need to zero it out.
2405 */
2406 ha->dpc_thread = NULL;
2407 kthread_stop(t);
2408 }
2409
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002410 qla2x00_free_sysfs_attr(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002412 fc_remove_host(base_vha->host);
bdf79622005-04-17 15:06:53 -05002413
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002414 scsi_remove_host(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002416 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002418 scsi_host_put(base_vha->host);
2419
Giridhar Malavalia9083012010-04-12 17:59:55 -07002420 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07002421 qla82xx_idc_lock(ha);
2422 qla82xx_clear_drv_active(ha);
2423 qla82xx_idc_unlock(ha);
2424
Giridhar Malavalia9083012010-04-12 17:59:55 -07002425 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
2426 if (!ql2xdbwr)
2427 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2428 } else {
2429 if (ha->iobase)
2430 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002431
Giridhar Malavalia9083012010-04-12 17:59:55 -07002432 if (ha->mqiobase)
2433 iounmap(ha->mqiobase);
2434 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002435
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002436 pci_release_selected_regions(ha->pdev, ha->bars);
2437 kfree(ha);
2438 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002440 pci_disable_pcie_error_reporting(pdev);
2441
Bernhard Walle665db932007-03-28 00:49:49 +02002442 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 pci_set_drvdata(pdev, NULL);
2444}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445
2446static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002447qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002449 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450
Andrew Vasquez85880802009-12-15 21:29:46 -08002451 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
2452
2453 /* Disable timer */
2454 if (vha->timer_active)
2455 qla2x00_stop_timer(vha);
2456
2457 /* Kill the kernel thread for this host */
2458 if (ha->dpc_thread) {
2459 struct task_struct *t = ha->dpc_thread;
2460
2461 /*
2462 * qla2xxx_wake_dpc checks for ->dpc_thread
2463 * so we need to zero it out.
2464 */
2465 ha->dpc_thread = NULL;
2466 kthread_stop(t);
2467 }
2468
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002469 qla25xx_delete_queues(vha);
2470
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002471 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002472 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002473
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002474 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002475 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002476
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002477 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002478 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479
Andrew Vasquez85880802009-12-15 21:29:46 -08002480 vha->flags.online = 0;
2481
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002482 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07002483 if (ha->interrupts_on) {
2484 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002485 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002486 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002487
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002488 qla2x00_free_irqs(vha);
2489
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002490 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002491
2492 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493}
2494
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002495static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002496qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002497 int defer)
2498{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002499 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07002500 scsi_qla_host_t *base_vha;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002501
2502 if (!fcport->rport)
2503 return;
2504
2505 rport = fcport->rport;
2506 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07002507 base_vha = pci_get_drvdata(vha->hw->pdev);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002508 spin_lock_irq(vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002509 fcport->drport = rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002510 spin_unlock_irq(vha->host->host_lock);
Andrew Vasquez67becc02009-08-25 11:36:20 -07002511 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2512 qla2xxx_wake_dpc(base_vha);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002513 } else
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002514 fc_remote_port_delete(rport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002515}
2516
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2519 *
2520 * Input: ha = adapter block pointer. fcport = port structure pointer.
2521 *
2522 * Return: None.
2523 *
2524 * Context:
2525 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002526void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002527 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002529 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002530 vha->vp_idx == fcport->vp_idx) {
2531 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2532 qla2x00_schedule_rport_del(vha, fcport, defer);
2533 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002534 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 * We may need to retry the login, so don't change the state of the
2536 * port but do the retries.
2537 */
2538 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2539 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2540
2541 if (!do_login)
2542 return;
2543
2544 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002545 fcport->login_retry = vha->hw->login_retry_count;
2546 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547
2548 DEBUG(printk("scsi(%ld): Port login retry: "
2549 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2550 "id = 0x%04x retry cnt=%d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002551 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 fcport->port_name[0],
2553 fcport->port_name[1],
2554 fcport->port_name[2],
2555 fcport->port_name[3],
2556 fcport->port_name[4],
2557 fcport->port_name[5],
2558 fcport->port_name[6],
2559 fcport->port_name[7],
2560 fcport->loop_id,
2561 fcport->login_retry));
2562 }
2563}
2564
2565/*
2566 * qla2x00_mark_all_devices_lost
2567 * Updates fcport state when device goes offline.
2568 *
2569 * Input:
2570 * ha = adapter block pointer.
2571 * fcport = port structure pointer.
2572 *
2573 * Return:
2574 * None.
2575 *
2576 * Context:
2577 */
2578void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002579qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580{
2581 fc_port_t *fcport;
2582
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002583 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002584 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002586
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 /*
2588 * No point in marking the device as lost, if the device is
2589 * already DEAD.
2590 */
2591 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2592 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002593 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002594 if (defer)
2595 qla2x00_schedule_rport_del(vha, fcport, defer);
2596 else if (vha->vp_idx == fcport->vp_idx)
2597 qla2x00_schedule_rport_del(vha, fcport, defer);
2598 }
2599 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 }
2601}
2602
2603/*
2604* qla2x00_mem_alloc
2605* Allocates adapter memory.
2606*
2607* Returns:
2608* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08002609* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08002611static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002612qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2613 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614{
2615 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616
Andrew Vasqueze8711082008-01-31 12:33:48 -08002617 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002618 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002619 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002620 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002622 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2623 &ha->gid_list_dma, GFP_KERNEL);
2624 if (!ha->gid_list)
Andrew Vasqueze8711082008-01-31 12:33:48 -08002625 goto fail_free_init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626
Andrew Vasqueze8711082008-01-31 12:33:48 -08002627 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2628 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002629 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630
Giridhar Malavalia9083012010-04-12 17:59:55 -07002631 if (IS_QLA82XX(ha)) {
2632 /* Allocate cache for CT6 Ctx. */
2633 if (!ctx_cachep) {
2634 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
2635 sizeof(struct ct6_dsd), 0,
2636 SLAB_HWCACHE_ALIGN, NULL);
2637 if (!ctx_cachep)
2638 goto fail_free_gid_list;
2639 }
2640 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
2641 ctx_cachep);
2642 if (!ha->ctx_mempool)
2643 goto fail_free_srb_mempool;
2644 }
2645
Andrew Vasqueze8711082008-01-31 12:33:48 -08002646 /* Get memory for cached NVRAM */
2647 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2648 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07002649 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002651 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2652 ha->pdev->device);
2653 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2654 DMA_POOL_SIZE, 8, 0);
2655 if (!ha->s_dma_pool)
2656 goto fail_free_nvram;
2657
Arun Easibad75002010-05-04 15:01:30 -07002658 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002659 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2660 DSD_LIST_DMA_POOL_SIZE, 8, 0);
2661 if (!ha->dl_dma_pool) {
2662 qla_printk(KERN_WARNING, ha,
2663 "Memory Allocation failed - dl_dma_pool\n");
2664 goto fail_s_dma_pool;
2665 }
2666
2667 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2668 FCP_CMND_DMA_POOL_SIZE, 8, 0);
2669 if (!ha->fcp_cmnd_dma_pool) {
2670 qla_printk(KERN_WARNING, ha,
2671 "Memory Allocation failed - fcp_cmnd_dma_pool\n");
2672 goto fail_dl_dma_pool;
2673 }
2674 }
2675
Andrew Vasqueze8711082008-01-31 12:33:48 -08002676 /* Allocate memory for SNS commands */
2677 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002678 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002679 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002680 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002681 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002682 goto fail_dma_pool;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002683 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002684 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002685 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002686 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002687 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002688 goto fail_dma_pool;
2689 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002690 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002691 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002692 if (!ha->ct_sns)
2693 goto fail_free_ms_iocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 }
2695
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002696 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002697 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2698 if (!*req) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002699 DEBUG(printk("Unable to allocate memory for req\n"));
2700 goto fail_req;
2701 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002702 (*req)->length = req_len;
2703 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2704 ((*req)->length + 1) * sizeof(request_t),
2705 &(*req)->dma, GFP_KERNEL);
2706 if (!(*req)->ring) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002707 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2708 goto fail_req_ring;
2709 }
2710 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002711 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2712 if (!*rsp) {
2713 qla_printk(KERN_WARNING, ha,
2714 "Unable to allocate memory for rsp\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002715 goto fail_rsp;
2716 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002717 (*rsp)->hw = ha;
2718 (*rsp)->length = rsp_len;
2719 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2720 ((*rsp)->length + 1) * sizeof(response_t),
2721 &(*rsp)->dma, GFP_KERNEL);
2722 if (!(*rsp)->ring) {
2723 qla_printk(KERN_WARNING, ha,
2724 "Unable to allocate memory for rsp_ring\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002725 goto fail_rsp_ring;
2726 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002727 (*req)->rsp = *rsp;
2728 (*rsp)->req = *req;
2729 /* Allocate memory for NVRAM data for vports */
2730 if (ha->nvram_npiv_size) {
2731 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
2732 ha->nvram_npiv_size, GFP_KERNEL);
2733 if (!ha->npiv_info) {
2734 qla_printk(KERN_WARNING, ha,
2735 "Unable to allocate memory for npiv info\n");
2736 goto fail_npiv_info;
2737 }
2738 } else
2739 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002740
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002741 /* Get consistent memory allocated for EX-INIT-CB. */
Giridhar Malavalia9083012010-04-12 17:59:55 -07002742 if (IS_QLA8XXX_TYPE(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002743 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2744 &ha->ex_init_cb_dma);
2745 if (!ha->ex_init_cb)
2746 goto fail_ex_init_cb;
2747 }
2748
Giridhar Malavalia9083012010-04-12 17:59:55 -07002749 INIT_LIST_HEAD(&ha->gbl_dsd_list);
2750
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002751 /* Get consistent memory allocated for Async Port-Database. */
2752 if (!IS_FWI2_CAPABLE(ha)) {
2753 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2754 &ha->async_pd_dma);
2755 if (!ha->async_pd)
2756 goto fail_async_pd;
2757 }
2758
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002759 INIT_LIST_HEAD(&ha->vp_list);
2760 return 1;
2761
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002762fail_async_pd:
2763 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002764fail_ex_init_cb:
2765 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002766fail_npiv_info:
2767 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2768 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2769 (*rsp)->ring = NULL;
2770 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002771fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002772 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002773fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002774 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2775 sizeof(request_t), (*req)->ring, (*req)->dma);
2776 (*req)->ring = NULL;
2777 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002778fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002779 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002780fail_req:
2781 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2782 ha->ct_sns, ha->ct_sns_dma);
2783 ha->ct_sns = NULL;
2784 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002785fail_free_ms_iocb:
2786 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2787 ha->ms_iocb = NULL;
2788 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002789fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07002790 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002791 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
2792 ha->fcp_cmnd_dma_pool = NULL;
2793 }
2794fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07002795 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002796 dma_pool_destroy(ha->dl_dma_pool);
2797 ha->dl_dma_pool = NULL;
2798 }
2799fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002800 dma_pool_destroy(ha->s_dma_pool);
2801 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002802fail_free_nvram:
2803 kfree(ha->nvram);
2804 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002805fail_free_ctx_mempool:
2806 mempool_destroy(ha->ctx_mempool);
2807 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002808fail_free_srb_mempool:
2809 mempool_destroy(ha->srb_mempool);
2810 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002811fail_free_gid_list:
2812 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002813 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002814 ha->gid_list = NULL;
2815 ha->gid_list_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002816fail_free_init_cb:
2817 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2818 ha->init_cb_dma);
2819 ha->init_cb = NULL;
2820 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002821fail:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002822 DEBUG(printk("%s: Memory allocation failure\n", __func__));
Andrew Vasqueze8711082008-01-31 12:33:48 -08002823 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824}
2825
2826/*
2827* qla2x00_mem_free
2828* Frees all adapter allocated memory.
2829*
2830* Input:
2831* ha = adapter block pointer.
2832*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08002833static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002834qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835{
Andrew Vasqueze8711082008-01-31 12:33:48 -08002836 if (ha->srb_mempool)
2837 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002839 if (ha->fce)
2840 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002841 ha->fce_dma);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002842
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002843 if (ha->fw_dump) {
2844 if (ha->eft)
2845 dma_free_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002846 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002847 vfree(ha->fw_dump);
2848 }
2849
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07002850 if (ha->dcbx_tlv)
2851 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
2852 ha->dcbx_tlv, ha->dcbx_tlv_dma);
2853
Andrew Vasquezce0423f2009-06-03 09:55:13 -07002854 if (ha->xgmac_data)
2855 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
2856 ha->xgmac_data, ha->xgmac_data_dma);
2857
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 if (ha->sns_cmd)
2859 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002860 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861
2862 if (ha->ct_sns)
2863 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002864 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865
Andrew Vasquez88729e52006-06-23 16:10:50 -07002866 if (ha->sfp_data)
2867 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2868
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07002869 if (ha->edc_data)
2870 dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
2871
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 if (ha->ms_iocb)
2873 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2874
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002875 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07002876 dma_pool_free(ha->s_dma_pool,
2877 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002878
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002879 if (ha->async_pd)
2880 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
2881
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 if (ha->s_dma_pool)
2883 dma_pool_destroy(ha->s_dma_pool);
2884
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 if (ha->gid_list)
2886 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002887 ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888
Giridhar Malavalia9083012010-04-12 17:59:55 -07002889 if (IS_QLA82XX(ha)) {
2890 if (!list_empty(&ha->gbl_dsd_list)) {
2891 struct dsd_dma *dsd_ptr, *tdsd_ptr;
2892
2893 /* clean up allocated prev pool */
2894 list_for_each_entry_safe(dsd_ptr,
2895 tdsd_ptr, &ha->gbl_dsd_list, list) {
2896 dma_pool_free(ha->dl_dma_pool,
2897 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
2898 list_del(&dsd_ptr->list);
2899 kfree(dsd_ptr);
2900 }
2901 }
2902 }
2903
2904 if (ha->dl_dma_pool)
2905 dma_pool_destroy(ha->dl_dma_pool);
2906
2907 if (ha->fcp_cmnd_dma_pool)
2908 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
2909
2910 if (ha->ctx_mempool)
2911 mempool_destroy(ha->ctx_mempool);
2912
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002913 if (ha->init_cb)
2914 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002915 ha->init_cb, ha->init_cb_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002916 vfree(ha->optrom_buffer);
2917 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002918 kfree(ha->npiv_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919
Andrew Vasqueze8711082008-01-31 12:33:48 -08002920 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002921 ha->ctx_mempool = NULL;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002922 ha->eft = NULL;
2923 ha->eft_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 ha->sns_cmd = NULL;
2925 ha->sns_cmd_dma = 0;
2926 ha->ct_sns = NULL;
2927 ha->ct_sns_dma = 0;
2928 ha->ms_iocb = NULL;
2929 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 ha->init_cb = NULL;
2931 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002932 ha->ex_init_cb = NULL;
2933 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002934 ha->async_pd = NULL;
2935 ha->async_pd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936
2937 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002938 ha->dl_dma_pool = NULL;
2939 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 ha->gid_list = NULL;
2942 ha->gid_list_dma = 0;
2943
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002945 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 ha->fw_dump_reading = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002947}
2948
2949struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
2950 struct qla_hw_data *ha)
2951{
2952 struct Scsi_Host *host;
2953 struct scsi_qla_host *vha = NULL;
2954
2955 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
2956 if (host == NULL) {
2957 printk(KERN_WARNING
2958 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2959 goto fail;
2960 }
2961
2962 /* Clear our data area */
2963 vha = shost_priv(host);
2964 memset(vha, 0, sizeof(scsi_qla_host_t));
2965
2966 vha->host = host;
2967 vha->host_no = host->host_no;
2968 vha->hw = ha;
2969
2970 INIT_LIST_HEAD(&vha->vp_fcports);
2971 INIT_LIST_HEAD(&vha->work_list);
2972 INIT_LIST_HEAD(&vha->list);
2973
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002974 spin_lock_init(&vha->work_lock);
2975
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002976 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
2977 return vha;
2978
2979fail:
2980 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981}
2982
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002983static struct qla_work_evt *
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002984qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002985{
2986 struct qla_work_evt *e;
2987
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002988 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002989 if (!e)
2990 return NULL;
2991
2992 INIT_LIST_HEAD(&e->list);
2993 e->type = type;
2994 e->flags = QLA_EVT_FLAG_FREE;
2995 return e;
2996}
2997
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002998static int
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002999qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003000{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003001 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003002
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003003 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003004 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003005 spin_unlock_irqrestore(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003006 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003007
Andrew Vasquez0971de72008-04-03 13:13:18 -07003008 return QLA_SUCCESS;
3009}
3010
3011int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003012qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07003013 u32 data)
3014{
3015 struct qla_work_evt *e;
3016
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003017 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003018 if (!e)
3019 return QLA_FUNCTION_FAILED;
3020
3021 e->u.aen.code = code;
3022 e->u.aen.data = data;
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003023 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003024}
3025
Andrew Vasquez8a659572009-02-08 20:50:12 -08003026int
3027qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
3028{
3029 struct qla_work_evt *e;
3030
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003031 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003032 if (!e)
3033 return QLA_FUNCTION_FAILED;
3034
3035 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003036 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003037}
3038
Andrew Vasquezac280b62009-08-20 11:06:05 -07003039#define qla2x00_post_async_work(name, type) \
3040int qla2x00_post_async_##name##_work( \
3041 struct scsi_qla_host *vha, \
3042 fc_port_t *fcport, uint16_t *data) \
3043{ \
3044 struct qla_work_evt *e; \
3045 \
3046 e = qla2x00_alloc_work(vha, type); \
3047 if (!e) \
3048 return QLA_FUNCTION_FAILED; \
3049 \
3050 e->u.logio.fcport = fcport; \
3051 if (data) { \
3052 e->u.logio.data[0] = data[0]; \
3053 e->u.logio.data[1] = data[1]; \
3054 } \
3055 return qla2x00_post_work(vha, e); \
3056}
3057
3058qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
3059qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
3060qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
3061qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003062qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
3063qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07003064
Andrew Vasquez3420d362009-10-13 15:16:45 -07003065int
3066qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
3067{
3068 struct qla_work_evt *e;
3069
3070 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
3071 if (!e)
3072 return QLA_FUNCTION_FAILED;
3073
3074 e->u.uevent.code = code;
3075 return qla2x00_post_work(vha, e);
3076}
3077
3078static void
3079qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
3080{
3081 char event_string[40];
3082 char *envp[] = { event_string, NULL };
3083
3084 switch (code) {
3085 case QLA_UEVENT_CODE_FW_DUMP:
3086 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
3087 vha->host_no);
3088 break;
3089 default:
3090 /* do nothing */
3091 break;
3092 }
3093 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
3094}
3095
Andrew Vasquezac280b62009-08-20 11:06:05 -07003096void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003097qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003098{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003099 struct qla_work_evt *e, *tmp;
3100 unsigned long flags;
3101 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003102
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003103 spin_lock_irqsave(&vha->work_lock, flags);
3104 list_splice_init(&vha->work_list, &work);
3105 spin_unlock_irqrestore(&vha->work_lock, flags);
3106
3107 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07003108 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003109
3110 switch (e->type) {
3111 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003112 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07003113 e->u.aen.code, e->u.aen.data);
3114 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08003115 case QLA_EVT_IDC_ACK:
3116 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
3117 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003118 case QLA_EVT_ASYNC_LOGIN:
3119 qla2x00_async_login(vha, e->u.logio.fcport,
3120 e->u.logio.data);
3121 break;
3122 case QLA_EVT_ASYNC_LOGIN_DONE:
3123 qla2x00_async_login_done(vha, e->u.logio.fcport,
3124 e->u.logio.data);
3125 break;
3126 case QLA_EVT_ASYNC_LOGOUT:
3127 qla2x00_async_logout(vha, e->u.logio.fcport);
3128 break;
3129 case QLA_EVT_ASYNC_LOGOUT_DONE:
3130 qla2x00_async_logout_done(vha, e->u.logio.fcport,
3131 e->u.logio.data);
3132 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003133 case QLA_EVT_ASYNC_ADISC:
3134 qla2x00_async_adisc(vha, e->u.logio.fcport,
3135 e->u.logio.data);
3136 break;
3137 case QLA_EVT_ASYNC_ADISC_DONE:
3138 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
3139 e->u.logio.data);
3140 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07003141 case QLA_EVT_UEVENT:
3142 qla2x00_uevent_emit(vha, e->u.uevent.code);
3143 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003144 }
3145 if (e->flags & QLA_EVT_FLAG_FREE)
3146 kfree(e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003147 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003148}
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003149
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003150/* Relogins all the fcports of a vport
3151 * Context: dpc thread
3152 */
3153void qla2x00_relogin(struct scsi_qla_host *vha)
3154{
3155 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003156 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003157 uint16_t next_loopid = 0;
3158 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003159 uint16_t data[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003160
3161 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3162 /*
3163 * If the port is not ONLINE then try to login
3164 * to it if we haven't run out of retries.
3165 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003166 if (atomic_read(&fcport->state) != FCS_ONLINE &&
3167 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07003168 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003169 if (fcport->flags & FCF_FABRIC_DEVICE) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003170 if (fcport->flags & FCF_FCP2_DEVICE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003171 ha->isp_ops->fabric_logout(vha,
3172 fcport->loop_id,
3173 fcport->d_id.b.domain,
3174 fcport->d_id.b.area,
3175 fcport->d_id.b.al_pa);
3176
Andrew Vasquezac280b62009-08-20 11:06:05 -07003177 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003178 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003179 data[0] = 0;
3180 data[1] = QLA_LOGIO_LOGIN_RETRIED;
3181 status = qla2x00_post_async_login_work(
3182 vha, fcport, data);
3183 if (status == QLA_SUCCESS)
3184 continue;
3185 /* Attempt a retry. */
3186 status = 1;
3187 } else
3188 status = qla2x00_fabric_login(vha,
3189 fcport, &next_loopid);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003190 } else
3191 status = qla2x00_local_device_login(vha,
3192 fcport);
3193
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003194 if (status == QLA_SUCCESS) {
3195 fcport->old_loop_id = fcport->loop_id;
3196
3197 DEBUG(printk("scsi(%ld): port login OK: logged "
3198 "in ID 0x%x\n", vha->host_no, fcport->loop_id));
3199
3200 qla2x00_update_fcport(vha, fcport);
3201
3202 } else if (status == 1) {
3203 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3204 /* retry the login again */
3205 DEBUG(printk("scsi(%ld): Retrying"
3206 " %d login again loop_id 0x%x\n",
3207 vha->host_no, fcport->login_retry,
3208 fcport->loop_id));
3209 } else {
3210 fcport->login_retry = 0;
3211 }
3212
3213 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
3214 fcport->loop_id = FC_NO_LOOP_ID;
3215 }
3216 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3217 break;
3218 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07003219}
3220
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221/**************************************************************************
3222* qla2x00_do_dpc
3223* This kernel thread is a task that is schedule by the interrupt handler
3224* to perform the background processing for interrupts.
3225*
3226* Notes:
3227* This task always run in the context of a kernel thread. It
3228* is kick-off by the driver's detect code and starts up
3229* up one per adapter. It immediately goes to sleep and waits for
3230* some fibre event. When either the interrupt handler or
3231* the timer routine detects a event it will one of the task
3232* bits then wake us up.
3233**************************************************************************/
3234static int
3235qla2x00_do_dpc(void *data)
3236{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003237 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003238 scsi_qla_host_t *base_vha;
3239 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08003240
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003241 ha = (struct qla_hw_data *)data;
3242 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 set_user_nice(current, -20);
3245
Christoph Hellwig39a11242006-02-14 18:46:22 +01003246 while (!kthread_should_stop()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
3248
Christoph Hellwig39a11242006-02-14 18:46:22 +01003249 set_current_state(TASK_INTERRUPTIBLE);
3250 schedule();
3251 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252
3253 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
3254
3255 /* Initialization not yet finished. Don't do anything yet. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003256 if (!base_vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 continue;
3258
Andrew Vasquez85880802009-12-15 21:29:46 -08003259 if (ha->flags.eeh_busy) {
3260 DEBUG17(qla_printk(KERN_WARNING, ha,
3261 "qla2x00_do_dpc: dpc_flags: %lx\n",
3262 base_vha->dpc_flags));
3263 continue;
3264 }
3265
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003266 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267
3268 ha->dpc_active = 1;
3269
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271 ha->dpc_active = 0;
3272 continue;
3273 }
3274
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003275 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003276
Giridhar Malavalia9083012010-04-12 17:59:55 -07003277 if (IS_QLA82XX(ha)) {
3278 if (test_and_clear_bit(ISP_UNRECOVERABLE,
3279 &base_vha->dpc_flags)) {
3280 qla82xx_idc_lock(ha);
3281 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3282 QLA82XX_DEV_FAILED);
3283 qla82xx_idc_unlock(ha);
3284 qla_printk(KERN_INFO, ha,
3285 "HW State: FAILED\n");
3286 qla82xx_device_state_handler(base_vha);
3287 continue;
3288 }
3289
3290 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
3291 &base_vha->dpc_flags)) {
3292
3293 DEBUG(printk(KERN_INFO
3294 "scsi(%ld): dpc: sched "
3295 "qla82xx_fcoe_ctx_reset ha = %p\n",
3296 base_vha->host_no, ha));
3297 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
3298 &base_vha->dpc_flags))) {
3299 if (qla82xx_fcoe_ctx_reset(base_vha)) {
3300 /* FCoE-ctx reset failed.
3301 * Escalate to chip-reset
3302 */
3303 set_bit(ISP_ABORT_NEEDED,
3304 &base_vha->dpc_flags);
3305 }
3306 clear_bit(ABORT_ISP_ACTIVE,
3307 &base_vha->dpc_flags);
3308 }
3309
3310 DEBUG(printk("scsi(%ld): dpc:"
3311 " qla82xx_fcoe_ctx_reset end\n",
3312 base_vha->host_no));
3313 }
3314 }
3315
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003316 if (test_and_clear_bit(ISP_ABORT_NEEDED,
3317 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318
3319 DEBUG(printk("scsi(%ld): dpc: sched "
3320 "qla2x00_abort_isp ha = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003321 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003323 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324
Giridhar Malavalia9083012010-04-12 17:59:55 -07003325 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 /* failed. retry later */
3327 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003328 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003330 clear_bit(ABORT_ISP_ACTIVE,
3331 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08003332 }
3333
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003335 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336 }
3337
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003338 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
3339 qla2x00_update_fcports(base_vha);
3340 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003341 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003342
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003343 if (test_and_clear_bit(RESET_MARKER_NEEDED,
3344 &base_vha->dpc_flags) &&
3345 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346
3347 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003348 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003350 qla2x00_rst_aen(base_vha);
3351 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 }
3353
3354 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003355 if ((test_and_clear_bit(RELOGIN_NEEDED,
3356 &base_vha->dpc_flags)) &&
3357 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
3358 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359
3360 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003361 base_vha->host_no));
3362 qla2x00_relogin(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003365 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 }
3367
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003368 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
3369 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370
3371 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003372 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373
3374 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003375 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003377 rval = qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003379 clear_bit(LOOP_RESYNC_ACTIVE,
3380 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381 }
3382
3383 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003384 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385 }
3386
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003387 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
3388 atomic_read(&base_vha->loop_state) == LOOP_READY) {
3389 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
3390 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07003391 }
3392
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003394 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003396 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
3397 &base_vha->dpc_flags))
3398 ha->isp_ops->beacon_blink(base_vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08003399
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003400 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003401
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402 ha->dpc_active = 0;
3403 } /* End of while(1) */
3404
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003405 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406
3407 /*
3408 * Make sure that nobody tries to wake us up again.
3409 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 ha->dpc_active = 0;
3411
Andrew Vasquezac280b62009-08-20 11:06:05 -07003412 /* Cleanup any residual CTX SRBs. */
3413 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3414
Christoph Hellwig39a11242006-02-14 18:46:22 +01003415 return 0;
3416}
3417
3418void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003419qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01003420{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003421 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003422 struct task_struct *t = ha->dpc_thread;
3423
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003424 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003425 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426}
3427
3428/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429* qla2x00_rst_aen
3430* Processes asynchronous reset.
3431*
3432* Input:
3433* ha = adapter block pointer.
3434*/
3435static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003436qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003438 if (vha->flags.online && !vha->flags.reset_active &&
3439 !atomic_read(&vha->loop_down_timer) &&
3440 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003442 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443
3444 /*
3445 * Issue marker command only when we are going to start
3446 * the I/O.
3447 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003448 vha->marker_needed = 1;
3449 } while (!atomic_read(&vha->loop_down_timer) &&
3450 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 }
3452}
3453
f4f051e2005-04-17 15:02:26 -05003454static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003455qla2x00_sp_free_dma(srb_t *sp)
f4f051e2005-04-17 15:02:26 -05003456{
3457 struct scsi_cmnd *cmd = sp->cmd;
Arun Easibad75002010-05-04 15:01:30 -07003458 struct qla_hw_data *ha = sp->fcport->vha->hw;
f4f051e2005-04-17 15:02:26 -05003459
3460 if (sp->flags & SRB_DMA_VALID) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09003461 scsi_dma_unmap(cmd);
f4f051e2005-04-17 15:02:26 -05003462 sp->flags &= ~SRB_DMA_VALID;
3463 }
Arun Easibad75002010-05-04 15:01:30 -07003464
3465 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
3466 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
3467 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
3468 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
3469 }
3470
3471 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
3472 /* List assured to be having elements */
3473 qla2x00_clean_dsd_pool(ha, sp);
3474 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
3475 }
3476
3477 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
3478 dma_pool_free(ha->dl_dma_pool, sp->ctx,
3479 ((struct crc_context *)sp->ctx)->crc_ctx_dma);
3480 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
3481 }
3482
Andrew Vasquezfca29702005-07-06 10:31:47 -07003483 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05003484}
3485
3486void
Giridhar Malavali083a4692010-05-28 15:08:18 -07003487qla2x00_sp_final_compl(struct qla_hw_data *ha, srb_t *sp)
f4f051e2005-04-17 15:02:26 -05003488{
3489 struct scsi_cmnd *cmd = sp->cmd;
3490
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003491 qla2x00_sp_free_dma(sp);
f4f051e2005-04-17 15:02:26 -05003492
Giridhar Malavalia9083012010-04-12 17:59:55 -07003493 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
3494 struct ct6_dsd *ctx = sp->ctx;
3495 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx->fcp_cmnd,
3496 ctx->fcp_cmnd_dma);
3497 list_splice(&ctx->dsd_list, &ha->gbl_dsd_list);
3498 ha->gbl_dsd_inuse -= ctx->dsd_use_cnt;
3499 ha->gbl_dsd_avail += ctx->dsd_use_cnt;
3500 mempool_free(sp->ctx, ha->ctx_mempool);
3501 sp->ctx = NULL;
3502 }
f4f051e2005-04-17 15:02:26 -05003503
Giridhar Malavalia9083012010-04-12 17:59:55 -07003504 mempool_free(sp, ha->srb_mempool);
f4f051e2005-04-17 15:02:26 -05003505 cmd->scsi_done(cmd);
3506}
bdf79622005-04-17 15:06:53 -05003507
Giridhar Malavali083a4692010-05-28 15:08:18 -07003508void
3509qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
3510{
3511 if (atomic_read(&sp->ref_count) == 0) {
3512 DEBUG2(qla_printk(KERN_WARNING, ha,
3513 "SP reference-count to ZERO -- sp=%p\n", sp));
3514 DEBUG2(BUG());
3515 return;
3516 }
3517 if (!atomic_dec_and_test(&sp->ref_count))
3518 return;
3519 qla2x00_sp_final_compl(ha, sp);
3520}
3521
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522/**************************************************************************
3523* qla2x00_timer
3524*
3525* Description:
3526* One second timer
3527*
3528* Context: Interrupt
3529***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003530void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003531qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 unsigned long cpu_flags = 0;
3534 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 int start_dpc = 0;
3536 int index;
3537 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05003538 int t;
Andrew Vasquez85880802009-12-15 21:29:46 -08003539 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003540 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003541 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08003542
Giridhar Malavalia9083012010-04-12 17:59:55 -07003543 if (IS_QLA82XX(ha))
3544 qla82xx_watchdog(vha);
3545
Andrew Vasquez85880802009-12-15 21:29:46 -08003546 /* Hardware read to raise pending EEH errors during mailbox waits. */
3547 if (!pci_channel_offline(ha->pdev))
3548 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 /*
3550 * Ports - Port down timer.
3551 *
3552 * Whenever, a port is in the LOST state we start decrementing its port
3553 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003554 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003555 */
3556 t = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003557 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558 if (fcport->port_type != FCT_TARGET)
3559 continue;
3560
3561 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
3562
3563 if (atomic_read(&fcport->port_down_timer) == 0)
3564 continue;
3565
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003566 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003568
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07003570 "%d remaining\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003571 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572 t, atomic_read(&fcport->port_down_timer)));
3573 }
3574 t++;
3575 } /* End of for fcport */
3576
Linus Torvalds1da177e2005-04-16 15:20:36 -07003577
3578 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003579 if (atomic_read(&vha->loop_down_timer) > 0 &&
3580 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
3581 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003583 if (atomic_read(&vha->loop_down_timer) ==
3584 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585
3586 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
3587 "queues before time expire\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003588 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003590 if (!IS_QLA2100(ha) && vha->link_down_timeout)
3591 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003593 /*
3594 * Schedule an ISP abort to return any FCP2-device
3595 * commands.
3596 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003597 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003598 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003599 spin_lock_irqsave(&ha->hardware_lock,
3600 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003601 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003602 for (index = 1;
3603 index < MAX_OUTSTANDING_COMMANDS;
3604 index++) {
3605 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05003606
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003607 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003608 if (!sp)
3609 continue;
Arun Easibad75002010-05-04 15:01:30 -07003610 if (sp->ctx && !IS_PROT_IO(sp))
Andrew Vasquezcf53b062009-08-20 11:06:04 -07003611 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003612 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003613 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003614 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003616 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003617 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003618 break;
3619 }
3620 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003621 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003622 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623 start_dpc++;
3624 }
3625
3626 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003627 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003628 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 DEBUG(printk("scsi(%ld): Loop down - "
3630 "aborting ISP.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003631 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632 qla_printk(KERN_WARNING, ha,
3633 "Loop down - aborting ISP.\n");
3634
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003635 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003636 }
3637 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07003638 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003639 vha->host_no,
3640 atomic_read(&vha->loop_down_timer)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641 }
3642
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08003643 /* Check if beacon LED needs to be blinked */
3644 if (ha->beacon_blink_led == 1) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003645 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08003646 start_dpc++;
3647 }
3648
Andrew Vasquez550bf572008-04-24 15:21:23 -07003649 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003650 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07003651 start_dpc++;
3652
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003654 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
3655 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
3656 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003658 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
3659 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07003660 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
3661 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003662 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
3663 test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
3664 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003665
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003666 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003667}
3668
Andrew Vasquez54333832005-11-09 15:49:04 -08003669/* Firmware interface routines. */
3670
Giridhar Malavalia9083012010-04-12 17:59:55 -07003671#define FW_BLOBS 8
Andrew Vasquez54333832005-11-09 15:49:04 -08003672#define FW_ISP21XX 0
3673#define FW_ISP22XX 1
3674#define FW_ISP2300 2
3675#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003676#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003677#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003678#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07003679#define FW_ISP82XX 7
Andrew Vasquez54333832005-11-09 15:49:04 -08003680
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003681#define FW_FILE_ISP21XX "ql2100_fw.bin"
3682#define FW_FILE_ISP22XX "ql2200_fw.bin"
3683#define FW_FILE_ISP2300 "ql2300_fw.bin"
3684#define FW_FILE_ISP2322 "ql2322_fw.bin"
3685#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003686#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003687#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07003688#define FW_FILE_ISP82XX "ql8200_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003689
Daniel Walkere1e82b62008-05-12 22:21:10 -07003690static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003691
3692static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003693 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
3694 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
3695 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
3696 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
3697 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003698 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003699 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07003700 { .name = FW_FILE_ISP82XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08003701};
3702
3703struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003704qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08003705{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003706 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08003707 struct fw_blob *blob;
3708
3709 blob = NULL;
3710 if (IS_QLA2100(ha)) {
3711 blob = &qla_fw_blobs[FW_ISP21XX];
3712 } else if (IS_QLA2200(ha)) {
3713 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003714 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003715 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003716 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003717 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003718 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003719 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003720 } else if (IS_QLA25XX(ha)) {
3721 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003722 } else if (IS_QLA81XX(ha)) {
3723 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07003724 } else if (IS_QLA82XX(ha)) {
3725 blob = &qla_fw_blobs[FW_ISP82XX];
Andrew Vasquez54333832005-11-09 15:49:04 -08003726 }
3727
Daniel Walkere1e82b62008-05-12 22:21:10 -07003728 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003729 if (blob->fw)
3730 goto out;
3731
3732 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
3733 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003734 "(%s).\n", vha->host_no, blob->name));
Andrew Vasquez54333832005-11-09 15:49:04 -08003735 blob->fw = NULL;
3736 blob = NULL;
3737 goto out;
3738 }
3739
3740out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07003741 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003742 return blob;
3743}
3744
3745static void
3746qla2x00_release_firmware(void)
3747{
3748 int idx;
3749
Daniel Walkere1e82b62008-05-12 22:21:10 -07003750 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003751 for (idx = 0; idx < FW_BLOBS; idx++)
3752 if (qla_fw_blobs[idx].fw)
3753 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07003754 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003755}
3756
Seokmann Ju14e660e2007-09-20 14:07:36 -07003757static pci_ers_result_t
3758qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3759{
Andrew Vasquez85880802009-12-15 21:29:46 -08003760 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
3761 struct qla_hw_data *ha = vha->hw;
3762
3763 DEBUG2(qla_printk(KERN_WARNING, ha, "error_detected:state %x\n",
3764 state));
Seokmann Jub9b12f72009-03-24 09:08:18 -07003765
Seokmann Ju14e660e2007-09-20 14:07:36 -07003766 switch (state) {
3767 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08003768 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003769 return PCI_ERS_RESULT_CAN_RECOVER;
3770 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08003771 ha->flags.eeh_busy = 1;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003772 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003773 pci_disable_device(pdev);
3774 return PCI_ERS_RESULT_NEED_RESET;
3775 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08003776 ha->flags.pci_channel_io_perm_failure = 1;
3777 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003778 return PCI_ERS_RESULT_DISCONNECT;
3779 }
3780 return PCI_ERS_RESULT_NEED_RESET;
3781}
3782
3783static pci_ers_result_t
3784qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
3785{
3786 int risc_paused = 0;
3787 uint32_t stat;
3788 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003789 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3790 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003791 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3792 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
3793
3794 spin_lock_irqsave(&ha->hardware_lock, flags);
3795 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
3796 stat = RD_REG_DWORD(&reg->hccr);
3797 if (stat & HCCR_RISC_PAUSE)
3798 risc_paused = 1;
3799 } else if (IS_QLA23XX(ha)) {
3800 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
3801 if (stat & HSR_RISC_PAUSED)
3802 risc_paused = 1;
3803 } else if (IS_FWI2_CAPABLE(ha)) {
3804 stat = RD_REG_DWORD(&reg24->host_status);
3805 if (stat & HSRX_RISC_PAUSED)
3806 risc_paused = 1;
3807 }
3808 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3809
3810 if (risc_paused) {
3811 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
3812 "Dumping firmware!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003813 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003814
3815 return PCI_ERS_RESULT_NEED_RESET;
3816 } else
3817 return PCI_ERS_RESULT_RECOVERED;
3818}
3819
3820static pci_ers_result_t
3821qla2xxx_pci_slot_reset(struct pci_dev *pdev)
3822{
3823 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003824 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3825 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003826 struct rsp_que *rsp;
3827 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003828
Andrew Vasquez85880802009-12-15 21:29:46 -08003829 DEBUG17(qla_printk(KERN_WARNING, ha, "slot_reset\n"));
3830
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003831 /* Workaround: qla2xxx driver which access hardware earlier
3832 * needs error state to be pci_channel_io_online.
3833 * Otherwise mailbox command timesout.
3834 */
3835 pdev->error_state = pci_channel_io_normal;
3836
3837 pci_restore_state(pdev);
3838
Richard Lary8c1496b2010-02-18 10:07:29 -08003839 /* pci_restore_state() clears the saved_state flag of the device
3840 * save restored state which resets saved_state flag
3841 */
3842 pci_save_state(pdev);
3843
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11003844 if (ha->mem_only)
3845 rc = pci_enable_device_mem(pdev);
3846 else
3847 rc = pci_enable_device(pdev);
3848
3849 if (rc) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07003850 qla_printk(KERN_WARNING, ha,
3851 "Can't re-enable PCI device after reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07003852 return ret;
3853 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07003854
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003855 rsp = ha->rsp_q_map[0];
3856 if (qla2x00_request_irqs(ha, rsp))
3857 return ret;
3858
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003859 if (ha->isp_ops->pci_config(base_vha))
Seokmann Ju14e660e2007-09-20 14:07:36 -07003860 return ret;
3861
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003862 while (ha->flags.mbox_busy && retries--)
3863 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08003864
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003865 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003866 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07003867 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003868 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003869
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003870
Andrew Vasquez85880802009-12-15 21:29:46 -08003871 DEBUG17(qla_printk(KERN_WARNING, ha,
3872 "slot_reset-return:ret=%x\n", ret));
3873
Seokmann Ju14e660e2007-09-20 14:07:36 -07003874 return ret;
3875}
3876
3877static void
3878qla2xxx_pci_resume(struct pci_dev *pdev)
3879{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003880 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3881 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003882 int ret;
3883
Andrew Vasquez85880802009-12-15 21:29:46 -08003884 DEBUG17(qla_printk(KERN_WARNING, ha, "pci_resume\n"));
3885
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003886 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003887 if (ret != QLA_SUCCESS) {
3888 qla_printk(KERN_ERR, ha,
3889 "the device failed to resume I/O "
3890 "from slot/link_reset");
3891 }
Andrew Vasquez85880802009-12-15 21:29:46 -08003892
Lalit Chandivade3e46f032010-05-04 15:01:23 -07003893 pci_cleanup_aer_uncorrect_error_status(pdev);
3894
Andrew Vasquez85880802009-12-15 21:29:46 -08003895 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003896}
3897
3898static struct pci_error_handlers qla2xxx_err_handler = {
3899 .error_detected = qla2xxx_pci_error_detected,
3900 .mmio_enabled = qla2xxx_pci_mmio_enabled,
3901 .slot_reset = qla2xxx_pci_slot_reset,
3902 .resume = qla2xxx_pci_resume,
3903};
3904
Andrew Vasquez54333832005-11-09 15:49:04 -08003905static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07003906 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
3907 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
3908 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
3909 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
3910 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
3911 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
3912 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
3913 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
3914 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003915 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07003916 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
3917 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003918 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003919 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07003920 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Andrew Vasquez54333832005-11-09 15:49:04 -08003921 { 0 },
3922};
3923MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
3924
Andrew Vasquezfca29702005-07-06 10:31:47 -07003925static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07003926 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06003927 .driver = {
3928 .owner = THIS_MODULE,
3929 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07003930 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003931 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08003932 .remove = qla2x00_remove_one,
Seokmann Ju14e660e2007-09-20 14:07:36 -07003933 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07003934};
3935
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07003936static struct file_operations apidev_fops = {
3937 .owner = THIS_MODULE,
3938};
3939
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940/**
3941 * qla2x00_module_init - Module initialization.
3942 **/
3943static int __init
3944qla2x00_module_init(void)
3945{
Andrew Vasquezfca29702005-07-06 10:31:47 -07003946 int ret = 0;
3947
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003949 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09003950 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951 if (srb_cachep == NULL) {
3952 printk(KERN_ERR
3953 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3954 return -ENOMEM;
3955 }
3956
3957 /* Derive version string. */
3958 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07003959 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07003960 strcat(qla2x00_version_str, "-debug");
3961
Andrew Vasquez1c97a122005-04-21 16:13:36 -04003962 qla2xxx_transport_template =
3963 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003964 if (!qla2xxx_transport_template) {
3965 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003967 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07003968
3969 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
3970 if (apidev_major < 0) {
3971 printk(KERN_WARNING "qla2xxx: Unable to register char device "
3972 "%s\n", QLA2XXX_APIDEV);
3973 }
3974
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003975 qla2xxx_transport_vport_template =
3976 fc_attach_transport(&qla2xxx_transport_vport_functions);
3977 if (!qla2xxx_transport_vport_template) {
3978 kmem_cache_destroy(srb_cachep);
3979 fc_release_transport(qla2xxx_transport_template);
3980 return -ENODEV;
3981 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07003983 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
3984 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003985 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003986 if (ret) {
3987 kmem_cache_destroy(srb_cachep);
3988 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003989 fc_release_transport(qla2xxx_transport_vport_template);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003990 }
3991 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992}
3993
3994/**
3995 * qla2x00_module_exit - Module cleanup.
3996 **/
3997static void __exit
3998qla2x00_module_exit(void)
3999{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004000 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07004001 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08004002 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04004003 kmem_cache_destroy(srb_cachep);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004004 if (ctx_cachep)
4005 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004007 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008}
4009
4010module_init(qla2x00_module_init);
4011module_exit(qla2x00_module_exit);
4012
4013MODULE_AUTHOR("QLogic Corporation");
4014MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
4015MODULE_LICENSE("GPL");
4016MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07004017MODULE_FIRMWARE(FW_FILE_ISP21XX);
4018MODULE_FIRMWARE(FW_FILE_ISP22XX);
4019MODULE_FIRMWARE(FW_FILE_ISP2300);
4020MODULE_FIRMWARE(FW_FILE_ISP2322);
4021MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08004022MODULE_FIRMWARE(FW_FILE_ISP25XX);