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"
19 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
20 #ifndef EXT_IS_LUN_BIT_SET
21 #define EXT_IS_LUN_BIT_SET(P,L) \
22 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
23 #define EXT_SET_LUN_BIT(P,L) \
24 ((P)->mask[L/8] |= (0x80 >> (L%8)))
28 * QLogic ISP2x00 Hardware Support Function Prototypes.
30 static int qla2x00_isp_firmware(scsi_qla_host_t *);
31 static void qla2x00_resize_request_q(scsi_qla_host_t *);
32 static int qla2x00_setup_chip(scsi_qla_host_t *);
33 static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
34 static int qla2x00_init_rings(scsi_qla_host_t *);
35 static int qla2x00_fw_ready(scsi_qla_host_t *);
36 static int qla2x00_configure_hba(scsi_qla_host_t *);
37 static int qla2x00_configure_loop(scsi_qla_host_t *);
38 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
39 static int qla2x00_configure_fabric(scsi_qla_host_t *);
40 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
41 static int qla2x00_device_resync(scsi_qla_host_t *);
42 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
45 static int qla2x00_restart_isp(scsi_qla_host_t *);
47 static int qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev);
49 /****************************************************************************/
50 /* QLogic ISP2x00 Hardware Support Functions. */
51 /****************************************************************************/
54 * qla2x00_initialize_adapter
58 * ha = adapter block pointer.
64 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
68 /* Clear adapter flags. */
70 ha->flags.reset_active = 0;
71 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
72 atomic_set(&ha->loop_state, LOOP_DOWN);
73 ha->device_flags = DFLG_NO_CABLE;
75 ha->flags.management_server_logged_in = 0;
76 ha->marker_needed = 0;
78 ha->isp_abort_cnt = 0;
79 ha->beacon_blink_led = 0;
80 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
82 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
83 rval = ha->isp_ops.pci_config(ha);
85 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
90 ha->isp_ops.reset_chip(ha);
92 ha->isp_ops.get_flash_version(ha, ha->request_ring);
94 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
96 ha->isp_ops.nvram_config(ha);
98 if (ha->flags.disable_serdes) {
99 /* Mask HBA via NVRAM settings? */
100 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
101 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
102 ha->port_name[0], ha->port_name[1],
103 ha->port_name[2], ha->port_name[3],
104 ha->port_name[4], ha->port_name[5],
105 ha->port_name[6], ha->port_name[7]);
106 return QLA_FUNCTION_FAILED;
109 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
111 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
112 rval = ha->isp_ops.chip_diag(ha);
115 rval = qla2x00_setup_chip(ha);
119 rval = qla2x00_init_rings(ha);
125 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
128 * Returns 0 on success.
131 qla2100_pci_config(scsi_qla_host_t *ha)
136 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
138 pci_set_master(ha->pdev);
140 if (pci_set_mwi(ha->pdev))
141 mwi = PCI_COMMAND_INVALIDATE;
143 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
144 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
145 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
147 /* Reset expansion ROM address decode enable */
148 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
149 d &= ~PCI_ROM_ADDRESS_ENABLE;
150 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
152 /* Get PCI bus information. */
153 spin_lock_irqsave(&ha->hardware_lock, flags);
154 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
155 spin_unlock_irqrestore(&ha->hardware_lock, flags);
161 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
164 * Returns 0 on success.
167 qla2300_pci_config(scsi_qla_host_t *ha)
171 unsigned long flags = 0;
173 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
175 pci_set_master(ha->pdev);
177 if (pci_set_mwi(ha->pdev))
178 mwi = PCI_COMMAND_INVALIDATE;
180 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
181 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
183 if (IS_QLA2322(ha) || IS_QLA6322(ha))
184 w &= ~PCI_COMMAND_INTX_DISABLE;
187 * If this is a 2300 card and not 2312, reset the
188 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
189 * the 2310 also reports itself as a 2300 so we need to get the
190 * fb revision level -- a 6 indicates it really is a 2300 and
193 if (IS_QLA2300(ha)) {
194 spin_lock_irqsave(&ha->hardware_lock, flags);
197 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
198 for (cnt = 0; cnt < 30000; cnt++) {
199 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
205 /* Select FPM registers. */
206 WRT_REG_WORD(®->ctrl_status, 0x20);
207 RD_REG_WORD(®->ctrl_status);
209 /* Get the fb rev level */
210 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
212 if (ha->fb_rev == FPM_2300)
213 w &= ~PCI_COMMAND_INVALIDATE;
215 /* Deselect FPM registers. */
216 WRT_REG_WORD(®->ctrl_status, 0x0);
217 RD_REG_WORD(®->ctrl_status);
219 /* Release RISC module. */
220 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
221 for (cnt = 0; cnt < 30000; cnt++) {
222 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
228 spin_unlock_irqrestore(&ha->hardware_lock, flags);
230 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
232 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
234 /* Reset expansion ROM address decode enable */
235 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
236 d &= ~PCI_ROM_ADDRESS_ENABLE;
237 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
239 /* Get PCI bus information. */
240 spin_lock_irqsave(&ha->hardware_lock, flags);
241 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
242 spin_unlock_irqrestore(&ha->hardware_lock, flags);
248 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
251 * Returns 0 on success.
254 qla24xx_pci_config(scsi_qla_host_t *ha)
258 unsigned long flags = 0;
259 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
260 int pcix_cmd_reg, pcie_dctl_reg;
262 pci_set_master(ha->pdev);
264 if (pci_set_mwi(ha->pdev))
265 mwi = PCI_COMMAND_INVALIDATE;
267 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
268 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
269 w &= ~PCI_COMMAND_INTX_DISABLE;
270 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
272 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
274 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
275 pcix_cmd_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX);
279 pcix_cmd_reg += PCI_X_CMD;
280 pci_read_config_word(ha->pdev, pcix_cmd_reg, &pcix_cmd);
281 pcix_cmd &= ~PCI_X_CMD_MAX_READ;
283 pci_write_config_word(ha->pdev, pcix_cmd_reg, pcix_cmd);
286 /* PCIe -- adjust Maximum Read Request Size (2048). */
287 pcie_dctl_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
291 pcie_dctl_reg += PCI_EXP_DEVCTL;
292 pci_read_config_word(ha->pdev, pcie_dctl_reg, &pcie_dctl);
293 pcie_dctl &= ~PCI_EXP_DEVCTL_READRQ;
295 pci_write_config_word(ha->pdev, pcie_dctl_reg, pcie_dctl);
298 /* Reset expansion ROM address decode enable */
299 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
300 d &= ~PCI_ROM_ADDRESS_ENABLE;
301 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
303 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->chip_revision);
305 /* Get PCI bus information. */
306 spin_lock_irqsave(&ha->hardware_lock, flags);
307 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
308 spin_unlock_irqrestore(&ha->hardware_lock, flags);
314 * qla2x00_isp_firmware() - Choose firmware image.
317 * Returns 0 on success.
320 qla2x00_isp_firmware(scsi_qla_host_t *ha)
324 /* Assume loading risc code */
325 rval = QLA_FUNCTION_FAILED;
327 if (ha->flags.disable_risc_code_load) {
328 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
330 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
332 /* Verify checksum of loaded RISC code. */
333 rval = qla2x00_verify_checksum(ha, ha->fw_srisc_address);
337 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
345 * qla2x00_reset_chip() - Reset ISP chip.
348 * Returns 0 on success.
351 qla2x00_reset_chip(scsi_qla_host_t *ha)
353 unsigned long flags = 0;
354 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
358 ha->isp_ops.disable_intrs(ha);
360 spin_lock_irqsave(&ha->hardware_lock, flags);
362 /* Turn off master enable */
364 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
365 cmd &= ~PCI_COMMAND_MASTER;
366 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
368 if (!IS_QLA2100(ha)) {
370 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
371 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
372 for (cnt = 0; cnt < 30000; cnt++) {
373 if ((RD_REG_WORD(®->hccr) &
374 HCCR_RISC_PAUSE) != 0)
379 RD_REG_WORD(®->hccr); /* PCI Posting. */
383 /* Select FPM registers. */
384 WRT_REG_WORD(®->ctrl_status, 0x20);
385 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
387 /* FPM Soft Reset. */
388 WRT_REG_WORD(®->fpm_diag_config, 0x100);
389 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
391 /* Toggle Fpm Reset. */
392 if (!IS_QLA2200(ha)) {
393 WRT_REG_WORD(®->fpm_diag_config, 0x0);
394 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
397 /* Select frame buffer registers. */
398 WRT_REG_WORD(®->ctrl_status, 0x10);
399 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
401 /* Reset frame buffer FIFOs. */
402 if (IS_QLA2200(ha)) {
403 WRT_FB_CMD_REG(ha, reg, 0xa000);
404 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
406 WRT_FB_CMD_REG(ha, reg, 0x00fc);
408 /* Read back fb_cmd until zero or 3 seconds max */
409 for (cnt = 0; cnt < 3000; cnt++) {
410 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
416 /* Select RISC module registers. */
417 WRT_REG_WORD(®->ctrl_status, 0);
418 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
420 /* Reset RISC processor. */
421 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
422 RD_REG_WORD(®->hccr); /* PCI Posting. */
424 /* Release RISC processor. */
425 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
426 RD_REG_WORD(®->hccr); /* PCI Posting. */
429 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
430 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
432 /* Reset ISP chip. */
433 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
435 /* Wait for RISC to recover from reset. */
436 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
438 * It is necessary to for a delay here since the card doesn't
439 * respond to PCI reads during a reset. On some architectures
440 * this will result in an MCA.
443 for (cnt = 30000; cnt; cnt--) {
444 if ((RD_REG_WORD(®->ctrl_status) &
445 CSR_ISP_SOFT_RESET) == 0)
452 /* Reset RISC processor. */
453 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
455 WRT_REG_WORD(®->semaphore, 0);
457 /* Release RISC processor. */
458 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
459 RD_REG_WORD(®->hccr); /* PCI Posting. */
461 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
462 for (cnt = 0; cnt < 30000; cnt++) {
463 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
471 /* Turn on master enable */
472 cmd |= PCI_COMMAND_MASTER;
473 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
475 /* Disable RISC pause on FPM parity error. */
476 if (!IS_QLA2100(ha)) {
477 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
478 RD_REG_WORD(®->hccr); /* PCI Posting. */
481 spin_unlock_irqrestore(&ha->hardware_lock, flags);
485 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
488 * Returns 0 on success.
491 qla24xx_reset_risc(scsi_qla_host_t *ha)
493 unsigned long flags = 0;
494 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
498 spin_lock_irqsave(&ha->hardware_lock, flags);
501 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
502 for (cnt = 0; cnt < 30000; cnt++) {
503 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
509 WRT_REG_DWORD(®->ctrl_status,
510 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
511 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
514 /* Wait for firmware to complete NVRAM accesses. */
515 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
516 for (cnt = 10000 ; cnt && d2; cnt--) {
518 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
522 /* Wait for soft-reset to complete. */
523 d2 = RD_REG_DWORD(®->ctrl_status);
524 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
526 d2 = RD_REG_DWORD(®->ctrl_status);
530 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
531 RD_REG_DWORD(®->hccr);
533 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
534 RD_REG_DWORD(®->hccr);
536 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
537 RD_REG_DWORD(®->hccr);
539 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
540 for (cnt = 6000000 ; cnt && d2; cnt--) {
542 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
546 spin_unlock_irqrestore(&ha->hardware_lock, flags);
550 * qla24xx_reset_chip() - Reset ISP24xx chip.
553 * Returns 0 on success.
556 qla24xx_reset_chip(scsi_qla_host_t *ha)
558 ha->isp_ops.disable_intrs(ha);
560 /* Perform RISC reset. */
561 qla24xx_reset_risc(ha);
565 * qla2x00_chip_diag() - Test chip for proper operation.
568 * Returns 0 on success.
571 qla2x00_chip_diag(scsi_qla_host_t *ha)
574 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
575 unsigned long flags = 0;
580 /* Assume a failed state */
581 rval = QLA_FUNCTION_FAILED;
583 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
584 ha->host_no, (u_long)®->flash_address));
586 spin_lock_irqsave(&ha->hardware_lock, flags);
588 /* Reset ISP chip. */
589 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
592 * We need to have a delay here since the card will not respond while
593 * in reset causing an MCA on some architectures.
596 data = qla2x00_debounce_register(®->ctrl_status);
597 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
599 data = RD_REG_WORD(®->ctrl_status);
604 goto chip_diag_failed;
606 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
609 /* Reset RISC processor. */
610 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
611 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
613 /* Workaround for QLA2312 PCI parity error */
614 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
615 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
616 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
618 data = RD_MAILBOX_REG(ha, reg, 0);
625 goto chip_diag_failed;
627 /* Check product ID of chip */
628 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
630 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
631 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
632 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
633 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
634 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
635 mb[3] != PROD_ID_3) {
636 qla_printk(KERN_WARNING, ha,
637 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
639 goto chip_diag_failed;
641 ha->product_id[0] = mb[1];
642 ha->product_id[1] = mb[2];
643 ha->product_id[2] = mb[3];
644 ha->product_id[3] = mb[4];
646 /* Adjust fw RISC transfer size */
647 if (ha->request_q_length > 1024)
648 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
650 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
651 ha->request_q_length;
653 if (IS_QLA2200(ha) &&
654 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
655 /* Limit firmware transfer size with a 2200A */
656 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
659 ha->device_type |= DT_ISP2200A;
660 ha->fw_transfer_size = 128;
663 /* Wrap Incoming Mailboxes Test. */
664 spin_unlock_irqrestore(&ha->hardware_lock, flags);
666 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
667 rval = qla2x00_mbx_reg_test(ha);
669 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
671 qla_printk(KERN_WARNING, ha,
672 "Failed mailbox send register test\n");
675 /* Flag a successful rval */
678 spin_lock_irqsave(&ha->hardware_lock, flags);
682 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
683 "****\n", ha->host_no));
685 spin_unlock_irqrestore(&ha->hardware_lock, flags);
691 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
694 * Returns 0 on success.
697 qla24xx_chip_diag(scsi_qla_host_t *ha)
701 /* Perform RISC reset. */
702 qla24xx_reset_risc(ha);
704 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
706 rval = qla2x00_mbx_reg_test(ha);
708 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
710 qla_printk(KERN_WARNING, ha,
711 "Failed mailbox send register test\n");
713 /* Flag a successful rval */
721 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
724 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
730 qla_printk(KERN_WARNING, ha,
731 "Firmware dump previously allocated.\n");
736 fixed_size = mem_size = eft_size = 0;
737 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
738 fixed_size = sizeof(struct qla2100_fw_dump);
739 } else if (IS_QLA23XX(ha)) {
740 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
741 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
743 } else if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
744 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
745 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
748 /* Allocate memory for Extended Trace Buffer. */
749 eft = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &eft_dma,
752 qla_printk(KERN_WARNING, ha, "Unable to allocate "
753 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
757 rval = qla2x00_trace_control(ha, TC_ENABLE, eft_dma,
760 qla_printk(KERN_WARNING, ha, "Unable to initialize "
761 "EFT (%d).\n", rval);
762 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, eft,
767 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
771 memset(eft, 0, eft_size);
772 ha->eft_dma = eft_dma;
776 req_q_size = ha->request_q_length * sizeof(request_t);
777 rsp_q_size = ha->response_q_length * sizeof(response_t);
779 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
780 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
783 ha->fw_dump = vmalloc(dump_size);
785 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
786 "firmware dump!!!\n", dump_size / 1024);
789 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
797 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
800 ha->fw_dump_len = dump_size;
801 ha->fw_dump->signature[0] = 'Q';
802 ha->fw_dump->signature[1] = 'L';
803 ha->fw_dump->signature[2] = 'G';
804 ha->fw_dump->signature[3] = 'C';
805 ha->fw_dump->version = __constant_htonl(1);
807 ha->fw_dump->fixed_size = htonl(fixed_size);
808 ha->fw_dump->mem_size = htonl(mem_size);
809 ha->fw_dump->req_q_size = htonl(req_q_size);
810 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
812 ha->fw_dump->eft_size = htonl(eft_size);
813 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
814 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
816 ha->fw_dump->header_size =
817 htonl(offsetof(struct qla2xxx_fw_dump, isp));
821 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
824 * Returns 0 on success.
827 qla2x00_resize_request_q(scsi_qla_host_t *ha)
830 uint16_t fw_iocb_cnt = 0;
831 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
832 dma_addr_t request_dma;
833 request_t *request_ring;
835 /* Valid only on recent ISPs. */
836 if (IS_QLA2100(ha) || IS_QLA2200(ha))
839 /* Retrieve IOCB counts available to the firmware. */
840 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
843 /* No point in continuing if current settings are sufficient. */
844 if (fw_iocb_cnt < 1024)
846 if (ha->request_q_length >= request_q_length)
849 /* Attempt to claim larger area for request queue. */
850 request_ring = dma_alloc_coherent(&ha->pdev->dev,
851 (request_q_length + 1) * sizeof(request_t), &request_dma,
853 if (request_ring == NULL)
856 /* Resize successful, report extensions. */
857 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
858 (ha->fw_memory_size + 1) / 1024);
859 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
860 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
862 /* Clear old allocations. */
863 dma_free_coherent(&ha->pdev->dev,
864 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
867 /* Begin using larger queue. */
868 ha->request_q_length = request_q_length;
869 ha->request_ring = request_ring;
870 ha->request_dma = request_dma;
874 * qla2x00_setup_chip() - Load and start RISC firmware.
877 * Returns 0 on success.
880 qla2x00_setup_chip(scsi_qla_host_t *ha)
883 uint32_t srisc_address = 0;
885 /* Load firmware sequences */
886 rval = ha->isp_ops.load_risc(ha, &srisc_address);
887 if (rval == QLA_SUCCESS) {
888 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
889 "code.\n", ha->host_no));
891 rval = qla2x00_verify_checksum(ha, srisc_address);
892 if (rval == QLA_SUCCESS) {
893 /* Start firmware execution. */
894 DEBUG(printk("scsi(%ld): Checksum OK, start "
895 "firmware.\n", ha->host_no));
897 rval = qla2x00_execute_fw(ha, srisc_address);
898 /* Retrieve firmware information. */
899 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
900 qla2x00_get_fw_version(ha,
901 &ha->fw_major_version,
902 &ha->fw_minor_version,
903 &ha->fw_subminor_version,
904 &ha->fw_attributes, &ha->fw_memory_size);
905 qla2x00_resize_request_q(ha);
908 qla2x00_alloc_fw_dump(ha);
911 DEBUG2(printk(KERN_INFO
912 "scsi(%ld): ISP Firmware failed checksum.\n",
918 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
926 * qla2x00_init_response_q_entries() - Initializes response queue entries.
929 * Beginning of request ring has initialization control block already built
930 * by nvram config routine.
932 * Returns 0 on success.
935 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
940 pkt = ha->response_ring_ptr;
941 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
942 pkt->signature = RESPONSE_PROCESSED;
949 * qla2x00_update_fw_options() - Read and process firmware options.
952 * Returns 0 on success.
955 qla2x00_update_fw_options(scsi_qla_host_t *ha)
957 uint16_t swing, emphasis, tx_sens, rx_sens;
959 memset(ha->fw_options, 0, sizeof(ha->fw_options));
960 qla2x00_get_fw_options(ha, ha->fw_options);
962 if (IS_QLA2100(ha) || IS_QLA2200(ha))
965 /* Serial Link options. */
966 DEBUG3(printk("scsi(%ld): Serial link options:\n",
968 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
969 sizeof(ha->fw_seriallink_options)));
971 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
972 if (ha->fw_seriallink_options[3] & BIT_2) {
973 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
976 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
977 emphasis = (ha->fw_seriallink_options[2] &
978 (BIT_4 | BIT_3)) >> 3;
979 tx_sens = ha->fw_seriallink_options[0] &
980 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
981 rx_sens = (ha->fw_seriallink_options[0] &
982 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
983 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
984 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
987 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
988 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
989 ha->fw_options[10] |= BIT_5 |
990 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
991 (tx_sens & (BIT_1 | BIT_0));
994 swing = (ha->fw_seriallink_options[2] &
995 (BIT_7 | BIT_6 | BIT_5)) >> 5;
996 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
997 tx_sens = ha->fw_seriallink_options[1] &
998 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
999 rx_sens = (ha->fw_seriallink_options[1] &
1000 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1001 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1002 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1005 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1006 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1007 ha->fw_options[11] |= BIT_5 |
1008 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1009 (tx_sens & (BIT_1 | BIT_0));
1013 /* Return command IOCBs without waiting for an ABTS to complete. */
1014 ha->fw_options[3] |= BIT_13;
1017 if (ha->flags.enable_led_scheme)
1018 ha->fw_options[2] |= BIT_12;
1020 /* Detect ISP6312. */
1022 ha->fw_options[2] |= BIT_13;
1024 /* Update firmware options. */
1025 qla2x00_set_fw_options(ha, ha->fw_options);
1029 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1033 /* Update Serial Link options. */
1034 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1037 rval = qla2x00_set_serdes_params(ha,
1038 le16_to_cpu(ha->fw_seriallink_options24[1]),
1039 le16_to_cpu(ha->fw_seriallink_options24[2]),
1040 le16_to_cpu(ha->fw_seriallink_options24[3]));
1041 if (rval != QLA_SUCCESS) {
1042 qla_printk(KERN_WARNING, ha,
1043 "Unable to update Serial Link options (%x).\n", rval);
1048 qla2x00_config_rings(struct scsi_qla_host *ha)
1050 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1052 /* Setup ring parameters in initialization control block. */
1053 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1054 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1055 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1056 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1057 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1058 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1059 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1060 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1062 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1063 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1064 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1065 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1066 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1070 qla24xx_config_rings(struct scsi_qla_host *ha)
1072 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1073 struct init_cb_24xx *icb;
1075 /* Setup ring parameters in initialization control block. */
1076 icb = (struct init_cb_24xx *)ha->init_cb;
1077 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1078 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1079 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1080 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1081 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1082 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1083 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1084 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1086 WRT_REG_DWORD(®->req_q_in, 0);
1087 WRT_REG_DWORD(®->req_q_out, 0);
1088 WRT_REG_DWORD(®->rsp_q_in, 0);
1089 WRT_REG_DWORD(®->rsp_q_out, 0);
1090 RD_REG_DWORD(®->rsp_q_out);
1094 * qla2x00_init_rings() - Initializes firmware.
1097 * Beginning of request ring has initialization control block already built
1098 * by nvram config routine.
1100 * Returns 0 on success.
1103 qla2x00_init_rings(scsi_qla_host_t *ha)
1106 unsigned long flags = 0;
1109 spin_lock_irqsave(&ha->hardware_lock, flags);
1111 /* Clear outstanding commands array. */
1112 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1113 ha->outstanding_cmds[cnt] = NULL;
1115 ha->current_outstanding_cmd = 0;
1117 /* Clear RSCN queue. */
1118 ha->rscn_in_ptr = 0;
1119 ha->rscn_out_ptr = 0;
1121 /* Initialize firmware. */
1122 ha->request_ring_ptr = ha->request_ring;
1123 ha->req_ring_index = 0;
1124 ha->req_q_cnt = ha->request_q_length;
1125 ha->response_ring_ptr = ha->response_ring;
1126 ha->rsp_ring_index = 0;
1128 /* Initialize response queue entries */
1129 qla2x00_init_response_q_entries(ha);
1131 ha->isp_ops.config_rings(ha);
1133 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1135 /* Update any ISP specific firmware options before initialization. */
1136 ha->isp_ops.update_fw_options(ha);
1138 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1139 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1141 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1144 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1152 * qla2x00_fw_ready() - Waits for firmware ready.
1155 * Returns 0 on success.
1158 qla2x00_fw_ready(scsi_qla_host_t *ha)
1161 unsigned long wtime, mtime;
1162 uint16_t min_wait; /* Minimum wait time if loop is down */
1163 uint16_t wait_time; /* Wait time if loop is coming ready */
1168 /* 20 seconds for loop down. */
1172 * Firmware should take at most one RATOV to login, plus 5 seconds for
1173 * our own processing.
1175 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1176 wait_time = min_wait;
1179 /* Min wait time if loop down */
1180 mtime = jiffies + (min_wait * HZ);
1182 /* wait time before firmware ready */
1183 wtime = jiffies + (wait_time * HZ);
1185 /* Wait for ISP to finish LIP */
1186 if (!ha->flags.init_done)
1187 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1189 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1193 rval = qla2x00_get_firmware_state(ha, &fw_state);
1194 if (rval == QLA_SUCCESS) {
1195 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1196 ha->device_flags &= ~DFLG_NO_CABLE;
1198 if (fw_state == FSTATE_READY) {
1199 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1202 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1203 &ha->login_timeout, &ha->r_a_tov);
1209 rval = QLA_FUNCTION_FAILED;
1211 if (atomic_read(&ha->loop_down_timer) &&
1212 fw_state != FSTATE_READY) {
1213 /* Loop down. Timeout on min_wait for states
1214 * other than Wait for Login.
1216 if (time_after_eq(jiffies, mtime)) {
1217 qla_printk(KERN_INFO, ha,
1218 "Cable is unplugged...\n");
1220 ha->device_flags |= DFLG_NO_CABLE;
1225 /* Mailbox cmd failed. Timeout on min_wait. */
1226 if (time_after_eq(jiffies, mtime))
1230 if (time_after_eq(jiffies, wtime))
1233 /* Delay for a while */
1236 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1237 ha->host_no, fw_state, jiffies));
1240 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1241 ha->host_no, fw_state, jiffies));
1244 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1252 * qla2x00_configure_hba
1253 * Setup adapter context.
1256 * ha = adapter state pointer.
1265 qla2x00_configure_hba(scsi_qla_host_t *ha)
1273 char connect_type[22];
1275 /* Get host addresses. */
1276 rval = qla2x00_get_adapter_id(ha,
1277 &loop_id, &al_pa, &area, &domain, &topo);
1278 if (rval != QLA_SUCCESS) {
1279 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
1280 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1281 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1282 __func__, ha->host_no));
1284 qla_printk(KERN_WARNING, ha,
1285 "ERROR -- Unable to get host loop ID.\n");
1286 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1292 qla_printk(KERN_INFO, ha,
1293 "Cannot get topology - retrying.\n");
1294 return (QLA_FUNCTION_FAILED);
1297 ha->loop_id = loop_id;
1300 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1301 ha->operating_mode = LOOP;
1305 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1307 ha->current_topology = ISP_CFG_NL;
1308 strcpy(connect_type, "(Loop)");
1312 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1314 ha->current_topology = ISP_CFG_FL;
1315 strcpy(connect_type, "(FL_Port)");
1319 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1321 ha->operating_mode = P2P;
1322 ha->current_topology = ISP_CFG_N;
1323 strcpy(connect_type, "(N_Port-to-N_Port)");
1327 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1329 ha->operating_mode = P2P;
1330 ha->current_topology = ISP_CFG_F;
1331 strcpy(connect_type, "(F_Port)");
1335 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1337 ha->host_no, topo));
1338 ha->current_topology = ISP_CFG_NL;
1339 strcpy(connect_type, "(Loop)");
1343 /* Save Host port and loop ID. */
1344 /* byte order - Big Endian */
1345 ha->d_id.b.domain = domain;
1346 ha->d_id.b.area = area;
1347 ha->d_id.b.al_pa = al_pa;
1349 if (!ha->flags.init_done)
1350 qla_printk(KERN_INFO, ha,
1351 "Topology - %s, Host Loop address 0x%x\n",
1352 connect_type, ha->loop_id);
1355 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1357 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1364 qla2x00_set_model_info(scsi_qla_host_t *ha, uint8_t *model, size_t len, char *def)
1369 if (memcmp(model, BINZERO, len) != 0) {
1370 strncpy(ha->model_number, model, len);
1371 st = en = ha->model_number;
1374 if (*en != 0x20 && *en != 0x00)
1379 index = (ha->pdev->subsystem_device & 0xff);
1380 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1381 index < QLA_MODEL_NAMES)
1382 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1384 index = (ha->pdev->subsystem_device & 0xff);
1385 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1386 index < QLA_MODEL_NAMES) {
1387 strcpy(ha->model_number,
1388 qla2x00_model_name[index * 2]);
1389 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1391 strcpy(ha->model_number, def);
1396 /* On sparc systems, obtain port and node WWN from firmware
1399 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, nvram_t *nv)
1402 struct pci_dev *pdev = ha->pdev;
1403 struct pcidev_cookie *pcp = pdev->sysdata;
1404 struct device_node *dp = pcp->prom_node;
1408 val = of_get_property(dp, "port-wwn", &len);
1409 if (val && len >= WWN_SIZE)
1410 memcpy(nv->port_name, val, WWN_SIZE);
1412 val = of_get_property(dp, "node-wwn", &len);
1413 if (val && len >= WWN_SIZE)
1414 memcpy(nv->node_name, val, WWN_SIZE);
1419 * NVRAM configuration for ISP 2xxx
1422 * ha = adapter block pointer.
1425 * initialization control block in response_ring
1426 * host adapters parameters in host adapter block
1432 qla2x00_nvram_config(scsi_qla_host_t *ha)
1437 uint8_t *dptr1, *dptr2;
1438 init_cb_t *icb = ha->init_cb;
1439 nvram_t *nv = (nvram_t *)ha->request_ring;
1440 uint8_t *ptr = (uint8_t *)ha->request_ring;
1441 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1445 /* Determine NVRAM starting address. */
1446 ha->nvram_size = sizeof(nvram_t);
1448 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1449 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1450 ha->nvram_base = 0x80;
1452 /* Get NVRAM data and calculate checksum. */
1453 ha->isp_ops.read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1454 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1457 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1458 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1461 /* Bad NVRAM data, set defaults parameters. */
1462 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1463 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1464 /* Reset NVRAM data. */
1465 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1466 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1468 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1469 "invalid -- WWPN) defaults.\n");
1472 * Set default initialization control block.
1474 memset(nv, 0, ha->nvram_size);
1475 nv->parameter_block_version = ICB_VERSION;
1477 if (IS_QLA23XX(ha)) {
1478 nv->firmware_options[0] = BIT_2 | BIT_1;
1479 nv->firmware_options[1] = BIT_7 | BIT_5;
1480 nv->add_firmware_options[0] = BIT_5;
1481 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1482 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1483 nv->special_options[1] = BIT_7;
1484 } else if (IS_QLA2200(ha)) {
1485 nv->firmware_options[0] = BIT_2 | BIT_1;
1486 nv->firmware_options[1] = BIT_7 | BIT_5;
1487 nv->add_firmware_options[0] = BIT_5;
1488 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1489 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1490 } else if (IS_QLA2100(ha)) {
1491 nv->firmware_options[0] = BIT_3 | BIT_1;
1492 nv->firmware_options[1] = BIT_5;
1493 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1496 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1497 nv->execution_throttle = __constant_cpu_to_le16(16);
1498 nv->retry_count = 8;
1499 nv->retry_delay = 1;
1501 nv->port_name[0] = 33;
1502 nv->port_name[3] = 224;
1503 nv->port_name[4] = 139;
1505 qla2xxx_nvram_wwn_from_ofw(ha, nv);
1507 nv->login_timeout = 4;
1510 * Set default host adapter parameters
1512 nv->host_p[1] = BIT_2;
1513 nv->reset_delay = 5;
1514 nv->port_down_retry_count = 8;
1515 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1516 nv->link_down_timeout = 60;
1521 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1523 * The SN2 does not provide BIOS emulation which means you can't change
1524 * potentially bogus BIOS settings. Force the use of default settings
1525 * for link rate and frame size. Hope that the rest of the settings
1528 if (ia64_platform_is("sn2")) {
1529 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1531 nv->special_options[1] = BIT_7;
1535 /* Reset Initialization control block */
1536 memset(icb, 0, ha->init_cb_size);
1539 * Setup driver NVRAM options.
1541 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1542 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1543 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1544 nv->firmware_options[1] &= ~BIT_4;
1546 if (IS_QLA23XX(ha)) {
1547 nv->firmware_options[0] |= BIT_2;
1548 nv->firmware_options[0] &= ~BIT_3;
1549 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1551 if (IS_QLA2300(ha)) {
1552 if (ha->fb_rev == FPM_2310) {
1553 strcpy(ha->model_number, "QLA2310");
1555 strcpy(ha->model_number, "QLA2300");
1558 qla2x00_set_model_info(ha, nv->model_number,
1559 sizeof(nv->model_number), "QLA23xx");
1561 } else if (IS_QLA2200(ha)) {
1562 nv->firmware_options[0] |= BIT_2;
1564 * 'Point-to-point preferred, else loop' is not a safe
1565 * connection mode setting.
1567 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1569 /* Force 'loop preferred, else point-to-point'. */
1570 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1571 nv->add_firmware_options[0] |= BIT_5;
1573 strcpy(ha->model_number, "QLA22xx");
1574 } else /*if (IS_QLA2100(ha))*/ {
1575 strcpy(ha->model_number, "QLA2100");
1579 * Copy over NVRAM RISC parameter block to initialization control block.
1581 dptr1 = (uint8_t *)icb;
1582 dptr2 = (uint8_t *)&nv->parameter_block_version;
1583 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1585 *dptr1++ = *dptr2++;
1587 /* Copy 2nd half. */
1588 dptr1 = (uint8_t *)icb->add_firmware_options;
1589 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1591 *dptr1++ = *dptr2++;
1593 /* Use alternate WWN? */
1594 if (nv->host_p[1] & BIT_7) {
1595 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1596 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1599 /* Prepare nodename */
1600 if ((icb->firmware_options[1] & BIT_6) == 0) {
1602 * Firmware will apply the following mask if the nodename was
1605 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1606 icb->node_name[0] &= 0xF0;
1610 * Set host adapter parameters.
1612 if (nv->host_p[0] & BIT_7)
1613 ql2xextended_error_logging = 1;
1614 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1615 /* Always load RISC code on non ISP2[12]00 chips. */
1616 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1617 ha->flags.disable_risc_code_load = 0;
1618 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1619 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1620 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1621 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1622 ha->flags.disable_serdes = 0;
1624 ha->operating_mode =
1625 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1627 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1628 sizeof(ha->fw_seriallink_options));
1630 /* save HBA serial number */
1631 ha->serial0 = icb->port_name[5];
1632 ha->serial1 = icb->port_name[6];
1633 ha->serial2 = icb->port_name[7];
1634 ha->node_name = icb->node_name;
1635 ha->port_name = icb->port_name;
1637 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1639 ha->retry_count = nv->retry_count;
1641 /* Set minimum login_timeout to 4 seconds. */
1642 if (nv->login_timeout < ql2xlogintimeout)
1643 nv->login_timeout = ql2xlogintimeout;
1644 if (nv->login_timeout < 4)
1645 nv->login_timeout = 4;
1646 ha->login_timeout = nv->login_timeout;
1647 icb->login_timeout = nv->login_timeout;
1649 /* Set minimum RATOV to 200 tenths of a second. */
1652 ha->loop_reset_delay = nv->reset_delay;
1654 /* Link Down Timeout = 0:
1656 * When Port Down timer expires we will start returning
1657 * I/O's to OS with "DID_NO_CONNECT".
1659 * Link Down Timeout != 0:
1661 * The driver waits for the link to come up after link down
1662 * before returning I/Os to OS with "DID_NO_CONNECT".
1664 if (nv->link_down_timeout == 0) {
1665 ha->loop_down_abort_time =
1666 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1668 ha->link_down_timeout = nv->link_down_timeout;
1669 ha->loop_down_abort_time =
1670 (LOOP_DOWN_TIME - ha->link_down_timeout);
1674 * Need enough time to try and get the port back.
1676 ha->port_down_retry_count = nv->port_down_retry_count;
1677 if (qlport_down_retry)
1678 ha->port_down_retry_count = qlport_down_retry;
1679 /* Set login_retry_count */
1680 ha->login_retry_count = nv->retry_count;
1681 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1682 ha->port_down_retry_count > 3)
1683 ha->login_retry_count = ha->port_down_retry_count;
1684 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1685 ha->login_retry_count = ha->port_down_retry_count;
1686 if (ql2xloginretrycount)
1687 ha->login_retry_count = ql2xloginretrycount;
1689 icb->lun_enables = __constant_cpu_to_le16(0);
1690 icb->command_resource_count = 0;
1691 icb->immediate_notify_resource_count = 0;
1692 icb->timeout = __constant_cpu_to_le16(0);
1694 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1696 icb->firmware_options[0] &= ~BIT_3;
1697 icb->add_firmware_options[0] &=
1698 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1699 icb->add_firmware_options[0] |= BIT_2;
1700 icb->response_accumulation_timer = 3;
1701 icb->interrupt_delay_timer = 5;
1703 ha->flags.process_response_queue = 1;
1706 if (!ha->flags.init_done) {
1707 ha->zio_mode = icb->add_firmware_options[0] &
1708 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1709 ha->zio_timer = icb->interrupt_delay_timer ?
1710 icb->interrupt_delay_timer: 2;
1712 icb->add_firmware_options[0] &=
1713 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1714 ha->flags.process_response_queue = 0;
1715 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1716 ha->zio_mode = QLA_ZIO_MODE_6;
1718 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1719 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1720 ha->zio_timer * 100));
1721 qla_printk(KERN_INFO, ha,
1722 "ZIO mode %d enabled; timer delay (%d us).\n",
1723 ha->zio_mode, ha->zio_timer * 100);
1725 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1726 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1727 ha->flags.process_response_queue = 1;
1732 DEBUG2_3(printk(KERN_WARNING
1733 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1739 qla2x00_rport_del(void *data)
1741 fc_port_t *fcport = data;
1742 struct fc_rport *rport;
1743 unsigned long flags;
1745 spin_lock_irqsave(&fcport->rport_lock, flags);
1746 rport = fcport->drport;
1747 fcport->drport = NULL;
1748 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1750 fc_remote_port_delete(rport);
1755 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1757 * @flags: allocation flags
1759 * Returns a pointer to the allocated fcport, or NULL, if none available.
1762 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1766 fcport = kmalloc(sizeof(fc_port_t), flags);
1770 /* Setup fcport template structure. */
1771 memset(fcport, 0, sizeof (fc_port_t));
1773 fcport->port_type = FCT_UNKNOWN;
1774 fcport->loop_id = FC_NO_LOOP_ID;
1775 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1776 fcport->flags = FCF_RLC_SUPPORT;
1777 fcport->supported_classes = FC_COS_UNSPECIFIED;
1778 spin_lock_init(&fcport->rport_lock);
1784 * qla2x00_configure_loop
1785 * Updates Fibre Channel Device Database with what is actually on loop.
1788 * ha = adapter block pointer.
1793 * 2 = database was full and device was not configured.
1796 qla2x00_configure_loop(scsi_qla_host_t *ha)
1799 unsigned long flags, save_flags;
1803 /* Get Initiator ID */
1804 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1805 rval = qla2x00_configure_hba(ha);
1806 if (rval != QLA_SUCCESS) {
1807 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1813 save_flags = flags = ha->dpc_flags;
1814 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1815 ha->host_no, flags));
1818 * If we have both an RSCN and PORT UPDATE pending then handle them
1819 * both at the same time.
1821 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1822 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1824 /* Determine what we need to do */
1825 if (ha->current_topology == ISP_CFG_FL &&
1826 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1828 ha->flags.rscn_queue_overflow = 1;
1829 set_bit(RSCN_UPDATE, &flags);
1831 } else if (ha->current_topology == ISP_CFG_F &&
1832 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1834 ha->flags.rscn_queue_overflow = 1;
1835 set_bit(RSCN_UPDATE, &flags);
1836 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1838 } else if (ha->current_topology == ISP_CFG_N) {
1839 clear_bit(RSCN_UPDATE, &flags);
1841 } else if (!ha->flags.online ||
1842 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1844 ha->flags.rscn_queue_overflow = 1;
1845 set_bit(RSCN_UPDATE, &flags);
1846 set_bit(LOCAL_LOOP_UPDATE, &flags);
1849 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1850 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1851 rval = QLA_FUNCTION_FAILED;
1853 rval = qla2x00_configure_local_loop(ha);
1857 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1858 if (LOOP_TRANSITION(ha)) {
1859 rval = QLA_FUNCTION_FAILED;
1861 rval = qla2x00_configure_fabric(ha);
1865 if (rval == QLA_SUCCESS) {
1866 if (atomic_read(&ha->loop_down_timer) ||
1867 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1868 rval = QLA_FUNCTION_FAILED;
1870 atomic_set(&ha->loop_state, LOOP_READY);
1872 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1877 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1878 __func__, ha->host_no));
1880 DEBUG3(printk("%s: exiting normally\n", __func__));
1883 /* Restore state if a resync event occured during processing */
1884 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1885 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1886 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1887 if (test_bit(RSCN_UPDATE, &save_flags))
1888 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1897 * qla2x00_configure_local_loop
1898 * Updates Fibre Channel Device Database with local loop devices.
1901 * ha = adapter block pointer.
1907 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1912 fc_port_t *fcport, *new_fcport;
1918 uint8_t domain, area, al_pa;
1922 entries = MAX_FIBRE_DEVICES;
1924 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1925 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1927 /* Get list of logged in devices. */
1928 memset(ha->gid_list, 0, GID_LIST_SIZE);
1929 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1931 if (rval != QLA_SUCCESS)
1932 goto cleanup_allocation;
1934 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1935 ha->host_no, entries));
1936 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1937 entries * sizeof(struct gid_list_info)));
1939 /* Allocate temporary fcport for any new fcports discovered. */
1940 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1941 if (new_fcport == NULL) {
1942 rval = QLA_MEMORY_ALLOC_FAILED;
1943 goto cleanup_allocation;
1945 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1948 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1950 list_for_each_entry(fcport, &ha->fcports, list) {
1951 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1952 fcport->port_type != FCT_BROADCAST &&
1953 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1955 DEBUG(printk("scsi(%ld): Marking port lost, "
1957 ha->host_no, fcport->loop_id));
1959 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1960 fcport->flags &= ~FCF_FARP_DONE;
1964 /* Add devices to port list. */
1965 id_iter = (char *)ha->gid_list;
1966 for (index = 0; index < entries; index++) {
1967 domain = ((struct gid_list_info *)id_iter)->domain;
1968 area = ((struct gid_list_info *)id_iter)->area;
1969 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1970 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1971 loop_id = (uint16_t)
1972 ((struct gid_list_info *)id_iter)->loop_id_2100;
1974 loop_id = le16_to_cpu(
1975 ((struct gid_list_info *)id_iter)->loop_id);
1976 id_iter += ha->gid_list_info_size;
1978 /* Bypass reserved domain fields. */
1979 if ((domain & 0xf0) == 0xf0)
1982 /* Bypass if not same domain and area of adapter. */
1983 if (area && domain &&
1984 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
1987 /* Bypass invalid local loop ID. */
1988 if (loop_id > LAST_LOCAL_LOOP_ID)
1991 /* Fill in member data. */
1992 new_fcport->d_id.b.domain = domain;
1993 new_fcport->d_id.b.area = area;
1994 new_fcport->d_id.b.al_pa = al_pa;
1995 new_fcport->loop_id = loop_id;
1996 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1997 if (rval2 != QLA_SUCCESS) {
1998 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1999 "information -- get_port_database=%x, "
2001 ha->host_no, rval2, new_fcport->loop_id));
2002 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2004 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2008 /* Check for matching device in port list. */
2011 list_for_each_entry(fcport, &ha->fcports, list) {
2012 if (memcmp(new_fcport->port_name, fcport->port_name,
2016 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2017 FCF_PERSISTENT_BOUND);
2018 fcport->loop_id = new_fcport->loop_id;
2019 fcport->port_type = new_fcport->port_type;
2020 fcport->d_id.b24 = new_fcport->d_id.b24;
2021 memcpy(fcport->node_name, new_fcport->node_name,
2029 /* New device, add to fcports list. */
2030 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
2031 list_add_tail(&new_fcport->list, &ha->fcports);
2033 /* Allocate a new replacement fcport. */
2034 fcport = new_fcport;
2035 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2036 if (new_fcport == NULL) {
2037 rval = QLA_MEMORY_ALLOC_FAILED;
2038 goto cleanup_allocation;
2040 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2043 /* Base iIDMA settings on HBA port speed. */
2044 switch (ha->link_data_rate) {
2045 case PORT_SPEED_1GB:
2046 fcport->fp_speed = cpu_to_be16(BIT_15);
2048 case PORT_SPEED_2GB:
2049 fcport->fp_speed = cpu_to_be16(BIT_14);
2051 case PORT_SPEED_4GB:
2052 fcport->fp_speed = cpu_to_be16(BIT_13);
2056 qla2x00_update_fcport(ha, fcport);
2064 if (rval != QLA_SUCCESS) {
2065 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2066 "rval=%x\n", ha->host_no, rval));
2070 ha->device_flags |= DFLG_LOCAL_DEVICES;
2071 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2078 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
2082 qla2x00_mark_all_devices_lost(ha, 0);
2083 list_for_each_entry(fcport, &ha->fcports, list) {
2084 if (fcport->port_type != FCT_TARGET)
2087 qla2x00_update_fcport(ha, fcport);
2092 qla2x00_iidma_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2094 #define LS_UNKNOWN 2
2095 static char *link_speeds[5] = { "1", "2", "?", "4" };
2097 uint16_t port_speed, mb[6];
2099 if (!IS_QLA24XX(ha))
2102 switch (be16_to_cpu(fcport->fp_speed)) {
2104 port_speed = PORT_SPEED_1GB;
2107 port_speed = PORT_SPEED_2GB;
2110 port_speed = PORT_SPEED_4GB;
2113 DEBUG2(printk("scsi(%ld): %02x%02x%02x%02x%02x%02x%02x%02x -- "
2114 "unsupported FM port operating speed (%04x).\n",
2115 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2116 fcport->port_name[2], fcport->port_name[3],
2117 fcport->port_name[4], fcport->port_name[5],
2118 fcport->port_name[6], fcport->port_name[7],
2119 be16_to_cpu(fcport->fp_speed)));
2120 port_speed = PORT_SPEED_UNKNOWN;
2123 if (port_speed == PORT_SPEED_UNKNOWN)
2126 rval = qla2x00_set_idma_speed(ha, fcport->loop_id, port_speed, mb);
2127 if (rval != QLA_SUCCESS) {
2128 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2129 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2130 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2131 fcport->port_name[2], fcport->port_name[3],
2132 fcport->port_name[4], fcport->port_name[5],
2133 fcport->port_name[6], fcport->port_name[7], rval,
2134 port_speed, mb[0], mb[1]));
2136 DEBUG2(qla_printk(KERN_INFO, ha,
2137 "iIDMA adjusted to %s GB/s on "
2138 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2139 link_speeds[port_speed], fcport->port_name[0],
2140 fcport->port_name[1], fcport->port_name[2],
2141 fcport->port_name[3], fcport->port_name[4],
2142 fcport->port_name[5], fcport->port_name[6],
2143 fcport->port_name[7]));
2148 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2150 struct fc_rport_identifiers rport_ids;
2151 struct fc_rport *rport;
2152 unsigned long flags;
2155 qla2x00_rport_del(fcport);
2159 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2160 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2161 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2162 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2163 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2164 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2166 qla_printk(KERN_WARNING, ha,
2167 "Unable to allocate fc remote port!\n");
2170 spin_lock_irqsave(&fcport->rport_lock, flags);
2171 fcport->rport = rport;
2172 *((fc_port_t **)rport->dd_data) = fcport;
2173 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2175 rport->supported_classes = fcport->supported_classes;
2177 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2178 if (fcport->port_type == FCT_INITIATOR)
2179 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2180 if (fcport->port_type == FCT_TARGET)
2181 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2182 fc_remote_port_rolechg(rport, rport_ids.roles);
2184 if (rport->scsi_target_id != -1 &&
2185 rport->scsi_target_id < ha->host->max_id)
2186 fcport->os_target_id = rport->scsi_target_id;
2190 * qla2x00_update_fcport
2191 * Updates device on list.
2194 * ha = adapter block pointer.
2195 * fcport = port structure pointer.
2205 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2208 fcport->login_retry = 0;
2209 fcport->port_login_retry_count = ha->port_down_retry_count *
2211 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2213 fcport->flags &= ~FCF_LOGIN_NEEDED;
2215 qla2x00_iidma_fcport(ha, fcport);
2217 atomic_set(&fcport->state, FCS_ONLINE);
2219 qla2x00_reg_remote_port(ha, fcport);
2223 * qla2x00_configure_fabric
2224 * Setup SNS devices with loop ID's.
2227 * ha = adapter block pointer.
2234 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2237 fc_port_t *fcport, *fcptemp;
2238 uint16_t next_loopid;
2239 uint16_t mb[MAILBOX_REGISTER_COUNT];
2241 LIST_HEAD(new_fcports);
2243 /* If FL port exists, then SNS is present */
2244 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2245 loop_id = NPH_F_PORT;
2247 loop_id = SNS_FL_PORT;
2248 rval = qla2x00_get_port_name(ha, loop_id, ha->fabric_node_name, 1);
2249 if (rval != QLA_SUCCESS) {
2250 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2251 "Port\n", ha->host_no));
2253 ha->device_flags &= ~SWITCH_FOUND;
2254 return (QLA_SUCCESS);
2256 ha->device_flags |= SWITCH_FOUND;
2258 /* Mark devices that need re-synchronization. */
2259 rval2 = qla2x00_device_resync(ha);
2260 if (rval2 == QLA_RSCNS_HANDLED) {
2261 /* No point doing the scan, just continue. */
2262 return (QLA_SUCCESS);
2266 if (ql2xfdmienable &&
2267 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2268 qla2x00_fdmi_register(ha);
2270 /* Ensure we are logged into the SNS. */
2271 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2274 loop_id = SIMPLE_NAME_SERVER;
2275 ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
2276 0xfc, mb, BIT_1 | BIT_0);
2277 if (mb[0] != MBS_COMMAND_COMPLETE) {
2278 DEBUG2(qla_printk(KERN_INFO, ha,
2279 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2280 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2281 mb[0], mb[1], mb[2], mb[6], mb[7]));
2282 return (QLA_SUCCESS);
2285 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2286 if (qla2x00_rft_id(ha)) {
2288 DEBUG2(printk("scsi(%ld): Register FC-4 "
2289 "TYPE failed.\n", ha->host_no));
2291 if (qla2x00_rff_id(ha)) {
2293 DEBUG2(printk("scsi(%ld): Register FC-4 "
2294 "Features failed.\n", ha->host_no));
2296 if (qla2x00_rnn_id(ha)) {
2298 DEBUG2(printk("scsi(%ld): Register Node Name "
2299 "failed.\n", ha->host_no));
2300 } else if (qla2x00_rsnn_nn(ha)) {
2302 DEBUG2(printk("scsi(%ld): Register Symbolic "
2303 "Node Name failed.\n", ha->host_no));
2307 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2308 if (rval != QLA_SUCCESS)
2312 * Logout all previous fabric devices marked lost, except
2315 list_for_each_entry(fcport, &ha->fcports, list) {
2316 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2319 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2322 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2323 qla2x00_mark_device_lost(ha, fcport,
2324 ql2xplogiabsentdevice, 0);
2325 if (fcport->loop_id != FC_NO_LOOP_ID &&
2326 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2327 fcport->port_type != FCT_INITIATOR &&
2328 fcport->port_type != FCT_BROADCAST) {
2329 ha->isp_ops.fabric_logout(ha,
2331 fcport->d_id.b.domain,
2332 fcport->d_id.b.area,
2333 fcport->d_id.b.al_pa);
2334 fcport->loop_id = FC_NO_LOOP_ID;
2339 /* Starting free loop ID. */
2340 next_loopid = ha->min_external_loopid;
2343 * Scan through our port list and login entries that need to be
2346 list_for_each_entry(fcport, &ha->fcports, list) {
2347 if (atomic_read(&ha->loop_down_timer) ||
2348 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2351 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2352 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2355 if (fcport->loop_id == FC_NO_LOOP_ID) {
2356 fcport->loop_id = next_loopid;
2357 rval = qla2x00_find_new_loop_id(ha, fcport);
2358 if (rval != QLA_SUCCESS) {
2359 /* Ran out of IDs to use */
2363 /* Login and update database */
2364 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2367 /* Exit if out of loop IDs. */
2368 if (rval != QLA_SUCCESS) {
2373 * Login and add the new devices to our port list.
2375 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2376 if (atomic_read(&ha->loop_down_timer) ||
2377 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2380 /* Find a new loop ID to use. */
2381 fcport->loop_id = next_loopid;
2382 rval = qla2x00_find_new_loop_id(ha, fcport);
2383 if (rval != QLA_SUCCESS) {
2384 /* Ran out of IDs to use */
2388 /* Remove device from the new list and add it to DB */
2389 list_move_tail(&fcport->list, &ha->fcports);
2391 /* Login and update database */
2392 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2396 /* Free all new device structures not processed. */
2397 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2398 list_del(&fcport->list);
2403 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2404 "rval=%d\n", ha->host_no, rval));
2412 * qla2x00_find_all_fabric_devs
2415 * ha = adapter block pointer.
2416 * dev = database device entry pointer.
2425 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2429 fc_port_t *fcport, *new_fcport, *fcptemp;
2434 int first_dev, last_dev;
2435 port_id_t wrap, nxt_d_id;
2439 /* Try GID_PT to get device list, else GAN. */
2440 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2443 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2444 "on GA_NXT\n", ha->host_no));
2446 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2447 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2450 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2453 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2456 } else if (qla2x00_gfpn_id(ha, swl) == QLA_SUCCESS) {
2457 qla2x00_gpsc(ha, swl);
2462 /* Allocate temporary fcport for any new fcports discovered. */
2463 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2464 if (new_fcport == NULL) {
2466 return (QLA_MEMORY_ALLOC_FAILED);
2468 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2470 /* Set start port ID scan at adapter ID. */
2474 /* Starting free loop ID. */
2475 loop_id = ha->min_external_loopid;
2476 for (; loop_id <= ha->last_loop_id; loop_id++) {
2477 if (qla2x00_is_reserved_id(ha, loop_id))
2480 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2485 wrap.b24 = new_fcport->d_id.b24;
2487 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2488 memcpy(new_fcport->node_name,
2489 swl[swl_idx].node_name, WWN_SIZE);
2490 memcpy(new_fcport->port_name,
2491 swl[swl_idx].port_name, WWN_SIZE);
2492 memcpy(new_fcport->fabric_port_name,
2493 swl[swl_idx].fabric_port_name, WWN_SIZE);
2494 new_fcport->fp_speed = swl[swl_idx].fp_speed;
2496 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2502 /* Send GA_NXT to the switch */
2503 rval = qla2x00_ga_nxt(ha, new_fcport);
2504 if (rval != QLA_SUCCESS) {
2505 qla_printk(KERN_WARNING, ha,
2506 "SNS scan failed -- assuming zero-entry "
2508 list_for_each_entry_safe(fcport, fcptemp,
2509 new_fcports, list) {
2510 list_del(&fcport->list);
2518 /* If wrap on switch device list, exit. */
2520 wrap.b24 = new_fcport->d_id.b24;
2522 } else if (new_fcport->d_id.b24 == wrap.b24) {
2523 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2524 ha->host_no, new_fcport->d_id.b.domain,
2525 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2529 /* Bypass if host adapter. */
2530 if (new_fcport->d_id.b24 == ha->d_id.b24)
2533 /* Bypass if same domain and area of adapter. */
2534 if (((new_fcport->d_id.b24 & 0xffff00) ==
2535 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2539 /* Bypass reserved domain fields. */
2540 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2543 /* Locate matching device in database. */
2545 list_for_each_entry(fcport, &ha->fcports, list) {
2546 if (memcmp(new_fcport->port_name, fcport->port_name,
2552 /* Update port state. */
2553 memcpy(fcport->fabric_port_name,
2554 new_fcport->fabric_port_name, WWN_SIZE);
2555 fcport->fp_speed = new_fcport->fp_speed;
2558 * If address the same and state FCS_ONLINE, nothing
2561 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2562 atomic_read(&fcport->state) == FCS_ONLINE) {
2567 * If device was not a fabric device before.
2569 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2570 fcport->d_id.b24 = new_fcport->d_id.b24;
2571 fcport->loop_id = FC_NO_LOOP_ID;
2572 fcport->flags |= (FCF_FABRIC_DEVICE |
2574 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2579 * Port ID changed or device was marked to be updated;
2580 * Log it out if still logged in and mark it for
2583 fcport->d_id.b24 = new_fcport->d_id.b24;
2584 fcport->flags |= FCF_LOGIN_NEEDED;
2585 if (fcport->loop_id != FC_NO_LOOP_ID &&
2586 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2587 fcport->port_type != FCT_INITIATOR &&
2588 fcport->port_type != FCT_BROADCAST) {
2589 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2590 fcport->d_id.b.domain, fcport->d_id.b.area,
2591 fcport->d_id.b.al_pa);
2592 fcport->loop_id = FC_NO_LOOP_ID;
2601 /* If device was not in our fcports list, then add it. */
2602 list_add_tail(&new_fcport->list, new_fcports);
2604 /* Allocate a new replacement fcport. */
2605 nxt_d_id.b24 = new_fcport->d_id.b24;
2606 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2607 if (new_fcport == NULL) {
2609 return (QLA_MEMORY_ALLOC_FAILED);
2611 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2612 new_fcport->d_id.b24 = nxt_d_id.b24;
2618 if (!list_empty(new_fcports))
2619 ha->device_flags |= DFLG_FABRIC_DEVICES;
2625 * qla2x00_find_new_loop_id
2626 * Scan through our port list and find a new usable loop ID.
2629 * ha: adapter state pointer.
2630 * dev: port structure pointer.
2633 * qla2x00 local function return status code.
2639 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2644 uint16_t first_loop_id;
2648 /* Save starting loop ID. */
2649 first_loop_id = dev->loop_id;
2652 /* Skip loop ID if already used by adapter. */
2653 if (dev->loop_id == ha->loop_id) {
2657 /* Skip reserved loop IDs. */
2658 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2662 /* Reset loop ID if passed the end. */
2663 if (dev->loop_id > ha->last_loop_id) {
2664 /* first loop ID. */
2665 dev->loop_id = ha->min_external_loopid;
2668 /* Check for loop ID being already in use. */
2671 list_for_each_entry(fcport, &ha->fcports, list) {
2672 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2673 /* ID possibly in use */
2679 /* If not in use then it is free to use. */
2684 /* ID in use. Try next value. */
2687 /* If wrap around. No free ID to use. */
2688 if (dev->loop_id == first_loop_id) {
2689 dev->loop_id = FC_NO_LOOP_ID;
2690 rval = QLA_FUNCTION_FAILED;
2699 * qla2x00_device_resync
2700 * Marks devices in the database that needs resynchronization.
2703 * ha = adapter block pointer.
2709 qla2x00_device_resync(scsi_qla_host_t *ha)
2714 uint32_t rscn_entry;
2715 uint8_t rscn_out_iter;
2719 rval = QLA_RSCNS_HANDLED;
2721 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2722 ha->flags.rscn_queue_overflow) {
2724 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2725 format = MSB(MSW(rscn_entry));
2726 d_id.b.domain = LSB(MSW(rscn_entry));
2727 d_id.b.area = MSB(LSW(rscn_entry));
2728 d_id.b.al_pa = LSB(LSW(rscn_entry));
2730 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2731 "[%02x/%02x%02x%02x].\n",
2732 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2733 d_id.b.area, d_id.b.al_pa));
2736 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2737 ha->rscn_out_ptr = 0;
2739 /* Skip duplicate entries. */
2740 for (rscn_out_iter = ha->rscn_out_ptr;
2741 !ha->flags.rscn_queue_overflow &&
2742 rscn_out_iter != ha->rscn_in_ptr;
2743 rscn_out_iter = (rscn_out_iter ==
2744 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2746 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2749 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2750 "entry found at [%d].\n", ha->host_no,
2753 ha->rscn_out_ptr = rscn_out_iter;
2756 /* Queue overflow, set switch default case. */
2757 if (ha->flags.rscn_queue_overflow) {
2758 DEBUG(printk("scsi(%ld): device_resync: rscn "
2759 "overflow.\n", ha->host_no));
2762 ha->flags.rscn_queue_overflow = 0;
2778 ha->rscn_out_ptr = ha->rscn_in_ptr;
2784 list_for_each_entry(fcport, &ha->fcports, list) {
2785 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2786 (fcport->d_id.b24 & mask) != d_id.b24 ||
2787 fcport->port_type == FCT_BROADCAST)
2790 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2792 fcport->port_type != FCT_INITIATOR) {
2793 qla2x00_mark_device_lost(ha, fcport,
2797 fcport->flags &= ~FCF_FARP_DONE;
2804 * qla2x00_fabric_dev_login
2805 * Login fabric target device and update FC port database.
2808 * ha: adapter state pointer.
2809 * fcport: port structure list pointer.
2810 * next_loopid: contains value of a new loop ID that can be used
2811 * by the next login attempt.
2814 * qla2x00 local function return status code.
2820 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2821 uint16_t *next_loopid)
2830 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2831 if (rval == QLA_SUCCESS) {
2832 /* Send an ADISC to tape devices.*/
2834 if (fcport->flags & FCF_TAPE_PRESENT)
2836 rval = qla2x00_get_port_database(ha, fcport, opts);
2837 if (rval != QLA_SUCCESS) {
2838 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2839 fcport->d_id.b.domain, fcport->d_id.b.area,
2840 fcport->d_id.b.al_pa);
2841 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2843 qla2x00_update_fcport(ha, fcport);
2851 * qla2x00_fabric_login
2852 * Issue fabric login command.
2855 * ha = adapter block pointer.
2856 * device = pointer to FC device type structure.
2859 * 0 - Login successfully
2861 * 2 - Initiator device
2865 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2866 uint16_t *next_loopid)
2870 uint16_t tmp_loopid;
2871 uint16_t mb[MAILBOX_REGISTER_COUNT];
2877 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2878 "for port %02x%02x%02x.\n",
2879 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2880 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2882 /* Login fcport on switch. */
2883 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2884 fcport->d_id.b.domain, fcport->d_id.b.area,
2885 fcport->d_id.b.al_pa, mb, BIT_0);
2886 if (mb[0] == MBS_PORT_ID_USED) {
2888 * Device has another loop ID. The firmware team
2889 * recommends the driver perform an implicit login with
2890 * the specified ID again. The ID we just used is save
2891 * here so we return with an ID that can be tried by
2895 tmp_loopid = fcport->loop_id;
2896 fcport->loop_id = mb[1];
2898 DEBUG(printk("Fabric Login: port in use - next "
2899 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2900 fcport->loop_id, fcport->d_id.b.domain,
2901 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2903 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2908 /* A retry occurred before. */
2909 *next_loopid = tmp_loopid;
2912 * No retry occurred before. Just increment the
2913 * ID value for next login.
2915 *next_loopid = (fcport->loop_id + 1);
2918 if (mb[1] & BIT_0) {
2919 fcport->port_type = FCT_INITIATOR;
2921 fcport->port_type = FCT_TARGET;
2922 if (mb[1] & BIT_1) {
2923 fcport->flags |= FCF_TAPE_PRESENT;
2928 fcport->supported_classes |= FC_COS_CLASS2;
2930 fcport->supported_classes |= FC_COS_CLASS3;
2934 } else if (mb[0] == MBS_LOOP_ID_USED) {
2936 * Loop ID already used, try next loop ID.
2939 rval = qla2x00_find_new_loop_id(ha, fcport);
2940 if (rval != QLA_SUCCESS) {
2941 /* Ran out of loop IDs to use */
2944 } else if (mb[0] == MBS_COMMAND_ERROR) {
2946 * Firmware possibly timed out during login. If NO
2947 * retries are left to do then the device is declared
2950 *next_loopid = fcport->loop_id;
2951 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2952 fcport->d_id.b.domain, fcport->d_id.b.area,
2953 fcport->d_id.b.al_pa);
2954 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2960 * unrecoverable / not handled error
2962 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2963 "loop_id=%x jiffies=%lx.\n",
2964 __func__, ha->host_no, mb[0],
2965 fcport->d_id.b.domain, fcport->d_id.b.area,
2966 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2968 *next_loopid = fcport->loop_id;
2969 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2970 fcport->d_id.b.domain, fcport->d_id.b.area,
2971 fcport->d_id.b.al_pa);
2972 fcport->loop_id = FC_NO_LOOP_ID;
2973 fcport->login_retry = 0;
2984 * qla2x00_local_device_login
2985 * Issue local device login command.
2988 * ha = adapter block pointer.
2989 * loop_id = loop id of device to login to.
2991 * Returns (Where's the #define!!!!):
2992 * 0 - Login successfully
2997 qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
3000 uint16_t mb[MAILBOX_REGISTER_COUNT];
3002 memset(mb, 0, sizeof(mb));
3003 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
3004 if (rval == QLA_SUCCESS) {
3005 /* Interrogate mailbox registers for any errors */
3006 if (mb[0] == MBS_COMMAND_ERROR)
3008 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3009 /* device not in PCB table */
3017 * qla2x00_loop_resync
3018 * Resync with fibre channel devices.
3021 * ha = adapter block pointer.
3027 qla2x00_loop_resync(scsi_qla_host_t *ha)
3034 atomic_set(&ha->loop_state, LOOP_UPDATE);
3035 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3036 if (ha->flags.online) {
3037 if (!(rval = qla2x00_fw_ready(ha))) {
3038 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3041 atomic_set(&ha->loop_state, LOOP_UPDATE);
3043 /* Issue a marker after FW becomes ready. */
3044 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3045 ha->marker_needed = 0;
3047 /* Remap devices on Loop. */
3048 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3050 qla2x00_configure_loop(ha);
3052 } while (!atomic_read(&ha->loop_down_timer) &&
3053 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3055 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3059 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3060 return (QLA_FUNCTION_FAILED);
3064 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3071 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
3077 list_for_each_entry(fcport, &ha->fcports, list) {
3078 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
3081 qla2x00_update_fcport(ha, fcport);
3082 fcport->flags &= ~FCF_RESCAN_NEEDED;
3086 qla2x00_probe_for_all_luns(ha);
3090 qla2x00_update_fcports(scsi_qla_host_t *ha)
3094 /* Go with deferred removal of rport references. */
3095 list_for_each_entry(fcport, &ha->fcports, list)
3097 qla2x00_rport_del(fcport);
3102 * Resets ISP and aborts all outstanding commands.
3105 * ha = adapter block pointer.
3111 qla2x00_abort_isp(scsi_qla_host_t *ha)
3114 unsigned long flags = 0;
3119 if (ha->flags.online) {
3120 ha->flags.online = 0;
3121 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3123 qla_printk(KERN_INFO, ha,
3124 "Performing ISP error recovery - ha= %p.\n", ha);
3125 ha->isp_ops.reset_chip(ha);
3127 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3128 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3129 atomic_set(&ha->loop_state, LOOP_DOWN);
3130 qla2x00_mark_all_devices_lost(ha, 0);
3132 if (!atomic_read(&ha->loop_down_timer))
3133 atomic_set(&ha->loop_down_timer,
3137 spin_lock_irqsave(&ha->hardware_lock, flags);
3138 /* Requeue all commands in outstanding command list. */
3139 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3140 sp = ha->outstanding_cmds[cnt];
3142 ha->outstanding_cmds[cnt] = NULL;
3144 sp->cmd->result = DID_RESET << 16;
3145 sp->cmd->host_scribble = (unsigned char *)NULL;
3146 qla2x00_sp_compl(ha, sp);
3149 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3151 ha->isp_ops.get_flash_version(ha, ha->request_ring);
3153 ha->isp_ops.nvram_config(ha);
3155 if (!qla2x00_restart_isp(ha)) {
3156 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3158 if (!atomic_read(&ha->loop_down_timer)) {
3160 * Issue marker command only when we are going
3161 * to start the I/O .
3163 ha->marker_needed = 1;
3166 ha->flags.online = 1;
3168 ha->isp_ops.enable_intrs(ha);
3170 ha->isp_abort_cnt = 0;
3171 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3174 rval = qla2x00_trace_control(ha, TC_ENABLE,
3175 ha->eft_dma, EFT_NUM_BUFFERS);
3177 qla_printk(KERN_WARNING, ha,
3178 "Unable to reinitialize EFT "
3182 } else { /* failed the ISP abort */
3183 ha->flags.online = 1;
3184 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3185 if (ha->isp_abort_cnt == 0) {
3186 qla_printk(KERN_WARNING, ha,
3187 "ISP error recovery failed - "
3188 "board disabled\n");
3190 * The next call disables the board
3193 ha->isp_ops.reset_adapter(ha);
3194 ha->flags.online = 0;
3195 clear_bit(ISP_ABORT_RETRY,
3198 } else { /* schedule another ISP abort */
3199 ha->isp_abort_cnt--;
3200 DEBUG(printk("qla%ld: ISP abort - "
3201 "retry remaining %d\n",
3202 ha->host_no, ha->isp_abort_cnt));
3206 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3207 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3208 "- retrying (%d) more times\n",
3209 ha->host_no, ha->isp_abort_cnt));
3210 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3218 qla_printk(KERN_INFO, ha,
3219 "qla2x00_abort_isp: **** FAILED ****\n");
3221 DEBUG(printk(KERN_INFO
3222 "qla2x00_abort_isp(%ld): exiting.\n",
3230 * qla2x00_restart_isp
3231 * restarts the ISP after a reset
3234 * ha = adapter block pointer.
3240 qla2x00_restart_isp(scsi_qla_host_t *ha)
3243 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3244 unsigned long flags = 0;
3247 /* If firmware needs to be loaded */
3248 if (qla2x00_isp_firmware(ha)) {
3249 ha->flags.online = 0;
3250 if (!(status = ha->isp_ops.chip_diag(ha))) {
3251 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3252 status = qla2x00_setup_chip(ha);
3256 spin_lock_irqsave(&ha->hardware_lock, flags);
3258 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3260 * Disable SRAM, Instruction RAM and GP RAM
3263 WRT_REG_WORD(®->hccr,
3264 (HCCR_ENABLE_PARITY + 0x0));
3265 RD_REG_WORD(®->hccr);
3268 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3270 status = qla2x00_setup_chip(ha);
3272 spin_lock_irqsave(&ha->hardware_lock, flags);
3274 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3275 /* Enable proper parity */
3278 WRT_REG_WORD(®->hccr,
3279 (HCCR_ENABLE_PARITY + 0x1));
3282 * SRAM, Instruction RAM and GP RAM
3285 WRT_REG_WORD(®->hccr,
3286 (HCCR_ENABLE_PARITY + 0x7));
3287 RD_REG_WORD(®->hccr);
3290 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3295 if (!status && !(status = qla2x00_init_rings(ha))) {
3296 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3297 if (!(status = qla2x00_fw_ready(ha))) {
3298 DEBUG(printk("%s(): Start configure loop, "
3299 "status = %d\n", __func__, status));
3301 /* Issue a marker after FW becomes ready. */
3302 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3304 ha->flags.online = 1;
3305 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3308 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3309 qla2x00_configure_loop(ha);
3311 } while (!atomic_read(&ha->loop_down_timer) &&
3312 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3314 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3317 /* if no cable then assume it's good */
3318 if ((ha->device_flags & DFLG_NO_CABLE))
3321 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3329 * qla2x00_reset_adapter
3333 * ha = adapter block pointer.
3336 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3338 unsigned long flags = 0;
3339 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3341 ha->flags.online = 0;
3342 ha->isp_ops.disable_intrs(ha);
3344 spin_lock_irqsave(&ha->hardware_lock, flags);
3345 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3346 RD_REG_WORD(®->hccr); /* PCI Posting. */
3347 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3348 RD_REG_WORD(®->hccr); /* PCI Posting. */
3349 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3353 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3355 unsigned long flags = 0;
3356 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3358 ha->flags.online = 0;
3359 ha->isp_ops.disable_intrs(ha);
3361 spin_lock_irqsave(&ha->hardware_lock, flags);
3362 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3363 RD_REG_DWORD(®->hccr);
3364 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3365 RD_REG_DWORD(®->hccr);
3366 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3369 /* On sparc systems, obtain port and node WWN from firmware
3372 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, struct nvram_24xx *nv)
3375 struct pci_dev *pdev = ha->pdev;
3376 struct pcidev_cookie *pcp = pdev->sysdata;
3377 struct device_node *dp = pcp->prom_node;
3381 val = of_get_property(dp, "port-wwn", &len);
3382 if (val && len >= WWN_SIZE)
3383 memcpy(nv->port_name, val, WWN_SIZE);
3385 val = of_get_property(dp, "node-wwn", &len);
3386 if (val && len >= WWN_SIZE)
3387 memcpy(nv->node_name, val, WWN_SIZE);
3392 qla24xx_nvram_config(scsi_qla_host_t *ha)
3395 struct init_cb_24xx *icb;
3396 struct nvram_24xx *nv;
3398 uint8_t *dptr1, *dptr2;
3403 icb = (struct init_cb_24xx *)ha->init_cb;
3404 nv = (struct nvram_24xx *)ha->request_ring;
3406 /* Determine NVRAM starting address. */
3407 ha->nvram_size = sizeof(struct nvram_24xx);
3408 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3409 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3410 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3411 if (PCI_FUNC(ha->pdev->devfn)) {
3412 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3413 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3416 /* Get NVRAM data and calculate checksum. */
3417 dptr = (uint32_t *)nv;
3418 ha->isp_ops.read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3420 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3421 chksum += le32_to_cpu(*dptr++);
3423 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3424 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3427 /* Bad NVRAM data, set defaults parameters. */
3428 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3429 || nv->id[3] != ' ' ||
3430 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3431 /* Reset NVRAM data. */
3432 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3433 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3434 le16_to_cpu(nv->nvram_version));
3435 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3436 "invalid -- WWPN) defaults.\n");
3439 * Set default initialization control block.
3441 memset(nv, 0, ha->nvram_size);
3442 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3443 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3444 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3445 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3446 nv->exchange_count = __constant_cpu_to_le16(0);
3447 nv->hard_address = __constant_cpu_to_le16(124);
3448 nv->port_name[0] = 0x21;
3449 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3450 nv->port_name[2] = 0x00;
3451 nv->port_name[3] = 0xe0;
3452 nv->port_name[4] = 0x8b;
3453 nv->port_name[5] = 0x1c;
3454 nv->port_name[6] = 0x55;
3455 nv->port_name[7] = 0x86;
3456 nv->node_name[0] = 0x20;
3457 nv->node_name[1] = 0x00;
3458 nv->node_name[2] = 0x00;
3459 nv->node_name[3] = 0xe0;
3460 nv->node_name[4] = 0x8b;
3461 nv->node_name[5] = 0x1c;
3462 nv->node_name[6] = 0x55;
3463 nv->node_name[7] = 0x86;
3464 qla24xx_nvram_wwn_from_ofw(ha, nv);
3465 nv->login_retry_count = __constant_cpu_to_le16(8);
3466 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3467 nv->login_timeout = __constant_cpu_to_le16(0);
3468 nv->firmware_options_1 =
3469 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3470 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3471 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3472 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3473 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3474 nv->efi_parameters = __constant_cpu_to_le32(0);
3475 nv->reset_delay = 5;
3476 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3477 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3478 nv->link_down_timeout = __constant_cpu_to_le16(30);
3483 /* Reset Initialization control block */
3484 memset(icb, 0, sizeof(struct init_cb_24xx));
3486 /* Copy 1st segment. */
3487 dptr1 = (uint8_t *)icb;
3488 dptr2 = (uint8_t *)&nv->version;
3489 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3491 *dptr1++ = *dptr2++;
3493 icb->login_retry_count = nv->login_retry_count;
3494 icb->link_down_on_nos = nv->link_down_on_nos;
3496 /* Copy 2nd segment. */
3497 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3498 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3499 cnt = (uint8_t *)&icb->reserved_3 -
3500 (uint8_t *)&icb->interrupt_delay_timer;
3502 *dptr1++ = *dptr2++;
3505 * Setup driver NVRAM options.
3507 qla2x00_set_model_info(ha, nv->model_name, sizeof(nv->model_name),
3510 /* Use alternate WWN? */
3511 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3512 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3513 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3516 /* Prepare nodename */
3517 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3519 * Firmware will apply the following mask if the nodename was
3522 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3523 icb->node_name[0] &= 0xF0;
3526 /* Set host adapter parameters. */
3527 ha->flags.disable_risc_code_load = 0;
3528 ha->flags.enable_lip_reset = 0;
3529 ha->flags.enable_lip_full_login =
3530 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3531 ha->flags.enable_target_reset =
3532 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
3533 ha->flags.enable_led_scheme = 0;
3534 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
3536 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3537 (BIT_6 | BIT_5 | BIT_4)) >> 4;
3539 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3540 sizeof(ha->fw_seriallink_options24));
3542 /* save HBA serial number */
3543 ha->serial0 = icb->port_name[5];
3544 ha->serial1 = icb->port_name[6];
3545 ha->serial2 = icb->port_name[7];
3546 ha->node_name = icb->node_name;
3547 ha->port_name = icb->port_name;
3549 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3551 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3553 /* Set minimum login_timeout to 4 seconds. */
3554 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3555 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3556 if (le16_to_cpu(nv->login_timeout) < 4)
3557 nv->login_timeout = __constant_cpu_to_le16(4);
3558 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3559 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3561 /* Set minimum RATOV to 200 tenths of a second. */
3564 ha->loop_reset_delay = nv->reset_delay;
3566 /* Link Down Timeout = 0:
3568 * When Port Down timer expires we will start returning
3569 * I/O's to OS with "DID_NO_CONNECT".
3571 * Link Down Timeout != 0:
3573 * The driver waits for the link to come up after link down
3574 * before returning I/Os to OS with "DID_NO_CONNECT".
3576 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3577 ha->loop_down_abort_time =
3578 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3580 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3581 ha->loop_down_abort_time =
3582 (LOOP_DOWN_TIME - ha->link_down_timeout);
3585 /* Need enough time to try and get the port back. */
3586 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3587 if (qlport_down_retry)
3588 ha->port_down_retry_count = qlport_down_retry;
3590 /* Set login_retry_count */
3591 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3592 if (ha->port_down_retry_count ==
3593 le16_to_cpu(nv->port_down_retry_count) &&
3594 ha->port_down_retry_count > 3)
3595 ha->login_retry_count = ha->port_down_retry_count;
3596 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3597 ha->login_retry_count = ha->port_down_retry_count;
3598 if (ql2xloginretrycount)
3599 ha->login_retry_count = ql2xloginretrycount;
3602 if (!ha->flags.init_done) {
3603 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3604 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3605 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3606 le16_to_cpu(icb->interrupt_delay_timer): 2;
3608 icb->firmware_options_2 &= __constant_cpu_to_le32(
3609 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3610 ha->flags.process_response_queue = 0;
3611 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3612 ha->zio_mode = QLA_ZIO_MODE_6;
3614 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3615 "(%d us).\n", ha->host_no, ha->zio_mode,
3616 ha->zio_timer * 100));
3617 qla_printk(KERN_INFO, ha,
3618 "ZIO mode %d enabled; timer delay (%d us).\n",
3619 ha->zio_mode, ha->zio_timer * 100);
3621 icb->firmware_options_2 |= cpu_to_le32(
3622 (uint32_t)ha->zio_mode);
3623 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3624 ha->flags.process_response_queue = 1;
3628 DEBUG2_3(printk(KERN_WARNING
3629 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3635 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3638 int segments, fragment;
3640 uint32_t *dcode, dlen;
3647 segments = FA_RISC_CODE_SEGMENTS;
3648 faddr = FA_RISC_CODE_ADDR;
3649 dcode = (uint32_t *)ha->request_ring;
3652 /* Validate firmware image by checking version. */
3653 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3654 for (i = 0; i < 4; i++)
3655 dcode[i] = be32_to_cpu(dcode[i]);
3656 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3657 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3658 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3660 qla_printk(KERN_WARNING, ha,
3661 "Unable to verify integrity of flash firmware image!\n");
3662 qla_printk(KERN_WARNING, ha,
3663 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3664 dcode[1], dcode[2], dcode[3]);
3666 return QLA_FUNCTION_FAILED;
3669 while (segments && rval == QLA_SUCCESS) {
3670 /* Read segment's load information. */
3671 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3673 risc_addr = be32_to_cpu(dcode[2]);
3674 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3675 risc_size = be32_to_cpu(dcode[3]);
3678 while (risc_size > 0 && rval == QLA_SUCCESS) {
3679 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3680 if (dlen > risc_size)
3683 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3684 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3685 ha->host_no, risc_addr, dlen, faddr));
3687 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3688 for (i = 0; i < dlen; i++)
3689 dcode[i] = swab32(dcode[i]);
3691 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3694 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3695 "segment %d of firmware\n", ha->host_no,
3697 qla_printk(KERN_WARNING, ha,
3698 "[ERROR] Failed to load segment %d of "
3699 "firmware\n", fragment);
3716 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3719 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3723 uint16_t *wcode, *fwcode;
3724 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3725 struct fw_blob *blob;
3727 /* Load firmware blob. */
3728 blob = qla2x00_request_firmware(ha);
3730 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3731 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3732 "from: " QLA_FW_URL ".\n");
3733 return QLA_FUNCTION_FAILED;
3738 wcode = (uint16_t *)ha->request_ring;
3740 fwcode = (uint16_t *)blob->fw->data;
3743 /* Validate firmware image by checking version. */
3744 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3745 qla_printk(KERN_WARNING, ha,
3746 "Unable to verify integrity of firmware image (%Zd)!\n",
3748 goto fail_fw_integrity;
3750 for (i = 0; i < 4; i++)
3751 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3752 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3753 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3754 wcode[2] == 0 && wcode[3] == 0)) {
3755 qla_printk(KERN_WARNING, ha,
3756 "Unable to verify integrity of firmware image!\n");
3757 qla_printk(KERN_WARNING, ha,
3758 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3759 wcode[1], wcode[2], wcode[3]);
3760 goto fail_fw_integrity;
3764 while (*seg && rval == QLA_SUCCESS) {
3766 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3767 risc_size = be16_to_cpu(fwcode[3]);
3769 /* Validate firmware image size. */
3770 fwclen += risc_size * sizeof(uint16_t);
3771 if (blob->fw->size < fwclen) {
3772 qla_printk(KERN_WARNING, ha,
3773 "Unable to verify integrity of firmware image "
3774 "(%Zd)!\n", blob->fw->size);
3775 goto fail_fw_integrity;
3779 while (risc_size > 0 && rval == QLA_SUCCESS) {
3780 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3781 if (wlen > risc_size)
3784 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3785 "addr %x, number of words 0x%x.\n", ha->host_no,
3788 for (i = 0; i < wlen; i++)
3789 wcode[i] = swab16(fwcode[i]);
3791 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3794 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3795 "segment %d of firmware\n", ha->host_no,
3797 qla_printk(KERN_WARNING, ha,
3798 "[ERROR] Failed to load segment %d of "
3799 "firmware\n", fragment);
3815 return QLA_FUNCTION_FAILED;
3819 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3822 int segments, fragment;
3823 uint32_t *dcode, dlen;
3827 struct fw_blob *blob;
3828 uint32_t *fwcode, fwclen;
3830 /* Load firmware blob. */
3831 blob = qla2x00_request_firmware(ha);
3833 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3834 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3835 "from: " QLA_FW_URL ".\n");
3837 /* Try to load RISC code from flash. */
3838 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3839 "outdated) firmware from flash.\n");
3840 return qla24xx_load_risc_flash(ha, srisc_addr);
3845 segments = FA_RISC_CODE_SEGMENTS;
3846 dcode = (uint32_t *)ha->request_ring;
3848 fwcode = (uint32_t *)blob->fw->data;
3851 /* Validate firmware image by checking version. */
3852 if (blob->fw->size < 8 * sizeof(uint32_t)) {
3853 qla_printk(KERN_WARNING, ha,
3854 "Unable to verify integrity of firmware image (%Zd)!\n",
3856 goto fail_fw_integrity;
3858 for (i = 0; i < 4; i++)
3859 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3860 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3861 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3862 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3864 qla_printk(KERN_WARNING, ha,
3865 "Unable to verify integrity of firmware image!\n");
3866 qla_printk(KERN_WARNING, ha,
3867 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3868 dcode[1], dcode[2], dcode[3]);
3869 goto fail_fw_integrity;
3872 while (segments && rval == QLA_SUCCESS) {
3873 risc_addr = be32_to_cpu(fwcode[2]);
3874 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3875 risc_size = be32_to_cpu(fwcode[3]);
3877 /* Validate firmware image size. */
3878 fwclen += risc_size * sizeof(uint32_t);
3879 if (blob->fw->size < fwclen) {
3880 qla_printk(KERN_WARNING, ha,
3881 "Unable to verify integrity of firmware image "
3882 "(%Zd)!\n", blob->fw->size);
3884 goto fail_fw_integrity;
3888 while (risc_size > 0 && rval == QLA_SUCCESS) {
3889 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3890 if (dlen > risc_size)
3893 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3894 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3897 for (i = 0; i < dlen; i++)
3898 dcode[i] = swab32(fwcode[i]);
3900 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3903 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3904 "segment %d of firmware\n", ha->host_no,
3906 qla_printk(KERN_WARNING, ha,
3907 "[ERROR] Failed to load segment %d of "
3908 "firmware\n", fragment);
3924 return QLA_FUNCTION_FAILED;
3928 qla2x00_try_to_stop_firmware(scsi_qla_host_t *ha)
3932 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
3935 ret = qla2x00_stop_firmware(ha);
3936 for (retries = 5; ret != QLA_SUCCESS && retries ; retries--) {
3937 qla2x00_reset_chip(ha);
3938 if (qla2x00_chip_diag(ha) != QLA_SUCCESS)
3940 if (qla2x00_setup_chip(ha) != QLA_SUCCESS)
3942 qla_printk(KERN_INFO, ha,
3943 "Attempting retry of stop-firmware command...\n");
3944 ret = qla2x00_stop_firmware(ha);