2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2008 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/moduleparam.h>
10 #include <linux/vmalloc.h>
11 #include <linux/delay.h>
12 #include <linux/kthread.h>
13 #include <linux/mutex.h>
15 #include <scsi/scsi_tcq.h>
16 #include <scsi/scsicam.h>
17 #include <scsi/scsi_transport.h>
18 #include <scsi/scsi_transport_fc.h>
23 char qla2x00_version_str[40];
26 * SRB allocation cache
28 static struct kmem_cache *srb_cachep;
30 int ql2xlogintimeout = 20;
31 module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
32 MODULE_PARM_DESC(ql2xlogintimeout,
33 "Login timeout value in seconds.");
35 int qlport_down_retry;
36 module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
37 MODULE_PARM_DESC(qlport_down_retry,
38 "Maximum number of command retries to a port that returns "
39 "a PORT-DOWN status.");
41 int ql2xplogiabsentdevice;
42 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
43 MODULE_PARM_DESC(ql2xplogiabsentdevice,
44 "Option to enable PLOGI to devices that are not present after "
45 "a Fabric scan. This is needed for several broken switches. "
46 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
48 int ql2xloginretrycount = 0;
49 module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
50 MODULE_PARM_DESC(ql2xloginretrycount,
51 "Specify an alternate value for the NVRAM login retry count.");
53 int ql2xallocfwdump = 1;
54 module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR);
55 MODULE_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.");
60 int ql2xextended_error_logging;
61 module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
62 MODULE_PARM_DESC(ql2xextended_error_logging,
63 "Option to enable extended error logging, "
64 "Default is 0 - no logging. 1 - log errors.");
66 static void qla2x00_free_device(scsi_qla_host_t *);
69 module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
70 MODULE_PARM_DESC(ql2xfdmienable,
71 "Enables FDMI registratons "
72 "Default is 0 - no FDMI. 1 - perfom FDMI.");
74 #define MAX_Q_DEPTH 32
75 static int ql2xmaxqdepth = MAX_Q_DEPTH;
76 module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
77 MODULE_PARM_DESC(ql2xmaxqdepth,
78 "Maximum queue depth to report for target devices.");
80 int ql2xqfullrampup = 120;
81 module_param(ql2xqfullrampup, int, S_IRUGO|S_IWUSR);
82 MODULE_PARM_DESC(ql2xqfullrampup,
83 "Number of seconds to wait to begin to ramp-up the queue "
84 "depth for a device after a queue-full condition has been "
85 "detected. Default is 120 seconds.");
87 int ql2xiidmaenable=1;
88 module_param(ql2xiidmaenable, int, S_IRUGO|S_IRUSR);
89 MODULE_PARM_DESC(ql2xiidmaenable,
90 "Enables iIDMA settings "
91 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
93 int ql2xmaxqueues = 1;
94 module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR);
95 MODULE_PARM_DESC(ql2xmaxqueues,
96 "Enables MQ settings "
97 "Default is 1 for single queue. Set it to number \
98 of queues in MQ mode.");
100 * SCSI host template entry points
102 static int qla2xxx_slave_configure(struct scsi_device * device);
103 static int qla2xxx_slave_alloc(struct scsi_device *);
104 static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
105 static void qla2xxx_scan_start(struct Scsi_Host *);
106 static void qla2xxx_slave_destroy(struct scsi_device *);
107 static int qla2xxx_queuecommand(struct scsi_cmnd *cmd,
108 void (*fn)(struct scsi_cmnd *));
109 static int qla2xxx_eh_abort(struct scsi_cmnd *);
110 static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
111 static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
112 static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
113 static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
115 static int qla2x00_change_queue_depth(struct scsi_device *, int);
116 static int qla2x00_change_queue_type(struct scsi_device *, int);
118 struct scsi_host_template qla2xxx_driver_template = {
119 .module = THIS_MODULE,
120 .name = QLA2XXX_DRIVER_NAME,
121 .queuecommand = qla2xxx_queuecommand,
123 .eh_abort_handler = qla2xxx_eh_abort,
124 .eh_device_reset_handler = qla2xxx_eh_device_reset,
125 .eh_target_reset_handler = qla2xxx_eh_target_reset,
126 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
127 .eh_host_reset_handler = qla2xxx_eh_host_reset,
129 .slave_configure = qla2xxx_slave_configure,
131 .slave_alloc = qla2xxx_slave_alloc,
132 .slave_destroy = qla2xxx_slave_destroy,
133 .scan_finished = qla2xxx_scan_finished,
134 .scan_start = qla2xxx_scan_start,
135 .change_queue_depth = qla2x00_change_queue_depth,
136 .change_queue_type = qla2x00_change_queue_type,
139 .use_clustering = ENABLE_CLUSTERING,
140 .sg_tablesize = SG_ALL,
142 .max_sectors = 0xFFFF,
143 .shost_attrs = qla2x00_host_attrs,
146 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
147 struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
149 /* TODO Convert to inlines
155 qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
157 init_timer(&vha->timer);
158 vha->timer.expires = jiffies + interval * HZ;
159 vha->timer.data = (unsigned long)vha;
160 vha->timer.function = (void (*)(unsigned long))func;
161 add_timer(&vha->timer);
162 vha->timer_active = 1;
166 qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
168 mod_timer(&vha->timer, jiffies + interval * HZ);
171 static __inline__ void
172 qla2x00_stop_timer(scsi_qla_host_t *vha)
174 del_timer_sync(&vha->timer);
175 vha->timer_active = 0;
178 static int qla2x00_do_dpc(void *data);
180 static void qla2x00_rst_aen(scsi_qla_host_t *);
182 static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
183 struct req_que **, struct rsp_que **);
184 static void qla2x00_mem_free(struct qla_hw_data *);
185 static void qla2x00_sp_free_dma(srb_t *);
187 /* -------------------------------------------------------------------------- */
188 static int qla2x00_alloc_queues(struct qla_hw_data *ha)
190 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
192 if (!ha->req_q_map) {
193 qla_printk(KERN_WARNING, ha,
194 "Unable to allocate memory for request queue ptrs\n");
198 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
200 if (!ha->rsp_q_map) {
201 qla_printk(KERN_WARNING, ha,
202 "Unable to allocate memory for response queue ptrs\n");
205 set_bit(0, ha->rsp_qid_map);
206 set_bit(0, ha->req_qid_map);
210 kfree(ha->req_q_map);
211 ha->req_q_map = NULL;
216 static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
218 if (req && req->ring)
219 dma_free_coherent(&ha->pdev->dev,
220 (req->length + 1) * sizeof(request_t),
221 req->ring, req->dma);
227 static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
229 if (rsp && rsp->ring)
230 dma_free_coherent(&ha->pdev->dev,
231 (rsp->length + 1) * sizeof(response_t),
232 rsp->ring, rsp->dma);
238 static void qla2x00_free_queues(struct qla_hw_data *ha)
244 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
245 req = ha->req_q_map[cnt];
246 qla2x00_free_req_que(ha, req);
248 kfree(ha->req_q_map);
249 ha->req_q_map = NULL;
251 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
252 rsp = ha->rsp_q_map[cnt];
253 qla2x00_free_rsp_que(ha, rsp);
255 kfree(ha->rsp_q_map);
256 ha->rsp_q_map = NULL;
260 qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
262 struct qla_hw_data *ha = vha->hw;
263 static char *pci_bus_modes[] = {
264 "33", "66", "100", "133",
269 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
272 strcat(str, pci_bus_modes[pci_bus]);
274 pci_bus = (ha->pci_attr & BIT_8) >> 8;
276 strcat(str, pci_bus_modes[pci_bus]);
278 strcat(str, " MHz)");
284 qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
286 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
287 struct qla_hw_data *ha = vha->hw;
291 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
294 uint16_t pcie_lstat, lspeed, lwidth;
297 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
298 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
299 lwidth = (pcie_lstat &
300 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
302 strcpy(str, "PCIe (");
304 strcat(str, "2.5GT/s ");
305 else if (lspeed == 2)
306 strcat(str, "5.0GT/s ");
308 strcat(str, "<unknown> ");
309 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
316 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
317 if (pci_bus == 0 || pci_bus == 8) {
319 strcat(str, pci_bus_modes[pci_bus >> 3]);
323 strcat(str, "Mode 2");
325 strcat(str, "Mode 1");
327 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
329 strcat(str, " MHz)");
335 qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
338 struct qla_hw_data *ha = vha->hw;
340 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
341 ha->fw_minor_version,
342 ha->fw_subminor_version);
344 if (ha->fw_attributes & BIT_9) {
349 switch (ha->fw_attributes & 0xFF) {
363 sprintf(un_str, "(%x)", ha->fw_attributes);
367 if (ha->fw_attributes & 0x100)
374 qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
376 struct qla_hw_data *ha = vha->hw;
378 sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
379 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
383 static inline srb_t *
384 qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
385 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
388 struct qla_hw_data *ha = vha->hw;
390 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
396 sp->que = ha->req_q_map[0];
398 CMD_SP(cmd) = (void *)sp;
399 cmd->scsi_done = done;
405 qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
407 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
408 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
409 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
410 struct qla_hw_data *ha = vha->hw;
411 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
415 if (unlikely(pci_channel_offline(ha->pdev))) {
416 if (ha->pdev->error_state == pci_channel_io_frozen)
417 cmd->result = DID_REQUEUE << 16;
419 cmd->result = DID_NO_CONNECT << 16;
420 goto qc24_fail_command;
423 rval = fc_remote_port_chkready(rport);
426 goto qc24_fail_command;
429 /* Close window on fcport/rport state-transitioning. */
431 goto qc24_target_busy;
433 if (atomic_read(&fcport->state) != FCS_ONLINE) {
434 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
435 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
436 cmd->result = DID_NO_CONNECT << 16;
437 goto qc24_fail_command;
439 goto qc24_target_busy;
442 spin_unlock_irq(vha->host->host_lock);
444 sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
446 goto qc24_host_busy_lock;
448 rval = ha->isp_ops->start_scsi(sp);
449 if (rval != QLA_SUCCESS)
450 goto qc24_host_busy_free_sp;
452 spin_lock_irq(vha->host->host_lock);
456 qc24_host_busy_free_sp:
457 qla2x00_sp_free_dma(sp);
458 mempool_free(sp, ha->srb_mempool);
461 spin_lock_irq(vha->host->host_lock);
462 return SCSI_MLQUEUE_HOST_BUSY;
465 return SCSI_MLQUEUE_TARGET_BUSY;
475 * qla2x00_eh_wait_on_command
476 * Waits for the command to be returned by the Firmware for some
480 * cmd = Scsi Command to wait on.
487 qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
489 #define ABORT_POLLING_PERIOD 1000
490 #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
491 unsigned long wait_iter = ABORT_WAIT_ITER;
492 int ret = QLA_SUCCESS;
494 while (CMD_SP(cmd)) {
495 msleep(ABORT_POLLING_PERIOD);
501 ret = QLA_FUNCTION_FAILED;
507 * qla2x00_wait_for_hba_online
508 * Wait till the HBA is online after going through
509 * <= MAX_RETRIES_OF_ISP_ABORT or
510 * finally HBA is disabled ie marked offline
513 * ha - pointer to host adapter structure
516 * Does context switching-Release SPIN_LOCK
517 * (if any) before calling this routine.
520 * Success (Adapter is online) : 0
521 * Failed (Adapter is offline/disabled) : 1
524 qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
527 unsigned long wait_online;
528 struct qla_hw_data *ha = vha->hw;
529 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
531 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
532 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
533 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
534 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
535 ha->dpc_active) && time_before(jiffies, wait_online)) {
539 if (base_vha->flags.online)
540 return_status = QLA_SUCCESS;
542 return_status = QLA_FUNCTION_FAILED;
544 return (return_status);
548 qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
551 unsigned long wait_reset;
552 struct qla_hw_data *ha = vha->hw;
553 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
555 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
556 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
557 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
558 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
559 ha->dpc_active) && time_before(jiffies, wait_reset)) {
563 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
564 ha->flags.chip_reset_done)
567 if (ha->flags.chip_reset_done)
568 return_status = QLA_SUCCESS;
570 return_status = QLA_FUNCTION_FAILED;
572 return return_status;
576 * qla2x00_wait_for_loop_ready
577 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
578 * to be in LOOP_READY state.
580 * ha - pointer to host adapter structure
583 * Does context switching-Release SPIN_LOCK
584 * (if any) before calling this routine.
588 * Success (LOOP_READY) : 0
589 * Failed (LOOP_NOT_READY) : 1
592 qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
594 int return_status = QLA_SUCCESS;
595 unsigned long loop_timeout ;
596 struct qla_hw_data *ha = vha->hw;
597 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
599 /* wait for 5 min at the max for loop to be ready */
600 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
602 while ((!atomic_read(&base_vha->loop_down_timer) &&
603 atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
604 atomic_read(&base_vha->loop_state) != LOOP_READY) {
605 if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
606 return_status = QLA_FUNCTION_FAILED;
610 if (time_after_eq(jiffies, loop_timeout)) {
611 return_status = QLA_FUNCTION_FAILED;
615 return (return_status);
619 qla2x00_abort_fcport_cmds(fc_port_t *fcport)
624 scsi_qla_host_t *vha = fcport->vha;
625 struct qla_hw_data *ha = vha->hw;
628 spin_lock_irqsave(&ha->hardware_lock, flags);
630 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
631 sp = req->outstanding_cmds[cnt];
634 if (sp->fcport != fcport)
637 spin_unlock_irqrestore(&ha->hardware_lock, flags);
638 if (ha->isp_ops->abort_command(sp)) {
639 DEBUG2(qla_printk(KERN_WARNING, ha,
640 "Abort failed -- %lx\n",
641 sp->cmd->serial_number));
643 if (qla2x00_eh_wait_on_command(sp->cmd) !=
645 DEBUG2(qla_printk(KERN_WARNING, ha,
646 "Abort failed while waiting -- %lx\n",
647 sp->cmd->serial_number));
649 spin_lock_irqsave(&ha->hardware_lock, flags);
651 spin_unlock_irqrestore(&ha->hardware_lock, flags);
655 qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
657 struct Scsi_Host *shost = cmnd->device->host;
658 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
661 spin_lock_irqsave(shost->host_lock, flags);
662 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
663 spin_unlock_irqrestore(shost->host_lock, flags);
665 spin_lock_irqsave(shost->host_lock, flags);
667 spin_unlock_irqrestore(shost->host_lock, flags);
671 /**************************************************************************
675 * The abort function will abort the specified command.
678 * cmd = Linux SCSI command packet to be aborted.
681 * Either SUCCESS or FAILED.
684 * Only return FAILED if command not returned by firmware.
685 **************************************************************************/
687 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
689 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
692 unsigned int id, lun;
693 unsigned long serial;
696 struct qla_hw_data *ha = vha->hw;
700 qla2x00_block_error_handler(cmd);
707 id = cmd->device->id;
708 lun = cmd->device->lun;
709 serial = cmd->serial_number;
710 spt = (srb_t *) CMD_SP(cmd);
715 /* Check active list for command command. */
716 spin_lock_irqsave(&ha->hardware_lock, flags);
717 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
718 sp = req->outstanding_cmds[i];
726 DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
727 " pid=%ld.\n", __func__, vha->host_no, sp, serial));
729 spin_unlock_irqrestore(&ha->hardware_lock, flags);
730 if (ha->isp_ops->abort_command(sp)) {
731 DEBUG2(printk("%s(%ld): abort_command "
732 "mbx failed.\n", __func__, vha->host_no));
735 DEBUG3(printk("%s(%ld): abort_command "
736 "mbx success.\n", __func__, vha->host_no));
739 spin_lock_irqsave(&ha->hardware_lock, flags);
742 spin_unlock_irqrestore(&ha->hardware_lock, flags);
744 /* Wait for the command to be returned. */
746 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
747 qla_printk(KERN_ERR, ha,
748 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
749 "%x.\n", vha->host_no, id, lun, serial, ret);
754 qla_printk(KERN_INFO, ha,
755 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
756 vha->host_no, id, lun, wait, serial, ret);
761 enum nexus_wait_type {
768 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
769 unsigned int l, srb_t *sp, enum nexus_wait_type type)
771 int cnt, match, status;
773 struct qla_hw_data *ha = vha->hw;
776 status = QLA_SUCCESS;
780 spin_lock_irqsave(&ha->hardware_lock, flags);
782 for (cnt = 1; status == QLA_SUCCESS &&
783 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
784 sp = req->outstanding_cmds[cnt];
788 if (vha->vp_idx != sp->fcport->vha->vp_idx)
796 match = sp->cmd->device->id == t;
799 match = (sp->cmd->device->id == t &&
800 sp->cmd->device->lun == l);
806 spin_unlock_irqrestore(&ha->hardware_lock, flags);
807 status = qla2x00_eh_wait_on_command(sp->cmd);
808 spin_lock_irqsave(&ha->hardware_lock, flags);
810 spin_unlock_irqrestore(&ha->hardware_lock, flags);
815 static char *reset_errors[] = {
818 "Task management failed",
819 "Waiting for command completions",
823 __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
824 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
826 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
827 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
830 qla2x00_block_error_handler(cmd);
835 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
836 vha->host_no, cmd->device->id, cmd->device->lun, name);
839 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
840 goto eh_reset_failed;
842 if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
843 goto eh_reset_failed;
845 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
847 goto eh_reset_failed;
849 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
850 cmd->device->lun, (srb_t *) CMD_SP(cmd), type) != QLA_SUCCESS)
851 goto eh_reset_failed;
853 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
854 vha->host_no, cmd->device->id, cmd->device->lun, name);
859 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
860 , vha->host_no, cmd->device->id, cmd->device->lun, name,
866 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
868 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
869 struct qla_hw_data *ha = vha->hw;
871 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
872 ha->isp_ops->lun_reset);
876 qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
878 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
879 struct qla_hw_data *ha = vha->hw;
881 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
882 ha->isp_ops->target_reset);
885 /**************************************************************************
886 * qla2xxx_eh_bus_reset
889 * The bus reset function will reset the bus and abort any executing
893 * cmd = Linux SCSI command packet of the command that cause the
897 * SUCCESS/FAILURE (defined as macro in scsi.h).
899 **************************************************************************/
901 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
903 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
904 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
906 unsigned int id, lun;
907 unsigned long serial;
908 srb_t *sp = (srb_t *) CMD_SP(cmd);
910 qla2x00_block_error_handler(cmd);
912 id = cmd->device->id;
913 lun = cmd->device->lun;
914 serial = cmd->serial_number;
919 qla_printk(KERN_INFO, vha->hw,
920 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
922 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
923 DEBUG2(printk("%s failed:board disabled\n",__func__));
924 goto eh_bus_reset_done;
927 if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
928 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
932 goto eh_bus_reset_done;
934 /* Flush outstanding commands. */
935 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) !=
940 qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
941 (ret == FAILED) ? "failed" : "succeded");
946 /**************************************************************************
947 * qla2xxx_eh_host_reset
950 * The reset function will reset the Adapter.
953 * cmd = Linux SCSI command packet of the command that cause the
957 * Either SUCCESS or FAILED.
960 **************************************************************************/
962 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
964 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
965 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
966 struct qla_hw_data *ha = vha->hw;
968 unsigned int id, lun;
969 unsigned long serial;
970 srb_t *sp = (srb_t *) CMD_SP(cmd);
971 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
973 qla2x00_block_error_handler(cmd);
975 id = cmd->device->id;
976 lun = cmd->device->lun;
977 serial = cmd->serial_number;
982 qla_printk(KERN_INFO, ha,
983 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
985 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
986 goto eh_host_reset_lock;
989 * Fixme-may be dpc thread is active and processing
990 * loop_resync,so wait a while for it to
991 * be completed and then issue big hammer.Otherwise
992 * it may cause I/O failure as big hammer marks the
993 * devices as lost kicking of the port_down_timer
994 * while dpc is stuck for the mailbox to complete.
996 qla2x00_wait_for_loop_ready(vha);
997 if (vha != base_vha) {
998 if (qla2x00_vp_abort_isp(vha))
999 goto eh_host_reset_lock;
1001 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1002 if (qla2x00_abort_isp(base_vha)) {
1003 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1004 /* failed. schedule dpc to try */
1005 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1007 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1008 goto eh_host_reset_lock;
1010 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1013 /* Waiting for command to be returned to OS.*/
1014 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) ==
1019 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1020 (ret == FAILED) ? "failed" : "succeded");
1026 * qla2x00_loop_reset
1030 * ha = adapter block pointer.
1036 qla2x00_loop_reset(scsi_qla_host_t *vha)
1039 struct fc_port *fcport;
1040 struct qla_hw_data *ha = vha->hw;
1042 if (ha->flags.enable_lip_full_login && !vha->vp_idx &&
1044 ret = qla2x00_full_login_lip(vha);
1045 if (ret != QLA_SUCCESS) {
1046 DEBUG2_3(printk("%s(%ld): failed: "
1047 "full_login_lip=%d.\n", __func__, vha->host_no,
1050 atomic_set(&vha->loop_state, LOOP_DOWN);
1051 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1052 qla2x00_mark_all_devices_lost(vha, 0);
1053 qla2x00_wait_for_loop_ready(vha);
1056 if (ha->flags.enable_lip_reset && !vha->vp_idx) {
1057 ret = qla2x00_lip_reset(vha);
1058 if (ret != QLA_SUCCESS) {
1059 DEBUG2_3(printk("%s(%ld): failed: "
1060 "lip_reset=%d.\n", __func__, vha->host_no, ret));
1062 qla2x00_wait_for_loop_ready(vha);
1065 if (ha->flags.enable_target_reset) {
1066 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1067 if (fcport->port_type != FCT_TARGET)
1070 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1071 if (ret != QLA_SUCCESS) {
1072 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1073 "target_reset=%d d_id=%x.\n", __func__,
1074 vha->host_no, ret, fcport->d_id.b24));
1078 /* Issue marker command only when we are going to start the I/O */
1079 vha->marker_needed = 1;
1085 qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1088 unsigned long flags;
1090 struct qla_hw_data *ha = vha->hw;
1091 struct req_que *req;
1093 spin_lock_irqsave(&ha->hardware_lock, flags);
1094 for (que = 0; que < ha->max_req_queues; que++) {
1095 req = ha->req_q_map[que];
1098 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1099 sp = req->outstanding_cmds[cnt];
1101 req->outstanding_cmds[cnt] = NULL;
1102 sp->cmd->result = res;
1103 qla2x00_sp_compl(ha, sp);
1107 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1111 qla2xxx_slave_alloc(struct scsi_device *sdev)
1113 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1115 if (!rport || fc_remote_port_chkready(rport))
1118 sdev->hostdata = *(fc_port_t **)rport->dd_data;
1124 qla2xxx_slave_configure(struct scsi_device *sdev)
1126 scsi_qla_host_t *vha = shost_priv(sdev->host);
1127 struct qla_hw_data *ha = vha->hw;
1128 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1129 struct req_que *req = vha->req;
1131 if (sdev->tagged_supported)
1132 scsi_activate_tcq(sdev, req->max_q_depth);
1134 scsi_deactivate_tcq(sdev, req->max_q_depth);
1136 rport->dev_loss_tmo = ha->port_down_retry_count;
1142 qla2xxx_slave_destroy(struct scsi_device *sdev)
1144 sdev->hostdata = NULL;
1148 qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1150 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1151 return sdev->queue_depth;
1155 qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1157 if (sdev->tagged_supported) {
1158 scsi_set_tag_type(sdev, tag_type);
1160 scsi_activate_tcq(sdev, sdev->queue_depth);
1162 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1170 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1173 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1174 * supported addressing method.
1177 qla2x00_config_dma_addressing(struct qla_hw_data *ha)
1179 /* Assume a 32bit DMA mask. */
1180 ha->flags.enable_64bit_addressing = 0;
1182 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1183 /* Any upper-dword bits set? */
1184 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1185 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
1186 /* Ok, a 64bit DMA mask is applicable. */
1187 ha->flags.enable_64bit_addressing = 1;
1188 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1189 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
1194 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1195 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
1199 qla2x00_enable_intrs(struct qla_hw_data *ha)
1201 unsigned long flags = 0;
1202 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1204 spin_lock_irqsave(&ha->hardware_lock, flags);
1205 ha->interrupts_on = 1;
1206 /* enable risc and host interrupts */
1207 WRT_REG_WORD(®->ictrl, ICR_EN_INT | ICR_EN_RISC);
1208 RD_REG_WORD(®->ictrl);
1209 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1214 qla2x00_disable_intrs(struct qla_hw_data *ha)
1216 unsigned long flags = 0;
1217 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1219 spin_lock_irqsave(&ha->hardware_lock, flags);
1220 ha->interrupts_on = 0;
1221 /* disable risc and host interrupts */
1222 WRT_REG_WORD(®->ictrl, 0);
1223 RD_REG_WORD(®->ictrl);
1224 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1228 qla24xx_enable_intrs(struct qla_hw_data *ha)
1230 unsigned long flags = 0;
1231 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1233 spin_lock_irqsave(&ha->hardware_lock, flags);
1234 ha->interrupts_on = 1;
1235 WRT_REG_DWORD(®->ictrl, ICRX_EN_RISC_INT);
1236 RD_REG_DWORD(®->ictrl);
1237 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1241 qla24xx_disable_intrs(struct qla_hw_data *ha)
1243 unsigned long flags = 0;
1244 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1246 if (IS_NOPOLLING_TYPE(ha))
1248 spin_lock_irqsave(&ha->hardware_lock, flags);
1249 ha->interrupts_on = 0;
1250 WRT_REG_DWORD(®->ictrl, 0);
1251 RD_REG_DWORD(®->ictrl);
1252 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1255 static struct isp_operations qla2100_isp_ops = {
1256 .pci_config = qla2100_pci_config,
1257 .reset_chip = qla2x00_reset_chip,
1258 .chip_diag = qla2x00_chip_diag,
1259 .config_rings = qla2x00_config_rings,
1260 .reset_adapter = qla2x00_reset_adapter,
1261 .nvram_config = qla2x00_nvram_config,
1262 .update_fw_options = qla2x00_update_fw_options,
1263 .load_risc = qla2x00_load_risc,
1264 .pci_info_str = qla2x00_pci_info_str,
1265 .fw_version_str = qla2x00_fw_version_str,
1266 .intr_handler = qla2100_intr_handler,
1267 .enable_intrs = qla2x00_enable_intrs,
1268 .disable_intrs = qla2x00_disable_intrs,
1269 .abort_command = qla2x00_abort_command,
1270 .target_reset = qla2x00_abort_target,
1271 .lun_reset = qla2x00_lun_reset,
1272 .fabric_login = qla2x00_login_fabric,
1273 .fabric_logout = qla2x00_fabric_logout,
1274 .calc_req_entries = qla2x00_calc_iocbs_32,
1275 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1276 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1277 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1278 .read_nvram = qla2x00_read_nvram_data,
1279 .write_nvram = qla2x00_write_nvram_data,
1280 .fw_dump = qla2100_fw_dump,
1283 .beacon_blink = NULL,
1284 .read_optrom = qla2x00_read_optrom_data,
1285 .write_optrom = qla2x00_write_optrom_data,
1286 .get_flash_version = qla2x00_get_flash_version,
1287 .start_scsi = qla2x00_start_scsi,
1290 static struct isp_operations qla2300_isp_ops = {
1291 .pci_config = qla2300_pci_config,
1292 .reset_chip = qla2x00_reset_chip,
1293 .chip_diag = qla2x00_chip_diag,
1294 .config_rings = qla2x00_config_rings,
1295 .reset_adapter = qla2x00_reset_adapter,
1296 .nvram_config = qla2x00_nvram_config,
1297 .update_fw_options = qla2x00_update_fw_options,
1298 .load_risc = qla2x00_load_risc,
1299 .pci_info_str = qla2x00_pci_info_str,
1300 .fw_version_str = qla2x00_fw_version_str,
1301 .intr_handler = qla2300_intr_handler,
1302 .enable_intrs = qla2x00_enable_intrs,
1303 .disable_intrs = qla2x00_disable_intrs,
1304 .abort_command = qla2x00_abort_command,
1305 .target_reset = qla2x00_abort_target,
1306 .lun_reset = qla2x00_lun_reset,
1307 .fabric_login = qla2x00_login_fabric,
1308 .fabric_logout = qla2x00_fabric_logout,
1309 .calc_req_entries = qla2x00_calc_iocbs_32,
1310 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1311 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1312 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1313 .read_nvram = qla2x00_read_nvram_data,
1314 .write_nvram = qla2x00_write_nvram_data,
1315 .fw_dump = qla2300_fw_dump,
1316 .beacon_on = qla2x00_beacon_on,
1317 .beacon_off = qla2x00_beacon_off,
1318 .beacon_blink = qla2x00_beacon_blink,
1319 .read_optrom = qla2x00_read_optrom_data,
1320 .write_optrom = qla2x00_write_optrom_data,
1321 .get_flash_version = qla2x00_get_flash_version,
1322 .start_scsi = qla2x00_start_scsi,
1325 static struct isp_operations qla24xx_isp_ops = {
1326 .pci_config = qla24xx_pci_config,
1327 .reset_chip = qla24xx_reset_chip,
1328 .chip_diag = qla24xx_chip_diag,
1329 .config_rings = qla24xx_config_rings,
1330 .reset_adapter = qla24xx_reset_adapter,
1331 .nvram_config = qla24xx_nvram_config,
1332 .update_fw_options = qla24xx_update_fw_options,
1333 .load_risc = qla24xx_load_risc,
1334 .pci_info_str = qla24xx_pci_info_str,
1335 .fw_version_str = qla24xx_fw_version_str,
1336 .intr_handler = qla24xx_intr_handler,
1337 .enable_intrs = qla24xx_enable_intrs,
1338 .disable_intrs = qla24xx_disable_intrs,
1339 .abort_command = qla24xx_abort_command,
1340 .target_reset = qla24xx_abort_target,
1341 .lun_reset = qla24xx_lun_reset,
1342 .fabric_login = qla24xx_login_fabric,
1343 .fabric_logout = qla24xx_fabric_logout,
1344 .calc_req_entries = NULL,
1345 .build_iocbs = NULL,
1346 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1347 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1348 .read_nvram = qla24xx_read_nvram_data,
1349 .write_nvram = qla24xx_write_nvram_data,
1350 .fw_dump = qla24xx_fw_dump,
1351 .beacon_on = qla24xx_beacon_on,
1352 .beacon_off = qla24xx_beacon_off,
1353 .beacon_blink = qla24xx_beacon_blink,
1354 .read_optrom = qla24xx_read_optrom_data,
1355 .write_optrom = qla24xx_write_optrom_data,
1356 .get_flash_version = qla24xx_get_flash_version,
1357 .start_scsi = qla24xx_start_scsi,
1360 static struct isp_operations qla25xx_isp_ops = {
1361 .pci_config = qla25xx_pci_config,
1362 .reset_chip = qla24xx_reset_chip,
1363 .chip_diag = qla24xx_chip_diag,
1364 .config_rings = qla24xx_config_rings,
1365 .reset_adapter = qla24xx_reset_adapter,
1366 .nvram_config = qla24xx_nvram_config,
1367 .update_fw_options = qla24xx_update_fw_options,
1368 .load_risc = qla24xx_load_risc,
1369 .pci_info_str = qla24xx_pci_info_str,
1370 .fw_version_str = qla24xx_fw_version_str,
1371 .intr_handler = qla24xx_intr_handler,
1372 .enable_intrs = qla24xx_enable_intrs,
1373 .disable_intrs = qla24xx_disable_intrs,
1374 .abort_command = qla24xx_abort_command,
1375 .target_reset = qla24xx_abort_target,
1376 .lun_reset = qla24xx_lun_reset,
1377 .fabric_login = qla24xx_login_fabric,
1378 .fabric_logout = qla24xx_fabric_logout,
1379 .calc_req_entries = NULL,
1380 .build_iocbs = NULL,
1381 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1382 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1383 .read_nvram = qla25xx_read_nvram_data,
1384 .write_nvram = qla25xx_write_nvram_data,
1385 .fw_dump = qla25xx_fw_dump,
1386 .beacon_on = qla24xx_beacon_on,
1387 .beacon_off = qla24xx_beacon_off,
1388 .beacon_blink = qla24xx_beacon_blink,
1389 .read_optrom = qla25xx_read_optrom_data,
1390 .write_optrom = qla24xx_write_optrom_data,
1391 .get_flash_version = qla24xx_get_flash_version,
1392 .start_scsi = qla24xx_start_scsi,
1395 static struct isp_operations qla81xx_isp_ops = {
1396 .pci_config = qla25xx_pci_config,
1397 .reset_chip = qla24xx_reset_chip,
1398 .chip_diag = qla24xx_chip_diag,
1399 .config_rings = qla24xx_config_rings,
1400 .reset_adapter = qla24xx_reset_adapter,
1401 .nvram_config = qla81xx_nvram_config,
1402 .update_fw_options = qla81xx_update_fw_options,
1403 .load_risc = qla81xx_load_risc,
1404 .pci_info_str = qla24xx_pci_info_str,
1405 .fw_version_str = qla24xx_fw_version_str,
1406 .intr_handler = qla24xx_intr_handler,
1407 .enable_intrs = qla24xx_enable_intrs,
1408 .disable_intrs = qla24xx_disable_intrs,
1409 .abort_command = qla24xx_abort_command,
1410 .target_reset = qla24xx_abort_target,
1411 .lun_reset = qla24xx_lun_reset,
1412 .fabric_login = qla24xx_login_fabric,
1413 .fabric_logout = qla24xx_fabric_logout,
1414 .calc_req_entries = NULL,
1415 .build_iocbs = NULL,
1416 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1417 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1419 .write_nvram = NULL,
1420 .fw_dump = qla81xx_fw_dump,
1421 .beacon_on = qla24xx_beacon_on,
1422 .beacon_off = qla24xx_beacon_off,
1423 .beacon_blink = qla24xx_beacon_blink,
1424 .read_optrom = qla25xx_read_optrom_data,
1425 .write_optrom = qla24xx_write_optrom_data,
1426 .get_flash_version = qla24xx_get_flash_version,
1427 .start_scsi = qla24xx_start_scsi,
1431 qla2x00_set_isp_flags(struct qla_hw_data *ha)
1433 ha->device_type = DT_EXTENDED_IDS;
1434 switch (ha->pdev->device) {
1435 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1436 ha->device_type |= DT_ISP2100;
1437 ha->device_type &= ~DT_EXTENDED_IDS;
1438 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
1440 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1441 ha->device_type |= DT_ISP2200;
1442 ha->device_type &= ~DT_EXTENDED_IDS;
1443 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
1445 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1446 ha->device_type |= DT_ISP2300;
1447 ha->device_type |= DT_ZIO_SUPPORTED;
1448 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1450 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1451 ha->device_type |= DT_ISP2312;
1452 ha->device_type |= DT_ZIO_SUPPORTED;
1453 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1455 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1456 ha->device_type |= DT_ISP2322;
1457 ha->device_type |= DT_ZIO_SUPPORTED;
1458 if (ha->pdev->subsystem_vendor == 0x1028 &&
1459 ha->pdev->subsystem_device == 0x0170)
1460 ha->device_type |= DT_OEM_001;
1461 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1463 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1464 ha->device_type |= DT_ISP6312;
1465 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1467 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1468 ha->device_type |= DT_ISP6322;
1469 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1471 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1472 ha->device_type |= DT_ISP2422;
1473 ha->device_type |= DT_ZIO_SUPPORTED;
1474 ha->device_type |= DT_FWI2;
1475 ha->device_type |= DT_IIDMA;
1476 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1478 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1479 ha->device_type |= DT_ISP2432;
1480 ha->device_type |= DT_ZIO_SUPPORTED;
1481 ha->device_type |= DT_FWI2;
1482 ha->device_type |= DT_IIDMA;
1483 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1485 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1486 ha->device_type |= DT_ISP8432;
1487 ha->device_type |= DT_ZIO_SUPPORTED;
1488 ha->device_type |= DT_FWI2;
1489 ha->device_type |= DT_IIDMA;
1490 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1492 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1493 ha->device_type |= DT_ISP5422;
1494 ha->device_type |= DT_FWI2;
1495 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1497 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1498 ha->device_type |= DT_ISP5432;
1499 ha->device_type |= DT_FWI2;
1500 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1502 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1503 ha->device_type |= DT_ISP2532;
1504 ha->device_type |= DT_ZIO_SUPPORTED;
1505 ha->device_type |= DT_FWI2;
1506 ha->device_type |= DT_IIDMA;
1507 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1509 case PCI_DEVICE_ID_QLOGIC_ISP8001:
1510 ha->device_type |= DT_ISP8001;
1511 ha->device_type |= DT_ZIO_SUPPORTED;
1512 ha->device_type |= DT_FWI2;
1513 ha->device_type |= DT_IIDMA;
1514 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1520 qla2x00_iospace_config(struct qla_hw_data *ha)
1522 resource_size_t pio;
1525 if (pci_request_selected_regions(ha->pdev, ha->bars,
1526 QLA2XXX_DRIVER_NAME)) {
1527 qla_printk(KERN_WARNING, ha,
1528 "Failed to reserve PIO/MMIO regions (%s)\n",
1529 pci_name(ha->pdev));
1531 goto iospace_error_exit;
1533 if (!(ha->bars & 1))
1536 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1537 pio = pci_resource_start(ha->pdev, 0);
1538 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1539 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1540 qla_printk(KERN_WARNING, ha,
1541 "Invalid PCI I/O region size (%s)...\n",
1542 pci_name(ha->pdev));
1546 qla_printk(KERN_WARNING, ha,
1547 "region #0 not a PIO resource (%s)...\n",
1548 pci_name(ha->pdev));
1551 ha->pio_address = pio;
1554 /* Use MMIO operations for all accesses. */
1555 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1556 qla_printk(KERN_ERR, ha,
1557 "region #1 not an MMIO resource (%s), aborting\n",
1558 pci_name(ha->pdev));
1559 goto iospace_error_exit;
1561 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1562 qla_printk(KERN_ERR, ha,
1563 "Invalid PCI mem region size (%s), aborting\n",
1564 pci_name(ha->pdev));
1565 goto iospace_error_exit;
1568 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1570 qla_printk(KERN_ERR, ha,
1571 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1573 goto iospace_error_exit;
1576 /* Determine queue resources */
1577 ha->max_req_queues = ha->max_rsp_queues = 1;
1578 if (ql2xmaxqueues <= 1 &&
1579 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1581 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1582 pci_resource_len(ha->pdev, 3));
1584 /* Read MSIX vector size of the board */
1585 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1586 ha->msix_count = msix;
1587 if (ql2xmaxqueues > 1) {
1588 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1589 QLA_MQ_SIZE : ql2xmaxqueues;
1590 DEBUG2(qla_printk(KERN_INFO, ha, "QoS mode set, max no"
1591 " of request queues:%d\n", ha->max_req_queues));
1594 qla_printk(KERN_INFO, ha, "BAR 3 not enabled\n");
1597 ha->msix_count = ha->max_rsp_queues + 1;
1605 qla2xxx_scan_start(struct Scsi_Host *shost)
1607 scsi_qla_host_t *vha = shost_priv(shost);
1609 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1610 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1611 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1612 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
1616 qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1618 scsi_qla_host_t *vha = shost_priv(shost);
1622 if (time > vha->hw->loop_reset_delay * HZ)
1625 return atomic_read(&vha->loop_state) == LOOP_READY;
1629 * PCI driver interface
1631 static int __devinit
1632 qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1635 struct Scsi_Host *host;
1636 scsi_qla_host_t *base_vha = NULL;
1637 struct qla_hw_data *ha;
1640 struct scsi_host_template *sht;
1641 int bars, max_id, mem_only = 0;
1642 uint16_t req_length = 0, rsp_length = 0;
1643 struct req_que *req = NULL;
1644 struct rsp_que *rsp = NULL;
1646 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
1647 sht = &qla2xxx_driver_template;
1648 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1649 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
1650 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
1651 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1652 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
1653 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
1654 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001) {
1655 bars = pci_select_bars(pdev, IORESOURCE_MEM);
1660 if (pci_enable_device_mem(pdev))
1663 if (pci_enable_device(pdev))
1667 /* This may fail but that's ok */
1668 pci_enable_pcie_error_reporting(pdev);
1670 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
1672 DEBUG(printk("Unable to allocate memory for ha\n"));
1677 /* Clear our data area */
1679 ha->mem_only = mem_only;
1680 spin_lock_init(&ha->hardware_lock);
1682 /* Set ISP-type information. */
1683 qla2x00_set_isp_flags(ha);
1684 /* Configure PCI I/O space */
1685 ret = qla2x00_iospace_config(ha);
1687 goto probe_hw_failed;
1689 qla_printk(KERN_INFO, ha,
1690 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1693 ha->prev_topology = 0;
1694 ha->init_cb_size = sizeof(init_cb_t);
1695 ha->link_data_rate = PORT_SPEED_UNKNOWN;
1696 ha->optrom_size = OPTROM_SIZE_2300;
1698 /* Assign ISP specific operations. */
1699 max_id = MAX_TARGETS_2200;
1700 if (IS_QLA2100(ha)) {
1701 max_id = MAX_TARGETS_2100;
1702 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1703 req_length = REQUEST_ENTRY_CNT_2100;
1704 rsp_length = RESPONSE_ENTRY_CNT_2100;
1705 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
1706 ha->gid_list_info_size = 4;
1707 ha->flash_conf_off = ~0;
1708 ha->flash_data_off = ~0;
1709 ha->nvram_conf_off = ~0;
1710 ha->nvram_data_off = ~0;
1711 ha->isp_ops = &qla2100_isp_ops;
1712 } else if (IS_QLA2200(ha)) {
1713 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1714 req_length = REQUEST_ENTRY_CNT_2200;
1715 rsp_length = RESPONSE_ENTRY_CNT_2100;
1716 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
1717 ha->gid_list_info_size = 4;
1718 ha->flash_conf_off = ~0;
1719 ha->flash_data_off = ~0;
1720 ha->nvram_conf_off = ~0;
1721 ha->nvram_data_off = ~0;
1722 ha->isp_ops = &qla2100_isp_ops;
1723 } else if (IS_QLA23XX(ha)) {
1724 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1725 req_length = REQUEST_ENTRY_CNT_2200;
1726 rsp_length = RESPONSE_ENTRY_CNT_2300;
1727 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1728 ha->gid_list_info_size = 6;
1729 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1730 ha->optrom_size = OPTROM_SIZE_2322;
1731 ha->flash_conf_off = ~0;
1732 ha->flash_data_off = ~0;
1733 ha->nvram_conf_off = ~0;
1734 ha->nvram_data_off = ~0;
1735 ha->isp_ops = &qla2300_isp_ops;
1736 } else if (IS_QLA24XX_TYPE(ha)) {
1737 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1738 req_length = REQUEST_ENTRY_CNT_24XX;
1739 rsp_length = RESPONSE_ENTRY_CNT_2300;
1740 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1741 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1742 ha->gid_list_info_size = 8;
1743 ha->optrom_size = OPTROM_SIZE_24XX;
1744 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
1745 ha->isp_ops = &qla24xx_isp_ops;
1746 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1747 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1748 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1749 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
1750 } else if (IS_QLA25XX(ha)) {
1751 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1752 req_length = REQUEST_ENTRY_CNT_24XX;
1753 rsp_length = RESPONSE_ENTRY_CNT_2300;
1754 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1755 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1756 ha->gid_list_info_size = 8;
1757 ha->optrom_size = OPTROM_SIZE_25XX;
1758 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
1759 ha->isp_ops = &qla25xx_isp_ops;
1760 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1761 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1762 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1763 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
1764 } else if (IS_QLA81XX(ha)) {
1765 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1766 req_length = REQUEST_ENTRY_CNT_24XX;
1767 rsp_length = RESPONSE_ENTRY_CNT_2300;
1768 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1769 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
1770 ha->gid_list_info_size = 8;
1771 ha->optrom_size = OPTROM_SIZE_81XX;
1772 ha->isp_ops = &qla81xx_isp_ops;
1773 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
1774 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
1775 ha->nvram_conf_off = ~0;
1776 ha->nvram_data_off = ~0;
1779 mutex_init(&ha->vport_lock);
1780 init_completion(&ha->mbx_cmd_comp);
1781 complete(&ha->mbx_cmd_comp);
1782 init_completion(&ha->mbx_intr_comp);
1784 set_bit(0, (unsigned long *) ha->vp_idx_map);
1786 qla2x00_config_dma_addressing(ha);
1787 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
1789 qla_printk(KERN_WARNING, ha,
1790 "[ERROR] Failed to allocate memory for adapter\n");
1792 goto probe_hw_failed;
1795 req->max_q_depth = MAX_Q_DEPTH;
1796 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
1797 req->max_q_depth = ql2xmaxqdepth;
1800 base_vha = qla2x00_create_host(sht, ha);
1802 qla_printk(KERN_WARNING, ha,
1803 "[ERROR] Failed to allocate memory for scsi_host\n");
1806 qla2x00_mem_free(ha);
1807 qla2x00_free_req_que(ha, req);
1808 qla2x00_free_rsp_que(ha, rsp);
1809 goto probe_hw_failed;
1812 pci_set_drvdata(pdev, base_vha);
1814 host = base_vha->host;
1815 base_vha->req = req;
1816 host->can_queue = req->length + 128;
1817 if (IS_QLA2XXX_MIDTYPE(ha))
1818 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
1820 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
1823 host->sg_tablesize = 32;
1824 host->max_id = max_id;
1825 host->this_id = 255;
1826 host->cmd_per_lun = 3;
1827 host->unique_id = host->host_no;
1828 host->max_cmd_len = MAX_CMDSZ;
1829 host->max_channel = MAX_BUSES - 1;
1830 host->max_lun = MAX_LUNS;
1831 host->transportt = qla2xxx_transport_template;
1833 /* Set up the irqs */
1834 ret = qla2x00_request_irqs(ha, rsp);
1836 goto probe_init_failed;
1837 /* Alloc arrays of request and response ring ptrs */
1838 if (!qla2x00_alloc_queues(ha)) {
1839 qla_printk(KERN_WARNING, ha,
1840 "[ERROR] Failed to allocate memory for queue"
1842 goto probe_init_failed;
1844 ha->rsp_q_map[0] = rsp;
1845 ha->req_q_map[0] = req;
1848 set_bit(0, ha->req_qid_map);
1849 set_bit(0, ha->rsp_qid_map);
1850 /* FWI2-capable only. */
1851 req->req_q_in = &ha->iobase->isp24.req_q_in;
1852 req->req_q_out = &ha->iobase->isp24.req_q_out;
1853 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
1854 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
1856 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
1857 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
1858 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
1859 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
1862 if (qla2x00_initialize_adapter(base_vha)) {
1863 qla_printk(KERN_WARNING, ha,
1864 "Failed to initialize adapter\n");
1866 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1867 "Adapter flags %x.\n",
1868 base_vha->host_no, base_vha->device_flags));
1875 * Startup the kernel thread for this host adapter
1877 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
1878 "%s_dpc", base_vha->host_str);
1879 if (IS_ERR(ha->dpc_thread)) {
1880 qla_printk(KERN_WARNING, ha,
1881 "Unable to start DPC thread!\n");
1882 ret = PTR_ERR(ha->dpc_thread);
1886 list_add_tail(&base_vha->list, &ha->vp_list);
1887 base_vha->host->irq = ha->pdev->irq;
1889 /* Initialized the timer */
1890 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
1892 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1893 base_vha->host_no, ha));
1895 base_vha->flags.init_done = 1;
1896 base_vha->flags.online = 1;
1898 ret = scsi_add_host(host, &pdev->dev);
1902 ha->isp_ops->enable_intrs(ha);
1904 scsi_scan_host(host);
1906 qla2x00_alloc_sysfs_attr(base_vha);
1908 qla2x00_init_host_attr(base_vha);
1910 qla2x00_dfs_setup(base_vha);
1912 qla_printk(KERN_INFO, ha, "\n"
1913 " QLogic Fibre Channel HBA Driver: %s\n"
1915 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
1916 qla2x00_version_str, ha->model_number,
1917 ha->model_desc ? ha->model_desc : "", pdev->device,
1918 ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
1919 ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
1920 ha->isp_ops->fw_version_str(base_vha, fw_str));
1925 qla2x00_free_req_que(ha, req);
1926 qla2x00_free_rsp_que(ha, rsp);
1927 ha->max_req_queues = ha->max_rsp_queues = 0;
1930 if (base_vha->timer_active)
1931 qla2x00_stop_timer(base_vha);
1932 base_vha->flags.online = 0;
1933 if (ha->dpc_thread) {
1934 struct task_struct *t = ha->dpc_thread;
1936 ha->dpc_thread = NULL;
1940 qla2x00_free_device(base_vha);
1942 scsi_host_put(base_vha->host);
1946 iounmap(ha->iobase);
1948 pci_release_selected_regions(ha->pdev, ha->bars);
1953 pci_disable_device(pdev);
1958 qla2x00_remove_one(struct pci_dev *pdev)
1960 scsi_qla_host_t *base_vha, *vha, *temp;
1961 struct qla_hw_data *ha;
1963 base_vha = pci_get_drvdata(pdev);
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);
1971 set_bit(UNLOADING, &base_vha->dpc_flags);
1973 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
1975 qla2x00_dfs_remove(base_vha);
1977 qla84xx_put_chip(base_vha);
1980 if (base_vha->timer_active)
1981 qla2x00_stop_timer(base_vha);
1983 base_vha->flags.online = 0;
1985 /* Kill the kernel thread for this host */
1986 if (ha->dpc_thread) {
1987 struct task_struct *t = ha->dpc_thread;
1990 * qla2xxx_wake_dpc checks for ->dpc_thread
1991 * so we need to zero it out.
1993 ha->dpc_thread = NULL;
1997 qla2x00_free_sysfs_attr(base_vha);
1999 fc_remove_host(base_vha->host);
2001 scsi_remove_host(base_vha->host);
2003 qla2x00_free_device(base_vha);
2005 scsi_host_put(base_vha->host);
2008 iounmap(ha->iobase);
2011 iounmap(ha->mqiobase);
2013 pci_release_selected_regions(ha->pdev, ha->bars);
2017 pci_disable_device(pdev);
2018 pci_set_drvdata(pdev, NULL);
2022 qla2x00_free_device(scsi_qla_host_t *vha)
2024 struct qla_hw_data *ha = vha->hw;
2026 qla25xx_delete_queues(vha);
2028 if (ha->flags.fce_enabled)
2029 qla2x00_disable_fce_trace(vha, NULL, NULL);
2032 qla2x00_disable_eft_trace(vha);
2034 /* Stop currently executing firmware. */
2035 qla2x00_try_to_stop_firmware(vha);
2037 /* turn-off interrupts on the card */
2038 if (ha->interrupts_on)
2039 ha->isp_ops->disable_intrs(ha);
2041 qla2x00_free_irqs(vha);
2043 qla2x00_mem_free(ha);
2045 qla2x00_free_queues(ha);
2049 qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
2052 struct fc_rport *rport;
2057 rport = fcport->rport;
2059 spin_lock_irq(vha->host->host_lock);
2060 fcport->drport = rport;
2061 spin_unlock_irq(vha->host->host_lock);
2062 set_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
2063 qla2xxx_wake_dpc(vha);
2065 fc_remote_port_delete(rport);
2069 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2071 * Input: ha = adapter block pointer. fcport = port structure pointer.
2077 void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
2078 int do_login, int defer)
2080 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2081 vha->vp_idx == fcport->vp_idx) {
2082 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2083 qla2x00_schedule_rport_del(vha, fcport, defer);
2086 * We may need to retry the login, so don't change the state of the
2087 * port but do the retries.
2089 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2090 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2095 if (fcport->login_retry == 0) {
2096 fcport->login_retry = vha->hw->login_retry_count;
2097 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2099 DEBUG(printk("scsi(%ld): Port login retry: "
2100 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2101 "id = 0x%04x retry cnt=%d\n",
2103 fcport->port_name[0],
2104 fcport->port_name[1],
2105 fcport->port_name[2],
2106 fcport->port_name[3],
2107 fcport->port_name[4],
2108 fcport->port_name[5],
2109 fcport->port_name[6],
2110 fcport->port_name[7],
2112 fcport->login_retry));
2117 * qla2x00_mark_all_devices_lost
2118 * Updates fcport state when device goes offline.
2121 * ha = adapter block pointer.
2122 * fcport = port structure pointer.
2130 qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
2134 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2135 if (vha->vp_idx != fcport->vp_idx)
2138 * No point in marking the device as lost, if the device is
2141 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2143 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2144 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2145 qla2x00_schedule_rport_del(vha, fcport, defer);
2147 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2153 * Allocates adapter memory.
2160 qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2161 struct req_que **req, struct rsp_que **rsp)
2165 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
2166 &ha->init_cb_dma, GFP_KERNEL);
2170 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2171 &ha->gid_list_dma, GFP_KERNEL);
2173 goto fail_free_init_cb;
2175 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2176 if (!ha->srb_mempool)
2177 goto fail_free_gid_list;
2179 /* Get memory for cached NVRAM */
2180 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2182 goto fail_free_srb_mempool;
2184 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2186 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2187 DMA_POOL_SIZE, 8, 0);
2188 if (!ha->s_dma_pool)
2189 goto fail_free_nvram;
2191 /* Allocate memory for SNS commands */
2192 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2193 /* Get consistent memory allocated for SNS commands */
2194 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
2195 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
2199 /* Get consistent memory allocated for MS IOCB */
2200 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2204 /* Get consistent memory allocated for CT SNS commands */
2205 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
2206 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
2208 goto fail_free_ms_iocb;
2211 /* Allocate memory for request ring */
2212 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2214 DEBUG(printk("Unable to allocate memory for req\n"));
2217 (*req)->length = req_len;
2218 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2219 ((*req)->length + 1) * sizeof(request_t),
2220 &(*req)->dma, GFP_KERNEL);
2221 if (!(*req)->ring) {
2222 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2225 /* Allocate memory for response ring */
2226 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2228 qla_printk(KERN_WARNING, ha,
2229 "Unable to allocate memory for rsp\n");
2233 (*rsp)->length = rsp_len;
2234 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2235 ((*rsp)->length + 1) * sizeof(response_t),
2236 &(*rsp)->dma, GFP_KERNEL);
2237 if (!(*rsp)->ring) {
2238 qla_printk(KERN_WARNING, ha,
2239 "Unable to allocate memory for rsp_ring\n");
2244 /* Allocate memory for NVRAM data for vports */
2245 if (ha->nvram_npiv_size) {
2246 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
2247 ha->nvram_npiv_size, GFP_KERNEL);
2248 if (!ha->npiv_info) {
2249 qla_printk(KERN_WARNING, ha,
2250 "Unable to allocate memory for npiv info\n");
2251 goto fail_npiv_info;
2254 ha->npiv_info = NULL;
2256 /* Get consistent memory allocated for EX-INIT-CB. */
2257 if (IS_QLA81XX(ha)) {
2258 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2259 &ha->ex_init_cb_dma);
2260 if (!ha->ex_init_cb)
2261 goto fail_ex_init_cb;
2264 INIT_LIST_HEAD(&ha->vp_list);
2268 kfree(ha->npiv_info);
2270 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2271 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2272 (*rsp)->ring = NULL;
2277 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2278 sizeof(request_t), (*req)->ring, (*req)->dma);
2279 (*req)->ring = NULL;
2284 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2285 ha->ct_sns, ha->ct_sns_dma);
2289 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2291 ha->ms_iocb_dma = 0;
2293 dma_pool_destroy(ha->s_dma_pool);
2294 ha->s_dma_pool = NULL;
2298 fail_free_srb_mempool:
2299 mempool_destroy(ha->srb_mempool);
2300 ha->srb_mempool = NULL;
2302 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2304 ha->gid_list = NULL;
2305 ha->gid_list_dma = 0;
2307 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2310 ha->init_cb_dma = 0;
2312 DEBUG(printk("%s: Memory allocation failure\n", __func__));
2318 * Frees all adapter allocated memory.
2321 * ha = adapter block pointer.
2324 qla2x00_mem_free(struct qla_hw_data *ha)
2326 if (ha->srb_mempool)
2327 mempool_destroy(ha->srb_mempool);
2330 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
2335 dma_free_coherent(&ha->pdev->dev,
2336 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
2341 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
2342 ha->sns_cmd, ha->sns_cmd_dma);
2345 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2346 ha->ct_sns, ha->ct_sns_dma);
2349 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2352 dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
2355 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2358 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
2361 dma_pool_destroy(ha->s_dma_pool);
2364 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2368 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2369 ha->init_cb, ha->init_cb_dma);
2370 vfree(ha->optrom_buffer);
2372 kfree(ha->npiv_info);
2374 ha->srb_mempool = NULL;
2378 ha->sns_cmd_dma = 0;
2382 ha->ms_iocb_dma = 0;
2384 ha->init_cb_dma = 0;
2385 ha->ex_init_cb = NULL;
2386 ha->ex_init_cb_dma = 0;
2388 ha->s_dma_pool = NULL;
2390 ha->gid_list = NULL;
2391 ha->gid_list_dma = 0;
2395 ha->fw_dump_reading = 0;
2398 struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
2399 struct qla_hw_data *ha)
2401 struct Scsi_Host *host;
2402 struct scsi_qla_host *vha = NULL;
2404 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
2407 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2411 /* Clear our data area */
2412 vha = shost_priv(host);
2413 memset(vha, 0, sizeof(scsi_qla_host_t));
2416 vha->host_no = host->host_no;
2419 INIT_LIST_HEAD(&vha->vp_fcports);
2420 INIT_LIST_HEAD(&vha->work_list);
2421 INIT_LIST_HEAD(&vha->list);
2423 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
2430 static struct qla_work_evt *
2431 qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type,
2434 struct qla_work_evt *e;
2436 e = kzalloc(sizeof(struct qla_work_evt), locked ? GFP_ATOMIC:
2441 INIT_LIST_HEAD(&e->list);
2443 e->flags = QLA_EVT_FLAG_FREE;
2448 qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e, int locked)
2450 unsigned long uninitialized_var(flags);
2451 struct qla_hw_data *ha = vha->hw;
2454 spin_lock_irqsave(&ha->hardware_lock, flags);
2455 list_add_tail(&e->list, &vha->work_list);
2456 qla2xxx_wake_dpc(vha);
2458 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2463 qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
2466 struct qla_work_evt *e;
2468 e = qla2x00_alloc_work(vha, QLA_EVT_AEN, 1);
2470 return QLA_FUNCTION_FAILED;
2472 e->u.aen.code = code;
2473 e->u.aen.data = data;
2474 return qla2x00_post_work(vha, e, 1);
2478 qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
2480 struct qla_work_evt *e;
2482 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK, 1);
2484 return QLA_FUNCTION_FAILED;
2486 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
2487 return qla2x00_post_work(vha, e, 1);
2491 qla2x00_do_work(struct scsi_qla_host *vha)
2493 struct qla_work_evt *e;
2494 struct qla_hw_data *ha = vha->hw;
2496 spin_lock_irq(&ha->hardware_lock);
2497 while (!list_empty(&vha->work_list)) {
2498 e = list_entry(vha->work_list.next, struct qla_work_evt, list);
2499 list_del_init(&e->list);
2500 spin_unlock_irq(&ha->hardware_lock);
2504 fc_host_post_event(vha->host, fc_get_event_number(),
2505 e->u.aen.code, e->u.aen.data);
2507 case QLA_EVT_IDC_ACK:
2508 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
2511 if (e->flags & QLA_EVT_FLAG_FREE)
2513 spin_lock_irq(&ha->hardware_lock);
2515 spin_unlock_irq(&ha->hardware_lock);
2517 /* Relogins all the fcports of a vport
2518 * Context: dpc thread
2520 void qla2x00_relogin(struct scsi_qla_host *vha)
2524 uint16_t next_loopid = 0;
2525 struct qla_hw_data *ha = vha->hw;
2527 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2529 * If the port is not ONLINE then try to login
2530 * to it if we haven't run out of retries.
2532 if (atomic_read(&fcport->state) !=
2533 FCS_ONLINE && fcport->login_retry) {
2535 if (fcport->flags & FCF_FABRIC_DEVICE) {
2536 if (fcport->flags & FCF_TAPE_PRESENT)
2537 ha->isp_ops->fabric_logout(vha,
2539 fcport->d_id.b.domain,
2540 fcport->d_id.b.area,
2541 fcport->d_id.b.al_pa);
2543 status = qla2x00_fabric_login(vha, fcport,
2546 status = qla2x00_local_device_login(vha,
2549 fcport->login_retry--;
2550 if (status == QLA_SUCCESS) {
2551 fcport->old_loop_id = fcport->loop_id;
2553 DEBUG(printk("scsi(%ld): port login OK: logged "
2554 "in ID 0x%x\n", vha->host_no, fcport->loop_id));
2556 qla2x00_update_fcport(vha, fcport);
2558 } else if (status == 1) {
2559 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2560 /* retry the login again */
2561 DEBUG(printk("scsi(%ld): Retrying"
2562 " %d login again loop_id 0x%x\n",
2563 vha->host_no, fcport->login_retry,
2566 fcport->login_retry = 0;
2569 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
2570 fcport->loop_id = FC_NO_LOOP_ID;
2572 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2577 /**************************************************************************
2579 * This kernel thread is a task that is schedule by the interrupt handler
2580 * to perform the background processing for interrupts.
2583 * This task always run in the context of a kernel thread. It
2584 * is kick-off by the driver's detect code and starts up
2585 * up one per adapter. It immediately goes to sleep and waits for
2586 * some fibre event. When either the interrupt handler or
2587 * the timer routine detects a event it will one of the task
2588 * bits then wake us up.
2589 **************************************************************************/
2591 qla2x00_do_dpc(void *data)
2594 scsi_qla_host_t *base_vha;
2595 struct qla_hw_data *ha;
2597 ha = (struct qla_hw_data *)data;
2598 base_vha = pci_get_drvdata(ha->pdev);
2600 set_user_nice(current, -20);
2602 while (!kthread_should_stop()) {
2603 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2605 set_current_state(TASK_INTERRUPTIBLE);
2607 __set_current_state(TASK_RUNNING);
2609 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2611 /* Initialization not yet finished. Don't do anything yet. */
2612 if (!base_vha->flags.init_done)
2615 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
2619 if (ha->flags.mbox_busy) {
2624 qla2x00_do_work(base_vha);
2626 if (test_and_clear_bit(ISP_ABORT_NEEDED,
2627 &base_vha->dpc_flags)) {
2629 DEBUG(printk("scsi(%ld): dpc: sched "
2630 "qla2x00_abort_isp ha = %p\n",
2631 base_vha->host_no, ha));
2632 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2633 &base_vha->dpc_flags))) {
2635 if (qla2x00_abort_isp(base_vha)) {
2636 /* failed. retry later */
2637 set_bit(ISP_ABORT_NEEDED,
2638 &base_vha->dpc_flags);
2640 clear_bit(ABORT_ISP_ACTIVE,
2641 &base_vha->dpc_flags);
2644 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2645 base_vha->host_no));
2648 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
2649 qla2x00_update_fcports(base_vha);
2650 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2653 if (test_and_clear_bit(RESET_MARKER_NEEDED,
2654 &base_vha->dpc_flags) &&
2655 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
2657 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2658 base_vha->host_no));
2660 qla2x00_rst_aen(base_vha);
2661 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
2664 /* Retry each device up to login retry count */
2665 if ((test_and_clear_bit(RELOGIN_NEEDED,
2666 &base_vha->dpc_flags)) &&
2667 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
2668 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
2670 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2671 base_vha->host_no));
2672 qla2x00_relogin(base_vha);
2674 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2675 base_vha->host_no));
2678 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
2679 &base_vha->dpc_flags)) {
2681 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2682 base_vha->host_no));
2684 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2685 &base_vha->dpc_flags))) {
2687 rval = qla2x00_loop_resync(base_vha);
2689 clear_bit(LOOP_RESYNC_ACTIVE,
2690 &base_vha->dpc_flags);
2693 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2694 base_vha->host_no));
2697 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
2698 atomic_read(&base_vha->loop_state) == LOOP_READY) {
2699 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
2700 qla2xxx_flash_npiv_conf(base_vha);
2703 if (!ha->interrupts_on)
2704 ha->isp_ops->enable_intrs(ha);
2706 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
2707 &base_vha->dpc_flags))
2708 ha->isp_ops->beacon_blink(base_vha);
2710 qla2x00_do_dpc_all_vps(base_vha);
2713 } /* End of while(1) */
2715 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
2718 * Make sure that nobody tries to wake us up again.
2726 qla2xxx_wake_dpc(struct scsi_qla_host *vha)
2728 struct qla_hw_data *ha = vha->hw;
2729 struct task_struct *t = ha->dpc_thread;
2731 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
2737 * Processes asynchronous reset.
2740 * ha = adapter block pointer.
2743 qla2x00_rst_aen(scsi_qla_host_t *vha)
2745 if (vha->flags.online && !vha->flags.reset_active &&
2746 !atomic_read(&vha->loop_down_timer) &&
2747 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
2749 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
2752 * Issue marker command only when we are going to start
2755 vha->marker_needed = 1;
2756 } while (!atomic_read(&vha->loop_down_timer) &&
2757 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
2762 qla2x00_sp_free_dma(srb_t *sp)
2764 struct scsi_cmnd *cmd = sp->cmd;
2766 if (sp->flags & SRB_DMA_VALID) {
2767 scsi_dma_unmap(cmd);
2768 sp->flags &= ~SRB_DMA_VALID;
2774 qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
2776 struct scsi_cmnd *cmd = sp->cmd;
2778 qla2x00_sp_free_dma(sp);
2780 mempool_free(sp, ha->srb_mempool);
2782 cmd->scsi_done(cmd);
2785 /**************************************************************************
2791 * Context: Interrupt
2792 ***************************************************************************/
2794 qla2x00_timer(scsi_qla_host_t *vha)
2796 unsigned long cpu_flags = 0;
2802 struct qla_hw_data *ha = vha->hw;
2803 struct req_que *req;
2805 * Ports - Port down timer.
2807 * Whenever, a port is in the LOST state we start decrementing its port
2808 * down timer every second until it reaches zero. Once it reaches zero
2809 * the port it marked DEAD.
2812 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2813 if (fcport->port_type != FCT_TARGET)
2816 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2818 if (atomic_read(&fcport->port_down_timer) == 0)
2821 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
2822 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
2824 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
2827 t, atomic_read(&fcport->port_down_timer)));
2830 } /* End of for fcport */
2833 /* Loop down handler. */
2834 if (atomic_read(&vha->loop_down_timer) > 0 &&
2835 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
2836 && vha->flags.online) {
2838 if (atomic_read(&vha->loop_down_timer) ==
2839 vha->loop_down_abort_time) {
2841 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2842 "queues before time expire\n",
2845 if (!IS_QLA2100(ha) && vha->link_down_timeout)
2846 atomic_set(&vha->loop_state, LOOP_DEAD);
2848 /* Schedule an ISP abort to return any tape commands. */
2849 /* NPIV - scan physical port only */
2851 spin_lock_irqsave(&ha->hardware_lock,
2853 req = ha->req_q_map[0];
2855 index < MAX_OUTSTANDING_COMMANDS;
2859 sp = req->outstanding_cmds[index];
2863 if (!(sfcp->flags & FCF_TAPE_PRESENT))
2866 set_bit(ISP_ABORT_NEEDED,
2870 spin_unlock_irqrestore(&ha->hardware_lock,
2876 /* if the loop has been down for 4 minutes, reinit adapter */
2877 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
2878 if (!(vha->device_flags & DFLG_NO_CABLE) &&
2880 DEBUG(printk("scsi(%ld): Loop down - "
2883 qla_printk(KERN_WARNING, ha,
2884 "Loop down - aborting ISP.\n");
2886 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2889 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
2891 atomic_read(&vha->loop_down_timer)));
2894 /* Check if beacon LED needs to be blinked */
2895 if (ha->beacon_blink_led == 1) {
2896 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
2900 /* Process any deferred work. */
2901 if (!list_empty(&vha->work_list))
2904 /* Schedule the DPC routine if needed */
2905 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
2906 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
2907 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
2909 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
2910 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
2911 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
2912 test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
2913 qla2xxx_wake_dpc(vha);
2915 qla2x00_restart_timer(vha, WATCH_INTERVAL);
2918 /* Firmware interface routines. */
2921 #define FW_ISP21XX 0
2922 #define FW_ISP22XX 1
2923 #define FW_ISP2300 2
2924 #define FW_ISP2322 3
2925 #define FW_ISP24XX 4
2926 #define FW_ISP25XX 5
2927 #define FW_ISP81XX 6
2929 #define FW_FILE_ISP21XX "ql2100_fw.bin"
2930 #define FW_FILE_ISP22XX "ql2200_fw.bin"
2931 #define FW_FILE_ISP2300 "ql2300_fw.bin"
2932 #define FW_FILE_ISP2322 "ql2322_fw.bin"
2933 #define FW_FILE_ISP24XX "ql2400_fw.bin"
2934 #define FW_FILE_ISP25XX "ql2500_fw.bin"
2935 #define FW_FILE_ISP81XX "ql8100_fw.bin"
2937 static DEFINE_MUTEX(qla_fw_lock);
2939 static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
2940 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
2941 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
2942 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
2943 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
2944 { .name = FW_FILE_ISP24XX, },
2945 { .name = FW_FILE_ISP25XX, },
2946 { .name = FW_FILE_ISP81XX, },
2950 qla2x00_request_firmware(scsi_qla_host_t *vha)
2952 struct qla_hw_data *ha = vha->hw;
2953 struct fw_blob *blob;
2956 if (IS_QLA2100(ha)) {
2957 blob = &qla_fw_blobs[FW_ISP21XX];
2958 } else if (IS_QLA2200(ha)) {
2959 blob = &qla_fw_blobs[FW_ISP22XX];
2960 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
2961 blob = &qla_fw_blobs[FW_ISP2300];
2962 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
2963 blob = &qla_fw_blobs[FW_ISP2322];
2964 } else if (IS_QLA24XX_TYPE(ha)) {
2965 blob = &qla_fw_blobs[FW_ISP24XX];
2966 } else if (IS_QLA25XX(ha)) {
2967 blob = &qla_fw_blobs[FW_ISP25XX];
2968 } else if (IS_QLA81XX(ha)) {
2969 blob = &qla_fw_blobs[FW_ISP81XX];
2972 mutex_lock(&qla_fw_lock);
2976 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
2977 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
2978 "(%s).\n", vha->host_no, blob->name));
2985 mutex_unlock(&qla_fw_lock);
2990 qla2x00_release_firmware(void)
2994 mutex_lock(&qla_fw_lock);
2995 for (idx = 0; idx < FW_BLOBS; idx++)
2996 if (qla_fw_blobs[idx].fw)
2997 release_firmware(qla_fw_blobs[idx].fw);
2998 mutex_unlock(&qla_fw_lock);
3001 static pci_ers_result_t
3002 qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3004 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3007 case pci_channel_io_normal:
3008 return PCI_ERS_RESULT_CAN_RECOVER;
3009 case pci_channel_io_frozen:
3010 pci_disable_device(pdev);
3011 return PCI_ERS_RESULT_NEED_RESET;
3012 case pci_channel_io_perm_failure:
3013 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3014 return PCI_ERS_RESULT_DISCONNECT;
3016 return PCI_ERS_RESULT_NEED_RESET;
3019 static pci_ers_result_t
3020 qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
3022 int risc_paused = 0;
3024 unsigned long flags;
3025 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3026 struct qla_hw_data *ha = base_vha->hw;
3027 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3028 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
3030 spin_lock_irqsave(&ha->hardware_lock, flags);
3031 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
3032 stat = RD_REG_DWORD(®->hccr);
3033 if (stat & HCCR_RISC_PAUSE)
3035 } else if (IS_QLA23XX(ha)) {
3036 stat = RD_REG_DWORD(®->u.isp2300.host_status);
3037 if (stat & HSR_RISC_PAUSED)
3039 } else if (IS_FWI2_CAPABLE(ha)) {
3040 stat = RD_REG_DWORD(®24->host_status);
3041 if (stat & HSRX_RISC_PAUSED)
3044 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3047 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
3048 "Dumping firmware!\n");
3049 ha->isp_ops->fw_dump(base_vha, 0);
3051 return PCI_ERS_RESULT_NEED_RESET;
3053 return PCI_ERS_RESULT_RECOVERED;
3056 static pci_ers_result_t
3057 qla2xxx_pci_slot_reset(struct pci_dev *pdev)
3059 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
3060 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3061 struct qla_hw_data *ha = base_vha->hw;
3065 rc = pci_enable_device_mem(pdev);
3067 rc = pci_enable_device(pdev);
3070 qla_printk(KERN_WARNING, ha,
3071 "Can't re-enable PCI device after reset.\n");
3075 pci_set_master(pdev);
3077 if (ha->isp_ops->pci_config(base_vha))
3080 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3081 if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
3082 ret = PCI_ERS_RESULT_RECOVERED;
3083 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3089 qla2xxx_pci_resume(struct pci_dev *pdev)
3091 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3092 struct qla_hw_data *ha = base_vha->hw;
3095 ret = qla2x00_wait_for_hba_online(base_vha);
3096 if (ret != QLA_SUCCESS) {
3097 qla_printk(KERN_ERR, ha,
3098 "the device failed to resume I/O "
3099 "from slot/link_reset");
3101 pci_cleanup_aer_uncorrect_error_status(pdev);
3104 static struct pci_error_handlers qla2xxx_err_handler = {
3105 .error_detected = qla2xxx_pci_error_detected,
3106 .mmio_enabled = qla2xxx_pci_mmio_enabled,
3107 .slot_reset = qla2xxx_pci_slot_reset,
3108 .resume = qla2xxx_pci_resume,
3111 static struct pci_device_id qla2xxx_pci_tbl[] = {
3112 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
3113 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
3114 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
3115 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
3116 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
3117 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
3118 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
3119 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
3120 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
3121 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
3122 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
3123 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
3124 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
3125 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
3128 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
3130 static struct pci_driver qla2xxx_pci_driver = {
3131 .name = QLA2XXX_DRIVER_NAME,
3133 .owner = THIS_MODULE,
3135 .id_table = qla2xxx_pci_tbl,
3136 .probe = qla2x00_probe_one,
3137 .remove = qla2x00_remove_one,
3138 .err_handler = &qla2xxx_err_handler,
3142 * qla2x00_module_init - Module initialization.
3145 qla2x00_module_init(void)
3149 /* Allocate cache for SRBs. */
3150 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
3151 SLAB_HWCACHE_ALIGN, NULL);
3152 if (srb_cachep == NULL) {
3154 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3158 /* Derive version string. */
3159 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
3160 if (ql2xextended_error_logging)
3161 strcat(qla2x00_version_str, "-debug");
3163 qla2xxx_transport_template =
3164 fc_attach_transport(&qla2xxx_transport_functions);
3165 if (!qla2xxx_transport_template) {
3166 kmem_cache_destroy(srb_cachep);
3169 qla2xxx_transport_vport_template =
3170 fc_attach_transport(&qla2xxx_transport_vport_functions);
3171 if (!qla2xxx_transport_vport_template) {
3172 kmem_cache_destroy(srb_cachep);
3173 fc_release_transport(qla2xxx_transport_template);
3177 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
3178 qla2x00_version_str);
3179 ret = pci_register_driver(&qla2xxx_pci_driver);
3181 kmem_cache_destroy(srb_cachep);
3182 fc_release_transport(qla2xxx_transport_template);
3183 fc_release_transport(qla2xxx_transport_vport_template);
3189 * qla2x00_module_exit - Module cleanup.
3192 qla2x00_module_exit(void)
3194 pci_unregister_driver(&qla2xxx_pci_driver);
3195 qla2x00_release_firmware();
3196 kmem_cache_destroy(srb_cachep);
3197 fc_release_transport(qla2xxx_transport_template);
3198 fc_release_transport(qla2xxx_transport_vport_template);
3201 module_init(qla2x00_module_init);
3202 module_exit(qla2x00_module_exit);
3204 MODULE_AUTHOR("QLogic Corporation");
3205 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3206 MODULE_LICENSE("GPL");
3207 MODULE_VERSION(QLA2XXX_VERSION);
3208 MODULE_FIRMWARE(FW_FILE_ISP21XX);
3209 MODULE_FIRMWARE(FW_FILE_ISP22XX);
3210 MODULE_FIRMWARE(FW_FILE_ISP2300);
3211 MODULE_FIRMWARE(FW_FILE_ISP2322);
3212 MODULE_FIRMWARE(FW_FILE_ISP24XX);
3213 MODULE_FIRMWARE(FW_FILE_ISP25XX);
3214 MODULE_FIRMWARE(FW_FILE_ISP81XX);