2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/delay.h>
10 #include <linux/vmalloc.h>
12 #include "qla_devtbl.h"
18 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
19 #ifndef EXT_IS_LUN_BIT_SET
20 #define EXT_IS_LUN_BIT_SET(P,L) \
21 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
22 #define EXT_SET_LUN_BIT(P,L) \
23 ((P)->mask[L/8] |= (0x80 >> (L%8)))
27 * QLogic ISP2x00 Hardware Support Function Prototypes.
29 static int qla2x00_isp_firmware(scsi_qla_host_t *);
30 static void qla2x00_resize_request_q(scsi_qla_host_t *);
31 static int qla2x00_setup_chip(scsi_qla_host_t *);
32 static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
33 static int qla2x00_init_rings(scsi_qla_host_t *);
34 static int qla2x00_fw_ready(scsi_qla_host_t *);
35 static int qla2x00_configure_hba(scsi_qla_host_t *);
36 static int qla2x00_configure_loop(scsi_qla_host_t *);
37 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
38 static int qla2x00_configure_fabric(scsi_qla_host_t *);
39 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
40 static int qla2x00_device_resync(scsi_qla_host_t *);
41 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
44 static int qla2x00_restart_isp(scsi_qla_host_t *);
46 static int qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev);
48 /****************************************************************************/
49 /* QLogic ISP2x00 Hardware Support Functions. */
50 /****************************************************************************/
53 * qla2x00_initialize_adapter
57 * ha = adapter block pointer.
63 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
67 /* Clear adapter flags. */
69 ha->flags.reset_active = 0;
70 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
71 atomic_set(&ha->loop_state, LOOP_DOWN);
72 ha->device_flags = DFLG_NO_CABLE;
74 ha->flags.management_server_logged_in = 0;
75 ha->marker_needed = 0;
77 ha->isp_abort_cnt = 0;
78 ha->beacon_blink_led = 0;
79 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
81 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
82 rval = ha->isp_ops->pci_config(ha);
84 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
89 ha->isp_ops->reset_chip(ha);
91 ha->isp_ops->get_flash_version(ha, ha->request_ring);
93 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
95 ha->isp_ops->nvram_config(ha);
97 if (ha->flags.disable_serdes) {
98 /* Mask HBA via NVRAM settings? */
99 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
100 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
101 ha->port_name[0], ha->port_name[1],
102 ha->port_name[2], ha->port_name[3],
103 ha->port_name[4], ha->port_name[5],
104 ha->port_name[6], ha->port_name[7]);
105 return QLA_FUNCTION_FAILED;
108 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
110 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
111 rval = ha->isp_ops->chip_diag(ha);
114 rval = qla2x00_setup_chip(ha);
118 rval = qla2x00_init_rings(ha);
124 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
127 * Returns 0 on success.
130 qla2100_pci_config(scsi_qla_host_t *ha)
135 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
137 pci_set_master(ha->pdev);
138 pci_try_set_mwi(ha->pdev);
140 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
141 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
142 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
144 /* Reset expansion ROM address decode enable */
145 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
146 d &= ~PCI_ROM_ADDRESS_ENABLE;
147 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
149 /* Get PCI bus information. */
150 spin_lock_irqsave(&ha->hardware_lock, flags);
151 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
152 spin_unlock_irqrestore(&ha->hardware_lock, flags);
158 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
161 * Returns 0 on success.
164 qla2300_pci_config(scsi_qla_host_t *ha)
168 unsigned long flags = 0;
170 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
172 pci_set_master(ha->pdev);
173 pci_try_set_mwi(ha->pdev);
175 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
176 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
178 if (IS_QLA2322(ha) || IS_QLA6322(ha))
179 w &= ~PCI_COMMAND_INTX_DISABLE;
180 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
183 * If this is a 2300 card and not 2312, reset the
184 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
185 * the 2310 also reports itself as a 2300 so we need to get the
186 * fb revision level -- a 6 indicates it really is a 2300 and
189 if (IS_QLA2300(ha)) {
190 spin_lock_irqsave(&ha->hardware_lock, flags);
193 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
194 for (cnt = 0; cnt < 30000; cnt++) {
195 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
201 /* Select FPM registers. */
202 WRT_REG_WORD(®->ctrl_status, 0x20);
203 RD_REG_WORD(®->ctrl_status);
205 /* Get the fb rev level */
206 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
208 if (ha->fb_rev == FPM_2300)
209 pci_clear_mwi(ha->pdev);
211 /* Deselect FPM registers. */
212 WRT_REG_WORD(®->ctrl_status, 0x0);
213 RD_REG_WORD(®->ctrl_status);
215 /* Release RISC module. */
216 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
217 for (cnt = 0; cnt < 30000; cnt++) {
218 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
224 spin_unlock_irqrestore(&ha->hardware_lock, flags);
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;
256 pci_set_master(ha->pdev);
257 pci_try_set_mwi(ha->pdev);
259 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
260 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
261 w &= ~PCI_COMMAND_INTX_DISABLE;
262 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
264 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
266 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
267 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
268 pcix_set_mmrbc(ha->pdev, 2048);
270 /* PCIe -- adjust Maximum Read Request Size (2048). */
271 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
272 pcie_set_readrq(ha->pdev, 2048);
274 /* Reset expansion ROM address decode enable */
275 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
276 d &= ~PCI_ROM_ADDRESS_ENABLE;
277 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
279 ha->chip_revision = ha->pdev->revision;
281 /* Get PCI bus information. */
282 spin_lock_irqsave(&ha->hardware_lock, flags);
283 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
284 spin_unlock_irqrestore(&ha->hardware_lock, flags);
290 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
293 * Returns 0 on success.
296 qla25xx_pci_config(scsi_qla_host_t *ha)
301 pci_set_master(ha->pdev);
302 pci_try_set_mwi(ha->pdev);
304 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
305 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
306 w &= ~PCI_COMMAND_INTX_DISABLE;
307 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
309 /* PCIe -- adjust Maximum Read Request Size (2048). */
310 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
311 pcie_set_readrq(ha->pdev, 2048);
313 /* Reset expansion ROM address decode enable */
314 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
315 d &= ~PCI_ROM_ADDRESS_ENABLE;
316 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
318 ha->chip_revision = ha->pdev->revision;
324 * qla2x00_isp_firmware() - Choose firmware image.
327 * Returns 0 on success.
330 qla2x00_isp_firmware(scsi_qla_host_t *ha)
334 /* Assume loading risc code */
335 rval = QLA_FUNCTION_FAILED;
337 if (ha->flags.disable_risc_code_load) {
338 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
340 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
342 /* Verify checksum of loaded RISC code. */
343 rval = qla2x00_verify_checksum(ha, ha->fw_srisc_address);
347 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
355 * qla2x00_reset_chip() - Reset ISP chip.
358 * Returns 0 on success.
361 qla2x00_reset_chip(scsi_qla_host_t *ha)
363 unsigned long flags = 0;
364 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
368 ha->isp_ops->disable_intrs(ha);
370 spin_lock_irqsave(&ha->hardware_lock, flags);
372 /* Turn off master enable */
374 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
375 cmd &= ~PCI_COMMAND_MASTER;
376 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
378 if (!IS_QLA2100(ha)) {
380 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
381 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
382 for (cnt = 0; cnt < 30000; cnt++) {
383 if ((RD_REG_WORD(®->hccr) &
384 HCCR_RISC_PAUSE) != 0)
389 RD_REG_WORD(®->hccr); /* PCI Posting. */
393 /* Select FPM registers. */
394 WRT_REG_WORD(®->ctrl_status, 0x20);
395 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
397 /* FPM Soft Reset. */
398 WRT_REG_WORD(®->fpm_diag_config, 0x100);
399 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
401 /* Toggle Fpm Reset. */
402 if (!IS_QLA2200(ha)) {
403 WRT_REG_WORD(®->fpm_diag_config, 0x0);
404 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
407 /* Select frame buffer registers. */
408 WRT_REG_WORD(®->ctrl_status, 0x10);
409 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
411 /* Reset frame buffer FIFOs. */
412 if (IS_QLA2200(ha)) {
413 WRT_FB_CMD_REG(ha, reg, 0xa000);
414 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
416 WRT_FB_CMD_REG(ha, reg, 0x00fc);
418 /* Read back fb_cmd until zero or 3 seconds max */
419 for (cnt = 0; cnt < 3000; cnt++) {
420 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
426 /* Select RISC module registers. */
427 WRT_REG_WORD(®->ctrl_status, 0);
428 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
430 /* Reset RISC processor. */
431 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
432 RD_REG_WORD(®->hccr); /* PCI Posting. */
434 /* Release RISC processor. */
435 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
436 RD_REG_WORD(®->hccr); /* PCI Posting. */
439 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
440 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
442 /* Reset ISP chip. */
443 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
445 /* Wait for RISC to recover from reset. */
446 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
448 * It is necessary to for a delay here since the card doesn't
449 * respond to PCI reads during a reset. On some architectures
450 * this will result in an MCA.
453 for (cnt = 30000; cnt; cnt--) {
454 if ((RD_REG_WORD(®->ctrl_status) &
455 CSR_ISP_SOFT_RESET) == 0)
462 /* Reset RISC processor. */
463 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
465 WRT_REG_WORD(®->semaphore, 0);
467 /* Release RISC processor. */
468 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
469 RD_REG_WORD(®->hccr); /* PCI Posting. */
471 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
472 for (cnt = 0; cnt < 30000; cnt++) {
473 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
481 /* Turn on master enable */
482 cmd |= PCI_COMMAND_MASTER;
483 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
485 /* Disable RISC pause on FPM parity error. */
486 if (!IS_QLA2100(ha)) {
487 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
488 RD_REG_WORD(®->hccr); /* PCI Posting. */
491 spin_unlock_irqrestore(&ha->hardware_lock, flags);
495 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
498 * Returns 0 on success.
501 qla24xx_reset_risc(scsi_qla_host_t *ha)
503 unsigned long flags = 0;
504 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
508 spin_lock_irqsave(&ha->hardware_lock, flags);
511 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
512 for (cnt = 0; cnt < 30000; cnt++) {
513 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
519 WRT_REG_DWORD(®->ctrl_status,
520 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
521 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
524 /* Wait for firmware to complete NVRAM accesses. */
525 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
526 for (cnt = 10000 ; cnt && d2; cnt--) {
528 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
532 /* Wait for soft-reset to complete. */
533 d2 = RD_REG_DWORD(®->ctrl_status);
534 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
536 d2 = RD_REG_DWORD(®->ctrl_status);
540 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
541 RD_REG_DWORD(®->hccr);
543 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
544 RD_REG_DWORD(®->hccr);
546 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
547 RD_REG_DWORD(®->hccr);
549 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
550 for (cnt = 6000000 ; cnt && d2; cnt--) {
552 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
556 spin_unlock_irqrestore(&ha->hardware_lock, flags);
560 * qla24xx_reset_chip() - Reset ISP24xx chip.
563 * Returns 0 on success.
566 qla24xx_reset_chip(scsi_qla_host_t *ha)
568 ha->isp_ops->disable_intrs(ha);
570 /* Perform RISC reset. */
571 qla24xx_reset_risc(ha);
575 * qla2x00_chip_diag() - Test chip for proper operation.
578 * Returns 0 on success.
581 qla2x00_chip_diag(scsi_qla_host_t *ha)
584 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
585 unsigned long flags = 0;
590 /* Assume a failed state */
591 rval = QLA_FUNCTION_FAILED;
593 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
594 ha->host_no, (u_long)®->flash_address));
596 spin_lock_irqsave(&ha->hardware_lock, flags);
598 /* Reset ISP chip. */
599 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
602 * We need to have a delay here since the card will not respond while
603 * in reset causing an MCA on some architectures.
606 data = qla2x00_debounce_register(®->ctrl_status);
607 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
609 data = RD_REG_WORD(®->ctrl_status);
614 goto chip_diag_failed;
616 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
619 /* Reset RISC processor. */
620 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
621 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
623 /* Workaround for QLA2312 PCI parity error */
624 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
625 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
626 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
628 data = RD_MAILBOX_REG(ha, reg, 0);
635 goto chip_diag_failed;
637 /* Check product ID of chip */
638 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
640 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
641 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
642 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
643 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
644 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
645 mb[3] != PROD_ID_3) {
646 qla_printk(KERN_WARNING, ha,
647 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
649 goto chip_diag_failed;
651 ha->product_id[0] = mb[1];
652 ha->product_id[1] = mb[2];
653 ha->product_id[2] = mb[3];
654 ha->product_id[3] = mb[4];
656 /* Adjust fw RISC transfer size */
657 if (ha->request_q_length > 1024)
658 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
660 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
661 ha->request_q_length;
663 if (IS_QLA2200(ha) &&
664 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
665 /* Limit firmware transfer size with a 2200A */
666 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
669 ha->device_type |= DT_ISP2200A;
670 ha->fw_transfer_size = 128;
673 /* Wrap Incoming Mailboxes Test. */
674 spin_unlock_irqrestore(&ha->hardware_lock, flags);
676 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
677 rval = qla2x00_mbx_reg_test(ha);
679 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
681 qla_printk(KERN_WARNING, ha,
682 "Failed mailbox send register test\n");
685 /* Flag a successful rval */
688 spin_lock_irqsave(&ha->hardware_lock, flags);
692 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
693 "****\n", ha->host_no));
695 spin_unlock_irqrestore(&ha->hardware_lock, flags);
701 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
704 * Returns 0 on success.
707 qla24xx_chip_diag(scsi_qla_host_t *ha)
711 /* Perform RISC reset. */
712 qla24xx_reset_risc(ha);
714 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
716 rval = qla2x00_mbx_reg_test(ha);
718 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
720 qla_printk(KERN_WARNING, ha,
721 "Failed mailbox send register test\n");
723 /* Flag a successful rval */
731 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
734 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
740 qla_printk(KERN_WARNING, ha,
741 "Firmware dump previously allocated.\n");
746 fixed_size = mem_size = eft_size = 0;
747 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
748 fixed_size = sizeof(struct qla2100_fw_dump);
749 } else if (IS_QLA23XX(ha)) {
750 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
751 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
753 } else if (IS_FWI2_CAPABLE(ha)) {
754 fixed_size = IS_QLA25XX(ha) ?
755 offsetof(struct qla25xx_fw_dump, ext_mem):
756 offsetof(struct qla24xx_fw_dump, ext_mem);
757 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
760 /* Allocate memory for Extended Trace Buffer. */
761 eft = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &eft_dma,
764 qla_printk(KERN_WARNING, ha, "Unable to allocate "
765 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
769 rval = qla2x00_trace_control(ha, TC_ENABLE, eft_dma,
772 qla_printk(KERN_WARNING, ha, "Unable to initialize "
773 "EFT (%d).\n", rval);
774 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, eft,
779 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
783 memset(eft, 0, eft_size);
784 ha->eft_dma = eft_dma;
788 req_q_size = ha->request_q_length * sizeof(request_t);
789 rsp_q_size = ha->response_q_length * sizeof(response_t);
791 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
792 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
795 ha->fw_dump = vmalloc(dump_size);
797 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
798 "firmware dump!!!\n", dump_size / 1024);
801 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
809 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
812 ha->fw_dump_len = dump_size;
813 ha->fw_dump->signature[0] = 'Q';
814 ha->fw_dump->signature[1] = 'L';
815 ha->fw_dump->signature[2] = 'G';
816 ha->fw_dump->signature[3] = 'C';
817 ha->fw_dump->version = __constant_htonl(1);
819 ha->fw_dump->fixed_size = htonl(fixed_size);
820 ha->fw_dump->mem_size = htonl(mem_size);
821 ha->fw_dump->req_q_size = htonl(req_q_size);
822 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
824 ha->fw_dump->eft_size = htonl(eft_size);
825 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
826 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
828 ha->fw_dump->header_size =
829 htonl(offsetof(struct qla2xxx_fw_dump, isp));
833 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
836 * Returns 0 on success.
839 qla2x00_resize_request_q(scsi_qla_host_t *ha)
842 uint16_t fw_iocb_cnt = 0;
843 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
844 dma_addr_t request_dma;
845 request_t *request_ring;
847 /* Valid only on recent ISPs. */
848 if (IS_QLA2100(ha) || IS_QLA2200(ha))
851 /* Retrieve IOCB counts available to the firmware. */
852 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
855 /* No point in continuing if current settings are sufficient. */
856 if (fw_iocb_cnt < 1024)
858 if (ha->request_q_length >= request_q_length)
861 /* Attempt to claim larger area for request queue. */
862 request_ring = dma_alloc_coherent(&ha->pdev->dev,
863 (request_q_length + 1) * sizeof(request_t), &request_dma,
865 if (request_ring == NULL)
868 /* Resize successful, report extensions. */
869 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
870 (ha->fw_memory_size + 1) / 1024);
871 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
872 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
874 /* Clear old allocations. */
875 dma_free_coherent(&ha->pdev->dev,
876 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
879 /* Begin using larger queue. */
880 ha->request_q_length = request_q_length;
881 ha->request_ring = request_ring;
882 ha->request_dma = request_dma;
886 * qla2x00_setup_chip() - Load and start RISC firmware.
889 * Returns 0 on success.
892 qla2x00_setup_chip(scsi_qla_host_t *ha)
895 uint32_t srisc_address = 0;
897 /* Load firmware sequences */
898 rval = ha->isp_ops->load_risc(ha, &srisc_address);
899 if (rval == QLA_SUCCESS) {
900 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
901 "code.\n", ha->host_no));
903 rval = qla2x00_verify_checksum(ha, srisc_address);
904 if (rval == QLA_SUCCESS) {
905 /* Start firmware execution. */
906 DEBUG(printk("scsi(%ld): Checksum OK, start "
907 "firmware.\n", ha->host_no));
909 rval = qla2x00_execute_fw(ha, srisc_address);
910 /* Retrieve firmware information. */
911 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
912 qla2x00_get_fw_version(ha,
913 &ha->fw_major_version,
914 &ha->fw_minor_version,
915 &ha->fw_subminor_version,
916 &ha->fw_attributes, &ha->fw_memory_size);
917 qla2x00_resize_request_q(ha);
918 ha->flags.npiv_supported = 0;
919 if (IS_QLA24XX(ha) &&
920 (ha->fw_attributes & BIT_2))
921 ha->flags.npiv_supported = 1;
924 qla2x00_alloc_fw_dump(ha);
927 DEBUG2(printk(KERN_INFO
928 "scsi(%ld): ISP Firmware failed checksum.\n",
934 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
942 * qla2x00_init_response_q_entries() - Initializes response queue entries.
945 * Beginning of request ring has initialization control block already built
946 * by nvram config routine.
948 * Returns 0 on success.
951 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
956 pkt = ha->response_ring_ptr;
957 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
958 pkt->signature = RESPONSE_PROCESSED;
965 * qla2x00_update_fw_options() - Read and process firmware options.
968 * Returns 0 on success.
971 qla2x00_update_fw_options(scsi_qla_host_t *ha)
973 uint16_t swing, emphasis, tx_sens, rx_sens;
975 memset(ha->fw_options, 0, sizeof(ha->fw_options));
976 qla2x00_get_fw_options(ha, ha->fw_options);
978 if (IS_QLA2100(ha) || IS_QLA2200(ha))
981 /* Serial Link options. */
982 DEBUG3(printk("scsi(%ld): Serial link options:\n",
984 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
985 sizeof(ha->fw_seriallink_options)));
987 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
988 if (ha->fw_seriallink_options[3] & BIT_2) {
989 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
992 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
993 emphasis = (ha->fw_seriallink_options[2] &
994 (BIT_4 | BIT_3)) >> 3;
995 tx_sens = ha->fw_seriallink_options[0] &
996 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
997 rx_sens = (ha->fw_seriallink_options[0] &
998 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
999 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1000 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1003 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1004 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1005 ha->fw_options[10] |= BIT_5 |
1006 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1007 (tx_sens & (BIT_1 | BIT_0));
1010 swing = (ha->fw_seriallink_options[2] &
1011 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1012 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1013 tx_sens = ha->fw_seriallink_options[1] &
1014 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1015 rx_sens = (ha->fw_seriallink_options[1] &
1016 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1017 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1018 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1021 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1022 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1023 ha->fw_options[11] |= BIT_5 |
1024 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1025 (tx_sens & (BIT_1 | BIT_0));
1029 /* Return command IOCBs without waiting for an ABTS to complete. */
1030 ha->fw_options[3] |= BIT_13;
1033 if (ha->flags.enable_led_scheme)
1034 ha->fw_options[2] |= BIT_12;
1036 /* Detect ISP6312. */
1038 ha->fw_options[2] |= BIT_13;
1040 /* Update firmware options. */
1041 qla2x00_set_fw_options(ha, ha->fw_options);
1045 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1049 /* Update Serial Link options. */
1050 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1053 rval = qla2x00_set_serdes_params(ha,
1054 le16_to_cpu(ha->fw_seriallink_options24[1]),
1055 le16_to_cpu(ha->fw_seriallink_options24[2]),
1056 le16_to_cpu(ha->fw_seriallink_options24[3]));
1057 if (rval != QLA_SUCCESS) {
1058 qla_printk(KERN_WARNING, ha,
1059 "Unable to update Serial Link options (%x).\n", rval);
1064 qla2x00_config_rings(struct scsi_qla_host *ha)
1066 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1068 /* Setup ring parameters in initialization control block. */
1069 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1070 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1071 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1072 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1073 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1074 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1075 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1076 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1078 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1079 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1080 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1081 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1082 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1086 qla24xx_config_rings(struct scsi_qla_host *ha)
1088 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1089 struct init_cb_24xx *icb;
1091 /* Setup ring parameters in initialization control block. */
1092 icb = (struct init_cb_24xx *)ha->init_cb;
1093 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1094 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1095 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1096 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1097 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1098 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1099 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1100 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1102 WRT_REG_DWORD(®->req_q_in, 0);
1103 WRT_REG_DWORD(®->req_q_out, 0);
1104 WRT_REG_DWORD(®->rsp_q_in, 0);
1105 WRT_REG_DWORD(®->rsp_q_out, 0);
1106 RD_REG_DWORD(®->rsp_q_out);
1110 * qla2x00_init_rings() - Initializes firmware.
1113 * Beginning of request ring has initialization control block already built
1114 * by nvram config routine.
1116 * Returns 0 on success.
1119 qla2x00_init_rings(scsi_qla_host_t *ha)
1122 unsigned long flags = 0;
1124 struct mid_init_cb_24xx *mid_init_cb =
1125 (struct mid_init_cb_24xx *) ha->init_cb;
1127 spin_lock_irqsave(&ha->hardware_lock, flags);
1129 /* Clear outstanding commands array. */
1130 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1131 ha->outstanding_cmds[cnt] = NULL;
1133 ha->current_outstanding_cmd = 0;
1135 /* Clear RSCN queue. */
1136 ha->rscn_in_ptr = 0;
1137 ha->rscn_out_ptr = 0;
1139 /* Initialize firmware. */
1140 ha->request_ring_ptr = ha->request_ring;
1141 ha->req_ring_index = 0;
1142 ha->req_q_cnt = ha->request_q_length;
1143 ha->response_ring_ptr = ha->response_ring;
1144 ha->rsp_ring_index = 0;
1146 /* Initialize response queue entries */
1147 qla2x00_init_response_q_entries(ha);
1149 ha->isp_ops->config_rings(ha);
1151 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1153 /* Update any ISP specific firmware options before initialization. */
1154 ha->isp_ops->update_fw_options(ha);
1156 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1158 mid_init_cb->count = MAX_NUM_VPORT_FABRIC;
1159 ha->max_npiv_vports = MAX_NUM_VPORT_FABRIC;
1161 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1163 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1166 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1174 * qla2x00_fw_ready() - Waits for firmware ready.
1177 * Returns 0 on success.
1180 qla2x00_fw_ready(scsi_qla_host_t *ha)
1183 unsigned long wtime, mtime;
1184 uint16_t min_wait; /* Minimum wait time if loop is down */
1185 uint16_t wait_time; /* Wait time if loop is coming ready */
1190 /* 20 seconds for loop down. */
1194 * Firmware should take at most one RATOV to login, plus 5 seconds for
1195 * our own processing.
1197 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1198 wait_time = min_wait;
1201 /* Min wait time if loop down */
1202 mtime = jiffies + (min_wait * HZ);
1204 /* wait time before firmware ready */
1205 wtime = jiffies + (wait_time * HZ);
1207 /* Wait for ISP to finish LIP */
1208 if (!ha->flags.init_done)
1209 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1211 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1215 rval = qla2x00_get_firmware_state(ha, &fw_state);
1216 if (rval == QLA_SUCCESS) {
1217 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1218 ha->device_flags &= ~DFLG_NO_CABLE;
1220 if (fw_state == FSTATE_READY) {
1221 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1224 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1225 &ha->login_timeout, &ha->r_a_tov);
1231 rval = QLA_FUNCTION_FAILED;
1233 if (atomic_read(&ha->loop_down_timer) &&
1234 fw_state != FSTATE_READY) {
1235 /* Loop down. Timeout on min_wait for states
1236 * other than Wait for Login.
1238 if (time_after_eq(jiffies, mtime)) {
1239 qla_printk(KERN_INFO, ha,
1240 "Cable is unplugged...\n");
1242 ha->device_flags |= DFLG_NO_CABLE;
1247 /* Mailbox cmd failed. Timeout on min_wait. */
1248 if (time_after_eq(jiffies, mtime))
1252 if (time_after_eq(jiffies, wtime))
1255 /* Delay for a while */
1258 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1259 ha->host_no, fw_state, jiffies));
1262 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1263 ha->host_no, fw_state, jiffies));
1266 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1274 * qla2x00_configure_hba
1275 * Setup adapter context.
1278 * ha = adapter state pointer.
1287 qla2x00_configure_hba(scsi_qla_host_t *ha)
1296 char connect_type[22];
1298 /* Get host addresses. */
1299 rval = qla2x00_get_adapter_id(ha,
1300 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
1301 if (rval != QLA_SUCCESS) {
1302 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
1303 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1304 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1305 __func__, ha->host_no));
1307 qla_printk(KERN_WARNING, ha,
1308 "ERROR -- Unable to get host loop ID.\n");
1309 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1315 qla_printk(KERN_INFO, ha,
1316 "Cannot get topology - retrying.\n");
1317 return (QLA_FUNCTION_FAILED);
1320 ha->loop_id = loop_id;
1323 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1324 ha->operating_mode = LOOP;
1329 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1331 ha->current_topology = ISP_CFG_NL;
1332 strcpy(connect_type, "(Loop)");
1336 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1338 ha->switch_cap = sw_cap;
1339 ha->current_topology = ISP_CFG_FL;
1340 strcpy(connect_type, "(FL_Port)");
1344 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1346 ha->operating_mode = P2P;
1347 ha->current_topology = ISP_CFG_N;
1348 strcpy(connect_type, "(N_Port-to-N_Port)");
1352 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1354 ha->switch_cap = sw_cap;
1355 ha->operating_mode = P2P;
1356 ha->current_topology = ISP_CFG_F;
1357 strcpy(connect_type, "(F_Port)");
1361 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1363 ha->host_no, topo));
1364 ha->current_topology = ISP_CFG_NL;
1365 strcpy(connect_type, "(Loop)");
1369 /* Save Host port and loop ID. */
1370 /* byte order - Big Endian */
1371 ha->d_id.b.domain = domain;
1372 ha->d_id.b.area = area;
1373 ha->d_id.b.al_pa = al_pa;
1375 if (!ha->flags.init_done)
1376 qla_printk(KERN_INFO, ha,
1377 "Topology - %s, Host Loop address 0x%x\n",
1378 connect_type, ha->loop_id);
1381 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1383 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1390 qla2x00_set_model_info(scsi_qla_host_t *ha, uint8_t *model, size_t len, char *def)
1395 if (memcmp(model, BINZERO, len) != 0) {
1396 strncpy(ha->model_number, model, len);
1397 st = en = ha->model_number;
1400 if (*en != 0x20 && *en != 0x00)
1405 index = (ha->pdev->subsystem_device & 0xff);
1406 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1407 index < QLA_MODEL_NAMES)
1408 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1410 index = (ha->pdev->subsystem_device & 0xff);
1411 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1412 index < QLA_MODEL_NAMES) {
1413 strcpy(ha->model_number,
1414 qla2x00_model_name[index * 2]);
1415 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1417 strcpy(ha->model_number, def);
1422 /* On sparc systems, obtain port and node WWN from firmware
1425 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, nvram_t *nv)
1428 struct pci_dev *pdev = ha->pdev;
1429 struct device_node *dp = pci_device_to_OF_node(pdev);
1433 val = of_get_property(dp, "port-wwn", &len);
1434 if (val && len >= WWN_SIZE)
1435 memcpy(nv->port_name, val, WWN_SIZE);
1437 val = of_get_property(dp, "node-wwn", &len);
1438 if (val && len >= WWN_SIZE)
1439 memcpy(nv->node_name, val, WWN_SIZE);
1444 * NVRAM configuration for ISP 2xxx
1447 * ha = adapter block pointer.
1450 * initialization control block in response_ring
1451 * host adapters parameters in host adapter block
1457 qla2x00_nvram_config(scsi_qla_host_t *ha)
1462 uint8_t *dptr1, *dptr2;
1463 init_cb_t *icb = ha->init_cb;
1464 nvram_t *nv = ha->nvram;
1465 uint8_t *ptr = ha->nvram;
1466 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1470 /* Determine NVRAM starting address. */
1471 ha->nvram_size = sizeof(nvram_t);
1473 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1474 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1475 ha->nvram_base = 0x80;
1477 /* Get NVRAM data and calculate checksum. */
1478 ha->isp_ops->read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1479 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1482 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1483 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
1485 /* Bad NVRAM data, set defaults parameters. */
1486 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1487 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1488 /* Reset NVRAM data. */
1489 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1490 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1492 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1493 "invalid -- WWPN) defaults.\n");
1496 * Set default initialization control block.
1498 memset(nv, 0, ha->nvram_size);
1499 nv->parameter_block_version = ICB_VERSION;
1501 if (IS_QLA23XX(ha)) {
1502 nv->firmware_options[0] = BIT_2 | BIT_1;
1503 nv->firmware_options[1] = BIT_7 | BIT_5;
1504 nv->add_firmware_options[0] = BIT_5;
1505 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1506 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1507 nv->special_options[1] = BIT_7;
1508 } else if (IS_QLA2200(ha)) {
1509 nv->firmware_options[0] = BIT_2 | BIT_1;
1510 nv->firmware_options[1] = BIT_7 | BIT_5;
1511 nv->add_firmware_options[0] = BIT_5;
1512 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1513 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1514 } else if (IS_QLA2100(ha)) {
1515 nv->firmware_options[0] = BIT_3 | BIT_1;
1516 nv->firmware_options[1] = BIT_5;
1517 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1520 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1521 nv->execution_throttle = __constant_cpu_to_le16(16);
1522 nv->retry_count = 8;
1523 nv->retry_delay = 1;
1525 nv->port_name[0] = 33;
1526 nv->port_name[3] = 224;
1527 nv->port_name[4] = 139;
1529 qla2xxx_nvram_wwn_from_ofw(ha, nv);
1531 nv->login_timeout = 4;
1534 * Set default host adapter parameters
1536 nv->host_p[1] = BIT_2;
1537 nv->reset_delay = 5;
1538 nv->port_down_retry_count = 8;
1539 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1540 nv->link_down_timeout = 60;
1545 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1547 * The SN2 does not provide BIOS emulation which means you can't change
1548 * potentially bogus BIOS settings. Force the use of default settings
1549 * for link rate and frame size. Hope that the rest of the settings
1552 if (ia64_platform_is("sn2")) {
1553 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1555 nv->special_options[1] = BIT_7;
1559 /* Reset Initialization control block */
1560 memset(icb, 0, ha->init_cb_size);
1563 * Setup driver NVRAM options.
1565 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1566 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1567 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1568 nv->firmware_options[1] &= ~BIT_4;
1570 if (IS_QLA23XX(ha)) {
1571 nv->firmware_options[0] |= BIT_2;
1572 nv->firmware_options[0] &= ~BIT_3;
1573 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1575 if (IS_QLA2300(ha)) {
1576 if (ha->fb_rev == FPM_2310) {
1577 strcpy(ha->model_number, "QLA2310");
1579 strcpy(ha->model_number, "QLA2300");
1582 qla2x00_set_model_info(ha, nv->model_number,
1583 sizeof(nv->model_number), "QLA23xx");
1585 } else if (IS_QLA2200(ha)) {
1586 nv->firmware_options[0] |= BIT_2;
1588 * 'Point-to-point preferred, else loop' is not a safe
1589 * connection mode setting.
1591 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1593 /* Force 'loop preferred, else point-to-point'. */
1594 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1595 nv->add_firmware_options[0] |= BIT_5;
1597 strcpy(ha->model_number, "QLA22xx");
1598 } else /*if (IS_QLA2100(ha))*/ {
1599 strcpy(ha->model_number, "QLA2100");
1603 * Copy over NVRAM RISC parameter block to initialization control block.
1605 dptr1 = (uint8_t *)icb;
1606 dptr2 = (uint8_t *)&nv->parameter_block_version;
1607 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1609 *dptr1++ = *dptr2++;
1611 /* Copy 2nd half. */
1612 dptr1 = (uint8_t *)icb->add_firmware_options;
1613 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1615 *dptr1++ = *dptr2++;
1617 /* Use alternate WWN? */
1618 if (nv->host_p[1] & BIT_7) {
1619 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1620 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1623 /* Prepare nodename */
1624 if ((icb->firmware_options[1] & BIT_6) == 0) {
1626 * Firmware will apply the following mask if the nodename was
1629 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1630 icb->node_name[0] &= 0xF0;
1634 * Set host adapter parameters.
1636 if (nv->host_p[0] & BIT_7)
1637 ql2xextended_error_logging = 1;
1638 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1639 /* Always load RISC code on non ISP2[12]00 chips. */
1640 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1641 ha->flags.disable_risc_code_load = 0;
1642 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1643 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1644 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1645 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1646 ha->flags.disable_serdes = 0;
1648 ha->operating_mode =
1649 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1651 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1652 sizeof(ha->fw_seriallink_options));
1654 /* save HBA serial number */
1655 ha->serial0 = icb->port_name[5];
1656 ha->serial1 = icb->port_name[6];
1657 ha->serial2 = icb->port_name[7];
1658 ha->node_name = icb->node_name;
1659 ha->port_name = icb->port_name;
1661 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1663 ha->retry_count = nv->retry_count;
1665 /* Set minimum login_timeout to 4 seconds. */
1666 if (nv->login_timeout < ql2xlogintimeout)
1667 nv->login_timeout = ql2xlogintimeout;
1668 if (nv->login_timeout < 4)
1669 nv->login_timeout = 4;
1670 ha->login_timeout = nv->login_timeout;
1671 icb->login_timeout = nv->login_timeout;
1673 /* Set minimum RATOV to 200 tenths of a second. */
1676 ha->loop_reset_delay = nv->reset_delay;
1678 /* Link Down Timeout = 0:
1680 * When Port Down timer expires we will start returning
1681 * I/O's to OS with "DID_NO_CONNECT".
1683 * Link Down Timeout != 0:
1685 * The driver waits for the link to come up after link down
1686 * before returning I/Os to OS with "DID_NO_CONNECT".
1688 if (nv->link_down_timeout == 0) {
1689 ha->loop_down_abort_time =
1690 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1692 ha->link_down_timeout = nv->link_down_timeout;
1693 ha->loop_down_abort_time =
1694 (LOOP_DOWN_TIME - ha->link_down_timeout);
1698 * Need enough time to try and get the port back.
1700 ha->port_down_retry_count = nv->port_down_retry_count;
1701 if (qlport_down_retry)
1702 ha->port_down_retry_count = qlport_down_retry;
1703 /* Set login_retry_count */
1704 ha->login_retry_count = nv->retry_count;
1705 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1706 ha->port_down_retry_count > 3)
1707 ha->login_retry_count = ha->port_down_retry_count;
1708 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1709 ha->login_retry_count = ha->port_down_retry_count;
1710 if (ql2xloginretrycount)
1711 ha->login_retry_count = ql2xloginretrycount;
1713 icb->lun_enables = __constant_cpu_to_le16(0);
1714 icb->command_resource_count = 0;
1715 icb->immediate_notify_resource_count = 0;
1716 icb->timeout = __constant_cpu_to_le16(0);
1718 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1720 icb->firmware_options[0] &= ~BIT_3;
1721 icb->add_firmware_options[0] &=
1722 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1723 icb->add_firmware_options[0] |= BIT_2;
1724 icb->response_accumulation_timer = 3;
1725 icb->interrupt_delay_timer = 5;
1727 ha->flags.process_response_queue = 1;
1730 if (!ha->flags.init_done) {
1731 ha->zio_mode = icb->add_firmware_options[0] &
1732 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1733 ha->zio_timer = icb->interrupt_delay_timer ?
1734 icb->interrupt_delay_timer: 2;
1736 icb->add_firmware_options[0] &=
1737 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1738 ha->flags.process_response_queue = 0;
1739 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1740 ha->zio_mode = QLA_ZIO_MODE_6;
1742 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1743 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1744 ha->zio_timer * 100));
1745 qla_printk(KERN_INFO, ha,
1746 "ZIO mode %d enabled; timer delay (%d us).\n",
1747 ha->zio_mode, ha->zio_timer * 100);
1749 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1750 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1751 ha->flags.process_response_queue = 1;
1756 DEBUG2_3(printk(KERN_WARNING
1757 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1763 qla2x00_rport_del(void *data)
1765 fc_port_t *fcport = data;
1766 struct fc_rport *rport;
1767 unsigned long flags;
1769 spin_lock_irqsave(&fcport->rport_lock, flags);
1770 rport = fcport->drport;
1771 fcport->drport = NULL;
1772 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1774 fc_remote_port_delete(rport);
1778 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1780 * @flags: allocation flags
1782 * Returns a pointer to the allocated fcport, or NULL, if none available.
1785 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1789 fcport = kmalloc(sizeof(fc_port_t), flags);
1793 /* Setup fcport template structure. */
1794 memset(fcport, 0, sizeof (fc_port_t));
1796 fcport->vp_idx = ha->vp_idx;
1797 fcport->port_type = FCT_UNKNOWN;
1798 fcport->loop_id = FC_NO_LOOP_ID;
1799 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1800 fcport->flags = FCF_RLC_SUPPORT;
1801 fcport->supported_classes = FC_COS_UNSPECIFIED;
1802 spin_lock_init(&fcport->rport_lock);
1808 * qla2x00_configure_loop
1809 * Updates Fibre Channel Device Database with what is actually on loop.
1812 * ha = adapter block pointer.
1817 * 2 = database was full and device was not configured.
1820 qla2x00_configure_loop(scsi_qla_host_t *ha)
1823 unsigned long flags, save_flags;
1827 /* Get Initiator ID */
1828 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1829 rval = qla2x00_configure_hba(ha);
1830 if (rval != QLA_SUCCESS) {
1831 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1837 save_flags = flags = ha->dpc_flags;
1838 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1839 ha->host_no, flags));
1842 * If we have both an RSCN and PORT UPDATE pending then handle them
1843 * both at the same time.
1845 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1846 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1848 /* Determine what we need to do */
1849 if (ha->current_topology == ISP_CFG_FL &&
1850 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1852 ha->flags.rscn_queue_overflow = 1;
1853 set_bit(RSCN_UPDATE, &flags);
1855 } else if (ha->current_topology == ISP_CFG_F &&
1856 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1858 ha->flags.rscn_queue_overflow = 1;
1859 set_bit(RSCN_UPDATE, &flags);
1860 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1862 } else if (ha->current_topology == ISP_CFG_N) {
1863 clear_bit(RSCN_UPDATE, &flags);
1865 } else if (!ha->flags.online ||
1866 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1868 ha->flags.rscn_queue_overflow = 1;
1869 set_bit(RSCN_UPDATE, &flags);
1870 set_bit(LOCAL_LOOP_UPDATE, &flags);
1873 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1874 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1875 rval = QLA_FUNCTION_FAILED;
1877 rval = qla2x00_configure_local_loop(ha);
1881 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1882 if (LOOP_TRANSITION(ha)) {
1883 rval = QLA_FUNCTION_FAILED;
1885 rval = qla2x00_configure_fabric(ha);
1889 if (rval == QLA_SUCCESS) {
1890 if (atomic_read(&ha->loop_down_timer) ||
1891 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1892 rval = QLA_FUNCTION_FAILED;
1894 atomic_set(&ha->loop_state, LOOP_READY);
1896 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1901 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1902 __func__, ha->host_no));
1904 DEBUG3(printk("%s: exiting normally\n", __func__));
1907 /* Restore state if a resync event occured during processing */
1908 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1909 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1910 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1911 if (test_bit(RSCN_UPDATE, &save_flags))
1912 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1921 * qla2x00_configure_local_loop
1922 * Updates Fibre Channel Device Database with local loop devices.
1925 * ha = adapter block pointer.
1931 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1936 fc_port_t *fcport, *new_fcport;
1942 uint8_t domain, area, al_pa;
1943 scsi_qla_host_t *pha = to_qla_parent(ha);
1947 entries = MAX_FIBRE_DEVICES;
1949 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1950 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1952 /* Get list of logged in devices. */
1953 memset(ha->gid_list, 0, GID_LIST_SIZE);
1954 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1956 if (rval != QLA_SUCCESS)
1957 goto cleanup_allocation;
1959 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1960 ha->host_no, entries));
1961 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1962 entries * sizeof(struct gid_list_info)));
1964 /* Allocate temporary fcport for any new fcports discovered. */
1965 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1966 if (new_fcport == NULL) {
1967 rval = QLA_MEMORY_ALLOC_FAILED;
1968 goto cleanup_allocation;
1970 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1973 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1975 list_for_each_entry(fcport, &pha->fcports, list) {
1976 if (fcport->vp_idx != ha->vp_idx)
1979 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1980 fcport->port_type != FCT_BROADCAST &&
1981 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1983 DEBUG(printk("scsi(%ld): Marking port lost, "
1985 ha->host_no, fcport->loop_id));
1987 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1988 fcport->flags &= ~FCF_FARP_DONE;
1992 /* Add devices to port list. */
1993 id_iter = (char *)ha->gid_list;
1994 for (index = 0; index < entries; index++) {
1995 domain = ((struct gid_list_info *)id_iter)->domain;
1996 area = ((struct gid_list_info *)id_iter)->area;
1997 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1998 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1999 loop_id = (uint16_t)
2000 ((struct gid_list_info *)id_iter)->loop_id_2100;
2002 loop_id = le16_to_cpu(
2003 ((struct gid_list_info *)id_iter)->loop_id);
2004 id_iter += ha->gid_list_info_size;
2006 /* Bypass reserved domain fields. */
2007 if ((domain & 0xf0) == 0xf0)
2010 /* Bypass if not same domain and area of adapter. */
2011 if (area && domain &&
2012 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
2015 /* Bypass invalid local loop ID. */
2016 if (loop_id > LAST_LOCAL_LOOP_ID)
2019 /* Fill in member data. */
2020 new_fcport->d_id.b.domain = domain;
2021 new_fcport->d_id.b.area = area;
2022 new_fcport->d_id.b.al_pa = al_pa;
2023 new_fcport->loop_id = loop_id;
2024 new_fcport->vp_idx = ha->vp_idx;
2025 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
2026 if (rval2 != QLA_SUCCESS) {
2027 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2028 "information -- get_port_database=%x, "
2030 ha->host_no, rval2, new_fcport->loop_id));
2031 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2033 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2037 /* Check for matching device in port list. */
2040 list_for_each_entry(fcport, &pha->fcports, list) {
2041 if (fcport->vp_idx != ha->vp_idx)
2044 if (memcmp(new_fcport->port_name, fcport->port_name,
2048 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2049 FCF_PERSISTENT_BOUND);
2050 fcport->loop_id = new_fcport->loop_id;
2051 fcport->port_type = new_fcport->port_type;
2052 fcport->d_id.b24 = new_fcport->d_id.b24;
2053 memcpy(fcport->node_name, new_fcport->node_name,
2061 /* New device, add to fcports list. */
2062 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
2064 new_fcport->ha = ha;
2065 new_fcport->vp_idx = ha->vp_idx;
2066 list_add_tail(&new_fcport->vp_fcport,
2069 list_add_tail(&new_fcport->list, &pha->fcports);
2071 /* Allocate a new replacement fcport. */
2072 fcport = new_fcport;
2073 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2074 if (new_fcport == NULL) {
2075 rval = QLA_MEMORY_ALLOC_FAILED;
2076 goto cleanup_allocation;
2078 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2081 /* Base iIDMA settings on HBA port speed. */
2082 switch (ha->link_data_rate) {
2083 case PORT_SPEED_1GB:
2084 fcport->fp_speed = cpu_to_be16(BIT_15);
2086 case PORT_SPEED_2GB:
2087 fcport->fp_speed = cpu_to_be16(BIT_14);
2089 case PORT_SPEED_4GB:
2090 fcport->fp_speed = cpu_to_be16(BIT_13);
2094 qla2x00_update_fcport(ha, fcport);
2102 if (rval != QLA_SUCCESS) {
2103 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2104 "rval=%x\n", ha->host_no, rval));
2108 ha->device_flags |= DFLG_LOCAL_DEVICES;
2109 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2116 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
2120 qla2x00_mark_all_devices_lost(ha, 0);
2121 list_for_each_entry(fcport, &ha->fcports, list) {
2122 if (fcport->port_type != FCT_TARGET)
2125 qla2x00_update_fcport(ha, fcport);
2130 qla2x00_iidma_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2132 #define LS_UNKNOWN 2
2133 static char *link_speeds[5] = { "1", "2", "?", "4" };
2135 uint16_t port_speed, mb[6];
2137 if (!IS_IIDMA_CAPABLE(ha))
2140 switch (be16_to_cpu(fcport->fp_speed)) {
2142 port_speed = PORT_SPEED_1GB;
2145 port_speed = PORT_SPEED_2GB;
2148 port_speed = PORT_SPEED_4GB;
2151 DEBUG2(printk("scsi(%ld): %02x%02x%02x%02x%02x%02x%02x%02x -- "
2152 "unsupported FM port operating speed (%04x).\n",
2153 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2154 fcport->port_name[2], fcport->port_name[3],
2155 fcport->port_name[4], fcport->port_name[5],
2156 fcport->port_name[6], fcport->port_name[7],
2157 be16_to_cpu(fcport->fp_speed)));
2158 port_speed = PORT_SPEED_UNKNOWN;
2161 if (port_speed == PORT_SPEED_UNKNOWN)
2164 rval = qla2x00_set_idma_speed(ha, fcport->loop_id, port_speed, mb);
2165 if (rval != QLA_SUCCESS) {
2166 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2167 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2168 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2169 fcport->port_name[2], fcport->port_name[3],
2170 fcport->port_name[4], fcport->port_name[5],
2171 fcport->port_name[6], fcport->port_name[7], rval,
2172 port_speed, mb[0], mb[1]));
2174 DEBUG2(qla_printk(KERN_INFO, ha,
2175 "iIDMA adjusted to %s GB/s on "
2176 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2177 link_speeds[port_speed], fcport->port_name[0],
2178 fcport->port_name[1], fcport->port_name[2],
2179 fcport->port_name[3], fcport->port_name[4],
2180 fcport->port_name[5], fcport->port_name[6],
2181 fcport->port_name[7]));
2186 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2188 struct fc_rport_identifiers rport_ids;
2189 struct fc_rport *rport;
2190 unsigned long flags;
2193 qla2x00_rport_del(fcport);
2197 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2198 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2199 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2200 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2201 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2202 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2204 qla_printk(KERN_WARNING, ha,
2205 "Unable to allocate fc remote port!\n");
2208 spin_lock_irqsave(&fcport->rport_lock, flags);
2209 fcport->rport = rport;
2210 *((fc_port_t **)rport->dd_data) = fcport;
2211 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2213 rport->supported_classes = fcport->supported_classes;
2215 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2216 if (fcport->port_type == FCT_INITIATOR)
2217 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2218 if (fcport->port_type == FCT_TARGET)
2219 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2220 fc_remote_port_rolechg(rport, rport_ids.roles);
2222 if (rport->scsi_target_id != -1 &&
2223 rport->scsi_target_id < ha->host->max_id)
2224 fcport->os_target_id = rport->scsi_target_id;
2228 * qla2x00_update_fcport
2229 * Updates device on list.
2232 * ha = adapter block pointer.
2233 * fcport = port structure pointer.
2243 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2245 scsi_qla_host_t *pha = to_qla_parent(ha);
2248 fcport->login_retry = 0;
2249 fcport->port_login_retry_count = pha->port_down_retry_count *
2251 atomic_set(&fcport->port_down_timer, pha->port_down_retry_count *
2253 fcport->flags &= ~FCF_LOGIN_NEEDED;
2255 qla2x00_iidma_fcport(ha, fcport);
2257 atomic_set(&fcport->state, FCS_ONLINE);
2259 qla2x00_reg_remote_port(ha, fcport);
2263 * qla2x00_configure_fabric
2264 * Setup SNS devices with loop ID's.
2267 * ha = adapter block pointer.
2274 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2277 fc_port_t *fcport, *fcptemp;
2278 uint16_t next_loopid;
2279 uint16_t mb[MAILBOX_REGISTER_COUNT];
2281 LIST_HEAD(new_fcports);
2282 scsi_qla_host_t *pha = to_qla_parent(ha);
2284 /* If FL port exists, then SNS is present */
2285 if (IS_FWI2_CAPABLE(ha))
2286 loop_id = NPH_F_PORT;
2288 loop_id = SNS_FL_PORT;
2289 rval = qla2x00_get_port_name(ha, loop_id, ha->fabric_node_name, 1);
2290 if (rval != QLA_SUCCESS) {
2291 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2292 "Port\n", ha->host_no));
2294 ha->device_flags &= ~SWITCH_FOUND;
2295 return (QLA_SUCCESS);
2297 ha->device_flags |= SWITCH_FOUND;
2299 /* Mark devices that need re-synchronization. */
2300 rval2 = qla2x00_device_resync(ha);
2301 if (rval2 == QLA_RSCNS_HANDLED) {
2302 /* No point doing the scan, just continue. */
2303 return (QLA_SUCCESS);
2307 if (ql2xfdmienable &&
2308 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2309 qla2x00_fdmi_register(ha);
2311 /* Ensure we are logged into the SNS. */
2312 if (IS_FWI2_CAPABLE(ha))
2315 loop_id = SIMPLE_NAME_SERVER;
2316 ha->isp_ops->fabric_login(ha, loop_id, 0xff, 0xff,
2317 0xfc, mb, BIT_1 | BIT_0);
2318 if (mb[0] != MBS_COMMAND_COMPLETE) {
2319 DEBUG2(qla_printk(KERN_INFO, ha,
2320 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2321 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2322 mb[0], mb[1], mb[2], mb[6], mb[7]));
2323 return (QLA_SUCCESS);
2326 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2327 if (qla2x00_rft_id(ha)) {
2329 DEBUG2(printk("scsi(%ld): Register FC-4 "
2330 "TYPE failed.\n", ha->host_no));
2332 if (qla2x00_rff_id(ha)) {
2334 DEBUG2(printk("scsi(%ld): Register FC-4 "
2335 "Features failed.\n", ha->host_no));
2337 if (qla2x00_rnn_id(ha)) {
2339 DEBUG2(printk("scsi(%ld): Register Node Name "
2340 "failed.\n", ha->host_no));
2341 } else if (qla2x00_rsnn_nn(ha)) {
2343 DEBUG2(printk("scsi(%ld): Register Symbolic "
2344 "Node Name failed.\n", ha->host_no));
2348 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2349 if (rval != QLA_SUCCESS)
2353 * Logout all previous fabric devices marked lost, except
2356 list_for_each_entry(fcport, &pha->fcports, list) {
2357 if (fcport->vp_idx !=ha->vp_idx)
2360 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2363 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2366 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2367 qla2x00_mark_device_lost(ha, fcport,
2368 ql2xplogiabsentdevice, 0);
2369 if (fcport->loop_id != FC_NO_LOOP_ID &&
2370 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2371 fcport->port_type != FCT_INITIATOR &&
2372 fcport->port_type != FCT_BROADCAST) {
2373 ha->isp_ops->fabric_logout(ha,
2375 fcport->d_id.b.domain,
2376 fcport->d_id.b.area,
2377 fcport->d_id.b.al_pa);
2378 fcport->loop_id = FC_NO_LOOP_ID;
2383 /* Starting free loop ID. */
2384 next_loopid = pha->min_external_loopid;
2387 * Scan through our port list and login entries that need to be
2390 list_for_each_entry(fcport, &pha->fcports, list) {
2391 if (fcport->vp_idx != ha->vp_idx)
2394 if (atomic_read(&ha->loop_down_timer) ||
2395 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2398 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2399 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2402 if (fcport->loop_id == FC_NO_LOOP_ID) {
2403 fcport->loop_id = next_loopid;
2404 rval = qla2x00_find_new_loop_id(ha, fcport);
2405 if (rval != QLA_SUCCESS) {
2406 /* Ran out of IDs to use */
2410 /* Login and update database */
2411 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2414 /* Exit if out of loop IDs. */
2415 if (rval != QLA_SUCCESS) {
2420 * Login and add the new devices to our port list.
2422 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2423 if (atomic_read(&ha->loop_down_timer) ||
2424 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2427 /* Find a new loop ID to use. */
2428 fcport->loop_id = next_loopid;
2429 rval = qla2x00_find_new_loop_id(ha, fcport);
2430 if (rval != QLA_SUCCESS) {
2431 /* Ran out of IDs to use */
2435 /* Login and update database */
2436 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2440 fcport->vp_idx = ha->vp_idx;
2441 list_add_tail(&fcport->vp_fcport,
2443 list_move_tail(&fcport->list,
2444 &ha->parent->fcports);
2446 list_move_tail(&fcport->list, &ha->fcports);
2450 /* Free all new device structures not processed. */
2451 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2452 list_del(&fcport->list);
2457 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2458 "rval=%d\n", ha->host_no, rval));
2466 * qla2x00_find_all_fabric_devs
2469 * ha = adapter block pointer.
2470 * dev = database device entry pointer.
2479 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2483 fc_port_t *fcport, *new_fcport, *fcptemp;
2488 int first_dev, last_dev;
2489 port_id_t wrap, nxt_d_id;
2493 scsi_qla_host_t *vha;
2494 scsi_qla_host_t *pha = to_qla_parent(ha);
2498 /* Try GID_PT to get device list, else GAN. */
2499 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2502 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2503 "on GA_NXT\n", ha->host_no));
2505 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2506 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2509 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2512 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2515 } else if (qla2x00_gfpn_id(ha, swl) == QLA_SUCCESS) {
2516 qla2x00_gpsc(ha, swl);
2521 /* Allocate temporary fcport for any new fcports discovered. */
2522 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2523 if (new_fcport == NULL) {
2525 return (QLA_MEMORY_ALLOC_FAILED);
2527 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2528 new_fcport->vp_idx = ha->vp_idx;
2529 /* Set start port ID scan at adapter ID. */
2533 /* Starting free loop ID. */
2534 loop_id = pha->min_external_loopid;
2535 for (; loop_id <= ha->last_loop_id; loop_id++) {
2536 if (qla2x00_is_reserved_id(ha, loop_id))
2539 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2544 wrap.b24 = new_fcport->d_id.b24;
2546 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2547 memcpy(new_fcport->node_name,
2548 swl[swl_idx].node_name, WWN_SIZE);
2549 memcpy(new_fcport->port_name,
2550 swl[swl_idx].port_name, WWN_SIZE);
2551 memcpy(new_fcport->fabric_port_name,
2552 swl[swl_idx].fabric_port_name, WWN_SIZE);
2553 new_fcport->fp_speed = swl[swl_idx].fp_speed;
2555 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2561 /* Send GA_NXT to the switch */
2562 rval = qla2x00_ga_nxt(ha, new_fcport);
2563 if (rval != QLA_SUCCESS) {
2564 qla_printk(KERN_WARNING, ha,
2565 "SNS scan failed -- assuming zero-entry "
2567 list_for_each_entry_safe(fcport, fcptemp,
2568 new_fcports, list) {
2569 list_del(&fcport->list);
2577 /* If wrap on switch device list, exit. */
2579 wrap.b24 = new_fcport->d_id.b24;
2581 } else if (new_fcport->d_id.b24 == wrap.b24) {
2582 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2583 ha->host_no, new_fcport->d_id.b.domain,
2584 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2588 /* Bypass if same physical adapter. */
2589 if (new_fcport->d_id.b24 == pha->d_id.b24)
2592 /* Bypass virtual ports of the same host. */
2593 if (pha->num_vhosts) {
2594 vp_index = find_next_bit(
2595 (unsigned long *)pha->vp_idx_map,
2596 MAX_MULTI_ID_FABRIC + 1, 1);
2598 for (;vp_index <= MAX_MULTI_ID_FABRIC;
2599 vp_index = find_next_bit(
2600 (unsigned long *)pha->vp_idx_map,
2601 MAX_MULTI_ID_FABRIC + 1, vp_index + 1)) {
2604 list_for_each_entry(vha, &pha->vp_list,
2606 if (vp_index == vha->vp_idx) {
2617 new_fcport->d_id.b24 == vha->d_id.b24)
2620 if (vp_index <= MAX_MULTI_ID_FABRIC)
2624 /* Bypass if same domain and area of adapter. */
2625 if (((new_fcport->d_id.b24 & 0xffff00) ==
2626 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2630 /* Bypass reserved domain fields. */
2631 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2634 /* Locate matching device in database. */
2636 list_for_each_entry(fcport, &pha->fcports, list) {
2637 if (new_fcport->vp_idx != fcport->vp_idx)
2639 if (memcmp(new_fcport->port_name, fcport->port_name,
2645 /* Update port state. */
2646 memcpy(fcport->fabric_port_name,
2647 new_fcport->fabric_port_name, WWN_SIZE);
2648 fcport->fp_speed = new_fcport->fp_speed;
2651 * If address the same and state FCS_ONLINE, nothing
2654 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2655 atomic_read(&fcport->state) == FCS_ONLINE) {
2660 * If device was not a fabric device before.
2662 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2663 fcport->d_id.b24 = new_fcport->d_id.b24;
2664 fcport->loop_id = FC_NO_LOOP_ID;
2665 fcport->flags |= (FCF_FABRIC_DEVICE |
2667 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2672 * Port ID changed or device was marked to be updated;
2673 * Log it out if still logged in and mark it for
2676 fcport->d_id.b24 = new_fcport->d_id.b24;
2677 fcport->flags |= FCF_LOGIN_NEEDED;
2678 if (fcport->loop_id != FC_NO_LOOP_ID &&
2679 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2680 fcport->port_type != FCT_INITIATOR &&
2681 fcport->port_type != FCT_BROADCAST) {
2682 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
2683 fcport->d_id.b.domain, fcport->d_id.b.area,
2684 fcport->d_id.b.al_pa);
2685 fcport->loop_id = FC_NO_LOOP_ID;
2694 /* If device was not in our fcports list, then add it. */
2695 list_add_tail(&new_fcport->list, new_fcports);
2697 /* Allocate a new replacement fcport. */
2698 nxt_d_id.b24 = new_fcport->d_id.b24;
2699 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2700 if (new_fcport == NULL) {
2702 return (QLA_MEMORY_ALLOC_FAILED);
2704 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2705 new_fcport->d_id.b24 = nxt_d_id.b24;
2706 new_fcport->vp_idx = ha->vp_idx;
2712 if (!list_empty(new_fcports))
2713 ha->device_flags |= DFLG_FABRIC_DEVICES;
2719 * qla2x00_find_new_loop_id
2720 * Scan through our port list and find a new usable loop ID.
2723 * ha: adapter state pointer.
2724 * dev: port structure pointer.
2727 * qla2x00 local function return status code.
2733 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2738 uint16_t first_loop_id;
2739 scsi_qla_host_t *pha = to_qla_parent(ha);
2743 /* Save starting loop ID. */
2744 first_loop_id = dev->loop_id;
2747 /* Skip loop ID if already used by adapter. */
2748 if (dev->loop_id == ha->loop_id) {
2752 /* Skip reserved loop IDs. */
2753 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2757 /* Reset loop ID if passed the end. */
2758 if (dev->loop_id > ha->last_loop_id) {
2759 /* first loop ID. */
2760 dev->loop_id = ha->min_external_loopid;
2763 /* Check for loop ID being already in use. */
2766 list_for_each_entry(fcport, &pha->fcports, list) {
2767 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2768 /* ID possibly in use */
2774 /* If not in use then it is free to use. */
2779 /* ID in use. Try next value. */
2782 /* If wrap around. No free ID to use. */
2783 if (dev->loop_id == first_loop_id) {
2784 dev->loop_id = FC_NO_LOOP_ID;
2785 rval = QLA_FUNCTION_FAILED;
2794 * qla2x00_device_resync
2795 * Marks devices in the database that needs resynchronization.
2798 * ha = adapter block pointer.
2804 qla2x00_device_resync(scsi_qla_host_t *ha)
2809 uint32_t rscn_entry;
2810 uint8_t rscn_out_iter;
2813 scsi_qla_host_t *pha = to_qla_parent(ha);
2815 rval = QLA_RSCNS_HANDLED;
2817 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2818 ha->flags.rscn_queue_overflow) {
2820 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2821 format = MSB(MSW(rscn_entry));
2822 d_id.b.domain = LSB(MSW(rscn_entry));
2823 d_id.b.area = MSB(LSW(rscn_entry));
2824 d_id.b.al_pa = LSB(LSW(rscn_entry));
2826 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2827 "[%02x/%02x%02x%02x].\n",
2828 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2829 d_id.b.area, d_id.b.al_pa));
2832 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2833 ha->rscn_out_ptr = 0;
2835 /* Skip duplicate entries. */
2836 for (rscn_out_iter = ha->rscn_out_ptr;
2837 !ha->flags.rscn_queue_overflow &&
2838 rscn_out_iter != ha->rscn_in_ptr;
2839 rscn_out_iter = (rscn_out_iter ==
2840 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2842 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2845 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2846 "entry found at [%d].\n", ha->host_no,
2849 ha->rscn_out_ptr = rscn_out_iter;
2852 /* Queue overflow, set switch default case. */
2853 if (ha->flags.rscn_queue_overflow) {
2854 DEBUG(printk("scsi(%ld): device_resync: rscn "
2855 "overflow.\n", ha->host_no));
2858 ha->flags.rscn_queue_overflow = 0;
2874 ha->rscn_out_ptr = ha->rscn_in_ptr;
2880 list_for_each_entry(fcport, &pha->fcports, list) {
2881 if (fcport->vp_idx != ha->vp_idx)
2884 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2885 (fcport->d_id.b24 & mask) != d_id.b24 ||
2886 fcport->port_type == FCT_BROADCAST)
2889 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2891 fcport->port_type != FCT_INITIATOR) {
2892 qla2x00_mark_device_lost(ha, fcport,
2896 fcport->flags &= ~FCF_FARP_DONE;
2903 * qla2x00_fabric_dev_login
2904 * Login fabric target device and update FC port database.
2907 * ha: adapter state pointer.
2908 * fcport: port structure list pointer.
2909 * next_loopid: contains value of a new loop ID that can be used
2910 * by the next login attempt.
2913 * qla2x00 local function return status code.
2919 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2920 uint16_t *next_loopid)
2929 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2930 if (rval == QLA_SUCCESS) {
2931 /* Send an ADISC to tape devices.*/
2933 if (fcport->flags & FCF_TAPE_PRESENT)
2935 rval = qla2x00_get_port_database(ha, fcport, opts);
2936 if (rval != QLA_SUCCESS) {
2937 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
2938 fcport->d_id.b.domain, fcport->d_id.b.area,
2939 fcport->d_id.b.al_pa);
2940 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2942 qla2x00_update_fcport(ha, fcport);
2950 * qla2x00_fabric_login
2951 * Issue fabric login command.
2954 * ha = adapter block pointer.
2955 * device = pointer to FC device type structure.
2958 * 0 - Login successfully
2960 * 2 - Initiator device
2964 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2965 uint16_t *next_loopid)
2969 uint16_t tmp_loopid;
2970 uint16_t mb[MAILBOX_REGISTER_COUNT];
2976 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2977 "for port %02x%02x%02x.\n",
2978 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2979 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2981 /* Login fcport on switch. */
2982 ha->isp_ops->fabric_login(ha, fcport->loop_id,
2983 fcport->d_id.b.domain, fcport->d_id.b.area,
2984 fcport->d_id.b.al_pa, mb, BIT_0);
2985 if (mb[0] == MBS_PORT_ID_USED) {
2987 * Device has another loop ID. The firmware team
2988 * recommends the driver perform an implicit login with
2989 * the specified ID again. The ID we just used is save
2990 * here so we return with an ID that can be tried by
2994 tmp_loopid = fcport->loop_id;
2995 fcport->loop_id = mb[1];
2997 DEBUG(printk("Fabric Login: port in use - next "
2998 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2999 fcport->loop_id, fcport->d_id.b.domain,
3000 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3002 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3007 /* A retry occurred before. */
3008 *next_loopid = tmp_loopid;
3011 * No retry occurred before. Just increment the
3012 * ID value for next login.
3014 *next_loopid = (fcport->loop_id + 1);
3017 if (mb[1] & BIT_0) {
3018 fcport->port_type = FCT_INITIATOR;
3020 fcport->port_type = FCT_TARGET;
3021 if (mb[1] & BIT_1) {
3022 fcport->flags |= FCF_TAPE_PRESENT;
3027 fcport->supported_classes |= FC_COS_CLASS2;
3029 fcport->supported_classes |= FC_COS_CLASS3;
3033 } else if (mb[0] == MBS_LOOP_ID_USED) {
3035 * Loop ID already used, try next loop ID.
3038 rval = qla2x00_find_new_loop_id(ha, fcport);
3039 if (rval != QLA_SUCCESS) {
3040 /* Ran out of loop IDs to use */
3043 } else if (mb[0] == MBS_COMMAND_ERROR) {
3045 * Firmware possibly timed out during login. If NO
3046 * retries are left to do then the device is declared
3049 *next_loopid = fcport->loop_id;
3050 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
3051 fcport->d_id.b.domain, fcport->d_id.b.area,
3052 fcport->d_id.b.al_pa);
3053 qla2x00_mark_device_lost(ha, fcport, 1, 0);
3059 * unrecoverable / not handled error
3061 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3062 "loop_id=%x jiffies=%lx.\n",
3063 __func__, ha->host_no, mb[0],
3064 fcport->d_id.b.domain, fcport->d_id.b.area,
3065 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3067 *next_loopid = fcport->loop_id;
3068 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
3069 fcport->d_id.b.domain, fcport->d_id.b.area,
3070 fcport->d_id.b.al_pa);
3071 fcport->loop_id = FC_NO_LOOP_ID;
3072 fcport->login_retry = 0;
3083 * qla2x00_local_device_login
3084 * Issue local device login command.
3087 * ha = adapter block pointer.
3088 * loop_id = loop id of device to login to.
3090 * Returns (Where's the #define!!!!):
3091 * 0 - Login successfully
3096 qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
3099 uint16_t mb[MAILBOX_REGISTER_COUNT];
3101 memset(mb, 0, sizeof(mb));
3102 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
3103 if (rval == QLA_SUCCESS) {
3104 /* Interrogate mailbox registers for any errors */
3105 if (mb[0] == MBS_COMMAND_ERROR)
3107 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3108 /* device not in PCB table */
3116 * qla2x00_loop_resync
3117 * Resync with fibre channel devices.
3120 * ha = adapter block pointer.
3126 qla2x00_loop_resync(scsi_qla_host_t *ha)
3133 atomic_set(&ha->loop_state, LOOP_UPDATE);
3134 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3135 if (ha->flags.online) {
3136 if (!(rval = qla2x00_fw_ready(ha))) {
3137 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3140 atomic_set(&ha->loop_state, LOOP_UPDATE);
3142 /* Issue a marker after FW becomes ready. */
3143 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3144 ha->marker_needed = 0;
3146 /* Remap devices on Loop. */
3147 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3149 qla2x00_configure_loop(ha);
3151 } while (!atomic_read(&ha->loop_down_timer) &&
3152 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3154 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3158 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3159 return (QLA_FUNCTION_FAILED);
3163 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3170 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
3176 list_for_each_entry(fcport, &ha->fcports, list) {
3177 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
3180 qla2x00_update_fcport(ha, fcport);
3181 fcport->flags &= ~FCF_RESCAN_NEEDED;
3185 qla2x00_probe_for_all_luns(ha);
3189 qla2x00_update_fcports(scsi_qla_host_t *ha)
3193 /* Go with deferred removal of rport references. */
3194 list_for_each_entry(fcport, &ha->fcports, list)
3196 qla2x00_rport_del(fcport);
3201 * Resets ISP and aborts all outstanding commands.
3204 * ha = adapter block pointer.
3210 qla2x00_abort_isp(scsi_qla_host_t *ha)
3213 unsigned long flags = 0;
3218 if (ha->flags.online) {
3219 ha->flags.online = 0;
3220 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3222 qla_printk(KERN_INFO, ha,
3223 "Performing ISP error recovery - ha= %p.\n", ha);
3224 ha->isp_ops->reset_chip(ha);
3226 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3227 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3228 atomic_set(&ha->loop_state, LOOP_DOWN);
3229 qla2x00_mark_all_devices_lost(ha, 0);
3231 if (!atomic_read(&ha->loop_down_timer))
3232 atomic_set(&ha->loop_down_timer,
3236 spin_lock_irqsave(&ha->hardware_lock, flags);
3237 /* Requeue all commands in outstanding command list. */
3238 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3239 sp = ha->outstanding_cmds[cnt];
3241 ha->outstanding_cmds[cnt] = NULL;
3243 sp->cmd->result = DID_RESET << 16;
3244 sp->cmd->host_scribble = (unsigned char *)NULL;
3245 qla2x00_sp_compl(ha, sp);
3248 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3250 ha->isp_ops->get_flash_version(ha, ha->request_ring);
3252 ha->isp_ops->nvram_config(ha);
3254 if (!qla2x00_restart_isp(ha)) {
3255 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3257 if (!atomic_read(&ha->loop_down_timer)) {
3259 * Issue marker command only when we are going
3260 * to start the I/O .
3262 ha->marker_needed = 1;
3265 ha->flags.online = 1;
3267 ha->isp_ops->enable_intrs(ha);
3269 ha->isp_abort_cnt = 0;
3270 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3273 rval = qla2x00_trace_control(ha, TC_ENABLE,
3274 ha->eft_dma, EFT_NUM_BUFFERS);
3276 qla_printk(KERN_WARNING, ha,
3277 "Unable to reinitialize EFT "
3281 } else { /* failed the ISP abort */
3282 ha->flags.online = 1;
3283 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3284 if (ha->isp_abort_cnt == 0) {
3285 qla_printk(KERN_WARNING, ha,
3286 "ISP error recovery failed - "
3287 "board disabled\n");
3289 * The next call disables the board
3292 ha->isp_ops->reset_adapter(ha);
3293 ha->flags.online = 0;
3294 clear_bit(ISP_ABORT_RETRY,
3297 } else { /* schedule another ISP abort */
3298 ha->isp_abort_cnt--;
3299 DEBUG(printk("qla%ld: ISP abort - "
3300 "retry remaining %d\n",
3301 ha->host_no, ha->isp_abort_cnt));
3305 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3306 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3307 "- retrying (%d) more times\n",
3308 ha->host_no, ha->isp_abort_cnt));
3309 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3317 qla_printk(KERN_INFO, ha,
3318 "qla2x00_abort_isp: **** FAILED ****\n");
3320 DEBUG(printk(KERN_INFO
3321 "qla2x00_abort_isp(%ld): exiting.\n",
3329 * qla2x00_restart_isp
3330 * restarts the ISP after a reset
3333 * ha = adapter block pointer.
3339 qla2x00_restart_isp(scsi_qla_host_t *ha)
3342 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3343 unsigned long flags = 0;
3346 /* If firmware needs to be loaded */
3347 if (qla2x00_isp_firmware(ha)) {
3348 ha->flags.online = 0;
3349 if (!(status = ha->isp_ops->chip_diag(ha))) {
3350 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3351 status = qla2x00_setup_chip(ha);
3355 spin_lock_irqsave(&ha->hardware_lock, flags);
3357 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3359 * Disable SRAM, Instruction RAM and GP RAM
3362 WRT_REG_WORD(®->hccr,
3363 (HCCR_ENABLE_PARITY + 0x0));
3364 RD_REG_WORD(®->hccr);
3367 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3369 status = qla2x00_setup_chip(ha);
3371 spin_lock_irqsave(&ha->hardware_lock, flags);
3373 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3374 /* Enable proper parity */
3377 WRT_REG_WORD(®->hccr,
3378 (HCCR_ENABLE_PARITY + 0x1));
3381 * SRAM, Instruction RAM and GP RAM
3384 WRT_REG_WORD(®->hccr,
3385 (HCCR_ENABLE_PARITY + 0x7));
3386 RD_REG_WORD(®->hccr);
3389 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3394 if (!status && !(status = qla2x00_init_rings(ha))) {
3395 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3396 if (!(status = qla2x00_fw_ready(ha))) {
3397 DEBUG(printk("%s(): Start configure loop, "
3398 "status = %d\n", __func__, status));
3400 /* Issue a marker after FW becomes ready. */
3401 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3403 ha->flags.online = 1;
3404 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3407 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3408 qla2x00_configure_loop(ha);
3410 } while (!atomic_read(&ha->loop_down_timer) &&
3411 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3413 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3416 /* if no cable then assume it's good */
3417 if ((ha->device_flags & DFLG_NO_CABLE))
3420 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3428 * qla2x00_reset_adapter
3432 * ha = adapter block pointer.
3435 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3437 unsigned long flags = 0;
3438 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3440 ha->flags.online = 0;
3441 ha->isp_ops->disable_intrs(ha);
3443 spin_lock_irqsave(&ha->hardware_lock, flags);
3444 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3445 RD_REG_WORD(®->hccr); /* PCI Posting. */
3446 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3447 RD_REG_WORD(®->hccr); /* PCI Posting. */
3448 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3452 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3454 unsigned long flags = 0;
3455 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3457 ha->flags.online = 0;
3458 ha->isp_ops->disable_intrs(ha);
3460 spin_lock_irqsave(&ha->hardware_lock, flags);
3461 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3462 RD_REG_DWORD(®->hccr);
3463 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3464 RD_REG_DWORD(®->hccr);
3465 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3468 /* On sparc systems, obtain port and node WWN from firmware
3471 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, struct nvram_24xx *nv)
3474 struct pci_dev *pdev = ha->pdev;
3475 struct device_node *dp = pci_device_to_OF_node(pdev);
3479 val = of_get_property(dp, "port-wwn", &len);
3480 if (val && len >= WWN_SIZE)
3481 memcpy(nv->port_name, val, WWN_SIZE);
3483 val = of_get_property(dp, "node-wwn", &len);
3484 if (val && len >= WWN_SIZE)
3485 memcpy(nv->node_name, val, WWN_SIZE);
3490 qla24xx_nvram_config(scsi_qla_host_t *ha)
3493 struct init_cb_24xx *icb;
3494 struct nvram_24xx *nv;
3496 uint8_t *dptr1, *dptr2;
3501 icb = (struct init_cb_24xx *)ha->init_cb;
3504 /* Determine NVRAM starting address. */
3505 ha->nvram_size = sizeof(struct nvram_24xx);
3506 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3507 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3508 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3509 if (PCI_FUNC(ha->pdev->devfn)) {
3510 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3511 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3514 /* Get VPD data into cache */
3515 ha->vpd = ha->nvram + VPD_OFFSET;
3516 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd,
3517 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3519 /* Get NVRAM data into cache and calculate checksum. */
3520 dptr = (uint32_t *)nv;
3521 ha->isp_ops->read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3523 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3524 chksum += le32_to_cpu(*dptr++);
3526 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3527 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
3529 /* Bad NVRAM data, set defaults parameters. */
3530 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3531 || nv->id[3] != ' ' ||
3532 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3533 /* Reset NVRAM data. */
3534 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3535 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3536 le16_to_cpu(nv->nvram_version));
3537 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3538 "invalid -- WWPN) defaults.\n");
3541 * Set default initialization control block.
3543 memset(nv, 0, ha->nvram_size);
3544 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3545 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3546 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3547 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3548 nv->exchange_count = __constant_cpu_to_le16(0);
3549 nv->hard_address = __constant_cpu_to_le16(124);
3550 nv->port_name[0] = 0x21;
3551 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3552 nv->port_name[2] = 0x00;
3553 nv->port_name[3] = 0xe0;
3554 nv->port_name[4] = 0x8b;
3555 nv->port_name[5] = 0x1c;
3556 nv->port_name[6] = 0x55;
3557 nv->port_name[7] = 0x86;
3558 nv->node_name[0] = 0x20;
3559 nv->node_name[1] = 0x00;
3560 nv->node_name[2] = 0x00;
3561 nv->node_name[3] = 0xe0;
3562 nv->node_name[4] = 0x8b;
3563 nv->node_name[5] = 0x1c;
3564 nv->node_name[6] = 0x55;
3565 nv->node_name[7] = 0x86;
3566 qla24xx_nvram_wwn_from_ofw(ha, nv);
3567 nv->login_retry_count = __constant_cpu_to_le16(8);
3568 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3569 nv->login_timeout = __constant_cpu_to_le16(0);
3570 nv->firmware_options_1 =
3571 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3572 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3573 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3574 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3575 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3576 nv->efi_parameters = __constant_cpu_to_le32(0);
3577 nv->reset_delay = 5;
3578 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3579 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3580 nv->link_down_timeout = __constant_cpu_to_le16(30);
3585 /* Reset Initialization control block */
3586 memset(icb, 0, sizeof(struct init_cb_24xx));
3588 /* Copy 1st segment. */
3589 dptr1 = (uint8_t *)icb;
3590 dptr2 = (uint8_t *)&nv->version;
3591 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3593 *dptr1++ = *dptr2++;
3595 icb->login_retry_count = nv->login_retry_count;
3596 icb->link_down_on_nos = nv->link_down_on_nos;
3598 /* Copy 2nd segment. */
3599 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3600 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3601 cnt = (uint8_t *)&icb->reserved_3 -
3602 (uint8_t *)&icb->interrupt_delay_timer;
3604 *dptr1++ = *dptr2++;
3607 * Setup driver NVRAM options.
3609 qla2x00_set_model_info(ha, nv->model_name, sizeof(nv->model_name),
3612 /* Use alternate WWN? */
3613 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3614 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3615 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3618 /* Prepare nodename */
3619 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3621 * Firmware will apply the following mask if the nodename was
3624 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3625 icb->node_name[0] &= 0xF0;
3628 /* Set host adapter parameters. */
3629 ha->flags.disable_risc_code_load = 0;
3630 ha->flags.enable_lip_reset = 0;
3631 ha->flags.enable_lip_full_login =
3632 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3633 ha->flags.enable_target_reset =
3634 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
3635 ha->flags.enable_led_scheme = 0;
3636 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
3638 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3639 (BIT_6 | BIT_5 | BIT_4)) >> 4;
3641 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3642 sizeof(ha->fw_seriallink_options24));
3644 /* save HBA serial number */
3645 ha->serial0 = icb->port_name[5];
3646 ha->serial1 = icb->port_name[6];
3647 ha->serial2 = icb->port_name[7];
3648 ha->node_name = icb->node_name;
3649 ha->port_name = icb->port_name;
3651 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3653 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3655 /* Set minimum login_timeout to 4 seconds. */
3656 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3657 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3658 if (le16_to_cpu(nv->login_timeout) < 4)
3659 nv->login_timeout = __constant_cpu_to_le16(4);
3660 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3661 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3663 /* Set minimum RATOV to 200 tenths of a second. */
3666 ha->loop_reset_delay = nv->reset_delay;
3668 /* Link Down Timeout = 0:
3670 * When Port Down timer expires we will start returning
3671 * I/O's to OS with "DID_NO_CONNECT".
3673 * Link Down Timeout != 0:
3675 * The driver waits for the link to come up after link down
3676 * before returning I/Os to OS with "DID_NO_CONNECT".
3678 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3679 ha->loop_down_abort_time =
3680 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3682 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3683 ha->loop_down_abort_time =
3684 (LOOP_DOWN_TIME - ha->link_down_timeout);
3687 /* Need enough time to try and get the port back. */
3688 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3689 if (qlport_down_retry)
3690 ha->port_down_retry_count = qlport_down_retry;
3692 /* Set login_retry_count */
3693 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3694 if (ha->port_down_retry_count ==
3695 le16_to_cpu(nv->port_down_retry_count) &&
3696 ha->port_down_retry_count > 3)
3697 ha->login_retry_count = ha->port_down_retry_count;
3698 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3699 ha->login_retry_count = ha->port_down_retry_count;
3700 if (ql2xloginretrycount)
3701 ha->login_retry_count = ql2xloginretrycount;
3704 if (!ha->flags.init_done) {
3705 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3706 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3707 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3708 le16_to_cpu(icb->interrupt_delay_timer): 2;
3710 icb->firmware_options_2 &= __constant_cpu_to_le32(
3711 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3712 ha->flags.process_response_queue = 0;
3713 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3714 ha->zio_mode = QLA_ZIO_MODE_6;
3716 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3717 "(%d us).\n", ha->host_no, ha->zio_mode,
3718 ha->zio_timer * 100));
3719 qla_printk(KERN_INFO, ha,
3720 "ZIO mode %d enabled; timer delay (%d us).\n",
3721 ha->zio_mode, ha->zio_timer * 100);
3723 icb->firmware_options_2 |= cpu_to_le32(
3724 (uint32_t)ha->zio_mode);
3725 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3726 ha->flags.process_response_queue = 1;
3730 DEBUG2_3(printk(KERN_WARNING
3731 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3737 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3740 int segments, fragment;
3742 uint32_t *dcode, dlen;
3749 segments = FA_RISC_CODE_SEGMENTS;
3750 faddr = FA_RISC_CODE_ADDR;
3751 dcode = (uint32_t *)ha->request_ring;
3754 /* Validate firmware image by checking version. */
3755 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3756 for (i = 0; i < 4; i++)
3757 dcode[i] = be32_to_cpu(dcode[i]);
3758 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3759 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3760 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3762 qla_printk(KERN_WARNING, ha,
3763 "Unable to verify integrity of flash firmware image!\n");
3764 qla_printk(KERN_WARNING, ha,
3765 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3766 dcode[1], dcode[2], dcode[3]);
3768 return QLA_FUNCTION_FAILED;
3771 while (segments && rval == QLA_SUCCESS) {
3772 /* Read segment's load information. */
3773 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3775 risc_addr = be32_to_cpu(dcode[2]);
3776 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3777 risc_size = be32_to_cpu(dcode[3]);
3780 while (risc_size > 0 && rval == QLA_SUCCESS) {
3781 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3782 if (dlen > risc_size)
3785 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3786 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3787 ha->host_no, risc_addr, dlen, faddr));
3789 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3790 for (i = 0; i < dlen; i++)
3791 dcode[i] = swab32(dcode[i]);
3793 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3796 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3797 "segment %d of firmware\n", ha->host_no,
3799 qla_printk(KERN_WARNING, ha,
3800 "[ERROR] Failed to load segment %d of "
3801 "firmware\n", fragment);
3818 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3821 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3825 uint16_t *wcode, *fwcode;
3826 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3827 struct fw_blob *blob;
3829 /* Load firmware blob. */
3830 blob = qla2x00_request_firmware(ha);
3832 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3833 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3834 "from: " QLA_FW_URL ".\n");
3835 return QLA_FUNCTION_FAILED;
3840 wcode = (uint16_t *)ha->request_ring;
3842 fwcode = (uint16_t *)blob->fw->data;
3845 /* Validate firmware image by checking version. */
3846 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3847 qla_printk(KERN_WARNING, ha,
3848 "Unable to verify integrity of firmware image (%Zd)!\n",
3850 goto fail_fw_integrity;
3852 for (i = 0; i < 4; i++)
3853 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3854 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3855 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3856 wcode[2] == 0 && wcode[3] == 0)) {
3857 qla_printk(KERN_WARNING, ha,
3858 "Unable to verify integrity of firmware image!\n");
3859 qla_printk(KERN_WARNING, ha,
3860 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3861 wcode[1], wcode[2], wcode[3]);
3862 goto fail_fw_integrity;
3866 while (*seg && rval == QLA_SUCCESS) {
3868 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3869 risc_size = be16_to_cpu(fwcode[3]);
3871 /* Validate firmware image size. */
3872 fwclen += risc_size * sizeof(uint16_t);
3873 if (blob->fw->size < fwclen) {
3874 qla_printk(KERN_WARNING, ha,
3875 "Unable to verify integrity of firmware image "
3876 "(%Zd)!\n", blob->fw->size);
3877 goto fail_fw_integrity;
3881 while (risc_size > 0 && rval == QLA_SUCCESS) {
3882 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3883 if (wlen > risc_size)
3886 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3887 "addr %x, number of words 0x%x.\n", ha->host_no,
3890 for (i = 0; i < wlen; i++)
3891 wcode[i] = swab16(fwcode[i]);
3893 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3896 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3897 "segment %d of firmware\n", ha->host_no,
3899 qla_printk(KERN_WARNING, ha,
3900 "[ERROR] Failed to load segment %d of "
3901 "firmware\n", fragment);
3917 return QLA_FUNCTION_FAILED;
3921 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3924 int segments, fragment;
3925 uint32_t *dcode, dlen;
3929 struct fw_blob *blob;
3930 uint32_t *fwcode, fwclen;
3932 /* Load firmware blob. */
3933 blob = qla2x00_request_firmware(ha);
3935 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3936 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3937 "from: " QLA_FW_URL ".\n");
3939 /* Try to load RISC code from flash. */
3940 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3941 "outdated) firmware from flash.\n");
3942 return qla24xx_load_risc_flash(ha, srisc_addr);
3947 segments = FA_RISC_CODE_SEGMENTS;
3948 dcode = (uint32_t *)ha->request_ring;
3950 fwcode = (uint32_t *)blob->fw->data;
3953 /* Validate firmware image by checking version. */
3954 if (blob->fw->size < 8 * sizeof(uint32_t)) {
3955 qla_printk(KERN_WARNING, ha,
3956 "Unable to verify integrity of firmware image (%Zd)!\n",
3958 goto fail_fw_integrity;
3960 for (i = 0; i < 4; i++)
3961 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3962 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3963 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3964 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3966 qla_printk(KERN_WARNING, ha,
3967 "Unable to verify integrity of firmware image!\n");
3968 qla_printk(KERN_WARNING, ha,
3969 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3970 dcode[1], dcode[2], dcode[3]);
3971 goto fail_fw_integrity;
3974 while (segments && rval == QLA_SUCCESS) {
3975 risc_addr = be32_to_cpu(fwcode[2]);
3976 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3977 risc_size = be32_to_cpu(fwcode[3]);
3979 /* Validate firmware image size. */
3980 fwclen += risc_size * sizeof(uint32_t);
3981 if (blob->fw->size < fwclen) {
3982 qla_printk(KERN_WARNING, ha,
3983 "Unable to verify integrity of firmware image "
3984 "(%Zd)!\n", blob->fw->size);
3986 goto fail_fw_integrity;
3990 while (risc_size > 0 && rval == QLA_SUCCESS) {
3991 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3992 if (dlen > risc_size)
3995 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3996 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3999 for (i = 0; i < dlen; i++)
4000 dcode[i] = swab32(fwcode[i]);
4002 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
4005 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4006 "segment %d of firmware\n", ha->host_no,
4008 qla_printk(KERN_WARNING, ha,
4009 "[ERROR] Failed to load segment %d of "
4010 "firmware\n", fragment);
4026 return QLA_FUNCTION_FAILED;
4030 qla2x00_try_to_stop_firmware(scsi_qla_host_t *ha)
4034 if (!IS_FWI2_CAPABLE(ha))
4036 if (!ha->fw_major_version)
4039 ret = qla2x00_stop_firmware(ha);
4040 for (retries = 5; ret != QLA_SUCCESS && retries ; retries--) {
4041 qla2x00_reset_chip(ha);
4042 if (qla2x00_chip_diag(ha) != QLA_SUCCESS)
4044 if (qla2x00_setup_chip(ha) != QLA_SUCCESS)
4046 qla_printk(KERN_INFO, ha,
4047 "Attempting retry of stop-firmware command...\n");
4048 ret = qla2x00_stop_firmware(ha);
4053 qla24xx_configure_vhba(scsi_qla_host_t *ha)
4055 int rval = QLA_SUCCESS;
4056 uint16_t mb[MAILBOX_REGISTER_COUNT];
4061 rval = qla2x00_fw_ready(ha);
4062 if (rval == QLA_SUCCESS) {
4063 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
4064 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
4067 ha->flags.management_server_logged_in = 0;
4069 /* Login to SNS first */
4070 qla24xx_login_fabric(ha, NPH_SNS, 0xff, 0xff, 0xfc,
4072 if (mb[0] != MBS_COMMAND_COMPLETE) {
4073 DEBUG15(qla_printk(KERN_INFO, ha,
4074 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4075 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4076 mb[0], mb[1], mb[2], mb[6], mb[7]));
4077 return (QLA_FUNCTION_FAILED);
4080 atomic_set(&ha->loop_down_timer, 0);
4081 atomic_set(&ha->loop_state, LOOP_UP);
4082 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4083 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
4084 rval = qla2x00_loop_resync(ha);