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)
776 uint32_t dump_size = 0;
779 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
780 dump_size = sizeof(struct qla2100_fw_dump);
781 } else if (IS_QLA23XX(ha)) {
782 dump_size = sizeof(struct qla2300_fw_dump);
783 dump_size += (ha->fw_memory_size - 0x11000) * sizeof(uint16_t);
784 } else if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
785 dump_size = sizeof(struct qla24xx_fw_dump);
786 dump_size += (ha->fw_memory_size - 0x100000) * sizeof(uint32_t);
789 ha->fw_dump = vmalloc(dump_size);
791 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware "
792 "dump...\n", dump_size / 1024);
794 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
795 "firmware dump!!!\n", dump_size / 1024);
799 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
802 * Returns 0 on success.
805 qla2x00_resize_request_q(scsi_qla_host_t *ha)
808 uint16_t fw_iocb_cnt = 0;
809 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
810 dma_addr_t request_dma;
811 request_t *request_ring;
813 qla2x00_alloc_fw_dump(ha);
815 /* Valid only on recent ISPs. */
816 if (IS_QLA2100(ha) || IS_QLA2200(ha))
819 /* Retrieve IOCB counts available to the firmware. */
820 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
823 /* No point in continuing if current settings are sufficient. */
824 if (fw_iocb_cnt < 1024)
826 if (ha->request_q_length >= request_q_length)
829 /* Attempt to claim larger area for request queue. */
830 request_ring = dma_alloc_coherent(&ha->pdev->dev,
831 (request_q_length + 1) * sizeof(request_t), &request_dma,
833 if (request_ring == NULL)
836 /* Resize successful, report extensions. */
837 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
838 (ha->fw_memory_size + 1) / 1024);
839 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
840 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
842 /* Clear old allocations. */
843 dma_free_coherent(&ha->pdev->dev,
844 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
847 /* Begin using larger queue. */
848 ha->request_q_length = request_q_length;
849 ha->request_ring = request_ring;
850 ha->request_dma = request_dma;
854 * qla2x00_setup_chip() - Load and start RISC firmware.
857 * Returns 0 on success.
860 qla2x00_setup_chip(scsi_qla_host_t *ha)
863 uint32_t srisc_address = 0;
865 /* Load firmware sequences */
866 rval = ha->isp_ops.load_risc(ha, &srisc_address);
867 if (rval == QLA_SUCCESS) {
868 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
869 "code.\n", ha->host_no));
871 rval = qla2x00_verify_checksum(ha, srisc_address);
872 if (rval == QLA_SUCCESS) {
873 /* Start firmware execution. */
874 DEBUG(printk("scsi(%ld): Checksum OK, start "
875 "firmware.\n", ha->host_no));
877 rval = qla2x00_execute_fw(ha, srisc_address);
878 /* Retrieve firmware information. */
879 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
880 qla2x00_get_fw_version(ha,
881 &ha->fw_major_version,
882 &ha->fw_minor_version,
883 &ha->fw_subminor_version,
884 &ha->fw_attributes, &ha->fw_memory_size);
885 qla2x00_resize_request_q(ha);
888 DEBUG2(printk(KERN_INFO
889 "scsi(%ld): ISP Firmware failed checksum.\n",
895 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
903 * qla2x00_init_response_q_entries() - Initializes response queue entries.
906 * Beginning of request ring has initialization control block already built
907 * by nvram config routine.
909 * Returns 0 on success.
912 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
917 pkt = ha->response_ring_ptr;
918 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
919 pkt->signature = RESPONSE_PROCESSED;
926 * qla2x00_update_fw_options() - Read and process firmware options.
929 * Returns 0 on success.
932 qla2x00_update_fw_options(scsi_qla_host_t *ha)
934 uint16_t swing, emphasis, tx_sens, rx_sens;
936 memset(ha->fw_options, 0, sizeof(ha->fw_options));
937 qla2x00_get_fw_options(ha, ha->fw_options);
939 if (IS_QLA2100(ha) || IS_QLA2200(ha))
942 /* Serial Link options. */
943 DEBUG3(printk("scsi(%ld): Serial link options:\n",
945 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
946 sizeof(ha->fw_seriallink_options)));
948 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
949 if (ha->fw_seriallink_options[3] & BIT_2) {
950 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
953 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
954 emphasis = (ha->fw_seriallink_options[2] &
955 (BIT_4 | BIT_3)) >> 3;
956 tx_sens = ha->fw_seriallink_options[0] &
957 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
958 rx_sens = (ha->fw_seriallink_options[0] &
959 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
960 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
961 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
964 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
965 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
966 ha->fw_options[10] |= BIT_5 |
967 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
968 (tx_sens & (BIT_1 | BIT_0));
971 swing = (ha->fw_seriallink_options[2] &
972 (BIT_7 | BIT_6 | BIT_5)) >> 5;
973 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
974 tx_sens = ha->fw_seriallink_options[1] &
975 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
976 rx_sens = (ha->fw_seriallink_options[1] &
977 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
978 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
979 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
982 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
983 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
984 ha->fw_options[11] |= BIT_5 |
985 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
986 (tx_sens & (BIT_1 | BIT_0));
990 /* Return command IOCBs without waiting for an ABTS to complete. */
991 ha->fw_options[3] |= BIT_13;
994 if (ha->flags.enable_led_scheme)
995 ha->fw_options[2] |= BIT_12;
997 /* Detect ISP6312. */
999 ha->fw_options[2] |= BIT_13;
1001 /* Update firmware options. */
1002 qla2x00_set_fw_options(ha, ha->fw_options);
1006 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1010 /* Update Serial Link options. */
1011 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1014 rval = qla2x00_set_serdes_params(ha,
1015 le16_to_cpu(ha->fw_seriallink_options24[1]),
1016 le16_to_cpu(ha->fw_seriallink_options24[2]),
1017 le16_to_cpu(ha->fw_seriallink_options24[3]));
1018 if (rval != QLA_SUCCESS) {
1019 qla_printk(KERN_WARNING, ha,
1020 "Unable to update Serial Link options (%x).\n", rval);
1025 qla2x00_config_rings(struct scsi_qla_host *ha)
1027 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1029 /* Setup ring parameters in initialization control block. */
1030 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1031 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1032 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1033 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1034 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1035 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1036 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1037 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1039 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1040 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1041 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1042 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1043 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1047 qla24xx_config_rings(struct scsi_qla_host *ha)
1049 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1050 struct init_cb_24xx *icb;
1052 /* Setup ring parameters in initialization control block. */
1053 icb = (struct init_cb_24xx *)ha->init_cb;
1054 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1055 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1056 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1057 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1058 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1059 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1060 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1061 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1063 WRT_REG_DWORD(®->req_q_in, 0);
1064 WRT_REG_DWORD(®->req_q_out, 0);
1065 WRT_REG_DWORD(®->rsp_q_in, 0);
1066 WRT_REG_DWORD(®->rsp_q_out, 0);
1067 RD_REG_DWORD(®->rsp_q_out);
1071 * qla2x00_init_rings() - Initializes firmware.
1074 * Beginning of request ring has initialization control block already built
1075 * by nvram config routine.
1077 * Returns 0 on success.
1080 qla2x00_init_rings(scsi_qla_host_t *ha)
1083 unsigned long flags = 0;
1086 spin_lock_irqsave(&ha->hardware_lock, flags);
1088 /* Clear outstanding commands array. */
1089 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1090 ha->outstanding_cmds[cnt] = NULL;
1092 ha->current_outstanding_cmd = 0;
1094 /* Clear RSCN queue. */
1095 ha->rscn_in_ptr = 0;
1096 ha->rscn_out_ptr = 0;
1098 /* Initialize firmware. */
1099 ha->request_ring_ptr = ha->request_ring;
1100 ha->req_ring_index = 0;
1101 ha->req_q_cnt = ha->request_q_length;
1102 ha->response_ring_ptr = ha->response_ring;
1103 ha->rsp_ring_index = 0;
1105 /* Initialize response queue entries */
1106 qla2x00_init_response_q_entries(ha);
1108 ha->isp_ops.config_rings(ha);
1110 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1112 /* Update any ISP specific firmware options before initialization. */
1113 ha->isp_ops.update_fw_options(ha);
1115 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1116 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1118 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1121 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1129 * qla2x00_fw_ready() - Waits for firmware ready.
1132 * Returns 0 on success.
1135 qla2x00_fw_ready(scsi_qla_host_t *ha)
1138 unsigned long wtime, mtime;
1139 uint16_t min_wait; /* Minimum wait time if loop is down */
1140 uint16_t wait_time; /* Wait time if loop is coming ready */
1145 /* 20 seconds for loop down. */
1149 * Firmware should take at most one RATOV to login, plus 5 seconds for
1150 * our own processing.
1152 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1153 wait_time = min_wait;
1156 /* Min wait time if loop down */
1157 mtime = jiffies + (min_wait * HZ);
1159 /* wait time before firmware ready */
1160 wtime = jiffies + (wait_time * HZ);
1162 /* Wait for ISP to finish LIP */
1163 if (!ha->flags.init_done)
1164 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1166 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1170 rval = qla2x00_get_firmware_state(ha, &fw_state);
1171 if (rval == QLA_SUCCESS) {
1172 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1173 ha->device_flags &= ~DFLG_NO_CABLE;
1175 if (fw_state == FSTATE_READY) {
1176 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1179 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1180 &ha->login_timeout, &ha->r_a_tov);
1186 rval = QLA_FUNCTION_FAILED;
1188 if (atomic_read(&ha->loop_down_timer) &&
1189 (fw_state >= FSTATE_LOSS_OF_SYNC ||
1190 fw_state == FSTATE_WAIT_AL_PA)) {
1191 /* Loop down. Timeout on min_wait for states
1192 * other than Wait for Login.
1194 if (time_after_eq(jiffies, mtime)) {
1195 qla_printk(KERN_INFO, ha,
1196 "Cable is unplugged...\n");
1198 ha->device_flags |= DFLG_NO_CABLE;
1203 /* Mailbox cmd failed. Timeout on min_wait. */
1204 if (time_after_eq(jiffies, mtime))
1208 if (time_after_eq(jiffies, wtime))
1211 /* Delay for a while */
1214 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1215 ha->host_no, fw_state, jiffies));
1218 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1219 ha->host_no, fw_state, jiffies));
1222 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1230 * qla2x00_configure_hba
1231 * Setup adapter context.
1234 * ha = adapter state pointer.
1243 qla2x00_configure_hba(scsi_qla_host_t *ha)
1251 char connect_type[22];
1253 /* Get host addresses. */
1254 rval = qla2x00_get_adapter_id(ha,
1255 &loop_id, &al_pa, &area, &domain, &topo);
1256 if (rval != QLA_SUCCESS) {
1257 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
1258 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1259 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1260 __func__, ha->host_no));
1262 qla_printk(KERN_WARNING, ha,
1263 "ERROR -- Unable to get host loop ID.\n");
1264 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1270 qla_printk(KERN_INFO, ha,
1271 "Cannot get topology - retrying.\n");
1272 return (QLA_FUNCTION_FAILED);
1275 ha->loop_id = loop_id;
1278 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1279 ha->operating_mode = LOOP;
1283 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1285 ha->current_topology = ISP_CFG_NL;
1286 strcpy(connect_type, "(Loop)");
1290 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1292 ha->current_topology = ISP_CFG_FL;
1293 strcpy(connect_type, "(FL_Port)");
1297 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1299 ha->operating_mode = P2P;
1300 ha->current_topology = ISP_CFG_N;
1301 strcpy(connect_type, "(N_Port-to-N_Port)");
1305 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1307 ha->operating_mode = P2P;
1308 ha->current_topology = ISP_CFG_F;
1309 strcpy(connect_type, "(F_Port)");
1313 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1315 ha->host_no, topo));
1316 ha->current_topology = ISP_CFG_NL;
1317 strcpy(connect_type, "(Loop)");
1321 /* Save Host port and loop ID. */
1322 /* byte order - Big Endian */
1323 ha->d_id.b.domain = domain;
1324 ha->d_id.b.area = area;
1325 ha->d_id.b.al_pa = al_pa;
1327 if (!ha->flags.init_done)
1328 qla_printk(KERN_INFO, ha,
1329 "Topology - %s, Host Loop address 0x%x\n",
1330 connect_type, ha->loop_id);
1333 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1335 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1342 * NVRAM configuration for ISP 2xxx
1345 * ha = adapter block pointer.
1348 * initialization control block in response_ring
1349 * host adapters parameters in host adapter block
1355 qla2x00_nvram_config(scsi_qla_host_t *ha)
1360 uint8_t *dptr1, *dptr2;
1361 init_cb_t *icb = ha->init_cb;
1362 nvram_t *nv = (nvram_t *)ha->request_ring;
1363 uint8_t *ptr = (uint8_t *)ha->request_ring;
1364 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1368 /* Determine NVRAM starting address. */
1369 ha->nvram_size = sizeof(nvram_t);
1371 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1372 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1373 ha->nvram_base = 0x80;
1375 /* Get NVRAM data and calculate checksum. */
1376 ha->isp_ops.read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1377 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1380 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1381 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1384 /* Bad NVRAM data, set defaults parameters. */
1385 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1386 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1387 /* Reset NVRAM data. */
1388 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1389 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1391 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1392 "invalid -- WWPN) defaults.\n");
1395 * Set default initialization control block.
1397 memset(nv, 0, ha->nvram_size);
1398 nv->parameter_block_version = ICB_VERSION;
1400 if (IS_QLA23XX(ha)) {
1401 nv->firmware_options[0] = BIT_2 | BIT_1;
1402 nv->firmware_options[1] = BIT_7 | BIT_5;
1403 nv->add_firmware_options[0] = BIT_5;
1404 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1405 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1406 nv->special_options[1] = BIT_7;
1407 } else if (IS_QLA2200(ha)) {
1408 nv->firmware_options[0] = BIT_2 | BIT_1;
1409 nv->firmware_options[1] = BIT_7 | BIT_5;
1410 nv->add_firmware_options[0] = BIT_5;
1411 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1412 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1413 } else if (IS_QLA2100(ha)) {
1414 nv->firmware_options[0] = BIT_3 | BIT_1;
1415 nv->firmware_options[1] = BIT_5;
1416 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1419 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1420 nv->execution_throttle = __constant_cpu_to_le16(16);
1421 nv->retry_count = 8;
1422 nv->retry_delay = 1;
1424 nv->port_name[0] = 33;
1425 nv->port_name[3] = 224;
1426 nv->port_name[4] = 139;
1428 nv->login_timeout = 4;
1431 * Set default host adapter parameters
1433 nv->host_p[1] = BIT_2;
1434 nv->reset_delay = 5;
1435 nv->port_down_retry_count = 8;
1436 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1437 nv->link_down_timeout = 60;
1442 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1444 * The SN2 does not provide BIOS emulation which means you can't change
1445 * potentially bogus BIOS settings. Force the use of default settings
1446 * for link rate and frame size. Hope that the rest of the settings
1449 if (ia64_platform_is("sn2")) {
1450 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1452 nv->special_options[1] = BIT_7;
1456 /* Reset Initialization control block */
1457 memset(icb, 0, ha->init_cb_size);
1460 * Setup driver NVRAM options.
1462 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1463 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1464 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1465 nv->firmware_options[1] &= ~BIT_4;
1467 if (IS_QLA23XX(ha)) {
1468 nv->firmware_options[0] |= BIT_2;
1469 nv->firmware_options[0] &= ~BIT_3;
1470 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1472 if (IS_QLA2300(ha)) {
1473 if (ha->fb_rev == FPM_2310) {
1474 strcpy(ha->model_number, "QLA2310");
1476 strcpy(ha->model_number, "QLA2300");
1480 memcmp(nv->model_number, BINZERO,
1481 sizeof(nv->model_number)) != 0) {
1484 strncpy(ha->model_number, nv->model_number,
1485 sizeof(nv->model_number));
1486 st = en = ha->model_number;
1487 en += sizeof(nv->model_number) - 1;
1489 if (*en != 0x20 && *en != 0x00)
1496 index = (ha->pdev->subsystem_device & 0xff);
1497 if (index < QLA_MODEL_NAMES) {
1498 strcpy(ha->model_number,
1499 qla2x00_model_name[index * 2]);
1501 qla2x00_model_name[index * 2 + 1];
1503 strcpy(ha->model_number, "QLA23xx");
1507 } else if (IS_QLA2200(ha)) {
1508 nv->firmware_options[0] |= BIT_2;
1510 * 'Point-to-point preferred, else loop' is not a safe
1511 * connection mode setting.
1513 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1515 /* Force 'loop preferred, else point-to-point'. */
1516 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1517 nv->add_firmware_options[0] |= BIT_5;
1519 strcpy(ha->model_number, "QLA22xx");
1520 } else /*if (IS_QLA2100(ha))*/ {
1521 strcpy(ha->model_number, "QLA2100");
1525 * Copy over NVRAM RISC parameter block to initialization control block.
1527 dptr1 = (uint8_t *)icb;
1528 dptr2 = (uint8_t *)&nv->parameter_block_version;
1529 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1531 *dptr1++ = *dptr2++;
1533 /* Copy 2nd half. */
1534 dptr1 = (uint8_t *)icb->add_firmware_options;
1535 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1537 *dptr1++ = *dptr2++;
1539 /* Use alternate WWN? */
1540 if (nv->host_p[1] & BIT_7) {
1541 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1542 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1545 /* Prepare nodename */
1546 if ((icb->firmware_options[1] & BIT_6) == 0) {
1548 * Firmware will apply the following mask if the nodename was
1551 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1552 icb->node_name[0] &= 0xF0;
1556 * Set host adapter parameters.
1558 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1559 /* Always load RISC code on non ISP2[12]00 chips. */
1560 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1561 ha->flags.disable_risc_code_load = 0;
1562 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1563 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1564 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1565 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1567 ha->operating_mode =
1568 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1570 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1571 sizeof(ha->fw_seriallink_options));
1573 /* save HBA serial number */
1574 ha->serial0 = icb->port_name[5];
1575 ha->serial1 = icb->port_name[6];
1576 ha->serial2 = icb->port_name[7];
1577 ha->node_name = icb->node_name;
1578 ha->port_name = icb->port_name;
1580 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1582 ha->retry_count = nv->retry_count;
1584 /* Set minimum login_timeout to 4 seconds. */
1585 if (nv->login_timeout < ql2xlogintimeout)
1586 nv->login_timeout = ql2xlogintimeout;
1587 if (nv->login_timeout < 4)
1588 nv->login_timeout = 4;
1589 ha->login_timeout = nv->login_timeout;
1590 icb->login_timeout = nv->login_timeout;
1592 /* Set minimum RATOV to 200 tenths of a second. */
1595 ha->loop_reset_delay = nv->reset_delay;
1597 /* Link Down Timeout = 0:
1599 * When Port Down timer expires we will start returning
1600 * I/O's to OS with "DID_NO_CONNECT".
1602 * Link Down Timeout != 0:
1604 * The driver waits for the link to come up after link down
1605 * before returning I/Os to OS with "DID_NO_CONNECT".
1607 if (nv->link_down_timeout == 0) {
1608 ha->loop_down_abort_time =
1609 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1611 ha->link_down_timeout = nv->link_down_timeout;
1612 ha->loop_down_abort_time =
1613 (LOOP_DOWN_TIME - ha->link_down_timeout);
1617 * Need enough time to try and get the port back.
1619 ha->port_down_retry_count = nv->port_down_retry_count;
1620 if (qlport_down_retry)
1621 ha->port_down_retry_count = qlport_down_retry;
1622 /* Set login_retry_count */
1623 ha->login_retry_count = nv->retry_count;
1624 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1625 ha->port_down_retry_count > 3)
1626 ha->login_retry_count = ha->port_down_retry_count;
1627 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1628 ha->login_retry_count = ha->port_down_retry_count;
1629 if (ql2xloginretrycount)
1630 ha->login_retry_count = ql2xloginretrycount;
1632 icb->lun_enables = __constant_cpu_to_le16(0);
1633 icb->command_resource_count = 0;
1634 icb->immediate_notify_resource_count = 0;
1635 icb->timeout = __constant_cpu_to_le16(0);
1637 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1639 icb->firmware_options[0] &= ~BIT_3;
1640 icb->add_firmware_options[0] &=
1641 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1642 icb->add_firmware_options[0] |= BIT_2;
1643 icb->response_accumulation_timer = 3;
1644 icb->interrupt_delay_timer = 5;
1646 ha->flags.process_response_queue = 1;
1649 if (!ha->flags.init_done) {
1650 ha->zio_mode = icb->add_firmware_options[0] &
1651 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1652 ha->zio_timer = icb->interrupt_delay_timer ?
1653 icb->interrupt_delay_timer: 2;
1655 icb->add_firmware_options[0] &=
1656 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1657 ha->flags.process_response_queue = 0;
1658 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1659 ha->zio_mode = QLA_ZIO_MODE_6;
1661 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1662 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1663 ha->zio_timer * 100));
1664 qla_printk(KERN_INFO, ha,
1665 "ZIO mode %d enabled; timer delay (%d us).\n",
1666 ha->zio_mode, ha->zio_timer * 100);
1668 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1669 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1670 ha->flags.process_response_queue = 1;
1675 DEBUG2_3(printk(KERN_WARNING
1676 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1682 qla2x00_rport_del(void *data)
1684 fc_port_t *fcport = data;
1685 struct fc_rport *rport;
1686 unsigned long flags;
1688 spin_lock_irqsave(&fcport->rport_lock, flags);
1689 rport = fcport->drport;
1690 fcport->drport = NULL;
1691 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1693 fc_remote_port_delete(rport);
1698 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1700 * @flags: allocation flags
1702 * Returns a pointer to the allocated fcport, or NULL, if none available.
1705 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1709 fcport = kmalloc(sizeof(fc_port_t), flags);
1713 /* Setup fcport template structure. */
1714 memset(fcport, 0, sizeof (fc_port_t));
1716 fcport->port_type = FCT_UNKNOWN;
1717 fcport->loop_id = FC_NO_LOOP_ID;
1718 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1719 fcport->flags = FCF_RLC_SUPPORT;
1720 fcport->supported_classes = FC_COS_UNSPECIFIED;
1721 spin_lock_init(&fcport->rport_lock);
1727 * qla2x00_configure_loop
1728 * Updates Fibre Channel Device Database with what is actually on loop.
1731 * ha = adapter block pointer.
1736 * 2 = database was full and device was not configured.
1739 qla2x00_configure_loop(scsi_qla_host_t *ha)
1742 unsigned long flags, save_flags;
1746 /* Get Initiator ID */
1747 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1748 rval = qla2x00_configure_hba(ha);
1749 if (rval != QLA_SUCCESS) {
1750 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1756 save_flags = flags = ha->dpc_flags;
1757 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1758 ha->host_no, flags));
1761 * If we have both an RSCN and PORT UPDATE pending then handle them
1762 * both at the same time.
1764 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1765 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1767 /* Determine what we need to do */
1768 if (ha->current_topology == ISP_CFG_FL &&
1769 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1771 ha->flags.rscn_queue_overflow = 1;
1772 set_bit(RSCN_UPDATE, &flags);
1774 } else if (ha->current_topology == ISP_CFG_F &&
1775 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1777 ha->flags.rscn_queue_overflow = 1;
1778 set_bit(RSCN_UPDATE, &flags);
1779 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1781 } else if (!ha->flags.online ||
1782 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1784 ha->flags.rscn_queue_overflow = 1;
1785 set_bit(RSCN_UPDATE, &flags);
1786 set_bit(LOCAL_LOOP_UPDATE, &flags);
1789 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1790 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1791 rval = QLA_FUNCTION_FAILED;
1793 rval = qla2x00_configure_local_loop(ha);
1797 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1798 if (LOOP_TRANSITION(ha)) {
1799 rval = QLA_FUNCTION_FAILED;
1801 rval = qla2x00_configure_fabric(ha);
1805 if (rval == QLA_SUCCESS) {
1806 if (atomic_read(&ha->loop_down_timer) ||
1807 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1808 rval = QLA_FUNCTION_FAILED;
1810 atomic_set(&ha->loop_state, LOOP_READY);
1812 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1817 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1818 __func__, ha->host_no));
1820 DEBUG3(printk("%s: exiting normally\n", __func__));
1823 /* Restore state if a resync event occured during processing */
1824 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1825 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1826 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1827 if (test_bit(RSCN_UPDATE, &save_flags))
1828 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1837 * qla2x00_configure_local_loop
1838 * Updates Fibre Channel Device Database with local loop devices.
1841 * ha = adapter block pointer.
1847 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1852 fc_port_t *fcport, *new_fcport;
1858 uint8_t domain, area, al_pa;
1862 entries = MAX_FIBRE_DEVICES;
1864 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1865 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1867 /* Get list of logged in devices. */
1868 memset(ha->gid_list, 0, GID_LIST_SIZE);
1869 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1871 if (rval != QLA_SUCCESS)
1872 goto cleanup_allocation;
1874 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1875 ha->host_no, entries));
1876 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1877 entries * sizeof(struct gid_list_info)));
1879 /* Allocate temporary fcport for any new fcports discovered. */
1880 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1881 if (new_fcport == NULL) {
1882 rval = QLA_MEMORY_ALLOC_FAILED;
1883 goto cleanup_allocation;
1885 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1888 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1890 list_for_each_entry(fcport, &ha->fcports, list) {
1891 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1892 fcport->port_type != FCT_BROADCAST &&
1893 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1895 DEBUG(printk("scsi(%ld): Marking port lost, "
1897 ha->host_no, fcport->loop_id));
1899 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1900 fcport->flags &= ~FCF_FARP_DONE;
1904 /* Add devices to port list. */
1905 id_iter = (char *)ha->gid_list;
1906 for (index = 0; index < entries; index++) {
1907 domain = ((struct gid_list_info *)id_iter)->domain;
1908 area = ((struct gid_list_info *)id_iter)->area;
1909 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1910 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1911 loop_id = (uint16_t)
1912 ((struct gid_list_info *)id_iter)->loop_id_2100;
1914 loop_id = le16_to_cpu(
1915 ((struct gid_list_info *)id_iter)->loop_id);
1916 id_iter += ha->gid_list_info_size;
1918 /* Bypass reserved domain fields. */
1919 if ((domain & 0xf0) == 0xf0)
1922 /* Bypass if not same domain and area of adapter. */
1923 if (area && domain &&
1924 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
1927 /* Bypass invalid local loop ID. */
1928 if (loop_id > LAST_LOCAL_LOOP_ID)
1931 /* Fill in member data. */
1932 new_fcport->d_id.b.domain = domain;
1933 new_fcport->d_id.b.area = area;
1934 new_fcport->d_id.b.al_pa = al_pa;
1935 new_fcport->loop_id = loop_id;
1936 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1937 if (rval2 != QLA_SUCCESS) {
1938 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1939 "information -- get_port_database=%x, "
1941 ha->host_no, rval2, new_fcport->loop_id));
1942 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
1944 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
1948 /* Check for matching device in port list. */
1951 list_for_each_entry(fcport, &ha->fcports, list) {
1952 if (memcmp(new_fcport->port_name, fcport->port_name,
1956 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1957 FCF_PERSISTENT_BOUND);
1958 fcport->loop_id = new_fcport->loop_id;
1959 fcport->port_type = new_fcport->port_type;
1960 fcport->d_id.b24 = new_fcport->d_id.b24;
1961 memcpy(fcport->node_name, new_fcport->node_name,
1969 /* New device, add to fcports list. */
1970 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1971 list_add_tail(&new_fcport->list, &ha->fcports);
1973 /* Allocate a new replacement fcport. */
1974 fcport = new_fcport;
1975 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1976 if (new_fcport == NULL) {
1977 rval = QLA_MEMORY_ALLOC_FAILED;
1978 goto cleanup_allocation;
1980 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1983 qla2x00_update_fcport(ha, fcport);
1991 if (rval != QLA_SUCCESS) {
1992 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1993 "rval=%x\n", ha->host_no, rval));
1997 ha->device_flags |= DFLG_LOCAL_DEVICES;
1998 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2005 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
2009 qla2x00_mark_all_devices_lost(ha, 0);
2010 list_for_each_entry(fcport, &ha->fcports, list) {
2011 if (fcport->port_type != FCT_TARGET)
2014 qla2x00_update_fcport(ha, fcport);
2019 * qla2x00_update_fcport
2020 * Updates device on list.
2023 * ha = adapter block pointer.
2024 * fcport = port structure pointer.
2034 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2037 fcport->login_retry = 0;
2038 fcport->port_login_retry_count = ha->port_down_retry_count *
2040 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2042 fcport->flags &= ~FCF_LOGIN_NEEDED;
2044 atomic_set(&fcport->state, FCS_ONLINE);
2046 if (ha->flags.init_done)
2047 qla2x00_reg_remote_port(ha, fcport);
2051 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2053 struct fc_rport_identifiers rport_ids;
2054 struct fc_rport *rport;
2055 unsigned long flags;
2058 qla2x00_rport_del(fcport);
2062 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2063 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2064 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2065 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2066 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2067 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2069 qla_printk(KERN_WARNING, ha,
2070 "Unable to allocate fc remote port!\n");
2073 spin_lock_irqsave(&fcport->rport_lock, flags);
2074 fcport->rport = rport;
2075 *((fc_port_t **)rport->dd_data) = fcport;
2076 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2078 rport->supported_classes = fcport->supported_classes;
2080 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2081 if (fcport->port_type == FCT_INITIATOR)
2082 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2083 if (fcport->port_type == FCT_TARGET)
2084 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2085 fc_remote_port_rolechg(rport, rport_ids.roles);
2087 if (rport->scsi_target_id != -1 &&
2088 rport->scsi_target_id < ha->host->max_id)
2089 fcport->os_target_id = rport->scsi_target_id;
2093 * qla2x00_configure_fabric
2094 * Setup SNS devices with loop ID's.
2097 * ha = adapter block pointer.
2104 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2107 fc_port_t *fcport, *fcptemp;
2108 uint16_t next_loopid;
2109 uint16_t mb[MAILBOX_REGISTER_COUNT];
2111 LIST_HEAD(new_fcports);
2113 /* If FL port exists, then SNS is present */
2114 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2115 loop_id = NPH_F_PORT;
2117 loop_id = SNS_FL_PORT;
2118 rval = qla2x00_get_port_name(ha, loop_id, NULL, 0);
2119 if (rval != QLA_SUCCESS) {
2120 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2121 "Port\n", ha->host_no));
2123 ha->device_flags &= ~SWITCH_FOUND;
2124 return (QLA_SUCCESS);
2127 /* Mark devices that need re-synchronization. */
2128 rval2 = qla2x00_device_resync(ha);
2129 if (rval2 == QLA_RSCNS_HANDLED) {
2130 /* No point doing the scan, just continue. */
2131 return (QLA_SUCCESS);
2135 if (ql2xfdmienable &&
2136 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2137 qla2x00_fdmi_register(ha);
2139 /* Ensure we are logged into the SNS. */
2140 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2143 loop_id = SIMPLE_NAME_SERVER;
2144 ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
2145 0xfc, mb, BIT_1 | BIT_0);
2146 if (mb[0] != MBS_COMMAND_COMPLETE) {
2147 DEBUG2(qla_printk(KERN_INFO, ha,
2148 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2149 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2150 mb[0], mb[1], mb[2], mb[6], mb[7]));
2151 return (QLA_SUCCESS);
2154 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2155 if (qla2x00_rft_id(ha)) {
2157 DEBUG2(printk("scsi(%ld): Register FC-4 "
2158 "TYPE failed.\n", ha->host_no));
2160 if (qla2x00_rff_id(ha)) {
2162 DEBUG2(printk("scsi(%ld): Register FC-4 "
2163 "Features failed.\n", ha->host_no));
2165 if (qla2x00_rnn_id(ha)) {
2167 DEBUG2(printk("scsi(%ld): Register Node Name "
2168 "failed.\n", ha->host_no));
2169 } else if (qla2x00_rsnn_nn(ha)) {
2171 DEBUG2(printk("scsi(%ld): Register Symbolic "
2172 "Node Name failed.\n", ha->host_no));
2176 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2177 if (rval != QLA_SUCCESS)
2181 * Logout all previous fabric devices marked lost, except
2184 list_for_each_entry(fcport, &ha->fcports, list) {
2185 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2188 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2191 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2192 qla2x00_mark_device_lost(ha, fcport,
2193 ql2xplogiabsentdevice, 0);
2194 if (fcport->loop_id != FC_NO_LOOP_ID &&
2195 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2196 fcport->port_type != FCT_INITIATOR &&
2197 fcport->port_type != FCT_BROADCAST) {
2198 ha->isp_ops.fabric_logout(ha,
2200 fcport->d_id.b.domain,
2201 fcport->d_id.b.area,
2202 fcport->d_id.b.al_pa);
2203 fcport->loop_id = FC_NO_LOOP_ID;
2208 /* Starting free loop ID. */
2209 next_loopid = ha->min_external_loopid;
2212 * Scan through our port list and login entries that need to be
2215 list_for_each_entry(fcport, &ha->fcports, list) {
2216 if (atomic_read(&ha->loop_down_timer) ||
2217 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2220 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2221 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2224 if (fcport->loop_id == FC_NO_LOOP_ID) {
2225 fcport->loop_id = next_loopid;
2226 rval = qla2x00_find_new_loop_id(ha, fcport);
2227 if (rval != QLA_SUCCESS) {
2228 /* Ran out of IDs to use */
2232 /* Login and update database */
2233 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2236 /* Exit if out of loop IDs. */
2237 if (rval != QLA_SUCCESS) {
2242 * Login and add the new devices to our port list.
2244 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2245 if (atomic_read(&ha->loop_down_timer) ||
2246 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2249 /* Find a new loop ID to use. */
2250 fcport->loop_id = next_loopid;
2251 rval = qla2x00_find_new_loop_id(ha, fcport);
2252 if (rval != QLA_SUCCESS) {
2253 /* Ran out of IDs to use */
2257 /* Remove device from the new list and add it to DB */
2258 list_del(&fcport->list);
2259 list_add_tail(&fcport->list, &ha->fcports);
2261 /* Login and update database */
2262 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2266 /* Free all new device structures not processed. */
2267 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2268 list_del(&fcport->list);
2273 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2274 "rval=%d\n", ha->host_no, rval));
2282 * qla2x00_find_all_fabric_devs
2285 * ha = adapter block pointer.
2286 * dev = database device entry pointer.
2295 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2299 fc_port_t *fcport, *new_fcport, *fcptemp;
2304 int first_dev, last_dev;
2305 port_id_t wrap, nxt_d_id;
2309 /* Try GID_PT to get device list, else GAN. */
2310 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2313 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2314 "on GA_NXT\n", ha->host_no));
2316 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2317 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2320 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2323 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2330 /* Allocate temporary fcport for any new fcports discovered. */
2331 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2332 if (new_fcport == NULL) {
2334 return (QLA_MEMORY_ALLOC_FAILED);
2336 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2338 /* Set start port ID scan at adapter ID. */
2342 /* Starting free loop ID. */
2343 loop_id = ha->min_external_loopid;
2344 for (; loop_id <= ha->last_loop_id; loop_id++) {
2345 if (qla2x00_is_reserved_id(ha, loop_id))
2348 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2353 wrap.b24 = new_fcport->d_id.b24;
2355 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2356 memcpy(new_fcport->node_name,
2357 swl[swl_idx].node_name, WWN_SIZE);
2358 memcpy(new_fcport->port_name,
2359 swl[swl_idx].port_name, WWN_SIZE);
2361 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2367 /* Send GA_NXT to the switch */
2368 rval = qla2x00_ga_nxt(ha, new_fcport);
2369 if (rval != QLA_SUCCESS) {
2370 qla_printk(KERN_WARNING, ha,
2371 "SNS scan failed -- assuming zero-entry "
2373 list_for_each_entry_safe(fcport, fcptemp,
2374 new_fcports, list) {
2375 list_del(&fcport->list);
2383 /* If wrap on switch device list, exit. */
2385 wrap.b24 = new_fcport->d_id.b24;
2387 } else if (new_fcport->d_id.b24 == wrap.b24) {
2388 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2389 ha->host_no, new_fcport->d_id.b.domain,
2390 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2394 /* Bypass if host adapter. */
2395 if (new_fcport->d_id.b24 == ha->d_id.b24)
2398 /* Bypass if same domain and area of adapter. */
2399 if (((new_fcport->d_id.b24 & 0xffff00) ==
2400 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2404 /* Bypass reserved domain fields. */
2405 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2408 /* Locate matching device in database. */
2410 list_for_each_entry(fcport, &ha->fcports, list) {
2411 if (memcmp(new_fcport->port_name, fcport->port_name,
2418 * If address the same and state FCS_ONLINE, nothing
2421 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2422 atomic_read(&fcport->state) == FCS_ONLINE) {
2427 * If device was not a fabric device before.
2429 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2430 fcport->d_id.b24 = new_fcport->d_id.b24;
2431 fcport->loop_id = FC_NO_LOOP_ID;
2432 fcport->flags |= (FCF_FABRIC_DEVICE |
2434 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2439 * Port ID changed or device was marked to be updated;
2440 * Log it out if still logged in and mark it for
2443 fcport->d_id.b24 = new_fcport->d_id.b24;
2444 fcport->flags |= FCF_LOGIN_NEEDED;
2445 if (fcport->loop_id != FC_NO_LOOP_ID &&
2446 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2447 fcport->port_type != FCT_INITIATOR &&
2448 fcport->port_type != FCT_BROADCAST) {
2449 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2450 fcport->d_id.b.domain, fcport->d_id.b.area,
2451 fcport->d_id.b.al_pa);
2452 fcport->loop_id = FC_NO_LOOP_ID;
2461 /* If device was not in our fcports list, then add it. */
2462 list_add_tail(&new_fcport->list, new_fcports);
2464 /* Allocate a new replacement fcport. */
2465 nxt_d_id.b24 = new_fcport->d_id.b24;
2466 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2467 if (new_fcport == NULL) {
2469 return (QLA_MEMORY_ALLOC_FAILED);
2471 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2472 new_fcport->d_id.b24 = nxt_d_id.b24;
2478 if (!list_empty(new_fcports))
2479 ha->device_flags |= DFLG_FABRIC_DEVICES;
2485 * qla2x00_find_new_loop_id
2486 * Scan through our port list and find a new usable loop ID.
2489 * ha: adapter state pointer.
2490 * dev: port structure pointer.
2493 * qla2x00 local function return status code.
2499 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2504 uint16_t first_loop_id;
2508 /* Save starting loop ID. */
2509 first_loop_id = dev->loop_id;
2512 /* Skip loop ID if already used by adapter. */
2513 if (dev->loop_id == ha->loop_id) {
2517 /* Skip reserved loop IDs. */
2518 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2522 /* Reset loop ID if passed the end. */
2523 if (dev->loop_id > ha->last_loop_id) {
2524 /* first loop ID. */
2525 dev->loop_id = ha->min_external_loopid;
2528 /* Check for loop ID being already in use. */
2531 list_for_each_entry(fcport, &ha->fcports, list) {
2532 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2533 /* ID possibly in use */
2539 /* If not in use then it is free to use. */
2544 /* ID in use. Try next value. */
2547 /* If wrap around. No free ID to use. */
2548 if (dev->loop_id == first_loop_id) {
2549 dev->loop_id = FC_NO_LOOP_ID;
2550 rval = QLA_FUNCTION_FAILED;
2559 * qla2x00_device_resync
2560 * Marks devices in the database that needs resynchronization.
2563 * ha = adapter block pointer.
2569 qla2x00_device_resync(scsi_qla_host_t *ha)
2574 uint32_t rscn_entry;
2575 uint8_t rscn_out_iter;
2579 rval = QLA_RSCNS_HANDLED;
2581 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2582 ha->flags.rscn_queue_overflow) {
2584 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2585 format = MSB(MSW(rscn_entry));
2586 d_id.b.domain = LSB(MSW(rscn_entry));
2587 d_id.b.area = MSB(LSW(rscn_entry));
2588 d_id.b.al_pa = LSB(LSW(rscn_entry));
2590 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2591 "[%02x/%02x%02x%02x].\n",
2592 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2593 d_id.b.area, d_id.b.al_pa));
2596 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2597 ha->rscn_out_ptr = 0;
2599 /* Skip duplicate entries. */
2600 for (rscn_out_iter = ha->rscn_out_ptr;
2601 !ha->flags.rscn_queue_overflow &&
2602 rscn_out_iter != ha->rscn_in_ptr;
2603 rscn_out_iter = (rscn_out_iter ==
2604 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2606 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2609 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2610 "entry found at [%d].\n", ha->host_no,
2613 ha->rscn_out_ptr = rscn_out_iter;
2616 /* Queue overflow, set switch default case. */
2617 if (ha->flags.rscn_queue_overflow) {
2618 DEBUG(printk("scsi(%ld): device_resync: rscn "
2619 "overflow.\n", ha->host_no));
2622 ha->flags.rscn_queue_overflow = 0;
2638 ha->rscn_out_ptr = ha->rscn_in_ptr;
2644 list_for_each_entry(fcport, &ha->fcports, list) {
2645 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2646 (fcport->d_id.b24 & mask) != d_id.b24 ||
2647 fcport->port_type == FCT_BROADCAST)
2650 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2652 fcport->port_type != FCT_INITIATOR) {
2653 qla2x00_mark_device_lost(ha, fcport,
2657 fcport->flags &= ~FCF_FARP_DONE;
2664 * qla2x00_fabric_dev_login
2665 * Login fabric target device and update FC port database.
2668 * ha: adapter state pointer.
2669 * fcport: port structure list pointer.
2670 * next_loopid: contains value of a new loop ID that can be used
2671 * by the next login attempt.
2674 * qla2x00 local function return status code.
2680 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2681 uint16_t *next_loopid)
2690 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2691 if (rval == QLA_SUCCESS) {
2692 /* Send an ADISC to tape devices.*/
2694 if (fcport->flags & FCF_TAPE_PRESENT)
2696 rval = qla2x00_get_port_database(ha, fcport, opts);
2697 if (rval != QLA_SUCCESS) {
2698 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2699 fcport->d_id.b.domain, fcport->d_id.b.area,
2700 fcport->d_id.b.al_pa);
2701 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2703 qla2x00_update_fcport(ha, fcport);
2711 * qla2x00_fabric_login
2712 * Issue fabric login command.
2715 * ha = adapter block pointer.
2716 * device = pointer to FC device type structure.
2719 * 0 - Login successfully
2721 * 2 - Initiator device
2725 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2726 uint16_t *next_loopid)
2730 uint16_t tmp_loopid;
2731 uint16_t mb[MAILBOX_REGISTER_COUNT];
2737 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2738 "for port %02x%02x%02x.\n",
2739 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2740 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2742 /* Login fcport on switch. */
2743 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2744 fcport->d_id.b.domain, fcport->d_id.b.area,
2745 fcport->d_id.b.al_pa, mb, BIT_0);
2746 if (mb[0] == MBS_PORT_ID_USED) {
2748 * Device has another loop ID. The firmware team
2749 * recommends the driver perform an implicit login with
2750 * the specified ID again. The ID we just used is save
2751 * here so we return with an ID that can be tried by
2755 tmp_loopid = fcport->loop_id;
2756 fcport->loop_id = mb[1];
2758 DEBUG(printk("Fabric Login: port in use - next "
2759 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2760 fcport->loop_id, fcport->d_id.b.domain,
2761 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2763 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2768 /* A retry occurred before. */
2769 *next_loopid = tmp_loopid;
2772 * No retry occurred before. Just increment the
2773 * ID value for next login.
2775 *next_loopid = (fcport->loop_id + 1);
2778 if (mb[1] & BIT_0) {
2779 fcport->port_type = FCT_INITIATOR;
2781 fcport->port_type = FCT_TARGET;
2782 if (mb[1] & BIT_1) {
2783 fcport->flags |= FCF_TAPE_PRESENT;
2788 fcport->supported_classes |= FC_COS_CLASS2;
2790 fcport->supported_classes |= FC_COS_CLASS3;
2794 } else if (mb[0] == MBS_LOOP_ID_USED) {
2796 * Loop ID already used, try next loop ID.
2799 rval = qla2x00_find_new_loop_id(ha, fcport);
2800 if (rval != QLA_SUCCESS) {
2801 /* Ran out of loop IDs to use */
2804 } else if (mb[0] == MBS_COMMAND_ERROR) {
2806 * Firmware possibly timed out during login. If NO
2807 * retries are left to do then the device is declared
2810 *next_loopid = fcport->loop_id;
2811 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2812 fcport->d_id.b.domain, fcport->d_id.b.area,
2813 fcport->d_id.b.al_pa);
2814 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2820 * unrecoverable / not handled error
2822 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2823 "loop_id=%x jiffies=%lx.\n",
2824 __func__, ha->host_no, mb[0],
2825 fcport->d_id.b.domain, fcport->d_id.b.area,
2826 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2828 *next_loopid = fcport->loop_id;
2829 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2830 fcport->d_id.b.domain, fcport->d_id.b.area,
2831 fcport->d_id.b.al_pa);
2832 fcport->loop_id = FC_NO_LOOP_ID;
2833 fcport->login_retry = 0;
2844 * qla2x00_local_device_login
2845 * Issue local device login command.
2848 * ha = adapter block pointer.
2849 * loop_id = loop id of device to login to.
2851 * Returns (Where's the #define!!!!):
2852 * 0 - Login successfully
2857 qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
2860 uint16_t mb[MAILBOX_REGISTER_COUNT];
2862 memset(mb, 0, sizeof(mb));
2863 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
2864 if (rval == QLA_SUCCESS) {
2865 /* Interrogate mailbox registers for any errors */
2866 if (mb[0] == MBS_COMMAND_ERROR)
2868 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
2869 /* device not in PCB table */
2877 * qla2x00_loop_resync
2878 * Resync with fibre channel devices.
2881 * ha = adapter block pointer.
2887 qla2x00_loop_resync(scsi_qla_host_t *ha)
2894 atomic_set(&ha->loop_state, LOOP_UPDATE);
2895 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2896 if (ha->flags.online) {
2897 if (!(rval = qla2x00_fw_ready(ha))) {
2898 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2901 atomic_set(&ha->loop_state, LOOP_UPDATE);
2903 /* Issue a marker after FW becomes ready. */
2904 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
2905 ha->marker_needed = 0;
2907 /* Remap devices on Loop. */
2908 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2910 qla2x00_configure_loop(ha);
2912 } while (!atomic_read(&ha->loop_down_timer) &&
2913 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
2915 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
2919 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2920 return (QLA_FUNCTION_FAILED);
2924 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
2931 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
2937 list_for_each_entry(fcport, &ha->fcports, list) {
2938 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
2941 qla2x00_update_fcport(ha, fcport);
2942 fcport->flags &= ~FCF_RESCAN_NEEDED;
2946 qla2x00_probe_for_all_luns(ha);
2950 qla2x00_update_fcports(scsi_qla_host_t *ha)
2954 /* Go with deferred removal of rport references. */
2955 list_for_each_entry(fcport, &ha->fcports, list)
2957 qla2x00_rport_del(fcport);
2962 * Resets ISP and aborts all outstanding commands.
2965 * ha = adapter block pointer.
2971 qla2x00_abort_isp(scsi_qla_host_t *ha)
2973 unsigned long flags = 0;
2978 if (ha->flags.online) {
2979 ha->flags.online = 0;
2980 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2982 qla_printk(KERN_INFO, ha,
2983 "Performing ISP error recovery - ha= %p.\n", ha);
2984 ha->isp_ops.reset_chip(ha);
2986 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
2987 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
2988 atomic_set(&ha->loop_state, LOOP_DOWN);
2989 qla2x00_mark_all_devices_lost(ha, 0);
2991 if (!atomic_read(&ha->loop_down_timer))
2992 atomic_set(&ha->loop_down_timer,
2996 spin_lock_irqsave(&ha->hardware_lock, flags);
2997 /* Requeue all commands in outstanding command list. */
2998 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
2999 sp = ha->outstanding_cmds[cnt];
3001 ha->outstanding_cmds[cnt] = NULL;
3003 sp->cmd->result = DID_RESET << 16;
3004 sp->cmd->host_scribble = (unsigned char *)NULL;
3005 qla2x00_sp_compl(ha, sp);
3008 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3010 ha->isp_ops.nvram_config(ha);
3012 if (!qla2x00_restart_isp(ha)) {
3013 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3015 if (!atomic_read(&ha->loop_down_timer)) {
3017 * Issue marker command only when we are going
3018 * to start the I/O .
3020 ha->marker_needed = 1;
3023 ha->flags.online = 1;
3025 ha->isp_ops.enable_intrs(ha);
3027 ha->isp_abort_cnt = 0;
3028 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3029 } else { /* failed the ISP abort */
3030 ha->flags.online = 1;
3031 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3032 if (ha->isp_abort_cnt == 0) {
3033 qla_printk(KERN_WARNING, ha,
3034 "ISP error recovery failed - "
3035 "board disabled\n");
3037 * The next call disables the board
3040 ha->isp_ops.reset_adapter(ha);
3041 ha->flags.online = 0;
3042 clear_bit(ISP_ABORT_RETRY,
3045 } else { /* schedule another ISP abort */
3046 ha->isp_abort_cnt--;
3047 DEBUG(printk("qla%ld: ISP abort - "
3048 "retry remaining %d\n",
3049 ha->host_no, ha->isp_abort_cnt);)
3053 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3054 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3055 "- retrying (%d) more times\n",
3056 ha->host_no, ha->isp_abort_cnt);)
3057 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3065 qla_printk(KERN_INFO, ha,
3066 "qla2x00_abort_isp: **** FAILED ****\n");
3068 DEBUG(printk(KERN_INFO
3069 "qla2x00_abort_isp(%ld): exiting.\n",
3077 * qla2x00_restart_isp
3078 * restarts the ISP after a reset
3081 * ha = adapter block pointer.
3087 qla2x00_restart_isp(scsi_qla_host_t *ha)
3090 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3091 unsigned long flags = 0;
3094 /* If firmware needs to be loaded */
3095 if (qla2x00_isp_firmware(ha)) {
3096 ha->flags.online = 0;
3097 if (!(status = ha->isp_ops.chip_diag(ha))) {
3098 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3099 status = qla2x00_setup_chip(ha);
3103 spin_lock_irqsave(&ha->hardware_lock, flags);
3105 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3107 * Disable SRAM, Instruction RAM and GP RAM
3110 WRT_REG_WORD(®->hccr,
3111 (HCCR_ENABLE_PARITY + 0x0));
3112 RD_REG_WORD(®->hccr);
3115 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3117 status = qla2x00_setup_chip(ha);
3119 spin_lock_irqsave(&ha->hardware_lock, flags);
3121 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3122 /* Enable proper parity */
3125 WRT_REG_WORD(®->hccr,
3126 (HCCR_ENABLE_PARITY + 0x1));
3129 * SRAM, Instruction RAM and GP RAM
3132 WRT_REG_WORD(®->hccr,
3133 (HCCR_ENABLE_PARITY + 0x7));
3134 RD_REG_WORD(®->hccr);
3137 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3142 if (!status && !(status = qla2x00_init_rings(ha))) {
3143 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3144 if (!(status = qla2x00_fw_ready(ha))) {
3145 DEBUG(printk("%s(): Start configure loop, "
3146 "status = %d\n", __func__, status);)
3148 /* Issue a marker after FW becomes ready. */
3149 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3151 ha->flags.online = 1;
3152 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3155 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3156 qla2x00_configure_loop(ha);
3158 } while (!atomic_read(&ha->loop_down_timer) &&
3159 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3161 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3164 /* if no cable then assume it's good */
3165 if ((ha->device_flags & DFLG_NO_CABLE))
3168 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3176 * qla2x00_reset_adapter
3180 * ha = adapter block pointer.
3183 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3185 unsigned long flags = 0;
3186 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3188 ha->flags.online = 0;
3189 ha->isp_ops.disable_intrs(ha);
3191 spin_lock_irqsave(&ha->hardware_lock, flags);
3192 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3193 RD_REG_WORD(®->hccr); /* PCI Posting. */
3194 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3195 RD_REG_WORD(®->hccr); /* PCI Posting. */
3196 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3200 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3202 unsigned long flags = 0;
3203 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3205 ha->flags.online = 0;
3206 ha->isp_ops.disable_intrs(ha);
3208 spin_lock_irqsave(&ha->hardware_lock, flags);
3209 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3210 RD_REG_DWORD(®->hccr);
3211 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3212 RD_REG_DWORD(®->hccr);
3213 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3217 qla24xx_nvram_config(scsi_qla_host_t *ha)
3220 struct init_cb_24xx *icb;
3221 struct nvram_24xx *nv;
3223 uint8_t *dptr1, *dptr2;
3228 icb = (struct init_cb_24xx *)ha->init_cb;
3229 nv = (struct nvram_24xx *)ha->request_ring;
3231 /* Determine NVRAM starting address. */
3232 ha->nvram_size = sizeof(struct nvram_24xx);
3233 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3234 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3235 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3236 if (PCI_FUNC(ha->pdev->devfn)) {
3237 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3238 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3241 /* Get NVRAM data and calculate checksum. */
3242 dptr = (uint32_t *)nv;
3243 ha->isp_ops.read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3245 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3246 chksum += le32_to_cpu(*dptr++);
3248 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3249 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3252 /* Bad NVRAM data, set defaults parameters. */
3253 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3254 || nv->id[3] != ' ' ||
3255 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3256 /* Reset NVRAM data. */
3257 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3258 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3259 le16_to_cpu(nv->nvram_version));
3260 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3261 "invalid -- WWPN) defaults.\n");
3264 * Set default initialization control block.
3266 memset(nv, 0, ha->nvram_size);
3267 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3268 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3269 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3270 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3271 nv->exchange_count = __constant_cpu_to_le16(0);
3272 nv->hard_address = __constant_cpu_to_le16(124);
3273 nv->port_name[0] = 0x21;
3274 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3275 nv->port_name[2] = 0x00;
3276 nv->port_name[3] = 0xe0;
3277 nv->port_name[4] = 0x8b;
3278 nv->port_name[5] = 0x1c;
3279 nv->port_name[6] = 0x55;
3280 nv->port_name[7] = 0x86;
3281 nv->node_name[0] = 0x20;
3282 nv->node_name[1] = 0x00;
3283 nv->node_name[2] = 0x00;
3284 nv->node_name[3] = 0xe0;
3285 nv->node_name[4] = 0x8b;
3286 nv->node_name[5] = 0x1c;
3287 nv->node_name[6] = 0x55;
3288 nv->node_name[7] = 0x86;
3289 nv->login_retry_count = __constant_cpu_to_le16(8);
3290 nv->link_down_timeout = __constant_cpu_to_le16(200);
3291 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3292 nv->login_timeout = __constant_cpu_to_le16(0);
3293 nv->firmware_options_1 =
3294 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3295 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3296 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3297 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3298 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3299 nv->efi_parameters = __constant_cpu_to_le32(0);
3300 nv->reset_delay = 5;
3301 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3302 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3303 nv->link_down_timeout = __constant_cpu_to_le16(30);
3308 /* Reset Initialization control block */
3309 memset(icb, 0, sizeof(struct init_cb_24xx));
3311 /* Copy 1st segment. */
3312 dptr1 = (uint8_t *)icb;
3313 dptr2 = (uint8_t *)&nv->version;
3314 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3316 *dptr1++ = *dptr2++;
3318 icb->login_retry_count = nv->login_retry_count;
3319 icb->link_down_timeout = nv->link_down_timeout;
3321 /* Copy 2nd segment. */
3322 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3323 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3324 cnt = (uint8_t *)&icb->reserved_3 -
3325 (uint8_t *)&icb->interrupt_delay_timer;
3327 *dptr1++ = *dptr2++;
3330 * Setup driver NVRAM options.
3332 if (memcmp(nv->model_name, BINZERO, sizeof(nv->model_name)) != 0) {
3336 strncpy(ha->model_number, nv->model_name,
3337 sizeof(nv->model_name));
3338 st = en = ha->model_number;
3339 en += sizeof(nv->model_name) - 1;
3341 if (*en != 0x20 && *en != 0x00)
3346 index = (ha->pdev->subsystem_device & 0xff);
3347 if (index < QLA_MODEL_NAMES)
3348 ha->model_desc = qla2x00_model_name[index * 2 + 1];
3350 strcpy(ha->model_number, "QLA2462");
3352 /* Use alternate WWN? */
3353 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3354 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3355 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3358 /* Prepare nodename */
3359 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3361 * Firmware will apply the following mask if the nodename was
3364 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3365 icb->node_name[0] &= 0xF0;
3368 /* Set host adapter parameters. */
3369 ha->flags.disable_risc_code_load = 0;
3370 ha->flags.enable_lip_reset = 1;
3371 ha->flags.enable_lip_full_login = 1;
3372 ha->flags.enable_target_reset = 1;
3373 ha->flags.enable_led_scheme = 0;
3375 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3376 (BIT_6 | BIT_5 | BIT_4)) >> 4;
3378 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3379 sizeof(ha->fw_seriallink_options24));
3381 /* save HBA serial number */
3382 ha->serial0 = icb->port_name[5];
3383 ha->serial1 = icb->port_name[6];
3384 ha->serial2 = icb->port_name[7];
3385 ha->node_name = icb->node_name;
3386 ha->port_name = icb->port_name;
3388 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3390 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3392 /* Set minimum login_timeout to 4 seconds. */
3393 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3394 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3395 if (le16_to_cpu(nv->login_timeout) < 4)
3396 nv->login_timeout = __constant_cpu_to_le16(4);
3397 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3398 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3400 /* Set minimum RATOV to 200 tenths of a second. */
3403 ha->loop_reset_delay = nv->reset_delay;
3405 /* Link Down Timeout = 0:
3407 * When Port Down timer expires we will start returning
3408 * I/O's to OS with "DID_NO_CONNECT".
3410 * Link Down Timeout != 0:
3412 * The driver waits for the link to come up after link down
3413 * before returning I/Os to OS with "DID_NO_CONNECT".
3415 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3416 ha->loop_down_abort_time =
3417 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3419 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3420 ha->loop_down_abort_time =
3421 (LOOP_DOWN_TIME - ha->link_down_timeout);
3424 /* Need enough time to try and get the port back. */
3425 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3426 if (qlport_down_retry)
3427 ha->port_down_retry_count = qlport_down_retry;
3429 /* Set login_retry_count */
3430 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3431 if (ha->port_down_retry_count ==
3432 le16_to_cpu(nv->port_down_retry_count) &&
3433 ha->port_down_retry_count > 3)
3434 ha->login_retry_count = ha->port_down_retry_count;
3435 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3436 ha->login_retry_count = ha->port_down_retry_count;
3437 if (ql2xloginretrycount)
3438 ha->login_retry_count = ql2xloginretrycount;
3441 if (!ha->flags.init_done) {
3442 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3443 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3444 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3445 le16_to_cpu(icb->interrupt_delay_timer): 2;
3447 icb->firmware_options_2 &= __constant_cpu_to_le32(
3448 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3449 ha->flags.process_response_queue = 0;
3450 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3451 ha->zio_mode = QLA_ZIO_MODE_6;
3453 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3454 "(%d us).\n", ha->host_no, ha->zio_mode,
3455 ha->zio_timer * 100));
3456 qla_printk(KERN_INFO, ha,
3457 "ZIO mode %d enabled; timer delay (%d us).\n",
3458 ha->zio_mode, ha->zio_timer * 100);
3460 icb->firmware_options_2 |= cpu_to_le32(
3461 (uint32_t)ha->zio_mode);
3462 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3463 ha->flags.process_response_queue = 1;
3467 DEBUG2_3(printk(KERN_WARNING
3468 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3474 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3477 int segments, fragment;
3479 uint32_t *dcode, dlen;
3486 segments = FA_RISC_CODE_SEGMENTS;
3487 faddr = FA_RISC_CODE_ADDR;
3488 dcode = (uint32_t *)ha->request_ring;
3491 /* Validate firmware image by checking version. */
3492 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3493 for (i = 0; i < 4; i++)
3494 dcode[i] = be32_to_cpu(dcode[i]);
3495 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3496 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3497 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3499 qla_printk(KERN_WARNING, ha,
3500 "Unable to verify integrity of flash firmware image!\n");
3501 qla_printk(KERN_WARNING, ha,
3502 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3503 dcode[1], dcode[2], dcode[3]);
3505 return QLA_FUNCTION_FAILED;
3508 while (segments && rval == QLA_SUCCESS) {
3509 /* Read segment's load information. */
3510 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3512 risc_addr = be32_to_cpu(dcode[2]);
3513 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3514 risc_size = be32_to_cpu(dcode[3]);
3517 while (risc_size > 0 && rval == QLA_SUCCESS) {
3518 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3519 if (dlen > risc_size)
3522 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3523 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3524 ha->host_no, risc_addr, dlen, faddr));
3526 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3527 for (i = 0; i < dlen; i++)
3528 dcode[i] = swab32(dcode[i]);
3530 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3533 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3534 "segment %d of firmware\n", ha->host_no,
3536 qla_printk(KERN_WARNING, ha,
3537 "[ERROR] Failed to load segment %d of "
3538 "firmware\n", fragment);
3555 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3558 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3562 uint16_t *wcode, *fwcode;
3563 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3564 struct fw_blob *blob;
3566 /* Load firmware blob. */
3567 blob = qla2x00_request_firmware(ha);
3569 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3570 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3571 "from: " QLA_FW_URL ".\n");
3572 return QLA_FUNCTION_FAILED;
3577 wcode = (uint16_t *)ha->request_ring;
3579 fwcode = (uint16_t *)blob->fw->data;
3582 /* Validate firmware image by checking version. */
3583 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3584 qla_printk(KERN_WARNING, ha,
3585 "Unable to verify integrity of firmware image (%Zd)!\n",
3587 goto fail_fw_integrity;
3589 for (i = 0; i < 4; i++)
3590 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3591 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3592 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3593 wcode[2] == 0 && wcode[3] == 0)) {
3594 qla_printk(KERN_WARNING, ha,
3595 "Unable to verify integrity of firmware image!\n");
3596 qla_printk(KERN_WARNING, ha,
3597 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3598 wcode[1], wcode[2], wcode[3]);
3599 goto fail_fw_integrity;
3603 while (*seg && rval == QLA_SUCCESS) {
3605 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3606 risc_size = be16_to_cpu(fwcode[3]);
3608 /* Validate firmware image size. */
3609 fwclen += risc_size * sizeof(uint16_t);
3610 if (blob->fw->size < fwclen) {
3611 qla_printk(KERN_WARNING, ha,
3612 "Unable to verify integrity of firmware image "
3613 "(%Zd)!\n", blob->fw->size);
3614 goto fail_fw_integrity;
3618 while (risc_size > 0 && rval == QLA_SUCCESS) {
3619 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3620 if (wlen > risc_size)
3623 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3624 "addr %x, number of words 0x%x.\n", ha->host_no,
3627 for (i = 0; i < wlen; i++)
3628 wcode[i] = swab16(fwcode[i]);
3630 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3633 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3634 "segment %d of firmware\n", ha->host_no,
3636 qla_printk(KERN_WARNING, ha,
3637 "[ERROR] Failed to load segment %d of "
3638 "firmware\n", fragment);
3654 return QLA_FUNCTION_FAILED;
3658 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3661 int segments, fragment;
3662 uint32_t *dcode, dlen;
3666 struct fw_blob *blob;
3667 uint32_t *fwcode, fwclen;
3669 /* Load firmware blob. */
3670 blob = qla2x00_request_firmware(ha);
3672 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3673 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3674 "from: " QLA_FW_URL ".\n");
3676 /* Try to load RISC code from flash. */
3677 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3678 "outdated) firmware from flash.\n");
3679 return qla24xx_load_risc_flash(ha, srisc_addr);
3684 segments = FA_RISC_CODE_SEGMENTS;
3685 dcode = (uint32_t *)ha->request_ring;
3687 fwcode = (uint32_t *)blob->fw->data;
3690 /* Validate firmware image by checking version. */
3691 if (blob->fw->size < 8 * sizeof(uint32_t)) {
3692 qla_printk(KERN_WARNING, ha,
3693 "Unable to verify integrity of firmware image (%Zd)!\n",
3695 goto fail_fw_integrity;
3697 for (i = 0; i < 4; i++)
3698 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3699 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3700 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3701 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3703 qla_printk(KERN_WARNING, ha,
3704 "Unable to verify integrity of firmware image!\n");
3705 qla_printk(KERN_WARNING, ha,
3706 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3707 dcode[1], dcode[2], dcode[3]);
3708 goto fail_fw_integrity;
3711 while (segments && rval == QLA_SUCCESS) {
3712 risc_addr = be32_to_cpu(fwcode[2]);
3713 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3714 risc_size = be32_to_cpu(fwcode[3]);
3716 /* Validate firmware image size. */
3717 fwclen += risc_size * sizeof(uint32_t);
3718 if (blob->fw->size < fwclen) {
3719 qla_printk(KERN_WARNING, ha,
3720 "Unable to verify integrity of firmware image "
3721 "(%Zd)!\n", blob->fw->size);
3723 goto fail_fw_integrity;
3727 while (risc_size > 0 && rval == QLA_SUCCESS) {
3728 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3729 if (dlen > risc_size)
3732 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3733 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3736 for (i = 0; i < dlen; i++)
3737 dcode[i] = swab32(fwcode[i]);
3739 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3742 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3743 "segment %d of firmware\n", ha->host_no,
3745 qla_printk(KERN_WARNING, ha,
3746 "[ERROR] Failed to load segment %d of "
3747 "firmware\n", fragment);
3763 return QLA_FUNCTION_FAILED;