2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2008 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
10 #include <linux/delay.h>
11 #include <linux/vmalloc.h>
13 #include "qla_devtbl.h"
20 * QLogic ISP2x00 Hardware Support Function Prototypes.
22 static int qla2x00_isp_firmware(scsi_qla_host_t *);
23 static int qla2x00_setup_chip(scsi_qla_host_t *);
24 static int qla2x00_init_rings(scsi_qla_host_t *);
25 static int qla2x00_fw_ready(scsi_qla_host_t *);
26 static int qla2x00_configure_hba(scsi_qla_host_t *);
27 static int qla2x00_configure_loop(scsi_qla_host_t *);
28 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
29 static int qla2x00_configure_fabric(scsi_qla_host_t *);
30 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
31 static int qla2x00_device_resync(scsi_qla_host_t *);
32 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
35 static int qla2x00_restart_isp(scsi_qla_host_t *);
37 static int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *);
39 static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
40 static int qla84xx_init_chip(scsi_qla_host_t *);
41 static int qla25xx_init_queues(struct qla_hw_data *);
43 /* SRB Extensions ---------------------------------------------------------- */
46 qla2x00_ctx_sp_timeout(unsigned long __data)
48 srb_t *sp = (srb_t *)__data;
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;
60 spin_unlock_irqrestore(&ha->hardware_lock, flags);
66 qla2x00_ctx_sp_free(srb_t *sp)
68 struct srb_ctx *ctx = sp->ctx;
71 mempool_free(sp, sp->fcport->vha->hw->srb_mempool);
75 qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size,
79 struct qla_hw_data *ha = vha->hw;
82 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
85 ctx = kzalloc(size, GFP_KERNEL);
87 mempool_free(sp, ha->srb_mempool);
91 memset(sp, 0, sizeof(*sp));
94 ctx->free = qla2x00_ctx_sp_free;
96 init_timer(&ctx->timer);
99 ctx->timer.expires = jiffies + tmo * HZ;
100 ctx->timer.data = (unsigned long)sp;
101 ctx->timer.function = qla2x00_ctx_sp_timeout;
102 add_timer(&ctx->timer);
107 /* Asynchronous Login/Logout Routines -------------------------------------- */
109 #define ELS_TMO_2_RATOV(ha) ((ha)->r_a_tov / 10 * 2)
112 qla2x00_async_logio_timeout(srb_t *sp)
114 fc_port_t *fcport = sp->fcport;
115 struct srb_logio *lio = sp->ctx;
117 DEBUG2(printk(KERN_WARNING
118 "scsi(%ld:%x): Async-%s timeout.\n",
119 fcport->vha->host_no, sp->handle,
120 lio->ctx.type == SRB_LOGIN_CMD ? "login": "logout"));
122 if (lio->ctx.type == SRB_LOGIN_CMD)
123 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
127 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
130 struct qla_hw_data *ha = vha->hw;
132 struct srb_logio *lio;
135 rval = QLA_FUNCTION_FAILED;
136 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_logio),
137 ELS_TMO_2_RATOV(ha) + 2);
142 lio->ctx.type = SRB_LOGIN_CMD;
143 lio->ctx.timeout = qla2x00_async_logio_timeout;
144 lio->flags |= SRB_LOGIN_COND_PLOGI;
145 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
146 lio->flags |= SRB_LOGIN_RETRIED;
147 rval = qla2x00_start_sp(sp);
148 if (rval != QLA_SUCCESS)
151 DEBUG2(printk(KERN_DEBUG
152 "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
153 "retries=%d.\n", fcport->vha->host_no, sp->handle, fcport->loop_id,
154 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
155 fcport->login_retry));
159 del_timer_sync(&lio->ctx.timer);
166 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
168 struct qla_hw_data *ha = vha->hw;
170 struct srb_logio *lio;
173 rval = QLA_FUNCTION_FAILED;
174 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_logio),
175 ELS_TMO_2_RATOV(ha) + 2);
180 lio->ctx.type = SRB_LOGOUT_CMD;
181 lio->ctx.timeout = qla2x00_async_logio_timeout;
182 rval = qla2x00_start_sp(sp);
183 if (rval != QLA_SUCCESS)
186 DEBUG2(printk(KERN_DEBUG
187 "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
188 fcport->vha->host_no, sp->handle, fcport->loop_id,
189 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
193 del_timer_sync(&lio->ctx.timer);
200 qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
207 case MBS_COMMAND_COMPLETE:
208 if (fcport->flags & FCF_TAPE_PRESENT)
210 rval = qla2x00_get_port_database(vha, fcport, opts);
211 if (rval != QLA_SUCCESS)
212 qla2x00_mark_device_lost(vha, fcport, 1, 0);
214 qla2x00_update_fcport(vha, fcport);
216 case MBS_COMMAND_ERROR:
217 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
218 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
220 qla2x00_mark_device_lost(vha, fcport, 1, 0);
222 case MBS_PORT_ID_USED:
223 fcport->loop_id = data[1];
224 qla2x00_post_async_login_work(vha, fcport, NULL);
226 case MBS_LOOP_ID_USED:
228 rval = qla2x00_find_new_loop_id(vha, fcport);
229 if (rval != QLA_SUCCESS) {
230 qla2x00_mark_device_lost(vha, fcport, 1, 0);
233 qla2x00_post_async_login_work(vha, fcport, NULL);
240 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
243 qla2x00_mark_device_lost(vha, fcport, 1, 0);
247 /****************************************************************************/
248 /* QLogic ISP2x00 Hardware Support Functions. */
249 /****************************************************************************/
252 * qla2x00_initialize_adapter
256 * ha = adapter block pointer.
262 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
265 struct qla_hw_data *ha = vha->hw;
266 struct req_que *req = ha->req_q_map[0];
268 /* Clear adapter flags. */
269 vha->flags.online = 0;
270 ha->flags.chip_reset_done = 0;
271 vha->flags.reset_active = 0;
272 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
273 atomic_set(&vha->loop_state, LOOP_DOWN);
274 vha->device_flags = DFLG_NO_CABLE;
276 vha->flags.management_server_logged_in = 0;
277 vha->marker_needed = 0;
278 ha->isp_abort_cnt = 0;
279 ha->beacon_blink_led = 0;
280 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
282 set_bit(0, ha->req_qid_map);
283 set_bit(0, ha->rsp_qid_map);
285 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
286 rval = ha->isp_ops->pci_config(vha);
288 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
293 ha->isp_ops->reset_chip(vha);
295 rval = qla2xxx_get_flash_info(vha);
297 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
302 ha->isp_ops->get_flash_version(vha, req->ring);
304 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
306 ha->isp_ops->nvram_config(vha);
308 if (ha->flags.disable_serdes) {
309 /* Mask HBA via NVRAM settings? */
310 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
311 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
312 vha->port_name[0], vha->port_name[1],
313 vha->port_name[2], vha->port_name[3],
314 vha->port_name[4], vha->port_name[5],
315 vha->port_name[6], vha->port_name[7]);
316 return QLA_FUNCTION_FAILED;
319 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
321 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
322 rval = ha->isp_ops->chip_diag(vha);
325 rval = qla2x00_setup_chip(vha);
329 if (IS_QLA84XX(ha)) {
330 ha->cs84xx = qla84xx_get_chip(vha);
332 qla_printk(KERN_ERR, ha,
333 "Unable to configure ISP84XX.\n");
334 return QLA_FUNCTION_FAILED;
337 rval = qla2x00_init_rings(vha);
338 ha->flags.chip_reset_done = 1;
344 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
347 * Returns 0 on success.
350 qla2100_pci_config(scsi_qla_host_t *vha)
354 struct qla_hw_data *ha = vha->hw;
355 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
357 pci_set_master(ha->pdev);
358 pci_try_set_mwi(ha->pdev);
360 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
361 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
362 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
364 pci_disable_rom(ha->pdev);
366 /* Get PCI bus information. */
367 spin_lock_irqsave(&ha->hardware_lock, flags);
368 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
369 spin_unlock_irqrestore(&ha->hardware_lock, flags);
375 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
378 * Returns 0 on success.
381 qla2300_pci_config(scsi_qla_host_t *vha)
384 unsigned long flags = 0;
386 struct qla_hw_data *ha = vha->hw;
387 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
389 pci_set_master(ha->pdev);
390 pci_try_set_mwi(ha->pdev);
392 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
393 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
395 if (IS_QLA2322(ha) || IS_QLA6322(ha))
396 w &= ~PCI_COMMAND_INTX_DISABLE;
397 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
400 * If this is a 2300 card and not 2312, reset the
401 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
402 * the 2310 also reports itself as a 2300 so we need to get the
403 * fb revision level -- a 6 indicates it really is a 2300 and
406 if (IS_QLA2300(ha)) {
407 spin_lock_irqsave(&ha->hardware_lock, flags);
410 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
411 for (cnt = 0; cnt < 30000; cnt++) {
412 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
418 /* Select FPM registers. */
419 WRT_REG_WORD(®->ctrl_status, 0x20);
420 RD_REG_WORD(®->ctrl_status);
422 /* Get the fb rev level */
423 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
425 if (ha->fb_rev == FPM_2300)
426 pci_clear_mwi(ha->pdev);
428 /* Deselect FPM registers. */
429 WRT_REG_WORD(®->ctrl_status, 0x0);
430 RD_REG_WORD(®->ctrl_status);
432 /* Release RISC module. */
433 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
434 for (cnt = 0; cnt < 30000; cnt++) {
435 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
441 spin_unlock_irqrestore(&ha->hardware_lock, flags);
444 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
446 pci_disable_rom(ha->pdev);
448 /* Get PCI bus information. */
449 spin_lock_irqsave(&ha->hardware_lock, flags);
450 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
451 spin_unlock_irqrestore(&ha->hardware_lock, flags);
457 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
460 * Returns 0 on success.
463 qla24xx_pci_config(scsi_qla_host_t *vha)
466 unsigned long flags = 0;
467 struct qla_hw_data *ha = vha->hw;
468 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
470 pci_set_master(ha->pdev);
471 pci_try_set_mwi(ha->pdev);
473 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
474 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
475 w &= ~PCI_COMMAND_INTX_DISABLE;
476 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
478 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
480 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
481 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
482 pcix_set_mmrbc(ha->pdev, 2048);
484 /* PCIe -- adjust Maximum Read Request Size (2048). */
485 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
486 pcie_set_readrq(ha->pdev, 2048);
488 pci_disable_rom(ha->pdev);
490 ha->chip_revision = ha->pdev->revision;
492 /* Get PCI bus information. */
493 spin_lock_irqsave(&ha->hardware_lock, flags);
494 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
495 spin_unlock_irqrestore(&ha->hardware_lock, flags);
501 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
504 * Returns 0 on success.
507 qla25xx_pci_config(scsi_qla_host_t *vha)
510 struct qla_hw_data *ha = vha->hw;
512 pci_set_master(ha->pdev);
513 pci_try_set_mwi(ha->pdev);
515 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
516 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
517 w &= ~PCI_COMMAND_INTX_DISABLE;
518 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
520 /* PCIe -- adjust Maximum Read Request Size (2048). */
521 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
522 pcie_set_readrq(ha->pdev, 2048);
524 pci_disable_rom(ha->pdev);
526 ha->chip_revision = ha->pdev->revision;
532 * qla2x00_isp_firmware() - Choose firmware image.
535 * Returns 0 on success.
538 qla2x00_isp_firmware(scsi_qla_host_t *vha)
541 uint16_t loop_id, topo, sw_cap;
542 uint8_t domain, area, al_pa;
543 struct qla_hw_data *ha = vha->hw;
545 /* Assume loading risc code */
546 rval = QLA_FUNCTION_FAILED;
548 if (ha->flags.disable_risc_code_load) {
549 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
551 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
553 /* Verify checksum of loaded RISC code. */
554 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
555 if (rval == QLA_SUCCESS) {
556 /* And, verify we are not in ROM code. */
557 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
558 &area, &domain, &topo, &sw_cap);
563 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
571 * qla2x00_reset_chip() - Reset ISP chip.
574 * Returns 0 on success.
577 qla2x00_reset_chip(scsi_qla_host_t *vha)
579 unsigned long flags = 0;
580 struct qla_hw_data *ha = vha->hw;
581 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
585 ha->isp_ops->disable_intrs(ha);
587 spin_lock_irqsave(&ha->hardware_lock, flags);
589 /* Turn off master enable */
591 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
592 cmd &= ~PCI_COMMAND_MASTER;
593 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
595 if (!IS_QLA2100(ha)) {
597 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
598 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
599 for (cnt = 0; cnt < 30000; cnt++) {
600 if ((RD_REG_WORD(®->hccr) &
601 HCCR_RISC_PAUSE) != 0)
606 RD_REG_WORD(®->hccr); /* PCI Posting. */
610 /* Select FPM registers. */
611 WRT_REG_WORD(®->ctrl_status, 0x20);
612 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
614 /* FPM Soft Reset. */
615 WRT_REG_WORD(®->fpm_diag_config, 0x100);
616 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
618 /* Toggle Fpm Reset. */
619 if (!IS_QLA2200(ha)) {
620 WRT_REG_WORD(®->fpm_diag_config, 0x0);
621 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
624 /* Select frame buffer registers. */
625 WRT_REG_WORD(®->ctrl_status, 0x10);
626 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
628 /* Reset frame buffer FIFOs. */
629 if (IS_QLA2200(ha)) {
630 WRT_FB_CMD_REG(ha, reg, 0xa000);
631 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
633 WRT_FB_CMD_REG(ha, reg, 0x00fc);
635 /* Read back fb_cmd until zero or 3 seconds max */
636 for (cnt = 0; cnt < 3000; cnt++) {
637 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
643 /* Select RISC module registers. */
644 WRT_REG_WORD(®->ctrl_status, 0);
645 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
647 /* Reset RISC processor. */
648 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
649 RD_REG_WORD(®->hccr); /* PCI Posting. */
651 /* Release RISC processor. */
652 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
653 RD_REG_WORD(®->hccr); /* PCI Posting. */
656 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
657 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
659 /* Reset ISP chip. */
660 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
662 /* Wait for RISC to recover from reset. */
663 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
665 * It is necessary to for a delay here since the card doesn't
666 * respond to PCI reads during a reset. On some architectures
667 * this will result in an MCA.
670 for (cnt = 30000; cnt; cnt--) {
671 if ((RD_REG_WORD(®->ctrl_status) &
672 CSR_ISP_SOFT_RESET) == 0)
679 /* Reset RISC processor. */
680 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
682 WRT_REG_WORD(®->semaphore, 0);
684 /* Release RISC processor. */
685 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
686 RD_REG_WORD(®->hccr); /* PCI Posting. */
688 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
689 for (cnt = 0; cnt < 30000; cnt++) {
690 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
698 /* Turn on master enable */
699 cmd |= PCI_COMMAND_MASTER;
700 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
702 /* Disable RISC pause on FPM parity error. */
703 if (!IS_QLA2100(ha)) {
704 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
705 RD_REG_WORD(®->hccr); /* PCI Posting. */
708 spin_unlock_irqrestore(&ha->hardware_lock, flags);
712 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
715 * Returns 0 on success.
718 qla24xx_reset_risc(scsi_qla_host_t *vha)
720 unsigned long flags = 0;
721 struct qla_hw_data *ha = vha->hw;
722 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
726 spin_lock_irqsave(&ha->hardware_lock, flags);
729 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
730 for (cnt = 0; cnt < 30000; cnt++) {
731 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
737 WRT_REG_DWORD(®->ctrl_status,
738 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
739 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
742 /* Wait for firmware to complete NVRAM accesses. */
743 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
744 for (cnt = 10000 ; cnt && d2; cnt--) {
746 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
750 /* Wait for soft-reset to complete. */
751 d2 = RD_REG_DWORD(®->ctrl_status);
752 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
754 d2 = RD_REG_DWORD(®->ctrl_status);
758 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
759 RD_REG_DWORD(®->hccr);
761 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
762 RD_REG_DWORD(®->hccr);
764 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
765 RD_REG_DWORD(®->hccr);
767 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
768 for (cnt = 6000000 ; cnt && d2; cnt--) {
770 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
774 spin_unlock_irqrestore(&ha->hardware_lock, flags);
776 if (IS_NOPOLLING_TYPE(ha))
777 ha->isp_ops->enable_intrs(ha);
781 * qla24xx_reset_chip() - Reset ISP24xx chip.
784 * Returns 0 on success.
787 qla24xx_reset_chip(scsi_qla_host_t *vha)
789 struct qla_hw_data *ha = vha->hw;
790 ha->isp_ops->disable_intrs(ha);
792 /* Perform RISC reset. */
793 qla24xx_reset_risc(vha);
797 * qla2x00_chip_diag() - Test chip for proper operation.
800 * Returns 0 on success.
803 qla2x00_chip_diag(scsi_qla_host_t *vha)
806 struct qla_hw_data *ha = vha->hw;
807 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
808 unsigned long flags = 0;
812 struct req_que *req = ha->req_q_map[0];
814 /* Assume a failed state */
815 rval = QLA_FUNCTION_FAILED;
817 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
818 vha->host_no, (u_long)®->flash_address));
820 spin_lock_irqsave(&ha->hardware_lock, flags);
822 /* Reset ISP chip. */
823 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
826 * We need to have a delay here since the card will not respond while
827 * in reset causing an MCA on some architectures.
830 data = qla2x00_debounce_register(®->ctrl_status);
831 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
833 data = RD_REG_WORD(®->ctrl_status);
838 goto chip_diag_failed;
840 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
843 /* Reset RISC processor. */
844 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
845 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
847 /* Workaround for QLA2312 PCI parity error */
848 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
849 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
850 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
852 data = RD_MAILBOX_REG(ha, reg, 0);
859 goto chip_diag_failed;
861 /* Check product ID of chip */
862 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
864 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
865 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
866 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
867 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
868 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
869 mb[3] != PROD_ID_3) {
870 qla_printk(KERN_WARNING, ha,
871 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
873 goto chip_diag_failed;
875 ha->product_id[0] = mb[1];
876 ha->product_id[1] = mb[2];
877 ha->product_id[2] = mb[3];
878 ha->product_id[3] = mb[4];
880 /* Adjust fw RISC transfer size */
881 if (req->length > 1024)
882 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
884 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
887 if (IS_QLA2200(ha) &&
888 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
889 /* Limit firmware transfer size with a 2200A */
890 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
893 ha->device_type |= DT_ISP2200A;
894 ha->fw_transfer_size = 128;
897 /* Wrap Incoming Mailboxes Test. */
898 spin_unlock_irqrestore(&ha->hardware_lock, flags);
900 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
901 rval = qla2x00_mbx_reg_test(vha);
903 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
905 qla_printk(KERN_WARNING, ha,
906 "Failed mailbox send register test\n");
909 /* Flag a successful rval */
912 spin_lock_irqsave(&ha->hardware_lock, flags);
916 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
917 "****\n", vha->host_no));
919 spin_unlock_irqrestore(&ha->hardware_lock, flags);
925 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
928 * Returns 0 on success.
931 qla24xx_chip_diag(scsi_qla_host_t *vha)
934 struct qla_hw_data *ha = vha->hw;
935 struct req_que *req = ha->req_q_map[0];
937 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
939 rval = qla2x00_mbx_reg_test(vha);
941 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
943 qla_printk(KERN_WARNING, ha,
944 "Failed mailbox send register test\n");
946 /* Flag a successful rval */
954 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
957 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
958 eft_size, fce_size, mq_size;
961 struct qla_hw_data *ha = vha->hw;
962 struct req_que *req = ha->req_q_map[0];
963 struct rsp_que *rsp = ha->rsp_q_map[0];
966 qla_printk(KERN_WARNING, ha,
967 "Firmware dump previously allocated.\n");
972 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
973 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
974 fixed_size = sizeof(struct qla2100_fw_dump);
975 } else if (IS_QLA23XX(ha)) {
976 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
977 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
979 } else if (IS_FWI2_CAPABLE(ha)) {
981 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
982 else if (IS_QLA25XX(ha))
983 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
985 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
986 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
989 mq_size = sizeof(struct qla2xxx_mq_chain);
990 /* Allocate memory for Fibre Channel Event Buffer. */
991 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
994 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
997 qla_printk(KERN_WARNING, ha, "Unable to allocate "
998 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
1002 memset(tc, 0, FCE_SIZE);
1003 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
1004 ha->fce_mb, &ha->fce_bufs);
1006 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1007 "FCE (%d).\n", rval);
1008 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1010 ha->flags.fce_enabled = 0;
1014 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
1017 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
1018 ha->flags.fce_enabled = 1;
1019 ha->fce_dma = tc_dma;
1022 /* Allocate memory for Extended Trace Buffer. */
1023 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
1026 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1027 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
1031 memset(tc, 0, EFT_SIZE);
1032 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
1034 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1035 "EFT (%d).\n", rval);
1036 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1041 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
1044 eft_size = EFT_SIZE;
1045 ha->eft_dma = tc_dma;
1049 req_q_size = req->length * sizeof(request_t);
1050 rsp_q_size = rsp->length * sizeof(response_t);
1052 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
1053 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
1054 ha->chain_offset = dump_size;
1055 dump_size += mq_size + fce_size;
1057 ha->fw_dump = vmalloc(dump_size);
1059 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
1060 "firmware dump!!!\n", dump_size / 1024);
1063 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1070 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
1073 ha->fw_dump_len = dump_size;
1074 ha->fw_dump->signature[0] = 'Q';
1075 ha->fw_dump->signature[1] = 'L';
1076 ha->fw_dump->signature[2] = 'G';
1077 ha->fw_dump->signature[3] = 'C';
1078 ha->fw_dump->version = __constant_htonl(1);
1080 ha->fw_dump->fixed_size = htonl(fixed_size);
1081 ha->fw_dump->mem_size = htonl(mem_size);
1082 ha->fw_dump->req_q_size = htonl(req_q_size);
1083 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1085 ha->fw_dump->eft_size = htonl(eft_size);
1086 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1087 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1089 ha->fw_dump->header_size =
1090 htonl(offsetof(struct qla2xxx_fw_dump, isp));
1094 qla81xx_mpi_sync(scsi_qla_host_t *vha)
1096 #define MPS_MASK 0xe0
1100 struct qla_hw_data *ha = vha->hw;
1102 if (!IS_QLA81XX(vha->hw))
1105 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1106 if (rval != QLA_SUCCESS) {
1107 DEBUG2(qla_printk(KERN_WARNING, ha,
1108 "Sync-MPI: Unable to acquire semaphore.\n"));
1112 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1113 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1114 if (rval != QLA_SUCCESS) {
1115 DEBUG2(qla_printk(KERN_WARNING, ha,
1116 "Sync-MPI: Unable to read sync.\n"));
1121 if (dc == (dw & MPS_MASK))
1126 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1127 if (rval != QLA_SUCCESS) {
1128 DEBUG2(qla_printk(KERN_WARNING, ha,
1129 "Sync-MPI: Unable to gain sync.\n"));
1133 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1134 if (rval != QLA_SUCCESS) {
1135 DEBUG2(qla_printk(KERN_WARNING, ha,
1136 "Sync-MPI: Unable to release semaphore.\n"));
1144 * qla2x00_setup_chip() - Load and start RISC firmware.
1147 * Returns 0 on success.
1150 qla2x00_setup_chip(scsi_qla_host_t *vha)
1153 uint32_t srisc_address = 0;
1154 struct qla_hw_data *ha = vha->hw;
1155 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1156 unsigned long flags;
1157 uint16_t fw_major_version;
1159 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1160 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1161 spin_lock_irqsave(&ha->hardware_lock, flags);
1162 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
1163 RD_REG_WORD(®->hccr);
1164 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1167 qla81xx_mpi_sync(vha);
1169 /* Load firmware sequences */
1170 rval = ha->isp_ops->load_risc(vha, &srisc_address);
1171 if (rval == QLA_SUCCESS) {
1172 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
1173 "code.\n", vha->host_no));
1175 rval = qla2x00_verify_checksum(vha, srisc_address);
1176 if (rval == QLA_SUCCESS) {
1177 /* Start firmware execution. */
1178 DEBUG(printk("scsi(%ld): Checksum OK, start "
1179 "firmware.\n", vha->host_no));
1181 rval = qla2x00_execute_fw(vha, srisc_address);
1182 /* Retrieve firmware information. */
1183 if (rval == QLA_SUCCESS) {
1184 fw_major_version = ha->fw_major_version;
1185 rval = qla2x00_get_fw_version(vha,
1186 &ha->fw_major_version,
1187 &ha->fw_minor_version,
1188 &ha->fw_subminor_version,
1189 &ha->fw_attributes, &ha->fw_memory_size,
1190 ha->mpi_version, &ha->mpi_capabilities,
1192 if (rval != QLA_SUCCESS)
1194 ha->flags.npiv_supported = 0;
1195 if (IS_QLA2XXX_MIDTYPE(ha) &&
1196 (ha->fw_attributes & BIT_2)) {
1197 ha->flags.npiv_supported = 1;
1198 if ((!ha->max_npiv_vports) ||
1199 ((ha->max_npiv_vports + 1) %
1200 MIN_MULTI_ID_FABRIC))
1201 ha->max_npiv_vports =
1202 MIN_MULTI_ID_FABRIC - 1;
1204 qla2x00_get_resource_cnts(vha, NULL,
1205 &ha->fw_xcb_count, NULL, NULL,
1206 &ha->max_npiv_vports);
1208 if (!fw_major_version && ql2xallocfwdump)
1209 qla2x00_alloc_fw_dump(vha);
1212 DEBUG2(printk(KERN_INFO
1213 "scsi(%ld): ISP Firmware failed checksum.\n",
1218 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1219 /* Enable proper parity. */
1220 spin_lock_irqsave(&ha->hardware_lock, flags);
1223 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
1225 /* SRAM, Instruction RAM and GP RAM parity */
1226 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
1227 RD_REG_WORD(®->hccr);
1228 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1231 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1234 rval = qla81xx_fac_get_sector_size(vha, &size);
1235 if (rval == QLA_SUCCESS) {
1236 ha->flags.fac_supported = 1;
1237 ha->fdt_block_size = size << 2;
1239 qla_printk(KERN_ERR, ha,
1240 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1241 ha->fw_major_version, ha->fw_minor_version,
1242 ha->fw_subminor_version);
1247 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
1255 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1258 * Beginning of request ring has initialization control block already built
1259 * by nvram config routine.
1261 * Returns 0 on success.
1264 qla2x00_init_response_q_entries(struct rsp_que *rsp)
1269 rsp->ring_ptr = rsp->ring;
1270 rsp->ring_index = 0;
1271 rsp->status_srb = NULL;
1272 pkt = rsp->ring_ptr;
1273 for (cnt = 0; cnt < rsp->length; cnt++) {
1274 pkt->signature = RESPONSE_PROCESSED;
1280 * qla2x00_update_fw_options() - Read and process firmware options.
1283 * Returns 0 on success.
1286 qla2x00_update_fw_options(scsi_qla_host_t *vha)
1288 uint16_t swing, emphasis, tx_sens, rx_sens;
1289 struct qla_hw_data *ha = vha->hw;
1291 memset(ha->fw_options, 0, sizeof(ha->fw_options));
1292 qla2x00_get_fw_options(vha, ha->fw_options);
1294 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1297 /* Serial Link options. */
1298 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1300 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1301 sizeof(ha->fw_seriallink_options)));
1303 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1304 if (ha->fw_seriallink_options[3] & BIT_2) {
1305 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1308 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1309 emphasis = (ha->fw_seriallink_options[2] &
1310 (BIT_4 | BIT_3)) >> 3;
1311 tx_sens = ha->fw_seriallink_options[0] &
1312 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1313 rx_sens = (ha->fw_seriallink_options[0] &
1314 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1315 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1316 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1319 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1320 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1321 ha->fw_options[10] |= BIT_5 |
1322 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1323 (tx_sens & (BIT_1 | BIT_0));
1326 swing = (ha->fw_seriallink_options[2] &
1327 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1328 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1329 tx_sens = ha->fw_seriallink_options[1] &
1330 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1331 rx_sens = (ha->fw_seriallink_options[1] &
1332 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1333 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1334 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1337 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1338 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1339 ha->fw_options[11] |= BIT_5 |
1340 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1341 (tx_sens & (BIT_1 | BIT_0));
1345 /* Return command IOCBs without waiting for an ABTS to complete. */
1346 ha->fw_options[3] |= BIT_13;
1349 if (ha->flags.enable_led_scheme)
1350 ha->fw_options[2] |= BIT_12;
1352 /* Detect ISP6312. */
1354 ha->fw_options[2] |= BIT_13;
1356 /* Update firmware options. */
1357 qla2x00_set_fw_options(vha, ha->fw_options);
1361 qla24xx_update_fw_options(scsi_qla_host_t *vha)
1364 struct qla_hw_data *ha = vha->hw;
1366 /* Update Serial Link options. */
1367 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1370 rval = qla2x00_set_serdes_params(vha,
1371 le16_to_cpu(ha->fw_seriallink_options24[1]),
1372 le16_to_cpu(ha->fw_seriallink_options24[2]),
1373 le16_to_cpu(ha->fw_seriallink_options24[3]));
1374 if (rval != QLA_SUCCESS) {
1375 qla_printk(KERN_WARNING, ha,
1376 "Unable to update Serial Link options (%x).\n", rval);
1381 qla2x00_config_rings(struct scsi_qla_host *vha)
1383 struct qla_hw_data *ha = vha->hw;
1384 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1385 struct req_que *req = ha->req_q_map[0];
1386 struct rsp_que *rsp = ha->rsp_q_map[0];
1388 /* Setup ring parameters in initialization control block. */
1389 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1390 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1391 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1392 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1393 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1394 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1395 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1396 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
1398 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1399 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1400 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1401 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1402 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1406 qla24xx_config_rings(struct scsi_qla_host *vha)
1408 struct qla_hw_data *ha = vha->hw;
1409 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1410 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1411 struct qla_msix_entry *msix;
1412 struct init_cb_24xx *icb;
1414 struct req_que *req = ha->req_q_map[0];
1415 struct rsp_que *rsp = ha->rsp_q_map[0];
1417 /* Setup ring parameters in initialization control block. */
1418 icb = (struct init_cb_24xx *)ha->init_cb;
1419 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1420 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1421 icb->request_q_length = cpu_to_le16(req->length);
1422 icb->response_q_length = cpu_to_le16(rsp->length);
1423 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1424 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1425 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1426 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
1429 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1430 icb->rid = __constant_cpu_to_le16(rid);
1431 if (ha->flags.msix_enabled) {
1432 msix = &ha->msix_entries[1];
1433 DEBUG2_17(printk(KERN_INFO
1434 "Registering vector 0x%x for base que\n", msix->entry));
1435 icb->msix = cpu_to_le16(msix->entry);
1437 /* Use alternate PCI bus number */
1439 icb->firmware_options_2 |=
1440 __constant_cpu_to_le32(BIT_19);
1441 /* Use alternate PCI devfn */
1443 icb->firmware_options_2 |=
1444 __constant_cpu_to_le32(BIT_18);
1446 icb->firmware_options_2 &= __constant_cpu_to_le32(~BIT_22);
1447 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
1449 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
1450 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
1451 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
1452 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
1454 WRT_REG_DWORD(®->isp24.req_q_in, 0);
1455 WRT_REG_DWORD(®->isp24.req_q_out, 0);
1456 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
1457 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
1460 RD_REG_DWORD(&ioreg->hccr);
1464 * qla2x00_init_rings() - Initializes firmware.
1467 * Beginning of request ring has initialization control block already built
1468 * by nvram config routine.
1470 * Returns 0 on success.
1473 qla2x00_init_rings(scsi_qla_host_t *vha)
1476 unsigned long flags = 0;
1478 struct qla_hw_data *ha = vha->hw;
1479 struct req_que *req;
1480 struct rsp_que *rsp;
1481 struct scsi_qla_host *vp;
1482 struct mid_init_cb_24xx *mid_init_cb =
1483 (struct mid_init_cb_24xx *) ha->init_cb;
1485 spin_lock_irqsave(&ha->hardware_lock, flags);
1487 /* Clear outstanding commands array. */
1488 for (que = 0; que < ha->max_req_queues; que++) {
1489 req = ha->req_q_map[que];
1492 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1493 req->outstanding_cmds[cnt] = NULL;
1495 req->current_outstanding_cmd = 1;
1497 /* Initialize firmware. */
1498 req->ring_ptr = req->ring;
1499 req->ring_index = 0;
1500 req->cnt = req->length;
1503 for (que = 0; que < ha->max_rsp_queues; que++) {
1504 rsp = ha->rsp_q_map[que];
1507 /* Initialize response queue entries */
1508 qla2x00_init_response_q_entries(rsp);
1511 /* Clear RSCN queue. */
1512 list_for_each_entry(vp, &ha->vp_list, list) {
1513 vp->rscn_in_ptr = 0;
1514 vp->rscn_out_ptr = 0;
1516 ha->isp_ops->config_rings(vha);
1518 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1520 /* Update any ISP specific firmware options before initialization. */
1521 ha->isp_ops->update_fw_options(vha);
1523 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
1525 if (ha->flags.npiv_supported) {
1526 if (ha->operating_mode == LOOP)
1527 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
1528 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1531 if (IS_FWI2_CAPABLE(ha)) {
1532 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1533 mid_init_cb->init_cb.execution_throttle =
1534 cpu_to_le16(ha->fw_xcb_count);
1537 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
1539 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1542 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1550 * qla2x00_fw_ready() - Waits for firmware ready.
1553 * Returns 0 on success.
1556 qla2x00_fw_ready(scsi_qla_host_t *vha)
1559 unsigned long wtime, mtime, cs84xx_time;
1560 uint16_t min_wait; /* Minimum wait time if loop is down */
1561 uint16_t wait_time; /* Wait time if loop is coming ready */
1563 struct qla_hw_data *ha = vha->hw;
1567 /* 20 seconds for loop down. */
1571 * Firmware should take at most one RATOV to login, plus 5 seconds for
1572 * our own processing.
1574 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1575 wait_time = min_wait;
1578 /* Min wait time if loop down */
1579 mtime = jiffies + (min_wait * HZ);
1581 /* wait time before firmware ready */
1582 wtime = jiffies + (wait_time * HZ);
1584 /* Wait for ISP to finish LIP */
1585 if (!vha->flags.init_done)
1586 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1588 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1592 rval = qla2x00_get_firmware_state(vha, state);
1593 if (rval == QLA_SUCCESS) {
1594 if (state[0] < FSTATE_LOSS_OF_SYNC) {
1595 vha->device_flags &= ~DFLG_NO_CABLE;
1597 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1598 DEBUG16(printk("scsi(%ld): fw_state=%x "
1599 "84xx=%x.\n", vha->host_no, state[0],
1601 if ((state[2] & FSTATE_LOGGED_IN) &&
1602 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1603 DEBUG16(printk("scsi(%ld): Sending "
1604 "verify iocb.\n", vha->host_no));
1606 cs84xx_time = jiffies;
1607 rval = qla84xx_init_chip(vha);
1608 if (rval != QLA_SUCCESS)
1611 /* Add time taken to initialize. */
1612 cs84xx_time = jiffies - cs84xx_time;
1613 wtime += cs84xx_time;
1614 mtime += cs84xx_time;
1615 DEBUG16(printk("scsi(%ld): Increasing "
1616 "wait time by %ld. New time %ld\n",
1617 vha->host_no, cs84xx_time, wtime));
1619 } else if (state[0] == FSTATE_READY) {
1620 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1623 qla2x00_get_retry_cnt(vha, &ha->retry_count,
1624 &ha->login_timeout, &ha->r_a_tov);
1630 rval = QLA_FUNCTION_FAILED;
1632 if (atomic_read(&vha->loop_down_timer) &&
1633 state[0] != FSTATE_READY) {
1634 /* Loop down. Timeout on min_wait for states
1635 * other than Wait for Login.
1637 if (time_after_eq(jiffies, mtime)) {
1638 qla_printk(KERN_INFO, ha,
1639 "Cable is unplugged...\n");
1641 vha->device_flags |= DFLG_NO_CABLE;
1646 /* Mailbox cmd failed. Timeout on min_wait. */
1647 if (time_after_eq(jiffies, mtime))
1651 if (time_after_eq(jiffies, wtime))
1654 /* Delay for a while */
1657 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1658 vha->host_no, state[0], jiffies));
1661 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1662 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1666 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1674 * qla2x00_configure_hba
1675 * Setup adapter context.
1678 * ha = adapter state pointer.
1687 qla2x00_configure_hba(scsi_qla_host_t *vha)
1696 char connect_type[22];
1697 struct qla_hw_data *ha = vha->hw;
1699 /* Get host addresses. */
1700 rval = qla2x00_get_adapter_id(vha,
1701 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
1702 if (rval != QLA_SUCCESS) {
1703 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
1704 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1705 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1706 __func__, vha->host_no));
1708 qla_printk(KERN_WARNING, ha,
1709 "ERROR -- Unable to get host loop ID.\n");
1710 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1716 qla_printk(KERN_INFO, ha,
1717 "Cannot get topology - retrying.\n");
1718 return (QLA_FUNCTION_FAILED);
1721 vha->loop_id = loop_id;
1724 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1725 ha->operating_mode = LOOP;
1730 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1732 ha->current_topology = ISP_CFG_NL;
1733 strcpy(connect_type, "(Loop)");
1737 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1739 ha->switch_cap = sw_cap;
1740 ha->current_topology = ISP_CFG_FL;
1741 strcpy(connect_type, "(FL_Port)");
1745 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1747 ha->operating_mode = P2P;
1748 ha->current_topology = ISP_CFG_N;
1749 strcpy(connect_type, "(N_Port-to-N_Port)");
1753 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1755 ha->switch_cap = sw_cap;
1756 ha->operating_mode = P2P;
1757 ha->current_topology = ISP_CFG_F;
1758 strcpy(connect_type, "(F_Port)");
1762 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1764 vha->host_no, topo));
1765 ha->current_topology = ISP_CFG_NL;
1766 strcpy(connect_type, "(Loop)");
1770 /* Save Host port and loop ID. */
1771 /* byte order - Big Endian */
1772 vha->d_id.b.domain = domain;
1773 vha->d_id.b.area = area;
1774 vha->d_id.b.al_pa = al_pa;
1776 if (!vha->flags.init_done)
1777 qla_printk(KERN_INFO, ha,
1778 "Topology - %s, Host Loop address 0x%x\n",
1779 connect_type, vha->loop_id);
1782 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
1784 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
1791 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1796 struct qla_hw_data *ha = vha->hw;
1797 int use_tbl = !IS_QLA25XX(ha) && !IS_QLA81XX(ha);
1799 if (memcmp(model, BINZERO, len) != 0) {
1800 strncpy(ha->model_number, model, len);
1801 st = en = ha->model_number;
1804 if (*en != 0x20 && *en != 0x00)
1809 index = (ha->pdev->subsystem_device & 0xff);
1811 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1812 index < QLA_MODEL_NAMES)
1813 strncpy(ha->model_desc,
1814 qla2x00_model_name[index * 2 + 1],
1815 sizeof(ha->model_desc) - 1);
1817 index = (ha->pdev->subsystem_device & 0xff);
1819 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1820 index < QLA_MODEL_NAMES) {
1821 strcpy(ha->model_number,
1822 qla2x00_model_name[index * 2]);
1823 strncpy(ha->model_desc,
1824 qla2x00_model_name[index * 2 + 1],
1825 sizeof(ha->model_desc) - 1);
1827 strcpy(ha->model_number, def);
1830 if (IS_FWI2_CAPABLE(ha))
1831 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
1832 sizeof(ha->model_desc));
1835 /* On sparc systems, obtain port and node WWN from firmware
1838 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
1841 struct qla_hw_data *ha = vha->hw;
1842 struct pci_dev *pdev = ha->pdev;
1843 struct device_node *dp = pci_device_to_OF_node(pdev);
1847 val = of_get_property(dp, "port-wwn", &len);
1848 if (val && len >= WWN_SIZE)
1849 memcpy(nv->port_name, val, WWN_SIZE);
1851 val = of_get_property(dp, "node-wwn", &len);
1852 if (val && len >= WWN_SIZE)
1853 memcpy(nv->node_name, val, WWN_SIZE);
1858 * NVRAM configuration for ISP 2xxx
1861 * ha = adapter block pointer.
1864 * initialization control block in response_ring
1865 * host adapters parameters in host adapter block
1871 qla2x00_nvram_config(scsi_qla_host_t *vha)
1876 uint8_t *dptr1, *dptr2;
1877 struct qla_hw_data *ha = vha->hw;
1878 init_cb_t *icb = ha->init_cb;
1879 nvram_t *nv = ha->nvram;
1880 uint8_t *ptr = ha->nvram;
1881 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1885 /* Determine NVRAM starting address. */
1886 ha->nvram_size = sizeof(nvram_t);
1888 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1889 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1890 ha->nvram_base = 0x80;
1892 /* Get NVRAM data and calculate checksum. */
1893 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
1894 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1897 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
1898 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
1900 /* Bad NVRAM data, set defaults parameters. */
1901 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1902 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1903 /* Reset NVRAM data. */
1904 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1905 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1907 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1908 "invalid -- WWPN) defaults.\n");
1911 * Set default initialization control block.
1913 memset(nv, 0, ha->nvram_size);
1914 nv->parameter_block_version = ICB_VERSION;
1916 if (IS_QLA23XX(ha)) {
1917 nv->firmware_options[0] = BIT_2 | BIT_1;
1918 nv->firmware_options[1] = BIT_7 | BIT_5;
1919 nv->add_firmware_options[0] = BIT_5;
1920 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1921 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1922 nv->special_options[1] = BIT_7;
1923 } else if (IS_QLA2200(ha)) {
1924 nv->firmware_options[0] = BIT_2 | BIT_1;
1925 nv->firmware_options[1] = BIT_7 | BIT_5;
1926 nv->add_firmware_options[0] = BIT_5;
1927 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1928 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1929 } else if (IS_QLA2100(ha)) {
1930 nv->firmware_options[0] = BIT_3 | BIT_1;
1931 nv->firmware_options[1] = BIT_5;
1932 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1935 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1936 nv->execution_throttle = __constant_cpu_to_le16(16);
1937 nv->retry_count = 8;
1938 nv->retry_delay = 1;
1940 nv->port_name[0] = 33;
1941 nv->port_name[3] = 224;
1942 nv->port_name[4] = 139;
1944 qla2xxx_nvram_wwn_from_ofw(vha, nv);
1946 nv->login_timeout = 4;
1949 * Set default host adapter parameters
1951 nv->host_p[1] = BIT_2;
1952 nv->reset_delay = 5;
1953 nv->port_down_retry_count = 8;
1954 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1955 nv->link_down_timeout = 60;
1960 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1962 * The SN2 does not provide BIOS emulation which means you can't change
1963 * potentially bogus BIOS settings. Force the use of default settings
1964 * for link rate and frame size. Hope that the rest of the settings
1967 if (ia64_platform_is("sn2")) {
1968 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1970 nv->special_options[1] = BIT_7;
1974 /* Reset Initialization control block */
1975 memset(icb, 0, ha->init_cb_size);
1978 * Setup driver NVRAM options.
1980 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1981 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1982 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1983 nv->firmware_options[1] &= ~BIT_4;
1985 if (IS_QLA23XX(ha)) {
1986 nv->firmware_options[0] |= BIT_2;
1987 nv->firmware_options[0] &= ~BIT_3;
1988 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1990 if (IS_QLA2300(ha)) {
1991 if (ha->fb_rev == FPM_2310) {
1992 strcpy(ha->model_number, "QLA2310");
1994 strcpy(ha->model_number, "QLA2300");
1997 qla2x00_set_model_info(vha, nv->model_number,
1998 sizeof(nv->model_number), "QLA23xx");
2000 } else if (IS_QLA2200(ha)) {
2001 nv->firmware_options[0] |= BIT_2;
2003 * 'Point-to-point preferred, else loop' is not a safe
2004 * connection mode setting.
2006 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2008 /* Force 'loop preferred, else point-to-point'. */
2009 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2010 nv->add_firmware_options[0] |= BIT_5;
2012 strcpy(ha->model_number, "QLA22xx");
2013 } else /*if (IS_QLA2100(ha))*/ {
2014 strcpy(ha->model_number, "QLA2100");
2018 * Copy over NVRAM RISC parameter block to initialization control block.
2020 dptr1 = (uint8_t *)icb;
2021 dptr2 = (uint8_t *)&nv->parameter_block_version;
2022 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2024 *dptr1++ = *dptr2++;
2026 /* Copy 2nd half. */
2027 dptr1 = (uint8_t *)icb->add_firmware_options;
2028 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2030 *dptr1++ = *dptr2++;
2032 /* Use alternate WWN? */
2033 if (nv->host_p[1] & BIT_7) {
2034 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2035 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2038 /* Prepare nodename */
2039 if ((icb->firmware_options[1] & BIT_6) == 0) {
2041 * Firmware will apply the following mask if the nodename was
2044 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2045 icb->node_name[0] &= 0xF0;
2049 * Set host adapter parameters.
2051 if (nv->host_p[0] & BIT_7)
2052 ql2xextended_error_logging = 1;
2053 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2054 /* Always load RISC code on non ISP2[12]00 chips. */
2055 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2056 ha->flags.disable_risc_code_load = 0;
2057 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2058 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2059 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
2060 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
2061 ha->flags.disable_serdes = 0;
2063 ha->operating_mode =
2064 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2066 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2067 sizeof(ha->fw_seriallink_options));
2069 /* save HBA serial number */
2070 ha->serial0 = icb->port_name[5];
2071 ha->serial1 = icb->port_name[6];
2072 ha->serial2 = icb->port_name[7];
2073 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2074 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
2076 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2078 ha->retry_count = nv->retry_count;
2080 /* Set minimum login_timeout to 4 seconds. */
2081 if (nv->login_timeout < ql2xlogintimeout)
2082 nv->login_timeout = ql2xlogintimeout;
2083 if (nv->login_timeout < 4)
2084 nv->login_timeout = 4;
2085 ha->login_timeout = nv->login_timeout;
2086 icb->login_timeout = nv->login_timeout;
2088 /* Set minimum RATOV to 100 tenths of a second. */
2091 ha->loop_reset_delay = nv->reset_delay;
2093 /* Link Down Timeout = 0:
2095 * When Port Down timer expires we will start returning
2096 * I/O's to OS with "DID_NO_CONNECT".
2098 * Link Down Timeout != 0:
2100 * The driver waits for the link to come up after link down
2101 * before returning I/Os to OS with "DID_NO_CONNECT".
2103 if (nv->link_down_timeout == 0) {
2104 ha->loop_down_abort_time =
2105 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
2107 ha->link_down_timeout = nv->link_down_timeout;
2108 ha->loop_down_abort_time =
2109 (LOOP_DOWN_TIME - ha->link_down_timeout);
2113 * Need enough time to try and get the port back.
2115 ha->port_down_retry_count = nv->port_down_retry_count;
2116 if (qlport_down_retry)
2117 ha->port_down_retry_count = qlport_down_retry;
2118 /* Set login_retry_count */
2119 ha->login_retry_count = nv->retry_count;
2120 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2121 ha->port_down_retry_count > 3)
2122 ha->login_retry_count = ha->port_down_retry_count;
2123 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2124 ha->login_retry_count = ha->port_down_retry_count;
2125 if (ql2xloginretrycount)
2126 ha->login_retry_count = ql2xloginretrycount;
2128 icb->lun_enables = __constant_cpu_to_le16(0);
2129 icb->command_resource_count = 0;
2130 icb->immediate_notify_resource_count = 0;
2131 icb->timeout = __constant_cpu_to_le16(0);
2133 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2135 icb->firmware_options[0] &= ~BIT_3;
2136 icb->add_firmware_options[0] &=
2137 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2138 icb->add_firmware_options[0] |= BIT_2;
2139 icb->response_accumulation_timer = 3;
2140 icb->interrupt_delay_timer = 5;
2142 vha->flags.process_response_queue = 1;
2145 if (!vha->flags.init_done) {
2146 ha->zio_mode = icb->add_firmware_options[0] &
2147 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2148 ha->zio_timer = icb->interrupt_delay_timer ?
2149 icb->interrupt_delay_timer: 2;
2151 icb->add_firmware_options[0] &=
2152 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2153 vha->flags.process_response_queue = 0;
2154 if (ha->zio_mode != QLA_ZIO_DISABLED) {
2155 ha->zio_mode = QLA_ZIO_MODE_6;
2157 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
2158 "delay (%d us).\n", vha->host_no, ha->zio_mode,
2159 ha->zio_timer * 100));
2160 qla_printk(KERN_INFO, ha,
2161 "ZIO mode %d enabled; timer delay (%d us).\n",
2162 ha->zio_mode, ha->zio_timer * 100);
2164 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2165 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
2166 vha->flags.process_response_queue = 1;
2171 DEBUG2_3(printk(KERN_WARNING
2172 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
2178 qla2x00_rport_del(void *data)
2180 fc_port_t *fcport = data;
2181 struct fc_rport *rport;
2183 spin_lock_irq(fcport->vha->host->host_lock);
2184 rport = fcport->drport ? fcport->drport: fcport->rport;
2185 fcport->drport = NULL;
2186 spin_unlock_irq(fcport->vha->host->host_lock);
2188 fc_remote_port_delete(rport);
2192 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2194 * @flags: allocation flags
2196 * Returns a pointer to the allocated fcport, or NULL, if none available.
2199 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
2203 fcport = kzalloc(sizeof(fc_port_t), flags);
2207 /* Setup fcport template structure. */
2209 fcport->vp_idx = vha->vp_idx;
2210 fcport->port_type = FCT_UNKNOWN;
2211 fcport->loop_id = FC_NO_LOOP_ID;
2212 atomic_set(&fcport->state, FCS_UNCONFIGURED);
2213 fcport->supported_classes = FC_COS_UNSPECIFIED;
2219 * qla2x00_configure_loop
2220 * Updates Fibre Channel Device Database with what is actually on loop.
2223 * ha = adapter block pointer.
2228 * 2 = database was full and device was not configured.
2231 qla2x00_configure_loop(scsi_qla_host_t *vha)
2234 unsigned long flags, save_flags;
2235 struct qla_hw_data *ha = vha->hw;
2238 /* Get Initiator ID */
2239 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2240 rval = qla2x00_configure_hba(vha);
2241 if (rval != QLA_SUCCESS) {
2242 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
2248 save_flags = flags = vha->dpc_flags;
2249 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
2250 vha->host_no, flags));
2253 * If we have both an RSCN and PORT UPDATE pending then handle them
2254 * both at the same time.
2256 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2257 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
2259 /* Determine what we need to do */
2260 if (ha->current_topology == ISP_CFG_FL &&
2261 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2263 vha->flags.rscn_queue_overflow = 1;
2264 set_bit(RSCN_UPDATE, &flags);
2266 } else if (ha->current_topology == ISP_CFG_F &&
2267 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2269 vha->flags.rscn_queue_overflow = 1;
2270 set_bit(RSCN_UPDATE, &flags);
2271 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2273 } else if (ha->current_topology == ISP_CFG_N) {
2274 clear_bit(RSCN_UPDATE, &flags);
2276 } else if (!vha->flags.online ||
2277 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2279 vha->flags.rscn_queue_overflow = 1;
2280 set_bit(RSCN_UPDATE, &flags);
2281 set_bit(LOCAL_LOOP_UPDATE, &flags);
2284 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
2285 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2286 rval = QLA_FUNCTION_FAILED;
2288 rval = qla2x00_configure_local_loop(vha);
2291 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
2292 if (LOOP_TRANSITION(vha))
2293 rval = QLA_FUNCTION_FAILED;
2295 rval = qla2x00_configure_fabric(vha);
2298 if (rval == QLA_SUCCESS) {
2299 if (atomic_read(&vha->loop_down_timer) ||
2300 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2301 rval = QLA_FUNCTION_FAILED;
2303 atomic_set(&vha->loop_state, LOOP_READY);
2305 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
2310 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
2311 __func__, vha->host_no));
2313 DEBUG3(printk("%s: exiting normally\n", __func__));
2316 /* Restore state if a resync event occurred during processing */
2317 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2318 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
2319 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2320 if (test_bit(RSCN_UPDATE, &save_flags)) {
2321 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2322 vha->flags.rscn_queue_overflow = 1;
2332 * qla2x00_configure_local_loop
2333 * Updates Fibre Channel Device Database with local loop devices.
2336 * ha = adapter block pointer.
2342 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
2347 fc_port_t *fcport, *new_fcport;
2353 uint8_t domain, area, al_pa;
2354 struct qla_hw_data *ha = vha->hw;
2358 entries = MAX_FIBRE_DEVICES;
2360 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2361 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
2363 /* Get list of logged in devices. */
2364 memset(ha->gid_list, 0, GID_LIST_SIZE);
2365 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
2367 if (rval != QLA_SUCCESS)
2368 goto cleanup_allocation;
2370 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2371 vha->host_no, entries));
2372 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2373 entries * sizeof(struct gid_list_info)));
2375 /* Allocate temporary fcport for any new fcports discovered. */
2376 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2377 if (new_fcport == NULL) {
2378 rval = QLA_MEMORY_ALLOC_FAILED;
2379 goto cleanup_allocation;
2381 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2384 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2386 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2387 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2388 fcport->port_type != FCT_BROADCAST &&
2389 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2391 DEBUG(printk("scsi(%ld): Marking port lost, "
2393 vha->host_no, fcport->loop_id));
2395 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2399 /* Add devices to port list. */
2400 id_iter = (char *)ha->gid_list;
2401 for (index = 0; index < entries; index++) {
2402 domain = ((struct gid_list_info *)id_iter)->domain;
2403 area = ((struct gid_list_info *)id_iter)->area;
2404 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
2405 if (IS_QLA2100(ha) || IS_QLA2200(ha))
2406 loop_id = (uint16_t)
2407 ((struct gid_list_info *)id_iter)->loop_id_2100;
2409 loop_id = le16_to_cpu(
2410 ((struct gid_list_info *)id_iter)->loop_id);
2411 id_iter += ha->gid_list_info_size;
2413 /* Bypass reserved domain fields. */
2414 if ((domain & 0xf0) == 0xf0)
2417 /* Bypass if not same domain and area of adapter. */
2418 if (area && domain &&
2419 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
2422 /* Bypass invalid local loop ID. */
2423 if (loop_id > LAST_LOCAL_LOOP_ID)
2426 /* Fill in member data. */
2427 new_fcport->d_id.b.domain = domain;
2428 new_fcport->d_id.b.area = area;
2429 new_fcport->d_id.b.al_pa = al_pa;
2430 new_fcport->loop_id = loop_id;
2431 new_fcport->vp_idx = vha->vp_idx;
2432 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
2433 if (rval2 != QLA_SUCCESS) {
2434 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2435 "information -- get_port_database=%x, "
2437 vha->host_no, rval2, new_fcport->loop_id));
2438 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2440 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2444 /* Check for matching device in port list. */
2447 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2448 if (memcmp(new_fcport->port_name, fcport->port_name,
2452 fcport->flags &= ~FCF_FABRIC_DEVICE;
2453 fcport->loop_id = new_fcport->loop_id;
2454 fcport->port_type = new_fcport->port_type;
2455 fcport->d_id.b24 = new_fcport->d_id.b24;
2456 memcpy(fcport->node_name, new_fcport->node_name,
2464 /* New device, add to fcports list. */
2466 new_fcport->vha = vha;
2467 new_fcport->vp_idx = vha->vp_idx;
2469 list_add_tail(&new_fcport->list, &vha->vp_fcports);
2471 /* Allocate a new replacement fcport. */
2472 fcport = new_fcport;
2473 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2474 if (new_fcport == NULL) {
2475 rval = QLA_MEMORY_ALLOC_FAILED;
2476 goto cleanup_allocation;
2478 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2481 /* Base iIDMA settings on HBA port speed. */
2482 fcport->fp_speed = ha->link_data_rate;
2484 qla2x00_update_fcport(vha, fcport);
2492 if (rval != QLA_SUCCESS) {
2493 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2494 "rval=%x\n", vha->host_no, rval));
2501 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
2503 #define LS_UNKNOWN 2
2504 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2508 struct qla_hw_data *ha = vha->hw;
2510 if (!IS_IIDMA_CAPABLE(ha))
2513 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2514 fcport->fp_speed > ha->link_data_rate)
2517 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
2519 if (rval != QLA_SUCCESS) {
2520 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2521 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2522 vha->host_no, fcport->port_name[0], fcport->port_name[1],
2523 fcport->port_name[2], fcport->port_name[3],
2524 fcport->port_name[4], fcport->port_name[5],
2525 fcport->port_name[6], fcport->port_name[7], rval,
2526 fcport->fp_speed, mb[0], mb[1]));
2528 link_speed = link_speeds[LS_UNKNOWN];
2529 if (fcport->fp_speed < 5)
2530 link_speed = link_speeds[fcport->fp_speed];
2531 else if (fcport->fp_speed == 0x13)
2532 link_speed = link_speeds[5];
2533 DEBUG2(qla_printk(KERN_INFO, ha,
2534 "iIDMA adjusted to %s GB/s on "
2535 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2536 link_speed, fcport->port_name[0],
2537 fcport->port_name[1], fcport->port_name[2],
2538 fcport->port_name[3], fcport->port_name[4],
2539 fcport->port_name[5], fcport->port_name[6],
2540 fcport->port_name[7]));
2545 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
2547 struct fc_rport_identifiers rport_ids;
2548 struct fc_rport *rport;
2549 struct qla_hw_data *ha = vha->hw;
2551 qla2x00_rport_del(fcport);
2553 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2554 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2555 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2556 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2557 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2558 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
2560 qla_printk(KERN_WARNING, ha,
2561 "Unable to allocate fc remote port!\n");
2564 spin_lock_irq(fcport->vha->host->host_lock);
2565 *((fc_port_t **)rport->dd_data) = fcport;
2566 spin_unlock_irq(fcport->vha->host->host_lock);
2568 rport->supported_classes = fcport->supported_classes;
2570 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2571 if (fcport->port_type == FCT_INITIATOR)
2572 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2573 if (fcport->port_type == FCT_TARGET)
2574 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2575 fc_remote_port_rolechg(rport, rport_ids.roles);
2579 * qla2x00_update_fcport
2580 * Updates device on list.
2583 * ha = adapter block pointer.
2584 * fcport = port structure pointer.
2594 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
2596 struct qla_hw_data *ha = vha->hw;
2599 fcport->login_retry = 0;
2600 fcport->port_login_retry_count = ha->port_down_retry_count *
2602 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2604 fcport->flags &= ~FCF_LOGIN_NEEDED;
2606 qla2x00_iidma_fcport(vha, fcport);
2608 atomic_set(&fcport->state, FCS_ONLINE);
2610 qla2x00_reg_remote_port(vha, fcport);
2614 * qla2x00_configure_fabric
2615 * Setup SNS devices with loop ID's.
2618 * ha = adapter block pointer.
2625 qla2x00_configure_fabric(scsi_qla_host_t *vha)
2628 fc_port_t *fcport, *fcptemp;
2629 uint16_t next_loopid;
2630 uint16_t mb[MAILBOX_REGISTER_COUNT];
2632 LIST_HEAD(new_fcports);
2633 struct qla_hw_data *ha = vha->hw;
2634 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2636 /* If FL port exists, then SNS is present */
2637 if (IS_FWI2_CAPABLE(ha))
2638 loop_id = NPH_F_PORT;
2640 loop_id = SNS_FL_PORT;
2641 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
2642 if (rval != QLA_SUCCESS) {
2643 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2644 "Port\n", vha->host_no));
2646 vha->device_flags &= ~SWITCH_FOUND;
2647 return (QLA_SUCCESS);
2649 vha->device_flags |= SWITCH_FOUND;
2651 /* Mark devices that need re-synchronization. */
2652 rval2 = qla2x00_device_resync(vha);
2653 if (rval2 == QLA_RSCNS_HANDLED) {
2654 /* No point doing the scan, just continue. */
2655 return (QLA_SUCCESS);
2659 if (ql2xfdmienable &&
2660 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2661 qla2x00_fdmi_register(vha);
2663 /* Ensure we are logged into the SNS. */
2664 if (IS_FWI2_CAPABLE(ha))
2667 loop_id = SIMPLE_NAME_SERVER;
2668 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
2669 0xfc, mb, BIT_1 | BIT_0);
2670 if (mb[0] != MBS_COMMAND_COMPLETE) {
2671 DEBUG2(qla_printk(KERN_INFO, ha,
2672 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2673 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2674 mb[0], mb[1], mb[2], mb[6], mb[7]));
2675 return (QLA_SUCCESS);
2678 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2679 if (qla2x00_rft_id(vha)) {
2681 DEBUG2(printk("scsi(%ld): Register FC-4 "
2682 "TYPE failed.\n", vha->host_no));
2684 if (qla2x00_rff_id(vha)) {
2686 DEBUG2(printk("scsi(%ld): Register FC-4 "
2687 "Features failed.\n", vha->host_no));
2689 if (qla2x00_rnn_id(vha)) {
2691 DEBUG2(printk("scsi(%ld): Register Node Name "
2692 "failed.\n", vha->host_no));
2693 } else if (qla2x00_rsnn_nn(vha)) {
2695 DEBUG2(printk("scsi(%ld): Register Symbolic "
2696 "Node Name failed.\n", vha->host_no));
2700 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
2701 if (rval != QLA_SUCCESS)
2705 * Logout all previous fabric devices marked lost, except
2708 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2709 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2712 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2715 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2716 qla2x00_mark_device_lost(vha, fcport,
2717 ql2xplogiabsentdevice, 0);
2718 if (fcport->loop_id != FC_NO_LOOP_ID &&
2719 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2720 fcport->port_type != FCT_INITIATOR &&
2721 fcport->port_type != FCT_BROADCAST) {
2722 ha->isp_ops->fabric_logout(vha,
2724 fcport->d_id.b.domain,
2725 fcport->d_id.b.area,
2726 fcport->d_id.b.al_pa);
2727 fcport->loop_id = FC_NO_LOOP_ID;
2732 /* Starting free loop ID. */
2733 next_loopid = ha->min_external_loopid;
2736 * Scan through our port list and login entries that need to be
2739 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2740 if (atomic_read(&vha->loop_down_timer) ||
2741 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2744 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2745 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2748 if (fcport->loop_id == FC_NO_LOOP_ID) {
2749 fcport->loop_id = next_loopid;
2750 rval = qla2x00_find_new_loop_id(
2752 if (rval != QLA_SUCCESS) {
2753 /* Ran out of IDs to use */
2757 /* Login and update database */
2758 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
2761 /* Exit if out of loop IDs. */
2762 if (rval != QLA_SUCCESS) {
2767 * Login and add the new devices to our port list.
2769 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2770 if (atomic_read(&vha->loop_down_timer) ||
2771 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2774 /* Find a new loop ID to use. */
2775 fcport->loop_id = next_loopid;
2776 rval = qla2x00_find_new_loop_id(base_vha, fcport);
2777 if (rval != QLA_SUCCESS) {
2778 /* Ran out of IDs to use */
2782 /* Login and update database */
2783 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
2787 fcport->vp_idx = vha->vp_idx;
2789 list_move_tail(&fcport->list, &vha->vp_fcports);
2793 /* Free all new device structures not processed. */
2794 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2795 list_del(&fcport->list);
2800 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2801 "rval=%d\n", vha->host_no, rval));
2809 * qla2x00_find_all_fabric_devs
2812 * ha = adapter block pointer.
2813 * dev = database device entry pointer.
2822 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2823 struct list_head *new_fcports)
2827 fc_port_t *fcport, *new_fcport, *fcptemp;
2832 int first_dev, last_dev;
2833 port_id_t wrap, nxt_d_id;
2834 struct qla_hw_data *ha = vha->hw;
2835 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
2836 struct scsi_qla_host *tvp;
2840 /* Try GID_PT to get device list, else GAN. */
2841 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
2844 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2845 "on GA_NXT\n", vha->host_no));
2847 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
2850 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
2853 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
2856 } else if (ql2xiidmaenable &&
2857 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2858 qla2x00_gpsc(vha, swl);
2863 /* Allocate temporary fcport for any new fcports discovered. */
2864 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2865 if (new_fcport == NULL) {
2867 return (QLA_MEMORY_ALLOC_FAILED);
2869 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2870 /* Set start port ID scan at adapter ID. */
2874 /* Starting free loop ID. */
2875 loop_id = ha->min_external_loopid;
2876 for (; loop_id <= ha->max_loop_id; loop_id++) {
2877 if (qla2x00_is_reserved_id(vha, loop_id))
2880 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
2885 wrap.b24 = new_fcport->d_id.b24;
2887 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2888 memcpy(new_fcport->node_name,
2889 swl[swl_idx].node_name, WWN_SIZE);
2890 memcpy(new_fcport->port_name,
2891 swl[swl_idx].port_name, WWN_SIZE);
2892 memcpy(new_fcport->fabric_port_name,
2893 swl[swl_idx].fabric_port_name, WWN_SIZE);
2894 new_fcport->fp_speed = swl[swl_idx].fp_speed;
2896 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2902 /* Send GA_NXT to the switch */
2903 rval = qla2x00_ga_nxt(vha, new_fcport);
2904 if (rval != QLA_SUCCESS) {
2905 qla_printk(KERN_WARNING, ha,
2906 "SNS scan failed -- assuming zero-entry "
2908 list_for_each_entry_safe(fcport, fcptemp,
2909 new_fcports, list) {
2910 list_del(&fcport->list);
2918 /* If wrap on switch device list, exit. */
2920 wrap.b24 = new_fcport->d_id.b24;
2922 } else if (new_fcport->d_id.b24 == wrap.b24) {
2923 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2924 vha->host_no, new_fcport->d_id.b.domain,
2925 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2929 /* Bypass if same physical adapter. */
2930 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
2933 /* Bypass virtual ports of the same host. */
2935 if (ha->num_vhosts) {
2936 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
2937 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2946 /* Bypass if same domain and area of adapter. */
2947 if (((new_fcport->d_id.b24 & 0xffff00) ==
2948 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2952 /* Bypass reserved domain fields. */
2953 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2956 /* Locate matching device in database. */
2958 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2959 if (memcmp(new_fcport->port_name, fcport->port_name,
2965 /* Update port state. */
2966 memcpy(fcport->fabric_port_name,
2967 new_fcport->fabric_port_name, WWN_SIZE);
2968 fcport->fp_speed = new_fcport->fp_speed;
2971 * If address the same and state FCS_ONLINE, nothing
2974 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2975 atomic_read(&fcport->state) == FCS_ONLINE) {
2980 * If device was not a fabric device before.
2982 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2983 fcport->d_id.b24 = new_fcport->d_id.b24;
2984 fcport->loop_id = FC_NO_LOOP_ID;
2985 fcport->flags |= (FCF_FABRIC_DEVICE |
2991 * Port ID changed or device was marked to be updated;
2992 * Log it out if still logged in and mark it for
2995 fcport->d_id.b24 = new_fcport->d_id.b24;
2996 fcport->flags |= FCF_LOGIN_NEEDED;
2997 if (fcport->loop_id != FC_NO_LOOP_ID &&
2998 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2999 fcport->port_type != FCT_INITIATOR &&
3000 fcport->port_type != FCT_BROADCAST) {
3001 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3002 fcport->d_id.b.domain, fcport->d_id.b.area,
3003 fcport->d_id.b.al_pa);
3004 fcport->loop_id = FC_NO_LOOP_ID;
3012 /* If device was not in our fcports list, then add it. */
3013 list_add_tail(&new_fcport->list, new_fcports);
3015 /* Allocate a new replacement fcport. */
3016 nxt_d_id.b24 = new_fcport->d_id.b24;
3017 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
3018 if (new_fcport == NULL) {
3020 return (QLA_MEMORY_ALLOC_FAILED);
3022 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3023 new_fcport->d_id.b24 = nxt_d_id.b24;
3033 * qla2x00_find_new_loop_id
3034 * Scan through our port list and find a new usable loop ID.
3037 * ha: adapter state pointer.
3038 * dev: port structure pointer.
3041 * qla2x00 local function return status code.
3047 qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
3052 uint16_t first_loop_id;
3053 struct qla_hw_data *ha = vha->hw;
3054 struct scsi_qla_host *vp;
3055 struct scsi_qla_host *tvp;
3059 /* Save starting loop ID. */
3060 first_loop_id = dev->loop_id;
3063 /* Skip loop ID if already used by adapter. */
3064 if (dev->loop_id == vha->loop_id)
3067 /* Skip reserved loop IDs. */
3068 while (qla2x00_is_reserved_id(vha, dev->loop_id))
3071 /* Reset loop ID if passed the end. */
3072 if (dev->loop_id > ha->max_loop_id) {
3073 /* first loop ID. */
3074 dev->loop_id = ha->min_external_loopid;
3077 /* Check for loop ID being already in use. */
3080 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
3081 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3082 if (fcport->loop_id == dev->loop_id &&
3084 /* ID possibly in use */
3093 /* If not in use then it is free to use. */
3098 /* ID in use. Try next value. */
3101 /* If wrap around. No free ID to use. */
3102 if (dev->loop_id == first_loop_id) {
3103 dev->loop_id = FC_NO_LOOP_ID;
3104 rval = QLA_FUNCTION_FAILED;
3113 * qla2x00_device_resync
3114 * Marks devices in the database that needs resynchronization.
3117 * ha = adapter block pointer.
3123 qla2x00_device_resync(scsi_qla_host_t *vha)
3128 uint32_t rscn_entry;
3129 uint8_t rscn_out_iter;
3133 rval = QLA_RSCNS_HANDLED;
3135 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3136 vha->flags.rscn_queue_overflow) {
3138 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
3139 format = MSB(MSW(rscn_entry));
3140 d_id.b.domain = LSB(MSW(rscn_entry));
3141 d_id.b.area = MSB(LSW(rscn_entry));
3142 d_id.b.al_pa = LSB(LSW(rscn_entry));
3144 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3145 "[%02x/%02x%02x%02x].\n",
3146 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
3147 d_id.b.area, d_id.b.al_pa));
3149 vha->rscn_out_ptr++;
3150 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3151 vha->rscn_out_ptr = 0;
3153 /* Skip duplicate entries. */
3154 for (rscn_out_iter = vha->rscn_out_ptr;
3155 !vha->flags.rscn_queue_overflow &&
3156 rscn_out_iter != vha->rscn_in_ptr;
3157 rscn_out_iter = (rscn_out_iter ==
3158 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3160 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
3163 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
3164 "entry found at [%d].\n", vha->host_no,
3167 vha->rscn_out_ptr = rscn_out_iter;
3170 /* Queue overflow, set switch default case. */
3171 if (vha->flags.rscn_queue_overflow) {
3172 DEBUG(printk("scsi(%ld): device_resync: rscn "
3173 "overflow.\n", vha->host_no));
3176 vha->flags.rscn_queue_overflow = 0;
3192 vha->rscn_out_ptr = vha->rscn_in_ptr;
3198 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3199 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3200 (fcport->d_id.b24 & mask) != d_id.b24 ||
3201 fcport->port_type == FCT_BROADCAST)
3204 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3206 fcport->port_type != FCT_INITIATOR) {
3207 qla2x00_mark_device_lost(vha, fcport,
3217 * qla2x00_fabric_dev_login
3218 * Login fabric target device and update FC port database.
3221 * ha: adapter state pointer.
3222 * fcport: port structure list pointer.
3223 * next_loopid: contains value of a new loop ID that can be used
3224 * by the next login attempt.
3227 * qla2x00 local function return status code.
3233 qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
3234 uint16_t *next_loopid)
3239 struct qla_hw_data *ha = vha->hw;
3244 if (IS_ALOGIO_CAPABLE(ha)) {
3245 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3250 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
3251 if (rval == QLA_SUCCESS) {
3252 /* Send an ADISC to tape devices.*/
3254 if (fcport->flags & FCF_TAPE_PRESENT)
3256 rval = qla2x00_get_port_database(vha, fcport, opts);
3257 if (rval != QLA_SUCCESS) {
3258 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3259 fcport->d_id.b.domain, fcport->d_id.b.area,
3260 fcport->d_id.b.al_pa);
3261 qla2x00_mark_device_lost(vha, fcport, 1, 0);
3263 qla2x00_update_fcport(vha, fcport);
3271 * qla2x00_fabric_login
3272 * Issue fabric login command.
3275 * ha = adapter block pointer.
3276 * device = pointer to FC device type structure.
3279 * 0 - Login successfully
3281 * 2 - Initiator device
3285 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
3286 uint16_t *next_loopid)
3290 uint16_t tmp_loopid;
3291 uint16_t mb[MAILBOX_REGISTER_COUNT];
3292 struct qla_hw_data *ha = vha->hw;
3298 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3299 "for port %02x%02x%02x.\n",
3300 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
3301 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3303 /* Login fcport on switch. */
3304 ha->isp_ops->fabric_login(vha, fcport->loop_id,
3305 fcport->d_id.b.domain, fcport->d_id.b.area,
3306 fcport->d_id.b.al_pa, mb, BIT_0);
3307 if (mb[0] == MBS_PORT_ID_USED) {
3309 * Device has another loop ID. The firmware team
3310 * recommends the driver perform an implicit login with
3311 * the specified ID again. The ID we just used is save
3312 * here so we return with an ID that can be tried by
3316 tmp_loopid = fcport->loop_id;
3317 fcport->loop_id = mb[1];
3319 DEBUG(printk("Fabric Login: port in use - next "
3320 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3321 fcport->loop_id, fcport->d_id.b.domain,
3322 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3324 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3329 /* A retry occurred before. */
3330 *next_loopid = tmp_loopid;
3333 * No retry occurred before. Just increment the
3334 * ID value for next login.
3336 *next_loopid = (fcport->loop_id + 1);
3339 if (mb[1] & BIT_0) {
3340 fcport->port_type = FCT_INITIATOR;
3342 fcport->port_type = FCT_TARGET;
3343 if (mb[1] & BIT_1) {
3344 fcport->flags |= FCF_TAPE_PRESENT;
3349 fcport->supported_classes |= FC_COS_CLASS2;
3351 fcport->supported_classes |= FC_COS_CLASS3;
3355 } else if (mb[0] == MBS_LOOP_ID_USED) {
3357 * Loop ID already used, try next loop ID.
3360 rval = qla2x00_find_new_loop_id(vha, fcport);
3361 if (rval != QLA_SUCCESS) {
3362 /* Ran out of loop IDs to use */
3365 } else if (mb[0] == MBS_COMMAND_ERROR) {
3367 * Firmware possibly timed out during login. If NO
3368 * retries are left to do then the device is declared
3371 *next_loopid = fcport->loop_id;
3372 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3373 fcport->d_id.b.domain, fcport->d_id.b.area,
3374 fcport->d_id.b.al_pa);
3375 qla2x00_mark_device_lost(vha, fcport, 1, 0);
3381 * unrecoverable / not handled error
3383 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3384 "loop_id=%x jiffies=%lx.\n",
3385 __func__, vha->host_no, mb[0],
3386 fcport->d_id.b.domain, fcport->d_id.b.area,
3387 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3389 *next_loopid = fcport->loop_id;
3390 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3391 fcport->d_id.b.domain, fcport->d_id.b.area,
3392 fcport->d_id.b.al_pa);
3393 fcport->loop_id = FC_NO_LOOP_ID;
3394 fcport->login_retry = 0;
3405 * qla2x00_local_device_login
3406 * Issue local device login command.
3409 * ha = adapter block pointer.
3410 * loop_id = loop id of device to login to.
3412 * Returns (Where's the #define!!!!):
3413 * 0 - Login successfully
3418 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
3421 uint16_t mb[MAILBOX_REGISTER_COUNT];
3423 memset(mb, 0, sizeof(mb));
3424 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
3425 if (rval == QLA_SUCCESS) {
3426 /* Interrogate mailbox registers for any errors */
3427 if (mb[0] == MBS_COMMAND_ERROR)
3429 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3430 /* device not in PCB table */
3438 * qla2x00_loop_resync
3439 * Resync with fibre channel devices.
3442 * ha = adapter block pointer.
3448 qla2x00_loop_resync(scsi_qla_host_t *vha)
3450 int rval = QLA_SUCCESS;
3452 struct req_que *req;
3453 struct rsp_que *rsp;
3455 if (vha->hw->flags.cpu_affinity_enabled)
3456 req = vha->hw->req_q_map[0];
3461 atomic_set(&vha->loop_state, LOOP_UPDATE);
3462 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3463 if (vha->flags.online) {
3464 if (!(rval = qla2x00_fw_ready(vha))) {
3465 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3468 atomic_set(&vha->loop_state, LOOP_UPDATE);
3470 /* Issue a marker after FW becomes ready. */
3471 qla2x00_marker(vha, req, rsp, 0, 0,
3473 vha->marker_needed = 0;
3475 /* Remap devices on Loop. */
3476 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3478 qla2x00_configure_loop(vha);
3480 } while (!atomic_read(&vha->loop_down_timer) &&
3481 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3482 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3487 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3488 return (QLA_FUNCTION_FAILED);
3491 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3497 qla2x00_update_fcports(scsi_qla_host_t *vha)
3501 /* Go with deferred removal of rport references. */
3502 list_for_each_entry(fcport, &vha->vp_fcports, list)
3503 if (fcport && fcport->drport &&
3504 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
3505 qla2x00_rport_del(fcport);
3510 * Resets ISP and aborts all outstanding commands.
3513 * ha = adapter block pointer.
3519 qla2x00_abort_isp(scsi_qla_host_t *vha)
3523 struct qla_hw_data *ha = vha->hw;
3524 struct scsi_qla_host *vp;
3525 struct scsi_qla_host *tvp;
3526 struct req_que *req = ha->req_q_map[0];
3528 if (vha->flags.online) {
3529 vha->flags.online = 0;
3530 ha->flags.chip_reset_done = 0;
3531 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3532 ha->qla_stats.total_isp_aborts++;
3534 qla_printk(KERN_INFO, ha,
3535 "Performing ISP error recovery - ha= %p.\n", ha);
3536 ha->isp_ops->reset_chip(vha);
3538 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3539 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3540 atomic_set(&vha->loop_state, LOOP_DOWN);
3541 qla2x00_mark_all_devices_lost(vha, 0);
3542 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list)
3543 qla2x00_mark_all_devices_lost(vp, 0);
3545 if (!atomic_read(&vha->loop_down_timer))
3546 atomic_set(&vha->loop_down_timer,
3550 /* Requeue all commands in outstanding command list. */
3551 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
3553 ha->isp_ops->get_flash_version(vha, req->ring);
3555 ha->isp_ops->nvram_config(vha);
3557 if (!qla2x00_restart_isp(vha)) {
3558 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
3560 if (!atomic_read(&vha->loop_down_timer)) {
3562 * Issue marker command only when we are going
3563 * to start the I/O .
3565 vha->marker_needed = 1;
3568 vha->flags.online = 1;
3570 ha->isp_ops->enable_intrs(ha);
3572 ha->isp_abort_cnt = 0;
3573 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3576 ha->flags.fce_enabled = 1;
3578 fce_calc_size(ha->fce_bufs));
3579 rval = qla2x00_enable_fce_trace(vha,
3580 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3583 qla_printk(KERN_WARNING, ha,
3584 "Unable to reinitialize FCE "
3586 ha->flags.fce_enabled = 0;
3591 memset(ha->eft, 0, EFT_SIZE);
3592 rval = qla2x00_enable_eft_trace(vha,
3593 ha->eft_dma, EFT_NUM_BUFFERS);
3595 qla_printk(KERN_WARNING, ha,
3596 "Unable to reinitialize EFT "
3600 } else { /* failed the ISP abort */
3601 vha->flags.online = 1;
3602 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
3603 if (ha->isp_abort_cnt == 0) {
3604 qla_printk(KERN_WARNING, ha,
3605 "ISP error recovery failed - "
3606 "board disabled\n");
3608 * The next call disables the board
3611 ha->isp_ops->reset_adapter(vha);
3612 vha->flags.online = 0;
3613 clear_bit(ISP_ABORT_RETRY,
3616 } else { /* schedule another ISP abort */
3617 ha->isp_abort_cnt--;
3618 DEBUG(printk("qla%ld: ISP abort - "
3619 "retry remaining %d\n",
3620 vha->host_no, ha->isp_abort_cnt));
3624 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3625 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3626 "- retrying (%d) more times\n",
3627 vha->host_no, ha->isp_abort_cnt));
3628 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3636 DEBUG(printk(KERN_INFO
3637 "qla2x00_abort_isp(%ld): succeeded.\n",
3639 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
3641 qla2x00_vp_abort_isp(vp);
3644 qla_printk(KERN_INFO, ha,
3645 "qla2x00_abort_isp: **** FAILED ****\n");
3652 * qla2x00_restart_isp
3653 * restarts the ISP after a reset
3656 * ha = adapter block pointer.
3662 qla2x00_restart_isp(scsi_qla_host_t *vha)
3666 struct qla_hw_data *ha = vha->hw;
3667 struct req_que *req = ha->req_q_map[0];
3668 struct rsp_que *rsp = ha->rsp_q_map[0];
3670 /* If firmware needs to be loaded */
3671 if (qla2x00_isp_firmware(vha)) {
3672 vha->flags.online = 0;
3673 status = ha->isp_ops->chip_diag(vha);
3675 status = qla2x00_setup_chip(vha);
3678 if (!status && !(status = qla2x00_init_rings(vha))) {
3679 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
3680 ha->flags.chip_reset_done = 1;
3681 /* Initialize the queues in use */
3682 qla25xx_init_queues(ha);
3684 status = qla2x00_fw_ready(vha);
3686 DEBUG(printk("%s(): Start configure loop, "
3687 "status = %d\n", __func__, status));
3689 /* Issue a marker after FW becomes ready. */
3690 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
3692 vha->flags.online = 1;
3693 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3696 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3697 qla2x00_configure_loop(vha);
3699 } while (!atomic_read(&vha->loop_down_timer) &&
3700 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3701 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3705 /* if no cable then assume it's good */
3706 if ((vha->device_flags & DFLG_NO_CABLE))
3709 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3717 qla25xx_init_queues(struct qla_hw_data *ha)
3719 struct rsp_que *rsp = NULL;
3720 struct req_que *req = NULL;
3721 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3725 for (i = 1; i < ha->max_rsp_queues; i++) {
3726 rsp = ha->rsp_q_map[i];
3728 rsp->options &= ~BIT_0;
3729 ret = qla25xx_init_rsp_que(base_vha, rsp);
3730 if (ret != QLA_SUCCESS)
3731 DEBUG2_17(printk(KERN_WARNING
3732 "%s Rsp que:%d init failed\n", __func__,
3735 DEBUG2_17(printk(KERN_INFO
3736 "%s Rsp que:%d inited\n", __func__,
3740 for (i = 1; i < ha->max_req_queues; i++) {
3741 req = ha->req_q_map[i];
3743 /* Clear outstanding commands array. */
3744 req->options &= ~BIT_0;
3745 ret = qla25xx_init_req_que(base_vha, req);
3746 if (ret != QLA_SUCCESS)
3747 DEBUG2_17(printk(KERN_WARNING
3748 "%s Req que:%d init failed\n", __func__,
3751 DEBUG2_17(printk(KERN_WARNING
3752 "%s Req que:%d inited\n", __func__,
3760 * qla2x00_reset_adapter
3764 * ha = adapter block pointer.
3767 qla2x00_reset_adapter(scsi_qla_host_t *vha)
3769 unsigned long flags = 0;
3770 struct qla_hw_data *ha = vha->hw;
3771 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3773 vha->flags.online = 0;
3774 ha->isp_ops->disable_intrs(ha);
3776 spin_lock_irqsave(&ha->hardware_lock, flags);
3777 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3778 RD_REG_WORD(®->hccr); /* PCI Posting. */
3779 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3780 RD_REG_WORD(®->hccr); /* PCI Posting. */
3781 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3785 qla24xx_reset_adapter(scsi_qla_host_t *vha)
3787 unsigned long flags = 0;
3788 struct qla_hw_data *ha = vha->hw;
3789 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3791 vha->flags.online = 0;
3792 ha->isp_ops->disable_intrs(ha);
3794 spin_lock_irqsave(&ha->hardware_lock, flags);
3795 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3796 RD_REG_DWORD(®->hccr);
3797 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3798 RD_REG_DWORD(®->hccr);
3799 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3801 if (IS_NOPOLLING_TYPE(ha))
3802 ha->isp_ops->enable_intrs(ha);
3805 /* On sparc systems, obtain port and node WWN from firmware
3808 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3809 struct nvram_24xx *nv)
3812 struct qla_hw_data *ha = vha->hw;
3813 struct pci_dev *pdev = ha->pdev;
3814 struct device_node *dp = pci_device_to_OF_node(pdev);
3818 val = of_get_property(dp, "port-wwn", &len);
3819 if (val && len >= WWN_SIZE)
3820 memcpy(nv->port_name, val, WWN_SIZE);
3822 val = of_get_property(dp, "node-wwn", &len);
3823 if (val && len >= WWN_SIZE)
3824 memcpy(nv->node_name, val, WWN_SIZE);
3829 qla24xx_nvram_config(scsi_qla_host_t *vha)
3832 struct init_cb_24xx *icb;
3833 struct nvram_24xx *nv;
3835 uint8_t *dptr1, *dptr2;
3838 struct qla_hw_data *ha = vha->hw;
3841 icb = (struct init_cb_24xx *)ha->init_cb;
3844 /* Determine NVRAM starting address. */
3845 if (ha->flags.port0) {
3846 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3847 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3849 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3850 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3852 ha->nvram_size = sizeof(struct nvram_24xx);
3853 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3855 /* Get VPD data into cache */
3856 ha->vpd = ha->nvram + VPD_OFFSET;
3857 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
3858 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3860 /* Get NVRAM data into cache and calculate checksum. */
3861 dptr = (uint32_t *)nv;
3862 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
3864 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3865 chksum += le32_to_cpu(*dptr++);
3867 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
3868 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
3870 /* Bad NVRAM data, set defaults parameters. */
3871 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3872 || nv->id[3] != ' ' ||
3873 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3874 /* Reset NVRAM data. */
3875 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3876 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3877 le16_to_cpu(nv->nvram_version));
3878 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3879 "invalid -- WWPN) defaults.\n");
3882 * Set default initialization control block.
3884 memset(nv, 0, ha->nvram_size);
3885 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3886 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3887 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3888 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3889 nv->exchange_count = __constant_cpu_to_le16(0);
3890 nv->hard_address = __constant_cpu_to_le16(124);
3891 nv->port_name[0] = 0x21;
3892 nv->port_name[1] = 0x00 + ha->port_no;
3893 nv->port_name[2] = 0x00;
3894 nv->port_name[3] = 0xe0;
3895 nv->port_name[4] = 0x8b;
3896 nv->port_name[5] = 0x1c;
3897 nv->port_name[6] = 0x55;
3898 nv->port_name[7] = 0x86;
3899 nv->node_name[0] = 0x20;
3900 nv->node_name[1] = 0x00;
3901 nv->node_name[2] = 0x00;
3902 nv->node_name[3] = 0xe0;
3903 nv->node_name[4] = 0x8b;
3904 nv->node_name[5] = 0x1c;
3905 nv->node_name[6] = 0x55;
3906 nv->node_name[7] = 0x86;
3907 qla24xx_nvram_wwn_from_ofw(vha, nv);
3908 nv->login_retry_count = __constant_cpu_to_le16(8);
3909 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3910 nv->login_timeout = __constant_cpu_to_le16(0);
3911 nv->firmware_options_1 =
3912 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3913 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3914 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3915 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3916 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3917 nv->efi_parameters = __constant_cpu_to_le32(0);
3918 nv->reset_delay = 5;
3919 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3920 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3921 nv->link_down_timeout = __constant_cpu_to_le16(30);
3926 /* Reset Initialization control block */
3927 memset(icb, 0, ha->init_cb_size);
3929 /* Copy 1st segment. */
3930 dptr1 = (uint8_t *)icb;
3931 dptr2 = (uint8_t *)&nv->version;
3932 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3934 *dptr1++ = *dptr2++;
3936 icb->login_retry_count = nv->login_retry_count;
3937 icb->link_down_on_nos = nv->link_down_on_nos;
3939 /* Copy 2nd segment. */
3940 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3941 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3942 cnt = (uint8_t *)&icb->reserved_3 -
3943 (uint8_t *)&icb->interrupt_delay_timer;
3945 *dptr1++ = *dptr2++;
3948 * Setup driver NVRAM options.
3950 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
3953 /* Use alternate WWN? */
3954 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3955 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3956 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3959 /* Prepare nodename */
3960 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3962 * Firmware will apply the following mask if the nodename was
3965 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3966 icb->node_name[0] &= 0xF0;
3969 /* Set host adapter parameters. */
3970 ha->flags.disable_risc_code_load = 0;
3971 ha->flags.enable_lip_reset = 0;
3972 ha->flags.enable_lip_full_login =
3973 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3974 ha->flags.enable_target_reset =
3975 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
3976 ha->flags.enable_led_scheme = 0;
3977 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
3979 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3980 (BIT_6 | BIT_5 | BIT_4)) >> 4;
3982 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3983 sizeof(ha->fw_seriallink_options24));
3985 /* save HBA serial number */
3986 ha->serial0 = icb->port_name[5];
3987 ha->serial1 = icb->port_name[6];
3988 ha->serial2 = icb->port_name[7];
3989 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3990 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
3992 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3994 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3996 /* Set minimum login_timeout to 4 seconds. */
3997 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3998 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3999 if (le16_to_cpu(nv->login_timeout) < 4)
4000 nv->login_timeout = __constant_cpu_to_le16(4);
4001 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4002 icb->login_timeout = nv->login_timeout;
4004 /* Set minimum RATOV to 100 tenths of a second. */
4007 ha->loop_reset_delay = nv->reset_delay;
4009 /* Link Down Timeout = 0:
4011 * When Port Down timer expires we will start returning
4012 * I/O's to OS with "DID_NO_CONNECT".
4014 * Link Down Timeout != 0:
4016 * The driver waits for the link to come up after link down
4017 * before returning I/Os to OS with "DID_NO_CONNECT".
4019 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4020 ha->loop_down_abort_time =
4021 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4023 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4024 ha->loop_down_abort_time =
4025 (LOOP_DOWN_TIME - ha->link_down_timeout);
4028 /* Need enough time to try and get the port back. */
4029 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4030 if (qlport_down_retry)
4031 ha->port_down_retry_count = qlport_down_retry;
4033 /* Set login_retry_count */
4034 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4035 if (ha->port_down_retry_count ==
4036 le16_to_cpu(nv->port_down_retry_count) &&
4037 ha->port_down_retry_count > 3)
4038 ha->login_retry_count = ha->port_down_retry_count;
4039 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4040 ha->login_retry_count = ha->port_down_retry_count;
4041 if (ql2xloginretrycount)
4042 ha->login_retry_count = ql2xloginretrycount;
4045 if (!vha->flags.init_done) {
4046 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4047 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4048 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4049 le16_to_cpu(icb->interrupt_delay_timer): 2;
4051 icb->firmware_options_2 &= __constant_cpu_to_le32(
4052 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4053 vha->flags.process_response_queue = 0;
4054 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4055 ha->zio_mode = QLA_ZIO_MODE_6;
4057 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4058 "(%d us).\n", vha->host_no, ha->zio_mode,
4059 ha->zio_timer * 100));
4060 qla_printk(KERN_INFO, ha,
4061 "ZIO mode %d enabled; timer delay (%d us).\n",
4062 ha->zio_mode, ha->zio_timer * 100);
4064 icb->firmware_options_2 |= cpu_to_le32(
4065 (uint32_t)ha->zio_mode);
4066 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4067 vha->flags.process_response_queue = 1;
4071 DEBUG2_3(printk(KERN_WARNING
4072 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4078 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4081 int rval = QLA_SUCCESS;
4082 int segments, fragment;
4083 uint32_t *dcode, dlen;
4087 struct qla_hw_data *ha = vha->hw;
4088 struct req_que *req = ha->req_q_map[0];
4090 qla_printk(KERN_INFO, ha,
4091 "FW: Loading from flash (%x)...\n", faddr);
4095 segments = FA_RISC_CODE_SEGMENTS;
4096 dcode = (uint32_t *)req->ring;
4099 /* Validate firmware image by checking version. */
4100 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
4101 for (i = 0; i < 4; i++)
4102 dcode[i] = be32_to_cpu(dcode[i]);
4103 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4104 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4105 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4107 qla_printk(KERN_WARNING, ha,
4108 "Unable to verify integrity of flash firmware image!\n");
4109 qla_printk(KERN_WARNING, ha,
4110 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4111 dcode[1], dcode[2], dcode[3]);
4113 return QLA_FUNCTION_FAILED;
4116 while (segments && rval == QLA_SUCCESS) {
4117 /* Read segment's load information. */
4118 qla24xx_read_flash_data(vha, dcode, faddr, 4);
4120 risc_addr = be32_to_cpu(dcode[2]);
4121 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4122 risc_size = be32_to_cpu(dcode[3]);
4125 while (risc_size > 0 && rval == QLA_SUCCESS) {
4126 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4127 if (dlen > risc_size)
4130 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4131 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
4132 vha->host_no, risc_addr, dlen, faddr));
4134 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
4135 for (i = 0; i < dlen; i++)
4136 dcode[i] = swab32(dcode[i]);
4138 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
4141 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4142 "segment %d of firmware\n", vha->host_no,
4144 qla_printk(KERN_WARNING, ha,
4145 "[ERROR] Failed to load segment %d of "
4146 "firmware\n", fragment);
4163 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4166 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4170 uint16_t *wcode, *fwcode;
4171 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4172 struct fw_blob *blob;
4173 struct qla_hw_data *ha = vha->hw;
4174 struct req_que *req = ha->req_q_map[0];
4176 /* Load firmware blob. */
4177 blob = qla2x00_request_firmware(vha);
4179 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
4180 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4181 "from: " QLA_FW_URL ".\n");
4182 return QLA_FUNCTION_FAILED;
4187 wcode = (uint16_t *)req->ring;
4189 fwcode = (uint16_t *)blob->fw->data;
4192 /* Validate firmware image by checking version. */
4193 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4194 qla_printk(KERN_WARNING, ha,
4195 "Unable to verify integrity of firmware image (%Zd)!\n",
4197 goto fail_fw_integrity;
4199 for (i = 0; i < 4; i++)
4200 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4201 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4202 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4203 wcode[2] == 0 && wcode[3] == 0)) {
4204 qla_printk(KERN_WARNING, ha,
4205 "Unable to verify integrity of firmware image!\n");
4206 qla_printk(KERN_WARNING, ha,
4207 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
4208 wcode[1], wcode[2], wcode[3]);
4209 goto fail_fw_integrity;
4213 while (*seg && rval == QLA_SUCCESS) {
4215 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4216 risc_size = be16_to_cpu(fwcode[3]);
4218 /* Validate firmware image size. */
4219 fwclen += risc_size * sizeof(uint16_t);
4220 if (blob->fw->size < fwclen) {
4221 qla_printk(KERN_WARNING, ha,
4222 "Unable to verify integrity of firmware image "
4223 "(%Zd)!\n", blob->fw->size);
4224 goto fail_fw_integrity;
4228 while (risc_size > 0 && rval == QLA_SUCCESS) {
4229 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4230 if (wlen > risc_size)
4233 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4234 "addr %x, number of words 0x%x.\n", vha->host_no,
4237 for (i = 0; i < wlen; i++)
4238 wcode[i] = swab16(fwcode[i]);
4240 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
4243 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4244 "segment %d of firmware\n", vha->host_no,
4246 qla_printk(KERN_WARNING, ha,
4247 "[ERROR] Failed to load segment %d of "
4248 "firmware\n", fragment);
4264 return QLA_FUNCTION_FAILED;
4268 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4271 int segments, fragment;
4272 uint32_t *dcode, dlen;
4276 struct fw_blob *blob;
4277 uint32_t *fwcode, fwclen;
4278 struct qla_hw_data *ha = vha->hw;
4279 struct req_que *req = ha->req_q_map[0];
4281 /* Load firmware blob. */
4282 blob = qla2x00_request_firmware(vha);
4284 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
4285 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4286 "from: " QLA_FW_URL ".\n");
4288 return QLA_FUNCTION_FAILED;
4291 qla_printk(KERN_INFO, ha,
4292 "FW: Loading via request-firmware...\n");
4296 segments = FA_RISC_CODE_SEGMENTS;
4297 dcode = (uint32_t *)req->ring;
4299 fwcode = (uint32_t *)blob->fw->data;
4302 /* Validate firmware image by checking version. */
4303 if (blob->fw->size < 8 * sizeof(uint32_t)) {
4304 qla_printk(KERN_WARNING, ha,
4305 "Unable to verify integrity of firmware image (%Zd)!\n",
4307 goto fail_fw_integrity;
4309 for (i = 0; i < 4; i++)
4310 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4311 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4312 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4313 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4315 qla_printk(KERN_WARNING, ha,
4316 "Unable to verify integrity of firmware image!\n");
4317 qla_printk(KERN_WARNING, ha,
4318 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4319 dcode[1], dcode[2], dcode[3]);
4320 goto fail_fw_integrity;
4323 while (segments && rval == QLA_SUCCESS) {
4324 risc_addr = be32_to_cpu(fwcode[2]);
4325 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4326 risc_size = be32_to_cpu(fwcode[3]);
4328 /* Validate firmware image size. */
4329 fwclen += risc_size * sizeof(uint32_t);
4330 if (blob->fw->size < fwclen) {
4331 qla_printk(KERN_WARNING, ha,
4332 "Unable to verify integrity of firmware image "
4333 "(%Zd)!\n", blob->fw->size);
4335 goto fail_fw_integrity;
4339 while (risc_size > 0 && rval == QLA_SUCCESS) {
4340 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4341 if (dlen > risc_size)
4344 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4345 "addr %x, number of dwords 0x%x.\n", vha->host_no,
4348 for (i = 0; i < dlen; i++)
4349 dcode[i] = swab32(fwcode[i]);
4351 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
4354 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4355 "segment %d of firmware\n", vha->host_no,
4357 qla_printk(KERN_WARNING, ha,
4358 "[ERROR] Failed to load segment %d of "
4359 "firmware\n", fragment);
4375 return QLA_FUNCTION_FAILED;
4379 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4383 if (ql2xfwloadbin == 1)
4384 return qla81xx_load_risc(vha, srisc_addr);
4388 * 1) Firmware via request-firmware interface (.bin file).
4389 * 2) Firmware residing in flash.
4391 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4392 if (rval == QLA_SUCCESS)
4395 return qla24xx_load_risc_flash(vha, srisc_addr,
4396 vha->hw->flt_region_fw);
4400 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4403 struct qla_hw_data *ha = vha->hw;
4405 if (ql2xfwloadbin == 2)
4410 * 1) Firmware residing in flash.
4411 * 2) Firmware via request-firmware interface (.bin file).
4412 * 3) Golden-Firmware residing in flash -- limited operation.
4414 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
4415 if (rval == QLA_SUCCESS)
4419 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4420 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4423 qla_printk(KERN_ERR, ha,
4424 "FW: Attempting to fallback to golden firmware...\n");
4425 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4426 if (rval != QLA_SUCCESS)
4429 qla_printk(KERN_ERR, ha,
4430 "FW: Please update operational firmware...\n");
4431 ha->flags.running_gold_fw = 1;
4437 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
4440 struct qla_hw_data *ha = vha->hw;
4442 if (!IS_FWI2_CAPABLE(ha))
4444 if (!ha->fw_major_version)
4447 ret = qla2x00_stop_firmware(vha);
4448 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4449 ret != QLA_INVALID_COMMAND && retries ; retries--) {
4450 ha->isp_ops->reset_chip(vha);
4451 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
4453 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
4455 qla_printk(KERN_INFO, ha,
4456 "Attempting retry of stop-firmware command...\n");
4457 ret = qla2x00_stop_firmware(vha);
4462 qla24xx_configure_vhba(scsi_qla_host_t *vha)
4464 int rval = QLA_SUCCESS;
4465 uint16_t mb[MAILBOX_REGISTER_COUNT];
4466 struct qla_hw_data *ha = vha->hw;
4467 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4468 struct req_que *req;
4469 struct rsp_que *rsp;
4474 rval = qla2x00_fw_ready(base_vha);
4475 if (ha->flags.cpu_affinity_enabled)
4476 req = ha->req_q_map[0];
4481 if (rval == QLA_SUCCESS) {
4482 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
4483 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
4486 vha->flags.management_server_logged_in = 0;
4488 /* Login to SNS first */
4489 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
4490 if (mb[0] != MBS_COMMAND_COMPLETE) {
4491 DEBUG15(qla_printk(KERN_INFO, ha,
4492 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4493 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4494 mb[0], mb[1], mb[2], mb[6], mb[7]));
4495 return (QLA_FUNCTION_FAILED);
4498 atomic_set(&vha->loop_down_timer, 0);
4499 atomic_set(&vha->loop_state, LOOP_UP);
4500 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4501 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4502 rval = qla2x00_loop_resync(base_vha);
4507 /* 84XX Support **************************************************************/
4509 static LIST_HEAD(qla_cs84xx_list);
4510 static DEFINE_MUTEX(qla_cs84xx_mutex);
4512 static struct qla_chip_state_84xx *
4513 qla84xx_get_chip(struct scsi_qla_host *vha)
4515 struct qla_chip_state_84xx *cs84xx;
4516 struct qla_hw_data *ha = vha->hw;
4518 mutex_lock(&qla_cs84xx_mutex);
4520 /* Find any shared 84xx chip. */
4521 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4522 if (cs84xx->bus == ha->pdev->bus) {
4523 kref_get(&cs84xx->kref);
4528 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4532 kref_init(&cs84xx->kref);
4533 spin_lock_init(&cs84xx->access_lock);
4534 mutex_init(&cs84xx->fw_update_mutex);
4535 cs84xx->bus = ha->pdev->bus;
4537 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4539 mutex_unlock(&qla_cs84xx_mutex);
4544 __qla84xx_chip_release(struct kref *kref)
4546 struct qla_chip_state_84xx *cs84xx =
4547 container_of(kref, struct qla_chip_state_84xx, kref);
4549 mutex_lock(&qla_cs84xx_mutex);
4550 list_del(&cs84xx->list);
4551 mutex_unlock(&qla_cs84xx_mutex);
4556 qla84xx_put_chip(struct scsi_qla_host *vha)
4558 struct qla_hw_data *ha = vha->hw;
4560 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4564 qla84xx_init_chip(scsi_qla_host_t *vha)
4568 struct qla_hw_data *ha = vha->hw;
4570 mutex_lock(&ha->cs84xx->fw_update_mutex);
4572 rval = qla84xx_verify_chip(vha, status);
4574 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4576 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4580 /* 81XX Support **************************************************************/
4583 qla81xx_nvram_config(scsi_qla_host_t *vha)
4586 struct init_cb_81xx *icb;
4587 struct nvram_81xx *nv;
4589 uint8_t *dptr1, *dptr2;
4592 struct qla_hw_data *ha = vha->hw;
4595 icb = (struct init_cb_81xx *)ha->init_cb;
4598 /* Determine NVRAM starting address. */
4599 ha->nvram_size = sizeof(struct nvram_81xx);
4600 ha->vpd_size = FA_NVRAM_VPD_SIZE;
4602 /* Get VPD data into cache */
4603 ha->vpd = ha->nvram + VPD_OFFSET;
4604 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4607 /* Get NVRAM data into cache and calculate checksum. */
4608 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
4610 dptr = (uint32_t *)nv;
4611 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4612 chksum += le32_to_cpu(*dptr++);
4614 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
4615 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4617 /* Bad NVRAM data, set defaults parameters. */
4618 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4619 || nv->id[3] != ' ' ||
4620 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4621 /* Reset NVRAM data. */
4622 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4623 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4624 le16_to_cpu(nv->nvram_version));
4625 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4626 "invalid -- WWPN) defaults.\n");
4629 * Set default initialization control block.
4631 memset(nv, 0, ha->nvram_size);
4632 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4633 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4634 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4635 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4636 nv->exchange_count = __constant_cpu_to_le16(0);
4637 nv->port_name[0] = 0x21;
4638 nv->port_name[1] = 0x00 + ha->port_no;
4639 nv->port_name[2] = 0x00;
4640 nv->port_name[3] = 0xe0;
4641 nv->port_name[4] = 0x8b;
4642 nv->port_name[5] = 0x1c;
4643 nv->port_name[6] = 0x55;
4644 nv->port_name[7] = 0x86;
4645 nv->node_name[0] = 0x20;
4646 nv->node_name[1] = 0x00;
4647 nv->node_name[2] = 0x00;
4648 nv->node_name[3] = 0xe0;
4649 nv->node_name[4] = 0x8b;
4650 nv->node_name[5] = 0x1c;
4651 nv->node_name[6] = 0x55;
4652 nv->node_name[7] = 0x86;
4653 nv->login_retry_count = __constant_cpu_to_le16(8);
4654 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4655 nv->login_timeout = __constant_cpu_to_le16(0);
4656 nv->firmware_options_1 =
4657 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4658 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4659 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4660 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4661 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4662 nv->efi_parameters = __constant_cpu_to_le32(0);
4663 nv->reset_delay = 5;
4664 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4665 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4666 nv->link_down_timeout = __constant_cpu_to_le16(30);
4667 nv->enode_mac[0] = 0x00;
4668 nv->enode_mac[1] = 0x02;
4669 nv->enode_mac[2] = 0x03;
4670 nv->enode_mac[3] = 0x04;
4671 nv->enode_mac[4] = 0x05;
4672 nv->enode_mac[5] = 0x06 + ha->port_no;
4677 /* Reset Initialization control block */
4678 memset(icb, 0, sizeof(struct init_cb_81xx));
4680 /* Copy 1st segment. */
4681 dptr1 = (uint8_t *)icb;
4682 dptr2 = (uint8_t *)&nv->version;
4683 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4685 *dptr1++ = *dptr2++;
4687 icb->login_retry_count = nv->login_retry_count;
4689 /* Copy 2nd segment. */
4690 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4691 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4692 cnt = (uint8_t *)&icb->reserved_5 -
4693 (uint8_t *)&icb->interrupt_delay_timer;
4695 *dptr1++ = *dptr2++;
4697 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4698 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4699 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4700 icb->enode_mac[0] = 0x01;
4701 icb->enode_mac[1] = 0x02;
4702 icb->enode_mac[2] = 0x03;
4703 icb->enode_mac[3] = 0x04;
4704 icb->enode_mac[4] = 0x05;
4705 icb->enode_mac[5] = 0x06 + ha->port_no;
4708 /* Use extended-initialization control block. */
4709 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
4712 * Setup driver NVRAM options.
4714 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4717 /* Use alternate WWN? */
4718 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4719 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4720 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4723 /* Prepare nodename */
4724 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4726 * Firmware will apply the following mask if the nodename was
4729 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4730 icb->node_name[0] &= 0xF0;
4733 /* Set host adapter parameters. */
4734 ha->flags.disable_risc_code_load = 0;
4735 ha->flags.enable_lip_reset = 0;
4736 ha->flags.enable_lip_full_login =
4737 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4738 ha->flags.enable_target_reset =
4739 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4740 ha->flags.enable_led_scheme = 0;
4741 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4743 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4744 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4746 /* save HBA serial number */
4747 ha->serial0 = icb->port_name[5];
4748 ha->serial1 = icb->port_name[6];
4749 ha->serial2 = icb->port_name[7];
4750 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4751 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4753 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4755 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4757 /* Set minimum login_timeout to 4 seconds. */
4758 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4759 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4760 if (le16_to_cpu(nv->login_timeout) < 4)
4761 nv->login_timeout = __constant_cpu_to_le16(4);
4762 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4763 icb->login_timeout = nv->login_timeout;
4765 /* Set minimum RATOV to 100 tenths of a second. */
4768 ha->loop_reset_delay = nv->reset_delay;
4770 /* Link Down Timeout = 0:
4772 * When Port Down timer expires we will start returning
4773 * I/O's to OS with "DID_NO_CONNECT".
4775 * Link Down Timeout != 0:
4777 * The driver waits for the link to come up after link down
4778 * before returning I/Os to OS with "DID_NO_CONNECT".
4780 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4781 ha->loop_down_abort_time =
4782 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4784 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4785 ha->loop_down_abort_time =
4786 (LOOP_DOWN_TIME - ha->link_down_timeout);
4789 /* Need enough time to try and get the port back. */
4790 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4791 if (qlport_down_retry)
4792 ha->port_down_retry_count = qlport_down_retry;
4794 /* Set login_retry_count */
4795 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4796 if (ha->port_down_retry_count ==
4797 le16_to_cpu(nv->port_down_retry_count) &&
4798 ha->port_down_retry_count > 3)
4799 ha->login_retry_count = ha->port_down_retry_count;
4800 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4801 ha->login_retry_count = ha->port_down_retry_count;
4802 if (ql2xloginretrycount)
4803 ha->login_retry_count = ql2xloginretrycount;
4806 if (!vha->flags.init_done) {
4807 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4808 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4809 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4810 le16_to_cpu(icb->interrupt_delay_timer): 2;
4812 icb->firmware_options_2 &= __constant_cpu_to_le32(
4813 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4814 vha->flags.process_response_queue = 0;
4815 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4816 ha->zio_mode = QLA_ZIO_MODE_6;
4818 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4819 "(%d us).\n", vha->host_no, ha->zio_mode,
4820 ha->zio_timer * 100));
4821 qla_printk(KERN_INFO, ha,
4822 "ZIO mode %d enabled; timer delay (%d us).\n",
4823 ha->zio_mode, ha->zio_timer * 100);
4825 icb->firmware_options_2 |= cpu_to_le32(
4826 (uint32_t)ha->zio_mode);
4827 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4828 vha->flags.process_response_queue = 1;
4832 DEBUG2_3(printk(KERN_WARNING
4833 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4839 qla81xx_update_fw_options(scsi_qla_host_t *ha)