2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 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"
14 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
15 #ifndef EXT_IS_LUN_BIT_SET
16 #define EXT_IS_LUN_BIT_SET(P,L) \
17 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
18 #define EXT_SET_LUN_BIT(P,L) \
19 ((P)->mask[L/8] |= (0x80 >> (L%8)))
23 * QLogic ISP2x00 Hardware Support Function Prototypes.
25 static int qla2x00_isp_firmware(scsi_qla_host_t *);
26 static void qla2x00_resize_request_q(scsi_qla_host_t *);
27 static int qla2x00_setup_chip(scsi_qla_host_t *);
28 static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
29 static int qla2x00_init_rings(scsi_qla_host_t *);
30 static int qla2x00_fw_ready(scsi_qla_host_t *);
31 static int qla2x00_configure_hba(scsi_qla_host_t *);
32 static int qla2x00_configure_loop(scsi_qla_host_t *);
33 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
34 static int qla2x00_configure_fabric(scsi_qla_host_t *);
35 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
36 static int qla2x00_device_resync(scsi_qla_host_t *);
37 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
40 static int qla2x00_restart_isp(scsi_qla_host_t *);
42 /****************************************************************************/
43 /* QLogic ISP2x00 Hardware Support Functions. */
44 /****************************************************************************/
47 * qla2x00_initialize_adapter
51 * ha = adapter block pointer.
57 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
60 uint8_t restart_risc = 0;
64 /* Clear adapter flags. */
66 ha->flags.reset_active = 0;
67 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
68 atomic_set(&ha->loop_state, LOOP_DOWN);
71 ha->flags.management_server_logged_in = 0;
72 ha->marker_needed = 0;
74 ha->isp_abort_cnt = 0;
75 ha->beacon_blink_led = 0;
76 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
78 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
79 rval = ha->isp_ops.pci_config(ha);
81 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
86 ha->isp_ops.reset_chip(ha);
88 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
90 ha->isp_ops.nvram_config(ha);
92 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
96 * Try to configure the loop.
101 /* If firmware needs to be loaded */
102 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
103 if ((rval = ha->isp_ops.chip_diag(ha)) == QLA_SUCCESS) {
104 rval = qla2x00_setup_chip(ha);
108 if (rval == QLA_SUCCESS &&
109 (rval = qla2x00_init_rings(ha)) == QLA_SUCCESS) {
110 check_fw_ready_again:
112 * Wait for a successful LIP up to a maximum
113 * of (in seconds): RISC login timeout value,
114 * RISC retry count value, and port down retry
115 * value OR a minimum of 4 seconds OR If no
116 * cable, only 5 seconds.
118 rval = qla2x00_fw_ready(ha);
119 if (rval == QLA_SUCCESS) {
120 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
122 /* Issue a marker after FW becomes ready. */
123 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
126 * Wait at most MAX_TARGET RSCNs for a stable
131 clear_bit(LOOP_RESYNC_NEEDED,
133 rval = qla2x00_configure_loop(ha);
135 if (test_and_clear_bit(ISP_ABORT_NEEDED,
142 * If loop state change while we were
143 * discoverying devices then wait for
147 if (atomic_read(&ha->loop_state) !=
148 LOOP_READY && retry--) {
149 goto check_fw_ready_again;
152 } while (!atomic_read(&ha->loop_down_timer) &&
155 (test_bit(LOOP_RESYNC_NEEDED,
159 rval = QLA_FUNCTION_FAILED;
160 } else if (ha->device_flags & DFLG_NO_CABLE)
161 /* If no cable, then all is good. */
164 } while (restart_risc && retry--);
166 if (rval == QLA_SUCCESS) {
167 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
168 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
169 ha->marker_needed = 0;
171 ha->flags.online = 1;
173 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
180 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
183 * Returns 0 on success.
186 qla2100_pci_config(scsi_qla_host_t *ha)
191 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
193 pci_set_master(ha->pdev);
195 if (pci_set_mwi(ha->pdev))
196 mwi = PCI_COMMAND_INVALIDATE;
197 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
199 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
200 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
201 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
203 /* Reset expansion ROM address decode enable */
204 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
205 d &= ~PCI_ROM_ADDRESS_ENABLE;
206 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
208 /* Get PCI bus information. */
209 spin_lock_irqsave(&ha->hardware_lock, flags);
210 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
211 spin_unlock_irqrestore(&ha->hardware_lock, flags);
217 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
220 * Returns 0 on success.
223 qla2300_pci_config(scsi_qla_host_t *ha)
227 unsigned long flags = 0;
229 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
231 pci_set_master(ha->pdev);
233 if (pci_set_mwi(ha->pdev))
234 mwi = PCI_COMMAND_INVALIDATE;
235 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
237 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
238 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
240 if (IS_QLA2322(ha) || IS_QLA6322(ha))
241 w &= ~PCI_COMMAND_INTX_DISABLE;
244 * If this is a 2300 card and not 2312, reset the
245 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
246 * the 2310 also reports itself as a 2300 so we need to get the
247 * fb revision level -- a 6 indicates it really is a 2300 and
250 if (IS_QLA2300(ha)) {
251 spin_lock_irqsave(&ha->hardware_lock, flags);
254 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
255 for (cnt = 0; cnt < 30000; cnt++) {
256 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
262 /* Select FPM registers. */
263 WRT_REG_WORD(®->ctrl_status, 0x20);
264 RD_REG_WORD(®->ctrl_status);
266 /* Get the fb rev level */
267 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
269 if (ha->fb_rev == FPM_2300)
270 w &= ~PCI_COMMAND_INVALIDATE;
272 /* Deselect FPM registers. */
273 WRT_REG_WORD(®->ctrl_status, 0x0);
274 RD_REG_WORD(®->ctrl_status);
276 /* Release RISC module. */
277 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
278 for (cnt = 0; cnt < 30000; cnt++) {
279 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
285 spin_unlock_irqrestore(&ha->hardware_lock, flags);
287 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
289 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
291 /* Reset expansion ROM address decode enable */
292 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
293 d &= ~PCI_ROM_ADDRESS_ENABLE;
294 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
296 /* Get PCI bus information. */
297 spin_lock_irqsave(&ha->hardware_lock, flags);
298 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
299 spin_unlock_irqrestore(&ha->hardware_lock, flags);
305 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
308 * Returns 0 on success.
311 qla24xx_pci_config(scsi_qla_host_t *ha)
315 unsigned long flags = 0;
316 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
317 int pcix_cmd_reg, pcie_dctl_reg;
319 pci_set_master(ha->pdev);
321 if (pci_set_mwi(ha->pdev))
322 mwi = PCI_COMMAND_INVALIDATE;
323 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
325 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
326 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
327 w &= ~PCI_COMMAND_INTX_DISABLE;
328 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
330 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
332 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
333 pcix_cmd_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX);
337 pcix_cmd_reg += PCI_X_CMD;
338 pci_read_config_word(ha->pdev, pcix_cmd_reg, &pcix_cmd);
339 pcix_cmd &= ~PCI_X_CMD_MAX_READ;
341 pci_write_config_word(ha->pdev, pcix_cmd_reg, pcix_cmd);
344 /* PCIe -- adjust Maximum Read Request Size (2048). */
345 pcie_dctl_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
349 pcie_dctl_reg += PCI_EXP_DEVCTL;
350 pci_read_config_word(ha->pdev, pcie_dctl_reg, &pcie_dctl);
351 pcie_dctl &= ~PCI_EXP_DEVCTL_READRQ;
353 pci_write_config_word(ha->pdev, pcie_dctl_reg, pcie_dctl);
356 /* Reset expansion ROM address decode enable */
357 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
358 d &= ~PCI_ROM_ADDRESS_ENABLE;
359 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
361 /* Get PCI bus information. */
362 spin_lock_irqsave(&ha->hardware_lock, flags);
363 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
364 spin_unlock_irqrestore(&ha->hardware_lock, flags);
370 * qla2x00_isp_firmware() - Choose firmware image.
373 * Returns 0 on success.
376 qla2x00_isp_firmware(scsi_qla_host_t *ha)
380 /* Assume loading risc code */
381 rval = QLA_FUNCTION_FAILED;
383 if (ha->flags.disable_risc_code_load) {
384 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
386 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
388 /* Verify checksum of loaded RISC code. */
389 rval = qla2x00_verify_checksum(ha,
390 IS_QLA24XX(ha) || IS_QLA54XX(ha) ? RISC_SADDRESS :
391 *ha->brd_info->fw_info[0].fwstart);
395 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
403 * qla2x00_reset_chip() - Reset ISP chip.
406 * Returns 0 on success.
409 qla2x00_reset_chip(scsi_qla_host_t *ha)
411 unsigned long flags = 0;
412 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
416 ha->isp_ops.disable_intrs(ha);
418 spin_lock_irqsave(&ha->hardware_lock, flags);
420 /* Turn off master enable */
422 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
423 cmd &= ~PCI_COMMAND_MASTER;
424 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
426 if (!IS_QLA2100(ha)) {
428 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
429 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
430 for (cnt = 0; cnt < 30000; cnt++) {
431 if ((RD_REG_WORD(®->hccr) &
432 HCCR_RISC_PAUSE) != 0)
437 RD_REG_WORD(®->hccr); /* PCI Posting. */
441 /* Select FPM registers. */
442 WRT_REG_WORD(®->ctrl_status, 0x20);
443 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
445 /* FPM Soft Reset. */
446 WRT_REG_WORD(®->fpm_diag_config, 0x100);
447 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
449 /* Toggle Fpm Reset. */
450 if (!IS_QLA2200(ha)) {
451 WRT_REG_WORD(®->fpm_diag_config, 0x0);
452 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
455 /* Select frame buffer registers. */
456 WRT_REG_WORD(®->ctrl_status, 0x10);
457 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
459 /* Reset frame buffer FIFOs. */
460 if (IS_QLA2200(ha)) {
461 WRT_FB_CMD_REG(ha, reg, 0xa000);
462 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
464 WRT_FB_CMD_REG(ha, reg, 0x00fc);
466 /* Read back fb_cmd until zero or 3 seconds max */
467 for (cnt = 0; cnt < 3000; cnt++) {
468 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
474 /* Select RISC module registers. */
475 WRT_REG_WORD(®->ctrl_status, 0);
476 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
478 /* Reset RISC processor. */
479 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
480 RD_REG_WORD(®->hccr); /* PCI Posting. */
482 /* Release RISC processor. */
483 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
484 RD_REG_WORD(®->hccr); /* PCI Posting. */
487 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
488 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
490 /* Reset ISP chip. */
491 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
493 /* Wait for RISC to recover from reset. */
494 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
496 * It is necessary to for a delay here since the card doesn't
497 * respond to PCI reads during a reset. On some architectures
498 * this will result in an MCA.
501 for (cnt = 30000; cnt; cnt--) {
502 if ((RD_REG_WORD(®->ctrl_status) &
503 CSR_ISP_SOFT_RESET) == 0)
510 /* Reset RISC processor. */
511 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
513 WRT_REG_WORD(®->semaphore, 0);
515 /* Release RISC processor. */
516 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
517 RD_REG_WORD(®->hccr); /* PCI Posting. */
519 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
520 for (cnt = 0; cnt < 30000; cnt++) {
521 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
529 /* Turn on master enable */
530 cmd |= PCI_COMMAND_MASTER;
531 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
533 /* Disable RISC pause on FPM parity error. */
534 if (!IS_QLA2100(ha)) {
535 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
536 RD_REG_WORD(®->hccr); /* PCI Posting. */
539 spin_unlock_irqrestore(&ha->hardware_lock, flags);
543 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
546 * Returns 0 on success.
549 qla24xx_reset_risc(scsi_qla_host_t *ha)
551 unsigned long flags = 0;
552 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
556 spin_lock_irqsave(&ha->hardware_lock, flags);
559 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
560 for (cnt = 0; cnt < 30000; cnt++) {
561 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
567 WRT_REG_DWORD(®->ctrl_status,
568 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
569 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
572 /* Wait for firmware to complete NVRAM accesses. */
573 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
574 for (cnt = 10000 ; cnt && d2; cnt--) {
576 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
580 /* Wait for soft-reset to complete. */
581 d2 = RD_REG_DWORD(®->ctrl_status);
582 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
584 d2 = RD_REG_DWORD(®->ctrl_status);
588 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
589 RD_REG_DWORD(®->hccr);
591 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
592 RD_REG_DWORD(®->hccr);
594 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
595 RD_REG_DWORD(®->hccr);
597 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
598 for (cnt = 6000000 ; cnt && d2; cnt--) {
600 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
604 spin_unlock_irqrestore(&ha->hardware_lock, flags);
608 * qla24xx_reset_chip() - Reset ISP24xx chip.
611 * Returns 0 on success.
614 qla24xx_reset_chip(scsi_qla_host_t *ha)
616 ha->isp_ops.disable_intrs(ha);
618 /* Perform RISC reset. */
619 qla24xx_reset_risc(ha);
623 * qla2x00_chip_diag() - Test chip for proper operation.
626 * Returns 0 on success.
629 qla2x00_chip_diag(scsi_qla_host_t *ha)
632 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
633 unsigned long flags = 0;
638 /* Assume a failed state */
639 rval = QLA_FUNCTION_FAILED;
641 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
642 ha->host_no, (u_long)®->flash_address));
644 spin_lock_irqsave(&ha->hardware_lock, flags);
646 /* Reset ISP chip. */
647 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
650 * We need to have a delay here since the card will not respond while
651 * in reset causing an MCA on some architectures.
654 data = qla2x00_debounce_register(®->ctrl_status);
655 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
657 data = RD_REG_WORD(®->ctrl_status);
662 goto chip_diag_failed;
664 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
667 /* Reset RISC processor. */
668 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
669 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
671 /* Workaround for QLA2312 PCI parity error */
672 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
673 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
674 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
676 data = RD_MAILBOX_REG(ha, reg, 0);
683 goto chip_diag_failed;
685 /* Check product ID of chip */
686 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
688 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
689 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
690 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
691 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
692 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
693 mb[3] != PROD_ID_3) {
694 qla_printk(KERN_WARNING, ha,
695 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
697 goto chip_diag_failed;
699 ha->product_id[0] = mb[1];
700 ha->product_id[1] = mb[2];
701 ha->product_id[2] = mb[3];
702 ha->product_id[3] = mb[4];
704 /* Adjust fw RISC transfer size */
705 if (ha->request_q_length > 1024)
706 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
708 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
709 ha->request_q_length;
711 if (IS_QLA2200(ha) &&
712 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
713 /* Limit firmware transfer size with a 2200A */
714 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
717 ha->device_type |= DT_ISP2200A;
718 ha->fw_transfer_size = 128;
721 /* Wrap Incoming Mailboxes Test. */
722 spin_unlock_irqrestore(&ha->hardware_lock, flags);
724 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
725 rval = qla2x00_mbx_reg_test(ha);
727 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
729 qla_printk(KERN_WARNING, ha,
730 "Failed mailbox send register test\n");
733 /* Flag a successful rval */
736 spin_lock_irqsave(&ha->hardware_lock, flags);
740 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
741 "****\n", ha->host_no));
743 spin_unlock_irqrestore(&ha->hardware_lock, flags);
749 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
752 * Returns 0 on success.
755 qla24xx_chip_diag(scsi_qla_host_t *ha)
759 /* Perform RISC reset. */
760 qla24xx_reset_risc(ha);
762 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
764 rval = qla2x00_mbx_reg_test(ha);
766 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
768 qla_printk(KERN_WARNING, ha,
769 "Failed mailbox send register test\n");
771 /* Flag a successful rval */
779 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
782 ha->fw_dump24_len = sizeof(struct qla24xx_fw_dump);
783 ha->fw_dump24_len += (ha->fw_memory_size - 0x100000) * sizeof(uint32_t);
784 ha->fw_dump24 = vmalloc(ha->fw_dump24_len);
786 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware "
787 "dump...\n", ha->fw_dump24_len / 1024);
789 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
790 "firmware dump!!!\n", ha->fw_dump24_len / 1024);
794 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
797 * Returns 0 on success.
800 qla2x00_resize_request_q(scsi_qla_host_t *ha)
803 uint16_t fw_iocb_cnt = 0;
804 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
805 dma_addr_t request_dma;
806 request_t *request_ring;
808 /* Valid only on recent ISPs. */
809 if (IS_QLA2100(ha) || IS_QLA2200(ha))
812 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
813 qla2x00_alloc_fw_dump(ha);
815 /* Retrieve IOCB counts available to the firmware. */
816 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
819 /* No point in continuing if current settings are sufficient. */
820 if (fw_iocb_cnt < 1024)
822 if (ha->request_q_length >= request_q_length)
825 /* Attempt to claim larger area for request queue. */
826 request_ring = dma_alloc_coherent(&ha->pdev->dev,
827 (request_q_length + 1) * sizeof(request_t), &request_dma,
829 if (request_ring == NULL)
832 /* Resize successful, report extensions. */
833 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
834 (ha->fw_memory_size + 1) / 1024);
835 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
836 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
838 /* Clear old allocations. */
839 dma_free_coherent(&ha->pdev->dev,
840 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
843 /* Begin using larger queue. */
844 ha->request_q_length = request_q_length;
845 ha->request_ring = request_ring;
846 ha->request_dma = request_dma;
850 * qla2x00_setup_chip() - Load and start RISC firmware.
853 * Returns 0 on success.
856 qla2x00_setup_chip(scsi_qla_host_t *ha)
859 uint32_t srisc_address = 0;
861 /* Load firmware sequences */
862 rval = ha->isp_ops.load_risc(ha, &srisc_address);
863 if (rval == QLA_SUCCESS) {
864 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
865 "code.\n", ha->host_no));
867 rval = qla2x00_verify_checksum(ha, srisc_address);
868 if (rval == QLA_SUCCESS) {
869 /* Start firmware execution. */
870 DEBUG(printk("scsi(%ld): Checksum OK, start "
871 "firmware.\n", ha->host_no));
873 rval = qla2x00_execute_fw(ha, srisc_address);
874 /* Retrieve firmware information. */
875 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
876 qla2x00_get_fw_version(ha,
877 &ha->fw_major_version,
878 &ha->fw_minor_version,
879 &ha->fw_subminor_version,
880 &ha->fw_attributes, &ha->fw_memory_size);
881 qla2x00_resize_request_q(ha);
884 DEBUG2(printk(KERN_INFO
885 "scsi(%ld): ISP Firmware failed checksum.\n",
891 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
899 * qla2x00_init_response_q_entries() - Initializes response queue entries.
902 * Beginning of request ring has initialization control block already built
903 * by nvram config routine.
905 * Returns 0 on success.
908 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
913 pkt = ha->response_ring_ptr;
914 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
915 pkt->signature = RESPONSE_PROCESSED;
922 * qla2x00_update_fw_options() - Read and process firmware options.
925 * Returns 0 on success.
928 qla2x00_update_fw_options(scsi_qla_host_t *ha)
930 uint16_t swing, emphasis, tx_sens, rx_sens;
932 memset(ha->fw_options, 0, sizeof(ha->fw_options));
933 qla2x00_get_fw_options(ha, ha->fw_options);
935 if (IS_QLA2100(ha) || IS_QLA2200(ha))
938 /* Serial Link options. */
939 DEBUG3(printk("scsi(%ld): Serial link options:\n",
941 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
942 sizeof(ha->fw_seriallink_options)));
944 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
945 if (ha->fw_seriallink_options[3] & BIT_2) {
946 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
949 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
950 emphasis = (ha->fw_seriallink_options[2] &
951 (BIT_4 | BIT_3)) >> 3;
952 tx_sens = ha->fw_seriallink_options[0] &
953 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
954 rx_sens = (ha->fw_seriallink_options[0] &
955 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
956 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
957 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
960 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
961 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
962 ha->fw_options[10] |= BIT_5 |
963 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
964 (tx_sens & (BIT_1 | BIT_0));
967 swing = (ha->fw_seriallink_options[2] &
968 (BIT_7 | BIT_6 | BIT_5)) >> 5;
969 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
970 tx_sens = ha->fw_seriallink_options[1] &
971 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
972 rx_sens = (ha->fw_seriallink_options[1] &
973 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
974 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
975 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
978 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
979 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
980 ha->fw_options[11] |= BIT_5 |
981 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
982 (tx_sens & (BIT_1 | BIT_0));
986 /* Return command IOCBs without waiting for an ABTS to complete. */
987 ha->fw_options[3] |= BIT_13;
990 if (ha->flags.enable_led_scheme)
991 ha->fw_options[2] |= BIT_12;
993 /* Detect ISP6312. */
995 ha->fw_options[2] |= BIT_13;
997 /* Update firmware options. */
998 qla2x00_set_fw_options(ha, ha->fw_options);
1002 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1006 /* Update Serial Link options. */
1007 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1010 rval = qla2x00_set_serdes_params(ha,
1011 le16_to_cpu(ha->fw_seriallink_options24[1]),
1012 le16_to_cpu(ha->fw_seriallink_options24[2]),
1013 le16_to_cpu(ha->fw_seriallink_options24[3]));
1014 if (rval != QLA_SUCCESS) {
1015 qla_printk(KERN_WARNING, ha,
1016 "Unable to update Serial Link options (%x).\n", rval);
1021 qla2x00_config_rings(struct scsi_qla_host *ha)
1023 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1025 /* Setup ring parameters in initialization control block. */
1026 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1027 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1028 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1029 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1030 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1031 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1032 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1033 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1035 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1036 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1037 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1038 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1039 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1043 qla24xx_config_rings(struct scsi_qla_host *ha)
1045 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1046 struct init_cb_24xx *icb;
1048 /* Setup ring parameters in initialization control block. */
1049 icb = (struct init_cb_24xx *)ha->init_cb;
1050 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1051 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1052 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1053 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1054 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1055 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1056 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1057 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1059 WRT_REG_DWORD(®->req_q_in, 0);
1060 WRT_REG_DWORD(®->req_q_out, 0);
1061 WRT_REG_DWORD(®->rsp_q_in, 0);
1062 WRT_REG_DWORD(®->rsp_q_out, 0);
1063 RD_REG_DWORD(®->rsp_q_out);
1067 * qla2x00_init_rings() - Initializes firmware.
1070 * Beginning of request ring has initialization control block already built
1071 * by nvram config routine.
1073 * Returns 0 on success.
1076 qla2x00_init_rings(scsi_qla_host_t *ha)
1079 unsigned long flags = 0;
1082 spin_lock_irqsave(&ha->hardware_lock, flags);
1084 /* Clear outstanding commands array. */
1085 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1086 ha->outstanding_cmds[cnt] = NULL;
1088 ha->current_outstanding_cmd = 0;
1090 /* Clear RSCN queue. */
1091 ha->rscn_in_ptr = 0;
1092 ha->rscn_out_ptr = 0;
1094 /* Initialize firmware. */
1095 ha->request_ring_ptr = ha->request_ring;
1096 ha->req_ring_index = 0;
1097 ha->req_q_cnt = ha->request_q_length;
1098 ha->response_ring_ptr = ha->response_ring;
1099 ha->rsp_ring_index = 0;
1101 /* Initialize response queue entries */
1102 qla2x00_init_response_q_entries(ha);
1104 ha->isp_ops.config_rings(ha);
1106 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1108 /* Update any ISP specific firmware options before initialization. */
1109 ha->isp_ops.update_fw_options(ha);
1111 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1112 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1114 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1117 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1125 * qla2x00_fw_ready() - Waits for firmware ready.
1128 * Returns 0 on success.
1131 qla2x00_fw_ready(scsi_qla_host_t *ha)
1134 unsigned long wtime, mtime;
1135 uint16_t min_wait; /* Minimum wait time if loop is down */
1136 uint16_t wait_time; /* Wait time if loop is coming ready */
1141 /* 20 seconds for loop down. */
1145 * Firmware should take at most one RATOV to login, plus 5 seconds for
1146 * our own processing.
1148 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1149 wait_time = min_wait;
1152 /* Min wait time if loop down */
1153 mtime = jiffies + (min_wait * HZ);
1155 /* wait time before firmware ready */
1156 wtime = jiffies + (wait_time * HZ);
1158 /* Wait for ISP to finish LIP */
1159 if (!ha->flags.init_done)
1160 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1162 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1166 rval = qla2x00_get_firmware_state(ha, &fw_state);
1167 if (rval == QLA_SUCCESS) {
1168 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1169 ha->device_flags &= ~DFLG_NO_CABLE;
1171 if (fw_state == FSTATE_READY) {
1172 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1175 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1176 &ha->login_timeout, &ha->r_a_tov);
1182 rval = QLA_FUNCTION_FAILED;
1184 if (atomic_read(&ha->loop_down_timer) &&
1185 (fw_state >= FSTATE_LOSS_OF_SYNC ||
1186 fw_state == FSTATE_WAIT_AL_PA)) {
1187 /* Loop down. Timeout on min_wait for states
1188 * other than Wait for Login.
1190 if (time_after_eq(jiffies, mtime)) {
1191 qla_printk(KERN_INFO, ha,
1192 "Cable is unplugged...\n");
1194 ha->device_flags |= DFLG_NO_CABLE;
1199 /* Mailbox cmd failed. Timeout on min_wait. */
1200 if (time_after_eq(jiffies, mtime))
1204 if (time_after_eq(jiffies, wtime))
1207 /* Delay for a while */
1210 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1211 ha->host_no, fw_state, jiffies));
1214 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1215 ha->host_no, fw_state, jiffies));
1218 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1226 * qla2x00_configure_hba
1227 * Setup adapter context.
1230 * ha = adapter state pointer.
1239 qla2x00_configure_hba(scsi_qla_host_t *ha)
1247 char connect_type[22];
1249 /* Get host addresses. */
1250 rval = qla2x00_get_adapter_id(ha,
1251 &loop_id, &al_pa, &area, &domain, &topo);
1252 if (rval != QLA_SUCCESS) {
1253 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
1254 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1255 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1256 __func__, ha->host_no));
1258 qla_printk(KERN_WARNING, ha,
1259 "ERROR -- Unable to get host loop ID.\n");
1260 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1266 qla_printk(KERN_INFO, ha,
1267 "Cannot get topology - retrying.\n");
1268 return (QLA_FUNCTION_FAILED);
1271 ha->loop_id = loop_id;
1274 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1275 ha->operating_mode = LOOP;
1279 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1281 ha->current_topology = ISP_CFG_NL;
1282 strcpy(connect_type, "(Loop)");
1286 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1288 ha->current_topology = ISP_CFG_FL;
1289 strcpy(connect_type, "(FL_Port)");
1293 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1295 ha->operating_mode = P2P;
1296 ha->current_topology = ISP_CFG_N;
1297 strcpy(connect_type, "(N_Port-to-N_Port)");
1301 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1303 ha->operating_mode = P2P;
1304 ha->current_topology = ISP_CFG_F;
1305 strcpy(connect_type, "(F_Port)");
1309 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1311 ha->host_no, topo));
1312 ha->current_topology = ISP_CFG_NL;
1313 strcpy(connect_type, "(Loop)");
1317 /* Save Host port and loop ID. */
1318 /* byte order - Big Endian */
1319 ha->d_id.b.domain = domain;
1320 ha->d_id.b.area = area;
1321 ha->d_id.b.al_pa = al_pa;
1323 if (!ha->flags.init_done)
1324 qla_printk(KERN_INFO, ha,
1325 "Topology - %s, Host Loop address 0x%x\n",
1326 connect_type, ha->loop_id);
1329 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1331 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1338 * NVRAM configuration for ISP 2xxx
1341 * ha = adapter block pointer.
1344 * initialization control block in response_ring
1345 * host adapters parameters in host adapter block
1351 qla2x00_nvram_config(scsi_qla_host_t *ha)
1356 uint8_t *dptr1, *dptr2;
1357 init_cb_t *icb = ha->init_cb;
1358 nvram_t *nv = (nvram_t *)ha->request_ring;
1359 uint8_t *ptr = (uint8_t *)ha->request_ring;
1360 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1364 /* Determine NVRAM starting address. */
1365 ha->nvram_size = sizeof(nvram_t);
1367 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1368 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1369 ha->nvram_base = 0x80;
1371 /* Get NVRAM data and calculate checksum. */
1372 ha->isp_ops.read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1373 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1376 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1377 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1380 /* Bad NVRAM data, set defaults parameters. */
1381 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1382 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1383 /* Reset NVRAM data. */
1384 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1385 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1387 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1388 "invalid -- WWPN) defaults.\n");
1391 * Set default initialization control block.
1393 memset(nv, 0, ha->nvram_size);
1394 nv->parameter_block_version = ICB_VERSION;
1396 if (IS_QLA23XX(ha)) {
1397 nv->firmware_options[0] = BIT_2 | BIT_1;
1398 nv->firmware_options[1] = BIT_7 | BIT_5;
1399 nv->add_firmware_options[0] = BIT_5;
1400 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1401 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1402 nv->special_options[1] = BIT_7;
1403 } else if (IS_QLA2200(ha)) {
1404 nv->firmware_options[0] = BIT_2 | BIT_1;
1405 nv->firmware_options[1] = BIT_7 | BIT_5;
1406 nv->add_firmware_options[0] = BIT_5;
1407 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1408 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1409 } else if (IS_QLA2100(ha)) {
1410 nv->firmware_options[0] = BIT_3 | BIT_1;
1411 nv->firmware_options[1] = BIT_5;
1412 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1415 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1416 nv->execution_throttle = __constant_cpu_to_le16(16);
1417 nv->retry_count = 8;
1418 nv->retry_delay = 1;
1420 nv->port_name[0] = 33;
1421 nv->port_name[3] = 224;
1422 nv->port_name[4] = 139;
1424 nv->login_timeout = 4;
1427 * Set default host adapter parameters
1429 nv->host_p[1] = BIT_2;
1430 nv->reset_delay = 5;
1431 nv->port_down_retry_count = 8;
1432 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1433 nv->link_down_timeout = 60;
1438 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1440 * The SN2 does not provide BIOS emulation which means you can't change
1441 * potentially bogus BIOS settings. Force the use of default settings
1442 * for link rate and frame size. Hope that the rest of the settings
1445 if (ia64_platform_is("sn2")) {
1446 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1448 nv->special_options[1] = BIT_7;
1452 /* Reset Initialization control block */
1453 memset(icb, 0, ha->init_cb_size);
1456 * Setup driver NVRAM options.
1458 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1459 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1460 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1461 nv->firmware_options[1] &= ~BIT_4;
1463 if (IS_QLA23XX(ha)) {
1464 nv->firmware_options[0] |= BIT_2;
1465 nv->firmware_options[0] &= ~BIT_3;
1466 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1468 if (IS_QLA2300(ha)) {
1469 if (ha->fb_rev == FPM_2310) {
1470 strcpy(ha->model_number, "QLA2310");
1472 strcpy(ha->model_number, "QLA2300");
1476 memcmp(nv->model_number, BINZERO,
1477 sizeof(nv->model_number)) != 0) {
1480 strncpy(ha->model_number, nv->model_number,
1481 sizeof(nv->model_number));
1482 st = en = ha->model_number;
1483 en += sizeof(nv->model_number) - 1;
1485 if (*en != 0x20 && *en != 0x00)
1492 index = (ha->pdev->subsystem_device & 0xff);
1493 if (index < QLA_MODEL_NAMES) {
1494 strcpy(ha->model_number,
1495 qla2x00_model_name[index * 2]);
1497 qla2x00_model_name[index * 2 + 1];
1499 strcpy(ha->model_number, "QLA23xx");
1503 } else if (IS_QLA2200(ha)) {
1504 nv->firmware_options[0] |= BIT_2;
1506 * 'Point-to-point preferred, else loop' is not a safe
1507 * connection mode setting.
1509 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1511 /* Force 'loop preferred, else point-to-point'. */
1512 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1513 nv->add_firmware_options[0] |= BIT_5;
1515 strcpy(ha->model_number, "QLA22xx");
1516 } else /*if (IS_QLA2100(ha))*/ {
1517 strcpy(ha->model_number, "QLA2100");
1521 * Copy over NVRAM RISC parameter block to initialization control block.
1523 dptr1 = (uint8_t *)icb;
1524 dptr2 = (uint8_t *)&nv->parameter_block_version;
1525 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1527 *dptr1++ = *dptr2++;
1529 /* Copy 2nd half. */
1530 dptr1 = (uint8_t *)icb->add_firmware_options;
1531 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1533 *dptr1++ = *dptr2++;
1535 /* Prepare nodename */
1536 if ((icb->firmware_options[1] & BIT_6) == 0) {
1538 * Firmware will apply the following mask if the nodename was
1541 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1542 icb->node_name[0] &= 0xF0;
1546 * Set host adapter parameters.
1548 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1549 /* Always load RISC code on non ISP2[12]00 chips. */
1550 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1551 ha->flags.disable_risc_code_load = 0;
1552 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1553 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1554 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1555 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1557 ha->operating_mode =
1558 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1560 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1561 sizeof(ha->fw_seriallink_options));
1563 /* save HBA serial number */
1564 ha->serial0 = icb->port_name[5];
1565 ha->serial1 = icb->port_name[6];
1566 ha->serial2 = icb->port_name[7];
1567 ha->node_name = icb->node_name;
1568 ha->port_name = icb->port_name;
1570 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1572 ha->retry_count = nv->retry_count;
1574 /* Set minimum login_timeout to 4 seconds. */
1575 if (nv->login_timeout < ql2xlogintimeout)
1576 nv->login_timeout = ql2xlogintimeout;
1577 if (nv->login_timeout < 4)
1578 nv->login_timeout = 4;
1579 ha->login_timeout = nv->login_timeout;
1580 icb->login_timeout = nv->login_timeout;
1582 /* Set minimum RATOV to 200 tenths of a second. */
1585 ha->loop_reset_delay = nv->reset_delay;
1587 /* Link Down Timeout = 0:
1589 * When Port Down timer expires we will start returning
1590 * I/O's to OS with "DID_NO_CONNECT".
1592 * Link Down Timeout != 0:
1594 * The driver waits for the link to come up after link down
1595 * before returning I/Os to OS with "DID_NO_CONNECT".
1597 if (nv->link_down_timeout == 0) {
1598 ha->loop_down_abort_time =
1599 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1601 ha->link_down_timeout = nv->link_down_timeout;
1602 ha->loop_down_abort_time =
1603 (LOOP_DOWN_TIME - ha->link_down_timeout);
1607 * Need enough time to try and get the port back.
1609 ha->port_down_retry_count = nv->port_down_retry_count;
1610 if (qlport_down_retry)
1611 ha->port_down_retry_count = qlport_down_retry;
1612 /* Set login_retry_count */
1613 ha->login_retry_count = nv->retry_count;
1614 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1615 ha->port_down_retry_count > 3)
1616 ha->login_retry_count = ha->port_down_retry_count;
1617 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1618 ha->login_retry_count = ha->port_down_retry_count;
1619 if (ql2xloginretrycount)
1620 ha->login_retry_count = ql2xloginretrycount;
1622 icb->lun_enables = __constant_cpu_to_le16(0);
1623 icb->command_resource_count = 0;
1624 icb->immediate_notify_resource_count = 0;
1625 icb->timeout = __constant_cpu_to_le16(0);
1627 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1629 icb->firmware_options[0] &= ~BIT_3;
1630 icb->add_firmware_options[0] &=
1631 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1632 icb->add_firmware_options[0] |= BIT_2;
1633 icb->response_accumulation_timer = 3;
1634 icb->interrupt_delay_timer = 5;
1636 ha->flags.process_response_queue = 1;
1639 if (!ha->flags.init_done) {
1640 ha->zio_mode = icb->add_firmware_options[0] &
1641 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1642 ha->zio_timer = icb->interrupt_delay_timer ?
1643 icb->interrupt_delay_timer: 2;
1645 icb->add_firmware_options[0] &=
1646 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1647 ha->flags.process_response_queue = 0;
1648 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1649 ha->zio_mode = QLA_ZIO_MODE_6;
1651 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1652 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1653 ha->zio_timer * 100));
1654 qla_printk(KERN_INFO, ha,
1655 "ZIO mode %d enabled; timer delay (%d us).\n",
1656 ha->zio_mode, ha->zio_timer * 100);
1658 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1659 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1660 ha->flags.process_response_queue = 1;
1665 DEBUG2_3(printk(KERN_WARNING
1666 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1672 qla2x00_rport_add(void *data)
1674 fc_port_t *fcport = data;
1676 qla2x00_reg_remote_port(fcport->ha, fcport);
1680 qla2x00_rport_del(void *data)
1682 fc_port_t *fcport = data;
1683 struct fc_rport *rport;
1684 unsigned long flags;
1686 spin_lock_irqsave(&fcport->rport_lock, flags);
1687 rport = fcport->drport;
1688 fcport->drport = NULL;
1689 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1691 fc_remote_port_delete(rport);
1696 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1698 * @flags: allocation flags
1700 * Returns a pointer to the allocated fcport, or NULL, if none available.
1703 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1707 fcport = kmalloc(sizeof(fc_port_t), flags);
1711 /* Setup fcport template structure. */
1712 memset(fcport, 0, sizeof (fc_port_t));
1714 fcport->port_type = FCT_UNKNOWN;
1715 fcport->loop_id = FC_NO_LOOP_ID;
1716 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1717 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1718 fcport->flags = FCF_RLC_SUPPORT;
1719 fcport->supported_classes = FC_COS_UNSPECIFIED;
1720 spin_lock_init(&fcport->rport_lock);
1721 INIT_WORK(&fcport->rport_add_work, qla2x00_rport_add, fcport);
1722 INIT_WORK(&fcport->rport_del_work, qla2x00_rport_del, fcport);
1728 * qla2x00_configure_loop
1729 * Updates Fibre Channel Device Database with what is actually on loop.
1732 * ha = adapter block pointer.
1737 * 2 = database was full and device was not configured.
1740 qla2x00_configure_loop(scsi_qla_host_t *ha)
1743 unsigned long flags, save_flags;
1747 /* Get Initiator ID */
1748 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1749 rval = qla2x00_configure_hba(ha);
1750 if (rval != QLA_SUCCESS) {
1751 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1757 save_flags = flags = ha->dpc_flags;
1758 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1759 ha->host_no, flags));
1762 * If we have both an RSCN and PORT UPDATE pending then handle them
1763 * both at the same time.
1765 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1766 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1768 /* Determine what we need to do */
1769 if (ha->current_topology == ISP_CFG_FL &&
1770 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1772 ha->flags.rscn_queue_overflow = 1;
1773 set_bit(RSCN_UPDATE, &flags);
1775 } else if (ha->current_topology == ISP_CFG_F &&
1776 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1778 ha->flags.rscn_queue_overflow = 1;
1779 set_bit(RSCN_UPDATE, &flags);
1780 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1782 } else if (!ha->flags.online ||
1783 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1785 ha->flags.rscn_queue_overflow = 1;
1786 set_bit(RSCN_UPDATE, &flags);
1787 set_bit(LOCAL_LOOP_UPDATE, &flags);
1790 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1791 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1792 rval = QLA_FUNCTION_FAILED;
1794 rval = qla2x00_configure_local_loop(ha);
1798 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1799 if (LOOP_TRANSITION(ha)) {
1800 rval = QLA_FUNCTION_FAILED;
1802 rval = qla2x00_configure_fabric(ha);
1806 if (rval == QLA_SUCCESS) {
1807 if (atomic_read(&ha->loop_down_timer) ||
1808 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1809 rval = QLA_FUNCTION_FAILED;
1811 atomic_set(&ha->loop_state, LOOP_READY);
1813 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1818 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1819 __func__, ha->host_no));
1821 DEBUG3(printk("%s: exiting normally\n", __func__));
1824 /* Restore state if a resync event occured during processing */
1825 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1826 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1827 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1828 if (test_bit(RSCN_UPDATE, &save_flags))
1829 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1838 * qla2x00_configure_local_loop
1839 * Updates Fibre Channel Device Database with local loop devices.
1842 * ha = adapter block pointer.
1848 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1853 fc_port_t *fcport, *new_fcport;
1859 uint8_t domain, area, al_pa;
1863 entries = MAX_FIBRE_DEVICES;
1865 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1866 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1868 /* Get list of logged in devices. */
1869 memset(ha->gid_list, 0, GID_LIST_SIZE);
1870 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1872 if (rval != QLA_SUCCESS)
1873 goto cleanup_allocation;
1875 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1876 ha->host_no, entries));
1877 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1878 entries * sizeof(struct gid_list_info)));
1880 /* Allocate temporary fcport for any new fcports discovered. */
1881 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1882 if (new_fcport == NULL) {
1883 rval = QLA_MEMORY_ALLOC_FAILED;
1884 goto cleanup_allocation;
1886 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1889 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1891 list_for_each_entry(fcport, &ha->fcports, list) {
1892 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1893 fcport->port_type != FCT_BROADCAST &&
1894 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1896 DEBUG(printk("scsi(%ld): Marking port lost, "
1898 ha->host_no, fcport->loop_id));
1900 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1901 fcport->flags &= ~FCF_FARP_DONE;
1905 /* Add devices to port list. */
1906 id_iter = (char *)ha->gid_list;
1907 for (index = 0; index < entries; index++) {
1908 domain = ((struct gid_list_info *)id_iter)->domain;
1909 area = ((struct gid_list_info *)id_iter)->area;
1910 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1911 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1912 loop_id = (uint16_t)
1913 ((struct gid_list_info *)id_iter)->loop_id_2100;
1915 loop_id = le16_to_cpu(
1916 ((struct gid_list_info *)id_iter)->loop_id);
1917 id_iter += ha->gid_list_info_size;
1919 /* Bypass reserved domain fields. */
1920 if ((domain & 0xf0) == 0xf0)
1923 /* Bypass if not same domain and area of adapter. */
1924 if (area && domain &&
1925 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
1928 /* Bypass invalid local loop ID. */
1929 if (loop_id > LAST_LOCAL_LOOP_ID)
1932 /* Fill in member data. */
1933 new_fcport->d_id.b.domain = domain;
1934 new_fcport->d_id.b.area = area;
1935 new_fcport->d_id.b.al_pa = al_pa;
1936 new_fcport->loop_id = loop_id;
1937 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1938 if (rval2 != QLA_SUCCESS) {
1939 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1940 "information -- get_port_database=%x, "
1942 ha->host_no, rval2, new_fcport->loop_id));
1943 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
1945 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
1949 /* Check for matching device in port list. */
1952 list_for_each_entry(fcport, &ha->fcports, list) {
1953 if (memcmp(new_fcport->port_name, fcport->port_name,
1957 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1958 FCF_PERSISTENT_BOUND);
1959 fcport->loop_id = new_fcport->loop_id;
1960 fcport->port_type = new_fcport->port_type;
1961 fcport->d_id.b24 = new_fcport->d_id.b24;
1962 memcpy(fcport->node_name, new_fcport->node_name,
1970 /* New device, add to fcports list. */
1971 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1972 list_add_tail(&new_fcport->list, &ha->fcports);
1974 /* Allocate a new replacement fcport. */
1975 fcport = new_fcport;
1976 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1977 if (new_fcport == NULL) {
1978 rval = QLA_MEMORY_ALLOC_FAILED;
1979 goto cleanup_allocation;
1981 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1984 qla2x00_update_fcport(ha, fcport);
1992 if (rval != QLA_SUCCESS) {
1993 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1994 "rval=%x\n", ha->host_no, rval));
1998 ha->device_flags |= DFLG_LOCAL_DEVICES;
1999 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2006 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
2010 qla2x00_mark_all_devices_lost(ha, 0);
2011 list_for_each_entry(fcport, &ha->fcports, list) {
2012 if (fcport->port_type != FCT_TARGET)
2015 qla2x00_update_fcport(ha, fcport);
2020 * qla2x00_update_fcport
2021 * Updates device on list.
2024 * ha = adapter block pointer.
2025 * fcport = port structure pointer.
2035 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2038 fcport->login_retry = 0;
2039 fcport->port_login_retry_count = ha->port_down_retry_count *
2041 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2043 fcport->flags &= ~FCF_LOGIN_NEEDED;
2045 if (fcport->port_type == FCT_INITIATOR ||
2046 fcport->port_type == FCT_BROADCAST)
2047 fcport->device_type = TYPE_PROCESSOR;
2049 atomic_set(&fcport->state, FCS_ONLINE);
2051 if (ha->flags.init_done)
2052 qla2x00_reg_remote_port(ha, fcport);
2056 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2058 struct fc_rport_identifiers rport_ids;
2059 struct fc_rport *rport;
2060 unsigned long flags;
2063 qla2x00_rport_del(fcport);
2067 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2068 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2069 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2070 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2071 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2072 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2074 qla_printk(KERN_WARNING, ha,
2075 "Unable to allocate fc remote port!\n");
2078 spin_lock_irqsave(&fcport->rport_lock, flags);
2079 fcport->rport = rport;
2080 *((fc_port_t **)rport->dd_data) = fcport;
2081 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2083 rport->supported_classes = fcport->supported_classes;
2085 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2086 if (fcport->port_type == FCT_INITIATOR)
2087 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2088 if (fcport->port_type == FCT_TARGET)
2089 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2090 fc_remote_port_rolechg(rport, rport_ids.roles);
2092 if (rport->scsi_target_id != -1 &&
2093 rport->scsi_target_id < ha->host->max_id)
2094 fcport->os_target_id = rport->scsi_target_id;
2098 * qla2x00_configure_fabric
2099 * Setup SNS devices with loop ID's.
2102 * ha = adapter block pointer.
2109 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2112 fc_port_t *fcport, *fcptemp;
2113 uint16_t next_loopid;
2114 uint16_t mb[MAILBOX_REGISTER_COUNT];
2116 LIST_HEAD(new_fcports);
2118 /* If FL port exists, then SNS is present */
2119 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2120 loop_id = NPH_F_PORT;
2122 loop_id = SNS_FL_PORT;
2123 rval = qla2x00_get_port_name(ha, loop_id, NULL, 0);
2124 if (rval != QLA_SUCCESS) {
2125 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2126 "Port\n", ha->host_no));
2128 ha->device_flags &= ~SWITCH_FOUND;
2129 return (QLA_SUCCESS);
2132 /* Mark devices that need re-synchronization. */
2133 rval2 = qla2x00_device_resync(ha);
2134 if (rval2 == QLA_RSCNS_HANDLED) {
2135 /* No point doing the scan, just continue. */
2136 return (QLA_SUCCESS);
2140 if (ql2xfdmienable &&
2141 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2142 qla2x00_fdmi_register(ha);
2144 /* Ensure we are logged into the SNS. */
2145 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2148 loop_id = SIMPLE_NAME_SERVER;
2149 ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
2150 0xfc, mb, BIT_1 | BIT_0);
2151 if (mb[0] != MBS_COMMAND_COMPLETE) {
2152 DEBUG2(qla_printk(KERN_INFO, ha,
2153 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2154 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2155 mb[0], mb[1], mb[2], mb[6], mb[7]));
2156 return (QLA_SUCCESS);
2159 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2160 if (qla2x00_rft_id(ha)) {
2162 DEBUG2(printk("scsi(%ld): Register FC-4 "
2163 "TYPE failed.\n", ha->host_no));
2165 if (qla2x00_rff_id(ha)) {
2167 DEBUG2(printk("scsi(%ld): Register FC-4 "
2168 "Features failed.\n", ha->host_no));
2170 if (qla2x00_rnn_id(ha)) {
2172 DEBUG2(printk("scsi(%ld): Register Node Name "
2173 "failed.\n", ha->host_no));
2174 } else if (qla2x00_rsnn_nn(ha)) {
2176 DEBUG2(printk("scsi(%ld): Register Symbolic "
2177 "Node Name failed.\n", ha->host_no));
2181 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2182 if (rval != QLA_SUCCESS)
2186 * Logout all previous fabric devices marked lost, except
2189 list_for_each_entry(fcport, &ha->fcports, list) {
2190 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2193 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2196 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2197 qla2x00_mark_device_lost(ha, fcport,
2198 ql2xplogiabsentdevice, 0);
2199 if (fcport->loop_id != FC_NO_LOOP_ID &&
2200 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2201 fcport->port_type != FCT_INITIATOR &&
2202 fcport->port_type != FCT_BROADCAST) {
2203 ha->isp_ops.fabric_logout(ha,
2205 fcport->d_id.b.domain,
2206 fcport->d_id.b.area,
2207 fcport->d_id.b.al_pa);
2208 fcport->loop_id = FC_NO_LOOP_ID;
2213 /* Starting free loop ID. */
2214 next_loopid = ha->min_external_loopid;
2217 * Scan through our port list and login entries that need to be
2220 list_for_each_entry(fcport, &ha->fcports, list) {
2221 if (atomic_read(&ha->loop_down_timer) ||
2222 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2225 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2226 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2229 if (fcport->loop_id == FC_NO_LOOP_ID) {
2230 fcport->loop_id = next_loopid;
2231 rval = qla2x00_find_new_loop_id(ha, fcport);
2232 if (rval != QLA_SUCCESS) {
2233 /* Ran out of IDs to use */
2237 /* Login and update database */
2238 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2241 /* Exit if out of loop IDs. */
2242 if (rval != QLA_SUCCESS) {
2247 * Login and add the new devices to our port list.
2249 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2250 if (atomic_read(&ha->loop_down_timer) ||
2251 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2254 /* Find a new loop ID to use. */
2255 fcport->loop_id = next_loopid;
2256 rval = qla2x00_find_new_loop_id(ha, fcport);
2257 if (rval != QLA_SUCCESS) {
2258 /* Ran out of IDs to use */
2262 /* Remove device from the new list and add it to DB */
2263 list_del(&fcport->list);
2264 list_add_tail(&fcport->list, &ha->fcports);
2266 /* Login and update database */
2267 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2271 /* Free all new device structures not processed. */
2272 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2273 list_del(&fcport->list);
2278 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2279 "rval=%d\n", ha->host_no, rval));
2287 * qla2x00_find_all_fabric_devs
2290 * ha = adapter block pointer.
2291 * dev = database device entry pointer.
2300 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2304 fc_port_t *fcport, *new_fcport, *fcptemp;
2309 int first_dev, last_dev;
2310 port_id_t wrap, nxt_d_id;
2314 /* Try GID_PT to get device list, else GAN. */
2315 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2318 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2319 "on GA_NXT\n", ha->host_no));
2321 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2322 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2325 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2328 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2335 /* Allocate temporary fcport for any new fcports discovered. */
2336 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2337 if (new_fcport == NULL) {
2339 return (QLA_MEMORY_ALLOC_FAILED);
2341 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2343 /* Set start port ID scan at adapter ID. */
2347 /* Starting free loop ID. */
2348 loop_id = ha->min_external_loopid;
2349 for (; loop_id <= ha->last_loop_id; loop_id++) {
2350 if (qla2x00_is_reserved_id(ha, loop_id))
2353 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2358 wrap.b24 = new_fcport->d_id.b24;
2360 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2361 memcpy(new_fcport->node_name,
2362 swl[swl_idx].node_name, WWN_SIZE);
2363 memcpy(new_fcport->port_name,
2364 swl[swl_idx].port_name, WWN_SIZE);
2366 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2372 /* Send GA_NXT to the switch */
2373 rval = qla2x00_ga_nxt(ha, new_fcport);
2374 if (rval != QLA_SUCCESS) {
2375 qla_printk(KERN_WARNING, ha,
2376 "SNS scan failed -- assuming zero-entry "
2378 list_for_each_entry_safe(fcport, fcptemp,
2379 new_fcports, list) {
2380 list_del(&fcport->list);
2388 /* If wrap on switch device list, exit. */
2390 wrap.b24 = new_fcport->d_id.b24;
2392 } else if (new_fcport->d_id.b24 == wrap.b24) {
2393 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2394 ha->host_no, new_fcport->d_id.b.domain,
2395 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2399 /* Bypass if host adapter. */
2400 if (new_fcport->d_id.b24 == ha->d_id.b24)
2403 /* Bypass if same domain and area of adapter. */
2404 if (((new_fcport->d_id.b24 & 0xffff00) ==
2405 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2409 /* Bypass reserved domain fields. */
2410 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2413 /* Locate matching device in database. */
2415 list_for_each_entry(fcport, &ha->fcports, list) {
2416 if (memcmp(new_fcport->port_name, fcport->port_name,
2423 * If address the same and state FCS_ONLINE, nothing
2426 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2427 atomic_read(&fcport->state) == FCS_ONLINE) {
2432 * If device was not a fabric device before.
2434 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2435 fcport->d_id.b24 = new_fcport->d_id.b24;
2436 fcport->loop_id = FC_NO_LOOP_ID;
2437 fcport->flags |= (FCF_FABRIC_DEVICE |
2439 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2444 * Port ID changed or device was marked to be updated;
2445 * Log it out if still logged in and mark it for
2448 fcport->d_id.b24 = new_fcport->d_id.b24;
2449 fcport->flags |= FCF_LOGIN_NEEDED;
2450 if (fcport->loop_id != FC_NO_LOOP_ID &&
2451 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2452 fcport->port_type != FCT_INITIATOR &&
2453 fcport->port_type != FCT_BROADCAST) {
2454 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2455 fcport->d_id.b.domain, fcport->d_id.b.area,
2456 fcport->d_id.b.al_pa);
2457 fcport->loop_id = FC_NO_LOOP_ID;
2466 /* If device was not in our fcports list, then add it. */
2467 list_add_tail(&new_fcport->list, new_fcports);
2469 /* Allocate a new replacement fcport. */
2470 nxt_d_id.b24 = new_fcport->d_id.b24;
2471 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2472 if (new_fcport == NULL) {
2474 return (QLA_MEMORY_ALLOC_FAILED);
2476 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2477 new_fcport->d_id.b24 = nxt_d_id.b24;
2483 if (!list_empty(new_fcports))
2484 ha->device_flags |= DFLG_FABRIC_DEVICES;
2490 * qla2x00_find_new_loop_id
2491 * Scan through our port list and find a new usable loop ID.
2494 * ha: adapter state pointer.
2495 * dev: port structure pointer.
2498 * qla2x00 local function return status code.
2504 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2509 uint16_t first_loop_id;
2513 /* Save starting loop ID. */
2514 first_loop_id = dev->loop_id;
2517 /* Skip loop ID if already used by adapter. */
2518 if (dev->loop_id == ha->loop_id) {
2522 /* Skip reserved loop IDs. */
2523 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2527 /* Reset loop ID if passed the end. */
2528 if (dev->loop_id > ha->last_loop_id) {
2529 /* first loop ID. */
2530 dev->loop_id = ha->min_external_loopid;
2533 /* Check for loop ID being already in use. */
2536 list_for_each_entry(fcport, &ha->fcports, list) {
2537 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2538 /* ID possibly in use */
2544 /* If not in use then it is free to use. */
2549 /* ID in use. Try next value. */
2552 /* If wrap around. No free ID to use. */
2553 if (dev->loop_id == first_loop_id) {
2554 dev->loop_id = FC_NO_LOOP_ID;
2555 rval = QLA_FUNCTION_FAILED;
2564 * qla2x00_device_resync
2565 * Marks devices in the database that needs resynchronization.
2568 * ha = adapter block pointer.
2574 qla2x00_device_resync(scsi_qla_host_t *ha)
2580 uint32_t rscn_entry;
2581 uint8_t rscn_out_iter;
2585 rval = QLA_RSCNS_HANDLED;
2587 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2588 ha->flags.rscn_queue_overflow) {
2590 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2591 format = MSB(MSW(rscn_entry));
2592 d_id.b.domain = LSB(MSW(rscn_entry));
2593 d_id.b.area = MSB(LSW(rscn_entry));
2594 d_id.b.al_pa = LSB(LSW(rscn_entry));
2596 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2597 "[%02x/%02x%02x%02x].\n",
2598 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2599 d_id.b.area, d_id.b.al_pa));
2602 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2603 ha->rscn_out_ptr = 0;
2605 /* Skip duplicate entries. */
2606 for (rscn_out_iter = ha->rscn_out_ptr;
2607 !ha->flags.rscn_queue_overflow &&
2608 rscn_out_iter != ha->rscn_in_ptr;
2609 rscn_out_iter = (rscn_out_iter ==
2610 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2612 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2615 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2616 "entry found at [%d].\n", ha->host_no,
2619 ha->rscn_out_ptr = rscn_out_iter;
2622 /* Queue overflow, set switch default case. */
2623 if (ha->flags.rscn_queue_overflow) {
2624 DEBUG(printk("scsi(%ld): device_resync: rscn "
2625 "overflow.\n", ha->host_no));
2628 ha->flags.rscn_queue_overflow = 0;
2633 if (ql2xprocessrscn &&
2634 !IS_QLA2100(ha) && !IS_QLA2200(ha) &&
2635 !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
2636 !IS_QLA24XX(ha) && !IS_QLA54XX(ha) &&
2637 ha->flags.init_done) {
2638 /* Handle port RSCN via asyncronous IOCBs */
2639 rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
2641 if (rval2 == QLA_SUCCESS)
2655 ha->rscn_out_ptr = ha->rscn_in_ptr;
2661 /* Abort any outstanding IO descriptors. */
2662 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2663 qla2x00_cancel_io_descriptors(ha);
2665 list_for_each_entry(fcport, &ha->fcports, list) {
2666 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2667 (fcport->d_id.b24 & mask) != d_id.b24 ||
2668 fcport->port_type == FCT_BROADCAST)
2671 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2673 fcport->port_type != FCT_INITIATOR) {
2674 qla2x00_mark_device_lost(ha, fcport,
2678 fcport->flags &= ~FCF_FARP_DONE;
2685 * qla2x00_fabric_dev_login
2686 * Login fabric target device and update FC port database.
2689 * ha: adapter state pointer.
2690 * fcport: port structure list pointer.
2691 * next_loopid: contains value of a new loop ID that can be used
2692 * by the next login attempt.
2695 * qla2x00 local function return status code.
2701 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2702 uint16_t *next_loopid)
2711 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2712 if (rval == QLA_SUCCESS) {
2713 /* Send an ADISC to tape devices.*/
2715 if (fcport->flags & FCF_TAPE_PRESENT)
2717 rval = qla2x00_get_port_database(ha, fcport, opts);
2718 if (rval != QLA_SUCCESS) {
2719 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2720 fcport->d_id.b.domain, fcport->d_id.b.area,
2721 fcport->d_id.b.al_pa);
2722 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2724 qla2x00_update_fcport(ha, fcport);
2732 * qla2x00_fabric_login
2733 * Issue fabric login command.
2736 * ha = adapter block pointer.
2737 * device = pointer to FC device type structure.
2740 * 0 - Login successfully
2742 * 2 - Initiator device
2746 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2747 uint16_t *next_loopid)
2751 uint16_t tmp_loopid;
2752 uint16_t mb[MAILBOX_REGISTER_COUNT];
2758 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2759 "for port %02x%02x%02x.\n",
2760 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2761 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2763 /* Login fcport on switch. */
2764 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2765 fcport->d_id.b.domain, fcport->d_id.b.area,
2766 fcport->d_id.b.al_pa, mb, BIT_0);
2767 if (mb[0] == MBS_PORT_ID_USED) {
2769 * Device has another loop ID. The firmware team
2770 * recommends the driver perform an implicit login with
2771 * the specified ID again. The ID we just used is save
2772 * here so we return with an ID that can be tried by
2776 tmp_loopid = fcport->loop_id;
2777 fcport->loop_id = mb[1];
2779 DEBUG(printk("Fabric Login: port in use - next "
2780 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2781 fcport->loop_id, fcport->d_id.b.domain,
2782 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2784 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2789 /* A retry occurred before. */
2790 *next_loopid = tmp_loopid;
2793 * No retry occurred before. Just increment the
2794 * ID value for next login.
2796 *next_loopid = (fcport->loop_id + 1);
2799 if (mb[1] & BIT_0) {
2800 fcport->port_type = FCT_INITIATOR;
2802 fcport->port_type = FCT_TARGET;
2803 if (mb[1] & BIT_1) {
2804 fcport->flags |= FCF_TAPE_PRESENT;
2809 fcport->supported_classes |= FC_COS_CLASS2;
2811 fcport->supported_classes |= FC_COS_CLASS3;
2815 } else if (mb[0] == MBS_LOOP_ID_USED) {
2817 * Loop ID already used, try next loop ID.
2820 rval = qla2x00_find_new_loop_id(ha, fcport);
2821 if (rval != QLA_SUCCESS) {
2822 /* Ran out of loop IDs to use */
2825 } else if (mb[0] == MBS_COMMAND_ERROR) {
2827 * Firmware possibly timed out during login. If NO
2828 * retries are left to do then the device is declared
2831 *next_loopid = fcport->loop_id;
2832 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2833 fcport->d_id.b.domain, fcport->d_id.b.area,
2834 fcport->d_id.b.al_pa);
2835 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2841 * unrecoverable / not handled error
2843 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2844 "loop_id=%x jiffies=%lx.\n",
2845 __func__, ha->host_no, mb[0],
2846 fcport->d_id.b.domain, fcport->d_id.b.area,
2847 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2849 *next_loopid = fcport->loop_id;
2850 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2851 fcport->d_id.b.domain, fcport->d_id.b.area,
2852 fcport->d_id.b.al_pa);
2853 fcport->loop_id = FC_NO_LOOP_ID;
2854 fcport->login_retry = 0;
2865 * qla2x00_local_device_login
2866 * Issue local device login command.
2869 * ha = adapter block pointer.
2870 * loop_id = loop id of device to login to.
2872 * Returns (Where's the #define!!!!):
2873 * 0 - Login successfully
2878 qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
2881 uint16_t mb[MAILBOX_REGISTER_COUNT];
2883 memset(mb, 0, sizeof(mb));
2884 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
2885 if (rval == QLA_SUCCESS) {
2886 /* Interrogate mailbox registers for any errors */
2887 if (mb[0] == MBS_COMMAND_ERROR)
2889 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
2890 /* device not in PCB table */
2898 * qla2x00_loop_resync
2899 * Resync with fibre channel devices.
2902 * ha = adapter block pointer.
2908 qla2x00_loop_resync(scsi_qla_host_t *ha)
2915 atomic_set(&ha->loop_state, LOOP_UPDATE);
2916 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2917 if (ha->flags.online) {
2918 if (!(rval = qla2x00_fw_ready(ha))) {
2919 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2922 atomic_set(&ha->loop_state, LOOP_UPDATE);
2924 /* Issue a marker after FW becomes ready. */
2925 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
2926 ha->marker_needed = 0;
2928 /* Remap devices on Loop. */
2929 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2931 qla2x00_configure_loop(ha);
2933 } while (!atomic_read(&ha->loop_down_timer) &&
2934 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
2936 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
2940 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2941 return (QLA_FUNCTION_FAILED);
2945 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
2952 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
2958 list_for_each_entry(fcport, &ha->fcports, list) {
2959 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
2962 qla2x00_update_fcport(ha, fcport);
2963 fcport->flags &= ~FCF_RESCAN_NEEDED;
2967 qla2x00_probe_for_all_luns(ha);
2971 qla2x00_update_fcports(scsi_qla_host_t *ha)
2975 /* Go with deferred removal of rport references. */
2976 list_for_each_entry(fcport, &ha->fcports, list)
2978 qla2x00_rport_del(fcport);
2983 * Resets ISP and aborts all outstanding commands.
2986 * ha = adapter block pointer.
2992 qla2x00_abort_isp(scsi_qla_host_t *ha)
2994 unsigned long flags = 0;
2999 if (ha->flags.online) {
3000 ha->flags.online = 0;
3001 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3003 qla_printk(KERN_INFO, ha,
3004 "Performing ISP error recovery - ha= %p.\n", ha);
3005 ha->isp_ops.reset_chip(ha);
3007 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3008 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3009 atomic_set(&ha->loop_state, LOOP_DOWN);
3010 qla2x00_mark_all_devices_lost(ha, 0);
3012 if (!atomic_read(&ha->loop_down_timer))
3013 atomic_set(&ha->loop_down_timer,
3017 spin_lock_irqsave(&ha->hardware_lock, flags);
3018 /* Requeue all commands in outstanding command list. */
3019 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3020 sp = ha->outstanding_cmds[cnt];
3022 ha->outstanding_cmds[cnt] = NULL;
3024 sp->cmd->result = DID_RESET << 16;
3025 sp->cmd->host_scribble = (unsigned char *)NULL;
3026 qla2x00_sp_compl(ha, sp);
3029 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3031 ha->isp_ops.nvram_config(ha);
3033 if (!qla2x00_restart_isp(ha)) {
3034 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3036 if (!atomic_read(&ha->loop_down_timer)) {
3038 * Issue marker command only when we are going
3039 * to start the I/O .
3041 ha->marker_needed = 1;
3044 ha->flags.online = 1;
3046 ha->isp_ops.enable_intrs(ha);
3048 ha->isp_abort_cnt = 0;
3049 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3050 } else { /* failed the ISP abort */
3051 ha->flags.online = 1;
3052 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3053 if (ha->isp_abort_cnt == 0) {
3054 qla_printk(KERN_WARNING, ha,
3055 "ISP error recovery failed - "
3056 "board disabled\n");
3058 * The next call disables the board
3061 ha->isp_ops.reset_adapter(ha);
3062 ha->flags.online = 0;
3063 clear_bit(ISP_ABORT_RETRY,
3066 } else { /* schedule another ISP abort */
3067 ha->isp_abort_cnt--;
3068 DEBUG(printk("qla%ld: ISP abort - "
3069 "retry remaining %d\n",
3070 ha->host_no, ha->isp_abort_cnt);)
3074 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3075 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3076 "- retrying (%d) more times\n",
3077 ha->host_no, ha->isp_abort_cnt);)
3078 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3086 qla_printk(KERN_INFO, ha,
3087 "qla2x00_abort_isp: **** FAILED ****\n");
3089 DEBUG(printk(KERN_INFO
3090 "qla2x00_abort_isp(%ld): exiting.\n",
3098 * qla2x00_restart_isp
3099 * restarts the ISP after a reset
3102 * ha = adapter block pointer.
3108 qla2x00_restart_isp(scsi_qla_host_t *ha)
3111 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3112 unsigned long flags = 0;
3115 /* If firmware needs to be loaded */
3116 if (qla2x00_isp_firmware(ha)) {
3117 ha->flags.online = 0;
3118 if (!(status = ha->isp_ops.chip_diag(ha))) {
3119 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3120 status = qla2x00_setup_chip(ha);
3124 spin_lock_irqsave(&ha->hardware_lock, flags);
3126 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3128 * Disable SRAM, Instruction RAM and GP RAM
3131 WRT_REG_WORD(®->hccr,
3132 (HCCR_ENABLE_PARITY + 0x0));
3133 RD_REG_WORD(®->hccr);
3136 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3138 status = qla2x00_setup_chip(ha);
3140 spin_lock_irqsave(&ha->hardware_lock, flags);
3142 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3143 /* Enable proper parity */
3146 WRT_REG_WORD(®->hccr,
3147 (HCCR_ENABLE_PARITY + 0x1));
3150 * SRAM, Instruction RAM and GP RAM
3153 WRT_REG_WORD(®->hccr,
3154 (HCCR_ENABLE_PARITY + 0x7));
3155 RD_REG_WORD(®->hccr);
3158 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3163 if (!status && !(status = qla2x00_init_rings(ha))) {
3164 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3165 if (!(status = qla2x00_fw_ready(ha))) {
3166 DEBUG(printk("%s(): Start configure loop, "
3167 "status = %d\n", __func__, status);)
3169 /* Issue a marker after FW becomes ready. */
3170 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3172 ha->flags.online = 1;
3173 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3176 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3177 qla2x00_configure_loop(ha);
3179 } while (!atomic_read(&ha->loop_down_timer) &&
3180 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3182 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3185 /* if no cable then assume it's good */
3186 if ((ha->device_flags & DFLG_NO_CABLE))
3189 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3197 * qla2x00_reset_adapter
3201 * ha = adapter block pointer.
3204 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3206 unsigned long flags = 0;
3207 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3209 ha->flags.online = 0;
3210 ha->isp_ops.disable_intrs(ha);
3212 spin_lock_irqsave(&ha->hardware_lock, flags);
3213 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3214 RD_REG_WORD(®->hccr); /* PCI Posting. */
3215 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3216 RD_REG_WORD(®->hccr); /* PCI Posting. */
3217 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3221 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3223 unsigned long flags = 0;
3224 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3226 ha->flags.online = 0;
3227 ha->isp_ops.disable_intrs(ha);
3229 spin_lock_irqsave(&ha->hardware_lock, flags);
3230 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3231 RD_REG_DWORD(®->hccr);
3232 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3233 RD_REG_DWORD(®->hccr);
3234 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3238 qla24xx_nvram_config(scsi_qla_host_t *ha)
3241 struct init_cb_24xx *icb;
3242 struct nvram_24xx *nv;
3244 uint8_t *dptr1, *dptr2;
3249 icb = (struct init_cb_24xx *)ha->init_cb;
3250 nv = (struct nvram_24xx *)ha->request_ring;
3252 /* Determine NVRAM starting address. */
3253 ha->nvram_size = sizeof(struct nvram_24xx);
3254 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3255 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3256 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3257 if (PCI_FUNC(ha->pdev->devfn)) {
3258 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3259 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3262 /* Get NVRAM data and calculate checksum. */
3263 dptr = (uint32_t *)nv;
3264 ha->isp_ops.read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3266 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3267 chksum += le32_to_cpu(*dptr++);
3269 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3270 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3273 /* Bad NVRAM data, set defaults parameters. */
3274 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3275 || nv->id[3] != ' ' ||
3276 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3277 /* Reset NVRAM data. */
3278 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3279 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3280 le16_to_cpu(nv->nvram_version));
3281 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3282 "invalid -- WWPN) defaults.\n");
3285 * Set default initialization control block.
3287 memset(nv, 0, ha->nvram_size);
3288 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3289 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3290 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3291 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3292 nv->exchange_count = __constant_cpu_to_le16(0);
3293 nv->hard_address = __constant_cpu_to_le16(124);
3294 nv->port_name[0] = 0x21;
3295 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3296 nv->port_name[2] = 0x00;
3297 nv->port_name[3] = 0xe0;
3298 nv->port_name[4] = 0x8b;
3299 nv->port_name[5] = 0x1c;
3300 nv->port_name[6] = 0x55;
3301 nv->port_name[7] = 0x86;
3302 nv->node_name[0] = 0x20;
3303 nv->node_name[1] = 0x00;
3304 nv->node_name[2] = 0x00;
3305 nv->node_name[3] = 0xe0;
3306 nv->node_name[4] = 0x8b;
3307 nv->node_name[5] = 0x1c;
3308 nv->node_name[6] = 0x55;
3309 nv->node_name[7] = 0x86;
3310 nv->login_retry_count = __constant_cpu_to_le16(8);
3311 nv->link_down_timeout = __constant_cpu_to_le16(200);
3312 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3313 nv->login_timeout = __constant_cpu_to_le16(0);
3314 nv->firmware_options_1 =
3315 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3316 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3317 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3318 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3319 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3320 nv->efi_parameters = __constant_cpu_to_le32(0);
3321 nv->reset_delay = 5;
3322 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3323 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3324 nv->link_down_timeout = __constant_cpu_to_le16(30);
3329 /* Reset Initialization control block */
3330 memset(icb, 0, sizeof(struct init_cb_24xx));
3332 /* Copy 1st segment. */
3333 dptr1 = (uint8_t *)icb;
3334 dptr2 = (uint8_t *)&nv->version;
3335 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3337 *dptr1++ = *dptr2++;
3339 icb->login_retry_count = nv->login_retry_count;
3340 icb->link_down_timeout = nv->link_down_timeout;
3342 /* Copy 2nd segment. */
3343 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3344 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3345 cnt = (uint8_t *)&icb->reserved_3 -
3346 (uint8_t *)&icb->interrupt_delay_timer;
3348 *dptr1++ = *dptr2++;
3351 * Setup driver NVRAM options.
3353 if (memcmp(nv->model_name, BINZERO, sizeof(nv->model_name)) != 0) {
3357 strncpy(ha->model_number, nv->model_name,
3358 sizeof(nv->model_name));
3359 st = en = ha->model_number;
3360 en += sizeof(nv->model_name) - 1;
3362 if (*en != 0x20 && *en != 0x00)
3367 index = (ha->pdev->subsystem_device & 0xff);
3368 if (index < QLA_MODEL_NAMES)
3369 ha->model_desc = qla2x00_model_name[index * 2 + 1];
3371 strcpy(ha->model_number, "QLA2462");
3373 /* Prepare nodename */
3374 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3376 * Firmware will apply the following mask if the nodename was
3379 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3380 icb->node_name[0] &= 0xF0;
3383 /* Set host adapter parameters. */
3384 ha->flags.disable_risc_code_load = 0;
3385 ha->flags.enable_lip_reset = 1;
3386 ha->flags.enable_lip_full_login = 1;
3387 ha->flags.enable_target_reset = 1;
3388 ha->flags.enable_led_scheme = 0;
3390 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3391 (BIT_6 | BIT_5 | BIT_4)) >> 4;
3393 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3394 sizeof(ha->fw_seriallink_options24));
3396 /* save HBA serial number */
3397 ha->serial0 = icb->port_name[5];
3398 ha->serial1 = icb->port_name[6];
3399 ha->serial2 = icb->port_name[7];
3400 ha->node_name = icb->node_name;
3401 ha->port_name = icb->port_name;
3403 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3405 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3407 /* Set minimum login_timeout to 4 seconds. */
3408 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3409 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3410 if (le16_to_cpu(nv->login_timeout) < 4)
3411 nv->login_timeout = __constant_cpu_to_le16(4);
3412 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3413 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3415 /* Set minimum RATOV to 200 tenths of a second. */
3418 ha->loop_reset_delay = nv->reset_delay;
3420 /* Link Down Timeout = 0:
3422 * When Port Down timer expires we will start returning
3423 * I/O's to OS with "DID_NO_CONNECT".
3425 * Link Down Timeout != 0:
3427 * The driver waits for the link to come up after link down
3428 * before returning I/Os to OS with "DID_NO_CONNECT".
3430 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3431 ha->loop_down_abort_time =
3432 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3434 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3435 ha->loop_down_abort_time =
3436 (LOOP_DOWN_TIME - ha->link_down_timeout);
3439 /* Need enough time to try and get the port back. */
3440 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3441 if (qlport_down_retry)
3442 ha->port_down_retry_count = qlport_down_retry;
3444 /* Set login_retry_count */
3445 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3446 if (ha->port_down_retry_count ==
3447 le16_to_cpu(nv->port_down_retry_count) &&
3448 ha->port_down_retry_count > 3)
3449 ha->login_retry_count = ha->port_down_retry_count;
3450 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3451 ha->login_retry_count = ha->port_down_retry_count;
3452 if (ql2xloginretrycount)
3453 ha->login_retry_count = ql2xloginretrycount;
3456 if (!ha->flags.init_done) {
3457 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3458 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3459 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3460 le16_to_cpu(icb->interrupt_delay_timer): 2;
3462 icb->firmware_options_2 &= __constant_cpu_to_le32(
3463 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3464 ha->flags.process_response_queue = 0;
3465 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3466 ha->zio_mode = QLA_ZIO_MODE_6;
3468 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3469 "(%d us).\n", ha->host_no, ha->zio_mode,
3470 ha->zio_timer * 100));
3471 qla_printk(KERN_INFO, ha,
3472 "ZIO mode %d enabled; timer delay (%d us).\n",
3473 ha->zio_mode, ha->zio_timer * 100);
3475 icb->firmware_options_2 |= cpu_to_le32(
3476 (uint32_t)ha->zio_mode);
3477 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3478 ha->flags.process_response_queue = 1;
3482 DEBUG2_3(printk(KERN_WARNING
3483 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3489 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3492 int segments, fragment;
3494 uint32_t *dcode, dlen;
3501 segments = FA_RISC_CODE_SEGMENTS;
3502 faddr = FA_RISC_CODE_ADDR;
3503 dcode = (uint32_t *)ha->request_ring;
3506 /* Validate firmware image by checking version. */
3507 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3508 for (i = 0; i < 4; i++)
3509 dcode[i] = be32_to_cpu(dcode[i]);
3510 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3511 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3512 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3514 qla_printk(KERN_WARNING, ha,
3515 "Unable to verify integrity of flash firmware image!\n");
3516 qla_printk(KERN_WARNING, ha,
3517 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3518 dcode[1], dcode[2], dcode[3]);
3520 return QLA_FUNCTION_FAILED;
3523 while (segments && rval == QLA_SUCCESS) {
3524 /* Read segment's load information. */
3525 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3527 risc_addr = be32_to_cpu(dcode[2]);
3528 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3529 risc_size = be32_to_cpu(dcode[3]);
3532 while (risc_size > 0 && rval == QLA_SUCCESS) {
3533 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3534 if (dlen > risc_size)
3537 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3538 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3539 ha->host_no, risc_addr, dlen, faddr));
3541 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3542 for (i = 0; i < dlen; i++)
3543 dcode[i] = swab32(dcode[i]);
3545 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3548 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3549 "segment %d of firmware\n", ha->host_no,
3551 qla_printk(KERN_WARNING, ha,
3552 "[ERROR] Failed to load segment %d of "
3553 "firmware\n", fragment);
3570 #if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
3573 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3577 uint16_t *risc_code;
3578 uint32_t risc_addr, risc_size;
3580 struct qla_fw_info *fw_iter;
3584 /* Load firmware sequences */
3585 fw_iter = ha->brd_info->fw_info;
3586 *srisc_addr = *ha->brd_info->fw_info->fwstart;
3587 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
3588 risc_code = fw_iter->fwcode;
3589 risc_size = *fw_iter->fwlen;
3590 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL)
3591 risc_addr = *fw_iter->fwstart;
3593 risc_addr = *fw_iter->lfwstart;
3597 while (risc_size > 0 && !rval) {
3598 cnt = (uint16_t)(ha->fw_transfer_size >> 1);
3599 if (cnt > risc_size)
3602 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
3603 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
3604 ha->host_no, risc_code, cnt, risc_addr));
3606 req_ring = (uint16_t *)ha->request_ring;
3607 for (i = 0; i < cnt; i++)
3608 req_ring[i] = cpu_to_le16(risc_code[i]);
3610 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3613 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
3614 "load segment %d of firmware\n",
3616 qla_printk(KERN_WARNING, ha,
3617 "[ERROR] Failed to load segment %d of "
3620 qla2x00_dump_regs(ha);
3630 /* Next firmware sequence */
3637 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3641 uint32_t *risc_code;
3642 uint32_t risc_addr, risc_size;
3644 struct qla_fw_info *fw_iter;
3648 /* Load firmware sequences */
3649 fw_iter = ha->brd_info->fw_info;
3650 *srisc_addr = *((uint32_t *)fw_iter->lfwstart);
3651 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
3652 risc_code = (uint32_t *)fw_iter->fwcode;
3653 risc_size = *((uint32_t *)fw_iter->fwlen);
3654 risc_addr = *((uint32_t *)fw_iter->lfwstart);
3658 while (risc_size > 0 && !rval) {
3659 cnt = (uint32_t)(ha->fw_transfer_size >> 2);
3660 if (cnt > risc_size)
3663 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
3664 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
3665 ha->host_no, risc_code, cnt, risc_addr));
3667 req_ring = (uint32_t *)ha->request_ring;
3668 for (i = 0; i < cnt; i++)
3669 req_ring[i] = cpu_to_le32(risc_code[i]);
3671 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3674 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
3675 "load segment %d of firmware\n",
3677 qla_printk(KERN_WARNING, ha,
3678 "[ERROR] Failed to load segment %d of "
3681 qla2x00_dump_regs(ha);
3691 /* Next firmware sequence */
3697 #else /* !defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE) */
3699 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3702 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3706 uint16_t *wcode, *fwcode;
3707 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3708 struct fw_blob *blob;
3710 /* Load firmware blob. */
3711 blob = qla2x00_request_firmware(ha);
3713 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3714 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3715 "from: " QLA_FW_URL ".\n");
3716 return QLA_FUNCTION_FAILED;
3721 wcode = (uint16_t *)ha->request_ring;
3723 fwcode = (uint16_t *)blob->fw->data;
3726 /* Validate firmware image by checking version. */
3727 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3728 qla_printk(KERN_WARNING, ha,
3729 "Unable to verify integrity of firmware image (%Zd)!\n",
3731 goto fail_fw_integrity;
3733 for (i = 0; i < 4; i++)
3734 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3735 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3736 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3737 wcode[2] == 0 && wcode[3] == 0)) {
3738 qla_printk(KERN_WARNING, ha,
3739 "Unable to verify integrity of firmware image!\n");
3740 qla_printk(KERN_WARNING, ha,
3741 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3742 wcode[1], wcode[2], wcode[3]);
3743 goto fail_fw_integrity;
3747 while (*seg && rval == QLA_SUCCESS) {
3749 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3750 risc_size = be16_to_cpu(fwcode[3]);
3752 /* Validate firmware image size. */
3753 fwclen += risc_size * sizeof(uint16_t);
3754 if (blob->fw->size < fwclen) {
3755 qla_printk(KERN_WARNING, ha,
3756 "Unable to verify integrity of firmware image "
3757 "(%Zd)!\n", blob->fw->size);
3758 goto fail_fw_integrity;
3762 while (risc_size > 0 && rval == QLA_SUCCESS) {
3763 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3764 if (wlen > risc_size)
3767 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3768 "addr %x, number of words 0x%x.\n", ha->host_no,
3771 for (i = 0; i < wlen; i++)
3772 wcode[i] = swab16(fwcode[i]);
3774 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3777 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3778 "segment %d of firmware\n", ha->host_no,
3780 qla_printk(KERN_WARNING, ha,
3781 "[ERROR] Failed to load segment %d of "
3782 "firmware\n", fragment);
3798 return QLA_FUNCTION_FAILED;
3802 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3805 int segments, fragment;
3806 uint32_t *dcode, dlen;
3810 struct fw_blob *blob;
3811 uint32_t *fwcode, fwclen;
3813 /* Load firmware blob. */
3814 blob = qla2x00_request_firmware(ha);
3816 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3817 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3818 "from: " QLA_FW_URL ".\n");
3820 /* Try to load RISC code from flash. */
3821 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3822 "outdated) firmware from flash.\n");
3823 return qla24xx_load_risc_flash(ha, srisc_addr);
3828 segments = FA_RISC_CODE_SEGMENTS;
3829 dcode = (uint32_t *)ha->request_ring;
3831 fwcode = (uint32_t *)blob->fw->data;
3834 /* Validate firmware image by checking version. */
3835 if (blob->fw->size < 8 * sizeof(uint32_t)) {
3836 qla_printk(KERN_WARNING, ha,
3837 "Unable to verify integrity of firmware image (%Zd)!\n",
3839 goto fail_fw_integrity;
3841 for (i = 0; i < 4; i++)
3842 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3843 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3844 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3845 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3847 qla_printk(KERN_WARNING, ha,
3848 "Unable to verify integrity of firmware image!\n");
3849 qla_printk(KERN_WARNING, ha,
3850 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3851 dcode[1], dcode[2], dcode[3]);
3852 goto fail_fw_integrity;
3855 while (segments && rval == QLA_SUCCESS) {
3856 risc_addr = be32_to_cpu(fwcode[2]);
3857 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3858 risc_size = be32_to_cpu(fwcode[3]);
3860 /* Validate firmware image size. */
3861 fwclen += risc_size * sizeof(uint32_t);
3862 if (blob->fw->size < fwclen) {
3863 qla_printk(KERN_WARNING, ha,
3864 "Unable to verify integrity of firmware image "
3865 "(%Zd)!\n", blob->fw->size);
3867 goto fail_fw_integrity;
3871 while (risc_size > 0 && rval == QLA_SUCCESS) {
3872 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3873 if (dlen > risc_size)
3876 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3877 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3880 for (i = 0; i < dlen; i++)
3881 dcode[i] = swab32(fwcode[i]);
3883 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3886 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3887 "segment %d of firmware\n", ha->host_no,
3889 qla_printk(KERN_WARNING, ha,
3890 "[ERROR] Failed to load segment %d of "
3891 "firmware\n", fragment);
3907 return QLA_FUNCTION_FAILED;