2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2005 QLogic Corporation
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
21 #include <linux/delay.h>
22 #include <linux/vmalloc.h>
23 #include <linux/firmware.h>
24 #include <scsi/scsi_transport_fc.h>
26 #include "qla_devtbl.h"
28 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
29 #ifndef EXT_IS_LUN_BIT_SET
30 #define EXT_IS_LUN_BIT_SET(P,L) \
31 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
32 #define EXT_SET_LUN_BIT(P,L) \
33 ((P)->mask[L/8] |= (0x80 >> (L%8)))
37 * QLogic ISP2x00 Hardware Support Function Prototypes.
39 static int qla2x00_isp_firmware(scsi_qla_host_t *);
40 static void qla2x00_resize_request_q(scsi_qla_host_t *);
41 static int qla2x00_setup_chip(scsi_qla_host_t *);
42 static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
43 static int qla2x00_init_rings(scsi_qla_host_t *);
44 static int qla2x00_fw_ready(scsi_qla_host_t *);
45 static int qla2x00_configure_hba(scsi_qla_host_t *);
46 static int qla2x00_configure_loop(scsi_qla_host_t *);
47 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
48 static void qla2x00_update_fcport(scsi_qla_host_t *, fc_port_t *);
49 static int qla2x00_configure_fabric(scsi_qla_host_t *);
50 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
51 static int qla2x00_device_resync(scsi_qla_host_t *);
52 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
55 static int qla2x00_restart_isp(scsi_qla_host_t *);
57 /****************************************************************************/
58 /* QLogic ISP2x00 Hardware Support Functions. */
59 /****************************************************************************/
62 * qla2x00_initialize_adapter
66 * ha = adapter block pointer.
72 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
75 uint8_t restart_risc = 0;
79 /* Clear adapter flags. */
81 ha->flags.reset_active = 0;
82 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
83 atomic_set(&ha->loop_state, LOOP_DOWN);
86 ha->flags.management_server_logged_in = 0;
87 ha->marker_needed = 0;
89 ha->isp_abort_cnt = 0;
90 ha->beacon_blink_led = 0;
91 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
93 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
94 rval = ha->isp_ops.pci_config(ha);
96 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
101 ha->isp_ops.reset_chip(ha);
103 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
105 ha->isp_ops.nvram_config(ha);
107 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
111 * Try to configure the loop.
116 /* If firmware needs to be loaded */
117 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
118 if ((rval = ha->isp_ops.chip_diag(ha)) == QLA_SUCCESS) {
119 rval = qla2x00_setup_chip(ha);
123 if (rval == QLA_SUCCESS &&
124 (rval = qla2x00_init_rings(ha)) == QLA_SUCCESS) {
125 check_fw_ready_again:
127 * Wait for a successful LIP up to a maximum
128 * of (in seconds): RISC login timeout value,
129 * RISC retry count value, and port down retry
130 * value OR a minimum of 4 seconds OR If no
131 * cable, only 5 seconds.
133 rval = qla2x00_fw_ready(ha);
134 if (rval == QLA_SUCCESS) {
135 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
137 /* Issue a marker after FW becomes ready. */
138 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
141 * Wait at most MAX_TARGET RSCNs for a stable
146 clear_bit(LOOP_RESYNC_NEEDED,
148 rval = qla2x00_configure_loop(ha);
150 if (test_and_clear_bit(ISP_ABORT_NEEDED,
157 * If loop state change while we were
158 * discoverying devices then wait for
162 if (atomic_read(&ha->loop_state) ==
163 LOOP_DOWN && retry--) {
164 goto check_fw_ready_again;
167 } while (!atomic_read(&ha->loop_down_timer) &&
170 (test_bit(LOOP_RESYNC_NEEDED,
174 rval = QLA_FUNCTION_FAILED;
175 } else if (ha->device_flags & DFLG_NO_CABLE)
176 /* If no cable, then all is good. */
179 } while (restart_risc && retry--);
181 if (rval == QLA_SUCCESS) {
182 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
183 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
184 ha->marker_needed = 0;
186 ha->flags.online = 1;
188 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
195 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
198 * Returns 0 on success.
201 qla2100_pci_config(scsi_qla_host_t *ha)
205 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
207 pci_set_master(ha->pdev);
209 if (pci_set_mwi(ha->pdev))
210 mwi = PCI_COMMAND_INVALIDATE;
211 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
213 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
214 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
215 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
217 /* Reset expansion ROM address decode enable */
218 pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w);
219 w &= ~PCI_ROM_ADDRESS_ENABLE;
220 pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
222 /* Get PCI bus information. */
223 spin_lock_irqsave(&ha->hardware_lock, flags);
224 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
225 spin_unlock_irqrestore(&ha->hardware_lock, flags);
231 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
234 * Returns 0 on success.
237 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_word(ha->pdev, PCI_ROM_ADDRESS, &w);
306 w &= ~PCI_ROM_ADDRESS_ENABLE;
307 pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
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)
327 unsigned long flags = 0;
328 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
329 int pcix_cmd_reg, pcie_dctl_reg;
331 pci_set_master(ha->pdev);
333 if (pci_set_mwi(ha->pdev))
334 mwi = PCI_COMMAND_INVALIDATE;
335 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
337 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
338 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
339 w &= ~PCI_COMMAND_INTX_DISABLE;
340 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
342 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
344 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
345 pcix_cmd_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX);
349 pcix_cmd_reg += PCI_X_CMD;
350 pci_read_config_word(ha->pdev, pcix_cmd_reg, &pcix_cmd);
351 pcix_cmd &= ~PCI_X_CMD_MAX_READ;
353 pci_write_config_word(ha->pdev, pcix_cmd_reg, pcix_cmd);
356 /* PCIe -- adjust Maximum Read Request Size (2048). */
357 pcie_dctl_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
361 pcie_dctl_reg += PCI_EXP_DEVCTL;
362 pci_read_config_word(ha->pdev, pcie_dctl_reg, &pcie_dctl);
363 pcie_dctl &= ~PCI_EXP_DEVCTL_READRQ;
365 pci_write_config_word(ha->pdev, pcie_dctl_reg, pcie_dctl);
368 /* Reset expansion ROM address decode enable */
369 pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w);
370 w &= ~PCI_ROM_ADDRESS_ENABLE;
371 pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
373 /* Get PCI bus information. */
374 spin_lock_irqsave(&ha->hardware_lock, flags);
375 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
376 spin_unlock_irqrestore(&ha->hardware_lock, flags);
382 * qla2x00_isp_firmware() - Choose firmware image.
385 * Returns 0 on success.
388 qla2x00_isp_firmware(scsi_qla_host_t *ha)
392 /* Assume loading risc code */
393 rval = QLA_FUNCTION_FAILED;
395 if (ha->flags.disable_risc_code_load) {
396 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
398 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
400 /* Verify checksum of loaded RISC code. */
401 rval = qla2x00_verify_checksum(ha,
402 IS_QLA24XX(ha) || IS_QLA25XX(ha) ? RISC_SADDRESS :
403 *ha->brd_info->fw_info[0].fwstart);
407 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
415 * qla2x00_reset_chip() - Reset ISP chip.
418 * Returns 0 on success.
421 qla2x00_reset_chip(scsi_qla_host_t *ha)
423 unsigned long flags = 0;
424 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
426 unsigned long mbx_flags = 0;
429 ha->isp_ops.disable_intrs(ha);
431 spin_lock_irqsave(&ha->hardware_lock, flags);
433 /* Turn off master enable */
435 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
436 cmd &= ~PCI_COMMAND_MASTER;
437 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
439 if (!IS_QLA2100(ha)) {
441 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
442 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
443 for (cnt = 0; cnt < 30000; cnt++) {
444 if ((RD_REG_WORD(®->hccr) &
445 HCCR_RISC_PAUSE) != 0)
450 RD_REG_WORD(®->hccr); /* PCI Posting. */
454 /* Select FPM registers. */
455 WRT_REG_WORD(®->ctrl_status, 0x20);
456 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
458 /* FPM Soft Reset. */
459 WRT_REG_WORD(®->fpm_diag_config, 0x100);
460 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
462 /* Toggle Fpm Reset. */
463 if (!IS_QLA2200(ha)) {
464 WRT_REG_WORD(®->fpm_diag_config, 0x0);
465 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
468 /* Select frame buffer registers. */
469 WRT_REG_WORD(®->ctrl_status, 0x10);
470 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
472 /* Reset frame buffer FIFOs. */
473 if (IS_QLA2200(ha)) {
474 WRT_FB_CMD_REG(ha, reg, 0xa000);
475 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
477 WRT_FB_CMD_REG(ha, reg, 0x00fc);
479 /* Read back fb_cmd until zero or 3 seconds max */
480 for (cnt = 0; cnt < 3000; cnt++) {
481 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
487 /* Select RISC module registers. */
488 WRT_REG_WORD(®->ctrl_status, 0);
489 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
491 /* Reset RISC processor. */
492 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
493 RD_REG_WORD(®->hccr); /* PCI Posting. */
495 /* Release RISC processor. */
496 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
497 RD_REG_WORD(®->hccr); /* PCI Posting. */
500 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
501 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
503 /* Reset ISP chip. */
504 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
506 /* Wait for RISC to recover from reset. */
507 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
509 * It is necessary to for a delay here since the card doesn't
510 * respond to PCI reads during a reset. On some architectures
511 * this will result in an MCA.
514 for (cnt = 30000; cnt; cnt--) {
515 if ((RD_REG_WORD(®->ctrl_status) &
516 CSR_ISP_SOFT_RESET) == 0)
523 /* Reset RISC processor. */
524 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
526 WRT_REG_WORD(®->semaphore, 0);
528 /* Release RISC processor. */
529 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
530 RD_REG_WORD(®->hccr); /* PCI Posting. */
532 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
533 for (cnt = 0; cnt < 30000; cnt++) {
534 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
535 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
537 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) {
538 if (!(test_bit(ABORT_ISP_ACTIVE,
540 spin_unlock_irqrestore(
541 &ha->mbx_reg_lock, mbx_flags);
545 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
546 spin_unlock_irqrestore(&ha->mbx_reg_lock,
554 /* Turn on master enable */
555 cmd |= PCI_COMMAND_MASTER;
556 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
558 /* Disable RISC pause on FPM parity error. */
559 if (!IS_QLA2100(ha)) {
560 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
561 RD_REG_WORD(®->hccr); /* PCI Posting. */
564 spin_unlock_irqrestore(&ha->hardware_lock, flags);
568 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
571 * Returns 0 on success.
574 qla24xx_reset_risc(scsi_qla_host_t *ha)
576 unsigned long flags = 0;
577 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
580 spin_lock_irqsave(&ha->hardware_lock, flags);
583 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
584 for (cnt = 0; cnt < 30000; cnt++) {
585 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
591 WRT_REG_DWORD(®->ctrl_status,
592 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
593 RD_REG_DWORD(®->ctrl_status);
595 /* Wait for firmware to complete NVRAM accesses. */
597 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
598 for (cnt = 10000 ; cnt && d2; cnt--) {
600 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
605 d2 = RD_REG_DWORD(®->ctrl_status);
606 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
608 d2 = RD_REG_DWORD(®->ctrl_status);
612 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
613 RD_REG_DWORD(®->hccr);
615 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
616 RD_REG_DWORD(®->hccr);
618 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
619 RD_REG_DWORD(®->hccr);
621 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
622 for (cnt = 6000000 ; cnt && d2; cnt--) {
624 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
628 spin_unlock_irqrestore(&ha->hardware_lock, flags);
632 * qla24xx_reset_chip() - Reset ISP24xx chip.
635 * Returns 0 on success.
638 qla24xx_reset_chip(scsi_qla_host_t *ha)
640 ha->isp_ops.disable_intrs(ha);
642 /* Perform RISC reset. */
643 qla24xx_reset_risc(ha);
647 * qla2x00_chip_diag() - Test chip for proper operation.
650 * Returns 0 on success.
653 qla2x00_chip_diag(scsi_qla_host_t *ha)
656 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
657 unsigned long flags = 0;
662 /* Assume a failed state */
663 rval = QLA_FUNCTION_FAILED;
665 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
666 ha->host_no, (u_long)®->flash_address));
668 spin_lock_irqsave(&ha->hardware_lock, flags);
670 /* Reset ISP chip. */
671 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
674 * We need to have a delay here since the card will not respond while
675 * in reset causing an MCA on some architectures.
678 data = qla2x00_debounce_register(®->ctrl_status);
679 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
681 data = RD_REG_WORD(®->ctrl_status);
686 goto chip_diag_failed;
688 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
691 /* Reset RISC processor. */
692 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
693 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
695 /* Workaround for QLA2312 PCI parity error */
696 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
697 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
698 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
700 data = RD_MAILBOX_REG(ha, reg, 0);
707 goto chip_diag_failed;
709 /* Check product ID of chip */
710 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
712 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
713 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
714 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
715 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
716 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
717 mb[3] != PROD_ID_3) {
718 qla_printk(KERN_WARNING, ha,
719 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
721 goto chip_diag_failed;
723 ha->product_id[0] = mb[1];
724 ha->product_id[1] = mb[2];
725 ha->product_id[2] = mb[3];
726 ha->product_id[3] = mb[4];
728 /* Adjust fw RISC transfer size */
729 if (ha->request_q_length > 1024)
730 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
732 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
733 ha->request_q_length;
735 if (IS_QLA2200(ha) &&
736 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
737 /* Limit firmware transfer size with a 2200A */
738 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
741 ha->fw_transfer_size = 128;
744 /* Wrap Incoming Mailboxes Test. */
745 spin_unlock_irqrestore(&ha->hardware_lock, flags);
747 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
748 rval = qla2x00_mbx_reg_test(ha);
750 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
752 qla_printk(KERN_WARNING, ha,
753 "Failed mailbox send register test\n");
756 /* Flag a successful rval */
759 spin_lock_irqsave(&ha->hardware_lock, flags);
763 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
764 "****\n", ha->host_no));
766 spin_unlock_irqrestore(&ha->hardware_lock, flags);
772 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
775 * Returns 0 on success.
778 qla24xx_chip_diag(scsi_qla_host_t *ha)
782 /* Perform RISC reset. */
783 qla24xx_reset_risc(ha);
785 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
787 rval = qla2x00_mbx_reg_test(ha);
789 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
791 qla_printk(KERN_WARNING, ha,
792 "Failed mailbox send register test\n");
794 /* Flag a successful rval */
802 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
805 ha->fw_dump24_len = sizeof(struct qla24xx_fw_dump);
806 ha->fw_dump24_len += (ha->fw_memory_size - 0x100000) * sizeof(uint32_t);
807 ha->fw_dump24 = vmalloc(ha->fw_dump24_len);
809 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware "
810 "dump...\n", ha->fw_dump24_len / 1024);
812 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
813 "firmware dump!!!\n", ha->fw_dump24_len / 1024);
817 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
820 * Returns 0 on success.
823 qla2x00_resize_request_q(scsi_qla_host_t *ha)
826 uint16_t fw_iocb_cnt = 0;
827 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
828 dma_addr_t request_dma;
829 request_t *request_ring;
831 /* Valid only on recent ISPs. */
832 if (IS_QLA2100(ha) || IS_QLA2200(ha))
835 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
836 qla2x00_alloc_fw_dump(ha);
838 /* Retrieve IOCB counts available to the firmware. */
839 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
842 /* No point in continuing if current settings are sufficient. */
843 if (fw_iocb_cnt < 1024)
845 if (ha->request_q_length >= request_q_length)
848 /* Attempt to claim larger area for request queue. */
849 request_ring = dma_alloc_coherent(&ha->pdev->dev,
850 (request_q_length + 1) * sizeof(request_t), &request_dma,
852 if (request_ring == NULL)
855 /* Resize successful, report extensions. */
856 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
857 (ha->fw_memory_size + 1) / 1024);
858 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
859 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
861 /* Clear old allocations. */
862 dma_free_coherent(&ha->pdev->dev,
863 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
866 /* Begin using larger queue. */
867 ha->request_q_length = request_q_length;
868 ha->request_ring = request_ring;
869 ha->request_dma = request_dma;
873 * qla2x00_setup_chip() - Load and start RISC firmware.
876 * Returns 0 on success.
879 qla2x00_setup_chip(scsi_qla_host_t *ha)
882 uint32_t srisc_address = 0;
884 /* Load firmware sequences */
885 rval = ha->isp_ops.load_risc(ha, &srisc_address);
886 if (rval == QLA_SUCCESS) {
887 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
888 "code.\n", ha->host_no));
890 rval = qla2x00_verify_checksum(ha, srisc_address);
891 if (rval == QLA_SUCCESS) {
892 /* Start firmware execution. */
893 DEBUG(printk("scsi(%ld): Checksum OK, start "
894 "firmware.\n", ha->host_no));
896 rval = qla2x00_execute_fw(ha, srisc_address);
897 /* Retrieve firmware information. */
898 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
899 qla2x00_get_fw_version(ha,
900 &ha->fw_major_version,
901 &ha->fw_minor_version,
902 &ha->fw_subminor_version,
903 &ha->fw_attributes, &ha->fw_memory_size);
904 qla2x00_resize_request_q(ha);
907 DEBUG2(printk(KERN_INFO
908 "scsi(%ld): ISP Firmware failed checksum.\n",
914 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
922 * qla2x00_init_response_q_entries() - Initializes response queue entries.
925 * Beginning of request ring has initialization control block already built
926 * by nvram config routine.
928 * Returns 0 on success.
931 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
936 pkt = ha->response_ring_ptr;
937 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
938 pkt->signature = RESPONSE_PROCESSED;
945 * qla2x00_update_fw_options() - Read and process firmware options.
948 * Returns 0 on success.
951 qla2x00_update_fw_options(scsi_qla_host_t *ha)
953 uint16_t swing, emphasis, tx_sens, rx_sens;
955 memset(ha->fw_options, 0, sizeof(ha->fw_options));
956 qla2x00_get_fw_options(ha, ha->fw_options);
958 if (IS_QLA2100(ha) || IS_QLA2200(ha))
961 /* Serial Link options. */
962 DEBUG3(printk("scsi(%ld): Serial link options:\n",
964 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
965 sizeof(ha->fw_seriallink_options)));
967 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
968 if (ha->fw_seriallink_options[3] & BIT_2) {
969 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
972 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
973 emphasis = (ha->fw_seriallink_options[2] &
974 (BIT_4 | BIT_3)) >> 3;
975 tx_sens = ha->fw_seriallink_options[0] &
976 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
977 rx_sens = (ha->fw_seriallink_options[0] &
978 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
979 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
980 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
983 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
984 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
985 ha->fw_options[10] |= BIT_5 |
986 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
987 (tx_sens & (BIT_1 | BIT_0));
990 swing = (ha->fw_seriallink_options[2] &
991 (BIT_7 | BIT_6 | BIT_5)) >> 5;
992 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
993 tx_sens = ha->fw_seriallink_options[1] &
994 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
995 rx_sens = (ha->fw_seriallink_options[1] &
996 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
997 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
998 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1001 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1002 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1003 ha->fw_options[11] |= BIT_5 |
1004 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1005 (tx_sens & (BIT_1 | BIT_0));
1009 /* Return command IOCBs without waiting for an ABTS to complete. */
1010 ha->fw_options[3] |= BIT_13;
1013 if (ha->flags.enable_led_scheme)
1014 ha->fw_options[2] |= BIT_12;
1016 /* Update firmware options. */
1017 qla2x00_set_fw_options(ha, ha->fw_options);
1021 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1025 /* Update Serial Link options. */
1026 if ((ha->fw_seriallink_options24[0] & BIT_0) == 0)
1029 rval = qla2x00_set_serdes_params(ha, ha->fw_seriallink_options24[1],
1030 ha->fw_seriallink_options24[2], ha->fw_seriallink_options24[3]);
1031 if (rval != QLA_SUCCESS) {
1032 qla_printk(KERN_WARNING, ha,
1033 "Unable to update Serial Link options (%x).\n", rval);
1038 qla2x00_config_rings(struct scsi_qla_host *ha)
1040 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1042 /* Setup ring parameters in initialization control block. */
1043 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1044 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1045 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1046 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1047 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1048 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1049 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1050 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1052 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1053 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1054 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1055 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1056 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1060 qla24xx_config_rings(struct scsi_qla_host *ha)
1062 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1063 struct init_cb_24xx *icb;
1065 /* Setup ring parameters in initialization control block. */
1066 icb = (struct init_cb_24xx *)ha->init_cb;
1067 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1068 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1069 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1070 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1071 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1072 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1073 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1074 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1076 WRT_REG_DWORD(®->req_q_in, 0);
1077 WRT_REG_DWORD(®->req_q_out, 0);
1078 WRT_REG_DWORD(®->rsp_q_in, 0);
1079 WRT_REG_DWORD(®->rsp_q_out, 0);
1080 RD_REG_DWORD(®->rsp_q_out);
1084 * qla2x00_init_rings() - Initializes firmware.
1087 * Beginning of request ring has initialization control block already built
1088 * by nvram config routine.
1090 * Returns 0 on success.
1093 qla2x00_init_rings(scsi_qla_host_t *ha)
1096 unsigned long flags = 0;
1099 spin_lock_irqsave(&ha->hardware_lock, flags);
1101 /* Clear outstanding commands array. */
1102 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1103 ha->outstanding_cmds[cnt] = NULL;
1105 ha->current_outstanding_cmd = 0;
1107 /* Clear RSCN queue. */
1108 ha->rscn_in_ptr = 0;
1109 ha->rscn_out_ptr = 0;
1111 /* Initialize firmware. */
1112 ha->request_ring_ptr = ha->request_ring;
1113 ha->req_ring_index = 0;
1114 ha->req_q_cnt = ha->request_q_length;
1115 ha->response_ring_ptr = ha->response_ring;
1116 ha->rsp_ring_index = 0;
1118 /* Initialize response queue entries */
1119 qla2x00_init_response_q_entries(ha);
1121 ha->isp_ops.config_rings(ha);
1123 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1125 /* Update any ISP specific firmware options before initialization. */
1126 ha->isp_ops.update_fw_options(ha);
1128 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1129 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1131 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1134 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1142 * qla2x00_fw_ready() - Waits for firmware ready.
1145 * Returns 0 on success.
1148 qla2x00_fw_ready(scsi_qla_host_t *ha)
1151 unsigned long wtime, mtime;
1152 uint16_t min_wait; /* Minimum wait time if loop is down */
1153 uint16_t wait_time; /* Wait time if loop is coming ready */
1158 /* 20 seconds for loop down. */
1162 * Firmware should take at most one RATOV to login, plus 5 seconds for
1163 * our own processing.
1165 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1166 wait_time = min_wait;
1169 /* Min wait time if loop down */
1170 mtime = jiffies + (min_wait * HZ);
1172 /* wait time before firmware ready */
1173 wtime = jiffies + (wait_time * HZ);
1175 /* Wait for ISP to finish LIP */
1176 if (!ha->flags.init_done)
1177 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1179 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1183 rval = qla2x00_get_firmware_state(ha, &fw_state);
1184 if (rval == QLA_SUCCESS) {
1185 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1186 ha->device_flags &= ~DFLG_NO_CABLE;
1188 if (fw_state == FSTATE_READY) {
1189 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1192 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1193 &ha->login_timeout, &ha->r_a_tov);
1199 rval = QLA_FUNCTION_FAILED;
1201 if (atomic_read(&ha->loop_down_timer) &&
1202 (fw_state >= FSTATE_LOSS_OF_SYNC ||
1203 fw_state == FSTATE_WAIT_AL_PA)) {
1204 /* Loop down. Timeout on min_wait for states
1205 * other than Wait for Login.
1207 if (time_after_eq(jiffies, mtime)) {
1208 qla_printk(KERN_INFO, ha,
1209 "Cable is unplugged...\n");
1211 ha->device_flags |= DFLG_NO_CABLE;
1216 /* Mailbox cmd failed. Timeout on min_wait. */
1217 if (time_after_eq(jiffies, mtime))
1221 if (time_after_eq(jiffies, wtime))
1224 /* Delay for a while */
1227 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1228 ha->host_no, fw_state, jiffies));
1231 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1232 ha->host_no, fw_state, jiffies));
1235 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1243 * qla2x00_configure_hba
1244 * Setup adapter context.
1247 * ha = adapter state pointer.
1256 qla2x00_configure_hba(scsi_qla_host_t *ha)
1264 char connect_type[22];
1266 /* Get host addresses. */
1267 rval = qla2x00_get_adapter_id(ha,
1268 &loop_id, &al_pa, &area, &domain, &topo);
1269 if (rval != QLA_SUCCESS) {
1270 qla_printk(KERN_WARNING, ha,
1271 "ERROR -- Unable to get host loop ID.\n");
1272 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1277 qla_printk(KERN_INFO, ha,
1278 "Cannot get topology - retrying.\n");
1279 return (QLA_FUNCTION_FAILED);
1282 ha->loop_id = loop_id;
1285 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1286 ha->operating_mode = LOOP;
1290 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1292 ha->current_topology = ISP_CFG_NL;
1293 strcpy(connect_type, "(Loop)");
1297 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1299 ha->current_topology = ISP_CFG_FL;
1300 strcpy(connect_type, "(FL_Port)");
1304 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1306 ha->operating_mode = P2P;
1307 ha->current_topology = ISP_CFG_N;
1308 strcpy(connect_type, "(N_Port-to-N_Port)");
1312 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1314 ha->operating_mode = P2P;
1315 ha->current_topology = ISP_CFG_F;
1316 strcpy(connect_type, "(F_Port)");
1320 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1322 ha->host_no, topo));
1323 ha->current_topology = ISP_CFG_NL;
1324 strcpy(connect_type, "(Loop)");
1328 /* Save Host port and loop ID. */
1329 /* byte order - Big Endian */
1330 ha->d_id.b.domain = domain;
1331 ha->d_id.b.area = area;
1332 ha->d_id.b.al_pa = al_pa;
1334 if (!ha->flags.init_done)
1335 qla_printk(KERN_INFO, ha,
1336 "Topology - %s, Host Loop address 0x%x\n",
1337 connect_type, ha->loop_id);
1340 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1342 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1349 * NVRAM configuration for ISP 2xxx
1352 * ha = adapter block pointer.
1355 * initialization control block in response_ring
1356 * host adapters parameters in host adapter block
1362 qla2x00_nvram_config(scsi_qla_host_t *ha)
1367 uint8_t *dptr1, *dptr2;
1368 init_cb_t *icb = ha->init_cb;
1369 nvram_t *nv = (nvram_t *)ha->request_ring;
1370 uint8_t *ptr = (uint8_t *)ha->request_ring;
1371 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1376 /* Determine NVRAM starting address. */
1377 ha->nvram_size = sizeof(nvram_t);
1379 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1380 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1381 ha->nvram_base = 0x80;
1383 /* Get NVRAM data and calculate checksum. */
1384 ha->isp_ops.read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1385 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1388 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1389 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1392 /* Bad NVRAM data, set defaults parameters. */
1393 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1394 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1395 /* Reset NVRAM data. */
1396 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1397 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1399 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1400 "invalid -- WWPN) defaults.\n");
1403 * Set default initialization control block.
1405 memset(nv, 0, ha->nvram_size);
1406 nv->parameter_block_version = ICB_VERSION;
1408 if (IS_QLA23XX(ha)) {
1409 nv->firmware_options[0] = BIT_2 | BIT_1;
1410 nv->firmware_options[1] = BIT_7 | BIT_5;
1411 nv->add_firmware_options[0] = BIT_5;
1412 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1413 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1414 nv->special_options[1] = BIT_7;
1415 } else if (IS_QLA2200(ha)) {
1416 nv->firmware_options[0] = BIT_2 | BIT_1;
1417 nv->firmware_options[1] = BIT_7 | BIT_5;
1418 nv->add_firmware_options[0] = BIT_5;
1419 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1420 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1421 } else if (IS_QLA2100(ha)) {
1422 nv->firmware_options[0] = BIT_3 | BIT_1;
1423 nv->firmware_options[1] = BIT_5;
1424 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1427 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1428 nv->execution_throttle = __constant_cpu_to_le16(16);
1429 nv->retry_count = 8;
1430 nv->retry_delay = 1;
1432 nv->port_name[0] = 33;
1433 nv->port_name[3] = 224;
1434 nv->port_name[4] = 139;
1436 nv->login_timeout = 4;
1439 * Set default host adapter parameters
1441 nv->host_p[1] = BIT_2;
1442 nv->reset_delay = 5;
1443 nv->port_down_retry_count = 8;
1444 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1445 nv->link_down_timeout = 60;
1450 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1452 * The SN2 does not provide BIOS emulation which means you can't change
1453 * potentially bogus BIOS settings. Force the use of default settings
1454 * for link rate and frame size. Hope that the rest of the settings
1457 if (ia64_platform_is("sn2")) {
1458 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1460 nv->special_options[1] = BIT_7;
1464 /* Reset Initialization control block */
1465 memset(icb, 0, ha->init_cb_size);
1468 * Setup driver NVRAM options.
1470 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1471 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1472 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1473 nv->firmware_options[1] &= ~BIT_4;
1475 if (IS_QLA23XX(ha)) {
1476 nv->firmware_options[0] |= BIT_2;
1477 nv->firmware_options[0] &= ~BIT_3;
1478 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1480 if (IS_QLA2300(ha)) {
1481 if (ha->fb_rev == FPM_2310) {
1482 strcpy(ha->model_number, "QLA2310");
1484 strcpy(ha->model_number, "QLA2300");
1488 memcmp(nv->model_number, BINZERO,
1489 sizeof(nv->model_number)) != 0) {
1492 strncpy(ha->model_number, nv->model_number,
1493 sizeof(nv->model_number));
1494 st = en = ha->model_number;
1495 en += sizeof(nv->model_number) - 1;
1497 if (*en != 0x20 && *en != 0x00)
1504 index = (ha->pdev->subsystem_device & 0xff);
1505 if (index < QLA_MODEL_NAMES) {
1506 strcpy(ha->model_number,
1507 qla2x00_model_name[index]);
1509 qla2x00_model_desc[index];
1511 strcpy(ha->model_number, "QLA23xx");
1515 } else if (IS_QLA2200(ha)) {
1516 nv->firmware_options[0] |= BIT_2;
1518 * 'Point-to-point preferred, else loop' is not a safe
1519 * connection mode setting.
1521 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1523 /* Force 'loop preferred, else point-to-point'. */
1524 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1525 nv->add_firmware_options[0] |= BIT_5;
1527 strcpy(ha->model_number, "QLA22xx");
1528 } else /*if (IS_QLA2100(ha))*/ {
1529 strcpy(ha->model_number, "QLA2100");
1533 * Copy over NVRAM RISC parameter block to initialization control block.
1535 dptr1 = (uint8_t *)icb;
1536 dptr2 = (uint8_t *)&nv->parameter_block_version;
1537 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1539 *dptr1++ = *dptr2++;
1541 /* Copy 2nd half. */
1542 dptr1 = (uint8_t *)icb->add_firmware_options;
1543 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1545 *dptr1++ = *dptr2++;
1547 /* Prepare nodename */
1548 if ((icb->firmware_options[1] & BIT_6) == 0) {
1550 * Firmware will apply the following mask if the nodename was
1553 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1554 icb->node_name[0] &= 0xF0;
1558 * Set host adapter parameters.
1560 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1561 /* Always load RISC code on non ISP2[12]00 chips. */
1562 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1563 ha->flags.disable_risc_code_load = 0;
1564 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1565 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1566 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1567 ha->flags.enable_led_scheme = ((nv->efi_parameters & BIT_3) ? 1 : 0);
1569 ha->operating_mode =
1570 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1572 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1573 sizeof(ha->fw_seriallink_options));
1575 /* save HBA serial number */
1576 ha->serial0 = icb->port_name[5];
1577 ha->serial1 = icb->port_name[6];
1578 ha->serial2 = icb->port_name[7];
1579 ha->node_name = icb->node_name;
1580 ha->port_name = icb->port_name;
1582 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1584 ha->retry_count = nv->retry_count;
1586 /* Set minimum login_timeout to 4 seconds. */
1587 if (nv->login_timeout < ql2xlogintimeout)
1588 nv->login_timeout = ql2xlogintimeout;
1589 if (nv->login_timeout < 4)
1590 nv->login_timeout = 4;
1591 ha->login_timeout = nv->login_timeout;
1592 icb->login_timeout = nv->login_timeout;
1594 /* Set minimum RATOV to 200 tenths of a second. */
1597 ha->loop_reset_delay = nv->reset_delay;
1599 /* Link Down Timeout = 0:
1601 * When Port Down timer expires we will start returning
1602 * I/O's to OS with "DID_NO_CONNECT".
1604 * Link Down Timeout != 0:
1606 * The driver waits for the link to come up after link down
1607 * before returning I/Os to OS with "DID_NO_CONNECT".
1609 if (nv->link_down_timeout == 0) {
1610 ha->loop_down_abort_time =
1611 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1613 ha->link_down_timeout = nv->link_down_timeout;
1614 ha->loop_down_abort_time =
1615 (LOOP_DOWN_TIME - ha->link_down_timeout);
1619 * Need enough time to try and get the port back.
1621 ha->port_down_retry_count = nv->port_down_retry_count;
1622 if (qlport_down_retry)
1623 ha->port_down_retry_count = qlport_down_retry;
1624 /* Set login_retry_count */
1625 ha->login_retry_count = nv->retry_count;
1626 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1627 ha->port_down_retry_count > 3)
1628 ha->login_retry_count = ha->port_down_retry_count;
1629 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1630 ha->login_retry_count = ha->port_down_retry_count;
1631 if (ql2xloginretrycount)
1632 ha->login_retry_count = ql2xloginretrycount;
1634 icb->lun_enables = __constant_cpu_to_le16(0);
1635 icb->command_resource_count = 0;
1636 icb->immediate_notify_resource_count = 0;
1637 icb->timeout = __constant_cpu_to_le16(0);
1639 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1641 icb->firmware_options[0] &= ~BIT_3;
1642 icb->add_firmware_options[0] &=
1643 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1644 icb->add_firmware_options[0] |= BIT_2;
1645 icb->response_accumulation_timer = 3;
1646 icb->interrupt_delay_timer = 5;
1648 ha->flags.process_response_queue = 1;
1650 /* Enable ZIO -- Support mode 5 only. */
1651 timer_mode = icb->add_firmware_options[0] &
1652 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1653 icb->add_firmware_options[0] &=
1654 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1656 timer_mode = BIT_2 | BIT_0;
1657 if (timer_mode == (BIT_2 | BIT_0)) {
1658 DEBUG2(printk("scsi(%ld): ZIO enabled; timer delay "
1659 "(%d).\n", ha->host_no, ql2xintrdelaytimer));
1660 qla_printk(KERN_INFO, ha,
1661 "ZIO enabled; timer delay (%d).\n",
1662 ql2xintrdelaytimer);
1664 icb->add_firmware_options[0] |= timer_mode;
1665 icb->interrupt_delay_timer = ql2xintrdelaytimer;
1666 ha->flags.process_response_queue = 1;
1671 DEBUG2_3(printk(KERN_WARNING
1672 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1678 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1680 * @flags: allocation flags
1682 * Returns a pointer to the allocated fcport, or NULL, if none available.
1685 qla2x00_alloc_fcport(scsi_qla_host_t *ha, int flags)
1689 fcport = kmalloc(sizeof(fc_port_t), flags);
1693 /* Setup fcport template structure. */
1694 memset(fcport, 0, sizeof (fc_port_t));
1696 fcport->port_type = FCT_UNKNOWN;
1697 fcport->loop_id = FC_NO_LOOP_ID;
1698 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1699 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1700 fcport->flags = FCF_RLC_SUPPORT;
1701 fcport->supported_classes = FC_COS_UNSPECIFIED;
1707 * qla2x00_configure_loop
1708 * Updates Fibre Channel Device Database with what is actually on loop.
1711 * ha = adapter block pointer.
1716 * 2 = database was full and device was not configured.
1719 qla2x00_configure_loop(scsi_qla_host_t *ha)
1722 unsigned long flags, save_flags;
1726 /* Get Initiator ID */
1727 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1728 rval = qla2x00_configure_hba(ha);
1729 if (rval != QLA_SUCCESS) {
1730 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1736 save_flags = flags = ha->dpc_flags;
1737 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1738 ha->host_no, flags));
1741 * If we have both an RSCN and PORT UPDATE pending then handle them
1742 * both at the same time.
1744 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1745 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1747 /* Determine what we need to do */
1748 if (ha->current_topology == ISP_CFG_FL &&
1749 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1751 ha->flags.rscn_queue_overflow = 1;
1752 set_bit(RSCN_UPDATE, &flags);
1754 } else if (ha->current_topology == ISP_CFG_F &&
1755 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1757 ha->flags.rscn_queue_overflow = 1;
1758 set_bit(RSCN_UPDATE, &flags);
1759 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1761 } else if (!ha->flags.online ||
1762 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1764 ha->flags.rscn_queue_overflow = 1;
1765 set_bit(RSCN_UPDATE, &flags);
1766 set_bit(LOCAL_LOOP_UPDATE, &flags);
1769 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1770 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1771 rval = QLA_FUNCTION_FAILED;
1773 rval = qla2x00_configure_local_loop(ha);
1777 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1778 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1779 rval = QLA_FUNCTION_FAILED;
1781 rval = qla2x00_configure_fabric(ha);
1785 if (rval == QLA_SUCCESS) {
1786 if (atomic_read(&ha->loop_down_timer) ||
1787 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1788 rval = QLA_FUNCTION_FAILED;
1790 atomic_set(&ha->loop_state, LOOP_READY);
1792 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1797 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1798 __func__, ha->host_no));
1800 DEBUG3(printk("%s: exiting normally\n", __func__));
1803 /* Restore state if a resync event occured during processing */
1804 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1805 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1806 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1807 if (test_bit(RSCN_UPDATE, &save_flags))
1808 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1817 * qla2x00_configure_local_loop
1818 * Updates Fibre Channel Device Database with local loop devices.
1821 * ha = adapter block pointer.
1827 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1832 fc_port_t *fcport, *new_fcport;
1838 uint8_t domain, area, al_pa;
1842 entries = MAX_FIBRE_DEVICES;
1844 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1845 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1847 /* Get list of logged in devices. */
1848 memset(ha->gid_list, 0, GID_LIST_SIZE);
1849 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1851 if (rval != QLA_SUCCESS)
1852 goto cleanup_allocation;
1854 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1855 ha->host_no, entries));
1856 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1857 entries * sizeof(struct gid_list_info)));
1859 /* Allocate temporary fcport for any new fcports discovered. */
1860 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1861 if (new_fcport == NULL) {
1862 rval = QLA_MEMORY_ALLOC_FAILED;
1863 goto cleanup_allocation;
1865 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1868 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1870 list_for_each_entry(fcport, &ha->fcports, list) {
1871 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1872 fcport->port_type != FCT_BROADCAST &&
1873 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1875 DEBUG(printk("scsi(%ld): Marking port lost, "
1877 ha->host_no, fcport->loop_id));
1879 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1880 fcport->flags &= ~FCF_FARP_DONE;
1884 /* Add devices to port list. */
1885 id_iter = (char *)ha->gid_list;
1886 for (index = 0; index < entries; index++) {
1887 domain = ((struct gid_list_info *)id_iter)->domain;
1888 area = ((struct gid_list_info *)id_iter)->area;
1889 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1890 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1891 loop_id = (uint16_t)
1892 ((struct gid_list_info *)id_iter)->loop_id_2100;
1894 loop_id = le16_to_cpu(
1895 ((struct gid_list_info *)id_iter)->loop_id);
1896 id_iter += ha->gid_list_info_size;
1898 /* Bypass reserved domain fields. */
1899 if ((domain & 0xf0) == 0xf0)
1902 /* Bypass if not same domain and area of adapter. */
1903 if (area != ha->d_id.b.area || domain != ha->d_id.b.domain)
1906 /* Bypass invalid local loop ID. */
1907 if (loop_id > LAST_LOCAL_LOOP_ID)
1910 /* Fill in member data. */
1911 new_fcport->d_id.b.domain = domain;
1912 new_fcport->d_id.b.area = area;
1913 new_fcport->d_id.b.al_pa = al_pa;
1914 new_fcport->loop_id = loop_id;
1915 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1916 if (rval2 != QLA_SUCCESS) {
1917 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1918 "information -- get_port_database=%x, "
1920 ha->host_no, rval2, new_fcport->loop_id));
1924 /* Check for matching device in port list. */
1927 list_for_each_entry(fcport, &ha->fcports, list) {
1928 if (memcmp(new_fcport->port_name, fcport->port_name,
1932 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1933 FCF_PERSISTENT_BOUND);
1934 fcport->loop_id = new_fcport->loop_id;
1935 fcport->port_type = new_fcport->port_type;
1936 fcport->d_id.b24 = new_fcport->d_id.b24;
1937 memcpy(fcport->node_name, new_fcport->node_name,
1945 /* New device, add to fcports list. */
1946 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1947 list_add_tail(&new_fcport->list, &ha->fcports);
1949 /* Allocate a new replacement fcport. */
1950 fcport = new_fcport;
1951 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1952 if (new_fcport == NULL) {
1953 rval = QLA_MEMORY_ALLOC_FAILED;
1954 goto cleanup_allocation;
1956 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1959 qla2x00_update_fcport(ha, fcport);
1968 if (rval != QLA_SUCCESS) {
1969 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1970 "rval=%x\n", ha->host_no, rval));
1974 ha->device_flags |= DFLG_LOCAL_DEVICES;
1975 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
1982 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
1986 qla2x00_mark_all_devices_lost(ha);
1987 list_for_each_entry(fcport, &ha->fcports, list) {
1988 if (fcport->port_type != FCT_TARGET)
1991 qla2x00_update_fcport(ha, fcport);
1996 * qla2x00_update_fcport
1997 * Updates device on list.
2000 * ha = adapter block pointer.
2001 * fcport = port structure pointer.
2011 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2014 unsigned long flags;
2018 fcport->login_retry = 0;
2019 fcport->port_login_retry_count = ha->port_down_retry_count *
2021 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2023 fcport->flags &= ~FCF_LOGIN_NEEDED;
2026 * Check for outstanding cmd on tape Bypass LUN discovery if active
2029 if (fcport->flags & FCF_TAPE_PRESENT) {
2030 spin_lock_irqsave(&ha->hardware_lock, flags);
2031 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
2034 if ((sp = ha->outstanding_cmds[index]) != 0) {
2036 if (sfcp == fcport) {
2037 atomic_set(&fcport->state, FCS_ONLINE);
2038 spin_unlock_irqrestore(
2039 &ha->hardware_lock, flags);
2044 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2047 if (fcport->port_type == FCT_INITIATOR ||
2048 fcport->port_type == FCT_BROADCAST)
2049 fcport->device_type = TYPE_PROCESSOR;
2051 atomic_set(&fcport->state, FCS_ONLINE);
2053 if (ha->flags.init_done)
2054 qla2x00_reg_remote_port(ha, fcport);
2058 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2060 struct fc_rport_identifiers rport_ids;
2061 struct fc_rport *rport;
2063 if (fcport->rport) {
2064 fc_remote_port_unblock(fcport->rport);
2068 rport_ids.node_name = be64_to_cpu(*(uint64_t *)fcport->node_name);
2069 rport_ids.port_name = be64_to_cpu(*(uint64_t *)fcport->port_name);
2070 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2071 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2072 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2073 fcport->rport = rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2075 qla_printk(KERN_WARNING, ha,
2076 "Unable to allocate fc remote port!\n");
2079 rport->dd_data = fcport;
2080 rport->supported_classes = fcport->supported_classes;
2082 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2083 if (fcport->port_type == FCT_INITIATOR)
2084 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2085 if (fcport->port_type == FCT_TARGET)
2086 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2087 fc_remote_port_rolechg(rport, rport_ids.roles);
2089 if (rport->scsi_target_id != -1 &&
2090 rport->scsi_target_id < ha->host->max_id)
2091 fcport->os_target_id = rport->scsi_target_id;
2095 * qla2x00_configure_fabric
2096 * Setup SNS devices with loop ID's.
2099 * ha = adapter block pointer.
2106 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2109 fc_port_t *fcport, *fcptemp;
2110 uint16_t next_loopid;
2111 uint16_t mb[MAILBOX_REGISTER_COUNT];
2113 LIST_HEAD(new_fcports);
2115 /* If FL port exists, then SNS is present */
2116 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
2117 loop_id = NPH_F_PORT;
2119 loop_id = SNS_FL_PORT;
2120 rval = qla2x00_get_port_name(ha, loop_id, NULL, 0);
2121 if (rval != QLA_SUCCESS) {
2122 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2123 "Port\n", ha->host_no));
2125 ha->device_flags &= ~SWITCH_FOUND;
2126 return (QLA_SUCCESS);
2129 /* Mark devices that need re-synchronization. */
2130 rval2 = qla2x00_device_resync(ha);
2131 if (rval2 == QLA_RSCNS_HANDLED) {
2132 /* No point doing the scan, just continue. */
2133 return (QLA_SUCCESS);
2137 if (ql2xfdmienable &&
2138 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2139 qla2x00_fdmi_register(ha);
2141 /* Ensure we are logged into the SNS. */
2142 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
2145 loop_id = SIMPLE_NAME_SERVER;
2146 ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
2147 0xfc, mb, BIT_1 | BIT_0);
2148 if (mb[0] != MBS_COMMAND_COMPLETE) {
2149 DEBUG2(qla_printk(KERN_INFO, ha,
2150 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2151 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2152 mb[0], mb[1], mb[2], mb[6], mb[7]));
2153 return (QLA_SUCCESS);
2156 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2157 if (qla2x00_rft_id(ha)) {
2159 DEBUG2(printk("scsi(%ld): Register FC-4 "
2160 "TYPE failed.\n", ha->host_no));
2162 if (qla2x00_rff_id(ha)) {
2164 DEBUG2(printk("scsi(%ld): Register FC-4 "
2165 "Features failed.\n", ha->host_no));
2167 if (qla2x00_rnn_id(ha)) {
2169 DEBUG2(printk("scsi(%ld): Register Node Name "
2170 "failed.\n", ha->host_no));
2171 } else if (qla2x00_rsnn_nn(ha)) {
2173 DEBUG2(printk("scsi(%ld): Register Symbolic "
2174 "Node Name failed.\n", ha->host_no));
2178 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2179 if (rval != QLA_SUCCESS)
2183 * Logout all previous fabric devices marked lost, except
2186 list_for_each_entry(fcport, &ha->fcports, list) {
2187 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2190 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2193 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2194 qla2x00_mark_device_lost(ha, fcport,
2195 ql2xplogiabsentdevice);
2196 if (fcport->loop_id != FC_NO_LOOP_ID &&
2197 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2198 fcport->port_type != FCT_INITIATOR &&
2199 fcport->port_type != FCT_BROADCAST) {
2201 ha->isp_ops.fabric_logout(ha,
2203 fcport->d_id.b.domain,
2204 fcport->d_id.b.area,
2205 fcport->d_id.b.al_pa);
2206 fcport->loop_id = FC_NO_LOOP_ID;
2211 /* Starting free loop ID. */
2212 next_loopid = ha->min_external_loopid;
2215 * Scan through our port list and login entries that need to be
2218 list_for_each_entry(fcport, &ha->fcports, list) {
2219 if (atomic_read(&ha->loop_down_timer) ||
2220 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2223 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2224 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2227 if (fcport->loop_id == FC_NO_LOOP_ID) {
2228 fcport->loop_id = next_loopid;
2229 rval = qla2x00_find_new_loop_id(ha, fcport);
2230 if (rval != QLA_SUCCESS) {
2231 /* Ran out of IDs to use */
2235 /* Login and update database */
2236 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2239 /* Exit if out of loop IDs. */
2240 if (rval != QLA_SUCCESS) {
2245 * Login and add the new devices to our port list.
2247 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2248 if (atomic_read(&ha->loop_down_timer) ||
2249 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2252 /* Find a new loop ID to use. */
2253 fcport->loop_id = next_loopid;
2254 rval = qla2x00_find_new_loop_id(ha, fcport);
2255 if (rval != QLA_SUCCESS) {
2256 /* Ran out of IDs to use */
2260 /* Remove device from the new list and add it to DB */
2261 list_del(&fcport->list);
2262 list_add_tail(&fcport->list, &ha->fcports);
2264 /* Login and update database */
2265 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2269 /* Free all new device structures not processed. */
2270 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2271 list_del(&fcport->list);
2276 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2277 "rval=%d\n", ha->host_no, rval));
2285 * qla2x00_find_all_fabric_devs
2288 * ha = adapter block pointer.
2289 * dev = database device entry pointer.
2298 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2302 fc_port_t *fcport, *new_fcport, *fcptemp;
2307 int first_dev, last_dev;
2308 port_id_t wrap, nxt_d_id;
2312 /* Try GID_PT to get device list, else GAN. */
2313 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2316 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2317 "on GA_NXT\n", ha->host_no));
2319 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2320 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2323 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2326 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2333 /* Allocate temporary fcport for any new fcports discovered. */
2334 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2335 if (new_fcport == NULL) {
2338 return (QLA_MEMORY_ALLOC_FAILED);
2340 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2342 /* Set start port ID scan at adapter ID. */
2346 /* Starting free loop ID. */
2347 loop_id = ha->min_external_loopid;
2348 for (; loop_id <= ha->last_loop_id; loop_id++) {
2349 if (qla2x00_is_reserved_id(ha, loop_id))
2352 if (atomic_read(&ha->loop_down_timer) ||
2353 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2358 wrap.b24 = new_fcport->d_id.b24;
2360 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2361 memcpy(new_fcport->node_name,
2362 swl[swl_idx].node_name, WWN_SIZE);
2363 memcpy(new_fcport->port_name,
2364 swl[swl_idx].port_name, WWN_SIZE);
2366 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2372 /* Send GA_NXT to the switch */
2373 rval = qla2x00_ga_nxt(ha, new_fcport);
2374 if (rval != QLA_SUCCESS) {
2375 qla_printk(KERN_WARNING, ha,
2376 "SNS scan failed -- assuming zero-entry "
2378 list_for_each_entry_safe(fcport, fcptemp,
2379 new_fcports, list) {
2380 list_del(&fcport->list);
2388 /* If wrap on switch device list, exit. */
2390 wrap.b24 = new_fcport->d_id.b24;
2392 } else if (new_fcport->d_id.b24 == wrap.b24) {
2393 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2394 ha->host_no, new_fcport->d_id.b.domain,
2395 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2399 /* Bypass if host adapter. */
2400 if (new_fcport->d_id.b24 == ha->d_id.b24)
2403 /* Bypass reserved domain fields. */
2404 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2407 /* Locate matching device in database. */
2409 list_for_each_entry(fcport, &ha->fcports, list) {
2410 if (memcmp(new_fcport->port_name, fcport->port_name,
2417 * If address the same and state FCS_ONLINE, nothing
2420 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2421 atomic_read(&fcport->state) == FCS_ONLINE) {
2426 * If device was not a fabric device before.
2428 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2429 fcport->d_id.b24 = new_fcport->d_id.b24;
2430 fcport->loop_id = FC_NO_LOOP_ID;
2431 fcport->flags |= (FCF_FABRIC_DEVICE |
2433 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2438 * Port ID changed or device was marked to be updated;
2439 * Log it out if still logged in and mark it for
2442 fcport->d_id.b24 = new_fcport->d_id.b24;
2443 fcport->flags |= FCF_LOGIN_NEEDED;
2444 if (fcport->loop_id != FC_NO_LOOP_ID &&
2445 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2446 fcport->port_type != FCT_INITIATOR &&
2447 fcport->port_type != FCT_BROADCAST) {
2448 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2449 fcport->d_id.b.domain, fcport->d_id.b.area,
2450 fcport->d_id.b.al_pa);
2451 fcport->loop_id = FC_NO_LOOP_ID;
2460 /* If device was not in our fcports list, then add it. */
2461 list_add_tail(&new_fcport->list, new_fcports);
2463 /* Allocate a new replacement fcport. */
2464 nxt_d_id.b24 = new_fcport->d_id.b24;
2465 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2466 if (new_fcport == NULL) {
2469 return (QLA_MEMORY_ALLOC_FAILED);
2471 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2472 new_fcport->d_id.b24 = nxt_d_id.b24;
2481 if (!list_empty(new_fcports))
2482 ha->device_flags |= DFLG_FABRIC_DEVICES;
2488 * qla2x00_find_new_loop_id
2489 * Scan through our port list and find a new usable loop ID.
2492 * ha: adapter state pointer.
2493 * dev: port structure pointer.
2496 * qla2x00 local function return status code.
2502 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2507 uint16_t first_loop_id;
2511 /* Save starting loop ID. */
2512 first_loop_id = dev->loop_id;
2515 /* Skip loop ID if already used by adapter. */
2516 if (dev->loop_id == ha->loop_id) {
2520 /* Skip reserved loop IDs. */
2521 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2525 /* Reset loop ID if passed the end. */
2526 if (dev->loop_id > ha->last_loop_id) {
2527 /* first loop ID. */
2528 dev->loop_id = ha->min_external_loopid;
2531 /* Check for loop ID being already in use. */
2534 list_for_each_entry(fcport, &ha->fcports, list) {
2535 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2536 /* ID possibly in use */
2542 /* If not in use then it is free to use. */
2547 /* ID in use. Try next value. */
2550 /* If wrap around. No free ID to use. */
2551 if (dev->loop_id == first_loop_id) {
2552 dev->loop_id = FC_NO_LOOP_ID;
2553 rval = QLA_FUNCTION_FAILED;
2562 * qla2x00_device_resync
2563 * Marks devices in the database that needs resynchronization.
2566 * ha = adapter block pointer.
2572 qla2x00_device_resync(scsi_qla_host_t *ha)
2578 uint32_t rscn_entry;
2579 uint8_t rscn_out_iter;
2583 rval = QLA_RSCNS_HANDLED;
2585 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2586 ha->flags.rscn_queue_overflow) {
2588 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2589 format = MSB(MSW(rscn_entry));
2590 d_id.b.domain = LSB(MSW(rscn_entry));
2591 d_id.b.area = MSB(LSW(rscn_entry));
2592 d_id.b.al_pa = LSB(LSW(rscn_entry));
2594 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2595 "[%02x/%02x%02x%02x].\n",
2596 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2597 d_id.b.area, d_id.b.al_pa));
2600 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2601 ha->rscn_out_ptr = 0;
2603 /* Skip duplicate entries. */
2604 for (rscn_out_iter = ha->rscn_out_ptr;
2605 !ha->flags.rscn_queue_overflow &&
2606 rscn_out_iter != ha->rscn_in_ptr;
2607 rscn_out_iter = (rscn_out_iter ==
2608 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2610 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2613 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2614 "entry found at [%d].\n", ha->host_no,
2617 ha->rscn_out_ptr = rscn_out_iter;
2620 /* Queue overflow, set switch default case. */
2621 if (ha->flags.rscn_queue_overflow) {
2622 DEBUG(printk("scsi(%ld): device_resync: rscn "
2623 "overflow.\n", ha->host_no));
2626 ha->flags.rscn_queue_overflow = 0;
2631 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) &&
2632 !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
2633 !IS_QLA24XX(ha) && !IS_QLA25XX(ha) &&
2634 ha->flags.init_done) {
2635 /* Handle port RSCN via asyncronous IOCBs */
2636 rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
2638 if (rval2 == QLA_SUCCESS)
2652 ha->rscn_out_ptr = ha->rscn_in_ptr;
2658 /* Abort any outstanding IO descriptors. */
2659 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2660 qla2x00_cancel_io_descriptors(ha);
2662 list_for_each_entry(fcport, &ha->fcports, list) {
2663 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2664 (fcport->d_id.b24 & mask) != d_id.b24 ||
2665 fcport->port_type == FCT_BROADCAST)
2668 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2670 fcport->port_type != FCT_INITIATOR) {
2671 qla2x00_mark_device_lost(ha, fcport, 0);
2674 fcport->flags &= ~FCF_FARP_DONE;
2681 * qla2x00_fabric_dev_login
2682 * Login fabric target device and update FC port database.
2685 * ha: adapter state pointer.
2686 * fcport: port structure list pointer.
2687 * next_loopid: contains value of a new loop ID that can be used
2688 * by the next login attempt.
2691 * qla2x00 local function return status code.
2697 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2698 uint16_t *next_loopid)
2707 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2708 if (rval == QLA_SUCCESS) {
2709 /* Send an ADISC to tape devices.*/
2711 if (fcport->flags & FCF_TAPE_PRESENT)
2713 rval = qla2x00_get_port_database(ha, fcport, opts);
2714 if (rval != QLA_SUCCESS) {
2715 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2716 fcport->d_id.b.domain, fcport->d_id.b.area,
2717 fcport->d_id.b.al_pa);
2718 qla2x00_mark_device_lost(ha, fcport, 1);
2721 qla2x00_update_fcport(ha, fcport);
2729 * qla2x00_fabric_login
2730 * Issue fabric login command.
2733 * ha = adapter block pointer.
2734 * device = pointer to FC device type structure.
2737 * 0 - Login successfully
2739 * 2 - Initiator device
2743 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2744 uint16_t *next_loopid)
2748 uint16_t tmp_loopid;
2749 uint16_t mb[MAILBOX_REGISTER_COUNT];
2755 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2756 "for port %02x%02x%02x.\n",
2757 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2758 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2760 /* Login fcport on switch. */
2761 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2762 fcport->d_id.b.domain, fcport->d_id.b.area,
2763 fcport->d_id.b.al_pa, mb, BIT_0);
2764 if (mb[0] == MBS_PORT_ID_USED) {
2766 * Device has another loop ID. The firmware team
2767 * recommends the driver perform an implicit login with
2768 * the specified ID again. The ID we just used is save
2769 * here so we return with an ID that can be tried by
2773 tmp_loopid = fcport->loop_id;
2774 fcport->loop_id = mb[1];
2776 DEBUG(printk("Fabric Login: port in use - next "
2777 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2778 fcport->loop_id, fcport->d_id.b.domain,
2779 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2781 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2786 /* A retry occurred before. */
2787 *next_loopid = tmp_loopid;
2790 * No retry occurred before. Just increment the
2791 * ID value for next login.
2793 *next_loopid = (fcport->loop_id + 1);
2796 if (mb[1] & BIT_0) {
2797 fcport->port_type = FCT_INITIATOR;
2799 fcport->port_type = FCT_TARGET;
2800 if (mb[1] & BIT_1) {
2801 fcport->flags |= FCF_TAPE_PRESENT;
2806 fcport->supported_classes |= FC_COS_CLASS2;
2808 fcport->supported_classes |= FC_COS_CLASS3;
2812 } else if (mb[0] == MBS_LOOP_ID_USED) {
2814 * Loop ID already used, try next loop ID.
2817 rval = qla2x00_find_new_loop_id(ha, fcport);
2818 if (rval != QLA_SUCCESS) {
2819 /* Ran out of loop IDs to use */
2822 } else if (mb[0] == MBS_COMMAND_ERROR) {
2824 * Firmware possibly timed out during login. If NO
2825 * retries are left to do then the device is declared
2828 *next_loopid = fcport->loop_id;
2829 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2830 fcport->d_id.b.domain, fcport->d_id.b.area,
2831 fcport->d_id.b.al_pa);
2832 qla2x00_mark_device_lost(ha, fcport, 1);
2838 * unrecoverable / not handled error
2840 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2841 "loop_id=%x jiffies=%lx.\n",
2842 __func__, ha->host_no, mb[0],
2843 fcport->d_id.b.domain, fcport->d_id.b.area,
2844 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2846 *next_loopid = fcport->loop_id;
2847 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2848 fcport->d_id.b.domain, fcport->d_id.b.area,
2849 fcport->d_id.b.al_pa);
2850 fcport->loop_id = FC_NO_LOOP_ID;
2851 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
2862 * qla2x00_local_device_login
2863 * Issue local device login command.
2866 * ha = adapter block pointer.
2867 * loop_id = loop id of device to login to.
2869 * Returns (Where's the #define!!!!):
2870 * 0 - Login successfully
2875 qla2x00_local_device_login(scsi_qla_host_t *ha, uint16_t loop_id)
2878 uint16_t mb[MAILBOX_REGISTER_COUNT];
2880 memset(mb, 0, sizeof(mb));
2881 rval = qla2x00_login_local_device(ha, loop_id, mb, BIT_0);
2882 if (rval == QLA_SUCCESS) {
2883 /* Interrogate mailbox registers for any errors */
2884 if (mb[0] == MBS_COMMAND_ERROR)
2886 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
2887 /* device not in PCB table */
2895 * qla2x00_loop_resync
2896 * Resync with fibre channel devices.
2899 * ha = adapter block pointer.
2905 qla2x00_loop_resync(scsi_qla_host_t *ha)
2912 atomic_set(&ha->loop_state, LOOP_UPDATE);
2913 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2914 if (ha->flags.online) {
2915 if (!(rval = qla2x00_fw_ready(ha))) {
2916 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2919 atomic_set(&ha->loop_state, LOOP_UPDATE);
2921 /* Issue a marker after FW becomes ready. */
2922 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
2923 ha->marker_needed = 0;
2925 /* Remap devices on Loop. */
2926 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2928 qla2x00_configure_loop(ha);
2930 } while (!atomic_read(&ha->loop_down_timer) &&
2931 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
2933 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
2937 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2938 return (QLA_FUNCTION_FAILED);
2942 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
2949 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
2955 list_for_each_entry(fcport, &ha->fcports, list) {
2956 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
2959 qla2x00_update_fcport(ha, fcport);
2960 fcport->flags &= ~FCF_RESCAN_NEEDED;
2964 qla2x00_probe_for_all_luns(ha);
2969 * Resets ISP and aborts all outstanding commands.
2972 * ha = adapter block pointer.
2978 qla2x00_abort_isp(scsi_qla_host_t *ha)
2980 unsigned long flags = 0;
2985 if (ha->flags.online) {
2986 ha->flags.online = 0;
2987 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2989 qla_printk(KERN_INFO, ha,
2990 "Performing ISP error recovery - ha= %p.\n", ha);
2991 ha->isp_ops.reset_chip(ha);
2993 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
2994 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
2995 atomic_set(&ha->loop_state, LOOP_DOWN);
2996 qla2x00_mark_all_devices_lost(ha);
2998 if (!atomic_read(&ha->loop_down_timer))
2999 atomic_set(&ha->loop_down_timer,
3003 spin_lock_irqsave(&ha->hardware_lock, flags);
3004 /* Requeue all commands in outstanding command list. */
3005 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3006 sp = ha->outstanding_cmds[cnt];
3008 ha->outstanding_cmds[cnt] = NULL;
3010 sp->cmd->result = DID_RESET << 16;
3011 sp->cmd->host_scribble = (unsigned char *)NULL;
3012 qla2x00_sp_compl(ha, sp);
3015 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3017 ha->isp_ops.nvram_config(ha);
3019 if (!qla2x00_restart_isp(ha)) {
3020 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3022 if (!atomic_read(&ha->loop_down_timer)) {
3024 * Issue marker command only when we are going
3025 * to start the I/O .
3027 ha->marker_needed = 1;
3030 ha->flags.online = 1;
3032 ha->isp_ops.enable_intrs(ha);
3034 ha->isp_abort_cnt = 0;
3035 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3036 } else { /* failed the ISP abort */
3037 ha->flags.online = 1;
3038 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3039 if (ha->isp_abort_cnt == 0) {
3040 qla_printk(KERN_WARNING, ha,
3041 "ISP error recovery failed - "
3042 "board disabled\n");
3044 * The next call disables the board
3047 ha->isp_ops.reset_adapter(ha);
3048 ha->flags.online = 0;
3049 clear_bit(ISP_ABORT_RETRY,
3052 } else { /* schedule another ISP abort */
3053 ha->isp_abort_cnt--;
3054 DEBUG(printk("qla%ld: ISP abort - "
3055 "retry remaining %d\n",
3056 ha->host_no, ha->isp_abort_cnt);)
3060 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3061 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3062 "- retrying (%d) more times\n",
3063 ha->host_no, ha->isp_abort_cnt);)
3064 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3072 qla_printk(KERN_INFO, ha,
3073 "qla2x00_abort_isp: **** FAILED ****\n");
3075 DEBUG(printk(KERN_INFO
3076 "qla2x00_abort_isp(%ld): exiting.\n",
3084 * qla2x00_restart_isp
3085 * restarts the ISP after a reset
3088 * ha = adapter block pointer.
3094 qla2x00_restart_isp(scsi_qla_host_t *ha)
3097 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3098 unsigned long flags = 0;
3101 /* If firmware needs to be loaded */
3102 if (qla2x00_isp_firmware(ha)) {
3103 ha->flags.online = 0;
3104 if (!(status = ha->isp_ops.chip_diag(ha))) {
3105 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3106 status = qla2x00_setup_chip(ha);
3110 spin_lock_irqsave(&ha->hardware_lock, flags);
3112 if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha)) {
3114 * Disable SRAM, Instruction RAM and GP RAM
3117 WRT_REG_WORD(®->hccr,
3118 (HCCR_ENABLE_PARITY + 0x0));
3119 RD_REG_WORD(®->hccr);
3122 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3124 status = qla2x00_setup_chip(ha);
3126 spin_lock_irqsave(&ha->hardware_lock, flags);
3128 if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha)) {
3129 /* Enable proper parity */
3132 WRT_REG_WORD(®->hccr,
3133 (HCCR_ENABLE_PARITY + 0x1));
3136 * SRAM, Instruction RAM and GP RAM
3139 WRT_REG_WORD(®->hccr,
3140 (HCCR_ENABLE_PARITY + 0x7));
3141 RD_REG_WORD(®->hccr);
3144 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3149 if (!status && !(status = qla2x00_init_rings(ha))) {
3150 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3151 if (!(status = qla2x00_fw_ready(ha))) {
3152 DEBUG(printk("%s(): Start configure loop, "
3153 "status = %d\n", __func__, status);)
3155 /* Issue a marker after FW becomes ready. */
3156 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3158 ha->flags.online = 1;
3159 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3162 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3163 qla2x00_configure_loop(ha);
3165 } while (!atomic_read(&ha->loop_down_timer) &&
3166 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3168 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3171 /* if no cable then assume it's good */
3172 if ((ha->device_flags & DFLG_NO_CABLE))
3175 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3183 * qla2x00_reset_adapter
3187 * ha = adapter block pointer.
3190 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3192 unsigned long flags = 0;
3193 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3195 ha->flags.online = 0;
3196 ha->isp_ops.disable_intrs(ha);
3198 spin_lock_irqsave(&ha->hardware_lock, flags);
3199 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3200 RD_REG_WORD(®->hccr); /* PCI Posting. */
3201 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3202 RD_REG_WORD(®->hccr); /* PCI Posting. */
3203 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3207 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3209 unsigned long flags = 0;
3210 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3212 ha->flags.online = 0;
3213 ha->isp_ops.disable_intrs(ha);
3215 spin_lock_irqsave(&ha->hardware_lock, flags);
3216 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3217 RD_REG_DWORD(®->hccr);
3218 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3219 RD_REG_DWORD(®->hccr);
3220 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3224 qla24xx_nvram_config(scsi_qla_host_t *ha)
3227 struct init_cb_24xx *icb;
3228 struct nvram_24xx *nv;
3230 uint8_t *dptr1, *dptr2;
3235 icb = (struct init_cb_24xx *)ha->init_cb;
3236 nv = (struct nvram_24xx *)ha->request_ring;
3238 /* Determine NVRAM starting address. */
3239 ha->nvram_size = sizeof(struct nvram_24xx);
3240 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3241 if (PCI_FUNC(ha->pdev->devfn))
3242 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3244 /* Get NVRAM data and calculate checksum. */
3245 dptr = (uint32_t *)nv;
3246 ha->isp_ops.read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3248 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3249 chksum += le32_to_cpu(*dptr++);
3251 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3252 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3255 /* Bad NVRAM data, set defaults parameters. */
3256 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3257 || nv->id[3] != ' ' ||
3258 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3259 /* Reset NVRAM data. */
3260 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3261 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3262 le16_to_cpu(nv->nvram_version));
3263 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3264 "invalid -- WWPN) defaults.\n");
3267 * Set default initialization control block.
3269 memset(nv, 0, ha->nvram_size);
3270 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3271 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3272 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3273 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3274 nv->exchange_count = __constant_cpu_to_le16(0);
3275 nv->hard_address = __constant_cpu_to_le16(124);
3276 nv->port_name[0] = 0x21;
3277 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3278 nv->port_name[2] = 0x00;
3279 nv->port_name[3] = 0xe0;
3280 nv->port_name[4] = 0x8b;
3281 nv->port_name[5] = 0x1c;
3282 nv->port_name[6] = 0x55;
3283 nv->port_name[7] = 0x86;
3284 nv->node_name[0] = 0x20;
3285 nv->node_name[1] = 0x00;
3286 nv->node_name[2] = 0x00;
3287 nv->node_name[3] = 0xe0;
3288 nv->node_name[4] = 0x8b;
3289 nv->node_name[5] = 0x1c;
3290 nv->node_name[6] = 0x55;
3291 nv->node_name[7] = 0x86;
3292 nv->login_retry_count = __constant_cpu_to_le16(8);
3293 nv->link_down_timeout = __constant_cpu_to_le16(200);
3294 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3295 nv->login_timeout = __constant_cpu_to_le16(0);
3296 nv->firmware_options_1 =
3297 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3298 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3299 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3300 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3301 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3302 nv->efi_parameters = __constant_cpu_to_le32(0);
3303 nv->reset_delay = 5;
3304 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3305 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3306 nv->link_down_timeout = __constant_cpu_to_le16(30);
3311 /* Reset Initialization control block */
3312 memset(icb, 0, sizeof(struct init_cb_24xx));
3314 /* Copy 1st segment. */
3315 dptr1 = (uint8_t *)icb;
3316 dptr2 = (uint8_t *)&nv->version;
3317 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3319 *dptr1++ = *dptr2++;
3321 icb->login_retry_count = nv->login_retry_count;
3322 icb->link_down_timeout = nv->link_down_timeout;
3324 /* Copy 2nd segment. */
3325 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3326 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3327 cnt = (uint8_t *)&icb->reserved_3 -
3328 (uint8_t *)&icb->interrupt_delay_timer;
3330 *dptr1++ = *dptr2++;
3333 * Setup driver NVRAM options.
3335 if (memcmp(nv->model_name, BINZERO, sizeof(nv->model_name)) != 0) {
3339 strncpy(ha->model_number, nv->model_name,
3340 sizeof(nv->model_name));
3341 st = en = ha->model_number;
3342 en += sizeof(nv->model_name) - 1;
3344 if (*en != 0x20 && *en != 0x00)
3349 index = (ha->pdev->subsystem_device & 0xff);
3350 if (index < QLA_MODEL_NAMES)
3351 ha->model_desc = qla2x00_model_desc[index];
3353 strcpy(ha->model_number, "QLA2462");
3355 /* Prepare nodename */
3356 if ((icb->firmware_options_1 & BIT_14) == 0) {
3358 * Firmware will apply the following mask if the nodename was
3361 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3362 icb->node_name[0] &= 0xF0;
3365 /* Set host adapter parameters. */
3366 ha->flags.disable_risc_code_load = 0;
3367 ha->flags.enable_lip_reset = 1;
3368 ha->flags.enable_lip_full_login = 1;
3369 ha->flags.enable_target_reset = 1;
3370 ha->flags.enable_led_scheme = 0;
3372 ha->operating_mode =
3373 (icb->firmware_options_2 & (BIT_6 | BIT_5 | BIT_4)) >> 4;
3375 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3376 sizeof(ha->fw_seriallink_options24));
3378 /* save HBA serial number */
3379 ha->serial0 = icb->port_name[5];
3380 ha->serial1 = icb->port_name[6];
3381 ha->serial2 = icb->port_name[7];
3382 ha->node_name = icb->node_name;
3383 ha->port_name = icb->port_name;
3385 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3387 /* Set minimum login_timeout to 4 seconds. */
3388 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3389 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3390 if (le16_to_cpu(nv->login_timeout) < 4)
3391 nv->login_timeout = __constant_cpu_to_le16(4);
3392 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3393 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3395 /* Set minimum RATOV to 200 tenths of a second. */
3398 ha->loop_reset_delay = nv->reset_delay;
3400 /* Link Down Timeout = 0:
3402 * When Port Down timer expires we will start returning
3403 * I/O's to OS with "DID_NO_CONNECT".
3405 * Link Down Timeout != 0:
3407 * The driver waits for the link to come up after link down
3408 * before returning I/Os to OS with "DID_NO_CONNECT".
3410 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3411 ha->loop_down_abort_time =
3412 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3414 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3415 ha->loop_down_abort_time =
3416 (LOOP_DOWN_TIME - ha->link_down_timeout);
3419 /* Need enough time to try and get the port back. */
3420 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3421 if (qlport_down_retry)
3422 ha->port_down_retry_count = qlport_down_retry;
3424 /* Set login_retry_count */
3425 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3426 if (ha->port_down_retry_count ==
3427 le16_to_cpu(nv->port_down_retry_count) &&
3428 ha->port_down_retry_count > 3)
3429 ha->login_retry_count = ha->port_down_retry_count;
3430 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3431 ha->login_retry_count = ha->port_down_retry_count;
3432 if (ql2xloginretrycount)
3433 ha->login_retry_count = ql2xloginretrycount;
3436 DEBUG2_3(printk(KERN_WARNING
3437 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3443 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3447 uint16_t *risc_code;
3448 unsigned long risc_address;
3449 unsigned long risc_code_size;
3453 struct qla_fw_info *fw_iter;
3457 /* Load firmware sequences */
3458 fw_iter = ha->brd_info->fw_info;
3459 *srisc_addr = *ha->brd_info->fw_info->fwstart;
3460 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
3461 risc_code = fw_iter->fwcode;
3462 risc_code_size = *fw_iter->fwlen;
3464 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
3465 risc_address = *fw_iter->fwstart;
3467 /* Extended address */
3468 risc_address = *fw_iter->lfwstart;
3473 while (risc_code_size > 0 && !rval) {
3474 cnt = (uint16_t)(ha->fw_transfer_size >> 1);
3475 if (cnt > risc_code_size)
3476 cnt = risc_code_size;
3478 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
3479 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
3480 ha->host_no, risc_code, cnt, risc_address));
3482 req_ring = (uint16_t *)ha->request_ring;
3483 for (i = 0; i < cnt; i++)
3484 req_ring[i] = cpu_to_le16(risc_code[i]);
3486 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
3487 rval = qla2x00_load_ram(ha, ha->request_dma,
3490 rval = qla2x00_load_ram_ext(ha,
3491 ha->request_dma, risc_address, cnt);
3494 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
3495 "load segment %d of firmware\n",
3497 qla_printk(KERN_WARNING, ha,
3498 "[ERROR] Failed to load segment %d of "
3501 qla2x00_dump_regs(ha);
3506 risc_address += cnt;
3507 risc_code_size -= cnt;
3511 /* Next firmware sequence */
3519 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3522 int segments, fragment;
3524 uint32_t *dcode, dlen;
3531 segments = FA_RISC_CODE_SEGMENTS;
3532 faddr = FA_RISC_CODE_ADDR;
3533 dcode = (uint32_t *)ha->request_ring;
3536 /* Validate firmware image by checking version. */
3537 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3538 for (i = 0; i < 4; i++)
3539 dcode[i] = be32_to_cpu(dcode[i]);
3540 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3541 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3542 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3544 qla_printk(KERN_WARNING, ha,
3545 "Unable to verify integrity of flash firmware image!\n");
3546 qla_printk(KERN_WARNING, ha,
3547 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3548 dcode[1], dcode[2], dcode[3]);
3550 return QLA_FUNCTION_FAILED;
3553 while (segments && rval == QLA_SUCCESS) {
3554 /* Read segment's load information. */
3555 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3557 risc_addr = be32_to_cpu(dcode[2]);
3558 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3559 risc_size = be32_to_cpu(dcode[3]);
3562 while (risc_size > 0 && rval == QLA_SUCCESS) {