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>
14 #include <linux/kobject.h>
16 #include <scsi/scsi_tcq.h>
17 #include <scsi/scsicam.h>
18 #include <scsi/scsi_transport.h>
19 #include <scsi/scsi_transport_fc.h>
24 char qla2x00_version_str[40];
27 * SRB allocation cache
29 static struct kmem_cache *srb_cachep;
31 int ql2xlogintimeout = 20;
32 module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
33 MODULE_PARM_DESC(ql2xlogintimeout,
34 "Login timeout value in seconds.");
36 int qlport_down_retry;
37 module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
38 MODULE_PARM_DESC(qlport_down_retry,
39 "Maximum number of command retries to a port that returns "
40 "a PORT-DOWN status.");
42 int ql2xplogiabsentdevice;
43 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
44 MODULE_PARM_DESC(ql2xplogiabsentdevice,
45 "Option to enable PLOGI to devices that are not present after "
46 "a Fabric scan. This is needed for several broken switches. "
47 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
49 int ql2xloginretrycount = 0;
50 module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
51 MODULE_PARM_DESC(ql2xloginretrycount,
52 "Specify an alternate value for the NVRAM login retry count.");
54 int ql2xallocfwdump = 1;
55 module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR);
56 MODULE_PARM_DESC(ql2xallocfwdump,
57 "Option to enable allocation of memory for a firmware dump "
58 "during HBA initialization. Memory allocation requirements "
59 "vary by ISP type. Default is 1 - allocate memory.");
61 int ql2xextended_error_logging;
62 module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
63 MODULE_PARM_DESC(ql2xextended_error_logging,
64 "Option to enable extended error logging, "
65 "Default is 0 - no logging. 1 - log errors.");
67 static void qla2x00_free_device(scsi_qla_host_t *);
70 module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
71 MODULE_PARM_DESC(ql2xfdmienable,
72 "Enables FDMI registratons "
73 "Default is 0 - no FDMI. 1 - perfom FDMI.");
75 #define MAX_Q_DEPTH 32
76 static int ql2xmaxqdepth = MAX_Q_DEPTH;
77 module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
78 MODULE_PARM_DESC(ql2xmaxqdepth,
79 "Maximum queue depth to report for target devices.");
81 int ql2xqfulltracking = 1;
82 module_param(ql2xqfulltracking, int, S_IRUGO|S_IWUSR);
83 MODULE_PARM_DESC(ql2xqfulltracking,
84 "Controls whether the driver tracks queue full status "
85 "returns and dynamically adjusts a scsi device's queue "
86 "depth. Default is 1, perform tracking. Set to 0 to "
87 "disable dynamic tracking and adjustment of queue depth.");
89 int ql2xqfullrampup = 120;
90 module_param(ql2xqfullrampup, int, S_IRUGO|S_IWUSR);
91 MODULE_PARM_DESC(ql2xqfullrampup,
92 "Number of seconds to wait to begin to ramp-up the queue "
93 "depth for a device after a queue-full condition has been "
94 "detected. Default is 120 seconds.");
96 int ql2xiidmaenable=1;
97 module_param(ql2xiidmaenable, int, S_IRUGO|S_IRUSR);
98 MODULE_PARM_DESC(ql2xiidmaenable,
99 "Enables iIDMA settings "
100 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
102 int ql2xmaxqueues = 1;
103 module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR);
104 MODULE_PARM_DESC(ql2xmaxqueues,
105 "Enables MQ settings "
106 "Default is 1 for single queue. Set it to number \
107 of queues in MQ mode.");
109 int ql2xmultique_tag;
110 module_param(ql2xmultique_tag, int, S_IRUGO|S_IRUSR);
111 MODULE_PARM_DESC(ql2xmultique_tag,
112 "Enables CPU affinity settings for the driver "
113 "Default is 0 for no affinity of request and response IO. "
114 "Set it to 1 to turn on the cpu affinity.");
117 module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR);
118 MODULE_PARM_DESC(ql2xfwloadbin,
119 "Option to specify location from which to load ISP firmware:\n"
120 " 2 -- load firmware via the request_firmware() (hotplug)\n"
122 " 1 -- load firmware from flash.\n"
123 " 0 -- use default semantics.\n");
126 * SCSI host template entry points
128 static int qla2xxx_slave_configure(struct scsi_device * device);
129 static int qla2xxx_slave_alloc(struct scsi_device *);
130 static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
131 static void qla2xxx_scan_start(struct Scsi_Host *);
132 static void qla2xxx_slave_destroy(struct scsi_device *);
133 static int qla2xxx_queuecommand(struct scsi_cmnd *cmd,
134 void (*fn)(struct scsi_cmnd *));
135 static int qla2xxx_eh_abort(struct scsi_cmnd *);
136 static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
137 static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
138 static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
139 static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
141 static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
142 static int qla2x00_change_queue_type(struct scsi_device *, int);
144 struct scsi_host_template qla2xxx_driver_template = {
145 .module = THIS_MODULE,
146 .name = QLA2XXX_DRIVER_NAME,
147 .queuecommand = qla2xxx_queuecommand,
149 .eh_abort_handler = qla2xxx_eh_abort,
150 .eh_device_reset_handler = qla2xxx_eh_device_reset,
151 .eh_target_reset_handler = qla2xxx_eh_target_reset,
152 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
153 .eh_host_reset_handler = qla2xxx_eh_host_reset,
155 .slave_configure = qla2xxx_slave_configure,
157 .slave_alloc = qla2xxx_slave_alloc,
158 .slave_destroy = qla2xxx_slave_destroy,
159 .scan_finished = qla2xxx_scan_finished,
160 .scan_start = qla2xxx_scan_start,
161 .change_queue_depth = qla2x00_change_queue_depth,
162 .change_queue_type = qla2x00_change_queue_type,
165 .use_clustering = ENABLE_CLUSTERING,
166 .sg_tablesize = SG_ALL,
168 .max_sectors = 0xFFFF,
169 .shost_attrs = qla2x00_host_attrs,
172 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
173 struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
175 /* TODO Convert to inlines
181 qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
183 init_timer(&vha->timer);
184 vha->timer.expires = jiffies + interval * HZ;
185 vha->timer.data = (unsigned long)vha;
186 vha->timer.function = (void (*)(unsigned long))func;
187 add_timer(&vha->timer);
188 vha->timer_active = 1;
192 qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
194 mod_timer(&vha->timer, jiffies + interval * HZ);
197 static __inline__ void
198 qla2x00_stop_timer(scsi_qla_host_t *vha)
200 del_timer_sync(&vha->timer);
201 vha->timer_active = 0;
204 static int qla2x00_do_dpc(void *data);
206 static void qla2x00_rst_aen(scsi_qla_host_t *);
208 static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
209 struct req_que **, struct rsp_que **);
210 static void qla2x00_mem_free(struct qla_hw_data *);
211 static void qla2x00_sp_free_dma(srb_t *);
213 /* -------------------------------------------------------------------------- */
214 static int qla2x00_alloc_queues(struct qla_hw_data *ha)
216 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
218 if (!ha->req_q_map) {
219 qla_printk(KERN_WARNING, ha,
220 "Unable to allocate memory for request queue ptrs\n");
224 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
226 if (!ha->rsp_q_map) {
227 qla_printk(KERN_WARNING, ha,
228 "Unable to allocate memory for response queue ptrs\n");
231 set_bit(0, ha->rsp_qid_map);
232 set_bit(0, ha->req_qid_map);
236 kfree(ha->req_q_map);
237 ha->req_q_map = NULL;
242 static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
244 if (req && req->ring)
245 dma_free_coherent(&ha->pdev->dev,
246 (req->length + 1) * sizeof(request_t),
247 req->ring, req->dma);
253 static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
255 if (rsp && rsp->ring)
256 dma_free_coherent(&ha->pdev->dev,
257 (rsp->length + 1) * sizeof(response_t),
258 rsp->ring, rsp->dma);
264 static void qla2x00_free_queues(struct qla_hw_data *ha)
270 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
271 req = ha->req_q_map[cnt];
272 qla2x00_free_req_que(ha, req);
274 kfree(ha->req_q_map);
275 ha->req_q_map = NULL;
277 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
278 rsp = ha->rsp_q_map[cnt];
279 qla2x00_free_rsp_que(ha, rsp);
281 kfree(ha->rsp_q_map);
282 ha->rsp_q_map = NULL;
285 static int qla25xx_setup_mode(struct scsi_qla_host *vha)
287 uint16_t options = 0;
289 struct qla_hw_data *ha = vha->hw;
291 if (!(ha->fw_attributes & BIT_6)) {
292 qla_printk(KERN_INFO, ha,
293 "Firmware is not multi-queue capable\n");
296 if (ql2xmultique_tag) {
297 /* create a request queue for IO */
299 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
300 QLA_DEFAULT_QUE_QOS);
302 qla_printk(KERN_WARNING, ha,
303 "Can't create request queue\n");
306 ha->wq = create_workqueue("qla2xxx_wq");
307 vha->req = ha->req_q_map[req];
309 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
310 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
312 qla_printk(KERN_WARNING, ha,
313 "Response Queue create failed\n");
317 ha->flags.cpu_affinity_enabled = 1;
319 DEBUG2(qla_printk(KERN_INFO, ha,
320 "CPU affinity mode enabled, no. of response"
321 " queues:%d, no. of request queues:%d\n",
322 ha->max_rsp_queues, ha->max_req_queues));
326 qla25xx_delete_queues(vha);
327 destroy_workqueue(ha->wq);
331 kfree(ha->req_q_map);
332 kfree(ha->rsp_q_map);
333 ha->max_req_queues = ha->max_rsp_queues = 1;
338 qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
340 struct qla_hw_data *ha = vha->hw;
341 static char *pci_bus_modes[] = {
342 "33", "66", "100", "133",
347 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
350 strcat(str, pci_bus_modes[pci_bus]);
352 pci_bus = (ha->pci_attr & BIT_8) >> 8;
354 strcat(str, pci_bus_modes[pci_bus]);
356 strcat(str, " MHz)");
362 qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
364 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
365 struct qla_hw_data *ha = vha->hw;
369 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
372 uint16_t pcie_lstat, lspeed, lwidth;
375 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
376 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
377 lwidth = (pcie_lstat &
378 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
380 strcpy(str, "PCIe (");
382 strcat(str, "2.5GT/s ");
383 else if (lspeed == 2)
384 strcat(str, "5.0GT/s ");
386 strcat(str, "<unknown> ");
387 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
394 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
395 if (pci_bus == 0 || pci_bus == 8) {
397 strcat(str, pci_bus_modes[pci_bus >> 3]);
401 strcat(str, "Mode 2");
403 strcat(str, "Mode 1");
405 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
407 strcat(str, " MHz)");
413 qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
416 struct qla_hw_data *ha = vha->hw;
418 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
419 ha->fw_minor_version,
420 ha->fw_subminor_version);
422 if (ha->fw_attributes & BIT_9) {
427 switch (ha->fw_attributes & 0xFF) {
441 sprintf(un_str, "(%x)", ha->fw_attributes);
445 if (ha->fw_attributes & 0x100)
452 qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
454 struct qla_hw_data *ha = vha->hw;
456 sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
457 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
461 static inline srb_t *
462 qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
463 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
466 struct qla_hw_data *ha = vha->hw;
468 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
475 CMD_SP(cmd) = (void *)sp;
476 cmd->scsi_done = done;
483 qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
485 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
486 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
487 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
488 struct qla_hw_data *ha = vha->hw;
489 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
493 if (unlikely(pci_channel_offline(ha->pdev))) {
494 if (ha->pdev->error_state == pci_channel_io_frozen)
495 cmd->result = DID_REQUEUE << 16;
497 cmd->result = DID_NO_CONNECT << 16;
498 goto qc24_fail_command;
501 rval = fc_remote_port_chkready(rport);
504 goto qc24_fail_command;
507 /* Close window on fcport/rport state-transitioning. */
509 goto qc24_target_busy;
511 if (atomic_read(&fcport->state) != FCS_ONLINE) {
512 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
513 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
514 cmd->result = DID_NO_CONNECT << 16;
515 goto qc24_fail_command;
517 goto qc24_target_busy;
520 spin_unlock_irq(vha->host->host_lock);
522 sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
524 goto qc24_host_busy_lock;
526 rval = ha->isp_ops->start_scsi(sp);
527 if (rval != QLA_SUCCESS)
528 goto qc24_host_busy_free_sp;
530 spin_lock_irq(vha->host->host_lock);
534 qc24_host_busy_free_sp:
535 qla2x00_sp_free_dma(sp);
536 mempool_free(sp, ha->srb_mempool);
539 spin_lock_irq(vha->host->host_lock);
540 return SCSI_MLQUEUE_HOST_BUSY;
543 return SCSI_MLQUEUE_TARGET_BUSY;
553 * qla2x00_eh_wait_on_command
554 * Waits for the command to be returned by the Firmware for some
558 * cmd = Scsi Command to wait on.
565 qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
567 #define ABORT_POLLING_PERIOD 1000
568 #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
569 unsigned long wait_iter = ABORT_WAIT_ITER;
570 int ret = QLA_SUCCESS;
572 while (CMD_SP(cmd) && wait_iter--) {
573 msleep(ABORT_POLLING_PERIOD);
576 ret = QLA_FUNCTION_FAILED;
582 * qla2x00_wait_for_hba_online
583 * Wait till the HBA is online after going through
584 * <= MAX_RETRIES_OF_ISP_ABORT or
585 * finally HBA is disabled ie marked offline
588 * ha - pointer to host adapter structure
591 * Does context switching-Release SPIN_LOCK
592 * (if any) before calling this routine.
595 * Success (Adapter is online) : 0
596 * Failed (Adapter is offline/disabled) : 1
599 qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
602 unsigned long wait_online;
603 struct qla_hw_data *ha = vha->hw;
604 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
606 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
607 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
608 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
609 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
610 ha->dpc_active) && time_before(jiffies, wait_online)) {
614 if (base_vha->flags.online)
615 return_status = QLA_SUCCESS;
617 return_status = QLA_FUNCTION_FAILED;
619 return (return_status);
623 qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
626 unsigned long wait_reset;
627 struct qla_hw_data *ha = vha->hw;
628 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
630 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
631 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
632 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
633 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
634 ha->dpc_active) && time_before(jiffies, wait_reset)) {
638 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
639 ha->flags.chip_reset_done)
642 if (ha->flags.chip_reset_done)
643 return_status = QLA_SUCCESS;
645 return_status = QLA_FUNCTION_FAILED;
647 return return_status;
651 * qla2x00_wait_for_loop_ready
652 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
653 * to be in LOOP_READY state.
655 * ha - pointer to host adapter structure
658 * Does context switching-Release SPIN_LOCK
659 * (if any) before calling this routine.
663 * Success (LOOP_READY) : 0
664 * Failed (LOOP_NOT_READY) : 1
667 qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
669 int return_status = QLA_SUCCESS;
670 unsigned long loop_timeout ;
671 struct qla_hw_data *ha = vha->hw;
672 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
674 /* wait for 5 min at the max for loop to be ready */
675 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
677 while ((!atomic_read(&base_vha->loop_down_timer) &&
678 atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
679 atomic_read(&base_vha->loop_state) != LOOP_READY) {
680 if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
681 return_status = QLA_FUNCTION_FAILED;
685 if (time_after_eq(jiffies, loop_timeout)) {
686 return_status = QLA_FUNCTION_FAILED;
690 return (return_status);
694 qla2x00_abort_fcport_cmds(fc_port_t *fcport)
699 scsi_qla_host_t *vha = fcport->vha;
700 struct qla_hw_data *ha = vha->hw;
703 spin_lock_irqsave(&ha->hardware_lock, flags);
705 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
706 sp = req->outstanding_cmds[cnt];
709 if (sp->fcport != fcport)
714 spin_unlock_irqrestore(&ha->hardware_lock, flags);
715 if (ha->isp_ops->abort_command(sp)) {
716 DEBUG2(qla_printk(KERN_WARNING, ha,
717 "Abort failed -- %lx\n",
718 sp->cmd->serial_number));
720 if (qla2x00_eh_wait_on_command(sp->cmd) !=
722 DEBUG2(qla_printk(KERN_WARNING, ha,
723 "Abort failed while waiting -- %lx\n",
724 sp->cmd->serial_number));
726 spin_lock_irqsave(&ha->hardware_lock, flags);
728 spin_unlock_irqrestore(&ha->hardware_lock, flags);
732 qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
734 struct Scsi_Host *shost = cmnd->device->host;
735 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
738 spin_lock_irqsave(shost->host_lock, flags);
739 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
740 spin_unlock_irqrestore(shost->host_lock, flags);
742 spin_lock_irqsave(shost->host_lock, flags);
744 spin_unlock_irqrestore(shost->host_lock, flags);
748 /**************************************************************************
752 * The abort function will abort the specified command.
755 * cmd = Linux SCSI command packet to be aborted.
758 * Either SUCCESS or FAILED.
761 * Only return FAILED if command not returned by firmware.
762 **************************************************************************/
764 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
766 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
769 unsigned int id, lun;
770 unsigned long serial;
773 struct qla_hw_data *ha = vha->hw;
774 struct req_que *req = vha->req;
777 qla2x00_block_error_handler(cmd);
784 id = cmd->device->id;
785 lun = cmd->device->lun;
786 serial = cmd->serial_number;
787 spt = (srb_t *) CMD_SP(cmd);
791 /* Check active list for command command. */
792 spin_lock_irqsave(&ha->hardware_lock, flags);
793 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
794 sp = req->outstanding_cmds[i];
803 DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
804 " pid=%ld.\n", __func__, vha->host_no, sp, serial));
806 spin_unlock_irqrestore(&ha->hardware_lock, flags);
807 if (ha->isp_ops->abort_command(sp)) {
808 DEBUG2(printk("%s(%ld): abort_command "
809 "mbx failed.\n", __func__, vha->host_no));
812 DEBUG3(printk("%s(%ld): abort_command "
813 "mbx success.\n", __func__, vha->host_no));
816 spin_lock_irqsave(&ha->hardware_lock, flags);
819 spin_unlock_irqrestore(&ha->hardware_lock, flags);
821 /* Wait for the command to be returned. */
823 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
824 qla_printk(KERN_ERR, ha,
825 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
826 "%x.\n", vha->host_no, id, lun, serial, ret);
831 qla_printk(KERN_INFO, ha,
832 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
833 vha->host_no, id, lun, wait, serial, ret);
838 enum nexus_wait_type {
845 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
846 unsigned int l, srb_t *sp, enum nexus_wait_type type)
848 int cnt, match, status;
850 struct qla_hw_data *ha = vha->hw;
853 status = QLA_SUCCESS;
857 spin_lock_irqsave(&ha->hardware_lock, flags);
859 for (cnt = 1; status == QLA_SUCCESS &&
860 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
861 sp = req->outstanding_cmds[cnt];
866 if (vha->vp_idx != sp->fcport->vha->vp_idx)
874 match = sp->cmd->device->id == t;
877 match = (sp->cmd->device->id == t &&
878 sp->cmd->device->lun == l);
884 spin_unlock_irqrestore(&ha->hardware_lock, flags);
885 status = qla2x00_eh_wait_on_command(sp->cmd);
886 spin_lock_irqsave(&ha->hardware_lock, flags);
888 spin_unlock_irqrestore(&ha->hardware_lock, flags);
893 static char *reset_errors[] = {
896 "Task management failed",
897 "Waiting for command completions",
901 __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
902 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
904 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
905 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
908 qla2x00_block_error_handler(cmd);
913 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
914 vha->host_no, cmd->device->id, cmd->device->lun, name);
917 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
918 goto eh_reset_failed;
920 if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
921 goto eh_reset_failed;
923 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
925 goto eh_reset_failed;
927 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
928 cmd->device->lun, (srb_t *) CMD_SP(cmd), type) != QLA_SUCCESS)
929 goto eh_reset_failed;
931 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
932 vha->host_no, cmd->device->id, cmd->device->lun, name);
937 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
938 , vha->host_no, cmd->device->id, cmd->device->lun, name,
944 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
946 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
947 struct qla_hw_data *ha = vha->hw;
949 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
950 ha->isp_ops->lun_reset);
954 qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
956 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
957 struct qla_hw_data *ha = vha->hw;
959 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
960 ha->isp_ops->target_reset);
963 /**************************************************************************
964 * qla2xxx_eh_bus_reset
967 * The bus reset function will reset the bus and abort any executing
971 * cmd = Linux SCSI command packet of the command that cause the
975 * SUCCESS/FAILURE (defined as macro in scsi.h).
977 **************************************************************************/
979 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
981 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
982 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
984 unsigned int id, lun;
985 unsigned long serial;
986 srb_t *sp = (srb_t *) CMD_SP(cmd);
988 qla2x00_block_error_handler(cmd);
990 id = cmd->device->id;
991 lun = cmd->device->lun;
992 serial = cmd->serial_number;
997 qla_printk(KERN_INFO, vha->hw,
998 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
1000 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1001 DEBUG2(printk("%s failed:board disabled\n",__func__));
1002 goto eh_bus_reset_done;
1005 if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
1006 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1010 goto eh_bus_reset_done;
1012 /* Flush outstanding commands. */
1013 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) !=
1018 qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
1019 (ret == FAILED) ? "failed" : "succeded");
1024 /**************************************************************************
1025 * qla2xxx_eh_host_reset
1028 * The reset function will reset the Adapter.
1031 * cmd = Linux SCSI command packet of the command that cause the
1035 * Either SUCCESS or FAILED.
1038 **************************************************************************/
1040 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1042 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1043 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1044 struct qla_hw_data *ha = vha->hw;
1046 unsigned int id, lun;
1047 unsigned long serial;
1048 srb_t *sp = (srb_t *) CMD_SP(cmd);
1049 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1051 qla2x00_block_error_handler(cmd);
1053 id = cmd->device->id;
1054 lun = cmd->device->lun;
1055 serial = cmd->serial_number;
1060 qla_printk(KERN_INFO, ha,
1061 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
1063 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1064 goto eh_host_reset_lock;
1067 * Fixme-may be dpc thread is active and processing
1068 * loop_resync,so wait a while for it to
1069 * be completed and then issue big hammer.Otherwise
1070 * it may cause I/O failure as big hammer marks the
1071 * devices as lost kicking of the port_down_timer
1072 * while dpc is stuck for the mailbox to complete.
1074 qla2x00_wait_for_loop_ready(vha);
1075 if (vha != base_vha) {
1076 if (qla2x00_vp_abort_isp(vha))
1077 goto eh_host_reset_lock;
1080 flush_workqueue(ha->wq);
1082 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1083 if (qla2x00_abort_isp(base_vha)) {
1084 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1085 /* failed. schedule dpc to try */
1086 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1088 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1089 goto eh_host_reset_lock;
1091 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1094 /* Waiting for command to be returned to OS.*/
1095 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) ==
1100 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1101 (ret == FAILED) ? "failed" : "succeded");
1107 * qla2x00_loop_reset
1111 * ha = adapter block pointer.
1117 qla2x00_loop_reset(scsi_qla_host_t *vha)
1120 struct fc_port *fcport;
1121 struct qla_hw_data *ha = vha->hw;
1123 if (ha->flags.enable_lip_full_login && !IS_QLA81XX(ha)) {
1124 ret = qla2x00_full_login_lip(vha);
1125 if (ret != QLA_SUCCESS) {
1126 DEBUG2_3(printk("%s(%ld): failed: "
1127 "full_login_lip=%d.\n", __func__, vha->host_no,
1130 atomic_set(&vha->loop_state, LOOP_DOWN);
1131 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1132 qla2x00_mark_all_devices_lost(vha, 0);
1133 qla2x00_wait_for_loop_ready(vha);
1136 if (ha->flags.enable_lip_reset) {
1137 ret = qla2x00_lip_reset(vha);
1138 if (ret != QLA_SUCCESS) {
1139 DEBUG2_3(printk("%s(%ld): failed: "
1140 "lip_reset=%d.\n", __func__, vha->host_no, ret));
1142 qla2x00_wait_for_loop_ready(vha);
1145 if (ha->flags.enable_target_reset) {
1146 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1147 if (fcport->port_type != FCT_TARGET)
1150 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1151 if (ret != QLA_SUCCESS) {
1152 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1153 "target_reset=%d d_id=%x.\n", __func__,
1154 vha->host_no, ret, fcport->d_id.b24));
1158 /* Issue marker command only when we are going to start the I/O */
1159 vha->marker_needed = 1;
1165 qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1168 unsigned long flags;
1170 struct srb_ctx *ctx;
1171 struct qla_hw_data *ha = vha->hw;
1172 struct req_que *req;
1174 spin_lock_irqsave(&ha->hardware_lock, flags);
1175 for (que = 0; que < ha->max_req_queues; que++) {
1176 req = ha->req_q_map[que];
1179 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1180 sp = req->outstanding_cmds[cnt];
1182 req->outstanding_cmds[cnt] = NULL;
1184 sp->cmd->result = res;
1185 qla2x00_sp_compl(ha, sp);
1188 del_timer_sync(&ctx->timer);
1194 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1198 qla2xxx_slave_alloc(struct scsi_device *sdev)
1200 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1202 if (!rport || fc_remote_port_chkready(rport))
1205 sdev->hostdata = *(fc_port_t **)rport->dd_data;
1211 qla2xxx_slave_configure(struct scsi_device *sdev)
1213 scsi_qla_host_t *vha = shost_priv(sdev->host);
1214 struct qla_hw_data *ha = vha->hw;
1215 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1216 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1217 struct req_que *req = vha->req;
1219 if (sdev->tagged_supported)
1220 scsi_activate_tcq(sdev, req->max_q_depth);
1222 scsi_deactivate_tcq(sdev, req->max_q_depth);
1224 rport->dev_loss_tmo = ha->port_down_retry_count;
1225 if (sdev->type == TYPE_TAPE)
1226 fcport->flags |= FCF_TAPE_PRESENT;
1232 qla2xxx_slave_destroy(struct scsi_device *sdev)
1234 sdev->hostdata = NULL;
1238 qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1240 if (reason != SCSI_QDEPTH_DEFAULT)
1243 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1244 return sdev->queue_depth;
1248 qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1250 if (sdev->tagged_supported) {
1251 scsi_set_tag_type(sdev, tag_type);
1253 scsi_activate_tcq(sdev, sdev->queue_depth);
1255 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1263 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1266 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1267 * supported addressing method.
1270 qla2x00_config_dma_addressing(struct qla_hw_data *ha)
1272 /* Assume a 32bit DMA mask. */
1273 ha->flags.enable_64bit_addressing = 0;
1275 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1276 /* Any upper-dword bits set? */
1277 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1278 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
1279 /* Ok, a 64bit DMA mask is applicable. */
1280 ha->flags.enable_64bit_addressing = 1;
1281 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1282 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
1287 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1288 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
1292 qla2x00_enable_intrs(struct qla_hw_data *ha)
1294 unsigned long flags = 0;
1295 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1297 spin_lock_irqsave(&ha->hardware_lock, flags);
1298 ha->interrupts_on = 1;
1299 /* enable risc and host interrupts */
1300 WRT_REG_WORD(®->ictrl, ICR_EN_INT | ICR_EN_RISC);
1301 RD_REG_WORD(®->ictrl);
1302 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1307 qla2x00_disable_intrs(struct qla_hw_data *ha)
1309 unsigned long flags = 0;
1310 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1312 spin_lock_irqsave(&ha->hardware_lock, flags);
1313 ha->interrupts_on = 0;
1314 /* disable risc and host interrupts */
1315 WRT_REG_WORD(®->ictrl, 0);
1316 RD_REG_WORD(®->ictrl);
1317 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1321 qla24xx_enable_intrs(struct qla_hw_data *ha)
1323 unsigned long flags = 0;
1324 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1326 spin_lock_irqsave(&ha->hardware_lock, flags);
1327 ha->interrupts_on = 1;
1328 WRT_REG_DWORD(®->ictrl, ICRX_EN_RISC_INT);
1329 RD_REG_DWORD(®->ictrl);
1330 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1334 qla24xx_disable_intrs(struct qla_hw_data *ha)
1336 unsigned long flags = 0;
1337 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1339 if (IS_NOPOLLING_TYPE(ha))
1341 spin_lock_irqsave(&ha->hardware_lock, flags);
1342 ha->interrupts_on = 0;
1343 WRT_REG_DWORD(®->ictrl, 0);
1344 RD_REG_DWORD(®->ictrl);
1345 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1348 static struct isp_operations qla2100_isp_ops = {
1349 .pci_config = qla2100_pci_config,
1350 .reset_chip = qla2x00_reset_chip,
1351 .chip_diag = qla2x00_chip_diag,
1352 .config_rings = qla2x00_config_rings,
1353 .reset_adapter = qla2x00_reset_adapter,
1354 .nvram_config = qla2x00_nvram_config,
1355 .update_fw_options = qla2x00_update_fw_options,
1356 .load_risc = qla2x00_load_risc,
1357 .pci_info_str = qla2x00_pci_info_str,
1358 .fw_version_str = qla2x00_fw_version_str,
1359 .intr_handler = qla2100_intr_handler,
1360 .enable_intrs = qla2x00_enable_intrs,
1361 .disable_intrs = qla2x00_disable_intrs,
1362 .abort_command = qla2x00_abort_command,
1363 .target_reset = qla2x00_abort_target,
1364 .lun_reset = qla2x00_lun_reset,
1365 .fabric_login = qla2x00_login_fabric,
1366 .fabric_logout = qla2x00_fabric_logout,
1367 .calc_req_entries = qla2x00_calc_iocbs_32,
1368 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1369 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1370 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1371 .read_nvram = qla2x00_read_nvram_data,
1372 .write_nvram = qla2x00_write_nvram_data,
1373 .fw_dump = qla2100_fw_dump,
1376 .beacon_blink = NULL,
1377 .read_optrom = qla2x00_read_optrom_data,
1378 .write_optrom = qla2x00_write_optrom_data,
1379 .get_flash_version = qla2x00_get_flash_version,
1380 .start_scsi = qla2x00_start_scsi,
1383 static struct isp_operations qla2300_isp_ops = {
1384 .pci_config = qla2300_pci_config,
1385 .reset_chip = qla2x00_reset_chip,
1386 .chip_diag = qla2x00_chip_diag,
1387 .config_rings = qla2x00_config_rings,
1388 .reset_adapter = qla2x00_reset_adapter,
1389 .nvram_config = qla2x00_nvram_config,
1390 .update_fw_options = qla2x00_update_fw_options,
1391 .load_risc = qla2x00_load_risc,
1392 .pci_info_str = qla2x00_pci_info_str,
1393 .fw_version_str = qla2x00_fw_version_str,
1394 .intr_handler = qla2300_intr_handler,
1395 .enable_intrs = qla2x00_enable_intrs,
1396 .disable_intrs = qla2x00_disable_intrs,
1397 .abort_command = qla2x00_abort_command,
1398 .target_reset = qla2x00_abort_target,
1399 .lun_reset = qla2x00_lun_reset,
1400 .fabric_login = qla2x00_login_fabric,
1401 .fabric_logout = qla2x00_fabric_logout,
1402 .calc_req_entries = qla2x00_calc_iocbs_32,
1403 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1404 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1405 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1406 .read_nvram = qla2x00_read_nvram_data,
1407 .write_nvram = qla2x00_write_nvram_data,
1408 .fw_dump = qla2300_fw_dump,
1409 .beacon_on = qla2x00_beacon_on,
1410 .beacon_off = qla2x00_beacon_off,
1411 .beacon_blink = qla2x00_beacon_blink,
1412 .read_optrom = qla2x00_read_optrom_data,
1413 .write_optrom = qla2x00_write_optrom_data,
1414 .get_flash_version = qla2x00_get_flash_version,
1415 .start_scsi = qla2x00_start_scsi,
1418 static struct isp_operations qla24xx_isp_ops = {
1419 .pci_config = qla24xx_pci_config,
1420 .reset_chip = qla24xx_reset_chip,
1421 .chip_diag = qla24xx_chip_diag,
1422 .config_rings = qla24xx_config_rings,
1423 .reset_adapter = qla24xx_reset_adapter,
1424 .nvram_config = qla24xx_nvram_config,
1425 .update_fw_options = qla24xx_update_fw_options,
1426 .load_risc = qla24xx_load_risc,
1427 .pci_info_str = qla24xx_pci_info_str,
1428 .fw_version_str = qla24xx_fw_version_str,
1429 .intr_handler = qla24xx_intr_handler,
1430 .enable_intrs = qla24xx_enable_intrs,
1431 .disable_intrs = qla24xx_disable_intrs,
1432 .abort_command = qla24xx_abort_command,
1433 .target_reset = qla24xx_abort_target,
1434 .lun_reset = qla24xx_lun_reset,
1435 .fabric_login = qla24xx_login_fabric,
1436 .fabric_logout = qla24xx_fabric_logout,
1437 .calc_req_entries = NULL,
1438 .build_iocbs = NULL,
1439 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1440 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1441 .read_nvram = qla24xx_read_nvram_data,
1442 .write_nvram = qla24xx_write_nvram_data,
1443 .fw_dump = qla24xx_fw_dump,
1444 .beacon_on = qla24xx_beacon_on,
1445 .beacon_off = qla24xx_beacon_off,
1446 .beacon_blink = qla24xx_beacon_blink,
1447 .read_optrom = qla24xx_read_optrom_data,
1448 .write_optrom = qla24xx_write_optrom_data,
1449 .get_flash_version = qla24xx_get_flash_version,
1450 .start_scsi = qla24xx_start_scsi,
1453 static struct isp_operations qla25xx_isp_ops = {
1454 .pci_config = qla25xx_pci_config,
1455 .reset_chip = qla24xx_reset_chip,
1456 .chip_diag = qla24xx_chip_diag,
1457 .config_rings = qla24xx_config_rings,
1458 .reset_adapter = qla24xx_reset_adapter,
1459 .nvram_config = qla24xx_nvram_config,
1460 .update_fw_options = qla24xx_update_fw_options,
1461 .load_risc = qla24xx_load_risc,
1462 .pci_info_str = qla24xx_pci_info_str,
1463 .fw_version_str = qla24xx_fw_version_str,
1464 .intr_handler = qla24xx_intr_handler,
1465 .enable_intrs = qla24xx_enable_intrs,
1466 .disable_intrs = qla24xx_disable_intrs,
1467 .abort_command = qla24xx_abort_command,
1468 .target_reset = qla24xx_abort_target,
1469 .lun_reset = qla24xx_lun_reset,
1470 .fabric_login = qla24xx_login_fabric,
1471 .fabric_logout = qla24xx_fabric_logout,
1472 .calc_req_entries = NULL,
1473 .build_iocbs = NULL,
1474 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1475 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1476 .read_nvram = qla25xx_read_nvram_data,
1477 .write_nvram = qla25xx_write_nvram_data,
1478 .fw_dump = qla25xx_fw_dump,
1479 .beacon_on = qla24xx_beacon_on,
1480 .beacon_off = qla24xx_beacon_off,
1481 .beacon_blink = qla24xx_beacon_blink,
1482 .read_optrom = qla25xx_read_optrom_data,
1483 .write_optrom = qla24xx_write_optrom_data,
1484 .get_flash_version = qla24xx_get_flash_version,
1485 .start_scsi = qla24xx_start_scsi,
1488 static struct isp_operations qla81xx_isp_ops = {
1489 .pci_config = qla25xx_pci_config,
1490 .reset_chip = qla24xx_reset_chip,
1491 .chip_diag = qla24xx_chip_diag,
1492 .config_rings = qla24xx_config_rings,
1493 .reset_adapter = qla24xx_reset_adapter,
1494 .nvram_config = qla81xx_nvram_config,
1495 .update_fw_options = qla81xx_update_fw_options,
1496 .load_risc = qla81xx_load_risc,
1497 .pci_info_str = qla24xx_pci_info_str,
1498 .fw_version_str = qla24xx_fw_version_str,
1499 .intr_handler = qla24xx_intr_handler,
1500 .enable_intrs = qla24xx_enable_intrs,
1501 .disable_intrs = qla24xx_disable_intrs,
1502 .abort_command = qla24xx_abort_command,
1503 .target_reset = qla24xx_abort_target,
1504 .lun_reset = qla24xx_lun_reset,
1505 .fabric_login = qla24xx_login_fabric,
1506 .fabric_logout = qla24xx_fabric_logout,
1507 .calc_req_entries = NULL,
1508 .build_iocbs = NULL,
1509 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1510 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1512 .write_nvram = NULL,
1513 .fw_dump = qla81xx_fw_dump,
1514 .beacon_on = qla24xx_beacon_on,
1515 .beacon_off = qla24xx_beacon_off,
1516 .beacon_blink = qla24xx_beacon_blink,
1517 .read_optrom = qla25xx_read_optrom_data,
1518 .write_optrom = qla24xx_write_optrom_data,
1519 .get_flash_version = qla24xx_get_flash_version,
1520 .start_scsi = qla24xx_start_scsi,
1524 qla2x00_set_isp_flags(struct qla_hw_data *ha)
1526 ha->device_type = DT_EXTENDED_IDS;
1527 switch (ha->pdev->device) {
1528 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1529 ha->device_type |= DT_ISP2100;
1530 ha->device_type &= ~DT_EXTENDED_IDS;
1531 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
1533 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1534 ha->device_type |= DT_ISP2200;
1535 ha->device_type &= ~DT_EXTENDED_IDS;
1536 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
1538 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1539 ha->device_type |= DT_ISP2300;
1540 ha->device_type |= DT_ZIO_SUPPORTED;
1541 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1543 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1544 ha->device_type |= DT_ISP2312;
1545 ha->device_type |= DT_ZIO_SUPPORTED;
1546 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1548 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1549 ha->device_type |= DT_ISP2322;
1550 ha->device_type |= DT_ZIO_SUPPORTED;
1551 if (ha->pdev->subsystem_vendor == 0x1028 &&
1552 ha->pdev->subsystem_device == 0x0170)
1553 ha->device_type |= DT_OEM_001;
1554 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1556 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1557 ha->device_type |= DT_ISP6312;
1558 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1560 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1561 ha->device_type |= DT_ISP6322;
1562 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1564 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1565 ha->device_type |= DT_ISP2422;
1566 ha->device_type |= DT_ZIO_SUPPORTED;
1567 ha->device_type |= DT_FWI2;
1568 ha->device_type |= DT_IIDMA;
1569 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1571 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1572 ha->device_type |= DT_ISP2432;
1573 ha->device_type |= DT_ZIO_SUPPORTED;
1574 ha->device_type |= DT_FWI2;
1575 ha->device_type |= DT_IIDMA;
1576 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1578 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1579 ha->device_type |= DT_ISP8432;
1580 ha->device_type |= DT_ZIO_SUPPORTED;
1581 ha->device_type |= DT_FWI2;
1582 ha->device_type |= DT_IIDMA;
1583 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1585 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1586 ha->device_type |= DT_ISP5422;
1587 ha->device_type |= DT_FWI2;
1588 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1590 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1591 ha->device_type |= DT_ISP5432;
1592 ha->device_type |= DT_FWI2;
1593 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1595 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1596 ha->device_type |= DT_ISP2532;
1597 ha->device_type |= DT_ZIO_SUPPORTED;
1598 ha->device_type |= DT_FWI2;
1599 ha->device_type |= DT_IIDMA;
1600 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1602 case PCI_DEVICE_ID_QLOGIC_ISP8001:
1603 ha->device_type |= DT_ISP8001;
1604 ha->device_type |= DT_ZIO_SUPPORTED;
1605 ha->device_type |= DT_FWI2;
1606 ha->device_type |= DT_IIDMA;
1607 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1611 /* Get adapter physical port no from interrupt pin register. */
1612 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
1613 if (ha->port_no & 1)
1614 ha->flags.port0 = 1;
1616 ha->flags.port0 = 0;
1620 qla2x00_iospace_config(struct qla_hw_data *ha)
1622 resource_size_t pio;
1626 if (pci_request_selected_regions(ha->pdev, ha->bars,
1627 QLA2XXX_DRIVER_NAME)) {
1628 qla_printk(KERN_WARNING, ha,
1629 "Failed to reserve PIO/MMIO regions (%s)\n",
1630 pci_name(ha->pdev));
1632 goto iospace_error_exit;
1634 if (!(ha->bars & 1))
1637 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1638 pio = pci_resource_start(ha->pdev, 0);
1639 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1640 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1641 qla_printk(KERN_WARNING, ha,
1642 "Invalid PCI I/O region size (%s)...\n",
1643 pci_name(ha->pdev));
1647 qla_printk(KERN_WARNING, ha,
1648 "region #0 not a PIO resource (%s)...\n",
1649 pci_name(ha->pdev));
1652 ha->pio_address = pio;
1655 /* Use MMIO operations for all accesses. */
1656 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1657 qla_printk(KERN_ERR, ha,
1658 "region #1 not an MMIO resource (%s), aborting\n",
1659 pci_name(ha->pdev));
1660 goto iospace_error_exit;
1662 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1663 qla_printk(KERN_ERR, ha,
1664 "Invalid PCI mem region size (%s), aborting\n",
1665 pci_name(ha->pdev));
1666 goto iospace_error_exit;
1669 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1671 qla_printk(KERN_ERR, ha,
1672 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1674 goto iospace_error_exit;
1677 /* Determine queue resources */
1678 ha->max_req_queues = ha->max_rsp_queues = 1;
1679 if ((ql2xmaxqueues <= 1 || ql2xmultique_tag < 1) &&
1680 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1682 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1683 pci_resource_len(ha->pdev, 3));
1685 /* Read MSIX vector size of the board */
1686 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1687 ha->msix_count = msix;
1688 /* Max queues are bounded by available msix vectors */
1689 /* queue 0 uses two msix vectors */
1690 if (ql2xmultique_tag) {
1691 cpus = num_online_cpus();
1692 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1693 (cpus + 1) : (ha->msix_count - 1);
1694 ha->max_req_queues = 2;
1695 } else if (ql2xmaxqueues > 1) {
1696 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1697 QLA_MQ_SIZE : ql2xmaxqueues;
1698 DEBUG2(qla_printk(KERN_INFO, ha, "QoS mode set, max no"
1699 " of request queues:%d\n", ha->max_req_queues));
1701 qla_printk(KERN_INFO, ha,
1702 "MSI-X vector count: %d\n", msix);
1704 qla_printk(KERN_INFO, ha, "BAR 3 not enabled\n");
1707 ha->msix_count = ha->max_rsp_queues + 1;
1715 qla2xxx_scan_start(struct Scsi_Host *shost)
1717 scsi_qla_host_t *vha = shost_priv(shost);
1719 if (vha->hw->flags.running_gold_fw)
1722 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1723 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1724 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1725 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
1729 qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1731 scsi_qla_host_t *vha = shost_priv(shost);
1735 if (time > vha->hw->loop_reset_delay * HZ)
1738 return atomic_read(&vha->loop_state) == LOOP_READY;
1742 * PCI driver interface
1744 static int __devinit
1745 qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1748 struct Scsi_Host *host;
1749 scsi_qla_host_t *base_vha = NULL;
1750 struct qla_hw_data *ha;
1753 struct scsi_host_template *sht;
1754 int bars, max_id, mem_only = 0;
1755 uint16_t req_length = 0, rsp_length = 0;
1756 struct req_que *req = NULL;
1757 struct rsp_que *rsp = NULL;
1759 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
1760 sht = &qla2xxx_driver_template;
1761 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1762 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
1763 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
1764 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1765 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
1766 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
1767 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001) {
1768 bars = pci_select_bars(pdev, IORESOURCE_MEM);
1773 if (pci_enable_device_mem(pdev))
1776 if (pci_enable_device(pdev))
1780 /* This may fail but that's ok */
1781 pci_enable_pcie_error_reporting(pdev);
1783 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
1785 DEBUG(printk("Unable to allocate memory for ha\n"));
1790 /* Clear our data area */
1792 ha->mem_only = mem_only;
1793 spin_lock_init(&ha->hardware_lock);
1795 /* Set ISP-type information. */
1796 qla2x00_set_isp_flags(ha);
1797 /* Configure PCI I/O space */
1798 ret = qla2x00_iospace_config(ha);
1800 goto probe_hw_failed;
1802 qla_printk(KERN_INFO, ha,
1803 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1806 ha->prev_topology = 0;
1807 ha->init_cb_size = sizeof(init_cb_t);
1808 ha->link_data_rate = PORT_SPEED_UNKNOWN;
1809 ha->optrom_size = OPTROM_SIZE_2300;
1811 /* Assign ISP specific operations. */
1812 max_id = MAX_TARGETS_2200;
1813 if (IS_QLA2100(ha)) {
1814 max_id = MAX_TARGETS_2100;
1815 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1816 req_length = REQUEST_ENTRY_CNT_2100;
1817 rsp_length = RESPONSE_ENTRY_CNT_2100;
1818 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
1819 ha->gid_list_info_size = 4;
1820 ha->flash_conf_off = ~0;
1821 ha->flash_data_off = ~0;
1822 ha->nvram_conf_off = ~0;
1823 ha->nvram_data_off = ~0;
1824 ha->isp_ops = &qla2100_isp_ops;
1825 } else if (IS_QLA2200(ha)) {
1826 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1827 req_length = REQUEST_ENTRY_CNT_2200;
1828 rsp_length = RESPONSE_ENTRY_CNT_2100;
1829 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
1830 ha->gid_list_info_size = 4;
1831 ha->flash_conf_off = ~0;
1832 ha->flash_data_off = ~0;
1833 ha->nvram_conf_off = ~0;
1834 ha->nvram_data_off = ~0;
1835 ha->isp_ops = &qla2100_isp_ops;
1836 } else if (IS_QLA23XX(ha)) {
1837 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1838 req_length = REQUEST_ENTRY_CNT_2200;
1839 rsp_length = RESPONSE_ENTRY_CNT_2300;
1840 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1841 ha->gid_list_info_size = 6;
1842 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1843 ha->optrom_size = OPTROM_SIZE_2322;
1844 ha->flash_conf_off = ~0;
1845 ha->flash_data_off = ~0;
1846 ha->nvram_conf_off = ~0;
1847 ha->nvram_data_off = ~0;
1848 ha->isp_ops = &qla2300_isp_ops;
1849 } else if (IS_QLA24XX_TYPE(ha)) {
1850 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1851 req_length = REQUEST_ENTRY_CNT_24XX;
1852 rsp_length = RESPONSE_ENTRY_CNT_2300;
1853 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1854 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1855 ha->gid_list_info_size = 8;
1856 ha->optrom_size = OPTROM_SIZE_24XX;
1857 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
1858 ha->isp_ops = &qla24xx_isp_ops;
1859 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1860 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1861 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1862 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
1863 } else if (IS_QLA25XX(ha)) {
1864 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1865 req_length = REQUEST_ENTRY_CNT_24XX;
1866 rsp_length = RESPONSE_ENTRY_CNT_2300;
1867 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1868 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1869 ha->gid_list_info_size = 8;
1870 ha->optrom_size = OPTROM_SIZE_25XX;
1871 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
1872 ha->isp_ops = &qla25xx_isp_ops;
1873 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1874 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1875 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1876 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
1877 } else if (IS_QLA81XX(ha)) {
1878 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1879 req_length = REQUEST_ENTRY_CNT_24XX;
1880 rsp_length = RESPONSE_ENTRY_CNT_2300;
1881 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1882 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
1883 ha->gid_list_info_size = 8;
1884 ha->optrom_size = OPTROM_SIZE_81XX;
1885 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
1886 ha->isp_ops = &qla81xx_isp_ops;
1887 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
1888 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
1889 ha->nvram_conf_off = ~0;
1890 ha->nvram_data_off = ~0;
1893 mutex_init(&ha->vport_lock);
1894 init_completion(&ha->mbx_cmd_comp);
1895 complete(&ha->mbx_cmd_comp);
1896 init_completion(&ha->mbx_intr_comp);
1898 set_bit(0, (unsigned long *) ha->vp_idx_map);
1900 qla2x00_config_dma_addressing(ha);
1901 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
1903 qla_printk(KERN_WARNING, ha,
1904 "[ERROR] Failed to allocate memory for adapter\n");
1906 goto probe_hw_failed;
1909 req->max_q_depth = MAX_Q_DEPTH;
1910 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
1911 req->max_q_depth = ql2xmaxqdepth;
1914 base_vha = qla2x00_create_host(sht, ha);
1916 qla_printk(KERN_WARNING, ha,
1917 "[ERROR] Failed to allocate memory for scsi_host\n");
1920 qla2x00_mem_free(ha);
1921 qla2x00_free_req_que(ha, req);
1922 qla2x00_free_rsp_que(ha, rsp);
1923 goto probe_hw_failed;
1926 pci_set_drvdata(pdev, base_vha);
1928 host = base_vha->host;
1929 base_vha->req = req;
1930 host->can_queue = req->length + 128;
1931 if (IS_QLA2XXX_MIDTYPE(ha))
1932 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
1934 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
1937 host->sg_tablesize = 32;
1938 host->max_id = max_id;
1939 host->this_id = 255;
1940 host->cmd_per_lun = 3;
1941 host->unique_id = host->host_no;
1942 host->max_cmd_len = MAX_CMDSZ;
1943 host->max_channel = MAX_BUSES - 1;
1944 host->max_lun = MAX_LUNS;
1945 host->transportt = qla2xxx_transport_template;
1947 /* Set up the irqs */
1948 ret = qla2x00_request_irqs(ha, rsp);
1950 goto probe_init_failed;
1951 /* Alloc arrays of request and response ring ptrs */
1953 if (!qla2x00_alloc_queues(ha)) {
1954 qla_printk(KERN_WARNING, ha,
1955 "[ERROR] Failed to allocate memory for queue"
1957 goto probe_init_failed;
1959 ha->rsp_q_map[0] = rsp;
1960 ha->req_q_map[0] = req;
1963 set_bit(0, ha->req_qid_map);
1964 set_bit(0, ha->rsp_qid_map);
1965 /* FWI2-capable only. */
1966 req->req_q_in = &ha->iobase->isp24.req_q_in;
1967 req->req_q_out = &ha->iobase->isp24.req_q_out;
1968 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
1969 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
1971 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
1972 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
1973 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
1974 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
1977 if (qla2x00_initialize_adapter(base_vha)) {
1978 qla_printk(KERN_WARNING, ha,
1979 "Failed to initialize adapter\n");
1981 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1982 "Adapter flags %x.\n",
1983 base_vha->host_no, base_vha->device_flags));
1990 if (qla25xx_setup_mode(base_vha)) {
1991 qla_printk(KERN_WARNING, ha,
1992 "Can't create queues, falling back to single"
1998 if (ha->flags.running_gold_fw)
2002 * Startup the kernel thread for this host adapter
2004 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
2005 "%s_dpc", base_vha->host_str);
2006 if (IS_ERR(ha->dpc_thread)) {
2007 qla_printk(KERN_WARNING, ha,
2008 "Unable to start DPC thread!\n");
2009 ret = PTR_ERR(ha->dpc_thread);
2014 list_add_tail(&base_vha->list, &ha->vp_list);
2015 base_vha->host->irq = ha->pdev->irq;
2017 /* Initialized the timer */
2018 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
2020 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
2021 base_vha->host_no, ha));
2023 base_vha->flags.init_done = 1;
2024 base_vha->flags.online = 1;
2026 ret = scsi_add_host(host, &pdev->dev);
2030 ha->isp_ops->enable_intrs(ha);
2032 scsi_scan_host(host);
2034 qla2x00_alloc_sysfs_attr(base_vha);
2036 qla2x00_init_host_attr(base_vha);
2038 qla2x00_dfs_setup(base_vha);
2040 qla_printk(KERN_INFO, ha, "\n"
2041 " QLogic Fibre Channel HBA Driver: %s\n"
2043 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
2044 qla2x00_version_str, ha->model_number,
2045 ha->model_desc ? ha->model_desc : "", pdev->device,
2046 ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
2047 ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
2048 ha->isp_ops->fw_version_str(base_vha, fw_str));
2053 qla2x00_free_req_que(ha, req);
2054 qla2x00_free_rsp_que(ha, rsp);
2055 ha->max_req_queues = ha->max_rsp_queues = 0;
2058 if (base_vha->timer_active)
2059 qla2x00_stop_timer(base_vha);
2060 base_vha->flags.online = 0;
2061 if (ha->dpc_thread) {
2062 struct task_struct *t = ha->dpc_thread;
2064 ha->dpc_thread = NULL;
2068 qla2x00_free_device(base_vha);
2070 scsi_host_put(base_vha->host);
2074 iounmap(ha->iobase);
2076 pci_release_selected_regions(ha->pdev, ha->bars);
2081 pci_disable_device(pdev);
2086 qla2x00_remove_one(struct pci_dev *pdev)
2088 scsi_qla_host_t *base_vha, *vha, *temp;
2089 struct qla_hw_data *ha;
2091 base_vha = pci_get_drvdata(pdev);
2094 list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
2095 if (vha && vha->fc_vport)
2096 fc_vport_terminate(vha->fc_vport);
2099 set_bit(UNLOADING, &base_vha->dpc_flags);
2101 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2103 qla2x00_dfs_remove(base_vha);
2105 qla84xx_put_chip(base_vha);
2108 if (base_vha->timer_active)
2109 qla2x00_stop_timer(base_vha);
2111 base_vha->flags.online = 0;
2113 /* Flush the work queue and remove it */
2115 flush_workqueue(ha->wq);
2116 destroy_workqueue(ha->wq);
2120 /* Kill the kernel thread for this host */
2121 if (ha->dpc_thread) {
2122 struct task_struct *t = ha->dpc_thread;
2125 * qla2xxx_wake_dpc checks for ->dpc_thread
2126 * so we need to zero it out.
2128 ha->dpc_thread = NULL;
2132 qla2x00_free_sysfs_attr(base_vha);
2134 fc_remove_host(base_vha->host);
2136 scsi_remove_host(base_vha->host);
2138 qla2x00_free_device(base_vha);
2140 scsi_host_put(base_vha->host);
2143 iounmap(ha->iobase);
2146 iounmap(ha->mqiobase);
2148 pci_release_selected_regions(ha->pdev, ha->bars);
2152 pci_disable_device(pdev);
2153 pci_set_drvdata(pdev, NULL);
2157 qla2x00_free_device(scsi_qla_host_t *vha)
2159 struct qla_hw_data *ha = vha->hw;
2161 qla25xx_delete_queues(vha);
2163 if (ha->flags.fce_enabled)
2164 qla2x00_disable_fce_trace(vha, NULL, NULL);
2167 qla2x00_disable_eft_trace(vha);
2169 /* Stop currently executing firmware. */
2170 qla2x00_try_to_stop_firmware(vha);
2172 /* turn-off interrupts on the card */
2173 if (ha->interrupts_on)
2174 ha->isp_ops->disable_intrs(ha);
2176 qla2x00_free_irqs(vha);
2178 qla2x00_mem_free(ha);
2180 qla2x00_free_queues(ha);
2184 qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
2187 struct fc_rport *rport;
2188 scsi_qla_host_t *base_vha;
2193 rport = fcport->rport;
2195 base_vha = pci_get_drvdata(vha->hw->pdev);
2196 spin_lock_irq(vha->host->host_lock);
2197 fcport->drport = rport;
2198 spin_unlock_irq(vha->host->host_lock);
2199 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2200 qla2xxx_wake_dpc(base_vha);
2202 fc_remote_port_delete(rport);
2206 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2208 * Input: ha = adapter block pointer. fcport = port structure pointer.
2214 void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
2215 int do_login, int defer)
2217 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2218 vha->vp_idx == fcport->vp_idx) {
2219 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2220 qla2x00_schedule_rport_del(vha, fcport, defer);
2223 * We may need to retry the login, so don't change the state of the
2224 * port but do the retries.
2226 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2227 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2232 if (fcport->login_retry == 0) {
2233 fcport->login_retry = vha->hw->login_retry_count;
2234 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2236 DEBUG(printk("scsi(%ld): Port login retry: "
2237 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2238 "id = 0x%04x retry cnt=%d\n",
2240 fcport->port_name[0],
2241 fcport->port_name[1],
2242 fcport->port_name[2],
2243 fcport->port_name[3],
2244 fcport->port_name[4],
2245 fcport->port_name[5],
2246 fcport->port_name[6],
2247 fcport->port_name[7],
2249 fcport->login_retry));
2254 * qla2x00_mark_all_devices_lost
2255 * Updates fcport state when device goes offline.
2258 * ha = adapter block pointer.
2259 * fcport = port structure pointer.
2267 qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
2271 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2272 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vp_idx)
2276 * No point in marking the device as lost, if the device is
2279 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2281 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2283 qla2x00_schedule_rport_del(vha, fcport, defer);
2284 else if (vha->vp_idx == fcport->vp_idx)
2285 qla2x00_schedule_rport_del(vha, fcport, defer);
2287 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2293 * Allocates adapter memory.
2300 qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2301 struct req_que **req, struct rsp_que **rsp)
2305 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
2306 &ha->init_cb_dma, GFP_KERNEL);
2310 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2311 &ha->gid_list_dma, GFP_KERNEL);
2313 goto fail_free_init_cb;
2315 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2316 if (!ha->srb_mempool)
2317 goto fail_free_gid_list;
2319 /* Get memory for cached NVRAM */
2320 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2322 goto fail_free_srb_mempool;
2324 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2326 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2327 DMA_POOL_SIZE, 8, 0);
2328 if (!ha->s_dma_pool)
2329 goto fail_free_nvram;
2331 /* Allocate memory for SNS commands */
2332 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2333 /* Get consistent memory allocated for SNS commands */
2334 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
2335 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
2339 /* Get consistent memory allocated for MS IOCB */
2340 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2344 /* Get consistent memory allocated for CT SNS commands */
2345 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
2346 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
2348 goto fail_free_ms_iocb;
2351 /* Allocate memory for request ring */
2352 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2354 DEBUG(printk("Unable to allocate memory for req\n"));
2357 (*req)->length = req_len;
2358 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2359 ((*req)->length + 1) * sizeof(request_t),
2360 &(*req)->dma, GFP_KERNEL);
2361 if (!(*req)->ring) {
2362 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2365 /* Allocate memory for response ring */
2366 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2368 qla_printk(KERN_WARNING, ha,
2369 "Unable to allocate memory for rsp\n");
2373 (*rsp)->length = rsp_len;
2374 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2375 ((*rsp)->length + 1) * sizeof(response_t),
2376 &(*rsp)->dma, GFP_KERNEL);
2377 if (!(*rsp)->ring) {
2378 qla_printk(KERN_WARNING, ha,
2379 "Unable to allocate memory for rsp_ring\n");
2384 /* Allocate memory for NVRAM data for vports */
2385 if (ha->nvram_npiv_size) {
2386 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
2387 ha->nvram_npiv_size, GFP_KERNEL);
2388 if (!ha->npiv_info) {
2389 qla_printk(KERN_WARNING, ha,
2390 "Unable to allocate memory for npiv info\n");
2391 goto fail_npiv_info;
2394 ha->npiv_info = NULL;
2396 /* Get consistent memory allocated for EX-INIT-CB. */
2397 if (IS_QLA81XX(ha)) {
2398 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2399 &ha->ex_init_cb_dma);
2400 if (!ha->ex_init_cb)
2401 goto fail_ex_init_cb;
2404 INIT_LIST_HEAD(&ha->vp_list);
2408 kfree(ha->npiv_info);
2410 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2411 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2412 (*rsp)->ring = NULL;
2417 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2418 sizeof(request_t), (*req)->ring, (*req)->dma);
2419 (*req)->ring = NULL;
2424 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2425 ha->ct_sns, ha->ct_sns_dma);
2429 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2431 ha->ms_iocb_dma = 0;
2433 dma_pool_destroy(ha->s_dma_pool);
2434 ha->s_dma_pool = NULL;
2438 fail_free_srb_mempool:
2439 mempool_destroy(ha->srb_mempool);
2440 ha->srb_mempool = NULL;
2442 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2444 ha->gid_list = NULL;
2445 ha->gid_list_dma = 0;
2447 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2450 ha->init_cb_dma = 0;
2452 DEBUG(printk("%s: Memory allocation failure\n", __func__));
2458 * Frees all adapter allocated memory.
2461 * ha = adapter block pointer.
2464 qla2x00_mem_free(struct qla_hw_data *ha)
2466 if (ha->srb_mempool)
2467 mempool_destroy(ha->srb_mempool);
2470 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
2475 dma_free_coherent(&ha->pdev->dev,
2476 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
2481 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
2482 ha->dcbx_tlv, ha->dcbx_tlv_dma);
2485 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
2486 ha->xgmac_data, ha->xgmac_data_dma);
2489 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
2490 ha->sns_cmd, ha->sns_cmd_dma);
2493 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2494 ha->ct_sns, ha->ct_sns_dma);
2497 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2500 dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
2503 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2506 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
2509 dma_pool_destroy(ha->s_dma_pool);
2512 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2516 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2517 ha->init_cb, ha->init_cb_dma);
2518 vfree(ha->optrom_buffer);
2520 kfree(ha->npiv_info);
2522 ha->srb_mempool = NULL;
2526 ha->sns_cmd_dma = 0;
2530 ha->ms_iocb_dma = 0;
2532 ha->init_cb_dma = 0;
2533 ha->ex_init_cb = NULL;
2534 ha->ex_init_cb_dma = 0;
2536 ha->s_dma_pool = NULL;
2538 ha->gid_list = NULL;
2539 ha->gid_list_dma = 0;
2543 ha->fw_dump_reading = 0;
2546 struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
2547 struct qla_hw_data *ha)
2549 struct Scsi_Host *host;
2550 struct scsi_qla_host *vha = NULL;
2552 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
2555 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2559 /* Clear our data area */
2560 vha = shost_priv(host);
2561 memset(vha, 0, sizeof(scsi_qla_host_t));
2564 vha->host_no = host->host_no;
2567 INIT_LIST_HEAD(&vha->vp_fcports);
2568 INIT_LIST_HEAD(&vha->work_list);
2569 INIT_LIST_HEAD(&vha->list);
2571 spin_lock_init(&vha->work_lock);
2573 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
2580 static struct qla_work_evt *
2581 qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
2583 struct qla_work_evt *e;
2585 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
2589 INIT_LIST_HEAD(&e->list);
2591 e->flags = QLA_EVT_FLAG_FREE;
2596 qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
2598 unsigned long flags;
2600 spin_lock_irqsave(&vha->work_lock, flags);
2601 list_add_tail(&e->list, &vha->work_list);
2602 spin_unlock_irqrestore(&vha->work_lock, flags);
2603 qla2xxx_wake_dpc(vha);
2609 qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
2612 struct qla_work_evt *e;
2614 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
2616 return QLA_FUNCTION_FAILED;
2618 e->u.aen.code = code;
2619 e->u.aen.data = data;
2620 return qla2x00_post_work(vha, e);
2624 qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
2626 struct qla_work_evt *e;
2628 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
2630 return QLA_FUNCTION_FAILED;
2632 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
2633 return qla2x00_post_work(vha, e);
2636 #define qla2x00_post_async_work(name, type) \
2637 int qla2x00_post_async_##name##_work( \
2638 struct scsi_qla_host *vha, \
2639 fc_port_t *fcport, uint16_t *data) \
2641 struct qla_work_evt *e; \
2643 e = qla2x00_alloc_work(vha, type); \
2645 return QLA_FUNCTION_FAILED; \
2647 e->u.logio.fcport = fcport; \
2649 e->u.logio.data[0] = data[0]; \
2650 e->u.logio.data[1] = data[1]; \
2652 return qla2x00_post_work(vha, e); \
2655 qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
2656 qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
2657 qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
2658 qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
2661 qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
2663 struct qla_work_evt *e;
2665 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
2667 return QLA_FUNCTION_FAILED;
2669 e->u.uevent.code = code;
2670 return qla2x00_post_work(vha, e);
2674 qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
2676 char event_string[40];
2677 char *envp[] = { event_string, NULL };
2680 case QLA_UEVENT_CODE_FW_DUMP:
2681 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
2688 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
2692 qla2x00_do_work(struct scsi_qla_host *vha)
2694 struct qla_work_evt *e, *tmp;
2695 unsigned long flags;
2698 spin_lock_irqsave(&vha->work_lock, flags);
2699 list_splice_init(&vha->work_list, &work);
2700 spin_unlock_irqrestore(&vha->work_lock, flags);
2702 list_for_each_entry_safe(e, tmp, &work, list) {
2703 list_del_init(&e->list);
2707 fc_host_post_event(vha->host, fc_get_event_number(),
2708 e->u.aen.code, e->u.aen.data);
2710 case QLA_EVT_IDC_ACK:
2711 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
2713 case QLA_EVT_ASYNC_LOGIN:
2714 qla2x00_async_login(vha, e->u.logio.fcport,
2717 case QLA_EVT_ASYNC_LOGIN_DONE:
2718 qla2x00_async_login_done(vha, e->u.logio.fcport,
2721 case QLA_EVT_ASYNC_LOGOUT:
2722 qla2x00_async_logout(vha, e->u.logio.fcport);
2724 case QLA_EVT_ASYNC_LOGOUT_DONE:
2725 qla2x00_async_logout_done(vha, e->u.logio.fcport,
2728 case QLA_EVT_UEVENT:
2729 qla2x00_uevent_emit(vha, e->u.uevent.code);
2732 if (e->flags & QLA_EVT_FLAG_FREE)
2737 /* Relogins all the fcports of a vport
2738 * Context: dpc thread
2740 void qla2x00_relogin(struct scsi_qla_host *vha)
2744 uint16_t next_loopid = 0;
2745 struct qla_hw_data *ha = vha->hw;
2748 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2750 * If the port is not ONLINE then try to login
2751 * to it if we haven't run out of retries.
2753 if (atomic_read(&fcport->state) !=
2754 FCS_ONLINE && fcport->login_retry) {
2756 fcport->login_retry--;
2757 if (fcport->flags & FCF_FABRIC_DEVICE) {
2758 if (fcport->flags & FCF_TAPE_PRESENT)
2759 ha->isp_ops->fabric_logout(vha,
2761 fcport->d_id.b.domain,
2762 fcport->d_id.b.area,
2763 fcport->d_id.b.al_pa);
2765 if (IS_ALOGIO_CAPABLE(ha)) {
2767 data[1] = QLA_LOGIO_LOGIN_RETRIED;
2768 status = qla2x00_post_async_login_work(
2770 if (status == QLA_SUCCESS)
2772 /* Attempt a retry. */
2775 status = qla2x00_fabric_login(vha,
2776 fcport, &next_loopid);
2778 status = qla2x00_local_device_login(vha,
2781 if (status == QLA_SUCCESS) {
2782 fcport->old_loop_id = fcport->loop_id;
2784 DEBUG(printk("scsi(%ld): port login OK: logged "
2785 "in ID 0x%x\n", vha->host_no, fcport->loop_id));
2787 qla2x00_update_fcport(vha, fcport);
2789 } else if (status == 1) {
2790 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2791 /* retry the login again */
2792 DEBUG(printk("scsi(%ld): Retrying"
2793 " %d login again loop_id 0x%x\n",
2794 vha->host_no, fcport->login_retry,
2797 fcport->login_retry = 0;
2800 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
2801 fcport->loop_id = FC_NO_LOOP_ID;
2803 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2808 /**************************************************************************
2810 * This kernel thread is a task that is schedule by the interrupt handler
2811 * to perform the background processing for interrupts.
2814 * This task always run in the context of a kernel thread. It
2815 * is kick-off by the driver's detect code and starts up
2816 * up one per adapter. It immediately goes to sleep and waits for
2817 * some fibre event. When either the interrupt handler or
2818 * the timer routine detects a event it will one of the task
2819 * bits then wake us up.
2820 **************************************************************************/
2822 qla2x00_do_dpc(void *data)
2825 scsi_qla_host_t *base_vha;
2826 struct qla_hw_data *ha;
2828 ha = (struct qla_hw_data *)data;
2829 base_vha = pci_get_drvdata(ha->pdev);
2831 set_user_nice(current, -20);
2833 while (!kthread_should_stop()) {
2834 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2836 set_current_state(TASK_INTERRUPTIBLE);
2838 __set_current_state(TASK_RUNNING);
2840 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2842 /* Initialization not yet finished. Don't do anything yet. */
2843 if (!base_vha->flags.init_done)
2846 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
2850 if (ha->flags.mbox_busy) {
2855 qla2x00_do_work(base_vha);
2857 if (test_and_clear_bit(ISP_ABORT_NEEDED,
2858 &base_vha->dpc_flags)) {
2860 DEBUG(printk("scsi(%ld): dpc: sched "
2861 "qla2x00_abort_isp ha = %p\n",
2862 base_vha->host_no, ha));
2863 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2864 &base_vha->dpc_flags))) {
2866 if (qla2x00_abort_isp(base_vha)) {
2867 /* failed. retry later */
2868 set_bit(ISP_ABORT_NEEDED,
2869 &base_vha->dpc_flags);
2871 clear_bit(ABORT_ISP_ACTIVE,
2872 &base_vha->dpc_flags);
2875 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2876 base_vha->host_no));
2879 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
2880 qla2x00_update_fcports(base_vha);
2881 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2884 if (test_and_clear_bit(RESET_MARKER_NEEDED,
2885 &base_vha->dpc_flags) &&
2886 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
2888 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2889 base_vha->host_no));
2891 qla2x00_rst_aen(base_vha);
2892 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
2895 /* Retry each device up to login retry count */
2896 if ((test_and_clear_bit(RELOGIN_NEEDED,
2897 &base_vha->dpc_flags)) &&
2898 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
2899 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
2901 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2902 base_vha->host_no));
2903 qla2x00_relogin(base_vha);
2905 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2906 base_vha->host_no));
2909 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
2910 &base_vha->dpc_flags)) {
2912 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2913 base_vha->host_no));
2915 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2916 &base_vha->dpc_flags))) {
2918 rval = qla2x00_loop_resync(base_vha);
2920 clear_bit(LOOP_RESYNC_ACTIVE,
2921 &base_vha->dpc_flags);
2924 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2925 base_vha->host_no));
2928 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
2929 atomic_read(&base_vha->loop_state) == LOOP_READY) {
2930 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
2931 qla2xxx_flash_npiv_conf(base_vha);
2934 if (!ha->interrupts_on)
2935 ha->isp_ops->enable_intrs(ha);
2937 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
2938 &base_vha->dpc_flags))
2939 ha->isp_ops->beacon_blink(base_vha);
2941 qla2x00_do_dpc_all_vps(base_vha);
2944 } /* End of while(1) */
2946 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
2949 * Make sure that nobody tries to wake us up again.
2953 /* Cleanup any residual CTX SRBs. */
2954 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2960 qla2xxx_wake_dpc(struct scsi_qla_host *vha)
2962 struct qla_hw_data *ha = vha->hw;
2963 struct task_struct *t = ha->dpc_thread;
2965 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
2971 * Processes asynchronous reset.
2974 * ha = adapter block pointer.
2977 qla2x00_rst_aen(scsi_qla_host_t *vha)
2979 if (vha->flags.online && !vha->flags.reset_active &&
2980 !atomic_read(&vha->loop_down_timer) &&
2981 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
2983 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
2986 * Issue marker command only when we are going to start
2989 vha->marker_needed = 1;
2990 } while (!atomic_read(&vha->loop_down_timer) &&
2991 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
2996 qla2x00_sp_free_dma(srb_t *sp)
2998 struct scsi_cmnd *cmd = sp->cmd;
3000 if (sp->flags & SRB_DMA_VALID) {
3001 scsi_dma_unmap(cmd);
3002 sp->flags &= ~SRB_DMA_VALID;
3008 qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
3010 struct scsi_cmnd *cmd = sp->cmd;
3012 qla2x00_sp_free_dma(sp);
3014 mempool_free(sp, ha->srb_mempool);
3016 cmd->scsi_done(cmd);
3019 /**************************************************************************
3025 * Context: Interrupt
3026 ***************************************************************************/
3028 qla2x00_timer(scsi_qla_host_t *vha)
3030 unsigned long cpu_flags = 0;
3036 struct qla_hw_data *ha = vha->hw;
3037 struct req_que *req;
3039 * Ports - Port down timer.
3041 * Whenever, a port is in the LOST state we start decrementing its port
3042 * down timer every second until it reaches zero. Once it reaches zero
3043 * the port it marked DEAD.
3046 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3047 if (fcport->port_type != FCT_TARGET)
3050 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
3052 if (atomic_read(&fcport->port_down_timer) == 0)
3055 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
3056 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
3058 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
3061 t, atomic_read(&fcport->port_down_timer)));
3064 } /* End of for fcport */
3067 /* Loop down handler. */
3068 if (atomic_read(&vha->loop_down_timer) > 0 &&
3069 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
3070 && vha->flags.online) {
3072 if (atomic_read(&vha->loop_down_timer) ==
3073 vha->loop_down_abort_time) {
3075 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
3076 "queues before time expire\n",
3079 if (!IS_QLA2100(ha) && vha->link_down_timeout)
3080 atomic_set(&vha->loop_state, LOOP_DEAD);
3082 /* Schedule an ISP abort to return any tape commands. */
3083 /* NPIV - scan physical port only */
3085 spin_lock_irqsave(&ha->hardware_lock,
3087 req = ha->req_q_map[0];
3089 index < MAX_OUTSTANDING_COMMANDS;
3093 sp = req->outstanding_cmds[index];
3099 if (!(sfcp->flags & FCF_TAPE_PRESENT))
3102 set_bit(ISP_ABORT_NEEDED,
3106 spin_unlock_irqrestore(&ha->hardware_lock,
3112 /* if the loop has been down for 4 minutes, reinit adapter */
3113 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
3114 if (!(vha->device_flags & DFLG_NO_CABLE)) {
3115 DEBUG(printk("scsi(%ld): Loop down - "
3118 qla_printk(KERN_WARNING, ha,
3119 "Loop down - aborting ISP.\n");
3121 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3124 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
3126 atomic_read(&vha->loop_down_timer)));
3129 /* Check if beacon LED needs to be blinked */
3130 if (ha->beacon_blink_led == 1) {
3131 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
3135 /* Process any deferred work. */
3136 if (!list_empty(&vha->work_list))
3139 /* Schedule the DPC routine if needed */
3140 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
3141 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
3142 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
3144 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
3145 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
3146 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
3147 test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
3148 qla2xxx_wake_dpc(vha);
3150 qla2x00_restart_timer(vha, WATCH_INTERVAL);
3153 /* Firmware interface routines. */
3156 #define FW_ISP21XX 0
3157 #define FW_ISP22XX 1
3158 #define FW_ISP2300 2
3159 #define FW_ISP2322 3
3160 #define FW_ISP24XX 4
3161 #define FW_ISP25XX 5
3162 #define FW_ISP81XX 6
3164 #define FW_FILE_ISP21XX "ql2100_fw.bin"
3165 #define FW_FILE_ISP22XX "ql2200_fw.bin"
3166 #define FW_FILE_ISP2300 "ql2300_fw.bin"
3167 #define FW_FILE_ISP2322 "ql2322_fw.bin"
3168 #define FW_FILE_ISP24XX "ql2400_fw.bin"
3169 #define FW_FILE_ISP25XX "ql2500_fw.bin"
3170 #define FW_FILE_ISP81XX "ql8100_fw.bin"
3172 static DEFINE_MUTEX(qla_fw_lock);
3174 static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
3175 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
3176 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
3177 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
3178 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
3179 { .name = FW_FILE_ISP24XX, },
3180 { .name = FW_FILE_ISP25XX, },
3181 { .name = FW_FILE_ISP81XX, },
3185 qla2x00_request_firmware(scsi_qla_host_t *vha)
3187 struct qla_hw_data *ha = vha->hw;
3188 struct fw_blob *blob;
3191 if (IS_QLA2100(ha)) {
3192 blob = &qla_fw_blobs[FW_ISP21XX];
3193 } else if (IS_QLA2200(ha)) {
3194 blob = &qla_fw_blobs[FW_ISP22XX];
3195 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3196 blob = &qla_fw_blobs[FW_ISP2300];
3197 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
3198 blob = &qla_fw_blobs[FW_ISP2322];
3199 } else if (IS_QLA24XX_TYPE(ha)) {
3200 blob = &qla_fw_blobs[FW_ISP24XX];
3201 } else if (IS_QLA25XX(ha)) {
3202 blob = &qla_fw_blobs[FW_ISP25XX];
3203 } else if (IS_QLA81XX(ha)) {
3204 blob = &qla_fw_blobs[FW_ISP81XX];
3207 mutex_lock(&qla_fw_lock);
3211 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
3212 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
3213 "(%s).\n", vha->host_no, blob->name));
3220 mutex_unlock(&qla_fw_lock);
3225 qla2x00_release_firmware(void)
3229 mutex_lock(&qla_fw_lock);
3230 for (idx = 0; idx < FW_BLOBS; idx++)
3231 if (qla_fw_blobs[idx].fw)
3232 release_firmware(qla_fw_blobs[idx].fw);
3233 mutex_unlock(&qla_fw_lock);
3236 static pci_ers_result_t
3237 qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3239 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3242 case pci_channel_io_normal:
3243 return PCI_ERS_RESULT_CAN_RECOVER;
3244 case pci_channel_io_frozen:
3245 pci_disable_device(pdev);
3246 return PCI_ERS_RESULT_NEED_RESET;
3247 case pci_channel_io_perm_failure:
3248 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3249 return PCI_ERS_RESULT_DISCONNECT;
3251 return PCI_ERS_RESULT_NEED_RESET;
3254 static pci_ers_result_t
3255 qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
3257 int risc_paused = 0;
3259 unsigned long flags;
3260 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3261 struct qla_hw_data *ha = base_vha->hw;
3262 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3263 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
3265 spin_lock_irqsave(&ha->hardware_lock, flags);
3266 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
3267 stat = RD_REG_DWORD(®->hccr);
3268 if (stat & HCCR_RISC_PAUSE)
3270 } else if (IS_QLA23XX(ha)) {
3271 stat = RD_REG_DWORD(®->u.isp2300.host_status);
3272 if (stat & HSR_RISC_PAUSED)
3274 } else if (IS_FWI2_CAPABLE(ha)) {
3275 stat = RD_REG_DWORD(®24->host_status);
3276 if (stat & HSRX_RISC_PAUSED)
3279 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3282 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
3283 "Dumping firmware!\n");
3284 ha->isp_ops->fw_dump(base_vha, 0);
3286 return PCI_ERS_RESULT_NEED_RESET;
3288 return PCI_ERS_RESULT_RECOVERED;
3291 static pci_ers_result_t
3292 qla2xxx_pci_slot_reset(struct pci_dev *pdev)
3294 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
3295 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3296 struct qla_hw_data *ha = base_vha->hw;
3300 rc = pci_enable_device_mem(pdev);
3302 rc = pci_enable_device(pdev);
3305 qla_printk(KERN_WARNING, ha,
3306 "Can't re-enable PCI device after reset.\n");
3310 pci_set_master(pdev);
3312 if (ha->isp_ops->pci_config(base_vha))
3315 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3316 if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
3317 ret = PCI_ERS_RESULT_RECOVERED;
3318 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3324 qla2xxx_pci_resume(struct pci_dev *pdev)
3326 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3327 struct qla_hw_data *ha = base_vha->hw;
3330 ret = qla2x00_wait_for_hba_online(base_vha);
3331 if (ret != QLA_SUCCESS) {
3332 qla_printk(KERN_ERR, ha,
3333 "the device failed to resume I/O "
3334 "from slot/link_reset");
3336 pci_cleanup_aer_uncorrect_error_status(pdev);
3339 static struct pci_error_handlers qla2xxx_err_handler = {
3340 .error_detected = qla2xxx_pci_error_detected,
3341 .mmio_enabled = qla2xxx_pci_mmio_enabled,
3342 .slot_reset = qla2xxx_pci_slot_reset,
3343 .resume = qla2xxx_pci_resume,
3346 static struct pci_device_id qla2xxx_pci_tbl[] = {
3347 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
3348 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
3349 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
3350 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
3351 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
3352 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
3353 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
3354 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
3355 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
3356 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
3357 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
3358 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
3359 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
3360 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
3363 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
3365 static struct pci_driver qla2xxx_pci_driver = {
3366 .name = QLA2XXX_DRIVER_NAME,
3368 .owner = THIS_MODULE,
3370 .id_table = qla2xxx_pci_tbl,
3371 .probe = qla2x00_probe_one,
3372 .remove = qla2x00_remove_one,
3373 .err_handler = &qla2xxx_err_handler,
3377 * qla2x00_module_init - Module initialization.
3380 qla2x00_module_init(void)
3384 /* Allocate cache for SRBs. */
3385 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
3386 SLAB_HWCACHE_ALIGN, NULL);
3387 if (srb_cachep == NULL) {
3389 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3393 /* Derive version string. */
3394 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
3395 if (ql2xextended_error_logging)
3396 strcat(qla2x00_version_str, "-debug");
3398 qla2xxx_transport_template =
3399 fc_attach_transport(&qla2xxx_transport_functions);
3400 if (!qla2xxx_transport_template) {
3401 kmem_cache_destroy(srb_cachep);
3404 qla2xxx_transport_vport_template =
3405 fc_attach_transport(&qla2xxx_transport_vport_functions);
3406 if (!qla2xxx_transport_vport_template) {
3407 kmem_cache_destroy(srb_cachep);
3408 fc_release_transport(qla2xxx_transport_template);
3412 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
3413 qla2x00_version_str);
3414 ret = pci_register_driver(&qla2xxx_pci_driver);
3416 kmem_cache_destroy(srb_cachep);
3417 fc_release_transport(qla2xxx_transport_template);
3418 fc_release_transport(qla2xxx_transport_vport_template);
3424 * qla2x00_module_exit - Module cleanup.
3427 qla2x00_module_exit(void)
3429 pci_unregister_driver(&qla2xxx_pci_driver);
3430 qla2x00_release_firmware();
3431 kmem_cache_destroy(srb_cachep);
3432 fc_release_transport(qla2xxx_transport_template);
3433 fc_release_transport(qla2xxx_transport_vport_template);
3436 module_init(qla2x00_module_init);
3437 module_exit(qla2x00_module_exit);
3439 MODULE_AUTHOR("QLogic Corporation");
3440 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3441 MODULE_LICENSE("GPL");
3442 MODULE_VERSION(QLA2XXX_VERSION);
3443 MODULE_FIRMWARE(FW_FILE_ISP21XX);
3444 MODULE_FIRMWARE(FW_FILE_ISP22XX);
3445 MODULE_FIRMWARE(FW_FILE_ISP2300);
3446 MODULE_FIRMWARE(FW_FILE_ISP2322);
3447 MODULE_FIRMWARE(FW_FILE_ISP24XX);
3448 MODULE_FIRMWARE(FW_FILE_ISP25XX);
3449 MODULE_FIRMWARE(FW_FILE_ISP81XX);