2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2008 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/moduleparam.h>
10 #include <linux/vmalloc.h>
11 #include <linux/delay.h>
12 #include <linux/kthread.h>
13 #include <linux/mutex.h>
15 #include <scsi/scsi_tcq.h>
16 #include <scsi/scsicam.h>
17 #include <scsi/scsi_transport.h>
18 #include <scsi/scsi_transport_fc.h>
23 char qla2x00_version_str[40];
26 * SRB allocation cache
28 static struct kmem_cache *srb_cachep;
30 int ql2xlogintimeout = 20;
31 module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
32 MODULE_PARM_DESC(ql2xlogintimeout,
33 "Login timeout value in seconds.");
35 int qlport_down_retry;
36 module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
37 MODULE_PARM_DESC(qlport_down_retry,
38 "Maximum number of command retries to a port that returns "
39 "a PORT-DOWN status.");
41 int ql2xplogiabsentdevice;
42 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
43 MODULE_PARM_DESC(ql2xplogiabsentdevice,
44 "Option to enable PLOGI to devices that are not present after "
45 "a Fabric scan. This is needed for several broken switches. "
46 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
48 int ql2xloginretrycount = 0;
49 module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
50 MODULE_PARM_DESC(ql2xloginretrycount,
51 "Specify an alternate value for the NVRAM login retry count.");
53 int ql2xallocfwdump = 1;
54 module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR);
55 MODULE_PARM_DESC(ql2xallocfwdump,
56 "Option to enable allocation of memory for a firmware dump "
57 "during HBA initialization. Memory allocation requirements "
58 "vary by ISP type. Default is 1 - allocate memory.");
60 int ql2xextended_error_logging;
61 module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
62 MODULE_PARM_DESC(ql2xextended_error_logging,
63 "Option to enable extended error logging, "
64 "Default is 0 - no logging. 1 - log errors.");
66 static void qla2x00_free_device(scsi_qla_host_t *);
69 module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
70 MODULE_PARM_DESC(ql2xfdmienable,
71 "Enables FDMI registratons "
72 "Default is 0 - no FDMI. 1 - perfom FDMI.");
74 #define MAX_Q_DEPTH 32
75 static int ql2xmaxqdepth = MAX_Q_DEPTH;
76 module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
77 MODULE_PARM_DESC(ql2xmaxqdepth,
78 "Maximum queue depth to report for target devices.");
80 int ql2xqfulltracking = 1;
81 module_param(ql2xqfulltracking, int, S_IRUGO|S_IWUSR);
82 MODULE_PARM_DESC(ql2xqfulltracking,
83 "Controls whether the driver tracks queue full status "
84 "returns and dynamically adjusts a scsi device's queue "
85 "depth. Default is 1, perform tracking. Set to 0 to "
86 "disable dynamic tracking and adjustment of queue depth.");
88 int ql2xqfullrampup = 120;
89 module_param(ql2xqfullrampup, int, S_IRUGO|S_IWUSR);
90 MODULE_PARM_DESC(ql2xqfullrampup,
91 "Number of seconds to wait to begin to ramp-up the queue "
92 "depth for a device after a queue-full condition has been "
93 "detected. Default is 120 seconds.");
95 int ql2xiidmaenable=1;
96 module_param(ql2xiidmaenable, int, S_IRUGO|S_IRUSR);
97 MODULE_PARM_DESC(ql2xiidmaenable,
98 "Enables iIDMA settings "
99 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
101 int ql2xmaxqueues = 1;
102 module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR);
103 MODULE_PARM_DESC(ql2xmaxqueues,
104 "Enables MQ settings "
105 "Default is 1 for single queue. Set it to number \
106 of queues in MQ mode.");
108 int ql2xmultique_tag;
109 module_param(ql2xmultique_tag, int, S_IRUGO|S_IRUSR);
110 MODULE_PARM_DESC(ql2xmultique_tag,
111 "Enables CPU affinity settings for the driver "
112 "Default is 0 for no affinity of request and response IO. "
113 "Set it to 1 to turn on the cpu affinity.");
116 module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR);
117 MODULE_PARM_DESC(ql2xfwloadbin,
118 "Option to specify location from which to load ISP firmware:\n"
119 " 2 -- load firmware via the request_firmware() (hotplug)\n"
121 " 1 -- load firmware from flash.\n"
122 " 0 -- use default semantics.\n");
125 * SCSI host template entry points
127 static int qla2xxx_slave_configure(struct scsi_device * device);
128 static int qla2xxx_slave_alloc(struct scsi_device *);
129 static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
130 static void qla2xxx_scan_start(struct Scsi_Host *);
131 static void qla2xxx_slave_destroy(struct scsi_device *);
132 static int qla2xxx_queuecommand(struct scsi_cmnd *cmd,
133 void (*fn)(struct scsi_cmnd *));
134 static int qla2xxx_eh_abort(struct scsi_cmnd *);
135 static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
136 static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
137 static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
138 static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
140 static int qla2x00_change_queue_depth(struct scsi_device *, int);
141 static int qla2x00_change_queue_type(struct scsi_device *, int);
143 struct scsi_host_template qla2xxx_driver_template = {
144 .module = THIS_MODULE,
145 .name = QLA2XXX_DRIVER_NAME,
146 .queuecommand = qla2xxx_queuecommand,
148 .eh_abort_handler = qla2xxx_eh_abort,
149 .eh_device_reset_handler = qla2xxx_eh_device_reset,
150 .eh_target_reset_handler = qla2xxx_eh_target_reset,
151 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
152 .eh_host_reset_handler = qla2xxx_eh_host_reset,
154 .slave_configure = qla2xxx_slave_configure,
156 .slave_alloc = qla2xxx_slave_alloc,
157 .slave_destroy = qla2xxx_slave_destroy,
158 .scan_finished = qla2xxx_scan_finished,
159 .scan_start = qla2xxx_scan_start,
160 .change_queue_depth = qla2x00_change_queue_depth,
161 .change_queue_type = qla2x00_change_queue_type,
164 .use_clustering = ENABLE_CLUSTERING,
165 .sg_tablesize = SG_ALL,
167 .max_sectors = 0xFFFF,
168 .shost_attrs = qla2x00_host_attrs,
171 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
172 struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
174 /* TODO Convert to inlines
180 qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
182 init_timer(&vha->timer);
183 vha->timer.expires = jiffies + interval * HZ;
184 vha->timer.data = (unsigned long)vha;
185 vha->timer.function = (void (*)(unsigned long))func;
186 add_timer(&vha->timer);
187 vha->timer_active = 1;
191 qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
193 mod_timer(&vha->timer, jiffies + interval * HZ);
196 static __inline__ void
197 qla2x00_stop_timer(scsi_qla_host_t *vha)
199 del_timer_sync(&vha->timer);
200 vha->timer_active = 0;
203 static int qla2x00_do_dpc(void *data);
205 static void qla2x00_rst_aen(scsi_qla_host_t *);
207 static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
208 struct req_que **, struct rsp_que **);
209 static void qla2x00_mem_free(struct qla_hw_data *);
210 static void qla2x00_sp_free_dma(srb_t *);
212 /* -------------------------------------------------------------------------- */
213 static int qla2x00_alloc_queues(struct qla_hw_data *ha)
215 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
217 if (!ha->req_q_map) {
218 qla_printk(KERN_WARNING, ha,
219 "Unable to allocate memory for request queue ptrs\n");
223 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
225 if (!ha->rsp_q_map) {
226 qla_printk(KERN_WARNING, ha,
227 "Unable to allocate memory for response queue ptrs\n");
230 set_bit(0, ha->rsp_qid_map);
231 set_bit(0, ha->req_qid_map);
235 kfree(ha->req_q_map);
236 ha->req_q_map = NULL;
241 static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
243 if (req && req->ring)
244 dma_free_coherent(&ha->pdev->dev,
245 (req->length + 1) * sizeof(request_t),
246 req->ring, req->dma);
252 static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
254 if (rsp && rsp->ring)
255 dma_free_coherent(&ha->pdev->dev,
256 (rsp->length + 1) * sizeof(response_t),
257 rsp->ring, rsp->dma);
263 static void qla2x00_free_queues(struct qla_hw_data *ha)
269 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
270 req = ha->req_q_map[cnt];
271 qla2x00_free_req_que(ha, req);
273 kfree(ha->req_q_map);
274 ha->req_q_map = NULL;
276 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
277 rsp = ha->rsp_q_map[cnt];
278 qla2x00_free_rsp_que(ha, rsp);
280 kfree(ha->rsp_q_map);
281 ha->rsp_q_map = NULL;
284 static int qla25xx_setup_mode(struct scsi_qla_host *vha)
286 uint16_t options = 0;
288 struct qla_hw_data *ha = vha->hw;
290 if (!(ha->fw_attributes & BIT_6)) {
291 qla_printk(KERN_INFO, ha,
292 "Firmware is not multi-queue capable\n");
295 if (ql2xmultique_tag) {
296 /* create a request queue for IO */
298 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
299 QLA_DEFAULT_QUE_QOS);
301 qla_printk(KERN_WARNING, ha,
302 "Can't create request queue\n");
305 ha->wq = create_workqueue("qla2xxx_wq");
306 vha->req = ha->req_q_map[req];
308 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
309 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
311 qla_printk(KERN_WARNING, ha,
312 "Response Queue create failed\n");
316 ha->flags.cpu_affinity_enabled = 1;
318 DEBUG2(qla_printk(KERN_INFO, ha,
319 "CPU affinity mode enabled, no. of response"
320 " queues:%d, no. of request queues:%d\n",
321 ha->max_rsp_queues, ha->max_req_queues));
325 qla25xx_delete_queues(vha);
326 destroy_workqueue(ha->wq);
330 kfree(ha->req_q_map);
331 kfree(ha->rsp_q_map);
332 ha->max_req_queues = ha->max_rsp_queues = 1;
337 qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
339 struct qla_hw_data *ha = vha->hw;
340 static char *pci_bus_modes[] = {
341 "33", "66", "100", "133",
346 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
349 strcat(str, pci_bus_modes[pci_bus]);
351 pci_bus = (ha->pci_attr & BIT_8) >> 8;
353 strcat(str, pci_bus_modes[pci_bus]);
355 strcat(str, " MHz)");
361 qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
363 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
364 struct qla_hw_data *ha = vha->hw;
368 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
371 uint16_t pcie_lstat, lspeed, lwidth;
374 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
375 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
376 lwidth = (pcie_lstat &
377 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
379 strcpy(str, "PCIe (");
381 strcat(str, "2.5GT/s ");
382 else if (lspeed == 2)
383 strcat(str, "5.0GT/s ");
385 strcat(str, "<unknown> ");
386 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
393 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
394 if (pci_bus == 0 || pci_bus == 8) {
396 strcat(str, pci_bus_modes[pci_bus >> 3]);
400 strcat(str, "Mode 2");
402 strcat(str, "Mode 1");
404 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
406 strcat(str, " MHz)");
412 qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
415 struct qla_hw_data *ha = vha->hw;
417 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
418 ha->fw_minor_version,
419 ha->fw_subminor_version);
421 if (ha->fw_attributes & BIT_9) {
426 switch (ha->fw_attributes & 0xFF) {
440 sprintf(un_str, "(%x)", ha->fw_attributes);
444 if (ha->fw_attributes & 0x100)
451 qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
453 struct qla_hw_data *ha = vha->hw;
455 sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
456 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
460 static inline srb_t *
461 qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
462 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
465 struct qla_hw_data *ha = vha->hw;
467 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
474 CMD_SP(cmd) = (void *)sp;
475 cmd->scsi_done = done;
482 qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
484 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
485 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
486 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
487 struct qla_hw_data *ha = vha->hw;
488 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
492 if (unlikely(pci_channel_offline(ha->pdev))) {
493 if (ha->pdev->error_state == pci_channel_io_frozen)
494 cmd->result = DID_REQUEUE << 16;
496 cmd->result = DID_NO_CONNECT << 16;
497 goto qc24_fail_command;
500 rval = fc_remote_port_chkready(rport);
503 goto qc24_fail_command;
506 /* Close window on fcport/rport state-transitioning. */
508 goto qc24_target_busy;
510 if (atomic_read(&fcport->state) != FCS_ONLINE) {
511 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
512 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
513 cmd->result = DID_NO_CONNECT << 16;
514 goto qc24_fail_command;
516 goto qc24_target_busy;
519 spin_unlock_irq(vha->host->host_lock);
521 sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
523 goto qc24_host_busy_lock;
525 rval = ha->isp_ops->start_scsi(sp);
526 if (rval != QLA_SUCCESS)
527 goto qc24_host_busy_free_sp;
529 spin_lock_irq(vha->host->host_lock);
533 qc24_host_busy_free_sp:
534 qla2x00_sp_free_dma(sp);
535 mempool_free(sp, ha->srb_mempool);
538 spin_lock_irq(vha->host->host_lock);
539 return SCSI_MLQUEUE_HOST_BUSY;
542 return SCSI_MLQUEUE_TARGET_BUSY;
552 * qla2x00_eh_wait_on_command
553 * Waits for the command to be returned by the Firmware for some
557 * cmd = Scsi Command to wait on.
564 qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
566 #define ABORT_POLLING_PERIOD 1000
567 #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
568 unsigned long wait_iter = ABORT_WAIT_ITER;
569 int ret = QLA_SUCCESS;
571 while (CMD_SP(cmd) && wait_iter--) {
572 msleep(ABORT_POLLING_PERIOD);
575 ret = QLA_FUNCTION_FAILED;
581 * qla2x00_wait_for_hba_online
582 * Wait till the HBA is online after going through
583 * <= MAX_RETRIES_OF_ISP_ABORT or
584 * finally HBA is disabled ie marked offline
587 * ha - pointer to host adapter structure
590 * Does context switching-Release SPIN_LOCK
591 * (if any) before calling this routine.
594 * Success (Adapter is online) : 0
595 * Failed (Adapter is offline/disabled) : 1
598 qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
601 unsigned long wait_online;
602 struct qla_hw_data *ha = vha->hw;
603 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
605 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
606 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
607 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
608 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
609 ha->dpc_active) && time_before(jiffies, wait_online)) {
613 if (base_vha->flags.online)
614 return_status = QLA_SUCCESS;
616 return_status = QLA_FUNCTION_FAILED;
618 return (return_status);
622 qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
625 unsigned long wait_reset;
626 struct qla_hw_data *ha = vha->hw;
627 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
629 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
630 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
631 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
632 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
633 ha->dpc_active) && time_before(jiffies, wait_reset)) {
637 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
638 ha->flags.chip_reset_done)
641 if (ha->flags.chip_reset_done)
642 return_status = QLA_SUCCESS;
644 return_status = QLA_FUNCTION_FAILED;
646 return return_status;
650 * qla2x00_wait_for_loop_ready
651 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
652 * to be in LOOP_READY state.
654 * ha - pointer to host adapter structure
657 * Does context switching-Release SPIN_LOCK
658 * (if any) before calling this routine.
662 * Success (LOOP_READY) : 0
663 * Failed (LOOP_NOT_READY) : 1
666 qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
668 int return_status = QLA_SUCCESS;
669 unsigned long loop_timeout ;
670 struct qla_hw_data *ha = vha->hw;
671 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
673 /* wait for 5 min at the max for loop to be ready */
674 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
676 while ((!atomic_read(&base_vha->loop_down_timer) &&
677 atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
678 atomic_read(&base_vha->loop_state) != LOOP_READY) {
679 if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
680 return_status = QLA_FUNCTION_FAILED;
684 if (time_after_eq(jiffies, loop_timeout)) {
685 return_status = QLA_FUNCTION_FAILED;
689 return (return_status);
693 qla2x00_abort_fcport_cmds(fc_port_t *fcport)
698 scsi_qla_host_t *vha = fcport->vha;
699 struct qla_hw_data *ha = vha->hw;
702 spin_lock_irqsave(&ha->hardware_lock, flags);
704 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
705 sp = req->outstanding_cmds[cnt];
708 if (sp->fcport != fcport)
713 spin_unlock_irqrestore(&ha->hardware_lock, flags);
714 if (ha->isp_ops->abort_command(sp)) {
715 DEBUG2(qla_printk(KERN_WARNING, ha,
716 "Abort failed -- %lx\n",
717 sp->cmd->serial_number));
719 if (qla2x00_eh_wait_on_command(sp->cmd) !=
721 DEBUG2(qla_printk(KERN_WARNING, ha,
722 "Abort failed while waiting -- %lx\n",
723 sp->cmd->serial_number));
725 spin_lock_irqsave(&ha->hardware_lock, flags);
727 spin_unlock_irqrestore(&ha->hardware_lock, flags);
731 qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
733 struct Scsi_Host *shost = cmnd->device->host;
734 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
737 spin_lock_irqsave(shost->host_lock, flags);
738 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
739 spin_unlock_irqrestore(shost->host_lock, flags);
741 spin_lock_irqsave(shost->host_lock, flags);
743 spin_unlock_irqrestore(shost->host_lock, flags);
747 /**************************************************************************
751 * The abort function will abort the specified command.
754 * cmd = Linux SCSI command packet to be aborted.
757 * Either SUCCESS or FAILED.
760 * Only return FAILED if command not returned by firmware.
761 **************************************************************************/
763 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
765 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
768 unsigned int id, lun;
769 unsigned long serial;
772 struct qla_hw_data *ha = vha->hw;
773 struct req_que *req = vha->req;
776 qla2x00_block_error_handler(cmd);
783 id = cmd->device->id;
784 lun = cmd->device->lun;
785 serial = cmd->serial_number;
786 spt = (srb_t *) CMD_SP(cmd);
790 /* Check active list for command command. */
791 spin_lock_irqsave(&ha->hardware_lock, flags);
792 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
793 sp = req->outstanding_cmds[i];
802 DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
803 " pid=%ld.\n", __func__, vha->host_no, sp, serial));
805 spin_unlock_irqrestore(&ha->hardware_lock, flags);
806 if (ha->isp_ops->abort_command(sp)) {
807 DEBUG2(printk("%s(%ld): abort_command "
808 "mbx failed.\n", __func__, vha->host_no));
811 DEBUG3(printk("%s(%ld): abort_command "
812 "mbx success.\n", __func__, vha->host_no));
815 spin_lock_irqsave(&ha->hardware_lock, flags);
818 spin_unlock_irqrestore(&ha->hardware_lock, flags);
820 /* Wait for the command to be returned. */
822 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
823 qla_printk(KERN_ERR, ha,
824 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
825 "%x.\n", vha->host_no, id, lun, serial, ret);
830 qla_printk(KERN_INFO, ha,
831 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
832 vha->host_no, id, lun, wait, serial, ret);
837 enum nexus_wait_type {
844 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
845 unsigned int l, srb_t *sp, enum nexus_wait_type type)
847 int cnt, match, status;
849 struct qla_hw_data *ha = vha->hw;
852 status = QLA_SUCCESS;
856 spin_lock_irqsave(&ha->hardware_lock, flags);
858 for (cnt = 1; status == QLA_SUCCESS &&
859 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
860 sp = req->outstanding_cmds[cnt];
865 if (vha->vp_idx != sp->fcport->vha->vp_idx)
873 match = sp->cmd->device->id == t;
876 match = (sp->cmd->device->id == t &&
877 sp->cmd->device->lun == l);
883 spin_unlock_irqrestore(&ha->hardware_lock, flags);
884 status = qla2x00_eh_wait_on_command(sp->cmd);
885 spin_lock_irqsave(&ha->hardware_lock, flags);
887 spin_unlock_irqrestore(&ha->hardware_lock, flags);
892 static char *reset_errors[] = {
895 "Task management failed",
896 "Waiting for command completions",
900 __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
901 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
903 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
904 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
907 qla2x00_block_error_handler(cmd);
912 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
913 vha->host_no, cmd->device->id, cmd->device->lun, name);
916 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
917 goto eh_reset_failed;
919 if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
920 goto eh_reset_failed;
922 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
924 goto eh_reset_failed;
926 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
927 cmd->device->lun, (srb_t *) CMD_SP(cmd), type) != QLA_SUCCESS)
928 goto eh_reset_failed;
930 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
931 vha->host_no, cmd->device->id, cmd->device->lun, name);
936 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
937 , vha->host_no, cmd->device->id, cmd->device->lun, name,
943 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
945 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
946 struct qla_hw_data *ha = vha->hw;
948 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
949 ha->isp_ops->lun_reset);
953 qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
955 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
956 struct qla_hw_data *ha = vha->hw;
958 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
959 ha->isp_ops->target_reset);
962 /**************************************************************************
963 * qla2xxx_eh_bus_reset
966 * The bus reset function will reset the bus and abort any executing
970 * cmd = Linux SCSI command packet of the command that cause the
974 * SUCCESS/FAILURE (defined as macro in scsi.h).
976 **************************************************************************/
978 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
980 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
981 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
983 unsigned int id, lun;
984 unsigned long serial;
985 srb_t *sp = (srb_t *) CMD_SP(cmd);
987 qla2x00_block_error_handler(cmd);
989 id = cmd->device->id;
990 lun = cmd->device->lun;
991 serial = cmd->serial_number;
996 qla_printk(KERN_INFO, vha->hw,
997 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
999 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1000 DEBUG2(printk("%s failed:board disabled\n",__func__));
1001 goto eh_bus_reset_done;
1004 if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
1005 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1009 goto eh_bus_reset_done;
1011 /* Flush outstanding commands. */
1012 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) !=
1017 qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
1018 (ret == FAILED) ? "failed" : "succeded");
1023 /**************************************************************************
1024 * qla2xxx_eh_host_reset
1027 * The reset function will reset the Adapter.
1030 * cmd = Linux SCSI command packet of the command that cause the
1034 * Either SUCCESS or FAILED.
1037 **************************************************************************/
1039 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1041 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1042 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1043 struct qla_hw_data *ha = vha->hw;
1045 unsigned int id, lun;
1046 unsigned long serial;
1047 srb_t *sp = (srb_t *) CMD_SP(cmd);
1048 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1050 qla2x00_block_error_handler(cmd);
1052 id = cmd->device->id;
1053 lun = cmd->device->lun;
1054 serial = cmd->serial_number;
1059 qla_printk(KERN_INFO, ha,
1060 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
1062 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1063 goto eh_host_reset_lock;
1066 * Fixme-may be dpc thread is active and processing
1067 * loop_resync,so wait a while for it to
1068 * be completed and then issue big hammer.Otherwise
1069 * it may cause I/O failure as big hammer marks the
1070 * devices as lost kicking of the port_down_timer
1071 * while dpc is stuck for the mailbox to complete.
1073 qla2x00_wait_for_loop_ready(vha);
1074 if (vha != base_vha) {
1075 if (qla2x00_vp_abort_isp(vha))
1076 goto eh_host_reset_lock;
1079 flush_workqueue(ha->wq);
1081 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1082 if (qla2x00_abort_isp(base_vha)) {
1083 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1084 /* failed. schedule dpc to try */
1085 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1087 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1088 goto eh_host_reset_lock;
1090 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1093 /* Waiting for command to be returned to OS.*/
1094 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) ==
1099 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1100 (ret == FAILED) ? "failed" : "succeded");
1106 * qla2x00_loop_reset
1110 * ha = adapter block pointer.
1116 qla2x00_loop_reset(scsi_qla_host_t *vha)
1119 struct fc_port *fcport;
1120 struct qla_hw_data *ha = vha->hw;
1122 if (ha->flags.enable_lip_full_login && !vha->vp_idx &&
1124 ret = qla2x00_full_login_lip(vha);
1125 if (ret != QLA_SUCCESS) {
1126 DEBUG2_3(printk("%s(%ld): failed: "
1127 "full_login_lip=%d.\n", __func__, vha->host_no,
1130 atomic_set(&vha->loop_state, LOOP_DOWN);
1131 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1132 qla2x00_mark_all_devices_lost(vha, 0);
1133 qla2x00_wait_for_loop_ready(vha);
1136 if (ha->flags.enable_lip_reset && !vha->vp_idx) {
1137 ret = qla2x00_lip_reset(vha);
1138 if (ret != QLA_SUCCESS) {
1139 DEBUG2_3(printk("%s(%ld): failed: "
1140 "lip_reset=%d.\n", __func__, vha->host_no, ret));
1142 qla2x00_wait_for_loop_ready(vha);
1145 if (ha->flags.enable_target_reset) {
1146 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1147 if (fcport->port_type != FCT_TARGET)
1150 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1151 if (ret != QLA_SUCCESS) {
1152 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1153 "target_reset=%d d_id=%x.\n", __func__,
1154 vha->host_no, ret, fcport->d_id.b24));
1158 /* Issue marker command only when we are going to start the I/O */
1159 vha->marker_needed = 1;
1165 qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1168 unsigned long flags;
1170 struct srb_ctx *ctx;
1171 struct qla_hw_data *ha = vha->hw;
1172 struct req_que *req;
1174 spin_lock_irqsave(&ha->hardware_lock, flags);
1175 for (que = 0; que < ha->max_req_queues; que++) {
1176 req = ha->req_q_map[que];
1179 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1180 sp = req->outstanding_cmds[cnt];
1182 req->outstanding_cmds[cnt] = NULL;
1184 sp->cmd->result = res;
1185 qla2x00_sp_compl(ha, sp);
1188 del_timer_sync(&ctx->timer);
1194 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1198 qla2xxx_slave_alloc(struct scsi_device *sdev)
1200 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1202 if (!rport || fc_remote_port_chkready(rport))
1205 sdev->hostdata = *(fc_port_t **)rport->dd_data;
1211 qla2xxx_slave_configure(struct scsi_device *sdev)
1213 scsi_qla_host_t *vha = shost_priv(sdev->host);
1214 struct qla_hw_data *ha = vha->hw;
1215 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1216 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1217 struct req_que *req = vha->req;
1219 if (sdev->tagged_supported)
1220 scsi_activate_tcq(sdev, req->max_q_depth);
1222 scsi_deactivate_tcq(sdev, req->max_q_depth);
1224 rport->dev_loss_tmo = ha->port_down_retry_count;
1225 if (sdev->type == TYPE_TAPE)
1226 fcport->flags |= FCF_TAPE_PRESENT;
1232 qla2xxx_slave_destroy(struct scsi_device *sdev)
1234 sdev->hostdata = NULL;
1238 qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1240 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1241 return sdev->queue_depth;
1245 qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1247 if (sdev->tagged_supported) {
1248 scsi_set_tag_type(sdev, tag_type);
1250 scsi_activate_tcq(sdev, sdev->queue_depth);
1252 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1260 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1263 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1264 * supported addressing method.
1267 qla2x00_config_dma_addressing(struct qla_hw_data *ha)
1269 /* Assume a 32bit DMA mask. */
1270 ha->flags.enable_64bit_addressing = 0;
1272 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1273 /* Any upper-dword bits set? */
1274 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1275 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
1276 /* Ok, a 64bit DMA mask is applicable. */
1277 ha->flags.enable_64bit_addressing = 1;
1278 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1279 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
1284 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1285 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
1289 qla2x00_enable_intrs(struct qla_hw_data *ha)
1291 unsigned long flags = 0;
1292 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1294 spin_lock_irqsave(&ha->hardware_lock, flags);
1295 ha->interrupts_on = 1;
1296 /* enable risc and host interrupts */
1297 WRT_REG_WORD(®->ictrl, ICR_EN_INT | ICR_EN_RISC);
1298 RD_REG_WORD(®->ictrl);
1299 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1304 qla2x00_disable_intrs(struct qla_hw_data *ha)
1306 unsigned long flags = 0;
1307 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1309 spin_lock_irqsave(&ha->hardware_lock, flags);
1310 ha->interrupts_on = 0;
1311 /* disable risc and host interrupts */
1312 WRT_REG_WORD(®->ictrl, 0);
1313 RD_REG_WORD(®->ictrl);
1314 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1318 qla24xx_enable_intrs(struct qla_hw_data *ha)
1320 unsigned long flags = 0;
1321 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1323 spin_lock_irqsave(&ha->hardware_lock, flags);
1324 ha->interrupts_on = 1;
1325 WRT_REG_DWORD(®->ictrl, ICRX_EN_RISC_INT);
1326 RD_REG_DWORD(®->ictrl);
1327 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1331 qla24xx_disable_intrs(struct qla_hw_data *ha)
1333 unsigned long flags = 0;
1334 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1336 if (IS_NOPOLLING_TYPE(ha))
1338 spin_lock_irqsave(&ha->hardware_lock, flags);
1339 ha->interrupts_on = 0;
1340 WRT_REG_DWORD(®->ictrl, 0);
1341 RD_REG_DWORD(®->ictrl);
1342 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1345 static struct isp_operations qla2100_isp_ops = {
1346 .pci_config = qla2100_pci_config,
1347 .reset_chip = qla2x00_reset_chip,
1348 .chip_diag = qla2x00_chip_diag,
1349 .config_rings = qla2x00_config_rings,
1350 .reset_adapter = qla2x00_reset_adapter,
1351 .nvram_config = qla2x00_nvram_config,
1352 .update_fw_options = qla2x00_update_fw_options,
1353 .load_risc = qla2x00_load_risc,
1354 .pci_info_str = qla2x00_pci_info_str,
1355 .fw_version_str = qla2x00_fw_version_str,
1356 .intr_handler = qla2100_intr_handler,
1357 .enable_intrs = qla2x00_enable_intrs,
1358 .disable_intrs = qla2x00_disable_intrs,
1359 .abort_command = qla2x00_abort_command,
1360 .target_reset = qla2x00_abort_target,
1361 .lun_reset = qla2x00_lun_reset,
1362 .fabric_login = qla2x00_login_fabric,
1363 .fabric_logout = qla2x00_fabric_logout,
1364 .calc_req_entries = qla2x00_calc_iocbs_32,
1365 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1366 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1367 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1368 .read_nvram = qla2x00_read_nvram_data,
1369 .write_nvram = qla2x00_write_nvram_data,
1370 .fw_dump = qla2100_fw_dump,
1373 .beacon_blink = NULL,
1374 .read_optrom = qla2x00_read_optrom_data,
1375 .write_optrom = qla2x00_write_optrom_data,
1376 .get_flash_version = qla2x00_get_flash_version,
1377 .start_scsi = qla2x00_start_scsi,
1380 static struct isp_operations qla2300_isp_ops = {
1381 .pci_config = qla2300_pci_config,
1382 .reset_chip = qla2x00_reset_chip,
1383 .chip_diag = qla2x00_chip_diag,
1384 .config_rings = qla2x00_config_rings,
1385 .reset_adapter = qla2x00_reset_adapter,
1386 .nvram_config = qla2x00_nvram_config,
1387 .update_fw_options = qla2x00_update_fw_options,
1388 .load_risc = qla2x00_load_risc,
1389 .pci_info_str = qla2x00_pci_info_str,
1390 .fw_version_str = qla2x00_fw_version_str,
1391 .intr_handler = qla2300_intr_handler,
1392 .enable_intrs = qla2x00_enable_intrs,
1393 .disable_intrs = qla2x00_disable_intrs,
1394 .abort_command = qla2x00_abort_command,
1395 .target_reset = qla2x00_abort_target,
1396 .lun_reset = qla2x00_lun_reset,
1397 .fabric_login = qla2x00_login_fabric,
1398 .fabric_logout = qla2x00_fabric_logout,
1399 .calc_req_entries = qla2x00_calc_iocbs_32,
1400 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1401 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1402 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1403 .read_nvram = qla2x00_read_nvram_data,
1404 .write_nvram = qla2x00_write_nvram_data,
1405 .fw_dump = qla2300_fw_dump,
1406 .beacon_on = qla2x00_beacon_on,
1407 .beacon_off = qla2x00_beacon_off,
1408 .beacon_blink = qla2x00_beacon_blink,
1409 .read_optrom = qla2x00_read_optrom_data,
1410 .write_optrom = qla2x00_write_optrom_data,
1411 .get_flash_version = qla2x00_get_flash_version,
1412 .start_scsi = qla2x00_start_scsi,
1415 static struct isp_operations qla24xx_isp_ops = {
1416 .pci_config = qla24xx_pci_config,
1417 .reset_chip = qla24xx_reset_chip,
1418 .chip_diag = qla24xx_chip_diag,
1419 .config_rings = qla24xx_config_rings,
1420 .reset_adapter = qla24xx_reset_adapter,
1421 .nvram_config = qla24xx_nvram_config,
1422 .update_fw_options = qla24xx_update_fw_options,
1423 .load_risc = qla24xx_load_risc,
1424 .pci_info_str = qla24xx_pci_info_str,
1425 .fw_version_str = qla24xx_fw_version_str,
1426 .intr_handler = qla24xx_intr_handler,
1427 .enable_intrs = qla24xx_enable_intrs,
1428 .disable_intrs = qla24xx_disable_intrs,
1429 .abort_command = qla24xx_abort_command,
1430 .target_reset = qla24xx_abort_target,
1431 .lun_reset = qla24xx_lun_reset,
1432 .fabric_login = qla24xx_login_fabric,
1433 .fabric_logout = qla24xx_fabric_logout,
1434 .calc_req_entries = NULL,
1435 .build_iocbs = NULL,
1436 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1437 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1438 .read_nvram = qla24xx_read_nvram_data,
1439 .write_nvram = qla24xx_write_nvram_data,
1440 .fw_dump = qla24xx_fw_dump,
1441 .beacon_on = qla24xx_beacon_on,
1442 .beacon_off = qla24xx_beacon_off,
1443 .beacon_blink = qla24xx_beacon_blink,
1444 .read_optrom = qla24xx_read_optrom_data,
1445 .write_optrom = qla24xx_write_optrom_data,
1446 .get_flash_version = qla24xx_get_flash_version,
1447 .start_scsi = qla24xx_start_scsi,
1450 static struct isp_operations qla25xx_isp_ops = {
1451 .pci_config = qla25xx_pci_config,
1452 .reset_chip = qla24xx_reset_chip,
1453 .chip_diag = qla24xx_chip_diag,
1454 .config_rings = qla24xx_config_rings,
1455 .reset_adapter = qla24xx_reset_adapter,
1456 .nvram_config = qla24xx_nvram_config,
1457 .update_fw_options = qla24xx_update_fw_options,
1458 .load_risc = qla24xx_load_risc,
1459 .pci_info_str = qla24xx_pci_info_str,
1460 .fw_version_str = qla24xx_fw_version_str,
1461 .intr_handler = qla24xx_intr_handler,
1462 .enable_intrs = qla24xx_enable_intrs,
1463 .disable_intrs = qla24xx_disable_intrs,
1464 .abort_command = qla24xx_abort_command,
1465 .target_reset = qla24xx_abort_target,
1466 .lun_reset = qla24xx_lun_reset,
1467 .fabric_login = qla24xx_login_fabric,
1468 .fabric_logout = qla24xx_fabric_logout,
1469 .calc_req_entries = NULL,
1470 .build_iocbs = NULL,
1471 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1472 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1473 .read_nvram = qla25xx_read_nvram_data,
1474 .write_nvram = qla25xx_write_nvram_data,
1475 .fw_dump = qla25xx_fw_dump,
1476 .beacon_on = qla24xx_beacon_on,
1477 .beacon_off = qla24xx_beacon_off,
1478 .beacon_blink = qla24xx_beacon_blink,
1479 .read_optrom = qla25xx_read_optrom_data,
1480 .write_optrom = qla24xx_write_optrom_data,
1481 .get_flash_version = qla24xx_get_flash_version,
1482 .start_scsi = qla24xx_start_scsi,
1485 static struct isp_operations qla81xx_isp_ops = {
1486 .pci_config = qla25xx_pci_config,
1487 .reset_chip = qla24xx_reset_chip,
1488 .chip_diag = qla24xx_chip_diag,
1489 .config_rings = qla24xx_config_rings,
1490 .reset_adapter = qla24xx_reset_adapter,
1491 .nvram_config = qla81xx_nvram_config,
1492 .update_fw_options = qla81xx_update_fw_options,
1493 .load_risc = qla81xx_load_risc,
1494 .pci_info_str = qla24xx_pci_info_str,
1495 .fw_version_str = qla24xx_fw_version_str,
1496 .intr_handler = qla24xx_intr_handler,
1497 .enable_intrs = qla24xx_enable_intrs,
1498 .disable_intrs = qla24xx_disable_intrs,
1499 .abort_command = qla24xx_abort_command,
1500 .target_reset = qla24xx_abort_target,
1501 .lun_reset = qla24xx_lun_reset,
1502 .fabric_login = qla24xx_login_fabric,
1503 .fabric_logout = qla24xx_fabric_logout,
1504 .calc_req_entries = NULL,
1505 .build_iocbs = NULL,
1506 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1507 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1509 .write_nvram = NULL,
1510 .fw_dump = qla81xx_fw_dump,
1511 .beacon_on = qla24xx_beacon_on,
1512 .beacon_off = qla24xx_beacon_off,
1513 .beacon_blink = qla24xx_beacon_blink,
1514 .read_optrom = qla25xx_read_optrom_data,
1515 .write_optrom = qla24xx_write_optrom_data,
1516 .get_flash_version = qla24xx_get_flash_version,
1517 .start_scsi = qla24xx_start_scsi,
1521 qla2x00_set_isp_flags(struct qla_hw_data *ha)
1523 ha->device_type = DT_EXTENDED_IDS;
1524 switch (ha->pdev->device) {
1525 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1526 ha->device_type |= DT_ISP2100;
1527 ha->device_type &= ~DT_EXTENDED_IDS;
1528 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
1530 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1531 ha->device_type |= DT_ISP2200;
1532 ha->device_type &= ~DT_EXTENDED_IDS;
1533 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
1535 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1536 ha->device_type |= DT_ISP2300;
1537 ha->device_type |= DT_ZIO_SUPPORTED;
1538 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1540 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1541 ha->device_type |= DT_ISP2312;
1542 ha->device_type |= DT_ZIO_SUPPORTED;
1543 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1545 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1546 ha->device_type |= DT_ISP2322;
1547 ha->device_type |= DT_ZIO_SUPPORTED;
1548 if (ha->pdev->subsystem_vendor == 0x1028 &&
1549 ha->pdev->subsystem_device == 0x0170)
1550 ha->device_type |= DT_OEM_001;
1551 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1553 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1554 ha->device_type |= DT_ISP6312;
1555 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1557 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1558 ha->device_type |= DT_ISP6322;
1559 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1561 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1562 ha->device_type |= DT_ISP2422;
1563 ha->device_type |= DT_ZIO_SUPPORTED;
1564 ha->device_type |= DT_FWI2;
1565 ha->device_type |= DT_IIDMA;
1566 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1568 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1569 ha->device_type |= DT_ISP2432;
1570 ha->device_type |= DT_ZIO_SUPPORTED;
1571 ha->device_type |= DT_FWI2;
1572 ha->device_type |= DT_IIDMA;
1573 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1575 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1576 ha->device_type |= DT_ISP8432;
1577 ha->device_type |= DT_ZIO_SUPPORTED;
1578 ha->device_type |= DT_FWI2;
1579 ha->device_type |= DT_IIDMA;
1580 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1582 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1583 ha->device_type |= DT_ISP5422;
1584 ha->device_type |= DT_FWI2;
1585 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1587 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1588 ha->device_type |= DT_ISP5432;
1589 ha->device_type |= DT_FWI2;
1590 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1592 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1593 ha->device_type |= DT_ISP2532;
1594 ha->device_type |= DT_ZIO_SUPPORTED;
1595 ha->device_type |= DT_FWI2;
1596 ha->device_type |= DT_IIDMA;
1597 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1599 case PCI_DEVICE_ID_QLOGIC_ISP8001:
1600 ha->device_type |= DT_ISP8001;
1601 ha->device_type |= DT_ZIO_SUPPORTED;
1602 ha->device_type |= DT_FWI2;
1603 ha->device_type |= DT_IIDMA;
1604 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1608 /* Get adapter physical port no from interrupt pin register. */
1609 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
1610 if (ha->port_no & 1)
1611 ha->flags.port0 = 1;
1613 ha->flags.port0 = 0;
1617 qla2x00_iospace_config(struct qla_hw_data *ha)
1619 resource_size_t pio;
1623 if (pci_request_selected_regions(ha->pdev, ha->bars,
1624 QLA2XXX_DRIVER_NAME)) {
1625 qla_printk(KERN_WARNING, ha,
1626 "Failed to reserve PIO/MMIO regions (%s)\n",
1627 pci_name(ha->pdev));
1629 goto iospace_error_exit;
1631 if (!(ha->bars & 1))
1634 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1635 pio = pci_resource_start(ha->pdev, 0);
1636 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1637 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1638 qla_printk(KERN_WARNING, ha,
1639 "Invalid PCI I/O region size (%s)...\n",
1640 pci_name(ha->pdev));
1644 qla_printk(KERN_WARNING, ha,
1645 "region #0 not a PIO resource (%s)...\n",
1646 pci_name(ha->pdev));
1649 ha->pio_address = pio;
1652 /* Use MMIO operations for all accesses. */
1653 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1654 qla_printk(KERN_ERR, ha,
1655 "region #1 not an MMIO resource (%s), aborting\n",
1656 pci_name(ha->pdev));
1657 goto iospace_error_exit;
1659 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1660 qla_printk(KERN_ERR, ha,
1661 "Invalid PCI mem region size (%s), aborting\n",
1662 pci_name(ha->pdev));
1663 goto iospace_error_exit;
1666 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1668 qla_printk(KERN_ERR, ha,
1669 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1671 goto iospace_error_exit;
1674 /* Determine queue resources */
1675 ha->max_req_queues = ha->max_rsp_queues = 1;
1676 if ((ql2xmaxqueues <= 1 || ql2xmultique_tag < 1) &&
1677 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1679 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1680 pci_resource_len(ha->pdev, 3));
1682 /* Read MSIX vector size of the board */
1683 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1684 ha->msix_count = msix;
1685 /* Max queues are bounded by available msix vectors */
1686 /* queue 0 uses two msix vectors */
1687 if (ql2xmultique_tag) {
1688 cpus = num_online_cpus();
1689 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1690 (cpus + 1) : (ha->msix_count - 1);
1691 ha->max_req_queues = 2;
1692 } else if (ql2xmaxqueues > 1) {
1693 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1694 QLA_MQ_SIZE : ql2xmaxqueues;
1695 DEBUG2(qla_printk(KERN_INFO, ha, "QoS mode set, max no"
1696 " of request queues:%d\n", ha->max_req_queues));
1698 qla_printk(KERN_INFO, ha,
1699 "MSI-X vector count: %d\n", msix);
1701 qla_printk(KERN_INFO, ha, "BAR 3 not enabled\n");
1704 ha->msix_count = ha->max_rsp_queues + 1;
1712 qla2xxx_scan_start(struct Scsi_Host *shost)
1714 scsi_qla_host_t *vha = shost_priv(shost);
1716 if (vha->hw->flags.running_gold_fw)
1719 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1720 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1721 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1722 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
1726 qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1728 scsi_qla_host_t *vha = shost_priv(shost);
1732 if (time > vha->hw->loop_reset_delay * HZ)
1735 return atomic_read(&vha->loop_state) == LOOP_READY;
1739 * PCI driver interface
1741 static int __devinit
1742 qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1745 struct Scsi_Host *host;
1746 scsi_qla_host_t *base_vha = NULL;
1747 struct qla_hw_data *ha;
1750 struct scsi_host_template *sht;
1751 int bars, max_id, mem_only = 0;
1752 uint16_t req_length = 0, rsp_length = 0;
1753 struct req_que *req = NULL;
1754 struct rsp_que *rsp = NULL;
1756 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
1757 sht = &qla2xxx_driver_template;
1758 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1759 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
1760 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
1761 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1762 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
1763 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
1764 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001) {
1765 bars = pci_select_bars(pdev, IORESOURCE_MEM);
1770 if (pci_enable_device_mem(pdev))
1773 if (pci_enable_device(pdev))
1777 /* This may fail but that's ok */
1778 pci_enable_pcie_error_reporting(pdev);
1780 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
1782 DEBUG(printk("Unable to allocate memory for ha\n"));
1787 /* Clear our data area */
1789 ha->mem_only = mem_only;
1790 spin_lock_init(&ha->hardware_lock);
1792 /* Set ISP-type information. */
1793 qla2x00_set_isp_flags(ha);
1794 /* Configure PCI I/O space */
1795 ret = qla2x00_iospace_config(ha);
1797 goto probe_hw_failed;
1799 qla_printk(KERN_INFO, ha,
1800 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1803 ha->prev_topology = 0;
1804 ha->init_cb_size = sizeof(init_cb_t);
1805 ha->link_data_rate = PORT_SPEED_UNKNOWN;
1806 ha->optrom_size = OPTROM_SIZE_2300;
1808 /* Assign ISP specific operations. */
1809 max_id = MAX_TARGETS_2200;
1810 if (IS_QLA2100(ha)) {
1811 max_id = MAX_TARGETS_2100;
1812 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1813 req_length = REQUEST_ENTRY_CNT_2100;
1814 rsp_length = RESPONSE_ENTRY_CNT_2100;
1815 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
1816 ha->gid_list_info_size = 4;
1817 ha->flash_conf_off = ~0;
1818 ha->flash_data_off = ~0;
1819 ha->nvram_conf_off = ~0;
1820 ha->nvram_data_off = ~0;
1821 ha->isp_ops = &qla2100_isp_ops;
1822 } else if (IS_QLA2200(ha)) {
1823 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1824 req_length = REQUEST_ENTRY_CNT_2200;
1825 rsp_length = RESPONSE_ENTRY_CNT_2100;
1826 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
1827 ha->gid_list_info_size = 4;
1828 ha->flash_conf_off = ~0;
1829 ha->flash_data_off = ~0;
1830 ha->nvram_conf_off = ~0;
1831 ha->nvram_data_off = ~0;
1832 ha->isp_ops = &qla2100_isp_ops;
1833 } else if (IS_QLA23XX(ha)) {
1834 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1835 req_length = REQUEST_ENTRY_CNT_2200;
1836 rsp_length = RESPONSE_ENTRY_CNT_2300;
1837 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1838 ha->gid_list_info_size = 6;
1839 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1840 ha->optrom_size = OPTROM_SIZE_2322;
1841 ha->flash_conf_off = ~0;
1842 ha->flash_data_off = ~0;
1843 ha->nvram_conf_off = ~0;
1844 ha->nvram_data_off = ~0;
1845 ha->isp_ops = &qla2300_isp_ops;
1846 } else if (IS_QLA24XX_TYPE(ha)) {
1847 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1848 req_length = REQUEST_ENTRY_CNT_24XX;
1849 rsp_length = RESPONSE_ENTRY_CNT_2300;
1850 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1851 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1852 ha->gid_list_info_size = 8;
1853 ha->optrom_size = OPTROM_SIZE_24XX;
1854 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
1855 ha->isp_ops = &qla24xx_isp_ops;
1856 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1857 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1858 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1859 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
1860 } else if (IS_QLA25XX(ha)) {
1861 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1862 req_length = REQUEST_ENTRY_CNT_24XX;
1863 rsp_length = RESPONSE_ENTRY_CNT_2300;
1864 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1865 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1866 ha->gid_list_info_size = 8;
1867 ha->optrom_size = OPTROM_SIZE_25XX;
1868 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
1869 ha->isp_ops = &qla25xx_isp_ops;
1870 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1871 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1872 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1873 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
1874 } else if (IS_QLA81XX(ha)) {
1875 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1876 req_length = REQUEST_ENTRY_CNT_24XX;
1877 rsp_length = RESPONSE_ENTRY_CNT_2300;
1878 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1879 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
1880 ha->gid_list_info_size = 8;
1881 ha->optrom_size = OPTROM_SIZE_81XX;
1882 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
1883 ha->isp_ops = &qla81xx_isp_ops;
1884 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
1885 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
1886 ha->nvram_conf_off = ~0;
1887 ha->nvram_data_off = ~0;
1890 mutex_init(&ha->vport_lock);
1891 init_completion(&ha->mbx_cmd_comp);
1892 complete(&ha->mbx_cmd_comp);
1893 init_completion(&ha->mbx_intr_comp);
1895 set_bit(0, (unsigned long *) ha->vp_idx_map);
1897 qla2x00_config_dma_addressing(ha);
1898 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
1900 qla_printk(KERN_WARNING, ha,
1901 "[ERROR] Failed to allocate memory for adapter\n");
1903 goto probe_hw_failed;
1906 req->max_q_depth = MAX_Q_DEPTH;
1907 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
1908 req->max_q_depth = ql2xmaxqdepth;
1911 base_vha = qla2x00_create_host(sht, ha);
1913 qla_printk(KERN_WARNING, ha,
1914 "[ERROR] Failed to allocate memory for scsi_host\n");
1917 qla2x00_mem_free(ha);
1918 qla2x00_free_req_que(ha, req);
1919 qla2x00_free_rsp_que(ha, rsp);
1920 goto probe_hw_failed;
1923 pci_set_drvdata(pdev, base_vha);
1925 host = base_vha->host;
1926 base_vha->req = req;
1927 host->can_queue = req->length + 128;
1928 if (IS_QLA2XXX_MIDTYPE(ha))
1929 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
1931 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
1934 host->sg_tablesize = 32;
1935 host->max_id = max_id;
1936 host->this_id = 255;
1937 host->cmd_per_lun = 3;
1938 host->unique_id = host->host_no;
1939 host->max_cmd_len = MAX_CMDSZ;
1940 host->max_channel = MAX_BUSES - 1;
1941 host->max_lun = MAX_LUNS;
1942 host->transportt = qla2xxx_transport_template;
1944 /* Set up the irqs */
1945 ret = qla2x00_request_irqs(ha, rsp);
1947 goto probe_init_failed;
1948 /* Alloc arrays of request and response ring ptrs */
1950 if (!qla2x00_alloc_queues(ha)) {
1951 qla_printk(KERN_WARNING, ha,
1952 "[ERROR] Failed to allocate memory for queue"
1954 goto probe_init_failed;
1956 ha->rsp_q_map[0] = rsp;
1957 ha->req_q_map[0] = req;
1960 set_bit(0, ha->req_qid_map);
1961 set_bit(0, ha->rsp_qid_map);
1962 /* FWI2-capable only. */
1963 req->req_q_in = &ha->iobase->isp24.req_q_in;
1964 req->req_q_out = &ha->iobase->isp24.req_q_out;
1965 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
1966 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
1968 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
1969 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
1970 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
1971 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
1974 if (qla2x00_initialize_adapter(base_vha)) {
1975 qla_printk(KERN_WARNING, ha,
1976 "Failed to initialize adapter\n");
1978 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1979 "Adapter flags %x.\n",
1980 base_vha->host_no, base_vha->device_flags));
1987 if (qla25xx_setup_mode(base_vha)) {
1988 qla_printk(KERN_WARNING, ha,
1989 "Can't create queues, falling back to single"
1995 if (ha->flags.running_gold_fw)
1999 * Startup the kernel thread for this host adapter
2001 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
2002 "%s_dpc", base_vha->host_str);
2003 if (IS_ERR(ha->dpc_thread)) {
2004 qla_printk(KERN_WARNING, ha,
2005 "Unable to start DPC thread!\n");
2006 ret = PTR_ERR(ha->dpc_thread);
2011 list_add_tail(&base_vha->list, &ha->vp_list);
2012 base_vha->host->irq = ha->pdev->irq;
2014 /* Initialized the timer */
2015 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
2017 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
2018 base_vha->host_no, ha));
2020 base_vha->flags.init_done = 1;
2021 base_vha->flags.online = 1;
2023 ret = scsi_add_host(host, &pdev->dev);
2027 ha->isp_ops->enable_intrs(ha);
2029 scsi_scan_host(host);
2031 qla2x00_alloc_sysfs_attr(base_vha);
2033 qla2x00_init_host_attr(base_vha);
2035 qla2x00_dfs_setup(base_vha);
2037 qla_printk(KERN_INFO, ha, "\n"
2038 " QLogic Fibre Channel HBA Driver: %s\n"
2040 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
2041 qla2x00_version_str, ha->model_number,
2042 ha->model_desc ? ha->model_desc : "", pdev->device,
2043 ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
2044 ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
2045 ha->isp_ops->fw_version_str(base_vha, fw_str));
2050 qla2x00_free_req_que(ha, req);
2051 qla2x00_free_rsp_que(ha, rsp);
2052 ha->max_req_queues = ha->max_rsp_queues = 0;
2055 if (base_vha->timer_active)
2056 qla2x00_stop_timer(base_vha);
2057 base_vha->flags.online = 0;
2058 if (ha->dpc_thread) {
2059 struct task_struct *t = ha->dpc_thread;
2061 ha->dpc_thread = NULL;
2065 qla2x00_free_device(base_vha);
2067 scsi_host_put(base_vha->host);
2071 iounmap(ha->iobase);
2073 pci_release_selected_regions(ha->pdev, ha->bars);
2078 pci_disable_device(pdev);
2083 qla2x00_remove_one(struct pci_dev *pdev)
2085 scsi_qla_host_t *base_vha, *vha, *temp;
2086 struct qla_hw_data *ha;
2088 base_vha = pci_get_drvdata(pdev);
2091 list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
2092 if (vha && vha->fc_vport)
2093 fc_vport_terminate(vha->fc_vport);
2096 set_bit(UNLOADING, &base_vha->dpc_flags);
2098 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2100 qla2x00_dfs_remove(base_vha);
2102 qla84xx_put_chip(base_vha);
2105 if (base_vha->timer_active)
2106 qla2x00_stop_timer(base_vha);
2108 base_vha->flags.online = 0;
2110 /* Flush the work queue and remove it */
2112 flush_workqueue(ha->wq);
2113 destroy_workqueue(ha->wq);
2117 /* Kill the kernel thread for this host */
2118 if (ha->dpc_thread) {
2119 struct task_struct *t = ha->dpc_thread;
2122 * qla2xxx_wake_dpc checks for ->dpc_thread
2123 * so we need to zero it out.
2125 ha->dpc_thread = NULL;
2129 qla2x00_free_sysfs_attr(base_vha);
2131 fc_remove_host(base_vha->host);
2133 scsi_remove_host(base_vha->host);
2135 qla2x00_free_device(base_vha);
2137 scsi_host_put(base_vha->host);
2140 iounmap(ha->iobase);
2143 iounmap(ha->mqiobase);
2145 pci_release_selected_regions(ha->pdev, ha->bars);
2149 pci_disable_device(pdev);
2150 pci_set_drvdata(pdev, NULL);
2154 qla2x00_free_device(scsi_qla_host_t *vha)
2156 struct qla_hw_data *ha = vha->hw;
2158 qla25xx_delete_queues(vha);
2160 if (ha->flags.fce_enabled)
2161 qla2x00_disable_fce_trace(vha, NULL, NULL);
2164 qla2x00_disable_eft_trace(vha);
2166 /* Stop currently executing firmware. */
2167 qla2x00_try_to_stop_firmware(vha);
2169 /* turn-off interrupts on the card */
2170 if (ha->interrupts_on)
2171 ha->isp_ops->disable_intrs(ha);
2173 qla2x00_free_irqs(vha);
2175 qla2x00_mem_free(ha);
2177 qla2x00_free_queues(ha);
2181 qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
2184 struct fc_rport *rport;
2189 rport = fcport->rport;
2191 spin_lock_irq(vha->host->host_lock);
2192 fcport->drport = rport;
2193 spin_unlock_irq(vha->host->host_lock);
2194 set_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
2195 qla2xxx_wake_dpc(vha);
2197 fc_remote_port_delete(rport);
2201 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2203 * Input: ha = adapter block pointer. fcport = port structure pointer.
2209 void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
2210 int do_login, int defer)
2212 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2213 vha->vp_idx == fcport->vp_idx) {
2214 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2215 qla2x00_schedule_rport_del(vha, fcport, defer);
2218 * We may need to retry the login, so don't change the state of the
2219 * port but do the retries.
2221 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2222 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2227 if (fcport->login_retry == 0) {
2228 fcport->login_retry = vha->hw->login_retry_count;
2229 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2231 DEBUG(printk("scsi(%ld): Port login retry: "
2232 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2233 "id = 0x%04x retry cnt=%d\n",
2235 fcport->port_name[0],
2236 fcport->port_name[1],
2237 fcport->port_name[2],
2238 fcport->port_name[3],
2239 fcport->port_name[4],
2240 fcport->port_name[5],
2241 fcport->port_name[6],
2242 fcport->port_name[7],
2244 fcport->login_retry));
2249 * qla2x00_mark_all_devices_lost
2250 * Updates fcport state when device goes offline.
2253 * ha = adapter block pointer.
2254 * fcport = port structure pointer.
2262 qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
2266 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2267 if (vha->vp_idx != fcport->vp_idx)
2270 * No point in marking the device as lost, if the device is
2273 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2275 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2276 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2277 qla2x00_schedule_rport_del(vha, fcport, defer);
2279 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2285 * Allocates adapter memory.
2292 qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2293 struct req_que **req, struct rsp_que **rsp)
2297 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
2298 &ha->init_cb_dma, GFP_KERNEL);
2302 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2303 &ha->gid_list_dma, GFP_KERNEL);
2305 goto fail_free_init_cb;
2307 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2308 if (!ha->srb_mempool)
2309 goto fail_free_gid_list;
2311 /* Get memory for cached NVRAM */
2312 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2314 goto fail_free_srb_mempool;
2316 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2318 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2319 DMA_POOL_SIZE, 8, 0);
2320 if (!ha->s_dma_pool)
2321 goto fail_free_nvram;
2323 /* Allocate memory for SNS commands */
2324 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2325 /* Get consistent memory allocated for SNS commands */
2326 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
2327 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
2331 /* Get consistent memory allocated for MS IOCB */
2332 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2336 /* Get consistent memory allocated for CT SNS commands */
2337 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
2338 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
2340 goto fail_free_ms_iocb;
2343 /* Allocate memory for request ring */
2344 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2346 DEBUG(printk("Unable to allocate memory for req\n"));
2349 (*req)->length = req_len;
2350 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2351 ((*req)->length + 1) * sizeof(request_t),
2352 &(*req)->dma, GFP_KERNEL);
2353 if (!(*req)->ring) {
2354 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2357 /* Allocate memory for response ring */
2358 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2360 qla_printk(KERN_WARNING, ha,
2361 "Unable to allocate memory for rsp\n");
2365 (*rsp)->length = rsp_len;
2366 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2367 ((*rsp)->length + 1) * sizeof(response_t),
2368 &(*rsp)->dma, GFP_KERNEL);
2369 if (!(*rsp)->ring) {
2370 qla_printk(KERN_WARNING, ha,
2371 "Unable to allocate memory for rsp_ring\n");
2376 /* Allocate memory for NVRAM data for vports */
2377 if (ha->nvram_npiv_size) {
2378 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
2379 ha->nvram_npiv_size, GFP_KERNEL);
2380 if (!ha->npiv_info) {
2381 qla_printk(KERN_WARNING, ha,
2382 "Unable to allocate memory for npiv info\n");
2383 goto fail_npiv_info;
2386 ha->npiv_info = NULL;
2388 /* Get consistent memory allocated for EX-INIT-CB. */
2389 if (IS_QLA81XX(ha)) {
2390 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2391 &ha->ex_init_cb_dma);
2392 if (!ha->ex_init_cb)
2393 goto fail_ex_init_cb;
2396 INIT_LIST_HEAD(&ha->vp_list);
2400 kfree(ha->npiv_info);
2402 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2403 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2404 (*rsp)->ring = NULL;
2409 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2410 sizeof(request_t), (*req)->ring, (*req)->dma);
2411 (*req)->ring = NULL;
2416 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2417 ha->ct_sns, ha->ct_sns_dma);
2421 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2423 ha->ms_iocb_dma = 0;
2425 dma_pool_destroy(ha->s_dma_pool);
2426 ha->s_dma_pool = NULL;
2430 fail_free_srb_mempool:
2431 mempool_destroy(ha->srb_mempool);
2432 ha->srb_mempool = NULL;
2434 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2436 ha->gid_list = NULL;
2437 ha->gid_list_dma = 0;
2439 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2442 ha->init_cb_dma = 0;
2444 DEBUG(printk("%s: Memory allocation failure\n", __func__));
2450 * Frees all adapter allocated memory.
2453 * ha = adapter block pointer.
2456 qla2x00_mem_free(struct qla_hw_data *ha)
2458 if (ha->srb_mempool)
2459 mempool_destroy(ha->srb_mempool);
2462 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
2467 dma_free_coherent(&ha->pdev->dev,
2468 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
2473 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
2474 ha->dcbx_tlv, ha->dcbx_tlv_dma);
2477 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
2478 ha->xgmac_data, ha->xgmac_data_dma);
2481 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
2482 ha->sns_cmd, ha->sns_cmd_dma);
2485 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2486 ha->ct_sns, ha->ct_sns_dma);
2489 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2492 dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
2495 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2498 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
2501 dma_pool_destroy(ha->s_dma_pool);
2504 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2508 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2509 ha->init_cb, ha->init_cb_dma);
2510 vfree(ha->optrom_buffer);
2512 kfree(ha->npiv_info);
2514 ha->srb_mempool = NULL;
2518 ha->sns_cmd_dma = 0;
2522 ha->ms_iocb_dma = 0;
2524 ha->init_cb_dma = 0;
2525 ha->ex_init_cb = NULL;
2526 ha->ex_init_cb_dma = 0;
2528 ha->s_dma_pool = NULL;
2530 ha->gid_list = NULL;
2531 ha->gid_list_dma = 0;
2535 ha->fw_dump_reading = 0;
2538 struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
2539 struct qla_hw_data *ha)
2541 struct Scsi_Host *host;
2542 struct scsi_qla_host *vha = NULL;
2544 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
2547 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2551 /* Clear our data area */
2552 vha = shost_priv(host);
2553 memset(vha, 0, sizeof(scsi_qla_host_t));
2556 vha->host_no = host->host_no;
2559 INIT_LIST_HEAD(&vha->vp_fcports);
2560 INIT_LIST_HEAD(&vha->work_list);
2561 INIT_LIST_HEAD(&vha->list);
2563 spin_lock_init(&vha->work_lock);
2565 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
2572 static struct qla_work_evt *
2573 qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
2575 struct qla_work_evt *e;
2577 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
2581 INIT_LIST_HEAD(&e->list);
2583 e->flags = QLA_EVT_FLAG_FREE;
2588 qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
2590 unsigned long flags;
2592 spin_lock_irqsave(&vha->work_lock, flags);
2593 list_add_tail(&e->list, &vha->work_list);
2594 spin_unlock_irqrestore(&vha->work_lock, flags);
2595 qla2xxx_wake_dpc(vha);
2601 qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
2604 struct qla_work_evt *e;
2606 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
2608 return QLA_FUNCTION_FAILED;
2610 e->u.aen.code = code;
2611 e->u.aen.data = data;
2612 return qla2x00_post_work(vha, e);
2616 qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
2618 struct qla_work_evt *e;
2620 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
2622 return QLA_FUNCTION_FAILED;
2624 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
2625 return qla2x00_post_work(vha, e);
2628 #define qla2x00_post_async_work(name, type) \
2629 int qla2x00_post_async_##name##_work( \
2630 struct scsi_qla_host *vha, \
2631 fc_port_t *fcport, uint16_t *data) \
2633 struct qla_work_evt *e; \
2635 e = qla2x00_alloc_work(vha, type); \
2637 return QLA_FUNCTION_FAILED; \
2639 e->u.logio.fcport = fcport; \
2641 e->u.logio.data[0] = data[0]; \
2642 e->u.logio.data[1] = data[1]; \
2644 return qla2x00_post_work(vha, e); \
2647 qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
2648 qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
2649 qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
2650 qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
2653 qla2x00_do_work(struct scsi_qla_host *vha)
2655 struct qla_work_evt *e, *tmp;
2656 unsigned long flags;
2659 spin_lock_irqsave(&vha->work_lock, flags);
2660 list_splice_init(&vha->work_list, &work);
2661 spin_unlock_irqrestore(&vha->work_lock, flags);
2663 list_for_each_entry_safe(e, tmp, &work, list) {
2664 list_del_init(&e->list);
2668 fc_host_post_event(vha->host, fc_get_event_number(),
2669 e->u.aen.code, e->u.aen.data);
2671 case QLA_EVT_IDC_ACK:
2672 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
2674 case QLA_EVT_ASYNC_LOGIN:
2675 qla2x00_async_login(vha, e->u.logio.fcport,
2678 case QLA_EVT_ASYNC_LOGIN_DONE:
2679 qla2x00_async_login_done(vha, e->u.logio.fcport,
2682 case QLA_EVT_ASYNC_LOGOUT:
2683 qla2x00_async_logout(vha, e->u.logio.fcport);
2685 case QLA_EVT_ASYNC_LOGOUT_DONE:
2686 qla2x00_async_logout_done(vha, e->u.logio.fcport,
2690 if (e->flags & QLA_EVT_FLAG_FREE)
2695 /* Relogins all the fcports of a vport
2696 * Context: dpc thread
2698 void qla2x00_relogin(struct scsi_qla_host *vha)
2702 uint16_t next_loopid = 0;
2703 struct qla_hw_data *ha = vha->hw;
2706 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2708 * If the port is not ONLINE then try to login
2709 * to it if we haven't run out of retries.
2711 if (atomic_read(&fcport->state) !=
2712 FCS_ONLINE && fcport->login_retry) {
2714 fcport->login_retry--;
2715 if (fcport->flags & FCF_FABRIC_DEVICE) {
2716 if (fcport->flags & FCF_TAPE_PRESENT)
2717 ha->isp_ops->fabric_logout(vha,
2719 fcport->d_id.b.domain,
2720 fcport->d_id.b.area,
2721 fcport->d_id.b.al_pa);
2723 if (IS_ALOGIO_CAPABLE(ha)) {
2725 data[1] = QLA_LOGIO_LOGIN_RETRIED;
2726 status = qla2x00_post_async_login_work(
2728 if (status == QLA_SUCCESS)
2730 /* Attempt a retry. */
2733 status = qla2x00_fabric_login(vha,
2734 fcport, &next_loopid);
2736 status = qla2x00_local_device_login(vha,
2739 if (status == QLA_SUCCESS) {
2740 fcport->old_loop_id = fcport->loop_id;
2742 DEBUG(printk("scsi(%ld): port login OK: logged "
2743 "in ID 0x%x\n", vha->host_no, fcport->loop_id));
2745 qla2x00_update_fcport(vha, fcport);
2747 } else if (status == 1) {
2748 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2749 /* retry the login again */
2750 DEBUG(printk("scsi(%ld): Retrying"
2751 " %d login again loop_id 0x%x\n",
2752 vha->host_no, fcport->login_retry,
2755 fcport->login_retry = 0;
2758 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
2759 fcport->loop_id = FC_NO_LOOP_ID;
2761 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2766 /**************************************************************************
2768 * This kernel thread is a task that is schedule by the interrupt handler
2769 * to perform the background processing for interrupts.
2772 * This task always run in the context of a kernel thread. It
2773 * is kick-off by the driver's detect code and starts up
2774 * up one per adapter. It immediately goes to sleep and waits for
2775 * some fibre event. When either the interrupt handler or
2776 * the timer routine detects a event it will one of the task
2777 * bits then wake us up.
2778 **************************************************************************/
2780 qla2x00_do_dpc(void *data)
2783 scsi_qla_host_t *base_vha;
2784 struct qla_hw_data *ha;
2786 ha = (struct qla_hw_data *)data;
2787 base_vha = pci_get_drvdata(ha->pdev);
2789 set_user_nice(current, -20);
2791 while (!kthread_should_stop()) {
2792 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2794 set_current_state(TASK_INTERRUPTIBLE);
2796 __set_current_state(TASK_RUNNING);
2798 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2800 /* Initialization not yet finished. Don't do anything yet. */
2801 if (!base_vha->flags.init_done)
2804 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
2808 if (ha->flags.mbox_busy) {
2813 qla2x00_do_work(base_vha);
2815 if (test_and_clear_bit(ISP_ABORT_NEEDED,
2816 &base_vha->dpc_flags)) {
2818 DEBUG(printk("scsi(%ld): dpc: sched "
2819 "qla2x00_abort_isp ha = %p\n",
2820 base_vha->host_no, ha));
2821 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2822 &base_vha->dpc_flags))) {
2824 if (qla2x00_abort_isp(base_vha)) {
2825 /* failed. retry later */
2826 set_bit(ISP_ABORT_NEEDED,
2827 &base_vha->dpc_flags);
2829 clear_bit(ABORT_ISP_ACTIVE,
2830 &base_vha->dpc_flags);
2833 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2834 base_vha->host_no));
2837 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
2838 qla2x00_update_fcports(base_vha);
2839 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2842 if (test_and_clear_bit(RESET_MARKER_NEEDED,
2843 &base_vha->dpc_flags) &&
2844 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
2846 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2847 base_vha->host_no));
2849 qla2x00_rst_aen(base_vha);
2850 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
2853 /* Retry each device up to login retry count */
2854 if ((test_and_clear_bit(RELOGIN_NEEDED,
2855 &base_vha->dpc_flags)) &&
2856 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
2857 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
2859 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2860 base_vha->host_no));
2861 qla2x00_relogin(base_vha);
2863 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2864 base_vha->host_no));
2867 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
2868 &base_vha->dpc_flags)) {
2870 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2871 base_vha->host_no));
2873 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2874 &base_vha->dpc_flags))) {
2876 rval = qla2x00_loop_resync(base_vha);
2878 clear_bit(LOOP_RESYNC_ACTIVE,
2879 &base_vha->dpc_flags);
2882 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2883 base_vha->host_no));
2886 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
2887 atomic_read(&base_vha->loop_state) == LOOP_READY) {
2888 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
2889 qla2xxx_flash_npiv_conf(base_vha);
2892 if (!ha->interrupts_on)
2893 ha->isp_ops->enable_intrs(ha);
2895 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
2896 &base_vha->dpc_flags))
2897 ha->isp_ops->beacon_blink(base_vha);
2899 qla2x00_do_dpc_all_vps(base_vha);
2902 } /* End of while(1) */
2904 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
2907 * Make sure that nobody tries to wake us up again.
2911 /* Cleanup any residual CTX SRBs. */
2912 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2918 qla2xxx_wake_dpc(struct scsi_qla_host *vha)
2920 struct qla_hw_data *ha = vha->hw;
2921 struct task_struct *t = ha->dpc_thread;
2923 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
2929 * Processes asynchronous reset.
2932 * ha = adapter block pointer.
2935 qla2x00_rst_aen(scsi_qla_host_t *vha)
2937 if (vha->flags.online && !vha->flags.reset_active &&
2938 !atomic_read(&vha->loop_down_timer) &&
2939 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
2941 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
2944 * Issue marker command only when we are going to start
2947 vha->marker_needed = 1;
2948 } while (!atomic_read(&vha->loop_down_timer) &&
2949 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
2954 qla2x00_sp_free_dma(srb_t *sp)
2956 struct scsi_cmnd *cmd = sp->cmd;
2958 if (sp->flags & SRB_DMA_VALID) {
2959 scsi_dma_unmap(cmd);
2960 sp->flags &= ~SRB_DMA_VALID;
2966 qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
2968 struct scsi_cmnd *cmd = sp->cmd;
2970 qla2x00_sp_free_dma(sp);
2972 mempool_free(sp, ha->srb_mempool);
2974 cmd->scsi_done(cmd);
2977 /**************************************************************************
2983 * Context: Interrupt
2984 ***************************************************************************/
2986 qla2x00_timer(scsi_qla_host_t *vha)
2988 unsigned long cpu_flags = 0;
2994 struct qla_hw_data *ha = vha->hw;
2995 struct req_que *req;
2997 * Ports - Port down timer.
2999 * Whenever, a port is in the LOST state we start decrementing its port
3000 * down timer every second until it reaches zero. Once it reaches zero
3001 * the port it marked DEAD.
3004 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3005 if (fcport->port_type != FCT_TARGET)
3008 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
3010 if (atomic_read(&fcport->port_down_timer) == 0)
3013 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
3014 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
3016 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
3019 t, atomic_read(&fcport->port_down_timer)));
3022 } /* End of for fcport */
3025 /* Loop down handler. */
3026 if (atomic_read(&vha->loop_down_timer) > 0 &&
3027 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
3028 && vha->flags.online) {
3030 if (atomic_read(&vha->loop_down_timer) ==
3031 vha->loop_down_abort_time) {
3033 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
3034 "queues before time expire\n",
3037 if (!IS_QLA2100(ha) && vha->link_down_timeout)
3038 atomic_set(&vha->loop_state, LOOP_DEAD);
3040 /* Schedule an ISP abort to return any tape commands. */
3041 /* NPIV - scan physical port only */
3043 spin_lock_irqsave(&ha->hardware_lock,
3045 req = ha->req_q_map[0];
3047 index < MAX_OUTSTANDING_COMMANDS;
3051 sp = req->outstanding_cmds[index];
3057 if (!(sfcp->flags & FCF_TAPE_PRESENT))
3060 set_bit(ISP_ABORT_NEEDED,
3064 spin_unlock_irqrestore(&ha->hardware_lock,
3070 /* if the loop has been down for 4 minutes, reinit adapter */
3071 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
3072 if (!(vha->device_flags & DFLG_NO_CABLE) &&
3074 DEBUG(printk("scsi(%ld): Loop down - "
3077 qla_printk(KERN_WARNING, ha,
3078 "Loop down - aborting ISP.\n");
3080 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3083 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
3085 atomic_read(&vha->loop_down_timer)));
3088 /* Check if beacon LED needs to be blinked */
3089 if (ha->beacon_blink_led == 1) {
3090 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
3094 /* Process any deferred work. */
3095 if (!list_empty(&vha->work_list))
3098 /* Schedule the DPC routine if needed */
3099 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
3100 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
3101 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
3103 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
3104 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
3105 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
3106 test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
3107 qla2xxx_wake_dpc(vha);
3109 qla2x00_restart_timer(vha, WATCH_INTERVAL);
3112 /* Firmware interface routines. */
3115 #define FW_ISP21XX 0
3116 #define FW_ISP22XX 1
3117 #define FW_ISP2300 2
3118 #define FW_ISP2322 3
3119 #define FW_ISP24XX 4
3120 #define FW_ISP25XX 5
3121 #define FW_ISP81XX 6
3123 #define FW_FILE_ISP21XX "ql2100_fw.bin"
3124 #define FW_FILE_ISP22XX "ql2200_fw.bin"
3125 #define FW_FILE_ISP2300 "ql2300_fw.bin"
3126 #define FW_FILE_ISP2322 "ql2322_fw.bin"
3127 #define FW_FILE_ISP24XX "ql2400_fw.bin"
3128 #define FW_FILE_ISP25XX "ql2500_fw.bin"
3129 #define FW_FILE_ISP81XX "ql8100_fw.bin"
3131 static DEFINE_MUTEX(qla_fw_lock);
3133 static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
3134 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
3135 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
3136 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
3137 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
3138 { .name = FW_FILE_ISP24XX, },
3139 { .name = FW_FILE_ISP25XX, },
3140 { .name = FW_FILE_ISP81XX, },
3144 qla2x00_request_firmware(scsi_qla_host_t *vha)
3146 struct qla_hw_data *ha = vha->hw;
3147 struct fw_blob *blob;
3150 if (IS_QLA2100(ha)) {
3151 blob = &qla_fw_blobs[FW_ISP21XX];
3152 } else if (IS_QLA2200(ha)) {
3153 blob = &qla_fw_blobs[FW_ISP22XX];
3154 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3155 blob = &qla_fw_blobs[FW_ISP2300];
3156 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
3157 blob = &qla_fw_blobs[FW_ISP2322];
3158 } else if (IS_QLA24XX_TYPE(ha)) {
3159 blob = &qla_fw_blobs[FW_ISP24XX];
3160 } else if (IS_QLA25XX(ha)) {
3161 blob = &qla_fw_blobs[FW_ISP25XX];
3162 } else if (IS_QLA81XX(ha)) {
3163 blob = &qla_fw_blobs[FW_ISP81XX];
3166 mutex_lock(&qla_fw_lock);
3170 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
3171 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
3172 "(%s).\n", vha->host_no, blob->name));
3179 mutex_unlock(&qla_fw_lock);
3184 qla2x00_release_firmware(void)
3188 mutex_lock(&qla_fw_lock);
3189 for (idx = 0; idx < FW_BLOBS; idx++)
3190 if (qla_fw_blobs[idx].fw)
3191 release_firmware(qla_fw_blobs[idx].fw);
3192 mutex_unlock(&qla_fw_lock);
3195 static pci_ers_result_t
3196 qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3198 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3201 case pci_channel_io_normal:
3202 return PCI_ERS_RESULT_CAN_RECOVER;
3203 case pci_channel_io_frozen:
3204 pci_disable_device(pdev);
3205 return PCI_ERS_RESULT_NEED_RESET;
3206 case pci_channel_io_perm_failure:
3207 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3208 return PCI_ERS_RESULT_DISCONNECT;
3210 return PCI_ERS_RESULT_NEED_RESET;
3213 static pci_ers_result_t
3214 qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
3216 int risc_paused = 0;
3218 unsigned long flags;
3219 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3220 struct qla_hw_data *ha = base_vha->hw;
3221 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3222 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
3224 spin_lock_irqsave(&ha->hardware_lock, flags);
3225 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
3226 stat = RD_REG_DWORD(®->hccr);
3227 if (stat & HCCR_RISC_PAUSE)
3229 } else if (IS_QLA23XX(ha)) {
3230 stat = RD_REG_DWORD(®->u.isp2300.host_status);
3231 if (stat & HSR_RISC_PAUSED)
3233 } else if (IS_FWI2_CAPABLE(ha)) {
3234 stat = RD_REG_DWORD(®24->host_status);
3235 if (stat & HSRX_RISC_PAUSED)
3238 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3241 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
3242 "Dumping firmware!\n");
3243 ha->isp_ops->fw_dump(base_vha, 0);
3245 return PCI_ERS_RESULT_NEED_RESET;
3247 return PCI_ERS_RESULT_RECOVERED;
3250 static pci_ers_result_t
3251 qla2xxx_pci_slot_reset(struct pci_dev *pdev)
3253 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
3254 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3255 struct qla_hw_data *ha = base_vha->hw;
3259 rc = pci_enable_device_mem(pdev);
3261 rc = pci_enable_device(pdev);
3264 qla_printk(KERN_WARNING, ha,
3265 "Can't re-enable PCI device after reset.\n");
3269 pci_set_master(pdev);
3271 if (ha->isp_ops->pci_config(base_vha))
3274 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3275 if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
3276 ret = PCI_ERS_RESULT_RECOVERED;
3277 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3283 qla2xxx_pci_resume(struct pci_dev *pdev)
3285 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3286 struct qla_hw_data *ha = base_vha->hw;
3289 ret = qla2x00_wait_for_hba_online(base_vha);
3290 if (ret != QLA_SUCCESS) {
3291 qla_printk(KERN_ERR, ha,
3292 "the device failed to resume I/O "
3293 "from slot/link_reset");
3295 pci_cleanup_aer_uncorrect_error_status(pdev);
3298 static struct pci_error_handlers qla2xxx_err_handler = {
3299 .error_detected = qla2xxx_pci_error_detected,
3300 .mmio_enabled = qla2xxx_pci_mmio_enabled,
3301 .slot_reset = qla2xxx_pci_slot_reset,
3302 .resume = qla2xxx_pci_resume,
3305 static struct pci_device_id qla2xxx_pci_tbl[] = {
3306 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
3307 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
3308 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
3309 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
3310 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
3311 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
3312 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
3313 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
3314 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
3315 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
3316 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
3317 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
3318 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
3319 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
3322 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
3324 static struct pci_driver qla2xxx_pci_driver = {
3325 .name = QLA2XXX_DRIVER_NAME,
3327 .owner = THIS_MODULE,
3329 .id_table = qla2xxx_pci_tbl,
3330 .probe = qla2x00_probe_one,
3331 .remove = qla2x00_remove_one,
3332 .err_handler = &qla2xxx_err_handler,
3336 * qla2x00_module_init - Module initialization.
3339 qla2x00_module_init(void)
3343 /* Allocate cache for SRBs. */
3344 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
3345 SLAB_HWCACHE_ALIGN, NULL);
3346 if (srb_cachep == NULL) {
3348 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3352 /* Derive version string. */
3353 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
3354 if (ql2xextended_error_logging)
3355 strcat(qla2x00_version_str, "-debug");
3357 qla2xxx_transport_template =
3358 fc_attach_transport(&qla2xxx_transport_functions);
3359 if (!qla2xxx_transport_template) {
3360 kmem_cache_destroy(srb_cachep);
3363 qla2xxx_transport_vport_template =
3364 fc_attach_transport(&qla2xxx_transport_vport_functions);
3365 if (!qla2xxx_transport_vport_template) {
3366 kmem_cache_destroy(srb_cachep);
3367 fc_release_transport(qla2xxx_transport_template);
3371 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
3372 qla2x00_version_str);
3373 ret = pci_register_driver(&qla2xxx_pci_driver);
3375 kmem_cache_destroy(srb_cachep);
3376 fc_release_transport(qla2xxx_transport_template);
3377 fc_release_transport(qla2xxx_transport_vport_template);
3383 * qla2x00_module_exit - Module cleanup.
3386 qla2x00_module_exit(void)
3388 pci_unregister_driver(&qla2xxx_pci_driver);
3389 qla2x00_release_firmware();
3390 kmem_cache_destroy(srb_cachep);
3391 fc_release_transport(qla2xxx_transport_template);
3392 fc_release_transport(qla2xxx_transport_vport_template);
3395 module_init(qla2x00_module_init);
3396 module_exit(qla2x00_module_exit);
3398 MODULE_AUTHOR("QLogic Corporation");
3399 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3400 MODULE_LICENSE("GPL");
3401 MODULE_VERSION(QLA2XXX_VERSION);
3402 MODULE_FIRMWARE(FW_FILE_ISP21XX);
3403 MODULE_FIRMWARE(FW_FILE_ISP22XX);
3404 MODULE_FIRMWARE(FW_FILE_ISP2300);
3405 MODULE_FIRMWARE(FW_FILE_ISP2322);
3406 MODULE_FIRMWARE(FW_FILE_ISP24XX);
3407 MODULE_FIRMWARE(FW_FILE_ISP25XX);
3408 MODULE_FIRMWARE(FW_FILE_ISP81XX);