2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/delay.h>
10 #include <linux/vmalloc.h>
12 #include "qla_devtbl.h"
14 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
15 #ifndef EXT_IS_LUN_BIT_SET
16 #define EXT_IS_LUN_BIT_SET(P,L) \
17 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
18 #define EXT_SET_LUN_BIT(P,L) \
19 ((P)->mask[L/8] |= (0x80 >> (L%8)))
23 * QLogic ISP2x00 Hardware Support Function Prototypes.
25 static int qla2x00_isp_firmware(scsi_qla_host_t *);
26 static void qla2x00_resize_request_q(scsi_qla_host_t *);
27 static int qla2x00_setup_chip(scsi_qla_host_t *);
28 static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
29 static int qla2x00_init_rings(scsi_qla_host_t *);
30 static int qla2x00_fw_ready(scsi_qla_host_t *);
31 static int qla2x00_configure_hba(scsi_qla_host_t *);
32 static int qla2x00_configure_loop(scsi_qla_host_t *);
33 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
34 static int qla2x00_configure_fabric(scsi_qla_host_t *);
35 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
36 static int qla2x00_device_resync(scsi_qla_host_t *);
37 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
40 static int qla2x00_restart_isp(scsi_qla_host_t *);
42 /****************************************************************************/
43 /* QLogic ISP2x00 Hardware Support Functions. */
44 /****************************************************************************/
47 * qla2x00_initialize_adapter
51 * ha = adapter block pointer.
57 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
60 uint8_t restart_risc = 0;
64 /* Clear adapter flags. */
66 ha->flags.reset_active = 0;
67 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
68 atomic_set(&ha->loop_state, LOOP_DOWN);
71 ha->flags.management_server_logged_in = 0;
72 ha->marker_needed = 0;
74 ha->isp_abort_cnt = 0;
75 ha->beacon_blink_led = 0;
76 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
78 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
79 rval = ha->isp_ops.pci_config(ha);
81 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
86 ha->isp_ops.reset_chip(ha);
88 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
90 ha->isp_ops.nvram_config(ha);
92 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
96 * Try to configure the loop.
101 /* If firmware needs to be loaded */
102 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
103 if ((rval = ha->isp_ops.chip_diag(ha)) == QLA_SUCCESS) {
104 rval = qla2x00_setup_chip(ha);
108 if (rval == QLA_SUCCESS &&
109 (rval = qla2x00_init_rings(ha)) == QLA_SUCCESS) {
110 check_fw_ready_again:
112 * Wait for a successful LIP up to a maximum
113 * of (in seconds): RISC login timeout value,
114 * RISC retry count value, and port down retry
115 * value OR a minimum of 4 seconds OR If no
116 * cable, only 5 seconds.
118 rval = qla2x00_fw_ready(ha);
119 if (rval == QLA_SUCCESS) {
120 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
122 /* Issue a marker after FW becomes ready. */
123 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
126 * Wait at most MAX_TARGET RSCNs for a stable
131 clear_bit(LOOP_RESYNC_NEEDED,
133 rval = qla2x00_configure_loop(ha);
135 if (test_and_clear_bit(ISP_ABORT_NEEDED,
142 * If loop state change while we were
143 * discoverying devices then wait for
147 if (atomic_read(&ha->loop_state) !=
148 LOOP_READY && retry--) {
149 goto check_fw_ready_again;
152 } while (!atomic_read(&ha->loop_down_timer) &&
155 (test_bit(LOOP_RESYNC_NEEDED,
159 rval = QLA_FUNCTION_FAILED;
160 } else if (ha->device_flags & DFLG_NO_CABLE)
161 /* If no cable, then all is good. */
164 } while (restart_risc && retry--);
166 if (rval == QLA_SUCCESS) {
167 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
168 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
169 ha->marker_needed = 0;
171 ha->flags.online = 1;
173 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
180 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
183 * Returns 0 on success.
186 qla2100_pci_config(scsi_qla_host_t *ha)
191 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
193 pci_set_master(ha->pdev);
195 if (pci_set_mwi(ha->pdev))
196 mwi = PCI_COMMAND_INVALIDATE;
198 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
199 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
200 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
202 /* Reset expansion ROM address decode enable */
203 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
204 d &= ~PCI_ROM_ADDRESS_ENABLE;
205 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
207 /* Get PCI bus information. */
208 spin_lock_irqsave(&ha->hardware_lock, flags);
209 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
210 spin_unlock_irqrestore(&ha->hardware_lock, flags);
216 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
219 * Returns 0 on success.
222 qla2300_pci_config(scsi_qla_host_t *ha)
226 unsigned long flags = 0;
228 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
230 pci_set_master(ha->pdev);
232 if (pci_set_mwi(ha->pdev))
233 mwi = PCI_COMMAND_INVALIDATE;
235 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
236 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
238 if (IS_QLA2322(ha) || IS_QLA6322(ha))
239 w &= ~PCI_COMMAND_INTX_DISABLE;
242 * If this is a 2300 card and not 2312, reset the
243 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
244 * the 2310 also reports itself as a 2300 so we need to get the
245 * fb revision level -- a 6 indicates it really is a 2300 and
248 if (IS_QLA2300(ha)) {
249 spin_lock_irqsave(&ha->hardware_lock, flags);
252 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
253 for (cnt = 0; cnt < 30000; cnt++) {
254 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
260 /* Select FPM registers. */
261 WRT_REG_WORD(®->ctrl_status, 0x20);
262 RD_REG_WORD(®->ctrl_status);
264 /* Get the fb rev level */
265 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
267 if (ha->fb_rev == FPM_2300)
268 w &= ~PCI_COMMAND_INVALIDATE;
270 /* Deselect FPM registers. */
271 WRT_REG_WORD(®->ctrl_status, 0x0);
272 RD_REG_WORD(®->ctrl_status);
274 /* Release RISC module. */
275 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
276 for (cnt = 0; cnt < 30000; cnt++) {
277 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
283 spin_unlock_irqrestore(&ha->hardware_lock, flags);
285 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
287 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
289 /* Reset expansion ROM address decode enable */
290 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
291 d &= ~PCI_ROM_ADDRESS_ENABLE;
292 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
294 /* Get PCI bus information. */
295 spin_lock_irqsave(&ha->hardware_lock, flags);
296 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
297 spin_unlock_irqrestore(&ha->hardware_lock, flags);
303 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
306 * Returns 0 on success.
309 qla24xx_pci_config(scsi_qla_host_t *ha)
313 unsigned long flags = 0;
314 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
315 int pcix_cmd_reg, pcie_dctl_reg;
317 pci_set_master(ha->pdev);
319 if (pci_set_mwi(ha->pdev))
320 mwi = PCI_COMMAND_INVALIDATE;
322 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
323 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
324 w &= ~PCI_COMMAND_INTX_DISABLE;
325 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
327 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
329 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
330 pcix_cmd_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX);
334 pcix_cmd_reg += PCI_X_CMD;
335 pci_read_config_word(ha->pdev, pcix_cmd_reg, &pcix_cmd);
336 pcix_cmd &= ~PCI_X_CMD_MAX_READ;
338 pci_write_config_word(ha->pdev, pcix_cmd_reg, pcix_cmd);
341 /* PCIe -- adjust Maximum Read Request Size (2048). */
342 pcie_dctl_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
346 pcie_dctl_reg += PCI_EXP_DEVCTL;
347 pci_read_config_word(ha->pdev, pcie_dctl_reg, &pcie_dctl);
348 pcie_dctl &= ~PCI_EXP_DEVCTL_READRQ;
350 pci_write_config_word(ha->pdev, pcie_dctl_reg, pcie_dctl);
353 /* Reset expansion ROM address decode enable */
354 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
355 d &= ~PCI_ROM_ADDRESS_ENABLE;
356 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
358 /* Get PCI bus information. */
359 spin_lock_irqsave(&ha->hardware_lock, flags);
360 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
361 spin_unlock_irqrestore(&ha->hardware_lock, flags);
367 * qla2x00_isp_firmware() - Choose firmware image.
370 * Returns 0 on success.
373 qla2x00_isp_firmware(scsi_qla_host_t *ha)
377 /* Assume loading risc code */
378 rval = QLA_FUNCTION_FAILED;
380 if (ha->flags.disable_risc_code_load) {
381 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
383 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
385 /* Verify checksum of loaded RISC code. */
386 rval = qla2x00_verify_checksum(ha, ha->fw_srisc_address);
390 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
398 * qla2x00_reset_chip() - Reset ISP chip.
401 * Returns 0 on success.
404 qla2x00_reset_chip(scsi_qla_host_t *ha)
406 unsigned long flags = 0;
407 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
411 ha->isp_ops.disable_intrs(ha);
413 spin_lock_irqsave(&ha->hardware_lock, flags);
415 /* Turn off master enable */
417 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
418 cmd &= ~PCI_COMMAND_MASTER;
419 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
421 if (!IS_QLA2100(ha)) {
423 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
424 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
425 for (cnt = 0; cnt < 30000; cnt++) {
426 if ((RD_REG_WORD(®->hccr) &
427 HCCR_RISC_PAUSE) != 0)
432 RD_REG_WORD(®->hccr); /* PCI Posting. */
436 /* Select FPM registers. */
437 WRT_REG_WORD(®->ctrl_status, 0x20);
438 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
440 /* FPM Soft Reset. */
441 WRT_REG_WORD(®->fpm_diag_config, 0x100);
442 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
444 /* Toggle Fpm Reset. */
445 if (!IS_QLA2200(ha)) {
446 WRT_REG_WORD(®->fpm_diag_config, 0x0);
447 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
450 /* Select frame buffer registers. */
451 WRT_REG_WORD(®->ctrl_status, 0x10);
452 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
454 /* Reset frame buffer FIFOs. */
455 if (IS_QLA2200(ha)) {
456 WRT_FB_CMD_REG(ha, reg, 0xa000);
457 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
459 WRT_FB_CMD_REG(ha, reg, 0x00fc);
461 /* Read back fb_cmd until zero or 3 seconds max */
462 for (cnt = 0; cnt < 3000; cnt++) {
463 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
469 /* Select RISC module registers. */
470 WRT_REG_WORD(®->ctrl_status, 0);
471 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
473 /* Reset RISC processor. */
474 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
475 RD_REG_WORD(®->hccr); /* PCI Posting. */
477 /* Release RISC processor. */
478 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
479 RD_REG_WORD(®->hccr); /* PCI Posting. */
482 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
483 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
485 /* Reset ISP chip. */
486 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
488 /* Wait for RISC to recover from reset. */
489 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
491 * It is necessary to for a delay here since the card doesn't
492 * respond to PCI reads during a reset. On some architectures
493 * this will result in an MCA.
496 for (cnt = 30000; cnt; cnt--) {
497 if ((RD_REG_WORD(®->ctrl_status) &
498 CSR_ISP_SOFT_RESET) == 0)
505 /* Reset RISC processor. */
506 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
508 WRT_REG_WORD(®->semaphore, 0);
510 /* Release RISC processor. */
511 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
512 RD_REG_WORD(®->hccr); /* PCI Posting. */
514 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
515 for (cnt = 0; cnt < 30000; cnt++) {
516 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
524 /* Turn on master enable */
525 cmd |= PCI_COMMAND_MASTER;
526 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
528 /* Disable RISC pause on FPM parity error. */
529 if (!IS_QLA2100(ha)) {
530 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
531 RD_REG_WORD(®->hccr); /* PCI Posting. */
534 spin_unlock_irqrestore(&ha->hardware_lock, flags);
538 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
541 * Returns 0 on success.
544 qla24xx_reset_risc(scsi_qla_host_t *ha)
546 unsigned long flags = 0;
547 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
551 spin_lock_irqsave(&ha->hardware_lock, flags);
554 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
555 for (cnt = 0; cnt < 30000; cnt++) {
556 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
562 WRT_REG_DWORD(®->ctrl_status,
563 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
564 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
567 /* Wait for firmware to complete NVRAM accesses. */
568 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
569 for (cnt = 10000 ; cnt && d2; cnt--) {
571 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
575 /* Wait for soft-reset to complete. */
576 d2 = RD_REG_DWORD(®->ctrl_status);
577 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
579 d2 = RD_REG_DWORD(®->ctrl_status);
583 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
584 RD_REG_DWORD(®->hccr);
586 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
587 RD_REG_DWORD(®->hccr);
589 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
590 RD_REG_DWORD(®->hccr);
592 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
593 for (cnt = 6000000 ; cnt && d2; cnt--) {
595 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
599 spin_unlock_irqrestore(&ha->hardware_lock, flags);
603 * qla24xx_reset_chip() - Reset ISP24xx chip.
606 * Returns 0 on success.
609 qla24xx_reset_chip(scsi_qla_host_t *ha)
611 ha->isp_ops.disable_intrs(ha);
613 /* Perform RISC reset. */
614 qla24xx_reset_risc(ha);
618 * qla2x00_chip_diag() - Test chip for proper operation.
621 * Returns 0 on success.
624 qla2x00_chip_diag(scsi_qla_host_t *ha)
627 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
628 unsigned long flags = 0;
633 /* Assume a failed state */
634 rval = QLA_FUNCTION_FAILED;
636 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
637 ha->host_no, (u_long)®->flash_address));
639 spin_lock_irqsave(&ha->hardware_lock, flags);
641 /* Reset ISP chip. */
642 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
645 * We need to have a delay here since the card will not respond while
646 * in reset causing an MCA on some architectures.
649 data = qla2x00_debounce_register(®->ctrl_status);
650 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
652 data = RD_REG_WORD(®->ctrl_status);
657 goto chip_diag_failed;
659 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
662 /* Reset RISC processor. */
663 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
664 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
666 /* Workaround for QLA2312 PCI parity error */
667 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
668 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
669 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
671 data = RD_MAILBOX_REG(ha, reg, 0);
678 goto chip_diag_failed;
680 /* Check product ID of chip */
681 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
683 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
684 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
685 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
686 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
687 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
688 mb[3] != PROD_ID_3) {
689 qla_printk(KERN_WARNING, ha,
690 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
692 goto chip_diag_failed;
694 ha->product_id[0] = mb[1];
695 ha->product_id[1] = mb[2];
696 ha->product_id[2] = mb[3];
697 ha->product_id[3] = mb[4];
699 /* Adjust fw RISC transfer size */
700 if (ha->request_q_length > 1024)
701 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
703 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
704 ha->request_q_length;
706 if (IS_QLA2200(ha) &&
707 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
708 /* Limit firmware transfer size with a 2200A */
709 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
712 ha->device_type |= DT_ISP2200A;
713 ha->fw_transfer_size = 128;
716 /* Wrap Incoming Mailboxes Test. */
717 spin_unlock_irqrestore(&ha->hardware_lock, flags);
719 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
720 rval = qla2x00_mbx_reg_test(ha);
722 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
724 qla_printk(KERN_WARNING, ha,
725 "Failed mailbox send register test\n");
728 /* Flag a successful rval */
731 spin_lock_irqsave(&ha->hardware_lock, flags);
735 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
736 "****\n", ha->host_no));
738 spin_unlock_irqrestore(&ha->hardware_lock, flags);
744 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
747 * Returns 0 on success.
750 qla24xx_chip_diag(scsi_qla_host_t *ha)
754 /* Perform RISC reset. */
755 qla24xx_reset_risc(ha);
757 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
759 rval = qla2x00_mbx_reg_test(ha);
761 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
763 qla_printk(KERN_WARNING, ha,
764 "Failed mailbox send register test\n");
766 /* Flag a successful rval */
774 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
777 ha->fw_dump24_len = sizeof(struct qla24xx_fw_dump);
778 ha->fw_dump24_len += (ha->fw_memory_size - 0x100000) * sizeof(uint32_t);
779 ha->fw_dump24 = vmalloc(ha->fw_dump24_len);
781 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware "
782 "dump...\n", ha->fw_dump24_len / 1024);
784 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
785 "firmware dump!!!\n", ha->fw_dump24_len / 1024);
789 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
792 * Returns 0 on success.
795 qla2x00_resize_request_q(scsi_qla_host_t *ha)
798 uint16_t fw_iocb_cnt = 0;
799 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
800 dma_addr_t request_dma;
801 request_t *request_ring;
803 /* Valid only on recent ISPs. */
804 if (IS_QLA2100(ha) || IS_QLA2200(ha))
807 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
808 qla2x00_alloc_fw_dump(ha);
810 /* Retrieve IOCB counts available to the firmware. */
811 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
814 /* No point in continuing if current settings are sufficient. */
815 if (fw_iocb_cnt < 1024)
817 if (ha->request_q_length >= request_q_length)
820 /* Attempt to claim larger area for request queue. */
821 request_ring = dma_alloc_coherent(&ha->pdev->dev,
822 (request_q_length + 1) * sizeof(request_t), &request_dma,
824 if (request_ring == NULL)
827 /* Resize successful, report extensions. */
828 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
829 (ha->fw_memory_size + 1) / 1024);
830 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
831 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
833 /* Clear old allocations. */
834 dma_free_coherent(&ha->pdev->dev,
835 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
838 /* Begin using larger queue. */
839 ha->request_q_length = request_q_length;
840 ha->request_ring = request_ring;
841 ha->request_dma = request_dma;
845 * qla2x00_setup_chip() - Load and start RISC firmware.
848 * Returns 0 on success.
851 qla2x00_setup_chip(scsi_qla_host_t *ha)
854 uint32_t srisc_address = 0;
856 /* Load firmware sequences */
857 rval = ha->isp_ops.load_risc(ha, &srisc_address);
858 if (rval == QLA_SUCCESS) {
859 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
860 "code.\n", ha->host_no));
862 rval = qla2x00_verify_checksum(ha, srisc_address);
863 if (rval == QLA_SUCCESS) {
864 /* Start firmware execution. */
865 DEBUG(printk("scsi(%ld): Checksum OK, start "
866 "firmware.\n", ha->host_no));
868 rval = qla2x00_execute_fw(ha, srisc_address);
869 /* Retrieve firmware information. */
870 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
871 qla2x00_get_fw_version(ha,
872 &ha->fw_major_version,
873 &ha->fw_minor_version,
874 &ha->fw_subminor_version,
875 &ha->fw_attributes, &ha->fw_memory_size);
876 qla2x00_resize_request_q(ha);
879 DEBUG2(printk(KERN_INFO
880 "scsi(%ld): ISP Firmware failed checksum.\n",
886 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
894 * qla2x00_init_response_q_entries() - Initializes response queue entries.
897 * Beginning of request ring has initialization control block already built
898 * by nvram config routine.
900 * Returns 0 on success.
903 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
908 pkt = ha->response_ring_ptr;
909 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
910 pkt->signature = RESPONSE_PROCESSED;
917 * qla2x00_update_fw_options() - Read and process firmware options.
920 * Returns 0 on success.
923 qla2x00_update_fw_options(scsi_qla_host_t *ha)
925 uint16_t swing, emphasis, tx_sens, rx_sens;
927 memset(ha->fw_options, 0, sizeof(ha->fw_options));
928 qla2x00_get_fw_options(ha, ha->fw_options);
930 if (IS_QLA2100(ha) || IS_QLA2200(ha))
933 /* Serial Link options. */
934 DEBUG3(printk("scsi(%ld): Serial link options:\n",
936 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
937 sizeof(ha->fw_seriallink_options)));
939 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
940 if (ha->fw_seriallink_options[3] & BIT_2) {
941 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
944 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
945 emphasis = (ha->fw_seriallink_options[2] &
946 (BIT_4 | BIT_3)) >> 3;
947 tx_sens = ha->fw_seriallink_options[0] &
948 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
949 rx_sens = (ha->fw_seriallink_options[0] &
950 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
951 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
952 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
955 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
956 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
957 ha->fw_options[10] |= BIT_5 |
958 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
959 (tx_sens & (BIT_1 | BIT_0));
962 swing = (ha->fw_seriallink_options[2] &
963 (BIT_7 | BIT_6 | BIT_5)) >> 5;
964 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
965 tx_sens = ha->fw_seriallink_options[1] &
966 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
967 rx_sens = (ha->fw_seriallink_options[1] &
968 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
969 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
970 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
973 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
974 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
975 ha->fw_options[11] |= BIT_5 |
976 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
977 (tx_sens & (BIT_1 | BIT_0));
981 /* Return command IOCBs without waiting for an ABTS to complete. */
982 ha->fw_options[3] |= BIT_13;
985 if (ha->flags.enable_led_scheme)
986 ha->fw_options[2] |= BIT_12;
988 /* Detect ISP6312. */
990 ha->fw_options[2] |= BIT_13;
992 /* Update firmware options. */
993 qla2x00_set_fw_options(ha, ha->fw_options);
997 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1001 /* Update Serial Link options. */
1002 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1005 rval = qla2x00_set_serdes_params(ha,
1006 le16_to_cpu(ha->fw_seriallink_options24[1]),
1007 le16_to_cpu(ha->fw_seriallink_options24[2]),
1008 le16_to_cpu(ha->fw_seriallink_options24[3]));
1009 if (rval != QLA_SUCCESS) {
1010 qla_printk(KERN_WARNING, ha,
1011 "Unable to update Serial Link options (%x).\n", rval);
1016 qla2x00_config_rings(struct scsi_qla_host *ha)
1018 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1020 /* Setup ring parameters in initialization control block. */
1021 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1022 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1023 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1024 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1025 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1026 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1027 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1028 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1030 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1031 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1032 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1033 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1034 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1038 qla24xx_config_rings(struct scsi_qla_host *ha)
1040 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1041 struct init_cb_24xx *icb;
1043 /* Setup ring parameters in initialization control block. */
1044 icb = (struct init_cb_24xx *)ha->init_cb;
1045 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1046 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1047 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1048 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1049 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1050 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1051 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1052 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1054 WRT_REG_DWORD(®->req_q_in, 0);
1055 WRT_REG_DWORD(®->req_q_out, 0);
1056 WRT_REG_DWORD(®->rsp_q_in, 0);
1057 WRT_REG_DWORD(®->rsp_q_out, 0);
1058 RD_REG_DWORD(®->rsp_q_out);
1062 * qla2x00_init_rings() - Initializes firmware.
1065 * Beginning of request ring has initialization control block already built
1066 * by nvram config routine.
1068 * Returns 0 on success.
1071 qla2x00_init_rings(scsi_qla_host_t *ha)
1074 unsigned long flags = 0;
1077 spin_lock_irqsave(&ha->hardware_lock, flags);
1079 /* Clear outstanding commands array. */
1080 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1081 ha->outstanding_cmds[cnt] = NULL;
1083 ha->current_outstanding_cmd = 0;
1085 /* Clear RSCN queue. */
1086 ha->rscn_in_ptr = 0;
1087 ha->rscn_out_ptr = 0;
1089 /* Initialize firmware. */
1090 ha->request_ring_ptr = ha->request_ring;
1091 ha->req_ring_index = 0;
1092 ha->req_q_cnt = ha->request_q_length;
1093 ha->response_ring_ptr = ha->response_ring;
1094 ha->rsp_ring_index = 0;
1096 /* Initialize response queue entries */
1097 qla2x00_init_response_q_entries(ha);
1099 ha->isp_ops.config_rings(ha);
1101 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1103 /* Update any ISP specific firmware options before initialization. */
1104 ha->isp_ops.update_fw_options(ha);
1106 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1107 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1109 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1112 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1120 * qla2x00_fw_ready() - Waits for firmware ready.
1123 * Returns 0 on success.
1126 qla2x00_fw_ready(scsi_qla_host_t *ha)
1129 unsigned long wtime, mtime;
1130 uint16_t min_wait; /* Minimum wait time if loop is down */
1131 uint16_t wait_time; /* Wait time if loop is coming ready */
1136 /* 20 seconds for loop down. */
1140 * Firmware should take at most one RATOV to login, plus 5 seconds for
1141 * our own processing.
1143 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1144 wait_time = min_wait;
1147 /* Min wait time if loop down */
1148 mtime = jiffies + (min_wait * HZ);
1150 /* wait time before firmware ready */
1151 wtime = jiffies + (wait_time * HZ);
1153 /* Wait for ISP to finish LIP */
1154 if (!ha->flags.init_done)
1155 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1157 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1161 rval = qla2x00_get_firmware_state(ha, &fw_state);
1162 if (rval == QLA_SUCCESS) {
1163 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1164 ha->device_flags &= ~DFLG_NO_CABLE;
1166 if (fw_state == FSTATE_READY) {
1167 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1170 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1171 &ha->login_timeout, &ha->r_a_tov);
1177 rval = QLA_FUNCTION_FAILED;
1179 if (atomic_read(&ha->loop_down_timer) &&
1180 (fw_state >= FSTATE_LOSS_OF_SYNC ||
1181 fw_state == FSTATE_WAIT_AL_PA)) {
1182 /* Loop down. Timeout on min_wait for states
1183 * other than Wait for Login.
1185 if (time_after_eq(jiffies, mtime)) {
1186 qla_printk(KERN_INFO, ha,
1187 "Cable is unplugged...\n");
1189 ha->device_flags |= DFLG_NO_CABLE;
1194 /* Mailbox cmd failed. Timeout on min_wait. */
1195 if (time_after_eq(jiffies, mtime))
1199 if (time_after_eq(jiffies, wtime))
1202 /* Delay for a while */
1205 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1206 ha->host_no, fw_state, jiffies));
1209 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1210 ha->host_no, fw_state, jiffies));
1213 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1221 * qla2x00_configure_hba
1222 * Setup adapter context.
1225 * ha = adapter state pointer.
1234 qla2x00_configure_hba(scsi_qla_host_t *ha)
1242 char connect_type[22];
1244 /* Get host addresses. */
1245 rval = qla2x00_get_adapter_id(ha,
1246 &loop_id, &al_pa, &area, &domain, &topo);
1247 if (rval != QLA_SUCCESS) {
1248 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
1249 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1250 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1251 __func__, ha->host_no));
1253 qla_printk(KERN_WARNING, ha,
1254 "ERROR -- Unable to get host loop ID.\n");
1255 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1261 qla_printk(KERN_INFO, ha,
1262 "Cannot get topology - retrying.\n");
1263 return (QLA_FUNCTION_FAILED);
1266 ha->loop_id = loop_id;
1269 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1270 ha->operating_mode = LOOP;
1274 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1276 ha->current_topology = ISP_CFG_NL;
1277 strcpy(connect_type, "(Loop)");
1281 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1283 ha->current_topology = ISP_CFG_FL;
1284 strcpy(connect_type, "(FL_Port)");
1288 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1290 ha->operating_mode = P2P;
1291 ha->current_topology = ISP_CFG_N;
1292 strcpy(connect_type, "(N_Port-to-N_Port)");
1296 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1298 ha->operating_mode = P2P;
1299 ha->current_topology = ISP_CFG_F;
1300 strcpy(connect_type, "(F_Port)");
1304 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1306 ha->host_no, topo));
1307 ha->current_topology = ISP_CFG_NL;
1308 strcpy(connect_type, "(Loop)");
1312 /* Save Host port and loop ID. */
1313 /* byte order - Big Endian */
1314 ha->d_id.b.domain = domain;
1315 ha->d_id.b.area = area;
1316 ha->d_id.b.al_pa = al_pa;
1318 if (!ha->flags.init_done)
1319 qla_printk(KERN_INFO, ha,
1320 "Topology - %s, Host Loop address 0x%x\n",
1321 connect_type, ha->loop_id);
1324 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1326 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1333 * NVRAM configuration for ISP 2xxx
1336 * ha = adapter block pointer.
1339 * initialization control block in response_ring
1340 * host adapters parameters in host adapter block
1346 qla2x00_nvram_config(scsi_qla_host_t *ha)
1351 uint8_t *dptr1, *dptr2;
1352 init_cb_t *icb = ha->init_cb;
1353 nvram_t *nv = (nvram_t *)ha->request_ring;
1354 uint8_t *ptr = (uint8_t *)ha->request_ring;
1355 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1359 /* Determine NVRAM starting address. */
1360 ha->nvram_size = sizeof(nvram_t);
1362 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1363 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1364 ha->nvram_base = 0x80;
1366 /* Get NVRAM data and calculate checksum. */
1367 ha->isp_ops.read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1368 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1371 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1372 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1375 /* Bad NVRAM data, set defaults parameters. */
1376 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1377 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1378 /* Reset NVRAM data. */
1379 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1380 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1382 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1383 "invalid -- WWPN) defaults.\n");
1386 * Set default initialization control block.
1388 memset(nv, 0, ha->nvram_size);
1389 nv->parameter_block_version = ICB_VERSION;
1391 if (IS_QLA23XX(ha)) {
1392 nv->firmware_options[0] = BIT_2 | BIT_1;
1393 nv->firmware_options[1] = BIT_7 | BIT_5;
1394 nv->add_firmware_options[0] = BIT_5;
1395 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1396 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1397 nv->special_options[1] = BIT_7;
1398 } else if (IS_QLA2200(ha)) {
1399 nv->firmware_options[0] = BIT_2 | BIT_1;
1400 nv->firmware_options[1] = BIT_7 | BIT_5;
1401 nv->add_firmware_options[0] = BIT_5;
1402 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1403 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1404 } else if (IS_QLA2100(ha)) {
1405 nv->firmware_options[0] = BIT_3 | BIT_1;
1406 nv->firmware_options[1] = BIT_5;
1407 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1410 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1411 nv->execution_throttle = __constant_cpu_to_le16(16);
1412 nv->retry_count = 8;
1413 nv->retry_delay = 1;
1415 nv->port_name[0] = 33;
1416 nv->port_name[3] = 224;
1417 nv->port_name[4] = 139;
1419 nv->login_timeout = 4;
1422 * Set default host adapter parameters
1424 nv->host_p[1] = BIT_2;
1425 nv->reset_delay = 5;
1426 nv->port_down_retry_count = 8;
1427 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1428 nv->link_down_timeout = 60;
1433 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1435 * The SN2 does not provide BIOS emulation which means you can't change
1436 * potentially bogus BIOS settings. Force the use of default settings
1437 * for link rate and frame size. Hope that the rest of the settings
1440 if (ia64_platform_is("sn2")) {
1441 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1443 nv->special_options[1] = BIT_7;
1447 /* Reset Initialization control block */
1448 memset(icb, 0, ha->init_cb_size);
1451 * Setup driver NVRAM options.
1453 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1454 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1455 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1456 nv->firmware_options[1] &= ~BIT_4;
1458 if (IS_QLA23XX(ha)) {
1459 nv->firmware_options[0] |= BIT_2;
1460 nv->firmware_options[0] &= ~BIT_3;
1461 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1463 if (IS_QLA2300(ha)) {
1464 if (ha->fb_rev == FPM_2310) {
1465 strcpy(ha->model_number, "QLA2310");
1467 strcpy(ha->model_number, "QLA2300");
1471 memcmp(nv->model_number, BINZERO,
1472 sizeof(nv->model_number)) != 0) {
1475 strncpy(ha->model_number, nv->model_number,
1476 sizeof(nv->model_number));
1477 st = en = ha->model_number;
1478 en += sizeof(nv->model_number) - 1;
1480 if (*en != 0x20 && *en != 0x00)
1487 index = (ha->pdev->subsystem_device & 0xff);
1488 if (index < QLA_MODEL_NAMES) {
1489 strcpy(ha->model_number,
1490 qla2x00_model_name[index * 2]);
1492 qla2x00_model_name[index * 2 + 1];
1494 strcpy(ha->model_number, "QLA23xx");
1498 } else if (IS_QLA2200(ha)) {
1499 nv->firmware_options[0] |= BIT_2;
1501 * 'Point-to-point preferred, else loop' is not a safe
1502 * connection mode setting.
1504 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1506 /* Force 'loop preferred, else point-to-point'. */
1507 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1508 nv->add_firmware_options[0] |= BIT_5;
1510 strcpy(ha->model_number, "QLA22xx");
1511 } else /*if (IS_QLA2100(ha))*/ {
1512 strcpy(ha->model_number, "QLA2100");
1516 * Copy over NVRAM RISC parameter block to initialization control block.
1518 dptr1 = (uint8_t *)icb;
1519 dptr2 = (uint8_t *)&nv->parameter_block_version;
1520 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1522 *dptr1++ = *dptr2++;
1524 /* Copy 2nd half. */
1525 dptr1 = (uint8_t *)icb->add_firmware_options;
1526 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1528 *dptr1++ = *dptr2++;
1530 /* Use alternate WWN? */
1531 if (nv->host_p[1] & BIT_7) {
1532 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1533 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1536 /* Prepare nodename */
1537 if ((icb->firmware_options[1] & BIT_6) == 0) {
1539 * Firmware will apply the following mask if the nodename was
1542 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1543 icb->node_name[0] &= 0xF0;
1547 * Set host adapter parameters.
1549 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1550 /* Always load RISC code on non ISP2[12]00 chips. */
1551 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1552 ha->flags.disable_risc_code_load = 0;
1553 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1554 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1555 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1556 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1558 ha->operating_mode =
1559 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1561 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1562 sizeof(ha->fw_seriallink_options));
1564 /* save HBA serial number */
1565 ha->serial0 = icb->port_name[5];
1566 ha->serial1 = icb->port_name[6];
1567 ha->serial2 = icb->port_name[7];
1568 ha->node_name = icb->node_name;
1569 ha->port_name = icb->port_name;
1571 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1573 ha->retry_count = nv->retry_count;
1575 /* Set minimum login_timeout to 4 seconds. */
1576 if (nv->login_timeout < ql2xlogintimeout)
1577 nv->login_timeout = ql2xlogintimeout;
1578 if (nv->login_timeout < 4)
1579 nv->login_timeout = 4;
1580 ha->login_timeout = nv->login_timeout;
1581 icb->login_timeout = nv->login_timeout;
1583 /* Set minimum RATOV to 200 tenths of a second. */
1586 ha->loop_reset_delay = nv->reset_delay;
1588 /* Link Down Timeout = 0:
1590 * When Port Down timer expires we will start returning
1591 * I/O's to OS with "DID_NO_CONNECT".
1593 * Link Down Timeout != 0:
1595 * The driver waits for the link to come up after link down
1596 * before returning I/Os to OS with "DID_NO_CONNECT".
1598 if (nv->link_down_timeout == 0) {
1599 ha->loop_down_abort_time =
1600 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1602 ha->link_down_timeout = nv->link_down_timeout;
1603 ha->loop_down_abort_time =
1604 (LOOP_DOWN_TIME - ha->link_down_timeout);
1608 * Need enough time to try and get the port back.
1610 ha->port_down_retry_count = nv->port_down_retry_count;
1611 if (qlport_down_retry)
1612 ha->port_down_retry_count = qlport_down_retry;
1613 /* Set login_retry_count */
1614 ha->login_retry_count = nv->retry_count;
1615 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1616 ha->port_down_retry_count > 3)
1617 ha->login_retry_count = ha->port_down_retry_count;
1618 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1619 ha->login_retry_count = ha->port_down_retry_count;
1620 if (ql2xloginretrycount)
1621 ha->login_retry_count = ql2xloginretrycount;
1623 icb->lun_enables = __constant_cpu_to_le16(0);
1624 icb->command_resource_count = 0;
1625 icb->immediate_notify_resource_count = 0;
1626 icb->timeout = __constant_cpu_to_le16(0);
1628 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1630 icb->firmware_options[0] &= ~BIT_3;
1631 icb->add_firmware_options[0] &=
1632 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1633 icb->add_firmware_options[0] |= BIT_2;
1634 icb->response_accumulation_timer = 3;
1635 icb->interrupt_delay_timer = 5;
1637 ha->flags.process_response_queue = 1;
1640 if (!ha->flags.init_done) {
1641 ha->zio_mode = icb->add_firmware_options[0] &
1642 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1643 ha->zio_timer = icb->interrupt_delay_timer ?
1644 icb->interrupt_delay_timer: 2;
1646 icb->add_firmware_options[0] &=
1647 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1648 ha->flags.process_response_queue = 0;
1649 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1650 ha->zio_mode = QLA_ZIO_MODE_6;
1652 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1653 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1654 ha->zio_timer * 100));
1655 qla_printk(KERN_INFO, ha,
1656 "ZIO mode %d enabled; timer delay (%d us).\n",
1657 ha->zio_mode, ha->zio_timer * 100);
1659 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1660 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1661 ha->flags.process_response_queue = 1;
1666 DEBUG2_3(printk(KERN_WARNING
1667 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1673 qla2x00_rport_del(void *data)
1675 fc_port_t *fcport = data;
1676 struct fc_rport *rport;
1677 unsigned long flags;
1679 spin_lock_irqsave(&fcport->rport_lock, flags);
1680 rport = fcport->drport;
1681 fcport->drport = NULL;
1682 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1684 fc_remote_port_delete(rport);
1689 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1691 * @flags: allocation flags
1693 * Returns a pointer to the allocated fcport, or NULL, if none available.
1696 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1700 fcport = kmalloc(sizeof(fc_port_t), flags);
1704 /* Setup fcport template structure. */
1705 memset(fcport, 0, sizeof (fc_port_t));
1707 fcport->port_type = FCT_UNKNOWN;
1708 fcport->loop_id = FC_NO_LOOP_ID;
1709 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1710 fcport->flags = FCF_RLC_SUPPORT;
1711 fcport->supported_classes = FC_COS_UNSPECIFIED;
1712 spin_lock_init(&fcport->rport_lock);
1718 * qla2x00_configure_loop
1719 * Updates Fibre Channel Device Database with what is actually on loop.
1722 * ha = adapter block pointer.
1727 * 2 = database was full and device was not configured.
1730 qla2x00_configure_loop(scsi_qla_host_t *ha)
1733 unsigned long flags, save_flags;
1737 /* Get Initiator ID */
1738 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1739 rval = qla2x00_configure_hba(ha);
1740 if (rval != QLA_SUCCESS) {
1741 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1747 save_flags = flags = ha->dpc_flags;
1748 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1749 ha->host_no, flags));
1752 * If we have both an RSCN and PORT UPDATE pending then handle them
1753 * both at the same time.
1755 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1756 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1758 /* Determine what we need to do */
1759 if (ha->current_topology == ISP_CFG_FL &&
1760 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1762 ha->flags.rscn_queue_overflow = 1;
1763 set_bit(RSCN_UPDATE, &flags);
1765 } else if (ha->current_topology == ISP_CFG_F &&
1766 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1768 ha->flags.rscn_queue_overflow = 1;
1769 set_bit(RSCN_UPDATE, &flags);
1770 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1772 } else if (!ha->flags.online ||
1773 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1775 ha->flags.rscn_queue_overflow = 1;
1776 set_bit(RSCN_UPDATE, &flags);
1777 set_bit(LOCAL_LOOP_UPDATE, &flags);
1780 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1781 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1782 rval = QLA_FUNCTION_FAILED;
1784 rval = qla2x00_configure_local_loop(ha);
1788 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1789 if (LOOP_TRANSITION(ha)) {
1790 rval = QLA_FUNCTION_FAILED;
1792 rval = qla2x00_configure_fabric(ha);
1796 if (rval == QLA_SUCCESS) {
1797 if (atomic_read(&ha->loop_down_timer) ||
1798 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1799 rval = QLA_FUNCTION_FAILED;
1801 atomic_set(&ha->loop_state, LOOP_READY);
1803 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1808 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1809 __func__, ha->host_no));
1811 DEBUG3(printk("%s: exiting normally\n", __func__));
1814 /* Restore state if a resync event occured during processing */
1815 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1816 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1817 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1818 if (test_bit(RSCN_UPDATE, &save_flags))
1819 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1828 * qla2x00_configure_local_loop
1829 * Updates Fibre Channel Device Database with local loop devices.
1832 * ha = adapter block pointer.
1838 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1843 fc_port_t *fcport, *new_fcport;
1849 uint8_t domain, area, al_pa;
1853 entries = MAX_FIBRE_DEVICES;
1855 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1856 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1858 /* Get list of logged in devices. */
1859 memset(ha->gid_list, 0, GID_LIST_SIZE);
1860 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1862 if (rval != QLA_SUCCESS)
1863 goto cleanup_allocation;
1865 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1866 ha->host_no, entries));
1867 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1868 entries * sizeof(struct gid_list_info)));
1870 /* Allocate temporary fcport for any new fcports discovered. */
1871 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1872 if (new_fcport == NULL) {
1873 rval = QLA_MEMORY_ALLOC_FAILED;
1874 goto cleanup_allocation;
1876 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1879 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1881 list_for_each_entry(fcport, &ha->fcports, list) {
1882 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1883 fcport->port_type != FCT_BROADCAST &&
1884 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1886 DEBUG(printk("scsi(%ld): Marking port lost, "
1888 ha->host_no, fcport->loop_id));
1890 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1891 fcport->flags &= ~FCF_FARP_DONE;
1895 /* Add devices to port list. */
1896 id_iter = (char *)ha->gid_list;
1897 for (index = 0; index < entries; index++) {
1898 domain = ((struct gid_list_info *)id_iter)->domain;
1899 area = ((struct gid_list_info *)id_iter)->area;
1900 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1901 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1902 loop_id = (uint16_t)
1903 ((struct gid_list_info *)id_iter)->loop_id_2100;
1905 loop_id = le16_to_cpu(
1906 ((struct gid_list_info *)id_iter)->loop_id);
1907 id_iter += ha->gid_list_info_size;
1909 /* Bypass reserved domain fields. */
1910 if ((domain & 0xf0) == 0xf0)
1913 /* Bypass if not same domain and area of adapter. */
1914 if (area && domain &&
1915 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
1918 /* Bypass invalid local loop ID. */
1919 if (loop_id > LAST_LOCAL_LOOP_ID)
1922 /* Fill in member data. */
1923 new_fcport->d_id.b.domain = domain;
1924 new_fcport->d_id.b.area = area;
1925 new_fcport->d_id.b.al_pa = al_pa;
1926 new_fcport->loop_id = loop_id;
1927 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1928 if (rval2 != QLA_SUCCESS) {
1929 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1930 "information -- get_port_database=%x, "
1932 ha->host_no, rval2, new_fcport->loop_id));
1933 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
1935 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
1939 /* Check for matching device in port list. */
1942 list_for_each_entry(fcport, &ha->fcports, list) {
1943 if (memcmp(new_fcport->port_name, fcport->port_name,
1947 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1948 FCF_PERSISTENT_BOUND);
1949 fcport->loop_id = new_fcport->loop_id;
1950 fcport->port_type = new_fcport->port_type;
1951 fcport->d_id.b24 = new_fcport->d_id.b24;
1952 memcpy(fcport->node_name, new_fcport->node_name,
1960 /* New device, add to fcports list. */
1961 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1962 list_add_tail(&new_fcport->list, &ha->fcports);
1964 /* Allocate a new replacement fcport. */
1965 fcport = new_fcport;
1966 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1967 if (new_fcport == NULL) {
1968 rval = QLA_MEMORY_ALLOC_FAILED;
1969 goto cleanup_allocation;
1971 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1974 qla2x00_update_fcport(ha, fcport);
1982 if (rval != QLA_SUCCESS) {
1983 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1984 "rval=%x\n", ha->host_no, rval));
1988 ha->device_flags |= DFLG_LOCAL_DEVICES;
1989 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
1996 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
2000 qla2x00_mark_all_devices_lost(ha, 0);
2001 list_for_each_entry(fcport, &ha->fcports, list) {
2002 if (fcport->port_type != FCT_TARGET)
2005 qla2x00_update_fcport(ha, fcport);
2010 * qla2x00_update_fcport
2011 * Updates device on list.
2014 * ha = adapter block pointer.
2015 * fcport = port structure pointer.
2025 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2028 fcport->login_retry = 0;
2029 fcport->port_login_retry_count = ha->port_down_retry_count *
2031 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2033 fcport->flags &= ~FCF_LOGIN_NEEDED;
2035 atomic_set(&fcport->state, FCS_ONLINE);
2037 if (ha->flags.init_done)
2038 qla2x00_reg_remote_port(ha, fcport);
2042 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2044 struct fc_rport_identifiers rport_ids;
2045 struct fc_rport *rport;
2046 unsigned long flags;
2049 qla2x00_rport_del(fcport);
2053 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2054 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2055 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2056 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2057 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2058 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2060 qla_printk(KERN_WARNING, ha,
2061 "Unable to allocate fc remote port!\n");
2064 spin_lock_irqsave(&fcport->rport_lock, flags);
2065 fcport->rport = rport;
2066 *((fc_port_t **)rport->dd_data) = fcport;
2067 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2069 rport->supported_classes = fcport->supported_classes;
2071 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2072 if (fcport->port_type == FCT_INITIATOR)
2073 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2074 if (fcport->port_type == FCT_TARGET)
2075 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2076 fc_remote_port_rolechg(rport, rport_ids.roles);
2078 if (rport->scsi_target_id != -1 &&
2079 rport->scsi_target_id < ha->host->max_id)
2080 fcport->os_target_id = rport->scsi_target_id;
2084 * qla2x00_configure_fabric
2085 * Setup SNS devices with loop ID's.
2088 * ha = adapter block pointer.
2095 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2098 fc_port_t *fcport, *fcptemp;
2099 uint16_t next_loopid;
2100 uint16_t mb[MAILBOX_REGISTER_COUNT];
2102 LIST_HEAD(new_fcports);
2104 /* If FL port exists, then SNS is present */
2105 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2106 loop_id = NPH_F_PORT;
2108 loop_id = SNS_FL_PORT;
2109 rval = qla2x00_get_port_name(ha, loop_id, NULL, 0);
2110 if (rval != QLA_SUCCESS) {
2111 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2112 "Port\n", ha->host_no));
2114 ha->device_flags &= ~SWITCH_FOUND;
2115 return (QLA_SUCCESS);
2118 /* Mark devices that need re-synchronization. */
2119 rval2 = qla2x00_device_resync(ha);
2120 if (rval2 == QLA_RSCNS_HANDLED) {
2121 /* No point doing the scan, just continue. */
2122 return (QLA_SUCCESS);
2126 if (ql2xfdmienable &&
2127 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2128 qla2x00_fdmi_register(ha);
2130 /* Ensure we are logged into the SNS. */
2131 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2134 loop_id = SIMPLE_NAME_SERVER;
2135 ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
2136 0xfc, mb, BIT_1 | BIT_0);
2137 if (mb[0] != MBS_COMMAND_COMPLETE) {
2138 DEBUG2(qla_printk(KERN_INFO, ha,
2139 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2140 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2141 mb[0], mb[1], mb[2], mb[6], mb[7]));
2142 return (QLA_SUCCESS);
2145 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2146 if (qla2x00_rft_id(ha)) {
2148 DEBUG2(printk("scsi(%ld): Register FC-4 "
2149 "TYPE failed.\n", ha->host_no));
2151 if (qla2x00_rff_id(ha)) {
2153 DEBUG2(printk("scsi(%ld): Register FC-4 "
2154 "Features failed.\n", ha->host_no));
2156 if (qla2x00_rnn_id(ha)) {
2158 DEBUG2(printk("scsi(%ld): Register Node Name "
2159 "failed.\n", ha->host_no));
2160 } else if (qla2x00_rsnn_nn(ha)) {
2162 DEBUG2(printk("scsi(%ld): Register Symbolic "
2163 "Node Name failed.\n", ha->host_no));
2167 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2168 if (rval != QLA_SUCCESS)
2172 * Logout all previous fabric devices marked lost, except
2175 list_for_each_entry(fcport, &ha->fcports, list) {
2176 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2179 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2182 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2183 qla2x00_mark_device_lost(ha, fcport,
2184 ql2xplogiabsentdevice, 0);
2185 if (fcport->loop_id != FC_NO_LOOP_ID &&
2186 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2187 fcport->port_type != FCT_INITIATOR &&
2188 fcport->port_type != FCT_BROADCAST) {
2189 ha->isp_ops.fabric_logout(ha,
2191 fcport->d_id.b.domain,
2192 fcport->d_id.b.area,
2193 fcport->d_id.b.al_pa);
2194 fcport->loop_id = FC_NO_LOOP_ID;
2199 /* Starting free loop ID. */
2200 next_loopid = ha->min_external_loopid;
2203 * Scan through our port list and login entries that need to be
2206 list_for_each_entry(fcport, &ha->fcports, list) {
2207 if (atomic_read(&ha->loop_down_timer) ||
2208 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2211 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2212 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2215 if (fcport->loop_id == FC_NO_LOOP_ID) {
2216 fcport->loop_id = next_loopid;
2217 rval = qla2x00_find_new_loop_id(ha, fcport);
2218 if (rval != QLA_SUCCESS) {
2219 /* Ran out of IDs to use */
2223 /* Login and update database */
2224 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2227 /* Exit if out of loop IDs. */
2228 if (rval != QLA_SUCCESS) {
2233 * Login and add the new devices to our port list.
2235 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2236 if (atomic_read(&ha->loop_down_timer) ||
2237 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2240 /* Find a new loop ID to use. */
2241 fcport->loop_id = next_loopid;
2242 rval = qla2x00_find_new_loop_id(ha, fcport);
2243 if (rval != QLA_SUCCESS) {
2244 /* Ran out of IDs to use */
2248 /* Remove device from the new list and add it to DB */
2249 list_del(&fcport->list);
2250 list_add_tail(&fcport->list, &ha->fcports);
2252 /* Login and update database */
2253 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2257 /* Free all new device structures not processed. */
2258 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2259 list_del(&fcport->list);
2264 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2265 "rval=%d\n", ha->host_no, rval));
2273 * qla2x00_find_all_fabric_devs
2276 * ha = adapter block pointer.
2277 * dev = database device entry pointer.
2286 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2290 fc_port_t *fcport, *new_fcport, *fcptemp;
2295 int first_dev, last_dev;
2296 port_id_t wrap, nxt_d_id;
2300 /* Try GID_PT to get device list, else GAN. */
2301 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2304 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2305 "on GA_NXT\n", ha->host_no));
2307 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2308 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2311 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2314 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2321 /* Allocate temporary fcport for any new fcports discovered. */
2322 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2323 if (new_fcport == NULL) {
2325 return (QLA_MEMORY_ALLOC_FAILED);
2327 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2329 /* Set start port ID scan at adapter ID. */
2333 /* Starting free loop ID. */
2334 loop_id = ha->min_external_loopid;
2335 for (; loop_id <= ha->last_loop_id; loop_id++) {
2336 if (qla2x00_is_reserved_id(ha, loop_id))
2339 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2344 wrap.b24 = new_fcport->d_id.b24;
2346 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2347 memcpy(new_fcport->node_name,
2348 swl[swl_idx].node_name, WWN_SIZE);
2349 memcpy(new_fcport->port_name,
2350 swl[swl_idx].port_name, WWN_SIZE);
2352 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2358 /* Send GA_NXT to the switch */
2359 rval = qla2x00_ga_nxt(ha, new_fcport);
2360 if (rval != QLA_SUCCESS) {
2361 qla_printk(KERN_WARNING, ha,
2362 "SNS scan failed -- assuming zero-entry "
2364 list_for_each_entry_safe(fcport, fcptemp,
2365 new_fcports, list) {
2366 list_del(&fcport->list);
2374 /* If wrap on switch device list, exit. */
2376 wrap.b24 = new_fcport->d_id.b24;
2378 } else if (new_fcport->d_id.b24 == wrap.b24) {
2379 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2380 ha->host_no, new_fcport->d_id.b.domain,
2381 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2385 /* Bypass if host adapter. */
2386 if (new_fcport->d_id.b24 == ha->d_id.b24)
2389 /* Bypass if same domain and area of adapter. */
2390 if (((new_fcport->d_id.b24 & 0xffff00) ==
2391 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2395 /* Bypass reserved domain fields. */
2396 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2399 /* Locate matching device in database. */
2401 list_for_each_entry(fcport, &ha->fcports, list) {
2402 if (memcmp(new_fcport->port_name, fcport->port_name,
2409 * If address the same and state FCS_ONLINE, nothing
2412 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2413 atomic_read(&fcport->state) == FCS_ONLINE) {
2418 * If device was not a fabric device before.
2420 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2421 fcport->d_id.b24 = new_fcport->d_id.b24;
2422 fcport->loop_id = FC_NO_LOOP_ID;
2423 fcport->flags |= (FCF_FABRIC_DEVICE |
2425 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2430 * Port ID changed or device was marked to be updated;
2431 * Log it out if still logged in and mark it for
2434 fcport->d_id.b24 = new_fcport->d_id.b24;
2435 fcport->flags |= FCF_LOGIN_NEEDED;
2436 if (fcport->loop_id != FC_NO_LOOP_ID &&
2437 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2438 fcport->port_type != FCT_INITIATOR &&
2439 fcport->port_type != FCT_BROADCAST) {
2440 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2441 fcport->d_id.b.domain, fcport->d_id.b.area,
2442 fcport->d_id.b.al_pa);
2443 fcport->loop_id = FC_NO_LOOP_ID;
2452 /* If device was not in our fcports list, then add it. */
2453 list_add_tail(&new_fcport->list, new_fcports);
2455 /* Allocate a new replacement fcport. */
2456 nxt_d_id.b24 = new_fcport->d_id.b24;
2457 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2458 if (new_fcport == NULL) {
2460 return (QLA_MEMORY_ALLOC_FAILED);
2462 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2463 new_fcport->d_id.b24 = nxt_d_id.b24;
2469 if (!list_empty(new_fcports))
2470 ha->device_flags |= DFLG_FABRIC_DEVICES;
2476 * qla2x00_find_new_loop_id
2477 * Scan through our port list and find a new usable loop ID.
2480 * ha: adapter state pointer.
2481 * dev: port structure pointer.
2484 * qla2x00 local function return status code.
2490 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2495 uint16_t first_loop_id;
2499 /* Save starting loop ID. */
2500 first_loop_id = dev->loop_id;
2503 /* Skip loop ID if already used by adapter. */
2504 if (dev->loop_id == ha->loop_id) {
2508 /* Skip reserved loop IDs. */
2509 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2513 /* Reset loop ID if passed the end. */
2514 if (dev->loop_id > ha->last_loop_id) {
2515 /* first loop ID. */
2516 dev->loop_id = ha->min_external_loopid;
2519 /* Check for loop ID being already in use. */
2522 list_for_each_entry(fcport, &ha->fcports, list) {
2523 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2524 /* ID possibly in use */
2530 /* If not in use then it is free to use. */
2535 /* ID in use. Try next value. */
2538 /* If wrap around. No free ID to use. */
2539 if (dev->loop_id == first_loop_id) {
2540 dev->loop_id = FC_NO_LOOP_ID;
2541 rval = QLA_FUNCTION_FAILED;
2550 * qla2x00_device_resync
2551 * Marks devices in the database that needs resynchronization.
2554 * ha = adapter block pointer.
2560 qla2x00_device_resync(scsi_qla_host_t *ha)
2565 uint32_t rscn_entry;
2566 uint8_t rscn_out_iter;
2570 rval = QLA_RSCNS_HANDLED;
2572 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2573 ha->flags.rscn_queue_overflow) {
2575 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2576 format = MSB(MSW(rscn_entry));
2577 d_id.b.domain = LSB(MSW(rscn_entry));
2578 d_id.b.area = MSB(LSW(rscn_entry));
2579 d_id.b.al_pa = LSB(LSW(rscn_entry));
2581 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2582 "[%02x/%02x%02x%02x].\n",
2583 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2584 d_id.b.area, d_id.b.al_pa));
2587 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2588 ha->rscn_out_ptr = 0;
2590 /* Skip duplicate entries. */
2591 for (rscn_out_iter = ha->rscn_out_ptr;
2592 !ha->flags.rscn_queue_overflow &&
2593 rscn_out_iter != ha->rscn_in_ptr;
2594 rscn_out_iter = (rscn_out_iter ==
2595 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2597 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2600 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2601 "entry found at [%d].\n", ha->host_no,
2604 ha->rscn_out_ptr = rscn_out_iter;
2607 /* Queue overflow, set switch default case. */
2608 if (ha->flags.rscn_queue_overflow) {
2609 DEBUG(printk("scsi(%ld): device_resync: rscn "
2610 "overflow.\n", ha->host_no));
2613 ha->flags.rscn_queue_overflow = 0;
2629 ha->rscn_out_ptr = ha->rscn_in_ptr;
2635 list_for_each_entry(fcport, &ha->fcports, list) {
2636 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2637 (fcport->d_id.b24 & mask) != d_id.b24 ||
2638 fcport->port_type == FCT_BROADCAST)
2641 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2643 fcport->port_type != FCT_INITIATOR) {
2644 qla2x00_mark_device_lost(ha, fcport,
2648 fcport->flags &= ~FCF_FARP_DONE;
2655 * qla2x00_fabric_dev_login
2656 * Login fabric target device and update FC port database.
2659 * ha: adapter state pointer.
2660 * fcport: port structure list pointer.
2661 * next_loopid: contains value of a new loop ID that can be used
2662 * by the next login attempt.
2665 * qla2x00 local function return status code.
2671 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2672 uint16_t *next_loopid)
2681 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2682 if (rval == QLA_SUCCESS) {
2683 /* Send an ADISC to tape devices.*/
2685 if (fcport->flags & FCF_TAPE_PRESENT)
2687 rval = qla2x00_get_port_database(ha, fcport, opts);
2688 if (rval != QLA_SUCCESS) {
2689 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2690 fcport->d_id.b.domain, fcport->d_id.b.area,
2691 fcport->d_id.b.al_pa);
2692 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2694 qla2x00_update_fcport(ha, fcport);
2702 * qla2x00_fabric_login
2703 * Issue fabric login command.
2706 * ha = adapter block pointer.
2707 * device = pointer to FC device type structure.
2710 * 0 - Login successfully
2712 * 2 - Initiator device
2716 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2717 uint16_t *next_loopid)
2721 uint16_t tmp_loopid;
2722 uint16_t mb[MAILBOX_REGISTER_COUNT];
2728 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2729 "for port %02x%02x%02x.\n",
2730 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2731 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2733 /* Login fcport on switch. */
2734 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2735 fcport->d_id.b.domain, fcport->d_id.b.area,
2736 fcport->d_id.b.al_pa, mb, BIT_0);
2737 if (mb[0] == MBS_PORT_ID_USED) {
2739 * Device has another loop ID. The firmware team
2740 * recommends the driver perform an implicit login with
2741 * the specified ID again. The ID we just used is save
2742 * here so we return with an ID that can be tried by
2746 tmp_loopid = fcport->loop_id;
2747 fcport->loop_id = mb[1];
2749 DEBUG(printk("Fabric Login: port in use - next "
2750 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2751 fcport->loop_id, fcport->d_id.b.domain,
2752 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2754 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2759 /* A retry occurred before. */
2760 *next_loopid = tmp_loopid;
2763 * No retry occurred before. Just increment the
2764 * ID value for next login.
2766 *next_loopid = (fcport->loop_id + 1);
2769 if (mb[1] & BIT_0) {
2770 fcport->port_type = FCT_INITIATOR;
2772 fcport->port_type = FCT_TARGET;
2773 if (mb[1] & BIT_1) {
2774 fcport->flags |= FCF_TAPE_PRESENT;
2779 fcport->supported_classes |= FC_COS_CLASS2;
2781 fcport->supported_classes |= FC_COS_CLASS3;
2785 } else if (mb[0] == MBS_LOOP_ID_USED) {
2787 * Loop ID already used, try next loop ID.
2790 rval = qla2x00_find_new_loop_id(ha, fcport);
2791 if (rval != QLA_SUCCESS) {
2792 /* Ran out of loop IDs to use */
2795 } else if (mb[0] == MBS_COMMAND_ERROR) {
2797 * Firmware possibly timed out during login. If NO
2798 * retries are left to do then the device is declared
2801 *next_loopid = fcport->loop_id;
2802 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2803 fcport->d_id.b.domain, fcport->d_id.b.area,
2804 fcport->d_id.b.al_pa);
2805 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2811 * unrecoverable / not handled error
2813 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2814 "loop_id=%x jiffies=%lx.\n",
2815 __func__, ha->host_no, mb[0],
2816 fcport->d_id.b.domain, fcport->d_id.b.area,
2817 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2819 *next_loopid = fcport->loop_id;
2820 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2821 fcport->d_id.b.domain, fcport->d_id.b.area,
2822 fcport->d_id.b.al_pa);
2823 fcport->loop_id = FC_NO_LOOP_ID;
2824 fcport->login_retry = 0;
2835 * qla2x00_local_device_login
2836 * Issue local device login command.
2839 * ha = adapter block pointer.
2840 * loop_id = loop id of device to login to.
2842 * Returns (Where's the #define!!!!):
2843 * 0 - Login successfully
2848 qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
2851 uint16_t mb[MAILBOX_REGISTER_COUNT];
2853 memset(mb, 0, sizeof(mb));
2854 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
2855 if (rval == QLA_SUCCESS) {
2856 /* Interrogate mailbox registers for any errors */
2857 if (mb[0] == MBS_COMMAND_ERROR)
2859 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
2860 /* device not in PCB table */
2868 * qla2x00_loop_resync
2869 * Resync with fibre channel devices.
2872 * ha = adapter block pointer.
2878 qla2x00_loop_resync(scsi_qla_host_t *ha)
2885 atomic_set(&ha->loop_state, LOOP_UPDATE);
2886 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2887 if (ha->flags.online) {
2888 if (!(rval = qla2x00_fw_ready(ha))) {
2889 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2892 atomic_set(&ha->loop_state, LOOP_UPDATE);
2894 /* Issue a marker after FW becomes ready. */
2895 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
2896 ha->marker_needed = 0;
2898 /* Remap devices on Loop. */
2899 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2901 qla2x00_configure_loop(ha);
2903 } while (!atomic_read(&ha->loop_down_timer) &&
2904 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
2906 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
2910 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2911 return (QLA_FUNCTION_FAILED);
2915 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
2922 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
2928 list_for_each_entry(fcport, &ha->fcports, list) {
2929 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
2932 qla2x00_update_fcport(ha, fcport);
2933 fcport->flags &= ~FCF_RESCAN_NEEDED;
2937 qla2x00_probe_for_all_luns(ha);
2941 qla2x00_update_fcports(scsi_qla_host_t *ha)
2945 /* Go with deferred removal of rport references. */
2946 list_for_each_entry(fcport, &ha->fcports, list)
2948 qla2x00_rport_del(fcport);
2953 * Resets ISP and aborts all outstanding commands.
2956 * ha = adapter block pointer.
2962 qla2x00_abort_isp(scsi_qla_host_t *ha)
2964 unsigned long flags = 0;
2969 if (ha->flags.online) {
2970 ha->flags.online = 0;
2971 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2973 qla_printk(KERN_INFO, ha,
2974 "Performing ISP error recovery - ha= %p.\n", ha);
2975 ha->isp_ops.reset_chip(ha);
2977 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
2978 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
2979 atomic_set(&ha->loop_state, LOOP_DOWN);
2980 qla2x00_mark_all_devices_lost(ha, 0);
2982 if (!atomic_read(&ha->loop_down_timer))
2983 atomic_set(&ha->loop_down_timer,
2987 spin_lock_irqsave(&ha->hardware_lock, flags);
2988 /* Requeue all commands in outstanding command list. */
2989 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
2990 sp = ha->outstanding_cmds[cnt];
2992 ha->outstanding_cmds[cnt] = NULL;
2994 sp->cmd->result = DID_RESET << 16;
2995 sp->cmd->host_scribble = (unsigned char *)NULL;
2996 qla2x00_sp_compl(ha, sp);
2999 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3001 ha->isp_ops.nvram_config(ha);
3003 if (!qla2x00_restart_isp(ha)) {
3004 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3006 if (!atomic_read(&ha->loop_down_timer)) {
3008 * Issue marker command only when we are going
3009 * to start the I/O .
3011 ha->marker_needed = 1;
3014 ha->flags.online = 1;
3016 ha->isp_ops.enable_intrs(ha);
3018 ha->isp_abort_cnt = 0;
3019 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3020 } else { /* failed the ISP abort */
3021 ha->flags.online = 1;
3022 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3023 if (ha->isp_abort_cnt == 0) {
3024 qla_printk(KERN_WARNING, ha,
3025 "ISP error recovery failed - "
3026 "board disabled\n");
3028 * The next call disables the board
3031 ha->isp_ops.reset_adapter(ha);
3032 ha->flags.online = 0;
3033 clear_bit(ISP_ABORT_RETRY,
3036 } else { /* schedule another ISP abort */
3037 ha->isp_abort_cnt--;
3038 DEBUG(printk("qla%ld: ISP abort - "
3039 "retry remaining %d\n",
3040 ha->host_no, ha->isp_abort_cnt);)
3044 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3045 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3046 "- retrying (%d) more times\n",
3047 ha->host_no, ha->isp_abort_cnt);)
3048 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3056 qla_printk(KERN_INFO, ha,
3057 "qla2x00_abort_isp: **** FAILED ****\n");
3059 DEBUG(printk(KERN_INFO
3060 "qla2x00_abort_isp(%ld): exiting.\n",
3068 * qla2x00_restart_isp
3069 * restarts the ISP after a reset
3072 * ha = adapter block pointer.
3078 qla2x00_restart_isp(scsi_qla_host_t *ha)
3081 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3082 unsigned long flags = 0;
3085 /* If firmware needs to be loaded */
3086 if (qla2x00_isp_firmware(ha)) {
3087 ha->flags.online = 0;
3088 if (!(status = ha->isp_ops.chip_diag(ha))) {
3089 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3090 status = qla2x00_setup_chip(ha);
3094 spin_lock_irqsave(&ha->hardware_lock, flags);
3096 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3098 * Disable SRAM, Instruction RAM and GP RAM
3101 WRT_REG_WORD(®->hccr,
3102 (HCCR_ENABLE_PARITY + 0x0));
3103 RD_REG_WORD(®->hccr);
3106 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3108 status = qla2x00_setup_chip(ha);
3110 spin_lock_irqsave(&ha->hardware_lock, flags);
3112 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3113 /* Enable proper parity */
3116 WRT_REG_WORD(®->hccr,
3117 (HCCR_ENABLE_PARITY + 0x1));
3120 * SRAM, Instruction RAM and GP RAM
3123 WRT_REG_WORD(®->hccr,
3124 (HCCR_ENABLE_PARITY + 0x7));
3125 RD_REG_WORD(®->hccr);
3128 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3133 if (!status && !(status = qla2x00_init_rings(ha))) {
3134 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3135 if (!(status = qla2x00_fw_ready(ha))) {
3136 DEBUG(printk("%s(): Start configure loop, "
3137 "status = %d\n", __func__, status);)
3139 /* Issue a marker after FW becomes ready. */
3140 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3142 ha->flags.online = 1;
3143 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3146 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3147 qla2x00_configure_loop(ha);
3149 } while (!atomic_read(&ha->loop_down_timer) &&
3150 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3152 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3155 /* if no cable then assume it's good */
3156 if ((ha->device_flags & DFLG_NO_CABLE))
3159 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3167 * qla2x00_reset_adapter
3171 * ha = adapter block pointer.
3174 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3176 unsigned long flags = 0;
3177 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3179 ha->flags.online = 0;
3180 ha->isp_ops.disable_intrs(ha);
3182 spin_lock_irqsave(&ha->hardware_lock, flags);
3183 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3184 RD_REG_WORD(®->hccr); /* PCI Posting. */
3185 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3186 RD_REG_WORD(®->hccr); /* PCI Posting. */
3187 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3191 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3193 unsigned long flags = 0;
3194 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3196 ha->flags.online = 0;
3197 ha->isp_ops.disable_intrs(ha);
3199 spin_lock_irqsave(&ha->hardware_lock, flags);
3200 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3201 RD_REG_DWORD(®->hccr);
3202 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3203 RD_REG_DWORD(®->hccr);
3204 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3208 qla24xx_nvram_config(scsi_qla_host_t *ha)
3211 struct init_cb_24xx *icb;
3212 struct nvram_24xx *nv;
3214 uint8_t *dptr1, *dptr2;
3219 icb = (struct init_cb_24xx *)ha->init_cb;
3220 nv = (struct nvram_24xx *)ha->request_ring;
3222 /* Determine NVRAM starting address. */
3223 ha->nvram_size = sizeof(struct nvram_24xx);
3224 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3225 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3226 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3227 if (PCI_FUNC(ha->pdev->devfn)) {
3228 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3229 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3232 /* Get NVRAM data and calculate checksum. */
3233 dptr = (uint32_t *)nv;
3234 ha->isp_ops.read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3236 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3237 chksum += le32_to_cpu(*dptr++);
3239 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3240 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3243 /* Bad NVRAM data, set defaults parameters. */
3244 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3245 || nv->id[3] != ' ' ||
3246 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3247 /* Reset NVRAM data. */
3248 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3249 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3250 le16_to_cpu(nv->nvram_version));
3251 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3252 "invalid -- WWPN) defaults.\n");
3255 * Set default initialization control block.
3257 memset(nv, 0, ha->nvram_size);
3258 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3259 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3260 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3261 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3262 nv->exchange_count = __constant_cpu_to_le16(0);
3263 nv->hard_address = __constant_cpu_to_le16(124);
3264 nv->port_name[0] = 0x21;
3265 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3266 nv->port_name[2] = 0x00;
3267 nv->port_name[3] = 0xe0;
3268 nv->port_name[4] = 0x8b;
3269 nv->port_name[5] = 0x1c;
3270 nv->port_name[6] = 0x55;
3271 nv->port_name[7] = 0x86;
3272 nv->node_name[0] = 0x20;
3273 nv->node_name[1] = 0x00;
3274 nv->node_name[2] = 0x00;
3275 nv->node_name[3] = 0xe0;
3276 nv->node_name[4] = 0x8b;
3277 nv->node_name[5] = 0x1c;
3278 nv->node_name[6] = 0x55;
3279 nv->node_name[7] = 0x86;
3280 nv->login_retry_count = __constant_cpu_to_le16(8);
3281 nv->link_down_timeout = __constant_cpu_to_le16(200);
3282 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3283 nv->login_timeout = __constant_cpu_to_le16(0);
3284 nv->firmware_options_1 =
3285 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3286 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3287 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3288 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3289 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3290 nv->efi_parameters = __constant_cpu_to_le32(0);
3291 nv->reset_delay = 5;
3292 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3293 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3294 nv->link_down_timeout = __constant_cpu_to_le16(30);
3299 /* Reset Initialization control block */
3300 memset(icb, 0, sizeof(struct init_cb_24xx));
3302 /* Copy 1st segment. */
3303 dptr1 = (uint8_t *)icb;
3304 dptr2 = (uint8_t *)&nv->version;
3305 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3307 *dptr1++ = *dptr2++;
3309 icb->login_retry_count = nv->login_retry_count;
3310 icb->link_down_timeout = nv->link_down_timeout;
3312 /* Copy 2nd segment. */
3313 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3314 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3315 cnt = (uint8_t *)&icb->reserved_3 -
3316 (uint8_t *)&icb->interrupt_delay_timer;
3318 *dptr1++ = *dptr2++;
3321 * Setup driver NVRAM options.
3323 if (memcmp(nv->model_name, BINZERO, sizeof(nv->model_name)) != 0) {
3327 strncpy(ha->model_number, nv->model_name,
3328 sizeof(nv->model_name));
3329 st = en = ha->model_number;
3330 en += sizeof(nv->model_name) - 1;
3332 if (*en != 0x20 && *en != 0x00)
3337 index = (ha->pdev->subsystem_device & 0xff);
3338 if (index < QLA_MODEL_NAMES)
3339 ha->model_desc = qla2x00_model_name[index * 2 + 1];
3341 strcpy(ha->model_number, "QLA2462");
3343 /* Use alternate WWN? */
3344 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3345 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3346 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3349 /* Prepare nodename */
3350 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3352 * Firmware will apply the following mask if the nodename was
3355 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3356 icb->node_name[0] &= 0xF0;
3359 /* Set host adapter parameters. */
3360 ha->flags.disable_risc_code_load = 0;
3361 ha->flags.enable_lip_reset = 1;
3362 ha->flags.enable_lip_full_login = 1;
3363 ha->flags.enable_target_reset = 1;
3364 ha->flags.enable_led_scheme = 0;
3366 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3367 (BIT_6 | BIT_5 | BIT_4)) >> 4;
3369 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3370 sizeof(ha->fw_seriallink_options24));
3372 /* save HBA serial number */
3373 ha->serial0 = icb->port_name[5];
3374 ha->serial1 = icb->port_name[6];
3375 ha->serial2 = icb->port_name[7];
3376 ha->node_name = icb->node_name;
3377 ha->port_name = icb->port_name;
3379 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3381 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3383 /* Set minimum login_timeout to 4 seconds. */
3384 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3385 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3386 if (le16_to_cpu(nv->login_timeout) < 4)
3387 nv->login_timeout = __constant_cpu_to_le16(4);
3388 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3389 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3391 /* Set minimum RATOV to 200 tenths of a second. */
3394 ha->loop_reset_delay = nv->reset_delay;
3396 /* Link Down Timeout = 0:
3398 * When Port Down timer expires we will start returning
3399 * I/O's to OS with "DID_NO_CONNECT".
3401 * Link Down Timeout != 0:
3403 * The driver waits for the link to come up after link down
3404 * before returning I/Os to OS with "DID_NO_CONNECT".
3406 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3407 ha->loop_down_abort_time =
3408 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3410 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3411 ha->loop_down_abort_time =
3412 (LOOP_DOWN_TIME - ha->link_down_timeout);
3415 /* Need enough time to try and get the port back. */
3416 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3417 if (qlport_down_retry)
3418 ha->port_down_retry_count = qlport_down_retry;
3420 /* Set login_retry_count */
3421 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3422 if (ha->port_down_retry_count ==
3423 le16_to_cpu(nv->port_down_retry_count) &&
3424 ha->port_down_retry_count > 3)
3425 ha->login_retry_count = ha->port_down_retry_count;
3426 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3427 ha->login_retry_count = ha->port_down_retry_count;
3428 if (ql2xloginretrycount)
3429 ha->login_retry_count = ql2xloginretrycount;
3432 if (!ha->flags.init_done) {
3433 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3434 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3435 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3436 le16_to_cpu(icb->interrupt_delay_timer): 2;
3438 icb->firmware_options_2 &= __constant_cpu_to_le32(
3439 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3440 ha->flags.process_response_queue = 0;
3441 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3442 ha->zio_mode = QLA_ZIO_MODE_6;
3444 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3445 "(%d us).\n", ha->host_no, ha->zio_mode,
3446 ha->zio_timer * 100));
3447 qla_printk(KERN_INFO, ha,
3448 "ZIO mode %d enabled; timer delay (%d us).\n",
3449 ha->zio_mode, ha->zio_timer * 100);
3451 icb->firmware_options_2 |= cpu_to_le32(
3452 (uint32_t)ha->zio_mode);
3453 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3454 ha->flags.process_response_queue = 1;
3458 DEBUG2_3(printk(KERN_WARNING
3459 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3465 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3468 int segments, fragment;
3470 uint32_t *dcode, dlen;
3477 segments = FA_RISC_CODE_SEGMENTS;
3478 faddr = FA_RISC_CODE_ADDR;
3479 dcode = (uint32_t *)ha->request_ring;
3482 /* Validate firmware image by checking version. */
3483 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3484 for (i = 0; i < 4; i++)
3485 dcode[i] = be32_to_cpu(dcode[i]);
3486 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3487 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3488 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3490 qla_printk(KERN_WARNING, ha,
3491 "Unable to verify integrity of flash firmware image!\n");
3492 qla_printk(KERN_WARNING, ha,
3493 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3494 dcode[1], dcode[2], dcode[3]);
3496 return QLA_FUNCTION_FAILED;
3499 while (segments && rval == QLA_SUCCESS) {
3500 /* Read segment's load information. */
3501 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3503 risc_addr = be32_to_cpu(dcode[2]);
3504 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3505 risc_size = be32_to_cpu(dcode[3]);
3508 while (risc_size > 0 && rval == QLA_SUCCESS) {
3509 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3510 if (dlen > risc_size)
3513 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3514 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3515 ha->host_no, risc_addr, dlen, faddr));
3517 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3518 for (i = 0; i < dlen; i++)
3519 dcode[i] = swab32(dcode[i]);
3521 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3524 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3525 "segment %d of firmware\n", ha->host_no,
3527 qla_printk(KERN_WARNING, ha,
3528 "[ERROR] Failed to load segment %d of "
3529 "firmware\n", fragment);
3546 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3549 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3553 uint16_t *wcode, *fwcode;
3554 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3555 struct fw_blob *blob;
3557 /* Load firmware blob. */
3558 blob = qla2x00_request_firmware(ha);
3560 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3561 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3562 "from: " QLA_FW_URL ".\n");
3563 return QLA_FUNCTION_FAILED;
3568 wcode = (uint16_t *)ha->request_ring;
3570 fwcode = (uint16_t *)blob->fw->data;
3573 /* Validate firmware image by checking version. */
3574 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3575 qla_printk(KERN_WARNING, ha,
3576 "Unable to verify integrity of firmware image (%Zd)!\n",
3578 goto fail_fw_integrity;
3580 for (i = 0; i < 4; i++)
3581 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3582 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3583 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3584 wcode[2] == 0 && wcode[3] == 0)) {
3585 qla_printk(KERN_WARNING, ha,
3586 "Unable to verify integrity of firmware image!\n");
3587 qla_printk(KERN_WARNING, ha,
3588 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3589 wcode[1], wcode[2], wcode[3]);
3590 goto fail_fw_integrity;
3594 while (*seg && rval == QLA_SUCCESS) {
3596 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3597 risc_size = be16_to_cpu(fwcode[3]);
3599 /* Validate firmware image size. */
3600 fwclen += risc_size * sizeof(uint16_t);
3601 if (blob->fw->size < fwclen) {
3602 qla_printk(KERN_WARNING, ha,
3603 "Unable to verify integrity of firmware image "
3604 "(%Zd)!\n", blob->fw->size);
3605 goto fail_fw_integrity;
3609 while (risc_size > 0 && rval == QLA_SUCCESS) {
3610 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3611 if (wlen > risc_size)
3614 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3615 "addr %x, number of words 0x%x.\n", ha->host_no,
3618 for (i = 0; i < wlen; i++)
3619 wcode[i] = swab16(fwcode[i]);
3621 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3624 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3625 "segment %d of firmware\n", ha->host_no,
3627 qla_printk(KERN_WARNING, ha,
3628 "[ERROR] Failed to load segment %d of "
3629 "firmware\n", fragment);
3645 return QLA_FUNCTION_FAILED;
3649 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3652 int segments, fragment;
3653 uint32_t *dcode, dlen;
3657 struct fw_blob *blob;
3658 uint32_t *fwcode, fwclen;
3660 /* Load firmware blob. */
3661 blob = qla2x00_request_firmware(ha);
3663 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3664 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3665 "from: " QLA_FW_URL ".\n");
3667 /* Try to load RISC code from flash. */
3668 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3669 "outdated) firmware from flash.\n");
3670 return qla24xx_load_risc_flash(ha, srisc_addr);
3675 segments = FA_RISC_CODE_SEGMENTS;
3676 dcode = (uint32_t *)ha->request_ring;
3678 fwcode = (uint32_t *)blob->fw->data;
3681 /* Validate firmware image by checking version. */
3682 if (blob->fw->size < 8 * sizeof(uint32_t)) {
3683 qla_printk(KERN_WARNING, ha,
3684 "Unable to verify integrity of firmware image (%Zd)!\n",
3686 goto fail_fw_integrity;
3688 for (i = 0; i < 4; i++)
3689 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3690 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3691 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3692 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3694 qla_printk(KERN_WARNING, ha,
3695 "Unable to verify integrity of firmware image!\n");
3696 qla_printk(KERN_WARNING, ha,
3697 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3698 dcode[1], dcode[2], dcode[3]);
3699 goto fail_fw_integrity;
3702 while (segments && rval == QLA_SUCCESS) {
3703 risc_addr = be32_to_cpu(fwcode[2]);
3704 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3705 risc_size = be32_to_cpu(fwcode[3]);
3707 /* Validate firmware image size. */
3708 fwclen += risc_size * sizeof(uint32_t);
3709 if (blob->fw->size < fwclen) {
3710 qla_printk(KERN_WARNING, ha,
3711 "Unable to verify integrity of firmware image "
3712 "(%Zd)!\n", blob->fw->size);
3714 goto fail_fw_integrity;
3718 while (risc_size > 0 && rval == QLA_SUCCESS) {
3719 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3720 if (dlen > risc_size)
3723 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3724 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3727 for (i = 0; i < dlen; i++)
3728 dcode[i] = swab32(fwcode[i]);
3730 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3733 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3734 "segment %d of firmware\n", ha->host_no,
3736 qla_printk(KERN_WARNING, ha,
3737 "[ERROR] Failed to load segment %d of "
3738 "firmware\n", fragment);
3754 return QLA_FUNCTION_FAILED;