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);
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 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
89 ha->isp_ops.nvram_config(ha);
91 if (ha->flags.disable_serdes) {
92 /* Mask HBA via NVRAM settings? */
93 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
94 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
95 ha->port_name[0], ha->port_name[1],
96 ha->port_name[2], ha->port_name[3],
97 ha->port_name[4], ha->port_name[5],
98 ha->port_name[6], ha->port_name[7]);
99 return QLA_FUNCTION_FAILED;
102 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
104 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
105 rval = ha->isp_ops.chip_diag(ha);
108 rval = qla2x00_setup_chip(ha);
112 rval = qla2x00_init_rings(ha);
118 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
121 * Returns 0 on success.
124 qla2100_pci_config(scsi_qla_host_t *ha)
129 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
131 pci_set_master(ha->pdev);
133 if (pci_set_mwi(ha->pdev))
134 mwi = PCI_COMMAND_INVALIDATE;
136 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
137 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
138 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
140 /* Reset expansion ROM address decode enable */
141 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
142 d &= ~PCI_ROM_ADDRESS_ENABLE;
143 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
145 /* Get PCI bus information. */
146 spin_lock_irqsave(&ha->hardware_lock, flags);
147 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
148 spin_unlock_irqrestore(&ha->hardware_lock, flags);
154 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
157 * Returns 0 on success.
160 qla2300_pci_config(scsi_qla_host_t *ha)
164 unsigned long flags = 0;
166 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
168 pci_set_master(ha->pdev);
170 if (pci_set_mwi(ha->pdev))
171 mwi = PCI_COMMAND_INVALIDATE;
173 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
174 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
176 if (IS_QLA2322(ha) || IS_QLA6322(ha))
177 w &= ~PCI_COMMAND_INTX_DISABLE;
180 * If this is a 2300 card and not 2312, reset the
181 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
182 * the 2310 also reports itself as a 2300 so we need to get the
183 * fb revision level -- a 6 indicates it really is a 2300 and
186 if (IS_QLA2300(ha)) {
187 spin_lock_irqsave(&ha->hardware_lock, flags);
190 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
191 for (cnt = 0; cnt < 30000; cnt++) {
192 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
198 /* Select FPM registers. */
199 WRT_REG_WORD(®->ctrl_status, 0x20);
200 RD_REG_WORD(®->ctrl_status);
202 /* Get the fb rev level */
203 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
205 if (ha->fb_rev == FPM_2300)
206 w &= ~PCI_COMMAND_INVALIDATE;
208 /* Deselect FPM registers. */
209 WRT_REG_WORD(®->ctrl_status, 0x0);
210 RD_REG_WORD(®->ctrl_status);
212 /* Release RISC module. */
213 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
214 for (cnt = 0; cnt < 30000; cnt++) {
215 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
221 spin_unlock_irqrestore(&ha->hardware_lock, flags);
223 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
225 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
227 /* Reset expansion ROM address decode enable */
228 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
229 d &= ~PCI_ROM_ADDRESS_ENABLE;
230 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
232 /* Get PCI bus information. */
233 spin_lock_irqsave(&ha->hardware_lock, flags);
234 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
235 spin_unlock_irqrestore(&ha->hardware_lock, flags);
241 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
244 * Returns 0 on success.
247 qla24xx_pci_config(scsi_qla_host_t *ha)
251 unsigned long flags = 0;
252 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
253 int pcix_cmd_reg, pcie_dctl_reg;
255 pci_set_master(ha->pdev);
257 if (pci_set_mwi(ha->pdev))
258 mwi = PCI_COMMAND_INVALIDATE;
260 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
261 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
262 w &= ~PCI_COMMAND_INTX_DISABLE;
263 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
265 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
267 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
268 pcix_cmd_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX);
272 pcix_cmd_reg += PCI_X_CMD;
273 pci_read_config_word(ha->pdev, pcix_cmd_reg, &pcix_cmd);
274 pcix_cmd &= ~PCI_X_CMD_MAX_READ;
276 pci_write_config_word(ha->pdev, pcix_cmd_reg, pcix_cmd);
279 /* PCIe -- adjust Maximum Read Request Size (2048). */
280 pcie_dctl_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
284 pcie_dctl_reg += PCI_EXP_DEVCTL;
285 pci_read_config_word(ha->pdev, pcie_dctl_reg, &pcie_dctl);
286 pcie_dctl &= ~PCI_EXP_DEVCTL_READRQ;
288 pci_write_config_word(ha->pdev, pcie_dctl_reg, pcie_dctl);
291 /* Reset expansion ROM address decode enable */
292 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
293 d &= ~PCI_ROM_ADDRESS_ENABLE;
294 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
296 /* Get PCI bus information. */
297 spin_lock_irqsave(&ha->hardware_lock, flags);
298 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
299 spin_unlock_irqrestore(&ha->hardware_lock, flags);
305 * qla2x00_isp_firmware() - Choose firmware image.
308 * Returns 0 on success.
311 qla2x00_isp_firmware(scsi_qla_host_t *ha)
315 /* Assume loading risc code */
316 rval = QLA_FUNCTION_FAILED;
318 if (ha->flags.disable_risc_code_load) {
319 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
321 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
323 /* Verify checksum of loaded RISC code. */
324 rval = qla2x00_verify_checksum(ha, ha->fw_srisc_address);
328 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
336 * qla2x00_reset_chip() - Reset ISP chip.
339 * Returns 0 on success.
342 qla2x00_reset_chip(scsi_qla_host_t *ha)
344 unsigned long flags = 0;
345 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
349 ha->isp_ops.disable_intrs(ha);
351 spin_lock_irqsave(&ha->hardware_lock, flags);
353 /* Turn off master enable */
355 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
356 cmd &= ~PCI_COMMAND_MASTER;
357 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
359 if (!IS_QLA2100(ha)) {
361 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
362 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
363 for (cnt = 0; cnt < 30000; cnt++) {
364 if ((RD_REG_WORD(®->hccr) &
365 HCCR_RISC_PAUSE) != 0)
370 RD_REG_WORD(®->hccr); /* PCI Posting. */
374 /* Select FPM registers. */
375 WRT_REG_WORD(®->ctrl_status, 0x20);
376 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
378 /* FPM Soft Reset. */
379 WRT_REG_WORD(®->fpm_diag_config, 0x100);
380 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
382 /* Toggle Fpm Reset. */
383 if (!IS_QLA2200(ha)) {
384 WRT_REG_WORD(®->fpm_diag_config, 0x0);
385 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
388 /* Select frame buffer registers. */
389 WRT_REG_WORD(®->ctrl_status, 0x10);
390 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
392 /* Reset frame buffer FIFOs. */
393 if (IS_QLA2200(ha)) {
394 WRT_FB_CMD_REG(ha, reg, 0xa000);
395 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
397 WRT_FB_CMD_REG(ha, reg, 0x00fc);
399 /* Read back fb_cmd until zero or 3 seconds max */
400 for (cnt = 0; cnt < 3000; cnt++) {
401 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
407 /* Select RISC module registers. */
408 WRT_REG_WORD(®->ctrl_status, 0);
409 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
411 /* Reset RISC processor. */
412 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
413 RD_REG_WORD(®->hccr); /* PCI Posting. */
415 /* Release RISC processor. */
416 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
417 RD_REG_WORD(®->hccr); /* PCI Posting. */
420 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
421 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
423 /* Reset ISP chip. */
424 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
426 /* Wait for RISC to recover from reset. */
427 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
429 * It is necessary to for a delay here since the card doesn't
430 * respond to PCI reads during a reset. On some architectures
431 * this will result in an MCA.
434 for (cnt = 30000; cnt; cnt--) {
435 if ((RD_REG_WORD(®->ctrl_status) &
436 CSR_ISP_SOFT_RESET) == 0)
443 /* Reset RISC processor. */
444 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
446 WRT_REG_WORD(®->semaphore, 0);
448 /* Release RISC processor. */
449 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
450 RD_REG_WORD(®->hccr); /* PCI Posting. */
452 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
453 for (cnt = 0; cnt < 30000; cnt++) {
454 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
462 /* Turn on master enable */
463 cmd |= PCI_COMMAND_MASTER;
464 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
466 /* Disable RISC pause on FPM parity error. */
467 if (!IS_QLA2100(ha)) {
468 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
469 RD_REG_WORD(®->hccr); /* PCI Posting. */
472 spin_unlock_irqrestore(&ha->hardware_lock, flags);
476 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
479 * Returns 0 on success.
482 qla24xx_reset_risc(scsi_qla_host_t *ha)
484 unsigned long flags = 0;
485 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
489 spin_lock_irqsave(&ha->hardware_lock, flags);
492 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
493 for (cnt = 0; cnt < 30000; cnt++) {
494 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
500 WRT_REG_DWORD(®->ctrl_status,
501 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
502 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
505 /* Wait for firmware to complete NVRAM accesses. */
506 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
507 for (cnt = 10000 ; cnt && d2; cnt--) {
509 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
513 /* Wait for soft-reset to complete. */
514 d2 = RD_REG_DWORD(®->ctrl_status);
515 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
517 d2 = RD_REG_DWORD(®->ctrl_status);
521 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
522 RD_REG_DWORD(®->hccr);
524 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
525 RD_REG_DWORD(®->hccr);
527 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
528 RD_REG_DWORD(®->hccr);
530 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
531 for (cnt = 6000000 ; cnt && d2; cnt--) {
533 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
537 spin_unlock_irqrestore(&ha->hardware_lock, flags);
541 * qla24xx_reset_chip() - Reset ISP24xx chip.
544 * Returns 0 on success.
547 qla24xx_reset_chip(scsi_qla_host_t *ha)
549 ha->isp_ops.disable_intrs(ha);
551 /* Perform RISC reset. */
552 qla24xx_reset_risc(ha);
556 * qla2x00_chip_diag() - Test chip for proper operation.
559 * Returns 0 on success.
562 qla2x00_chip_diag(scsi_qla_host_t *ha)
565 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
566 unsigned long flags = 0;
571 /* Assume a failed state */
572 rval = QLA_FUNCTION_FAILED;
574 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
575 ha->host_no, (u_long)®->flash_address));
577 spin_lock_irqsave(&ha->hardware_lock, flags);
579 /* Reset ISP chip. */
580 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
583 * We need to have a delay here since the card will not respond while
584 * in reset causing an MCA on some architectures.
587 data = qla2x00_debounce_register(®->ctrl_status);
588 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
590 data = RD_REG_WORD(®->ctrl_status);
595 goto chip_diag_failed;
597 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
600 /* Reset RISC processor. */
601 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
602 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
604 /* Workaround for QLA2312 PCI parity error */
605 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
606 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
607 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
609 data = RD_MAILBOX_REG(ha, reg, 0);
616 goto chip_diag_failed;
618 /* Check product ID of chip */
619 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
621 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
622 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
623 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
624 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
625 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
626 mb[3] != PROD_ID_3) {
627 qla_printk(KERN_WARNING, ha,
628 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
630 goto chip_diag_failed;
632 ha->product_id[0] = mb[1];
633 ha->product_id[1] = mb[2];
634 ha->product_id[2] = mb[3];
635 ha->product_id[3] = mb[4];
637 /* Adjust fw RISC transfer size */
638 if (ha->request_q_length > 1024)
639 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
641 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
642 ha->request_q_length;
644 if (IS_QLA2200(ha) &&
645 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
646 /* Limit firmware transfer size with a 2200A */
647 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
650 ha->device_type |= DT_ISP2200A;
651 ha->fw_transfer_size = 128;
654 /* Wrap Incoming Mailboxes Test. */
655 spin_unlock_irqrestore(&ha->hardware_lock, flags);
657 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
658 rval = qla2x00_mbx_reg_test(ha);
660 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
662 qla_printk(KERN_WARNING, ha,
663 "Failed mailbox send register test\n");
666 /* Flag a successful rval */
669 spin_lock_irqsave(&ha->hardware_lock, flags);
673 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
674 "****\n", ha->host_no));
676 spin_unlock_irqrestore(&ha->hardware_lock, flags);
682 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
685 * Returns 0 on success.
688 qla24xx_chip_diag(scsi_qla_host_t *ha)
692 /* Perform RISC reset. */
693 qla24xx_reset_risc(ha);
695 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
697 rval = qla2x00_mbx_reg_test(ha);
699 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
701 qla_printk(KERN_WARNING, ha,
702 "Failed mailbox send register test\n");
704 /* Flag a successful rval */
712 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
715 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
721 qla_printk(KERN_WARNING, ha,
722 "Firmware dump previously allocated.\n");
727 fixed_size = mem_size = eft_size = 0;
728 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
729 fixed_size = sizeof(struct qla2100_fw_dump);
730 } else if (IS_QLA23XX(ha)) {
731 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
732 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
734 } else if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
735 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
736 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
739 /* Allocate memory for Extended Trace Buffer. */
740 eft = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &eft_dma,
743 qla_printk(KERN_WARNING, ha, "Unable to allocate "
744 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
748 rval = qla2x00_trace_control(ha, TC_ENABLE, eft_dma,
751 qla_printk(KERN_WARNING, ha, "Unable to initialize "
752 "EFT (%d).\n", rval);
753 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, eft,
758 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
762 memset(eft, 0, eft_size);
763 ha->eft_dma = eft_dma;
767 req_q_size = ha->request_q_length * sizeof(request_t);
768 rsp_q_size = ha->response_q_length * sizeof(response_t);
770 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
771 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
774 ha->fw_dump = vmalloc(dump_size);
776 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
777 "firmware dump!!!\n", dump_size / 1024);
780 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
788 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
791 ha->fw_dump_len = dump_size;
792 ha->fw_dump->signature[0] = 'Q';
793 ha->fw_dump->signature[1] = 'L';
794 ha->fw_dump->signature[2] = 'G';
795 ha->fw_dump->signature[3] = 'C';
796 ha->fw_dump->version = __constant_htonl(1);
798 ha->fw_dump->fixed_size = htonl(fixed_size);
799 ha->fw_dump->mem_size = htonl(mem_size);
800 ha->fw_dump->req_q_size = htonl(req_q_size);
801 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
803 ha->fw_dump->eft_size = htonl(eft_size);
804 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
805 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
807 ha->fw_dump->header_size =
808 htonl(offsetof(struct qla2xxx_fw_dump, isp));
812 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
815 * Returns 0 on success.
818 qla2x00_resize_request_q(scsi_qla_host_t *ha)
821 uint16_t fw_iocb_cnt = 0;
822 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
823 dma_addr_t request_dma;
824 request_t *request_ring;
826 /* Valid only on recent ISPs. */
827 if (IS_QLA2100(ha) || IS_QLA2200(ha))
830 /* Retrieve IOCB counts available to the firmware. */
831 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
834 /* No point in continuing if current settings are sufficient. */
835 if (fw_iocb_cnt < 1024)
837 if (ha->request_q_length >= request_q_length)
840 /* Attempt to claim larger area for request queue. */
841 request_ring = dma_alloc_coherent(&ha->pdev->dev,
842 (request_q_length + 1) * sizeof(request_t), &request_dma,
844 if (request_ring == NULL)
847 /* Resize successful, report extensions. */
848 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
849 (ha->fw_memory_size + 1) / 1024);
850 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
851 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
853 /* Clear old allocations. */
854 dma_free_coherent(&ha->pdev->dev,
855 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
858 /* Begin using larger queue. */
859 ha->request_q_length = request_q_length;
860 ha->request_ring = request_ring;
861 ha->request_dma = request_dma;
865 * qla2x00_setup_chip() - Load and start RISC firmware.
868 * Returns 0 on success.
871 qla2x00_setup_chip(scsi_qla_host_t *ha)
874 uint32_t srisc_address = 0;
876 /* Load firmware sequences */
877 rval = ha->isp_ops.load_risc(ha, &srisc_address);
878 if (rval == QLA_SUCCESS) {
879 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
880 "code.\n", ha->host_no));
882 rval = qla2x00_verify_checksum(ha, srisc_address);
883 if (rval == QLA_SUCCESS) {
884 /* Start firmware execution. */
885 DEBUG(printk("scsi(%ld): Checksum OK, start "
886 "firmware.\n", ha->host_no));
888 rval = qla2x00_execute_fw(ha, srisc_address);
889 /* Retrieve firmware information. */
890 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
891 qla2x00_get_fw_version(ha,
892 &ha->fw_major_version,
893 &ha->fw_minor_version,
894 &ha->fw_subminor_version,
895 &ha->fw_attributes, &ha->fw_memory_size);
896 qla2x00_resize_request_q(ha);
899 qla2x00_alloc_fw_dump(ha);
902 DEBUG2(printk(KERN_INFO
903 "scsi(%ld): ISP Firmware failed checksum.\n",
909 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
917 * qla2x00_init_response_q_entries() - Initializes response queue entries.
920 * Beginning of request ring has initialization control block already built
921 * by nvram config routine.
923 * Returns 0 on success.
926 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
931 pkt = ha->response_ring_ptr;
932 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
933 pkt->signature = RESPONSE_PROCESSED;
940 * qla2x00_update_fw_options() - Read and process firmware options.
943 * Returns 0 on success.
946 qla2x00_update_fw_options(scsi_qla_host_t *ha)
948 uint16_t swing, emphasis, tx_sens, rx_sens;
950 memset(ha->fw_options, 0, sizeof(ha->fw_options));
951 qla2x00_get_fw_options(ha, ha->fw_options);
953 if (IS_QLA2100(ha) || IS_QLA2200(ha))
956 /* Serial Link options. */
957 DEBUG3(printk("scsi(%ld): Serial link options:\n",
959 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
960 sizeof(ha->fw_seriallink_options)));
962 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
963 if (ha->fw_seriallink_options[3] & BIT_2) {
964 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
967 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
968 emphasis = (ha->fw_seriallink_options[2] &
969 (BIT_4 | BIT_3)) >> 3;
970 tx_sens = ha->fw_seriallink_options[0] &
971 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
972 rx_sens = (ha->fw_seriallink_options[0] &
973 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
974 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
975 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
978 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
979 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
980 ha->fw_options[10] |= BIT_5 |
981 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
982 (tx_sens & (BIT_1 | BIT_0));
985 swing = (ha->fw_seriallink_options[2] &
986 (BIT_7 | BIT_6 | BIT_5)) >> 5;
987 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
988 tx_sens = ha->fw_seriallink_options[1] &
989 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
990 rx_sens = (ha->fw_seriallink_options[1] &
991 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
992 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
993 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
996 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
997 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
998 ha->fw_options[11] |= BIT_5 |
999 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1000 (tx_sens & (BIT_1 | BIT_0));
1004 /* Return command IOCBs without waiting for an ABTS to complete. */
1005 ha->fw_options[3] |= BIT_13;
1008 if (ha->flags.enable_led_scheme)
1009 ha->fw_options[2] |= BIT_12;
1011 /* Detect ISP6312. */
1013 ha->fw_options[2] |= BIT_13;
1015 /* Update firmware options. */
1016 qla2x00_set_fw_options(ha, ha->fw_options);
1020 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1024 /* Update Serial Link options. */
1025 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1028 rval = qla2x00_set_serdes_params(ha,
1029 le16_to_cpu(ha->fw_seriallink_options24[1]),
1030 le16_to_cpu(ha->fw_seriallink_options24[2]),
1031 le16_to_cpu(ha->fw_seriallink_options24[3]));
1032 if (rval != QLA_SUCCESS) {
1033 qla_printk(KERN_WARNING, ha,
1034 "Unable to update Serial Link options (%x).\n", rval);
1039 qla2x00_config_rings(struct scsi_qla_host *ha)
1041 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1043 /* Setup ring parameters in initialization control block. */
1044 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1045 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1046 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1047 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1048 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1049 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1050 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1051 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1053 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1054 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1055 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1056 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1057 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1061 qla24xx_config_rings(struct scsi_qla_host *ha)
1063 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1064 struct init_cb_24xx *icb;
1066 /* Setup ring parameters in initialization control block. */
1067 icb = (struct init_cb_24xx *)ha->init_cb;
1068 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1069 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1070 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1071 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1072 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1073 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1074 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1075 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1077 WRT_REG_DWORD(®->req_q_in, 0);
1078 WRT_REG_DWORD(®->req_q_out, 0);
1079 WRT_REG_DWORD(®->rsp_q_in, 0);
1080 WRT_REG_DWORD(®->rsp_q_out, 0);
1081 RD_REG_DWORD(®->rsp_q_out);
1085 * qla2x00_init_rings() - Initializes firmware.
1088 * Beginning of request ring has initialization control block already built
1089 * by nvram config routine.
1091 * Returns 0 on success.
1094 qla2x00_init_rings(scsi_qla_host_t *ha)
1097 unsigned long flags = 0;
1100 spin_lock_irqsave(&ha->hardware_lock, flags);
1102 /* Clear outstanding commands array. */
1103 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1104 ha->outstanding_cmds[cnt] = NULL;
1106 ha->current_outstanding_cmd = 0;
1108 /* Clear RSCN queue. */
1109 ha->rscn_in_ptr = 0;
1110 ha->rscn_out_ptr = 0;
1112 /* Initialize firmware. */
1113 ha->request_ring_ptr = ha->request_ring;
1114 ha->req_ring_index = 0;
1115 ha->req_q_cnt = ha->request_q_length;
1116 ha->response_ring_ptr = ha->response_ring;
1117 ha->rsp_ring_index = 0;
1119 /* Initialize response queue entries */
1120 qla2x00_init_response_q_entries(ha);
1122 ha->isp_ops.config_rings(ha);
1124 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1126 /* Update any ISP specific firmware options before initialization. */
1127 ha->isp_ops.update_fw_options(ha);
1129 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1130 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1132 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1135 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1143 * qla2x00_fw_ready() - Waits for firmware ready.
1146 * Returns 0 on success.
1149 qla2x00_fw_ready(scsi_qla_host_t *ha)
1152 unsigned long wtime, mtime;
1153 uint16_t min_wait; /* Minimum wait time if loop is down */
1154 uint16_t wait_time; /* Wait time if loop is coming ready */
1159 /* 20 seconds for loop down. */
1163 * Firmware should take at most one RATOV to login, plus 5 seconds for
1164 * our own processing.
1166 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1167 wait_time = min_wait;
1170 /* Min wait time if loop down */
1171 mtime = jiffies + (min_wait * HZ);
1173 /* wait time before firmware ready */
1174 wtime = jiffies + (wait_time * HZ);
1176 /* Wait for ISP to finish LIP */
1177 if (!ha->flags.init_done)
1178 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1180 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1184 rval = qla2x00_get_firmware_state(ha, &fw_state);
1185 if (rval == QLA_SUCCESS) {
1186 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1187 ha->device_flags &= ~DFLG_NO_CABLE;
1189 if (fw_state == FSTATE_READY) {
1190 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1193 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1194 &ha->login_timeout, &ha->r_a_tov);
1200 rval = QLA_FUNCTION_FAILED;
1202 if (atomic_read(&ha->loop_down_timer) &&
1203 fw_state != FSTATE_READY) {
1204 /* Loop down. Timeout on min_wait for states
1205 * other than Wait for Login.
1207 if (time_after_eq(jiffies, mtime)) {
1208 qla_printk(KERN_INFO, ha,
1209 "Cable is unplugged...\n");
1211 ha->device_flags |= DFLG_NO_CABLE;
1216 /* Mailbox cmd failed. Timeout on min_wait. */
1217 if (time_after_eq(jiffies, mtime))
1221 if (time_after_eq(jiffies, wtime))
1224 /* Delay for a while */
1227 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1228 ha->host_no, fw_state, jiffies));
1231 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1232 ha->host_no, fw_state, jiffies));
1235 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1243 * qla2x00_configure_hba
1244 * Setup adapter context.
1247 * ha = adapter state pointer.
1256 qla2x00_configure_hba(scsi_qla_host_t *ha)
1264 char connect_type[22];
1266 /* Get host addresses. */
1267 rval = qla2x00_get_adapter_id(ha,
1268 &loop_id, &al_pa, &area, &domain, &topo);
1269 if (rval != QLA_SUCCESS) {
1270 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
1271 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1272 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1273 __func__, ha->host_no));
1275 qla_printk(KERN_WARNING, ha,
1276 "ERROR -- Unable to get host loop ID.\n");
1277 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1283 qla_printk(KERN_INFO, ha,
1284 "Cannot get topology - retrying.\n");
1285 return (QLA_FUNCTION_FAILED);
1288 ha->loop_id = loop_id;
1291 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1292 ha->operating_mode = LOOP;
1296 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1298 ha->current_topology = ISP_CFG_NL;
1299 strcpy(connect_type, "(Loop)");
1303 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1305 ha->current_topology = ISP_CFG_FL;
1306 strcpy(connect_type, "(FL_Port)");
1310 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1312 ha->operating_mode = P2P;
1313 ha->current_topology = ISP_CFG_N;
1314 strcpy(connect_type, "(N_Port-to-N_Port)");
1318 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1320 ha->operating_mode = P2P;
1321 ha->current_topology = ISP_CFG_F;
1322 strcpy(connect_type, "(F_Port)");
1326 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1328 ha->host_no, topo));
1329 ha->current_topology = ISP_CFG_NL;
1330 strcpy(connect_type, "(Loop)");
1334 /* Save Host port and loop ID. */
1335 /* byte order - Big Endian */
1336 ha->d_id.b.domain = domain;
1337 ha->d_id.b.area = area;
1338 ha->d_id.b.al_pa = al_pa;
1340 if (!ha->flags.init_done)
1341 qla_printk(KERN_INFO, ha,
1342 "Topology - %s, Host Loop address 0x%x\n",
1343 connect_type, ha->loop_id);
1346 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1348 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1355 * NVRAM configuration for ISP 2xxx
1358 * ha = adapter block pointer.
1361 * initialization control block in response_ring
1362 * host adapters parameters in host adapter block
1368 qla2x00_nvram_config(scsi_qla_host_t *ha)
1373 uint8_t *dptr1, *dptr2;
1374 init_cb_t *icb = ha->init_cb;
1375 nvram_t *nv = (nvram_t *)ha->request_ring;
1376 uint8_t *ptr = (uint8_t *)ha->request_ring;
1377 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1381 /* Determine NVRAM starting address. */
1382 ha->nvram_size = sizeof(nvram_t);
1384 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1385 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1386 ha->nvram_base = 0x80;
1388 /* Get NVRAM data and calculate checksum. */
1389 ha->isp_ops.read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1390 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1393 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1394 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1397 /* Bad NVRAM data, set defaults parameters. */
1398 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1399 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1400 /* Reset NVRAM data. */
1401 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1402 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1404 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1405 "invalid -- WWPN) defaults.\n");
1408 * Set default initialization control block.
1410 memset(nv, 0, ha->nvram_size);
1411 nv->parameter_block_version = ICB_VERSION;
1413 if (IS_QLA23XX(ha)) {
1414 nv->firmware_options[0] = BIT_2 | BIT_1;
1415 nv->firmware_options[1] = BIT_7 | BIT_5;
1416 nv->add_firmware_options[0] = BIT_5;
1417 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1418 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1419 nv->special_options[1] = BIT_7;
1420 } else if (IS_QLA2200(ha)) {
1421 nv->firmware_options[0] = BIT_2 | BIT_1;
1422 nv->firmware_options[1] = BIT_7 | BIT_5;
1423 nv->add_firmware_options[0] = BIT_5;
1424 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1425 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1426 } else if (IS_QLA2100(ha)) {
1427 nv->firmware_options[0] = BIT_3 | BIT_1;
1428 nv->firmware_options[1] = BIT_5;
1429 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1432 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1433 nv->execution_throttle = __constant_cpu_to_le16(16);
1434 nv->retry_count = 8;
1435 nv->retry_delay = 1;
1437 nv->port_name[0] = 33;
1438 nv->port_name[3] = 224;
1439 nv->port_name[4] = 139;
1441 nv->login_timeout = 4;
1444 * Set default host adapter parameters
1446 nv->host_p[1] = BIT_2;
1447 nv->reset_delay = 5;
1448 nv->port_down_retry_count = 8;
1449 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1450 nv->link_down_timeout = 60;
1455 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1457 * The SN2 does not provide BIOS emulation which means you can't change
1458 * potentially bogus BIOS settings. Force the use of default settings
1459 * for link rate and frame size. Hope that the rest of the settings
1462 if (ia64_platform_is("sn2")) {
1463 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1465 nv->special_options[1] = BIT_7;
1469 /* Reset Initialization control block */
1470 memset(icb, 0, ha->init_cb_size);
1473 * Setup driver NVRAM options.
1475 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1476 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1477 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1478 nv->firmware_options[1] &= ~BIT_4;
1480 if (IS_QLA23XX(ha)) {
1481 nv->firmware_options[0] |= BIT_2;
1482 nv->firmware_options[0] &= ~BIT_3;
1483 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1485 if (IS_QLA2300(ha)) {
1486 if (ha->fb_rev == FPM_2310) {
1487 strcpy(ha->model_number, "QLA2310");
1489 strcpy(ha->model_number, "QLA2300");
1493 memcmp(nv->model_number, BINZERO,
1494 sizeof(nv->model_number)) != 0) {
1497 strncpy(ha->model_number, nv->model_number,
1498 sizeof(nv->model_number));
1499 st = en = ha->model_number;
1500 en += sizeof(nv->model_number) - 1;
1502 if (*en != 0x20 && *en != 0x00)
1509 index = (ha->pdev->subsystem_device & 0xff);
1510 if (index < QLA_MODEL_NAMES) {
1511 strcpy(ha->model_number,
1512 qla2x00_model_name[index * 2]);
1514 qla2x00_model_name[index * 2 + 1];
1516 strcpy(ha->model_number, "QLA23xx");
1520 } else if (IS_QLA2200(ha)) {
1521 nv->firmware_options[0] |= BIT_2;
1523 * 'Point-to-point preferred, else loop' is not a safe
1524 * connection mode setting.
1526 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1528 /* Force 'loop preferred, else point-to-point'. */
1529 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1530 nv->add_firmware_options[0] |= BIT_5;
1532 strcpy(ha->model_number, "QLA22xx");
1533 } else /*if (IS_QLA2100(ha))*/ {
1534 strcpy(ha->model_number, "QLA2100");
1538 * Copy over NVRAM RISC parameter block to initialization control block.
1540 dptr1 = (uint8_t *)icb;
1541 dptr2 = (uint8_t *)&nv->parameter_block_version;
1542 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1544 *dptr1++ = *dptr2++;
1546 /* Copy 2nd half. */
1547 dptr1 = (uint8_t *)icb->add_firmware_options;
1548 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1550 *dptr1++ = *dptr2++;
1552 /* Use alternate WWN? */
1553 if (nv->host_p[1] & BIT_7) {
1554 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1555 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1558 /* Prepare nodename */
1559 if ((icb->firmware_options[1] & BIT_6) == 0) {
1561 * Firmware will apply the following mask if the nodename was
1564 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1565 icb->node_name[0] &= 0xF0;
1569 * Set host adapter parameters.
1571 if (nv->host_p[0] & BIT_7)
1572 ql2xextended_error_logging = 1;
1573 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1574 /* Always load RISC code on non ISP2[12]00 chips. */
1575 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1576 ha->flags.disable_risc_code_load = 0;
1577 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1578 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1579 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1580 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1581 ha->flags.disable_serdes = 0;
1583 ha->operating_mode =
1584 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1586 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1587 sizeof(ha->fw_seriallink_options));
1589 /* save HBA serial number */
1590 ha->serial0 = icb->port_name[5];
1591 ha->serial1 = icb->port_name[6];
1592 ha->serial2 = icb->port_name[7];
1593 ha->node_name = icb->node_name;
1594 ha->port_name = icb->port_name;
1596 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1598 ha->retry_count = nv->retry_count;
1600 /* Set minimum login_timeout to 4 seconds. */
1601 if (nv->login_timeout < ql2xlogintimeout)
1602 nv->login_timeout = ql2xlogintimeout;
1603 if (nv->login_timeout < 4)
1604 nv->login_timeout = 4;
1605 ha->login_timeout = nv->login_timeout;
1606 icb->login_timeout = nv->login_timeout;
1608 /* Set minimum RATOV to 200 tenths of a second. */
1611 ha->loop_reset_delay = nv->reset_delay;
1613 /* Link Down Timeout = 0:
1615 * When Port Down timer expires we will start returning
1616 * I/O's to OS with "DID_NO_CONNECT".
1618 * Link Down Timeout != 0:
1620 * The driver waits for the link to come up after link down
1621 * before returning I/Os to OS with "DID_NO_CONNECT".
1623 if (nv->link_down_timeout == 0) {
1624 ha->loop_down_abort_time =
1625 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1627 ha->link_down_timeout = nv->link_down_timeout;
1628 ha->loop_down_abort_time =
1629 (LOOP_DOWN_TIME - ha->link_down_timeout);
1633 * Need enough time to try and get the port back.
1635 ha->port_down_retry_count = nv->port_down_retry_count;
1636 if (qlport_down_retry)
1637 ha->port_down_retry_count = qlport_down_retry;
1638 /* Set login_retry_count */
1639 ha->login_retry_count = nv->retry_count;
1640 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1641 ha->port_down_retry_count > 3)
1642 ha->login_retry_count = ha->port_down_retry_count;
1643 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1644 ha->login_retry_count = ha->port_down_retry_count;
1645 if (ql2xloginretrycount)
1646 ha->login_retry_count = ql2xloginretrycount;
1648 icb->lun_enables = __constant_cpu_to_le16(0);
1649 icb->command_resource_count = 0;
1650 icb->immediate_notify_resource_count = 0;
1651 icb->timeout = __constant_cpu_to_le16(0);
1653 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1655 icb->firmware_options[0] &= ~BIT_3;
1656 icb->add_firmware_options[0] &=
1657 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1658 icb->add_firmware_options[0] |= BIT_2;
1659 icb->response_accumulation_timer = 3;
1660 icb->interrupt_delay_timer = 5;
1662 ha->flags.process_response_queue = 1;
1665 if (!ha->flags.init_done) {
1666 ha->zio_mode = icb->add_firmware_options[0] &
1667 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1668 ha->zio_timer = icb->interrupt_delay_timer ?
1669 icb->interrupt_delay_timer: 2;
1671 icb->add_firmware_options[0] &=
1672 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1673 ha->flags.process_response_queue = 0;
1674 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1675 ha->zio_mode = QLA_ZIO_MODE_6;
1677 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1678 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1679 ha->zio_timer * 100));
1680 qla_printk(KERN_INFO, ha,
1681 "ZIO mode %d enabled; timer delay (%d us).\n",
1682 ha->zio_mode, ha->zio_timer * 100);
1684 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1685 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1686 ha->flags.process_response_queue = 1;
1691 DEBUG2_3(printk(KERN_WARNING
1692 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1698 qla2x00_rport_del(void *data)
1700 fc_port_t *fcport = data;
1701 struct fc_rport *rport;
1702 unsigned long flags;
1704 spin_lock_irqsave(&fcport->rport_lock, flags);
1705 rport = fcport->drport;
1706 fcport->drport = NULL;
1707 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1709 fc_remote_port_delete(rport);
1714 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1716 * @flags: allocation flags
1718 * Returns a pointer to the allocated fcport, or NULL, if none available.
1721 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1725 fcport = kmalloc(sizeof(fc_port_t), flags);
1729 /* Setup fcport template structure. */
1730 memset(fcport, 0, sizeof (fc_port_t));
1732 fcport->port_type = FCT_UNKNOWN;
1733 fcport->loop_id = FC_NO_LOOP_ID;
1734 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1735 fcport->flags = FCF_RLC_SUPPORT;
1736 fcport->supported_classes = FC_COS_UNSPECIFIED;
1737 spin_lock_init(&fcport->rport_lock);
1743 * qla2x00_configure_loop
1744 * Updates Fibre Channel Device Database with what is actually on loop.
1747 * ha = adapter block pointer.
1752 * 2 = database was full and device was not configured.
1755 qla2x00_configure_loop(scsi_qla_host_t *ha)
1758 unsigned long flags, save_flags;
1762 /* Get Initiator ID */
1763 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1764 rval = qla2x00_configure_hba(ha);
1765 if (rval != QLA_SUCCESS) {
1766 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1772 save_flags = flags = ha->dpc_flags;
1773 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1774 ha->host_no, flags));
1777 * If we have both an RSCN and PORT UPDATE pending then handle them
1778 * both at the same time.
1780 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1781 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1783 /* Determine what we need to do */
1784 if (ha->current_topology == ISP_CFG_FL &&
1785 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1787 ha->flags.rscn_queue_overflow = 1;
1788 set_bit(RSCN_UPDATE, &flags);
1790 } else if (ha->current_topology == ISP_CFG_F &&
1791 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1793 ha->flags.rscn_queue_overflow = 1;
1794 set_bit(RSCN_UPDATE, &flags);
1795 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1797 } else if (ha->current_topology == ISP_CFG_N) {
1798 clear_bit(RSCN_UPDATE, &flags);
1800 } else if (!ha->flags.online ||
1801 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1803 ha->flags.rscn_queue_overflow = 1;
1804 set_bit(RSCN_UPDATE, &flags);
1805 set_bit(LOCAL_LOOP_UPDATE, &flags);
1808 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1809 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1810 rval = QLA_FUNCTION_FAILED;
1812 rval = qla2x00_configure_local_loop(ha);
1816 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1817 if (LOOP_TRANSITION(ha)) {
1818 rval = QLA_FUNCTION_FAILED;
1820 rval = qla2x00_configure_fabric(ha);
1824 if (rval == QLA_SUCCESS) {
1825 if (atomic_read(&ha->loop_down_timer) ||
1826 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1827 rval = QLA_FUNCTION_FAILED;
1829 atomic_set(&ha->loop_state, LOOP_READY);
1831 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1836 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1837 __func__, ha->host_no));
1839 DEBUG3(printk("%s: exiting normally\n", __func__));
1842 /* Restore state if a resync event occured during processing */
1843 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1844 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1845 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1846 if (test_bit(RSCN_UPDATE, &save_flags))
1847 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1856 * qla2x00_configure_local_loop
1857 * Updates Fibre Channel Device Database with local loop devices.
1860 * ha = adapter block pointer.
1866 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1871 fc_port_t *fcport, *new_fcport;
1877 uint8_t domain, area, al_pa;
1881 entries = MAX_FIBRE_DEVICES;
1883 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1884 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1886 /* Get list of logged in devices. */
1887 memset(ha->gid_list, 0, GID_LIST_SIZE);
1888 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1890 if (rval != QLA_SUCCESS)
1891 goto cleanup_allocation;
1893 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1894 ha->host_no, entries));
1895 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1896 entries * sizeof(struct gid_list_info)));
1898 /* Allocate temporary fcport for any new fcports discovered. */
1899 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1900 if (new_fcport == NULL) {
1901 rval = QLA_MEMORY_ALLOC_FAILED;
1902 goto cleanup_allocation;
1904 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1907 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1909 list_for_each_entry(fcport, &ha->fcports, list) {
1910 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1911 fcport->port_type != FCT_BROADCAST &&
1912 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1914 DEBUG(printk("scsi(%ld): Marking port lost, "
1916 ha->host_no, fcport->loop_id));
1918 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1919 fcport->flags &= ~FCF_FARP_DONE;
1923 /* Add devices to port list. */
1924 id_iter = (char *)ha->gid_list;
1925 for (index = 0; index < entries; index++) {
1926 domain = ((struct gid_list_info *)id_iter)->domain;
1927 area = ((struct gid_list_info *)id_iter)->area;
1928 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1929 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1930 loop_id = (uint16_t)
1931 ((struct gid_list_info *)id_iter)->loop_id_2100;
1933 loop_id = le16_to_cpu(
1934 ((struct gid_list_info *)id_iter)->loop_id);
1935 id_iter += ha->gid_list_info_size;
1937 /* Bypass reserved domain fields. */
1938 if ((domain & 0xf0) == 0xf0)
1941 /* Bypass if not same domain and area of adapter. */
1942 if (area && domain &&
1943 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
1946 /* Bypass invalid local loop ID. */
1947 if (loop_id > LAST_LOCAL_LOOP_ID)
1950 /* Fill in member data. */
1951 new_fcport->d_id.b.domain = domain;
1952 new_fcport->d_id.b.area = area;
1953 new_fcport->d_id.b.al_pa = al_pa;
1954 new_fcport->loop_id = loop_id;
1955 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1956 if (rval2 != QLA_SUCCESS) {
1957 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1958 "information -- get_port_database=%x, "
1960 ha->host_no, rval2, new_fcport->loop_id));
1961 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
1963 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
1967 /* Check for matching device in port list. */
1970 list_for_each_entry(fcport, &ha->fcports, list) {
1971 if (memcmp(new_fcport->port_name, fcport->port_name,
1975 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1976 FCF_PERSISTENT_BOUND);
1977 fcport->loop_id = new_fcport->loop_id;
1978 fcport->port_type = new_fcport->port_type;
1979 fcport->d_id.b24 = new_fcport->d_id.b24;
1980 memcpy(fcport->node_name, new_fcport->node_name,
1988 /* New device, add to fcports list. */
1989 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1990 list_add_tail(&new_fcport->list, &ha->fcports);
1992 /* Allocate a new replacement fcport. */
1993 fcport = new_fcport;
1994 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1995 if (new_fcport == NULL) {
1996 rval = QLA_MEMORY_ALLOC_FAILED;
1997 goto cleanup_allocation;
1999 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2002 /* Base iIDMA settings on HBA port speed. */
2003 switch (ha->link_data_rate) {
2004 case PORT_SPEED_1GB:
2005 fcport->fp_speed = cpu_to_be16(BIT_15);
2007 case PORT_SPEED_2GB:
2008 fcport->fp_speed = cpu_to_be16(BIT_14);
2010 case PORT_SPEED_4GB:
2011 fcport->fp_speed = cpu_to_be16(BIT_13);
2015 qla2x00_update_fcport(ha, fcport);
2023 if (rval != QLA_SUCCESS) {
2024 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2025 "rval=%x\n", ha->host_no, rval));
2029 ha->device_flags |= DFLG_LOCAL_DEVICES;
2030 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2037 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
2041 qla2x00_mark_all_devices_lost(ha, 0);
2042 list_for_each_entry(fcport, &ha->fcports, list) {
2043 if (fcport->port_type != FCT_TARGET)
2046 qla2x00_update_fcport(ha, fcport);
2051 qla2x00_iidma_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2053 #define LS_UNKNOWN 2
2054 static char *link_speeds[5] = { "1", "2", "?", "4" };
2056 uint16_t port_speed, mb[6];
2058 if (!IS_QLA24XX(ha))
2061 switch (be16_to_cpu(fcport->fp_speed)) {
2063 port_speed = PORT_SPEED_1GB;
2066 port_speed = PORT_SPEED_2GB;
2069 port_speed = PORT_SPEED_4GB;
2072 DEBUG2(printk("scsi(%ld): %02x%02x%02x%02x%02x%02x%02x%02x -- "
2073 "unsupported FM port operating speed (%04x).\n",
2074 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2075 fcport->port_name[2], fcport->port_name[3],
2076 fcport->port_name[4], fcport->port_name[5],
2077 fcport->port_name[6], fcport->port_name[7],
2078 be16_to_cpu(fcport->fp_speed)));
2079 port_speed = PORT_SPEED_UNKNOWN;
2082 if (port_speed == PORT_SPEED_UNKNOWN)
2085 rval = qla2x00_set_idma_speed(ha, fcport->loop_id, port_speed, mb);
2086 if (rval != QLA_SUCCESS) {
2087 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2088 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2089 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2090 fcport->port_name[2], fcport->port_name[3],
2091 fcport->port_name[4], fcport->port_name[5],
2092 fcport->port_name[6], fcport->port_name[7], rval,
2093 port_speed, mb[0], mb[1]));
2095 DEBUG2(qla_printk(KERN_INFO, ha,
2096 "iIDMA adjusted to %s GB/s on "
2097 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2098 link_speeds[port_speed], fcport->port_name[0],
2099 fcport->port_name[1], fcport->port_name[2],
2100 fcport->port_name[3], fcport->port_name[4],
2101 fcport->port_name[5], fcport->port_name[6],
2102 fcport->port_name[7]));
2107 * qla2x00_update_fcport
2108 * Updates device on list.
2111 * ha = adapter block pointer.
2112 * fcport = port structure pointer.
2122 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2125 fcport->login_retry = 0;
2126 fcport->port_login_retry_count = ha->port_down_retry_count *
2128 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2130 fcport->flags &= ~FCF_LOGIN_NEEDED;
2132 qla2x00_iidma_fcport(ha, fcport);
2134 atomic_set(&fcport->state, FCS_ONLINE);
2136 qla2x00_reg_remote_port(ha, fcport);
2140 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2142 struct fc_rport_identifiers rport_ids;
2143 struct fc_rport *rport;
2144 unsigned long flags;
2147 qla2x00_rport_del(fcport);
2151 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2152 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2153 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2154 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2155 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2156 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2158 qla_printk(KERN_WARNING, ha,
2159 "Unable to allocate fc remote port!\n");
2162 spin_lock_irqsave(&fcport->rport_lock, flags);
2163 fcport->rport = rport;
2164 *((fc_port_t **)rport->dd_data) = fcport;
2165 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2167 rport->supported_classes = fcport->supported_classes;
2169 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2170 if (fcport->port_type == FCT_INITIATOR)
2171 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2172 if (fcport->port_type == FCT_TARGET)
2173 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2174 fc_remote_port_rolechg(rport, rport_ids.roles);
2176 if (rport->scsi_target_id != -1 &&
2177 rport->scsi_target_id < ha->host->max_id)
2178 fcport->os_target_id = rport->scsi_target_id;
2182 * qla2x00_configure_fabric
2183 * Setup SNS devices with loop ID's.
2186 * ha = adapter block pointer.
2193 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2196 fc_port_t *fcport, *fcptemp;
2197 uint16_t next_loopid;
2198 uint16_t mb[MAILBOX_REGISTER_COUNT];
2200 LIST_HEAD(new_fcports);
2202 /* If FL port exists, then SNS is present */
2203 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2204 loop_id = NPH_F_PORT;
2206 loop_id = SNS_FL_PORT;
2207 rval = qla2x00_get_port_name(ha, loop_id, ha->fabric_node_name, 1);
2208 if (rval != QLA_SUCCESS) {
2209 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2210 "Port\n", ha->host_no));
2212 ha->device_flags &= ~SWITCH_FOUND;
2213 return (QLA_SUCCESS);
2215 ha->device_flags |= SWITCH_FOUND;
2217 /* Mark devices that need re-synchronization. */
2218 rval2 = qla2x00_device_resync(ha);
2219 if (rval2 == QLA_RSCNS_HANDLED) {
2220 /* No point doing the scan, just continue. */
2221 return (QLA_SUCCESS);
2225 if (ql2xfdmienable &&
2226 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2227 qla2x00_fdmi_register(ha);
2229 /* Ensure we are logged into the SNS. */
2230 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2233 loop_id = SIMPLE_NAME_SERVER;
2234 ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
2235 0xfc, mb, BIT_1 | BIT_0);
2236 if (mb[0] != MBS_COMMAND_COMPLETE) {
2237 DEBUG2(qla_printk(KERN_INFO, ha,
2238 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2239 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2240 mb[0], mb[1], mb[2], mb[6], mb[7]));
2241 return (QLA_SUCCESS);
2244 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2245 if (qla2x00_rft_id(ha)) {
2247 DEBUG2(printk("scsi(%ld): Register FC-4 "
2248 "TYPE failed.\n", ha->host_no));
2250 if (qla2x00_rff_id(ha)) {
2252 DEBUG2(printk("scsi(%ld): Register FC-4 "
2253 "Features failed.\n", ha->host_no));
2255 if (qla2x00_rnn_id(ha)) {
2257 DEBUG2(printk("scsi(%ld): Register Node Name "
2258 "failed.\n", ha->host_no));
2259 } else if (qla2x00_rsnn_nn(ha)) {
2261 DEBUG2(printk("scsi(%ld): Register Symbolic "
2262 "Node Name failed.\n", ha->host_no));
2266 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2267 if (rval != QLA_SUCCESS)
2271 * Logout all previous fabric devices marked lost, except
2274 list_for_each_entry(fcport, &ha->fcports, list) {
2275 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2278 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2281 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2282 qla2x00_mark_device_lost(ha, fcport,
2283 ql2xplogiabsentdevice, 0);
2284 if (fcport->loop_id != FC_NO_LOOP_ID &&
2285 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2286 fcport->port_type != FCT_INITIATOR &&
2287 fcport->port_type != FCT_BROADCAST) {
2288 ha->isp_ops.fabric_logout(ha,
2290 fcport->d_id.b.domain,
2291 fcport->d_id.b.area,
2292 fcport->d_id.b.al_pa);
2293 fcport->loop_id = FC_NO_LOOP_ID;
2298 /* Starting free loop ID. */
2299 next_loopid = ha->min_external_loopid;
2302 * Scan through our port list and login entries that need to be
2305 list_for_each_entry(fcport, &ha->fcports, list) {
2306 if (atomic_read(&ha->loop_down_timer) ||
2307 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2310 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2311 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2314 if (fcport->loop_id == FC_NO_LOOP_ID) {
2315 fcport->loop_id = next_loopid;
2316 rval = qla2x00_find_new_loop_id(ha, fcport);
2317 if (rval != QLA_SUCCESS) {
2318 /* Ran out of IDs to use */
2322 /* Login and update database */
2323 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2326 /* Exit if out of loop IDs. */
2327 if (rval != QLA_SUCCESS) {
2332 * Login and add the new devices to our port list.
2334 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2335 if (atomic_read(&ha->loop_down_timer) ||
2336 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2339 /* Find a new loop ID to use. */
2340 fcport->loop_id = next_loopid;
2341 rval = qla2x00_find_new_loop_id(ha, fcport);
2342 if (rval != QLA_SUCCESS) {
2343 /* Ran out of IDs to use */
2347 /* Remove device from the new list and add it to DB */
2348 list_move_tail(&fcport->list, &ha->fcports);
2350 /* Login and update database */
2351 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2355 /* Free all new device structures not processed. */
2356 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2357 list_del(&fcport->list);
2362 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2363 "rval=%d\n", ha->host_no, rval));
2371 * qla2x00_find_all_fabric_devs
2374 * ha = adapter block pointer.
2375 * dev = database device entry pointer.
2384 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2388 fc_port_t *fcport, *new_fcport, *fcptemp;
2393 int first_dev, last_dev;
2394 port_id_t wrap, nxt_d_id;
2398 /* Try GID_PT to get device list, else GAN. */
2399 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2402 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2403 "on GA_NXT\n", ha->host_no));
2405 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2406 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2409 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2412 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2415 } else if (qla2x00_gfpn_id(ha, swl) == QLA_SUCCESS) {
2416 qla2x00_gpsc(ha, swl);
2421 /* Allocate temporary fcport for any new fcports discovered. */
2422 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2423 if (new_fcport == NULL) {
2425 return (QLA_MEMORY_ALLOC_FAILED);
2427 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2429 /* Set start port ID scan at adapter ID. */
2433 /* Starting free loop ID. */
2434 loop_id = ha->min_external_loopid;
2435 for (; loop_id <= ha->last_loop_id; loop_id++) {
2436 if (qla2x00_is_reserved_id(ha, loop_id))
2439 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2444 wrap.b24 = new_fcport->d_id.b24;
2446 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2447 memcpy(new_fcport->node_name,
2448 swl[swl_idx].node_name, WWN_SIZE);
2449 memcpy(new_fcport->port_name,
2450 swl[swl_idx].port_name, WWN_SIZE);
2451 memcpy(new_fcport->fabric_port_name,
2452 swl[swl_idx].fabric_port_name, WWN_SIZE);
2453 new_fcport->fp_speed = swl[swl_idx].fp_speed;
2455 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2461 /* Send GA_NXT to the switch */
2462 rval = qla2x00_ga_nxt(ha, new_fcport);
2463 if (rval != QLA_SUCCESS) {
2464 qla_printk(KERN_WARNING, ha,
2465 "SNS scan failed -- assuming zero-entry "
2467 list_for_each_entry_safe(fcport, fcptemp,
2468 new_fcports, list) {
2469 list_del(&fcport->list);
2477 /* If wrap on switch device list, exit. */
2479 wrap.b24 = new_fcport->d_id.b24;
2481 } else if (new_fcport->d_id.b24 == wrap.b24) {
2482 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2483 ha->host_no, new_fcport->d_id.b.domain,
2484 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2488 /* Bypass if host adapter. */
2489 if (new_fcport->d_id.b24 == ha->d_id.b24)
2492 /* Bypass if same domain and area of adapter. */
2493 if (((new_fcport->d_id.b24 & 0xffff00) ==
2494 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2498 /* Bypass reserved domain fields. */
2499 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2502 /* Locate matching device in database. */
2504 list_for_each_entry(fcport, &ha->fcports, list) {
2505 if (memcmp(new_fcport->port_name, fcport->port_name,
2511 /* Update port state. */
2512 memcpy(fcport->fabric_port_name,
2513 new_fcport->fabric_port_name, WWN_SIZE);
2514 fcport->fp_speed = new_fcport->fp_speed;
2517 * If address the same and state FCS_ONLINE, nothing
2520 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2521 atomic_read(&fcport->state) == FCS_ONLINE) {
2526 * If device was not a fabric device before.
2528 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2529 fcport->d_id.b24 = new_fcport->d_id.b24;
2530 fcport->loop_id = FC_NO_LOOP_ID;
2531 fcport->flags |= (FCF_FABRIC_DEVICE |
2533 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2538 * Port ID changed or device was marked to be updated;
2539 * Log it out if still logged in and mark it for
2542 fcport->d_id.b24 = new_fcport->d_id.b24;
2543 fcport->flags |= FCF_LOGIN_NEEDED;
2544 if (fcport->loop_id != FC_NO_LOOP_ID &&
2545 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2546 fcport->port_type != FCT_INITIATOR &&
2547 fcport->port_type != FCT_BROADCAST) {
2548 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2549 fcport->d_id.b.domain, fcport->d_id.b.area,
2550 fcport->d_id.b.al_pa);
2551 fcport->loop_id = FC_NO_LOOP_ID;
2560 /* If device was not in our fcports list, then add it. */
2561 list_add_tail(&new_fcport->list, new_fcports);
2563 /* Allocate a new replacement fcport. */
2564 nxt_d_id.b24 = new_fcport->d_id.b24;
2565 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2566 if (new_fcport == NULL) {
2568 return (QLA_MEMORY_ALLOC_FAILED);
2570 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2571 new_fcport->d_id.b24 = nxt_d_id.b24;
2577 if (!list_empty(new_fcports))
2578 ha->device_flags |= DFLG_FABRIC_DEVICES;
2584 * qla2x00_find_new_loop_id
2585 * Scan through our port list and find a new usable loop ID.
2588 * ha: adapter state pointer.
2589 * dev: port structure pointer.
2592 * qla2x00 local function return status code.
2598 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2603 uint16_t first_loop_id;
2607 /* Save starting loop ID. */
2608 first_loop_id = dev->loop_id;
2611 /* Skip loop ID if already used by adapter. */
2612 if (dev->loop_id == ha->loop_id) {
2616 /* Skip reserved loop IDs. */
2617 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2621 /* Reset loop ID if passed the end. */
2622 if (dev->loop_id > ha->last_loop_id) {
2623 /* first loop ID. */
2624 dev->loop_id = ha->min_external_loopid;
2627 /* Check for loop ID being already in use. */
2630 list_for_each_entry(fcport, &ha->fcports, list) {
2631 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2632 /* ID possibly in use */
2638 /* If not in use then it is free to use. */
2643 /* ID in use. Try next value. */
2646 /* If wrap around. No free ID to use. */
2647 if (dev->loop_id == first_loop_id) {
2648 dev->loop_id = FC_NO_LOOP_ID;
2649 rval = QLA_FUNCTION_FAILED;
2658 * qla2x00_device_resync
2659 * Marks devices in the database that needs resynchronization.
2662 * ha = adapter block pointer.
2668 qla2x00_device_resync(scsi_qla_host_t *ha)
2673 uint32_t rscn_entry;
2674 uint8_t rscn_out_iter;
2678 rval = QLA_RSCNS_HANDLED;
2680 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2681 ha->flags.rscn_queue_overflow) {
2683 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2684 format = MSB(MSW(rscn_entry));
2685 d_id.b.domain = LSB(MSW(rscn_entry));
2686 d_id.b.area = MSB(LSW(rscn_entry));
2687 d_id.b.al_pa = LSB(LSW(rscn_entry));
2689 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2690 "[%02x/%02x%02x%02x].\n",
2691 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2692 d_id.b.area, d_id.b.al_pa));
2695 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2696 ha->rscn_out_ptr = 0;
2698 /* Skip duplicate entries. */
2699 for (rscn_out_iter = ha->rscn_out_ptr;
2700 !ha->flags.rscn_queue_overflow &&
2701 rscn_out_iter != ha->rscn_in_ptr;
2702 rscn_out_iter = (rscn_out_iter ==
2703 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2705 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2708 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2709 "entry found at [%d].\n", ha->host_no,
2712 ha->rscn_out_ptr = rscn_out_iter;
2715 /* Queue overflow, set switch default case. */
2716 if (ha->flags.rscn_queue_overflow) {
2717 DEBUG(printk("scsi(%ld): device_resync: rscn "
2718 "overflow.\n", ha->host_no));
2721 ha->flags.rscn_queue_overflow = 0;
2737 ha->rscn_out_ptr = ha->rscn_in_ptr;
2743 list_for_each_entry(fcport, &ha->fcports, list) {
2744 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2745 (fcport->d_id.b24 & mask) != d_id.b24 ||
2746 fcport->port_type == FCT_BROADCAST)
2749 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2751 fcport->port_type != FCT_INITIATOR) {
2752 qla2x00_mark_device_lost(ha, fcport,
2756 fcport->flags &= ~FCF_FARP_DONE;
2763 * qla2x00_fabric_dev_login
2764 * Login fabric target device and update FC port database.
2767 * ha: adapter state pointer.
2768 * fcport: port structure list pointer.
2769 * next_loopid: contains value of a new loop ID that can be used
2770 * by the next login attempt.
2773 * qla2x00 local function return status code.
2779 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2780 uint16_t *next_loopid)
2789 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2790 if (rval == QLA_SUCCESS) {
2791 /* Send an ADISC to tape devices.*/
2793 if (fcport->flags & FCF_TAPE_PRESENT)
2795 rval = qla2x00_get_port_database(ha, fcport, opts);
2796 if (rval != QLA_SUCCESS) {
2797 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2798 fcport->d_id.b.domain, fcport->d_id.b.area,
2799 fcport->d_id.b.al_pa);
2800 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2802 qla2x00_update_fcport(ha, fcport);
2810 * qla2x00_fabric_login
2811 * Issue fabric login command.
2814 * ha = adapter block pointer.
2815 * device = pointer to FC device type structure.
2818 * 0 - Login successfully
2820 * 2 - Initiator device
2824 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2825 uint16_t *next_loopid)
2829 uint16_t tmp_loopid;
2830 uint16_t mb[MAILBOX_REGISTER_COUNT];
2836 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2837 "for port %02x%02x%02x.\n",
2838 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2839 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2841 /* Login fcport on switch. */
2842 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2843 fcport->d_id.b.domain, fcport->d_id.b.area,
2844 fcport->d_id.b.al_pa, mb, BIT_0);
2845 if (mb[0] == MBS_PORT_ID_USED) {
2847 * Device has another loop ID. The firmware team
2848 * recommends the driver perform an implicit login with
2849 * the specified ID again. The ID we just used is save
2850 * here so we return with an ID that can be tried by
2854 tmp_loopid = fcport->loop_id;
2855 fcport->loop_id = mb[1];
2857 DEBUG(printk("Fabric Login: port in use - next "
2858 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2859 fcport->loop_id, fcport->d_id.b.domain,
2860 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2862 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2867 /* A retry occurred before. */
2868 *next_loopid = tmp_loopid;
2871 * No retry occurred before. Just increment the
2872 * ID value for next login.
2874 *next_loopid = (fcport->loop_id + 1);
2877 if (mb[1] & BIT_0) {
2878 fcport->port_type = FCT_INITIATOR;
2880 fcport->port_type = FCT_TARGET;
2881 if (mb[1] & BIT_1) {
2882 fcport->flags |= FCF_TAPE_PRESENT;
2887 fcport->supported_classes |= FC_COS_CLASS2;
2889 fcport->supported_classes |= FC_COS_CLASS3;
2893 } else if (mb[0] == MBS_LOOP_ID_USED) {
2895 * Loop ID already used, try next loop ID.
2898 rval = qla2x00_find_new_loop_id(ha, fcport);
2899 if (rval != QLA_SUCCESS) {
2900 /* Ran out of loop IDs to use */
2903 } else if (mb[0] == MBS_COMMAND_ERROR) {
2905 * Firmware possibly timed out during login. If NO
2906 * retries are left to do then the device is declared
2909 *next_loopid = fcport->loop_id;
2910 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2911 fcport->d_id.b.domain, fcport->d_id.b.area,
2912 fcport->d_id.b.al_pa);
2913 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2919 * unrecoverable / not handled error
2921 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2922 "loop_id=%x jiffies=%lx.\n",
2923 __func__, ha->host_no, mb[0],
2924 fcport->d_id.b.domain, fcport->d_id.b.area,
2925 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2927 *next_loopid = fcport->loop_id;
2928 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2929 fcport->d_id.b.domain, fcport->d_id.b.area,
2930 fcport->d_id.b.al_pa);
2931 fcport->loop_id = FC_NO_LOOP_ID;
2932 fcport->login_retry = 0;
2943 * qla2x00_local_device_login
2944 * Issue local device login command.
2947 * ha = adapter block pointer.
2948 * loop_id = loop id of device to login to.
2950 * Returns (Where's the #define!!!!):
2951 * 0 - Login successfully
2956 qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
2959 uint16_t mb[MAILBOX_REGISTER_COUNT];
2961 memset(mb, 0, sizeof(mb));
2962 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
2963 if (rval == QLA_SUCCESS) {
2964 /* Interrogate mailbox registers for any errors */
2965 if (mb[0] == MBS_COMMAND_ERROR)
2967 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
2968 /* device not in PCB table */
2976 * qla2x00_loop_resync
2977 * Resync with fibre channel devices.
2980 * ha = adapter block pointer.
2986 qla2x00_loop_resync(scsi_qla_host_t *ha)
2993 atomic_set(&ha->loop_state, LOOP_UPDATE);
2994 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2995 if (ha->flags.online) {
2996 if (!(rval = qla2x00_fw_ready(ha))) {
2997 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3000 atomic_set(&ha->loop_state, LOOP_UPDATE);
3002 /* Issue a marker after FW becomes ready. */
3003 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3004 ha->marker_needed = 0;
3006 /* Remap devices on Loop. */
3007 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3009 qla2x00_configure_loop(ha);
3011 } while (!atomic_read(&ha->loop_down_timer) &&
3012 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3014 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3018 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3019 return (QLA_FUNCTION_FAILED);
3023 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3030 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
3036 list_for_each_entry(fcport, &ha->fcports, list) {
3037 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
3040 qla2x00_update_fcport(ha, fcport);
3041 fcport->flags &= ~FCF_RESCAN_NEEDED;
3045 qla2x00_probe_for_all_luns(ha);
3049 qla2x00_update_fcports(scsi_qla_host_t *ha)
3053 /* Go with deferred removal of rport references. */
3054 list_for_each_entry(fcport, &ha->fcports, list)
3056 qla2x00_rport_del(fcport);
3061 * Resets ISP and aborts all outstanding commands.
3064 * ha = adapter block pointer.
3070 qla2x00_abort_isp(scsi_qla_host_t *ha)
3073 unsigned long flags = 0;
3078 if (ha->flags.online) {
3079 ha->flags.online = 0;
3080 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3082 qla_printk(KERN_INFO, ha,
3083 "Performing ISP error recovery - ha= %p.\n", ha);
3084 ha->isp_ops.reset_chip(ha);
3086 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3087 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3088 atomic_set(&ha->loop_state, LOOP_DOWN);
3089 qla2x00_mark_all_devices_lost(ha, 0);
3091 if (!atomic_read(&ha->loop_down_timer))
3092 atomic_set(&ha->loop_down_timer,
3096 spin_lock_irqsave(&ha->hardware_lock, flags);
3097 /* Requeue all commands in outstanding command list. */
3098 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3099 sp = ha->outstanding_cmds[cnt];
3101 ha->outstanding_cmds[cnt] = NULL;
3103 sp->cmd->result = DID_RESET << 16;
3104 sp->cmd->host_scribble = (unsigned char *)NULL;
3105 qla2x00_sp_compl(ha, sp);
3108 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3110 ha->isp_ops.nvram_config(ha);
3112 if (!qla2x00_restart_isp(ha)) {
3113 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3115 if (!atomic_read(&ha->loop_down_timer)) {
3117 * Issue marker command only when we are going
3118 * to start the I/O .
3120 ha->marker_needed = 1;
3123 ha->flags.online = 1;
3125 ha->isp_ops.enable_intrs(ha);
3127 ha->isp_abort_cnt = 0;
3128 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3131 rval = qla2x00_trace_control(ha, TC_ENABLE,
3132 ha->eft_dma, EFT_NUM_BUFFERS);
3134 qla_printk(KERN_WARNING, ha,
3135 "Unable to reinitialize EFT "
3139 } else { /* failed the ISP abort */
3140 ha->flags.online = 1;
3141 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3142 if (ha->isp_abort_cnt == 0) {
3143 qla_printk(KERN_WARNING, ha,
3144 "ISP error recovery failed - "
3145 "board disabled\n");
3147 * The next call disables the board
3150 ha->isp_ops.reset_adapter(ha);
3151 ha->flags.online = 0;
3152 clear_bit(ISP_ABORT_RETRY,
3155 } else { /* schedule another ISP abort */
3156 ha->isp_abort_cnt--;
3157 DEBUG(printk("qla%ld: ISP abort - "
3158 "retry remaining %d\n",
3159 ha->host_no, ha->isp_abort_cnt));
3163 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3164 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3165 "- retrying (%d) more times\n",
3166 ha->host_no, ha->isp_abort_cnt));
3167 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3175 qla_printk(KERN_INFO, ha,
3176 "qla2x00_abort_isp: **** FAILED ****\n");
3178 DEBUG(printk(KERN_INFO
3179 "qla2x00_abort_isp(%ld): exiting.\n",
3187 * qla2x00_restart_isp
3188 * restarts the ISP after a reset
3191 * ha = adapter block pointer.
3197 qla2x00_restart_isp(scsi_qla_host_t *ha)
3200 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3201 unsigned long flags = 0;
3204 /* If firmware needs to be loaded */
3205 if (qla2x00_isp_firmware(ha)) {
3206 ha->flags.online = 0;
3207 if (!(status = ha->isp_ops.chip_diag(ha))) {
3208 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3209 status = qla2x00_setup_chip(ha);
3213 spin_lock_irqsave(&ha->hardware_lock, flags);
3215 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3217 * Disable SRAM, Instruction RAM and GP RAM
3220 WRT_REG_WORD(®->hccr,
3221 (HCCR_ENABLE_PARITY + 0x0));
3222 RD_REG_WORD(®->hccr);
3225 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3227 status = qla2x00_setup_chip(ha);
3229 spin_lock_irqsave(&ha->hardware_lock, flags);
3231 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3232 /* Enable proper parity */
3235 WRT_REG_WORD(®->hccr,
3236 (HCCR_ENABLE_PARITY + 0x1));
3239 * SRAM, Instruction RAM and GP RAM
3242 WRT_REG_WORD(®->hccr,
3243 (HCCR_ENABLE_PARITY + 0x7));
3244 RD_REG_WORD(®->hccr);
3247 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3252 if (!status && !(status = qla2x00_init_rings(ha))) {
3253 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3254 if (!(status = qla2x00_fw_ready(ha))) {
3255 DEBUG(printk("%s(): Start configure loop, "
3256 "status = %d\n", __func__, status));
3258 /* Issue a marker after FW becomes ready. */
3259 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3261 ha->flags.online = 1;
3262 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3265 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3266 qla2x00_configure_loop(ha);
3268 } while (!atomic_read(&ha->loop_down_timer) &&
3269 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3271 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3274 /* if no cable then assume it's good */
3275 if ((ha->device_flags & DFLG_NO_CABLE))
3278 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3286 * qla2x00_reset_adapter
3290 * ha = adapter block pointer.
3293 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3295 unsigned long flags = 0;
3296 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3298 ha->flags.online = 0;
3299 ha->isp_ops.disable_intrs(ha);
3301 spin_lock_irqsave(&ha->hardware_lock, flags);
3302 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3303 RD_REG_WORD(®->hccr); /* PCI Posting. */
3304 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3305 RD_REG_WORD(®->hccr); /* PCI Posting. */
3306 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3310 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3312 unsigned long flags = 0;
3313 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3315 ha->flags.online = 0;
3316 ha->isp_ops.disable_intrs(ha);
3318 spin_lock_irqsave(&ha->hardware_lock, flags);
3319 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3320 RD_REG_DWORD(®->hccr);
3321 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3322 RD_REG_DWORD(®->hccr);
3323 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3327 qla24xx_nvram_config(scsi_qla_host_t *ha)
3330 struct init_cb_24xx *icb;
3331 struct nvram_24xx *nv;
3333 uint8_t *dptr1, *dptr2;
3338 icb = (struct init_cb_24xx *)ha->init_cb;
3339 nv = (struct nvram_24xx *)ha->request_ring;
3341 /* Determine NVRAM starting address. */
3342 ha->nvram_size = sizeof(struct nvram_24xx);
3343 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3344 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3345 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3346 if (PCI_FUNC(ha->pdev->devfn)) {
3347 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3348 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3351 /* Get NVRAM data and calculate checksum. */
3352 dptr = (uint32_t *)nv;
3353 ha->isp_ops.read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3355 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3356 chksum += le32_to_cpu(*dptr++);
3358 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3359 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3362 /* Bad NVRAM data, set defaults parameters. */
3363 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3364 || nv->id[3] != ' ' ||
3365 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3366 /* Reset NVRAM data. */
3367 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3368 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3369 le16_to_cpu(nv->nvram_version));
3370 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3371 "invalid -- WWPN) defaults.\n");
3374 * Set default initialization control block.
3376 memset(nv, 0, ha->nvram_size);
3377 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3378 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3379 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3380 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3381 nv->exchange_count = __constant_cpu_to_le16(0);
3382 nv->hard_address = __constant_cpu_to_le16(124);
3383 nv->port_name[0] = 0x21;
3384 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3385 nv->port_name[2] = 0x00;
3386 nv->port_name[3] = 0xe0;
3387 nv->port_name[4] = 0x8b;
3388 nv->port_name[5] = 0x1c;
3389 nv->port_name[6] = 0x55;
3390 nv->port_name[7] = 0x86;
3391 nv->node_name[0] = 0x20;
3392 nv->node_name[1] = 0x00;
3393 nv->node_name[2] = 0x00;
3394 nv->node_name[3] = 0xe0;
3395 nv->node_name[4] = 0x8b;
3396 nv->node_name[5] = 0x1c;
3397 nv->node_name[6] = 0x55;
3398 nv->node_name[7] = 0x86;
3399 nv->login_retry_count = __constant_cpu_to_le16(8);
3400 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3401 nv->login_timeout = __constant_cpu_to_le16(0);
3402 nv->firmware_options_1 =
3403 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3404 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3405 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3406 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3407 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3408 nv->efi_parameters = __constant_cpu_to_le32(0);
3409 nv->reset_delay = 5;
3410 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3411 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3412 nv->link_down_timeout = __constant_cpu_to_le16(30);
3417 /* Reset Initialization control block */
3418 memset(icb, 0, sizeof(struct init_cb_24xx));
3420 /* Copy 1st segment. */
3421 dptr1 = (uint8_t *)icb;
3422 dptr2 = (uint8_t *)&nv->version;
3423 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3425 *dptr1++ = *dptr2++;
3427 icb->login_retry_count = nv->login_retry_count;
3428 icb->link_down_on_nos = nv->link_down_on_nos;
3430 /* Copy 2nd segment. */
3431 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3432 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3433 cnt = (uint8_t *)&icb->reserved_3 -
3434 (uint8_t *)&icb->interrupt_delay_timer;
3436 *dptr1++ = *dptr2++;
3439 * Setup driver NVRAM options.
3441 if (memcmp(nv->model_name, BINZERO, sizeof(nv->model_name)) != 0) {
3445 strncpy(ha->model_number, nv->model_name,
3446 sizeof(nv->model_name));
3447 st = en = ha->model_number;
3448 en += sizeof(nv->model_name) - 1;
3450 if (*en != 0x20 && *en != 0x00)
3455 index = (ha->pdev->subsystem_device & 0xff);
3456 if (index < QLA_MODEL_NAMES)
3457 ha->model_desc = qla2x00_model_name[index * 2 + 1];
3459 strcpy(ha->model_number, "QLA2462");
3461 /* Use alternate WWN? */
3462 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3463 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3464 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3467 /* Prepare nodename */
3468 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3470 * Firmware will apply the following mask if the nodename was
3473 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3474 icb->node_name[0] &= 0xF0;
3477 /* Set host adapter parameters. */
3478 ha->flags.disable_risc_code_load = 0;
3479 ha->flags.enable_lip_reset = 1;
3480 ha->flags.enable_lip_full_login = 1;
3481 ha->flags.enable_target_reset = 1;
3482 ha->flags.enable_led_scheme = 0;
3483 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
3485 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3486 (BIT_6 | BIT_5 | BIT_4)) >> 4;
3488 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3489 sizeof(ha->fw_seriallink_options24));
3491 /* save HBA serial number */
3492 ha->serial0 = icb->port_name[5];
3493 ha->serial1 = icb->port_name[6];
3494 ha->serial2 = icb->port_name[7];
3495 ha->node_name = icb->node_name;
3496 ha->port_name = icb->port_name;
3498 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3500 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3502 /* Set minimum login_timeout to 4 seconds. */
3503 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3504 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3505 if (le16_to_cpu(nv->login_timeout) < 4)
3506 nv->login_timeout = __constant_cpu_to_le16(4);
3507 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3508 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3510 /* Set minimum RATOV to 200 tenths of a second. */
3513 ha->loop_reset_delay = nv->reset_delay;
3515 /* Link Down Timeout = 0:
3517 * When Port Down timer expires we will start returning
3518 * I/O's to OS with "DID_NO_CONNECT".
3520 * Link Down Timeout != 0:
3522 * The driver waits for the link to come up after link down
3523 * before returning I/Os to OS with "DID_NO_CONNECT".
3525 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3526 ha->loop_down_abort_time =
3527 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3529 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3530 ha->loop_down_abort_time =
3531 (LOOP_DOWN_TIME - ha->link_down_timeout);
3534 /* Need enough time to try and get the port back. */
3535 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3536 if (qlport_down_retry)
3537 ha->port_down_retry_count = qlport_down_retry;
3539 /* Set login_retry_count */
3540 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3541 if (ha->port_down_retry_count ==
3542 le16_to_cpu(nv->port_down_retry_count) &&
3543 ha->port_down_retry_count > 3)
3544 ha->login_retry_count = ha->port_down_retry_count;
3545 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3546 ha->login_retry_count = ha->port_down_retry_count;
3547 if (ql2xloginretrycount)
3548 ha->login_retry_count = ql2xloginretrycount;
3551 if (!ha->flags.init_done) {
3552 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3553 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3554 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3555 le16_to_cpu(icb->interrupt_delay_timer): 2;
3557 icb->firmware_options_2 &= __constant_cpu_to_le32(
3558 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3559 ha->flags.process_response_queue = 0;
3560 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3561 ha->zio_mode = QLA_ZIO_MODE_6;
3563 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3564 "(%d us).\n", ha->host_no, ha->zio_mode,
3565 ha->zio_timer * 100));
3566 qla_printk(KERN_INFO, ha,
3567 "ZIO mode %d enabled; timer delay (%d us).\n",
3568 ha->zio_mode, ha->zio_timer * 100);
3570 icb->firmware_options_2 |= cpu_to_le32(
3571 (uint32_t)ha->zio_mode);
3572 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3573 ha->flags.process_response_queue = 1;
3577 DEBUG2_3(printk(KERN_WARNING
3578 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3584 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3587 int segments, fragment;
3589 uint32_t *dcode, dlen;
3596 segments = FA_RISC_CODE_SEGMENTS;
3597 faddr = FA_RISC_CODE_ADDR;
3598 dcode = (uint32_t *)ha->request_ring;
3601 /* Validate firmware image by checking version. */
3602 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3603 for (i = 0; i < 4; i++)
3604 dcode[i] = be32_to_cpu(dcode[i]);
3605 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3606 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3607 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3609 qla_printk(KERN_WARNING, ha,
3610 "Unable to verify integrity of flash firmware image!\n");
3611 qla_printk(KERN_WARNING, ha,
3612 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3613 dcode[1], dcode[2], dcode[3]);
3615 return QLA_FUNCTION_FAILED;
3618 while (segments && rval == QLA_SUCCESS) {
3619 /* Read segment's load information. */
3620 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3622 risc_addr = be32_to_cpu(dcode[2]);
3623 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3624 risc_size = be32_to_cpu(dcode[3]);
3627 while (risc_size > 0 && rval == QLA_SUCCESS) {
3628 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3629 if (dlen > risc_size)
3632 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3633 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3634 ha->host_no, risc_addr, dlen, faddr));
3636 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3637 for (i = 0; i < dlen; i++)
3638 dcode[i] = swab32(dcode[i]);
3640 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3643 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3644 "segment %d of firmware\n", ha->host_no,
3646 qla_printk(KERN_WARNING, ha,
3647 "[ERROR] Failed to load segment %d of "
3648 "firmware\n", fragment);
3665 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3668 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3672 uint16_t *wcode, *fwcode;
3673 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3674 struct fw_blob *blob;
3676 /* Load firmware blob. */
3677 blob = qla2x00_request_firmware(ha);
3679 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3680 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3681 "from: " QLA_FW_URL ".\n");
3682 return QLA_FUNCTION_FAILED;
3687 wcode = (uint16_t *)ha->request_ring;
3689 fwcode = (uint16_t *)blob->fw->data;
3692 /* Validate firmware image by checking version. */
3693 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3694 qla_printk(KERN_WARNING, ha,
3695 "Unable to verify integrity of firmware image (%Zd)!\n",
3697 goto fail_fw_integrity;
3699 for (i = 0; i < 4; i++)
3700 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3701 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3702 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3703 wcode[2] == 0 && wcode[3] == 0)) {
3704 qla_printk(KERN_WARNING, ha,
3705 "Unable to verify integrity of firmware image!\n");
3706 qla_printk(KERN_WARNING, ha,
3707 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3708 wcode[1], wcode[2], wcode[3]);
3709 goto fail_fw_integrity;
3713 while (*seg && rval == QLA_SUCCESS) {
3715 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3716 risc_size = be16_to_cpu(fwcode[3]);
3718 /* Validate firmware image size. */
3719 fwclen += risc_size * sizeof(uint16_t);
3720 if (blob->fw->size < fwclen) {
3721 qla_printk(KERN_WARNING, ha,
3722 "Unable to verify integrity of firmware image "
3723 "(%Zd)!\n", blob->fw->size);
3724 goto fail_fw_integrity;
3728 while (risc_size > 0 && rval == QLA_SUCCESS) {
3729 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3730 if (wlen > risc_size)
3733 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3734 "addr %x, number of words 0x%x.\n", ha->host_no,
3737 for (i = 0; i < wlen; i++)
3738 wcode[i] = swab16(fwcode[i]);
3740 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3743 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3744 "segment %d of firmware\n", ha->host_no,
3746 qla_printk(KERN_WARNING, ha,
3747 "[ERROR] Failed to load segment %d of "
3748 "firmware\n", fragment);
3764 return QLA_FUNCTION_FAILED;
3768 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3771 int segments, fragment;
3772 uint32_t *dcode, dlen;
3776 struct fw_blob *blob;
3777 uint32_t *fwcode, fwclen;
3779 /* Load firmware blob. */
3780 blob = qla2x00_request_firmware(ha);
3782 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3783 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3784 "from: " QLA_FW_URL ".\n");
3786 /* Try to load RISC code from flash. */
3787 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3788 "outdated) firmware from flash.\n");
3789 return qla24xx_load_risc_flash(ha, srisc_addr);
3794 segments = FA_RISC_CODE_SEGMENTS;
3795 dcode = (uint32_t *)ha->request_ring;
3797 fwcode = (uint32_t *)blob->fw->data;
3800 /* Validate firmware image by checking version. */
3801 if (blob->fw->size < 8 * sizeof(uint32_t)) {
3802 qla_printk(KERN_WARNING, ha,
3803 "Unable to verify integrity of firmware image (%Zd)!\n",
3805 goto fail_fw_integrity;
3807 for (i = 0; i < 4; i++)
3808 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3809 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3810 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3811 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3813 qla_printk(KERN_WARNING, ha,
3814 "Unable to verify integrity of firmware image!\n");
3815 qla_printk(KERN_WARNING, ha,
3816 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3817 dcode[1], dcode[2], dcode[3]);
3818 goto fail_fw_integrity;
3821 while (segments && rval == QLA_SUCCESS) {
3822 risc_addr = be32_to_cpu(fwcode[2]);
3823 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3824 risc_size = be32_to_cpu(fwcode[3]);
3826 /* Validate firmware image size. */
3827 fwclen += risc_size * sizeof(uint32_t);
3828 if (blob->fw->size < fwclen) {
3829 qla_printk(KERN_WARNING, ha,
3830 "Unable to verify integrity of firmware image "
3831 "(%Zd)!\n", blob->fw->size);
3833 goto fail_fw_integrity;
3837 while (risc_size > 0 && rval == QLA_SUCCESS) {
3838 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3839 if (dlen > risc_size)
3842 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3843 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3846 for (i = 0; i < dlen; i++)
3847 dcode[i] = swab32(fwcode[i]);
3849 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3852 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3853 "segment %d of firmware\n", ha->host_no,
3855 qla_printk(KERN_WARNING, ha,
3856 "[ERROR] Failed to load segment %d of "
3857 "firmware\n", fragment);
3873 return QLA_FUNCTION_FAILED;
3877 qla2x00_try_to_stop_firmware(scsi_qla_host_t *ha)
3881 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
3884 ret = qla2x00_stop_firmware(ha);
3885 for (retries = 5; ret != QLA_SUCCESS && retries ; retries--) {
3886 qla2x00_reset_chip(ha);
3887 if (qla2x00_chip_diag(ha) != QLA_SUCCESS)
3889 if (qla2x00_setup_chip(ha) != QLA_SUCCESS)
3891 qla_printk(KERN_INFO, ha,
3892 "Attempting retry of stop-firmware command...\n");
3893 ret = qla2x00_stop_firmware(ha);