2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2011 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 struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
39 static int qla84xx_init_chip(scsi_qla_host_t *);
40 static int qla25xx_init_queues(struct qla_hw_data *);
42 /* SRB Extensions ---------------------------------------------------------- */
45 qla2x00_ctx_sp_timeout(unsigned long __data)
47 srb_t *sp = (srb_t *)__data;
49 struct srb_iocb *iocb;
50 fc_port_t *fcport = sp->fcport;
51 struct qla_hw_data *ha = fcport->vha->hw;
55 spin_lock_irqsave(&ha->hardware_lock, flags);
56 req = ha->req_q_map[0];
57 req->outstanding_cmds[sp->handle] = NULL;
59 iocb = ctx->u.iocb_cmd;
62 spin_unlock_irqrestore(&ha->hardware_lock, flags);
66 qla2x00_ctx_sp_free(srb_t *sp)
68 struct srb_ctx *ctx = sp->ctx;
69 struct srb_iocb *iocb = ctx->u.iocb_cmd;
70 struct scsi_qla_host *vha = sp->fcport->vha;
72 del_timer(&iocb->timer);
75 mempool_free(sp, sp->fcport->vha->hw->srb_mempool);
77 QLA_VHA_MARK_NOT_BUSY(vha);
81 qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size,
85 struct qla_hw_data *ha = vha->hw;
87 struct srb_iocb *iocb;
90 QLA_VHA_MARK_BUSY(vha, bail);
94 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
97 ctx = kzalloc(size, GFP_KERNEL);
99 mempool_free(sp, ha->srb_mempool);
103 iocb = kzalloc(sizeof(struct srb_iocb), GFP_KERNEL);
105 mempool_free(sp, ha->srb_mempool);
111 memset(sp, 0, sizeof(*sp));
115 ctx->u.iocb_cmd = iocb;
116 iocb->free = qla2x00_ctx_sp_free;
118 init_timer(&iocb->timer);
121 iocb->timer.expires = jiffies + tmo * HZ;
122 iocb->timer.data = (unsigned long)sp;
123 iocb->timer.function = qla2x00_ctx_sp_timeout;
124 add_timer(&iocb->timer);
127 QLA_VHA_MARK_NOT_BUSY(vha);
131 /* Asynchronous Login/Logout Routines -------------------------------------- */
133 static inline unsigned long
134 qla2x00_get_async_timeout(struct scsi_qla_host *vha)
137 struct qla_hw_data *ha = vha->hw;
139 /* Firmware should use switch negotiated r_a_tov for timeout. */
140 tmo = ha->r_a_tov / 10 * 2;
141 if (!IS_FWI2_CAPABLE(ha)) {
143 * Except for earlier ISPs where the timeout is seeded from the
144 * initialization control block.
146 tmo = ha->login_timeout;
152 qla2x00_async_iocb_timeout(srb_t *sp)
154 fc_port_t *fcport = sp->fcport;
155 struct srb_ctx *ctx = sp->ctx;
157 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
158 "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n",
159 ctx->name, sp->handle, fcport->d_id.b.domain, fcport->d_id.b.area,
160 fcport->d_id.b.al_pa);
162 fcport->flags &= ~FCF_ASYNC_SENT;
163 if (ctx->type == SRB_LOGIN_CMD) {
164 struct srb_iocb *lio = ctx->u.iocb_cmd;
165 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
166 /* Retry as needed. */
167 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
168 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
169 QLA_LOGIO_LOGIN_RETRIED : 0;
170 qla2x00_post_async_login_done_work(fcport->vha, fcport,
176 qla2x00_async_login_ctx_done(srb_t *sp)
178 struct srb_ctx *ctx = sp->ctx;
179 struct srb_iocb *lio = ctx->u.iocb_cmd;
181 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
187 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
192 struct srb_iocb *lio;
195 rval = QLA_FUNCTION_FAILED;
196 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
197 qla2x00_get_async_timeout(vha) + 2);
202 ctx->type = SRB_LOGIN_CMD;
204 lio = ctx->u.iocb_cmd;
205 lio->timeout = qla2x00_async_iocb_timeout;
206 lio->done = qla2x00_async_login_ctx_done;
207 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
208 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
209 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
210 rval = qla2x00_start_sp(sp);
211 if (rval != QLA_SUCCESS)
214 ql_dbg(ql_dbg_disc, vha, 0x2072,
215 "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x "
216 "retries=%d.\n", sp->handle, fcport->loop_id,
217 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
218 fcport->login_retry);
228 qla2x00_async_logout_ctx_done(srb_t *sp)
230 struct srb_ctx *ctx = sp->ctx;
231 struct srb_iocb *lio = ctx->u.iocb_cmd;
233 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
239 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
243 struct srb_iocb *lio;
246 rval = QLA_FUNCTION_FAILED;
247 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
248 qla2x00_get_async_timeout(vha) + 2);
253 ctx->type = SRB_LOGOUT_CMD;
254 ctx->name = "logout";
255 lio = ctx->u.iocb_cmd;
256 lio->timeout = qla2x00_async_iocb_timeout;
257 lio->done = qla2x00_async_logout_ctx_done;
258 rval = qla2x00_start_sp(sp);
259 if (rval != QLA_SUCCESS)
262 ql_dbg(ql_dbg_disc, vha, 0x2070,
263 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
264 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
265 fcport->d_id.b.area, fcport->d_id.b.al_pa);
275 qla2x00_async_adisc_ctx_done(srb_t *sp)
277 struct srb_ctx *ctx = sp->ctx;
278 struct srb_iocb *lio = ctx->u.iocb_cmd;
280 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
286 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
291 struct srb_iocb *lio;
294 rval = QLA_FUNCTION_FAILED;
295 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
296 qla2x00_get_async_timeout(vha) + 2);
301 ctx->type = SRB_ADISC_CMD;
303 lio = ctx->u.iocb_cmd;
304 lio->timeout = qla2x00_async_iocb_timeout;
305 lio->done = qla2x00_async_adisc_ctx_done;
306 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
307 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
308 rval = qla2x00_start_sp(sp);
309 if (rval != QLA_SUCCESS)
312 ql_dbg(ql_dbg_disc, vha, 0x206f,
313 "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
314 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
315 fcport->d_id.b.area, fcport->d_id.b.al_pa);
325 qla2x00_async_tm_cmd_ctx_done(srb_t *sp)
327 struct srb_ctx *ctx = sp->ctx;
328 struct srb_iocb *iocb = (struct srb_iocb *)ctx->u.iocb_cmd;
330 qla2x00_async_tm_cmd_done(sp->fcport->vha, sp->fcport, iocb);
335 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
338 struct scsi_qla_host *vha = fcport->vha;
341 struct srb_iocb *tcf;
344 rval = QLA_FUNCTION_FAILED;
345 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
346 qla2x00_get_async_timeout(vha) + 2);
351 ctx->type = SRB_TM_CMD;
353 tcf = ctx->u.iocb_cmd;
354 tcf->u.tmf.flags = flags;
355 tcf->u.tmf.lun = lun;
356 tcf->u.tmf.data = tag;
357 tcf->timeout = qla2x00_async_iocb_timeout;
358 tcf->done = qla2x00_async_tm_cmd_ctx_done;
360 rval = qla2x00_start_sp(sp);
361 if (rval != QLA_SUCCESS)
364 ql_dbg(ql_dbg_taskm, vha, 0x802f,
365 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
366 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
367 fcport->d_id.b.area, fcport->d_id.b.al_pa);
377 qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
383 case MBS_COMMAND_COMPLETE:
385 * Driver must validate login state - If PRLI not complete,
386 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
389 rval = qla2x00_get_port_database(vha, fcport, 0);
390 if (rval != QLA_SUCCESS) {
391 qla2x00_post_async_logout_work(vha, fcport, NULL);
392 qla2x00_post_async_login_work(vha, fcport, NULL);
395 if (fcport->flags & FCF_FCP2_DEVICE) {
396 qla2x00_post_async_adisc_work(vha, fcport, data);
399 qla2x00_update_fcport(vha, fcport);
401 case MBS_COMMAND_ERROR:
402 fcport->flags &= ~FCF_ASYNC_SENT;
403 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
404 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
406 qla2x00_mark_device_lost(vha, fcport, 1, 0);
408 case MBS_PORT_ID_USED:
409 fcport->loop_id = data[1];
410 qla2x00_post_async_logout_work(vha, fcport, NULL);
411 qla2x00_post_async_login_work(vha, fcport, NULL);
413 case MBS_LOOP_ID_USED:
415 rval = qla2x00_find_new_loop_id(vha, fcport);
416 if (rval != QLA_SUCCESS) {
417 fcport->flags &= ~FCF_ASYNC_SENT;
418 qla2x00_mark_device_lost(vha, fcport, 1, 0);
421 qla2x00_post_async_login_work(vha, fcport, NULL);
428 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
431 qla2x00_mark_device_lost(vha, fcport, 1, 0);
436 qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
439 if (data[0] == MBS_COMMAND_COMPLETE) {
440 qla2x00_update_fcport(vha, fcport);
446 fcport->flags &= ~FCF_ASYNC_SENT;
447 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
448 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
450 qla2x00_mark_device_lost(vha, fcport, 1, 0);
456 qla2x00_async_tm_cmd_done(struct scsi_qla_host *vha, fc_port_t *fcport,
457 struct srb_iocb *iocb)
463 flags = iocb->u.tmf.flags;
464 lun = (uint16_t)iocb->u.tmf.lun;
466 /* Issue Marker IOCB */
467 rval = qla2x00_marker(vha, vha->hw->req_q_map[0],
468 vha->hw->rsp_q_map[0], fcport->loop_id, lun,
469 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
471 if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) {
472 ql_dbg(ql_dbg_taskm, vha, 0x8030,
473 "TM IOCB failed (%x).\n", rval);
479 /****************************************************************************/
480 /* QLogic ISP2x00 Hardware Support Functions. */
481 /****************************************************************************/
484 * qla2x00_initialize_adapter
488 * ha = adapter block pointer.
494 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
497 struct qla_hw_data *ha = vha->hw;
498 struct req_que *req = ha->req_q_map[0];
500 /* Clear adapter flags. */
501 vha->flags.online = 0;
502 ha->flags.chip_reset_done = 0;
503 vha->flags.reset_active = 0;
504 ha->flags.pci_channel_io_perm_failure = 0;
505 ha->flags.eeh_busy = 0;
506 ha->flags.thermal_supported = 1;
507 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
508 atomic_set(&vha->loop_state, LOOP_DOWN);
509 vha->device_flags = DFLG_NO_CABLE;
511 vha->flags.management_server_logged_in = 0;
512 vha->marker_needed = 0;
513 ha->isp_abort_cnt = 0;
514 ha->beacon_blink_led = 0;
516 set_bit(0, ha->req_qid_map);
517 set_bit(0, ha->rsp_qid_map);
519 ql_dbg(ql_dbg_init, vha, 0x0040,
520 "Configuring PCI space...\n");
521 rval = ha->isp_ops->pci_config(vha);
523 ql_log(ql_log_warn, vha, 0x0044,
524 "Unable to configure PCI space.\n");
528 ha->isp_ops->reset_chip(vha);
530 rval = qla2xxx_get_flash_info(vha);
532 ql_log(ql_log_fatal, vha, 0x004f,
533 "Unable to validate FLASH data.\n");
537 ha->isp_ops->get_flash_version(vha, req->ring);
538 ql_dbg(ql_dbg_init, vha, 0x0061,
539 "Configure NVRAM parameters...\n");
541 ha->isp_ops->nvram_config(vha);
543 if (ha->flags.disable_serdes) {
544 /* Mask HBA via NVRAM settings? */
545 ql_log(ql_log_info, vha, 0x0077,
547 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
548 vha->port_name[0], vha->port_name[1],
549 vha->port_name[2], vha->port_name[3],
550 vha->port_name[4], vha->port_name[5],
551 vha->port_name[6], vha->port_name[7]);
552 return QLA_FUNCTION_FAILED;
555 ql_dbg(ql_dbg_init, vha, 0x0078,
556 "Verifying loaded RISC code...\n");
558 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
559 rval = ha->isp_ops->chip_diag(vha);
562 rval = qla2x00_setup_chip(vha);
567 if (IS_QLA84XX(ha)) {
568 ha->cs84xx = qla84xx_get_chip(vha);
570 ql_log(ql_log_warn, vha, 0x00d0,
571 "Unable to configure ISP84XX.\n");
572 return QLA_FUNCTION_FAILED;
575 rval = qla2x00_init_rings(vha);
576 ha->flags.chip_reset_done = 1;
578 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
579 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
580 rval = qla84xx_init_chip(vha);
581 if (rval != QLA_SUCCESS) {
582 ql_log(ql_log_warn, vha, 0x00d4,
583 "Unable to initialize ISP84XX.\n");
584 qla84xx_put_chip(vha);
588 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
589 qla24xx_read_fcp_prio_cfg(vha);
595 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
598 * Returns 0 on success.
601 qla2100_pci_config(scsi_qla_host_t *vha)
605 struct qla_hw_data *ha = vha->hw;
606 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
608 pci_set_master(ha->pdev);
609 pci_try_set_mwi(ha->pdev);
611 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
612 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
613 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
615 pci_disable_rom(ha->pdev);
617 /* Get PCI bus information. */
618 spin_lock_irqsave(&ha->hardware_lock, flags);
619 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
620 spin_unlock_irqrestore(&ha->hardware_lock, flags);
626 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
629 * Returns 0 on success.
632 qla2300_pci_config(scsi_qla_host_t *vha)
635 unsigned long flags = 0;
637 struct qla_hw_data *ha = vha->hw;
638 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
640 pci_set_master(ha->pdev);
641 pci_try_set_mwi(ha->pdev);
643 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
644 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
646 if (IS_QLA2322(ha) || IS_QLA6322(ha))
647 w &= ~PCI_COMMAND_INTX_DISABLE;
648 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
651 * If this is a 2300 card and not 2312, reset the
652 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
653 * the 2310 also reports itself as a 2300 so we need to get the
654 * fb revision level -- a 6 indicates it really is a 2300 and
657 if (IS_QLA2300(ha)) {
658 spin_lock_irqsave(&ha->hardware_lock, flags);
661 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
662 for (cnt = 0; cnt < 30000; cnt++) {
663 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
669 /* Select FPM registers. */
670 WRT_REG_WORD(®->ctrl_status, 0x20);
671 RD_REG_WORD(®->ctrl_status);
673 /* Get the fb rev level */
674 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
676 if (ha->fb_rev == FPM_2300)
677 pci_clear_mwi(ha->pdev);
679 /* Deselect FPM registers. */
680 WRT_REG_WORD(®->ctrl_status, 0x0);
681 RD_REG_WORD(®->ctrl_status);
683 /* Release RISC module. */
684 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
685 for (cnt = 0; cnt < 30000; cnt++) {
686 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
692 spin_unlock_irqrestore(&ha->hardware_lock, flags);
695 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
697 pci_disable_rom(ha->pdev);
699 /* Get PCI bus information. */
700 spin_lock_irqsave(&ha->hardware_lock, flags);
701 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
702 spin_unlock_irqrestore(&ha->hardware_lock, flags);
708 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
711 * Returns 0 on success.
714 qla24xx_pci_config(scsi_qla_host_t *vha)
717 unsigned long flags = 0;
718 struct qla_hw_data *ha = vha->hw;
719 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
721 pci_set_master(ha->pdev);
722 pci_try_set_mwi(ha->pdev);
724 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
725 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
726 w &= ~PCI_COMMAND_INTX_DISABLE;
727 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
729 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
731 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
732 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
733 pcix_set_mmrbc(ha->pdev, 2048);
735 /* PCIe -- adjust Maximum Read Request Size (2048). */
736 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
737 pcie_set_readrq(ha->pdev, 2048);
739 pci_disable_rom(ha->pdev);
741 ha->chip_revision = ha->pdev->revision;
743 /* Get PCI bus information. */
744 spin_lock_irqsave(&ha->hardware_lock, flags);
745 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
746 spin_unlock_irqrestore(&ha->hardware_lock, flags);
752 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
755 * Returns 0 on success.
758 qla25xx_pci_config(scsi_qla_host_t *vha)
761 struct qla_hw_data *ha = vha->hw;
763 pci_set_master(ha->pdev);
764 pci_try_set_mwi(ha->pdev);
766 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
767 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
768 w &= ~PCI_COMMAND_INTX_DISABLE;
769 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
771 /* PCIe -- adjust Maximum Read Request Size (2048). */
772 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
773 pcie_set_readrq(ha->pdev, 2048);
775 pci_disable_rom(ha->pdev);
777 ha->chip_revision = ha->pdev->revision;
783 * qla2x00_isp_firmware() - Choose firmware image.
786 * Returns 0 on success.
789 qla2x00_isp_firmware(scsi_qla_host_t *vha)
792 uint16_t loop_id, topo, sw_cap;
793 uint8_t domain, area, al_pa;
794 struct qla_hw_data *ha = vha->hw;
796 /* Assume loading risc code */
797 rval = QLA_FUNCTION_FAILED;
799 if (ha->flags.disable_risc_code_load) {
800 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
802 /* Verify checksum of loaded RISC code. */
803 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
804 if (rval == QLA_SUCCESS) {
805 /* And, verify we are not in ROM code. */
806 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
807 &area, &domain, &topo, &sw_cap);
812 ql_dbg(ql_dbg_init, vha, 0x007a,
813 "**** Load RISC code ****.\n");
819 * qla2x00_reset_chip() - Reset ISP chip.
822 * Returns 0 on success.
825 qla2x00_reset_chip(scsi_qla_host_t *vha)
827 unsigned long flags = 0;
828 struct qla_hw_data *ha = vha->hw;
829 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
833 if (unlikely(pci_channel_offline(ha->pdev)))
836 ha->isp_ops->disable_intrs(ha);
838 spin_lock_irqsave(&ha->hardware_lock, flags);
840 /* Turn off master enable */
842 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
843 cmd &= ~PCI_COMMAND_MASTER;
844 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
846 if (!IS_QLA2100(ha)) {
848 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
849 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
850 for (cnt = 0; cnt < 30000; cnt++) {
851 if ((RD_REG_WORD(®->hccr) &
852 HCCR_RISC_PAUSE) != 0)
857 RD_REG_WORD(®->hccr); /* PCI Posting. */
861 /* Select FPM registers. */
862 WRT_REG_WORD(®->ctrl_status, 0x20);
863 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
865 /* FPM Soft Reset. */
866 WRT_REG_WORD(®->fpm_diag_config, 0x100);
867 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
869 /* Toggle Fpm Reset. */
870 if (!IS_QLA2200(ha)) {
871 WRT_REG_WORD(®->fpm_diag_config, 0x0);
872 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
875 /* Select frame buffer registers. */
876 WRT_REG_WORD(®->ctrl_status, 0x10);
877 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
879 /* Reset frame buffer FIFOs. */
880 if (IS_QLA2200(ha)) {
881 WRT_FB_CMD_REG(ha, reg, 0xa000);
882 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
884 WRT_FB_CMD_REG(ha, reg, 0x00fc);
886 /* Read back fb_cmd until zero or 3 seconds max */
887 for (cnt = 0; cnt < 3000; cnt++) {
888 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
894 /* Select RISC module registers. */
895 WRT_REG_WORD(®->ctrl_status, 0);
896 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
898 /* Reset RISC processor. */
899 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
900 RD_REG_WORD(®->hccr); /* PCI Posting. */
902 /* Release RISC processor. */
903 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
904 RD_REG_WORD(®->hccr); /* PCI Posting. */
907 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
908 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
910 /* Reset ISP chip. */
911 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
913 /* Wait for RISC to recover from reset. */
914 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
916 * It is necessary to for a delay here since the card doesn't
917 * respond to PCI reads during a reset. On some architectures
918 * this will result in an MCA.
921 for (cnt = 30000; cnt; cnt--) {
922 if ((RD_REG_WORD(®->ctrl_status) &
923 CSR_ISP_SOFT_RESET) == 0)
930 /* Reset RISC processor. */
931 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
933 WRT_REG_WORD(®->semaphore, 0);
935 /* Release RISC processor. */
936 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
937 RD_REG_WORD(®->hccr); /* PCI Posting. */
939 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
940 for (cnt = 0; cnt < 30000; cnt++) {
941 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
949 /* Turn on master enable */
950 cmd |= PCI_COMMAND_MASTER;
951 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
953 /* Disable RISC pause on FPM parity error. */
954 if (!IS_QLA2100(ha)) {
955 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
956 RD_REG_WORD(®->hccr); /* PCI Posting. */
959 spin_unlock_irqrestore(&ha->hardware_lock, flags);
963 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
965 * Returns 0 on success.
968 qla81xx_reset_mpi(scsi_qla_host_t *vha)
970 uint16_t mb[4] = {0x1010, 0, 1, 0};
972 if (!IS_QLA81XX(vha->hw))
975 return qla81xx_write_mpi_register(vha, mb);
979 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
982 * Returns 0 on success.
985 qla24xx_reset_risc(scsi_qla_host_t *vha)
987 unsigned long flags = 0;
988 struct qla_hw_data *ha = vha->hw;
989 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
992 static int abts_cnt; /* ISP abort retry counts */
994 spin_lock_irqsave(&ha->hardware_lock, flags);
997 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
998 for (cnt = 0; cnt < 30000; cnt++) {
999 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
1005 WRT_REG_DWORD(®->ctrl_status,
1006 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
1007 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
1010 /* Wait for firmware to complete NVRAM accesses. */
1011 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
1012 for (cnt = 10000 ; cnt && d2; cnt--) {
1014 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
1018 /* Wait for soft-reset to complete. */
1019 d2 = RD_REG_DWORD(®->ctrl_status);
1020 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
1022 d2 = RD_REG_DWORD(®->ctrl_status);
1026 /* If required, do an MPI FW reset now */
1027 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
1028 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
1029 if (++abts_cnt < 5) {
1030 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1031 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
1034 * We exhausted the ISP abort retries. We have to
1035 * set the board offline.
1038 vha->flags.online = 0;
1043 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
1044 RD_REG_DWORD(®->hccr);
1046 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
1047 RD_REG_DWORD(®->hccr);
1049 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
1050 RD_REG_DWORD(®->hccr);
1052 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
1053 for (cnt = 6000000 ; cnt && d2; cnt--) {
1055 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
1059 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1061 if (IS_NOPOLLING_TYPE(ha))
1062 ha->isp_ops->enable_intrs(ha);
1066 * qla24xx_reset_chip() - Reset ISP24xx chip.
1069 * Returns 0 on success.
1072 qla24xx_reset_chip(scsi_qla_host_t *vha)
1074 struct qla_hw_data *ha = vha->hw;
1076 if (pci_channel_offline(ha->pdev) &&
1077 ha->flags.pci_channel_io_perm_failure) {
1081 ha->isp_ops->disable_intrs(ha);
1083 /* Perform RISC reset. */
1084 qla24xx_reset_risc(vha);
1088 * qla2x00_chip_diag() - Test chip for proper operation.
1091 * Returns 0 on success.
1094 qla2x00_chip_diag(scsi_qla_host_t *vha)
1097 struct qla_hw_data *ha = vha->hw;
1098 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1099 unsigned long flags = 0;
1103 struct req_que *req = ha->req_q_map[0];
1105 /* Assume a failed state */
1106 rval = QLA_FUNCTION_FAILED;
1108 ql_dbg(ql_dbg_init, vha, 0x007b,
1109 "Testing device at %lx.\n", (u_long)®->flash_address);
1111 spin_lock_irqsave(&ha->hardware_lock, flags);
1113 /* Reset ISP chip. */
1114 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
1117 * We need to have a delay here since the card will not respond while
1118 * in reset causing an MCA on some architectures.
1121 data = qla2x00_debounce_register(®->ctrl_status);
1122 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1124 data = RD_REG_WORD(®->ctrl_status);
1129 goto chip_diag_failed;
1131 ql_dbg(ql_dbg_init, vha, 0x007c,
1132 "Reset register cleared by chip reset.\n");
1134 /* Reset RISC processor. */
1135 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
1136 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
1138 /* Workaround for QLA2312 PCI parity error */
1139 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1140 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1141 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1143 data = RD_MAILBOX_REG(ha, reg, 0);
1150 goto chip_diag_failed;
1152 /* Check product ID of chip */
1153 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
1155 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1156 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1157 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1158 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1159 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1160 mb[3] != PROD_ID_3) {
1161 ql_log(ql_log_warn, vha, 0x0062,
1162 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
1163 mb[1], mb[2], mb[3]);
1165 goto chip_diag_failed;
1167 ha->product_id[0] = mb[1];
1168 ha->product_id[1] = mb[2];
1169 ha->product_id[2] = mb[3];
1170 ha->product_id[3] = mb[4];
1172 /* Adjust fw RISC transfer size */
1173 if (req->length > 1024)
1174 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1176 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
1179 if (IS_QLA2200(ha) &&
1180 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1181 /* Limit firmware transfer size with a 2200A */
1182 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
1184 ha->device_type |= DT_ISP2200A;
1185 ha->fw_transfer_size = 128;
1188 /* Wrap Incoming Mailboxes Test. */
1189 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1191 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
1192 rval = qla2x00_mbx_reg_test(vha);
1194 ql_log(ql_log_warn, vha, 0x0080,
1195 "Failed mailbox send register test.\n");
1197 /* Flag a successful rval */
1199 spin_lock_irqsave(&ha->hardware_lock, flags);
1203 ql_log(ql_log_info, vha, 0x0081,
1204 "Chip diagnostics **** FAILED ****.\n");
1206 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1212 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1215 * Returns 0 on success.
1218 qla24xx_chip_diag(scsi_qla_host_t *vha)
1221 struct qla_hw_data *ha = vha->hw;
1222 struct req_que *req = ha->req_q_map[0];
1227 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
1229 rval = qla2x00_mbx_reg_test(vha);
1231 ql_log(ql_log_warn, vha, 0x0082,
1232 "Failed mailbox send register test.\n");
1234 /* Flag a successful rval */
1242 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
1245 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
1246 eft_size, fce_size, mq_size;
1249 struct qla_hw_data *ha = vha->hw;
1250 struct req_que *req = ha->req_q_map[0];
1251 struct rsp_que *rsp = ha->rsp_q_map[0];
1254 ql_dbg(ql_dbg_init, vha, 0x00bd,
1255 "Firmware dump already allocated.\n");
1260 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
1261 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1262 fixed_size = sizeof(struct qla2100_fw_dump);
1263 } else if (IS_QLA23XX(ha)) {
1264 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1265 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1267 } else if (IS_FWI2_CAPABLE(ha)) {
1269 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
1270 else if (IS_QLA81XX(ha))
1271 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1272 else if (IS_QLA25XX(ha))
1273 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1275 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
1276 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1279 if (!IS_QLA83XX(ha))
1280 mq_size = sizeof(struct qla2xxx_mq_chain);
1282 * Allocate maximum buffer size for all queues.
1283 * Resizing must be done at end-of-dump processing.
1285 mq_size += ha->max_req_queues *
1286 (req->length * sizeof(request_t));
1287 mq_size += ha->max_rsp_queues *
1288 (rsp->length * sizeof(response_t));
1290 /* Allocate memory for Fibre Channel Event Buffer. */
1291 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha))
1294 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1297 ql_log(ql_log_warn, vha, 0x00be,
1298 "Unable to allocate (%d KB) for FCE.\n",
1303 memset(tc, 0, FCE_SIZE);
1304 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
1305 ha->fce_mb, &ha->fce_bufs);
1307 ql_log(ql_log_warn, vha, 0x00bf,
1308 "Unable to initialize FCE (%d).\n", rval);
1309 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1311 ha->flags.fce_enabled = 0;
1314 ql_dbg(ql_dbg_init, vha, 0x00c0,
1315 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
1317 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
1318 ha->flags.fce_enabled = 1;
1319 ha->fce_dma = tc_dma;
1322 /* Allocate memory for Extended Trace Buffer. */
1323 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
1326 ql_log(ql_log_warn, vha, 0x00c1,
1327 "Unable to allocate (%d KB) for EFT.\n",
1332 memset(tc, 0, EFT_SIZE);
1333 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
1335 ql_log(ql_log_warn, vha, 0x00c2,
1336 "Unable to initialize EFT (%d).\n", rval);
1337 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1341 ql_dbg(ql_dbg_init, vha, 0x00c3,
1342 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
1344 eft_size = EFT_SIZE;
1345 ha->eft_dma = tc_dma;
1349 req_q_size = req->length * sizeof(request_t);
1350 rsp_q_size = rsp->length * sizeof(response_t);
1352 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
1353 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
1354 ha->chain_offset = dump_size;
1355 dump_size += mq_size + fce_size;
1357 ha->fw_dump = vmalloc(dump_size);
1359 ql_log(ql_log_warn, vha, 0x00c4,
1360 "Unable to allocate (%d KB) for firmware dump.\n",
1364 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1371 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1378 ql_dbg(ql_dbg_init, vha, 0x00c5,
1379 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
1381 ha->fw_dump_len = dump_size;
1382 ha->fw_dump->signature[0] = 'Q';
1383 ha->fw_dump->signature[1] = 'L';
1384 ha->fw_dump->signature[2] = 'G';
1385 ha->fw_dump->signature[3] = 'C';
1386 ha->fw_dump->version = __constant_htonl(1);
1388 ha->fw_dump->fixed_size = htonl(fixed_size);
1389 ha->fw_dump->mem_size = htonl(mem_size);
1390 ha->fw_dump->req_q_size = htonl(req_q_size);
1391 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1393 ha->fw_dump->eft_size = htonl(eft_size);
1394 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1395 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1397 ha->fw_dump->header_size =
1398 htonl(offsetof(struct qla2xxx_fw_dump, isp));
1402 qla81xx_mpi_sync(scsi_qla_host_t *vha)
1404 #define MPS_MASK 0xe0
1409 if (!IS_QLA81XX(vha->hw))
1412 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1413 if (rval != QLA_SUCCESS) {
1414 ql_log(ql_log_warn, vha, 0x0105,
1415 "Unable to acquire semaphore.\n");
1419 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1420 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1421 if (rval != QLA_SUCCESS) {
1422 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
1427 if (dc == (dw & MPS_MASK))
1432 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1433 if (rval != QLA_SUCCESS) {
1434 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
1438 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1439 if (rval != QLA_SUCCESS) {
1440 ql_log(ql_log_warn, vha, 0x006d,
1441 "Unable to release semaphore.\n");
1449 * qla2x00_setup_chip() - Load and start RISC firmware.
1452 * Returns 0 on success.
1455 qla2x00_setup_chip(scsi_qla_host_t *vha)
1458 uint32_t srisc_address = 0;
1459 struct qla_hw_data *ha = vha->hw;
1460 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1461 unsigned long flags;
1462 uint16_t fw_major_version;
1464 if (IS_QLA82XX(ha)) {
1465 rval = ha->isp_ops->load_risc(vha, &srisc_address);
1466 if (rval == QLA_SUCCESS) {
1467 qla2x00_stop_firmware(vha);
1468 goto enable_82xx_npiv;
1473 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1474 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1475 spin_lock_irqsave(&ha->hardware_lock, flags);
1476 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
1477 RD_REG_WORD(®->hccr);
1478 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1481 qla81xx_mpi_sync(vha);
1483 /* Load firmware sequences */
1484 rval = ha->isp_ops->load_risc(vha, &srisc_address);
1485 if (rval == QLA_SUCCESS) {
1486 ql_dbg(ql_dbg_init, vha, 0x00c9,
1487 "Verifying Checksum of loaded RISC code.\n");
1489 rval = qla2x00_verify_checksum(vha, srisc_address);
1490 if (rval == QLA_SUCCESS) {
1491 /* Start firmware execution. */
1492 ql_dbg(ql_dbg_init, vha, 0x00ca,
1493 "Starting firmware.\n");
1495 rval = qla2x00_execute_fw(vha, srisc_address);
1496 /* Retrieve firmware information. */
1497 if (rval == QLA_SUCCESS) {
1499 fw_major_version = ha->fw_major_version;
1501 qla82xx_check_md_needed(vha);
1503 rval = qla2x00_get_fw_version(vha);
1504 if (rval != QLA_SUCCESS)
1506 ha->flags.npiv_supported = 0;
1507 if (IS_QLA2XXX_MIDTYPE(ha) &&
1508 (ha->fw_attributes & BIT_2)) {
1509 ha->flags.npiv_supported = 1;
1510 if ((!ha->max_npiv_vports) ||
1511 ((ha->max_npiv_vports + 1) %
1512 MIN_MULTI_ID_FABRIC))
1513 ha->max_npiv_vports =
1514 MIN_MULTI_ID_FABRIC - 1;
1516 qla2x00_get_resource_cnts(vha, NULL,
1517 &ha->fw_xcb_count, NULL, NULL,
1518 &ha->max_npiv_vports, NULL);
1520 if (!fw_major_version && ql2xallocfwdump
1522 qla2x00_alloc_fw_dump(vha);
1525 ql_log(ql_log_fatal, vha, 0x00cd,
1526 "ISP Firmware failed checksum.\n");
1531 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1532 /* Enable proper parity. */
1533 spin_lock_irqsave(&ha->hardware_lock, flags);
1536 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
1538 /* SRAM, Instruction RAM and GP RAM parity */
1539 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
1540 RD_REG_WORD(®->hccr);
1541 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1545 goto skip_fac_check;
1547 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1550 rval = qla81xx_fac_get_sector_size(vha, &size);
1551 if (rval == QLA_SUCCESS) {
1552 ha->flags.fac_supported = 1;
1553 ha->fdt_block_size = size << 2;
1555 ql_log(ql_log_warn, vha, 0x00ce,
1556 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1557 ha->fw_major_version, ha->fw_minor_version,
1558 ha->fw_subminor_version);
1560 if (IS_QLA83XX(ha)) {
1561 ha->flags.fac_supported = 0;
1568 ql_log(ql_log_fatal, vha, 0x00cf,
1569 "Setup chip ****FAILED****.\n");
1576 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1579 * Beginning of request ring has initialization control block already built
1580 * by nvram config routine.
1582 * Returns 0 on success.
1585 qla2x00_init_response_q_entries(struct rsp_que *rsp)
1590 rsp->ring_ptr = rsp->ring;
1591 rsp->ring_index = 0;
1592 rsp->status_srb = NULL;
1593 pkt = rsp->ring_ptr;
1594 for (cnt = 0; cnt < rsp->length; cnt++) {
1595 pkt->signature = RESPONSE_PROCESSED;
1601 * qla2x00_update_fw_options() - Read and process firmware options.
1604 * Returns 0 on success.
1607 qla2x00_update_fw_options(scsi_qla_host_t *vha)
1609 uint16_t swing, emphasis, tx_sens, rx_sens;
1610 struct qla_hw_data *ha = vha->hw;
1612 memset(ha->fw_options, 0, sizeof(ha->fw_options));
1613 qla2x00_get_fw_options(vha, ha->fw_options);
1615 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1618 /* Serial Link options. */
1619 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
1620 "Serial link options.\n");
1621 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
1622 (uint8_t *)&ha->fw_seriallink_options,
1623 sizeof(ha->fw_seriallink_options));
1625 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1626 if (ha->fw_seriallink_options[3] & BIT_2) {
1627 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1630 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1631 emphasis = (ha->fw_seriallink_options[2] &
1632 (BIT_4 | BIT_3)) >> 3;
1633 tx_sens = ha->fw_seriallink_options[0] &
1634 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1635 rx_sens = (ha->fw_seriallink_options[0] &
1636 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1637 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1638 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1641 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1642 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1643 ha->fw_options[10] |= BIT_5 |
1644 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1645 (tx_sens & (BIT_1 | BIT_0));
1648 swing = (ha->fw_seriallink_options[2] &
1649 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1650 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1651 tx_sens = ha->fw_seriallink_options[1] &
1652 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1653 rx_sens = (ha->fw_seriallink_options[1] &
1654 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1655 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1656 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1659 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1660 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1661 ha->fw_options[11] |= BIT_5 |
1662 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1663 (tx_sens & (BIT_1 | BIT_0));
1667 /* Return command IOCBs without waiting for an ABTS to complete. */
1668 ha->fw_options[3] |= BIT_13;
1671 if (ha->flags.enable_led_scheme)
1672 ha->fw_options[2] |= BIT_12;
1674 /* Detect ISP6312. */
1676 ha->fw_options[2] |= BIT_13;
1678 /* Update firmware options. */
1679 qla2x00_set_fw_options(vha, ha->fw_options);
1683 qla24xx_update_fw_options(scsi_qla_host_t *vha)
1686 struct qla_hw_data *ha = vha->hw;
1691 /* Update Serial Link options. */
1692 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1695 rval = qla2x00_set_serdes_params(vha,
1696 le16_to_cpu(ha->fw_seriallink_options24[1]),
1697 le16_to_cpu(ha->fw_seriallink_options24[2]),
1698 le16_to_cpu(ha->fw_seriallink_options24[3]));
1699 if (rval != QLA_SUCCESS) {
1700 ql_log(ql_log_warn, vha, 0x0104,
1701 "Unable to update Serial Link options (%x).\n", rval);
1706 qla2x00_config_rings(struct scsi_qla_host *vha)
1708 struct qla_hw_data *ha = vha->hw;
1709 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1710 struct req_que *req = ha->req_q_map[0];
1711 struct rsp_que *rsp = ha->rsp_q_map[0];
1713 /* Setup ring parameters in initialization control block. */
1714 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1715 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1716 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1717 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1718 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1719 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1720 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1721 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
1723 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1724 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1725 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1726 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1727 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1731 qla24xx_config_rings(struct scsi_qla_host *vha)
1733 struct qla_hw_data *ha = vha->hw;
1734 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1735 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1736 struct qla_msix_entry *msix;
1737 struct init_cb_24xx *icb;
1739 struct req_que *req = ha->req_q_map[0];
1740 struct rsp_que *rsp = ha->rsp_q_map[0];
1742 /* Setup ring parameters in initialization control block. */
1743 icb = (struct init_cb_24xx *)ha->init_cb;
1744 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1745 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1746 icb->request_q_length = cpu_to_le16(req->length);
1747 icb->response_q_length = cpu_to_le16(rsp->length);
1748 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1749 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1750 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1751 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
1753 if (ha->mqenable || IS_QLA83XX(ha)) {
1754 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1755 icb->rid = __constant_cpu_to_le16(rid);
1756 if (ha->flags.msix_enabled) {
1757 msix = &ha->msix_entries[1];
1758 ql_dbg(ql_dbg_init, vha, 0x00fd,
1759 "Registering vector 0x%x for base que.\n",
1761 icb->msix = cpu_to_le16(msix->entry);
1763 /* Use alternate PCI bus number */
1765 icb->firmware_options_2 |=
1766 __constant_cpu_to_le32(BIT_19);
1767 /* Use alternate PCI devfn */
1769 icb->firmware_options_2 |=
1770 __constant_cpu_to_le32(BIT_18);
1772 /* Use Disable MSIX Handshake mode for capable adapters */
1773 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
1774 (ha->flags.msix_enabled)) {
1775 icb->firmware_options_2 &=
1776 __constant_cpu_to_le32(~BIT_22);
1777 ha->flags.disable_msix_handshake = 1;
1778 ql_dbg(ql_dbg_init, vha, 0x00fe,
1779 "MSIX Handshake Disable Mode turned on.\n");
1781 icb->firmware_options_2 |=
1782 __constant_cpu_to_le32(BIT_22);
1784 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
1786 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
1787 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
1788 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
1789 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
1791 WRT_REG_DWORD(®->isp24.req_q_in, 0);
1792 WRT_REG_DWORD(®->isp24.req_q_out, 0);
1793 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
1794 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
1797 RD_REG_DWORD(&ioreg->hccr);
1801 * qla2x00_init_rings() - Initializes firmware.
1804 * Beginning of request ring has initialization control block already built
1805 * by nvram config routine.
1807 * Returns 0 on success.
1810 qla2x00_init_rings(scsi_qla_host_t *vha)
1813 unsigned long flags = 0;
1815 struct qla_hw_data *ha = vha->hw;
1816 struct req_que *req;
1817 struct rsp_que *rsp;
1818 struct scsi_qla_host *vp;
1819 struct mid_init_cb_24xx *mid_init_cb =
1820 (struct mid_init_cb_24xx *) ha->init_cb;
1822 spin_lock_irqsave(&ha->hardware_lock, flags);
1824 /* Clear outstanding commands array. */
1825 for (que = 0; que < ha->max_req_queues; que++) {
1826 req = ha->req_q_map[que];
1829 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1830 req->outstanding_cmds[cnt] = NULL;
1832 req->current_outstanding_cmd = 1;
1834 /* Initialize firmware. */
1835 req->ring_ptr = req->ring;
1836 req->ring_index = 0;
1837 req->cnt = req->length;
1840 for (que = 0; que < ha->max_rsp_queues; que++) {
1841 rsp = ha->rsp_q_map[que];
1844 /* Initialize response queue entries */
1845 qla2x00_init_response_q_entries(rsp);
1848 spin_lock(&ha->vport_slock);
1849 /* Clear RSCN queue. */
1850 list_for_each_entry(vp, &ha->vp_list, list) {
1851 vp->rscn_in_ptr = 0;
1852 vp->rscn_out_ptr = 0;
1855 spin_unlock(&ha->vport_slock);
1857 ha->isp_ops->config_rings(vha);
1859 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1861 /* Update any ISP specific firmware options before initialization. */
1862 ha->isp_ops->update_fw_options(vha);
1864 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
1866 if (ha->flags.npiv_supported) {
1867 if (ha->operating_mode == LOOP)
1868 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
1869 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1872 if (IS_FWI2_CAPABLE(ha)) {
1873 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1874 mid_init_cb->init_cb.execution_throttle =
1875 cpu_to_le16(ha->fw_xcb_count);
1878 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
1880 ql_log(ql_log_fatal, vha, 0x00d2,
1881 "Init Firmware **** FAILED ****.\n");
1883 ql_dbg(ql_dbg_init, vha, 0x00d3,
1884 "Init Firmware -- success.\n");
1891 * qla2x00_fw_ready() - Waits for firmware ready.
1894 * Returns 0 on success.
1897 qla2x00_fw_ready(scsi_qla_host_t *vha)
1900 unsigned long wtime, mtime, cs84xx_time;
1901 uint16_t min_wait; /* Minimum wait time if loop is down */
1902 uint16_t wait_time; /* Wait time if loop is coming ready */
1904 struct qla_hw_data *ha = vha->hw;
1908 /* 20 seconds for loop down. */
1912 * Firmware should take at most one RATOV to login, plus 5 seconds for
1913 * our own processing.
1915 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1916 wait_time = min_wait;
1919 /* Min wait time if loop down */
1920 mtime = jiffies + (min_wait * HZ);
1922 /* wait time before firmware ready */
1923 wtime = jiffies + (wait_time * HZ);
1925 /* Wait for ISP to finish LIP */
1926 if (!vha->flags.init_done)
1927 ql_log(ql_log_info, vha, 0x801e,
1928 "Waiting for LIP to complete.\n");
1931 rval = qla2x00_get_firmware_state(vha, state);
1932 if (rval == QLA_SUCCESS) {
1933 if (state[0] < FSTATE_LOSS_OF_SYNC) {
1934 vha->device_flags &= ~DFLG_NO_CABLE;
1936 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1937 ql_dbg(ql_dbg_taskm, vha, 0x801f,
1938 "fw_state=%x 84xx=%x.\n", state[0],
1940 if ((state[2] & FSTATE_LOGGED_IN) &&
1941 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1942 ql_dbg(ql_dbg_taskm, vha, 0x8028,
1943 "Sending verify iocb.\n");
1945 cs84xx_time = jiffies;
1946 rval = qla84xx_init_chip(vha);
1947 if (rval != QLA_SUCCESS) {
1950 "Init chip failed.\n");
1954 /* Add time taken to initialize. */
1955 cs84xx_time = jiffies - cs84xx_time;
1956 wtime += cs84xx_time;
1957 mtime += cs84xx_time;
1958 ql_dbg(ql_dbg_taskm, vha, 0x8008,
1959 "Increasing wait time by %ld. "
1960 "New time %ld.\n", cs84xx_time,
1963 } else if (state[0] == FSTATE_READY) {
1964 ql_dbg(ql_dbg_taskm, vha, 0x8037,
1965 "F/W Ready - OK.\n");
1967 qla2x00_get_retry_cnt(vha, &ha->retry_count,
1968 &ha->login_timeout, &ha->r_a_tov);
1974 rval = QLA_FUNCTION_FAILED;
1976 if (atomic_read(&vha->loop_down_timer) &&
1977 state[0] != FSTATE_READY) {
1978 /* Loop down. Timeout on min_wait for states
1979 * other than Wait for Login.
1981 if (time_after_eq(jiffies, mtime)) {
1982 ql_log(ql_log_info, vha, 0x8038,
1983 "Cable is unplugged...\n");
1985 vha->device_flags |= DFLG_NO_CABLE;
1990 /* Mailbox cmd failed. Timeout on min_wait. */
1991 if (time_after_eq(jiffies, mtime) ||
1992 ha->flags.isp82xx_fw_hung)
1996 if (time_after_eq(jiffies, wtime))
1999 /* Delay for a while */
2003 ql_dbg(ql_dbg_taskm, vha, 0x803a,
2004 "fw_state=%x (%x, %x, %x, %x) " "curr time=%lx.\n", state[0],
2005 state[1], state[2], state[3], state[4], jiffies);
2007 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
2008 ql_log(ql_log_warn, vha, 0x803b,
2009 "Firmware ready **** FAILED ****.\n");
2016 * qla2x00_configure_hba
2017 * Setup adapter context.
2020 * ha = adapter state pointer.
2029 qla2x00_configure_hba(scsi_qla_host_t *vha)
2038 char connect_type[22];
2039 struct qla_hw_data *ha = vha->hw;
2041 /* Get host addresses. */
2042 rval = qla2x00_get_adapter_id(vha,
2043 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
2044 if (rval != QLA_SUCCESS) {
2045 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
2046 IS_CNA_CAPABLE(ha) ||
2047 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
2048 ql_dbg(ql_dbg_disc, vha, 0x2008,
2049 "Loop is in a transition state.\n");
2051 ql_log(ql_log_warn, vha, 0x2009,
2052 "Unable to get host loop ID.\n");
2053 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2059 ql_log(ql_log_info, vha, 0x200a,
2060 "Cannot get topology - retrying.\n");
2061 return (QLA_FUNCTION_FAILED);
2064 vha->loop_id = loop_id;
2067 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2068 ha->operating_mode = LOOP;
2073 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
2074 ha->current_topology = ISP_CFG_NL;
2075 strcpy(connect_type, "(Loop)");
2079 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
2080 ha->switch_cap = sw_cap;
2081 ha->current_topology = ISP_CFG_FL;
2082 strcpy(connect_type, "(FL_Port)");
2086 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
2087 ha->operating_mode = P2P;
2088 ha->current_topology = ISP_CFG_N;
2089 strcpy(connect_type, "(N_Port-to-N_Port)");
2093 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
2094 ha->switch_cap = sw_cap;
2095 ha->operating_mode = P2P;
2096 ha->current_topology = ISP_CFG_F;
2097 strcpy(connect_type, "(F_Port)");
2101 ql_dbg(ql_dbg_disc, vha, 0x200f,
2102 "HBA in unknown topology %x, using NL.\n", topo);
2103 ha->current_topology = ISP_CFG_NL;
2104 strcpy(connect_type, "(Loop)");
2108 /* Save Host port and loop ID. */
2109 /* byte order - Big Endian */
2110 vha->d_id.b.domain = domain;
2111 vha->d_id.b.area = area;
2112 vha->d_id.b.al_pa = al_pa;
2114 if (!vha->flags.init_done)
2115 ql_log(ql_log_info, vha, 0x2010,
2116 "Topology - %s, Host Loop address 0x%x.\n",
2117 connect_type, vha->loop_id);
2120 ql_log(ql_log_warn, vha, 0x2011,
2121 "%s FAILED\n", __func__);
2123 ql_dbg(ql_dbg_disc, vha, 0x2012,
2124 "%s success\n", __func__);
2131 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2136 struct qla_hw_data *ha = vha->hw;
2137 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
2138 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
2140 if (memcmp(model, BINZERO, len) != 0) {
2141 strncpy(ha->model_number, model, len);
2142 st = en = ha->model_number;
2145 if (*en != 0x20 && *en != 0x00)
2150 index = (ha->pdev->subsystem_device & 0xff);
2152 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
2153 index < QLA_MODEL_NAMES)
2154 strncpy(ha->model_desc,
2155 qla2x00_model_name[index * 2 + 1],
2156 sizeof(ha->model_desc) - 1);
2158 index = (ha->pdev->subsystem_device & 0xff);
2160 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
2161 index < QLA_MODEL_NAMES) {
2162 strcpy(ha->model_number,
2163 qla2x00_model_name[index * 2]);
2164 strncpy(ha->model_desc,
2165 qla2x00_model_name[index * 2 + 1],
2166 sizeof(ha->model_desc) - 1);
2168 strcpy(ha->model_number, def);
2171 if (IS_FWI2_CAPABLE(ha))
2172 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
2173 sizeof(ha->model_desc));
2176 /* On sparc systems, obtain port and node WWN from firmware
2179 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
2182 struct qla_hw_data *ha = vha->hw;
2183 struct pci_dev *pdev = ha->pdev;
2184 struct device_node *dp = pci_device_to_OF_node(pdev);
2188 val = of_get_property(dp, "port-wwn", &len);
2189 if (val && len >= WWN_SIZE)
2190 memcpy(nv->port_name, val, WWN_SIZE);
2192 val = of_get_property(dp, "node-wwn", &len);
2193 if (val && len >= WWN_SIZE)
2194 memcpy(nv->node_name, val, WWN_SIZE);
2199 * NVRAM configuration for ISP 2xxx
2202 * ha = adapter block pointer.
2205 * initialization control block in response_ring
2206 * host adapters parameters in host adapter block
2212 qla2x00_nvram_config(scsi_qla_host_t *vha)
2217 uint8_t *dptr1, *dptr2;
2218 struct qla_hw_data *ha = vha->hw;
2219 init_cb_t *icb = ha->init_cb;
2220 nvram_t *nv = ha->nvram;
2221 uint8_t *ptr = ha->nvram;
2222 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2226 /* Determine NVRAM starting address. */
2227 ha->nvram_size = sizeof(nvram_t);
2229 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2230 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
2231 ha->nvram_base = 0x80;
2233 /* Get NVRAM data and calculate checksum. */
2234 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
2235 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2238 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
2239 "Contents of NVRAM.\n");
2240 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
2241 (uint8_t *)nv, ha->nvram_size);
2243 /* Bad NVRAM data, set defaults parameters. */
2244 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2245 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2246 /* Reset NVRAM data. */
2247 ql_log(ql_log_warn, vha, 0x0064,
2248 "Inconisistent NVRAM "
2249 "detected: checksum=0x%x id=%c version=0x%x.\n",
2250 chksum, nv->id[0], nv->nvram_version);
2251 ql_log(ql_log_warn, vha, 0x0065,
2253 "functioning (yet invalid -- WWPN) defaults.\n");
2256 * Set default initialization control block.
2258 memset(nv, 0, ha->nvram_size);
2259 nv->parameter_block_version = ICB_VERSION;
2261 if (IS_QLA23XX(ha)) {
2262 nv->firmware_options[0] = BIT_2 | BIT_1;
2263 nv->firmware_options[1] = BIT_7 | BIT_5;
2264 nv->add_firmware_options[0] = BIT_5;
2265 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2266 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2267 nv->special_options[1] = BIT_7;
2268 } else if (IS_QLA2200(ha)) {
2269 nv->firmware_options[0] = BIT_2 | BIT_1;
2270 nv->firmware_options[1] = BIT_7 | BIT_5;
2271 nv->add_firmware_options[0] = BIT_5;
2272 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2273 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2274 } else if (IS_QLA2100(ha)) {
2275 nv->firmware_options[0] = BIT_3 | BIT_1;
2276 nv->firmware_options[1] = BIT_5;
2277 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2280 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2281 nv->execution_throttle = __constant_cpu_to_le16(16);
2282 nv->retry_count = 8;
2283 nv->retry_delay = 1;
2285 nv->port_name[0] = 33;
2286 nv->port_name[3] = 224;
2287 nv->port_name[4] = 139;
2289 qla2xxx_nvram_wwn_from_ofw(vha, nv);
2291 nv->login_timeout = 4;
2294 * Set default host adapter parameters
2296 nv->host_p[1] = BIT_2;
2297 nv->reset_delay = 5;
2298 nv->port_down_retry_count = 8;
2299 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2300 nv->link_down_timeout = 60;
2305 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2307 * The SN2 does not provide BIOS emulation which means you can't change
2308 * potentially bogus BIOS settings. Force the use of default settings
2309 * for link rate and frame size. Hope that the rest of the settings
2312 if (ia64_platform_is("sn2")) {
2313 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2315 nv->special_options[1] = BIT_7;
2319 /* Reset Initialization control block */
2320 memset(icb, 0, ha->init_cb_size);
2323 * Setup driver NVRAM options.
2325 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2326 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2327 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2328 nv->firmware_options[1] &= ~BIT_4;
2330 if (IS_QLA23XX(ha)) {
2331 nv->firmware_options[0] |= BIT_2;
2332 nv->firmware_options[0] &= ~BIT_3;
2333 nv->firmware_options[0] &= ~BIT_6;
2334 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
2336 if (IS_QLA2300(ha)) {
2337 if (ha->fb_rev == FPM_2310) {
2338 strcpy(ha->model_number, "QLA2310");
2340 strcpy(ha->model_number, "QLA2300");
2343 qla2x00_set_model_info(vha, nv->model_number,
2344 sizeof(nv->model_number), "QLA23xx");
2346 } else if (IS_QLA2200(ha)) {
2347 nv->firmware_options[0] |= BIT_2;
2349 * 'Point-to-point preferred, else loop' is not a safe
2350 * connection mode setting.
2352 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2354 /* Force 'loop preferred, else point-to-point'. */
2355 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2356 nv->add_firmware_options[0] |= BIT_5;
2358 strcpy(ha->model_number, "QLA22xx");
2359 } else /*if (IS_QLA2100(ha))*/ {
2360 strcpy(ha->model_number, "QLA2100");
2364 * Copy over NVRAM RISC parameter block to initialization control block.
2366 dptr1 = (uint8_t *)icb;
2367 dptr2 = (uint8_t *)&nv->parameter_block_version;
2368 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2370 *dptr1++ = *dptr2++;
2372 /* Copy 2nd half. */
2373 dptr1 = (uint8_t *)icb->add_firmware_options;
2374 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2376 *dptr1++ = *dptr2++;
2378 /* Use alternate WWN? */
2379 if (nv->host_p[1] & BIT_7) {
2380 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2381 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2384 /* Prepare nodename */
2385 if ((icb->firmware_options[1] & BIT_6) == 0) {
2387 * Firmware will apply the following mask if the nodename was
2390 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2391 icb->node_name[0] &= 0xF0;
2395 * Set host adapter parameters.
2399 * BIT_7 in the host-parameters section allows for modification to
2400 * internal driver logging.
2402 if (nv->host_p[0] & BIT_7)
2403 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
2404 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2405 /* Always load RISC code on non ISP2[12]00 chips. */
2406 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2407 ha->flags.disable_risc_code_load = 0;
2408 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2409 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2410 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
2411 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
2412 ha->flags.disable_serdes = 0;
2414 ha->operating_mode =
2415 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2417 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2418 sizeof(ha->fw_seriallink_options));
2420 /* save HBA serial number */
2421 ha->serial0 = icb->port_name[5];
2422 ha->serial1 = icb->port_name[6];
2423 ha->serial2 = icb->port_name[7];
2424 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2425 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
2427 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2429 ha->retry_count = nv->retry_count;
2431 /* Set minimum login_timeout to 4 seconds. */
2432 if (nv->login_timeout != ql2xlogintimeout)
2433 nv->login_timeout = ql2xlogintimeout;
2434 if (nv->login_timeout < 4)
2435 nv->login_timeout = 4;
2436 ha->login_timeout = nv->login_timeout;
2437 icb->login_timeout = nv->login_timeout;
2439 /* Set minimum RATOV to 100 tenths of a second. */
2442 ha->loop_reset_delay = nv->reset_delay;
2444 /* Link Down Timeout = 0:
2446 * When Port Down timer expires we will start returning
2447 * I/O's to OS with "DID_NO_CONNECT".
2449 * Link Down Timeout != 0:
2451 * The driver waits for the link to come up after link down
2452 * before returning I/Os to OS with "DID_NO_CONNECT".
2454 if (nv->link_down_timeout == 0) {
2455 ha->loop_down_abort_time =
2456 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
2458 ha->link_down_timeout = nv->link_down_timeout;
2459 ha->loop_down_abort_time =
2460 (LOOP_DOWN_TIME - ha->link_down_timeout);
2464 * Need enough time to try and get the port back.
2466 ha->port_down_retry_count = nv->port_down_retry_count;
2467 if (qlport_down_retry)
2468 ha->port_down_retry_count = qlport_down_retry;
2469 /* Set login_retry_count */
2470 ha->login_retry_count = nv->retry_count;
2471 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2472 ha->port_down_retry_count > 3)
2473 ha->login_retry_count = ha->port_down_retry_count;
2474 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2475 ha->login_retry_count = ha->port_down_retry_count;
2476 if (ql2xloginretrycount)
2477 ha->login_retry_count = ql2xloginretrycount;
2479 icb->lun_enables = __constant_cpu_to_le16(0);
2480 icb->command_resource_count = 0;
2481 icb->immediate_notify_resource_count = 0;
2482 icb->timeout = __constant_cpu_to_le16(0);
2484 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2486 icb->firmware_options[0] &= ~BIT_3;
2487 icb->add_firmware_options[0] &=
2488 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2489 icb->add_firmware_options[0] |= BIT_2;
2490 icb->response_accumulation_timer = 3;
2491 icb->interrupt_delay_timer = 5;
2493 vha->flags.process_response_queue = 1;
2496 if (!vha->flags.init_done) {
2497 ha->zio_mode = icb->add_firmware_options[0] &
2498 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2499 ha->zio_timer = icb->interrupt_delay_timer ?
2500 icb->interrupt_delay_timer: 2;
2502 icb->add_firmware_options[0] &=
2503 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2504 vha->flags.process_response_queue = 0;
2505 if (ha->zio_mode != QLA_ZIO_DISABLED) {
2506 ha->zio_mode = QLA_ZIO_MODE_6;
2508 ql_log(ql_log_info, vha, 0x0068,
2509 "ZIO mode %d enabled; timer delay (%d us).\n",
2510 ha->zio_mode, ha->zio_timer * 100);
2512 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2513 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
2514 vha->flags.process_response_queue = 1;
2519 ql_log(ql_log_warn, vha, 0x0069,
2520 "NVRAM configuration failed.\n");
2526 qla2x00_rport_del(void *data)
2528 fc_port_t *fcport = data;
2529 struct fc_rport *rport;
2530 unsigned long flags;
2532 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
2533 rport = fcport->drport ? fcport->drport: fcport->rport;
2534 fcport->drport = NULL;
2535 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
2537 fc_remote_port_delete(rport);
2541 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2543 * @flags: allocation flags
2545 * Returns a pointer to the allocated fcport, or NULL, if none available.
2548 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
2552 fcport = kzalloc(sizeof(fc_port_t), flags);
2556 /* Setup fcport template structure. */
2558 fcport->vp_idx = vha->vp_idx;
2559 fcport->port_type = FCT_UNKNOWN;
2560 fcport->loop_id = FC_NO_LOOP_ID;
2561 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
2562 fcport->supported_classes = FC_COS_UNSPECIFIED;
2568 * qla2x00_configure_loop
2569 * Updates Fibre Channel Device Database with what is actually on loop.
2572 * ha = adapter block pointer.
2577 * 2 = database was full and device was not configured.
2580 qla2x00_configure_loop(scsi_qla_host_t *vha)
2583 unsigned long flags, save_flags;
2584 struct qla_hw_data *ha = vha->hw;
2587 /* Get Initiator ID */
2588 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2589 rval = qla2x00_configure_hba(vha);
2590 if (rval != QLA_SUCCESS) {
2591 ql_dbg(ql_dbg_disc, vha, 0x2013,
2592 "Unable to configure HBA.\n");
2597 save_flags = flags = vha->dpc_flags;
2598 ql_dbg(ql_dbg_disc, vha, 0x2014,
2599 "Configure loop -- dpc flags = 0x%lx.\n", flags);
2602 * If we have both an RSCN and PORT UPDATE pending then handle them
2603 * both at the same time.
2605 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2606 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
2608 qla2x00_get_data_rate(vha);
2610 /* Determine what we need to do */
2611 if (ha->current_topology == ISP_CFG_FL &&
2612 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2614 vha->flags.rscn_queue_overflow = 1;
2615 set_bit(RSCN_UPDATE, &flags);
2617 } else if (ha->current_topology == ISP_CFG_F &&
2618 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2620 vha->flags.rscn_queue_overflow = 1;
2621 set_bit(RSCN_UPDATE, &flags);
2622 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2624 } else if (ha->current_topology == ISP_CFG_N) {
2625 clear_bit(RSCN_UPDATE, &flags);
2627 } else if (!vha->flags.online ||
2628 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2630 vha->flags.rscn_queue_overflow = 1;
2631 set_bit(RSCN_UPDATE, &flags);
2632 set_bit(LOCAL_LOOP_UPDATE, &flags);
2635 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
2636 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2637 ql_dbg(ql_dbg_disc, vha, 0x2015,
2638 "Loop resync needed, failing.\n");
2639 rval = QLA_FUNCTION_FAILED;
2642 rval = qla2x00_configure_local_loop(vha);
2645 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
2646 if (LOOP_TRANSITION(vha)) {
2647 ql_dbg(ql_dbg_disc, vha, 0x201e,
2648 "Needs RSCN update and loop transition.\n");
2649 rval = QLA_FUNCTION_FAILED;
2652 rval = qla2x00_configure_fabric(vha);
2655 if (rval == QLA_SUCCESS) {
2656 if (atomic_read(&vha->loop_down_timer) ||
2657 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2658 rval = QLA_FUNCTION_FAILED;
2660 atomic_set(&vha->loop_state, LOOP_READY);
2661 ql_dbg(ql_dbg_disc, vha, 0x2069,
2667 ql_dbg(ql_dbg_disc, vha, 0x206a,
2668 "%s *** FAILED ***.\n", __func__);
2670 ql_dbg(ql_dbg_disc, vha, 0x206b,
2671 "%s: exiting normally.\n", __func__);
2674 /* Restore state if a resync event occurred during processing */
2675 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2676 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
2677 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2678 if (test_bit(RSCN_UPDATE, &save_flags)) {
2679 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2680 if (!IS_ALOGIO_CAPABLE(ha))
2681 vha->flags.rscn_queue_overflow = 1;
2691 * qla2x00_configure_local_loop
2692 * Updates Fibre Channel Device Database with local loop devices.
2695 * ha = adapter block pointer.
2701 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
2706 fc_port_t *fcport, *new_fcport;
2712 uint8_t domain, area, al_pa;
2713 struct qla_hw_data *ha = vha->hw;
2717 entries = MAX_FIBRE_DEVICES;
2719 ql_dbg(ql_dbg_disc, vha, 0x2016,
2720 "Getting FCAL position map.\n");
2721 if (ql2xextended_error_logging & ql_dbg_disc)
2722 qla2x00_get_fcal_position_map(vha, NULL);
2724 /* Get list of logged in devices. */
2725 memset(ha->gid_list, 0, GID_LIST_SIZE);
2726 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
2728 if (rval != QLA_SUCCESS)
2729 goto cleanup_allocation;
2731 ql_dbg(ql_dbg_disc, vha, 0x2017,
2732 "Entries in ID list (%d).\n", entries);
2733 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
2734 (uint8_t *)ha->gid_list,
2735 entries * sizeof(struct gid_list_info));
2737 /* Allocate temporary fcport for any new fcports discovered. */
2738 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2739 if (new_fcport == NULL) {
2740 ql_log(ql_log_warn, vha, 0x2018,
2741 "Memory allocation failed for fcport.\n");
2742 rval = QLA_MEMORY_ALLOC_FAILED;
2743 goto cleanup_allocation;
2745 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2748 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2750 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2751 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2752 fcport->port_type != FCT_BROADCAST &&
2753 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2755 ql_dbg(ql_dbg_disc, vha, 0x2019,
2756 "Marking port lost loop_id=0x%04x.\n",
2759 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
2763 /* Add devices to port list. */
2764 id_iter = (char *)ha->gid_list;
2765 for (index = 0; index < entries; index++) {
2766 domain = ((struct gid_list_info *)id_iter)->domain;
2767 area = ((struct gid_list_info *)id_iter)->area;
2768 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
2769 if (IS_QLA2100(ha) || IS_QLA2200(ha))
2770 loop_id = (uint16_t)
2771 ((struct gid_list_info *)id_iter)->loop_id_2100;
2773 loop_id = le16_to_cpu(
2774 ((struct gid_list_info *)id_iter)->loop_id);
2775 id_iter += ha->gid_list_info_size;
2777 /* Bypass reserved domain fields. */
2778 if ((domain & 0xf0) == 0xf0)
2781 /* Bypass if not same domain and area of adapter. */
2782 if (area && domain &&
2783 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
2786 /* Bypass invalid local loop ID. */
2787 if (loop_id > LAST_LOCAL_LOOP_ID)
2790 /* Fill in member data. */
2791 new_fcport->d_id.b.domain = domain;
2792 new_fcport->d_id.b.area = area;
2793 new_fcport->d_id.b.al_pa = al_pa;
2794 new_fcport->loop_id = loop_id;
2795 new_fcport->vp_idx = vha->vp_idx;
2796 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
2797 if (rval2 != QLA_SUCCESS) {
2798 ql_dbg(ql_dbg_disc, vha, 0x201a,
2799 "Failed to retrieve fcport information "
2800 "-- get_port_database=%x, loop_id=0x%04x.\n",
2801 rval2, new_fcport->loop_id);
2802 ql_dbg(ql_dbg_disc, vha, 0x201b,
2803 "Scheduling resync.\n");
2804 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2808 /* Check for matching device in port list. */
2811 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2812 if (memcmp(new_fcport->port_name, fcport->port_name,
2816 fcport->flags &= ~FCF_FABRIC_DEVICE;
2817 fcport->loop_id = new_fcport->loop_id;
2818 fcport->port_type = new_fcport->port_type;
2819 fcport->d_id.b24 = new_fcport->d_id.b24;
2820 memcpy(fcport->node_name, new_fcport->node_name,
2828 /* New device, add to fcports list. */
2830 new_fcport->vha = vha;
2831 new_fcport->vp_idx = vha->vp_idx;
2833 list_add_tail(&new_fcport->list, &vha->vp_fcports);
2835 /* Allocate a new replacement fcport. */
2836 fcport = new_fcport;
2837 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2838 if (new_fcport == NULL) {
2839 ql_log(ql_log_warn, vha, 0x201c,
2840 "Failed to allocate memory for fcport.\n");
2841 rval = QLA_MEMORY_ALLOC_FAILED;
2842 goto cleanup_allocation;
2844 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2847 /* Base iIDMA settings on HBA port speed. */
2848 fcport->fp_speed = ha->link_data_rate;
2850 qla2x00_update_fcport(vha, fcport);
2858 if (rval != QLA_SUCCESS) {
2859 ql_dbg(ql_dbg_disc, vha, 0x201d,
2860 "Configure local loop error exit: rval=%x.\n", rval);
2867 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
2869 #define LS_UNKNOWN 2
2870 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2874 struct qla_hw_data *ha = vha->hw;
2876 if (!IS_IIDMA_CAPABLE(ha))
2879 if (atomic_read(&fcport->state) != FCS_ONLINE)
2882 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2883 fcport->fp_speed > ha->link_data_rate)
2886 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
2888 if (rval != QLA_SUCCESS) {
2889 ql_dbg(ql_dbg_disc, vha, 0x2004,
2890 "Unable to adjust iIDMA "
2891 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x "
2892 "%04x.\n", fcport->port_name[0], fcport->port_name[1],
2893 fcport->port_name[2], fcport->port_name[3],
2894 fcport->port_name[4], fcport->port_name[5],
2895 fcport->port_name[6], fcport->port_name[7], rval,
2896 fcport->fp_speed, mb[0], mb[1]);
2898 link_speed = link_speeds[LS_UNKNOWN];
2899 if (fcport->fp_speed < 5)
2900 link_speed = link_speeds[fcport->fp_speed];
2901 else if (fcport->fp_speed == 0x13)
2902 link_speed = link_speeds[5];
2903 ql_dbg(ql_dbg_disc, vha, 0x2005,
2904 "iIDMA adjusted to %s GB/s "
2905 "on %02x%02x%02x%02x%02x%02x%02x%02x.\n", link_speed,
2906 fcport->port_name[0], fcport->port_name[1],
2907 fcport->port_name[2], fcport->port_name[3],
2908 fcport->port_name[4], fcport->port_name[5],
2909 fcport->port_name[6], fcport->port_name[7]);
2914 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
2916 struct fc_rport_identifiers rport_ids;
2917 struct fc_rport *rport;
2918 unsigned long flags;
2920 qla2x00_rport_del(fcport);
2922 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2923 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2924 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2925 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2926 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2927 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
2929 ql_log(ql_log_warn, vha, 0x2006,
2930 "Unable to allocate fc remote port.\n");
2933 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
2934 *((fc_port_t **)rport->dd_data) = fcport;
2935 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
2937 rport->supported_classes = fcport->supported_classes;
2939 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2940 if (fcport->port_type == FCT_INITIATOR)
2941 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2942 if (fcport->port_type == FCT_TARGET)
2943 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2944 fc_remote_port_rolechg(rport, rport_ids.roles);
2948 * qla2x00_update_fcport
2949 * Updates device on list.
2952 * ha = adapter block pointer.
2953 * fcport = port structure pointer.
2963 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
2966 fcport->login_retry = 0;
2967 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
2969 qla2x00_iidma_fcport(vha, fcport);
2970 qla24xx_update_fcport_fcp_prio(vha, fcport);
2971 qla2x00_reg_remote_port(vha, fcport);
2972 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
2976 * qla2x00_configure_fabric
2977 * Setup SNS devices with loop ID's.
2980 * ha = adapter block pointer.
2987 qla2x00_configure_fabric(scsi_qla_host_t *vha)
2990 fc_port_t *fcport, *fcptemp;
2991 uint16_t next_loopid;
2992 uint16_t mb[MAILBOX_REGISTER_COUNT];
2994 LIST_HEAD(new_fcports);
2995 struct qla_hw_data *ha = vha->hw;
2996 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2998 /* If FL port exists, then SNS is present */
2999 if (IS_FWI2_CAPABLE(ha))
3000 loop_id = NPH_F_PORT;
3002 loop_id = SNS_FL_PORT;
3003 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
3004 if (rval != QLA_SUCCESS) {
3005 ql_dbg(ql_dbg_disc, vha, 0x201f,
3006 "MBX_GET_PORT_NAME failed, No FL Port.\n");
3008 vha->device_flags &= ~SWITCH_FOUND;
3009 return (QLA_SUCCESS);
3011 vha->device_flags |= SWITCH_FOUND;
3013 /* Mark devices that need re-synchronization. */
3014 rval2 = qla2x00_device_resync(vha);
3015 if (rval2 == QLA_RSCNS_HANDLED) {
3016 /* No point doing the scan, just continue. */
3017 return (QLA_SUCCESS);
3021 if (ql2xfdmienable &&
3022 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
3023 qla2x00_fdmi_register(vha);
3025 /* Ensure we are logged into the SNS. */
3026 if (IS_FWI2_CAPABLE(ha))
3029 loop_id = SIMPLE_NAME_SERVER;
3030 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
3031 0xfc, mb, BIT_1 | BIT_0);
3032 if (mb[0] != MBS_COMMAND_COMPLETE) {
3033 ql_dbg(ql_dbg_disc, vha, 0x2042,
3034 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
3035 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
3036 mb[2], mb[6], mb[7]);
3037 return (QLA_SUCCESS);
3040 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3041 if (qla2x00_rft_id(vha)) {
3043 ql_dbg(ql_dbg_disc, vha, 0x2045,
3044 "Register FC-4 TYPE failed.\n");
3046 if (qla2x00_rff_id(vha)) {
3048 ql_dbg(ql_dbg_disc, vha, 0x2049,
3049 "Register FC-4 Features failed.\n");
3051 if (qla2x00_rnn_id(vha)) {
3053 ql_dbg(ql_dbg_disc, vha, 0x204f,
3054 "Register Node Name failed.\n");
3055 } else if (qla2x00_rsnn_nn(vha)) {
3057 ql_dbg(ql_dbg_disc, vha, 0x2053,
3058 "Register Symobilic Node Name failed.\n");
3062 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
3063 if (rval != QLA_SUCCESS)
3067 * Logout all previous fabric devices marked lost, except
3070 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3071 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3074 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3077 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
3078 qla2x00_mark_device_lost(vha, fcport,
3079 ql2xplogiabsentdevice, 0);
3080 if (fcport->loop_id != FC_NO_LOOP_ID &&
3081 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
3082 fcport->port_type != FCT_INITIATOR &&
3083 fcport->port_type != FCT_BROADCAST) {
3084 ha->isp_ops->fabric_logout(vha,
3086 fcport->d_id.b.domain,
3087 fcport->d_id.b.area,
3088 fcport->d_id.b.al_pa);
3089 fcport->loop_id = FC_NO_LOOP_ID;
3094 /* Starting free loop ID. */
3095 next_loopid = ha->min_external_loopid;
3098 * Scan through our port list and login entries that need to be
3101 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3102 if (atomic_read(&vha->loop_down_timer) ||
3103 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3106 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3107 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3110 if (fcport->loop_id == FC_NO_LOOP_ID) {
3111 fcport->loop_id = next_loopid;
3112 rval = qla2x00_find_new_loop_id(
3114 if (rval != QLA_SUCCESS) {
3115 /* Ran out of IDs to use */
3119 /* Login and update database */
3120 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
3123 /* Exit if out of loop IDs. */
3124 if (rval != QLA_SUCCESS) {
3129 * Login and add the new devices to our port list.
3131 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3132 if (atomic_read(&vha->loop_down_timer) ||
3133 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3136 /* Find a new loop ID to use. */
3137 fcport->loop_id = next_loopid;
3138 rval = qla2x00_find_new_loop_id(base_vha, fcport);
3139 if (rval != QLA_SUCCESS) {
3140 /* Ran out of IDs to use */
3144 /* Login and update database */
3145 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
3149 fcport->vp_idx = vha->vp_idx;
3151 list_move_tail(&fcport->list, &vha->vp_fcports);
3155 /* Free all new device structures not processed. */
3156 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3157 list_del(&fcport->list);
3162 ql_dbg(ql_dbg_disc, vha, 0x2068,
3163 "Configure fabric error exit rval=%d.\n", rval);
3170 * qla2x00_find_all_fabric_devs
3173 * ha = adapter block pointer.
3174 * dev = database device entry pointer.
3183 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3184 struct list_head *new_fcports)
3188 fc_port_t *fcport, *new_fcport, *fcptemp;
3193 int first_dev, last_dev;
3194 port_id_t wrap = {}, nxt_d_id;
3195 struct qla_hw_data *ha = vha->hw;
3196 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
3197 struct scsi_qla_host *tvp;
3201 /* Try GID_PT to get device list, else GAN. */
3202 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
3205 ql_dbg(ql_dbg_disc, vha, 0x2054,
3206 "GID_PT allocations failed, fallback on GA_NXT.\n");
3208 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
3211 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
3214 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
3217 } else if (ql2xiidmaenable &&
3218 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3219 qla2x00_gpsc(vha, swl);
3222 /* If other queries succeeded probe for FC-4 type */
3224 qla2x00_gff_id(vha, swl);
3228 /* Allocate temporary fcport for any new fcports discovered. */
3229 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
3230 if (new_fcport == NULL) {
3231 ql_log(ql_log_warn, vha, 0x205e,
3232 "Failed to allocate memory for fcport.\n");
3234 return (QLA_MEMORY_ALLOC_FAILED);
3236 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3237 /* Set start port ID scan at adapter ID. */
3241 /* Starting free loop ID. */
3242 loop_id = ha->min_external_loopid;
3243 for (; loop_id <= ha->max_loop_id; loop_id++) {
3244 if (qla2x00_is_reserved_id(vha, loop_id))
3247 if (ha->current_topology == ISP_CFG_FL &&
3248 (atomic_read(&vha->loop_down_timer) ||
3249 LOOP_TRANSITION(vha))) {
3250 atomic_set(&vha->loop_down_timer, 0);
3251 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3252 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
3258 wrap.b24 = new_fcport->d_id.b24;
3260 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3261 memcpy(new_fcport->node_name,
3262 swl[swl_idx].node_name, WWN_SIZE);
3263 memcpy(new_fcport->port_name,
3264 swl[swl_idx].port_name, WWN_SIZE);
3265 memcpy(new_fcport->fabric_port_name,
3266 swl[swl_idx].fabric_port_name, WWN_SIZE);
3267 new_fcport->fp_speed = swl[swl_idx].fp_speed;
3268 new_fcport->fc4_type = swl[swl_idx].fc4_type;
3270 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3276 /* Send GA_NXT to the switch */
3277 rval = qla2x00_ga_nxt(vha, new_fcport);
3278 if (rval != QLA_SUCCESS) {
3279 ql_log(ql_log_warn, vha, 0x2064,
3280 "SNS scan failed -- assuming "
3281 "zero-entry result.\n");
3282 list_for_each_entry_safe(fcport, fcptemp,
3283 new_fcports, list) {
3284 list_del(&fcport->list);
3292 /* If wrap on switch device list, exit. */
3294 wrap.b24 = new_fcport->d_id.b24;
3296 } else if (new_fcport->d_id.b24 == wrap.b24) {
3297 ql_dbg(ql_dbg_disc, vha, 0x2065,
3298 "Device wrap (%02x%02x%02x).\n",
3299 new_fcport->d_id.b.domain,
3300 new_fcport->d_id.b.area,
3301 new_fcport->d_id.b.al_pa);
3305 /* Bypass if same physical adapter. */
3306 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
3309 /* Bypass virtual ports of the same host. */
3311 if (ha->num_vhosts) {
3312 unsigned long flags;
3314 spin_lock_irqsave(&ha->vport_slock, flags);
3315 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
3316 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3321 spin_unlock_irqrestore(&ha->vport_slock, flags);
3327 /* Bypass if same domain and area of adapter. */
3328 if (((new_fcport->d_id.b24 & 0xffff00) ==
3329 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
3333 /* Bypass reserved domain fields. */
3334 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3337 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
3338 if (ql2xgffidenable &&
3339 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3340 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
3343 /* Locate matching device in database. */
3345 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3346 if (memcmp(new_fcport->port_name, fcport->port_name,
3352 /* Update port state. */
3353 memcpy(fcport->fabric_port_name,
3354 new_fcport->fabric_port_name, WWN_SIZE);
3355 fcport->fp_speed = new_fcport->fp_speed;
3358 * If address the same and state FCS_ONLINE, nothing
3361 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3362 atomic_read(&fcport->state) == FCS_ONLINE) {
3367 * If device was not a fabric device before.
3369 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3370 fcport->d_id.b24 = new_fcport->d_id.b24;
3371 fcport->loop_id = FC_NO_LOOP_ID;
3372 fcport->flags |= (FCF_FABRIC_DEVICE |
3378 * Port ID changed or device was marked to be updated;
3379 * Log it out if still logged in and mark it for
3382 fcport->d_id.b24 = new_fcport->d_id.b24;
3383 fcport->flags |= FCF_LOGIN_NEEDED;
3384 if (fcport->loop_id != FC_NO_LOOP_ID &&
3385 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
3386 fcport->port_type != FCT_INITIATOR &&
3387 fcport->port_type != FCT_BROADCAST) {
3388 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3389 fcport->d_id.b.domain, fcport->d_id.b.area,
3390 fcport->d_id.b.al_pa);
3391 fcport->loop_id = FC_NO_LOOP_ID;
3399 /* If device was not in our fcports list, then add it. */
3400 list_add_tail(&new_fcport->list, new_fcports);
3402 /* Allocate a new replacement fcport. */
3403 nxt_d_id.b24 = new_fcport->d_id.b24;
3404 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
3405 if (new_fcport == NULL) {
3406 ql_log(ql_log_warn, vha, 0x2066,
3407 "Memory allocation failed for fcport.\n");
3409 return (QLA_MEMORY_ALLOC_FAILED);
3411 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3412 new_fcport->d_id.b24 = nxt_d_id.b24;
3422 * qla2x00_find_new_loop_id
3423 * Scan through our port list and find a new usable loop ID.
3426 * ha: adapter state pointer.
3427 * dev: port structure pointer.
3430 * qla2x00 local function return status code.
3436 qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
3441 uint16_t first_loop_id;
3442 struct qla_hw_data *ha = vha->hw;
3443 struct scsi_qla_host *vp;
3444 struct scsi_qla_host *tvp;
3445 unsigned long flags = 0;
3449 /* Save starting loop ID. */
3450 first_loop_id = dev->loop_id;
3453 /* Skip loop ID if already used by adapter. */
3454 if (dev->loop_id == vha->loop_id)
3457 /* Skip reserved loop IDs. */
3458 while (qla2x00_is_reserved_id(vha, dev->loop_id))
3461 /* Reset loop ID if passed the end. */
3462 if (dev->loop_id > ha->max_loop_id) {
3463 /* first loop ID. */
3464 dev->loop_id = ha->min_external_loopid;
3467 /* Check for loop ID being already in use. */
3471 spin_lock_irqsave(&ha->vport_slock, flags);
3472 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
3473 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3474 if (fcport->loop_id == dev->loop_id &&
3476 /* ID possibly in use */
3484 spin_unlock_irqrestore(&ha->vport_slock, flags);
3486 /* If not in use then it is free to use. */
3491 /* ID in use. Try next value. */
3494 /* If wrap around. No free ID to use. */
3495 if (dev->loop_id == first_loop_id) {
3496 dev->loop_id = FC_NO_LOOP_ID;
3497 rval = QLA_FUNCTION_FAILED;
3506 * qla2x00_device_resync
3507 * Marks devices in the database that needs resynchronization.
3510 * ha = adapter block pointer.
3516 qla2x00_device_resync(scsi_qla_host_t *vha)
3521 uint32_t rscn_entry;
3522 uint8_t rscn_out_iter;
3524 port_id_t d_id = {};
3526 rval = QLA_RSCNS_HANDLED;
3528 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3529 vha->flags.rscn_queue_overflow) {
3531 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
3532 format = MSB(MSW(rscn_entry));
3533 d_id.b.domain = LSB(MSW(rscn_entry));
3534 d_id.b.area = MSB(LSW(rscn_entry));
3535 d_id.b.al_pa = LSB(LSW(rscn_entry));
3537 ql_dbg(ql_dbg_disc, vha, 0x2020,
3538 "RSCN queue entry[%d] = [%02x/%02x%02x%02x].\n",
3539 vha->rscn_out_ptr, format, d_id.b.domain, d_id.b.area,
3542 vha->rscn_out_ptr++;
3543 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3544 vha->rscn_out_ptr = 0;
3546 /* Skip duplicate entries. */
3547 for (rscn_out_iter = vha->rscn_out_ptr;
3548 !vha->flags.rscn_queue_overflow &&
3549 rscn_out_iter != vha->rscn_in_ptr;
3550 rscn_out_iter = (rscn_out_iter ==
3551 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3553 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
3556 ql_dbg(ql_dbg_disc, vha, 0x2021,
3557 "Skipping duplicate RSCN queue entry found at "
3558 "[%d].\n", rscn_out_iter);
3560 vha->rscn_out_ptr = rscn_out_iter;
3563 /* Queue overflow, set switch default case. */
3564 if (vha->flags.rscn_queue_overflow) {
3565 ql_dbg(ql_dbg_disc, vha, 0x2022,
3566 "device_resync: rscn overflow.\n");
3569 vha->flags.rscn_queue_overflow = 0;
3585 vha->rscn_out_ptr = vha->rscn_in_ptr;
3591 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3592 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3593 (fcport->d_id.b24 & mask) != d_id.b24 ||
3594 fcport->port_type == FCT_BROADCAST)
3597 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3599 fcport->port_type != FCT_INITIATOR) {
3600 qla2x00_mark_device_lost(vha, fcport,
3610 * qla2x00_fabric_dev_login
3611 * Login fabric target device and update FC port database.
3614 * ha: adapter state pointer.
3615 * fcport: port structure list pointer.
3616 * next_loopid: contains value of a new loop ID that can be used
3617 * by the next login attempt.
3620 * qla2x00 local function return status code.
3626 qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
3627 uint16_t *next_loopid)
3632 struct qla_hw_data *ha = vha->hw;
3637 if (IS_ALOGIO_CAPABLE(ha)) {
3638 if (fcport->flags & FCF_ASYNC_SENT)
3640 fcport->flags |= FCF_ASYNC_SENT;
3641 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3646 fcport->flags &= ~FCF_ASYNC_SENT;
3647 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
3648 if (rval == QLA_SUCCESS) {
3649 /* Send an ADISC to FCP2 devices.*/
3651 if (fcport->flags & FCF_FCP2_DEVICE)
3653 rval = qla2x00_get_port_database(vha, fcport, opts);
3654 if (rval != QLA_SUCCESS) {
3655 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3656 fcport->d_id.b.domain, fcport->d_id.b.area,
3657 fcport->d_id.b.al_pa);
3658 qla2x00_mark_device_lost(vha, fcport, 1, 0);
3660 qla2x00_update_fcport(vha, fcport);
3668 * qla2x00_fabric_login
3669 * Issue fabric login command.
3672 * ha = adapter block pointer.
3673 * device = pointer to FC device type structure.
3676 * 0 - Login successfully
3678 * 2 - Initiator device
3682 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
3683 uint16_t *next_loopid)
3687 uint16_t tmp_loopid;
3688 uint16_t mb[MAILBOX_REGISTER_COUNT];
3689 struct qla_hw_data *ha = vha->hw;
3695 ql_dbg(ql_dbg_disc, vha, 0x2000,
3696 "Trying Fabric Login w/loop id 0x%04x for port "
3698 fcport->loop_id, fcport->d_id.b.domain,
3699 fcport->d_id.b.area, fcport->d_id.b.al_pa);
3701 /* Login fcport on switch. */
3702 ha->isp_ops->fabric_login(vha, fcport->loop_id,
3703 fcport->d_id.b.domain, fcport->d_id.b.area,
3704 fcport->d_id.b.al_pa, mb, BIT_0);
3705 if (mb[0] == MBS_PORT_ID_USED) {
3707 * Device has another loop ID. The firmware team
3708 * recommends the driver perform an implicit login with
3709 * the specified ID again. The ID we just used is save
3710 * here so we return with an ID that can be tried by
3714 tmp_loopid = fcport->loop_id;
3715 fcport->loop_id = mb[1];
3717 ql_dbg(ql_dbg_disc, vha, 0x2001,
3718 "Fabric Login: port in use - next loop "
3719 "id=0x%04x, port id= %02x%02x%02x.\n",
3720 fcport->loop_id, fcport->d_id.b.domain,
3721 fcport->d_id.b.area, fcport->d_id.b.al_pa);
3723 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3728 /* A retry occurred before. */
3729 *next_loopid = tmp_loopid;
3732 * No retry occurred before. Just increment the
3733 * ID value for next login.
3735 *next_loopid = (fcport->loop_id + 1);
3738 if (mb[1] & BIT_0) {
3739 fcport->port_type = FCT_INITIATOR;
3741 fcport->port_type = FCT_TARGET;
3742 if (mb[1] & BIT_1) {
3743 fcport->flags |= FCF_FCP2_DEVICE;
3748 fcport->supported_classes |= FC_COS_CLASS2;
3750 fcport->supported_classes |= FC_COS_CLASS3;
3754 } else if (mb[0] == MBS_LOOP_ID_USED) {
3756 * Loop ID already used, try next loop ID.
3759 rval = qla2x00_find_new_loop_id(vha, fcport);
3760 if (rval != QLA_SUCCESS) {
3761 /* Ran out of loop IDs to use */
3764 } else if (mb[0] == MBS_COMMAND_ERROR) {
3766 * Firmware possibly timed out during login. If NO
3767 * retries are left to do then the device is declared
3770 *next_loopid = fcport->loop_id;
3771 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3772 fcport->d_id.b.domain, fcport->d_id.b.area,
3773 fcport->d_id.b.al_pa);
3774 qla2x00_mark_device_lost(vha, fcport, 1, 0);
3780 * unrecoverable / not handled error
3782 ql_dbg(ql_dbg_disc, vha, 0x2002,
3783 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
3784 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
3785 fcport->d_id.b.area, fcport->d_id.b.al_pa,
3786 fcport->loop_id, jiffies);
3788 *next_loopid = fcport->loop_id;
3789 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3790 fcport->d_id.b.domain, fcport->d_id.b.area,
3791 fcport->d_id.b.al_pa);
3792 fcport->loop_id = FC_NO_LOOP_ID;
3793 fcport->login_retry = 0;
3804 * qla2x00_local_device_login
3805 * Issue local device login command.
3808 * ha = adapter block pointer.
3809 * loop_id = loop id of device to login to.
3811 * Returns (Where's the #define!!!!):
3812 * 0 - Login successfully
3817 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
3820 uint16_t mb[MAILBOX_REGISTER_COUNT];
3822 memset(mb, 0, sizeof(mb));
3823 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
3824 if (rval == QLA_SUCCESS) {
3825 /* Interrogate mailbox registers for any errors */
3826 if (mb[0] == MBS_COMMAND_ERROR)
3828 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3829 /* device not in PCB table */
3837 * qla2x00_loop_resync
3838 * Resync with fibre channel devices.
3841 * ha = adapter block pointer.
3847 qla2x00_loop_resync(scsi_qla_host_t *vha)
3849 int rval = QLA_SUCCESS;
3851 struct req_que *req;
3852 struct rsp_que *rsp;
3854 if (vha->hw->flags.cpu_affinity_enabled)
3855 req = vha->hw->req_q_map[0];
3860 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3861 if (vha->flags.online) {
3862 if (!(rval = qla2x00_fw_ready(vha))) {
3863 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3866 /* Issue a marker after FW becomes ready. */
3867 qla2x00_marker(vha, req, rsp, 0, 0,
3869 vha->marker_needed = 0;
3871 /* Remap devices on Loop. */
3872 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3874 qla2x00_configure_loop(vha);
3876 } while (!atomic_read(&vha->loop_down_timer) &&
3877 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3878 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3883 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3884 return (QLA_FUNCTION_FAILED);
3887 ql_dbg(ql_dbg_disc, vha, 0x206c,
3888 "%s *** FAILED ***.\n", __func__);
3894 * qla2x00_perform_loop_resync
3895 * Description: This function will set the appropriate flags and call
3896 * qla2x00_loop_resync. If successful loop will be resynced
3897 * Arguments : scsi_qla_host_t pointer
3898 * returm : Success or Failure
3901 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
3905 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
3906 /*Configure the flags so that resync happens properly*/
3907 atomic_set(&ha->loop_down_timer, 0);
3908 if (!(ha->device_flags & DFLG_NO_CABLE)) {
3909 atomic_set(&ha->loop_state, LOOP_UP);
3910 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
3911 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
3912 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3914 rval = qla2x00_loop_resync(ha);
3916 atomic_set(&ha->loop_state, LOOP_DEAD);
3918 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
3925 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
3928 struct scsi_qla_host *vha;
3929 struct qla_hw_data *ha = base_vha->hw;
3930 unsigned long flags;
3932 spin_lock_irqsave(&ha->vport_slock, flags);
3933 /* Go with deferred removal of rport references. */
3934 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
3935 atomic_inc(&vha->vref_count);
3936 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3937 if (fcport->drport &&
3938 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
3939 spin_unlock_irqrestore(&ha->vport_slock, flags);
3941 qla2x00_rport_del(fcport);
3943 spin_lock_irqsave(&ha->vport_slock, flags);
3946 atomic_dec(&vha->vref_count);
3948 spin_unlock_irqrestore(&ha->vport_slock, flags);
3952 * qla82xx_quiescent_state_cleanup
3953 * Description: This function will block the new I/Os
3954 * Its not aborting any I/Os as context
3955 * is not destroyed during quiescence
3956 * Arguments: scsi_qla_host_t
3960 qla82xx_quiescent_state_cleanup(scsi_qla_host_t *vha)
3962 struct qla_hw_data *ha = vha->hw;
3963 struct scsi_qla_host *vp;
3965 ql_dbg(ql_dbg_p3p, vha, 0xb002,
3966 "Performing ISP error recovery - ha=%p.\n", ha);
3968 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3969 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3970 atomic_set(&vha->loop_state, LOOP_DOWN);
3971 qla2x00_mark_all_devices_lost(vha, 0);
3972 list_for_each_entry(vp, &ha->vp_list, list)
3973 qla2x00_mark_all_devices_lost(vha, 0);
3975 if (!atomic_read(&vha->loop_down_timer))
3976 atomic_set(&vha->loop_down_timer,
3979 /* Wait for pending cmds to complete */
3980 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
3984 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3986 struct qla_hw_data *ha = vha->hw;
3987 struct scsi_qla_host *vp;
3988 unsigned long flags;
3991 /* For ISP82XX, driver waits for completion of the commands.
3992 * online flag should be set.
3994 if (!IS_QLA82XX(ha))
3995 vha->flags.online = 0;
3996 ha->flags.chip_reset_done = 0;
3997 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3998 ha->qla_stats.total_isp_aborts++;
4000 ql_log(ql_log_info, vha, 0x00af,
4001 "Performing ISP error recovery - ha=%p.\n", ha);
4003 /* For ISP82XX, reset_chip is just disabling interrupts.
4004 * Driver waits for the completion of the commands.
4005 * the interrupts need to be enabled.
4007 if (!IS_QLA82XX(ha))
4008 ha->isp_ops->reset_chip(vha);
4010 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
4011 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4012 atomic_set(&vha->loop_state, LOOP_DOWN);
4013 qla2x00_mark_all_devices_lost(vha, 0);
4015 spin_lock_irqsave(&ha->vport_slock, flags);
4016 list_for_each_entry(vp, &ha->vp_list, list) {
4017 atomic_inc(&vp->vref_count);
4018 spin_unlock_irqrestore(&ha->vport_slock, flags);
4020 qla2x00_mark_all_devices_lost(vp, 0);
4022 spin_lock_irqsave(&ha->vport_slock, flags);
4023 atomic_dec(&vp->vref_count);
4025 spin_unlock_irqrestore(&ha->vport_slock, flags);
4027 if (!atomic_read(&vha->loop_down_timer))
4028 atomic_set(&vha->loop_down_timer,
4032 /* Clear all async request states across all VPs. */
4033 list_for_each_entry(fcport, &vha->vp_fcports, list)
4034 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4035 spin_lock_irqsave(&ha->vport_slock, flags);
4036 list_for_each_entry(vp, &ha->vp_list, list) {
4037 atomic_inc(&vp->vref_count);
4038 spin_unlock_irqrestore(&ha->vport_slock, flags);
4040 list_for_each_entry(fcport, &vp->vp_fcports, list)
4041 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4043 spin_lock_irqsave(&ha->vport_slock, flags);
4044 atomic_dec(&vp->vref_count);
4046 spin_unlock_irqrestore(&ha->vport_slock, flags);
4048 if (!ha->flags.eeh_busy) {
4049 /* Make sure for ISP 82XX IO DMA is complete */
4050 if (IS_QLA82XX(ha)) {
4051 qla82xx_chip_reset_cleanup(vha);
4052 ql_log(ql_log_info, vha, 0x00b4,
4053 "Done chip reset cleanup.\n");
4055 /* Done waiting for pending commands.
4056 * Reset the online flag.
4058 vha->flags.online = 0;
4061 /* Requeue all commands in outstanding command list. */
4062 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
4068 * Resets ISP and aborts all outstanding commands.
4071 * ha = adapter block pointer.
4077 qla2x00_abort_isp(scsi_qla_host_t *vha)
4081 struct qla_hw_data *ha = vha->hw;
4082 struct scsi_qla_host *vp;
4083 struct req_que *req = ha->req_q_map[0];
4084 unsigned long flags;
4086 if (vha->flags.online) {
4087 qla2x00_abort_isp_cleanup(vha);
4089 if (unlikely(pci_channel_offline(ha->pdev) &&
4090 ha->flags.pci_channel_io_perm_failure)) {
4091 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4096 ha->isp_ops->get_flash_version(vha, req->ring);
4098 ha->isp_ops->nvram_config(vha);
4100 if (!qla2x00_restart_isp(vha)) {
4101 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
4103 if (!atomic_read(&vha->loop_down_timer)) {
4105 * Issue marker command only when we are going
4106 * to start the I/O .
4108 vha->marker_needed = 1;
4111 vha->flags.online = 1;
4113 ha->isp_ops->enable_intrs(ha);
4115 ha->isp_abort_cnt = 0;
4116 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4118 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
4119 qla2x00_get_fw_version(vha);
4121 ha->flags.fce_enabled = 1;
4123 fce_calc_size(ha->fce_bufs));
4124 rval = qla2x00_enable_fce_trace(vha,
4125 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
4128 ql_log(ql_log_warn, vha, 0x8033,
4129 "Unable to reinitialize FCE "
4131 ha->flags.fce_enabled = 0;
4136 memset(ha->eft, 0, EFT_SIZE);
4137 rval = qla2x00_enable_eft_trace(vha,
4138 ha->eft_dma, EFT_NUM_BUFFERS);
4140 ql_log(ql_log_warn, vha, 0x8034,
4141 "Unable to reinitialize EFT "
4145 } else { /* failed the ISP abort */
4146 vha->flags.online = 1;
4147 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
4148 if (ha->isp_abort_cnt == 0) {
4149 ql_log(ql_log_fatal, vha, 0x8035,
4150 "ISP error recover failed - "
4151 "board disabled.\n");
4153 * The next call disables the board
4156 ha->isp_ops->reset_adapter(vha);
4157 vha->flags.online = 0;
4158 clear_bit(ISP_ABORT_RETRY,
4161 } else { /* schedule another ISP abort */
4162 ha->isp_abort_cnt--;
4163 ql_dbg(ql_dbg_taskm, vha, 0x8020,
4164 "ISP abort - retry remaining %d.\n",
4169 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
4170 ql_dbg(ql_dbg_taskm, vha, 0x8021,
4171 "ISP error recovery - retrying (%d) "
4172 "more times.\n", ha->isp_abort_cnt);
4173 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4181 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
4183 spin_lock_irqsave(&ha->vport_slock, flags);
4184 list_for_each_entry(vp, &ha->vp_list, list) {
4186 atomic_inc(&vp->vref_count);
4187 spin_unlock_irqrestore(&ha->vport_slock, flags);
4189 qla2x00_vp_abort_isp(vp);
4191 spin_lock_irqsave(&ha->vport_slock, flags);
4192 atomic_dec(&vp->vref_count);
4195 spin_unlock_irqrestore(&ha->vport_slock, flags);
4198 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
4206 * qla2x00_restart_isp
4207 * restarts the ISP after a reset
4210 * ha = adapter block pointer.
4216 qla2x00_restart_isp(scsi_qla_host_t *vha)
4220 struct qla_hw_data *ha = vha->hw;
4221 struct req_que *req = ha->req_q_map[0];
4222 struct rsp_que *rsp = ha->rsp_q_map[0];
4224 /* If firmware needs to be loaded */
4225 if (qla2x00_isp_firmware(vha)) {
4226 vha->flags.online = 0;
4227 status = ha->isp_ops->chip_diag(vha);
4229 status = qla2x00_setup_chip(vha);
4232 if (!status && !(status = qla2x00_init_rings(vha))) {
4233 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
4234 ha->flags.chip_reset_done = 1;
4235 /* Initialize the queues in use */
4236 qla25xx_init_queues(ha);
4238 status = qla2x00_fw_ready(vha);
4240 ql_dbg(ql_dbg_taskm, vha, 0x8031,
4241 "Start configure loop status = %d.\n", status);
4243 /* Issue a marker after FW becomes ready. */
4244 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
4246 vha->flags.online = 1;
4247 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4250 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4251 qla2x00_configure_loop(vha);
4253 } while (!atomic_read(&vha->loop_down_timer) &&
4254 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4255 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4259 /* if no cable then assume it's good */
4260 if ((vha->device_flags & DFLG_NO_CABLE))
4263 ql_dbg(ql_dbg_taskm, vha, 0x8032,
4264 "Configure loop done, status = 0x%x.\n", status);
4270 qla25xx_init_queues(struct qla_hw_data *ha)
4272 struct rsp_que *rsp = NULL;
4273 struct req_que *req = NULL;
4274 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4278 for (i = 1; i < ha->max_rsp_queues; i++) {
4279 rsp = ha->rsp_q_map[i];
4281 rsp->options &= ~BIT_0;
4282 ret = qla25xx_init_rsp_que(base_vha, rsp);
4283 if (ret != QLA_SUCCESS)
4284 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
4285 "%s Rsp que: %d init failed.\n",
4288 ql_dbg(ql_dbg_init, base_vha, 0x0100,
4289 "%s Rsp que: %d inited.\n",
4293 for (i = 1; i < ha->max_req_queues; i++) {
4294 req = ha->req_q_map[i];
4296 /* Clear outstanding commands array. */
4297 req->options &= ~BIT_0;
4298 ret = qla25xx_init_req_que(base_vha, req);
4299 if (ret != QLA_SUCCESS)
4300 ql_dbg(ql_dbg_init, base_vha, 0x0101,
4301 "%s Req que: %d init failed.\n",
4304 ql_dbg(ql_dbg_init, base_vha, 0x0102,
4305 "%s Req que: %d inited.\n",
4313 * qla2x00_reset_adapter
4317 * ha = adapter block pointer.
4320 qla2x00_reset_adapter(scsi_qla_host_t *vha)
4322 unsigned long flags = 0;
4323 struct qla_hw_data *ha = vha->hw;
4324 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4326 vha->flags.online = 0;
4327 ha->isp_ops->disable_intrs(ha);
4329 spin_lock_irqsave(&ha->hardware_lock, flags);
4330 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
4331 RD_REG_WORD(®->hccr); /* PCI Posting. */
4332 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
4333 RD_REG_WORD(®->hccr); /* PCI Posting. */
4334 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4338 qla24xx_reset_adapter(scsi_qla_host_t *vha)
4340 unsigned long flags = 0;
4341 struct qla_hw_data *ha = vha->hw;
4342 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4347 vha->flags.online = 0;
4348 ha->isp_ops->disable_intrs(ha);
4350 spin_lock_irqsave(&ha->hardware_lock, flags);
4351 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
4352 RD_REG_DWORD(®->hccr);
4353 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
4354 RD_REG_DWORD(®->hccr);
4355 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4357 if (IS_NOPOLLING_TYPE(ha))
4358 ha->isp_ops->enable_intrs(ha);
4361 /* On sparc systems, obtain port and node WWN from firmware
4364 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4365 struct nvram_24xx *nv)
4368 struct qla_hw_data *ha = vha->hw;
4369 struct pci_dev *pdev = ha->pdev;
4370 struct device_node *dp = pci_device_to_OF_node(pdev);
4374 val = of_get_property(dp, "port-wwn", &len);
4375 if (val && len >= WWN_SIZE)
4376 memcpy(nv->port_name, val, WWN_SIZE);
4378 val = of_get_property(dp, "node-wwn", &len);
4379 if (val && len >= WWN_SIZE)
4380 memcpy(nv->node_name, val, WWN_SIZE);
4385 qla24xx_nvram_config(scsi_qla_host_t *vha)
4388 struct init_cb_24xx *icb;
4389 struct nvram_24xx *nv;
4391 uint8_t *dptr1, *dptr2;
4394 struct qla_hw_data *ha = vha->hw;
4397 icb = (struct init_cb_24xx *)ha->init_cb;
4400 /* Determine NVRAM starting address. */
4401 if (ha->flags.port0) {
4402 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4403 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4405 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
4406 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4408 ha->nvram_size = sizeof(struct nvram_24xx);
4409 ha->vpd_size = FA_NVRAM_VPD_SIZE;
4411 ha->vpd_size = FA_VPD_SIZE_82XX;
4413 /* Get VPD data into cache */
4414 ha->vpd = ha->nvram + VPD_OFFSET;
4415 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
4416 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4418 /* Get NVRAM data into cache and calculate checksum. */
4419 dptr = (uint32_t *)nv;
4420 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
4422 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4423 chksum += le32_to_cpu(*dptr++);
4425 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
4426 "Contents of NVRAM\n");
4427 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
4428 (uint8_t *)nv, ha->nvram_size);
4430 /* Bad NVRAM data, set defaults parameters. */
4431 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4432 || nv->id[3] != ' ' ||
4433 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4434 /* Reset NVRAM data. */
4435 ql_log(ql_log_warn, vha, 0x006b,
4436 "Inconisistent NVRAM detected: checksum=0x%x id=%c "
4437 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
4438 ql_log(ql_log_warn, vha, 0x006c,
4439 "Falling back to functioning (yet invalid -- WWPN) "
4443 * Set default initialization control block.
4445 memset(nv, 0, ha->nvram_size);
4446 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4447 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4448 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4449 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4450 nv->exchange_count = __constant_cpu_to_le16(0);
4451 nv->hard_address = __constant_cpu_to_le16(124);
4452 nv->port_name[0] = 0x21;
4453 nv->port_name[1] = 0x00 + ha->port_no;
4454 nv->port_name[2] = 0x00;
4455 nv->port_name[3] = 0xe0;
4456 nv->port_name[4] = 0x8b;
4457 nv->port_name[5] = 0x1c;
4458 nv->port_name[6] = 0x55;
4459 nv->port_name[7] = 0x86;
4460 nv->node_name[0] = 0x20;
4461 nv->node_name[1] = 0x00;
4462 nv->node_name[2] = 0x00;
4463 nv->node_name[3] = 0xe0;
4464 nv->node_name[4] = 0x8b;
4465 nv->node_name[5] = 0x1c;
4466 nv->node_name[6] = 0x55;
4467 nv->node_name[7] = 0x86;
4468 qla24xx_nvram_wwn_from_ofw(vha, nv);
4469 nv->login_retry_count = __constant_cpu_to_le16(8);
4470 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4471 nv->login_timeout = __constant_cpu_to_le16(0);
4472 nv->firmware_options_1 =
4473 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4474 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4475 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4476 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4477 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4478 nv->efi_parameters = __constant_cpu_to_le32(0);
4479 nv->reset_delay = 5;
4480 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4481 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4482 nv->link_down_timeout = __constant_cpu_to_le16(30);
4487 /* Reset Initialization control block */
4488 memset(icb, 0, ha->init_cb_size);
4490 /* Copy 1st segment. */
4491 dptr1 = (uint8_t *)icb;
4492 dptr2 = (uint8_t *)&nv->version;
4493 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4495 *dptr1++ = *dptr2++;
4497 icb->login_retry_count = nv->login_retry_count;
4498 icb->link_down_on_nos = nv->link_down_on_nos;
4500 /* Copy 2nd segment. */
4501 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4502 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4503 cnt = (uint8_t *)&icb->reserved_3 -
4504 (uint8_t *)&icb->interrupt_delay_timer;
4506 *dptr1++ = *dptr2++;
4509 * Setup driver NVRAM options.
4511 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4514 /* Use alternate WWN? */
4515 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4516 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4517 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4520 /* Prepare nodename */
4521 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4523 * Firmware will apply the following mask if the nodename was
4526 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4527 icb->node_name[0] &= 0xF0;
4530 /* Set host adapter parameters. */
4531 ha->flags.disable_risc_code_load = 0;
4532 ha->flags.enable_lip_reset = 0;
4533 ha->flags.enable_lip_full_login =
4534 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4535 ha->flags.enable_target_reset =
4536 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4537 ha->flags.enable_led_scheme = 0;
4538 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4540 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4541 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4543 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4544 sizeof(ha->fw_seriallink_options24));
4546 /* save HBA serial number */
4547 ha->serial0 = icb->port_name[5];
4548 ha->serial1 = icb->port_name[6];
4549 ha->serial2 = icb->port_name[7];
4550 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4551 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4553 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4555 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4557 /* Set minimum login_timeout to 4 seconds. */
4558 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4559 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4560 if (le16_to_cpu(nv->login_timeout) < 4)
4561 nv->login_timeout = __constant_cpu_to_le16(4);
4562 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4563 icb->login_timeout = nv->login_timeout;
4565 /* Set minimum RATOV to 100 tenths of a second. */
4568 ha->loop_reset_delay = nv->reset_delay;
4570 /* Link Down Timeout = 0:
4572 * When Port Down timer expires we will start returning
4573 * I/O's to OS with "DID_NO_CONNECT".
4575 * Link Down Timeout != 0:
4577 * The driver waits for the link to come up after link down
4578 * before returning I/Os to OS with "DID_NO_CONNECT".
4580 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4581 ha->loop_down_abort_time =
4582 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4584 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4585 ha->loop_down_abort_time =
4586 (LOOP_DOWN_TIME - ha->link_down_timeout);
4589 /* Need enough time to try and get the port back. */
4590 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4591 if (qlport_down_retry)
4592 ha->port_down_retry_count = qlport_down_retry;
4594 /* Set login_retry_count */
4595 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4596 if (ha->port_down_retry_count ==
4597 le16_to_cpu(nv->port_down_retry_count) &&
4598 ha->port_down_retry_count > 3)
4599 ha->login_retry_count = ha->port_down_retry_count;
4600 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4601 ha->login_retry_count = ha->port_down_retry_count;
4602 if (ql2xloginretrycount)
4603 ha->login_retry_count = ql2xloginretrycount;
4606 if (!vha->flags.init_done) {
4607 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4608 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4609 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4610 le16_to_cpu(icb->interrupt_delay_timer): 2;
4612 icb->firmware_options_2 &= __constant_cpu_to_le32(
4613 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4614 vha->flags.process_response_queue = 0;
4615 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4616 ha->zio_mode = QLA_ZIO_MODE_6;
4618 ql_log(ql_log_info, vha, 0x006f,
4619 "ZIO mode %d enabled; timer delay (%d us).\n",
4620 ha->zio_mode, ha->zio_timer * 100);
4622 icb->firmware_options_2 |= cpu_to_le32(
4623 (uint32_t)ha->zio_mode);
4624 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4625 vha->flags.process_response_queue = 1;
4629 ql_log(ql_log_warn, vha, 0x0070,
4630 "NVRAM configuration failed.\n");
4636 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4639 int rval = QLA_SUCCESS;
4640 int segments, fragment;
4641 uint32_t *dcode, dlen;
4645 struct qla_hw_data *ha = vha->hw;
4646 struct req_que *req = ha->req_q_map[0];
4648 ql_dbg(ql_dbg_init, vha, 0x008b,
4649 "FW: Loading firmware from flash (%x).\n", faddr);
4653 segments = FA_RISC_CODE_SEGMENTS;
4654 dcode = (uint32_t *)req->ring;
4657 /* Validate firmware image by checking version. */
4658 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
4659 for (i = 0; i < 4; i++)
4660 dcode[i] = be32_to_cpu(dcode[i]);
4661 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4662 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4663 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4665 ql_log(ql_log_fatal, vha, 0x008c,
4666 "Unable to verify the integrity of flash firmware "
4668 ql_log(ql_log_fatal, vha, 0x008d,
4669 "Firmware data: %08x %08x %08x %08x.\n",
4670 dcode[0], dcode[1], dcode[2], dcode[3]);
4672 return QLA_FUNCTION_FAILED;
4675 while (segments && rval == QLA_SUCCESS) {
4676 /* Read segment's load information. */
4677 qla24xx_read_flash_data(vha, dcode, faddr, 4);
4679 risc_addr = be32_to_cpu(dcode[2]);
4680 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4681 risc_size = be32_to_cpu(dcode[3]);
4684 while (risc_size > 0 && rval == QLA_SUCCESS) {
4685 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4686 if (dlen > risc_size)
4689 ql_dbg(ql_dbg_init, vha, 0x008e,
4690 "Loading risc segment@ risc addr %x "
4691 "number of dwords 0x%x offset 0x%x.\n",
4692 risc_addr, dlen, faddr);
4694 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
4695 for (i = 0; i < dlen; i++)
4696 dcode[i] = swab32(dcode[i]);
4698 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
4701 ql_log(ql_log_fatal, vha, 0x008f,
4702 "Failed to load segment %d of firmware.\n",
4720 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4723 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4727 uint16_t *wcode, *fwcode;
4728 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4729 struct fw_blob *blob;
4730 struct qla_hw_data *ha = vha->hw;
4731 struct req_que *req = ha->req_q_map[0];
4733 /* Load firmware blob. */
4734 blob = qla2x00_request_firmware(vha);
4736 ql_log(ql_log_info, vha, 0x0083,
4737 "Fimware image unavailable.\n");
4738 ql_log(ql_log_info, vha, 0x0084,
4739 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
4740 return QLA_FUNCTION_FAILED;
4745 wcode = (uint16_t *)req->ring;
4747 fwcode = (uint16_t *)blob->fw->data;
4750 /* Validate firmware image by checking version. */
4751 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4752 ql_log(ql_log_fatal, vha, 0x0085,
4753 "Unable to verify integrity of firmware image (%Zd).\n",
4755 goto fail_fw_integrity;
4757 for (i = 0; i < 4; i++)
4758 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4759 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4760 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4761 wcode[2] == 0 && wcode[3] == 0)) {
4762 ql_log(ql_log_fatal, vha, 0x0086,
4763 "Unable to verify integrity of firmware image.\n");
4764 ql_log(ql_log_fatal, vha, 0x0087,
4765 "Firmware data: %04x %04x %04x %04x.\n",
4766 wcode[0], wcode[1], wcode[2], wcode[3]);
4767 goto fail_fw_integrity;
4771 while (*seg && rval == QLA_SUCCESS) {
4773 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4774 risc_size = be16_to_cpu(fwcode[3]);
4776 /* Validate firmware image size. */
4777 fwclen += risc_size * sizeof(uint16_t);
4778 if (blob->fw->size < fwclen) {
4779 ql_log(ql_log_fatal, vha, 0x0088,
4780 "Unable to verify integrity of firmware image "
4781 "(%Zd).\n", blob->fw->size);
4782 goto fail_fw_integrity;
4786 while (risc_size > 0 && rval == QLA_SUCCESS) {
4787 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4788 if (wlen > risc_size)
4790 ql_dbg(ql_dbg_init, vha, 0x0089,
4791 "Loading risc segment@ risc addr %x number of "
4792 "words 0x%x.\n", risc_addr, wlen);
4794 for (i = 0; i < wlen; i++)
4795 wcode[i] = swab16(fwcode[i]);
4797 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
4800 ql_log(ql_log_fatal, vha, 0x008a,
4801 "Failed to load segment %d of firmware.\n",
4818 return QLA_FUNCTION_FAILED;
4822 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4825 int segments, fragment;
4826 uint32_t *dcode, dlen;
4830 struct fw_blob *blob;
4831 uint32_t *fwcode, fwclen;
4832 struct qla_hw_data *ha = vha->hw;
4833 struct req_que *req = ha->req_q_map[0];
4835 /* Load firmware blob. */
4836 blob = qla2x00_request_firmware(vha);
4838 ql_log(ql_log_warn, vha, 0x0090,
4839 "Fimware image unavailable.\n");
4840 ql_log(ql_log_warn, vha, 0x0091,
4841 "Firmware images can be retrieved from: "
4844 return QLA_FUNCTION_FAILED;
4847 ql_dbg(ql_dbg_init, vha, 0x0092,
4848 "FW: Loading via request-firmware.\n");
4852 segments = FA_RISC_CODE_SEGMENTS;
4853 dcode = (uint32_t *)req->ring;
4855 fwcode = (uint32_t *)blob->fw->data;
4858 /* Validate firmware image by checking version. */
4859 if (blob->fw->size < 8 * sizeof(uint32_t)) {
4860 ql_log(ql_log_fatal, vha, 0x0093,
4861 "Unable to verify integrity of firmware image (%Zd).\n",
4863 goto fail_fw_integrity;
4865 for (i = 0; i < 4; i++)
4866 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4867 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4868 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4869 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4871 ql_log(ql_log_fatal, vha, 0x0094,
4872 "Unable to verify integrity of firmware image (%Zd).\n",
4874 ql_log(ql_log_fatal, vha, 0x0095,
4875 "Firmware data: %08x %08x %08x %08x.\n",
4876 dcode[0], dcode[1], dcode[2], dcode[3]);
4877 goto fail_fw_integrity;
4880 while (segments && rval == QLA_SUCCESS) {
4881 risc_addr = be32_to_cpu(fwcode[2]);
4882 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4883 risc_size = be32_to_cpu(fwcode[3]);
4885 /* Validate firmware image size. */
4886 fwclen += risc_size * sizeof(uint32_t);
4887 if (blob->fw->size < fwclen) {
4888 ql_log(ql_log_fatal, vha, 0x0096,
4889 "Unable to verify integrity of firmware image "
4890 "(%Zd).\n", blob->fw->size);
4892 goto fail_fw_integrity;
4896 while (risc_size > 0 && rval == QLA_SUCCESS) {
4897 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4898 if (dlen > risc_size)
4901 ql_dbg(ql_dbg_init, vha, 0x0097,
4902 "Loading risc segment@ risc addr %x "
4903 "number of dwords 0x%x.\n", risc_addr, dlen);
4905 for (i = 0; i < dlen; i++)
4906 dcode[i] = swab32(fwcode[i]);
4908 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
4911 ql_log(ql_log_fatal, vha, 0x0098,
4912 "Failed to load segment %d of firmware.\n",
4929 return QLA_FUNCTION_FAILED;
4933 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4937 if (ql2xfwloadbin == 1)
4938 return qla81xx_load_risc(vha, srisc_addr);
4942 * 1) Firmware via request-firmware interface (.bin file).
4943 * 2) Firmware residing in flash.
4945 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4946 if (rval == QLA_SUCCESS)
4949 return qla24xx_load_risc_flash(vha, srisc_addr,
4950 vha->hw->flt_region_fw);
4954 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4957 struct qla_hw_data *ha = vha->hw;
4959 if (ql2xfwloadbin == 2)
4964 * 1) Firmware residing in flash.
4965 * 2) Firmware via request-firmware interface (.bin file).
4966 * 3) Golden-Firmware residing in flash -- limited operation.
4968 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
4969 if (rval == QLA_SUCCESS)
4973 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4974 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4977 ql_log(ql_log_info, vha, 0x0099,
4978 "Attempting to fallback to golden firmware.\n");
4979 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4980 if (rval != QLA_SUCCESS)
4983 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
4984 ha->flags.running_gold_fw = 1;
4989 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
4992 struct qla_hw_data *ha = vha->hw;
4994 if (ha->flags.pci_channel_io_perm_failure)
4996 if (!IS_FWI2_CAPABLE(ha))
4998 if (!ha->fw_major_version)
5001 ret = qla2x00_stop_firmware(vha);
5002 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
5003 ret != QLA_INVALID_COMMAND && retries ; retries--) {
5004 ha->isp_ops->reset_chip(vha);
5005 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
5007 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
5009 ql_log(ql_log_info, vha, 0x8015,
5010 "Attempting retry of stop-firmware command.\n");
5011 ret = qla2x00_stop_firmware(vha);
5016 qla24xx_configure_vhba(scsi_qla_host_t *vha)
5018 int rval = QLA_SUCCESS;
5019 uint16_t mb[MAILBOX_REGISTER_COUNT];
5020 struct qla_hw_data *ha = vha->hw;
5021 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5022 struct req_que *req;
5023 struct rsp_que *rsp;
5028 rval = qla2x00_fw_ready(base_vha);
5029 if (ha->flags.cpu_affinity_enabled)
5030 req = ha->req_q_map[0];
5035 if (rval == QLA_SUCCESS) {
5036 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5037 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5040 vha->flags.management_server_logged_in = 0;
5042 /* Login to SNS first */
5043 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
5044 if (mb[0] != MBS_COMMAND_COMPLETE) {
5045 ql_dbg(ql_dbg_init, vha, 0x0103,
5046 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
5047 "mb[6]=%x mb[7]=%x.\n",
5048 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
5049 return (QLA_FUNCTION_FAILED);
5052 atomic_set(&vha->loop_down_timer, 0);
5053 atomic_set(&vha->loop_state, LOOP_UP);
5054 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5055 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5056 rval = qla2x00_loop_resync(base_vha);
5061 /* 84XX Support **************************************************************/
5063 static LIST_HEAD(qla_cs84xx_list);
5064 static DEFINE_MUTEX(qla_cs84xx_mutex);
5066 static struct qla_chip_state_84xx *
5067 qla84xx_get_chip(struct scsi_qla_host *vha)
5069 struct qla_chip_state_84xx *cs84xx;
5070 struct qla_hw_data *ha = vha->hw;
5072 mutex_lock(&qla_cs84xx_mutex);
5074 /* Find any shared 84xx chip. */
5075 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
5076 if (cs84xx->bus == ha->pdev->bus) {
5077 kref_get(&cs84xx->kref);
5082 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
5086 kref_init(&cs84xx->kref);
5087 spin_lock_init(&cs84xx->access_lock);
5088 mutex_init(&cs84xx->fw_update_mutex);
5089 cs84xx->bus = ha->pdev->bus;
5091 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
5093 mutex_unlock(&qla_cs84xx_mutex);
5098 __qla84xx_chip_release(struct kref *kref)
5100 struct qla_chip_state_84xx *cs84xx =
5101 container_of(kref, struct qla_chip_state_84xx, kref);
5103 mutex_lock(&qla_cs84xx_mutex);
5104 list_del(&cs84xx->list);
5105 mutex_unlock(&qla_cs84xx_mutex);
5110 qla84xx_put_chip(struct scsi_qla_host *vha)
5112 struct qla_hw_data *ha = vha->hw;
5114 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
5118 qla84xx_init_chip(scsi_qla_host_t *vha)
5122 struct qla_hw_data *ha = vha->hw;
5124 mutex_lock(&ha->cs84xx->fw_update_mutex);
5126 rval = qla84xx_verify_chip(vha, status);
5128 mutex_unlock(&ha->cs84xx->fw_update_mutex);
5130 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
5134 /* 81XX Support **************************************************************/
5137 qla81xx_nvram_config(scsi_qla_host_t *vha)
5140 struct init_cb_81xx *icb;
5141 struct nvram_81xx *nv;
5143 uint8_t *dptr1, *dptr2;
5146 struct qla_hw_data *ha = vha->hw;
5149 icb = (struct init_cb_81xx *)ha->init_cb;
5152 /* Determine NVRAM starting address. */
5153 ha->nvram_size = sizeof(struct nvram_81xx);
5154 ha->vpd_size = FA_NVRAM_VPD_SIZE;
5156 /* Get VPD data into cache */
5157 ha->vpd = ha->nvram + VPD_OFFSET;
5158 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
5161 /* Get NVRAM data into cache and calculate checksum. */
5162 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
5164 dptr = (uint32_t *)nv;
5165 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5166 chksum += le32_to_cpu(*dptr++);
5168 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
5169 "Contents of NVRAM:\n");
5170 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
5171 (uint8_t *)nv, ha->nvram_size);
5173 /* Bad NVRAM data, set defaults parameters. */
5174 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5175 || nv->id[3] != ' ' ||
5176 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
5177 /* Reset NVRAM data. */
5178 ql_log(ql_log_info, vha, 0x0073,
5179 "Inconisistent NVRAM detected: checksum=0x%x id=%c "
5180 "version=0x%x.\n", chksum, nv->id[0],
5181 le16_to_cpu(nv->nvram_version));
5182 ql_log(ql_log_info, vha, 0x0074,
5183 "Falling back to functioning (yet invalid -- WWPN) "
5187 * Set default initialization control block.
5189 memset(nv, 0, ha->nvram_size);
5190 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5191 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5192 nv->frame_payload_size = __constant_cpu_to_le16(2048);
5193 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5194 nv->exchange_count = __constant_cpu_to_le16(0);
5195 nv->port_name[0] = 0x21;
5196 nv->port_name[1] = 0x00 + ha->port_no;
5197 nv->port_name[2] = 0x00;
5198 nv->port_name[3] = 0xe0;
5199 nv->port_name[4] = 0x8b;
5200 nv->port_name[5] = 0x1c;
5201 nv->port_name[6] = 0x55;
5202 nv->port_name[7] = 0x86;
5203 nv->node_name[0] = 0x20;
5204 nv->node_name[1] = 0x00;
5205 nv->node_name[2] = 0x00;
5206 nv->node_name[3] = 0xe0;
5207 nv->node_name[4] = 0x8b;
5208 nv->node_name[5] = 0x1c;
5209 nv->node_name[6] = 0x55;
5210 nv->node_name[7] = 0x86;
5211 nv->login_retry_count = __constant_cpu_to_le16(8);
5212 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5213 nv->login_timeout = __constant_cpu_to_le16(0);
5214 nv->firmware_options_1 =
5215 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5216 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5217 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5218 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5219 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5220 nv->efi_parameters = __constant_cpu_to_le32(0);
5221 nv->reset_delay = 5;
5222 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5223 nv->port_down_retry_count = __constant_cpu_to_le16(30);
5224 nv->link_down_timeout = __constant_cpu_to_le16(180);
5225 nv->enode_mac[0] = 0x00;
5226 nv->enode_mac[1] = 0xC0;
5227 nv->enode_mac[2] = 0xDD;
5228 nv->enode_mac[3] = 0x04;
5229 nv->enode_mac[4] = 0x05;
5230 nv->enode_mac[5] = 0x06 + ha->port_no;
5235 /* Reset Initialization control block */
5236 memset(icb, 0, ha->init_cb_size);
5238 /* Copy 1st segment. */
5239 dptr1 = (uint8_t *)icb;
5240 dptr2 = (uint8_t *)&nv->version;
5241 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5243 *dptr1++ = *dptr2++;
5245 icb->login_retry_count = nv->login_retry_count;
5247 /* Copy 2nd segment. */
5248 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5249 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5250 cnt = (uint8_t *)&icb->reserved_5 -
5251 (uint8_t *)&icb->interrupt_delay_timer;
5253 *dptr1++ = *dptr2++;
5255 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5256 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5257 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
5258 icb->enode_mac[0] = 0x01;
5259 icb->enode_mac[1] = 0x02;
5260 icb->enode_mac[2] = 0x03;
5261 icb->enode_mac[3] = 0x04;
5262 icb->enode_mac[4] = 0x05;
5263 icb->enode_mac[5] = 0x06 + ha->port_no;
5266 /* Use extended-initialization control block. */
5267 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5270 * Setup driver NVRAM options.
5272 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
5275 /* Use alternate WWN? */
5276 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5277 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5278 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5281 /* Prepare nodename */
5282 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5284 * Firmware will apply the following mask if the nodename was
5287 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5288 icb->node_name[0] &= 0xF0;
5291 /* Set host adapter parameters. */
5292 ha->flags.disable_risc_code_load = 0;
5293 ha->flags.enable_lip_reset = 0;
5294 ha->flags.enable_lip_full_login =
5295 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5296 ha->flags.enable_target_reset =
5297 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5298 ha->flags.enable_led_scheme = 0;
5299 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5301 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5302 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5304 /* save HBA serial number */
5305 ha->serial0 = icb->port_name[5];
5306 ha->serial1 = icb->port_name[6];
5307 ha->serial2 = icb->port_name[7];
5308 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5309 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5311 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5313 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5315 /* Set minimum login_timeout to 4 seconds. */
5316 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5317 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5318 if (le16_to_cpu(nv->login_timeout) < 4)
5319 nv->login_timeout = __constant_cpu_to_le16(4);
5320 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5321 icb->login_timeout = nv->login_timeout;
5323 /* Set minimum RATOV to 100 tenths of a second. */
5326 ha->loop_reset_delay = nv->reset_delay;
5328 /* Link Down Timeout = 0:
5330 * When Port Down timer expires we will start returning
5331 * I/O's to OS with "DID_NO_CONNECT".
5333 * Link Down Timeout != 0:
5335 * The driver waits for the link to come up after link down
5336 * before returning I/Os to OS with "DID_NO_CONNECT".
5338 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5339 ha->loop_down_abort_time =
5340 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5342 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5343 ha->loop_down_abort_time =
5344 (LOOP_DOWN_TIME - ha->link_down_timeout);
5347 /* Need enough time to try and get the port back. */
5348 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5349 if (qlport_down_retry)
5350 ha->port_down_retry_count = qlport_down_retry;
5352 /* Set login_retry_count */
5353 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5354 if (ha->port_down_retry_count ==
5355 le16_to_cpu(nv->port_down_retry_count) &&
5356 ha->port_down_retry_count > 3)
5357 ha->login_retry_count = ha->port_down_retry_count;
5358 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5359 ha->login_retry_count = ha->port_down_retry_count;
5360 if (ql2xloginretrycount)
5361 ha->login_retry_count = ql2xloginretrycount;
5363 /* if not running MSI-X we need handshaking on interrupts */
5364 if (!vha->hw->flags.msix_enabled && IS_QLA83XX(ha))
5365 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
5368 if (!vha->flags.init_done) {
5369 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5370 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5371 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5372 le16_to_cpu(icb->interrupt_delay_timer): 2;
5374 icb->firmware_options_2 &= __constant_cpu_to_le32(
5375 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5376 vha->flags.process_response_queue = 0;
5377 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5378 ha->zio_mode = QLA_ZIO_MODE_6;
5380 ql_log(ql_log_info, vha, 0x0075,
5381 "ZIO mode %d enabled; timer delay (%d us).\n",
5383 ha->zio_timer * 100);
5385 icb->firmware_options_2 |= cpu_to_le32(
5386 (uint32_t)ha->zio_mode);
5387 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5388 vha->flags.process_response_queue = 1;
5392 ql_log(ql_log_warn, vha, 0x0076,
5393 "NVRAM configuration failed.\n");
5399 qla82xx_restart_isp(scsi_qla_host_t *vha)
5403 struct qla_hw_data *ha = vha->hw;
5404 struct req_que *req = ha->req_q_map[0];
5405 struct rsp_que *rsp = ha->rsp_q_map[0];
5406 struct scsi_qla_host *vp;
5407 unsigned long flags;
5409 status = qla2x00_init_rings(vha);
5411 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5412 ha->flags.chip_reset_done = 1;
5414 status = qla2x00_fw_ready(vha);
5416 ql_log(ql_log_info, vha, 0x803c,
5417 "Start configure loop, status =%d.\n", status);
5419 /* Issue a marker after FW becomes ready. */
5420 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5422 vha->flags.online = 1;
5423 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5426 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5427 qla2x00_configure_loop(vha);
5429 } while (!atomic_read(&vha->loop_down_timer) &&
5430 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5432 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5435 /* if no cable then assume it's good */
5436 if ((vha->device_flags & DFLG_NO_CABLE))
5439 ql_log(ql_log_info, vha, 0x8000,
5440 "Configure loop done, status = 0x%x.\n", status);
5444 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5446 if (!atomic_read(&vha->loop_down_timer)) {
5448 * Issue marker command only when we are going
5449 * to start the I/O .
5451 vha->marker_needed = 1;
5454 vha->flags.online = 1;
5456 ha->isp_ops->enable_intrs(ha);
5458 ha->isp_abort_cnt = 0;
5459 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5461 /* Update the firmware version */
5462 status = qla82xx_check_md_needed(vha);
5465 ha->flags.fce_enabled = 1;
5467 fce_calc_size(ha->fce_bufs));
5468 rval = qla2x00_enable_fce_trace(vha,
5469 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5472 ql_log(ql_log_warn, vha, 0x8001,
5473 "Unable to reinitialize FCE (%d).\n",
5475 ha->flags.fce_enabled = 0;
5480 memset(ha->eft, 0, EFT_SIZE);
5481 rval = qla2x00_enable_eft_trace(vha,
5482 ha->eft_dma, EFT_NUM_BUFFERS);
5484 ql_log(ql_log_warn, vha, 0x8010,
5485 "Unable to reinitialize EFT (%d).\n",
5492 ql_dbg(ql_dbg_taskm, vha, 0x8011,
5493 "qla82xx_restart_isp succeeded.\n");
5495 spin_lock_irqsave(&ha->vport_slock, flags);
5496 list_for_each_entry(vp, &ha->vp_list, list) {
5498 atomic_inc(&vp->vref_count);
5499 spin_unlock_irqrestore(&ha->vport_slock, flags);
5501 qla2x00_vp_abort_isp(vp);
5503 spin_lock_irqsave(&ha->vport_slock, flags);
5504 atomic_dec(&vp->vref_count);
5507 spin_unlock_irqrestore(&ha->vport_slock, flags);
5510 ql_log(ql_log_warn, vha, 0x8016,
5511 "qla82xx_restart_isp **** FAILED ****.\n");
5518 qla81xx_update_fw_options(scsi_qla_host_t *vha)
5520 struct qla_hw_data *ha = vha->hw;
5525 /* Enable ETS Burst. */
5526 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5527 ha->fw_options[2] |= BIT_9;
5528 qla2x00_set_fw_options(vha, ha->fw_options);
5532 * qla24xx_get_fcp_prio
5533 * Gets the fcp cmd priority value for the logged in port.
5534 * Looks for a match of the port descriptors within
5535 * each of the fcp prio config entries. If a match is found,
5536 * the tag (priority) value is returned.
5539 * vha = scsi host structure pointer.
5540 * fcport = port structure pointer.
5543 * non-zero (if found)
5550 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5553 uint8_t pid_match, wwn_match;
5555 uint32_t pid1, pid2;
5556 uint64_t wwn1, wwn2;
5557 struct qla_fcp_prio_entry *pri_entry;
5558 struct qla_hw_data *ha = vha->hw;
5560 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
5564 entries = ha->fcp_prio_cfg->num_entries;
5565 pri_entry = &ha->fcp_prio_cfg->entry[0];
5567 for (i = 0; i < entries; i++) {
5568 pid_match = wwn_match = 0;
5570 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5575 /* check source pid for a match */
5576 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5577 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5578 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5579 if (pid1 == INVALID_PORT_ID)
5581 else if (pid1 == pid2)
5585 /* check destination pid for a match */
5586 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5587 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5588 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5589 if (pid1 == INVALID_PORT_ID)
5591 else if (pid1 == pid2)
5595 /* check source WWN for a match */
5596 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5597 wwn1 = wwn_to_u64(vha->port_name);
5598 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5599 if (wwn2 == (uint64_t)-1)
5601 else if (wwn1 == wwn2)
5605 /* check destination WWN for a match */
5606 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5607 wwn1 = wwn_to_u64(fcport->port_name);
5608 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5609 if (wwn2 == (uint64_t)-1)
5611 else if (wwn1 == wwn2)
5615 if (pid_match == 2 || wwn_match == 2) {
5616 /* Found a matching entry */
5617 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5618 priority = pri_entry->tag;
5629 * qla24xx_update_fcport_fcp_prio
5630 * Activates fcp priority for the logged in fc port
5633 * vha = scsi host structure pointer.
5634 * fcp = port structure pointer.
5637 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5643 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5649 if (fcport->port_type != FCT_TARGET ||
5650 fcport->loop_id == FC_NO_LOOP_ID)
5651 return QLA_FUNCTION_FAILED;
5653 priority = qla24xx_get_fcp_prio(vha, fcport);
5655 return QLA_FUNCTION_FAILED;
5657 if (IS_QLA82XX(vha->hw)) {
5658 fcport->fcp_prio = priority & 0xf;
5662 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
5663 if (ret == QLA_SUCCESS) {
5664 if (fcport->fcp_prio != priority)
5665 ql_dbg(ql_dbg_user, vha, 0x709e,
5666 "Updated FCP_CMND priority - value=%d loop_id=%d "
5667 "port_id=%02x%02x%02x.\n", priority,
5668 fcport->loop_id, fcport->d_id.b.domain,
5669 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5670 fcport->fcp_prio = priority & 0xf;
5672 ql_dbg(ql_dbg_user, vha, 0x704f,
5673 "Unable to update FCP_CMND priority - ret=0x%x for "
5674 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
5675 fcport->d_id.b.domain, fcport->d_id.b.area,
5676 fcport->d_id.b.al_pa);
5681 * qla24xx_update_all_fcp_prio
5682 * Activates fcp priority for all the logged in ports
5685 * ha = adapter block pointer.
5688 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5694 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5699 ret = QLA_FUNCTION_FAILED;
5700 /* We need to set priority for all logged in ports */
5701 list_for_each_entry(fcport, &vha->vp_fcports, list)
5702 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);