]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/scsi/qla2xxx/qla_os.c
qla2xxx: Change scsi host lookup method.
[mirror_ubuntu-bionic-kernel.git] / drivers / scsi / qla2xxx / qla_os.c
CommitLineData
1da177e4 1/*
fa90c54f 2 * QLogic Fibre Channel HBA Driver
bd21eaf9 3 * Copyright (c) 2003-2014 QLogic Corporation
1da177e4 4 *
fa90c54f 5 * See LICENSE.qla2xxx for copyright and licensing details.
1da177e4
LT
6 */
7#include "qla_def.h"
8
9#include <linux/moduleparam.h>
10#include <linux/vmalloc.h>
1da177e4 11#include <linux/delay.h>
39a11240 12#include <linux/kthread.h>
e1e82b6f 13#include <linux/mutex.h>
3420d36c 14#include <linux/kobject.h>
5a0e3ad6 15#include <linux/slab.h>
5601236b 16#include <linux/blk-mq-pci.h>
1da177e4
LT
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
2d70c103
NB
22#include "qla_target.h"
23
1da177e4
LT
24/*
25 * Driver version
26 */
27char qla2x00_version_str[40];
28
6a03b4cd
HZ
29static int apidev_major;
30
1da177e4
LT
31/*
32 * SRB allocation cache
33 */
d7459527 34struct kmem_cache *srb_cachep;
1da177e4 35
a9083016
GM
36/*
37 * CT6 CTX allocation cache
38 */
39static struct kmem_cache *ctx_cachep;
3ce8866c
SK
40/*
41 * error level for logging
42 */
43int ql_errlev = ql_log_all;
a9083016 44
fa492630 45static int ql2xenableclass2;
2d70c103
NB
46module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR);
47MODULE_PARM_DESC(ql2xenableclass2,
48 "Specify if Class 2 operations are supported from the very "
49 "beginning. Default is 0 - class 2 not supported.");
50
8ae6d9c7 51
1da177e4 52int ql2xlogintimeout = 20;
f2019cb1 53module_param(ql2xlogintimeout, int, S_IRUGO);
1da177e4
LT
54MODULE_PARM_DESC(ql2xlogintimeout,
55 "Login timeout value in seconds.");
56
a7b61842 57int qlport_down_retry;
f2019cb1 58module_param(qlport_down_retry, int, S_IRUGO);
1da177e4 59MODULE_PARM_DESC(qlport_down_retry,
900d9f98 60 "Maximum number of command retries to a port that returns "
1da177e4
LT
61 "a PORT-DOWN status.");
62
1da177e4
LT
63int ql2xplogiabsentdevice;
64module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
65MODULE_PARM_DESC(ql2xplogiabsentdevice,
66 "Option to enable PLOGI to devices that are not present after "
900d9f98 67 "a Fabric scan. This is needed for several broken switches. "
1da177e4
LT
68 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
69
1da177e4 70int ql2xloginretrycount = 0;
f2019cb1 71module_param(ql2xloginretrycount, int, S_IRUGO);
1da177e4
LT
72MODULE_PARM_DESC(ql2xloginretrycount,
73 "Specify an alternate value for the NVRAM login retry count.");
74
a7a167bf 75int ql2xallocfwdump = 1;
f2019cb1 76module_param(ql2xallocfwdump, int, S_IRUGO);
a7a167bf
AV
77MODULE_PARM_DESC(ql2xallocfwdump,
78 "Option to enable allocation of memory for a firmware dump "
79 "during HBA initialization. Memory allocation requirements "
80 "vary by ISP type. Default is 1 - allocate memory.");
81
11010fec 82int ql2xextended_error_logging;
27d94035 83module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
a2b3e01d 84module_param_named(logging, ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
11010fec 85MODULE_PARM_DESC(ql2xextended_error_logging,
3ce8866c
SK
86 "Option to enable extended error logging,\n"
87 "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
88 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
89 "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
90 "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
91 "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
92 "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
93 "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
94 "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
29f9f90c
CD
95 "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
96 "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
3ce8866c 97 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
cfb0919c
CD
98 "\t\t0x1e400000 - Preferred value for capturing essential "
99 "debug information (equivalent to old "
100 "ql2xextended_error_logging=1).\n"
3ce8866c 101 "\t\tDo LOGICAL OR of the value to enable more than one level");
0181944f 102
a9083016 103int ql2xshiftctondsd = 6;
f2019cb1 104module_param(ql2xshiftctondsd, int, S_IRUGO);
a9083016
GM
105MODULE_PARM_DESC(ql2xshiftctondsd,
106 "Set to control shifting of command type processing "
107 "based on total number of SG elements.");
108
7e47e5ca 109int ql2xfdmienable=1;
de187df8 110module_param(ql2xfdmienable, int, S_IRUGO|S_IWUSR);
a2b3e01d 111module_param_named(fdmi, ql2xfdmienable, int, S_IRUGO|S_IWUSR);
cca5335c 112MODULE_PARM_DESC(ql2xfdmienable,
7794a5af
FW
113 "Enables FDMI registrations. "
114 "0 - no FDMI. Default is 1 - perform FDMI.");
cca5335c 115
50280c01
CD
116#define MAX_Q_DEPTH 32
117static int ql2xmaxqdepth = MAX_Q_DEPTH;
df7baa50
AV
118module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
119MODULE_PARM_DESC(ql2xmaxqdepth,
e92e4a8f
CD
120 "Maximum queue depth to set for each LUN. "
121 "Default is 32.");
df7baa50 122
9e522cd8
AE
123int ql2xenabledif = 2;
124module_param(ql2xenabledif, int, S_IRUGO);
bad75002 125MODULE_PARM_DESC(ql2xenabledif,
b97f5d0b
SM
126 " Enable T10-CRC-DIF:\n"
127 " Default is 2.\n"
128 " 0 -- No DIF Support\n"
129 " 1 -- Enable DIF for all types\n"
130 " 2 -- Enable DIF for all types, except Type 0.\n");
bad75002 131
8cb2049c 132int ql2xenablehba_err_chk = 2;
bad75002
AE
133module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
134MODULE_PARM_DESC(ql2xenablehba_err_chk,
8cb2049c 135 " Enable T10-CRC-DIF Error isolation by HBA:\n"
b97f5d0b 136 " Default is 2.\n"
8cb2049c
AE
137 " 0 -- Error isolation disabled\n"
138 " 1 -- Error isolation enabled only for DIX Type 0\n"
139 " 2 -- Error isolation enabled for all Types\n");
bad75002 140
e5896bd5 141int ql2xiidmaenable=1;
f2019cb1 142module_param(ql2xiidmaenable, int, S_IRUGO);
e5896bd5
AV
143MODULE_PARM_DESC(ql2xiidmaenable,
144 "Enables iIDMA settings "
145 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
146
d7459527
MH
147int ql2xmqsupport = 1;
148module_param(ql2xmqsupport, int, S_IRUGO);
149MODULE_PARM_DESC(ql2xmqsupport,
150 "Enable on demand multiple queue pairs support "
151 "Default is 1 for supported. "
152 "Set it to 0 to turn off mq qpair support.");
e337d907
AV
153
154int ql2xfwloadbin;
86e45bf6 155module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
a2b3e01d 156module_param_named(fwload, ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
e337d907 157MODULE_PARM_DESC(ql2xfwloadbin,
7c3df132
SK
158 "Option to specify location from which to load ISP firmware:.\n"
159 " 2 -- load firmware via the request_firmware() (hotplug).\n"
e337d907
AV
160 " interface.\n"
161 " 1 -- load firmware from flash.\n"
162 " 0 -- use default semantics.\n");
163
ae97c91e 164int ql2xetsenable;
f2019cb1 165module_param(ql2xetsenable, int, S_IRUGO);
ae97c91e
AV
166MODULE_PARM_DESC(ql2xetsenable,
167 "Enables firmware ETS burst."
168 "Default is 0 - skip ETS enablement.");
169
6907869d 170int ql2xdbwr = 1;
86e45bf6 171module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
a9083016 172MODULE_PARM_DESC(ql2xdbwr,
08de2844
GM
173 "Option to specify scheme for request queue posting.\n"
174 " 0 -- Regular doorbell.\n"
175 " 1 -- CAMRAM doorbell (faster).\n");
a9083016 176
f4c496c1 177int ql2xtargetreset = 1;
f2019cb1 178module_param(ql2xtargetreset, int, S_IRUGO);
f4c496c1
GM
179MODULE_PARM_DESC(ql2xtargetreset,
180 "Enable target reset."
181 "Default is 1 - use hw defaults.");
182
4da26e16 183int ql2xgffidenable;
f2019cb1 184module_param(ql2xgffidenable, int, S_IRUGO);
4da26e16
CD
185MODULE_PARM_DESC(ql2xgffidenable,
186 "Enables GFF_ID checks of port type. "
187 "Default is 0 - Do not use GFF_ID information.");
a9083016 188
3822263e 189int ql2xasynctmfenable;
f2019cb1 190module_param(ql2xasynctmfenable, int, S_IRUGO);
3822263e
MI
191MODULE_PARM_DESC(ql2xasynctmfenable,
192 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
193 "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
ed0de87c
GM
194
195int ql2xdontresethba;
86e45bf6 196module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
ed0de87c 197MODULE_PARM_DESC(ql2xdontresethba,
08de2844
GM
198 "Option to specify reset behaviour.\n"
199 " 0 (Default) -- Reset on failure.\n"
200 " 1 -- Do not reset on failure.\n");
ed0de87c 201
1abf635d
HR
202uint64_t ql2xmaxlun = MAX_LUNS;
203module_param(ql2xmaxlun, ullong, S_IRUGO);
82515920
AV
204MODULE_PARM_DESC(ql2xmaxlun,
205 "Defines the maximum LU number to register with the SCSI "
206 "midlayer. Default is 65535.");
207
08de2844
GM
208int ql2xmdcapmask = 0x1F;
209module_param(ql2xmdcapmask, int, S_IRUGO);
210MODULE_PARM_DESC(ql2xmdcapmask,
211 "Set the Minidump driver capture mask level. "
6e96fa7b 212 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
08de2844 213
3aadff35 214int ql2xmdenable = 1;
08de2844
GM
215module_param(ql2xmdenable, int, S_IRUGO);
216MODULE_PARM_DESC(ql2xmdenable,
217 "Enable/disable MiniDump. "
3aadff35
GM
218 "0 - MiniDump disabled. "
219 "1 (Default) - MiniDump enabled.");
08de2844 220
b0d6cabd
HM
221int ql2xexlogins = 0;
222module_param(ql2xexlogins, uint, S_IRUGO|S_IWUSR);
223MODULE_PARM_DESC(ql2xexlogins,
224 "Number of extended Logins. "
225 "0 (Default)- Disabled.");
226
2f56a7f1
HM
227int ql2xexchoffld = 0;
228module_param(ql2xexchoffld, uint, S_IRUGO|S_IWUSR);
229MODULE_PARM_DESC(ql2xexchoffld,
230 "Number of exchanges to offload. "
231 "0 (Default)- Disabled.");
232
f198cafa
HM
233int ql2xfwholdabts = 0;
234module_param(ql2xfwholdabts, int, S_IRUGO);
235MODULE_PARM_DESC(ql2xfwholdabts,
236 "Allow FW to hold status IOCB until ABTS rsp received. "
237 "0 (Default) Do not set fw option. "
238 "1 - Set fw option to hold ABTS.");
239
41dc529a
QT
240int ql2xmvasynctoatio = 1;
241module_param(ql2xmvasynctoatio, int, S_IRUGO|S_IWUSR);
242MODULE_PARM_DESC(ql2xmvasynctoatio,
243 "Move PUREX, ABTS RX and RIDA IOCBs to ATIOQ"
244 "0 (Default). Do not move IOCBs"
245 "1 - Move IOCBs.");
246
1da177e4 247/*
fa2a1ce5 248 * SCSI host template entry points
1da177e4
LT
249 */
250static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051eb 251static int qla2xxx_slave_alloc(struct scsi_device *);
1e99e33a
AV
252static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
253static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051eb 254static void qla2xxx_slave_destroy(struct scsi_device *);
f281233d 255static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
1da177e4
LT
256static int qla2xxx_eh_abort(struct scsi_cmnd *);
257static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
523ec773 258static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
1da177e4
LT
259static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
260static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
1da177e4 261
1a2fbf18 262static void qla2x00_clear_drv_active(struct qla_hw_data *);
3491255e 263static void qla2x00_free_device(scsi_qla_host_t *);
2d5a4c34 264static void qla83xx_disable_laser(scsi_qla_host_t *vha);
5601236b 265static int qla2xxx_map_queues(struct Scsi_Host *shost);
ce7e4af7 266
a5326f86 267struct scsi_host_template qla2xxx_driver_template = {
1da177e4 268 .module = THIS_MODULE,
cb63067a 269 .name = QLA2XXX_DRIVER_NAME,
a5326f86 270 .queuecommand = qla2xxx_queuecommand,
fca29703 271
b6a05c82 272 .eh_timed_out = fc_eh_timed_out,
fca29703
AV
273 .eh_abort_handler = qla2xxx_eh_abort,
274 .eh_device_reset_handler = qla2xxx_eh_device_reset,
523ec773 275 .eh_target_reset_handler = qla2xxx_eh_target_reset,
fca29703
AV
276 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
277 .eh_host_reset_handler = qla2xxx_eh_host_reset,
278
279 .slave_configure = qla2xxx_slave_configure,
280
281 .slave_alloc = qla2xxx_slave_alloc,
282 .slave_destroy = qla2xxx_slave_destroy,
ed677086
AV
283 .scan_finished = qla2xxx_scan_finished,
284 .scan_start = qla2xxx_scan_start,
db5ed4df 285 .change_queue_depth = scsi_change_queue_depth,
5601236b 286 .map_queues = qla2xxx_map_queues,
fca29703
AV
287 .this_id = -1,
288 .cmd_per_lun = 3,
289 .use_clustering = ENABLE_CLUSTERING,
290 .sg_tablesize = SG_ALL,
291
292 .max_sectors = 0xFFFF,
afb046e2 293 .shost_attrs = qla2x00_host_attrs,
2d70c103
NB
294
295 .supported_mode = MODE_INITIATOR,
c40ecc12 296 .track_queue_depth = 1,
fca29703
AV
297};
298
1da177e4 299static struct scsi_transport_template *qla2xxx_transport_template = NULL;
2c3dfe3f 300struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
1da177e4 301
1da177e4
LT
302/* TODO Convert to inlines
303 *
304 * Timer routines
305 */
1da177e4 306
2c3dfe3f 307__inline__ void
e315cd28 308qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
1da177e4 309{
e315cd28
AC
310 init_timer(&vha->timer);
311 vha->timer.expires = jiffies + interval * HZ;
312 vha->timer.data = (unsigned long)vha;
313 vha->timer.function = (void (*)(unsigned long))func;
314 add_timer(&vha->timer);
315 vha->timer_active = 1;
1da177e4
LT
316}
317
318static inline void
e315cd28 319qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
1da177e4 320{
a9083016 321 /* Currently used for 82XX only. */
7c3df132
SK
322 if (vha->device_flags & DFLG_DEV_FAILED) {
323 ql_dbg(ql_dbg_timer, vha, 0x600d,
324 "Device in a failed state, returning.\n");
a9083016 325 return;
7c3df132 326 }
a9083016 327
e315cd28 328 mod_timer(&vha->timer, jiffies + interval * HZ);
1da177e4
LT
329}
330
a824ebb3 331static __inline__ void
e315cd28 332qla2x00_stop_timer(scsi_qla_host_t *vha)
1da177e4 333{
e315cd28
AC
334 del_timer_sync(&vha->timer);
335 vha->timer_active = 0;
1da177e4
LT
336}
337
1da177e4
LT
338static int qla2x00_do_dpc(void *data);
339
340static void qla2x00_rst_aen(scsi_qla_host_t *);
341
73208dfd
AC
342static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
343 struct req_que **, struct rsp_que **);
e30d1756 344static void qla2x00_free_fw_dump(struct qla_hw_data *);
e315cd28 345static void qla2x00_mem_free(struct qla_hw_data *);
d7459527
MH
346int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
347 struct qla_qpair *qpair);
1da177e4 348
1da177e4 349/* -------------------------------------------------------------------------- */
9a347ff4
CD
350static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
351 struct rsp_que *rsp)
73208dfd 352{
7c3df132 353 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
2afa19a9 354 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
73208dfd
AC
355 GFP_KERNEL);
356 if (!ha->req_q_map) {
7c3df132
SK
357 ql_log(ql_log_fatal, vha, 0x003b,
358 "Unable to allocate memory for request queue ptrs.\n");
73208dfd
AC
359 goto fail_req_map;
360 }
361
2afa19a9 362 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
73208dfd
AC
363 GFP_KERNEL);
364 if (!ha->rsp_q_map) {
7c3df132
SK
365 ql_log(ql_log_fatal, vha, 0x003c,
366 "Unable to allocate memory for response queue ptrs.\n");
73208dfd
AC
367 goto fail_rsp_map;
368 }
d7459527
MH
369
370 if (ql2xmqsupport && ha->max_qpairs) {
371 ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct qla_qpair *),
372 GFP_KERNEL);
373 if (!ha->queue_pair_map) {
374 ql_log(ql_log_fatal, vha, 0x0180,
375 "Unable to allocate memory for queue pair ptrs.\n");
376 goto fail_qpair_map;
377 }
378 ha->base_qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
379 if (ha->base_qpair == NULL) {
380 ql_log(ql_log_warn, vha, 0x0182,
381 "Failed to allocate base queue pair memory.\n");
382 goto fail_base_qpair;
383 }
384 ha->base_qpair->req = req;
385 ha->base_qpair->rsp = rsp;
386 }
387
9a347ff4
CD
388 /*
389 * Make sure we record at least the request and response queue zero in
390 * case we need to free them if part of the probe fails.
391 */
392 ha->rsp_q_map[0] = rsp;
393 ha->req_q_map[0] = req;
73208dfd
AC
394 set_bit(0, ha->rsp_qid_map);
395 set_bit(0, ha->req_qid_map);
396 return 1;
397
d7459527
MH
398fail_base_qpair:
399 kfree(ha->queue_pair_map);
400fail_qpair_map:
401 kfree(ha->rsp_q_map);
402 ha->rsp_q_map = NULL;
73208dfd
AC
403fail_rsp_map:
404 kfree(ha->req_q_map);
405 ha->req_q_map = NULL;
406fail_req_map:
407 return -ENOMEM;
408}
409
2afa19a9 410static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
73208dfd 411{
8ae6d9c7
GM
412 if (IS_QLAFX00(ha)) {
413 if (req && req->ring_fx00)
414 dma_free_coherent(&ha->pdev->dev,
415 (req->length_fx00 + 1) * sizeof(request_t),
416 req->ring_fx00, req->dma_fx00);
417 } else if (req && req->ring)
73208dfd
AC
418 dma_free_coherent(&ha->pdev->dev,
419 (req->length + 1) * sizeof(request_t),
420 req->ring, req->dma);
421
8d93f550
CD
422 if (req)
423 kfree(req->outstanding_cmds);
424
73208dfd
AC
425 kfree(req);
426 req = NULL;
427}
428
2afa19a9
AC
429static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
430{
8ae6d9c7
GM
431 if (IS_QLAFX00(ha)) {
432 if (rsp && rsp->ring)
433 dma_free_coherent(&ha->pdev->dev,
434 (rsp->length_fx00 + 1) * sizeof(request_t),
435 rsp->ring_fx00, rsp->dma_fx00);
436 } else if (rsp && rsp->ring) {
2afa19a9
AC
437 dma_free_coherent(&ha->pdev->dev,
438 (rsp->length + 1) * sizeof(response_t),
439 rsp->ring, rsp->dma);
8ae6d9c7 440 }
2afa19a9
AC
441 kfree(rsp);
442 rsp = NULL;
443}
444
73208dfd
AC
445static void qla2x00_free_queues(struct qla_hw_data *ha)
446{
447 struct req_que *req;
448 struct rsp_que *rsp;
449 int cnt;
093df737 450 unsigned long flags;
73208dfd 451
093df737 452 spin_lock_irqsave(&ha->hardware_lock, flags);
2afa19a9 453 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
cb43285f
QT
454 if (!test_bit(cnt, ha->req_qid_map))
455 continue;
456
73208dfd 457 req = ha->req_q_map[cnt];
093df737
QT
458 clear_bit(cnt, ha->req_qid_map);
459 ha->req_q_map[cnt] = NULL;
460
461 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2afa19a9 462 qla2x00_free_req_que(ha, req);
093df737 463 spin_lock_irqsave(&ha->hardware_lock, flags);
73208dfd 464 }
093df737
QT
465 spin_unlock_irqrestore(&ha->hardware_lock, flags);
466
73208dfd
AC
467 kfree(ha->req_q_map);
468 ha->req_q_map = NULL;
2afa19a9 469
093df737
QT
470
471 spin_lock_irqsave(&ha->hardware_lock, flags);
2afa19a9 472 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
cb43285f
QT
473 if (!test_bit(cnt, ha->rsp_qid_map))
474 continue;
475
2afa19a9 476 rsp = ha->rsp_q_map[cnt];
c3c42394 477 clear_bit(cnt, ha->rsp_qid_map);
093df737
QT
478 ha->rsp_q_map[cnt] = NULL;
479 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2afa19a9 480 qla2x00_free_rsp_que(ha, rsp);
093df737 481 spin_lock_irqsave(&ha->hardware_lock, flags);
2afa19a9 482 }
093df737
QT
483 spin_unlock_irqrestore(&ha->hardware_lock, flags);
484
2afa19a9
AC
485 kfree(ha->rsp_q_map);
486 ha->rsp_q_map = NULL;
73208dfd
AC
487}
488
1da177e4 489static char *
e315cd28 490qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
1da177e4 491{
e315cd28 492 struct qla_hw_data *ha = vha->hw;
1da177e4
LT
493 static char *pci_bus_modes[] = {
494 "33", "66", "100", "133",
495 };
496 uint16_t pci_bus;
497
498 strcpy(str, "PCI");
499 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
500 if (pci_bus) {
501 strcat(str, "-X (");
502 strcat(str, pci_bus_modes[pci_bus]);
503 } else {
504 pci_bus = (ha->pci_attr & BIT_8) >> 8;
505 strcat(str, " (");
506 strcat(str, pci_bus_modes[pci_bus]);
507 }
508 strcat(str, " MHz)");
509
510 return (str);
511}
512
fca29703 513static char *
e315cd28 514qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
fca29703
AV
515{
516 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
e315cd28 517 struct qla_hw_data *ha = vha->hw;
fca29703 518 uint32_t pci_bus;
fca29703 519
62a276f8 520 if (pci_is_pcie(ha->pdev)) {
fca29703 521 char lwstr[6];
62a276f8 522 uint32_t lstat, lspeed, lwidth;
fca29703 523
62a276f8
BH
524 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
525 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
526 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
fca29703
AV
527
528 strcpy(str, "PCIe (");
49300af7
SK
529 switch (lspeed) {
530 case 1:
c87a0d8c 531 strcat(str, "2.5GT/s ");
49300af7
SK
532 break;
533 case 2:
c87a0d8c 534 strcat(str, "5.0GT/s ");
49300af7
SK
535 break;
536 case 3:
537 strcat(str, "8.0GT/s ");
538 break;
539 default:
fca29703 540 strcat(str, "<unknown> ");
49300af7
SK
541 break;
542 }
fca29703
AV
543 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
544 strcat(str, lwstr);
545
546 return str;
547 }
548
549 strcpy(str, "PCI");
550 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
551 if (pci_bus == 0 || pci_bus == 8) {
552 strcat(str, " (");
553 strcat(str, pci_bus_modes[pci_bus >> 3]);
554 } else {
555 strcat(str, "-X ");
556 if (pci_bus & BIT_2)
557 strcat(str, "Mode 2");
558 else
559 strcat(str, "Mode 1");
560 strcat(str, " (");
561 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
562 }
563 strcat(str, " MHz)");
564
565 return str;
566}
567
e5f82ab8 568static char *
df57caba 569qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
1da177e4
LT
570{
571 char un_str[10];
e315cd28 572 struct qla_hw_data *ha = vha->hw;
fa2a1ce5 573
df57caba
HM
574 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
575 ha->fw_minor_version, ha->fw_subminor_version);
1da177e4
LT
576
577 if (ha->fw_attributes & BIT_9) {
578 strcat(str, "FLX");
579 return (str);
580 }
581
582 switch (ha->fw_attributes & 0xFF) {
583 case 0x7:
584 strcat(str, "EF");
585 break;
586 case 0x17:
587 strcat(str, "TP");
588 break;
589 case 0x37:
590 strcat(str, "IP");
591 break;
592 case 0x77:
593 strcat(str, "VI");
594 break;
595 default:
596 sprintf(un_str, "(%x)", ha->fw_attributes);
597 strcat(str, un_str);
598 break;
599 }
600 if (ha->fw_attributes & 0x100)
601 strcat(str, "X");
602
603 return (str);
604}
605
e5f82ab8 606static char *
df57caba 607qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
fca29703 608{
e315cd28 609 struct qla_hw_data *ha = vha->hw;
f0883ac6 610
df57caba 611 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
3a03eb79 612 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
fca29703 613 return str;
fca29703
AV
614}
615
9ba56b95 616void
25ff6af1 617qla2x00_sp_free_dma(void *ptr)
fca29703 618{
25ff6af1
JC
619 srb_t *sp = ptr;
620 struct qla_hw_data *ha = sp->vha->hw;
9ba56b95 621 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
9ba56b95 622 void *ctx = GET_CMD_CTX_SP(sp);
fca29703 623
9ba56b95
GM
624 if (sp->flags & SRB_DMA_VALID) {
625 scsi_dma_unmap(cmd);
626 sp->flags &= ~SRB_DMA_VALID;
7c3df132 627 }
fca29703 628
9ba56b95
GM
629 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
630 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
631 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
632 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
633 }
634
635 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
636 /* List assured to be having elements */
f83adb61 637 qla2x00_clean_dsd_pool(ha, sp, NULL);
9ba56b95
GM
638 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
639 }
640
641 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
642 dma_pool_free(ha->dl_dma_pool, ctx,
643 ((struct crc_context *)ctx)->crc_ctx_dma);
644 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
645 }
646
647 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
648 struct ct6_dsd *ctx1 = (struct ct6_dsd *)ctx;
fca29703 649
9ba56b95
GM
650 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
651 ctx1->fcp_cmnd_dma);
652 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
653 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
654 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
655 mempool_free(ctx1, ha->ctx_mempool);
656 ctx1 = NULL;
657 }
658
659 CMD_SP(cmd) = NULL;
25ff6af1 660 qla2x00_rel_sp(sp);
9ba56b95
GM
661}
662
d7459527 663void
25ff6af1 664qla2x00_sp_compl(void *ptr, int res)
9ba56b95 665{
25ff6af1 666 srb_t *sp = ptr;
9ba56b95
GM
667 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
668
669 cmd->result = res;
670
671 if (atomic_read(&sp->ref_count) == 0) {
25ff6af1 672 ql_dbg(ql_dbg_io, sp->vha, 0x3015,
9ba56b95
GM
673 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
674 sp, GET_CMD_SP(sp));
675 if (ql2xextended_error_logging & ql_dbg_io)
8fbdac8c 676 WARN_ON(atomic_read(&sp->ref_count) == 0);
9ba56b95
GM
677 return;
678 }
679 if (!atomic_dec_and_test(&sp->ref_count))
680 return;
681
25ff6af1 682 qla2x00_sp_free_dma(sp);
9ba56b95 683 cmd->scsi_done(cmd);
fca29703
AV
684}
685
d7459527 686void
25ff6af1 687qla2xxx_qpair_sp_free_dma(void *ptr)
d7459527
MH
688{
689 srb_t *sp = (srb_t *)ptr;
690 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
691 struct qla_hw_data *ha = sp->fcport->vha->hw;
692 void *ctx = GET_CMD_CTX_SP(sp);
693
694 if (sp->flags & SRB_DMA_VALID) {
695 scsi_dma_unmap(cmd);
696 sp->flags &= ~SRB_DMA_VALID;
697 }
698
699 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
700 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
701 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
702 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
703 }
704
705 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
706 /* List assured to be having elements */
707 qla2x00_clean_dsd_pool(ha, sp, NULL);
708 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
709 }
710
711 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
712 dma_pool_free(ha->dl_dma_pool, ctx,
713 ((struct crc_context *)ctx)->crc_ctx_dma);
714 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
715 }
716
717 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
718 struct ct6_dsd *ctx1 = (struct ct6_dsd *)ctx;
719
720 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
721 ctx1->fcp_cmnd_dma);
722 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
723 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
724 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
725 mempool_free(ctx1, ha->ctx_mempool);
726 }
727
728 CMD_SP(cmd) = NULL;
729 qla2xxx_rel_qpair_sp(sp->qpair, sp);
730}
731
732void
25ff6af1 733qla2xxx_qpair_sp_compl(void *ptr, int res)
d7459527 734{
25ff6af1 735 srb_t *sp = ptr;
d7459527
MH
736 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
737
738 cmd->result = res;
739
740 if (atomic_read(&sp->ref_count) == 0) {
741 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3079,
742 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
743 sp, GET_CMD_SP(sp));
744 if (ql2xextended_error_logging & ql_dbg_io)
745 WARN_ON(atomic_read(&sp->ref_count) == 0);
746 return;
747 }
748 if (!atomic_dec_and_test(&sp->ref_count))
749 return;
750
25ff6af1 751 qla2xxx_qpair_sp_free_dma(sp);
d7459527
MH
752 cmd->scsi_done(cmd);
753}
754
8ae6d9c7
GM
755/* If we are SP1 here, we need to still take and release the host_lock as SP1
756 * does not have the changes necessary to avoid taking host->host_lock.
757 */
1da177e4 758static int
f5e3e40b 759qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
fca29703 760{
134ae078 761 scsi_qla_host_t *vha = shost_priv(host);
fca29703 762 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
19a7b4ae 763 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
e315cd28
AC
764 struct qla_hw_data *ha = vha->hw;
765 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
fca29703
AV
766 srb_t *sp;
767 int rval;
5601236b
MH
768 struct qla_qpair *qpair = NULL;
769 uint32_t tag;
770 uint16_t hwq;
fca29703 771
04dfaa53
MFO
772 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags))) {
773 cmd->result = DID_NO_CONNECT << 16;
774 goto qc24_fail_command;
775 }
776
5601236b
MH
777 if (ha->mqenable) {
778 if (shost_use_blk_mq(vha->host)) {
779 tag = blk_mq_unique_tag(cmd->request);
780 hwq = blk_mq_unique_tag_to_hwq(tag);
781 qpair = ha->queue_pair_map[hwq];
782 } else if (vha->vp_idx && vha->qpair) {
783 qpair = vha->qpair;
784 }
785
786 if (qpair)
787 return qla2xxx_mqueuecommand(host, cmd, qpair);
d7459527
MH
788 }
789
85880801 790 if (ha->flags.eeh_busy) {
7c3df132 791 if (ha->flags.pci_channel_io_perm_failure) {
5f28d2d7 792 ql_dbg(ql_dbg_aer, vha, 0x9010,
7c3df132
SK
793 "PCI Channel IO permanent failure, exiting "
794 "cmd=%p.\n", cmd);
b9b12f73 795 cmd->result = DID_NO_CONNECT << 16;
7c3df132 796 } else {
5f28d2d7 797 ql_dbg(ql_dbg_aer, vha, 0x9011,
7c3df132 798 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
85880801 799 cmd->result = DID_REQUEUE << 16;
7c3df132 800 }
14e660e6
SJ
801 goto qc24_fail_command;
802 }
803
19a7b4ae
JSEC
804 rval = fc_remote_port_chkready(rport);
805 if (rval) {
806 cmd->result = rval;
5f28d2d7 807 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
7c3df132
SK
808 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
809 cmd, rval);
fca29703
AV
810 goto qc24_fail_command;
811 }
812
bad75002
AE
813 if (!vha->flags.difdix_supported &&
814 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
7c3df132
SK
815 ql_dbg(ql_dbg_io, vha, 0x3004,
816 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
817 cmd);
bad75002
AE
818 cmd->result = DID_NO_CONNECT << 16;
819 goto qc24_fail_command;
820 }
aa651be8
CD
821
822 if (!fcport) {
823 cmd->result = DID_NO_CONNECT << 16;
824 goto qc24_fail_command;
825 }
826
fca29703
AV
827 if (atomic_read(&fcport->state) != FCS_ONLINE) {
828 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
38170fa8 829 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
7c3df132
SK
830 ql_dbg(ql_dbg_io, vha, 0x3005,
831 "Returning DNC, fcport_state=%d loop_state=%d.\n",
832 atomic_read(&fcport->state),
833 atomic_read(&base_vha->loop_state));
fca29703
AV
834 cmd->result = DID_NO_CONNECT << 16;
835 goto qc24_fail_command;
836 }
7b594131 837 goto qc24_target_busy;
fca29703
AV
838 }
839
e05fe292
CD
840 /*
841 * Return target busy if we've received a non-zero retry_delay_timer
842 * in a FCP_RSP.
843 */
975f7d46
BP
844 if (fcport->retry_delay_timestamp == 0) {
845 /* retry delay not set */
846 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
e05fe292
CD
847 fcport->retry_delay_timestamp = 0;
848 else
849 goto qc24_target_busy;
850
b00ee7d7 851 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
50280c01 852 if (!sp)
f5e3e40b 853 goto qc24_host_busy;
fca29703 854
9ba56b95
GM
855 sp->u.scmd.cmd = cmd;
856 sp->type = SRB_SCSI_CMD;
857 atomic_set(&sp->ref_count, 1);
858 CMD_SP(cmd) = (void *)sp;
859 sp->free = qla2x00_sp_free_dma;
860 sp->done = qla2x00_sp_compl;
861
e315cd28 862 rval = ha->isp_ops->start_scsi(sp);
7c3df132 863 if (rval != QLA_SUCCESS) {
53016ed3 864 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
7c3df132 865 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
fca29703 866 goto qc24_host_busy_free_sp;
7c3df132 867 }
fca29703 868
fca29703
AV
869 return 0;
870
871qc24_host_busy_free_sp:
25ff6af1 872 qla2x00_sp_free_dma(sp);
fca29703 873
f5e3e40b 874qc24_host_busy:
fca29703
AV
875 return SCSI_MLQUEUE_HOST_BUSY;
876
7b594131
MC
877qc24_target_busy:
878 return SCSI_MLQUEUE_TARGET_BUSY;
879
fca29703 880qc24_fail_command:
f5e3e40b 881 cmd->scsi_done(cmd);
fca29703
AV
882
883 return 0;
884}
885
d7459527
MH
886/* For MQ supported I/O */
887int
888qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
889 struct qla_qpair *qpair)
890{
891 scsi_qla_host_t *vha = shost_priv(host);
892 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
893 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
894 struct qla_hw_data *ha = vha->hw;
895 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
896 srb_t *sp;
897 int rval;
898
899 rval = fc_remote_port_chkready(rport);
900 if (rval) {
901 cmd->result = rval;
902 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
903 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
904 cmd, rval);
905 goto qc24_fail_command;
906 }
907
908 if (!fcport) {
909 cmd->result = DID_NO_CONNECT << 16;
910 goto qc24_fail_command;
911 }
912
913 if (atomic_read(&fcport->state) != FCS_ONLINE) {
914 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
915 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
916 ql_dbg(ql_dbg_io, vha, 0x3077,
917 "Returning DNC, fcport_state=%d loop_state=%d.\n",
918 atomic_read(&fcport->state),
919 atomic_read(&base_vha->loop_state));
920 cmd->result = DID_NO_CONNECT << 16;
921 goto qc24_fail_command;
922 }
923 goto qc24_target_busy;
924 }
925
926 /*
927 * Return target busy if we've received a non-zero retry_delay_timer
928 * in a FCP_RSP.
929 */
930 if (fcport->retry_delay_timestamp == 0) {
931 /* retry delay not set */
932 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
933 fcport->retry_delay_timestamp = 0;
934 else
935 goto qc24_target_busy;
936
937 sp = qla2xxx_get_qpair_sp(qpair, fcport, GFP_ATOMIC);
938 if (!sp)
939 goto qc24_host_busy;
940
941 sp->u.scmd.cmd = cmd;
942 sp->type = SRB_SCSI_CMD;
943 atomic_set(&sp->ref_count, 1);
944 CMD_SP(cmd) = (void *)sp;
945 sp->free = qla2xxx_qpair_sp_free_dma;
946 sp->done = qla2xxx_qpair_sp_compl;
947 sp->qpair = qpair;
948
949 rval = ha->isp_ops->start_scsi_mq(sp);
950 if (rval != QLA_SUCCESS) {
951 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
952 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
953 if (rval == QLA_INTERFACE_ERROR)
954 goto qc24_fail_command;
955 goto qc24_host_busy_free_sp;
956 }
957
958 return 0;
959
960qc24_host_busy_free_sp:
25ff6af1 961 qla2xxx_qpair_sp_free_dma(sp);
d7459527
MH
962
963qc24_host_busy:
964 return SCSI_MLQUEUE_HOST_BUSY;
965
966qc24_target_busy:
967 return SCSI_MLQUEUE_TARGET_BUSY;
968
969qc24_fail_command:
970 cmd->scsi_done(cmd);
971
972 return 0;
973}
974
1da177e4
LT
975/*
976 * qla2x00_eh_wait_on_command
977 * Waits for the command to be returned by the Firmware for some
978 * max time.
979 *
980 * Input:
1da177e4 981 * cmd = Scsi Command to wait on.
1da177e4
LT
982 *
983 * Return:
984 * Not Found : 0
985 * Found : 1
986 */
987static int
e315cd28 988qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
1da177e4 989{
fe74c71f 990#define ABORT_POLLING_PERIOD 1000
478c3b03 991#define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
f4f051eb 992 unsigned long wait_iter = ABORT_WAIT_ITER;
85880801
AV
993 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
994 struct qla_hw_data *ha = vha->hw;
f4f051eb 995 int ret = QLA_SUCCESS;
1da177e4 996
85880801 997 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
7c3df132
SK
998 ql_dbg(ql_dbg_taskm, vha, 0x8005,
999 "Return:eh_wait.\n");
85880801
AV
1000 return ret;
1001 }
1002
d970432c 1003 while (CMD_SP(cmd) && wait_iter--) {
fe74c71f 1004 msleep(ABORT_POLLING_PERIOD);
f4f051eb
AV
1005 }
1006 if (CMD_SP(cmd))
1007 ret = QLA_FUNCTION_FAILED;
1da177e4 1008
f4f051eb 1009 return ret;
1da177e4
LT
1010}
1011
1012/*
1013 * qla2x00_wait_for_hba_online
fa2a1ce5 1014 * Wait till the HBA is online after going through
1da177e4
LT
1015 * <= MAX_RETRIES_OF_ISP_ABORT or
1016 * finally HBA is disabled ie marked offline
1017 *
1018 * Input:
1019 * ha - pointer to host adapter structure
fa2a1ce5
AV
1020 *
1021 * Note:
1da177e4
LT
1022 * Does context switching-Release SPIN_LOCK
1023 * (if any) before calling this routine.
1024 *
1025 * Return:
1026 * Success (Adapter is online) : 0
1027 * Failed (Adapter is offline/disabled) : 1
1028 */
854165f4 1029int
e315cd28 1030qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
1da177e4 1031{
fca29703
AV
1032 int return_status;
1033 unsigned long wait_online;
e315cd28
AC
1034 struct qla_hw_data *ha = vha->hw;
1035 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1da177e4 1036
fa2a1ce5 1037 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
e315cd28
AC
1038 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1039 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1040 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1041 ha->dpc_active) && time_before(jiffies, wait_online)) {
1da177e4
LT
1042
1043 msleep(1000);
1044 }
e315cd28 1045 if (base_vha->flags.online)
fa2a1ce5 1046 return_status = QLA_SUCCESS;
1da177e4
LT
1047 else
1048 return_status = QLA_FUNCTION_FAILED;
1049
1da177e4
LT
1050 return (return_status);
1051}
1052
726b8548
QT
1053static inline int test_fcport_count(scsi_qla_host_t *vha)
1054{
1055 struct qla_hw_data *ha = vha->hw;
1056 unsigned long flags;
1057 int res;
1058
1059 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
1060 ql_dbg(ql_dbg_init, vha, 0xffff,
1061 "tgt %p, fcport_count=%d\n",
1062 vha, vha->fcport_count);
1063 res = (vha->fcport_count == 0);
1064 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1065
1066 return res;
1067}
1068
1069/*
1070 * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1071 * it has dependency on UNLOADING flag to stop device discovery
1072 */
1073static void
1074qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1075{
1076 qla2x00_mark_all_devices_lost(vha, 0);
1077
1078 wait_event(vha->fcport_waitQ, test_fcport_count(vha));
1079}
1080
86fbee86 1081/*
638a1a01
SC
1082 * qla2x00_wait_for_hba_ready
1083 * Wait till the HBA is ready before doing driver unload
86fbee86
LC
1084 *
1085 * Input:
1086 * ha - pointer to host adapter structure
1087 *
1088 * Note:
1089 * Does context switching-Release SPIN_LOCK
1090 * (if any) before calling this routine.
1091 *
86fbee86 1092 */
638a1a01
SC
1093static void
1094qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
86fbee86 1095{
86fbee86 1096 struct qla_hw_data *ha = vha->hw;
783e0dc4 1097 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
86fbee86 1098
1d483901
DC
1099 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
1100 ha->flags.mbox_busy) ||
1101 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
1102 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
1103 if (test_bit(UNLOADING, &base_vha->dpc_flags))
1104 break;
86fbee86 1105 msleep(1000);
783e0dc4 1106 }
86fbee86
LC
1107}
1108
2533cf67
LC
1109int
1110qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
1111{
1112 int return_status;
1113 unsigned long wait_reset;
1114 struct qla_hw_data *ha = vha->hw;
1115 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1116
1117 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1118 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1119 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1120 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1121 ha->dpc_active) && time_before(jiffies, wait_reset)) {
1122
1123 msleep(1000);
1124
1125 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1126 ha->flags.chip_reset_done)
1127 break;
1128 }
1129 if (ha->flags.chip_reset_done)
1130 return_status = QLA_SUCCESS;
1131 else
1132 return_status = QLA_FUNCTION_FAILED;
1133
1134 return return_status;
1135}
1136
083a469d
GM
1137static void
1138sp_get(struct srb *sp)
1139{
1140 atomic_inc(&sp->ref_count);
1141}
1142
a465537a
SC
1143#define ISP_REG_DISCONNECT 0xffffffffU
1144/**************************************************************************
1145* qla2x00_isp_reg_stat
1146*
1147* Description:
1148* Read the host status register of ISP before aborting the command.
1149*
1150* Input:
1151* ha = pointer to host adapter structure.
1152*
1153*
1154* Returns:
1155* Either true or false.
1156*
1157* Note: Return true if there is register disconnect.
1158**************************************************************************/
1159static inline
1160uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
1161{
1162 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1163
1164 return ((RD_REG_DWORD(&reg->host_status)) == ISP_REG_DISCONNECT);
1165}
1166
1da177e4
LT
1167/**************************************************************************
1168* qla2xxx_eh_abort
1169*
1170* Description:
1171* The abort function will abort the specified command.
1172*
1173* Input:
1174* cmd = Linux SCSI command packet to be aborted.
1175*
1176* Returns:
1177* Either SUCCESS or FAILED.
1178*
1179* Note:
2ea00202 1180* Only return FAILED if command not returned by firmware.
1da177e4 1181**************************************************************************/
e5f82ab8 1182static int
1da177e4
LT
1183qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1184{
e315cd28 1185 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051eb 1186 srb_t *sp;
4e98d3b8 1187 int ret;
9cb78c16
HR
1188 unsigned int id;
1189 uint64_t lun;
18e144d3 1190 unsigned long flags;
f934c9d0 1191 int rval, wait = 0;
e315cd28 1192 struct qla_hw_data *ha = vha->hw;
1da177e4 1193
a465537a
SC
1194 if (qla2x00_isp_reg_stat(ha)) {
1195 ql_log(ql_log_info, vha, 0x8042,
1196 "PCI/Register disconnect, exiting.\n");
1197 return FAILED;
1198 }
f4f051eb 1199 if (!CMD_SP(cmd))
2ea00202 1200 return SUCCESS;
1da177e4 1201
4e98d3b8
AV
1202 ret = fc_block_scsi_eh(cmd);
1203 if (ret != 0)
1204 return ret;
1205 ret = SUCCESS;
1206
f4f051eb
AV
1207 id = cmd->device->id;
1208 lun = cmd->device->lun;
1da177e4 1209
e315cd28 1210 spin_lock_irqsave(&ha->hardware_lock, flags);
170babc3
MC
1211 sp = (srb_t *) CMD_SP(cmd);
1212 if (!sp) {
1213 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1214 return SUCCESS;
1215 }
1da177e4 1216
7c3df132 1217 ql_dbg(ql_dbg_taskm, vha, 0x8002,
c7bc4cae
CD
1218 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1219 vha->host_no, id, lun, sp, cmd, sp->handle);
17d98630 1220
170babc3
MC
1221 /* Get a reference to the sp and drop the lock.*/
1222 sp_get(sp);
083a469d 1223
e315cd28 1224 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f934c9d0
CD
1225 rval = ha->isp_ops->abort_command(sp);
1226 if (rval) {
96219424 1227 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
f934c9d0 1228 ret = SUCCESS;
96219424 1229 else
f934c9d0
CD
1230 ret = FAILED;
1231
7c3df132 1232 ql_dbg(ql_dbg_taskm, vha, 0x8003,
f934c9d0 1233 "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
170babc3 1234 } else {
7c3df132 1235 ql_dbg(ql_dbg_taskm, vha, 0x8004,
cfb0919c 1236 "Abort command mbx success cmd=%p.\n", cmd);
170babc3
MC
1237 wait = 1;
1238 }
75942064
SK
1239
1240 spin_lock_irqsave(&ha->hardware_lock, flags);
25ff6af1 1241 sp->done(sp, 0);
75942064 1242 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1da177e4 1243
bc91ade9
CD
1244 /* Did the command return during mailbox execution? */
1245 if (ret == FAILED && !CMD_SP(cmd))
1246 ret = SUCCESS;
1247
f4f051eb 1248 /* Wait for the command to be returned. */
2ea00202 1249 if (wait) {
e315cd28 1250 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
7c3df132 1251 ql_log(ql_log_warn, vha, 0x8006,
cfb0919c 1252 "Abort handler timed out cmd=%p.\n", cmd);
2ea00202 1253 ret = FAILED;
f4f051eb 1254 }
1da177e4 1255 }
1da177e4 1256
7c3df132 1257 ql_log(ql_log_info, vha, 0x801c,
9cb78c16 1258 "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
cfb0919c 1259 vha->host_no, id, lun, wait, ret);
1da177e4 1260
f4f051eb
AV
1261 return ret;
1262}
1da177e4 1263
4d78c973 1264int
e315cd28 1265qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
9cb78c16 1266 uint64_t l, enum nexus_wait_type type)
f4f051eb 1267{
17d98630 1268 int cnt, match, status;
18e144d3 1269 unsigned long flags;
e315cd28 1270 struct qla_hw_data *ha = vha->hw;
73208dfd 1271 struct req_que *req;
4d78c973 1272 srb_t *sp;
9ba56b95 1273 struct scsi_cmnd *cmd;
1da177e4 1274
523ec773 1275 status = QLA_SUCCESS;
17d98630 1276
e315cd28 1277 spin_lock_irqsave(&ha->hardware_lock, flags);
67c2e93a 1278 req = vha->req;
17d98630 1279 for (cnt = 1; status == QLA_SUCCESS &&
8d93f550 1280 cnt < req->num_outstanding_cmds; cnt++) {
17d98630
AC
1281 sp = req->outstanding_cmds[cnt];
1282 if (!sp)
523ec773 1283 continue;
9ba56b95 1284 if (sp->type != SRB_SCSI_CMD)
cf53b069 1285 continue;
25ff6af1 1286 if (vha->vp_idx != sp->vha->vp_idx)
17d98630
AC
1287 continue;
1288 match = 0;
9ba56b95 1289 cmd = GET_CMD_SP(sp);
17d98630
AC
1290 switch (type) {
1291 case WAIT_HOST:
1292 match = 1;
1293 break;
1294 case WAIT_TARGET:
9ba56b95 1295 match = cmd->device->id == t;
17d98630
AC
1296 break;
1297 case WAIT_LUN:
9ba56b95
GM
1298 match = (cmd->device->id == t &&
1299 cmd->device->lun == l);
17d98630 1300 break;
73208dfd 1301 }
17d98630
AC
1302 if (!match)
1303 continue;
1304
1305 spin_unlock_irqrestore(&ha->hardware_lock, flags);
9ba56b95 1306 status = qla2x00_eh_wait_on_command(cmd);
17d98630 1307 spin_lock_irqsave(&ha->hardware_lock, flags);
1da177e4 1308 }
e315cd28 1309 spin_unlock_irqrestore(&ha->hardware_lock, flags);
523ec773
AV
1310
1311 return status;
1da177e4
LT
1312}
1313
523ec773
AV
1314static char *reset_errors[] = {
1315 "HBA not online",
1316 "HBA not ready",
1317 "Task management failed",
1318 "Waiting for command completions",
1319};
1da177e4 1320
e5f82ab8 1321static int
523ec773 1322__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
9cb78c16 1323 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
1da177e4 1324{
e315cd28 1325 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79621 1326 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
523ec773 1327 int err;
1da177e4 1328
7c3df132 1329 if (!fcport) {
523ec773 1330 return FAILED;
7c3df132 1331 }
1da177e4 1332
4e98d3b8
AV
1333 err = fc_block_scsi_eh(cmd);
1334 if (err != 0)
1335 return err;
1336
7c3df132 1337 ql_log(ql_log_info, vha, 0x8009,
9cb78c16 1338 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
7c3df132 1339 cmd->device->id, cmd->device->lun, cmd);
1da177e4 1340
523ec773 1341 err = 0;
7c3df132
SK
1342 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1343 ql_log(ql_log_warn, vha, 0x800a,
1344 "Wait for hba online failed for cmd=%p.\n", cmd);
523ec773 1345 goto eh_reset_failed;
7c3df132 1346 }
523ec773 1347 err = 2;
2afa19a9 1348 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
7c3df132
SK
1349 != QLA_SUCCESS) {
1350 ql_log(ql_log_warn, vha, 0x800c,
1351 "do_reset failed for cmd=%p.\n", cmd);
523ec773 1352 goto eh_reset_failed;
7c3df132 1353 }
523ec773 1354 err = 3;
e315cd28 1355 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
7c3df132
SK
1356 cmd->device->lun, type) != QLA_SUCCESS) {
1357 ql_log(ql_log_warn, vha, 0x800d,
d6a03581 1358 "wait for pending cmds failed for cmd=%p.\n", cmd);
523ec773 1359 goto eh_reset_failed;
7c3df132 1360 }
523ec773 1361
7c3df132 1362 ql_log(ql_log_info, vha, 0x800e,
9cb78c16 1363 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
cfb0919c 1364 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
523ec773
AV
1365
1366 return SUCCESS;
1367
4d78c973 1368eh_reset_failed:
7c3df132 1369 ql_log(ql_log_info, vha, 0x800f,
9cb78c16 1370 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
cfb0919c
CD
1371 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1372 cmd);
523ec773
AV
1373 return FAILED;
1374}
1da177e4 1375
523ec773
AV
1376static int
1377qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1378{
e315cd28
AC
1379 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1380 struct qla_hw_data *ha = vha->hw;
1da177e4 1381
a465537a
SC
1382 if (qla2x00_isp_reg_stat(ha)) {
1383 ql_log(ql_log_info, vha, 0x803e,
1384 "PCI/Register disconnect, exiting.\n");
1385 return FAILED;
1386 }
1387
523ec773
AV
1388 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1389 ha->isp_ops->lun_reset);
1da177e4
LT
1390}
1391
1da177e4 1392static int
523ec773 1393qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
1da177e4 1394{
e315cd28
AC
1395 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1396 struct qla_hw_data *ha = vha->hw;
1da177e4 1397
a465537a
SC
1398 if (qla2x00_isp_reg_stat(ha)) {
1399 ql_log(ql_log_info, vha, 0x803f,
1400 "PCI/Register disconnect, exiting.\n");
1401 return FAILED;
1402 }
1403
523ec773
AV
1404 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1405 ha->isp_ops->target_reset);
1da177e4
LT
1406}
1407
1da177e4
LT
1408/**************************************************************************
1409* qla2xxx_eh_bus_reset
1410*
1411* Description:
1412* The bus reset function will reset the bus and abort any executing
1413* commands.
1414*
1415* Input:
1416* cmd = Linux SCSI command packet of the command that cause the
1417* bus reset.
1418*
1419* Returns:
1420* SUCCESS/FAILURE (defined as macro in scsi.h).
1421*
1422**************************************************************************/
e5f82ab8 1423static int
1da177e4
LT
1424qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1425{
e315cd28 1426 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79621 1427 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
2c3dfe3f 1428 int ret = FAILED;
9cb78c16
HR
1429 unsigned int id;
1430 uint64_t lun;
a465537a
SC
1431 struct qla_hw_data *ha = vha->hw;
1432
1433 if (qla2x00_isp_reg_stat(ha)) {
1434 ql_log(ql_log_info, vha, 0x8040,
1435 "PCI/Register disconnect, exiting.\n");
1436 return FAILED;
1437 }
f4f051eb 1438
f4f051eb
AV
1439 id = cmd->device->id;
1440 lun = cmd->device->lun;
1da177e4 1441
7c3df132 1442 if (!fcport) {
f4f051eb 1443 return ret;
7c3df132 1444 }
1da177e4 1445
4e98d3b8
AV
1446 ret = fc_block_scsi_eh(cmd);
1447 if (ret != 0)
1448 return ret;
1449 ret = FAILED;
1450
7c3df132 1451 ql_log(ql_log_info, vha, 0x8012,
9cb78c16 1452 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
1da177e4 1453
e315cd28 1454 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
7c3df132
SK
1455 ql_log(ql_log_fatal, vha, 0x8013,
1456 "Wait for hba online failed board disabled.\n");
f4f051eb 1457 goto eh_bus_reset_done;
1da177e4
LT
1458 }
1459
ad537689
SK
1460 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1461 ret = SUCCESS;
1462
f4f051eb
AV
1463 if (ret == FAILED)
1464 goto eh_bus_reset_done;
1da177e4 1465
9a41a62b 1466 /* Flush outstanding commands. */
4d78c973 1467 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
7c3df132
SK
1468 QLA_SUCCESS) {
1469 ql_log(ql_log_warn, vha, 0x8014,
1470 "Wait for pending commands failed.\n");
9a41a62b 1471 ret = FAILED;
7c3df132 1472 }
1da177e4 1473
f4f051eb 1474eh_bus_reset_done:
7c3df132 1475 ql_log(ql_log_warn, vha, 0x802b,
9cb78c16 1476 "BUS RESET %s nexus=%ld:%d:%llu.\n",
d6a03581 1477 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
1da177e4 1478
f4f051eb 1479 return ret;
1da177e4
LT
1480}
1481
1482/**************************************************************************
1483* qla2xxx_eh_host_reset
1484*
1485* Description:
1486* The reset function will reset the Adapter.
1487*
1488* Input:
1489* cmd = Linux SCSI command packet of the command that cause the
1490* adapter reset.
1491*
1492* Returns:
1493* Either SUCCESS or FAILED.
1494*
1495* Note:
1496**************************************************************************/
e5f82ab8 1497static int
1da177e4
LT
1498qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1499{
e315cd28 1500 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
e315cd28 1501 struct qla_hw_data *ha = vha->hw;
2c3dfe3f 1502 int ret = FAILED;
9cb78c16
HR
1503 unsigned int id;
1504 uint64_t lun;
e315cd28 1505 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1da177e4 1506
a465537a
SC
1507 if (qla2x00_isp_reg_stat(ha)) {
1508 ql_log(ql_log_info, vha, 0x8041,
1509 "PCI/Register disconnect, exiting.\n");
1510 schedule_work(&ha->board_disable);
1511 return SUCCESS;
1512 }
1513
f4f051eb
AV
1514 id = cmd->device->id;
1515 lun = cmd->device->lun;
f4f051eb 1516
7c3df132 1517 ql_log(ql_log_info, vha, 0x8018,
9cb78c16 1518 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
1da177e4 1519
63ee7072
CD
1520 /*
1521 * No point in issuing another reset if one is active. Also do not
1522 * attempt a reset if we are updating flash.
1523 */
1524 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
f4f051eb 1525 goto eh_host_reset_lock;
1da177e4 1526
e315cd28
AC
1527 if (vha != base_vha) {
1528 if (qla2x00_vp_abort_isp(vha))
f4f051eb 1529 goto eh_host_reset_lock;
e315cd28 1530 } else {
7ec0effd 1531 if (IS_P3P_TYPE(vha->hw)) {
a9083016
GM
1532 if (!qla82xx_fcoe_ctx_reset(vha)) {
1533 /* Ctx reset success */
1534 ret = SUCCESS;
1535 goto eh_host_reset_lock;
1536 }
1537 /* fall thru if ctx reset failed */
1538 }
68ca949c
AC
1539 if (ha->wq)
1540 flush_workqueue(ha->wq);
1541
e315cd28 1542 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
a9083016 1543 if (ha->isp_ops->abort_isp(base_vha)) {
e315cd28
AC
1544 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1545 /* failed. schedule dpc to try */
1546 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1547
7c3df132
SK
1548 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1549 ql_log(ql_log_warn, vha, 0x802a,
1550 "wait for hba online failed.\n");
e315cd28 1551 goto eh_host_reset_lock;
7c3df132 1552 }
e315cd28
AC
1553 }
1554 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
fa2a1ce5 1555 }
1da177e4 1556
e315cd28 1557 /* Waiting for command to be returned to OS.*/
4d78c973 1558 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
e315cd28 1559 QLA_SUCCESS)
f4f051eb 1560 ret = SUCCESS;
1da177e4 1561
f4f051eb 1562eh_host_reset_lock:
cfb0919c 1563 ql_log(ql_log_info, vha, 0x8017,
9cb78c16 1564 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
cfb0919c 1565 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
1da177e4 1566
f4f051eb
AV
1567 return ret;
1568}
1da177e4
LT
1569
1570/*
1571* qla2x00_loop_reset
1572* Issue loop reset.
1573*
1574* Input:
1575* ha = adapter block pointer.
1576*
1577* Returns:
1578* 0 = success
1579*/
a4722cf2 1580int
e315cd28 1581qla2x00_loop_reset(scsi_qla_host_t *vha)
1da177e4 1582{
0c8c39af 1583 int ret;
bdf79621 1584 struct fc_port *fcport;
e315cd28 1585 struct qla_hw_data *ha = vha->hw;
1da177e4 1586
5854771e
AB
1587 if (IS_QLAFX00(ha)) {
1588 return qlafx00_loop_reset(vha);
1589 }
1590
f4c496c1 1591 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
55e5ed27
AV
1592 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1593 if (fcport->port_type != FCT_TARGET)
1594 continue;
1595
1596 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1597 if (ret != QLA_SUCCESS) {
7c3df132 1598 ql_dbg(ql_dbg_taskm, vha, 0x802c,
5854771e 1599 "Bus Reset failed: Reset=%d "
7c3df132 1600 "d_id=%x.\n", ret, fcport->d_id.b24);
55e5ed27
AV
1601 }
1602 }
1603 }
1604
8ae6d9c7 1605
6246b8a1 1606 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
0b7e7c53
AV
1607 atomic_set(&vha->loop_state, LOOP_DOWN);
1608 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1609 qla2x00_mark_all_devices_lost(vha, 0);
e315cd28 1610 ret = qla2x00_full_login_lip(vha);
0c8c39af 1611 if (ret != QLA_SUCCESS) {
7c3df132
SK
1612 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1613 "full_login_lip=%d.\n", ret);
749af3d5 1614 }
0c8c39af
AV
1615 }
1616
0d6e61bc 1617 if (ha->flags.enable_lip_reset) {
e315cd28 1618 ret = qla2x00_lip_reset(vha);
ad537689 1619 if (ret != QLA_SUCCESS)
7c3df132
SK
1620 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1621 "lip_reset failed (%d).\n", ret);
1da177e4
LT
1622 }
1623
1da177e4 1624 /* Issue marker command only when we are going to start the I/O */
e315cd28 1625 vha->marker_needed = 1;
1da177e4 1626
0c8c39af 1627 return QLA_SUCCESS;
1da177e4
LT
1628}
1629
df4bf0bb 1630void
e315cd28 1631qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
df4bf0bb 1632{
73208dfd 1633 int que, cnt;
df4bf0bb
AV
1634 unsigned long flags;
1635 srb_t *sp;
e315cd28 1636 struct qla_hw_data *ha = vha->hw;
73208dfd 1637 struct req_que *req;
df4bf0bb 1638
c0cb4496
AE
1639 qlt_host_reset_handler(ha);
1640
df4bf0bb 1641 spin_lock_irqsave(&ha->hardware_lock, flags);
2afa19a9 1642 for (que = 0; que < ha->max_req_queues; que++) {
29bdccbe 1643 req = ha->req_q_map[que];
73208dfd
AC
1644 if (!req)
1645 continue;
8d93f550
CD
1646 if (!req->outstanding_cmds)
1647 continue;
1648 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
73208dfd 1649 sp = req->outstanding_cmds[cnt];
e612d465 1650 if (sp) {
c733ab35
MFO
1651 /* Don't abort commands in adapter during EEH
1652 * recovery as it's not accessible/responding.
1535aa75 1653 */
2780f3c8 1654 if (GET_CMD_SP(sp) && !ha->flags.eeh_busy) {
c733ab35
MFO
1655 /* Get a reference to the sp and drop the lock.
1656 * The reference ensures this sp->done() call
1657 * - and not the call in qla2xxx_eh_abort() -
1658 * ends the SCSI command (with result 'res').
1659 */
1660 sp_get(sp);
1661 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1662 qla2xxx_eh_abort(GET_CMD_SP(sp));
1663 spin_lock_irqsave(&ha->hardware_lock, flags);
1664 }
73208dfd 1665 req->outstanding_cmds[cnt] = NULL;
25ff6af1 1666 sp->done(sp, res);
73208dfd 1667 }
df4bf0bb
AV
1668 }
1669 }
1670 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1671}
1672
f4f051eb
AV
1673static int
1674qla2xxx_slave_alloc(struct scsi_device *sdev)
1da177e4 1675{
bdf79621 1676 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1da177e4 1677
19a7b4ae 1678 if (!rport || fc_remote_port_chkready(rport))
f4f051eb 1679 return -ENXIO;
bdf79621 1680
19a7b4ae 1681 sdev->hostdata = *(fc_port_t **)rport->dd_data;
1da177e4 1682
f4f051eb
AV
1683 return 0;
1684}
1da177e4 1685
f4f051eb
AV
1686static int
1687qla2xxx_slave_configure(struct scsi_device *sdev)
1688{
e315cd28 1689 scsi_qla_host_t *vha = shost_priv(sdev->host);
2afa19a9 1690 struct req_que *req = vha->req;
8482e118 1691
9e522cd8
AE
1692 if (IS_T10_PI_CAPABLE(vha->hw))
1693 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1694
db5ed4df 1695 scsi_change_queue_depth(sdev, req->max_q_depth);
f4f051eb
AV
1696 return 0;
1697}
1da177e4 1698
f4f051eb
AV
1699static void
1700qla2xxx_slave_destroy(struct scsi_device *sdev)
1701{
1702 sdev->hostdata = NULL;
1da177e4
LT
1703}
1704
1705/**
1706 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1707 * @ha: HA context
1708 *
1709 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1710 * supported addressing method.
1711 */
1712static void
53303c42 1713qla2x00_config_dma_addressing(struct qla_hw_data *ha)
1da177e4 1714{
7524f9b9 1715 /* Assume a 32bit DMA mask. */
1da177e4 1716 ha->flags.enable_64bit_addressing = 0;
1da177e4 1717
6a35528a 1718 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
7524f9b9
AV
1719 /* Any upper-dword bits set? */
1720 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
6a35528a 1721 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
7524f9b9 1722 /* Ok, a 64bit DMA mask is applicable. */
1da177e4 1723 ha->flags.enable_64bit_addressing = 1;
fd34f556
AV
1724 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1725 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
7524f9b9 1726 return;
1da177e4 1727 }
1da177e4 1728 }
7524f9b9 1729
284901a9
YH
1730 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1731 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
1da177e4
LT
1732}
1733
fd34f556 1734static void
e315cd28 1735qla2x00_enable_intrs(struct qla_hw_data *ha)
fd34f556
AV
1736{
1737 unsigned long flags = 0;
1738 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1739
1740 spin_lock_irqsave(&ha->hardware_lock, flags);
1741 ha->interrupts_on = 1;
1742 /* enable risc and host interrupts */
1743 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1744 RD_REG_WORD(&reg->ictrl);
1745 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1746
1747}
1748
1749static void
e315cd28 1750qla2x00_disable_intrs(struct qla_hw_data *ha)
fd34f556
AV
1751{
1752 unsigned long flags = 0;
1753 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1754
1755 spin_lock_irqsave(&ha->hardware_lock, flags);
1756 ha->interrupts_on = 0;
1757 /* disable risc and host interrupts */
1758 WRT_REG_WORD(&reg->ictrl, 0);
1759 RD_REG_WORD(&reg->ictrl);
1760 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1761}
1762
1763static void
e315cd28 1764qla24xx_enable_intrs(struct qla_hw_data *ha)
fd34f556
AV
1765{
1766 unsigned long flags = 0;
1767 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1768
1769 spin_lock_irqsave(&ha->hardware_lock, flags);
1770 ha->interrupts_on = 1;
1771 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1772 RD_REG_DWORD(&reg->ictrl);
1773 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1774}
1775
1776static void
e315cd28 1777qla24xx_disable_intrs(struct qla_hw_data *ha)
fd34f556
AV
1778{
1779 unsigned long flags = 0;
1780 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1781
124f85e6
AV
1782 if (IS_NOPOLLING_TYPE(ha))
1783 return;
fd34f556
AV
1784 spin_lock_irqsave(&ha->hardware_lock, flags);
1785 ha->interrupts_on = 0;
1786 WRT_REG_DWORD(&reg->ictrl, 0);
1787 RD_REG_DWORD(&reg->ictrl);
1788 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1789}
1790
706f457d
GM
1791static int
1792qla2x00_iospace_config(struct qla_hw_data *ha)
1793{
1794 resource_size_t pio;
1795 uint16_t msix;
706f457d 1796
706f457d
GM
1797 if (pci_request_selected_regions(ha->pdev, ha->bars,
1798 QLA2XXX_DRIVER_NAME)) {
1799 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1800 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1801 pci_name(ha->pdev));
1802 goto iospace_error_exit;
1803 }
1804 if (!(ha->bars & 1))
1805 goto skip_pio;
1806
1807 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1808 pio = pci_resource_start(ha->pdev, 0);
1809 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1810 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1811 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1812 "Invalid pci I/O region size (%s).\n",
1813 pci_name(ha->pdev));
1814 pio = 0;
1815 }
1816 } else {
1817 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1818 "Region #0 no a PIO resource (%s).\n",
1819 pci_name(ha->pdev));
1820 pio = 0;
1821 }
1822 ha->pio_address = pio;
1823 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1824 "PIO address=%llu.\n",
1825 (unsigned long long)ha->pio_address);
1826
1827skip_pio:
1828 /* Use MMIO operations for all accesses. */
1829 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1830 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1831 "Region #1 not an MMIO resource (%s), aborting.\n",
1832 pci_name(ha->pdev));
1833 goto iospace_error_exit;
1834 }
1835 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1836 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1837 "Invalid PCI mem region size (%s), aborting.\n",
1838 pci_name(ha->pdev));
1839 goto iospace_error_exit;
1840 }
1841
1842 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1843 if (!ha->iobase) {
1844 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1845 "Cannot remap MMIO (%s), aborting.\n",
1846 pci_name(ha->pdev));
1847 goto iospace_error_exit;
1848 }
1849
1850 /* Determine queue resources */
1851 ha->max_req_queues = ha->max_rsp_queues = 1;
f54f2cb5 1852 ha->msix_count = QLA_BASE_VECTORS;
d7459527 1853 if (!ql2xmqsupport || (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
706f457d
GM
1854 goto mqiobase_exit;
1855
1856 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1857 pci_resource_len(ha->pdev, 3));
1858 if (ha->mqiobase) {
1859 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1860 "MQIO Base=%p.\n", ha->mqiobase);
1861 /* Read MSIX vector size of the board */
1862 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
d7459527 1863 ha->msix_count = msix + 1;
706f457d 1864 /* Max queues are bounded by available msix vectors */
d7459527
MH
1865 /* MB interrupt uses 1 vector */
1866 ha->max_req_queues = ha->msix_count - 1;
1867 ha->max_rsp_queues = ha->max_req_queues;
1868 /* Queue pairs is the max value minus the base queue pair */
1869 ha->max_qpairs = ha->max_rsp_queues - 1;
1870 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
1871 "Max no of queues pairs: %d.\n", ha->max_qpairs);
1872
706f457d 1873 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
d7459527 1874 "MSI-X vector count: %d.\n", ha->msix_count);
706f457d
GM
1875 } else
1876 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1877 "BAR 3 not enabled.\n");
1878
1879mqiobase_exit:
706f457d 1880 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
f54f2cb5 1881 "MSIX Count: %d.\n", ha->msix_count);
706f457d
GM
1882 return (0);
1883
1884iospace_error_exit:
1885 return (-ENOMEM);
1886}
1887
1888
6246b8a1
GM
1889static int
1890qla83xx_iospace_config(struct qla_hw_data *ha)
1891{
1892 uint16_t msix;
6246b8a1
GM
1893
1894 if (pci_request_selected_regions(ha->pdev, ha->bars,
1895 QLA2XXX_DRIVER_NAME)) {
1896 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
1897 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1898 pci_name(ha->pdev));
1899
1900 goto iospace_error_exit;
1901 }
1902
1903 /* Use MMIO operations for all accesses. */
1904 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
1905 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
1906 "Invalid pci I/O region size (%s).\n",
1907 pci_name(ha->pdev));
1908 goto iospace_error_exit;
1909 }
1910 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1911 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
1912 "Invalid PCI mem region size (%s), aborting\n",
1913 pci_name(ha->pdev));
1914 goto iospace_error_exit;
1915 }
1916
1917 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
1918 if (!ha->iobase) {
1919 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
1920 "Cannot remap MMIO (%s), aborting.\n",
1921 pci_name(ha->pdev));
1922 goto iospace_error_exit;
1923 }
1924
1925 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
1926 /* 83XX 26XX always use MQ type access for queues
1927 * - mbar 2, a.k.a region 4 */
1928 ha->max_req_queues = ha->max_rsp_queues = 1;
f54f2cb5 1929 ha->msix_count = QLA_BASE_VECTORS;
6246b8a1
GM
1930 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
1931 pci_resource_len(ha->pdev, 4));
1932
1933 if (!ha->mqiobase) {
1934 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
1935 "BAR2/region4 not enabled\n");
1936 goto mqiobase_exit;
1937 }
1938
1939 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
1940 pci_resource_len(ha->pdev, 2));
1941 if (ha->msixbase) {
1942 /* Read MSIX vector size of the board */
1943 pci_read_config_word(ha->pdev,
1944 QLA_83XX_PCI_MSIX_CONTROL, &msix);
d7459527 1945 ha->msix_count = msix + 1;
093df737
QT
1946 /*
1947 * By default, driver uses at least two msix vectors
1948 * (default & rspq)
1949 */
d7459527
MH
1950 if (ql2xmqsupport) {
1951 /* MB interrupt uses 1 vector */
1952 ha->max_req_queues = ha->msix_count - 1;
093df737
QT
1953
1954 /* ATIOQ needs 1 vector. That's 1 less QPair */
1955 if (QLA_TGT_MODE_ENABLED())
1956 ha->max_req_queues--;
1957
d0d2c68b
MH
1958 ha->max_rsp_queues = ha->max_req_queues;
1959
d7459527
MH
1960 /* Queue pairs is the max value minus
1961 * the base queue pair */
1962 ha->max_qpairs = ha->max_req_queues - 1;
d7459527
MH
1963 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0190,
1964 "Max no of queues pairs: %d.\n", ha->max_qpairs);
6246b8a1
GM
1965 }
1966 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
d7459527 1967 "MSI-X vector count: %d.\n", ha->msix_count);
6246b8a1
GM
1968 } else
1969 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
1970 "BAR 1 not enabled.\n");
1971
1972mqiobase_exit:
6246b8a1 1973 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
f54f2cb5 1974 "MSIX Count: %d.\n", ha->msix_count);
6246b8a1
GM
1975 return 0;
1976
1977iospace_error_exit:
1978 return -ENOMEM;
1979}
1980
fd34f556
AV
1981static struct isp_operations qla2100_isp_ops = {
1982 .pci_config = qla2100_pci_config,
1983 .reset_chip = qla2x00_reset_chip,
1984 .chip_diag = qla2x00_chip_diag,
1985 .config_rings = qla2x00_config_rings,
1986 .reset_adapter = qla2x00_reset_adapter,
1987 .nvram_config = qla2x00_nvram_config,
1988 .update_fw_options = qla2x00_update_fw_options,
1989 .load_risc = qla2x00_load_risc,
1990 .pci_info_str = qla2x00_pci_info_str,
1991 .fw_version_str = qla2x00_fw_version_str,
1992 .intr_handler = qla2100_intr_handler,
1993 .enable_intrs = qla2x00_enable_intrs,
1994 .disable_intrs = qla2x00_disable_intrs,
1995 .abort_command = qla2x00_abort_command,
523ec773
AV
1996 .target_reset = qla2x00_abort_target,
1997 .lun_reset = qla2x00_lun_reset,
fd34f556
AV
1998 .fabric_login = qla2x00_login_fabric,
1999 .fabric_logout = qla2x00_fabric_logout,
2000 .calc_req_entries = qla2x00_calc_iocbs_32,
2001 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2002 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2003 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2004 .read_nvram = qla2x00_read_nvram_data,
2005 .write_nvram = qla2x00_write_nvram_data,
2006 .fw_dump = qla2100_fw_dump,
2007 .beacon_on = NULL,
2008 .beacon_off = NULL,
2009 .beacon_blink = NULL,
2010 .read_optrom = qla2x00_read_optrom_data,
2011 .write_optrom = qla2x00_write_optrom_data,
2012 .get_flash_version = qla2x00_get_flash_version,
e315cd28 2013 .start_scsi = qla2x00_start_scsi,
d7459527 2014 .start_scsi_mq = NULL,
a9083016 2015 .abort_isp = qla2x00_abort_isp,
706f457d 2016 .iospace_config = qla2x00_iospace_config,
8ae6d9c7 2017 .initialize_adapter = qla2x00_initialize_adapter,
fd34f556
AV
2018};
2019
2020static struct isp_operations qla2300_isp_ops = {
2021 .pci_config = qla2300_pci_config,
2022 .reset_chip = qla2x00_reset_chip,
2023 .chip_diag = qla2x00_chip_diag,
2024 .config_rings = qla2x00_config_rings,
2025 .reset_adapter = qla2x00_reset_adapter,
2026 .nvram_config = qla2x00_nvram_config,
2027 .update_fw_options = qla2x00_update_fw_options,
2028 .load_risc = qla2x00_load_risc,
2029 .pci_info_str = qla2x00_pci_info_str,
2030 .fw_version_str = qla2x00_fw_version_str,
2031 .intr_handler = qla2300_intr_handler,
2032 .enable_intrs = qla2x00_enable_intrs,
2033 .disable_intrs = qla2x00_disable_intrs,
2034 .abort_command = qla2x00_abort_command,
523ec773
AV
2035 .target_reset = qla2x00_abort_target,
2036 .lun_reset = qla2x00_lun_reset,
fd34f556
AV
2037 .fabric_login = qla2x00_login_fabric,
2038 .fabric_logout = qla2x00_fabric_logout,
2039 .calc_req_entries = qla2x00_calc_iocbs_32,
2040 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2041 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2042 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2043 .read_nvram = qla2x00_read_nvram_data,
2044 .write_nvram = qla2x00_write_nvram_data,
2045 .fw_dump = qla2300_fw_dump,
2046 .beacon_on = qla2x00_beacon_on,
2047 .beacon_off = qla2x00_beacon_off,
2048 .beacon_blink = qla2x00_beacon_blink,
2049 .read_optrom = qla2x00_read_optrom_data,
2050 .write_optrom = qla2x00_write_optrom_data,
2051 .get_flash_version = qla2x00_get_flash_version,
e315cd28 2052 .start_scsi = qla2x00_start_scsi,
d7459527 2053 .start_scsi_mq = NULL,
a9083016 2054 .abort_isp = qla2x00_abort_isp,
7ec0effd 2055 .iospace_config = qla2x00_iospace_config,
8ae6d9c7 2056 .initialize_adapter = qla2x00_initialize_adapter,
fd34f556
AV
2057};
2058
2059static struct isp_operations qla24xx_isp_ops = {
2060 .pci_config = qla24xx_pci_config,
2061 .reset_chip = qla24xx_reset_chip,
2062 .chip_diag = qla24xx_chip_diag,
2063 .config_rings = qla24xx_config_rings,
2064 .reset_adapter = qla24xx_reset_adapter,
2065 .nvram_config = qla24xx_nvram_config,
2066 .update_fw_options = qla24xx_update_fw_options,
2067 .load_risc = qla24xx_load_risc,
2068 .pci_info_str = qla24xx_pci_info_str,
2069 .fw_version_str = qla24xx_fw_version_str,
2070 .intr_handler = qla24xx_intr_handler,
2071 .enable_intrs = qla24xx_enable_intrs,
2072 .disable_intrs = qla24xx_disable_intrs,
2073 .abort_command = qla24xx_abort_command,
523ec773
AV
2074 .target_reset = qla24xx_abort_target,
2075 .lun_reset = qla24xx_lun_reset,
fd34f556
AV
2076 .fabric_login = qla24xx_login_fabric,
2077 .fabric_logout = qla24xx_fabric_logout,
2078 .calc_req_entries = NULL,
2079 .build_iocbs = NULL,
2080 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2081 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2082 .read_nvram = qla24xx_read_nvram_data,
2083 .write_nvram = qla24xx_write_nvram_data,
2084 .fw_dump = qla24xx_fw_dump,
2085 .beacon_on = qla24xx_beacon_on,
2086 .beacon_off = qla24xx_beacon_off,
2087 .beacon_blink = qla24xx_beacon_blink,
2088 .read_optrom = qla24xx_read_optrom_data,
2089 .write_optrom = qla24xx_write_optrom_data,
2090 .get_flash_version = qla24xx_get_flash_version,
e315cd28 2091 .start_scsi = qla24xx_start_scsi,
d7459527 2092 .start_scsi_mq = NULL,
a9083016 2093 .abort_isp = qla2x00_abort_isp,
7ec0effd 2094 .iospace_config = qla2x00_iospace_config,
8ae6d9c7 2095 .initialize_adapter = qla2x00_initialize_adapter,
fd34f556
AV
2096};
2097
c3a2f0df
AV
2098static struct isp_operations qla25xx_isp_ops = {
2099 .pci_config = qla25xx_pci_config,
2100 .reset_chip = qla24xx_reset_chip,
2101 .chip_diag = qla24xx_chip_diag,
2102 .config_rings = qla24xx_config_rings,
2103 .reset_adapter = qla24xx_reset_adapter,
2104 .nvram_config = qla24xx_nvram_config,
2105 .update_fw_options = qla24xx_update_fw_options,
2106 .load_risc = qla24xx_load_risc,
2107 .pci_info_str = qla24xx_pci_info_str,
2108 .fw_version_str = qla24xx_fw_version_str,
2109 .intr_handler = qla24xx_intr_handler,
2110 .enable_intrs = qla24xx_enable_intrs,
2111 .disable_intrs = qla24xx_disable_intrs,
2112 .abort_command = qla24xx_abort_command,
523ec773
AV
2113 .target_reset = qla24xx_abort_target,
2114 .lun_reset = qla24xx_lun_reset,
c3a2f0df
AV
2115 .fabric_login = qla24xx_login_fabric,
2116 .fabric_logout = qla24xx_fabric_logout,
2117 .calc_req_entries = NULL,
2118 .build_iocbs = NULL,
2119 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2120 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2121 .read_nvram = qla25xx_read_nvram_data,
2122 .write_nvram = qla25xx_write_nvram_data,
2123 .fw_dump = qla25xx_fw_dump,
2124 .beacon_on = qla24xx_beacon_on,
2125 .beacon_off = qla24xx_beacon_off,
2126 .beacon_blink = qla24xx_beacon_blink,
338c9161 2127 .read_optrom = qla25xx_read_optrom_data,
c3a2f0df
AV
2128 .write_optrom = qla24xx_write_optrom_data,
2129 .get_flash_version = qla24xx_get_flash_version,
bad75002 2130 .start_scsi = qla24xx_dif_start_scsi,
d7459527 2131 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
a9083016 2132 .abort_isp = qla2x00_abort_isp,
7ec0effd 2133 .iospace_config = qla2x00_iospace_config,
8ae6d9c7 2134 .initialize_adapter = qla2x00_initialize_adapter,
c3a2f0df
AV
2135};
2136
3a03eb79
AV
2137static struct isp_operations qla81xx_isp_ops = {
2138 .pci_config = qla25xx_pci_config,
2139 .reset_chip = qla24xx_reset_chip,
2140 .chip_diag = qla24xx_chip_diag,
2141 .config_rings = qla24xx_config_rings,
2142 .reset_adapter = qla24xx_reset_adapter,
2143 .nvram_config = qla81xx_nvram_config,
2144 .update_fw_options = qla81xx_update_fw_options,
eaac30be 2145 .load_risc = qla81xx_load_risc,
3a03eb79
AV
2146 .pci_info_str = qla24xx_pci_info_str,
2147 .fw_version_str = qla24xx_fw_version_str,
2148 .intr_handler = qla24xx_intr_handler,
2149 .enable_intrs = qla24xx_enable_intrs,
2150 .disable_intrs = qla24xx_disable_intrs,
2151 .abort_command = qla24xx_abort_command,
2152 .target_reset = qla24xx_abort_target,
2153 .lun_reset = qla24xx_lun_reset,
2154 .fabric_login = qla24xx_login_fabric,
2155 .fabric_logout = qla24xx_fabric_logout,
2156 .calc_req_entries = NULL,
2157 .build_iocbs = NULL,
2158 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2159 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
3d79038f
AV
2160 .read_nvram = NULL,
2161 .write_nvram = NULL,
3a03eb79
AV
2162 .fw_dump = qla81xx_fw_dump,
2163 .beacon_on = qla24xx_beacon_on,
2164 .beacon_off = qla24xx_beacon_off,
6246b8a1 2165 .beacon_blink = qla83xx_beacon_blink,
3a03eb79
AV
2166 .read_optrom = qla25xx_read_optrom_data,
2167 .write_optrom = qla24xx_write_optrom_data,
2168 .get_flash_version = qla24xx_get_flash_version,
ba77ef53 2169 .start_scsi = qla24xx_dif_start_scsi,
d7459527 2170 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
a9083016 2171 .abort_isp = qla2x00_abort_isp,
7ec0effd 2172 .iospace_config = qla2x00_iospace_config,
8ae6d9c7 2173 .initialize_adapter = qla2x00_initialize_adapter,
a9083016
GM
2174};
2175
2176static struct isp_operations qla82xx_isp_ops = {
2177 .pci_config = qla82xx_pci_config,
2178 .reset_chip = qla82xx_reset_chip,
2179 .chip_diag = qla24xx_chip_diag,
2180 .config_rings = qla82xx_config_rings,
2181 .reset_adapter = qla24xx_reset_adapter,
2182 .nvram_config = qla81xx_nvram_config,
2183 .update_fw_options = qla24xx_update_fw_options,
2184 .load_risc = qla82xx_load_risc,
9d55ca66 2185 .pci_info_str = qla24xx_pci_info_str,
a9083016
GM
2186 .fw_version_str = qla24xx_fw_version_str,
2187 .intr_handler = qla82xx_intr_handler,
2188 .enable_intrs = qla82xx_enable_intrs,
2189 .disable_intrs = qla82xx_disable_intrs,
2190 .abort_command = qla24xx_abort_command,
2191 .target_reset = qla24xx_abort_target,
2192 .lun_reset = qla24xx_lun_reset,
2193 .fabric_login = qla24xx_login_fabric,
2194 .fabric_logout = qla24xx_fabric_logout,
2195 .calc_req_entries = NULL,
2196 .build_iocbs = NULL,
2197 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2198 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2199 .read_nvram = qla24xx_read_nvram_data,
2200 .write_nvram = qla24xx_write_nvram_data,
a1b23c5a 2201 .fw_dump = qla82xx_fw_dump,
999916dc
SK
2202 .beacon_on = qla82xx_beacon_on,
2203 .beacon_off = qla82xx_beacon_off,
2204 .beacon_blink = NULL,
a9083016
GM
2205 .read_optrom = qla82xx_read_optrom_data,
2206 .write_optrom = qla82xx_write_optrom_data,
7ec0effd 2207 .get_flash_version = qla82xx_get_flash_version,
a9083016 2208 .start_scsi = qla82xx_start_scsi,
d7459527 2209 .start_scsi_mq = NULL,
a9083016 2210 .abort_isp = qla82xx_abort_isp,
706f457d 2211 .iospace_config = qla82xx_iospace_config,
8ae6d9c7 2212 .initialize_adapter = qla2x00_initialize_adapter,
3a03eb79
AV
2213};
2214
7ec0effd
AD
2215static struct isp_operations qla8044_isp_ops = {
2216 .pci_config = qla82xx_pci_config,
2217 .reset_chip = qla82xx_reset_chip,
2218 .chip_diag = qla24xx_chip_diag,
2219 .config_rings = qla82xx_config_rings,
2220 .reset_adapter = qla24xx_reset_adapter,
2221 .nvram_config = qla81xx_nvram_config,
2222 .update_fw_options = qla24xx_update_fw_options,
2223 .load_risc = qla82xx_load_risc,
2224 .pci_info_str = qla24xx_pci_info_str,
2225 .fw_version_str = qla24xx_fw_version_str,
2226 .intr_handler = qla8044_intr_handler,
2227 .enable_intrs = qla82xx_enable_intrs,
2228 .disable_intrs = qla82xx_disable_intrs,
2229 .abort_command = qla24xx_abort_command,
2230 .target_reset = qla24xx_abort_target,
2231 .lun_reset = qla24xx_lun_reset,
2232 .fabric_login = qla24xx_login_fabric,
2233 .fabric_logout = qla24xx_fabric_logout,
2234 .calc_req_entries = NULL,
2235 .build_iocbs = NULL,
2236 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2237 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2238 .read_nvram = NULL,
2239 .write_nvram = NULL,
a1b23c5a 2240 .fw_dump = qla8044_fw_dump,
7ec0effd
AD
2241 .beacon_on = qla82xx_beacon_on,
2242 .beacon_off = qla82xx_beacon_off,
2243 .beacon_blink = NULL,
888e639d 2244 .read_optrom = qla8044_read_optrom_data,
7ec0effd
AD
2245 .write_optrom = qla8044_write_optrom_data,
2246 .get_flash_version = qla82xx_get_flash_version,
2247 .start_scsi = qla82xx_start_scsi,
d7459527 2248 .start_scsi_mq = NULL,
7ec0effd
AD
2249 .abort_isp = qla8044_abort_isp,
2250 .iospace_config = qla82xx_iospace_config,
2251 .initialize_adapter = qla2x00_initialize_adapter,
2252};
2253
6246b8a1
GM
2254static struct isp_operations qla83xx_isp_ops = {
2255 .pci_config = qla25xx_pci_config,
2256 .reset_chip = qla24xx_reset_chip,
2257 .chip_diag = qla24xx_chip_diag,
2258 .config_rings = qla24xx_config_rings,
2259 .reset_adapter = qla24xx_reset_adapter,
2260 .nvram_config = qla81xx_nvram_config,
2261 .update_fw_options = qla81xx_update_fw_options,
2262 .load_risc = qla81xx_load_risc,
2263 .pci_info_str = qla24xx_pci_info_str,
2264 .fw_version_str = qla24xx_fw_version_str,
2265 .intr_handler = qla24xx_intr_handler,
2266 .enable_intrs = qla24xx_enable_intrs,
2267 .disable_intrs = qla24xx_disable_intrs,
2268 .abort_command = qla24xx_abort_command,
2269 .target_reset = qla24xx_abort_target,
2270 .lun_reset = qla24xx_lun_reset,
2271 .fabric_login = qla24xx_login_fabric,
2272 .fabric_logout = qla24xx_fabric_logout,
2273 .calc_req_entries = NULL,
2274 .build_iocbs = NULL,
2275 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2276 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2277 .read_nvram = NULL,
2278 .write_nvram = NULL,
2279 .fw_dump = qla83xx_fw_dump,
2280 .beacon_on = qla24xx_beacon_on,
2281 .beacon_off = qla24xx_beacon_off,
2282 .beacon_blink = qla83xx_beacon_blink,
2283 .read_optrom = qla25xx_read_optrom_data,
2284 .write_optrom = qla24xx_write_optrom_data,
2285 .get_flash_version = qla24xx_get_flash_version,
2286 .start_scsi = qla24xx_dif_start_scsi,
d7459527 2287 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
6246b8a1
GM
2288 .abort_isp = qla2x00_abort_isp,
2289 .iospace_config = qla83xx_iospace_config,
8ae6d9c7
GM
2290 .initialize_adapter = qla2x00_initialize_adapter,
2291};
2292
2293static struct isp_operations qlafx00_isp_ops = {
2294 .pci_config = qlafx00_pci_config,
2295 .reset_chip = qlafx00_soft_reset,
2296 .chip_diag = qlafx00_chip_diag,
2297 .config_rings = qlafx00_config_rings,
2298 .reset_adapter = qlafx00_soft_reset,
2299 .nvram_config = NULL,
2300 .update_fw_options = NULL,
2301 .load_risc = NULL,
2302 .pci_info_str = qlafx00_pci_info_str,
2303 .fw_version_str = qlafx00_fw_version_str,
2304 .intr_handler = qlafx00_intr_handler,
2305 .enable_intrs = qlafx00_enable_intrs,
2306 .disable_intrs = qlafx00_disable_intrs,
4440e46d 2307 .abort_command = qla24xx_async_abort_command,
8ae6d9c7
GM
2308 .target_reset = qlafx00_abort_target,
2309 .lun_reset = qlafx00_lun_reset,
2310 .fabric_login = NULL,
2311 .fabric_logout = NULL,
2312 .calc_req_entries = NULL,
2313 .build_iocbs = NULL,
2314 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2315 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2316 .read_nvram = qla24xx_read_nvram_data,
2317 .write_nvram = qla24xx_write_nvram_data,
2318 .fw_dump = NULL,
2319 .beacon_on = qla24xx_beacon_on,
2320 .beacon_off = qla24xx_beacon_off,
2321 .beacon_blink = NULL,
2322 .read_optrom = qla24xx_read_optrom_data,
2323 .write_optrom = qla24xx_write_optrom_data,
2324 .get_flash_version = qla24xx_get_flash_version,
2325 .start_scsi = qlafx00_start_scsi,
d7459527 2326 .start_scsi_mq = NULL,
8ae6d9c7
GM
2327 .abort_isp = qlafx00_abort_isp,
2328 .iospace_config = qlafx00_iospace_config,
2329 .initialize_adapter = qlafx00_initialize_adapter,
6246b8a1
GM
2330};
2331
f73cb695
CD
2332static struct isp_operations qla27xx_isp_ops = {
2333 .pci_config = qla25xx_pci_config,
2334 .reset_chip = qla24xx_reset_chip,
2335 .chip_diag = qla24xx_chip_diag,
2336 .config_rings = qla24xx_config_rings,
2337 .reset_adapter = qla24xx_reset_adapter,
2338 .nvram_config = qla81xx_nvram_config,
2339 .update_fw_options = qla81xx_update_fw_options,
2340 .load_risc = qla81xx_load_risc,
2341 .pci_info_str = qla24xx_pci_info_str,
2342 .fw_version_str = qla24xx_fw_version_str,
2343 .intr_handler = qla24xx_intr_handler,
2344 .enable_intrs = qla24xx_enable_intrs,
2345 .disable_intrs = qla24xx_disable_intrs,
2346 .abort_command = qla24xx_abort_command,
2347 .target_reset = qla24xx_abort_target,
2348 .lun_reset = qla24xx_lun_reset,
2349 .fabric_login = qla24xx_login_fabric,
2350 .fabric_logout = qla24xx_fabric_logout,
2351 .calc_req_entries = NULL,
2352 .build_iocbs = NULL,
2353 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2354 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2355 .read_nvram = NULL,
2356 .write_nvram = NULL,
2357 .fw_dump = qla27xx_fwdump,
2358 .beacon_on = qla24xx_beacon_on,
2359 .beacon_off = qla24xx_beacon_off,
2360 .beacon_blink = qla83xx_beacon_blink,
2361 .read_optrom = qla25xx_read_optrom_data,
2362 .write_optrom = qla24xx_write_optrom_data,
2363 .get_flash_version = qla24xx_get_flash_version,
2364 .start_scsi = qla24xx_dif_start_scsi,
d7459527 2365 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
f73cb695
CD
2366 .abort_isp = qla2x00_abort_isp,
2367 .iospace_config = qla83xx_iospace_config,
2368 .initialize_adapter = qla2x00_initialize_adapter,
2369};
2370
ea5b6382 2371static inline void
e315cd28 2372qla2x00_set_isp_flags(struct qla_hw_data *ha)
ea5b6382
AV
2373{
2374 ha->device_type = DT_EXTENDED_IDS;
2375 switch (ha->pdev->device) {
2376 case PCI_DEVICE_ID_QLOGIC_ISP2100:
9e052e2d 2377 ha->isp_type |= DT_ISP2100;
ea5b6382 2378 ha->device_type &= ~DT_EXTENDED_IDS;
441d1072 2379 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
ea5b6382
AV
2380 break;
2381 case PCI_DEVICE_ID_QLOGIC_ISP2200:
9e052e2d 2382 ha->isp_type |= DT_ISP2200;
ea5b6382 2383 ha->device_type &= ~DT_EXTENDED_IDS;
441d1072 2384 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
ea5b6382
AV
2385 break;
2386 case PCI_DEVICE_ID_QLOGIC_ISP2300:
9e052e2d 2387 ha->isp_type |= DT_ISP2300;
4a59f71d 2388 ha->device_type |= DT_ZIO_SUPPORTED;
441d1072 2389 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
ea5b6382
AV
2390 break;
2391 case PCI_DEVICE_ID_QLOGIC_ISP2312:
9e052e2d 2392 ha->isp_type |= DT_ISP2312;
4a59f71d 2393 ha->device_type |= DT_ZIO_SUPPORTED;
441d1072 2394 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
ea5b6382
AV
2395 break;
2396 case PCI_DEVICE_ID_QLOGIC_ISP2322:
9e052e2d 2397 ha->isp_type |= DT_ISP2322;
4a59f71d 2398 ha->device_type |= DT_ZIO_SUPPORTED;
ea5b6382
AV
2399 if (ha->pdev->subsystem_vendor == 0x1028 &&
2400 ha->pdev->subsystem_device == 0x0170)
2401 ha->device_type |= DT_OEM_001;
441d1072 2402 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
ea5b6382
AV
2403 break;
2404 case PCI_DEVICE_ID_QLOGIC_ISP6312:
9e052e2d 2405 ha->isp_type |= DT_ISP6312;
441d1072 2406 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
ea5b6382
AV
2407 break;
2408 case PCI_DEVICE_ID_QLOGIC_ISP6322:
9e052e2d 2409 ha->isp_type |= DT_ISP6322;
441d1072 2410 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
ea5b6382
AV
2411 break;
2412 case PCI_DEVICE_ID_QLOGIC_ISP2422:
9e052e2d 2413 ha->isp_type |= DT_ISP2422;
4a59f71d 2414 ha->device_type |= DT_ZIO_SUPPORTED;
e428924c 2415 ha->device_type |= DT_FWI2;
c76f2c01 2416 ha->device_type |= DT_IIDMA;
441d1072 2417 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
ea5b6382
AV
2418 break;
2419 case PCI_DEVICE_ID_QLOGIC_ISP2432:
9e052e2d 2420 ha->isp_type |= DT_ISP2432;
4a59f71d 2421 ha->device_type |= DT_ZIO_SUPPORTED;
e428924c 2422 ha->device_type |= DT_FWI2;
c76f2c01 2423 ha->device_type |= DT_IIDMA;
441d1072 2424 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
ea5b6382 2425 break;
4d4df193 2426 case PCI_DEVICE_ID_QLOGIC_ISP8432:
9e052e2d 2427 ha->isp_type |= DT_ISP8432;
4d4df193
HK
2428 ha->device_type |= DT_ZIO_SUPPORTED;
2429 ha->device_type |= DT_FWI2;
2430 ha->device_type |= DT_IIDMA;
2431 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2432 break;
044cc6c8 2433 case PCI_DEVICE_ID_QLOGIC_ISP5422:
9e052e2d 2434 ha->isp_type |= DT_ISP5422;
e428924c 2435 ha->device_type |= DT_FWI2;
441d1072 2436 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
ea5b6382 2437 break;
044cc6c8 2438 case PCI_DEVICE_ID_QLOGIC_ISP5432:
9e052e2d 2439 ha->isp_type |= DT_ISP5432;
e428924c 2440 ha->device_type |= DT_FWI2;
441d1072 2441 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
ea5b6382 2442 break;
c3a2f0df 2443 case PCI_DEVICE_ID_QLOGIC_ISP2532:
9e052e2d 2444 ha->isp_type |= DT_ISP2532;
c3a2f0df
AV
2445 ha->device_type |= DT_ZIO_SUPPORTED;
2446 ha->device_type |= DT_FWI2;
2447 ha->device_type |= DT_IIDMA;
441d1072 2448 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
ea5b6382 2449 break;
3a03eb79 2450 case PCI_DEVICE_ID_QLOGIC_ISP8001:
9e052e2d 2451 ha->isp_type |= DT_ISP8001;
3a03eb79
AV
2452 ha->device_type |= DT_ZIO_SUPPORTED;
2453 ha->device_type |= DT_FWI2;
2454 ha->device_type |= DT_IIDMA;
2455 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2456 break;
a9083016 2457 case PCI_DEVICE_ID_QLOGIC_ISP8021:
9e052e2d 2458 ha->isp_type |= DT_ISP8021;
a9083016
GM
2459 ha->device_type |= DT_ZIO_SUPPORTED;
2460 ha->device_type |= DT_FWI2;
2461 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2462 /* Initialize 82XX ISP flags */
2463 qla82xx_init_flags(ha);
2464 break;
7ec0effd 2465 case PCI_DEVICE_ID_QLOGIC_ISP8044:
9e052e2d 2466 ha->isp_type |= DT_ISP8044;
7ec0effd
AD
2467 ha->device_type |= DT_ZIO_SUPPORTED;
2468 ha->device_type |= DT_FWI2;
2469 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2470 /* Initialize 82XX ISP flags */
2471 qla82xx_init_flags(ha);
2472 break;
6246b8a1 2473 case PCI_DEVICE_ID_QLOGIC_ISP2031:
9e052e2d 2474 ha->isp_type |= DT_ISP2031;
6246b8a1
GM
2475 ha->device_type |= DT_ZIO_SUPPORTED;
2476 ha->device_type |= DT_FWI2;
2477 ha->device_type |= DT_IIDMA;
2478 ha->device_type |= DT_T10_PI;
2479 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2480 break;
2481 case PCI_DEVICE_ID_QLOGIC_ISP8031:
9e052e2d 2482 ha->isp_type |= DT_ISP8031;
6246b8a1
GM
2483 ha->device_type |= DT_ZIO_SUPPORTED;
2484 ha->device_type |= DT_FWI2;
2485 ha->device_type |= DT_IIDMA;
2486 ha->device_type |= DT_T10_PI;
2487 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2488 break;
8ae6d9c7 2489 case PCI_DEVICE_ID_QLOGIC_ISPF001:
9e052e2d 2490 ha->isp_type |= DT_ISPFX00;
8ae6d9c7 2491 break;
f73cb695 2492 case PCI_DEVICE_ID_QLOGIC_ISP2071:
9e052e2d 2493 ha->isp_type |= DT_ISP2071;
f73cb695
CD
2494 ha->device_type |= DT_ZIO_SUPPORTED;
2495 ha->device_type |= DT_FWI2;
2496 ha->device_type |= DT_IIDMA;
8ce3f570 2497 ha->device_type |= DT_T10_PI;
f73cb695
CD
2498 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2499 break;
2c5bbbb2 2500 case PCI_DEVICE_ID_QLOGIC_ISP2271:
9e052e2d 2501 ha->isp_type |= DT_ISP2271;
2c5bbbb2
JC
2502 ha->device_type |= DT_ZIO_SUPPORTED;
2503 ha->device_type |= DT_FWI2;
2504 ha->device_type |= DT_IIDMA;
8ce3f570 2505 ha->device_type |= DT_T10_PI;
2c5bbbb2
JC
2506 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2507 break;
2b48992f 2508 case PCI_DEVICE_ID_QLOGIC_ISP2261:
9e052e2d 2509 ha->isp_type |= DT_ISP2261;
2b48992f
SC
2510 ha->device_type |= DT_ZIO_SUPPORTED;
2511 ha->device_type |= DT_FWI2;
2512 ha->device_type |= DT_IIDMA;
8ce3f570 2513 ha->device_type |= DT_T10_PI;
2b48992f
SC
2514 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2515 break;
ea5b6382 2516 }
e5b68a61 2517
a9083016 2518 if (IS_QLA82XX(ha))
43a9c38b 2519 ha->port_no = ha->portnum & 1;
f73cb695 2520 else {
a9083016
GM
2521 /* Get adapter physical port no from interrupt pin register. */
2522 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
f73cb695
CD
2523 if (IS_QLA27XX(ha))
2524 ha->port_no--;
2525 else
2526 ha->port_no = !(ha->port_no & 1);
2527 }
a9083016 2528
7c3df132 2529 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
d8424f68 2530 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
f73cb695 2531 ha->device_type, ha->port_no, ha->fw_srisc_address);
ea5b6382
AV
2532}
2533
1e99e33a
AV
2534static void
2535qla2xxx_scan_start(struct Scsi_Host *shost)
2536{
e315cd28 2537 scsi_qla_host_t *vha = shost_priv(shost);
1e99e33a 2538
cbc8eb67
AV
2539 if (vha->hw->flags.running_gold_fw)
2540 return;
2541
e315cd28
AC
2542 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2543 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2544 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2545 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
1e99e33a
AV
2546}
2547
2548static int
2549qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2550{
e315cd28 2551 scsi_qla_host_t *vha = shost_priv(shost);
1e99e33a 2552
a5dd506e
BK
2553 if (test_bit(UNLOADING, &vha->dpc_flags))
2554 return 1;
e315cd28 2555 if (!vha->host)
1e99e33a 2556 return 1;
e315cd28 2557 if (time > vha->hw->loop_reset_delay * HZ)
1e99e33a
AV
2558 return 1;
2559
e315cd28 2560 return atomic_read(&vha->loop_state) == LOOP_READY;
1e99e33a
AV
2561}
2562
1da177e4
LT
2563/*
2564 * PCI driver interface
2565 */
6f039790 2566static int
7ee61397 2567qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1da177e4 2568{
a1541d5a 2569 int ret = -ENODEV;
1da177e4 2570 struct Scsi_Host *host;
e315cd28
AC
2571 scsi_qla_host_t *base_vha = NULL;
2572 struct qla_hw_data *ha;
29856e28 2573 char pci_info[30];
7d613ac6 2574 char fw_str[30], wq_name[30];
5433383e 2575 struct scsi_host_template *sht;
642ef983 2576 int bars, mem_only = 0;
e315cd28 2577 uint16_t req_length = 0, rsp_length = 0;
73208dfd
AC
2578 struct req_que *req = NULL;
2579 struct rsp_que *rsp = NULL;
5601236b 2580 int i;
d7459527 2581
285d0321 2582 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
a5326f86 2583 sht = &qla2xxx_driver_template;
5433383e 2584 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
8bc69e7d 2585 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
4d4df193 2586 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
8bc69e7d 2587 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
c3a2f0df 2588 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
3a03eb79 2589 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
a9083016 2590 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
6246b8a1
GM
2591 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2592 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
8ae6d9c7 2593 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
7ec0effd 2594 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
f73cb695 2595 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
2c5bbbb2 2596 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
2b48992f
SC
2597 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2598 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261) {
285d0321 2599 bars = pci_select_bars(pdev, IORESOURCE_MEM);
09483916 2600 mem_only = 1;
7c3df132
SK
2601 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2602 "Mem only adapter.\n");
285d0321 2603 }
7c3df132
SK
2604 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2605 "Bars=%d.\n", bars);
285d0321 2606
09483916
BH
2607 if (mem_only) {
2608 if (pci_enable_device_mem(pdev))
2609 goto probe_out;
2610 } else {
2611 if (pci_enable_device(pdev))
2612 goto probe_out;
2613 }
285d0321 2614
0927678f
JB
2615 /* This may fail but that's ok */
2616 pci_enable_pcie_error_reporting(pdev);
285d0321 2617
e315cd28
AC
2618 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2619 if (!ha) {
7c3df132
SK
2620 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2621 "Unable to allocate memory for ha.\n");
e315cd28 2622 goto probe_out;
1da177e4 2623 }
7c3df132
SK
2624 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2625 "Memory allocated for ha=%p.\n", ha);
e315cd28 2626 ha->pdev = pdev;
2d70c103 2627 ha->tgt.enable_class_2 = ql2xenableclass2;
33e79977
QT
2628 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2629 spin_lock_init(&ha->tgt.q_full_lock);
7560151b 2630 spin_lock_init(&ha->tgt.sess_lock);
2f424b9b
QT
2631 spin_lock_init(&ha->tgt.atio_lock);
2632
1da177e4
LT
2633
2634 /* Clear our data area */
285d0321 2635 ha->bars = bars;
09483916 2636 ha->mem_only = mem_only;
df4bf0bb 2637 spin_lock_init(&ha->hardware_lock);
339aa70e 2638 spin_lock_init(&ha->vport_slock);
a9b6f722 2639 mutex_init(&ha->selflogin_lock);
7a8ab9c8 2640 mutex_init(&ha->optrom_mutex);
1da177e4 2641
ea5b6382
AV
2642 /* Set ISP-type information. */
2643 qla2x00_set_isp_flags(ha);
ca79cf66
DG
2644
2645 /* Set EEH reset type to fundamental if required by hba */
95676112 2646 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
f73cb695 2647 IS_QLA83XX(ha) || IS_QLA27XX(ha))
ca79cf66 2648 pdev->needs_freset = 1;
ca79cf66 2649
cba1e47f
CD
2650 ha->prev_topology = 0;
2651 ha->init_cb_size = sizeof(init_cb_t);
2652 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2653 ha->optrom_size = OPTROM_SIZE_2300;
2654
abbd8870 2655 /* Assign ISP specific operations. */
1da177e4 2656 if (IS_QLA2100(ha)) {
642ef983 2657 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
1da177e4 2658 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
e315cd28
AC
2659 req_length = REQUEST_ENTRY_CNT_2100;
2660 rsp_length = RESPONSE_ENTRY_CNT_2100;
2661 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
abbd8870 2662 ha->gid_list_info_size = 4;
3a03eb79
AV
2663 ha->flash_conf_off = ~0;
2664 ha->flash_data_off = ~0;
2665 ha->nvram_conf_off = ~0;
2666 ha->nvram_data_off = ~0;
fd34f556 2667 ha->isp_ops = &qla2100_isp_ops;
1da177e4 2668 } else if (IS_QLA2200(ha)) {
642ef983 2669 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
67ddda35 2670 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
e315cd28
AC
2671 req_length = REQUEST_ENTRY_CNT_2200;
2672 rsp_length = RESPONSE_ENTRY_CNT_2100;
2673 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
abbd8870 2674 ha->gid_list_info_size = 4;
3a03eb79
AV
2675 ha->flash_conf_off = ~0;
2676 ha->flash_data_off = ~0;
2677 ha->nvram_conf_off = ~0;
2678 ha->nvram_data_off = ~0;
fd34f556 2679 ha->isp_ops = &qla2100_isp_ops;
fca29703 2680 } else if (IS_QLA23XX(ha)) {
642ef983 2681 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
1da177e4 2682 ha->mbx_count = MAILBOX_REGISTER_COUNT;
e315cd28
AC
2683 req_length = REQUEST_ENTRY_CNT_2200;
2684 rsp_length = RESPONSE_ENTRY_CNT_2300;
2685 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
abbd8870 2686 ha->gid_list_info_size = 6;
854165f4
AV
2687 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2688 ha->optrom_size = OPTROM_SIZE_2322;
3a03eb79
AV
2689 ha->flash_conf_off = ~0;
2690 ha->flash_data_off = ~0;
2691 ha->nvram_conf_off = ~0;
2692 ha->nvram_data_off = ~0;
fd34f556 2693 ha->isp_ops = &qla2300_isp_ops;
4d4df193 2694 } else if (IS_QLA24XX_TYPE(ha)) {
642ef983 2695 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
fca29703 2696 ha->mbx_count = MAILBOX_REGISTER_COUNT;
e315cd28
AC
2697 req_length = REQUEST_ENTRY_CNT_24XX;
2698 rsp_length = RESPONSE_ENTRY_CNT_2300;
2d70c103 2699 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
e315cd28 2700 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2c3dfe3f 2701 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
fca29703 2702 ha->gid_list_info_size = 8;
854165f4 2703 ha->optrom_size = OPTROM_SIZE_24XX;
73208dfd 2704 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
fd34f556 2705 ha->isp_ops = &qla24xx_isp_ops;
3a03eb79
AV
2706 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2707 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2708 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2709 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
c3a2f0df 2710 } else if (IS_QLA25XX(ha)) {
642ef983 2711 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
c3a2f0df 2712 ha->mbx_count = MAILBOX_REGISTER_COUNT;
e315cd28
AC
2713 req_length = REQUEST_ENTRY_CNT_24XX;
2714 rsp_length = RESPONSE_ENTRY_CNT_2300;
2d70c103 2715 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
e315cd28 2716 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
c3a2f0df 2717 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
c3a2f0df
AV
2718 ha->gid_list_info_size = 8;
2719 ha->optrom_size = OPTROM_SIZE_25XX;
73208dfd 2720 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
c3a2f0df 2721 ha->isp_ops = &qla25xx_isp_ops;
3a03eb79
AV
2722 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2723 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2724 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2725 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2726 } else if (IS_QLA81XX(ha)) {
642ef983 2727 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3a03eb79
AV
2728 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2729 req_length = REQUEST_ENTRY_CNT_24XX;
2730 rsp_length = RESPONSE_ENTRY_CNT_2300;
aa230bc5 2731 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3a03eb79
AV
2732 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2733 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2734 ha->gid_list_info_size = 8;
2735 ha->optrom_size = OPTROM_SIZE_81XX;
40859ae5 2736 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3a03eb79
AV
2737 ha->isp_ops = &qla81xx_isp_ops;
2738 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2739 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2740 ha->nvram_conf_off = ~0;
2741 ha->nvram_data_off = ~0;
a9083016 2742 } else if (IS_QLA82XX(ha)) {
642ef983 2743 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
a9083016
GM
2744 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2745 req_length = REQUEST_ENTRY_CNT_82XX;
2746 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2747 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2748 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2749 ha->gid_list_info_size = 8;
2750 ha->optrom_size = OPTROM_SIZE_82XX;
087c621e 2751 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
a9083016
GM
2752 ha->isp_ops = &qla82xx_isp_ops;
2753 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2754 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2755 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2756 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
7ec0effd
AD
2757 } else if (IS_QLA8044(ha)) {
2758 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2759 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2760 req_length = REQUEST_ENTRY_CNT_82XX;
2761 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2762 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2763 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2764 ha->gid_list_info_size = 8;
2765 ha->optrom_size = OPTROM_SIZE_83XX;
2766 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2767 ha->isp_ops = &qla8044_isp_ops;
2768 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2769 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2770 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2771 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
6246b8a1 2772 } else if (IS_QLA83XX(ha)) {
7d613ac6 2773 ha->portnum = PCI_FUNC(ha->pdev->devfn);
642ef983 2774 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
6246b8a1 2775 ha->mbx_count = MAILBOX_REGISTER_COUNT;
f2ea653f 2776 req_length = REQUEST_ENTRY_CNT_83XX;
e7b42e33 2777 rsp_length = RESPONSE_ENTRY_CNT_83XX;
b8aa4bdf 2778 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
6246b8a1
GM
2779 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2780 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2781 ha->gid_list_info_size = 8;
2782 ha->optrom_size = OPTROM_SIZE_83XX;
2783 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2784 ha->isp_ops = &qla83xx_isp_ops;
2785 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2786 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2787 ha->nvram_conf_off = ~0;
2788 ha->nvram_data_off = ~0;
8ae6d9c7
GM
2789 } else if (IS_QLAFX00(ha)) {
2790 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2791 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2792 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
2793 req_length = REQUEST_ENTRY_CNT_FX00;
2794 rsp_length = RESPONSE_ENTRY_CNT_FX00;
8ae6d9c7
GM
2795 ha->isp_ops = &qlafx00_isp_ops;
2796 ha->port_down_retry_count = 30; /* default value */
2797 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
2798 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
71e56003 2799 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
8ae6d9c7 2800 ha->mr.fw_hbt_en = 1;
e8f5e95d
AB
2801 ha->mr.host_info_resend = false;
2802 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
f73cb695
CD
2803 } else if (IS_QLA27XX(ha)) {
2804 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2805 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2806 ha->mbx_count = MAILBOX_REGISTER_COUNT;
e7b42e33
QT
2807 req_length = REQUEST_ENTRY_CNT_83XX;
2808 rsp_length = RESPONSE_ENTRY_CNT_83XX;
b20f02e1 2809 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
f73cb695
CD
2810 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2811 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2812 ha->gid_list_info_size = 8;
2813 ha->optrom_size = OPTROM_SIZE_83XX;
2814 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2815 ha->isp_ops = &qla27xx_isp_ops;
2816 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2817 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2818 ha->nvram_conf_off = ~0;
2819 ha->nvram_data_off = ~0;
1da177e4 2820 }
6246b8a1 2821
7c3df132
SK
2822 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2823 "mbx_count=%d, req_length=%d, "
2824 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
642ef983
CD
2825 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
2826 "max_fibre_devices=%d.\n",
7c3df132
SK
2827 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2828 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
642ef983 2829 ha->nvram_npiv_size, ha->max_fibre_devices);
7c3df132
SK
2830 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2831 "isp_ops=%p, flash_conf_off=%d, "
2832 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2833 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2834 ha->nvram_conf_off, ha->nvram_data_off);
706f457d
GM
2835
2836 /* Configure PCI I/O space */
2837 ret = ha->isp_ops->iospace_config(ha);
2838 if (ret)
0a63ad12 2839 goto iospace_config_failed;
706f457d
GM
2840
2841 ql_log_pci(ql_log_info, pdev, 0x001d,
2842 "Found an ISP%04X irq %d iobase 0x%p.\n",
2843 pdev->device, pdev->irq, ha->iobase);
6c2f527c 2844 mutex_init(&ha->vport_lock);
d7459527 2845 mutex_init(&ha->mq_lock);
0b05a1f0
MB
2846 init_completion(&ha->mbx_cmd_comp);
2847 complete(&ha->mbx_cmd_comp);
2848 init_completion(&ha->mbx_intr_comp);
23f2ebd1 2849 init_completion(&ha->dcbx_comp);
f356bef1 2850 init_completion(&ha->lb_portup_comp);
1da177e4 2851
2c3dfe3f 2852 set_bit(0, (unsigned long *) ha->vp_idx_map);
1da177e4 2853
53303c42 2854 qla2x00_config_dma_addressing(ha);
7c3df132
SK
2855 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2856 "64 Bit addressing is %s.\n",
2857 ha->flags.enable_64bit_addressing ? "enable" :
2858 "disable");
73208dfd 2859 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
b2a72ec3 2860 if (ret) {
7c3df132
SK
2861 ql_log_pci(ql_log_fatal, pdev, 0x0031,
2862 "Failed to allocate memory for adapter, aborting.\n");
1da177e4 2863
e315cd28
AC
2864 goto probe_hw_failed;
2865 }
2866
73208dfd 2867 req->max_q_depth = MAX_Q_DEPTH;
e315cd28 2868 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
73208dfd
AC
2869 req->max_q_depth = ql2xmaxqdepth;
2870
e315cd28
AC
2871
2872 base_vha = qla2x00_create_host(sht, ha);
2873 if (!base_vha) {
a1541d5a 2874 ret = -ENOMEM;
6e9f21f3 2875 qla2x00_mem_free(ha);
2afa19a9
AC
2876 qla2x00_free_req_que(ha, req);
2877 qla2x00_free_rsp_que(ha, rsp);
e315cd28 2878 goto probe_hw_failed;
1da177e4
LT
2879 }
2880
e315cd28 2881 pci_set_drvdata(pdev, base_vha);
6b383979 2882 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
e315cd28 2883
e315cd28 2884 host = base_vha->host;
2afa19a9 2885 base_vha->req = req;
73208dfd 2886 if (IS_QLA2XXX_MIDTYPE(ha))
e315cd28 2887 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
73208dfd 2888 else
e315cd28
AC
2889 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2890 base_vha->vp_idx;
58548cb5 2891
8ae6d9c7
GM
2892 /* Setup fcport template structure. */
2893 ha->mr.fcport.vha = base_vha;
2894 ha->mr.fcport.port_type = FCT_UNKNOWN;
2895 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
2896 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
2897 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
2898 ha->mr.fcport.scan_state = 1;
2899
58548cb5
GM
2900 /* Set the SG table size based on ISP type */
2901 if (!IS_FWI2_CAPABLE(ha)) {
2902 if (IS_QLA2100(ha))
2903 host->sg_tablesize = 32;
2904 } else {
2905 if (!IS_QLA82XX(ha))
2906 host->sg_tablesize = QLA_SG_ALL;
2907 }
642ef983 2908 host->max_id = ha->max_fibre_devices;
e315cd28
AC
2909 host->cmd_per_lun = 3;
2910 host->unique_id = host->host_no;
e02587d7 2911 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
0c470874
AE
2912 host->max_cmd_len = 32;
2913 else
2914 host->max_cmd_len = MAX_CMDSZ;
e315cd28 2915 host->max_channel = MAX_BUSES - 1;
755f516b
HR
2916 /* Older HBAs support only 16-bit LUNs */
2917 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
2918 ql2xmaxlun > 0xffff)
2919 host->max_lun = 0xffff;
2920 else
2921 host->max_lun = ql2xmaxlun;
e315cd28 2922 host->transportt = qla2xxx_transport_template;
9a069e19 2923 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
e315cd28 2924
7c3df132
SK
2925 ql_dbg(ql_dbg_init, base_vha, 0x0033,
2926 "max_id=%d this_id=%d "
2927 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
1abf635d 2928 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
7c3df132
SK
2929 host->this_id, host->cmd_per_lun, host->unique_id,
2930 host->max_cmd_len, host->max_channel, host->max_lun,
2931 host->transportt, sht->vendor_id);
2932
d7459527
MH
2933 /* Set up the irqs */
2934 ret = qla2x00_request_irqs(ha, rsp);
2935 if (ret)
2936 goto probe_init_failed;
2937
9a347ff4
CD
2938 /* Alloc arrays of request and response ring ptrs */
2939 if (!qla2x00_alloc_queues(ha, req, rsp)) {
2940 ql_log(ql_log_fatal, base_vha, 0x003d,
2941 "Failed to allocate memory for queue pointers..."
2942 "aborting.\n");
2943 goto probe_init_failed;
2944 }
2945
5601236b
MH
2946 if (ha->mqenable && shost_use_blk_mq(host)) {
2947 /* number of hardware queues supported by blk/scsi-mq*/
2948 host->nr_hw_queues = ha->max_qpairs;
2949
2950 ql_dbg(ql_dbg_init, base_vha, 0x0192,
2951 "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
2952 } else
2953 ql_dbg(ql_dbg_init, base_vha, 0x0193,
2954 "blk/scsi-mq disabled.\n");
2955
2d70c103 2956 qlt_probe_one_stage1(base_vha, ha);
9a347ff4 2957
90a86fc0
JC
2958 pci_save_state(pdev);
2959
9a347ff4 2960 /* Assign back pointers */
2afa19a9
AC
2961 rsp->req = req;
2962 req->rsp = rsp;
9a347ff4 2963
8ae6d9c7
GM
2964 if (IS_QLAFX00(ha)) {
2965 ha->rsp_q_map[0] = rsp;
2966 ha->req_q_map[0] = req;
2967 set_bit(0, ha->req_qid_map);
2968 set_bit(0, ha->rsp_qid_map);
2969 }
2970
08029990
AV
2971 /* FWI2-capable only. */
2972 req->req_q_in = &ha->iobase->isp24.req_q_in;
2973 req->req_q_out = &ha->iobase->isp24.req_q_out;
2974 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
2975 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
f73cb695 2976 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
08029990
AV
2977 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2978 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2979 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2980 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
17d98630
AC
2981 }
2982
8ae6d9c7
GM
2983 if (IS_QLAFX00(ha)) {
2984 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
2985 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
2986 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
2987 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
2988 }
2989
7ec0effd 2990 if (IS_P3P_TYPE(ha)) {
a9083016
GM
2991 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
2992 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
2993 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
2994 }
2995
7c3df132
SK
2996 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
2997 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2998 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2999 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3000 "req->req_q_in=%p req->req_q_out=%p "
3001 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3002 req->req_q_in, req->req_q_out,
3003 rsp->rsp_q_in, rsp->rsp_q_out);
3004 ql_dbg(ql_dbg_init, base_vha, 0x003e,
3005 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3006 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3007 ql_dbg(ql_dbg_init, base_vha, 0x003f,
3008 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3009 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
1da177e4 3010
8ae6d9c7 3011 if (ha->isp_ops->initialize_adapter(base_vha)) {
7c3df132
SK
3012 ql_log(ql_log_fatal, base_vha, 0x00d6,
3013 "Failed to initialize adapter - Adapter flags %x.\n",
3014 base_vha->device_flags);
1da177e4 3015
a9083016
GM
3016 if (IS_QLA82XX(ha)) {
3017 qla82xx_idc_lock(ha);
3018 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
7d613ac6 3019 QLA8XXX_DEV_FAILED);
a9083016 3020 qla82xx_idc_unlock(ha);
7c3df132
SK
3021 ql_log(ql_log_fatal, base_vha, 0x00d7,
3022 "HW State: FAILED.\n");
7ec0effd
AD
3023 } else if (IS_QLA8044(ha)) {
3024 qla8044_idc_lock(ha);
3025 qla8044_wr_direct(base_vha,
3026 QLA8044_CRB_DEV_STATE_INDEX,
3027 QLA8XXX_DEV_FAILED);
3028 qla8044_idc_unlock(ha);
3029 ql_log(ql_log_fatal, base_vha, 0x0150,
3030 "HW State: FAILED.\n");
a9083016
GM
3031 }
3032
a1541d5a 3033 ret = -ENODEV;
1da177e4
LT
3034 goto probe_failed;
3035 }
3036
3b1bef64
CD
3037 if (IS_QLAFX00(ha))
3038 host->can_queue = QLAFX00_MAX_CANQUEUE;
3039 else
3040 host->can_queue = req->num_outstanding_cmds - 10;
3041
3042 ql_dbg(ql_dbg_init, base_vha, 0x0032,
3043 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3044 host->can_queue, base_vha->req,
3045 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3046
093df737 3047 if (ha->mqenable && qla_ini_mode_enabled(base_vha)) {
d7459527 3048 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
5601236b
MH
3049 /* Create start of day qpairs for Block MQ */
3050 if (shost_use_blk_mq(host)) {
3051 for (i = 0; i < ha->max_qpairs; i++)
3052 qla2xxx_create_qpair(base_vha, 5, 0);
3053 }
3054 }
68ca949c 3055
cbc8eb67
AV
3056 if (ha->flags.running_gold_fw)
3057 goto skip_dpc;
3058
1da177e4
LT
3059 /*
3060 * Startup the kernel thread for this host adapter
3061 */
39a11240 3062 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
7c3df132 3063 "%s_dpc", base_vha->host_str);
39a11240 3064 if (IS_ERR(ha->dpc_thread)) {
7c3df132
SK
3065 ql_log(ql_log_fatal, base_vha, 0x00ed,
3066 "Failed to start DPC thread.\n");
39a11240 3067 ret = PTR_ERR(ha->dpc_thread);
1da177e4
LT
3068 goto probe_failed;
3069 }
7c3df132
SK
3070 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3071 "DPC thread started successfully.\n");
1da177e4 3072
2d70c103
NB
3073 /*
3074 * If we're not coming up in initiator mode, we might sit for
3075 * a while without waking up the dpc thread, which leads to a
3076 * stuck process warning. So just kick the dpc once here and
3077 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3078 */
3079 qla2xxx_wake_dpc(base_vha);
3080
f3ddac19
CD
3081 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3082
81178772
SK
3083 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3084 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3085 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
3086 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3087
3088 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3089 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
3090 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3091 INIT_WORK(&ha->idc_state_handler,
3092 qla83xx_idc_state_handler_work);
3093 INIT_WORK(&ha->nic_core_unrecoverable,
3094 qla83xx_nic_core_unrecoverable_work);
3095 }
3096
cbc8eb67 3097skip_dpc:
e315cd28
AC
3098 list_add_tail(&base_vha->list, &ha->vp_list);
3099 base_vha->host->irq = ha->pdev->irq;
1da177e4
LT
3100
3101 /* Initialized the timer */
e315cd28 3102 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
7c3df132
SK
3103 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3104 "Started qla2x00_timer with "
3105 "interval=%d.\n", WATCH_INTERVAL);
3106 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3107 "Detected hba at address=%p.\n",
3108 ha);
d19044c3 3109
e02587d7 3110 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
bad75002 3111 if (ha->fw_attributes & BIT_4) {
9e522cd8 3112 int prot = 0, guard;
bad75002 3113 base_vha->flags.difdix_supported = 1;
7c3df132
SK
3114 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3115 "Registering for DIF/DIX type 1 and 3 protection.\n");
8cb2049c
AE
3116 if (ql2xenabledif == 1)
3117 prot = SHOST_DIX_TYPE0_PROTECTION;
bad75002 3118 scsi_host_set_prot(host,
8cb2049c 3119 prot | SHOST_DIF_TYPE1_PROTECTION
0c470874 3120 | SHOST_DIF_TYPE2_PROTECTION
bad75002
AE
3121 | SHOST_DIF_TYPE3_PROTECTION
3122 | SHOST_DIX_TYPE1_PROTECTION
0c470874 3123 | SHOST_DIX_TYPE2_PROTECTION
bad75002 3124 | SHOST_DIX_TYPE3_PROTECTION);
9e522cd8
AE
3125
3126 guard = SHOST_DIX_GUARD_CRC;
3127
3128 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3129 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3130 guard |= SHOST_DIX_GUARD_IP;
3131
3132 scsi_host_set_guard(host, guard);
bad75002
AE
3133 } else
3134 base_vha->flags.difdix_supported = 0;
3135 }
3136
a9083016
GM
3137 ha->isp_ops->enable_intrs(ha);
3138
1fe19ee4
AB
3139 if (IS_QLAFX00(ha)) {
3140 ret = qlafx00_fx_disc(base_vha,
3141 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3142 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3143 QLA_SG_ALL : 128;
3144 }
3145
a1541d5a
AV
3146 ret = scsi_add_host(host, &pdev->dev);
3147 if (ret)
3148 goto probe_failed;
3149
1486400f
MR
3150 base_vha->flags.init_done = 1;
3151 base_vha->flags.online = 1;
edaa5c74 3152 ha->prev_minidump_failed = 0;
1486400f 3153
7c3df132
SK
3154 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3155 "Init done and hba is online.\n");
3156
726b8548
QT
3157 if (qla_ini_mode_enabled(base_vha) ||
3158 qla_dual_mode_enabled(base_vha))
2d70c103
NB
3159 scsi_scan_host(host);
3160 else
3161 ql_dbg(ql_dbg_init, base_vha, 0x0122,
3162 "skipping scsi_scan_host() for non-initiator port\n");
1e99e33a 3163
e315cd28 3164 qla2x00_alloc_sysfs_attr(base_vha);
a1541d5a 3165
8ae6d9c7 3166 if (IS_QLAFX00(ha)) {
8ae6d9c7
GM
3167 ret = qlafx00_fx_disc(base_vha,
3168 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3169
3170 /* Register system information */
3171 ret = qlafx00_fx_disc(base_vha,
3172 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3173 }
3174
e315cd28 3175 qla2x00_init_host_attr(base_vha);
a1541d5a 3176
e315cd28 3177 qla2x00_dfs_setup(base_vha);
df613b96 3178
03eb912a
AB
3179 ql_log(ql_log_info, base_vha, 0x00fb,
3180 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
7c3df132
SK
3181 ql_log(ql_log_info, base_vha, 0x00fc,
3182 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3183 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
3184 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3185 base_vha->host_no,
df57caba 3186 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
1da177e4 3187
2d70c103
NB
3188 qlt_add_target(ha, base_vha);
3189
6b383979 3190 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
a29b3dd7
JC
3191
3192 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3193 return -ENODEV;
3194
1da177e4
LT
3195 return 0;
3196
6e9f21f3 3197probe_init_failed:
2afa19a9 3198 qla2x00_free_req_que(ha, req);
9a347ff4
CD
3199 ha->req_q_map[0] = NULL;
3200 clear_bit(0, ha->req_qid_map);
2afa19a9 3201 qla2x00_free_rsp_que(ha, rsp);
9a347ff4
CD
3202 ha->rsp_q_map[0] = NULL;
3203 clear_bit(0, ha->rsp_qid_map);
2afa19a9 3204 ha->max_req_queues = ha->max_rsp_queues = 0;
6e9f21f3 3205
1da177e4 3206probe_failed:
b9978769
AV
3207 if (base_vha->timer_active)
3208 qla2x00_stop_timer(base_vha);
3209 base_vha->flags.online = 0;
3210 if (ha->dpc_thread) {
3211 struct task_struct *t = ha->dpc_thread;
3212
3213 ha->dpc_thread = NULL;
3214 kthread_stop(t);
3215 }
3216
e315cd28 3217 qla2x00_free_device(base_vha);
1da177e4 3218
e315cd28 3219 scsi_host_put(base_vha->host);
1da177e4 3220
e315cd28 3221probe_hw_failed:
1a2fbf18
JL
3222 qla2x00_clear_drv_active(ha);
3223
0a63ad12 3224iospace_config_failed:
7ec0effd 3225 if (IS_P3P_TYPE(ha)) {
0a63ad12 3226 if (!ha->nx_pcibase)
f73cb695 3227 iounmap((device_reg_t *)ha->nx_pcibase);
a9083016 3228 if (!ql2xdbwr)
f73cb695 3229 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
a9083016
GM
3230 } else {
3231 if (ha->iobase)
3232 iounmap(ha->iobase);
8ae6d9c7
GM
3233 if (ha->cregbase)
3234 iounmap(ha->cregbase);
a9083016 3235 }
e315cd28
AC
3236 pci_release_selected_regions(ha->pdev, ha->bars);
3237 kfree(ha);
3238 ha = NULL;
1da177e4 3239
a1541d5a 3240probe_out:
e315cd28 3241 pci_disable_device(pdev);
a1541d5a 3242 return ret;
1da177e4 3243}
1da177e4 3244
e30d1756
MI
3245static void
3246qla2x00_shutdown(struct pci_dev *pdev)
3247{
3248 scsi_qla_host_t *vha;
3249 struct qla_hw_data *ha;
3250
552f3f9a
MI
3251 if (!atomic_read(&pdev->enable_cnt))
3252 return;
3253
e30d1756
MI
3254 vha = pci_get_drvdata(pdev);
3255 ha = vha->hw;
3256
42479343
AB
3257 /* Notify ISPFX00 firmware */
3258 if (IS_QLAFX00(ha))
3259 qlafx00_driver_shutdown(vha, 20);
3260
e30d1756
MI
3261 /* Turn-off FCE trace */
3262 if (ha->flags.fce_enabled) {
3263 qla2x00_disable_fce_trace(vha, NULL, NULL);
3264 ha->flags.fce_enabled = 0;
3265 }
3266
3267 /* Turn-off EFT trace */
3268 if (ha->eft)
3269 qla2x00_disable_eft_trace(vha);
3270
3271 /* Stop currently executing firmware. */
3272 qla2x00_try_to_stop_firmware(vha);
3273
3274 /* Turn adapter off line */
3275 vha->flags.online = 0;
3276
3277 /* turn-off interrupts on the card */
3278 if (ha->interrupts_on) {
3279 vha->flags.init_done = 0;
3280 ha->isp_ops->disable_intrs(ha);
3281 }
3282
3283 qla2x00_free_irqs(vha);
3284
3285 qla2x00_free_fw_dump(ha);
61d41f61
CD
3286
3287 pci_disable_pcie_error_reporting(pdev);
3288 pci_disable_device(pdev);
e30d1756
MI
3289}
3290
fe1b806f 3291/* Deletes all the virtual ports for a given ha */
4c993f76 3292static void
fe1b806f 3293qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
1da177e4 3294{
fe1b806f 3295 scsi_qla_host_t *vha;
feafb7b1 3296 unsigned long flags;
e315cd28 3297
43ebf16d
AE
3298 mutex_lock(&ha->vport_lock);
3299 while (ha->cur_vport_count) {
43ebf16d 3300 spin_lock_irqsave(&ha->vport_slock, flags);
feafb7b1 3301
43ebf16d
AE
3302 BUG_ON(base_vha->list.next == &ha->vp_list);
3303 /* This assumes first entry in ha->vp_list is always base vha */
3304 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
52c82823 3305 scsi_host_get(vha->host);
feafb7b1 3306
43ebf16d
AE
3307 spin_unlock_irqrestore(&ha->vport_slock, flags);
3308 mutex_unlock(&ha->vport_lock);
3309
3310 fc_vport_terminate(vha->fc_vport);
3311 scsi_host_put(vha->host);
feafb7b1 3312
43ebf16d 3313 mutex_lock(&ha->vport_lock);
e315cd28 3314 }
43ebf16d 3315 mutex_unlock(&ha->vport_lock);
fe1b806f 3316}
1da177e4 3317
fe1b806f
CD
3318/* Stops all deferred work threads */
3319static void
3320qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3321{
7d613ac6
SV
3322 /* Cancel all work and destroy DPC workqueues */
3323 if (ha->dpc_lp_wq) {
3324 cancel_work_sync(&ha->idc_aen);
3325 destroy_workqueue(ha->dpc_lp_wq);
3326 ha->dpc_lp_wq = NULL;
3327 }
3328
3329 if (ha->dpc_hp_wq) {
3330 cancel_work_sync(&ha->nic_core_reset);
3331 cancel_work_sync(&ha->idc_state_handler);
3332 cancel_work_sync(&ha->nic_core_unrecoverable);
3333 destroy_workqueue(ha->dpc_hp_wq);
3334 ha->dpc_hp_wq = NULL;
3335 }
3336
b9978769
AV
3337 /* Kill the kernel thread for this host */
3338 if (ha->dpc_thread) {
3339 struct task_struct *t = ha->dpc_thread;
3340
3341 /*
3342 * qla2xxx_wake_dpc checks for ->dpc_thread
3343 * so we need to zero it out.
3344 */
3345 ha->dpc_thread = NULL;
3346 kthread_stop(t);
3347 }
fe1b806f 3348}
1da177e4 3349
fe1b806f
CD
3350static void
3351qla2x00_unmap_iobases(struct qla_hw_data *ha)
3352{
a9083016 3353 if (IS_QLA82XX(ha)) {
b963752f 3354
f73cb695 3355 iounmap((device_reg_t *)ha->nx_pcibase);
a9083016 3356 if (!ql2xdbwr)
f73cb695 3357 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
a9083016
GM
3358 } else {
3359 if (ha->iobase)
3360 iounmap(ha->iobase);
1da177e4 3361
8ae6d9c7
GM
3362 if (ha->cregbase)
3363 iounmap(ha->cregbase);
3364
a9083016
GM
3365 if (ha->mqiobase)
3366 iounmap(ha->mqiobase);
6246b8a1 3367
f73cb695 3368 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) && ha->msixbase)
6246b8a1 3369 iounmap(ha->msixbase);
a9083016 3370 }
fe1b806f
CD
3371}
3372
3373static void
db7157d4 3374qla2x00_clear_drv_active(struct qla_hw_data *ha)
fe1b806f 3375{
fe1b806f
CD
3376 if (IS_QLA8044(ha)) {
3377 qla8044_idc_lock(ha);
c41afc9a 3378 qla8044_clear_drv_active(ha);
fe1b806f
CD
3379 qla8044_idc_unlock(ha);
3380 } else if (IS_QLA82XX(ha)) {
3381 qla82xx_idc_lock(ha);
3382 qla82xx_clear_drv_active(ha);
3383 qla82xx_idc_unlock(ha);
3384 }
3385}
3386
3387static void
3388qla2x00_remove_one(struct pci_dev *pdev)
3389{
3390 scsi_qla_host_t *base_vha;
3391 struct qla_hw_data *ha;
3392
beb9e315
JL
3393 base_vha = pci_get_drvdata(pdev);
3394 ha = base_vha->hw;
3395
3396 /* Indicate device removal to prevent future board_disable and wait
3397 * until any pending board_disable has completed. */
3398 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3399 cancel_work_sync(&ha->board_disable);
3400
fe1b806f 3401 /*
beb9e315
JL
3402 * If the PCI device is disabled then there was a PCI-disconnect and
3403 * qla2x00_disable_board_on_pci_error has taken care of most of the
3404 * resources.
fe1b806f 3405 */
beb9e315 3406 if (!atomic_read(&pdev->enable_cnt)) {
726b8548
QT
3407 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3408 base_vha->gnl.l, base_vha->gnl.ldma);
3409
beb9e315
JL
3410 scsi_host_put(base_vha->host);
3411 kfree(ha);
3412 pci_set_drvdata(pdev, NULL);
fe1b806f 3413 return;
beb9e315 3414 }
638a1a01
SC
3415 qla2x00_wait_for_hba_ready(base_vha);
3416
726b8548
QT
3417 /*
3418 * if UNLOAD flag is already set, then continue unload,
783e0dc4
SC
3419 * where it was set first.
3420 */
3421 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3422 return;
3423
fe1b806f 3424 set_bit(UNLOADING, &base_vha->dpc_flags);
726b8548
QT
3425 dma_free_coherent(&ha->pdev->dev,
3426 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
fe1b806f
CD
3427
3428 if (IS_QLAFX00(ha))
3429 qlafx00_driver_shutdown(base_vha, 20);
3430
3431 qla2x00_delete_all_vps(ha, base_vha);
3432
3433 if (IS_QLA8031(ha)) {
3434 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3435 "Clearing fcoe driver presence.\n");
3436 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3437 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3438 "Error while clearing DRV-Presence.\n");
3439 }
3440
3441 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3442
3443 qla2x00_dfs_remove(base_vha);
3444
3445 qla84xx_put_chip(base_vha);
3446
2d5a4c34
HM
3447 /* Laser should be disabled only for ISP2031 */
3448 if (IS_QLA2031(ha))
3449 qla83xx_disable_laser(base_vha);
3450
fe1b806f
CD
3451 /* Disable timer */
3452 if (base_vha->timer_active)
3453 qla2x00_stop_timer(base_vha);
3454
3455 base_vha->flags.online = 0;
3456
b0d6cabd
HM
3457 /* free DMA memory */
3458 if (ha->exlogin_buf)
3459 qla2x00_free_exlogin_buffer(ha);
3460
2f56a7f1
HM
3461 /* free DMA memory */
3462 if (ha->exchoffld_buf)
3463 qla2x00_free_exchoffld_buffer(ha);
3464
fe1b806f
CD
3465 qla2x00_destroy_deferred_work(ha);
3466
3467 qlt_remove_target(ha, base_vha);
3468
3469 qla2x00_free_sysfs_attr(base_vha, true);
3470
3471 fc_remove_host(base_vha->host);
482c9dc7 3472 qlt_remove_target_resources(ha);
fe1b806f
CD
3473
3474 scsi_remove_host(base_vha->host);
3475
3476 qla2x00_free_device(base_vha);
3477
db7157d4 3478 qla2x00_clear_drv_active(ha);
fe1b806f 3479
d2749ffa
AE
3480 scsi_host_put(base_vha->host);
3481
fe1b806f 3482 qla2x00_unmap_iobases(ha);
73208dfd 3483
e315cd28
AC
3484 pci_release_selected_regions(ha->pdev, ha->bars);
3485 kfree(ha);
3486 ha = NULL;
1da177e4 3487
90a86fc0
JC
3488 pci_disable_pcie_error_reporting(pdev);
3489
665db93b 3490 pci_disable_device(pdev);
1da177e4 3491}
1da177e4
LT
3492
3493static void
e315cd28 3494qla2x00_free_device(scsi_qla_host_t *vha)
1da177e4 3495{
e315cd28 3496 struct qla_hw_data *ha = vha->hw;
1da177e4 3497
85880801
AV
3498 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3499
3500 /* Disable timer */
3501 if (vha->timer_active)
3502 qla2x00_stop_timer(vha);
3503
2afa19a9 3504 qla25xx_delete_queues(vha);
fe1b806f 3505
df613b96 3506 if (ha->flags.fce_enabled)
e315cd28 3507 qla2x00_disable_fce_trace(vha, NULL, NULL);
df613b96 3508
a7a167bf 3509 if (ha->eft)
e315cd28 3510 qla2x00_disable_eft_trace(vha);
a7a167bf 3511
f6ef3b18 3512 /* Stop currently executing firmware. */
e315cd28 3513 qla2x00_try_to_stop_firmware(vha);
1da177e4 3514
85880801
AV
3515 vha->flags.online = 0;
3516
f6ef3b18 3517 /* turn-off interrupts on the card */
a9083016
GM
3518 if (ha->interrupts_on) {
3519 vha->flags.init_done = 0;
fd34f556 3520 ha->isp_ops->disable_intrs(ha);
a9083016 3521 }
f6ef3b18 3522
093df737
QT
3523 qla2x00_free_fcports(vha);
3524
e315cd28 3525 qla2x00_free_irqs(vha);
1da177e4 3526
093df737
QT
3527 /* Flush the work queue and remove it */
3528 if (ha->wq) {
3529 flush_workqueue(ha->wq);
3530 destroy_workqueue(ha->wq);
3531 ha->wq = NULL;
3532 }
3533
8867048b 3534
e315cd28 3535 qla2x00_mem_free(ha);
73208dfd 3536
08de2844
GM
3537 qla82xx_md_free(vha);
3538
73208dfd 3539 qla2x00_free_queues(ha);
1da177e4
LT
3540}
3541
8867048b
CD
3542void qla2x00_free_fcports(struct scsi_qla_host *vha)
3543{
3544 fc_port_t *fcport, *tfcport;
3545
3546 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3547 list_del(&fcport->list);
5f16b331 3548 qla2x00_clear_loop_id(fcport);
8867048b
CD
3549 kfree(fcport);
3550 fcport = NULL;
3551 }
3552}
3553
d97994dc 3554static inline void
e315cd28 3555qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
d97994dc
AV
3556 int defer)
3557{
d97994dc 3558 struct fc_rport *rport;
67becc00 3559 scsi_qla_host_t *base_vha;
044d78e1 3560 unsigned long flags;
d97994dc
AV
3561
3562 if (!fcport->rport)
3563 return;
3564
3565 rport = fcport->rport;
3566 if (defer) {
67becc00 3567 base_vha = pci_get_drvdata(vha->hw->pdev);
044d78e1 3568 spin_lock_irqsave(vha->host->host_lock, flags);
d97994dc 3569 fcport->drport = rport;
044d78e1 3570 spin_unlock_irqrestore(vha->host->host_lock, flags);
df673274 3571 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
67becc00
AV
3572 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3573 qla2xxx_wake_dpc(base_vha);
2d70c103 3574 } else {
df673274 3575 int now;
726b8548
QT
3576 if (rport) {
3577 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
3578 "%s %8phN. rport %p roles %x \n",
3579 __func__, fcport->port_name, rport,
3580 rport->roles);
d20ed91b 3581 fc_remote_port_delete(rport);
726b8548 3582 }
df673274 3583 qlt_do_generation_tick(vha, &now);
2d70c103 3584 }
d97994dc
AV
3585}
3586
1da177e4
LT
3587/*
3588 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3589 *
3590 * Input: ha = adapter block pointer. fcport = port structure pointer.
3591 *
3592 * Return: None.
3593 *
3594 * Context:
3595 */
e315cd28 3596void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
d97994dc 3597 int do_login, int defer)
1da177e4 3598{
8ae6d9c7
GM
3599 if (IS_QLAFX00(vha->hw)) {
3600 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3601 qla2x00_schedule_rport_del(vha, fcport, defer);
3602 return;
3603 }
3604
2c3dfe3f 3605 if (atomic_read(&fcport->state) == FCS_ONLINE &&
c6d39e23 3606 vha->vp_idx == fcport->vha->vp_idx) {
ec426e10 3607 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
e315cd28
AC
3608 qla2x00_schedule_rport_del(vha, fcport, defer);
3609 }
fa2a1ce5 3610 /*
1da177e4
LT
3611 * We may need to retry the login, so don't change the state of the
3612 * port but do the retries.
3613 */
3614 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
ec426e10 3615 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
1da177e4
LT
3616
3617 if (!do_login)
3618 return;
3619
a1d0285e
AE
3620 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3621
1da177e4 3622 if (fcport->login_retry == 0) {
e315cd28 3623 fcport->login_retry = vha->hw->login_retry_count;
1da177e4 3624
7c3df132 3625 ql_dbg(ql_dbg_disc, vha, 0x2067,
726b8548 3626 "Port login retry %8phN, lid 0x%04x retry cnt=%d.\n",
7b833558 3627 fcport->port_name, fcport->loop_id, fcport->login_retry);
1da177e4
LT
3628 }
3629}
3630
3631/*
3632 * qla2x00_mark_all_devices_lost
3633 * Updates fcport state when device goes offline.
3634 *
3635 * Input:
3636 * ha = adapter block pointer.
3637 * fcport = port structure pointer.
3638 *
3639 * Return:
3640 * None.
3641 *
3642 * Context:
3643 */
3644void
e315cd28 3645qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
1da177e4
LT
3646{
3647 fc_port_t *fcport;
3648
726b8548
QT
3649 ql_dbg(ql_dbg_disc, vha, 0xffff,
3650 "Mark all dev lost\n");
3651
e315cd28 3652 list_for_each_entry(fcport, &vha->vp_fcports, list) {
726b8548
QT
3653 fcport->scan_state = 0;
3654 qlt_schedule_sess_for_deletion_lock(fcport);
3655
c6d39e23 3656 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
1da177e4 3657 continue;
0d6e61bc 3658
1da177e4
LT
3659 /*
3660 * No point in marking the device as lost, if the device is
3661 * already DEAD.
3662 */
3663 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3664 continue;
e315cd28 3665 if (atomic_read(&fcport->state) == FCS_ONLINE) {
ec426e10 3666 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
0d6e61bc
AV
3667 if (defer)
3668 qla2x00_schedule_rport_del(vha, fcport, defer);
c6d39e23 3669 else if (vha->vp_idx == fcport->vha->vp_idx)
0d6e61bc
AV
3670 qla2x00_schedule_rport_del(vha, fcport, defer);
3671 }
1da177e4
LT
3672 }
3673}
3674
3675/*
3676* qla2x00_mem_alloc
3677* Allocates adapter memory.
3678*
3679* Returns:
3680* 0 = success.
e8711085 3681* !0 = failure.
1da177e4 3682*/
e8711085 3683static int
73208dfd
AC
3684qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3685 struct req_que **req, struct rsp_que **rsp)
1da177e4
LT
3686{
3687 char name[16];
1da177e4 3688
e8711085 3689 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
e315cd28 3690 &ha->init_cb_dma, GFP_KERNEL);
e8711085 3691 if (!ha->init_cb)
e315cd28 3692 goto fail;
e8711085 3693
2d70c103
NB
3694 if (qlt_mem_alloc(ha) < 0)
3695 goto fail_free_init_cb;
3696
642ef983
CD
3697 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3698 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
e315cd28 3699 if (!ha->gid_list)
2d70c103 3700 goto fail_free_tgt_mem;
1da177e4 3701
e8711085
AV
3702 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3703 if (!ha->srb_mempool)
e315cd28 3704 goto fail_free_gid_list;
e8711085 3705
7ec0effd 3706 if (IS_P3P_TYPE(ha)) {
a9083016
GM
3707 /* Allocate cache for CT6 Ctx. */
3708 if (!ctx_cachep) {
3709 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3710 sizeof(struct ct6_dsd), 0,
3711 SLAB_HWCACHE_ALIGN, NULL);
3712 if (!ctx_cachep)
fc1ffd6c 3713 goto fail_free_srb_mempool;
a9083016
GM
3714 }
3715 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3716 ctx_cachep);
3717 if (!ha->ctx_mempool)
3718 goto fail_free_srb_mempool;
7c3df132
SK
3719 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3720 "ctx_cachep=%p ctx_mempool=%p.\n",
3721 ctx_cachep, ha->ctx_mempool);
a9083016
GM
3722 }
3723
e8711085
AV
3724 /* Get memory for cached NVRAM */
3725 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3726 if (!ha->nvram)
a9083016 3727 goto fail_free_ctx_mempool;
e8711085 3728
e315cd28
AC
3729 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3730 ha->pdev->device);
3731 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3732 DMA_POOL_SIZE, 8, 0);
3733 if (!ha->s_dma_pool)
3734 goto fail_free_nvram;
3735
7c3df132
SK
3736 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3737 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3738 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3739
7ec0effd 3740 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
a9083016
GM
3741 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3742 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3743 if (!ha->dl_dma_pool) {
7c3df132
SK
3744 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3745 "Failed to allocate memory for dl_dma_pool.\n");
a9083016
GM
3746 goto fail_s_dma_pool;
3747 }
3748
3749 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3750 FCP_CMND_DMA_POOL_SIZE, 8, 0);
3751 if (!ha->fcp_cmnd_dma_pool) {
7c3df132
SK
3752 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
3753 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
a9083016
GM
3754 goto fail_dl_dma_pool;
3755 }
7c3df132
SK
3756 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3757 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3758 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
a9083016
GM
3759 }
3760
e8711085
AV
3761 /* Allocate memory for SNS commands */
3762 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
e315cd28 3763 /* Get consistent memory allocated for SNS commands */
e8711085 3764 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
e315cd28 3765 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
e8711085 3766 if (!ha->sns_cmd)
e315cd28 3767 goto fail_dma_pool;
7c3df132 3768 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
d8424f68 3769 "sns_cmd: %p.\n", ha->sns_cmd);
e8711085 3770 } else {
e315cd28 3771 /* Get consistent memory allocated for MS IOCB */
e8711085 3772 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
e315cd28 3773 &ha->ms_iocb_dma);
e8711085 3774 if (!ha->ms_iocb)
e315cd28
AC
3775 goto fail_dma_pool;
3776 /* Get consistent memory allocated for CT SNS commands */
e8711085 3777 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
e315cd28 3778 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
e8711085
AV
3779 if (!ha->ct_sns)
3780 goto fail_free_ms_iocb;
7c3df132
SK
3781 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
3782 "ms_iocb=%p ct_sns=%p.\n",
3783 ha->ms_iocb, ha->ct_sns);
1da177e4
LT
3784 }
3785
e315cd28 3786 /* Allocate memory for request ring */
73208dfd
AC
3787 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
3788 if (!*req) {
7c3df132
SK
3789 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
3790 "Failed to allocate memory for req.\n");
e315cd28
AC
3791 goto fail_req;
3792 }
73208dfd
AC
3793 (*req)->length = req_len;
3794 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
3795 ((*req)->length + 1) * sizeof(request_t),
3796 &(*req)->dma, GFP_KERNEL);
3797 if (!(*req)->ring) {
7c3df132
SK
3798 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
3799 "Failed to allocate memory for req_ring.\n");
e315cd28
AC
3800 goto fail_req_ring;
3801 }
3802 /* Allocate memory for response ring */
73208dfd
AC
3803 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
3804 if (!*rsp) {
7c3df132
SK
3805 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
3806 "Failed to allocate memory for rsp.\n");
e315cd28
AC
3807 goto fail_rsp;
3808 }
73208dfd
AC
3809 (*rsp)->hw = ha;
3810 (*rsp)->length = rsp_len;
3811 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
3812 ((*rsp)->length + 1) * sizeof(response_t),
3813 &(*rsp)->dma, GFP_KERNEL);
3814 if (!(*rsp)->ring) {
7c3df132
SK
3815 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
3816 "Failed to allocate memory for rsp_ring.\n");
e315cd28
AC
3817 goto fail_rsp_ring;
3818 }
73208dfd
AC
3819 (*req)->rsp = *rsp;
3820 (*rsp)->req = *req;
7c3df132
SK
3821 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
3822 "req=%p req->length=%d req->ring=%p rsp=%p "
3823 "rsp->length=%d rsp->ring=%p.\n",
3824 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
3825 (*rsp)->ring);
73208dfd
AC
3826 /* Allocate memory for NVRAM data for vports */
3827 if (ha->nvram_npiv_size) {
3828 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
7c3df132 3829 ha->nvram_npiv_size, GFP_KERNEL);
73208dfd 3830 if (!ha->npiv_info) {
7c3df132
SK
3831 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
3832 "Failed to allocate memory for npiv_info.\n");
73208dfd
AC
3833 goto fail_npiv_info;
3834 }
3835 } else
3836 ha->npiv_info = NULL;
e8711085 3837
b64b0e8f 3838 /* Get consistent memory allocated for EX-INIT-CB. */
f73cb695 3839 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
b64b0e8f
AV
3840 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3841 &ha->ex_init_cb_dma);
3842 if (!ha->ex_init_cb)
3843 goto fail_ex_init_cb;
7c3df132
SK
3844 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
3845 "ex_init_cb=%p.\n", ha->ex_init_cb);
b64b0e8f
AV
3846 }
3847
a9083016
GM
3848 INIT_LIST_HEAD(&ha->gbl_dsd_list);
3849
5ff1d584
AV
3850 /* Get consistent memory allocated for Async Port-Database. */
3851 if (!IS_FWI2_CAPABLE(ha)) {
3852 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3853 &ha->async_pd_dma);
3854 if (!ha->async_pd)
3855 goto fail_async_pd;
7c3df132
SK
3856 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
3857 "async_pd=%p.\n", ha->async_pd);
5ff1d584
AV
3858 }
3859
e315cd28 3860 INIT_LIST_HEAD(&ha->vp_list);
5f16b331
CD
3861
3862 /* Allocate memory for our loop_id bitmap */
3863 ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
3864 GFP_KERNEL);
3865 if (!ha->loop_id_map)
fc1ffd6c 3866 goto fail_loop_id_map;
5f16b331
CD
3867 else {
3868 qla2x00_set_reserved_loop_ids(ha);
3869 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
b2a72ec3 3870 "loop_id_map=%p.\n", ha->loop_id_map);
5f16b331
CD
3871 }
3872
b2a72ec3 3873 return 0;
e315cd28 3874
fc1ffd6c
QT
3875fail_loop_id_map:
3876 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
5ff1d584
AV
3877fail_async_pd:
3878 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
b64b0e8f
AV
3879fail_ex_init_cb:
3880 kfree(ha->npiv_info);
73208dfd
AC
3881fail_npiv_info:
3882 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
3883 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
3884 (*rsp)->ring = NULL;
3885 (*rsp)->dma = 0;
e315cd28 3886fail_rsp_ring:
73208dfd 3887 kfree(*rsp);
e315cd28 3888fail_rsp:
73208dfd
AC
3889 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
3890 sizeof(request_t), (*req)->ring, (*req)->dma);
3891 (*req)->ring = NULL;
3892 (*req)->dma = 0;
e315cd28 3893fail_req_ring:
73208dfd 3894 kfree(*req);
e315cd28
AC
3895fail_req:
3896 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
3897 ha->ct_sns, ha->ct_sns_dma);
3898 ha->ct_sns = NULL;
3899 ha->ct_sns_dma = 0;
e8711085
AV
3900fail_free_ms_iocb:
3901 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3902 ha->ms_iocb = NULL;
3903 ha->ms_iocb_dma = 0;
fc1ffd6c
QT
3904
3905 if (ha->sns_cmd)
3906 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
3907 ha->sns_cmd, ha->sns_cmd_dma);
e315cd28 3908fail_dma_pool:
bad75002 3909 if (IS_QLA82XX(ha) || ql2xenabledif) {
a9083016
GM
3910 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3911 ha->fcp_cmnd_dma_pool = NULL;
3912 }
3913fail_dl_dma_pool:
bad75002 3914 if (IS_QLA82XX(ha) || ql2xenabledif) {
a9083016
GM
3915 dma_pool_destroy(ha->dl_dma_pool);
3916 ha->dl_dma_pool = NULL;
3917 }
3918fail_s_dma_pool:
e315cd28
AC
3919 dma_pool_destroy(ha->s_dma_pool);
3920 ha->s_dma_pool = NULL;
e8711085
AV
3921fail_free_nvram:
3922 kfree(ha->nvram);
3923 ha->nvram = NULL;
a9083016 3924fail_free_ctx_mempool:
fc1ffd6c
QT
3925 if (ha->ctx_mempool)
3926 mempool_destroy(ha->ctx_mempool);
a9083016 3927 ha->ctx_mempool = NULL;
e8711085 3928fail_free_srb_mempool:
fc1ffd6c
QT
3929 if (ha->srb_mempool)
3930 mempool_destroy(ha->srb_mempool);
e8711085 3931 ha->srb_mempool = NULL;
e8711085 3932fail_free_gid_list:
642ef983
CD
3933 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
3934 ha->gid_list,
e315cd28 3935 ha->gid_list_dma);
e8711085
AV
3936 ha->gid_list = NULL;
3937 ha->gid_list_dma = 0;
2d70c103
NB
3938fail_free_tgt_mem:
3939 qlt_mem_free(ha);
e315cd28
AC
3940fail_free_init_cb:
3941 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
3942 ha->init_cb_dma);
3943 ha->init_cb = NULL;
3944 ha->init_cb_dma = 0;
e8711085 3945fail:
7c3df132
SK
3946 ql_log(ql_log_fatal, NULL, 0x0030,
3947 "Memory allocation failure.\n");
e8711085 3948 return -ENOMEM;
1da177e4
LT
3949}
3950
b0d6cabd
HM
3951int
3952qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
3953{
3954 int rval;
3955 uint16_t size, max_cnt, temp;
3956 struct qla_hw_data *ha = vha->hw;
3957
3958 /* Return if we don't need to alloacate any extended logins */
3959 if (!ql2xexlogins)
3960 return QLA_SUCCESS;
3961
3962 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
3963 max_cnt = 0;
3964 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
3965 if (rval != QLA_SUCCESS) {
3966 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
3967 "Failed to get exlogin status.\n");
3968 return rval;
3969 }
3970
3971 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
3972 ha->exlogin_size = (size * temp);
3973 ql_log(ql_log_info, vha, 0xd024,
3974 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
3975 max_cnt, size, temp);
3976
3977 ql_log(ql_log_info, vha, 0xd025, "EXLOGIN: requested size=0x%x\n",
3978 ha->exlogin_size);
3979
3980 /* Get consistent memory for extended logins */
3981 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
3982 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
3983 if (!ha->exlogin_buf) {
3984 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
3985 "Failed to allocate memory for exlogin_buf_dma.\n");
3986 return -ENOMEM;
3987 }
3988
3989 /* Now configure the dma buffer */
3990 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
3991 if (rval) {
3992 ql_log(ql_log_fatal, vha, 0x00cf,
3993 "Setup extended login buffer ****FAILED****.\n");
3994 qla2x00_free_exlogin_buffer(ha);
3995 }
3996
3997 return rval;
3998}
3999
4000/*
4001* qla2x00_free_exlogin_buffer
4002*
4003* Input:
4004* ha = adapter block pointer
4005*/
4006void
4007qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4008{
4009 if (ha->exlogin_buf) {
4010 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4011 ha->exlogin_buf, ha->exlogin_buf_dma);
4012 ha->exlogin_buf = NULL;
4013 ha->exlogin_size = 0;
4014 }
4015}
4016
2f56a7f1
HM
4017int
4018qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4019{
4020 int rval;
4021 uint16_t size, max_cnt, temp;
4022 struct qla_hw_data *ha = vha->hw;
4023
4024 /* Return if we don't need to alloacate any extended logins */
4025 if (!ql2xexchoffld)
4026 return QLA_SUCCESS;
4027
4028 ql_log(ql_log_info, vha, 0xd014,
4029 "Exchange offload count: %d.\n", ql2xexlogins);
4030
4031 max_cnt = 0;
4032 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4033 if (rval != QLA_SUCCESS) {
4034 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4035 "Failed to get exlogin status.\n");
4036 return rval;
4037 }
4038
4039 temp = (ql2xexchoffld > max_cnt) ? max_cnt : ql2xexchoffld;
4040 ha->exchoffld_size = (size * temp);
4041 ql_log(ql_log_info, vha, 0xd016,
4042 "Exchange offload: max_count=%d, buffers=0x%x, total=%d.\n",
4043 max_cnt, size, temp);
4044
4045 ql_log(ql_log_info, vha, 0xd017,
4046 "Exchange Buffers requested size = 0x%x\n", ha->exchoffld_size);
4047
4048 /* Get consistent memory for extended logins */
4049 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4050 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4051 if (!ha->exchoffld_buf) {
4052 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4053 "Failed to allocate memory for exchoffld_buf_dma.\n");
4054 return -ENOMEM;
4055 }
4056
4057 /* Now configure the dma buffer */
4058 rval = qla_set_exchoffld_mem_cfg(vha, ha->exchoffld_buf_dma);
4059 if (rval) {
4060 ql_log(ql_log_fatal, vha, 0xd02e,
4061 "Setup exchange offload buffer ****FAILED****.\n");
4062 qla2x00_free_exchoffld_buffer(ha);
4063 }
4064
4065 return rval;
4066}
4067
4068/*
4069* qla2x00_free_exchoffld_buffer
4070*
4071* Input:
4072* ha = adapter block pointer
4073*/
4074void
4075qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4076{
4077 if (ha->exchoffld_buf) {
4078 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4079 ha->exchoffld_buf, ha->exchoffld_buf_dma);
4080 ha->exchoffld_buf = NULL;
4081 ha->exchoffld_size = 0;
4082 }
4083}
4084
1da177e4 4085/*
e30d1756
MI
4086* qla2x00_free_fw_dump
4087* Frees fw dump stuff.
1da177e4
LT
4088*
4089* Input:
7ec0effd 4090* ha = adapter block pointer
1da177e4 4091*/
a824ebb3 4092static void
e30d1756 4093qla2x00_free_fw_dump(struct qla_hw_data *ha)
1da177e4 4094{
df613b96 4095 if (ha->fce)
f73cb695
CD
4096 dma_free_coherent(&ha->pdev->dev,
4097 FCE_SIZE, ha->fce, ha->fce_dma);
df613b96 4098
f73cb695
CD
4099 if (ha->eft)
4100 dma_free_coherent(&ha->pdev->dev,
4101 EFT_SIZE, ha->eft, ha->eft_dma);
4102
4103 if (ha->fw_dump)
a7a167bf 4104 vfree(ha->fw_dump);
f73cb695
CD
4105 if (ha->fw_dump_template)
4106 vfree(ha->fw_dump_template);
4107
e30d1756
MI
4108 ha->fce = NULL;
4109 ha->fce_dma = 0;
4110 ha->eft = NULL;
4111 ha->eft_dma = 0;
e30d1756 4112 ha->fw_dumped = 0;
61f098dd 4113 ha->fw_dump_cap_flags = 0;
e30d1756 4114 ha->fw_dump_reading = 0;
f73cb695
CD
4115 ha->fw_dump = NULL;
4116 ha->fw_dump_len = 0;
4117 ha->fw_dump_template = NULL;
4118 ha->fw_dump_template_len = 0;
e30d1756
MI
4119}
4120
4121/*
4122* qla2x00_mem_free
4123* Frees all adapter allocated memory.
4124*
4125* Input:
4126* ha = adapter block pointer.
4127*/
4128static void
4129qla2x00_mem_free(struct qla_hw_data *ha)
4130{
4131 qla2x00_free_fw_dump(ha);
4132
81178772
SK
4133 if (ha->mctp_dump)
4134 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4135 ha->mctp_dump_dma);
4136
e30d1756
MI
4137 if (ha->srb_mempool)
4138 mempool_destroy(ha->srb_mempool);
a7a167bf 4139
11bbc1d8
AV
4140 if (ha->dcbx_tlv)
4141 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4142 ha->dcbx_tlv, ha->dcbx_tlv_dma);
4143
ce0423f4
AV
4144 if (ha->xgmac_data)
4145 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4146 ha->xgmac_data, ha->xgmac_data_dma);
4147
1da177e4
LT
4148 if (ha->sns_cmd)
4149 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
e315cd28 4150 ha->sns_cmd, ha->sns_cmd_dma);
1da177e4
LT
4151
4152 if (ha->ct_sns)
4153 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
e315cd28 4154 ha->ct_sns, ha->ct_sns_dma);
1da177e4 4155
88729e53
AV
4156 if (ha->sfp_data)
4157 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
4158
1da177e4
LT
4159 if (ha->ms_iocb)
4160 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4161
b64b0e8f 4162 if (ha->ex_init_cb)
a9083016
GM
4163 dma_pool_free(ha->s_dma_pool,
4164 ha->ex_init_cb, ha->ex_init_cb_dma);
b64b0e8f 4165
5ff1d584
AV
4166 if (ha->async_pd)
4167 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4168
1da177e4
LT
4169 if (ha->s_dma_pool)
4170 dma_pool_destroy(ha->s_dma_pool);
4171
1da177e4 4172 if (ha->gid_list)
642ef983
CD
4173 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4174 ha->gid_list, ha->gid_list_dma);
1da177e4 4175
a9083016
GM
4176 if (IS_QLA82XX(ha)) {
4177 if (!list_empty(&ha->gbl_dsd_list)) {
4178 struct dsd_dma *dsd_ptr, *tdsd_ptr;
4179
4180 /* clean up allocated prev pool */
4181 list_for_each_entry_safe(dsd_ptr,
4182 tdsd_ptr, &ha->gbl_dsd_list, list) {
4183 dma_pool_free(ha->dl_dma_pool,
4184 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
4185 list_del(&dsd_ptr->list);
4186 kfree(dsd_ptr);
4187 }
4188 }
4189 }
4190
4191 if (ha->dl_dma_pool)
4192 dma_pool_destroy(ha->dl_dma_pool);
4193
4194 if (ha->fcp_cmnd_dma_pool)
4195 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4196
4197 if (ha->ctx_mempool)
4198 mempool_destroy(ha->ctx_mempool);
4199
2d70c103
NB
4200 qlt_mem_free(ha);
4201
e315cd28
AC
4202 if (ha->init_cb)
4203 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
a9083016 4204 ha->init_cb, ha->init_cb_dma);
e315cd28
AC
4205 vfree(ha->optrom_buffer);
4206 kfree(ha->nvram);
73208dfd 4207 kfree(ha->npiv_info);
7a67735b 4208 kfree(ha->swl);
5f16b331 4209 kfree(ha->loop_id_map);
1da177e4 4210
e8711085 4211 ha->srb_mempool = NULL;
a9083016 4212 ha->ctx_mempool = NULL;
1da177e4
LT
4213 ha->sns_cmd = NULL;
4214 ha->sns_cmd_dma = 0;
4215 ha->ct_sns = NULL;
4216 ha->ct_sns_dma = 0;
4217 ha->ms_iocb = NULL;
4218 ha->ms_iocb_dma = 0;
1da177e4
LT
4219 ha->init_cb = NULL;
4220 ha->init_cb_dma = 0;
b64b0e8f
AV
4221 ha->ex_init_cb = NULL;
4222 ha->ex_init_cb_dma = 0;
5ff1d584
AV
4223 ha->async_pd = NULL;
4224 ha->async_pd_dma = 0;
1da177e4
LT
4225
4226 ha->s_dma_pool = NULL;
a9083016
GM
4227 ha->dl_dma_pool = NULL;
4228 ha->fcp_cmnd_dma_pool = NULL;
1da177e4 4229
1da177e4
LT
4230 ha->gid_list = NULL;
4231 ha->gid_list_dma = 0;
2d70c103
NB
4232
4233 ha->tgt.atio_ring = NULL;
4234 ha->tgt.atio_dma = 0;
4235 ha->tgt.tgt_vp_map = NULL;
e315cd28 4236}
1da177e4 4237
e315cd28
AC
4238struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4239 struct qla_hw_data *ha)
4240{
4241 struct Scsi_Host *host;
4242 struct scsi_qla_host *vha = NULL;
854165f4 4243
e315cd28 4244 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
41dc529a 4245 if (!host) {
7c3df132
SK
4246 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4247 "Failed to allocate host from the scsi layer, aborting.\n");
41dc529a 4248 return NULL;
e315cd28
AC
4249 }
4250
4251 /* Clear our data area */
4252 vha = shost_priv(host);
4253 memset(vha, 0, sizeof(scsi_qla_host_t));
4254
4255 vha->host = host;
4256 vha->host_no = host->host_no;
4257 vha->hw = ha;
4258
4259 INIT_LIST_HEAD(&vha->vp_fcports);
4260 INIT_LIST_HEAD(&vha->work_list);
4261 INIT_LIST_HEAD(&vha->list);
8b2f5ff3
SN
4262 INIT_LIST_HEAD(&vha->qla_cmd_list);
4263 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
71cdc079 4264 INIT_LIST_HEAD(&vha->logo_list);
b7bd104e 4265 INIT_LIST_HEAD(&vha->plogi_ack_list);
d7459527 4266 INIT_LIST_HEAD(&vha->qp_list);
41dc529a 4267 INIT_LIST_HEAD(&vha->gnl.fcports);
e315cd28 4268
f999f4c1 4269 spin_lock_init(&vha->work_lock);
8b2f5ff3 4270 spin_lock_init(&vha->cmd_list_lock);
726b8548 4271 init_waitqueue_head(&vha->fcport_waitQ);
c4a9b538 4272 init_waitqueue_head(&vha->vref_waitq);
f999f4c1 4273
2fdbc65e
BVA
4274 vha->gnl.size = sizeof(struct get_name_list_extended) *
4275 (ha->max_loop_id + 1);
41dc529a
QT
4276 vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
4277 vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
4278 if (!vha->gnl.l) {
4279 ql_log(ql_log_fatal, vha, 0xffff,
4280 "Alloc failed for name list.\n");
4281 scsi_remove_host(vha->host);
4282 return NULL;
4283 }
f999f4c1 4284
e315cd28 4285 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
7c3df132
SK
4286 ql_dbg(ql_dbg_init, vha, 0x0041,
4287 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4288 vha->host, vha->hw, vha,
4289 dev_name(&(ha->pdev->dev)));
4290
e315cd28 4291 return vha;
1da177e4
LT
4292}
4293
726b8548 4294struct qla_work_evt *
f999f4c1 4295qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
0971de7f
AV
4296{
4297 struct qla_work_evt *e;
feafb7b1
AE
4298 uint8_t bail;
4299
4300 QLA_VHA_MARK_BUSY(vha, bail);
4301 if (bail)
4302 return NULL;
0971de7f 4303
f999f4c1 4304 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
feafb7b1
AE
4305 if (!e) {
4306 QLA_VHA_MARK_NOT_BUSY(vha);
0971de7f 4307 return NULL;
feafb7b1 4308 }
0971de7f
AV
4309
4310 INIT_LIST_HEAD(&e->list);
4311 e->type = type;
4312 e->flags = QLA_EVT_FLAG_FREE;
4313 return e;
4314}
4315
726b8548 4316int
f999f4c1 4317qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
0971de7f 4318{
f999f4c1 4319 unsigned long flags;
0971de7f 4320
f999f4c1 4321 spin_lock_irqsave(&vha->work_lock, flags);
e315cd28 4322 list_add_tail(&e->list, &vha->work_list);
f999f4c1 4323 spin_unlock_irqrestore(&vha->work_lock, flags);
e315cd28 4324 qla2xxx_wake_dpc(vha);
f999f4c1 4325
0971de7f
AV
4326 return QLA_SUCCESS;
4327}
4328
4329int
e315cd28 4330qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
0971de7f
AV
4331 u32 data)
4332{
4333 struct qla_work_evt *e;
4334
f999f4c1 4335 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
0971de7f
AV
4336 if (!e)
4337 return QLA_FUNCTION_FAILED;
4338
4339 e->u.aen.code = code;
4340 e->u.aen.data = data;
f999f4c1 4341 return qla2x00_post_work(vha, e);
0971de7f
AV
4342}
4343
8a659571
AV
4344int
4345qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
4346{
4347 struct qla_work_evt *e;
4348
f999f4c1 4349 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
8a659571
AV
4350 if (!e)
4351 return QLA_FUNCTION_FAILED;
4352
4353 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
f999f4c1 4354 return qla2x00_post_work(vha, e);
8a659571
AV
4355}
4356
ac280b67
AV
4357#define qla2x00_post_async_work(name, type) \
4358int qla2x00_post_async_##name##_work( \
4359 struct scsi_qla_host *vha, \
4360 fc_port_t *fcport, uint16_t *data) \
4361{ \
4362 struct qla_work_evt *e; \
4363 \
4364 e = qla2x00_alloc_work(vha, type); \
4365 if (!e) \
4366 return QLA_FUNCTION_FAILED; \
4367 \
4368 e->u.logio.fcport = fcport; \
4369 if (data) { \
4370 e->u.logio.data[0] = data[0]; \
4371 e->u.logio.data[1] = data[1]; \
4372 } \
4373 return qla2x00_post_work(vha, e); \
4374}
4375
4376qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
ac280b67
AV
4377qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
4378qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
5ff1d584
AV
4379qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
4380qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
ac280b67 4381
3420d36c
AV
4382int
4383qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
4384{
4385 struct qla_work_evt *e;
4386
4387 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
4388 if (!e)
4389 return QLA_FUNCTION_FAILED;
4390
4391 e->u.uevent.code = code;
4392 return qla2x00_post_work(vha, e);
4393}
4394
4395static void
4396qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
4397{
4398 char event_string[40];
4399 char *envp[] = { event_string, NULL };
4400
4401 switch (code) {
4402 case QLA_UEVENT_CODE_FW_DUMP:
4403 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
4404 vha->host_no);
4405 break;
4406 default:
4407 /* do nothing */
4408 break;
4409 }
4410 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
4411}
4412
8ae6d9c7
GM
4413int
4414qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
4415 uint32_t *data, int cnt)
4416{
4417 struct qla_work_evt *e;
4418
4419 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
4420 if (!e)
4421 return QLA_FUNCTION_FAILED;
4422
4423 e->u.aenfx.evtcode = evtcode;
4424 e->u.aenfx.count = cnt;
4425 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
4426 return qla2x00_post_work(vha, e);
4427}
4428
726b8548
QT
4429int qla24xx_post_upd_fcport_work(struct scsi_qla_host *vha, fc_port_t *fcport)
4430{
4431 struct qla_work_evt *e;
4432
4433 e = qla2x00_alloc_work(vha, QLA_EVT_UPD_FCPORT);
4434 if (!e)
4435 return QLA_FUNCTION_FAILED;
4436
4437 e->u.fcport.fcport = fcport;
4438 return qla2x00_post_work(vha, e);
4439}
4440
4441static
4442void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
4443{
4444 unsigned long flags;
4445 fc_port_t *fcport = NULL;
4446 struct qlt_plogi_ack_t *pla =
4447 (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
4448
4449 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4450 fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
4451 if (fcport) {
4452 fcport->d_id = e->u.new_sess.id;
4453 if (pla) {
4454 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
4455 qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
4456 /* we took an extra ref_count to prevent PLOGI ACK when
4457 * fcport/sess has not been created.
4458 */
4459 pla->ref_count--;
4460 }
4461 } else {
4462 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
4463 if (fcport) {
4464 fcport->d_id = e->u.new_sess.id;
4465 fcport->scan_state = QLA_FCPORT_FOUND;
4466 fcport->flags |= FCF_FABRIC_DEVICE;
4467 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
4468
4469 memcpy(fcport->port_name, e->u.new_sess.port_name,
4470 WWN_SIZE);
4471 list_add_tail(&fcport->list, &vha->vp_fcports);
4472
4473 if (pla) {
4474 qlt_plogi_ack_link(vha, pla, fcport,
4475 QLT_PLOGI_LINK_SAME_WWN);
4476 pla->ref_count--;
4477 }
4478 }
4479 }
4480 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4481
4482 if (fcport) {
4483 if (pla)
4484 qlt_plogi_ack_unref(vha, pla);
4485 else
4486 qla24xx_async_gnl(vha, fcport);
4487 }
4488}
4489
ac280b67 4490void
e315cd28 4491qla2x00_do_work(struct scsi_qla_host *vha)
0971de7f 4492{
f999f4c1
AV
4493 struct qla_work_evt *e, *tmp;
4494 unsigned long flags;
4495 LIST_HEAD(work);
0971de7f 4496
f999f4c1
AV
4497 spin_lock_irqsave(&vha->work_lock, flags);
4498 list_splice_init(&vha->work_list, &work);
4499 spin_unlock_irqrestore(&vha->work_lock, flags);
4500
4501 list_for_each_entry_safe(e, tmp, &work, list) {
0971de7f 4502 list_del_init(&e->list);
0971de7f
AV
4503
4504 switch (e->type) {
4505 case QLA_EVT_AEN:
e315cd28 4506 fc_host_post_event(vha->host, fc_get_event_number(),
0971de7f
AV
4507 e->u.aen.code, e->u.aen.data);
4508 break;
8a659571
AV
4509 case QLA_EVT_IDC_ACK:
4510 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
4511 break;
ac280b67
AV
4512 case QLA_EVT_ASYNC_LOGIN:
4513 qla2x00_async_login(vha, e->u.logio.fcport,
4514 e->u.logio.data);
4515 break;
ac280b67
AV
4516 case QLA_EVT_ASYNC_LOGOUT:
4517 qla2x00_async_logout(vha, e->u.logio.fcport);
4518 break;
4519 case QLA_EVT_ASYNC_LOGOUT_DONE:
4520 qla2x00_async_logout_done(vha, e->u.logio.fcport,
4521 e->u.logio.data);
4522 break;
5ff1d584
AV
4523 case QLA_EVT_ASYNC_ADISC:
4524 qla2x00_async_adisc(vha, e->u.logio.fcport,
4525 e->u.logio.data);
4526 break;
4527 case QLA_EVT_ASYNC_ADISC_DONE:
4528 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
4529 e->u.logio.data);
4530 break;
3420d36c
AV
4531 case QLA_EVT_UEVENT:
4532 qla2x00_uevent_emit(vha, e->u.uevent.code);
4533 break;
8ae6d9c7
GM
4534 case QLA_EVT_AENFX:
4535 qlafx00_process_aen(vha, e);
4536 break;
726b8548
QT
4537 case QLA_EVT_GIDPN:
4538 qla24xx_async_gidpn(vha, e->u.fcport.fcport);
4539 break;
4540 case QLA_EVT_GPNID:
4541 qla24xx_async_gpnid(vha, &e->u.gpnid.id);
4542 break;
4543 case QLA_EVT_GPNID_DONE:
4544 qla24xx_async_gpnid_done(vha, e->u.iosb.sp);
4545 break;
4546 case QLA_EVT_NEW_SESS:
4547 qla24xx_create_new_sess(vha, e);
4548 break;
4549 case QLA_EVT_GPDB:
4550 qla24xx_async_gpdb(vha, e->u.fcport.fcport,
4551 e->u.fcport.opt);
4552 break;
4553 case QLA_EVT_GPSC:
4554 qla24xx_async_gpsc(vha, e->u.fcport.fcport);
4555 break;
4556 case QLA_EVT_UPD_FCPORT:
4557 qla2x00_update_fcport(vha, e->u.fcport.fcport);
4558 break;
4559 case QLA_EVT_GNL:
4560 qla24xx_async_gnl(vha, e->u.fcport.fcport);
4561 break;
4562 case QLA_EVT_NACK:
4563 qla24xx_do_nack_work(vha, e);
4564 break;
0971de7f
AV
4565 }
4566 if (e->flags & QLA_EVT_FLAG_FREE)
4567 kfree(e);
feafb7b1
AE
4568
4569 /* For each work completed decrement vha ref count */
4570 QLA_VHA_MARK_NOT_BUSY(vha);
e315cd28 4571 }
e315cd28 4572}
f999f4c1 4573
e315cd28
AC
4574/* Relogins all the fcports of a vport
4575 * Context: dpc thread
4576 */
4577void qla2x00_relogin(struct scsi_qla_host *vha)
4578{
4579 fc_port_t *fcport;
c6b2fca8 4580 int status;
726b8548 4581 struct event_arg ea;
e315cd28
AC
4582
4583 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4584 /*
4585 * If the port is not ONLINE then try to login
4586 * to it if we haven't run out of retries.
4587 */
5ff1d584
AV
4588 if (atomic_read(&fcport->state) != FCS_ONLINE &&
4589 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
ac280b67 4590 fcport->login_retry--;
e315cd28 4591 if (fcport->flags & FCF_FABRIC_DEVICE) {
726b8548
QT
4592 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
4593 "%s %8phC DS %d LS %d\n", __func__,
4594 fcport->port_name, fcport->disc_state,
4595 fcport->fw_login_state);
4596 memset(&ea, 0, sizeof(ea));
4597 ea.event = FCME_RELOGIN;
4598 ea.fcport = fcport;
4599 qla2x00_fcport_event_handler(vha, &ea);
4600 } else {
e315cd28
AC
4601 status = qla2x00_local_device_login(vha,
4602 fcport);
726b8548
QT
4603 if (status == QLA_SUCCESS) {
4604 fcport->old_loop_id = fcport->loop_id;
4605 ql_dbg(ql_dbg_disc, vha, 0x2003,
4606 "Port login OK: logged in ID 0x%x.\n",
4607 fcport->loop_id);
4608 qla2x00_update_fcport(vha, fcport);
4609 } else if (status == 1) {
4610 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4611 /* retry the login again */
4612 ql_dbg(ql_dbg_disc, vha, 0x2007,
4613 "Retrying %d login again loop_id 0x%x.\n",
4614 fcport->login_retry,
4615 fcport->loop_id);
4616 } else {
4617 fcport->login_retry = 0;
4618 }
e315cd28 4619
726b8548
QT
4620 if (fcport->login_retry == 0 &&
4621 status != QLA_SUCCESS)
4622 qla2x00_clear_loop_id(fcport);
e315cd28 4623 }
e315cd28
AC
4624 }
4625 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4626 break;
0971de7f 4627 }
0971de7f
AV
4628}
4629
7d613ac6
SV
4630/* Schedule work on any of the dpc-workqueues */
4631void
4632qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
4633{
4634 struct qla_hw_data *ha = base_vha->hw;
4635
4636 switch (work_code) {
4637 case MBA_IDC_AEN: /* 0x8200 */
4638 if (ha->dpc_lp_wq)
4639 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
4640 break;
4641
4642 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
4643 if (!ha->flags.nic_core_reset_hdlr_active) {
4644 if (ha->dpc_hp_wq)
4645 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
4646 } else
4647 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
4648 "NIC Core reset is already active. Skip "
4649 "scheduling it again.\n");
4650 break;
4651 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
4652 if (ha->dpc_hp_wq)
4653 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
4654 break;
4655 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
4656 if (ha->dpc_hp_wq)
4657 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
4658 break;
4659 default:
4660 ql_log(ql_log_warn, base_vha, 0xb05f,
d939be3a 4661 "Unknown work-code=0x%x.\n", work_code);
7d613ac6
SV
4662 }
4663
4664 return;
4665}
4666
4667/* Work: Perform NIC Core Unrecoverable state handling */
4668void
4669qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
4670{
4671 struct qla_hw_data *ha =
2ad1b67c 4672 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
7d613ac6
SV
4673 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4674 uint32_t dev_state = 0;
4675
4676 qla83xx_idc_lock(base_vha, 0);
4677 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4678 qla83xx_reset_ownership(base_vha);
4679 if (ha->flags.nic_core_reset_owner) {
4680 ha->flags.nic_core_reset_owner = 0;
4681 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4682 QLA8XXX_DEV_FAILED);
4683 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
4684 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4685 }
4686 qla83xx_idc_unlock(base_vha, 0);
4687}
4688
4689/* Work: Execute IDC state handler */
4690void
4691qla83xx_idc_state_handler_work(struct work_struct *work)
4692{
4693 struct qla_hw_data *ha =
2ad1b67c 4694 container_of(work, struct qla_hw_data, idc_state_handler);
7d613ac6
SV
4695 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4696 uint32_t dev_state = 0;
4697
4698 qla83xx_idc_lock(base_vha, 0);
4699 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4700 if (dev_state == QLA8XXX_DEV_FAILED ||
4701 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
4702 qla83xx_idc_state_handler(base_vha);
4703 qla83xx_idc_unlock(base_vha, 0);
4704}
4705
fa492630 4706static int
7d613ac6
SV
4707qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
4708{
4709 int rval = QLA_SUCCESS;
4710 unsigned long heart_beat_wait = jiffies + (1 * HZ);
4711 uint32_t heart_beat_counter1, heart_beat_counter2;
4712
4713 do {
4714 if (time_after(jiffies, heart_beat_wait)) {
4715 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
4716 "Nic Core f/w is not alive.\n");
4717 rval = QLA_FUNCTION_FAILED;
4718 break;
4719 }
4720
4721 qla83xx_idc_lock(base_vha, 0);
4722 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4723 &heart_beat_counter1);
4724 qla83xx_idc_unlock(base_vha, 0);
4725 msleep(100);
4726 qla83xx_idc_lock(base_vha, 0);
4727 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
4728 &heart_beat_counter2);
4729 qla83xx_idc_unlock(base_vha, 0);
4730 } while (heart_beat_counter1 == heart_beat_counter2);
4731
4732 return rval;
4733}
4734
4735/* Work: Perform NIC Core Reset handling */
4736void
4737qla83xx_nic_core_reset_work(struct work_struct *work)
4738{
4739 struct qla_hw_data *ha =
4740 container_of(work, struct qla_hw_data, nic_core_reset);
4741 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4742 uint32_t dev_state = 0;
4743
81178772
SK
4744 if (IS_QLA2031(ha)) {
4745 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
4746 ql_log(ql_log_warn, base_vha, 0xb081,
4747 "Failed to dump mctp\n");
4748 return;
4749 }
4750
7d613ac6
SV
4751 if (!ha->flags.nic_core_reset_hdlr_active) {
4752 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
4753 qla83xx_idc_lock(base_vha, 0);
4754 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
4755 &dev_state);
4756 qla83xx_idc_unlock(base_vha, 0);
4757 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
4758 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
4759 "Nic Core f/w is alive.\n");
4760 return;
4761 }
4762 }
4763
4764 ha->flags.nic_core_reset_hdlr_active = 1;
4765 if (qla83xx_nic_core_reset(base_vha)) {
4766 /* NIC Core reset failed. */
4767 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
4768 "NIC Core reset failed.\n");
4769 }
4770 ha->flags.nic_core_reset_hdlr_active = 0;
4771 }
4772}
4773
4774/* Work: Handle 8200 IDC aens */
4775void
4776qla83xx_service_idc_aen(struct work_struct *work)
4777{
4778 struct qla_hw_data *ha =
4779 container_of(work, struct qla_hw_data, idc_aen);
4780 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4781 uint32_t dev_state, idc_control;
4782
4783 qla83xx_idc_lock(base_vha, 0);
4784 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4785 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
4786 qla83xx_idc_unlock(base_vha, 0);
4787 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
4788 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
4789 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
4790 "Application requested NIC Core Reset.\n");
4791 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4792 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
4793 QLA_SUCCESS) {
4794 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
4795 "Other protocol driver requested NIC Core Reset.\n");
4796 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
4797 }
4798 } else if (dev_state == QLA8XXX_DEV_FAILED ||
4799 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
4800 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
4801 }
4802}
4803
4804static void
4805qla83xx_wait_logic(void)
4806{
4807 int i;
4808
4809 /* Yield CPU */
4810 if (!in_interrupt()) {
4811 /*
4812 * Wait about 200ms before retrying again.
4813 * This controls the number of retries for single
4814 * lock operation.
4815 */
4816 msleep(100);
4817 schedule();
4818 } else {
4819 for (i = 0; i < 20; i++)
4820 cpu_relax(); /* This a nop instr on i386 */
4821 }
4822}
4823
fa492630 4824static int
7d613ac6
SV
4825qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
4826{
4827 int rval;
4828 uint32_t data;
4829 uint32_t idc_lck_rcvry_stage_mask = 0x3;
4830 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
4831 struct qla_hw_data *ha = base_vha->hw;
6c315553
SK
4832 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
4833 "Trying force recovery of the IDC lock.\n");
7d613ac6
SV
4834
4835 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
4836 if (rval)
4837 return rval;
4838
4839 if ((data & idc_lck_rcvry_stage_mask) > 0) {
4840 return QLA_SUCCESS;
4841 } else {
4842 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
4843 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4844 data);
4845 if (rval)
4846 return rval;
4847
4848 msleep(200);
4849
4850 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
4851 &data);
4852 if (rval)
4853 return rval;
4854
4855 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
4856 data &= (IDC_LOCK_RECOVERY_STAGE2 |
4857 ~(idc_lck_rcvry_stage_mask));
4858 rval = qla83xx_wr_reg(base_vha,
4859 QLA83XX_IDC_LOCK_RECOVERY, data);
4860 if (rval)
4861 return rval;
4862
4863 /* Forcefully perform IDC UnLock */
4864 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
4865 &data);
4866 if (rval)
4867 return rval;
4868 /* Clear lock-id by setting 0xff */
4869 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4870 0xff);
4871 if (rval)
4872 return rval;
4873 /* Clear lock-recovery by setting 0x0 */
4874 rval = qla83xx_wr_reg(base_vha,
4875 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
4876 if (rval)
4877 return rval;
4878 } else
4879 return QLA_SUCCESS;
4880 }
4881
4882 return rval;
4883}
4884
fa492630 4885static int
7d613ac6
SV
4886qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
4887{
4888 int rval = QLA_SUCCESS;
4889 uint32_t o_drv_lockid, n_drv_lockid;
4890 unsigned long lock_recovery_timeout;
4891
4892 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
4893retry_lockid:
4894 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
4895 if (rval)
4896 goto exit;
4897
4898 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
4899 if (time_after_eq(jiffies, lock_recovery_timeout)) {
4900 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
4901 return QLA_SUCCESS;
4902 else
4903 return QLA_FUNCTION_FAILED;
4904 }
4905
4906 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
4907 if (rval)
4908 goto exit;
4909
4910 if (o_drv_lockid == n_drv_lockid) {
4911 qla83xx_wait_logic();
4912 goto retry_lockid;
4913 } else
4914 return QLA_SUCCESS;
4915
4916exit:
4917 return rval;
4918}
4919
4920void
4921qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4922{
4923 uint16_t options = (requester_id << 15) | BIT_6;
4924 uint32_t data;
6c315553 4925 uint32_t lock_owner;
7d613ac6
SV
4926 struct qla_hw_data *ha = base_vha->hw;
4927
4928 /* IDC-lock implementation using driver-lock/lock-id remote registers */
4929retry_lock:
4930 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
4931 == QLA_SUCCESS) {
4932 if (data) {
4933 /* Setting lock-id to our function-number */
4934 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4935 ha->portnum);
4936 } else {
6c315553
SK
4937 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
4938 &lock_owner);
7d613ac6 4939 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
6c315553
SK
4940 "Failed to acquire IDC lock, acquired by %d, "
4941 "retrying...\n", lock_owner);
7d613ac6
SV
4942
4943 /* Retry/Perform IDC-Lock recovery */
4944 if (qla83xx_idc_lock_recovery(base_vha)
4945 == QLA_SUCCESS) {
4946 qla83xx_wait_logic();
4947 goto retry_lock;
4948 } else
4949 ql_log(ql_log_warn, base_vha, 0xb075,
4950 "IDC Lock recovery FAILED.\n");
4951 }
4952
4953 }
4954
4955 return;
4956
4957 /* XXX: IDC-lock implementation using access-control mbx */
4958retry_lock2:
4959 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
4960 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
4961 "Failed to acquire IDC lock. retrying...\n");
4962 /* Retry/Perform IDC-Lock recovery */
4963 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
4964 qla83xx_wait_logic();
4965 goto retry_lock2;
4966 } else
4967 ql_log(ql_log_warn, base_vha, 0xb076,
4968 "IDC Lock recovery FAILED.\n");
4969 }
4970
4971 return;
4972}
4973
4974void
4975qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
4976{
5897cb2f
BVA
4977#if 0
4978 uint16_t options = (requester_id << 15) | BIT_7;
4979#endif
4980 uint16_t retry;
7d613ac6
SV
4981 uint32_t data;
4982 struct qla_hw_data *ha = base_vha->hw;
4983
4984 /* IDC-unlock implementation using driver-unlock/lock-id
4985 * remote registers
4986 */
4987 retry = 0;
4988retry_unlock:
4989 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
4990 == QLA_SUCCESS) {
4991 if (data == ha->portnum) {
4992 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
4993 /* Clearing lock-id by setting 0xff */
4994 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
4995 } else if (retry < 10) {
4996 /* SV: XXX: IDC unlock retrying needed here? */
4997
4998 /* Retry for IDC-unlock */
4999 qla83xx_wait_logic();
5000 retry++;
5001 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
ee6a8773 5002 "Failed to release IDC lock, retrying=%d\n", retry);
7d613ac6
SV
5003 goto retry_unlock;
5004 }
5005 } else if (retry < 10) {
5006 /* Retry for IDC-unlock */
5007 qla83xx_wait_logic();
5008 retry++;
5009 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
ee6a8773 5010 "Failed to read drv-lockid, retrying=%d\n", retry);
7d613ac6
SV
5011 goto retry_unlock;
5012 }
5013
5014 return;
5015
5897cb2f 5016#if 0
7d613ac6
SV
5017 /* XXX: IDC-unlock implementation using access-control mbx */
5018 retry = 0;
5019retry_unlock2:
5020 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5021 if (retry < 10) {
5022 /* Retry for IDC-unlock */
5023 qla83xx_wait_logic();
5024 retry++;
5025 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
ee6a8773 5026 "Failed to release IDC lock, retrying=%d\n", retry);
7d613ac6
SV
5027 goto retry_unlock2;
5028 }
5029 }
5030
5031 return;
5897cb2f 5032#endif
7d613ac6
SV
5033}
5034
5035int
5036__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5037{
5038 int rval = QLA_SUCCESS;
5039 struct qla_hw_data *ha = vha->hw;
5040 uint32_t drv_presence;
5041
5042 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5043 if (rval == QLA_SUCCESS) {
5044 drv_presence |= (1 << ha->portnum);
5045 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5046 drv_presence);
5047 }
5048
5049 return rval;
5050}
5051
5052int
5053qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5054{
5055 int rval = QLA_SUCCESS;
5056
5057 qla83xx_idc_lock(vha, 0);
5058 rval = __qla83xx_set_drv_presence(vha);
5059 qla83xx_idc_unlock(vha, 0);
5060
5061 return rval;
5062}
5063
5064int
5065__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5066{
5067 int rval = QLA_SUCCESS;
5068 struct qla_hw_data *ha = vha->hw;
5069 uint32_t drv_presence;
5070
5071 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5072 if (rval == QLA_SUCCESS) {
5073 drv_presence &= ~(1 << ha->portnum);
5074 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5075 drv_presence);
5076 }
5077
5078 return rval;
5079}
5080
5081int
5082qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5083{
5084 int rval = QLA_SUCCESS;
5085
5086 qla83xx_idc_lock(vha, 0);
5087 rval = __qla83xx_clear_drv_presence(vha);
5088 qla83xx_idc_unlock(vha, 0);
5089
5090 return rval;
5091}
5092
fa492630 5093static void
7d613ac6
SV
5094qla83xx_need_reset_handler(scsi_qla_host_t *vha)
5095{
5096 struct qla_hw_data *ha = vha->hw;
5097 uint32_t drv_ack, drv_presence;
5098 unsigned long ack_timeout;
5099
5100 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
5101 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
5102 while (1) {
5103 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5104 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
807fb6d8 5105 if ((drv_ack & drv_presence) == drv_presence)
7d613ac6
SV
5106 break;
5107
5108 if (time_after_eq(jiffies, ack_timeout)) {
5109 ql_log(ql_log_warn, vha, 0xb067,
5110 "RESET ACK TIMEOUT! drv_presence=0x%x "
5111 "drv_ack=0x%x\n", drv_presence, drv_ack);
5112 /*
5113 * The function(s) which did not ack in time are forced
5114 * to withdraw any further participation in the IDC
5115 * reset.
5116 */
5117 if (drv_ack != drv_presence)
5118 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5119 drv_ack);
5120 break;
5121 }
5122
5123 qla83xx_idc_unlock(vha, 0);
5124 msleep(1000);
5125 qla83xx_idc_lock(vha, 0);
5126 }
5127
5128 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
5129 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
5130}
5131
fa492630 5132static int
7d613ac6
SV
5133qla83xx_device_bootstrap(scsi_qla_host_t *vha)
5134{
5135 int rval = QLA_SUCCESS;
5136 uint32_t idc_control;
5137
5138 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
5139 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
5140
5141 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
5142 __qla83xx_get_idc_control(vha, &idc_control);
5143 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
5144 __qla83xx_set_idc_control(vha, 0);
5145
5146 qla83xx_idc_unlock(vha, 0);
5147 rval = qla83xx_restart_nic_firmware(vha);
5148 qla83xx_idc_lock(vha, 0);
5149
5150 if (rval != QLA_SUCCESS) {
5151 ql_log(ql_log_fatal, vha, 0xb06a,
5152 "Failed to restart NIC f/w.\n");
5153 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
5154 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
5155 } else {
5156 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
5157 "Success in restarting nic f/w.\n");
5158 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
5159 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
5160 }
5161
5162 return rval;
5163}
5164
5165/* Assumes idc_lock always held on entry */
5166int
5167qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
5168{
5169 struct qla_hw_data *ha = base_vha->hw;
5170 int rval = QLA_SUCCESS;
5171 unsigned long dev_init_timeout;
5172 uint32_t dev_state;
5173
5174 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
5175 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
5176
5177 while (1) {
5178
5179 if (time_after_eq(jiffies, dev_init_timeout)) {
5180 ql_log(ql_log_warn, base_vha, 0xb06e,
5181 "Initialization TIMEOUT!\n");
5182 /* Init timeout. Disable further NIC Core
5183 * communication.
5184 */
5185 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5186 QLA8XXX_DEV_FAILED);
5187 ql_log(ql_log_info, base_vha, 0xb06f,
5188 "HW State: FAILED.\n");
5189 }
5190
5191 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5192 switch (dev_state) {
5193 case QLA8XXX_DEV_READY:
5194 if (ha->flags.nic_core_reset_owner)
5195 qla83xx_idc_audit(base_vha,
5196 IDC_AUDIT_COMPLETION);
5197 ha->flags.nic_core_reset_owner = 0;
5198 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
5199 "Reset_owner reset by 0x%x.\n",
5200 ha->portnum);
5201 goto exit;
5202 case QLA8XXX_DEV_COLD:
5203 if (ha->flags.nic_core_reset_owner)
5204 rval = qla83xx_device_bootstrap(base_vha);
5205 else {
5206 /* Wait for AEN to change device-state */
5207 qla83xx_idc_unlock(base_vha, 0);
5208 msleep(1000);
5209 qla83xx_idc_lock(base_vha, 0);
5210 }
5211 break;
5212 case QLA8XXX_DEV_INITIALIZING:
5213 /* Wait for AEN to change device-state */
5214 qla83xx_idc_unlock(base_vha, 0);
5215 msleep(1000);
5216 qla83xx_idc_lock(base_vha, 0);
5217 break;
5218 case QLA8XXX_DEV_NEED_RESET:
5219 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
5220 qla83xx_need_reset_handler(base_vha);
5221 else {
5222 /* Wait for AEN to change device-state */
5223 qla83xx_idc_unlock(base_vha, 0);
5224 msleep(1000);
5225 qla83xx_idc_lock(base_vha, 0);
5226 }
5227 /* reset timeout value after need reset handler */
5228 dev_init_timeout = jiffies +
5229 (ha->fcoe_dev_init_timeout * HZ);
5230 break;
5231 case QLA8XXX_DEV_NEED_QUIESCENT:
5232 /* XXX: DEBUG for now */
5233 qla83xx_idc_unlock(base_vha, 0);
5234 msleep(1000);
5235 qla83xx_idc_lock(base_vha, 0);
5236 break;
5237 case QLA8XXX_DEV_QUIESCENT:
5238 /* XXX: DEBUG for now */
5239 if (ha->flags.quiesce_owner)
5240 goto exit;
5241
5242 qla83xx_idc_unlock(base_vha, 0);
5243 msleep(1000);
5244 qla83xx_idc_lock(base_vha, 0);
5245 dev_init_timeout = jiffies +
5246 (ha->fcoe_dev_init_timeout * HZ);
5247 break;
5248 case QLA8XXX_DEV_FAILED:
5249 if (ha->flags.nic_core_reset_owner)
5250 qla83xx_idc_audit(base_vha,
5251 IDC_AUDIT_COMPLETION);
5252 ha->flags.nic_core_reset_owner = 0;
5253 __qla83xx_clear_drv_presence(base_vha);
5254 qla83xx_idc_unlock(base_vha, 0);
5255 qla8xxx_dev_failed_handler(base_vha);
5256 rval = QLA_FUNCTION_FAILED;
5257 qla83xx_idc_lock(base_vha, 0);
5258 goto exit;
5259 case QLA8XXX_BAD_VALUE:
5260 qla83xx_idc_unlock(base_vha, 0);
5261 msleep(1000);
5262 qla83xx_idc_lock(base_vha, 0);
5263 break;
5264 default:
5265 ql_log(ql_log_warn, base_vha, 0xb071,
d939be3a 5266 "Unknown Device State: %x.\n", dev_state);
7d613ac6
SV
5267 qla83xx_idc_unlock(base_vha, 0);
5268 qla8xxx_dev_failed_handler(base_vha);
5269 rval = QLA_FUNCTION_FAILED;
5270 qla83xx_idc_lock(base_vha, 0);
5271 goto exit;
5272 }
5273 }
5274
5275exit:
5276 return rval;
5277}
5278
f3ddac19
CD
5279void
5280qla2x00_disable_board_on_pci_error(struct work_struct *work)
5281{
5282 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
5283 board_disable);
5284 struct pci_dev *pdev = ha->pdev;
5285 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5286
726b8548
QT
5287 /*
5288 * if UNLOAD flag is already set, then continue unload,
783e0dc4
SC
5289 * where it was set first.
5290 */
5291 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5292 return;
5293
f3ddac19
CD
5294 ql_log(ql_log_warn, base_vha, 0x015b,
5295 "Disabling adapter.\n");
5296
726b8548
QT
5297 qla2x00_wait_for_sess_deletion(base_vha);
5298
f3ddac19
CD
5299 set_bit(UNLOADING, &base_vha->dpc_flags);
5300
5301 qla2x00_delete_all_vps(ha, base_vha);
5302
5303 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5304
5305 qla2x00_dfs_remove(base_vha);
5306
5307 qla84xx_put_chip(base_vha);
5308
5309 if (base_vha->timer_active)
5310 qla2x00_stop_timer(base_vha);
5311
5312 base_vha->flags.online = 0;
5313
5314 qla2x00_destroy_deferred_work(ha);
5315
5316 /*
5317 * Do not try to stop beacon blink as it will issue a mailbox
5318 * command.
5319 */
5320 qla2x00_free_sysfs_attr(base_vha, false);
5321
5322 fc_remove_host(base_vha->host);
5323
5324 scsi_remove_host(base_vha->host);
5325
5326 base_vha->flags.init_done = 0;
5327 qla25xx_delete_queues(base_vha);
f3ddac19 5328 qla2x00_free_fcports(base_vha);
093df737 5329 qla2x00_free_irqs(base_vha);
f3ddac19
CD
5330 qla2x00_mem_free(ha);
5331 qla82xx_md_free(base_vha);
5332 qla2x00_free_queues(ha);
5333
f3ddac19
CD
5334 qla2x00_unmap_iobases(ha);
5335
5336 pci_release_selected_regions(ha->pdev, ha->bars);
f3ddac19
CD
5337 pci_disable_pcie_error_reporting(pdev);
5338 pci_disable_device(pdev);
f3ddac19 5339
beb9e315
JL
5340 /*
5341 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
5342 */
f3ddac19
CD
5343}
5344
1da177e4
LT
5345/**************************************************************************
5346* qla2x00_do_dpc
5347* This kernel thread is a task that is schedule by the interrupt handler
5348* to perform the background processing for interrupts.
5349*
5350* Notes:
5351* This task always run in the context of a kernel thread. It
5352* is kick-off by the driver's detect code and starts up
5353* up one per adapter. It immediately goes to sleep and waits for
5354* some fibre event. When either the interrupt handler or
5355* the timer routine detects a event it will one of the task
5356* bits then wake us up.
5357**************************************************************************/
5358static int
5359qla2x00_do_dpc(void *data)
5360{
e315cd28
AC
5361 scsi_qla_host_t *base_vha;
5362 struct qla_hw_data *ha;
d7459527
MH
5363 uint32_t online;
5364 struct qla_qpair *qpair;
1da177e4 5365
e315cd28
AC
5366 ha = (struct qla_hw_data *)data;
5367 base_vha = pci_get_drvdata(ha->pdev);
1da177e4 5368
8698a745 5369 set_user_nice(current, MIN_NICE);
1da177e4 5370
563585ec 5371 set_current_state(TASK_INTERRUPTIBLE);
39a11240 5372 while (!kthread_should_stop()) {
7c3df132
SK
5373 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
5374 "DPC handler sleeping.\n");
1da177e4 5375
39a11240 5376 schedule();
1da177e4 5377
c142caf0
AV
5378 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
5379 goto end_loop;
1da177e4 5380
85880801 5381 if (ha->flags.eeh_busy) {
7c3df132
SK
5382 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
5383 "eeh_busy=%d.\n", ha->flags.eeh_busy);
c142caf0 5384 goto end_loop;
85880801
AV
5385 }
5386
1da177e4
LT
5387 ha->dpc_active = 1;
5388
5f28d2d7
SK
5389 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
5390 "DPC handler waking up, dpc_flags=0x%lx.\n",
5391 base_vha->dpc_flags);
1da177e4 5392
a29b3dd7
JC
5393 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5394 break;
5395
e315cd28 5396 qla2x00_do_work(base_vha);
0971de7f 5397
7ec0effd
AD
5398 if (IS_P3P_TYPE(ha)) {
5399 if (IS_QLA8044(ha)) {
5400 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5401 &base_vha->dpc_flags)) {
5402 qla8044_idc_lock(ha);
5403 qla8044_wr_direct(base_vha,
5404 QLA8044_CRB_DEV_STATE_INDEX,
5405 QLA8XXX_DEV_FAILED);
5406 qla8044_idc_unlock(ha);
5407 ql_log(ql_log_info, base_vha, 0x4004,
5408 "HW State: FAILED.\n");
5409 qla8044_device_state_handler(base_vha);
5410 continue;
5411 }
5412
5413 } else {
5414 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5415 &base_vha->dpc_flags)) {
5416 qla82xx_idc_lock(ha);
5417 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5418 QLA8XXX_DEV_FAILED);
5419 qla82xx_idc_unlock(ha);
5420 ql_log(ql_log_info, base_vha, 0x0151,
5421 "HW State: FAILED.\n");
5422 qla82xx_device_state_handler(base_vha);
5423 continue;
5424 }
a9083016
GM
5425 }
5426
5427 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
5428 &base_vha->dpc_flags)) {
5429
7c3df132
SK
5430 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
5431 "FCoE context reset scheduled.\n");
a9083016
GM
5432 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
5433 &base_vha->dpc_flags))) {
5434 if (qla82xx_fcoe_ctx_reset(base_vha)) {
5435 /* FCoE-ctx reset failed.
5436 * Escalate to chip-reset
5437 */
5438 set_bit(ISP_ABORT_NEEDED,
5439 &base_vha->dpc_flags);
5440 }
5441 clear_bit(ABORT_ISP_ACTIVE,
5442 &base_vha->dpc_flags);
5443 }
5444
7c3df132
SK
5445 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
5446 "FCoE context reset end.\n");
a9083016 5447 }
8ae6d9c7
GM
5448 } else if (IS_QLAFX00(ha)) {
5449 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5450 &base_vha->dpc_flags)) {
5451 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
5452 "Firmware Reset Recovery\n");
5453 if (qlafx00_reset_initialize(base_vha)) {
5454 /* Failed. Abort isp later. */
5455 if (!test_bit(UNLOADING,
f92f82d6 5456 &base_vha->dpc_flags)) {
8ae6d9c7
GM
5457 set_bit(ISP_UNRECOVERABLE,
5458 &base_vha->dpc_flags);
5459 ql_dbg(ql_dbg_dpc, base_vha,
5460 0x4021,
5461 "Reset Recovery Failed\n");
f92f82d6 5462 }
8ae6d9c7
GM
5463 }
5464 }
5465
5466 if (test_and_clear_bit(FX00_TARGET_SCAN,
5467 &base_vha->dpc_flags)) {
5468 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
5469 "ISPFx00 Target Scan scheduled\n");
5470 if (qlafx00_rescan_isp(base_vha)) {
5471 if (!test_bit(UNLOADING,
5472 &base_vha->dpc_flags))
5473 set_bit(ISP_UNRECOVERABLE,
5474 &base_vha->dpc_flags);
5475 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
5476 "ISPFx00 Target Scan Failed\n");
5477 }
5478 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
5479 "ISPFx00 Target Scan End\n");
5480 }
e8f5e95d
AB
5481 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
5482 &base_vha->dpc_flags)) {
5483 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
5484 "ISPFx00 Host Info resend scheduled\n");
5485 qlafx00_fx_disc(base_vha,
5486 &base_vha->hw->mr.fcport,
5487 FXDISC_REG_HOST_INFO);
5488 }
a9083016
GM
5489 }
5490
e315cd28
AC
5491 if (test_and_clear_bit(ISP_ABORT_NEEDED,
5492 &base_vha->dpc_flags)) {
1da177e4 5493
7c3df132
SK
5494 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
5495 "ISP abort scheduled.\n");
1da177e4 5496 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
e315cd28 5497 &base_vha->dpc_flags))) {
1da177e4 5498
a9083016 5499 if (ha->isp_ops->abort_isp(base_vha)) {
1da177e4
LT
5500 /* failed. retry later */
5501 set_bit(ISP_ABORT_NEEDED,
e315cd28 5502 &base_vha->dpc_flags);
99363ef8 5503 }
e315cd28
AC
5504 clear_bit(ABORT_ISP_ACTIVE,
5505 &base_vha->dpc_flags);
99363ef8
SJ
5506 }
5507
7c3df132
SK
5508 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
5509 "ISP abort end.\n");
1da177e4
LT
5510 }
5511
a394aac8
DJ
5512 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
5513 &base_vha->dpc_flags)) {
e315cd28 5514 qla2x00_update_fcports(base_vha);
c9c5ced9 5515 }
d97994dc 5516
8ae6d9c7
GM
5517 if (IS_QLAFX00(ha))
5518 goto loop_resync_check;
5519
579d12b5 5520 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
7c3df132
SK
5521 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
5522 "Quiescence mode scheduled.\n");
7ec0effd
AD
5523 if (IS_P3P_TYPE(ha)) {
5524 if (IS_QLA82XX(ha))
5525 qla82xx_device_state_handler(base_vha);
5526 if (IS_QLA8044(ha))
5527 qla8044_device_state_handler(base_vha);
8fcd6b8b
CD
5528 clear_bit(ISP_QUIESCE_NEEDED,
5529 &base_vha->dpc_flags);
5530 if (!ha->flags.quiesce_owner) {
5531 qla2x00_perform_loop_resync(base_vha);
7ec0effd
AD
5532 if (IS_QLA82XX(ha)) {
5533 qla82xx_idc_lock(ha);
5534 qla82xx_clear_qsnt_ready(
5535 base_vha);
5536 qla82xx_idc_unlock(ha);
5537 } else if (IS_QLA8044(ha)) {
5538 qla8044_idc_lock(ha);
5539 qla8044_clear_qsnt_ready(
5540 base_vha);
5541 qla8044_idc_unlock(ha);
5542 }
8fcd6b8b
CD
5543 }
5544 } else {
5545 clear_bit(ISP_QUIESCE_NEEDED,
5546 &base_vha->dpc_flags);
5547 qla2x00_quiesce_io(base_vha);
579d12b5 5548 }
7c3df132
SK
5549 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
5550 "Quiescence mode end.\n");
579d12b5
SK
5551 }
5552
e315cd28 5553 if (test_and_clear_bit(RESET_MARKER_NEEDED,
8ae6d9c7 5554 &base_vha->dpc_flags) &&
e315cd28 5555 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
1da177e4 5556
7c3df132
SK
5557 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
5558 "Reset marker scheduled.\n");
e315cd28
AC
5559 qla2x00_rst_aen(base_vha);
5560 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
7c3df132
SK
5561 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
5562 "Reset marker end.\n");
1da177e4
LT
5563 }
5564
5565 /* Retry each device up to login retry count */
e315cd28
AC
5566 if ((test_and_clear_bit(RELOGIN_NEEDED,
5567 &base_vha->dpc_flags)) &&
5568 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
5569 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
1da177e4 5570
7c3df132
SK
5571 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
5572 "Relogin scheduled.\n");
e315cd28 5573 qla2x00_relogin(base_vha);
7c3df132
SK
5574 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
5575 "Relogin end.\n");
1da177e4 5576 }
8ae6d9c7 5577loop_resync_check:
e315cd28 5578 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
8ae6d9c7 5579 &base_vha->dpc_flags)) {
1da177e4 5580
7c3df132
SK
5581 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
5582 "Loop resync scheduled.\n");
1da177e4
LT
5583
5584 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
e315cd28 5585 &base_vha->dpc_flags))) {
1da177e4 5586
52c82823 5587 qla2x00_loop_resync(base_vha);
1da177e4 5588
e315cd28
AC
5589 clear_bit(LOOP_RESYNC_ACTIVE,
5590 &base_vha->dpc_flags);
1da177e4
LT
5591 }
5592
7c3df132
SK
5593 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
5594 "Loop resync end.\n");
1da177e4
LT
5595 }
5596
8ae6d9c7
GM
5597 if (IS_QLAFX00(ha))
5598 goto intr_on_check;
5599
e315cd28
AC
5600 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
5601 atomic_read(&base_vha->loop_state) == LOOP_READY) {
5602 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
5603 qla2xxx_flash_npiv_conf(base_vha);
272976ca
AV
5604 }
5605
8ae6d9c7 5606intr_on_check:
1da177e4 5607 if (!ha->interrupts_on)
fd34f556 5608 ha->isp_ops->enable_intrs(ha);
1da177e4 5609
e315cd28 5610 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
90b604f2
HM
5611 &base_vha->dpc_flags)) {
5612 if (ha->beacon_blink_led == 1)
5613 ha->isp_ops->beacon_blink(base_vha);
5614 }
f6df144c 5615
d7459527
MH
5616 /* qpair online check */
5617 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
5618 &base_vha->dpc_flags)) {
5619 if (ha->flags.eeh_busy ||
5620 ha->flags.pci_channel_io_perm_failure)
5621 online = 0;
5622 else
5623 online = 1;
5624
5625 mutex_lock(&ha->mq_lock);
5626 list_for_each_entry(qpair, &base_vha->qp_list,
5627 qp_list_elem)
5628 qpair->online = online;
5629 mutex_unlock(&ha->mq_lock);
5630 }
5631
8ae6d9c7
GM
5632 if (!IS_QLAFX00(ha))
5633 qla2x00_do_dpc_all_vps(base_vha);
2c3dfe3f 5634
1da177e4 5635 ha->dpc_active = 0;
c142caf0 5636end_loop:
563585ec 5637 set_current_state(TASK_INTERRUPTIBLE);
1da177e4 5638 } /* End of while(1) */
563585ec 5639 __set_current_state(TASK_RUNNING);
1da177e4 5640
7c3df132
SK
5641 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
5642 "DPC handler exiting.\n");
1da177e4
LT
5643
5644 /*
5645 * Make sure that nobody tries to wake us up again.
5646 */
1da177e4
LT
5647 ha->dpc_active = 0;
5648
ac280b67
AV
5649 /* Cleanup any residual CTX SRBs. */
5650 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5651
39a11240
CH
5652 return 0;
5653}
5654
5655void
e315cd28 5656qla2xxx_wake_dpc(struct scsi_qla_host *vha)
39a11240 5657{
e315cd28 5658 struct qla_hw_data *ha = vha->hw;
c795c1e4
AV
5659 struct task_struct *t = ha->dpc_thread;
5660
e315cd28 5661 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
c795c1e4 5662 wake_up_process(t);
1da177e4
LT
5663}
5664
1da177e4
LT
5665/*
5666* qla2x00_rst_aen
5667* Processes asynchronous reset.
5668*
5669* Input:
5670* ha = adapter block pointer.
5671*/
5672static void
e315cd28 5673qla2x00_rst_aen(scsi_qla_host_t *vha)
1da177e4 5674{
e315cd28
AC
5675 if (vha->flags.online && !vha->flags.reset_active &&
5676 !atomic_read(&vha->loop_down_timer) &&
5677 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
1da177e4 5678 do {
e315cd28 5679 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
1da177e4
LT
5680
5681 /*
5682 * Issue marker command only when we are going to start
5683 * the I/O.
5684 */
e315cd28
AC
5685 vha->marker_needed = 1;
5686 } while (!atomic_read(&vha->loop_down_timer) &&
5687 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
1da177e4
LT
5688 }
5689}
5690
1da177e4
LT
5691/**************************************************************************
5692* qla2x00_timer
5693*
5694* Description:
5695* One second timer
5696*
5697* Context: Interrupt
5698***************************************************************************/
2c3dfe3f 5699void
e315cd28 5700qla2x00_timer(scsi_qla_host_t *vha)
1da177e4 5701{
1da177e4 5702 unsigned long cpu_flags = 0;
1da177e4
LT
5703 int start_dpc = 0;
5704 int index;
5705 srb_t *sp;
85880801 5706 uint16_t w;
e315cd28 5707 struct qla_hw_data *ha = vha->hw;
73208dfd 5708 struct req_que *req;
85880801 5709
a5b36321 5710 if (ha->flags.eeh_busy) {
7c3df132
SK
5711 ql_dbg(ql_dbg_timer, vha, 0x6000,
5712 "EEH = %d, restarting timer.\n",
5713 ha->flags.eeh_busy);
a5b36321
LC
5714 qla2x00_restart_timer(vha, WATCH_INTERVAL);
5715 return;
5716 }
5717
f3ddac19
CD
5718 /*
5719 * Hardware read to raise pending EEH errors during mailbox waits. If
5720 * the read returns -1 then disable the board.
5721 */
5722 if (!pci_channel_offline(ha->pdev)) {
85880801 5723 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
c821e0d5 5724 qla2x00_check_reg16_for_disconnect(vha, w);
f3ddac19 5725 }
1da177e4 5726
cefcaba6 5727 /* Make sure qla82xx_watchdog is run only for physical port */
7ec0effd 5728 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
579d12b5
SK
5729 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
5730 start_dpc++;
7ec0effd
AD
5731 if (IS_QLA82XX(ha))
5732 qla82xx_watchdog(vha);
5733 else if (IS_QLA8044(ha))
5734 qla8044_watchdog(vha);
579d12b5
SK
5735 }
5736
8ae6d9c7
GM
5737 if (!vha->vp_idx && IS_QLAFX00(ha))
5738 qlafx00_timer_routine(vha);
5739
1da177e4 5740 /* Loop down handler. */
e315cd28 5741 if (atomic_read(&vha->loop_down_timer) > 0 &&
8f7daead
GM
5742 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
5743 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
e315cd28 5744 && vha->flags.online) {
1da177e4 5745
e315cd28
AC
5746 if (atomic_read(&vha->loop_down_timer) ==
5747 vha->loop_down_abort_time) {
1da177e4 5748
7c3df132
SK
5749 ql_log(ql_log_info, vha, 0x6008,
5750 "Loop down - aborting the queues before time expires.\n");
1da177e4 5751
e315cd28
AC
5752 if (!IS_QLA2100(ha) && vha->link_down_timeout)
5753 atomic_set(&vha->loop_state, LOOP_DEAD);
1da177e4 5754
f08b7251
AV
5755 /*
5756 * Schedule an ISP abort to return any FCP2-device
5757 * commands.
5758 */
2c3dfe3f 5759 /* NPIV - scan physical port only */
e315cd28 5760 if (!vha->vp_idx) {
2c3dfe3f
SJ
5761 spin_lock_irqsave(&ha->hardware_lock,
5762 cpu_flags);
73208dfd 5763 req = ha->req_q_map[0];
2c3dfe3f 5764 for (index = 1;
8d93f550 5765 index < req->num_outstanding_cmds;
2c3dfe3f
SJ
5766 index++) {
5767 fc_port_t *sfcp;
5768
e315cd28 5769 sp = req->outstanding_cmds[index];
2c3dfe3f
SJ
5770 if (!sp)
5771 continue;
9ba56b95 5772 if (sp->type != SRB_SCSI_CMD)
cf53b069 5773 continue;
2c3dfe3f 5774 sfcp = sp->fcport;
f08b7251 5775 if (!(sfcp->flags & FCF_FCP2_DEVICE))
2c3dfe3f 5776 continue;
bdf79621 5777
8f7daead
GM
5778 if (IS_QLA82XX(ha))
5779 set_bit(FCOE_CTX_RESET_NEEDED,
5780 &vha->dpc_flags);
5781 else
5782 set_bit(ISP_ABORT_NEEDED,
e315cd28 5783 &vha->dpc_flags);
2c3dfe3f
SJ
5784 break;
5785 }
5786 spin_unlock_irqrestore(&ha->hardware_lock,
e315cd28 5787 cpu_flags);
1da177e4 5788 }
1da177e4
LT
5789 start_dpc++;
5790 }
5791
5792 /* if the loop has been down for 4 minutes, reinit adapter */
e315cd28 5793 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
0d6e61bc 5794 if (!(vha->device_flags & DFLG_NO_CABLE)) {
7c3df132 5795 ql_log(ql_log_warn, vha, 0x6009,
1da177e4
LT
5796 "Loop down - aborting ISP.\n");
5797
8f7daead
GM
5798 if (IS_QLA82XX(ha))
5799 set_bit(FCOE_CTX_RESET_NEEDED,
5800 &vha->dpc_flags);
5801 else
5802 set_bit(ISP_ABORT_NEEDED,
5803 &vha->dpc_flags);
1da177e4
LT
5804 }
5805 }
7c3df132
SK
5806 ql_dbg(ql_dbg_timer, vha, 0x600a,
5807 "Loop down - seconds remaining %d.\n",
5808 atomic_read(&vha->loop_down_timer));
1da177e4 5809 }
cefcaba6
SK
5810 /* Check if beacon LED needs to be blinked for physical host only */
5811 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
999916dc 5812 /* There is no beacon_blink function for ISP82xx */
7ec0effd 5813 if (!IS_P3P_TYPE(ha)) {
999916dc
SK
5814 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
5815 start_dpc++;
5816 }
f6df144c
AV
5817 }
5818
550bf57d 5819 /* Process any deferred work. */
e315cd28 5820 if (!list_empty(&vha->work_list))
550bf57d
AV
5821 start_dpc++;
5822
1da177e4 5823 /* Schedule the DPC routine if needed */
e315cd28
AC
5824 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
5825 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
5826 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
1da177e4 5827 start_dpc ||
e315cd28
AC
5828 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
5829 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
a9083016
GM
5830 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
5831 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
e315cd28 5832 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
50280c01 5833 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
7c3df132
SK
5834 ql_dbg(ql_dbg_timer, vha, 0x600b,
5835 "isp_abort_needed=%d loop_resync_needed=%d "
5836 "fcport_update_needed=%d start_dpc=%d "
5837 "reset_marker_needed=%d",
5838 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
5839 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
5840 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
5841 start_dpc,
5842 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
5843 ql_dbg(ql_dbg_timer, vha, 0x600c,
5844 "beacon_blink_needed=%d isp_unrecoverable=%d "
5845 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
50280c01 5846 "relogin_needed=%d.\n",
7c3df132
SK
5847 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
5848 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
5849 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
5850 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
50280c01 5851 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
e315cd28 5852 qla2xxx_wake_dpc(vha);
7c3df132 5853 }
1da177e4 5854
e315cd28 5855 qla2x00_restart_timer(vha, WATCH_INTERVAL);
1da177e4
LT
5856}
5857
5433383e
AV
5858/* Firmware interface routines. */
5859
f73cb695 5860#define FW_BLOBS 11
5433383e
AV
5861#define FW_ISP21XX 0
5862#define FW_ISP22XX 1
5863#define FW_ISP2300 2
5864#define FW_ISP2322 3
48c02fde 5865#define FW_ISP24XX 4
c3a2f0df 5866#define FW_ISP25XX 5
3a03eb79 5867#define FW_ISP81XX 6
a9083016 5868#define FW_ISP82XX 7
6246b8a1
GM
5869#define FW_ISP2031 8
5870#define FW_ISP8031 9
2c5bbbb2 5871#define FW_ISP27XX 10
5433383e 5872
bb8ee499
AV
5873#define FW_FILE_ISP21XX "ql2100_fw.bin"
5874#define FW_FILE_ISP22XX "ql2200_fw.bin"
5875#define FW_FILE_ISP2300 "ql2300_fw.bin"
5876#define FW_FILE_ISP2322 "ql2322_fw.bin"
5877#define FW_FILE_ISP24XX "ql2400_fw.bin"
c3a2f0df 5878#define FW_FILE_ISP25XX "ql2500_fw.bin"
3a03eb79 5879#define FW_FILE_ISP81XX "ql8100_fw.bin"
a9083016 5880#define FW_FILE_ISP82XX "ql8200_fw.bin"
6246b8a1
GM
5881#define FW_FILE_ISP2031 "ql2600_fw.bin"
5882#define FW_FILE_ISP8031 "ql8300_fw.bin"
2c5bbbb2 5883#define FW_FILE_ISP27XX "ql2700_fw.bin"
f73cb695 5884
bb8ee499 5885
e1e82b6f 5886static DEFINE_MUTEX(qla_fw_lock);
5433383e
AV
5887
5888static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
bb8ee499
AV
5889 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
5890 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
5891 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
5892 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
5893 { .name = FW_FILE_ISP24XX, },
c3a2f0df 5894 { .name = FW_FILE_ISP25XX, },
3a03eb79 5895 { .name = FW_FILE_ISP81XX, },
a9083016 5896 { .name = FW_FILE_ISP82XX, },
6246b8a1
GM
5897 { .name = FW_FILE_ISP2031, },
5898 { .name = FW_FILE_ISP8031, },
2c5bbbb2 5899 { .name = FW_FILE_ISP27XX, },
5433383e
AV
5900};
5901
5902struct fw_blob *
e315cd28 5903qla2x00_request_firmware(scsi_qla_host_t *vha)
5433383e 5904{
e315cd28 5905 struct qla_hw_data *ha = vha->hw;
5433383e
AV
5906 struct fw_blob *blob;
5907
5433383e
AV
5908 if (IS_QLA2100(ha)) {
5909 blob = &qla_fw_blobs[FW_ISP21XX];
5910 } else if (IS_QLA2200(ha)) {
5911 blob = &qla_fw_blobs[FW_ISP22XX];
48c02fde 5912 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
5433383e 5913 blob = &qla_fw_blobs[FW_ISP2300];
48c02fde 5914 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
5433383e 5915 blob = &qla_fw_blobs[FW_ISP2322];
4d4df193 5916 } else if (IS_QLA24XX_TYPE(ha)) {
5433383e 5917 blob = &qla_fw_blobs[FW_ISP24XX];
c3a2f0df
AV
5918 } else if (IS_QLA25XX(ha)) {
5919 blob = &qla_fw_blobs[FW_ISP25XX];
3a03eb79
AV
5920 } else if (IS_QLA81XX(ha)) {
5921 blob = &qla_fw_blobs[FW_ISP81XX];
a9083016
GM
5922 } else if (IS_QLA82XX(ha)) {
5923 blob = &qla_fw_blobs[FW_ISP82XX];
6246b8a1
GM
5924 } else if (IS_QLA2031(ha)) {
5925 blob = &qla_fw_blobs[FW_ISP2031];
5926 } else if (IS_QLA8031(ha)) {
5927 blob = &qla_fw_blobs[FW_ISP8031];
2c5bbbb2
JC
5928 } else if (IS_QLA27XX(ha)) {
5929 blob = &qla_fw_blobs[FW_ISP27XX];
8a655229
DC
5930 } else {
5931 return NULL;
5433383e
AV
5932 }
5933
e1e82b6f 5934 mutex_lock(&qla_fw_lock);
5433383e
AV
5935 if (blob->fw)
5936 goto out;
5937
5938 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
7c3df132
SK
5939 ql_log(ql_log_warn, vha, 0x0063,
5940 "Failed to load firmware image (%s).\n", blob->name);
5433383e
AV
5941 blob->fw = NULL;
5942 blob = NULL;
5943 goto out;
5944 }
5945
5946out:
e1e82b6f 5947 mutex_unlock(&qla_fw_lock);
5433383e
AV
5948 return blob;
5949}
5950
5951static void
5952qla2x00_release_firmware(void)
5953{
5954 int idx;
5955
e1e82b6f 5956 mutex_lock(&qla_fw_lock);
5433383e 5957 for (idx = 0; idx < FW_BLOBS; idx++)
cf92549f 5958 release_firmware(qla_fw_blobs[idx].fw);
e1e82b6f 5959 mutex_unlock(&qla_fw_lock);
5433383e
AV
5960}
5961
14e660e6
SJ
5962static pci_ers_result_t
5963qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
5964{
85880801
AV
5965 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
5966 struct qla_hw_data *ha = vha->hw;
5967
7c3df132
SK
5968 ql_dbg(ql_dbg_aer, vha, 0x9000,
5969 "PCI error detected, state %x.\n", state);
b9b12f73 5970
14e660e6
SJ
5971 switch (state) {
5972 case pci_channel_io_normal:
85880801 5973 ha->flags.eeh_busy = 0;
d7459527
MH
5974 if (ql2xmqsupport) {
5975 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
5976 qla2xxx_wake_dpc(vha);
5977 }
14e660e6
SJ
5978 return PCI_ERS_RESULT_CAN_RECOVER;
5979 case pci_channel_io_frozen:
85880801 5980 ha->flags.eeh_busy = 1;
a5b36321
LC
5981 /* For ISP82XX complete any pending mailbox cmd */
5982 if (IS_QLA82XX(ha)) {
7190575f 5983 ha->flags.isp82xx_fw_hung = 1;
c8f6544e
CD
5984 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
5985 qla82xx_clear_pending_mbx(vha);
a5b36321 5986 }
90a86fc0 5987 qla2x00_free_irqs(vha);
14e660e6 5988 pci_disable_device(pdev);
bddd2d65
LC
5989 /* Return back all IOs */
5990 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
d7459527
MH
5991 if (ql2xmqsupport) {
5992 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
5993 qla2xxx_wake_dpc(vha);
5994 }
14e660e6
SJ
5995 return PCI_ERS_RESULT_NEED_RESET;
5996 case pci_channel_io_perm_failure:
85880801
AV
5997 ha->flags.pci_channel_io_perm_failure = 1;
5998 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
d7459527
MH
5999 if (ql2xmqsupport) {
6000 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6001 qla2xxx_wake_dpc(vha);
6002 }
14e660e6
SJ
6003 return PCI_ERS_RESULT_DISCONNECT;
6004 }
6005 return PCI_ERS_RESULT_NEED_RESET;
6006}
6007
6008static pci_ers_result_t
6009qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
6010{
6011 int risc_paused = 0;
6012 uint32_t stat;
6013 unsigned long flags;
e315cd28
AC
6014 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6015 struct qla_hw_data *ha = base_vha->hw;
14e660e6
SJ
6016 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6017 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
6018
bcc5b6d3
SK
6019 if (IS_QLA82XX(ha))
6020 return PCI_ERS_RESULT_RECOVERED;
6021
14e660e6
SJ
6022 spin_lock_irqsave(&ha->hardware_lock, flags);
6023 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
6024 stat = RD_REG_DWORD(&reg->hccr);
6025 if (stat & HCCR_RISC_PAUSE)
6026 risc_paused = 1;
6027 } else if (IS_QLA23XX(ha)) {
6028 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
6029 if (stat & HSR_RISC_PAUSED)
6030 risc_paused = 1;
6031 } else if (IS_FWI2_CAPABLE(ha)) {
6032 stat = RD_REG_DWORD(&reg24->host_status);
6033 if (stat & HSRX_RISC_PAUSED)
6034 risc_paused = 1;
6035 }
6036 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6037
6038 if (risc_paused) {
7c3df132
SK
6039 ql_log(ql_log_info, base_vha, 0x9003,
6040 "RISC paused -- mmio_enabled, Dumping firmware.\n");
e315cd28 6041 ha->isp_ops->fw_dump(base_vha, 0);
14e660e6
SJ
6042
6043 return PCI_ERS_RESULT_NEED_RESET;
6044 } else
6045 return PCI_ERS_RESULT_RECOVERED;
6046}
6047
fa492630
SK
6048static uint32_t
6049qla82xx_error_recovery(scsi_qla_host_t *base_vha)
a5b36321
LC
6050{
6051 uint32_t rval = QLA_FUNCTION_FAILED;
6052 uint32_t drv_active = 0;
6053 struct qla_hw_data *ha = base_vha->hw;
6054 int fn;
6055 struct pci_dev *other_pdev = NULL;
6056
7c3df132
SK
6057 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
6058 "Entered %s.\n", __func__);
a5b36321
LC
6059
6060 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6061
6062 if (base_vha->flags.online) {
6063 /* Abort all outstanding commands,
6064 * so as to be requeued later */
6065 qla2x00_abort_isp_cleanup(base_vha);
6066 }
6067
6068
6069 fn = PCI_FUNC(ha->pdev->devfn);
6070 while (fn > 0) {
6071 fn--;
7c3df132
SK
6072 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
6073 "Finding pci device at function = 0x%x.\n", fn);
a5b36321
LC
6074 other_pdev =
6075 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
6076 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
6077 fn));
6078
6079 if (!other_pdev)
6080 continue;
6081 if (atomic_read(&other_pdev->enable_cnt)) {
7c3df132
SK
6082 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
6083 "Found PCI func available and enable at 0x%x.\n",
6084 fn);
a5b36321
LC
6085 pci_dev_put(other_pdev);
6086 break;
6087 }
6088 pci_dev_put(other_pdev);
6089 }
6090
6091 if (!fn) {
6092 /* Reset owner */
7c3df132
SK
6093 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
6094 "This devfn is reset owner = 0x%x.\n",
6095 ha->pdev->devfn);
a5b36321
LC
6096 qla82xx_idc_lock(ha);
6097
6098 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
7d613ac6 6099 QLA8XXX_DEV_INITIALIZING);
a5b36321
LC
6100
6101 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
6102 QLA82XX_IDC_VERSION);
6103
6104 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
7c3df132
SK
6105 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
6106 "drv_active = 0x%x.\n", drv_active);
a5b36321
LC
6107
6108 qla82xx_idc_unlock(ha);
6109 /* Reset if device is not already reset
6110 * drv_active would be 0 if a reset has already been done
6111 */
6112 if (drv_active)
6113 rval = qla82xx_start_firmware(base_vha);
6114 else
6115 rval = QLA_SUCCESS;
6116 qla82xx_idc_lock(ha);
6117
6118 if (rval != QLA_SUCCESS) {
7c3df132
SK
6119 ql_log(ql_log_info, base_vha, 0x900b,
6120 "HW State: FAILED.\n");
a5b36321
LC
6121 qla82xx_clear_drv_active(ha);
6122 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
7d613ac6 6123 QLA8XXX_DEV_FAILED);
a5b36321 6124 } else {
7c3df132
SK
6125 ql_log(ql_log_info, base_vha, 0x900c,
6126 "HW State: READY.\n");
a5b36321 6127 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
7d613ac6 6128 QLA8XXX_DEV_READY);
a5b36321 6129 qla82xx_idc_unlock(ha);
7190575f 6130 ha->flags.isp82xx_fw_hung = 0;
a5b36321
LC
6131 rval = qla82xx_restart_isp(base_vha);
6132 qla82xx_idc_lock(ha);
6133 /* Clear driver state register */
6134 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
6135 qla82xx_set_drv_active(base_vha);
6136 }
6137 qla82xx_idc_unlock(ha);
6138 } else {
7c3df132
SK
6139 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
6140 "This devfn is not reset owner = 0x%x.\n",
6141 ha->pdev->devfn);
a5b36321 6142 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
7d613ac6 6143 QLA8XXX_DEV_READY)) {
7190575f 6144 ha->flags.isp82xx_fw_hung = 0;
a5b36321
LC
6145 rval = qla82xx_restart_isp(base_vha);
6146 qla82xx_idc_lock(ha);
6147 qla82xx_set_drv_active(base_vha);
6148 qla82xx_idc_unlock(ha);
6149 }
6150 }
6151 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6152
6153 return rval;
6154}
6155
14e660e6
SJ
6156static pci_ers_result_t
6157qla2xxx_pci_slot_reset(struct pci_dev *pdev)
6158{
6159 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
e315cd28
AC
6160 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6161 struct qla_hw_data *ha = base_vha->hw;
90a86fc0
JC
6162 struct rsp_que *rsp;
6163 int rc, retries = 10;
09483916 6164
7c3df132
SK
6165 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
6166 "Slot Reset.\n");
85880801 6167
90a86fc0
JC
6168 /* Workaround: qla2xxx driver which access hardware earlier
6169 * needs error state to be pci_channel_io_online.
6170 * Otherwise mailbox command timesout.
6171 */
6172 pdev->error_state = pci_channel_io_normal;
6173
6174 pci_restore_state(pdev);
6175
8c1496bd
RL
6176 /* pci_restore_state() clears the saved_state flag of the device
6177 * save restored state which resets saved_state flag
6178 */
6179 pci_save_state(pdev);
6180
09483916
BH
6181 if (ha->mem_only)
6182 rc = pci_enable_device_mem(pdev);
6183 else
6184 rc = pci_enable_device(pdev);
14e660e6 6185
09483916 6186 if (rc) {
7c3df132 6187 ql_log(ql_log_warn, base_vha, 0x9005,
14e660e6 6188 "Can't re-enable PCI device after reset.\n");
a5b36321 6189 goto exit_slot_reset;
14e660e6 6190 }
14e660e6 6191
90a86fc0
JC
6192 rsp = ha->rsp_q_map[0];
6193 if (qla2x00_request_irqs(ha, rsp))
a5b36321 6194 goto exit_slot_reset;
90a86fc0 6195
e315cd28 6196 if (ha->isp_ops->pci_config(base_vha))
a5b36321
LC
6197 goto exit_slot_reset;
6198
6199 if (IS_QLA82XX(ha)) {
6200 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
6201 ret = PCI_ERS_RESULT_RECOVERED;
6202 goto exit_slot_reset;
6203 } else
6204 goto exit_slot_reset;
6205 }
14e660e6 6206
90a86fc0
JC
6207 while (ha->flags.mbox_busy && retries--)
6208 msleep(1000);
85880801 6209
e315cd28 6210 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
a9083016 6211 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
14e660e6 6212 ret = PCI_ERS_RESULT_RECOVERED;
e315cd28 6213 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
14e660e6 6214
90a86fc0 6215
a5b36321 6216exit_slot_reset:
7c3df132
SK
6217 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
6218 "slot_reset return %x.\n", ret);
85880801 6219
14e660e6
SJ
6220 return ret;
6221}
6222
6223static void
6224qla2xxx_pci_resume(struct pci_dev *pdev)
6225{
e315cd28
AC
6226 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6227 struct qla_hw_data *ha = base_vha->hw;
14e660e6
SJ
6228 int ret;
6229
7c3df132
SK
6230 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
6231 "pci_resume.\n");
85880801 6232
e315cd28 6233 ret = qla2x00_wait_for_hba_online(base_vha);
14e660e6 6234 if (ret != QLA_SUCCESS) {
7c3df132
SK
6235 ql_log(ql_log_fatal, base_vha, 0x9002,
6236 "The device failed to resume I/O from slot/link_reset.\n");
14e660e6 6237 }
85880801 6238
3e46f031
LC
6239 pci_cleanup_aer_uncorrect_error_status(pdev);
6240
85880801 6241 ha->flags.eeh_busy = 0;
14e660e6
SJ
6242}
6243
2d5a4c34
HM
6244static void
6245qla83xx_disable_laser(scsi_qla_host_t *vha)
6246{
6247 uint32_t reg, data, fn;
6248 struct qla_hw_data *ha = vha->hw;
6249 struct device_reg_24xx __iomem *isp_reg = &ha->iobase->isp24;
6250
6251 /* pci func #/port # */
6252 ql_dbg(ql_dbg_init, vha, 0x004b,
6253 "Disabling Laser for hba: %p\n", vha);
6254
6255 fn = (RD_REG_DWORD(&isp_reg->ctrl_status) &
6256 (BIT_15|BIT_14|BIT_13|BIT_12));
6257
6258 fn = (fn >> 12);
6259
6260 if (fn & 1)
6261 reg = PORT_1_2031;
6262 else
6263 reg = PORT_0_2031;
6264
6265 data = LASER_OFF_2031;
6266
6267 qla83xx_wr_reg(vha, reg, data);
6268}
6269
5601236b
MH
6270static int qla2xxx_map_queues(struct Scsi_Host *shost)
6271{
6272 scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
6273
6274 return blk_mq_pci_map_queues(&shost->tag_set, vha->hw->pdev);
6275}
6276
a55b2d21 6277static const struct pci_error_handlers qla2xxx_err_handler = {
14e660e6
SJ
6278 .error_detected = qla2xxx_pci_error_detected,
6279 .mmio_enabled = qla2xxx_pci_mmio_enabled,
6280 .slot_reset = qla2xxx_pci_slot_reset,
6281 .resume = qla2xxx_pci_resume,
6282};
6283
5433383e 6284static struct pci_device_id qla2xxx_pci_tbl[] = {
47f5e069
AV
6285 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
6286 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
6287 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
6288 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
6289 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
6290 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
6291 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
6292 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
6293 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
4d4df193 6294 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
47f5e069
AV
6295 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
6296 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
c3a2f0df 6297 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
6246b8a1 6298 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
3a03eb79 6299 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
a9083016 6300 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
650f528f 6301 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
8ae6d9c7 6302 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
7ec0effd 6303 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
f73cb695 6304 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
2c5bbbb2 6305 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
2b48992f 6306 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
5433383e
AV
6307 { 0 },
6308};
6309MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
6310
fca29703 6311static struct pci_driver qla2xxx_pci_driver = {
cb63067a 6312 .name = QLA2XXX_DRIVER_NAME,
0a21ef1e
JB
6313 .driver = {
6314 .owner = THIS_MODULE,
6315 },
fca29703 6316 .id_table = qla2xxx_pci_tbl,
7ee61397 6317 .probe = qla2x00_probe_one,
4c993f76 6318 .remove = qla2x00_remove_one,
e30d1756 6319 .shutdown = qla2x00_shutdown,
14e660e6 6320 .err_handler = &qla2xxx_err_handler,
fca29703
AV
6321};
6322
75ef9de1 6323static const struct file_operations apidev_fops = {
6a03b4cd 6324 .owner = THIS_MODULE,
6038f373 6325 .llseek = noop_llseek,
6a03b4cd
HZ
6326};
6327
1da177e4
LT
6328/**
6329 * qla2x00_module_init - Module initialization.
6330 **/
6331static int __init
6332qla2x00_module_init(void)
6333{
fca29703
AV
6334 int ret = 0;
6335
1da177e4 6336 /* Allocate cache for SRBs. */
354d6b21 6337 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
20c2df83 6338 SLAB_HWCACHE_ALIGN, NULL);
1da177e4 6339 if (srb_cachep == NULL) {
7c3df132
SK
6340 ql_log(ql_log_fatal, NULL, 0x0001,
6341 "Unable to allocate SRB cache...Failing load!.\n");
1da177e4
LT
6342 return -ENOMEM;
6343 }
6344
2d70c103
NB
6345 /* Initialize target kmem_cache and mem_pools */
6346 ret = qlt_init();
6347 if (ret < 0) {
6348 kmem_cache_destroy(srb_cachep);
6349 return ret;
6350 } else if (ret > 0) {
6351 /*
6352 * If initiator mode is explictly disabled by qlt_init(),
6353 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
6354 * performing scsi_scan_target() during LOOP UP event.
6355 */
6356 qla2xxx_transport_functions.disable_target_scan = 1;
6357 qla2xxx_transport_vport_functions.disable_target_scan = 1;
6358 }
6359
1da177e4
LT
6360 /* Derive version string. */
6361 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
11010fec 6362 if (ql2xextended_error_logging)
0181944f
AV
6363 strcat(qla2x00_version_str, "-debug");
6364
1c97a12a
AV
6365 qla2xxx_transport_template =
6366 fc_attach_transport(&qla2xxx_transport_functions);
2c3dfe3f
SJ
6367 if (!qla2xxx_transport_template) {
6368 kmem_cache_destroy(srb_cachep);
7c3df132
SK
6369 ql_log(ql_log_fatal, NULL, 0x0002,
6370 "fc_attach_transport failed...Failing load!.\n");
2d70c103 6371 qlt_exit();
1da177e4 6372 return -ENODEV;
2c3dfe3f 6373 }
6a03b4cd
HZ
6374
6375 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
6376 if (apidev_major < 0) {
7c3df132
SK
6377 ql_log(ql_log_fatal, NULL, 0x0003,
6378 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
6a03b4cd
HZ
6379 }
6380
2c3dfe3f
SJ
6381 qla2xxx_transport_vport_template =
6382 fc_attach_transport(&qla2xxx_transport_vport_functions);
6383 if (!qla2xxx_transport_vport_template) {
6384 kmem_cache_destroy(srb_cachep);
2d70c103 6385 qlt_exit();
2c3dfe3f 6386 fc_release_transport(qla2xxx_transport_template);
7c3df132
SK
6387 ql_log(ql_log_fatal, NULL, 0x0004,
6388 "fc_attach_transport vport failed...Failing load!.\n");
1da177e4 6389 return -ENODEV;
2c3dfe3f 6390 }
7c3df132
SK
6391 ql_log(ql_log_info, NULL, 0x0005,
6392 "QLogic Fibre Channel HBA Driver: %s.\n",
fd9a29f0 6393 qla2x00_version_str);
7ee61397 6394 ret = pci_register_driver(&qla2xxx_pci_driver);
fca29703
AV
6395 if (ret) {
6396 kmem_cache_destroy(srb_cachep);
2d70c103 6397 qlt_exit();
fca29703 6398 fc_release_transport(qla2xxx_transport_template);
2c3dfe3f 6399 fc_release_transport(qla2xxx_transport_vport_template);
7c3df132
SK
6400 ql_log(ql_log_fatal, NULL, 0x0006,
6401 "pci_register_driver failed...ret=%d Failing load!.\n",
6402 ret);
fca29703
AV
6403 }
6404 return ret;
1da177e4
LT
6405}
6406
6407/**
6408 * qla2x00_module_exit - Module cleanup.
6409 **/
6410static void __exit
6411qla2x00_module_exit(void)
6412{
6a03b4cd 6413 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
7ee61397 6414 pci_unregister_driver(&qla2xxx_pci_driver);
5433383e 6415 qla2x00_release_firmware();
354d6b21 6416 kmem_cache_destroy(srb_cachep);
2d70c103 6417 qlt_exit();
a9083016
GM
6418 if (ctx_cachep)
6419 kmem_cache_destroy(ctx_cachep);
1da177e4 6420 fc_release_transport(qla2xxx_transport_template);
2c3dfe3f 6421 fc_release_transport(qla2xxx_transport_vport_template);
1da177e4
LT
6422}
6423
6424module_init(qla2x00_module_init);
6425module_exit(qla2x00_module_exit);
6426
6427MODULE_AUTHOR("QLogic Corporation");
6428MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
6429MODULE_LICENSE("GPL");
6430MODULE_VERSION(QLA2XXX_VERSION);
bb8ee499
AV
6431MODULE_FIRMWARE(FW_FILE_ISP21XX);
6432MODULE_FIRMWARE(FW_FILE_ISP22XX);
6433MODULE_FIRMWARE(FW_FILE_ISP2300);
6434MODULE_FIRMWARE(FW_FILE_ISP2322);
6435MODULE_FIRMWARE(FW_FILE_ISP24XX);
61623fc3 6436MODULE_FIRMWARE(FW_FILE_ISP25XX);