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>
11 #include <scsi/scsi_transport_fc.h>
13 #include "qla_devtbl.h"
15 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
16 #ifndef EXT_IS_LUN_BIT_SET
17 #define EXT_IS_LUN_BIT_SET(P,L) \
18 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
19 #define EXT_SET_LUN_BIT(P,L) \
20 ((P)->mask[L/8] |= (0x80 >> (L%8)))
24 * QLogic ISP2x00 Hardware Support Function Prototypes.
26 static int qla2x00_isp_firmware(scsi_qla_host_t *);
27 static void qla2x00_resize_request_q(scsi_qla_host_t *);
28 static int qla2x00_setup_chip(scsi_qla_host_t *);
29 static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
30 static int qla2x00_init_rings(scsi_qla_host_t *);
31 static int qla2x00_fw_ready(scsi_qla_host_t *);
32 static int qla2x00_configure_hba(scsi_qla_host_t *);
33 static int qla2x00_configure_loop(scsi_qla_host_t *);
34 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
35 static int qla2x00_configure_fabric(scsi_qla_host_t *);
36 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
37 static int qla2x00_device_resync(scsi_qla_host_t *);
38 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
41 static int qla2x00_restart_isp(scsi_qla_host_t *);
43 /****************************************************************************/
44 /* QLogic ISP2x00 Hardware Support Functions. */
45 /****************************************************************************/
48 * qla2x00_initialize_adapter
52 * ha = adapter block pointer.
58 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
61 uint8_t restart_risc = 0;
65 /* Clear adapter flags. */
67 ha->flags.reset_active = 0;
68 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
69 atomic_set(&ha->loop_state, LOOP_DOWN);
72 ha->flags.management_server_logged_in = 0;
73 ha->marker_needed = 0;
75 ha->isp_abort_cnt = 0;
76 ha->beacon_blink_led = 0;
77 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
79 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
80 rval = ha->isp_ops.pci_config(ha);
82 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
87 ha->isp_ops.reset_chip(ha);
89 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
91 ha->isp_ops.nvram_config(ha);
93 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
97 * Try to configure the loop.
102 /* If firmware needs to be loaded */
103 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
104 if ((rval = ha->isp_ops.chip_diag(ha)) == QLA_SUCCESS) {
105 rval = qla2x00_setup_chip(ha);
109 if (rval == QLA_SUCCESS &&
110 (rval = qla2x00_init_rings(ha)) == QLA_SUCCESS) {
111 check_fw_ready_again:
113 * Wait for a successful LIP up to a maximum
114 * of (in seconds): RISC login timeout value,
115 * RISC retry count value, and port down retry
116 * value OR a minimum of 4 seconds OR If no
117 * cable, only 5 seconds.
119 rval = qla2x00_fw_ready(ha);
120 if (rval == QLA_SUCCESS) {
121 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
123 /* Issue a marker after FW becomes ready. */
124 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
127 * Wait at most MAX_TARGET RSCNs for a stable
132 clear_bit(LOOP_RESYNC_NEEDED,
134 rval = qla2x00_configure_loop(ha);
136 if (test_and_clear_bit(ISP_ABORT_NEEDED,
143 * If loop state change while we were
144 * discoverying devices then wait for
148 if (atomic_read(&ha->loop_state) !=
149 LOOP_READY && retry--) {
150 goto check_fw_ready_again;
153 } while (!atomic_read(&ha->loop_down_timer) &&
156 (test_bit(LOOP_RESYNC_NEEDED,
160 rval = QLA_FUNCTION_FAILED;
161 } else if (ha->device_flags & DFLG_NO_CABLE)
162 /* If no cable, then all is good. */
165 } while (restart_risc && retry--);
167 if (rval == QLA_SUCCESS) {
168 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
169 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
170 ha->marker_needed = 0;
172 ha->flags.online = 1;
174 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
181 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
184 * Returns 0 on success.
187 qla2100_pci_config(scsi_qla_host_t *ha)
192 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
194 pci_set_master(ha->pdev);
196 if (pci_set_mwi(ha->pdev))
197 mwi = PCI_COMMAND_INVALIDATE;
198 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
200 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
201 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
202 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
204 /* Reset expansion ROM address decode enable */
205 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
206 d &= ~PCI_ROM_ADDRESS_ENABLE;
207 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
209 /* Get PCI bus information. */
210 spin_lock_irqsave(&ha->hardware_lock, flags);
211 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
212 spin_unlock_irqrestore(&ha->hardware_lock, flags);
218 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
221 * Returns 0 on success.
224 qla2300_pci_config(scsi_qla_host_t *ha)
228 unsigned long flags = 0;
230 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
232 pci_set_master(ha->pdev);
234 if (pci_set_mwi(ha->pdev))
235 mwi = PCI_COMMAND_INVALIDATE;
236 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
238 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
239 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
241 if (IS_QLA2322(ha) || IS_QLA6322(ha))
242 w &= ~PCI_COMMAND_INTX_DISABLE;
245 * If this is a 2300 card and not 2312, reset the
246 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
247 * the 2310 also reports itself as a 2300 so we need to get the
248 * fb revision level -- a 6 indicates it really is a 2300 and
251 if (IS_QLA2300(ha)) {
252 spin_lock_irqsave(&ha->hardware_lock, flags);
255 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
256 for (cnt = 0; cnt < 30000; cnt++) {
257 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
263 /* Select FPM registers. */
264 WRT_REG_WORD(®->ctrl_status, 0x20);
265 RD_REG_WORD(®->ctrl_status);
267 /* Get the fb rev level */
268 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
270 if (ha->fb_rev == FPM_2300)
271 w &= ~PCI_COMMAND_INVALIDATE;
273 /* Deselect FPM registers. */
274 WRT_REG_WORD(®->ctrl_status, 0x0);
275 RD_REG_WORD(®->ctrl_status);
277 /* Release RISC module. */
278 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
279 for (cnt = 0; cnt < 30000; cnt++) {
280 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
286 spin_unlock_irqrestore(&ha->hardware_lock, flags);
288 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
290 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
292 /* Reset expansion ROM address decode enable */
293 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
294 d &= ~PCI_ROM_ADDRESS_ENABLE;
295 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
297 /* Get PCI bus information. */
298 spin_lock_irqsave(&ha->hardware_lock, flags);
299 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
300 spin_unlock_irqrestore(&ha->hardware_lock, flags);
306 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
309 * Returns 0 on success.
312 qla24xx_pci_config(scsi_qla_host_t *ha)
316 unsigned long flags = 0;
317 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
318 int pcix_cmd_reg, pcie_dctl_reg;
320 pci_set_master(ha->pdev);
322 if (pci_set_mwi(ha->pdev))
323 mwi = PCI_COMMAND_INVALIDATE;
324 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
326 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
327 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
328 w &= ~PCI_COMMAND_INTX_DISABLE;
329 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
331 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
333 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
334 pcix_cmd_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX);
338 pcix_cmd_reg += PCI_X_CMD;
339 pci_read_config_word(ha->pdev, pcix_cmd_reg, &pcix_cmd);
340 pcix_cmd &= ~PCI_X_CMD_MAX_READ;
342 pci_write_config_word(ha->pdev, pcix_cmd_reg, pcix_cmd);
345 /* PCIe -- adjust Maximum Read Request Size (2048). */
346 pcie_dctl_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
350 pcie_dctl_reg += PCI_EXP_DEVCTL;
351 pci_read_config_word(ha->pdev, pcie_dctl_reg, &pcie_dctl);
352 pcie_dctl &= ~PCI_EXP_DEVCTL_READRQ;
354 pci_write_config_word(ha->pdev, pcie_dctl_reg, pcie_dctl);
357 /* Reset expansion ROM address decode enable */
358 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
359 d &= ~PCI_ROM_ADDRESS_ENABLE;
360 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
362 /* Get PCI bus information. */
363 spin_lock_irqsave(&ha->hardware_lock, flags);
364 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
365 spin_unlock_irqrestore(&ha->hardware_lock, flags);
371 * qla2x00_isp_firmware() - Choose firmware image.
374 * Returns 0 on success.
377 qla2x00_isp_firmware(scsi_qla_host_t *ha)
381 /* Assume loading risc code */
382 rval = QLA_FUNCTION_FAILED;
384 if (ha->flags.disable_risc_code_load) {
385 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
387 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
389 /* Verify checksum of loaded RISC code. */
390 rval = qla2x00_verify_checksum(ha,
391 IS_QLA24XX(ha) || IS_QLA25XX(ha) ? RISC_SADDRESS :
392 *ha->brd_info->fw_info[0].fwstart);
396 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
404 * qla2x00_reset_chip() - Reset ISP chip.
407 * Returns 0 on success.
410 qla2x00_reset_chip(scsi_qla_host_t *ha)
412 unsigned long flags = 0;
413 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
415 unsigned long mbx_flags = 0;
418 ha->isp_ops.disable_intrs(ha);
420 spin_lock_irqsave(&ha->hardware_lock, flags);
422 /* Turn off master enable */
424 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
425 cmd &= ~PCI_COMMAND_MASTER;
426 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
428 if (!IS_QLA2100(ha)) {
430 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
431 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
432 for (cnt = 0; cnt < 30000; cnt++) {
433 if ((RD_REG_WORD(®->hccr) &
434 HCCR_RISC_PAUSE) != 0)
439 RD_REG_WORD(®->hccr); /* PCI Posting. */
443 /* Select FPM registers. */
444 WRT_REG_WORD(®->ctrl_status, 0x20);
445 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
447 /* FPM Soft Reset. */
448 WRT_REG_WORD(®->fpm_diag_config, 0x100);
449 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
451 /* Toggle Fpm Reset. */
452 if (!IS_QLA2200(ha)) {
453 WRT_REG_WORD(®->fpm_diag_config, 0x0);
454 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
457 /* Select frame buffer registers. */
458 WRT_REG_WORD(®->ctrl_status, 0x10);
459 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
461 /* Reset frame buffer FIFOs. */
462 if (IS_QLA2200(ha)) {
463 WRT_FB_CMD_REG(ha, reg, 0xa000);
464 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
466 WRT_FB_CMD_REG(ha, reg, 0x00fc);
468 /* Read back fb_cmd until zero or 3 seconds max */
469 for (cnt = 0; cnt < 3000; cnt++) {
470 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
476 /* Select RISC module registers. */
477 WRT_REG_WORD(®->ctrl_status, 0);
478 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
480 /* Reset RISC processor. */
481 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
482 RD_REG_WORD(®->hccr); /* PCI Posting. */
484 /* Release RISC processor. */
485 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
486 RD_REG_WORD(®->hccr); /* PCI Posting. */
489 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
490 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
492 /* Reset ISP chip. */
493 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
495 /* Wait for RISC to recover from reset. */
496 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
498 * It is necessary to for a delay here since the card doesn't
499 * respond to PCI reads during a reset. On some architectures
500 * this will result in an MCA.
503 for (cnt = 30000; cnt; cnt--) {
504 if ((RD_REG_WORD(®->ctrl_status) &
505 CSR_ISP_SOFT_RESET) == 0)
512 /* Reset RISC processor. */
513 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
515 WRT_REG_WORD(®->semaphore, 0);
517 /* Release RISC processor. */
518 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
519 RD_REG_WORD(®->hccr); /* PCI Posting. */
521 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
522 for (cnt = 0; cnt < 30000; cnt++) {
523 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
524 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
526 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) {
527 if (!(test_bit(ABORT_ISP_ACTIVE,
529 spin_unlock_irqrestore(
530 &ha->mbx_reg_lock, mbx_flags);
534 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
535 spin_unlock_irqrestore(&ha->mbx_reg_lock,
543 /* Turn on master enable */
544 cmd |= PCI_COMMAND_MASTER;
545 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
547 /* Disable RISC pause on FPM parity error. */
548 if (!IS_QLA2100(ha)) {
549 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
550 RD_REG_WORD(®->hccr); /* PCI Posting. */
553 spin_unlock_irqrestore(&ha->hardware_lock, flags);
557 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
560 * Returns 0 on success.
563 qla24xx_reset_risc(scsi_qla_host_t *ha)
565 unsigned long flags = 0;
566 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
570 spin_lock_irqsave(&ha->hardware_lock, flags);
573 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
574 for (cnt = 0; cnt < 30000; cnt++) {
575 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
581 WRT_REG_DWORD(®->ctrl_status,
582 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
583 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
586 /* Wait for firmware to complete NVRAM accesses. */
587 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
588 for (cnt = 10000 ; cnt && d2; cnt--) {
590 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
594 /* Wait for soft-reset to complete. */
595 d2 = RD_REG_DWORD(®->ctrl_status);
596 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
598 d2 = RD_REG_DWORD(®->ctrl_status);
602 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
603 RD_REG_DWORD(®->hccr);
605 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
606 RD_REG_DWORD(®->hccr);
608 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
609 RD_REG_DWORD(®->hccr);
611 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
612 for (cnt = 6000000 ; cnt && d2; cnt--) {
614 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
618 spin_unlock_irqrestore(&ha->hardware_lock, flags);
622 * qla24xx_reset_chip() - Reset ISP24xx chip.
625 * Returns 0 on success.
628 qla24xx_reset_chip(scsi_qla_host_t *ha)
630 ha->isp_ops.disable_intrs(ha);
632 /* Perform RISC reset. */
633 qla24xx_reset_risc(ha);
637 * qla2x00_chip_diag() - Test chip for proper operation.
640 * Returns 0 on success.
643 qla2x00_chip_diag(scsi_qla_host_t *ha)
646 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
647 unsigned long flags = 0;
652 /* Assume a failed state */
653 rval = QLA_FUNCTION_FAILED;
655 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
656 ha->host_no, (u_long)®->flash_address));
658 spin_lock_irqsave(&ha->hardware_lock, flags);
660 /* Reset ISP chip. */
661 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
664 * We need to have a delay here since the card will not respond while
665 * in reset causing an MCA on some architectures.
668 data = qla2x00_debounce_register(®->ctrl_status);
669 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
671 data = RD_REG_WORD(®->ctrl_status);
676 goto chip_diag_failed;
678 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
681 /* Reset RISC processor. */
682 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
683 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
685 /* Workaround for QLA2312 PCI parity error */
686 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
687 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
688 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
690 data = RD_MAILBOX_REG(ha, reg, 0);
697 goto chip_diag_failed;
699 /* Check product ID of chip */
700 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
702 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
703 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
704 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
705 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
706 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
707 mb[3] != PROD_ID_3) {
708 qla_printk(KERN_WARNING, ha,
709 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
711 goto chip_diag_failed;
713 ha->product_id[0] = mb[1];
714 ha->product_id[1] = mb[2];
715 ha->product_id[2] = mb[3];
716 ha->product_id[3] = mb[4];
718 /* Adjust fw RISC transfer size */
719 if (ha->request_q_length > 1024)
720 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
722 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
723 ha->request_q_length;
725 if (IS_QLA2200(ha) &&
726 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
727 /* Limit firmware transfer size with a 2200A */
728 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
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_QLA25XX(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 /* Update firmware options. */
1007 qla2x00_set_fw_options(ha, ha->fw_options);
1011 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1015 /* Update Serial Link options. */
1016 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1019 rval = qla2x00_set_serdes_params(ha,
1020 le16_to_cpu(ha->fw_seriallink_options24[1]),
1021 le16_to_cpu(ha->fw_seriallink_options24[2]),
1022 le16_to_cpu(ha->fw_seriallink_options24[3]));
1023 if (rval != QLA_SUCCESS) {
1024 qla_printk(KERN_WARNING, ha,
1025 "Unable to update Serial Link options (%x).\n", rval);
1030 qla2x00_config_rings(struct scsi_qla_host *ha)
1032 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1034 /* Setup ring parameters in initialization control block. */
1035 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1036 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1037 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1038 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1039 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1040 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1041 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1042 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1044 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1045 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1046 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1047 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1048 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1052 qla24xx_config_rings(struct scsi_qla_host *ha)
1054 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1055 struct init_cb_24xx *icb;
1057 /* Setup ring parameters in initialization control block. */
1058 icb = (struct init_cb_24xx *)ha->init_cb;
1059 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1060 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1061 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1062 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1063 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1064 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1065 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1066 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1068 WRT_REG_DWORD(®->req_q_in, 0);
1069 WRT_REG_DWORD(®->req_q_out, 0);
1070 WRT_REG_DWORD(®->rsp_q_in, 0);
1071 WRT_REG_DWORD(®->rsp_q_out, 0);
1072 RD_REG_DWORD(®->rsp_q_out);
1076 * qla2x00_init_rings() - Initializes firmware.
1079 * Beginning of request ring has initialization control block already built
1080 * by nvram config routine.
1082 * Returns 0 on success.
1085 qla2x00_init_rings(scsi_qla_host_t *ha)
1088 unsigned long flags = 0;
1091 spin_lock_irqsave(&ha->hardware_lock, flags);
1093 /* Clear outstanding commands array. */
1094 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1095 ha->outstanding_cmds[cnt] = NULL;
1097 ha->current_outstanding_cmd = 0;
1099 /* Clear RSCN queue. */
1100 ha->rscn_in_ptr = 0;
1101 ha->rscn_out_ptr = 0;
1103 /* Initialize firmware. */
1104 ha->request_ring_ptr = ha->request_ring;
1105 ha->req_ring_index = 0;
1106 ha->req_q_cnt = ha->request_q_length;
1107 ha->response_ring_ptr = ha->response_ring;
1108 ha->rsp_ring_index = 0;
1110 /* Initialize response queue entries */
1111 qla2x00_init_response_q_entries(ha);
1113 ha->isp_ops.config_rings(ha);
1115 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1117 /* Update any ISP specific firmware options before initialization. */
1118 ha->isp_ops.update_fw_options(ha);
1120 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1121 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1123 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1126 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1134 * qla2x00_fw_ready() - Waits for firmware ready.
1137 * Returns 0 on success.
1140 qla2x00_fw_ready(scsi_qla_host_t *ha)
1143 unsigned long wtime, mtime;
1144 uint16_t min_wait; /* Minimum wait time if loop is down */
1145 uint16_t wait_time; /* Wait time if loop is coming ready */
1150 /* 20 seconds for loop down. */
1154 * Firmware should take at most one RATOV to login, plus 5 seconds for
1155 * our own processing.
1157 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1158 wait_time = min_wait;
1161 /* Min wait time if loop down */
1162 mtime = jiffies + (min_wait * HZ);
1164 /* wait time before firmware ready */
1165 wtime = jiffies + (wait_time * HZ);
1167 /* Wait for ISP to finish LIP */
1168 if (!ha->flags.init_done)
1169 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1171 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1175 rval = qla2x00_get_firmware_state(ha, &fw_state);
1176 if (rval == QLA_SUCCESS) {
1177 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1178 ha->device_flags &= ~DFLG_NO_CABLE;
1180 if (fw_state == FSTATE_READY) {
1181 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1184 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1185 &ha->login_timeout, &ha->r_a_tov);
1191 rval = QLA_FUNCTION_FAILED;
1193 if (atomic_read(&ha->loop_down_timer) &&
1194 (fw_state >= FSTATE_LOSS_OF_SYNC ||
1195 fw_state == FSTATE_WAIT_AL_PA)) {
1196 /* Loop down. Timeout on min_wait for states
1197 * other than Wait for Login.
1199 if (time_after_eq(jiffies, mtime)) {
1200 qla_printk(KERN_INFO, ha,
1201 "Cable is unplugged...\n");
1203 ha->device_flags |= DFLG_NO_CABLE;
1208 /* Mailbox cmd failed. Timeout on min_wait. */
1209 if (time_after_eq(jiffies, mtime))
1213 if (time_after_eq(jiffies, wtime))
1216 /* Delay for a while */
1219 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1220 ha->host_no, fw_state, jiffies));
1223 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1224 ha->host_no, fw_state, jiffies));
1227 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1235 * qla2x00_configure_hba
1236 * Setup adapter context.
1239 * ha = adapter state pointer.
1248 qla2x00_configure_hba(scsi_qla_host_t *ha)
1256 char connect_type[22];
1258 /* Get host addresses. */
1259 rval = qla2x00_get_adapter_id(ha,
1260 &loop_id, &al_pa, &area, &domain, &topo);
1261 if (rval != QLA_SUCCESS) {
1262 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
1263 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1264 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1265 __func__, ha->host_no));
1267 qla_printk(KERN_WARNING, ha,
1268 "ERROR -- Unable to get host loop ID.\n");
1269 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1275 qla_printk(KERN_INFO, ha,
1276 "Cannot get topology - retrying.\n");
1277 return (QLA_FUNCTION_FAILED);
1280 ha->loop_id = loop_id;
1283 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1284 ha->operating_mode = LOOP;
1288 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1290 ha->current_topology = ISP_CFG_NL;
1291 strcpy(connect_type, "(Loop)");
1295 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1297 ha->current_topology = ISP_CFG_FL;
1298 strcpy(connect_type, "(FL_Port)");
1302 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1304 ha->operating_mode = P2P;
1305 ha->current_topology = ISP_CFG_N;
1306 strcpy(connect_type, "(N_Port-to-N_Port)");
1310 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1312 ha->operating_mode = P2P;
1313 ha->current_topology = ISP_CFG_F;
1314 strcpy(connect_type, "(F_Port)");
1318 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1320 ha->host_no, topo));
1321 ha->current_topology = ISP_CFG_NL;
1322 strcpy(connect_type, "(Loop)");
1326 /* Save Host port and loop ID. */
1327 /* byte order - Big Endian */
1328 ha->d_id.b.domain = domain;
1329 ha->d_id.b.area = area;
1330 ha->d_id.b.al_pa = al_pa;
1332 if (!ha->flags.init_done)
1333 qla_printk(KERN_INFO, ha,
1334 "Topology - %s, Host Loop address 0x%x\n",
1335 connect_type, ha->loop_id);
1338 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1340 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1347 * NVRAM configuration for ISP 2xxx
1350 * ha = adapter block pointer.
1353 * initialization control block in response_ring
1354 * host adapters parameters in host adapter block
1360 qla2x00_nvram_config(scsi_qla_host_t *ha)
1365 uint8_t *dptr1, *dptr2;
1366 init_cb_t *icb = ha->init_cb;
1367 nvram_t *nv = (nvram_t *)ha->request_ring;
1368 uint8_t *ptr = (uint8_t *)ha->request_ring;
1369 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1373 /* Determine NVRAM starting address. */
1374 ha->nvram_size = sizeof(nvram_t);
1376 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1377 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1378 ha->nvram_base = 0x80;
1380 /* Get NVRAM data and calculate checksum. */
1381 ha->isp_ops.read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1382 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1385 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1386 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1389 /* Bad NVRAM data, set defaults parameters. */
1390 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1391 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1392 /* Reset NVRAM data. */
1393 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1394 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1396 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1397 "invalid -- WWPN) defaults.\n");
1400 * Set default initialization control block.
1402 memset(nv, 0, ha->nvram_size);
1403 nv->parameter_block_version = ICB_VERSION;
1405 if (IS_QLA23XX(ha)) {
1406 nv->firmware_options[0] = BIT_2 | BIT_1;
1407 nv->firmware_options[1] = BIT_7 | BIT_5;
1408 nv->add_firmware_options[0] = BIT_5;
1409 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1410 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1411 nv->special_options[1] = BIT_7;
1412 } else if (IS_QLA2200(ha)) {
1413 nv->firmware_options[0] = BIT_2 | BIT_1;
1414 nv->firmware_options[1] = BIT_7 | BIT_5;
1415 nv->add_firmware_options[0] = BIT_5;
1416 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1417 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1418 } else if (IS_QLA2100(ha)) {
1419 nv->firmware_options[0] = BIT_3 | BIT_1;
1420 nv->firmware_options[1] = BIT_5;
1421 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1424 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1425 nv->execution_throttle = __constant_cpu_to_le16(16);
1426 nv->retry_count = 8;
1427 nv->retry_delay = 1;
1429 nv->port_name[0] = 33;
1430 nv->port_name[3] = 224;
1431 nv->port_name[4] = 139;
1433 nv->login_timeout = 4;
1436 * Set default host adapter parameters
1438 nv->host_p[1] = BIT_2;
1439 nv->reset_delay = 5;
1440 nv->port_down_retry_count = 8;
1441 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1442 nv->link_down_timeout = 60;
1447 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1449 * The SN2 does not provide BIOS emulation which means you can't change
1450 * potentially bogus BIOS settings. Force the use of default settings
1451 * for link rate and frame size. Hope that the rest of the settings
1454 if (ia64_platform_is("sn2")) {
1455 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1457 nv->special_options[1] = BIT_7;
1461 /* Reset Initialization control block */
1462 memset(icb, 0, ha->init_cb_size);
1465 * Setup driver NVRAM options.
1467 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1468 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1469 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1470 nv->firmware_options[1] &= ~BIT_4;
1472 if (IS_QLA23XX(ha)) {
1473 nv->firmware_options[0] |= BIT_2;
1474 nv->firmware_options[0] &= ~BIT_3;
1475 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1477 if (IS_QLA2300(ha)) {
1478 if (ha->fb_rev == FPM_2310) {
1479 strcpy(ha->model_number, "QLA2310");
1481 strcpy(ha->model_number, "QLA2300");
1485 memcmp(nv->model_number, BINZERO,
1486 sizeof(nv->model_number)) != 0) {
1489 strncpy(ha->model_number, nv->model_number,
1490 sizeof(nv->model_number));
1491 st = en = ha->model_number;
1492 en += sizeof(nv->model_number) - 1;
1494 if (*en != 0x20 && *en != 0x00)
1501 index = (ha->pdev->subsystem_device & 0xff);
1502 if (index < QLA_MODEL_NAMES) {
1503 strcpy(ha->model_number,
1504 qla2x00_model_name[index]);
1506 qla2x00_model_desc[index];
1508 strcpy(ha->model_number, "QLA23xx");
1512 } else if (IS_QLA2200(ha)) {
1513 nv->firmware_options[0] |= BIT_2;
1515 * 'Point-to-point preferred, else loop' is not a safe
1516 * connection mode setting.
1518 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1520 /* Force 'loop preferred, else point-to-point'. */
1521 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1522 nv->add_firmware_options[0] |= BIT_5;
1524 strcpy(ha->model_number, "QLA22xx");
1525 } else /*if (IS_QLA2100(ha))*/ {
1526 strcpy(ha->model_number, "QLA2100");
1530 * Copy over NVRAM RISC parameter block to initialization control block.
1532 dptr1 = (uint8_t *)icb;
1533 dptr2 = (uint8_t *)&nv->parameter_block_version;
1534 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1536 *dptr1++ = *dptr2++;
1538 /* Copy 2nd half. */
1539 dptr1 = (uint8_t *)icb->add_firmware_options;
1540 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1542 *dptr1++ = *dptr2++;
1544 /* Prepare nodename */
1545 if ((icb->firmware_options[1] & BIT_6) == 0) {
1547 * Firmware will apply the following mask if the nodename was
1550 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1551 icb->node_name[0] &= 0xF0;
1555 * Set host adapter parameters.
1557 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1558 /* Always load RISC code on non ISP2[12]00 chips. */
1559 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1560 ha->flags.disable_risc_code_load = 0;
1561 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1562 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1563 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1564 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1566 ha->operating_mode =
1567 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1569 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1570 sizeof(ha->fw_seriallink_options));
1572 /* save HBA serial number */
1573 ha->serial0 = icb->port_name[5];
1574 ha->serial1 = icb->port_name[6];
1575 ha->serial2 = icb->port_name[7];
1576 ha->node_name = icb->node_name;
1577 ha->port_name = icb->port_name;
1579 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1581 ha->retry_count = nv->retry_count;
1583 /* Set minimum login_timeout to 4 seconds. */
1584 if (nv->login_timeout < ql2xlogintimeout)
1585 nv->login_timeout = ql2xlogintimeout;
1586 if (nv->login_timeout < 4)
1587 nv->login_timeout = 4;
1588 ha->login_timeout = nv->login_timeout;
1589 icb->login_timeout = nv->login_timeout;
1591 /* Set minimum RATOV to 200 tenths of a second. */
1594 ha->loop_reset_delay = nv->reset_delay;
1596 /* Link Down Timeout = 0:
1598 * When Port Down timer expires we will start returning
1599 * I/O's to OS with "DID_NO_CONNECT".
1601 * Link Down Timeout != 0:
1603 * The driver waits for the link to come up after link down
1604 * before returning I/Os to OS with "DID_NO_CONNECT".
1606 if (nv->link_down_timeout == 0) {
1607 ha->loop_down_abort_time =
1608 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1610 ha->link_down_timeout = nv->link_down_timeout;
1611 ha->loop_down_abort_time =
1612 (LOOP_DOWN_TIME - ha->link_down_timeout);
1616 * Need enough time to try and get the port back.
1618 ha->port_down_retry_count = nv->port_down_retry_count;
1619 if (qlport_down_retry)
1620 ha->port_down_retry_count = qlport_down_retry;
1621 /* Set login_retry_count */
1622 ha->login_retry_count = nv->retry_count;
1623 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1624 ha->port_down_retry_count > 3)
1625 ha->login_retry_count = ha->port_down_retry_count;
1626 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1627 ha->login_retry_count = ha->port_down_retry_count;
1628 if (ql2xloginretrycount)
1629 ha->login_retry_count = ql2xloginretrycount;
1631 icb->lun_enables = __constant_cpu_to_le16(0);
1632 icb->command_resource_count = 0;
1633 icb->immediate_notify_resource_count = 0;
1634 icb->timeout = __constant_cpu_to_le16(0);
1636 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1638 icb->firmware_options[0] &= ~BIT_3;
1639 icb->add_firmware_options[0] &=
1640 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1641 icb->add_firmware_options[0] |= BIT_2;
1642 icb->response_accumulation_timer = 3;
1643 icb->interrupt_delay_timer = 5;
1645 ha->flags.process_response_queue = 1;
1648 if (!ha->flags.init_done) {
1649 ha->zio_mode = icb->add_firmware_options[0] &
1650 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1651 ha->zio_timer = icb->interrupt_delay_timer ?
1652 icb->interrupt_delay_timer: 2;
1654 icb->add_firmware_options[0] &=
1655 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1656 ha->flags.process_response_queue = 0;
1657 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1658 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1659 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1660 ha->zio_timer * 100));
1661 qla_printk(KERN_INFO, ha,
1662 "ZIO mode %d enabled; timer delay (%d us).\n",
1663 ha->zio_mode, ha->zio_timer * 100);
1665 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1666 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1667 ha->flags.process_response_queue = 1;
1672 DEBUG2_3(printk(KERN_WARNING
1673 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1679 qla2x00_rport_add(void *data)
1681 fc_port_t *fcport = data;
1683 qla2x00_reg_remote_port(fcport->ha, fcport);
1687 qla2x00_rport_del(void *data)
1689 fc_port_t *fcport = data;
1690 struct fc_rport *rport;
1691 unsigned long flags;
1693 spin_lock_irqsave(&fcport->rport_lock, flags);
1694 rport = fcport->drport;
1695 fcport->drport = NULL;
1696 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1698 fc_remote_port_delete(rport);
1703 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1705 * @flags: allocation flags
1707 * Returns a pointer to the allocated fcport, or NULL, if none available.
1710 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1714 fcport = kmalloc(sizeof(fc_port_t), flags);
1718 /* Setup fcport template structure. */
1719 memset(fcport, 0, sizeof (fc_port_t));
1721 fcport->port_type = FCT_UNKNOWN;
1722 fcport->loop_id = FC_NO_LOOP_ID;
1723 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1724 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1725 fcport->flags = FCF_RLC_SUPPORT;
1726 fcport->supported_classes = FC_COS_UNSPECIFIED;
1727 spin_lock_init(&fcport->rport_lock);
1728 INIT_WORK(&fcport->rport_add_work, qla2x00_rport_add, fcport);
1729 INIT_WORK(&fcport->rport_del_work, qla2x00_rport_del, fcport);
1735 * qla2x00_configure_loop
1736 * Updates Fibre Channel Device Database with what is actually on loop.
1739 * ha = adapter block pointer.
1744 * 2 = database was full and device was not configured.
1747 qla2x00_configure_loop(scsi_qla_host_t *ha)
1750 unsigned long flags, save_flags;
1754 /* Get Initiator ID */
1755 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1756 rval = qla2x00_configure_hba(ha);
1757 if (rval != QLA_SUCCESS) {
1758 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1764 save_flags = flags = ha->dpc_flags;
1765 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1766 ha->host_no, flags));
1769 * If we have both an RSCN and PORT UPDATE pending then handle them
1770 * both at the same time.
1772 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1773 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1775 /* Determine what we need to do */
1776 if (ha->current_topology == ISP_CFG_FL &&
1777 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1779 ha->flags.rscn_queue_overflow = 1;
1780 set_bit(RSCN_UPDATE, &flags);
1782 } else if (ha->current_topology == ISP_CFG_F &&
1783 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1785 ha->flags.rscn_queue_overflow = 1;
1786 set_bit(RSCN_UPDATE, &flags);
1787 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1789 } else if (!ha->flags.online ||
1790 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1792 ha->flags.rscn_queue_overflow = 1;
1793 set_bit(RSCN_UPDATE, &flags);
1794 set_bit(LOCAL_LOOP_UPDATE, &flags);
1797 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1798 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1799 rval = QLA_FUNCTION_FAILED;
1801 rval = qla2x00_configure_local_loop(ha);
1805 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1806 if (LOOP_TRANSITION(ha)) {
1807 rval = QLA_FUNCTION_FAILED;
1809 rval = qla2x00_configure_fabric(ha);
1813 if (rval == QLA_SUCCESS) {
1814 if (atomic_read(&ha->loop_down_timer) ||
1815 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1816 rval = QLA_FUNCTION_FAILED;
1818 atomic_set(&ha->loop_state, LOOP_READY);
1820 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1825 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1826 __func__, ha->host_no));
1828 DEBUG3(printk("%s: exiting normally\n", __func__));
1831 /* Restore state if a resync event occured during processing */
1832 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1833 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1834 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1835 if (test_bit(RSCN_UPDATE, &save_flags))
1836 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1845 * qla2x00_configure_local_loop
1846 * Updates Fibre Channel Device Database with local loop devices.
1849 * ha = adapter block pointer.
1855 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1860 fc_port_t *fcport, *new_fcport;
1866 uint8_t domain, area, al_pa;
1870 entries = MAX_FIBRE_DEVICES;
1872 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1873 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1875 /* Get list of logged in devices. */
1876 memset(ha->gid_list, 0, GID_LIST_SIZE);
1877 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1879 if (rval != QLA_SUCCESS)
1880 goto cleanup_allocation;
1882 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1883 ha->host_no, entries));
1884 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1885 entries * sizeof(struct gid_list_info)));
1887 /* Allocate temporary fcport for any new fcports discovered. */
1888 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1889 if (new_fcport == NULL) {
1890 rval = QLA_MEMORY_ALLOC_FAILED;
1891 goto cleanup_allocation;
1893 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1896 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1898 list_for_each_entry(fcport, &ha->fcports, list) {
1899 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1900 fcport->port_type != FCT_BROADCAST &&
1901 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1903 DEBUG(printk("scsi(%ld): Marking port lost, "
1905 ha->host_no, fcport->loop_id));
1907 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1908 fcport->flags &= ~FCF_FARP_DONE;
1912 /* Add devices to port list. */
1913 id_iter = (char *)ha->gid_list;
1914 for (index = 0; index < entries; index++) {
1915 domain = ((struct gid_list_info *)id_iter)->domain;
1916 area = ((struct gid_list_info *)id_iter)->area;
1917 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1918 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1919 loop_id = (uint16_t)
1920 ((struct gid_list_info *)id_iter)->loop_id_2100;
1922 loop_id = le16_to_cpu(
1923 ((struct gid_list_info *)id_iter)->loop_id);
1924 id_iter += ha->gid_list_info_size;
1926 /* Bypass reserved domain fields. */
1927 if ((domain & 0xf0) == 0xf0)
1930 /* Bypass if not same domain and area of adapter. */
1931 if (area && domain &&
1932 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
1935 /* Bypass invalid local loop ID. */
1936 if (loop_id > LAST_LOCAL_LOOP_ID)
1939 /* Fill in member data. */
1940 new_fcport->d_id.b.domain = domain;
1941 new_fcport->d_id.b.area = area;
1942 new_fcport->d_id.b.al_pa = al_pa;
1943 new_fcport->loop_id = loop_id;
1944 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1945 if (rval2 != QLA_SUCCESS) {
1946 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1947 "information -- get_port_database=%x, "
1949 ha->host_no, rval2, new_fcport->loop_id));
1950 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
1952 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
1956 /* Check for matching device in port list. */
1959 list_for_each_entry(fcport, &ha->fcports, list) {
1960 if (memcmp(new_fcport->port_name, fcport->port_name,
1964 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1965 FCF_PERSISTENT_BOUND);
1966 fcport->loop_id = new_fcport->loop_id;
1967 fcport->port_type = new_fcport->port_type;
1968 fcport->d_id.b24 = new_fcport->d_id.b24;
1969 memcpy(fcport->node_name, new_fcport->node_name,
1977 /* New device, add to fcports list. */
1978 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1979 list_add_tail(&new_fcport->list, &ha->fcports);
1981 /* Allocate a new replacement fcport. */
1982 fcport = new_fcport;
1983 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1984 if (new_fcport == NULL) {
1985 rval = QLA_MEMORY_ALLOC_FAILED;
1986 goto cleanup_allocation;
1988 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1991 qla2x00_update_fcport(ha, fcport);
1999 if (rval != QLA_SUCCESS) {
2000 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2001 "rval=%x\n", ha->host_no, rval));
2005 ha->device_flags |= DFLG_LOCAL_DEVICES;
2006 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2013 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
2017 qla2x00_mark_all_devices_lost(ha, 0);
2018 list_for_each_entry(fcport, &ha->fcports, list) {
2019 if (fcport->port_type != FCT_TARGET)
2022 qla2x00_update_fcport(ha, fcport);
2027 * qla2x00_update_fcport
2028 * Updates device on list.
2031 * ha = adapter block pointer.
2032 * fcport = port structure pointer.
2042 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2045 fcport->login_retry = 0;
2046 fcport->port_login_retry_count = ha->port_down_retry_count *
2048 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2050 fcport->flags &= ~FCF_LOGIN_NEEDED;
2052 if (fcport->port_type == FCT_INITIATOR ||
2053 fcport->port_type == FCT_BROADCAST)
2054 fcport->device_type = TYPE_PROCESSOR;
2056 atomic_set(&fcport->state, FCS_ONLINE);
2058 if (ha->flags.init_done)
2059 qla2x00_reg_remote_port(ha, fcport);
2063 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2065 struct fc_rport_identifiers rport_ids;
2066 struct fc_rport *rport;
2067 unsigned long flags;
2070 qla2x00_rport_del(fcport);
2074 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2075 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2076 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2077 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2078 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2079 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2081 qla_printk(KERN_WARNING, ha,
2082 "Unable to allocate fc remote port!\n");
2085 spin_lock_irqsave(&fcport->rport_lock, flags);
2086 fcport->rport = rport;
2087 *((fc_port_t **)rport->dd_data) = fcport;
2088 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2090 rport->supported_classes = fcport->supported_classes;
2092 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2093 if (fcport->port_type == FCT_INITIATOR)
2094 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2095 if (fcport->port_type == FCT_TARGET)
2096 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2097 fc_remote_port_rolechg(rport, rport_ids.roles);
2099 if (rport->scsi_target_id != -1 &&
2100 rport->scsi_target_id < ha->host->max_id)
2101 fcport->os_target_id = rport->scsi_target_id;
2105 * qla2x00_configure_fabric
2106 * Setup SNS devices with loop ID's.
2109 * ha = adapter block pointer.
2116 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2119 fc_port_t *fcport, *fcptemp;
2120 uint16_t next_loopid;
2121 uint16_t mb[MAILBOX_REGISTER_COUNT];
2123 LIST_HEAD(new_fcports);
2125 /* If FL port exists, then SNS is present */
2126 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
2127 loop_id = NPH_F_PORT;
2129 loop_id = SNS_FL_PORT;
2130 rval = qla2x00_get_port_name(ha, loop_id, NULL, 0);
2131 if (rval != QLA_SUCCESS) {
2132 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2133 "Port\n", ha->host_no));
2135 ha->device_flags &= ~SWITCH_FOUND;
2136 return (QLA_SUCCESS);
2139 /* Mark devices that need re-synchronization. */
2140 rval2 = qla2x00_device_resync(ha);
2141 if (rval2 == QLA_RSCNS_HANDLED) {
2142 /* No point doing the scan, just continue. */
2143 return (QLA_SUCCESS);
2147 if (ql2xfdmienable &&
2148 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2149 qla2x00_fdmi_register(ha);
2151 /* Ensure we are logged into the SNS. */
2152 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
2155 loop_id = SIMPLE_NAME_SERVER;
2156 ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
2157 0xfc, mb, BIT_1 | BIT_0);
2158 if (mb[0] != MBS_COMMAND_COMPLETE) {
2159 DEBUG2(qla_printk(KERN_INFO, ha,
2160 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2161 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2162 mb[0], mb[1], mb[2], mb[6], mb[7]));
2163 return (QLA_SUCCESS);
2166 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2167 if (qla2x00_rft_id(ha)) {
2169 DEBUG2(printk("scsi(%ld): Register FC-4 "
2170 "TYPE failed.\n", ha->host_no));
2172 if (qla2x00_rff_id(ha)) {
2174 DEBUG2(printk("scsi(%ld): Register FC-4 "
2175 "Features failed.\n", ha->host_no));
2177 if (qla2x00_rnn_id(ha)) {
2179 DEBUG2(printk("scsi(%ld): Register Node Name "
2180 "failed.\n", ha->host_no));
2181 } else if (qla2x00_rsnn_nn(ha)) {
2183 DEBUG2(printk("scsi(%ld): Register Symbolic "
2184 "Node Name failed.\n", ha->host_no));
2188 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2189 if (rval != QLA_SUCCESS)
2193 * Logout all previous fabric devices marked lost, except
2196 list_for_each_entry(fcport, &ha->fcports, list) {
2197 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2200 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2203 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2204 qla2x00_mark_device_lost(ha, fcport,
2205 ql2xplogiabsentdevice, 0);
2206 if (fcport->loop_id != FC_NO_LOOP_ID &&
2207 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2208 fcport->port_type != FCT_INITIATOR &&
2209 fcport->port_type != FCT_BROADCAST) {
2210 ha->isp_ops.fabric_logout(ha,
2212 fcport->d_id.b.domain,
2213 fcport->d_id.b.area,
2214 fcport->d_id.b.al_pa);
2215 fcport->loop_id = FC_NO_LOOP_ID;
2220 /* Starting free loop ID. */
2221 next_loopid = ha->min_external_loopid;
2224 * Scan through our port list and login entries that need to be
2227 list_for_each_entry(fcport, &ha->fcports, list) {
2228 if (atomic_read(&ha->loop_down_timer) ||
2229 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2232 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2233 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2236 if (fcport->loop_id == FC_NO_LOOP_ID) {
2237 fcport->loop_id = next_loopid;
2238 rval = qla2x00_find_new_loop_id(ha, fcport);
2239 if (rval != QLA_SUCCESS) {
2240 /* Ran out of IDs to use */
2244 /* Login and update database */
2245 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2248 /* Exit if out of loop IDs. */
2249 if (rval != QLA_SUCCESS) {
2254 * Login and add the new devices to our port list.
2256 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2257 if (atomic_read(&ha->loop_down_timer) ||
2258 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2261 /* Find a new loop ID to use. */
2262 fcport->loop_id = next_loopid;
2263 rval = qla2x00_find_new_loop_id(ha, fcport);
2264 if (rval != QLA_SUCCESS) {
2265 /* Ran out of IDs to use */
2269 /* Remove device from the new list and add it to DB */
2270 list_del(&fcport->list);
2271 list_add_tail(&fcport->list, &ha->fcports);
2273 /* Login and update database */
2274 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2278 /* Free all new device structures not processed. */
2279 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2280 list_del(&fcport->list);
2285 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2286 "rval=%d\n", ha->host_no, rval));
2294 * qla2x00_find_all_fabric_devs
2297 * ha = adapter block pointer.
2298 * dev = database device entry pointer.
2307 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2311 fc_port_t *fcport, *new_fcport, *fcptemp;
2316 int first_dev, last_dev;
2317 port_id_t wrap, nxt_d_id;
2321 /* Try GID_PT to get device list, else GAN. */
2322 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2325 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2326 "on GA_NXT\n", ha->host_no));
2328 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2329 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2332 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2335 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2342 /* Allocate temporary fcport for any new fcports discovered. */
2343 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2344 if (new_fcport == NULL) {
2346 return (QLA_MEMORY_ALLOC_FAILED);
2348 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2350 /* Set start port ID scan at adapter ID. */
2354 /* Starting free loop ID. */
2355 loop_id = ha->min_external_loopid;
2356 for (; loop_id <= ha->last_loop_id; loop_id++) {
2357 if (qla2x00_is_reserved_id(ha, loop_id))
2360 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2365 wrap.b24 = new_fcport->d_id.b24;
2367 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2368 memcpy(new_fcport->node_name,
2369 swl[swl_idx].node_name, WWN_SIZE);
2370 memcpy(new_fcport->port_name,
2371 swl[swl_idx].port_name, WWN_SIZE);
2373 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2379 /* Send GA_NXT to the switch */
2380 rval = qla2x00_ga_nxt(ha, new_fcport);
2381 if (rval != QLA_SUCCESS) {
2382 qla_printk(KERN_WARNING, ha,
2383 "SNS scan failed -- assuming zero-entry "
2385 list_for_each_entry_safe(fcport, fcptemp,
2386 new_fcports, list) {
2387 list_del(&fcport->list);
2395 /* If wrap on switch device list, exit. */
2397 wrap.b24 = new_fcport->d_id.b24;
2399 } else if (new_fcport->d_id.b24 == wrap.b24) {
2400 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2401 ha->host_no, new_fcport->d_id.b.domain,
2402 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2406 /* Bypass if host adapter. */
2407 if (new_fcport->d_id.b24 == ha->d_id.b24)
2410 /* Bypass if same domain and area of adapter. */
2411 if (((new_fcport->d_id.b24 & 0xffff00) ==
2412 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2416 /* Bypass reserved domain fields. */
2417 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2420 /* Locate matching device in database. */
2422 list_for_each_entry(fcport, &ha->fcports, list) {
2423 if (memcmp(new_fcport->port_name, fcport->port_name,
2430 * If address the same and state FCS_ONLINE, nothing
2433 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2434 atomic_read(&fcport->state) == FCS_ONLINE) {
2439 * If device was not a fabric device before.
2441 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2442 fcport->d_id.b24 = new_fcport->d_id.b24;
2443 fcport->loop_id = FC_NO_LOOP_ID;
2444 fcport->flags |= (FCF_FABRIC_DEVICE |
2446 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2451 * Port ID changed or device was marked to be updated;
2452 * Log it out if still logged in and mark it for
2455 fcport->d_id.b24 = new_fcport->d_id.b24;
2456 fcport->flags |= FCF_LOGIN_NEEDED;
2457 if (fcport->loop_id != FC_NO_LOOP_ID &&
2458 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2459 fcport->port_type != FCT_INITIATOR &&
2460 fcport->port_type != FCT_BROADCAST) {
2461 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2462 fcport->d_id.b.domain, fcport->d_id.b.area,
2463 fcport->d_id.b.al_pa);
2464 fcport->loop_id = FC_NO_LOOP_ID;
2473 /* If device was not in our fcports list, then add it. */
2474 list_add_tail(&new_fcport->list, new_fcports);
2476 /* Allocate a new replacement fcport. */
2477 nxt_d_id.b24 = new_fcport->d_id.b24;
2478 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2479 if (new_fcport == NULL) {
2481 return (QLA_MEMORY_ALLOC_FAILED);
2483 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2484 new_fcport->d_id.b24 = nxt_d_id.b24;
2490 if (!list_empty(new_fcports))
2491 ha->device_flags |= DFLG_FABRIC_DEVICES;
2497 * qla2x00_find_new_loop_id
2498 * Scan through our port list and find a new usable loop ID.
2501 * ha: adapter state pointer.
2502 * dev: port structure pointer.
2505 * qla2x00 local function return status code.
2511 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2516 uint16_t first_loop_id;
2520 /* Save starting loop ID. */
2521 first_loop_id = dev->loop_id;
2524 /* Skip loop ID if already used by adapter. */
2525 if (dev->loop_id == ha->loop_id) {
2529 /* Skip reserved loop IDs. */
2530 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2534 /* Reset loop ID if passed the end. */
2535 if (dev->loop_id > ha->last_loop_id) {
2536 /* first loop ID. */
2537 dev->loop_id = ha->min_external_loopid;
2540 /* Check for loop ID being already in use. */
2543 list_for_each_entry(fcport, &ha->fcports, list) {
2544 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2545 /* ID possibly in use */
2551 /* If not in use then it is free to use. */
2556 /* ID in use. Try next value. */
2559 /* If wrap around. No free ID to use. */
2560 if (dev->loop_id == first_loop_id) {
2561 dev->loop_id = FC_NO_LOOP_ID;
2562 rval = QLA_FUNCTION_FAILED;
2571 * qla2x00_device_resync
2572 * Marks devices in the database that needs resynchronization.
2575 * ha = adapter block pointer.
2581 qla2x00_device_resync(scsi_qla_host_t *ha)
2587 uint32_t rscn_entry;
2588 uint8_t rscn_out_iter;
2592 rval = QLA_RSCNS_HANDLED;
2594 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2595 ha->flags.rscn_queue_overflow) {
2597 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2598 format = MSB(MSW(rscn_entry));
2599 d_id.b.domain = LSB(MSW(rscn_entry));
2600 d_id.b.area = MSB(LSW(rscn_entry));
2601 d_id.b.al_pa = LSB(LSW(rscn_entry));
2603 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2604 "[%02x/%02x%02x%02x].\n",
2605 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2606 d_id.b.area, d_id.b.al_pa));
2609 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2610 ha->rscn_out_ptr = 0;
2612 /* Skip duplicate entries. */
2613 for (rscn_out_iter = ha->rscn_out_ptr;
2614 !ha->flags.rscn_queue_overflow &&
2615 rscn_out_iter != ha->rscn_in_ptr;
2616 rscn_out_iter = (rscn_out_iter ==
2617 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2619 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2622 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2623 "entry found at [%d].\n", ha->host_no,
2626 ha->rscn_out_ptr = rscn_out_iter;
2629 /* Queue overflow, set switch default case. */
2630 if (ha->flags.rscn_queue_overflow) {
2631 DEBUG(printk("scsi(%ld): device_resync: rscn "
2632 "overflow.\n", ha->host_no));
2635 ha->flags.rscn_queue_overflow = 0;
2640 if (ql2xprocessrscn &&
2641 !IS_QLA2100(ha) && !IS_QLA2200(ha) &&
2642 !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
2643 !IS_QLA24XX(ha) && !IS_QLA25XX(ha) &&
2644 ha->flags.init_done) {
2645 /* Handle port RSCN via asyncronous IOCBs */
2646 rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
2648 if (rval2 == QLA_SUCCESS)
2662 ha->rscn_out_ptr = ha->rscn_in_ptr;
2668 /* Abort any outstanding IO descriptors. */
2669 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2670 qla2x00_cancel_io_descriptors(ha);
2672 list_for_each_entry(fcport, &ha->fcports, list) {
2673 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2674 (fcport->d_id.b24 & mask) != d_id.b24 ||
2675 fcport->port_type == FCT_BROADCAST)
2678 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2680 fcport->port_type != FCT_INITIATOR) {
2681 qla2x00_mark_device_lost(ha, fcport,
2685 fcport->flags &= ~FCF_FARP_DONE;
2692 * qla2x00_fabric_dev_login
2693 * Login fabric target device and update FC port database.
2696 * ha: adapter state pointer.
2697 * fcport: port structure list pointer.
2698 * next_loopid: contains value of a new loop ID that can be used
2699 * by the next login attempt.
2702 * qla2x00 local function return status code.
2708 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2709 uint16_t *next_loopid)
2718 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2719 if (rval == QLA_SUCCESS) {
2720 /* Send an ADISC to tape devices.*/
2722 if (fcport->flags & FCF_TAPE_PRESENT)
2724 rval = qla2x00_get_port_database(ha, fcport, opts);
2725 if (rval != QLA_SUCCESS) {
2726 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2727 fcport->d_id.b.domain, fcport->d_id.b.area,
2728 fcport->d_id.b.al_pa);
2729 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2731 qla2x00_update_fcport(ha, fcport);
2739 * qla2x00_fabric_login
2740 * Issue fabric login command.
2743 * ha = adapter block pointer.
2744 * device = pointer to FC device type structure.
2747 * 0 - Login successfully
2749 * 2 - Initiator device
2753 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2754 uint16_t *next_loopid)
2758 uint16_t tmp_loopid;
2759 uint16_t mb[MAILBOX_REGISTER_COUNT];
2765 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2766 "for port %02x%02x%02x.\n",
2767 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2768 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2770 /* Login fcport on switch. */
2771 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2772 fcport->d_id.b.domain, fcport->d_id.b.area,
2773 fcport->d_id.b.al_pa, mb, BIT_0);
2774 if (mb[0] == MBS_PORT_ID_USED) {
2776 * Device has another loop ID. The firmware team
2777 * recommends the driver perform an implicit login with
2778 * the specified ID again. The ID we just used is save
2779 * here so we return with an ID that can be tried by
2783 tmp_loopid = fcport->loop_id;
2784 fcport->loop_id = mb[1];
2786 DEBUG(printk("Fabric Login: port in use - next "
2787 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2788 fcport->loop_id, fcport->d_id.b.domain,
2789 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2791 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2796 /* A retry occurred before. */
2797 *next_loopid = tmp_loopid;
2800 * No retry occurred before. Just increment the
2801 * ID value for next login.
2803 *next_loopid = (fcport->loop_id + 1);
2806 if (mb[1] & BIT_0) {
2807 fcport->port_type = FCT_INITIATOR;
2809 fcport->port_type = FCT_TARGET;
2810 if (mb[1] & BIT_1) {
2811 fcport->flags |= FCF_TAPE_PRESENT;
2816 fcport->supported_classes |= FC_COS_CLASS2;
2818 fcport->supported_classes |= FC_COS_CLASS3;
2822 } else if (mb[0] == MBS_LOOP_ID_USED) {
2824 * Loop ID already used, try next loop ID.
2827 rval = qla2x00_find_new_loop_id(ha, fcport);
2828 if (rval != QLA_SUCCESS) {
2829 /* Ran out of loop IDs to use */
2832 } else if (mb[0] == MBS_COMMAND_ERROR) {
2834 * Firmware possibly timed out during login. If NO
2835 * retries are left to do then the device is declared
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 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2848 * unrecoverable / not handled error
2850 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2851 "loop_id=%x jiffies=%lx.\n",
2852 __func__, ha->host_no, mb[0],
2853 fcport->d_id.b.domain, fcport->d_id.b.area,
2854 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2856 *next_loopid = fcport->loop_id;
2857 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2858 fcport->d_id.b.domain, fcport->d_id.b.area,
2859 fcport->d_id.b.al_pa);
2860 fcport->loop_id = FC_NO_LOOP_ID;
2861 fcport->login_retry = 0;
2872 * qla2x00_local_device_login
2873 * Issue local device login command.
2876 * ha = adapter block pointer.
2877 * loop_id = loop id of device to login to.
2879 * Returns (Where's the #define!!!!):
2880 * 0 - Login successfully
2885 qla2x00_local_device_login(scsi_qla_host_t *ha, uint16_t loop_id)
2888 uint16_t mb[MAILBOX_REGISTER_COUNT];
2890 memset(mb, 0, sizeof(mb));
2891 rval = qla2x00_login_local_device(ha, loop_id, mb, BIT_0);
2892 if (rval == QLA_SUCCESS) {
2893 /* Interrogate mailbox registers for any errors */
2894 if (mb[0] == MBS_COMMAND_ERROR)
2896 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
2897 /* device not in PCB table */
2905 * qla2x00_loop_resync
2906 * Resync with fibre channel devices.
2909 * ha = adapter block pointer.
2915 qla2x00_loop_resync(scsi_qla_host_t *ha)
2922 atomic_set(&ha->loop_state, LOOP_UPDATE);
2923 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2924 if (ha->flags.online) {
2925 if (!(rval = qla2x00_fw_ready(ha))) {
2926 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2929 atomic_set(&ha->loop_state, LOOP_UPDATE);
2931 /* Issue a marker after FW becomes ready. */
2932 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
2933 ha->marker_needed = 0;
2935 /* Remap devices on Loop. */
2936 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2938 qla2x00_configure_loop(ha);
2940 } while (!atomic_read(&ha->loop_down_timer) &&
2941 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
2943 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
2947 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2948 return (QLA_FUNCTION_FAILED);
2952 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
2959 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
2965 list_for_each_entry(fcport, &ha->fcports, list) {
2966 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
2969 qla2x00_update_fcport(ha, fcport);
2970 fcport->flags &= ~FCF_RESCAN_NEEDED;
2974 qla2x00_probe_for_all_luns(ha);
2978 qla2x00_update_fcports(scsi_qla_host_t *ha)
2982 /* Go with deferred removal of rport references. */
2983 list_for_each_entry(fcport, &ha->fcports, list)
2985 qla2x00_rport_del(fcport);
2990 * Resets ISP and aborts all outstanding commands.
2993 * ha = adapter block pointer.
2999 qla2x00_abort_isp(scsi_qla_host_t *ha)
3001 unsigned long flags = 0;
3006 if (ha->flags.online) {
3007 ha->flags.online = 0;
3008 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3010 qla_printk(KERN_INFO, ha,
3011 "Performing ISP error recovery - ha= %p.\n", ha);
3012 ha->isp_ops.reset_chip(ha);
3014 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3015 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3016 atomic_set(&ha->loop_state, LOOP_DOWN);
3017 qla2x00_mark_all_devices_lost(ha, 0);
3019 if (!atomic_read(&ha->loop_down_timer))
3020 atomic_set(&ha->loop_down_timer,
3024 spin_lock_irqsave(&ha->hardware_lock, flags);
3025 /* Requeue all commands in outstanding command list. */
3026 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3027 sp = ha->outstanding_cmds[cnt];
3029 ha->outstanding_cmds[cnt] = NULL;
3031 sp->cmd->result = DID_RESET << 16;
3032 sp->cmd->host_scribble = (unsigned char *)NULL;
3033 qla2x00_sp_compl(ha, sp);
3036 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3038 ha->isp_ops.nvram_config(ha);
3040 if (!qla2x00_restart_isp(ha)) {
3041 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3043 if (!atomic_read(&ha->loop_down_timer)) {
3045 * Issue marker command only when we are going
3046 * to start the I/O .
3048 ha->marker_needed = 1;
3051 ha->flags.online = 1;
3053 ha->isp_ops.enable_intrs(ha);
3055 ha->isp_abort_cnt = 0;
3056 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3057 } else { /* failed the ISP abort */
3058 ha->flags.online = 1;
3059 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3060 if (ha->isp_abort_cnt == 0) {
3061 qla_printk(KERN_WARNING, ha,
3062 "ISP error recovery failed - "
3063 "board disabled\n");
3065 * The next call disables the board
3068 ha->isp_ops.reset_adapter(ha);
3069 ha->flags.online = 0;
3070 clear_bit(ISP_ABORT_RETRY,
3073 } else { /* schedule another ISP abort */
3074 ha->isp_abort_cnt--;
3075 DEBUG(printk("qla%ld: ISP abort - "
3076 "retry remaining %d\n",
3077 ha->host_no, ha->isp_abort_cnt);)
3081 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3082 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3083 "- retrying (%d) more times\n",
3084 ha->host_no, ha->isp_abort_cnt);)
3085 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3093 qla_printk(KERN_INFO, ha,
3094 "qla2x00_abort_isp: **** FAILED ****\n");
3096 DEBUG(printk(KERN_INFO
3097 "qla2x00_abort_isp(%ld): exiting.\n",
3105 * qla2x00_restart_isp
3106 * restarts the ISP after a reset
3109 * ha = adapter block pointer.
3115 qla2x00_restart_isp(scsi_qla_host_t *ha)
3118 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3119 unsigned long flags = 0;
3122 /* If firmware needs to be loaded */
3123 if (qla2x00_isp_firmware(ha)) {
3124 ha->flags.online = 0;
3125 if (!(status = ha->isp_ops.chip_diag(ha))) {
3126 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3127 status = qla2x00_setup_chip(ha);
3131 spin_lock_irqsave(&ha->hardware_lock, flags);
3133 if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha)) {
3135 * Disable SRAM, Instruction RAM and GP RAM
3138 WRT_REG_WORD(®->hccr,
3139 (HCCR_ENABLE_PARITY + 0x0));
3140 RD_REG_WORD(®->hccr);
3143 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3145 status = qla2x00_setup_chip(ha);
3147 spin_lock_irqsave(&ha->hardware_lock, flags);
3149 if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha)) {
3150 /* Enable proper parity */
3153 WRT_REG_WORD(®->hccr,
3154 (HCCR_ENABLE_PARITY + 0x1));
3157 * SRAM, Instruction RAM and GP RAM
3160 WRT_REG_WORD(®->hccr,
3161 (HCCR_ENABLE_PARITY + 0x7));
3162 RD_REG_WORD(®->hccr);
3165 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3170 if (!status && !(status = qla2x00_init_rings(ha))) {
3171 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3172 if (!(status = qla2x00_fw_ready(ha))) {
3173 DEBUG(printk("%s(): Start configure loop, "
3174 "status = %d\n", __func__, status);)
3176 /* Issue a marker after FW becomes ready. */
3177 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3179 ha->flags.online = 1;
3180 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3183 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3184 qla2x00_configure_loop(ha);
3186 } while (!atomic_read(&ha->loop_down_timer) &&
3187 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3189 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3192 /* if no cable then assume it's good */
3193 if ((ha->device_flags & DFLG_NO_CABLE))
3196 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3204 * qla2x00_reset_adapter
3208 * ha = adapter block pointer.
3211 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3213 unsigned long flags = 0;
3214 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3216 ha->flags.online = 0;
3217 ha->isp_ops.disable_intrs(ha);
3219 spin_lock_irqsave(&ha->hardware_lock, flags);
3220 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3221 RD_REG_WORD(®->hccr); /* PCI Posting. */
3222 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3223 RD_REG_WORD(®->hccr); /* PCI Posting. */
3224 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3228 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3230 unsigned long flags = 0;
3231 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3233 ha->flags.online = 0;
3234 ha->isp_ops.disable_intrs(ha);
3236 spin_lock_irqsave(&ha->hardware_lock, flags);
3237 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3238 RD_REG_DWORD(®->hccr);
3239 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3240 RD_REG_DWORD(®->hccr);
3241 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3245 qla24xx_nvram_config(scsi_qla_host_t *ha)
3248 struct init_cb_24xx *icb;
3249 struct nvram_24xx *nv;
3251 uint8_t *dptr1, *dptr2;
3256 icb = (struct init_cb_24xx *)ha->init_cb;
3257 nv = (struct nvram_24xx *)ha->request_ring;
3259 /* Determine NVRAM starting address. */
3260 ha->nvram_size = sizeof(struct nvram_24xx);
3261 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3262 if (PCI_FUNC(ha->pdev->devfn))
3263 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3265 /* Get NVRAM data and calculate checksum. */
3266 dptr = (uint32_t *)nv;
3267 ha->isp_ops.read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3269 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3270 chksum += le32_to_cpu(*dptr++);
3272 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3273 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3276 /* Bad NVRAM data, set defaults parameters. */
3277 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3278 || nv->id[3] != ' ' ||
3279 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3280 /* Reset NVRAM data. */
3281 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3282 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3283 le16_to_cpu(nv->nvram_version));
3284 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3285 "invalid -- WWPN) defaults.\n");
3288 * Set default initialization control block.
3290 memset(nv, 0, ha->nvram_size);
3291 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3292 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3293 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3294 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3295 nv->exchange_count = __constant_cpu_to_le16(0);
3296 nv->hard_address = __constant_cpu_to_le16(124);
3297 nv->port_name[0] = 0x21;
3298 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3299 nv->port_name[2] = 0x00;
3300 nv->port_name[3] = 0xe0;
3301 nv->port_name[4] = 0x8b;
3302 nv->port_name[5] = 0x1c;
3303 nv->port_name[6] = 0x55;
3304 nv->port_name[7] = 0x86;
3305 nv->node_name[0] = 0x20;
3306 nv->node_name[1] = 0x00;
3307 nv->node_name[2] = 0x00;
3308 nv->node_name[3] = 0xe0;
3309 nv->node_name[4] = 0x8b;
3310 nv->node_name[5] = 0x1c;
3311 nv->node_name[6] = 0x55;
3312 nv->node_name[7] = 0x86;
3313 nv->login_retry_count = __constant_cpu_to_le16(8);
3314 nv->link_down_timeout = __constant_cpu_to_le16(200);
3315 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3316 nv->login_timeout = __constant_cpu_to_le16(0);
3317 nv->firmware_options_1 =
3318 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3319 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3320 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3321 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3322 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3323 nv->efi_parameters = __constant_cpu_to_le32(0);
3324 nv->reset_delay = 5;
3325 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3326 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3327 nv->link_down_timeout = __constant_cpu_to_le16(30);
3332 /* Reset Initialization control block */
3333 memset(icb, 0, sizeof(struct init_cb_24xx));
3335 /* Copy 1st segment. */
3336 dptr1 = (uint8_t *)icb;
3337 dptr2 = (uint8_t *)&nv->version;
3338 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3340 *dptr1++ = *dptr2++;
3342 icb->login_retry_count = nv->login_retry_count;
3343 icb->link_down_timeout = nv->link_down_timeout;
3345 /* Copy 2nd segment. */
3346 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3347 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3348 cnt = (uint8_t *)&icb->reserved_3 -
3349 (uint8_t *)&icb->interrupt_delay_timer;
3351 *dptr1++ = *dptr2++;
3354 * Setup driver NVRAM options.
3356 if (memcmp(nv->model_name, BINZERO, sizeof(nv->model_name)) != 0) {
3360 strncpy(ha->model_number, nv->model_name,
3361 sizeof(nv->model_name));
3362 st = en = ha->model_number;
3363 en += sizeof(nv->model_name) - 1;
3365 if (*en != 0x20 && *en != 0x00)
3370 index = (ha->pdev->subsystem_device & 0xff);
3371 if (index < QLA_MODEL_NAMES)
3372 ha->model_desc = qla2x00_model_desc[index];
3374 strcpy(ha->model_number, "QLA2462");
3376 /* Prepare nodename */
3377 if ((icb->firmware_options_1 & BIT_14) == 0) {
3379 * Firmware will apply the following mask if the nodename was
3382 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3383 icb->node_name[0] &= 0xF0;
3386 /* Set host adapter parameters. */
3387 ha->flags.disable_risc_code_load = 0;
3388 ha->flags.enable_lip_reset = 1;
3389 ha->flags.enable_lip_full_login = 1;
3390 ha->flags.enable_target_reset = 1;
3391 ha->flags.enable_led_scheme = 0;
3393 ha->operating_mode =
3394 (icb->firmware_options_2 & (BIT_6 | BIT_5 | BIT_4)) >> 4;
3396 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3397 sizeof(ha->fw_seriallink_options24));
3399 /* save HBA serial number */
3400 ha->serial0 = icb->port_name[5];
3401 ha->serial1 = icb->port_name[6];
3402 ha->serial2 = icb->port_name[7];
3403 ha->node_name = icb->node_name;
3404 ha->port_name = icb->port_name;
3406 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3408 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3410 /* Set minimum login_timeout to 4 seconds. */
3411 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3412 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3413 if (le16_to_cpu(nv->login_timeout) < 4)
3414 nv->login_timeout = __constant_cpu_to_le16(4);
3415 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3416 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3418 /* Set minimum RATOV to 200 tenths of a second. */
3421 ha->loop_reset_delay = nv->reset_delay;
3423 /* Link Down Timeout = 0:
3425 * When Port Down timer expires we will start returning
3426 * I/O's to OS with "DID_NO_CONNECT".
3428 * Link Down Timeout != 0:
3430 * The driver waits for the link to come up after link down
3431 * before returning I/Os to OS with "DID_NO_CONNECT".
3433 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3434 ha->loop_down_abort_time =
3435 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3437 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3438 ha->loop_down_abort_time =
3439 (LOOP_DOWN_TIME - ha->link_down_timeout);
3442 /* Need enough time to try and get the port back. */
3443 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3444 if (qlport_down_retry)
3445 ha->port_down_retry_count = qlport_down_retry;
3447 /* Set login_retry_count */
3448 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3449 if (ha->port_down_retry_count ==
3450 le16_to_cpu(nv->port_down_retry_count) &&
3451 ha->port_down_retry_count > 3)
3452 ha->login_retry_count = ha->port_down_retry_count;
3453 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3454 ha->login_retry_count = ha->port_down_retry_count;
3455 if (ql2xloginretrycount)
3456 ha->login_retry_count = ql2xloginretrycount;
3459 if (!ha->flags.init_done) {
3460 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3461 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3462 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3463 le16_to_cpu(icb->interrupt_delay_timer): 2;
3465 icb->firmware_options_2 &= __constant_cpu_to_le32(
3466 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3467 ha->flags.process_response_queue = 0;
3468 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3469 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3470 "(%d us).\n", ha->host_no, ha->zio_mode,
3471 ha->zio_timer * 100));
3472 qla_printk(KERN_INFO, ha,
3473 "ZIO mode %d enabled; timer delay (%d us).\n",
3474 ha->zio_mode, ha->zio_timer * 100);
3476 icb->firmware_options_2 |= cpu_to_le32(
3477 (uint32_t)ha->zio_mode);
3478 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3479 ha->flags.process_response_queue = 1;
3483 DEBUG2_3(printk(KERN_WARNING
3484 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3489 #if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
3492 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3496 uint16_t *risc_code;
3497 uint32_t risc_addr, risc_size;
3499 struct qla_fw_info *fw_iter;
3503 /* Load firmware sequences */
3504 fw_iter = ha->brd_info->fw_info;
3505 *srisc_addr = *ha->brd_info->fw_info->fwstart;
3506 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
3507 risc_code = fw_iter->fwcode;
3508 risc_size = *fw_iter->fwlen;
3509 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL)
3510 risc_addr = *fw_iter->fwstart;
3512 risc_addr = *fw_iter->lfwstart;
3516 while (risc_size > 0 && !rval) {
3517 cnt = (uint16_t)(ha->fw_transfer_size >> 1);
3518 if (cnt > risc_size)
3521 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
3522 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
3523 ha->host_no, risc_code, cnt, risc_addr));
3525 req_ring = (uint16_t *)ha->request_ring;
3526 for (i = 0; i < cnt; i++)
3527 req_ring[i] = cpu_to_le16(risc_code[i]);
3529 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3532 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
3533 "load segment %d of firmware\n",
3535 qla_printk(KERN_WARNING, ha,
3536 "[ERROR] Failed to load segment %d of "
3539 qla2x00_dump_regs(ha);
3549 /* Next firmware sequence */
3556 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3560 uint32_t *risc_code;
3561 uint32_t risc_addr, risc_size;
3563 struct qla_fw_info *fw_iter;
3567 /* Load firmware sequences */
3568 fw_iter = ha->brd_info->fw_info;
3569 *srisc_addr = *((uint32_t *)fw_iter->lfwstart);
3570 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
3571 risc_code = (uint32_t *)fw_iter->fwcode;
3572 risc_size = *((uint32_t *)fw_iter->fwlen);
3573 risc_addr = *((uint32_t *)fw_iter->lfwstart);
3577 while (risc_size > 0 && !rval) {
3578 cnt = (uint32_t)(ha->fw_transfer_size >> 2);
3579 if (cnt > risc_size)
3582 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
3583 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
3584 ha->host_no, risc_code, cnt, risc_addr));
3586 req_ring = (uint32_t *)ha->request_ring;
3587 for (i = 0; i < cnt; i++)
3588 req_ring[i] = cpu_to_le32(risc_code[i]);
3590 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3593 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
3594 "load segment %d of firmware\n",
3596 qla_printk(KERN_WARNING, ha,
3597 "[ERROR] Failed to load segment %d of "
3600 qla2x00_dump_regs(ha);
3610 /* Next firmware sequence */
3617 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3620 int segments, fragment;
3622 uint32_t *dcode, dlen;
3629 segments = FA_RISC_CODE_SEGMENTS;
3630 faddr = FA_RISC_CODE_ADDR;
3631 dcode = (uint32_t *)ha->request_ring;
3634 /* Validate firmware image by checking version. */
3635 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3636 for (i = 0; i < 4; i++)
3637 dcode[i] = be32_to_cpu(dcode[i]);
3638 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3639 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3640 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3642 qla_printk(KERN_WARNING, ha,
3643 "Unable to verify integrity of flash firmware image!\n");
3644 qla_printk(KERN_WARNING, ha,
3645 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3646 dcode[1], dcode[2], dcode[3]);
3648 return QLA_FUNCTION_FAILED;
3651 while (segments && rval == QLA_SUCCESS) {
3652 /* Read segment's load information. */
3653 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3655 risc_addr = be32_to_cpu(dcode[2]);
3656 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3657 risc_size = be32_to_cpu(dcode[3]);
3660 while (risc_size > 0 && rval == QLA_SUCCESS) {
3661 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3662 if (dlen > risc_size)
3665 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3666 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3667 ha->host_no, risc_addr, dlen, faddr));
3669 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3670 for (i = 0; i < dlen; i++)
3671 dcode[i] = swab32(dcode[i]);
3673 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3676 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3677 "segment %d of firmware\n", ha->host_no,
3679 qla_printk(KERN_WARNING, ha,
3680 "[ERROR] Failed to load segment %d of "
3681 "firmware\n", fragment);
3698 #else /* !defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE) */
3701 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3705 uint16_t *wcode, *fwcode;
3706 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3707 struct fw_blob *blob;
3709 /* Load firmware blob. */
3710 blob = qla2x00_request_firmware(ha);
3712 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3713 return QLA_FUNCTION_FAILED;
3718 wcode = (uint16_t *)ha->request_ring;
3720 fwcode = (uint16_t *)blob->fw->data;
3723 /* Validate firmware image by checking version. */
3724 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3725 qla_printk(KERN_WARNING, ha,
3726 "Unable to verify integrity of firmware image (%Zd)!\n",
3728 goto fail_fw_integrity;
3730 for (i = 0; i < 4; i++)
3731 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3732 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3733 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3734 wcode[2] == 0 && wcode[3] == 0)) {
3735 qla_printk(KERN_WARNING, ha,
3736 "Unable to verify integrity of firmware image!\n");
3737 qla_printk(KERN_WARNING, ha,
3738 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3739 wcode[1], wcode[2], wcode[3]);
3740 goto fail_fw_integrity;
3744 while (*seg && rval == QLA_SUCCESS) {
3746 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3747 risc_size = be16_to_cpu(fwcode[3]);
3749 /* Validate firmware image size. */
3750 fwclen += risc_size * sizeof(uint16_t);
3751 if (blob->fw->size < fwclen) {
3752 qla_printk(KERN_WARNING, ha,
3753 "Unable to verify integrity of firmware image "
3754 "(%Zd)!\n", blob->fw->size);
3755 goto fail_fw_integrity;
3759 while (risc_size > 0 && rval == QLA_SUCCESS) {
3760 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3761 if (wlen > risc_size)
3764 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3765 "addr %x, number of words 0x%x.\n", ha->host_no,
3768 for (i = 0; i < wlen; i++)
3769 wcode[i] = swab16(fwcode[i]);
3771 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3774 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3775 "segment %d of firmware\n", ha->host_no,
3777 qla_printk(KERN_WARNING, ha,
3778 "[ERROR] Failed to load segment %d of "
3779 "firmware\n", fragment);
3795 return QLA_FUNCTION_FAILED;
3799 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3802 int segments, fragment;
3803 uint32_t *dcode, dlen;
3807 struct fw_blob *blob;
3808 uint32_t *fwcode, fwclen;
3810 /* Load firmware blob. */
3811 blob = qla2x00_request_firmware(ha);
3813 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3814 return QLA_FUNCTION_FAILED;
3819 segments = FA_RISC_CODE_SEGMENTS;
3820 dcode = (uint32_t *)ha->request_ring;
3822 fwcode = (uint32_t *)blob->fw->data;
3825 /* Validate firmware image by checking version. */
3826 if (blob->fw->size < 8 * sizeof(uint32_t)) {
3827 qla_printk(KERN_WARNING, ha,
3828 "Unable to verify integrity of firmware image (%Zd)!\n",
3830 goto fail_fw_integrity;
3832 for (i = 0; i < 4; i++)
3833 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3834 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3835 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3836 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3838 qla_printk(KERN_WARNING, ha,
3839 "Unable to verify integrity of firmware image!\n");
3840 qla_printk(KERN_WARNING, ha,
3841 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3842 dcode[1], dcode[2], dcode[3]);
3843 goto fail_fw_integrity;
3846 while (segments && rval == QLA_SUCCESS) {
3847 risc_addr = be32_to_cpu(fwcode[2]);
3848 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3849 risc_size = be32_to_cpu(fwcode[3]);
3851 /* Validate firmware image size. */
3852 fwclen += risc_size * sizeof(uint32_t);
3853 if (blob->fw->size < fwclen) {
3854 qla_printk(KERN_WARNING, ha,
3855 "Unable to verify integrity of firmware image "
3856 "(%Zd)!\n", blob->fw->size);
3858 goto fail_fw_integrity;
3862 while (risc_size > 0 && rval == QLA_SUCCESS) {
3863 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3864 if (dlen > risc_size)
3867 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3868 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3871 for (i = 0; i < dlen; i++)
3872 dcode[i] = swab32(fwcode[i]);
3874 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3877 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3878 "segment %d of firmware\n", ha->host_no,
3880 qla_printk(KERN_WARNING, ha,
3881 "[ERROR] Failed to load segment %d of "
3882 "firmware\n", fragment);
3898 return QLA_FUNCTION_FAILED;