blob: e1782f7714003f10a6b7223d0788cb8bf32c7c92 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Giridhar Malavalide7c5d02010-07-23 15:28:36 +05003 * Copyright (c) 2003-2010 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 "
Joe Perchesae682302010-08-10 18:01:21 -0700118 "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 Malavali69078692010-05-28 15:08:28 -0700143int ql2xdbwr = 1;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700144module_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 */
Andrew Vasquez3dbe7562010-07-23 15:28:37 +0500704static int
Lalit Chandivade86fbee82010-05-04 15:01:32 -0700705qla2x00_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
Giridhar Malavali4d78c972010-07-23 15:28:35 +0500906int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800907qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Giridhar Malavali4d78c972010-07-23 15:28:35 +0500908 unsigned int l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909{
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800910 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700911 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800912 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800913 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +0500914 srb_t *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Andrew Vasquez523ec772008-04-03 13:13:24 -0700916 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800917
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800918 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700919 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800920 for (cnt = 1; status == QLA_SUCCESS &&
921 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
922 sp = req->outstanding_cmds[cnt];
923 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700924 continue;
Arun Easibad75002010-05-04 15:01:30 -0700925 if ((sp->ctx) && !IS_PROT_IO(sp))
Andrew Vasquezcf53b062009-08-20 11:06:04 -0700926 continue;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800927 if (vha->vp_idx != sp->fcport->vha->vp_idx)
928 continue;
929 match = 0;
930 switch (type) {
931 case WAIT_HOST:
932 match = 1;
933 break;
934 case WAIT_TARGET:
935 match = sp->cmd->device->id == t;
936 break;
937 case WAIT_LUN:
938 match = (sp->cmd->device->id == t &&
939 sp->cmd->device->lun == l);
940 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800942 if (!match)
943 continue;
944
945 spin_unlock_irqrestore(&ha->hardware_lock, flags);
946 status = qla2x00_eh_wait_on_command(sp->cmd);
947 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800949 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700950
951 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952}
953
Andrew Vasquez523ec772008-04-03 13:13:24 -0700954static char *reset_errors[] = {
955 "HBA not online",
956 "HBA not ready",
957 "Task management failed",
958 "Waiting for command completions",
959};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
Andrew Vasquez523ec772008-04-03 13:13:24 -0700961static int
962__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700963 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -0700964{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800965 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700966 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
967 int err;
968
Christof Schmitt65d430f2009-10-30 17:59:29 +0100969 fc_block_scsi_eh(cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700970
971 if (!fcport)
972 return FAILED;
973
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800974 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
975 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700976
977 err = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800978 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700979 goto eh_reset_failed;
980 err = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800981 if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700982 goto eh_reset_failed;
983 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700984 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
985 != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700986 goto eh_reset_failed;
987 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800988 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Giridhar Malavali4d78c972010-07-23 15:28:35 +0500989 cmd->device->lun, type) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700990 goto eh_reset_failed;
991
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800992 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
993 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700994
995 return SUCCESS;
996
Giridhar Malavali4d78c972010-07-23 15:28:35 +0500997eh_reset_failed:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800998 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
999 , vha->host_no, cmd->device->id, cmd->device->lun, name,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001000 reset_errors[err]);
1001 return FAILED;
1002}
1003
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001004static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1006{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001007 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1008 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
Andrew Vasquez523ec772008-04-03 13:13:24 -07001010 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1011 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012}
1013
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001015qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001017 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1018 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019
Andrew Vasquez523ec772008-04-03 13:13:24 -07001020 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1021 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022}
1023
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024/**************************************************************************
1025* qla2xxx_eh_bus_reset
1026*
1027* Description:
1028* The bus reset function will reset the bus and abort any executing
1029* commands.
1030*
1031* Input:
1032* cmd = Linux SCSI command packet of the command that cause the
1033* bus reset.
1034*
1035* Returns:
1036* SUCCESS/FAILURE (defined as macro in scsi.h).
1037*
1038**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001039static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1041{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001042 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001043 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001044 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001045 unsigned int id, lun;
1046 unsigned long serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
Christof Schmitt65d430f2009-10-30 17:59:29 +01001048 fc_block_scsi_eh(cmd);
Andrew Vasquez07db5182006-10-02 12:00:49 -07001049
f4f051e2005-04-17 15:02:26 -05001050 id = cmd->device->id;
1051 lun = cmd->device->lun;
1052 serial = cmd->serial_number;
1053
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -07001054 if (!fcport)
f4f051e2005-04-17 15:02:26 -05001055 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001057 qla_printk(KERN_INFO, vha->hw,
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001058 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001060 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -05001062 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 }
1064
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001065 if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
1066 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001067 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 }
f4f051e2005-04-17 15:02:26 -05001069 if (ret == FAILED)
1070 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001072 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001073 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Andrew Vasquez523ec772008-04-03 13:13:24 -07001074 QLA_SUCCESS)
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001075 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
f4f051e2005-04-17 15:02:26 -05001077eh_bus_reset_done:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001078 qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -05001079 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
f4f051e2005-04-17 15:02:26 -05001081 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082}
1083
1084/**************************************************************************
1085* qla2xxx_eh_host_reset
1086*
1087* Description:
1088* The reset function will reset the Adapter.
1089*
1090* Input:
1091* cmd = Linux SCSI command packet of the command that cause the
1092* adapter reset.
1093*
1094* Returns:
1095* Either SUCCESS or FAILED.
1096*
1097* Note:
1098**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001099static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1101{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001102 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001103 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001104 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001105 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001106 unsigned int id, lun;
1107 unsigned long serial;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001108 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109
Christof Schmitt65d430f2009-10-30 17:59:29 +01001110 fc_block_scsi_eh(cmd);
Andrew Vasquez07db5182006-10-02 12:00:49 -07001111
f4f051e2005-04-17 15:02:26 -05001112 id = cmd->device->id;
1113 lun = cmd->device->lun;
1114 serial = cmd->serial_number;
1115
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -07001116 if (!fcport)
f4f051e2005-04-17 15:02:26 -05001117 return ret;
1118
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 qla_printk(KERN_INFO, ha,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001120 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001122 if (qla2x00_wait_for_reset_ready(vha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001123 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
1125 /*
1126 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001127 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 * be completed and then issue big hammer.Otherwise
1129 * it may cause I/O failure as big hammer marks the
1130 * devices as lost kicking of the port_down_timer
1131 * while dpc is stuck for the mailbox to complete.
1132 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001133 qla2x00_wait_for_loop_ready(vha);
1134 if (vha != base_vha) {
1135 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001136 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001137 } else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001138 if (IS_QLA82XX(vha->hw)) {
1139 if (!qla82xx_fcoe_ctx_reset(vha)) {
1140 /* Ctx reset success */
1141 ret = SUCCESS;
1142 goto eh_host_reset_lock;
1143 }
1144 /* fall thru if ctx reset failed */
1145 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001146 if (ha->wq)
1147 flush_workqueue(ha->wq);
1148
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001149 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001150 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001151 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1152 /* failed. schedule dpc to try */
1153 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1154
1155 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1156 goto eh_host_reset_lock;
1157 }
1158 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001159 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001161 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001162 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001163 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001164 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
f4f051e2005-04-17 15:02:26 -05001166eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -05001167 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1168 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
f4f051e2005-04-17 15:02:26 -05001170 return ret;
1171}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
1173/*
1174* qla2x00_loop_reset
1175* Issue loop reset.
1176*
1177* Input:
1178* ha = adapter block pointer.
1179*
1180* Returns:
1181* 0 = success
1182*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001183int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001184qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001186 int ret;
bdf79622005-04-17 15:06:53 -05001187 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001188 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001190 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001191 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1192 if (fcport->port_type != FCT_TARGET)
1193 continue;
1194
1195 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1196 if (ret != QLA_SUCCESS) {
1197 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1198 "target_reset=%d d_id=%x.\n", __func__,
1199 vha->host_no, ret, fcport->d_id.b24));
1200 }
1201 }
1202 }
1203
Giridhar Malavalia9083012010-04-12 17:59:55 -07001204 if (ha->flags.enable_lip_full_login && !IS_QLA8XXX_TYPE(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001205 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001206 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001207 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001208 "full_login_lip=%d.\n", __func__, vha->host_no,
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001209 ret));
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001210 }
1211 atomic_set(&vha->loop_state, LOOP_DOWN);
1212 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1213 qla2x00_mark_all_devices_lost(vha, 0);
1214 qla2x00_wait_for_loop_ready(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 }
1216
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001217 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001218 ret = qla2x00_lip_reset(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001219 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001220 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001221 "lip_reset=%d.\n", __func__, vha->host_no, ret));
1222 } else
1223 qla2x00_wait_for_loop_ready(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001224 }
1225
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001227 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001229 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230}
1231
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001232void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001233qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001234{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001235 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001236 unsigned long flags;
1237 srb_t *sp;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001238 struct srb_ctx *ctx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001239 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001240 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001241
1242 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001243 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001244 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001245 if (!req)
1246 continue;
1247 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1248 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001249 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001250 req->outstanding_cmds[cnt] = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001251 if (!sp->ctx ||
Arun Easibad75002010-05-04 15:01:30 -07001252 (sp->flags & SRB_FCP_CMND_DMA_VALID) ||
1253 IS_PROT_IO(sp)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07001254 sp->cmd->result = res;
1255 qla2x00_sp_compl(ha, sp);
1256 } else {
1257 ctx = sp->ctx;
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001258 if (ctx->type == SRB_LOGIN_CMD ||
1259 ctx->type == SRB_LOGOUT_CMD) {
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001260 ctx->u.iocb_cmd->free(sp);
Giridhar Malavalidb3ad7f2010-02-18 10:07:24 -08001261 } else {
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001262 struct fc_bsg_job *bsg_job =
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001263 ctx->u.bsg_job;
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001264 if (bsg_job->request->msgcode
1265 == FC_BSG_HST_CT)
Giridhar Malavalidb3ad7f2010-02-18 10:07:24 -08001266 kfree(sp->fcport);
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001267 bsg_job->req->errors = 0;
1268 bsg_job->reply->result = res;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001269 bsg_job->job_done(bsg_job);
Giridhar Malavalidb3ad7f2010-02-18 10:07:24 -08001270 kfree(sp->ctx);
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001271 mempool_free(sp,
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001272 ha->srb_mempool);
Giridhar Malavalidb3ad7f2010-02-18 10:07:24 -08001273 }
Andrew Vasquezac280b62009-08-20 11:06:05 -07001274 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001275 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001276 }
1277 }
1278 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1279}
1280
f4f051e2005-04-17 15:02:26 -05001281static int
1282qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283{
bdf79622005-04-17 15:06:53 -05001284 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001286 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001287 return -ENXIO;
1288
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001289 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001290
1291 return 0;
1292}
1293
1294static int
1295qla2xxx_slave_configure(struct scsi_device *sdev)
1296{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001297 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001298 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001299
f4f051e2005-04-17 15:02:26 -05001300 if (sdev->tagged_supported)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001301 scsi_activate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001303 scsi_deactivate_tcq(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001304 return 0;
1305}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
f4f051e2005-04-17 15:02:26 -05001307static void
1308qla2xxx_slave_destroy(struct scsi_device *sdev)
1309{
1310 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311}
1312
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001313static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
1314{
1315 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1316
1317 if (!scsi_track_queue_full(sdev, qdepth))
1318 return;
1319
1320 DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw,
1321 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
1322 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
1323 sdev->queue_depth));
1324}
1325
1326static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
1327{
1328 fc_port_t *fcport = sdev->hostdata;
1329 struct scsi_qla_host *vha = fcport->vha;
1330 struct qla_hw_data *ha = vha->hw;
1331 struct req_que *req = NULL;
1332
1333 req = vha->req;
1334 if (!req)
1335 return;
1336
1337 if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
1338 return;
1339
1340 if (sdev->ordered_tags)
1341 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
1342 else
1343 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
1344
1345 DEBUG2(qla_printk(KERN_INFO, ha,
1346 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
1347 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
1348 sdev->queue_depth));
1349}
1350
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001351static int
Mike Christiee881a172009-10-15 17:46:39 -07001352qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001353{
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001354 switch (reason) {
1355 case SCSI_QDEPTH_DEFAULT:
1356 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1357 break;
1358 case SCSI_QDEPTH_QFULL:
1359 qla2x00_handle_queue_full(sdev, qdepth);
1360 break;
1361 case SCSI_QDEPTH_RAMP_UP:
1362 qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
1363 break;
1364 default:
Roel Kluin08002af2010-01-29 11:25:19 +01001365 return -EOPNOTSUPP;
Giridhar Malavalic45dd302009-12-02 10:36:54 -08001366 }
Mike Christiee881a172009-10-15 17:46:39 -07001367
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001368 return sdev->queue_depth;
1369}
1370
1371static int
1372qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1373{
1374 if (sdev->tagged_supported) {
1375 scsi_set_tag_type(sdev, tag_type);
1376 if (tag_type)
1377 scsi_activate_tcq(sdev, sdev->queue_depth);
1378 else
1379 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1380 } else
1381 tag_type = 0;
1382
1383 return tag_type;
1384}
1385
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386/**
1387 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1388 * @ha: HA context
1389 *
1390 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1391 * supported addressing method.
1392 */
1393static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001394qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001396 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398
Yang Hongyang6a355282009-04-06 19:01:13 -07001399 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001400 /* Any upper-dword bits set? */
1401 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001402 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001403 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001405 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1406 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001407 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001410
Yang Hongyang284901a2009-04-06 19:01:15 -07001411 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1412 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413}
1414
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001415static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001416qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001417{
1418 unsigned long flags = 0;
1419 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1420
1421 spin_lock_irqsave(&ha->hardware_lock, flags);
1422 ha->interrupts_on = 1;
1423 /* enable risc and host interrupts */
1424 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1425 RD_REG_WORD(&reg->ictrl);
1426 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1427
1428}
1429
1430static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001431qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001432{
1433 unsigned long flags = 0;
1434 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1435
1436 spin_lock_irqsave(&ha->hardware_lock, flags);
1437 ha->interrupts_on = 0;
1438 /* disable risc and host interrupts */
1439 WRT_REG_WORD(&reg->ictrl, 0);
1440 RD_REG_WORD(&reg->ictrl);
1441 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1442}
1443
1444static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001445qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001446{
1447 unsigned long flags = 0;
1448 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1449
1450 spin_lock_irqsave(&ha->hardware_lock, flags);
1451 ha->interrupts_on = 1;
1452 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1453 RD_REG_DWORD(&reg->ictrl);
1454 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1455}
1456
1457static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001458qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001459{
1460 unsigned long flags = 0;
1461 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1462
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001463 if (IS_NOPOLLING_TYPE(ha))
1464 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001465 spin_lock_irqsave(&ha->hardware_lock, flags);
1466 ha->interrupts_on = 0;
1467 WRT_REG_DWORD(&reg->ictrl, 0);
1468 RD_REG_DWORD(&reg->ictrl);
1469 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1470}
1471
1472static struct isp_operations qla2100_isp_ops = {
1473 .pci_config = qla2100_pci_config,
1474 .reset_chip = qla2x00_reset_chip,
1475 .chip_diag = qla2x00_chip_diag,
1476 .config_rings = qla2x00_config_rings,
1477 .reset_adapter = qla2x00_reset_adapter,
1478 .nvram_config = qla2x00_nvram_config,
1479 .update_fw_options = qla2x00_update_fw_options,
1480 .load_risc = qla2x00_load_risc,
1481 .pci_info_str = qla2x00_pci_info_str,
1482 .fw_version_str = qla2x00_fw_version_str,
1483 .intr_handler = qla2100_intr_handler,
1484 .enable_intrs = qla2x00_enable_intrs,
1485 .disable_intrs = qla2x00_disable_intrs,
1486 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001487 .target_reset = qla2x00_abort_target,
1488 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001489 .fabric_login = qla2x00_login_fabric,
1490 .fabric_logout = qla2x00_fabric_logout,
1491 .calc_req_entries = qla2x00_calc_iocbs_32,
1492 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1493 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1494 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1495 .read_nvram = qla2x00_read_nvram_data,
1496 .write_nvram = qla2x00_write_nvram_data,
1497 .fw_dump = qla2100_fw_dump,
1498 .beacon_on = NULL,
1499 .beacon_off = NULL,
1500 .beacon_blink = NULL,
1501 .read_optrom = qla2x00_read_optrom_data,
1502 .write_optrom = qla2x00_write_optrom_data,
1503 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001504 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001505 .abort_isp = qla2x00_abort_isp,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001506};
1507
1508static struct isp_operations qla2300_isp_ops = {
1509 .pci_config = qla2300_pci_config,
1510 .reset_chip = qla2x00_reset_chip,
1511 .chip_diag = qla2x00_chip_diag,
1512 .config_rings = qla2x00_config_rings,
1513 .reset_adapter = qla2x00_reset_adapter,
1514 .nvram_config = qla2x00_nvram_config,
1515 .update_fw_options = qla2x00_update_fw_options,
1516 .load_risc = qla2x00_load_risc,
1517 .pci_info_str = qla2x00_pci_info_str,
1518 .fw_version_str = qla2x00_fw_version_str,
1519 .intr_handler = qla2300_intr_handler,
1520 .enable_intrs = qla2x00_enable_intrs,
1521 .disable_intrs = qla2x00_disable_intrs,
1522 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001523 .target_reset = qla2x00_abort_target,
1524 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001525 .fabric_login = qla2x00_login_fabric,
1526 .fabric_logout = qla2x00_fabric_logout,
1527 .calc_req_entries = qla2x00_calc_iocbs_32,
1528 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1529 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1530 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1531 .read_nvram = qla2x00_read_nvram_data,
1532 .write_nvram = qla2x00_write_nvram_data,
1533 .fw_dump = qla2300_fw_dump,
1534 .beacon_on = qla2x00_beacon_on,
1535 .beacon_off = qla2x00_beacon_off,
1536 .beacon_blink = qla2x00_beacon_blink,
1537 .read_optrom = qla2x00_read_optrom_data,
1538 .write_optrom = qla2x00_write_optrom_data,
1539 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001540 .start_scsi = qla2x00_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001541 .abort_isp = qla2x00_abort_isp,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001542};
1543
1544static struct isp_operations qla24xx_isp_ops = {
1545 .pci_config = qla24xx_pci_config,
1546 .reset_chip = qla24xx_reset_chip,
1547 .chip_diag = qla24xx_chip_diag,
1548 .config_rings = qla24xx_config_rings,
1549 .reset_adapter = qla24xx_reset_adapter,
1550 .nvram_config = qla24xx_nvram_config,
1551 .update_fw_options = qla24xx_update_fw_options,
1552 .load_risc = qla24xx_load_risc,
1553 .pci_info_str = qla24xx_pci_info_str,
1554 .fw_version_str = qla24xx_fw_version_str,
1555 .intr_handler = qla24xx_intr_handler,
1556 .enable_intrs = qla24xx_enable_intrs,
1557 .disable_intrs = qla24xx_disable_intrs,
1558 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001559 .target_reset = qla24xx_abort_target,
1560 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001561 .fabric_login = qla24xx_login_fabric,
1562 .fabric_logout = qla24xx_fabric_logout,
1563 .calc_req_entries = NULL,
1564 .build_iocbs = NULL,
1565 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1566 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1567 .read_nvram = qla24xx_read_nvram_data,
1568 .write_nvram = qla24xx_write_nvram_data,
1569 .fw_dump = qla24xx_fw_dump,
1570 .beacon_on = qla24xx_beacon_on,
1571 .beacon_off = qla24xx_beacon_off,
1572 .beacon_blink = qla24xx_beacon_blink,
1573 .read_optrom = qla24xx_read_optrom_data,
1574 .write_optrom = qla24xx_write_optrom_data,
1575 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001576 .start_scsi = qla24xx_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001577 .abort_isp = qla2x00_abort_isp,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001578};
1579
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001580static struct isp_operations qla25xx_isp_ops = {
1581 .pci_config = qla25xx_pci_config,
1582 .reset_chip = qla24xx_reset_chip,
1583 .chip_diag = qla24xx_chip_diag,
1584 .config_rings = qla24xx_config_rings,
1585 .reset_adapter = qla24xx_reset_adapter,
1586 .nvram_config = qla24xx_nvram_config,
1587 .update_fw_options = qla24xx_update_fw_options,
1588 .load_risc = qla24xx_load_risc,
1589 .pci_info_str = qla24xx_pci_info_str,
1590 .fw_version_str = qla24xx_fw_version_str,
1591 .intr_handler = qla24xx_intr_handler,
1592 .enable_intrs = qla24xx_enable_intrs,
1593 .disable_intrs = qla24xx_disable_intrs,
1594 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001595 .target_reset = qla24xx_abort_target,
1596 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001597 .fabric_login = qla24xx_login_fabric,
1598 .fabric_logout = qla24xx_fabric_logout,
1599 .calc_req_entries = NULL,
1600 .build_iocbs = NULL,
1601 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1602 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1603 .read_nvram = qla25xx_read_nvram_data,
1604 .write_nvram = qla25xx_write_nvram_data,
1605 .fw_dump = qla25xx_fw_dump,
1606 .beacon_on = qla24xx_beacon_on,
1607 .beacon_off = qla24xx_beacon_off,
1608 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001609 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001610 .write_optrom = qla24xx_write_optrom_data,
1611 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07001612 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001613 .abort_isp = qla2x00_abort_isp,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001614};
1615
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001616static struct isp_operations qla81xx_isp_ops = {
1617 .pci_config = qla25xx_pci_config,
1618 .reset_chip = qla24xx_reset_chip,
1619 .chip_diag = qla24xx_chip_diag,
1620 .config_rings = qla24xx_config_rings,
1621 .reset_adapter = qla24xx_reset_adapter,
1622 .nvram_config = qla81xx_nvram_config,
1623 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001624 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001625 .pci_info_str = qla24xx_pci_info_str,
1626 .fw_version_str = qla24xx_fw_version_str,
1627 .intr_handler = qla24xx_intr_handler,
1628 .enable_intrs = qla24xx_enable_intrs,
1629 .disable_intrs = qla24xx_disable_intrs,
1630 .abort_command = qla24xx_abort_command,
1631 .target_reset = qla24xx_abort_target,
1632 .lun_reset = qla24xx_lun_reset,
1633 .fabric_login = qla24xx_login_fabric,
1634 .fabric_logout = qla24xx_fabric_logout,
1635 .calc_req_entries = NULL,
1636 .build_iocbs = NULL,
1637 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1638 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07001639 .read_nvram = NULL,
1640 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001641 .fw_dump = qla81xx_fw_dump,
1642 .beacon_on = qla24xx_beacon_on,
1643 .beacon_off = qla24xx_beacon_off,
1644 .beacon_blink = qla24xx_beacon_blink,
1645 .read_optrom = qla25xx_read_optrom_data,
1646 .write_optrom = qla24xx_write_optrom_data,
1647 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07001648 .start_scsi = qla24xx_dif_start_scsi,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001649 .abort_isp = qla2x00_abort_isp,
1650};
1651
1652static struct isp_operations qla82xx_isp_ops = {
1653 .pci_config = qla82xx_pci_config,
1654 .reset_chip = qla82xx_reset_chip,
1655 .chip_diag = qla24xx_chip_diag,
1656 .config_rings = qla82xx_config_rings,
1657 .reset_adapter = qla24xx_reset_adapter,
1658 .nvram_config = qla81xx_nvram_config,
1659 .update_fw_options = qla24xx_update_fw_options,
1660 .load_risc = qla82xx_load_risc,
1661 .pci_info_str = qla82xx_pci_info_str,
1662 .fw_version_str = qla24xx_fw_version_str,
1663 .intr_handler = qla82xx_intr_handler,
1664 .enable_intrs = qla82xx_enable_intrs,
1665 .disable_intrs = qla82xx_disable_intrs,
1666 .abort_command = qla24xx_abort_command,
1667 .target_reset = qla24xx_abort_target,
1668 .lun_reset = qla24xx_lun_reset,
1669 .fabric_login = qla24xx_login_fabric,
1670 .fabric_logout = qla24xx_fabric_logout,
1671 .calc_req_entries = NULL,
1672 .build_iocbs = NULL,
1673 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1674 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1675 .read_nvram = qla24xx_read_nvram_data,
1676 .write_nvram = qla24xx_write_nvram_data,
1677 .fw_dump = qla24xx_fw_dump,
1678 .beacon_on = qla24xx_beacon_on,
1679 .beacon_off = qla24xx_beacon_off,
1680 .beacon_blink = qla24xx_beacon_blink,
1681 .read_optrom = qla82xx_read_optrom_data,
1682 .write_optrom = qla82xx_write_optrom_data,
1683 .get_flash_version = qla24xx_get_flash_version,
1684 .start_scsi = qla82xx_start_scsi,
1685 .abort_isp = qla82xx_abort_isp,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001686};
1687
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001688static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001689qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001690{
1691 ha->device_type = DT_EXTENDED_IDS;
1692 switch (ha->pdev->device) {
1693 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1694 ha->device_type |= DT_ISP2100;
1695 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001696 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001697 break;
1698 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1699 ha->device_type |= DT_ISP2200;
1700 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001701 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001702 break;
1703 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1704 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001705 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001706 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001707 break;
1708 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1709 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001710 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001711 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001712 break;
1713 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1714 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001715 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001716 if (ha->pdev->subsystem_vendor == 0x1028 &&
1717 ha->pdev->subsystem_device == 0x0170)
1718 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001719 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001720 break;
1721 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1722 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001723 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001724 break;
1725 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1726 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001727 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001728 break;
1729 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1730 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001731 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001732 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001733 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001734 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001735 break;
1736 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1737 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001738 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001739 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001740 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001741 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001742 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001743 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1744 ha->device_type |= DT_ISP8432;
1745 ha->device_type |= DT_ZIO_SUPPORTED;
1746 ha->device_type |= DT_FWI2;
1747 ha->device_type |= DT_IIDMA;
1748 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1749 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001750 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1751 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001752 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001753 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001754 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001755 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1756 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001757 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001758 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001759 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001760 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1761 ha->device_type |= DT_ISP2532;
1762 ha->device_type |= DT_ZIO_SUPPORTED;
1763 ha->device_type |= DT_FWI2;
1764 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001765 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1766 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001767 case PCI_DEVICE_ID_QLOGIC_ISP8001:
1768 ha->device_type |= DT_ISP8001;
1769 ha->device_type |= DT_ZIO_SUPPORTED;
1770 ha->device_type |= DT_FWI2;
1771 ha->device_type |= DT_IIDMA;
1772 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1773 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001774 case PCI_DEVICE_ID_QLOGIC_ISP8021:
1775 ha->device_type |= DT_ISP8021;
1776 ha->device_type |= DT_ZIO_SUPPORTED;
1777 ha->device_type |= DT_FWI2;
1778 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1779 /* Initialize 82XX ISP flags */
1780 qla82xx_init_flags(ha);
1781 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001782 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07001783
Giridhar Malavalia9083012010-04-12 17:59:55 -07001784 if (IS_QLA82XX(ha))
1785 ha->port_no = !(ha->portnum & 1);
1786 else
1787 /* Get adapter physical port no from interrupt pin register. */
1788 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
1789
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07001790 if (ha->port_no & 1)
1791 ha->flags.port0 = 1;
1792 else
1793 ha->flags.port0 = 0;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001794}
1795
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001797qla2x00_iospace_config(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798{
Andrew Vasquez37765412008-01-17 09:02:09 -08001799 resource_size_t pio;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001800 uint16_t msix;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001801 int cpus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802
Giridhar Malavalia9083012010-04-12 17:59:55 -07001803 if (IS_QLA82XX(ha))
1804 return qla82xx_iospace_config(ha);
1805
Andrew Vasquez285d0322007-10-19 15:59:17 -07001806 if (pci_request_selected_regions(ha->pdev, ha->bars,
1807 QLA2XXX_DRIVER_NAME)) {
1808 qla_printk(KERN_WARNING, ha,
1809 "Failed to reserve PIO/MMIO regions (%s)\n",
1810 pci_name(ha->pdev));
1811
1812 goto iospace_error_exit;
1813 }
1814 if (!(ha->bars & 1))
1815 goto skip_pio;
1816
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1818 pio = pci_resource_start(ha->pdev, 0);
Andrew Vasquez37765412008-01-17 09:02:09 -08001819 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1820 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 qla_printk(KERN_WARNING, ha,
1822 "Invalid PCI I/O region size (%s)...\n",
1823 pci_name(ha->pdev));
1824 pio = 0;
1825 }
1826 } else {
1827 qla_printk(KERN_WARNING, ha,
1828 "region #0 not a PIO resource (%s)...\n",
1829 pci_name(ha->pdev));
1830 pio = 0;
1831 }
Andrew Vasquez285d0322007-10-19 15:59:17 -07001832 ha->pio_address = pio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833
Andrew Vasquez285d0322007-10-19 15:59:17 -07001834skip_pio:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 /* Use MMIO operations for all accesses. */
Andrew Vasquez37765412008-01-17 09:02:09 -08001836 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 qla_printk(KERN_ERR, ha,
Andrew Vasquez37765412008-01-17 09:02:09 -08001838 "region #1 not an MMIO resource (%s), aborting\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 pci_name(ha->pdev));
1840 goto iospace_error_exit;
1841 }
Andrew Vasquez37765412008-01-17 09:02:09 -08001842 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 qla_printk(KERN_ERR, ha,
1844 "Invalid PCI mem region size (%s), aborting\n",
1845 pci_name(ha->pdev));
1846 goto iospace_error_exit;
1847 }
1848
Andrew Vasquez37765412008-01-17 09:02:09 -08001849 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 if (!ha->iobase) {
1851 qla_printk(KERN_ERR, ha,
1852 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1853
1854 goto iospace_error_exit;
1855 }
1856
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001857 /* Determine queue resources */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001858 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezd84a47c2010-03-19 16:59:18 -07001859 if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
1860 (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001861 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001862 goto mqiobase_exit;
Michael Hernandezd84a47c2010-03-19 16:59:18 -07001863
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001864 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1865 pci_resource_len(ha->pdev, 3));
1866 if (ha->mqiobase) {
1867 /* Read MSIX vector size of the board */
1868 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1869 ha->msix_count = msix;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001870 /* Max queues are bounded by available msix vectors */
1871 /* queue 0 uses two msix vectors */
1872 if (ql2xmultique_tag) {
1873 cpus = num_online_cpus();
Anirban Chakraborty27dc9c52009-06-17 10:30:28 -07001874 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001875 (cpus + 1) : (ha->msix_count - 1);
1876 ha->max_req_queues = 2;
1877 } else if (ql2xmaxqueues > 1) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001878 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1879 QLA_MQ_SIZE : ql2xmaxqueues;
1880 DEBUG2(qla_printk(KERN_INFO, ha, "QoS mode set, max no"
1881 " of request queues:%d\n", ha->max_req_queues));
1882 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001883 qla_printk(KERN_INFO, ha,
1884 "MSI-X vector count: %d\n", msix);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001885 } else
1886 qla_printk(KERN_INFO, ha, "BAR 3 not enabled\n");
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001887
1888mqiobase_exit:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001889 ha->msix_count = ha->max_rsp_queues + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 return (0);
1891
1892iospace_error_exit:
1893 return (-ENOMEM);
1894}
1895
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001896static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001897qla2xxx_scan_start(struct Scsi_Host *shost)
1898{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001899 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001900
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07001901 if (vha->hw->flags.running_gold_fw)
1902 return;
1903
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001904 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1905 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1906 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1907 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001908}
1909
1910static int
1911qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1912{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001913 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001914
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001915 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001916 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001917 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001918 return 1;
1919
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001920 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001921}
1922
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923/*
1924 * PCI driver interface
1925 */
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001926static int __devinit
1927qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001929 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001931 scsi_qla_host_t *base_vha = NULL;
1932 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07001933 char pci_info[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 char fw_str[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08001935 struct scsi_host_template *sht;
Anirban Chakrabortyc51da4e2008-11-10 15:53:20 -08001936 int bars, max_id, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001937 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001938 struct req_que *req = NULL;
1939 struct rsp_que *rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940
Andrew Vasquez285d0322007-10-19 15:59:17 -07001941 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07001942 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001943 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1944 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001945 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07001946 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1947 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001948 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07001949 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
1950 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07001951 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001952 mem_only = 1;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001953 }
1954
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001955 if (mem_only) {
1956 if (pci_enable_device_mem(pdev))
1957 goto probe_out;
1958 } else {
1959 if (pci_enable_device(pdev))
1960 goto probe_out;
1961 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962
Jesse Barnes09276782008-10-18 17:33:19 -07001963 /* This may fail but that's ok */
1964 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07001965
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001966 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
1967 if (!ha) {
1968 DEBUG(printk("Unable to allocate memory for ha\n"));
1969 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001971 ha->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
1973 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07001974 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001975 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001976 spin_lock_init(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001978 /* Set ISP-type information. */
1979 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08001980
1981 /* Set EEH reset type to fundamental if required by hba */
1982 if ( IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha)) {
1983 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08001984 }
1985
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 /* Configure PCI I/O space */
1987 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001988 if (ret)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001989 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 qla_printk(KERN_INFO, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08001992 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1993 ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 ha->prev_topology = 0;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001996 ha->init_cb_size = sizeof(init_cb_t);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001997 ha->link_data_rate = PORT_SPEED_UNKNOWN;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001998 ha->optrom_size = OPTROM_SIZE_2300;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002000 /* Assign ISP specific operations. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002001 max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 if (IS_QLA2100(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002003 max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002005 req_length = REQUEST_ENTRY_CNT_2100;
2006 rsp_length = RESPONSE_ENTRY_CNT_2100;
2007 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002008 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002009 ha->flash_conf_off = ~0;
2010 ha->flash_data_off = ~0;
2011 ha->nvram_conf_off = ~0;
2012 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002013 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 } else if (IS_QLA2200(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002016 req_length = REQUEST_ENTRY_CNT_2200;
2017 rsp_length = RESPONSE_ENTRY_CNT_2100;
2018 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002019 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002020 ha->flash_conf_off = ~0;
2021 ha->flash_data_off = ~0;
2022 ha->nvram_conf_off = ~0;
2023 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002024 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002025 } else if (IS_QLA23XX(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002027 req_length = REQUEST_ENTRY_CNT_2200;
2028 rsp_length = RESPONSE_ENTRY_CNT_2300;
2029 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002030 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002031 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2032 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002033 ha->flash_conf_off = ~0;
2034 ha->flash_data_off = ~0;
2035 ha->nvram_conf_off = ~0;
2036 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002037 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002038 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -07002039 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002040 req_length = REQUEST_ENTRY_CNT_24XX;
2041 rsp_length = RESPONSE_ENTRY_CNT_2300;
2042 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002043 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002044 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002045 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002046 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002047 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002048 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2049 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2050 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2051 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002052 } else if (IS_QLA25XX(ha)) {
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002053 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002054 req_length = REQUEST_ENTRY_CNT_24XX;
2055 rsp_length = RESPONSE_ENTRY_CNT_2300;
2056 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002057 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002058 ha->gid_list_info_size = 8;
2059 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002060 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002061 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002062 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2063 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2064 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2065 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2066 } else if (IS_QLA81XX(ha)) {
2067 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2068 req_length = REQUEST_ENTRY_CNT_24XX;
2069 rsp_length = RESPONSE_ENTRY_CNT_2300;
2070 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2071 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2072 ha->gid_list_info_size = 8;
2073 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002074 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002075 ha->isp_ops = &qla81xx_isp_ops;
2076 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2077 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2078 ha->nvram_conf_off = ~0;
2079 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002080 } else if (IS_QLA82XX(ha)) {
2081 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2082 req_length = REQUEST_ENTRY_CNT_82XX;
2083 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2084 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2085 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2086 ha->gid_list_info_size = 8;
2087 ha->optrom_size = OPTROM_SIZE_82XX;
2088 ha->isp_ops = &qla82xx_isp_ops;
2089 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2090 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2091 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2092 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002095 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002096 init_completion(&ha->mbx_cmd_comp);
2097 complete(&ha->mbx_cmd_comp);
2098 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07002099 init_completion(&ha->dcbx_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002101 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102
Andrew Vasquez53303c42009-01-22 09:45:37 -08002103 qla2x00_config_dma_addressing(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002104 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002105 if (!ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 qla_printk(KERN_WARNING, ha,
2107 "[ERROR] Failed to allocate memory for adapter\n");
2108
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002109 goto probe_hw_failed;
2110 }
2111
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002112 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002113 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002114 req->max_q_depth = ql2xmaxqdepth;
2115
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002116
2117 base_vha = qla2x00_create_host(sht, ha);
2118 if (!base_vha) {
2119 qla_printk(KERN_WARNING, ha,
2120 "[ERROR] Failed to allocate memory for scsi_host\n");
2121
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002122 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002123 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002124 qla2x00_free_req_que(ha, req);
2125 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002126 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 }
2128
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002129 pci_set_drvdata(pdev, base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002131 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002132 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002133 host->can_queue = req->length + 128;
2134 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002135 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002136 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002137 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2138 base_vha->vp_idx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002139 if (IS_QLA2100(ha))
2140 host->sg_tablesize = 32;
2141 host->max_id = max_id;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002142 host->this_id = 255;
2143 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07002144 host->unique_id = host->host_no;
Arun Easi0c470872010-07-23 15:28:38 +05002145 if ((IS_QLA25XX(ha) || IS_QLA81XX(ha)) && ql2xenabledif)
2146 host->max_cmd_len = 32;
2147 else
2148 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07002149 host->max_channel = MAX_BUSES - 1;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002150 host->max_lun = MAX_LUNS;
2151 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002152 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002153
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002154 /* Set up the irqs */
2155 ret = qla2x00_request_irqs(ha, rsp);
2156 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002157 goto probe_init_failed;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002158
2159 pci_save_state(pdev);
2160
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002161 /* Alloc arrays of request and response ring ptrs */
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002162que_init:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002163 if (!qla2x00_alloc_queues(ha)) {
2164 qla_printk(KERN_WARNING, ha,
2165 "[ERROR] Failed to allocate memory for queue"
2166 " pointers\n");
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002167 goto probe_init_failed;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002168 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002169
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002170 ha->rsp_q_map[0] = rsp;
2171 ha->req_q_map[0] = req;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002172 rsp->req = req;
2173 req->rsp = rsp;
2174 set_bit(0, ha->req_qid_map);
2175 set_bit(0, ha->rsp_qid_map);
Andrew Vasquez08029992009-03-24 09:07:55 -07002176 /* FWI2-capable only. */
2177 req->req_q_in = &ha->iobase->isp24.req_q_in;
2178 req->req_q_out = &ha->iobase->isp24.req_q_out;
2179 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
2180 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002181 if (ha->mqenable) {
Andrew Vasquez08029992009-03-24 09:07:55 -07002182 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2183 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2184 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2185 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002186 }
2187
Giridhar Malavalia9083012010-04-12 17:59:55 -07002188 if (IS_QLA82XX(ha)) {
2189 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
2190 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
2191 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
2192 }
2193
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002194 if (qla2x00_initialize_adapter(base_vha)) {
2195 qla_printk(KERN_WARNING, ha,
2196 "Failed to initialize adapter\n");
2197
2198 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
2199 "Adapter flags %x.\n",
2200 base_vha->host_no, base_vha->device_flags));
2201
Giridhar Malavalia9083012010-04-12 17:59:55 -07002202 if (IS_QLA82XX(ha)) {
2203 qla82xx_idc_lock(ha);
2204 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2205 QLA82XX_DEV_FAILED);
2206 qla82xx_idc_unlock(ha);
2207 qla_printk(KERN_INFO, ha, "HW State: FAILED\n");
2208 }
2209
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002210 ret = -ENODEV;
2211 goto probe_failed;
2212 }
2213
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002214 if (ha->mqenable) {
2215 if (qla25xx_setup_mode(base_vha)) {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002216 qla_printk(KERN_WARNING, ha,
2217 "Can't create queues, falling back to single"
2218 " queue mode\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002219 goto que_init;
2220 }
2221 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002222
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002223 if (ha->flags.running_gold_fw)
2224 goto skip_dpc;
2225
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002226 /*
2227 * Startup the kernel thread for this host adapter
2228 */
2229 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
2230 "%s_dpc", base_vha->host_str);
2231 if (IS_ERR(ha->dpc_thread)) {
2232 qla_printk(KERN_WARNING, ha,
2233 "Unable to start DPC thread!\n");
2234 ret = PTR_ERR(ha->dpc_thread);
2235 goto probe_failed;
2236 }
2237
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002238skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002239 list_add_tail(&base_vha->list, &ha->vp_list);
2240 base_vha->host->irq = ha->pdev->irq;
2241
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002243 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244
2245 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002246 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247
Arun Easiba77ef52010-05-28 15:08:27 -07002248 if ((IS_QLA25XX(ha) || IS_QLA81XX(ha)) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07002249 if (ha->fw_attributes & BIT_4) {
2250 base_vha->flags.difdix_supported = 1;
2251 DEBUG18(qla_printk(KERN_INFO, ha,
2252 "Registering for DIF/DIX type 1 and 3"
2253 " protection.\n"));
2254 scsi_host_set_prot(host,
2255 SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002256 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002257 | SHOST_DIF_TYPE3_PROTECTION
2258 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05002259 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07002260 | SHOST_DIX_TYPE3_PROTECTION);
2261 scsi_host_set_guard(host, SHOST_DIX_GUARD_CRC);
2262 } else
2263 base_vha->flags.difdix_supported = 0;
2264 }
2265
Giridhar Malavalia9083012010-04-12 17:59:55 -07002266 ha->isp_ops->enable_intrs(ha);
2267
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002268 ret = scsi_add_host(host, &pdev->dev);
2269 if (ret)
2270 goto probe_failed;
2271
Michael Reed14864002009-12-02 09:11:16 -06002272 base_vha->flags.init_done = 1;
2273 base_vha->flags.online = 1;
2274
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002275 scsi_scan_host(host);
2276
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002277 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002278
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002279 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002280
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002281 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002282
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 qla_printk(KERN_INFO, ha, "\n"
2284 " QLogic Fibre Channel HBA Driver: %s\n"
2285 " QLogic %s - %s\n"
Andrew Vasquez54333832005-11-09 15:49:04 -08002286 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
2287 qla2x00_version_str, ha->model_number,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002288 ha->model_desc ? ha->model_desc : "", pdev->device,
2289 ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
2290 ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
2291 ha->isp_ops->fw_version_str(base_vha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 return 0;
2294
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002295probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002296 qla2x00_free_req_que(ha, req);
2297 qla2x00_free_rsp_que(ha, rsp);
2298 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002299
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07002301 if (base_vha->timer_active)
2302 qla2x00_stop_timer(base_vha);
2303 base_vha->flags.online = 0;
2304 if (ha->dpc_thread) {
2305 struct task_struct *t = ha->dpc_thread;
2306
2307 ha->dpc_thread = NULL;
2308 kthread_stop(t);
2309 }
2310
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002311 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002313 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002315probe_hw_failed:
Giridhar Malavalia9083012010-04-12 17:59:55 -07002316 if (IS_QLA82XX(ha)) {
2317 qla82xx_idc_lock(ha);
2318 qla82xx_clear_drv_active(ha);
2319 qla82xx_idc_unlock(ha);
2320 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
2321 if (!ql2xdbwr)
2322 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2323 } else {
2324 if (ha->iobase)
2325 iounmap(ha->iobase);
2326 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002327 pci_release_selected_regions(ha->pdev, ha->bars);
2328 kfree(ha);
2329 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002331probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002332 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002333 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335
Adrian Bunk4c993f72008-01-14 00:55:16 -08002336static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002337qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002339 scsi_qla_host_t *base_vha, *vha, *temp;
2340 struct qla_hw_data *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002342 base_vha = pci_get_drvdata(pdev);
2343 ha = base_vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002345 list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
2346 if (vha && vha->fc_vport)
2347 fc_vport_terminate(vha->fc_vport);
2348 }
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002349
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002350 set_bit(UNLOADING, &base_vha->dpc_flags);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002351
Andrew Vasquezb9978762009-03-24 09:08:05 -07002352 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2353
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002354 qla2x00_dfs_remove(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002355
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002356 qla84xx_put_chip(base_vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002357
Andrew Vasquezb9978762009-03-24 09:08:05 -07002358 /* Disable timer */
2359 if (base_vha->timer_active)
2360 qla2x00_stop_timer(base_vha);
2361
2362 base_vha->flags.online = 0;
2363
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002364 /* Flush the work queue and remove it */
2365 if (ha->wq) {
2366 flush_workqueue(ha->wq);
2367 destroy_workqueue(ha->wq);
2368 ha->wq = NULL;
2369 }
2370
Andrew Vasquezb9978762009-03-24 09:08:05 -07002371 /* Kill the kernel thread for this host */
2372 if (ha->dpc_thread) {
2373 struct task_struct *t = ha->dpc_thread;
2374
2375 /*
2376 * qla2xxx_wake_dpc checks for ->dpc_thread
2377 * so we need to zero it out.
2378 */
2379 ha->dpc_thread = NULL;
2380 kthread_stop(t);
2381 }
2382
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002383 qla2x00_free_sysfs_attr(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002385 fc_remove_host(base_vha->host);
bdf79622005-04-17 15:06:53 -05002386
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002387 scsi_remove_host(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002389 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002391 scsi_host_put(base_vha->host);
2392
Giridhar Malavalia9083012010-04-12 17:59:55 -07002393 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07002394 qla82xx_idc_lock(ha);
2395 qla82xx_clear_drv_active(ha);
2396 qla82xx_idc_unlock(ha);
2397
Giridhar Malavalia9083012010-04-12 17:59:55 -07002398 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
2399 if (!ql2xdbwr)
2400 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2401 } else {
2402 if (ha->iobase)
2403 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002404
Giridhar Malavalia9083012010-04-12 17:59:55 -07002405 if (ha->mqiobase)
2406 iounmap(ha->mqiobase);
2407 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002408
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002409 pci_release_selected_regions(ha->pdev, ha->bars);
2410 kfree(ha);
2411 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08002413 pci_disable_pcie_error_reporting(pdev);
2414
Bernhard Walle665db932007-03-28 00:49:49 +02002415 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 pci_set_drvdata(pdev, NULL);
2417}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418
2419static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002420qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002422 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423
Andrew Vasquez85880802009-12-15 21:29:46 -08002424 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
2425
2426 /* Disable timer */
2427 if (vha->timer_active)
2428 qla2x00_stop_timer(vha);
2429
2430 /* Kill the kernel thread for this host */
2431 if (ha->dpc_thread) {
2432 struct task_struct *t = ha->dpc_thread;
2433
2434 /*
2435 * qla2xxx_wake_dpc checks for ->dpc_thread
2436 * so we need to zero it out.
2437 */
2438 ha->dpc_thread = NULL;
2439 kthread_stop(t);
2440 }
2441
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002442 qla25xx_delete_queues(vha);
2443
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002444 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002445 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002446
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002447 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002448 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002449
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002450 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002451 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452
Andrew Vasquez85880802009-12-15 21:29:46 -08002453 vha->flags.online = 0;
2454
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002455 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07002456 if (ha->interrupts_on) {
2457 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002458 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002459 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002460
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002461 qla2x00_free_irqs(vha);
2462
Chad Dupuis88670482010-07-23 15:28:30 +05002463 qla2x00_free_fcports(vha);
2464
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002465 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002466
2467 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468}
2469
Chad Dupuis88670482010-07-23 15:28:30 +05002470void qla2x00_free_fcports(struct scsi_qla_host *vha)
2471{
2472 fc_port_t *fcport, *tfcport;
2473
2474 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
2475 list_del(&fcport->list);
2476 kfree(fcport);
2477 fcport = NULL;
2478 }
2479}
2480
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002481static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002482qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002483 int defer)
2484{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002485 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07002486 scsi_qla_host_t *base_vha;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002487
2488 if (!fcport->rport)
2489 return;
2490
2491 rport = fcport->rport;
2492 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07002493 base_vha = pci_get_drvdata(vha->hw->pdev);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002494 spin_lock_irq(vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002495 fcport->drport = rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002496 spin_unlock_irq(vha->host->host_lock);
Andrew Vasquez67becc02009-08-25 11:36:20 -07002497 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2498 qla2xxx_wake_dpc(base_vha);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002499 } else
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002500 fc_remote_port_delete(rport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002501}
2502
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2505 *
2506 * Input: ha = adapter block pointer. fcport = port structure pointer.
2507 *
2508 * Return: None.
2509 *
2510 * Context:
2511 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002512void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002513 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002515 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002516 vha->vp_idx == fcport->vp_idx) {
2517 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2518 qla2x00_schedule_rport_del(vha, fcport, defer);
2519 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002520 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 * We may need to retry the login, so don't change the state of the
2522 * port but do the retries.
2523 */
2524 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2525 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2526
2527 if (!do_login)
2528 return;
2529
2530 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002531 fcport->login_retry = vha->hw->login_retry_count;
2532 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533
2534 DEBUG(printk("scsi(%ld): Port login retry: "
2535 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2536 "id = 0x%04x retry cnt=%d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002537 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 fcport->port_name[0],
2539 fcport->port_name[1],
2540 fcport->port_name[2],
2541 fcport->port_name[3],
2542 fcport->port_name[4],
2543 fcport->port_name[5],
2544 fcport->port_name[6],
2545 fcport->port_name[7],
2546 fcport->loop_id,
2547 fcport->login_retry));
2548 }
2549}
2550
2551/*
2552 * qla2x00_mark_all_devices_lost
2553 * Updates fcport state when device goes offline.
2554 *
2555 * Input:
2556 * ha = adapter block pointer.
2557 * fcport = port structure pointer.
2558 *
2559 * Return:
2560 * None.
2561 *
2562 * Context:
2563 */
2564void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002565qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566{
2567 fc_port_t *fcport;
2568
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002569 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002570 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002572
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 /*
2574 * No point in marking the device as lost, if the device is
2575 * already DEAD.
2576 */
2577 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2578 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002579 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07002580 if (defer)
2581 qla2x00_schedule_rport_del(vha, fcport, defer);
2582 else if (vha->vp_idx == fcport->vp_idx)
2583 qla2x00_schedule_rport_del(vha, fcport, defer);
2584 }
2585 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 }
2587}
2588
2589/*
2590* qla2x00_mem_alloc
2591* Allocates adapter memory.
2592*
2593* Returns:
2594* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08002595* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08002597static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002598qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2599 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600{
2601 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602
Andrew Vasqueze8711082008-01-31 12:33:48 -08002603 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002604 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002605 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002606 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002608 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2609 &ha->gid_list_dma, GFP_KERNEL);
2610 if (!ha->gid_list)
Andrew Vasqueze8711082008-01-31 12:33:48 -08002611 goto fail_free_init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612
Andrew Vasqueze8711082008-01-31 12:33:48 -08002613 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2614 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002615 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616
Giridhar Malavalia9083012010-04-12 17:59:55 -07002617 if (IS_QLA82XX(ha)) {
2618 /* Allocate cache for CT6 Ctx. */
2619 if (!ctx_cachep) {
2620 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
2621 sizeof(struct ct6_dsd), 0,
2622 SLAB_HWCACHE_ALIGN, NULL);
2623 if (!ctx_cachep)
2624 goto fail_free_gid_list;
2625 }
2626 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
2627 ctx_cachep);
2628 if (!ha->ctx_mempool)
2629 goto fail_free_srb_mempool;
2630 }
2631
Andrew Vasqueze8711082008-01-31 12:33:48 -08002632 /* Get memory for cached NVRAM */
2633 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2634 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07002635 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002637 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2638 ha->pdev->device);
2639 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2640 DMA_POOL_SIZE, 8, 0);
2641 if (!ha->s_dma_pool)
2642 goto fail_free_nvram;
2643
Arun Easibad75002010-05-04 15:01:30 -07002644 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002645 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2646 DSD_LIST_DMA_POOL_SIZE, 8, 0);
2647 if (!ha->dl_dma_pool) {
2648 qla_printk(KERN_WARNING, ha,
2649 "Memory Allocation failed - dl_dma_pool\n");
2650 goto fail_s_dma_pool;
2651 }
2652
2653 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2654 FCP_CMND_DMA_POOL_SIZE, 8, 0);
2655 if (!ha->fcp_cmnd_dma_pool) {
2656 qla_printk(KERN_WARNING, ha,
2657 "Memory Allocation failed - fcp_cmnd_dma_pool\n");
2658 goto fail_dl_dma_pool;
2659 }
2660 }
2661
Andrew Vasqueze8711082008-01-31 12:33:48 -08002662 /* Allocate memory for SNS commands */
2663 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002664 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002665 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002666 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002667 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002668 goto fail_dma_pool;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002669 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002670 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002671 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002672 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002673 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002674 goto fail_dma_pool;
2675 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002676 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002677 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002678 if (!ha->ct_sns)
2679 goto fail_free_ms_iocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 }
2681
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002682 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002683 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2684 if (!*req) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002685 DEBUG(printk("Unable to allocate memory for req\n"));
2686 goto fail_req;
2687 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002688 (*req)->length = req_len;
2689 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2690 ((*req)->length + 1) * sizeof(request_t),
2691 &(*req)->dma, GFP_KERNEL);
2692 if (!(*req)->ring) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002693 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2694 goto fail_req_ring;
2695 }
2696 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002697 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2698 if (!*rsp) {
2699 qla_printk(KERN_WARNING, ha,
2700 "Unable to allocate memory for rsp\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002701 goto fail_rsp;
2702 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002703 (*rsp)->hw = ha;
2704 (*rsp)->length = rsp_len;
2705 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2706 ((*rsp)->length + 1) * sizeof(response_t),
2707 &(*rsp)->dma, GFP_KERNEL);
2708 if (!(*rsp)->ring) {
2709 qla_printk(KERN_WARNING, ha,
2710 "Unable to allocate memory for rsp_ring\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002711 goto fail_rsp_ring;
2712 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002713 (*req)->rsp = *rsp;
2714 (*rsp)->req = *req;
2715 /* Allocate memory for NVRAM data for vports */
2716 if (ha->nvram_npiv_size) {
2717 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
2718 ha->nvram_npiv_size, GFP_KERNEL);
2719 if (!ha->npiv_info) {
2720 qla_printk(KERN_WARNING, ha,
2721 "Unable to allocate memory for npiv info\n");
2722 goto fail_npiv_info;
2723 }
2724 } else
2725 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002726
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002727 /* Get consistent memory allocated for EX-INIT-CB. */
Giridhar Malavalia9083012010-04-12 17:59:55 -07002728 if (IS_QLA8XXX_TYPE(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002729 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2730 &ha->ex_init_cb_dma);
2731 if (!ha->ex_init_cb)
2732 goto fail_ex_init_cb;
2733 }
2734
Giridhar Malavalia9083012010-04-12 17:59:55 -07002735 INIT_LIST_HEAD(&ha->gbl_dsd_list);
2736
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002737 /* Get consistent memory allocated for Async Port-Database. */
2738 if (!IS_FWI2_CAPABLE(ha)) {
2739 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2740 &ha->async_pd_dma);
2741 if (!ha->async_pd)
2742 goto fail_async_pd;
2743 }
2744
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002745 INIT_LIST_HEAD(&ha->vp_list);
2746 return 1;
2747
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002748fail_async_pd:
2749 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002750fail_ex_init_cb:
2751 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002752fail_npiv_info:
2753 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2754 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2755 (*rsp)->ring = NULL;
2756 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002757fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002758 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002759fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002760 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2761 sizeof(request_t), (*req)->ring, (*req)->dma);
2762 (*req)->ring = NULL;
2763 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002764fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002765 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002766fail_req:
2767 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2768 ha->ct_sns, ha->ct_sns_dma);
2769 ha->ct_sns = NULL;
2770 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002771fail_free_ms_iocb:
2772 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2773 ha->ms_iocb = NULL;
2774 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002775fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07002776 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002777 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
2778 ha->fcp_cmnd_dma_pool = NULL;
2779 }
2780fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07002781 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002782 dma_pool_destroy(ha->dl_dma_pool);
2783 ha->dl_dma_pool = NULL;
2784 }
2785fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002786 dma_pool_destroy(ha->s_dma_pool);
2787 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002788fail_free_nvram:
2789 kfree(ha->nvram);
2790 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002791fail_free_ctx_mempool:
2792 mempool_destroy(ha->ctx_mempool);
2793 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002794fail_free_srb_mempool:
2795 mempool_destroy(ha->srb_mempool);
2796 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002797fail_free_gid_list:
2798 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002799 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002800 ha->gid_list = NULL;
2801 ha->gid_list_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002802fail_free_init_cb:
2803 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2804 ha->init_cb_dma);
2805 ha->init_cb = NULL;
2806 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002807fail:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002808 DEBUG(printk("%s: Memory allocation failure\n", __func__));
Andrew Vasqueze8711082008-01-31 12:33:48 -08002809 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810}
2811
2812/*
2813* qla2x00_mem_free
2814* Frees all adapter allocated memory.
2815*
2816* Input:
2817* ha = adapter block pointer.
2818*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08002819static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002820qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821{
Andrew Vasqueze8711082008-01-31 12:33:48 -08002822 if (ha->srb_mempool)
2823 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002825 if (ha->fce)
2826 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002827 ha->fce_dma);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002828
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002829 if (ha->fw_dump) {
2830 if (ha->eft)
2831 dma_free_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002832 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002833 vfree(ha->fw_dump);
2834 }
2835
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07002836 if (ha->dcbx_tlv)
2837 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
2838 ha->dcbx_tlv, ha->dcbx_tlv_dma);
2839
Andrew Vasquezce0423f2009-06-03 09:55:13 -07002840 if (ha->xgmac_data)
2841 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
2842 ha->xgmac_data, ha->xgmac_data_dma);
2843
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 if (ha->sns_cmd)
2845 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002846 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847
2848 if (ha->ct_sns)
2849 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002850 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851
Andrew Vasquez88729e52006-06-23 16:10:50 -07002852 if (ha->sfp_data)
2853 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2854
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07002855 if (ha->edc_data)
2856 dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
2857
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 if (ha->ms_iocb)
2859 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2860
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002861 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07002862 dma_pool_free(ha->s_dma_pool,
2863 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002864
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002865 if (ha->async_pd)
2866 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
2867
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868 if (ha->s_dma_pool)
2869 dma_pool_destroy(ha->s_dma_pool);
2870
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 if (ha->gid_list)
2872 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002873 ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874
Giridhar Malavalia9083012010-04-12 17:59:55 -07002875 if (IS_QLA82XX(ha)) {
2876 if (!list_empty(&ha->gbl_dsd_list)) {
2877 struct dsd_dma *dsd_ptr, *tdsd_ptr;
2878
2879 /* clean up allocated prev pool */
2880 list_for_each_entry_safe(dsd_ptr,
2881 tdsd_ptr, &ha->gbl_dsd_list, list) {
2882 dma_pool_free(ha->dl_dma_pool,
2883 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
2884 list_del(&dsd_ptr->list);
2885 kfree(dsd_ptr);
2886 }
2887 }
2888 }
2889
2890 if (ha->dl_dma_pool)
2891 dma_pool_destroy(ha->dl_dma_pool);
2892
2893 if (ha->fcp_cmnd_dma_pool)
2894 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
2895
2896 if (ha->ctx_mempool)
2897 mempool_destroy(ha->ctx_mempool);
2898
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002899 if (ha->init_cb)
2900 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002901 ha->init_cb, ha->init_cb_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002902 vfree(ha->optrom_buffer);
2903 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002904 kfree(ha->npiv_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905
Andrew Vasqueze8711082008-01-31 12:33:48 -08002906 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002907 ha->ctx_mempool = NULL;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002908 ha->eft = NULL;
2909 ha->eft_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 ha->sns_cmd = NULL;
2911 ha->sns_cmd_dma = 0;
2912 ha->ct_sns = NULL;
2913 ha->ct_sns_dma = 0;
2914 ha->ms_iocb = NULL;
2915 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 ha->init_cb = NULL;
2917 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002918 ha->ex_init_cb = NULL;
2919 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002920 ha->async_pd = NULL;
2921 ha->async_pd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922
2923 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002924 ha->dl_dma_pool = NULL;
2925 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 ha->gid_list = NULL;
2928 ha->gid_list_dma = 0;
2929
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002931 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 ha->fw_dump_reading = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002933}
2934
2935struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
2936 struct qla_hw_data *ha)
2937{
2938 struct Scsi_Host *host;
2939 struct scsi_qla_host *vha = NULL;
2940
2941 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
2942 if (host == NULL) {
2943 printk(KERN_WARNING
2944 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2945 goto fail;
2946 }
2947
2948 /* Clear our data area */
2949 vha = shost_priv(host);
2950 memset(vha, 0, sizeof(scsi_qla_host_t));
2951
2952 vha->host = host;
2953 vha->host_no = host->host_no;
2954 vha->hw = ha;
2955
2956 INIT_LIST_HEAD(&vha->vp_fcports);
2957 INIT_LIST_HEAD(&vha->work_list);
2958 INIT_LIST_HEAD(&vha->list);
2959
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002960 spin_lock_init(&vha->work_lock);
2961
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002962 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
2963 return vha;
2964
2965fail:
2966 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967}
2968
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002969static struct qla_work_evt *
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002970qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002971{
2972 struct qla_work_evt *e;
2973
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002974 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002975 if (!e)
2976 return NULL;
2977
2978 INIT_LIST_HEAD(&e->list);
2979 e->type = type;
2980 e->flags = QLA_EVT_FLAG_FREE;
2981 return e;
2982}
2983
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002984static int
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002985qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002986{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002987 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002988
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002989 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002990 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002991 spin_unlock_irqrestore(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002992 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002993
Andrew Vasquez0971de72008-04-03 13:13:18 -07002994 return QLA_SUCCESS;
2995}
2996
2997int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002998qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07002999 u32 data)
3000{
3001 struct qla_work_evt *e;
3002
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003003 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003004 if (!e)
3005 return QLA_FUNCTION_FAILED;
3006
3007 e->u.aen.code = code;
3008 e->u.aen.data = data;
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003009 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003010}
3011
Andrew Vasquez8a659572009-02-08 20:50:12 -08003012int
3013qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
3014{
3015 struct qla_work_evt *e;
3016
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003017 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003018 if (!e)
3019 return QLA_FUNCTION_FAILED;
3020
3021 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003022 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003023}
3024
Andrew Vasquezac280b62009-08-20 11:06:05 -07003025#define qla2x00_post_async_work(name, type) \
3026int qla2x00_post_async_##name##_work( \
3027 struct scsi_qla_host *vha, \
3028 fc_port_t *fcport, uint16_t *data) \
3029{ \
3030 struct qla_work_evt *e; \
3031 \
3032 e = qla2x00_alloc_work(vha, type); \
3033 if (!e) \
3034 return QLA_FUNCTION_FAILED; \
3035 \
3036 e->u.logio.fcport = fcport; \
3037 if (data) { \
3038 e->u.logio.data[0] = data[0]; \
3039 e->u.logio.data[1] = data[1]; \
3040 } \
3041 return qla2x00_post_work(vha, e); \
3042}
3043
3044qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
3045qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
3046qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
3047qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003048qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
3049qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07003050
Andrew Vasquez3420d362009-10-13 15:16:45 -07003051int
3052qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
3053{
3054 struct qla_work_evt *e;
3055
3056 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
3057 if (!e)
3058 return QLA_FUNCTION_FAILED;
3059
3060 e->u.uevent.code = code;
3061 return qla2x00_post_work(vha, e);
3062}
3063
3064static void
3065qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
3066{
3067 char event_string[40];
3068 char *envp[] = { event_string, NULL };
3069
3070 switch (code) {
3071 case QLA_UEVENT_CODE_FW_DUMP:
3072 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
3073 vha->host_no);
3074 break;
3075 default:
3076 /* do nothing */
3077 break;
3078 }
3079 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
3080}
3081
Andrew Vasquezac280b62009-08-20 11:06:05 -07003082void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003083qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07003084{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003085 struct qla_work_evt *e, *tmp;
3086 unsigned long flags;
3087 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003088
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003089 spin_lock_irqsave(&vha->work_lock, flags);
3090 list_splice_init(&vha->work_list, &work);
3091 spin_unlock_irqrestore(&vha->work_lock, flags);
3092
3093 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07003094 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003095
3096 switch (e->type) {
3097 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003098 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07003099 e->u.aen.code, e->u.aen.data);
3100 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08003101 case QLA_EVT_IDC_ACK:
3102 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
3103 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003104 case QLA_EVT_ASYNC_LOGIN:
3105 qla2x00_async_login(vha, e->u.logio.fcport,
3106 e->u.logio.data);
3107 break;
3108 case QLA_EVT_ASYNC_LOGIN_DONE:
3109 qla2x00_async_login_done(vha, e->u.logio.fcport,
3110 e->u.logio.data);
3111 break;
3112 case QLA_EVT_ASYNC_LOGOUT:
3113 qla2x00_async_logout(vha, e->u.logio.fcport);
3114 break;
3115 case QLA_EVT_ASYNC_LOGOUT_DONE:
3116 qla2x00_async_logout_done(vha, e->u.logio.fcport,
3117 e->u.logio.data);
3118 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003119 case QLA_EVT_ASYNC_ADISC:
3120 qla2x00_async_adisc(vha, e->u.logio.fcport,
3121 e->u.logio.data);
3122 break;
3123 case QLA_EVT_ASYNC_ADISC_DONE:
3124 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
3125 e->u.logio.data);
3126 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07003127 case QLA_EVT_UEVENT:
3128 qla2x00_uevent_emit(vha, e->u.uevent.code);
3129 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07003130 }
3131 if (e->flags & QLA_EVT_FLAG_FREE)
3132 kfree(e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003133 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003134}
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07003135
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003136/* Relogins all the fcports of a vport
3137 * Context: dpc thread
3138 */
3139void qla2x00_relogin(struct scsi_qla_host *vha)
3140{
3141 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003142 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003143 uint16_t next_loopid = 0;
3144 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003145 uint16_t data[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003146
3147 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3148 /*
3149 * If the port is not ONLINE then try to login
3150 * to it if we haven't run out of retries.
3151 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003152 if (atomic_read(&fcport->state) != FCS_ONLINE &&
3153 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07003154 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003155 if (fcport->flags & FCF_FABRIC_DEVICE) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003156 if (fcport->flags & FCF_FCP2_DEVICE)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003157 ha->isp_ops->fabric_logout(vha,
3158 fcport->loop_id,
3159 fcport->d_id.b.domain,
3160 fcport->d_id.b.area,
3161 fcport->d_id.b.al_pa);
3162
Andrew Vasquezac280b62009-08-20 11:06:05 -07003163 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003164 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003165 data[0] = 0;
3166 data[1] = QLA_LOGIO_LOGIN_RETRIED;
3167 status = qla2x00_post_async_login_work(
3168 vha, fcport, data);
3169 if (status == QLA_SUCCESS)
3170 continue;
3171 /* Attempt a retry. */
3172 status = 1;
3173 } else
3174 status = qla2x00_fabric_login(vha,
3175 fcport, &next_loopid);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003176 } else
3177 status = qla2x00_local_device_login(vha,
3178 fcport);
3179
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003180 if (status == QLA_SUCCESS) {
3181 fcport->old_loop_id = fcport->loop_id;
3182
3183 DEBUG(printk("scsi(%ld): port login OK: logged "
3184 "in ID 0x%x\n", vha->host_no, fcport->loop_id));
3185
3186 qla2x00_update_fcport(vha, fcport);
3187
3188 } else if (status == 1) {
3189 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3190 /* retry the login again */
3191 DEBUG(printk("scsi(%ld): Retrying"
3192 " %d login again loop_id 0x%x\n",
3193 vha->host_no, fcport->login_retry,
3194 fcport->loop_id));
3195 } else {
3196 fcport->login_retry = 0;
3197 }
3198
3199 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
3200 fcport->loop_id = FC_NO_LOOP_ID;
3201 }
3202 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3203 break;
3204 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07003205}
3206
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207/**************************************************************************
3208* qla2x00_do_dpc
3209* This kernel thread is a task that is schedule by the interrupt handler
3210* to perform the background processing for interrupts.
3211*
3212* Notes:
3213* This task always run in the context of a kernel thread. It
3214* is kick-off by the driver's detect code and starts up
3215* up one per adapter. It immediately goes to sleep and waits for
3216* some fibre event. When either the interrupt handler or
3217* the timer routine detects a event it will one of the task
3218* bits then wake us up.
3219**************************************************************************/
3220static int
3221qla2x00_do_dpc(void *data)
3222{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003223 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003224 scsi_qla_host_t *base_vha;
3225 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08003226
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003227 ha = (struct qla_hw_data *)data;
3228 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230 set_user_nice(current, -20);
3231
Christoph Hellwig39a11242006-02-14 18:46:22 +01003232 while (!kthread_should_stop()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
3234
Christoph Hellwig39a11242006-02-14 18:46:22 +01003235 set_current_state(TASK_INTERRUPTIBLE);
3236 schedule();
3237 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238
3239 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
3240
3241 /* Initialization not yet finished. Don't do anything yet. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003242 if (!base_vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 continue;
3244
Andrew Vasquez85880802009-12-15 21:29:46 -08003245 if (ha->flags.eeh_busy) {
3246 DEBUG17(qla_printk(KERN_WARNING, ha,
3247 "qla2x00_do_dpc: dpc_flags: %lx\n",
3248 base_vha->dpc_flags));
3249 continue;
3250 }
3251
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003252 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253
3254 ha->dpc_active = 1;
3255
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 ha->dpc_active = 0;
3258 continue;
3259 }
3260
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003261 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07003262
Giridhar Malavalia9083012010-04-12 17:59:55 -07003263 if (IS_QLA82XX(ha)) {
3264 if (test_and_clear_bit(ISP_UNRECOVERABLE,
3265 &base_vha->dpc_flags)) {
3266 qla82xx_idc_lock(ha);
3267 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3268 QLA82XX_DEV_FAILED);
3269 qla82xx_idc_unlock(ha);
3270 qla_printk(KERN_INFO, ha,
3271 "HW State: FAILED\n");
3272 qla82xx_device_state_handler(base_vha);
3273 continue;
3274 }
3275
3276 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
3277 &base_vha->dpc_flags)) {
3278
3279 DEBUG(printk(KERN_INFO
3280 "scsi(%ld): dpc: sched "
3281 "qla82xx_fcoe_ctx_reset ha = %p\n",
3282 base_vha->host_no, ha));
3283 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
3284 &base_vha->dpc_flags))) {
3285 if (qla82xx_fcoe_ctx_reset(base_vha)) {
3286 /* FCoE-ctx reset failed.
3287 * Escalate to chip-reset
3288 */
3289 set_bit(ISP_ABORT_NEEDED,
3290 &base_vha->dpc_flags);
3291 }
3292 clear_bit(ABORT_ISP_ACTIVE,
3293 &base_vha->dpc_flags);
3294 }
3295
3296 DEBUG(printk("scsi(%ld): dpc:"
3297 " qla82xx_fcoe_ctx_reset end\n",
3298 base_vha->host_no));
3299 }
3300 }
3301
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003302 if (test_and_clear_bit(ISP_ABORT_NEEDED,
3303 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304
3305 DEBUG(printk("scsi(%ld): dpc: sched "
3306 "qla2x00_abort_isp ha = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003307 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003309 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310
Giridhar Malavalia9083012010-04-12 17:59:55 -07003311 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 /* failed. retry later */
3313 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003314 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003316 clear_bit(ABORT_ISP_ACTIVE,
3317 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08003318 }
3319
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003321 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 }
3323
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003324 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
3325 qla2x00_update_fcports(base_vha);
3326 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003327 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003328
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003329 if (test_and_clear_bit(RESET_MARKER_NEEDED,
3330 &base_vha->dpc_flags) &&
3331 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332
3333 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003334 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003336 qla2x00_rst_aen(base_vha);
3337 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338 }
3339
3340 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003341 if ((test_and_clear_bit(RELOGIN_NEEDED,
3342 &base_vha->dpc_flags)) &&
3343 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
3344 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345
3346 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003347 base_vha->host_no));
3348 qla2x00_relogin(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003351 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 }
3353
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003354 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
3355 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356
3357 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003358 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359
3360 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003361 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003363 rval = qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003365 clear_bit(LOOP_RESYNC_ACTIVE,
3366 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367 }
3368
3369 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003370 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371 }
3372
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003373 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
3374 atomic_read(&base_vha->loop_state) == LOOP_READY) {
3375 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
3376 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07003377 }
3378
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003380 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003382 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
3383 &base_vha->dpc_flags))
3384 ha->isp_ops->beacon_blink(base_vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08003385
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003386 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003387
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 ha->dpc_active = 0;
3389 } /* End of while(1) */
3390
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003391 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392
3393 /*
3394 * Make sure that nobody tries to wake us up again.
3395 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396 ha->dpc_active = 0;
3397
Andrew Vasquezac280b62009-08-20 11:06:05 -07003398 /* Cleanup any residual CTX SRBs. */
3399 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3400
Christoph Hellwig39a11242006-02-14 18:46:22 +01003401 return 0;
3402}
3403
3404void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003405qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01003406{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003407 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003408 struct task_struct *t = ha->dpc_thread;
3409
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003410 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003411 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412}
3413
3414/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415* qla2x00_rst_aen
3416* Processes asynchronous reset.
3417*
3418* Input:
3419* ha = adapter block pointer.
3420*/
3421static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003422qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003424 if (vha->flags.online && !vha->flags.reset_active &&
3425 !atomic_read(&vha->loop_down_timer) &&
3426 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003428 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429
3430 /*
3431 * Issue marker command only when we are going to start
3432 * the I/O.
3433 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003434 vha->marker_needed = 1;
3435 } while (!atomic_read(&vha->loop_down_timer) &&
3436 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 }
3438}
3439
f4f051e2005-04-17 15:02:26 -05003440static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003441qla2x00_sp_free_dma(srb_t *sp)
f4f051e2005-04-17 15:02:26 -05003442{
3443 struct scsi_cmnd *cmd = sp->cmd;
Arun Easibad75002010-05-04 15:01:30 -07003444 struct qla_hw_data *ha = sp->fcport->vha->hw;
f4f051e2005-04-17 15:02:26 -05003445
3446 if (sp->flags & SRB_DMA_VALID) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09003447 scsi_dma_unmap(cmd);
f4f051e2005-04-17 15:02:26 -05003448 sp->flags &= ~SRB_DMA_VALID;
3449 }
Arun Easibad75002010-05-04 15:01:30 -07003450
3451 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
3452 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
3453 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
3454 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
3455 }
3456
3457 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
3458 /* List assured to be having elements */
3459 qla2x00_clean_dsd_pool(ha, sp);
3460 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
3461 }
3462
3463 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
3464 dma_pool_free(ha->dl_dma_pool, sp->ctx,
3465 ((struct crc_context *)sp->ctx)->crc_ctx_dma);
3466 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
3467 }
3468
Andrew Vasquezfca29702005-07-06 10:31:47 -07003469 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05003470}
3471
Andrew Vasquez3dbe7562010-07-23 15:28:37 +05003472static void
Giridhar Malavali083a4692010-05-28 15:08:18 -07003473qla2x00_sp_final_compl(struct qla_hw_data *ha, srb_t *sp)
f4f051e2005-04-17 15:02:26 -05003474{
3475 struct scsi_cmnd *cmd = sp->cmd;
3476
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003477 qla2x00_sp_free_dma(sp);
f4f051e2005-04-17 15:02:26 -05003478
Giridhar Malavalia9083012010-04-12 17:59:55 -07003479 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
3480 struct ct6_dsd *ctx = sp->ctx;
3481 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx->fcp_cmnd,
3482 ctx->fcp_cmnd_dma);
3483 list_splice(&ctx->dsd_list, &ha->gbl_dsd_list);
3484 ha->gbl_dsd_inuse -= ctx->dsd_use_cnt;
3485 ha->gbl_dsd_avail += ctx->dsd_use_cnt;
3486 mempool_free(sp->ctx, ha->ctx_mempool);
3487 sp->ctx = NULL;
3488 }
f4f051e2005-04-17 15:02:26 -05003489
Giridhar Malavalia9083012010-04-12 17:59:55 -07003490 mempool_free(sp, ha->srb_mempool);
f4f051e2005-04-17 15:02:26 -05003491 cmd->scsi_done(cmd);
3492}
bdf79622005-04-17 15:06:53 -05003493
Giridhar Malavali083a4692010-05-28 15:08:18 -07003494void
3495qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
3496{
3497 if (atomic_read(&sp->ref_count) == 0) {
3498 DEBUG2(qla_printk(KERN_WARNING, ha,
3499 "SP reference-count to ZERO -- sp=%p\n", sp));
3500 DEBUG2(BUG());
3501 return;
3502 }
3503 if (!atomic_dec_and_test(&sp->ref_count))
3504 return;
3505 qla2x00_sp_final_compl(ha, sp);
3506}
3507
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508/**************************************************************************
3509* qla2x00_timer
3510*
3511* Description:
3512* One second timer
3513*
3514* Context: Interrupt
3515***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003516void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003517qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519 unsigned long cpu_flags = 0;
3520 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521 int start_dpc = 0;
3522 int index;
3523 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05003524 int t;
Andrew Vasquez85880802009-12-15 21:29:46 -08003525 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003526 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003527 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08003528
Lalit Chandivadea5b36322010-09-03 15:20:50 -07003529 if (ha->flags.eeh_busy) {
3530 qla2x00_restart_timer(vha, WATCH_INTERVAL);
3531 return;
3532 }
3533
Giridhar Malavalia9083012010-04-12 17:59:55 -07003534 if (IS_QLA82XX(ha))
3535 qla82xx_watchdog(vha);
3536
Andrew Vasquez85880802009-12-15 21:29:46 -08003537 /* Hardware read to raise pending EEH errors during mailbox waits. */
3538 if (!pci_channel_offline(ha->pdev))
3539 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 /*
3541 * Ports - Port down timer.
3542 *
3543 * Whenever, a port is in the LOST state we start decrementing its port
3544 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003545 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546 */
3547 t = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003548 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 if (fcport->port_type != FCT_TARGET)
3550 continue;
3551
3552 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
3553
3554 if (atomic_read(&fcport->port_down_timer) == 0)
3555 continue;
3556
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003557 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003559
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07003561 "%d remaining\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003562 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563 t, atomic_read(&fcport->port_down_timer)));
3564 }
3565 t++;
3566 } /* End of for fcport */
3567
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568
3569 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003570 if (atomic_read(&vha->loop_down_timer) > 0 &&
3571 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
3572 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003574 if (atomic_read(&vha->loop_down_timer) ==
3575 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576
3577 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
3578 "queues before time expire\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003579 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003580
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003581 if (!IS_QLA2100(ha) && vha->link_down_timeout)
3582 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003584 /*
3585 * Schedule an ISP abort to return any FCP2-device
3586 * commands.
3587 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003588 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003589 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003590 spin_lock_irqsave(&ha->hardware_lock,
3591 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003592 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003593 for (index = 1;
3594 index < MAX_OUTSTANDING_COMMANDS;
3595 index++) {
3596 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05003597
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003598 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003599 if (!sp)
3600 continue;
Arun Easibad75002010-05-04 15:01:30 -07003601 if (sp->ctx && !IS_PROT_IO(sp))
Andrew Vasquezcf53b062009-08-20 11:06:04 -07003602 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003603 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003604 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003605 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003607 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003608 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003609 break;
3610 }
3611 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003612 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614 start_dpc++;
3615 }
3616
3617 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003618 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003619 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003620 DEBUG(printk("scsi(%ld): Loop down - "
3621 "aborting ISP.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003622 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623 qla_printk(KERN_WARNING, ha,
3624 "Loop down - aborting ISP.\n");
3625
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003626 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003627 }
3628 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07003629 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003630 vha->host_no,
3631 atomic_read(&vha->loop_down_timer)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632 }
3633
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08003634 /* Check if beacon LED needs to be blinked */
3635 if (ha->beacon_blink_led == 1) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003636 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08003637 start_dpc++;
3638 }
3639
Andrew Vasquez550bf572008-04-24 15:21:23 -07003640 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003641 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07003642 start_dpc++;
3643
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003645 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
3646 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
3647 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003649 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
3650 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07003651 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
3652 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003653 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
3654 test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
3655 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003657 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658}
3659
Andrew Vasquez54333832005-11-09 15:49:04 -08003660/* Firmware interface routines. */
3661
Giridhar Malavalia9083012010-04-12 17:59:55 -07003662#define FW_BLOBS 8
Andrew Vasquez54333832005-11-09 15:49:04 -08003663#define FW_ISP21XX 0
3664#define FW_ISP22XX 1
3665#define FW_ISP2300 2
3666#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003667#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003668#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003669#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07003670#define FW_ISP82XX 7
Andrew Vasquez54333832005-11-09 15:49:04 -08003671
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003672#define FW_FILE_ISP21XX "ql2100_fw.bin"
3673#define FW_FILE_ISP22XX "ql2200_fw.bin"
3674#define FW_FILE_ISP2300 "ql2300_fw.bin"
3675#define FW_FILE_ISP2322 "ql2322_fw.bin"
3676#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003677#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003678#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07003679#define FW_FILE_ISP82XX "ql8200_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003680
Daniel Walkere1e82b62008-05-12 22:21:10 -07003681static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003682
3683static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003684 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
3685 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
3686 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
3687 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
3688 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003689 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003690 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07003691 { .name = FW_FILE_ISP82XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08003692};
3693
3694struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003695qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08003696{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003697 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08003698 struct fw_blob *blob;
3699
3700 blob = NULL;
3701 if (IS_QLA2100(ha)) {
3702 blob = &qla_fw_blobs[FW_ISP21XX];
3703 } else if (IS_QLA2200(ha)) {
3704 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003705 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003706 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003707 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003708 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003709 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003710 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003711 } else if (IS_QLA25XX(ha)) {
3712 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003713 } else if (IS_QLA81XX(ha)) {
3714 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07003715 } else if (IS_QLA82XX(ha)) {
3716 blob = &qla_fw_blobs[FW_ISP82XX];
Andrew Vasquez54333832005-11-09 15:49:04 -08003717 }
3718
Daniel Walkere1e82b62008-05-12 22:21:10 -07003719 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003720 if (blob->fw)
3721 goto out;
3722
3723 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
3724 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003725 "(%s).\n", vha->host_no, blob->name));
Andrew Vasquez54333832005-11-09 15:49:04 -08003726 blob->fw = NULL;
3727 blob = NULL;
3728 goto out;
3729 }
3730
3731out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07003732 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003733 return blob;
3734}
3735
3736static void
3737qla2x00_release_firmware(void)
3738{
3739 int idx;
3740
Daniel Walkere1e82b62008-05-12 22:21:10 -07003741 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003742 for (idx = 0; idx < FW_BLOBS; idx++)
3743 if (qla_fw_blobs[idx].fw)
3744 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07003745 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003746}
3747
Seokmann Ju14e660e2007-09-20 14:07:36 -07003748static pci_ers_result_t
3749qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3750{
Andrew Vasquez85880802009-12-15 21:29:46 -08003751 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
3752 struct qla_hw_data *ha = vha->hw;
3753
3754 DEBUG2(qla_printk(KERN_WARNING, ha, "error_detected:state %x\n",
3755 state));
Seokmann Jub9b12f72009-03-24 09:08:18 -07003756
Seokmann Ju14e660e2007-09-20 14:07:36 -07003757 switch (state) {
3758 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08003759 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003760 return PCI_ERS_RESULT_CAN_RECOVER;
3761 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08003762 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07003763 /* For ISP82XX complete any pending mailbox cmd */
3764 if (IS_QLA82XX(ha)) {
3765 ha->flags.fw_hung = 1;
3766 if (ha->flags.mbox_busy) {
3767 ha->flags.mbox_int = 1;
3768 DEBUG2(qla_printk(KERN_ERR, ha,
3769 "Due to pci channel io frozen, doing premature "
3770 "completion of mbx command\n"));
3771 complete(&ha->mbx_intr_comp);
3772 }
3773 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003774 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003775 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07003776 /* Return back all IOs */
3777 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003778 return PCI_ERS_RESULT_NEED_RESET;
3779 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08003780 ha->flags.pci_channel_io_perm_failure = 1;
3781 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003782 return PCI_ERS_RESULT_DISCONNECT;
3783 }
3784 return PCI_ERS_RESULT_NEED_RESET;
3785}
3786
3787static pci_ers_result_t
3788qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
3789{
3790 int risc_paused = 0;
3791 uint32_t stat;
3792 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003793 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3794 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003795 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3796 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
3797
3798 spin_lock_irqsave(&ha->hardware_lock, flags);
3799 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
3800 stat = RD_REG_DWORD(&reg->hccr);
3801 if (stat & HCCR_RISC_PAUSE)
3802 risc_paused = 1;
3803 } else if (IS_QLA23XX(ha)) {
3804 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
3805 if (stat & HSR_RISC_PAUSED)
3806 risc_paused = 1;
3807 } else if (IS_FWI2_CAPABLE(ha)) {
3808 stat = RD_REG_DWORD(&reg24->host_status);
3809 if (stat & HSRX_RISC_PAUSED)
3810 risc_paused = 1;
3811 }
3812 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3813
3814 if (risc_paused) {
3815 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
3816 "Dumping firmware!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003817 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003818
3819 return PCI_ERS_RESULT_NEED_RESET;
3820 } else
3821 return PCI_ERS_RESULT_RECOVERED;
3822}
3823
Lalit Chandivadea5b36322010-09-03 15:20:50 -07003824uint32_t qla82xx_error_recovery(scsi_qla_host_t *base_vha)
3825{
3826 uint32_t rval = QLA_FUNCTION_FAILED;
3827 uint32_t drv_active = 0;
3828 struct qla_hw_data *ha = base_vha->hw;
3829 int fn;
3830 struct pci_dev *other_pdev = NULL;
3831
3832 DEBUG17(qla_printk(KERN_INFO, ha,
3833 "scsi(%ld): In qla82xx_error_recovery\n", base_vha->host_no));
3834
3835 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3836
3837 if (base_vha->flags.online) {
3838 /* Abort all outstanding commands,
3839 * so as to be requeued later */
3840 qla2x00_abort_isp_cleanup(base_vha);
3841 }
3842
3843
3844 fn = PCI_FUNC(ha->pdev->devfn);
3845 while (fn > 0) {
3846 fn--;
3847 DEBUG17(qla_printk(KERN_INFO, ha,
3848 "Finding pci device at function = 0x%x\n", fn));
3849 other_pdev =
3850 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
3851 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
3852 fn));
3853
3854 if (!other_pdev)
3855 continue;
3856 if (atomic_read(&other_pdev->enable_cnt)) {
3857 DEBUG17(qla_printk(KERN_INFO, ha,
3858 "Found PCI func availabe and enabled at 0x%x\n",
3859 fn));
3860 pci_dev_put(other_pdev);
3861 break;
3862 }
3863 pci_dev_put(other_pdev);
3864 }
3865
3866 if (!fn) {
3867 /* Reset owner */
3868 DEBUG17(qla_printk(KERN_INFO, ha,
3869 "This devfn is reset owner = 0x%x\n", ha->pdev->devfn));
3870 qla82xx_idc_lock(ha);
3871
3872 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3873 QLA82XX_DEV_INITIALIZING);
3874
3875 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
3876 QLA82XX_IDC_VERSION);
3877
3878 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
3879 DEBUG17(qla_printk(KERN_INFO, ha,
3880 "drv_active = 0x%x\n", drv_active));
3881
3882 qla82xx_idc_unlock(ha);
3883 /* Reset if device is not already reset
3884 * drv_active would be 0 if a reset has already been done
3885 */
3886 if (drv_active)
3887 rval = qla82xx_start_firmware(base_vha);
3888 else
3889 rval = QLA_SUCCESS;
3890 qla82xx_idc_lock(ha);
3891
3892 if (rval != QLA_SUCCESS) {
3893 qla_printk(KERN_INFO, ha, "HW State: FAILED\n");
3894 qla82xx_clear_drv_active(ha);
3895 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3896 QLA82XX_DEV_FAILED);
3897 } else {
3898 qla_printk(KERN_INFO, ha, "HW State: READY\n");
3899 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3900 QLA82XX_DEV_READY);
3901 qla82xx_idc_unlock(ha);
3902 ha->flags.fw_hung = 0;
3903 rval = qla82xx_restart_isp(base_vha);
3904 qla82xx_idc_lock(ha);
3905 /* Clear driver state register */
3906 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
3907 qla82xx_set_drv_active(base_vha);
3908 }
3909 qla82xx_idc_unlock(ha);
3910 } else {
3911 DEBUG17(qla_printk(KERN_INFO, ha,
3912 "This devfn is not reset owner = 0x%x\n", ha->pdev->devfn));
3913 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
3914 QLA82XX_DEV_READY)) {
3915 ha->flags.fw_hung = 0;
3916 rval = qla82xx_restart_isp(base_vha);
3917 qla82xx_idc_lock(ha);
3918 qla82xx_set_drv_active(base_vha);
3919 qla82xx_idc_unlock(ha);
3920 }
3921 }
3922 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3923
3924 return rval;
3925}
3926
Seokmann Ju14e660e2007-09-20 14:07:36 -07003927static pci_ers_result_t
3928qla2xxx_pci_slot_reset(struct pci_dev *pdev)
3929{
3930 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003931 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3932 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003933 struct rsp_que *rsp;
3934 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003935
Andrew Vasquez85880802009-12-15 21:29:46 -08003936 DEBUG17(qla_printk(KERN_WARNING, ha, "slot_reset\n"));
3937
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003938 /* Workaround: qla2xxx driver which access hardware earlier
3939 * needs error state to be pci_channel_io_online.
3940 * Otherwise mailbox command timesout.
3941 */
3942 pdev->error_state = pci_channel_io_normal;
3943
3944 pci_restore_state(pdev);
3945
Richard Lary8c1496b2010-02-18 10:07:29 -08003946 /* pci_restore_state() clears the saved_state flag of the device
3947 * save restored state which resets saved_state flag
3948 */
3949 pci_save_state(pdev);
3950
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11003951 if (ha->mem_only)
3952 rc = pci_enable_device_mem(pdev);
3953 else
3954 rc = pci_enable_device(pdev);
3955
3956 if (rc) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07003957 qla_printk(KERN_WARNING, ha,
3958 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07003959 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003960 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07003961
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003962 rsp = ha->rsp_q_map[0];
3963 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07003964 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003965
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003966 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07003967 goto exit_slot_reset;
3968
3969 if (IS_QLA82XX(ha)) {
3970 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
3971 ret = PCI_ERS_RESULT_RECOVERED;
3972 goto exit_slot_reset;
3973 } else
3974 goto exit_slot_reset;
3975 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07003976
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003977 while (ha->flags.mbox_busy && retries--)
3978 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08003979
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003980 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003981 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07003982 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003983 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003984
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003985
Lalit Chandivadea5b36322010-09-03 15:20:50 -07003986exit_slot_reset:
Andrew Vasquez85880802009-12-15 21:29:46 -08003987 DEBUG17(qla_printk(KERN_WARNING, ha,
3988 "slot_reset-return:ret=%x\n", ret));
3989
Seokmann Ju14e660e2007-09-20 14:07:36 -07003990 return ret;
3991}
3992
3993static void
3994qla2xxx_pci_resume(struct pci_dev *pdev)
3995{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003996 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3997 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003998 int ret;
3999
Andrew Vasquez85880802009-12-15 21:29:46 -08004000 DEBUG17(qla_printk(KERN_WARNING, ha, "pci_resume\n"));
4001
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004002 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07004003 if (ret != QLA_SUCCESS) {
4004 qla_printk(KERN_ERR, ha,
4005 "the device failed to resume I/O "
4006 "from slot/link_reset");
4007 }
Andrew Vasquez85880802009-12-15 21:29:46 -08004008
Lalit Chandivade3e46f032010-05-04 15:01:23 -07004009 pci_cleanup_aer_uncorrect_error_status(pdev);
4010
Andrew Vasquez85880802009-12-15 21:29:46 -08004011 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07004012}
4013
4014static struct pci_error_handlers qla2xxx_err_handler = {
4015 .error_detected = qla2xxx_pci_error_detected,
4016 .mmio_enabled = qla2xxx_pci_mmio_enabled,
4017 .slot_reset = qla2xxx_pci_slot_reset,
4018 .resume = qla2xxx_pci_resume,
4019};
4020
Andrew Vasquez54333832005-11-09 15:49:04 -08004021static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07004022 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
4023 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
4024 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
4025 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
4026 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
4027 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
4028 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
4029 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
4030 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004031 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07004032 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
4033 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07004034 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004035 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07004036 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Andrew Vasquez54333832005-11-09 15:49:04 -08004037 { 0 },
4038};
4039MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
4040
Andrew Vasquezfca29702005-07-06 10:31:47 -07004041static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07004042 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06004043 .driver = {
4044 .owner = THIS_MODULE,
4045 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07004046 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07004047 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08004048 .remove = qla2x00_remove_one,
Seokmann Ju14e660e2007-09-20 14:07:36 -07004049 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07004050};
4051
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004052static struct file_operations apidev_fops = {
4053 .owner = THIS_MODULE,
4054};
4055
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056/**
4057 * qla2x00_module_init - Module initialization.
4058 **/
4059static int __init
4060qla2x00_module_init(void)
4061{
Andrew Vasquezfca29702005-07-06 10:31:47 -07004062 int ret = 0;
4063
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04004065 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09004066 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067 if (srb_cachep == NULL) {
4068 printk(KERN_ERR
4069 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
4070 return -ENOMEM;
4071 }
4072
4073 /* Derive version string. */
4074 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07004075 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07004076 strcat(qla2x00_version_str, "-debug");
4077
Andrew Vasquez1c97a122005-04-21 16:13:36 -04004078 qla2xxx_transport_template =
4079 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004080 if (!qla2xxx_transport_template) {
4081 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004083 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004084
4085 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
4086 if (apidev_major < 0) {
4087 printk(KERN_WARNING "qla2xxx: Unable to register char device "
4088 "%s\n", QLA2XXX_APIDEV);
4089 }
4090
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004091 qla2xxx_transport_vport_template =
4092 fc_attach_transport(&qla2xxx_transport_vport_functions);
4093 if (!qla2xxx_transport_vport_template) {
4094 kmem_cache_destroy(srb_cachep);
4095 fc_release_transport(qla2xxx_transport_template);
4096 return -ENODEV;
4097 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07004099 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
4100 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07004101 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07004102 if (ret) {
4103 kmem_cache_destroy(srb_cachep);
4104 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004105 fc_release_transport(qla2xxx_transport_vport_template);
Andrew Vasquezfca29702005-07-06 10:31:47 -07004106 }
4107 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004108}
4109
4110/**
4111 * qla2x00_module_exit - Module cleanup.
4112 **/
4113static void __exit
4114qla2x00_module_exit(void)
4115{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07004116 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07004117 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08004118 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04004119 kmem_cache_destroy(srb_cachep);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004120 if (ctx_cachep)
4121 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004122 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004123 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004124}
4125
4126module_init(qla2x00_module_init);
4127module_exit(qla2x00_module_exit);
4128
4129MODULE_AUTHOR("QLogic Corporation");
4130MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
4131MODULE_LICENSE("GPL");
4132MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07004133MODULE_FIRMWARE(FW_FILE_ISP21XX);
4134MODULE_FIRMWARE(FW_FILE_ISP22XX);
4135MODULE_FIRMWARE(FW_FILE_ISP2300);
4136MODULE_FIRMWARE(FW_FILE_ISP2322);
4137MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08004138MODULE_FIRMWARE(FW_FILE_ISP25XX);