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 /****************************************************************************/
44 /* QLogic ISP2x00 Hardware Support Functions. */
45 /****************************************************************************/
48 * qla2x00_initialize_adapter
52 * ha = adapter block pointer.
58 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
61 struct qla_hw_data *ha = vha->hw;
62 struct req_que *req = ha->req_q_map[0];
64 /* Clear adapter flags. */
65 vha->flags.online = 0;
66 ha->flags.chip_reset_done = 0;
67 vha->flags.reset_active = 0;
68 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
69 atomic_set(&vha->loop_state, LOOP_DOWN);
70 vha->device_flags = DFLG_NO_CABLE;
72 vha->flags.management_server_logged_in = 0;
73 vha->marker_needed = 0;
74 ha->isp_abort_cnt = 0;
75 ha->beacon_blink_led = 0;
76 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
78 set_bit(0, ha->req_qid_map);
79 set_bit(0, ha->rsp_qid_map);
81 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
82 rval = ha->isp_ops->pci_config(vha);
84 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
89 ha->isp_ops->reset_chip(vha);
91 rval = qla2xxx_get_flash_info(vha);
93 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
98 ha->isp_ops->get_flash_version(vha, req->ring);
100 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
102 ha->isp_ops->nvram_config(vha);
104 if (ha->flags.disable_serdes) {
105 /* Mask HBA via NVRAM settings? */
106 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
107 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
108 vha->port_name[0], vha->port_name[1],
109 vha->port_name[2], vha->port_name[3],
110 vha->port_name[4], vha->port_name[5],
111 vha->port_name[6], vha->port_name[7]);
112 return QLA_FUNCTION_FAILED;
115 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
117 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
118 rval = ha->isp_ops->chip_diag(vha);
121 rval = qla2x00_setup_chip(vha);
125 if (IS_QLA84XX(ha)) {
126 ha->cs84xx = qla84xx_get_chip(vha);
128 qla_printk(KERN_ERR, ha,
129 "Unable to configure ISP84XX.\n");
130 return QLA_FUNCTION_FAILED;
133 rval = qla2x00_init_rings(vha);
134 ha->flags.chip_reset_done = 1;
140 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
143 * Returns 0 on success.
146 qla2100_pci_config(scsi_qla_host_t *vha)
150 struct qla_hw_data *ha = vha->hw;
151 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
153 pci_set_master(ha->pdev);
154 pci_try_set_mwi(ha->pdev);
156 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
157 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
158 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
160 pci_disable_rom(ha->pdev);
162 /* Get PCI bus information. */
163 spin_lock_irqsave(&ha->hardware_lock, flags);
164 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
165 spin_unlock_irqrestore(&ha->hardware_lock, flags);
171 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
174 * Returns 0 on success.
177 qla2300_pci_config(scsi_qla_host_t *vha)
180 unsigned long flags = 0;
182 struct qla_hw_data *ha = vha->hw;
183 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
185 pci_set_master(ha->pdev);
186 pci_try_set_mwi(ha->pdev);
188 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
189 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
191 if (IS_QLA2322(ha) || IS_QLA6322(ha))
192 w &= ~PCI_COMMAND_INTX_DISABLE;
193 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
196 * If this is a 2300 card and not 2312, reset the
197 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
198 * the 2310 also reports itself as a 2300 so we need to get the
199 * fb revision level -- a 6 indicates it really is a 2300 and
202 if (IS_QLA2300(ha)) {
203 spin_lock_irqsave(&ha->hardware_lock, flags);
206 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
207 for (cnt = 0; cnt < 30000; cnt++) {
208 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
214 /* Select FPM registers. */
215 WRT_REG_WORD(®->ctrl_status, 0x20);
216 RD_REG_WORD(®->ctrl_status);
218 /* Get the fb rev level */
219 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
221 if (ha->fb_rev == FPM_2300)
222 pci_clear_mwi(ha->pdev);
224 /* Deselect FPM registers. */
225 WRT_REG_WORD(®->ctrl_status, 0x0);
226 RD_REG_WORD(®->ctrl_status);
228 /* Release RISC module. */
229 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
230 for (cnt = 0; cnt < 30000; cnt++) {
231 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
237 spin_unlock_irqrestore(&ha->hardware_lock, flags);
240 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
242 pci_disable_rom(ha->pdev);
244 /* Get PCI bus information. */
245 spin_lock_irqsave(&ha->hardware_lock, flags);
246 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
247 spin_unlock_irqrestore(&ha->hardware_lock, flags);
253 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
256 * Returns 0 on success.
259 qla24xx_pci_config(scsi_qla_host_t *vha)
262 unsigned long flags = 0;
263 struct qla_hw_data *ha = vha->hw;
264 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
266 pci_set_master(ha->pdev);
267 pci_try_set_mwi(ha->pdev);
269 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
270 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
271 w &= ~PCI_COMMAND_INTX_DISABLE;
272 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
274 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
276 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
277 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
278 pcix_set_mmrbc(ha->pdev, 2048);
280 /* PCIe -- adjust Maximum Read Request Size (2048). */
281 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
282 pcie_set_readrq(ha->pdev, 2048);
284 pci_disable_rom(ha->pdev);
286 ha->chip_revision = ha->pdev->revision;
288 /* Get PCI bus information. */
289 spin_lock_irqsave(&ha->hardware_lock, flags);
290 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
291 spin_unlock_irqrestore(&ha->hardware_lock, flags);
297 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
300 * Returns 0 on success.
303 qla25xx_pci_config(scsi_qla_host_t *vha)
306 struct qla_hw_data *ha = vha->hw;
308 pci_set_master(ha->pdev);
309 pci_try_set_mwi(ha->pdev);
311 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
312 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
313 w &= ~PCI_COMMAND_INTX_DISABLE;
314 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
316 /* PCIe -- adjust Maximum Read Request Size (2048). */
317 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
318 pcie_set_readrq(ha->pdev, 2048);
320 pci_disable_rom(ha->pdev);
322 ha->chip_revision = ha->pdev->revision;
328 * qla2x00_isp_firmware() - Choose firmware image.
331 * Returns 0 on success.
334 qla2x00_isp_firmware(scsi_qla_host_t *vha)
337 uint16_t loop_id, topo, sw_cap;
338 uint8_t domain, area, al_pa;
339 struct qla_hw_data *ha = vha->hw;
341 /* Assume loading risc code */
342 rval = QLA_FUNCTION_FAILED;
344 if (ha->flags.disable_risc_code_load) {
345 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
347 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
349 /* Verify checksum of loaded RISC code. */
350 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
351 if (rval == QLA_SUCCESS) {
352 /* And, verify we are not in ROM code. */
353 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
354 &area, &domain, &topo, &sw_cap);
359 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
367 * qla2x00_reset_chip() - Reset ISP chip.
370 * Returns 0 on success.
373 qla2x00_reset_chip(scsi_qla_host_t *vha)
375 unsigned long flags = 0;
376 struct qla_hw_data *ha = vha->hw;
377 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
381 ha->isp_ops->disable_intrs(ha);
383 spin_lock_irqsave(&ha->hardware_lock, flags);
385 /* Turn off master enable */
387 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
388 cmd &= ~PCI_COMMAND_MASTER;
389 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
391 if (!IS_QLA2100(ha)) {
393 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
394 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
395 for (cnt = 0; cnt < 30000; cnt++) {
396 if ((RD_REG_WORD(®->hccr) &
397 HCCR_RISC_PAUSE) != 0)
402 RD_REG_WORD(®->hccr); /* PCI Posting. */
406 /* Select FPM registers. */
407 WRT_REG_WORD(®->ctrl_status, 0x20);
408 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
410 /* FPM Soft Reset. */
411 WRT_REG_WORD(®->fpm_diag_config, 0x100);
412 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
414 /* Toggle Fpm Reset. */
415 if (!IS_QLA2200(ha)) {
416 WRT_REG_WORD(®->fpm_diag_config, 0x0);
417 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
420 /* Select frame buffer registers. */
421 WRT_REG_WORD(®->ctrl_status, 0x10);
422 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
424 /* Reset frame buffer FIFOs. */
425 if (IS_QLA2200(ha)) {
426 WRT_FB_CMD_REG(ha, reg, 0xa000);
427 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
429 WRT_FB_CMD_REG(ha, reg, 0x00fc);
431 /* Read back fb_cmd until zero or 3 seconds max */
432 for (cnt = 0; cnt < 3000; cnt++) {
433 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
439 /* Select RISC module registers. */
440 WRT_REG_WORD(®->ctrl_status, 0);
441 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
443 /* Reset RISC processor. */
444 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
445 RD_REG_WORD(®->hccr); /* PCI Posting. */
447 /* Release RISC processor. */
448 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
449 RD_REG_WORD(®->hccr); /* PCI Posting. */
452 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
453 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
455 /* Reset ISP chip. */
456 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
458 /* Wait for RISC to recover from reset. */
459 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
461 * It is necessary to for a delay here since the card doesn't
462 * respond to PCI reads during a reset. On some architectures
463 * this will result in an MCA.
466 for (cnt = 30000; cnt; cnt--) {
467 if ((RD_REG_WORD(®->ctrl_status) &
468 CSR_ISP_SOFT_RESET) == 0)
475 /* Reset RISC processor. */
476 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
478 WRT_REG_WORD(®->semaphore, 0);
480 /* Release RISC processor. */
481 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
482 RD_REG_WORD(®->hccr); /* PCI Posting. */
484 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
485 for (cnt = 0; cnt < 30000; cnt++) {
486 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
494 /* Turn on master enable */
495 cmd |= PCI_COMMAND_MASTER;
496 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
498 /* Disable RISC pause on FPM parity error. */
499 if (!IS_QLA2100(ha)) {
500 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
501 RD_REG_WORD(®->hccr); /* PCI Posting. */
504 spin_unlock_irqrestore(&ha->hardware_lock, flags);
508 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
511 * Returns 0 on success.
514 qla24xx_reset_risc(scsi_qla_host_t *vha)
516 unsigned long flags = 0;
517 struct qla_hw_data *ha = vha->hw;
518 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
522 spin_lock_irqsave(&ha->hardware_lock, flags);
525 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
526 for (cnt = 0; cnt < 30000; cnt++) {
527 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
533 WRT_REG_DWORD(®->ctrl_status,
534 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
535 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
538 /* Wait for firmware to complete NVRAM accesses. */
539 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
540 for (cnt = 10000 ; cnt && d2; cnt--) {
542 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
546 /* Wait for soft-reset to complete. */
547 d2 = RD_REG_DWORD(®->ctrl_status);
548 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
550 d2 = RD_REG_DWORD(®->ctrl_status);
554 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
555 RD_REG_DWORD(®->hccr);
557 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
558 RD_REG_DWORD(®->hccr);
560 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
561 RD_REG_DWORD(®->hccr);
563 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
564 for (cnt = 6000000 ; cnt && d2; cnt--) {
566 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
570 spin_unlock_irqrestore(&ha->hardware_lock, flags);
572 if (IS_NOPOLLING_TYPE(ha))
573 ha->isp_ops->enable_intrs(ha);
577 * qla24xx_reset_chip() - Reset ISP24xx chip.
580 * Returns 0 on success.
583 qla24xx_reset_chip(scsi_qla_host_t *vha)
585 struct qla_hw_data *ha = vha->hw;
586 ha->isp_ops->disable_intrs(ha);
588 /* Perform RISC reset. */
589 qla24xx_reset_risc(vha);
593 * qla2x00_chip_diag() - Test chip for proper operation.
596 * Returns 0 on success.
599 qla2x00_chip_diag(scsi_qla_host_t *vha)
602 struct qla_hw_data *ha = vha->hw;
603 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
604 unsigned long flags = 0;
608 struct req_que *req = ha->req_q_map[0];
610 /* Assume a failed state */
611 rval = QLA_FUNCTION_FAILED;
613 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
614 vha->host_no, (u_long)®->flash_address));
616 spin_lock_irqsave(&ha->hardware_lock, flags);
618 /* Reset ISP chip. */
619 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
622 * We need to have a delay here since the card will not respond while
623 * in reset causing an MCA on some architectures.
626 data = qla2x00_debounce_register(®->ctrl_status);
627 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
629 data = RD_REG_WORD(®->ctrl_status);
634 goto chip_diag_failed;
636 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
639 /* Reset RISC processor. */
640 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
641 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
643 /* Workaround for QLA2312 PCI parity error */
644 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
645 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
646 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
648 data = RD_MAILBOX_REG(ha, reg, 0);
655 goto chip_diag_failed;
657 /* Check product ID of chip */
658 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
660 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
661 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
662 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
663 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
664 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
665 mb[3] != PROD_ID_3) {
666 qla_printk(KERN_WARNING, ha,
667 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
669 goto chip_diag_failed;
671 ha->product_id[0] = mb[1];
672 ha->product_id[1] = mb[2];
673 ha->product_id[2] = mb[3];
674 ha->product_id[3] = mb[4];
676 /* Adjust fw RISC transfer size */
677 if (req->length > 1024)
678 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
680 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
683 if (IS_QLA2200(ha) &&
684 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
685 /* Limit firmware transfer size with a 2200A */
686 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
689 ha->device_type |= DT_ISP2200A;
690 ha->fw_transfer_size = 128;
693 /* Wrap Incoming Mailboxes Test. */
694 spin_unlock_irqrestore(&ha->hardware_lock, flags);
696 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
697 rval = qla2x00_mbx_reg_test(vha);
699 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
701 qla_printk(KERN_WARNING, ha,
702 "Failed mailbox send register test\n");
705 /* Flag a successful rval */
708 spin_lock_irqsave(&ha->hardware_lock, flags);
712 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
713 "****\n", vha->host_no));
715 spin_unlock_irqrestore(&ha->hardware_lock, flags);
721 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
724 * Returns 0 on success.
727 qla24xx_chip_diag(scsi_qla_host_t *vha)
730 struct qla_hw_data *ha = vha->hw;
731 struct req_que *req = ha->req_q_map[0];
733 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
735 rval = qla2x00_mbx_reg_test(vha);
737 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
739 qla_printk(KERN_WARNING, ha,
740 "Failed mailbox send register test\n");
742 /* Flag a successful rval */
750 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
753 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
754 eft_size, fce_size, mq_size;
757 struct qla_hw_data *ha = vha->hw;
758 struct req_que *req = ha->req_q_map[0];
759 struct rsp_que *rsp = ha->rsp_q_map[0];
762 qla_printk(KERN_WARNING, ha,
763 "Firmware dump previously allocated.\n");
768 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
769 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
770 fixed_size = sizeof(struct qla2100_fw_dump);
771 } else if (IS_QLA23XX(ha)) {
772 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
773 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
775 } else if (IS_FWI2_CAPABLE(ha)) {
777 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
778 else if (IS_QLA25XX(ha))
779 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
781 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
782 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
785 mq_size = sizeof(struct qla2xxx_mq_chain);
786 /* Allocate memory for Fibre Channel Event Buffer. */
787 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
790 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
793 qla_printk(KERN_WARNING, ha, "Unable to allocate "
794 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
798 memset(tc, 0, FCE_SIZE);
799 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
800 ha->fce_mb, &ha->fce_bufs);
802 qla_printk(KERN_WARNING, ha, "Unable to initialize "
803 "FCE (%d).\n", rval);
804 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
806 ha->flags.fce_enabled = 0;
810 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
813 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
814 ha->flags.fce_enabled = 1;
815 ha->fce_dma = tc_dma;
818 /* Allocate memory for Extended Trace Buffer. */
819 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
822 qla_printk(KERN_WARNING, ha, "Unable to allocate "
823 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
827 memset(tc, 0, EFT_SIZE);
828 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
830 qla_printk(KERN_WARNING, ha, "Unable to initialize "
831 "EFT (%d).\n", rval);
832 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
837 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
841 ha->eft_dma = tc_dma;
845 req_q_size = req->length * sizeof(request_t);
846 rsp_q_size = rsp->length * sizeof(response_t);
848 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
849 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
850 ha->chain_offset = dump_size;
851 dump_size += mq_size + fce_size;
853 ha->fw_dump = vmalloc(dump_size);
855 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
856 "firmware dump!!!\n", dump_size / 1024);
859 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
866 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
869 ha->fw_dump_len = dump_size;
870 ha->fw_dump->signature[0] = 'Q';
871 ha->fw_dump->signature[1] = 'L';
872 ha->fw_dump->signature[2] = 'G';
873 ha->fw_dump->signature[3] = 'C';
874 ha->fw_dump->version = __constant_htonl(1);
876 ha->fw_dump->fixed_size = htonl(fixed_size);
877 ha->fw_dump->mem_size = htonl(mem_size);
878 ha->fw_dump->req_q_size = htonl(req_q_size);
879 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
881 ha->fw_dump->eft_size = htonl(eft_size);
882 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
883 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
885 ha->fw_dump->header_size =
886 htonl(offsetof(struct qla2xxx_fw_dump, isp));
890 * qla2x00_setup_chip() - Load and start RISC firmware.
893 * Returns 0 on success.
896 qla2x00_setup_chip(scsi_qla_host_t *vha)
899 uint32_t srisc_address = 0;
900 struct qla_hw_data *ha = vha->hw;
901 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
903 uint16_t fw_major_version;
905 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
906 /* Disable SRAM, Instruction RAM and GP RAM parity. */
907 spin_lock_irqsave(&ha->hardware_lock, flags);
908 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
909 RD_REG_WORD(®->hccr);
910 spin_unlock_irqrestore(&ha->hardware_lock, flags);
913 /* Load firmware sequences */
914 rval = ha->isp_ops->load_risc(vha, &srisc_address);
915 if (rval == QLA_SUCCESS) {
916 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
917 "code.\n", vha->host_no));
919 rval = qla2x00_verify_checksum(vha, srisc_address);
920 if (rval == QLA_SUCCESS) {
921 /* Start firmware execution. */
922 DEBUG(printk("scsi(%ld): Checksum OK, start "
923 "firmware.\n", vha->host_no));
925 rval = qla2x00_execute_fw(vha, srisc_address);
926 /* Retrieve firmware information. */
927 if (rval == QLA_SUCCESS) {
928 fw_major_version = ha->fw_major_version;
929 rval = qla2x00_get_fw_version(vha,
930 &ha->fw_major_version,
931 &ha->fw_minor_version,
932 &ha->fw_subminor_version,
933 &ha->fw_attributes, &ha->fw_memory_size,
934 ha->mpi_version, &ha->mpi_capabilities,
936 if (rval != QLA_SUCCESS)
939 ha->flags.npiv_supported = 0;
940 if (IS_QLA2XXX_MIDTYPE(ha) &&
941 (ha->fw_attributes & BIT_2)) {
942 ha->flags.npiv_supported = 1;
943 if ((!ha->max_npiv_vports) ||
944 ((ha->max_npiv_vports + 1) %
945 MIN_MULTI_ID_FABRIC))
946 ha->max_npiv_vports =
947 MIN_MULTI_ID_FABRIC - 1;
949 qla2x00_get_resource_cnts(vha, NULL,
950 &ha->fw_xcb_count, NULL, NULL,
951 &ha->max_npiv_vports);
953 if (!fw_major_version && ql2xallocfwdump)
954 qla2x00_alloc_fw_dump(vha);
957 DEBUG2(printk(KERN_INFO
958 "scsi(%ld): ISP Firmware failed checksum.\n",
963 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
964 /* Enable proper parity. */
965 spin_lock_irqsave(&ha->hardware_lock, flags);
968 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
970 /* SRAM, Instruction RAM and GP RAM parity */
971 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
972 RD_REG_WORD(®->hccr);
973 spin_unlock_irqrestore(&ha->hardware_lock, flags);
976 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
979 rval = qla81xx_fac_get_sector_size(vha, &size);
980 if (rval == QLA_SUCCESS) {
981 ha->flags.fac_supported = 1;
982 ha->fdt_block_size = size << 2;
984 qla_printk(KERN_ERR, ha,
985 "Unsupported FAC firmware (%d.%02d.%02d).\n",
986 ha->fw_major_version, ha->fw_minor_version,
987 ha->fw_subminor_version);
992 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
1000 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1003 * Beginning of request ring has initialization control block already built
1004 * by nvram config routine.
1006 * Returns 0 on success.
1009 qla2x00_init_response_q_entries(struct rsp_que *rsp)
1014 rsp->ring_ptr = rsp->ring;
1015 rsp->ring_index = 0;
1016 rsp->status_srb = NULL;
1017 pkt = rsp->ring_ptr;
1018 for (cnt = 0; cnt < rsp->length; cnt++) {
1019 pkt->signature = RESPONSE_PROCESSED;
1025 * qla2x00_update_fw_options() - Read and process firmware options.
1028 * Returns 0 on success.
1031 qla2x00_update_fw_options(scsi_qla_host_t *vha)
1033 uint16_t swing, emphasis, tx_sens, rx_sens;
1034 struct qla_hw_data *ha = vha->hw;
1036 memset(ha->fw_options, 0, sizeof(ha->fw_options));
1037 qla2x00_get_fw_options(vha, ha->fw_options);
1039 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1042 /* Serial Link options. */
1043 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1045 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1046 sizeof(ha->fw_seriallink_options)));
1048 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1049 if (ha->fw_seriallink_options[3] & BIT_2) {
1050 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1053 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1054 emphasis = (ha->fw_seriallink_options[2] &
1055 (BIT_4 | BIT_3)) >> 3;
1056 tx_sens = ha->fw_seriallink_options[0] &
1057 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1058 rx_sens = (ha->fw_seriallink_options[0] &
1059 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1060 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1061 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1064 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1065 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1066 ha->fw_options[10] |= BIT_5 |
1067 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1068 (tx_sens & (BIT_1 | BIT_0));
1071 swing = (ha->fw_seriallink_options[2] &
1072 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1073 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1074 tx_sens = ha->fw_seriallink_options[1] &
1075 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1076 rx_sens = (ha->fw_seriallink_options[1] &
1077 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1078 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1079 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1082 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1083 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1084 ha->fw_options[11] |= BIT_5 |
1085 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1086 (tx_sens & (BIT_1 | BIT_0));
1090 /* Return command IOCBs without waiting for an ABTS to complete. */
1091 ha->fw_options[3] |= BIT_13;
1094 if (ha->flags.enable_led_scheme)
1095 ha->fw_options[2] |= BIT_12;
1097 /* Detect ISP6312. */
1099 ha->fw_options[2] |= BIT_13;
1101 /* Update firmware options. */
1102 qla2x00_set_fw_options(vha, ha->fw_options);
1106 qla24xx_update_fw_options(scsi_qla_host_t *vha)
1109 struct qla_hw_data *ha = vha->hw;
1111 /* Update Serial Link options. */
1112 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1115 rval = qla2x00_set_serdes_params(vha,
1116 le16_to_cpu(ha->fw_seriallink_options24[1]),
1117 le16_to_cpu(ha->fw_seriallink_options24[2]),
1118 le16_to_cpu(ha->fw_seriallink_options24[3]));
1119 if (rval != QLA_SUCCESS) {
1120 qla_printk(KERN_WARNING, ha,
1121 "Unable to update Serial Link options (%x).\n", rval);
1126 qla2x00_config_rings(struct scsi_qla_host *vha)
1128 struct qla_hw_data *ha = vha->hw;
1129 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1130 struct req_que *req = ha->req_q_map[0];
1131 struct rsp_que *rsp = ha->rsp_q_map[0];
1133 /* Setup ring parameters in initialization control block. */
1134 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1135 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1136 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1137 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1138 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1139 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1140 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1141 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
1143 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1144 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1145 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1146 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1147 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1151 qla24xx_config_rings(struct scsi_qla_host *vha)
1153 struct qla_hw_data *ha = vha->hw;
1154 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1155 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1156 struct qla_msix_entry *msix;
1157 struct init_cb_24xx *icb;
1159 struct req_que *req = ha->req_q_map[0];
1160 struct rsp_que *rsp = ha->rsp_q_map[0];
1162 /* Setup ring parameters in initialization control block. */
1163 icb = (struct init_cb_24xx *)ha->init_cb;
1164 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1165 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1166 icb->request_q_length = cpu_to_le16(req->length);
1167 icb->response_q_length = cpu_to_le16(rsp->length);
1168 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1169 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1170 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1171 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
1174 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1175 icb->rid = __constant_cpu_to_le16(rid);
1176 if (ha->flags.msix_enabled) {
1177 msix = &ha->msix_entries[1];
1178 DEBUG2_17(printk(KERN_INFO
1179 "Registering vector 0x%x for base que\n", msix->entry));
1180 icb->msix = cpu_to_le16(msix->entry);
1182 /* Use alternate PCI bus number */
1184 icb->firmware_options_2 |=
1185 __constant_cpu_to_le32(BIT_19);
1186 /* Use alternate PCI devfn */
1188 icb->firmware_options_2 |=
1189 __constant_cpu_to_le32(BIT_18);
1191 icb->firmware_options_2 &= __constant_cpu_to_le32(~BIT_22);
1192 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
1194 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
1195 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
1196 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
1197 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
1199 WRT_REG_DWORD(®->isp24.req_q_in, 0);
1200 WRT_REG_DWORD(®->isp24.req_q_out, 0);
1201 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
1202 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
1205 RD_REG_DWORD(&ioreg->hccr);
1209 * qla2x00_init_rings() - Initializes firmware.
1212 * Beginning of request ring has initialization control block already built
1213 * by nvram config routine.
1215 * Returns 0 on success.
1218 qla2x00_init_rings(scsi_qla_host_t *vha)
1221 unsigned long flags = 0;
1223 struct qla_hw_data *ha = vha->hw;
1224 struct req_que *req;
1225 struct rsp_que *rsp;
1226 struct scsi_qla_host *vp;
1227 struct mid_init_cb_24xx *mid_init_cb =
1228 (struct mid_init_cb_24xx *) ha->init_cb;
1230 spin_lock_irqsave(&ha->hardware_lock, flags);
1232 /* Clear outstanding commands array. */
1233 for (que = 0; que < ha->max_req_queues; que++) {
1234 req = ha->req_q_map[que];
1237 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1238 req->outstanding_cmds[cnt] = NULL;
1240 req->current_outstanding_cmd = 1;
1242 /* Initialize firmware. */
1243 req->ring_ptr = req->ring;
1244 req->ring_index = 0;
1245 req->cnt = req->length;
1248 for (que = 0; que < ha->max_rsp_queues; que++) {
1249 rsp = ha->rsp_q_map[que];
1252 /* Initialize response queue entries */
1253 qla2x00_init_response_q_entries(rsp);
1256 /* Clear RSCN queue. */
1257 list_for_each_entry(vp, &ha->vp_list, list) {
1258 vp->rscn_in_ptr = 0;
1259 vp->rscn_out_ptr = 0;
1261 ha->isp_ops->config_rings(vha);
1263 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1265 /* Update any ISP specific firmware options before initialization. */
1266 ha->isp_ops->update_fw_options(vha);
1268 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
1270 if (ha->flags.npiv_supported) {
1271 if (ha->operating_mode == LOOP)
1272 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
1273 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1276 if (IS_FWI2_CAPABLE(ha)) {
1277 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1278 mid_init_cb->init_cb.execution_throttle =
1279 cpu_to_le16(ha->fw_xcb_count);
1282 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
1284 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1287 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1295 * qla2x00_fw_ready() - Waits for firmware ready.
1298 * Returns 0 on success.
1301 qla2x00_fw_ready(scsi_qla_host_t *vha)
1304 unsigned long wtime, mtime, cs84xx_time;
1305 uint16_t min_wait; /* Minimum wait time if loop is down */
1306 uint16_t wait_time; /* Wait time if loop is coming ready */
1308 struct qla_hw_data *ha = vha->hw;
1312 /* 20 seconds for loop down. */
1316 * Firmware should take at most one RATOV to login, plus 5 seconds for
1317 * our own processing.
1319 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1320 wait_time = min_wait;
1323 /* Min wait time if loop down */
1324 mtime = jiffies + (min_wait * HZ);
1326 /* wait time before firmware ready */
1327 wtime = jiffies + (wait_time * HZ);
1329 /* Wait for ISP to finish LIP */
1330 if (!vha->flags.init_done)
1331 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1333 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1337 rval = qla2x00_get_firmware_state(vha, state);
1338 if (rval == QLA_SUCCESS) {
1339 if (state[0] < FSTATE_LOSS_OF_SYNC) {
1340 vha->device_flags &= ~DFLG_NO_CABLE;
1342 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1343 DEBUG16(printk("scsi(%ld): fw_state=%x "
1344 "84xx=%x.\n", vha->host_no, state[0],
1346 if ((state[2] & FSTATE_LOGGED_IN) &&
1347 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1348 DEBUG16(printk("scsi(%ld): Sending "
1349 "verify iocb.\n", vha->host_no));
1351 cs84xx_time = jiffies;
1352 rval = qla84xx_init_chip(vha);
1353 if (rval != QLA_SUCCESS)
1356 /* Add time taken to initialize. */
1357 cs84xx_time = jiffies - cs84xx_time;
1358 wtime += cs84xx_time;
1359 mtime += cs84xx_time;
1360 DEBUG16(printk("scsi(%ld): Increasing "
1361 "wait time by %ld. New time %ld\n",
1362 vha->host_no, cs84xx_time, wtime));
1364 } else if (state[0] == FSTATE_READY) {
1365 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1368 qla2x00_get_retry_cnt(vha, &ha->retry_count,
1369 &ha->login_timeout, &ha->r_a_tov);
1375 rval = QLA_FUNCTION_FAILED;
1377 if (atomic_read(&vha->loop_down_timer) &&
1378 state[0] != FSTATE_READY) {
1379 /* Loop down. Timeout on min_wait for states
1380 * other than Wait for Login.
1382 if (time_after_eq(jiffies, mtime)) {
1383 qla_printk(KERN_INFO, ha,
1384 "Cable is unplugged...\n");
1386 vha->device_flags |= DFLG_NO_CABLE;
1391 /* Mailbox cmd failed. Timeout on min_wait. */
1392 if (time_after_eq(jiffies, mtime))
1396 if (time_after_eq(jiffies, wtime))
1399 /* Delay for a while */
1402 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1403 vha->host_no, state[0], jiffies));
1406 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1407 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1411 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1419 * qla2x00_configure_hba
1420 * Setup adapter context.
1423 * ha = adapter state pointer.
1432 qla2x00_configure_hba(scsi_qla_host_t *vha)
1441 char connect_type[22];
1442 struct qla_hw_data *ha = vha->hw;
1444 /* Get host addresses. */
1445 rval = qla2x00_get_adapter_id(vha,
1446 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
1447 if (rval != QLA_SUCCESS) {
1448 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
1449 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1450 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1451 __func__, vha->host_no));
1453 qla_printk(KERN_WARNING, ha,
1454 "ERROR -- Unable to get host loop ID.\n");
1455 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1461 qla_printk(KERN_INFO, ha,
1462 "Cannot get topology - retrying.\n");
1463 return (QLA_FUNCTION_FAILED);
1466 vha->loop_id = loop_id;
1469 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1470 ha->operating_mode = LOOP;
1475 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1477 ha->current_topology = ISP_CFG_NL;
1478 strcpy(connect_type, "(Loop)");
1482 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1484 ha->switch_cap = sw_cap;
1485 ha->current_topology = ISP_CFG_FL;
1486 strcpy(connect_type, "(FL_Port)");
1490 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1492 ha->operating_mode = P2P;
1493 ha->current_topology = ISP_CFG_N;
1494 strcpy(connect_type, "(N_Port-to-N_Port)");
1498 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1500 ha->switch_cap = sw_cap;
1501 ha->operating_mode = P2P;
1502 ha->current_topology = ISP_CFG_F;
1503 strcpy(connect_type, "(F_Port)");
1507 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1509 vha->host_no, topo));
1510 ha->current_topology = ISP_CFG_NL;
1511 strcpy(connect_type, "(Loop)");
1515 /* Save Host port and loop ID. */
1516 /* byte order - Big Endian */
1517 vha->d_id.b.domain = domain;
1518 vha->d_id.b.area = area;
1519 vha->d_id.b.al_pa = al_pa;
1521 if (!vha->flags.init_done)
1522 qla_printk(KERN_INFO, ha,
1523 "Topology - %s, Host Loop address 0x%x\n",
1524 connect_type, vha->loop_id);
1527 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
1529 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
1536 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1541 struct qla_hw_data *ha = vha->hw;
1542 int use_tbl = !IS_QLA25XX(ha) && !IS_QLA81XX(ha);
1544 if (memcmp(model, BINZERO, len) != 0) {
1545 strncpy(ha->model_number, model, len);
1546 st = en = ha->model_number;
1549 if (*en != 0x20 && *en != 0x00)
1554 index = (ha->pdev->subsystem_device & 0xff);
1556 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1557 index < QLA_MODEL_NAMES)
1558 strncpy(ha->model_desc,
1559 qla2x00_model_name[index * 2 + 1],
1560 sizeof(ha->model_desc) - 1);
1562 index = (ha->pdev->subsystem_device & 0xff);
1564 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1565 index < QLA_MODEL_NAMES) {
1566 strcpy(ha->model_number,
1567 qla2x00_model_name[index * 2]);
1568 strncpy(ha->model_desc,
1569 qla2x00_model_name[index * 2 + 1],
1570 sizeof(ha->model_desc) - 1);
1572 strcpy(ha->model_number, def);
1575 if (IS_FWI2_CAPABLE(ha))
1576 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
1577 sizeof(ha->model_desc));
1580 /* On sparc systems, obtain port and node WWN from firmware
1583 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
1586 struct qla_hw_data *ha = vha->hw;
1587 struct pci_dev *pdev = ha->pdev;
1588 struct device_node *dp = pci_device_to_OF_node(pdev);
1592 val = of_get_property(dp, "port-wwn", &len);
1593 if (val && len >= WWN_SIZE)
1594 memcpy(nv->port_name, val, WWN_SIZE);
1596 val = of_get_property(dp, "node-wwn", &len);
1597 if (val && len >= WWN_SIZE)
1598 memcpy(nv->node_name, val, WWN_SIZE);
1603 * NVRAM configuration for ISP 2xxx
1606 * ha = adapter block pointer.
1609 * initialization control block in response_ring
1610 * host adapters parameters in host adapter block
1616 qla2x00_nvram_config(scsi_qla_host_t *vha)
1621 uint8_t *dptr1, *dptr2;
1622 struct qla_hw_data *ha = vha->hw;
1623 init_cb_t *icb = ha->init_cb;
1624 nvram_t *nv = ha->nvram;
1625 uint8_t *ptr = ha->nvram;
1626 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1630 /* Determine NVRAM starting address. */
1631 ha->nvram_size = sizeof(nvram_t);
1633 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1634 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1635 ha->nvram_base = 0x80;
1637 /* Get NVRAM data and calculate checksum. */
1638 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
1639 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1642 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
1643 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
1645 /* Bad NVRAM data, set defaults parameters. */
1646 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1647 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1648 /* Reset NVRAM data. */
1649 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1650 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1652 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1653 "invalid -- WWPN) defaults.\n");
1656 * Set default initialization control block.
1658 memset(nv, 0, ha->nvram_size);
1659 nv->parameter_block_version = ICB_VERSION;
1661 if (IS_QLA23XX(ha)) {
1662 nv->firmware_options[0] = BIT_2 | BIT_1;
1663 nv->firmware_options[1] = BIT_7 | BIT_5;
1664 nv->add_firmware_options[0] = BIT_5;
1665 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1666 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1667 nv->special_options[1] = BIT_7;
1668 } else if (IS_QLA2200(ha)) {
1669 nv->firmware_options[0] = BIT_2 | BIT_1;
1670 nv->firmware_options[1] = BIT_7 | BIT_5;
1671 nv->add_firmware_options[0] = BIT_5;
1672 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1673 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1674 } else if (IS_QLA2100(ha)) {
1675 nv->firmware_options[0] = BIT_3 | BIT_1;
1676 nv->firmware_options[1] = BIT_5;
1677 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1680 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1681 nv->execution_throttle = __constant_cpu_to_le16(16);
1682 nv->retry_count = 8;
1683 nv->retry_delay = 1;
1685 nv->port_name[0] = 33;
1686 nv->port_name[3] = 224;
1687 nv->port_name[4] = 139;
1689 qla2xxx_nvram_wwn_from_ofw(vha, nv);
1691 nv->login_timeout = 4;
1694 * Set default host adapter parameters
1696 nv->host_p[1] = BIT_2;
1697 nv->reset_delay = 5;
1698 nv->port_down_retry_count = 8;
1699 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1700 nv->link_down_timeout = 60;
1705 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1707 * The SN2 does not provide BIOS emulation which means you can't change
1708 * potentially bogus BIOS settings. Force the use of default settings
1709 * for link rate and frame size. Hope that the rest of the settings
1712 if (ia64_platform_is("sn2")) {
1713 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1715 nv->special_options[1] = BIT_7;
1719 /* Reset Initialization control block */
1720 memset(icb, 0, ha->init_cb_size);
1723 * Setup driver NVRAM options.
1725 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1726 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1727 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1728 nv->firmware_options[1] &= ~BIT_4;
1730 if (IS_QLA23XX(ha)) {
1731 nv->firmware_options[0] |= BIT_2;
1732 nv->firmware_options[0] &= ~BIT_3;
1733 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1735 if (IS_QLA2300(ha)) {
1736 if (ha->fb_rev == FPM_2310) {
1737 strcpy(ha->model_number, "QLA2310");
1739 strcpy(ha->model_number, "QLA2300");
1742 qla2x00_set_model_info(vha, nv->model_number,
1743 sizeof(nv->model_number), "QLA23xx");
1745 } else if (IS_QLA2200(ha)) {
1746 nv->firmware_options[0] |= BIT_2;
1748 * 'Point-to-point preferred, else loop' is not a safe
1749 * connection mode setting.
1751 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1753 /* Force 'loop preferred, else point-to-point'. */
1754 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1755 nv->add_firmware_options[0] |= BIT_5;
1757 strcpy(ha->model_number, "QLA22xx");
1758 } else /*if (IS_QLA2100(ha))*/ {
1759 strcpy(ha->model_number, "QLA2100");
1763 * Copy over NVRAM RISC parameter block to initialization control block.
1765 dptr1 = (uint8_t *)icb;
1766 dptr2 = (uint8_t *)&nv->parameter_block_version;
1767 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1769 *dptr1++ = *dptr2++;
1771 /* Copy 2nd half. */
1772 dptr1 = (uint8_t *)icb->add_firmware_options;
1773 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1775 *dptr1++ = *dptr2++;
1777 /* Use alternate WWN? */
1778 if (nv->host_p[1] & BIT_7) {
1779 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1780 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1783 /* Prepare nodename */
1784 if ((icb->firmware_options[1] & BIT_6) == 0) {
1786 * Firmware will apply the following mask if the nodename was
1789 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1790 icb->node_name[0] &= 0xF0;
1794 * Set host adapter parameters.
1796 if (nv->host_p[0] & BIT_7)
1797 ql2xextended_error_logging = 1;
1798 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1799 /* Always load RISC code on non ISP2[12]00 chips. */
1800 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1801 ha->flags.disable_risc_code_load = 0;
1802 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1803 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1804 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1805 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1806 ha->flags.disable_serdes = 0;
1808 ha->operating_mode =
1809 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1811 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1812 sizeof(ha->fw_seriallink_options));
1814 /* save HBA serial number */
1815 ha->serial0 = icb->port_name[5];
1816 ha->serial1 = icb->port_name[6];
1817 ha->serial2 = icb->port_name[7];
1818 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
1819 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
1821 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1823 ha->retry_count = nv->retry_count;
1825 /* Set minimum login_timeout to 4 seconds. */
1826 if (nv->login_timeout < ql2xlogintimeout)
1827 nv->login_timeout = ql2xlogintimeout;
1828 if (nv->login_timeout < 4)
1829 nv->login_timeout = 4;
1830 ha->login_timeout = nv->login_timeout;
1831 icb->login_timeout = nv->login_timeout;
1833 /* Set minimum RATOV to 100 tenths of a second. */
1836 ha->loop_reset_delay = nv->reset_delay;
1838 /* Link Down Timeout = 0:
1840 * When Port Down timer expires we will start returning
1841 * I/O's to OS with "DID_NO_CONNECT".
1843 * Link Down Timeout != 0:
1845 * The driver waits for the link to come up after link down
1846 * before returning I/Os to OS with "DID_NO_CONNECT".
1848 if (nv->link_down_timeout == 0) {
1849 ha->loop_down_abort_time =
1850 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1852 ha->link_down_timeout = nv->link_down_timeout;
1853 ha->loop_down_abort_time =
1854 (LOOP_DOWN_TIME - ha->link_down_timeout);
1858 * Need enough time to try and get the port back.
1860 ha->port_down_retry_count = nv->port_down_retry_count;
1861 if (qlport_down_retry)
1862 ha->port_down_retry_count = qlport_down_retry;
1863 /* Set login_retry_count */
1864 ha->login_retry_count = nv->retry_count;
1865 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1866 ha->port_down_retry_count > 3)
1867 ha->login_retry_count = ha->port_down_retry_count;
1868 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1869 ha->login_retry_count = ha->port_down_retry_count;
1870 if (ql2xloginretrycount)
1871 ha->login_retry_count = ql2xloginretrycount;
1873 icb->lun_enables = __constant_cpu_to_le16(0);
1874 icb->command_resource_count = 0;
1875 icb->immediate_notify_resource_count = 0;
1876 icb->timeout = __constant_cpu_to_le16(0);
1878 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1880 icb->firmware_options[0] &= ~BIT_3;
1881 icb->add_firmware_options[0] &=
1882 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1883 icb->add_firmware_options[0] |= BIT_2;
1884 icb->response_accumulation_timer = 3;
1885 icb->interrupt_delay_timer = 5;
1887 vha->flags.process_response_queue = 1;
1890 if (!vha->flags.init_done) {
1891 ha->zio_mode = icb->add_firmware_options[0] &
1892 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1893 ha->zio_timer = icb->interrupt_delay_timer ?
1894 icb->interrupt_delay_timer: 2;
1896 icb->add_firmware_options[0] &=
1897 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1898 vha->flags.process_response_queue = 0;
1899 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1900 ha->zio_mode = QLA_ZIO_MODE_6;
1902 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1903 "delay (%d us).\n", vha->host_no, ha->zio_mode,
1904 ha->zio_timer * 100));
1905 qla_printk(KERN_INFO, ha,
1906 "ZIO mode %d enabled; timer delay (%d us).\n",
1907 ha->zio_mode, ha->zio_timer * 100);
1909 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1910 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1911 vha->flags.process_response_queue = 1;
1916 DEBUG2_3(printk(KERN_WARNING
1917 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
1923 qla2x00_rport_del(void *data)
1925 fc_port_t *fcport = data;
1926 struct fc_rport *rport;
1928 spin_lock_irq(fcport->vha->host->host_lock);
1929 rport = fcport->drport;
1930 fcport->drport = NULL;
1931 spin_unlock_irq(fcport->vha->host->host_lock);
1933 fc_remote_port_delete(rport);
1937 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1939 * @flags: allocation flags
1941 * Returns a pointer to the allocated fcport, or NULL, if none available.
1944 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
1948 fcport = kzalloc(sizeof(fc_port_t), flags);
1952 /* Setup fcport template structure. */
1954 fcport->vp_idx = vha->vp_idx;
1955 fcport->port_type = FCT_UNKNOWN;
1956 fcport->loop_id = FC_NO_LOOP_ID;
1957 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1958 fcport->supported_classes = FC_COS_UNSPECIFIED;
1964 * qla2x00_configure_loop
1965 * Updates Fibre Channel Device Database with what is actually on loop.
1968 * ha = adapter block pointer.
1973 * 2 = database was full and device was not configured.
1976 qla2x00_configure_loop(scsi_qla_host_t *vha)
1979 unsigned long flags, save_flags;
1980 struct qla_hw_data *ha = vha->hw;
1983 /* Get Initiator ID */
1984 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
1985 rval = qla2x00_configure_hba(vha);
1986 if (rval != QLA_SUCCESS) {
1987 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1993 save_flags = flags = vha->dpc_flags;
1994 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1995 vha->host_no, flags));
1998 * If we have both an RSCN and PORT UPDATE pending then handle them
1999 * both at the same time.
2001 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2002 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
2004 /* Determine what we need to do */
2005 if (ha->current_topology == ISP_CFG_FL &&
2006 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2008 vha->flags.rscn_queue_overflow = 1;
2009 set_bit(RSCN_UPDATE, &flags);
2011 } else if (ha->current_topology == ISP_CFG_F &&
2012 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2014 vha->flags.rscn_queue_overflow = 1;
2015 set_bit(RSCN_UPDATE, &flags);
2016 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2018 } else if (ha->current_topology == ISP_CFG_N) {
2019 clear_bit(RSCN_UPDATE, &flags);
2021 } else if (!vha->flags.online ||
2022 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2024 vha->flags.rscn_queue_overflow = 1;
2025 set_bit(RSCN_UPDATE, &flags);
2026 set_bit(LOCAL_LOOP_UPDATE, &flags);
2029 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
2030 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2031 rval = QLA_FUNCTION_FAILED;
2033 rval = qla2x00_configure_local_loop(vha);
2036 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
2037 if (LOOP_TRANSITION(vha))
2038 rval = QLA_FUNCTION_FAILED;
2040 rval = qla2x00_configure_fabric(vha);
2043 if (rval == QLA_SUCCESS) {
2044 if (atomic_read(&vha->loop_down_timer) ||
2045 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2046 rval = QLA_FUNCTION_FAILED;
2048 atomic_set(&vha->loop_state, LOOP_READY);
2050 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
2055 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
2056 __func__, vha->host_no));
2058 DEBUG3(printk("%s: exiting normally\n", __func__));
2061 /* Restore state if a resync event occurred during processing */
2062 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2063 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
2064 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2065 if (test_bit(RSCN_UPDATE, &save_flags)) {
2066 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2067 vha->flags.rscn_queue_overflow = 1;
2077 * qla2x00_configure_local_loop
2078 * Updates Fibre Channel Device Database with local loop devices.
2081 * ha = adapter block pointer.
2087 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
2092 fc_port_t *fcport, *new_fcport;
2098 uint8_t domain, area, al_pa;
2099 struct qla_hw_data *ha = vha->hw;
2103 entries = MAX_FIBRE_DEVICES;
2105 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2106 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
2108 /* Get list of logged in devices. */
2109 memset(ha->gid_list, 0, GID_LIST_SIZE);
2110 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
2112 if (rval != QLA_SUCCESS)
2113 goto cleanup_allocation;
2115 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2116 vha->host_no, entries));
2117 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2118 entries * sizeof(struct gid_list_info)));
2120 /* Allocate temporary fcport for any new fcports discovered. */
2121 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2122 if (new_fcport == NULL) {
2123 rval = QLA_MEMORY_ALLOC_FAILED;
2124 goto cleanup_allocation;
2126 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2129 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2131 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2132 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2133 fcport->port_type != FCT_BROADCAST &&
2134 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2136 DEBUG(printk("scsi(%ld): Marking port lost, "
2138 vha->host_no, fcport->loop_id));
2140 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2144 /* Add devices to port list. */
2145 id_iter = (char *)ha->gid_list;
2146 for (index = 0; index < entries; index++) {
2147 domain = ((struct gid_list_info *)id_iter)->domain;
2148 area = ((struct gid_list_info *)id_iter)->area;
2149 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
2150 if (IS_QLA2100(ha) || IS_QLA2200(ha))
2151 loop_id = (uint16_t)
2152 ((struct gid_list_info *)id_iter)->loop_id_2100;
2154 loop_id = le16_to_cpu(
2155 ((struct gid_list_info *)id_iter)->loop_id);
2156 id_iter += ha->gid_list_info_size;
2158 /* Bypass reserved domain fields. */
2159 if ((domain & 0xf0) == 0xf0)
2162 /* Bypass if not same domain and area of adapter. */
2163 if (area && domain &&
2164 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
2167 /* Bypass invalid local loop ID. */
2168 if (loop_id > LAST_LOCAL_LOOP_ID)
2171 /* Fill in member data. */
2172 new_fcport->d_id.b.domain = domain;
2173 new_fcport->d_id.b.area = area;
2174 new_fcport->d_id.b.al_pa = al_pa;
2175 new_fcport->loop_id = loop_id;
2176 new_fcport->vp_idx = vha->vp_idx;
2177 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
2178 if (rval2 != QLA_SUCCESS) {
2179 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2180 "information -- get_port_database=%x, "
2182 vha->host_no, rval2, new_fcport->loop_id));
2183 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2185 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2189 /* Check for matching device in port list. */
2192 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2193 if (memcmp(new_fcport->port_name, fcport->port_name,
2197 fcport->flags &= ~FCF_FABRIC_DEVICE;
2198 fcport->loop_id = new_fcport->loop_id;
2199 fcport->port_type = new_fcport->port_type;
2200 fcport->d_id.b24 = new_fcport->d_id.b24;
2201 memcpy(fcport->node_name, new_fcport->node_name,
2209 /* New device, add to fcports list. */
2211 new_fcport->vha = vha;
2212 new_fcport->vp_idx = vha->vp_idx;
2214 list_add_tail(&new_fcport->list, &vha->vp_fcports);
2216 /* Allocate a new replacement fcport. */
2217 fcport = new_fcport;
2218 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2219 if (new_fcport == NULL) {
2220 rval = QLA_MEMORY_ALLOC_FAILED;
2221 goto cleanup_allocation;
2223 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2226 /* Base iIDMA settings on HBA port speed. */
2227 fcport->fp_speed = ha->link_data_rate;
2229 qla2x00_update_fcport(vha, fcport);
2237 if (rval != QLA_SUCCESS) {
2238 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2239 "rval=%x\n", vha->host_no, rval));
2246 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
2248 #define LS_UNKNOWN 2
2249 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2253 struct qla_hw_data *ha = vha->hw;
2255 if (!IS_IIDMA_CAPABLE(ha))
2258 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2259 fcport->fp_speed > ha->link_data_rate)
2262 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
2264 if (rval != QLA_SUCCESS) {
2265 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2266 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2267 vha->host_no, fcport->port_name[0], fcport->port_name[1],
2268 fcport->port_name[2], fcport->port_name[3],
2269 fcport->port_name[4], fcport->port_name[5],
2270 fcport->port_name[6], fcport->port_name[7], rval,
2271 fcport->fp_speed, mb[0], mb[1]));
2273 link_speed = link_speeds[LS_UNKNOWN];
2274 if (fcport->fp_speed < 5)
2275 link_speed = link_speeds[fcport->fp_speed];
2276 else if (fcport->fp_speed == 0x13)
2277 link_speed = link_speeds[5];
2278 DEBUG2(qla_printk(KERN_INFO, ha,
2279 "iIDMA adjusted to %s GB/s on "
2280 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2281 link_speed, fcport->port_name[0],
2282 fcport->port_name[1], fcport->port_name[2],
2283 fcport->port_name[3], fcport->port_name[4],
2284 fcport->port_name[5], fcport->port_name[6],
2285 fcport->port_name[7]));
2290 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
2292 struct fc_rport_identifiers rport_ids;
2293 struct fc_rport *rport;
2294 struct qla_hw_data *ha = vha->hw;
2297 qla2x00_rport_del(fcport);
2299 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2300 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2301 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2302 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2303 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2304 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
2306 qla_printk(KERN_WARNING, ha,
2307 "Unable to allocate fc remote port!\n");
2310 spin_lock_irq(fcport->vha->host->host_lock);
2311 *((fc_port_t **)rport->dd_data) = fcport;
2312 spin_unlock_irq(fcport->vha->host->host_lock);
2314 rport->supported_classes = fcport->supported_classes;
2316 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2317 if (fcport->port_type == FCT_INITIATOR)
2318 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2319 if (fcport->port_type == FCT_TARGET)
2320 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2321 fc_remote_port_rolechg(rport, rport_ids.roles);
2325 * qla2x00_update_fcport
2326 * Updates device on list.
2329 * ha = adapter block pointer.
2330 * fcport = port structure pointer.
2340 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
2342 struct qla_hw_data *ha = vha->hw;
2345 fcport->login_retry = 0;
2346 fcport->port_login_retry_count = ha->port_down_retry_count *
2348 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2350 fcport->flags &= ~FCF_LOGIN_NEEDED;
2352 qla2x00_iidma_fcport(vha, fcport);
2354 atomic_set(&fcport->state, FCS_ONLINE);
2356 qla2x00_reg_remote_port(vha, fcport);
2360 * qla2x00_configure_fabric
2361 * Setup SNS devices with loop ID's.
2364 * ha = adapter block pointer.
2371 qla2x00_configure_fabric(scsi_qla_host_t *vha)
2374 fc_port_t *fcport, *fcptemp;
2375 uint16_t next_loopid;
2376 uint16_t mb[MAILBOX_REGISTER_COUNT];
2378 LIST_HEAD(new_fcports);
2379 struct qla_hw_data *ha = vha->hw;
2380 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2382 /* If FL port exists, then SNS is present */
2383 if (IS_FWI2_CAPABLE(ha))
2384 loop_id = NPH_F_PORT;
2386 loop_id = SNS_FL_PORT;
2387 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
2388 if (rval != QLA_SUCCESS) {
2389 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2390 "Port\n", vha->host_no));
2392 vha->device_flags &= ~SWITCH_FOUND;
2393 return (QLA_SUCCESS);
2395 vha->device_flags |= SWITCH_FOUND;
2397 /* Mark devices that need re-synchronization. */
2398 rval2 = qla2x00_device_resync(vha);
2399 if (rval2 == QLA_RSCNS_HANDLED) {
2400 /* No point doing the scan, just continue. */
2401 return (QLA_SUCCESS);
2405 if (ql2xfdmienable &&
2406 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2407 qla2x00_fdmi_register(vha);
2409 /* Ensure we are logged into the SNS. */
2410 if (IS_FWI2_CAPABLE(ha))
2413 loop_id = SIMPLE_NAME_SERVER;
2414 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
2415 0xfc, mb, BIT_1 | BIT_0);
2416 if (mb[0] != MBS_COMMAND_COMPLETE) {
2417 DEBUG2(qla_printk(KERN_INFO, ha,
2418 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2419 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2420 mb[0], mb[1], mb[2], mb[6], mb[7]));
2421 return (QLA_SUCCESS);
2424 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2425 if (qla2x00_rft_id(vha)) {
2427 DEBUG2(printk("scsi(%ld): Register FC-4 "
2428 "TYPE failed.\n", vha->host_no));
2430 if (qla2x00_rff_id(vha)) {
2432 DEBUG2(printk("scsi(%ld): Register FC-4 "
2433 "Features failed.\n", vha->host_no));
2435 if (qla2x00_rnn_id(vha)) {
2437 DEBUG2(printk("scsi(%ld): Register Node Name "
2438 "failed.\n", vha->host_no));
2439 } else if (qla2x00_rsnn_nn(vha)) {
2441 DEBUG2(printk("scsi(%ld): Register Symbolic "
2442 "Node Name failed.\n", vha->host_no));
2446 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
2447 if (rval != QLA_SUCCESS)
2451 * Logout all previous fabric devices marked lost, except
2454 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2455 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2458 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2461 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2462 qla2x00_mark_device_lost(vha, fcport,
2463 ql2xplogiabsentdevice, 0);
2464 if (fcport->loop_id != FC_NO_LOOP_ID &&
2465 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2466 fcport->port_type != FCT_INITIATOR &&
2467 fcport->port_type != FCT_BROADCAST) {
2468 ha->isp_ops->fabric_logout(vha,
2470 fcport->d_id.b.domain,
2471 fcport->d_id.b.area,
2472 fcport->d_id.b.al_pa);
2473 fcport->loop_id = FC_NO_LOOP_ID;
2478 /* Starting free loop ID. */
2479 next_loopid = ha->min_external_loopid;
2482 * Scan through our port list and login entries that need to be
2485 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2486 if (atomic_read(&vha->loop_down_timer) ||
2487 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2490 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2491 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2494 if (fcport->loop_id == FC_NO_LOOP_ID) {
2495 fcport->loop_id = next_loopid;
2496 rval = qla2x00_find_new_loop_id(
2498 if (rval != QLA_SUCCESS) {
2499 /* Ran out of IDs to use */
2503 /* Login and update database */
2504 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
2507 /* Exit if out of loop IDs. */
2508 if (rval != QLA_SUCCESS) {
2513 * Login and add the new devices to our port list.
2515 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2516 if (atomic_read(&vha->loop_down_timer) ||
2517 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2520 /* Find a new loop ID to use. */
2521 fcport->loop_id = next_loopid;
2522 rval = qla2x00_find_new_loop_id(base_vha, fcport);
2523 if (rval != QLA_SUCCESS) {
2524 /* Ran out of IDs to use */
2528 /* Login and update database */
2529 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
2533 fcport->vp_idx = vha->vp_idx;
2535 list_move_tail(&fcport->list, &vha->vp_fcports);
2539 /* Free all new device structures not processed. */
2540 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2541 list_del(&fcport->list);
2546 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2547 "rval=%d\n", vha->host_no, rval));
2555 * qla2x00_find_all_fabric_devs
2558 * ha = adapter block pointer.
2559 * dev = database device entry pointer.
2568 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2569 struct list_head *new_fcports)
2573 fc_port_t *fcport, *new_fcport, *fcptemp;
2578 int first_dev, last_dev;
2579 port_id_t wrap, nxt_d_id;
2580 struct qla_hw_data *ha = vha->hw;
2581 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
2582 struct scsi_qla_host *tvp;
2586 /* Try GID_PT to get device list, else GAN. */
2587 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
2590 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2591 "on GA_NXT\n", vha->host_no));
2593 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
2596 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
2599 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
2602 } else if (ql2xiidmaenable &&
2603 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2604 qla2x00_gpsc(vha, swl);
2609 /* Allocate temporary fcport for any new fcports discovered. */
2610 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2611 if (new_fcport == NULL) {
2613 return (QLA_MEMORY_ALLOC_FAILED);
2615 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2616 /* Set start port ID scan at adapter ID. */
2620 /* Starting free loop ID. */
2621 loop_id = ha->min_external_loopid;
2622 for (; loop_id <= ha->max_loop_id; loop_id++) {
2623 if (qla2x00_is_reserved_id(vha, loop_id))
2626 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
2631 wrap.b24 = new_fcport->d_id.b24;
2633 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2634 memcpy(new_fcport->node_name,
2635 swl[swl_idx].node_name, WWN_SIZE);
2636 memcpy(new_fcport->port_name,
2637 swl[swl_idx].port_name, WWN_SIZE);
2638 memcpy(new_fcport->fabric_port_name,
2639 swl[swl_idx].fabric_port_name, WWN_SIZE);
2640 new_fcport->fp_speed = swl[swl_idx].fp_speed;
2642 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2648 /* Send GA_NXT to the switch */
2649 rval = qla2x00_ga_nxt(vha, new_fcport);
2650 if (rval != QLA_SUCCESS) {
2651 qla_printk(KERN_WARNING, ha,
2652 "SNS scan failed -- assuming zero-entry "
2654 list_for_each_entry_safe(fcport, fcptemp,
2655 new_fcports, list) {
2656 list_del(&fcport->list);
2664 /* If wrap on switch device list, exit. */
2666 wrap.b24 = new_fcport->d_id.b24;
2668 } else if (new_fcport->d_id.b24 == wrap.b24) {
2669 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2670 vha->host_no, new_fcport->d_id.b.domain,
2671 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2675 /* Bypass if same physical adapter. */
2676 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
2679 /* Bypass virtual ports of the same host. */
2681 if (ha->num_vhosts) {
2682 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
2683 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2692 /* Bypass if same domain and area of adapter. */
2693 if (((new_fcport->d_id.b24 & 0xffff00) ==
2694 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2698 /* Bypass reserved domain fields. */
2699 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2702 /* Locate matching device in database. */
2704 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2705 if (memcmp(new_fcport->port_name, fcport->port_name,
2711 /* Update port state. */
2712 memcpy(fcport->fabric_port_name,
2713 new_fcport->fabric_port_name, WWN_SIZE);
2714 fcport->fp_speed = new_fcport->fp_speed;
2717 * If address the same and state FCS_ONLINE, nothing
2720 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2721 atomic_read(&fcport->state) == FCS_ONLINE) {
2726 * If device was not a fabric device before.
2728 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2729 fcport->d_id.b24 = new_fcport->d_id.b24;
2730 fcport->loop_id = FC_NO_LOOP_ID;
2731 fcport->flags |= (FCF_FABRIC_DEVICE |
2737 * Port ID changed or device was marked to be updated;
2738 * Log it out if still logged in and mark it for
2741 fcport->d_id.b24 = new_fcport->d_id.b24;
2742 fcport->flags |= FCF_LOGIN_NEEDED;
2743 if (fcport->loop_id != FC_NO_LOOP_ID &&
2744 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2745 fcport->port_type != FCT_INITIATOR &&
2746 fcport->port_type != FCT_BROADCAST) {
2747 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
2748 fcport->d_id.b.domain, fcport->d_id.b.area,
2749 fcport->d_id.b.al_pa);
2750 fcport->loop_id = FC_NO_LOOP_ID;
2758 /* If device was not in our fcports list, then add it. */
2759 list_add_tail(&new_fcport->list, new_fcports);
2761 /* Allocate a new replacement fcport. */
2762 nxt_d_id.b24 = new_fcport->d_id.b24;
2763 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2764 if (new_fcport == NULL) {
2766 return (QLA_MEMORY_ALLOC_FAILED);
2768 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2769 new_fcport->d_id.b24 = nxt_d_id.b24;
2779 * qla2x00_find_new_loop_id
2780 * Scan through our port list and find a new usable loop ID.
2783 * ha: adapter state pointer.
2784 * dev: port structure pointer.
2787 * qla2x00 local function return status code.
2793 qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
2798 uint16_t first_loop_id;
2799 struct qla_hw_data *ha = vha->hw;
2800 struct scsi_qla_host *vp;
2801 struct scsi_qla_host *tvp;
2805 /* Save starting loop ID. */
2806 first_loop_id = dev->loop_id;
2809 /* Skip loop ID if already used by adapter. */
2810 if (dev->loop_id == vha->loop_id)
2813 /* Skip reserved loop IDs. */
2814 while (qla2x00_is_reserved_id(vha, dev->loop_id))
2817 /* Reset loop ID if passed the end. */
2818 if (dev->loop_id > ha->max_loop_id) {
2819 /* first loop ID. */
2820 dev->loop_id = ha->min_external_loopid;
2823 /* Check for loop ID being already in use. */
2826 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
2827 list_for_each_entry(fcport, &vp->vp_fcports, list) {
2828 if (fcport->loop_id == dev->loop_id &&
2830 /* ID possibly in use */
2839 /* If not in use then it is free to use. */
2844 /* ID in use. Try next value. */
2847 /* If wrap around. No free ID to use. */
2848 if (dev->loop_id == first_loop_id) {
2849 dev->loop_id = FC_NO_LOOP_ID;
2850 rval = QLA_FUNCTION_FAILED;
2859 * qla2x00_device_resync
2860 * Marks devices in the database that needs resynchronization.
2863 * ha = adapter block pointer.
2869 qla2x00_device_resync(scsi_qla_host_t *vha)
2874 uint32_t rscn_entry;
2875 uint8_t rscn_out_iter;
2879 rval = QLA_RSCNS_HANDLED;
2881 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
2882 vha->flags.rscn_queue_overflow) {
2884 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
2885 format = MSB(MSW(rscn_entry));
2886 d_id.b.domain = LSB(MSW(rscn_entry));
2887 d_id.b.area = MSB(LSW(rscn_entry));
2888 d_id.b.al_pa = LSB(LSW(rscn_entry));
2890 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2891 "[%02x/%02x%02x%02x].\n",
2892 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
2893 d_id.b.area, d_id.b.al_pa));
2895 vha->rscn_out_ptr++;
2896 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
2897 vha->rscn_out_ptr = 0;
2899 /* Skip duplicate entries. */
2900 for (rscn_out_iter = vha->rscn_out_ptr;
2901 !vha->flags.rscn_queue_overflow &&
2902 rscn_out_iter != vha->rscn_in_ptr;
2903 rscn_out_iter = (rscn_out_iter ==
2904 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2906 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
2909 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2910 "entry found at [%d].\n", vha->host_no,
2913 vha->rscn_out_ptr = rscn_out_iter;
2916 /* Queue overflow, set switch default case. */
2917 if (vha->flags.rscn_queue_overflow) {
2918 DEBUG(printk("scsi(%ld): device_resync: rscn "
2919 "overflow.\n", vha->host_no));
2922 vha->flags.rscn_queue_overflow = 0;
2938 vha->rscn_out_ptr = vha->rscn_in_ptr;
2944 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2945 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2946 (fcport->d_id.b24 & mask) != d_id.b24 ||
2947 fcport->port_type == FCT_BROADCAST)
2950 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2952 fcport->port_type != FCT_INITIATOR) {
2953 qla2x00_mark_device_lost(vha, fcport,
2963 * qla2x00_fabric_dev_login
2964 * Login fabric target device and update FC port database.
2967 * ha: adapter state pointer.
2968 * fcport: port structure list pointer.
2969 * next_loopid: contains value of a new loop ID that can be used
2970 * by the next login attempt.
2973 * qla2x00 local function return status code.
2979 qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
2980 uint16_t *next_loopid)
2985 struct qla_hw_data *ha = vha->hw;
2990 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
2991 if (rval == QLA_SUCCESS) {
2992 /* Send an ADISC to tape devices.*/
2994 if (fcport->flags & FCF_TAPE_PRESENT)
2996 rval = qla2x00_get_port_database(vha, fcport, opts);
2997 if (rval != QLA_SUCCESS) {
2998 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
2999 fcport->d_id.b.domain, fcport->d_id.b.area,
3000 fcport->d_id.b.al_pa);
3001 qla2x00_mark_device_lost(vha, fcport, 1, 0);
3003 qla2x00_update_fcport(vha, fcport);
3011 * qla2x00_fabric_login
3012 * Issue fabric login command.
3015 * ha = adapter block pointer.
3016 * device = pointer to FC device type structure.
3019 * 0 - Login successfully
3021 * 2 - Initiator device
3025 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
3026 uint16_t *next_loopid)
3030 uint16_t tmp_loopid;
3031 uint16_t mb[MAILBOX_REGISTER_COUNT];
3032 struct qla_hw_data *ha = vha->hw;
3038 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3039 "for port %02x%02x%02x.\n",
3040 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
3041 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3043 /* Login fcport on switch. */
3044 ha->isp_ops->fabric_login(vha, fcport->loop_id,
3045 fcport->d_id.b.domain, fcport->d_id.b.area,
3046 fcport->d_id.b.al_pa, mb, BIT_0);
3047 if (mb[0] == MBS_PORT_ID_USED) {
3049 * Device has another loop ID. The firmware team
3050 * recommends the driver perform an implicit login with
3051 * the specified ID again. The ID we just used is save
3052 * here so we return with an ID that can be tried by
3056 tmp_loopid = fcport->loop_id;
3057 fcport->loop_id = mb[1];
3059 DEBUG(printk("Fabric Login: port in use - next "
3060 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3061 fcport->loop_id, fcport->d_id.b.domain,
3062 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3064 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3069 /* A retry occurred before. */
3070 *next_loopid = tmp_loopid;
3073 * No retry occurred before. Just increment the
3074 * ID value for next login.
3076 *next_loopid = (fcport->loop_id + 1);
3079 if (mb[1] & BIT_0) {
3080 fcport->port_type = FCT_INITIATOR;
3082 fcport->port_type = FCT_TARGET;
3083 if (mb[1] & BIT_1) {
3084 fcport->flags |= FCF_TAPE_PRESENT;
3089 fcport->supported_classes |= FC_COS_CLASS2;
3091 fcport->supported_classes |= FC_COS_CLASS3;
3095 } else if (mb[0] == MBS_LOOP_ID_USED) {
3097 * Loop ID already used, try next loop ID.
3100 rval = qla2x00_find_new_loop_id(vha, fcport);
3101 if (rval != QLA_SUCCESS) {
3102 /* Ran out of loop IDs to use */
3105 } else if (mb[0] == MBS_COMMAND_ERROR) {
3107 * Firmware possibly timed out during login. If NO
3108 * retries are left to do then the device is declared
3111 *next_loopid = fcport->loop_id;
3112 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3113 fcport->d_id.b.domain, fcport->d_id.b.area,
3114 fcport->d_id.b.al_pa);
3115 qla2x00_mark_device_lost(vha, fcport, 1, 0);
3121 * unrecoverable / not handled error
3123 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3124 "loop_id=%x jiffies=%lx.\n",
3125 __func__, vha->host_no, mb[0],
3126 fcport->d_id.b.domain, fcport->d_id.b.area,
3127 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3129 *next_loopid = fcport->loop_id;
3130 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3131 fcport->d_id.b.domain, fcport->d_id.b.area,
3132 fcport->d_id.b.al_pa);
3133 fcport->loop_id = FC_NO_LOOP_ID;
3134 fcport->login_retry = 0;
3145 * qla2x00_local_device_login
3146 * Issue local device login command.
3149 * ha = adapter block pointer.
3150 * loop_id = loop id of device to login to.
3152 * Returns (Where's the #define!!!!):
3153 * 0 - Login successfully
3158 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
3161 uint16_t mb[MAILBOX_REGISTER_COUNT];
3163 memset(mb, 0, sizeof(mb));
3164 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
3165 if (rval == QLA_SUCCESS) {
3166 /* Interrogate mailbox registers for any errors */
3167 if (mb[0] == MBS_COMMAND_ERROR)
3169 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3170 /* device not in PCB table */
3178 * qla2x00_loop_resync
3179 * Resync with fibre channel devices.
3182 * ha = adapter block pointer.
3188 qla2x00_loop_resync(scsi_qla_host_t *vha)
3190 int rval = QLA_SUCCESS;
3192 struct req_que *req;
3193 struct rsp_que *rsp;
3195 if (ql2xmultique_tag)
3196 req = vha->hw->req_q_map[0];
3201 atomic_set(&vha->loop_state, LOOP_UPDATE);
3202 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3203 if (vha->flags.online) {
3204 if (!(rval = qla2x00_fw_ready(vha))) {
3205 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3208 atomic_set(&vha->loop_state, LOOP_UPDATE);
3210 /* Issue a marker after FW becomes ready. */
3211 qla2x00_marker(vha, req, rsp, 0, 0,
3213 vha->marker_needed = 0;
3215 /* Remap devices on Loop. */
3216 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3218 qla2x00_configure_loop(vha);
3220 } while (!atomic_read(&vha->loop_down_timer) &&
3221 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3222 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3227 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3228 return (QLA_FUNCTION_FAILED);
3231 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3237 qla2x00_update_fcports(scsi_qla_host_t *vha)
3241 /* Go with deferred removal of rport references. */
3242 list_for_each_entry(fcport, &vha->vp_fcports, list)
3243 if (fcport && fcport->drport &&
3244 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
3245 qla2x00_rport_del(fcport);
3250 * Resets ISP and aborts all outstanding commands.
3253 * ha = adapter block pointer.
3259 qla2x00_abort_isp(scsi_qla_host_t *vha)
3263 struct qla_hw_data *ha = vha->hw;
3264 struct scsi_qla_host *vp;
3265 struct scsi_qla_host *tvp;
3266 struct req_que *req = ha->req_q_map[0];
3268 if (vha->flags.online) {
3269 vha->flags.online = 0;
3270 ha->flags.chip_reset_done = 0;
3271 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3272 ha->qla_stats.total_isp_aborts++;
3274 qla_printk(KERN_INFO, ha,
3275 "Performing ISP error recovery - ha= %p.\n", ha);
3276 ha->isp_ops->reset_chip(vha);
3278 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3279 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3280 atomic_set(&vha->loop_state, LOOP_DOWN);
3281 qla2x00_mark_all_devices_lost(vha, 0);
3282 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list)
3283 qla2x00_mark_all_devices_lost(vp, 0);
3285 if (!atomic_read(&vha->loop_down_timer))
3286 atomic_set(&vha->loop_down_timer,
3290 /* Requeue all commands in outstanding command list. */
3291 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
3293 ha->isp_ops->get_flash_version(vha, req->ring);
3295 ha->isp_ops->nvram_config(vha);
3297 if (!qla2x00_restart_isp(vha)) {
3298 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
3300 if (!atomic_read(&vha->loop_down_timer)) {
3302 * Issue marker command only when we are going
3303 * to start the I/O .
3305 vha->marker_needed = 1;
3308 vha->flags.online = 1;
3310 ha->isp_ops->enable_intrs(ha);
3312 ha->isp_abort_cnt = 0;
3313 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3316 ha->flags.fce_enabled = 1;
3318 fce_calc_size(ha->fce_bufs));
3319 rval = qla2x00_enable_fce_trace(vha,
3320 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3323 qla_printk(KERN_WARNING, ha,
3324 "Unable to reinitialize FCE "
3326 ha->flags.fce_enabled = 0;
3331 memset(ha->eft, 0, EFT_SIZE);
3332 rval = qla2x00_enable_eft_trace(vha,
3333 ha->eft_dma, EFT_NUM_BUFFERS);
3335 qla_printk(KERN_WARNING, ha,
3336 "Unable to reinitialize EFT "
3340 } else { /* failed the ISP abort */
3341 vha->flags.online = 1;
3342 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
3343 if (ha->isp_abort_cnt == 0) {
3344 qla_printk(KERN_WARNING, ha,
3345 "ISP error recovery failed - "
3346 "board disabled\n");
3348 * The next call disables the board
3351 ha->isp_ops->reset_adapter(vha);
3352 vha->flags.online = 0;
3353 clear_bit(ISP_ABORT_RETRY,
3356 } else { /* schedule another ISP abort */
3357 ha->isp_abort_cnt--;
3358 DEBUG(printk("qla%ld: ISP abort - "
3359 "retry remaining %d\n",
3360 vha->host_no, ha->isp_abort_cnt));
3364 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3365 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3366 "- retrying (%d) more times\n",
3367 vha->host_no, ha->isp_abort_cnt));
3368 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3376 DEBUG(printk(KERN_INFO
3377 "qla2x00_abort_isp(%ld): succeeded.\n",
3379 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
3381 qla2x00_vp_abort_isp(vp);
3384 qla_printk(KERN_INFO, ha,
3385 "qla2x00_abort_isp: **** FAILED ****\n");
3392 * qla2x00_restart_isp
3393 * restarts the ISP after a reset
3396 * ha = adapter block pointer.
3402 qla2x00_restart_isp(scsi_qla_host_t *vha)
3406 struct qla_hw_data *ha = vha->hw;
3407 struct req_que *req = ha->req_q_map[0];
3408 struct rsp_que *rsp = ha->rsp_q_map[0];
3410 /* If firmware needs to be loaded */
3411 if (qla2x00_isp_firmware(vha)) {
3412 vha->flags.online = 0;
3413 status = ha->isp_ops->chip_diag(vha);
3415 status = qla2x00_setup_chip(vha);
3418 if (!status && !(status = qla2x00_init_rings(vha))) {
3419 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
3420 ha->flags.chip_reset_done = 1;
3421 /* Initialize the queues in use */
3422 qla25xx_init_queues(ha);
3424 status = qla2x00_fw_ready(vha);
3426 DEBUG(printk("%s(): Start configure loop, "
3427 "status = %d\n", __func__, status));
3429 /* Issue a marker after FW becomes ready. */
3430 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
3432 vha->flags.online = 1;
3433 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3436 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3437 qla2x00_configure_loop(vha);
3439 } while (!atomic_read(&vha->loop_down_timer) &&
3440 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3441 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3445 /* if no cable then assume it's good */
3446 if ((vha->device_flags & DFLG_NO_CABLE))
3449 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3457 qla25xx_init_queues(struct qla_hw_data *ha)
3459 struct rsp_que *rsp = NULL;
3460 struct req_que *req = NULL;
3461 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3465 for (i = 1; i < ha->max_rsp_queues; i++) {
3466 rsp = ha->rsp_q_map[i];
3468 rsp->options &= ~BIT_0;
3469 ret = qla25xx_init_rsp_que(base_vha, rsp);
3470 if (ret != QLA_SUCCESS)
3471 DEBUG2_17(printk(KERN_WARNING
3472 "%s Rsp que:%d init failed\n", __func__,
3475 DEBUG2_17(printk(KERN_INFO
3476 "%s Rsp que:%d inited\n", __func__,
3480 for (i = 1; i < ha->max_req_queues; i++) {
3481 req = ha->req_q_map[i];
3483 /* Clear outstanding commands array. */
3484 req->options &= ~BIT_0;
3485 ret = qla25xx_init_req_que(base_vha, req);
3486 if (ret != QLA_SUCCESS)
3487 DEBUG2_17(printk(KERN_WARNING
3488 "%s Req que:%d init failed\n", __func__,
3491 DEBUG2_17(printk(KERN_WARNING
3492 "%s Req que:%d inited\n", __func__,
3500 * qla2x00_reset_adapter
3504 * ha = adapter block pointer.
3507 qla2x00_reset_adapter(scsi_qla_host_t *vha)
3509 unsigned long flags = 0;
3510 struct qla_hw_data *ha = vha->hw;
3511 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3513 vha->flags.online = 0;
3514 ha->isp_ops->disable_intrs(ha);
3516 spin_lock_irqsave(&ha->hardware_lock, flags);
3517 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3518 RD_REG_WORD(®->hccr); /* PCI Posting. */
3519 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3520 RD_REG_WORD(®->hccr); /* PCI Posting. */
3521 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3525 qla24xx_reset_adapter(scsi_qla_host_t *vha)
3527 unsigned long flags = 0;
3528 struct qla_hw_data *ha = vha->hw;
3529 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3531 vha->flags.online = 0;
3532 ha->isp_ops->disable_intrs(ha);
3534 spin_lock_irqsave(&ha->hardware_lock, flags);
3535 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3536 RD_REG_DWORD(®->hccr);
3537 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3538 RD_REG_DWORD(®->hccr);
3539 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3541 if (IS_NOPOLLING_TYPE(ha))
3542 ha->isp_ops->enable_intrs(ha);
3545 /* On sparc systems, obtain port and node WWN from firmware
3548 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3549 struct nvram_24xx *nv)
3552 struct qla_hw_data *ha = vha->hw;
3553 struct pci_dev *pdev = ha->pdev;
3554 struct device_node *dp = pci_device_to_OF_node(pdev);
3558 val = of_get_property(dp, "port-wwn", &len);
3559 if (val && len >= WWN_SIZE)
3560 memcpy(nv->port_name, val, WWN_SIZE);
3562 val = of_get_property(dp, "node-wwn", &len);
3563 if (val && len >= WWN_SIZE)
3564 memcpy(nv->node_name, val, WWN_SIZE);
3569 qla24xx_nvram_config(scsi_qla_host_t *vha)
3572 struct init_cb_24xx *icb;
3573 struct nvram_24xx *nv;
3575 uint8_t *dptr1, *dptr2;
3578 struct qla_hw_data *ha = vha->hw;
3581 icb = (struct init_cb_24xx *)ha->init_cb;
3584 /* Determine NVRAM starting address. */
3585 if (ha->flags.port0) {
3586 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3587 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3589 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3590 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3592 ha->nvram_size = sizeof(struct nvram_24xx);
3593 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3595 /* Get VPD data into cache */
3596 ha->vpd = ha->nvram + VPD_OFFSET;
3597 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
3598 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3600 /* Get NVRAM data into cache and calculate checksum. */
3601 dptr = (uint32_t *)nv;
3602 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
3604 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3605 chksum += le32_to_cpu(*dptr++);
3607 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
3608 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
3610 /* Bad NVRAM data, set defaults parameters. */
3611 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3612 || nv->id[3] != ' ' ||
3613 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3614 /* Reset NVRAM data. */
3615 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3616 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3617 le16_to_cpu(nv->nvram_version));
3618 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3619 "invalid -- WWPN) defaults.\n");
3622 * Set default initialization control block.
3624 memset(nv, 0, ha->nvram_size);
3625 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3626 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3627 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3628 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3629 nv->exchange_count = __constant_cpu_to_le16(0);
3630 nv->hard_address = __constant_cpu_to_le16(124);
3631 nv->port_name[0] = 0x21;
3632 nv->port_name[1] = 0x00 + ha->port_no;
3633 nv->port_name[2] = 0x00;
3634 nv->port_name[3] = 0xe0;
3635 nv->port_name[4] = 0x8b;
3636 nv->port_name[5] = 0x1c;
3637 nv->port_name[6] = 0x55;
3638 nv->port_name[7] = 0x86;
3639 nv->node_name[0] = 0x20;
3640 nv->node_name[1] = 0x00;
3641 nv->node_name[2] = 0x00;
3642 nv->node_name[3] = 0xe0;
3643 nv->node_name[4] = 0x8b;
3644 nv->node_name[5] = 0x1c;
3645 nv->node_name[6] = 0x55;
3646 nv->node_name[7] = 0x86;
3647 qla24xx_nvram_wwn_from_ofw(vha, nv);
3648 nv->login_retry_count = __constant_cpu_to_le16(8);
3649 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3650 nv->login_timeout = __constant_cpu_to_le16(0);
3651 nv->firmware_options_1 =
3652 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3653 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3654 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3655 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3656 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3657 nv->efi_parameters = __constant_cpu_to_le32(0);
3658 nv->reset_delay = 5;
3659 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3660 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3661 nv->link_down_timeout = __constant_cpu_to_le16(30);
3666 /* Reset Initialization control block */
3667 memset(icb, 0, ha->init_cb_size);
3669 /* Copy 1st segment. */
3670 dptr1 = (uint8_t *)icb;
3671 dptr2 = (uint8_t *)&nv->version;
3672 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3674 *dptr1++ = *dptr2++;
3676 icb->login_retry_count = nv->login_retry_count;
3677 icb->link_down_on_nos = nv->link_down_on_nos;
3679 /* Copy 2nd segment. */
3680 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3681 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3682 cnt = (uint8_t *)&icb->reserved_3 -
3683 (uint8_t *)&icb->interrupt_delay_timer;
3685 *dptr1++ = *dptr2++;
3688 * Setup driver NVRAM options.
3690 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
3693 /* Use alternate WWN? */
3694 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3695 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3696 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3699 /* Prepare nodename */
3700 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3702 * Firmware will apply the following mask if the nodename was
3705 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3706 icb->node_name[0] &= 0xF0;
3709 /* Set host adapter parameters. */
3710 ha->flags.disable_risc_code_load = 0;
3711 ha->flags.enable_lip_reset = 0;
3712 ha->flags.enable_lip_full_login =
3713 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3714 ha->flags.enable_target_reset =
3715 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
3716 ha->flags.enable_led_scheme = 0;
3717 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
3719 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3720 (BIT_6 | BIT_5 | BIT_4)) >> 4;
3722 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3723 sizeof(ha->fw_seriallink_options24));
3725 /* save HBA serial number */
3726 ha->serial0 = icb->port_name[5];
3727 ha->serial1 = icb->port_name[6];
3728 ha->serial2 = icb->port_name[7];
3729 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3730 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
3732 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3734 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3736 /* Set minimum login_timeout to 4 seconds. */
3737 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3738 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3739 if (le16_to_cpu(nv->login_timeout) < 4)
3740 nv->login_timeout = __constant_cpu_to_le16(4);
3741 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3742 icb->login_timeout = nv->login_timeout;
3744 /* Set minimum RATOV to 100 tenths of a second. */
3747 ha->loop_reset_delay = nv->reset_delay;
3749 /* Link Down Timeout = 0:
3751 * When Port Down timer expires we will start returning
3752 * I/O's to OS with "DID_NO_CONNECT".
3754 * Link Down Timeout != 0:
3756 * The driver waits for the link to come up after link down
3757 * before returning I/Os to OS with "DID_NO_CONNECT".
3759 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3760 ha->loop_down_abort_time =
3761 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3763 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3764 ha->loop_down_abort_time =
3765 (LOOP_DOWN_TIME - ha->link_down_timeout);
3768 /* Need enough time to try and get the port back. */
3769 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3770 if (qlport_down_retry)
3771 ha->port_down_retry_count = qlport_down_retry;
3773 /* Set login_retry_count */
3774 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3775 if (ha->port_down_retry_count ==
3776 le16_to_cpu(nv->port_down_retry_count) &&
3777 ha->port_down_retry_count > 3)
3778 ha->login_retry_count = ha->port_down_retry_count;
3779 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3780 ha->login_retry_count = ha->port_down_retry_count;
3781 if (ql2xloginretrycount)
3782 ha->login_retry_count = ql2xloginretrycount;
3785 if (!vha->flags.init_done) {
3786 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3787 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3788 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3789 le16_to_cpu(icb->interrupt_delay_timer): 2;
3791 icb->firmware_options_2 &= __constant_cpu_to_le32(
3792 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3793 vha->flags.process_response_queue = 0;
3794 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3795 ha->zio_mode = QLA_ZIO_MODE_6;
3797 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3798 "(%d us).\n", vha->host_no, ha->zio_mode,
3799 ha->zio_timer * 100));
3800 qla_printk(KERN_INFO, ha,
3801 "ZIO mode %d enabled; timer delay (%d us).\n",
3802 ha->zio_mode, ha->zio_timer * 100);
3804 icb->firmware_options_2 |= cpu_to_le32(
3805 (uint32_t)ha->zio_mode);
3806 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3807 vha->flags.process_response_queue = 1;
3811 DEBUG2_3(printk(KERN_WARNING
3812 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
3818 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
3821 int rval = QLA_SUCCESS;
3822 int segments, fragment;
3823 uint32_t *dcode, dlen;
3827 struct qla_hw_data *ha = vha->hw;
3828 struct req_que *req = ha->req_q_map[0];
3830 qla_printk(KERN_INFO, ha,
3831 "FW: Loading from flash (%x)...\n", faddr);
3835 segments = FA_RISC_CODE_SEGMENTS;
3836 dcode = (uint32_t *)req->ring;
3839 /* Validate firmware image by checking version. */
3840 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
3841 for (i = 0; i < 4; i++)
3842 dcode[i] = be32_to_cpu(dcode[i]);
3843 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3844 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3845 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3847 qla_printk(KERN_WARNING, ha,
3848 "Unable to verify integrity of flash firmware image!\n");
3849 qla_printk(KERN_WARNING, ha,
3850 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3851 dcode[1], dcode[2], dcode[3]);
3853 return QLA_FUNCTION_FAILED;
3856 while (segments && rval == QLA_SUCCESS) {
3857 /* Read segment's load information. */
3858 qla24xx_read_flash_data(vha, dcode, faddr, 4);
3860 risc_addr = be32_to_cpu(dcode[2]);
3861 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3862 risc_size = be32_to_cpu(dcode[3]);
3865 while (risc_size > 0 && rval == QLA_SUCCESS) {
3866 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3867 if (dlen > risc_size)
3870 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3871 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3872 vha->host_no, risc_addr, dlen, faddr));
3874 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
3875 for (i = 0; i < dlen; i++)
3876 dcode[i] = swab32(dcode[i]);
3878 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
3881 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3882 "segment %d of firmware\n", vha->host_no,
3884 qla_printk(KERN_WARNING, ha,
3885 "[ERROR] Failed to load segment %d of "
3886 "firmware\n", fragment);
3903 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3906 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
3910 uint16_t *wcode, *fwcode;
3911 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3912 struct fw_blob *blob;
3913 struct qla_hw_data *ha = vha->hw;
3914 struct req_que *req = ha->req_q_map[0];
3916 /* Load firmware blob. */
3917 blob = qla2x00_request_firmware(vha);
3919 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3920 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3921 "from: " QLA_FW_URL ".\n");
3922 return QLA_FUNCTION_FAILED;
3927 wcode = (uint16_t *)req->ring;
3929 fwcode = (uint16_t *)blob->fw->data;
3932 /* Validate firmware image by checking version. */
3933 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3934 qla_printk(KERN_WARNING, ha,
3935 "Unable to verify integrity of firmware image (%Zd)!\n",
3937 goto fail_fw_integrity;
3939 for (i = 0; i < 4; i++)
3940 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3941 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3942 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3943 wcode[2] == 0 && wcode[3] == 0)) {
3944 qla_printk(KERN_WARNING, ha,
3945 "Unable to verify integrity of firmware image!\n");
3946 qla_printk(KERN_WARNING, ha,
3947 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3948 wcode[1], wcode[2], wcode[3]);
3949 goto fail_fw_integrity;
3953 while (*seg && rval == QLA_SUCCESS) {
3955 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3956 risc_size = be16_to_cpu(fwcode[3]);
3958 /* Validate firmware image size. */
3959 fwclen += risc_size * sizeof(uint16_t);
3960 if (blob->fw->size < fwclen) {
3961 qla_printk(KERN_WARNING, ha,
3962 "Unable to verify integrity of firmware image "
3963 "(%Zd)!\n", blob->fw->size);
3964 goto fail_fw_integrity;
3968 while (risc_size > 0 && rval == QLA_SUCCESS) {
3969 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3970 if (wlen > risc_size)
3973 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3974 "addr %x, number of words 0x%x.\n", vha->host_no,
3977 for (i = 0; i < wlen; i++)
3978 wcode[i] = swab16(fwcode[i]);
3980 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
3983 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3984 "segment %d of firmware\n", vha->host_no,
3986 qla_printk(KERN_WARNING, ha,
3987 "[ERROR] Failed to load segment %d of "
3988 "firmware\n", fragment);
4004 return QLA_FUNCTION_FAILED;
4008 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4011 int segments, fragment;
4012 uint32_t *dcode, dlen;
4016 struct fw_blob *blob;
4017 uint32_t *fwcode, fwclen;
4018 struct qla_hw_data *ha = vha->hw;
4019 struct req_que *req = ha->req_q_map[0];
4021 /* Load firmware blob. */
4022 blob = qla2x00_request_firmware(vha);
4024 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
4025 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4026 "from: " QLA_FW_URL ".\n");
4028 return QLA_FUNCTION_FAILED;
4031 qla_printk(KERN_INFO, ha,
4032 "FW: Loading via request-firmware...\n");
4036 segments = FA_RISC_CODE_SEGMENTS;
4037 dcode = (uint32_t *)req->ring;
4039 fwcode = (uint32_t *)blob->fw->data;
4042 /* Validate firmware image by checking version. */
4043 if (blob->fw->size < 8 * sizeof(uint32_t)) {
4044 qla_printk(KERN_WARNING, ha,
4045 "Unable to verify integrity of firmware image (%Zd)!\n",
4047 goto fail_fw_integrity;
4049 for (i = 0; i < 4; i++)
4050 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4051 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4052 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4053 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4055 qla_printk(KERN_WARNING, ha,
4056 "Unable to verify integrity of firmware image!\n");
4057 qla_printk(KERN_WARNING, ha,
4058 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4059 dcode[1], dcode[2], dcode[3]);
4060 goto fail_fw_integrity;
4063 while (segments && rval == QLA_SUCCESS) {
4064 risc_addr = be32_to_cpu(fwcode[2]);
4065 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4066 risc_size = be32_to_cpu(fwcode[3]);
4068 /* Validate firmware image size. */
4069 fwclen += risc_size * sizeof(uint32_t);
4070 if (blob->fw->size < fwclen) {
4071 qla_printk(KERN_WARNING, ha,
4072 "Unable to verify integrity of firmware image "
4073 "(%Zd)!\n", blob->fw->size);
4075 goto fail_fw_integrity;
4079 while (risc_size > 0 && rval == QLA_SUCCESS) {
4080 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4081 if (dlen > risc_size)
4084 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4085 "addr %x, number of dwords 0x%x.\n", vha->host_no,
4088 for (i = 0; i < dlen; i++)
4089 dcode[i] = swab32(fwcode[i]);
4091 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
4094 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4095 "segment %d of firmware\n", vha->host_no,
4097 qla_printk(KERN_WARNING, ha,
4098 "[ERROR] Failed to load segment %d of "
4099 "firmware\n", fragment);
4115 return QLA_FUNCTION_FAILED;
4119 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4123 if (ql2xfwloadbin == 1)
4124 return qla81xx_load_risc(vha, srisc_addr);
4128 * 1) Firmware via request-firmware interface (.bin file).
4129 * 2) Firmware residing in flash.
4131 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4132 if (rval == QLA_SUCCESS)
4135 return qla24xx_load_risc_flash(vha, srisc_addr,
4136 vha->hw->flt_region_fw);
4140 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4143 struct qla_hw_data *ha = vha->hw;
4145 if (ql2xfwloadbin == 2)
4150 * 1) Firmware residing in flash.
4151 * 2) Firmware via request-firmware interface (.bin file).
4152 * 3) Golden-Firmware residing in flash -- limited operation.
4154 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
4155 if (rval == QLA_SUCCESS)
4159 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4160 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4163 qla_printk(KERN_ERR, ha,
4164 "FW: Attempting to fallback to golden firmware...\n");
4165 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4166 if (rval != QLA_SUCCESS)
4169 qla_printk(KERN_ERR, ha,
4170 "FW: Please update operational firmware...\n");
4171 ha->flags.running_gold_fw = 1;
4177 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
4180 struct qla_hw_data *ha = vha->hw;
4182 if (!IS_FWI2_CAPABLE(ha))
4184 if (!ha->fw_major_version)
4187 ret = qla2x00_stop_firmware(vha);
4188 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4189 ret != QLA_INVALID_COMMAND && retries ; retries--) {
4190 ha->isp_ops->reset_chip(vha);
4191 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
4193 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
4195 qla_printk(KERN_INFO, ha,
4196 "Attempting retry of stop-firmware command...\n");
4197 ret = qla2x00_stop_firmware(vha);
4202 qla24xx_configure_vhba(scsi_qla_host_t *vha)
4204 int rval = QLA_SUCCESS;
4205 uint16_t mb[MAILBOX_REGISTER_COUNT];
4206 struct qla_hw_data *ha = vha->hw;
4207 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4208 struct req_que *req;
4209 struct rsp_que *rsp;
4214 rval = qla2x00_fw_ready(base_vha);
4215 if (ql2xmultique_tag)
4216 req = ha->req_q_map[0];
4221 if (rval == QLA_SUCCESS) {
4222 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
4223 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
4226 vha->flags.management_server_logged_in = 0;
4228 /* Login to SNS first */
4229 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
4230 if (mb[0] != MBS_COMMAND_COMPLETE) {
4231 DEBUG15(qla_printk(KERN_INFO, ha,
4232 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4233 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4234 mb[0], mb[1], mb[2], mb[6], mb[7]));
4235 return (QLA_FUNCTION_FAILED);
4238 atomic_set(&vha->loop_down_timer, 0);
4239 atomic_set(&vha->loop_state, LOOP_UP);
4240 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4241 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4242 rval = qla2x00_loop_resync(base_vha);
4247 /* 84XX Support **************************************************************/
4249 static LIST_HEAD(qla_cs84xx_list);
4250 static DEFINE_MUTEX(qla_cs84xx_mutex);
4252 static struct qla_chip_state_84xx *
4253 qla84xx_get_chip(struct scsi_qla_host *vha)
4255 struct qla_chip_state_84xx *cs84xx;
4256 struct qla_hw_data *ha = vha->hw;
4258 mutex_lock(&qla_cs84xx_mutex);
4260 /* Find any shared 84xx chip. */
4261 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4262 if (cs84xx->bus == ha->pdev->bus) {
4263 kref_get(&cs84xx->kref);
4268 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4272 kref_init(&cs84xx->kref);
4273 spin_lock_init(&cs84xx->access_lock);
4274 mutex_init(&cs84xx->fw_update_mutex);
4275 cs84xx->bus = ha->pdev->bus;
4277 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4279 mutex_unlock(&qla_cs84xx_mutex);
4284 __qla84xx_chip_release(struct kref *kref)
4286 struct qla_chip_state_84xx *cs84xx =
4287 container_of(kref, struct qla_chip_state_84xx, kref);
4289 mutex_lock(&qla_cs84xx_mutex);
4290 list_del(&cs84xx->list);
4291 mutex_unlock(&qla_cs84xx_mutex);
4296 qla84xx_put_chip(struct scsi_qla_host *vha)
4298 struct qla_hw_data *ha = vha->hw;
4300 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4304 qla84xx_init_chip(scsi_qla_host_t *vha)
4308 struct qla_hw_data *ha = vha->hw;
4310 mutex_lock(&ha->cs84xx->fw_update_mutex);
4312 rval = qla84xx_verify_chip(vha, status);
4314 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4316 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4320 /* 81XX Support **************************************************************/
4323 qla81xx_nvram_config(scsi_qla_host_t *vha)
4326 struct init_cb_81xx *icb;
4327 struct nvram_81xx *nv;
4329 uint8_t *dptr1, *dptr2;
4332 struct qla_hw_data *ha = vha->hw;
4335 icb = (struct init_cb_81xx *)ha->init_cb;
4338 /* Determine NVRAM starting address. */
4339 ha->nvram_size = sizeof(struct nvram_81xx);
4340 ha->vpd_size = FA_NVRAM_VPD_SIZE;
4342 /* Get VPD data into cache */
4343 ha->vpd = ha->nvram + VPD_OFFSET;
4344 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4347 /* Get NVRAM data into cache and calculate checksum. */
4348 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
4350 dptr = (uint32_t *)nv;
4351 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4352 chksum += le32_to_cpu(*dptr++);
4354 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
4355 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4357 /* Bad NVRAM data, set defaults parameters. */
4358 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4359 || nv->id[3] != ' ' ||
4360 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4361 /* Reset NVRAM data. */
4362 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4363 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4364 le16_to_cpu(nv->nvram_version));
4365 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4366 "invalid -- WWPN) defaults.\n");
4369 * Set default initialization control block.
4371 memset(nv, 0, ha->nvram_size);
4372 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4373 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4374 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4375 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4376 nv->exchange_count = __constant_cpu_to_le16(0);
4377 nv->port_name[0] = 0x21;
4378 nv->port_name[1] = 0x00 + ha->port_no;
4379 nv->port_name[2] = 0x00;
4380 nv->port_name[3] = 0xe0;
4381 nv->port_name[4] = 0x8b;
4382 nv->port_name[5] = 0x1c;
4383 nv->port_name[6] = 0x55;
4384 nv->port_name[7] = 0x86;
4385 nv->node_name[0] = 0x20;
4386 nv->node_name[1] = 0x00;
4387 nv->node_name[2] = 0x00;
4388 nv->node_name[3] = 0xe0;
4389 nv->node_name[4] = 0x8b;
4390 nv->node_name[5] = 0x1c;
4391 nv->node_name[6] = 0x55;
4392 nv->node_name[7] = 0x86;
4393 nv->login_retry_count = __constant_cpu_to_le16(8);
4394 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4395 nv->login_timeout = __constant_cpu_to_le16(0);
4396 nv->firmware_options_1 =
4397 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4398 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4399 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4400 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4401 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4402 nv->efi_parameters = __constant_cpu_to_le32(0);
4403 nv->reset_delay = 5;
4404 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4405 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4406 nv->link_down_timeout = __constant_cpu_to_le16(30);
4407 nv->enode_mac[0] = 0x00;
4408 nv->enode_mac[1] = 0x02;
4409 nv->enode_mac[2] = 0x03;
4410 nv->enode_mac[3] = 0x04;
4411 nv->enode_mac[4] = 0x05;
4412 nv->enode_mac[5] = 0x06 + ha->port_no;
4417 /* Reset Initialization control block */
4418 memset(icb, 0, sizeof(struct init_cb_81xx));
4420 /* Copy 1st segment. */
4421 dptr1 = (uint8_t *)icb;
4422 dptr2 = (uint8_t *)&nv->version;
4423 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4425 *dptr1++ = *dptr2++;
4427 icb->login_retry_count = nv->login_retry_count;
4429 /* Copy 2nd segment. */
4430 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4431 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4432 cnt = (uint8_t *)&icb->reserved_5 -
4433 (uint8_t *)&icb->interrupt_delay_timer;
4435 *dptr1++ = *dptr2++;
4437 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4438 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4439 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4440 icb->enode_mac[0] = 0x01;
4441 icb->enode_mac[1] = 0x02;
4442 icb->enode_mac[2] = 0x03;
4443 icb->enode_mac[3] = 0x04;
4444 icb->enode_mac[4] = 0x05;
4445 icb->enode_mac[5] = 0x06 + ha->port_no;
4448 /* Use extended-initialization control block. */
4449 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
4452 * Setup driver NVRAM options.
4454 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4457 /* Use alternate WWN? */
4458 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4459 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4460 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4463 /* Prepare nodename */
4464 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4466 * Firmware will apply the following mask if the nodename was
4469 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4470 icb->node_name[0] &= 0xF0;
4473 /* Set host adapter parameters. */
4474 ha->flags.disable_risc_code_load = 0;
4475 ha->flags.enable_lip_reset = 0;
4476 ha->flags.enable_lip_full_login =
4477 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4478 ha->flags.enable_target_reset =
4479 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4480 ha->flags.enable_led_scheme = 0;
4481 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4483 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4484 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4486 /* save HBA serial number */
4487 ha->serial0 = icb->port_name[5];
4488 ha->serial1 = icb->port_name[6];
4489 ha->serial2 = icb->port_name[7];
4490 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4491 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4493 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4495 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4497 /* Set minimum login_timeout to 4 seconds. */
4498 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4499 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4500 if (le16_to_cpu(nv->login_timeout) < 4)
4501 nv->login_timeout = __constant_cpu_to_le16(4);
4502 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4503 icb->login_timeout = nv->login_timeout;
4505 /* Set minimum RATOV to 100 tenths of a second. */
4508 ha->loop_reset_delay = nv->reset_delay;
4510 /* Link Down Timeout = 0:
4512 * When Port Down timer expires we will start returning
4513 * I/O's to OS with "DID_NO_CONNECT".
4515 * Link Down Timeout != 0:
4517 * The driver waits for the link to come up after link down
4518 * before returning I/Os to OS with "DID_NO_CONNECT".
4520 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4521 ha->loop_down_abort_time =
4522 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4524 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4525 ha->loop_down_abort_time =
4526 (LOOP_DOWN_TIME - ha->link_down_timeout);
4529 /* Need enough time to try and get the port back. */
4530 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4531 if (qlport_down_retry)
4532 ha->port_down_retry_count = qlport_down_retry;
4534 /* Set login_retry_count */
4535 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4536 if (ha->port_down_retry_count ==
4537 le16_to_cpu(nv->port_down_retry_count) &&
4538 ha->port_down_retry_count > 3)
4539 ha->login_retry_count = ha->port_down_retry_count;
4540 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4541 ha->login_retry_count = ha->port_down_retry_count;
4542 if (ql2xloginretrycount)
4543 ha->login_retry_count = ql2xloginretrycount;
4546 if (!vha->flags.init_done) {
4547 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4548 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4549 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4550 le16_to_cpu(icb->interrupt_delay_timer): 2;
4552 icb->firmware_options_2 &= __constant_cpu_to_le32(
4553 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4554 vha->flags.process_response_queue = 0;
4555 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4556 ha->zio_mode = QLA_ZIO_MODE_6;
4558 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4559 "(%d us).\n", vha->host_no, ha->zio_mode,
4560 ha->zio_timer * 100));
4561 qla_printk(KERN_INFO, ha,
4562 "ZIO mode %d enabled; timer delay (%d us).\n",
4563 ha->zio_mode, ha->zio_timer * 100);
4565 icb->firmware_options_2 |= cpu_to_le32(
4566 (uint32_t)ha->zio_mode);
4567 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4568 vha->flags.process_response_queue = 1;
4572 DEBUG2_3(printk(KERN_WARNING
4573 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4579 qla81xx_update_fw_options(scsi_qla_host_t *ha)