2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/delay.h>
10 #include <linux/vmalloc.h>
12 #include "qla_devtbl.h"
14 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
15 #ifndef EXT_IS_LUN_BIT_SET
16 #define EXT_IS_LUN_BIT_SET(P,L) \
17 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
18 #define EXT_SET_LUN_BIT(P,L) \
19 ((P)->mask[L/8] |= (0x80 >> (L%8)))
23 * QLogic ISP2x00 Hardware Support Function Prototypes.
25 static int qla2x00_isp_firmware(scsi_qla_host_t *);
26 static void qla2x00_resize_request_q(scsi_qla_host_t *);
27 static int qla2x00_setup_chip(scsi_qla_host_t *);
28 static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
29 static int qla2x00_init_rings(scsi_qla_host_t *);
30 static int qla2x00_fw_ready(scsi_qla_host_t *);
31 static int qla2x00_configure_hba(scsi_qla_host_t *);
32 static int qla2x00_configure_loop(scsi_qla_host_t *);
33 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
34 static int qla2x00_configure_fabric(scsi_qla_host_t *);
35 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
36 static int qla2x00_device_resync(scsi_qla_host_t *);
37 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
40 static int qla2x00_restart_isp(scsi_qla_host_t *);
42 static int qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev);
44 /****************************************************************************/
45 /* QLogic ISP2x00 Hardware Support Functions. */
46 /****************************************************************************/
49 * qla2x00_initialize_adapter
53 * ha = adapter block pointer.
59 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
63 /* Clear adapter flags. */
65 ha->flags.reset_active = 0;
66 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
67 atomic_set(&ha->loop_state, LOOP_DOWN);
70 ha->flags.management_server_logged_in = 0;
71 ha->marker_needed = 0;
73 ha->isp_abort_cnt = 0;
74 ha->beacon_blink_led = 0;
75 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
77 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
78 rval = ha->isp_ops.pci_config(ha);
80 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
85 ha->isp_ops.reset_chip(ha);
87 ha->isp_ops.get_flash_version(ha, ha->request_ring);
89 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
91 ha->isp_ops.nvram_config(ha);
93 if (ha->flags.disable_serdes) {
94 /* Mask HBA via NVRAM settings? */
95 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
96 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
97 ha->port_name[0], ha->port_name[1],
98 ha->port_name[2], ha->port_name[3],
99 ha->port_name[4], ha->port_name[5],
100 ha->port_name[6], ha->port_name[7]);
101 return QLA_FUNCTION_FAILED;
104 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
106 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
107 rval = ha->isp_ops.chip_diag(ha);
110 rval = qla2x00_setup_chip(ha);
114 rval = qla2x00_init_rings(ha);
120 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
123 * Returns 0 on success.
126 qla2100_pci_config(scsi_qla_host_t *ha)
131 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
133 pci_set_master(ha->pdev);
135 if (pci_set_mwi(ha->pdev))
136 mwi = PCI_COMMAND_INVALIDATE;
138 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
139 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
140 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
142 /* Reset expansion ROM address decode enable */
143 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
144 d &= ~PCI_ROM_ADDRESS_ENABLE;
145 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
147 /* Get PCI bus information. */
148 spin_lock_irqsave(&ha->hardware_lock, flags);
149 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
150 spin_unlock_irqrestore(&ha->hardware_lock, flags);
156 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
159 * Returns 0 on success.
162 qla2300_pci_config(scsi_qla_host_t *ha)
166 unsigned long flags = 0;
168 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
170 pci_set_master(ha->pdev);
172 if (pci_set_mwi(ha->pdev))
173 mwi = PCI_COMMAND_INVALIDATE;
175 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
176 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
178 if (IS_QLA2322(ha) || IS_QLA6322(ha))
179 w &= ~PCI_COMMAND_INTX_DISABLE;
182 * If this is a 2300 card and not 2312, reset the
183 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
184 * the 2310 also reports itself as a 2300 so we need to get the
185 * fb revision level -- a 6 indicates it really is a 2300 and
188 if (IS_QLA2300(ha)) {
189 spin_lock_irqsave(&ha->hardware_lock, flags);
192 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
193 for (cnt = 0; cnt < 30000; cnt++) {
194 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
200 /* Select FPM registers. */
201 WRT_REG_WORD(®->ctrl_status, 0x20);
202 RD_REG_WORD(®->ctrl_status);
204 /* Get the fb rev level */
205 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
207 if (ha->fb_rev == FPM_2300)
208 w &= ~PCI_COMMAND_INVALIDATE;
210 /* Deselect FPM registers. */
211 WRT_REG_WORD(®->ctrl_status, 0x0);
212 RD_REG_WORD(®->ctrl_status);
214 /* Release RISC module. */
215 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
216 for (cnt = 0; cnt < 30000; cnt++) {
217 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
223 spin_unlock_irqrestore(&ha->hardware_lock, flags);
225 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
227 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
229 /* Reset expansion ROM address decode enable */
230 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
231 d &= ~PCI_ROM_ADDRESS_ENABLE;
232 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
234 /* Get PCI bus information. */
235 spin_lock_irqsave(&ha->hardware_lock, flags);
236 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
237 spin_unlock_irqrestore(&ha->hardware_lock, flags);
243 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
246 * Returns 0 on success.
249 qla24xx_pci_config(scsi_qla_host_t *ha)
253 unsigned long flags = 0;
254 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
255 int pcix_cmd_reg, pcie_dctl_reg;
257 pci_set_master(ha->pdev);
259 if (pci_set_mwi(ha->pdev))
260 mwi = PCI_COMMAND_INVALIDATE;
262 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
263 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
264 w &= ~PCI_COMMAND_INTX_DISABLE;
265 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
267 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
269 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
270 pcix_cmd_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX);
274 pcix_cmd_reg += PCI_X_CMD;
275 pci_read_config_word(ha->pdev, pcix_cmd_reg, &pcix_cmd);
276 pcix_cmd &= ~PCI_X_CMD_MAX_READ;
278 pci_write_config_word(ha->pdev, pcix_cmd_reg, pcix_cmd);
281 /* PCIe -- adjust Maximum Read Request Size (2048). */
282 pcie_dctl_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
286 pcie_dctl_reg += PCI_EXP_DEVCTL;
287 pci_read_config_word(ha->pdev, pcie_dctl_reg, &pcie_dctl);
288 pcie_dctl &= ~PCI_EXP_DEVCTL_READRQ;
290 pci_write_config_word(ha->pdev, pcie_dctl_reg, pcie_dctl);
293 /* Reset expansion ROM address decode enable */
294 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
295 d &= ~PCI_ROM_ADDRESS_ENABLE;
296 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
298 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->chip_revision);
300 /* Get PCI bus information. */
301 spin_lock_irqsave(&ha->hardware_lock, flags);
302 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
303 spin_unlock_irqrestore(&ha->hardware_lock, flags);
309 * qla2x00_isp_firmware() - Choose firmware image.
312 * Returns 0 on success.
315 qla2x00_isp_firmware(scsi_qla_host_t *ha)
319 /* Assume loading risc code */
320 rval = QLA_FUNCTION_FAILED;
322 if (ha->flags.disable_risc_code_load) {
323 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
325 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
327 /* Verify checksum of loaded RISC code. */
328 rval = qla2x00_verify_checksum(ha, ha->fw_srisc_address);
332 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
340 * qla2x00_reset_chip() - Reset ISP chip.
343 * Returns 0 on success.
346 qla2x00_reset_chip(scsi_qla_host_t *ha)
348 unsigned long flags = 0;
349 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
353 ha->isp_ops.disable_intrs(ha);
355 spin_lock_irqsave(&ha->hardware_lock, flags);
357 /* Turn off master enable */
359 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
360 cmd &= ~PCI_COMMAND_MASTER;
361 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
363 if (!IS_QLA2100(ha)) {
365 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
366 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
367 for (cnt = 0; cnt < 30000; cnt++) {
368 if ((RD_REG_WORD(®->hccr) &
369 HCCR_RISC_PAUSE) != 0)
374 RD_REG_WORD(®->hccr); /* PCI Posting. */
378 /* Select FPM registers. */
379 WRT_REG_WORD(®->ctrl_status, 0x20);
380 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
382 /* FPM Soft Reset. */
383 WRT_REG_WORD(®->fpm_diag_config, 0x100);
384 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
386 /* Toggle Fpm Reset. */
387 if (!IS_QLA2200(ha)) {
388 WRT_REG_WORD(®->fpm_diag_config, 0x0);
389 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
392 /* Select frame buffer registers. */
393 WRT_REG_WORD(®->ctrl_status, 0x10);
394 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
396 /* Reset frame buffer FIFOs. */
397 if (IS_QLA2200(ha)) {
398 WRT_FB_CMD_REG(ha, reg, 0xa000);
399 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
401 WRT_FB_CMD_REG(ha, reg, 0x00fc);
403 /* Read back fb_cmd until zero or 3 seconds max */
404 for (cnt = 0; cnt < 3000; cnt++) {
405 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
411 /* Select RISC module registers. */
412 WRT_REG_WORD(®->ctrl_status, 0);
413 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
415 /* Reset RISC processor. */
416 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
417 RD_REG_WORD(®->hccr); /* PCI Posting. */
419 /* Release RISC processor. */
420 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
421 RD_REG_WORD(®->hccr); /* PCI Posting. */
424 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
425 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
427 /* Reset ISP chip. */
428 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
430 /* Wait for RISC to recover from reset. */
431 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
433 * It is necessary to for a delay here since the card doesn't
434 * respond to PCI reads during a reset. On some architectures
435 * this will result in an MCA.
438 for (cnt = 30000; cnt; cnt--) {
439 if ((RD_REG_WORD(®->ctrl_status) &
440 CSR_ISP_SOFT_RESET) == 0)
447 /* Reset RISC processor. */
448 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
450 WRT_REG_WORD(®->semaphore, 0);
452 /* Release RISC processor. */
453 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
454 RD_REG_WORD(®->hccr); /* PCI Posting. */
456 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
457 for (cnt = 0; cnt < 30000; cnt++) {
458 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
466 /* Turn on master enable */
467 cmd |= PCI_COMMAND_MASTER;
468 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
470 /* Disable RISC pause on FPM parity error. */
471 if (!IS_QLA2100(ha)) {
472 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
473 RD_REG_WORD(®->hccr); /* PCI Posting. */
476 spin_unlock_irqrestore(&ha->hardware_lock, flags);
480 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
483 * Returns 0 on success.
486 qla24xx_reset_risc(scsi_qla_host_t *ha)
488 unsigned long flags = 0;
489 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
493 spin_lock_irqsave(&ha->hardware_lock, flags);
496 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
497 for (cnt = 0; cnt < 30000; cnt++) {
498 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
504 WRT_REG_DWORD(®->ctrl_status,
505 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
506 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
509 /* Wait for firmware to complete NVRAM accesses. */
510 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
511 for (cnt = 10000 ; cnt && d2; cnt--) {
513 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
517 /* Wait for soft-reset to complete. */
518 d2 = RD_REG_DWORD(®->ctrl_status);
519 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
521 d2 = RD_REG_DWORD(®->ctrl_status);
525 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
526 RD_REG_DWORD(®->hccr);
528 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
529 RD_REG_DWORD(®->hccr);
531 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
532 RD_REG_DWORD(®->hccr);
534 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
535 for (cnt = 6000000 ; cnt && d2; cnt--) {
537 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
541 spin_unlock_irqrestore(&ha->hardware_lock, flags);
545 * qla24xx_reset_chip() - Reset ISP24xx chip.
548 * Returns 0 on success.
551 qla24xx_reset_chip(scsi_qla_host_t *ha)
553 ha->isp_ops.disable_intrs(ha);
555 /* Perform RISC reset. */
556 qla24xx_reset_risc(ha);
560 * qla2x00_chip_diag() - Test chip for proper operation.
563 * Returns 0 on success.
566 qla2x00_chip_diag(scsi_qla_host_t *ha)
569 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
570 unsigned long flags = 0;
575 /* Assume a failed state */
576 rval = QLA_FUNCTION_FAILED;
578 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
579 ha->host_no, (u_long)®->flash_address));
581 spin_lock_irqsave(&ha->hardware_lock, flags);
583 /* Reset ISP chip. */
584 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
587 * We need to have a delay here since the card will not respond while
588 * in reset causing an MCA on some architectures.
591 data = qla2x00_debounce_register(®->ctrl_status);
592 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
594 data = RD_REG_WORD(®->ctrl_status);
599 goto chip_diag_failed;
601 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
604 /* Reset RISC processor. */
605 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
606 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
608 /* Workaround for QLA2312 PCI parity error */
609 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
610 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
611 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
613 data = RD_MAILBOX_REG(ha, reg, 0);
620 goto chip_diag_failed;
622 /* Check product ID of chip */
623 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
625 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
626 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
627 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
628 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
629 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
630 mb[3] != PROD_ID_3) {
631 qla_printk(KERN_WARNING, ha,
632 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
634 goto chip_diag_failed;
636 ha->product_id[0] = mb[1];
637 ha->product_id[1] = mb[2];
638 ha->product_id[2] = mb[3];
639 ha->product_id[3] = mb[4];
641 /* Adjust fw RISC transfer size */
642 if (ha->request_q_length > 1024)
643 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
645 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
646 ha->request_q_length;
648 if (IS_QLA2200(ha) &&
649 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
650 /* Limit firmware transfer size with a 2200A */
651 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
654 ha->device_type |= DT_ISP2200A;
655 ha->fw_transfer_size = 128;
658 /* Wrap Incoming Mailboxes Test. */
659 spin_unlock_irqrestore(&ha->hardware_lock, flags);
661 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
662 rval = qla2x00_mbx_reg_test(ha);
664 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
666 qla_printk(KERN_WARNING, ha,
667 "Failed mailbox send register test\n");
670 /* Flag a successful rval */
673 spin_lock_irqsave(&ha->hardware_lock, flags);
677 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
678 "****\n", ha->host_no));
680 spin_unlock_irqrestore(&ha->hardware_lock, flags);
686 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
689 * Returns 0 on success.
692 qla24xx_chip_diag(scsi_qla_host_t *ha)
696 /* Perform RISC reset. */
697 qla24xx_reset_risc(ha);
699 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
701 rval = qla2x00_mbx_reg_test(ha);
703 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
705 qla_printk(KERN_WARNING, ha,
706 "Failed mailbox send register test\n");
708 /* Flag a successful rval */
716 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
719 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
725 qla_printk(KERN_WARNING, ha,
726 "Firmware dump previously allocated.\n");
731 fixed_size = mem_size = eft_size = 0;
732 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
733 fixed_size = sizeof(struct qla2100_fw_dump);
734 } else if (IS_QLA23XX(ha)) {
735 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
736 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
738 } else if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
739 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
740 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
743 /* Allocate memory for Extended Trace Buffer. */
744 eft = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &eft_dma,
747 qla_printk(KERN_WARNING, ha, "Unable to allocate "
748 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
752 rval = qla2x00_trace_control(ha, TC_ENABLE, eft_dma,
755 qla_printk(KERN_WARNING, ha, "Unable to initialize "
756 "EFT (%d).\n", rval);
757 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, eft,
762 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
766 memset(eft, 0, eft_size);
767 ha->eft_dma = eft_dma;
771 req_q_size = ha->request_q_length * sizeof(request_t);
772 rsp_q_size = ha->response_q_length * sizeof(response_t);
774 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
775 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
778 ha->fw_dump = vmalloc(dump_size);
780 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
781 "firmware dump!!!\n", dump_size / 1024);
784 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
792 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
795 ha->fw_dump_len = dump_size;
796 ha->fw_dump->signature[0] = 'Q';
797 ha->fw_dump->signature[1] = 'L';
798 ha->fw_dump->signature[2] = 'G';
799 ha->fw_dump->signature[3] = 'C';
800 ha->fw_dump->version = __constant_htonl(1);
802 ha->fw_dump->fixed_size = htonl(fixed_size);
803 ha->fw_dump->mem_size = htonl(mem_size);
804 ha->fw_dump->req_q_size = htonl(req_q_size);
805 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
807 ha->fw_dump->eft_size = htonl(eft_size);
808 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
809 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
811 ha->fw_dump->header_size =
812 htonl(offsetof(struct qla2xxx_fw_dump, isp));
816 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
819 * Returns 0 on success.
822 qla2x00_resize_request_q(scsi_qla_host_t *ha)
825 uint16_t fw_iocb_cnt = 0;
826 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
827 dma_addr_t request_dma;
828 request_t *request_ring;
830 /* Valid only on recent ISPs. */
831 if (IS_QLA2100(ha) || IS_QLA2200(ha))
834 /* Retrieve IOCB counts available to the firmware. */
835 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
838 /* No point in continuing if current settings are sufficient. */
839 if (fw_iocb_cnt < 1024)
841 if (ha->request_q_length >= request_q_length)
844 /* Attempt to claim larger area for request queue. */
845 request_ring = dma_alloc_coherent(&ha->pdev->dev,
846 (request_q_length + 1) * sizeof(request_t), &request_dma,
848 if (request_ring == NULL)
851 /* Resize successful, report extensions. */
852 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
853 (ha->fw_memory_size + 1) / 1024);
854 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
855 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
857 /* Clear old allocations. */
858 dma_free_coherent(&ha->pdev->dev,
859 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
862 /* Begin using larger queue. */
863 ha->request_q_length = request_q_length;
864 ha->request_ring = request_ring;
865 ha->request_dma = request_dma;
869 * qla2x00_setup_chip() - Load and start RISC firmware.
872 * Returns 0 on success.
875 qla2x00_setup_chip(scsi_qla_host_t *ha)
878 uint32_t srisc_address = 0;
880 /* Load firmware sequences */
881 rval = ha->isp_ops.load_risc(ha, &srisc_address);
882 if (rval == QLA_SUCCESS) {
883 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
884 "code.\n", ha->host_no));
886 rval = qla2x00_verify_checksum(ha, srisc_address);
887 if (rval == QLA_SUCCESS) {
888 /* Start firmware execution. */
889 DEBUG(printk("scsi(%ld): Checksum OK, start "
890 "firmware.\n", ha->host_no));
892 rval = qla2x00_execute_fw(ha, srisc_address);
893 /* Retrieve firmware information. */
894 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
895 qla2x00_get_fw_version(ha,
896 &ha->fw_major_version,
897 &ha->fw_minor_version,
898 &ha->fw_subminor_version,
899 &ha->fw_attributes, &ha->fw_memory_size);
900 qla2x00_resize_request_q(ha);
903 qla2x00_alloc_fw_dump(ha);
906 DEBUG2(printk(KERN_INFO
907 "scsi(%ld): ISP Firmware failed checksum.\n",
913 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
921 * qla2x00_init_response_q_entries() - Initializes response queue entries.
924 * Beginning of request ring has initialization control block already built
925 * by nvram config routine.
927 * Returns 0 on success.
930 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
935 pkt = ha->response_ring_ptr;
936 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
937 pkt->signature = RESPONSE_PROCESSED;
944 * qla2x00_update_fw_options() - Read and process firmware options.
947 * Returns 0 on success.
950 qla2x00_update_fw_options(scsi_qla_host_t *ha)
952 uint16_t swing, emphasis, tx_sens, rx_sens;
954 memset(ha->fw_options, 0, sizeof(ha->fw_options));
955 qla2x00_get_fw_options(ha, ha->fw_options);
957 if (IS_QLA2100(ha) || IS_QLA2200(ha))
960 /* Serial Link options. */
961 DEBUG3(printk("scsi(%ld): Serial link options:\n",
963 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
964 sizeof(ha->fw_seriallink_options)));
966 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
967 if (ha->fw_seriallink_options[3] & BIT_2) {
968 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
971 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
972 emphasis = (ha->fw_seriallink_options[2] &
973 (BIT_4 | BIT_3)) >> 3;
974 tx_sens = ha->fw_seriallink_options[0] &
975 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
976 rx_sens = (ha->fw_seriallink_options[0] &
977 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
978 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
979 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
982 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
983 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
984 ha->fw_options[10] |= BIT_5 |
985 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
986 (tx_sens & (BIT_1 | BIT_0));
989 swing = (ha->fw_seriallink_options[2] &
990 (BIT_7 | BIT_6 | BIT_5)) >> 5;
991 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
992 tx_sens = ha->fw_seriallink_options[1] &
993 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
994 rx_sens = (ha->fw_seriallink_options[1] &
995 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
996 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
997 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1000 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1001 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1002 ha->fw_options[11] |= BIT_5 |
1003 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1004 (tx_sens & (BIT_1 | BIT_0));
1008 /* Return command IOCBs without waiting for an ABTS to complete. */
1009 ha->fw_options[3] |= BIT_13;
1012 if (ha->flags.enable_led_scheme)
1013 ha->fw_options[2] |= BIT_12;
1015 /* Detect ISP6312. */
1017 ha->fw_options[2] |= BIT_13;
1019 /* Update firmware options. */
1020 qla2x00_set_fw_options(ha, ha->fw_options);
1024 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1028 /* Update Serial Link options. */
1029 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1032 rval = qla2x00_set_serdes_params(ha,
1033 le16_to_cpu(ha->fw_seriallink_options24[1]),
1034 le16_to_cpu(ha->fw_seriallink_options24[2]),
1035 le16_to_cpu(ha->fw_seriallink_options24[3]));
1036 if (rval != QLA_SUCCESS) {
1037 qla_printk(KERN_WARNING, ha,
1038 "Unable to update Serial Link options (%x).\n", rval);
1043 qla2x00_config_rings(struct scsi_qla_host *ha)
1045 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1047 /* Setup ring parameters in initialization control block. */
1048 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1049 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1050 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1051 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1052 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1053 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1054 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1055 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1057 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1058 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1059 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1060 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1061 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1065 qla24xx_config_rings(struct scsi_qla_host *ha)
1067 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1068 struct init_cb_24xx *icb;
1070 /* Setup ring parameters in initialization control block. */
1071 icb = (struct init_cb_24xx *)ha->init_cb;
1072 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1073 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1074 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1075 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1076 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1077 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1078 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1079 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1081 WRT_REG_DWORD(®->req_q_in, 0);
1082 WRT_REG_DWORD(®->req_q_out, 0);
1083 WRT_REG_DWORD(®->rsp_q_in, 0);
1084 WRT_REG_DWORD(®->rsp_q_out, 0);
1085 RD_REG_DWORD(®->rsp_q_out);
1089 * qla2x00_init_rings() - Initializes firmware.
1092 * Beginning of request ring has initialization control block already built
1093 * by nvram config routine.
1095 * Returns 0 on success.
1098 qla2x00_init_rings(scsi_qla_host_t *ha)
1101 unsigned long flags = 0;
1104 spin_lock_irqsave(&ha->hardware_lock, flags);
1106 /* Clear outstanding commands array. */
1107 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1108 ha->outstanding_cmds[cnt] = NULL;
1110 ha->current_outstanding_cmd = 0;
1112 /* Clear RSCN queue. */
1113 ha->rscn_in_ptr = 0;
1114 ha->rscn_out_ptr = 0;
1116 /* Initialize firmware. */
1117 ha->request_ring_ptr = ha->request_ring;
1118 ha->req_ring_index = 0;
1119 ha->req_q_cnt = ha->request_q_length;
1120 ha->response_ring_ptr = ha->response_ring;
1121 ha->rsp_ring_index = 0;
1123 /* Initialize response queue entries */
1124 qla2x00_init_response_q_entries(ha);
1126 ha->isp_ops.config_rings(ha);
1128 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1130 /* Update any ISP specific firmware options before initialization. */
1131 ha->isp_ops.update_fw_options(ha);
1133 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1134 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1136 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1139 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1147 * qla2x00_fw_ready() - Waits for firmware ready.
1150 * Returns 0 on success.
1153 qla2x00_fw_ready(scsi_qla_host_t *ha)
1156 unsigned long wtime, mtime;
1157 uint16_t min_wait; /* Minimum wait time if loop is down */
1158 uint16_t wait_time; /* Wait time if loop is coming ready */
1163 /* 20 seconds for loop down. */
1167 * Firmware should take at most one RATOV to login, plus 5 seconds for
1168 * our own processing.
1170 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1171 wait_time = min_wait;
1174 /* Min wait time if loop down */
1175 mtime = jiffies + (min_wait * HZ);
1177 /* wait time before firmware ready */
1178 wtime = jiffies + (wait_time * HZ);
1180 /* Wait for ISP to finish LIP */
1181 if (!ha->flags.init_done)
1182 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1184 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1188 rval = qla2x00_get_firmware_state(ha, &fw_state);
1189 if (rval == QLA_SUCCESS) {
1190 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1191 ha->device_flags &= ~DFLG_NO_CABLE;
1193 if (fw_state == FSTATE_READY) {
1194 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1197 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1198 &ha->login_timeout, &ha->r_a_tov);
1204 rval = QLA_FUNCTION_FAILED;
1206 if (atomic_read(&ha->loop_down_timer) &&
1207 fw_state != FSTATE_READY) {
1208 /* Loop down. Timeout on min_wait for states
1209 * other than Wait for Login.
1211 if (time_after_eq(jiffies, mtime)) {
1212 qla_printk(KERN_INFO, ha,
1213 "Cable is unplugged...\n");
1215 ha->device_flags |= DFLG_NO_CABLE;
1220 /* Mailbox cmd failed. Timeout on min_wait. */
1221 if (time_after_eq(jiffies, mtime))
1225 if (time_after_eq(jiffies, wtime))
1228 /* Delay for a while */
1231 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1232 ha->host_no, fw_state, jiffies));
1235 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1236 ha->host_no, fw_state, jiffies));
1239 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1247 * qla2x00_configure_hba
1248 * Setup adapter context.
1251 * ha = adapter state pointer.
1260 qla2x00_configure_hba(scsi_qla_host_t *ha)
1268 char connect_type[22];
1270 /* Get host addresses. */
1271 rval = qla2x00_get_adapter_id(ha,
1272 &loop_id, &al_pa, &area, &domain, &topo);
1273 if (rval != QLA_SUCCESS) {
1274 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
1275 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1276 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1277 __func__, ha->host_no));
1279 qla_printk(KERN_WARNING, ha,
1280 "ERROR -- Unable to get host loop ID.\n");
1281 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1287 qla_printk(KERN_INFO, ha,
1288 "Cannot get topology - retrying.\n");
1289 return (QLA_FUNCTION_FAILED);
1292 ha->loop_id = loop_id;
1295 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1296 ha->operating_mode = LOOP;
1300 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1302 ha->current_topology = ISP_CFG_NL;
1303 strcpy(connect_type, "(Loop)");
1307 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1309 ha->current_topology = ISP_CFG_FL;
1310 strcpy(connect_type, "(FL_Port)");
1314 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1316 ha->operating_mode = P2P;
1317 ha->current_topology = ISP_CFG_N;
1318 strcpy(connect_type, "(N_Port-to-N_Port)");
1322 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1324 ha->operating_mode = P2P;
1325 ha->current_topology = ISP_CFG_F;
1326 strcpy(connect_type, "(F_Port)");
1330 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1332 ha->host_no, topo));
1333 ha->current_topology = ISP_CFG_NL;
1334 strcpy(connect_type, "(Loop)");
1338 /* Save Host port and loop ID. */
1339 /* byte order - Big Endian */
1340 ha->d_id.b.domain = domain;
1341 ha->d_id.b.area = area;
1342 ha->d_id.b.al_pa = al_pa;
1344 if (!ha->flags.init_done)
1345 qla_printk(KERN_INFO, ha,
1346 "Topology - %s, Host Loop address 0x%x\n",
1347 connect_type, ha->loop_id);
1350 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1352 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1359 * NVRAM configuration for ISP 2xxx
1362 * ha = adapter block pointer.
1365 * initialization control block in response_ring
1366 * host adapters parameters in host adapter block
1372 qla2x00_nvram_config(scsi_qla_host_t *ha)
1377 uint8_t *dptr1, *dptr2;
1378 init_cb_t *icb = ha->init_cb;
1379 nvram_t *nv = (nvram_t *)ha->request_ring;
1380 uint8_t *ptr = (uint8_t *)ha->request_ring;
1381 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1385 /* Determine NVRAM starting address. */
1386 ha->nvram_size = sizeof(nvram_t);
1388 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1389 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1390 ha->nvram_base = 0x80;
1392 /* Get NVRAM data and calculate checksum. */
1393 ha->isp_ops.read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1394 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1397 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1398 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1401 /* Bad NVRAM data, set defaults parameters. */
1402 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1403 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1404 /* Reset NVRAM data. */
1405 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1406 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1408 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1409 "invalid -- WWPN) defaults.\n");
1412 * Set default initialization control block.
1414 memset(nv, 0, ha->nvram_size);
1415 nv->parameter_block_version = ICB_VERSION;
1417 if (IS_QLA23XX(ha)) {
1418 nv->firmware_options[0] = BIT_2 | BIT_1;
1419 nv->firmware_options[1] = BIT_7 | BIT_5;
1420 nv->add_firmware_options[0] = BIT_5;
1421 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1422 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1423 nv->special_options[1] = BIT_7;
1424 } else if (IS_QLA2200(ha)) {
1425 nv->firmware_options[0] = BIT_2 | BIT_1;
1426 nv->firmware_options[1] = BIT_7 | BIT_5;
1427 nv->add_firmware_options[0] = BIT_5;
1428 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1429 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1430 } else if (IS_QLA2100(ha)) {
1431 nv->firmware_options[0] = BIT_3 | BIT_1;
1432 nv->firmware_options[1] = BIT_5;
1433 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1436 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1437 nv->execution_throttle = __constant_cpu_to_le16(16);
1438 nv->retry_count = 8;
1439 nv->retry_delay = 1;
1441 nv->port_name[0] = 33;
1442 nv->port_name[3] = 224;
1443 nv->port_name[4] = 139;
1445 nv->login_timeout = 4;
1448 * Set default host adapter parameters
1450 nv->host_p[1] = BIT_2;
1451 nv->reset_delay = 5;
1452 nv->port_down_retry_count = 8;
1453 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1454 nv->link_down_timeout = 60;
1459 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1461 * The SN2 does not provide BIOS emulation which means you can't change
1462 * potentially bogus BIOS settings. Force the use of default settings
1463 * for link rate and frame size. Hope that the rest of the settings
1466 if (ia64_platform_is("sn2")) {
1467 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1469 nv->special_options[1] = BIT_7;
1473 /* Reset Initialization control block */
1474 memset(icb, 0, ha->init_cb_size);
1477 * Setup driver NVRAM options.
1479 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1480 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1481 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1482 nv->firmware_options[1] &= ~BIT_4;
1484 if (IS_QLA23XX(ha)) {
1485 nv->firmware_options[0] |= BIT_2;
1486 nv->firmware_options[0] &= ~BIT_3;
1487 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1489 if (IS_QLA2300(ha)) {
1490 if (ha->fb_rev == FPM_2310) {
1491 strcpy(ha->model_number, "QLA2310");
1493 strcpy(ha->model_number, "QLA2300");
1497 memcmp(nv->model_number, BINZERO,
1498 sizeof(nv->model_number)) != 0) {
1501 strncpy(ha->model_number, nv->model_number,
1502 sizeof(nv->model_number));
1503 st = en = ha->model_number;
1504 en += sizeof(nv->model_number) - 1;
1506 if (*en != 0x20 && *en != 0x00)
1513 index = (ha->pdev->subsystem_device & 0xff);
1514 if (index < QLA_MODEL_NAMES) {
1515 strcpy(ha->model_number,
1516 qla2x00_model_name[index * 2]);
1518 qla2x00_model_name[index * 2 + 1];
1520 strcpy(ha->model_number, "QLA23xx");
1524 } else if (IS_QLA2200(ha)) {
1525 nv->firmware_options[0] |= BIT_2;
1527 * 'Point-to-point preferred, else loop' is not a safe
1528 * connection mode setting.
1530 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1532 /* Force 'loop preferred, else point-to-point'. */
1533 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1534 nv->add_firmware_options[0] |= BIT_5;
1536 strcpy(ha->model_number, "QLA22xx");
1537 } else /*if (IS_QLA2100(ha))*/ {
1538 strcpy(ha->model_number, "QLA2100");
1542 * Copy over NVRAM RISC parameter block to initialization control block.
1544 dptr1 = (uint8_t *)icb;
1545 dptr2 = (uint8_t *)&nv->parameter_block_version;
1546 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1548 *dptr1++ = *dptr2++;
1550 /* Copy 2nd half. */
1551 dptr1 = (uint8_t *)icb->add_firmware_options;
1552 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1554 *dptr1++ = *dptr2++;
1556 /* Use alternate WWN? */
1557 if (nv->host_p[1] & BIT_7) {
1558 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1559 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1562 /* Prepare nodename */
1563 if ((icb->firmware_options[1] & BIT_6) == 0) {
1565 * Firmware will apply the following mask if the nodename was
1568 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1569 icb->node_name[0] &= 0xF0;
1573 * Set host adapter parameters.
1575 if (nv->host_p[0] & BIT_7)
1576 ql2xextended_error_logging = 1;
1577 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1578 /* Always load RISC code on non ISP2[12]00 chips. */
1579 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1580 ha->flags.disable_risc_code_load = 0;
1581 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1582 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1583 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1584 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1585 ha->flags.disable_serdes = 0;
1587 ha->operating_mode =
1588 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1590 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1591 sizeof(ha->fw_seriallink_options));
1593 /* save HBA serial number */
1594 ha->serial0 = icb->port_name[5];
1595 ha->serial1 = icb->port_name[6];
1596 ha->serial2 = icb->port_name[7];
1597 ha->node_name = icb->node_name;
1598 ha->port_name = icb->port_name;
1600 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1602 ha->retry_count = nv->retry_count;
1604 /* Set minimum login_timeout to 4 seconds. */
1605 if (nv->login_timeout < ql2xlogintimeout)
1606 nv->login_timeout = ql2xlogintimeout;
1607 if (nv->login_timeout < 4)
1608 nv->login_timeout = 4;
1609 ha->login_timeout = nv->login_timeout;
1610 icb->login_timeout = nv->login_timeout;
1612 /* Set minimum RATOV to 200 tenths of a second. */
1615 ha->loop_reset_delay = nv->reset_delay;
1617 /* Link Down Timeout = 0:
1619 * When Port Down timer expires we will start returning
1620 * I/O's to OS with "DID_NO_CONNECT".
1622 * Link Down Timeout != 0:
1624 * The driver waits for the link to come up after link down
1625 * before returning I/Os to OS with "DID_NO_CONNECT".
1627 if (nv->link_down_timeout == 0) {
1628 ha->loop_down_abort_time =
1629 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1631 ha->link_down_timeout = nv->link_down_timeout;
1632 ha->loop_down_abort_time =
1633 (LOOP_DOWN_TIME - ha->link_down_timeout);
1637 * Need enough time to try and get the port back.
1639 ha->port_down_retry_count = nv->port_down_retry_count;
1640 if (qlport_down_retry)
1641 ha->port_down_retry_count = qlport_down_retry;
1642 /* Set login_retry_count */
1643 ha->login_retry_count = nv->retry_count;
1644 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1645 ha->port_down_retry_count > 3)
1646 ha->login_retry_count = ha->port_down_retry_count;
1647 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1648 ha->login_retry_count = ha->port_down_retry_count;
1649 if (ql2xloginretrycount)
1650 ha->login_retry_count = ql2xloginretrycount;
1652 icb->lun_enables = __constant_cpu_to_le16(0);
1653 icb->command_resource_count = 0;
1654 icb->immediate_notify_resource_count = 0;
1655 icb->timeout = __constant_cpu_to_le16(0);
1657 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1659 icb->firmware_options[0] &= ~BIT_3;
1660 icb->add_firmware_options[0] &=
1661 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1662 icb->add_firmware_options[0] |= BIT_2;
1663 icb->response_accumulation_timer = 3;
1664 icb->interrupt_delay_timer = 5;
1666 ha->flags.process_response_queue = 1;
1669 if (!ha->flags.init_done) {
1670 ha->zio_mode = icb->add_firmware_options[0] &
1671 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1672 ha->zio_timer = icb->interrupt_delay_timer ?
1673 icb->interrupt_delay_timer: 2;
1675 icb->add_firmware_options[0] &=
1676 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1677 ha->flags.process_response_queue = 0;
1678 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1679 ha->zio_mode = QLA_ZIO_MODE_6;
1681 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1682 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1683 ha->zio_timer * 100));
1684 qla_printk(KERN_INFO, ha,
1685 "ZIO mode %d enabled; timer delay (%d us).\n",
1686 ha->zio_mode, ha->zio_timer * 100);
1688 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1689 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1690 ha->flags.process_response_queue = 1;
1695 DEBUG2_3(printk(KERN_WARNING
1696 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1702 qla2x00_rport_del(void *data)
1704 fc_port_t *fcport = data;
1705 struct fc_rport *rport;
1706 unsigned long flags;
1708 spin_lock_irqsave(&fcport->rport_lock, flags);
1709 rport = fcport->drport;
1710 fcport->drport = NULL;
1711 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1713 fc_remote_port_delete(rport);
1718 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1720 * @flags: allocation flags
1722 * Returns a pointer to the allocated fcport, or NULL, if none available.
1725 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1729 fcport = kmalloc(sizeof(fc_port_t), flags);
1733 /* Setup fcport template structure. */
1734 memset(fcport, 0, sizeof (fc_port_t));
1736 fcport->port_type = FCT_UNKNOWN;
1737 fcport->loop_id = FC_NO_LOOP_ID;
1738 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1739 fcport->flags = FCF_RLC_SUPPORT;
1740 fcport->supported_classes = FC_COS_UNSPECIFIED;
1741 spin_lock_init(&fcport->rport_lock);
1747 * qla2x00_configure_loop
1748 * Updates Fibre Channel Device Database with what is actually on loop.
1751 * ha = adapter block pointer.
1756 * 2 = database was full and device was not configured.
1759 qla2x00_configure_loop(scsi_qla_host_t *ha)
1762 unsigned long flags, save_flags;
1766 /* Get Initiator ID */
1767 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1768 rval = qla2x00_configure_hba(ha);
1769 if (rval != QLA_SUCCESS) {
1770 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1776 save_flags = flags = ha->dpc_flags;
1777 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1778 ha->host_no, flags));
1781 * If we have both an RSCN and PORT UPDATE pending then handle them
1782 * both at the same time.
1784 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1785 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1787 /* Determine what we need to do */
1788 if (ha->current_topology == ISP_CFG_FL &&
1789 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1791 ha->flags.rscn_queue_overflow = 1;
1792 set_bit(RSCN_UPDATE, &flags);
1794 } else if (ha->current_topology == ISP_CFG_F &&
1795 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1797 ha->flags.rscn_queue_overflow = 1;
1798 set_bit(RSCN_UPDATE, &flags);
1799 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1801 } else if (ha->current_topology == ISP_CFG_N) {
1802 clear_bit(RSCN_UPDATE, &flags);
1804 } else if (!ha->flags.online ||
1805 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1807 ha->flags.rscn_queue_overflow = 1;
1808 set_bit(RSCN_UPDATE, &flags);
1809 set_bit(LOCAL_LOOP_UPDATE, &flags);
1812 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1813 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1814 rval = QLA_FUNCTION_FAILED;
1816 rval = qla2x00_configure_local_loop(ha);
1820 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1821 if (LOOP_TRANSITION(ha)) {
1822 rval = QLA_FUNCTION_FAILED;
1824 rval = qla2x00_configure_fabric(ha);
1828 if (rval == QLA_SUCCESS) {
1829 if (atomic_read(&ha->loop_down_timer) ||
1830 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1831 rval = QLA_FUNCTION_FAILED;
1833 atomic_set(&ha->loop_state, LOOP_READY);
1835 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1840 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1841 __func__, ha->host_no));
1843 DEBUG3(printk("%s: exiting normally\n", __func__));
1846 /* Restore state if a resync event occured during processing */
1847 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1848 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1849 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1850 if (test_bit(RSCN_UPDATE, &save_flags))
1851 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1860 * qla2x00_configure_local_loop
1861 * Updates Fibre Channel Device Database with local loop devices.
1864 * ha = adapter block pointer.
1870 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1875 fc_port_t *fcport, *new_fcport;
1881 uint8_t domain, area, al_pa;
1885 entries = MAX_FIBRE_DEVICES;
1887 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1888 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1890 /* Get list of logged in devices. */
1891 memset(ha->gid_list, 0, GID_LIST_SIZE);
1892 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1894 if (rval != QLA_SUCCESS)
1895 goto cleanup_allocation;
1897 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1898 ha->host_no, entries));
1899 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1900 entries * sizeof(struct gid_list_info)));
1902 /* Allocate temporary fcport for any new fcports discovered. */
1903 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1904 if (new_fcport == NULL) {
1905 rval = QLA_MEMORY_ALLOC_FAILED;
1906 goto cleanup_allocation;
1908 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1911 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1913 list_for_each_entry(fcport, &ha->fcports, list) {
1914 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1915 fcport->port_type != FCT_BROADCAST &&
1916 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1918 DEBUG(printk("scsi(%ld): Marking port lost, "
1920 ha->host_no, fcport->loop_id));
1922 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1923 fcport->flags &= ~FCF_FARP_DONE;
1927 /* Add devices to port list. */
1928 id_iter = (char *)ha->gid_list;
1929 for (index = 0; index < entries; index++) {
1930 domain = ((struct gid_list_info *)id_iter)->domain;
1931 area = ((struct gid_list_info *)id_iter)->area;
1932 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1933 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1934 loop_id = (uint16_t)
1935 ((struct gid_list_info *)id_iter)->loop_id_2100;
1937 loop_id = le16_to_cpu(
1938 ((struct gid_list_info *)id_iter)->loop_id);
1939 id_iter += ha->gid_list_info_size;
1941 /* Bypass reserved domain fields. */
1942 if ((domain & 0xf0) == 0xf0)
1945 /* Bypass if not same domain and area of adapter. */
1946 if (area && domain &&
1947 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
1950 /* Bypass invalid local loop ID. */
1951 if (loop_id > LAST_LOCAL_LOOP_ID)
1954 /* Fill in member data. */
1955 new_fcport->d_id.b.domain = domain;
1956 new_fcport->d_id.b.area = area;
1957 new_fcport->d_id.b.al_pa = al_pa;
1958 new_fcport->loop_id = loop_id;
1959 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1960 if (rval2 != QLA_SUCCESS) {
1961 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1962 "information -- get_port_database=%x, "
1964 ha->host_no, rval2, new_fcport->loop_id));
1965 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
1967 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
1971 /* Check for matching device in port list. */
1974 list_for_each_entry(fcport, &ha->fcports, list) {
1975 if (memcmp(new_fcport->port_name, fcport->port_name,
1979 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1980 FCF_PERSISTENT_BOUND);
1981 fcport->loop_id = new_fcport->loop_id;
1982 fcport->port_type = new_fcport->port_type;
1983 fcport->d_id.b24 = new_fcport->d_id.b24;
1984 memcpy(fcport->node_name, new_fcport->node_name,
1992 /* New device, add to fcports list. */
1993 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1994 list_add_tail(&new_fcport->list, &ha->fcports);
1996 /* Allocate a new replacement fcport. */
1997 fcport = new_fcport;
1998 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1999 if (new_fcport == NULL) {
2000 rval = QLA_MEMORY_ALLOC_FAILED;
2001 goto cleanup_allocation;
2003 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2006 /* Base iIDMA settings on HBA port speed. */
2007 switch (ha->link_data_rate) {
2008 case PORT_SPEED_1GB:
2009 fcport->fp_speed = cpu_to_be16(BIT_15);
2011 case PORT_SPEED_2GB:
2012 fcport->fp_speed = cpu_to_be16(BIT_14);
2014 case PORT_SPEED_4GB:
2015 fcport->fp_speed = cpu_to_be16(BIT_13);
2019 qla2x00_update_fcport(ha, fcport);
2027 if (rval != QLA_SUCCESS) {
2028 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2029 "rval=%x\n", ha->host_no, rval));
2033 ha->device_flags |= DFLG_LOCAL_DEVICES;
2034 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2041 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
2045 qla2x00_mark_all_devices_lost(ha, 0);
2046 list_for_each_entry(fcport, &ha->fcports, list) {
2047 if (fcport->port_type != FCT_TARGET)
2050 qla2x00_update_fcport(ha, fcport);
2055 qla2x00_iidma_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2057 #define LS_UNKNOWN 2
2058 static char *link_speeds[5] = { "1", "2", "?", "4" };
2060 uint16_t port_speed, mb[6];
2062 if (!IS_QLA24XX(ha))
2065 switch (be16_to_cpu(fcport->fp_speed)) {
2067 port_speed = PORT_SPEED_1GB;
2070 port_speed = PORT_SPEED_2GB;
2073 port_speed = PORT_SPEED_4GB;
2076 DEBUG2(printk("scsi(%ld): %02x%02x%02x%02x%02x%02x%02x%02x -- "
2077 "unsupported FM port operating speed (%04x).\n",
2078 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2079 fcport->port_name[2], fcport->port_name[3],
2080 fcport->port_name[4], fcport->port_name[5],
2081 fcport->port_name[6], fcport->port_name[7],
2082 be16_to_cpu(fcport->fp_speed)));
2083 port_speed = PORT_SPEED_UNKNOWN;
2086 if (port_speed == PORT_SPEED_UNKNOWN)
2089 rval = qla2x00_set_idma_speed(ha, fcport->loop_id, port_speed, mb);
2090 if (rval != QLA_SUCCESS) {
2091 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2092 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2093 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2094 fcport->port_name[2], fcport->port_name[3],
2095 fcport->port_name[4], fcport->port_name[5],
2096 fcport->port_name[6], fcport->port_name[7], rval,
2097 port_speed, mb[0], mb[1]));
2099 DEBUG2(qla_printk(KERN_INFO, ha,
2100 "iIDMA adjusted to %s GB/s on "
2101 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2102 link_speeds[port_speed], fcport->port_name[0],
2103 fcport->port_name[1], fcport->port_name[2],
2104 fcport->port_name[3], fcport->port_name[4],
2105 fcport->port_name[5], fcport->port_name[6],
2106 fcport->port_name[7]));
2111 * qla2x00_update_fcport
2112 * Updates device on list.
2115 * ha = adapter block pointer.
2116 * fcport = port structure pointer.
2126 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2129 fcport->login_retry = 0;
2130 fcport->port_login_retry_count = ha->port_down_retry_count *
2132 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2134 fcport->flags &= ~FCF_LOGIN_NEEDED;
2136 qla2x00_iidma_fcport(ha, fcport);
2138 atomic_set(&fcport->state, FCS_ONLINE);
2140 qla2x00_reg_remote_port(ha, fcport);
2144 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2146 struct fc_rport_identifiers rport_ids;
2147 struct fc_rport *rport;
2148 unsigned long flags;
2151 qla2x00_rport_del(fcport);
2155 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2156 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2157 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2158 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2159 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2160 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2162 qla_printk(KERN_WARNING, ha,
2163 "Unable to allocate fc remote port!\n");
2166 spin_lock_irqsave(&fcport->rport_lock, flags);
2167 fcport->rport = rport;
2168 *((fc_port_t **)rport->dd_data) = fcport;
2169 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2171 rport->supported_classes = fcport->supported_classes;
2173 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2174 if (fcport->port_type == FCT_INITIATOR)
2175 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2176 if (fcport->port_type == FCT_TARGET)
2177 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2178 fc_remote_port_rolechg(rport, rport_ids.roles);
2180 if (rport->scsi_target_id != -1 &&
2181 rport->scsi_target_id < ha->host->max_id)
2182 fcport->os_target_id = rport->scsi_target_id;
2186 * qla2x00_configure_fabric
2187 * Setup SNS devices with loop ID's.
2190 * ha = adapter block pointer.
2197 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2200 fc_port_t *fcport, *fcptemp;
2201 uint16_t next_loopid;
2202 uint16_t mb[MAILBOX_REGISTER_COUNT];
2204 LIST_HEAD(new_fcports);
2206 /* If FL port exists, then SNS is present */
2207 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2208 loop_id = NPH_F_PORT;
2210 loop_id = SNS_FL_PORT;
2211 rval = qla2x00_get_port_name(ha, loop_id, ha->fabric_node_name, 1);
2212 if (rval != QLA_SUCCESS) {
2213 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2214 "Port\n", ha->host_no));
2216 ha->device_flags &= ~SWITCH_FOUND;
2217 return (QLA_SUCCESS);
2219 ha->device_flags |= SWITCH_FOUND;
2221 /* Mark devices that need re-synchronization. */
2222 rval2 = qla2x00_device_resync(ha);
2223 if (rval2 == QLA_RSCNS_HANDLED) {
2224 /* No point doing the scan, just continue. */
2225 return (QLA_SUCCESS);
2229 if (ql2xfdmienable &&
2230 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2231 qla2x00_fdmi_register(ha);
2233 /* Ensure we are logged into the SNS. */
2234 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2237 loop_id = SIMPLE_NAME_SERVER;
2238 ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
2239 0xfc, mb, BIT_1 | BIT_0);
2240 if (mb[0] != MBS_COMMAND_COMPLETE) {
2241 DEBUG2(qla_printk(KERN_INFO, ha,
2242 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2243 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2244 mb[0], mb[1], mb[2], mb[6], mb[7]));
2245 return (QLA_SUCCESS);
2248 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2249 if (qla2x00_rft_id(ha)) {
2251 DEBUG2(printk("scsi(%ld): Register FC-4 "
2252 "TYPE failed.\n", ha->host_no));
2254 if (qla2x00_rff_id(ha)) {
2256 DEBUG2(printk("scsi(%ld): Register FC-4 "
2257 "Features failed.\n", ha->host_no));
2259 if (qla2x00_rnn_id(ha)) {
2261 DEBUG2(printk("scsi(%ld): Register Node Name "
2262 "failed.\n", ha->host_no));
2263 } else if (qla2x00_rsnn_nn(ha)) {
2265 DEBUG2(printk("scsi(%ld): Register Symbolic "
2266 "Node Name failed.\n", ha->host_no));
2270 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2271 if (rval != QLA_SUCCESS)
2275 * Logout all previous fabric devices marked lost, except
2278 list_for_each_entry(fcport, &ha->fcports, list) {
2279 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2282 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2285 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2286 qla2x00_mark_device_lost(ha, fcport,
2287 ql2xplogiabsentdevice, 0);
2288 if (fcport->loop_id != FC_NO_LOOP_ID &&
2289 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2290 fcport->port_type != FCT_INITIATOR &&
2291 fcport->port_type != FCT_BROADCAST) {
2292 ha->isp_ops.fabric_logout(ha,
2294 fcport->d_id.b.domain,
2295 fcport->d_id.b.area,
2296 fcport->d_id.b.al_pa);
2297 fcport->loop_id = FC_NO_LOOP_ID;
2302 /* Starting free loop ID. */
2303 next_loopid = ha->min_external_loopid;
2306 * Scan through our port list and login entries that need to be
2309 list_for_each_entry(fcport, &ha->fcports, list) {
2310 if (atomic_read(&ha->loop_down_timer) ||
2311 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2314 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2315 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2318 if (fcport->loop_id == FC_NO_LOOP_ID) {
2319 fcport->loop_id = next_loopid;
2320 rval = qla2x00_find_new_loop_id(ha, fcport);
2321 if (rval != QLA_SUCCESS) {
2322 /* Ran out of IDs to use */
2326 /* Login and update database */
2327 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2330 /* Exit if out of loop IDs. */
2331 if (rval != QLA_SUCCESS) {
2336 * Login and add the new devices to our port list.
2338 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2339 if (atomic_read(&ha->loop_down_timer) ||
2340 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2343 /* Find a new loop ID to use. */
2344 fcport->loop_id = next_loopid;
2345 rval = qla2x00_find_new_loop_id(ha, fcport);
2346 if (rval != QLA_SUCCESS) {
2347 /* Ran out of IDs to use */
2351 /* Remove device from the new list and add it to DB */
2352 list_move_tail(&fcport->list, &ha->fcports);
2354 /* Login and update database */
2355 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2359 /* Free all new device structures not processed. */
2360 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2361 list_del(&fcport->list);
2366 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2367 "rval=%d\n", ha->host_no, rval));
2375 * qla2x00_find_all_fabric_devs
2378 * ha = adapter block pointer.
2379 * dev = database device entry pointer.
2388 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2392 fc_port_t *fcport, *new_fcport, *fcptemp;
2397 int first_dev, last_dev;
2398 port_id_t wrap, nxt_d_id;
2402 /* Try GID_PT to get device list, else GAN. */
2403 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2406 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2407 "on GA_NXT\n", ha->host_no));
2409 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2410 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2413 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2416 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2419 } else if (qla2x00_gfpn_id(ha, swl) == QLA_SUCCESS) {
2420 qla2x00_gpsc(ha, swl);
2425 /* Allocate temporary fcport for any new fcports discovered. */
2426 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2427 if (new_fcport == NULL) {
2429 return (QLA_MEMORY_ALLOC_FAILED);
2431 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2433 /* Set start port ID scan at adapter ID. */
2437 /* Starting free loop ID. */
2438 loop_id = ha->min_external_loopid;
2439 for (; loop_id <= ha->last_loop_id; loop_id++) {
2440 if (qla2x00_is_reserved_id(ha, loop_id))
2443 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2448 wrap.b24 = new_fcport->d_id.b24;
2450 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2451 memcpy(new_fcport->node_name,
2452 swl[swl_idx].node_name, WWN_SIZE);
2453 memcpy(new_fcport->port_name,
2454 swl[swl_idx].port_name, WWN_SIZE);
2455 memcpy(new_fcport->fabric_port_name,
2456 swl[swl_idx].fabric_port_name, WWN_SIZE);
2457 new_fcport->fp_speed = swl[swl_idx].fp_speed;
2459 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2465 /* Send GA_NXT to the switch */
2466 rval = qla2x00_ga_nxt(ha, new_fcport);
2467 if (rval != QLA_SUCCESS) {
2468 qla_printk(KERN_WARNING, ha,
2469 "SNS scan failed -- assuming zero-entry "
2471 list_for_each_entry_safe(fcport, fcptemp,
2472 new_fcports, list) {
2473 list_del(&fcport->list);
2481 /* If wrap on switch device list, exit. */
2483 wrap.b24 = new_fcport->d_id.b24;
2485 } else if (new_fcport->d_id.b24 == wrap.b24) {
2486 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2487 ha->host_no, new_fcport->d_id.b.domain,
2488 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2492 /* Bypass if host adapter. */
2493 if (new_fcport->d_id.b24 == ha->d_id.b24)
2496 /* Bypass if same domain and area of adapter. */
2497 if (((new_fcport->d_id.b24 & 0xffff00) ==
2498 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2502 /* Bypass reserved domain fields. */
2503 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2506 /* Locate matching device in database. */
2508 list_for_each_entry(fcport, &ha->fcports, list) {
2509 if (memcmp(new_fcport->port_name, fcport->port_name,
2515 /* Update port state. */
2516 memcpy(fcport->fabric_port_name,
2517 new_fcport->fabric_port_name, WWN_SIZE);
2518 fcport->fp_speed = new_fcport->fp_speed;
2521 * If address the same and state FCS_ONLINE, nothing
2524 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2525 atomic_read(&fcport->state) == FCS_ONLINE) {
2530 * If device was not a fabric device before.
2532 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2533 fcport->d_id.b24 = new_fcport->d_id.b24;
2534 fcport->loop_id = FC_NO_LOOP_ID;
2535 fcport->flags |= (FCF_FABRIC_DEVICE |
2537 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2542 * Port ID changed or device was marked to be updated;
2543 * Log it out if still logged in and mark it for
2546 fcport->d_id.b24 = new_fcport->d_id.b24;
2547 fcport->flags |= FCF_LOGIN_NEEDED;
2548 if (fcport->loop_id != FC_NO_LOOP_ID &&
2549 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2550 fcport->port_type != FCT_INITIATOR &&
2551 fcport->port_type != FCT_BROADCAST) {
2552 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2553 fcport->d_id.b.domain, fcport->d_id.b.area,
2554 fcport->d_id.b.al_pa);
2555 fcport->loop_id = FC_NO_LOOP_ID;
2564 /* If device was not in our fcports list, then add it. */
2565 list_add_tail(&new_fcport->list, new_fcports);
2567 /* Allocate a new replacement fcport. */
2568 nxt_d_id.b24 = new_fcport->d_id.b24;
2569 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2570 if (new_fcport == NULL) {
2572 return (QLA_MEMORY_ALLOC_FAILED);
2574 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2575 new_fcport->d_id.b24 = nxt_d_id.b24;
2581 if (!list_empty(new_fcports))
2582 ha->device_flags |= DFLG_FABRIC_DEVICES;
2588 * qla2x00_find_new_loop_id
2589 * Scan through our port list and find a new usable loop ID.
2592 * ha: adapter state pointer.
2593 * dev: port structure pointer.
2596 * qla2x00 local function return status code.
2602 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2607 uint16_t first_loop_id;
2611 /* Save starting loop ID. */
2612 first_loop_id = dev->loop_id;
2615 /* Skip loop ID if already used by adapter. */
2616 if (dev->loop_id == ha->loop_id) {
2620 /* Skip reserved loop IDs. */
2621 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2625 /* Reset loop ID if passed the end. */
2626 if (dev->loop_id > ha->last_loop_id) {
2627 /* first loop ID. */
2628 dev->loop_id = ha->min_external_loopid;
2631 /* Check for loop ID being already in use. */
2634 list_for_each_entry(fcport, &ha->fcports, list) {
2635 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2636 /* ID possibly in use */
2642 /* If not in use then it is free to use. */
2647 /* ID in use. Try next value. */
2650 /* If wrap around. No free ID to use. */
2651 if (dev->loop_id == first_loop_id) {
2652 dev->loop_id = FC_NO_LOOP_ID;
2653 rval = QLA_FUNCTION_FAILED;
2662 * qla2x00_device_resync
2663 * Marks devices in the database that needs resynchronization.
2666 * ha = adapter block pointer.
2672 qla2x00_device_resync(scsi_qla_host_t *ha)
2677 uint32_t rscn_entry;
2678 uint8_t rscn_out_iter;
2682 rval = QLA_RSCNS_HANDLED;
2684 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2685 ha->flags.rscn_queue_overflow) {
2687 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2688 format = MSB(MSW(rscn_entry));
2689 d_id.b.domain = LSB(MSW(rscn_entry));
2690 d_id.b.area = MSB(LSW(rscn_entry));
2691 d_id.b.al_pa = LSB(LSW(rscn_entry));
2693 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2694 "[%02x/%02x%02x%02x].\n",
2695 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2696 d_id.b.area, d_id.b.al_pa));
2699 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2700 ha->rscn_out_ptr = 0;
2702 /* Skip duplicate entries. */
2703 for (rscn_out_iter = ha->rscn_out_ptr;
2704 !ha->flags.rscn_queue_overflow &&
2705 rscn_out_iter != ha->rscn_in_ptr;
2706 rscn_out_iter = (rscn_out_iter ==
2707 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2709 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2712 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2713 "entry found at [%d].\n", ha->host_no,
2716 ha->rscn_out_ptr = rscn_out_iter;
2719 /* Queue overflow, set switch default case. */
2720 if (ha->flags.rscn_queue_overflow) {
2721 DEBUG(printk("scsi(%ld): device_resync: rscn "
2722 "overflow.\n", ha->host_no));
2725 ha->flags.rscn_queue_overflow = 0;
2741 ha->rscn_out_ptr = ha->rscn_in_ptr;
2747 list_for_each_entry(fcport, &ha->fcports, list) {
2748 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2749 (fcport->d_id.b24 & mask) != d_id.b24 ||
2750 fcport->port_type == FCT_BROADCAST)
2753 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2755 fcport->port_type != FCT_INITIATOR) {
2756 qla2x00_mark_device_lost(ha, fcport,
2760 fcport->flags &= ~FCF_FARP_DONE;
2767 * qla2x00_fabric_dev_login
2768 * Login fabric target device and update FC port database.
2771 * ha: adapter state pointer.
2772 * fcport: port structure list pointer.
2773 * next_loopid: contains value of a new loop ID that can be used
2774 * by the next login attempt.
2777 * qla2x00 local function return status code.
2783 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2784 uint16_t *next_loopid)
2793 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2794 if (rval == QLA_SUCCESS) {
2795 /* Send an ADISC to tape devices.*/
2797 if (fcport->flags & FCF_TAPE_PRESENT)
2799 rval = qla2x00_get_port_database(ha, fcport, opts);
2800 if (rval != QLA_SUCCESS) {
2801 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2802 fcport->d_id.b.domain, fcport->d_id.b.area,
2803 fcport->d_id.b.al_pa);
2804 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2806 qla2x00_update_fcport(ha, fcport);
2814 * qla2x00_fabric_login
2815 * Issue fabric login command.
2818 * ha = adapter block pointer.
2819 * device = pointer to FC device type structure.
2822 * 0 - Login successfully
2824 * 2 - Initiator device
2828 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2829 uint16_t *next_loopid)
2833 uint16_t tmp_loopid;
2834 uint16_t mb[MAILBOX_REGISTER_COUNT];
2840 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2841 "for port %02x%02x%02x.\n",
2842 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2843 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2845 /* Login fcport on switch. */
2846 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2847 fcport->d_id.b.domain, fcport->d_id.b.area,
2848 fcport->d_id.b.al_pa, mb, BIT_0);
2849 if (mb[0] == MBS_PORT_ID_USED) {
2851 * Device has another loop ID. The firmware team
2852 * recommends the driver perform an implicit login with
2853 * the specified ID again. The ID we just used is save
2854 * here so we return with an ID that can be tried by
2858 tmp_loopid = fcport->loop_id;
2859 fcport->loop_id = mb[1];
2861 DEBUG(printk("Fabric Login: port in use - next "
2862 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2863 fcport->loop_id, fcport->d_id.b.domain,
2864 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2866 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2871 /* A retry occurred before. */
2872 *next_loopid = tmp_loopid;
2875 * No retry occurred before. Just increment the
2876 * ID value for next login.
2878 *next_loopid = (fcport->loop_id + 1);
2881 if (mb[1] & BIT_0) {
2882 fcport->port_type = FCT_INITIATOR;
2884 fcport->port_type = FCT_TARGET;
2885 if (mb[1] & BIT_1) {
2886 fcport->flags |= FCF_TAPE_PRESENT;
2891 fcport->supported_classes |= FC_COS_CLASS2;
2893 fcport->supported_classes |= FC_COS_CLASS3;
2897 } else if (mb[0] == MBS_LOOP_ID_USED) {
2899 * Loop ID already used, try next loop ID.
2902 rval = qla2x00_find_new_loop_id(ha, fcport);
2903 if (rval != QLA_SUCCESS) {
2904 /* Ran out of loop IDs to use */
2907 } else if (mb[0] == MBS_COMMAND_ERROR) {
2909 * Firmware possibly timed out during login. If NO
2910 * retries are left to do then the device is declared
2913 *next_loopid = fcport->loop_id;
2914 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2915 fcport->d_id.b.domain, fcport->d_id.b.area,
2916 fcport->d_id.b.al_pa);
2917 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2923 * unrecoverable / not handled error
2925 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2926 "loop_id=%x jiffies=%lx.\n",
2927 __func__, ha->host_no, mb[0],
2928 fcport->d_id.b.domain, fcport->d_id.b.area,
2929 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2931 *next_loopid = fcport->loop_id;
2932 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2933 fcport->d_id.b.domain, fcport->d_id.b.area,
2934 fcport->d_id.b.al_pa);
2935 fcport->loop_id = FC_NO_LOOP_ID;
2936 fcport->login_retry = 0;
2947 * qla2x00_local_device_login
2948 * Issue local device login command.
2951 * ha = adapter block pointer.
2952 * loop_id = loop id of device to login to.
2954 * Returns (Where's the #define!!!!):
2955 * 0 - Login successfully
2960 qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
2963 uint16_t mb[MAILBOX_REGISTER_COUNT];
2965 memset(mb, 0, sizeof(mb));
2966 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
2967 if (rval == QLA_SUCCESS) {
2968 /* Interrogate mailbox registers for any errors */
2969 if (mb[0] == MBS_COMMAND_ERROR)
2971 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
2972 /* device not in PCB table */
2980 * qla2x00_loop_resync
2981 * Resync with fibre channel devices.
2984 * ha = adapter block pointer.
2990 qla2x00_loop_resync(scsi_qla_host_t *ha)
2997 atomic_set(&ha->loop_state, LOOP_UPDATE);
2998 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2999 if (ha->flags.online) {
3000 if (!(rval = qla2x00_fw_ready(ha))) {
3001 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3004 atomic_set(&ha->loop_state, LOOP_UPDATE);
3006 /* Issue a marker after FW becomes ready. */
3007 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3008 ha->marker_needed = 0;
3010 /* Remap devices on Loop. */
3011 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3013 qla2x00_configure_loop(ha);
3015 } while (!atomic_read(&ha->loop_down_timer) &&
3016 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3018 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3022 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3023 return (QLA_FUNCTION_FAILED);
3027 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3034 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
3040 list_for_each_entry(fcport, &ha->fcports, list) {
3041 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
3044 qla2x00_update_fcport(ha, fcport);
3045 fcport->flags &= ~FCF_RESCAN_NEEDED;
3049 qla2x00_probe_for_all_luns(ha);
3053 qla2x00_update_fcports(scsi_qla_host_t *ha)
3057 /* Go with deferred removal of rport references. */
3058 list_for_each_entry(fcport, &ha->fcports, list)
3060 qla2x00_rport_del(fcport);
3065 * Resets ISP and aborts all outstanding commands.
3068 * ha = adapter block pointer.
3074 qla2x00_abort_isp(scsi_qla_host_t *ha)
3077 unsigned long flags = 0;
3082 if (ha->flags.online) {
3083 ha->flags.online = 0;
3084 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3086 qla_printk(KERN_INFO, ha,
3087 "Performing ISP error recovery - ha= %p.\n", ha);
3088 ha->isp_ops.reset_chip(ha);
3090 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3091 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3092 atomic_set(&ha->loop_state, LOOP_DOWN);
3093 qla2x00_mark_all_devices_lost(ha, 0);
3095 if (!atomic_read(&ha->loop_down_timer))
3096 atomic_set(&ha->loop_down_timer,
3100 spin_lock_irqsave(&ha->hardware_lock, flags);
3101 /* Requeue all commands in outstanding command list. */
3102 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3103 sp = ha->outstanding_cmds[cnt];
3105 ha->outstanding_cmds[cnt] = NULL;
3107 sp->cmd->result = DID_RESET << 16;
3108 sp->cmd->host_scribble = (unsigned char *)NULL;
3109 qla2x00_sp_compl(ha, sp);
3112 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3114 ha->isp_ops.get_flash_version(ha, ha->request_ring);
3116 ha->isp_ops.nvram_config(ha);
3118 if (!qla2x00_restart_isp(ha)) {
3119 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3121 if (!atomic_read(&ha->loop_down_timer)) {
3123 * Issue marker command only when we are going
3124 * to start the I/O .
3126 ha->marker_needed = 1;
3129 ha->flags.online = 1;
3131 ha->isp_ops.enable_intrs(ha);
3133 ha->isp_abort_cnt = 0;
3134 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3137 rval = qla2x00_trace_control(ha, TC_ENABLE,
3138 ha->eft_dma, EFT_NUM_BUFFERS);
3140 qla_printk(KERN_WARNING, ha,
3141 "Unable to reinitialize EFT "
3145 } else { /* failed the ISP abort */
3146 ha->flags.online = 1;
3147 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3148 if (ha->isp_abort_cnt == 0) {
3149 qla_printk(KERN_WARNING, ha,
3150 "ISP error recovery failed - "
3151 "board disabled\n");
3153 * The next call disables the board
3156 ha->isp_ops.reset_adapter(ha);
3157 ha->flags.online = 0;
3158 clear_bit(ISP_ABORT_RETRY,
3161 } else { /* schedule another ISP abort */
3162 ha->isp_abort_cnt--;
3163 DEBUG(printk("qla%ld: ISP abort - "
3164 "retry remaining %d\n",
3165 ha->host_no, ha->isp_abort_cnt));
3169 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3170 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3171 "- retrying (%d) more times\n",
3172 ha->host_no, ha->isp_abort_cnt));
3173 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3181 qla_printk(KERN_INFO, ha,
3182 "qla2x00_abort_isp: **** FAILED ****\n");
3184 DEBUG(printk(KERN_INFO
3185 "qla2x00_abort_isp(%ld): exiting.\n",
3193 * qla2x00_restart_isp
3194 * restarts the ISP after a reset
3197 * ha = adapter block pointer.
3203 qla2x00_restart_isp(scsi_qla_host_t *ha)
3206 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3207 unsigned long flags = 0;
3210 /* If firmware needs to be loaded */
3211 if (qla2x00_isp_firmware(ha)) {
3212 ha->flags.online = 0;
3213 if (!(status = ha->isp_ops.chip_diag(ha))) {
3214 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3215 status = qla2x00_setup_chip(ha);
3219 spin_lock_irqsave(&ha->hardware_lock, flags);
3221 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3223 * Disable SRAM, Instruction RAM and GP RAM
3226 WRT_REG_WORD(®->hccr,
3227 (HCCR_ENABLE_PARITY + 0x0));
3228 RD_REG_WORD(®->hccr);
3231 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3233 status = qla2x00_setup_chip(ha);
3235 spin_lock_irqsave(&ha->hardware_lock, flags);
3237 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3238 /* Enable proper parity */
3241 WRT_REG_WORD(®->hccr,
3242 (HCCR_ENABLE_PARITY + 0x1));
3245 * SRAM, Instruction RAM and GP RAM
3248 WRT_REG_WORD(®->hccr,
3249 (HCCR_ENABLE_PARITY + 0x7));
3250 RD_REG_WORD(®->hccr);
3253 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3258 if (!status && !(status = qla2x00_init_rings(ha))) {
3259 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3260 if (!(status = qla2x00_fw_ready(ha))) {
3261 DEBUG(printk("%s(): Start configure loop, "
3262 "status = %d\n", __func__, status));
3264 /* Issue a marker after FW becomes ready. */
3265 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3267 ha->flags.online = 1;
3268 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3271 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3272 qla2x00_configure_loop(ha);
3274 } while (!atomic_read(&ha->loop_down_timer) &&
3275 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3277 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3280 /* if no cable then assume it's good */
3281 if ((ha->device_flags & DFLG_NO_CABLE))
3284 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3292 * qla2x00_reset_adapter
3296 * ha = adapter block pointer.
3299 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3301 unsigned long flags = 0;
3302 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3304 ha->flags.online = 0;
3305 ha->isp_ops.disable_intrs(ha);
3307 spin_lock_irqsave(&ha->hardware_lock, flags);
3308 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3309 RD_REG_WORD(®->hccr); /* PCI Posting. */
3310 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3311 RD_REG_WORD(®->hccr); /* PCI Posting. */
3312 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3316 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3318 unsigned long flags = 0;
3319 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3321 ha->flags.online = 0;
3322 ha->isp_ops.disable_intrs(ha);
3324 spin_lock_irqsave(&ha->hardware_lock, flags);
3325 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3326 RD_REG_DWORD(®->hccr);
3327 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3328 RD_REG_DWORD(®->hccr);
3329 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3333 qla24xx_nvram_config(scsi_qla_host_t *ha)
3336 struct init_cb_24xx *icb;
3337 struct nvram_24xx *nv;
3339 uint8_t *dptr1, *dptr2;
3344 icb = (struct init_cb_24xx *)ha->init_cb;
3345 nv = (struct nvram_24xx *)ha->request_ring;
3347 /* Determine NVRAM starting address. */
3348 ha->nvram_size = sizeof(struct nvram_24xx);
3349 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3350 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3351 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3352 if (PCI_FUNC(ha->pdev->devfn)) {
3353 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3354 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3357 /* Get NVRAM data and calculate checksum. */
3358 dptr = (uint32_t *)nv;
3359 ha->isp_ops.read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3361 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3362 chksum += le32_to_cpu(*dptr++);
3364 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3365 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3368 /* Bad NVRAM data, set defaults parameters. */
3369 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3370 || nv->id[3] != ' ' ||
3371 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3372 /* Reset NVRAM data. */
3373 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3374 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3375 le16_to_cpu(nv->nvram_version));
3376 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3377 "invalid -- WWPN) defaults.\n");
3380 * Set default initialization control block.
3382 memset(nv, 0, ha->nvram_size);
3383 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3384 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3385 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3386 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3387 nv->exchange_count = __constant_cpu_to_le16(0);
3388 nv->hard_address = __constant_cpu_to_le16(124);
3389 nv->port_name[0] = 0x21;
3390 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3391 nv->port_name[2] = 0x00;
3392 nv->port_name[3] = 0xe0;
3393 nv->port_name[4] = 0x8b;
3394 nv->port_name[5] = 0x1c;
3395 nv->port_name[6] = 0x55;
3396 nv->port_name[7] = 0x86;
3397 nv->node_name[0] = 0x20;
3398 nv->node_name[1] = 0x00;
3399 nv->node_name[2] = 0x00;
3400 nv->node_name[3] = 0xe0;
3401 nv->node_name[4] = 0x8b;
3402 nv->node_name[5] = 0x1c;
3403 nv->node_name[6] = 0x55;
3404 nv->node_name[7] = 0x86;
3405 nv->login_retry_count = __constant_cpu_to_le16(8);
3406 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3407 nv->login_timeout = __constant_cpu_to_le16(0);
3408 nv->firmware_options_1 =
3409 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3410 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3411 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3412 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3413 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3414 nv->efi_parameters = __constant_cpu_to_le32(0);
3415 nv->reset_delay = 5;
3416 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3417 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3418 nv->link_down_timeout = __constant_cpu_to_le16(30);
3423 /* Reset Initialization control block */
3424 memset(icb, 0, sizeof(struct init_cb_24xx));
3426 /* Copy 1st segment. */
3427 dptr1 = (uint8_t *)icb;
3428 dptr2 = (uint8_t *)&nv->version;
3429 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3431 *dptr1++ = *dptr2++;
3433 icb->login_retry_count = nv->login_retry_count;
3434 icb->link_down_on_nos = nv->link_down_on_nos;
3436 /* Copy 2nd segment. */
3437 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3438 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3439 cnt = (uint8_t *)&icb->reserved_3 -
3440 (uint8_t *)&icb->interrupt_delay_timer;
3442 *dptr1++ = *dptr2++;
3445 * Setup driver NVRAM options.
3447 if (memcmp(nv->model_name, BINZERO, sizeof(nv->model_name)) != 0) {
3451 strncpy(ha->model_number, nv->model_name,
3452 sizeof(nv->model_name));
3453 st = en = ha->model_number;
3454 en += sizeof(nv->model_name) - 1;
3456 if (*en != 0x20 && *en != 0x00)
3461 index = (ha->pdev->subsystem_device & 0xff);
3462 if (index < QLA_MODEL_NAMES)
3463 ha->model_desc = qla2x00_model_name[index * 2 + 1];
3465 strcpy(ha->model_number, "QLA2462");
3467 /* Use alternate WWN? */
3468 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3469 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3470 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3473 /* Prepare nodename */
3474 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3476 * Firmware will apply the following mask if the nodename was
3479 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3480 icb->node_name[0] &= 0xF0;
3483 /* Set host adapter parameters. */
3484 ha->flags.disable_risc_code_load = 0;
3485 ha->flags.enable_lip_reset = 1;
3486 ha->flags.enable_lip_full_login = 1;
3487 ha->flags.enable_target_reset = 1;
3488 ha->flags.enable_led_scheme = 0;
3489 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
3491 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3492 (BIT_6 | BIT_5 | BIT_4)) >> 4;
3494 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3495 sizeof(ha->fw_seriallink_options24));
3497 /* save HBA serial number */
3498 ha->serial0 = icb->port_name[5];
3499 ha->serial1 = icb->port_name[6];
3500 ha->serial2 = icb->port_name[7];
3501 ha->node_name = icb->node_name;
3502 ha->port_name = icb->port_name;
3504 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3506 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3508 /* Set minimum login_timeout to 4 seconds. */
3509 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3510 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3511 if (le16_to_cpu(nv->login_timeout) < 4)
3512 nv->login_timeout = __constant_cpu_to_le16(4);
3513 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3514 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3516 /* Set minimum RATOV to 200 tenths of a second. */
3519 ha->loop_reset_delay = nv->reset_delay;
3521 /* Link Down Timeout = 0:
3523 * When Port Down timer expires we will start returning
3524 * I/O's to OS with "DID_NO_CONNECT".
3526 * Link Down Timeout != 0:
3528 * The driver waits for the link to come up after link down
3529 * before returning I/Os to OS with "DID_NO_CONNECT".
3531 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3532 ha->loop_down_abort_time =
3533 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3535 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3536 ha->loop_down_abort_time =
3537 (LOOP_DOWN_TIME - ha->link_down_timeout);
3540 /* Need enough time to try and get the port back. */
3541 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3542 if (qlport_down_retry)
3543 ha->port_down_retry_count = qlport_down_retry;
3545 /* Set login_retry_count */
3546 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3547 if (ha->port_down_retry_count ==
3548 le16_to_cpu(nv->port_down_retry_count) &&
3549 ha->port_down_retry_count > 3)
3550 ha->login_retry_count = ha->port_down_retry_count;
3551 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3552 ha->login_retry_count = ha->port_down_retry_count;
3553 if (ql2xloginretrycount)
3554 ha->login_retry_count = ql2xloginretrycount;
3557 if (!ha->flags.init_done) {
3558 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3559 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3560 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3561 le16_to_cpu(icb->interrupt_delay_timer): 2;
3563 icb->firmware_options_2 &= __constant_cpu_to_le32(
3564 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3565 ha->flags.process_response_queue = 0;
3566 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3567 ha->zio_mode = QLA_ZIO_MODE_6;
3569 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3570 "(%d us).\n", ha->host_no, ha->zio_mode,
3571 ha->zio_timer * 100));
3572 qla_printk(KERN_INFO, ha,
3573 "ZIO mode %d enabled; timer delay (%d us).\n",
3574 ha->zio_mode, ha->zio_timer * 100);
3576 icb->firmware_options_2 |= cpu_to_le32(
3577 (uint32_t)ha->zio_mode);
3578 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3579 ha->flags.process_response_queue = 1;
3583 DEBUG2_3(printk(KERN_WARNING
3584 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3590 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3593 int segments, fragment;
3595 uint32_t *dcode, dlen;
3602 segments = FA_RISC_CODE_SEGMENTS;
3603 faddr = FA_RISC_CODE_ADDR;
3604 dcode = (uint32_t *)ha->request_ring;
3607 /* Validate firmware image by checking version. */
3608 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3609 for (i = 0; i < 4; i++)
3610 dcode[i] = be32_to_cpu(dcode[i]);
3611 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3612 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3613 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3615 qla_printk(KERN_WARNING, ha,
3616 "Unable to verify integrity of flash firmware image!\n");
3617 qla_printk(KERN_WARNING, ha,
3618 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3619 dcode[1], dcode[2], dcode[3]);
3621 return QLA_FUNCTION_FAILED;
3624 while (segments && rval == QLA_SUCCESS) {
3625 /* Read segment's load information. */
3626 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3628 risc_addr = be32_to_cpu(dcode[2]);
3629 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3630 risc_size = be32_to_cpu(dcode[3]);
3633 while (risc_size > 0 && rval == QLA_SUCCESS) {
3634 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3635 if (dlen > risc_size)
3638 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3639 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3640 ha->host_no, risc_addr, dlen, faddr));
3642 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3643 for (i = 0; i < dlen; i++)
3644 dcode[i] = swab32(dcode[i]);
3646 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3649 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3650 "segment %d of firmware\n", ha->host_no,
3652 qla_printk(KERN_WARNING, ha,
3653 "[ERROR] Failed to load segment %d of "
3654 "firmware\n", fragment);
3671 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3674 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3678 uint16_t *wcode, *fwcode;
3679 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3680 struct fw_blob *blob;
3682 /* Load firmware blob. */
3683 blob = qla2x00_request_firmware(ha);
3685 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3686 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3687 "from: " QLA_FW_URL ".\n");
3688 return QLA_FUNCTION_FAILED;
3693 wcode = (uint16_t *)ha->request_ring;
3695 fwcode = (uint16_t *)blob->fw->data;
3698 /* Validate firmware image by checking version. */
3699 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3700 qla_printk(KERN_WARNING, ha,
3701 "Unable to verify integrity of firmware image (%Zd)!\n",
3703 goto fail_fw_integrity;
3705 for (i = 0; i < 4; i++)
3706 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3707 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3708 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3709 wcode[2] == 0 && wcode[3] == 0)) {
3710 qla_printk(KERN_WARNING, ha,
3711 "Unable to verify integrity of firmware image!\n");
3712 qla_printk(KERN_WARNING, ha,
3713 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3714 wcode[1], wcode[2], wcode[3]);
3715 goto fail_fw_integrity;
3719 while (*seg && rval == QLA_SUCCESS) {
3721 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3722 risc_size = be16_to_cpu(fwcode[3]);
3724 /* Validate firmware image size. */
3725 fwclen += risc_size * sizeof(uint16_t);
3726 if (blob->fw->size < fwclen) {
3727 qla_printk(KERN_WARNING, ha,
3728 "Unable to verify integrity of firmware image "
3729 "(%Zd)!\n", blob->fw->size);
3730 goto fail_fw_integrity;
3734 while (risc_size > 0 && rval == QLA_SUCCESS) {
3735 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3736 if (wlen > risc_size)
3739 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3740 "addr %x, number of words 0x%x.\n", ha->host_no,
3743 for (i = 0; i < wlen; i++)
3744 wcode[i] = swab16(fwcode[i]);
3746 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3749 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3750 "segment %d of firmware\n", ha->host_no,
3752 qla_printk(KERN_WARNING, ha,
3753 "[ERROR] Failed to load segment %d of "
3754 "firmware\n", fragment);
3770 return QLA_FUNCTION_FAILED;
3774 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3777 int segments, fragment;
3778 uint32_t *dcode, dlen;
3782 struct fw_blob *blob;
3783 uint32_t *fwcode, fwclen;
3785 /* Load firmware blob. */
3786 blob = qla2x00_request_firmware(ha);
3788 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3789 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3790 "from: " QLA_FW_URL ".\n");
3792 /* Try to load RISC code from flash. */
3793 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3794 "outdated) firmware from flash.\n");
3795 return qla24xx_load_risc_flash(ha, srisc_addr);
3800 segments = FA_RISC_CODE_SEGMENTS;
3801 dcode = (uint32_t *)ha->request_ring;
3803 fwcode = (uint32_t *)blob->fw->data;
3806 /* Validate firmware image by checking version. */
3807 if (blob->fw->size < 8 * sizeof(uint32_t)) {
3808 qla_printk(KERN_WARNING, ha,
3809 "Unable to verify integrity of firmware image (%Zd)!\n",
3811 goto fail_fw_integrity;
3813 for (i = 0; i < 4; i++)
3814 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3815 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3816 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3817 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3819 qla_printk(KERN_WARNING, ha,
3820 "Unable to verify integrity of firmware image!\n");
3821 qla_printk(KERN_WARNING, ha,
3822 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3823 dcode[1], dcode[2], dcode[3]);
3824 goto fail_fw_integrity;
3827 while (segments && rval == QLA_SUCCESS) {
3828 risc_addr = be32_to_cpu(fwcode[2]);
3829 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3830 risc_size = be32_to_cpu(fwcode[3]);
3832 /* Validate firmware image size. */
3833 fwclen += risc_size * sizeof(uint32_t);
3834 if (blob->fw->size < fwclen) {
3835 qla_printk(KERN_WARNING, ha,
3836 "Unable to verify integrity of firmware image "
3837 "(%Zd)!\n", blob->fw->size);
3839 goto fail_fw_integrity;
3843 while (risc_size > 0 && rval == QLA_SUCCESS) {
3844 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3845 if (dlen > risc_size)
3848 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3849 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3852 for (i = 0; i < dlen; i++)
3853 dcode[i] = swab32(fwcode[i]);
3855 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3858 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3859 "segment %d of firmware\n", ha->host_no,
3861 qla_printk(KERN_WARNING, ha,
3862 "[ERROR] Failed to load segment %d of "
3863 "firmware\n", fragment);
3879 return QLA_FUNCTION_FAILED;
3883 qla2x00_try_to_stop_firmware(scsi_qla_host_t *ha)
3887 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
3890 ret = qla2x00_stop_firmware(ha);
3891 for (retries = 5; ret != QLA_SUCCESS && retries ; retries--) {
3892 qla2x00_reset_chip(ha);
3893 if (qla2x00_chip_diag(ha) != QLA_SUCCESS)
3895 if (qla2x00_setup_chip(ha) != QLA_SUCCESS)
3897 qla_printk(KERN_INFO, ha,
3898 "Attempting retry of stop-firmware command...\n");
3899 ret = qla2x00_stop_firmware(ha);