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>
11 #include <linux/firmware.h>
12 #include <scsi/scsi_transport_fc.h>
14 #include "qla_devtbl.h"
16 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
17 #ifndef EXT_IS_LUN_BIT_SET
18 #define EXT_IS_LUN_BIT_SET(P,L) \
19 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
20 #define EXT_SET_LUN_BIT(P,L) \
21 ((P)->mask[L/8] |= (0x80 >> (L%8)))
25 * QLogic ISP2x00 Hardware Support Function Prototypes.
27 static int qla2x00_isp_firmware(scsi_qla_host_t *);
28 static void qla2x00_resize_request_q(scsi_qla_host_t *);
29 static int qla2x00_setup_chip(scsi_qla_host_t *);
30 static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
31 static int qla2x00_init_rings(scsi_qla_host_t *);
32 static int qla2x00_fw_ready(scsi_qla_host_t *);
33 static int qla2x00_configure_hba(scsi_qla_host_t *);
34 static int qla2x00_configure_loop(scsi_qla_host_t *);
35 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
36 static void qla2x00_update_fcport(scsi_qla_host_t *, fc_port_t *);
37 static int qla2x00_configure_fabric(scsi_qla_host_t *);
38 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
39 static int qla2x00_device_resync(scsi_qla_host_t *);
40 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_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_DOWN && 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 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
183 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
186 * Returns 0 on success.
189 qla2100_pci_config(scsi_qla_host_t *ha)
194 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
196 pci_set_master(ha->pdev);
198 if (pci_set_mwi(ha->pdev))
199 mwi = PCI_COMMAND_INVALIDATE;
200 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
202 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
203 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
204 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
206 /* Reset expansion ROM address decode enable */
207 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
208 d &= ~PCI_ROM_ADDRESS_ENABLE;
209 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
211 /* Get PCI bus information. */
212 spin_lock_irqsave(&ha->hardware_lock, flags);
213 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
214 spin_unlock_irqrestore(&ha->hardware_lock, flags);
220 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
223 * Returns 0 on success.
226 qla2300_pci_config(scsi_qla_host_t *ha)
230 unsigned long flags = 0;
232 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
234 pci_set_master(ha->pdev);
236 if (pci_set_mwi(ha->pdev))
237 mwi = PCI_COMMAND_INVALIDATE;
238 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
240 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
241 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
243 if (IS_QLA2322(ha) || IS_QLA6322(ha))
244 w &= ~PCI_COMMAND_INTX_DISABLE;
247 * If this is a 2300 card and not 2312, reset the
248 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
249 * the 2310 also reports itself as a 2300 so we need to get the
250 * fb revision level -- a 6 indicates it really is a 2300 and
253 if (IS_QLA2300(ha)) {
254 spin_lock_irqsave(&ha->hardware_lock, flags);
257 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
258 for (cnt = 0; cnt < 30000; cnt++) {
259 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
265 /* Select FPM registers. */
266 WRT_REG_WORD(®->ctrl_status, 0x20);
267 RD_REG_WORD(®->ctrl_status);
269 /* Get the fb rev level */
270 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
272 if (ha->fb_rev == FPM_2300)
273 w &= ~PCI_COMMAND_INVALIDATE;
275 /* Deselect FPM registers. */
276 WRT_REG_WORD(®->ctrl_status, 0x0);
277 RD_REG_WORD(®->ctrl_status);
279 /* Release RISC module. */
280 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
281 for (cnt = 0; cnt < 30000; cnt++) {
282 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
288 spin_unlock_irqrestore(&ha->hardware_lock, flags);
290 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
292 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
294 /* Reset expansion ROM address decode enable */
295 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
296 d &= ~PCI_ROM_ADDRESS_ENABLE;
297 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
299 /* Get PCI bus information. */
300 spin_lock_irqsave(&ha->hardware_lock, flags);
301 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
302 spin_unlock_irqrestore(&ha->hardware_lock, flags);
308 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
311 * Returns 0 on success.
314 qla24xx_pci_config(scsi_qla_host_t *ha)
318 unsigned long flags = 0;
319 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
320 int pcix_cmd_reg, pcie_dctl_reg;
322 pci_set_master(ha->pdev);
324 if (pci_set_mwi(ha->pdev))
325 mwi = PCI_COMMAND_INVALIDATE;
326 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
328 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
329 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
330 w &= ~PCI_COMMAND_INTX_DISABLE;
331 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
333 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
335 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
336 pcix_cmd_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX);
340 pcix_cmd_reg += PCI_X_CMD;
341 pci_read_config_word(ha->pdev, pcix_cmd_reg, &pcix_cmd);
342 pcix_cmd &= ~PCI_X_CMD_MAX_READ;
344 pci_write_config_word(ha->pdev, pcix_cmd_reg, pcix_cmd);
347 /* PCIe -- adjust Maximum Read Request Size (2048). */
348 pcie_dctl_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
352 pcie_dctl_reg += PCI_EXP_DEVCTL;
353 pci_read_config_word(ha->pdev, pcie_dctl_reg, &pcie_dctl);
354 pcie_dctl &= ~PCI_EXP_DEVCTL_READRQ;
356 pci_write_config_word(ha->pdev, pcie_dctl_reg, pcie_dctl);
359 /* Reset expansion ROM address decode enable */
360 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
361 d &= ~PCI_ROM_ADDRESS_ENABLE;
362 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
364 /* Get PCI bus information. */
365 spin_lock_irqsave(&ha->hardware_lock, flags);
366 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
367 spin_unlock_irqrestore(&ha->hardware_lock, flags);
373 * qla2x00_isp_firmware() - Choose firmware image.
376 * Returns 0 on success.
379 qla2x00_isp_firmware(scsi_qla_host_t *ha)
383 /* Assume loading risc code */
384 rval = QLA_FUNCTION_FAILED;
386 if (ha->flags.disable_risc_code_load) {
387 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
389 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
391 /* Verify checksum of loaded RISC code. */
392 rval = qla2x00_verify_checksum(ha,
393 IS_QLA24XX(ha) || IS_QLA25XX(ha) ? RISC_SADDRESS :
394 *ha->brd_info->fw_info[0].fwstart);
398 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
406 * qla2x00_reset_chip() - Reset ISP chip.
409 * Returns 0 on success.
412 qla2x00_reset_chip(scsi_qla_host_t *ha)
414 unsigned long flags = 0;
415 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
417 unsigned long mbx_flags = 0;
420 ha->isp_ops.disable_intrs(ha);
422 spin_lock_irqsave(&ha->hardware_lock, flags);
424 /* Turn off master enable */
426 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
427 cmd &= ~PCI_COMMAND_MASTER;
428 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
430 if (!IS_QLA2100(ha)) {
432 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
433 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
434 for (cnt = 0; cnt < 30000; cnt++) {
435 if ((RD_REG_WORD(®->hccr) &
436 HCCR_RISC_PAUSE) != 0)
441 RD_REG_WORD(®->hccr); /* PCI Posting. */
445 /* Select FPM registers. */
446 WRT_REG_WORD(®->ctrl_status, 0x20);
447 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
449 /* FPM Soft Reset. */
450 WRT_REG_WORD(®->fpm_diag_config, 0x100);
451 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
453 /* Toggle Fpm Reset. */
454 if (!IS_QLA2200(ha)) {
455 WRT_REG_WORD(®->fpm_diag_config, 0x0);
456 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
459 /* Select frame buffer registers. */
460 WRT_REG_WORD(®->ctrl_status, 0x10);
461 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
463 /* Reset frame buffer FIFOs. */
464 if (IS_QLA2200(ha)) {
465 WRT_FB_CMD_REG(ha, reg, 0xa000);
466 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
468 WRT_FB_CMD_REG(ha, reg, 0x00fc);
470 /* Read back fb_cmd until zero or 3 seconds max */
471 for (cnt = 0; cnt < 3000; cnt++) {
472 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
478 /* Select RISC module registers. */
479 WRT_REG_WORD(®->ctrl_status, 0);
480 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
482 /* Reset RISC processor. */
483 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
484 RD_REG_WORD(®->hccr); /* PCI Posting. */
486 /* Release RISC processor. */
487 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
488 RD_REG_WORD(®->hccr); /* PCI Posting. */
491 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
492 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
494 /* Reset ISP chip. */
495 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
497 /* Wait for RISC to recover from reset. */
498 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
500 * It is necessary to for a delay here since the card doesn't
501 * respond to PCI reads during a reset. On some architectures
502 * this will result in an MCA.
505 for (cnt = 30000; cnt; cnt--) {
506 if ((RD_REG_WORD(®->ctrl_status) &
507 CSR_ISP_SOFT_RESET) == 0)
514 /* Reset RISC processor. */
515 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
517 WRT_REG_WORD(®->semaphore, 0);
519 /* Release RISC processor. */
520 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
521 RD_REG_WORD(®->hccr); /* PCI Posting. */
523 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
524 for (cnt = 0; cnt < 30000; cnt++) {
525 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
526 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
528 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) {
529 if (!(test_bit(ABORT_ISP_ACTIVE,
531 spin_unlock_irqrestore(
532 &ha->mbx_reg_lock, mbx_flags);
536 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
537 spin_unlock_irqrestore(&ha->mbx_reg_lock,
545 /* Turn on master enable */
546 cmd |= PCI_COMMAND_MASTER;
547 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
549 /* Disable RISC pause on FPM parity error. */
550 if (!IS_QLA2100(ha)) {
551 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
552 RD_REG_WORD(®->hccr); /* PCI Posting. */
555 spin_unlock_irqrestore(&ha->hardware_lock, flags);
559 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
562 * Returns 0 on success.
565 qla24xx_reset_risc(scsi_qla_host_t *ha)
567 unsigned long flags = 0;
568 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
571 spin_lock_irqsave(&ha->hardware_lock, flags);
574 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
575 for (cnt = 0; cnt < 30000; cnt++) {
576 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
582 WRT_REG_DWORD(®->ctrl_status,
583 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
584 RD_REG_DWORD(®->ctrl_status);
586 /* Wait for firmware to complete NVRAM accesses. */
588 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
589 for (cnt = 10000 ; cnt && d2; cnt--) {
591 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
596 d2 = RD_REG_DWORD(®->ctrl_status);
597 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
599 d2 = RD_REG_DWORD(®->ctrl_status);
603 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
604 RD_REG_DWORD(®->hccr);
606 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
607 RD_REG_DWORD(®->hccr);
609 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
610 RD_REG_DWORD(®->hccr);
612 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
613 for (cnt = 6000000 ; cnt && d2; cnt--) {
615 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
619 spin_unlock_irqrestore(&ha->hardware_lock, flags);
623 * qla24xx_reset_chip() - Reset ISP24xx chip.
626 * Returns 0 on success.
629 qla24xx_reset_chip(scsi_qla_host_t *ha)
631 ha->isp_ops.disable_intrs(ha);
633 /* Perform RISC reset. */
634 qla24xx_reset_risc(ha);
638 * qla2x00_chip_diag() - Test chip for proper operation.
641 * Returns 0 on success.
644 qla2x00_chip_diag(scsi_qla_host_t *ha)
647 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
648 unsigned long flags = 0;
653 /* Assume a failed state */
654 rval = QLA_FUNCTION_FAILED;
656 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
657 ha->host_no, (u_long)®->flash_address));
659 spin_lock_irqsave(&ha->hardware_lock, flags);
661 /* Reset ISP chip. */
662 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
665 * We need to have a delay here since the card will not respond while
666 * in reset causing an MCA on some architectures.
669 data = qla2x00_debounce_register(®->ctrl_status);
670 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
672 data = RD_REG_WORD(®->ctrl_status);
677 goto chip_diag_failed;
679 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
682 /* Reset RISC processor. */
683 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
684 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
686 /* Workaround for QLA2312 PCI parity error */
687 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
688 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
689 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
691 data = RD_MAILBOX_REG(ha, reg, 0);
698 goto chip_diag_failed;
700 /* Check product ID of chip */
701 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
703 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
704 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
705 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
706 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
707 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
708 mb[3] != PROD_ID_3) {
709 qla_printk(KERN_WARNING, ha,
710 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
712 goto chip_diag_failed;
714 ha->product_id[0] = mb[1];
715 ha->product_id[1] = mb[2];
716 ha->product_id[2] = mb[3];
717 ha->product_id[3] = mb[4];
719 /* Adjust fw RISC transfer size */
720 if (ha->request_q_length > 1024)
721 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
723 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
724 ha->request_q_length;
726 if (IS_QLA2200(ha) &&
727 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
728 /* Limit firmware transfer size with a 2200A */
729 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
732 ha->fw_transfer_size = 128;
735 /* Wrap Incoming Mailboxes Test. */
736 spin_unlock_irqrestore(&ha->hardware_lock, flags);
738 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
739 rval = qla2x00_mbx_reg_test(ha);
741 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
743 qla_printk(KERN_WARNING, ha,
744 "Failed mailbox send register test\n");
747 /* Flag a successful rval */
750 spin_lock_irqsave(&ha->hardware_lock, flags);
754 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
755 "****\n", ha->host_no));
757 spin_unlock_irqrestore(&ha->hardware_lock, flags);
763 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
766 * Returns 0 on success.
769 qla24xx_chip_diag(scsi_qla_host_t *ha)
773 /* Perform RISC reset. */
774 qla24xx_reset_risc(ha);
776 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
778 rval = qla2x00_mbx_reg_test(ha);
780 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
782 qla_printk(KERN_WARNING, ha,
783 "Failed mailbox send register test\n");
785 /* Flag a successful rval */
793 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
796 ha->fw_dump24_len = sizeof(struct qla24xx_fw_dump);
797 ha->fw_dump24_len += (ha->fw_memory_size - 0x100000) * sizeof(uint32_t);
798 ha->fw_dump24 = vmalloc(ha->fw_dump24_len);
800 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware "
801 "dump...\n", ha->fw_dump24_len / 1024);
803 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
804 "firmware dump!!!\n", ha->fw_dump24_len / 1024);
808 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
811 * Returns 0 on success.
814 qla2x00_resize_request_q(scsi_qla_host_t *ha)
817 uint16_t fw_iocb_cnt = 0;
818 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
819 dma_addr_t request_dma;
820 request_t *request_ring;
822 /* Valid only on recent ISPs. */
823 if (IS_QLA2100(ha) || IS_QLA2200(ha))
826 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
827 qla2x00_alloc_fw_dump(ha);
829 /* Retrieve IOCB counts available to the firmware. */
830 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
833 /* No point in continuing if current settings are sufficient. */
834 if (fw_iocb_cnt < 1024)
836 if (ha->request_q_length >= request_q_length)
839 /* Attempt to claim larger area for request queue. */
840 request_ring = dma_alloc_coherent(&ha->pdev->dev,
841 (request_q_length + 1) * sizeof(request_t), &request_dma,
843 if (request_ring == NULL)
846 /* Resize successful, report extensions. */
847 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
848 (ha->fw_memory_size + 1) / 1024);
849 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
850 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
852 /* Clear old allocations. */
853 dma_free_coherent(&ha->pdev->dev,
854 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
857 /* Begin using larger queue. */
858 ha->request_q_length = request_q_length;
859 ha->request_ring = request_ring;
860 ha->request_dma = request_dma;
864 * qla2x00_setup_chip() - Load and start RISC firmware.
867 * Returns 0 on success.
870 qla2x00_setup_chip(scsi_qla_host_t *ha)
873 uint32_t srisc_address = 0;
875 /* Load firmware sequences */
876 rval = ha->isp_ops.load_risc(ha, &srisc_address);
877 if (rval == QLA_SUCCESS) {
878 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
879 "code.\n", ha->host_no));
881 rval = qla2x00_verify_checksum(ha, srisc_address);
882 if (rval == QLA_SUCCESS) {
883 /* Start firmware execution. */
884 DEBUG(printk("scsi(%ld): Checksum OK, start "
885 "firmware.\n", ha->host_no));
887 rval = qla2x00_execute_fw(ha, srisc_address);
888 /* Retrieve firmware information. */
889 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
890 qla2x00_get_fw_version(ha,
891 &ha->fw_major_version,
892 &ha->fw_minor_version,
893 &ha->fw_subminor_version,
894 &ha->fw_attributes, &ha->fw_memory_size);
895 qla2x00_resize_request_q(ha);
898 DEBUG2(printk(KERN_INFO
899 "scsi(%ld): ISP Firmware failed checksum.\n",
905 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
913 * qla2x00_init_response_q_entries() - Initializes response queue entries.
916 * Beginning of request ring has initialization control block already built
917 * by nvram config routine.
919 * Returns 0 on success.
922 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
927 pkt = ha->response_ring_ptr;
928 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
929 pkt->signature = RESPONSE_PROCESSED;
936 * qla2x00_update_fw_options() - Read and process firmware options.
939 * Returns 0 on success.
942 qla2x00_update_fw_options(scsi_qla_host_t *ha)
944 uint16_t swing, emphasis, tx_sens, rx_sens;
946 memset(ha->fw_options, 0, sizeof(ha->fw_options));
947 qla2x00_get_fw_options(ha, ha->fw_options);
949 if (IS_QLA2100(ha) || IS_QLA2200(ha))
952 /* Serial Link options. */
953 DEBUG3(printk("scsi(%ld): Serial link options:\n",
955 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
956 sizeof(ha->fw_seriallink_options)));
958 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
959 if (ha->fw_seriallink_options[3] & BIT_2) {
960 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
963 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
964 emphasis = (ha->fw_seriallink_options[2] &
965 (BIT_4 | BIT_3)) >> 3;
966 tx_sens = ha->fw_seriallink_options[0] &
967 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
968 rx_sens = (ha->fw_seriallink_options[0] &
969 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
970 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
971 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
974 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
975 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
976 ha->fw_options[10] |= BIT_5 |
977 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
978 (tx_sens & (BIT_1 | BIT_0));
981 swing = (ha->fw_seriallink_options[2] &
982 (BIT_7 | BIT_6 | BIT_5)) >> 5;
983 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
984 tx_sens = ha->fw_seriallink_options[1] &
985 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
986 rx_sens = (ha->fw_seriallink_options[1] &
987 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
988 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
989 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
992 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
993 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
994 ha->fw_options[11] |= BIT_5 |
995 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
996 (tx_sens & (BIT_1 | BIT_0));
1000 /* Return command IOCBs without waiting for an ABTS to complete. */
1001 ha->fw_options[3] |= BIT_13;
1004 if (ha->flags.enable_led_scheme)
1005 ha->fw_options[2] |= BIT_12;
1007 /* Update firmware options. */
1008 qla2x00_set_fw_options(ha, ha->fw_options);
1012 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1016 /* Update Serial Link options. */
1017 if ((ha->fw_seriallink_options24[0] & BIT_0) == 0)
1020 rval = qla2x00_set_serdes_params(ha, ha->fw_seriallink_options24[1],
1021 ha->fw_seriallink_options24[2], ha->fw_seriallink_options24[3]);
1022 if (rval != QLA_SUCCESS) {
1023 qla_printk(KERN_WARNING, ha,
1024 "Unable to update Serial Link options (%x).\n", rval);
1029 qla2x00_config_rings(struct scsi_qla_host *ha)
1031 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1033 /* Setup ring parameters in initialization control block. */
1034 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1035 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1036 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1037 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1038 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1039 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1040 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1041 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1043 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1044 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1045 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1046 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1047 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1051 qla24xx_config_rings(struct scsi_qla_host *ha)
1053 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1054 struct init_cb_24xx *icb;
1056 /* Setup ring parameters in initialization control block. */
1057 icb = (struct init_cb_24xx *)ha->init_cb;
1058 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1059 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1060 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1061 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1062 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1063 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1064 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1065 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1067 WRT_REG_DWORD(®->req_q_in, 0);
1068 WRT_REG_DWORD(®->req_q_out, 0);
1069 WRT_REG_DWORD(®->rsp_q_in, 0);
1070 WRT_REG_DWORD(®->rsp_q_out, 0);
1071 RD_REG_DWORD(®->rsp_q_out);
1075 * qla2x00_init_rings() - Initializes firmware.
1078 * Beginning of request ring has initialization control block already built
1079 * by nvram config routine.
1081 * Returns 0 on success.
1084 qla2x00_init_rings(scsi_qla_host_t *ha)
1087 unsigned long flags = 0;
1090 spin_lock_irqsave(&ha->hardware_lock, flags);
1092 /* Clear outstanding commands array. */
1093 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1094 ha->outstanding_cmds[cnt] = NULL;
1096 ha->current_outstanding_cmd = 0;
1098 /* Clear RSCN queue. */
1099 ha->rscn_in_ptr = 0;
1100 ha->rscn_out_ptr = 0;
1102 /* Initialize firmware. */
1103 ha->request_ring_ptr = ha->request_ring;
1104 ha->req_ring_index = 0;
1105 ha->req_q_cnt = ha->request_q_length;
1106 ha->response_ring_ptr = ha->response_ring;
1107 ha->rsp_ring_index = 0;
1109 /* Initialize response queue entries */
1110 qla2x00_init_response_q_entries(ha);
1112 ha->isp_ops.config_rings(ha);
1114 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1116 /* Update any ISP specific firmware options before initialization. */
1117 ha->isp_ops.update_fw_options(ha);
1119 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1120 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1122 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1125 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1133 * qla2x00_fw_ready() - Waits for firmware ready.
1136 * Returns 0 on success.
1139 qla2x00_fw_ready(scsi_qla_host_t *ha)
1142 unsigned long wtime, mtime;
1143 uint16_t min_wait; /* Minimum wait time if loop is down */
1144 uint16_t wait_time; /* Wait time if loop is coming ready */
1149 /* 20 seconds for loop down. */
1153 * Firmware should take at most one RATOV to login, plus 5 seconds for
1154 * our own processing.
1156 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1157 wait_time = min_wait;
1160 /* Min wait time if loop down */
1161 mtime = jiffies + (min_wait * HZ);
1163 /* wait time before firmware ready */
1164 wtime = jiffies + (wait_time * HZ);
1166 /* Wait for ISP to finish LIP */
1167 if (!ha->flags.init_done)
1168 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1170 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1174 rval = qla2x00_get_firmware_state(ha, &fw_state);
1175 if (rval == QLA_SUCCESS) {
1176 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1177 ha->device_flags &= ~DFLG_NO_CABLE;
1179 if (fw_state == FSTATE_READY) {
1180 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1183 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1184 &ha->login_timeout, &ha->r_a_tov);
1190 rval = QLA_FUNCTION_FAILED;
1192 if (atomic_read(&ha->loop_down_timer) &&
1193 (fw_state >= FSTATE_LOSS_OF_SYNC ||
1194 fw_state == FSTATE_WAIT_AL_PA)) {
1195 /* Loop down. Timeout on min_wait for states
1196 * other than Wait for Login.
1198 if (time_after_eq(jiffies, mtime)) {
1199 qla_printk(KERN_INFO, ha,
1200 "Cable is unplugged...\n");
1202 ha->device_flags |= DFLG_NO_CABLE;
1207 /* Mailbox cmd failed. Timeout on min_wait. */
1208 if (time_after_eq(jiffies, mtime))
1212 if (time_after_eq(jiffies, wtime))
1215 /* Delay for a while */
1218 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1219 ha->host_no, fw_state, jiffies));
1222 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1223 ha->host_no, fw_state, jiffies));
1226 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1234 * qla2x00_configure_hba
1235 * Setup adapter context.
1238 * ha = adapter state pointer.
1247 qla2x00_configure_hba(scsi_qla_host_t *ha)
1255 char connect_type[22];
1257 /* Get host addresses. */
1258 rval = qla2x00_get_adapter_id(ha,
1259 &loop_id, &al_pa, &area, &domain, &topo);
1260 if (rval != QLA_SUCCESS) {
1261 qla_printk(KERN_WARNING, ha,
1262 "ERROR -- Unable to get host loop ID.\n");
1263 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1268 qla_printk(KERN_INFO, ha,
1269 "Cannot get topology - retrying.\n");
1270 return (QLA_FUNCTION_FAILED);
1273 ha->loop_id = loop_id;
1276 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1277 ha->operating_mode = LOOP;
1281 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1283 ha->current_topology = ISP_CFG_NL;
1284 strcpy(connect_type, "(Loop)");
1288 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1290 ha->current_topology = ISP_CFG_FL;
1291 strcpy(connect_type, "(FL_Port)");
1295 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1297 ha->operating_mode = P2P;
1298 ha->current_topology = ISP_CFG_N;
1299 strcpy(connect_type, "(N_Port-to-N_Port)");
1303 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1305 ha->operating_mode = P2P;
1306 ha->current_topology = ISP_CFG_F;
1307 strcpy(connect_type, "(F_Port)");
1311 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1313 ha->host_no, topo));
1314 ha->current_topology = ISP_CFG_NL;
1315 strcpy(connect_type, "(Loop)");
1319 /* Save Host port and loop ID. */
1320 /* byte order - Big Endian */
1321 ha->d_id.b.domain = domain;
1322 ha->d_id.b.area = area;
1323 ha->d_id.b.al_pa = al_pa;
1325 if (!ha->flags.init_done)
1326 qla_printk(KERN_INFO, ha,
1327 "Topology - %s, Host Loop address 0x%x\n",
1328 connect_type, ha->loop_id);
1331 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1333 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1340 * NVRAM configuration for ISP 2xxx
1343 * ha = adapter block pointer.
1346 * initialization control block in response_ring
1347 * host adapters parameters in host adapter block
1353 qla2x00_nvram_config(scsi_qla_host_t *ha)
1358 uint8_t *dptr1, *dptr2;
1359 init_cb_t *icb = ha->init_cb;
1360 nvram_t *nv = (nvram_t *)ha->request_ring;
1361 uint8_t *ptr = (uint8_t *)ha->request_ring;
1362 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1366 /* Determine NVRAM starting address. */
1367 ha->nvram_size = sizeof(nvram_t);
1369 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1370 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1371 ha->nvram_base = 0x80;
1373 /* Get NVRAM data and calculate checksum. */
1374 ha->isp_ops.read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1375 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1378 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1379 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1382 /* Bad NVRAM data, set defaults parameters. */
1383 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1384 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1385 /* Reset NVRAM data. */
1386 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1387 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1389 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1390 "invalid -- WWPN) defaults.\n");
1393 * Set default initialization control block.
1395 memset(nv, 0, ha->nvram_size);
1396 nv->parameter_block_version = ICB_VERSION;
1398 if (IS_QLA23XX(ha)) {
1399 nv->firmware_options[0] = BIT_2 | BIT_1;
1400 nv->firmware_options[1] = BIT_7 | BIT_5;
1401 nv->add_firmware_options[0] = BIT_5;
1402 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1403 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1404 nv->special_options[1] = BIT_7;
1405 } else if (IS_QLA2200(ha)) {
1406 nv->firmware_options[0] = BIT_2 | BIT_1;
1407 nv->firmware_options[1] = BIT_7 | BIT_5;
1408 nv->add_firmware_options[0] = BIT_5;
1409 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1410 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1411 } else if (IS_QLA2100(ha)) {
1412 nv->firmware_options[0] = BIT_3 | BIT_1;
1413 nv->firmware_options[1] = BIT_5;
1414 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1417 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1418 nv->execution_throttle = __constant_cpu_to_le16(16);
1419 nv->retry_count = 8;
1420 nv->retry_delay = 1;
1422 nv->port_name[0] = 33;
1423 nv->port_name[3] = 224;
1424 nv->port_name[4] = 139;
1426 nv->login_timeout = 4;
1429 * Set default host adapter parameters
1431 nv->host_p[1] = BIT_2;
1432 nv->reset_delay = 5;
1433 nv->port_down_retry_count = 8;
1434 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1435 nv->link_down_timeout = 60;
1440 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1442 * The SN2 does not provide BIOS emulation which means you can't change
1443 * potentially bogus BIOS settings. Force the use of default settings
1444 * for link rate and frame size. Hope that the rest of the settings
1447 if (ia64_platform_is("sn2")) {
1448 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1450 nv->special_options[1] = BIT_7;
1454 /* Reset Initialization control block */
1455 memset(icb, 0, ha->init_cb_size);
1458 * Setup driver NVRAM options.
1460 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1461 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1462 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1463 nv->firmware_options[1] &= ~BIT_4;
1465 if (IS_QLA23XX(ha)) {
1466 nv->firmware_options[0] |= BIT_2;
1467 nv->firmware_options[0] &= ~BIT_3;
1468 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1470 if (IS_QLA2300(ha)) {
1471 if (ha->fb_rev == FPM_2310) {
1472 strcpy(ha->model_number, "QLA2310");
1474 strcpy(ha->model_number, "QLA2300");
1478 memcmp(nv->model_number, BINZERO,
1479 sizeof(nv->model_number)) != 0) {
1482 strncpy(ha->model_number, nv->model_number,
1483 sizeof(nv->model_number));
1484 st = en = ha->model_number;
1485 en += sizeof(nv->model_number) - 1;
1487 if (*en != 0x20 && *en != 0x00)
1494 index = (ha->pdev->subsystem_device & 0xff);
1495 if (index < QLA_MODEL_NAMES) {
1496 strcpy(ha->model_number,
1497 qla2x00_model_name[index]);
1499 qla2x00_model_desc[index];
1501 strcpy(ha->model_number, "QLA23xx");
1505 } else if (IS_QLA2200(ha)) {
1506 nv->firmware_options[0] |= BIT_2;
1508 * 'Point-to-point preferred, else loop' is not a safe
1509 * connection mode setting.
1511 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1513 /* Force 'loop preferred, else point-to-point'. */
1514 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1515 nv->add_firmware_options[0] |= BIT_5;
1517 strcpy(ha->model_number, "QLA22xx");
1518 } else /*if (IS_QLA2100(ha))*/ {
1519 strcpy(ha->model_number, "QLA2100");
1523 * Copy over NVRAM RISC parameter block to initialization control block.
1525 dptr1 = (uint8_t *)icb;
1526 dptr2 = (uint8_t *)&nv->parameter_block_version;
1527 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1529 *dptr1++ = *dptr2++;
1531 /* Copy 2nd half. */
1532 dptr1 = (uint8_t *)icb->add_firmware_options;
1533 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1535 *dptr1++ = *dptr2++;
1537 /* Prepare nodename */
1538 if ((icb->firmware_options[1] & BIT_6) == 0) {
1540 * Firmware will apply the following mask if the nodename was
1543 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1544 icb->node_name[0] &= 0xF0;
1548 * Set host adapter parameters.
1550 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1551 /* Always load RISC code on non ISP2[12]00 chips. */
1552 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1553 ha->flags.disable_risc_code_load = 0;
1554 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1555 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1556 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1557 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1559 ha->operating_mode =
1560 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1562 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1563 sizeof(ha->fw_seriallink_options));
1565 /* save HBA serial number */
1566 ha->serial0 = icb->port_name[5];
1567 ha->serial1 = icb->port_name[6];
1568 ha->serial2 = icb->port_name[7];
1569 ha->node_name = icb->node_name;
1570 ha->port_name = icb->port_name;
1572 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1574 ha->retry_count = nv->retry_count;
1576 /* Set minimum login_timeout to 4 seconds. */
1577 if (nv->login_timeout < ql2xlogintimeout)
1578 nv->login_timeout = ql2xlogintimeout;
1579 if (nv->login_timeout < 4)
1580 nv->login_timeout = 4;
1581 ha->login_timeout = nv->login_timeout;
1582 icb->login_timeout = nv->login_timeout;
1584 /* Set minimum RATOV to 200 tenths of a second. */
1587 ha->loop_reset_delay = nv->reset_delay;
1589 /* Link Down Timeout = 0:
1591 * When Port Down timer expires we will start returning
1592 * I/O's to OS with "DID_NO_CONNECT".
1594 * Link Down Timeout != 0:
1596 * The driver waits for the link to come up after link down
1597 * before returning I/Os to OS with "DID_NO_CONNECT".
1599 if (nv->link_down_timeout == 0) {
1600 ha->loop_down_abort_time =
1601 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1603 ha->link_down_timeout = nv->link_down_timeout;
1604 ha->loop_down_abort_time =
1605 (LOOP_DOWN_TIME - ha->link_down_timeout);
1609 * Need enough time to try and get the port back.
1611 ha->port_down_retry_count = nv->port_down_retry_count;
1612 if (qlport_down_retry)
1613 ha->port_down_retry_count = qlport_down_retry;
1614 /* Set login_retry_count */
1615 ha->login_retry_count = nv->retry_count;
1616 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1617 ha->port_down_retry_count > 3)
1618 ha->login_retry_count = ha->port_down_retry_count;
1619 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1620 ha->login_retry_count = ha->port_down_retry_count;
1621 if (ql2xloginretrycount)
1622 ha->login_retry_count = ql2xloginretrycount;
1624 icb->lun_enables = __constant_cpu_to_le16(0);
1625 icb->command_resource_count = 0;
1626 icb->immediate_notify_resource_count = 0;
1627 icb->timeout = __constant_cpu_to_le16(0);
1629 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1631 icb->firmware_options[0] &= ~BIT_3;
1632 icb->add_firmware_options[0] &=
1633 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1634 icb->add_firmware_options[0] |= BIT_2;
1635 icb->response_accumulation_timer = 3;
1636 icb->interrupt_delay_timer = 5;
1638 ha->flags.process_response_queue = 1;
1641 if (!ha->flags.init_done) {
1642 ha->zio_mode = icb->add_firmware_options[0] &
1643 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1644 ha->zio_timer = icb->interrupt_delay_timer ?
1645 icb->interrupt_delay_timer: 2;
1647 icb->add_firmware_options[0] &=
1648 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1649 ha->flags.process_response_queue = 0;
1650 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1651 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1652 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1653 ha->zio_timer * 100));
1654 qla_printk(KERN_INFO, ha,
1655 "ZIO mode %d enabled; timer delay (%d us).\n",
1656 ha->zio_mode, ha->zio_timer * 100);
1658 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1659 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1660 ha->flags.process_response_queue = 1;
1665 DEBUG2_3(printk(KERN_WARNING
1666 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1672 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1674 * @flags: allocation flags
1676 * Returns a pointer to the allocated fcport, or NULL, if none available.
1679 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1683 fcport = kmalloc(sizeof(fc_port_t), flags);
1687 /* Setup fcport template structure. */
1688 memset(fcport, 0, sizeof (fc_port_t));
1690 fcport->port_type = FCT_UNKNOWN;
1691 fcport->loop_id = FC_NO_LOOP_ID;
1692 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1693 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1694 fcport->flags = FCF_RLC_SUPPORT;
1695 fcport->supported_classes = FC_COS_UNSPECIFIED;
1701 * qla2x00_configure_loop
1702 * Updates Fibre Channel Device Database with what is actually on loop.
1705 * ha = adapter block pointer.
1710 * 2 = database was full and device was not configured.
1713 qla2x00_configure_loop(scsi_qla_host_t *ha)
1716 unsigned long flags, save_flags;
1720 /* Get Initiator ID */
1721 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1722 rval = qla2x00_configure_hba(ha);
1723 if (rval != QLA_SUCCESS) {
1724 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1730 save_flags = flags = ha->dpc_flags;
1731 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1732 ha->host_no, flags));
1735 * If we have both an RSCN and PORT UPDATE pending then handle them
1736 * both at the same time.
1738 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1739 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1741 /* Determine what we need to do */
1742 if (ha->current_topology == ISP_CFG_FL &&
1743 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1745 ha->flags.rscn_queue_overflow = 1;
1746 set_bit(RSCN_UPDATE, &flags);
1748 } else if (ha->current_topology == ISP_CFG_F &&
1749 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1751 ha->flags.rscn_queue_overflow = 1;
1752 set_bit(RSCN_UPDATE, &flags);
1753 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1755 } else if (!ha->flags.online ||
1756 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1758 ha->flags.rscn_queue_overflow = 1;
1759 set_bit(RSCN_UPDATE, &flags);
1760 set_bit(LOCAL_LOOP_UPDATE, &flags);
1763 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1764 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1765 rval = QLA_FUNCTION_FAILED;
1767 rval = qla2x00_configure_local_loop(ha);
1771 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1772 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1773 rval = QLA_FUNCTION_FAILED;
1775 rval = qla2x00_configure_fabric(ha);
1779 if (rval == QLA_SUCCESS) {
1780 if (atomic_read(&ha->loop_down_timer) ||
1781 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1782 rval = QLA_FUNCTION_FAILED;
1784 atomic_set(&ha->loop_state, LOOP_READY);
1786 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1791 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1792 __func__, ha->host_no));
1794 DEBUG3(printk("%s: exiting normally\n", __func__));
1797 /* Restore state if a resync event occured during processing */
1798 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1799 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1800 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1801 if (test_bit(RSCN_UPDATE, &save_flags))
1802 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1811 * qla2x00_configure_local_loop
1812 * Updates Fibre Channel Device Database with local loop devices.
1815 * ha = adapter block pointer.
1821 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1826 fc_port_t *fcport, *new_fcport;
1832 uint8_t domain, area, al_pa;
1836 entries = MAX_FIBRE_DEVICES;
1838 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1839 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1841 /* Get list of logged in devices. */
1842 memset(ha->gid_list, 0, GID_LIST_SIZE);
1843 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1845 if (rval != QLA_SUCCESS)
1846 goto cleanup_allocation;
1848 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1849 ha->host_no, entries));
1850 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1851 entries * sizeof(struct gid_list_info)));
1853 /* Allocate temporary fcport for any new fcports discovered. */
1854 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1855 if (new_fcport == NULL) {
1856 rval = QLA_MEMORY_ALLOC_FAILED;
1857 goto cleanup_allocation;
1859 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1862 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1864 list_for_each_entry(fcport, &ha->fcports, list) {
1865 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1866 fcport->port_type != FCT_BROADCAST &&
1867 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1869 DEBUG(printk("scsi(%ld): Marking port lost, "
1871 ha->host_no, fcport->loop_id));
1873 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1874 fcport->flags &= ~FCF_FARP_DONE;
1878 /* Add devices to port list. */
1879 id_iter = (char *)ha->gid_list;
1880 for (index = 0; index < entries; index++) {
1881 domain = ((struct gid_list_info *)id_iter)->domain;
1882 area = ((struct gid_list_info *)id_iter)->area;
1883 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1884 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1885 loop_id = (uint16_t)
1886 ((struct gid_list_info *)id_iter)->loop_id_2100;
1888 loop_id = le16_to_cpu(
1889 ((struct gid_list_info *)id_iter)->loop_id);
1890 id_iter += ha->gid_list_info_size;
1892 /* Bypass reserved domain fields. */
1893 if ((domain & 0xf0) == 0xf0)
1896 /* Bypass if not same domain and area of adapter. */
1897 if (area && domain &&
1898 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
1901 /* Bypass invalid local loop ID. */
1902 if (loop_id > LAST_LOCAL_LOOP_ID)
1905 /* Fill in member data. */
1906 new_fcport->d_id.b.domain = domain;
1907 new_fcport->d_id.b.area = area;
1908 new_fcport->d_id.b.al_pa = al_pa;
1909 new_fcport->loop_id = loop_id;
1910 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1911 if (rval2 != QLA_SUCCESS) {
1912 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1913 "information -- get_port_database=%x, "
1915 ha->host_no, rval2, new_fcport->loop_id));
1919 /* Check for matching device in port list. */
1922 list_for_each_entry(fcport, &ha->fcports, list) {
1923 if (memcmp(new_fcport->port_name, fcport->port_name,
1927 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1928 FCF_PERSISTENT_BOUND);
1929 fcport->loop_id = new_fcport->loop_id;
1930 fcport->port_type = new_fcport->port_type;
1931 fcport->d_id.b24 = new_fcport->d_id.b24;
1932 memcpy(fcport->node_name, new_fcport->node_name,
1940 /* New device, add to fcports list. */
1941 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1942 list_add_tail(&new_fcport->list, &ha->fcports);
1944 /* Allocate a new replacement fcport. */
1945 fcport = new_fcport;
1946 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1947 if (new_fcport == NULL) {
1948 rval = QLA_MEMORY_ALLOC_FAILED;
1949 goto cleanup_allocation;
1951 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1954 qla2x00_update_fcport(ha, fcport);
1963 if (rval != QLA_SUCCESS) {
1964 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1965 "rval=%x\n", ha->host_no, rval));
1969 ha->device_flags |= DFLG_LOCAL_DEVICES;
1970 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
1977 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
1981 qla2x00_mark_all_devices_lost(ha);
1982 list_for_each_entry(fcport, &ha->fcports, list) {
1983 if (fcport->port_type != FCT_TARGET)
1986 qla2x00_update_fcport(ha, fcport);
1991 * qla2x00_update_fcport
1992 * Updates device on list.
1995 * ha = adapter block pointer.
1996 * fcport = port structure pointer.
2006 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2009 unsigned long flags;
2013 fcport->login_retry = 0;
2014 fcport->port_login_retry_count = ha->port_down_retry_count *
2016 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2018 fcport->flags &= ~FCF_LOGIN_NEEDED;
2021 * Check for outstanding cmd on tape Bypass LUN discovery if active
2024 if (fcport->flags & FCF_TAPE_PRESENT) {
2025 spin_lock_irqsave(&ha->hardware_lock, flags);
2026 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
2029 if ((sp = ha->outstanding_cmds[index]) != 0) {
2031 if (sfcp == fcport) {
2032 atomic_set(&fcport->state, FCS_ONLINE);
2033 spin_unlock_irqrestore(
2034 &ha->hardware_lock, flags);
2039 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2042 if (fcport->port_type == FCT_INITIATOR ||
2043 fcport->port_type == FCT_BROADCAST)
2044 fcport->device_type = TYPE_PROCESSOR;
2046 atomic_set(&fcport->state, FCS_ONLINE);
2048 if (ha->flags.init_done)
2049 qla2x00_reg_remote_port(ha, fcport);
2053 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2055 struct fc_rport_identifiers rport_ids;
2056 struct fc_rport *rport;
2058 if (fcport->rport) {
2059 fc_remote_port_unblock(fcport->rport);
2063 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2064 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2065 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2066 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2067 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2068 fcport->rport = rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2070 qla_printk(KERN_WARNING, ha,
2071 "Unable to allocate fc remote port!\n");
2074 rport->dd_data = fcport;
2075 rport->supported_classes = fcport->supported_classes;
2077 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2078 if (fcport->port_type == FCT_INITIATOR)
2079 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2080 if (fcport->port_type == FCT_TARGET)
2081 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2082 fc_remote_port_rolechg(rport, rport_ids.roles);
2084 if (rport->scsi_target_id != -1 &&
2085 rport->scsi_target_id < ha->host->max_id)
2086 fcport->os_target_id = rport->scsi_target_id;
2090 * qla2x00_configure_fabric
2091 * Setup SNS devices with loop ID's.
2094 * ha = adapter block pointer.
2101 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2104 fc_port_t *fcport, *fcptemp;
2105 uint16_t next_loopid;
2106 uint16_t mb[MAILBOX_REGISTER_COUNT];
2108 LIST_HEAD(new_fcports);
2110 /* If FL port exists, then SNS is present */
2111 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
2112 loop_id = NPH_F_PORT;
2114 loop_id = SNS_FL_PORT;
2115 rval = qla2x00_get_port_name(ha, loop_id, NULL, 0);
2116 if (rval != QLA_SUCCESS) {
2117 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2118 "Port\n", ha->host_no));
2120 ha->device_flags &= ~SWITCH_FOUND;
2121 return (QLA_SUCCESS);
2124 /* Mark devices that need re-synchronization. */
2125 rval2 = qla2x00_device_resync(ha);
2126 if (rval2 == QLA_RSCNS_HANDLED) {
2127 /* No point doing the scan, just continue. */
2128 return (QLA_SUCCESS);
2132 if (ql2xfdmienable &&
2133 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2134 qla2x00_fdmi_register(ha);
2136 /* Ensure we are logged into the SNS. */
2137 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
2140 loop_id = SIMPLE_NAME_SERVER;
2141 ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
2142 0xfc, mb, BIT_1 | BIT_0);
2143 if (mb[0] != MBS_COMMAND_COMPLETE) {
2144 DEBUG2(qla_printk(KERN_INFO, ha,
2145 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2146 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2147 mb[0], mb[1], mb[2], mb[6], mb[7]));
2148 return (QLA_SUCCESS);
2151 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2152 if (qla2x00_rft_id(ha)) {
2154 DEBUG2(printk("scsi(%ld): Register FC-4 "
2155 "TYPE failed.\n", ha->host_no));
2157 if (qla2x00_rff_id(ha)) {
2159 DEBUG2(printk("scsi(%ld): Register FC-4 "
2160 "Features failed.\n", ha->host_no));
2162 if (qla2x00_rnn_id(ha)) {
2164 DEBUG2(printk("scsi(%ld): Register Node Name "
2165 "failed.\n", ha->host_no));
2166 } else if (qla2x00_rsnn_nn(ha)) {
2168 DEBUG2(printk("scsi(%ld): Register Symbolic "
2169 "Node Name failed.\n", ha->host_no));
2173 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2174 if (rval != QLA_SUCCESS)
2178 * Logout all previous fabric devices marked lost, except
2181 list_for_each_entry(fcport, &ha->fcports, list) {
2182 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2185 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2188 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2189 qla2x00_mark_device_lost(ha, fcport,
2190 ql2xplogiabsentdevice);
2191 if (fcport->loop_id != FC_NO_LOOP_ID &&
2192 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2193 fcport->port_type != FCT_INITIATOR &&
2194 fcport->port_type != FCT_BROADCAST) {
2196 ha->isp_ops.fabric_logout(ha,
2198 fcport->d_id.b.domain,
2199 fcport->d_id.b.area,
2200 fcport->d_id.b.al_pa);
2201 fcport->loop_id = FC_NO_LOOP_ID;
2206 /* Starting free loop ID. */
2207 next_loopid = ha->min_external_loopid;
2210 * Scan through our port list and login entries that need to be
2213 list_for_each_entry(fcport, &ha->fcports, list) {
2214 if (atomic_read(&ha->loop_down_timer) ||
2215 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2218 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2219 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2222 if (fcport->loop_id == FC_NO_LOOP_ID) {
2223 fcport->loop_id = next_loopid;
2224 rval = qla2x00_find_new_loop_id(ha, fcport);
2225 if (rval != QLA_SUCCESS) {
2226 /* Ran out of IDs to use */
2230 /* Login and update database */
2231 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2234 /* Exit if out of loop IDs. */
2235 if (rval != QLA_SUCCESS) {
2240 * Login and add the new devices to our port list.
2242 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2243 if (atomic_read(&ha->loop_down_timer) ||
2244 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2247 /* Find a new loop ID to use. */
2248 fcport->loop_id = next_loopid;
2249 rval = qla2x00_find_new_loop_id(ha, fcport);
2250 if (rval != QLA_SUCCESS) {
2251 /* Ran out of IDs to use */
2255 /* Remove device from the new list and add it to DB */
2256 list_del(&fcport->list);
2257 list_add_tail(&fcport->list, &ha->fcports);
2259 /* Login and update database */
2260 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2264 /* Free all new device structures not processed. */
2265 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2266 list_del(&fcport->list);
2271 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2272 "rval=%d\n", ha->host_no, rval));
2280 * qla2x00_find_all_fabric_devs
2283 * ha = adapter block pointer.
2284 * dev = database device entry pointer.
2293 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2297 fc_port_t *fcport, *new_fcport, *fcptemp;
2302 int first_dev, last_dev;
2303 port_id_t wrap, nxt_d_id;
2307 /* Try GID_PT to get device list, else GAN. */
2308 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2311 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2312 "on GA_NXT\n", ha->host_no));
2314 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2315 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2318 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2321 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2328 /* Allocate temporary fcport for any new fcports discovered. */
2329 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2330 if (new_fcport == NULL) {
2333 return (QLA_MEMORY_ALLOC_FAILED);
2335 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2337 /* Set start port ID scan at adapter ID. */
2341 /* Starting free loop ID. */
2342 loop_id = ha->min_external_loopid;
2343 for (; loop_id <= ha->last_loop_id; loop_id++) {
2344 if (qla2x00_is_reserved_id(ha, loop_id))
2347 if (atomic_read(&ha->loop_down_timer) ||
2348 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2353 wrap.b24 = new_fcport->d_id.b24;
2355 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2356 memcpy(new_fcport->node_name,
2357 swl[swl_idx].node_name, WWN_SIZE);
2358 memcpy(new_fcport->port_name,
2359 swl[swl_idx].port_name, WWN_SIZE);
2361 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2367 /* Send GA_NXT to the switch */
2368 rval = qla2x00_ga_nxt(ha, new_fcport);
2369 if (rval != QLA_SUCCESS) {
2370 qla_printk(KERN_WARNING, ha,
2371 "SNS scan failed -- assuming zero-entry "
2373 list_for_each_entry_safe(fcport, fcptemp,
2374 new_fcports, list) {
2375 list_del(&fcport->list);
2383 /* If wrap on switch device list, exit. */
2385 wrap.b24 = new_fcport->d_id.b24;
2387 } else if (new_fcport->d_id.b24 == wrap.b24) {
2388 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2389 ha->host_no, new_fcport->d_id.b.domain,
2390 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2394 /* Bypass if host adapter. */
2395 if (new_fcport->d_id.b24 == ha->d_id.b24)
2398 /* Bypass if same domain and area of adapter. */
2399 if (((new_fcport->d_id.b24 & 0xffff00) ==
2400 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2404 /* Bypass reserved domain fields. */
2405 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2408 /* Locate matching device in database. */
2410 list_for_each_entry(fcport, &ha->fcports, list) {
2411 if (memcmp(new_fcport->port_name, fcport->port_name,
2418 * If address the same and state FCS_ONLINE, nothing
2421 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2422 atomic_read(&fcport->state) == FCS_ONLINE) {
2427 * If device was not a fabric device before.
2429 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2430 fcport->d_id.b24 = new_fcport->d_id.b24;
2431 fcport->loop_id = FC_NO_LOOP_ID;
2432 fcport->flags |= (FCF_FABRIC_DEVICE |
2434 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2439 * Port ID changed or device was marked to be updated;
2440 * Log it out if still logged in and mark it for
2443 fcport->d_id.b24 = new_fcport->d_id.b24;
2444 fcport->flags |= FCF_LOGIN_NEEDED;
2445 if (fcport->loop_id != FC_NO_LOOP_ID &&
2446 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2447 fcport->port_type != FCT_INITIATOR &&
2448 fcport->port_type != FCT_BROADCAST) {
2449 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2450 fcport->d_id.b.domain, fcport->d_id.b.area,
2451 fcport->d_id.b.al_pa);
2452 fcport->loop_id = FC_NO_LOOP_ID;
2461 /* If device was not in our fcports list, then add it. */
2462 list_add_tail(&new_fcport->list, new_fcports);
2464 /* Allocate a new replacement fcport. */
2465 nxt_d_id.b24 = new_fcport->d_id.b24;
2466 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2467 if (new_fcport == NULL) {
2470 return (QLA_MEMORY_ALLOC_FAILED);
2472 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2473 new_fcport->d_id.b24 = nxt_d_id.b24;
2482 if (!list_empty(new_fcports))
2483 ha->device_flags |= DFLG_FABRIC_DEVICES;
2489 * qla2x00_find_new_loop_id
2490 * Scan through our port list and find a new usable loop ID.
2493 * ha: adapter state pointer.
2494 * dev: port structure pointer.
2497 * qla2x00 local function return status code.
2503 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2508 uint16_t first_loop_id;
2512 /* Save starting loop ID. */
2513 first_loop_id = dev->loop_id;
2516 /* Skip loop ID if already used by adapter. */
2517 if (dev->loop_id == ha->loop_id) {
2521 /* Skip reserved loop IDs. */
2522 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2526 /* Reset loop ID if passed the end. */
2527 if (dev->loop_id > ha->last_loop_id) {
2528 /* first loop ID. */
2529 dev->loop_id = ha->min_external_loopid;
2532 /* Check for loop ID being already in use. */
2535 list_for_each_entry(fcport, &ha->fcports, list) {
2536 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2537 /* ID possibly in use */
2543 /* If not in use then it is free to use. */
2548 /* ID in use. Try next value. */
2551 /* If wrap around. No free ID to use. */
2552 if (dev->loop_id == first_loop_id) {
2553 dev->loop_id = FC_NO_LOOP_ID;
2554 rval = QLA_FUNCTION_FAILED;
2563 * qla2x00_device_resync
2564 * Marks devices in the database that needs resynchronization.
2567 * ha = adapter block pointer.
2573 qla2x00_device_resync(scsi_qla_host_t *ha)
2579 uint32_t rscn_entry;
2580 uint8_t rscn_out_iter;
2584 rval = QLA_RSCNS_HANDLED;
2586 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2587 ha->flags.rscn_queue_overflow) {
2589 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2590 format = MSB(MSW(rscn_entry));
2591 d_id.b.domain = LSB(MSW(rscn_entry));
2592 d_id.b.area = MSB(LSW(rscn_entry));
2593 d_id.b.al_pa = LSB(LSW(rscn_entry));
2595 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2596 "[%02x/%02x%02x%02x].\n",
2597 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2598 d_id.b.area, d_id.b.al_pa));
2601 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2602 ha->rscn_out_ptr = 0;
2604 /* Skip duplicate entries. */
2605 for (rscn_out_iter = ha->rscn_out_ptr;
2606 !ha->flags.rscn_queue_overflow &&
2607 rscn_out_iter != ha->rscn_in_ptr;
2608 rscn_out_iter = (rscn_out_iter ==
2609 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2611 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2614 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2615 "entry found at [%d].\n", ha->host_no,
2618 ha->rscn_out_ptr = rscn_out_iter;
2621 /* Queue overflow, set switch default case. */
2622 if (ha->flags.rscn_queue_overflow) {
2623 DEBUG(printk("scsi(%ld): device_resync: rscn "
2624 "overflow.\n", ha->host_no));
2627 ha->flags.rscn_queue_overflow = 0;
2632 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) &&
2633 !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
2634 !IS_QLA24XX(ha) && !IS_QLA25XX(ha) &&
2635 ha->flags.init_done) {
2636 /* Handle port RSCN via asyncronous IOCBs */
2637 rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
2639 if (rval2 == QLA_SUCCESS)
2653 ha->rscn_out_ptr = ha->rscn_in_ptr;
2659 /* Abort any outstanding IO descriptors. */
2660 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2661 qla2x00_cancel_io_descriptors(ha);
2663 list_for_each_entry(fcport, &ha->fcports, list) {
2664 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2665 (fcport->d_id.b24 & mask) != d_id.b24 ||
2666 fcport->port_type == FCT_BROADCAST)
2669 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2671 fcport->port_type != FCT_INITIATOR) {
2672 qla2x00_mark_device_lost(ha, fcport, 0);
2675 fcport->flags &= ~FCF_FARP_DONE;
2682 * qla2x00_fabric_dev_login
2683 * Login fabric target device and update FC port database.
2686 * ha: adapter state pointer.
2687 * fcport: port structure list pointer.
2688 * next_loopid: contains value of a new loop ID that can be used
2689 * by the next login attempt.
2692 * qla2x00 local function return status code.
2698 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2699 uint16_t *next_loopid)
2708 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2709 if (rval == QLA_SUCCESS) {
2710 /* Send an ADISC to tape devices.*/
2712 if (fcport->flags & FCF_TAPE_PRESENT)
2714 rval = qla2x00_get_port_database(ha, fcport, opts);
2715 if (rval != QLA_SUCCESS) {
2716 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2717 fcport->d_id.b.domain, fcport->d_id.b.area,
2718 fcport->d_id.b.al_pa);
2719 qla2x00_mark_device_lost(ha, fcport, 1);
2722 qla2x00_update_fcport(ha, fcport);
2730 * qla2x00_fabric_login
2731 * Issue fabric login command.
2734 * ha = adapter block pointer.
2735 * device = pointer to FC device type structure.
2738 * 0 - Login successfully
2740 * 2 - Initiator device
2744 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2745 uint16_t *next_loopid)
2749 uint16_t tmp_loopid;
2750 uint16_t mb[MAILBOX_REGISTER_COUNT];
2756 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2757 "for port %02x%02x%02x.\n",
2758 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2759 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2761 /* Login fcport on switch. */
2762 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2763 fcport->d_id.b.domain, fcport->d_id.b.area,
2764 fcport->d_id.b.al_pa, mb, BIT_0);
2765 if (mb[0] == MBS_PORT_ID_USED) {
2767 * Device has another loop ID. The firmware team
2768 * recommends the driver perform an implicit login with
2769 * the specified ID again. The ID we just used is save
2770 * here so we return with an ID that can be tried by
2774 tmp_loopid = fcport->loop_id;
2775 fcport->loop_id = mb[1];
2777 DEBUG(printk("Fabric Login: port in use - next "
2778 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2779 fcport->loop_id, fcport->d_id.b.domain,
2780 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2782 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2787 /* A retry occurred before. */
2788 *next_loopid = tmp_loopid;
2791 * No retry occurred before. Just increment the
2792 * ID value for next login.
2794 *next_loopid = (fcport->loop_id + 1);
2797 if (mb[1] & BIT_0) {
2798 fcport->port_type = FCT_INITIATOR;
2800 fcport->port_type = FCT_TARGET;
2801 if (mb[1] & BIT_1) {
2802 fcport->flags |= FCF_TAPE_PRESENT;
2807 fcport->supported_classes |= FC_COS_CLASS2;
2809 fcport->supported_classes |= FC_COS_CLASS3;
2813 } else if (mb[0] == MBS_LOOP_ID_USED) {
2815 * Loop ID already used, try next loop ID.
2818 rval = qla2x00_find_new_loop_id(ha, fcport);
2819 if (rval != QLA_SUCCESS) {
2820 /* Ran out of loop IDs to use */
2823 } else if (mb[0] == MBS_COMMAND_ERROR) {
2825 * Firmware possibly timed out during login. If NO
2826 * retries are left to do then the device is declared
2829 *next_loopid = fcport->loop_id;
2830 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2831 fcport->d_id.b.domain, fcport->d_id.b.area,
2832 fcport->d_id.b.al_pa);
2833 qla2x00_mark_device_lost(ha, fcport, 1);
2839 * unrecoverable / not handled error
2841 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2842 "loop_id=%x jiffies=%lx.\n",
2843 __func__, ha->host_no, mb[0],
2844 fcport->d_id.b.domain, fcport->d_id.b.area,
2845 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2847 *next_loopid = fcport->loop_id;
2848 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2849 fcport->d_id.b.domain, fcport->d_id.b.area,
2850 fcport->d_id.b.al_pa);
2851 fcport->loop_id = FC_NO_LOOP_ID;
2852 fcport->login_retry = 0;
2863 * qla2x00_local_device_login
2864 * Issue local device login command.
2867 * ha = adapter block pointer.
2868 * loop_id = loop id of device to login to.
2870 * Returns (Where's the #define!!!!):
2871 * 0 - Login successfully
2876 qla2x00_local_device_login(scsi_qla_host_t *ha, uint16_t loop_id)
2879 uint16_t mb[MAILBOX_REGISTER_COUNT];
2881 memset(mb, 0, sizeof(mb));
2882 rval = qla2x00_login_local_device(ha, loop_id, mb, BIT_0);
2883 if (rval == QLA_SUCCESS) {
2884 /* Interrogate mailbox registers for any errors */
2885 if (mb[0] == MBS_COMMAND_ERROR)
2887 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
2888 /* device not in PCB table */
2896 * qla2x00_loop_resync
2897 * Resync with fibre channel devices.
2900 * ha = adapter block pointer.
2906 qla2x00_loop_resync(scsi_qla_host_t *ha)
2913 atomic_set(&ha->loop_state, LOOP_UPDATE);
2914 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2915 if (ha->flags.online) {
2916 if (!(rval = qla2x00_fw_ready(ha))) {
2917 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2920 atomic_set(&ha->loop_state, LOOP_UPDATE);
2922 /* Issue a marker after FW becomes ready. */
2923 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
2924 ha->marker_needed = 0;
2926 /* Remap devices on Loop. */
2927 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2929 qla2x00_configure_loop(ha);
2931 } while (!atomic_read(&ha->loop_down_timer) &&
2932 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
2934 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
2938 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2939 return (QLA_FUNCTION_FAILED);
2943 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
2950 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
2956 list_for_each_entry(fcport, &ha->fcports, list) {
2957 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
2960 qla2x00_update_fcport(ha, fcport);
2961 fcport->flags &= ~FCF_RESCAN_NEEDED;
2965 qla2x00_probe_for_all_luns(ha);
2970 * Resets ISP and aborts all outstanding commands.
2973 * ha = adapter block pointer.
2979 qla2x00_abort_isp(scsi_qla_host_t *ha)
2981 unsigned long flags = 0;
2986 if (ha->flags.online) {
2987 ha->flags.online = 0;
2988 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2990 qla_printk(KERN_INFO, ha,
2991 "Performing ISP error recovery - ha= %p.\n", ha);
2992 ha->isp_ops.reset_chip(ha);
2994 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
2995 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
2996 atomic_set(&ha->loop_state, LOOP_DOWN);
2997 qla2x00_mark_all_devices_lost(ha);
2999 if (!atomic_read(&ha->loop_down_timer))
3000 atomic_set(&ha->loop_down_timer,
3004 spin_lock_irqsave(&ha->hardware_lock, flags);
3005 /* Requeue all commands in outstanding command list. */
3006 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3007 sp = ha->outstanding_cmds[cnt];
3009 ha->outstanding_cmds[cnt] = NULL;
3011 sp->cmd->result = DID_RESET << 16;
3012 sp->cmd->host_scribble = (unsigned char *)NULL;
3013 qla2x00_sp_compl(ha, sp);
3016 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3018 ha->isp_ops.nvram_config(ha);
3020 if (!qla2x00_restart_isp(ha)) {
3021 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3023 if (!atomic_read(&ha->loop_down_timer)) {
3025 * Issue marker command only when we are going
3026 * to start the I/O .
3028 ha->marker_needed = 1;
3031 ha->flags.online = 1;
3033 ha->isp_ops.enable_intrs(ha);
3035 ha->isp_abort_cnt = 0;
3036 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3037 } else { /* failed the ISP abort */
3038 ha->flags.online = 1;
3039 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3040 if (ha->isp_abort_cnt == 0) {
3041 qla_printk(KERN_WARNING, ha,
3042 "ISP error recovery failed - "
3043 "board disabled\n");
3045 * The next call disables the board
3048 ha->isp_ops.reset_adapter(ha);
3049 ha->flags.online = 0;
3050 clear_bit(ISP_ABORT_RETRY,
3053 } else { /* schedule another ISP abort */
3054 ha->isp_abort_cnt--;
3055 DEBUG(printk("qla%ld: ISP abort - "
3056 "retry remaining %d\n",
3057 ha->host_no, ha->isp_abort_cnt);)
3061 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3062 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3063 "- retrying (%d) more times\n",
3064 ha->host_no, ha->isp_abort_cnt);)
3065 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3073 qla_printk(KERN_INFO, ha,
3074 "qla2x00_abort_isp: **** FAILED ****\n");
3076 DEBUG(printk(KERN_INFO
3077 "qla2x00_abort_isp(%ld): exiting.\n",
3085 * qla2x00_restart_isp
3086 * restarts the ISP after a reset
3089 * ha = adapter block pointer.
3095 qla2x00_restart_isp(scsi_qla_host_t *ha)
3098 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3099 unsigned long flags = 0;
3102 /* If firmware needs to be loaded */
3103 if (qla2x00_isp_firmware(ha)) {
3104 ha->flags.online = 0;
3105 if (!(status = ha->isp_ops.chip_diag(ha))) {
3106 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3107 status = qla2x00_setup_chip(ha);
3111 spin_lock_irqsave(&ha->hardware_lock, flags);
3113 if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha)) {
3115 * Disable SRAM, Instruction RAM and GP RAM
3118 WRT_REG_WORD(®->hccr,
3119 (HCCR_ENABLE_PARITY + 0x0));
3120 RD_REG_WORD(®->hccr);
3123 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3125 status = qla2x00_setup_chip(ha);
3127 spin_lock_irqsave(&ha->hardware_lock, flags);
3129 if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha)) {
3130 /* Enable proper parity */
3133 WRT_REG_WORD(®->hccr,
3134 (HCCR_ENABLE_PARITY + 0x1));
3137 * SRAM, Instruction RAM and GP RAM
3140 WRT_REG_WORD(®->hccr,
3141 (HCCR_ENABLE_PARITY + 0x7));
3142 RD_REG_WORD(®->hccr);
3145 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3150 if (!status && !(status = qla2x00_init_rings(ha))) {
3151 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3152 if (!(status = qla2x00_fw_ready(ha))) {
3153 DEBUG(printk("%s(): Start configure loop, "
3154 "status = %d\n", __func__, status);)
3156 /* Issue a marker after FW becomes ready. */
3157 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3159 ha->flags.online = 1;
3160 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3163 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3164 qla2x00_configure_loop(ha);
3166 } while (!atomic_read(&ha->loop_down_timer) &&
3167 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3169 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3172 /* if no cable then assume it's good */
3173 if ((ha->device_flags & DFLG_NO_CABLE))
3176 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3184 * qla2x00_reset_adapter
3188 * ha = adapter block pointer.
3191 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3193 unsigned long flags = 0;
3194 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3196 ha->flags.online = 0;
3197 ha->isp_ops.disable_intrs(ha);
3199 spin_lock_irqsave(&ha->hardware_lock, flags);
3200 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3201 RD_REG_WORD(®->hccr); /* PCI Posting. */
3202 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3203 RD_REG_WORD(®->hccr); /* PCI Posting. */
3204 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3208 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3210 unsigned long flags = 0;
3211 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3213 ha->flags.online = 0;
3214 ha->isp_ops.disable_intrs(ha);
3216 spin_lock_irqsave(&ha->hardware_lock, flags);
3217 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3218 RD_REG_DWORD(®->hccr);
3219 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3220 RD_REG_DWORD(®->hccr);
3221 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3225 qla24xx_nvram_config(scsi_qla_host_t *ha)
3228 struct init_cb_24xx *icb;
3229 struct nvram_24xx *nv;
3231 uint8_t *dptr1, *dptr2;
3236 icb = (struct init_cb_24xx *)ha->init_cb;
3237 nv = (struct nvram_24xx *)ha->request_ring;
3239 /* Determine NVRAM starting address. */
3240 ha->nvram_size = sizeof(struct nvram_24xx);
3241 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3242 if (PCI_FUNC(ha->pdev->devfn))
3243 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3245 /* Get NVRAM data and calculate checksum. */
3246 dptr = (uint32_t *)nv;
3247 ha->isp_ops.read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3249 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3250 chksum += le32_to_cpu(*dptr++);
3252 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3253 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3256 /* Bad NVRAM data, set defaults parameters. */
3257 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3258 || nv->id[3] != ' ' ||
3259 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3260 /* Reset NVRAM data. */
3261 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3262 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3263 le16_to_cpu(nv->nvram_version));
3264 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3265 "invalid -- WWPN) defaults.\n");
3268 * Set default initialization control block.
3270 memset(nv, 0, ha->nvram_size);
3271 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3272 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3273 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3274 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3275 nv->exchange_count = __constant_cpu_to_le16(0);
3276 nv->hard_address = __constant_cpu_to_le16(124);
3277 nv->port_name[0] = 0x21;
3278 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3279 nv->port_name[2] = 0x00;
3280 nv->port_name[3] = 0xe0;
3281 nv->port_name[4] = 0x8b;
3282 nv->port_name[5] = 0x1c;
3283 nv->port_name[6] = 0x55;
3284 nv->port_name[7] = 0x86;
3285 nv->node_name[0] = 0x20;
3286 nv->node_name[1] = 0x00;
3287 nv->node_name[2] = 0x00;
3288 nv->node_name[3] = 0xe0;
3289 nv->node_name[4] = 0x8b;
3290 nv->node_name[5] = 0x1c;
3291 nv->node_name[6] = 0x55;
3292 nv->node_name[7] = 0x86;
3293 nv->login_retry_count = __constant_cpu_to_le16(8);
3294 nv->link_down_timeout = __constant_cpu_to_le16(200);
3295 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3296 nv->login_timeout = __constant_cpu_to_le16(0);
3297 nv->firmware_options_1 =
3298 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3299 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3300 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3301 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3302 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3303 nv->efi_parameters = __constant_cpu_to_le32(0);
3304 nv->reset_delay = 5;
3305 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3306 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3307 nv->link_down_timeout = __constant_cpu_to_le16(30);
3312 /* Reset Initialization control block */
3313 memset(icb, 0, sizeof(struct init_cb_24xx));
3315 /* Copy 1st segment. */
3316 dptr1 = (uint8_t *)icb;
3317 dptr2 = (uint8_t *)&nv->version;
3318 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3320 *dptr1++ = *dptr2++;
3322 icb->login_retry_count = nv->login_retry_count;
3323 icb->link_down_timeout = nv->link_down_timeout;
3325 /* Copy 2nd segment. */
3326 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3327 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3328 cnt = (uint8_t *)&icb->reserved_3 -
3329 (uint8_t *)&icb->interrupt_delay_timer;
3331 *dptr1++ = *dptr2++;
3334 * Setup driver NVRAM options.
3336 if (memcmp(nv->model_name, BINZERO, sizeof(nv->model_name)) != 0) {
3340 strncpy(ha->model_number, nv->model_name,
3341 sizeof(nv->model_name));
3342 st = en = ha->model_number;
3343 en += sizeof(nv->model_name) - 1;
3345 if (*en != 0x20 && *en != 0x00)
3350 index = (ha->pdev->subsystem_device & 0xff);
3351 if (index < QLA_MODEL_NAMES)
3352 ha->model_desc = qla2x00_model_desc[index];
3354 strcpy(ha->model_number, "QLA2462");
3356 /* Prepare nodename */
3357 if ((icb->firmware_options_1 & BIT_14) == 0) {
3359 * Firmware will apply the following mask if the nodename was
3362 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3363 icb->node_name[0] &= 0xF0;
3366 /* Set host adapter parameters. */
3367 ha->flags.disable_risc_code_load = 0;
3368 ha->flags.enable_lip_reset = 1;
3369 ha->flags.enable_lip_full_login = 1;
3370 ha->flags.enable_target_reset = 1;
3371 ha->flags.enable_led_scheme = 0;
3373 ha->operating_mode =
3374 (icb->firmware_options_2 & (BIT_6 | BIT_5 | BIT_4)) >> 4;
3376 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3377 sizeof(ha->fw_seriallink_options24));
3379 /* save HBA serial number */
3380 ha->serial0 = icb->port_name[5];
3381 ha->serial1 = icb->port_name[6];
3382 ha->serial2 = icb->port_name[7];
3383 ha->node_name = icb->node_name;
3384 ha->port_name = icb->port_name;
3386 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3388 /* Set minimum login_timeout to 4 seconds. */
3389 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3390 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3391 if (le16_to_cpu(nv->login_timeout) < 4)
3392 nv->login_timeout = __constant_cpu_to_le16(4);
3393 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3394 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3396 /* Set minimum RATOV to 200 tenths of a second. */
3399 ha->loop_reset_delay = nv->reset_delay;
3401 /* Link Down Timeout = 0:
3403 * When Port Down timer expires we will start returning
3404 * I/O's to OS with "DID_NO_CONNECT".
3406 * Link Down Timeout != 0:
3408 * The driver waits for the link to come up after link down
3409 * before returning I/Os to OS with "DID_NO_CONNECT".
3411 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3412 ha->loop_down_abort_time =
3413 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3415 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3416 ha->loop_down_abort_time =
3417 (LOOP_DOWN_TIME - ha->link_down_timeout);
3420 /* Need enough time to try and get the port back. */
3421 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3422 if (qlport_down_retry)
3423 ha->port_down_retry_count = qlport_down_retry;
3425 /* Set login_retry_count */
3426 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3427 if (ha->port_down_retry_count ==
3428 le16_to_cpu(nv->port_down_retry_count) &&
3429 ha->port_down_retry_count > 3)
3430 ha->login_retry_count = ha->port_down_retry_count;
3431 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3432 ha->login_retry_count = ha->port_down_retry_count;
3433 if (ql2xloginretrycount)
3434 ha->login_retry_count = ql2xloginretrycount;
3437 if (!ha->flags.init_done) {
3438 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3439 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3440 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3441 le16_to_cpu(icb->interrupt_delay_timer): 2;
3443 icb->firmware_options_2 &= __constant_cpu_to_le32(
3444 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3445 ha->flags.process_response_queue = 0;
3446 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3447 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3448 "(%d us).\n", ha->host_no, ha->zio_mode,
3449 ha->zio_timer * 100));
3450 qla_printk(KERN_INFO, ha,
3451 "ZIO mode %d enabled; timer delay (%d us).\n",
3452 ha->zio_mode, ha->zio_timer * 100);
3454 icb->firmware_options_2 |= cpu_to_le32(
3455 (uint32_t)ha->zio_mode);
3456 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3457 ha->flags.process_response_queue = 1;
3461 DEBUG2_3(printk(KERN_WARNING
3462 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3468 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3472 uint16_t *risc_code;
3473 unsigned long risc_address;
3474 unsigned long risc_code_size;
3478 struct qla_fw_info *fw_iter;
3482 /* Load firmware sequences */
3483 fw_iter = ha->brd_info->fw_info;
3484 *srisc_addr = *ha->brd_info->fw_info->fwstart;
3485 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
3486 risc_code = fw_iter->fwcode;
3487 risc_code_size = *fw_iter->fwlen;
3489 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
3490 risc_address = *fw_iter->fwstart;
3492 /* Extended address */
3493 risc_address = *fw_iter->lfwstart;
3498 while (risc_code_size > 0 && !rval) {
3499 cnt = (uint16_t)(ha->fw_transfer_size >> 1);
3500 if (cnt > risc_code_size)
3501 cnt = risc_code_size;
3503 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
3504 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
3505 ha->host_no, risc_code, cnt, risc_address));
3507 req_ring = (uint16_t *)ha->request_ring;
3508 for (i = 0; i < cnt; i++)
3509 req_ring[i] = cpu_to_le16(risc_code[i]);
3511 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
3512 rval = qla2x00_load_ram(ha, ha->request_dma,
3515 rval = qla2x00_load_ram_ext(ha,
3516 ha->request_dma, risc_address, cnt);
3519 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
3520 "load segment %d of firmware\n",
3522 qla_printk(KERN_WARNING, ha,
3523 "[ERROR] Failed to load segment %d of "
3526 qla2x00_dump_regs(ha);
3531 risc_address += cnt;
3532 risc_code_size -= cnt;
3536 /* Next firmware sequence */
3544 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3547 int segments, fragment;
3549 uint32_t *dcode, dlen;
3556 segments = FA_RISC_CODE_SEGMENTS;
3557 faddr = FA_RISC_CODE_ADDR;
3558 dcode = (uint32_t *)ha->request_ring;
3561 /* Validate firmware image by checking version. */
3562 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3563 for (i = 0; i < 4; i++)
3564 dcode[i] = be32_to_cpu(dcode[i]);
3565 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3566 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3567 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3569 qla_printk(KERN_WARNING, ha,
3570 "Unable to verify integrity of flash firmware image!\n");
3571 qla_printk(KERN_WARNING, ha,
3572 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3573 dcode[1], dcode[2], dcode[3]);
3575 return QLA_FUNCTION_FAILED;
3578 while (segments && rval == QLA_SUCCESS) {
3579 /* Read segment's load information. */
3580 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3582 risc_addr = be32_to_cpu(dcode[2]);
3583 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3584 risc_size = be32_to_cpu(dcode[3]);
3587 while (risc_size > 0 && rval == QLA_SUCCESS) {
3588 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3589 if (dlen > risc_size)
3592 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3593 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3594 ha->host_no, risc_addr, dlen, faddr));
3596 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3597 for (i = 0; i < dlen; i++)
3598 dcode[i] = swab32(dcode[i]);
3600 rval = qla2x00_load_ram_ext(ha, ha->request_dma,
3603 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3604 "segment %d of firmware\n", ha->host_no,
3606 qla_printk(KERN_WARNING, ha,
3607 "[ERROR] Failed to load segment %d of "
3608 "firmware\n", fragment);
3626 qla24xx_load_risc_hotplug(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3629 int segments, fragment;
3630 uint32_t *dcode, dlen;
3634 const struct firmware *fw_entry;
3635 uint32_t *fwcode, fwclen;
3637 if (request_firmware(&fw_entry, ha->brd_info->fw_fname,
3639 qla_printk(KERN_ERR, ha,
3640 "Firmware image file not available: '%s'\n",
3641 ha->brd_info->fw_fname);
3642 return QLA_FUNCTION_FAILED;
3647 segments = FA_RISC_CODE_SEGMENTS;
3648 dcode = (uint32_t *)ha->request_ring;
3650 fwcode = (uint32_t *)fw_entry->data;
3653 /* Validate firmware image by checking version. */
3654 if (fw_entry->size < 8 * sizeof(uint32_t)) {
3655 qla_printk(KERN_WARNING, ha,
3656 "Unable to verify integrity of flash firmware image "
3657 "(%Zd)!\n", fw_entry->size);
3658 goto fail_fw_integrity;
3660 for (i = 0; i < 4; i++)
3661 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3662 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3663 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3664 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3666 qla_printk(KERN_WARNING, ha,
3667 "Unable to verify integrity of flash firmware image!\n");
3668 qla_printk(KERN_WARNING, ha,
3669 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3670 dcode[1], dcode[2], dcode[3]);
3671 goto fail_fw_integrity;
3674 while (segments && rval == QLA_SUCCESS) {
3675 risc_addr = be32_to_cpu(fwcode[2]);
3676 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3677 risc_size = be32_to_cpu(fwcode[3]);
3679 /* Validate firmware image size. */
3680 fwclen += risc_size * sizeof(uint32_t);
3681 if (fw_entry->size < fwclen) {
3682 qla_printk(KERN_WARNING, ha,
3683 "Unable to verify integrity of flash firmware "
3684 "image (%Zd)!\n", fw_entry->size);
3685 goto fail_fw_integrity;
3689 while (risc_size > 0 && rval == QLA_SUCCESS) {
3690 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3691 if (dlen > risc_size)
3694 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3695 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3698 for (i = 0; i < dlen; i++)
3699 dcode[i] = swab32(fwcode[i]);
3701 rval = qla2x00_load_ram_ext(ha, ha->request_dma,
3704 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3705 "segment %d of firmware\n", ha->host_no,
3707 qla_printk(KERN_WARNING, ha,
3708 "[ERROR] Failed to load segment %d of "
3709 "firmware\n", fragment);
3723 release_firmware(fw_entry);
3728 release_firmware(fw_entry);
3729 return QLA_FUNCTION_FAILED;