2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2008 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/delay.h>
10 #include <linux/vmalloc.h>
12 #include "qla_devtbl.h"
19 * QLogic ISP2x00 Hardware Support Function Prototypes.
21 static int qla2x00_isp_firmware(scsi_qla_host_t *);
22 static void qla2x00_resize_request_q(scsi_qla_host_t *);
23 static int qla2x00_setup_chip(scsi_qla_host_t *);
24 static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
25 static int qla2x00_init_rings(scsi_qla_host_t *);
26 static int qla2x00_fw_ready(scsi_qla_host_t *);
27 static int qla2x00_configure_hba(scsi_qla_host_t *);
28 static int qla2x00_configure_loop(scsi_qla_host_t *);
29 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
30 static int qla2x00_configure_fabric(scsi_qla_host_t *);
31 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
32 static int qla2x00_device_resync(scsi_qla_host_t *);
33 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
36 static int qla2x00_restart_isp(scsi_qla_host_t *);
38 static int qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev);
40 static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
41 static int qla84xx_init_chip(scsi_qla_host_t *);
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 *ha)
62 /* Clear adapter flags. */
64 ha->flags.reset_active = 0;
65 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
66 atomic_set(&ha->loop_state, LOOP_DOWN);
67 ha->device_flags = DFLG_NO_CABLE;
69 ha->flags.management_server_logged_in = 0;
70 ha->marker_needed = 0;
72 ha->isp_abort_cnt = 0;
73 ha->beacon_blink_led = 0;
74 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
76 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
77 rval = ha->isp_ops->pci_config(ha);
79 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
84 ha->isp_ops->reset_chip(ha);
86 ha->isp_ops->get_flash_version(ha, ha->request_ring);
88 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
90 ha->isp_ops->nvram_config(ha);
92 if (ha->flags.disable_serdes) {
93 /* Mask HBA via NVRAM settings? */
94 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
95 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
96 ha->port_name[0], ha->port_name[1],
97 ha->port_name[2], ha->port_name[3],
98 ha->port_name[4], ha->port_name[5],
99 ha->port_name[6], ha->port_name[7]);
100 return QLA_FUNCTION_FAILED;
103 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
105 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
106 rval = ha->isp_ops->chip_diag(ha);
109 rval = qla2x00_setup_chip(ha);
112 qla2xxx_get_flash_info(ha);
114 if (IS_QLA84XX(ha)) {
115 ha->cs84xx = qla84xx_get_chip(ha);
117 qla_printk(KERN_ERR, ha,
118 "Unable to configure ISP84XX.\n");
119 return QLA_FUNCTION_FAILED;
122 rval = qla2x00_init_rings(ha);
128 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
131 * Returns 0 on success.
134 qla2100_pci_config(scsi_qla_host_t *ha)
139 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
141 pci_set_master(ha->pdev);
142 pci_try_set_mwi(ha->pdev);
144 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
145 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
146 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
148 /* Reset expansion ROM address decode enable */
149 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
150 d &= ~PCI_ROM_ADDRESS_ENABLE;
151 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
153 /* Get PCI bus information. */
154 spin_lock_irqsave(&ha->hardware_lock, flags);
155 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
156 spin_unlock_irqrestore(&ha->hardware_lock, flags);
162 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
165 * Returns 0 on success.
168 qla2300_pci_config(scsi_qla_host_t *ha)
172 unsigned long flags = 0;
174 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
176 pci_set_master(ha->pdev);
177 pci_try_set_mwi(ha->pdev);
179 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
180 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
182 if (IS_QLA2322(ha) || IS_QLA6322(ha))
183 w &= ~PCI_COMMAND_INTX_DISABLE;
184 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
187 * If this is a 2300 card and not 2312, reset the
188 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
189 * the 2310 also reports itself as a 2300 so we need to get the
190 * fb revision level -- a 6 indicates it really is a 2300 and
193 if (IS_QLA2300(ha)) {
194 spin_lock_irqsave(&ha->hardware_lock, flags);
197 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
198 for (cnt = 0; cnt < 30000; cnt++) {
199 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
205 /* Select FPM registers. */
206 WRT_REG_WORD(®->ctrl_status, 0x20);
207 RD_REG_WORD(®->ctrl_status);
209 /* Get the fb rev level */
210 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
212 if (ha->fb_rev == FPM_2300)
213 pci_clear_mwi(ha->pdev);
215 /* Deselect FPM registers. */
216 WRT_REG_WORD(®->ctrl_status, 0x0);
217 RD_REG_WORD(®->ctrl_status);
219 /* Release RISC module. */
220 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
221 for (cnt = 0; cnt < 30000; cnt++) {
222 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
228 spin_unlock_irqrestore(&ha->hardware_lock, flags);
231 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
233 /* Reset expansion ROM address decode enable */
234 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
235 d &= ~PCI_ROM_ADDRESS_ENABLE;
236 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
238 /* Get PCI bus information. */
239 spin_lock_irqsave(&ha->hardware_lock, flags);
240 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
241 spin_unlock_irqrestore(&ha->hardware_lock, flags);
247 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
250 * Returns 0 on success.
253 qla24xx_pci_config(scsi_qla_host_t *ha)
257 unsigned long flags = 0;
258 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
260 pci_set_master(ha->pdev);
261 pci_try_set_mwi(ha->pdev);
263 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
264 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
265 w &= ~PCI_COMMAND_INTX_DISABLE;
266 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
268 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
270 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
271 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
272 pcix_set_mmrbc(ha->pdev, 2048);
274 /* PCIe -- adjust Maximum Read Request Size (2048). */
275 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
276 pcie_set_readrq(ha->pdev, 2048);
278 /* Reset expansion ROM address decode enable */
279 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
280 d &= ~PCI_ROM_ADDRESS_ENABLE;
281 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
283 ha->chip_revision = ha->pdev->revision;
285 /* Get PCI bus information. */
286 spin_lock_irqsave(&ha->hardware_lock, flags);
287 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
288 spin_unlock_irqrestore(&ha->hardware_lock, flags);
294 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
297 * Returns 0 on success.
300 qla25xx_pci_config(scsi_qla_host_t *ha)
305 pci_set_master(ha->pdev);
306 pci_try_set_mwi(ha->pdev);
308 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
309 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
310 w &= ~PCI_COMMAND_INTX_DISABLE;
311 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
313 /* PCIe -- adjust Maximum Read Request Size (2048). */
314 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
315 pcie_set_readrq(ha->pdev, 2048);
317 /* Reset expansion ROM address decode enable */
318 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
319 d &= ~PCI_ROM_ADDRESS_ENABLE;
320 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
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 *ha)
338 /* Assume loading risc code */
339 rval = QLA_FUNCTION_FAILED;
341 if (ha->flags.disable_risc_code_load) {
342 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
344 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
346 /* Verify checksum of loaded RISC code. */
347 rval = qla2x00_verify_checksum(ha, ha->fw_srisc_address);
351 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
359 * qla2x00_reset_chip() - Reset ISP chip.
362 * Returns 0 on success.
365 qla2x00_reset_chip(scsi_qla_host_t *ha)
367 unsigned long flags = 0;
368 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
372 ha->isp_ops->disable_intrs(ha);
374 spin_lock_irqsave(&ha->hardware_lock, flags);
376 /* Turn off master enable */
378 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
379 cmd &= ~PCI_COMMAND_MASTER;
380 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
382 if (!IS_QLA2100(ha)) {
384 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
385 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
386 for (cnt = 0; cnt < 30000; cnt++) {
387 if ((RD_REG_WORD(®->hccr) &
388 HCCR_RISC_PAUSE) != 0)
393 RD_REG_WORD(®->hccr); /* PCI Posting. */
397 /* Select FPM registers. */
398 WRT_REG_WORD(®->ctrl_status, 0x20);
399 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
401 /* FPM Soft Reset. */
402 WRT_REG_WORD(®->fpm_diag_config, 0x100);
403 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
405 /* Toggle Fpm Reset. */
406 if (!IS_QLA2200(ha)) {
407 WRT_REG_WORD(®->fpm_diag_config, 0x0);
408 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
411 /* Select frame buffer registers. */
412 WRT_REG_WORD(®->ctrl_status, 0x10);
413 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
415 /* Reset frame buffer FIFOs. */
416 if (IS_QLA2200(ha)) {
417 WRT_FB_CMD_REG(ha, reg, 0xa000);
418 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
420 WRT_FB_CMD_REG(ha, reg, 0x00fc);
422 /* Read back fb_cmd until zero or 3 seconds max */
423 for (cnt = 0; cnt < 3000; cnt++) {
424 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
430 /* Select RISC module registers. */
431 WRT_REG_WORD(®->ctrl_status, 0);
432 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
434 /* Reset RISC processor. */
435 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
436 RD_REG_WORD(®->hccr); /* PCI Posting. */
438 /* Release RISC processor. */
439 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
440 RD_REG_WORD(®->hccr); /* PCI Posting. */
443 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
444 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
446 /* Reset ISP chip. */
447 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
449 /* Wait for RISC to recover from reset. */
450 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
452 * It is necessary to for a delay here since the card doesn't
453 * respond to PCI reads during a reset. On some architectures
454 * this will result in an MCA.
457 for (cnt = 30000; cnt; cnt--) {
458 if ((RD_REG_WORD(®->ctrl_status) &
459 CSR_ISP_SOFT_RESET) == 0)
466 /* Reset RISC processor. */
467 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
469 WRT_REG_WORD(®->semaphore, 0);
471 /* Release RISC processor. */
472 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
473 RD_REG_WORD(®->hccr); /* PCI Posting. */
475 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
476 for (cnt = 0; cnt < 30000; cnt++) {
477 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
485 /* Turn on master enable */
486 cmd |= PCI_COMMAND_MASTER;
487 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
489 /* Disable RISC pause on FPM parity error. */
490 if (!IS_QLA2100(ha)) {
491 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
492 RD_REG_WORD(®->hccr); /* PCI Posting. */
495 spin_unlock_irqrestore(&ha->hardware_lock, flags);
499 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
502 * Returns 0 on success.
505 qla24xx_reset_risc(scsi_qla_host_t *ha)
508 unsigned long flags = 0;
509 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
513 spin_lock_irqsave(&ha->hardware_lock, flags);
516 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
517 for (cnt = 0; cnt < 30000; cnt++) {
518 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
524 WRT_REG_DWORD(®->ctrl_status,
525 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
526 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
529 /* Wait for firmware to complete NVRAM accesses. */
530 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
531 for (cnt = 10000 ; cnt && d2; cnt--) {
533 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
539 /* Wait for soft-reset to complete. */
540 d2 = RD_REG_DWORD(®->ctrl_status);
541 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
543 d2 = RD_REG_DWORD(®->ctrl_status);
546 if (cnt == 0 || hw_evt)
547 qla2xxx_hw_event_log(ha, HW_EVENT_RESET_ERR,
548 RD_REG_WORD(®->mailbox1), RD_REG_WORD(®->mailbox2),
549 RD_REG_WORD(®->mailbox3));
551 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
552 RD_REG_DWORD(®->hccr);
554 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
555 RD_REG_DWORD(®->hccr);
557 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
558 RD_REG_DWORD(®->hccr);
560 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
561 for (cnt = 6000000 ; cnt && d2; cnt--) {
563 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
567 spin_unlock_irqrestore(&ha->hardware_lock, flags);
571 * qla24xx_reset_chip() - Reset ISP24xx chip.
574 * Returns 0 on success.
577 qla24xx_reset_chip(scsi_qla_host_t *ha)
579 ha->isp_ops->disable_intrs(ha);
581 /* Perform RISC reset. */
582 qla24xx_reset_risc(ha);
586 * qla2x00_chip_diag() - Test chip for proper operation.
589 * Returns 0 on success.
592 qla2x00_chip_diag(scsi_qla_host_t *ha)
595 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
596 unsigned long flags = 0;
601 /* Assume a failed state */
602 rval = QLA_FUNCTION_FAILED;
604 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
605 ha->host_no, (u_long)®->flash_address));
607 spin_lock_irqsave(&ha->hardware_lock, flags);
609 /* Reset ISP chip. */
610 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
613 * We need to have a delay here since the card will not respond while
614 * in reset causing an MCA on some architectures.
617 data = qla2x00_debounce_register(®->ctrl_status);
618 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
620 data = RD_REG_WORD(®->ctrl_status);
625 goto chip_diag_failed;
627 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
630 /* Reset RISC processor. */
631 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
632 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
634 /* Workaround for QLA2312 PCI parity error */
635 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
636 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
637 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
639 data = RD_MAILBOX_REG(ha, reg, 0);
646 goto chip_diag_failed;
648 /* Check product ID of chip */
649 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
651 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
652 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
653 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
654 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
655 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
656 mb[3] != PROD_ID_3) {
657 qla_printk(KERN_WARNING, ha,
658 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
660 goto chip_diag_failed;
662 ha->product_id[0] = mb[1];
663 ha->product_id[1] = mb[2];
664 ha->product_id[2] = mb[3];
665 ha->product_id[3] = mb[4];
667 /* Adjust fw RISC transfer size */
668 if (ha->request_q_length > 1024)
669 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
671 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
672 ha->request_q_length;
674 if (IS_QLA2200(ha) &&
675 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
676 /* Limit firmware transfer size with a 2200A */
677 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
680 ha->device_type |= DT_ISP2200A;
681 ha->fw_transfer_size = 128;
684 /* Wrap Incoming Mailboxes Test. */
685 spin_unlock_irqrestore(&ha->hardware_lock, flags);
687 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
688 rval = qla2x00_mbx_reg_test(ha);
690 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
692 qla_printk(KERN_WARNING, ha,
693 "Failed mailbox send register test\n");
696 /* Flag a successful rval */
699 spin_lock_irqsave(&ha->hardware_lock, flags);
703 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
704 "****\n", ha->host_no));
706 spin_unlock_irqrestore(&ha->hardware_lock, flags);
712 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
715 * Returns 0 on success.
718 qla24xx_chip_diag(scsi_qla_host_t *ha)
722 /* Perform RISC reset. */
723 qla24xx_reset_risc(ha);
725 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
727 rval = qla2x00_mbx_reg_test(ha);
729 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
731 qla_printk(KERN_WARNING, ha,
732 "Failed mailbox send register test\n");
734 /* Flag a successful rval */
742 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
745 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
751 qla_printk(KERN_WARNING, ha,
752 "Firmware dump previously allocated.\n");
757 fixed_size = mem_size = eft_size = fce_size = 0;
758 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
759 fixed_size = sizeof(struct qla2100_fw_dump);
760 } else if (IS_QLA23XX(ha)) {
761 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
762 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
764 } else if (IS_FWI2_CAPABLE(ha)) {
765 fixed_size = IS_QLA25XX(ha) ?
766 offsetof(struct qla25xx_fw_dump, ext_mem):
767 offsetof(struct qla24xx_fw_dump, ext_mem);
768 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
771 /* Allocate memory for Extended Trace Buffer. */
772 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
775 qla_printk(KERN_WARNING, ha, "Unable to allocate "
776 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
780 memset(tc, 0, EFT_SIZE);
781 rval = qla2x00_enable_eft_trace(ha, tc_dma, EFT_NUM_BUFFERS);
783 qla_printk(KERN_WARNING, ha, "Unable to initialize "
784 "EFT (%d).\n", rval);
785 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
790 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
794 ha->eft_dma = tc_dma;
797 /* Allocate memory for Fibre Channel Event Buffer. */
801 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
804 qla_printk(KERN_WARNING, ha, "Unable to allocate "
805 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
809 memset(tc, 0, FCE_SIZE);
810 rval = qla2x00_enable_fce_trace(ha, tc_dma, FCE_NUM_BUFFERS,
811 ha->fce_mb, &ha->fce_bufs);
813 qla_printk(KERN_WARNING, ha, "Unable to initialize "
814 "FCE (%d).\n", rval);
815 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
817 ha->flags.fce_enabled = 0;
821 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
824 fce_size = sizeof(struct qla2xxx_fce_chain) + EFT_SIZE;
825 ha->flags.fce_enabled = 1;
826 ha->fce_dma = tc_dma;
830 req_q_size = ha->request_q_length * sizeof(request_t);
831 rsp_q_size = ha->response_q_length * sizeof(response_t);
833 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
834 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
837 ha->fw_dump = vmalloc(dump_size);
839 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
840 "firmware dump!!!\n", dump_size / 1024);
843 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
851 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
854 ha->fw_dump_len = dump_size;
855 ha->fw_dump->signature[0] = 'Q';
856 ha->fw_dump->signature[1] = 'L';
857 ha->fw_dump->signature[2] = 'G';
858 ha->fw_dump->signature[3] = 'C';
859 ha->fw_dump->version = __constant_htonl(1);
861 ha->fw_dump->fixed_size = htonl(fixed_size);
862 ha->fw_dump->mem_size = htonl(mem_size);
863 ha->fw_dump->req_q_size = htonl(req_q_size);
864 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
866 ha->fw_dump->eft_size = htonl(eft_size);
867 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
868 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
870 ha->fw_dump->header_size =
871 htonl(offsetof(struct qla2xxx_fw_dump, isp));
875 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
878 * Returns 0 on success.
881 qla2x00_resize_request_q(scsi_qla_host_t *ha)
884 uint16_t fw_iocb_cnt = 0;
885 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
886 dma_addr_t request_dma;
887 request_t *request_ring;
889 /* Valid only on recent ISPs. */
890 if (IS_QLA2100(ha) || IS_QLA2200(ha))
893 /* Retrieve IOCB counts available to the firmware. */
894 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt,
895 &ha->max_npiv_vports);
898 /* No point in continuing if current settings are sufficient. */
899 if (fw_iocb_cnt < 1024)
901 if (ha->request_q_length >= request_q_length)
904 /* Attempt to claim larger area for request queue. */
905 request_ring = dma_alloc_coherent(&ha->pdev->dev,
906 (request_q_length + 1) * sizeof(request_t), &request_dma,
908 if (request_ring == NULL)
911 /* Resize successful, report extensions. */
912 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
913 (ha->fw_memory_size + 1) / 1024);
914 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
915 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
917 /* Clear old allocations. */
918 dma_free_coherent(&ha->pdev->dev,
919 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
922 /* Begin using larger queue. */
923 ha->request_q_length = request_q_length;
924 ha->request_ring = request_ring;
925 ha->request_dma = request_dma;
929 * qla2x00_setup_chip() - Load and start RISC firmware.
932 * Returns 0 on success.
935 qla2x00_setup_chip(scsi_qla_host_t *ha)
938 uint32_t srisc_address = 0;
939 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
942 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
943 /* Disable SRAM, Instruction RAM and GP RAM parity. */
944 spin_lock_irqsave(&ha->hardware_lock, flags);
945 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
946 RD_REG_WORD(®->hccr);
947 spin_unlock_irqrestore(&ha->hardware_lock, flags);
950 /* Load firmware sequences */
951 rval = ha->isp_ops->load_risc(ha, &srisc_address);
952 if (rval == QLA_SUCCESS) {
953 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
954 "code.\n", ha->host_no));
956 rval = qla2x00_verify_checksum(ha, srisc_address);
957 if (rval == QLA_SUCCESS) {
958 /* Start firmware execution. */
959 DEBUG(printk("scsi(%ld): Checksum OK, start "
960 "firmware.\n", ha->host_no));
962 rval = qla2x00_execute_fw(ha, srisc_address);
963 /* Retrieve firmware information. */
964 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
965 qla2x00_get_fw_version(ha,
966 &ha->fw_major_version,
967 &ha->fw_minor_version,
968 &ha->fw_subminor_version,
969 &ha->fw_attributes, &ha->fw_memory_size);
970 qla2x00_resize_request_q(ha);
971 ha->flags.npiv_supported = 0;
972 if ((IS_QLA24XX(ha) || IS_QLA25XX(ha)) &&
973 (ha->fw_attributes & BIT_2)) {
974 ha->flags.npiv_supported = 1;
975 if ((!ha->max_npiv_vports) ||
976 ((ha->max_npiv_vports + 1) %
977 MIN_MULTI_ID_FABRIC))
978 ha->max_npiv_vports =
979 MIN_MULTI_ID_FABRIC - 1;
983 qla2x00_alloc_fw_dump(ha);
986 DEBUG2(printk(KERN_INFO
987 "scsi(%ld): ISP Firmware failed checksum.\n",
992 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
993 /* Enable proper parity. */
994 spin_lock_irqsave(&ha->hardware_lock, flags);
997 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
999 /* SRAM, Instruction RAM and GP RAM parity */
1000 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
1001 RD_REG_WORD(®->hccr);
1002 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1006 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
1014 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1017 * Beginning of request ring has initialization control block already built
1018 * by nvram config routine.
1020 * Returns 0 on success.
1023 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
1028 pkt = ha->response_ring_ptr;
1029 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
1030 pkt->signature = RESPONSE_PROCESSED;
1037 * qla2x00_update_fw_options() - Read and process firmware options.
1040 * Returns 0 on success.
1043 qla2x00_update_fw_options(scsi_qla_host_t *ha)
1045 uint16_t swing, emphasis, tx_sens, rx_sens;
1047 memset(ha->fw_options, 0, sizeof(ha->fw_options));
1048 qla2x00_get_fw_options(ha, ha->fw_options);
1050 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1053 /* Serial Link options. */
1054 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1056 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1057 sizeof(ha->fw_seriallink_options)));
1059 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1060 if (ha->fw_seriallink_options[3] & BIT_2) {
1061 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1064 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1065 emphasis = (ha->fw_seriallink_options[2] &
1066 (BIT_4 | BIT_3)) >> 3;
1067 tx_sens = ha->fw_seriallink_options[0] &
1068 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1069 rx_sens = (ha->fw_seriallink_options[0] &
1070 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1071 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1072 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1075 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1076 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1077 ha->fw_options[10] |= BIT_5 |
1078 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1079 (tx_sens & (BIT_1 | BIT_0));
1082 swing = (ha->fw_seriallink_options[2] &
1083 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1084 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1085 tx_sens = ha->fw_seriallink_options[1] &
1086 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1087 rx_sens = (ha->fw_seriallink_options[1] &
1088 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1089 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1090 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1093 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1094 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1095 ha->fw_options[11] |= BIT_5 |
1096 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1097 (tx_sens & (BIT_1 | BIT_0));
1101 /* Return command IOCBs without waiting for an ABTS to complete. */
1102 ha->fw_options[3] |= BIT_13;
1105 if (ha->flags.enable_led_scheme)
1106 ha->fw_options[2] |= BIT_12;
1108 /* Detect ISP6312. */
1110 ha->fw_options[2] |= BIT_13;
1112 /* Update firmware options. */
1113 qla2x00_set_fw_options(ha, ha->fw_options);
1117 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1121 /* Update Serial Link options. */
1122 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1125 rval = qla2x00_set_serdes_params(ha,
1126 le16_to_cpu(ha->fw_seriallink_options24[1]),
1127 le16_to_cpu(ha->fw_seriallink_options24[2]),
1128 le16_to_cpu(ha->fw_seriallink_options24[3]));
1129 if (rval != QLA_SUCCESS) {
1130 qla_printk(KERN_WARNING, ha,
1131 "Unable to update Serial Link options (%x).\n", rval);
1136 qla2x00_config_rings(struct scsi_qla_host *ha)
1138 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1140 /* Setup ring parameters in initialization control block. */
1141 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1142 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1143 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1144 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1145 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1146 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1147 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1148 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1150 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1151 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1152 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1153 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1154 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1158 qla24xx_config_rings(struct scsi_qla_host *ha)
1160 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1161 struct init_cb_24xx *icb;
1163 /* Setup ring parameters in initialization control block. */
1164 icb = (struct init_cb_24xx *)ha->init_cb;
1165 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1166 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1167 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1168 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1169 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1170 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1171 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1172 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1174 WRT_REG_DWORD(®->req_q_in, 0);
1175 WRT_REG_DWORD(®->req_q_out, 0);
1176 WRT_REG_DWORD(®->rsp_q_in, 0);
1177 WRT_REG_DWORD(®->rsp_q_out, 0);
1178 RD_REG_DWORD(®->rsp_q_out);
1182 * qla2x00_init_rings() - Initializes firmware.
1185 * Beginning of request ring has initialization control block already built
1186 * by nvram config routine.
1188 * Returns 0 on success.
1191 qla2x00_init_rings(scsi_qla_host_t *ha)
1194 unsigned long flags = 0;
1196 struct mid_init_cb_24xx *mid_init_cb =
1197 (struct mid_init_cb_24xx *) ha->init_cb;
1199 spin_lock_irqsave(&ha->hardware_lock, flags);
1201 /* Clear outstanding commands array. */
1202 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1203 ha->outstanding_cmds[cnt] = NULL;
1205 ha->current_outstanding_cmd = 0;
1207 /* Clear RSCN queue. */
1208 ha->rscn_in_ptr = 0;
1209 ha->rscn_out_ptr = 0;
1211 /* Initialize firmware. */
1212 ha->request_ring_ptr = ha->request_ring;
1213 ha->req_ring_index = 0;
1214 ha->req_q_cnt = ha->request_q_length;
1215 ha->response_ring_ptr = ha->response_ring;
1216 ha->rsp_ring_index = 0;
1218 /* Initialize response queue entries */
1219 qla2x00_init_response_q_entries(ha);
1221 ha->isp_ops->config_rings(ha);
1223 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1225 /* Update any ISP specific firmware options before initialization. */
1226 ha->isp_ops->update_fw_options(ha);
1228 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1230 if (ha->flags.npiv_supported)
1231 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1233 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1235 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1237 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1240 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1248 * qla2x00_fw_ready() - Waits for firmware ready.
1251 * Returns 0 on success.
1254 qla2x00_fw_ready(scsi_qla_host_t *ha)
1257 unsigned long wtime, mtime, cs84xx_time;
1258 uint16_t min_wait; /* Minimum wait time if loop is down */
1259 uint16_t wait_time; /* Wait time if loop is coming ready */
1264 /* 20 seconds for loop down. */
1268 * Firmware should take at most one RATOV to login, plus 5 seconds for
1269 * our own processing.
1271 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1272 wait_time = min_wait;
1275 /* Min wait time if loop down */
1276 mtime = jiffies + (min_wait * HZ);
1278 /* wait time before firmware ready */
1279 wtime = jiffies + (wait_time * HZ);
1281 /* Wait for ISP to finish LIP */
1282 if (!ha->flags.init_done)
1283 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1285 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1289 rval = qla2x00_get_firmware_state(ha, state);
1290 if (rval == QLA_SUCCESS) {
1291 if (state[0] < FSTATE_LOSS_OF_SYNC) {
1292 ha->device_flags &= ~DFLG_NO_CABLE;
1294 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1295 DEBUG16(printk("scsi(%ld): fw_state=%x "
1296 "84xx=%x.\n", ha->host_no, state[0],
1298 if ((state[2] & FSTATE_LOGGED_IN) &&
1299 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1300 DEBUG16(printk("scsi(%ld): Sending "
1301 "verify iocb.\n", ha->host_no));
1303 cs84xx_time = jiffies;
1304 rval = qla84xx_init_chip(ha);
1305 if (rval != QLA_SUCCESS)
1308 /* Add time taken to initialize. */
1309 cs84xx_time = jiffies - cs84xx_time;
1310 wtime += cs84xx_time;
1311 mtime += cs84xx_time;
1312 DEBUG16(printk("scsi(%ld): Increasing "
1313 "wait time by %ld. New time %ld\n",
1314 ha->host_no, cs84xx_time, wtime));
1316 } else if (state[0] == FSTATE_READY) {
1317 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1320 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1321 &ha->login_timeout, &ha->r_a_tov);
1327 rval = QLA_FUNCTION_FAILED;
1329 if (atomic_read(&ha->loop_down_timer) &&
1330 state[0] != FSTATE_READY) {
1331 /* Loop down. Timeout on min_wait for states
1332 * other than Wait for Login.
1334 if (time_after_eq(jiffies, mtime)) {
1335 qla_printk(KERN_INFO, ha,
1336 "Cable is unplugged...\n");
1338 ha->device_flags |= DFLG_NO_CABLE;
1343 /* Mailbox cmd failed. Timeout on min_wait. */
1344 if (time_after_eq(jiffies, mtime))
1348 if (time_after_eq(jiffies, wtime))
1351 /* Delay for a while */
1354 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1355 ha->host_no, state[0], jiffies));
1358 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1359 ha->host_no, state[0], jiffies));
1362 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1370 * qla2x00_configure_hba
1371 * Setup adapter context.
1374 * ha = adapter state pointer.
1383 qla2x00_configure_hba(scsi_qla_host_t *ha)
1392 char connect_type[22];
1394 /* Get host addresses. */
1395 rval = qla2x00_get_adapter_id(ha,
1396 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
1397 if (rval != QLA_SUCCESS) {
1398 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
1399 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1400 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1401 __func__, ha->host_no));
1403 qla_printk(KERN_WARNING, ha,
1404 "ERROR -- Unable to get host loop ID.\n");
1405 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1411 qla_printk(KERN_INFO, ha,
1412 "Cannot get topology - retrying.\n");
1413 return (QLA_FUNCTION_FAILED);
1416 ha->loop_id = loop_id;
1419 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1420 ha->operating_mode = LOOP;
1425 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1427 ha->current_topology = ISP_CFG_NL;
1428 strcpy(connect_type, "(Loop)");
1432 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1434 ha->switch_cap = sw_cap;
1435 ha->current_topology = ISP_CFG_FL;
1436 strcpy(connect_type, "(FL_Port)");
1440 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1442 ha->operating_mode = P2P;
1443 ha->current_topology = ISP_CFG_N;
1444 strcpy(connect_type, "(N_Port-to-N_Port)");
1448 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1450 ha->switch_cap = sw_cap;
1451 ha->operating_mode = P2P;
1452 ha->current_topology = ISP_CFG_F;
1453 strcpy(connect_type, "(F_Port)");
1457 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1459 ha->host_no, topo));
1460 ha->current_topology = ISP_CFG_NL;
1461 strcpy(connect_type, "(Loop)");
1465 /* Save Host port and loop ID. */
1466 /* byte order - Big Endian */
1467 ha->d_id.b.domain = domain;
1468 ha->d_id.b.area = area;
1469 ha->d_id.b.al_pa = al_pa;
1471 if (!ha->flags.init_done)
1472 qla_printk(KERN_INFO, ha,
1473 "Topology - %s, Host Loop address 0x%x\n",
1474 connect_type, ha->loop_id);
1477 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1479 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1486 qla2x00_set_model_info(scsi_qla_host_t *ha, uint8_t *model, size_t len, char *def)
1491 if (memcmp(model, BINZERO, len) != 0) {
1492 strncpy(ha->model_number, model, len);
1493 st = en = ha->model_number;
1496 if (*en != 0x20 && *en != 0x00)
1501 index = (ha->pdev->subsystem_device & 0xff);
1502 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1503 index < QLA_MODEL_NAMES)
1504 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1506 index = (ha->pdev->subsystem_device & 0xff);
1507 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1508 index < QLA_MODEL_NAMES) {
1509 strcpy(ha->model_number,
1510 qla2x00_model_name[index * 2]);
1511 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1513 strcpy(ha->model_number, def);
1518 /* On sparc systems, obtain port and node WWN from firmware
1521 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, nvram_t *nv)
1524 struct pci_dev *pdev = ha->pdev;
1525 struct device_node *dp = pci_device_to_OF_node(pdev);
1529 val = of_get_property(dp, "port-wwn", &len);
1530 if (val && len >= WWN_SIZE)
1531 memcpy(nv->port_name, val, WWN_SIZE);
1533 val = of_get_property(dp, "node-wwn", &len);
1534 if (val && len >= WWN_SIZE)
1535 memcpy(nv->node_name, val, WWN_SIZE);
1540 * NVRAM configuration for ISP 2xxx
1543 * ha = adapter block pointer.
1546 * initialization control block in response_ring
1547 * host adapters parameters in host adapter block
1553 qla2x00_nvram_config(scsi_qla_host_t *ha)
1558 uint8_t *dptr1, *dptr2;
1559 init_cb_t *icb = ha->init_cb;
1560 nvram_t *nv = ha->nvram;
1561 uint8_t *ptr = ha->nvram;
1562 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1566 /* Determine NVRAM starting address. */
1567 ha->nvram_size = sizeof(nvram_t);
1569 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1570 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1571 ha->nvram_base = 0x80;
1573 /* Get NVRAM data and calculate checksum. */
1574 ha->isp_ops->read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1575 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1578 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1579 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
1581 /* Bad NVRAM data, set defaults parameters. */
1582 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1583 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1584 /* Reset NVRAM data. */
1585 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1586 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1588 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1589 "invalid -- WWPN) defaults.\n");
1592 qla2xxx_hw_event_log(ha, HW_EVENT_NVRAM_CHKSUM_ERR, 0,
1593 MSW(chksum), LSW(chksum));
1596 * Set default initialization control block.
1598 memset(nv, 0, ha->nvram_size);
1599 nv->parameter_block_version = ICB_VERSION;
1601 if (IS_QLA23XX(ha)) {
1602 nv->firmware_options[0] = BIT_2 | BIT_1;
1603 nv->firmware_options[1] = BIT_7 | BIT_5;
1604 nv->add_firmware_options[0] = BIT_5;
1605 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1606 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1607 nv->special_options[1] = BIT_7;
1608 } else if (IS_QLA2200(ha)) {
1609 nv->firmware_options[0] = BIT_2 | BIT_1;
1610 nv->firmware_options[1] = BIT_7 | BIT_5;
1611 nv->add_firmware_options[0] = BIT_5;
1612 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1613 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1614 } else if (IS_QLA2100(ha)) {
1615 nv->firmware_options[0] = BIT_3 | BIT_1;
1616 nv->firmware_options[1] = BIT_5;
1617 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1620 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1621 nv->execution_throttle = __constant_cpu_to_le16(16);
1622 nv->retry_count = 8;
1623 nv->retry_delay = 1;
1625 nv->port_name[0] = 33;
1626 nv->port_name[3] = 224;
1627 nv->port_name[4] = 139;
1629 qla2xxx_nvram_wwn_from_ofw(ha, nv);
1631 nv->login_timeout = 4;
1634 * Set default host adapter parameters
1636 nv->host_p[1] = BIT_2;
1637 nv->reset_delay = 5;
1638 nv->port_down_retry_count = 8;
1639 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1640 nv->link_down_timeout = 60;
1645 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1647 * The SN2 does not provide BIOS emulation which means you can't change
1648 * potentially bogus BIOS settings. Force the use of default settings
1649 * for link rate and frame size. Hope that the rest of the settings
1652 if (ia64_platform_is("sn2")) {
1653 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1655 nv->special_options[1] = BIT_7;
1659 /* Reset Initialization control block */
1660 memset(icb, 0, ha->init_cb_size);
1663 * Setup driver NVRAM options.
1665 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1666 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1667 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1668 nv->firmware_options[1] &= ~BIT_4;
1670 if (IS_QLA23XX(ha)) {
1671 nv->firmware_options[0] |= BIT_2;
1672 nv->firmware_options[0] &= ~BIT_3;
1673 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1675 if (IS_QLA2300(ha)) {
1676 if (ha->fb_rev == FPM_2310) {
1677 strcpy(ha->model_number, "QLA2310");
1679 strcpy(ha->model_number, "QLA2300");
1682 qla2x00_set_model_info(ha, nv->model_number,
1683 sizeof(nv->model_number), "QLA23xx");
1685 } else if (IS_QLA2200(ha)) {
1686 nv->firmware_options[0] |= BIT_2;
1688 * 'Point-to-point preferred, else loop' is not a safe
1689 * connection mode setting.
1691 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1693 /* Force 'loop preferred, else point-to-point'. */
1694 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1695 nv->add_firmware_options[0] |= BIT_5;
1697 strcpy(ha->model_number, "QLA22xx");
1698 } else /*if (IS_QLA2100(ha))*/ {
1699 strcpy(ha->model_number, "QLA2100");
1703 * Copy over NVRAM RISC parameter block to initialization control block.
1705 dptr1 = (uint8_t *)icb;
1706 dptr2 = (uint8_t *)&nv->parameter_block_version;
1707 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1709 *dptr1++ = *dptr2++;
1711 /* Copy 2nd half. */
1712 dptr1 = (uint8_t *)icb->add_firmware_options;
1713 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1715 *dptr1++ = *dptr2++;
1717 /* Use alternate WWN? */
1718 if (nv->host_p[1] & BIT_7) {
1719 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1720 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1723 /* Prepare nodename */
1724 if ((icb->firmware_options[1] & BIT_6) == 0) {
1726 * Firmware will apply the following mask if the nodename was
1729 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1730 icb->node_name[0] &= 0xF0;
1734 * Set host adapter parameters.
1736 if (nv->host_p[0] & BIT_7)
1737 ql2xextended_error_logging = 1;
1738 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1739 /* Always load RISC code on non ISP2[12]00 chips. */
1740 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1741 ha->flags.disable_risc_code_load = 0;
1742 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1743 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1744 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1745 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1746 ha->flags.disable_serdes = 0;
1748 ha->operating_mode =
1749 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1751 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1752 sizeof(ha->fw_seriallink_options));
1754 /* save HBA serial number */
1755 ha->serial0 = icb->port_name[5];
1756 ha->serial1 = icb->port_name[6];
1757 ha->serial2 = icb->port_name[7];
1758 ha->node_name = icb->node_name;
1759 ha->port_name = icb->port_name;
1761 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1763 ha->retry_count = nv->retry_count;
1765 /* Set minimum login_timeout to 4 seconds. */
1766 if (nv->login_timeout < ql2xlogintimeout)
1767 nv->login_timeout = ql2xlogintimeout;
1768 if (nv->login_timeout < 4)
1769 nv->login_timeout = 4;
1770 ha->login_timeout = nv->login_timeout;
1771 icb->login_timeout = nv->login_timeout;
1773 /* Set minimum RATOV to 100 tenths of a second. */
1776 ha->loop_reset_delay = nv->reset_delay;
1778 /* Link Down Timeout = 0:
1780 * When Port Down timer expires we will start returning
1781 * I/O's to OS with "DID_NO_CONNECT".
1783 * Link Down Timeout != 0:
1785 * The driver waits for the link to come up after link down
1786 * before returning I/Os to OS with "DID_NO_CONNECT".
1788 if (nv->link_down_timeout == 0) {
1789 ha->loop_down_abort_time =
1790 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1792 ha->link_down_timeout = nv->link_down_timeout;
1793 ha->loop_down_abort_time =
1794 (LOOP_DOWN_TIME - ha->link_down_timeout);
1798 * Need enough time to try and get the port back.
1800 ha->port_down_retry_count = nv->port_down_retry_count;
1801 if (qlport_down_retry)
1802 ha->port_down_retry_count = qlport_down_retry;
1803 /* Set login_retry_count */
1804 ha->login_retry_count = nv->retry_count;
1805 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1806 ha->port_down_retry_count > 3)
1807 ha->login_retry_count = ha->port_down_retry_count;
1808 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1809 ha->login_retry_count = ha->port_down_retry_count;
1810 if (ql2xloginretrycount)
1811 ha->login_retry_count = ql2xloginretrycount;
1813 icb->lun_enables = __constant_cpu_to_le16(0);
1814 icb->command_resource_count = 0;
1815 icb->immediate_notify_resource_count = 0;
1816 icb->timeout = __constant_cpu_to_le16(0);
1818 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1820 icb->firmware_options[0] &= ~BIT_3;
1821 icb->add_firmware_options[0] &=
1822 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1823 icb->add_firmware_options[0] |= BIT_2;
1824 icb->response_accumulation_timer = 3;
1825 icb->interrupt_delay_timer = 5;
1827 ha->flags.process_response_queue = 1;
1830 if (!ha->flags.init_done) {
1831 ha->zio_mode = icb->add_firmware_options[0] &
1832 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1833 ha->zio_timer = icb->interrupt_delay_timer ?
1834 icb->interrupt_delay_timer: 2;
1836 icb->add_firmware_options[0] &=
1837 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1838 ha->flags.process_response_queue = 0;
1839 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1840 ha->zio_mode = QLA_ZIO_MODE_6;
1842 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1843 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1844 ha->zio_timer * 100));
1845 qla_printk(KERN_INFO, ha,
1846 "ZIO mode %d enabled; timer delay (%d us).\n",
1847 ha->zio_mode, ha->zio_timer * 100);
1849 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1850 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1851 ha->flags.process_response_queue = 1;
1856 DEBUG2_3(printk(KERN_WARNING
1857 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1863 qla2x00_rport_del(void *data)
1865 fc_port_t *fcport = data;
1866 struct fc_rport *rport;
1867 unsigned long flags;
1869 spin_lock_irqsave(&fcport->rport_lock, flags);
1870 rport = fcport->drport;
1871 fcport->drport = NULL;
1872 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1874 fc_remote_port_delete(rport);
1878 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1880 * @flags: allocation flags
1882 * Returns a pointer to the allocated fcport, or NULL, if none available.
1885 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1889 fcport = kzalloc(sizeof(fc_port_t), flags);
1893 /* Setup fcport template structure. */
1895 fcport->vp_idx = ha->vp_idx;
1896 fcport->port_type = FCT_UNKNOWN;
1897 fcport->loop_id = FC_NO_LOOP_ID;
1898 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1899 fcport->flags = FCF_RLC_SUPPORT;
1900 fcport->supported_classes = FC_COS_UNSPECIFIED;
1901 spin_lock_init(&fcport->rport_lock);
1907 * qla2x00_configure_loop
1908 * Updates Fibre Channel Device Database with what is actually on loop.
1911 * ha = adapter block pointer.
1916 * 2 = database was full and device was not configured.
1919 qla2x00_configure_loop(scsi_qla_host_t *ha)
1922 unsigned long flags, save_flags;
1926 /* Get Initiator ID */
1927 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1928 rval = qla2x00_configure_hba(ha);
1929 if (rval != QLA_SUCCESS) {
1930 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1936 save_flags = flags = ha->dpc_flags;
1937 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1938 ha->host_no, flags));
1941 * If we have both an RSCN and PORT UPDATE pending then handle them
1942 * both at the same time.
1944 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1945 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1947 /* Determine what we need to do */
1948 if (ha->current_topology == ISP_CFG_FL &&
1949 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1951 ha->flags.rscn_queue_overflow = 1;
1952 set_bit(RSCN_UPDATE, &flags);
1954 } else if (ha->current_topology == ISP_CFG_F &&
1955 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1957 ha->flags.rscn_queue_overflow = 1;
1958 set_bit(RSCN_UPDATE, &flags);
1959 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1961 } else if (ha->current_topology == ISP_CFG_N) {
1962 clear_bit(RSCN_UPDATE, &flags);
1964 } else if (!ha->flags.online ||
1965 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1967 ha->flags.rscn_queue_overflow = 1;
1968 set_bit(RSCN_UPDATE, &flags);
1969 set_bit(LOCAL_LOOP_UPDATE, &flags);
1972 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1973 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1974 rval = QLA_FUNCTION_FAILED;
1976 rval = qla2x00_configure_local_loop(ha);
1980 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1981 if (LOOP_TRANSITION(ha)) {
1982 rval = QLA_FUNCTION_FAILED;
1984 rval = qla2x00_configure_fabric(ha);
1988 if (rval == QLA_SUCCESS) {
1989 if (atomic_read(&ha->loop_down_timer) ||
1990 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1991 rval = QLA_FUNCTION_FAILED;
1993 atomic_set(&ha->loop_state, LOOP_READY);
1995 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
2000 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
2001 __func__, ha->host_no));
2003 DEBUG3(printk("%s: exiting normally\n", __func__));
2006 /* Restore state if a resync event occured during processing */
2007 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2008 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
2009 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
2010 if (test_bit(RSCN_UPDATE, &save_flags))
2011 set_bit(RSCN_UPDATE, &ha->dpc_flags);
2020 * qla2x00_configure_local_loop
2021 * Updates Fibre Channel Device Database with local loop devices.
2024 * ha = adapter block pointer.
2030 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
2035 fc_port_t *fcport, *new_fcport;
2041 uint8_t domain, area, al_pa;
2042 scsi_qla_host_t *pha = to_qla_parent(ha);
2046 entries = MAX_FIBRE_DEVICES;
2048 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
2049 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
2051 /* Get list of logged in devices. */
2052 memset(ha->gid_list, 0, GID_LIST_SIZE);
2053 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
2055 if (rval != QLA_SUCCESS)
2056 goto cleanup_allocation;
2058 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2059 ha->host_no, entries));
2060 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2061 entries * sizeof(struct gid_list_info)));
2063 /* Allocate temporary fcport for any new fcports discovered. */
2064 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2065 if (new_fcport == NULL) {
2066 rval = QLA_MEMORY_ALLOC_FAILED;
2067 goto cleanup_allocation;
2069 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2072 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2074 list_for_each_entry(fcport, &pha->fcports, list) {
2075 if (fcport->vp_idx != ha->vp_idx)
2078 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2079 fcport->port_type != FCT_BROADCAST &&
2080 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2082 DEBUG(printk("scsi(%ld): Marking port lost, "
2084 ha->host_no, fcport->loop_id));
2086 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2087 fcport->flags &= ~FCF_FARP_DONE;
2091 /* Add devices to port list. */
2092 id_iter = (char *)ha->gid_list;
2093 for (index = 0; index < entries; index++) {
2094 domain = ((struct gid_list_info *)id_iter)->domain;
2095 area = ((struct gid_list_info *)id_iter)->area;
2096 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
2097 if (IS_QLA2100(ha) || IS_QLA2200(ha))
2098 loop_id = (uint16_t)
2099 ((struct gid_list_info *)id_iter)->loop_id_2100;
2101 loop_id = le16_to_cpu(
2102 ((struct gid_list_info *)id_iter)->loop_id);
2103 id_iter += ha->gid_list_info_size;
2105 /* Bypass reserved domain fields. */
2106 if ((domain & 0xf0) == 0xf0)
2109 /* Bypass if not same domain and area of adapter. */
2110 if (area && domain &&
2111 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
2114 /* Bypass invalid local loop ID. */
2115 if (loop_id > LAST_LOCAL_LOOP_ID)
2118 /* Fill in member data. */
2119 new_fcport->d_id.b.domain = domain;
2120 new_fcport->d_id.b.area = area;
2121 new_fcport->d_id.b.al_pa = al_pa;
2122 new_fcport->loop_id = loop_id;
2123 new_fcport->vp_idx = ha->vp_idx;
2124 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
2125 if (rval2 != QLA_SUCCESS) {
2126 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2127 "information -- get_port_database=%x, "
2129 ha->host_no, rval2, new_fcport->loop_id));
2130 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2132 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2136 /* Check for matching device in port list. */
2139 list_for_each_entry(fcport, &pha->fcports, list) {
2140 if (fcport->vp_idx != ha->vp_idx)
2143 if (memcmp(new_fcport->port_name, fcport->port_name,
2147 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2148 FCF_PERSISTENT_BOUND);
2149 fcport->loop_id = new_fcport->loop_id;
2150 fcport->port_type = new_fcport->port_type;
2151 fcport->d_id.b24 = new_fcport->d_id.b24;
2152 memcpy(fcport->node_name, new_fcport->node_name,
2160 /* New device, add to fcports list. */
2161 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
2163 new_fcport->ha = ha;
2164 new_fcport->vp_idx = ha->vp_idx;
2165 list_add_tail(&new_fcport->vp_fcport,
2168 list_add_tail(&new_fcport->list, &pha->fcports);
2170 /* Allocate a new replacement fcport. */
2171 fcport = new_fcport;
2172 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2173 if (new_fcport == NULL) {
2174 rval = QLA_MEMORY_ALLOC_FAILED;
2175 goto cleanup_allocation;
2177 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2180 /* Base iIDMA settings on HBA port speed. */
2181 fcport->fp_speed = ha->link_data_rate;
2183 qla2x00_update_fcport(ha, fcport);
2191 if (rval != QLA_SUCCESS) {
2192 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2193 "rval=%x\n", ha->host_no, rval));
2197 ha->device_flags |= DFLG_LOCAL_DEVICES;
2198 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2205 qla2x00_iidma_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2207 #define LS_UNKNOWN 2
2208 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
2212 if (!IS_IIDMA_CAPABLE(ha))
2215 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2216 fcport->fp_speed > ha->link_data_rate)
2219 rval = qla2x00_set_idma_speed(ha, fcport->loop_id, fcport->fp_speed,
2221 if (rval != QLA_SUCCESS) {
2222 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2223 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2224 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2225 fcport->port_name[2], fcport->port_name[3],
2226 fcport->port_name[4], fcport->port_name[5],
2227 fcport->port_name[6], fcport->port_name[7], rval,
2228 fcport->fp_speed, mb[0], mb[1]));
2230 DEBUG2(qla_printk(KERN_INFO, ha,
2231 "iIDMA adjusted to %s GB/s on "
2232 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2233 link_speeds[fcport->fp_speed], fcport->port_name[0],
2234 fcport->port_name[1], fcport->port_name[2],
2235 fcport->port_name[3], fcport->port_name[4],
2236 fcport->port_name[5], fcport->port_name[6],
2237 fcport->port_name[7]));
2242 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2244 struct fc_rport_identifiers rport_ids;
2245 struct fc_rport *rport;
2246 unsigned long flags;
2249 qla2x00_rport_del(fcport);
2253 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2254 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2255 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2256 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2257 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2258 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2260 qla_printk(KERN_WARNING, ha,
2261 "Unable to allocate fc remote port!\n");
2264 spin_lock_irqsave(&fcport->rport_lock, flags);
2265 fcport->rport = rport;
2266 *((fc_port_t **)rport->dd_data) = fcport;
2267 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2269 rport->supported_classes = fcport->supported_classes;
2271 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2272 if (fcport->port_type == FCT_INITIATOR)
2273 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2274 if (fcport->port_type == FCT_TARGET)
2275 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2276 fc_remote_port_rolechg(rport, rport_ids.roles);
2280 * qla2x00_update_fcport
2281 * Updates device on list.
2284 * ha = adapter block pointer.
2285 * fcport = port structure pointer.
2295 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2297 scsi_qla_host_t *pha = to_qla_parent(ha);
2300 fcport->login_retry = 0;
2301 fcport->port_login_retry_count = pha->port_down_retry_count *
2303 atomic_set(&fcport->port_down_timer, pha->port_down_retry_count *
2305 fcport->flags &= ~FCF_LOGIN_NEEDED;
2307 qla2x00_iidma_fcport(ha, fcport);
2309 atomic_set(&fcport->state, FCS_ONLINE);
2311 qla2x00_reg_remote_port(ha, fcport);
2315 * qla2x00_configure_fabric
2316 * Setup SNS devices with loop ID's.
2319 * ha = adapter block pointer.
2326 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2329 fc_port_t *fcport, *fcptemp;
2330 uint16_t next_loopid;
2331 uint16_t mb[MAILBOX_REGISTER_COUNT];
2333 LIST_HEAD(new_fcports);
2334 scsi_qla_host_t *pha = to_qla_parent(ha);
2336 /* If FL port exists, then SNS is present */
2337 if (IS_FWI2_CAPABLE(ha))
2338 loop_id = NPH_F_PORT;
2340 loop_id = SNS_FL_PORT;
2341 rval = qla2x00_get_port_name(ha, loop_id, ha->fabric_node_name, 1);
2342 if (rval != QLA_SUCCESS) {
2343 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2344 "Port\n", ha->host_no));
2346 ha->device_flags &= ~SWITCH_FOUND;
2347 return (QLA_SUCCESS);
2349 ha->device_flags |= SWITCH_FOUND;
2351 /* Mark devices that need re-synchronization. */
2352 rval2 = qla2x00_device_resync(ha);
2353 if (rval2 == QLA_RSCNS_HANDLED) {
2354 /* No point doing the scan, just continue. */
2355 return (QLA_SUCCESS);
2359 if (ql2xfdmienable &&
2360 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2361 qla2x00_fdmi_register(ha);
2363 /* Ensure we are logged into the SNS. */
2364 if (IS_FWI2_CAPABLE(ha))
2367 loop_id = SIMPLE_NAME_SERVER;
2368 ha->isp_ops->fabric_login(ha, loop_id, 0xff, 0xff,
2369 0xfc, mb, BIT_1 | BIT_0);
2370 if (mb[0] != MBS_COMMAND_COMPLETE) {
2371 DEBUG2(qla_printk(KERN_INFO, ha,
2372 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2373 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2374 mb[0], mb[1], mb[2], mb[6], mb[7]));
2375 return (QLA_SUCCESS);
2378 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2379 if (qla2x00_rft_id(ha)) {
2381 DEBUG2(printk("scsi(%ld): Register FC-4 "
2382 "TYPE failed.\n", ha->host_no));
2384 if (qla2x00_rff_id(ha)) {
2386 DEBUG2(printk("scsi(%ld): Register FC-4 "
2387 "Features failed.\n", ha->host_no));
2389 if (qla2x00_rnn_id(ha)) {
2391 DEBUG2(printk("scsi(%ld): Register Node Name "
2392 "failed.\n", ha->host_no));
2393 } else if (qla2x00_rsnn_nn(ha)) {
2395 DEBUG2(printk("scsi(%ld): Register Symbolic "
2396 "Node Name failed.\n", ha->host_no));
2400 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2401 if (rval != QLA_SUCCESS)
2405 * Logout all previous fabric devices marked lost, except
2408 list_for_each_entry(fcport, &pha->fcports, list) {
2409 if (fcport->vp_idx !=ha->vp_idx)
2412 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2415 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2418 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2419 qla2x00_mark_device_lost(ha, fcport,
2420 ql2xplogiabsentdevice, 0);
2421 if (fcport->loop_id != FC_NO_LOOP_ID &&
2422 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2423 fcport->port_type != FCT_INITIATOR &&
2424 fcport->port_type != FCT_BROADCAST) {
2425 ha->isp_ops->fabric_logout(ha,
2427 fcport->d_id.b.domain,
2428 fcport->d_id.b.area,
2429 fcport->d_id.b.al_pa);
2430 fcport->loop_id = FC_NO_LOOP_ID;
2435 /* Starting free loop ID. */
2436 next_loopid = pha->min_external_loopid;
2439 * Scan through our port list and login entries that need to be
2442 list_for_each_entry(fcport, &pha->fcports, list) {
2443 if (fcport->vp_idx != ha->vp_idx)
2446 if (atomic_read(&ha->loop_down_timer) ||
2447 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2450 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2451 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2454 if (fcport->loop_id == FC_NO_LOOP_ID) {
2455 fcport->loop_id = next_loopid;
2456 rval = qla2x00_find_new_loop_id(
2457 to_qla_parent(ha), fcport);
2458 if (rval != QLA_SUCCESS) {
2459 /* Ran out of IDs to use */
2463 /* Login and update database */
2464 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2467 /* Exit if out of loop IDs. */
2468 if (rval != QLA_SUCCESS) {
2473 * Login and add the new devices to our port list.
2475 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2476 if (atomic_read(&ha->loop_down_timer) ||
2477 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2480 /* Find a new loop ID to use. */
2481 fcport->loop_id = next_loopid;
2482 rval = qla2x00_find_new_loop_id(to_qla_parent(ha),
2484 if (rval != QLA_SUCCESS) {
2485 /* Ran out of IDs to use */
2489 /* Login and update database */
2490 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2494 fcport->vp_idx = ha->vp_idx;
2495 list_add_tail(&fcport->vp_fcport,
2497 list_move_tail(&fcport->list,
2498 &ha->parent->fcports);
2500 list_move_tail(&fcport->list, &ha->fcports);
2504 /* Free all new device structures not processed. */
2505 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2506 list_del(&fcport->list);
2511 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2512 "rval=%d\n", ha->host_no, rval));
2520 * qla2x00_find_all_fabric_devs
2523 * ha = adapter block pointer.
2524 * dev = database device entry pointer.
2533 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2537 fc_port_t *fcport, *new_fcport, *fcptemp;
2542 int first_dev, last_dev;
2543 port_id_t wrap, nxt_d_id;
2547 scsi_qla_host_t *vha;
2548 scsi_qla_host_t *pha = to_qla_parent(ha);
2552 /* Try GID_PT to get device list, else GAN. */
2553 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_ATOMIC);
2556 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2557 "on GA_NXT\n", ha->host_no));
2559 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2562 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2565 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2568 } else if (qla2x00_gfpn_id(ha, swl) == QLA_SUCCESS) {
2569 qla2x00_gpsc(ha, swl);
2574 /* Allocate temporary fcport for any new fcports discovered. */
2575 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2576 if (new_fcport == NULL) {
2578 return (QLA_MEMORY_ALLOC_FAILED);
2580 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2581 new_fcport->vp_idx = ha->vp_idx;
2582 /* Set start port ID scan at adapter ID. */
2586 /* Starting free loop ID. */
2587 loop_id = pha->min_external_loopid;
2588 for (; loop_id <= ha->last_loop_id; loop_id++) {
2589 if (qla2x00_is_reserved_id(ha, loop_id))
2592 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2597 wrap.b24 = new_fcport->d_id.b24;
2599 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2600 memcpy(new_fcport->node_name,
2601 swl[swl_idx].node_name, WWN_SIZE);
2602 memcpy(new_fcport->port_name,
2603 swl[swl_idx].port_name, WWN_SIZE);
2604 memcpy(new_fcport->fabric_port_name,
2605 swl[swl_idx].fabric_port_name, WWN_SIZE);
2606 new_fcport->fp_speed = swl[swl_idx].fp_speed;
2608 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2614 /* Send GA_NXT to the switch */
2615 rval = qla2x00_ga_nxt(ha, new_fcport);
2616 if (rval != QLA_SUCCESS) {
2617 qla_printk(KERN_WARNING, ha,
2618 "SNS scan failed -- assuming zero-entry "
2620 list_for_each_entry_safe(fcport, fcptemp,
2621 new_fcports, list) {
2622 list_del(&fcport->list);
2630 /* If wrap on switch device list, exit. */
2632 wrap.b24 = new_fcport->d_id.b24;
2634 } else if (new_fcport->d_id.b24 == wrap.b24) {
2635 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2636 ha->host_no, new_fcport->d_id.b.domain,
2637 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2641 /* Bypass if same physical adapter. */
2642 if (new_fcport->d_id.b24 == pha->d_id.b24)
2645 /* Bypass virtual ports of the same host. */
2646 if (pha->num_vhosts) {
2647 for_each_mapped_vp_idx(pha, vp_index) {
2650 list_for_each_entry(vha, &pha->vp_list,
2652 if (vp_index == vha->vp_idx) {
2663 new_fcport->d_id.b24 == vha->d_id.b24)
2667 if (vp_index <= pha->max_npiv_vports)
2671 /* Bypass if same domain and area of adapter. */
2672 if (((new_fcport->d_id.b24 & 0xffff00) ==
2673 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2677 /* Bypass reserved domain fields. */
2678 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2681 /* Locate matching device in database. */
2683 list_for_each_entry(fcport, &pha->fcports, list) {
2684 if (new_fcport->vp_idx != fcport->vp_idx)
2686 if (memcmp(new_fcport->port_name, fcport->port_name,
2692 /* Update port state. */
2693 memcpy(fcport->fabric_port_name,
2694 new_fcport->fabric_port_name, WWN_SIZE);
2695 fcport->fp_speed = new_fcport->fp_speed;
2698 * If address the same and state FCS_ONLINE, nothing
2701 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2702 atomic_read(&fcport->state) == FCS_ONLINE) {
2707 * If device was not a fabric device before.
2709 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2710 fcport->d_id.b24 = new_fcport->d_id.b24;
2711 fcport->loop_id = FC_NO_LOOP_ID;
2712 fcport->flags |= (FCF_FABRIC_DEVICE |
2714 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2719 * Port ID changed or device was marked to be updated;
2720 * Log it out if still logged in and mark it for
2723 fcport->d_id.b24 = new_fcport->d_id.b24;
2724 fcport->flags |= FCF_LOGIN_NEEDED;
2725 if (fcport->loop_id != FC_NO_LOOP_ID &&
2726 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2727 fcport->port_type != FCT_INITIATOR &&
2728 fcport->port_type != FCT_BROADCAST) {
2729 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
2730 fcport->d_id.b.domain, fcport->d_id.b.area,
2731 fcport->d_id.b.al_pa);
2732 fcport->loop_id = FC_NO_LOOP_ID;
2741 /* If device was not in our fcports list, then add it. */
2742 list_add_tail(&new_fcport->list, new_fcports);
2744 /* Allocate a new replacement fcport. */
2745 nxt_d_id.b24 = new_fcport->d_id.b24;
2746 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2747 if (new_fcport == NULL) {
2749 return (QLA_MEMORY_ALLOC_FAILED);
2751 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2752 new_fcport->d_id.b24 = nxt_d_id.b24;
2753 new_fcport->vp_idx = ha->vp_idx;
2759 if (!list_empty(new_fcports))
2760 ha->device_flags |= DFLG_FABRIC_DEVICES;
2766 * qla2x00_find_new_loop_id
2767 * Scan through our port list and find a new usable loop ID.
2770 * ha: adapter state pointer.
2771 * dev: port structure pointer.
2774 * qla2x00 local function return status code.
2780 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2785 uint16_t first_loop_id;
2786 scsi_qla_host_t *pha = to_qla_parent(ha);
2790 /* Save starting loop ID. */
2791 first_loop_id = dev->loop_id;
2794 /* Skip loop ID if already used by adapter. */
2795 if (dev->loop_id == ha->loop_id) {
2799 /* Skip reserved loop IDs. */
2800 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2804 /* Reset loop ID if passed the end. */
2805 if (dev->loop_id > ha->last_loop_id) {
2806 /* first loop ID. */
2807 dev->loop_id = ha->min_external_loopid;
2810 /* Check for loop ID being already in use. */
2813 list_for_each_entry(fcport, &pha->fcports, list) {
2814 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2815 /* ID possibly in use */
2821 /* If not in use then it is free to use. */
2826 /* ID in use. Try next value. */
2829 /* If wrap around. No free ID to use. */
2830 if (dev->loop_id == first_loop_id) {
2831 dev->loop_id = FC_NO_LOOP_ID;
2832 rval = QLA_FUNCTION_FAILED;
2841 * qla2x00_device_resync
2842 * Marks devices in the database that needs resynchronization.
2845 * ha = adapter block pointer.
2851 qla2x00_device_resync(scsi_qla_host_t *ha)
2856 uint32_t rscn_entry;
2857 uint8_t rscn_out_iter;
2860 scsi_qla_host_t *pha = to_qla_parent(ha);
2862 rval = QLA_RSCNS_HANDLED;
2864 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2865 ha->flags.rscn_queue_overflow) {
2867 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2868 format = MSB(MSW(rscn_entry));
2869 d_id.b.domain = LSB(MSW(rscn_entry));
2870 d_id.b.area = MSB(LSW(rscn_entry));
2871 d_id.b.al_pa = LSB(LSW(rscn_entry));
2873 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2874 "[%02x/%02x%02x%02x].\n",
2875 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2876 d_id.b.area, d_id.b.al_pa));
2879 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2880 ha->rscn_out_ptr = 0;
2882 /* Skip duplicate entries. */
2883 for (rscn_out_iter = ha->rscn_out_ptr;
2884 !ha->flags.rscn_queue_overflow &&
2885 rscn_out_iter != ha->rscn_in_ptr;
2886 rscn_out_iter = (rscn_out_iter ==
2887 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2889 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2892 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2893 "entry found at [%d].\n", ha->host_no,
2896 ha->rscn_out_ptr = rscn_out_iter;
2899 /* Queue overflow, set switch default case. */
2900 if (ha->flags.rscn_queue_overflow) {
2901 DEBUG(printk("scsi(%ld): device_resync: rscn "
2902 "overflow.\n", ha->host_no));
2905 ha->flags.rscn_queue_overflow = 0;
2921 ha->rscn_out_ptr = ha->rscn_in_ptr;
2927 list_for_each_entry(fcport, &pha->fcports, list) {
2928 if (fcport->vp_idx != ha->vp_idx)
2931 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2932 (fcport->d_id.b24 & mask) != d_id.b24 ||
2933 fcport->port_type == FCT_BROADCAST)
2936 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2938 fcport->port_type != FCT_INITIATOR) {
2939 qla2x00_mark_device_lost(ha, fcport,
2943 fcport->flags &= ~FCF_FARP_DONE;
2950 * qla2x00_fabric_dev_login
2951 * Login fabric target device and update FC port database.
2954 * ha: adapter state pointer.
2955 * fcport: port structure list pointer.
2956 * next_loopid: contains value of a new loop ID that can be used
2957 * by the next login attempt.
2960 * qla2x00 local function return status code.
2966 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2967 uint16_t *next_loopid)
2976 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2977 if (rval == QLA_SUCCESS) {
2978 /* Send an ADISC to tape devices.*/
2980 if (fcport->flags & FCF_TAPE_PRESENT)
2982 rval = qla2x00_get_port_database(ha, fcport, opts);
2983 if (rval != QLA_SUCCESS) {
2984 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
2985 fcport->d_id.b.domain, fcport->d_id.b.area,
2986 fcport->d_id.b.al_pa);
2987 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2989 qla2x00_update_fcport(ha, fcport);
2997 * qla2x00_fabric_login
2998 * Issue fabric login command.
3001 * ha = adapter block pointer.
3002 * device = pointer to FC device type structure.
3005 * 0 - Login successfully
3007 * 2 - Initiator device
3011 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
3012 uint16_t *next_loopid)
3016 uint16_t tmp_loopid;
3017 uint16_t mb[MAILBOX_REGISTER_COUNT];
3023 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3024 "for port %02x%02x%02x.\n",
3025 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
3026 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3028 /* Login fcport on switch. */
3029 ha->isp_ops->fabric_login(ha, fcport->loop_id,
3030 fcport->d_id.b.domain, fcport->d_id.b.area,
3031 fcport->d_id.b.al_pa, mb, BIT_0);
3032 if (mb[0] == MBS_PORT_ID_USED) {
3034 * Device has another loop ID. The firmware team
3035 * recommends the driver perform an implicit login with
3036 * the specified ID again. The ID we just used is save
3037 * here so we return with an ID that can be tried by
3041 tmp_loopid = fcport->loop_id;
3042 fcport->loop_id = mb[1];
3044 DEBUG(printk("Fabric Login: port in use - next "
3045 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3046 fcport->loop_id, fcport->d_id.b.domain,
3047 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3049 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3054 /* A retry occurred before. */
3055 *next_loopid = tmp_loopid;
3058 * No retry occurred before. Just increment the
3059 * ID value for next login.
3061 *next_loopid = (fcport->loop_id + 1);
3064 if (mb[1] & BIT_0) {
3065 fcport->port_type = FCT_INITIATOR;
3067 fcport->port_type = FCT_TARGET;
3068 if (mb[1] & BIT_1) {
3069 fcport->flags |= FCF_TAPE_PRESENT;
3074 fcport->supported_classes |= FC_COS_CLASS2;
3076 fcport->supported_classes |= FC_COS_CLASS3;
3080 } else if (mb[0] == MBS_LOOP_ID_USED) {
3082 * Loop ID already used, try next loop ID.
3085 rval = qla2x00_find_new_loop_id(ha, fcport);
3086 if (rval != QLA_SUCCESS) {
3087 /* Ran out of loop IDs to use */
3090 } else if (mb[0] == MBS_COMMAND_ERROR) {
3092 * Firmware possibly timed out during login. If NO
3093 * retries are left to do then the device is declared
3096 *next_loopid = fcport->loop_id;
3097 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
3098 fcport->d_id.b.domain, fcport->d_id.b.area,
3099 fcport->d_id.b.al_pa);
3100 qla2x00_mark_device_lost(ha, fcport, 1, 0);
3106 * unrecoverable / not handled error
3108 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3109 "loop_id=%x jiffies=%lx.\n",
3110 __func__, ha->host_no, mb[0],
3111 fcport->d_id.b.domain, fcport->d_id.b.area,
3112 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3114 *next_loopid = fcport->loop_id;
3115 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
3116 fcport->d_id.b.domain, fcport->d_id.b.area,
3117 fcport->d_id.b.al_pa);
3118 fcport->loop_id = FC_NO_LOOP_ID;
3119 fcport->login_retry = 0;
3130 * qla2x00_local_device_login
3131 * Issue local device login command.
3134 * ha = adapter block pointer.
3135 * loop_id = loop id of device to login to.
3137 * Returns (Where's the #define!!!!):
3138 * 0 - Login successfully
3143 qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
3146 uint16_t mb[MAILBOX_REGISTER_COUNT];
3148 memset(mb, 0, sizeof(mb));
3149 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
3150 if (rval == QLA_SUCCESS) {
3151 /* Interrogate mailbox registers for any errors */
3152 if (mb[0] == MBS_COMMAND_ERROR)
3154 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3155 /* device not in PCB table */
3163 * qla2x00_loop_resync
3164 * Resync with fibre channel devices.
3167 * ha = adapter block pointer.
3173 qla2x00_loop_resync(scsi_qla_host_t *ha)
3180 atomic_set(&ha->loop_state, LOOP_UPDATE);
3181 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3182 if (ha->flags.online) {
3183 if (!(rval = qla2x00_fw_ready(ha))) {
3184 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3187 atomic_set(&ha->loop_state, LOOP_UPDATE);
3189 /* Issue a marker after FW becomes ready. */
3190 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3191 ha->marker_needed = 0;
3193 /* Remap devices on Loop. */
3194 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3196 qla2x00_configure_loop(ha);
3198 } while (!atomic_read(&ha->loop_down_timer) &&
3199 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3201 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3205 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3206 return (QLA_FUNCTION_FAILED);
3210 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3217 qla2x00_update_fcports(scsi_qla_host_t *ha)
3221 /* Go with deferred removal of rport references. */
3222 list_for_each_entry(fcport, &ha->fcports, list)
3224 qla2x00_rport_del(fcport);
3229 * Resets ISP and aborts all outstanding commands.
3232 * ha = adapter block pointer.
3238 qla2x00_abort_isp(scsi_qla_host_t *ha)
3243 if (ha->flags.online) {
3244 ha->flags.online = 0;
3245 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3247 qla_printk(KERN_INFO, ha,
3248 "Performing ISP error recovery - ha= %p.\n", ha);
3249 ha->isp_ops->reset_chip(ha);
3251 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3252 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3253 atomic_set(&ha->loop_state, LOOP_DOWN);
3254 qla2x00_mark_all_devices_lost(ha, 0);
3256 if (!atomic_read(&ha->loop_down_timer))
3257 atomic_set(&ha->loop_down_timer,
3261 /* Requeue all commands in outstanding command list. */
3262 qla2x00_abort_all_cmds(ha, DID_RESET << 16);
3264 ha->isp_ops->get_flash_version(ha, ha->request_ring);
3266 ha->isp_ops->nvram_config(ha);
3268 if (!qla2x00_restart_isp(ha)) {
3269 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3271 if (!atomic_read(&ha->loop_down_timer)) {
3273 * Issue marker command only when we are going
3274 * to start the I/O .
3276 ha->marker_needed = 1;
3279 ha->flags.online = 1;
3281 ha->isp_ops->enable_intrs(ha);
3283 ha->isp_abort_cnt = 0;
3284 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3287 memset(ha->eft, 0, EFT_SIZE);
3288 rval = qla2x00_enable_eft_trace(ha,
3289 ha->eft_dma, EFT_NUM_BUFFERS);
3291 qla_printk(KERN_WARNING, ha,
3292 "Unable to reinitialize EFT "
3298 ha->flags.fce_enabled = 1;
3300 fce_calc_size(ha->fce_bufs));
3301 rval = qla2x00_enable_fce_trace(ha,
3302 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3305 qla_printk(KERN_WARNING, ha,
3306 "Unable to reinitialize FCE "
3308 ha->flags.fce_enabled = 0;
3311 } else { /* failed the ISP abort */
3312 ha->flags.online = 1;
3313 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3314 if (ha->isp_abort_cnt == 0) {
3315 qla_printk(KERN_WARNING, ha,
3316 "ISP error recovery failed - "
3317 "board disabled\n");
3319 * The next call disables the board
3322 ha->isp_ops->reset_adapter(ha);
3323 ha->flags.online = 0;
3324 clear_bit(ISP_ABORT_RETRY,
3327 } else { /* schedule another ISP abort */
3328 ha->isp_abort_cnt--;
3329 DEBUG(printk("qla%ld: ISP abort - "
3330 "retry remaining %d\n",
3331 ha->host_no, ha->isp_abort_cnt));
3335 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3336 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3337 "- retrying (%d) more times\n",
3338 ha->host_no, ha->isp_abort_cnt));
3339 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3347 qla_printk(KERN_INFO, ha,
3348 "qla2x00_abort_isp: **** FAILED ****\n");
3350 DEBUG(printk(KERN_INFO
3351 "qla2x00_abort_isp(%ld): exiting.\n",
3359 * qla2x00_restart_isp
3360 * restarts the ISP after a reset
3363 * ha = adapter block pointer.
3369 qla2x00_restart_isp(scsi_qla_host_t *ha)
3374 /* If firmware needs to be loaded */
3375 if (qla2x00_isp_firmware(ha)) {
3376 ha->flags.online = 0;
3377 if (!(status = ha->isp_ops->chip_diag(ha)))
3378 status = qla2x00_setup_chip(ha);
3381 if (!status && !(status = qla2x00_init_rings(ha))) {
3382 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3383 if (!(status = qla2x00_fw_ready(ha))) {
3384 DEBUG(printk("%s(): Start configure loop, "
3385 "status = %d\n", __func__, status));
3387 /* Issue a marker after FW becomes ready. */
3388 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3390 ha->flags.online = 1;
3391 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3394 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3395 qla2x00_configure_loop(ha);
3397 } while (!atomic_read(&ha->loop_down_timer) &&
3398 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3400 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3403 /* if no cable then assume it's good */
3404 if ((ha->device_flags & DFLG_NO_CABLE))
3407 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3415 * qla2x00_reset_adapter
3419 * ha = adapter block pointer.
3422 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3424 unsigned long flags = 0;
3425 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3427 ha->flags.online = 0;
3428 ha->isp_ops->disable_intrs(ha);
3430 spin_lock_irqsave(&ha->hardware_lock, flags);
3431 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3432 RD_REG_WORD(®->hccr); /* PCI Posting. */
3433 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3434 RD_REG_WORD(®->hccr); /* PCI Posting. */
3435 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3439 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3441 unsigned long flags = 0;
3442 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3444 ha->flags.online = 0;
3445 ha->isp_ops->disable_intrs(ha);
3447 spin_lock_irqsave(&ha->hardware_lock, flags);
3448 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3449 RD_REG_DWORD(®->hccr);
3450 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3451 RD_REG_DWORD(®->hccr);
3452 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3455 /* On sparc systems, obtain port and node WWN from firmware
3458 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, struct nvram_24xx *nv)
3461 struct pci_dev *pdev = ha->pdev;
3462 struct device_node *dp = pci_device_to_OF_node(pdev);
3466 val = of_get_property(dp, "port-wwn", &len);
3467 if (val && len >= WWN_SIZE)
3468 memcpy(nv->port_name, val, WWN_SIZE);
3470 val = of_get_property(dp, "node-wwn", &len);
3471 if (val && len >= WWN_SIZE)
3472 memcpy(nv->node_name, val, WWN_SIZE);
3477 qla24xx_nvram_config(scsi_qla_host_t *ha)
3480 struct init_cb_24xx *icb;
3481 struct nvram_24xx *nv;
3483 uint8_t *dptr1, *dptr2;
3488 icb = (struct init_cb_24xx *)ha->init_cb;
3491 /* Determine NVRAM starting address. */
3492 ha->nvram_size = sizeof(struct nvram_24xx);
3493 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3494 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3495 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3496 if (PCI_FUNC(ha->pdev->devfn)) {
3497 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3498 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3501 /* Get VPD data into cache */
3502 ha->vpd = ha->nvram + VPD_OFFSET;
3503 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd,
3504 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3506 /* Get NVRAM data into cache and calculate checksum. */
3507 dptr = (uint32_t *)nv;
3508 ha->isp_ops->read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3510 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3511 chksum += le32_to_cpu(*dptr++);
3513 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3514 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
3516 /* Bad NVRAM data, set defaults parameters. */
3517 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3518 || nv->id[3] != ' ' ||
3519 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3520 /* Reset NVRAM data. */
3521 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3522 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3523 le16_to_cpu(nv->nvram_version));
3524 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3525 "invalid -- WWPN) defaults.\n");
3528 * Set default initialization control block.
3530 memset(nv, 0, ha->nvram_size);
3531 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3532 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3533 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3534 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3535 nv->exchange_count = __constant_cpu_to_le16(0);
3536 nv->hard_address = __constant_cpu_to_le16(124);
3537 nv->port_name[0] = 0x21;
3538 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3539 nv->port_name[2] = 0x00;
3540 nv->port_name[3] = 0xe0;
3541 nv->port_name[4] = 0x8b;
3542 nv->port_name[5] = 0x1c;
3543 nv->port_name[6] = 0x55;
3544 nv->port_name[7] = 0x86;
3545 nv->node_name[0] = 0x20;
3546 nv->node_name[1] = 0x00;
3547 nv->node_name[2] = 0x00;
3548 nv->node_name[3] = 0xe0;
3549 nv->node_name[4] = 0x8b;
3550 nv->node_name[5] = 0x1c;
3551 nv->node_name[6] = 0x55;
3552 nv->node_name[7] = 0x86;
3553 qla24xx_nvram_wwn_from_ofw(ha, nv);
3554 nv->login_retry_count = __constant_cpu_to_le16(8);
3555 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3556 nv->login_timeout = __constant_cpu_to_le16(0);
3557 nv->firmware_options_1 =
3558 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3559 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3560 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3561 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3562 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3563 nv->efi_parameters = __constant_cpu_to_le32(0);
3564 nv->reset_delay = 5;
3565 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3566 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3567 nv->link_down_timeout = __constant_cpu_to_le16(30);
3572 /* Reset Initialization control block */
3573 memset(icb, 0, sizeof(struct init_cb_24xx));
3575 /* Copy 1st segment. */
3576 dptr1 = (uint8_t *)icb;
3577 dptr2 = (uint8_t *)&nv->version;
3578 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3580 *dptr1++ = *dptr2++;
3582 icb->login_retry_count = nv->login_retry_count;
3583 icb->link_down_on_nos = nv->link_down_on_nos;
3585 /* Copy 2nd segment. */
3586 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3587 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3588 cnt = (uint8_t *)&icb->reserved_3 -
3589 (uint8_t *)&icb->interrupt_delay_timer;
3591 *dptr1++ = *dptr2++;
3594 * Setup driver NVRAM options.
3596 qla2x00_set_model_info(ha, nv->model_name, sizeof(nv->model_name),
3599 /* Use alternate WWN? */
3600 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3601 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3602 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3605 /* Prepare nodename */
3606 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3608 * Firmware will apply the following mask if the nodename was
3611 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3612 icb->node_name[0] &= 0xF0;
3615 /* Set host adapter parameters. */
3616 ha->flags.disable_risc_code_load = 0;
3617 ha->flags.enable_lip_reset = 0;
3618 ha->flags.enable_lip_full_login =
3619 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3620 ha->flags.enable_target_reset =
3621 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
3622 ha->flags.enable_led_scheme = 0;
3623 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
3625 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3626 (BIT_6 | BIT_5 | BIT_4)) >> 4;
3628 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3629 sizeof(ha->fw_seriallink_options24));
3631 /* save HBA serial number */
3632 ha->serial0 = icb->port_name[5];
3633 ha->serial1 = icb->port_name[6];
3634 ha->serial2 = icb->port_name[7];
3635 ha->node_name = icb->node_name;
3636 ha->port_name = icb->port_name;
3638 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3640 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3642 /* Set minimum login_timeout to 4 seconds. */
3643 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3644 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3645 if (le16_to_cpu(nv->login_timeout) < 4)
3646 nv->login_timeout = __constant_cpu_to_le16(4);
3647 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3648 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3650 /* Set minimum RATOV to 100 tenths of a second. */
3653 ha->loop_reset_delay = nv->reset_delay;
3655 /* Link Down Timeout = 0:
3657 * When Port Down timer expires we will start returning
3658 * I/O's to OS with "DID_NO_CONNECT".
3660 * Link Down Timeout != 0:
3662 * The driver waits for the link to come up after link down
3663 * before returning I/Os to OS with "DID_NO_CONNECT".
3665 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3666 ha->loop_down_abort_time =
3667 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3669 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3670 ha->loop_down_abort_time =
3671 (LOOP_DOWN_TIME - ha->link_down_timeout);
3674 /* Need enough time to try and get the port back. */
3675 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3676 if (qlport_down_retry)
3677 ha->port_down_retry_count = qlport_down_retry;
3679 /* Set login_retry_count */
3680 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3681 if (ha->port_down_retry_count ==
3682 le16_to_cpu(nv->port_down_retry_count) &&
3683 ha->port_down_retry_count > 3)
3684 ha->login_retry_count = ha->port_down_retry_count;
3685 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3686 ha->login_retry_count = ha->port_down_retry_count;
3687 if (ql2xloginretrycount)
3688 ha->login_retry_count = ql2xloginretrycount;
3691 if (!ha->flags.init_done) {
3692 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3693 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3694 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3695 le16_to_cpu(icb->interrupt_delay_timer): 2;
3697 icb->firmware_options_2 &= __constant_cpu_to_le32(
3698 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3699 ha->flags.process_response_queue = 0;
3700 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3701 ha->zio_mode = QLA_ZIO_MODE_6;
3703 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3704 "(%d us).\n", ha->host_no, ha->zio_mode,
3705 ha->zio_timer * 100));
3706 qla_printk(KERN_INFO, ha,
3707 "ZIO mode %d enabled; timer delay (%d us).\n",
3708 ha->zio_mode, ha->zio_timer * 100);
3710 icb->firmware_options_2 |= cpu_to_le32(
3711 (uint32_t)ha->zio_mode);
3712 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3713 ha->flags.process_response_queue = 1;
3717 DEBUG2_3(printk(KERN_WARNING
3718 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3724 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3727 int segments, fragment;
3729 uint32_t *dcode, dlen;
3736 segments = FA_RISC_CODE_SEGMENTS;
3737 faddr = FA_RISC_CODE_ADDR;
3738 dcode = (uint32_t *)ha->request_ring;
3741 /* Validate firmware image by checking version. */
3742 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3743 for (i = 0; i < 4; i++)
3744 dcode[i] = be32_to_cpu(dcode[i]);
3745 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3746 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3747 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3749 qla_printk(KERN_WARNING, ha,
3750 "Unable to verify integrity of flash firmware image!\n");
3751 qla_printk(KERN_WARNING, ha,
3752 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3753 dcode[1], dcode[2], dcode[3]);
3755 return QLA_FUNCTION_FAILED;
3758 while (segments && rval == QLA_SUCCESS) {
3759 /* Read segment's load information. */
3760 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3762 risc_addr = be32_to_cpu(dcode[2]);
3763 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3764 risc_size = be32_to_cpu(dcode[3]);
3767 while (risc_size > 0 && rval == QLA_SUCCESS) {
3768 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3769 if (dlen > risc_size)
3772 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3773 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3774 ha->host_no, risc_addr, dlen, faddr));
3776 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3777 for (i = 0; i < dlen; i++)
3778 dcode[i] = swab32(dcode[i]);
3780 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3783 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3784 "segment %d of firmware\n", ha->host_no,
3786 qla_printk(KERN_WARNING, ha,
3787 "[ERROR] Failed to load segment %d of "
3788 "firmware\n", fragment);
3805 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3808 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3812 uint16_t *wcode, *fwcode;
3813 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3814 struct fw_blob *blob;
3816 /* Load firmware blob. */
3817 blob = qla2x00_request_firmware(ha);
3819 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3820 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3821 "from: " QLA_FW_URL ".\n");
3822 return QLA_FUNCTION_FAILED;
3827 wcode = (uint16_t *)ha->request_ring;
3829 fwcode = (uint16_t *)blob->fw->data;
3832 /* Validate firmware image by checking version. */
3833 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3834 qla_printk(KERN_WARNING, ha,
3835 "Unable to verify integrity of firmware image (%Zd)!\n",
3837 goto fail_fw_integrity;
3839 for (i = 0; i < 4; i++)
3840 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3841 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3842 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3843 wcode[2] == 0 && wcode[3] == 0)) {
3844 qla_printk(KERN_WARNING, ha,
3845 "Unable to verify integrity of firmware image!\n");
3846 qla_printk(KERN_WARNING, ha,
3847 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3848 wcode[1], wcode[2], wcode[3]);
3849 goto fail_fw_integrity;
3853 while (*seg && rval == QLA_SUCCESS) {
3855 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3856 risc_size = be16_to_cpu(fwcode[3]);
3858 /* Validate firmware image size. */
3859 fwclen += risc_size * sizeof(uint16_t);
3860 if (blob->fw->size < fwclen) {
3861 qla_printk(KERN_WARNING, ha,
3862 "Unable to verify integrity of firmware image "
3863 "(%Zd)!\n", blob->fw->size);
3864 goto fail_fw_integrity;
3868 while (risc_size > 0 && rval == QLA_SUCCESS) {
3869 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3870 if (wlen > risc_size)
3873 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3874 "addr %x, number of words 0x%x.\n", ha->host_no,
3877 for (i = 0; i < wlen; i++)
3878 wcode[i] = swab16(fwcode[i]);
3880 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3883 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3884 "segment %d of firmware\n", ha->host_no,
3886 qla_printk(KERN_WARNING, ha,
3887 "[ERROR] Failed to load segment %d of "
3888 "firmware\n", fragment);
3904 return QLA_FUNCTION_FAILED;
3908 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3911 int segments, fragment;
3912 uint32_t *dcode, dlen;
3916 struct fw_blob *blob;
3917 uint32_t *fwcode, fwclen;
3919 /* Load firmware blob. */
3920 blob = qla2x00_request_firmware(ha);
3922 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3923 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3924 "from: " QLA_FW_URL ".\n");
3926 /* Try to load RISC code from flash. */
3927 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3928 "outdated) firmware from flash.\n");
3929 return qla24xx_load_risc_flash(ha, srisc_addr);
3934 segments = FA_RISC_CODE_SEGMENTS;
3935 dcode = (uint32_t *)ha->request_ring;
3937 fwcode = (uint32_t *)blob->fw->data;
3940 /* Validate firmware image by checking version. */
3941 if (blob->fw->size < 8 * sizeof(uint32_t)) {
3942 qla_printk(KERN_WARNING, ha,
3943 "Unable to verify integrity of firmware image (%Zd)!\n",
3945 goto fail_fw_integrity;
3947 for (i = 0; i < 4; i++)
3948 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3949 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3950 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3951 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3953 qla_printk(KERN_WARNING, ha,
3954 "Unable to verify integrity of firmware image!\n");
3955 qla_printk(KERN_WARNING, ha,
3956 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3957 dcode[1], dcode[2], dcode[3]);
3958 goto fail_fw_integrity;
3961 while (segments && rval == QLA_SUCCESS) {
3962 risc_addr = be32_to_cpu(fwcode[2]);
3963 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3964 risc_size = be32_to_cpu(fwcode[3]);
3966 /* Validate firmware image size. */
3967 fwclen += risc_size * sizeof(uint32_t);
3968 if (blob->fw->size < fwclen) {
3969 qla_printk(KERN_WARNING, ha,
3970 "Unable to verify integrity of firmware image "
3971 "(%Zd)!\n", blob->fw->size);
3973 goto fail_fw_integrity;
3977 while (risc_size > 0 && rval == QLA_SUCCESS) {
3978 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3979 if (dlen > risc_size)
3982 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3983 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3986 for (i = 0; i < dlen; i++)
3987 dcode[i] = swab32(fwcode[i]);
3989 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3992 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3993 "segment %d of firmware\n", ha->host_no,
3995 qla_printk(KERN_WARNING, ha,
3996 "[ERROR] Failed to load segment %d of "
3997 "firmware\n", fragment);
4013 return QLA_FUNCTION_FAILED;
4017 qla2x00_try_to_stop_firmware(scsi_qla_host_t *ha)
4021 if (!IS_FWI2_CAPABLE(ha))
4023 if (!ha->fw_major_version)
4026 ret = qla2x00_stop_firmware(ha);
4027 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4028 retries ; retries--) {
4029 qla2x00_reset_chip(ha);
4030 if (qla2x00_chip_diag(ha) != QLA_SUCCESS)
4032 if (qla2x00_setup_chip(ha) != QLA_SUCCESS)
4034 qla_printk(KERN_INFO, ha,
4035 "Attempting retry of stop-firmware command...\n");
4036 ret = qla2x00_stop_firmware(ha);
4041 qla24xx_configure_vhba(scsi_qla_host_t *ha)
4043 int rval = QLA_SUCCESS;
4044 uint16_t mb[MAILBOX_REGISTER_COUNT];
4049 rval = qla2x00_fw_ready(ha->parent);
4050 if (rval == QLA_SUCCESS) {
4051 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
4052 qla2x00_marker(ha->parent, 0, 0, MK_SYNC_ALL);
4055 ha->flags.management_server_logged_in = 0;
4057 /* Login to SNS first */
4058 qla24xx_login_fabric(ha->parent, NPH_SNS, 0xff, 0xff, 0xfc,
4060 if (mb[0] != MBS_COMMAND_COMPLETE) {
4061 DEBUG15(qla_printk(KERN_INFO, ha,
4062 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4063 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4064 mb[0], mb[1], mb[2], mb[6], mb[7]));
4065 return (QLA_FUNCTION_FAILED);
4068 atomic_set(&ha->loop_down_timer, 0);
4069 atomic_set(&ha->loop_state, LOOP_UP);
4070 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4071 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
4072 rval = qla2x00_loop_resync(ha->parent);
4077 /* 84XX Support **************************************************************/
4079 static LIST_HEAD(qla_cs84xx_list);
4080 static DEFINE_MUTEX(qla_cs84xx_mutex);
4082 static struct qla_chip_state_84xx *
4083 qla84xx_get_chip(struct scsi_qla_host *ha)
4085 struct qla_chip_state_84xx *cs84xx;
4087 mutex_lock(&qla_cs84xx_mutex);
4089 /* Find any shared 84xx chip. */
4090 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4091 if (cs84xx->bus == ha->pdev->bus) {
4092 kref_get(&cs84xx->kref);
4097 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4101 kref_init(&cs84xx->kref);
4102 spin_lock_init(&cs84xx->access_lock);
4103 mutex_init(&cs84xx->fw_update_mutex);
4104 cs84xx->bus = ha->pdev->bus;
4106 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4108 mutex_unlock(&qla_cs84xx_mutex);
4113 __qla84xx_chip_release(struct kref *kref)
4115 struct qla_chip_state_84xx *cs84xx =
4116 container_of(kref, struct qla_chip_state_84xx, kref);
4118 mutex_lock(&qla_cs84xx_mutex);
4119 list_del(&cs84xx->list);
4120 mutex_unlock(&qla_cs84xx_mutex);
4125 qla84xx_put_chip(struct scsi_qla_host *ha)
4128 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4132 qla84xx_init_chip(scsi_qla_host_t *ha)
4137 mutex_lock(&ha->cs84xx->fw_update_mutex);
4139 rval = qla84xx_verify_chip(ha, status);
4141 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4143 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED: