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 module_param(ql2xetsenable, int, S_IRUGO|S_IRUSR);
112 MODULE_PARM_DESC(ql2xetsenable,
113 "Enables firmware ETS burst."
114 "Default is 0 - skip ETS enablement.");
117 * SCSI host template entry points
119 static int qla2xxx_slave_configure(struct scsi_device * device);
120 static int qla2xxx_slave_alloc(struct scsi_device *);
121 static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
122 static void qla2xxx_scan_start(struct Scsi_Host *);
123 static void qla2xxx_slave_destroy(struct scsi_device *);
124 static int qla2xxx_queuecommand(struct scsi_cmnd *cmd,
125 void (*fn)(struct scsi_cmnd *));
126 static int qla2xxx_eh_abort(struct scsi_cmnd *);
127 static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
128 static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
129 static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
130 static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
132 static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
133 static int qla2x00_change_queue_type(struct scsi_device *, int);
135 struct scsi_host_template qla2xxx_driver_template = {
136 .module = THIS_MODULE,
137 .name = QLA2XXX_DRIVER_NAME,
138 .queuecommand = qla2xxx_queuecommand,
140 .eh_abort_handler = qla2xxx_eh_abort,
141 .eh_device_reset_handler = qla2xxx_eh_device_reset,
142 .eh_target_reset_handler = qla2xxx_eh_target_reset,
143 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
144 .eh_host_reset_handler = qla2xxx_eh_host_reset,
146 .slave_configure = qla2xxx_slave_configure,
148 .slave_alloc = qla2xxx_slave_alloc,
149 .slave_destroy = qla2xxx_slave_destroy,
150 .scan_finished = qla2xxx_scan_finished,
151 .scan_start = qla2xxx_scan_start,
152 .change_queue_depth = qla2x00_change_queue_depth,
153 .change_queue_type = qla2x00_change_queue_type,
156 .use_clustering = ENABLE_CLUSTERING,
157 .sg_tablesize = SG_ALL,
159 .max_sectors = 0xFFFF,
160 .shost_attrs = qla2x00_host_attrs,
163 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
164 struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
166 /* TODO Convert to inlines
172 qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
174 init_timer(&vha->timer);
175 vha->timer.expires = jiffies + interval * HZ;
176 vha->timer.data = (unsigned long)vha;
177 vha->timer.function = (void (*)(unsigned long))func;
178 add_timer(&vha->timer);
179 vha->timer_active = 1;
183 qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
185 mod_timer(&vha->timer, jiffies + interval * HZ);
188 static __inline__ void
189 qla2x00_stop_timer(scsi_qla_host_t *vha)
191 del_timer_sync(&vha->timer);
192 vha->timer_active = 0;
195 static int qla2x00_do_dpc(void *data);
197 static void qla2x00_rst_aen(scsi_qla_host_t *);
199 static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
200 struct req_que **, struct rsp_que **);
201 static void qla2x00_mem_free(struct qla_hw_data *);
202 static void qla2x00_sp_free_dma(srb_t *);
204 /* -------------------------------------------------------------------------- */
205 static int qla2x00_alloc_queues(struct qla_hw_data *ha)
207 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
209 if (!ha->req_q_map) {
210 qla_printk(KERN_WARNING, ha,
211 "Unable to allocate memory for request queue ptrs\n");
215 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
217 if (!ha->rsp_q_map) {
218 qla_printk(KERN_WARNING, ha,
219 "Unable to allocate memory for response queue ptrs\n");
222 set_bit(0, ha->rsp_qid_map);
223 set_bit(0, ha->req_qid_map);
227 kfree(ha->req_q_map);
228 ha->req_q_map = NULL;
233 static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
235 if (req && req->ring)
236 dma_free_coherent(&ha->pdev->dev,
237 (req->length + 1) * sizeof(request_t),
238 req->ring, req->dma);
244 static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
246 if (rsp && rsp->ring)
247 dma_free_coherent(&ha->pdev->dev,
248 (rsp->length + 1) * sizeof(response_t),
249 rsp->ring, rsp->dma);
255 static void qla2x00_free_queues(struct qla_hw_data *ha)
261 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
262 req = ha->req_q_map[cnt];
263 qla2x00_free_req_que(ha, req);
265 kfree(ha->req_q_map);
266 ha->req_q_map = NULL;
268 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
269 rsp = ha->rsp_q_map[cnt];
270 qla2x00_free_rsp_que(ha, rsp);
272 kfree(ha->rsp_q_map);
273 ha->rsp_q_map = NULL;
276 static int qla25xx_setup_mode(struct scsi_qla_host *vha)
278 uint16_t options = 0;
280 struct qla_hw_data *ha = vha->hw;
282 if (!(ha->fw_attributes & BIT_6)) {
283 qla_printk(KERN_INFO, ha,
284 "Firmware is not multi-queue capable\n");
287 if (ql2xmultique_tag) {
288 /* create a request queue for IO */
290 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
291 QLA_DEFAULT_QUE_QOS);
293 qla_printk(KERN_WARNING, ha,
294 "Can't create request queue\n");
297 ha->wq = create_workqueue("qla2xxx_wq");
298 vha->req = ha->req_q_map[req];
300 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
301 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
303 qla_printk(KERN_WARNING, ha,
304 "Response Queue create failed\n");
308 ha->flags.cpu_affinity_enabled = 1;
310 DEBUG2(qla_printk(KERN_INFO, ha,
311 "CPU affinity mode enabled, no. of response"
312 " queues:%d, no. of request queues:%d\n",
313 ha->max_rsp_queues, ha->max_req_queues));
317 qla25xx_delete_queues(vha);
318 destroy_workqueue(ha->wq);
322 kfree(ha->req_q_map);
323 kfree(ha->rsp_q_map);
324 ha->max_req_queues = ha->max_rsp_queues = 1;
329 qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
331 struct qla_hw_data *ha = vha->hw;
332 static char *pci_bus_modes[] = {
333 "33", "66", "100", "133",
338 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
341 strcat(str, pci_bus_modes[pci_bus]);
343 pci_bus = (ha->pci_attr & BIT_8) >> 8;
345 strcat(str, pci_bus_modes[pci_bus]);
347 strcat(str, " MHz)");
353 qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
355 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
356 struct qla_hw_data *ha = vha->hw;
360 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
363 uint16_t pcie_lstat, lspeed, lwidth;
366 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
367 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
368 lwidth = (pcie_lstat &
369 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
371 strcpy(str, "PCIe (");
373 strcat(str, "2.5GT/s ");
374 else if (lspeed == 2)
375 strcat(str, "5.0GT/s ");
377 strcat(str, "<unknown> ");
378 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
385 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
386 if (pci_bus == 0 || pci_bus == 8) {
388 strcat(str, pci_bus_modes[pci_bus >> 3]);
392 strcat(str, "Mode 2");
394 strcat(str, "Mode 1");
396 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
398 strcat(str, " MHz)");
404 qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
407 struct qla_hw_data *ha = vha->hw;
409 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
410 ha->fw_minor_version,
411 ha->fw_subminor_version);
413 if (ha->fw_attributes & BIT_9) {
418 switch (ha->fw_attributes & 0xFF) {
432 sprintf(un_str, "(%x)", ha->fw_attributes);
436 if (ha->fw_attributes & 0x100)
443 qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
445 struct qla_hw_data *ha = vha->hw;
447 sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
448 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
452 static inline srb_t *
453 qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
454 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
457 struct qla_hw_data *ha = vha->hw;
459 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
466 CMD_SP(cmd) = (void *)sp;
467 cmd->scsi_done = done;
474 qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
476 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
477 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
478 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
479 struct qla_hw_data *ha = vha->hw;
480 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
484 if (ha->flags.eeh_busy) {
485 if (ha->flags.pci_channel_io_perm_failure)
486 cmd->result = DID_NO_CONNECT << 16;
488 cmd->result = DID_REQUEUE << 16;
489 goto qc24_fail_command;
492 rval = fc_remote_port_chkready(rport);
495 goto qc24_fail_command;
498 /* Close window on fcport/rport state-transitioning. */
500 goto qc24_target_busy;
502 if (atomic_read(&fcport->state) != FCS_ONLINE) {
503 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
504 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
505 cmd->result = DID_NO_CONNECT << 16;
506 goto qc24_fail_command;
508 goto qc24_target_busy;
511 spin_unlock_irq(vha->host->host_lock);
513 sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
515 goto qc24_host_busy_lock;
517 rval = ha->isp_ops->start_scsi(sp);
518 if (rval != QLA_SUCCESS)
519 goto qc24_host_busy_free_sp;
521 spin_lock_irq(vha->host->host_lock);
525 qc24_host_busy_free_sp:
526 qla2x00_sp_free_dma(sp);
527 mempool_free(sp, ha->srb_mempool);
530 spin_lock_irq(vha->host->host_lock);
531 return SCSI_MLQUEUE_HOST_BUSY;
534 return SCSI_MLQUEUE_TARGET_BUSY;
544 * qla2x00_eh_wait_on_command
545 * Waits for the command to be returned by the Firmware for some
549 * cmd = Scsi Command to wait on.
556 qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
558 #define ABORT_POLLING_PERIOD 1000
559 #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
560 unsigned long wait_iter = ABORT_WAIT_ITER;
561 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
562 struct qla_hw_data *ha = vha->hw;
563 int ret = QLA_SUCCESS;
565 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
566 DEBUG17(qla_printk(KERN_WARNING, ha, "return:eh_wait\n"));
570 while (CMD_SP(cmd) && wait_iter--) {
571 msleep(ABORT_POLLING_PERIOD);
574 ret = QLA_FUNCTION_FAILED;
580 * qla2x00_wait_for_hba_online
581 * Wait till the HBA is online after going through
582 * <= MAX_RETRIES_OF_ISP_ABORT or
583 * finally HBA is disabled ie marked offline
586 * ha - pointer to host adapter structure
589 * Does context switching-Release SPIN_LOCK
590 * (if any) before calling this routine.
593 * Success (Adapter is online) : 0
594 * Failed (Adapter is offline/disabled) : 1
597 qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
600 unsigned long wait_online;
601 struct qla_hw_data *ha = vha->hw;
602 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
604 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
605 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
606 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
607 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
608 ha->dpc_active) && time_before(jiffies, wait_online)) {
612 if (base_vha->flags.online)
613 return_status = QLA_SUCCESS;
615 return_status = QLA_FUNCTION_FAILED;
617 return (return_status);
621 qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
624 unsigned long wait_reset;
625 struct qla_hw_data *ha = vha->hw;
626 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
628 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
629 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
630 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
631 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
632 ha->dpc_active) && time_before(jiffies, wait_reset)) {
636 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
637 ha->flags.chip_reset_done)
640 if (ha->flags.chip_reset_done)
641 return_status = QLA_SUCCESS;
643 return_status = QLA_FUNCTION_FAILED;
645 return return_status;
649 * qla2x00_wait_for_loop_ready
650 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
651 * to be in LOOP_READY state.
653 * ha - pointer to host adapter structure
656 * Does context switching-Release SPIN_LOCK
657 * (if any) before calling this routine.
661 * Success (LOOP_READY) : 0
662 * Failed (LOOP_NOT_READY) : 1
665 qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
667 int return_status = QLA_SUCCESS;
668 unsigned long loop_timeout ;
669 struct qla_hw_data *ha = vha->hw;
670 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
672 /* wait for 5 min at the max for loop to be ready */
673 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
675 while ((!atomic_read(&base_vha->loop_down_timer) &&
676 atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
677 atomic_read(&base_vha->loop_state) != LOOP_READY) {
678 if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
679 return_status = QLA_FUNCTION_FAILED;
683 if (time_after_eq(jiffies, loop_timeout)) {
684 return_status = QLA_FUNCTION_FAILED;
688 return (return_status);
691 /**************************************************************************
695 * The abort function will abort the specified command.
698 * cmd = Linux SCSI command packet to be aborted.
701 * Either SUCCESS or FAILED.
704 * Only return FAILED if command not returned by firmware.
705 **************************************************************************/
707 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
709 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
712 unsigned int id, lun;
713 unsigned long serial;
716 struct qla_hw_data *ha = vha->hw;
717 struct req_que *req = vha->req;
720 fc_block_scsi_eh(cmd);
727 id = cmd->device->id;
728 lun = cmd->device->lun;
729 serial = cmd->serial_number;
730 spt = (srb_t *) CMD_SP(cmd);
734 /* Check active list for command command. */
735 spin_lock_irqsave(&ha->hardware_lock, flags);
736 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
737 sp = req->outstanding_cmds[i];
746 DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
747 " pid=%ld.\n", __func__, vha->host_no, sp, serial));
749 spin_unlock_irqrestore(&ha->hardware_lock, flags);
750 if (ha->isp_ops->abort_command(sp)) {
751 DEBUG2(printk("%s(%ld): abort_command "
752 "mbx failed.\n", __func__, vha->host_no));
755 DEBUG3(printk("%s(%ld): abort_command "
756 "mbx success.\n", __func__, vha->host_no));
759 spin_lock_irqsave(&ha->hardware_lock, flags);
762 spin_unlock_irqrestore(&ha->hardware_lock, flags);
764 /* Wait for the command to be returned. */
766 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
767 qla_printk(KERN_ERR, ha,
768 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
769 "%x.\n", vha->host_no, id, lun, serial, ret);
774 qla_printk(KERN_INFO, ha,
775 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
776 vha->host_no, id, lun, wait, serial, ret);
781 enum nexus_wait_type {
788 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
789 unsigned int l, srb_t *sp, enum nexus_wait_type type)
791 int cnt, match, status;
793 struct qla_hw_data *ha = vha->hw;
796 status = QLA_SUCCESS;
800 spin_lock_irqsave(&ha->hardware_lock, flags);
802 for (cnt = 1; status == QLA_SUCCESS &&
803 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
804 sp = req->outstanding_cmds[cnt];
809 if (vha->vp_idx != sp->fcport->vha->vp_idx)
817 match = sp->cmd->device->id == t;
820 match = (sp->cmd->device->id == t &&
821 sp->cmd->device->lun == l);
827 spin_unlock_irqrestore(&ha->hardware_lock, flags);
828 status = qla2x00_eh_wait_on_command(sp->cmd);
829 spin_lock_irqsave(&ha->hardware_lock, flags);
831 spin_unlock_irqrestore(&ha->hardware_lock, flags);
836 static char *reset_errors[] = {
839 "Task management failed",
840 "Waiting for command completions",
844 __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
845 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
847 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
848 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
851 fc_block_scsi_eh(cmd);
856 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
857 vha->host_no, cmd->device->id, cmd->device->lun, name);
860 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
861 goto eh_reset_failed;
863 if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
864 goto eh_reset_failed;
866 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
868 goto eh_reset_failed;
870 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
871 cmd->device->lun, (srb_t *) CMD_SP(cmd), type) != QLA_SUCCESS)
872 goto eh_reset_failed;
874 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
875 vha->host_no, cmd->device->id, cmd->device->lun, name);
880 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
881 , vha->host_no, cmd->device->id, cmd->device->lun, name,
887 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
889 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
890 struct qla_hw_data *ha = vha->hw;
892 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
893 ha->isp_ops->lun_reset);
897 qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
899 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
900 struct qla_hw_data *ha = vha->hw;
902 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
903 ha->isp_ops->target_reset);
906 /**************************************************************************
907 * qla2xxx_eh_bus_reset
910 * The bus reset function will reset the bus and abort any executing
914 * cmd = Linux SCSI command packet of the command that cause the
918 * SUCCESS/FAILURE (defined as macro in scsi.h).
920 **************************************************************************/
922 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
924 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
925 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
927 unsigned int id, lun;
928 unsigned long serial;
929 srb_t *sp = (srb_t *) CMD_SP(cmd);
931 fc_block_scsi_eh(cmd);
933 id = cmd->device->id;
934 lun = cmd->device->lun;
935 serial = cmd->serial_number;
940 qla_printk(KERN_INFO, vha->hw,
941 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
943 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
944 DEBUG2(printk("%s failed:board disabled\n",__func__));
945 goto eh_bus_reset_done;
948 if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
949 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
953 goto eh_bus_reset_done;
955 /* Flush outstanding commands. */
956 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) !=
961 qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
962 (ret == FAILED) ? "failed" : "succeded");
967 /**************************************************************************
968 * qla2xxx_eh_host_reset
971 * The reset function will reset the Adapter.
974 * cmd = Linux SCSI command packet of the command that cause the
978 * Either SUCCESS or FAILED.
981 **************************************************************************/
983 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
985 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
986 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
987 struct qla_hw_data *ha = vha->hw;
989 unsigned int id, lun;
990 unsigned long serial;
991 srb_t *sp = (srb_t *) CMD_SP(cmd);
992 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
994 fc_block_scsi_eh(cmd);
996 id = cmd->device->id;
997 lun = cmd->device->lun;
998 serial = cmd->serial_number;
1003 qla_printk(KERN_INFO, ha,
1004 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
1006 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1007 goto eh_host_reset_lock;
1010 * Fixme-may be dpc thread is active and processing
1011 * loop_resync,so wait a while for it to
1012 * be completed and then issue big hammer.Otherwise
1013 * it may cause I/O failure as big hammer marks the
1014 * devices as lost kicking of the port_down_timer
1015 * while dpc is stuck for the mailbox to complete.
1017 qla2x00_wait_for_loop_ready(vha);
1018 if (vha != base_vha) {
1019 if (qla2x00_vp_abort_isp(vha))
1020 goto eh_host_reset_lock;
1023 flush_workqueue(ha->wq);
1025 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1026 if (qla2x00_abort_isp(base_vha)) {
1027 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1028 /* failed. schedule dpc to try */
1029 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1031 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1032 goto eh_host_reset_lock;
1034 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1037 /* Waiting for command to be returned to OS.*/
1038 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) ==
1043 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1044 (ret == FAILED) ? "failed" : "succeded");
1050 * qla2x00_loop_reset
1054 * ha = adapter block pointer.
1060 qla2x00_loop_reset(scsi_qla_host_t *vha)
1063 struct fc_port *fcport;
1064 struct qla_hw_data *ha = vha->hw;
1066 if (ha->flags.enable_target_reset) {
1067 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1068 if (fcport->port_type != FCT_TARGET)
1071 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1072 if (ret != QLA_SUCCESS) {
1073 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1074 "target_reset=%d d_id=%x.\n", __func__,
1075 vha->host_no, ret, fcport->d_id.b24));
1080 if (ha->flags.enable_lip_full_login && !IS_QLA81XX(ha)) {
1081 ret = qla2x00_full_login_lip(vha);
1082 if (ret != QLA_SUCCESS) {
1083 DEBUG2_3(printk("%s(%ld): failed: "
1084 "full_login_lip=%d.\n", __func__, vha->host_no,
1087 atomic_set(&vha->loop_state, LOOP_DOWN);
1088 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1089 qla2x00_mark_all_devices_lost(vha, 0);
1090 qla2x00_wait_for_loop_ready(vha);
1093 if (ha->flags.enable_lip_reset) {
1094 ret = qla2x00_lip_reset(vha);
1095 if (ret != QLA_SUCCESS) {
1096 DEBUG2_3(printk("%s(%ld): failed: "
1097 "lip_reset=%d.\n", __func__, vha->host_no, ret));
1099 qla2x00_wait_for_loop_ready(vha);
1102 /* Issue marker command only when we are going to start the I/O */
1103 vha->marker_needed = 1;
1109 qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1112 unsigned long flags;
1114 struct srb_ctx *ctx;
1115 struct qla_hw_data *ha = vha->hw;
1116 struct req_que *req;
1118 spin_lock_irqsave(&ha->hardware_lock, flags);
1119 for (que = 0; que < ha->max_req_queues; que++) {
1120 req = ha->req_q_map[que];
1123 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1124 sp = req->outstanding_cmds[cnt];
1126 req->outstanding_cmds[cnt] = NULL;
1128 sp->cmd->result = res;
1129 qla2x00_sp_compl(ha, sp);
1132 if (ctx->type == SRB_LOGIN_CMD || ctx->type == SRB_LOGOUT_CMD) {
1133 del_timer_sync(&ctx->timer);
1136 struct srb_bsg* sp_bsg = (struct srb_bsg*)sp->ctx;
1137 if (sp_bsg->bsg_job->request->msgcode == FC_BSG_HST_CT)
1139 sp_bsg->bsg_job->req->errors = 0;
1140 sp_bsg->bsg_job->reply->result = res;
1141 sp_bsg->bsg_job->job_done(sp_bsg->bsg_job);
1143 mempool_free(sp, ha->srb_mempool);
1149 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1153 qla2xxx_slave_alloc(struct scsi_device *sdev)
1155 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1157 if (!rport || fc_remote_port_chkready(rport))
1160 sdev->hostdata = *(fc_port_t **)rport->dd_data;
1166 qla2xxx_slave_configure(struct scsi_device *sdev)
1168 scsi_qla_host_t *vha = shost_priv(sdev->host);
1169 struct qla_hw_data *ha = vha->hw;
1170 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1171 struct req_que *req = vha->req;
1173 if (sdev->tagged_supported)
1174 scsi_activate_tcq(sdev, req->max_q_depth);
1176 scsi_deactivate_tcq(sdev, req->max_q_depth);
1178 rport->dev_loss_tmo = ha->port_down_retry_count;
1184 qla2xxx_slave_destroy(struct scsi_device *sdev)
1186 sdev->hostdata = NULL;
1189 static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
1191 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1193 if (!scsi_track_queue_full(sdev, qdepth))
1196 DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw,
1197 "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
1198 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
1199 sdev->queue_depth));
1202 static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
1204 fc_port_t *fcport = sdev->hostdata;
1205 struct scsi_qla_host *vha = fcport->vha;
1206 struct qla_hw_data *ha = vha->hw;
1207 struct req_que *req = NULL;
1213 if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
1216 if (sdev->ordered_tags)
1217 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
1219 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
1221 DEBUG2(qla_printk(KERN_INFO, ha,
1222 "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
1223 fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun,
1224 sdev->queue_depth));
1228 qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1231 case SCSI_QDEPTH_DEFAULT:
1232 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1234 case SCSI_QDEPTH_QFULL:
1235 qla2x00_handle_queue_full(sdev, qdepth);
1237 case SCSI_QDEPTH_RAMP_UP:
1238 qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
1244 return sdev->queue_depth;
1248 qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1250 if (sdev->tagged_supported) {
1251 scsi_set_tag_type(sdev, tag_type);
1253 scsi_activate_tcq(sdev, sdev->queue_depth);
1255 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1263 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1266 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1267 * supported addressing method.
1270 qla2x00_config_dma_addressing(struct qla_hw_data *ha)
1272 /* Assume a 32bit DMA mask. */
1273 ha->flags.enable_64bit_addressing = 0;
1275 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1276 /* Any upper-dword bits set? */
1277 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1278 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
1279 /* Ok, a 64bit DMA mask is applicable. */
1280 ha->flags.enable_64bit_addressing = 1;
1281 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1282 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
1287 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1288 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
1292 qla2x00_enable_intrs(struct qla_hw_data *ha)
1294 unsigned long flags = 0;
1295 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1297 spin_lock_irqsave(&ha->hardware_lock, flags);
1298 ha->interrupts_on = 1;
1299 /* enable risc and host interrupts */
1300 WRT_REG_WORD(®->ictrl, ICR_EN_INT | ICR_EN_RISC);
1301 RD_REG_WORD(®->ictrl);
1302 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1307 qla2x00_disable_intrs(struct qla_hw_data *ha)
1309 unsigned long flags = 0;
1310 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1312 spin_lock_irqsave(&ha->hardware_lock, flags);
1313 ha->interrupts_on = 0;
1314 /* disable risc and host interrupts */
1315 WRT_REG_WORD(®->ictrl, 0);
1316 RD_REG_WORD(®->ictrl);
1317 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1321 qla24xx_enable_intrs(struct qla_hw_data *ha)
1323 unsigned long flags = 0;
1324 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1326 spin_lock_irqsave(&ha->hardware_lock, flags);
1327 ha->interrupts_on = 1;
1328 WRT_REG_DWORD(®->ictrl, ICRX_EN_RISC_INT);
1329 RD_REG_DWORD(®->ictrl);
1330 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1334 qla24xx_disable_intrs(struct qla_hw_data *ha)
1336 unsigned long flags = 0;
1337 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1339 if (IS_NOPOLLING_TYPE(ha))
1341 spin_lock_irqsave(&ha->hardware_lock, flags);
1342 ha->interrupts_on = 0;
1343 WRT_REG_DWORD(®->ictrl, 0);
1344 RD_REG_DWORD(®->ictrl);
1345 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1348 static struct isp_operations qla2100_isp_ops = {
1349 .pci_config = qla2100_pci_config,
1350 .reset_chip = qla2x00_reset_chip,
1351 .chip_diag = qla2x00_chip_diag,
1352 .config_rings = qla2x00_config_rings,
1353 .reset_adapter = qla2x00_reset_adapter,
1354 .nvram_config = qla2x00_nvram_config,
1355 .update_fw_options = qla2x00_update_fw_options,
1356 .load_risc = qla2x00_load_risc,
1357 .pci_info_str = qla2x00_pci_info_str,
1358 .fw_version_str = qla2x00_fw_version_str,
1359 .intr_handler = qla2100_intr_handler,
1360 .enable_intrs = qla2x00_enable_intrs,
1361 .disable_intrs = qla2x00_disable_intrs,
1362 .abort_command = qla2x00_abort_command,
1363 .target_reset = qla2x00_abort_target,
1364 .lun_reset = qla2x00_lun_reset,
1365 .fabric_login = qla2x00_login_fabric,
1366 .fabric_logout = qla2x00_fabric_logout,
1367 .calc_req_entries = qla2x00_calc_iocbs_32,
1368 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1369 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1370 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1371 .read_nvram = qla2x00_read_nvram_data,
1372 .write_nvram = qla2x00_write_nvram_data,
1373 .fw_dump = qla2100_fw_dump,
1376 .beacon_blink = NULL,
1377 .read_optrom = qla2x00_read_optrom_data,
1378 .write_optrom = qla2x00_write_optrom_data,
1379 .get_flash_version = qla2x00_get_flash_version,
1380 .start_scsi = qla2x00_start_scsi,
1383 static struct isp_operations qla2300_isp_ops = {
1384 .pci_config = qla2300_pci_config,
1385 .reset_chip = qla2x00_reset_chip,
1386 .chip_diag = qla2x00_chip_diag,
1387 .config_rings = qla2x00_config_rings,
1388 .reset_adapter = qla2x00_reset_adapter,
1389 .nvram_config = qla2x00_nvram_config,
1390 .update_fw_options = qla2x00_update_fw_options,
1391 .load_risc = qla2x00_load_risc,
1392 .pci_info_str = qla2x00_pci_info_str,
1393 .fw_version_str = qla2x00_fw_version_str,
1394 .intr_handler = qla2300_intr_handler,
1395 .enable_intrs = qla2x00_enable_intrs,
1396 .disable_intrs = qla2x00_disable_intrs,
1397 .abort_command = qla2x00_abort_command,
1398 .target_reset = qla2x00_abort_target,
1399 .lun_reset = qla2x00_lun_reset,
1400 .fabric_login = qla2x00_login_fabric,
1401 .fabric_logout = qla2x00_fabric_logout,
1402 .calc_req_entries = qla2x00_calc_iocbs_32,
1403 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1404 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1405 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1406 .read_nvram = qla2x00_read_nvram_data,
1407 .write_nvram = qla2x00_write_nvram_data,
1408 .fw_dump = qla2300_fw_dump,
1409 .beacon_on = qla2x00_beacon_on,
1410 .beacon_off = qla2x00_beacon_off,
1411 .beacon_blink = qla2x00_beacon_blink,
1412 .read_optrom = qla2x00_read_optrom_data,
1413 .write_optrom = qla2x00_write_optrom_data,
1414 .get_flash_version = qla2x00_get_flash_version,
1415 .start_scsi = qla2x00_start_scsi,
1418 static struct isp_operations qla24xx_isp_ops = {
1419 .pci_config = qla24xx_pci_config,
1420 .reset_chip = qla24xx_reset_chip,
1421 .chip_diag = qla24xx_chip_diag,
1422 .config_rings = qla24xx_config_rings,
1423 .reset_adapter = qla24xx_reset_adapter,
1424 .nvram_config = qla24xx_nvram_config,
1425 .update_fw_options = qla24xx_update_fw_options,
1426 .load_risc = qla24xx_load_risc,
1427 .pci_info_str = qla24xx_pci_info_str,
1428 .fw_version_str = qla24xx_fw_version_str,
1429 .intr_handler = qla24xx_intr_handler,
1430 .enable_intrs = qla24xx_enable_intrs,
1431 .disable_intrs = qla24xx_disable_intrs,
1432 .abort_command = qla24xx_abort_command,
1433 .target_reset = qla24xx_abort_target,
1434 .lun_reset = qla24xx_lun_reset,
1435 .fabric_login = qla24xx_login_fabric,
1436 .fabric_logout = qla24xx_fabric_logout,
1437 .calc_req_entries = NULL,
1438 .build_iocbs = NULL,
1439 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1440 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1441 .read_nvram = qla24xx_read_nvram_data,
1442 .write_nvram = qla24xx_write_nvram_data,
1443 .fw_dump = qla24xx_fw_dump,
1444 .beacon_on = qla24xx_beacon_on,
1445 .beacon_off = qla24xx_beacon_off,
1446 .beacon_blink = qla24xx_beacon_blink,
1447 .read_optrom = qla24xx_read_optrom_data,
1448 .write_optrom = qla24xx_write_optrom_data,
1449 .get_flash_version = qla24xx_get_flash_version,
1450 .start_scsi = qla24xx_start_scsi,
1453 static struct isp_operations qla25xx_isp_ops = {
1454 .pci_config = qla25xx_pci_config,
1455 .reset_chip = qla24xx_reset_chip,
1456 .chip_diag = qla24xx_chip_diag,
1457 .config_rings = qla24xx_config_rings,
1458 .reset_adapter = qla24xx_reset_adapter,
1459 .nvram_config = qla24xx_nvram_config,
1460 .update_fw_options = qla24xx_update_fw_options,
1461 .load_risc = qla24xx_load_risc,
1462 .pci_info_str = qla24xx_pci_info_str,
1463 .fw_version_str = qla24xx_fw_version_str,
1464 .intr_handler = qla24xx_intr_handler,
1465 .enable_intrs = qla24xx_enable_intrs,
1466 .disable_intrs = qla24xx_disable_intrs,
1467 .abort_command = qla24xx_abort_command,
1468 .target_reset = qla24xx_abort_target,
1469 .lun_reset = qla24xx_lun_reset,
1470 .fabric_login = qla24xx_login_fabric,
1471 .fabric_logout = qla24xx_fabric_logout,
1472 .calc_req_entries = NULL,
1473 .build_iocbs = NULL,
1474 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1475 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1476 .read_nvram = qla25xx_read_nvram_data,
1477 .write_nvram = qla25xx_write_nvram_data,
1478 .fw_dump = qla25xx_fw_dump,
1479 .beacon_on = qla24xx_beacon_on,
1480 .beacon_off = qla24xx_beacon_off,
1481 .beacon_blink = qla24xx_beacon_blink,
1482 .read_optrom = qla25xx_read_optrom_data,
1483 .write_optrom = qla24xx_write_optrom_data,
1484 .get_flash_version = qla24xx_get_flash_version,
1485 .start_scsi = qla24xx_start_scsi,
1488 static struct isp_operations qla81xx_isp_ops = {
1489 .pci_config = qla25xx_pci_config,
1490 .reset_chip = qla24xx_reset_chip,
1491 .chip_diag = qla24xx_chip_diag,
1492 .config_rings = qla24xx_config_rings,
1493 .reset_adapter = qla24xx_reset_adapter,
1494 .nvram_config = qla81xx_nvram_config,
1495 .update_fw_options = qla81xx_update_fw_options,
1496 .load_risc = qla81xx_load_risc,
1497 .pci_info_str = qla24xx_pci_info_str,
1498 .fw_version_str = qla24xx_fw_version_str,
1499 .intr_handler = qla24xx_intr_handler,
1500 .enable_intrs = qla24xx_enable_intrs,
1501 .disable_intrs = qla24xx_disable_intrs,
1502 .abort_command = qla24xx_abort_command,
1503 .target_reset = qla24xx_abort_target,
1504 .lun_reset = qla24xx_lun_reset,
1505 .fabric_login = qla24xx_login_fabric,
1506 .fabric_logout = qla24xx_fabric_logout,
1507 .calc_req_entries = NULL,
1508 .build_iocbs = NULL,
1509 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1510 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1512 .write_nvram = NULL,
1513 .fw_dump = qla81xx_fw_dump,
1514 .beacon_on = qla24xx_beacon_on,
1515 .beacon_off = qla24xx_beacon_off,
1516 .beacon_blink = qla24xx_beacon_blink,
1517 .read_optrom = qla25xx_read_optrom_data,
1518 .write_optrom = qla24xx_write_optrom_data,
1519 .get_flash_version = qla24xx_get_flash_version,
1520 .start_scsi = qla24xx_start_scsi,
1524 qla2x00_set_isp_flags(struct qla_hw_data *ha)
1526 ha->device_type = DT_EXTENDED_IDS;
1527 switch (ha->pdev->device) {
1528 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1529 ha->device_type |= DT_ISP2100;
1530 ha->device_type &= ~DT_EXTENDED_IDS;
1531 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
1533 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1534 ha->device_type |= DT_ISP2200;
1535 ha->device_type &= ~DT_EXTENDED_IDS;
1536 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
1538 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1539 ha->device_type |= DT_ISP2300;
1540 ha->device_type |= DT_ZIO_SUPPORTED;
1541 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1543 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1544 ha->device_type |= DT_ISP2312;
1545 ha->device_type |= DT_ZIO_SUPPORTED;
1546 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1548 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1549 ha->device_type |= DT_ISP2322;
1550 ha->device_type |= DT_ZIO_SUPPORTED;
1551 if (ha->pdev->subsystem_vendor == 0x1028 &&
1552 ha->pdev->subsystem_device == 0x0170)
1553 ha->device_type |= DT_OEM_001;
1554 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1556 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1557 ha->device_type |= DT_ISP6312;
1558 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1560 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1561 ha->device_type |= DT_ISP6322;
1562 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1564 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1565 ha->device_type |= DT_ISP2422;
1566 ha->device_type |= DT_ZIO_SUPPORTED;
1567 ha->device_type |= DT_FWI2;
1568 ha->device_type |= DT_IIDMA;
1569 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1571 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1572 ha->device_type |= DT_ISP2432;
1573 ha->device_type |= DT_ZIO_SUPPORTED;
1574 ha->device_type |= DT_FWI2;
1575 ha->device_type |= DT_IIDMA;
1576 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1578 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1579 ha->device_type |= DT_ISP8432;
1580 ha->device_type |= DT_ZIO_SUPPORTED;
1581 ha->device_type |= DT_FWI2;
1582 ha->device_type |= DT_IIDMA;
1583 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1585 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1586 ha->device_type |= DT_ISP5422;
1587 ha->device_type |= DT_FWI2;
1588 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1590 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1591 ha->device_type |= DT_ISP5432;
1592 ha->device_type |= DT_FWI2;
1593 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1595 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1596 ha->device_type |= DT_ISP2532;
1597 ha->device_type |= DT_ZIO_SUPPORTED;
1598 ha->device_type |= DT_FWI2;
1599 ha->device_type |= DT_IIDMA;
1600 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1602 case PCI_DEVICE_ID_QLOGIC_ISP8001:
1603 ha->device_type |= DT_ISP8001;
1604 ha->device_type |= DT_ZIO_SUPPORTED;
1605 ha->device_type |= DT_FWI2;
1606 ha->device_type |= DT_IIDMA;
1607 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1611 /* Get adapter physical port no from interrupt pin register. */
1612 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
1613 if (ha->port_no & 1)
1614 ha->flags.port0 = 1;
1616 ha->flags.port0 = 0;
1620 qla2x00_iospace_config(struct qla_hw_data *ha)
1622 resource_size_t pio;
1626 if (pci_request_selected_regions(ha->pdev, ha->bars,
1627 QLA2XXX_DRIVER_NAME)) {
1628 qla_printk(KERN_WARNING, ha,
1629 "Failed to reserve PIO/MMIO regions (%s)\n",
1630 pci_name(ha->pdev));
1632 goto iospace_error_exit;
1634 if (!(ha->bars & 1))
1637 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1638 pio = pci_resource_start(ha->pdev, 0);
1639 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1640 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1641 qla_printk(KERN_WARNING, ha,
1642 "Invalid PCI I/O region size (%s)...\n",
1643 pci_name(ha->pdev));
1647 qla_printk(KERN_WARNING, ha,
1648 "region #0 not a PIO resource (%s)...\n",
1649 pci_name(ha->pdev));
1652 ha->pio_address = pio;
1655 /* Use MMIO operations for all accesses. */
1656 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1657 qla_printk(KERN_ERR, ha,
1658 "region #1 not an MMIO resource (%s), aborting\n",
1659 pci_name(ha->pdev));
1660 goto iospace_error_exit;
1662 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1663 qla_printk(KERN_ERR, ha,
1664 "Invalid PCI mem region size (%s), aborting\n",
1665 pci_name(ha->pdev));
1666 goto iospace_error_exit;
1669 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1671 qla_printk(KERN_ERR, ha,
1672 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1674 goto iospace_error_exit;
1677 /* Determine queue resources */
1678 ha->max_req_queues = ha->max_rsp_queues = 1;
1679 if ((ql2xmaxqueues <= 1 || ql2xmultique_tag < 1) &&
1680 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1682 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1683 pci_resource_len(ha->pdev, 3));
1685 /* Read MSIX vector size of the board */
1686 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1687 ha->msix_count = msix;
1688 /* Max queues are bounded by available msix vectors */
1689 /* queue 0 uses two msix vectors */
1690 if (ql2xmultique_tag) {
1691 cpus = num_online_cpus();
1692 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1693 (cpus + 1) : (ha->msix_count - 1);
1694 ha->max_req_queues = 2;
1695 } else if (ql2xmaxqueues > 1) {
1696 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1697 QLA_MQ_SIZE : ql2xmaxqueues;
1698 DEBUG2(qla_printk(KERN_INFO, ha, "QoS mode set, max no"
1699 " of request queues:%d\n", ha->max_req_queues));
1701 qla_printk(KERN_INFO, ha,
1702 "MSI-X vector count: %d\n", msix);
1704 qla_printk(KERN_INFO, ha, "BAR 3 not enabled\n");
1707 ha->msix_count = ha->max_rsp_queues + 1;
1715 qla2xxx_scan_start(struct Scsi_Host *shost)
1717 scsi_qla_host_t *vha = shost_priv(shost);
1719 if (vha->hw->flags.running_gold_fw)
1722 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1723 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1724 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1725 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
1729 qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1731 scsi_qla_host_t *vha = shost_priv(shost);
1735 if (time > vha->hw->loop_reset_delay * HZ)
1738 return atomic_read(&vha->loop_state) == LOOP_READY;
1742 * PCI driver interface
1744 static int __devinit
1745 qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1748 struct Scsi_Host *host;
1749 scsi_qla_host_t *base_vha = NULL;
1750 struct qla_hw_data *ha;
1753 struct scsi_host_template *sht;
1754 int bars, max_id, mem_only = 0;
1755 uint16_t req_length = 0, rsp_length = 0;
1756 struct req_que *req = NULL;
1757 struct rsp_que *rsp = NULL;
1759 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
1760 sht = &qla2xxx_driver_template;
1761 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1762 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
1763 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
1764 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1765 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
1766 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
1767 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001) {
1768 bars = pci_select_bars(pdev, IORESOURCE_MEM);
1773 if (pci_enable_device_mem(pdev))
1776 if (pci_enable_device(pdev))
1780 /* This may fail but that's ok */
1781 pci_enable_pcie_error_reporting(pdev);
1783 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
1785 DEBUG(printk("Unable to allocate memory for ha\n"));
1790 /* Clear our data area */
1792 ha->mem_only = mem_only;
1793 spin_lock_init(&ha->hardware_lock);
1795 /* Set ISP-type information. */
1796 qla2x00_set_isp_flags(ha);
1798 /* Set EEH reset type to fundamental if required by hba */
1799 if ( IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha)) {
1800 pdev->needs_freset = 1;
1803 /* Configure PCI I/O space */
1804 ret = qla2x00_iospace_config(ha);
1806 goto probe_hw_failed;
1808 qla_printk(KERN_INFO, ha,
1809 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1812 ha->prev_topology = 0;
1813 ha->init_cb_size = sizeof(init_cb_t);
1814 ha->link_data_rate = PORT_SPEED_UNKNOWN;
1815 ha->optrom_size = OPTROM_SIZE_2300;
1817 /* Assign ISP specific operations. */
1818 max_id = MAX_TARGETS_2200;
1819 if (IS_QLA2100(ha)) {
1820 max_id = MAX_TARGETS_2100;
1821 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1822 req_length = REQUEST_ENTRY_CNT_2100;
1823 rsp_length = RESPONSE_ENTRY_CNT_2100;
1824 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
1825 ha->gid_list_info_size = 4;
1826 ha->flash_conf_off = ~0;
1827 ha->flash_data_off = ~0;
1828 ha->nvram_conf_off = ~0;
1829 ha->nvram_data_off = ~0;
1830 ha->isp_ops = &qla2100_isp_ops;
1831 } else if (IS_QLA2200(ha)) {
1832 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1833 req_length = REQUEST_ENTRY_CNT_2200;
1834 rsp_length = RESPONSE_ENTRY_CNT_2100;
1835 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
1836 ha->gid_list_info_size = 4;
1837 ha->flash_conf_off = ~0;
1838 ha->flash_data_off = ~0;
1839 ha->nvram_conf_off = ~0;
1840 ha->nvram_data_off = ~0;
1841 ha->isp_ops = &qla2100_isp_ops;
1842 } else if (IS_QLA23XX(ha)) {
1843 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1844 req_length = REQUEST_ENTRY_CNT_2200;
1845 rsp_length = RESPONSE_ENTRY_CNT_2300;
1846 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1847 ha->gid_list_info_size = 6;
1848 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1849 ha->optrom_size = OPTROM_SIZE_2322;
1850 ha->flash_conf_off = ~0;
1851 ha->flash_data_off = ~0;
1852 ha->nvram_conf_off = ~0;
1853 ha->nvram_data_off = ~0;
1854 ha->isp_ops = &qla2300_isp_ops;
1855 } else if (IS_QLA24XX_TYPE(ha)) {
1856 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1857 req_length = REQUEST_ENTRY_CNT_24XX;
1858 rsp_length = RESPONSE_ENTRY_CNT_2300;
1859 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1860 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1861 ha->gid_list_info_size = 8;
1862 ha->optrom_size = OPTROM_SIZE_24XX;
1863 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
1864 ha->isp_ops = &qla24xx_isp_ops;
1865 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1866 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1867 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1868 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
1869 } else if (IS_QLA25XX(ha)) {
1870 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1871 req_length = REQUEST_ENTRY_CNT_24XX;
1872 rsp_length = RESPONSE_ENTRY_CNT_2300;
1873 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1874 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1875 ha->gid_list_info_size = 8;
1876 ha->optrom_size = OPTROM_SIZE_25XX;
1877 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
1878 ha->isp_ops = &qla25xx_isp_ops;
1879 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1880 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1881 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1882 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
1883 } else if (IS_QLA81XX(ha)) {
1884 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1885 req_length = REQUEST_ENTRY_CNT_24XX;
1886 rsp_length = RESPONSE_ENTRY_CNT_2300;
1887 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1888 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
1889 ha->gid_list_info_size = 8;
1890 ha->optrom_size = OPTROM_SIZE_81XX;
1891 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
1892 ha->isp_ops = &qla81xx_isp_ops;
1893 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
1894 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
1895 ha->nvram_conf_off = ~0;
1896 ha->nvram_data_off = ~0;
1899 mutex_init(&ha->vport_lock);
1900 init_completion(&ha->mbx_cmd_comp);
1901 complete(&ha->mbx_cmd_comp);
1902 init_completion(&ha->mbx_intr_comp);
1904 set_bit(0, (unsigned long *) ha->vp_idx_map);
1906 qla2x00_config_dma_addressing(ha);
1907 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
1909 qla_printk(KERN_WARNING, ha,
1910 "[ERROR] Failed to allocate memory for adapter\n");
1912 goto probe_hw_failed;
1915 req->max_q_depth = MAX_Q_DEPTH;
1916 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
1917 req->max_q_depth = ql2xmaxqdepth;
1920 base_vha = qla2x00_create_host(sht, ha);
1922 qla_printk(KERN_WARNING, ha,
1923 "[ERROR] Failed to allocate memory for scsi_host\n");
1926 qla2x00_mem_free(ha);
1927 qla2x00_free_req_que(ha, req);
1928 qla2x00_free_rsp_que(ha, rsp);
1929 goto probe_hw_failed;
1932 pci_set_drvdata(pdev, base_vha);
1934 host = base_vha->host;
1935 base_vha->req = req;
1936 host->can_queue = req->length + 128;
1937 if (IS_QLA2XXX_MIDTYPE(ha))
1938 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
1940 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
1943 host->sg_tablesize = 32;
1944 host->max_id = max_id;
1945 host->this_id = 255;
1946 host->cmd_per_lun = 3;
1947 host->unique_id = host->host_no;
1948 host->max_cmd_len = MAX_CMDSZ;
1949 host->max_channel = MAX_BUSES - 1;
1950 host->max_lun = MAX_LUNS;
1951 host->transportt = qla2xxx_transport_template;
1952 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
1954 /* Set up the irqs */
1955 ret = qla2x00_request_irqs(ha, rsp);
1957 goto probe_init_failed;
1959 pci_save_state(pdev);
1961 /* Alloc arrays of request and response ring ptrs */
1963 if (!qla2x00_alloc_queues(ha)) {
1964 qla_printk(KERN_WARNING, ha,
1965 "[ERROR] Failed to allocate memory for queue"
1967 goto probe_init_failed;
1969 ha->rsp_q_map[0] = rsp;
1970 ha->req_q_map[0] = req;
1973 set_bit(0, ha->req_qid_map);
1974 set_bit(0, ha->rsp_qid_map);
1975 /* FWI2-capable only. */
1976 req->req_q_in = &ha->iobase->isp24.req_q_in;
1977 req->req_q_out = &ha->iobase->isp24.req_q_out;
1978 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
1979 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
1981 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
1982 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
1983 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
1984 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
1987 if (qla2x00_initialize_adapter(base_vha)) {
1988 qla_printk(KERN_WARNING, ha,
1989 "Failed to initialize adapter\n");
1991 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1992 "Adapter flags %x.\n",
1993 base_vha->host_no, base_vha->device_flags));
2000 if (qla25xx_setup_mode(base_vha)) {
2001 qla_printk(KERN_WARNING, ha,
2002 "Can't create queues, falling back to single"
2008 if (ha->flags.running_gold_fw)
2012 * Startup the kernel thread for this host adapter
2014 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
2015 "%s_dpc", base_vha->host_str);
2016 if (IS_ERR(ha->dpc_thread)) {
2017 qla_printk(KERN_WARNING, ha,
2018 "Unable to start DPC thread!\n");
2019 ret = PTR_ERR(ha->dpc_thread);
2024 list_add_tail(&base_vha->list, &ha->vp_list);
2025 base_vha->host->irq = ha->pdev->irq;
2027 /* Initialized the timer */
2028 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
2030 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
2031 base_vha->host_no, ha));
2033 ret = scsi_add_host(host, &pdev->dev);
2037 base_vha->flags.init_done = 1;
2038 base_vha->flags.online = 1;
2040 ha->isp_ops->enable_intrs(ha);
2042 scsi_scan_host(host);
2044 qla2x00_alloc_sysfs_attr(base_vha);
2046 qla2x00_init_host_attr(base_vha);
2048 qla2x00_dfs_setup(base_vha);
2050 qla_printk(KERN_INFO, ha, "\n"
2051 " QLogic Fibre Channel HBA Driver: %s\n"
2053 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
2054 qla2x00_version_str, ha->model_number,
2055 ha->model_desc ? ha->model_desc : "", pdev->device,
2056 ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
2057 ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
2058 ha->isp_ops->fw_version_str(base_vha, fw_str));
2063 qla2x00_free_req_que(ha, req);
2064 qla2x00_free_rsp_que(ha, rsp);
2065 ha->max_req_queues = ha->max_rsp_queues = 0;
2068 if (base_vha->timer_active)
2069 qla2x00_stop_timer(base_vha);
2070 base_vha->flags.online = 0;
2071 if (ha->dpc_thread) {
2072 struct task_struct *t = ha->dpc_thread;
2074 ha->dpc_thread = NULL;
2078 qla2x00_free_device(base_vha);
2080 scsi_host_put(base_vha->host);
2084 iounmap(ha->iobase);
2086 pci_release_selected_regions(ha->pdev, ha->bars);
2091 pci_disable_device(pdev);
2096 qla2x00_remove_one(struct pci_dev *pdev)
2098 scsi_qla_host_t *base_vha, *vha, *temp;
2099 struct qla_hw_data *ha;
2101 base_vha = pci_get_drvdata(pdev);
2104 list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
2105 if (vha && vha->fc_vport)
2106 fc_vport_terminate(vha->fc_vport);
2109 set_bit(UNLOADING, &base_vha->dpc_flags);
2111 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2113 qla2x00_dfs_remove(base_vha);
2115 qla84xx_put_chip(base_vha);
2118 if (base_vha->timer_active)
2119 qla2x00_stop_timer(base_vha);
2121 base_vha->flags.online = 0;
2123 /* Flush the work queue and remove it */
2125 flush_workqueue(ha->wq);
2126 destroy_workqueue(ha->wq);
2130 /* Kill the kernel thread for this host */
2131 if (ha->dpc_thread) {
2132 struct task_struct *t = ha->dpc_thread;
2135 * qla2xxx_wake_dpc checks for ->dpc_thread
2136 * so we need to zero it out.
2138 ha->dpc_thread = NULL;
2142 qla2x00_free_sysfs_attr(base_vha);
2144 fc_remove_host(base_vha->host);
2146 scsi_remove_host(base_vha->host);
2148 qla2x00_free_device(base_vha);
2150 scsi_host_put(base_vha->host);
2153 iounmap(ha->iobase);
2156 iounmap(ha->mqiobase);
2158 pci_release_selected_regions(ha->pdev, ha->bars);
2162 pci_disable_pcie_error_reporting(pdev);
2164 pci_disable_device(pdev);
2165 pci_set_drvdata(pdev, NULL);
2169 qla2x00_free_device(scsi_qla_host_t *vha)
2171 struct qla_hw_data *ha = vha->hw;
2173 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
2176 if (vha->timer_active)
2177 qla2x00_stop_timer(vha);
2179 /* Kill the kernel thread for this host */
2180 if (ha->dpc_thread) {
2181 struct task_struct *t = ha->dpc_thread;
2184 * qla2xxx_wake_dpc checks for ->dpc_thread
2185 * so we need to zero it out.
2187 ha->dpc_thread = NULL;
2191 qla25xx_delete_queues(vha);
2193 if (ha->flags.fce_enabled)
2194 qla2x00_disable_fce_trace(vha, NULL, NULL);
2197 qla2x00_disable_eft_trace(vha);
2199 /* Stop currently executing firmware. */
2200 qla2x00_try_to_stop_firmware(vha);
2202 vha->flags.online = 0;
2204 /* turn-off interrupts on the card */
2205 if (ha->interrupts_on)
2206 ha->isp_ops->disable_intrs(ha);
2208 qla2x00_free_irqs(vha);
2210 qla2x00_mem_free(ha);
2212 qla2x00_free_queues(ha);
2216 qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
2219 struct fc_rport *rport;
2220 scsi_qla_host_t *base_vha;
2225 rport = fcport->rport;
2227 base_vha = pci_get_drvdata(vha->hw->pdev);
2228 spin_lock_irq(vha->host->host_lock);
2229 fcport->drport = rport;
2230 spin_unlock_irq(vha->host->host_lock);
2231 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2232 qla2xxx_wake_dpc(base_vha);
2234 fc_remote_port_delete(rport);
2238 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2240 * Input: ha = adapter block pointer. fcport = port structure pointer.
2246 void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
2247 int do_login, int defer)
2249 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2250 vha->vp_idx == fcport->vp_idx) {
2251 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2252 qla2x00_schedule_rport_del(vha, fcport, defer);
2255 * We may need to retry the login, so don't change the state of the
2256 * port but do the retries.
2258 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2259 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2264 if (fcport->login_retry == 0) {
2265 fcport->login_retry = vha->hw->login_retry_count;
2266 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2268 DEBUG(printk("scsi(%ld): Port login retry: "
2269 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2270 "id = 0x%04x retry cnt=%d\n",
2272 fcport->port_name[0],
2273 fcport->port_name[1],
2274 fcport->port_name[2],
2275 fcport->port_name[3],
2276 fcport->port_name[4],
2277 fcport->port_name[5],
2278 fcport->port_name[6],
2279 fcport->port_name[7],
2281 fcport->login_retry));
2286 * qla2x00_mark_all_devices_lost
2287 * Updates fcport state when device goes offline.
2290 * ha = adapter block pointer.
2291 * fcport = port structure pointer.
2299 qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
2303 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2304 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vp_idx)
2308 * No point in marking the device as lost, if the device is
2311 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2313 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2315 qla2x00_schedule_rport_del(vha, fcport, defer);
2316 else if (vha->vp_idx == fcport->vp_idx)
2317 qla2x00_schedule_rport_del(vha, fcport, defer);
2319 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2325 * Allocates adapter memory.
2332 qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2333 struct req_que **req, struct rsp_que **rsp)
2337 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
2338 &ha->init_cb_dma, GFP_KERNEL);
2342 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2343 &ha->gid_list_dma, GFP_KERNEL);
2345 goto fail_free_init_cb;
2347 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2348 if (!ha->srb_mempool)
2349 goto fail_free_gid_list;
2351 /* Get memory for cached NVRAM */
2352 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2354 goto fail_free_srb_mempool;
2356 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2358 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2359 DMA_POOL_SIZE, 8, 0);
2360 if (!ha->s_dma_pool)
2361 goto fail_free_nvram;
2363 /* Allocate memory for SNS commands */
2364 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2365 /* Get consistent memory allocated for SNS commands */
2366 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
2367 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
2371 /* Get consistent memory allocated for MS IOCB */
2372 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2376 /* Get consistent memory allocated for CT SNS commands */
2377 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
2378 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
2380 goto fail_free_ms_iocb;
2383 /* Allocate memory for request ring */
2384 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2386 DEBUG(printk("Unable to allocate memory for req\n"));
2389 (*req)->length = req_len;
2390 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2391 ((*req)->length + 1) * sizeof(request_t),
2392 &(*req)->dma, GFP_KERNEL);
2393 if (!(*req)->ring) {
2394 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2397 /* Allocate memory for response ring */
2398 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2400 qla_printk(KERN_WARNING, ha,
2401 "Unable to allocate memory for rsp\n");
2405 (*rsp)->length = rsp_len;
2406 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2407 ((*rsp)->length + 1) * sizeof(response_t),
2408 &(*rsp)->dma, GFP_KERNEL);
2409 if (!(*rsp)->ring) {
2410 qla_printk(KERN_WARNING, ha,
2411 "Unable to allocate memory for rsp_ring\n");
2416 /* Allocate memory for NVRAM data for vports */
2417 if (ha->nvram_npiv_size) {
2418 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
2419 ha->nvram_npiv_size, GFP_KERNEL);
2420 if (!ha->npiv_info) {
2421 qla_printk(KERN_WARNING, ha,
2422 "Unable to allocate memory for npiv info\n");
2423 goto fail_npiv_info;
2426 ha->npiv_info = NULL;
2428 /* Get consistent memory allocated for EX-INIT-CB. */
2429 if (IS_QLA81XX(ha)) {
2430 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2431 &ha->ex_init_cb_dma);
2432 if (!ha->ex_init_cb)
2433 goto fail_ex_init_cb;
2436 INIT_LIST_HEAD(&ha->vp_list);
2440 kfree(ha->npiv_info);
2442 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2443 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2444 (*rsp)->ring = NULL;
2449 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2450 sizeof(request_t), (*req)->ring, (*req)->dma);
2451 (*req)->ring = NULL;
2456 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2457 ha->ct_sns, ha->ct_sns_dma);
2461 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2463 ha->ms_iocb_dma = 0;
2465 dma_pool_destroy(ha->s_dma_pool);
2466 ha->s_dma_pool = NULL;
2470 fail_free_srb_mempool:
2471 mempool_destroy(ha->srb_mempool);
2472 ha->srb_mempool = NULL;
2474 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2476 ha->gid_list = NULL;
2477 ha->gid_list_dma = 0;
2479 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2482 ha->init_cb_dma = 0;
2484 DEBUG(printk("%s: Memory allocation failure\n", __func__));
2490 * Frees all adapter allocated memory.
2493 * ha = adapter block pointer.
2496 qla2x00_mem_free(struct qla_hw_data *ha)
2498 if (ha->srb_mempool)
2499 mempool_destroy(ha->srb_mempool);
2502 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
2507 dma_free_coherent(&ha->pdev->dev,
2508 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
2513 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
2514 ha->dcbx_tlv, ha->dcbx_tlv_dma);
2517 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
2518 ha->xgmac_data, ha->xgmac_data_dma);
2521 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
2522 ha->sns_cmd, ha->sns_cmd_dma);
2525 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2526 ha->ct_sns, ha->ct_sns_dma);
2529 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2532 dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
2535 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2538 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
2541 dma_pool_destroy(ha->s_dma_pool);
2544 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2548 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2549 ha->init_cb, ha->init_cb_dma);
2550 vfree(ha->optrom_buffer);
2552 kfree(ha->npiv_info);
2554 ha->srb_mempool = NULL;
2558 ha->sns_cmd_dma = 0;
2562 ha->ms_iocb_dma = 0;
2564 ha->init_cb_dma = 0;
2565 ha->ex_init_cb = NULL;
2566 ha->ex_init_cb_dma = 0;
2568 ha->s_dma_pool = NULL;
2570 ha->gid_list = NULL;
2571 ha->gid_list_dma = 0;
2575 ha->fw_dump_reading = 0;
2578 struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
2579 struct qla_hw_data *ha)
2581 struct Scsi_Host *host;
2582 struct scsi_qla_host *vha = NULL;
2584 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
2587 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2591 /* Clear our data area */
2592 vha = shost_priv(host);
2593 memset(vha, 0, sizeof(scsi_qla_host_t));
2596 vha->host_no = host->host_no;
2599 INIT_LIST_HEAD(&vha->vp_fcports);
2600 INIT_LIST_HEAD(&vha->work_list);
2601 INIT_LIST_HEAD(&vha->list);
2603 spin_lock_init(&vha->work_lock);
2605 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
2612 static struct qla_work_evt *
2613 qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
2615 struct qla_work_evt *e;
2617 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
2621 INIT_LIST_HEAD(&e->list);
2623 e->flags = QLA_EVT_FLAG_FREE;
2628 qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
2630 unsigned long flags;
2632 spin_lock_irqsave(&vha->work_lock, flags);
2633 list_add_tail(&e->list, &vha->work_list);
2634 spin_unlock_irqrestore(&vha->work_lock, flags);
2635 qla2xxx_wake_dpc(vha);
2641 qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
2644 struct qla_work_evt *e;
2646 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
2648 return QLA_FUNCTION_FAILED;
2650 e->u.aen.code = code;
2651 e->u.aen.data = data;
2652 return qla2x00_post_work(vha, e);
2656 qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
2658 struct qla_work_evt *e;
2660 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
2662 return QLA_FUNCTION_FAILED;
2664 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
2665 return qla2x00_post_work(vha, e);
2668 #define qla2x00_post_async_work(name, type) \
2669 int qla2x00_post_async_##name##_work( \
2670 struct scsi_qla_host *vha, \
2671 fc_port_t *fcport, uint16_t *data) \
2673 struct qla_work_evt *e; \
2675 e = qla2x00_alloc_work(vha, type); \
2677 return QLA_FUNCTION_FAILED; \
2679 e->u.logio.fcport = fcport; \
2681 e->u.logio.data[0] = data[0]; \
2682 e->u.logio.data[1] = data[1]; \
2684 return qla2x00_post_work(vha, e); \
2687 qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
2688 qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
2689 qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
2690 qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
2693 qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
2695 struct qla_work_evt *e;
2697 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
2699 return QLA_FUNCTION_FAILED;
2701 e->u.uevent.code = code;
2702 return qla2x00_post_work(vha, e);
2706 qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
2708 char event_string[40];
2709 char *envp[] = { event_string, NULL };
2712 case QLA_UEVENT_CODE_FW_DUMP:
2713 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
2720 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
2724 qla2x00_do_work(struct scsi_qla_host *vha)
2726 struct qla_work_evt *e, *tmp;
2727 unsigned long flags;
2730 spin_lock_irqsave(&vha->work_lock, flags);
2731 list_splice_init(&vha->work_list, &work);
2732 spin_unlock_irqrestore(&vha->work_lock, flags);
2734 list_for_each_entry_safe(e, tmp, &work, list) {
2735 list_del_init(&e->list);
2739 fc_host_post_event(vha->host, fc_get_event_number(),
2740 e->u.aen.code, e->u.aen.data);
2742 case QLA_EVT_IDC_ACK:
2743 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
2745 case QLA_EVT_ASYNC_LOGIN:
2746 qla2x00_async_login(vha, e->u.logio.fcport,
2749 case QLA_EVT_ASYNC_LOGIN_DONE:
2750 qla2x00_async_login_done(vha, e->u.logio.fcport,
2753 case QLA_EVT_ASYNC_LOGOUT:
2754 qla2x00_async_logout(vha, e->u.logio.fcport);
2756 case QLA_EVT_ASYNC_LOGOUT_DONE:
2757 qla2x00_async_logout_done(vha, e->u.logio.fcport,
2760 case QLA_EVT_UEVENT:
2761 qla2x00_uevent_emit(vha, e->u.uevent.code);
2764 if (e->flags & QLA_EVT_FLAG_FREE)
2769 /* Relogins all the fcports of a vport
2770 * Context: dpc thread
2772 void qla2x00_relogin(struct scsi_qla_host *vha)
2776 uint16_t next_loopid = 0;
2777 struct qla_hw_data *ha = vha->hw;
2780 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2782 * If the port is not ONLINE then try to login
2783 * to it if we haven't run out of retries.
2785 if (atomic_read(&fcport->state) !=
2786 FCS_ONLINE && fcport->login_retry) {
2788 fcport->login_retry--;
2789 if (fcport->flags & FCF_FABRIC_DEVICE) {
2790 if (fcport->flags & FCF_FCP2_DEVICE)
2791 ha->isp_ops->fabric_logout(vha,
2793 fcport->d_id.b.domain,
2794 fcport->d_id.b.area,
2795 fcport->d_id.b.al_pa);
2797 if (IS_ALOGIO_CAPABLE(ha)) {
2799 data[1] = QLA_LOGIO_LOGIN_RETRIED;
2800 status = qla2x00_post_async_login_work(
2802 if (status == QLA_SUCCESS)
2804 /* Attempt a retry. */
2807 status = qla2x00_fabric_login(vha,
2808 fcport, &next_loopid);
2810 status = qla2x00_local_device_login(vha,
2813 if (status == QLA_SUCCESS) {
2814 fcport->old_loop_id = fcport->loop_id;
2816 DEBUG(printk("scsi(%ld): port login OK: logged "
2817 "in ID 0x%x\n", vha->host_no, fcport->loop_id));
2819 qla2x00_update_fcport(vha, fcport);
2821 } else if (status == 1) {
2822 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2823 /* retry the login again */
2824 DEBUG(printk("scsi(%ld): Retrying"
2825 " %d login again loop_id 0x%x\n",
2826 vha->host_no, fcport->login_retry,
2829 fcport->login_retry = 0;
2832 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
2833 fcport->loop_id = FC_NO_LOOP_ID;
2835 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2840 /**************************************************************************
2842 * This kernel thread is a task that is schedule by the interrupt handler
2843 * to perform the background processing for interrupts.
2846 * This task always run in the context of a kernel thread. It
2847 * is kick-off by the driver's detect code and starts up
2848 * up one per adapter. It immediately goes to sleep and waits for
2849 * some fibre event. When either the interrupt handler or
2850 * the timer routine detects a event it will one of the task
2851 * bits then wake us up.
2852 **************************************************************************/
2854 qla2x00_do_dpc(void *data)
2857 scsi_qla_host_t *base_vha;
2858 struct qla_hw_data *ha;
2860 ha = (struct qla_hw_data *)data;
2861 base_vha = pci_get_drvdata(ha->pdev);
2863 set_user_nice(current, -20);
2865 while (!kthread_should_stop()) {
2866 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2868 set_current_state(TASK_INTERRUPTIBLE);
2870 __set_current_state(TASK_RUNNING);
2872 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2874 /* Initialization not yet finished. Don't do anything yet. */
2875 if (!base_vha->flags.init_done)
2878 if (ha->flags.eeh_busy) {
2879 DEBUG17(qla_printk(KERN_WARNING, ha,
2880 "qla2x00_do_dpc: dpc_flags: %lx\n",
2881 base_vha->dpc_flags));
2885 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
2889 if (ha->flags.mbox_busy) {
2894 qla2x00_do_work(base_vha);
2896 if (test_and_clear_bit(ISP_ABORT_NEEDED,
2897 &base_vha->dpc_flags)) {
2899 DEBUG(printk("scsi(%ld): dpc: sched "
2900 "qla2x00_abort_isp ha = %p\n",
2901 base_vha->host_no, ha));
2902 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2903 &base_vha->dpc_flags))) {
2905 if (qla2x00_abort_isp(base_vha)) {
2906 /* failed. retry later */
2907 set_bit(ISP_ABORT_NEEDED,
2908 &base_vha->dpc_flags);
2910 clear_bit(ABORT_ISP_ACTIVE,
2911 &base_vha->dpc_flags);
2914 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2915 base_vha->host_no));
2918 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
2919 qla2x00_update_fcports(base_vha);
2920 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2923 if (test_and_clear_bit(RESET_MARKER_NEEDED,
2924 &base_vha->dpc_flags) &&
2925 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
2927 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2928 base_vha->host_no));
2930 qla2x00_rst_aen(base_vha);
2931 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
2934 /* Retry each device up to login retry count */
2935 if ((test_and_clear_bit(RELOGIN_NEEDED,
2936 &base_vha->dpc_flags)) &&
2937 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
2938 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
2940 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2941 base_vha->host_no));
2942 qla2x00_relogin(base_vha);
2944 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2945 base_vha->host_no));
2948 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
2949 &base_vha->dpc_flags)) {
2951 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2952 base_vha->host_no));
2954 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2955 &base_vha->dpc_flags))) {
2957 rval = qla2x00_loop_resync(base_vha);
2959 clear_bit(LOOP_RESYNC_ACTIVE,
2960 &base_vha->dpc_flags);
2963 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2964 base_vha->host_no));
2967 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
2968 atomic_read(&base_vha->loop_state) == LOOP_READY) {
2969 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
2970 qla2xxx_flash_npiv_conf(base_vha);
2973 if (!ha->interrupts_on)
2974 ha->isp_ops->enable_intrs(ha);
2976 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
2977 &base_vha->dpc_flags))
2978 ha->isp_ops->beacon_blink(base_vha);
2980 qla2x00_do_dpc_all_vps(base_vha);
2983 } /* End of while(1) */
2985 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
2988 * Make sure that nobody tries to wake us up again.
2992 /* Cleanup any residual CTX SRBs. */
2993 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2999 qla2xxx_wake_dpc(struct scsi_qla_host *vha)
3001 struct qla_hw_data *ha = vha->hw;
3002 struct task_struct *t = ha->dpc_thread;
3004 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
3010 * Processes asynchronous reset.
3013 * ha = adapter block pointer.
3016 qla2x00_rst_aen(scsi_qla_host_t *vha)
3018 if (vha->flags.online && !vha->flags.reset_active &&
3019 !atomic_read(&vha->loop_down_timer) &&
3020 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
3022 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
3025 * Issue marker command only when we are going to start
3028 vha->marker_needed = 1;
3029 } while (!atomic_read(&vha->loop_down_timer) &&
3030 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
3035 qla2x00_sp_free_dma(srb_t *sp)
3037 struct scsi_cmnd *cmd = sp->cmd;
3039 if (sp->flags & SRB_DMA_VALID) {
3040 scsi_dma_unmap(cmd);
3041 sp->flags &= ~SRB_DMA_VALID;
3047 qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
3049 struct scsi_cmnd *cmd = sp->cmd;
3051 qla2x00_sp_free_dma(sp);
3053 mempool_free(sp, ha->srb_mempool);
3055 cmd->scsi_done(cmd);
3058 /**************************************************************************
3064 * Context: Interrupt
3065 ***************************************************************************/
3067 qla2x00_timer(scsi_qla_host_t *vha)
3069 unsigned long cpu_flags = 0;
3076 struct qla_hw_data *ha = vha->hw;
3077 struct req_que *req;
3079 /* Hardware read to raise pending EEH errors during mailbox waits. */
3080 if (!pci_channel_offline(ha->pdev))
3081 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
3083 * Ports - Port down timer.
3085 * Whenever, a port is in the LOST state we start decrementing its port
3086 * down timer every second until it reaches zero. Once it reaches zero
3087 * the port it marked DEAD.
3090 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3091 if (fcport->port_type != FCT_TARGET)
3094 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
3096 if (atomic_read(&fcport->port_down_timer) == 0)
3099 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
3100 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
3102 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
3105 t, atomic_read(&fcport->port_down_timer)));
3108 } /* End of for fcport */
3111 /* Loop down handler. */
3112 if (atomic_read(&vha->loop_down_timer) > 0 &&
3113 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
3114 && vha->flags.online) {
3116 if (atomic_read(&vha->loop_down_timer) ==
3117 vha->loop_down_abort_time) {
3119 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
3120 "queues before time expire\n",
3123 if (!IS_QLA2100(ha) && vha->link_down_timeout)
3124 atomic_set(&vha->loop_state, LOOP_DEAD);
3127 * Schedule an ISP abort to return any FCP2-device
3130 /* NPIV - scan physical port only */
3132 spin_lock_irqsave(&ha->hardware_lock,
3134 req = ha->req_q_map[0];
3136 index < MAX_OUTSTANDING_COMMANDS;
3140 sp = req->outstanding_cmds[index];
3146 if (!(sfcp->flags & FCF_FCP2_DEVICE))
3149 set_bit(ISP_ABORT_NEEDED,
3153 spin_unlock_irqrestore(&ha->hardware_lock,
3159 /* if the loop has been down for 4 minutes, reinit adapter */
3160 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
3161 if (!(vha->device_flags & DFLG_NO_CABLE)) {
3162 DEBUG(printk("scsi(%ld): Loop down - "
3165 qla_printk(KERN_WARNING, ha,
3166 "Loop down - aborting ISP.\n");
3168 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3171 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
3173 atomic_read(&vha->loop_down_timer)));
3176 /* Check if beacon LED needs to be blinked */
3177 if (ha->beacon_blink_led == 1) {
3178 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
3182 /* Process any deferred work. */
3183 if (!list_empty(&vha->work_list))
3186 /* Schedule the DPC routine if needed */
3187 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
3188 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
3189 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
3191 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
3192 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
3193 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
3194 test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
3195 qla2xxx_wake_dpc(vha);
3197 qla2x00_restart_timer(vha, WATCH_INTERVAL);
3200 /* Firmware interface routines. */
3203 #define FW_ISP21XX 0
3204 #define FW_ISP22XX 1
3205 #define FW_ISP2300 2
3206 #define FW_ISP2322 3
3207 #define FW_ISP24XX 4
3208 #define FW_ISP25XX 5
3209 #define FW_ISP81XX 6
3211 #define FW_FILE_ISP21XX "ql2100_fw.bin"
3212 #define FW_FILE_ISP22XX "ql2200_fw.bin"
3213 #define FW_FILE_ISP2300 "ql2300_fw.bin"
3214 #define FW_FILE_ISP2322 "ql2322_fw.bin"
3215 #define FW_FILE_ISP24XX "ql2400_fw.bin"
3216 #define FW_FILE_ISP25XX "ql2500_fw.bin"
3217 #define FW_FILE_ISP81XX "ql8100_fw.bin"
3219 static DEFINE_MUTEX(qla_fw_lock);
3221 static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
3222 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
3223 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
3224 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
3225 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
3226 { .name = FW_FILE_ISP24XX, },
3227 { .name = FW_FILE_ISP25XX, },
3228 { .name = FW_FILE_ISP81XX, },
3232 qla2x00_request_firmware(scsi_qla_host_t *vha)
3234 struct qla_hw_data *ha = vha->hw;
3235 struct fw_blob *blob;
3238 if (IS_QLA2100(ha)) {
3239 blob = &qla_fw_blobs[FW_ISP21XX];
3240 } else if (IS_QLA2200(ha)) {
3241 blob = &qla_fw_blobs[FW_ISP22XX];
3242 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3243 blob = &qla_fw_blobs[FW_ISP2300];
3244 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
3245 blob = &qla_fw_blobs[FW_ISP2322];
3246 } else if (IS_QLA24XX_TYPE(ha)) {
3247 blob = &qla_fw_blobs[FW_ISP24XX];
3248 } else if (IS_QLA25XX(ha)) {
3249 blob = &qla_fw_blobs[FW_ISP25XX];
3250 } else if (IS_QLA81XX(ha)) {
3251 blob = &qla_fw_blobs[FW_ISP81XX];
3254 mutex_lock(&qla_fw_lock);
3258 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
3259 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
3260 "(%s).\n", vha->host_no, blob->name));
3267 mutex_unlock(&qla_fw_lock);
3272 qla2x00_release_firmware(void)
3276 mutex_lock(&qla_fw_lock);
3277 for (idx = 0; idx < FW_BLOBS; idx++)
3278 if (qla_fw_blobs[idx].fw)
3279 release_firmware(qla_fw_blobs[idx].fw);
3280 mutex_unlock(&qla_fw_lock);
3283 static pci_ers_result_t
3284 qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3286 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
3287 struct qla_hw_data *ha = vha->hw;
3289 DEBUG2(qla_printk(KERN_WARNING, ha, "error_detected:state %x\n",
3293 case pci_channel_io_normal:
3294 ha->flags.eeh_busy = 0;
3295 return PCI_ERS_RESULT_CAN_RECOVER;
3296 case pci_channel_io_frozen:
3297 ha->flags.eeh_busy = 1;
3298 qla2x00_free_irqs(vha);
3299 pci_disable_device(pdev);
3300 return PCI_ERS_RESULT_NEED_RESET;
3301 case pci_channel_io_perm_failure:
3302 ha->flags.pci_channel_io_perm_failure = 1;
3303 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3304 return PCI_ERS_RESULT_DISCONNECT;
3306 return PCI_ERS_RESULT_NEED_RESET;
3309 static pci_ers_result_t
3310 qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
3312 int risc_paused = 0;
3314 unsigned long flags;
3315 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3316 struct qla_hw_data *ha = base_vha->hw;
3317 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3318 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
3320 spin_lock_irqsave(&ha->hardware_lock, flags);
3321 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
3322 stat = RD_REG_DWORD(®->hccr);
3323 if (stat & HCCR_RISC_PAUSE)
3325 } else if (IS_QLA23XX(ha)) {
3326 stat = RD_REG_DWORD(®->u.isp2300.host_status);
3327 if (stat & HSR_RISC_PAUSED)
3329 } else if (IS_FWI2_CAPABLE(ha)) {
3330 stat = RD_REG_DWORD(®24->host_status);
3331 if (stat & HSRX_RISC_PAUSED)
3334 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3337 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
3338 "Dumping firmware!\n");
3339 ha->isp_ops->fw_dump(base_vha, 0);
3341 return PCI_ERS_RESULT_NEED_RESET;
3343 return PCI_ERS_RESULT_RECOVERED;
3346 static pci_ers_result_t
3347 qla2xxx_pci_slot_reset(struct pci_dev *pdev)
3349 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
3350 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3351 struct qla_hw_data *ha = base_vha->hw;
3352 struct rsp_que *rsp;
3353 int rc, retries = 10;
3355 DEBUG17(qla_printk(KERN_WARNING, ha, "slot_reset\n"));
3357 /* Workaround: qla2xxx driver which access hardware earlier
3358 * needs error state to be pci_channel_io_online.
3359 * Otherwise mailbox command timesout.
3361 pdev->error_state = pci_channel_io_normal;
3363 pci_restore_state(pdev);
3365 /* pci_restore_state() clears the saved_state flag of the device
3366 * save restored state which resets saved_state flag
3368 pci_save_state(pdev);
3371 rc = pci_enable_device_mem(pdev);
3373 rc = pci_enable_device(pdev);
3376 qla_printk(KERN_WARNING, ha,
3377 "Can't re-enable PCI device after reset.\n");
3381 rsp = ha->rsp_q_map[0];
3382 if (qla2x00_request_irqs(ha, rsp))
3385 if (ha->isp_ops->pci_config(base_vha))
3388 while (ha->flags.mbox_busy && retries--)
3391 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3392 if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
3393 ret = PCI_ERS_RESULT_RECOVERED;
3394 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3396 pci_cleanup_aer_uncorrect_error_status(pdev);
3398 DEBUG17(qla_printk(KERN_WARNING, ha,
3399 "slot_reset-return:ret=%x\n", ret));
3405 qla2xxx_pci_resume(struct pci_dev *pdev)
3407 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3408 struct qla_hw_data *ha = base_vha->hw;
3411 DEBUG17(qla_printk(KERN_WARNING, ha, "pci_resume\n"));
3413 ret = qla2x00_wait_for_hba_online(base_vha);
3414 if (ret != QLA_SUCCESS) {
3415 qla_printk(KERN_ERR, ha,
3416 "the device failed to resume I/O "
3417 "from slot/link_reset");
3420 ha->flags.eeh_busy = 0;
3423 static struct pci_error_handlers qla2xxx_err_handler = {
3424 .error_detected = qla2xxx_pci_error_detected,
3425 .mmio_enabled = qla2xxx_pci_mmio_enabled,
3426 .slot_reset = qla2xxx_pci_slot_reset,
3427 .resume = qla2xxx_pci_resume,
3430 static struct pci_device_id qla2xxx_pci_tbl[] = {
3431 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
3432 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
3433 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
3434 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
3435 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
3436 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
3437 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
3438 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
3439 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
3440 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
3441 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
3442 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
3443 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
3444 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
3447 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
3449 static struct pci_driver qla2xxx_pci_driver = {
3450 .name = QLA2XXX_DRIVER_NAME,
3452 .owner = THIS_MODULE,
3454 .id_table = qla2xxx_pci_tbl,
3455 .probe = qla2x00_probe_one,
3456 .remove = qla2x00_remove_one,
3457 .err_handler = &qla2xxx_err_handler,
3461 * qla2x00_module_init - Module initialization.
3464 qla2x00_module_init(void)
3468 /* Allocate cache for SRBs. */
3469 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
3470 SLAB_HWCACHE_ALIGN, NULL);
3471 if (srb_cachep == NULL) {
3473 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3477 /* Derive version string. */
3478 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
3479 if (ql2xextended_error_logging)
3480 strcat(qla2x00_version_str, "-debug");
3482 qla2xxx_transport_template =
3483 fc_attach_transport(&qla2xxx_transport_functions);
3484 if (!qla2xxx_transport_template) {
3485 kmem_cache_destroy(srb_cachep);
3488 qla2xxx_transport_vport_template =
3489 fc_attach_transport(&qla2xxx_transport_vport_functions);
3490 if (!qla2xxx_transport_vport_template) {
3491 kmem_cache_destroy(srb_cachep);
3492 fc_release_transport(qla2xxx_transport_template);
3496 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
3497 qla2x00_version_str);
3498 ret = pci_register_driver(&qla2xxx_pci_driver);
3500 kmem_cache_destroy(srb_cachep);
3501 fc_release_transport(qla2xxx_transport_template);
3502 fc_release_transport(qla2xxx_transport_vport_template);
3508 * qla2x00_module_exit - Module cleanup.
3511 qla2x00_module_exit(void)
3513 pci_unregister_driver(&qla2xxx_pci_driver);
3514 qla2x00_release_firmware();
3515 kmem_cache_destroy(srb_cachep);
3516 fc_release_transport(qla2xxx_transport_template);
3517 fc_release_transport(qla2xxx_transport_vport_template);
3520 module_init(qla2x00_module_init);
3521 module_exit(qla2x00_module_exit);
3523 MODULE_AUTHOR("QLogic Corporation");
3524 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3525 MODULE_LICENSE("GPL");
3526 MODULE_VERSION(QLA2XXX_VERSION);
3527 MODULE_FIRMWARE(FW_FILE_ISP21XX);
3528 MODULE_FIRMWARE(FW_FILE_ISP22XX);
3529 MODULE_FIRMWARE(FW_FILE_ISP2300);
3530 MODULE_FIRMWARE(FW_FILE_ISP2322);
3531 MODULE_FIRMWARE(FW_FILE_ISP24XX);
3532 MODULE_FIRMWARE(FW_FILE_ISP25XX);