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"
18 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
19 #ifndef EXT_IS_LUN_BIT_SET
20 #define EXT_IS_LUN_BIT_SET(P,L) \
21 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
22 #define EXT_SET_LUN_BIT(P,L) \
23 ((P)->mask[L/8] |= (0x80 >> (L%8)))
27 * QLogic ISP2x00 Hardware Support Function Prototypes.
29 static int qla2x00_isp_firmware(scsi_qla_host_t *);
30 static void qla2x00_resize_request_q(scsi_qla_host_t *);
31 static int qla2x00_setup_chip(scsi_qla_host_t *);
32 static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
33 static int qla2x00_init_rings(scsi_qla_host_t *);
34 static int qla2x00_fw_ready(scsi_qla_host_t *);
35 static int qla2x00_configure_hba(scsi_qla_host_t *);
36 static int qla2x00_configure_loop(scsi_qla_host_t *);
37 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
38 static int qla2x00_configure_fabric(scsi_qla_host_t *);
39 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
40 static int qla2x00_device_resync(scsi_qla_host_t *);
41 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
44 static int qla2x00_restart_isp(scsi_qla_host_t *);
46 static int qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev);
48 /****************************************************************************/
49 /* QLogic ISP2x00 Hardware Support Functions. */
50 /****************************************************************************/
53 * qla2x00_initialize_adapter
57 * ha = adapter block pointer.
63 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
67 /* Clear adapter flags. */
69 ha->flags.reset_active = 0;
70 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
71 atomic_set(&ha->loop_state, LOOP_DOWN);
72 ha->device_flags = DFLG_NO_CABLE;
74 ha->flags.management_server_logged_in = 0;
75 ha->marker_needed = 0;
77 ha->isp_abort_cnt = 0;
78 ha->beacon_blink_led = 0;
79 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
81 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
82 rval = ha->isp_ops.pci_config(ha);
84 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
89 ha->isp_ops.reset_chip(ha);
91 ha->isp_ops.get_flash_version(ha, ha->request_ring);
93 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
95 ha->isp_ops.nvram_config(ha);
97 if (ha->flags.disable_serdes) {
98 /* Mask HBA via NVRAM settings? */
99 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
100 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
101 ha->port_name[0], ha->port_name[1],
102 ha->port_name[2], ha->port_name[3],
103 ha->port_name[4], ha->port_name[5],
104 ha->port_name[6], ha->port_name[7]);
105 return QLA_FUNCTION_FAILED;
108 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
110 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
111 rval = ha->isp_ops.chip_diag(ha);
114 rval = qla2x00_setup_chip(ha);
118 rval = qla2x00_init_rings(ha);
124 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
127 * Returns 0 on success.
130 qla2100_pci_config(scsi_qla_host_t *ha)
136 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
138 pci_set_master(ha->pdev);
139 ret = pci_set_mwi(ha->pdev);
141 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
142 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
143 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
145 /* Reset expansion ROM address decode enable */
146 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
147 d &= ~PCI_ROM_ADDRESS_ENABLE;
148 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
150 /* Get PCI bus information. */
151 spin_lock_irqsave(&ha->hardware_lock, flags);
152 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
153 spin_unlock_irqrestore(&ha->hardware_lock, flags);
159 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
162 * Returns 0 on success.
165 qla2300_pci_config(scsi_qla_host_t *ha)
170 unsigned long flags = 0;
172 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
174 pci_set_master(ha->pdev);
175 ret = pci_set_mwi(ha->pdev);
177 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
178 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
180 if (IS_QLA2322(ha) || IS_QLA6322(ha))
181 w &= ~PCI_COMMAND_INTX_DISABLE;
182 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
185 * If this is a 2300 card and not 2312, reset the
186 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
187 * the 2310 also reports itself as a 2300 so we need to get the
188 * fb revision level -- a 6 indicates it really is a 2300 and
191 if (IS_QLA2300(ha)) {
192 spin_lock_irqsave(&ha->hardware_lock, flags);
195 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
196 for (cnt = 0; cnt < 30000; cnt++) {
197 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
203 /* Select FPM registers. */
204 WRT_REG_WORD(®->ctrl_status, 0x20);
205 RD_REG_WORD(®->ctrl_status);
207 /* Get the fb rev level */
208 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
210 if (ha->fb_rev == FPM_2300)
211 pci_clear_mwi(ha->pdev);
213 /* Deselect FPM registers. */
214 WRT_REG_WORD(®->ctrl_status, 0x0);
215 RD_REG_WORD(®->ctrl_status);
217 /* Release RISC module. */
218 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
219 for (cnt = 0; cnt < 30000; cnt++) {
220 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
226 spin_unlock_irqrestore(&ha->hardware_lock, flags);
229 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
231 /* Reset expansion ROM address decode enable */
232 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
233 d &= ~PCI_ROM_ADDRESS_ENABLE;
234 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
236 /* Get PCI bus information. */
237 spin_lock_irqsave(&ha->hardware_lock, flags);
238 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
239 spin_unlock_irqrestore(&ha->hardware_lock, flags);
245 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
248 * Returns 0 on success.
251 qla24xx_pci_config(scsi_qla_host_t *ha)
256 unsigned long flags = 0;
257 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
258 int pcix_cmd_reg, pcie_dctl_reg;
260 pci_set_master(ha->pdev);
261 ret = pci_set_mwi(ha->pdev);
263 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
264 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
265 w &= ~PCI_COMMAND_INTX_DISABLE;
266 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
268 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
270 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
271 pcix_cmd_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX);
275 pcix_cmd_reg += PCI_X_CMD;
276 pci_read_config_word(ha->pdev, pcix_cmd_reg, &pcix_cmd);
277 pcix_cmd &= ~PCI_X_CMD_MAX_READ;
279 pci_write_config_word(ha->pdev, pcix_cmd_reg, pcix_cmd);
282 /* PCIe -- adjust Maximum Read Request Size (2048). */
283 pcie_dctl_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
287 pcie_dctl_reg += PCI_EXP_DEVCTL;
288 pci_read_config_word(ha->pdev, pcie_dctl_reg, &pcie_dctl);
289 pcie_dctl &= ~PCI_EXP_DEVCTL_READRQ;
291 pci_write_config_word(ha->pdev, pcie_dctl_reg, pcie_dctl);
294 /* Reset expansion ROM address decode enable */
295 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
296 d &= ~PCI_ROM_ADDRESS_ENABLE;
297 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
299 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->chip_revision);
301 /* Get PCI bus information. */
302 spin_lock_irqsave(&ha->hardware_lock, flags);
303 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
304 spin_unlock_irqrestore(&ha->hardware_lock, flags);
310 * qla2x00_isp_firmware() - Choose firmware image.
313 * Returns 0 on success.
316 qla2x00_isp_firmware(scsi_qla_host_t *ha)
320 /* Assume loading risc code */
321 rval = QLA_FUNCTION_FAILED;
323 if (ha->flags.disable_risc_code_load) {
324 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
326 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
328 /* Verify checksum of loaded RISC code. */
329 rval = qla2x00_verify_checksum(ha, ha->fw_srisc_address);
333 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
341 * qla2x00_reset_chip() - Reset ISP chip.
344 * Returns 0 on success.
347 qla2x00_reset_chip(scsi_qla_host_t *ha)
349 unsigned long flags = 0;
350 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
354 ha->isp_ops.disable_intrs(ha);
356 spin_lock_irqsave(&ha->hardware_lock, flags);
358 /* Turn off master enable */
360 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
361 cmd &= ~PCI_COMMAND_MASTER;
362 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
364 if (!IS_QLA2100(ha)) {
366 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
367 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
368 for (cnt = 0; cnt < 30000; cnt++) {
369 if ((RD_REG_WORD(®->hccr) &
370 HCCR_RISC_PAUSE) != 0)
375 RD_REG_WORD(®->hccr); /* PCI Posting. */
379 /* Select FPM registers. */
380 WRT_REG_WORD(®->ctrl_status, 0x20);
381 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
383 /* FPM Soft Reset. */
384 WRT_REG_WORD(®->fpm_diag_config, 0x100);
385 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
387 /* Toggle Fpm Reset. */
388 if (!IS_QLA2200(ha)) {
389 WRT_REG_WORD(®->fpm_diag_config, 0x0);
390 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
393 /* Select frame buffer registers. */
394 WRT_REG_WORD(®->ctrl_status, 0x10);
395 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
397 /* Reset frame buffer FIFOs. */
398 if (IS_QLA2200(ha)) {
399 WRT_FB_CMD_REG(ha, reg, 0xa000);
400 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
402 WRT_FB_CMD_REG(ha, reg, 0x00fc);
404 /* Read back fb_cmd until zero or 3 seconds max */
405 for (cnt = 0; cnt < 3000; cnt++) {
406 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
412 /* Select RISC module registers. */
413 WRT_REG_WORD(®->ctrl_status, 0);
414 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
416 /* Reset RISC processor. */
417 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
418 RD_REG_WORD(®->hccr); /* PCI Posting. */
420 /* Release RISC processor. */
421 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
422 RD_REG_WORD(®->hccr); /* PCI Posting. */
425 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
426 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
428 /* Reset ISP chip. */
429 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
431 /* Wait for RISC to recover from reset. */
432 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
434 * It is necessary to for a delay here since the card doesn't
435 * respond to PCI reads during a reset. On some architectures
436 * this will result in an MCA.
439 for (cnt = 30000; cnt; cnt--) {
440 if ((RD_REG_WORD(®->ctrl_status) &
441 CSR_ISP_SOFT_RESET) == 0)
448 /* Reset RISC processor. */
449 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
451 WRT_REG_WORD(®->semaphore, 0);
453 /* Release RISC processor. */
454 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
455 RD_REG_WORD(®->hccr); /* PCI Posting. */
457 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
458 for (cnt = 0; cnt < 30000; cnt++) {
459 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
467 /* Turn on master enable */
468 cmd |= PCI_COMMAND_MASTER;
469 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
471 /* Disable RISC pause on FPM parity error. */
472 if (!IS_QLA2100(ha)) {
473 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
474 RD_REG_WORD(®->hccr); /* PCI Posting. */
477 spin_unlock_irqrestore(&ha->hardware_lock, flags);
481 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
484 * Returns 0 on success.
487 qla24xx_reset_risc(scsi_qla_host_t *ha)
489 unsigned long flags = 0;
490 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
494 spin_lock_irqsave(&ha->hardware_lock, flags);
497 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
498 for (cnt = 0; cnt < 30000; cnt++) {
499 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
505 WRT_REG_DWORD(®->ctrl_status,
506 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
507 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
510 /* Wait for firmware to complete NVRAM accesses. */
511 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
512 for (cnt = 10000 ; cnt && d2; cnt--) {
514 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
518 /* Wait for soft-reset to complete. */
519 d2 = RD_REG_DWORD(®->ctrl_status);
520 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
522 d2 = RD_REG_DWORD(®->ctrl_status);
526 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
527 RD_REG_DWORD(®->hccr);
529 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
530 RD_REG_DWORD(®->hccr);
532 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
533 RD_REG_DWORD(®->hccr);
535 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
536 for (cnt = 6000000 ; cnt && d2; cnt--) {
538 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
542 spin_unlock_irqrestore(&ha->hardware_lock, flags);
546 * qla24xx_reset_chip() - Reset ISP24xx chip.
549 * Returns 0 on success.
552 qla24xx_reset_chip(scsi_qla_host_t *ha)
554 ha->isp_ops.disable_intrs(ha);
556 /* Perform RISC reset. */
557 qla24xx_reset_risc(ha);
561 * qla2x00_chip_diag() - Test chip for proper operation.
564 * Returns 0 on success.
567 qla2x00_chip_diag(scsi_qla_host_t *ha)
570 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
571 unsigned long flags = 0;
576 /* Assume a failed state */
577 rval = QLA_FUNCTION_FAILED;
579 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
580 ha->host_no, (u_long)®->flash_address));
582 spin_lock_irqsave(&ha->hardware_lock, flags);
584 /* Reset ISP chip. */
585 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
588 * We need to have a delay here since the card will not respond while
589 * in reset causing an MCA on some architectures.
592 data = qla2x00_debounce_register(®->ctrl_status);
593 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
595 data = RD_REG_WORD(®->ctrl_status);
600 goto chip_diag_failed;
602 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
605 /* Reset RISC processor. */
606 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
607 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
609 /* Workaround for QLA2312 PCI parity error */
610 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
611 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
612 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
614 data = RD_MAILBOX_REG(ha, reg, 0);
621 goto chip_diag_failed;
623 /* Check product ID of chip */
624 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
626 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
627 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
628 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
629 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
630 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
631 mb[3] != PROD_ID_3) {
632 qla_printk(KERN_WARNING, ha,
633 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
635 goto chip_diag_failed;
637 ha->product_id[0] = mb[1];
638 ha->product_id[1] = mb[2];
639 ha->product_id[2] = mb[3];
640 ha->product_id[3] = mb[4];
642 /* Adjust fw RISC transfer size */
643 if (ha->request_q_length > 1024)
644 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
646 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
647 ha->request_q_length;
649 if (IS_QLA2200(ha) &&
650 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
651 /* Limit firmware transfer size with a 2200A */
652 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
655 ha->device_type |= DT_ISP2200A;
656 ha->fw_transfer_size = 128;
659 /* Wrap Incoming Mailboxes Test. */
660 spin_unlock_irqrestore(&ha->hardware_lock, flags);
662 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
663 rval = qla2x00_mbx_reg_test(ha);
665 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
667 qla_printk(KERN_WARNING, ha,
668 "Failed mailbox send register test\n");
671 /* Flag a successful rval */
674 spin_lock_irqsave(&ha->hardware_lock, flags);
678 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
679 "****\n", ha->host_no));
681 spin_unlock_irqrestore(&ha->hardware_lock, flags);
687 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
690 * Returns 0 on success.
693 qla24xx_chip_diag(scsi_qla_host_t *ha)
697 /* Perform RISC reset. */
698 qla24xx_reset_risc(ha);
700 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
702 rval = qla2x00_mbx_reg_test(ha);
704 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
706 qla_printk(KERN_WARNING, ha,
707 "Failed mailbox send register test\n");
709 /* Flag a successful rval */
717 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
720 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
726 qla_printk(KERN_WARNING, ha,
727 "Firmware dump previously allocated.\n");
732 fixed_size = mem_size = eft_size = 0;
733 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
734 fixed_size = sizeof(struct qla2100_fw_dump);
735 } else if (IS_QLA23XX(ha)) {
736 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
737 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
739 } else if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
740 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
741 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
744 /* Allocate memory for Extended Trace Buffer. */
745 eft = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &eft_dma,
748 qla_printk(KERN_WARNING, ha, "Unable to allocate "
749 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
753 rval = qla2x00_trace_control(ha, TC_ENABLE, eft_dma,
756 qla_printk(KERN_WARNING, ha, "Unable to initialize "
757 "EFT (%d).\n", rval);
758 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, eft,
763 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
767 memset(eft, 0, eft_size);
768 ha->eft_dma = eft_dma;
772 req_q_size = ha->request_q_length * sizeof(request_t);
773 rsp_q_size = ha->response_q_length * sizeof(response_t);
775 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
776 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
779 ha->fw_dump = vmalloc(dump_size);
781 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
782 "firmware dump!!!\n", dump_size / 1024);
785 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
793 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
796 ha->fw_dump_len = dump_size;
797 ha->fw_dump->signature[0] = 'Q';
798 ha->fw_dump->signature[1] = 'L';
799 ha->fw_dump->signature[2] = 'G';
800 ha->fw_dump->signature[3] = 'C';
801 ha->fw_dump->version = __constant_htonl(1);
803 ha->fw_dump->fixed_size = htonl(fixed_size);
804 ha->fw_dump->mem_size = htonl(mem_size);
805 ha->fw_dump->req_q_size = htonl(req_q_size);
806 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
808 ha->fw_dump->eft_size = htonl(eft_size);
809 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
810 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
812 ha->fw_dump->header_size =
813 htonl(offsetof(struct qla2xxx_fw_dump, isp));
817 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
820 * Returns 0 on success.
823 qla2x00_resize_request_q(scsi_qla_host_t *ha)
826 uint16_t fw_iocb_cnt = 0;
827 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
828 dma_addr_t request_dma;
829 request_t *request_ring;
831 /* Valid only on recent ISPs. */
832 if (IS_QLA2100(ha) || IS_QLA2200(ha))
835 /* Retrieve IOCB counts available to the firmware. */
836 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
839 /* No point in continuing if current settings are sufficient. */
840 if (fw_iocb_cnt < 1024)
842 if (ha->request_q_length >= request_q_length)
845 /* Attempt to claim larger area for request queue. */
846 request_ring = dma_alloc_coherent(&ha->pdev->dev,
847 (request_q_length + 1) * sizeof(request_t), &request_dma,
849 if (request_ring == NULL)
852 /* Resize successful, report extensions. */
853 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
854 (ha->fw_memory_size + 1) / 1024);
855 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
856 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
858 /* Clear old allocations. */
859 dma_free_coherent(&ha->pdev->dev,
860 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
863 /* Begin using larger queue. */
864 ha->request_q_length = request_q_length;
865 ha->request_ring = request_ring;
866 ha->request_dma = request_dma;
870 * qla2x00_setup_chip() - Load and start RISC firmware.
873 * Returns 0 on success.
876 qla2x00_setup_chip(scsi_qla_host_t *ha)
879 uint32_t srisc_address = 0;
881 /* Load firmware sequences */
882 rval = ha->isp_ops.load_risc(ha, &srisc_address);
883 if (rval == QLA_SUCCESS) {
884 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
885 "code.\n", ha->host_no));
887 rval = qla2x00_verify_checksum(ha, srisc_address);
888 if (rval == QLA_SUCCESS) {
889 /* Start firmware execution. */
890 DEBUG(printk("scsi(%ld): Checksum OK, start "
891 "firmware.\n", ha->host_no));
893 rval = qla2x00_execute_fw(ha, srisc_address);
894 /* Retrieve firmware information. */
895 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
896 qla2x00_get_fw_version(ha,
897 &ha->fw_major_version,
898 &ha->fw_minor_version,
899 &ha->fw_subminor_version,
900 &ha->fw_attributes, &ha->fw_memory_size);
901 qla2x00_resize_request_q(ha);
904 qla2x00_alloc_fw_dump(ha);
907 DEBUG2(printk(KERN_INFO
908 "scsi(%ld): ISP Firmware failed checksum.\n",
914 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
922 * qla2x00_init_response_q_entries() - Initializes response queue entries.
925 * Beginning of request ring has initialization control block already built
926 * by nvram config routine.
928 * Returns 0 on success.
931 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
936 pkt = ha->response_ring_ptr;
937 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
938 pkt->signature = RESPONSE_PROCESSED;
945 * qla2x00_update_fw_options() - Read and process firmware options.
948 * Returns 0 on success.
951 qla2x00_update_fw_options(scsi_qla_host_t *ha)
953 uint16_t swing, emphasis, tx_sens, rx_sens;
955 memset(ha->fw_options, 0, sizeof(ha->fw_options));
956 qla2x00_get_fw_options(ha, ha->fw_options);
958 if (IS_QLA2100(ha) || IS_QLA2200(ha))
961 /* Serial Link options. */
962 DEBUG3(printk("scsi(%ld): Serial link options:\n",
964 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
965 sizeof(ha->fw_seriallink_options)));
967 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
968 if (ha->fw_seriallink_options[3] & BIT_2) {
969 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
972 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
973 emphasis = (ha->fw_seriallink_options[2] &
974 (BIT_4 | BIT_3)) >> 3;
975 tx_sens = ha->fw_seriallink_options[0] &
976 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
977 rx_sens = (ha->fw_seriallink_options[0] &
978 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
979 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
980 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
983 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
984 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
985 ha->fw_options[10] |= BIT_5 |
986 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
987 (tx_sens & (BIT_1 | BIT_0));
990 swing = (ha->fw_seriallink_options[2] &
991 (BIT_7 | BIT_6 | BIT_5)) >> 5;
992 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
993 tx_sens = ha->fw_seriallink_options[1] &
994 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
995 rx_sens = (ha->fw_seriallink_options[1] &
996 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
997 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
998 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1001 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1002 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1003 ha->fw_options[11] |= BIT_5 |
1004 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1005 (tx_sens & (BIT_1 | BIT_0));
1009 /* Return command IOCBs without waiting for an ABTS to complete. */
1010 ha->fw_options[3] |= BIT_13;
1013 if (ha->flags.enable_led_scheme)
1014 ha->fw_options[2] |= BIT_12;
1016 /* Detect ISP6312. */
1018 ha->fw_options[2] |= BIT_13;
1020 /* Update firmware options. */
1021 qla2x00_set_fw_options(ha, ha->fw_options);
1025 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1029 /* Update Serial Link options. */
1030 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1033 rval = qla2x00_set_serdes_params(ha,
1034 le16_to_cpu(ha->fw_seriallink_options24[1]),
1035 le16_to_cpu(ha->fw_seriallink_options24[2]),
1036 le16_to_cpu(ha->fw_seriallink_options24[3]));
1037 if (rval != QLA_SUCCESS) {
1038 qla_printk(KERN_WARNING, ha,
1039 "Unable to update Serial Link options (%x).\n", rval);
1044 qla2x00_config_rings(struct scsi_qla_host *ha)
1046 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1048 /* Setup ring parameters in initialization control block. */
1049 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1050 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1051 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1052 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1053 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1054 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1055 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1056 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1058 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1059 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1060 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1061 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1062 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1066 qla24xx_config_rings(struct scsi_qla_host *ha)
1068 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1069 struct init_cb_24xx *icb;
1071 /* Setup ring parameters in initialization control block. */
1072 icb = (struct init_cb_24xx *)ha->init_cb;
1073 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1074 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1075 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1076 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1077 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1078 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1079 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1080 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1082 WRT_REG_DWORD(®->req_q_in, 0);
1083 WRT_REG_DWORD(®->req_q_out, 0);
1084 WRT_REG_DWORD(®->rsp_q_in, 0);
1085 WRT_REG_DWORD(®->rsp_q_out, 0);
1086 RD_REG_DWORD(®->rsp_q_out);
1090 * qla2x00_init_rings() - Initializes firmware.
1093 * Beginning of request ring has initialization control block already built
1094 * by nvram config routine.
1096 * Returns 0 on success.
1099 qla2x00_init_rings(scsi_qla_host_t *ha)
1102 unsigned long flags = 0;
1105 spin_lock_irqsave(&ha->hardware_lock, flags);
1107 /* Clear outstanding commands array. */
1108 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1109 ha->outstanding_cmds[cnt] = NULL;
1111 ha->current_outstanding_cmd = 0;
1113 /* Clear RSCN queue. */
1114 ha->rscn_in_ptr = 0;
1115 ha->rscn_out_ptr = 0;
1117 /* Initialize firmware. */
1118 ha->request_ring_ptr = ha->request_ring;
1119 ha->req_ring_index = 0;
1120 ha->req_q_cnt = ha->request_q_length;
1121 ha->response_ring_ptr = ha->response_ring;
1122 ha->rsp_ring_index = 0;
1124 /* Initialize response queue entries */
1125 qla2x00_init_response_q_entries(ha);
1127 ha->isp_ops.config_rings(ha);
1129 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1131 /* Update any ISP specific firmware options before initialization. */
1132 ha->isp_ops.update_fw_options(ha);
1134 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1135 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1137 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1140 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1148 * qla2x00_fw_ready() - Waits for firmware ready.
1151 * Returns 0 on success.
1154 qla2x00_fw_ready(scsi_qla_host_t *ha)
1157 unsigned long wtime, mtime;
1158 uint16_t min_wait; /* Minimum wait time if loop is down */
1159 uint16_t wait_time; /* Wait time if loop is coming ready */
1164 /* 20 seconds for loop down. */
1168 * Firmware should take at most one RATOV to login, plus 5 seconds for
1169 * our own processing.
1171 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1172 wait_time = min_wait;
1175 /* Min wait time if loop down */
1176 mtime = jiffies + (min_wait * HZ);
1178 /* wait time before firmware ready */
1179 wtime = jiffies + (wait_time * HZ);
1181 /* Wait for ISP to finish LIP */
1182 if (!ha->flags.init_done)
1183 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1185 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1189 rval = qla2x00_get_firmware_state(ha, &fw_state);
1190 if (rval == QLA_SUCCESS) {
1191 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1192 ha->device_flags &= ~DFLG_NO_CABLE;
1194 if (fw_state == FSTATE_READY) {
1195 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1198 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1199 &ha->login_timeout, &ha->r_a_tov);
1205 rval = QLA_FUNCTION_FAILED;
1207 if (atomic_read(&ha->loop_down_timer) &&
1208 fw_state != FSTATE_READY) {
1209 /* Loop down. Timeout on min_wait for states
1210 * other than Wait for Login.
1212 if (time_after_eq(jiffies, mtime)) {
1213 qla_printk(KERN_INFO, ha,
1214 "Cable is unplugged...\n");
1216 ha->device_flags |= DFLG_NO_CABLE;
1221 /* Mailbox cmd failed. Timeout on min_wait. */
1222 if (time_after_eq(jiffies, mtime))
1226 if (time_after_eq(jiffies, wtime))
1229 /* Delay for a while */
1232 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1233 ha->host_no, fw_state, jiffies));
1236 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1237 ha->host_no, fw_state, jiffies));
1240 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1248 * qla2x00_configure_hba
1249 * Setup adapter context.
1252 * ha = adapter state pointer.
1261 qla2x00_configure_hba(scsi_qla_host_t *ha)
1269 char connect_type[22];
1271 /* Get host addresses. */
1272 rval = qla2x00_get_adapter_id(ha,
1273 &loop_id, &al_pa, &area, &domain, &topo);
1274 if (rval != QLA_SUCCESS) {
1275 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
1276 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1277 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1278 __func__, ha->host_no));
1280 qla_printk(KERN_WARNING, ha,
1281 "ERROR -- Unable to get host loop ID.\n");
1282 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1288 qla_printk(KERN_INFO, ha,
1289 "Cannot get topology - retrying.\n");
1290 return (QLA_FUNCTION_FAILED);
1293 ha->loop_id = loop_id;
1296 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1297 ha->operating_mode = LOOP;
1301 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1303 ha->current_topology = ISP_CFG_NL;
1304 strcpy(connect_type, "(Loop)");
1308 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1310 ha->current_topology = ISP_CFG_FL;
1311 strcpy(connect_type, "(FL_Port)");
1315 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1317 ha->operating_mode = P2P;
1318 ha->current_topology = ISP_CFG_N;
1319 strcpy(connect_type, "(N_Port-to-N_Port)");
1323 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1325 ha->operating_mode = P2P;
1326 ha->current_topology = ISP_CFG_F;
1327 strcpy(connect_type, "(F_Port)");
1331 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1333 ha->host_no, topo));
1334 ha->current_topology = ISP_CFG_NL;
1335 strcpy(connect_type, "(Loop)");
1339 /* Save Host port and loop ID. */
1340 /* byte order - Big Endian */
1341 ha->d_id.b.domain = domain;
1342 ha->d_id.b.area = area;
1343 ha->d_id.b.al_pa = al_pa;
1345 if (!ha->flags.init_done)
1346 qla_printk(KERN_INFO, ha,
1347 "Topology - %s, Host Loop address 0x%x\n",
1348 connect_type, ha->loop_id);
1351 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1353 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1360 qla2x00_set_model_info(scsi_qla_host_t *ha, uint8_t *model, size_t len, char *def)
1365 if (memcmp(model, BINZERO, len) != 0) {
1366 strncpy(ha->model_number, model, len);
1367 st = en = ha->model_number;
1370 if (*en != 0x20 && *en != 0x00)
1375 index = (ha->pdev->subsystem_device & 0xff);
1376 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1377 index < QLA_MODEL_NAMES)
1378 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1380 index = (ha->pdev->subsystem_device & 0xff);
1381 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1382 index < QLA_MODEL_NAMES) {
1383 strcpy(ha->model_number,
1384 qla2x00_model_name[index * 2]);
1385 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1387 strcpy(ha->model_number, def);
1392 /* On sparc systems, obtain port and node WWN from firmware
1395 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, nvram_t *nv)
1398 struct pci_dev *pdev = ha->pdev;
1399 struct device_node *dp = pci_device_to_OF_node(pdev);
1403 val = of_get_property(dp, "port-wwn", &len);
1404 if (val && len >= WWN_SIZE)
1405 memcpy(nv->port_name, val, WWN_SIZE);
1407 val = of_get_property(dp, "node-wwn", &len);
1408 if (val && len >= WWN_SIZE)
1409 memcpy(nv->node_name, val, WWN_SIZE);
1414 * NVRAM configuration for ISP 2xxx
1417 * ha = adapter block pointer.
1420 * initialization control block in response_ring
1421 * host adapters parameters in host adapter block
1427 qla2x00_nvram_config(scsi_qla_host_t *ha)
1432 uint8_t *dptr1, *dptr2;
1433 init_cb_t *icb = ha->init_cb;
1434 nvram_t *nv = (nvram_t *)ha->request_ring;
1435 uint8_t *ptr = (uint8_t *)ha->request_ring;
1436 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1440 /* Determine NVRAM starting address. */
1441 ha->nvram_size = sizeof(nvram_t);
1443 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1444 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1445 ha->nvram_base = 0x80;
1447 /* Get NVRAM data and calculate checksum. */
1448 ha->isp_ops.read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1449 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1452 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1453 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1456 /* Bad NVRAM data, set defaults parameters. */
1457 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1458 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1459 /* Reset NVRAM data. */
1460 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1461 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1463 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1464 "invalid -- WWPN) defaults.\n");
1467 * Set default initialization control block.
1469 memset(nv, 0, ha->nvram_size);
1470 nv->parameter_block_version = ICB_VERSION;
1472 if (IS_QLA23XX(ha)) {
1473 nv->firmware_options[0] = BIT_2 | BIT_1;
1474 nv->firmware_options[1] = BIT_7 | BIT_5;
1475 nv->add_firmware_options[0] = BIT_5;
1476 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1477 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1478 nv->special_options[1] = BIT_7;
1479 } else if (IS_QLA2200(ha)) {
1480 nv->firmware_options[0] = BIT_2 | BIT_1;
1481 nv->firmware_options[1] = BIT_7 | BIT_5;
1482 nv->add_firmware_options[0] = BIT_5;
1483 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1484 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1485 } else if (IS_QLA2100(ha)) {
1486 nv->firmware_options[0] = BIT_3 | BIT_1;
1487 nv->firmware_options[1] = BIT_5;
1488 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1491 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1492 nv->execution_throttle = __constant_cpu_to_le16(16);
1493 nv->retry_count = 8;
1494 nv->retry_delay = 1;
1496 nv->port_name[0] = 33;
1497 nv->port_name[3] = 224;
1498 nv->port_name[4] = 139;
1500 qla2xxx_nvram_wwn_from_ofw(ha, nv);
1502 nv->login_timeout = 4;
1505 * Set default host adapter parameters
1507 nv->host_p[1] = BIT_2;
1508 nv->reset_delay = 5;
1509 nv->port_down_retry_count = 8;
1510 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1511 nv->link_down_timeout = 60;
1516 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1518 * The SN2 does not provide BIOS emulation which means you can't change
1519 * potentially bogus BIOS settings. Force the use of default settings
1520 * for link rate and frame size. Hope that the rest of the settings
1523 if (ia64_platform_is("sn2")) {
1524 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1526 nv->special_options[1] = BIT_7;
1530 /* Reset Initialization control block */
1531 memset(icb, 0, ha->init_cb_size);
1534 * Setup driver NVRAM options.
1536 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1537 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1538 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1539 nv->firmware_options[1] &= ~BIT_4;
1541 if (IS_QLA23XX(ha)) {
1542 nv->firmware_options[0] |= BIT_2;
1543 nv->firmware_options[0] &= ~BIT_3;
1544 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1546 if (IS_QLA2300(ha)) {
1547 if (ha->fb_rev == FPM_2310) {
1548 strcpy(ha->model_number, "QLA2310");
1550 strcpy(ha->model_number, "QLA2300");
1553 qla2x00_set_model_info(ha, nv->model_number,
1554 sizeof(nv->model_number), "QLA23xx");
1556 } else if (IS_QLA2200(ha)) {
1557 nv->firmware_options[0] |= BIT_2;
1559 * 'Point-to-point preferred, else loop' is not a safe
1560 * connection mode setting.
1562 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1564 /* Force 'loop preferred, else point-to-point'. */
1565 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1566 nv->add_firmware_options[0] |= BIT_5;
1568 strcpy(ha->model_number, "QLA22xx");
1569 } else /*if (IS_QLA2100(ha))*/ {
1570 strcpy(ha->model_number, "QLA2100");
1574 * Copy over NVRAM RISC parameter block to initialization control block.
1576 dptr1 = (uint8_t *)icb;
1577 dptr2 = (uint8_t *)&nv->parameter_block_version;
1578 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1580 *dptr1++ = *dptr2++;
1582 /* Copy 2nd half. */
1583 dptr1 = (uint8_t *)icb->add_firmware_options;
1584 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1586 *dptr1++ = *dptr2++;
1588 /* Use alternate WWN? */
1589 if (nv->host_p[1] & BIT_7) {
1590 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1591 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1594 /* Prepare nodename */
1595 if ((icb->firmware_options[1] & BIT_6) == 0) {
1597 * Firmware will apply the following mask if the nodename was
1600 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1601 icb->node_name[0] &= 0xF0;
1605 * Set host adapter parameters.
1607 if (nv->host_p[0] & BIT_7)
1608 ql2xextended_error_logging = 1;
1609 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1610 /* Always load RISC code on non ISP2[12]00 chips. */
1611 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1612 ha->flags.disable_risc_code_load = 0;
1613 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1614 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1615 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1616 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1617 ha->flags.disable_serdes = 0;
1619 ha->operating_mode =
1620 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1622 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1623 sizeof(ha->fw_seriallink_options));
1625 /* save HBA serial number */
1626 ha->serial0 = icb->port_name[5];
1627 ha->serial1 = icb->port_name[6];
1628 ha->serial2 = icb->port_name[7];
1629 ha->node_name = icb->node_name;
1630 ha->port_name = icb->port_name;
1632 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1634 ha->retry_count = nv->retry_count;
1636 /* Set minimum login_timeout to 4 seconds. */
1637 if (nv->login_timeout < ql2xlogintimeout)
1638 nv->login_timeout = ql2xlogintimeout;
1639 if (nv->login_timeout < 4)
1640 nv->login_timeout = 4;
1641 ha->login_timeout = nv->login_timeout;
1642 icb->login_timeout = nv->login_timeout;
1644 /* Set minimum RATOV to 200 tenths of a second. */
1647 ha->loop_reset_delay = nv->reset_delay;
1649 /* Link Down Timeout = 0:
1651 * When Port Down timer expires we will start returning
1652 * I/O's to OS with "DID_NO_CONNECT".
1654 * Link Down Timeout != 0:
1656 * The driver waits for the link to come up after link down
1657 * before returning I/Os to OS with "DID_NO_CONNECT".
1659 if (nv->link_down_timeout == 0) {
1660 ha->loop_down_abort_time =
1661 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1663 ha->link_down_timeout = nv->link_down_timeout;
1664 ha->loop_down_abort_time =
1665 (LOOP_DOWN_TIME - ha->link_down_timeout);
1669 * Need enough time to try and get the port back.
1671 ha->port_down_retry_count = nv->port_down_retry_count;
1672 if (qlport_down_retry)
1673 ha->port_down_retry_count = qlport_down_retry;
1674 /* Set login_retry_count */
1675 ha->login_retry_count = nv->retry_count;
1676 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1677 ha->port_down_retry_count > 3)
1678 ha->login_retry_count = ha->port_down_retry_count;
1679 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1680 ha->login_retry_count = ha->port_down_retry_count;
1681 if (ql2xloginretrycount)
1682 ha->login_retry_count = ql2xloginretrycount;
1684 icb->lun_enables = __constant_cpu_to_le16(0);
1685 icb->command_resource_count = 0;
1686 icb->immediate_notify_resource_count = 0;
1687 icb->timeout = __constant_cpu_to_le16(0);
1689 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1691 icb->firmware_options[0] &= ~BIT_3;
1692 icb->add_firmware_options[0] &=
1693 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1694 icb->add_firmware_options[0] |= BIT_2;
1695 icb->response_accumulation_timer = 3;
1696 icb->interrupt_delay_timer = 5;
1698 ha->flags.process_response_queue = 1;
1701 if (!ha->flags.init_done) {
1702 ha->zio_mode = icb->add_firmware_options[0] &
1703 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1704 ha->zio_timer = icb->interrupt_delay_timer ?
1705 icb->interrupt_delay_timer: 2;
1707 icb->add_firmware_options[0] &=
1708 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1709 ha->flags.process_response_queue = 0;
1710 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1711 ha->zio_mode = QLA_ZIO_MODE_6;
1713 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1714 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1715 ha->zio_timer * 100));
1716 qla_printk(KERN_INFO, ha,
1717 "ZIO mode %d enabled; timer delay (%d us).\n",
1718 ha->zio_mode, ha->zio_timer * 100);
1720 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1721 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1722 ha->flags.process_response_queue = 1;
1727 DEBUG2_3(printk(KERN_WARNING
1728 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1734 qla2x00_rport_del(void *data)
1736 fc_port_t *fcport = data;
1737 struct fc_rport *rport;
1738 unsigned long flags;
1740 spin_lock_irqsave(&fcport->rport_lock, flags);
1741 rport = fcport->drport;
1742 fcport->drport = NULL;
1743 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1745 fc_remote_port_delete(rport);
1750 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1752 * @flags: allocation flags
1754 * Returns a pointer to the allocated fcport, or NULL, if none available.
1757 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1761 fcport = kmalloc(sizeof(fc_port_t), flags);
1765 /* Setup fcport template structure. */
1766 memset(fcport, 0, sizeof (fc_port_t));
1768 fcport->port_type = FCT_UNKNOWN;
1769 fcport->loop_id = FC_NO_LOOP_ID;
1770 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1771 fcport->flags = FCF_RLC_SUPPORT;
1772 fcport->supported_classes = FC_COS_UNSPECIFIED;
1773 spin_lock_init(&fcport->rport_lock);
1779 * qla2x00_configure_loop
1780 * Updates Fibre Channel Device Database with what is actually on loop.
1783 * ha = adapter block pointer.
1788 * 2 = database was full and device was not configured.
1791 qla2x00_configure_loop(scsi_qla_host_t *ha)
1794 unsigned long flags, save_flags;
1798 /* Get Initiator ID */
1799 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1800 rval = qla2x00_configure_hba(ha);
1801 if (rval != QLA_SUCCESS) {
1802 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1808 save_flags = flags = ha->dpc_flags;
1809 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1810 ha->host_no, flags));
1813 * If we have both an RSCN and PORT UPDATE pending then handle them
1814 * both at the same time.
1816 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1817 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1819 /* Determine what we need to do */
1820 if (ha->current_topology == ISP_CFG_FL &&
1821 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1823 ha->flags.rscn_queue_overflow = 1;
1824 set_bit(RSCN_UPDATE, &flags);
1826 } else if (ha->current_topology == ISP_CFG_F &&
1827 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1829 ha->flags.rscn_queue_overflow = 1;
1830 set_bit(RSCN_UPDATE, &flags);
1831 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1833 } else if (ha->current_topology == ISP_CFG_N) {
1834 clear_bit(RSCN_UPDATE, &flags);
1836 } else if (!ha->flags.online ||
1837 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1839 ha->flags.rscn_queue_overflow = 1;
1840 set_bit(RSCN_UPDATE, &flags);
1841 set_bit(LOCAL_LOOP_UPDATE, &flags);
1844 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1845 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1846 rval = QLA_FUNCTION_FAILED;
1848 rval = qla2x00_configure_local_loop(ha);
1852 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1853 if (LOOP_TRANSITION(ha)) {
1854 rval = QLA_FUNCTION_FAILED;
1856 rval = qla2x00_configure_fabric(ha);
1860 if (rval == QLA_SUCCESS) {
1861 if (atomic_read(&ha->loop_down_timer) ||
1862 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1863 rval = QLA_FUNCTION_FAILED;
1865 atomic_set(&ha->loop_state, LOOP_READY);
1867 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1872 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1873 __func__, ha->host_no));
1875 DEBUG3(printk("%s: exiting normally\n", __func__));
1878 /* Restore state if a resync event occured during processing */
1879 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1880 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1881 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1882 if (test_bit(RSCN_UPDATE, &save_flags))
1883 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1892 * qla2x00_configure_local_loop
1893 * Updates Fibre Channel Device Database with local loop devices.
1896 * ha = adapter block pointer.
1902 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1907 fc_port_t *fcport, *new_fcport;
1913 uint8_t domain, area, al_pa;
1917 entries = MAX_FIBRE_DEVICES;
1919 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1920 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1922 /* Get list of logged in devices. */
1923 memset(ha->gid_list, 0, GID_LIST_SIZE);
1924 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1926 if (rval != QLA_SUCCESS)
1927 goto cleanup_allocation;
1929 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1930 ha->host_no, entries));
1931 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1932 entries * sizeof(struct gid_list_info)));
1934 /* Allocate temporary fcport for any new fcports discovered. */
1935 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1936 if (new_fcport == NULL) {
1937 rval = QLA_MEMORY_ALLOC_FAILED;
1938 goto cleanup_allocation;
1940 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1943 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1945 list_for_each_entry(fcport, &ha->fcports, list) {
1946 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1947 fcport->port_type != FCT_BROADCAST &&
1948 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1950 DEBUG(printk("scsi(%ld): Marking port lost, "
1952 ha->host_no, fcport->loop_id));
1954 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1955 fcport->flags &= ~FCF_FARP_DONE;
1959 /* Add devices to port list. */
1960 id_iter = (char *)ha->gid_list;
1961 for (index = 0; index < entries; index++) {
1962 domain = ((struct gid_list_info *)id_iter)->domain;
1963 area = ((struct gid_list_info *)id_iter)->area;
1964 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1965 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1966 loop_id = (uint16_t)
1967 ((struct gid_list_info *)id_iter)->loop_id_2100;
1969 loop_id = le16_to_cpu(
1970 ((struct gid_list_info *)id_iter)->loop_id);
1971 id_iter += ha->gid_list_info_size;
1973 /* Bypass reserved domain fields. */
1974 if ((domain & 0xf0) == 0xf0)
1977 /* Bypass if not same domain and area of adapter. */
1978 if (area && domain &&
1979 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
1982 /* Bypass invalid local loop ID. */
1983 if (loop_id > LAST_LOCAL_LOOP_ID)
1986 /* Fill in member data. */
1987 new_fcport->d_id.b.domain = domain;
1988 new_fcport->d_id.b.area = area;
1989 new_fcport->d_id.b.al_pa = al_pa;
1990 new_fcport->loop_id = loop_id;
1991 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1992 if (rval2 != QLA_SUCCESS) {
1993 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1994 "information -- get_port_database=%x, "
1996 ha->host_no, rval2, new_fcport->loop_id));
1997 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
1999 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2003 /* Check for matching device in port list. */
2006 list_for_each_entry(fcport, &ha->fcports, list) {
2007 if (memcmp(new_fcport->port_name, fcport->port_name,
2011 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2012 FCF_PERSISTENT_BOUND);
2013 fcport->loop_id = new_fcport->loop_id;
2014 fcport->port_type = new_fcport->port_type;
2015 fcport->d_id.b24 = new_fcport->d_id.b24;
2016 memcpy(fcport->node_name, new_fcport->node_name,
2024 /* New device, add to fcports list. */
2025 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
2026 list_add_tail(&new_fcport->list, &ha->fcports);
2028 /* Allocate a new replacement fcport. */
2029 fcport = new_fcport;
2030 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2031 if (new_fcport == NULL) {
2032 rval = QLA_MEMORY_ALLOC_FAILED;
2033 goto cleanup_allocation;
2035 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2038 /* Base iIDMA settings on HBA port speed. */
2039 switch (ha->link_data_rate) {
2040 case PORT_SPEED_1GB:
2041 fcport->fp_speed = cpu_to_be16(BIT_15);
2043 case PORT_SPEED_2GB:
2044 fcport->fp_speed = cpu_to_be16(BIT_14);
2046 case PORT_SPEED_4GB:
2047 fcport->fp_speed = cpu_to_be16(BIT_13);
2051 qla2x00_update_fcport(ha, fcport);
2059 if (rval != QLA_SUCCESS) {
2060 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2061 "rval=%x\n", ha->host_no, rval));
2065 ha->device_flags |= DFLG_LOCAL_DEVICES;
2066 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2073 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
2077 qla2x00_mark_all_devices_lost(ha, 0);
2078 list_for_each_entry(fcport, &ha->fcports, list) {
2079 if (fcport->port_type != FCT_TARGET)
2082 qla2x00_update_fcport(ha, fcport);
2087 qla2x00_iidma_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2089 #define LS_UNKNOWN 2
2090 static char *link_speeds[5] = { "1", "2", "?", "4" };
2092 uint16_t port_speed, mb[6];
2094 if (!IS_QLA24XX(ha))
2097 switch (be16_to_cpu(fcport->fp_speed)) {
2099 port_speed = PORT_SPEED_1GB;
2102 port_speed = PORT_SPEED_2GB;
2105 port_speed = PORT_SPEED_4GB;
2108 DEBUG2(printk("scsi(%ld): %02x%02x%02x%02x%02x%02x%02x%02x -- "
2109 "unsupported FM port operating speed (%04x).\n",
2110 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2111 fcport->port_name[2], fcport->port_name[3],
2112 fcport->port_name[4], fcport->port_name[5],
2113 fcport->port_name[6], fcport->port_name[7],
2114 be16_to_cpu(fcport->fp_speed)));
2115 port_speed = PORT_SPEED_UNKNOWN;
2118 if (port_speed == PORT_SPEED_UNKNOWN)
2121 rval = qla2x00_set_idma_speed(ha, fcport->loop_id, port_speed, mb);
2122 if (rval != QLA_SUCCESS) {
2123 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2124 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2125 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2126 fcport->port_name[2], fcport->port_name[3],
2127 fcport->port_name[4], fcport->port_name[5],
2128 fcport->port_name[6], fcport->port_name[7], rval,
2129 port_speed, mb[0], mb[1]));
2131 DEBUG2(qla_printk(KERN_INFO, ha,
2132 "iIDMA adjusted to %s GB/s on "
2133 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2134 link_speeds[port_speed], fcport->port_name[0],
2135 fcport->port_name[1], fcport->port_name[2],
2136 fcport->port_name[3], fcport->port_name[4],
2137 fcport->port_name[5], fcport->port_name[6],
2138 fcport->port_name[7]));
2143 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2145 struct fc_rport_identifiers rport_ids;
2146 struct fc_rport *rport;
2147 unsigned long flags;
2150 qla2x00_rport_del(fcport);
2154 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2155 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2156 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2157 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2158 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2159 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2161 qla_printk(KERN_WARNING, ha,
2162 "Unable to allocate fc remote port!\n");
2165 spin_lock_irqsave(&fcport->rport_lock, flags);
2166 fcport->rport = rport;
2167 *((fc_port_t **)rport->dd_data) = fcport;
2168 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2170 rport->supported_classes = fcport->supported_classes;
2172 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2173 if (fcport->port_type == FCT_INITIATOR)
2174 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2175 if (fcport->port_type == FCT_TARGET)
2176 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2177 fc_remote_port_rolechg(rport, rport_ids.roles);
2179 if (rport->scsi_target_id != -1 &&
2180 rport->scsi_target_id < ha->host->max_id)
2181 fcport->os_target_id = rport->scsi_target_id;
2185 * qla2x00_update_fcport
2186 * Updates device on list.
2189 * ha = adapter block pointer.
2190 * fcport = port structure pointer.
2200 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2203 fcport->login_retry = 0;
2204 fcport->port_login_retry_count = ha->port_down_retry_count *
2206 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2208 fcport->flags &= ~FCF_LOGIN_NEEDED;
2210 qla2x00_iidma_fcport(ha, fcport);
2212 atomic_set(&fcport->state, FCS_ONLINE);
2214 qla2x00_reg_remote_port(ha, fcport);
2218 * qla2x00_configure_fabric
2219 * Setup SNS devices with loop ID's.
2222 * ha = adapter block pointer.
2229 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2232 fc_port_t *fcport, *fcptemp;
2233 uint16_t next_loopid;
2234 uint16_t mb[MAILBOX_REGISTER_COUNT];
2236 LIST_HEAD(new_fcports);
2238 /* If FL port exists, then SNS is present */
2239 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2240 loop_id = NPH_F_PORT;
2242 loop_id = SNS_FL_PORT;
2243 rval = qla2x00_get_port_name(ha, loop_id, ha->fabric_node_name, 1);
2244 if (rval != QLA_SUCCESS) {
2245 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2246 "Port\n", ha->host_no));
2248 ha->device_flags &= ~SWITCH_FOUND;
2249 return (QLA_SUCCESS);
2251 ha->device_flags |= SWITCH_FOUND;
2253 /* Mark devices that need re-synchronization. */
2254 rval2 = qla2x00_device_resync(ha);
2255 if (rval2 == QLA_RSCNS_HANDLED) {
2256 /* No point doing the scan, just continue. */
2257 return (QLA_SUCCESS);
2261 if (ql2xfdmienable &&
2262 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2263 qla2x00_fdmi_register(ha);
2265 /* Ensure we are logged into the SNS. */
2266 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2269 loop_id = SIMPLE_NAME_SERVER;
2270 ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
2271 0xfc, mb, BIT_1 | BIT_0);
2272 if (mb[0] != MBS_COMMAND_COMPLETE) {
2273 DEBUG2(qla_printk(KERN_INFO, ha,
2274 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2275 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2276 mb[0], mb[1], mb[2], mb[6], mb[7]));
2277 return (QLA_SUCCESS);
2280 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2281 if (qla2x00_rft_id(ha)) {
2283 DEBUG2(printk("scsi(%ld): Register FC-4 "
2284 "TYPE failed.\n", ha->host_no));
2286 if (qla2x00_rff_id(ha)) {
2288 DEBUG2(printk("scsi(%ld): Register FC-4 "
2289 "Features failed.\n", ha->host_no));
2291 if (qla2x00_rnn_id(ha)) {
2293 DEBUG2(printk("scsi(%ld): Register Node Name "
2294 "failed.\n", ha->host_no));
2295 } else if (qla2x00_rsnn_nn(ha)) {
2297 DEBUG2(printk("scsi(%ld): Register Symbolic "
2298 "Node Name failed.\n", ha->host_no));
2302 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2303 if (rval != QLA_SUCCESS)
2307 * Logout all previous fabric devices marked lost, except
2310 list_for_each_entry(fcport, &ha->fcports, list) {
2311 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2314 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2317 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2318 qla2x00_mark_device_lost(ha, fcport,
2319 ql2xplogiabsentdevice, 0);
2320 if (fcport->loop_id != FC_NO_LOOP_ID &&
2321 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2322 fcport->port_type != FCT_INITIATOR &&
2323 fcport->port_type != FCT_BROADCAST) {
2324 ha->isp_ops.fabric_logout(ha,
2326 fcport->d_id.b.domain,
2327 fcport->d_id.b.area,
2328 fcport->d_id.b.al_pa);
2329 fcport->loop_id = FC_NO_LOOP_ID;
2334 /* Starting free loop ID. */
2335 next_loopid = ha->min_external_loopid;
2338 * Scan through our port list and login entries that need to be
2341 list_for_each_entry(fcport, &ha->fcports, list) {
2342 if (atomic_read(&ha->loop_down_timer) ||
2343 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2346 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2347 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2350 if (fcport->loop_id == FC_NO_LOOP_ID) {
2351 fcport->loop_id = next_loopid;
2352 rval = qla2x00_find_new_loop_id(ha, fcport);
2353 if (rval != QLA_SUCCESS) {
2354 /* Ran out of IDs to use */
2358 /* Login and update database */
2359 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2362 /* Exit if out of loop IDs. */
2363 if (rval != QLA_SUCCESS) {
2368 * Login and add the new devices to our port list.
2370 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2371 if (atomic_read(&ha->loop_down_timer) ||
2372 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2375 /* Find a new loop ID to use. */
2376 fcport->loop_id = next_loopid;
2377 rval = qla2x00_find_new_loop_id(ha, fcport);
2378 if (rval != QLA_SUCCESS) {
2379 /* Ran out of IDs to use */
2383 /* Remove device from the new list and add it to DB */
2384 list_move_tail(&fcport->list, &ha->fcports);
2386 /* Login and update database */
2387 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2391 /* Free all new device structures not processed. */
2392 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2393 list_del(&fcport->list);
2398 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2399 "rval=%d\n", ha->host_no, rval));
2407 * qla2x00_find_all_fabric_devs
2410 * ha = adapter block pointer.
2411 * dev = database device entry pointer.
2420 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2424 fc_port_t *fcport, *new_fcport, *fcptemp;
2429 int first_dev, last_dev;
2430 port_id_t wrap, nxt_d_id;
2434 /* Try GID_PT to get device list, else GAN. */
2435 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2438 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2439 "on GA_NXT\n", ha->host_no));
2441 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2442 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2445 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2448 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2451 } else if (qla2x00_gfpn_id(ha, swl) == QLA_SUCCESS) {
2452 qla2x00_gpsc(ha, swl);
2457 /* Allocate temporary fcport for any new fcports discovered. */
2458 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2459 if (new_fcport == NULL) {
2461 return (QLA_MEMORY_ALLOC_FAILED);
2463 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2465 /* Set start port ID scan at adapter ID. */
2469 /* Starting free loop ID. */
2470 loop_id = ha->min_external_loopid;
2471 for (; loop_id <= ha->last_loop_id; loop_id++) {
2472 if (qla2x00_is_reserved_id(ha, loop_id))
2475 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2480 wrap.b24 = new_fcport->d_id.b24;
2482 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2483 memcpy(new_fcport->node_name,
2484 swl[swl_idx].node_name, WWN_SIZE);
2485 memcpy(new_fcport->port_name,
2486 swl[swl_idx].port_name, WWN_SIZE);
2487 memcpy(new_fcport->fabric_port_name,
2488 swl[swl_idx].fabric_port_name, WWN_SIZE);
2489 new_fcport->fp_speed = swl[swl_idx].fp_speed;
2491 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2497 /* Send GA_NXT to the switch */
2498 rval = qla2x00_ga_nxt(ha, new_fcport);
2499 if (rval != QLA_SUCCESS) {
2500 qla_printk(KERN_WARNING, ha,
2501 "SNS scan failed -- assuming zero-entry "
2503 list_for_each_entry_safe(fcport, fcptemp,
2504 new_fcports, list) {
2505 list_del(&fcport->list);
2513 /* If wrap on switch device list, exit. */
2515 wrap.b24 = new_fcport->d_id.b24;
2517 } else if (new_fcport->d_id.b24 == wrap.b24) {
2518 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2519 ha->host_no, new_fcport->d_id.b.domain,
2520 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2524 /* Bypass if host adapter. */
2525 if (new_fcport->d_id.b24 == ha->d_id.b24)
2528 /* Bypass if same domain and area of adapter. */
2529 if (((new_fcport->d_id.b24 & 0xffff00) ==
2530 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2534 /* Bypass reserved domain fields. */
2535 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2538 /* Locate matching device in database. */
2540 list_for_each_entry(fcport, &ha->fcports, list) {
2541 if (memcmp(new_fcport->port_name, fcport->port_name,
2547 /* Update port state. */
2548 memcpy(fcport->fabric_port_name,
2549 new_fcport->fabric_port_name, WWN_SIZE);
2550 fcport->fp_speed = new_fcport->fp_speed;
2553 * If address the same and state FCS_ONLINE, nothing
2556 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2557 atomic_read(&fcport->state) == FCS_ONLINE) {
2562 * If device was not a fabric device before.
2564 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2565 fcport->d_id.b24 = new_fcport->d_id.b24;
2566 fcport->loop_id = FC_NO_LOOP_ID;
2567 fcport->flags |= (FCF_FABRIC_DEVICE |
2569 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2574 * Port ID changed or device was marked to be updated;
2575 * Log it out if still logged in and mark it for
2578 fcport->d_id.b24 = new_fcport->d_id.b24;
2579 fcport->flags |= FCF_LOGIN_NEEDED;
2580 if (fcport->loop_id != FC_NO_LOOP_ID &&
2581 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2582 fcport->port_type != FCT_INITIATOR &&
2583 fcport->port_type != FCT_BROADCAST) {
2584 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2585 fcport->d_id.b.domain, fcport->d_id.b.area,
2586 fcport->d_id.b.al_pa);
2587 fcport->loop_id = FC_NO_LOOP_ID;
2596 /* If device was not in our fcports list, then add it. */
2597 list_add_tail(&new_fcport->list, new_fcports);
2599 /* Allocate a new replacement fcport. */
2600 nxt_d_id.b24 = new_fcport->d_id.b24;
2601 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2602 if (new_fcport == NULL) {
2604 return (QLA_MEMORY_ALLOC_FAILED);
2606 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2607 new_fcport->d_id.b24 = nxt_d_id.b24;
2613 if (!list_empty(new_fcports))
2614 ha->device_flags |= DFLG_FABRIC_DEVICES;
2620 * qla2x00_find_new_loop_id
2621 * Scan through our port list and find a new usable loop ID.
2624 * ha: adapter state pointer.
2625 * dev: port structure pointer.
2628 * qla2x00 local function return status code.
2634 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2639 uint16_t first_loop_id;
2643 /* Save starting loop ID. */
2644 first_loop_id = dev->loop_id;
2647 /* Skip loop ID if already used by adapter. */
2648 if (dev->loop_id == ha->loop_id) {
2652 /* Skip reserved loop IDs. */
2653 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2657 /* Reset loop ID if passed the end. */
2658 if (dev->loop_id > ha->last_loop_id) {
2659 /* first loop ID. */
2660 dev->loop_id = ha->min_external_loopid;
2663 /* Check for loop ID being already in use. */
2666 list_for_each_entry(fcport, &ha->fcports, list) {
2667 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2668 /* ID possibly in use */
2674 /* If not in use then it is free to use. */
2679 /* ID in use. Try next value. */
2682 /* If wrap around. No free ID to use. */
2683 if (dev->loop_id == first_loop_id) {
2684 dev->loop_id = FC_NO_LOOP_ID;
2685 rval = QLA_FUNCTION_FAILED;
2694 * qla2x00_device_resync
2695 * Marks devices in the database that needs resynchronization.
2698 * ha = adapter block pointer.
2704 qla2x00_device_resync(scsi_qla_host_t *ha)
2709 uint32_t rscn_entry;
2710 uint8_t rscn_out_iter;
2714 rval = QLA_RSCNS_HANDLED;
2716 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2717 ha->flags.rscn_queue_overflow) {
2719 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2720 format = MSB(MSW(rscn_entry));
2721 d_id.b.domain = LSB(MSW(rscn_entry));
2722 d_id.b.area = MSB(LSW(rscn_entry));
2723 d_id.b.al_pa = LSB(LSW(rscn_entry));
2725 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2726 "[%02x/%02x%02x%02x].\n",
2727 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2728 d_id.b.area, d_id.b.al_pa));
2731 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2732 ha->rscn_out_ptr = 0;
2734 /* Skip duplicate entries. */
2735 for (rscn_out_iter = ha->rscn_out_ptr;
2736 !ha->flags.rscn_queue_overflow &&
2737 rscn_out_iter != ha->rscn_in_ptr;
2738 rscn_out_iter = (rscn_out_iter ==
2739 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2741 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2744 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2745 "entry found at [%d].\n", ha->host_no,
2748 ha->rscn_out_ptr = rscn_out_iter;
2751 /* Queue overflow, set switch default case. */
2752 if (ha->flags.rscn_queue_overflow) {
2753 DEBUG(printk("scsi(%ld): device_resync: rscn "
2754 "overflow.\n", ha->host_no));
2757 ha->flags.rscn_queue_overflow = 0;
2773 ha->rscn_out_ptr = ha->rscn_in_ptr;
2779 list_for_each_entry(fcport, &ha->fcports, list) {
2780 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2781 (fcport->d_id.b24 & mask) != d_id.b24 ||
2782 fcport->port_type == FCT_BROADCAST)
2785 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2787 fcport->port_type != FCT_INITIATOR) {
2788 qla2x00_mark_device_lost(ha, fcport,
2792 fcport->flags &= ~FCF_FARP_DONE;
2799 * qla2x00_fabric_dev_login
2800 * Login fabric target device and update FC port database.
2803 * ha: adapter state pointer.
2804 * fcport: port structure list pointer.
2805 * next_loopid: contains value of a new loop ID that can be used
2806 * by the next login attempt.
2809 * qla2x00 local function return status code.
2815 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2816 uint16_t *next_loopid)
2825 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2826 if (rval == QLA_SUCCESS) {
2827 /* Send an ADISC to tape devices.*/
2829 if (fcport->flags & FCF_TAPE_PRESENT)
2831 rval = qla2x00_get_port_database(ha, fcport, opts);
2832 if (rval != QLA_SUCCESS) {
2833 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2834 fcport->d_id.b.domain, fcport->d_id.b.area,
2835 fcport->d_id.b.al_pa);
2836 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2838 qla2x00_update_fcport(ha, fcport);
2846 * qla2x00_fabric_login
2847 * Issue fabric login command.
2850 * ha = adapter block pointer.
2851 * device = pointer to FC device type structure.
2854 * 0 - Login successfully
2856 * 2 - Initiator device
2860 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2861 uint16_t *next_loopid)
2865 uint16_t tmp_loopid;
2866 uint16_t mb[MAILBOX_REGISTER_COUNT];
2872 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2873 "for port %02x%02x%02x.\n",
2874 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2875 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2877 /* Login fcport on switch. */
2878 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2879 fcport->d_id.b.domain, fcport->d_id.b.area,
2880 fcport->d_id.b.al_pa, mb, BIT_0);
2881 if (mb[0] == MBS_PORT_ID_USED) {
2883 * Device has another loop ID. The firmware team
2884 * recommends the driver perform an implicit login with
2885 * the specified ID again. The ID we just used is save
2886 * here so we return with an ID that can be tried by
2890 tmp_loopid = fcport->loop_id;
2891 fcport->loop_id = mb[1];
2893 DEBUG(printk("Fabric Login: port in use - next "
2894 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2895 fcport->loop_id, fcport->d_id.b.domain,
2896 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2898 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2903 /* A retry occurred before. */
2904 *next_loopid = tmp_loopid;
2907 * No retry occurred before. Just increment the
2908 * ID value for next login.
2910 *next_loopid = (fcport->loop_id + 1);
2913 if (mb[1] & BIT_0) {
2914 fcport->port_type = FCT_INITIATOR;
2916 fcport->port_type = FCT_TARGET;
2917 if (mb[1] & BIT_1) {
2918 fcport->flags |= FCF_TAPE_PRESENT;
2923 fcport->supported_classes |= FC_COS_CLASS2;
2925 fcport->supported_classes |= FC_COS_CLASS3;
2929 } else if (mb[0] == MBS_LOOP_ID_USED) {
2931 * Loop ID already used, try next loop ID.
2934 rval = qla2x00_find_new_loop_id(ha, fcport);
2935 if (rval != QLA_SUCCESS) {
2936 /* Ran out of loop IDs to use */
2939 } else if (mb[0] == MBS_COMMAND_ERROR) {
2941 * Firmware possibly timed out during login. If NO
2942 * retries are left to do then the device is declared
2945 *next_loopid = fcport->loop_id;
2946 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2947 fcport->d_id.b.domain, fcport->d_id.b.area,
2948 fcport->d_id.b.al_pa);
2949 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2955 * unrecoverable / not handled error
2957 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2958 "loop_id=%x jiffies=%lx.\n",
2959 __func__, ha->host_no, mb[0],
2960 fcport->d_id.b.domain, fcport->d_id.b.area,
2961 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2963 *next_loopid = fcport->loop_id;
2964 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2965 fcport->d_id.b.domain, fcport->d_id.b.area,
2966 fcport->d_id.b.al_pa);
2967 fcport->loop_id = FC_NO_LOOP_ID;
2968 fcport->login_retry = 0;
2979 * qla2x00_local_device_login
2980 * Issue local device login command.
2983 * ha = adapter block pointer.
2984 * loop_id = loop id of device to login to.
2986 * Returns (Where's the #define!!!!):
2987 * 0 - Login successfully
2992 qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
2995 uint16_t mb[MAILBOX_REGISTER_COUNT];
2997 memset(mb, 0, sizeof(mb));
2998 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
2999 if (rval == QLA_SUCCESS) {
3000 /* Interrogate mailbox registers for any errors */
3001 if (mb[0] == MBS_COMMAND_ERROR)
3003 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3004 /* device not in PCB table */
3012 * qla2x00_loop_resync
3013 * Resync with fibre channel devices.
3016 * ha = adapter block pointer.
3022 qla2x00_loop_resync(scsi_qla_host_t *ha)
3029 atomic_set(&ha->loop_state, LOOP_UPDATE);
3030 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3031 if (ha->flags.online) {
3032 if (!(rval = qla2x00_fw_ready(ha))) {
3033 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3036 atomic_set(&ha->loop_state, LOOP_UPDATE);
3038 /* Issue a marker after FW becomes ready. */
3039 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3040 ha->marker_needed = 0;
3042 /* Remap devices on Loop. */
3043 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3045 qla2x00_configure_loop(ha);
3047 } while (!atomic_read(&ha->loop_down_timer) &&
3048 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3050 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3054 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3055 return (QLA_FUNCTION_FAILED);
3059 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3066 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
3072 list_for_each_entry(fcport, &ha->fcports, list) {
3073 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
3076 qla2x00_update_fcport(ha, fcport);
3077 fcport->flags &= ~FCF_RESCAN_NEEDED;
3081 qla2x00_probe_for_all_luns(ha);
3085 qla2x00_update_fcports(scsi_qla_host_t *ha)
3089 /* Go with deferred removal of rport references. */
3090 list_for_each_entry(fcport, &ha->fcports, list)
3092 qla2x00_rport_del(fcport);
3097 * Resets ISP and aborts all outstanding commands.
3100 * ha = adapter block pointer.
3106 qla2x00_abort_isp(scsi_qla_host_t *ha)
3109 unsigned long flags = 0;
3114 if (ha->flags.online) {
3115 ha->flags.online = 0;
3116 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3118 qla_printk(KERN_INFO, ha,
3119 "Performing ISP error recovery - ha= %p.\n", ha);
3120 ha->isp_ops.reset_chip(ha);
3122 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3123 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3124 atomic_set(&ha->loop_state, LOOP_DOWN);
3125 qla2x00_mark_all_devices_lost(ha, 0);
3127 if (!atomic_read(&ha->loop_down_timer))
3128 atomic_set(&ha->loop_down_timer,
3132 spin_lock_irqsave(&ha->hardware_lock, flags);
3133 /* Requeue all commands in outstanding command list. */
3134 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3135 sp = ha->outstanding_cmds[cnt];
3137 ha->outstanding_cmds[cnt] = NULL;
3139 sp->cmd->result = DID_RESET << 16;
3140 sp->cmd->host_scribble = (unsigned char *)NULL;
3141 qla2x00_sp_compl(ha, sp);
3144 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3146 ha->isp_ops.get_flash_version(ha, ha->request_ring);
3148 ha->isp_ops.nvram_config(ha);
3150 if (!qla2x00_restart_isp(ha)) {
3151 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3153 if (!atomic_read(&ha->loop_down_timer)) {
3155 * Issue marker command only when we are going
3156 * to start the I/O .
3158 ha->marker_needed = 1;
3161 ha->flags.online = 1;
3163 ha->isp_ops.enable_intrs(ha);
3165 ha->isp_abort_cnt = 0;
3166 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3169 rval = qla2x00_trace_control(ha, TC_ENABLE,
3170 ha->eft_dma, EFT_NUM_BUFFERS);
3172 qla_printk(KERN_WARNING, ha,
3173 "Unable to reinitialize EFT "
3177 } else { /* failed the ISP abort */
3178 ha->flags.online = 1;
3179 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3180 if (ha->isp_abort_cnt == 0) {
3181 qla_printk(KERN_WARNING, ha,
3182 "ISP error recovery failed - "
3183 "board disabled\n");
3185 * The next call disables the board
3188 ha->isp_ops.reset_adapter(ha);
3189 ha->flags.online = 0;
3190 clear_bit(ISP_ABORT_RETRY,
3193 } else { /* schedule another ISP abort */
3194 ha->isp_abort_cnt--;
3195 DEBUG(printk("qla%ld: ISP abort - "
3196 "retry remaining %d\n",
3197 ha->host_no, ha->isp_abort_cnt));
3201 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3202 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3203 "- retrying (%d) more times\n",
3204 ha->host_no, ha->isp_abort_cnt));
3205 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3213 qla_printk(KERN_INFO, ha,
3214 "qla2x00_abort_isp: **** FAILED ****\n");
3216 DEBUG(printk(KERN_INFO
3217 "qla2x00_abort_isp(%ld): exiting.\n",
3225 * qla2x00_restart_isp
3226 * restarts the ISP after a reset
3229 * ha = adapter block pointer.
3235 qla2x00_restart_isp(scsi_qla_host_t *ha)
3238 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3239 unsigned long flags = 0;
3242 /* If firmware needs to be loaded */
3243 if (qla2x00_isp_firmware(ha)) {
3244 ha->flags.online = 0;
3245 if (!(status = ha->isp_ops.chip_diag(ha))) {
3246 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3247 status = qla2x00_setup_chip(ha);
3251 spin_lock_irqsave(&ha->hardware_lock, flags);
3253 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3255 * Disable SRAM, Instruction RAM and GP RAM
3258 WRT_REG_WORD(®->hccr,
3259 (HCCR_ENABLE_PARITY + 0x0));
3260 RD_REG_WORD(®->hccr);
3263 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3265 status = qla2x00_setup_chip(ha);
3267 spin_lock_irqsave(&ha->hardware_lock, flags);
3269 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3270 /* Enable proper parity */
3273 WRT_REG_WORD(®->hccr,
3274 (HCCR_ENABLE_PARITY + 0x1));
3277 * SRAM, Instruction RAM and GP RAM
3280 WRT_REG_WORD(®->hccr,
3281 (HCCR_ENABLE_PARITY + 0x7));
3282 RD_REG_WORD(®->hccr);
3285 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3290 if (!status && !(status = qla2x00_init_rings(ha))) {
3291 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3292 if (!(status = qla2x00_fw_ready(ha))) {
3293 DEBUG(printk("%s(): Start configure loop, "
3294 "status = %d\n", __func__, status));
3296 /* Issue a marker after FW becomes ready. */
3297 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3299 ha->flags.online = 1;
3300 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3303 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3304 qla2x00_configure_loop(ha);
3306 } while (!atomic_read(&ha->loop_down_timer) &&
3307 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3309 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3312 /* if no cable then assume it's good */
3313 if ((ha->device_flags & DFLG_NO_CABLE))
3316 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3324 * qla2x00_reset_adapter
3328 * ha = adapter block pointer.
3331 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3333 unsigned long flags = 0;
3334 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3336 ha->flags.online = 0;
3337 ha->isp_ops.disable_intrs(ha);
3339 spin_lock_irqsave(&ha->hardware_lock, flags);
3340 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3341 RD_REG_WORD(®->hccr); /* PCI Posting. */
3342 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3343 RD_REG_WORD(®->hccr); /* PCI Posting. */
3344 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3348 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3350 unsigned long flags = 0;
3351 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3353 ha->flags.online = 0;
3354 ha->isp_ops.disable_intrs(ha);
3356 spin_lock_irqsave(&ha->hardware_lock, flags);
3357 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3358 RD_REG_DWORD(®->hccr);
3359 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3360 RD_REG_DWORD(®->hccr);
3361 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3364 /* On sparc systems, obtain port and node WWN from firmware
3367 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, struct nvram_24xx *nv)
3370 struct pci_dev *pdev = ha->pdev;
3371 struct device_node *dp = pci_device_to_OF_node(pdev);
3375 val = of_get_property(dp, "port-wwn", &len);
3376 if (val && len >= WWN_SIZE)
3377 memcpy(nv->port_name, val, WWN_SIZE);
3379 val = of_get_property(dp, "node-wwn", &len);
3380 if (val && len >= WWN_SIZE)
3381 memcpy(nv->node_name, val, WWN_SIZE);
3386 qla24xx_nvram_config(scsi_qla_host_t *ha)
3389 struct init_cb_24xx *icb;
3390 struct nvram_24xx *nv;
3392 uint8_t *dptr1, *dptr2;
3397 icb = (struct init_cb_24xx *)ha->init_cb;
3398 nv = (struct nvram_24xx *)ha->request_ring;
3400 /* Determine NVRAM starting address. */
3401 ha->nvram_size = sizeof(struct nvram_24xx);
3402 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3403 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3404 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3405 if (PCI_FUNC(ha->pdev->devfn)) {
3406 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3407 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3410 /* Get NVRAM data and calculate checksum. */
3411 dptr = (uint32_t *)nv;
3412 ha->isp_ops.read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3414 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3415 chksum += le32_to_cpu(*dptr++);
3417 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3418 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3421 /* Bad NVRAM data, set defaults parameters. */
3422 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3423 || nv->id[3] != ' ' ||
3424 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3425 /* Reset NVRAM data. */
3426 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3427 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3428 le16_to_cpu(nv->nvram_version));
3429 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3430 "invalid -- WWPN) defaults.\n");
3433 * Set default initialization control block.
3435 memset(nv, 0, ha->nvram_size);
3436 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3437 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3438 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3439 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3440 nv->exchange_count = __constant_cpu_to_le16(0);
3441 nv->hard_address = __constant_cpu_to_le16(124);
3442 nv->port_name[0] = 0x21;
3443 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3444 nv->port_name[2] = 0x00;
3445 nv->port_name[3] = 0xe0;
3446 nv->port_name[4] = 0x8b;
3447 nv->port_name[5] = 0x1c;
3448 nv->port_name[6] = 0x55;
3449 nv->port_name[7] = 0x86;
3450 nv->node_name[0] = 0x20;
3451 nv->node_name[1] = 0x00;
3452 nv->node_name[2] = 0x00;
3453 nv->node_name[3] = 0xe0;
3454 nv->node_name[4] = 0x8b;
3455 nv->node_name[5] = 0x1c;
3456 nv->node_name[6] = 0x55;
3457 nv->node_name[7] = 0x86;
3458 qla24xx_nvram_wwn_from_ofw(ha, nv);
3459 nv->login_retry_count = __constant_cpu_to_le16(8);
3460 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3461 nv->login_timeout = __constant_cpu_to_le16(0);
3462 nv->firmware_options_1 =
3463 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3464 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3465 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3466 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3467 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3468 nv->efi_parameters = __constant_cpu_to_le32(0);
3469 nv->reset_delay = 5;
3470 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3471 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3472 nv->link_down_timeout = __constant_cpu_to_le16(30);
3477 /* Reset Initialization control block */
3478 memset(icb, 0, sizeof(struct init_cb_24xx));
3480 /* Copy 1st segment. */
3481 dptr1 = (uint8_t *)icb;
3482 dptr2 = (uint8_t *)&nv->version;
3483 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3485 *dptr1++ = *dptr2++;
3487 icb->login_retry_count = nv->login_retry_count;
3488 icb->link_down_on_nos = nv->link_down_on_nos;
3490 /* Copy 2nd segment. */
3491 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3492 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3493 cnt = (uint8_t *)&icb->reserved_3 -
3494 (uint8_t *)&icb->interrupt_delay_timer;
3496 *dptr1++ = *dptr2++;
3499 * Setup driver NVRAM options.
3501 qla2x00_set_model_info(ha, nv->model_name, sizeof(nv->model_name),
3504 /* Use alternate WWN? */
3505 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3506 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3507 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3510 /* Prepare nodename */
3511 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3513 * Firmware will apply the following mask if the nodename was
3516 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3517 icb->node_name[0] &= 0xF0;
3520 /* Set host adapter parameters. */
3521 ha->flags.disable_risc_code_load = 0;
3522 ha->flags.enable_lip_reset = 0;
3523 ha->flags.enable_lip_full_login =
3524 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3525 ha->flags.enable_target_reset =
3526 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
3527 ha->flags.enable_led_scheme = 0;
3528 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
3530 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3531 (BIT_6 | BIT_5 | BIT_4)) >> 4;
3533 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3534 sizeof(ha->fw_seriallink_options24));
3536 /* save HBA serial number */
3537 ha->serial0 = icb->port_name[5];
3538 ha->serial1 = icb->port_name[6];
3539 ha->serial2 = icb->port_name[7];
3540 ha->node_name = icb->node_name;
3541 ha->port_name = icb->port_name;
3543 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3545 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3547 /* Set minimum login_timeout to 4 seconds. */
3548 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3549 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3550 if (le16_to_cpu(nv->login_timeout) < 4)
3551 nv->login_timeout = __constant_cpu_to_le16(4);
3552 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3553 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3555 /* Set minimum RATOV to 200 tenths of a second. */
3558 ha->loop_reset_delay = nv->reset_delay;
3560 /* Link Down Timeout = 0:
3562 * When Port Down timer expires we will start returning
3563 * I/O's to OS with "DID_NO_CONNECT".
3565 * Link Down Timeout != 0:
3567 * The driver waits for the link to come up after link down
3568 * before returning I/Os to OS with "DID_NO_CONNECT".
3570 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3571 ha->loop_down_abort_time =
3572 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3574 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3575 ha->loop_down_abort_time =
3576 (LOOP_DOWN_TIME - ha->link_down_timeout);
3579 /* Need enough time to try and get the port back. */
3580 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3581 if (qlport_down_retry)
3582 ha->port_down_retry_count = qlport_down_retry;
3584 /* Set login_retry_count */
3585 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3586 if (ha->port_down_retry_count ==
3587 le16_to_cpu(nv->port_down_retry_count) &&
3588 ha->port_down_retry_count > 3)
3589 ha->login_retry_count = ha->port_down_retry_count;
3590 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3591 ha->login_retry_count = ha->port_down_retry_count;
3592 if (ql2xloginretrycount)
3593 ha->login_retry_count = ql2xloginretrycount;
3596 if (!ha->flags.init_done) {
3597 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3598 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3599 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3600 le16_to_cpu(icb->interrupt_delay_timer): 2;
3602 icb->firmware_options_2 &= __constant_cpu_to_le32(
3603 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3604 ha->flags.process_response_queue = 0;
3605 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3606 ha->zio_mode = QLA_ZIO_MODE_6;
3608 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3609 "(%d us).\n", ha->host_no, ha->zio_mode,
3610 ha->zio_timer * 100));
3611 qla_printk(KERN_INFO, ha,
3612 "ZIO mode %d enabled; timer delay (%d us).\n",
3613 ha->zio_mode, ha->zio_timer * 100);
3615 icb->firmware_options_2 |= cpu_to_le32(
3616 (uint32_t)ha->zio_mode);
3617 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3618 ha->flags.process_response_queue = 1;
3622 DEBUG2_3(printk(KERN_WARNING
3623 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3629 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3632 int segments, fragment;
3634 uint32_t *dcode, dlen;
3641 segments = FA_RISC_CODE_SEGMENTS;
3642 faddr = FA_RISC_CODE_ADDR;
3643 dcode = (uint32_t *)ha->request_ring;
3646 /* Validate firmware image by checking version. */
3647 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3648 for (i = 0; i < 4; i++)
3649 dcode[i] = be32_to_cpu(dcode[i]);
3650 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3651 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3652 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3654 qla_printk(KERN_WARNING, ha,
3655 "Unable to verify integrity of flash firmware image!\n");
3656 qla_printk(KERN_WARNING, ha,
3657 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3658 dcode[1], dcode[2], dcode[3]);
3660 return QLA_FUNCTION_FAILED;
3663 while (segments && rval == QLA_SUCCESS) {
3664 /* Read segment's load information. */
3665 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3667 risc_addr = be32_to_cpu(dcode[2]);
3668 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3669 risc_size = be32_to_cpu(dcode[3]);
3672 while (risc_size > 0 && rval == QLA_SUCCESS) {
3673 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3674 if (dlen > risc_size)
3677 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3678 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3679 ha->host_no, risc_addr, dlen, faddr));
3681 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3682 for (i = 0; i < dlen; i++)
3683 dcode[i] = swab32(dcode[i]);
3685 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3688 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3689 "segment %d of firmware\n", ha->host_no,
3691 qla_printk(KERN_WARNING, ha,
3692 "[ERROR] Failed to load segment %d of "
3693 "firmware\n", fragment);
3710 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3713 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3717 uint16_t *wcode, *fwcode;
3718 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3719 struct fw_blob *blob;
3721 /* Load firmware blob. */
3722 blob = qla2x00_request_firmware(ha);
3724 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3725 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3726 "from: " QLA_FW_URL ".\n");
3727 return QLA_FUNCTION_FAILED;
3732 wcode = (uint16_t *)ha->request_ring;
3734 fwcode = (uint16_t *)blob->fw->data;
3737 /* Validate firmware image by checking version. */
3738 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3739 qla_printk(KERN_WARNING, ha,
3740 "Unable to verify integrity of firmware image (%Zd)!\n",
3742 goto fail_fw_integrity;
3744 for (i = 0; i < 4; i++)
3745 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3746 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3747 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3748 wcode[2] == 0 && wcode[3] == 0)) {
3749 qla_printk(KERN_WARNING, ha,
3750 "Unable to verify integrity of firmware image!\n");
3751 qla_printk(KERN_WARNING, ha,
3752 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3753 wcode[1], wcode[2], wcode[3]);
3754 goto fail_fw_integrity;
3758 while (*seg && rval == QLA_SUCCESS) {
3760 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3761 risc_size = be16_to_cpu(fwcode[3]);
3763 /* Validate firmware image size. */
3764 fwclen += risc_size * sizeof(uint16_t);
3765 if (blob->fw->size < fwclen) {
3766 qla_printk(KERN_WARNING, ha,
3767 "Unable to verify integrity of firmware image "
3768 "(%Zd)!\n", blob->fw->size);
3769 goto fail_fw_integrity;
3773 while (risc_size > 0 && rval == QLA_SUCCESS) {
3774 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3775 if (wlen > risc_size)
3778 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3779 "addr %x, number of words 0x%x.\n", ha->host_no,
3782 for (i = 0; i < wlen; i++)
3783 wcode[i] = swab16(fwcode[i]);
3785 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3788 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3789 "segment %d of firmware\n", ha->host_no,
3791 qla_printk(KERN_WARNING, ha,
3792 "[ERROR] Failed to load segment %d of "
3793 "firmware\n", fragment);
3809 return QLA_FUNCTION_FAILED;
3813 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3816 int segments, fragment;
3817 uint32_t *dcode, dlen;
3821 struct fw_blob *blob;
3822 uint32_t *fwcode, fwclen;
3824 /* Load firmware blob. */
3825 blob = qla2x00_request_firmware(ha);
3827 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3828 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3829 "from: " QLA_FW_URL ".\n");
3831 /* Try to load RISC code from flash. */
3832 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3833 "outdated) firmware from flash.\n");
3834 return qla24xx_load_risc_flash(ha, srisc_addr);
3839 segments = FA_RISC_CODE_SEGMENTS;
3840 dcode = (uint32_t *)ha->request_ring;
3842 fwcode = (uint32_t *)blob->fw->data;
3845 /* Validate firmware image by checking version. */
3846 if (blob->fw->size < 8 * sizeof(uint32_t)) {
3847 qla_printk(KERN_WARNING, ha,
3848 "Unable to verify integrity of firmware image (%Zd)!\n",
3850 goto fail_fw_integrity;
3852 for (i = 0; i < 4; i++)
3853 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3854 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3855 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3856 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3858 qla_printk(KERN_WARNING, ha,
3859 "Unable to verify integrity of firmware image!\n");
3860 qla_printk(KERN_WARNING, ha,
3861 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3862 dcode[1], dcode[2], dcode[3]);
3863 goto fail_fw_integrity;
3866 while (segments && rval == QLA_SUCCESS) {
3867 risc_addr = be32_to_cpu(fwcode[2]);
3868 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3869 risc_size = be32_to_cpu(fwcode[3]);
3871 /* Validate firmware image size. */
3872 fwclen += risc_size * sizeof(uint32_t);
3873 if (blob->fw->size < fwclen) {
3874 qla_printk(KERN_WARNING, ha,
3875 "Unable to verify integrity of firmware image "
3876 "(%Zd)!\n", blob->fw->size);
3878 goto fail_fw_integrity;
3882 while (risc_size > 0 && rval == QLA_SUCCESS) {
3883 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3884 if (dlen > risc_size)
3887 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3888 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3891 for (i = 0; i < dlen; i++)
3892 dcode[i] = swab32(fwcode[i]);
3894 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3897 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3898 "segment %d of firmware\n", ha->host_no,
3900 qla_printk(KERN_WARNING, ha,
3901 "[ERROR] Failed to load segment %d of "
3902 "firmware\n", fragment);
3918 return QLA_FUNCTION_FAILED;
3922 qla2x00_try_to_stop_firmware(scsi_qla_host_t *ha)
3926 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
3928 if (!ha->fw_major_version)
3931 ret = qla2x00_stop_firmware(ha);
3932 for (retries = 5; ret != QLA_SUCCESS && retries ; retries--) {
3933 qla2x00_reset_chip(ha);
3934 if (qla2x00_chip_diag(ha) != QLA_SUCCESS)
3936 if (qla2x00_setup_chip(ha) != QLA_SUCCESS)
3938 qla_printk(KERN_INFO, ha,
3939 "Attempting retry of stop-firmware command...\n");
3940 ret = qla2x00_stop_firmware(ha);