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 rval = qla2xxx_get_flash_info(ha);
88 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
93 ha->isp_ops->get_flash_version(ha, ha->request_ring);
95 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
97 ha->isp_ops->nvram_config(ha);
99 if (ha->flags.disable_serdes) {
100 /* Mask HBA via NVRAM settings? */
101 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
102 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
103 ha->port_name[0], ha->port_name[1],
104 ha->port_name[2], ha->port_name[3],
105 ha->port_name[4], ha->port_name[5],
106 ha->port_name[6], ha->port_name[7]);
107 return QLA_FUNCTION_FAILED;
110 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
112 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
113 rval = ha->isp_ops->chip_diag(ha);
116 rval = qla2x00_setup_chip(ha);
120 if (IS_QLA84XX(ha)) {
121 ha->cs84xx = qla84xx_get_chip(ha);
123 qla_printk(KERN_ERR, ha,
124 "Unable to configure ISP84XX.\n");
125 return QLA_FUNCTION_FAILED;
128 rval = qla2x00_init_rings(ha);
134 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
137 * Returns 0 on success.
140 qla2100_pci_config(scsi_qla_host_t *ha)
145 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
147 pci_set_master(ha->pdev);
148 pci_try_set_mwi(ha->pdev);
150 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
151 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
152 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
154 /* Reset expansion ROM address decode enable */
155 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
156 d &= ~PCI_ROM_ADDRESS_ENABLE;
157 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
159 /* Get PCI bus information. */
160 spin_lock_irqsave(&ha->hardware_lock, flags);
161 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
162 spin_unlock_irqrestore(&ha->hardware_lock, flags);
168 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
171 * Returns 0 on success.
174 qla2300_pci_config(scsi_qla_host_t *ha)
178 unsigned long flags = 0;
180 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
182 pci_set_master(ha->pdev);
183 pci_try_set_mwi(ha->pdev);
185 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
186 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
188 if (IS_QLA2322(ha) || IS_QLA6322(ha))
189 w &= ~PCI_COMMAND_INTX_DISABLE;
190 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
193 * If this is a 2300 card and not 2312, reset the
194 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
195 * the 2310 also reports itself as a 2300 so we need to get the
196 * fb revision level -- a 6 indicates it really is a 2300 and
199 if (IS_QLA2300(ha)) {
200 spin_lock_irqsave(&ha->hardware_lock, flags);
203 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
204 for (cnt = 0; cnt < 30000; cnt++) {
205 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
211 /* Select FPM registers. */
212 WRT_REG_WORD(®->ctrl_status, 0x20);
213 RD_REG_WORD(®->ctrl_status);
215 /* Get the fb rev level */
216 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
218 if (ha->fb_rev == FPM_2300)
219 pci_clear_mwi(ha->pdev);
221 /* Deselect FPM registers. */
222 WRT_REG_WORD(®->ctrl_status, 0x0);
223 RD_REG_WORD(®->ctrl_status);
225 /* Release RISC module. */
226 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
227 for (cnt = 0; cnt < 30000; cnt++) {
228 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
234 spin_unlock_irqrestore(&ha->hardware_lock, flags);
237 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
239 /* Reset expansion ROM address decode enable */
240 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
241 d &= ~PCI_ROM_ADDRESS_ENABLE;
242 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
244 /* Get PCI bus information. */
245 spin_lock_irqsave(&ha->hardware_lock, flags);
246 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
247 spin_unlock_irqrestore(&ha->hardware_lock, flags);
253 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
256 * Returns 0 on success.
259 qla24xx_pci_config(scsi_qla_host_t *ha)
263 unsigned long flags = 0;
264 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
266 pci_set_master(ha->pdev);
267 pci_try_set_mwi(ha->pdev);
269 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
270 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
271 w &= ~PCI_COMMAND_INTX_DISABLE;
272 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
274 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
276 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
277 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
278 pcix_set_mmrbc(ha->pdev, 2048);
280 /* PCIe -- adjust Maximum Read Request Size (2048). */
281 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
282 pcie_set_readrq(ha->pdev, 2048);
284 /* Reset expansion ROM address decode enable */
285 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
286 d &= ~PCI_ROM_ADDRESS_ENABLE;
287 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
289 ha->chip_revision = ha->pdev->revision;
291 /* Get PCI bus information. */
292 spin_lock_irqsave(&ha->hardware_lock, flags);
293 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
294 spin_unlock_irqrestore(&ha->hardware_lock, flags);
300 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
303 * Returns 0 on success.
306 qla25xx_pci_config(scsi_qla_host_t *ha)
311 pci_set_master(ha->pdev);
312 pci_try_set_mwi(ha->pdev);
314 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
315 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
316 w &= ~PCI_COMMAND_INTX_DISABLE;
317 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
319 /* PCIe -- adjust Maximum Read Request Size (2048). */
320 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
321 pcie_set_readrq(ha->pdev, 2048);
323 /* Reset expansion ROM address decode enable */
324 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
325 d &= ~PCI_ROM_ADDRESS_ENABLE;
326 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
328 ha->chip_revision = ha->pdev->revision;
334 * qla2x00_isp_firmware() - Choose firmware image.
337 * Returns 0 on success.
340 qla2x00_isp_firmware(scsi_qla_host_t *ha)
343 uint16_t loop_id, topo, sw_cap;
344 uint8_t domain, area, al_pa;
346 /* Assume loading risc code */
347 rval = QLA_FUNCTION_FAILED;
349 if (ha->flags.disable_risc_code_load) {
350 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
352 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
354 /* Verify checksum of loaded RISC code. */
355 rval = qla2x00_verify_checksum(ha, ha->fw_srisc_address);
356 if (rval == QLA_SUCCESS) {
357 /* And, verify we are not in ROM code. */
358 rval = qla2x00_get_adapter_id(ha, &loop_id, &al_pa,
359 &area, &domain, &topo, &sw_cap);
364 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
372 * qla2x00_reset_chip() - Reset ISP chip.
375 * Returns 0 on success.
378 qla2x00_reset_chip(scsi_qla_host_t *ha)
380 unsigned long flags = 0;
381 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
385 ha->isp_ops->disable_intrs(ha);
387 spin_lock_irqsave(&ha->hardware_lock, flags);
389 /* Turn off master enable */
391 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
392 cmd &= ~PCI_COMMAND_MASTER;
393 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
395 if (!IS_QLA2100(ha)) {
397 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
398 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
399 for (cnt = 0; cnt < 30000; cnt++) {
400 if ((RD_REG_WORD(®->hccr) &
401 HCCR_RISC_PAUSE) != 0)
406 RD_REG_WORD(®->hccr); /* PCI Posting. */
410 /* Select FPM registers. */
411 WRT_REG_WORD(®->ctrl_status, 0x20);
412 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
414 /* FPM Soft Reset. */
415 WRT_REG_WORD(®->fpm_diag_config, 0x100);
416 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
418 /* Toggle Fpm Reset. */
419 if (!IS_QLA2200(ha)) {
420 WRT_REG_WORD(®->fpm_diag_config, 0x0);
421 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
424 /* Select frame buffer registers. */
425 WRT_REG_WORD(®->ctrl_status, 0x10);
426 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
428 /* Reset frame buffer FIFOs. */
429 if (IS_QLA2200(ha)) {
430 WRT_FB_CMD_REG(ha, reg, 0xa000);
431 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
433 WRT_FB_CMD_REG(ha, reg, 0x00fc);
435 /* Read back fb_cmd until zero or 3 seconds max */
436 for (cnt = 0; cnt < 3000; cnt++) {
437 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
443 /* Select RISC module registers. */
444 WRT_REG_WORD(®->ctrl_status, 0);
445 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
447 /* Reset RISC processor. */
448 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
449 RD_REG_WORD(®->hccr); /* PCI Posting. */
451 /* Release RISC processor. */
452 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
453 RD_REG_WORD(®->hccr); /* PCI Posting. */
456 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
457 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
459 /* Reset ISP chip. */
460 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
462 /* Wait for RISC to recover from reset. */
463 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
465 * It is necessary to for a delay here since the card doesn't
466 * respond to PCI reads during a reset. On some architectures
467 * this will result in an MCA.
470 for (cnt = 30000; cnt; cnt--) {
471 if ((RD_REG_WORD(®->ctrl_status) &
472 CSR_ISP_SOFT_RESET) == 0)
479 /* Reset RISC processor. */
480 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
482 WRT_REG_WORD(®->semaphore, 0);
484 /* Release RISC processor. */
485 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
486 RD_REG_WORD(®->hccr); /* PCI Posting. */
488 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
489 for (cnt = 0; cnt < 30000; cnt++) {
490 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
498 /* Turn on master enable */
499 cmd |= PCI_COMMAND_MASTER;
500 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
502 /* Disable RISC pause on FPM parity error. */
503 if (!IS_QLA2100(ha)) {
504 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
505 RD_REG_WORD(®->hccr); /* PCI Posting. */
508 spin_unlock_irqrestore(&ha->hardware_lock, flags);
512 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
515 * Returns 0 on success.
518 qla24xx_reset_risc(scsi_qla_host_t *ha)
521 unsigned long flags = 0;
522 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
526 spin_lock_irqsave(&ha->hardware_lock, flags);
529 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
530 for (cnt = 0; cnt < 30000; cnt++) {
531 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
537 WRT_REG_DWORD(®->ctrl_status,
538 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
539 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
542 /* Wait for firmware to complete NVRAM accesses. */
543 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
544 for (cnt = 10000 ; cnt && d2; cnt--) {
546 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
552 /* Wait for soft-reset to complete. */
553 d2 = RD_REG_DWORD(®->ctrl_status);
554 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
556 d2 = RD_REG_DWORD(®->ctrl_status);
559 if (cnt == 0 || hw_evt)
560 qla2xxx_hw_event_log(ha, HW_EVENT_RESET_ERR,
561 RD_REG_WORD(®->mailbox1), RD_REG_WORD(®->mailbox2),
562 RD_REG_WORD(®->mailbox3));
564 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
565 RD_REG_DWORD(®->hccr);
567 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
568 RD_REG_DWORD(®->hccr);
570 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
571 RD_REG_DWORD(®->hccr);
573 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
574 for (cnt = 6000000 ; cnt && d2; cnt--) {
576 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
580 spin_unlock_irqrestore(&ha->hardware_lock, flags);
584 * qla24xx_reset_chip() - Reset ISP24xx chip.
587 * Returns 0 on success.
590 qla24xx_reset_chip(scsi_qla_host_t *ha)
592 ha->isp_ops->disable_intrs(ha);
594 /* Perform RISC reset. */
595 qla24xx_reset_risc(ha);
599 * qla2x00_chip_diag() - Test chip for proper operation.
602 * Returns 0 on success.
605 qla2x00_chip_diag(scsi_qla_host_t *ha)
608 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
609 unsigned long flags = 0;
614 /* Assume a failed state */
615 rval = QLA_FUNCTION_FAILED;
617 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
618 ha->host_no, (u_long)®->flash_address));
620 spin_lock_irqsave(&ha->hardware_lock, flags);
622 /* Reset ISP chip. */
623 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
626 * We need to have a delay here since the card will not respond while
627 * in reset causing an MCA on some architectures.
630 data = qla2x00_debounce_register(®->ctrl_status);
631 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
633 data = RD_REG_WORD(®->ctrl_status);
638 goto chip_diag_failed;
640 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
643 /* Reset RISC processor. */
644 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
645 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
647 /* Workaround for QLA2312 PCI parity error */
648 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
649 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
650 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
652 data = RD_MAILBOX_REG(ha, reg, 0);
659 goto chip_diag_failed;
661 /* Check product ID of chip */
662 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
664 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
665 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
666 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
667 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
668 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
669 mb[3] != PROD_ID_3) {
670 qla_printk(KERN_WARNING, ha,
671 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
673 goto chip_diag_failed;
675 ha->product_id[0] = mb[1];
676 ha->product_id[1] = mb[2];
677 ha->product_id[2] = mb[3];
678 ha->product_id[3] = mb[4];
680 /* Adjust fw RISC transfer size */
681 if (ha->request_q_length > 1024)
682 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
684 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
685 ha->request_q_length;
687 if (IS_QLA2200(ha) &&
688 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
689 /* Limit firmware transfer size with a 2200A */
690 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
693 ha->device_type |= DT_ISP2200A;
694 ha->fw_transfer_size = 128;
697 /* Wrap Incoming Mailboxes Test. */
698 spin_unlock_irqrestore(&ha->hardware_lock, flags);
700 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
701 rval = qla2x00_mbx_reg_test(ha);
703 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
705 qla_printk(KERN_WARNING, ha,
706 "Failed mailbox send register test\n");
709 /* Flag a successful rval */
712 spin_lock_irqsave(&ha->hardware_lock, flags);
716 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
717 "****\n", ha->host_no));
719 spin_unlock_irqrestore(&ha->hardware_lock, flags);
725 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
728 * Returns 0 on success.
731 qla24xx_chip_diag(scsi_qla_host_t *ha)
735 /* Perform RISC reset. */
736 qla24xx_reset_risc(ha);
738 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * ha->request_q_length;
740 rval = qla2x00_mbx_reg_test(ha);
742 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
744 qla_printk(KERN_WARNING, ha,
745 "Failed mailbox send register test\n");
747 /* Flag a successful rval */
755 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
758 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
764 qla_printk(KERN_WARNING, ha,
765 "Firmware dump previously allocated.\n");
770 fixed_size = mem_size = eft_size = fce_size = 0;
771 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
772 fixed_size = sizeof(struct qla2100_fw_dump);
773 } else if (IS_QLA23XX(ha)) {
774 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
775 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
777 } else if (IS_FWI2_CAPABLE(ha)) {
778 fixed_size = IS_QLA25XX(ha) ?
779 offsetof(struct qla25xx_fw_dump, ext_mem):
780 offsetof(struct qla24xx_fw_dump, ext_mem);
781 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
784 /* Allocate memory for Fibre Channel Event Buffer. */
788 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
791 qla_printk(KERN_WARNING, ha, "Unable to allocate "
792 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
796 memset(tc, 0, FCE_SIZE);
797 rval = qla2x00_enable_fce_trace(ha, tc_dma, FCE_NUM_BUFFERS,
798 ha->fce_mb, &ha->fce_bufs);
800 qla_printk(KERN_WARNING, ha, "Unable to initialize "
801 "FCE (%d).\n", rval);
802 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
804 ha->flags.fce_enabled = 0;
808 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
811 fce_size = sizeof(struct qla2xxx_fce_chain) + EFT_SIZE;
812 ha->flags.fce_enabled = 1;
813 ha->fce_dma = tc_dma;
816 /* Allocate memory for Extended Trace Buffer. */
817 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
820 qla_printk(KERN_WARNING, ha, "Unable to allocate "
821 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
825 memset(tc, 0, EFT_SIZE);
826 rval = qla2x00_enable_eft_trace(ha, tc_dma, EFT_NUM_BUFFERS);
828 qla_printk(KERN_WARNING, ha, "Unable to initialize "
829 "EFT (%d).\n", rval);
830 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
835 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
839 ha->eft_dma = tc_dma;
843 req_q_size = ha->request_q_length * sizeof(request_t);
844 rsp_q_size = ha->response_q_length * sizeof(response_t);
846 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
847 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
850 ha->fw_dump = vmalloc(dump_size);
852 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
853 "firmware dump!!!\n", dump_size / 1024);
856 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
864 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
867 ha->fw_dump_len = dump_size;
868 ha->fw_dump->signature[0] = 'Q';
869 ha->fw_dump->signature[1] = 'L';
870 ha->fw_dump->signature[2] = 'G';
871 ha->fw_dump->signature[3] = 'C';
872 ha->fw_dump->version = __constant_htonl(1);
874 ha->fw_dump->fixed_size = htonl(fixed_size);
875 ha->fw_dump->mem_size = htonl(mem_size);
876 ha->fw_dump->req_q_size = htonl(req_q_size);
877 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
879 ha->fw_dump->eft_size = htonl(eft_size);
880 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
881 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
883 ha->fw_dump->header_size =
884 htonl(offsetof(struct qla2xxx_fw_dump, isp));
888 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
891 * Returns 0 on success.
894 qla2x00_resize_request_q(scsi_qla_host_t *ha)
897 uint16_t fw_iocb_cnt = 0;
898 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
899 dma_addr_t request_dma;
900 request_t *request_ring;
902 /* Valid only on recent ISPs. */
903 if (IS_QLA2100(ha) || IS_QLA2200(ha))
906 /* Retrieve IOCB counts available to the firmware. */
907 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt,
908 &ha->max_npiv_vports);
911 /* No point in continuing if current settings are sufficient. */
912 if (fw_iocb_cnt < 1024)
914 if (ha->request_q_length >= request_q_length)
917 /* Attempt to claim larger area for request queue. */
918 request_ring = dma_alloc_coherent(&ha->pdev->dev,
919 (request_q_length + 1) * sizeof(request_t), &request_dma,
921 if (request_ring == NULL)
924 /* Resize successful, report extensions. */
925 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
926 (ha->fw_memory_size + 1) / 1024);
927 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
928 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
930 /* Clear old allocations. */
931 dma_free_coherent(&ha->pdev->dev,
932 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
935 /* Begin using larger queue. */
936 ha->request_q_length = request_q_length;
937 ha->request_ring = request_ring;
938 ha->request_dma = request_dma;
942 * qla2x00_setup_chip() - Load and start RISC firmware.
945 * Returns 0 on success.
948 qla2x00_setup_chip(scsi_qla_host_t *ha)
951 uint32_t srisc_address = 0;
952 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
955 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
956 /* Disable SRAM, Instruction RAM and GP RAM parity. */
957 spin_lock_irqsave(&ha->hardware_lock, flags);
958 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
959 RD_REG_WORD(®->hccr);
960 spin_unlock_irqrestore(&ha->hardware_lock, flags);
963 /* Load firmware sequences */
964 rval = ha->isp_ops->load_risc(ha, &srisc_address);
965 if (rval == QLA_SUCCESS) {
966 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
967 "code.\n", ha->host_no));
969 rval = qla2x00_verify_checksum(ha, srisc_address);
970 if (rval == QLA_SUCCESS) {
971 /* Start firmware execution. */
972 DEBUG(printk("scsi(%ld): Checksum OK, start "
973 "firmware.\n", ha->host_no));
975 rval = qla2x00_execute_fw(ha, srisc_address);
976 /* Retrieve firmware information. */
977 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
978 qla2x00_get_fw_version(ha,
979 &ha->fw_major_version,
980 &ha->fw_minor_version,
981 &ha->fw_subminor_version,
982 &ha->fw_attributes, &ha->fw_memory_size);
983 qla2x00_resize_request_q(ha);
984 ha->flags.npiv_supported = 0;
985 if ((IS_QLA24XX(ha) || IS_QLA25XX(ha) ||
987 (ha->fw_attributes & BIT_2)) {
988 ha->flags.npiv_supported = 1;
989 if ((!ha->max_npiv_vports) ||
990 ((ha->max_npiv_vports + 1) %
991 MIN_MULTI_ID_FABRIC))
992 ha->max_npiv_vports =
993 MIN_MULTI_ID_FABRIC - 1;
997 qla2x00_alloc_fw_dump(ha);
1000 DEBUG2(printk(KERN_INFO
1001 "scsi(%ld): ISP Firmware failed checksum.\n",
1006 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1007 /* Enable proper parity. */
1008 spin_lock_irqsave(&ha->hardware_lock, flags);
1011 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
1013 /* SRAM, Instruction RAM and GP RAM parity */
1014 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
1015 RD_REG_WORD(®->hccr);
1016 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1020 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
1028 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1031 * Beginning of request ring has initialization control block already built
1032 * by nvram config routine.
1034 * Returns 0 on success.
1037 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
1042 pkt = ha->response_ring_ptr;
1043 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
1044 pkt->signature = RESPONSE_PROCESSED;
1051 * qla2x00_update_fw_options() - Read and process firmware options.
1054 * Returns 0 on success.
1057 qla2x00_update_fw_options(scsi_qla_host_t *ha)
1059 uint16_t swing, emphasis, tx_sens, rx_sens;
1061 memset(ha->fw_options, 0, sizeof(ha->fw_options));
1062 qla2x00_get_fw_options(ha, ha->fw_options);
1064 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1067 /* Serial Link options. */
1068 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1070 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1071 sizeof(ha->fw_seriallink_options)));
1073 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1074 if (ha->fw_seriallink_options[3] & BIT_2) {
1075 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1078 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1079 emphasis = (ha->fw_seriallink_options[2] &
1080 (BIT_4 | BIT_3)) >> 3;
1081 tx_sens = ha->fw_seriallink_options[0] &
1082 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1083 rx_sens = (ha->fw_seriallink_options[0] &
1084 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1085 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1086 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1089 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1090 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1091 ha->fw_options[10] |= BIT_5 |
1092 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1093 (tx_sens & (BIT_1 | BIT_0));
1096 swing = (ha->fw_seriallink_options[2] &
1097 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1098 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1099 tx_sens = ha->fw_seriallink_options[1] &
1100 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1101 rx_sens = (ha->fw_seriallink_options[1] &
1102 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1103 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1104 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1107 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1108 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1109 ha->fw_options[11] |= BIT_5 |
1110 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1111 (tx_sens & (BIT_1 | BIT_0));
1115 /* Return command IOCBs without waiting for an ABTS to complete. */
1116 ha->fw_options[3] |= BIT_13;
1119 if (ha->flags.enable_led_scheme)
1120 ha->fw_options[2] |= BIT_12;
1122 /* Detect ISP6312. */
1124 ha->fw_options[2] |= BIT_13;
1126 /* Update firmware options. */
1127 qla2x00_set_fw_options(ha, ha->fw_options);
1131 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1135 /* Update Serial Link options. */
1136 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1139 rval = qla2x00_set_serdes_params(ha,
1140 le16_to_cpu(ha->fw_seriallink_options24[1]),
1141 le16_to_cpu(ha->fw_seriallink_options24[2]),
1142 le16_to_cpu(ha->fw_seriallink_options24[3]));
1143 if (rval != QLA_SUCCESS) {
1144 qla_printk(KERN_WARNING, ha,
1145 "Unable to update Serial Link options (%x).\n", rval);
1150 qla2x00_config_rings(struct scsi_qla_host *ha)
1152 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1154 /* Setup ring parameters in initialization control block. */
1155 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1156 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1157 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1158 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1159 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1160 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1161 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1162 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1164 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1165 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1166 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1167 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1168 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1172 qla24xx_config_rings(struct scsi_qla_host *ha)
1174 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1175 struct init_cb_24xx *icb;
1177 /* Setup ring parameters in initialization control block. */
1178 icb = (struct init_cb_24xx *)ha->init_cb;
1179 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1180 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1181 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1182 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1183 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1184 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1185 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1186 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1188 WRT_REG_DWORD(®->req_q_in, 0);
1189 WRT_REG_DWORD(®->req_q_out, 0);
1190 WRT_REG_DWORD(®->rsp_q_in, 0);
1191 WRT_REG_DWORD(®->rsp_q_out, 0);
1192 RD_REG_DWORD(®->rsp_q_out);
1196 * qla2x00_init_rings() - Initializes firmware.
1199 * Beginning of request ring has initialization control block already built
1200 * by nvram config routine.
1202 * Returns 0 on success.
1205 qla2x00_init_rings(scsi_qla_host_t *ha)
1208 unsigned long flags = 0;
1210 struct mid_init_cb_24xx *mid_init_cb =
1211 (struct mid_init_cb_24xx *) ha->init_cb;
1213 spin_lock_irqsave(&ha->hardware_lock, flags);
1215 /* Clear outstanding commands array. */
1216 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1217 ha->outstanding_cmds[cnt] = NULL;
1219 ha->current_outstanding_cmd = 0;
1221 /* Clear RSCN queue. */
1222 ha->rscn_in_ptr = 0;
1223 ha->rscn_out_ptr = 0;
1225 /* Initialize firmware. */
1226 ha->request_ring_ptr = ha->request_ring;
1227 ha->req_ring_index = 0;
1228 ha->req_q_cnt = ha->request_q_length;
1229 ha->response_ring_ptr = ha->response_ring;
1230 ha->rsp_ring_index = 0;
1232 /* Initialize response queue entries */
1233 qla2x00_init_response_q_entries(ha);
1235 ha->isp_ops->config_rings(ha);
1237 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1239 /* Update any ISP specific firmware options before initialization. */
1240 ha->isp_ops->update_fw_options(ha);
1242 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1244 if (ha->flags.npiv_supported)
1245 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1247 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1249 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1251 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1254 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1262 * qla2x00_fw_ready() - Waits for firmware ready.
1265 * Returns 0 on success.
1268 qla2x00_fw_ready(scsi_qla_host_t *ha)
1271 unsigned long wtime, mtime, cs84xx_time;
1272 uint16_t min_wait; /* Minimum wait time if loop is down */
1273 uint16_t wait_time; /* Wait time if loop is coming ready */
1278 /* 20 seconds for loop down. */
1282 * Firmware should take at most one RATOV to login, plus 5 seconds for
1283 * our own processing.
1285 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1286 wait_time = min_wait;
1289 /* Min wait time if loop down */
1290 mtime = jiffies + (min_wait * HZ);
1292 /* wait time before firmware ready */
1293 wtime = jiffies + (wait_time * HZ);
1295 /* Wait for ISP to finish LIP */
1296 if (!ha->flags.init_done)
1297 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1299 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1303 rval = qla2x00_get_firmware_state(ha, state);
1304 if (rval == QLA_SUCCESS) {
1305 if (state[0] < FSTATE_LOSS_OF_SYNC) {
1306 ha->device_flags &= ~DFLG_NO_CABLE;
1308 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1309 DEBUG16(printk("scsi(%ld): fw_state=%x "
1310 "84xx=%x.\n", ha->host_no, state[0],
1312 if ((state[2] & FSTATE_LOGGED_IN) &&
1313 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1314 DEBUG16(printk("scsi(%ld): Sending "
1315 "verify iocb.\n", ha->host_no));
1317 cs84xx_time = jiffies;
1318 rval = qla84xx_init_chip(ha);
1319 if (rval != QLA_SUCCESS)
1322 /* Add time taken to initialize. */
1323 cs84xx_time = jiffies - cs84xx_time;
1324 wtime += cs84xx_time;
1325 mtime += cs84xx_time;
1326 DEBUG16(printk("scsi(%ld): Increasing "
1327 "wait time by %ld. New time %ld\n",
1328 ha->host_no, cs84xx_time, wtime));
1330 } else if (state[0] == FSTATE_READY) {
1331 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1334 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1335 &ha->login_timeout, &ha->r_a_tov);
1341 rval = QLA_FUNCTION_FAILED;
1343 if (atomic_read(&ha->loop_down_timer) &&
1344 state[0] != FSTATE_READY) {
1345 /* Loop down. Timeout on min_wait for states
1346 * other than Wait for Login.
1348 if (time_after_eq(jiffies, mtime)) {
1349 qla_printk(KERN_INFO, ha,
1350 "Cable is unplugged...\n");
1352 ha->device_flags |= DFLG_NO_CABLE;
1357 /* Mailbox cmd failed. Timeout on min_wait. */
1358 if (time_after_eq(jiffies, mtime))
1362 if (time_after_eq(jiffies, wtime))
1365 /* Delay for a while */
1368 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1369 ha->host_no, state[0], jiffies));
1372 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1373 ha->host_no, state[0], jiffies));
1376 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1384 * qla2x00_configure_hba
1385 * Setup adapter context.
1388 * ha = adapter state pointer.
1397 qla2x00_configure_hba(scsi_qla_host_t *ha)
1406 char connect_type[22];
1408 /* Get host addresses. */
1409 rval = qla2x00_get_adapter_id(ha,
1410 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
1411 if (rval != QLA_SUCCESS) {
1412 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
1413 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1414 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1415 __func__, ha->host_no));
1417 qla_printk(KERN_WARNING, ha,
1418 "ERROR -- Unable to get host loop ID.\n");
1419 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1425 qla_printk(KERN_INFO, ha,
1426 "Cannot get topology - retrying.\n");
1427 return (QLA_FUNCTION_FAILED);
1430 ha->loop_id = loop_id;
1433 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1434 ha->operating_mode = LOOP;
1439 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1441 ha->current_topology = ISP_CFG_NL;
1442 strcpy(connect_type, "(Loop)");
1446 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1448 ha->switch_cap = sw_cap;
1449 ha->current_topology = ISP_CFG_FL;
1450 strcpy(connect_type, "(FL_Port)");
1454 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1456 ha->operating_mode = P2P;
1457 ha->current_topology = ISP_CFG_N;
1458 strcpy(connect_type, "(N_Port-to-N_Port)");
1462 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1464 ha->switch_cap = sw_cap;
1465 ha->operating_mode = P2P;
1466 ha->current_topology = ISP_CFG_F;
1467 strcpy(connect_type, "(F_Port)");
1471 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1473 ha->host_no, topo));
1474 ha->current_topology = ISP_CFG_NL;
1475 strcpy(connect_type, "(Loop)");
1479 /* Save Host port and loop ID. */
1480 /* byte order - Big Endian */
1481 ha->d_id.b.domain = domain;
1482 ha->d_id.b.area = area;
1483 ha->d_id.b.al_pa = al_pa;
1485 if (!ha->flags.init_done)
1486 qla_printk(KERN_INFO, ha,
1487 "Topology - %s, Host Loop address 0x%x\n",
1488 connect_type, ha->loop_id);
1491 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1493 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1500 qla2x00_set_model_info(scsi_qla_host_t *ha, uint8_t *model, size_t len, char *def)
1505 if (memcmp(model, BINZERO, len) != 0) {
1506 strncpy(ha->model_number, model, len);
1507 st = en = ha->model_number;
1510 if (*en != 0x20 && *en != 0x00)
1515 index = (ha->pdev->subsystem_device & 0xff);
1516 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1517 index < QLA_MODEL_NAMES)
1518 strncpy(ha->model_desc,
1519 qla2x00_model_name[index * 2 + 1],
1520 sizeof(ha->model_desc) - 1);
1522 index = (ha->pdev->subsystem_device & 0xff);
1523 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1524 index < QLA_MODEL_NAMES) {
1525 strcpy(ha->model_number,
1526 qla2x00_model_name[index * 2]);
1527 strncpy(ha->model_desc,
1528 qla2x00_model_name[index * 2 + 1],
1529 sizeof(ha->model_desc) - 1);
1531 strcpy(ha->model_number, def);
1534 if (IS_FWI2_CAPABLE(ha))
1535 qla2xxx_get_vpd_field(ha, "\x82", ha->model_desc,
1536 sizeof(ha->model_desc));
1539 /* On sparc systems, obtain port and node WWN from firmware
1542 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, nvram_t *nv)
1545 struct pci_dev *pdev = ha->pdev;
1546 struct device_node *dp = pci_device_to_OF_node(pdev);
1550 val = of_get_property(dp, "port-wwn", &len);
1551 if (val && len >= WWN_SIZE)
1552 memcpy(nv->port_name, val, WWN_SIZE);
1554 val = of_get_property(dp, "node-wwn", &len);
1555 if (val && len >= WWN_SIZE)
1556 memcpy(nv->node_name, val, WWN_SIZE);
1561 * NVRAM configuration for ISP 2xxx
1564 * ha = adapter block pointer.
1567 * initialization control block in response_ring
1568 * host adapters parameters in host adapter block
1574 qla2x00_nvram_config(scsi_qla_host_t *ha)
1579 uint8_t *dptr1, *dptr2;
1580 init_cb_t *icb = ha->init_cb;
1581 nvram_t *nv = ha->nvram;
1582 uint8_t *ptr = ha->nvram;
1583 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1587 /* Determine NVRAM starting address. */
1588 ha->nvram_size = sizeof(nvram_t);
1590 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1591 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1592 ha->nvram_base = 0x80;
1594 /* Get NVRAM data and calculate checksum. */
1595 ha->isp_ops->read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1596 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1599 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1600 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
1602 /* Bad NVRAM data, set defaults parameters. */
1603 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1604 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1605 /* Reset NVRAM data. */
1606 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1607 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1609 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1610 "invalid -- WWPN) defaults.\n");
1613 qla2xxx_hw_event_log(ha, HW_EVENT_NVRAM_CHKSUM_ERR, 0,
1614 MSW(chksum), LSW(chksum));
1617 * Set default initialization control block.
1619 memset(nv, 0, ha->nvram_size);
1620 nv->parameter_block_version = ICB_VERSION;
1622 if (IS_QLA23XX(ha)) {
1623 nv->firmware_options[0] = BIT_2 | BIT_1;
1624 nv->firmware_options[1] = BIT_7 | BIT_5;
1625 nv->add_firmware_options[0] = BIT_5;
1626 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1627 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1628 nv->special_options[1] = BIT_7;
1629 } else if (IS_QLA2200(ha)) {
1630 nv->firmware_options[0] = BIT_2 | BIT_1;
1631 nv->firmware_options[1] = BIT_7 | BIT_5;
1632 nv->add_firmware_options[0] = BIT_5;
1633 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1634 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1635 } else if (IS_QLA2100(ha)) {
1636 nv->firmware_options[0] = BIT_3 | BIT_1;
1637 nv->firmware_options[1] = BIT_5;
1638 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1641 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1642 nv->execution_throttle = __constant_cpu_to_le16(16);
1643 nv->retry_count = 8;
1644 nv->retry_delay = 1;
1646 nv->port_name[0] = 33;
1647 nv->port_name[3] = 224;
1648 nv->port_name[4] = 139;
1650 qla2xxx_nvram_wwn_from_ofw(ha, nv);
1652 nv->login_timeout = 4;
1655 * Set default host adapter parameters
1657 nv->host_p[1] = BIT_2;
1658 nv->reset_delay = 5;
1659 nv->port_down_retry_count = 8;
1660 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1661 nv->link_down_timeout = 60;
1666 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1668 * The SN2 does not provide BIOS emulation which means you can't change
1669 * potentially bogus BIOS settings. Force the use of default settings
1670 * for link rate and frame size. Hope that the rest of the settings
1673 if (ia64_platform_is("sn2")) {
1674 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1676 nv->special_options[1] = BIT_7;
1680 /* Reset Initialization control block */
1681 memset(icb, 0, ha->init_cb_size);
1684 * Setup driver NVRAM options.
1686 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1687 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1688 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1689 nv->firmware_options[1] &= ~BIT_4;
1691 if (IS_QLA23XX(ha)) {
1692 nv->firmware_options[0] |= BIT_2;
1693 nv->firmware_options[0] &= ~BIT_3;
1694 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1696 if (IS_QLA2300(ha)) {
1697 if (ha->fb_rev == FPM_2310) {
1698 strcpy(ha->model_number, "QLA2310");
1700 strcpy(ha->model_number, "QLA2300");
1703 qla2x00_set_model_info(ha, nv->model_number,
1704 sizeof(nv->model_number), "QLA23xx");
1706 } else if (IS_QLA2200(ha)) {
1707 nv->firmware_options[0] |= BIT_2;
1709 * 'Point-to-point preferred, else loop' is not a safe
1710 * connection mode setting.
1712 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1714 /* Force 'loop preferred, else point-to-point'. */
1715 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1716 nv->add_firmware_options[0] |= BIT_5;
1718 strcpy(ha->model_number, "QLA22xx");
1719 } else /*if (IS_QLA2100(ha))*/ {
1720 strcpy(ha->model_number, "QLA2100");
1724 * Copy over NVRAM RISC parameter block to initialization control block.
1726 dptr1 = (uint8_t *)icb;
1727 dptr2 = (uint8_t *)&nv->parameter_block_version;
1728 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1730 *dptr1++ = *dptr2++;
1732 /* Copy 2nd half. */
1733 dptr1 = (uint8_t *)icb->add_firmware_options;
1734 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1736 *dptr1++ = *dptr2++;
1738 /* Use alternate WWN? */
1739 if (nv->host_p[1] & BIT_7) {
1740 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1741 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1744 /* Prepare nodename */
1745 if ((icb->firmware_options[1] & BIT_6) == 0) {
1747 * Firmware will apply the following mask if the nodename was
1750 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1751 icb->node_name[0] &= 0xF0;
1755 * Set host adapter parameters.
1757 if (nv->host_p[0] & BIT_7)
1758 ql2xextended_error_logging = 1;
1759 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1760 /* Always load RISC code on non ISP2[12]00 chips. */
1761 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1762 ha->flags.disable_risc_code_load = 0;
1763 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1764 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1765 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1766 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1767 ha->flags.disable_serdes = 0;
1769 ha->operating_mode =
1770 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1772 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1773 sizeof(ha->fw_seriallink_options));
1775 /* save HBA serial number */
1776 ha->serial0 = icb->port_name[5];
1777 ha->serial1 = icb->port_name[6];
1778 ha->serial2 = icb->port_name[7];
1779 ha->node_name = icb->node_name;
1780 ha->port_name = icb->port_name;
1782 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1784 ha->retry_count = nv->retry_count;
1786 /* Set minimum login_timeout to 4 seconds. */
1787 if (nv->login_timeout < ql2xlogintimeout)
1788 nv->login_timeout = ql2xlogintimeout;
1789 if (nv->login_timeout < 4)
1790 nv->login_timeout = 4;
1791 ha->login_timeout = nv->login_timeout;
1792 icb->login_timeout = nv->login_timeout;
1794 /* Set minimum RATOV to 100 tenths of a second. */
1797 ha->loop_reset_delay = nv->reset_delay;
1799 /* Link Down Timeout = 0:
1801 * When Port Down timer expires we will start returning
1802 * I/O's to OS with "DID_NO_CONNECT".
1804 * Link Down Timeout != 0:
1806 * The driver waits for the link to come up after link down
1807 * before returning I/Os to OS with "DID_NO_CONNECT".
1809 if (nv->link_down_timeout == 0) {
1810 ha->loop_down_abort_time =
1811 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1813 ha->link_down_timeout = nv->link_down_timeout;
1814 ha->loop_down_abort_time =
1815 (LOOP_DOWN_TIME - ha->link_down_timeout);
1819 * Need enough time to try and get the port back.
1821 ha->port_down_retry_count = nv->port_down_retry_count;
1822 if (qlport_down_retry)
1823 ha->port_down_retry_count = qlport_down_retry;
1824 /* Set login_retry_count */
1825 ha->login_retry_count = nv->retry_count;
1826 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1827 ha->port_down_retry_count > 3)
1828 ha->login_retry_count = ha->port_down_retry_count;
1829 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1830 ha->login_retry_count = ha->port_down_retry_count;
1831 if (ql2xloginretrycount)
1832 ha->login_retry_count = ql2xloginretrycount;
1834 icb->lun_enables = __constant_cpu_to_le16(0);
1835 icb->command_resource_count = 0;
1836 icb->immediate_notify_resource_count = 0;
1837 icb->timeout = __constant_cpu_to_le16(0);
1839 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1841 icb->firmware_options[0] &= ~BIT_3;
1842 icb->add_firmware_options[0] &=
1843 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1844 icb->add_firmware_options[0] |= BIT_2;
1845 icb->response_accumulation_timer = 3;
1846 icb->interrupt_delay_timer = 5;
1848 ha->flags.process_response_queue = 1;
1851 if (!ha->flags.init_done) {
1852 ha->zio_mode = icb->add_firmware_options[0] &
1853 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1854 ha->zio_timer = icb->interrupt_delay_timer ?
1855 icb->interrupt_delay_timer: 2;
1857 icb->add_firmware_options[0] &=
1858 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1859 ha->flags.process_response_queue = 0;
1860 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1861 ha->zio_mode = QLA_ZIO_MODE_6;
1863 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1864 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1865 ha->zio_timer * 100));
1866 qla_printk(KERN_INFO, ha,
1867 "ZIO mode %d enabled; timer delay (%d us).\n",
1868 ha->zio_mode, ha->zio_timer * 100);
1870 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1871 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1872 ha->flags.process_response_queue = 1;
1877 DEBUG2_3(printk(KERN_WARNING
1878 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1884 qla2x00_rport_del(void *data)
1886 fc_port_t *fcport = data;
1887 struct fc_rport *rport;
1889 spin_lock_irq(fcport->ha->host->host_lock);
1890 rport = fcport->drport;
1891 fcport->drport = NULL;
1892 spin_unlock_irq(fcport->ha->host->host_lock);
1894 fc_remote_port_delete(rport);
1898 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1900 * @flags: allocation flags
1902 * Returns a pointer to the allocated fcport, or NULL, if none available.
1905 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1909 fcport = kzalloc(sizeof(fc_port_t), flags);
1913 /* Setup fcport template structure. */
1915 fcport->vp_idx = ha->vp_idx;
1916 fcport->port_type = FCT_UNKNOWN;
1917 fcport->loop_id = FC_NO_LOOP_ID;
1918 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1919 fcport->flags = FCF_RLC_SUPPORT;
1920 fcport->supported_classes = FC_COS_UNSPECIFIED;
1926 * qla2x00_configure_loop
1927 * Updates Fibre Channel Device Database with what is actually on loop.
1930 * ha = adapter block pointer.
1935 * 2 = database was full and device was not configured.
1938 qla2x00_configure_loop(scsi_qla_host_t *ha)
1941 unsigned long flags, save_flags;
1945 /* Get Initiator ID */
1946 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1947 rval = qla2x00_configure_hba(ha);
1948 if (rval != QLA_SUCCESS) {
1949 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1955 save_flags = flags = ha->dpc_flags;
1956 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1957 ha->host_no, flags));
1960 * If we have both an RSCN and PORT UPDATE pending then handle them
1961 * both at the same time.
1963 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1964 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1966 /* Determine what we need to do */
1967 if (ha->current_topology == ISP_CFG_FL &&
1968 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1970 ha->flags.rscn_queue_overflow = 1;
1971 set_bit(RSCN_UPDATE, &flags);
1973 } else if (ha->current_topology == ISP_CFG_F &&
1974 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1976 ha->flags.rscn_queue_overflow = 1;
1977 set_bit(RSCN_UPDATE, &flags);
1978 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1980 } else if (ha->current_topology == ISP_CFG_N) {
1981 clear_bit(RSCN_UPDATE, &flags);
1983 } else if (!ha->flags.online ||
1984 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1986 ha->flags.rscn_queue_overflow = 1;
1987 set_bit(RSCN_UPDATE, &flags);
1988 set_bit(LOCAL_LOOP_UPDATE, &flags);
1991 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1992 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1993 rval = QLA_FUNCTION_FAILED;
1995 rval = qla2x00_configure_local_loop(ha);
1999 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
2000 if (LOOP_TRANSITION(ha)) {
2001 rval = QLA_FUNCTION_FAILED;
2003 rval = qla2x00_configure_fabric(ha);
2007 if (rval == QLA_SUCCESS) {
2008 if (atomic_read(&ha->loop_down_timer) ||
2009 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2010 rval = QLA_FUNCTION_FAILED;
2012 atomic_set(&ha->loop_state, LOOP_READY);
2014 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
2019 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
2020 __func__, ha->host_no));
2022 DEBUG3(printk("%s: exiting normally\n", __func__));
2025 /* Restore state if a resync event occurred during processing */
2026 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2027 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
2028 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
2029 if (test_bit(RSCN_UPDATE, &save_flags)) {
2030 ha->flags.rscn_queue_overflow = 1;
2031 set_bit(RSCN_UPDATE, &ha->dpc_flags);
2041 * qla2x00_configure_local_loop
2042 * Updates Fibre Channel Device Database with local loop devices.
2045 * ha = adapter block pointer.
2051 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
2056 fc_port_t *fcport, *new_fcport;
2062 uint8_t domain, area, al_pa;
2063 scsi_qla_host_t *pha = to_qla_parent(ha);
2067 entries = MAX_FIBRE_DEVICES;
2069 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
2070 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
2072 /* Get list of logged in devices. */
2073 memset(ha->gid_list, 0, GID_LIST_SIZE);
2074 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
2076 if (rval != QLA_SUCCESS)
2077 goto cleanup_allocation;
2079 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2080 ha->host_no, entries));
2081 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2082 entries * sizeof(struct gid_list_info)));
2084 /* Allocate temporary fcport for any new fcports discovered. */
2085 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2086 if (new_fcport == NULL) {
2087 rval = QLA_MEMORY_ALLOC_FAILED;
2088 goto cleanup_allocation;
2090 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2093 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2095 list_for_each_entry(fcport, &pha->fcports, list) {
2096 if (fcport->vp_idx != ha->vp_idx)
2099 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2100 fcport->port_type != FCT_BROADCAST &&
2101 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2103 DEBUG(printk("scsi(%ld): Marking port lost, "
2105 ha->host_no, fcport->loop_id));
2107 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2108 fcport->flags &= ~FCF_FARP_DONE;
2112 /* Add devices to port list. */
2113 id_iter = (char *)ha->gid_list;
2114 for (index = 0; index < entries; index++) {
2115 domain = ((struct gid_list_info *)id_iter)->domain;
2116 area = ((struct gid_list_info *)id_iter)->area;
2117 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
2118 if (IS_QLA2100(ha) || IS_QLA2200(ha))
2119 loop_id = (uint16_t)
2120 ((struct gid_list_info *)id_iter)->loop_id_2100;
2122 loop_id = le16_to_cpu(
2123 ((struct gid_list_info *)id_iter)->loop_id);
2124 id_iter += ha->gid_list_info_size;
2126 /* Bypass reserved domain fields. */
2127 if ((domain & 0xf0) == 0xf0)
2130 /* Bypass if not same domain and area of adapter. */
2131 if (area && domain &&
2132 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
2135 /* Bypass invalid local loop ID. */
2136 if (loop_id > LAST_LOCAL_LOOP_ID)
2139 /* Fill in member data. */
2140 new_fcport->d_id.b.domain = domain;
2141 new_fcport->d_id.b.area = area;
2142 new_fcport->d_id.b.al_pa = al_pa;
2143 new_fcport->loop_id = loop_id;
2144 new_fcport->vp_idx = ha->vp_idx;
2145 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
2146 if (rval2 != QLA_SUCCESS) {
2147 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2148 "information -- get_port_database=%x, "
2150 ha->host_no, rval2, new_fcport->loop_id));
2151 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2153 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2157 /* Check for matching device in port list. */
2160 list_for_each_entry(fcport, &pha->fcports, list) {
2161 if (fcport->vp_idx != ha->vp_idx)
2164 if (memcmp(new_fcport->port_name, fcport->port_name,
2168 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2169 FCF_PERSISTENT_BOUND);
2170 fcport->loop_id = new_fcport->loop_id;
2171 fcport->port_type = new_fcport->port_type;
2172 fcport->d_id.b24 = new_fcport->d_id.b24;
2173 memcpy(fcport->node_name, new_fcport->node_name,
2181 /* New device, add to fcports list. */
2182 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
2184 new_fcport->ha = ha;
2185 new_fcport->vp_idx = ha->vp_idx;
2186 list_add_tail(&new_fcport->vp_fcport,
2189 list_add_tail(&new_fcport->list, &pha->fcports);
2191 /* Allocate a new replacement fcport. */
2192 fcport = new_fcport;
2193 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2194 if (new_fcport == NULL) {
2195 rval = QLA_MEMORY_ALLOC_FAILED;
2196 goto cleanup_allocation;
2198 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2201 /* Base iIDMA settings on HBA port speed. */
2202 fcport->fp_speed = ha->link_data_rate;
2204 qla2x00_update_fcport(ha, fcport);
2212 if (rval != QLA_SUCCESS) {
2213 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2214 "rval=%x\n", ha->host_no, rval));
2218 ha->device_flags |= DFLG_LOCAL_DEVICES;
2219 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2226 qla2x00_iidma_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2228 #define LS_UNKNOWN 2
2229 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
2233 if (!IS_IIDMA_CAPABLE(ha))
2236 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2237 fcport->fp_speed > ha->link_data_rate)
2240 rval = qla2x00_set_idma_speed(ha, fcport->loop_id, fcport->fp_speed,
2242 if (rval != QLA_SUCCESS) {
2243 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2244 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2245 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2246 fcport->port_name[2], fcport->port_name[3],
2247 fcport->port_name[4], fcport->port_name[5],
2248 fcport->port_name[6], fcport->port_name[7], rval,
2249 fcport->fp_speed, mb[0], mb[1]));
2251 DEBUG2(qla_printk(KERN_INFO, ha,
2252 "iIDMA adjusted to %s GB/s on "
2253 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2254 link_speeds[fcport->fp_speed], fcport->port_name[0],
2255 fcport->port_name[1], fcport->port_name[2],
2256 fcport->port_name[3], fcport->port_name[4],
2257 fcport->port_name[5], fcport->port_name[6],
2258 fcport->port_name[7]));
2263 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2265 struct fc_rport_identifiers rport_ids;
2266 struct fc_rport *rport;
2269 qla2x00_rport_del(fcport);
2271 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2272 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2273 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2274 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2275 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2276 fcport->rport = rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2278 qla_printk(KERN_WARNING, ha,
2279 "Unable to allocate fc remote port!\n");
2282 spin_lock_irq(fcport->ha->host->host_lock);
2283 *((fc_port_t **)rport->dd_data) = fcport;
2284 spin_unlock_irq(fcport->ha->host->host_lock);
2286 rport->supported_classes = fcport->supported_classes;
2288 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2289 if (fcport->port_type == FCT_INITIATOR)
2290 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2291 if (fcport->port_type == FCT_TARGET)
2292 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2293 fc_remote_port_rolechg(rport, rport_ids.roles);
2297 * qla2x00_update_fcport
2298 * Updates device on list.
2301 * ha = adapter block pointer.
2302 * fcport = port structure pointer.
2312 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2314 scsi_qla_host_t *pha = to_qla_parent(ha);
2317 fcport->login_retry = 0;
2318 fcport->port_login_retry_count = pha->port_down_retry_count *
2320 atomic_set(&fcport->port_down_timer, pha->port_down_retry_count *
2322 fcport->flags &= ~FCF_LOGIN_NEEDED;
2324 qla2x00_iidma_fcport(ha, fcport);
2326 atomic_set(&fcport->state, FCS_ONLINE);
2328 qla2x00_reg_remote_port(ha, fcport);
2332 * qla2x00_configure_fabric
2333 * Setup SNS devices with loop ID's.
2336 * ha = adapter block pointer.
2343 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2346 fc_port_t *fcport, *fcptemp;
2347 uint16_t next_loopid;
2348 uint16_t mb[MAILBOX_REGISTER_COUNT];
2350 LIST_HEAD(new_fcports);
2351 scsi_qla_host_t *pha = to_qla_parent(ha);
2353 /* If FL port exists, then SNS is present */
2354 if (IS_FWI2_CAPABLE(ha))
2355 loop_id = NPH_F_PORT;
2357 loop_id = SNS_FL_PORT;
2358 rval = qla2x00_get_port_name(ha, loop_id, ha->fabric_node_name, 1);
2359 if (rval != QLA_SUCCESS) {
2360 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2361 "Port\n", ha->host_no));
2363 ha->device_flags &= ~SWITCH_FOUND;
2364 return (QLA_SUCCESS);
2366 ha->device_flags |= SWITCH_FOUND;
2368 /* Mark devices that need re-synchronization. */
2369 rval2 = qla2x00_device_resync(ha);
2370 if (rval2 == QLA_RSCNS_HANDLED) {
2371 /* No point doing the scan, just continue. */
2372 return (QLA_SUCCESS);
2376 if (ql2xfdmienable &&
2377 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2378 qla2x00_fdmi_register(ha);
2380 /* Ensure we are logged into the SNS. */
2381 if (IS_FWI2_CAPABLE(ha))
2384 loop_id = SIMPLE_NAME_SERVER;
2385 ha->isp_ops->fabric_login(ha, loop_id, 0xff, 0xff,
2386 0xfc, mb, BIT_1 | BIT_0);
2387 if (mb[0] != MBS_COMMAND_COMPLETE) {
2388 DEBUG2(qla_printk(KERN_INFO, ha,
2389 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2390 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2391 mb[0], mb[1], mb[2], mb[6], mb[7]));
2392 return (QLA_SUCCESS);
2395 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2396 if (qla2x00_rft_id(ha)) {
2398 DEBUG2(printk("scsi(%ld): Register FC-4 "
2399 "TYPE failed.\n", ha->host_no));
2401 if (qla2x00_rff_id(ha)) {
2403 DEBUG2(printk("scsi(%ld): Register FC-4 "
2404 "Features failed.\n", ha->host_no));
2406 if (qla2x00_rnn_id(ha)) {
2408 DEBUG2(printk("scsi(%ld): Register Node Name "
2409 "failed.\n", ha->host_no));
2410 } else if (qla2x00_rsnn_nn(ha)) {
2412 DEBUG2(printk("scsi(%ld): Register Symbolic "
2413 "Node Name failed.\n", ha->host_no));
2417 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2418 if (rval != QLA_SUCCESS)
2422 * Logout all previous fabric devices marked lost, except
2425 list_for_each_entry(fcport, &pha->fcports, list) {
2426 if (fcport->vp_idx !=ha->vp_idx)
2429 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2432 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2435 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2436 qla2x00_mark_device_lost(ha, fcport,
2437 ql2xplogiabsentdevice, 0);
2438 if (fcport->loop_id != FC_NO_LOOP_ID &&
2439 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2440 fcport->port_type != FCT_INITIATOR &&
2441 fcport->port_type != FCT_BROADCAST) {
2442 ha->isp_ops->fabric_logout(ha,
2444 fcport->d_id.b.domain,
2445 fcport->d_id.b.area,
2446 fcport->d_id.b.al_pa);
2447 fcport->loop_id = FC_NO_LOOP_ID;
2452 /* Starting free loop ID. */
2453 next_loopid = pha->min_external_loopid;
2456 * Scan through our port list and login entries that need to be
2459 list_for_each_entry(fcport, &pha->fcports, list) {
2460 if (fcport->vp_idx != ha->vp_idx)
2463 if (atomic_read(&ha->loop_down_timer) ||
2464 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2467 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2468 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2471 if (fcport->loop_id == FC_NO_LOOP_ID) {
2472 fcport->loop_id = next_loopid;
2473 rval = qla2x00_find_new_loop_id(
2474 to_qla_parent(ha), fcport);
2475 if (rval != QLA_SUCCESS) {
2476 /* Ran out of IDs to use */
2480 /* Login and update database */
2481 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2484 /* Exit if out of loop IDs. */
2485 if (rval != QLA_SUCCESS) {
2490 * Login and add the new devices to our port list.
2492 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2493 if (atomic_read(&ha->loop_down_timer) ||
2494 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2497 /* Find a new loop ID to use. */
2498 fcport->loop_id = next_loopid;
2499 rval = qla2x00_find_new_loop_id(to_qla_parent(ha),
2501 if (rval != QLA_SUCCESS) {
2502 /* Ran out of IDs to use */
2506 /* Login and update database */
2507 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2511 fcport->vp_idx = ha->vp_idx;
2512 list_add_tail(&fcport->vp_fcport,
2514 list_move_tail(&fcport->list,
2515 &ha->parent->fcports);
2517 list_move_tail(&fcport->list, &ha->fcports);
2521 /* Free all new device structures not processed. */
2522 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2523 list_del(&fcport->list);
2528 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2529 "rval=%d\n", ha->host_no, rval));
2537 * qla2x00_find_all_fabric_devs
2540 * ha = adapter block pointer.
2541 * dev = database device entry pointer.
2550 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2554 fc_port_t *fcport, *new_fcport, *fcptemp;
2559 int first_dev, last_dev;
2560 port_id_t wrap, nxt_d_id;
2564 scsi_qla_host_t *vha;
2565 scsi_qla_host_t *pha = to_qla_parent(ha);
2569 /* Try GID_PT to get device list, else GAN. */
2570 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
2573 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2574 "on GA_NXT\n", ha->host_no));
2576 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2579 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2582 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2585 } else if (ql2xiidmaenable &&
2586 qla2x00_gfpn_id(ha, swl) == QLA_SUCCESS) {
2587 qla2x00_gpsc(ha, swl);
2592 /* Allocate temporary fcport for any new fcports discovered. */
2593 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2594 if (new_fcport == NULL) {
2596 return (QLA_MEMORY_ALLOC_FAILED);
2598 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2599 new_fcport->vp_idx = ha->vp_idx;
2600 /* Set start port ID scan at adapter ID. */
2604 /* Starting free loop ID. */
2605 loop_id = pha->min_external_loopid;
2606 for (; loop_id <= ha->last_loop_id; loop_id++) {
2607 if (qla2x00_is_reserved_id(ha, loop_id))
2610 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2615 wrap.b24 = new_fcport->d_id.b24;
2617 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2618 memcpy(new_fcport->node_name,
2619 swl[swl_idx].node_name, WWN_SIZE);
2620 memcpy(new_fcport->port_name,
2621 swl[swl_idx].port_name, WWN_SIZE);
2622 memcpy(new_fcport->fabric_port_name,
2623 swl[swl_idx].fabric_port_name, WWN_SIZE);
2624 new_fcport->fp_speed = swl[swl_idx].fp_speed;
2626 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2632 /* Send GA_NXT to the switch */
2633 rval = qla2x00_ga_nxt(ha, new_fcport);
2634 if (rval != QLA_SUCCESS) {
2635 qla_printk(KERN_WARNING, ha,
2636 "SNS scan failed -- assuming zero-entry "
2638 list_for_each_entry_safe(fcport, fcptemp,
2639 new_fcports, list) {
2640 list_del(&fcport->list);
2648 /* If wrap on switch device list, exit. */
2650 wrap.b24 = new_fcport->d_id.b24;
2652 } else if (new_fcport->d_id.b24 == wrap.b24) {
2653 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2654 ha->host_no, new_fcport->d_id.b.domain,
2655 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2659 /* Bypass if same physical adapter. */
2660 if (new_fcport->d_id.b24 == pha->d_id.b24)
2663 /* Bypass virtual ports of the same host. */
2664 if (pha->num_vhosts) {
2665 for_each_mapped_vp_idx(pha, vp_index) {
2668 list_for_each_entry(vha, &pha->vp_list,
2670 if (vp_index == vha->vp_idx) {
2681 new_fcport->d_id.b24 == vha->d_id.b24)
2685 if (vp_index <= pha->max_npiv_vports)
2689 /* Bypass if same domain and area of adapter. */
2690 if (((new_fcport->d_id.b24 & 0xffff00) ==
2691 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2695 /* Bypass reserved domain fields. */
2696 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2699 /* Locate matching device in database. */
2701 list_for_each_entry(fcport, &pha->fcports, list) {
2702 if (new_fcport->vp_idx != fcport->vp_idx)
2704 if (memcmp(new_fcport->port_name, fcport->port_name,
2710 /* Update port state. */
2711 memcpy(fcport->fabric_port_name,
2712 new_fcport->fabric_port_name, WWN_SIZE);
2713 fcport->fp_speed = new_fcport->fp_speed;
2716 * If address the same and state FCS_ONLINE, nothing
2719 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2720 atomic_read(&fcport->state) == FCS_ONLINE) {
2725 * If device was not a fabric device before.
2727 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2728 fcport->d_id.b24 = new_fcport->d_id.b24;
2729 fcport->loop_id = FC_NO_LOOP_ID;
2730 fcport->flags |= (FCF_FABRIC_DEVICE |
2732 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2737 * Port ID changed or device was marked to be updated;
2738 * Log it out if still logged in and mark it for
2741 fcport->d_id.b24 = new_fcport->d_id.b24;
2742 fcport->flags |= FCF_LOGIN_NEEDED;
2743 if (fcport->loop_id != FC_NO_LOOP_ID &&
2744 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2745 fcport->port_type != FCT_INITIATOR &&
2746 fcport->port_type != FCT_BROADCAST) {
2747 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
2748 fcport->d_id.b.domain, fcport->d_id.b.area,
2749 fcport->d_id.b.al_pa);
2750 fcport->loop_id = FC_NO_LOOP_ID;
2759 /* If device was not in our fcports list, then add it. */
2760 list_add_tail(&new_fcport->list, new_fcports);
2762 /* Allocate a new replacement fcport. */
2763 nxt_d_id.b24 = new_fcport->d_id.b24;
2764 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2765 if (new_fcport == NULL) {
2767 return (QLA_MEMORY_ALLOC_FAILED);
2769 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2770 new_fcport->d_id.b24 = nxt_d_id.b24;
2771 new_fcport->vp_idx = ha->vp_idx;
2777 if (!list_empty(new_fcports))
2778 ha->device_flags |= DFLG_FABRIC_DEVICES;
2784 * qla2x00_find_new_loop_id
2785 * Scan through our port list and find a new usable loop ID.
2788 * ha: adapter state pointer.
2789 * dev: port structure pointer.
2792 * qla2x00 local function return status code.
2798 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2803 uint16_t first_loop_id;
2804 scsi_qla_host_t *pha = to_qla_parent(ha);
2808 /* Save starting loop ID. */
2809 first_loop_id = dev->loop_id;
2812 /* Skip loop ID if already used by adapter. */
2813 if (dev->loop_id == ha->loop_id) {
2817 /* Skip reserved loop IDs. */
2818 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2822 /* Reset loop ID if passed the end. */
2823 if (dev->loop_id > ha->last_loop_id) {
2824 /* first loop ID. */
2825 dev->loop_id = ha->min_external_loopid;
2828 /* Check for loop ID being already in use. */
2831 list_for_each_entry(fcport, &pha->fcports, list) {
2832 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2833 /* ID possibly in use */
2839 /* If not in use then it is free to use. */
2844 /* ID in use. Try next value. */
2847 /* If wrap around. No free ID to use. */
2848 if (dev->loop_id == first_loop_id) {
2849 dev->loop_id = FC_NO_LOOP_ID;
2850 rval = QLA_FUNCTION_FAILED;
2859 * qla2x00_device_resync
2860 * Marks devices in the database that needs resynchronization.
2863 * ha = adapter block pointer.
2869 qla2x00_device_resync(scsi_qla_host_t *ha)
2874 uint32_t rscn_entry;
2875 uint8_t rscn_out_iter;
2878 scsi_qla_host_t *pha = to_qla_parent(ha);
2880 rval = QLA_RSCNS_HANDLED;
2882 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2883 ha->flags.rscn_queue_overflow) {
2885 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2886 format = MSB(MSW(rscn_entry));
2887 d_id.b.domain = LSB(MSW(rscn_entry));
2888 d_id.b.area = MSB(LSW(rscn_entry));
2889 d_id.b.al_pa = LSB(LSW(rscn_entry));
2891 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2892 "[%02x/%02x%02x%02x].\n",
2893 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2894 d_id.b.area, d_id.b.al_pa));
2897 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2898 ha->rscn_out_ptr = 0;
2900 /* Skip duplicate entries. */
2901 for (rscn_out_iter = ha->rscn_out_ptr;
2902 !ha->flags.rscn_queue_overflow &&
2903 rscn_out_iter != ha->rscn_in_ptr;
2904 rscn_out_iter = (rscn_out_iter ==
2905 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2907 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2910 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2911 "entry found at [%d].\n", ha->host_no,
2914 ha->rscn_out_ptr = rscn_out_iter;
2917 /* Queue overflow, set switch default case. */
2918 if (ha->flags.rscn_queue_overflow) {
2919 DEBUG(printk("scsi(%ld): device_resync: rscn "
2920 "overflow.\n", ha->host_no));
2923 ha->flags.rscn_queue_overflow = 0;
2939 ha->rscn_out_ptr = ha->rscn_in_ptr;
2945 list_for_each_entry(fcport, &pha->fcports, list) {
2946 if (fcport->vp_idx != ha->vp_idx)
2949 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2950 (fcport->d_id.b24 & mask) != d_id.b24 ||
2951 fcport->port_type == FCT_BROADCAST)
2954 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2956 fcport->port_type != FCT_INITIATOR) {
2957 qla2x00_mark_device_lost(ha, fcport,
2961 fcport->flags &= ~FCF_FARP_DONE;
2968 * qla2x00_fabric_dev_login
2969 * Login fabric target device and update FC port database.
2972 * ha: adapter state pointer.
2973 * fcport: port structure list pointer.
2974 * next_loopid: contains value of a new loop ID that can be used
2975 * by the next login attempt.
2978 * qla2x00 local function return status code.
2984 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2985 uint16_t *next_loopid)
2994 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2995 if (rval == QLA_SUCCESS) {
2996 /* Send an ADISC to tape devices.*/
2998 if (fcport->flags & FCF_TAPE_PRESENT)
3000 rval = qla2x00_get_port_database(ha, fcport, opts);
3001 if (rval != QLA_SUCCESS) {
3002 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
3003 fcport->d_id.b.domain, fcport->d_id.b.area,
3004 fcport->d_id.b.al_pa);
3005 qla2x00_mark_device_lost(ha, fcport, 1, 0);
3007 qla2x00_update_fcport(ha, fcport);
3015 * qla2x00_fabric_login
3016 * Issue fabric login command.
3019 * ha = adapter block pointer.
3020 * device = pointer to FC device type structure.
3023 * 0 - Login successfully
3025 * 2 - Initiator device
3029 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
3030 uint16_t *next_loopid)
3034 uint16_t tmp_loopid;
3035 uint16_t mb[MAILBOX_REGISTER_COUNT];
3041 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3042 "for port %02x%02x%02x.\n",
3043 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
3044 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3046 /* Login fcport on switch. */
3047 ha->isp_ops->fabric_login(ha, fcport->loop_id,
3048 fcport->d_id.b.domain, fcport->d_id.b.area,
3049 fcport->d_id.b.al_pa, mb, BIT_0);
3050 if (mb[0] == MBS_PORT_ID_USED) {
3052 * Device has another loop ID. The firmware team
3053 * recommends the driver perform an implicit login with
3054 * the specified ID again. The ID we just used is save
3055 * here so we return with an ID that can be tried by
3059 tmp_loopid = fcport->loop_id;
3060 fcport->loop_id = mb[1];
3062 DEBUG(printk("Fabric Login: port in use - next "
3063 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3064 fcport->loop_id, fcport->d_id.b.domain,
3065 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3067 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3072 /* A retry occurred before. */
3073 *next_loopid = tmp_loopid;
3076 * No retry occurred before. Just increment the
3077 * ID value for next login.
3079 *next_loopid = (fcport->loop_id + 1);
3082 if (mb[1] & BIT_0) {
3083 fcport->port_type = FCT_INITIATOR;
3085 fcport->port_type = FCT_TARGET;
3086 if (mb[1] & BIT_1) {
3087 fcport->flags |= FCF_TAPE_PRESENT;
3092 fcport->supported_classes |= FC_COS_CLASS2;
3094 fcport->supported_classes |= FC_COS_CLASS3;
3098 } else if (mb[0] == MBS_LOOP_ID_USED) {
3100 * Loop ID already used, try next loop ID.
3103 rval = qla2x00_find_new_loop_id(ha, fcport);
3104 if (rval != QLA_SUCCESS) {
3105 /* Ran out of loop IDs to use */
3108 } else if (mb[0] == MBS_COMMAND_ERROR) {
3110 * Firmware possibly timed out during login. If NO
3111 * retries are left to do then the device is declared
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 qla2x00_mark_device_lost(ha, fcport, 1, 0);
3124 * unrecoverable / not handled error
3126 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3127 "loop_id=%x jiffies=%lx.\n",
3128 __func__, ha->host_no, mb[0],
3129 fcport->d_id.b.domain, fcport->d_id.b.area,
3130 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3132 *next_loopid = fcport->loop_id;
3133 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
3134 fcport->d_id.b.domain, fcport->d_id.b.area,
3135 fcport->d_id.b.al_pa);
3136 fcport->loop_id = FC_NO_LOOP_ID;
3137 fcport->login_retry = 0;
3148 * qla2x00_local_device_login
3149 * Issue local device login command.
3152 * ha = adapter block pointer.
3153 * loop_id = loop id of device to login to.
3155 * Returns (Where's the #define!!!!):
3156 * 0 - Login successfully
3161 qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
3164 uint16_t mb[MAILBOX_REGISTER_COUNT];
3166 memset(mb, 0, sizeof(mb));
3167 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
3168 if (rval == QLA_SUCCESS) {
3169 /* Interrogate mailbox registers for any errors */
3170 if (mb[0] == MBS_COMMAND_ERROR)
3172 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3173 /* device not in PCB table */
3181 * qla2x00_loop_resync
3182 * Resync with fibre channel devices.
3185 * ha = adapter block pointer.
3191 qla2x00_loop_resync(scsi_qla_host_t *ha)
3198 atomic_set(&ha->loop_state, LOOP_UPDATE);
3199 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3200 if (ha->flags.online) {
3201 if (!(rval = qla2x00_fw_ready(ha))) {
3202 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3205 atomic_set(&ha->loop_state, LOOP_UPDATE);
3207 /* Issue a marker after FW becomes ready. */
3208 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3209 ha->marker_needed = 0;
3211 /* Remap devices on Loop. */
3212 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3214 qla2x00_configure_loop(ha);
3216 } while (!atomic_read(&ha->loop_down_timer) &&
3217 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3219 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3223 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3224 return (QLA_FUNCTION_FAILED);
3228 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3235 qla2x00_update_fcports(scsi_qla_host_t *ha)
3239 /* Go with deferred removal of rport references. */
3240 list_for_each_entry(fcport, &ha->fcports, list)
3241 if (fcport->drport &&
3242 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
3243 qla2x00_rport_del(fcport);
3248 * Resets ISP and aborts all outstanding commands.
3251 * ha = adapter block pointer.
3257 qla2x00_abort_isp(scsi_qla_host_t *ha)
3261 scsi_qla_host_t *vha;
3263 if (ha->flags.online) {
3264 ha->flags.online = 0;
3265 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3266 ha->qla_stats.total_isp_aborts++;
3268 qla_printk(KERN_INFO, ha,
3269 "Performing ISP error recovery - ha= %p.\n", ha);
3270 ha->isp_ops->reset_chip(ha);
3272 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3273 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3274 atomic_set(&ha->loop_state, LOOP_DOWN);
3275 qla2x00_mark_all_devices_lost(ha, 0);
3276 list_for_each_entry(vha, &ha->vp_list, vp_list)
3277 qla2x00_mark_all_devices_lost(vha, 0);
3279 if (!atomic_read(&ha->loop_down_timer))
3280 atomic_set(&ha->loop_down_timer,
3284 /* Requeue all commands in outstanding command list. */
3285 qla2x00_abort_all_cmds(ha, DID_RESET << 16);
3287 ha->isp_ops->get_flash_version(ha, ha->request_ring);
3289 ha->isp_ops->nvram_config(ha);
3291 if (!qla2x00_restart_isp(ha)) {
3292 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3294 if (!atomic_read(&ha->loop_down_timer)) {
3296 * Issue marker command only when we are going
3297 * to start the I/O .
3299 ha->marker_needed = 1;
3302 ha->flags.online = 1;
3304 ha->isp_ops->enable_intrs(ha);
3306 ha->isp_abort_cnt = 0;
3307 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3310 ha->flags.fce_enabled = 1;
3312 fce_calc_size(ha->fce_bufs));
3313 rval = qla2x00_enable_fce_trace(ha,
3314 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3317 qla_printk(KERN_WARNING, ha,
3318 "Unable to reinitialize FCE "
3320 ha->flags.fce_enabled = 0;
3325 memset(ha->eft, 0, EFT_SIZE);
3326 rval = qla2x00_enable_eft_trace(ha,
3327 ha->eft_dma, EFT_NUM_BUFFERS);
3329 qla_printk(KERN_WARNING, ha,
3330 "Unable to reinitialize EFT "
3334 } else { /* failed the ISP abort */
3335 ha->flags.online = 1;
3336 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3337 if (ha->isp_abort_cnt == 0) {
3338 qla_printk(KERN_WARNING, ha,
3339 "ISP error recovery failed - "
3340 "board disabled\n");
3342 * The next call disables the board
3345 ha->isp_ops->reset_adapter(ha);
3346 ha->flags.online = 0;
3347 clear_bit(ISP_ABORT_RETRY,
3350 } else { /* schedule another ISP abort */
3351 ha->isp_abort_cnt--;
3352 DEBUG(printk("qla%ld: ISP abort - "
3353 "retry remaining %d\n",
3354 ha->host_no, ha->isp_abort_cnt));
3358 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3359 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3360 "- retrying (%d) more times\n",
3361 ha->host_no, ha->isp_abort_cnt));
3362 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3370 qla_printk(KERN_INFO, ha,
3371 "qla2x00_abort_isp: **** FAILED ****\n");
3373 DEBUG(printk(KERN_INFO
3374 "qla2x00_abort_isp(%ld): exiting.\n",
3382 * qla2x00_restart_isp
3383 * restarts the ISP after a reset
3386 * ha = adapter block pointer.
3392 qla2x00_restart_isp(scsi_qla_host_t *ha)
3397 /* If firmware needs to be loaded */
3398 if (qla2x00_isp_firmware(ha)) {
3399 ha->flags.online = 0;
3400 if (!(status = ha->isp_ops->chip_diag(ha)))
3401 status = qla2x00_setup_chip(ha);
3404 if (!status && !(status = qla2x00_init_rings(ha))) {
3405 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3406 if (!(status = qla2x00_fw_ready(ha))) {
3407 DEBUG(printk("%s(): Start configure loop, "
3408 "status = %d\n", __func__, status));
3410 /* Issue a marker after FW becomes ready. */
3411 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3413 ha->flags.online = 1;
3414 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3417 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3418 qla2x00_configure_loop(ha);
3420 } while (!atomic_read(&ha->loop_down_timer) &&
3421 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3423 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3426 /* if no cable then assume it's good */
3427 if ((ha->device_flags & DFLG_NO_CABLE))
3430 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3438 * qla2x00_reset_adapter
3442 * ha = adapter block pointer.
3445 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3447 unsigned long flags = 0;
3448 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3450 ha->flags.online = 0;
3451 ha->isp_ops->disable_intrs(ha);
3453 spin_lock_irqsave(&ha->hardware_lock, flags);
3454 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3455 RD_REG_WORD(®->hccr); /* PCI Posting. */
3456 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3457 RD_REG_WORD(®->hccr); /* PCI Posting. */
3458 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3462 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3464 unsigned long flags = 0;
3465 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3467 ha->flags.online = 0;
3468 ha->isp_ops->disable_intrs(ha);
3470 spin_lock_irqsave(&ha->hardware_lock, flags);
3471 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3472 RD_REG_DWORD(®->hccr);
3473 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3474 RD_REG_DWORD(®->hccr);
3475 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3478 /* On sparc systems, obtain port and node WWN from firmware
3481 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, struct nvram_24xx *nv)
3484 struct pci_dev *pdev = ha->pdev;
3485 struct device_node *dp = pci_device_to_OF_node(pdev);
3489 val = of_get_property(dp, "port-wwn", &len);
3490 if (val && len >= WWN_SIZE)
3491 memcpy(nv->port_name, val, WWN_SIZE);
3493 val = of_get_property(dp, "node-wwn", &len);
3494 if (val && len >= WWN_SIZE)
3495 memcpy(nv->node_name, val, WWN_SIZE);
3500 qla24xx_nvram_config(scsi_qla_host_t *ha)
3503 struct init_cb_24xx *icb;
3504 struct nvram_24xx *nv;
3506 uint8_t *dptr1, *dptr2;
3511 icb = (struct init_cb_24xx *)ha->init_cb;
3514 /* Determine NVRAM starting address. */
3515 ha->nvram_size = sizeof(struct nvram_24xx);
3516 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3517 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3518 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3519 if (PCI_FUNC(ha->pdev->devfn)) {
3520 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3521 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3524 /* Get VPD data into cache */
3525 ha->vpd = ha->nvram + VPD_OFFSET;
3526 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd,
3527 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3529 /* Get NVRAM data into cache and calculate checksum. */
3530 dptr = (uint32_t *)nv;
3531 ha->isp_ops->read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3533 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3534 chksum += le32_to_cpu(*dptr++);
3536 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3537 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
3539 /* Bad NVRAM data, set defaults parameters. */
3540 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3541 || nv->id[3] != ' ' ||
3542 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3543 /* Reset NVRAM data. */
3544 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3545 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3546 le16_to_cpu(nv->nvram_version));
3547 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3548 "invalid -- WWPN) defaults.\n");
3551 * Set default initialization control block.
3553 memset(nv, 0, ha->nvram_size);
3554 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3555 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3556 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3557 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3558 nv->exchange_count = __constant_cpu_to_le16(0);
3559 nv->hard_address = __constant_cpu_to_le16(124);
3560 nv->port_name[0] = 0x21;
3561 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3562 nv->port_name[2] = 0x00;
3563 nv->port_name[3] = 0xe0;
3564 nv->port_name[4] = 0x8b;
3565 nv->port_name[5] = 0x1c;
3566 nv->port_name[6] = 0x55;
3567 nv->port_name[7] = 0x86;
3568 nv->node_name[0] = 0x20;
3569 nv->node_name[1] = 0x00;
3570 nv->node_name[2] = 0x00;
3571 nv->node_name[3] = 0xe0;
3572 nv->node_name[4] = 0x8b;
3573 nv->node_name[5] = 0x1c;
3574 nv->node_name[6] = 0x55;
3575 nv->node_name[7] = 0x86;
3576 qla24xx_nvram_wwn_from_ofw(ha, nv);
3577 nv->login_retry_count = __constant_cpu_to_le16(8);
3578 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3579 nv->login_timeout = __constant_cpu_to_le16(0);
3580 nv->firmware_options_1 =
3581 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3582 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3583 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3584 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3585 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3586 nv->efi_parameters = __constant_cpu_to_le32(0);
3587 nv->reset_delay = 5;
3588 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3589 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3590 nv->link_down_timeout = __constant_cpu_to_le16(30);
3595 /* Reset Initialization control block */
3596 memset(icb, 0, sizeof(struct init_cb_24xx));
3598 /* Copy 1st segment. */
3599 dptr1 = (uint8_t *)icb;
3600 dptr2 = (uint8_t *)&nv->version;
3601 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3603 *dptr1++ = *dptr2++;
3605 icb->login_retry_count = nv->login_retry_count;
3606 icb->link_down_on_nos = nv->link_down_on_nos;
3608 /* Copy 2nd segment. */
3609 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3610 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3611 cnt = (uint8_t *)&icb->reserved_3 -
3612 (uint8_t *)&icb->interrupt_delay_timer;
3614 *dptr1++ = *dptr2++;
3617 * Setup driver NVRAM options.
3619 qla2x00_set_model_info(ha, nv->model_name, sizeof(nv->model_name),
3622 /* Use alternate WWN? */
3623 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3624 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3625 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3628 /* Prepare nodename */
3629 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3631 * Firmware will apply the following mask if the nodename was
3634 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3635 icb->node_name[0] &= 0xF0;
3638 /* Set host adapter parameters. */
3639 ha->flags.disable_risc_code_load = 0;
3640 ha->flags.enable_lip_reset = 0;
3641 ha->flags.enable_lip_full_login =
3642 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3643 ha->flags.enable_target_reset =
3644 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
3645 ha->flags.enable_led_scheme = 0;
3646 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
3648 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3649 (BIT_6 | BIT_5 | BIT_4)) >> 4;
3651 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3652 sizeof(ha->fw_seriallink_options24));
3654 /* save HBA serial number */
3655 ha->serial0 = icb->port_name[5];
3656 ha->serial1 = icb->port_name[6];
3657 ha->serial2 = icb->port_name[7];
3658 ha->node_name = icb->node_name;
3659 ha->port_name = icb->port_name;
3661 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3663 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3665 /* Set minimum login_timeout to 4 seconds. */
3666 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3667 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3668 if (le16_to_cpu(nv->login_timeout) < 4)
3669 nv->login_timeout = __constant_cpu_to_le16(4);
3670 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3671 icb->login_timeout = nv->login_timeout;
3673 /* Set minimum RATOV to 100 tenths of a second. */
3676 ha->loop_reset_delay = nv->reset_delay;
3678 /* Link Down Timeout = 0:
3680 * When Port Down timer expires we will start returning
3681 * I/O's to OS with "DID_NO_CONNECT".
3683 * Link Down Timeout != 0:
3685 * The driver waits for the link to come up after link down
3686 * before returning I/Os to OS with "DID_NO_CONNECT".
3688 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3689 ha->loop_down_abort_time =
3690 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3692 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3693 ha->loop_down_abort_time =
3694 (LOOP_DOWN_TIME - ha->link_down_timeout);
3697 /* Need enough time to try and get the port back. */
3698 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3699 if (qlport_down_retry)
3700 ha->port_down_retry_count = qlport_down_retry;
3702 /* Set login_retry_count */
3703 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3704 if (ha->port_down_retry_count ==
3705 le16_to_cpu(nv->port_down_retry_count) &&
3706 ha->port_down_retry_count > 3)
3707 ha->login_retry_count = ha->port_down_retry_count;
3708 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3709 ha->login_retry_count = ha->port_down_retry_count;
3710 if (ql2xloginretrycount)
3711 ha->login_retry_count = ql2xloginretrycount;
3714 if (!ha->flags.init_done) {
3715 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3716 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3717 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3718 le16_to_cpu(icb->interrupt_delay_timer): 2;
3720 icb->firmware_options_2 &= __constant_cpu_to_le32(
3721 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3722 ha->flags.process_response_queue = 0;
3723 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3724 ha->zio_mode = QLA_ZIO_MODE_6;
3726 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3727 "(%d us).\n", ha->host_no, ha->zio_mode,
3728 ha->zio_timer * 100));
3729 qla_printk(KERN_INFO, ha,
3730 "ZIO mode %d enabled; timer delay (%d us).\n",
3731 ha->zio_mode, ha->zio_timer * 100);
3733 icb->firmware_options_2 |= cpu_to_le32(
3734 (uint32_t)ha->zio_mode);
3735 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3736 ha->flags.process_response_queue = 1;
3740 DEBUG2_3(printk(KERN_WARNING
3741 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3747 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3750 int segments, fragment;
3752 uint32_t *dcode, dlen;
3759 segments = FA_RISC_CODE_SEGMENTS;
3760 faddr = ha->flt_region_fw;
3761 dcode = (uint32_t *)ha->request_ring;
3764 /* Validate firmware image by checking version. */
3765 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3766 for (i = 0; i < 4; i++)
3767 dcode[i] = be32_to_cpu(dcode[i]);
3768 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3769 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3770 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3772 qla_printk(KERN_WARNING, ha,
3773 "Unable to verify integrity of flash firmware image!\n");
3774 qla_printk(KERN_WARNING, ha,
3775 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3776 dcode[1], dcode[2], dcode[3]);
3778 return QLA_FUNCTION_FAILED;
3781 while (segments && rval == QLA_SUCCESS) {
3782 /* Read segment's load information. */
3783 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3785 risc_addr = be32_to_cpu(dcode[2]);
3786 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3787 risc_size = be32_to_cpu(dcode[3]);
3790 while (risc_size > 0 && rval == QLA_SUCCESS) {
3791 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3792 if (dlen > risc_size)
3795 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3796 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3797 ha->host_no, risc_addr, dlen, faddr));
3799 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3800 for (i = 0; i < dlen; i++)
3801 dcode[i] = swab32(dcode[i]);
3803 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3806 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3807 "segment %d of firmware\n", ha->host_no,
3809 qla_printk(KERN_WARNING, ha,
3810 "[ERROR] Failed to load segment %d of "
3811 "firmware\n", fragment);
3828 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3831 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3835 uint16_t *wcode, *fwcode;
3836 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3837 struct fw_blob *blob;
3839 /* Load firmware blob. */
3840 blob = qla2x00_request_firmware(ha);
3842 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3843 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3844 "from: " QLA_FW_URL ".\n");
3845 return QLA_FUNCTION_FAILED;
3850 wcode = (uint16_t *)ha->request_ring;
3852 fwcode = (uint16_t *)blob->fw->data;
3855 /* Validate firmware image by checking version. */
3856 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3857 qla_printk(KERN_WARNING, ha,
3858 "Unable to verify integrity of firmware image (%Zd)!\n",
3860 goto fail_fw_integrity;
3862 for (i = 0; i < 4; i++)
3863 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3864 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3865 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3866 wcode[2] == 0 && wcode[3] == 0)) {
3867 qla_printk(KERN_WARNING, ha,
3868 "Unable to verify integrity of firmware image!\n");
3869 qla_printk(KERN_WARNING, ha,
3870 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3871 wcode[1], wcode[2], wcode[3]);
3872 goto fail_fw_integrity;
3876 while (*seg && rval == QLA_SUCCESS) {
3878 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3879 risc_size = be16_to_cpu(fwcode[3]);
3881 /* Validate firmware image size. */
3882 fwclen += risc_size * sizeof(uint16_t);
3883 if (blob->fw->size < fwclen) {
3884 qla_printk(KERN_WARNING, ha,
3885 "Unable to verify integrity of firmware image "
3886 "(%Zd)!\n", blob->fw->size);
3887 goto fail_fw_integrity;
3891 while (risc_size > 0 && rval == QLA_SUCCESS) {
3892 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3893 if (wlen > risc_size)
3896 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3897 "addr %x, number of words 0x%x.\n", ha->host_no,
3900 for (i = 0; i < wlen; i++)
3901 wcode[i] = swab16(fwcode[i]);
3903 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3906 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3907 "segment %d of firmware\n", ha->host_no,
3909 qla_printk(KERN_WARNING, ha,
3910 "[ERROR] Failed to load segment %d of "
3911 "firmware\n", fragment);
3927 return QLA_FUNCTION_FAILED;
3931 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3934 int segments, fragment;
3935 uint32_t *dcode, dlen;
3939 struct fw_blob *blob;
3940 uint32_t *fwcode, fwclen;
3942 /* Load firmware blob. */
3943 blob = qla2x00_request_firmware(ha);
3945 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3946 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3947 "from: " QLA_FW_URL ".\n");
3949 /* Try to load RISC code from flash. */
3950 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3951 "outdated) firmware from flash.\n");
3952 return qla24xx_load_risc_flash(ha, srisc_addr);
3957 segments = FA_RISC_CODE_SEGMENTS;
3958 dcode = (uint32_t *)ha->request_ring;
3960 fwcode = (uint32_t *)blob->fw->data;
3963 /* Validate firmware image by checking version. */
3964 if (blob->fw->size < 8 * sizeof(uint32_t)) {
3965 qla_printk(KERN_WARNING, ha,
3966 "Unable to verify integrity of firmware image (%Zd)!\n",
3968 goto fail_fw_integrity;
3970 for (i = 0; i < 4; i++)
3971 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3972 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3973 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3974 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3976 qla_printk(KERN_WARNING, ha,
3977 "Unable to verify integrity of firmware image!\n");
3978 qla_printk(KERN_WARNING, ha,
3979 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3980 dcode[1], dcode[2], dcode[3]);
3981 goto fail_fw_integrity;
3984 while (segments && rval == QLA_SUCCESS) {
3985 risc_addr = be32_to_cpu(fwcode[2]);
3986 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3987 risc_size = be32_to_cpu(fwcode[3]);
3989 /* Validate firmware image size. */
3990 fwclen += risc_size * sizeof(uint32_t);
3991 if (blob->fw->size < fwclen) {
3992 qla_printk(KERN_WARNING, ha,
3993 "Unable to verify integrity of firmware image "
3994 "(%Zd)!\n", blob->fw->size);
3996 goto fail_fw_integrity;
4000 while (risc_size > 0 && rval == QLA_SUCCESS) {
4001 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4002 if (dlen > risc_size)
4005 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4006 "addr %x, number of dwords 0x%x.\n", ha->host_no,
4009 for (i = 0; i < dlen; i++)
4010 dcode[i] = swab32(fwcode[i]);
4012 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
4015 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4016 "segment %d of firmware\n", ha->host_no,
4018 qla_printk(KERN_WARNING, ha,
4019 "[ERROR] Failed to load segment %d of "
4020 "firmware\n", fragment);
4036 return QLA_FUNCTION_FAILED;
4040 qla2x00_try_to_stop_firmware(scsi_qla_host_t *ha)
4044 if (!IS_FWI2_CAPABLE(ha))
4046 if (!ha->fw_major_version)
4049 ret = qla2x00_stop_firmware(ha);
4050 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4051 retries ; retries--) {
4052 ha->isp_ops->reset_chip(ha);
4053 if (ha->isp_ops->chip_diag(ha) != QLA_SUCCESS)
4055 if (qla2x00_setup_chip(ha) != QLA_SUCCESS)
4057 qla_printk(KERN_INFO, ha,
4058 "Attempting retry of stop-firmware command...\n");
4059 ret = qla2x00_stop_firmware(ha);
4064 qla24xx_configure_vhba(scsi_qla_host_t *ha)
4066 int rval = QLA_SUCCESS;
4067 uint16_t mb[MAILBOX_REGISTER_COUNT];
4072 rval = qla2x00_fw_ready(ha->parent);
4073 if (rval == QLA_SUCCESS) {
4074 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
4075 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
4078 ha->flags.management_server_logged_in = 0;
4080 /* Login to SNS first */
4081 qla24xx_login_fabric(ha->parent, NPH_SNS, 0xff, 0xff, 0xfc,
4083 if (mb[0] != MBS_COMMAND_COMPLETE) {
4084 DEBUG15(qla_printk(KERN_INFO, ha,
4085 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4086 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4087 mb[0], mb[1], mb[2], mb[6], mb[7]));
4088 return (QLA_FUNCTION_FAILED);
4091 atomic_set(&ha->loop_down_timer, 0);
4092 atomic_set(&ha->loop_state, LOOP_UP);
4093 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4094 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
4095 rval = qla2x00_loop_resync(ha->parent);
4100 /* 84XX Support **************************************************************/
4102 static LIST_HEAD(qla_cs84xx_list);
4103 static DEFINE_MUTEX(qla_cs84xx_mutex);
4105 static struct qla_chip_state_84xx *
4106 qla84xx_get_chip(struct scsi_qla_host *ha)
4108 struct qla_chip_state_84xx *cs84xx;
4110 mutex_lock(&qla_cs84xx_mutex);
4112 /* Find any shared 84xx chip. */
4113 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4114 if (cs84xx->bus == ha->pdev->bus) {
4115 kref_get(&cs84xx->kref);
4120 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4124 kref_init(&cs84xx->kref);
4125 spin_lock_init(&cs84xx->access_lock);
4126 mutex_init(&cs84xx->fw_update_mutex);
4127 cs84xx->bus = ha->pdev->bus;
4129 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4131 mutex_unlock(&qla_cs84xx_mutex);
4136 __qla84xx_chip_release(struct kref *kref)
4138 struct qla_chip_state_84xx *cs84xx =
4139 container_of(kref, struct qla_chip_state_84xx, kref);
4141 mutex_lock(&qla_cs84xx_mutex);
4142 list_del(&cs84xx->list);
4143 mutex_unlock(&qla_cs84xx_mutex);
4148 qla84xx_put_chip(struct scsi_qla_host *ha)
4151 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4155 qla84xx_init_chip(scsi_qla_host_t *ha)
4160 mutex_lock(&ha->cs84xx->fw_update_mutex);
4162 rval = qla84xx_verify_chip(ha, status);
4164 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4166 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED: