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 ql2xiidmaenable=1;
82 module_param(ql2xiidmaenable, int, S_IRUGO|S_IRUSR);
83 MODULE_PARM_DESC(ql2xiidmaenable,
84 "Enables iIDMA settings "
85 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
87 int ql2xmaxqueues = 1;
88 module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR);
89 MODULE_PARM_DESC(ql2xmaxqueues,
90 "Enables MQ settings "
91 "Default is 1 for single queue. Set it to number \
92 of queues in MQ mode.");
95 module_param(ql2xmultique_tag, int, S_IRUGO|S_IRUSR);
96 MODULE_PARM_DESC(ql2xmultique_tag,
97 "Enables CPU affinity settings for the driver "
98 "Default is 0 for no affinity of request and response IO. "
99 "Set it to 1 to turn on the cpu affinity.");
102 module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR);
103 MODULE_PARM_DESC(ql2xfwloadbin,
104 "Option to specify location from which to load ISP firmware:\n"
105 " 2 -- load firmware via the request_firmware() (hotplug)\n"
107 " 1 -- load firmware from flash.\n"
108 " 0 -- use default semantics.\n");
111 * SCSI host template entry points
113 static int qla2xxx_slave_configure(struct scsi_device * device);
114 static int qla2xxx_slave_alloc(struct scsi_device *);
115 static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
116 static void qla2xxx_scan_start(struct Scsi_Host *);
117 static void qla2xxx_slave_destroy(struct scsi_device *);
118 static int qla2xxx_queuecommand(struct scsi_cmnd *cmd,
119 void (*fn)(struct scsi_cmnd *));
120 static int qla2xxx_eh_abort(struct scsi_cmnd *);
121 static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
122 static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
123 static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
124 static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
126 static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
127 static int qla2x00_change_queue_type(struct scsi_device *, int);
129 struct scsi_host_template qla2xxx_driver_template = {
130 .module = THIS_MODULE,
131 .name = QLA2XXX_DRIVER_NAME,
132 .queuecommand = qla2xxx_queuecommand,
134 .eh_abort_handler = qla2xxx_eh_abort,
135 .eh_device_reset_handler = qla2xxx_eh_device_reset,
136 .eh_target_reset_handler = qla2xxx_eh_target_reset,
137 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
138 .eh_host_reset_handler = qla2xxx_eh_host_reset,
140 .slave_configure = qla2xxx_slave_configure,
142 .slave_alloc = qla2xxx_slave_alloc,
143 .slave_destroy = qla2xxx_slave_destroy,
144 .scan_finished = qla2xxx_scan_finished,
145 .scan_start = qla2xxx_scan_start,
146 .change_queue_depth = qla2x00_change_queue_depth,
147 .change_queue_type = qla2x00_change_queue_type,
150 .use_clustering = ENABLE_CLUSTERING,
151 .sg_tablesize = SG_ALL,
153 .max_sectors = 0xFFFF,
154 .shost_attrs = qla2x00_host_attrs,
157 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
158 struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
160 /* TODO Convert to inlines
166 qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
168 init_timer(&vha->timer);
169 vha->timer.expires = jiffies + interval * HZ;
170 vha->timer.data = (unsigned long)vha;
171 vha->timer.function = (void (*)(unsigned long))func;
172 add_timer(&vha->timer);
173 vha->timer_active = 1;
177 qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
179 mod_timer(&vha->timer, jiffies + interval * HZ);
182 static __inline__ void
183 qla2x00_stop_timer(scsi_qla_host_t *vha)
185 del_timer_sync(&vha->timer);
186 vha->timer_active = 0;
189 static int qla2x00_do_dpc(void *data);
191 static void qla2x00_rst_aen(scsi_qla_host_t *);
193 static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
194 struct req_que **, struct rsp_que **);
195 static void qla2x00_mem_free(struct qla_hw_data *);
196 static void qla2x00_sp_free_dma(srb_t *);
198 /* -------------------------------------------------------------------------- */
199 static int qla2x00_alloc_queues(struct qla_hw_data *ha)
201 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
203 if (!ha->req_q_map) {
204 qla_printk(KERN_WARNING, ha,
205 "Unable to allocate memory for request queue ptrs\n");
209 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
211 if (!ha->rsp_q_map) {
212 qla_printk(KERN_WARNING, ha,
213 "Unable to allocate memory for response queue ptrs\n");
216 set_bit(0, ha->rsp_qid_map);
217 set_bit(0, ha->req_qid_map);
221 kfree(ha->req_q_map);
222 ha->req_q_map = NULL;
227 static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
229 if (req && req->ring)
230 dma_free_coherent(&ha->pdev->dev,
231 (req->length + 1) * sizeof(request_t),
232 req->ring, req->dma);
238 static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
240 if (rsp && rsp->ring)
241 dma_free_coherent(&ha->pdev->dev,
242 (rsp->length + 1) * sizeof(response_t),
243 rsp->ring, rsp->dma);
249 static void qla2x00_free_queues(struct qla_hw_data *ha)
255 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
256 req = ha->req_q_map[cnt];
257 qla2x00_free_req_que(ha, req);
259 kfree(ha->req_q_map);
260 ha->req_q_map = NULL;
262 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
263 rsp = ha->rsp_q_map[cnt];
264 qla2x00_free_rsp_que(ha, rsp);
266 kfree(ha->rsp_q_map);
267 ha->rsp_q_map = NULL;
270 static int qla25xx_setup_mode(struct scsi_qla_host *vha)
272 uint16_t options = 0;
274 struct qla_hw_data *ha = vha->hw;
276 if (!(ha->fw_attributes & BIT_6)) {
277 qla_printk(KERN_INFO, ha,
278 "Firmware is not multi-queue capable\n");
281 if (ql2xmultique_tag) {
282 /* create a request queue for IO */
284 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
285 QLA_DEFAULT_QUE_QOS);
287 qla_printk(KERN_WARNING, ha,
288 "Can't create request queue\n");
291 ha->wq = create_workqueue("qla2xxx_wq");
292 vha->req = ha->req_q_map[req];
294 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
295 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
297 qla_printk(KERN_WARNING, ha,
298 "Response Queue create failed\n");
302 ha->flags.cpu_affinity_enabled = 1;
304 DEBUG2(qla_printk(KERN_INFO, ha,
305 "CPU affinity mode enabled, no. of response"
306 " queues:%d, no. of request queues:%d\n",
307 ha->max_rsp_queues, ha->max_req_queues));
311 qla25xx_delete_queues(vha);
312 destroy_workqueue(ha->wq);
316 kfree(ha->req_q_map);
317 kfree(ha->rsp_q_map);
318 ha->max_req_queues = ha->max_rsp_queues = 1;
323 qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
325 struct qla_hw_data *ha = vha->hw;
326 static char *pci_bus_modes[] = {
327 "33", "66", "100", "133",
332 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
335 strcat(str, pci_bus_modes[pci_bus]);
337 pci_bus = (ha->pci_attr & BIT_8) >> 8;
339 strcat(str, pci_bus_modes[pci_bus]);
341 strcat(str, " MHz)");
347 qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
349 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
350 struct qla_hw_data *ha = vha->hw;
354 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
357 uint16_t pcie_lstat, lspeed, lwidth;
360 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
361 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
362 lwidth = (pcie_lstat &
363 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
365 strcpy(str, "PCIe (");
367 strcat(str, "2.5GT/s ");
368 else if (lspeed == 2)
369 strcat(str, "5.0GT/s ");
371 strcat(str, "<unknown> ");
372 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
379 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
380 if (pci_bus == 0 || pci_bus == 8) {
382 strcat(str, pci_bus_modes[pci_bus >> 3]);
386 strcat(str, "Mode 2");
388 strcat(str, "Mode 1");
390 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
392 strcat(str, " MHz)");
398 qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
401 struct qla_hw_data *ha = vha->hw;
403 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
404 ha->fw_minor_version,
405 ha->fw_subminor_version);
407 if (ha->fw_attributes & BIT_9) {
412 switch (ha->fw_attributes & 0xFF) {
426 sprintf(un_str, "(%x)", ha->fw_attributes);
430 if (ha->fw_attributes & 0x100)
437 qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
439 struct qla_hw_data *ha = vha->hw;
441 sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
442 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
446 static inline srb_t *
447 qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
448 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
451 struct qla_hw_data *ha = vha->hw;
453 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
460 CMD_SP(cmd) = (void *)sp;
461 cmd->scsi_done = done;
468 qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
470 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
471 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
472 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
473 struct qla_hw_data *ha = vha->hw;
474 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
478 if (unlikely(pci_channel_offline(ha->pdev))) {
479 if (ha->pdev->error_state == pci_channel_io_frozen)
480 cmd->result = DID_REQUEUE << 16;
482 cmd->result = DID_NO_CONNECT << 16;
483 goto qc24_fail_command;
486 rval = fc_remote_port_chkready(rport);
489 goto qc24_fail_command;
492 /* Close window on fcport/rport state-transitioning. */
494 goto qc24_target_busy;
496 if (atomic_read(&fcport->state) != FCS_ONLINE) {
497 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
498 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
499 cmd->result = DID_NO_CONNECT << 16;
500 goto qc24_fail_command;
502 goto qc24_target_busy;
505 spin_unlock_irq(vha->host->host_lock);
507 sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
509 goto qc24_host_busy_lock;
511 rval = ha->isp_ops->start_scsi(sp);
512 if (rval != QLA_SUCCESS)
513 goto qc24_host_busy_free_sp;
515 spin_lock_irq(vha->host->host_lock);
519 qc24_host_busy_free_sp:
520 qla2x00_sp_free_dma(sp);
521 mempool_free(sp, ha->srb_mempool);
524 spin_lock_irq(vha->host->host_lock);
525 return SCSI_MLQUEUE_HOST_BUSY;
528 return SCSI_MLQUEUE_TARGET_BUSY;
538 * qla2x00_eh_wait_on_command
539 * Waits for the command to be returned by the Firmware for some
543 * cmd = Scsi Command to wait on.
550 qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
552 #define ABORT_POLLING_PERIOD 1000
553 #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
554 unsigned long wait_iter = ABORT_WAIT_ITER;
555 int ret = QLA_SUCCESS;
557 while (CMD_SP(cmd) && wait_iter--) {
558 msleep(ABORT_POLLING_PERIOD);
561 ret = QLA_FUNCTION_FAILED;
567 * qla2x00_wait_for_hba_online
568 * Wait till the HBA is online after going through
569 * <= MAX_RETRIES_OF_ISP_ABORT or
570 * finally HBA is disabled ie marked offline
573 * ha - pointer to host adapter structure
576 * Does context switching-Release SPIN_LOCK
577 * (if any) before calling this routine.
580 * Success (Adapter is online) : 0
581 * Failed (Adapter is offline/disabled) : 1
584 qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
587 unsigned long wait_online;
588 struct qla_hw_data *ha = vha->hw;
589 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
591 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
592 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
593 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
594 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
595 ha->dpc_active) && time_before(jiffies, wait_online)) {
599 if (base_vha->flags.online)
600 return_status = QLA_SUCCESS;
602 return_status = QLA_FUNCTION_FAILED;
604 return (return_status);
608 qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
611 unsigned long wait_reset;
612 struct qla_hw_data *ha = vha->hw;
613 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
615 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
616 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
617 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
618 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
619 ha->dpc_active) && time_before(jiffies, wait_reset)) {
623 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
624 ha->flags.chip_reset_done)
627 if (ha->flags.chip_reset_done)
628 return_status = QLA_SUCCESS;
630 return_status = QLA_FUNCTION_FAILED;
632 return return_status;
636 * qla2x00_wait_for_loop_ready
637 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
638 * to be in LOOP_READY state.
640 * ha - pointer to host adapter structure
643 * Does context switching-Release SPIN_LOCK
644 * (if any) before calling this routine.
648 * Success (LOOP_READY) : 0
649 * Failed (LOOP_NOT_READY) : 1
652 qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
654 int return_status = QLA_SUCCESS;
655 unsigned long loop_timeout ;
656 struct qla_hw_data *ha = vha->hw;
657 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
659 /* wait for 5 min at the max for loop to be ready */
660 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
662 while ((!atomic_read(&base_vha->loop_down_timer) &&
663 atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
664 atomic_read(&base_vha->loop_state) != LOOP_READY) {
665 if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
666 return_status = QLA_FUNCTION_FAILED;
670 if (time_after_eq(jiffies, loop_timeout)) {
671 return_status = QLA_FUNCTION_FAILED;
675 return (return_status);
679 qla2x00_abort_fcport_cmds(fc_port_t *fcport)
684 scsi_qla_host_t *vha = fcport->vha;
685 struct qla_hw_data *ha = vha->hw;
688 spin_lock_irqsave(&ha->hardware_lock, flags);
690 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
691 sp = req->outstanding_cmds[cnt];
694 if (sp->fcport != fcport)
699 spin_unlock_irqrestore(&ha->hardware_lock, flags);
700 if (ha->isp_ops->abort_command(sp)) {
701 DEBUG2(qla_printk(KERN_WARNING, ha,
702 "Abort failed -- %lx\n",
703 sp->cmd->serial_number));
705 if (qla2x00_eh_wait_on_command(sp->cmd) !=
707 DEBUG2(qla_printk(KERN_WARNING, ha,
708 "Abort failed while waiting -- %lx\n",
709 sp->cmd->serial_number));
711 spin_lock_irqsave(&ha->hardware_lock, flags);
713 spin_unlock_irqrestore(&ha->hardware_lock, flags);
716 /**************************************************************************
720 * The abort function will abort the specified command.
723 * cmd = Linux SCSI command packet to be aborted.
726 * Either SUCCESS or FAILED.
729 * Only return FAILED if command not returned by firmware.
730 **************************************************************************/
732 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
734 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
737 unsigned int id, lun;
738 unsigned long serial;
741 struct qla_hw_data *ha = vha->hw;
742 struct req_que *req = vha->req;
745 fc_block_scsi_eh(cmd);
752 id = cmd->device->id;
753 lun = cmd->device->lun;
754 serial = cmd->serial_number;
755 spt = (srb_t *) CMD_SP(cmd);
759 /* Check active list for command command. */
760 spin_lock_irqsave(&ha->hardware_lock, flags);
761 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
762 sp = req->outstanding_cmds[i];
771 DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
772 " pid=%ld.\n", __func__, vha->host_no, sp, serial));
774 spin_unlock_irqrestore(&ha->hardware_lock, flags);
775 if (ha->isp_ops->abort_command(sp)) {
776 DEBUG2(printk("%s(%ld): abort_command "
777 "mbx failed.\n", __func__, vha->host_no));
780 DEBUG3(printk("%s(%ld): abort_command "
781 "mbx success.\n", __func__, vha->host_no));
784 spin_lock_irqsave(&ha->hardware_lock, flags);
787 spin_unlock_irqrestore(&ha->hardware_lock, flags);
789 /* Wait for the command to be returned. */
791 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
792 qla_printk(KERN_ERR, ha,
793 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
794 "%x.\n", vha->host_no, id, lun, serial, ret);
799 qla_printk(KERN_INFO, ha,
800 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
801 vha->host_no, id, lun, wait, serial, ret);
806 enum nexus_wait_type {
813 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
814 unsigned int l, srb_t *sp, enum nexus_wait_type type)
816 int cnt, match, status;
818 struct qla_hw_data *ha = vha->hw;
821 status = QLA_SUCCESS;
825 spin_lock_irqsave(&ha->hardware_lock, flags);
827 for (cnt = 1; status == QLA_SUCCESS &&
828 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
829 sp = req->outstanding_cmds[cnt];
834 if (vha->vp_idx != sp->fcport->vha->vp_idx)
842 match = sp->cmd->device->id == t;
845 match = (sp->cmd->device->id == t &&
846 sp->cmd->device->lun == l);
852 spin_unlock_irqrestore(&ha->hardware_lock, flags);
853 status = qla2x00_eh_wait_on_command(sp->cmd);
854 spin_lock_irqsave(&ha->hardware_lock, flags);
856 spin_unlock_irqrestore(&ha->hardware_lock, flags);
861 static char *reset_errors[] = {
864 "Task management failed",
865 "Waiting for command completions",
869 __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
870 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
872 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
873 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
876 fc_block_scsi_eh(cmd);
881 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
882 vha->host_no, cmd->device->id, cmd->device->lun, name);
885 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
886 goto eh_reset_failed;
888 if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
889 goto eh_reset_failed;
891 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
893 goto eh_reset_failed;
895 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
896 cmd->device->lun, (srb_t *) CMD_SP(cmd), type) != QLA_SUCCESS)
897 goto eh_reset_failed;
899 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
900 vha->host_no, cmd->device->id, cmd->device->lun, name);
905 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
906 , vha->host_no, cmd->device->id, cmd->device->lun, name,
912 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
914 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
915 struct qla_hw_data *ha = vha->hw;
917 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
918 ha->isp_ops->lun_reset);
922 qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
924 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
925 struct qla_hw_data *ha = vha->hw;
927 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
928 ha->isp_ops->target_reset);
931 /**************************************************************************
932 * qla2xxx_eh_bus_reset
935 * The bus reset function will reset the bus and abort any executing
939 * cmd = Linux SCSI command packet of the command that cause the
943 * SUCCESS/FAILURE (defined as macro in scsi.h).
945 **************************************************************************/
947 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
949 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
950 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
952 unsigned int id, lun;
953 unsigned long serial;
954 srb_t *sp = (srb_t *) CMD_SP(cmd);
956 fc_block_scsi_eh(cmd);
958 id = cmd->device->id;
959 lun = cmd->device->lun;
960 serial = cmd->serial_number;
965 qla_printk(KERN_INFO, vha->hw,
966 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
968 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
969 DEBUG2(printk("%s failed:board disabled\n",__func__));
970 goto eh_bus_reset_done;
973 if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
974 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
978 goto eh_bus_reset_done;
980 /* Flush outstanding commands. */
981 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) !=
986 qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
987 (ret == FAILED) ? "failed" : "succeded");
992 /**************************************************************************
993 * qla2xxx_eh_host_reset
996 * The reset function will reset the Adapter.
999 * cmd = Linux SCSI command packet of the command that cause the
1003 * Either SUCCESS or FAILED.
1006 **************************************************************************/
1008 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1010 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1011 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1012 struct qla_hw_data *ha = vha->hw;
1014 unsigned int id, lun;
1015 unsigned long serial;
1016 srb_t *sp = (srb_t *) CMD_SP(cmd);
1017 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1019 fc_block_scsi_eh(cmd);
1021 id = cmd->device->id;
1022 lun = cmd->device->lun;
1023 serial = cmd->serial_number;
1028 qla_printk(KERN_INFO, ha,
1029 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
1031 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1032 goto eh_host_reset_lock;
1035 * Fixme-may be dpc thread is active and processing
1036 * loop_resync,so wait a while for it to
1037 * be completed and then issue big hammer.Otherwise
1038 * it may cause I/O failure as big hammer marks the
1039 * devices as lost kicking of the port_down_timer
1040 * while dpc is stuck for the mailbox to complete.
1042 qla2x00_wait_for_loop_ready(vha);
1043 if (vha != base_vha) {
1044 if (qla2x00_vp_abort_isp(vha))
1045 goto eh_host_reset_lock;
1048 flush_workqueue(ha->wq);
1050 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1051 if (qla2x00_abort_isp(base_vha)) {
1052 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1053 /* failed. schedule dpc to try */
1054 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1056 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1057 goto eh_host_reset_lock;
1059 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1062 /* Waiting for command to be returned to OS.*/
1063 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) ==
1068 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1069 (ret == FAILED) ? "failed" : "succeded");
1075 * qla2x00_loop_reset
1079 * ha = adapter block pointer.
1085 qla2x00_loop_reset(scsi_qla_host_t *vha)
1088 struct fc_port *fcport;
1089 struct qla_hw_data *ha = vha->hw;
1091 if (ha->flags.enable_lip_full_login && !IS_QLA81XX(ha)) {
1092 ret = qla2x00_full_login_lip(vha);
1093 if (ret != QLA_SUCCESS) {
1094 DEBUG2_3(printk("%s(%ld): failed: "
1095 "full_login_lip=%d.\n", __func__, vha->host_no,
1098 atomic_set(&vha->loop_state, LOOP_DOWN);
1099 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1100 qla2x00_mark_all_devices_lost(vha, 0);
1101 qla2x00_wait_for_loop_ready(vha);
1104 if (ha->flags.enable_lip_reset) {
1105 ret = qla2x00_lip_reset(vha);
1106 if (ret != QLA_SUCCESS) {
1107 DEBUG2_3(printk("%s(%ld): failed: "
1108 "lip_reset=%d.\n", __func__, vha->host_no, ret));
1110 qla2x00_wait_for_loop_ready(vha);
1113 if (ha->flags.enable_target_reset) {
1114 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1115 if (fcport->port_type != FCT_TARGET)
1118 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1119 if (ret != QLA_SUCCESS) {
1120 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1121 "target_reset=%d d_id=%x.\n", __func__,
1122 vha->host_no, ret, fcport->d_id.b24));
1126 /* Issue marker command only when we are going to start the I/O */
1127 vha->marker_needed = 1;
1133 qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1136 unsigned long flags;
1138 struct srb_ctx *ctx;
1139 struct qla_hw_data *ha = vha->hw;
1140 struct req_que *req;
1142 spin_lock_irqsave(&ha->hardware_lock, flags);
1143 for (que = 0; que < ha->max_req_queues; que++) {
1144 req = ha->req_q_map[que];
1147 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1148 sp = req->outstanding_cmds[cnt];
1150 req->outstanding_cmds[cnt] = NULL;
1152 sp->cmd->result = res;
1153 qla2x00_sp_compl(ha, sp);
1156 del_timer_sync(&ctx->timer);
1162 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1166 qla2xxx_slave_alloc(struct scsi_device *sdev)
1168 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1170 if (!rport || fc_remote_port_chkready(rport))
1173 sdev->hostdata = *(fc_port_t **)rport->dd_data;
1179 qla2xxx_slave_configure(struct scsi_device *sdev)
1181 scsi_qla_host_t *vha = shost_priv(sdev->host);
1182 struct qla_hw_data *ha = vha->hw;
1183 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1184 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1185 struct req_que *req = vha->req;
1187 if (sdev->tagged_supported)
1188 scsi_activate_tcq(sdev, req->max_q_depth);
1190 scsi_deactivate_tcq(sdev, req->max_q_depth);
1192 rport->dev_loss_tmo = ha->port_down_retry_count;
1193 if (sdev->type == TYPE_TAPE)
1194 fcport->flags |= FCF_TAPE_PRESENT;
1200 qla2xxx_slave_destroy(struct scsi_device *sdev)
1202 sdev->hostdata = NULL;
1205 static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
1207 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1209 if (!scsi_track_queue_full(sdev, qdepth))
1212 DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw,
1213 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
1214 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
1215 sdev->queue_depth));
1218 static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
1220 fc_port_t *fcport = sdev->hostdata;
1221 struct scsi_qla_host *vha = fcport->vha;
1222 struct qla_hw_data *ha = vha->hw;
1223 struct req_que *req = NULL;
1229 if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
1232 if (sdev->ordered_tags)
1233 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
1235 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
1237 DEBUG2(qla_printk(KERN_INFO, ha,
1238 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
1239 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
1240 sdev->queue_depth));
1244 qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1247 case SCSI_QDEPTH_DEFAULT:
1248 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1250 case SCSI_QDEPTH_QFULL:
1251 qla2x00_handle_queue_full(sdev, qdepth);
1253 case SCSI_QDEPTH_RAMP_UP:
1254 qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
1260 return sdev->queue_depth;
1264 qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1266 if (sdev->tagged_supported) {
1267 scsi_set_tag_type(sdev, tag_type);
1269 scsi_activate_tcq(sdev, sdev->queue_depth);
1271 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1279 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1282 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1283 * supported addressing method.
1286 qla2x00_config_dma_addressing(struct qla_hw_data *ha)
1288 /* Assume a 32bit DMA mask. */
1289 ha->flags.enable_64bit_addressing = 0;
1291 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1292 /* Any upper-dword bits set? */
1293 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1294 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
1295 /* Ok, a 64bit DMA mask is applicable. */
1296 ha->flags.enable_64bit_addressing = 1;
1297 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1298 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
1303 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1304 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
1308 qla2x00_enable_intrs(struct qla_hw_data *ha)
1310 unsigned long flags = 0;
1311 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1313 spin_lock_irqsave(&ha->hardware_lock, flags);
1314 ha->interrupts_on = 1;
1315 /* enable risc and host interrupts */
1316 WRT_REG_WORD(®->ictrl, ICR_EN_INT | ICR_EN_RISC);
1317 RD_REG_WORD(®->ictrl);
1318 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1323 qla2x00_disable_intrs(struct qla_hw_data *ha)
1325 unsigned long flags = 0;
1326 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1328 spin_lock_irqsave(&ha->hardware_lock, flags);
1329 ha->interrupts_on = 0;
1330 /* disable risc and host interrupts */
1331 WRT_REG_WORD(®->ictrl, 0);
1332 RD_REG_WORD(®->ictrl);
1333 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1337 qla24xx_enable_intrs(struct qla_hw_data *ha)
1339 unsigned long flags = 0;
1340 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1342 spin_lock_irqsave(&ha->hardware_lock, flags);
1343 ha->interrupts_on = 1;
1344 WRT_REG_DWORD(®->ictrl, ICRX_EN_RISC_INT);
1345 RD_REG_DWORD(®->ictrl);
1346 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1350 qla24xx_disable_intrs(struct qla_hw_data *ha)
1352 unsigned long flags = 0;
1353 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1355 if (IS_NOPOLLING_TYPE(ha))
1357 spin_lock_irqsave(&ha->hardware_lock, flags);
1358 ha->interrupts_on = 0;
1359 WRT_REG_DWORD(®->ictrl, 0);
1360 RD_REG_DWORD(®->ictrl);
1361 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1364 static struct isp_operations qla2100_isp_ops = {
1365 .pci_config = qla2100_pci_config,
1366 .reset_chip = qla2x00_reset_chip,
1367 .chip_diag = qla2x00_chip_diag,
1368 .config_rings = qla2x00_config_rings,
1369 .reset_adapter = qla2x00_reset_adapter,
1370 .nvram_config = qla2x00_nvram_config,
1371 .update_fw_options = qla2x00_update_fw_options,
1372 .load_risc = qla2x00_load_risc,
1373 .pci_info_str = qla2x00_pci_info_str,
1374 .fw_version_str = qla2x00_fw_version_str,
1375 .intr_handler = qla2100_intr_handler,
1376 .enable_intrs = qla2x00_enable_intrs,
1377 .disable_intrs = qla2x00_disable_intrs,
1378 .abort_command = qla2x00_abort_command,
1379 .target_reset = qla2x00_abort_target,
1380 .lun_reset = qla2x00_lun_reset,
1381 .fabric_login = qla2x00_login_fabric,
1382 .fabric_logout = qla2x00_fabric_logout,
1383 .calc_req_entries = qla2x00_calc_iocbs_32,
1384 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1385 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1386 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1387 .read_nvram = qla2x00_read_nvram_data,
1388 .write_nvram = qla2x00_write_nvram_data,
1389 .fw_dump = qla2100_fw_dump,
1392 .beacon_blink = NULL,
1393 .read_optrom = qla2x00_read_optrom_data,
1394 .write_optrom = qla2x00_write_optrom_data,
1395 .get_flash_version = qla2x00_get_flash_version,
1396 .start_scsi = qla2x00_start_scsi,
1399 static struct isp_operations qla2300_isp_ops = {
1400 .pci_config = qla2300_pci_config,
1401 .reset_chip = qla2x00_reset_chip,
1402 .chip_diag = qla2x00_chip_diag,
1403 .config_rings = qla2x00_config_rings,
1404 .reset_adapter = qla2x00_reset_adapter,
1405 .nvram_config = qla2x00_nvram_config,
1406 .update_fw_options = qla2x00_update_fw_options,
1407 .load_risc = qla2x00_load_risc,
1408 .pci_info_str = qla2x00_pci_info_str,
1409 .fw_version_str = qla2x00_fw_version_str,
1410 .intr_handler = qla2300_intr_handler,
1411 .enable_intrs = qla2x00_enable_intrs,
1412 .disable_intrs = qla2x00_disable_intrs,
1413 .abort_command = qla2x00_abort_command,
1414 .target_reset = qla2x00_abort_target,
1415 .lun_reset = qla2x00_lun_reset,
1416 .fabric_login = qla2x00_login_fabric,
1417 .fabric_logout = qla2x00_fabric_logout,
1418 .calc_req_entries = qla2x00_calc_iocbs_32,
1419 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1420 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1421 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1422 .read_nvram = qla2x00_read_nvram_data,
1423 .write_nvram = qla2x00_write_nvram_data,
1424 .fw_dump = qla2300_fw_dump,
1425 .beacon_on = qla2x00_beacon_on,
1426 .beacon_off = qla2x00_beacon_off,
1427 .beacon_blink = qla2x00_beacon_blink,
1428 .read_optrom = qla2x00_read_optrom_data,
1429 .write_optrom = qla2x00_write_optrom_data,
1430 .get_flash_version = qla2x00_get_flash_version,
1431 .start_scsi = qla2x00_start_scsi,
1434 static struct isp_operations qla24xx_isp_ops = {
1435 .pci_config = qla24xx_pci_config,
1436 .reset_chip = qla24xx_reset_chip,
1437 .chip_diag = qla24xx_chip_diag,
1438 .config_rings = qla24xx_config_rings,
1439 .reset_adapter = qla24xx_reset_adapter,
1440 .nvram_config = qla24xx_nvram_config,
1441 .update_fw_options = qla24xx_update_fw_options,
1442 .load_risc = qla24xx_load_risc,
1443 .pci_info_str = qla24xx_pci_info_str,
1444 .fw_version_str = qla24xx_fw_version_str,
1445 .intr_handler = qla24xx_intr_handler,
1446 .enable_intrs = qla24xx_enable_intrs,
1447 .disable_intrs = qla24xx_disable_intrs,
1448 .abort_command = qla24xx_abort_command,
1449 .target_reset = qla24xx_abort_target,
1450 .lun_reset = qla24xx_lun_reset,
1451 .fabric_login = qla24xx_login_fabric,
1452 .fabric_logout = qla24xx_fabric_logout,
1453 .calc_req_entries = NULL,
1454 .build_iocbs = NULL,
1455 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1456 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1457 .read_nvram = qla24xx_read_nvram_data,
1458 .write_nvram = qla24xx_write_nvram_data,
1459 .fw_dump = qla24xx_fw_dump,
1460 .beacon_on = qla24xx_beacon_on,
1461 .beacon_off = qla24xx_beacon_off,
1462 .beacon_blink = qla24xx_beacon_blink,
1463 .read_optrom = qla24xx_read_optrom_data,
1464 .write_optrom = qla24xx_write_optrom_data,
1465 .get_flash_version = qla24xx_get_flash_version,
1466 .start_scsi = qla24xx_start_scsi,
1469 static struct isp_operations qla25xx_isp_ops = {
1470 .pci_config = qla25xx_pci_config,
1471 .reset_chip = qla24xx_reset_chip,
1472 .chip_diag = qla24xx_chip_diag,
1473 .config_rings = qla24xx_config_rings,
1474 .reset_adapter = qla24xx_reset_adapter,
1475 .nvram_config = qla24xx_nvram_config,
1476 .update_fw_options = qla24xx_update_fw_options,
1477 .load_risc = qla24xx_load_risc,
1478 .pci_info_str = qla24xx_pci_info_str,
1479 .fw_version_str = qla24xx_fw_version_str,
1480 .intr_handler = qla24xx_intr_handler,
1481 .enable_intrs = qla24xx_enable_intrs,
1482 .disable_intrs = qla24xx_disable_intrs,
1483 .abort_command = qla24xx_abort_command,
1484 .target_reset = qla24xx_abort_target,
1485 .lun_reset = qla24xx_lun_reset,
1486 .fabric_login = qla24xx_login_fabric,
1487 .fabric_logout = qla24xx_fabric_logout,
1488 .calc_req_entries = NULL,
1489 .build_iocbs = NULL,
1490 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1491 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1492 .read_nvram = qla25xx_read_nvram_data,
1493 .write_nvram = qla25xx_write_nvram_data,
1494 .fw_dump = qla25xx_fw_dump,
1495 .beacon_on = qla24xx_beacon_on,
1496 .beacon_off = qla24xx_beacon_off,
1497 .beacon_blink = qla24xx_beacon_blink,
1498 .read_optrom = qla25xx_read_optrom_data,
1499 .write_optrom = qla24xx_write_optrom_data,
1500 .get_flash_version = qla24xx_get_flash_version,
1501 .start_scsi = qla24xx_start_scsi,
1504 static struct isp_operations qla81xx_isp_ops = {
1505 .pci_config = qla25xx_pci_config,
1506 .reset_chip = qla24xx_reset_chip,
1507 .chip_diag = qla24xx_chip_diag,
1508 .config_rings = qla24xx_config_rings,
1509 .reset_adapter = qla24xx_reset_adapter,
1510 .nvram_config = qla81xx_nvram_config,
1511 .update_fw_options = qla81xx_update_fw_options,
1512 .load_risc = qla81xx_load_risc,
1513 .pci_info_str = qla24xx_pci_info_str,
1514 .fw_version_str = qla24xx_fw_version_str,
1515 .intr_handler = qla24xx_intr_handler,
1516 .enable_intrs = qla24xx_enable_intrs,
1517 .disable_intrs = qla24xx_disable_intrs,
1518 .abort_command = qla24xx_abort_command,
1519 .target_reset = qla24xx_abort_target,
1520 .lun_reset = qla24xx_lun_reset,
1521 .fabric_login = qla24xx_login_fabric,
1522 .fabric_logout = qla24xx_fabric_logout,
1523 .calc_req_entries = NULL,
1524 .build_iocbs = NULL,
1525 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1526 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1528 .write_nvram = NULL,
1529 .fw_dump = qla81xx_fw_dump,
1530 .beacon_on = qla24xx_beacon_on,
1531 .beacon_off = qla24xx_beacon_off,
1532 .beacon_blink = qla24xx_beacon_blink,
1533 .read_optrom = qla25xx_read_optrom_data,
1534 .write_optrom = qla24xx_write_optrom_data,
1535 .get_flash_version = qla24xx_get_flash_version,
1536 .start_scsi = qla24xx_start_scsi,
1540 qla2x00_set_isp_flags(struct qla_hw_data *ha)
1542 ha->device_type = DT_EXTENDED_IDS;
1543 switch (ha->pdev->device) {
1544 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1545 ha->device_type |= DT_ISP2100;
1546 ha->device_type &= ~DT_EXTENDED_IDS;
1547 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
1549 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1550 ha->device_type |= DT_ISP2200;
1551 ha->device_type &= ~DT_EXTENDED_IDS;
1552 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
1554 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1555 ha->device_type |= DT_ISP2300;
1556 ha->device_type |= DT_ZIO_SUPPORTED;
1557 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1559 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1560 ha->device_type |= DT_ISP2312;
1561 ha->device_type |= DT_ZIO_SUPPORTED;
1562 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1564 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1565 ha->device_type |= DT_ISP2322;
1566 ha->device_type |= DT_ZIO_SUPPORTED;
1567 if (ha->pdev->subsystem_vendor == 0x1028 &&
1568 ha->pdev->subsystem_device == 0x0170)
1569 ha->device_type |= DT_OEM_001;
1570 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1572 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1573 ha->device_type |= DT_ISP6312;
1574 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1576 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1577 ha->device_type |= DT_ISP6322;
1578 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1580 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1581 ha->device_type |= DT_ISP2422;
1582 ha->device_type |= DT_ZIO_SUPPORTED;
1583 ha->device_type |= DT_FWI2;
1584 ha->device_type |= DT_IIDMA;
1585 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1587 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1588 ha->device_type |= DT_ISP2432;
1589 ha->device_type |= DT_ZIO_SUPPORTED;
1590 ha->device_type |= DT_FWI2;
1591 ha->device_type |= DT_IIDMA;
1592 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1594 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1595 ha->device_type |= DT_ISP8432;
1596 ha->device_type |= DT_ZIO_SUPPORTED;
1597 ha->device_type |= DT_FWI2;
1598 ha->device_type |= DT_IIDMA;
1599 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1601 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1602 ha->device_type |= DT_ISP5422;
1603 ha->device_type |= DT_FWI2;
1604 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1606 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1607 ha->device_type |= DT_ISP5432;
1608 ha->device_type |= DT_FWI2;
1609 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1611 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1612 ha->device_type |= DT_ISP2532;
1613 ha->device_type |= DT_ZIO_SUPPORTED;
1614 ha->device_type |= DT_FWI2;
1615 ha->device_type |= DT_IIDMA;
1616 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1618 case PCI_DEVICE_ID_QLOGIC_ISP8001:
1619 ha->device_type |= DT_ISP8001;
1620 ha->device_type |= DT_ZIO_SUPPORTED;
1621 ha->device_type |= DT_FWI2;
1622 ha->device_type |= DT_IIDMA;
1623 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1627 /* Get adapter physical port no from interrupt pin register. */
1628 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
1629 if (ha->port_no & 1)
1630 ha->flags.port0 = 1;
1632 ha->flags.port0 = 0;
1636 qla2x00_iospace_config(struct qla_hw_data *ha)
1638 resource_size_t pio;
1642 if (pci_request_selected_regions(ha->pdev, ha->bars,
1643 QLA2XXX_DRIVER_NAME)) {
1644 qla_printk(KERN_WARNING, ha,
1645 "Failed to reserve PIO/MMIO regions (%s)\n",
1646 pci_name(ha->pdev));
1648 goto iospace_error_exit;
1650 if (!(ha->bars & 1))
1653 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1654 pio = pci_resource_start(ha->pdev, 0);
1655 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1656 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1657 qla_printk(KERN_WARNING, ha,
1658 "Invalid PCI I/O region size (%s)...\n",
1659 pci_name(ha->pdev));
1663 qla_printk(KERN_WARNING, ha,
1664 "region #0 not a PIO resource (%s)...\n",
1665 pci_name(ha->pdev));
1668 ha->pio_address = pio;
1671 /* Use MMIO operations for all accesses. */
1672 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1673 qla_printk(KERN_ERR, ha,
1674 "region #1 not an MMIO resource (%s), aborting\n",
1675 pci_name(ha->pdev));
1676 goto iospace_error_exit;
1678 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1679 qla_printk(KERN_ERR, ha,
1680 "Invalid PCI mem region size (%s), aborting\n",
1681 pci_name(ha->pdev));
1682 goto iospace_error_exit;
1685 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1687 qla_printk(KERN_ERR, ha,
1688 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1690 goto iospace_error_exit;
1693 /* Determine queue resources */
1694 ha->max_req_queues = ha->max_rsp_queues = 1;
1695 if ((ql2xmaxqueues <= 1 || ql2xmultique_tag < 1) &&
1696 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1698 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1699 pci_resource_len(ha->pdev, 3));
1701 /* Read MSIX vector size of the board */
1702 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1703 ha->msix_count = msix;
1704 /* Max queues are bounded by available msix vectors */
1705 /* queue 0 uses two msix vectors */
1706 if (ql2xmultique_tag) {
1707 cpus = num_online_cpus();
1708 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1709 (cpus + 1) : (ha->msix_count - 1);
1710 ha->max_req_queues = 2;
1711 } else if (ql2xmaxqueues > 1) {
1712 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1713 QLA_MQ_SIZE : ql2xmaxqueues;
1714 DEBUG2(qla_printk(KERN_INFO, ha, "QoS mode set, max no"
1715 " of request queues:%d\n", ha->max_req_queues));
1717 qla_printk(KERN_INFO, ha,
1718 "MSI-X vector count: %d\n", msix);
1720 qla_printk(KERN_INFO, ha, "BAR 3 not enabled\n");
1723 ha->msix_count = ha->max_rsp_queues + 1;
1731 qla2xxx_scan_start(struct Scsi_Host *shost)
1733 scsi_qla_host_t *vha = shost_priv(shost);
1735 if (vha->hw->flags.running_gold_fw)
1738 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1739 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1740 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1741 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
1745 qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1747 scsi_qla_host_t *vha = shost_priv(shost);
1751 if (time > vha->hw->loop_reset_delay * HZ)
1754 return atomic_read(&vha->loop_state) == LOOP_READY;
1758 * PCI driver interface
1760 static int __devinit
1761 qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1764 struct Scsi_Host *host;
1765 scsi_qla_host_t *base_vha = NULL;
1766 struct qla_hw_data *ha;
1769 struct scsi_host_template *sht;
1770 int bars, max_id, mem_only = 0;
1771 uint16_t req_length = 0, rsp_length = 0;
1772 struct req_que *req = NULL;
1773 struct rsp_que *rsp = NULL;
1775 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
1776 sht = &qla2xxx_driver_template;
1777 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1778 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
1779 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
1780 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1781 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
1782 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
1783 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001) {
1784 bars = pci_select_bars(pdev, IORESOURCE_MEM);
1789 if (pci_enable_device_mem(pdev))
1792 if (pci_enable_device(pdev))
1796 /* This may fail but that's ok */
1797 pci_enable_pcie_error_reporting(pdev);
1799 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
1801 DEBUG(printk("Unable to allocate memory for ha\n"));
1806 /* Clear our data area */
1808 ha->mem_only = mem_only;
1809 spin_lock_init(&ha->hardware_lock);
1811 /* Set ISP-type information. */
1812 qla2x00_set_isp_flags(ha);
1813 /* Configure PCI I/O space */
1814 ret = qla2x00_iospace_config(ha);
1816 goto probe_hw_failed;
1818 qla_printk(KERN_INFO, ha,
1819 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1822 ha->prev_topology = 0;
1823 ha->init_cb_size = sizeof(init_cb_t);
1824 ha->link_data_rate = PORT_SPEED_UNKNOWN;
1825 ha->optrom_size = OPTROM_SIZE_2300;
1827 /* Assign ISP specific operations. */
1828 max_id = MAX_TARGETS_2200;
1829 if (IS_QLA2100(ha)) {
1830 max_id = MAX_TARGETS_2100;
1831 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1832 req_length = REQUEST_ENTRY_CNT_2100;
1833 rsp_length = RESPONSE_ENTRY_CNT_2100;
1834 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
1835 ha->gid_list_info_size = 4;
1836 ha->flash_conf_off = ~0;
1837 ha->flash_data_off = ~0;
1838 ha->nvram_conf_off = ~0;
1839 ha->nvram_data_off = ~0;
1840 ha->isp_ops = &qla2100_isp_ops;
1841 } else if (IS_QLA2200(ha)) {
1842 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1843 req_length = REQUEST_ENTRY_CNT_2200;
1844 rsp_length = RESPONSE_ENTRY_CNT_2100;
1845 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
1846 ha->gid_list_info_size = 4;
1847 ha->flash_conf_off = ~0;
1848 ha->flash_data_off = ~0;
1849 ha->nvram_conf_off = ~0;
1850 ha->nvram_data_off = ~0;
1851 ha->isp_ops = &qla2100_isp_ops;
1852 } else if (IS_QLA23XX(ha)) {
1853 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1854 req_length = REQUEST_ENTRY_CNT_2200;
1855 rsp_length = RESPONSE_ENTRY_CNT_2300;
1856 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1857 ha->gid_list_info_size = 6;
1858 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1859 ha->optrom_size = OPTROM_SIZE_2322;
1860 ha->flash_conf_off = ~0;
1861 ha->flash_data_off = ~0;
1862 ha->nvram_conf_off = ~0;
1863 ha->nvram_data_off = ~0;
1864 ha->isp_ops = &qla2300_isp_ops;
1865 } else if (IS_QLA24XX_TYPE(ha)) {
1866 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1867 req_length = REQUEST_ENTRY_CNT_24XX;
1868 rsp_length = RESPONSE_ENTRY_CNT_2300;
1869 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1870 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1871 ha->gid_list_info_size = 8;
1872 ha->optrom_size = OPTROM_SIZE_24XX;
1873 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
1874 ha->isp_ops = &qla24xx_isp_ops;
1875 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1876 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1877 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1878 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
1879 } else if (IS_QLA25XX(ha)) {
1880 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1881 req_length = REQUEST_ENTRY_CNT_24XX;
1882 rsp_length = RESPONSE_ENTRY_CNT_2300;
1883 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1884 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1885 ha->gid_list_info_size = 8;
1886 ha->optrom_size = OPTROM_SIZE_25XX;
1887 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
1888 ha->isp_ops = &qla25xx_isp_ops;
1889 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1890 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1891 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1892 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
1893 } else if (IS_QLA81XX(ha)) {
1894 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1895 req_length = REQUEST_ENTRY_CNT_24XX;
1896 rsp_length = RESPONSE_ENTRY_CNT_2300;
1897 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1898 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
1899 ha->gid_list_info_size = 8;
1900 ha->optrom_size = OPTROM_SIZE_81XX;
1901 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
1902 ha->isp_ops = &qla81xx_isp_ops;
1903 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
1904 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
1905 ha->nvram_conf_off = ~0;
1906 ha->nvram_data_off = ~0;
1909 mutex_init(&ha->vport_lock);
1910 init_completion(&ha->mbx_cmd_comp);
1911 complete(&ha->mbx_cmd_comp);
1912 init_completion(&ha->mbx_intr_comp);
1914 set_bit(0, (unsigned long *) ha->vp_idx_map);
1916 qla2x00_config_dma_addressing(ha);
1917 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
1919 qla_printk(KERN_WARNING, ha,
1920 "[ERROR] Failed to allocate memory for adapter\n");
1922 goto probe_hw_failed;
1925 req->max_q_depth = MAX_Q_DEPTH;
1926 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
1927 req->max_q_depth = ql2xmaxqdepth;
1930 base_vha = qla2x00_create_host(sht, ha);
1932 qla_printk(KERN_WARNING, ha,
1933 "[ERROR] Failed to allocate memory for scsi_host\n");
1936 qla2x00_mem_free(ha);
1937 qla2x00_free_req_que(ha, req);
1938 qla2x00_free_rsp_que(ha, rsp);
1939 goto probe_hw_failed;
1942 pci_set_drvdata(pdev, base_vha);
1944 host = base_vha->host;
1945 base_vha->req = req;
1946 host->can_queue = req->length + 128;
1947 if (IS_QLA2XXX_MIDTYPE(ha))
1948 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
1950 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
1953 host->sg_tablesize = 32;
1954 host->max_id = max_id;
1955 host->this_id = 255;
1956 host->cmd_per_lun = 3;
1957 host->unique_id = host->host_no;
1958 host->max_cmd_len = MAX_CMDSZ;
1959 host->max_channel = MAX_BUSES - 1;
1960 host->max_lun = MAX_LUNS;
1961 host->transportt = qla2xxx_transport_template;
1963 /* Set up the irqs */
1964 ret = qla2x00_request_irqs(ha, rsp);
1966 goto probe_init_failed;
1967 /* Alloc arrays of request and response ring ptrs */
1969 if (!qla2x00_alloc_queues(ha)) {
1970 qla_printk(KERN_WARNING, ha,
1971 "[ERROR] Failed to allocate memory for queue"
1973 goto probe_init_failed;
1975 ha->rsp_q_map[0] = rsp;
1976 ha->req_q_map[0] = req;
1979 set_bit(0, ha->req_qid_map);
1980 set_bit(0, ha->rsp_qid_map);
1981 /* FWI2-capable only. */
1982 req->req_q_in = &ha->iobase->isp24.req_q_in;
1983 req->req_q_out = &ha->iobase->isp24.req_q_out;
1984 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
1985 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
1987 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
1988 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
1989 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
1990 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
1993 if (qla2x00_initialize_adapter(base_vha)) {
1994 qla_printk(KERN_WARNING, ha,
1995 "Failed to initialize adapter\n");
1997 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1998 "Adapter flags %x.\n",
1999 base_vha->host_no, base_vha->device_flags));
2006 if (qla25xx_setup_mode(base_vha)) {
2007 qla_printk(KERN_WARNING, ha,
2008 "Can't create queues, falling back to single"
2014 if (ha->flags.running_gold_fw)
2018 * Startup the kernel thread for this host adapter
2020 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
2021 "%s_dpc", base_vha->host_str);
2022 if (IS_ERR(ha->dpc_thread)) {
2023 qla_printk(KERN_WARNING, ha,
2024 "Unable to start DPC thread!\n");
2025 ret = PTR_ERR(ha->dpc_thread);
2030 list_add_tail(&base_vha->list, &ha->vp_list);
2031 base_vha->host->irq = ha->pdev->irq;
2033 /* Initialized the timer */
2034 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
2036 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
2037 base_vha->host_no, ha));
2039 ret = scsi_add_host(host, &pdev->dev);
2043 base_vha->flags.init_done = 1;
2044 base_vha->flags.online = 1;
2046 ha->isp_ops->enable_intrs(ha);
2048 scsi_scan_host(host);
2050 qla2x00_alloc_sysfs_attr(base_vha);
2052 qla2x00_init_host_attr(base_vha);
2054 qla2x00_dfs_setup(base_vha);
2056 qla_printk(KERN_INFO, ha, "\n"
2057 " QLogic Fibre Channel HBA Driver: %s\n"
2059 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
2060 qla2x00_version_str, ha->model_number,
2061 ha->model_desc ? ha->model_desc : "", pdev->device,
2062 ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
2063 ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
2064 ha->isp_ops->fw_version_str(base_vha, fw_str));
2069 qla2x00_free_req_que(ha, req);
2070 qla2x00_free_rsp_que(ha, rsp);
2071 ha->max_req_queues = ha->max_rsp_queues = 0;
2074 if (base_vha->timer_active)
2075 qla2x00_stop_timer(base_vha);
2076 base_vha->flags.online = 0;
2077 if (ha->dpc_thread) {
2078 struct task_struct *t = ha->dpc_thread;
2080 ha->dpc_thread = NULL;
2084 qla2x00_free_device(base_vha);
2086 scsi_host_put(base_vha->host);
2090 iounmap(ha->iobase);
2092 pci_release_selected_regions(ha->pdev, ha->bars);
2097 pci_disable_device(pdev);
2102 qla2x00_remove_one(struct pci_dev *pdev)
2104 scsi_qla_host_t *base_vha, *vha, *temp;
2105 struct qla_hw_data *ha;
2107 base_vha = pci_get_drvdata(pdev);
2110 list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
2111 if (vha && vha->fc_vport)
2112 fc_vport_terminate(vha->fc_vport);
2115 set_bit(UNLOADING, &base_vha->dpc_flags);
2117 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2119 qla2x00_dfs_remove(base_vha);
2121 qla84xx_put_chip(base_vha);
2124 if (base_vha->timer_active)
2125 qla2x00_stop_timer(base_vha);
2127 base_vha->flags.online = 0;
2129 /* Flush the work queue and remove it */
2131 flush_workqueue(ha->wq);
2132 destroy_workqueue(ha->wq);
2136 /* Kill the kernel thread for this host */
2137 if (ha->dpc_thread) {
2138 struct task_struct *t = ha->dpc_thread;
2141 * qla2xxx_wake_dpc checks for ->dpc_thread
2142 * so we need to zero it out.
2144 ha->dpc_thread = NULL;
2148 qla2x00_free_sysfs_attr(base_vha);
2150 fc_remove_host(base_vha->host);
2152 scsi_remove_host(base_vha->host);
2154 qla2x00_free_device(base_vha);
2156 scsi_host_put(base_vha->host);
2159 iounmap(ha->iobase);
2162 iounmap(ha->mqiobase);
2164 pci_release_selected_regions(ha->pdev, ha->bars);
2168 pci_disable_device(pdev);
2169 pci_set_drvdata(pdev, NULL);
2173 qla2x00_free_device(scsi_qla_host_t *vha)
2175 struct qla_hw_data *ha = vha->hw;
2177 qla25xx_delete_queues(vha);
2179 if (ha->flags.fce_enabled)
2180 qla2x00_disable_fce_trace(vha, NULL, NULL);
2183 qla2x00_disable_eft_trace(vha);
2185 /* Stop currently executing firmware. */
2186 qla2x00_try_to_stop_firmware(vha);
2188 /* turn-off interrupts on the card */
2189 if (ha->interrupts_on)
2190 ha->isp_ops->disable_intrs(ha);
2192 qla2x00_free_irqs(vha);
2194 qla2x00_mem_free(ha);
2196 qla2x00_free_queues(ha);
2200 qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
2203 struct fc_rport *rport;
2204 scsi_qla_host_t *base_vha;
2209 rport = fcport->rport;
2211 base_vha = pci_get_drvdata(vha->hw->pdev);
2212 spin_lock_irq(vha->host->host_lock);
2213 fcport->drport = rport;
2214 spin_unlock_irq(vha->host->host_lock);
2215 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2216 qla2xxx_wake_dpc(base_vha);
2218 fc_remote_port_delete(rport);
2222 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2224 * Input: ha = adapter block pointer. fcport = port structure pointer.
2230 void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
2231 int do_login, int defer)
2233 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2234 vha->vp_idx == fcport->vp_idx) {
2235 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2236 qla2x00_schedule_rport_del(vha, fcport, defer);
2239 * We may need to retry the login, so don't change the state of the
2240 * port but do the retries.
2242 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2243 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2248 if (fcport->login_retry == 0) {
2249 fcport->login_retry = vha->hw->login_retry_count;
2250 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2252 DEBUG(printk("scsi(%ld): Port login retry: "
2253 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2254 "id = 0x%04x retry cnt=%d\n",
2256 fcport->port_name[0],
2257 fcport->port_name[1],
2258 fcport->port_name[2],
2259 fcport->port_name[3],
2260 fcport->port_name[4],
2261 fcport->port_name[5],
2262 fcport->port_name[6],
2263 fcport->port_name[7],
2265 fcport->login_retry));
2270 * qla2x00_mark_all_devices_lost
2271 * Updates fcport state when device goes offline.
2274 * ha = adapter block pointer.
2275 * fcport = port structure pointer.
2283 qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
2287 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2288 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vp_idx)
2292 * No point in marking the device as lost, if the device is
2295 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2297 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2299 qla2x00_schedule_rport_del(vha, fcport, defer);
2300 else if (vha->vp_idx == fcport->vp_idx)
2301 qla2x00_schedule_rport_del(vha, fcport, defer);
2303 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2309 * Allocates adapter memory.
2316 qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2317 struct req_que **req, struct rsp_que **rsp)
2321 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
2322 &ha->init_cb_dma, GFP_KERNEL);
2326 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2327 &ha->gid_list_dma, GFP_KERNEL);
2329 goto fail_free_init_cb;
2331 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2332 if (!ha->srb_mempool)
2333 goto fail_free_gid_list;
2335 /* Get memory for cached NVRAM */
2336 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2338 goto fail_free_srb_mempool;
2340 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2342 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2343 DMA_POOL_SIZE, 8, 0);
2344 if (!ha->s_dma_pool)
2345 goto fail_free_nvram;
2347 /* Allocate memory for SNS commands */
2348 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2349 /* Get consistent memory allocated for SNS commands */
2350 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
2351 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
2355 /* Get consistent memory allocated for MS IOCB */
2356 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2360 /* Get consistent memory allocated for CT SNS commands */
2361 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
2362 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
2364 goto fail_free_ms_iocb;
2367 /* Allocate memory for request ring */
2368 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2370 DEBUG(printk("Unable to allocate memory for req\n"));
2373 (*req)->length = req_len;
2374 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2375 ((*req)->length + 1) * sizeof(request_t),
2376 &(*req)->dma, GFP_KERNEL);
2377 if (!(*req)->ring) {
2378 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2381 /* Allocate memory for response ring */
2382 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2384 qla_printk(KERN_WARNING, ha,
2385 "Unable to allocate memory for rsp\n");
2389 (*rsp)->length = rsp_len;
2390 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2391 ((*rsp)->length + 1) * sizeof(response_t),
2392 &(*rsp)->dma, GFP_KERNEL);
2393 if (!(*rsp)->ring) {
2394 qla_printk(KERN_WARNING, ha,
2395 "Unable to allocate memory for rsp_ring\n");
2400 /* Allocate memory for NVRAM data for vports */
2401 if (ha->nvram_npiv_size) {
2402 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
2403 ha->nvram_npiv_size, GFP_KERNEL);
2404 if (!ha->npiv_info) {
2405 qla_printk(KERN_WARNING, ha,
2406 "Unable to allocate memory for npiv info\n");
2407 goto fail_npiv_info;
2410 ha->npiv_info = NULL;
2412 /* Get consistent memory allocated for EX-INIT-CB. */
2413 if (IS_QLA81XX(ha)) {
2414 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2415 &ha->ex_init_cb_dma);
2416 if (!ha->ex_init_cb)
2417 goto fail_ex_init_cb;
2420 INIT_LIST_HEAD(&ha->vp_list);
2424 kfree(ha->npiv_info);
2426 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2427 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2428 (*rsp)->ring = NULL;
2433 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2434 sizeof(request_t), (*req)->ring, (*req)->dma);
2435 (*req)->ring = NULL;
2440 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2441 ha->ct_sns, ha->ct_sns_dma);
2445 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2447 ha->ms_iocb_dma = 0;
2449 dma_pool_destroy(ha->s_dma_pool);
2450 ha->s_dma_pool = NULL;
2454 fail_free_srb_mempool:
2455 mempool_destroy(ha->srb_mempool);
2456 ha->srb_mempool = NULL;
2458 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2460 ha->gid_list = NULL;
2461 ha->gid_list_dma = 0;
2463 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2466 ha->init_cb_dma = 0;
2468 DEBUG(printk("%s: Memory allocation failure\n", __func__));
2474 * Frees all adapter allocated memory.
2477 * ha = adapter block pointer.
2480 qla2x00_mem_free(struct qla_hw_data *ha)
2482 if (ha->srb_mempool)
2483 mempool_destroy(ha->srb_mempool);
2486 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
2491 dma_free_coherent(&ha->pdev->dev,
2492 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
2497 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
2498 ha->dcbx_tlv, ha->dcbx_tlv_dma);
2501 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
2502 ha->xgmac_data, ha->xgmac_data_dma);
2505 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
2506 ha->sns_cmd, ha->sns_cmd_dma);
2509 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2510 ha->ct_sns, ha->ct_sns_dma);
2513 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2516 dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
2519 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2522 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
2525 dma_pool_destroy(ha->s_dma_pool);
2528 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2532 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2533 ha->init_cb, ha->init_cb_dma);
2534 vfree(ha->optrom_buffer);
2536 kfree(ha->npiv_info);
2538 ha->srb_mempool = NULL;
2542 ha->sns_cmd_dma = 0;
2546 ha->ms_iocb_dma = 0;
2548 ha->init_cb_dma = 0;
2549 ha->ex_init_cb = NULL;
2550 ha->ex_init_cb_dma = 0;
2552 ha->s_dma_pool = NULL;
2554 ha->gid_list = NULL;
2555 ha->gid_list_dma = 0;
2559 ha->fw_dump_reading = 0;
2562 struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
2563 struct qla_hw_data *ha)
2565 struct Scsi_Host *host;
2566 struct scsi_qla_host *vha = NULL;
2568 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
2571 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2575 /* Clear our data area */
2576 vha = shost_priv(host);
2577 memset(vha, 0, sizeof(scsi_qla_host_t));
2580 vha->host_no = host->host_no;
2583 INIT_LIST_HEAD(&vha->vp_fcports);
2584 INIT_LIST_HEAD(&vha->work_list);
2585 INIT_LIST_HEAD(&vha->list);
2587 spin_lock_init(&vha->work_lock);
2589 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
2596 static struct qla_work_evt *
2597 qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
2599 struct qla_work_evt *e;
2601 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
2605 INIT_LIST_HEAD(&e->list);
2607 e->flags = QLA_EVT_FLAG_FREE;
2612 qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
2614 unsigned long flags;
2616 spin_lock_irqsave(&vha->work_lock, flags);
2617 list_add_tail(&e->list, &vha->work_list);
2618 spin_unlock_irqrestore(&vha->work_lock, flags);
2619 qla2xxx_wake_dpc(vha);
2625 qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
2628 struct qla_work_evt *e;
2630 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
2632 return QLA_FUNCTION_FAILED;
2634 e->u.aen.code = code;
2635 e->u.aen.data = data;
2636 return qla2x00_post_work(vha, e);
2640 qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
2642 struct qla_work_evt *e;
2644 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
2646 return QLA_FUNCTION_FAILED;
2648 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
2649 return qla2x00_post_work(vha, e);
2652 #define qla2x00_post_async_work(name, type) \
2653 int qla2x00_post_async_##name##_work( \
2654 struct scsi_qla_host *vha, \
2655 fc_port_t *fcport, uint16_t *data) \
2657 struct qla_work_evt *e; \
2659 e = qla2x00_alloc_work(vha, type); \
2661 return QLA_FUNCTION_FAILED; \
2663 e->u.logio.fcport = fcport; \
2665 e->u.logio.data[0] = data[0]; \
2666 e->u.logio.data[1] = data[1]; \
2668 return qla2x00_post_work(vha, e); \
2671 qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
2672 qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
2673 qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
2674 qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
2677 qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
2679 struct qla_work_evt *e;
2681 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
2683 return QLA_FUNCTION_FAILED;
2685 e->u.uevent.code = code;
2686 return qla2x00_post_work(vha, e);
2690 qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
2692 char event_string[40];
2693 char *envp[] = { event_string, NULL };
2696 case QLA_UEVENT_CODE_FW_DUMP:
2697 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
2704 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
2708 qla2x00_do_work(struct scsi_qla_host *vha)
2710 struct qla_work_evt *e, *tmp;
2711 unsigned long flags;
2714 spin_lock_irqsave(&vha->work_lock, flags);
2715 list_splice_init(&vha->work_list, &work);
2716 spin_unlock_irqrestore(&vha->work_lock, flags);
2718 list_for_each_entry_safe(e, tmp, &work, list) {
2719 list_del_init(&e->list);
2723 fc_host_post_event(vha->host, fc_get_event_number(),
2724 e->u.aen.code, e->u.aen.data);
2726 case QLA_EVT_IDC_ACK:
2727 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
2729 case QLA_EVT_ASYNC_LOGIN:
2730 qla2x00_async_login(vha, e->u.logio.fcport,
2733 case QLA_EVT_ASYNC_LOGIN_DONE:
2734 qla2x00_async_login_done(vha, e->u.logio.fcport,
2737 case QLA_EVT_ASYNC_LOGOUT:
2738 qla2x00_async_logout(vha, e->u.logio.fcport);
2740 case QLA_EVT_ASYNC_LOGOUT_DONE:
2741 qla2x00_async_logout_done(vha, e->u.logio.fcport,
2744 case QLA_EVT_UEVENT:
2745 qla2x00_uevent_emit(vha, e->u.uevent.code);
2748 if (e->flags & QLA_EVT_FLAG_FREE)
2753 /* Relogins all the fcports of a vport
2754 * Context: dpc thread
2756 void qla2x00_relogin(struct scsi_qla_host *vha)
2760 uint16_t next_loopid = 0;
2761 struct qla_hw_data *ha = vha->hw;
2764 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2766 * If the port is not ONLINE then try to login
2767 * to it if we haven't run out of retries.
2769 if (atomic_read(&fcport->state) !=
2770 FCS_ONLINE && fcport->login_retry) {
2772 fcport->login_retry--;
2773 if (fcport->flags & FCF_FABRIC_DEVICE) {
2774 if (fcport->flags & FCF_TAPE_PRESENT)
2775 ha->isp_ops->fabric_logout(vha,
2777 fcport->d_id.b.domain,
2778 fcport->d_id.b.area,
2779 fcport->d_id.b.al_pa);
2781 if (IS_ALOGIO_CAPABLE(ha)) {
2783 data[1] = QLA_LOGIO_LOGIN_RETRIED;
2784 status = qla2x00_post_async_login_work(
2786 if (status == QLA_SUCCESS)
2788 /* Attempt a retry. */
2791 status = qla2x00_fabric_login(vha,
2792 fcport, &next_loopid);
2794 status = qla2x00_local_device_login(vha,
2797 if (status == QLA_SUCCESS) {
2798 fcport->old_loop_id = fcport->loop_id;
2800 DEBUG(printk("scsi(%ld): port login OK: logged "
2801 "in ID 0x%x\n", vha->host_no, fcport->loop_id));
2803 qla2x00_update_fcport(vha, fcport);
2805 } else if (status == 1) {
2806 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2807 /* retry the login again */
2808 DEBUG(printk("scsi(%ld): Retrying"
2809 " %d login again loop_id 0x%x\n",
2810 vha->host_no, fcport->login_retry,
2813 fcport->login_retry = 0;
2816 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
2817 fcport->loop_id = FC_NO_LOOP_ID;
2819 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2824 /**************************************************************************
2826 * This kernel thread is a task that is schedule by the interrupt handler
2827 * to perform the background processing for interrupts.
2830 * This task always run in the context of a kernel thread. It
2831 * is kick-off by the driver's detect code and starts up
2832 * up one per adapter. It immediately goes to sleep and waits for
2833 * some fibre event. When either the interrupt handler or
2834 * the timer routine detects a event it will one of the task
2835 * bits then wake us up.
2836 **************************************************************************/
2838 qla2x00_do_dpc(void *data)
2841 scsi_qla_host_t *base_vha;
2842 struct qla_hw_data *ha;
2844 ha = (struct qla_hw_data *)data;
2845 base_vha = pci_get_drvdata(ha->pdev);
2847 set_user_nice(current, -20);
2849 while (!kthread_should_stop()) {
2850 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2852 set_current_state(TASK_INTERRUPTIBLE);
2854 __set_current_state(TASK_RUNNING);
2856 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2858 /* Initialization not yet finished. Don't do anything yet. */
2859 if (!base_vha->flags.init_done)
2862 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
2866 if (ha->flags.mbox_busy) {
2871 qla2x00_do_work(base_vha);
2873 if (test_and_clear_bit(ISP_ABORT_NEEDED,
2874 &base_vha->dpc_flags)) {
2876 DEBUG(printk("scsi(%ld): dpc: sched "
2877 "qla2x00_abort_isp ha = %p\n",
2878 base_vha->host_no, ha));
2879 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2880 &base_vha->dpc_flags))) {
2882 if (qla2x00_abort_isp(base_vha)) {
2883 /* failed. retry later */
2884 set_bit(ISP_ABORT_NEEDED,
2885 &base_vha->dpc_flags);
2887 clear_bit(ABORT_ISP_ACTIVE,
2888 &base_vha->dpc_flags);
2891 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2892 base_vha->host_no));
2895 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
2896 qla2x00_update_fcports(base_vha);
2897 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2900 if (test_and_clear_bit(RESET_MARKER_NEEDED,
2901 &base_vha->dpc_flags) &&
2902 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
2904 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2905 base_vha->host_no));
2907 qla2x00_rst_aen(base_vha);
2908 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
2911 /* Retry each device up to login retry count */
2912 if ((test_and_clear_bit(RELOGIN_NEEDED,
2913 &base_vha->dpc_flags)) &&
2914 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
2915 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
2917 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2918 base_vha->host_no));
2919 qla2x00_relogin(base_vha);
2921 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2922 base_vha->host_no));
2925 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
2926 &base_vha->dpc_flags)) {
2928 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2929 base_vha->host_no));
2931 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2932 &base_vha->dpc_flags))) {
2934 rval = qla2x00_loop_resync(base_vha);
2936 clear_bit(LOOP_RESYNC_ACTIVE,
2937 &base_vha->dpc_flags);
2940 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2941 base_vha->host_no));
2944 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
2945 atomic_read(&base_vha->loop_state) == LOOP_READY) {
2946 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
2947 qla2xxx_flash_npiv_conf(base_vha);
2950 if (!ha->interrupts_on)
2951 ha->isp_ops->enable_intrs(ha);
2953 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
2954 &base_vha->dpc_flags))
2955 ha->isp_ops->beacon_blink(base_vha);
2957 qla2x00_do_dpc_all_vps(base_vha);
2960 } /* End of while(1) */
2962 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
2965 * Make sure that nobody tries to wake us up again.
2969 /* Cleanup any residual CTX SRBs. */
2970 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2976 qla2xxx_wake_dpc(struct scsi_qla_host *vha)
2978 struct qla_hw_data *ha = vha->hw;
2979 struct task_struct *t = ha->dpc_thread;
2981 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
2987 * Processes asynchronous reset.
2990 * ha = adapter block pointer.
2993 qla2x00_rst_aen(scsi_qla_host_t *vha)
2995 if (vha->flags.online && !vha->flags.reset_active &&
2996 !atomic_read(&vha->loop_down_timer) &&
2997 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
2999 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
3002 * Issue marker command only when we are going to start
3005 vha->marker_needed = 1;
3006 } while (!atomic_read(&vha->loop_down_timer) &&
3007 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
3012 qla2x00_sp_free_dma(srb_t *sp)
3014 struct scsi_cmnd *cmd = sp->cmd;
3016 if (sp->flags & SRB_DMA_VALID) {
3017 scsi_dma_unmap(cmd);
3018 sp->flags &= ~SRB_DMA_VALID;
3024 qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
3026 struct scsi_cmnd *cmd = sp->cmd;
3028 qla2x00_sp_free_dma(sp);
3030 mempool_free(sp, ha->srb_mempool);
3032 cmd->scsi_done(cmd);
3035 /**************************************************************************
3041 * Context: Interrupt
3042 ***************************************************************************/
3044 qla2x00_timer(scsi_qla_host_t *vha)
3046 unsigned long cpu_flags = 0;
3052 struct qla_hw_data *ha = vha->hw;
3053 struct req_que *req;
3055 * Ports - Port down timer.
3057 * Whenever, a port is in the LOST state we start decrementing its port
3058 * down timer every second until it reaches zero. Once it reaches zero
3059 * the port it marked DEAD.
3062 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3063 if (fcport->port_type != FCT_TARGET)
3066 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
3068 if (atomic_read(&fcport->port_down_timer) == 0)
3071 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
3072 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
3074 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
3077 t, atomic_read(&fcport->port_down_timer)));
3080 } /* End of for fcport */
3083 /* Loop down handler. */
3084 if (atomic_read(&vha->loop_down_timer) > 0 &&
3085 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
3086 && vha->flags.online) {
3088 if (atomic_read(&vha->loop_down_timer) ==
3089 vha->loop_down_abort_time) {
3091 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
3092 "queues before time expire\n",
3095 if (!IS_QLA2100(ha) && vha->link_down_timeout)
3096 atomic_set(&vha->loop_state, LOOP_DEAD);
3098 /* Schedule an ISP abort to return any tape commands. */
3099 /* NPIV - scan physical port only */
3101 spin_lock_irqsave(&ha->hardware_lock,
3103 req = ha->req_q_map[0];
3105 index < MAX_OUTSTANDING_COMMANDS;
3109 sp = req->outstanding_cmds[index];
3115 if (!(sfcp->flags & FCF_TAPE_PRESENT))
3118 set_bit(ISP_ABORT_NEEDED,
3122 spin_unlock_irqrestore(&ha->hardware_lock,
3128 /* if the loop has been down for 4 minutes, reinit adapter */
3129 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
3130 if (!(vha->device_flags & DFLG_NO_CABLE)) {
3131 DEBUG(printk("scsi(%ld): Loop down - "
3134 qla_printk(KERN_WARNING, ha,
3135 "Loop down - aborting ISP.\n");
3137 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3140 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
3142 atomic_read(&vha->loop_down_timer)));
3145 /* Check if beacon LED needs to be blinked */
3146 if (ha->beacon_blink_led == 1) {
3147 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
3151 /* Process any deferred work. */
3152 if (!list_empty(&vha->work_list))
3155 /* Schedule the DPC routine if needed */
3156 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
3157 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
3158 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
3160 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
3161 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
3162 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
3163 test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
3164 qla2xxx_wake_dpc(vha);
3166 qla2x00_restart_timer(vha, WATCH_INTERVAL);
3169 /* Firmware interface routines. */
3172 #define FW_ISP21XX 0
3173 #define FW_ISP22XX 1
3174 #define FW_ISP2300 2
3175 #define FW_ISP2322 3
3176 #define FW_ISP24XX 4
3177 #define FW_ISP25XX 5
3178 #define FW_ISP81XX 6
3180 #define FW_FILE_ISP21XX "ql2100_fw.bin"
3181 #define FW_FILE_ISP22XX "ql2200_fw.bin"
3182 #define FW_FILE_ISP2300 "ql2300_fw.bin"
3183 #define FW_FILE_ISP2322 "ql2322_fw.bin"
3184 #define FW_FILE_ISP24XX "ql2400_fw.bin"
3185 #define FW_FILE_ISP25XX "ql2500_fw.bin"
3186 #define FW_FILE_ISP81XX "ql8100_fw.bin"
3188 static DEFINE_MUTEX(qla_fw_lock);
3190 static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
3191 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
3192 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
3193 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
3194 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
3195 { .name = FW_FILE_ISP24XX, },
3196 { .name = FW_FILE_ISP25XX, },
3197 { .name = FW_FILE_ISP81XX, },
3201 qla2x00_request_firmware(scsi_qla_host_t *vha)
3203 struct qla_hw_data *ha = vha->hw;
3204 struct fw_blob *blob;
3207 if (IS_QLA2100(ha)) {
3208 blob = &qla_fw_blobs[FW_ISP21XX];
3209 } else if (IS_QLA2200(ha)) {
3210 blob = &qla_fw_blobs[FW_ISP22XX];
3211 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3212 blob = &qla_fw_blobs[FW_ISP2300];
3213 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
3214 blob = &qla_fw_blobs[FW_ISP2322];
3215 } else if (IS_QLA24XX_TYPE(ha)) {
3216 blob = &qla_fw_blobs[FW_ISP24XX];
3217 } else if (IS_QLA25XX(ha)) {
3218 blob = &qla_fw_blobs[FW_ISP25XX];
3219 } else if (IS_QLA81XX(ha)) {
3220 blob = &qla_fw_blobs[FW_ISP81XX];
3223 mutex_lock(&qla_fw_lock);
3227 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
3228 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
3229 "(%s).\n", vha->host_no, blob->name));
3236 mutex_unlock(&qla_fw_lock);
3241 qla2x00_release_firmware(void)
3245 mutex_lock(&qla_fw_lock);
3246 for (idx = 0; idx < FW_BLOBS; idx++)
3247 if (qla_fw_blobs[idx].fw)
3248 release_firmware(qla_fw_blobs[idx].fw);
3249 mutex_unlock(&qla_fw_lock);
3252 static pci_ers_result_t
3253 qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3255 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3258 case pci_channel_io_normal:
3259 return PCI_ERS_RESULT_CAN_RECOVER;
3260 case pci_channel_io_frozen:
3261 pci_disable_device(pdev);
3262 return PCI_ERS_RESULT_NEED_RESET;
3263 case pci_channel_io_perm_failure:
3264 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3265 return PCI_ERS_RESULT_DISCONNECT;
3267 return PCI_ERS_RESULT_NEED_RESET;
3270 static pci_ers_result_t
3271 qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
3273 int risc_paused = 0;
3275 unsigned long flags;
3276 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3277 struct qla_hw_data *ha = base_vha->hw;
3278 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3279 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
3281 spin_lock_irqsave(&ha->hardware_lock, flags);
3282 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
3283 stat = RD_REG_DWORD(®->hccr);
3284 if (stat & HCCR_RISC_PAUSE)
3286 } else if (IS_QLA23XX(ha)) {
3287 stat = RD_REG_DWORD(®->u.isp2300.host_status);
3288 if (stat & HSR_RISC_PAUSED)
3290 } else if (IS_FWI2_CAPABLE(ha)) {
3291 stat = RD_REG_DWORD(®24->host_status);
3292 if (stat & HSRX_RISC_PAUSED)
3295 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3298 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
3299 "Dumping firmware!\n");
3300 ha->isp_ops->fw_dump(base_vha, 0);
3302 return PCI_ERS_RESULT_NEED_RESET;
3304 return PCI_ERS_RESULT_RECOVERED;
3307 static pci_ers_result_t
3308 qla2xxx_pci_slot_reset(struct pci_dev *pdev)
3310 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
3311 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3312 struct qla_hw_data *ha = base_vha->hw;
3316 rc = pci_enable_device_mem(pdev);
3318 rc = pci_enable_device(pdev);
3321 qla_printk(KERN_WARNING, ha,
3322 "Can't re-enable PCI device after reset.\n");
3326 pci_set_master(pdev);
3328 if (ha->isp_ops->pci_config(base_vha))
3331 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3332 if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
3333 ret = PCI_ERS_RESULT_RECOVERED;
3334 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3340 qla2xxx_pci_resume(struct pci_dev *pdev)
3342 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3343 struct qla_hw_data *ha = base_vha->hw;
3346 ret = qla2x00_wait_for_hba_online(base_vha);
3347 if (ret != QLA_SUCCESS) {
3348 qla_printk(KERN_ERR, ha,
3349 "the device failed to resume I/O "
3350 "from slot/link_reset");
3352 pci_cleanup_aer_uncorrect_error_status(pdev);
3355 static struct pci_error_handlers qla2xxx_err_handler = {
3356 .error_detected = qla2xxx_pci_error_detected,
3357 .mmio_enabled = qla2xxx_pci_mmio_enabled,
3358 .slot_reset = qla2xxx_pci_slot_reset,
3359 .resume = qla2xxx_pci_resume,
3362 static struct pci_device_id qla2xxx_pci_tbl[] = {
3363 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
3364 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
3365 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
3366 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
3367 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
3368 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
3369 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
3370 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
3371 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
3372 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
3373 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
3374 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
3375 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
3376 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
3379 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
3381 static struct pci_driver qla2xxx_pci_driver = {
3382 .name = QLA2XXX_DRIVER_NAME,
3384 .owner = THIS_MODULE,
3386 .id_table = qla2xxx_pci_tbl,
3387 .probe = qla2x00_probe_one,
3388 .remove = qla2x00_remove_one,
3389 .err_handler = &qla2xxx_err_handler,
3393 * qla2x00_module_init - Module initialization.
3396 qla2x00_module_init(void)
3400 /* Allocate cache for SRBs. */
3401 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
3402 SLAB_HWCACHE_ALIGN, NULL);
3403 if (srb_cachep == NULL) {
3405 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3409 /* Derive version string. */
3410 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
3411 if (ql2xextended_error_logging)
3412 strcat(qla2x00_version_str, "-debug");
3414 qla2xxx_transport_template =
3415 fc_attach_transport(&qla2xxx_transport_functions);
3416 if (!qla2xxx_transport_template) {
3417 kmem_cache_destroy(srb_cachep);
3420 qla2xxx_transport_vport_template =
3421 fc_attach_transport(&qla2xxx_transport_vport_functions);
3422 if (!qla2xxx_transport_vport_template) {
3423 kmem_cache_destroy(srb_cachep);
3424 fc_release_transport(qla2xxx_transport_template);
3428 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
3429 qla2x00_version_str);
3430 ret = pci_register_driver(&qla2xxx_pci_driver);
3432 kmem_cache_destroy(srb_cachep);
3433 fc_release_transport(qla2xxx_transport_template);
3434 fc_release_transport(qla2xxx_transport_vport_template);
3440 * qla2x00_module_exit - Module cleanup.
3443 qla2x00_module_exit(void)
3445 pci_unregister_driver(&qla2xxx_pci_driver);
3446 qla2x00_release_firmware();
3447 kmem_cache_destroy(srb_cachep);
3448 fc_release_transport(qla2xxx_transport_template);
3449 fc_release_transport(qla2xxx_transport_vport_template);
3452 module_init(qla2x00_module_init);
3453 module_exit(qla2x00_module_exit);
3455 MODULE_AUTHOR("QLogic Corporation");
3456 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3457 MODULE_LICENSE("GPL");
3458 MODULE_VERSION(QLA2XXX_VERSION);
3459 MODULE_FIRMWARE(FW_FILE_ISP21XX);
3460 MODULE_FIRMWARE(FW_FILE_ISP22XX);
3461 MODULE_FIRMWARE(FW_FILE_ISP2300);
3462 MODULE_FIRMWARE(FW_FILE_ISP2322);
3463 MODULE_FIRMWARE(FW_FILE_ISP24XX);
3464 MODULE_FIRMWARE(FW_FILE_ISP25XX);
3465 MODULE_FIRMWARE(FW_FILE_ISP81XX);