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