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