2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/delay.h>
10 #include <linux/vmalloc.h>
12 #include "qla_devtbl.h"
14 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
15 #ifndef EXT_IS_LUN_BIT_SET
16 #define EXT_IS_LUN_BIT_SET(P,L) \
17 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
18 #define EXT_SET_LUN_BIT(P,L) \
19 ((P)->mask[L/8] |= (0x80 >> (L%8)))
23 * QLogic ISP2x00 Hardware Support Function Prototypes.
25 static int qla2x00_isp_firmware(scsi_qla_host_t *);
26 static void qla2x00_resize_request_q(scsi_qla_host_t *);
27 static int qla2x00_setup_chip(scsi_qla_host_t *);
28 static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
29 static int qla2x00_init_rings(scsi_qla_host_t *);
30 static int qla2x00_fw_ready(scsi_qla_host_t *);
31 static int qla2x00_configure_hba(scsi_qla_host_t *);
32 static int qla2x00_configure_loop(scsi_qla_host_t *);
33 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
34 static int qla2x00_configure_fabric(scsi_qla_host_t *);
35 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
36 static int qla2x00_device_resync(scsi_qla_host_t *);
37 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
40 static int qla2x00_restart_isp(scsi_qla_host_t *);
42 /****************************************************************************/
43 /* QLogic ISP2x00 Hardware Support Functions. */
44 /****************************************************************************/
47 * qla2x00_initialize_adapter
51 * ha = adapter block pointer.
57 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
60 uint8_t restart_risc = 0;
64 /* Clear adapter flags. */
66 ha->flags.reset_active = 0;
67 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
68 atomic_set(&ha->loop_state, LOOP_DOWN);
71 ha->flags.management_server_logged_in = 0;
72 ha->marker_needed = 0;
74 ha->isp_abort_cnt = 0;
75 ha->beacon_blink_led = 0;
76 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
78 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
79 rval = ha->isp_ops.pci_config(ha);
81 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
86 ha->isp_ops.reset_chip(ha);
88 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
90 ha->isp_ops.nvram_config(ha);
92 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
96 * Try to configure the loop.
101 /* If firmware needs to be loaded */
102 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
103 if ((rval = ha->isp_ops.chip_diag(ha)) == QLA_SUCCESS) {
104 rval = qla2x00_setup_chip(ha);
108 if (rval == QLA_SUCCESS &&
109 (rval = qla2x00_init_rings(ha)) == QLA_SUCCESS) {
110 check_fw_ready_again:
112 * Wait for a successful LIP up to a maximum
113 * of (in seconds): RISC login timeout value,
114 * RISC retry count value, and port down retry
115 * value OR a minimum of 4 seconds OR If no
116 * cable, only 5 seconds.
118 rval = qla2x00_fw_ready(ha);
119 if (rval == QLA_SUCCESS) {
120 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
122 /* Issue a marker after FW becomes ready. */
123 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
126 * Wait at most MAX_TARGET RSCNs for a stable
131 clear_bit(LOOP_RESYNC_NEEDED,
133 rval = qla2x00_configure_loop(ha);
135 if (test_and_clear_bit(ISP_ABORT_NEEDED,
142 * If loop state change while we were
143 * discoverying devices then wait for
147 if (atomic_read(&ha->loop_state) !=
148 LOOP_READY && retry--) {
149 goto check_fw_ready_again;
152 } while (!atomic_read(&ha->loop_down_timer) &&
155 (test_bit(LOOP_RESYNC_NEEDED,
159 rval = QLA_FUNCTION_FAILED;
160 } else if (ha->device_flags & DFLG_NO_CABLE)
161 /* If no cable, then all is good. */
164 } while (restart_risc && retry--);
166 if (rval == QLA_SUCCESS) {
167 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
168 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
169 ha->marker_needed = 0;
171 ha->flags.online = 1;
173 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
180 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
183 * Returns 0 on success.
186 qla2100_pci_config(scsi_qla_host_t *ha)
191 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
193 pci_set_master(ha->pdev);
195 if (pci_set_mwi(ha->pdev))
196 mwi = PCI_COMMAND_INVALIDATE;
197 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
199 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
200 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
201 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
203 /* Reset expansion ROM address decode enable */
204 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
205 d &= ~PCI_ROM_ADDRESS_ENABLE;
206 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
208 /* Get PCI bus information. */
209 spin_lock_irqsave(&ha->hardware_lock, flags);
210 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
211 spin_unlock_irqrestore(&ha->hardware_lock, flags);
217 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
220 * Returns 0 on success.
223 qla2300_pci_config(scsi_qla_host_t *ha)
227 unsigned long flags = 0;
229 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
231 pci_set_master(ha->pdev);
233 if (pci_set_mwi(ha->pdev))
234 mwi = PCI_COMMAND_INVALIDATE;
235 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
237 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
238 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
240 if (IS_QLA2322(ha) || IS_QLA6322(ha))
241 w &= ~PCI_COMMAND_INTX_DISABLE;
244 * If this is a 2300 card and not 2312, reset the
245 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
246 * the 2310 also reports itself as a 2300 so we need to get the
247 * fb revision level -- a 6 indicates it really is a 2300 and
250 if (IS_QLA2300(ha)) {
251 spin_lock_irqsave(&ha->hardware_lock, flags);
254 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
255 for (cnt = 0; cnt < 30000; cnt++) {
256 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
262 /* Select FPM registers. */
263 WRT_REG_WORD(®->ctrl_status, 0x20);
264 RD_REG_WORD(®->ctrl_status);
266 /* Get the fb rev level */
267 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
269 if (ha->fb_rev == FPM_2300)
270 w &= ~PCI_COMMAND_INVALIDATE;
272 /* Deselect FPM registers. */
273 WRT_REG_WORD(®->ctrl_status, 0x0);
274 RD_REG_WORD(®->ctrl_status);
276 /* Release RISC module. */
277 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
278 for (cnt = 0; cnt < 30000; cnt++) {
279 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
285 spin_unlock_irqrestore(&ha->hardware_lock, flags);
287 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
289 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
291 /* Reset expansion ROM address decode enable */
292 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
293 d &= ~PCI_ROM_ADDRESS_ENABLE;
294 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
296 /* Get PCI bus information. */
297 spin_lock_irqsave(&ha->hardware_lock, flags);
298 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
299 spin_unlock_irqrestore(&ha->hardware_lock, flags);
305 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
308 * Returns 0 on success.
311 qla24xx_pci_config(scsi_qla_host_t *ha)
315 unsigned long flags = 0;
316 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
317 int pcix_cmd_reg, pcie_dctl_reg;
319 pci_set_master(ha->pdev);
321 if (pci_set_mwi(ha->pdev))
322 mwi = PCI_COMMAND_INVALIDATE;
323 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
325 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
326 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
327 w &= ~PCI_COMMAND_INTX_DISABLE;
328 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
330 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
332 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
333 pcix_cmd_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX);
337 pcix_cmd_reg += PCI_X_CMD;
338 pci_read_config_word(ha->pdev, pcix_cmd_reg, &pcix_cmd);
339 pcix_cmd &= ~PCI_X_CMD_MAX_READ;
341 pci_write_config_word(ha->pdev, pcix_cmd_reg, pcix_cmd);
344 /* PCIe -- adjust Maximum Read Request Size (2048). */
345 pcie_dctl_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
349 pcie_dctl_reg += PCI_EXP_DEVCTL;
350 pci_read_config_word(ha->pdev, pcie_dctl_reg, &pcie_dctl);
351 pcie_dctl &= ~PCI_EXP_DEVCTL_READRQ;
353 pci_write_config_word(ha->pdev, pcie_dctl_reg, pcie_dctl);
356 /* Reset expansion ROM address decode enable */
357 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
358 d &= ~PCI_ROM_ADDRESS_ENABLE;
359 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
361 /* Get PCI bus information. */
362 spin_lock_irqsave(&ha->hardware_lock, flags);
363 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
364 spin_unlock_irqrestore(&ha->hardware_lock, flags);
370 * qla2x00_isp_firmware() - Choose firmware image.
373 * Returns 0 on success.
376 qla2x00_isp_firmware(scsi_qla_host_t *ha)
380 /* Assume loading risc code */
381 rval = QLA_FUNCTION_FAILED;
383 if (ha->flags.disable_risc_code_load) {
384 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
386 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
388 /* Verify checksum of loaded RISC code. */
389 rval = qla2x00_verify_checksum(ha,
390 IS_QLA24XX(ha) || IS_QLA54XX(ha) ? RISC_SADDRESS :
391 *ha->brd_info->fw_info[0].fwstart);
395 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
403 * qla2x00_reset_chip() - Reset ISP chip.
406 * Returns 0 on success.
409 qla2x00_reset_chip(scsi_qla_host_t *ha)
411 unsigned long flags = 0;
412 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
414 unsigned long mbx_flags = 0;
417 ha->isp_ops.disable_intrs(ha);
419 spin_lock_irqsave(&ha->hardware_lock, flags);
421 /* Turn off master enable */
423 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
424 cmd &= ~PCI_COMMAND_MASTER;
425 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
427 if (!IS_QLA2100(ha)) {
429 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
430 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
431 for (cnt = 0; cnt < 30000; cnt++) {
432 if ((RD_REG_WORD(®->hccr) &
433 HCCR_RISC_PAUSE) != 0)
438 RD_REG_WORD(®->hccr); /* PCI Posting. */
442 /* Select FPM registers. */
443 WRT_REG_WORD(®->ctrl_status, 0x20);
444 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
446 /* FPM Soft Reset. */
447 WRT_REG_WORD(®->fpm_diag_config, 0x100);
448 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
450 /* Toggle Fpm Reset. */
451 if (!IS_QLA2200(ha)) {
452 WRT_REG_WORD(®->fpm_diag_config, 0x0);
453 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
456 /* Select frame buffer registers. */
457 WRT_REG_WORD(®->ctrl_status, 0x10);
458 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
460 /* Reset frame buffer FIFOs. */
461 if (IS_QLA2200(ha)) {
462 WRT_FB_CMD_REG(ha, reg, 0xa000);
463 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
465 WRT_FB_CMD_REG(ha, reg, 0x00fc);
467 /* Read back fb_cmd until zero or 3 seconds max */
468 for (cnt = 0; cnt < 3000; cnt++) {
469 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
475 /* Select RISC module registers. */
476 WRT_REG_WORD(®->ctrl_status, 0);
477 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
479 /* Reset RISC processor. */
480 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
481 RD_REG_WORD(®->hccr); /* PCI Posting. */
483 /* Release RISC processor. */
484 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
485 RD_REG_WORD(®->hccr); /* PCI Posting. */
488 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
489 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
491 /* Reset ISP chip. */
492 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
494 /* Wait for RISC to recover from reset. */
495 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
497 * It is necessary to for a delay here since the card doesn't
498 * respond to PCI reads during a reset. On some architectures
499 * this will result in an MCA.
502 for (cnt = 30000; cnt; cnt--) {
503 if ((RD_REG_WORD(®->ctrl_status) &
504 CSR_ISP_SOFT_RESET) == 0)
511 /* Reset RISC processor. */
512 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
514 WRT_REG_WORD(®->semaphore, 0);
516 /* Release RISC processor. */
517 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
518 RD_REG_WORD(®->hccr); /* PCI Posting. */
520 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
521 for (cnt = 0; cnt < 30000; cnt++) {
522 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
523 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
525 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) {
526 if (!(test_bit(ABORT_ISP_ACTIVE,
528 spin_unlock_irqrestore(
529 &ha->mbx_reg_lock, mbx_flags);
533 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
534 spin_unlock_irqrestore(&ha->mbx_reg_lock,
542 /* Turn on master enable */
543 cmd |= PCI_COMMAND_MASTER;
544 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
546 /* Disable RISC pause on FPM parity error. */
547 if (!IS_QLA2100(ha)) {
548 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
549 RD_REG_WORD(®->hccr); /* PCI Posting. */
552 spin_unlock_irqrestore(&ha->hardware_lock, flags);
556 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
559 * Returns 0 on success.
562 qla24xx_reset_risc(scsi_qla_host_t *ha)
564 unsigned long flags = 0;
565 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
569 spin_lock_irqsave(&ha->hardware_lock, flags);
572 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
573 for (cnt = 0; cnt < 30000; cnt++) {
574 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
580 WRT_REG_DWORD(®->ctrl_status,
581 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
582 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
585 /* Wait for firmware to complete NVRAM accesses. */
586 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
587 for (cnt = 10000 ; cnt && d2; cnt--) {
589 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
593 /* Wait for soft-reset to complete. */
594 d2 = RD_REG_DWORD(®->ctrl_status);
595 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
597 d2 = RD_REG_DWORD(®->ctrl_status);
601 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
602 RD_REG_DWORD(®->hccr);
604 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
605 RD_REG_DWORD(®->hccr);
607 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
608 RD_REG_DWORD(®->hccr);
610 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
611 for (cnt = 6000000 ; cnt && d2; cnt--) {
613 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
617 spin_unlock_irqrestore(&ha->hardware_lock, flags);
621 * qla24xx_reset_chip() - Reset ISP24xx chip.
624 * Returns 0 on success.
627 qla24xx_reset_chip(scsi_qla_host_t *ha)
629 ha->isp_ops.disable_intrs(ha);
631 /* Perform RISC reset. */
632 qla24xx_reset_risc(ha);
636 * qla2x00_chip_diag() - Test chip for proper operation.
639 * Returns 0 on success.
642 qla2x00_chip_diag(scsi_qla_host_t *ha)
645 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
646 unsigned long flags = 0;
651 /* Assume a failed state */
652 rval = QLA_FUNCTION_FAILED;
654 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
655 ha->host_no, (u_long)®->flash_address));
657 spin_lock_irqsave(&ha->hardware_lock, flags);
659 /* Reset ISP chip. */
660 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
663 * We need to have a delay here since the card will not respond while
664 * in reset causing an MCA on some architectures.
667 data = qla2x00_debounce_register(®->ctrl_status);
668 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
670 data = RD_REG_WORD(®->ctrl_status);
675 goto chip_diag_failed;
677 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
680 /* Reset RISC processor. */
681 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
682 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
684 /* Workaround for QLA2312 PCI parity error */
685 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
686 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
687 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
689 data = RD_MAILBOX_REG(ha, reg, 0);
696 goto chip_diag_failed;
698 /* Check product ID of chip */
699 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
701 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
702 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
703 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
704 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
705 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
706 mb[3] != PROD_ID_3) {
707 qla_printk(KERN_WARNING, ha,
708 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
710 goto chip_diag_failed;
712 ha->product_id[0] = mb[1];
713 ha->product_id[1] = mb[2];
714 ha->product_id[2] = mb[3];
715 ha->product_id[3] = mb[4];
717 /* Adjust fw RISC transfer size */
718 if (ha->request_q_length > 1024)
719 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
721 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
722 ha->request_q_length;
724 if (IS_QLA2200(ha) &&
725 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
726 /* Limit firmware transfer size with a 2200A */
727 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
730 ha->device_type |= DT_ISP2200A;
731 ha->fw_transfer_size = 128;
734 /* Wrap Incoming Mailboxes Test. */
735 spin_unlock_irqrestore(&ha->hardware_lock, flags);
737 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
738 rval = qla2x00_mbx_reg_test(ha);
740 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
742 qla_printk(KERN_WARNING, ha,
743 "Failed mailbox send register test\n");
746 /* Flag a successful rval */
749 spin_lock_irqsave(&ha->hardware_lock, flags);
753 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
754 "****\n", ha->host_no));
756 spin_unlock_irqrestore(&ha->hardware_lock, flags);
762 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
765 * Returns 0 on success.
768 qla24xx_chip_diag(scsi_qla_host_t *ha)
772 /* Perform RISC reset. */
773 qla24xx_reset_risc(ha);
775 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
777 rval = qla2x00_mbx_reg_test(ha);
779 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
781 qla_printk(KERN_WARNING, ha,
782 "Failed mailbox send register test\n");
784 /* Flag a successful rval */
792 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
795 ha->fw_dump24_len = sizeof(struct qla24xx_fw_dump);
796 ha->fw_dump24_len += (ha->fw_memory_size - 0x100000) * sizeof(uint32_t);
797 ha->fw_dump24 = vmalloc(ha->fw_dump24_len);
799 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware "
800 "dump...\n", ha->fw_dump24_len / 1024);
802 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
803 "firmware dump!!!\n", ha->fw_dump24_len / 1024);
807 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
810 * Returns 0 on success.
813 qla2x00_resize_request_q(scsi_qla_host_t *ha)
816 uint16_t fw_iocb_cnt = 0;
817 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
818 dma_addr_t request_dma;
819 request_t *request_ring;
821 /* Valid only on recent ISPs. */
822 if (IS_QLA2100(ha) || IS_QLA2200(ha))
825 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
826 qla2x00_alloc_fw_dump(ha);
828 /* Retrieve IOCB counts available to the firmware. */
829 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
832 /* No point in continuing if current settings are sufficient. */
833 if (fw_iocb_cnt < 1024)
835 if (ha->request_q_length >= request_q_length)
838 /* Attempt to claim larger area for request queue. */
839 request_ring = dma_alloc_coherent(&ha->pdev->dev,
840 (request_q_length + 1) * sizeof(request_t), &request_dma,
842 if (request_ring == NULL)
845 /* Resize successful, report extensions. */
846 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
847 (ha->fw_memory_size + 1) / 1024);
848 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
849 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
851 /* Clear old allocations. */
852 dma_free_coherent(&ha->pdev->dev,
853 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
856 /* Begin using larger queue. */
857 ha->request_q_length = request_q_length;
858 ha->request_ring = request_ring;
859 ha->request_dma = request_dma;
863 * qla2x00_setup_chip() - Load and start RISC firmware.
866 * Returns 0 on success.
869 qla2x00_setup_chip(scsi_qla_host_t *ha)
872 uint32_t srisc_address = 0;
874 /* Load firmware sequences */
875 rval = ha->isp_ops.load_risc(ha, &srisc_address);
876 if (rval == QLA_SUCCESS) {
877 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
878 "code.\n", ha->host_no));
880 rval = qla2x00_verify_checksum(ha, srisc_address);
881 if (rval == QLA_SUCCESS) {
882 /* Start firmware execution. */
883 DEBUG(printk("scsi(%ld): Checksum OK, start "
884 "firmware.\n", ha->host_no));
886 rval = qla2x00_execute_fw(ha, srisc_address);
887 /* Retrieve firmware information. */
888 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
889 qla2x00_get_fw_version(ha,
890 &ha->fw_major_version,
891 &ha->fw_minor_version,
892 &ha->fw_subminor_version,
893 &ha->fw_attributes, &ha->fw_memory_size);
894 qla2x00_resize_request_q(ha);
897 DEBUG2(printk(KERN_INFO
898 "scsi(%ld): ISP Firmware failed checksum.\n",
904 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
912 * qla2x00_init_response_q_entries() - Initializes response queue entries.
915 * Beginning of request ring has initialization control block already built
916 * by nvram config routine.
918 * Returns 0 on success.
921 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
926 pkt = ha->response_ring_ptr;
927 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
928 pkt->signature = RESPONSE_PROCESSED;
935 * qla2x00_update_fw_options() - Read and process firmware options.
938 * Returns 0 on success.
941 qla2x00_update_fw_options(scsi_qla_host_t *ha)
943 uint16_t swing, emphasis, tx_sens, rx_sens;
945 memset(ha->fw_options, 0, sizeof(ha->fw_options));
946 qla2x00_get_fw_options(ha, ha->fw_options);
948 if (IS_QLA2100(ha) || IS_QLA2200(ha))
951 /* Serial Link options. */
952 DEBUG3(printk("scsi(%ld): Serial link options:\n",
954 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
955 sizeof(ha->fw_seriallink_options)));
957 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
958 if (ha->fw_seriallink_options[3] & BIT_2) {
959 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
962 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
963 emphasis = (ha->fw_seriallink_options[2] &
964 (BIT_4 | BIT_3)) >> 3;
965 tx_sens = ha->fw_seriallink_options[0] &
966 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
967 rx_sens = (ha->fw_seriallink_options[0] &
968 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
969 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
970 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
973 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
974 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
975 ha->fw_options[10] |= BIT_5 |
976 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
977 (tx_sens & (BIT_1 | BIT_0));
980 swing = (ha->fw_seriallink_options[2] &
981 (BIT_7 | BIT_6 | BIT_5)) >> 5;
982 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
983 tx_sens = ha->fw_seriallink_options[1] &
984 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
985 rx_sens = (ha->fw_seriallink_options[1] &
986 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
987 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
988 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
991 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
992 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
993 ha->fw_options[11] |= BIT_5 |
994 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
995 (tx_sens & (BIT_1 | BIT_0));
999 /* Return command IOCBs without waiting for an ABTS to complete. */
1000 ha->fw_options[3] |= BIT_13;
1003 if (ha->flags.enable_led_scheme)
1004 ha->fw_options[2] |= BIT_12;
1006 /* Detect ISP6312. */
1008 ha->fw_options[2] |= BIT_13;
1010 /* Update firmware options. */
1011 qla2x00_set_fw_options(ha, ha->fw_options);
1015 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1019 /* Update Serial Link options. */
1020 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1023 rval = qla2x00_set_serdes_params(ha,
1024 le16_to_cpu(ha->fw_seriallink_options24[1]),
1025 le16_to_cpu(ha->fw_seriallink_options24[2]),
1026 le16_to_cpu(ha->fw_seriallink_options24[3]));
1027 if (rval != QLA_SUCCESS) {
1028 qla_printk(KERN_WARNING, ha,
1029 "Unable to update Serial Link options (%x).\n", rval);
1034 qla2x00_config_rings(struct scsi_qla_host *ha)
1036 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1038 /* Setup ring parameters in initialization control block. */
1039 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1040 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1041 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1042 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1043 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1044 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1045 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1046 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1048 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1049 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1050 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1051 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1052 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1056 qla24xx_config_rings(struct scsi_qla_host *ha)
1058 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1059 struct init_cb_24xx *icb;
1061 /* Setup ring parameters in initialization control block. */
1062 icb = (struct init_cb_24xx *)ha->init_cb;
1063 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1064 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1065 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1066 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1067 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1068 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1069 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1070 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1072 WRT_REG_DWORD(®->req_q_in, 0);
1073 WRT_REG_DWORD(®->req_q_out, 0);
1074 WRT_REG_DWORD(®->rsp_q_in, 0);
1075 WRT_REG_DWORD(®->rsp_q_out, 0);
1076 RD_REG_DWORD(®->rsp_q_out);
1080 * qla2x00_init_rings() - Initializes firmware.
1083 * Beginning of request ring has initialization control block already built
1084 * by nvram config routine.
1086 * Returns 0 on success.
1089 qla2x00_init_rings(scsi_qla_host_t *ha)
1092 unsigned long flags = 0;
1095 spin_lock_irqsave(&ha->hardware_lock, flags);
1097 /* Clear outstanding commands array. */
1098 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1099 ha->outstanding_cmds[cnt] = NULL;
1101 ha->current_outstanding_cmd = 0;
1103 /* Clear RSCN queue. */
1104 ha->rscn_in_ptr = 0;
1105 ha->rscn_out_ptr = 0;
1107 /* Initialize firmware. */
1108 ha->request_ring_ptr = ha->request_ring;
1109 ha->req_ring_index = 0;
1110 ha->req_q_cnt = ha->request_q_length;
1111 ha->response_ring_ptr = ha->response_ring;
1112 ha->rsp_ring_index = 0;
1114 /* Initialize response queue entries */
1115 qla2x00_init_response_q_entries(ha);
1117 ha->isp_ops.config_rings(ha);
1119 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1121 /* Update any ISP specific firmware options before initialization. */
1122 ha->isp_ops.update_fw_options(ha);
1124 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1125 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1127 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1130 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1138 * qla2x00_fw_ready() - Waits for firmware ready.
1141 * Returns 0 on success.
1144 qla2x00_fw_ready(scsi_qla_host_t *ha)
1147 unsigned long wtime, mtime;
1148 uint16_t min_wait; /* Minimum wait time if loop is down */
1149 uint16_t wait_time; /* Wait time if loop is coming ready */
1154 /* 20 seconds for loop down. */
1158 * Firmware should take at most one RATOV to login, plus 5 seconds for
1159 * our own processing.
1161 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1162 wait_time = min_wait;
1165 /* Min wait time if loop down */
1166 mtime = jiffies + (min_wait * HZ);
1168 /* wait time before firmware ready */
1169 wtime = jiffies + (wait_time * HZ);
1171 /* Wait for ISP to finish LIP */
1172 if (!ha->flags.init_done)
1173 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1175 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1179 rval = qla2x00_get_firmware_state(ha, &fw_state);
1180 if (rval == QLA_SUCCESS) {
1181 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1182 ha->device_flags &= ~DFLG_NO_CABLE;
1184 if (fw_state == FSTATE_READY) {
1185 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1188 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1189 &ha->login_timeout, &ha->r_a_tov);
1195 rval = QLA_FUNCTION_FAILED;
1197 if (atomic_read(&ha->loop_down_timer) &&
1198 (fw_state >= FSTATE_LOSS_OF_SYNC ||
1199 fw_state == FSTATE_WAIT_AL_PA)) {
1200 /* Loop down. Timeout on min_wait for states
1201 * other than Wait for Login.
1203 if (time_after_eq(jiffies, mtime)) {
1204 qla_printk(KERN_INFO, ha,
1205 "Cable is unplugged...\n");
1207 ha->device_flags |= DFLG_NO_CABLE;
1212 /* Mailbox cmd failed. Timeout on min_wait. */
1213 if (time_after_eq(jiffies, mtime))
1217 if (time_after_eq(jiffies, wtime))
1220 /* Delay for a while */
1223 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1224 ha->host_no, fw_state, jiffies));
1227 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1228 ha->host_no, fw_state, jiffies));
1231 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1239 * qla2x00_configure_hba
1240 * Setup adapter context.
1243 * ha = adapter state pointer.
1252 qla2x00_configure_hba(scsi_qla_host_t *ha)
1260 char connect_type[22];
1262 /* Get host addresses. */
1263 rval = qla2x00_get_adapter_id(ha,
1264 &loop_id, &al_pa, &area, &domain, &topo);
1265 if (rval != QLA_SUCCESS) {
1266 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
1267 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1268 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1269 __func__, ha->host_no));
1271 qla_printk(KERN_WARNING, ha,
1272 "ERROR -- Unable to get host loop ID.\n");
1273 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1279 qla_printk(KERN_INFO, ha,
1280 "Cannot get topology - retrying.\n");
1281 return (QLA_FUNCTION_FAILED);
1284 ha->loop_id = loop_id;
1287 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1288 ha->operating_mode = LOOP;
1292 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1294 ha->current_topology = ISP_CFG_NL;
1295 strcpy(connect_type, "(Loop)");
1299 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1301 ha->current_topology = ISP_CFG_FL;
1302 strcpy(connect_type, "(FL_Port)");
1306 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1308 ha->operating_mode = P2P;
1309 ha->current_topology = ISP_CFG_N;
1310 strcpy(connect_type, "(N_Port-to-N_Port)");
1314 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1316 ha->operating_mode = P2P;
1317 ha->current_topology = ISP_CFG_F;
1318 strcpy(connect_type, "(F_Port)");
1322 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1324 ha->host_no, topo));
1325 ha->current_topology = ISP_CFG_NL;
1326 strcpy(connect_type, "(Loop)");
1330 /* Save Host port and loop ID. */
1331 /* byte order - Big Endian */
1332 ha->d_id.b.domain = domain;
1333 ha->d_id.b.area = area;
1334 ha->d_id.b.al_pa = al_pa;
1336 if (!ha->flags.init_done)
1337 qla_printk(KERN_INFO, ha,
1338 "Topology - %s, Host Loop address 0x%x\n",
1339 connect_type, ha->loop_id);
1342 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1344 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1351 * NVRAM configuration for ISP 2xxx
1354 * ha = adapter block pointer.
1357 * initialization control block in response_ring
1358 * host adapters parameters in host adapter block
1364 qla2x00_nvram_config(scsi_qla_host_t *ha)
1369 uint8_t *dptr1, *dptr2;
1370 init_cb_t *icb = ha->init_cb;
1371 nvram_t *nv = (nvram_t *)ha->request_ring;
1372 uint8_t *ptr = (uint8_t *)ha->request_ring;
1373 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1377 /* Determine NVRAM starting address. */
1378 ha->nvram_size = sizeof(nvram_t);
1380 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1381 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1382 ha->nvram_base = 0x80;
1384 /* Get NVRAM data and calculate checksum. */
1385 ha->isp_ops.read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1386 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1389 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1390 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1393 /* Bad NVRAM data, set defaults parameters. */
1394 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1395 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1396 /* Reset NVRAM data. */
1397 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1398 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1400 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1401 "invalid -- WWPN) defaults.\n");
1404 * Set default initialization control block.
1406 memset(nv, 0, ha->nvram_size);
1407 nv->parameter_block_version = ICB_VERSION;
1409 if (IS_QLA23XX(ha)) {
1410 nv->firmware_options[0] = BIT_2 | BIT_1;
1411 nv->firmware_options[1] = BIT_7 | BIT_5;
1412 nv->add_firmware_options[0] = BIT_5;
1413 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1414 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1415 nv->special_options[1] = BIT_7;
1416 } else if (IS_QLA2200(ha)) {
1417 nv->firmware_options[0] = BIT_2 | BIT_1;
1418 nv->firmware_options[1] = BIT_7 | BIT_5;
1419 nv->add_firmware_options[0] = BIT_5;
1420 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1421 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1422 } else if (IS_QLA2100(ha)) {
1423 nv->firmware_options[0] = BIT_3 | BIT_1;
1424 nv->firmware_options[1] = BIT_5;
1425 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1428 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1429 nv->execution_throttle = __constant_cpu_to_le16(16);
1430 nv->retry_count = 8;
1431 nv->retry_delay = 1;
1433 nv->port_name[0] = 33;
1434 nv->port_name[3] = 224;
1435 nv->port_name[4] = 139;
1437 nv->login_timeout = 4;
1440 * Set default host adapter parameters
1442 nv->host_p[1] = BIT_2;
1443 nv->reset_delay = 5;
1444 nv->port_down_retry_count = 8;
1445 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1446 nv->link_down_timeout = 60;
1451 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1453 * The SN2 does not provide BIOS emulation which means you can't change
1454 * potentially bogus BIOS settings. Force the use of default settings
1455 * for link rate and frame size. Hope that the rest of the settings
1458 if (ia64_platform_is("sn2")) {
1459 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1461 nv->special_options[1] = BIT_7;
1465 /* Reset Initialization control block */
1466 memset(icb, 0, ha->init_cb_size);
1469 * Setup driver NVRAM options.
1471 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1472 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1473 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1474 nv->firmware_options[1] &= ~BIT_4;
1476 if (IS_QLA23XX(ha)) {
1477 nv->firmware_options[0] |= BIT_2;
1478 nv->firmware_options[0] &= ~BIT_3;
1479 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1481 if (IS_QLA2300(ha)) {
1482 if (ha->fb_rev == FPM_2310) {
1483 strcpy(ha->model_number, "QLA2310");
1485 strcpy(ha->model_number, "QLA2300");
1489 memcmp(nv->model_number, BINZERO,
1490 sizeof(nv->model_number)) != 0) {
1493 strncpy(ha->model_number, nv->model_number,
1494 sizeof(nv->model_number));
1495 st = en = ha->model_number;
1496 en += sizeof(nv->model_number) - 1;
1498 if (*en != 0x20 && *en != 0x00)
1505 index = (ha->pdev->subsystem_device & 0xff);
1506 if (index < QLA_MODEL_NAMES) {
1507 strcpy(ha->model_number,
1508 qla2x00_model_name[index * 2]);
1510 qla2x00_model_name[index * 2 + 1];
1512 strcpy(ha->model_number, "QLA23xx");
1516 } else if (IS_QLA2200(ha)) {
1517 nv->firmware_options[0] |= BIT_2;
1519 * 'Point-to-point preferred, else loop' is not a safe
1520 * connection mode setting.
1522 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1524 /* Force 'loop preferred, else point-to-point'. */
1525 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1526 nv->add_firmware_options[0] |= BIT_5;
1528 strcpy(ha->model_number, "QLA22xx");
1529 } else /*if (IS_QLA2100(ha))*/ {
1530 strcpy(ha->model_number, "QLA2100");
1534 * Copy over NVRAM RISC parameter block to initialization control block.
1536 dptr1 = (uint8_t *)icb;
1537 dptr2 = (uint8_t *)&nv->parameter_block_version;
1538 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1540 *dptr1++ = *dptr2++;
1542 /* Copy 2nd half. */
1543 dptr1 = (uint8_t *)icb->add_firmware_options;
1544 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1546 *dptr1++ = *dptr2++;
1548 /* Prepare nodename */
1549 if ((icb->firmware_options[1] & BIT_6) == 0) {
1551 * Firmware will apply the following mask if the nodename was
1554 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1555 icb->node_name[0] &= 0xF0;
1559 * Set host adapter parameters.
1561 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1562 /* Always load RISC code on non ISP2[12]00 chips. */
1563 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1564 ha->flags.disable_risc_code_load = 0;
1565 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1566 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1567 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1568 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1570 ha->operating_mode =
1571 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1573 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1574 sizeof(ha->fw_seriallink_options));
1576 /* save HBA serial number */
1577 ha->serial0 = icb->port_name[5];
1578 ha->serial1 = icb->port_name[6];
1579 ha->serial2 = icb->port_name[7];
1580 ha->node_name = icb->node_name;
1581 ha->port_name = icb->port_name;
1583 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1585 ha->retry_count = nv->retry_count;
1587 /* Set minimum login_timeout to 4 seconds. */
1588 if (nv->login_timeout < ql2xlogintimeout)
1589 nv->login_timeout = ql2xlogintimeout;
1590 if (nv->login_timeout < 4)
1591 nv->login_timeout = 4;
1592 ha->login_timeout = nv->login_timeout;
1593 icb->login_timeout = nv->login_timeout;
1595 /* Set minimum RATOV to 200 tenths of a second. */
1598 ha->loop_reset_delay = nv->reset_delay;
1600 /* Link Down Timeout = 0:
1602 * When Port Down timer expires we will start returning
1603 * I/O's to OS with "DID_NO_CONNECT".
1605 * Link Down Timeout != 0:
1607 * The driver waits for the link to come up after link down
1608 * before returning I/Os to OS with "DID_NO_CONNECT".
1610 if (nv->link_down_timeout == 0) {
1611 ha->loop_down_abort_time =
1612 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1614 ha->link_down_timeout = nv->link_down_timeout;
1615 ha->loop_down_abort_time =
1616 (LOOP_DOWN_TIME - ha->link_down_timeout);
1620 * Need enough time to try and get the port back.
1622 ha->port_down_retry_count = nv->port_down_retry_count;
1623 if (qlport_down_retry)
1624 ha->port_down_retry_count = qlport_down_retry;
1625 /* Set login_retry_count */
1626 ha->login_retry_count = nv->retry_count;
1627 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1628 ha->port_down_retry_count > 3)
1629 ha->login_retry_count = ha->port_down_retry_count;
1630 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1631 ha->login_retry_count = ha->port_down_retry_count;
1632 if (ql2xloginretrycount)
1633 ha->login_retry_count = ql2xloginretrycount;
1635 icb->lun_enables = __constant_cpu_to_le16(0);
1636 icb->command_resource_count = 0;
1637 icb->immediate_notify_resource_count = 0;
1638 icb->timeout = __constant_cpu_to_le16(0);
1640 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1642 icb->firmware_options[0] &= ~BIT_3;
1643 icb->add_firmware_options[0] &=
1644 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1645 icb->add_firmware_options[0] |= BIT_2;
1646 icb->response_accumulation_timer = 3;
1647 icb->interrupt_delay_timer = 5;
1649 ha->flags.process_response_queue = 1;
1652 if (!ha->flags.init_done) {
1653 ha->zio_mode = icb->add_firmware_options[0] &
1654 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1655 ha->zio_timer = icb->interrupt_delay_timer ?
1656 icb->interrupt_delay_timer: 2;
1658 icb->add_firmware_options[0] &=
1659 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1660 ha->flags.process_response_queue = 0;
1661 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1662 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1663 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1664 ha->zio_timer * 100));
1665 qla_printk(KERN_INFO, ha,
1666 "ZIO mode %d enabled; timer delay (%d us).\n",
1667 ha->zio_mode, ha->zio_timer * 100);
1669 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1670 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1671 ha->flags.process_response_queue = 1;
1676 DEBUG2_3(printk(KERN_WARNING
1677 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1683 qla2x00_rport_add(void *data)
1685 fc_port_t *fcport = data;
1687 qla2x00_reg_remote_port(fcport->ha, fcport);
1691 qla2x00_rport_del(void *data)
1693 fc_port_t *fcport = data;
1694 struct fc_rport *rport;
1695 unsigned long flags;
1697 spin_lock_irqsave(&fcport->rport_lock, flags);
1698 rport = fcport->drport;
1699 fcport->drport = NULL;
1700 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1702 fc_remote_port_delete(rport);
1707 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1709 * @flags: allocation flags
1711 * Returns a pointer to the allocated fcport, or NULL, if none available.
1714 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1718 fcport = kmalloc(sizeof(fc_port_t), flags);
1722 /* Setup fcport template structure. */
1723 memset(fcport, 0, sizeof (fc_port_t));
1725 fcport->port_type = FCT_UNKNOWN;
1726 fcport->loop_id = FC_NO_LOOP_ID;
1727 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1728 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1729 fcport->flags = FCF_RLC_SUPPORT;
1730 fcport->supported_classes = FC_COS_UNSPECIFIED;
1731 spin_lock_init(&fcport->rport_lock);
1732 INIT_WORK(&fcport->rport_add_work, qla2x00_rport_add, fcport);
1733 INIT_WORK(&fcport->rport_del_work, qla2x00_rport_del, fcport);
1739 * qla2x00_configure_loop
1740 * Updates Fibre Channel Device Database with what is actually on loop.
1743 * ha = adapter block pointer.
1748 * 2 = database was full and device was not configured.
1751 qla2x00_configure_loop(scsi_qla_host_t *ha)
1754 unsigned long flags, save_flags;
1758 /* Get Initiator ID */
1759 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1760 rval = qla2x00_configure_hba(ha);
1761 if (rval != QLA_SUCCESS) {
1762 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1768 save_flags = flags = ha->dpc_flags;
1769 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1770 ha->host_no, flags));
1773 * If we have both an RSCN and PORT UPDATE pending then handle them
1774 * both at the same time.
1776 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1777 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1779 /* Determine what we need to do */
1780 if (ha->current_topology == ISP_CFG_FL &&
1781 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1783 ha->flags.rscn_queue_overflow = 1;
1784 set_bit(RSCN_UPDATE, &flags);
1786 } else if (ha->current_topology == ISP_CFG_F &&
1787 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1789 ha->flags.rscn_queue_overflow = 1;
1790 set_bit(RSCN_UPDATE, &flags);
1791 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1793 } else if (!ha->flags.online ||
1794 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1796 ha->flags.rscn_queue_overflow = 1;
1797 set_bit(RSCN_UPDATE, &flags);
1798 set_bit(LOCAL_LOOP_UPDATE, &flags);
1801 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1802 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1803 rval = QLA_FUNCTION_FAILED;
1805 rval = qla2x00_configure_local_loop(ha);
1809 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1810 if (LOOP_TRANSITION(ha)) {
1811 rval = QLA_FUNCTION_FAILED;
1813 rval = qla2x00_configure_fabric(ha);
1817 if (rval == QLA_SUCCESS) {
1818 if (atomic_read(&ha->loop_down_timer) ||
1819 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1820 rval = QLA_FUNCTION_FAILED;
1822 atomic_set(&ha->loop_state, LOOP_READY);
1824 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1829 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1830 __func__, ha->host_no));
1832 DEBUG3(printk("%s: exiting normally\n", __func__));
1835 /* Restore state if a resync event occured during processing */
1836 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1837 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1838 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1839 if (test_bit(RSCN_UPDATE, &save_flags))
1840 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1849 * qla2x00_configure_local_loop
1850 * Updates Fibre Channel Device Database with local loop devices.
1853 * ha = adapter block pointer.
1859 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1864 fc_port_t *fcport, *new_fcport;
1870 uint8_t domain, area, al_pa;
1874 entries = MAX_FIBRE_DEVICES;
1876 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1877 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1879 /* Get list of logged in devices. */
1880 memset(ha->gid_list, 0, GID_LIST_SIZE);
1881 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1883 if (rval != QLA_SUCCESS)
1884 goto cleanup_allocation;
1886 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1887 ha->host_no, entries));
1888 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1889 entries * sizeof(struct gid_list_info)));
1891 /* Allocate temporary fcport for any new fcports discovered. */
1892 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1893 if (new_fcport == NULL) {
1894 rval = QLA_MEMORY_ALLOC_FAILED;
1895 goto cleanup_allocation;
1897 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1900 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1902 list_for_each_entry(fcport, &ha->fcports, list) {
1903 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1904 fcport->port_type != FCT_BROADCAST &&
1905 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1907 DEBUG(printk("scsi(%ld): Marking port lost, "
1909 ha->host_no, fcport->loop_id));
1911 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1912 fcport->flags &= ~FCF_FARP_DONE;
1916 /* Add devices to port list. */
1917 id_iter = (char *)ha->gid_list;
1918 for (index = 0; index < entries; index++) {
1919 domain = ((struct gid_list_info *)id_iter)->domain;
1920 area = ((struct gid_list_info *)id_iter)->area;
1921 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1922 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1923 loop_id = (uint16_t)
1924 ((struct gid_list_info *)id_iter)->loop_id_2100;
1926 loop_id = le16_to_cpu(
1927 ((struct gid_list_info *)id_iter)->loop_id);
1928 id_iter += ha->gid_list_info_size;
1930 /* Bypass reserved domain fields. */
1931 if ((domain & 0xf0) == 0xf0)
1934 /* Bypass if not same domain and area of adapter. */
1935 if (area && domain &&
1936 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
1939 /* Bypass invalid local loop ID. */
1940 if (loop_id > LAST_LOCAL_LOOP_ID)
1943 /* Fill in member data. */
1944 new_fcport->d_id.b.domain = domain;
1945 new_fcport->d_id.b.area = area;
1946 new_fcport->d_id.b.al_pa = al_pa;
1947 new_fcport->loop_id = loop_id;
1948 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1949 if (rval2 != QLA_SUCCESS) {
1950 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1951 "information -- get_port_database=%x, "
1953 ha->host_no, rval2, new_fcport->loop_id));
1954 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
1956 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
1960 /* Check for matching device in port list. */
1963 list_for_each_entry(fcport, &ha->fcports, list) {
1964 if (memcmp(new_fcport->port_name, fcport->port_name,
1968 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1969 FCF_PERSISTENT_BOUND);
1970 fcport->loop_id = new_fcport->loop_id;
1971 fcport->port_type = new_fcport->port_type;
1972 fcport->d_id.b24 = new_fcport->d_id.b24;
1973 memcpy(fcport->node_name, new_fcport->node_name,
1981 /* New device, add to fcports list. */
1982 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1983 list_add_tail(&new_fcport->list, &ha->fcports);
1985 /* Allocate a new replacement fcport. */
1986 fcport = new_fcport;
1987 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1988 if (new_fcport == NULL) {
1989 rval = QLA_MEMORY_ALLOC_FAILED;
1990 goto cleanup_allocation;
1992 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1995 qla2x00_update_fcport(ha, fcport);
2003 if (rval != QLA_SUCCESS) {
2004 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2005 "rval=%x\n", ha->host_no, rval));
2009 ha->device_flags |= DFLG_LOCAL_DEVICES;
2010 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2017 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
2021 qla2x00_mark_all_devices_lost(ha, 0);
2022 list_for_each_entry(fcport, &ha->fcports, list) {
2023 if (fcport->port_type != FCT_TARGET)
2026 qla2x00_update_fcport(ha, fcport);
2031 * qla2x00_update_fcport
2032 * Updates device on list.
2035 * ha = adapter block pointer.
2036 * fcport = port structure pointer.
2046 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2049 fcport->login_retry = 0;
2050 fcport->port_login_retry_count = ha->port_down_retry_count *
2052 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2054 fcport->flags &= ~FCF_LOGIN_NEEDED;
2056 if (fcport->port_type == FCT_INITIATOR ||
2057 fcport->port_type == FCT_BROADCAST)
2058 fcport->device_type = TYPE_PROCESSOR;
2060 atomic_set(&fcport->state, FCS_ONLINE);
2062 if (ha->flags.init_done)
2063 qla2x00_reg_remote_port(ha, fcport);
2067 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2069 struct fc_rport_identifiers rport_ids;
2070 struct fc_rport *rport;
2071 unsigned long flags;
2074 qla2x00_rport_del(fcport);
2078 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2079 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2080 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2081 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2082 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2083 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2085 qla_printk(KERN_WARNING, ha,
2086 "Unable to allocate fc remote port!\n");
2089 spin_lock_irqsave(&fcport->rport_lock, flags);
2090 fcport->rport = rport;
2091 *((fc_port_t **)rport->dd_data) = fcport;
2092 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2094 rport->supported_classes = fcport->supported_classes;
2096 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2097 if (fcport->port_type == FCT_INITIATOR)
2098 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2099 if (fcport->port_type == FCT_TARGET)
2100 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2101 fc_remote_port_rolechg(rport, rport_ids.roles);
2103 if (rport->scsi_target_id != -1 &&
2104 rport->scsi_target_id < ha->host->max_id)
2105 fcport->os_target_id = rport->scsi_target_id;
2109 * qla2x00_configure_fabric
2110 * Setup SNS devices with loop ID's.
2113 * ha = adapter block pointer.
2120 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2123 fc_port_t *fcport, *fcptemp;
2124 uint16_t next_loopid;
2125 uint16_t mb[MAILBOX_REGISTER_COUNT];
2127 LIST_HEAD(new_fcports);
2129 /* If FL port exists, then SNS is present */
2130 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2131 loop_id = NPH_F_PORT;
2133 loop_id = SNS_FL_PORT;
2134 rval = qla2x00_get_port_name(ha, loop_id, NULL, 0);
2135 if (rval != QLA_SUCCESS) {
2136 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2137 "Port\n", ha->host_no));
2139 ha->device_flags &= ~SWITCH_FOUND;
2140 return (QLA_SUCCESS);
2143 /* Mark devices that need re-synchronization. */
2144 rval2 = qla2x00_device_resync(ha);
2145 if (rval2 == QLA_RSCNS_HANDLED) {
2146 /* No point doing the scan, just continue. */
2147 return (QLA_SUCCESS);
2151 if (ql2xfdmienable &&
2152 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2153 qla2x00_fdmi_register(ha);
2155 /* Ensure we are logged into the SNS. */
2156 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2159 loop_id = SIMPLE_NAME_SERVER;
2160 ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
2161 0xfc, mb, BIT_1 | BIT_0);
2162 if (mb[0] != MBS_COMMAND_COMPLETE) {
2163 DEBUG2(qla_printk(KERN_INFO, ha,
2164 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2165 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2166 mb[0], mb[1], mb[2], mb[6], mb[7]));
2167 return (QLA_SUCCESS);
2170 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2171 if (qla2x00_rft_id(ha)) {
2173 DEBUG2(printk("scsi(%ld): Register FC-4 "
2174 "TYPE failed.\n", ha->host_no));
2176 if (qla2x00_rff_id(ha)) {
2178 DEBUG2(printk("scsi(%ld): Register FC-4 "
2179 "Features failed.\n", ha->host_no));
2181 if (qla2x00_rnn_id(ha)) {
2183 DEBUG2(printk("scsi(%ld): Register Node Name "
2184 "failed.\n", ha->host_no));
2185 } else if (qla2x00_rsnn_nn(ha)) {
2187 DEBUG2(printk("scsi(%ld): Register Symbolic "
2188 "Node Name failed.\n", ha->host_no));
2192 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2193 if (rval != QLA_SUCCESS)
2197 * Logout all previous fabric devices marked lost, except
2200 list_for_each_entry(fcport, &ha->fcports, list) {
2201 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2204 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2207 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2208 qla2x00_mark_device_lost(ha, fcport,
2209 ql2xplogiabsentdevice, 0);
2210 if (fcport->loop_id != FC_NO_LOOP_ID &&
2211 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2212 fcport->port_type != FCT_INITIATOR &&
2213 fcport->port_type != FCT_BROADCAST) {
2214 ha->isp_ops.fabric_logout(ha,
2216 fcport->d_id.b.domain,
2217 fcport->d_id.b.area,
2218 fcport->d_id.b.al_pa);
2219 fcport->loop_id = FC_NO_LOOP_ID;
2224 /* Starting free loop ID. */
2225 next_loopid = ha->min_external_loopid;
2228 * Scan through our port list and login entries that need to be
2231 list_for_each_entry(fcport, &ha->fcports, list) {
2232 if (atomic_read(&ha->loop_down_timer) ||
2233 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2236 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2237 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2240 if (fcport->loop_id == FC_NO_LOOP_ID) {
2241 fcport->loop_id = next_loopid;
2242 rval = qla2x00_find_new_loop_id(ha, fcport);
2243 if (rval != QLA_SUCCESS) {
2244 /* Ran out of IDs to use */
2248 /* Login and update database */
2249 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2252 /* Exit if out of loop IDs. */
2253 if (rval != QLA_SUCCESS) {
2258 * Login and add the new devices to our port list.
2260 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2261 if (atomic_read(&ha->loop_down_timer) ||
2262 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2265 /* Find a new loop ID to use. */
2266 fcport->loop_id = next_loopid;
2267 rval = qla2x00_find_new_loop_id(ha, fcport);
2268 if (rval != QLA_SUCCESS) {
2269 /* Ran out of IDs to use */
2273 /* Remove device from the new list and add it to DB */
2274 list_del(&fcport->list);
2275 list_add_tail(&fcport->list, &ha->fcports);
2277 /* Login and update database */
2278 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2282 /* Free all new device structures not processed. */
2283 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2284 list_del(&fcport->list);
2289 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2290 "rval=%d\n", ha->host_no, rval));
2298 * qla2x00_find_all_fabric_devs
2301 * ha = adapter block pointer.
2302 * dev = database device entry pointer.
2311 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2315 fc_port_t *fcport, *new_fcport, *fcptemp;
2320 int first_dev, last_dev;
2321 port_id_t wrap, nxt_d_id;
2325 /* Try GID_PT to get device list, else GAN. */
2326 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2329 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2330 "on GA_NXT\n", ha->host_no));
2332 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2333 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2336 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2339 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2346 /* Allocate temporary fcport for any new fcports discovered. */
2347 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2348 if (new_fcport == NULL) {
2350 return (QLA_MEMORY_ALLOC_FAILED);
2352 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2354 /* Set start port ID scan at adapter ID. */
2358 /* Starting free loop ID. */
2359 loop_id = ha->min_external_loopid;
2360 for (; loop_id <= ha->last_loop_id; loop_id++) {
2361 if (qla2x00_is_reserved_id(ha, loop_id))
2364 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2369 wrap.b24 = new_fcport->d_id.b24;
2371 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2372 memcpy(new_fcport->node_name,
2373 swl[swl_idx].node_name, WWN_SIZE);
2374 memcpy(new_fcport->port_name,
2375 swl[swl_idx].port_name, WWN_SIZE);
2377 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2383 /* Send GA_NXT to the switch */
2384 rval = qla2x00_ga_nxt(ha, new_fcport);
2385 if (rval != QLA_SUCCESS) {
2386 qla_printk(KERN_WARNING, ha,
2387 "SNS scan failed -- assuming zero-entry "
2389 list_for_each_entry_safe(fcport, fcptemp,
2390 new_fcports, list) {
2391 list_del(&fcport->list);
2399 /* If wrap on switch device list, exit. */
2401 wrap.b24 = new_fcport->d_id.b24;
2403 } else if (new_fcport->d_id.b24 == wrap.b24) {
2404 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2405 ha->host_no, new_fcport->d_id.b.domain,
2406 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2410 /* Bypass if host adapter. */
2411 if (new_fcport->d_id.b24 == ha->d_id.b24)
2414 /* Bypass if same domain and area of adapter. */
2415 if (((new_fcport->d_id.b24 & 0xffff00) ==
2416 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2420 /* Bypass reserved domain fields. */
2421 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2424 /* Locate matching device in database. */
2426 list_for_each_entry(fcport, &ha->fcports, list) {
2427 if (memcmp(new_fcport->port_name, fcport->port_name,
2434 * If address the same and state FCS_ONLINE, nothing
2437 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2438 atomic_read(&fcport->state) == FCS_ONLINE) {
2443 * If device was not a fabric device before.
2445 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2446 fcport->d_id.b24 = new_fcport->d_id.b24;
2447 fcport->loop_id = FC_NO_LOOP_ID;
2448 fcport->flags |= (FCF_FABRIC_DEVICE |
2450 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2455 * Port ID changed or device was marked to be updated;
2456 * Log it out if still logged in and mark it for
2459 fcport->d_id.b24 = new_fcport->d_id.b24;
2460 fcport->flags |= FCF_LOGIN_NEEDED;
2461 if (fcport->loop_id != FC_NO_LOOP_ID &&
2462 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2463 fcport->port_type != FCT_INITIATOR &&
2464 fcport->port_type != FCT_BROADCAST) {
2465 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2466 fcport->d_id.b.domain, fcport->d_id.b.area,
2467 fcport->d_id.b.al_pa);
2468 fcport->loop_id = FC_NO_LOOP_ID;
2477 /* If device was not in our fcports list, then add it. */
2478 list_add_tail(&new_fcport->list, new_fcports);
2480 /* Allocate a new replacement fcport. */
2481 nxt_d_id.b24 = new_fcport->d_id.b24;
2482 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2483 if (new_fcport == NULL) {
2485 return (QLA_MEMORY_ALLOC_FAILED);
2487 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2488 new_fcport->d_id.b24 = nxt_d_id.b24;
2494 if (!list_empty(new_fcports))
2495 ha->device_flags |= DFLG_FABRIC_DEVICES;
2501 * qla2x00_find_new_loop_id
2502 * Scan through our port list and find a new usable loop ID.
2505 * ha: adapter state pointer.
2506 * dev: port structure pointer.
2509 * qla2x00 local function return status code.
2515 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2520 uint16_t first_loop_id;
2524 /* Save starting loop ID. */
2525 first_loop_id = dev->loop_id;
2528 /* Skip loop ID if already used by adapter. */
2529 if (dev->loop_id == ha->loop_id) {
2533 /* Skip reserved loop IDs. */
2534 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2538 /* Reset loop ID if passed the end. */
2539 if (dev->loop_id > ha->last_loop_id) {
2540 /* first loop ID. */
2541 dev->loop_id = ha->min_external_loopid;
2544 /* Check for loop ID being already in use. */
2547 list_for_each_entry(fcport, &ha->fcports, list) {
2548 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2549 /* ID possibly in use */
2555 /* If not in use then it is free to use. */
2560 /* ID in use. Try next value. */
2563 /* If wrap around. No free ID to use. */
2564 if (dev->loop_id == first_loop_id) {
2565 dev->loop_id = FC_NO_LOOP_ID;
2566 rval = QLA_FUNCTION_FAILED;
2575 * qla2x00_device_resync
2576 * Marks devices in the database that needs resynchronization.
2579 * ha = adapter block pointer.
2585 qla2x00_device_resync(scsi_qla_host_t *ha)
2591 uint32_t rscn_entry;
2592 uint8_t rscn_out_iter;
2596 rval = QLA_RSCNS_HANDLED;
2598 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2599 ha->flags.rscn_queue_overflow) {
2601 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2602 format = MSB(MSW(rscn_entry));
2603 d_id.b.domain = LSB(MSW(rscn_entry));
2604 d_id.b.area = MSB(LSW(rscn_entry));
2605 d_id.b.al_pa = LSB(LSW(rscn_entry));
2607 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2608 "[%02x/%02x%02x%02x].\n",
2609 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2610 d_id.b.area, d_id.b.al_pa));
2613 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2614 ha->rscn_out_ptr = 0;
2616 /* Skip duplicate entries. */
2617 for (rscn_out_iter = ha->rscn_out_ptr;
2618 !ha->flags.rscn_queue_overflow &&
2619 rscn_out_iter != ha->rscn_in_ptr;
2620 rscn_out_iter = (rscn_out_iter ==
2621 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2623 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2626 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2627 "entry found at [%d].\n", ha->host_no,
2630 ha->rscn_out_ptr = rscn_out_iter;
2633 /* Queue overflow, set switch default case. */
2634 if (ha->flags.rscn_queue_overflow) {
2635 DEBUG(printk("scsi(%ld): device_resync: rscn "
2636 "overflow.\n", ha->host_no));
2639 ha->flags.rscn_queue_overflow = 0;
2644 if (ql2xprocessrscn &&
2645 !IS_QLA2100(ha) && !IS_QLA2200(ha) &&
2646 !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
2647 !IS_QLA24XX(ha) && !IS_QLA54XX(ha) &&
2648 ha->flags.init_done) {
2649 /* Handle port RSCN via asyncronous IOCBs */
2650 rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
2652 if (rval2 == QLA_SUCCESS)
2666 ha->rscn_out_ptr = ha->rscn_in_ptr;
2672 /* Abort any outstanding IO descriptors. */
2673 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2674 qla2x00_cancel_io_descriptors(ha);
2676 list_for_each_entry(fcport, &ha->fcports, list) {
2677 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2678 (fcport->d_id.b24 & mask) != d_id.b24 ||
2679 fcport->port_type == FCT_BROADCAST)
2682 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2684 fcport->port_type != FCT_INITIATOR) {
2685 qla2x00_mark_device_lost(ha, fcport,
2689 fcport->flags &= ~FCF_FARP_DONE;
2696 * qla2x00_fabric_dev_login
2697 * Login fabric target device and update FC port database.
2700 * ha: adapter state pointer.
2701 * fcport: port structure list pointer.
2702 * next_loopid: contains value of a new loop ID that can be used
2703 * by the next login attempt.
2706 * qla2x00 local function return status code.
2712 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2713 uint16_t *next_loopid)
2722 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2723 if (rval == QLA_SUCCESS) {
2724 /* Send an ADISC to tape devices.*/
2726 if (fcport->flags & FCF_TAPE_PRESENT)
2728 rval = qla2x00_get_port_database(ha, fcport, opts);
2729 if (rval != QLA_SUCCESS) {
2730 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2731 fcport->d_id.b.domain, fcport->d_id.b.area,
2732 fcport->d_id.b.al_pa);
2733 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2735 qla2x00_update_fcport(ha, fcport);
2743 * qla2x00_fabric_login
2744 * Issue fabric login command.
2747 * ha = adapter block pointer.
2748 * device = pointer to FC device type structure.
2751 * 0 - Login successfully
2753 * 2 - Initiator device
2757 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2758 uint16_t *next_loopid)
2762 uint16_t tmp_loopid;
2763 uint16_t mb[MAILBOX_REGISTER_COUNT];
2769 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2770 "for port %02x%02x%02x.\n",
2771 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2772 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2774 /* Login fcport on switch. */
2775 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2776 fcport->d_id.b.domain, fcport->d_id.b.area,
2777 fcport->d_id.b.al_pa, mb, BIT_0);
2778 if (mb[0] == MBS_PORT_ID_USED) {
2780 * Device has another loop ID. The firmware team
2781 * recommends the driver perform an implicit login with
2782 * the specified ID again. The ID we just used is save
2783 * here so we return with an ID that can be tried by
2787 tmp_loopid = fcport->loop_id;
2788 fcport->loop_id = mb[1];
2790 DEBUG(printk("Fabric Login: port in use - next "
2791 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2792 fcport->loop_id, fcport->d_id.b.domain,
2793 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2795 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2800 /* A retry occurred before. */
2801 *next_loopid = tmp_loopid;
2804 * No retry occurred before. Just increment the
2805 * ID value for next login.
2807 *next_loopid = (fcport->loop_id + 1);
2810 if (mb[1] & BIT_0) {
2811 fcport->port_type = FCT_INITIATOR;
2813 fcport->port_type = FCT_TARGET;
2814 if (mb[1] & BIT_1) {
2815 fcport->flags |= FCF_TAPE_PRESENT;
2820 fcport->supported_classes |= FC_COS_CLASS2;
2822 fcport->supported_classes |= FC_COS_CLASS3;
2826 } else if (mb[0] == MBS_LOOP_ID_USED) {
2828 * Loop ID already used, try next loop ID.
2831 rval = qla2x00_find_new_loop_id(ha, fcport);
2832 if (rval != QLA_SUCCESS) {
2833 /* Ran out of loop IDs to use */
2836 } else if (mb[0] == MBS_COMMAND_ERROR) {
2838 * Firmware possibly timed out during login. If NO
2839 * retries are left to do then the device is declared
2842 *next_loopid = fcport->loop_id;
2843 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2844 fcport->d_id.b.domain, fcport->d_id.b.area,
2845 fcport->d_id.b.al_pa);
2846 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2852 * unrecoverable / not handled error
2854 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2855 "loop_id=%x jiffies=%lx.\n",
2856 __func__, ha->host_no, mb[0],
2857 fcport->d_id.b.domain, fcport->d_id.b.area,
2858 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2860 *next_loopid = fcport->loop_id;
2861 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2862 fcport->d_id.b.domain, fcport->d_id.b.area,
2863 fcport->d_id.b.al_pa);
2864 fcport->loop_id = FC_NO_LOOP_ID;
2865 fcport->login_retry = 0;
2876 * qla2x00_local_device_login
2877 * Issue local device login command.
2880 * ha = adapter block pointer.
2881 * loop_id = loop id of device to login to.
2883 * Returns (Where's the #define!!!!):
2884 * 0 - Login successfully
2889 qla2x00_local_device_login(scsi_qla_host_t *ha, uint16_t loop_id)
2892 uint16_t mb[MAILBOX_REGISTER_COUNT];
2894 memset(mb, 0, sizeof(mb));
2895 rval = qla2x00_login_local_device(ha, loop_id, mb, BIT_0);
2896 if (rval == QLA_SUCCESS) {
2897 /* Interrogate mailbox registers for any errors */
2898 if (mb[0] == MBS_COMMAND_ERROR)
2900 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
2901 /* device not in PCB table */
2909 * qla2x00_loop_resync
2910 * Resync with fibre channel devices.
2913 * ha = adapter block pointer.
2919 qla2x00_loop_resync(scsi_qla_host_t *ha)
2926 atomic_set(&ha->loop_state, LOOP_UPDATE);
2927 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2928 if (ha->flags.online) {
2929 if (!(rval = qla2x00_fw_ready(ha))) {
2930 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2933 atomic_set(&ha->loop_state, LOOP_UPDATE);
2935 /* Issue a marker after FW becomes ready. */
2936 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
2937 ha->marker_needed = 0;
2939 /* Remap devices on Loop. */
2940 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2942 qla2x00_configure_loop(ha);
2944 } while (!atomic_read(&ha->loop_down_timer) &&
2945 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
2947 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
2951 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2952 return (QLA_FUNCTION_FAILED);
2956 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
2963 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
2969 list_for_each_entry(fcport, &ha->fcports, list) {
2970 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
2973 qla2x00_update_fcport(ha, fcport);
2974 fcport->flags &= ~FCF_RESCAN_NEEDED;
2978 qla2x00_probe_for_all_luns(ha);
2982 qla2x00_update_fcports(scsi_qla_host_t *ha)
2986 /* Go with deferred removal of rport references. */
2987 list_for_each_entry(fcport, &ha->fcports, list)
2989 qla2x00_rport_del(fcport);
2994 * Resets ISP and aborts all outstanding commands.
2997 * ha = adapter block pointer.
3003 qla2x00_abort_isp(scsi_qla_host_t *ha)
3005 unsigned long flags = 0;
3010 if (ha->flags.online) {
3011 ha->flags.online = 0;
3012 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3014 qla_printk(KERN_INFO, ha,
3015 "Performing ISP error recovery - ha= %p.\n", ha);
3016 ha->isp_ops.reset_chip(ha);
3018 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3019 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3020 atomic_set(&ha->loop_state, LOOP_DOWN);
3021 qla2x00_mark_all_devices_lost(ha, 0);
3023 if (!atomic_read(&ha->loop_down_timer))
3024 atomic_set(&ha->loop_down_timer,
3028 spin_lock_irqsave(&ha->hardware_lock, flags);
3029 /* Requeue all commands in outstanding command list. */
3030 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3031 sp = ha->outstanding_cmds[cnt];
3033 ha->outstanding_cmds[cnt] = NULL;
3035 sp->cmd->result = DID_RESET << 16;
3036 sp->cmd->host_scribble = (unsigned char *)NULL;
3037 qla2x00_sp_compl(ha, sp);
3040 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3042 ha->isp_ops.nvram_config(ha);
3044 if (!qla2x00_restart_isp(ha)) {
3045 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3047 if (!atomic_read(&ha->loop_down_timer)) {
3049 * Issue marker command only when we are going
3050 * to start the I/O .
3052 ha->marker_needed = 1;
3055 ha->flags.online = 1;
3057 ha->isp_ops.enable_intrs(ha);
3059 ha->isp_abort_cnt = 0;
3060 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3061 } else { /* failed the ISP abort */
3062 ha->flags.online = 1;
3063 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3064 if (ha->isp_abort_cnt == 0) {
3065 qla_printk(KERN_WARNING, ha,
3066 "ISP error recovery failed - "
3067 "board disabled\n");
3069 * The next call disables the board
3072 ha->isp_ops.reset_adapter(ha);
3073 ha->flags.online = 0;
3074 clear_bit(ISP_ABORT_RETRY,
3077 } else { /* schedule another ISP abort */
3078 ha->isp_abort_cnt--;
3079 DEBUG(printk("qla%ld: ISP abort - "
3080 "retry remaining %d\n",
3081 ha->host_no, ha->isp_abort_cnt);)
3085 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3086 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3087 "- retrying (%d) more times\n",
3088 ha->host_no, ha->isp_abort_cnt);)
3089 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3097 qla_printk(KERN_INFO, ha,
3098 "qla2x00_abort_isp: **** FAILED ****\n");
3100 DEBUG(printk(KERN_INFO
3101 "qla2x00_abort_isp(%ld): exiting.\n",
3109 * qla2x00_restart_isp
3110 * restarts the ISP after a reset
3113 * ha = adapter block pointer.
3119 qla2x00_restart_isp(scsi_qla_host_t *ha)
3122 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3123 unsigned long flags = 0;
3126 /* If firmware needs to be loaded */
3127 if (qla2x00_isp_firmware(ha)) {
3128 ha->flags.online = 0;
3129 if (!(status = ha->isp_ops.chip_diag(ha))) {
3130 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3131 status = qla2x00_setup_chip(ha);
3135 spin_lock_irqsave(&ha->hardware_lock, flags);
3137 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3139 * Disable SRAM, Instruction RAM and GP RAM
3142 WRT_REG_WORD(®->hccr,
3143 (HCCR_ENABLE_PARITY + 0x0));
3144 RD_REG_WORD(®->hccr);
3147 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3149 status = qla2x00_setup_chip(ha);
3151 spin_lock_irqsave(&ha->hardware_lock, flags);
3153 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3154 /* Enable proper parity */
3157 WRT_REG_WORD(®->hccr,
3158 (HCCR_ENABLE_PARITY + 0x1));
3161 * SRAM, Instruction RAM and GP RAM
3164 WRT_REG_WORD(®->hccr,
3165 (HCCR_ENABLE_PARITY + 0x7));
3166 RD_REG_WORD(®->hccr);
3169 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3174 if (!status && !(status = qla2x00_init_rings(ha))) {
3175 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3176 if (!(status = qla2x00_fw_ready(ha))) {
3177 DEBUG(printk("%s(): Start configure loop, "
3178 "status = %d\n", __func__, status);)
3180 /* Issue a marker after FW becomes ready. */
3181 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3183 ha->flags.online = 1;
3184 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3187 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3188 qla2x00_configure_loop(ha);
3190 } while (!atomic_read(&ha->loop_down_timer) &&
3191 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3193 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3196 /* if no cable then assume it's good */
3197 if ((ha->device_flags & DFLG_NO_CABLE))
3200 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3208 * qla2x00_reset_adapter
3212 * ha = adapter block pointer.
3215 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3217 unsigned long flags = 0;
3218 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3220 ha->flags.online = 0;
3221 ha->isp_ops.disable_intrs(ha);
3223 spin_lock_irqsave(&ha->hardware_lock, flags);
3224 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3225 RD_REG_WORD(®->hccr); /* PCI Posting. */
3226 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3227 RD_REG_WORD(®->hccr); /* PCI Posting. */
3228 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3232 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3234 unsigned long flags = 0;
3235 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3237 ha->flags.online = 0;
3238 ha->isp_ops.disable_intrs(ha);
3240 spin_lock_irqsave(&ha->hardware_lock, flags);
3241 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3242 RD_REG_DWORD(®->hccr);
3243 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3244 RD_REG_DWORD(®->hccr);
3245 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3249 qla24xx_nvram_config(scsi_qla_host_t *ha)
3252 struct init_cb_24xx *icb;
3253 struct nvram_24xx *nv;
3255 uint8_t *dptr1, *dptr2;
3260 icb = (struct init_cb_24xx *)ha->init_cb;
3261 nv = (struct nvram_24xx *)ha->request_ring;
3263 /* Determine NVRAM starting address. */
3264 ha->nvram_size = sizeof(struct nvram_24xx);
3265 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3266 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3267 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3268 if (PCI_FUNC(ha->pdev->devfn)) {
3269 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3270 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3273 /* Get NVRAM data and calculate checksum. */
3274 dptr = (uint32_t *)nv;
3275 ha->isp_ops.read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3277 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3278 chksum += le32_to_cpu(*dptr++);
3280 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3281 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3284 /* Bad NVRAM data, set defaults parameters. */
3285 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3286 || nv->id[3] != ' ' ||
3287 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3288 /* Reset NVRAM data. */
3289 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3290 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3291 le16_to_cpu(nv->nvram_version));
3292 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3293 "invalid -- WWPN) defaults.\n");
3296 * Set default initialization control block.
3298 memset(nv, 0, ha->nvram_size);
3299 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3300 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3301 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3302 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3303 nv->exchange_count = __constant_cpu_to_le16(0);
3304 nv->hard_address = __constant_cpu_to_le16(124);
3305 nv->port_name[0] = 0x21;
3306 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3307 nv->port_name[2] = 0x00;
3308 nv->port_name[3] = 0xe0;
3309 nv->port_name[4] = 0x8b;
3310 nv->port_name[5] = 0x1c;
3311 nv->port_name[6] = 0x55;
3312 nv->port_name[7] = 0x86;
3313 nv->node_name[0] = 0x20;
3314 nv->node_name[1] = 0x00;
3315 nv->node_name[2] = 0x00;
3316 nv->node_name[3] = 0xe0;
3317 nv->node_name[4] = 0x8b;
3318 nv->node_name[5] = 0x1c;
3319 nv->node_name[6] = 0x55;
3320 nv->node_name[7] = 0x86;
3321 nv->login_retry_count = __constant_cpu_to_le16(8);
3322 nv->link_down_timeout = __constant_cpu_to_le16(200);
3323 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3324 nv->login_timeout = __constant_cpu_to_le16(0);
3325 nv->firmware_options_1 =
3326 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3327 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3328 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3329 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3330 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3331 nv->efi_parameters = __constant_cpu_to_le32(0);
3332 nv->reset_delay = 5;
3333 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3334 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3335 nv->link_down_timeout = __constant_cpu_to_le16(30);
3340 /* Reset Initialization control block */
3341 memset(icb, 0, sizeof(struct init_cb_24xx));
3343 /* Copy 1st segment. */
3344 dptr1 = (uint8_t *)icb;
3345 dptr2 = (uint8_t *)&nv->version;
3346 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3348 *dptr1++ = *dptr2++;
3350 icb->login_retry_count = nv->login_retry_count;
3351 icb->link_down_timeout = nv->link_down_timeout;
3353 /* Copy 2nd segment. */
3354 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3355 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3356 cnt = (uint8_t *)&icb->reserved_3 -
3357 (uint8_t *)&icb->interrupt_delay_timer;
3359 *dptr1++ = *dptr2++;
3362 * Setup driver NVRAM options.
3364 if (memcmp(nv->model_name, BINZERO, sizeof(nv->model_name)) != 0) {
3368 strncpy(ha->model_number, nv->model_name,
3369 sizeof(nv->model_name));
3370 st = en = ha->model_number;
3371 en += sizeof(nv->model_name) - 1;
3373 if (*en != 0x20 && *en != 0x00)
3378 index = (ha->pdev->subsystem_device & 0xff);
3379 if (index < QLA_MODEL_NAMES)
3380 ha->model_desc = qla2x00_model_name[index * 2 + 1];
3382 strcpy(ha->model_number, "QLA2462");
3384 /* Prepare nodename */
3385 if ((icb->firmware_options_1 & BIT_14) == 0) {
3387 * Firmware will apply the following mask if the nodename was
3390 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3391 icb->node_name[0] &= 0xF0;
3394 /* Set host adapter parameters. */
3395 ha->flags.disable_risc_code_load = 0;
3396 ha->flags.enable_lip_reset = 1;
3397 ha->flags.enable_lip_full_login = 1;
3398 ha->flags.enable_target_reset = 1;
3399 ha->flags.enable_led_scheme = 0;
3401 ha->operating_mode =
3402 (icb->firmware_options_2 & (BIT_6 | BIT_5 | BIT_4)) >> 4;
3404 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3405 sizeof(ha->fw_seriallink_options24));
3407 /* save HBA serial number */
3408 ha->serial0 = icb->port_name[5];
3409 ha->serial1 = icb->port_name[6];
3410 ha->serial2 = icb->port_name[7];
3411 ha->node_name = icb->node_name;
3412 ha->port_name = icb->port_name;
3414 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3416 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3418 /* Set minimum login_timeout to 4 seconds. */
3419 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3420 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3421 if (le16_to_cpu(nv->login_timeout) < 4)
3422 nv->login_timeout = __constant_cpu_to_le16(4);
3423 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3424 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3426 /* Set minimum RATOV to 200 tenths of a second. */
3429 ha->loop_reset_delay = nv->reset_delay;
3431 /* Link Down Timeout = 0:
3433 * When Port Down timer expires we will start returning
3434 * I/O's to OS with "DID_NO_CONNECT".
3436 * Link Down Timeout != 0:
3438 * The driver waits for the link to come up after link down
3439 * before returning I/Os to OS with "DID_NO_CONNECT".
3441 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3442 ha->loop_down_abort_time =
3443 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3445 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3446 ha->loop_down_abort_time =
3447 (LOOP_DOWN_TIME - ha->link_down_timeout);
3450 /* Need enough time to try and get the port back. */
3451 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3452 if (qlport_down_retry)
3453 ha->port_down_retry_count = qlport_down_retry;
3455 /* Set login_retry_count */
3456 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3457 if (ha->port_down_retry_count ==
3458 le16_to_cpu(nv->port_down_retry_count) &&
3459 ha->port_down_retry_count > 3)
3460 ha->login_retry_count = ha->port_down_retry_count;
3461 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3462 ha->login_retry_count = ha->port_down_retry_count;
3463 if (ql2xloginretrycount)
3464 ha->login_retry_count = ql2xloginretrycount;
3467 if (!ha->flags.init_done) {
3468 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3469 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3470 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3471 le16_to_cpu(icb->interrupt_delay_timer): 2;
3473 icb->firmware_options_2 &= __constant_cpu_to_le32(
3474 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3475 ha->flags.process_response_queue = 0;
3476 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3477 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3478 "(%d us).\n", ha->host_no, ha->zio_mode,
3479 ha->zio_timer * 100));
3480 qla_printk(KERN_INFO, ha,
3481 "ZIO mode %d enabled; timer delay (%d us).\n",
3482 ha->zio_mode, ha->zio_timer * 100);
3484 icb->firmware_options_2 |= cpu_to_le32(
3485 (uint32_t)ha->zio_mode);
3486 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3487 ha->flags.process_response_queue = 1;
3491 DEBUG2_3(printk(KERN_WARNING
3492 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3497 #if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
3500 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3504 uint16_t *risc_code;
3505 uint32_t risc_addr, risc_size;
3507 struct qla_fw_info *fw_iter;
3511 /* Load firmware sequences */
3512 fw_iter = ha->brd_info->fw_info;
3513 *srisc_addr = *ha->brd_info->fw_info->fwstart;
3514 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
3515 risc_code = fw_iter->fwcode;
3516 risc_size = *fw_iter->fwlen;
3517 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL)
3518 risc_addr = *fw_iter->fwstart;
3520 risc_addr = *fw_iter->lfwstart;
3524 while (risc_size > 0 && !rval) {
3525 cnt = (uint16_t)(ha->fw_transfer_size >> 1);
3526 if (cnt > risc_size)
3529 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
3530 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
3531 ha->host_no, risc_code, cnt, risc_addr));
3533 req_ring = (uint16_t *)ha->request_ring;
3534 for (i = 0; i < cnt; i++)
3535 req_ring[i] = cpu_to_le16(risc_code[i]);
3537 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3540 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
3541 "load segment %d of firmware\n",
3543 qla_printk(KERN_WARNING, ha,
3544 "[ERROR] Failed to load segment %d of "
3547 qla2x00_dump_regs(ha);
3557 /* Next firmware sequence */
3564 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3568 uint32_t *risc_code;
3569 uint32_t risc_addr, risc_size;
3571 struct qla_fw_info *fw_iter;
3575 /* Load firmware sequences */
3576 fw_iter = ha->brd_info->fw_info;
3577 *srisc_addr = *((uint32_t *)fw_iter->lfwstart);
3578 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
3579 risc_code = (uint32_t *)fw_iter->fwcode;
3580 risc_size = *((uint32_t *)fw_iter->fwlen);
3581 risc_addr = *((uint32_t *)fw_iter->lfwstart);
3585 while (risc_size > 0 && !rval) {
3586 cnt = (uint32_t)(ha->fw_transfer_size >> 2);
3587 if (cnt > risc_size)
3590 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
3591 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
3592 ha->host_no, risc_code, cnt, risc_addr));
3594 req_ring = (uint32_t *)ha->request_ring;
3595 for (i = 0; i < cnt; i++)
3596 req_ring[i] = cpu_to_le32(risc_code[i]);
3598 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3601 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
3602 "load segment %d of firmware\n",
3604 qla_printk(KERN_WARNING, ha,
3605 "[ERROR] Failed to load segment %d of "
3608 qla2x00_dump_regs(ha);
3618 /* Next firmware sequence */
3625 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3628 int segments, fragment;
3630 uint32_t *dcode, dlen;
3637 segments = FA_RISC_CODE_SEGMENTS;
3638 faddr = FA_RISC_CODE_ADDR;
3639 dcode = (uint32_t *)ha->request_ring;
3642 /* Validate firmware image by checking version. */
3643 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3644 for (i = 0; i < 4; i++)
3645 dcode[i] = be32_to_cpu(dcode[i]);
3646 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3647 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3648 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3650 qla_printk(KERN_WARNING, ha,
3651 "Unable to verify integrity of flash firmware image!\n");
3652 qla_printk(KERN_WARNING, ha,
3653 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3654 dcode[1], dcode[2], dcode[3]);
3656 return QLA_FUNCTION_FAILED;
3659 while (segments && rval == QLA_SUCCESS) {
3660 /* Read segment's load information. */
3661 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3663 risc_addr = be32_to_cpu(dcode[2]);
3664 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3665 risc_size = be32_to_cpu(dcode[3]);
3668 while (risc_size > 0 && rval == QLA_SUCCESS) {
3669 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3670 if (dlen > risc_size)
3673 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3674 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3675 ha->host_no, risc_addr, dlen, faddr));
3677 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3678 for (i = 0; i < dlen; i++)
3679 dcode[i] = swab32(dcode[i]);
3681 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3684 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3685 "segment %d of firmware\n", ha->host_no,
3687 qla_printk(KERN_WARNING, ha,
3688 "[ERROR] Failed to load segment %d of "
3689 "firmware\n", fragment);
3706 #else /* !defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE) */
3709 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3713 uint16_t *wcode, *fwcode;
3714 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3715 struct fw_blob *blob;
3717 /* Load firmware blob. */
3718 blob = qla2x00_request_firmware(ha);
3720 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3721 return QLA_FUNCTION_FAILED;
3726 wcode = (uint16_t *)ha->request_ring;
3728 fwcode = (uint16_t *)blob->fw->data;
3731 /* Validate firmware image by checking version. */
3732 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3733 qla_printk(KERN_WARNING, ha,
3734 "Unable to verify integrity of firmware image (%Zd)!\n",
3736 goto fail_fw_integrity;
3738 for (i = 0; i < 4; i++)
3739 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3740 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3741 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3742 wcode[2] == 0 && wcode[3] == 0)) {
3743 qla_printk(KERN_WARNING, ha,
3744 "Unable to verify integrity of firmware image!\n");
3745 qla_printk(KERN_WARNING, ha,
3746 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3747 wcode[1], wcode[2], wcode[3]);
3748 goto fail_fw_integrity;
3752 while (*seg && rval == QLA_SUCCESS) {
3754 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3755 risc_size = be16_to_cpu(fwcode[3]);
3757 /* Validate firmware image size. */
3758 fwclen += risc_size * sizeof(uint16_t);
3759 if (blob->fw->size < fwclen) {
3760 qla_printk(KERN_WARNING, ha,
3761 "Unable to verify integrity of firmware image "
3762 "(%Zd)!\n", blob->fw->size);
3763 goto fail_fw_integrity;
3767 while (risc_size > 0 && rval == QLA_SUCCESS) {
3768 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3769 if (wlen > risc_size)
3772 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3773 "addr %x, number of words 0x%x.\n", ha->host_no,
3776 for (i = 0; i < wlen; i++)
3777 wcode[i] = swab16(fwcode[i]);
3779 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3782 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3783 "segment %d of firmware\n", ha->host_no,
3785 qla_printk(KERN_WARNING, ha,
3786 "[ERROR] Failed to load segment %d of "
3787 "firmware\n", fragment);
3803 return QLA_FUNCTION_FAILED;
3807 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3810 int segments, fragment;
3811 uint32_t *dcode, dlen;
3815 struct fw_blob *blob;
3816 uint32_t *fwcode, fwclen;
3818 /* Load firmware blob. */
3819 blob = qla2x00_request_firmware(ha);
3821 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3822 return QLA_FUNCTION_FAILED;
3827 segments = FA_RISC_CODE_SEGMENTS;
3828 dcode = (uint32_t *)ha->request_ring;
3830 fwcode = (uint32_t *)blob->fw->data;
3833 /* Validate firmware image by checking version. */
3834 if (blob->fw->size < 8 * sizeof(uint32_t)) {
3835 qla_printk(KERN_WARNING, ha,
3836 "Unable to verify integrity of firmware image (%Zd)!\n",
3838 goto fail_fw_integrity;
3840 for (i = 0; i < 4; i++)
3841 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3842 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3843 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3844 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3846 qla_printk(KERN_WARNING, ha,
3847 "Unable to verify integrity of firmware image!\n");
3848 qla_printk(KERN_WARNING, ha,
3849 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3850 dcode[1], dcode[2], dcode[3]);
3851 goto fail_fw_integrity;
3854 while (segments && rval == QLA_SUCCESS) {
3855 risc_addr = be32_to_cpu(fwcode[2]);
3856 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3857 risc_size = be32_to_cpu(fwcode[3]);
3859 /* Validate firmware image size. */
3860 fwclen += risc_size * sizeof(uint32_t);
3861 if (blob->fw->size < fwclen) {
3862 qla_printk(KERN_WARNING, ha,
3863 "Unable to verify integrity of firmware image "
3864 "(%Zd)!\n", blob->fw->size);
3866 goto fail_fw_integrity;
3870 while (risc_size > 0 && rval == QLA_SUCCESS) {
3871 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3872 if (dlen > risc_size)
3875 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3876 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3879 for (i = 0; i < dlen; i++)
3880 dcode[i] = swab32(fwcode[i]);
3882 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3885 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3886 "segment %d of firmware\n", ha->host_no,
3888 qla_printk(KERN_WARNING, ha,
3889 "[ERROR] Failed to load segment %d of "
3890 "firmware\n", fragment);
3906 return QLA_FUNCTION_FAILED;