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 /****************************************************************************/
41 /* QLogic ISP2x00 Hardware Support Functions. */
42 /****************************************************************************/
45 * qla2x00_initialize_adapter
49 * ha = adapter block pointer.
55 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
59 /* Clear adapter flags. */
61 ha->flags.reset_active = 0;
62 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
63 atomic_set(&ha->loop_state, LOOP_DOWN);
64 ha->device_flags = DFLG_NO_CABLE;
66 ha->flags.management_server_logged_in = 0;
67 ha->marker_needed = 0;
69 ha->isp_abort_cnt = 0;
70 ha->beacon_blink_led = 0;
71 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
73 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
74 rval = ha->isp_ops->pci_config(ha);
76 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
81 ha->isp_ops->reset_chip(ha);
83 ha->isp_ops->get_flash_version(ha, ha->request_ring);
85 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
87 ha->isp_ops->nvram_config(ha);
89 if (ha->flags.disable_serdes) {
90 /* Mask HBA via NVRAM settings? */
91 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
92 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
93 ha->port_name[0], ha->port_name[1],
94 ha->port_name[2], ha->port_name[3],
95 ha->port_name[4], ha->port_name[5],
96 ha->port_name[6], ha->port_name[7]);
97 return QLA_FUNCTION_FAILED;
100 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
102 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
103 rval = ha->isp_ops->chip_diag(ha);
106 rval = qla2x00_setup_chip(ha);
109 qla2xxx_get_flash_info(ha);
111 rval = qla2x00_init_rings(ha);
117 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
120 * Returns 0 on success.
123 qla2100_pci_config(scsi_qla_host_t *ha)
128 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
130 pci_set_master(ha->pdev);
131 pci_try_set_mwi(ha->pdev);
133 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
134 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
135 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
137 /* Reset expansion ROM address decode enable */
138 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
139 d &= ~PCI_ROM_ADDRESS_ENABLE;
140 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
142 /* Get PCI bus information. */
143 spin_lock_irqsave(&ha->hardware_lock, flags);
144 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
145 spin_unlock_irqrestore(&ha->hardware_lock, flags);
151 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
154 * Returns 0 on success.
157 qla2300_pci_config(scsi_qla_host_t *ha)
161 unsigned long flags = 0;
163 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
165 pci_set_master(ha->pdev);
166 pci_try_set_mwi(ha->pdev);
168 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
169 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
171 if (IS_QLA2322(ha) || IS_QLA6322(ha))
172 w &= ~PCI_COMMAND_INTX_DISABLE;
173 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
176 * If this is a 2300 card and not 2312, reset the
177 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
178 * the 2310 also reports itself as a 2300 so we need to get the
179 * fb revision level -- a 6 indicates it really is a 2300 and
182 if (IS_QLA2300(ha)) {
183 spin_lock_irqsave(&ha->hardware_lock, flags);
186 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
187 for (cnt = 0; cnt < 30000; cnt++) {
188 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
194 /* Select FPM registers. */
195 WRT_REG_WORD(®->ctrl_status, 0x20);
196 RD_REG_WORD(®->ctrl_status);
198 /* Get the fb rev level */
199 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
201 if (ha->fb_rev == FPM_2300)
202 pci_clear_mwi(ha->pdev);
204 /* Deselect FPM registers. */
205 WRT_REG_WORD(®->ctrl_status, 0x0);
206 RD_REG_WORD(®->ctrl_status);
208 /* Release RISC module. */
209 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
210 for (cnt = 0; cnt < 30000; cnt++) {
211 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
217 spin_unlock_irqrestore(&ha->hardware_lock, flags);
220 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
222 /* Reset expansion ROM address decode enable */
223 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
224 d &= ~PCI_ROM_ADDRESS_ENABLE;
225 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
227 /* Get PCI bus information. */
228 spin_lock_irqsave(&ha->hardware_lock, flags);
229 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
230 spin_unlock_irqrestore(&ha->hardware_lock, flags);
236 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
239 * Returns 0 on success.
242 qla24xx_pci_config(scsi_qla_host_t *ha)
246 unsigned long flags = 0;
247 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
249 pci_set_master(ha->pdev);
250 pci_try_set_mwi(ha->pdev);
252 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
253 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
254 w &= ~PCI_COMMAND_INTX_DISABLE;
255 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
257 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
259 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
260 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
261 pcix_set_mmrbc(ha->pdev, 2048);
263 /* PCIe -- adjust Maximum Read Request Size (2048). */
264 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
265 pcie_set_readrq(ha->pdev, 2048);
267 /* Reset expansion ROM address decode enable */
268 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
269 d &= ~PCI_ROM_ADDRESS_ENABLE;
270 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
272 ha->chip_revision = ha->pdev->revision;
274 /* Get PCI bus information. */
275 spin_lock_irqsave(&ha->hardware_lock, flags);
276 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
277 spin_unlock_irqrestore(&ha->hardware_lock, flags);
283 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
286 * Returns 0 on success.
289 qla25xx_pci_config(scsi_qla_host_t *ha)
294 pci_set_master(ha->pdev);
295 pci_try_set_mwi(ha->pdev);
297 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
298 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
299 w &= ~PCI_COMMAND_INTX_DISABLE;
300 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
302 /* PCIe -- adjust Maximum Read Request Size (2048). */
303 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
304 pcie_set_readrq(ha->pdev, 2048);
306 /* Reset expansion ROM address decode enable */
307 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
308 d &= ~PCI_ROM_ADDRESS_ENABLE;
309 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
311 ha->chip_revision = ha->pdev->revision;
317 * qla2x00_isp_firmware() - Choose firmware image.
320 * Returns 0 on success.
323 qla2x00_isp_firmware(scsi_qla_host_t *ha)
327 /* Assume loading risc code */
328 rval = QLA_FUNCTION_FAILED;
330 if (ha->flags.disable_risc_code_load) {
331 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
333 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
335 /* Verify checksum of loaded RISC code. */
336 rval = qla2x00_verify_checksum(ha, ha->fw_srisc_address);
340 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
348 * qla2x00_reset_chip() - Reset ISP chip.
351 * Returns 0 on success.
354 qla2x00_reset_chip(scsi_qla_host_t *ha)
356 unsigned long flags = 0;
357 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
361 ha->isp_ops->disable_intrs(ha);
363 spin_lock_irqsave(&ha->hardware_lock, flags);
365 /* Turn off master enable */
367 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
368 cmd &= ~PCI_COMMAND_MASTER;
369 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
371 if (!IS_QLA2100(ha)) {
373 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
374 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
375 for (cnt = 0; cnt < 30000; cnt++) {
376 if ((RD_REG_WORD(®->hccr) &
377 HCCR_RISC_PAUSE) != 0)
382 RD_REG_WORD(®->hccr); /* PCI Posting. */
386 /* Select FPM registers. */
387 WRT_REG_WORD(®->ctrl_status, 0x20);
388 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
390 /* FPM Soft Reset. */
391 WRT_REG_WORD(®->fpm_diag_config, 0x100);
392 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
394 /* Toggle Fpm Reset. */
395 if (!IS_QLA2200(ha)) {
396 WRT_REG_WORD(®->fpm_diag_config, 0x0);
397 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
400 /* Select frame buffer registers. */
401 WRT_REG_WORD(®->ctrl_status, 0x10);
402 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
404 /* Reset frame buffer FIFOs. */
405 if (IS_QLA2200(ha)) {
406 WRT_FB_CMD_REG(ha, reg, 0xa000);
407 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
409 WRT_FB_CMD_REG(ha, reg, 0x00fc);
411 /* Read back fb_cmd until zero or 3 seconds max */
412 for (cnt = 0; cnt < 3000; cnt++) {
413 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
419 /* Select RISC module registers. */
420 WRT_REG_WORD(®->ctrl_status, 0);
421 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
423 /* Reset RISC processor. */
424 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
425 RD_REG_WORD(®->hccr); /* PCI Posting. */
427 /* Release RISC processor. */
428 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
429 RD_REG_WORD(®->hccr); /* PCI Posting. */
432 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
433 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
435 /* Reset ISP chip. */
436 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
438 /* Wait for RISC to recover from reset. */
439 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
441 * It is necessary to for a delay here since the card doesn't
442 * respond to PCI reads during a reset. On some architectures
443 * this will result in an MCA.
446 for (cnt = 30000; cnt; cnt--) {
447 if ((RD_REG_WORD(®->ctrl_status) &
448 CSR_ISP_SOFT_RESET) == 0)
455 /* Reset RISC processor. */
456 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
458 WRT_REG_WORD(®->semaphore, 0);
460 /* Release RISC processor. */
461 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
462 RD_REG_WORD(®->hccr); /* PCI Posting. */
464 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
465 for (cnt = 0; cnt < 30000; cnt++) {
466 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
474 /* Turn on master enable */
475 cmd |= PCI_COMMAND_MASTER;
476 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
478 /* Disable RISC pause on FPM parity error. */
479 if (!IS_QLA2100(ha)) {
480 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
481 RD_REG_WORD(®->hccr); /* PCI Posting. */
484 spin_unlock_irqrestore(&ha->hardware_lock, flags);
488 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
491 * Returns 0 on success.
494 qla24xx_reset_risc(scsi_qla_host_t *ha)
497 unsigned long flags = 0;
498 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
502 spin_lock_irqsave(&ha->hardware_lock, flags);
505 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
506 for (cnt = 0; cnt < 30000; cnt++) {
507 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
513 WRT_REG_DWORD(®->ctrl_status,
514 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
515 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
518 /* Wait for firmware to complete NVRAM accesses. */
519 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
520 for (cnt = 10000 ; cnt && d2; cnt--) {
522 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
528 /* Wait for soft-reset to complete. */
529 d2 = RD_REG_DWORD(®->ctrl_status);
530 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
532 d2 = RD_REG_DWORD(®->ctrl_status);
535 if (cnt == 0 || hw_evt)
536 qla2xxx_hw_event_log(ha, HW_EVENT_RESET_ERR,
537 RD_REG_WORD(®->mailbox1), RD_REG_WORD(®->mailbox2),
538 RD_REG_WORD(®->mailbox3));
540 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
541 RD_REG_DWORD(®->hccr);
543 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
544 RD_REG_DWORD(®->hccr);
546 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
547 RD_REG_DWORD(®->hccr);
549 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
550 for (cnt = 6000000 ; cnt && d2; cnt--) {
552 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
556 spin_unlock_irqrestore(&ha->hardware_lock, flags);
560 * qla24xx_reset_chip() - Reset ISP24xx chip.
563 * Returns 0 on success.
566 qla24xx_reset_chip(scsi_qla_host_t *ha)
568 ha->isp_ops->disable_intrs(ha);
570 /* Perform RISC reset. */
571 qla24xx_reset_risc(ha);
575 * qla2x00_chip_diag() - Test chip for proper operation.
578 * Returns 0 on success.
581 qla2x00_chip_diag(scsi_qla_host_t *ha)
584 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
585 unsigned long flags = 0;
590 /* Assume a failed state */
591 rval = QLA_FUNCTION_FAILED;
593 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
594 ha->host_no, (u_long)®->flash_address));
596 spin_lock_irqsave(&ha->hardware_lock, flags);
598 /* Reset ISP chip. */
599 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
602 * We need to have a delay here since the card will not respond while
603 * in reset causing an MCA on some architectures.
606 data = qla2x00_debounce_register(®->ctrl_status);
607 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
609 data = RD_REG_WORD(®->ctrl_status);
614 goto chip_diag_failed;
616 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
619 /* Reset RISC processor. */
620 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
621 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
623 /* Workaround for QLA2312 PCI parity error */
624 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
625 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
626 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
628 data = RD_MAILBOX_REG(ha, reg, 0);
635 goto chip_diag_failed;
637 /* Check product ID of chip */
638 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
640 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
641 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
642 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
643 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
644 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
645 mb[3] != PROD_ID_3) {
646 qla_printk(KERN_WARNING, ha,
647 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
649 goto chip_diag_failed;
651 ha->product_id[0] = mb[1];
652 ha->product_id[1] = mb[2];
653 ha->product_id[2] = mb[3];
654 ha->product_id[3] = mb[4];
656 /* Adjust fw RISC transfer size */
657 if (ha->request_q_length > 1024)
658 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
660 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
661 ha->request_q_length;
663 if (IS_QLA2200(ha) &&
664 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
665 /* Limit firmware transfer size with a 2200A */
666 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
669 ha->device_type |= DT_ISP2200A;
670 ha->fw_transfer_size = 128;
673 /* Wrap Incoming Mailboxes Test. */
674 spin_unlock_irqrestore(&ha->hardware_lock, flags);
676 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
677 rval = qla2x00_mbx_reg_test(ha);
679 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
681 qla_printk(KERN_WARNING, ha,
682 "Failed mailbox send register test\n");
685 /* Flag a successful rval */
688 spin_lock_irqsave(&ha->hardware_lock, flags);
692 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
693 "****\n", ha->host_no));
695 spin_unlock_irqrestore(&ha->hardware_lock, flags);
701 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
704 * Returns 0 on success.
707 qla24xx_chip_diag(scsi_qla_host_t *ha)
711 /* Perform RISC reset. */
712 qla24xx_reset_risc(ha);
714 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
716 rval = qla2x00_mbx_reg_test(ha);
718 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
720 qla_printk(KERN_WARNING, ha,
721 "Failed mailbox send register test\n");
723 /* Flag a successful rval */
731 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
734 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
740 qla_printk(KERN_WARNING, ha,
741 "Firmware dump previously allocated.\n");
746 fixed_size = mem_size = eft_size = fce_size = 0;
747 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
748 fixed_size = sizeof(struct qla2100_fw_dump);
749 } else if (IS_QLA23XX(ha)) {
750 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
751 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
753 } else if (IS_FWI2_CAPABLE(ha)) {
754 fixed_size = IS_QLA25XX(ha) ?
755 offsetof(struct qla25xx_fw_dump, ext_mem):
756 offsetof(struct qla24xx_fw_dump, ext_mem);
757 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
760 /* Allocate memory for Extended Trace Buffer. */
761 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
764 qla_printk(KERN_WARNING, ha, "Unable to allocate "
765 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
769 memset(tc, 0, EFT_SIZE);
770 rval = qla2x00_enable_eft_trace(ha, tc_dma, EFT_NUM_BUFFERS);
772 qla_printk(KERN_WARNING, ha, "Unable to initialize "
773 "EFT (%d).\n", rval);
774 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
779 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
783 ha->eft_dma = tc_dma;
786 /* Allocate memory for Fibre Channel Event Buffer. */
790 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
793 qla_printk(KERN_WARNING, ha, "Unable to allocate "
794 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
798 memset(tc, 0, FCE_SIZE);
799 rval = qla2x00_enable_fce_trace(ha, tc_dma, FCE_NUM_BUFFERS,
800 ha->fce_mb, &ha->fce_bufs);
802 qla_printk(KERN_WARNING, ha, "Unable to initialize "
803 "FCE (%d).\n", rval);
804 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
806 ha->flags.fce_enabled = 0;
810 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
813 fce_size = sizeof(struct qla2xxx_fce_chain) + EFT_SIZE;
814 ha->flags.fce_enabled = 1;
815 ha->fce_dma = tc_dma;
819 req_q_size = ha->request_q_length * sizeof(request_t);
820 rsp_q_size = ha->response_q_length * sizeof(response_t);
822 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
823 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
826 ha->fw_dump = vmalloc(dump_size);
828 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
829 "firmware dump!!!\n", dump_size / 1024);
832 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
840 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
843 ha->fw_dump_len = dump_size;
844 ha->fw_dump->signature[0] = 'Q';
845 ha->fw_dump->signature[1] = 'L';
846 ha->fw_dump->signature[2] = 'G';
847 ha->fw_dump->signature[3] = 'C';
848 ha->fw_dump->version = __constant_htonl(1);
850 ha->fw_dump->fixed_size = htonl(fixed_size);
851 ha->fw_dump->mem_size = htonl(mem_size);
852 ha->fw_dump->req_q_size = htonl(req_q_size);
853 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
855 ha->fw_dump->eft_size = htonl(eft_size);
856 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
857 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
859 ha->fw_dump->header_size =
860 htonl(offsetof(struct qla2xxx_fw_dump, isp));
864 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
867 * Returns 0 on success.
870 qla2x00_resize_request_q(scsi_qla_host_t *ha)
873 uint16_t fw_iocb_cnt = 0;
874 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
875 dma_addr_t request_dma;
876 request_t *request_ring;
878 /* Valid only on recent ISPs. */
879 if (IS_QLA2100(ha) || IS_QLA2200(ha))
882 /* Retrieve IOCB counts available to the firmware. */
883 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt,
884 &ha->max_npiv_vports);
887 /* No point in continuing if current settings are sufficient. */
888 if (fw_iocb_cnt < 1024)
890 if (ha->request_q_length >= request_q_length)
893 /* Attempt to claim larger area for request queue. */
894 request_ring = dma_alloc_coherent(&ha->pdev->dev,
895 (request_q_length + 1) * sizeof(request_t), &request_dma,
897 if (request_ring == NULL)
900 /* Resize successful, report extensions. */
901 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
902 (ha->fw_memory_size + 1) / 1024);
903 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
904 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
906 /* Clear old allocations. */
907 dma_free_coherent(&ha->pdev->dev,
908 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
911 /* Begin using larger queue. */
912 ha->request_q_length = request_q_length;
913 ha->request_ring = request_ring;
914 ha->request_dma = request_dma;
918 * qla2x00_setup_chip() - Load and start RISC firmware.
921 * Returns 0 on success.
924 qla2x00_setup_chip(scsi_qla_host_t *ha)
927 uint32_t srisc_address = 0;
928 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
931 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
932 /* Disable SRAM, Instruction RAM and GP RAM parity. */
933 spin_lock_irqsave(&ha->hardware_lock, flags);
934 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
935 RD_REG_WORD(®->hccr);
936 spin_unlock_irqrestore(&ha->hardware_lock, flags);
939 /* Load firmware sequences */
940 rval = ha->isp_ops->load_risc(ha, &srisc_address);
941 if (rval == QLA_SUCCESS) {
942 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
943 "code.\n", ha->host_no));
945 rval = qla2x00_verify_checksum(ha, srisc_address);
946 if (rval == QLA_SUCCESS) {
947 /* Start firmware execution. */
948 DEBUG(printk("scsi(%ld): Checksum OK, start "
949 "firmware.\n", ha->host_no));
951 rval = qla2x00_execute_fw(ha, srisc_address);
952 /* Retrieve firmware information. */
953 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
954 qla2x00_get_fw_version(ha,
955 &ha->fw_major_version,
956 &ha->fw_minor_version,
957 &ha->fw_subminor_version,
958 &ha->fw_attributes, &ha->fw_memory_size);
959 qla2x00_resize_request_q(ha);
960 ha->flags.npiv_supported = 0;
961 if ((IS_QLA24XX(ha) || IS_QLA25XX(ha)) &&
962 (ha->fw_attributes & BIT_2)) {
963 ha->flags.npiv_supported = 1;
964 if ((!ha->max_npiv_vports) ||
965 ((ha->max_npiv_vports + 1) %
966 MIN_MULTI_ID_FABRIC))
967 ha->max_npiv_vports =
968 MIN_MULTI_ID_FABRIC - 1;
972 qla2x00_alloc_fw_dump(ha);
975 DEBUG2(printk(KERN_INFO
976 "scsi(%ld): ISP Firmware failed checksum.\n",
981 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
982 /* Enable proper parity. */
983 spin_lock_irqsave(&ha->hardware_lock, flags);
986 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
988 /* SRAM, Instruction RAM and GP RAM parity */
989 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
990 RD_REG_WORD(®->hccr);
991 spin_unlock_irqrestore(&ha->hardware_lock, flags);
995 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
1003 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1006 * Beginning of request ring has initialization control block already built
1007 * by nvram config routine.
1009 * Returns 0 on success.
1012 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
1017 pkt = ha->response_ring_ptr;
1018 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
1019 pkt->signature = RESPONSE_PROCESSED;
1026 * qla2x00_update_fw_options() - Read and process firmware options.
1029 * Returns 0 on success.
1032 qla2x00_update_fw_options(scsi_qla_host_t *ha)
1034 uint16_t swing, emphasis, tx_sens, rx_sens;
1036 memset(ha->fw_options, 0, sizeof(ha->fw_options));
1037 qla2x00_get_fw_options(ha, ha->fw_options);
1039 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1042 /* Serial Link options. */
1043 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1045 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1046 sizeof(ha->fw_seriallink_options)));
1048 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1049 if (ha->fw_seriallink_options[3] & BIT_2) {
1050 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1053 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1054 emphasis = (ha->fw_seriallink_options[2] &
1055 (BIT_4 | BIT_3)) >> 3;
1056 tx_sens = ha->fw_seriallink_options[0] &
1057 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1058 rx_sens = (ha->fw_seriallink_options[0] &
1059 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1060 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1061 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1064 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1065 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1066 ha->fw_options[10] |= BIT_5 |
1067 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1068 (tx_sens & (BIT_1 | BIT_0));
1071 swing = (ha->fw_seriallink_options[2] &
1072 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1073 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1074 tx_sens = ha->fw_seriallink_options[1] &
1075 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1076 rx_sens = (ha->fw_seriallink_options[1] &
1077 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1078 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1079 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1082 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1083 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1084 ha->fw_options[11] |= BIT_5 |
1085 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1086 (tx_sens & (BIT_1 | BIT_0));
1090 /* Return command IOCBs without waiting for an ABTS to complete. */
1091 ha->fw_options[3] |= BIT_13;
1094 if (ha->flags.enable_led_scheme)
1095 ha->fw_options[2] |= BIT_12;
1097 /* Detect ISP6312. */
1099 ha->fw_options[2] |= BIT_13;
1101 /* Update firmware options. */
1102 qla2x00_set_fw_options(ha, ha->fw_options);
1106 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1110 /* Update Serial Link options. */
1111 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1114 rval = qla2x00_set_serdes_params(ha,
1115 le16_to_cpu(ha->fw_seriallink_options24[1]),
1116 le16_to_cpu(ha->fw_seriallink_options24[2]),
1117 le16_to_cpu(ha->fw_seriallink_options24[3]));
1118 if (rval != QLA_SUCCESS) {
1119 qla_printk(KERN_WARNING, ha,
1120 "Unable to update Serial Link options (%x).\n", rval);
1125 qla2x00_config_rings(struct scsi_qla_host *ha)
1127 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1129 /* Setup ring parameters in initialization control block. */
1130 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1131 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1132 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1133 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1134 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1135 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1136 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1137 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1139 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1140 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1141 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1142 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1143 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1147 qla24xx_config_rings(struct scsi_qla_host *ha)
1149 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1150 struct init_cb_24xx *icb;
1152 /* Setup ring parameters in initialization control block. */
1153 icb = (struct init_cb_24xx *)ha->init_cb;
1154 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1155 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1156 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1157 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1158 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1159 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1160 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1161 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1163 WRT_REG_DWORD(®->req_q_in, 0);
1164 WRT_REG_DWORD(®->req_q_out, 0);
1165 WRT_REG_DWORD(®->rsp_q_in, 0);
1166 WRT_REG_DWORD(®->rsp_q_out, 0);
1167 RD_REG_DWORD(®->rsp_q_out);
1171 * qla2x00_init_rings() - Initializes firmware.
1174 * Beginning of request ring has initialization control block already built
1175 * by nvram config routine.
1177 * Returns 0 on success.
1180 qla2x00_init_rings(scsi_qla_host_t *ha)
1183 unsigned long flags = 0;
1185 struct mid_init_cb_24xx *mid_init_cb =
1186 (struct mid_init_cb_24xx *) ha->init_cb;
1188 spin_lock_irqsave(&ha->hardware_lock, flags);
1190 /* Clear outstanding commands array. */
1191 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1192 ha->outstanding_cmds[cnt] = NULL;
1194 ha->current_outstanding_cmd = 0;
1196 /* Clear RSCN queue. */
1197 ha->rscn_in_ptr = 0;
1198 ha->rscn_out_ptr = 0;
1200 /* Initialize firmware. */
1201 ha->request_ring_ptr = ha->request_ring;
1202 ha->req_ring_index = 0;
1203 ha->req_q_cnt = ha->request_q_length;
1204 ha->response_ring_ptr = ha->response_ring;
1205 ha->rsp_ring_index = 0;
1207 /* Initialize response queue entries */
1208 qla2x00_init_response_q_entries(ha);
1210 ha->isp_ops->config_rings(ha);
1212 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1214 /* Update any ISP specific firmware options before initialization. */
1215 ha->isp_ops->update_fw_options(ha);
1217 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1219 if (ha->flags.npiv_supported)
1220 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1222 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1224 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1226 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1229 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1237 * qla2x00_fw_ready() - Waits for firmware ready.
1240 * Returns 0 on success.
1243 qla2x00_fw_ready(scsi_qla_host_t *ha)
1246 unsigned long wtime, mtime;
1247 uint16_t min_wait; /* Minimum wait time if loop is down */
1248 uint16_t wait_time; /* Wait time if loop is coming ready */
1253 /* 20 seconds for loop down. */
1257 * Firmware should take at most one RATOV to login, plus 5 seconds for
1258 * our own processing.
1260 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1261 wait_time = min_wait;
1264 /* Min wait time if loop down */
1265 mtime = jiffies + (min_wait * HZ);
1267 /* wait time before firmware ready */
1268 wtime = jiffies + (wait_time * HZ);
1270 /* Wait for ISP to finish LIP */
1271 if (!ha->flags.init_done)
1272 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1274 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1278 rval = qla2x00_get_firmware_state(ha, &fw_state);
1279 if (rval == QLA_SUCCESS) {
1280 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1281 ha->device_flags &= ~DFLG_NO_CABLE;
1283 if (fw_state == FSTATE_READY) {
1284 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1287 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1288 &ha->login_timeout, &ha->r_a_tov);
1294 rval = QLA_FUNCTION_FAILED;
1296 if (atomic_read(&ha->loop_down_timer) &&
1297 fw_state != FSTATE_READY) {
1298 /* Loop down. Timeout on min_wait for states
1299 * other than Wait for Login.
1301 if (time_after_eq(jiffies, mtime)) {
1302 qla_printk(KERN_INFO, ha,
1303 "Cable is unplugged...\n");
1305 ha->device_flags |= DFLG_NO_CABLE;
1310 /* Mailbox cmd failed. Timeout on min_wait. */
1311 if (time_after_eq(jiffies, mtime))
1315 if (time_after_eq(jiffies, wtime))
1318 /* Delay for a while */
1321 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1322 ha->host_no, fw_state, jiffies));
1325 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1326 ha->host_no, fw_state, jiffies));
1329 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1337 * qla2x00_configure_hba
1338 * Setup adapter context.
1341 * ha = adapter state pointer.
1350 qla2x00_configure_hba(scsi_qla_host_t *ha)
1359 char connect_type[22];
1361 /* Get host addresses. */
1362 rval = qla2x00_get_adapter_id(ha,
1363 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
1364 if (rval != QLA_SUCCESS) {
1365 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
1366 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1367 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1368 __func__, ha->host_no));
1370 qla_printk(KERN_WARNING, ha,
1371 "ERROR -- Unable to get host loop ID.\n");
1372 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1378 qla_printk(KERN_INFO, ha,
1379 "Cannot get topology - retrying.\n");
1380 return (QLA_FUNCTION_FAILED);
1383 ha->loop_id = loop_id;
1386 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1387 ha->operating_mode = LOOP;
1392 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1394 ha->current_topology = ISP_CFG_NL;
1395 strcpy(connect_type, "(Loop)");
1399 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1401 ha->switch_cap = sw_cap;
1402 ha->current_topology = ISP_CFG_FL;
1403 strcpy(connect_type, "(FL_Port)");
1407 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1409 ha->operating_mode = P2P;
1410 ha->current_topology = ISP_CFG_N;
1411 strcpy(connect_type, "(N_Port-to-N_Port)");
1415 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1417 ha->switch_cap = sw_cap;
1418 ha->operating_mode = P2P;
1419 ha->current_topology = ISP_CFG_F;
1420 strcpy(connect_type, "(F_Port)");
1424 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1426 ha->host_no, topo));
1427 ha->current_topology = ISP_CFG_NL;
1428 strcpy(connect_type, "(Loop)");
1432 /* Save Host port and loop ID. */
1433 /* byte order - Big Endian */
1434 ha->d_id.b.domain = domain;
1435 ha->d_id.b.area = area;
1436 ha->d_id.b.al_pa = al_pa;
1438 if (!ha->flags.init_done)
1439 qla_printk(KERN_INFO, ha,
1440 "Topology - %s, Host Loop address 0x%x\n",
1441 connect_type, ha->loop_id);
1444 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1446 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1453 qla2x00_set_model_info(scsi_qla_host_t *ha, uint8_t *model, size_t len, char *def)
1458 if (memcmp(model, BINZERO, len) != 0) {
1459 strncpy(ha->model_number, model, len);
1460 st = en = ha->model_number;
1463 if (*en != 0x20 && *en != 0x00)
1468 index = (ha->pdev->subsystem_device & 0xff);
1469 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1470 index < QLA_MODEL_NAMES)
1471 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1473 index = (ha->pdev->subsystem_device & 0xff);
1474 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1475 index < QLA_MODEL_NAMES) {
1476 strcpy(ha->model_number,
1477 qla2x00_model_name[index * 2]);
1478 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1480 strcpy(ha->model_number, def);
1485 /* On sparc systems, obtain port and node WWN from firmware
1488 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, nvram_t *nv)
1491 struct pci_dev *pdev = ha->pdev;
1492 struct device_node *dp = pci_device_to_OF_node(pdev);
1496 val = of_get_property(dp, "port-wwn", &len);
1497 if (val && len >= WWN_SIZE)
1498 memcpy(nv->port_name, val, WWN_SIZE);
1500 val = of_get_property(dp, "node-wwn", &len);
1501 if (val && len >= WWN_SIZE)
1502 memcpy(nv->node_name, val, WWN_SIZE);
1507 * NVRAM configuration for ISP 2xxx
1510 * ha = adapter block pointer.
1513 * initialization control block in response_ring
1514 * host adapters parameters in host adapter block
1520 qla2x00_nvram_config(scsi_qla_host_t *ha)
1525 uint8_t *dptr1, *dptr2;
1526 init_cb_t *icb = ha->init_cb;
1527 nvram_t *nv = ha->nvram;
1528 uint8_t *ptr = ha->nvram;
1529 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1533 /* Determine NVRAM starting address. */
1534 ha->nvram_size = sizeof(nvram_t);
1536 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1537 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1538 ha->nvram_base = 0x80;
1540 /* Get NVRAM data and calculate checksum. */
1541 ha->isp_ops->read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1542 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1545 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1546 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
1548 /* Bad NVRAM data, set defaults parameters. */
1549 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1550 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1551 /* Reset NVRAM data. */
1552 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1553 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1555 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1556 "invalid -- WWPN) defaults.\n");
1559 qla2xxx_hw_event_log(ha, HW_EVENT_NVRAM_CHKSUM_ERR, 0,
1560 MSW(chksum), LSW(chksum));
1563 * Set default initialization control block.
1565 memset(nv, 0, ha->nvram_size);
1566 nv->parameter_block_version = ICB_VERSION;
1568 if (IS_QLA23XX(ha)) {
1569 nv->firmware_options[0] = BIT_2 | BIT_1;
1570 nv->firmware_options[1] = BIT_7 | BIT_5;
1571 nv->add_firmware_options[0] = BIT_5;
1572 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1573 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1574 nv->special_options[1] = BIT_7;
1575 } else if (IS_QLA2200(ha)) {
1576 nv->firmware_options[0] = BIT_2 | BIT_1;
1577 nv->firmware_options[1] = BIT_7 | BIT_5;
1578 nv->add_firmware_options[0] = BIT_5;
1579 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1580 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1581 } else if (IS_QLA2100(ha)) {
1582 nv->firmware_options[0] = BIT_3 | BIT_1;
1583 nv->firmware_options[1] = BIT_5;
1584 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1587 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1588 nv->execution_throttle = __constant_cpu_to_le16(16);
1589 nv->retry_count = 8;
1590 nv->retry_delay = 1;
1592 nv->port_name[0] = 33;
1593 nv->port_name[3] = 224;
1594 nv->port_name[4] = 139;
1596 qla2xxx_nvram_wwn_from_ofw(ha, nv);
1598 nv->login_timeout = 4;
1601 * Set default host adapter parameters
1603 nv->host_p[1] = BIT_2;
1604 nv->reset_delay = 5;
1605 nv->port_down_retry_count = 8;
1606 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1607 nv->link_down_timeout = 60;
1612 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1614 * The SN2 does not provide BIOS emulation which means you can't change
1615 * potentially bogus BIOS settings. Force the use of default settings
1616 * for link rate and frame size. Hope that the rest of the settings
1619 if (ia64_platform_is("sn2")) {
1620 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1622 nv->special_options[1] = BIT_7;
1626 /* Reset Initialization control block */
1627 memset(icb, 0, ha->init_cb_size);
1630 * Setup driver NVRAM options.
1632 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1633 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1634 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1635 nv->firmware_options[1] &= ~BIT_4;
1637 if (IS_QLA23XX(ha)) {
1638 nv->firmware_options[0] |= BIT_2;
1639 nv->firmware_options[0] &= ~BIT_3;
1640 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1642 if (IS_QLA2300(ha)) {
1643 if (ha->fb_rev == FPM_2310) {
1644 strcpy(ha->model_number, "QLA2310");
1646 strcpy(ha->model_number, "QLA2300");
1649 qla2x00_set_model_info(ha, nv->model_number,
1650 sizeof(nv->model_number), "QLA23xx");
1652 } else if (IS_QLA2200(ha)) {
1653 nv->firmware_options[0] |= BIT_2;
1655 * 'Point-to-point preferred, else loop' is not a safe
1656 * connection mode setting.
1658 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1660 /* Force 'loop preferred, else point-to-point'. */
1661 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1662 nv->add_firmware_options[0] |= BIT_5;
1664 strcpy(ha->model_number, "QLA22xx");
1665 } else /*if (IS_QLA2100(ha))*/ {
1666 strcpy(ha->model_number, "QLA2100");
1670 * Copy over NVRAM RISC parameter block to initialization control block.
1672 dptr1 = (uint8_t *)icb;
1673 dptr2 = (uint8_t *)&nv->parameter_block_version;
1674 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1676 *dptr1++ = *dptr2++;
1678 /* Copy 2nd half. */
1679 dptr1 = (uint8_t *)icb->add_firmware_options;
1680 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1682 *dptr1++ = *dptr2++;
1684 /* Use alternate WWN? */
1685 if (nv->host_p[1] & BIT_7) {
1686 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1687 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1690 /* Prepare nodename */
1691 if ((icb->firmware_options[1] & BIT_6) == 0) {
1693 * Firmware will apply the following mask if the nodename was
1696 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1697 icb->node_name[0] &= 0xF0;
1701 * Set host adapter parameters.
1703 if (nv->host_p[0] & BIT_7)
1704 ql2xextended_error_logging = 1;
1705 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1706 /* Always load RISC code on non ISP2[12]00 chips. */
1707 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1708 ha->flags.disable_risc_code_load = 0;
1709 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1710 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1711 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1712 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1713 ha->flags.disable_serdes = 0;
1715 ha->operating_mode =
1716 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1718 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1719 sizeof(ha->fw_seriallink_options));
1721 /* save HBA serial number */
1722 ha->serial0 = icb->port_name[5];
1723 ha->serial1 = icb->port_name[6];
1724 ha->serial2 = icb->port_name[7];
1725 ha->node_name = icb->node_name;
1726 ha->port_name = icb->port_name;
1728 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1730 ha->retry_count = nv->retry_count;
1732 /* Set minimum login_timeout to 4 seconds. */
1733 if (nv->login_timeout < ql2xlogintimeout)
1734 nv->login_timeout = ql2xlogintimeout;
1735 if (nv->login_timeout < 4)
1736 nv->login_timeout = 4;
1737 ha->login_timeout = nv->login_timeout;
1738 icb->login_timeout = nv->login_timeout;
1740 /* Set minimum RATOV to 100 tenths of a second. */
1743 ha->loop_reset_delay = nv->reset_delay;
1745 /* Link Down Timeout = 0:
1747 * When Port Down timer expires we will start returning
1748 * I/O's to OS with "DID_NO_CONNECT".
1750 * Link Down Timeout != 0:
1752 * The driver waits for the link to come up after link down
1753 * before returning I/Os to OS with "DID_NO_CONNECT".
1755 if (nv->link_down_timeout == 0) {
1756 ha->loop_down_abort_time =
1757 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1759 ha->link_down_timeout = nv->link_down_timeout;
1760 ha->loop_down_abort_time =
1761 (LOOP_DOWN_TIME - ha->link_down_timeout);
1765 * Need enough time to try and get the port back.
1767 ha->port_down_retry_count = nv->port_down_retry_count;
1768 if (qlport_down_retry)
1769 ha->port_down_retry_count = qlport_down_retry;
1770 /* Set login_retry_count */
1771 ha->login_retry_count = nv->retry_count;
1772 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1773 ha->port_down_retry_count > 3)
1774 ha->login_retry_count = ha->port_down_retry_count;
1775 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1776 ha->login_retry_count = ha->port_down_retry_count;
1777 if (ql2xloginretrycount)
1778 ha->login_retry_count = ql2xloginretrycount;
1780 icb->lun_enables = __constant_cpu_to_le16(0);
1781 icb->command_resource_count = 0;
1782 icb->immediate_notify_resource_count = 0;
1783 icb->timeout = __constant_cpu_to_le16(0);
1785 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1787 icb->firmware_options[0] &= ~BIT_3;
1788 icb->add_firmware_options[0] &=
1789 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1790 icb->add_firmware_options[0] |= BIT_2;
1791 icb->response_accumulation_timer = 3;
1792 icb->interrupt_delay_timer = 5;
1794 ha->flags.process_response_queue = 1;
1797 if (!ha->flags.init_done) {
1798 ha->zio_mode = icb->add_firmware_options[0] &
1799 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1800 ha->zio_timer = icb->interrupt_delay_timer ?
1801 icb->interrupt_delay_timer: 2;
1803 icb->add_firmware_options[0] &=
1804 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1805 ha->flags.process_response_queue = 0;
1806 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1807 ha->zio_mode = QLA_ZIO_MODE_6;
1809 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1810 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1811 ha->zio_timer * 100));
1812 qla_printk(KERN_INFO, ha,
1813 "ZIO mode %d enabled; timer delay (%d us).\n",
1814 ha->zio_mode, ha->zio_timer * 100);
1816 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1817 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1818 ha->flags.process_response_queue = 1;
1823 DEBUG2_3(printk(KERN_WARNING
1824 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1830 qla2x00_rport_del(void *data)
1832 fc_port_t *fcport = data;
1833 struct fc_rport *rport;
1834 unsigned long flags;
1836 spin_lock_irqsave(&fcport->rport_lock, flags);
1837 rport = fcport->drport;
1838 fcport->drport = NULL;
1839 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1841 fc_remote_port_delete(rport);
1845 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1847 * @flags: allocation flags
1849 * Returns a pointer to the allocated fcport, or NULL, if none available.
1852 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1856 fcport = kzalloc(sizeof(fc_port_t), flags);
1860 /* Setup fcport template structure. */
1862 fcport->vp_idx = ha->vp_idx;
1863 fcport->port_type = FCT_UNKNOWN;
1864 fcport->loop_id = FC_NO_LOOP_ID;
1865 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1866 fcport->flags = FCF_RLC_SUPPORT;
1867 fcport->supported_classes = FC_COS_UNSPECIFIED;
1868 spin_lock_init(&fcport->rport_lock);
1874 * qla2x00_configure_loop
1875 * Updates Fibre Channel Device Database with what is actually on loop.
1878 * ha = adapter block pointer.
1883 * 2 = database was full and device was not configured.
1886 qla2x00_configure_loop(scsi_qla_host_t *ha)
1889 unsigned long flags, save_flags;
1893 /* Get Initiator ID */
1894 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1895 rval = qla2x00_configure_hba(ha);
1896 if (rval != QLA_SUCCESS) {
1897 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1903 save_flags = flags = ha->dpc_flags;
1904 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1905 ha->host_no, flags));
1908 * If we have both an RSCN and PORT UPDATE pending then handle them
1909 * both at the same time.
1911 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1912 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1914 /* Determine what we need to do */
1915 if (ha->current_topology == ISP_CFG_FL &&
1916 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1918 ha->flags.rscn_queue_overflow = 1;
1919 set_bit(RSCN_UPDATE, &flags);
1921 } else if (ha->current_topology == ISP_CFG_F &&
1922 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1924 ha->flags.rscn_queue_overflow = 1;
1925 set_bit(RSCN_UPDATE, &flags);
1926 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1928 } else if (ha->current_topology == ISP_CFG_N) {
1929 clear_bit(RSCN_UPDATE, &flags);
1931 } else if (!ha->flags.online ||
1932 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1934 ha->flags.rscn_queue_overflow = 1;
1935 set_bit(RSCN_UPDATE, &flags);
1936 set_bit(LOCAL_LOOP_UPDATE, &flags);
1939 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1940 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1941 rval = QLA_FUNCTION_FAILED;
1943 rval = qla2x00_configure_local_loop(ha);
1947 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1948 if (LOOP_TRANSITION(ha)) {
1949 rval = QLA_FUNCTION_FAILED;
1951 rval = qla2x00_configure_fabric(ha);
1955 if (rval == QLA_SUCCESS) {
1956 if (atomic_read(&ha->loop_down_timer) ||
1957 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1958 rval = QLA_FUNCTION_FAILED;
1960 atomic_set(&ha->loop_state, LOOP_READY);
1962 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1967 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1968 __func__, ha->host_no));
1970 DEBUG3(printk("%s: exiting normally\n", __func__));
1973 /* Restore state if a resync event occured during processing */
1974 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1975 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1976 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1977 if (test_bit(RSCN_UPDATE, &save_flags))
1978 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1987 * qla2x00_configure_local_loop
1988 * Updates Fibre Channel Device Database with local loop devices.
1991 * ha = adapter block pointer.
1997 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
2002 fc_port_t *fcport, *new_fcport;
2008 uint8_t domain, area, al_pa;
2009 scsi_qla_host_t *pha = to_qla_parent(ha);
2013 entries = MAX_FIBRE_DEVICES;
2015 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
2016 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
2018 /* Get list of logged in devices. */
2019 memset(ha->gid_list, 0, GID_LIST_SIZE);
2020 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
2022 if (rval != QLA_SUCCESS)
2023 goto cleanup_allocation;
2025 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2026 ha->host_no, entries));
2027 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2028 entries * sizeof(struct gid_list_info)));
2030 /* Allocate temporary fcport for any new fcports discovered. */
2031 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2032 if (new_fcport == NULL) {
2033 rval = QLA_MEMORY_ALLOC_FAILED;
2034 goto cleanup_allocation;
2036 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2039 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2041 list_for_each_entry(fcport, &pha->fcports, list) {
2042 if (fcport->vp_idx != ha->vp_idx)
2045 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2046 fcport->port_type != FCT_BROADCAST &&
2047 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2049 DEBUG(printk("scsi(%ld): Marking port lost, "
2051 ha->host_no, fcport->loop_id));
2053 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2054 fcport->flags &= ~FCF_FARP_DONE;
2058 /* Add devices to port list. */
2059 id_iter = (char *)ha->gid_list;
2060 for (index = 0; index < entries; index++) {
2061 domain = ((struct gid_list_info *)id_iter)->domain;
2062 area = ((struct gid_list_info *)id_iter)->area;
2063 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
2064 if (IS_QLA2100(ha) || IS_QLA2200(ha))
2065 loop_id = (uint16_t)
2066 ((struct gid_list_info *)id_iter)->loop_id_2100;
2068 loop_id = le16_to_cpu(
2069 ((struct gid_list_info *)id_iter)->loop_id);
2070 id_iter += ha->gid_list_info_size;
2072 /* Bypass reserved domain fields. */
2073 if ((domain & 0xf0) == 0xf0)
2076 /* Bypass if not same domain and area of adapter. */
2077 if (area && domain &&
2078 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
2081 /* Bypass invalid local loop ID. */
2082 if (loop_id > LAST_LOCAL_LOOP_ID)
2085 /* Fill in member data. */
2086 new_fcport->d_id.b.domain = domain;
2087 new_fcport->d_id.b.area = area;
2088 new_fcport->d_id.b.al_pa = al_pa;
2089 new_fcport->loop_id = loop_id;
2090 new_fcport->vp_idx = ha->vp_idx;
2091 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
2092 if (rval2 != QLA_SUCCESS) {
2093 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2094 "information -- get_port_database=%x, "
2096 ha->host_no, rval2, new_fcport->loop_id));
2097 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2099 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2103 /* Check for matching device in port list. */
2106 list_for_each_entry(fcport, &pha->fcports, list) {
2107 if (fcport->vp_idx != ha->vp_idx)
2110 if (memcmp(new_fcport->port_name, fcport->port_name,
2114 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2115 FCF_PERSISTENT_BOUND);
2116 fcport->loop_id = new_fcport->loop_id;
2117 fcport->port_type = new_fcport->port_type;
2118 fcport->d_id.b24 = new_fcport->d_id.b24;
2119 memcpy(fcport->node_name, new_fcport->node_name,
2127 /* New device, add to fcports list. */
2128 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
2130 new_fcport->ha = ha;
2131 new_fcport->vp_idx = ha->vp_idx;
2132 list_add_tail(&new_fcport->vp_fcport,
2135 list_add_tail(&new_fcport->list, &pha->fcports);
2137 /* Allocate a new replacement fcport. */
2138 fcport = new_fcport;
2139 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2140 if (new_fcport == NULL) {
2141 rval = QLA_MEMORY_ALLOC_FAILED;
2142 goto cleanup_allocation;
2144 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2147 /* Base iIDMA settings on HBA port speed. */
2148 fcport->fp_speed = ha->link_data_rate;
2150 qla2x00_update_fcport(ha, fcport);
2158 if (rval != QLA_SUCCESS) {
2159 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2160 "rval=%x\n", ha->host_no, rval));
2164 ha->device_flags |= DFLG_LOCAL_DEVICES;
2165 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2172 qla2x00_iidma_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2174 #define LS_UNKNOWN 2
2175 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
2179 if (!IS_IIDMA_CAPABLE(ha))
2182 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2183 fcport->fp_speed > ha->link_data_rate)
2186 rval = qla2x00_set_idma_speed(ha, fcport->loop_id, fcport->fp_speed,
2188 if (rval != QLA_SUCCESS) {
2189 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2190 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2191 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2192 fcport->port_name[2], fcport->port_name[3],
2193 fcport->port_name[4], fcport->port_name[5],
2194 fcport->port_name[6], fcport->port_name[7], rval,
2195 fcport->fp_speed, mb[0], mb[1]));
2197 DEBUG2(qla_printk(KERN_INFO, ha,
2198 "iIDMA adjusted to %s GB/s on "
2199 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2200 link_speeds[fcport->fp_speed], fcport->port_name[0],
2201 fcport->port_name[1], fcport->port_name[2],
2202 fcport->port_name[3], fcport->port_name[4],
2203 fcport->port_name[5], fcport->port_name[6],
2204 fcport->port_name[7]));
2209 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2211 struct fc_rport_identifiers rport_ids;
2212 struct fc_rport *rport;
2213 unsigned long flags;
2216 qla2x00_rport_del(fcport);
2220 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2221 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2222 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2223 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2224 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2225 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2227 qla_printk(KERN_WARNING, ha,
2228 "Unable to allocate fc remote port!\n");
2231 spin_lock_irqsave(&fcport->rport_lock, flags);
2232 fcport->rport = rport;
2233 *((fc_port_t **)rport->dd_data) = fcport;
2234 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2236 rport->supported_classes = fcport->supported_classes;
2238 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2239 if (fcport->port_type == FCT_INITIATOR)
2240 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2241 if (fcport->port_type == FCT_TARGET)
2242 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2243 fc_remote_port_rolechg(rport, rport_ids.roles);
2247 * qla2x00_update_fcport
2248 * Updates device on list.
2251 * ha = adapter block pointer.
2252 * fcport = port structure pointer.
2262 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2264 scsi_qla_host_t *pha = to_qla_parent(ha);
2267 fcport->login_retry = 0;
2268 fcport->port_login_retry_count = pha->port_down_retry_count *
2270 atomic_set(&fcport->port_down_timer, pha->port_down_retry_count *
2272 fcport->flags &= ~FCF_LOGIN_NEEDED;
2274 qla2x00_iidma_fcport(ha, fcport);
2276 atomic_set(&fcport->state, FCS_ONLINE);
2278 qla2x00_reg_remote_port(ha, fcport);
2282 * qla2x00_configure_fabric
2283 * Setup SNS devices with loop ID's.
2286 * ha = adapter block pointer.
2293 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2296 fc_port_t *fcport, *fcptemp;
2297 uint16_t next_loopid;
2298 uint16_t mb[MAILBOX_REGISTER_COUNT];
2300 LIST_HEAD(new_fcports);
2301 scsi_qla_host_t *pha = to_qla_parent(ha);
2303 /* If FL port exists, then SNS is present */
2304 if (IS_FWI2_CAPABLE(ha))
2305 loop_id = NPH_F_PORT;
2307 loop_id = SNS_FL_PORT;
2308 rval = qla2x00_get_port_name(ha, loop_id, ha->fabric_node_name, 1);
2309 if (rval != QLA_SUCCESS) {
2310 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2311 "Port\n", ha->host_no));
2313 ha->device_flags &= ~SWITCH_FOUND;
2314 return (QLA_SUCCESS);
2316 ha->device_flags |= SWITCH_FOUND;
2318 /* Mark devices that need re-synchronization. */
2319 rval2 = qla2x00_device_resync(ha);
2320 if (rval2 == QLA_RSCNS_HANDLED) {
2321 /* No point doing the scan, just continue. */
2322 return (QLA_SUCCESS);
2326 if (ql2xfdmienable &&
2327 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2328 qla2x00_fdmi_register(ha);
2330 /* Ensure we are logged into the SNS. */
2331 if (IS_FWI2_CAPABLE(ha))
2334 loop_id = SIMPLE_NAME_SERVER;
2335 ha->isp_ops->fabric_login(ha, loop_id, 0xff, 0xff,
2336 0xfc, mb, BIT_1 | BIT_0);
2337 if (mb[0] != MBS_COMMAND_COMPLETE) {
2338 DEBUG2(qla_printk(KERN_INFO, ha,
2339 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2340 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2341 mb[0], mb[1], mb[2], mb[6], mb[7]));
2342 return (QLA_SUCCESS);
2345 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2346 if (qla2x00_rft_id(ha)) {
2348 DEBUG2(printk("scsi(%ld): Register FC-4 "
2349 "TYPE failed.\n", ha->host_no));
2351 if (qla2x00_rff_id(ha)) {
2353 DEBUG2(printk("scsi(%ld): Register FC-4 "
2354 "Features failed.\n", ha->host_no));
2356 if (qla2x00_rnn_id(ha)) {
2358 DEBUG2(printk("scsi(%ld): Register Node Name "
2359 "failed.\n", ha->host_no));
2360 } else if (qla2x00_rsnn_nn(ha)) {
2362 DEBUG2(printk("scsi(%ld): Register Symbolic "
2363 "Node Name failed.\n", ha->host_no));
2367 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2368 if (rval != QLA_SUCCESS)
2372 * Logout all previous fabric devices marked lost, except
2375 list_for_each_entry(fcport, &pha->fcports, list) {
2376 if (fcport->vp_idx !=ha->vp_idx)
2379 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2382 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2385 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2386 qla2x00_mark_device_lost(ha, fcport,
2387 ql2xplogiabsentdevice, 0);
2388 if (fcport->loop_id != FC_NO_LOOP_ID &&
2389 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2390 fcport->port_type != FCT_INITIATOR &&
2391 fcport->port_type != FCT_BROADCAST) {
2392 ha->isp_ops->fabric_logout(ha,
2394 fcport->d_id.b.domain,
2395 fcport->d_id.b.area,
2396 fcport->d_id.b.al_pa);
2397 fcport->loop_id = FC_NO_LOOP_ID;
2402 /* Starting free loop ID. */
2403 next_loopid = pha->min_external_loopid;
2406 * Scan through our port list and login entries that need to be
2409 list_for_each_entry(fcport, &pha->fcports, list) {
2410 if (fcport->vp_idx != ha->vp_idx)
2413 if (atomic_read(&ha->loop_down_timer) ||
2414 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2417 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2418 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2421 if (fcport->loop_id == FC_NO_LOOP_ID) {
2422 fcport->loop_id = next_loopid;
2423 rval = qla2x00_find_new_loop_id(ha, fcport);
2424 if (rval != QLA_SUCCESS) {
2425 /* Ran out of IDs to use */
2429 /* Login and update database */
2430 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2433 /* Exit if out of loop IDs. */
2434 if (rval != QLA_SUCCESS) {
2439 * Login and add the new devices to our port list.
2441 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2442 if (atomic_read(&ha->loop_down_timer) ||
2443 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2446 /* Find a new loop ID to use. */
2447 fcport->loop_id = next_loopid;
2448 rval = qla2x00_find_new_loop_id(ha, fcport);
2449 if (rval != QLA_SUCCESS) {
2450 /* Ran out of IDs to use */
2454 /* Login and update database */
2455 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2459 fcport->vp_idx = ha->vp_idx;
2460 list_add_tail(&fcport->vp_fcport,
2462 list_move_tail(&fcport->list,
2463 &ha->parent->fcports);
2465 list_move_tail(&fcport->list, &ha->fcports);
2469 /* Free all new device structures not processed. */
2470 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2471 list_del(&fcport->list);
2476 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2477 "rval=%d\n", ha->host_no, rval));
2485 * qla2x00_find_all_fabric_devs
2488 * ha = adapter block pointer.
2489 * dev = database device entry pointer.
2498 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2502 fc_port_t *fcport, *new_fcport, *fcptemp;
2507 int first_dev, last_dev;
2508 port_id_t wrap, nxt_d_id;
2512 scsi_qla_host_t *vha;
2513 scsi_qla_host_t *pha = to_qla_parent(ha);
2517 /* Try GID_PT to get device list, else GAN. */
2518 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_ATOMIC);
2521 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2522 "on GA_NXT\n", ha->host_no));
2524 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2527 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2530 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2533 } else if (qla2x00_gfpn_id(ha, swl) == QLA_SUCCESS) {
2534 qla2x00_gpsc(ha, swl);
2539 /* Allocate temporary fcport for any new fcports discovered. */
2540 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2541 if (new_fcport == NULL) {
2543 return (QLA_MEMORY_ALLOC_FAILED);
2545 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2546 new_fcport->vp_idx = ha->vp_idx;
2547 /* Set start port ID scan at adapter ID. */
2551 /* Starting free loop ID. */
2552 loop_id = pha->min_external_loopid;
2553 for (; loop_id <= ha->last_loop_id; loop_id++) {
2554 if (qla2x00_is_reserved_id(ha, loop_id))
2557 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2562 wrap.b24 = new_fcport->d_id.b24;
2564 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2565 memcpy(new_fcport->node_name,
2566 swl[swl_idx].node_name, WWN_SIZE);
2567 memcpy(new_fcport->port_name,
2568 swl[swl_idx].port_name, WWN_SIZE);
2569 memcpy(new_fcport->fabric_port_name,
2570 swl[swl_idx].fabric_port_name, WWN_SIZE);
2571 new_fcport->fp_speed = swl[swl_idx].fp_speed;
2573 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2579 /* Send GA_NXT to the switch */
2580 rval = qla2x00_ga_nxt(ha, new_fcport);
2581 if (rval != QLA_SUCCESS) {
2582 qla_printk(KERN_WARNING, ha,
2583 "SNS scan failed -- assuming zero-entry "
2585 list_for_each_entry_safe(fcport, fcptemp,
2586 new_fcports, list) {
2587 list_del(&fcport->list);
2595 /* If wrap on switch device list, exit. */
2597 wrap.b24 = new_fcport->d_id.b24;
2599 } else if (new_fcport->d_id.b24 == wrap.b24) {
2600 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2601 ha->host_no, new_fcport->d_id.b.domain,
2602 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2606 /* Bypass if same physical adapter. */
2607 if (new_fcport->d_id.b24 == pha->d_id.b24)
2610 /* Bypass virtual ports of the same host. */
2611 if (pha->num_vhosts) {
2612 for_each_mapped_vp_idx(pha, vp_index) {
2615 list_for_each_entry(vha, &pha->vp_list,
2617 if (vp_index == vha->vp_idx) {
2628 new_fcport->d_id.b24 == vha->d_id.b24)
2632 if (vp_index <= pha->max_npiv_vports)
2636 /* Bypass if same domain and area of adapter. */
2637 if (((new_fcport->d_id.b24 & 0xffff00) ==
2638 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2642 /* Bypass reserved domain fields. */
2643 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2646 /* Locate matching device in database. */
2648 list_for_each_entry(fcport, &pha->fcports, list) {
2649 if (new_fcport->vp_idx != fcport->vp_idx)
2651 if (memcmp(new_fcport->port_name, fcport->port_name,
2657 /* Update port state. */
2658 memcpy(fcport->fabric_port_name,
2659 new_fcport->fabric_port_name, WWN_SIZE);
2660 fcport->fp_speed = new_fcport->fp_speed;
2663 * If address the same and state FCS_ONLINE, nothing
2666 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2667 atomic_read(&fcport->state) == FCS_ONLINE) {
2672 * If device was not a fabric device before.
2674 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2675 fcport->d_id.b24 = new_fcport->d_id.b24;
2676 fcport->loop_id = FC_NO_LOOP_ID;
2677 fcport->flags |= (FCF_FABRIC_DEVICE |
2679 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2684 * Port ID changed or device was marked to be updated;
2685 * Log it out if still logged in and mark it for
2688 fcport->d_id.b24 = new_fcport->d_id.b24;
2689 fcport->flags |= FCF_LOGIN_NEEDED;
2690 if (fcport->loop_id != FC_NO_LOOP_ID &&
2691 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2692 fcport->port_type != FCT_INITIATOR &&
2693 fcport->port_type != FCT_BROADCAST) {
2694 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
2695 fcport->d_id.b.domain, fcport->d_id.b.area,
2696 fcport->d_id.b.al_pa);
2697 fcport->loop_id = FC_NO_LOOP_ID;
2706 /* If device was not in our fcports list, then add it. */
2707 list_add_tail(&new_fcport->list, new_fcports);
2709 /* Allocate a new replacement fcport. */
2710 nxt_d_id.b24 = new_fcport->d_id.b24;
2711 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2712 if (new_fcport == NULL) {
2714 return (QLA_MEMORY_ALLOC_FAILED);
2716 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2717 new_fcport->d_id.b24 = nxt_d_id.b24;
2718 new_fcport->vp_idx = ha->vp_idx;
2724 if (!list_empty(new_fcports))
2725 ha->device_flags |= DFLG_FABRIC_DEVICES;
2731 * qla2x00_find_new_loop_id
2732 * Scan through our port list and find a new usable loop ID.
2735 * ha: adapter state pointer.
2736 * dev: port structure pointer.
2739 * qla2x00 local function return status code.
2745 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2750 uint16_t first_loop_id;
2751 scsi_qla_host_t *pha = to_qla_parent(ha);
2755 /* Save starting loop ID. */
2756 first_loop_id = dev->loop_id;
2759 /* Skip loop ID if already used by adapter. */
2760 if (dev->loop_id == ha->loop_id) {
2764 /* Skip reserved loop IDs. */
2765 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2769 /* Reset loop ID if passed the end. */
2770 if (dev->loop_id > ha->last_loop_id) {
2771 /* first loop ID. */
2772 dev->loop_id = ha->min_external_loopid;
2775 /* Check for loop ID being already in use. */
2778 list_for_each_entry(fcport, &pha->fcports, list) {
2779 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2780 /* ID possibly in use */
2786 /* If not in use then it is free to use. */
2791 /* ID in use. Try next value. */
2794 /* If wrap around. No free ID to use. */
2795 if (dev->loop_id == first_loop_id) {
2796 dev->loop_id = FC_NO_LOOP_ID;
2797 rval = QLA_FUNCTION_FAILED;
2806 * qla2x00_device_resync
2807 * Marks devices in the database that needs resynchronization.
2810 * ha = adapter block pointer.
2816 qla2x00_device_resync(scsi_qla_host_t *ha)
2821 uint32_t rscn_entry;
2822 uint8_t rscn_out_iter;
2825 scsi_qla_host_t *pha = to_qla_parent(ha);
2827 rval = QLA_RSCNS_HANDLED;
2829 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2830 ha->flags.rscn_queue_overflow) {
2832 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2833 format = MSB(MSW(rscn_entry));
2834 d_id.b.domain = LSB(MSW(rscn_entry));
2835 d_id.b.area = MSB(LSW(rscn_entry));
2836 d_id.b.al_pa = LSB(LSW(rscn_entry));
2838 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2839 "[%02x/%02x%02x%02x].\n",
2840 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2841 d_id.b.area, d_id.b.al_pa));
2844 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2845 ha->rscn_out_ptr = 0;
2847 /* Skip duplicate entries. */
2848 for (rscn_out_iter = ha->rscn_out_ptr;
2849 !ha->flags.rscn_queue_overflow &&
2850 rscn_out_iter != ha->rscn_in_ptr;
2851 rscn_out_iter = (rscn_out_iter ==
2852 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2854 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2857 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2858 "entry found at [%d].\n", ha->host_no,
2861 ha->rscn_out_ptr = rscn_out_iter;
2864 /* Queue overflow, set switch default case. */
2865 if (ha->flags.rscn_queue_overflow) {
2866 DEBUG(printk("scsi(%ld): device_resync: rscn "
2867 "overflow.\n", ha->host_no));
2870 ha->flags.rscn_queue_overflow = 0;
2886 ha->rscn_out_ptr = ha->rscn_in_ptr;
2892 list_for_each_entry(fcport, &pha->fcports, list) {
2893 if (fcport->vp_idx != ha->vp_idx)
2896 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2897 (fcport->d_id.b24 & mask) != d_id.b24 ||
2898 fcport->port_type == FCT_BROADCAST)
2901 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2903 fcport->port_type != FCT_INITIATOR) {
2904 qla2x00_mark_device_lost(ha, fcport,
2908 fcport->flags &= ~FCF_FARP_DONE;
2915 * qla2x00_fabric_dev_login
2916 * Login fabric target device and update FC port database.
2919 * ha: adapter state pointer.
2920 * fcport: port structure list pointer.
2921 * next_loopid: contains value of a new loop ID that can be used
2922 * by the next login attempt.
2925 * qla2x00 local function return status code.
2931 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2932 uint16_t *next_loopid)
2941 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2942 if (rval == QLA_SUCCESS) {
2943 /* Send an ADISC to tape devices.*/
2945 if (fcport->flags & FCF_TAPE_PRESENT)
2947 rval = qla2x00_get_port_database(ha, fcport, opts);
2948 if (rval != QLA_SUCCESS) {
2949 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
2950 fcport->d_id.b.domain, fcport->d_id.b.area,
2951 fcport->d_id.b.al_pa);
2952 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2954 qla2x00_update_fcport(ha, fcport);
2962 * qla2x00_fabric_login
2963 * Issue fabric login command.
2966 * ha = adapter block pointer.
2967 * device = pointer to FC device type structure.
2970 * 0 - Login successfully
2972 * 2 - Initiator device
2976 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2977 uint16_t *next_loopid)
2981 uint16_t tmp_loopid;
2982 uint16_t mb[MAILBOX_REGISTER_COUNT];
2988 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2989 "for port %02x%02x%02x.\n",
2990 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2991 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2993 /* Login fcport on switch. */
2994 ha->isp_ops->fabric_login(ha, fcport->loop_id,
2995 fcport->d_id.b.domain, fcport->d_id.b.area,
2996 fcport->d_id.b.al_pa, mb, BIT_0);
2997 if (mb[0] == MBS_PORT_ID_USED) {
2999 * Device has another loop ID. The firmware team
3000 * recommends the driver perform an implicit login with
3001 * the specified ID again. The ID we just used is save
3002 * here so we return with an ID that can be tried by
3006 tmp_loopid = fcport->loop_id;
3007 fcport->loop_id = mb[1];
3009 DEBUG(printk("Fabric Login: port in use - next "
3010 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3011 fcport->loop_id, fcport->d_id.b.domain,
3012 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3014 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3019 /* A retry occurred before. */
3020 *next_loopid = tmp_loopid;
3023 * No retry occurred before. Just increment the
3024 * ID value for next login.
3026 *next_loopid = (fcport->loop_id + 1);
3029 if (mb[1] & BIT_0) {
3030 fcport->port_type = FCT_INITIATOR;
3032 fcport->port_type = FCT_TARGET;
3033 if (mb[1] & BIT_1) {
3034 fcport->flags |= FCF_TAPE_PRESENT;
3039 fcport->supported_classes |= FC_COS_CLASS2;
3041 fcport->supported_classes |= FC_COS_CLASS3;
3045 } else if (mb[0] == MBS_LOOP_ID_USED) {
3047 * Loop ID already used, try next loop ID.
3050 rval = qla2x00_find_new_loop_id(ha, fcport);
3051 if (rval != QLA_SUCCESS) {
3052 /* Ran out of loop IDs to use */
3055 } else if (mb[0] == MBS_COMMAND_ERROR) {
3057 * Firmware possibly timed out during login. If NO
3058 * retries are left to do then the device is declared
3061 *next_loopid = fcport->loop_id;
3062 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
3063 fcport->d_id.b.domain, fcport->d_id.b.area,
3064 fcport->d_id.b.al_pa);
3065 qla2x00_mark_device_lost(ha, fcport, 1, 0);
3071 * unrecoverable / not handled error
3073 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3074 "loop_id=%x jiffies=%lx.\n",
3075 __func__, ha->host_no, mb[0],
3076 fcport->d_id.b.domain, fcport->d_id.b.area,
3077 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3079 *next_loopid = fcport->loop_id;
3080 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
3081 fcport->d_id.b.domain, fcport->d_id.b.area,
3082 fcport->d_id.b.al_pa);
3083 fcport->loop_id = FC_NO_LOOP_ID;
3084 fcport->login_retry = 0;
3095 * qla2x00_local_device_login
3096 * Issue local device login command.
3099 * ha = adapter block pointer.
3100 * loop_id = loop id of device to login to.
3102 * Returns (Where's the #define!!!!):
3103 * 0 - Login successfully
3108 qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
3111 uint16_t mb[MAILBOX_REGISTER_COUNT];
3113 memset(mb, 0, sizeof(mb));
3114 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
3115 if (rval == QLA_SUCCESS) {
3116 /* Interrogate mailbox registers for any errors */
3117 if (mb[0] == MBS_COMMAND_ERROR)
3119 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3120 /* device not in PCB table */
3128 * qla2x00_loop_resync
3129 * Resync with fibre channel devices.
3132 * ha = adapter block pointer.
3138 qla2x00_loop_resync(scsi_qla_host_t *ha)
3145 atomic_set(&ha->loop_state, LOOP_UPDATE);
3146 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3147 if (ha->flags.online) {
3148 if (!(rval = qla2x00_fw_ready(ha))) {
3149 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3152 atomic_set(&ha->loop_state, LOOP_UPDATE);
3154 /* Issue a marker after FW becomes ready. */
3155 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3156 ha->marker_needed = 0;
3158 /* Remap devices on Loop. */
3159 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3161 qla2x00_configure_loop(ha);
3163 } while (!atomic_read(&ha->loop_down_timer) &&
3164 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3166 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3170 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3171 return (QLA_FUNCTION_FAILED);
3175 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3182 qla2x00_update_fcports(scsi_qla_host_t *ha)
3186 /* Go with deferred removal of rport references. */
3187 list_for_each_entry(fcport, &ha->fcports, list)
3189 qla2x00_rport_del(fcport);
3194 * Resets ISP and aborts all outstanding commands.
3197 * ha = adapter block pointer.
3203 qla2x00_abort_isp(scsi_qla_host_t *ha)
3208 if (ha->flags.online) {
3209 ha->flags.online = 0;
3210 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3212 qla_printk(KERN_INFO, ha,
3213 "Performing ISP error recovery - ha= %p.\n", ha);
3214 ha->isp_ops->reset_chip(ha);
3216 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3217 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3218 atomic_set(&ha->loop_state, LOOP_DOWN);
3219 qla2x00_mark_all_devices_lost(ha, 0);
3221 if (!atomic_read(&ha->loop_down_timer))
3222 atomic_set(&ha->loop_down_timer,
3226 /* Requeue all commands in outstanding command list. */
3227 qla2x00_abort_all_cmds(ha, DID_RESET << 16);
3229 ha->isp_ops->get_flash_version(ha, ha->request_ring);
3231 ha->isp_ops->nvram_config(ha);
3233 if (!qla2x00_restart_isp(ha)) {
3234 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3236 if (!atomic_read(&ha->loop_down_timer)) {
3238 * Issue marker command only when we are going
3239 * to start the I/O .
3241 ha->marker_needed = 1;
3244 ha->flags.online = 1;
3246 ha->isp_ops->enable_intrs(ha);
3248 ha->isp_abort_cnt = 0;
3249 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3252 memset(ha->eft, 0, EFT_SIZE);
3253 rval = qla2x00_enable_eft_trace(ha,
3254 ha->eft_dma, EFT_NUM_BUFFERS);
3256 qla_printk(KERN_WARNING, ha,
3257 "Unable to reinitialize EFT "
3263 ha->flags.fce_enabled = 1;
3265 fce_calc_size(ha->fce_bufs));
3266 rval = qla2x00_enable_fce_trace(ha,
3267 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3270 qla_printk(KERN_WARNING, ha,
3271 "Unable to reinitialize FCE "
3273 ha->flags.fce_enabled = 0;
3276 } else { /* failed the ISP abort */
3277 ha->flags.online = 1;
3278 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3279 if (ha->isp_abort_cnt == 0) {
3280 qla_printk(KERN_WARNING, ha,
3281 "ISP error recovery failed - "
3282 "board disabled\n");
3284 * The next call disables the board
3287 ha->isp_ops->reset_adapter(ha);
3288 ha->flags.online = 0;
3289 clear_bit(ISP_ABORT_RETRY,
3292 } else { /* schedule another ISP abort */
3293 ha->isp_abort_cnt--;
3294 DEBUG(printk("qla%ld: ISP abort - "
3295 "retry remaining %d\n",
3296 ha->host_no, ha->isp_abort_cnt));
3300 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3301 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3302 "- retrying (%d) more times\n",
3303 ha->host_no, ha->isp_abort_cnt));
3304 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3312 qla_printk(KERN_INFO, ha,
3313 "qla2x00_abort_isp: **** FAILED ****\n");
3315 DEBUG(printk(KERN_INFO
3316 "qla2x00_abort_isp(%ld): exiting.\n",
3324 * qla2x00_restart_isp
3325 * restarts the ISP after a reset
3328 * ha = adapter block pointer.
3334 qla2x00_restart_isp(scsi_qla_host_t *ha)
3339 /* If firmware needs to be loaded */
3340 if (qla2x00_isp_firmware(ha)) {
3341 ha->flags.online = 0;
3342 if (!(status = ha->isp_ops->chip_diag(ha)))
3343 status = qla2x00_setup_chip(ha);
3346 if (!status && !(status = qla2x00_init_rings(ha))) {
3347 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3348 if (!(status = qla2x00_fw_ready(ha))) {
3349 DEBUG(printk("%s(): Start configure loop, "
3350 "status = %d\n", __func__, status));
3352 /* Issue a marker after FW becomes ready. */
3353 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3355 ha->flags.online = 1;
3356 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3359 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3360 qla2x00_configure_loop(ha);
3362 } while (!atomic_read(&ha->loop_down_timer) &&
3363 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3365 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3368 /* if no cable then assume it's good */
3369 if ((ha->device_flags & DFLG_NO_CABLE))
3372 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3380 * qla2x00_reset_adapter
3384 * ha = adapter block pointer.
3387 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3389 unsigned long flags = 0;
3390 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3392 ha->flags.online = 0;
3393 ha->isp_ops->disable_intrs(ha);
3395 spin_lock_irqsave(&ha->hardware_lock, flags);
3396 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3397 RD_REG_WORD(®->hccr); /* PCI Posting. */
3398 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3399 RD_REG_WORD(®->hccr); /* PCI Posting. */
3400 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3404 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3406 unsigned long flags = 0;
3407 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3409 ha->flags.online = 0;
3410 ha->isp_ops->disable_intrs(ha);
3412 spin_lock_irqsave(&ha->hardware_lock, flags);
3413 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3414 RD_REG_DWORD(®->hccr);
3415 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3416 RD_REG_DWORD(®->hccr);
3417 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3420 /* On sparc systems, obtain port and node WWN from firmware
3423 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, struct nvram_24xx *nv)
3426 struct pci_dev *pdev = ha->pdev;
3427 struct device_node *dp = pci_device_to_OF_node(pdev);
3431 val = of_get_property(dp, "port-wwn", &len);
3432 if (val && len >= WWN_SIZE)
3433 memcpy(nv->port_name, val, WWN_SIZE);
3435 val = of_get_property(dp, "node-wwn", &len);
3436 if (val && len >= WWN_SIZE)
3437 memcpy(nv->node_name, val, WWN_SIZE);
3442 qla24xx_nvram_config(scsi_qla_host_t *ha)
3445 struct init_cb_24xx *icb;
3446 struct nvram_24xx *nv;
3448 uint8_t *dptr1, *dptr2;
3453 icb = (struct init_cb_24xx *)ha->init_cb;
3456 /* Determine NVRAM starting address. */
3457 ha->nvram_size = sizeof(struct nvram_24xx);
3458 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3459 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3460 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3461 if (PCI_FUNC(ha->pdev->devfn)) {
3462 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3463 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3466 /* Get VPD data into cache */
3467 ha->vpd = ha->nvram + VPD_OFFSET;
3468 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd,
3469 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3471 /* Get NVRAM data into cache and calculate checksum. */
3472 dptr = (uint32_t *)nv;
3473 ha->isp_ops->read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3475 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3476 chksum += le32_to_cpu(*dptr++);
3478 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3479 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
3481 /* Bad NVRAM data, set defaults parameters. */
3482 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3483 || nv->id[3] != ' ' ||
3484 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3485 /* Reset NVRAM data. */
3486 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3487 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3488 le16_to_cpu(nv->nvram_version));
3489 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3490 "invalid -- WWPN) defaults.\n");
3493 * Set default initialization control block.
3495 memset(nv, 0, ha->nvram_size);
3496 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3497 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3498 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3499 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3500 nv->exchange_count = __constant_cpu_to_le16(0);
3501 nv->hard_address = __constant_cpu_to_le16(124);
3502 nv->port_name[0] = 0x21;
3503 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3504 nv->port_name[2] = 0x00;
3505 nv->port_name[3] = 0xe0;
3506 nv->port_name[4] = 0x8b;
3507 nv->port_name[5] = 0x1c;
3508 nv->port_name[6] = 0x55;
3509 nv->port_name[7] = 0x86;
3510 nv->node_name[0] = 0x20;
3511 nv->node_name[1] = 0x00;
3512 nv->node_name[2] = 0x00;
3513 nv->node_name[3] = 0xe0;
3514 nv->node_name[4] = 0x8b;
3515 nv->node_name[5] = 0x1c;
3516 nv->node_name[6] = 0x55;
3517 nv->node_name[7] = 0x86;
3518 qla24xx_nvram_wwn_from_ofw(ha, nv);
3519 nv->login_retry_count = __constant_cpu_to_le16(8);
3520 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3521 nv->login_timeout = __constant_cpu_to_le16(0);
3522 nv->firmware_options_1 =
3523 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3524 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3525 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3526 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3527 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3528 nv->efi_parameters = __constant_cpu_to_le32(0);
3529 nv->reset_delay = 5;
3530 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3531 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3532 nv->link_down_timeout = __constant_cpu_to_le16(30);
3537 /* Reset Initialization control block */
3538 memset(icb, 0, sizeof(struct init_cb_24xx));
3540 /* Copy 1st segment. */
3541 dptr1 = (uint8_t *)icb;
3542 dptr2 = (uint8_t *)&nv->version;
3543 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3545 *dptr1++ = *dptr2++;
3547 icb->login_retry_count = nv->login_retry_count;
3548 icb->link_down_on_nos = nv->link_down_on_nos;
3550 /* Copy 2nd segment. */
3551 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3552 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3553 cnt = (uint8_t *)&icb->reserved_3 -
3554 (uint8_t *)&icb->interrupt_delay_timer;
3556 *dptr1++ = *dptr2++;
3559 * Setup driver NVRAM options.
3561 qla2x00_set_model_info(ha, nv->model_name, sizeof(nv->model_name),
3564 /* Use alternate WWN? */
3565 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3566 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3567 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3570 /* Prepare nodename */
3571 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3573 * Firmware will apply the following mask if the nodename was
3576 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3577 icb->node_name[0] &= 0xF0;
3580 /* Set host adapter parameters. */
3581 ha->flags.disable_risc_code_load = 0;
3582 ha->flags.enable_lip_reset = 0;
3583 ha->flags.enable_lip_full_login =
3584 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3585 ha->flags.enable_target_reset =
3586 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
3587 ha->flags.enable_led_scheme = 0;
3588 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
3590 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3591 (BIT_6 | BIT_5 | BIT_4)) >> 4;
3593 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3594 sizeof(ha->fw_seriallink_options24));
3596 /* save HBA serial number */
3597 ha->serial0 = icb->port_name[5];
3598 ha->serial1 = icb->port_name[6];
3599 ha->serial2 = icb->port_name[7];
3600 ha->node_name = icb->node_name;
3601 ha->port_name = icb->port_name;
3603 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3605 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3607 /* Set minimum login_timeout to 4 seconds. */
3608 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3609 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3610 if (le16_to_cpu(nv->login_timeout) < 4)
3611 nv->login_timeout = __constant_cpu_to_le16(4);
3612 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3613 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3615 /* Set minimum RATOV to 100 tenths of a second. */
3618 ha->loop_reset_delay = nv->reset_delay;
3620 /* Link Down Timeout = 0:
3622 * When Port Down timer expires we will start returning
3623 * I/O's to OS with "DID_NO_CONNECT".
3625 * Link Down Timeout != 0:
3627 * The driver waits for the link to come up after link down
3628 * before returning I/Os to OS with "DID_NO_CONNECT".
3630 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3631 ha->loop_down_abort_time =
3632 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3634 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3635 ha->loop_down_abort_time =
3636 (LOOP_DOWN_TIME - ha->link_down_timeout);
3639 /* Need enough time to try and get the port back. */
3640 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3641 if (qlport_down_retry)
3642 ha->port_down_retry_count = qlport_down_retry;
3644 /* Set login_retry_count */
3645 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3646 if (ha->port_down_retry_count ==
3647 le16_to_cpu(nv->port_down_retry_count) &&
3648 ha->port_down_retry_count > 3)
3649 ha->login_retry_count = ha->port_down_retry_count;
3650 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3651 ha->login_retry_count = ha->port_down_retry_count;
3652 if (ql2xloginretrycount)
3653 ha->login_retry_count = ql2xloginretrycount;
3656 if (!ha->flags.init_done) {
3657 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3658 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3659 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3660 le16_to_cpu(icb->interrupt_delay_timer): 2;
3662 icb->firmware_options_2 &= __constant_cpu_to_le32(
3663 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3664 ha->flags.process_response_queue = 0;
3665 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3666 ha->zio_mode = QLA_ZIO_MODE_6;
3668 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3669 "(%d us).\n", ha->host_no, ha->zio_mode,
3670 ha->zio_timer * 100));
3671 qla_printk(KERN_INFO, ha,
3672 "ZIO mode %d enabled; timer delay (%d us).\n",
3673 ha->zio_mode, ha->zio_timer * 100);
3675 icb->firmware_options_2 |= cpu_to_le32(
3676 (uint32_t)ha->zio_mode);
3677 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3678 ha->flags.process_response_queue = 1;
3682 DEBUG2_3(printk(KERN_WARNING
3683 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3689 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3692 int segments, fragment;
3694 uint32_t *dcode, dlen;
3701 segments = FA_RISC_CODE_SEGMENTS;
3702 faddr = FA_RISC_CODE_ADDR;
3703 dcode = (uint32_t *)ha->request_ring;
3706 /* Validate firmware image by checking version. */
3707 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3708 for (i = 0; i < 4; i++)
3709 dcode[i] = be32_to_cpu(dcode[i]);
3710 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3711 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3712 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3714 qla_printk(KERN_WARNING, ha,
3715 "Unable to verify integrity of flash firmware image!\n");
3716 qla_printk(KERN_WARNING, ha,
3717 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3718 dcode[1], dcode[2], dcode[3]);
3720 return QLA_FUNCTION_FAILED;
3723 while (segments && rval == QLA_SUCCESS) {
3724 /* Read segment's load information. */
3725 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3727 risc_addr = be32_to_cpu(dcode[2]);
3728 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3729 risc_size = be32_to_cpu(dcode[3]);
3732 while (risc_size > 0 && rval == QLA_SUCCESS) {
3733 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3734 if (dlen > risc_size)
3737 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3738 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3739 ha->host_no, risc_addr, dlen, faddr));
3741 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3742 for (i = 0; i < dlen; i++)
3743 dcode[i] = swab32(dcode[i]);
3745 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3748 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3749 "segment %d of firmware\n", ha->host_no,
3751 qla_printk(KERN_WARNING, ha,
3752 "[ERROR] Failed to load segment %d of "
3753 "firmware\n", fragment);
3770 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3773 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3777 uint16_t *wcode, *fwcode;
3778 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3779 struct fw_blob *blob;
3781 /* Load firmware blob. */
3782 blob = qla2x00_request_firmware(ha);
3784 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3785 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3786 "from: " QLA_FW_URL ".\n");
3787 return QLA_FUNCTION_FAILED;
3792 wcode = (uint16_t *)ha->request_ring;
3794 fwcode = (uint16_t *)blob->fw->data;
3797 /* Validate firmware image by checking version. */
3798 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3799 qla_printk(KERN_WARNING, ha,
3800 "Unable to verify integrity of firmware image (%Zd)!\n",
3802 goto fail_fw_integrity;
3804 for (i = 0; i < 4; i++)
3805 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3806 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3807 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3808 wcode[2] == 0 && wcode[3] == 0)) {
3809 qla_printk(KERN_WARNING, ha,
3810 "Unable to verify integrity of firmware image!\n");
3811 qla_printk(KERN_WARNING, ha,
3812 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3813 wcode[1], wcode[2], wcode[3]);
3814 goto fail_fw_integrity;
3818 while (*seg && rval == QLA_SUCCESS) {
3820 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3821 risc_size = be16_to_cpu(fwcode[3]);
3823 /* Validate firmware image size. */
3824 fwclen += risc_size * sizeof(uint16_t);
3825 if (blob->fw->size < fwclen) {
3826 qla_printk(KERN_WARNING, ha,
3827 "Unable to verify integrity of firmware image "
3828 "(%Zd)!\n", blob->fw->size);
3829 goto fail_fw_integrity;
3833 while (risc_size > 0 && rval == QLA_SUCCESS) {
3834 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3835 if (wlen > risc_size)
3838 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3839 "addr %x, number of words 0x%x.\n", ha->host_no,
3842 for (i = 0; i < wlen; i++)
3843 wcode[i] = swab16(fwcode[i]);
3845 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3848 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3849 "segment %d of firmware\n", ha->host_no,
3851 qla_printk(KERN_WARNING, ha,
3852 "[ERROR] Failed to load segment %d of "
3853 "firmware\n", fragment);
3869 return QLA_FUNCTION_FAILED;
3873 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3876 int segments, fragment;
3877 uint32_t *dcode, dlen;
3881 struct fw_blob *blob;
3882 uint32_t *fwcode, fwclen;
3884 /* Load firmware blob. */
3885 blob = qla2x00_request_firmware(ha);
3887 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3888 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3889 "from: " QLA_FW_URL ".\n");
3891 /* Try to load RISC code from flash. */
3892 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3893 "outdated) firmware from flash.\n");
3894 return qla24xx_load_risc_flash(ha, srisc_addr);
3899 segments = FA_RISC_CODE_SEGMENTS;
3900 dcode = (uint32_t *)ha->request_ring;
3902 fwcode = (uint32_t *)blob->fw->data;
3905 /* Validate firmware image by checking version. */
3906 if (blob->fw->size < 8 * sizeof(uint32_t)) {
3907 qla_printk(KERN_WARNING, ha,
3908 "Unable to verify integrity of firmware image (%Zd)!\n",
3910 goto fail_fw_integrity;
3912 for (i = 0; i < 4; i++)
3913 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3914 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3915 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3916 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3918 qla_printk(KERN_WARNING, ha,
3919 "Unable to verify integrity of firmware image!\n");
3920 qla_printk(KERN_WARNING, ha,
3921 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3922 dcode[1], dcode[2], dcode[3]);
3923 goto fail_fw_integrity;
3926 while (segments && rval == QLA_SUCCESS) {
3927 risc_addr = be32_to_cpu(fwcode[2]);
3928 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3929 risc_size = be32_to_cpu(fwcode[3]);
3931 /* Validate firmware image size. */
3932 fwclen += risc_size * sizeof(uint32_t);
3933 if (blob->fw->size < fwclen) {
3934 qla_printk(KERN_WARNING, ha,
3935 "Unable to verify integrity of firmware image "
3936 "(%Zd)!\n", blob->fw->size);
3938 goto fail_fw_integrity;
3942 while (risc_size > 0 && rval == QLA_SUCCESS) {
3943 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3944 if (dlen > risc_size)
3947 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3948 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3951 for (i = 0; i < dlen; i++)
3952 dcode[i] = swab32(fwcode[i]);
3954 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3957 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3958 "segment %d of firmware\n", ha->host_no,
3960 qla_printk(KERN_WARNING, ha,
3961 "[ERROR] Failed to load segment %d of "
3962 "firmware\n", fragment);
3978 return QLA_FUNCTION_FAILED;
3982 qla2x00_try_to_stop_firmware(scsi_qla_host_t *ha)
3986 if (!IS_FWI2_CAPABLE(ha))
3988 if (!ha->fw_major_version)
3991 ret = qla2x00_stop_firmware(ha);
3992 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
3993 retries ; retries--) {
3994 qla2x00_reset_chip(ha);
3995 if (qla2x00_chip_diag(ha) != QLA_SUCCESS)
3997 if (qla2x00_setup_chip(ha) != QLA_SUCCESS)
3999 qla_printk(KERN_INFO, ha,
4000 "Attempting retry of stop-firmware command...\n");
4001 ret = qla2x00_stop_firmware(ha);
4006 qla24xx_configure_vhba(scsi_qla_host_t *ha)
4008 int rval = QLA_SUCCESS;
4009 uint16_t mb[MAILBOX_REGISTER_COUNT];
4014 rval = qla2x00_fw_ready(ha);
4015 if (rval == QLA_SUCCESS) {
4016 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
4017 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
4020 ha->flags.management_server_logged_in = 0;
4022 /* Login to SNS first */
4023 qla24xx_login_fabric(ha, NPH_SNS, 0xff, 0xff, 0xfc,
4025 if (mb[0] != MBS_COMMAND_COMPLETE) {
4026 DEBUG15(qla_printk(KERN_INFO, ha,
4027 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4028 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4029 mb[0], mb[1], mb[2], mb[6], mb[7]));
4030 return (QLA_FUNCTION_FAILED);
4033 atomic_set(&ha->loop_down_timer, 0);
4034 atomic_set(&ha->loop_state, LOOP_UP);
4035 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4036 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
4037 rval = qla2x00_loop_resync(ha);