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 qla2x00_rport_add(void *data)
1730 fc_port_t *fcport = data;
1732 qla2x00_reg_remote_port(fcport->ha, fcport);
1736 qla2x00_rport_del(void *data)
1738 fc_port_t *fcport = data;
1739 struct fc_rport *rport;
1740 unsigned long flags;
1742 spin_lock_irqsave(&fcport->rport_lock, flags);
1743 rport = fcport->drport;
1744 fcport->drport = NULL;
1745 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1747 fc_remote_port_delete(rport);
1752 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1754 * @flags: allocation flags
1756 * Returns a pointer to the allocated fcport, or NULL, if none available.
1759 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1763 fcport = kmalloc(sizeof(fc_port_t), flags);
1767 /* Setup fcport template structure. */
1768 memset(fcport, 0, sizeof (fc_port_t));
1770 fcport->port_type = FCT_UNKNOWN;
1771 fcport->loop_id = FC_NO_LOOP_ID;
1772 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1773 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1774 fcport->flags = FCF_RLC_SUPPORT;
1775 fcport->supported_classes = FC_COS_UNSPECIFIED;
1776 spin_lock_init(&fcport->rport_lock);
1777 INIT_WORK(&fcport->rport_add_work, qla2x00_rport_add, fcport);
1778 INIT_WORK(&fcport->rport_del_work, qla2x00_rport_del, fcport);
1784 * qla2x00_configure_loop
1785 * Updates Fibre Channel Device Database with what is actually on loop.
1788 * ha = adapter block pointer.
1793 * 2 = database was full and device was not configured.
1796 qla2x00_configure_loop(scsi_qla_host_t *ha)
1799 unsigned long flags, save_flags;
1803 /* Get Initiator ID */
1804 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1805 rval = qla2x00_configure_hba(ha);
1806 if (rval != QLA_SUCCESS) {
1807 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1813 save_flags = flags = ha->dpc_flags;
1814 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1815 ha->host_no, flags));
1818 * If we have both an RSCN and PORT UPDATE pending then handle them
1819 * both at the same time.
1821 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1822 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1824 /* Determine what we need to do */
1825 if (ha->current_topology == ISP_CFG_FL &&
1826 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1828 ha->flags.rscn_queue_overflow = 1;
1829 set_bit(RSCN_UPDATE, &flags);
1831 } else if (ha->current_topology == ISP_CFG_F &&
1832 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1834 ha->flags.rscn_queue_overflow = 1;
1835 set_bit(RSCN_UPDATE, &flags);
1836 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1838 } else if (!ha->flags.online ||
1839 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1841 ha->flags.rscn_queue_overflow = 1;
1842 set_bit(RSCN_UPDATE, &flags);
1843 set_bit(LOCAL_LOOP_UPDATE, &flags);
1846 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1847 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1848 rval = QLA_FUNCTION_FAILED;
1850 rval = qla2x00_configure_local_loop(ha);
1854 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1855 if (LOOP_TRANSITION(ha)) {
1856 rval = QLA_FUNCTION_FAILED;
1858 rval = qla2x00_configure_fabric(ha);
1862 if (rval == QLA_SUCCESS) {
1863 if (atomic_read(&ha->loop_down_timer) ||
1864 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1865 rval = QLA_FUNCTION_FAILED;
1867 atomic_set(&ha->loop_state, LOOP_READY);
1869 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1874 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1875 __func__, ha->host_no));
1877 DEBUG3(printk("%s: exiting normally\n", __func__));
1880 /* Restore state if a resync event occured during processing */
1881 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1882 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1883 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1884 if (test_bit(RSCN_UPDATE, &save_flags))
1885 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1894 * qla2x00_configure_local_loop
1895 * Updates Fibre Channel Device Database with local loop devices.
1898 * ha = adapter block pointer.
1904 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1909 fc_port_t *fcport, *new_fcport;
1915 uint8_t domain, area, al_pa;
1919 entries = MAX_FIBRE_DEVICES;
1921 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1922 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1924 /* Get list of logged in devices. */
1925 memset(ha->gid_list, 0, GID_LIST_SIZE);
1926 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1928 if (rval != QLA_SUCCESS)
1929 goto cleanup_allocation;
1931 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1932 ha->host_no, entries));
1933 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1934 entries * sizeof(struct gid_list_info)));
1936 /* Allocate temporary fcport for any new fcports discovered. */
1937 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1938 if (new_fcport == NULL) {
1939 rval = QLA_MEMORY_ALLOC_FAILED;
1940 goto cleanup_allocation;
1942 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1945 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1947 list_for_each_entry(fcport, &ha->fcports, list) {
1948 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1949 fcport->port_type != FCT_BROADCAST &&
1950 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1952 DEBUG(printk("scsi(%ld): Marking port lost, "
1954 ha->host_no, fcport->loop_id));
1956 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1957 fcport->flags &= ~FCF_FARP_DONE;
1961 /* Add devices to port list. */
1962 id_iter = (char *)ha->gid_list;
1963 for (index = 0; index < entries; index++) {
1964 domain = ((struct gid_list_info *)id_iter)->domain;
1965 area = ((struct gid_list_info *)id_iter)->area;
1966 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1967 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1968 loop_id = (uint16_t)
1969 ((struct gid_list_info *)id_iter)->loop_id_2100;
1971 loop_id = le16_to_cpu(
1972 ((struct gid_list_info *)id_iter)->loop_id);
1973 id_iter += ha->gid_list_info_size;
1975 /* Bypass reserved domain fields. */
1976 if ((domain & 0xf0) == 0xf0)
1979 /* Bypass if not same domain and area of adapter. */
1980 if (area && domain &&
1981 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
1984 /* Bypass invalid local loop ID. */
1985 if (loop_id > LAST_LOCAL_LOOP_ID)
1988 /* Fill in member data. */
1989 new_fcport->d_id.b.domain = domain;
1990 new_fcport->d_id.b.area = area;
1991 new_fcport->d_id.b.al_pa = al_pa;
1992 new_fcport->loop_id = loop_id;
1993 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1994 if (rval2 != QLA_SUCCESS) {
1995 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1996 "information -- get_port_database=%x, "
1998 ha->host_no, rval2, new_fcport->loop_id));
1999 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2001 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2005 /* Check for matching device in port list. */
2008 list_for_each_entry(fcport, &ha->fcports, list) {
2009 if (memcmp(new_fcport->port_name, fcport->port_name,
2013 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2014 FCF_PERSISTENT_BOUND);
2015 fcport->loop_id = new_fcport->loop_id;
2016 fcport->port_type = new_fcport->port_type;
2017 fcport->d_id.b24 = new_fcport->d_id.b24;
2018 memcpy(fcport->node_name, new_fcport->node_name,
2026 /* New device, add to fcports list. */
2027 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
2028 list_add_tail(&new_fcport->list, &ha->fcports);
2030 /* Allocate a new replacement fcport. */
2031 fcport = new_fcport;
2032 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2033 if (new_fcport == NULL) {
2034 rval = QLA_MEMORY_ALLOC_FAILED;
2035 goto cleanup_allocation;
2037 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2040 qla2x00_update_fcport(ha, fcport);
2048 if (rval != QLA_SUCCESS) {
2049 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2050 "rval=%x\n", ha->host_no, rval));
2054 ha->device_flags |= DFLG_LOCAL_DEVICES;
2055 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2062 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
2066 qla2x00_mark_all_devices_lost(ha, 0);
2067 list_for_each_entry(fcport, &ha->fcports, list) {
2068 if (fcport->port_type != FCT_TARGET)
2071 qla2x00_update_fcport(ha, fcport);
2076 * qla2x00_update_fcport
2077 * Updates device on list.
2080 * ha = adapter block pointer.
2081 * fcport = port structure pointer.
2091 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2094 fcport->login_retry = 0;
2095 fcport->port_login_retry_count = ha->port_down_retry_count *
2097 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2099 fcport->flags &= ~FCF_LOGIN_NEEDED;
2101 if (fcport->port_type == FCT_INITIATOR ||
2102 fcport->port_type == FCT_BROADCAST)
2103 fcport->device_type = TYPE_PROCESSOR;
2105 atomic_set(&fcport->state, FCS_ONLINE);
2107 if (ha->flags.init_done)
2108 qla2x00_reg_remote_port(ha, fcport);
2112 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2114 struct fc_rport_identifiers rport_ids;
2115 struct fc_rport *rport;
2116 unsigned long flags;
2119 qla2x00_rport_del(fcport);
2123 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2124 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2125 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2126 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2127 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2128 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2130 qla_printk(KERN_WARNING, ha,
2131 "Unable to allocate fc remote port!\n");
2134 spin_lock_irqsave(&fcport->rport_lock, flags);
2135 fcport->rport = rport;
2136 *((fc_port_t **)rport->dd_data) = fcport;
2137 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2139 rport->supported_classes = fcport->supported_classes;
2141 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2142 if (fcport->port_type == FCT_INITIATOR)
2143 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2144 if (fcport->port_type == FCT_TARGET)
2145 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2146 fc_remote_port_rolechg(rport, rport_ids.roles);
2148 if (rport->scsi_target_id != -1 &&
2149 rport->scsi_target_id < ha->host->max_id)
2150 fcport->os_target_id = rport->scsi_target_id;
2154 * qla2x00_configure_fabric
2155 * Setup SNS devices with loop ID's.
2158 * ha = adapter block pointer.
2165 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2168 fc_port_t *fcport, *fcptemp;
2169 uint16_t next_loopid;
2170 uint16_t mb[MAILBOX_REGISTER_COUNT];
2172 LIST_HEAD(new_fcports);
2174 /* If FL port exists, then SNS is present */
2175 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2176 loop_id = NPH_F_PORT;
2178 loop_id = SNS_FL_PORT;
2179 rval = qla2x00_get_port_name(ha, loop_id, NULL, 0);
2180 if (rval != QLA_SUCCESS) {
2181 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2182 "Port\n", ha->host_no));
2184 ha->device_flags &= ~SWITCH_FOUND;
2185 return (QLA_SUCCESS);
2188 /* Mark devices that need re-synchronization. */
2189 rval2 = qla2x00_device_resync(ha);
2190 if (rval2 == QLA_RSCNS_HANDLED) {
2191 /* No point doing the scan, just continue. */
2192 return (QLA_SUCCESS);
2196 if (ql2xfdmienable &&
2197 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2198 qla2x00_fdmi_register(ha);
2200 /* Ensure we are logged into the SNS. */
2201 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2204 loop_id = SIMPLE_NAME_SERVER;
2205 ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
2206 0xfc, mb, BIT_1 | BIT_0);
2207 if (mb[0] != MBS_COMMAND_COMPLETE) {
2208 DEBUG2(qla_printk(KERN_INFO, ha,
2209 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2210 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2211 mb[0], mb[1], mb[2], mb[6], mb[7]));
2212 return (QLA_SUCCESS);
2215 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2216 if (qla2x00_rft_id(ha)) {
2218 DEBUG2(printk("scsi(%ld): Register FC-4 "
2219 "TYPE failed.\n", ha->host_no));
2221 if (qla2x00_rff_id(ha)) {
2223 DEBUG2(printk("scsi(%ld): Register FC-4 "
2224 "Features failed.\n", ha->host_no));
2226 if (qla2x00_rnn_id(ha)) {
2228 DEBUG2(printk("scsi(%ld): Register Node Name "
2229 "failed.\n", ha->host_no));
2230 } else if (qla2x00_rsnn_nn(ha)) {
2232 DEBUG2(printk("scsi(%ld): Register Symbolic "
2233 "Node Name failed.\n", ha->host_no));
2237 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2238 if (rval != QLA_SUCCESS)
2242 * Logout all previous fabric devices marked lost, except
2245 list_for_each_entry(fcport, &ha->fcports, list) {
2246 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2249 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2252 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2253 qla2x00_mark_device_lost(ha, fcport,
2254 ql2xplogiabsentdevice, 0);
2255 if (fcport->loop_id != FC_NO_LOOP_ID &&
2256 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2257 fcport->port_type != FCT_INITIATOR &&
2258 fcport->port_type != FCT_BROADCAST) {
2259 ha->isp_ops.fabric_logout(ha,
2261 fcport->d_id.b.domain,
2262 fcport->d_id.b.area,
2263 fcport->d_id.b.al_pa);
2264 fcport->loop_id = FC_NO_LOOP_ID;
2269 /* Starting free loop ID. */
2270 next_loopid = ha->min_external_loopid;
2273 * Scan through our port list and login entries that need to be
2276 list_for_each_entry(fcport, &ha->fcports, list) {
2277 if (atomic_read(&ha->loop_down_timer) ||
2278 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2281 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2282 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2285 if (fcport->loop_id == FC_NO_LOOP_ID) {
2286 fcport->loop_id = next_loopid;
2287 rval = qla2x00_find_new_loop_id(ha, fcport);
2288 if (rval != QLA_SUCCESS) {
2289 /* Ran out of IDs to use */
2293 /* Login and update database */
2294 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2297 /* Exit if out of loop IDs. */
2298 if (rval != QLA_SUCCESS) {
2303 * Login and add the new devices to our port list.
2305 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2306 if (atomic_read(&ha->loop_down_timer) ||
2307 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2310 /* Find a new loop ID to use. */
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 /* Remove device from the new list and add it to DB */
2319 list_del(&fcport->list);
2320 list_add_tail(&fcport->list, &ha->fcports);
2322 /* Login and update database */
2323 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2327 /* Free all new device structures not processed. */
2328 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2329 list_del(&fcport->list);
2334 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2335 "rval=%d\n", ha->host_no, rval));
2343 * qla2x00_find_all_fabric_devs
2346 * ha = adapter block pointer.
2347 * dev = database device entry pointer.
2356 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2360 fc_port_t *fcport, *new_fcport, *fcptemp;
2365 int first_dev, last_dev;
2366 port_id_t wrap, nxt_d_id;
2370 /* Try GID_PT to get device list, else GAN. */
2371 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2374 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2375 "on GA_NXT\n", ha->host_no));
2377 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2378 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2381 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2384 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2391 /* Allocate temporary fcport for any new fcports discovered. */
2392 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2393 if (new_fcport == NULL) {
2395 return (QLA_MEMORY_ALLOC_FAILED);
2397 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2399 /* Set start port ID scan at adapter ID. */
2403 /* Starting free loop ID. */
2404 loop_id = ha->min_external_loopid;
2405 for (; loop_id <= ha->last_loop_id; loop_id++) {
2406 if (qla2x00_is_reserved_id(ha, loop_id))
2409 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2414 wrap.b24 = new_fcport->d_id.b24;
2416 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2417 memcpy(new_fcport->node_name,
2418 swl[swl_idx].node_name, WWN_SIZE);
2419 memcpy(new_fcport->port_name,
2420 swl[swl_idx].port_name, WWN_SIZE);
2422 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2428 /* Send GA_NXT to the switch */
2429 rval = qla2x00_ga_nxt(ha, new_fcport);
2430 if (rval != QLA_SUCCESS) {
2431 qla_printk(KERN_WARNING, ha,
2432 "SNS scan failed -- assuming zero-entry "
2434 list_for_each_entry_safe(fcport, fcptemp,
2435 new_fcports, list) {
2436 list_del(&fcport->list);
2444 /* If wrap on switch device list, exit. */
2446 wrap.b24 = new_fcport->d_id.b24;
2448 } else if (new_fcport->d_id.b24 == wrap.b24) {
2449 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2450 ha->host_no, new_fcport->d_id.b.domain,
2451 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2455 /* Bypass if host adapter. */
2456 if (new_fcport->d_id.b24 == ha->d_id.b24)
2459 /* Bypass if same domain and area of adapter. */
2460 if (((new_fcport->d_id.b24 & 0xffff00) ==
2461 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2465 /* Bypass reserved domain fields. */
2466 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2469 /* Locate matching device in database. */
2471 list_for_each_entry(fcport, &ha->fcports, list) {
2472 if (memcmp(new_fcport->port_name, fcport->port_name,
2479 * If address the same and state FCS_ONLINE, nothing
2482 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2483 atomic_read(&fcport->state) == FCS_ONLINE) {
2488 * If device was not a fabric device before.
2490 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2491 fcport->d_id.b24 = new_fcport->d_id.b24;
2492 fcport->loop_id = FC_NO_LOOP_ID;
2493 fcport->flags |= (FCF_FABRIC_DEVICE |
2495 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2500 * Port ID changed or device was marked to be updated;
2501 * Log it out if still logged in and mark it for
2504 fcport->d_id.b24 = new_fcport->d_id.b24;
2505 fcport->flags |= FCF_LOGIN_NEEDED;
2506 if (fcport->loop_id != FC_NO_LOOP_ID &&
2507 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2508 fcport->port_type != FCT_INITIATOR &&
2509 fcport->port_type != FCT_BROADCAST) {
2510 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2511 fcport->d_id.b.domain, fcport->d_id.b.area,
2512 fcport->d_id.b.al_pa);
2513 fcport->loop_id = FC_NO_LOOP_ID;
2522 /* If device was not in our fcports list, then add it. */
2523 list_add_tail(&new_fcport->list, new_fcports);
2525 /* Allocate a new replacement fcport. */
2526 nxt_d_id.b24 = new_fcport->d_id.b24;
2527 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2528 if (new_fcport == NULL) {
2530 return (QLA_MEMORY_ALLOC_FAILED);
2532 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2533 new_fcport->d_id.b24 = nxt_d_id.b24;
2539 if (!list_empty(new_fcports))
2540 ha->device_flags |= DFLG_FABRIC_DEVICES;
2546 * qla2x00_find_new_loop_id
2547 * Scan through our port list and find a new usable loop ID.
2550 * ha: adapter state pointer.
2551 * dev: port structure pointer.
2554 * qla2x00 local function return status code.
2560 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2565 uint16_t first_loop_id;
2569 /* Save starting loop ID. */
2570 first_loop_id = dev->loop_id;
2573 /* Skip loop ID if already used by adapter. */
2574 if (dev->loop_id == ha->loop_id) {
2578 /* Skip reserved loop IDs. */
2579 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2583 /* Reset loop ID if passed the end. */
2584 if (dev->loop_id > ha->last_loop_id) {
2585 /* first loop ID. */
2586 dev->loop_id = ha->min_external_loopid;
2589 /* Check for loop ID being already in use. */
2592 list_for_each_entry(fcport, &ha->fcports, list) {
2593 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2594 /* ID possibly in use */
2600 /* If not in use then it is free to use. */
2605 /* ID in use. Try next value. */
2608 /* If wrap around. No free ID to use. */
2609 if (dev->loop_id == first_loop_id) {
2610 dev->loop_id = FC_NO_LOOP_ID;
2611 rval = QLA_FUNCTION_FAILED;
2620 * qla2x00_device_resync
2621 * Marks devices in the database that needs resynchronization.
2624 * ha = adapter block pointer.
2630 qla2x00_device_resync(scsi_qla_host_t *ha)
2636 uint32_t rscn_entry;
2637 uint8_t rscn_out_iter;
2641 rval = QLA_RSCNS_HANDLED;
2643 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2644 ha->flags.rscn_queue_overflow) {
2646 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2647 format = MSB(MSW(rscn_entry));
2648 d_id.b.domain = LSB(MSW(rscn_entry));
2649 d_id.b.area = MSB(LSW(rscn_entry));
2650 d_id.b.al_pa = LSB(LSW(rscn_entry));
2652 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2653 "[%02x/%02x%02x%02x].\n",
2654 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2655 d_id.b.area, d_id.b.al_pa));
2658 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2659 ha->rscn_out_ptr = 0;
2661 /* Skip duplicate entries. */
2662 for (rscn_out_iter = ha->rscn_out_ptr;
2663 !ha->flags.rscn_queue_overflow &&
2664 rscn_out_iter != ha->rscn_in_ptr;
2665 rscn_out_iter = (rscn_out_iter ==
2666 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2668 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2671 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2672 "entry found at [%d].\n", ha->host_no,
2675 ha->rscn_out_ptr = rscn_out_iter;
2678 /* Queue overflow, set switch default case. */
2679 if (ha->flags.rscn_queue_overflow) {
2680 DEBUG(printk("scsi(%ld): device_resync: rscn "
2681 "overflow.\n", ha->host_no));
2684 ha->flags.rscn_queue_overflow = 0;
2689 if (ql2xprocessrscn &&
2690 !IS_QLA2100(ha) && !IS_QLA2200(ha) &&
2691 !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
2692 !IS_QLA24XX(ha) && !IS_QLA54XX(ha) &&
2693 ha->flags.init_done) {
2694 /* Handle port RSCN via asyncronous IOCBs */
2695 rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
2697 if (rval2 == QLA_SUCCESS)
2711 ha->rscn_out_ptr = ha->rscn_in_ptr;
2717 /* Abort any outstanding IO descriptors. */
2718 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2719 qla2x00_cancel_io_descriptors(ha);
2721 list_for_each_entry(fcport, &ha->fcports, list) {
2722 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2723 (fcport->d_id.b24 & mask) != d_id.b24 ||
2724 fcport->port_type == FCT_BROADCAST)
2727 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2729 fcport->port_type != FCT_INITIATOR) {
2730 qla2x00_mark_device_lost(ha, fcport,
2734 fcport->flags &= ~FCF_FARP_DONE;
2741 * qla2x00_fabric_dev_login
2742 * Login fabric target device and update FC port database.
2745 * ha: adapter state pointer.
2746 * fcport: port structure list pointer.
2747 * next_loopid: contains value of a new loop ID that can be used
2748 * by the next login attempt.
2751 * qla2x00 local function return status code.
2757 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2758 uint16_t *next_loopid)
2767 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2768 if (rval == QLA_SUCCESS) {
2769 /* Send an ADISC to tape devices.*/
2771 if (fcport->flags & FCF_TAPE_PRESENT)
2773 rval = qla2x00_get_port_database(ha, fcport, opts);
2774 if (rval != QLA_SUCCESS) {
2775 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2776 fcport->d_id.b.domain, fcport->d_id.b.area,
2777 fcport->d_id.b.al_pa);
2778 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2780 qla2x00_update_fcport(ha, fcport);
2788 * qla2x00_fabric_login
2789 * Issue fabric login command.
2792 * ha = adapter block pointer.
2793 * device = pointer to FC device type structure.
2796 * 0 - Login successfully
2798 * 2 - Initiator device
2802 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2803 uint16_t *next_loopid)
2807 uint16_t tmp_loopid;
2808 uint16_t mb[MAILBOX_REGISTER_COUNT];
2814 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2815 "for port %02x%02x%02x.\n",
2816 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2817 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2819 /* Login fcport on switch. */
2820 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2821 fcport->d_id.b.domain, fcport->d_id.b.area,
2822 fcport->d_id.b.al_pa, mb, BIT_0);
2823 if (mb[0] == MBS_PORT_ID_USED) {
2825 * Device has another loop ID. The firmware team
2826 * recommends the driver perform an implicit login with
2827 * the specified ID again. The ID we just used is save
2828 * here so we return with an ID that can be tried by
2832 tmp_loopid = fcport->loop_id;
2833 fcport->loop_id = mb[1];
2835 DEBUG(printk("Fabric Login: port in use - next "
2836 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2837 fcport->loop_id, fcport->d_id.b.domain,
2838 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2840 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2845 /* A retry occurred before. */
2846 *next_loopid = tmp_loopid;
2849 * No retry occurred before. Just increment the
2850 * ID value for next login.
2852 *next_loopid = (fcport->loop_id + 1);
2855 if (mb[1] & BIT_0) {
2856 fcport->port_type = FCT_INITIATOR;
2858 fcport->port_type = FCT_TARGET;
2859 if (mb[1] & BIT_1) {
2860 fcport->flags |= FCF_TAPE_PRESENT;
2865 fcport->supported_classes |= FC_COS_CLASS2;
2867 fcport->supported_classes |= FC_COS_CLASS3;
2871 } else if (mb[0] == MBS_LOOP_ID_USED) {
2873 * Loop ID already used, try next loop ID.
2876 rval = qla2x00_find_new_loop_id(ha, fcport);
2877 if (rval != QLA_SUCCESS) {
2878 /* Ran out of loop IDs to use */
2881 } else if (mb[0] == MBS_COMMAND_ERROR) {
2883 * Firmware possibly timed out during login. If NO
2884 * retries are left to do then the device is declared
2887 *next_loopid = fcport->loop_id;
2888 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2889 fcport->d_id.b.domain, fcport->d_id.b.area,
2890 fcport->d_id.b.al_pa);
2891 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2897 * unrecoverable / not handled error
2899 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2900 "loop_id=%x jiffies=%lx.\n",
2901 __func__, ha->host_no, mb[0],
2902 fcport->d_id.b.domain, fcport->d_id.b.area,
2903 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2905 *next_loopid = fcport->loop_id;
2906 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2907 fcport->d_id.b.domain, fcport->d_id.b.area,
2908 fcport->d_id.b.al_pa);
2909 fcport->loop_id = FC_NO_LOOP_ID;
2910 fcport->login_retry = 0;
2921 * qla2x00_local_device_login
2922 * Issue local device login command.
2925 * ha = adapter block pointer.
2926 * loop_id = loop id of device to login to.
2928 * Returns (Where's the #define!!!!):
2929 * 0 - Login successfully
2934 qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
2937 uint16_t mb[MAILBOX_REGISTER_COUNT];
2939 memset(mb, 0, sizeof(mb));
2940 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
2941 if (rval == QLA_SUCCESS) {
2942 /* Interrogate mailbox registers for any errors */
2943 if (mb[0] == MBS_COMMAND_ERROR)
2945 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
2946 /* device not in PCB table */
2954 * qla2x00_loop_resync
2955 * Resync with fibre channel devices.
2958 * ha = adapter block pointer.
2964 qla2x00_loop_resync(scsi_qla_host_t *ha)
2971 atomic_set(&ha->loop_state, LOOP_UPDATE);
2972 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2973 if (ha->flags.online) {
2974 if (!(rval = qla2x00_fw_ready(ha))) {
2975 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2978 atomic_set(&ha->loop_state, LOOP_UPDATE);
2980 /* Issue a marker after FW becomes ready. */
2981 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
2982 ha->marker_needed = 0;
2984 /* Remap devices on Loop. */
2985 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2987 qla2x00_configure_loop(ha);
2989 } while (!atomic_read(&ha->loop_down_timer) &&
2990 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
2992 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
2996 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2997 return (QLA_FUNCTION_FAILED);
3001 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3008 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
3014 list_for_each_entry(fcport, &ha->fcports, list) {
3015 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
3018 qla2x00_update_fcport(ha, fcport);
3019 fcport->flags &= ~FCF_RESCAN_NEEDED;
3023 qla2x00_probe_for_all_luns(ha);
3027 qla2x00_update_fcports(scsi_qla_host_t *ha)
3031 /* Go with deferred removal of rport references. */
3032 list_for_each_entry(fcport, &ha->fcports, list)
3034 qla2x00_rport_del(fcport);
3039 * Resets ISP and aborts all outstanding commands.
3042 * ha = adapter block pointer.
3048 qla2x00_abort_isp(scsi_qla_host_t *ha)
3050 unsigned long flags = 0;
3055 if (ha->flags.online) {
3056 ha->flags.online = 0;
3057 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3059 qla_printk(KERN_INFO, ha,
3060 "Performing ISP error recovery - ha= %p.\n", ha);
3061 ha->isp_ops.reset_chip(ha);
3063 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3064 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3065 atomic_set(&ha->loop_state, LOOP_DOWN);
3066 qla2x00_mark_all_devices_lost(ha, 0);
3068 if (!atomic_read(&ha->loop_down_timer))
3069 atomic_set(&ha->loop_down_timer,
3073 spin_lock_irqsave(&ha->hardware_lock, flags);
3074 /* Requeue all commands in outstanding command list. */
3075 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3076 sp = ha->outstanding_cmds[cnt];
3078 ha->outstanding_cmds[cnt] = NULL;
3080 sp->cmd->result = DID_RESET << 16;
3081 sp->cmd->host_scribble = (unsigned char *)NULL;
3082 qla2x00_sp_compl(ha, sp);
3085 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3087 ha->isp_ops.nvram_config(ha);
3089 if (!qla2x00_restart_isp(ha)) {
3090 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3092 if (!atomic_read(&ha->loop_down_timer)) {
3094 * Issue marker command only when we are going
3095 * to start the I/O .
3097 ha->marker_needed = 1;
3100 ha->flags.online = 1;
3102 #ifdef FC_TARGET_SUPPORT
3103 /* Enable target response to SCSI bus. */
3104 if (ha->flags.enable_target_mode)
3105 qla2x00_enable_lun(ha);
3108 ha->isp_ops.enable_intrs(ha);
3110 ha->isp_abort_cnt = 0;
3111 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3112 } else { /* failed the ISP abort */
3113 ha->flags.online = 1;
3114 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3115 if (ha->isp_abort_cnt == 0) {
3116 qla_printk(KERN_WARNING, ha,
3117 "ISP error recovery failed - "
3118 "board disabled\n");
3120 * The next call disables the board
3123 ha->isp_ops.reset_adapter(ha);
3124 ha->flags.online = 0;
3125 clear_bit(ISP_ABORT_RETRY,
3128 } else { /* schedule another ISP abort */
3129 ha->isp_abort_cnt--;
3130 DEBUG(printk("qla%ld: ISP abort - "
3131 "retry remaining %d\n",
3132 ha->host_no, ha->isp_abort_cnt);)
3136 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3137 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3138 "- retrying (%d) more times\n",
3139 ha->host_no, ha->isp_abort_cnt);)
3140 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3148 qla_printk(KERN_INFO, ha,
3149 "qla2x00_abort_isp: **** FAILED ****\n");
3151 DEBUG(printk(KERN_INFO
3152 "qla2x00_abort_isp(%ld): exiting.\n",
3160 * qla2x00_restart_isp
3161 * restarts the ISP after a reset
3164 * ha = adapter block pointer.
3170 qla2x00_restart_isp(scsi_qla_host_t *ha)
3173 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3174 unsigned long flags = 0;
3177 /* If firmware needs to be loaded */
3178 if (qla2x00_isp_firmware(ha)) {
3179 ha->flags.online = 0;
3180 if (!(status = ha->isp_ops.chip_diag(ha))) {
3181 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3182 status = qla2x00_setup_chip(ha);
3186 spin_lock_irqsave(&ha->hardware_lock, flags);
3188 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3190 * Disable SRAM, Instruction RAM and GP RAM
3193 WRT_REG_WORD(®->hccr,
3194 (HCCR_ENABLE_PARITY + 0x0));
3195 RD_REG_WORD(®->hccr);
3198 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3200 status = qla2x00_setup_chip(ha);
3202 spin_lock_irqsave(&ha->hardware_lock, flags);
3204 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3205 /* Enable proper parity */
3208 WRT_REG_WORD(®->hccr,
3209 (HCCR_ENABLE_PARITY + 0x1));
3212 * SRAM, Instruction RAM and GP RAM
3215 WRT_REG_WORD(®->hccr,
3216 (HCCR_ENABLE_PARITY + 0x7));
3217 RD_REG_WORD(®->hccr);
3220 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3225 if (!status && !(status = qla2x00_init_rings(ha))) {
3226 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3227 if (!(status = qla2x00_fw_ready(ha))) {
3228 DEBUG(printk("%s(): Start configure loop, "
3229 "status = %d\n", __func__, status);)
3231 /* Issue a marker after FW becomes ready. */
3232 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3234 ha->flags.online = 1;
3235 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3238 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3239 qla2x00_configure_loop(ha);
3241 } while (!atomic_read(&ha->loop_down_timer) &&
3242 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3244 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3247 /* if no cable then assume it's good */
3248 if ((ha->device_flags & DFLG_NO_CABLE))
3251 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3259 * qla2x00_reset_adapter
3263 * ha = adapter block pointer.
3266 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3268 unsigned long flags = 0;
3269 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3271 ha->flags.online = 0;
3272 ha->isp_ops.disable_intrs(ha);
3274 spin_lock_irqsave(&ha->hardware_lock, flags);
3275 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3276 RD_REG_WORD(®->hccr); /* PCI Posting. */
3277 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3278 RD_REG_WORD(®->hccr); /* PCI Posting. */
3279 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3283 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3285 unsigned long flags = 0;
3286 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3288 ha->flags.online = 0;
3289 ha->isp_ops.disable_intrs(ha);
3291 spin_lock_irqsave(&ha->hardware_lock, flags);
3292 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3293 RD_REG_DWORD(®->hccr);
3294 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3295 RD_REG_DWORD(®->hccr);
3296 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3300 qla24xx_nvram_config(scsi_qla_host_t *ha)
3303 struct init_cb_24xx *icb;
3304 struct nvram_24xx *nv;
3306 uint8_t *dptr1, *dptr2;
3311 icb = (struct init_cb_24xx *)ha->init_cb;
3312 nv = (struct nvram_24xx *)ha->request_ring;
3314 /* Determine NVRAM starting address. */
3315 ha->nvram_size = sizeof(struct nvram_24xx);
3316 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3317 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3318 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3319 if (PCI_FUNC(ha->pdev->devfn)) {
3320 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3321 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3324 /* Get NVRAM data and calculate checksum. */
3325 dptr = (uint32_t *)nv;
3326 ha->isp_ops.read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3328 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3329 chksum += le32_to_cpu(*dptr++);
3331 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3332 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3335 /* Bad NVRAM data, set defaults parameters. */
3336 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3337 || nv->id[3] != ' ' ||
3338 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3339 /* Reset NVRAM data. */
3340 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3341 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3342 le16_to_cpu(nv->nvram_version));
3343 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3344 "invalid -- WWPN) defaults.\n");
3347 * Set default initialization control block.
3349 memset(nv, 0, ha->nvram_size);
3350 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3351 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3352 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3353 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3354 nv->exchange_count = __constant_cpu_to_le16(0);
3355 nv->hard_address = __constant_cpu_to_le16(124);
3356 nv->port_name[0] = 0x21;
3357 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3358 nv->port_name[2] = 0x00;
3359 nv->port_name[3] = 0xe0;
3360 nv->port_name[4] = 0x8b;
3361 nv->port_name[5] = 0x1c;
3362 nv->port_name[6] = 0x55;
3363 nv->port_name[7] = 0x86;
3364 nv->node_name[0] = 0x20;
3365 nv->node_name[1] = 0x00;
3366 nv->node_name[2] = 0x00;
3367 nv->node_name[3] = 0xe0;
3368 nv->node_name[4] = 0x8b;
3369 nv->node_name[5] = 0x1c;
3370 nv->node_name[6] = 0x55;
3371 nv->node_name[7] = 0x86;
3372 nv->login_retry_count = __constant_cpu_to_le16(8);
3373 nv->link_down_timeout = __constant_cpu_to_le16(200);
3374 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3375 nv->login_timeout = __constant_cpu_to_le16(0);
3376 nv->firmware_options_1 =
3377 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3378 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3379 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3380 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3381 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3382 nv->efi_parameters = __constant_cpu_to_le32(0);
3383 nv->reset_delay = 5;
3384 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3385 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3386 nv->link_down_timeout = __constant_cpu_to_le16(30);
3391 /* Reset Initialization control block */
3392 memset(icb, 0, sizeof(struct init_cb_24xx));
3394 /* Copy 1st segment. */
3395 dptr1 = (uint8_t *)icb;
3396 dptr2 = (uint8_t *)&nv->version;
3397 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3399 *dptr1++ = *dptr2++;
3401 icb->login_retry_count = nv->login_retry_count;
3402 icb->link_down_timeout = nv->link_down_timeout;
3404 /* Copy 2nd segment. */
3405 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3406 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3407 cnt = (uint8_t *)&icb->reserved_3 -
3408 (uint8_t *)&icb->interrupt_delay_timer;
3410 *dptr1++ = *dptr2++;
3413 * Setup driver NVRAM options.
3415 if (memcmp(nv->model_name, BINZERO, sizeof(nv->model_name)) != 0) {
3419 strncpy(ha->model_number, nv->model_name,
3420 sizeof(nv->model_name));
3421 st = en = ha->model_number;
3422 en += sizeof(nv->model_name) - 1;
3424 if (*en != 0x20 && *en != 0x00)
3429 index = (ha->pdev->subsystem_device & 0xff);
3430 if (index < QLA_MODEL_NAMES)
3431 ha->model_desc = qla2x00_model_name[index * 2 + 1];
3433 strcpy(ha->model_number, "QLA2462");
3435 /* Prepare nodename */
3436 if ((icb->firmware_options_1 & BIT_14) == 0) {
3438 * Firmware will apply the following mask if the nodename was
3441 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3442 icb->node_name[0] &= 0xF0;
3445 /* Set host adapter parameters. */
3446 ha->flags.disable_risc_code_load = 0;
3447 ha->flags.enable_lip_reset = 1;
3448 ha->flags.enable_lip_full_login = 1;
3449 ha->flags.enable_target_reset = 1;
3450 ha->flags.enable_led_scheme = 0;
3452 ha->operating_mode =
3453 (icb->firmware_options_2 & (BIT_6 | BIT_5 | BIT_4)) >> 4;
3455 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3456 sizeof(ha->fw_seriallink_options24));
3458 /* save HBA serial number */
3459 ha->serial0 = icb->port_name[5];
3460 ha->serial1 = icb->port_name[6];
3461 ha->serial2 = icb->port_name[7];
3462 ha->node_name = icb->node_name;
3463 ha->port_name = icb->port_name;
3465 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3467 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3469 /* Set minimum login_timeout to 4 seconds. */
3470 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3471 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3472 if (le16_to_cpu(nv->login_timeout) < 4)
3473 nv->login_timeout = __constant_cpu_to_le16(4);
3474 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3475 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3477 /* Set minimum RATOV to 200 tenths of a second. */
3480 ha->loop_reset_delay = nv->reset_delay;
3482 /* Link Down Timeout = 0:
3484 * When Port Down timer expires we will start returning
3485 * I/O's to OS with "DID_NO_CONNECT".
3487 * Link Down Timeout != 0:
3489 * The driver waits for the link to come up after link down
3490 * before returning I/Os to OS with "DID_NO_CONNECT".
3492 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3493 ha->loop_down_abort_time =
3494 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3496 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3497 ha->loop_down_abort_time =
3498 (LOOP_DOWN_TIME - ha->link_down_timeout);
3501 /* Need enough time to try and get the port back. */
3502 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3503 if (qlport_down_retry)
3504 ha->port_down_retry_count = qlport_down_retry;
3506 /* Set login_retry_count */
3507 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3508 if (ha->port_down_retry_count ==
3509 le16_to_cpu(nv->port_down_retry_count) &&
3510 ha->port_down_retry_count > 3)
3511 ha->login_retry_count = ha->port_down_retry_count;
3512 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3513 ha->login_retry_count = ha->port_down_retry_count;
3514 if (ql2xloginretrycount)
3515 ha->login_retry_count = ql2xloginretrycount;
3518 if (!ha->flags.init_done) {
3519 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3520 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3521 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3522 le16_to_cpu(icb->interrupt_delay_timer): 2;
3524 icb->firmware_options_2 &= __constant_cpu_to_le32(
3525 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3526 ha->flags.process_response_queue = 0;
3527 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3528 ha->zio_mode = QLA_ZIO_MODE_6;
3530 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3531 "(%d us).\n", ha->host_no, ha->zio_mode,
3532 ha->zio_timer * 100));
3533 qla_printk(KERN_INFO, ha,
3534 "ZIO mode %d enabled; timer delay (%d us).\n",
3535 ha->zio_mode, ha->zio_timer * 100);
3537 icb->firmware_options_2 |= cpu_to_le32(
3538 (uint32_t)ha->zio_mode);
3539 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3540 ha->flags.process_response_queue = 1;
3544 DEBUG2_3(printk(KERN_WARNING
3545 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3550 #if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
3553 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3557 uint16_t *risc_code;
3558 uint32_t risc_addr, risc_size;
3560 struct qla_fw_info *fw_iter;
3564 /* Load firmware sequences */
3565 fw_iter = ha->brd_info->fw_info;
3566 *srisc_addr = *ha->brd_info->fw_info->fwstart;
3567 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
3568 risc_code = fw_iter->fwcode;
3569 risc_size = *fw_iter->fwlen;
3570 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL)