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 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1712 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1713 fcport->flags = FCF_RLC_SUPPORT;
1714 fcport->supported_classes = FC_COS_UNSPECIFIED;
1715 spin_lock_init(&fcport->rport_lock);
1721 * qla2x00_configure_loop
1722 * Updates Fibre Channel Device Database with what is actually on loop.
1725 * ha = adapter block pointer.
1730 * 2 = database was full and device was not configured.
1733 qla2x00_configure_loop(scsi_qla_host_t *ha)
1736 unsigned long flags, save_flags;
1740 /* Get Initiator ID */
1741 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1742 rval = qla2x00_configure_hba(ha);
1743 if (rval != QLA_SUCCESS) {
1744 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1750 save_flags = flags = ha->dpc_flags;
1751 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1752 ha->host_no, flags));
1755 * If we have both an RSCN and PORT UPDATE pending then handle them
1756 * both at the same time.
1758 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1759 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1761 /* Determine what we need to do */
1762 if (ha->current_topology == ISP_CFG_FL &&
1763 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1765 ha->flags.rscn_queue_overflow = 1;
1766 set_bit(RSCN_UPDATE, &flags);
1768 } else if (ha->current_topology == ISP_CFG_F &&
1769 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1771 ha->flags.rscn_queue_overflow = 1;
1772 set_bit(RSCN_UPDATE, &flags);
1773 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1775 } else if (!ha->flags.online ||
1776 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1778 ha->flags.rscn_queue_overflow = 1;
1779 set_bit(RSCN_UPDATE, &flags);
1780 set_bit(LOCAL_LOOP_UPDATE, &flags);
1783 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1784 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1785 rval = QLA_FUNCTION_FAILED;
1787 rval = qla2x00_configure_local_loop(ha);
1791 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1792 if (LOOP_TRANSITION(ha)) {
1793 rval = QLA_FUNCTION_FAILED;
1795 rval = qla2x00_configure_fabric(ha);
1799 if (rval == QLA_SUCCESS) {
1800 if (atomic_read(&ha->loop_down_timer) ||
1801 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1802 rval = QLA_FUNCTION_FAILED;
1804 atomic_set(&ha->loop_state, LOOP_READY);
1806 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1811 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1812 __func__, ha->host_no));
1814 DEBUG3(printk("%s: exiting normally\n", __func__));
1817 /* Restore state if a resync event occured during processing */
1818 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1819 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1820 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1821 if (test_bit(RSCN_UPDATE, &save_flags))
1822 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1831 * qla2x00_configure_local_loop
1832 * Updates Fibre Channel Device Database with local loop devices.
1835 * ha = adapter block pointer.
1841 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1846 fc_port_t *fcport, *new_fcport;
1852 uint8_t domain, area, al_pa;
1856 entries = MAX_FIBRE_DEVICES;
1858 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1859 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1861 /* Get list of logged in devices. */
1862 memset(ha->gid_list, 0, GID_LIST_SIZE);
1863 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1865 if (rval != QLA_SUCCESS)
1866 goto cleanup_allocation;
1868 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1869 ha->host_no, entries));
1870 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1871 entries * sizeof(struct gid_list_info)));
1873 /* Allocate temporary fcport for any new fcports discovered. */
1874 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1875 if (new_fcport == NULL) {
1876 rval = QLA_MEMORY_ALLOC_FAILED;
1877 goto cleanup_allocation;
1879 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1882 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1884 list_for_each_entry(fcport, &ha->fcports, list) {
1885 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1886 fcport->port_type != FCT_BROADCAST &&
1887 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1889 DEBUG(printk("scsi(%ld): Marking port lost, "
1891 ha->host_no, fcport->loop_id));
1893 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1894 fcport->flags &= ~FCF_FARP_DONE;
1898 /* Add devices to port list. */
1899 id_iter = (char *)ha->gid_list;
1900 for (index = 0; index < entries; index++) {
1901 domain = ((struct gid_list_info *)id_iter)->domain;
1902 area = ((struct gid_list_info *)id_iter)->area;
1903 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1904 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1905 loop_id = (uint16_t)
1906 ((struct gid_list_info *)id_iter)->loop_id_2100;
1908 loop_id = le16_to_cpu(
1909 ((struct gid_list_info *)id_iter)->loop_id);
1910 id_iter += ha->gid_list_info_size;
1912 /* Bypass reserved domain fields. */
1913 if ((domain & 0xf0) == 0xf0)
1916 /* Bypass if not same domain and area of adapter. */
1917 if (area && domain &&
1918 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
1921 /* Bypass invalid local loop ID. */
1922 if (loop_id > LAST_LOCAL_LOOP_ID)
1925 /* Fill in member data. */
1926 new_fcport->d_id.b.domain = domain;
1927 new_fcport->d_id.b.area = area;
1928 new_fcport->d_id.b.al_pa = al_pa;
1929 new_fcport->loop_id = loop_id;
1930 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1931 if (rval2 != QLA_SUCCESS) {
1932 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1933 "information -- get_port_database=%x, "
1935 ha->host_no, rval2, new_fcport->loop_id));
1936 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
1938 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
1942 /* Check for matching device in port list. */
1945 list_for_each_entry(fcport, &ha->fcports, list) {
1946 if (memcmp(new_fcport->port_name, fcport->port_name,
1950 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1951 FCF_PERSISTENT_BOUND);
1952 fcport->loop_id = new_fcport->loop_id;
1953 fcport->port_type = new_fcport->port_type;
1954 fcport->d_id.b24 = new_fcport->d_id.b24;
1955 memcpy(fcport->node_name, new_fcport->node_name,
1963 /* New device, add to fcports list. */
1964 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1965 list_add_tail(&new_fcport->list, &ha->fcports);
1967 /* Allocate a new replacement fcport. */
1968 fcport = new_fcport;
1969 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1970 if (new_fcport == NULL) {
1971 rval = QLA_MEMORY_ALLOC_FAILED;
1972 goto cleanup_allocation;
1974 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1977 qla2x00_update_fcport(ha, fcport);
1985 if (rval != QLA_SUCCESS) {
1986 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1987 "rval=%x\n", ha->host_no, rval));
1991 ha->device_flags |= DFLG_LOCAL_DEVICES;
1992 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
1999 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
2003 qla2x00_mark_all_devices_lost(ha, 0);
2004 list_for_each_entry(fcport, &ha->fcports, list) {
2005 if (fcport->port_type != FCT_TARGET)
2008 qla2x00_update_fcport(ha, fcport);
2013 * qla2x00_update_fcport
2014 * Updates device on list.
2017 * ha = adapter block pointer.
2018 * fcport = port structure pointer.
2028 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2031 fcport->login_retry = 0;
2032 fcport->port_login_retry_count = ha->port_down_retry_count *
2034 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2036 fcport->flags &= ~FCF_LOGIN_NEEDED;
2038 atomic_set(&fcport->state, FCS_ONLINE);
2040 if (ha->flags.init_done)
2041 qla2x00_reg_remote_port(ha, fcport);
2045 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2047 struct fc_rport_identifiers rport_ids;
2048 struct fc_rport *rport;
2049 unsigned long flags;
2052 qla2x00_rport_del(fcport);
2056 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2057 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2058 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2059 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2060 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2061 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2063 qla_printk(KERN_WARNING, ha,
2064 "Unable to allocate fc remote port!\n");
2067 spin_lock_irqsave(&fcport->rport_lock, flags);
2068 fcport->rport = rport;
2069 *((fc_port_t **)rport->dd_data) = fcport;
2070 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2072 rport->supported_classes = fcport->supported_classes;
2074 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2075 if (fcport->port_type == FCT_INITIATOR)
2076 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2077 if (fcport->port_type == FCT_TARGET)
2078 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2079 fc_remote_port_rolechg(rport, rport_ids.roles);
2081 if (rport->scsi_target_id != -1 &&
2082 rport->scsi_target_id < ha->host->max_id)
2083 fcport->os_target_id = rport->scsi_target_id;
2087 * qla2x00_configure_fabric
2088 * Setup SNS devices with loop ID's.
2091 * ha = adapter block pointer.
2098 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2101 fc_port_t *fcport, *fcptemp;
2102 uint16_t next_loopid;
2103 uint16_t mb[MAILBOX_REGISTER_COUNT];
2105 LIST_HEAD(new_fcports);
2107 /* If FL port exists, then SNS is present */
2108 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2109 loop_id = NPH_F_PORT;
2111 loop_id = SNS_FL_PORT;
2112 rval = qla2x00_get_port_name(ha, loop_id, NULL, 0);
2113 if (rval != QLA_SUCCESS) {
2114 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2115 "Port\n", ha->host_no));
2117 ha->device_flags &= ~SWITCH_FOUND;
2118 return (QLA_SUCCESS);
2121 /* Mark devices that need re-synchronization. */
2122 rval2 = qla2x00_device_resync(ha);
2123 if (rval2 == QLA_RSCNS_HANDLED) {
2124 /* No point doing the scan, just continue. */
2125 return (QLA_SUCCESS);
2129 if (ql2xfdmienable &&
2130 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2131 qla2x00_fdmi_register(ha);
2133 /* Ensure we are logged into the SNS. */
2134 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2137 loop_id = SIMPLE_NAME_SERVER;
2138 ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
2139 0xfc, mb, BIT_1 | BIT_0);
2140 if (mb[0] != MBS_COMMAND_COMPLETE) {
2141 DEBUG2(qla_printk(KERN_INFO, ha,
2142 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2143 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2144 mb[0], mb[1], mb[2], mb[6], mb[7]));
2145 return (QLA_SUCCESS);
2148 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2149 if (qla2x00_rft_id(ha)) {
2151 DEBUG2(printk("scsi(%ld): Register FC-4 "
2152 "TYPE failed.\n", ha->host_no));
2154 if (qla2x00_rff_id(ha)) {
2156 DEBUG2(printk("scsi(%ld): Register FC-4 "
2157 "Features failed.\n", ha->host_no));
2159 if (qla2x00_rnn_id(ha)) {
2161 DEBUG2(printk("scsi(%ld): Register Node Name "
2162 "failed.\n", ha->host_no));
2163 } else if (qla2x00_rsnn_nn(ha)) {
2165 DEBUG2(printk("scsi(%ld): Register Symbolic "
2166 "Node Name failed.\n", ha->host_no));
2170 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2171 if (rval != QLA_SUCCESS)
2175 * Logout all previous fabric devices marked lost, except
2178 list_for_each_entry(fcport, &ha->fcports, list) {
2179 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2182 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2185 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2186 qla2x00_mark_device_lost(ha, fcport,
2187 ql2xplogiabsentdevice, 0);
2188 if (fcport->loop_id != FC_NO_LOOP_ID &&
2189 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2190 fcport->port_type != FCT_INITIATOR &&
2191 fcport->port_type != FCT_BROADCAST) {
2192 ha->isp_ops.fabric_logout(ha,
2194 fcport->d_id.b.domain,
2195 fcport->d_id.b.area,
2196 fcport->d_id.b.al_pa);
2197 fcport->loop_id = FC_NO_LOOP_ID;
2202 /* Starting free loop ID. */
2203 next_loopid = ha->min_external_loopid;
2206 * Scan through our port list and login entries that need to be
2209 list_for_each_entry(fcport, &ha->fcports, list) {
2210 if (atomic_read(&ha->loop_down_timer) ||
2211 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2214 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2215 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2218 if (fcport->loop_id == FC_NO_LOOP_ID) {
2219 fcport->loop_id = next_loopid;
2220 rval = qla2x00_find_new_loop_id(ha, fcport);
2221 if (rval != QLA_SUCCESS) {
2222 /* Ran out of IDs to use */
2226 /* Login and update database */
2227 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2230 /* Exit if out of loop IDs. */
2231 if (rval != QLA_SUCCESS) {
2236 * Login and add the new devices to our port list.
2238 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2239 if (atomic_read(&ha->loop_down_timer) ||
2240 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2243 /* Find a new loop ID to use. */
2244 fcport->loop_id = next_loopid;
2245 rval = qla2x00_find_new_loop_id(ha, fcport);
2246 if (rval != QLA_SUCCESS) {
2247 /* Ran out of IDs to use */
2251 /* Remove device from the new list and add it to DB */
2252 list_del(&fcport->list);
2253 list_add_tail(&fcport->list, &ha->fcports);
2255 /* Login and update database */
2256 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2260 /* Free all new device structures not processed. */
2261 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2262 list_del(&fcport->list);
2267 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2268 "rval=%d\n", ha->host_no, rval));
2276 * qla2x00_find_all_fabric_devs
2279 * ha = adapter block pointer.
2280 * dev = database device entry pointer.
2289 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2293 fc_port_t *fcport, *new_fcport, *fcptemp;
2298 int first_dev, last_dev;
2299 port_id_t wrap, nxt_d_id;
2303 /* Try GID_PT to get device list, else GAN. */
2304 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2307 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2308 "on GA_NXT\n", ha->host_no));
2310 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2311 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2314 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2317 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2324 /* Allocate temporary fcport for any new fcports discovered. */
2325 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2326 if (new_fcport == NULL) {
2328 return (QLA_MEMORY_ALLOC_FAILED);
2330 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2332 /* Set start port ID scan at adapter ID. */
2336 /* Starting free loop ID. */
2337 loop_id = ha->min_external_loopid;
2338 for (; loop_id <= ha->last_loop_id; loop_id++) {
2339 if (qla2x00_is_reserved_id(ha, loop_id))
2342 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2347 wrap.b24 = new_fcport->d_id.b24;
2349 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2350 memcpy(new_fcport->node_name,
2351 swl[swl_idx].node_name, WWN_SIZE);
2352 memcpy(new_fcport->port_name,
2353 swl[swl_idx].port_name, WWN_SIZE);
2355 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2361 /* Send GA_NXT to the switch */
2362 rval = qla2x00_ga_nxt(ha, new_fcport);
2363 if (rval != QLA_SUCCESS) {
2364 qla_printk(KERN_WARNING, ha,
2365 "SNS scan failed -- assuming zero-entry "
2367 list_for_each_entry_safe(fcport, fcptemp,
2368 new_fcports, list) {
2369 list_del(&fcport->list);
2377 /* If wrap on switch device list, exit. */
2379 wrap.b24 = new_fcport->d_id.b24;
2381 } else if (new_fcport->d_id.b24 == wrap.b24) {
2382 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2383 ha->host_no, new_fcport->d_id.b.domain,
2384 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2388 /* Bypass if host adapter. */
2389 if (new_fcport->d_id.b24 == ha->d_id.b24)
2392 /* Bypass if same domain and area of adapter. */
2393 if (((new_fcport->d_id.b24 & 0xffff00) ==
2394 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2398 /* Bypass reserved domain fields. */
2399 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2402 /* Locate matching device in database. */
2404 list_for_each_entry(fcport, &ha->fcports, list) {
2405 if (memcmp(new_fcport->port_name, fcport->port_name,
2412 * If address the same and state FCS_ONLINE, nothing
2415 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2416 atomic_read(&fcport->state) == FCS_ONLINE) {
2421 * If device was not a fabric device before.
2423 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2424 fcport->d_id.b24 = new_fcport->d_id.b24;
2425 fcport->loop_id = FC_NO_LOOP_ID;
2426 fcport->flags |= (FCF_FABRIC_DEVICE |
2428 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2433 * Port ID changed or device was marked to be updated;
2434 * Log it out if still logged in and mark it for
2437 fcport->d_id.b24 = new_fcport->d_id.b24;
2438 fcport->flags |= FCF_LOGIN_NEEDED;
2439 if (fcport->loop_id != FC_NO_LOOP_ID &&
2440 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2441 fcport->port_type != FCT_INITIATOR &&
2442 fcport->port_type != FCT_BROADCAST) {
2443 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2444 fcport->d_id.b.domain, fcport->d_id.b.area,
2445 fcport->d_id.b.al_pa);
2446 fcport->loop_id = FC_NO_LOOP_ID;
2455 /* If device was not in our fcports list, then add it. */
2456 list_add_tail(&new_fcport->list, new_fcports);
2458 /* Allocate a new replacement fcport. */
2459 nxt_d_id.b24 = new_fcport->d_id.b24;
2460 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2461 if (new_fcport == NULL) {
2463 return (QLA_MEMORY_ALLOC_FAILED);
2465 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2466 new_fcport->d_id.b24 = nxt_d_id.b24;
2472 if (!list_empty(new_fcports))
2473 ha->device_flags |= DFLG_FABRIC_DEVICES;
2479 * qla2x00_find_new_loop_id
2480 * Scan through our port list and find a new usable loop ID.
2483 * ha: adapter state pointer.
2484 * dev: port structure pointer.
2487 * qla2x00 local function return status code.
2493 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2498 uint16_t first_loop_id;
2502 /* Save starting loop ID. */
2503 first_loop_id = dev->loop_id;
2506 /* Skip loop ID if already used by adapter. */
2507 if (dev->loop_id == ha->loop_id) {
2511 /* Skip reserved loop IDs. */
2512 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2516 /* Reset loop ID if passed the end. */
2517 if (dev->loop_id > ha->last_loop_id) {
2518 /* first loop ID. */
2519 dev->loop_id = ha->min_external_loopid;
2522 /* Check for loop ID being already in use. */
2525 list_for_each_entry(fcport, &ha->fcports, list) {
2526 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2527 /* ID possibly in use */
2533 /* If not in use then it is free to use. */
2538 /* ID in use. Try next value. */
2541 /* If wrap around. No free ID to use. */
2542 if (dev->loop_id == first_loop_id) {
2543 dev->loop_id = FC_NO_LOOP_ID;
2544 rval = QLA_FUNCTION_FAILED;
2553 * qla2x00_device_resync
2554 * Marks devices in the database that needs resynchronization.
2557 * ha = adapter block pointer.
2563 qla2x00_device_resync(scsi_qla_host_t *ha)
2569 uint32_t rscn_entry;
2570 uint8_t rscn_out_iter;
2574 rval = QLA_RSCNS_HANDLED;
2576 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2577 ha->flags.rscn_queue_overflow) {
2579 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2580 format = MSB(MSW(rscn_entry));
2581 d_id.b.domain = LSB(MSW(rscn_entry));
2582 d_id.b.area = MSB(LSW(rscn_entry));
2583 d_id.b.al_pa = LSB(LSW(rscn_entry));
2585 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2586 "[%02x/%02x%02x%02x].\n",
2587 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2588 d_id.b.area, d_id.b.al_pa));
2591 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2592 ha->rscn_out_ptr = 0;
2594 /* Skip duplicate entries. */
2595 for (rscn_out_iter = ha->rscn_out_ptr;
2596 !ha->flags.rscn_queue_overflow &&
2597 rscn_out_iter != ha->rscn_in_ptr;
2598 rscn_out_iter = (rscn_out_iter ==
2599 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2601 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2604 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2605 "entry found at [%d].\n", ha->host_no,
2608 ha->rscn_out_ptr = rscn_out_iter;
2611 /* Queue overflow, set switch default case. */
2612 if (ha->flags.rscn_queue_overflow) {
2613 DEBUG(printk("scsi(%ld): device_resync: rscn "
2614 "overflow.\n", ha->host_no));
2617 ha->flags.rscn_queue_overflow = 0;
2622 if (ql2xprocessrscn &&
2623 !IS_QLA2100(ha) && !IS_QLA2200(ha) &&
2624 !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
2625 !IS_QLA24XX(ha) && !IS_QLA54XX(ha) &&
2626 ha->flags.init_done) {
2627 /* Handle port RSCN via asyncronous IOCBs */
2628 rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
2630 if (rval2 == QLA_SUCCESS)
2644 ha->rscn_out_ptr = ha->rscn_in_ptr;
2650 /* Abort any outstanding IO descriptors. */
2651 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2652 qla2x00_cancel_io_descriptors(ha);
2654 list_for_each_entry(fcport, &ha->fcports, list) {
2655 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2656 (fcport->d_id.b24 & mask) != d_id.b24 ||
2657 fcport->port_type == FCT_BROADCAST)
2660 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2662 fcport->port_type != FCT_INITIATOR) {
2663 qla2x00_mark_device_lost(ha, fcport,
2667 fcport->flags &= ~FCF_FARP_DONE;
2674 * qla2x00_fabric_dev_login
2675 * Login fabric target device and update FC port database.
2678 * ha: adapter state pointer.
2679 * fcport: port structure list pointer.
2680 * next_loopid: contains value of a new loop ID that can be used
2681 * by the next login attempt.
2684 * qla2x00 local function return status code.
2690 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2691 uint16_t *next_loopid)
2700 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2701 if (rval == QLA_SUCCESS) {
2702 /* Send an ADISC to tape devices.*/
2704 if (fcport->flags & FCF_TAPE_PRESENT)
2706 rval = qla2x00_get_port_database(ha, fcport, opts);
2707 if (rval != QLA_SUCCESS) {
2708 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2709 fcport->d_id.b.domain, fcport->d_id.b.area,
2710 fcport->d_id.b.al_pa);
2711 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2713 qla2x00_update_fcport(ha, fcport);
2721 * qla2x00_fabric_login
2722 * Issue fabric login command.
2725 * ha = adapter block pointer.
2726 * device = pointer to FC device type structure.
2729 * 0 - Login successfully
2731 * 2 - Initiator device
2735 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2736 uint16_t *next_loopid)
2740 uint16_t tmp_loopid;
2741 uint16_t mb[MAILBOX_REGISTER_COUNT];
2747 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2748 "for port %02x%02x%02x.\n",
2749 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2750 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2752 /* Login fcport on switch. */
2753 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2754 fcport->d_id.b.domain, fcport->d_id.b.area,
2755 fcport->d_id.b.al_pa, mb, BIT_0);
2756 if (mb[0] == MBS_PORT_ID_USED) {
2758 * Device has another loop ID. The firmware team
2759 * recommends the driver perform an implicit login with
2760 * the specified ID again. The ID we just used is save
2761 * here so we return with an ID that can be tried by
2765 tmp_loopid = fcport->loop_id;
2766 fcport->loop_id = mb[1];
2768 DEBUG(printk("Fabric Login: port in use - next "
2769 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2770 fcport->loop_id, fcport->d_id.b.domain,
2771 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2773 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2778 /* A retry occurred before. */
2779 *next_loopid = tmp_loopid;
2782 * No retry occurred before. Just increment the
2783 * ID value for next login.
2785 *next_loopid = (fcport->loop_id + 1);
2788 if (mb[1] & BIT_0) {
2789 fcport->port_type = FCT_INITIATOR;
2791 fcport->port_type = FCT_TARGET;
2792 if (mb[1] & BIT_1) {
2793 fcport->flags |= FCF_TAPE_PRESENT;
2798 fcport->supported_classes |= FC_COS_CLASS2;
2800 fcport->supported_classes |= FC_COS_CLASS3;
2804 } else if (mb[0] == MBS_LOOP_ID_USED) {
2806 * Loop ID already used, try next loop ID.
2809 rval = qla2x00_find_new_loop_id(ha, fcport);
2810 if (rval != QLA_SUCCESS) {
2811 /* Ran out of loop IDs to use */
2814 } else if (mb[0] == MBS_COMMAND_ERROR) {
2816 * Firmware possibly timed out during login. If NO
2817 * retries are left to do then the device is declared
2820 *next_loopid = fcport->loop_id;
2821 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2822 fcport->d_id.b.domain, fcport->d_id.b.area,
2823 fcport->d_id.b.al_pa);
2824 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2830 * unrecoverable / not handled error
2832 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2833 "loop_id=%x jiffies=%lx.\n",
2834 __func__, ha->host_no, mb[0],
2835 fcport->d_id.b.domain, fcport->d_id.b.area,
2836 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2838 *next_loopid = fcport->loop_id;
2839 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2840 fcport->d_id.b.domain, fcport->d_id.b.area,
2841 fcport->d_id.b.al_pa);
2842 fcport->loop_id = FC_NO_LOOP_ID;
2843 fcport->login_retry = 0;
2854 * qla2x00_local_device_login
2855 * Issue local device login command.
2858 * ha = adapter block pointer.
2859 * loop_id = loop id of device to login to.
2861 * Returns (Where's the #define!!!!):
2862 * 0 - Login successfully
2867 qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
2870 uint16_t mb[MAILBOX_REGISTER_COUNT];
2872 memset(mb, 0, sizeof(mb));
2873 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
2874 if (rval == QLA_SUCCESS) {
2875 /* Interrogate mailbox registers for any errors */
2876 if (mb[0] == MBS_COMMAND_ERROR)
2878 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
2879 /* device not in PCB table */
2887 * qla2x00_loop_resync
2888 * Resync with fibre channel devices.
2891 * ha = adapter block pointer.
2897 qla2x00_loop_resync(scsi_qla_host_t *ha)
2904 atomic_set(&ha->loop_state, LOOP_UPDATE);
2905 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2906 if (ha->flags.online) {
2907 if (!(rval = qla2x00_fw_ready(ha))) {
2908 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2911 atomic_set(&ha->loop_state, LOOP_UPDATE);
2913 /* Issue a marker after FW becomes ready. */
2914 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
2915 ha->marker_needed = 0;
2917 /* Remap devices on Loop. */
2918 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2920 qla2x00_configure_loop(ha);
2922 } while (!atomic_read(&ha->loop_down_timer) &&
2923 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
2925 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
2929 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2930 return (QLA_FUNCTION_FAILED);
2934 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
2941 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
2947 list_for_each_entry(fcport, &ha->fcports, list) {
2948 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
2951 qla2x00_update_fcport(ha, fcport);
2952 fcport->flags &= ~FCF_RESCAN_NEEDED;
2956 qla2x00_probe_for_all_luns(ha);
2960 qla2x00_update_fcports(scsi_qla_host_t *ha)
2964 /* Go with deferred removal of rport references. */
2965 list_for_each_entry(fcport, &ha->fcports, list)
2967 qla2x00_rport_del(fcport);
2972 * Resets ISP and aborts all outstanding commands.
2975 * ha = adapter block pointer.
2981 qla2x00_abort_isp(scsi_qla_host_t *ha)
2983 unsigned long flags = 0;
2988 if (ha->flags.online) {
2989 ha->flags.online = 0;
2990 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2992 qla_printk(KERN_INFO, ha,
2993 "Performing ISP error recovery - ha= %p.\n", ha);
2994 ha->isp_ops.reset_chip(ha);
2996 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
2997 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
2998 atomic_set(&ha->loop_state, LOOP_DOWN);
2999 qla2x00_mark_all_devices_lost(ha, 0);
3001 if (!atomic_read(&ha->loop_down_timer))
3002 atomic_set(&ha->loop_down_timer,
3006 spin_lock_irqsave(&ha->hardware_lock, flags);
3007 /* Requeue all commands in outstanding command list. */
3008 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3009 sp = ha->outstanding_cmds[cnt];
3011 ha->outstanding_cmds[cnt] = NULL;
3013 sp->cmd->result = DID_RESET << 16;
3014 sp->cmd->host_scribble = (unsigned char *)NULL;
3015 qla2x00_sp_compl(ha, sp);
3018 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3020 ha->isp_ops.nvram_config(ha);
3022 if (!qla2x00_restart_isp(ha)) {
3023 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3025 if (!atomic_read(&ha->loop_down_timer)) {
3027 * Issue marker command only when we are going
3028 * to start the I/O .
3030 ha->marker_needed = 1;
3033 ha->flags.online = 1;
3035 ha->isp_ops.enable_intrs(ha);
3037 ha->isp_abort_cnt = 0;
3038 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3039 } else { /* failed the ISP abort */
3040 ha->flags.online = 1;
3041 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3042 if (ha->isp_abort_cnt == 0) {
3043 qla_printk(KERN_WARNING, ha,
3044 "ISP error recovery failed - "
3045 "board disabled\n");
3047 * The next call disables the board
3050 ha->isp_ops.reset_adapter(ha);
3051 ha->flags.online = 0;
3052 clear_bit(ISP_ABORT_RETRY,
3055 } else { /* schedule another ISP abort */
3056 ha->isp_abort_cnt--;
3057 DEBUG(printk("qla%ld: ISP abort - "
3058 "retry remaining %d\n",
3059 ha->host_no, ha->isp_abort_cnt);)
3063 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3064 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3065 "- retrying (%d) more times\n",
3066 ha->host_no, ha->isp_abort_cnt);)
3067 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3075 qla_printk(KERN_INFO, ha,
3076 "qla2x00_abort_isp: **** FAILED ****\n");
3078 DEBUG(printk(KERN_INFO
3079 "qla2x00_abort_isp(%ld): exiting.\n",
3087 * qla2x00_restart_isp
3088 * restarts the ISP after a reset
3091 * ha = adapter block pointer.
3097 qla2x00_restart_isp(scsi_qla_host_t *ha)
3100 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3101 unsigned long flags = 0;
3104 /* If firmware needs to be loaded */
3105 if (qla2x00_isp_firmware(ha)) {
3106 ha->flags.online = 0;
3107 if (!(status = ha->isp_ops.chip_diag(ha))) {
3108 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3109 status = qla2x00_setup_chip(ha);
3113 spin_lock_irqsave(&ha->hardware_lock, flags);
3115 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3117 * Disable SRAM, Instruction RAM and GP RAM
3120 WRT_REG_WORD(®->hccr,
3121 (HCCR_ENABLE_PARITY + 0x0));
3122 RD_REG_WORD(®->hccr);
3125 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3127 status = qla2x00_setup_chip(ha);
3129 spin_lock_irqsave(&ha->hardware_lock, flags);
3131 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3132 /* Enable proper parity */
3135 WRT_REG_WORD(®->hccr,
3136 (HCCR_ENABLE_PARITY + 0x1));
3139 * SRAM, Instruction RAM and GP RAM
3142 WRT_REG_WORD(®->hccr,
3143 (HCCR_ENABLE_PARITY + 0x7));
3144 RD_REG_WORD(®->hccr);
3147 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3152 if (!status && !(status = qla2x00_init_rings(ha))) {
3153 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3154 if (!(status = qla2x00_fw_ready(ha))) {
3155 DEBUG(printk("%s(): Start configure loop, "
3156 "status = %d\n", __func__, status);)
3158 /* Issue a marker after FW becomes ready. */
3159 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3161 ha->flags.online = 1;
3162 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3165 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3166 qla2x00_configure_loop(ha);
3168 } while (!atomic_read(&ha->loop_down_timer) &&
3169 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3171 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3174 /* if no cable then assume it's good */
3175 if ((ha->device_flags & DFLG_NO_CABLE))
3178 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3186 * qla2x00_reset_adapter
3190 * ha = adapter block pointer.
3193 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3195 unsigned long flags = 0;
3196 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3198 ha->flags.online = 0;
3199 ha->isp_ops.disable_intrs(ha);
3201 spin_lock_irqsave(&ha->hardware_lock, flags);
3202 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3203 RD_REG_WORD(®->hccr); /* PCI Posting. */
3204 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3205 RD_REG_WORD(®->hccr); /* PCI Posting. */
3206 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3210 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3212 unsigned long flags = 0;
3213 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3215 ha->flags.online = 0;
3216 ha->isp_ops.disable_intrs(ha);
3218 spin_lock_irqsave(&ha->hardware_lock, flags);
3219 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3220 RD_REG_DWORD(®->hccr);
3221 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3222 RD_REG_DWORD(®->hccr);
3223 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3227 qla24xx_nvram_config(scsi_qla_host_t *ha)
3230 struct init_cb_24xx *icb;
3231 struct nvram_24xx *nv;
3233 uint8_t *dptr1, *dptr2;
3238 icb = (struct init_cb_24xx *)ha->init_cb;
3239 nv = (struct nvram_24xx *)ha->request_ring;
3241 /* Determine NVRAM starting address. */
3242 ha->nvram_size = sizeof(struct nvram_24xx);
3243 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3244 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3245 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3246 if (PCI_FUNC(ha->pdev->devfn)) {
3247 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3248 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3251 /* Get NVRAM data and calculate checksum. */
3252 dptr = (uint32_t *)nv;
3253 ha->isp_ops.read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3255 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3256 chksum += le32_to_cpu(*dptr++);
3258 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3259 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3262 /* Bad NVRAM data, set defaults parameters. */
3263 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3264 || nv->id[3] != ' ' ||
3265 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3266 /* Reset NVRAM data. */
3267 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3268 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3269 le16_to_cpu(nv->nvram_version));
3270 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3271 "invalid -- WWPN) defaults.\n");
3274 * Set default initialization control block.
3276 memset(nv, 0, ha->nvram_size);
3277 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3278 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3279 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3280 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3281 nv->exchange_count = __constant_cpu_to_le16(0);
3282 nv->hard_address = __constant_cpu_to_le16(124);
3283 nv->port_name[0] = 0x21;
3284 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3285 nv->port_name[2] = 0x00;
3286 nv->port_name[3] = 0xe0;
3287 nv->port_name[4] = 0x8b;
3288 nv->port_name[5] = 0x1c;
3289 nv->port_name[6] = 0x55;
3290 nv->port_name[7] = 0x86;
3291 nv->node_name[0] = 0x20;
3292 nv->node_name[1] = 0x00;
3293 nv->node_name[2] = 0x00;
3294 nv->node_name[3] = 0xe0;
3295 nv->node_name[4] = 0x8b;
3296 nv->node_name[5] = 0x1c;
3297 nv->node_name[6] = 0x55;
3298 nv->node_name[7] = 0x86;
3299 nv->login_retry_count = __constant_cpu_to_le16(8);
3300 nv->link_down_timeout = __constant_cpu_to_le16(200);
3301 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3302 nv->login_timeout = __constant_cpu_to_le16(0);
3303 nv->firmware_options_1 =
3304 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3305 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3306 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3307 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3308 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3309 nv->efi_parameters = __constant_cpu_to_le32(0);
3310 nv->reset_delay = 5;
3311 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3312 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3313 nv->link_down_timeout = __constant_cpu_to_le16(30);
3318 /* Reset Initialization control block */
3319 memset(icb, 0, sizeof(struct init_cb_24xx));
3321 /* Copy 1st segment. */
3322 dptr1 = (uint8_t *)icb;
3323 dptr2 = (uint8_t *)&nv->version;
3324 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3326 *dptr1++ = *dptr2++;
3328 icb->login_retry_count = nv->login_retry_count;
3329 icb->link_down_timeout = nv->link_down_timeout;
3331 /* Copy 2nd segment. */
3332 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3333 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3334 cnt = (uint8_t *)&icb->reserved_3 -
3335 (uint8_t *)&icb->interrupt_delay_timer;
3337 *dptr1++ = *dptr2++;
3340 * Setup driver NVRAM options.
3342 if (memcmp(nv->model_name, BINZERO, sizeof(nv->model_name)) != 0) {
3346 strncpy(ha->model_number, nv->model_name,
3347 sizeof(nv->model_name));
3348 st = en = ha->model_number;
3349 en += sizeof(nv->model_name) - 1;
3351 if (*en != 0x20 && *en != 0x00)
3356 index = (ha->pdev->subsystem_device & 0xff);
3357 if (index < QLA_MODEL_NAMES)
3358 ha->model_desc = qla2x00_model_name[index * 2 + 1];
3360 strcpy(ha->model_number, "QLA2462");
3362 /* Use alternate WWN? */
3363 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3364 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3365 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3368 /* Prepare nodename */
3369 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3371 * Firmware will apply the following mask if the nodename was
3374 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3375 icb->node_name[0] &= 0xF0;
3378 /* Set host adapter parameters. */
3379 ha->flags.disable_risc_code_load = 0;
3380 ha->flags.enable_lip_reset = 1;
3381 ha->flags.enable_lip_full_login = 1;
3382 ha->flags.enable_target_reset = 1;
3383 ha->flags.enable_led_scheme = 0;
3385 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3386 (BIT_6 | BIT_5 | BIT_4)) >> 4;
3388 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3389 sizeof(ha->fw_seriallink_options24));
3391 /* save HBA serial number */
3392 ha->serial0 = icb->port_name[5];
3393 ha->serial1 = icb->port_name[6];
3394 ha->serial2 = icb->port_name[7];
3395 ha->node_name = icb->node_name;
3396 ha->port_name = icb->port_name;
3398 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3400 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3402 /* Set minimum login_timeout to 4 seconds. */
3403 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3404 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3405 if (le16_to_cpu(nv->login_timeout) < 4)
3406 nv->login_timeout = __constant_cpu_to_le16(4);
3407 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3408 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3410 /* Set minimum RATOV to 200 tenths of a second. */
3413 ha->loop_reset_delay = nv->reset_delay;
3415 /* Link Down Timeout = 0:
3417 * When Port Down timer expires we will start returning
3418 * I/O's to OS with "DID_NO_CONNECT".
3420 * Link Down Timeout != 0:
3422 * The driver waits for the link to come up after link down
3423 * before returning I/Os to OS with "DID_NO_CONNECT".
3425 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3426 ha->loop_down_abort_time =
3427 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3429 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3430 ha->loop_down_abort_time =
3431 (LOOP_DOWN_TIME - ha->link_down_timeout);
3434 /* Need enough time to try and get the port back. */
3435 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3436 if (qlport_down_retry)
3437 ha->port_down_retry_count = qlport_down_retry;
3439 /* Set login_retry_count */
3440 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3441 if (ha->port_down_retry_count ==
3442 le16_to_cpu(nv->port_down_retry_count) &&
3443 ha->port_down_retry_count > 3)
3444 ha->login_retry_count = ha->port_down_retry_count;
3445 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3446 ha->login_retry_count = ha->port_down_retry_count;
3447 if (ql2xloginretrycount)
3448 ha->login_retry_count = ql2xloginretrycount;
3451 if (!ha->flags.init_done) {
3452 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3453 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3454 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3455 le16_to_cpu(icb->interrupt_delay_timer): 2;
3457 icb->firmware_options_2 &= __constant_cpu_to_le32(
3458 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3459 ha->flags.process_response_queue = 0;
3460 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3461 ha->zio_mode = QLA_ZIO_MODE_6;
3463 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3464 "(%d us).\n", ha->host_no, ha->zio_mode,
3465 ha->zio_timer * 100));
3466 qla_printk(KERN_INFO, ha,
3467 "ZIO mode %d enabled; timer delay (%d us).\n",
3468 ha->zio_mode, ha->zio_timer * 100);
3470 icb->firmware_options_2 |= cpu_to_le32(
3471 (uint32_t)ha->zio_mode);
3472 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3473 ha->flags.process_response_queue = 1;
3477 DEBUG2_3(printk(KERN_WARNING
3478 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3484 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3487 int segments, fragment;
3489 uint32_t *dcode, dlen;
3496 segments = FA_RISC_CODE_SEGMENTS;
3497 faddr = FA_RISC_CODE_ADDR;
3498 dcode = (uint32_t *)ha->request_ring;
3501 /* Validate firmware image by checking version. */
3502 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3503 for (i = 0; i < 4; i++)
3504 dcode[i] = be32_to_cpu(dcode[i]);
3505 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3506 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3507 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3509 qla_printk(KERN_WARNING, ha,
3510 "Unable to verify integrity of flash firmware image!\n");
3511 qla_printk(KERN_WARNING, ha,
3512 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3513 dcode[1], dcode[2], dcode[3]);
3515 return QLA_FUNCTION_FAILED;
3518 while (segments && rval == QLA_SUCCESS) {
3519 /* Read segment's load information. */
3520 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3522 risc_addr = be32_to_cpu(dcode[2]);
3523 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3524 risc_size = be32_to_cpu(dcode[3]);
3527 while (risc_size > 0 && rval == QLA_SUCCESS) {
3528 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3529 if (dlen > risc_size)
3532 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3533 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3534 ha->host_no, risc_addr, dlen, faddr));
3536 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3537 for (i = 0; i < dlen; i++)
3538 dcode[i] = swab32(dcode[i]);
3540 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3543 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3544 "segment %d of firmware\n", ha->host_no,
3546 qla_printk(KERN_WARNING, ha,
3547 "[ERROR] Failed to load segment %d of "
3548 "firmware\n", fragment);
3565 #if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
3568 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3572 uint16_t *risc_code;
3573 uint32_t risc_addr, risc_size;
3575 struct qla_fw_info *fw_iter;
3579 /* Load firmware sequences */
3580 fw_iter = ha->brd_info->fw_info;
3581 *srisc_addr = *ha->brd_info->fw_info->fwstart;
3582 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
3583 risc_code = fw_iter->fwcode;
3584 risc_size = *fw_iter->fwlen;
3585 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL)
3586 risc_addr = *fw_iter->fwstart;
3588 risc_addr = *fw_iter->lfwstart;
3592 while (risc_size > 0 && !rval) {
3593 cnt = (uint16_t)(ha->fw_transfer_size >> 1);
3594 if (cnt > risc_size)
3597 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
3598 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
3599 ha->host_no, risc_code, cnt, risc_addr));
3601 req_ring = (uint16_t *)ha->request_ring;
3602 for (i = 0; i < cnt; i++)
3603 req_ring[i] = cpu_to_le16(risc_code[i]);
3605 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3608 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
3609 "load segment %d of firmware\n",
3611 qla_printk(KERN_WARNING, ha,
3612 "[ERROR] Failed to load segment %d of "
3615 qla2x00_dump_regs(ha);
3625 /* Next firmware sequence */
3632 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3636 uint32_t *risc_code;
3637 uint32_t risc_addr, risc_size;
3639 struct qla_fw_info *fw_iter;
3643 /* Load firmware sequences */
3644 fw_iter = ha->brd_info->fw_info;
3645 *srisc_addr = *((uint32_t *)fw_iter->lfwstart);
3646 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
3647 risc_code = (uint32_t *)fw_iter->fwcode;
3648 risc_size = *((uint32_t *)fw_iter->fwlen);
3649 risc_addr = *((uint32_t *)fw_iter->lfwstart);
3653 while (risc_size > 0 && !rval) {
3654 cnt = (uint32_t)(ha->fw_transfer_size >> 2);
3655 if (cnt > risc_size)
3658 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
3659 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
3660 ha->host_no, risc_code, cnt, risc_addr));
3662 req_ring = (uint32_t *)ha->request_ring;
3663 for (i = 0; i < cnt; i++)
3664 req_ring[i] = cpu_to_le32(risc_code[i]);
3666 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3669 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
3670 "load segment %d of firmware\n",
3672 qla_printk(KERN_WARNING, ha,
3673 "[ERROR] Failed to load segment %d of "
3676 qla2x00_dump_regs(ha);
3686 /* Next firmware sequence */
3692 #else /* !defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE) */
3694 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3697 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3701 uint16_t *wcode, *fwcode;
3702 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3703 struct fw_blob *blob;
3705 /* Load firmware blob. */
3706 blob = qla2x00_request_firmware(ha);
3708 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3709 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3710 "from: " QLA_FW_URL ".\n");
3711 return QLA_FUNCTION_FAILED;
3716 wcode = (uint16_t *)ha->request_ring;
3718 fwcode = (uint16_t *)blob->fw->data;
3721 /* Validate firmware image by checking version. */
3722 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3723 qla_printk(KERN_WARNING, ha,
3724 "Unable to verify integrity of firmware image (%Zd)!\n",
3726 goto fail_fw_integrity;
3728 for (i = 0; i < 4; i++)
3729 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3730 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3731 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3732 wcode[2] == 0 && wcode[3] == 0)) {
3733 qla_printk(KERN_WARNING, ha,
3734 "Unable to verify integrity of firmware image!\n");
3735 qla_printk(KERN_WARNING, ha,
3736 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3737 wcode[1], wcode[2], wcode[3]);
3738 goto fail_fw_integrity;
3742 while (*seg && rval == QLA_SUCCESS) {
3744 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3745 risc_size = be16_to_cpu(fwcode[3]);
3747 /* Validate firmware image size. */
3748 fwclen += risc_size * sizeof(uint16_t);
3749 if (blob->fw->size < fwclen) {
3750 qla_printk(KERN_WARNING, ha,
3751 "Unable to verify integrity of firmware image "
3752 "(%Zd)!\n", blob->fw->size);
3753 goto fail_fw_integrity;
3757 while (risc_size > 0 && rval == QLA_SUCCESS) {
3758 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3759 if (wlen > risc_size)
3762 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3763 "addr %x, number of words 0x%x.\n", ha->host_no,
3766 for (i = 0; i < wlen; i++)
3767 wcode[i] = swab16(fwcode[i]);
3769 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3772 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3773 "segment %d of firmware\n", ha->host_no,
3775 qla_printk(KERN_WARNING, ha,
3776 "[ERROR] Failed to load segment %d of "
3777 "firmware\n", fragment);
3793 return QLA_FUNCTION_FAILED;
3797 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3800 int segments, fragment;
3801 uint32_t *dcode, dlen;
3805 struct fw_blob *blob;
3806 uint32_t *fwcode, fwclen;
3808 /* Load firmware blob. */
3809 blob = qla2x00_request_firmware(ha);
3811 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3812 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3813 "from: " QLA_FW_URL ".\n");
3815 /* Try to load RISC code from flash. */
3816 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3817 "outdated) firmware from flash.\n");
3818 return qla24xx_load_risc_flash(ha, srisc_addr);
3823 segments = FA_RISC_CODE_SEGMENTS;
3824 dcode = (uint32_t *)ha->request_ring;
3826 fwcode = (uint32_t *)blob->fw->data;
3829 /* Validate firmware image by checking version. */
3830 if (blob->fw->size < 8 * sizeof(uint32_t)) {
3831 qla_printk(KERN_WARNING, ha,
3832 "Unable to verify integrity of firmware image (%Zd)!\n",
3834 goto fail_fw_integrity;
3836 for (i = 0; i < 4; i++)
3837 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3838 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3839 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3840 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3842 qla_printk(KERN_WARNING, ha,
3843 "Unable to verify integrity of firmware image!\n");
3844 qla_printk(KERN_WARNING, ha,
3845 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3846 dcode[1], dcode[2], dcode[3]);
3847 goto fail_fw_integrity;
3850 while (segments && rval == QLA_SUCCESS) {
3851 risc_addr = be32_to_cpu(fwcode[2]);
3852 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3853 risc_size = be32_to_cpu(fwcode[3]);
3855 /* Validate firmware image size. */
3856 fwclen += risc_size * sizeof(uint32_t);
3857 if (blob->fw->size < fwclen) {
3858 qla_printk(KERN_WARNING, ha,
3859 "Unable to verify integrity of firmware image "
3860 "(%Zd)!\n", blob->fw->size);
3862 goto fail_fw_integrity;
3866 while (risc_size > 0 && rval == QLA_SUCCESS) {
3867 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3868 if (dlen > risc_size)
3871 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3872 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3875 for (i = 0; i < dlen; i++)
3876 dcode[i] = swab32(fwcode[i]);
3878 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3881 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3882 "segment %d of firmware\n", ha->host_no,
3884 qla_printk(KERN_WARNING, ha,
3885 "[ERROR] Failed to load segment %d of "
3886 "firmware\n", fragment);
3902 return QLA_FUNCTION_FAILED;