2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2010 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
10 #include <linux/delay.h>
11 #include <linux/slab.h>
12 #include <linux/vmalloc.h>
14 #include "qla_devtbl.h"
21 * QLogic ISP2x00 Hardware Support Function Prototypes.
23 static int qla2x00_isp_firmware(scsi_qla_host_t *);
24 static int qla2x00_setup_chip(scsi_qla_host_t *);
25 static int qla2x00_init_rings(scsi_qla_host_t *);
26 static int qla2x00_fw_ready(scsi_qla_host_t *);
27 static int qla2x00_configure_hba(scsi_qla_host_t *);
28 static int qla2x00_configure_loop(scsi_qla_host_t *);
29 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
30 static int qla2x00_configure_fabric(scsi_qla_host_t *);
31 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
32 static int qla2x00_device_resync(scsi_qla_host_t *);
33 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
36 static int qla2x00_restart_isp(scsi_qla_host_t *);
38 static int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *);
40 static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
41 static int qla84xx_init_chip(scsi_qla_host_t *);
42 static int qla25xx_init_queues(struct qla_hw_data *);
44 /* SRB Extensions ---------------------------------------------------------- */
47 qla2x00_ctx_sp_timeout(unsigned long __data)
49 srb_t *sp = (srb_t *)__data;
51 struct srb_iocb *iocb;
52 fc_port_t *fcport = sp->fcport;
53 struct qla_hw_data *ha = fcport->vha->hw;
57 spin_lock_irqsave(&ha->hardware_lock, flags);
58 req = ha->req_q_map[0];
59 req->outstanding_cmds[sp->handle] = NULL;
61 iocb = ctx->u.iocb_cmd;
64 spin_unlock_irqrestore(&ha->hardware_lock, flags);
68 qla2x00_ctx_sp_free(srb_t *sp)
70 struct srb_ctx *ctx = sp->ctx;
71 struct srb_iocb *iocb = ctx->u.iocb_cmd;
72 struct scsi_qla_host *vha = sp->fcport->vha;
74 del_timer_sync(&iocb->timer);
77 mempool_free(sp, sp->fcport->vha->hw->srb_mempool);
79 QLA_VHA_MARK_NOT_BUSY(vha);
83 qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size,
87 struct qla_hw_data *ha = vha->hw;
89 struct srb_iocb *iocb;
92 QLA_VHA_MARK_BUSY(vha, bail);
96 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
99 ctx = kzalloc(size, GFP_KERNEL);
101 mempool_free(sp, ha->srb_mempool);
105 iocb = kzalloc(sizeof(struct srb_iocb), GFP_KERNEL);
107 mempool_free(sp, ha->srb_mempool);
113 memset(sp, 0, sizeof(*sp));
116 ctx->u.iocb_cmd = iocb;
117 iocb->free = qla2x00_ctx_sp_free;
119 init_timer(&iocb->timer);
122 iocb->timer.expires = jiffies + tmo * HZ;
123 iocb->timer.data = (unsigned long)sp;
124 iocb->timer.function = qla2x00_ctx_sp_timeout;
125 add_timer(&iocb->timer);
128 QLA_VHA_MARK_NOT_BUSY(vha);
132 /* Asynchronous Login/Logout Routines -------------------------------------- */
134 static inline unsigned long
135 qla2x00_get_async_timeout(struct scsi_qla_host *vha)
138 struct qla_hw_data *ha = vha->hw;
140 /* Firmware should use switch negotiated r_a_tov for timeout. */
141 tmo = ha->r_a_tov / 10 * 2;
142 if (!IS_FWI2_CAPABLE(ha)) {
144 * Except for earlier ISPs where the timeout is seeded from the
145 * initialization control block.
147 tmo = ha->login_timeout;
153 qla2x00_async_iocb_timeout(srb_t *sp)
155 fc_port_t *fcport = sp->fcport;
156 struct srb_ctx *ctx = sp->ctx;
158 DEBUG2(printk(KERN_WARNING
159 "scsi(%ld:%x): Async-%s timeout - portid=%02x%02x%02x.\n",
160 fcport->vha->host_no, sp->handle,
161 ctx->name, fcport->d_id.b.domain,
162 fcport->d_id.b.area, fcport->d_id.b.al_pa));
164 fcport->flags &= ~FCF_ASYNC_SENT;
165 if (ctx->type == SRB_LOGIN_CMD) {
166 struct srb_iocb *lio = ctx->u.iocb_cmd;
167 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
168 /* Retry as needed. */
169 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
170 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
171 QLA_LOGIO_LOGIN_RETRIED : 0;
172 qla2x00_post_async_login_done_work(fcport->vha, fcport,
178 qla2x00_async_login_ctx_done(srb_t *sp)
180 struct srb_ctx *ctx = sp->ctx;
181 struct srb_iocb *lio = ctx->u.iocb_cmd;
183 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
189 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
194 struct srb_iocb *lio;
197 rval = QLA_FUNCTION_FAILED;
198 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
199 qla2x00_get_async_timeout(vha) + 2);
204 ctx->type = SRB_LOGIN_CMD;
206 lio = ctx->u.iocb_cmd;
207 lio->timeout = qla2x00_async_iocb_timeout;
208 lio->done = qla2x00_async_login_ctx_done;
209 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
210 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
211 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
212 rval = qla2x00_start_sp(sp);
213 if (rval != QLA_SUCCESS)
216 DEBUG2(printk(KERN_DEBUG
217 "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
218 "retries=%d.\n", fcport->vha->host_no, sp->handle, fcport->loop_id,
219 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
220 fcport->login_retry));
230 qla2x00_async_logout_ctx_done(srb_t *sp)
232 struct srb_ctx *ctx = sp->ctx;
233 struct srb_iocb *lio = ctx->u.iocb_cmd;
235 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
241 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
245 struct srb_iocb *lio;
248 rval = QLA_FUNCTION_FAILED;
249 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
250 qla2x00_get_async_timeout(vha) + 2);
255 ctx->type = SRB_LOGOUT_CMD;
256 ctx->name = "logout";
257 lio = ctx->u.iocb_cmd;
258 lio->timeout = qla2x00_async_iocb_timeout;
259 lio->done = qla2x00_async_logout_ctx_done;
260 rval = qla2x00_start_sp(sp);
261 if (rval != QLA_SUCCESS)
264 DEBUG2(printk(KERN_DEBUG
265 "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
266 fcport->vha->host_no, sp->handle, fcport->loop_id,
267 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
277 qla2x00_async_adisc_ctx_done(srb_t *sp)
279 struct srb_ctx *ctx = sp->ctx;
280 struct srb_iocb *lio = ctx->u.iocb_cmd;
282 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
288 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
293 struct srb_iocb *lio;
296 rval = QLA_FUNCTION_FAILED;
297 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
298 qla2x00_get_async_timeout(vha) + 2);
303 ctx->type = SRB_ADISC_CMD;
305 lio = ctx->u.iocb_cmd;
306 lio->timeout = qla2x00_async_iocb_timeout;
307 lio->done = qla2x00_async_adisc_ctx_done;
308 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
309 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
310 rval = qla2x00_start_sp(sp);
311 if (rval != QLA_SUCCESS)
314 DEBUG2(printk(KERN_DEBUG
315 "scsi(%ld:%x): Async-adisc - loop-id=%x portid=%02x%02x%02x.\n",
316 fcport->vha->host_no, sp->handle, fcport->loop_id,
317 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
328 qla2x00_async_tm_cmd_ctx_done(srb_t *sp)
330 struct srb_ctx *ctx = sp->ctx;
331 struct srb_iocb *iocb = (struct srb_iocb *)ctx->u.iocb_cmd;
333 qla2x00_async_tm_cmd_done(sp->fcport->vha, sp->fcport, iocb);
338 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
341 struct scsi_qla_host *vha = fcport->vha;
344 struct srb_iocb *tcf;
347 rval = QLA_FUNCTION_FAILED;
348 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
349 qla2x00_get_async_timeout(vha) + 2);
354 ctx->type = SRB_TM_CMD;
356 tcf = ctx->u.iocb_cmd;
357 tcf->u.tmf.flags = flags;
358 tcf->u.tmf.lun = lun;
359 tcf->u.tmf.data = tag;
360 tcf->timeout = qla2x00_async_iocb_timeout;
361 tcf->done = qla2x00_async_tm_cmd_ctx_done;
363 rval = qla2x00_start_sp(sp);
364 if (rval != QLA_SUCCESS)
367 DEBUG2(printk(KERN_DEBUG
368 "scsi(%ld:%x): Async-tmf - loop-id=%x portid=%02x%02x%02x.\n",
369 fcport->vha->host_no, sp->handle, fcport->loop_id,
370 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
381 qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
387 case MBS_COMMAND_COMPLETE:
388 if (fcport->flags & FCF_FCP2_DEVICE) {
389 fcport->flags |= FCF_ASYNC_SENT;
390 qla2x00_post_async_adisc_work(vha, fcport, data);
393 qla2x00_update_fcport(vha, fcport);
395 case MBS_COMMAND_ERROR:
396 fcport->flags &= ~FCF_ASYNC_SENT;
397 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
398 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
400 qla2x00_mark_device_lost(vha, fcport, 1, 1);
402 case MBS_PORT_ID_USED:
403 fcport->loop_id = data[1];
404 qla2x00_post_async_logout_work(vha, fcport, NULL);
405 qla2x00_post_async_login_work(vha, fcport, NULL);
407 case MBS_LOOP_ID_USED:
409 rval = qla2x00_find_new_loop_id(vha, fcport);
410 if (rval != QLA_SUCCESS) {
411 fcport->flags &= ~FCF_ASYNC_SENT;
412 qla2x00_mark_device_lost(vha, fcport, 1, 1);
415 qla2x00_post_async_login_work(vha, fcport, NULL);
422 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
425 qla2x00_mark_device_lost(vha, fcport, 1, 0);
430 qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
433 if (data[0] == MBS_COMMAND_COMPLETE) {
434 qla2x00_update_fcport(vha, fcport);
440 fcport->flags &= ~FCF_ASYNC_SENT;
441 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
442 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
444 qla2x00_mark_device_lost(vha, fcport, 1, 1);
450 qla2x00_async_tm_cmd_done(struct scsi_qla_host *vha, fc_port_t *fcport,
451 struct srb_iocb *iocb)
457 flags = iocb->u.tmf.flags;
458 lun = (uint16_t)iocb->u.tmf.lun;
460 /* Issue Marker IOCB */
461 rval = qla2x00_marker(vha, vha->hw->req_q_map[0],
462 vha->hw->rsp_q_map[0], fcport->loop_id, lun,
463 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
465 if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) {
466 DEBUG2_3_11(printk(KERN_WARNING
467 "%s(%ld): TM IOCB failed (%x).\n",
468 __func__, vha->host_no, rval));
474 /****************************************************************************/
475 /* QLogic ISP2x00 Hardware Support Functions. */
476 /****************************************************************************/
479 * qla2x00_initialize_adapter
483 * ha = adapter block pointer.
489 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
492 struct qla_hw_data *ha = vha->hw;
493 struct req_que *req = ha->req_q_map[0];
495 /* Clear adapter flags. */
496 vha->flags.online = 0;
497 ha->flags.chip_reset_done = 0;
498 vha->flags.reset_active = 0;
499 ha->flags.pci_channel_io_perm_failure = 0;
500 ha->flags.eeh_busy = 0;
501 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
502 atomic_set(&vha->loop_state, LOOP_DOWN);
503 vha->device_flags = DFLG_NO_CABLE;
505 vha->flags.management_server_logged_in = 0;
506 vha->marker_needed = 0;
507 ha->isp_abort_cnt = 0;
508 ha->beacon_blink_led = 0;
510 set_bit(0, ha->req_qid_map);
511 set_bit(0, ha->rsp_qid_map);
513 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
514 rval = ha->isp_ops->pci_config(vha);
516 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
521 ha->isp_ops->reset_chip(vha);
523 rval = qla2xxx_get_flash_info(vha);
525 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
530 ha->isp_ops->get_flash_version(vha, req->ring);
532 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
534 ha->isp_ops->nvram_config(vha);
536 if (ha->flags.disable_serdes) {
537 /* Mask HBA via NVRAM settings? */
538 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
539 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
540 vha->port_name[0], vha->port_name[1],
541 vha->port_name[2], vha->port_name[3],
542 vha->port_name[4], vha->port_name[5],
543 vha->port_name[6], vha->port_name[7]);
544 return QLA_FUNCTION_FAILED;
547 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
549 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
550 rval = ha->isp_ops->chip_diag(vha);
553 rval = qla2x00_setup_chip(vha);
558 if (IS_QLA84XX(ha)) {
559 ha->cs84xx = qla84xx_get_chip(vha);
561 qla_printk(KERN_ERR, ha,
562 "Unable to configure ISP84XX.\n");
563 return QLA_FUNCTION_FAILED;
566 rval = qla2x00_init_rings(vha);
567 ha->flags.chip_reset_done = 1;
569 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
570 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
571 rval = qla84xx_init_chip(vha);
572 if (rval != QLA_SUCCESS) {
573 qla_printk(KERN_ERR, ha,
574 "Unable to initialize ISP84XX.\n");
575 qla84xx_put_chip(vha);
579 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
580 qla24xx_read_fcp_prio_cfg(vha);
586 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
589 * Returns 0 on success.
592 qla2100_pci_config(scsi_qla_host_t *vha)
596 struct qla_hw_data *ha = vha->hw;
597 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
599 pci_set_master(ha->pdev);
600 pci_try_set_mwi(ha->pdev);
602 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
603 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
604 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
606 pci_disable_rom(ha->pdev);
608 /* Get PCI bus information. */
609 spin_lock_irqsave(&ha->hardware_lock, flags);
610 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
611 spin_unlock_irqrestore(&ha->hardware_lock, flags);
617 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
620 * Returns 0 on success.
623 qla2300_pci_config(scsi_qla_host_t *vha)
626 unsigned long flags = 0;
628 struct qla_hw_data *ha = vha->hw;
629 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
631 pci_set_master(ha->pdev);
632 pci_try_set_mwi(ha->pdev);
634 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
635 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
637 if (IS_QLA2322(ha) || IS_QLA6322(ha))
638 w &= ~PCI_COMMAND_INTX_DISABLE;
639 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
642 * If this is a 2300 card and not 2312, reset the
643 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
644 * the 2310 also reports itself as a 2300 so we need to get the
645 * fb revision level -- a 6 indicates it really is a 2300 and
648 if (IS_QLA2300(ha)) {
649 spin_lock_irqsave(&ha->hardware_lock, flags);
652 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
653 for (cnt = 0; cnt < 30000; cnt++) {
654 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
660 /* Select FPM registers. */
661 WRT_REG_WORD(®->ctrl_status, 0x20);
662 RD_REG_WORD(®->ctrl_status);
664 /* Get the fb rev level */
665 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
667 if (ha->fb_rev == FPM_2300)
668 pci_clear_mwi(ha->pdev);
670 /* Deselect FPM registers. */
671 WRT_REG_WORD(®->ctrl_status, 0x0);
672 RD_REG_WORD(®->ctrl_status);
674 /* Release RISC module. */
675 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
676 for (cnt = 0; cnt < 30000; cnt++) {
677 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
683 spin_unlock_irqrestore(&ha->hardware_lock, flags);
686 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
688 pci_disable_rom(ha->pdev);
690 /* Get PCI bus information. */
691 spin_lock_irqsave(&ha->hardware_lock, flags);
692 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
693 spin_unlock_irqrestore(&ha->hardware_lock, flags);
699 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
702 * Returns 0 on success.
705 qla24xx_pci_config(scsi_qla_host_t *vha)
708 unsigned long flags = 0;
709 struct qla_hw_data *ha = vha->hw;
710 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
712 pci_set_master(ha->pdev);
713 pci_try_set_mwi(ha->pdev);
715 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
716 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
717 w &= ~PCI_COMMAND_INTX_DISABLE;
718 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
720 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
722 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
723 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
724 pcix_set_mmrbc(ha->pdev, 2048);
726 /* PCIe -- adjust Maximum Read Request Size (2048). */
727 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
728 pcie_set_readrq(ha->pdev, 2048);
730 pci_disable_rom(ha->pdev);
732 ha->chip_revision = ha->pdev->revision;
734 /* Get PCI bus information. */
735 spin_lock_irqsave(&ha->hardware_lock, flags);
736 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
737 spin_unlock_irqrestore(&ha->hardware_lock, flags);
743 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
746 * Returns 0 on success.
749 qla25xx_pci_config(scsi_qla_host_t *vha)
752 struct qla_hw_data *ha = vha->hw;
754 pci_set_master(ha->pdev);
755 pci_try_set_mwi(ha->pdev);
757 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
758 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
759 w &= ~PCI_COMMAND_INTX_DISABLE;
760 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
762 /* PCIe -- adjust Maximum Read Request Size (2048). */
763 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
764 pcie_set_readrq(ha->pdev, 2048);
766 pci_disable_rom(ha->pdev);
768 ha->chip_revision = ha->pdev->revision;
774 * qla2x00_isp_firmware() - Choose firmware image.
777 * Returns 0 on success.
780 qla2x00_isp_firmware(scsi_qla_host_t *vha)
783 uint16_t loop_id, topo, sw_cap;
784 uint8_t domain, area, al_pa;
785 struct qla_hw_data *ha = vha->hw;
787 /* Assume loading risc code */
788 rval = QLA_FUNCTION_FAILED;
790 if (ha->flags.disable_risc_code_load) {
791 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
793 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
795 /* Verify checksum of loaded RISC code. */
796 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
797 if (rval == QLA_SUCCESS) {
798 /* And, verify we are not in ROM code. */
799 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
800 &area, &domain, &topo, &sw_cap);
805 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
813 * qla2x00_reset_chip() - Reset ISP chip.
816 * Returns 0 on success.
819 qla2x00_reset_chip(scsi_qla_host_t *vha)
821 unsigned long flags = 0;
822 struct qla_hw_data *ha = vha->hw;
823 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
827 if (unlikely(pci_channel_offline(ha->pdev)))
830 ha->isp_ops->disable_intrs(ha);
832 spin_lock_irqsave(&ha->hardware_lock, flags);
834 /* Turn off master enable */
836 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
837 cmd &= ~PCI_COMMAND_MASTER;
838 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
840 if (!IS_QLA2100(ha)) {
842 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
843 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
844 for (cnt = 0; cnt < 30000; cnt++) {
845 if ((RD_REG_WORD(®->hccr) &
846 HCCR_RISC_PAUSE) != 0)
851 RD_REG_WORD(®->hccr); /* PCI Posting. */
855 /* Select FPM registers. */
856 WRT_REG_WORD(®->ctrl_status, 0x20);
857 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
859 /* FPM Soft Reset. */
860 WRT_REG_WORD(®->fpm_diag_config, 0x100);
861 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
863 /* Toggle Fpm Reset. */
864 if (!IS_QLA2200(ha)) {
865 WRT_REG_WORD(®->fpm_diag_config, 0x0);
866 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
869 /* Select frame buffer registers. */
870 WRT_REG_WORD(®->ctrl_status, 0x10);
871 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
873 /* Reset frame buffer FIFOs. */
874 if (IS_QLA2200(ha)) {
875 WRT_FB_CMD_REG(ha, reg, 0xa000);
876 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
878 WRT_FB_CMD_REG(ha, reg, 0x00fc);
880 /* Read back fb_cmd until zero or 3 seconds max */
881 for (cnt = 0; cnt < 3000; cnt++) {
882 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
888 /* Select RISC module registers. */
889 WRT_REG_WORD(®->ctrl_status, 0);
890 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
892 /* Reset RISC processor. */
893 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
894 RD_REG_WORD(®->hccr); /* PCI Posting. */
896 /* Release RISC processor. */
897 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
898 RD_REG_WORD(®->hccr); /* PCI Posting. */
901 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
902 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
904 /* Reset ISP chip. */
905 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
907 /* Wait for RISC to recover from reset. */
908 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
910 * It is necessary to for a delay here since the card doesn't
911 * respond to PCI reads during a reset. On some architectures
912 * this will result in an MCA.
915 for (cnt = 30000; cnt; cnt--) {
916 if ((RD_REG_WORD(®->ctrl_status) &
917 CSR_ISP_SOFT_RESET) == 0)
924 /* Reset RISC processor. */
925 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
927 WRT_REG_WORD(®->semaphore, 0);
929 /* Release RISC processor. */
930 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
931 RD_REG_WORD(®->hccr); /* PCI Posting. */
933 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
934 for (cnt = 0; cnt < 30000; cnt++) {
935 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
943 /* Turn on master enable */
944 cmd |= PCI_COMMAND_MASTER;
945 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
947 /* Disable RISC pause on FPM parity error. */
948 if (!IS_QLA2100(ha)) {
949 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
950 RD_REG_WORD(®->hccr); /* PCI Posting. */
953 spin_unlock_irqrestore(&ha->hardware_lock, flags);
957 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
959 * Returns 0 on success.
962 qla81xx_reset_mpi(scsi_qla_host_t *vha)
964 uint16_t mb[4] = {0x1010, 0, 1, 0};
966 return qla81xx_write_mpi_register(vha, mb);
970 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
973 * Returns 0 on success.
976 qla24xx_reset_risc(scsi_qla_host_t *vha)
978 unsigned long flags = 0;
979 struct qla_hw_data *ha = vha->hw;
980 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
983 static int abts_cnt; /* ISP abort retry counts */
985 spin_lock_irqsave(&ha->hardware_lock, flags);
988 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
989 for (cnt = 0; cnt < 30000; cnt++) {
990 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
996 WRT_REG_DWORD(®->ctrl_status,
997 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
998 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
1001 /* Wait for firmware to complete NVRAM accesses. */
1002 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
1003 for (cnt = 10000 ; cnt && d2; cnt--) {
1005 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
1009 /* Wait for soft-reset to complete. */
1010 d2 = RD_REG_DWORD(®->ctrl_status);
1011 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
1013 d2 = RD_REG_DWORD(®->ctrl_status);
1017 /* If required, do an MPI FW reset now */
1018 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
1019 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
1020 if (++abts_cnt < 5) {
1021 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1022 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
1025 * We exhausted the ISP abort retries. We have to
1026 * set the board offline.
1029 vha->flags.online = 0;
1034 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
1035 RD_REG_DWORD(®->hccr);
1037 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
1038 RD_REG_DWORD(®->hccr);
1040 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
1041 RD_REG_DWORD(®->hccr);
1043 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
1044 for (cnt = 6000000 ; cnt && d2; cnt--) {
1046 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
1050 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1052 if (IS_NOPOLLING_TYPE(ha))
1053 ha->isp_ops->enable_intrs(ha);
1057 * qla24xx_reset_chip() - Reset ISP24xx chip.
1060 * Returns 0 on success.
1063 qla24xx_reset_chip(scsi_qla_host_t *vha)
1065 struct qla_hw_data *ha = vha->hw;
1067 if (pci_channel_offline(ha->pdev) &&
1068 ha->flags.pci_channel_io_perm_failure) {
1072 ha->isp_ops->disable_intrs(ha);
1074 /* Perform RISC reset. */
1075 qla24xx_reset_risc(vha);
1079 * qla2x00_chip_diag() - Test chip for proper operation.
1082 * Returns 0 on success.
1085 qla2x00_chip_diag(scsi_qla_host_t *vha)
1088 struct qla_hw_data *ha = vha->hw;
1089 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1090 unsigned long flags = 0;
1094 struct req_que *req = ha->req_q_map[0];
1096 /* Assume a failed state */
1097 rval = QLA_FUNCTION_FAILED;
1099 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
1100 vha->host_no, (u_long)®->flash_address));
1102 spin_lock_irqsave(&ha->hardware_lock, flags);
1104 /* Reset ISP chip. */
1105 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
1108 * We need to have a delay here since the card will not respond while
1109 * in reset causing an MCA on some architectures.
1112 data = qla2x00_debounce_register(®->ctrl_status);
1113 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1115 data = RD_REG_WORD(®->ctrl_status);
1120 goto chip_diag_failed;
1122 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
1125 /* Reset RISC processor. */
1126 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
1127 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
1129 /* Workaround for QLA2312 PCI parity error */
1130 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1131 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1132 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1134 data = RD_MAILBOX_REG(ha, reg, 0);
1141 goto chip_diag_failed;
1143 /* Check product ID of chip */
1144 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
1146 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1147 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1148 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1149 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1150 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1151 mb[3] != PROD_ID_3) {
1152 qla_printk(KERN_WARNING, ha,
1153 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
1155 goto chip_diag_failed;
1157 ha->product_id[0] = mb[1];
1158 ha->product_id[1] = mb[2];
1159 ha->product_id[2] = mb[3];
1160 ha->product_id[3] = mb[4];
1162 /* Adjust fw RISC transfer size */
1163 if (req->length > 1024)
1164 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1166 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
1169 if (IS_QLA2200(ha) &&
1170 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1171 /* Limit firmware transfer size with a 2200A */
1172 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
1175 ha->device_type |= DT_ISP2200A;
1176 ha->fw_transfer_size = 128;
1179 /* Wrap Incoming Mailboxes Test. */
1180 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1182 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
1183 rval = qla2x00_mbx_reg_test(vha);
1185 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
1187 qla_printk(KERN_WARNING, ha,
1188 "Failed mailbox send register test\n");
1191 /* Flag a successful rval */
1194 spin_lock_irqsave(&ha->hardware_lock, flags);
1198 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
1199 "****\n", vha->host_no));
1201 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1207 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1210 * Returns 0 on success.
1213 qla24xx_chip_diag(scsi_qla_host_t *vha)
1216 struct qla_hw_data *ha = vha->hw;
1217 struct req_que *req = ha->req_q_map[0];
1222 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
1224 rval = qla2x00_mbx_reg_test(vha);
1226 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
1228 qla_printk(KERN_WARNING, ha,
1229 "Failed mailbox send register test\n");
1231 /* Flag a successful rval */
1239 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
1242 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
1243 eft_size, fce_size, mq_size;
1246 struct qla_hw_data *ha = vha->hw;
1247 struct req_que *req = ha->req_q_map[0];
1248 struct rsp_que *rsp = ha->rsp_q_map[0];
1251 qla_printk(KERN_WARNING, ha,
1252 "Firmware dump previously allocated.\n");
1257 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
1258 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1259 fixed_size = sizeof(struct qla2100_fw_dump);
1260 } else if (IS_QLA23XX(ha)) {
1261 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1262 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1264 } else if (IS_FWI2_CAPABLE(ha)) {
1266 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1267 else if (IS_QLA25XX(ha))
1268 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1270 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
1271 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1274 mq_size = sizeof(struct qla2xxx_mq_chain);
1275 /* Allocate memory for Fibre Channel Event Buffer. */
1276 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
1279 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1282 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1283 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
1287 memset(tc, 0, FCE_SIZE);
1288 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
1289 ha->fce_mb, &ha->fce_bufs);
1291 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1292 "FCE (%d).\n", rval);
1293 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1295 ha->flags.fce_enabled = 0;
1299 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
1302 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
1303 ha->flags.fce_enabled = 1;
1304 ha->fce_dma = tc_dma;
1307 /* Allocate memory for Extended Trace Buffer. */
1308 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
1311 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1312 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
1316 memset(tc, 0, EFT_SIZE);
1317 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
1319 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1320 "EFT (%d).\n", rval);
1321 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1326 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
1329 eft_size = EFT_SIZE;
1330 ha->eft_dma = tc_dma;
1334 req_q_size = req->length * sizeof(request_t);
1335 rsp_q_size = rsp->length * sizeof(response_t);
1337 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
1338 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
1339 ha->chain_offset = dump_size;
1340 dump_size += mq_size + fce_size;
1342 ha->fw_dump = vmalloc(dump_size);
1344 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
1345 "firmware dump!!!\n", dump_size / 1024);
1348 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1355 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
1358 ha->fw_dump_len = dump_size;
1359 ha->fw_dump->signature[0] = 'Q';
1360 ha->fw_dump->signature[1] = 'L';
1361 ha->fw_dump->signature[2] = 'G';
1362 ha->fw_dump->signature[3] = 'C';
1363 ha->fw_dump->version = __constant_htonl(1);
1365 ha->fw_dump->fixed_size = htonl(fixed_size);
1366 ha->fw_dump->mem_size = htonl(mem_size);
1367 ha->fw_dump->req_q_size = htonl(req_q_size);
1368 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1370 ha->fw_dump->eft_size = htonl(eft_size);
1371 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1372 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1374 ha->fw_dump->header_size =
1375 htonl(offsetof(struct qla2xxx_fw_dump, isp));
1379 qla81xx_mpi_sync(scsi_qla_host_t *vha)
1381 #define MPS_MASK 0xe0
1385 struct qla_hw_data *ha = vha->hw;
1387 if (!IS_QLA81XX(vha->hw))
1390 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1391 if (rval != QLA_SUCCESS) {
1392 DEBUG2(qla_printk(KERN_WARNING, ha,
1393 "Sync-MPI: Unable to acquire semaphore.\n"));
1397 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1398 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1399 if (rval != QLA_SUCCESS) {
1400 DEBUG2(qla_printk(KERN_WARNING, ha,
1401 "Sync-MPI: Unable to read sync.\n"));
1406 if (dc == (dw & MPS_MASK))
1411 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1412 if (rval != QLA_SUCCESS) {
1413 DEBUG2(qla_printk(KERN_WARNING, ha,
1414 "Sync-MPI: Unable to gain sync.\n"));
1418 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1419 if (rval != QLA_SUCCESS) {
1420 DEBUG2(qla_printk(KERN_WARNING, ha,
1421 "Sync-MPI: Unable to release semaphore.\n"));
1429 * qla2x00_setup_chip() - Load and start RISC firmware.
1432 * Returns 0 on success.
1435 qla2x00_setup_chip(scsi_qla_host_t *vha)
1438 uint32_t srisc_address = 0;
1439 struct qla_hw_data *ha = vha->hw;
1440 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1441 unsigned long flags;
1442 uint16_t fw_major_version;
1444 if (IS_QLA82XX(ha)) {
1445 rval = ha->isp_ops->load_risc(vha, &srisc_address);
1446 if (rval == QLA_SUCCESS) {
1447 qla2x00_stop_firmware(vha);
1448 goto enable_82xx_npiv;
1453 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1454 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1455 spin_lock_irqsave(&ha->hardware_lock, flags);
1456 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
1457 RD_REG_WORD(®->hccr);
1458 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1461 qla81xx_mpi_sync(vha);
1463 /* Load firmware sequences */
1464 rval = ha->isp_ops->load_risc(vha, &srisc_address);
1465 if (rval == QLA_SUCCESS) {
1466 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
1467 "code.\n", vha->host_no));
1469 rval = qla2x00_verify_checksum(vha, srisc_address);
1470 if (rval == QLA_SUCCESS) {
1471 /* Start firmware execution. */
1472 DEBUG(printk("scsi(%ld): Checksum OK, start "
1473 "firmware.\n", vha->host_no));
1475 rval = qla2x00_execute_fw(vha, srisc_address);
1476 /* Retrieve firmware information. */
1477 if (rval == QLA_SUCCESS) {
1479 fw_major_version = ha->fw_major_version;
1480 rval = qla2x00_get_fw_version(vha,
1481 &ha->fw_major_version,
1482 &ha->fw_minor_version,
1483 &ha->fw_subminor_version,
1484 &ha->fw_attributes, &ha->fw_memory_size,
1485 ha->mpi_version, &ha->mpi_capabilities,
1487 if (rval != QLA_SUCCESS)
1489 ha->flags.npiv_supported = 0;
1490 if (IS_QLA2XXX_MIDTYPE(ha) &&
1491 (ha->fw_attributes & BIT_2)) {
1492 ha->flags.npiv_supported = 1;
1493 if ((!ha->max_npiv_vports) ||
1494 ((ha->max_npiv_vports + 1) %
1495 MIN_MULTI_ID_FABRIC))
1496 ha->max_npiv_vports =
1497 MIN_MULTI_ID_FABRIC - 1;
1499 qla2x00_get_resource_cnts(vha, NULL,
1500 &ha->fw_xcb_count, NULL, NULL,
1501 &ha->max_npiv_vports, NULL);
1503 if (!fw_major_version && ql2xallocfwdump) {
1504 if (!IS_QLA82XX(ha))
1505 qla2x00_alloc_fw_dump(vha);
1509 DEBUG2(printk(KERN_INFO
1510 "scsi(%ld): ISP Firmware failed checksum.\n",
1515 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1516 /* Enable proper parity. */
1517 spin_lock_irqsave(&ha->hardware_lock, flags);
1520 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
1522 /* SRAM, Instruction RAM and GP RAM parity */
1523 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
1524 RD_REG_WORD(®->hccr);
1525 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1528 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1531 rval = qla81xx_fac_get_sector_size(vha, &size);
1532 if (rval == QLA_SUCCESS) {
1533 ha->flags.fac_supported = 1;
1534 ha->fdt_block_size = size << 2;
1536 qla_printk(KERN_ERR, ha,
1537 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1538 ha->fw_major_version, ha->fw_minor_version,
1539 ha->fw_subminor_version);
1544 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
1552 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1555 * Beginning of request ring has initialization control block already built
1556 * by nvram config routine.
1558 * Returns 0 on success.
1561 qla2x00_init_response_q_entries(struct rsp_que *rsp)
1566 rsp->ring_ptr = rsp->ring;
1567 rsp->ring_index = 0;
1568 rsp->status_srb = NULL;
1569 pkt = rsp->ring_ptr;
1570 for (cnt = 0; cnt < rsp->length; cnt++) {
1571 pkt->signature = RESPONSE_PROCESSED;
1577 * qla2x00_update_fw_options() - Read and process firmware options.
1580 * Returns 0 on success.
1583 qla2x00_update_fw_options(scsi_qla_host_t *vha)
1585 uint16_t swing, emphasis, tx_sens, rx_sens;
1586 struct qla_hw_data *ha = vha->hw;
1588 memset(ha->fw_options, 0, sizeof(ha->fw_options));
1589 qla2x00_get_fw_options(vha, ha->fw_options);
1591 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1594 /* Serial Link options. */
1595 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1597 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1598 sizeof(ha->fw_seriallink_options)));
1600 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1601 if (ha->fw_seriallink_options[3] & BIT_2) {
1602 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1605 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1606 emphasis = (ha->fw_seriallink_options[2] &
1607 (BIT_4 | BIT_3)) >> 3;
1608 tx_sens = ha->fw_seriallink_options[0] &
1609 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1610 rx_sens = (ha->fw_seriallink_options[0] &
1611 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1612 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1613 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1616 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1617 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1618 ha->fw_options[10] |= BIT_5 |
1619 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1620 (tx_sens & (BIT_1 | BIT_0));
1623 swing = (ha->fw_seriallink_options[2] &
1624 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1625 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1626 tx_sens = ha->fw_seriallink_options[1] &
1627 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1628 rx_sens = (ha->fw_seriallink_options[1] &
1629 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1630 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1631 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1634 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1635 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1636 ha->fw_options[11] |= BIT_5 |
1637 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1638 (tx_sens & (BIT_1 | BIT_0));
1642 /* Return command IOCBs without waiting for an ABTS to complete. */
1643 ha->fw_options[3] |= BIT_13;
1646 if (ha->flags.enable_led_scheme)
1647 ha->fw_options[2] |= BIT_12;
1649 /* Detect ISP6312. */
1651 ha->fw_options[2] |= BIT_13;
1653 /* Update firmware options. */
1654 qla2x00_set_fw_options(vha, ha->fw_options);
1658 qla24xx_update_fw_options(scsi_qla_host_t *vha)
1661 struct qla_hw_data *ha = vha->hw;
1666 /* Update Serial Link options. */
1667 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1670 rval = qla2x00_set_serdes_params(vha,
1671 le16_to_cpu(ha->fw_seriallink_options24[1]),
1672 le16_to_cpu(ha->fw_seriallink_options24[2]),
1673 le16_to_cpu(ha->fw_seriallink_options24[3]));
1674 if (rval != QLA_SUCCESS) {
1675 qla_printk(KERN_WARNING, ha,
1676 "Unable to update Serial Link options (%x).\n", rval);
1681 qla2x00_config_rings(struct scsi_qla_host *vha)
1683 struct qla_hw_data *ha = vha->hw;
1684 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1685 struct req_que *req = ha->req_q_map[0];
1686 struct rsp_que *rsp = ha->rsp_q_map[0];
1688 /* Setup ring parameters in initialization control block. */
1689 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1690 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1691 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1692 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1693 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1694 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1695 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1696 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
1698 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1699 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1700 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1701 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1702 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1706 qla24xx_config_rings(struct scsi_qla_host *vha)
1708 struct qla_hw_data *ha = vha->hw;
1709 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1710 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1711 struct qla_msix_entry *msix;
1712 struct init_cb_24xx *icb;
1714 struct req_que *req = ha->req_q_map[0];
1715 struct rsp_que *rsp = ha->rsp_q_map[0];
1717 /* Setup ring parameters in initialization control block. */
1718 icb = (struct init_cb_24xx *)ha->init_cb;
1719 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1720 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1721 icb->request_q_length = cpu_to_le16(req->length);
1722 icb->response_q_length = cpu_to_le16(rsp->length);
1723 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1724 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1725 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1726 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
1729 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1730 icb->rid = __constant_cpu_to_le16(rid);
1731 if (ha->flags.msix_enabled) {
1732 msix = &ha->msix_entries[1];
1733 DEBUG2_17(printk(KERN_INFO
1734 "Registering vector 0x%x for base que\n", msix->entry));
1735 icb->msix = cpu_to_le16(msix->entry);
1737 /* Use alternate PCI bus number */
1739 icb->firmware_options_2 |=
1740 __constant_cpu_to_le32(BIT_19);
1741 /* Use alternate PCI devfn */
1743 icb->firmware_options_2 |=
1744 __constant_cpu_to_le32(BIT_18);
1746 /* Use Disable MSIX Handshake mode for capable adapters */
1747 if (IS_MSIX_NACK_CAPABLE(ha)) {
1748 icb->firmware_options_2 &=
1749 __constant_cpu_to_le32(~BIT_22);
1750 ha->flags.disable_msix_handshake = 1;
1751 qla_printk(KERN_INFO, ha,
1752 "MSIX Handshake Disable Mode turned on\n");
1754 icb->firmware_options_2 |=
1755 __constant_cpu_to_le32(BIT_22);
1757 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
1759 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
1760 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
1761 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
1762 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
1764 WRT_REG_DWORD(®->isp24.req_q_in, 0);
1765 WRT_REG_DWORD(®->isp24.req_q_out, 0);
1766 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
1767 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
1770 RD_REG_DWORD(&ioreg->hccr);
1774 * qla2x00_init_rings() - Initializes firmware.
1777 * Beginning of request ring has initialization control block already built
1778 * by nvram config routine.
1780 * Returns 0 on success.
1783 qla2x00_init_rings(scsi_qla_host_t *vha)
1786 unsigned long flags = 0;
1788 struct qla_hw_data *ha = vha->hw;
1789 struct req_que *req;
1790 struct rsp_que *rsp;
1791 struct scsi_qla_host *vp;
1792 struct mid_init_cb_24xx *mid_init_cb =
1793 (struct mid_init_cb_24xx *) ha->init_cb;
1795 spin_lock_irqsave(&ha->hardware_lock, flags);
1797 /* Clear outstanding commands array. */
1798 for (que = 0; que < ha->max_req_queues; que++) {
1799 req = ha->req_q_map[que];
1802 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1803 req->outstanding_cmds[cnt] = NULL;
1805 req->current_outstanding_cmd = 1;
1807 /* Initialize firmware. */
1808 req->ring_ptr = req->ring;
1809 req->ring_index = 0;
1810 req->cnt = req->length;
1813 for (que = 0; que < ha->max_rsp_queues; que++) {
1814 rsp = ha->rsp_q_map[que];
1817 /* Initialize response queue entries */
1818 qla2x00_init_response_q_entries(rsp);
1821 spin_lock(&ha->vport_slock);
1822 /* Clear RSCN queue. */
1823 list_for_each_entry(vp, &ha->vp_list, list) {
1824 vp->rscn_in_ptr = 0;
1825 vp->rscn_out_ptr = 0;
1828 spin_unlock(&ha->vport_slock);
1830 ha->isp_ops->config_rings(vha);
1832 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1834 /* Update any ISP specific firmware options before initialization. */
1835 ha->isp_ops->update_fw_options(vha);
1837 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
1839 if (ha->flags.npiv_supported) {
1840 if (ha->operating_mode == LOOP)
1841 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
1842 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1845 if (IS_FWI2_CAPABLE(ha)) {
1846 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1847 mid_init_cb->init_cb.execution_throttle =
1848 cpu_to_le16(ha->fw_xcb_count);
1851 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
1853 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1856 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1864 * qla2x00_fw_ready() - Waits for firmware ready.
1867 * Returns 0 on success.
1870 qla2x00_fw_ready(scsi_qla_host_t *vha)
1873 unsigned long wtime, mtime, cs84xx_time;
1874 uint16_t min_wait; /* Minimum wait time if loop is down */
1875 uint16_t wait_time; /* Wait time if loop is coming ready */
1877 struct qla_hw_data *ha = vha->hw;
1881 /* 20 seconds for loop down. */
1885 * Firmware should take at most one RATOV to login, plus 5 seconds for
1886 * our own processing.
1888 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1889 wait_time = min_wait;
1892 /* Min wait time if loop down */
1893 mtime = jiffies + (min_wait * HZ);
1895 /* wait time before firmware ready */
1896 wtime = jiffies + (wait_time * HZ);
1898 /* Wait for ISP to finish LIP */
1899 if (!vha->flags.init_done)
1900 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1902 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1906 rval = qla2x00_get_firmware_state(vha, state);
1907 if (rval == QLA_SUCCESS) {
1908 if (state[0] < FSTATE_LOSS_OF_SYNC) {
1909 vha->device_flags &= ~DFLG_NO_CABLE;
1911 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1912 DEBUG16(printk("scsi(%ld): fw_state=%x "
1913 "84xx=%x.\n", vha->host_no, state[0],
1915 if ((state[2] & FSTATE_LOGGED_IN) &&
1916 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1917 DEBUG16(printk("scsi(%ld): Sending "
1918 "verify iocb.\n", vha->host_no));
1920 cs84xx_time = jiffies;
1921 rval = qla84xx_init_chip(vha);
1922 if (rval != QLA_SUCCESS)
1925 /* Add time taken to initialize. */
1926 cs84xx_time = jiffies - cs84xx_time;
1927 wtime += cs84xx_time;
1928 mtime += cs84xx_time;
1929 DEBUG16(printk("scsi(%ld): Increasing "
1930 "wait time by %ld. New time %ld\n",
1931 vha->host_no, cs84xx_time, wtime));
1933 } else if (state[0] == FSTATE_READY) {
1934 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1937 qla2x00_get_retry_cnt(vha, &ha->retry_count,
1938 &ha->login_timeout, &ha->r_a_tov);
1944 rval = QLA_FUNCTION_FAILED;
1946 if (atomic_read(&vha->loop_down_timer) &&
1947 state[0] != FSTATE_READY) {
1948 /* Loop down. Timeout on min_wait for states
1949 * other than Wait for Login.
1951 if (time_after_eq(jiffies, mtime)) {
1952 qla_printk(KERN_INFO, ha,
1953 "Cable is unplugged...\n");
1955 vha->device_flags |= DFLG_NO_CABLE;
1960 /* Mailbox cmd failed. Timeout on min_wait. */
1961 if (time_after_eq(jiffies, mtime) ||
1962 (IS_QLA82XX(ha) && ha->flags.fw_hung))
1966 if (time_after_eq(jiffies, wtime))
1969 /* Delay for a while */
1972 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1973 vha->host_no, state[0], jiffies));
1976 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1977 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1981 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1989 * qla2x00_configure_hba
1990 * Setup adapter context.
1993 * ha = adapter state pointer.
2002 qla2x00_configure_hba(scsi_qla_host_t *vha)
2011 char connect_type[22];
2012 struct qla_hw_data *ha = vha->hw;
2014 /* Get host addresses. */
2015 rval = qla2x00_get_adapter_id(vha,
2016 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
2017 if (rval != QLA_SUCCESS) {
2018 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
2019 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
2020 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
2021 __func__, vha->host_no));
2023 qla_printk(KERN_WARNING, ha,
2024 "ERROR -- Unable to get host loop ID.\n");
2025 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2031 qla_printk(KERN_INFO, ha,
2032 "Cannot get topology - retrying.\n");
2033 return (QLA_FUNCTION_FAILED);
2036 vha->loop_id = loop_id;
2039 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2040 ha->operating_mode = LOOP;
2045 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
2047 ha->current_topology = ISP_CFG_NL;
2048 strcpy(connect_type, "(Loop)");
2052 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
2054 ha->switch_cap = sw_cap;
2055 ha->current_topology = ISP_CFG_FL;
2056 strcpy(connect_type, "(FL_Port)");
2060 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
2062 ha->operating_mode = P2P;
2063 ha->current_topology = ISP_CFG_N;
2064 strcpy(connect_type, "(N_Port-to-N_Port)");
2068 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
2070 ha->switch_cap = sw_cap;
2071 ha->operating_mode = P2P;
2072 ha->current_topology = ISP_CFG_F;
2073 strcpy(connect_type, "(F_Port)");
2077 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
2079 vha->host_no, topo));
2080 ha->current_topology = ISP_CFG_NL;
2081 strcpy(connect_type, "(Loop)");
2085 /* Save Host port and loop ID. */
2086 /* byte order - Big Endian */
2087 vha->d_id.b.domain = domain;
2088 vha->d_id.b.area = area;
2089 vha->d_id.b.al_pa = al_pa;
2091 if (!vha->flags.init_done)
2092 qla_printk(KERN_INFO, ha,
2093 "Topology - %s, Host Loop address 0x%x\n",
2094 connect_type, vha->loop_id);
2097 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
2099 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
2106 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2111 struct qla_hw_data *ha = vha->hw;
2112 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
2113 !IS_QLA8XXX_TYPE(ha);
2115 if (memcmp(model, BINZERO, len) != 0) {
2116 strncpy(ha->model_number, model, len);
2117 st = en = ha->model_number;
2120 if (*en != 0x20 && *en != 0x00)
2125 index = (ha->pdev->subsystem_device & 0xff);
2127 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
2128 index < QLA_MODEL_NAMES)
2129 strncpy(ha->model_desc,
2130 qla2x00_model_name[index * 2 + 1],
2131 sizeof(ha->model_desc) - 1);
2133 index = (ha->pdev->subsystem_device & 0xff);
2135 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
2136 index < QLA_MODEL_NAMES) {
2137 strcpy(ha->model_number,
2138 qla2x00_model_name[index * 2]);
2139 strncpy(ha->model_desc,
2140 qla2x00_model_name[index * 2 + 1],
2141 sizeof(ha->model_desc) - 1);
2143 strcpy(ha->model_number, def);
2146 if (IS_FWI2_CAPABLE(ha))
2147 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
2148 sizeof(ha->model_desc));
2151 /* On sparc systems, obtain port and node WWN from firmware
2154 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
2157 struct qla_hw_data *ha = vha->hw;
2158 struct pci_dev *pdev = ha->pdev;
2159 struct device_node *dp = pci_device_to_OF_node(pdev);
2163 val = of_get_property(dp, "port-wwn", &len);
2164 if (val && len >= WWN_SIZE)
2165 memcpy(nv->port_name, val, WWN_SIZE);
2167 val = of_get_property(dp, "node-wwn", &len);
2168 if (val && len >= WWN_SIZE)
2169 memcpy(nv->node_name, val, WWN_SIZE);
2174 * NVRAM configuration for ISP 2xxx
2177 * ha = adapter block pointer.
2180 * initialization control block in response_ring
2181 * host adapters parameters in host adapter block
2187 qla2x00_nvram_config(scsi_qla_host_t *vha)
2192 uint8_t *dptr1, *dptr2;
2193 struct qla_hw_data *ha = vha->hw;
2194 init_cb_t *icb = ha->init_cb;
2195 nvram_t *nv = ha->nvram;
2196 uint8_t *ptr = ha->nvram;
2197 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2201 /* Determine NVRAM starting address. */
2202 ha->nvram_size = sizeof(nvram_t);
2204 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2205 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
2206 ha->nvram_base = 0x80;
2208 /* Get NVRAM data and calculate checksum. */
2209 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
2210 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2213 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
2214 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
2216 /* Bad NVRAM data, set defaults parameters. */
2217 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2218 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2219 /* Reset NVRAM data. */
2220 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
2221 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
2223 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
2224 "invalid -- WWPN) defaults.\n");
2227 * Set default initialization control block.
2229 memset(nv, 0, ha->nvram_size);
2230 nv->parameter_block_version = ICB_VERSION;
2232 if (IS_QLA23XX(ha)) {
2233 nv->firmware_options[0] = BIT_2 | BIT_1;
2234 nv->firmware_options[1] = BIT_7 | BIT_5;
2235 nv->add_firmware_options[0] = BIT_5;
2236 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2237 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2238 nv->special_options[1] = BIT_7;
2239 } else if (IS_QLA2200(ha)) {
2240 nv->firmware_options[0] = BIT_2 | BIT_1;
2241 nv->firmware_options[1] = BIT_7 | BIT_5;
2242 nv->add_firmware_options[0] = BIT_5;
2243 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2244 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2245 } else if (IS_QLA2100(ha)) {
2246 nv->firmware_options[0] = BIT_3 | BIT_1;
2247 nv->firmware_options[1] = BIT_5;
2248 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2251 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2252 nv->execution_throttle = __constant_cpu_to_le16(16);
2253 nv->retry_count = 8;
2254 nv->retry_delay = 1;
2256 nv->port_name[0] = 33;
2257 nv->port_name[3] = 224;
2258 nv->port_name[4] = 139;
2260 qla2xxx_nvram_wwn_from_ofw(vha, nv);
2262 nv->login_timeout = 4;
2265 * Set default host adapter parameters
2267 nv->host_p[1] = BIT_2;
2268 nv->reset_delay = 5;
2269 nv->port_down_retry_count = 8;
2270 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2271 nv->link_down_timeout = 60;
2276 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2278 * The SN2 does not provide BIOS emulation which means you can't change
2279 * potentially bogus BIOS settings. Force the use of default settings
2280 * for link rate and frame size. Hope that the rest of the settings
2283 if (ia64_platform_is("sn2")) {
2284 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2286 nv->special_options[1] = BIT_7;
2290 /* Reset Initialization control block */
2291 memset(icb, 0, ha->init_cb_size);
2294 * Setup driver NVRAM options.
2296 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2297 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2298 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2299 nv->firmware_options[1] &= ~BIT_4;
2301 if (IS_QLA23XX(ha)) {
2302 nv->firmware_options[0] |= BIT_2;
2303 nv->firmware_options[0] &= ~BIT_3;
2304 nv->firmware_options[0] &= ~BIT_6;
2305 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
2307 if (IS_QLA2300(ha)) {
2308 if (ha->fb_rev == FPM_2310) {
2309 strcpy(ha->model_number, "QLA2310");
2311 strcpy(ha->model_number, "QLA2300");
2314 qla2x00_set_model_info(vha, nv->model_number,
2315 sizeof(nv->model_number), "QLA23xx");
2317 } else if (IS_QLA2200(ha)) {
2318 nv->firmware_options[0] |= BIT_2;
2320 * 'Point-to-point preferred, else loop' is not a safe
2321 * connection mode setting.
2323 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2325 /* Force 'loop preferred, else point-to-point'. */
2326 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2327 nv->add_firmware_options[0] |= BIT_5;
2329 strcpy(ha->model_number, "QLA22xx");
2330 } else /*if (IS_QLA2100(ha))*/ {
2331 strcpy(ha->model_number, "QLA2100");
2335 * Copy over NVRAM RISC parameter block to initialization control block.
2337 dptr1 = (uint8_t *)icb;
2338 dptr2 = (uint8_t *)&nv->parameter_block_version;
2339 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2341 *dptr1++ = *dptr2++;
2343 /* Copy 2nd half. */
2344 dptr1 = (uint8_t *)icb->add_firmware_options;
2345 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2347 *dptr1++ = *dptr2++;
2349 /* Use alternate WWN? */
2350 if (nv->host_p[1] & BIT_7) {
2351 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2352 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2355 /* Prepare nodename */
2356 if ((icb->firmware_options[1] & BIT_6) == 0) {
2358 * Firmware will apply the following mask if the nodename was
2361 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2362 icb->node_name[0] &= 0xF0;
2366 * Set host adapter parameters.
2368 if (nv->host_p[0] & BIT_7)
2369 ql2xextended_error_logging = 1;
2370 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2371 /* Always load RISC code on non ISP2[12]00 chips. */
2372 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2373 ha->flags.disable_risc_code_load = 0;
2374 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2375 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2376 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
2377 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
2378 ha->flags.disable_serdes = 0;
2380 ha->operating_mode =
2381 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2383 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2384 sizeof(ha->fw_seriallink_options));
2386 /* save HBA serial number */
2387 ha->serial0 = icb->port_name[5];
2388 ha->serial1 = icb->port_name[6];
2389 ha->serial2 = icb->port_name[7];
2390 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2391 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
2393 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2395 ha->retry_count = nv->retry_count;
2397 /* Set minimum login_timeout to 4 seconds. */
2398 if (nv->login_timeout != ql2xlogintimeout)
2399 nv->login_timeout = ql2xlogintimeout;
2400 if (nv->login_timeout < 4)
2401 nv->login_timeout = 4;
2402 ha->login_timeout = nv->login_timeout;
2403 icb->login_timeout = nv->login_timeout;
2405 /* Set minimum RATOV to 100 tenths of a second. */
2408 ha->loop_reset_delay = nv->reset_delay;
2410 /* Link Down Timeout = 0:
2412 * When Port Down timer expires we will start returning
2413 * I/O's to OS with "DID_NO_CONNECT".
2415 * Link Down Timeout != 0:
2417 * The driver waits for the link to come up after link down
2418 * before returning I/Os to OS with "DID_NO_CONNECT".
2420 if (nv->link_down_timeout == 0) {
2421 ha->loop_down_abort_time =
2422 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
2424 ha->link_down_timeout = nv->link_down_timeout;
2425 ha->loop_down_abort_time =
2426 (LOOP_DOWN_TIME - ha->link_down_timeout);
2430 * Need enough time to try and get the port back.
2432 ha->port_down_retry_count = nv->port_down_retry_count;
2433 if (qlport_down_retry)
2434 ha->port_down_retry_count = qlport_down_retry;
2435 /* Set login_retry_count */
2436 ha->login_retry_count = nv->retry_count;
2437 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2438 ha->port_down_retry_count > 3)
2439 ha->login_retry_count = ha->port_down_retry_count;
2440 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2441 ha->login_retry_count = ha->port_down_retry_count;
2442 if (ql2xloginretrycount)
2443 ha->login_retry_count = ql2xloginretrycount;
2445 icb->lun_enables = __constant_cpu_to_le16(0);
2446 icb->command_resource_count = 0;
2447 icb->immediate_notify_resource_count = 0;
2448 icb->timeout = __constant_cpu_to_le16(0);
2450 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2452 icb->firmware_options[0] &= ~BIT_3;
2453 icb->add_firmware_options[0] &=
2454 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2455 icb->add_firmware_options[0] |= BIT_2;
2456 icb->response_accumulation_timer = 3;
2457 icb->interrupt_delay_timer = 5;
2459 vha->flags.process_response_queue = 1;
2462 if (!vha->flags.init_done) {
2463 ha->zio_mode = icb->add_firmware_options[0] &
2464 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2465 ha->zio_timer = icb->interrupt_delay_timer ?
2466 icb->interrupt_delay_timer: 2;
2468 icb->add_firmware_options[0] &=
2469 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2470 vha->flags.process_response_queue = 0;
2471 if (ha->zio_mode != QLA_ZIO_DISABLED) {
2472 ha->zio_mode = QLA_ZIO_MODE_6;
2474 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
2475 "delay (%d us).\n", vha->host_no, ha->zio_mode,
2476 ha->zio_timer * 100));
2477 qla_printk(KERN_INFO, ha,
2478 "ZIO mode %d enabled; timer delay (%d us).\n",
2479 ha->zio_mode, ha->zio_timer * 100);
2481 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2482 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
2483 vha->flags.process_response_queue = 1;
2488 DEBUG2_3(printk(KERN_WARNING
2489 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
2495 qla2x00_rport_del(void *data)
2497 fc_port_t *fcport = data;
2498 struct fc_rport *rport;
2500 spin_lock_irq(fcport->vha->host->host_lock);
2501 rport = fcport->drport ? fcport->drport: fcport->rport;
2502 fcport->drport = NULL;
2503 spin_unlock_irq(fcport->vha->host->host_lock);
2505 fc_remote_port_delete(rport);
2509 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2511 * @flags: allocation flags
2513 * Returns a pointer to the allocated fcport, or NULL, if none available.
2516 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
2520 fcport = kzalloc(sizeof(fc_port_t), flags);
2524 /* Setup fcport template structure. */
2526 fcport->vp_idx = vha->vp_idx;
2527 fcport->port_type = FCT_UNKNOWN;
2528 fcport->loop_id = FC_NO_LOOP_ID;
2529 atomic_set(&fcport->state, FCS_UNCONFIGURED);
2530 fcport->supported_classes = FC_COS_UNSPECIFIED;
2536 * qla2x00_configure_loop
2537 * Updates Fibre Channel Device Database with what is actually on loop.
2540 * ha = adapter block pointer.
2545 * 2 = database was full and device was not configured.
2548 qla2x00_configure_loop(scsi_qla_host_t *vha)
2551 unsigned long flags, save_flags;
2552 struct qla_hw_data *ha = vha->hw;
2555 /* Get Initiator ID */
2556 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2557 rval = qla2x00_configure_hba(vha);
2558 if (rval != QLA_SUCCESS) {
2559 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
2565 save_flags = flags = vha->dpc_flags;
2566 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
2567 vha->host_no, flags));
2570 * If we have both an RSCN and PORT UPDATE pending then handle them
2571 * both at the same time.
2573 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2574 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
2576 qla2x00_get_data_rate(vha);
2578 /* Determine what we need to do */
2579 if (ha->current_topology == ISP_CFG_FL &&
2580 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2582 vha->flags.rscn_queue_overflow = 1;
2583 set_bit(RSCN_UPDATE, &flags);
2585 } else if (ha->current_topology == ISP_CFG_F &&
2586 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2588 vha->flags.rscn_queue_overflow = 1;
2589 set_bit(RSCN_UPDATE, &flags);
2590 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2592 } else if (ha->current_topology == ISP_CFG_N) {
2593 clear_bit(RSCN_UPDATE, &flags);
2595 } else if (!vha->flags.online ||
2596 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2598 vha->flags.rscn_queue_overflow = 1;
2599 set_bit(RSCN_UPDATE, &flags);
2600 set_bit(LOCAL_LOOP_UPDATE, &flags);
2603 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
2604 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2605 rval = QLA_FUNCTION_FAILED;
2607 rval = qla2x00_configure_local_loop(vha);
2610 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
2611 if (LOOP_TRANSITION(vha))
2612 rval = QLA_FUNCTION_FAILED;
2614 rval = qla2x00_configure_fabric(vha);
2617 if (rval == QLA_SUCCESS) {
2618 if (atomic_read(&vha->loop_down_timer) ||
2619 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2620 rval = QLA_FUNCTION_FAILED;
2622 atomic_set(&vha->loop_state, LOOP_READY);
2624 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
2629 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
2630 __func__, vha->host_no));
2632 DEBUG3(printk("%s: exiting normally\n", __func__));
2635 /* Restore state if a resync event occurred during processing */
2636 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2637 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
2638 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2639 if (test_bit(RSCN_UPDATE, &save_flags)) {
2640 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2641 if (!IS_ALOGIO_CAPABLE(ha))
2642 vha->flags.rscn_queue_overflow = 1;
2652 * qla2x00_configure_local_loop
2653 * Updates Fibre Channel Device Database with local loop devices.
2656 * ha = adapter block pointer.
2662 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
2667 fc_port_t *fcport, *new_fcport;
2673 uint8_t domain, area, al_pa;
2674 struct qla_hw_data *ha = vha->hw;
2678 entries = MAX_FIBRE_DEVICES;
2680 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2681 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
2683 /* Get list of logged in devices. */
2684 memset(ha->gid_list, 0, GID_LIST_SIZE);
2685 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
2687 if (rval != QLA_SUCCESS)
2688 goto cleanup_allocation;
2690 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2691 vha->host_no, entries));
2692 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2693 entries * sizeof(struct gid_list_info)));
2695 /* Allocate temporary fcport for any new fcports discovered. */
2696 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2697 if (new_fcport == NULL) {
2698 rval = QLA_MEMORY_ALLOC_FAILED;
2699 goto cleanup_allocation;
2701 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2704 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2706 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2707 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2708 fcport->port_type != FCT_BROADCAST &&
2709 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2711 DEBUG(printk("scsi(%ld): Marking port lost, "
2713 vha->host_no, fcport->loop_id));
2715 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2719 /* Add devices to port list. */
2720 id_iter = (char *)ha->gid_list;
2721 for (index = 0; index < entries; index++) {
2722 domain = ((struct gid_list_info *)id_iter)->domain;
2723 area = ((struct gid_list_info *)id_iter)->area;
2724 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
2725 if (IS_QLA2100(ha) || IS_QLA2200(ha))
2726 loop_id = (uint16_t)
2727 ((struct gid_list_info *)id_iter)->loop_id_2100;
2729 loop_id = le16_to_cpu(
2730 ((struct gid_list_info *)id_iter)->loop_id);
2731 id_iter += ha->gid_list_info_size;
2733 /* Bypass reserved domain fields. */
2734 if ((domain & 0xf0) == 0xf0)
2737 /* Bypass if not same domain and area of adapter. */
2738 if (area && domain &&
2739 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
2742 /* Bypass invalid local loop ID. */
2743 if (loop_id > LAST_LOCAL_LOOP_ID)
2746 /* Fill in member data. */
2747 new_fcport->d_id.b.domain = domain;
2748 new_fcport->d_id.b.area = area;
2749 new_fcport->d_id.b.al_pa = al_pa;
2750 new_fcport->loop_id = loop_id;
2751 new_fcport->vp_idx = vha->vp_idx;
2752 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
2753 if (rval2 != QLA_SUCCESS) {
2754 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2755 "information -- get_port_database=%x, "
2757 vha->host_no, rval2, new_fcport->loop_id));
2758 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2760 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2764 /* Check for matching device in port list. */
2767 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2768 if (memcmp(new_fcport->port_name, fcport->port_name,
2772 fcport->flags &= ~FCF_FABRIC_DEVICE;
2773 fcport->loop_id = new_fcport->loop_id;
2774 fcport->port_type = new_fcport->port_type;
2775 fcport->d_id.b24 = new_fcport->d_id.b24;
2776 memcpy(fcport->node_name, new_fcport->node_name,
2784 /* New device, add to fcports list. */
2786 new_fcport->vha = vha;
2787 new_fcport->vp_idx = vha->vp_idx;
2789 list_add_tail(&new_fcport->list, &vha->vp_fcports);
2791 /* Allocate a new replacement fcport. */
2792 fcport = new_fcport;
2793 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2794 if (new_fcport == NULL) {
2795 rval = QLA_MEMORY_ALLOC_FAILED;
2796 goto cleanup_allocation;
2798 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2801 /* Base iIDMA settings on HBA port speed. */
2802 fcport->fp_speed = ha->link_data_rate;
2804 qla2x00_update_fcport(vha, fcport);
2812 if (rval != QLA_SUCCESS) {
2813 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2814 "rval=%x\n", vha->host_no, rval));
2821 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
2823 #define LS_UNKNOWN 2
2824 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2828 struct qla_hw_data *ha = vha->hw;
2830 if (!IS_IIDMA_CAPABLE(ha))
2833 if (atomic_read(&fcport->state) != FCS_ONLINE)
2836 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2837 fcport->fp_speed > ha->link_data_rate)
2840 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
2842 if (rval != QLA_SUCCESS) {
2843 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2844 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2845 vha->host_no, fcport->port_name[0], fcport->port_name[1],
2846 fcport->port_name[2], fcport->port_name[3],
2847 fcport->port_name[4], fcport->port_name[5],
2848 fcport->port_name[6], fcport->port_name[7], rval,
2849 fcport->fp_speed, mb[0], mb[1]));
2851 link_speed = link_speeds[LS_UNKNOWN];
2852 if (fcport->fp_speed < 5)
2853 link_speed = link_speeds[fcport->fp_speed];
2854 else if (fcport->fp_speed == 0x13)
2855 link_speed = link_speeds[5];
2856 DEBUG2(qla_printk(KERN_INFO, ha,
2857 "iIDMA adjusted to %s GB/s on "
2858 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2859 link_speed, fcport->port_name[0],
2860 fcport->port_name[1], fcport->port_name[2],
2861 fcport->port_name[3], fcport->port_name[4],
2862 fcport->port_name[5], fcport->port_name[6],
2863 fcport->port_name[7]));
2868 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
2870 struct fc_rport_identifiers rport_ids;
2871 struct fc_rport *rport;
2872 struct qla_hw_data *ha = vha->hw;
2874 qla2x00_rport_del(fcport);
2876 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2877 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2878 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2879 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2880 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2881 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
2883 qla_printk(KERN_WARNING, ha,
2884 "Unable to allocate fc remote port!\n");
2887 spin_lock_irq(fcport->vha->host->host_lock);
2888 *((fc_port_t **)rport->dd_data) = fcport;
2889 spin_unlock_irq(fcport->vha->host->host_lock);
2891 rport->supported_classes = fcport->supported_classes;
2893 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2894 if (fcport->port_type == FCT_INITIATOR)
2895 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2896 if (fcport->port_type == FCT_TARGET)
2897 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2898 fc_remote_port_rolechg(rport, rport_ids.roles);
2902 * qla2x00_update_fcport
2903 * Updates device on list.
2906 * ha = adapter block pointer.
2907 * fcport = port structure pointer.
2917 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
2920 fcport->login_retry = 0;
2921 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
2923 qla2x00_iidma_fcport(vha, fcport);
2924 atomic_set(&fcport->state, FCS_ONLINE);
2925 qla2x00_reg_remote_port(vha, fcport);
2929 * qla2x00_configure_fabric
2930 * Setup SNS devices with loop ID's.
2933 * ha = adapter block pointer.
2940 qla2x00_configure_fabric(scsi_qla_host_t *vha)
2943 fc_port_t *fcport, *fcptemp;
2944 uint16_t next_loopid;
2945 uint16_t mb[MAILBOX_REGISTER_COUNT];
2947 LIST_HEAD(new_fcports);
2948 struct qla_hw_data *ha = vha->hw;
2949 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2951 /* If FL port exists, then SNS is present */
2952 if (IS_FWI2_CAPABLE(ha))
2953 loop_id = NPH_F_PORT;
2955 loop_id = SNS_FL_PORT;
2956 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
2957 if (rval != QLA_SUCCESS) {
2958 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2959 "Port\n", vha->host_no));
2961 vha->device_flags &= ~SWITCH_FOUND;
2962 return (QLA_SUCCESS);
2964 vha->device_flags |= SWITCH_FOUND;
2966 /* Mark devices that need re-synchronization. */
2967 rval2 = qla2x00_device_resync(vha);
2968 if (rval2 == QLA_RSCNS_HANDLED) {
2969 /* No point doing the scan, just continue. */
2970 return (QLA_SUCCESS);
2974 if (ql2xfdmienable &&
2975 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2976 qla2x00_fdmi_register(vha);
2978 /* Ensure we are logged into the SNS. */
2979 if (IS_FWI2_CAPABLE(ha))
2982 loop_id = SIMPLE_NAME_SERVER;
2983 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
2984 0xfc, mb, BIT_1 | BIT_0);
2985 if (mb[0] != MBS_COMMAND_COMPLETE) {
2986 DEBUG2(qla_printk(KERN_INFO, ha,
2987 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2988 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2989 mb[0], mb[1], mb[2], mb[6], mb[7]));
2990 return (QLA_SUCCESS);
2993 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2994 if (qla2x00_rft_id(vha)) {
2996 DEBUG2(printk("scsi(%ld): Register FC-4 "
2997 "TYPE failed.\n", vha->host_no));
2999 if (qla2x00_rff_id(vha)) {
3001 DEBUG2(printk("scsi(%ld): Register FC-4 "
3002 "Features failed.\n", vha->host_no));
3004 if (qla2x00_rnn_id(vha)) {
3006 DEBUG2(printk("scsi(%ld): Register Node Name "
3007 "failed.\n", vha->host_no));
3008 } else if (qla2x00_rsnn_nn(vha)) {
3010 DEBUG2(printk("scsi(%ld): Register Symbolic "
3011 "Node Name failed.\n", vha->host_no));
3015 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
3016 if (rval != QLA_SUCCESS)
3020 * Logout all previous fabric devices marked lost, except
3023 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3024 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3027 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3030 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
3031 qla2x00_mark_device_lost(vha, fcport,
3032 ql2xplogiabsentdevice, 0);
3033 if (fcport->loop_id != FC_NO_LOOP_ID &&
3034 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
3035 fcport->port_type != FCT_INITIATOR &&
3036 fcport->port_type != FCT_BROADCAST) {
3037 ha->isp_ops->fabric_logout(vha,
3039 fcport->d_id.b.domain,
3040 fcport->d_id.b.area,
3041 fcport->d_id.b.al_pa);
3042 fcport->loop_id = FC_NO_LOOP_ID;
3047 /* Starting free loop ID. */
3048 next_loopid = ha->min_external_loopid;
3051 * Scan through our port list and login entries that need to be
3054 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3055 if (atomic_read(&vha->loop_down_timer) ||
3056 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3059 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3060 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3063 if (fcport->loop_id == FC_NO_LOOP_ID) {
3064 fcport->loop_id = next_loopid;
3065 rval = qla2x00_find_new_loop_id(
3067 if (rval != QLA_SUCCESS) {
3068 /* Ran out of IDs to use */
3072 /* Login and update database */
3073 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
3076 /* Exit if out of loop IDs. */
3077 if (rval != QLA_SUCCESS) {
3082 * Login and add the new devices to our port list.
3084 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3085 if (atomic_read(&vha->loop_down_timer) ||
3086 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3089 /* Find a new loop ID to use. */
3090 fcport->loop_id = next_loopid;
3091 rval = qla2x00_find_new_loop_id(base_vha, fcport);
3092 if (rval != QLA_SUCCESS) {
3093 /* Ran out of IDs to use */
3097 /* Login and update database */
3098 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
3102 fcport->vp_idx = vha->vp_idx;
3104 list_move_tail(&fcport->list, &vha->vp_fcports);
3108 /* Free all new device structures not processed. */
3109 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3110 list_del(&fcport->list);
3115 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
3116 "rval=%d\n", vha->host_no, rval));
3123 * qla2x00_find_all_fabric_devs
3126 * ha = adapter block pointer.
3127 * dev = database device entry pointer.
3136 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3137 struct list_head *new_fcports)
3141 fc_port_t *fcport, *new_fcport, *fcptemp;
3146 int first_dev, last_dev;
3147 port_id_t wrap = {}, nxt_d_id;
3148 struct qla_hw_data *ha = vha->hw;
3149 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
3150 struct scsi_qla_host *tvp;
3154 /* Try GID_PT to get device list, else GAN. */
3155 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
3158 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
3159 "on GA_NXT\n", vha->host_no));
3161 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
3164 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
3167 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
3170 } else if (ql2xiidmaenable &&
3171 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3172 qla2x00_gpsc(vha, swl);
3175 /* If other queries succeeded probe for FC-4 type */
3177 qla2x00_gff_id(vha, swl);
3181 /* Allocate temporary fcport for any new fcports discovered. */
3182 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
3183 if (new_fcport == NULL) {
3185 return (QLA_MEMORY_ALLOC_FAILED);
3187 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3188 /* Set start port ID scan at adapter ID. */
3192 /* Starting free loop ID. */
3193 loop_id = ha->min_external_loopid;
3194 for (; loop_id <= ha->max_loop_id; loop_id++) {
3195 if (qla2x00_is_reserved_id(vha, loop_id))
3198 if (ha->current_topology == ISP_CFG_FL &&
3199 (atomic_read(&vha->loop_down_timer) ||
3200 LOOP_TRANSITION(vha))) {
3201 atomic_set(&vha->loop_down_timer, 0);
3202 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3203 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
3209 wrap.b24 = new_fcport->d_id.b24;
3211 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3212 memcpy(new_fcport->node_name,
3213 swl[swl_idx].node_name, WWN_SIZE);
3214 memcpy(new_fcport->port_name,
3215 swl[swl_idx].port_name, WWN_SIZE);
3216 memcpy(new_fcport->fabric_port_name,
3217 swl[swl_idx].fabric_port_name, WWN_SIZE);
3218 new_fcport->fp_speed = swl[swl_idx].fp_speed;
3219 new_fcport->fc4_type = swl[swl_idx].fc4_type;
3221 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3227 /* Send GA_NXT to the switch */
3228 rval = qla2x00_ga_nxt(vha, new_fcport);
3229 if (rval != QLA_SUCCESS) {
3230 qla_printk(KERN_WARNING, ha,
3231 "SNS scan failed -- assuming zero-entry "
3233 list_for_each_entry_safe(fcport, fcptemp,
3234 new_fcports, list) {
3235 list_del(&fcport->list);
3243 /* If wrap on switch device list, exit. */
3245 wrap.b24 = new_fcport->d_id.b24;
3247 } else if (new_fcport->d_id.b24 == wrap.b24) {
3248 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
3249 vha->host_no, new_fcport->d_id.b.domain,
3250 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
3254 /* Bypass if same physical adapter. */
3255 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
3258 /* Bypass virtual ports of the same host. */
3260 if (ha->num_vhosts) {
3261 unsigned long flags;
3263 spin_lock_irqsave(&ha->vport_slock, flags);
3264 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
3265 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3270 spin_unlock_irqrestore(&ha->vport_slock, flags);
3276 /* Bypass if same domain and area of adapter. */
3277 if (((new_fcport->d_id.b24 & 0xffff00) ==
3278 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
3282 /* Bypass reserved domain fields. */
3283 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3286 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
3287 if (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3288 new_fcport->fc4_type != FC4_TYPE_UNKNOWN)
3291 /* Locate matching device in database. */
3293 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3294 if (memcmp(new_fcport->port_name, fcport->port_name,
3300 /* Update port state. */
3301 memcpy(fcport->fabric_port_name,
3302 new_fcport->fabric_port_name, WWN_SIZE);
3303 fcport->fp_speed = new_fcport->fp_speed;
3306 * If address the same and state FCS_ONLINE, nothing
3309 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3310 atomic_read(&fcport->state) == FCS_ONLINE) {
3315 * If device was not a fabric device before.
3317 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3318 fcport->d_id.b24 = new_fcport->d_id.b24;
3319 fcport->loop_id = FC_NO_LOOP_ID;
3320 fcport->flags |= (FCF_FABRIC_DEVICE |
3326 * Port ID changed or device was marked to be updated;
3327 * Log it out if still logged in and mark it for
3330 fcport->d_id.b24 = new_fcport->d_id.b24;
3331 fcport->flags |= FCF_LOGIN_NEEDED;
3332 if (fcport->loop_id != FC_NO_LOOP_ID &&
3333 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
3334 fcport->port_type != FCT_INITIATOR &&
3335 fcport->port_type != FCT_BROADCAST) {
3336 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3337 fcport->d_id.b.domain, fcport->d_id.b.area,
3338 fcport->d_id.b.al_pa);
3339 fcport->loop_id = FC_NO_LOOP_ID;
3347 /* If device was not in our fcports list, then add it. */
3348 list_add_tail(&new_fcport->list, new_fcports);
3350 /* Allocate a new replacement fcport. */
3351 nxt_d_id.b24 = new_fcport->d_id.b24;
3352 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
3353 if (new_fcport == NULL) {
3355 return (QLA_MEMORY_ALLOC_FAILED);
3357 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3358 new_fcport->d_id.b24 = nxt_d_id.b24;
3368 * qla2x00_find_new_loop_id
3369 * Scan through our port list and find a new usable loop ID.
3372 * ha: adapter state pointer.
3373 * dev: port structure pointer.
3376 * qla2x00 local function return status code.
3382 qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
3387 uint16_t first_loop_id;
3388 struct qla_hw_data *ha = vha->hw;
3389 struct scsi_qla_host *vp;
3390 struct scsi_qla_host *tvp;
3391 unsigned long flags = 0;
3395 /* Save starting loop ID. */
3396 first_loop_id = dev->loop_id;
3399 /* Skip loop ID if already used by adapter. */
3400 if (dev->loop_id == vha->loop_id)
3403 /* Skip reserved loop IDs. */
3404 while (qla2x00_is_reserved_id(vha, dev->loop_id))
3407 /* Reset loop ID if passed the end. */
3408 if (dev->loop_id > ha->max_loop_id) {
3409 /* first loop ID. */
3410 dev->loop_id = ha->min_external_loopid;
3413 /* Check for loop ID being already in use. */
3417 spin_lock_irqsave(&ha->vport_slock, flags);
3418 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
3419 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3420 if (fcport->loop_id == dev->loop_id &&
3422 /* ID possibly in use */
3430 spin_unlock_irqrestore(&ha->vport_slock, flags);
3432 /* If not in use then it is free to use. */
3437 /* ID in use. Try next value. */
3440 /* If wrap around. No free ID to use. */
3441 if (dev->loop_id == first_loop_id) {
3442 dev->loop_id = FC_NO_LOOP_ID;
3443 rval = QLA_FUNCTION_FAILED;
3452 * qla2x00_device_resync
3453 * Marks devices in the database that needs resynchronization.
3456 * ha = adapter block pointer.
3462 qla2x00_device_resync(scsi_qla_host_t *vha)
3467 uint32_t rscn_entry;
3468 uint8_t rscn_out_iter;
3470 port_id_t d_id = {};
3472 rval = QLA_RSCNS_HANDLED;
3474 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3475 vha->flags.rscn_queue_overflow) {
3477 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
3478 format = MSB(MSW(rscn_entry));
3479 d_id.b.domain = LSB(MSW(rscn_entry));
3480 d_id.b.area = MSB(LSW(rscn_entry));
3481 d_id.b.al_pa = LSB(LSW(rscn_entry));
3483 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3484 "[%02x/%02x%02x%02x].\n",
3485 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
3486 d_id.b.area, d_id.b.al_pa));
3488 vha->rscn_out_ptr++;
3489 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3490 vha->rscn_out_ptr = 0;
3492 /* Skip duplicate entries. */
3493 for (rscn_out_iter = vha->rscn_out_ptr;
3494 !vha->flags.rscn_queue_overflow &&
3495 rscn_out_iter != vha->rscn_in_ptr;
3496 rscn_out_iter = (rscn_out_iter ==
3497 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3499 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
3502 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
3503 "entry found at [%d].\n", vha->host_no,
3506 vha->rscn_out_ptr = rscn_out_iter;
3509 /* Queue overflow, set switch default case. */
3510 if (vha->flags.rscn_queue_overflow) {
3511 DEBUG(printk("scsi(%ld): device_resync: rscn "
3512 "overflow.\n", vha->host_no));
3515 vha->flags.rscn_queue_overflow = 0;
3531 vha->rscn_out_ptr = vha->rscn_in_ptr;
3537 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3538 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3539 (fcport->d_id.b24 & mask) != d_id.b24 ||
3540 fcport->port_type == FCT_BROADCAST)
3543 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3545 fcport->port_type != FCT_INITIATOR) {
3546 qla2x00_mark_device_lost(vha, fcport,
3556 * qla2x00_fabric_dev_login
3557 * Login fabric target device and update FC port database.
3560 * ha: adapter state pointer.
3561 * fcport: port structure list pointer.
3562 * next_loopid: contains value of a new loop ID that can be used
3563 * by the next login attempt.
3566 * qla2x00 local function return status code.
3572 qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
3573 uint16_t *next_loopid)
3578 struct qla_hw_data *ha = vha->hw;
3583 if (IS_ALOGIO_CAPABLE(ha)) {
3584 if (fcport->flags & FCF_ASYNC_SENT)
3586 fcport->flags |= FCF_ASYNC_SENT;
3587 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3592 fcport->flags &= ~FCF_ASYNC_SENT;
3593 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
3594 if (rval == QLA_SUCCESS) {
3595 /* Send an ADISC to FCP2 devices.*/
3597 if (fcport->flags & FCF_FCP2_DEVICE)
3599 rval = qla2x00_get_port_database(vha, fcport, opts);
3600 if (rval != QLA_SUCCESS) {
3601 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3602 fcport->d_id.b.domain, fcport->d_id.b.area,
3603 fcport->d_id.b.al_pa);
3604 qla2x00_mark_device_lost(vha, fcport, 1, 0);
3606 qla2x00_update_fcport(vha, fcport);
3614 * qla2x00_fabric_login
3615 * Issue fabric login command.
3618 * ha = adapter block pointer.
3619 * device = pointer to FC device type structure.
3622 * 0 - Login successfully
3624 * 2 - Initiator device
3628 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
3629 uint16_t *next_loopid)
3633 uint16_t tmp_loopid;
3634 uint16_t mb[MAILBOX_REGISTER_COUNT];
3635 struct qla_hw_data *ha = vha->hw;
3641 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3642 "for port %02x%02x%02x.\n",
3643 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
3644 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3646 /* Login fcport on switch. */
3647 ha->isp_ops->fabric_login(vha, fcport->loop_id,
3648 fcport->d_id.b.domain, fcport->d_id.b.area,
3649 fcport->d_id.b.al_pa, mb, BIT_0);
3650 if (mb[0] == MBS_PORT_ID_USED) {
3652 * Device has another loop ID. The firmware team
3653 * recommends the driver perform an implicit login with
3654 * the specified ID again. The ID we just used is save
3655 * here so we return with an ID that can be tried by
3659 tmp_loopid = fcport->loop_id;
3660 fcport->loop_id = mb[1];
3662 DEBUG(printk("Fabric Login: port in use - next "
3663 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3664 fcport->loop_id, fcport->d_id.b.domain,
3665 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3667 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3672 /* A retry occurred before. */
3673 *next_loopid = tmp_loopid;
3676 * No retry occurred before. Just increment the
3677 * ID value for next login.
3679 *next_loopid = (fcport->loop_id + 1);
3682 if (mb[1] & BIT_0) {
3683 fcport->port_type = FCT_INITIATOR;
3685 fcport->port_type = FCT_TARGET;
3686 if (mb[1] & BIT_1) {
3687 fcport->flags |= FCF_FCP2_DEVICE;
3692 fcport->supported_classes |= FC_COS_CLASS2;
3694 fcport->supported_classes |= FC_COS_CLASS3;
3698 } else if (mb[0] == MBS_LOOP_ID_USED) {
3700 * Loop ID already used, try next loop ID.
3703 rval = qla2x00_find_new_loop_id(vha, fcport);
3704 if (rval != QLA_SUCCESS) {
3705 /* Ran out of loop IDs to use */
3708 } else if (mb[0] == MBS_COMMAND_ERROR) {
3710 * Firmware possibly timed out during login. If NO
3711 * retries are left to do then the device is declared
3714 *next_loopid = fcport->loop_id;
3715 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3716 fcport->d_id.b.domain, fcport->d_id.b.area,
3717 fcport->d_id.b.al_pa);
3718 qla2x00_mark_device_lost(vha, fcport, 1, 0);
3724 * unrecoverable / not handled error
3726 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3727 "loop_id=%x jiffies=%lx.\n",
3728 __func__, vha->host_no, mb[0],
3729 fcport->d_id.b.domain, fcport->d_id.b.area,
3730 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3732 *next_loopid = fcport->loop_id;
3733 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3734 fcport->d_id.b.domain, fcport->d_id.b.area,
3735 fcport->d_id.b.al_pa);
3736 fcport->loop_id = FC_NO_LOOP_ID;
3737 fcport->login_retry = 0;
3748 * qla2x00_local_device_login
3749 * Issue local device login command.
3752 * ha = adapter block pointer.
3753 * loop_id = loop id of device to login to.
3755 * Returns (Where's the #define!!!!):
3756 * 0 - Login successfully
3761 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
3764 uint16_t mb[MAILBOX_REGISTER_COUNT];
3766 memset(mb, 0, sizeof(mb));
3767 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
3768 if (rval == QLA_SUCCESS) {
3769 /* Interrogate mailbox registers for any errors */
3770 if (mb[0] == MBS_COMMAND_ERROR)
3772 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3773 /* device not in PCB table */
3781 * qla2x00_loop_resync
3782 * Resync with fibre channel devices.
3785 * ha = adapter block pointer.
3791 qla2x00_loop_resync(scsi_qla_host_t *vha)
3793 int rval = QLA_SUCCESS;
3795 struct req_que *req;
3796 struct rsp_que *rsp;
3798 if (vha->hw->flags.cpu_affinity_enabled)
3799 req = vha->hw->req_q_map[0];
3804 atomic_set(&vha->loop_state, LOOP_UPDATE);
3805 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3806 if (vha->flags.online) {
3807 if (!(rval = qla2x00_fw_ready(vha))) {
3808 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3811 atomic_set(&vha->loop_state, LOOP_UPDATE);
3813 /* Issue a marker after FW becomes ready. */
3814 qla2x00_marker(vha, req, rsp, 0, 0,
3816 vha->marker_needed = 0;
3818 /* Remap devices on Loop. */
3819 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3821 qla2x00_configure_loop(vha);
3823 } while (!atomic_read(&vha->loop_down_timer) &&
3824 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3825 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3830 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3831 return (QLA_FUNCTION_FAILED);
3834 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3840 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
3843 struct scsi_qla_host *vha;
3844 struct qla_hw_data *ha = base_vha->hw;
3845 unsigned long flags;
3847 spin_lock_irqsave(&ha->vport_slock, flags);
3848 /* Go with deferred removal of rport references. */
3849 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
3850 atomic_inc(&vha->vref_count);
3851 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3852 if (fcport && fcport->drport &&
3853 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
3854 spin_unlock_irqrestore(&ha->vport_slock, flags);
3856 qla2x00_rport_del(fcport);
3858 spin_lock_irqsave(&ha->vport_slock, flags);
3861 atomic_dec(&vha->vref_count);
3863 spin_unlock_irqrestore(&ha->vport_slock, flags);
3867 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3869 struct qla_hw_data *ha = vha->hw;
3870 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
3871 unsigned long flags;
3873 vha->flags.online = 0;
3874 ha->flags.chip_reset_done = 0;
3875 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3876 ha->qla_stats.total_isp_aborts++;
3878 qla_printk(KERN_INFO, ha,
3879 "Performing ISP error recovery - ha= %p.\n", ha);
3881 /* Chip reset does not apply to 82XX */
3882 if (!IS_QLA82XX(ha))
3883 ha->isp_ops->reset_chip(vha);
3885 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3886 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3887 atomic_set(&vha->loop_state, LOOP_DOWN);
3888 qla2x00_mark_all_devices_lost(vha, 0);
3890 spin_lock_irqsave(&ha->vport_slock, flags);
3891 list_for_each_entry(vp, &base_vha->hw->vp_list, list) {
3892 atomic_inc(&vp->vref_count);
3893 spin_unlock_irqrestore(&ha->vport_slock, flags);
3895 qla2x00_mark_all_devices_lost(vp, 0);
3897 spin_lock_irqsave(&ha->vport_slock, flags);
3898 atomic_dec(&vp->vref_count);
3900 spin_unlock_irqrestore(&ha->vport_slock, flags);
3902 if (!atomic_read(&vha->loop_down_timer))
3903 atomic_set(&vha->loop_down_timer,
3907 if (!ha->flags.eeh_busy) {
3908 /* Make sure for ISP 82XX IO DMA is complete */
3909 if (IS_QLA82XX(ha)) {
3910 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0,
3911 WAIT_HOST) == QLA_SUCCESS) {
3912 DEBUG2(qla_printk(KERN_INFO, ha,
3913 "Done wait for pending commands\n"));
3917 /* Requeue all commands in outstanding command list. */
3918 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
3924 * Resets ISP and aborts all outstanding commands.
3927 * ha = adapter block pointer.
3933 qla2x00_abort_isp(scsi_qla_host_t *vha)
3937 struct qla_hw_data *ha = vha->hw;
3938 struct scsi_qla_host *vp;
3939 struct req_que *req = ha->req_q_map[0];
3940 unsigned long flags;
3942 if (vha->flags.online) {
3943 qla2x00_abort_isp_cleanup(vha);
3945 if (unlikely(pci_channel_offline(ha->pdev) &&
3946 ha->flags.pci_channel_io_perm_failure)) {
3947 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3952 ha->isp_ops->get_flash_version(vha, req->ring);
3954 ha->isp_ops->nvram_config(vha);
3956 if (!qla2x00_restart_isp(vha)) {
3957 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
3959 if (!atomic_read(&vha->loop_down_timer)) {
3961 * Issue marker command only when we are going
3962 * to start the I/O .
3964 vha->marker_needed = 1;
3967 vha->flags.online = 1;
3969 ha->isp_ops->enable_intrs(ha);
3971 ha->isp_abort_cnt = 0;
3972 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3975 qla2x00_get_fw_version(vha,
3976 &ha->fw_major_version,
3977 &ha->fw_minor_version,
3978 &ha->fw_subminor_version,
3979 &ha->fw_attributes, &ha->fw_memory_size,
3980 ha->mpi_version, &ha->mpi_capabilities,
3984 ha->flags.fce_enabled = 1;
3986 fce_calc_size(ha->fce_bufs));
3987 rval = qla2x00_enable_fce_trace(vha,
3988 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3991 qla_printk(KERN_WARNING, ha,
3992 "Unable to reinitialize FCE "
3994 ha->flags.fce_enabled = 0;
3999 memset(ha->eft, 0, EFT_SIZE);
4000 rval = qla2x00_enable_eft_trace(vha,
4001 ha->eft_dma, EFT_NUM_BUFFERS);
4003 qla_printk(KERN_WARNING, ha,
4004 "Unable to reinitialize EFT "
4008 } else { /* failed the ISP abort */
4009 vha->flags.online = 1;
4010 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
4011 if (ha->isp_abort_cnt == 0) {
4012 qla_printk(KERN_WARNING, ha,
4013 "ISP error recovery failed - "
4014 "board disabled\n");
4016 * The next call disables the board
4019 ha->isp_ops->reset_adapter(vha);
4020 vha->flags.online = 0;
4021 clear_bit(ISP_ABORT_RETRY,
4024 } else { /* schedule another ISP abort */
4025 ha->isp_abort_cnt--;
4026 DEBUG(printk("qla%ld: ISP abort - "
4027 "retry remaining %d\n",
4028 vha->host_no, ha->isp_abort_cnt));
4032 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
4033 DEBUG(printk("qla2x00(%ld): ISP error recovery "
4034 "- retrying (%d) more times\n",
4035 vha->host_no, ha->isp_abort_cnt));
4036 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4044 DEBUG(printk(KERN_INFO
4045 "qla2x00_abort_isp(%ld): succeeded.\n",
4048 spin_lock_irqsave(&ha->vport_slock, flags);
4049 list_for_each_entry(vp, &ha->vp_list, list) {
4051 atomic_inc(&vp->vref_count);
4052 spin_unlock_irqrestore(&ha->vport_slock, flags);
4054 qla2x00_vp_abort_isp(vp);
4056 spin_lock_irqsave(&ha->vport_slock, flags);
4057 atomic_dec(&vp->vref_count);
4060 spin_unlock_irqrestore(&ha->vport_slock, flags);
4063 qla_printk(KERN_INFO, ha,
4064 "qla2x00_abort_isp: **** FAILED ****\n");
4071 * qla2x00_restart_isp
4072 * restarts the ISP after a reset
4075 * ha = adapter block pointer.
4081 qla2x00_restart_isp(scsi_qla_host_t *vha)
4085 struct qla_hw_data *ha = vha->hw;
4086 struct req_que *req = ha->req_q_map[0];
4087 struct rsp_que *rsp = ha->rsp_q_map[0];
4089 /* If firmware needs to be loaded */
4090 if (qla2x00_isp_firmware(vha)) {
4091 vha->flags.online = 0;
4092 status = ha->isp_ops->chip_diag(vha);
4094 status = qla2x00_setup_chip(vha);
4097 if (!status && !(status = qla2x00_init_rings(vha))) {
4098 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
4099 ha->flags.chip_reset_done = 1;
4100 /* Initialize the queues in use */
4101 qla25xx_init_queues(ha);
4103 status = qla2x00_fw_ready(vha);
4105 DEBUG(printk("%s(): Start configure loop, "
4106 "status = %d\n", __func__, status));
4108 /* Issue a marker after FW becomes ready. */
4109 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
4111 vha->flags.online = 1;
4112 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4115 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4116 qla2x00_configure_loop(vha);
4118 } while (!atomic_read(&vha->loop_down_timer) &&
4119 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4120 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4124 /* if no cable then assume it's good */
4125 if ((vha->device_flags & DFLG_NO_CABLE))
4128 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
4136 qla25xx_init_queues(struct qla_hw_data *ha)
4138 struct rsp_que *rsp = NULL;
4139 struct req_que *req = NULL;
4140 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4144 for (i = 1; i < ha->max_rsp_queues; i++) {
4145 rsp = ha->rsp_q_map[i];
4147 rsp->options &= ~BIT_0;
4148 ret = qla25xx_init_rsp_que(base_vha, rsp);
4149 if (ret != QLA_SUCCESS)
4150 DEBUG2_17(printk(KERN_WARNING
4151 "%s Rsp que:%d init failed\n", __func__,
4154 DEBUG2_17(printk(KERN_INFO
4155 "%s Rsp que:%d inited\n", __func__,
4159 for (i = 1; i < ha->max_req_queues; i++) {
4160 req = ha->req_q_map[i];
4162 /* Clear outstanding commands array. */
4163 req->options &= ~BIT_0;
4164 ret = qla25xx_init_req_que(base_vha, req);
4165 if (ret != QLA_SUCCESS)
4166 DEBUG2_17(printk(KERN_WARNING
4167 "%s Req que:%d init failed\n", __func__,
4170 DEBUG2_17(printk(KERN_WARNING
4171 "%s Req que:%d inited\n", __func__,
4179 * qla2x00_reset_adapter
4183 * ha = adapter block pointer.
4186 qla2x00_reset_adapter(scsi_qla_host_t *vha)
4188 unsigned long flags = 0;
4189 struct qla_hw_data *ha = vha->hw;
4190 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4192 vha->flags.online = 0;
4193 ha->isp_ops->disable_intrs(ha);
4195 spin_lock_irqsave(&ha->hardware_lock, flags);
4196 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
4197 RD_REG_WORD(®->hccr); /* PCI Posting. */
4198 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
4199 RD_REG_WORD(®->hccr); /* PCI Posting. */
4200 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4204 qla24xx_reset_adapter(scsi_qla_host_t *vha)
4206 unsigned long flags = 0;
4207 struct qla_hw_data *ha = vha->hw;
4208 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4213 vha->flags.online = 0;
4214 ha->isp_ops->disable_intrs(ha);
4216 spin_lock_irqsave(&ha->hardware_lock, flags);
4217 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
4218 RD_REG_DWORD(®->hccr);
4219 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
4220 RD_REG_DWORD(®->hccr);
4221 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4223 if (IS_NOPOLLING_TYPE(ha))
4224 ha->isp_ops->enable_intrs(ha);
4227 /* On sparc systems, obtain port and node WWN from firmware
4230 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4231 struct nvram_24xx *nv)
4234 struct qla_hw_data *ha = vha->hw;
4235 struct pci_dev *pdev = ha->pdev;
4236 struct device_node *dp = pci_device_to_OF_node(pdev);
4240 val = of_get_property(dp, "port-wwn", &len);
4241 if (val && len >= WWN_SIZE)
4242 memcpy(nv->port_name, val, WWN_SIZE);
4244 val = of_get_property(dp, "node-wwn", &len);
4245 if (val && len >= WWN_SIZE)
4246 memcpy(nv->node_name, val, WWN_SIZE);
4251 qla24xx_nvram_config(scsi_qla_host_t *vha)
4254 struct init_cb_24xx *icb;
4255 struct nvram_24xx *nv;
4257 uint8_t *dptr1, *dptr2;
4260 struct qla_hw_data *ha = vha->hw;
4263 icb = (struct init_cb_24xx *)ha->init_cb;
4266 /* Determine NVRAM starting address. */
4267 if (ha->flags.port0) {
4268 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4269 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4271 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
4272 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4274 ha->nvram_size = sizeof(struct nvram_24xx);
4275 ha->vpd_size = FA_NVRAM_VPD_SIZE;
4277 ha->vpd_size = FA_VPD_SIZE_82XX;
4279 /* Get VPD data into cache */
4280 ha->vpd = ha->nvram + VPD_OFFSET;
4281 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
4282 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4284 /* Get NVRAM data into cache and calculate checksum. */
4285 dptr = (uint32_t *)nv;
4286 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
4288 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4289 chksum += le32_to_cpu(*dptr++);
4291 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
4292 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4294 /* Bad NVRAM data, set defaults parameters. */
4295 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4296 || nv->id[3] != ' ' ||
4297 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4298 /* Reset NVRAM data. */
4299 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4300 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4301 le16_to_cpu(nv->nvram_version));
4302 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4303 "invalid -- WWPN) defaults.\n");
4306 * Set default initialization control block.
4308 memset(nv, 0, ha->nvram_size);
4309 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4310 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4311 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4312 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4313 nv->exchange_count = __constant_cpu_to_le16(0);
4314 nv->hard_address = __constant_cpu_to_le16(124);
4315 nv->port_name[0] = 0x21;
4316 nv->port_name[1] = 0x00 + ha->port_no;
4317 nv->port_name[2] = 0x00;
4318 nv->port_name[3] = 0xe0;
4319 nv->port_name[4] = 0x8b;
4320 nv->port_name[5] = 0x1c;
4321 nv->port_name[6] = 0x55;
4322 nv->port_name[7] = 0x86;
4323 nv->node_name[0] = 0x20;
4324 nv->node_name[1] = 0x00;
4325 nv->node_name[2] = 0x00;
4326 nv->node_name[3] = 0xe0;
4327 nv->node_name[4] = 0x8b;
4328 nv->node_name[5] = 0x1c;
4329 nv->node_name[6] = 0x55;
4330 nv->node_name[7] = 0x86;
4331 qla24xx_nvram_wwn_from_ofw(vha, nv);
4332 nv->login_retry_count = __constant_cpu_to_le16(8);
4333 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4334 nv->login_timeout = __constant_cpu_to_le16(0);
4335 nv->firmware_options_1 =
4336 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4337 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4338 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4339 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4340 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4341 nv->efi_parameters = __constant_cpu_to_le32(0);
4342 nv->reset_delay = 5;
4343 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4344 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4345 nv->link_down_timeout = __constant_cpu_to_le16(30);
4350 /* Reset Initialization control block */
4351 memset(icb, 0, ha->init_cb_size);
4353 /* Copy 1st segment. */
4354 dptr1 = (uint8_t *)icb;
4355 dptr2 = (uint8_t *)&nv->version;
4356 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4358 *dptr1++ = *dptr2++;
4360 icb->login_retry_count = nv->login_retry_count;
4361 icb->link_down_on_nos = nv->link_down_on_nos;
4363 /* Copy 2nd segment. */
4364 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4365 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4366 cnt = (uint8_t *)&icb->reserved_3 -
4367 (uint8_t *)&icb->interrupt_delay_timer;
4369 *dptr1++ = *dptr2++;
4372 * Setup driver NVRAM options.
4374 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4377 /* Use alternate WWN? */
4378 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4379 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4380 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4383 /* Prepare nodename */
4384 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4386 * Firmware will apply the following mask if the nodename was
4389 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4390 icb->node_name[0] &= 0xF0;
4393 /* Set host adapter parameters. */
4394 ha->flags.disable_risc_code_load = 0;
4395 ha->flags.enable_lip_reset = 0;
4396 ha->flags.enable_lip_full_login =
4397 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4398 ha->flags.enable_target_reset =
4399 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4400 ha->flags.enable_led_scheme = 0;
4401 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4403 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4404 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4406 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4407 sizeof(ha->fw_seriallink_options24));
4409 /* save HBA serial number */
4410 ha->serial0 = icb->port_name[5];
4411 ha->serial1 = icb->port_name[6];
4412 ha->serial2 = icb->port_name[7];
4413 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4414 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4416 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4418 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4420 /* Set minimum login_timeout to 4 seconds. */
4421 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4422 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4423 if (le16_to_cpu(nv->login_timeout) < 4)
4424 nv->login_timeout = __constant_cpu_to_le16(4);
4425 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4426 icb->login_timeout = nv->login_timeout;
4428 /* Set minimum RATOV to 100 tenths of a second. */
4431 ha->loop_reset_delay = nv->reset_delay;
4433 /* Link Down Timeout = 0:
4435 * When Port Down timer expires we will start returning
4436 * I/O's to OS with "DID_NO_CONNECT".
4438 * Link Down Timeout != 0:
4440 * The driver waits for the link to come up after link down
4441 * before returning I/Os to OS with "DID_NO_CONNECT".
4443 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4444 ha->loop_down_abort_time =
4445 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4447 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4448 ha->loop_down_abort_time =
4449 (LOOP_DOWN_TIME - ha->link_down_timeout);
4452 /* Need enough time to try and get the port back. */
4453 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4454 if (qlport_down_retry)
4455 ha->port_down_retry_count = qlport_down_retry;
4457 /* Set login_retry_count */
4458 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4459 if (ha->port_down_retry_count ==
4460 le16_to_cpu(nv->port_down_retry_count) &&
4461 ha->port_down_retry_count > 3)
4462 ha->login_retry_count = ha->port_down_retry_count;
4463 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4464 ha->login_retry_count = ha->port_down_retry_count;
4465 if (ql2xloginretrycount)
4466 ha->login_retry_count = ql2xloginretrycount;
4469 if (!vha->flags.init_done) {
4470 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4471 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4472 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4473 le16_to_cpu(icb->interrupt_delay_timer): 2;
4475 icb->firmware_options_2 &= __constant_cpu_to_le32(
4476 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4477 vha->flags.process_response_queue = 0;
4478 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4479 ha->zio_mode = QLA_ZIO_MODE_6;
4481 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4482 "(%d us).\n", vha->host_no, ha->zio_mode,
4483 ha->zio_timer * 100));
4484 qla_printk(KERN_INFO, ha,
4485 "ZIO mode %d enabled; timer delay (%d us).\n",
4486 ha->zio_mode, ha->zio_timer * 100);
4488 icb->firmware_options_2 |= cpu_to_le32(
4489 (uint32_t)ha->zio_mode);
4490 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4491 vha->flags.process_response_queue = 1;
4495 DEBUG2_3(printk(KERN_WARNING
4496 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4502 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4505 int rval = QLA_SUCCESS;
4506 int segments, fragment;
4507 uint32_t *dcode, dlen;
4511 struct qla_hw_data *ha = vha->hw;
4512 struct req_que *req = ha->req_q_map[0];
4514 qla_printk(KERN_INFO, ha,
4515 "FW: Loading from flash (%x)...\n", faddr);
4519 segments = FA_RISC_CODE_SEGMENTS;
4520 dcode = (uint32_t *)req->ring;
4523 /* Validate firmware image by checking version. */
4524 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
4525 for (i = 0; i < 4; i++)
4526 dcode[i] = be32_to_cpu(dcode[i]);
4527 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4528 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4529 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4531 qla_printk(KERN_WARNING, ha,
4532 "Unable to verify integrity of flash firmware image!\n");
4533 qla_printk(KERN_WARNING, ha,
4534 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4535 dcode[1], dcode[2], dcode[3]);
4537 return QLA_FUNCTION_FAILED;
4540 while (segments && rval == QLA_SUCCESS) {
4541 /* Read segment's load information. */
4542 qla24xx_read_flash_data(vha, dcode, faddr, 4);
4544 risc_addr = be32_to_cpu(dcode[2]);
4545 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4546 risc_size = be32_to_cpu(dcode[3]);
4549 while (risc_size > 0 && rval == QLA_SUCCESS) {
4550 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4551 if (dlen > risc_size)
4554 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4555 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
4556 vha->host_no, risc_addr, dlen, faddr));
4558 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
4559 for (i = 0; i < dlen; i++)
4560 dcode[i] = swab32(dcode[i]);
4562 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
4565 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4566 "segment %d of firmware\n", vha->host_no,
4568 qla_printk(KERN_WARNING, ha,
4569 "[ERROR] Failed to load segment %d of "
4570 "firmware\n", fragment);
4587 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4590 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4594 uint16_t *wcode, *fwcode;
4595 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4596 struct fw_blob *blob;
4597 struct qla_hw_data *ha = vha->hw;
4598 struct req_que *req = ha->req_q_map[0];
4600 /* Load firmware blob. */
4601 blob = qla2x00_request_firmware(vha);
4603 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
4604 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4605 "from: " QLA_FW_URL ".\n");
4606 return QLA_FUNCTION_FAILED;
4611 wcode = (uint16_t *)req->ring;
4613 fwcode = (uint16_t *)blob->fw->data;
4616 /* Validate firmware image by checking version. */
4617 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4618 qla_printk(KERN_WARNING, ha,
4619 "Unable to verify integrity of firmware image (%Zd)!\n",
4621 goto fail_fw_integrity;
4623 for (i = 0; i < 4; i++)
4624 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4625 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4626 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4627 wcode[2] == 0 && wcode[3] == 0)) {
4628 qla_printk(KERN_WARNING, ha,
4629 "Unable to verify integrity of firmware image!\n");
4630 qla_printk(KERN_WARNING, ha,
4631 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
4632 wcode[1], wcode[2], wcode[3]);
4633 goto fail_fw_integrity;
4637 while (*seg && rval == QLA_SUCCESS) {
4639 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4640 risc_size = be16_to_cpu(fwcode[3]);
4642 /* Validate firmware image size. */
4643 fwclen += risc_size * sizeof(uint16_t);
4644 if (blob->fw->size < fwclen) {
4645 qla_printk(KERN_WARNING, ha,
4646 "Unable to verify integrity of firmware image "
4647 "(%Zd)!\n", blob->fw->size);
4648 goto fail_fw_integrity;
4652 while (risc_size > 0 && rval == QLA_SUCCESS) {
4653 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4654 if (wlen > risc_size)
4657 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4658 "addr %x, number of words 0x%x.\n", vha->host_no,
4661 for (i = 0; i < wlen; i++)
4662 wcode[i] = swab16(fwcode[i]);
4664 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
4667 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4668 "segment %d of firmware\n", vha->host_no,
4670 qla_printk(KERN_WARNING, ha,
4671 "[ERROR] Failed to load segment %d of "
4672 "firmware\n", fragment);
4688 return QLA_FUNCTION_FAILED;
4692 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4695 int segments, fragment;
4696 uint32_t *dcode, dlen;
4700 struct fw_blob *blob;
4701 uint32_t *fwcode, fwclen;
4702 struct qla_hw_data *ha = vha->hw;
4703 struct req_que *req = ha->req_q_map[0];
4705 /* Load firmware blob. */
4706 blob = qla2x00_request_firmware(vha);
4708 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
4709 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4710 "from: " QLA_FW_URL ".\n");
4712 return QLA_FUNCTION_FAILED;
4715 qla_printk(KERN_INFO, ha,
4716 "FW: Loading via request-firmware...\n");
4720 segments = FA_RISC_CODE_SEGMENTS;
4721 dcode = (uint32_t *)req->ring;
4723 fwcode = (uint32_t *)blob->fw->data;
4726 /* Validate firmware image by checking version. */
4727 if (blob->fw->size < 8 * sizeof(uint32_t)) {
4728 qla_printk(KERN_WARNING, ha,
4729 "Unable to verify integrity of firmware image (%Zd)!\n",
4731 goto fail_fw_integrity;
4733 for (i = 0; i < 4; i++)
4734 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4735 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4736 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4737 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4739 qla_printk(KERN_WARNING, ha,
4740 "Unable to verify integrity of firmware image!\n");
4741 qla_printk(KERN_WARNING, ha,
4742 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4743 dcode[1], dcode[2], dcode[3]);
4744 goto fail_fw_integrity;
4747 while (segments && rval == QLA_SUCCESS) {
4748 risc_addr = be32_to_cpu(fwcode[2]);
4749 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4750 risc_size = be32_to_cpu(fwcode[3]);
4752 /* Validate firmware image size. */
4753 fwclen += risc_size * sizeof(uint32_t);
4754 if (blob->fw->size < fwclen) {
4755 qla_printk(KERN_WARNING, ha,
4756 "Unable to verify integrity of firmware image "
4757 "(%Zd)!\n", blob->fw->size);
4759 goto fail_fw_integrity;
4763 while (risc_size > 0 && rval == QLA_SUCCESS) {
4764 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4765 if (dlen > risc_size)
4768 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4769 "addr %x, number of dwords 0x%x.\n", vha->host_no,
4772 for (i = 0; i < dlen; i++)
4773 dcode[i] = swab32(fwcode[i]);
4775 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
4778 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4779 "segment %d of firmware\n", vha->host_no,
4781 qla_printk(KERN_WARNING, ha,
4782 "[ERROR] Failed to load segment %d of "
4783 "firmware\n", fragment);
4799 return QLA_FUNCTION_FAILED;
4803 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4807 if (ql2xfwloadbin == 1)
4808 return qla81xx_load_risc(vha, srisc_addr);
4812 * 1) Firmware via request-firmware interface (.bin file).
4813 * 2) Firmware residing in flash.
4815 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4816 if (rval == QLA_SUCCESS)
4819 return qla24xx_load_risc_flash(vha, srisc_addr,
4820 vha->hw->flt_region_fw);
4824 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4827 struct qla_hw_data *ha = vha->hw;
4829 if (ql2xfwloadbin == 2)
4834 * 1) Firmware residing in flash.
4835 * 2) Firmware via request-firmware interface (.bin file).
4836 * 3) Golden-Firmware residing in flash -- limited operation.
4838 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
4839 if (rval == QLA_SUCCESS)
4843 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4844 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4847 qla_printk(KERN_ERR, ha,
4848 "FW: Attempting to fallback to golden firmware...\n");
4849 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4850 if (rval != QLA_SUCCESS)
4853 qla_printk(KERN_ERR, ha,
4854 "FW: Please update operational firmware...\n");
4855 ha->flags.running_gold_fw = 1;
4861 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
4864 struct qla_hw_data *ha = vha->hw;
4866 if (ha->flags.pci_channel_io_perm_failure)
4868 if (!IS_FWI2_CAPABLE(ha))
4870 if (!ha->fw_major_version)
4873 ret = qla2x00_stop_firmware(vha);
4874 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4875 ret != QLA_INVALID_COMMAND && retries ; retries--) {
4876 ha->isp_ops->reset_chip(vha);
4877 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
4879 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
4881 qla_printk(KERN_INFO, ha,
4882 "Attempting retry of stop-firmware command...\n");
4883 ret = qla2x00_stop_firmware(vha);
4888 qla24xx_configure_vhba(scsi_qla_host_t *vha)
4890 int rval = QLA_SUCCESS;
4891 uint16_t mb[MAILBOX_REGISTER_COUNT];
4892 struct qla_hw_data *ha = vha->hw;
4893 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4894 struct req_que *req;
4895 struct rsp_que *rsp;
4900 rval = qla2x00_fw_ready(base_vha);
4901 if (ha->flags.cpu_affinity_enabled)
4902 req = ha->req_q_map[0];
4907 if (rval == QLA_SUCCESS) {
4908 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
4909 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
4912 vha->flags.management_server_logged_in = 0;
4914 /* Login to SNS first */
4915 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
4916 if (mb[0] != MBS_COMMAND_COMPLETE) {
4917 DEBUG15(qla_printk(KERN_INFO, ha,
4918 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4919 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4920 mb[0], mb[1], mb[2], mb[6], mb[7]));
4921 return (QLA_FUNCTION_FAILED);
4924 atomic_set(&vha->loop_down_timer, 0);
4925 atomic_set(&vha->loop_state, LOOP_UP);
4926 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4927 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4928 rval = qla2x00_loop_resync(base_vha);
4933 /* 84XX Support **************************************************************/
4935 static LIST_HEAD(qla_cs84xx_list);
4936 static DEFINE_MUTEX(qla_cs84xx_mutex);
4938 static struct qla_chip_state_84xx *
4939 qla84xx_get_chip(struct scsi_qla_host *vha)
4941 struct qla_chip_state_84xx *cs84xx;
4942 struct qla_hw_data *ha = vha->hw;
4944 mutex_lock(&qla_cs84xx_mutex);
4946 /* Find any shared 84xx chip. */
4947 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4948 if (cs84xx->bus == ha->pdev->bus) {
4949 kref_get(&cs84xx->kref);
4954 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4958 kref_init(&cs84xx->kref);
4959 spin_lock_init(&cs84xx->access_lock);
4960 mutex_init(&cs84xx->fw_update_mutex);
4961 cs84xx->bus = ha->pdev->bus;
4963 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4965 mutex_unlock(&qla_cs84xx_mutex);
4970 __qla84xx_chip_release(struct kref *kref)
4972 struct qla_chip_state_84xx *cs84xx =
4973 container_of(kref, struct qla_chip_state_84xx, kref);
4975 mutex_lock(&qla_cs84xx_mutex);
4976 list_del(&cs84xx->list);
4977 mutex_unlock(&qla_cs84xx_mutex);
4982 qla84xx_put_chip(struct scsi_qla_host *vha)
4984 struct qla_hw_data *ha = vha->hw;
4986 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4990 qla84xx_init_chip(scsi_qla_host_t *vha)
4994 struct qla_hw_data *ha = vha->hw;
4996 mutex_lock(&ha->cs84xx->fw_update_mutex);
4998 rval = qla84xx_verify_chip(vha, status);
5000 mutex_unlock(&ha->cs84xx->fw_update_mutex);
5002 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
5006 /* 81XX Support **************************************************************/
5009 qla81xx_nvram_config(scsi_qla_host_t *vha)
5012 struct init_cb_81xx *icb;
5013 struct nvram_81xx *nv;
5015 uint8_t *dptr1, *dptr2;
5018 struct qla_hw_data *ha = vha->hw;
5021 icb = (struct init_cb_81xx *)ha->init_cb;
5024 /* Determine NVRAM starting address. */
5025 ha->nvram_size = sizeof(struct nvram_81xx);
5026 ha->vpd_size = FA_NVRAM_VPD_SIZE;
5028 /* Get VPD data into cache */
5029 ha->vpd = ha->nvram + VPD_OFFSET;
5030 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
5033 /* Get NVRAM data into cache and calculate checksum. */
5034 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
5036 dptr = (uint32_t *)nv;
5037 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5038 chksum += le32_to_cpu(*dptr++);
5040 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
5041 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
5043 /* Bad NVRAM data, set defaults parameters. */
5044 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5045 || nv->id[3] != ' ' ||
5046 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
5047 /* Reset NVRAM data. */
5048 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
5049 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
5050 le16_to_cpu(nv->nvram_version));
5051 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
5052 "invalid -- WWPN) defaults.\n");
5055 * Set default initialization control block.
5057 memset(nv, 0, ha->nvram_size);
5058 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5059 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5060 nv->frame_payload_size = __constant_cpu_to_le16(2048);
5061 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5062 nv->exchange_count = __constant_cpu_to_le16(0);
5063 nv->port_name[0] = 0x21;
5064 nv->port_name[1] = 0x00 + ha->port_no;
5065 nv->port_name[2] = 0x00;
5066 nv->port_name[3] = 0xe0;
5067 nv->port_name[4] = 0x8b;
5068 nv->port_name[5] = 0x1c;
5069 nv->port_name[6] = 0x55;
5070 nv->port_name[7] = 0x86;
5071 nv->node_name[0] = 0x20;
5072 nv->node_name[1] = 0x00;
5073 nv->node_name[2] = 0x00;
5074 nv->node_name[3] = 0xe0;
5075 nv->node_name[4] = 0x8b;
5076 nv->node_name[5] = 0x1c;
5077 nv->node_name[6] = 0x55;
5078 nv->node_name[7] = 0x86;
5079 nv->login_retry_count = __constant_cpu_to_le16(8);
5080 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5081 nv->login_timeout = __constant_cpu_to_le16(0);
5082 nv->firmware_options_1 =
5083 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5084 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5085 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5086 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5087 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5088 nv->efi_parameters = __constant_cpu_to_le32(0);
5089 nv->reset_delay = 5;
5090 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5091 nv->port_down_retry_count = __constant_cpu_to_le16(30);
5092 nv->link_down_timeout = __constant_cpu_to_le16(30);
5093 nv->enode_mac[0] = 0x00;
5094 nv->enode_mac[1] = 0x02;
5095 nv->enode_mac[2] = 0x03;
5096 nv->enode_mac[3] = 0x04;
5097 nv->enode_mac[4] = 0x05;
5098 nv->enode_mac[5] = 0x06 + ha->port_no;
5103 /* Reset Initialization control block */
5104 memset(icb, 0, sizeof(struct init_cb_81xx));
5106 /* Copy 1st segment. */
5107 dptr1 = (uint8_t *)icb;
5108 dptr2 = (uint8_t *)&nv->version;
5109 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5111 *dptr1++ = *dptr2++;
5113 icb->login_retry_count = nv->login_retry_count;
5115 /* Copy 2nd segment. */
5116 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5117 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5118 cnt = (uint8_t *)&icb->reserved_5 -
5119 (uint8_t *)&icb->interrupt_delay_timer;
5121 *dptr1++ = *dptr2++;
5123 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5124 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5125 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
5126 icb->enode_mac[0] = 0x01;
5127 icb->enode_mac[1] = 0x02;
5128 icb->enode_mac[2] = 0x03;
5129 icb->enode_mac[3] = 0x04;
5130 icb->enode_mac[4] = 0x05;
5131 icb->enode_mac[5] = 0x06 + ha->port_no;
5134 /* Use extended-initialization control block. */
5135 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5138 * Setup driver NVRAM options.
5140 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
5143 /* Use alternate WWN? */
5144 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5145 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5146 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5149 /* Prepare nodename */
5150 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5152 * Firmware will apply the following mask if the nodename was
5155 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5156 icb->node_name[0] &= 0xF0;
5159 /* Set host adapter parameters. */
5160 ha->flags.disable_risc_code_load = 0;
5161 ha->flags.enable_lip_reset = 0;
5162 ha->flags.enable_lip_full_login =
5163 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5164 ha->flags.enable_target_reset =
5165 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5166 ha->flags.enable_led_scheme = 0;
5167 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5169 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5170 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5172 /* save HBA serial number */
5173 ha->serial0 = icb->port_name[5];
5174 ha->serial1 = icb->port_name[6];
5175 ha->serial2 = icb->port_name[7];
5176 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5177 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5179 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5181 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5183 /* Set minimum login_timeout to 4 seconds. */
5184 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5185 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5186 if (le16_to_cpu(nv->login_timeout) < 4)
5187 nv->login_timeout = __constant_cpu_to_le16(4);
5188 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5189 icb->login_timeout = nv->login_timeout;
5191 /* Set minimum RATOV to 100 tenths of a second. */
5194 ha->loop_reset_delay = nv->reset_delay;
5196 /* Link Down Timeout = 0:
5198 * When Port Down timer expires we will start returning
5199 * I/O's to OS with "DID_NO_CONNECT".
5201 * Link Down Timeout != 0:
5203 * The driver waits for the link to come up after link down
5204 * before returning I/Os to OS with "DID_NO_CONNECT".
5206 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5207 ha->loop_down_abort_time =
5208 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5210 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5211 ha->loop_down_abort_time =
5212 (LOOP_DOWN_TIME - ha->link_down_timeout);
5215 /* Need enough time to try and get the port back. */
5216 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5217 if (qlport_down_retry)
5218 ha->port_down_retry_count = qlport_down_retry;
5220 /* Set login_retry_count */
5221 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5222 if (ha->port_down_retry_count ==
5223 le16_to_cpu(nv->port_down_retry_count) &&
5224 ha->port_down_retry_count > 3)
5225 ha->login_retry_count = ha->port_down_retry_count;
5226 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5227 ha->login_retry_count = ha->port_down_retry_count;
5228 if (ql2xloginretrycount)
5229 ha->login_retry_count = ql2xloginretrycount;
5232 if (!vha->flags.init_done) {
5233 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5234 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5235 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5236 le16_to_cpu(icb->interrupt_delay_timer): 2;
5238 icb->firmware_options_2 &= __constant_cpu_to_le32(
5239 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5240 vha->flags.process_response_queue = 0;
5241 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5242 ha->zio_mode = QLA_ZIO_MODE_6;
5244 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
5245 "(%d us).\n", vha->host_no, ha->zio_mode,
5246 ha->zio_timer * 100));
5247 qla_printk(KERN_INFO, ha,
5248 "ZIO mode %d enabled; timer delay (%d us).\n",
5249 ha->zio_mode, ha->zio_timer * 100);
5251 icb->firmware_options_2 |= cpu_to_le32(
5252 (uint32_t)ha->zio_mode);
5253 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5254 vha->flags.process_response_queue = 1;
5258 DEBUG2_3(printk(KERN_WARNING
5259 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
5265 qla82xx_restart_isp(scsi_qla_host_t *vha)
5269 struct qla_hw_data *ha = vha->hw;
5270 struct req_que *req = ha->req_q_map[0];
5271 struct rsp_que *rsp = ha->rsp_q_map[0];
5272 struct scsi_qla_host *vp;
5273 unsigned long flags;
5275 status = qla2x00_init_rings(vha);
5277 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5278 ha->flags.chip_reset_done = 1;
5280 status = qla2x00_fw_ready(vha);
5282 qla_printk(KERN_INFO, ha,
5283 "%s(): Start configure loop, "
5284 "status = %d\n", __func__, status);
5286 /* Issue a marker after FW becomes ready. */
5287 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5289 vha->flags.online = 1;
5290 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5293 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5294 qla2x00_configure_loop(vha);
5296 } while (!atomic_read(&vha->loop_down_timer) &&
5297 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5299 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5302 /* if no cable then assume it's good */
5303 if ((vha->device_flags & DFLG_NO_CABLE))
5306 qla_printk(KERN_INFO, ha,
5307 "%s(): Configure loop done, status = 0x%x\n",
5312 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5314 if (!atomic_read(&vha->loop_down_timer)) {
5316 * Issue marker command only when we are going
5317 * to start the I/O .
5319 vha->marker_needed = 1;
5322 vha->flags.online = 1;
5324 ha->isp_ops->enable_intrs(ha);
5326 ha->isp_abort_cnt = 0;
5327 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5330 ha->flags.fce_enabled = 1;
5332 fce_calc_size(ha->fce_bufs));
5333 rval = qla2x00_enable_fce_trace(vha,
5334 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5337 qla_printk(KERN_WARNING, ha,
5338 "Unable to reinitialize FCE "
5340 ha->flags.fce_enabled = 0;
5345 memset(ha->eft, 0, EFT_SIZE);
5346 rval = qla2x00_enable_eft_trace(vha,
5347 ha->eft_dma, EFT_NUM_BUFFERS);
5349 qla_printk(KERN_WARNING, ha,
5350 "Unable to reinitialize EFT "
5357 DEBUG(printk(KERN_INFO
5358 "qla82xx_restart_isp(%ld): succeeded.\n",
5361 spin_lock_irqsave(&ha->vport_slock, flags);
5362 list_for_each_entry(vp, &ha->vp_list, list) {
5364 atomic_inc(&vp->vref_count);
5365 spin_unlock_irqrestore(&ha->vport_slock, flags);
5367 qla2x00_vp_abort_isp(vp);
5369 spin_lock_irqsave(&ha->vport_slock, flags);
5370 atomic_dec(&vp->vref_count);
5373 spin_unlock_irqrestore(&ha->vport_slock, flags);
5376 qla_printk(KERN_INFO, ha,
5377 "qla82xx_restart_isp: **** FAILED ****\n");
5384 qla81xx_update_fw_options(scsi_qla_host_t *vha)
5386 struct qla_hw_data *ha = vha->hw;
5391 /* Enable ETS Burst. */
5392 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5393 ha->fw_options[2] |= BIT_9;
5394 qla2x00_set_fw_options(vha, ha->fw_options);
5398 * qla24xx_get_fcp_prio
5399 * Gets the fcp cmd priority value for the logged in port.
5400 * Looks for a match of the port descriptors within
5401 * each of the fcp prio config entries. If a match is found,
5402 * the tag (priority) value is returned.
5405 * ha = adapter block po
5406 * fcport = port structure pointer.
5409 * non-zero (if found)
5416 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5419 uint8_t pid_match, wwn_match;
5421 uint32_t pid1, pid2;
5422 uint64_t wwn1, wwn2;
5423 struct qla_fcp_prio_entry *pri_entry;
5424 struct qla_hw_data *ha = vha->hw;
5426 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
5430 entries = ha->fcp_prio_cfg->num_entries;
5431 pri_entry = &ha->fcp_prio_cfg->entry[0];
5433 for (i = 0; i < entries; i++) {
5434 pid_match = wwn_match = 0;
5436 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5441 /* check source pid for a match */
5442 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5443 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5444 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5445 if (pid1 == INVALID_PORT_ID)
5447 else if (pid1 == pid2)
5451 /* check destination pid for a match */
5452 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5453 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5454 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5455 if (pid1 == INVALID_PORT_ID)
5457 else if (pid1 == pid2)
5461 /* check source WWN for a match */
5462 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5463 wwn1 = wwn_to_u64(vha->port_name);
5464 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5465 if (wwn2 == (uint64_t)-1)
5467 else if (wwn1 == wwn2)
5471 /* check destination WWN for a match */
5472 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5473 wwn1 = wwn_to_u64(fcport->port_name);
5474 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5475 if (wwn2 == (uint64_t)-1)
5477 else if (wwn1 == wwn2)
5481 if (pid_match == 2 || wwn_match == 2) {
5482 /* Found a matching entry */
5483 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5484 priority = pri_entry->tag;
5495 * qla24xx_update_fcport_fcp_prio
5496 * Activates fcp priority for the logged in fc port
5499 * ha = adapter block pointer.
5500 * fcp = port structure pointer.
5503 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5509 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *ha, fc_port_t *fcport)
5515 if (atomic_read(&fcport->state) == FCS_UNCONFIGURED ||
5516 fcport->port_type != FCT_TARGET ||
5517 fcport->loop_id == FC_NO_LOOP_ID)
5518 return QLA_FUNCTION_FAILED;
5520 priority = qla24xx_get_fcp_prio(ha, fcport);
5521 ret = qla24xx_set_fcp_prio(ha, fcport->loop_id, priority, mb);
5522 if (ret == QLA_SUCCESS)
5523 fcport->fcp_prio = priority;
5525 DEBUG2(printk(KERN_WARNING
5526 "scsi(%ld): Unable to activate fcp priority, "
5527 " ret=0x%x\n", ha->host_no, ret));
5533 * qla24xx_update_all_fcp_prio
5534 * Activates fcp priority for all the logged in ports
5537 * ha = adapter block pointer.
5540 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5546 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5551 ret = QLA_FUNCTION_FAILED;
5552 /* We need to set priority for all logged in ports */
5553 list_for_each_entry(fcport, &vha->vp_fcports, list)
5554 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);