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;
198 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
199 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
200 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
202 /* Reset expansion ROM address decode enable */
203 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
204 d &= ~PCI_ROM_ADDRESS_ENABLE;
205 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
207 /* Get PCI bus information. */
208 spin_lock_irqsave(&ha->hardware_lock, flags);
209 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
210 spin_unlock_irqrestore(&ha->hardware_lock, flags);
216 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
219 * Returns 0 on success.
222 qla2300_pci_config(scsi_qla_host_t *ha)
226 unsigned long flags = 0;
228 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
230 pci_set_master(ha->pdev);
232 if (pci_set_mwi(ha->pdev))
233 mwi = PCI_COMMAND_INVALIDATE;
235 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
236 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
238 if (IS_QLA2322(ha) || IS_QLA6322(ha))
239 w &= ~PCI_COMMAND_INTX_DISABLE;
242 * If this is a 2300 card and not 2312, reset the
243 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
244 * the 2310 also reports itself as a 2300 so we need to get the
245 * fb revision level -- a 6 indicates it really is a 2300 and
248 if (IS_QLA2300(ha)) {
249 spin_lock_irqsave(&ha->hardware_lock, flags);
252 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
253 for (cnt = 0; cnt < 30000; cnt++) {
254 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
260 /* Select FPM registers. */
261 WRT_REG_WORD(®->ctrl_status, 0x20);
262 RD_REG_WORD(®->ctrl_status);
264 /* Get the fb rev level */
265 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
267 if (ha->fb_rev == FPM_2300)
268 w &= ~PCI_COMMAND_INVALIDATE;
270 /* Deselect FPM registers. */
271 WRT_REG_WORD(®->ctrl_status, 0x0);
272 RD_REG_WORD(®->ctrl_status);
274 /* Release RISC module. */
275 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
276 for (cnt = 0; cnt < 30000; cnt++) {
277 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
283 spin_unlock_irqrestore(&ha->hardware_lock, flags);
285 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
287 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
289 /* Reset expansion ROM address decode enable */
290 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
291 d &= ~PCI_ROM_ADDRESS_ENABLE;
292 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
294 /* Get PCI bus information. */
295 spin_lock_irqsave(&ha->hardware_lock, flags);
296 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
297 spin_unlock_irqrestore(&ha->hardware_lock, flags);
303 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
306 * Returns 0 on success.
309 qla24xx_pci_config(scsi_qla_host_t *ha)
313 unsigned long flags = 0;
314 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
315 int pcix_cmd_reg, pcie_dctl_reg;
317 pci_set_master(ha->pdev);
319 if (pci_set_mwi(ha->pdev))
320 mwi = PCI_COMMAND_INVALIDATE;
322 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
323 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
324 w &= ~PCI_COMMAND_INTX_DISABLE;
325 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
327 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
329 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
330 pcix_cmd_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX);
334 pcix_cmd_reg += PCI_X_CMD;
335 pci_read_config_word(ha->pdev, pcix_cmd_reg, &pcix_cmd);
336 pcix_cmd &= ~PCI_X_CMD_MAX_READ;
338 pci_write_config_word(ha->pdev, pcix_cmd_reg, pcix_cmd);
341 /* PCIe -- adjust Maximum Read Request Size (2048). */
342 pcie_dctl_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
346 pcie_dctl_reg += PCI_EXP_DEVCTL;
347 pci_read_config_word(ha->pdev, pcie_dctl_reg, &pcie_dctl);
348 pcie_dctl &= ~PCI_EXP_DEVCTL_READRQ;
350 pci_write_config_word(ha->pdev, pcie_dctl_reg, pcie_dctl);
353 /* Reset expansion ROM address decode enable */
354 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
355 d &= ~PCI_ROM_ADDRESS_ENABLE;
356 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
358 /* Get PCI bus information. */
359 spin_lock_irqsave(&ha->hardware_lock, flags);
360 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
361 spin_unlock_irqrestore(&ha->hardware_lock, flags);
367 * qla2x00_isp_firmware() - Choose firmware image.
370 * Returns 0 on success.
373 qla2x00_isp_firmware(scsi_qla_host_t *ha)
377 /* Assume loading risc code */
378 rval = QLA_FUNCTION_FAILED;
380 if (ha->flags.disable_risc_code_load) {
381 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
383 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
385 /* Verify checksum of loaded RISC code. */
386 rval = qla2x00_verify_checksum(ha,
387 IS_QLA24XX(ha) || IS_QLA54XX(ha) ? RISC_SADDRESS :
388 *ha->brd_info->fw_info[0].fwstart);
392 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
400 * qla2x00_reset_chip() - Reset ISP chip.
403 * Returns 0 on success.
406 qla2x00_reset_chip(scsi_qla_host_t *ha)
408 unsigned long flags = 0;
409 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
413 ha->isp_ops.disable_intrs(ha);
415 spin_lock_irqsave(&ha->hardware_lock, flags);
417 /* Turn off master enable */
419 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
420 cmd &= ~PCI_COMMAND_MASTER;
421 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
423 if (!IS_QLA2100(ha)) {
425 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
426 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
427 for (cnt = 0; cnt < 30000; cnt++) {
428 if ((RD_REG_WORD(®->hccr) &
429 HCCR_RISC_PAUSE) != 0)
434 RD_REG_WORD(®->hccr); /* PCI Posting. */
438 /* Select FPM registers. */
439 WRT_REG_WORD(®->ctrl_status, 0x20);
440 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
442 /* FPM Soft Reset. */
443 WRT_REG_WORD(®->fpm_diag_config, 0x100);
444 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
446 /* Toggle Fpm Reset. */
447 if (!IS_QLA2200(ha)) {
448 WRT_REG_WORD(®->fpm_diag_config, 0x0);
449 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
452 /* Select frame buffer registers. */
453 WRT_REG_WORD(®->ctrl_status, 0x10);
454 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
456 /* Reset frame buffer FIFOs. */
457 if (IS_QLA2200(ha)) {
458 WRT_FB_CMD_REG(ha, reg, 0xa000);
459 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
461 WRT_FB_CMD_REG(ha, reg, 0x00fc);
463 /* Read back fb_cmd until zero or 3 seconds max */
464 for (cnt = 0; cnt < 3000; cnt++) {
465 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
471 /* Select RISC module registers. */
472 WRT_REG_WORD(®->ctrl_status, 0);
473 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
475 /* Reset RISC processor. */
476 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
477 RD_REG_WORD(®->hccr); /* PCI Posting. */
479 /* Release RISC processor. */
480 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
481 RD_REG_WORD(®->hccr); /* PCI Posting. */
484 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
485 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
487 /* Reset ISP chip. */
488 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
490 /* Wait for RISC to recover from reset. */
491 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
493 * It is necessary to for a delay here since the card doesn't
494 * respond to PCI reads during a reset. On some architectures
495 * this will result in an MCA.
498 for (cnt = 30000; cnt; cnt--) {
499 if ((RD_REG_WORD(®->ctrl_status) &
500 CSR_ISP_SOFT_RESET) == 0)
507 /* Reset RISC processor. */
508 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
510 WRT_REG_WORD(®->semaphore, 0);
512 /* Release RISC processor. */
513 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
514 RD_REG_WORD(®->hccr); /* PCI Posting. */
516 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
517 for (cnt = 0; cnt < 30000; cnt++) {
518 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
526 /* Turn on master enable */
527 cmd |= PCI_COMMAND_MASTER;
528 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
530 /* Disable RISC pause on FPM parity error. */
531 if (!IS_QLA2100(ha)) {
532 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
533 RD_REG_WORD(®->hccr); /* PCI Posting. */
536 spin_unlock_irqrestore(&ha->hardware_lock, flags);
540 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
543 * Returns 0 on success.
546 qla24xx_reset_risc(scsi_qla_host_t *ha)
548 unsigned long flags = 0;
549 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
553 spin_lock_irqsave(&ha->hardware_lock, flags);
556 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
557 for (cnt = 0; cnt < 30000; cnt++) {
558 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
564 WRT_REG_DWORD(®->ctrl_status,
565 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
566 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
569 /* Wait for firmware to complete NVRAM accesses. */
570 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
571 for (cnt = 10000 ; cnt && d2; cnt--) {
573 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
577 /* Wait for soft-reset to complete. */
578 d2 = RD_REG_DWORD(®->ctrl_status);
579 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
581 d2 = RD_REG_DWORD(®->ctrl_status);
585 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
586 RD_REG_DWORD(®->hccr);
588 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
589 RD_REG_DWORD(®->hccr);
591 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
592 RD_REG_DWORD(®->hccr);
594 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
595 for (cnt = 6000000 ; cnt && d2; cnt--) {
597 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
601 spin_unlock_irqrestore(&ha->hardware_lock, flags);
605 * qla24xx_reset_chip() - Reset ISP24xx chip.
608 * Returns 0 on success.
611 qla24xx_reset_chip(scsi_qla_host_t *ha)
613 ha->isp_ops.disable_intrs(ha);
615 /* Perform RISC reset. */
616 qla24xx_reset_risc(ha);
620 * qla2x00_chip_diag() - Test chip for proper operation.
623 * Returns 0 on success.
626 qla2x00_chip_diag(scsi_qla_host_t *ha)
629 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
630 unsigned long flags = 0;
635 /* Assume a failed state */
636 rval = QLA_FUNCTION_FAILED;
638 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
639 ha->host_no, (u_long)®->flash_address));
641 spin_lock_irqsave(&ha->hardware_lock, flags);
643 /* Reset ISP chip. */
644 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
647 * We need to have a delay here since the card will not respond while
648 * in reset causing an MCA on some architectures.
651 data = qla2x00_debounce_register(®->ctrl_status);
652 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
654 data = RD_REG_WORD(®->ctrl_status);
659 goto chip_diag_failed;
661 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
664 /* Reset RISC processor. */
665 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
666 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
668 /* Workaround for QLA2312 PCI parity error */
669 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
670 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
671 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
673 data = RD_MAILBOX_REG(ha, reg, 0);
680 goto chip_diag_failed;
682 /* Check product ID of chip */
683 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
685 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
686 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
687 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
688 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
689 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
690 mb[3] != PROD_ID_3) {
691 qla_printk(KERN_WARNING, ha,
692 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
694 goto chip_diag_failed;
696 ha->product_id[0] = mb[1];
697 ha->product_id[1] = mb[2];
698 ha->product_id[2] = mb[3];
699 ha->product_id[3] = mb[4];
701 /* Adjust fw RISC transfer size */
702 if (ha->request_q_length > 1024)
703 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
705 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
706 ha->request_q_length;
708 if (IS_QLA2200(ha) &&
709 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
710 /* Limit firmware transfer size with a 2200A */
711 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
714 ha->device_type |= DT_ISP2200A;
715 ha->fw_transfer_size = 128;
718 /* Wrap Incoming Mailboxes Test. */
719 spin_unlock_irqrestore(&ha->hardware_lock, flags);
721 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
722 rval = qla2x00_mbx_reg_test(ha);
724 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
726 qla_printk(KERN_WARNING, ha,
727 "Failed mailbox send register test\n");
730 /* Flag a successful rval */
733 spin_lock_irqsave(&ha->hardware_lock, flags);
737 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
738 "****\n", ha->host_no));
740 spin_unlock_irqrestore(&ha->hardware_lock, flags);
746 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
749 * Returns 0 on success.
752 qla24xx_chip_diag(scsi_qla_host_t *ha)
756 /* Perform RISC reset. */
757 qla24xx_reset_risc(ha);
759 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
761 rval = qla2x00_mbx_reg_test(ha);
763 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
765 qla_printk(KERN_WARNING, ha,
766 "Failed mailbox send register test\n");
768 /* Flag a successful rval */
776 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
779 ha->fw_dump24_len = sizeof(struct qla24xx_fw_dump);
780 ha->fw_dump24_len += (ha->fw_memory_size - 0x100000) * sizeof(uint32_t);
781 ha->fw_dump24 = vmalloc(ha->fw_dump24_len);
783 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware "
784 "dump...\n", ha->fw_dump24_len / 1024);
786 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
787 "firmware dump!!!\n", ha->fw_dump24_len / 1024);
791 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
794 * Returns 0 on success.
797 qla2x00_resize_request_q(scsi_qla_host_t *ha)
800 uint16_t fw_iocb_cnt = 0;
801 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
802 dma_addr_t request_dma;
803 request_t *request_ring;
805 /* Valid only on recent ISPs. */
806 if (IS_QLA2100(ha) || IS_QLA2200(ha))
809 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
810 qla2x00_alloc_fw_dump(ha);
812 /* Retrieve IOCB counts available to the firmware. */
813 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
816 /* No point in continuing if current settings are sufficient. */
817 if (fw_iocb_cnt < 1024)
819 if (ha->request_q_length >= request_q_length)
822 /* Attempt to claim larger area for request queue. */
823 request_ring = dma_alloc_coherent(&ha->pdev->dev,
824 (request_q_length + 1) * sizeof(request_t), &request_dma,
826 if (request_ring == NULL)
829 /* Resize successful, report extensions. */
830 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
831 (ha->fw_memory_size + 1) / 1024);
832 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
833 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
835 /* Clear old allocations. */
836 dma_free_coherent(&ha->pdev->dev,
837 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
840 /* Begin using larger queue. */
841 ha->request_q_length = request_q_length;
842 ha->request_ring = request_ring;
843 ha->request_dma = request_dma;
847 * qla2x00_setup_chip() - Load and start RISC firmware.
850 * Returns 0 on success.
853 qla2x00_setup_chip(scsi_qla_host_t *ha)
856 uint32_t srisc_address = 0;
858 /* Load firmware sequences */
859 rval = ha->isp_ops.load_risc(ha, &srisc_address);
860 if (rval == QLA_SUCCESS) {
861 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
862 "code.\n", ha->host_no));
864 rval = qla2x00_verify_checksum(ha, srisc_address);
865 if (rval == QLA_SUCCESS) {
866 /* Start firmware execution. */
867 DEBUG(printk("scsi(%ld): Checksum OK, start "
868 "firmware.\n", ha->host_no));
870 rval = qla2x00_execute_fw(ha, srisc_address);
871 /* Retrieve firmware information. */
872 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
873 qla2x00_get_fw_version(ha,
874 &ha->fw_major_version,
875 &ha->fw_minor_version,
876 &ha->fw_subminor_version,
877 &ha->fw_attributes, &ha->fw_memory_size);
878 qla2x00_resize_request_q(ha);
881 DEBUG2(printk(KERN_INFO
882 "scsi(%ld): ISP Firmware failed checksum.\n",
888 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
896 * qla2x00_init_response_q_entries() - Initializes response queue entries.
899 * Beginning of request ring has initialization control block already built
900 * by nvram config routine.
902 * Returns 0 on success.
905 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
910 pkt = ha->response_ring_ptr;
911 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
912 pkt->signature = RESPONSE_PROCESSED;
919 * qla2x00_update_fw_options() - Read and process firmware options.
922 * Returns 0 on success.
925 qla2x00_update_fw_options(scsi_qla_host_t *ha)
927 uint16_t swing, emphasis, tx_sens, rx_sens;
929 memset(ha->fw_options, 0, sizeof(ha->fw_options));
930 qla2x00_get_fw_options(ha, ha->fw_options);
932 if (IS_QLA2100(ha) || IS_QLA2200(ha))
935 /* Serial Link options. */
936 DEBUG3(printk("scsi(%ld): Serial link options:\n",
938 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
939 sizeof(ha->fw_seriallink_options)));
941 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
942 if (ha->fw_seriallink_options[3] & BIT_2) {
943 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
946 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
947 emphasis = (ha->fw_seriallink_options[2] &
948 (BIT_4 | BIT_3)) >> 3;
949 tx_sens = ha->fw_seriallink_options[0] &
950 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
951 rx_sens = (ha->fw_seriallink_options[0] &
952 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
953 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
954 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
957 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
958 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
959 ha->fw_options[10] |= BIT_5 |
960 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
961 (tx_sens & (BIT_1 | BIT_0));
964 swing = (ha->fw_seriallink_options[2] &
965 (BIT_7 | BIT_6 | BIT_5)) >> 5;
966 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
967 tx_sens = ha->fw_seriallink_options[1] &
968 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
969 rx_sens = (ha->fw_seriallink_options[1] &
970 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
971 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
972 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
975 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
976 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
977 ha->fw_options[11] |= BIT_5 |
978 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
979 (tx_sens & (BIT_1 | BIT_0));
983 /* Return command IOCBs without waiting for an ABTS to complete. */
984 ha->fw_options[3] |= BIT_13;
987 if (ha->flags.enable_led_scheme)
988 ha->fw_options[2] |= BIT_12;
990 /* Detect ISP6312. */
992 ha->fw_options[2] |= BIT_13;
994 /* Update firmware options. */
995 qla2x00_set_fw_options(ha, ha->fw_options);
999 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1003 /* Update Serial Link options. */
1004 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1007 rval = qla2x00_set_serdes_params(ha,
1008 le16_to_cpu(ha->fw_seriallink_options24[1]),
1009 le16_to_cpu(ha->fw_seriallink_options24[2]),
1010 le16_to_cpu(ha->fw_seriallink_options24[3]));
1011 if (rval != QLA_SUCCESS) {
1012 qla_printk(KERN_WARNING, ha,
1013 "Unable to update Serial Link options (%x).\n", rval);
1018 qla2x00_config_rings(struct scsi_qla_host *ha)
1020 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1022 /* Setup ring parameters in initialization control block. */
1023 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1024 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1025 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1026 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1027 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1028 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1029 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1030 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1032 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1033 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1034 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1035 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1036 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1040 qla24xx_config_rings(struct scsi_qla_host *ha)
1042 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1043 struct init_cb_24xx *icb;
1045 /* Setup ring parameters in initialization control block. */
1046 icb = (struct init_cb_24xx *)ha->init_cb;
1047 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1048 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1049 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1050 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1051 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1052 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1053 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1054 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1056 WRT_REG_DWORD(®->req_q_in, 0);
1057 WRT_REG_DWORD(®->req_q_out, 0);
1058 WRT_REG_DWORD(®->rsp_q_in, 0);
1059 WRT_REG_DWORD(®->rsp_q_out, 0);
1060 RD_REG_DWORD(®->rsp_q_out);
1064 * qla2x00_init_rings() - Initializes firmware.
1067 * Beginning of request ring has initialization control block already built
1068 * by nvram config routine.
1070 * Returns 0 on success.
1073 qla2x00_init_rings(scsi_qla_host_t *ha)
1076 unsigned long flags = 0;
1079 spin_lock_irqsave(&ha->hardware_lock, flags);
1081 /* Clear outstanding commands array. */
1082 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1083 ha->outstanding_cmds[cnt] = NULL;
1085 ha->current_outstanding_cmd = 0;
1087 /* Clear RSCN queue. */
1088 ha->rscn_in_ptr = 0;
1089 ha->rscn_out_ptr = 0;
1091 /* Initialize firmware. */
1092 ha->request_ring_ptr = ha->request_ring;
1093 ha->req_ring_index = 0;
1094 ha->req_q_cnt = ha->request_q_length;
1095 ha->response_ring_ptr = ha->response_ring;
1096 ha->rsp_ring_index = 0;
1098 /* Initialize response queue entries */
1099 qla2x00_init_response_q_entries(ha);
1101 ha->isp_ops.config_rings(ha);
1103 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1105 /* Update any ISP specific firmware options before initialization. */
1106 ha->isp_ops.update_fw_options(ha);
1108 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1109 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1111 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1114 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1122 * qla2x00_fw_ready() - Waits for firmware ready.
1125 * Returns 0 on success.
1128 qla2x00_fw_ready(scsi_qla_host_t *ha)
1131 unsigned long wtime, mtime;
1132 uint16_t min_wait; /* Minimum wait time if loop is down */
1133 uint16_t wait_time; /* Wait time if loop is coming ready */
1138 /* 20 seconds for loop down. */
1142 * Firmware should take at most one RATOV to login, plus 5 seconds for
1143 * our own processing.
1145 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1146 wait_time = min_wait;
1149 /* Min wait time if loop down */
1150 mtime = jiffies + (min_wait * HZ);
1152 /* wait time before firmware ready */
1153 wtime = jiffies + (wait_time * HZ);
1155 /* Wait for ISP to finish LIP */
1156 if (!ha->flags.init_done)
1157 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1159 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1163 rval = qla2x00_get_firmware_state(ha, &fw_state);
1164 if (rval == QLA_SUCCESS) {
1165 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1166 ha->device_flags &= ~DFLG_NO_CABLE;
1168 if (fw_state == FSTATE_READY) {
1169 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1172 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1173 &ha->login_timeout, &ha->r_a_tov);
1179 rval = QLA_FUNCTION_FAILED;
1181 if (atomic_read(&ha->loop_down_timer) &&
1182 (fw_state >= FSTATE_LOSS_OF_SYNC ||
1183 fw_state == FSTATE_WAIT_AL_PA)) {
1184 /* Loop down. Timeout on min_wait for states
1185 * other than Wait for Login.
1187 if (time_after_eq(jiffies, mtime)) {
1188 qla_printk(KERN_INFO, ha,
1189 "Cable is unplugged...\n");
1191 ha->device_flags |= DFLG_NO_CABLE;
1196 /* Mailbox cmd failed. Timeout on min_wait. */
1197 if (time_after_eq(jiffies, mtime))
1201 if (time_after_eq(jiffies, wtime))
1204 /* Delay for a while */
1207 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1208 ha->host_no, fw_state, jiffies));
1211 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1212 ha->host_no, fw_state, jiffies));
1215 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1223 * qla2x00_configure_hba
1224 * Setup adapter context.
1227 * ha = adapter state pointer.
1236 qla2x00_configure_hba(scsi_qla_host_t *ha)
1244 char connect_type[22];
1246 /* Get host addresses. */
1247 rval = qla2x00_get_adapter_id(ha,
1248 &loop_id, &al_pa, &area, &domain, &topo);
1249 if (rval != QLA_SUCCESS) {
1250 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
1251 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1252 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1253 __func__, ha->host_no));
1255 qla_printk(KERN_WARNING, ha,
1256 "ERROR -- Unable to get host loop ID.\n");
1257 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1263 qla_printk(KERN_INFO, ha,
1264 "Cannot get topology - retrying.\n");
1265 return (QLA_FUNCTION_FAILED);
1268 ha->loop_id = loop_id;
1271 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1272 ha->operating_mode = LOOP;
1276 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1278 ha->current_topology = ISP_CFG_NL;
1279 strcpy(connect_type, "(Loop)");
1283 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1285 ha->current_topology = ISP_CFG_FL;
1286 strcpy(connect_type, "(FL_Port)");
1290 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1292 ha->operating_mode = P2P;
1293 ha->current_topology = ISP_CFG_N;
1294 strcpy(connect_type, "(N_Port-to-N_Port)");
1298 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1300 ha->operating_mode = P2P;
1301 ha->current_topology = ISP_CFG_F;
1302 strcpy(connect_type, "(F_Port)");
1306 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1308 ha->host_no, topo));
1309 ha->current_topology = ISP_CFG_NL;
1310 strcpy(connect_type, "(Loop)");
1314 /* Save Host port and loop ID. */
1315 /* byte order - Big Endian */
1316 ha->d_id.b.domain = domain;
1317 ha->d_id.b.area = area;
1318 ha->d_id.b.al_pa = al_pa;
1320 if (!ha->flags.init_done)
1321 qla_printk(KERN_INFO, ha,
1322 "Topology - %s, Host Loop address 0x%x\n",
1323 connect_type, ha->loop_id);
1326 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1328 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1335 * NVRAM configuration for ISP 2xxx
1338 * ha = adapter block pointer.
1341 * initialization control block in response_ring
1342 * host adapters parameters in host adapter block
1348 qla2x00_nvram_config(scsi_qla_host_t *ha)
1353 uint8_t *dptr1, *dptr2;
1354 init_cb_t *icb = ha->init_cb;
1355 nvram_t *nv = (nvram_t *)ha->request_ring;
1356 uint8_t *ptr = (uint8_t *)ha->request_ring;
1357 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1361 /* Determine NVRAM starting address. */
1362 ha->nvram_size = sizeof(nvram_t);
1364 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1365 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1366 ha->nvram_base = 0x80;
1368 /* Get NVRAM data and calculate checksum. */
1369 ha->isp_ops.read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1370 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1373 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1374 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1377 /* Bad NVRAM data, set defaults parameters. */
1378 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1379 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1380 /* Reset NVRAM data. */
1381 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1382 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1384 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1385 "invalid -- WWPN) defaults.\n");
1388 * Set default initialization control block.
1390 memset(nv, 0, ha->nvram_size);
1391 nv->parameter_block_version = ICB_VERSION;
1393 if (IS_QLA23XX(ha)) {
1394 nv->firmware_options[0] = BIT_2 | BIT_1;
1395 nv->firmware_options[1] = BIT_7 | BIT_5;
1396 nv->add_firmware_options[0] = BIT_5;
1397 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1398 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1399 nv->special_options[1] = BIT_7;
1400 } else if (IS_QLA2200(ha)) {
1401 nv->firmware_options[0] = BIT_2 | BIT_1;
1402 nv->firmware_options[1] = BIT_7 | BIT_5;
1403 nv->add_firmware_options[0] = BIT_5;
1404 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1405 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1406 } else if (IS_QLA2100(ha)) {
1407 nv->firmware_options[0] = BIT_3 | BIT_1;
1408 nv->firmware_options[1] = BIT_5;
1409 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1412 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1413 nv->execution_throttle = __constant_cpu_to_le16(16);
1414 nv->retry_count = 8;
1415 nv->retry_delay = 1;
1417 nv->port_name[0] = 33;
1418 nv->port_name[3] = 224;
1419 nv->port_name[4] = 139;
1421 nv->login_timeout = 4;
1424 * Set default host adapter parameters
1426 nv->host_p[1] = BIT_2;
1427 nv->reset_delay = 5;
1428 nv->port_down_retry_count = 8;
1429 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1430 nv->link_down_timeout = 60;
1435 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1437 * The SN2 does not provide BIOS emulation which means you can't change
1438 * potentially bogus BIOS settings. Force the use of default settings
1439 * for link rate and frame size. Hope that the rest of the settings
1442 if (ia64_platform_is("sn2")) {
1443 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1445 nv->special_options[1] = BIT_7;
1449 /* Reset Initialization control block */
1450 memset(icb, 0, ha->init_cb_size);
1453 * Setup driver NVRAM options.
1455 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1456 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1457 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1458 nv->firmware_options[1] &= ~BIT_4;
1460 if (IS_QLA23XX(ha)) {
1461 nv->firmware_options[0] |= BIT_2;
1462 nv->firmware_options[0] &= ~BIT_3;
1463 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1465 if (IS_QLA2300(ha)) {
1466 if (ha->fb_rev == FPM_2310) {
1467 strcpy(ha->model_number, "QLA2310");
1469 strcpy(ha->model_number, "QLA2300");
1473 memcmp(nv->model_number, BINZERO,
1474 sizeof(nv->model_number)) != 0) {
1477 strncpy(ha->model_number, nv->model_number,
1478 sizeof(nv->model_number));
1479 st = en = ha->model_number;
1480 en += sizeof(nv->model_number) - 1;
1482 if (*en != 0x20 && *en != 0x00)
1489 index = (ha->pdev->subsystem_device & 0xff);
1490 if (index < QLA_MODEL_NAMES) {
1491 strcpy(ha->model_number,
1492 qla2x00_model_name[index * 2]);
1494 qla2x00_model_name[index * 2 + 1];
1496 strcpy(ha->model_number, "QLA23xx");
1500 } else if (IS_QLA2200(ha)) {
1501 nv->firmware_options[0] |= BIT_2;
1503 * 'Point-to-point preferred, else loop' is not a safe
1504 * connection mode setting.
1506 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1508 /* Force 'loop preferred, else point-to-point'. */
1509 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1510 nv->add_firmware_options[0] |= BIT_5;
1512 strcpy(ha->model_number, "QLA22xx");
1513 } else /*if (IS_QLA2100(ha))*/ {
1514 strcpy(ha->model_number, "QLA2100");
1518 * Copy over NVRAM RISC parameter block to initialization control block.
1520 dptr1 = (uint8_t *)icb;
1521 dptr2 = (uint8_t *)&nv->parameter_block_version;
1522 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1524 *dptr1++ = *dptr2++;
1526 /* Copy 2nd half. */
1527 dptr1 = (uint8_t *)icb->add_firmware_options;
1528 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1530 *dptr1++ = *dptr2++;
1532 /* Use alternate WWN? */
1533 if (nv->host_p[1] & BIT_7) {
1534 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1535 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1538 /* Prepare nodename */
1539 if ((icb->firmware_options[1] & BIT_6) == 0) {
1541 * Firmware will apply the following mask if the nodename was
1544 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1545 icb->node_name[0] &= 0xF0;
1549 * Set host adapter parameters.
1551 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1552 /* Always load RISC code on non ISP2[12]00 chips. */
1553 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1554 ha->flags.disable_risc_code_load = 0;
1555 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1556 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1557 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1558 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1560 ha->operating_mode =
1561 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1563 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1564 sizeof(ha->fw_seriallink_options));
1566 /* save HBA serial number */
1567 ha->serial0 = icb->port_name[5];
1568 ha->serial1 = icb->port_name[6];
1569 ha->serial2 = icb->port_name[7];
1570 ha->node_name = icb->node_name;
1571 ha->port_name = icb->port_name;
1573 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1575 ha->retry_count = nv->retry_count;
1577 /* Set minimum login_timeout to 4 seconds. */
1578 if (nv->login_timeout < ql2xlogintimeout)
1579 nv->login_timeout = ql2xlogintimeout;
1580 if (nv->login_timeout < 4)
1581 nv->login_timeout = 4;
1582 ha->login_timeout = nv->login_timeout;
1583 icb->login_timeout = nv->login_timeout;
1585 /* Set minimum RATOV to 200 tenths of a second. */
1588 ha->loop_reset_delay = nv->reset_delay;
1590 /* Link Down Timeout = 0:
1592 * When Port Down timer expires we will start returning
1593 * I/O's to OS with "DID_NO_CONNECT".
1595 * Link Down Timeout != 0:
1597 * The driver waits for the link to come up after link down
1598 * before returning I/Os to OS with "DID_NO_CONNECT".
1600 if (nv->link_down_timeout == 0) {
1601 ha->loop_down_abort_time =
1602 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1604 ha->link_down_timeout = nv->link_down_timeout;
1605 ha->loop_down_abort_time =
1606 (LOOP_DOWN_TIME - ha->link_down_timeout);
1610 * Need enough time to try and get the port back.
1612 ha->port_down_retry_count = nv->port_down_retry_count;
1613 if (qlport_down_retry)
1614 ha->port_down_retry_count = qlport_down_retry;
1615 /* Set login_retry_count */
1616 ha->login_retry_count = nv->retry_count;
1617 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1618 ha->port_down_retry_count > 3)
1619 ha->login_retry_count = ha->port_down_retry_count;
1620 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1621 ha->login_retry_count = ha->port_down_retry_count;
1622 if (ql2xloginretrycount)
1623 ha->login_retry_count = ql2xloginretrycount;
1625 icb->lun_enables = __constant_cpu_to_le16(0);
1626 icb->command_resource_count = 0;
1627 icb->immediate_notify_resource_count = 0;
1628 icb->timeout = __constant_cpu_to_le16(0);
1630 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1632 icb->firmware_options[0] &= ~BIT_3;
1633 icb->add_firmware_options[0] &=
1634 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1635 icb->add_firmware_options[0] |= BIT_2;
1636 icb->response_accumulation_timer = 3;
1637 icb->interrupt_delay_timer = 5;
1639 ha->flags.process_response_queue = 1;
1642 if (!ha->flags.init_done) {
1643 ha->zio_mode = icb->add_firmware_options[0] &
1644 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1645 ha->zio_timer = icb->interrupt_delay_timer ?
1646 icb->interrupt_delay_timer: 2;
1648 icb->add_firmware_options[0] &=
1649 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1650 ha->flags.process_response_queue = 0;
1651 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1652 ha->zio_mode = QLA_ZIO_MODE_6;
1654 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1655 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1656 ha->zio_timer * 100));
1657 qla_printk(KERN_INFO, ha,
1658 "ZIO mode %d enabled; timer delay (%d us).\n",
1659 ha->zio_mode, ha->zio_timer * 100);
1661 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1662 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1663 ha->flags.process_response_queue = 1;
1668 DEBUG2_3(printk(KERN_WARNING
1669 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1675 qla2x00_rport_del(void *data)
1677 fc_port_t *fcport = data;
1678 struct fc_rport *rport;
1679 unsigned long flags;
1681 spin_lock_irqsave(&fcport->rport_lock, flags);
1682 rport = fcport->drport;
1683 fcport->drport = NULL;
1684 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1686 fc_remote_port_delete(rport);
1691 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1693 * @flags: allocation flags
1695 * Returns a pointer to the allocated fcport, or NULL, if none available.
1698 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1702 fcport = kmalloc(sizeof(fc_port_t), flags);
1706 /* Setup fcport template structure. */
1707 memset(fcport, 0, sizeof (fc_port_t));
1709 fcport->port_type = FCT_UNKNOWN;
1710 fcport->loop_id = FC_NO_LOOP_ID;
1711 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1712 fcport->flags = FCF_RLC_SUPPORT;
1713 fcport->supported_classes = FC_COS_UNSPECIFIED;
1714 spin_lock_init(&fcport->rport_lock);
1720 * qla2x00_configure_loop
1721 * Updates Fibre Channel Device Database with what is actually on loop.
1724 * ha = adapter block pointer.
1729 * 2 = database was full and device was not configured.
1732 qla2x00_configure_loop(scsi_qla_host_t *ha)
1735 unsigned long flags, save_flags;
1739 /* Get Initiator ID */
1740 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1741 rval = qla2x00_configure_hba(ha);
1742 if (rval != QLA_SUCCESS) {
1743 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1749 save_flags = flags = ha->dpc_flags;
1750 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1751 ha->host_no, flags));
1754 * If we have both an RSCN and PORT UPDATE pending then handle them
1755 * both at the same time.
1757 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1758 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1760 /* Determine what we need to do */
1761 if (ha->current_topology == ISP_CFG_FL &&
1762 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1764 ha->flags.rscn_queue_overflow = 1;
1765 set_bit(RSCN_UPDATE, &flags);
1767 } else if (ha->current_topology == ISP_CFG_F &&
1768 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1770 ha->flags.rscn_queue_overflow = 1;
1771 set_bit(RSCN_UPDATE, &flags);
1772 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1774 } else if (!ha->flags.online ||
1775 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1777 ha->flags.rscn_queue_overflow = 1;
1778 set_bit(RSCN_UPDATE, &flags);
1779 set_bit(LOCAL_LOOP_UPDATE, &flags);
1782 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1783 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1784 rval = QLA_FUNCTION_FAILED;
1786 rval = qla2x00_configure_local_loop(ha);
1790 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1791 if (LOOP_TRANSITION(ha)) {
1792 rval = QLA_FUNCTION_FAILED;
1794 rval = qla2x00_configure_fabric(ha);
1798 if (rval == QLA_SUCCESS) {
1799 if (atomic_read(&ha->loop_down_timer) ||
1800 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1801 rval = QLA_FUNCTION_FAILED;
1803 atomic_set(&ha->loop_state, LOOP_READY);
1805 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1810 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1811 __func__, ha->host_no));
1813 DEBUG3(printk("%s: exiting normally\n", __func__));
1816 /* Restore state if a resync event occured during processing */
1817 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1818 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1819 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1820 if (test_bit(RSCN_UPDATE, &save_flags))
1821 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1830 * qla2x00_configure_local_loop
1831 * Updates Fibre Channel Device Database with local loop devices.
1834 * ha = adapter block pointer.
1840 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1845 fc_port_t *fcport, *new_fcport;
1851 uint8_t domain, area, al_pa;
1855 entries = MAX_FIBRE_DEVICES;
1857 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1858 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1860 /* Get list of logged in devices. */
1861 memset(ha->gid_list, 0, GID_LIST_SIZE);
1862 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1864 if (rval != QLA_SUCCESS)
1865 goto cleanup_allocation;
1867 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1868 ha->host_no, entries));
1869 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1870 entries * sizeof(struct gid_list_info)));
1872 /* Allocate temporary fcport for any new fcports discovered. */
1873 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1874 if (new_fcport == NULL) {
1875 rval = QLA_MEMORY_ALLOC_FAILED;
1876 goto cleanup_allocation;
1878 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1881 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1883 list_for_each_entry(fcport, &ha->fcports, list) {
1884 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1885 fcport->port_type != FCT_BROADCAST &&
1886 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1888 DEBUG(printk("scsi(%ld): Marking port lost, "
1890 ha->host_no, fcport->loop_id));
1892 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1893 fcport->flags &= ~FCF_FARP_DONE;
1897 /* Add devices to port list. */
1898 id_iter = (char *)ha->gid_list;
1899 for (index = 0; index < entries; index++) {
1900 domain = ((struct gid_list_info *)id_iter)->domain;
1901 area = ((struct gid_list_info *)id_iter)->area;
1902 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1903 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1904 loop_id = (uint16_t)
1905 ((struct gid_list_info *)id_iter)->loop_id_2100;
1907 loop_id = le16_to_cpu(
1908 ((struct gid_list_info *)id_iter)->loop_id);
1909 id_iter += ha->gid_list_info_size;
1911 /* Bypass reserved domain fields. */
1912 if ((domain & 0xf0) == 0xf0)
1915 /* Bypass if not same domain and area of adapter. */
1916 if (area && domain &&
1917 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
1920 /* Bypass invalid local loop ID. */
1921 if (loop_id > LAST_LOCAL_LOOP_ID)
1924 /* Fill in member data. */
1925 new_fcport->d_id.b.domain = domain;
1926 new_fcport->d_id.b.area = area;
1927 new_fcport->d_id.b.al_pa = al_pa;
1928 new_fcport->loop_id = loop_id;
1929 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1930 if (rval2 != QLA_SUCCESS) {
1931 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1932 "information -- get_port_database=%x, "
1934 ha->host_no, rval2, new_fcport->loop_id));
1935 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
1937 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
1941 /* Check for matching device in port list. */
1944 list_for_each_entry(fcport, &ha->fcports, list) {
1945 if (memcmp(new_fcport->port_name, fcport->port_name,
1949 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1950 FCF_PERSISTENT_BOUND);
1951 fcport->loop_id = new_fcport->loop_id;
1952 fcport->port_type = new_fcport->port_type;
1953 fcport->d_id.b24 = new_fcport->d_id.b24;
1954 memcpy(fcport->node_name, new_fcport->node_name,
1962 /* New device, add to fcports list. */
1963 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1964 list_add_tail(&new_fcport->list, &ha->fcports);
1966 /* Allocate a new replacement fcport. */
1967 fcport = new_fcport;
1968 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1969 if (new_fcport == NULL) {
1970 rval = QLA_MEMORY_ALLOC_FAILED;
1971 goto cleanup_allocation;
1973 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1976 qla2x00_update_fcport(ha, fcport);
1984 if (rval != QLA_SUCCESS) {
1985 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1986 "rval=%x\n", ha->host_no, rval));
1990 ha->device_flags |= DFLG_LOCAL_DEVICES;
1991 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
1998 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
2002 qla2x00_mark_all_devices_lost(ha, 0);
2003 list_for_each_entry(fcport, &ha->fcports, list) {
2004 if (fcport->port_type != FCT_TARGET)
2007 qla2x00_update_fcport(ha, fcport);
2012 * qla2x00_update_fcport
2013 * Updates device on list.
2016 * ha = adapter block pointer.
2017 * fcport = port structure pointer.
2027 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2030 fcport->login_retry = 0;
2031 fcport->port_login_retry_count = ha->port_down_retry_count *
2033 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2035 fcport->flags &= ~FCF_LOGIN_NEEDED;
2037 atomic_set(&fcport->state, FCS_ONLINE);
2039 if (ha->flags.init_done)
2040 qla2x00_reg_remote_port(ha, fcport);
2044 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2046 struct fc_rport_identifiers rport_ids;
2047 struct fc_rport *rport;
2048 unsigned long flags;
2051 qla2x00_rport_del(fcport);
2055 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2056 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2057 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2058 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2059 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2060 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2062 qla_printk(KERN_WARNING, ha,
2063 "Unable to allocate fc remote port!\n");
2066 spin_lock_irqsave(&fcport->rport_lock, flags);
2067 fcport->rport = rport;
2068 *((fc_port_t **)rport->dd_data) = fcport;
2069 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2071 rport->supported_classes = fcport->supported_classes;
2073 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2074 if (fcport->port_type == FCT_INITIATOR)
2075 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2076 if (fcport->port_type == FCT_TARGET)
2077 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2078 fc_remote_port_rolechg(rport, rport_ids.roles);
2080 if (rport->scsi_target_id != -1 &&
2081 rport->scsi_target_id < ha->host->max_id)
2082 fcport->os_target_id = rport->scsi_target_id;
2086 * qla2x00_configure_fabric
2087 * Setup SNS devices with loop ID's.
2090 * ha = adapter block pointer.
2097 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2100 fc_port_t *fcport, *fcptemp;
2101 uint16_t next_loopid;
2102 uint16_t mb[MAILBOX_REGISTER_COUNT];
2104 LIST_HEAD(new_fcports);
2106 /* If FL port exists, then SNS is present */
2107 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2108 loop_id = NPH_F_PORT;
2110 loop_id = SNS_FL_PORT;
2111 rval = qla2x00_get_port_name(ha, loop_id, NULL, 0);
2112 if (rval != QLA_SUCCESS) {
2113 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2114 "Port\n", ha->host_no));
2116 ha->device_flags &= ~SWITCH_FOUND;
2117 return (QLA_SUCCESS);
2120 /* Mark devices that need re-synchronization. */
2121 rval2 = qla2x00_device_resync(ha);
2122 if (rval2 == QLA_RSCNS_HANDLED) {
2123 /* No point doing the scan, just continue. */
2124 return (QLA_SUCCESS);
2128 if (ql2xfdmienable &&
2129 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2130 qla2x00_fdmi_register(ha);
2132 /* Ensure we are logged into the SNS. */
2133 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2136 loop_id = SIMPLE_NAME_SERVER;
2137 ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
2138 0xfc, mb, BIT_1 | BIT_0);
2139 if (mb[0] != MBS_COMMAND_COMPLETE) {
2140 DEBUG2(qla_printk(KERN_INFO, ha,
2141 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2142 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2143 mb[0], mb[1], mb[2], mb[6], mb[7]));
2144 return (QLA_SUCCESS);
2147 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2148 if (qla2x00_rft_id(ha)) {
2150 DEBUG2(printk("scsi(%ld): Register FC-4 "
2151 "TYPE failed.\n", ha->host_no));
2153 if (qla2x00_rff_id(ha)) {
2155 DEBUG2(printk("scsi(%ld): Register FC-4 "
2156 "Features failed.\n", ha->host_no));
2158 if (qla2x00_rnn_id(ha)) {
2160 DEBUG2(printk("scsi(%ld): Register Node Name "
2161 "failed.\n", ha->host_no));
2162 } else if (qla2x00_rsnn_nn(ha)) {
2164 DEBUG2(printk("scsi(%ld): Register Symbolic "
2165 "Node Name failed.\n", ha->host_no));
2169 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2170 if (rval != QLA_SUCCESS)
2174 * Logout all previous fabric devices marked lost, except
2177 list_for_each_entry(fcport, &ha->fcports, list) {
2178 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2181 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2184 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2185 qla2x00_mark_device_lost(ha, fcport,
2186 ql2xplogiabsentdevice, 0);
2187 if (fcport->loop_id != FC_NO_LOOP_ID &&
2188 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2189 fcport->port_type != FCT_INITIATOR &&
2190 fcport->port_type != FCT_BROADCAST) {
2191 ha->isp_ops.fabric_logout(ha,
2193 fcport->d_id.b.domain,
2194 fcport->d_id.b.area,
2195 fcport->d_id.b.al_pa);
2196 fcport->loop_id = FC_NO_LOOP_ID;
2201 /* Starting free loop ID. */
2202 next_loopid = ha->min_external_loopid;
2205 * Scan through our port list and login entries that need to be
2208 list_for_each_entry(fcport, &ha->fcports, list) {
2209 if (atomic_read(&ha->loop_down_timer) ||
2210 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2213 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2214 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2217 if (fcport->loop_id == FC_NO_LOOP_ID) {
2218 fcport->loop_id = next_loopid;
2219 rval = qla2x00_find_new_loop_id(ha, fcport);
2220 if (rval != QLA_SUCCESS) {
2221 /* Ran out of IDs to use */
2225 /* Login and update database */
2226 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2229 /* Exit if out of loop IDs. */
2230 if (rval != QLA_SUCCESS) {
2235 * Login and add the new devices to our port list.
2237 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2238 if (atomic_read(&ha->loop_down_timer) ||
2239 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2242 /* Find a new loop ID to use. */
2243 fcport->loop_id = next_loopid;
2244 rval = qla2x00_find_new_loop_id(ha, fcport);
2245 if (rval != QLA_SUCCESS) {
2246 /* Ran out of IDs to use */
2250 /* Remove device from the new list and add it to DB */
2251 list_del(&fcport->list);
2252 list_add_tail(&fcport->list, &ha->fcports);
2254 /* Login and update database */
2255 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2259 /* Free all new device structures not processed. */
2260 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2261 list_del(&fcport->list);
2266 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2267 "rval=%d\n", ha->host_no, rval));
2275 * qla2x00_find_all_fabric_devs
2278 * ha = adapter block pointer.
2279 * dev = database device entry pointer.
2288 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2292 fc_port_t *fcport, *new_fcport, *fcptemp;
2297 int first_dev, last_dev;
2298 port_id_t wrap, nxt_d_id;
2302 /* Try GID_PT to get device list, else GAN. */
2303 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2306 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2307 "on GA_NXT\n", ha->host_no));
2309 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2310 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2313 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2316 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2323 /* Allocate temporary fcport for any new fcports discovered. */
2324 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2325 if (new_fcport == NULL) {
2327 return (QLA_MEMORY_ALLOC_FAILED);
2329 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2331 /* Set start port ID scan at adapter ID. */
2335 /* Starting free loop ID. */
2336 loop_id = ha->min_external_loopid;
2337 for (; loop_id <= ha->last_loop_id; loop_id++) {
2338 if (qla2x00_is_reserved_id(ha, loop_id))
2341 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2346 wrap.b24 = new_fcport->d_id.b24;
2348 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2349 memcpy(new_fcport->node_name,
2350 swl[swl_idx].node_name, WWN_SIZE);
2351 memcpy(new_fcport->port_name,
2352 swl[swl_idx].port_name, WWN_SIZE);
2354 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2360 /* Send GA_NXT to the switch */
2361 rval = qla2x00_ga_nxt(ha, new_fcport);
2362 if (rval != QLA_SUCCESS) {
2363 qla_printk(KERN_WARNING, ha,
2364 "SNS scan failed -- assuming zero-entry "
2366 list_for_each_entry_safe(fcport, fcptemp,
2367 new_fcports, list) {
2368 list_del(&fcport->list);
2376 /* If wrap on switch device list, exit. */
2378 wrap.b24 = new_fcport->d_id.b24;
2380 } else if (new_fcport->d_id.b24 == wrap.b24) {
2381 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2382 ha->host_no, new_fcport->d_id.b.domain,
2383 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2387 /* Bypass if host adapter. */
2388 if (new_fcport->d_id.b24 == ha->d_id.b24)
2391 /* Bypass if same domain and area of adapter. */
2392 if (((new_fcport->d_id.b24 & 0xffff00) ==
2393 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2397 /* Bypass reserved domain fields. */
2398 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2401 /* Locate matching device in database. */
2403 list_for_each_entry(fcport, &ha->fcports, list) {
2404 if (memcmp(new_fcport->port_name, fcport->port_name,
2411 * If address the same and state FCS_ONLINE, nothing
2414 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2415 atomic_read(&fcport->state) == FCS_ONLINE) {
2420 * If device was not a fabric device before.
2422 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2423 fcport->d_id.b24 = new_fcport->d_id.b24;
2424 fcport->loop_id = FC_NO_LOOP_ID;
2425 fcport->flags |= (FCF_FABRIC_DEVICE |
2427 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2432 * Port ID changed or device was marked to be updated;
2433 * Log it out if still logged in and mark it for
2436 fcport->d_id.b24 = new_fcport->d_id.b24;
2437 fcport->flags |= FCF_LOGIN_NEEDED;
2438 if (fcport->loop_id != FC_NO_LOOP_ID &&
2439 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2440 fcport->port_type != FCT_INITIATOR &&
2441 fcport->port_type != FCT_BROADCAST) {
2442 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2443 fcport->d_id.b.domain, fcport->d_id.b.area,
2444 fcport->d_id.b.al_pa);
2445 fcport->loop_id = FC_NO_LOOP_ID;
2454 /* If device was not in our fcports list, then add it. */
2455 list_add_tail(&new_fcport->list, new_fcports);
2457 /* Allocate a new replacement fcport. */
2458 nxt_d_id.b24 = new_fcport->d_id.b24;
2459 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2460 if (new_fcport == NULL) {
2462 return (QLA_MEMORY_ALLOC_FAILED);
2464 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2465 new_fcport->d_id.b24 = nxt_d_id.b24;
2471 if (!list_empty(new_fcports))
2472 ha->device_flags |= DFLG_FABRIC_DEVICES;
2478 * qla2x00_find_new_loop_id
2479 * Scan through our port list and find a new usable loop ID.
2482 * ha: adapter state pointer.
2483 * dev: port structure pointer.
2486 * qla2x00 local function return status code.
2492 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2497 uint16_t first_loop_id;
2501 /* Save starting loop ID. */
2502 first_loop_id = dev->loop_id;
2505 /* Skip loop ID if already used by adapter. */
2506 if (dev->loop_id == ha->loop_id) {
2510 /* Skip reserved loop IDs. */
2511 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2515 /* Reset loop ID if passed the end. */
2516 if (dev->loop_id > ha->last_loop_id) {
2517 /* first loop ID. */
2518 dev->loop_id = ha->min_external_loopid;
2521 /* Check for loop ID being already in use. */
2524 list_for_each_entry(fcport, &ha->fcports, list) {
2525 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2526 /* ID possibly in use */
2532 /* If not in use then it is free to use. */
2537 /* ID in use. Try next value. */
2540 /* If wrap around. No free ID to use. */
2541 if (dev->loop_id == first_loop_id) {
2542 dev->loop_id = FC_NO_LOOP_ID;
2543 rval = QLA_FUNCTION_FAILED;
2552 * qla2x00_device_resync
2553 * Marks devices in the database that needs resynchronization.
2556 * ha = adapter block pointer.
2562 qla2x00_device_resync(scsi_qla_host_t *ha)
2567 uint32_t rscn_entry;
2568 uint8_t rscn_out_iter;
2572 rval = QLA_RSCNS_HANDLED;
2574 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2575 ha->flags.rscn_queue_overflow) {
2577 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2578 format = MSB(MSW(rscn_entry));
2579 d_id.b.domain = LSB(MSW(rscn_entry));
2580 d_id.b.area = MSB(LSW(rscn_entry));
2581 d_id.b.al_pa = LSB(LSW(rscn_entry));
2583 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2584 "[%02x/%02x%02x%02x].\n",
2585 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2586 d_id.b.area, d_id.b.al_pa));
2589 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2590 ha->rscn_out_ptr = 0;
2592 /* Skip duplicate entries. */
2593 for (rscn_out_iter = ha->rscn_out_ptr;
2594 !ha->flags.rscn_queue_overflow &&
2595 rscn_out_iter != ha->rscn_in_ptr;
2596 rscn_out_iter = (rscn_out_iter ==
2597 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2599 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2602 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2603 "entry found at [%d].\n", ha->host_no,
2606 ha->rscn_out_ptr = rscn_out_iter;
2609 /* Queue overflow, set switch default case. */
2610 if (ha->flags.rscn_queue_overflow) {
2611 DEBUG(printk("scsi(%ld): device_resync: rscn "
2612 "overflow.\n", ha->host_no));
2615 ha->flags.rscn_queue_overflow = 0;
2631 ha->rscn_out_ptr = ha->rscn_in_ptr;
2637 list_for_each_entry(fcport, &ha->fcports, list) {
2638 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2639 (fcport->d_id.b24 & mask) != d_id.b24 ||
2640 fcport->port_type == FCT_BROADCAST)
2643 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2645 fcport->port_type != FCT_INITIATOR) {
2646 qla2x00_mark_device_lost(ha, fcport,
2650 fcport->flags &= ~FCF_FARP_DONE;
2657 * qla2x00_fabric_dev_login
2658 * Login fabric target device and update FC port database.
2661 * ha: adapter state pointer.
2662 * fcport: port structure list pointer.
2663 * next_loopid: contains value of a new loop ID that can be used
2664 * by the next login attempt.
2667 * qla2x00 local function return status code.
2673 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2674 uint16_t *next_loopid)
2683 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2684 if (rval == QLA_SUCCESS) {
2685 /* Send an ADISC to tape devices.*/
2687 if (fcport->flags & FCF_TAPE_PRESENT)
2689 rval = qla2x00_get_port_database(ha, fcport, opts);
2690 if (rval != QLA_SUCCESS) {
2691 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2692 fcport->d_id.b.domain, fcport->d_id.b.area,
2693 fcport->d_id.b.al_pa);
2694 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2696 qla2x00_update_fcport(ha, fcport);
2704 * qla2x00_fabric_login
2705 * Issue fabric login command.
2708 * ha = adapter block pointer.
2709 * device = pointer to FC device type structure.
2712 * 0 - Login successfully
2714 * 2 - Initiator device
2718 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2719 uint16_t *next_loopid)
2723 uint16_t tmp_loopid;
2724 uint16_t mb[MAILBOX_REGISTER_COUNT];
2730 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2731 "for port %02x%02x%02x.\n",
2732 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2733 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2735 /* Login fcport on switch. */
2736 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2737 fcport->d_id.b.domain, fcport->d_id.b.area,
2738 fcport->d_id.b.al_pa, mb, BIT_0);
2739 if (mb[0] == MBS_PORT_ID_USED) {
2741 * Device has another loop ID. The firmware team
2742 * recommends the driver perform an implicit login with
2743 * the specified ID again. The ID we just used is save
2744 * here so we return with an ID that can be tried by
2748 tmp_loopid = fcport->loop_id;
2749 fcport->loop_id = mb[1];
2751 DEBUG(printk("Fabric Login: port in use - next "
2752 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2753 fcport->loop_id, fcport->d_id.b.domain,
2754 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2756 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2761 /* A retry occurred before. */
2762 *next_loopid = tmp_loopid;
2765 * No retry occurred before. Just increment the
2766 * ID value for next login.
2768 *next_loopid = (fcport->loop_id + 1);
2771 if (mb[1] & BIT_0) {
2772 fcport->port_type = FCT_INITIATOR;
2774 fcport->port_type = FCT_TARGET;
2775 if (mb[1] & BIT_1) {
2776 fcport->flags |= FCF_TAPE_PRESENT;
2781 fcport->supported_classes |= FC_COS_CLASS2;
2783 fcport->supported_classes |= FC_COS_CLASS3;
2787 } else if (mb[0] == MBS_LOOP_ID_USED) {
2789 * Loop ID already used, try next loop ID.
2792 rval = qla2x00_find_new_loop_id(ha, fcport);
2793 if (rval != QLA_SUCCESS) {
2794 /* Ran out of loop IDs to use */
2797 } else if (mb[0] == MBS_COMMAND_ERROR) {
2799 * Firmware possibly timed out during login. If NO
2800 * retries are left to do then the device is declared
2803 *next_loopid = fcport->loop_id;
2804 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2805 fcport->d_id.b.domain, fcport->d_id.b.area,
2806 fcport->d_id.b.al_pa);
2807 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2813 * unrecoverable / not handled error
2815 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2816 "loop_id=%x jiffies=%lx.\n",
2817 __func__, ha->host_no, mb[0],
2818 fcport->d_id.b.domain, fcport->d_id.b.area,
2819 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2821 *next_loopid = fcport->loop_id;
2822 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2823 fcport->d_id.b.domain, fcport->d_id.b.area,
2824 fcport->d_id.b.al_pa);
2825 fcport->loop_id = FC_NO_LOOP_ID;
2826 fcport->login_retry = 0;
2837 * qla2x00_local_device_login
2838 * Issue local device login command.
2841 * ha = adapter block pointer.
2842 * loop_id = loop id of device to login to.
2844 * Returns (Where's the #define!!!!):
2845 * 0 - Login successfully
2850 qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
2853 uint16_t mb[MAILBOX_REGISTER_COUNT];
2855 memset(mb, 0, sizeof(mb));
2856 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
2857 if (rval == QLA_SUCCESS) {
2858 /* Interrogate mailbox registers for any errors */
2859 if (mb[0] == MBS_COMMAND_ERROR)
2861 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
2862 /* device not in PCB table */
2870 * qla2x00_loop_resync
2871 * Resync with fibre channel devices.
2874 * ha = adapter block pointer.
2880 qla2x00_loop_resync(scsi_qla_host_t *ha)
2887 atomic_set(&ha->loop_state, LOOP_UPDATE);
2888 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2889 if (ha->flags.online) {
2890 if (!(rval = qla2x00_fw_ready(ha))) {
2891 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2894 atomic_set(&ha->loop_state, LOOP_UPDATE);
2896 /* Issue a marker after FW becomes ready. */
2897 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
2898 ha->marker_needed = 0;
2900 /* Remap devices on Loop. */
2901 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2903 qla2x00_configure_loop(ha);
2905 } while (!atomic_read(&ha->loop_down_timer) &&
2906 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
2908 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
2912 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2913 return (QLA_FUNCTION_FAILED);
2917 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
2924 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
2930 list_for_each_entry(fcport, &ha->fcports, list) {
2931 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
2934 qla2x00_update_fcport(ha, fcport);
2935 fcport->flags &= ~FCF_RESCAN_NEEDED;
2939 qla2x00_probe_for_all_luns(ha);
2943 qla2x00_update_fcports(scsi_qla_host_t *ha)
2947 /* Go with deferred removal of rport references. */
2948 list_for_each_entry(fcport, &ha->fcports, list)
2950 qla2x00_rport_del(fcport);
2955 * Resets ISP and aborts all outstanding commands.
2958 * ha = adapter block pointer.
2964 qla2x00_abort_isp(scsi_qla_host_t *ha)
2966 unsigned long flags = 0;
2971 if (ha->flags.online) {
2972 ha->flags.online = 0;
2973 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2975 qla_printk(KERN_INFO, ha,
2976 "Performing ISP error recovery - ha= %p.\n", ha);
2977 ha->isp_ops.reset_chip(ha);
2979 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
2980 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
2981 atomic_set(&ha->loop_state, LOOP_DOWN);
2982 qla2x00_mark_all_devices_lost(ha, 0);
2984 if (!atomic_read(&ha->loop_down_timer))
2985 atomic_set(&ha->loop_down_timer,
2989 spin_lock_irqsave(&ha->hardware_lock, flags);
2990 /* Requeue all commands in outstanding command list. */
2991 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
2992 sp = ha->outstanding_cmds[cnt];
2994 ha->outstanding_cmds[cnt] = NULL;
2996 sp->cmd->result = DID_RESET << 16;
2997 sp->cmd->host_scribble = (unsigned char *)NULL;
2998 qla2x00_sp_compl(ha, sp);
3001 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3003 ha->isp_ops.nvram_config(ha);
3005 if (!qla2x00_restart_isp(ha)) {
3006 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3008 if (!atomic_read(&ha->loop_down_timer)) {
3010 * Issue marker command only when we are going
3011 * to start the I/O .
3013 ha->marker_needed = 1;
3016 ha->flags.online = 1;
3018 ha->isp_ops.enable_intrs(ha);
3020 ha->isp_abort_cnt = 0;
3021 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3022 } else { /* failed the ISP abort */
3023 ha->flags.online = 1;
3024 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3025 if (ha->isp_abort_cnt == 0) {
3026 qla_printk(KERN_WARNING, ha,
3027 "ISP error recovery failed - "
3028 "board disabled\n");
3030 * The next call disables the board
3033 ha->isp_ops.reset_adapter(ha);
3034 ha->flags.online = 0;
3035 clear_bit(ISP_ABORT_RETRY,
3038 } else { /* schedule another ISP abort */
3039 ha->isp_abort_cnt--;
3040 DEBUG(printk("qla%ld: ISP abort - "
3041 "retry remaining %d\n",
3042 ha->host_no, ha->isp_abort_cnt);)
3046 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3047 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3048 "- retrying (%d) more times\n",
3049 ha->host_no, ha->isp_abort_cnt);)
3050 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3058 qla_printk(KERN_INFO, ha,
3059 "qla2x00_abort_isp: **** FAILED ****\n");
3061 DEBUG(printk(KERN_INFO
3062 "qla2x00_abort_isp(%ld): exiting.\n",
3070 * qla2x00_restart_isp
3071 * restarts the ISP after a reset
3074 * ha = adapter block pointer.
3080 qla2x00_restart_isp(scsi_qla_host_t *ha)
3083 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3084 unsigned long flags = 0;
3087 /* If firmware needs to be loaded */
3088 if (qla2x00_isp_firmware(ha)) {
3089 ha->flags.online = 0;
3090 if (!(status = ha->isp_ops.chip_diag(ha))) {
3091 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3092 status = qla2x00_setup_chip(ha);
3096 spin_lock_irqsave(&ha->hardware_lock, flags);
3098 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3100 * Disable SRAM, Instruction RAM and GP RAM
3103 WRT_REG_WORD(®->hccr,
3104 (HCCR_ENABLE_PARITY + 0x0));
3105 RD_REG_WORD(®->hccr);
3108 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3110 status = qla2x00_setup_chip(ha);
3112 spin_lock_irqsave(&ha->hardware_lock, flags);
3114 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3115 /* Enable proper parity */
3118 WRT_REG_WORD(®->hccr,
3119 (HCCR_ENABLE_PARITY + 0x1));
3122 * SRAM, Instruction RAM and GP RAM
3125 WRT_REG_WORD(®->hccr,
3126 (HCCR_ENABLE_PARITY + 0x7));
3127 RD_REG_WORD(®->hccr);
3130 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3135 if (!status && !(status = qla2x00_init_rings(ha))) {
3136 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3137 if (!(status = qla2x00_fw_ready(ha))) {
3138 DEBUG(printk("%s(): Start configure loop, "
3139 "status = %d\n", __func__, status);)
3141 /* Issue a marker after FW becomes ready. */
3142 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3144 ha->flags.online = 1;
3145 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3148 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3149 qla2x00_configure_loop(ha);
3151 } while (!atomic_read(&ha->loop_down_timer) &&
3152 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3154 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3157 /* if no cable then assume it's good */
3158 if ((ha->device_flags & DFLG_NO_CABLE))
3161 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3169 * qla2x00_reset_adapter
3173 * ha = adapter block pointer.
3176 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3178 unsigned long flags = 0;
3179 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3181 ha->flags.online = 0;
3182 ha->isp_ops.disable_intrs(ha);
3184 spin_lock_irqsave(&ha->hardware_lock, flags);
3185 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3186 RD_REG_WORD(®->hccr); /* PCI Posting. */
3187 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3188 RD_REG_WORD(®->hccr); /* PCI Posting. */
3189 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3193 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3195 unsigned long flags = 0;
3196 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3198 ha->flags.online = 0;
3199 ha->isp_ops.disable_intrs(ha);
3201 spin_lock_irqsave(&ha->hardware_lock, flags);
3202 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3203 RD_REG_DWORD(®->hccr);
3204 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3205 RD_REG_DWORD(®->hccr);
3206 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3210 qla24xx_nvram_config(scsi_qla_host_t *ha)
3213 struct init_cb_24xx *icb;
3214 struct nvram_24xx *nv;
3216 uint8_t *dptr1, *dptr2;
3221 icb = (struct init_cb_24xx *)ha->init_cb;
3222 nv = (struct nvram_24xx *)ha->request_ring;
3224 /* Determine NVRAM starting address. */
3225 ha->nvram_size = sizeof(struct nvram_24xx);
3226 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3227 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3228 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3229 if (PCI_FUNC(ha->pdev->devfn)) {
3230 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3231 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3234 /* Get NVRAM data and calculate checksum. */
3235 dptr = (uint32_t *)nv;
3236 ha->isp_ops.read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3238 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3239 chksum += le32_to_cpu(*dptr++);
3241 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3242 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3245 /* Bad NVRAM data, set defaults parameters. */
3246 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3247 || nv->id[3] != ' ' ||
3248 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3249 /* Reset NVRAM data. */
3250 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3251 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3252 le16_to_cpu(nv->nvram_version));
3253 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3254 "invalid -- WWPN) defaults.\n");
3257 * Set default initialization control block.
3259 memset(nv, 0, ha->nvram_size);
3260 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3261 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3262 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3263 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3264 nv->exchange_count = __constant_cpu_to_le16(0);
3265 nv->hard_address = __constant_cpu_to_le16(124);
3266 nv->port_name[0] = 0x21;
3267 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3268 nv->port_name[2] = 0x00;
3269 nv->port_name[3] = 0xe0;
3270 nv->port_name[4] = 0x8b;
3271 nv->port_name[5] = 0x1c;
3272 nv->port_name[6] = 0x55;
3273 nv->port_name[7] = 0x86;
3274 nv->node_name[0] = 0x20;
3275 nv->node_name[1] = 0x00;
3276 nv->node_name[2] = 0x00;
3277 nv->node_name[3] = 0xe0;
3278 nv->node_name[4] = 0x8b;
3279 nv->node_name[5] = 0x1c;
3280 nv->node_name[6] = 0x55;
3281 nv->node_name[7] = 0x86;
3282 nv->login_retry_count = __constant_cpu_to_le16(8);
3283 nv->link_down_timeout = __constant_cpu_to_le16(200);
3284 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3285 nv->login_timeout = __constant_cpu_to_le16(0);
3286 nv->firmware_options_1 =
3287 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3288 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3289 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3290 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3291 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3292 nv->efi_parameters = __constant_cpu_to_le32(0);
3293 nv->reset_delay = 5;
3294 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3295 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3296 nv->link_down_timeout = __constant_cpu_to_le16(30);
3301 /* Reset Initialization control block */
3302 memset(icb, 0, sizeof(struct init_cb_24xx));
3304 /* Copy 1st segment. */
3305 dptr1 = (uint8_t *)icb;
3306 dptr2 = (uint8_t *)&nv->version;
3307 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3309 *dptr1++ = *dptr2++;
3311 icb->login_retry_count = nv->login_retry_count;
3312 icb->link_down_timeout = nv->link_down_timeout;
3314 /* Copy 2nd segment. */
3315 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3316 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3317 cnt = (uint8_t *)&icb->reserved_3 -
3318 (uint8_t *)&icb->interrupt_delay_timer;
3320 *dptr1++ = *dptr2++;
3323 * Setup driver NVRAM options.
3325 if (memcmp(nv->model_name, BINZERO, sizeof(nv->model_name)) != 0) {
3329 strncpy(ha->model_number, nv->model_name,
3330 sizeof(nv->model_name));
3331 st = en = ha->model_number;
3332 en += sizeof(nv->model_name) - 1;
3334 if (*en != 0x20 && *en != 0x00)
3339 index = (ha->pdev->subsystem_device & 0xff);
3340 if (index < QLA_MODEL_NAMES)
3341 ha->model_desc = qla2x00_model_name[index * 2 + 1];
3343 strcpy(ha->model_number, "QLA2462");
3345 /* Use alternate WWN? */
3346 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3347 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3348 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3351 /* Prepare nodename */
3352 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3354 * Firmware will apply the following mask if the nodename was
3357 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3358 icb->node_name[0] &= 0xF0;
3361 /* Set host adapter parameters. */
3362 ha->flags.disable_risc_code_load = 0;
3363 ha->flags.enable_lip_reset = 1;
3364 ha->flags.enable_lip_full_login = 1;
3365 ha->flags.enable_target_reset = 1;
3366 ha->flags.enable_led_scheme = 0;
3368 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3369 (BIT_6 | BIT_5 | BIT_4)) >> 4;
3371 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3372 sizeof(ha->fw_seriallink_options24));
3374 /* save HBA serial number */
3375 ha->serial0 = icb->port_name[5];
3376 ha->serial1 = icb->port_name[6];
3377 ha->serial2 = icb->port_name[7];
3378 ha->node_name = icb->node_name;
3379 ha->port_name = icb->port_name;
3381 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3383 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3385 /* Set minimum login_timeout to 4 seconds. */
3386 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3387 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3388 if (le16_to_cpu(nv->login_timeout) < 4)
3389 nv->login_timeout = __constant_cpu_to_le16(4);
3390 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3391 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3393 /* Set minimum RATOV to 200 tenths of a second. */
3396 ha->loop_reset_delay = nv->reset_delay;
3398 /* Link Down Timeout = 0:
3400 * When Port Down timer expires we will start returning
3401 * I/O's to OS with "DID_NO_CONNECT".
3403 * Link Down Timeout != 0:
3405 * The driver waits for the link to come up after link down
3406 * before returning I/Os to OS with "DID_NO_CONNECT".
3408 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3409 ha->loop_down_abort_time =
3410 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3412 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3413 ha->loop_down_abort_time =
3414 (LOOP_DOWN_TIME - ha->link_down_timeout);
3417 /* Need enough time to try and get the port back. */
3418 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3419 if (qlport_down_retry)
3420 ha->port_down_retry_count = qlport_down_retry;
3422 /* Set login_retry_count */
3423 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3424 if (ha->port_down_retry_count ==
3425 le16_to_cpu(nv->port_down_retry_count) &&
3426 ha->port_down_retry_count > 3)
3427 ha->login_retry_count = ha->port_down_retry_count;
3428 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3429 ha->login_retry_count = ha->port_down_retry_count;
3430 if (ql2xloginretrycount)
3431 ha->login_retry_count = ql2xloginretrycount;
3434 if (!ha->flags.init_done) {
3435 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3436 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3437 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3438 le16_to_cpu(icb->interrupt_delay_timer): 2;
3440 icb->firmware_options_2 &= __constant_cpu_to_le32(
3441 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3442 ha->flags.process_response_queue = 0;
3443 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3444 ha->zio_mode = QLA_ZIO_MODE_6;
3446 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3447 "(%d us).\n", ha->host_no, ha->zio_mode,
3448 ha->zio_timer * 100));
3449 qla_printk(KERN_INFO, ha,
3450 "ZIO mode %d enabled; timer delay (%d us).\n",
3451 ha->zio_mode, ha->zio_timer * 100);
3453 icb->firmware_options_2 |= cpu_to_le32(
3454 (uint32_t)ha->zio_mode);
3455 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3456 ha->flags.process_response_queue = 1;
3460 DEBUG2_3(printk(KERN_WARNING
3461 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3467 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3470 int segments, fragment;
3472 uint32_t *dcode, dlen;
3479 segments = FA_RISC_CODE_SEGMENTS;
3480 faddr = FA_RISC_CODE_ADDR;
3481 dcode = (uint32_t *)ha->request_ring;
3484 /* Validate firmware image by checking version. */
3485 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3486 for (i = 0; i < 4; i++)
3487 dcode[i] = be32_to_cpu(dcode[i]);
3488 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3489 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3490 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3492 qla_printk(KERN_WARNING, ha,
3493 "Unable to verify integrity of flash firmware image!\n");
3494 qla_printk(KERN_WARNING, ha,
3495 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3496 dcode[1], dcode[2], dcode[3]);
3498 return QLA_FUNCTION_FAILED;
3501 while (segments && rval == QLA_SUCCESS) {
3502 /* Read segment's load information. */
3503 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3505 risc_addr = be32_to_cpu(dcode[2]);
3506 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3507 risc_size = be32_to_cpu(dcode[3]);
3510 while (risc_size > 0 && rval == QLA_SUCCESS) {
3511 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3512 if (dlen > risc_size)
3515 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3516 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3517 ha->host_no, risc_addr, dlen, faddr));
3519 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3520 for (i = 0; i < dlen; i++)
3521 dcode[i] = swab32(dcode[i]);
3523 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3526 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3527 "segment %d of firmware\n", ha->host_no,
3529 qla_printk(KERN_WARNING, ha,
3530 "[ERROR] Failed to load segment %d of "
3531 "firmware\n", fragment);
3548 #if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
3551 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3555 uint16_t *risc_code;
3556 uint32_t risc_addr, risc_size;
3558 struct qla_fw_info *fw_iter;
3562 /* Load firmware sequences */
3563 fw_iter = ha->brd_info->fw_info;
3564 *srisc_addr = *ha->brd_info->fw_info->fwstart;
3565 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
3566 risc_code = fw_iter->fwcode;
3567 risc_size = *fw_iter->fwlen;
3568 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL)
3569 risc_addr = *fw_iter->fwstart;
3571 risc_addr = *fw_iter->lfwstart;
3575 while (risc_size > 0 && !rval) {
3576 cnt = (uint16_t)(ha->fw_transfer_size >> 1);
3577 if (cnt > risc_size)
3580 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
3581 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
3582 ha->host_no, risc_code, cnt, risc_addr));
3584 req_ring = (uint16_t *)ha->request_ring;
3585 for (i = 0; i < cnt; i++)
3586 req_ring[i] = cpu_to_le16(risc_code[i]);
3588 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3591 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
3592 "load segment %d of firmware\n",
3594 qla_printk(KERN_WARNING, ha,
3595 "[ERROR] Failed to load segment %d of "
3598 qla2x00_dump_regs(ha);
3608 /* Next firmware sequence */
3615 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3619 uint32_t *risc_code;
3620 uint32_t risc_addr, risc_size;
3622 struct qla_fw_info *fw_iter;
3626 /* Load firmware sequences */
3627 fw_iter = ha->brd_info->fw_info;
3628 *srisc_addr = *((uint32_t *)fw_iter->lfwstart);
3629 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
3630 risc_code = (uint32_t *)fw_iter->fwcode;
3631 risc_size = *((uint32_t *)fw_iter->fwlen);
3632 risc_addr = *((uint32_t *)fw_iter->lfwstart);
3636 while (risc_size > 0 && !rval) {
3637 cnt = (uint32_t)(ha->fw_transfer_size >> 2);
3638 if (cnt > risc_size)
3641 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
3642 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
3643 ha->host_no, risc_code, cnt, risc_addr));
3645 req_ring = (uint32_t *)ha->request_ring;
3646 for (i = 0; i < cnt; i++)
3647 req_ring[i] = cpu_to_le32(risc_code[i]);
3649 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3652 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
3653 "load segment %d of firmware\n",
3655 qla_printk(KERN_WARNING, ha,
3656 "[ERROR] Failed to load segment %d of "
3659 qla2x00_dump_regs(ha);
3669 /* Next firmware sequence */
3675 #else /* !defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE) */
3677 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3680 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3684 uint16_t *wcode, *fwcode;
3685 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3686 struct fw_blob *blob;
3688 /* Load firmware blob. */
3689 blob = qla2x00_request_firmware(ha);
3691 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3692 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3693 "from: " QLA_FW_URL ".\n");
3694 return QLA_FUNCTION_FAILED;
3699 wcode = (uint16_t *)ha->request_ring;
3701 fwcode = (uint16_t *)blob->fw->data;
3704 /* Validate firmware image by checking version. */
3705 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3706 qla_printk(KERN_WARNING, ha,
3707 "Unable to verify integrity of firmware image (%Zd)!\n",
3709 goto fail_fw_integrity;
3711 for (i = 0; i < 4; i++)
3712 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3713 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3714 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3715 wcode[2] == 0 && wcode[3] == 0)) {
3716 qla_printk(KERN_WARNING, ha,
3717 "Unable to verify integrity of firmware image!\n");
3718 qla_printk(KERN_WARNING, ha,
3719 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3720 wcode[1], wcode[2], wcode[3]);
3721 goto fail_fw_integrity;
3725 while (*seg && rval == QLA_SUCCESS) {
3727 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3728 risc_size = be16_to_cpu(fwcode[3]);
3730 /* Validate firmware image size. */
3731 fwclen += risc_size * sizeof(uint16_t);
3732 if (blob->fw->size < fwclen) {
3733 qla_printk(KERN_WARNING, ha,
3734 "Unable to verify integrity of firmware image "
3735 "(%Zd)!\n", blob->fw->size);
3736 goto fail_fw_integrity;
3740 while (risc_size > 0 && rval == QLA_SUCCESS) {
3741 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3742 if (wlen > risc_size)
3745 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3746 "addr %x, number of words 0x%x.\n", ha->host_no,
3749 for (i = 0; i < wlen; i++)
3750 wcode[i] = swab16(fwcode[i]);
3752 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3755 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3756 "segment %d of firmware\n", ha->host_no,
3758 qla_printk(KERN_WARNING, ha,
3759 "[ERROR] Failed to load segment %d of "
3760 "firmware\n", fragment);
3776 return QLA_FUNCTION_FAILED;
3780 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3783 int segments, fragment;
3784 uint32_t *dcode, dlen;
3788 struct fw_blob *blob;
3789 uint32_t *fwcode, fwclen;
3791 /* Load firmware blob. */
3792 blob = qla2x00_request_firmware(ha);
3794 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3795 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3796 "from: " QLA_FW_URL ".\n");
3798 /* Try to load RISC code from flash. */
3799 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3800 "outdated) firmware from flash.\n");
3801 return qla24xx_load_risc_flash(ha, srisc_addr);
3806 segments = FA_RISC_CODE_SEGMENTS;
3807 dcode = (uint32_t *)ha->request_ring;
3809 fwcode = (uint32_t *)blob->fw->data;
3812 /* Validate firmware image by checking version. */
3813 if (blob->fw->size < 8 * sizeof(uint32_t)) {
3814 qla_printk(KERN_WARNING, ha,
3815 "Unable to verify integrity of firmware image (%Zd)!\n",
3817 goto fail_fw_integrity;
3819 for (i = 0; i < 4; i++)
3820 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3821 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3822 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3823 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3825 qla_printk(KERN_WARNING, ha,
3826 "Unable to verify integrity of firmware image!\n");
3827 qla_printk(KERN_WARNING, ha,
3828 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3829 dcode[1], dcode[2], dcode[3]);
3830 goto fail_fw_integrity;
3833 while (segments && rval == QLA_SUCCESS) {
3834 risc_addr = be32_to_cpu(fwcode[2]);
3835 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3836 risc_size = be32_to_cpu(fwcode[3]);
3838 /* Validate firmware image size. */
3839 fwclen += risc_size * sizeof(uint32_t);
3840 if (blob->fw->size < fwclen) {
3841 qla_printk(KERN_WARNING, ha,
3842 "Unable to verify integrity of firmware image "
3843 "(%Zd)!\n", blob->fw->size);
3845 goto fail_fw_integrity;
3849 while (risc_size > 0 && rval == QLA_SUCCESS) {
3850 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3851 if (dlen > risc_size)
3854 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3855 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3858 for (i = 0; i < dlen; i++)
3859 dcode[i] = swab32(fwcode[i]);
3861 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3864 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3865 "segment %d of firmware\n", ha->host_no,
3867 qla_printk(KERN_WARNING, ha,
3868 "[ERROR] Failed to load segment %d of "
3869 "firmware\n", fragment);
3885 return QLA_FUNCTION_FAILED;