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)))
22 #ifdef FC_TARGET_SUPPORT
23 #include "qla2x_tgt.h"
27 * QLogic ISP2x00 Hardware Support Function Prototypes.
29 static int qla2x00_isp_firmware(scsi_qla_host_t *);
30 static void qla2x00_resize_request_q(scsi_qla_host_t *);
31 static int qla2x00_setup_chip(scsi_qla_host_t *);
32 static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
33 static int qla2x00_init_rings(scsi_qla_host_t *);
34 static int qla2x00_fw_ready(scsi_qla_host_t *);
35 static int qla2x00_configure_hba(scsi_qla_host_t *);
36 int qla2x00_configure_loop(scsi_qla_host_t *);
37 int qla2x00_configure_local_loop(scsi_qla_host_t *);
38 int qla2x00_configure_fabric(scsi_qla_host_t *);
39 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
40 static int qla2x00_device_resync(scsi_qla_host_t *);
41 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *, uint16_t *);
43 static int qla2x00_restart_isp(scsi_qla_host_t *);
45 /****************************************************************************/
46 /* QLogic ISP2x00 Hardware Support Functions. */
47 /****************************************************************************/
50 * qla2x00_initialize_adapter
54 * ha = adapter block pointer.
60 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
63 uint8_t restart_risc = 0;
67 /* Clear adapter flags. */
69 ha->flags.reset_active = 0;
70 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
71 atomic_set(&ha->loop_state, LOOP_DOWN);
74 ha->flags.management_server_logged_in = 0;
75 ha->marker_needed = 0;
77 ha->isp_abort_cnt = 0;
78 ha->beacon_blink_led = 0;
79 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
81 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
82 rval = ha->isp_ops.pci_config(ha);
84 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
89 ha->isp_ops.reset_chip(ha);
91 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
93 ha->isp_ops.nvram_config(ha);
95 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
99 * Try to configure the loop.
104 /* If firmware needs to be loaded */
105 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
106 if ((rval = ha->isp_ops.chip_diag(ha)) == QLA_SUCCESS) {
107 rval = qla2x00_setup_chip(ha);
111 if (rval == QLA_SUCCESS &&
112 (rval = qla2x00_init_rings(ha)) == QLA_SUCCESS) {
113 check_fw_ready_again:
115 * Wait for a successful LIP up to a maximum
116 * of (in seconds): RISC login timeout value,
117 * RISC retry count value, and port down retry
118 * value OR a minimum of 4 seconds OR If no
119 * cable, only 5 seconds.
121 rval = qla2x00_fw_ready(ha);
122 if (rval == QLA_SUCCESS) {
123 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
125 /* Issue a marker after FW becomes ready. */
126 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
129 * Wait at most MAX_TARGET RSCNs for a stable
134 clear_bit(LOOP_RESYNC_NEEDED,
136 rval = qla2x00_configure_loop(ha);
138 if (test_and_clear_bit(ISP_ABORT_NEEDED,
145 * If loop state change while we were
146 * discoverying devices then wait for
150 if (atomic_read(&ha->loop_state) !=
151 LOOP_READY && retry--) {
152 goto check_fw_ready_again;
155 } while (!atomic_read(&ha->loop_down_timer) &&
158 (test_bit(LOOP_RESYNC_NEEDED,
162 rval = QLA_FUNCTION_FAILED;
163 } else if (ha->device_flags & DFLG_NO_CABLE)
164 /* If no cable, then all is good. */
167 } while (restart_risc && retry--);
169 if (rval == QLA_SUCCESS) {
170 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
171 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
172 ha->marker_needed = 0;
174 ha->flags.online = 1;
176 #ifdef FC_TARGET_SUPPORT
177 /* Enable target response to SCSI bus. */
178 if (ha->flags.enable_target_mode) {
179 qla2x00_enable_lun(ha);
181 qla2x00_disable_lun(ha);
186 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
193 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
196 * Returns 0 on success.
199 qla2100_pci_config(scsi_qla_host_t *ha)
204 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
206 pci_set_master(ha->pdev);
208 if (pci_set_mwi(ha->pdev))
209 mwi = PCI_COMMAND_INVALIDATE;
210 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
212 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
213 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
214 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
216 /* Reset expansion ROM address decode enable */
217 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
218 d &= ~PCI_ROM_ADDRESS_ENABLE;
219 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
221 /* Get PCI bus information. */
222 spin_lock_irqsave(&ha->hardware_lock, flags);
223 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
224 spin_unlock_irqrestore(&ha->hardware_lock, flags);
230 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
233 * Returns 0 on success.
236 qla2300_pci_config(scsi_qla_host_t *ha)
240 unsigned long flags = 0;
242 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
244 pci_set_master(ha->pdev);
246 if (pci_set_mwi(ha->pdev))
247 mwi = PCI_COMMAND_INVALIDATE;
248 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
250 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
251 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
253 if (IS_QLA2322(ha) || IS_QLA6322(ha))
254 w &= ~PCI_COMMAND_INTX_DISABLE;
257 * If this is a 2300 card and not 2312, reset the
258 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
259 * the 2310 also reports itself as a 2300 so we need to get the
260 * fb revision level -- a 6 indicates it really is a 2300 and
263 if (IS_QLA2300(ha)) {
264 spin_lock_irqsave(&ha->hardware_lock, flags);
267 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
268 for (cnt = 0; cnt < 30000; cnt++) {
269 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
275 /* Select FPM registers. */
276 WRT_REG_WORD(®->ctrl_status, 0x20);
277 RD_REG_WORD(®->ctrl_status);
279 /* Get the fb rev level */
280 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
282 if (ha->fb_rev == FPM_2300)
283 w &= ~PCI_COMMAND_INVALIDATE;
285 /* Deselect FPM registers. */
286 WRT_REG_WORD(®->ctrl_status, 0x0);
287 RD_REG_WORD(®->ctrl_status);
289 /* Release RISC module. */
290 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
291 for (cnt = 0; cnt < 30000; cnt++) {
292 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
298 spin_unlock_irqrestore(&ha->hardware_lock, flags);
300 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
302 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
304 /* Reset expansion ROM address decode enable */
305 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
306 d &= ~PCI_ROM_ADDRESS_ENABLE;
307 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
309 /* Get PCI bus information. */
310 spin_lock_irqsave(&ha->hardware_lock, flags);
311 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
312 spin_unlock_irqrestore(&ha->hardware_lock, flags);
318 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
321 * Returns 0 on success.
324 qla24xx_pci_config(scsi_qla_host_t *ha)
328 unsigned long flags = 0;
329 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
330 int pcix_cmd_reg, pcie_dctl_reg;
332 pci_set_master(ha->pdev);
334 if (pci_set_mwi(ha->pdev))
335 mwi = PCI_COMMAND_INVALIDATE;
336 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
338 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
339 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
340 w &= ~PCI_COMMAND_INTX_DISABLE;
341 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
343 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
345 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
346 pcix_cmd_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX);
350 pcix_cmd_reg += PCI_X_CMD;
351 pci_read_config_word(ha->pdev, pcix_cmd_reg, &pcix_cmd);
352 pcix_cmd &= ~PCI_X_CMD_MAX_READ;
354 pci_write_config_word(ha->pdev, pcix_cmd_reg, pcix_cmd);
357 /* PCIe -- adjust Maximum Read Request Size (2048). */
358 pcie_dctl_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
362 pcie_dctl_reg += PCI_EXP_DEVCTL;
363 pci_read_config_word(ha->pdev, pcie_dctl_reg, &pcie_dctl);
364 pcie_dctl &= ~PCI_EXP_DEVCTL_READRQ;
366 pci_write_config_word(ha->pdev, pcie_dctl_reg, pcie_dctl);
369 /* Reset expansion ROM address decode enable */
370 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
371 d &= ~PCI_ROM_ADDRESS_ENABLE;
372 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
374 /* Get PCI bus information. */
375 spin_lock_irqsave(&ha->hardware_lock, flags);
376 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
377 spin_unlock_irqrestore(&ha->hardware_lock, flags);
383 * qla2x00_isp_firmware() - Choose firmware image.
386 * Returns 0 on success.
389 qla2x00_isp_firmware(scsi_qla_host_t *ha)
393 /* Assume loading risc code */
394 rval = QLA_FUNCTION_FAILED;
396 if (ha->flags.disable_risc_code_load) {
397 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
399 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
401 /* Verify checksum of loaded RISC code. */
402 rval = qla2x00_verify_checksum(ha,
403 IS_QLA24XX(ha) || IS_QLA54XX(ha) ? RISC_SADDRESS :
404 *ha->brd_info->fw_info[0].fwstart);
408 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
416 * qla2x00_reset_chip() - Reset ISP chip.
419 * Returns 0 on success.
422 qla2x00_reset_chip(scsi_qla_host_t *ha)
424 unsigned long flags = 0;
425 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
427 unsigned long mbx_flags = 0;
430 ha->isp_ops.disable_intrs(ha);
432 spin_lock_irqsave(&ha->hardware_lock, flags);
434 /* Turn off master enable */
436 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
437 cmd &= ~PCI_COMMAND_MASTER;
438 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
440 if (!IS_QLA2100(ha)) {
442 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
443 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
444 for (cnt = 0; cnt < 30000; cnt++) {
445 if ((RD_REG_WORD(®->hccr) &
446 HCCR_RISC_PAUSE) != 0)
451 RD_REG_WORD(®->hccr); /* PCI Posting. */
455 /* Select FPM registers. */
456 WRT_REG_WORD(®->ctrl_status, 0x20);
457 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
459 /* FPM Soft Reset. */
460 WRT_REG_WORD(®->fpm_diag_config, 0x100);
461 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
463 /* Toggle Fpm Reset. */
464 if (!IS_QLA2200(ha)) {
465 WRT_REG_WORD(®->fpm_diag_config, 0x0);
466 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
469 /* Select frame buffer registers. */
470 WRT_REG_WORD(®->ctrl_status, 0x10);
471 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
473 /* Reset frame buffer FIFOs. */
474 if (IS_QLA2200(ha)) {
475 WRT_FB_CMD_REG(ha, reg, 0xa000);
476 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
478 WRT_FB_CMD_REG(ha, reg, 0x00fc);
480 /* Read back fb_cmd until zero or 3 seconds max */
481 for (cnt = 0; cnt < 3000; cnt++) {
482 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
488 /* Select RISC module registers. */
489 WRT_REG_WORD(®->ctrl_status, 0);
490 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
492 /* Reset RISC processor. */
493 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
494 RD_REG_WORD(®->hccr); /* PCI Posting. */
496 /* Release RISC processor. */
497 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
498 RD_REG_WORD(®->hccr); /* PCI Posting. */
501 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
502 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
504 /* Reset ISP chip. */
505 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
507 /* Wait for RISC to recover from reset. */
508 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
510 * It is necessary to for a delay here since the card doesn't
511 * respond to PCI reads during a reset. On some architectures
512 * this will result in an MCA.
515 for (cnt = 30000; cnt; cnt--) {
516 if ((RD_REG_WORD(®->ctrl_status) &
517 CSR_ISP_SOFT_RESET) == 0)
524 /* Reset RISC processor. */
525 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
527 WRT_REG_WORD(®->semaphore, 0);
529 /* Release RISC processor. */
530 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
531 RD_REG_WORD(®->hccr); /* PCI Posting. */
533 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
534 for (cnt = 0; cnt < 30000; cnt++) {
535 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
536 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
538 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) {
539 if (!(test_bit(ABORT_ISP_ACTIVE,
541 spin_unlock_irqrestore(
542 &ha->mbx_reg_lock, mbx_flags);
546 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
547 spin_unlock_irqrestore(&ha->mbx_reg_lock,
555 /* Turn on master enable */
556 cmd |= PCI_COMMAND_MASTER;
557 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
559 /* Disable RISC pause on FPM parity error. */
560 if (!IS_QLA2100(ha)) {
561 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
562 RD_REG_WORD(®->hccr); /* PCI Posting. */
565 spin_unlock_irqrestore(&ha->hardware_lock, flags);
569 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
572 * Returns 0 on success.
575 qla24xx_reset_risc(scsi_qla_host_t *ha)
577 unsigned long flags = 0;
578 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
582 spin_lock_irqsave(&ha->hardware_lock, flags);
585 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
586 for (cnt = 0; cnt < 30000; cnt++) {
587 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
593 WRT_REG_DWORD(®->ctrl_status,
594 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
595 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
598 /* Wait for firmware to complete NVRAM accesses. */
599 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
600 for (cnt = 10000 ; cnt && d2; cnt--) {
602 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
606 /* Wait for soft-reset to complete. */
607 d2 = RD_REG_DWORD(®->ctrl_status);
608 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
610 d2 = RD_REG_DWORD(®->ctrl_status);
614 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
615 RD_REG_DWORD(®->hccr);
617 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
618 RD_REG_DWORD(®->hccr);
620 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
621 RD_REG_DWORD(®->hccr);
623 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
624 for (cnt = 6000000 ; cnt && d2; cnt--) {
626 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
630 spin_unlock_irqrestore(&ha->hardware_lock, flags);
634 * qla24xx_reset_chip() - Reset ISP24xx chip.
637 * Returns 0 on success.
640 qla24xx_reset_chip(scsi_qla_host_t *ha)
642 ha->isp_ops.disable_intrs(ha);
644 /* Perform RISC reset. */
645 qla24xx_reset_risc(ha);
649 * qla2x00_chip_diag() - Test chip for proper operation.
652 * Returns 0 on success.
655 qla2x00_chip_diag(scsi_qla_host_t *ha)
658 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
659 unsigned long flags = 0;
664 /* Assume a failed state */
665 rval = QLA_FUNCTION_FAILED;
667 DEBUG3(printk(KERN_WARNING "scsi(%ld): Testing device at %p\n",
668 ha->host_no, ®->flash_address));
670 spin_lock_irqsave(&ha->hardware_lock, flags);
672 /* Disable PCI "Bus Master Enable bit" */
673 if (IS_QLA23XX(ha)) {
674 data = RD_REG_WORD(®->unused_1[0]);
675 WRT_REG_WORD(®->unused_1[0], data&~BIT_2);
678 /* Reset ISP chip. */
679 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
681 if (!IS_QLA23XX(ha)) {
683 * We need to have a delay here since the card will not respond while
684 * in reset causing an MCA on some architectures.
687 data = qla2x00_debounce_register(®->ctrl_status);
688 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
690 data = RD_REG_WORD(®->ctrl_status);
695 goto chip_diag_failed;
697 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
702 * Should be 16 PCI Clock cycles, but this is arbitrarily safer
705 data = RD_REG_WORD(®->unused_1[0]);
706 WRT_REG_WORD(®->unused_1[0], data&BIT_2);
709 /* Reset RISC processor. */
710 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
711 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
713 /* Workaround for QLA2312 PCI parity error */
714 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
715 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
716 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
718 data = RD_MAILBOX_REG(ha, reg, 0);
723 goto chip_diag_failed;
728 /* Check product ID of chip */
729 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
731 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
732 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
733 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
734 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
735 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
736 mb[3] != PROD_ID_3) {
737 qla_printk(KERN_WARNING, ha,
738 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
740 goto chip_diag_failed;
742 ha->product_id[0] = mb[1];
743 ha->product_id[1] = mb[2];
744 ha->product_id[2] = mb[3];
745 ha->product_id[3] = mb[4];
747 /* Adjust fw RISC transfer size */
748 if (ha->request_q_length > 1024)
749 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
751 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
752 ha->request_q_length;
754 if (IS_QLA2200(ha) &&
755 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
756 /* Limit firmware transfer size with a 2200A */
757 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
760 ha->device_type |= DT_ISP2200A;
761 ha->fw_transfer_size = 128;
764 /* Wrap Incoming Mailboxes Test. */
765 spin_unlock_irqrestore(&ha->hardware_lock, flags);
767 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
768 rval = qla2x00_mbx_reg_test(ha);
770 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
772 qla_printk(KERN_WARNING, ha,
773 "Failed mailbox send register test\n");
776 /* Flag a successful rval */
779 spin_lock_irqsave(&ha->hardware_lock, flags);
783 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
784 "****\n", ha->host_no));
786 spin_unlock_irqrestore(&ha->hardware_lock, flags);
792 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
795 * Returns 0 on success.
798 qla24xx_chip_diag(scsi_qla_host_t *ha)
802 /* Perform RISC reset. */
803 qla24xx_reset_risc(ha);
805 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
807 rval = qla2x00_mbx_reg_test(ha);
809 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
811 qla_printk(KERN_WARNING, ha,
812 "Failed mailbox send register test\n");
814 /* Flag a successful rval */
822 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
825 ha->fw_dump24_len = sizeof(struct qla24xx_fw_dump);
826 ha->fw_dump24_len += (ha->fw_memory_size - 0x100000) * sizeof(uint32_t);
827 ha->fw_dump24 = vmalloc(ha->fw_dump24_len);
829 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware "
830 "dump...\n", ha->fw_dump24_len / 1024);
832 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
833 "firmware dump!!!\n", ha->fw_dump24_len / 1024);
837 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
840 * Returns 0 on success.
843 qla2x00_resize_request_q(scsi_qla_host_t *ha)
846 uint16_t fw_iocb_cnt = 0;
847 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
848 dma_addr_t request_dma;
849 request_t *request_ring;
851 /* Valid only on recent ISPs. */
852 if (IS_QLA2100(ha) || IS_QLA2200(ha))
855 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
856 qla2x00_alloc_fw_dump(ha);
858 /* Retrieve IOCB counts available to the firmware. */
859 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
862 /* No point in continuing if current settings are sufficient. */
863 if (fw_iocb_cnt < 1024)
865 if (ha->request_q_length >= request_q_length)
868 /* Attempt to claim larger area for request queue. */
869 request_ring = dma_alloc_coherent(&ha->pdev->dev,
870 (request_q_length + 1) * sizeof(request_t), &request_dma,
872 if (request_ring == NULL)
875 /* Resize successful, report extensions. */
876 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
877 (ha->fw_memory_size + 1) / 1024);
878 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
879 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
881 /* Clear old allocations. */
882 dma_free_coherent(&ha->pdev->dev,
883 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
886 /* Begin using larger queue. */
887 ha->request_q_length = request_q_length;
888 ha->request_ring = request_ring;
889 ha->request_dma = request_dma;
893 * qla2x00_setup_chip() - Load and start RISC firmware.
896 * Returns 0 on success.
899 qla2x00_setup_chip(scsi_qla_host_t *ha)
902 uint32_t srisc_address = 0;
904 /* Load firmware sequences */
905 rval = ha->isp_ops.load_risc(ha, &srisc_address);
906 if (rval == QLA_SUCCESS) {
907 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
908 "code.\n", ha->host_no));
910 rval = qla2x00_verify_checksum(ha, srisc_address);
911 if (rval == QLA_SUCCESS) {
912 /* Start firmware execution. */
913 DEBUG(printk("scsi(%ld): Checksum OK, start "
914 "firmware.\n", ha->host_no));
916 rval = qla2x00_execute_fw(ha, srisc_address);
917 /* Retrieve firmware information. */
918 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
919 qla2x00_get_fw_version(ha,
920 &ha->fw_major_version,
921 &ha->fw_minor_version,
922 &ha->fw_subminor_version,
923 &ha->fw_attributes, &ha->fw_memory_size);
924 qla2x00_resize_request_q(ha);
927 DEBUG2(printk(KERN_INFO
928 "scsi(%ld): ISP Firmware failed checksum.\n",
934 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
942 * qla2x00_init_response_q_entries() - Initializes response queue entries.
945 * Beginning of request ring has initialization control block already built
946 * by nvram config routine.
948 * Returns 0 on success.
951 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
956 pkt = ha->response_ring_ptr;
957 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
958 pkt->signature = RESPONSE_PROCESSED;
965 * qla2x00_update_fw_options() - Read and process firmware options.
968 * Returns 0 on success.
971 qla2x00_update_fw_options(scsi_qla_host_t *ha)
973 uint16_t swing, emphasis, tx_sens, rx_sens;
975 memset(ha->fw_options, 0, sizeof(ha->fw_options));
976 qla2x00_get_fw_options(ha, ha->fw_options);
978 if (IS_QLA2100(ha) || IS_QLA2200(ha))
981 /* Serial Link options. */
982 DEBUG3(printk("scsi(%ld): Serial link options:\n",
984 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
985 sizeof(ha->fw_seriallink_options)));
987 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
988 if (ha->fw_seriallink_options[3] & BIT_2) {
989 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
992 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
993 emphasis = (ha->fw_seriallink_options[2] &
994 (BIT_4 | BIT_3)) >> 3;
995 tx_sens = ha->fw_seriallink_options[0] &
996 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
997 rx_sens = (ha->fw_seriallink_options[0] &
998 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
999 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1000 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1003 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1004 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1005 ha->fw_options[10] |= BIT_5 |
1006 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1007 (tx_sens & (BIT_1 | BIT_0));
1010 swing = (ha->fw_seriallink_options[2] &
1011 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1012 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1013 tx_sens = ha->fw_seriallink_options[1] &
1014 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1015 rx_sens = (ha->fw_seriallink_options[1] &
1016 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1017 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1018 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1021 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1022 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1023 ha->fw_options[11] |= BIT_5 |
1024 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1025 (tx_sens & (BIT_1 | BIT_0));
1029 /* Return command IOCBs without waiting for an ABTS to complete. */
1030 ha->fw_options[3] |= BIT_13;
1033 if (ha->flags.enable_led_scheme)
1034 ha->fw_options[2] |= BIT_12;
1036 /* Detect ISP6312. */
1038 ha->fw_options[2] |= BIT_13;
1040 /* Update firmware options. */
1041 qla2x00_set_fw_options(ha, ha->fw_options);
1045 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1049 /* Update Serial Link options. */
1050 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1053 rval = qla2x00_set_serdes_params(ha,
1054 le16_to_cpu(ha->fw_seriallink_options24[1]),
1055 le16_to_cpu(ha->fw_seriallink_options24[2]),
1056 le16_to_cpu(ha->fw_seriallink_options24[3]));
1057 if (rval != QLA_SUCCESS) {
1058 qla_printk(KERN_WARNING, ha,
1059 "Unable to update Serial Link options (%x).\n", rval);
1064 qla2x00_config_rings(struct scsi_qla_host *ha)
1066 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1068 /* Setup ring parameters in initialization control block. */
1069 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1070 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1071 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1072 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1073 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1074 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1075 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1076 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1078 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1079 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1080 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1081 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1082 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1086 qla24xx_config_rings(struct scsi_qla_host *ha)
1088 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1089 struct init_cb_24xx *icb;
1091 /* Setup ring parameters in initialization control block. */
1092 icb = (struct init_cb_24xx *)ha->init_cb;
1093 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1094 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1095 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1096 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1097 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1098 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1099 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1100 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1102 WRT_REG_DWORD(®->req_q_in, 0);
1103 WRT_REG_DWORD(®->req_q_out, 0);
1104 WRT_REG_DWORD(®->rsp_q_in, 0);
1105 WRT_REG_DWORD(®->rsp_q_out, 0);
1106 RD_REG_DWORD(®->rsp_q_out);
1110 * qla2x00_init_rings() - Initializes firmware.
1113 * Beginning of request ring has initialization control block already built
1114 * by nvram config routine.
1116 * Returns 0 on success.
1119 qla2x00_init_rings(scsi_qla_host_t *ha)
1122 unsigned long flags = 0;
1125 spin_lock_irqsave(&ha->hardware_lock, flags);
1127 /* Clear outstanding commands array. */
1128 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1129 ha->outstanding_cmds[cnt] = NULL;
1131 ha->current_outstanding_cmd = 0;
1133 /* Clear RSCN queue. */
1134 ha->rscn_in_ptr = 0;
1135 ha->rscn_out_ptr = 0;
1137 /* Initialize firmware. */
1138 ha->request_ring_ptr = ha->request_ring;
1139 ha->req_ring_index = 0;
1140 ha->req_q_cnt = ha->request_q_length;
1141 ha->response_ring_ptr = ha->response_ring;
1142 ha->rsp_ring_index = 0;
1144 /* Initialize response queue entries */
1145 qla2x00_init_response_q_entries(ha);
1147 ha->isp_ops.config_rings(ha);
1149 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1151 /* Update any ISP specific firmware options before initialization. */
1152 ha->isp_ops.update_fw_options(ha);
1154 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1155 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1157 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1160 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1168 * qla2x00_fw_ready() - Waits for firmware ready.
1171 * Returns 0 on success.
1174 qla2x00_fw_ready(scsi_qla_host_t *ha)
1177 unsigned long wtime, mtime;
1178 uint16_t min_wait; /* Minimum wait time if loop is down */
1179 uint16_t wait_time; /* Wait time if loop is coming ready */
1184 /* 20 seconds for loop down. */
1188 * Firmware should take at most one RATOV to login, plus 5 seconds for
1189 * our own processing.
1191 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1192 wait_time = min_wait;
1195 /* Min wait time if loop down */
1196 mtime = jiffies + (min_wait * HZ);
1198 /* wait time before firmware ready */
1199 wtime = jiffies + (wait_time * HZ);
1201 /* Wait for ISP to finish LIP */
1202 if (!ha->flags.init_done)
1203 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1205 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1209 rval = qla2x00_get_firmware_state(ha, &fw_state);
1210 if (rval == QLA_SUCCESS) {
1211 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1212 ha->device_flags &= ~DFLG_NO_CABLE;
1214 if (fw_state == FSTATE_READY) {
1215 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1218 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1219 &ha->login_timeout, &ha->r_a_tov);
1225 rval = QLA_FUNCTION_FAILED;
1227 if (atomic_read(&ha->loop_down_timer) &&
1228 (fw_state >= FSTATE_LOSS_OF_SYNC ||
1229 fw_state == FSTATE_WAIT_AL_PA)) {
1230 /* Loop down. Timeout on min_wait for states
1231 * other than Wait for Login.
1233 if (time_after_eq(jiffies, mtime)) {
1234 qla_printk(KERN_INFO, ha,
1235 "Cable is unplugged...\n");
1237 ha->device_flags |= DFLG_NO_CABLE;
1242 /* Mailbox cmd failed. Timeout on min_wait. */
1243 if (time_after_eq(jiffies, mtime))
1247 if (time_after_eq(jiffies, wtime))
1250 /* Delay for a while */
1253 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1254 ha->host_no, fw_state, jiffies));
1257 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1258 ha->host_no, fw_state, jiffies));
1261 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1269 * qla2x00_configure_hba
1270 * Setup adapter context.
1273 * ha = adapter state pointer.
1282 qla2x00_configure_hba(scsi_qla_host_t *ha)
1290 char connect_type[22];
1292 /* Get host addresses. */
1293 rval = qla2x00_get_adapter_id(ha,
1294 &loop_id, &al_pa, &area, &domain, &topo);
1295 if (rval != QLA_SUCCESS) {
1296 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
1297 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1298 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1299 __func__, ha->host_no));
1301 qla_printk(KERN_WARNING, ha,
1302 "ERROR -- Unable to get host loop ID.\n");
1303 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1309 qla_printk(KERN_INFO, ha,
1310 "Cannot get topology - retrying.\n");
1311 return (QLA_FUNCTION_FAILED);
1314 ha->loop_id = loop_id;
1317 ha->min_external_loopid = SNS_FIRST_LOOP_ID+1;
1318 ha->operating_mode = LOOP;
1322 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1324 ha->current_topology = ISP_CFG_NL;
1325 strcpy(connect_type, "(Loop)");
1329 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1331 ha->current_topology = ISP_CFG_FL;
1332 strcpy(connect_type, "(FL_Port)");
1336 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1338 ha->operating_mode = P2P;
1339 ha->current_topology = ISP_CFG_N;
1340 strcpy(connect_type, "(N_Port-to-N_Port)");
1344 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1346 ha->operating_mode = P2P;
1347 ha->current_topology = ISP_CFG_F;
1348 strcpy(connect_type, "(F_Port)");
1352 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1354 ha->host_no, topo));
1355 ha->current_topology = ISP_CFG_NL;
1356 strcpy(connect_type, "(Loop)");
1360 /* Save Host port and loop ID. */
1361 /* byte order - Big Endian */
1362 ha->d_id.b.domain = domain;
1363 ha->d_id.b.area = area;
1364 ha->d_id.b.al_pa = al_pa;
1366 if (!ha->flags.init_done)
1367 qla_printk(KERN_INFO, ha,
1368 "Topology - %s, Host Loop address 0x%x\n",
1369 connect_type, ha->loop_id);
1372 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1374 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1381 * NVRAM configuration for ISP 2xxx
1384 * ha = adapter block pointer.
1387 * initialization control block in response_ring
1388 * host adapters parameters in host adapter block
1394 qla2x00_nvram_config(scsi_qla_host_t *ha)
1399 uint8_t *dptr1, *dptr2;
1400 init_cb_t *icb = ha->init_cb;
1401 nvram_t *nv = (nvram_t *)ha->request_ring;
1402 uint8_t *ptr = (uint8_t *)ha->request_ring;
1403 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1407 if (unlikely(nv == NULL)) {
1408 qla_printk(KERN_ERR, ha, "request_ring pointer is NULL\n");
1414 /* Determine NVRAM starting address. */
1415 ha->nvram_size = sizeof(nvram_t);
1417 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1418 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1419 ha->nvram_base = 0x80;
1421 /* Get NVRAM data and calculate checksum. */
1422 ha->isp_ops.read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1423 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1426 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1427 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1430 /* Bad NVRAM data, set defaults parameters. */
1431 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1432 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1433 /* Reset NVRAM data. */
1434 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1435 "checksum=0x%x nv=%p id=%c version=0x%x.\n", chksum, nv,
1436 nv->id[0], nv->nvram_version);
1437 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1438 "invalid -- WWPN) defaults.\n");
1441 * Set default initialization control block.
1443 memset(nv, 0, ha->nvram_size);
1444 nv->parameter_block_version = ICB_VERSION;
1446 if (IS_QLA23XX(ha)) {
1447 nv->firmware_options[0] = BIT_2 | BIT_1;
1448 nv->firmware_options[1] = BIT_7 | BIT_5;
1449 nv->add_firmware_options[0] = BIT_5;
1450 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1451 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1452 nv->special_options[1] = BIT_7;
1453 } else if (IS_QLA2200(ha)) {
1454 nv->firmware_options[0] = BIT_2 | BIT_1;
1455 nv->firmware_options[1] = BIT_7 | BIT_5;
1456 nv->add_firmware_options[0] = BIT_5;
1457 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1458 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1459 } else if (IS_QLA2100(ha)) {
1460 nv->firmware_options[0] = BIT_3 | BIT_1;
1461 nv->firmware_options[1] = BIT_5;
1462 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1465 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1466 nv->execution_throttle = __constant_cpu_to_le16(16);
1467 nv->retry_count = 8;
1468 nv->retry_delay = 1;
1470 nv->port_name[0] = 33;
1471 nv->port_name[3] = 224;
1472 nv->port_name[4] = 139;
1474 nv->login_timeout = 4;
1477 * Set default host adapter parameters
1479 nv->host_p[1] = BIT_2;
1480 nv->reset_delay = 5;
1481 nv->port_down_retry_count = 8;
1482 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1483 nv->link_down_timeout = 60;
1488 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1490 * The SN2 does not provide BIOS emulation which means you can't change
1491 * potentially bogus BIOS settings. Force the use of default settings
1492 * for link rate and frame size. Hope that the rest of the settings
1495 if (ia64_platform_is("sn2")) {
1496 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1498 nv->special_options[1] = BIT_7;
1502 /* Reset Initialization control block */
1503 memset(icb, 0, ha->init_cb_size);
1506 * Setup driver NVRAM options.
1508 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1509 nv->firmware_options[0] &= ~(BIT_5);
1510 #ifdef FC_TARGET_SUPPORT
1511 if (ha->flags.enable_target_mode)
1512 nv->firmware_options[0] |= BIT_4;
1514 #endif /* FC_TARGET_SUPPORT */
1515 nv->firmware_options[0] &= ~BIT_4;
1516 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1517 nv->firmware_options[1] &= ~BIT_4;
1519 if (IS_QLA23XX(ha)) {
1520 nv->firmware_options[0] |= BIT_2;
1521 nv->firmware_options[0] &= ~BIT_3;
1522 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1524 if (IS_QLA2300(ha)) {
1525 if (ha->fb_rev == FPM_2310) {
1526 strcpy(ha->model_number, "QLA2310");
1528 strcpy(ha->model_number, "QLA2300");
1532 memcmp(nv->model_number, BINZERO,
1533 sizeof(nv->model_number)) != 0) {
1536 strncpy(ha->model_number, nv->model_number,
1537 sizeof(nv->model_number));
1538 st = en = ha->model_number;
1539 en += sizeof(nv->model_number) - 1;
1541 if (*en != 0x20 && *en != 0x00)
1548 index = (ha->pdev->subsystem_device & 0xff);
1549 if (index < QLA_MODEL_NAMES) {
1550 strcpy(ha->model_number,
1551 qla2x00_model_name[index * 2]);
1553 qla2x00_model_name[index * 2 + 1];
1555 strcpy(ha->model_number, "QLA23xx");
1559 } else if (IS_QLA2200(ha)) {
1560 nv->firmware_options[0] |= BIT_2;
1562 * 'Point-to-point preferred, else loop' is not a safe
1563 * connection mode setting.
1565 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1567 /* Force 'loop preferred, else point-to-point'. */
1568 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1569 nv->add_firmware_options[0] |= BIT_5;
1571 strcpy(ha->model_number, "QLA22xx");
1572 } else /*if (IS_QLA2100(ha))*/ {
1573 strcpy(ha->model_number, "QLA2100");
1577 * Copy over NVRAM RISC parameter block to initialization control block.
1579 dptr1 = (uint8_t *)icb;
1580 dptr2 = (uint8_t *)&nv->parameter_block_version;
1581 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1583 *dptr1++ = *dptr2++;
1585 /* Copy 2nd half. */
1586 dptr1 = (uint8_t *)icb->add_firmware_options;
1587 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1589 *dptr1++ = *dptr2++;
1591 /* Prepare nodename */
1592 if ((icb->firmware_options[1] & BIT_6) == 0) {
1594 * Firmware will apply the following mask if the nodename was
1597 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1598 icb->node_name[0] &= 0xF0;
1602 * Set host adapter parameters.
1604 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1605 /* Always load RISC code on non ISP2[12]00 chips. */
1606 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1607 ha->flags.disable_risc_code_load = 0;
1608 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1609 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1610 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1611 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1613 ha->operating_mode =
1614 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1616 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1617 sizeof(ha->fw_seriallink_options));
1619 /* save HBA serial number */
1620 ha->serial0 = icb->port_name[5];
1621 ha->serial1 = icb->port_name[6];
1622 ha->serial2 = icb->port_name[7];
1623 ha->node_name = icb->node_name;
1624 ha->port_name = icb->port_name;
1626 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1628 ha->retry_count = nv->retry_count;
1630 /* Set minimum login_timeout to 4 seconds. */
1631 if (nv->login_timeout < ql2xlogintimeout)
1632 nv->login_timeout = ql2xlogintimeout;
1633 if (nv->login_timeout < 4)
1634 nv->login_timeout = 4;
1635 ha->login_timeout = nv->login_timeout;
1636 icb->login_timeout = nv->login_timeout;
1638 /* Set minimum RATOV to 200 tenths of a second. */
1641 ha->loop_reset_delay = nv->reset_delay;
1643 /* Link Down Timeout = 0:
1645 * When Port Down timer expires we will start returning
1646 * I/O's to OS with "DID_NO_CONNECT".
1648 * Link Down Timeout != 0:
1650 * The driver waits for the link to come up after link down
1651 * before returning I/Os to OS with "DID_NO_CONNECT".
1653 if (nv->link_down_timeout == 0) {
1654 ha->loop_down_abort_time =
1655 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1657 ha->link_down_timeout = nv->link_down_timeout;
1658 ha->loop_down_abort_time =
1659 (LOOP_DOWN_TIME - ha->link_down_timeout);
1663 * Need enough time to try and get the port back.
1665 ha->port_down_retry_count = nv->port_down_retry_count;
1666 if (qlport_down_retry)
1667 ha->port_down_retry_count = qlport_down_retry;
1668 /* Set login_retry_count */
1669 ha->login_retry_count = nv->retry_count;
1670 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1671 ha->port_down_retry_count > 3)
1672 ha->login_retry_count = ha->port_down_retry_count;
1673 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1674 ha->login_retry_count = ha->port_down_retry_count;
1675 if (ql2xloginretrycount)
1676 ha->login_retry_count = ql2xloginretrycount;
1678 icb->lun_enables = __constant_cpu_to_le16(0);
1679 icb->command_resource_count = 0;
1680 icb->immediate_notify_resource_count = 0;
1681 icb->timeout = __constant_cpu_to_le16(0);
1683 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1685 icb->firmware_options[0] &= ~BIT_3;
1686 icb->add_firmware_options[0] &=
1687 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1688 icb->add_firmware_options[0] |= BIT_2;
1689 icb->response_accumulation_timer = 3;
1690 icb->interrupt_delay_timer = 5;
1692 ha->flags.process_response_queue = 1;
1695 if (!ha->flags.init_done) {
1696 ha->zio_mode = icb->add_firmware_options[0] &
1697 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1698 ha->zio_timer = icb->interrupt_delay_timer ?
1699 icb->interrupt_delay_timer: 2;
1701 icb->add_firmware_options[0] &=
1702 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1703 ha->flags.process_response_queue = 0;
1704 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1705 ha->zio_mode = QLA_ZIO_MODE_6;
1707 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1708 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1709 ha->zio_timer * 100));
1710 qla_printk(KERN_INFO, ha,
1711 "ZIO mode %d enabled; timer delay (%d us).\n",
1712 ha->zio_mode, ha->zio_timer * 100);
1714 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1715 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1716 ha->flags.process_response_queue = 1;
1721 DEBUG2_3(printk(KERN_WARNING
1722 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1728 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
1729 qla2x00_rport_add(void *data)
1731 qla2x00_rport_add(struct work_struct *work)
1734 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
1735 fc_port_t *fcport = data;
1737 fc_port_t *fcport = container_of(work, struct fc_port, rport_add_work);
1740 qla2x00_reg_remote_port(fcport->ha, fcport);
1744 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
1745 qla2x00_rport_del(void *data)
1747 qla2x00_rport_del(struct work_struct *work)
1750 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
1751 fc_port_t *fcport = data;
1753 fc_port_t *fcport = container_of(work, struct fc_port, rport_del_work);
1755 struct fc_rport *rport;
1756 unsigned long flags;
1758 spin_lock_irqsave(&fcport->rport_lock, flags);
1759 rport = fcport->drport;
1760 fcport->drport = NULL;
1761 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1763 fc_remote_port_delete(rport);
1768 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1770 * @flags: allocation flags
1772 * Returns a pointer to the allocated fcport, or NULL, if none available.
1775 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1779 fcport = kmalloc(sizeof(fc_port_t), flags);
1783 /* Setup fcport template structure. */
1784 memset(fcport, 0, sizeof (fc_port_t));
1786 fcport->port_type = FCT_UNKNOWN;
1787 fcport->loop_id = FC_NO_LOOP_ID;
1788 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1789 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1790 fcport->flags = FCF_RLC_SUPPORT;
1791 fcport->supported_classes = FC_COS_UNSPECIFIED;
1792 spin_lock_init(&fcport->rport_lock);
1793 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
1794 INIT_WORK(&fcport->rport_add_work, qla2x00_rport_add, fcport);
1795 INIT_WORK(&fcport->rport_del_work, qla2x00_rport_del, fcport);
1797 INIT_WORK(&fcport->rport_add_work, qla2x00_rport_add);
1798 INIT_WORK(&fcport->rport_del_work, qla2x00_rport_del);
1805 * qla2x00_configure_loop
1806 * Updates Fibre Channel Device Database with what is actually on loop.
1809 * ha = adapter block pointer.
1814 * 2 = database was full and device was not configured.
1817 qla2x00_configure_loop(scsi_qla_host_t *ha)
1820 unsigned long flags, save_flags;
1824 /* Get Initiator ID */
1825 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1826 rval = qla2x00_configure_hba(ha);
1827 if (rval != QLA_SUCCESS) {
1828 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1834 save_flags = flags = ha->dpc_flags;
1835 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1836 ha->host_no, flags));
1839 * If we have both an RSCN and PORT UPDATE pending then handle them
1840 * both at the same time.
1842 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1843 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1845 /* Determine what we need to do */
1846 if (ha->current_topology == ISP_CFG_FL &&
1847 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1849 ha->flags.rscn_queue_overflow = 1;
1850 set_bit(RSCN_UPDATE, &flags);
1852 } else if (ha->current_topology == ISP_CFG_F &&
1853 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1855 ha->flags.rscn_queue_overflow = 1;
1856 set_bit(RSCN_UPDATE, &flags);
1857 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1859 } else if (!ha->flags.online ||
1860 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1862 ha->flags.rscn_queue_overflow = 1;
1863 set_bit(RSCN_UPDATE, &flags);
1864 set_bit(LOCAL_LOOP_UPDATE, &flags);
1867 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1868 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1869 rval = QLA_FUNCTION_FAILED;
1871 rval = qla2x00_configure_local_loop(ha);
1875 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1876 if (LOOP_TRANSITION(ha)) {
1877 rval = QLA_FUNCTION_FAILED;
1879 rval = qla2x00_configure_fabric(ha);
1883 if (rval == QLA_SUCCESS) {
1884 if (atomic_read(&ha->loop_down_timer) ||
1885 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1886 rval = QLA_FUNCTION_FAILED;
1888 atomic_set(&ha->loop_state, LOOP_READY);
1890 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1895 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1896 __func__, ha->host_no));
1898 DEBUG3(printk("%s: exiting normally\n", __func__));
1901 /* Restore state if a resync event occured during processing */
1902 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1903 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1904 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1905 if (test_bit(RSCN_UPDATE, &save_flags))
1906 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1915 * qla2x00_configure_local_loop
1916 * Updates Fibre Channel Device Database with local loop devices.
1919 * ha = adapter block pointer.
1925 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1930 fc_port_t *fcport, *new_fcport;
1936 uint8_t domain, area, al_pa;
1940 entries = MAX_FIBRE_DEVICES;
1942 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1943 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1945 /* Get list of logged in devices. */
1946 memset(ha->gid_list, 0, GID_LIST_SIZE);
1947 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1949 if (rval != QLA_SUCCESS)
1950 goto cleanup_allocation;
1952 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1953 ha->host_no, entries));
1954 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1955 entries * sizeof(struct gid_list_info)));
1957 /* Allocate temporary fcport for any new fcports discovered. */
1958 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1959 if (new_fcport == NULL) {
1960 rval = QLA_MEMORY_ALLOC_FAILED;
1961 goto cleanup_allocation;
1963 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1966 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1968 list_for_each_entry(fcport, &ha->fcports, list) {
1969 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1970 fcport->port_type != FCT_BROADCAST &&
1971 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1973 DEBUG(printk("scsi(%ld): Marking port lost, "
1975 ha->host_no, fcport->loop_id));
1977 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1978 fcport->flags &= ~FCF_FARP_DONE;
1982 /* Add devices to port list. */
1983 id_iter = (char *)ha->gid_list;
1984 for (index = 0; index < entries; index++) {
1985 domain = ((struct gid_list_info *)id_iter)->domain;
1986 area = ((struct gid_list_info *)id_iter)->area;
1987 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1988 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1989 loop_id = (uint16_t)
1990 ((struct gid_list_info *)id_iter)->loop_id_2100;
1992 loop_id = le16_to_cpu(
1993 ((struct gid_list_info *)id_iter)->loop_id);
1994 id_iter += ha->gid_list_info_size;
1996 /* Bypass reserved domain fields. */
1997 if ((domain & 0xf0) == 0xf0)
2000 /* Bypass if not same domain and area of adapter. */
2001 if (area && domain &&
2002 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
2005 /* Bypass invalid local loop ID. */
2006 if (loop_id > LAST_LOCAL_LOOP_ID)
2009 /* Fill in member data. */
2010 new_fcport->d_id.b.domain = domain;
2011 new_fcport->d_id.b.area = area;
2012 new_fcport->d_id.b.al_pa = al_pa;
2013 new_fcport->loop_id = loop_id;
2014 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
2015 if (rval2 != QLA_SUCCESS) {
2016 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2017 "information -- get_port_database=%x, "
2019 ha->host_no, rval2, new_fcport->loop_id));
2020 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2022 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2026 /* Check for matching device in port list. */
2029 list_for_each_entry(fcport, &ha->fcports, list) {
2030 if (memcmp(new_fcport->port_name, fcport->port_name,
2034 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2035 FCF_PERSISTENT_BOUND);
2036 fcport->loop_id = new_fcport->loop_id;
2037 fcport->port_type = new_fcport->port_type;
2038 fcport->d_id.b24 = new_fcport->d_id.b24;
2039 memcpy(fcport->node_name, new_fcport->node_name,
2047 /* New device, add to fcports list. */
2048 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
2049 list_add_tail(&new_fcport->list, &ha->fcports);
2051 /* Allocate a new replacement fcport. */
2052 fcport = new_fcport;
2053 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2054 if (new_fcport == NULL) {
2055 rval = QLA_MEMORY_ALLOC_FAILED;
2056 goto cleanup_allocation;
2058 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2061 qla2x00_update_fcport(ha, fcport);
2069 if (rval != QLA_SUCCESS) {
2070 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2071 "rval=%x\n", ha->host_no, rval));
2075 ha->device_flags |= DFLG_LOCAL_DEVICES;
2076 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2083 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
2087 qla2x00_mark_all_devices_lost(ha, 0);
2088 list_for_each_entry(fcport, &ha->fcports, list) {
2089 if (fcport->port_type != FCT_TARGET)
2092 qla2x00_update_fcport(ha, fcport);
2097 * qla2x00_update_fcport
2098 * Updates device on list.
2101 * ha = adapter block pointer.
2102 * fcport = port structure pointer.
2112 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2115 fcport->login_retry = 0;
2116 fcport->port_login_retry_count = ha->port_down_retry_count *
2118 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2120 fcport->flags &= ~FCF_LOGIN_NEEDED;
2122 if (fcport->port_type == FCT_INITIATOR ||
2123 fcport->port_type == FCT_BROADCAST)
2124 fcport->device_type = TYPE_PROCESSOR;
2126 atomic_set(&fcport->state, FCS_ONLINE);
2128 if (ha->flags.init_done)
2129 qla2x00_reg_remote_port(ha, fcport);
2133 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2135 struct fc_rport_identifiers rport_ids;
2136 struct fc_rport *rport;
2137 unsigned long flags;
2140 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
2141 qla2x00_rport_del(fcport);
2143 qla2x00_rport_del(&fcport->rport_del_work);
2148 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2149 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2150 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2151 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2152 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2153 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2155 qla_printk(KERN_WARNING, ha,
2156 "Unable to allocate fc remote port!\n");
2159 spin_lock_irqsave(&fcport->rport_lock, flags);
2160 fcport->rport = rport;
2161 *((fc_port_t **)rport->dd_data) = fcport;
2162 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2164 rport->supported_classes = fcport->supported_classes;
2166 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2167 if (fcport->port_type == FCT_INITIATOR)
2168 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2169 if (fcport->port_type == FCT_TARGET)
2170 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2171 fc_remote_port_rolechg(rport, rport_ids.roles);
2173 if (rport->scsi_target_id != -1 &&
2174 rport->scsi_target_id < ha->host->max_id)
2175 fcport->os_target_id = rport->scsi_target_id;
2179 * qla2x00_configure_fabric
2180 * Setup SNS devices with loop ID's.
2183 * ha = adapter block pointer.
2190 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2193 fc_port_t *fcport, *fcptemp;
2194 uint16_t next_loopid;
2195 uint16_t mb[MAILBOX_REGISTER_COUNT];
2197 LIST_HEAD(new_fcports);
2199 /* If FL port exists, then SNS is present */
2200 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2201 loop_id = NPH_F_PORT;
2203 loop_id = SNS_FL_PORT;
2204 rval = qla2x00_get_port_name(ha, loop_id, NULL, 0);
2205 if (rval != QLA_SUCCESS) {
2206 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2207 "Port\n", ha->host_no));
2209 ha->device_flags &= ~SWITCH_FOUND;
2210 return (QLA_SUCCESS);
2213 /* Mark devices that need re-synchronization. */
2214 rval2 = qla2x00_device_resync(ha);
2215 if (rval2 == QLA_RSCNS_HANDLED) {
2216 /* No point doing the scan, just continue. */
2217 return (QLA_SUCCESS);
2221 if (ql2xfdmienable &&
2222 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2223 qla2x00_fdmi_register(ha);
2225 /* Ensure we are logged into the SNS. */
2226 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2229 loop_id = SIMPLE_NAME_SERVER;
2230 ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
2231 0xfc, mb, BIT_1 | BIT_0);
2232 if (mb[0] != MBS_COMMAND_COMPLETE) {
2233 DEBUG2(qla_printk(KERN_INFO, ha,
2234 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2235 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2236 mb[0], mb[1], mb[2], mb[6], mb[7]));
2237 return (QLA_SUCCESS);
2240 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2241 if (qla2x00_rft_id(ha)) {
2243 DEBUG2(printk("scsi(%ld): Register FC-4 "
2244 "TYPE failed.\n", ha->host_no));
2246 if (qla2x00_rff_id(ha)) {
2248 DEBUG2(printk("scsi(%ld): Register FC-4 "
2249 "Features failed.\n", ha->host_no));
2251 if (qla2x00_rnn_id(ha)) {
2253 DEBUG2(printk("scsi(%ld): Register Node Name "
2254 "failed.\n", ha->host_no));
2255 } else if (qla2x00_rsnn_nn(ha)) {
2257 DEBUG2(printk("scsi(%ld): Register Symbolic "
2258 "Node Name failed.\n", ha->host_no));
2262 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2263 if (rval != QLA_SUCCESS)
2267 * Logout all previous fabric devices marked lost, except
2270 list_for_each_entry(fcport, &ha->fcports, list) {
2271 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2274 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2277 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2278 qla2x00_mark_device_lost(ha, fcport,
2279 ql2xplogiabsentdevice, 0);
2280 if (fcport->loop_id != FC_NO_LOOP_ID &&
2281 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2282 fcport->port_type != FCT_INITIATOR &&
2283 fcport->port_type != FCT_BROADCAST) {
2284 ha->isp_ops.fabric_logout(ha,
2286 fcport->d_id.b.domain,
2287 fcport->d_id.b.area,
2288 fcport->d_id.b.al_pa);
2289 fcport->loop_id = FC_NO_LOOP_ID;
2294 /* Starting free loop ID. */
2295 next_loopid = ha->min_external_loopid;
2298 * Scan through our port list and login entries that need to be
2301 list_for_each_entry(fcport, &ha->fcports, list) {
2302 if (atomic_read(&ha->loop_down_timer) ||
2303 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2306 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2307 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2310 if (fcport->loop_id == FC_NO_LOOP_ID) {
2311 fcport->loop_id = next_loopid;
2312 rval = qla2x00_find_new_loop_id(ha, fcport);
2313 if (rval != QLA_SUCCESS) {
2314 /* Ran out of IDs to use */
2318 /* Login and update database */
2319 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2322 /* Exit if out of loop IDs. */
2323 if (rval != QLA_SUCCESS) {
2328 * Login and add the new devices to our port list.
2330 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2331 if (atomic_read(&ha->loop_down_timer) ||
2332 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2335 /* Find a new loop ID to use. */
2336 fcport->loop_id = next_loopid;
2337 rval = qla2x00_find_new_loop_id(ha, fcport);
2338 if (rval != QLA_SUCCESS) {
2339 /* Ran out of IDs to use */
2343 /* Remove device from the new list and add it to DB */
2344 list_del(&fcport->list);
2345 list_add_tail(&fcport->list, &ha->fcports);
2347 /* Login and update database */
2348 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2352 /* Free all new device structures not processed. */
2353 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2354 list_del(&fcport->list);
2359 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2360 "rval=%d\n", ha->host_no, rval));
2368 * qla2x00_find_all_fabric_devs
2371 * ha = adapter block pointer.
2372 * dev = database device entry pointer.
2381 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2385 fc_port_t *fcport, *new_fcport, *fcptemp;
2390 int first_dev, last_dev;
2391 port_id_t wrap, nxt_d_id;
2395 /* Try GID_PT to get device list, else GAN. */
2396 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2399 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2400 "on GA_NXT\n", ha->host_no));
2402 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2403 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2406 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2409 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2416 /* Allocate temporary fcport for any new fcports discovered. */
2417 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2418 if (new_fcport == NULL) {
2420 return (QLA_MEMORY_ALLOC_FAILED);
2422 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2424 /* Set start port ID scan at adapter ID. */
2428 /* Starting free loop ID. */
2429 loop_id = ha->min_external_loopid;
2430 for (; loop_id <= ha->last_loop_id; loop_id++) {
2431 if (qla2x00_is_reserved_id(ha, loop_id))
2434 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2439 wrap.b24 = new_fcport->d_id.b24;
2441 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2442 memcpy(new_fcport->node_name,
2443 swl[swl_idx].node_name, WWN_SIZE);
2444 memcpy(new_fcport->port_name,
2445 swl[swl_idx].port_name, WWN_SIZE);
2447 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2453 /* Send GA_NXT to the switch */
2454 rval = qla2x00_ga_nxt(ha, new_fcport);
2455 if (rval != QLA_SUCCESS) {
2456 qla_printk(KERN_WARNING, ha,
2457 "SNS scan failed -- assuming zero-entry "
2459 list_for_each_entry_safe(fcport, fcptemp,
2460 new_fcports, list) {
2461 list_del(&fcport->list);
2469 /* If wrap on switch device list, exit. */
2471 wrap.b24 = new_fcport->d_id.b24;
2473 } else if (new_fcport->d_id.b24 == wrap.b24) {
2474 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2475 ha->host_no, new_fcport->d_id.b.domain,
2476 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2480 /* Bypass if host adapter. */
2481 if (new_fcport->d_id.b24 == ha->d_id.b24)
2484 /* Bypass if same domain and area of adapter. */
2485 if (((new_fcport->d_id.b24 & 0xffff00) ==
2486 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2490 /* Bypass reserved domain fields. */
2491 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2494 /* Locate matching device in database. */
2496 list_for_each_entry(fcport, &ha->fcports, list) {
2497 if (memcmp(new_fcport->port_name, fcport->port_name,
2504 * If address the same and state FCS_ONLINE, nothing
2507 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2508 atomic_read(&fcport->state) == FCS_ONLINE) {
2513 * If device was not a fabric device before.
2515 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2516 fcport->d_id.b24 = new_fcport->d_id.b24;
2517 fcport->loop_id = FC_NO_LOOP_ID;
2518 fcport->flags |= (FCF_FABRIC_DEVICE |
2520 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2525 * Port ID changed or device was marked to be updated;
2526 * Log it out if still logged in and mark it for
2529 fcport->d_id.b24 = new_fcport->d_id.b24;
2530 fcport->flags |= FCF_LOGIN_NEEDED;
2531 if (fcport->loop_id != FC_NO_LOOP_ID &&
2532 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2533 fcport->port_type != FCT_INITIATOR &&
2534 fcport->port_type != FCT_BROADCAST) {
2535 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2536 fcport->d_id.b.domain, fcport->d_id.b.area,
2537 fcport->d_id.b.al_pa);
2538 fcport->loop_id = FC_NO_LOOP_ID;
2547 /* If device was not in our fcports list, then add it. */
2548 list_add_tail(&new_fcport->list, new_fcports);
2550 /* Allocate a new replacement fcport. */
2551 nxt_d_id.b24 = new_fcport->d_id.b24;
2552 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2553 if (new_fcport == NULL) {
2555 return (QLA_MEMORY_ALLOC_FAILED);
2557 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2558 new_fcport->d_id.b24 = nxt_d_id.b24;
2564 if (!list_empty(new_fcports))
2565 ha->device_flags |= DFLG_FABRIC_DEVICES;
2571 * qla2x00_find_new_loop_id
2572 * Scan through our port list and find a new usable loop ID.
2575 * ha: adapter state pointer.
2576 * dev: port structure pointer.
2579 * qla2x00 local function return status code.
2585 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2590 uint16_t first_loop_id;
2594 /* Save starting loop ID. */
2595 first_loop_id = dev->loop_id;
2598 /* Skip loop ID if already used by adapter. */
2599 if (dev->loop_id == ha->loop_id) {
2603 /* Skip reserved loop IDs. */
2604 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2608 /* Reset loop ID if passed the end. */
2609 if (dev->loop_id > ha->last_loop_id) {
2610 /* first loop ID. */
2611 dev->loop_id = ha->min_external_loopid;
2614 /* Check for loop ID being already in use. */
2617 list_for_each_entry(fcport, &ha->fcports, list) {
2618 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2619 /* ID possibly in use */
2625 /* If not in use then it is free to use. */
2630 /* ID in use. Try next value. */
2633 /* If wrap around. No free ID to use. */
2634 if (dev->loop_id == first_loop_id) {
2635 dev->loop_id = FC_NO_LOOP_ID;
2636 rval = QLA_FUNCTION_FAILED;
2645 * qla2x00_device_resync
2646 * Marks devices in the database that needs resynchronization.
2649 * ha = adapter block pointer.
2655 qla2x00_device_resync(scsi_qla_host_t *ha)
2661 uint32_t rscn_entry;
2662 uint8_t rscn_out_iter;
2666 rval = QLA_RSCNS_HANDLED;
2668 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2669 ha->flags.rscn_queue_overflow) {
2671 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2672 format = MSB(MSW(rscn_entry));
2673 d_id.b.domain = LSB(MSW(rscn_entry));
2674 d_id.b.area = MSB(LSW(rscn_entry));
2675 d_id.b.al_pa = LSB(LSW(rscn_entry));
2677 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2678 "[%02x/%02x%02x%02x].\n",
2679 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2680 d_id.b.area, d_id.b.al_pa));
2683 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2684 ha->rscn_out_ptr = 0;
2686 /* Skip duplicate entries. */
2687 for (rscn_out_iter = ha->rscn_out_ptr;
2688 !ha->flags.rscn_queue_overflow &&
2689 rscn_out_iter != ha->rscn_in_ptr;
2690 rscn_out_iter = (rscn_out_iter ==
2691 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2693 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2696 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2697 "entry found at [%d].\n", ha->host_no,
2700 ha->rscn_out_ptr = rscn_out_iter;
2703 /* Queue overflow, set switch default case. */
2704 if (ha->flags.rscn_queue_overflow) {
2705 DEBUG(printk("scsi(%ld): device_resync: rscn "
2706 "overflow.\n", ha->host_no));
2709 ha->flags.rscn_queue_overflow = 0;
2714 if (ql2xprocessrscn &&
2715 !IS_QLA2100(ha) && !IS_QLA2200(ha) &&
2716 !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
2717 !IS_QLA24XX(ha) && !IS_QLA54XX(ha) &&
2718 ha->flags.init_done) {
2719 /* Handle port RSCN via asyncronous IOCBs */
2720 rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
2722 if (rval2 == QLA_SUCCESS)
2736 ha->rscn_out_ptr = ha->rscn_in_ptr;
2742 /* Abort any outstanding IO descriptors. */
2743 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2744 qla2x00_cancel_io_descriptors(ha);
2746 list_for_each_entry(fcport, &ha->fcports, list) {
2747 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2748 (fcport->d_id.b24 & mask) != d_id.b24 ||
2749 fcport->port_type == FCT_BROADCAST)
2752 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2754 fcport->port_type != FCT_INITIATOR) {
2755 qla2x00_mark_device_lost(ha, fcport,
2759 fcport->flags &= ~FCF_FARP_DONE;
2766 * qla2x00_fabric_dev_login
2767 * Login fabric target device and update FC port database.
2770 * ha: adapter state pointer.
2771 * fcport: port structure list pointer.
2772 * next_loopid: contains value of a new loop ID that can be used
2773 * by the next login attempt.
2776 * qla2x00 local function return status code.
2782 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2783 uint16_t *next_loopid)
2792 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2793 if (rval == QLA_SUCCESS) {
2794 /* Send an ADISC to tape devices.*/
2796 if (fcport->flags & FCF_TAPE_PRESENT)
2798 rval = qla2x00_get_port_database(ha, fcport, opts);
2799 if (rval != QLA_SUCCESS) {
2800 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2801 fcport->d_id.b.domain, fcport->d_id.b.area,
2802 fcport->d_id.b.al_pa);
2803 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2805 qla2x00_update_fcport(ha, fcport);
2813 * qla2x00_fabric_login
2814 * Issue fabric login command.
2817 * ha = adapter block pointer.
2818 * device = pointer to FC device type structure.
2821 * 0 - Login successfully
2823 * 2 - Initiator device
2827 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2828 uint16_t *next_loopid)
2832 uint16_t tmp_loopid;
2833 uint16_t mb[MAILBOX_REGISTER_COUNT];
2839 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2840 "for port %02x%02x%02x.\n",
2841 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2842 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2844 /* Login fcport on switch. */
2845 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2846 fcport->d_id.b.domain, fcport->d_id.b.area,
2847 fcport->d_id.b.al_pa, mb, BIT_0);
2848 if (mb[0] == MBS_PORT_ID_USED) {
2850 * Device has another loop ID. The firmware team
2851 * recommends the driver perform an implicit login with
2852 * the specified ID again. The ID we just used is save
2853 * here so we return with an ID that can be tried by
2857 tmp_loopid = fcport->loop_id;
2858 fcport->loop_id = mb[1];
2860 DEBUG(printk("Fabric Login: port in use - next "
2861 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2862 fcport->loop_id, fcport->d_id.b.domain,
2863 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2865 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2870 /* A retry occurred before. */
2871 *next_loopid = tmp_loopid;
2874 * No retry occurred before. Just increment the
2875 * ID value for next login.
2877 *next_loopid = (fcport->loop_id + 1);
2880 if (mb[1] & BIT_0) {
2881 fcport->port_type = FCT_INITIATOR;
2883 fcport->port_type = FCT_TARGET;
2884 if (mb[1] & BIT_1) {
2885 fcport->flags |= FCF_TAPE_PRESENT;
2890 fcport->supported_classes |= FC_COS_CLASS2;
2892 fcport->supported_classes |= FC_COS_CLASS3;
2896 } else if (mb[0] == MBS_LOOP_ID_USED) {
2898 * Loop ID already used, try next loop ID.
2901 rval = qla2x00_find_new_loop_id(ha, fcport);
2902 if (rval != QLA_SUCCESS) {
2903 /* Ran out of loop IDs to use */
2906 } else if (mb[0] == MBS_COMMAND_ERROR) {
2908 * Firmware possibly timed out during login. If NO
2909 * retries are left to do then the device is declared
2912 *next_loopid = fcport->loop_id;
2913 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2914 fcport->d_id.b.domain, fcport->d_id.b.area,
2915 fcport->d_id.b.al_pa);
2916 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2922 * unrecoverable / not handled error
2924 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2925 "loop_id=%x jiffies=%lx.\n",
2926 __func__, ha->host_no, mb[0],
2927 fcport->d_id.b.domain, fcport->d_id.b.area,
2928 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2930 *next_loopid = fcport->loop_id;
2931 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2932 fcport->d_id.b.domain, fcport->d_id.b.area,
2933 fcport->d_id.b.al_pa);
2934 fcport->loop_id = FC_NO_LOOP_ID;
2935 fcport->login_retry = 0;
2946 * qla2x00_local_device_login
2947 * Issue local device login command.
2950 * ha = adapter block pointer.
2951 * loop_id = loop id of device to login to.
2953 * Returns (Where's the #define!!!!):
2954 * 0 - Login successfully
2959 qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
2962 uint16_t mb[MAILBOX_REGISTER_COUNT];
2964 memset(mb, 0, sizeof(mb));
2965 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
2966 if (rval == QLA_SUCCESS) {
2967 /* Interrogate mailbox registers for any errors */
2968 if (mb[0] == MBS_COMMAND_ERROR)
2970 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
2971 /* device not in PCB table */
2979 * qla2x00_loop_resync
2980 * Resync with fibre channel devices.
2983 * ha = adapter block pointer.
2989 qla2x00_loop_resync(scsi_qla_host_t *ha)
2996 atomic_set(&ha->loop_state, LOOP_UPDATE);
2997 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2998 if (ha->flags.online) {
2999 if (!(rval = qla2x00_fw_ready(ha))) {
3000 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3003 atomic_set(&ha->loop_state, LOOP_UPDATE);
3005 /* Issue a marker after FW becomes ready. */
3006 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3007 ha->marker_needed = 0;
3009 /* Remap devices on Loop. */
3010 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3012 qla2x00_configure_loop(ha);
3014 } while (!atomic_read(&ha->loop_down_timer) &&
3015 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3017 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3021 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3022 return (QLA_FUNCTION_FAILED);
3026 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3033 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
3039 list_for_each_entry(fcport, &ha->fcports, list) {
3040 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
3043 qla2x00_update_fcport(ha, fcport);
3044 fcport->flags &= ~FCF_RESCAN_NEEDED;
3048 qla2x00_probe_for_all_luns(ha);
3052 qla2x00_update_fcports(scsi_qla_host_t *ha)
3056 /* Go with deferred removal of rport references. */
3057 list_for_each_entry(fcport, &ha->fcports, list)
3059 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
3060 qla2x00_rport_del(fcport);
3062 qla2x00_rport_del(&fcport->rport_del_work);
3068 * Resets ISP and aborts all outstanding commands.
3071 * ha = adapter block pointer.
3077 qla2x00_abort_isp(scsi_qla_host_t *ha)
3079 unsigned long flags = 0;
3084 if (ha->flags.online) {
3085 ha->flags.online = 0;
3086 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3088 qla_printk(KERN_INFO, ha,
3089 "Performing ISP error recovery - ha= %p.\n", ha);
3090 ha->isp_ops.reset_chip(ha);
3092 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3093 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3094 atomic_set(&ha->loop_state, LOOP_DOWN);
3095 qla2x00_mark_all_devices_lost(ha, 0);
3097 if (!atomic_read(&ha->loop_down_timer))
3098 atomic_set(&ha->loop_down_timer,
3102 spin_lock_irqsave(&ha->hardware_lock, flags);
3103 /* Requeue all commands in outstanding command list. */
3104 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3105 sp = ha->outstanding_cmds[cnt];
3107 ha->outstanding_cmds[cnt] = NULL;
3109 sp->cmd->result = DID_RESET << 16;
3110 sp->cmd->host_scribble = (unsigned char *)NULL;
3111 qla2x00_sp_compl(ha, sp);
3114 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3116 ha->isp_ops.nvram_config(ha);
3118 if (!qla2x00_restart_isp(ha)) {
3119 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3121 if (!atomic_read(&ha->loop_down_timer)) {
3123 * Issue marker command only when we are going
3124 * to start the I/O .
3126 ha->marker_needed = 1;
3129 ha->flags.online = 1;
3131 #ifdef FC_TARGET_SUPPORT
3132 /* Enable target response to SCSI bus. */
3133 if (ha->flags.enable_target_mode)
3134 qla2x00_enable_lun(ha);
3137 ha->isp_ops.enable_intrs(ha);
3139 ha->isp_abort_cnt = 0;
3140 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3141 } else { /* failed the ISP abort */
3142 ha->flags.online = 1;
3143 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3144 if (ha->isp_abort_cnt == 0) {
3145 qla_printk(KERN_WARNING, ha,
3146 "ISP error recovery failed - "
3147 "board disabled\n");
3149 * The next call disables the board
3152 ha->isp_ops.reset_adapter(ha);
3153 ha->flags.online = 0;
3154 clear_bit(ISP_ABORT_RETRY,
3157 } else { /* schedule another ISP abort */
3158 ha->isp_abort_cnt--;
3159 DEBUG(printk("qla%ld: ISP abort - "
3160 "retry remaining %d\n",
3161 ha->host_no, ha->isp_abort_cnt);)
3165 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3166 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3167 "- retrying (%d) more times\n",
3168 ha->host_no, ha->isp_abort_cnt);)
3169 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3177 qla_printk(KERN_INFO, ha,
3178 "qla2x00_abort_isp: **** FAILED ****\n");
3180 DEBUG(printk(KERN_INFO
3181 "qla2x00_abort_isp(%ld): exiting.\n",
3189 * qla2x00_restart_isp
3190 * restarts the ISP after a reset
3193 * ha = adapter block pointer.
3199 qla2x00_restart_isp(scsi_qla_host_t *ha)
3202 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3203 unsigned long flags = 0;
3206 /* If firmware needs to be loaded */
3207 if (qla2x00_isp_firmware(ha)) {
3208 ha->flags.online = 0;
3209 if (!(status = ha->isp_ops.chip_diag(ha))) {
3210 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3211 status = qla2x00_setup_chip(ha);
3215 spin_lock_irqsave(&ha->hardware_lock, flags);
3217 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3219 * Disable SRAM, Instruction RAM and GP RAM
3222 WRT_REG_WORD(®->hccr,
3223 (HCCR_ENABLE_PARITY + 0x0));
3224 RD_REG_WORD(®->hccr);
3227 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3229 status = qla2x00_setup_chip(ha);
3231 spin_lock_irqsave(&ha->hardware_lock, flags);
3233 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3234 /* Enable proper parity */
3237 WRT_REG_WORD(®->hccr,
3238 (HCCR_ENABLE_PARITY + 0x1));
3241 * SRAM, Instruction RAM and GP RAM
3244 WRT_REG_WORD(®->hccr,
3245 (HCCR_ENABLE_PARITY + 0x7));
3246 RD_REG_WORD(®->hccr);
3249 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3254 if (!status && !(status = qla2x00_init_rings(ha))) {
3255 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3256 if (!(status = qla2x00_fw_ready(ha))) {
3257 DEBUG(printk("%s(): Start configure loop, "
3258 "status = %d\n", __func__, status);)
3260 /* Issue a marker after FW becomes ready. */
3261 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3263 ha->flags.online = 1;
3264 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3267 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3268 qla2x00_configure_loop(ha);
3270 } while (!atomic_read(&ha->loop_down_timer) &&
3271 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3273 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3276 /* if no cable then assume it's good */
3277 if ((ha->device_flags & DFLG_NO_CABLE))
3280 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3288 * qla2x00_reset_adapter
3292 * ha = adapter block pointer.
3295 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3297 unsigned long flags = 0;
3298 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3300 ha->flags.online = 0;
3301 ha->isp_ops.disable_intrs(ha);
3303 spin_lock_irqsave(&ha->hardware_lock, flags);
3304 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3305 RD_REG_WORD(®->hccr); /* PCI Posting. */
3306 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3307 RD_REG_WORD(®->hccr); /* PCI Posting. */
3308 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3312 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3314 unsigned long flags = 0;
3315 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3317 ha->flags.online = 0;
3318 ha->isp_ops.disable_intrs(ha);
3320 spin_lock_irqsave(&ha->hardware_lock, flags);
3321 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3322 RD_REG_DWORD(®->hccr);
3323 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3324 RD_REG_DWORD(®->hccr);
3325 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3329 qla24xx_nvram_config(scsi_qla_host_t *ha)
3332 struct init_cb_24xx *icb;
3333 struct nvram_24xx *nv;
3335 uint8_t *dptr1, *dptr2;
3340 icb = (struct init_cb_24xx *)ha->init_cb;
3341 nv = (struct nvram_24xx *)ha->request_ring;
3343 /* Determine NVRAM starting address. */
3344 ha->nvram_size = sizeof(struct nvram_24xx);
3345 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3346 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3347 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3348 if (PCI_FUNC(ha->pdev->devfn)) {
3349 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3350 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3353 /* Get NVRAM data and calculate checksum. */
3354 dptr = (uint32_t *)nv;
3355 ha->isp_ops.read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3357 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3358 chksum += le32_to_cpu(*dptr++);
3360 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3361 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3364 /* Bad NVRAM data, set defaults parameters. */
3365 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3366 || nv->id[3] != ' ' ||
3367 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3368 /* Reset NVRAM data. */
3369 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3370 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3371 le16_to_cpu(nv->nvram_version));
3372 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3373 "invalid -- WWPN) defaults.\n");
3376 * Set default initialization control block.
3378 memset(nv, 0, ha->nvram_size);
3379 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3380 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3381 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3382 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3383 nv->exchange_count = __constant_cpu_to_le16(0);
3384 nv->hard_address = __constant_cpu_to_le16(124);
3385 nv->port_name[0] = 0x21;
3386 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3387 nv->port_name[2] = 0x00;
3388 nv->port_name[3] = 0xe0;
3389 nv->port_name[4] = 0x8b;
3390 nv->port_name[5] = 0x1c;
3391 nv->port_name[6] = 0x55;
3392 nv->port_name[7] = 0x86;
3393 nv->node_name[0] = 0x20;
3394 nv->node_name[1] = 0x00;
3395 nv->node_name[2] = 0x00;
3396 nv->node_name[3] = 0xe0;
3397 nv->node_name[4] = 0x8b;
3398 nv->node_name[5] = 0x1c;
3399 nv->node_name[6] = 0x55;
3400 nv->node_name[7] = 0x86;
3401 nv->login_retry_count = __constant_cpu_to_le16(8);
3402 nv->link_down_timeout = __constant_cpu_to_le16(200);
3403 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3404 nv->login_timeout = __constant_cpu_to_le16(0);
3405 nv->firmware_options_1 =
3406 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3407 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3408 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3409 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3410 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3411 nv->efi_parameters = __constant_cpu_to_le32(0);
3412 nv->reset_delay = 5;
3413 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3414 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3415 nv->link_down_timeout = __constant_cpu_to_le16(30);
3420 /* Reset Initialization control block */
3421 memset(icb, 0, sizeof(struct init_cb_24xx));
3423 /* Copy 1st segment. */
3424 dptr1 = (uint8_t *)icb;
3425 dptr2 = (uint8_t *)&nv->version;
3426 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3428 *dptr1++ = *dptr2++;
3430 icb->login_retry_count = nv->login_retry_count;
3431 icb->link_down_timeout = nv->link_down_timeout;
3433 /* Copy 2nd segment. */
3434 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3435 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3436 cnt = (uint8_t *)&icb->reserved_3 -
3437 (uint8_t *)&icb->interrupt_delay_timer;
3439 *dptr1++ = *dptr2++;
3442 * Setup driver NVRAM options.
3444 if (memcmp(nv->model_name, BINZERO, sizeof(nv->model_name)) != 0) {
3448 strncpy(ha->model_number, nv->model_name,
3449 sizeof(nv->model_name));
3450 st = en = ha->model_number;
3451 en += sizeof(nv->model_name) - 1;
3453 if (*en != 0x20 && *en != 0x00)
3458 index = (ha->pdev->subsystem_device & 0xff);
3459 if (index < QLA_MODEL_NAMES)
3460 ha->model_desc = qla2x00_model_name[index * 2 + 1];
3462 strcpy(ha->model_number, "QLA2462");
3464 /* Prepare nodename */
3465 if ((icb->firmware_options_1 & BIT_14) == 0) {
3467 * Firmware will apply the following mask if the nodename was
3470 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3471 icb->node_name[0] &= 0xF0;
3474 /* Set host adapter parameters. */
3475 ha->flags.disable_risc_code_load = 0;
3476 ha->flags.enable_lip_reset = 1;
3477 ha->flags.enable_lip_full_login = 1;
3478 ha->flags.enable_target_reset = 1;
3479 ha->flags.enable_led_scheme = 0;
3481 ha->operating_mode =
3482 (icb->firmware_options_2 & (BIT_6 | BIT_5 | BIT_4)) >> 4;
3484 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3485 sizeof(ha->fw_seriallink_options24));
3487 /* save HBA serial number */
3488 ha->serial0 = icb->port_name[5];
3489 ha->serial1 = icb->port_name[6];
3490 ha->serial2 = icb->port_name[7];
3491 ha->node_name = icb->node_name;
3492 ha->port_name = icb->port_name;
3494 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3496 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3498 /* Set minimum login_timeout to 4 seconds. */
3499 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3500 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3501 if (le16_to_cpu(nv->login_timeout) < 4)
3502 nv->login_timeout = __constant_cpu_to_le16(4);
3503 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3504 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3506 /* Set minimum RATOV to 200 tenths of a second. */
3509 ha->loop_reset_delay = nv->reset_delay;
3511 /* Link Down Timeout = 0:
3513 * When Port Down timer expires we will start returning
3514 * I/O's to OS with "DID_NO_CONNECT".
3516 * Link Down Timeout != 0:
3518 * The driver waits for the link to come up after link down
3519 * before returning I/Os to OS with "DID_NO_CONNECT".
3521 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3522 ha->loop_down_abort_time =
3523 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3525 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3526 ha->loop_down_abort_time =
3527 (LOOP_DOWN_TIME - ha->link_down_timeout);
3530 /* Need enough time to try and get the port back. */
3531 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3532 if (qlport_down_retry)
3533 ha->port_down_retry_count = qlport_down_retry;
3535 /* Set login_retry_count */
3536 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3537 if (ha->port_down_retry_count ==
3538 le16_to_cpu(nv->port_down_retry_count) &&
3539 ha->port_down_retry_count > 3)
3540 ha->login_retry_count = ha->port_down_retry_count;
3541 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3542 ha->login_retry_count = ha->port_down_retry_count;
3543 if (ql2xloginretrycount)
3544 ha->login_retry_count = ql2xloginretrycount;
3547 if (!ha->flags.init_done) {
3548 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3549 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3550 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3551 le16_to_cpu(icb->interrupt_delay_timer): 2;
3553 icb->firmware_options_2 &= __constant_cpu_to_le32(
3554 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3555 ha->flags.process_response_queue = 0;
3556 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3557 ha->zio_mode = QLA_ZIO_MODE_6;
3559 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3560 "(%d us).\n", ha->host_no, ha->zio_mode,
3561 ha->zio_timer * 100));
3562 qla_printk(KERN_INFO, ha,
3563 "ZIO mode %d enabled; timer delay (%d us).\n",
3564 ha->zio_mode, ha->zio_timer * 100);
3566 icb->firmware_options_2 |= cpu_to_le32(
3567 (uint32_t)ha->zio_mode);
3568 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3569 ha->flags.process_response_queue = 1;
3573 DEBUG2_3(printk(KERN_WARNING
3574 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3579 #if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
3582 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)