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 (ha->flags.eeh_busy) {
479 if (ha->flags.pci_channel_io_perm_failure)
480 cmd->result = DID_NO_CONNECT << 16;
482 cmd->result = DID_REQUEUE << 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 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
556 struct qla_hw_data *ha = vha->hw;
557 int ret = QLA_SUCCESS;
559 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
560 DEBUG17(qla_printk(KERN_WARNING, ha, "return:eh_wait\n"));
564 while (CMD_SP(cmd) && wait_iter--) {
565 msleep(ABORT_POLLING_PERIOD);
568 ret = QLA_FUNCTION_FAILED;
574 * qla2x00_wait_for_hba_online
575 * Wait till the HBA is online after going through
576 * <= MAX_RETRIES_OF_ISP_ABORT or
577 * finally HBA is disabled ie marked offline
580 * ha - pointer to host adapter structure
583 * Does context switching-Release SPIN_LOCK
584 * (if any) before calling this routine.
587 * Success (Adapter is online) : 0
588 * Failed (Adapter is offline/disabled) : 1
591 qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
594 unsigned long wait_online;
595 struct qla_hw_data *ha = vha->hw;
596 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
598 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
599 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
600 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
601 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
602 ha->dpc_active) && time_before(jiffies, wait_online)) {
606 if (base_vha->flags.online)
607 return_status = QLA_SUCCESS;
609 return_status = QLA_FUNCTION_FAILED;
611 return (return_status);
615 qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
618 unsigned long wait_reset;
619 struct qla_hw_data *ha = vha->hw;
620 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
622 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
623 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
624 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
625 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
626 ha->dpc_active) && time_before(jiffies, wait_reset)) {
630 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
631 ha->flags.chip_reset_done)
634 if (ha->flags.chip_reset_done)
635 return_status = QLA_SUCCESS;
637 return_status = QLA_FUNCTION_FAILED;
639 return return_status;
643 * qla2x00_wait_for_loop_ready
644 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
645 * to be in LOOP_READY state.
647 * ha - pointer to host adapter structure
650 * Does context switching-Release SPIN_LOCK
651 * (if any) before calling this routine.
655 * Success (LOOP_READY) : 0
656 * Failed (LOOP_NOT_READY) : 1
659 qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
661 int return_status = QLA_SUCCESS;
662 unsigned long loop_timeout ;
663 struct qla_hw_data *ha = vha->hw;
664 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
666 /* wait for 5 min at the max for loop to be ready */
667 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
669 while ((!atomic_read(&base_vha->loop_down_timer) &&
670 atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
671 atomic_read(&base_vha->loop_state) != LOOP_READY) {
672 if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
673 return_status = QLA_FUNCTION_FAILED;
677 if (time_after_eq(jiffies, loop_timeout)) {
678 return_status = QLA_FUNCTION_FAILED;
682 return (return_status);
686 qla2x00_abort_fcport_cmds(fc_port_t *fcport)
691 scsi_qla_host_t *vha = fcport->vha;
692 struct qla_hw_data *ha = vha->hw;
695 spin_lock_irqsave(&ha->hardware_lock, flags);
697 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
698 sp = req->outstanding_cmds[cnt];
701 if (sp->fcport != fcport)
706 spin_unlock_irqrestore(&ha->hardware_lock, flags);
707 if (ha->isp_ops->abort_command(sp)) {
708 DEBUG2(qla_printk(KERN_WARNING, ha,
709 "Abort failed -- %lx\n",
710 sp->cmd->serial_number));
712 if (qla2x00_eh_wait_on_command(sp->cmd) !=
714 DEBUG2(qla_printk(KERN_WARNING, ha,
715 "Abort failed while waiting -- %lx\n",
716 sp->cmd->serial_number));
718 spin_lock_irqsave(&ha->hardware_lock, flags);
720 spin_unlock_irqrestore(&ha->hardware_lock, flags);
723 /**************************************************************************
727 * The abort function will abort the specified command.
730 * cmd = Linux SCSI command packet to be aborted.
733 * Either SUCCESS or FAILED.
736 * Only return FAILED if command not returned by firmware.
737 **************************************************************************/
739 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
741 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
744 unsigned int id, lun;
745 unsigned long serial;
748 struct qla_hw_data *ha = vha->hw;
749 struct req_que *req = vha->req;
752 fc_block_scsi_eh(cmd);
759 id = cmd->device->id;
760 lun = cmd->device->lun;
761 serial = cmd->serial_number;
762 spt = (srb_t *) CMD_SP(cmd);
766 /* Check active list for command command. */
767 spin_lock_irqsave(&ha->hardware_lock, flags);
768 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
769 sp = req->outstanding_cmds[i];
778 DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
779 " pid=%ld.\n", __func__, vha->host_no, sp, serial));
781 spin_unlock_irqrestore(&ha->hardware_lock, flags);
782 if (ha->isp_ops->abort_command(sp)) {
783 DEBUG2(printk("%s(%ld): abort_command "
784 "mbx failed.\n", __func__, vha->host_no));
787 DEBUG3(printk("%s(%ld): abort_command "
788 "mbx success.\n", __func__, vha->host_no));
791 spin_lock_irqsave(&ha->hardware_lock, flags);
794 spin_unlock_irqrestore(&ha->hardware_lock, flags);
796 /* Wait for the command to be returned. */
798 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
799 qla_printk(KERN_ERR, ha,
800 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
801 "%x.\n", vha->host_no, id, lun, serial, ret);
806 qla_printk(KERN_INFO, ha,
807 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
808 vha->host_no, id, lun, wait, serial, ret);
813 enum nexus_wait_type {
820 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
821 unsigned int l, srb_t *sp, enum nexus_wait_type type)
823 int cnt, match, status;
825 struct qla_hw_data *ha = vha->hw;
828 status = QLA_SUCCESS;
832 spin_lock_irqsave(&ha->hardware_lock, flags);
834 for (cnt = 1; status == QLA_SUCCESS &&
835 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
836 sp = req->outstanding_cmds[cnt];
841 if (vha->vp_idx != sp->fcport->vha->vp_idx)
849 match = sp->cmd->device->id == t;
852 match = (sp->cmd->device->id == t &&
853 sp->cmd->device->lun == l);
859 spin_unlock_irqrestore(&ha->hardware_lock, flags);
860 status = qla2x00_eh_wait_on_command(sp->cmd);
861 spin_lock_irqsave(&ha->hardware_lock, flags);
863 spin_unlock_irqrestore(&ha->hardware_lock, flags);
868 static char *reset_errors[] = {
871 "Task management failed",
872 "Waiting for command completions",
876 __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
877 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
879 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
880 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
883 fc_block_scsi_eh(cmd);
888 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
889 vha->host_no, cmd->device->id, cmd->device->lun, name);
892 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
893 goto eh_reset_failed;
895 if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
896 goto eh_reset_failed;
898 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
900 goto eh_reset_failed;
902 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
903 cmd->device->lun, (srb_t *) CMD_SP(cmd), type) != QLA_SUCCESS)
904 goto eh_reset_failed;
906 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
907 vha->host_no, cmd->device->id, cmd->device->lun, name);
912 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
913 , vha->host_no, cmd->device->id, cmd->device->lun, name,
919 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
921 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
922 struct qla_hw_data *ha = vha->hw;
924 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
925 ha->isp_ops->lun_reset);
929 qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
931 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
932 struct qla_hw_data *ha = vha->hw;
934 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
935 ha->isp_ops->target_reset);
938 /**************************************************************************
939 * qla2xxx_eh_bus_reset
942 * The bus reset function will reset the bus and abort any executing
946 * cmd = Linux SCSI command packet of the command that cause the
950 * SUCCESS/FAILURE (defined as macro in scsi.h).
952 **************************************************************************/
954 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
956 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
957 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
959 unsigned int id, lun;
960 unsigned long serial;
961 srb_t *sp = (srb_t *) CMD_SP(cmd);
963 fc_block_scsi_eh(cmd);
965 id = cmd->device->id;
966 lun = cmd->device->lun;
967 serial = cmd->serial_number;
972 qla_printk(KERN_INFO, vha->hw,
973 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
975 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
976 DEBUG2(printk("%s failed:board disabled\n",__func__));
977 goto eh_bus_reset_done;
980 if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
981 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
985 goto eh_bus_reset_done;
987 /* Flush outstanding commands. */
988 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) !=
993 qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
994 (ret == FAILED) ? "failed" : "succeded");
999 /**************************************************************************
1000 * qla2xxx_eh_host_reset
1003 * The reset function will reset the Adapter.
1006 * cmd = Linux SCSI command packet of the command that cause the
1010 * Either SUCCESS or FAILED.
1013 **************************************************************************/
1015 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1017 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1018 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1019 struct qla_hw_data *ha = vha->hw;
1021 unsigned int id, lun;
1022 unsigned long serial;
1023 srb_t *sp = (srb_t *) CMD_SP(cmd);
1024 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1026 fc_block_scsi_eh(cmd);
1028 id = cmd->device->id;
1029 lun = cmd->device->lun;
1030 serial = cmd->serial_number;
1035 qla_printk(KERN_INFO, ha,
1036 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
1038 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1039 goto eh_host_reset_lock;
1042 * Fixme-may be dpc thread is active and processing
1043 * loop_resync,so wait a while for it to
1044 * be completed and then issue big hammer.Otherwise
1045 * it may cause I/O failure as big hammer marks the
1046 * devices as lost kicking of the port_down_timer
1047 * while dpc is stuck for the mailbox to complete.
1049 qla2x00_wait_for_loop_ready(vha);
1050 if (vha != base_vha) {
1051 if (qla2x00_vp_abort_isp(vha))
1052 goto eh_host_reset_lock;
1055 flush_workqueue(ha->wq);
1057 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1058 if (qla2x00_abort_isp(base_vha)) {
1059 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1060 /* failed. schedule dpc to try */
1061 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1063 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1064 goto eh_host_reset_lock;
1066 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1069 /* Waiting for command to be returned to OS.*/
1070 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) ==
1075 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1076 (ret == FAILED) ? "failed" : "succeded");
1082 * qla2x00_loop_reset
1086 * ha = adapter block pointer.
1092 qla2x00_loop_reset(scsi_qla_host_t *vha)
1095 struct fc_port *fcport;
1096 struct qla_hw_data *ha = vha->hw;
1098 if (ha->flags.enable_lip_full_login && !IS_QLA81XX(ha)) {
1099 ret = qla2x00_full_login_lip(vha);
1100 if (ret != QLA_SUCCESS) {
1101 DEBUG2_3(printk("%s(%ld): failed: "
1102 "full_login_lip=%d.\n", __func__, vha->host_no,
1105 atomic_set(&vha->loop_state, LOOP_DOWN);
1106 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1107 qla2x00_mark_all_devices_lost(vha, 0);
1108 qla2x00_wait_for_loop_ready(vha);
1111 if (ha->flags.enable_lip_reset) {
1112 ret = qla2x00_lip_reset(vha);
1113 if (ret != QLA_SUCCESS) {
1114 DEBUG2_3(printk("%s(%ld): failed: "
1115 "lip_reset=%d.\n", __func__, vha->host_no, ret));
1117 qla2x00_wait_for_loop_ready(vha);
1120 if (ha->flags.enable_target_reset) {
1121 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1122 if (fcport->port_type != FCT_TARGET)
1125 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1126 if (ret != QLA_SUCCESS) {
1127 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1128 "target_reset=%d d_id=%x.\n", __func__,
1129 vha->host_no, ret, fcport->d_id.b24));
1133 /* Issue marker command only when we are going to start the I/O */
1134 vha->marker_needed = 1;
1140 qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1143 unsigned long flags;
1145 struct srb_ctx *ctx;
1146 struct qla_hw_data *ha = vha->hw;
1147 struct req_que *req;
1149 spin_lock_irqsave(&ha->hardware_lock, flags);
1150 for (que = 0; que < ha->max_req_queues; que++) {
1151 req = ha->req_q_map[que];
1154 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1155 sp = req->outstanding_cmds[cnt];
1157 req->outstanding_cmds[cnt] = NULL;
1159 sp->cmd->result = res;
1160 qla2x00_sp_compl(ha, sp);
1163 if (ctx->type == SRB_LOGIN_CMD || ctx->type == SRB_LOGOUT_CMD) {
1164 del_timer_sync(&ctx->timer);
1167 struct srb_bsg* sp_bsg = (struct srb_bsg*)sp->ctx;
1168 if (sp_bsg->bsg_job->request->msgcode == FC_BSG_HST_CT)
1170 sp_bsg->bsg_job->req->errors = 0;
1171 sp_bsg->bsg_job->reply->result = res;
1172 sp_bsg->bsg_job->job_done(sp_bsg->bsg_job);
1174 mempool_free(sp, ha->srb_mempool);
1180 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1184 qla2xxx_slave_alloc(struct scsi_device *sdev)
1186 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1188 if (!rport || fc_remote_port_chkready(rport))
1191 sdev->hostdata = *(fc_port_t **)rport->dd_data;
1197 qla2xxx_slave_configure(struct scsi_device *sdev)
1199 scsi_qla_host_t *vha = shost_priv(sdev->host);
1200 struct qla_hw_data *ha = vha->hw;
1201 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1202 struct req_que *req = vha->req;
1204 if (sdev->tagged_supported)
1205 scsi_activate_tcq(sdev, req->max_q_depth);
1207 scsi_deactivate_tcq(sdev, req->max_q_depth);
1209 rport->dev_loss_tmo = ha->port_down_retry_count;
1215 qla2xxx_slave_destroy(struct scsi_device *sdev)
1217 sdev->hostdata = NULL;
1220 static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
1222 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1224 if (!scsi_track_queue_full(sdev, qdepth))
1227 DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw,
1228 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
1229 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
1230 sdev->queue_depth));
1233 static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
1235 fc_port_t *fcport = sdev->hostdata;
1236 struct scsi_qla_host *vha = fcport->vha;
1237 struct qla_hw_data *ha = vha->hw;
1238 struct req_que *req = NULL;
1244 if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
1247 if (sdev->ordered_tags)
1248 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
1250 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
1252 DEBUG2(qla_printk(KERN_INFO, ha,
1253 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
1254 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
1255 sdev->queue_depth));
1259 qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1262 case SCSI_QDEPTH_DEFAULT:
1263 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1265 case SCSI_QDEPTH_QFULL:
1266 qla2x00_handle_queue_full(sdev, qdepth);
1268 case SCSI_QDEPTH_RAMP_UP:
1269 qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
1275 return sdev->queue_depth;
1279 qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1281 if (sdev->tagged_supported) {
1282 scsi_set_tag_type(sdev, tag_type);
1284 scsi_activate_tcq(sdev, sdev->queue_depth);
1286 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1294 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1297 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1298 * supported addressing method.
1301 qla2x00_config_dma_addressing(struct qla_hw_data *ha)
1303 /* Assume a 32bit DMA mask. */
1304 ha->flags.enable_64bit_addressing = 0;
1306 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1307 /* Any upper-dword bits set? */
1308 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1309 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
1310 /* Ok, a 64bit DMA mask is applicable. */
1311 ha->flags.enable_64bit_addressing = 1;
1312 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1313 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
1318 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1319 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
1323 qla2x00_enable_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 = 1;
1330 /* enable risc and host interrupts */
1331 WRT_REG_WORD(®->ictrl, ICR_EN_INT | ICR_EN_RISC);
1332 RD_REG_WORD(®->ictrl);
1333 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1338 qla2x00_disable_intrs(struct qla_hw_data *ha)
1340 unsigned long flags = 0;
1341 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1343 spin_lock_irqsave(&ha->hardware_lock, flags);
1344 ha->interrupts_on = 0;
1345 /* disable risc and host interrupts */
1346 WRT_REG_WORD(®->ictrl, 0);
1347 RD_REG_WORD(®->ictrl);
1348 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1352 qla24xx_enable_intrs(struct qla_hw_data *ha)
1354 unsigned long flags = 0;
1355 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1357 spin_lock_irqsave(&ha->hardware_lock, flags);
1358 ha->interrupts_on = 1;
1359 WRT_REG_DWORD(®->ictrl, ICRX_EN_RISC_INT);
1360 RD_REG_DWORD(®->ictrl);
1361 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1365 qla24xx_disable_intrs(struct qla_hw_data *ha)
1367 unsigned long flags = 0;
1368 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1370 if (IS_NOPOLLING_TYPE(ha))
1372 spin_lock_irqsave(&ha->hardware_lock, flags);
1373 ha->interrupts_on = 0;
1374 WRT_REG_DWORD(®->ictrl, 0);
1375 RD_REG_DWORD(®->ictrl);
1376 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1379 static struct isp_operations qla2100_isp_ops = {
1380 .pci_config = qla2100_pci_config,
1381 .reset_chip = qla2x00_reset_chip,
1382 .chip_diag = qla2x00_chip_diag,
1383 .config_rings = qla2x00_config_rings,
1384 .reset_adapter = qla2x00_reset_adapter,
1385 .nvram_config = qla2x00_nvram_config,
1386 .update_fw_options = qla2x00_update_fw_options,
1387 .load_risc = qla2x00_load_risc,
1388 .pci_info_str = qla2x00_pci_info_str,
1389 .fw_version_str = qla2x00_fw_version_str,
1390 .intr_handler = qla2100_intr_handler,
1391 .enable_intrs = qla2x00_enable_intrs,
1392 .disable_intrs = qla2x00_disable_intrs,
1393 .abort_command = qla2x00_abort_command,
1394 .target_reset = qla2x00_abort_target,
1395 .lun_reset = qla2x00_lun_reset,
1396 .fabric_login = qla2x00_login_fabric,
1397 .fabric_logout = qla2x00_fabric_logout,
1398 .calc_req_entries = qla2x00_calc_iocbs_32,
1399 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1400 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1401 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1402 .read_nvram = qla2x00_read_nvram_data,
1403 .write_nvram = qla2x00_write_nvram_data,
1404 .fw_dump = qla2100_fw_dump,
1407 .beacon_blink = NULL,
1408 .read_optrom = qla2x00_read_optrom_data,
1409 .write_optrom = qla2x00_write_optrom_data,
1410 .get_flash_version = qla2x00_get_flash_version,
1411 .start_scsi = qla2x00_start_scsi,
1414 static struct isp_operations qla2300_isp_ops = {
1415 .pci_config = qla2300_pci_config,
1416 .reset_chip = qla2x00_reset_chip,
1417 .chip_diag = qla2x00_chip_diag,
1418 .config_rings = qla2x00_config_rings,
1419 .reset_adapter = qla2x00_reset_adapter,
1420 .nvram_config = qla2x00_nvram_config,
1421 .update_fw_options = qla2x00_update_fw_options,
1422 .load_risc = qla2x00_load_risc,
1423 .pci_info_str = qla2x00_pci_info_str,
1424 .fw_version_str = qla2x00_fw_version_str,
1425 .intr_handler = qla2300_intr_handler,
1426 .enable_intrs = qla2x00_enable_intrs,
1427 .disable_intrs = qla2x00_disable_intrs,
1428 .abort_command = qla2x00_abort_command,
1429 .target_reset = qla2x00_abort_target,
1430 .lun_reset = qla2x00_lun_reset,
1431 .fabric_login = qla2x00_login_fabric,
1432 .fabric_logout = qla2x00_fabric_logout,
1433 .calc_req_entries = qla2x00_calc_iocbs_32,
1434 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1435 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1436 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1437 .read_nvram = qla2x00_read_nvram_data,
1438 .write_nvram = qla2x00_write_nvram_data,
1439 .fw_dump = qla2300_fw_dump,
1440 .beacon_on = qla2x00_beacon_on,
1441 .beacon_off = qla2x00_beacon_off,
1442 .beacon_blink = qla2x00_beacon_blink,
1443 .read_optrom = qla2x00_read_optrom_data,
1444 .write_optrom = qla2x00_write_optrom_data,
1445 .get_flash_version = qla2x00_get_flash_version,
1446 .start_scsi = qla2x00_start_scsi,
1449 static struct isp_operations qla24xx_isp_ops = {
1450 .pci_config = qla24xx_pci_config,
1451 .reset_chip = qla24xx_reset_chip,
1452 .chip_diag = qla24xx_chip_diag,
1453 .config_rings = qla24xx_config_rings,
1454 .reset_adapter = qla24xx_reset_adapter,
1455 .nvram_config = qla24xx_nvram_config,
1456 .update_fw_options = qla24xx_update_fw_options,
1457 .load_risc = qla24xx_load_risc,
1458 .pci_info_str = qla24xx_pci_info_str,
1459 .fw_version_str = qla24xx_fw_version_str,
1460 .intr_handler = qla24xx_intr_handler,
1461 .enable_intrs = qla24xx_enable_intrs,
1462 .disable_intrs = qla24xx_disable_intrs,
1463 .abort_command = qla24xx_abort_command,
1464 .target_reset = qla24xx_abort_target,
1465 .lun_reset = qla24xx_lun_reset,
1466 .fabric_login = qla24xx_login_fabric,
1467 .fabric_logout = qla24xx_fabric_logout,
1468 .calc_req_entries = NULL,
1469 .build_iocbs = NULL,
1470 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1471 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1472 .read_nvram = qla24xx_read_nvram_data,
1473 .write_nvram = qla24xx_write_nvram_data,
1474 .fw_dump = qla24xx_fw_dump,
1475 .beacon_on = qla24xx_beacon_on,
1476 .beacon_off = qla24xx_beacon_off,
1477 .beacon_blink = qla24xx_beacon_blink,
1478 .read_optrom = qla24xx_read_optrom_data,
1479 .write_optrom = qla24xx_write_optrom_data,
1480 .get_flash_version = qla24xx_get_flash_version,
1481 .start_scsi = qla24xx_start_scsi,
1484 static struct isp_operations qla25xx_isp_ops = {
1485 .pci_config = qla25xx_pci_config,
1486 .reset_chip = qla24xx_reset_chip,
1487 .chip_diag = qla24xx_chip_diag,
1488 .config_rings = qla24xx_config_rings,
1489 .reset_adapter = qla24xx_reset_adapter,
1490 .nvram_config = qla24xx_nvram_config,
1491 .update_fw_options = qla24xx_update_fw_options,
1492 .load_risc = qla24xx_load_risc,
1493 .pci_info_str = qla24xx_pci_info_str,
1494 .fw_version_str = qla24xx_fw_version_str,
1495 .intr_handler = qla24xx_intr_handler,
1496 .enable_intrs = qla24xx_enable_intrs,
1497 .disable_intrs = qla24xx_disable_intrs,
1498 .abort_command = qla24xx_abort_command,
1499 .target_reset = qla24xx_abort_target,
1500 .lun_reset = qla24xx_lun_reset,
1501 .fabric_login = qla24xx_login_fabric,
1502 .fabric_logout = qla24xx_fabric_logout,
1503 .calc_req_entries = NULL,
1504 .build_iocbs = NULL,
1505 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1506 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1507 .read_nvram = qla25xx_read_nvram_data,
1508 .write_nvram = qla25xx_write_nvram_data,
1509 .fw_dump = qla25xx_fw_dump,
1510 .beacon_on = qla24xx_beacon_on,
1511 .beacon_off = qla24xx_beacon_off,
1512 .beacon_blink = qla24xx_beacon_blink,
1513 .read_optrom = qla25xx_read_optrom_data,
1514 .write_optrom = qla24xx_write_optrom_data,
1515 .get_flash_version = qla24xx_get_flash_version,
1516 .start_scsi = qla24xx_start_scsi,
1519 static struct isp_operations qla81xx_isp_ops = {
1520 .pci_config = qla25xx_pci_config,
1521 .reset_chip = qla24xx_reset_chip,
1522 .chip_diag = qla24xx_chip_diag,
1523 .config_rings = qla24xx_config_rings,
1524 .reset_adapter = qla24xx_reset_adapter,
1525 .nvram_config = qla81xx_nvram_config,
1526 .update_fw_options = qla81xx_update_fw_options,
1527 .load_risc = qla81xx_load_risc,
1528 .pci_info_str = qla24xx_pci_info_str,
1529 .fw_version_str = qla24xx_fw_version_str,
1530 .intr_handler = qla24xx_intr_handler,
1531 .enable_intrs = qla24xx_enable_intrs,
1532 .disable_intrs = qla24xx_disable_intrs,
1533 .abort_command = qla24xx_abort_command,
1534 .target_reset = qla24xx_abort_target,
1535 .lun_reset = qla24xx_lun_reset,
1536 .fabric_login = qla24xx_login_fabric,
1537 .fabric_logout = qla24xx_fabric_logout,
1538 .calc_req_entries = NULL,
1539 .build_iocbs = NULL,
1540 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1541 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1543 .write_nvram = NULL,
1544 .fw_dump = qla81xx_fw_dump,
1545 .beacon_on = qla24xx_beacon_on,
1546 .beacon_off = qla24xx_beacon_off,
1547 .beacon_blink = qla24xx_beacon_blink,
1548 .read_optrom = qla25xx_read_optrom_data,
1549 .write_optrom = qla24xx_write_optrom_data,
1550 .get_flash_version = qla24xx_get_flash_version,
1551 .start_scsi = qla24xx_start_scsi,
1555 qla2x00_set_isp_flags(struct qla_hw_data *ha)
1557 ha->device_type = DT_EXTENDED_IDS;
1558 switch (ha->pdev->device) {
1559 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1560 ha->device_type |= DT_ISP2100;
1561 ha->device_type &= ~DT_EXTENDED_IDS;
1562 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
1564 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1565 ha->device_type |= DT_ISP2200;
1566 ha->device_type &= ~DT_EXTENDED_IDS;
1567 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
1569 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1570 ha->device_type |= DT_ISP2300;
1571 ha->device_type |= DT_ZIO_SUPPORTED;
1572 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1574 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1575 ha->device_type |= DT_ISP2312;
1576 ha->device_type |= DT_ZIO_SUPPORTED;
1577 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1579 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1580 ha->device_type |= DT_ISP2322;
1581 ha->device_type |= DT_ZIO_SUPPORTED;
1582 if (ha->pdev->subsystem_vendor == 0x1028 &&
1583 ha->pdev->subsystem_device == 0x0170)
1584 ha->device_type |= DT_OEM_001;
1585 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1587 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1588 ha->device_type |= DT_ISP6312;
1589 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1591 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1592 ha->device_type |= DT_ISP6322;
1593 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1595 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1596 ha->device_type |= DT_ISP2422;
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_ISP2432:
1603 ha->device_type |= DT_ISP2432;
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;
1609 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1610 ha->device_type |= DT_ISP8432;
1611 ha->device_type |= DT_ZIO_SUPPORTED;
1612 ha->device_type |= DT_FWI2;
1613 ha->device_type |= DT_IIDMA;
1614 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1616 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1617 ha->device_type |= DT_ISP5422;
1618 ha->device_type |= DT_FWI2;
1619 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1621 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1622 ha->device_type |= DT_ISP5432;
1623 ha->device_type |= DT_FWI2;
1624 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1626 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1627 ha->device_type |= DT_ISP2532;
1628 ha->device_type |= DT_ZIO_SUPPORTED;
1629 ha->device_type |= DT_FWI2;
1630 ha->device_type |= DT_IIDMA;
1631 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1633 case PCI_DEVICE_ID_QLOGIC_ISP8001:
1634 ha->device_type |= DT_ISP8001;
1635 ha->device_type |= DT_ZIO_SUPPORTED;
1636 ha->device_type |= DT_FWI2;
1637 ha->device_type |= DT_IIDMA;
1638 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1642 /* Get adapter physical port no from interrupt pin register. */
1643 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
1644 if (ha->port_no & 1)
1645 ha->flags.port0 = 1;
1647 ha->flags.port0 = 0;
1651 qla2x00_iospace_config(struct qla_hw_data *ha)
1653 resource_size_t pio;
1657 if (pci_request_selected_regions(ha->pdev, ha->bars,
1658 QLA2XXX_DRIVER_NAME)) {
1659 qla_printk(KERN_WARNING, ha,
1660 "Failed to reserve PIO/MMIO regions (%s)\n",
1661 pci_name(ha->pdev));
1663 goto iospace_error_exit;
1665 if (!(ha->bars & 1))
1668 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1669 pio = pci_resource_start(ha->pdev, 0);
1670 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1671 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1672 qla_printk(KERN_WARNING, ha,
1673 "Invalid PCI I/O region size (%s)...\n",
1674 pci_name(ha->pdev));
1678 qla_printk(KERN_WARNING, ha,
1679 "region #0 not a PIO resource (%s)...\n",
1680 pci_name(ha->pdev));
1683 ha->pio_address = pio;
1686 /* Use MMIO operations for all accesses. */
1687 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1688 qla_printk(KERN_ERR, ha,
1689 "region #1 not an MMIO resource (%s), aborting\n",
1690 pci_name(ha->pdev));
1691 goto iospace_error_exit;
1693 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1694 qla_printk(KERN_ERR, ha,
1695 "Invalid PCI mem region size (%s), aborting\n",
1696 pci_name(ha->pdev));
1697 goto iospace_error_exit;
1700 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1702 qla_printk(KERN_ERR, ha,
1703 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1705 goto iospace_error_exit;
1708 /* Determine queue resources */
1709 ha->max_req_queues = ha->max_rsp_queues = 1;
1710 if ((ql2xmaxqueues <= 1 || ql2xmultique_tag < 1) &&
1711 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1713 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1714 pci_resource_len(ha->pdev, 3));
1716 /* Read MSIX vector size of the board */
1717 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1718 ha->msix_count = msix;
1719 /* Max queues are bounded by available msix vectors */
1720 /* queue 0 uses two msix vectors */
1721 if (ql2xmultique_tag) {
1722 cpus = num_online_cpus();
1723 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1724 (cpus + 1) : (ha->msix_count - 1);
1725 ha->max_req_queues = 2;
1726 } else if (ql2xmaxqueues > 1) {
1727 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1728 QLA_MQ_SIZE : ql2xmaxqueues;
1729 DEBUG2(qla_printk(KERN_INFO, ha, "QoS mode set, max no"
1730 " of request queues:%d\n", ha->max_req_queues));
1732 qla_printk(KERN_INFO, ha,
1733 "MSI-X vector count: %d\n", msix);
1735 qla_printk(KERN_INFO, ha, "BAR 3 not enabled\n");
1738 ha->msix_count = ha->max_rsp_queues + 1;
1746 qla2xxx_scan_start(struct Scsi_Host *shost)
1748 scsi_qla_host_t *vha = shost_priv(shost);
1750 if (vha->hw->flags.running_gold_fw)
1753 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1754 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1755 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1756 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
1760 qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1762 scsi_qla_host_t *vha = shost_priv(shost);
1766 if (time > vha->hw->loop_reset_delay * HZ)
1769 return atomic_read(&vha->loop_state) == LOOP_READY;
1773 * PCI driver interface
1775 static int __devinit
1776 qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1779 struct Scsi_Host *host;
1780 scsi_qla_host_t *base_vha = NULL;
1781 struct qla_hw_data *ha;
1784 struct scsi_host_template *sht;
1785 int bars, max_id, mem_only = 0;
1786 uint16_t req_length = 0, rsp_length = 0;
1787 struct req_que *req = NULL;
1788 struct rsp_que *rsp = NULL;
1790 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
1791 sht = &qla2xxx_driver_template;
1792 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1793 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
1794 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
1795 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1796 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
1797 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
1798 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001) {
1799 bars = pci_select_bars(pdev, IORESOURCE_MEM);
1804 if (pci_enable_device_mem(pdev))
1807 if (pci_enable_device(pdev))
1811 /* This may fail but that's ok */
1812 pci_enable_pcie_error_reporting(pdev);
1814 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
1816 DEBUG(printk("Unable to allocate memory for ha\n"));
1821 /* Clear our data area */
1823 ha->mem_only = mem_only;
1824 spin_lock_init(&ha->hardware_lock);
1826 /* Set ISP-type information. */
1827 qla2x00_set_isp_flags(ha);
1829 /* Set EEH reset type to fundamental if required by hba */
1830 if ( IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha)) {
1831 pdev->needs_freset = 1;
1834 /* Configure PCI I/O space */
1835 ret = qla2x00_iospace_config(ha);
1837 goto probe_hw_failed;
1839 qla_printk(KERN_INFO, ha,
1840 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1843 ha->prev_topology = 0;
1844 ha->init_cb_size = sizeof(init_cb_t);
1845 ha->link_data_rate = PORT_SPEED_UNKNOWN;
1846 ha->optrom_size = OPTROM_SIZE_2300;
1848 /* Assign ISP specific operations. */
1849 max_id = MAX_TARGETS_2200;
1850 if (IS_QLA2100(ha)) {
1851 max_id = MAX_TARGETS_2100;
1852 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1853 req_length = REQUEST_ENTRY_CNT_2100;
1854 rsp_length = RESPONSE_ENTRY_CNT_2100;
1855 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
1856 ha->gid_list_info_size = 4;
1857 ha->flash_conf_off = ~0;
1858 ha->flash_data_off = ~0;
1859 ha->nvram_conf_off = ~0;
1860 ha->nvram_data_off = ~0;
1861 ha->isp_ops = &qla2100_isp_ops;
1862 } else if (IS_QLA2200(ha)) {
1863 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1864 req_length = REQUEST_ENTRY_CNT_2200;
1865 rsp_length = RESPONSE_ENTRY_CNT_2100;
1866 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
1867 ha->gid_list_info_size = 4;
1868 ha->flash_conf_off = ~0;
1869 ha->flash_data_off = ~0;
1870 ha->nvram_conf_off = ~0;
1871 ha->nvram_data_off = ~0;
1872 ha->isp_ops = &qla2100_isp_ops;
1873 } else if (IS_QLA23XX(ha)) {
1874 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1875 req_length = REQUEST_ENTRY_CNT_2200;
1876 rsp_length = RESPONSE_ENTRY_CNT_2300;
1877 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1878 ha->gid_list_info_size = 6;
1879 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1880 ha->optrom_size = OPTROM_SIZE_2322;
1881 ha->flash_conf_off = ~0;
1882 ha->flash_data_off = ~0;
1883 ha->nvram_conf_off = ~0;
1884 ha->nvram_data_off = ~0;
1885 ha->isp_ops = &qla2300_isp_ops;
1886 } else if (IS_QLA24XX_TYPE(ha)) {
1887 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1888 req_length = REQUEST_ENTRY_CNT_24XX;
1889 rsp_length = RESPONSE_ENTRY_CNT_2300;
1890 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1891 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1892 ha->gid_list_info_size = 8;
1893 ha->optrom_size = OPTROM_SIZE_24XX;
1894 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
1895 ha->isp_ops = &qla24xx_isp_ops;
1896 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1897 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1898 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1899 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
1900 } else if (IS_QLA25XX(ha)) {
1901 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1902 req_length = REQUEST_ENTRY_CNT_24XX;
1903 rsp_length = RESPONSE_ENTRY_CNT_2300;
1904 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1905 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1906 ha->gid_list_info_size = 8;
1907 ha->optrom_size = OPTROM_SIZE_25XX;
1908 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
1909 ha->isp_ops = &qla25xx_isp_ops;
1910 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1911 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1912 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1913 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
1914 } else if (IS_QLA81XX(ha)) {
1915 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1916 req_length = REQUEST_ENTRY_CNT_24XX;
1917 rsp_length = RESPONSE_ENTRY_CNT_2300;
1918 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1919 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
1920 ha->gid_list_info_size = 8;
1921 ha->optrom_size = OPTROM_SIZE_81XX;
1922 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
1923 ha->isp_ops = &qla81xx_isp_ops;
1924 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
1925 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
1926 ha->nvram_conf_off = ~0;
1927 ha->nvram_data_off = ~0;
1930 mutex_init(&ha->vport_lock);
1931 init_completion(&ha->mbx_cmd_comp);
1932 complete(&ha->mbx_cmd_comp);
1933 init_completion(&ha->mbx_intr_comp);
1935 set_bit(0, (unsigned long *) ha->vp_idx_map);
1937 qla2x00_config_dma_addressing(ha);
1938 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
1940 qla_printk(KERN_WARNING, ha,
1941 "[ERROR] Failed to allocate memory for adapter\n");
1943 goto probe_hw_failed;
1946 req->max_q_depth = MAX_Q_DEPTH;
1947 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
1948 req->max_q_depth = ql2xmaxqdepth;
1951 base_vha = qla2x00_create_host(sht, ha);
1953 qla_printk(KERN_WARNING, ha,
1954 "[ERROR] Failed to allocate memory for scsi_host\n");
1957 qla2x00_mem_free(ha);
1958 qla2x00_free_req_que(ha, req);
1959 qla2x00_free_rsp_que(ha, rsp);
1960 goto probe_hw_failed;
1963 pci_set_drvdata(pdev, base_vha);
1965 host = base_vha->host;
1966 base_vha->req = req;
1967 host->can_queue = req->length + 128;
1968 if (IS_QLA2XXX_MIDTYPE(ha))
1969 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
1971 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
1974 host->sg_tablesize = 32;
1975 host->max_id = max_id;
1976 host->this_id = 255;
1977 host->cmd_per_lun = 3;
1978 host->unique_id = host->host_no;
1979 host->max_cmd_len = MAX_CMDSZ;
1980 host->max_channel = MAX_BUSES - 1;
1981 host->max_lun = MAX_LUNS;
1982 host->transportt = qla2xxx_transport_template;
1983 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
1985 /* Set up the irqs */
1986 ret = qla2x00_request_irqs(ha, rsp);
1988 goto probe_init_failed;
1990 pci_save_state(pdev);
1992 /* Alloc arrays of request and response ring ptrs */
1994 if (!qla2x00_alloc_queues(ha)) {
1995 qla_printk(KERN_WARNING, ha,
1996 "[ERROR] Failed to allocate memory for queue"
1998 goto probe_init_failed;
2000 ha->rsp_q_map[0] = rsp;
2001 ha->req_q_map[0] = req;
2004 set_bit(0, ha->req_qid_map);
2005 set_bit(0, ha->rsp_qid_map);
2006 /* FWI2-capable only. */
2007 req->req_q_in = &ha->iobase->isp24.req_q_in;
2008 req->req_q_out = &ha->iobase->isp24.req_q_out;
2009 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
2010 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
2012 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2013 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2014 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2015 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
2018 if (qla2x00_initialize_adapter(base_vha)) {
2019 qla_printk(KERN_WARNING, ha,
2020 "Failed to initialize adapter\n");
2022 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
2023 "Adapter flags %x.\n",
2024 base_vha->host_no, base_vha->device_flags));
2031 if (qla25xx_setup_mode(base_vha)) {
2032 qla_printk(KERN_WARNING, ha,
2033 "Can't create queues, falling back to single"
2039 if (ha->flags.running_gold_fw)
2043 * Startup the kernel thread for this host adapter
2045 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
2046 "%s_dpc", base_vha->host_str);
2047 if (IS_ERR(ha->dpc_thread)) {
2048 qla_printk(KERN_WARNING, ha,
2049 "Unable to start DPC thread!\n");
2050 ret = PTR_ERR(ha->dpc_thread);
2055 list_add_tail(&base_vha->list, &ha->vp_list);
2056 base_vha->host->irq = ha->pdev->irq;
2058 /* Initialized the timer */
2059 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
2061 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
2062 base_vha->host_no, ha));
2064 ret = scsi_add_host(host, &pdev->dev);
2068 base_vha->flags.init_done = 1;
2069 base_vha->flags.online = 1;
2071 ha->isp_ops->enable_intrs(ha);
2073 scsi_scan_host(host);
2075 qla2x00_alloc_sysfs_attr(base_vha);
2077 qla2x00_init_host_attr(base_vha);
2079 qla2x00_dfs_setup(base_vha);
2081 qla_printk(KERN_INFO, ha, "\n"
2082 " QLogic Fibre Channel HBA Driver: %s\n"
2084 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
2085 qla2x00_version_str, ha->model_number,
2086 ha->model_desc ? ha->model_desc : "", pdev->device,
2087 ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
2088 ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
2089 ha->isp_ops->fw_version_str(base_vha, fw_str));
2094 qla2x00_free_req_que(ha, req);
2095 qla2x00_free_rsp_que(ha, rsp);
2096 ha->max_req_queues = ha->max_rsp_queues = 0;
2099 if (base_vha->timer_active)
2100 qla2x00_stop_timer(base_vha);
2101 base_vha->flags.online = 0;
2102 if (ha->dpc_thread) {
2103 struct task_struct *t = ha->dpc_thread;
2105 ha->dpc_thread = NULL;
2109 qla2x00_free_device(base_vha);
2111 scsi_host_put(base_vha->host);
2115 iounmap(ha->iobase);
2117 pci_release_selected_regions(ha->pdev, ha->bars);
2122 pci_disable_device(pdev);
2127 qla2x00_remove_one(struct pci_dev *pdev)
2129 scsi_qla_host_t *base_vha, *vha, *temp;
2130 struct qla_hw_data *ha;
2132 base_vha = pci_get_drvdata(pdev);
2135 list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
2136 if (vha && vha->fc_vport)
2137 fc_vport_terminate(vha->fc_vport);
2140 set_bit(UNLOADING, &base_vha->dpc_flags);
2142 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2144 qla2x00_dfs_remove(base_vha);
2146 qla84xx_put_chip(base_vha);
2149 if (base_vha->timer_active)
2150 qla2x00_stop_timer(base_vha);
2152 base_vha->flags.online = 0;
2154 /* Flush the work queue and remove it */
2156 flush_workqueue(ha->wq);
2157 destroy_workqueue(ha->wq);
2161 /* Kill the kernel thread for this host */
2162 if (ha->dpc_thread) {
2163 struct task_struct *t = ha->dpc_thread;
2166 * qla2xxx_wake_dpc checks for ->dpc_thread
2167 * so we need to zero it out.
2169 ha->dpc_thread = NULL;
2173 qla2x00_free_sysfs_attr(base_vha);
2175 fc_remove_host(base_vha->host);
2177 scsi_remove_host(base_vha->host);
2179 qla2x00_free_device(base_vha);
2181 scsi_host_put(base_vha->host);
2184 iounmap(ha->iobase);
2187 iounmap(ha->mqiobase);
2189 pci_release_selected_regions(ha->pdev, ha->bars);
2193 pci_disable_pcie_error_reporting(pdev);
2195 pci_disable_device(pdev);
2196 pci_set_drvdata(pdev, NULL);
2200 qla2x00_free_device(scsi_qla_host_t *vha)
2202 struct qla_hw_data *ha = vha->hw;
2204 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
2207 if (vha->timer_active)
2208 qla2x00_stop_timer(vha);
2210 /* Kill the kernel thread for this host */
2211 if (ha->dpc_thread) {
2212 struct task_struct *t = ha->dpc_thread;
2215 * qla2xxx_wake_dpc checks for ->dpc_thread
2216 * so we need to zero it out.
2218 ha->dpc_thread = NULL;
2222 qla25xx_delete_queues(vha);
2224 if (ha->flags.fce_enabled)
2225 qla2x00_disable_fce_trace(vha, NULL, NULL);
2228 qla2x00_disable_eft_trace(vha);
2230 /* Stop currently executing firmware. */
2231 qla2x00_try_to_stop_firmware(vha);
2233 vha->flags.online = 0;
2235 /* turn-off interrupts on the card */
2236 if (ha->interrupts_on)
2237 ha->isp_ops->disable_intrs(ha);
2239 qla2x00_free_irqs(vha);
2241 qla2x00_mem_free(ha);
2243 qla2x00_free_queues(ha);
2247 qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
2250 struct fc_rport *rport;
2251 scsi_qla_host_t *base_vha;
2256 rport = fcport->rport;
2258 base_vha = pci_get_drvdata(vha->hw->pdev);
2259 spin_lock_irq(vha->host->host_lock);
2260 fcport->drport = rport;
2261 spin_unlock_irq(vha->host->host_lock);
2262 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2263 qla2xxx_wake_dpc(base_vha);
2265 fc_remote_port_delete(rport);
2269 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2271 * Input: ha = adapter block pointer. fcport = port structure pointer.
2277 void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
2278 int do_login, int defer)
2280 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2281 vha->vp_idx == fcport->vp_idx) {
2282 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2283 qla2x00_schedule_rport_del(vha, fcport, defer);
2286 * We may need to retry the login, so don't change the state of the
2287 * port but do the retries.
2289 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2290 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2295 if (fcport->login_retry == 0) {
2296 fcport->login_retry = vha->hw->login_retry_count;
2297 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2299 DEBUG(printk("scsi(%ld): Port login retry: "
2300 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2301 "id = 0x%04x retry cnt=%d\n",
2303 fcport->port_name[0],
2304 fcport->port_name[1],
2305 fcport->port_name[2],
2306 fcport->port_name[3],
2307 fcport->port_name[4],
2308 fcport->port_name[5],
2309 fcport->port_name[6],
2310 fcport->port_name[7],
2312 fcport->login_retry));
2317 * qla2x00_mark_all_devices_lost
2318 * Updates fcport state when device goes offline.
2321 * ha = adapter block pointer.
2322 * fcport = port structure pointer.
2330 qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
2334 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2335 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vp_idx)
2339 * No point in marking the device as lost, if the device is
2342 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2344 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2346 qla2x00_schedule_rport_del(vha, fcport, defer);
2347 else if (vha->vp_idx == fcport->vp_idx)
2348 qla2x00_schedule_rport_del(vha, fcport, defer);
2350 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2356 * Allocates adapter memory.
2363 qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2364 struct req_que **req, struct rsp_que **rsp)
2368 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
2369 &ha->init_cb_dma, GFP_KERNEL);
2373 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2374 &ha->gid_list_dma, GFP_KERNEL);
2376 goto fail_free_init_cb;
2378 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2379 if (!ha->srb_mempool)
2380 goto fail_free_gid_list;
2382 /* Get memory for cached NVRAM */
2383 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2385 goto fail_free_srb_mempool;
2387 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2389 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2390 DMA_POOL_SIZE, 8, 0);
2391 if (!ha->s_dma_pool)
2392 goto fail_free_nvram;
2394 /* Allocate memory for SNS commands */
2395 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2396 /* Get consistent memory allocated for SNS commands */
2397 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
2398 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
2402 /* Get consistent memory allocated for MS IOCB */
2403 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2407 /* Get consistent memory allocated for CT SNS commands */
2408 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
2409 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
2411 goto fail_free_ms_iocb;
2414 /* Allocate memory for request ring */
2415 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2417 DEBUG(printk("Unable to allocate memory for req\n"));
2420 (*req)->length = req_len;
2421 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2422 ((*req)->length + 1) * sizeof(request_t),
2423 &(*req)->dma, GFP_KERNEL);
2424 if (!(*req)->ring) {
2425 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2428 /* Allocate memory for response ring */
2429 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2431 qla_printk(KERN_WARNING, ha,
2432 "Unable to allocate memory for rsp\n");
2436 (*rsp)->length = rsp_len;
2437 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2438 ((*rsp)->length + 1) * sizeof(response_t),
2439 &(*rsp)->dma, GFP_KERNEL);
2440 if (!(*rsp)->ring) {
2441 qla_printk(KERN_WARNING, ha,
2442 "Unable to allocate memory for rsp_ring\n");
2447 /* Allocate memory for NVRAM data for vports */
2448 if (ha->nvram_npiv_size) {
2449 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
2450 ha->nvram_npiv_size, GFP_KERNEL);
2451 if (!ha->npiv_info) {
2452 qla_printk(KERN_WARNING, ha,
2453 "Unable to allocate memory for npiv info\n");
2454 goto fail_npiv_info;
2457 ha->npiv_info = NULL;
2459 /* Get consistent memory allocated for EX-INIT-CB. */
2460 if (IS_QLA81XX(ha)) {
2461 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2462 &ha->ex_init_cb_dma);
2463 if (!ha->ex_init_cb)
2464 goto fail_ex_init_cb;
2467 INIT_LIST_HEAD(&ha->vp_list);
2471 kfree(ha->npiv_info);
2473 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2474 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2475 (*rsp)->ring = NULL;
2480 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2481 sizeof(request_t), (*req)->ring, (*req)->dma);
2482 (*req)->ring = NULL;
2487 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2488 ha->ct_sns, ha->ct_sns_dma);
2492 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2494 ha->ms_iocb_dma = 0;
2496 dma_pool_destroy(ha->s_dma_pool);
2497 ha->s_dma_pool = NULL;
2501 fail_free_srb_mempool:
2502 mempool_destroy(ha->srb_mempool);
2503 ha->srb_mempool = NULL;
2505 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2507 ha->gid_list = NULL;
2508 ha->gid_list_dma = 0;
2510 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2513 ha->init_cb_dma = 0;
2515 DEBUG(printk("%s: Memory allocation failure\n", __func__));
2521 * Frees all adapter allocated memory.
2524 * ha = adapter block pointer.
2527 qla2x00_mem_free(struct qla_hw_data *ha)
2529 if (ha->srb_mempool)
2530 mempool_destroy(ha->srb_mempool);
2533 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
2538 dma_free_coherent(&ha->pdev->dev,
2539 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
2544 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
2545 ha->dcbx_tlv, ha->dcbx_tlv_dma);
2548 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
2549 ha->xgmac_data, ha->xgmac_data_dma);
2552 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
2553 ha->sns_cmd, ha->sns_cmd_dma);
2556 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2557 ha->ct_sns, ha->ct_sns_dma);
2560 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2563 dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
2566 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2569 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
2572 dma_pool_destroy(ha->s_dma_pool);
2575 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2579 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2580 ha->init_cb, ha->init_cb_dma);
2581 vfree(ha->optrom_buffer);
2583 kfree(ha->npiv_info);
2585 ha->srb_mempool = NULL;
2589 ha->sns_cmd_dma = 0;
2593 ha->ms_iocb_dma = 0;
2595 ha->init_cb_dma = 0;
2596 ha->ex_init_cb = NULL;
2597 ha->ex_init_cb_dma = 0;
2599 ha->s_dma_pool = NULL;
2601 ha->gid_list = NULL;
2602 ha->gid_list_dma = 0;
2606 ha->fw_dump_reading = 0;
2609 struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
2610 struct qla_hw_data *ha)
2612 struct Scsi_Host *host;
2613 struct scsi_qla_host *vha = NULL;
2615 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
2618 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2622 /* Clear our data area */
2623 vha = shost_priv(host);
2624 memset(vha, 0, sizeof(scsi_qla_host_t));
2627 vha->host_no = host->host_no;
2630 INIT_LIST_HEAD(&vha->vp_fcports);
2631 INIT_LIST_HEAD(&vha->work_list);
2632 INIT_LIST_HEAD(&vha->list);
2634 spin_lock_init(&vha->work_lock);
2636 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
2643 static struct qla_work_evt *
2644 qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
2646 struct qla_work_evt *e;
2648 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
2652 INIT_LIST_HEAD(&e->list);
2654 e->flags = QLA_EVT_FLAG_FREE;
2659 qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
2661 unsigned long flags;
2663 spin_lock_irqsave(&vha->work_lock, flags);
2664 list_add_tail(&e->list, &vha->work_list);
2665 spin_unlock_irqrestore(&vha->work_lock, flags);
2666 qla2xxx_wake_dpc(vha);
2672 qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
2675 struct qla_work_evt *e;
2677 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
2679 return QLA_FUNCTION_FAILED;
2681 e->u.aen.code = code;
2682 e->u.aen.data = data;
2683 return qla2x00_post_work(vha, e);
2687 qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
2689 struct qla_work_evt *e;
2691 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
2693 return QLA_FUNCTION_FAILED;
2695 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
2696 return qla2x00_post_work(vha, e);
2699 #define qla2x00_post_async_work(name, type) \
2700 int qla2x00_post_async_##name##_work( \
2701 struct scsi_qla_host *vha, \
2702 fc_port_t *fcport, uint16_t *data) \
2704 struct qla_work_evt *e; \
2706 e = qla2x00_alloc_work(vha, type); \
2708 return QLA_FUNCTION_FAILED; \
2710 e->u.logio.fcport = fcport; \
2712 e->u.logio.data[0] = data[0]; \
2713 e->u.logio.data[1] = data[1]; \
2715 return qla2x00_post_work(vha, e); \
2718 qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
2719 qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
2720 qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
2721 qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
2724 qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
2726 struct qla_work_evt *e;
2728 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
2730 return QLA_FUNCTION_FAILED;
2732 e->u.uevent.code = code;
2733 return qla2x00_post_work(vha, e);
2737 qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
2739 char event_string[40];
2740 char *envp[] = { event_string, NULL };
2743 case QLA_UEVENT_CODE_FW_DUMP:
2744 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
2751 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
2755 qla2x00_do_work(struct scsi_qla_host *vha)
2757 struct qla_work_evt *e, *tmp;
2758 unsigned long flags;
2761 spin_lock_irqsave(&vha->work_lock, flags);
2762 list_splice_init(&vha->work_list, &work);
2763 spin_unlock_irqrestore(&vha->work_lock, flags);
2765 list_for_each_entry_safe(e, tmp, &work, list) {
2766 list_del_init(&e->list);
2770 fc_host_post_event(vha->host, fc_get_event_number(),
2771 e->u.aen.code, e->u.aen.data);
2773 case QLA_EVT_IDC_ACK:
2774 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
2776 case QLA_EVT_ASYNC_LOGIN:
2777 qla2x00_async_login(vha, e->u.logio.fcport,
2780 case QLA_EVT_ASYNC_LOGIN_DONE:
2781 qla2x00_async_login_done(vha, e->u.logio.fcport,
2784 case QLA_EVT_ASYNC_LOGOUT:
2785 qla2x00_async_logout(vha, e->u.logio.fcport);
2787 case QLA_EVT_ASYNC_LOGOUT_DONE:
2788 qla2x00_async_logout_done(vha, e->u.logio.fcport,
2791 case QLA_EVT_UEVENT:
2792 qla2x00_uevent_emit(vha, e->u.uevent.code);
2795 if (e->flags & QLA_EVT_FLAG_FREE)
2800 /* Relogins all the fcports of a vport
2801 * Context: dpc thread
2803 void qla2x00_relogin(struct scsi_qla_host *vha)
2807 uint16_t next_loopid = 0;
2808 struct qla_hw_data *ha = vha->hw;
2811 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2813 * If the port is not ONLINE then try to login
2814 * to it if we haven't run out of retries.
2816 if (atomic_read(&fcport->state) !=
2817 FCS_ONLINE && fcport->login_retry) {
2819 fcport->login_retry--;
2820 if (fcport->flags & FCF_FABRIC_DEVICE) {
2821 if (fcport->flags & FCF_FCP2_DEVICE)
2822 ha->isp_ops->fabric_logout(vha,
2824 fcport->d_id.b.domain,
2825 fcport->d_id.b.area,
2826 fcport->d_id.b.al_pa);
2828 if (IS_ALOGIO_CAPABLE(ha)) {
2830 data[1] = QLA_LOGIO_LOGIN_RETRIED;
2831 status = qla2x00_post_async_login_work(
2833 if (status == QLA_SUCCESS)
2835 /* Attempt a retry. */
2838 status = qla2x00_fabric_login(vha,
2839 fcport, &next_loopid);
2841 status = qla2x00_local_device_login(vha,
2844 if (status == QLA_SUCCESS) {
2845 fcport->old_loop_id = fcport->loop_id;
2847 DEBUG(printk("scsi(%ld): port login OK: logged "
2848 "in ID 0x%x\n", vha->host_no, fcport->loop_id));
2850 qla2x00_update_fcport(vha, fcport);
2852 } else if (status == 1) {
2853 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2854 /* retry the login again */
2855 DEBUG(printk("scsi(%ld): Retrying"
2856 " %d login again loop_id 0x%x\n",
2857 vha->host_no, fcport->login_retry,
2860 fcport->login_retry = 0;
2863 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
2864 fcport->loop_id = FC_NO_LOOP_ID;
2866 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2871 /**************************************************************************
2873 * This kernel thread is a task that is schedule by the interrupt handler
2874 * to perform the background processing for interrupts.
2877 * This task always run in the context of a kernel thread. It
2878 * is kick-off by the driver's detect code and starts up
2879 * up one per adapter. It immediately goes to sleep and waits for
2880 * some fibre event. When either the interrupt handler or
2881 * the timer routine detects a event it will one of the task
2882 * bits then wake us up.
2883 **************************************************************************/
2885 qla2x00_do_dpc(void *data)
2888 scsi_qla_host_t *base_vha;
2889 struct qla_hw_data *ha;
2891 ha = (struct qla_hw_data *)data;
2892 base_vha = pci_get_drvdata(ha->pdev);
2894 set_user_nice(current, -20);
2896 while (!kthread_should_stop()) {
2897 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2899 set_current_state(TASK_INTERRUPTIBLE);
2901 __set_current_state(TASK_RUNNING);
2903 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2905 /* Initialization not yet finished. Don't do anything yet. */
2906 if (!base_vha->flags.init_done)
2909 if (ha->flags.eeh_busy) {
2910 DEBUG17(qla_printk(KERN_WARNING, ha,
2911 "qla2x00_do_dpc: dpc_flags: %lx\n",
2912 base_vha->dpc_flags));
2916 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
2920 if (ha->flags.mbox_busy) {
2925 qla2x00_do_work(base_vha);
2927 if (test_and_clear_bit(ISP_ABORT_NEEDED,
2928 &base_vha->dpc_flags)) {
2930 DEBUG(printk("scsi(%ld): dpc: sched "
2931 "qla2x00_abort_isp ha = %p\n",
2932 base_vha->host_no, ha));
2933 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2934 &base_vha->dpc_flags))) {
2936 if (qla2x00_abort_isp(base_vha)) {
2937 /* failed. retry later */
2938 set_bit(ISP_ABORT_NEEDED,
2939 &base_vha->dpc_flags);
2941 clear_bit(ABORT_ISP_ACTIVE,
2942 &base_vha->dpc_flags);
2945 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2946 base_vha->host_no));
2949 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
2950 qla2x00_update_fcports(base_vha);
2951 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2954 if (test_and_clear_bit(RESET_MARKER_NEEDED,
2955 &base_vha->dpc_flags) &&
2956 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
2958 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2959 base_vha->host_no));
2961 qla2x00_rst_aen(base_vha);
2962 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
2965 /* Retry each device up to login retry count */
2966 if ((test_and_clear_bit(RELOGIN_NEEDED,
2967 &base_vha->dpc_flags)) &&
2968 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
2969 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
2971 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2972 base_vha->host_no));
2973 qla2x00_relogin(base_vha);
2975 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2976 base_vha->host_no));
2979 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
2980 &base_vha->dpc_flags)) {
2982 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2983 base_vha->host_no));
2985 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2986 &base_vha->dpc_flags))) {
2988 rval = qla2x00_loop_resync(base_vha);
2990 clear_bit(LOOP_RESYNC_ACTIVE,
2991 &base_vha->dpc_flags);
2994 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2995 base_vha->host_no));
2998 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
2999 atomic_read(&base_vha->loop_state) == LOOP_READY) {
3000 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
3001 qla2xxx_flash_npiv_conf(base_vha);
3004 if (!ha->interrupts_on)
3005 ha->isp_ops->enable_intrs(ha);
3007 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
3008 &base_vha->dpc_flags))
3009 ha->isp_ops->beacon_blink(base_vha);
3011 qla2x00_do_dpc_all_vps(base_vha);
3014 } /* End of while(1) */
3016 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
3019 * Make sure that nobody tries to wake us up again.
3023 /* Cleanup any residual CTX SRBs. */
3024 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3030 qla2xxx_wake_dpc(struct scsi_qla_host *vha)
3032 struct qla_hw_data *ha = vha->hw;
3033 struct task_struct *t = ha->dpc_thread;
3035 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
3041 * Processes asynchronous reset.
3044 * ha = adapter block pointer.
3047 qla2x00_rst_aen(scsi_qla_host_t *vha)
3049 if (vha->flags.online && !vha->flags.reset_active &&
3050 !atomic_read(&vha->loop_down_timer) &&
3051 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
3053 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
3056 * Issue marker command only when we are going to start
3059 vha->marker_needed = 1;
3060 } while (!atomic_read(&vha->loop_down_timer) &&
3061 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
3066 qla2x00_sp_free_dma(srb_t *sp)
3068 struct scsi_cmnd *cmd = sp->cmd;
3070 if (sp->flags & SRB_DMA_VALID) {
3071 scsi_dma_unmap(cmd);
3072 sp->flags &= ~SRB_DMA_VALID;
3078 qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
3080 struct scsi_cmnd *cmd = sp->cmd;
3082 qla2x00_sp_free_dma(sp);
3084 mempool_free(sp, ha->srb_mempool);
3086 cmd->scsi_done(cmd);
3089 /**************************************************************************
3095 * Context: Interrupt
3096 ***************************************************************************/
3098 qla2x00_timer(scsi_qla_host_t *vha)
3100 unsigned long cpu_flags = 0;
3107 struct qla_hw_data *ha = vha->hw;
3108 struct req_que *req;
3110 /* Hardware read to raise pending EEH errors during mailbox waits. */
3111 if (!pci_channel_offline(ha->pdev))
3112 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
3114 * Ports - Port down timer.
3116 * Whenever, a port is in the LOST state we start decrementing its port
3117 * down timer every second until it reaches zero. Once it reaches zero
3118 * the port it marked DEAD.
3121 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3122 if (fcport->port_type != FCT_TARGET)
3125 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
3127 if (atomic_read(&fcport->port_down_timer) == 0)
3130 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
3131 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
3133 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
3136 t, atomic_read(&fcport->port_down_timer)));
3139 } /* End of for fcport */
3142 /* Loop down handler. */
3143 if (atomic_read(&vha->loop_down_timer) > 0 &&
3144 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
3145 && vha->flags.online) {
3147 if (atomic_read(&vha->loop_down_timer) ==
3148 vha->loop_down_abort_time) {
3150 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
3151 "queues before time expire\n",
3154 if (!IS_QLA2100(ha) && vha->link_down_timeout)
3155 atomic_set(&vha->loop_state, LOOP_DEAD);
3158 * Schedule an ISP abort to return any FCP2-device
3161 /* NPIV - scan physical port only */
3163 spin_lock_irqsave(&ha->hardware_lock,
3165 req = ha->req_q_map[0];
3167 index < MAX_OUTSTANDING_COMMANDS;
3171 sp = req->outstanding_cmds[index];
3177 if (!(sfcp->flags & FCF_FCP2_DEVICE))
3180 set_bit(ISP_ABORT_NEEDED,
3184 spin_unlock_irqrestore(&ha->hardware_lock,
3190 /* if the loop has been down for 4 minutes, reinit adapter */
3191 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
3192 if (!(vha->device_flags & DFLG_NO_CABLE)) {
3193 DEBUG(printk("scsi(%ld): Loop down - "
3196 qla_printk(KERN_WARNING, ha,
3197 "Loop down - aborting ISP.\n");
3199 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3202 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
3204 atomic_read(&vha->loop_down_timer)));
3207 /* Check if beacon LED needs to be blinked */
3208 if (ha->beacon_blink_led == 1) {
3209 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
3213 /* Process any deferred work. */
3214 if (!list_empty(&vha->work_list))
3217 /* Schedule the DPC routine if needed */
3218 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
3219 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
3220 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
3222 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
3223 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
3224 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
3225 test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
3226 qla2xxx_wake_dpc(vha);
3228 qla2x00_restart_timer(vha, WATCH_INTERVAL);
3231 /* Firmware interface routines. */
3234 #define FW_ISP21XX 0
3235 #define FW_ISP22XX 1
3236 #define FW_ISP2300 2
3237 #define FW_ISP2322 3
3238 #define FW_ISP24XX 4
3239 #define FW_ISP25XX 5
3240 #define FW_ISP81XX 6
3242 #define FW_FILE_ISP21XX "ql2100_fw.bin"
3243 #define FW_FILE_ISP22XX "ql2200_fw.bin"
3244 #define FW_FILE_ISP2300 "ql2300_fw.bin"
3245 #define FW_FILE_ISP2322 "ql2322_fw.bin"
3246 #define FW_FILE_ISP24XX "ql2400_fw.bin"
3247 #define FW_FILE_ISP25XX "ql2500_fw.bin"
3248 #define FW_FILE_ISP81XX "ql8100_fw.bin"
3250 static DEFINE_MUTEX(qla_fw_lock);
3252 static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
3253 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
3254 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
3255 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
3256 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
3257 { .name = FW_FILE_ISP24XX, },
3258 { .name = FW_FILE_ISP25XX, },
3259 { .name = FW_FILE_ISP81XX, },
3263 qla2x00_request_firmware(scsi_qla_host_t *vha)
3265 struct qla_hw_data *ha = vha->hw;
3266 struct fw_blob *blob;
3269 if (IS_QLA2100(ha)) {
3270 blob = &qla_fw_blobs[FW_ISP21XX];
3271 } else if (IS_QLA2200(ha)) {
3272 blob = &qla_fw_blobs[FW_ISP22XX];
3273 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3274 blob = &qla_fw_blobs[FW_ISP2300];
3275 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
3276 blob = &qla_fw_blobs[FW_ISP2322];
3277 } else if (IS_QLA24XX_TYPE(ha)) {
3278 blob = &qla_fw_blobs[FW_ISP24XX];
3279 } else if (IS_QLA25XX(ha)) {
3280 blob = &qla_fw_blobs[FW_ISP25XX];
3281 } else if (IS_QLA81XX(ha)) {
3282 blob = &qla_fw_blobs[FW_ISP81XX];
3285 mutex_lock(&qla_fw_lock);
3289 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
3290 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
3291 "(%s).\n", vha->host_no, blob->name));
3298 mutex_unlock(&qla_fw_lock);
3303 qla2x00_release_firmware(void)
3307 mutex_lock(&qla_fw_lock);
3308 for (idx = 0; idx < FW_BLOBS; idx++)
3309 if (qla_fw_blobs[idx].fw)
3310 release_firmware(qla_fw_blobs[idx].fw);
3311 mutex_unlock(&qla_fw_lock);
3314 static pci_ers_result_t
3315 qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3317 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
3318 struct qla_hw_data *ha = vha->hw;
3320 DEBUG2(qla_printk(KERN_WARNING, ha, "error_detected:state %x\n",
3324 case pci_channel_io_normal:
3325 ha->flags.eeh_busy = 0;
3326 return PCI_ERS_RESULT_CAN_RECOVER;
3327 case pci_channel_io_frozen:
3328 ha->flags.eeh_busy = 1;
3329 qla2x00_free_irqs(vha);
3330 pci_disable_device(pdev);
3331 return PCI_ERS_RESULT_NEED_RESET;
3332 case pci_channel_io_perm_failure:
3333 ha->flags.pci_channel_io_perm_failure = 1;
3334 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3335 return PCI_ERS_RESULT_DISCONNECT;
3337 return PCI_ERS_RESULT_NEED_RESET;
3340 static pci_ers_result_t
3341 qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
3343 int risc_paused = 0;
3345 unsigned long flags;
3346 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3347 struct qla_hw_data *ha = base_vha->hw;
3348 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3349 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
3351 spin_lock_irqsave(&ha->hardware_lock, flags);
3352 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
3353 stat = RD_REG_DWORD(®->hccr);
3354 if (stat & HCCR_RISC_PAUSE)
3356 } else if (IS_QLA23XX(ha)) {
3357 stat = RD_REG_DWORD(®->u.isp2300.host_status);
3358 if (stat & HSR_RISC_PAUSED)
3360 } else if (IS_FWI2_CAPABLE(ha)) {
3361 stat = RD_REG_DWORD(®24->host_status);
3362 if (stat & HSRX_RISC_PAUSED)
3365 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3368 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
3369 "Dumping firmware!\n");
3370 ha->isp_ops->fw_dump(base_vha, 0);
3372 return PCI_ERS_RESULT_NEED_RESET;
3374 return PCI_ERS_RESULT_RECOVERED;
3377 static pci_ers_result_t
3378 qla2xxx_pci_slot_reset(struct pci_dev *pdev)
3380 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
3381 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3382 struct qla_hw_data *ha = base_vha->hw;
3383 struct rsp_que *rsp;
3384 int rc, retries = 10;
3386 DEBUG17(qla_printk(KERN_WARNING, ha, "slot_reset\n"));
3388 /* Workaround: qla2xxx driver which access hardware earlier
3389 * needs error state to be pci_channel_io_online.
3390 * Otherwise mailbox command timesout.
3392 pdev->error_state = pci_channel_io_normal;
3394 pci_restore_state(pdev);
3397 rc = pci_enable_device_mem(pdev);
3399 rc = pci_enable_device(pdev);
3402 qla_printk(KERN_WARNING, ha,
3403 "Can't re-enable PCI device after reset.\n");
3407 rsp = ha->rsp_q_map[0];
3408 if (qla2x00_request_irqs(ha, rsp))
3411 if (ha->isp_ops->pci_config(base_vha))
3414 while (ha->flags.mbox_busy && retries--)
3417 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3418 if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
3419 ret = PCI_ERS_RESULT_RECOVERED;
3420 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3422 pci_cleanup_aer_uncorrect_error_status(pdev);
3424 DEBUG17(qla_printk(KERN_WARNING, ha,
3425 "slot_reset-return:ret=%x\n", ret));
3431 qla2xxx_pci_resume(struct pci_dev *pdev)
3433 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3434 struct qla_hw_data *ha = base_vha->hw;
3437 DEBUG17(qla_printk(KERN_WARNING, ha, "pci_resume\n"));
3439 ret = qla2x00_wait_for_hba_online(base_vha);
3440 if (ret != QLA_SUCCESS) {
3441 qla_printk(KERN_ERR, ha,
3442 "the device failed to resume I/O "
3443 "from slot/link_reset");
3446 ha->flags.eeh_busy = 0;
3449 static struct pci_error_handlers qla2xxx_err_handler = {
3450 .error_detected = qla2xxx_pci_error_detected,
3451 .mmio_enabled = qla2xxx_pci_mmio_enabled,
3452 .slot_reset = qla2xxx_pci_slot_reset,
3453 .resume = qla2xxx_pci_resume,
3456 static struct pci_device_id qla2xxx_pci_tbl[] = {
3457 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
3458 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
3459 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
3460 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
3461 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
3462 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
3463 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
3464 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
3465 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
3466 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
3467 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
3468 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
3469 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
3470 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
3473 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
3475 static struct pci_driver qla2xxx_pci_driver = {
3476 .name = QLA2XXX_DRIVER_NAME,
3478 .owner = THIS_MODULE,
3480 .id_table = qla2xxx_pci_tbl,
3481 .probe = qla2x00_probe_one,
3482 .remove = qla2x00_remove_one,
3483 .err_handler = &qla2xxx_err_handler,
3487 * qla2x00_module_init - Module initialization.
3490 qla2x00_module_init(void)
3494 /* Allocate cache for SRBs. */
3495 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
3496 SLAB_HWCACHE_ALIGN, NULL);
3497 if (srb_cachep == NULL) {
3499 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3503 /* Derive version string. */
3504 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
3505 if (ql2xextended_error_logging)
3506 strcat(qla2x00_version_str, "-debug");
3508 qla2xxx_transport_template =
3509 fc_attach_transport(&qla2xxx_transport_functions);
3510 if (!qla2xxx_transport_template) {
3511 kmem_cache_destroy(srb_cachep);
3514 qla2xxx_transport_vport_template =
3515 fc_attach_transport(&qla2xxx_transport_vport_functions);
3516 if (!qla2xxx_transport_vport_template) {
3517 kmem_cache_destroy(srb_cachep);
3518 fc_release_transport(qla2xxx_transport_template);
3522 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
3523 qla2x00_version_str);
3524 ret = pci_register_driver(&qla2xxx_pci_driver);
3526 kmem_cache_destroy(srb_cachep);
3527 fc_release_transport(qla2xxx_transport_template);
3528 fc_release_transport(qla2xxx_transport_vport_template);
3534 * qla2x00_module_exit - Module cleanup.
3537 qla2x00_module_exit(void)
3539 pci_unregister_driver(&qla2xxx_pci_driver);
3540 qla2x00_release_firmware();
3541 kmem_cache_destroy(srb_cachep);
3542 fc_release_transport(qla2xxx_transport_template);
3543 fc_release_transport(qla2xxx_transport_vport_template);
3546 module_init(qla2x00_module_init);
3547 module_exit(qla2x00_module_exit);
3549 MODULE_AUTHOR("QLogic Corporation");
3550 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3551 MODULE_LICENSE("GPL");
3552 MODULE_VERSION(QLA2XXX_VERSION);
3553 MODULE_FIRMWARE(FW_FILE_ISP21XX);
3554 MODULE_FIRMWARE(FW_FILE_ISP22XX);
3555 MODULE_FIRMWARE(FW_FILE_ISP2300);
3556 MODULE_FIRMWARE(FW_FILE_ISP2322);
3557 MODULE_FIRMWARE(FW_FILE_ISP24XX);
3558 MODULE_FIRMWARE(FW_FILE_ISP25XX);