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 static int qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev);
44 /****************************************************************************/
45 /* QLogic ISP2x00 Hardware Support Functions. */
46 /****************************************************************************/
49 * qla2x00_initialize_adapter
53 * ha = adapter block pointer.
59 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
63 /* Clear adapter flags. */
65 ha->flags.reset_active = 0;
66 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
67 atomic_set(&ha->loop_state, LOOP_DOWN);
68 ha->device_flags = DFLG_NO_CABLE;
70 ha->flags.management_server_logged_in = 0;
71 ha->marker_needed = 0;
73 ha->isp_abort_cnt = 0;
74 ha->beacon_blink_led = 0;
75 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
77 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
78 rval = ha->isp_ops.pci_config(ha);
80 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
85 ha->isp_ops.reset_chip(ha);
87 ha->isp_ops.get_flash_version(ha, ha->request_ring);
89 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
91 rval = ha->isp_ops.nvram_config(ha);
93 DEBUG2(printk("scsi(%ld): Unable to verify NVRAM data.\n",
98 if (ha->flags.disable_serdes) {
99 /* Mask HBA via NVRAM settings? */
100 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
101 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
102 ha->port_name[0], ha->port_name[1],
103 ha->port_name[2], ha->port_name[3],
104 ha->port_name[4], ha->port_name[5],
105 ha->port_name[6], ha->port_name[7]);
106 return QLA_FUNCTION_FAILED;
109 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
111 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
112 rval = ha->isp_ops.chip_diag(ha);
115 rval = qla2x00_setup_chip(ha);
119 rval = qla2x00_init_rings(ha);
125 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
128 * Returns 0 on success.
131 qla2100_pci_config(scsi_qla_host_t *ha)
136 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
138 pci_set_master(ha->pdev);
140 if (pci_set_mwi(ha->pdev))
141 mwi = PCI_COMMAND_INVALIDATE;
143 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
144 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
145 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
147 /* Reset expansion ROM address decode enable */
148 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
149 d &= ~PCI_ROM_ADDRESS_ENABLE;
150 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
152 /* Get PCI bus information. */
153 spin_lock_irqsave(&ha->hardware_lock, flags);
154 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
155 spin_unlock_irqrestore(&ha->hardware_lock, flags);
161 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
164 * Returns 0 on success.
167 qla2300_pci_config(scsi_qla_host_t *ha)
171 unsigned long flags = 0;
173 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
175 pci_set_master(ha->pdev);
177 if (pci_set_mwi(ha->pdev))
178 mwi = PCI_COMMAND_INVALIDATE;
180 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
181 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
183 if (IS_QLA2322(ha) || IS_QLA6322(ha))
184 w &= ~PCI_COMMAND_INTX_DISABLE;
187 * If this is a 2300 card and not 2312, reset the
188 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
189 * the 2310 also reports itself as a 2300 so we need to get the
190 * fb revision level -- a 6 indicates it really is a 2300 and
193 if (IS_QLA2300(ha)) {
194 spin_lock_irqsave(&ha->hardware_lock, flags);
197 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
198 for (cnt = 0; cnt < 30000; cnt++) {
199 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
205 /* Select FPM registers. */
206 WRT_REG_WORD(®->ctrl_status, 0x20);
207 RD_REG_WORD(®->ctrl_status);
209 /* Get the fb rev level */
210 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
212 if (ha->fb_rev == FPM_2300)
213 w &= ~PCI_COMMAND_INVALIDATE;
215 /* Deselect FPM registers. */
216 WRT_REG_WORD(®->ctrl_status, 0x0);
217 RD_REG_WORD(®->ctrl_status);
219 /* Release RISC module. */
220 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
221 for (cnt = 0; cnt < 30000; cnt++) {
222 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
228 spin_unlock_irqrestore(&ha->hardware_lock, flags);
230 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
232 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
234 /* Reset expansion ROM address decode enable */
235 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
236 d &= ~PCI_ROM_ADDRESS_ENABLE;
237 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
239 /* Get PCI bus information. */
240 spin_lock_irqsave(&ha->hardware_lock, flags);
241 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
242 spin_unlock_irqrestore(&ha->hardware_lock, flags);
248 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
251 * Returns 0 on success.
254 qla24xx_pci_config(scsi_qla_host_t *ha)
258 unsigned long flags = 0;
259 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
260 int pcix_cmd_reg, pcie_dctl_reg;
262 pci_set_master(ha->pdev);
264 if (pci_set_mwi(ha->pdev))
265 mwi = PCI_COMMAND_INVALIDATE;
267 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
268 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
269 w &= ~PCI_COMMAND_INTX_DISABLE;
270 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
272 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
274 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
275 pcix_cmd_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX);
279 pcix_cmd_reg += PCI_X_CMD;
280 pci_read_config_word(ha->pdev, pcix_cmd_reg, &pcix_cmd);
281 pcix_cmd &= ~PCI_X_CMD_MAX_READ;
283 pci_write_config_word(ha->pdev, pcix_cmd_reg, pcix_cmd);
286 /* PCIe -- adjust Maximum Read Request Size (2048). */
287 pcie_dctl_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
291 pcie_dctl_reg += PCI_EXP_DEVCTL;
292 pci_read_config_word(ha->pdev, pcie_dctl_reg, &pcie_dctl);
293 pcie_dctl &= ~PCI_EXP_DEVCTL_READRQ;
295 pci_write_config_word(ha->pdev, pcie_dctl_reg, pcie_dctl);
298 /* Reset expansion ROM address decode enable */
299 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
300 d &= ~PCI_ROM_ADDRESS_ENABLE;
301 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
303 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->chip_revision);
305 /* Get PCI bus information. */
306 spin_lock_irqsave(&ha->hardware_lock, flags);
307 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
308 spin_unlock_irqrestore(&ha->hardware_lock, flags);
314 * qla2x00_isp_firmware() - Choose firmware image.
317 * Returns 0 on success.
320 qla2x00_isp_firmware(scsi_qla_host_t *ha)
324 /* Assume loading risc code */
325 rval = QLA_FUNCTION_FAILED;
327 if (ha->flags.disable_risc_code_load) {
328 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
330 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
332 /* Verify checksum of loaded RISC code. */
333 rval = qla2x00_verify_checksum(ha, ha->fw_srisc_address);
337 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
345 * qla2x00_reset_chip() - Reset ISP chip.
348 * Returns 0 on success.
351 qla2x00_reset_chip(scsi_qla_host_t *ha)
353 unsigned long flags = 0;
354 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
358 ha->isp_ops.disable_intrs(ha);
360 spin_lock_irqsave(&ha->hardware_lock, flags);
362 /* Turn off master enable */
364 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
365 cmd &= ~PCI_COMMAND_MASTER;
366 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
368 if (!IS_QLA2100(ha)) {
370 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
371 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
372 for (cnt = 0; cnt < 30000; cnt++) {
373 if ((RD_REG_WORD(®->hccr) &
374 HCCR_RISC_PAUSE) != 0)
379 RD_REG_WORD(®->hccr); /* PCI Posting. */
383 /* Select FPM registers. */
384 WRT_REG_WORD(®->ctrl_status, 0x20);
385 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
387 /* FPM Soft Reset. */
388 WRT_REG_WORD(®->fpm_diag_config, 0x100);
389 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
391 /* Toggle Fpm Reset. */
392 if (!IS_QLA2200(ha)) {
393 WRT_REG_WORD(®->fpm_diag_config, 0x0);
394 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
397 /* Select frame buffer registers. */
398 WRT_REG_WORD(®->ctrl_status, 0x10);
399 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
401 /* Reset frame buffer FIFOs. */
402 if (IS_QLA2200(ha)) {
403 WRT_FB_CMD_REG(ha, reg, 0xa000);
404 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
406 WRT_FB_CMD_REG(ha, reg, 0x00fc);
408 /* Read back fb_cmd until zero or 3 seconds max */
409 for (cnt = 0; cnt < 3000; cnt++) {
410 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
416 /* Select RISC module registers. */
417 WRT_REG_WORD(®->ctrl_status, 0);
418 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
420 /* Reset RISC processor. */
421 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
422 RD_REG_WORD(®->hccr); /* PCI Posting. */
424 /* Release RISC processor. */
425 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
426 RD_REG_WORD(®->hccr); /* PCI Posting. */
429 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
430 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
432 /* Reset ISP chip. */
433 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
435 /* Wait for RISC to recover from reset. */
436 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
438 * It is necessary to for a delay here since the card doesn't
439 * respond to PCI reads during a reset. On some architectures
440 * this will result in an MCA.
443 for (cnt = 30000; cnt; cnt--) {
444 if ((RD_REG_WORD(®->ctrl_status) &
445 CSR_ISP_SOFT_RESET) == 0)
452 /* Reset RISC processor. */
453 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
455 WRT_REG_WORD(®->semaphore, 0);
457 /* Release RISC processor. */
458 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
459 RD_REG_WORD(®->hccr); /* PCI Posting. */
461 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
462 for (cnt = 0; cnt < 30000; cnt++) {
463 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
471 /* Turn on master enable */
472 cmd |= PCI_COMMAND_MASTER;
473 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
475 /* Disable RISC pause on FPM parity error. */
476 if (!IS_QLA2100(ha)) {
477 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
478 RD_REG_WORD(®->hccr); /* PCI Posting. */
481 spin_unlock_irqrestore(&ha->hardware_lock, flags);
485 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
488 * Returns 0 on success.
491 qla24xx_reset_risc(scsi_qla_host_t *ha)
493 unsigned long flags = 0;
494 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
498 spin_lock_irqsave(&ha->hardware_lock, flags);
501 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
502 for (cnt = 0; cnt < 30000; cnt++) {
503 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
509 WRT_REG_DWORD(®->ctrl_status,
510 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
511 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
514 /* Wait for firmware to complete NVRAM accesses. */
515 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
516 for (cnt = 10000 ; cnt && d2; cnt--) {
518 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
522 /* Wait for soft-reset to complete. */
523 d2 = RD_REG_DWORD(®->ctrl_status);
524 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
526 d2 = RD_REG_DWORD(®->ctrl_status);
530 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
531 RD_REG_DWORD(®->hccr);
533 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
534 RD_REG_DWORD(®->hccr);
536 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
537 RD_REG_DWORD(®->hccr);
539 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
540 for (cnt = 6000000 ; cnt && d2; cnt--) {
542 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
546 spin_unlock_irqrestore(&ha->hardware_lock, flags);
550 * qla24xx_reset_chip() - Reset ISP24xx chip.
553 * Returns 0 on success.
556 qla24xx_reset_chip(scsi_qla_host_t *ha)
558 ha->isp_ops.disable_intrs(ha);
560 /* Perform RISC reset. */
561 qla24xx_reset_risc(ha);
565 * qla2x00_chip_diag() - Test chip for proper operation.
568 * Returns 0 on success.
571 qla2x00_chip_diag(scsi_qla_host_t *ha)
574 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
575 unsigned long flags = 0;
580 /* Assume a failed state */
581 rval = QLA_FUNCTION_FAILED;
583 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
584 ha->host_no, (u_long)®->flash_address));
586 spin_lock_irqsave(&ha->hardware_lock, flags);
588 /* Reset ISP chip. */
589 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
592 * We need to have a delay here since the card will not respond while
593 * in reset causing an MCA on some architectures.
596 data = qla2x00_debounce_register(®->ctrl_status);
597 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
599 data = RD_REG_WORD(®->ctrl_status);
604 goto chip_diag_failed;
606 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
609 /* Reset RISC processor. */
610 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
611 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
613 /* Workaround for QLA2312 PCI parity error */
614 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
615 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
616 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
618 data = RD_MAILBOX_REG(ha, reg, 0);
625 goto chip_diag_failed;
627 /* Check product ID of chip */
628 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
630 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
631 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
632 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
633 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
634 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
635 mb[3] != PROD_ID_3) {
636 qla_printk(KERN_WARNING, ha,
637 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
639 goto chip_diag_failed;
641 ha->product_id[0] = mb[1];
642 ha->product_id[1] = mb[2];
643 ha->product_id[2] = mb[3];
644 ha->product_id[3] = mb[4];
646 /* Adjust fw RISC transfer size */
647 if (ha->request_q_length > 1024)
648 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
650 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
651 ha->request_q_length;
653 if (IS_QLA2200(ha) &&
654 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
655 /* Limit firmware transfer size with a 2200A */
656 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
659 ha->device_type |= DT_ISP2200A;
660 ha->fw_transfer_size = 128;
663 /* Wrap Incoming Mailboxes Test. */
664 spin_unlock_irqrestore(&ha->hardware_lock, flags);
666 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
667 rval = qla2x00_mbx_reg_test(ha);
669 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
671 qla_printk(KERN_WARNING, ha,
672 "Failed mailbox send register test\n");
675 /* Flag a successful rval */
678 spin_lock_irqsave(&ha->hardware_lock, flags);
682 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
683 "****\n", ha->host_no));
685 spin_unlock_irqrestore(&ha->hardware_lock, flags);
691 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
694 * Returns 0 on success.
697 qla24xx_chip_diag(scsi_qla_host_t *ha)
701 /* Perform RISC reset. */
702 qla24xx_reset_risc(ha);
704 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
706 rval = qla2x00_mbx_reg_test(ha);
708 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
710 qla_printk(KERN_WARNING, ha,
711 "Failed mailbox send register test\n");
713 /* Flag a successful rval */
721 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
724 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
730 qla_printk(KERN_WARNING, ha,
731 "Firmware dump previously allocated.\n");
736 fixed_size = mem_size = eft_size = 0;
737 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
738 fixed_size = sizeof(struct qla2100_fw_dump);
739 } else if (IS_QLA23XX(ha)) {
740 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
741 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
743 } else if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
744 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
745 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
748 /* Allocate memory for Extended Trace Buffer. */
749 eft = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &eft_dma,
752 qla_printk(KERN_WARNING, ha, "Unable to allocate "
753 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
757 rval = qla2x00_trace_control(ha, TC_ENABLE, eft_dma,
760 qla_printk(KERN_WARNING, ha, "Unable to initialize "
761 "EFT (%d).\n", rval);
762 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, eft,
767 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
771 memset(eft, 0, eft_size);
772 ha->eft_dma = eft_dma;
776 req_q_size = ha->request_q_length * sizeof(request_t);
777 rsp_q_size = ha->response_q_length * sizeof(response_t);
779 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
780 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
783 ha->fw_dump = vmalloc(dump_size);
785 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
786 "firmware dump!!!\n", dump_size / 1024);
789 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
797 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
800 ha->fw_dump_len = dump_size;
801 ha->fw_dump->signature[0] = 'Q';
802 ha->fw_dump->signature[1] = 'L';
803 ha->fw_dump->signature[2] = 'G';
804 ha->fw_dump->signature[3] = 'C';
805 ha->fw_dump->version = __constant_htonl(1);
807 ha->fw_dump->fixed_size = htonl(fixed_size);
808 ha->fw_dump->mem_size = htonl(mem_size);
809 ha->fw_dump->req_q_size = htonl(req_q_size);
810 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
812 ha->fw_dump->eft_size = htonl(eft_size);
813 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
814 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
816 ha->fw_dump->header_size =
817 htonl(offsetof(struct qla2xxx_fw_dump, isp));
821 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
824 * Returns 0 on success.
827 qla2x00_resize_request_q(scsi_qla_host_t *ha)
830 uint16_t fw_iocb_cnt = 0;
831 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
832 dma_addr_t request_dma;
833 request_t *request_ring;
835 /* Valid only on recent ISPs. */
836 if (IS_QLA2100(ha) || IS_QLA2200(ha))
839 /* Retrieve IOCB counts available to the firmware. */
840 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
843 /* No point in continuing if current settings are sufficient. */
844 if (fw_iocb_cnt < 1024)
846 if (ha->request_q_length >= request_q_length)
849 /* Attempt to claim larger area for request queue. */
850 request_ring = dma_alloc_coherent(&ha->pdev->dev,
851 (request_q_length + 1) * sizeof(request_t), &request_dma,
853 if (request_ring == NULL)
856 /* Resize successful, report extensions. */
857 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
858 (ha->fw_memory_size + 1) / 1024);
859 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
860 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
862 /* Clear old allocations. */
863 dma_free_coherent(&ha->pdev->dev,
864 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
867 /* Begin using larger queue. */
868 ha->request_q_length = request_q_length;
869 ha->request_ring = request_ring;
870 ha->request_dma = request_dma;
874 * qla2x00_setup_chip() - Load and start RISC firmware.
877 * Returns 0 on success.
880 qla2x00_setup_chip(scsi_qla_host_t *ha)
883 uint32_t srisc_address = 0;
885 /* Load firmware sequences */
886 rval = ha->isp_ops.load_risc(ha, &srisc_address);
887 if (rval == QLA_SUCCESS) {
888 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
889 "code.\n", ha->host_no));
891 rval = qla2x00_verify_checksum(ha, srisc_address);
892 if (rval == QLA_SUCCESS) {
893 /* Start firmware execution. */
894 DEBUG(printk("scsi(%ld): Checksum OK, start "
895 "firmware.\n", ha->host_no));
897 rval = qla2x00_execute_fw(ha, srisc_address);
898 /* Retrieve firmware information. */
899 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
900 qla2x00_get_fw_version(ha,
901 &ha->fw_major_version,
902 &ha->fw_minor_version,
903 &ha->fw_subminor_version,
904 &ha->fw_attributes, &ha->fw_memory_size);
905 qla2x00_resize_request_q(ha);
908 qla2x00_alloc_fw_dump(ha);
911 DEBUG2(printk(KERN_INFO
912 "scsi(%ld): ISP Firmware failed checksum.\n",
918 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
926 * qla2x00_init_response_q_entries() - Initializes response queue entries.
929 * Beginning of request ring has initialization control block already built
930 * by nvram config routine.
932 * Returns 0 on success.
935 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
940 pkt = ha->response_ring_ptr;
941 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
942 pkt->signature = RESPONSE_PROCESSED;
949 * qla2x00_update_fw_options() - Read and process firmware options.
952 * Returns 0 on success.
955 qla2x00_update_fw_options(scsi_qla_host_t *ha)
957 uint16_t swing, emphasis, tx_sens, rx_sens;
959 memset(ha->fw_options, 0, sizeof(ha->fw_options));
960 qla2x00_get_fw_options(ha, ha->fw_options);
962 if (IS_QLA2100(ha) || IS_QLA2200(ha))
965 /* Serial Link options. */
966 DEBUG3(printk("scsi(%ld): Serial link options:\n",
968 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
969 sizeof(ha->fw_seriallink_options)));
971 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
972 if (ha->fw_seriallink_options[3] & BIT_2) {
973 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
976 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
977 emphasis = (ha->fw_seriallink_options[2] &
978 (BIT_4 | BIT_3)) >> 3;
979 tx_sens = ha->fw_seriallink_options[0] &
980 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
981 rx_sens = (ha->fw_seriallink_options[0] &
982 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
983 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
984 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
987 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
988 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
989 ha->fw_options[10] |= BIT_5 |
990 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
991 (tx_sens & (BIT_1 | BIT_0));
994 swing = (ha->fw_seriallink_options[2] &
995 (BIT_7 | BIT_6 | BIT_5)) >> 5;
996 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
997 tx_sens = ha->fw_seriallink_options[1] &
998 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
999 rx_sens = (ha->fw_seriallink_options[1] &
1000 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1001 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1002 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1005 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1006 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1007 ha->fw_options[11] |= BIT_5 |
1008 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1009 (tx_sens & (BIT_1 | BIT_0));
1013 /* Return command IOCBs without waiting for an ABTS to complete. */
1014 ha->fw_options[3] |= BIT_13;
1017 if (ha->flags.enable_led_scheme)
1018 ha->fw_options[2] |= BIT_12;
1020 /* Detect ISP6312. */
1022 ha->fw_options[2] |= BIT_13;
1024 /* Update firmware options. */
1025 qla2x00_set_fw_options(ha, ha->fw_options);
1029 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1033 /* Update Serial Link options. */
1034 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1037 rval = qla2x00_set_serdes_params(ha,
1038 le16_to_cpu(ha->fw_seriallink_options24[1]),
1039 le16_to_cpu(ha->fw_seriallink_options24[2]),
1040 le16_to_cpu(ha->fw_seriallink_options24[3]));
1041 if (rval != QLA_SUCCESS) {
1042 qla_printk(KERN_WARNING, ha,
1043 "Unable to update Serial Link options (%x).\n", rval);
1048 qla2x00_config_rings(struct scsi_qla_host *ha)
1050 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1052 /* Setup ring parameters in initialization control block. */
1053 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1054 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1055 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1056 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1057 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1058 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1059 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1060 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1062 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1063 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1064 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1065 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1066 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1070 qla24xx_config_rings(struct scsi_qla_host *ha)
1072 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1073 struct init_cb_24xx *icb;
1075 /* Setup ring parameters in initialization control block. */
1076 icb = (struct init_cb_24xx *)ha->init_cb;
1077 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1078 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1079 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1080 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1081 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1082 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1083 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1084 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1086 WRT_REG_DWORD(®->req_q_in, 0);
1087 WRT_REG_DWORD(®->req_q_out, 0);
1088 WRT_REG_DWORD(®->rsp_q_in, 0);
1089 WRT_REG_DWORD(®->rsp_q_out, 0);
1090 RD_REG_DWORD(®->rsp_q_out);
1094 * qla2x00_init_rings() - Initializes firmware.
1097 * Beginning of request ring has initialization control block already built
1098 * by nvram config routine.
1100 * Returns 0 on success.
1103 qla2x00_init_rings(scsi_qla_host_t *ha)
1106 unsigned long flags = 0;
1109 spin_lock_irqsave(&ha->hardware_lock, flags);
1111 /* Clear outstanding commands array. */
1112 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1113 ha->outstanding_cmds[cnt] = NULL;
1115 ha->current_outstanding_cmd = 0;
1117 /* Clear RSCN queue. */
1118 ha->rscn_in_ptr = 0;
1119 ha->rscn_out_ptr = 0;
1121 /* Initialize firmware. */
1122 ha->request_ring_ptr = ha->request_ring;
1123 ha->req_ring_index = 0;
1124 ha->req_q_cnt = ha->request_q_length;
1125 ha->response_ring_ptr = ha->response_ring;
1126 ha->rsp_ring_index = 0;
1128 /* Initialize response queue entries */
1129 qla2x00_init_response_q_entries(ha);
1131 ha->isp_ops.config_rings(ha);
1133 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1135 /* Update any ISP specific firmware options before initialization. */
1136 ha->isp_ops.update_fw_options(ha);
1138 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1139 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1141 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1144 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1152 * qla2x00_fw_ready() - Waits for firmware ready.
1155 * Returns 0 on success.
1158 qla2x00_fw_ready(scsi_qla_host_t *ha)
1161 unsigned long wtime, mtime;
1162 uint16_t min_wait; /* Minimum wait time if loop is down */
1163 uint16_t wait_time; /* Wait time if loop is coming ready */
1168 /* 20 seconds for loop down. */
1172 * Firmware should take at most one RATOV to login, plus 5 seconds for
1173 * our own processing.
1175 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1176 wait_time = min_wait;
1179 /* Min wait time if loop down */
1180 mtime = jiffies + (min_wait * HZ);
1182 /* wait time before firmware ready */
1183 wtime = jiffies + (wait_time * HZ);
1185 /* Wait for ISP to finish LIP */
1186 if (!ha->flags.init_done)
1187 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1189 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1193 rval = qla2x00_get_firmware_state(ha, &fw_state);
1194 if (rval == QLA_SUCCESS) {
1195 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1196 ha->device_flags &= ~DFLG_NO_CABLE;
1198 if (fw_state == FSTATE_READY) {
1199 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1202 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1203 &ha->login_timeout, &ha->r_a_tov);
1209 rval = QLA_FUNCTION_FAILED;
1211 if (atomic_read(&ha->loop_down_timer) &&
1212 fw_state != FSTATE_READY) {
1213 /* Loop down. Timeout on min_wait for states
1214 * other than Wait for Login.
1216 if (time_after_eq(jiffies, mtime)) {
1217 qla_printk(KERN_INFO, ha,
1218 "Cable is unplugged...\n");
1220 ha->device_flags |= DFLG_NO_CABLE;
1225 /* Mailbox cmd failed. Timeout on min_wait. */
1226 if (time_after_eq(jiffies, mtime))
1230 if (time_after_eq(jiffies, wtime))
1233 /* Delay for a while */
1236 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1237 ha->host_no, fw_state, jiffies));
1240 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1241 ha->host_no, fw_state, jiffies));
1244 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1252 * qla2x00_configure_hba
1253 * Setup adapter context.
1256 * ha = adapter state pointer.
1265 qla2x00_configure_hba(scsi_qla_host_t *ha)
1273 char connect_type[22];
1275 /* Get host addresses. */
1276 rval = qla2x00_get_adapter_id(ha,
1277 &loop_id, &al_pa, &area, &domain, &topo);
1278 if (rval != QLA_SUCCESS) {
1279 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
1280 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1281 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1282 __func__, ha->host_no));
1284 qla_printk(KERN_WARNING, ha,
1285 "ERROR -- Unable to get host loop ID.\n");
1286 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1292 qla_printk(KERN_INFO, ha,
1293 "Cannot get topology - retrying.\n");
1294 return (QLA_FUNCTION_FAILED);
1297 ha->loop_id = loop_id;
1300 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1301 ha->operating_mode = LOOP;
1305 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1307 ha->current_topology = ISP_CFG_NL;
1308 strcpy(connect_type, "(Loop)");
1312 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1314 ha->current_topology = ISP_CFG_FL;
1315 strcpy(connect_type, "(FL_Port)");
1319 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1321 ha->operating_mode = P2P;
1322 ha->current_topology = ISP_CFG_N;
1323 strcpy(connect_type, "(N_Port-to-N_Port)");
1327 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1329 ha->operating_mode = P2P;
1330 ha->current_topology = ISP_CFG_F;
1331 strcpy(connect_type, "(F_Port)");
1335 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1337 ha->host_no, topo));
1338 ha->current_topology = ISP_CFG_NL;
1339 strcpy(connect_type, "(Loop)");
1343 /* Save Host port and loop ID. */
1344 /* byte order - Big Endian */
1345 ha->d_id.b.domain = domain;
1346 ha->d_id.b.area = area;
1347 ha->d_id.b.al_pa = al_pa;
1349 if (!ha->flags.init_done)
1350 qla_printk(KERN_INFO, ha,
1351 "Topology - %s, Host Loop address 0x%x\n",
1352 connect_type, ha->loop_id);
1355 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1357 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1364 qla2x00_set_model_info(scsi_qla_host_t *ha, uint8_t *model, size_t len, char *def)
1369 if (memcmp(model, BINZERO, len) != 0) {
1370 strncpy(ha->model_number, model, len);
1371 st = en = ha->model_number;
1374 if (*en != 0x20 && *en != 0x00)
1379 index = (ha->pdev->subsystem_device & 0xff);
1380 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1381 index < QLA_MODEL_NAMES)
1382 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1384 index = (ha->pdev->subsystem_device & 0xff);
1385 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1386 index < QLA_MODEL_NAMES) {
1387 strcpy(ha->model_number,
1388 qla2x00_model_name[index * 2]);
1389 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1391 strcpy(ha->model_number, def);
1397 * NVRAM configuration for ISP 2xxx
1400 * ha = adapter block pointer.
1403 * initialization control block in response_ring
1404 * host adapters parameters in host adapter block
1410 qla2x00_nvram_config(scsi_qla_host_t *ha)
1414 uint8_t *dptr1, *dptr2;
1415 init_cb_t *icb = ha->init_cb;
1416 nvram_t *nv = (nvram_t *)ha->request_ring;
1417 uint8_t *ptr = (uint8_t *)ha->request_ring;
1418 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1420 /* Determine NVRAM starting address. */
1421 ha->nvram_size = sizeof(nvram_t);
1423 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1424 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1425 ha->nvram_base = 0x80;
1427 /* Get NVRAM data and calculate checksum. */
1428 ha->isp_ops.read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1429 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1432 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1433 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1436 /* Bad NVRAM data, set defaults parameters. */
1437 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1438 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1439 /* Reset NVRAM data. */
1440 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1441 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1443 return QLA_FUNCTION_FAILED;
1446 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1448 * The SN2 does not provide BIOS emulation which means you can't change
1449 * potentially bogus BIOS settings. Force the use of default settings
1450 * for link rate and frame size. Hope that the rest of the settings
1453 if (ia64_platform_is("sn2")) {
1454 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1456 nv->special_options[1] = BIT_7;
1460 /* Reset Initialization control block */
1461 memset(icb, 0, ha->init_cb_size);
1464 * Setup driver NVRAM options.
1466 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1467 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1468 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1469 nv->firmware_options[1] &= ~BIT_4;
1471 if (IS_QLA23XX(ha)) {
1472 nv->firmware_options[0] |= BIT_2;
1473 nv->firmware_options[0] &= ~BIT_3;
1474 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1476 if (IS_QLA2300(ha)) {
1477 if (ha->fb_rev == FPM_2310) {
1478 strcpy(ha->model_number, "QLA2310");
1480 strcpy(ha->model_number, "QLA2300");
1483 qla2x00_set_model_info(ha, nv->model_number,
1484 sizeof(nv->model_number), "QLA23xx");
1486 } else if (IS_QLA2200(ha)) {
1487 nv->firmware_options[0] |= BIT_2;
1489 * 'Point-to-point preferred, else loop' is not a safe
1490 * connection mode setting.
1492 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1494 /* Force 'loop preferred, else point-to-point'. */
1495 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1496 nv->add_firmware_options[0] |= BIT_5;
1498 strcpy(ha->model_number, "QLA22xx");
1499 } else /*if (IS_QLA2100(ha))*/ {
1500 strcpy(ha->model_number, "QLA2100");
1504 * Copy over NVRAM RISC parameter block to initialization control block.
1506 dptr1 = (uint8_t *)icb;
1507 dptr2 = (uint8_t *)&nv->parameter_block_version;
1508 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1510 *dptr1++ = *dptr2++;
1512 /* Copy 2nd half. */
1513 dptr1 = (uint8_t *)icb->add_firmware_options;
1514 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1516 *dptr1++ = *dptr2++;
1518 /* Use alternate WWN? */
1519 if (nv->host_p[1] & BIT_7) {
1520 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1521 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1524 /* Prepare nodename */
1525 if ((icb->firmware_options[1] & BIT_6) == 0) {
1527 * Firmware will apply the following mask if the nodename was
1530 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1531 icb->node_name[0] &= 0xF0;
1535 * Set host adapter parameters.
1537 if (nv->host_p[0] & BIT_7)
1538 ql2xextended_error_logging = 1;
1539 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1540 /* Always load RISC code on non ISP2[12]00 chips. */
1541 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1542 ha->flags.disable_risc_code_load = 0;
1543 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1544 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1545 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1546 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1547 ha->flags.disable_serdes = 0;
1549 ha->operating_mode =
1550 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1552 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1553 sizeof(ha->fw_seriallink_options));
1555 /* save HBA serial number */
1556 ha->serial0 = icb->port_name[5];
1557 ha->serial1 = icb->port_name[6];
1558 ha->serial2 = icb->port_name[7];
1559 ha->node_name = icb->node_name;
1560 ha->port_name = icb->port_name;
1562 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1564 ha->retry_count = nv->retry_count;
1566 /* Set minimum login_timeout to 4 seconds. */
1567 if (nv->login_timeout < ql2xlogintimeout)
1568 nv->login_timeout = ql2xlogintimeout;
1569 if (nv->login_timeout < 4)
1570 nv->login_timeout = 4;
1571 ha->login_timeout = nv->login_timeout;
1572 icb->login_timeout = nv->login_timeout;
1574 /* Set minimum RATOV to 200 tenths of a second. */
1577 ha->loop_reset_delay = nv->reset_delay;
1579 /* Link Down Timeout = 0:
1581 * When Port Down timer expires we will start returning
1582 * I/O's to OS with "DID_NO_CONNECT".
1584 * Link Down Timeout != 0:
1586 * The driver waits for the link to come up after link down
1587 * before returning I/Os to OS with "DID_NO_CONNECT".
1589 if (nv->link_down_timeout == 0) {
1590 ha->loop_down_abort_time =
1591 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1593 ha->link_down_timeout = nv->link_down_timeout;
1594 ha->loop_down_abort_time =
1595 (LOOP_DOWN_TIME - ha->link_down_timeout);
1599 * Need enough time to try and get the port back.
1601 ha->port_down_retry_count = nv->port_down_retry_count;
1602 if (qlport_down_retry)
1603 ha->port_down_retry_count = qlport_down_retry;
1604 /* Set login_retry_count */
1605 ha->login_retry_count = nv->retry_count;
1606 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1607 ha->port_down_retry_count > 3)
1608 ha->login_retry_count = ha->port_down_retry_count;
1609 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1610 ha->login_retry_count = ha->port_down_retry_count;
1611 if (ql2xloginretrycount)
1612 ha->login_retry_count = ql2xloginretrycount;
1614 icb->lun_enables = __constant_cpu_to_le16(0);
1615 icb->command_resource_count = 0;
1616 icb->immediate_notify_resource_count = 0;
1617 icb->timeout = __constant_cpu_to_le16(0);
1619 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1621 icb->firmware_options[0] &= ~BIT_3;
1622 icb->add_firmware_options[0] &=
1623 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1624 icb->add_firmware_options[0] |= BIT_2;
1625 icb->response_accumulation_timer = 3;
1626 icb->interrupt_delay_timer = 5;
1628 ha->flags.process_response_queue = 1;
1631 if (!ha->flags.init_done) {
1632 ha->zio_mode = icb->add_firmware_options[0] &
1633 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1634 ha->zio_timer = icb->interrupt_delay_timer ?
1635 icb->interrupt_delay_timer: 2;
1637 icb->add_firmware_options[0] &=
1638 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1639 ha->flags.process_response_queue = 0;
1640 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1641 ha->zio_mode = QLA_ZIO_MODE_6;
1643 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1644 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1645 ha->zio_timer * 100));
1646 qla_printk(KERN_INFO, ha,
1647 "ZIO mode %d enabled; timer delay (%d us).\n",
1648 ha->zio_mode, ha->zio_timer * 100);
1650 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1651 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1652 ha->flags.process_response_queue = 1;
1660 qla2x00_rport_del(void *data)
1662 fc_port_t *fcport = data;
1663 struct fc_rport *rport;
1664 unsigned long flags;
1666 spin_lock_irqsave(&fcport->rport_lock, flags);
1667 rport = fcport->drport;
1668 fcport->drport = NULL;
1669 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1671 fc_remote_port_delete(rport);
1676 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1678 * @flags: allocation flags
1680 * Returns a pointer to the allocated fcport, or NULL, if none available.
1683 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1687 fcport = kmalloc(sizeof(fc_port_t), flags);
1691 /* Setup fcport template structure. */
1692 memset(fcport, 0, sizeof (fc_port_t));
1694 fcport->port_type = FCT_UNKNOWN;
1695 fcport->loop_id = FC_NO_LOOP_ID;
1696 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1697 fcport->flags = FCF_RLC_SUPPORT;
1698 fcport->supported_classes = FC_COS_UNSPECIFIED;
1699 spin_lock_init(&fcport->rport_lock);
1705 * qla2x00_configure_loop
1706 * Updates Fibre Channel Device Database with what is actually on loop.
1709 * ha = adapter block pointer.
1714 * 2 = database was full and device was not configured.
1717 qla2x00_configure_loop(scsi_qla_host_t *ha)
1720 unsigned long flags, save_flags;
1724 /* Get Initiator ID */
1725 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1726 rval = qla2x00_configure_hba(ha);
1727 if (rval != QLA_SUCCESS) {
1728 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1734 save_flags = flags = ha->dpc_flags;
1735 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1736 ha->host_no, flags));
1739 * If we have both an RSCN and PORT UPDATE pending then handle them
1740 * both at the same time.
1742 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1743 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1745 /* Determine what we need to do */
1746 if (ha->current_topology == ISP_CFG_FL &&
1747 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1749 ha->flags.rscn_queue_overflow = 1;
1750 set_bit(RSCN_UPDATE, &flags);
1752 } else if (ha->current_topology == ISP_CFG_F &&
1753 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1755 ha->flags.rscn_queue_overflow = 1;
1756 set_bit(RSCN_UPDATE, &flags);
1757 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1759 } else if (ha->current_topology == ISP_CFG_N) {
1760 clear_bit(RSCN_UPDATE, &flags);
1762 } else if (!ha->flags.online ||
1763 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1765 ha->flags.rscn_queue_overflow = 1;
1766 set_bit(RSCN_UPDATE, &flags);
1767 set_bit(LOCAL_LOOP_UPDATE, &flags);
1770 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1771 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1772 rval = QLA_FUNCTION_FAILED;
1774 rval = qla2x00_configure_local_loop(ha);
1778 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1779 if (LOOP_TRANSITION(ha)) {
1780 rval = QLA_FUNCTION_FAILED;
1782 rval = qla2x00_configure_fabric(ha);
1786 if (rval == QLA_SUCCESS) {
1787 if (atomic_read(&ha->loop_down_timer) ||
1788 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1789 rval = QLA_FUNCTION_FAILED;
1791 atomic_set(&ha->loop_state, LOOP_READY);
1793 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1798 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1799 __func__, ha->host_no));
1801 DEBUG3(printk("%s: exiting normally\n", __func__));
1804 /* Restore state if a resync event occured during processing */
1805 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1806 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1807 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1808 if (test_bit(RSCN_UPDATE, &save_flags))
1809 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1818 * qla2x00_configure_local_loop
1819 * Updates Fibre Channel Device Database with local loop devices.
1822 * ha = adapter block pointer.
1828 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1833 fc_port_t *fcport, *new_fcport;
1839 uint8_t domain, area, al_pa;
1843 entries = MAX_FIBRE_DEVICES;
1845 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1846 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1848 /* Get list of logged in devices. */
1849 memset(ha->gid_list, 0, GID_LIST_SIZE);
1850 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1852 if (rval != QLA_SUCCESS)
1853 goto cleanup_allocation;
1855 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1856 ha->host_no, entries));
1857 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1858 entries * sizeof(struct gid_list_info)));
1860 /* Allocate temporary fcport for any new fcports discovered. */
1861 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1862 if (new_fcport == NULL) {
1863 rval = QLA_MEMORY_ALLOC_FAILED;
1864 goto cleanup_allocation;
1866 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1869 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1871 list_for_each_entry(fcport, &ha->fcports, list) {
1872 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1873 fcport->port_type != FCT_BROADCAST &&
1874 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1876 DEBUG(printk("scsi(%ld): Marking port lost, "
1878 ha->host_no, fcport->loop_id));
1880 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1881 fcport->flags &= ~FCF_FARP_DONE;
1885 /* Add devices to port list. */
1886 id_iter = (char *)ha->gid_list;
1887 for (index = 0; index < entries; index++) {
1888 domain = ((struct gid_list_info *)id_iter)->domain;
1889 area = ((struct gid_list_info *)id_iter)->area;
1890 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1891 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1892 loop_id = (uint16_t)
1893 ((struct gid_list_info *)id_iter)->loop_id_2100;
1895 loop_id = le16_to_cpu(
1896 ((struct gid_list_info *)id_iter)->loop_id);
1897 id_iter += ha->gid_list_info_size;
1899 /* Bypass reserved domain fields. */
1900 if ((domain & 0xf0) == 0xf0)
1903 /* Bypass if not same domain and area of adapter. */
1904 if (area && domain &&
1905 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
1908 /* Bypass invalid local loop ID. */
1909 if (loop_id > LAST_LOCAL_LOOP_ID)
1912 /* Fill in member data. */
1913 new_fcport->d_id.b.domain = domain;
1914 new_fcport->d_id.b.area = area;
1915 new_fcport->d_id.b.al_pa = al_pa;
1916 new_fcport->loop_id = loop_id;
1917 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1918 if (rval2 != QLA_SUCCESS) {
1919 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1920 "information -- get_port_database=%x, "
1922 ha->host_no, rval2, new_fcport->loop_id));
1923 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
1925 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
1929 /* Check for matching device in port list. */
1932 list_for_each_entry(fcport, &ha->fcports, list) {
1933 if (memcmp(new_fcport->port_name, fcport->port_name,
1937 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1938 FCF_PERSISTENT_BOUND);
1939 fcport->loop_id = new_fcport->loop_id;
1940 fcport->port_type = new_fcport->port_type;
1941 fcport->d_id.b24 = new_fcport->d_id.b24;
1942 memcpy(fcport->node_name, new_fcport->node_name,
1950 /* New device, add to fcports list. */
1951 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1952 list_add_tail(&new_fcport->list, &ha->fcports);
1954 /* Allocate a new replacement fcport. */
1955 fcport = new_fcport;
1956 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1957 if (new_fcport == NULL) {
1958 rval = QLA_MEMORY_ALLOC_FAILED;
1959 goto cleanup_allocation;
1961 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1964 /* Base iIDMA settings on HBA port speed. */
1965 switch (ha->link_data_rate) {
1966 case PORT_SPEED_1GB:
1967 fcport->fp_speed = cpu_to_be16(BIT_15);
1969 case PORT_SPEED_2GB:
1970 fcport->fp_speed = cpu_to_be16(BIT_14);
1972 case PORT_SPEED_4GB:
1973 fcport->fp_speed = cpu_to_be16(BIT_13);
1977 qla2x00_update_fcport(ha, fcport);
1985 if (rval != QLA_SUCCESS) {
1986 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1987 "rval=%x\n", ha->host_no, rval));
1991 ha->device_flags |= DFLG_LOCAL_DEVICES;
1992 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
1999 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
2003 qla2x00_mark_all_devices_lost(ha, 0);
2004 list_for_each_entry(fcport, &ha->fcports, list) {
2005 if (fcport->port_type != FCT_TARGET)
2008 qla2x00_update_fcport(ha, fcport);
2013 qla2x00_iidma_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2015 #define LS_UNKNOWN 2
2016 static char *link_speeds[5] = { "1", "2", "?", "4" };
2018 uint16_t port_speed, mb[6];
2020 if (!IS_QLA24XX(ha))
2023 switch (be16_to_cpu(fcport->fp_speed)) {
2025 port_speed = PORT_SPEED_1GB;
2028 port_speed = PORT_SPEED_2GB;
2031 port_speed = PORT_SPEED_4GB;
2034 DEBUG2(printk("scsi(%ld): %02x%02x%02x%02x%02x%02x%02x%02x -- "
2035 "unsupported FM port operating speed (%04x).\n",
2036 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2037 fcport->port_name[2], fcport->port_name[3],
2038 fcport->port_name[4], fcport->port_name[5],
2039 fcport->port_name[6], fcport->port_name[7],
2040 be16_to_cpu(fcport->fp_speed)));
2041 port_speed = PORT_SPEED_UNKNOWN;
2044 if (port_speed == PORT_SPEED_UNKNOWN)
2047 rval = qla2x00_set_idma_speed(ha, fcport->loop_id, port_speed, mb);
2048 if (rval != QLA_SUCCESS) {
2049 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2050 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2051 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2052 fcport->port_name[2], fcport->port_name[3],
2053 fcport->port_name[4], fcport->port_name[5],
2054 fcport->port_name[6], fcport->port_name[7], rval,
2055 port_speed, mb[0], mb[1]));
2057 DEBUG2(qla_printk(KERN_INFO, ha,
2058 "iIDMA adjusted to %s GB/s on "
2059 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2060 link_speeds[port_speed], fcport->port_name[0],
2061 fcport->port_name[1], fcport->port_name[2],
2062 fcport->port_name[3], fcport->port_name[4],
2063 fcport->port_name[5], fcport->port_name[6],
2064 fcport->port_name[7]));
2069 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2071 struct fc_rport_identifiers rport_ids;
2072 struct fc_rport *rport;
2073 unsigned long flags;
2076 qla2x00_rport_del(fcport);
2080 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2081 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2082 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2083 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2084 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2085 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2087 qla_printk(KERN_WARNING, ha,
2088 "Unable to allocate fc remote port!\n");
2091 spin_lock_irqsave(&fcport->rport_lock, flags);
2092 fcport->rport = rport;
2093 *((fc_port_t **)rport->dd_data) = fcport;
2094 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2096 rport->supported_classes = fcport->supported_classes;
2098 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2099 if (fcport->port_type == FCT_INITIATOR)
2100 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2101 if (fcport->port_type == FCT_TARGET)
2102 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2103 fc_remote_port_rolechg(rport, rport_ids.roles);
2105 if (rport->scsi_target_id != -1 &&
2106 rport->scsi_target_id < ha->host->max_id)
2107 fcport->os_target_id = rport->scsi_target_id;
2111 * qla2x00_update_fcport
2112 * Updates device on list.
2115 * ha = adapter block pointer.
2116 * fcport = port structure pointer.
2126 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2129 fcport->login_retry = 0;
2130 fcport->port_login_retry_count = ha->port_down_retry_count *
2132 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2134 fcport->flags &= ~FCF_LOGIN_NEEDED;
2136 qla2x00_iidma_fcport(ha, fcport);
2138 atomic_set(&fcport->state, FCS_ONLINE);
2140 qla2x00_reg_remote_port(ha, fcport);
2144 * qla2x00_configure_fabric
2145 * Setup SNS devices with loop ID's.
2148 * ha = adapter block pointer.
2155 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2158 fc_port_t *fcport, *fcptemp;
2159 uint16_t next_loopid;
2160 uint16_t mb[MAILBOX_REGISTER_COUNT];
2162 LIST_HEAD(new_fcports);
2164 /* If FL port exists, then SNS is present */
2165 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2166 loop_id = NPH_F_PORT;
2168 loop_id = SNS_FL_PORT;
2169 rval = qla2x00_get_port_name(ha, loop_id, ha->fabric_node_name, 1);
2170 if (rval != QLA_SUCCESS) {
2171 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2172 "Port\n", ha->host_no));
2174 ha->device_flags &= ~SWITCH_FOUND;
2175 return (QLA_SUCCESS);
2177 ha->device_flags |= SWITCH_FOUND;
2179 /* Mark devices that need re-synchronization. */
2180 rval2 = qla2x00_device_resync(ha);
2181 if (rval2 == QLA_RSCNS_HANDLED) {
2182 /* No point doing the scan, just continue. */
2183 return (QLA_SUCCESS);
2187 if (ql2xfdmienable &&
2188 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2189 qla2x00_fdmi_register(ha);
2191 /* Ensure we are logged into the SNS. */
2192 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2195 loop_id = SIMPLE_NAME_SERVER;
2196 ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
2197 0xfc, mb, BIT_1 | BIT_0);
2198 if (mb[0] != MBS_COMMAND_COMPLETE) {
2199 DEBUG2(qla_printk(KERN_INFO, ha,
2200 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2201 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2202 mb[0], mb[1], mb[2], mb[6], mb[7]));
2203 return (QLA_SUCCESS);
2206 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2207 if (qla2x00_rft_id(ha)) {
2209 DEBUG2(printk("scsi(%ld): Register FC-4 "
2210 "TYPE failed.\n", ha->host_no));
2212 if (qla2x00_rff_id(ha)) {
2214 DEBUG2(printk("scsi(%ld): Register FC-4 "
2215 "Features failed.\n", ha->host_no));
2217 if (qla2x00_rnn_id(ha)) {
2219 DEBUG2(printk("scsi(%ld): Register Node Name "
2220 "failed.\n", ha->host_no));
2221 } else if (qla2x00_rsnn_nn(ha)) {
2223 DEBUG2(printk("scsi(%ld): Register Symbolic "
2224 "Node Name failed.\n", ha->host_no));
2228 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2229 if (rval != QLA_SUCCESS)
2233 * Logout all previous fabric devices marked lost, except
2236 list_for_each_entry(fcport, &ha->fcports, list) {
2237 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2240 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2243 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2244 qla2x00_mark_device_lost(ha, fcport,
2245 ql2xplogiabsentdevice, 0);
2246 if (fcport->loop_id != FC_NO_LOOP_ID &&
2247 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2248 fcport->port_type != FCT_INITIATOR &&
2249 fcport->port_type != FCT_BROADCAST) {
2250 ha->isp_ops.fabric_logout(ha,
2252 fcport->d_id.b.domain,
2253 fcport->d_id.b.area,
2254 fcport->d_id.b.al_pa);
2255 fcport->loop_id = FC_NO_LOOP_ID;
2260 /* Starting free loop ID. */
2261 next_loopid = ha->min_external_loopid;
2264 * Scan through our port list and login entries that need to be
2267 list_for_each_entry(fcport, &ha->fcports, list) {
2268 if (atomic_read(&ha->loop_down_timer) ||
2269 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2272 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2273 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2276 if (fcport->loop_id == FC_NO_LOOP_ID) {
2277 fcport->loop_id = next_loopid;
2278 rval = qla2x00_find_new_loop_id(ha, fcport);
2279 if (rval != QLA_SUCCESS) {
2280 /* Ran out of IDs to use */
2284 /* Login and update database */
2285 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2288 /* Exit if out of loop IDs. */
2289 if (rval != QLA_SUCCESS) {
2294 * Login and add the new devices to our port list.
2296 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2297 if (atomic_read(&ha->loop_down_timer) ||
2298 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2301 /* Find a new loop ID to use. */
2302 fcport->loop_id = next_loopid;
2303 rval = qla2x00_find_new_loop_id(ha, fcport);
2304 if (rval != QLA_SUCCESS) {
2305 /* Ran out of IDs to use */
2309 /* Remove device from the new list and add it to DB */
2310 list_move_tail(&fcport->list, &ha->fcports);
2312 /* Login and update database */
2313 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2317 /* Free all new device structures not processed. */
2318 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2319 list_del(&fcport->list);
2324 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2325 "rval=%d\n", ha->host_no, rval));
2333 * qla2x00_find_all_fabric_devs
2336 * ha = adapter block pointer.
2337 * dev = database device entry pointer.
2346 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2350 fc_port_t *fcport, *new_fcport, *fcptemp;
2355 int first_dev, last_dev;
2356 port_id_t wrap, nxt_d_id;
2360 /* Try GID_PT to get device list, else GAN. */
2361 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2364 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2365 "on GA_NXT\n", ha->host_no));
2367 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2368 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2371 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2374 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2377 } else if (qla2x00_gfpn_id(ha, swl) == QLA_SUCCESS) {
2378 qla2x00_gpsc(ha, swl);
2383 /* Allocate temporary fcport for any new fcports discovered. */
2384 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2385 if (new_fcport == NULL) {
2387 return (QLA_MEMORY_ALLOC_FAILED);
2389 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2391 /* Set start port ID scan at adapter ID. */
2395 /* Starting free loop ID. */
2396 loop_id = ha->min_external_loopid;
2397 for (; loop_id <= ha->last_loop_id; loop_id++) {
2398 if (qla2x00_is_reserved_id(ha, loop_id))
2401 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2406 wrap.b24 = new_fcport->d_id.b24;
2408 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2409 memcpy(new_fcport->node_name,
2410 swl[swl_idx].node_name, WWN_SIZE);
2411 memcpy(new_fcport->port_name,
2412 swl[swl_idx].port_name, WWN_SIZE);
2413 memcpy(new_fcport->fabric_port_name,
2414 swl[swl_idx].fabric_port_name, WWN_SIZE);
2415 new_fcport->fp_speed = swl[swl_idx].fp_speed;
2417 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2423 /* Send GA_NXT to the switch */
2424 rval = qla2x00_ga_nxt(ha, new_fcport);
2425 if (rval != QLA_SUCCESS) {
2426 qla_printk(KERN_WARNING, ha,
2427 "SNS scan failed -- assuming zero-entry "
2429 list_for_each_entry_safe(fcport, fcptemp,
2430 new_fcports, list) {
2431 list_del(&fcport->list);
2439 /* If wrap on switch device list, exit. */
2441 wrap.b24 = new_fcport->d_id.b24;
2443 } else if (new_fcport->d_id.b24 == wrap.b24) {
2444 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2445 ha->host_no, new_fcport->d_id.b.domain,
2446 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2450 /* Bypass if host adapter. */
2451 if (new_fcport->d_id.b24 == ha->d_id.b24)
2454 /* Bypass if same domain and area of adapter. */
2455 if (((new_fcport->d_id.b24 & 0xffff00) ==
2456 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2460 /* Bypass reserved domain fields. */
2461 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2464 /* Locate matching device in database. */
2466 list_for_each_entry(fcport, &ha->fcports, list) {
2467 if (memcmp(new_fcport->port_name, fcport->port_name,
2473 /* Update port state. */
2474 memcpy(fcport->fabric_port_name,
2475 new_fcport->fabric_port_name, WWN_SIZE);
2476 fcport->fp_speed = new_fcport->fp_speed;
2479 * If address the same and state FCS_ONLINE, nothing
2482 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2483 atomic_read(&fcport->state) == FCS_ONLINE) {
2488 * If device was not a fabric device before.
2490 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2491 fcport->d_id.b24 = new_fcport->d_id.b24;
2492 fcport->loop_id = FC_NO_LOOP_ID;
2493 fcport->flags |= (FCF_FABRIC_DEVICE |
2495 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2500 * Port ID changed or device was marked to be updated;
2501 * Log it out if still logged in and mark it for
2504 fcport->d_id.b24 = new_fcport->d_id.b24;
2505 fcport->flags |= FCF_LOGIN_NEEDED;
2506 if (fcport->loop_id != FC_NO_LOOP_ID &&
2507 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2508 fcport->port_type != FCT_INITIATOR &&
2509 fcport->port_type != FCT_BROADCAST) {
2510 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2511 fcport->d_id.b.domain, fcport->d_id.b.area,
2512 fcport->d_id.b.al_pa);
2513 fcport->loop_id = FC_NO_LOOP_ID;
2522 /* If device was not in our fcports list, then add it. */
2523 list_add_tail(&new_fcport->list, new_fcports);
2525 /* Allocate a new replacement fcport. */
2526 nxt_d_id.b24 = new_fcport->d_id.b24;
2527 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2528 if (new_fcport == NULL) {
2530 return (QLA_MEMORY_ALLOC_FAILED);
2532 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2533 new_fcport->d_id.b24 = nxt_d_id.b24;
2539 if (!list_empty(new_fcports))
2540 ha->device_flags |= DFLG_FABRIC_DEVICES;
2546 * qla2x00_find_new_loop_id
2547 * Scan through our port list and find a new usable loop ID.
2550 * ha: adapter state pointer.
2551 * dev: port structure pointer.
2554 * qla2x00 local function return status code.
2560 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2565 uint16_t first_loop_id;
2569 /* Save starting loop ID. */
2570 first_loop_id = dev->loop_id;
2573 /* Skip loop ID if already used by adapter. */
2574 if (dev->loop_id == ha->loop_id) {
2578 /* Skip reserved loop IDs. */
2579 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2583 /* Reset loop ID if passed the end. */
2584 if (dev->loop_id > ha->last_loop_id) {
2585 /* first loop ID. */
2586 dev->loop_id = ha->min_external_loopid;
2589 /* Check for loop ID being already in use. */
2592 list_for_each_entry(fcport, &ha->fcports, list) {
2593 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2594 /* ID possibly in use */
2600 /* If not in use then it is free to use. */
2605 /* ID in use. Try next value. */
2608 /* If wrap around. No free ID to use. */
2609 if (dev->loop_id == first_loop_id) {
2610 dev->loop_id = FC_NO_LOOP_ID;
2611 rval = QLA_FUNCTION_FAILED;
2620 * qla2x00_device_resync
2621 * Marks devices in the database that needs resynchronization.
2624 * ha = adapter block pointer.
2630 qla2x00_device_resync(scsi_qla_host_t *ha)
2635 uint32_t rscn_entry;
2636 uint8_t rscn_out_iter;
2640 rval = QLA_RSCNS_HANDLED;
2642 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2643 ha->flags.rscn_queue_overflow) {
2645 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2646 format = MSB(MSW(rscn_entry));
2647 d_id.b.domain = LSB(MSW(rscn_entry));
2648 d_id.b.area = MSB(LSW(rscn_entry));
2649 d_id.b.al_pa = LSB(LSW(rscn_entry));
2651 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2652 "[%02x/%02x%02x%02x].\n",
2653 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2654 d_id.b.area, d_id.b.al_pa));
2657 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2658 ha->rscn_out_ptr = 0;
2660 /* Skip duplicate entries. */
2661 for (rscn_out_iter = ha->rscn_out_ptr;
2662 !ha->flags.rscn_queue_overflow &&
2663 rscn_out_iter != ha->rscn_in_ptr;
2664 rscn_out_iter = (rscn_out_iter ==
2665 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2667 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2670 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2671 "entry found at [%d].\n", ha->host_no,
2674 ha->rscn_out_ptr = rscn_out_iter;
2677 /* Queue overflow, set switch default case. */
2678 if (ha->flags.rscn_queue_overflow) {
2679 DEBUG(printk("scsi(%ld): device_resync: rscn "
2680 "overflow.\n", ha->host_no));
2683 ha->flags.rscn_queue_overflow = 0;
2699 ha->rscn_out_ptr = ha->rscn_in_ptr;
2705 list_for_each_entry(fcport, &ha->fcports, list) {
2706 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2707 (fcport->d_id.b24 & mask) != d_id.b24 ||
2708 fcport->port_type == FCT_BROADCAST)
2711 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2713 fcport->port_type != FCT_INITIATOR) {
2714 qla2x00_mark_device_lost(ha, fcport,
2718 fcport->flags &= ~FCF_FARP_DONE;
2725 * qla2x00_fabric_dev_login
2726 * Login fabric target device and update FC port database.
2729 * ha: adapter state pointer.
2730 * fcport: port structure list pointer.
2731 * next_loopid: contains value of a new loop ID that can be used
2732 * by the next login attempt.
2735 * qla2x00 local function return status code.
2741 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2742 uint16_t *next_loopid)
2751 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2752 if (rval == QLA_SUCCESS) {
2753 /* Send an ADISC to tape devices.*/
2755 if (fcport->flags & FCF_TAPE_PRESENT)
2757 rval = qla2x00_get_port_database(ha, fcport, opts);
2758 if (rval != QLA_SUCCESS) {
2759 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2760 fcport->d_id.b.domain, fcport->d_id.b.area,
2761 fcport->d_id.b.al_pa);
2762 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2764 qla2x00_update_fcport(ha, fcport);
2772 * qla2x00_fabric_login
2773 * Issue fabric login command.
2776 * ha = adapter block pointer.
2777 * device = pointer to FC device type structure.
2780 * 0 - Login successfully
2782 * 2 - Initiator device
2786 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2787 uint16_t *next_loopid)
2791 uint16_t tmp_loopid;
2792 uint16_t mb[MAILBOX_REGISTER_COUNT];
2798 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2799 "for port %02x%02x%02x.\n",
2800 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2801 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2803 /* Login fcport on switch. */
2804 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2805 fcport->d_id.b.domain, fcport->d_id.b.area,
2806 fcport->d_id.b.al_pa, mb, BIT_0);
2807 if (mb[0] == MBS_PORT_ID_USED) {
2809 * Device has another loop ID. The firmware team
2810 * recommends the driver perform an implicit login with
2811 * the specified ID again. The ID we just used is save
2812 * here so we return with an ID that can be tried by
2816 tmp_loopid = fcport->loop_id;
2817 fcport->loop_id = mb[1];
2819 DEBUG(printk("Fabric Login: port in use - next "
2820 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2821 fcport->loop_id, fcport->d_id.b.domain,
2822 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2824 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2829 /* A retry occurred before. */
2830 *next_loopid = tmp_loopid;
2833 * No retry occurred before. Just increment the
2834 * ID value for next login.
2836 *next_loopid = (fcport->loop_id + 1);
2839 if (mb[1] & BIT_0) {
2840 fcport->port_type = FCT_INITIATOR;
2842 fcport->port_type = FCT_TARGET;
2843 if (mb[1] & BIT_1) {
2844 fcport->flags |= FCF_TAPE_PRESENT;
2849 fcport->supported_classes |= FC_COS_CLASS2;
2851 fcport->supported_classes |= FC_COS_CLASS3;
2855 } else if (mb[0] == MBS_LOOP_ID_USED) {
2857 * Loop ID already used, try next loop ID.
2860 rval = qla2x00_find_new_loop_id(ha, fcport);
2861 if (rval != QLA_SUCCESS) {
2862 /* Ran out of loop IDs to use */
2865 } else if (mb[0] == MBS_COMMAND_ERROR) {
2867 * Firmware possibly timed out during login. If NO
2868 * retries are left to do then the device is declared
2871 *next_loopid = fcport->loop_id;
2872 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2873 fcport->d_id.b.domain, fcport->d_id.b.area,
2874 fcport->d_id.b.al_pa);
2875 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2881 * unrecoverable / not handled error
2883 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2884 "loop_id=%x jiffies=%lx.\n",
2885 __func__, ha->host_no, mb[0],
2886 fcport->d_id.b.domain, fcport->d_id.b.area,
2887 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2889 *next_loopid = fcport->loop_id;
2890 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2891 fcport->d_id.b.domain, fcport->d_id.b.area,
2892 fcport->d_id.b.al_pa);
2893 fcport->loop_id = FC_NO_LOOP_ID;
2894 fcport->login_retry = 0;
2905 * qla2x00_local_device_login
2906 * Issue local device login command.
2909 * ha = adapter block pointer.
2910 * loop_id = loop id of device to login to.
2912 * Returns (Where's the #define!!!!):
2913 * 0 - Login successfully
2918 qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
2921 uint16_t mb[MAILBOX_REGISTER_COUNT];
2923 memset(mb, 0, sizeof(mb));
2924 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
2925 if (rval == QLA_SUCCESS) {
2926 /* Interrogate mailbox registers for any errors */
2927 if (mb[0] == MBS_COMMAND_ERROR)
2929 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
2930 /* device not in PCB table */
2938 * qla2x00_loop_resync
2939 * Resync with fibre channel devices.
2942 * ha = adapter block pointer.
2948 qla2x00_loop_resync(scsi_qla_host_t *ha)
2955 atomic_set(&ha->loop_state, LOOP_UPDATE);
2956 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2957 if (ha->flags.online) {
2958 if (!(rval = qla2x00_fw_ready(ha))) {
2959 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2962 atomic_set(&ha->loop_state, LOOP_UPDATE);
2964 /* Issue a marker after FW becomes ready. */
2965 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
2966 ha->marker_needed = 0;
2968 /* Remap devices on Loop. */
2969 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2971 qla2x00_configure_loop(ha);
2973 } while (!atomic_read(&ha->loop_down_timer) &&
2974 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
2976 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
2980 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2981 return (QLA_FUNCTION_FAILED);
2985 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
2992 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
2998 list_for_each_entry(fcport, &ha->fcports, list) {
2999 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
3002 qla2x00_update_fcport(ha, fcport);
3003 fcport->flags &= ~FCF_RESCAN_NEEDED;
3007 qla2x00_probe_for_all_luns(ha);
3011 qla2x00_update_fcports(scsi_qla_host_t *ha)
3015 /* Go with deferred removal of rport references. */
3016 list_for_each_entry(fcport, &ha->fcports, list)
3018 qla2x00_rport_del(fcport);
3023 * Resets ISP and aborts all outstanding commands.
3026 * ha = adapter block pointer.
3032 qla2x00_abort_isp(scsi_qla_host_t *ha)
3035 unsigned long flags = 0;
3040 if (ha->flags.online) {
3041 ha->flags.online = 0;
3042 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3044 qla_printk(KERN_INFO, ha,
3045 "Performing ISP error recovery - ha= %p.\n", ha);
3046 ha->isp_ops.reset_chip(ha);
3048 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3049 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3050 atomic_set(&ha->loop_state, LOOP_DOWN);
3051 qla2x00_mark_all_devices_lost(ha, 0);
3053 if (!atomic_read(&ha->loop_down_timer))
3054 atomic_set(&ha->loop_down_timer,
3058 spin_lock_irqsave(&ha->hardware_lock, flags);
3059 /* Requeue all commands in outstanding command list. */
3060 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3061 sp = ha->outstanding_cmds[cnt];
3063 ha->outstanding_cmds[cnt] = NULL;
3065 sp->cmd->result = DID_RESET << 16;
3066 sp->cmd->host_scribble = (unsigned char *)NULL;
3067 qla2x00_sp_compl(ha, sp);
3070 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3072 ha->isp_ops.get_flash_version(ha, ha->request_ring);
3074 rval = ha->isp_ops.nvram_config(ha);
3076 goto isp_abort_retry;
3078 if (!qla2x00_restart_isp(ha)) {
3079 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3081 if (!atomic_read(&ha->loop_down_timer)) {
3083 * Issue marker command only when we are going
3084 * to start the I/O .
3086 ha->marker_needed = 1;
3089 ha->flags.online = 1;
3091 ha->isp_ops.enable_intrs(ha);
3093 ha->isp_abort_cnt = 0;
3094 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3097 rval = qla2x00_trace_control(ha, TC_ENABLE,
3098 ha->eft_dma, EFT_NUM_BUFFERS);
3100 qla_printk(KERN_WARNING, ha,
3101 "Unable to reinitialize EFT "
3105 } else { /* failed the ISP abort */
3107 ha->flags.online = 1;
3108 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3109 if (ha->isp_abort_cnt == 0) {
3110 qla_printk(KERN_WARNING, ha,
3111 "ISP error recovery failed - "
3112 "board disabled\n");
3114 * The next call disables the board
3117 ha->isp_ops.reset_adapter(ha);
3118 ha->flags.online = 0;
3119 clear_bit(ISP_ABORT_RETRY,
3122 } else { /* schedule another ISP abort */
3123 ha->isp_abort_cnt--;
3124 DEBUG(printk("qla%ld: ISP abort - "
3125 "retry remaining %d\n",
3126 ha->host_no, ha->isp_abort_cnt));
3130 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3131 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3132 "- retrying (%d) more times\n",
3133 ha->host_no, ha->isp_abort_cnt));
3134 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3142 qla_printk(KERN_INFO, ha,
3143 "qla2x00_abort_isp: **** FAILED ****\n");
3145 DEBUG(printk(KERN_INFO
3146 "qla2x00_abort_isp(%ld): exiting.\n",
3154 * qla2x00_restart_isp
3155 * restarts the ISP after a reset
3158 * ha = adapter block pointer.
3164 qla2x00_restart_isp(scsi_qla_host_t *ha)
3167 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3168 unsigned long flags = 0;
3171 /* If firmware needs to be loaded */
3172 if (qla2x00_isp_firmware(ha)) {
3173 ha->flags.online = 0;
3174 if (!(status = ha->isp_ops.chip_diag(ha))) {
3175 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3176 status = qla2x00_setup_chip(ha);
3180 spin_lock_irqsave(&ha->hardware_lock, flags);
3182 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3184 * Disable SRAM, Instruction RAM and GP RAM
3187 WRT_REG_WORD(®->hccr,
3188 (HCCR_ENABLE_PARITY + 0x0));
3189 RD_REG_WORD(®->hccr);
3192 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3194 status = qla2x00_setup_chip(ha);
3196 spin_lock_irqsave(&ha->hardware_lock, flags);
3198 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3199 /* Enable proper parity */
3202 WRT_REG_WORD(®->hccr,
3203 (HCCR_ENABLE_PARITY + 0x1));
3206 * SRAM, Instruction RAM and GP RAM
3209 WRT_REG_WORD(®->hccr,
3210 (HCCR_ENABLE_PARITY + 0x7));
3211 RD_REG_WORD(®->hccr);
3214 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3219 if (!status && !(status = qla2x00_init_rings(ha))) {
3220 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3221 if (!(status = qla2x00_fw_ready(ha))) {
3222 DEBUG(printk("%s(): Start configure loop, "
3223 "status = %d\n", __func__, status));
3225 /* Issue a marker after FW becomes ready. */
3226 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3228 ha->flags.online = 1;
3229 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3232 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3233 qla2x00_configure_loop(ha);
3235 } while (!atomic_read(&ha->loop_down_timer) &&
3236 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3238 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3241 /* if no cable then assume it's good */
3242 if ((ha->device_flags & DFLG_NO_CABLE))
3245 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3253 * qla2x00_reset_adapter
3257 * ha = adapter block pointer.
3260 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3262 unsigned long flags = 0;
3263 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3265 ha->flags.online = 0;
3266 ha->isp_ops.disable_intrs(ha);
3268 spin_lock_irqsave(&ha->hardware_lock, flags);
3269 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3270 RD_REG_WORD(®->hccr); /* PCI Posting. */
3271 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3272 RD_REG_WORD(®->hccr); /* PCI Posting. */
3273 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3277 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3279 unsigned long flags = 0;
3280 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3282 ha->flags.online = 0;
3283 ha->isp_ops.disable_intrs(ha);
3285 spin_lock_irqsave(&ha->hardware_lock, flags);
3286 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3287 RD_REG_DWORD(®->hccr);
3288 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3289 RD_REG_DWORD(®->hccr);
3290 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3294 qla24xx_nvram_config(scsi_qla_host_t *ha)
3296 struct init_cb_24xx *icb;
3297 struct nvram_24xx *nv;
3299 uint8_t *dptr1, *dptr2;
3303 icb = (struct init_cb_24xx *)ha->init_cb;
3304 nv = (struct nvram_24xx *)ha->request_ring;
3306 /* Determine NVRAM starting address. */
3307 ha->nvram_size = sizeof(struct nvram_24xx);
3308 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3309 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3310 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3311 if (PCI_FUNC(ha->pdev->devfn)) {
3312 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3313 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3316 /* Get NVRAM data and calculate checksum. */
3317 dptr = (uint32_t *)nv;
3318 ha->isp_ops.read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3320 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3321 chksum += le32_to_cpu(*dptr++);
3323 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3324 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3327 /* Bad NVRAM data, set defaults parameters. */
3328 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3329 || nv->id[3] != ' ' ||
3330 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3331 /* Reset NVRAM data. */
3332 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3333 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3334 le16_to_cpu(nv->nvram_version));
3335 return QLA_FUNCTION_FAILED;
3338 /* Reset Initialization control block */
3339 memset(icb, 0, sizeof(struct init_cb_24xx));
3341 /* Copy 1st segment. */
3342 dptr1 = (uint8_t *)icb;
3343 dptr2 = (uint8_t *)&nv->version;
3344 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3346 *dptr1++ = *dptr2++;
3348 icb->login_retry_count = nv->login_retry_count;
3349 icb->link_down_on_nos = nv->link_down_on_nos;
3351 /* Copy 2nd segment. */
3352 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3353 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3354 cnt = (uint8_t *)&icb->reserved_3 -
3355 (uint8_t *)&icb->interrupt_delay_timer;
3357 *dptr1++ = *dptr2++;
3360 * Setup driver NVRAM options.
3362 qla2x00_set_model_info(ha, nv->model_name, sizeof(nv->model_name),
3365 /* Use alternate WWN? */
3366 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3367 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3368 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3371 /* Prepare nodename */
3372 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3374 * Firmware will apply the following mask if the nodename was
3377 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3378 icb->node_name[0] &= 0xF0;
3381 /* Set host adapter parameters. */
3382 ha->flags.disable_risc_code_load = 0;
3383 ha->flags.enable_lip_reset = 0;
3384 ha->flags.enable_lip_full_login =
3385 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3386 ha->flags.enable_target_reset =
3387 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
3388 ha->flags.enable_led_scheme = 0;
3389 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
3391 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3392 (BIT_6 | BIT_5 | BIT_4)) >> 4;
3394 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3395 sizeof(ha->fw_seriallink_options24));
3397 /* save HBA serial number */
3398 ha->serial0 = icb->port_name[5];
3399 ha->serial1 = icb->port_name[6];
3400 ha->serial2 = icb->port_name[7];
3401 ha->node_name = icb->node_name;
3402 ha->port_name = icb->port_name;
3404 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3406 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3408 /* Set minimum login_timeout to 4 seconds. */
3409 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3410 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3411 if (le16_to_cpu(nv->login_timeout) < 4)
3412 nv->login_timeout = __constant_cpu_to_le16(4);
3413 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3414 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3416 /* Set minimum RATOV to 200 tenths of a second. */
3419 ha->loop_reset_delay = nv->reset_delay;
3421 /* Link Down Timeout = 0:
3423 * When Port Down timer expires we will start returning
3424 * I/O's to OS with "DID_NO_CONNECT".
3426 * Link Down Timeout != 0:
3428 * The driver waits for the link to come up after link down
3429 * before returning I/Os to OS with "DID_NO_CONNECT".
3431 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3432 ha->loop_down_abort_time =
3433 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3435 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3436 ha->loop_down_abort_time =
3437 (LOOP_DOWN_TIME - ha->link_down_timeout);
3440 /* Need enough time to try and get the port back. */
3441 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3442 if (qlport_down_retry)
3443 ha->port_down_retry_count = qlport_down_retry;
3445 /* Set login_retry_count */
3446 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3447 if (ha->port_down_retry_count ==
3448 le16_to_cpu(nv->port_down_retry_count) &&
3449 ha->port_down_retry_count > 3)
3450 ha->login_retry_count = ha->port_down_retry_count;
3451 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3452 ha->login_retry_count = ha->port_down_retry_count;
3453 if (ql2xloginretrycount)
3454 ha->login_retry_count = ql2xloginretrycount;
3457 if (!ha->flags.init_done) {
3458 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3459 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3460 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3461 le16_to_cpu(icb->interrupt_delay_timer): 2;
3463 icb->firmware_options_2 &= __constant_cpu_to_le32(
3464 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3465 ha->flags.process_response_queue = 0;
3466 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3467 ha->zio_mode = QLA_ZIO_MODE_6;
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;
3486 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3489 int segments, fragment;
3491 uint32_t *dcode, dlen;
3498 segments = FA_RISC_CODE_SEGMENTS;
3499 faddr = FA_RISC_CODE_ADDR;
3500 dcode = (uint32_t *)ha->request_ring;
3503 /* Validate firmware image by checking version. */
3504 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3505 for (i = 0; i < 4; i++)
3506 dcode[i] = be32_to_cpu(dcode[i]);
3507 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3508 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3509 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3511 qla_printk(KERN_WARNING, ha,
3512 "Unable to verify integrity of flash firmware image!\n");
3513 qla_printk(KERN_WARNING, ha,
3514 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3515 dcode[1], dcode[2], dcode[3]);
3517 return QLA_FUNCTION_FAILED;
3520 while (segments && rval == QLA_SUCCESS) {
3521 /* Read segment's load information. */
3522 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3524 risc_addr = be32_to_cpu(dcode[2]);
3525 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3526 risc_size = be32_to_cpu(dcode[3]);
3529 while (risc_size > 0 && rval == QLA_SUCCESS) {
3530 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3531 if (dlen > risc_size)
3534 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3535 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3536 ha->host_no, risc_addr, dlen, faddr));
3538 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3539 for (i = 0; i < dlen; i++)
3540 dcode[i] = swab32(dcode[i]);
3542 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3545 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3546 "segment %d of firmware\n", ha->host_no,
3548 qla_printk(KERN_WARNING, ha,
3549 "[ERROR] Failed to load segment %d of "
3550 "firmware\n", fragment);
3567 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3570 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3574 uint16_t *wcode, *fwcode;
3575 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3576 struct fw_blob *blob;
3578 /* Load firmware blob. */
3579 blob = qla2x00_request_firmware(ha);
3581 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3582 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3583 "from: " QLA_FW_URL ".\n");
3584 return QLA_FUNCTION_FAILED;
3589 wcode = (uint16_t *)ha->request_ring;
3591 fwcode = (uint16_t *)blob->fw->data;
3594 /* Validate firmware image by checking version. */
3595 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3596 qla_printk(KERN_WARNING, ha,
3597 "Unable to verify integrity of firmware image (%Zd)!\n",
3599 goto fail_fw_integrity;
3601 for (i = 0; i < 4; i++)
3602 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3603 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3604 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3605 wcode[2] == 0 && wcode[3] == 0)) {
3606 qla_printk(KERN_WARNING, ha,
3607 "Unable to verify integrity of firmware image!\n");
3608 qla_printk(KERN_WARNING, ha,
3609 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3610 wcode[1], wcode[2], wcode[3]);
3611 goto fail_fw_integrity;
3615 while (*seg && rval == QLA_SUCCESS) {
3617 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3618 risc_size = be16_to_cpu(fwcode[3]);
3620 /* Validate firmware image size. */
3621 fwclen += risc_size * sizeof(uint16_t);
3622 if (blob->fw->size < fwclen) {
3623 qla_printk(KERN_WARNING, ha,
3624 "Unable to verify integrity of firmware image "
3625 "(%Zd)!\n", blob->fw->size);
3626 goto fail_fw_integrity;
3630 while (risc_size > 0 && rval == QLA_SUCCESS) {
3631 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3632 if (wlen > risc_size)
3635 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3636 "addr %x, number of words 0x%x.\n", ha->host_no,
3639 for (i = 0; i < wlen; i++)
3640 wcode[i] = swab16(fwcode[i]);
3642 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3645 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3646 "segment %d of firmware\n", ha->host_no,
3648 qla_printk(KERN_WARNING, ha,
3649 "[ERROR] Failed to load segment %d of "
3650 "firmware\n", fragment);
3666 return QLA_FUNCTION_FAILED;
3670 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3673 int segments, fragment;
3674 uint32_t *dcode, dlen;
3678 struct fw_blob *blob;
3679 uint32_t *fwcode, fwclen;
3681 /* Load firmware blob. */
3682 blob = qla2x00_request_firmware(ha);
3684 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3685 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3686 "from: " QLA_FW_URL ".\n");
3688 /* Try to load RISC code from flash. */
3689 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3690 "outdated) firmware from flash.\n");
3691 return qla24xx_load_risc_flash(ha, srisc_addr);
3696 segments = FA_RISC_CODE_SEGMENTS;
3697 dcode = (uint32_t *)ha->request_ring;
3699 fwcode = (uint32_t *)blob->fw->data;
3702 /* Validate firmware image by checking version. */
3703 if (blob->fw->size < 8 * sizeof(uint32_t)) {
3704 qla_printk(KERN_WARNING, ha,
3705 "Unable to verify integrity of firmware image (%Zd)!\n",
3707 goto fail_fw_integrity;
3709 for (i = 0; i < 4; i++)
3710 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3711 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3712 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3713 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3715 qla_printk(KERN_WARNING, ha,
3716 "Unable to verify integrity of firmware image!\n");
3717 qla_printk(KERN_WARNING, ha,
3718 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3719 dcode[1], dcode[2], dcode[3]);
3720 goto fail_fw_integrity;
3723 while (segments && rval == QLA_SUCCESS) {
3724 risc_addr = be32_to_cpu(fwcode[2]);
3725 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3726 risc_size = be32_to_cpu(fwcode[3]);
3728 /* Validate firmware image size. */
3729 fwclen += risc_size * sizeof(uint32_t);
3730 if (blob->fw->size < fwclen) {
3731 qla_printk(KERN_WARNING, ha,
3732 "Unable to verify integrity of firmware image "
3733 "(%Zd)!\n", blob->fw->size);
3735 goto fail_fw_integrity;
3739 while (risc_size > 0 && rval == QLA_SUCCESS) {
3740 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3741 if (dlen > risc_size)
3744 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3745 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3748 for (i = 0; i < dlen; i++)
3749 dcode[i] = swab32(fwcode[i]);
3751 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3754 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3755 "segment %d of firmware\n", ha->host_no,
3757 qla_printk(KERN_WARNING, ha,
3758 "[ERROR] Failed to load segment %d of "
3759 "firmware\n", fragment);
3775 return QLA_FUNCTION_FAILED;
3779 qla2x00_try_to_stop_firmware(scsi_qla_host_t *ha)
3783 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
3786 ret = qla2x00_stop_firmware(ha);
3787 for (retries = 5; ret != QLA_SUCCESS && retries ; retries--) {
3788 qla2x00_reset_chip(ha);
3789 if (qla2x00_chip_diag(ha) != QLA_SUCCESS)
3791 if (qla2x00_setup_chip(ha) != QLA_SUCCESS)
3793 qla_printk(KERN_INFO, ha,
3794 "Attempting retry of stop-firmware command...\n");
3795 ret = qla2x00_stop_firmware(ha);