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)
206 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
208 pci_set_master(ha->pdev);
210 if (pci_set_mwi(ha->pdev))
211 mwi = PCI_COMMAND_INVALIDATE;
212 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
214 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
215 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
216 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
218 /* Reset expansion ROM address decode enable */
219 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
220 d &= ~PCI_ROM_ADDRESS_ENABLE;
221 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
223 /* Get PCI bus information. */
224 spin_lock_irqsave(&ha->hardware_lock, flags);
225 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
226 spin_unlock_irqrestore(&ha->hardware_lock, flags);
232 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
235 * Returns 0 on success.
238 qla2300_pci_config(scsi_qla_host_t *ha)
242 unsigned long flags = 0;
244 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
246 pci_set_master(ha->pdev);
248 if (pci_set_mwi(ha->pdev))
249 mwi = PCI_COMMAND_INVALIDATE;
250 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
252 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
253 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
255 if (IS_QLA2322(ha) || IS_QLA6322(ha))
256 w &= ~PCI_COMMAND_INTX_DISABLE;
259 * If this is a 2300 card and not 2312, reset the
260 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
261 * the 2310 also reports itself as a 2300 so we need to get the
262 * fb revision level -- a 6 indicates it really is a 2300 and
265 if (IS_QLA2300(ha)) {
266 spin_lock_irqsave(&ha->hardware_lock, flags);
269 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
270 for (cnt = 0; cnt < 30000; cnt++) {
271 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
277 /* Select FPM registers. */
278 WRT_REG_WORD(®->ctrl_status, 0x20);
279 RD_REG_WORD(®->ctrl_status);
281 /* Get the fb rev level */
282 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
284 if (ha->fb_rev == FPM_2300)
285 w &= ~PCI_COMMAND_INVALIDATE;
287 /* Deselect FPM registers. */
288 WRT_REG_WORD(®->ctrl_status, 0x0);
289 RD_REG_WORD(®->ctrl_status);
291 /* Release RISC module. */
292 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
293 for (cnt = 0; cnt < 30000; cnt++) {
294 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
300 spin_unlock_irqrestore(&ha->hardware_lock, flags);
302 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
304 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
306 /* Reset expansion ROM address decode enable */
307 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
308 d &= ~PCI_ROM_ADDRESS_ENABLE;
309 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
311 /* Get PCI bus information. */
312 spin_lock_irqsave(&ha->hardware_lock, flags);
313 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
314 spin_unlock_irqrestore(&ha->hardware_lock, flags);
320 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
323 * Returns 0 on success.
326 qla24xx_pci_config(scsi_qla_host_t *ha)
330 unsigned long flags = 0;
331 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
332 int pcix_cmd_reg, pcie_dctl_reg;
334 pci_set_master(ha->pdev);
336 if (pci_set_mwi(ha->pdev))
337 mwi = PCI_COMMAND_INVALIDATE;
338 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
340 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
341 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
342 w &= ~PCI_COMMAND_INTX_DISABLE;
343 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
345 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
347 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
348 pcix_cmd_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX);
352 pcix_cmd_reg += PCI_X_CMD;
353 pci_read_config_word(ha->pdev, pcix_cmd_reg, &pcix_cmd);
354 pcix_cmd &= ~PCI_X_CMD_MAX_READ;
356 pci_write_config_word(ha->pdev, pcix_cmd_reg, pcix_cmd);
359 /* PCIe -- adjust Maximum Read Request Size (2048). */
360 pcie_dctl_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
364 pcie_dctl_reg += PCI_EXP_DEVCTL;
365 pci_read_config_word(ha->pdev, pcie_dctl_reg, &pcie_dctl);
366 pcie_dctl &= ~PCI_EXP_DEVCTL_READRQ;
368 pci_write_config_word(ha->pdev, pcie_dctl_reg, pcie_dctl);
371 /* Reset expansion ROM address decode enable */
372 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
373 d &= ~PCI_ROM_ADDRESS_ENABLE;
374 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
376 /* Get PCI bus information. */
377 spin_lock_irqsave(&ha->hardware_lock, flags);
378 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
379 spin_unlock_irqrestore(&ha->hardware_lock, flags);
385 * qla2x00_isp_firmware() - Choose firmware image.
388 * Returns 0 on success.
391 qla2x00_isp_firmware(scsi_qla_host_t *ha)
395 /* Assume loading risc code */
396 rval = QLA_FUNCTION_FAILED;
398 if (ha->flags.disable_risc_code_load) {
399 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
401 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
403 /* Verify checksum of loaded RISC code. */
404 rval = qla2x00_verify_checksum(ha,
405 IS_QLA24XX(ha) || IS_QLA25XX(ha) ? RISC_SADDRESS :
406 *ha->brd_info->fw_info[0].fwstart);
410 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
418 * qla2x00_reset_chip() - Reset ISP chip.
421 * Returns 0 on success.
424 qla2x00_reset_chip(scsi_qla_host_t *ha)
426 unsigned long flags = 0;
427 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
429 unsigned long mbx_flags = 0;
432 ha->isp_ops.disable_intrs(ha);
434 spin_lock_irqsave(&ha->hardware_lock, flags);
436 /* Turn off master enable */
438 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
439 cmd &= ~PCI_COMMAND_MASTER;
440 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
442 if (!IS_QLA2100(ha)) {
444 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
445 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
446 for (cnt = 0; cnt < 30000; cnt++) {
447 if ((RD_REG_WORD(®->hccr) &
448 HCCR_RISC_PAUSE) != 0)
453 RD_REG_WORD(®->hccr); /* PCI Posting. */
457 /* Select FPM registers. */
458 WRT_REG_WORD(®->ctrl_status, 0x20);
459 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
461 /* FPM Soft Reset. */
462 WRT_REG_WORD(®->fpm_diag_config, 0x100);
463 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
465 /* Toggle Fpm Reset. */
466 if (!IS_QLA2200(ha)) {
467 WRT_REG_WORD(®->fpm_diag_config, 0x0);
468 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
471 /* Select frame buffer registers. */
472 WRT_REG_WORD(®->ctrl_status, 0x10);
473 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
475 /* Reset frame buffer FIFOs. */
476 if (IS_QLA2200(ha)) {
477 WRT_FB_CMD_REG(ha, reg, 0xa000);
478 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
480 WRT_FB_CMD_REG(ha, reg, 0x00fc);
482 /* Read back fb_cmd until zero or 3 seconds max */
483 for (cnt = 0; cnt < 3000; cnt++) {
484 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
490 /* Select RISC module registers. */
491 WRT_REG_WORD(®->ctrl_status, 0);
492 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
494 /* Reset RISC processor. */
495 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
496 RD_REG_WORD(®->hccr); /* PCI Posting. */
498 /* Release RISC processor. */
499 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
500 RD_REG_WORD(®->hccr); /* PCI Posting. */
503 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
504 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
506 /* Reset ISP chip. */
507 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
509 /* Wait for RISC to recover from reset. */
510 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
512 * It is necessary to for a delay here since the card doesn't
513 * respond to PCI reads during a reset. On some architectures
514 * this will result in an MCA.
517 for (cnt = 30000; cnt; cnt--) {
518 if ((RD_REG_WORD(®->ctrl_status) &
519 CSR_ISP_SOFT_RESET) == 0)
526 /* Reset RISC processor. */
527 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
529 WRT_REG_WORD(®->semaphore, 0);
531 /* Release RISC processor. */
532 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
533 RD_REG_WORD(®->hccr); /* PCI Posting. */
535 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
536 for (cnt = 0; cnt < 30000; cnt++) {
537 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
538 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
540 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) {
541 if (!(test_bit(ABORT_ISP_ACTIVE,
543 spin_unlock_irqrestore(
544 &ha->mbx_reg_lock, mbx_flags);
548 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
549 spin_unlock_irqrestore(&ha->mbx_reg_lock,
557 /* Turn on master enable */
558 cmd |= PCI_COMMAND_MASTER;
559 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
561 /* Disable RISC pause on FPM parity error. */
562 if (!IS_QLA2100(ha)) {
563 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
564 RD_REG_WORD(®->hccr); /* PCI Posting. */
567 spin_unlock_irqrestore(&ha->hardware_lock, flags);
571 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
574 * Returns 0 on success.
577 qla24xx_reset_risc(scsi_qla_host_t *ha)
579 unsigned long flags = 0;
580 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
583 spin_lock_irqsave(&ha->hardware_lock, flags);
586 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
587 for (cnt = 0; cnt < 30000; cnt++) {
588 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
594 WRT_REG_DWORD(®->ctrl_status,
595 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
596 RD_REG_DWORD(®->ctrl_status);
598 /* Wait for firmware to complete NVRAM accesses. */
600 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
601 for (cnt = 10000 ; cnt && d2; cnt--) {
603 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
608 d2 = RD_REG_DWORD(®->ctrl_status);
609 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
611 d2 = RD_REG_DWORD(®->ctrl_status);
615 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
616 RD_REG_DWORD(®->hccr);
618 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
619 RD_REG_DWORD(®->hccr);
621 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
622 RD_REG_DWORD(®->hccr);
624 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
625 for (cnt = 6000000 ; cnt && d2; cnt--) {
627 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
631 spin_unlock_irqrestore(&ha->hardware_lock, flags);
635 * qla24xx_reset_chip() - Reset ISP24xx chip.
638 * Returns 0 on success.
641 qla24xx_reset_chip(scsi_qla_host_t *ha)
643 ha->isp_ops.disable_intrs(ha);
645 /* Perform RISC reset. */
646 qla24xx_reset_risc(ha);
650 * qla2x00_chip_diag() - Test chip for proper operation.
653 * Returns 0 on success.
656 qla2x00_chip_diag(scsi_qla_host_t *ha)
659 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
660 unsigned long flags = 0;
665 /* Assume a failed state */
666 rval = QLA_FUNCTION_FAILED;
668 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
669 ha->host_no, (u_long)®->flash_address));
671 spin_lock_irqsave(&ha->hardware_lock, flags);
673 /* Reset ISP chip. */
674 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
677 * We need to have a delay here since the card will not respond while
678 * in reset causing an MCA on some architectures.
681 data = qla2x00_debounce_register(®->ctrl_status);
682 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
684 data = RD_REG_WORD(®->ctrl_status);
689 goto chip_diag_failed;
691 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
694 /* Reset RISC processor. */
695 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
696 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
698 /* Workaround for QLA2312 PCI parity error */
699 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
700 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
701 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
703 data = RD_MAILBOX_REG(ha, reg, 0);
710 goto chip_diag_failed;
712 /* Check product ID of chip */
713 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
715 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
716 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
717 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
718 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
719 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
720 mb[3] != PROD_ID_3) {
721 qla_printk(KERN_WARNING, ha,
722 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
724 goto chip_diag_failed;
726 ha->product_id[0] = mb[1];
727 ha->product_id[1] = mb[2];
728 ha->product_id[2] = mb[3];
729 ha->product_id[3] = mb[4];
731 /* Adjust fw RISC transfer size */
732 if (ha->request_q_length > 1024)
733 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
735 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
736 ha->request_q_length;
738 if (IS_QLA2200(ha) &&
739 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
740 /* Limit firmware transfer size with a 2200A */
741 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
744 ha->fw_transfer_size = 128;
747 /* Wrap Incoming Mailboxes Test. */
748 spin_unlock_irqrestore(&ha->hardware_lock, flags);
750 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
751 rval = qla2x00_mbx_reg_test(ha);
753 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
755 qla_printk(KERN_WARNING, ha,
756 "Failed mailbox send register test\n");
759 /* Flag a successful rval */
762 spin_lock_irqsave(&ha->hardware_lock, flags);
766 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
767 "****\n", ha->host_no));
769 spin_unlock_irqrestore(&ha->hardware_lock, flags);
775 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
778 * Returns 0 on success.
781 qla24xx_chip_diag(scsi_qla_host_t *ha)
785 /* Perform RISC reset. */
786 qla24xx_reset_risc(ha);
788 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
790 rval = qla2x00_mbx_reg_test(ha);
792 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
794 qla_printk(KERN_WARNING, ha,
795 "Failed mailbox send register test\n");
797 /* Flag a successful rval */
805 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
808 ha->fw_dump24_len = sizeof(struct qla24xx_fw_dump);
809 ha->fw_dump24_len += (ha->fw_memory_size - 0x100000) * sizeof(uint32_t);
810 ha->fw_dump24 = vmalloc(ha->fw_dump24_len);
812 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware "
813 "dump...\n", ha->fw_dump24_len / 1024);
815 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
816 "firmware dump!!!\n", ha->fw_dump24_len / 1024);
820 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
823 * Returns 0 on success.
826 qla2x00_resize_request_q(scsi_qla_host_t *ha)
829 uint16_t fw_iocb_cnt = 0;
830 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
831 dma_addr_t request_dma;
832 request_t *request_ring;
834 /* Valid only on recent ISPs. */
835 if (IS_QLA2100(ha) || IS_QLA2200(ha))
838 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
839 qla2x00_alloc_fw_dump(ha);
841 /* Retrieve IOCB counts available to the firmware. */
842 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
845 /* No point in continuing if current settings are sufficient. */
846 if (fw_iocb_cnt < 1024)
848 if (ha->request_q_length >= request_q_length)
851 /* Attempt to claim larger area for request queue. */
852 request_ring = dma_alloc_coherent(&ha->pdev->dev,
853 (request_q_length + 1) * sizeof(request_t), &request_dma,
855 if (request_ring == NULL)
858 /* Resize successful, report extensions. */
859 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
860 (ha->fw_memory_size + 1) / 1024);
861 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
862 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
864 /* Clear old allocations. */
865 dma_free_coherent(&ha->pdev->dev,
866 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
869 /* Begin using larger queue. */
870 ha->request_q_length = request_q_length;
871 ha->request_ring = request_ring;
872 ha->request_dma = request_dma;
876 * qla2x00_setup_chip() - Load and start RISC firmware.
879 * Returns 0 on success.
882 qla2x00_setup_chip(scsi_qla_host_t *ha)
885 uint32_t srisc_address = 0;
887 /* Load firmware sequences */
888 rval = ha->isp_ops.load_risc(ha, &srisc_address);
889 if (rval == QLA_SUCCESS) {
890 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
891 "code.\n", ha->host_no));
893 rval = qla2x00_verify_checksum(ha, srisc_address);
894 if (rval == QLA_SUCCESS) {
895 /* Start firmware execution. */
896 DEBUG(printk("scsi(%ld): Checksum OK, start "
897 "firmware.\n", ha->host_no));
899 rval = qla2x00_execute_fw(ha, srisc_address);
900 /* Retrieve firmware information. */
901 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
902 qla2x00_get_fw_version(ha,
903 &ha->fw_major_version,
904 &ha->fw_minor_version,
905 &ha->fw_subminor_version,
906 &ha->fw_attributes, &ha->fw_memory_size);
907 qla2x00_resize_request_q(ha);
910 DEBUG2(printk(KERN_INFO
911 "scsi(%ld): ISP Firmware failed checksum.\n",
917 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
925 * qla2x00_init_response_q_entries() - Initializes response queue entries.
928 * Beginning of request ring has initialization control block already built
929 * by nvram config routine.
931 * Returns 0 on success.
934 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
939 pkt = ha->response_ring_ptr;
940 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
941 pkt->signature = RESPONSE_PROCESSED;
948 * qla2x00_update_fw_options() - Read and process firmware options.
951 * Returns 0 on success.
954 qla2x00_update_fw_options(scsi_qla_host_t *ha)
956 uint16_t swing, emphasis, tx_sens, rx_sens;
958 memset(ha->fw_options, 0, sizeof(ha->fw_options));
959 qla2x00_get_fw_options(ha, ha->fw_options);
961 if (IS_QLA2100(ha) || IS_QLA2200(ha))
964 /* Serial Link options. */
965 DEBUG3(printk("scsi(%ld): Serial link options:\n",
967 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
968 sizeof(ha->fw_seriallink_options)));
970 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
971 if (ha->fw_seriallink_options[3] & BIT_2) {
972 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
975 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
976 emphasis = (ha->fw_seriallink_options[2] &
977 (BIT_4 | BIT_3)) >> 3;
978 tx_sens = ha->fw_seriallink_options[0] &
979 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
980 rx_sens = (ha->fw_seriallink_options[0] &
981 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
982 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
983 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
986 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
987 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
988 ha->fw_options[10] |= BIT_5 |
989 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
990 (tx_sens & (BIT_1 | BIT_0));
993 swing = (ha->fw_seriallink_options[2] &
994 (BIT_7 | BIT_6 | BIT_5)) >> 5;
995 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
996 tx_sens = ha->fw_seriallink_options[1] &
997 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
998 rx_sens = (ha->fw_seriallink_options[1] &
999 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1000 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1001 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1004 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1005 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1006 ha->fw_options[11] |= BIT_5 |
1007 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1008 (tx_sens & (BIT_1 | BIT_0));
1012 /* Return command IOCBs without waiting for an ABTS to complete. */
1013 ha->fw_options[3] |= BIT_13;
1016 if (ha->flags.enable_led_scheme)
1017 ha->fw_options[2] |= BIT_12;
1019 /* Update firmware options. */
1020 qla2x00_set_fw_options(ha, ha->fw_options);
1024 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1028 /* Update Serial Link options. */
1029 if ((ha->fw_seriallink_options24[0] & BIT_0) == 0)
1032 rval = qla2x00_set_serdes_params(ha, ha->fw_seriallink_options24[1],
1033 ha->fw_seriallink_options24[2], ha->fw_seriallink_options24[3]);
1034 if (rval != QLA_SUCCESS) {
1035 qla_printk(KERN_WARNING, ha,
1036 "Unable to update Serial Link options (%x).\n", rval);
1041 qla2x00_config_rings(struct scsi_qla_host *ha)
1043 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1045 /* Setup ring parameters in initialization control block. */
1046 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1047 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1048 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1049 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1050 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1051 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1052 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1053 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1055 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1056 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1057 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1058 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1059 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1063 qla24xx_config_rings(struct scsi_qla_host *ha)
1065 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1066 struct init_cb_24xx *icb;
1068 /* Setup ring parameters in initialization control block. */
1069 icb = (struct init_cb_24xx *)ha->init_cb;
1070 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1071 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1072 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1073 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1074 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1075 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1076 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1077 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1079 WRT_REG_DWORD(®->req_q_in, 0);
1080 WRT_REG_DWORD(®->req_q_out, 0);
1081 WRT_REG_DWORD(®->rsp_q_in, 0);
1082 WRT_REG_DWORD(®->rsp_q_out, 0);
1083 RD_REG_DWORD(®->rsp_q_out);
1087 * qla2x00_init_rings() - Initializes firmware.
1090 * Beginning of request ring has initialization control block already built
1091 * by nvram config routine.
1093 * Returns 0 on success.
1096 qla2x00_init_rings(scsi_qla_host_t *ha)
1099 unsigned long flags = 0;
1102 spin_lock_irqsave(&ha->hardware_lock, flags);
1104 /* Clear outstanding commands array. */
1105 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1106 ha->outstanding_cmds[cnt] = NULL;
1108 ha->current_outstanding_cmd = 0;
1110 /* Clear RSCN queue. */
1111 ha->rscn_in_ptr = 0;
1112 ha->rscn_out_ptr = 0;
1114 /* Initialize firmware. */
1115 ha->request_ring_ptr = ha->request_ring;
1116 ha->req_ring_index = 0;
1117 ha->req_q_cnt = ha->request_q_length;
1118 ha->response_ring_ptr = ha->response_ring;
1119 ha->rsp_ring_index = 0;
1121 /* Initialize response queue entries */
1122 qla2x00_init_response_q_entries(ha);
1124 ha->isp_ops.config_rings(ha);
1126 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1128 /* Update any ISP specific firmware options before initialization. */
1129 ha->isp_ops.update_fw_options(ha);
1131 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1132 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1134 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1137 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1145 * qla2x00_fw_ready() - Waits for firmware ready.
1148 * Returns 0 on success.
1151 qla2x00_fw_ready(scsi_qla_host_t *ha)
1154 unsigned long wtime, mtime;
1155 uint16_t min_wait; /* Minimum wait time if loop is down */
1156 uint16_t wait_time; /* Wait time if loop is coming ready */
1161 /* 20 seconds for loop down. */
1165 * Firmware should take at most one RATOV to login, plus 5 seconds for
1166 * our own processing.
1168 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1169 wait_time = min_wait;
1172 /* Min wait time if loop down */
1173 mtime = jiffies + (min_wait * HZ);
1175 /* wait time before firmware ready */
1176 wtime = jiffies + (wait_time * HZ);
1178 /* Wait for ISP to finish LIP */
1179 if (!ha->flags.init_done)
1180 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1182 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1186 rval = qla2x00_get_firmware_state(ha, &fw_state);
1187 if (rval == QLA_SUCCESS) {
1188 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1189 ha->device_flags &= ~DFLG_NO_CABLE;
1191 if (fw_state == FSTATE_READY) {
1192 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1195 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1196 &ha->login_timeout, &ha->r_a_tov);
1202 rval = QLA_FUNCTION_FAILED;
1204 if (atomic_read(&ha->loop_down_timer) &&
1205 (fw_state >= FSTATE_LOSS_OF_SYNC ||
1206 fw_state == FSTATE_WAIT_AL_PA)) {
1207 /* Loop down. Timeout on min_wait for states
1208 * other than Wait for Login.
1210 if (time_after_eq(jiffies, mtime)) {
1211 qla_printk(KERN_INFO, ha,
1212 "Cable is unplugged...\n");
1214 ha->device_flags |= DFLG_NO_CABLE;
1219 /* Mailbox cmd failed. Timeout on min_wait. */
1220 if (time_after_eq(jiffies, mtime))
1224 if (time_after_eq(jiffies, wtime))
1227 /* Delay for a while */
1230 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1231 ha->host_no, fw_state, jiffies));
1234 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1235 ha->host_no, fw_state, jiffies));
1238 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1246 * qla2x00_configure_hba
1247 * Setup adapter context.
1250 * ha = adapter state pointer.
1259 qla2x00_configure_hba(scsi_qla_host_t *ha)
1267 char connect_type[22];
1269 /* Get host addresses. */
1270 rval = qla2x00_get_adapter_id(ha,
1271 &loop_id, &al_pa, &area, &domain, &topo);
1272 if (rval != QLA_SUCCESS) {
1273 qla_printk(KERN_WARNING, ha,
1274 "ERROR -- Unable to get host loop ID.\n");
1275 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1280 qla_printk(KERN_INFO, ha,
1281 "Cannot get topology - retrying.\n");
1282 return (QLA_FUNCTION_FAILED);
1285 ha->loop_id = loop_id;
1288 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1289 ha->operating_mode = LOOP;
1293 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1295 ha->current_topology = ISP_CFG_NL;
1296 strcpy(connect_type, "(Loop)");
1300 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1302 ha->current_topology = ISP_CFG_FL;
1303 strcpy(connect_type, "(FL_Port)");
1307 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1309 ha->operating_mode = P2P;
1310 ha->current_topology = ISP_CFG_N;
1311 strcpy(connect_type, "(N_Port-to-N_Port)");
1315 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1317 ha->operating_mode = P2P;
1318 ha->current_topology = ISP_CFG_F;
1319 strcpy(connect_type, "(F_Port)");
1323 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1325 ha->host_no, topo));
1326 ha->current_topology = ISP_CFG_NL;
1327 strcpy(connect_type, "(Loop)");
1331 /* Save Host port and loop ID. */
1332 /* byte order - Big Endian */
1333 ha->d_id.b.domain = domain;
1334 ha->d_id.b.area = area;
1335 ha->d_id.b.al_pa = al_pa;
1337 if (!ha->flags.init_done)
1338 qla_printk(KERN_INFO, ha,
1339 "Topology - %s, Host Loop address 0x%x\n",
1340 connect_type, ha->loop_id);
1343 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1345 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1352 * NVRAM configuration for ISP 2xxx
1355 * ha = adapter block pointer.
1358 * initialization control block in response_ring
1359 * host adapters parameters in host adapter block
1365 qla2x00_nvram_config(scsi_qla_host_t *ha)
1370 uint8_t *dptr1, *dptr2;
1371 init_cb_t *icb = ha->init_cb;
1372 nvram_t *nv = (nvram_t *)ha->request_ring;
1373 uint8_t *ptr = (uint8_t *)ha->request_ring;
1374 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1378 /* Determine NVRAM starting address. */
1379 ha->nvram_size = sizeof(nvram_t);
1381 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1382 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1383 ha->nvram_base = 0x80;
1385 /* Get NVRAM data and calculate checksum. */
1386 ha->isp_ops.read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1387 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1390 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1391 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1394 /* Bad NVRAM data, set defaults parameters. */
1395 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1396 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1397 /* Reset NVRAM data. */
1398 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1399 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1401 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1402 "invalid -- WWPN) defaults.\n");
1405 * Set default initialization control block.
1407 memset(nv, 0, ha->nvram_size);
1408 nv->parameter_block_version = ICB_VERSION;
1410 if (IS_QLA23XX(ha)) {
1411 nv->firmware_options[0] = BIT_2 | BIT_1;
1412 nv->firmware_options[1] = BIT_7 | BIT_5;
1413 nv->add_firmware_options[0] = BIT_5;
1414 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1415 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1416 nv->special_options[1] = BIT_7;
1417 } else if (IS_QLA2200(ha)) {
1418 nv->firmware_options[0] = BIT_2 | BIT_1;
1419 nv->firmware_options[1] = BIT_7 | BIT_5;
1420 nv->add_firmware_options[0] = BIT_5;
1421 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1422 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1423 } else if (IS_QLA2100(ha)) {
1424 nv->firmware_options[0] = BIT_3 | BIT_1;
1425 nv->firmware_options[1] = BIT_5;
1426 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1429 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1430 nv->execution_throttle = __constant_cpu_to_le16(16);
1431 nv->retry_count = 8;
1432 nv->retry_delay = 1;
1434 nv->port_name[0] = 33;
1435 nv->port_name[3] = 224;
1436 nv->port_name[4] = 139;
1438 nv->login_timeout = 4;
1441 * Set default host adapter parameters
1443 nv->host_p[1] = BIT_2;
1444 nv->reset_delay = 5;
1445 nv->port_down_retry_count = 8;
1446 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1447 nv->link_down_timeout = 60;
1452 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1454 * The SN2 does not provide BIOS emulation which means you can't change
1455 * potentially bogus BIOS settings. Force the use of default settings
1456 * for link rate and frame size. Hope that the rest of the settings
1459 if (ia64_platform_is("sn2")) {
1460 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1462 nv->special_options[1] = BIT_7;
1466 /* Reset Initialization control block */
1467 memset(icb, 0, ha->init_cb_size);
1470 * Setup driver NVRAM options.
1472 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1473 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1474 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1475 nv->firmware_options[1] &= ~BIT_4;
1477 if (IS_QLA23XX(ha)) {
1478 nv->firmware_options[0] |= BIT_2;
1479 nv->firmware_options[0] &= ~BIT_3;
1480 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1482 if (IS_QLA2300(ha)) {
1483 if (ha->fb_rev == FPM_2310) {
1484 strcpy(ha->model_number, "QLA2310");
1486 strcpy(ha->model_number, "QLA2300");
1490 memcmp(nv->model_number, BINZERO,
1491 sizeof(nv->model_number)) != 0) {
1494 strncpy(ha->model_number, nv->model_number,
1495 sizeof(nv->model_number));
1496 st = en = ha->model_number;
1497 en += sizeof(nv->model_number) - 1;
1499 if (*en != 0x20 && *en != 0x00)
1506 index = (ha->pdev->subsystem_device & 0xff);
1507 if (index < QLA_MODEL_NAMES) {
1508 strcpy(ha->model_number,
1509 qla2x00_model_name[index]);
1511 qla2x00_model_desc[index];
1513 strcpy(ha->model_number, "QLA23xx");
1517 } else if (IS_QLA2200(ha)) {
1518 nv->firmware_options[0] |= BIT_2;
1520 * 'Point-to-point preferred, else loop' is not a safe
1521 * connection mode setting.
1523 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1525 /* Force 'loop preferred, else point-to-point'. */
1526 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1527 nv->add_firmware_options[0] |= BIT_5;
1529 strcpy(ha->model_number, "QLA22xx");
1530 } else /*if (IS_QLA2100(ha))*/ {
1531 strcpy(ha->model_number, "QLA2100");
1535 * Copy over NVRAM RISC parameter block to initialization control block.
1537 dptr1 = (uint8_t *)icb;
1538 dptr2 = (uint8_t *)&nv->parameter_block_version;
1539 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1541 *dptr1++ = *dptr2++;
1543 /* Copy 2nd half. */
1544 dptr1 = (uint8_t *)icb->add_firmware_options;
1545 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1547 *dptr1++ = *dptr2++;
1549 /* Prepare nodename */
1550 if ((icb->firmware_options[1] & BIT_6) == 0) {
1552 * Firmware will apply the following mask if the nodename was
1555 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1556 icb->node_name[0] &= 0xF0;
1560 * Set host adapter parameters.
1562 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1563 /* Always load RISC code on non ISP2[12]00 chips. */
1564 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1565 ha->flags.disable_risc_code_load = 0;
1566 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1567 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1568 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1569 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1571 ha->operating_mode =
1572 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1574 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1575 sizeof(ha->fw_seriallink_options));
1577 /* save HBA serial number */
1578 ha->serial0 = icb->port_name[5];
1579 ha->serial1 = icb->port_name[6];
1580 ha->serial2 = icb->port_name[7];
1581 ha->node_name = icb->node_name;
1582 ha->port_name = icb->port_name;
1584 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1586 ha->retry_count = nv->retry_count;
1588 /* Set minimum login_timeout to 4 seconds. */
1589 if (nv->login_timeout < ql2xlogintimeout)
1590 nv->login_timeout = ql2xlogintimeout;
1591 if (nv->login_timeout < 4)
1592 nv->login_timeout = 4;
1593 ha->login_timeout = nv->login_timeout;
1594 icb->login_timeout = nv->login_timeout;
1596 /* Set minimum RATOV to 200 tenths of a second. */
1599 ha->loop_reset_delay = nv->reset_delay;
1601 /* Link Down Timeout = 0:
1603 * When Port Down timer expires we will start returning
1604 * I/O's to OS with "DID_NO_CONNECT".
1606 * Link Down Timeout != 0:
1608 * The driver waits for the link to come up after link down
1609 * before returning I/Os to OS with "DID_NO_CONNECT".
1611 if (nv->link_down_timeout == 0) {
1612 ha->loop_down_abort_time =
1613 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1615 ha->link_down_timeout = nv->link_down_timeout;
1616 ha->loop_down_abort_time =
1617 (LOOP_DOWN_TIME - ha->link_down_timeout);
1621 * Need enough time to try and get the port back.
1623 ha->port_down_retry_count = nv->port_down_retry_count;
1624 if (qlport_down_retry)
1625 ha->port_down_retry_count = qlport_down_retry;
1626 /* Set login_retry_count */
1627 ha->login_retry_count = nv->retry_count;
1628 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1629 ha->port_down_retry_count > 3)
1630 ha->login_retry_count = ha->port_down_retry_count;
1631 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1632 ha->login_retry_count = ha->port_down_retry_count;
1633 if (ql2xloginretrycount)
1634 ha->login_retry_count = ql2xloginretrycount;
1636 icb->lun_enables = __constant_cpu_to_le16(0);
1637 icb->command_resource_count = 0;
1638 icb->immediate_notify_resource_count = 0;
1639 icb->timeout = __constant_cpu_to_le16(0);
1641 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1643 icb->firmware_options[0] &= ~BIT_3;
1644 icb->add_firmware_options[0] &=
1645 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1646 icb->add_firmware_options[0] |= BIT_2;
1647 icb->response_accumulation_timer = 3;
1648 icb->interrupt_delay_timer = 5;
1650 ha->flags.process_response_queue = 1;
1653 if (!ha->flags.init_done) {
1654 ha->zio_mode = icb->add_firmware_options[0] &
1655 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1656 ha->zio_timer = icb->interrupt_delay_timer ?
1657 icb->interrupt_delay_timer: 2;
1659 icb->add_firmware_options[0] &=
1660 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1661 ha->flags.process_response_queue = 0;
1662 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1663 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1664 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1665 ha->zio_timer * 100));
1666 qla_printk(KERN_INFO, ha,
1667 "ZIO mode %d enabled; timer delay (%d us).\n",
1668 ha->zio_mode, ha->zio_timer * 100);
1670 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1671 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1672 ha->flags.process_response_queue = 1;
1677 DEBUG2_3(printk(KERN_WARNING
1678 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1684 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1686 * @flags: allocation flags
1688 * Returns a pointer to the allocated fcport, or NULL, if none available.
1691 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1695 fcport = kmalloc(sizeof(fc_port_t), flags);
1699 /* Setup fcport template structure. */
1700 memset(fcport, 0, sizeof (fc_port_t));
1702 fcport->port_type = FCT_UNKNOWN;
1703 fcport->loop_id = FC_NO_LOOP_ID;
1704 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1705 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1706 fcport->flags = FCF_RLC_SUPPORT;
1707 fcport->supported_classes = FC_COS_UNSPECIFIED;
1713 * qla2x00_configure_loop
1714 * Updates Fibre Channel Device Database with what is actually on loop.
1717 * ha = adapter block pointer.
1722 * 2 = database was full and device was not configured.
1725 qla2x00_configure_loop(scsi_qla_host_t *ha)
1728 unsigned long flags, save_flags;
1732 /* Get Initiator ID */
1733 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1734 rval = qla2x00_configure_hba(ha);
1735 if (rval != QLA_SUCCESS) {
1736 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1742 save_flags = flags = ha->dpc_flags;
1743 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1744 ha->host_no, flags));
1747 * If we have both an RSCN and PORT UPDATE pending then handle them
1748 * both at the same time.
1750 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1751 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1753 /* Determine what we need to do */
1754 if (ha->current_topology == ISP_CFG_FL &&
1755 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1757 ha->flags.rscn_queue_overflow = 1;
1758 set_bit(RSCN_UPDATE, &flags);
1760 } else if (ha->current_topology == ISP_CFG_F &&
1761 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1763 ha->flags.rscn_queue_overflow = 1;
1764 set_bit(RSCN_UPDATE, &flags);
1765 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1767 } else if (!ha->flags.online ||
1768 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1770 ha->flags.rscn_queue_overflow = 1;
1771 set_bit(RSCN_UPDATE, &flags);
1772 set_bit(LOCAL_LOOP_UPDATE, &flags);
1775 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1776 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1777 rval = QLA_FUNCTION_FAILED;
1779 rval = qla2x00_configure_local_loop(ha);
1783 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1784 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1785 rval = QLA_FUNCTION_FAILED;
1787 rval = qla2x00_configure_fabric(ha);
1791 if (rval == QLA_SUCCESS) {
1792 if (atomic_read(&ha->loop_down_timer) ||
1793 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1794 rval = QLA_FUNCTION_FAILED;
1796 atomic_set(&ha->loop_state, LOOP_READY);
1798 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1803 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1804 __func__, ha->host_no));
1806 DEBUG3(printk("%s: exiting normally\n", __func__));
1809 /* Restore state if a resync event occured during processing */
1810 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1811 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1812 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1813 if (test_bit(RSCN_UPDATE, &save_flags))
1814 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1823 * qla2x00_configure_local_loop
1824 * Updates Fibre Channel Device Database with local loop devices.
1827 * ha = adapter block pointer.
1833 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1838 fc_port_t *fcport, *new_fcport;
1844 uint8_t domain, area, al_pa;
1848 entries = MAX_FIBRE_DEVICES;
1850 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1851 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1853 /* Get list of logged in devices. */
1854 memset(ha->gid_list, 0, GID_LIST_SIZE);
1855 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1857 if (rval != QLA_SUCCESS)
1858 goto cleanup_allocation;
1860 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1861 ha->host_no, entries));
1862 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1863 entries * sizeof(struct gid_list_info)));
1865 /* Allocate temporary fcport for any new fcports discovered. */
1866 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1867 if (new_fcport == NULL) {
1868 rval = QLA_MEMORY_ALLOC_FAILED;
1869 goto cleanup_allocation;
1871 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1874 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1876 list_for_each_entry(fcport, &ha->fcports, list) {
1877 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1878 fcport->port_type != FCT_BROADCAST &&
1879 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1881 DEBUG(printk("scsi(%ld): Marking port lost, "
1883 ha->host_no, fcport->loop_id));
1885 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1886 fcport->flags &= ~FCF_FARP_DONE;
1890 /* Add devices to port list. */
1891 id_iter = (char *)ha->gid_list;
1892 for (index = 0; index < entries; index++) {
1893 domain = ((struct gid_list_info *)id_iter)->domain;
1894 area = ((struct gid_list_info *)id_iter)->area;
1895 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1896 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1897 loop_id = (uint16_t)
1898 ((struct gid_list_info *)id_iter)->loop_id_2100;
1900 loop_id = le16_to_cpu(
1901 ((struct gid_list_info *)id_iter)->loop_id);
1902 id_iter += ha->gid_list_info_size;
1904 /* Bypass reserved domain fields. */
1905 if ((domain & 0xf0) == 0xf0)
1908 /* Bypass if not same domain and area of adapter. */
1909 if (area && domain &&
1910 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
1913 /* Bypass invalid local loop ID. */
1914 if (loop_id > LAST_LOCAL_LOOP_ID)
1917 /* Fill in member data. */
1918 new_fcport->d_id.b.domain = domain;
1919 new_fcport->d_id.b.area = area;
1920 new_fcport->d_id.b.al_pa = al_pa;
1921 new_fcport->loop_id = loop_id;
1922 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1923 if (rval2 != QLA_SUCCESS) {
1924 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1925 "information -- get_port_database=%x, "
1927 ha->host_no, rval2, new_fcport->loop_id));
1931 /* Check for matching device in port list. */
1934 list_for_each_entry(fcport, &ha->fcports, list) {
1935 if (memcmp(new_fcport->port_name, fcport->port_name,
1939 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1940 FCF_PERSISTENT_BOUND);
1941 fcport->loop_id = new_fcport->loop_id;
1942 fcport->port_type = new_fcport->port_type;
1943 fcport->d_id.b24 = new_fcport->d_id.b24;
1944 memcpy(fcport->node_name, new_fcport->node_name,
1952 /* New device, add to fcports list. */
1953 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1954 list_add_tail(&new_fcport->list, &ha->fcports);
1956 /* Allocate a new replacement fcport. */
1957 fcport = new_fcport;
1958 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1959 if (new_fcport == NULL) {
1960 rval = QLA_MEMORY_ALLOC_FAILED;
1961 goto cleanup_allocation;
1963 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1966 qla2x00_update_fcport(ha, fcport);
1975 if (rval != QLA_SUCCESS) {
1976 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1977 "rval=%x\n", ha->host_no, rval));
1981 ha->device_flags |= DFLG_LOCAL_DEVICES;
1982 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
1989 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
1993 qla2x00_mark_all_devices_lost(ha);
1994 list_for_each_entry(fcport, &ha->fcports, list) {
1995 if (fcport->port_type != FCT_TARGET)
1998 qla2x00_update_fcport(ha, fcport);
2003 * qla2x00_update_fcport
2004 * Updates device on list.
2007 * ha = adapter block pointer.
2008 * fcport = port structure pointer.
2018 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2021 unsigned long flags;
2025 fcport->login_retry = 0;
2026 fcport->port_login_retry_count = ha->port_down_retry_count *
2028 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2030 fcport->flags &= ~FCF_LOGIN_NEEDED;
2033 * Check for outstanding cmd on tape Bypass LUN discovery if active
2036 if (fcport->flags & FCF_TAPE_PRESENT) {
2037 spin_lock_irqsave(&ha->hardware_lock, flags);
2038 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
2041 if ((sp = ha->outstanding_cmds[index]) != 0) {
2043 if (sfcp == fcport) {
2044 atomic_set(&fcport->state, FCS_ONLINE);
2045 spin_unlock_irqrestore(
2046 &ha->hardware_lock, flags);
2051 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2054 if (fcport->port_type == FCT_INITIATOR ||
2055 fcport->port_type == FCT_BROADCAST)
2056 fcport->device_type = TYPE_PROCESSOR;
2058 atomic_set(&fcport->state, FCS_ONLINE);
2060 if (ha->flags.init_done)
2061 qla2x00_reg_remote_port(ha, fcport);
2065 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2067 struct fc_rport_identifiers rport_ids;
2068 struct fc_rport *rport;
2070 if (fcport->rport) {
2071 fc_remote_port_unblock(fcport->rport);
2075 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2076 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2077 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2078 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2079 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2080 fcport->rport = rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2082 qla_printk(KERN_WARNING, ha,
2083 "Unable to allocate fc remote port!\n");
2086 rport->dd_data = fcport;
2087 rport->supported_classes = fcport->supported_classes;
2089 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2090 if (fcport->port_type == FCT_INITIATOR)
2091 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2092 if (fcport->port_type == FCT_TARGET)
2093 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2094 fc_remote_port_rolechg(rport, rport_ids.roles);
2096 if (rport->scsi_target_id != -1 &&
2097 rport->scsi_target_id < ha->host->max_id)
2098 fcport->os_target_id = rport->scsi_target_id;
2102 * qla2x00_configure_fabric
2103 * Setup SNS devices with loop ID's.
2106 * ha = adapter block pointer.
2113 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2116 fc_port_t *fcport, *fcptemp;
2117 uint16_t next_loopid;
2118 uint16_t mb[MAILBOX_REGISTER_COUNT];
2120 LIST_HEAD(new_fcports);
2122 /* If FL port exists, then SNS is present */
2123 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
2124 loop_id = NPH_F_PORT;
2126 loop_id = SNS_FL_PORT;
2127 rval = qla2x00_get_port_name(ha, loop_id, NULL, 0);
2128 if (rval != QLA_SUCCESS) {
2129 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2130 "Port\n", ha->host_no));
2132 ha->device_flags &= ~SWITCH_FOUND;
2133 return (QLA_SUCCESS);
2136 /* Mark devices that need re-synchronization. */
2137 rval2 = qla2x00_device_resync(ha);
2138 if (rval2 == QLA_RSCNS_HANDLED) {
2139 /* No point doing the scan, just continue. */
2140 return (QLA_SUCCESS);
2144 if (ql2xfdmienable &&
2145 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2146 qla2x00_fdmi_register(ha);
2148 /* Ensure we are logged into the SNS. */
2149 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
2152 loop_id = SIMPLE_NAME_SERVER;
2153 ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
2154 0xfc, mb, BIT_1 | BIT_0);
2155 if (mb[0] != MBS_COMMAND_COMPLETE) {
2156 DEBUG2(qla_printk(KERN_INFO, ha,
2157 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2158 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2159 mb[0], mb[1], mb[2], mb[6], mb[7]));
2160 return (QLA_SUCCESS);
2163 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2164 if (qla2x00_rft_id(ha)) {
2166 DEBUG2(printk("scsi(%ld): Register FC-4 "
2167 "TYPE failed.\n", ha->host_no));
2169 if (qla2x00_rff_id(ha)) {
2171 DEBUG2(printk("scsi(%ld): Register FC-4 "
2172 "Features failed.\n", ha->host_no));
2174 if (qla2x00_rnn_id(ha)) {
2176 DEBUG2(printk("scsi(%ld): Register Node Name "
2177 "failed.\n", ha->host_no));
2178 } else if (qla2x00_rsnn_nn(ha)) {
2180 DEBUG2(printk("scsi(%ld): Register Symbolic "
2181 "Node Name failed.\n", ha->host_no));
2185 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2186 if (rval != QLA_SUCCESS)
2190 * Logout all previous fabric devices marked lost, except
2193 list_for_each_entry(fcport, &ha->fcports, list) {
2194 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2197 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2200 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2201 qla2x00_mark_device_lost(ha, fcport,
2202 ql2xplogiabsentdevice);
2203 if (fcport->loop_id != FC_NO_LOOP_ID &&
2204 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2205 fcport->port_type != FCT_INITIATOR &&
2206 fcport->port_type != FCT_BROADCAST) {
2208 ha->isp_ops.fabric_logout(ha,
2210 fcport->d_id.b.domain,
2211 fcport->d_id.b.area,
2212 fcport->d_id.b.al_pa);
2213 fcport->loop_id = FC_NO_LOOP_ID;
2218 /* Starting free loop ID. */
2219 next_loopid = ha->min_external_loopid;
2222 * Scan through our port list and login entries that need to be
2225 list_for_each_entry(fcport, &ha->fcports, list) {
2226 if (atomic_read(&ha->loop_down_timer) ||
2227 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2230 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2231 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2234 if (fcport->loop_id == FC_NO_LOOP_ID) {
2235 fcport->loop_id = next_loopid;
2236 rval = qla2x00_find_new_loop_id(ha, fcport);
2237 if (rval != QLA_SUCCESS) {
2238 /* Ran out of IDs to use */
2242 /* Login and update database */
2243 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2246 /* Exit if out of loop IDs. */
2247 if (rval != QLA_SUCCESS) {
2252 * Login and add the new devices to our port list.
2254 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2255 if (atomic_read(&ha->loop_down_timer) ||
2256 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2259 /* Find a new loop ID to use. */
2260 fcport->loop_id = next_loopid;
2261 rval = qla2x00_find_new_loop_id(ha, fcport);
2262 if (rval != QLA_SUCCESS) {
2263 /* Ran out of IDs to use */
2267 /* Remove device from the new list and add it to DB */
2268 list_del(&fcport->list);
2269 list_add_tail(&fcport->list, &ha->fcports);
2271 /* Login and update database */
2272 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2276 /* Free all new device structures not processed. */
2277 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2278 list_del(&fcport->list);
2283 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2284 "rval=%d\n", ha->host_no, rval));
2292 * qla2x00_find_all_fabric_devs
2295 * ha = adapter block pointer.
2296 * dev = database device entry pointer.
2305 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2309 fc_port_t *fcport, *new_fcport, *fcptemp;
2314 int first_dev, last_dev;
2315 port_id_t wrap, nxt_d_id;
2319 /* Try GID_PT to get device list, else GAN. */
2320 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2323 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2324 "on GA_NXT\n", ha->host_no));
2326 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2327 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2330 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2333 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2340 /* Allocate temporary fcport for any new fcports discovered. */
2341 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2342 if (new_fcport == NULL) {
2345 return (QLA_MEMORY_ALLOC_FAILED);
2347 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2349 /* Set start port ID scan at adapter ID. */
2353 /* Starting free loop ID. */
2354 loop_id = ha->min_external_loopid;
2355 for (; loop_id <= ha->last_loop_id; loop_id++) {
2356 if (qla2x00_is_reserved_id(ha, loop_id))
2359 if (atomic_read(&ha->loop_down_timer) ||
2360 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2365 wrap.b24 = new_fcport->d_id.b24;
2367 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2368 memcpy(new_fcport->node_name,
2369 swl[swl_idx].node_name, WWN_SIZE);
2370 memcpy(new_fcport->port_name,
2371 swl[swl_idx].port_name, WWN_SIZE);
2373 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2379 /* Send GA_NXT to the switch */
2380 rval = qla2x00_ga_nxt(ha, new_fcport);
2381 if (rval != QLA_SUCCESS) {
2382 qla_printk(KERN_WARNING, ha,
2383 "SNS scan failed -- assuming zero-entry "
2385 list_for_each_entry_safe(fcport, fcptemp,
2386 new_fcports, list) {
2387 list_del(&fcport->list);
2395 /* If wrap on switch device list, exit. */
2397 wrap.b24 = new_fcport->d_id.b24;
2399 } else if (new_fcport->d_id.b24 == wrap.b24) {
2400 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2401 ha->host_no, new_fcport->d_id.b.domain,
2402 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2406 /* Bypass if host adapter. */
2407 if (new_fcport->d_id.b24 == ha->d_id.b24)
2410 /* Bypass if same domain and area of adapter. */
2411 if (((new_fcport->d_id.b24 & 0xffff00) ==
2412 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2416 /* Bypass reserved domain fields. */
2417 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2420 /* Locate matching device in database. */
2422 list_for_each_entry(fcport, &ha->fcports, list) {
2423 if (memcmp(new_fcport->port_name, fcport->port_name,
2430 * If address the same and state FCS_ONLINE, nothing
2433 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2434 atomic_read(&fcport->state) == FCS_ONLINE) {
2439 * If device was not a fabric device before.
2441 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2442 fcport->d_id.b24 = new_fcport->d_id.b24;
2443 fcport->loop_id = FC_NO_LOOP_ID;
2444 fcport->flags |= (FCF_FABRIC_DEVICE |
2446 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2451 * Port ID changed or device was marked to be updated;
2452 * Log it out if still logged in and mark it for
2455 fcport->d_id.b24 = new_fcport->d_id.b24;
2456 fcport->flags |= FCF_LOGIN_NEEDED;
2457 if (fcport->loop_id != FC_NO_LOOP_ID &&
2458 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2459 fcport->port_type != FCT_INITIATOR &&
2460 fcport->port_type != FCT_BROADCAST) {
2461 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2462 fcport->d_id.b.domain, fcport->d_id.b.area,
2463 fcport->d_id.b.al_pa);
2464 fcport->loop_id = FC_NO_LOOP_ID;
2473 /* If device was not in our fcports list, then add it. */
2474 list_add_tail(&new_fcport->list, new_fcports);
2476 /* Allocate a new replacement fcport. */
2477 nxt_d_id.b24 = new_fcport->d_id.b24;
2478 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2479 if (new_fcport == NULL) {
2482 return (QLA_MEMORY_ALLOC_FAILED);
2484 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2485 new_fcport->d_id.b24 = nxt_d_id.b24;
2494 if (!list_empty(new_fcports))
2495 ha->device_flags |= DFLG_FABRIC_DEVICES;
2501 * qla2x00_find_new_loop_id
2502 * Scan through our port list and find a new usable loop ID.
2505 * ha: adapter state pointer.
2506 * dev: port structure pointer.
2509 * qla2x00 local function return status code.
2515 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2520 uint16_t first_loop_id;
2524 /* Save starting loop ID. */
2525 first_loop_id = dev->loop_id;
2528 /* Skip loop ID if already used by adapter. */
2529 if (dev->loop_id == ha->loop_id) {
2533 /* Skip reserved loop IDs. */
2534 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2538 /* Reset loop ID if passed the end. */
2539 if (dev->loop_id > ha->last_loop_id) {
2540 /* first loop ID. */
2541 dev->loop_id = ha->min_external_loopid;
2544 /* Check for loop ID being already in use. */
2547 list_for_each_entry(fcport, &ha->fcports, list) {
2548 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2549 /* ID possibly in use */
2555 /* If not in use then it is free to use. */
2560 /* ID in use. Try next value. */
2563 /* If wrap around. No free ID to use. */
2564 if (dev->loop_id == first_loop_id) {
2565 dev->loop_id = FC_NO_LOOP_ID;
2566 rval = QLA_FUNCTION_FAILED;
2575 * qla2x00_device_resync
2576 * Marks devices in the database that needs resynchronization.
2579 * ha = adapter block pointer.
2585 qla2x00_device_resync(scsi_qla_host_t *ha)
2591 uint32_t rscn_entry;
2592 uint8_t rscn_out_iter;
2596 rval = QLA_RSCNS_HANDLED;
2598 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2599 ha->flags.rscn_queue_overflow) {
2601 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2602 format = MSB(MSW(rscn_entry));
2603 d_id.b.domain = LSB(MSW(rscn_entry));
2604 d_id.b.area = MSB(LSW(rscn_entry));
2605 d_id.b.al_pa = LSB(LSW(rscn_entry));
2607 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2608 "[%02x/%02x%02x%02x].\n",
2609 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2610 d_id.b.area, d_id.b.al_pa));
2613 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2614 ha->rscn_out_ptr = 0;
2616 /* Skip duplicate entries. */
2617 for (rscn_out_iter = ha->rscn_out_ptr;
2618 !ha->flags.rscn_queue_overflow &&
2619 rscn_out_iter != ha->rscn_in_ptr;
2620 rscn_out_iter = (rscn_out_iter ==
2621 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2623 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2626 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2627 "entry found at [%d].\n", ha->host_no,
2630 ha->rscn_out_ptr = rscn_out_iter;
2633 /* Queue overflow, set switch default case. */
2634 if (ha->flags.rscn_queue_overflow) {
2635 DEBUG(printk("scsi(%ld): device_resync: rscn "
2636 "overflow.\n", ha->host_no));
2639 ha->flags.rscn_queue_overflow = 0;
2644 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) &&
2645 !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
2646 !IS_QLA24XX(ha) && !IS_QLA25XX(ha) &&
2647 ha->flags.init_done) {
2648 /* Handle port RSCN via asyncronous IOCBs */
2649 rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
2651 if (rval2 == QLA_SUCCESS)
2665 ha->rscn_out_ptr = ha->rscn_in_ptr;
2671 /* Abort any outstanding IO descriptors. */
2672 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2673 qla2x00_cancel_io_descriptors(ha);
2675 list_for_each_entry(fcport, &ha->fcports, list) {
2676 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2677 (fcport->d_id.b24 & mask) != d_id.b24 ||
2678 fcport->port_type == FCT_BROADCAST)
2681 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2683 fcport->port_type != FCT_INITIATOR) {
2684 qla2x00_mark_device_lost(ha, fcport, 0);
2687 fcport->flags &= ~FCF_FARP_DONE;
2694 * qla2x00_fabric_dev_login
2695 * Login fabric target device and update FC port database.
2698 * ha: adapter state pointer.
2699 * fcport: port structure list pointer.
2700 * next_loopid: contains value of a new loop ID that can be used
2701 * by the next login attempt.
2704 * qla2x00 local function return status code.
2710 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2711 uint16_t *next_loopid)
2720 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2721 if (rval == QLA_SUCCESS) {
2722 /* Send an ADISC to tape devices.*/
2724 if (fcport->flags & FCF_TAPE_PRESENT)
2726 rval = qla2x00_get_port_database(ha, fcport, opts);
2727 if (rval != QLA_SUCCESS) {
2728 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2729 fcport->d_id.b.domain, fcport->d_id.b.area,
2730 fcport->d_id.b.al_pa);
2731 qla2x00_mark_device_lost(ha, fcport, 1);
2734 qla2x00_update_fcport(ha, fcport);
2742 * qla2x00_fabric_login
2743 * Issue fabric login command.
2746 * ha = adapter block pointer.
2747 * device = pointer to FC device type structure.
2750 * 0 - Login successfully
2752 * 2 - Initiator device
2756 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2757 uint16_t *next_loopid)
2761 uint16_t tmp_loopid;
2762 uint16_t mb[MAILBOX_REGISTER_COUNT];
2768 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2769 "for port %02x%02x%02x.\n",
2770 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2771 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2773 /* Login fcport on switch. */
2774 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2775 fcport->d_id.b.domain, fcport->d_id.b.area,
2776 fcport->d_id.b.al_pa, mb, BIT_0);
2777 if (mb[0] == MBS_PORT_ID_USED) {
2779 * Device has another loop ID. The firmware team
2780 * recommends the driver perform an implicit login with
2781 * the specified ID again. The ID we just used is save
2782 * here so we return with an ID that can be tried by
2786 tmp_loopid = fcport->loop_id;
2787 fcport->loop_id = mb[1];
2789 DEBUG(printk("Fabric Login: port in use - next "
2790 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2791 fcport->loop_id, fcport->d_id.b.domain,
2792 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2794 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2799 /* A retry occurred before. */
2800 *next_loopid = tmp_loopid;
2803 * No retry occurred before. Just increment the
2804 * ID value for next login.
2806 *next_loopid = (fcport->loop_id + 1);
2809 if (mb[1] & BIT_0) {
2810 fcport->port_type = FCT_INITIATOR;
2812 fcport->port_type = FCT_TARGET;
2813 if (mb[1] & BIT_1) {
2814 fcport->flags |= FCF_TAPE_PRESENT;
2819 fcport->supported_classes |= FC_COS_CLASS2;
2821 fcport->supported_classes |= FC_COS_CLASS3;
2825 } else if (mb[0] == MBS_LOOP_ID_USED) {
2827 * Loop ID already used, try next loop ID.
2830 rval = qla2x00_find_new_loop_id(ha, fcport);
2831 if (rval != QLA_SUCCESS) {
2832 /* Ran out of loop IDs to use */
2835 } else if (mb[0] == MBS_COMMAND_ERROR) {
2837 * Firmware possibly timed out during login. If NO
2838 * retries are left to do then the device is declared
2841 *next_loopid = fcport->loop_id;
2842 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2843 fcport->d_id.b.domain, fcport->d_id.b.area,
2844 fcport->d_id.b.al_pa);
2845 qla2x00_mark_device_lost(ha, fcport, 1);
2851 * unrecoverable / not handled error
2853 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2854 "loop_id=%x jiffies=%lx.\n",
2855 __func__, ha->host_no, mb[0],
2856 fcport->d_id.b.domain, fcport->d_id.b.area,
2857 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2859 *next_loopid = fcport->loop_id;
2860 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2861 fcport->d_id.b.domain, fcport->d_id.b.area,
2862 fcport->d_id.b.al_pa);
2863 fcport->loop_id = FC_NO_LOOP_ID;
2864 fcport->login_retry = 0;
2875 * qla2x00_local_device_login
2876 * Issue local device login command.
2879 * ha = adapter block pointer.
2880 * loop_id = loop id of device to login to.
2882 * Returns (Where's the #define!!!!):
2883 * 0 - Login successfully
2888 qla2x00_local_device_login(scsi_qla_host_t *ha, uint16_t loop_id)
2891 uint16_t mb[MAILBOX_REGISTER_COUNT];
2893 memset(mb, 0, sizeof(mb));
2894 rval = qla2x00_login_local_device(ha, loop_id, mb, BIT_0);
2895 if (rval == QLA_SUCCESS) {
2896 /* Interrogate mailbox registers for any errors */
2897 if (mb[0] == MBS_COMMAND_ERROR)
2899 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
2900 /* device not in PCB table */
2908 * qla2x00_loop_resync
2909 * Resync with fibre channel devices.
2912 * ha = adapter block pointer.
2918 qla2x00_loop_resync(scsi_qla_host_t *ha)
2925 atomic_set(&ha->loop_state, LOOP_UPDATE);
2926 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2927 if (ha->flags.online) {
2928 if (!(rval = qla2x00_fw_ready(ha))) {
2929 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2932 atomic_set(&ha->loop_state, LOOP_UPDATE);
2934 /* Issue a marker after FW becomes ready. */
2935 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
2936 ha->marker_needed = 0;
2938 /* Remap devices on Loop. */
2939 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2941 qla2x00_configure_loop(ha);
2943 } while (!atomic_read(&ha->loop_down_timer) &&
2944 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
2946 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
2950 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2951 return (QLA_FUNCTION_FAILED);
2955 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
2962 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
2968 list_for_each_entry(fcport, &ha->fcports, list) {
2969 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
2972 qla2x00_update_fcport(ha, fcport);
2973 fcport->flags &= ~FCF_RESCAN_NEEDED;
2977 qla2x00_probe_for_all_luns(ha);
2982 * Resets ISP and aborts all outstanding commands.
2985 * ha = adapter block pointer.
2991 qla2x00_abort_isp(scsi_qla_host_t *ha)
2993 unsigned long flags = 0;
2998 if (ha->flags.online) {
2999 ha->flags.online = 0;
3000 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3002 qla_printk(KERN_INFO, ha,
3003 "Performing ISP error recovery - ha= %p.\n", ha);
3004 ha->isp_ops.reset_chip(ha);
3006 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3007 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3008 atomic_set(&ha->loop_state, LOOP_DOWN);
3009 qla2x00_mark_all_devices_lost(ha);
3011 if (!atomic_read(&ha->loop_down_timer))
3012 atomic_set(&ha->loop_down_timer,
3016 spin_lock_irqsave(&ha->hardware_lock, flags);
3017 /* Requeue all commands in outstanding command list. */
3018 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3019 sp = ha->outstanding_cmds[cnt];
3021 ha->outstanding_cmds[cnt] = NULL;
3023 sp->cmd->result = DID_RESET << 16;
3024 sp->cmd->host_scribble = (unsigned char *)NULL;
3025 qla2x00_sp_compl(ha, sp);
3028 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3030 ha->isp_ops.nvram_config(ha);
3032 if (!qla2x00_restart_isp(ha)) {
3033 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3035 if (!atomic_read(&ha->loop_down_timer)) {
3037 * Issue marker command only when we are going
3038 * to start the I/O .
3040 ha->marker_needed = 1;
3043 ha->flags.online = 1;
3045 ha->isp_ops.enable_intrs(ha);
3047 ha->isp_abort_cnt = 0;
3048 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3049 } else { /* failed the ISP abort */
3050 ha->flags.online = 1;
3051 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3052 if (ha->isp_abort_cnt == 0) {
3053 qla_printk(KERN_WARNING, ha,
3054 "ISP error recovery failed - "
3055 "board disabled\n");
3057 * The next call disables the board
3060 ha->isp_ops.reset_adapter(ha);
3061 ha->flags.online = 0;
3062 clear_bit(ISP_ABORT_RETRY,
3065 } else { /* schedule another ISP abort */
3066 ha->isp_abort_cnt--;
3067 DEBUG(printk("qla%ld: ISP abort - "
3068 "retry remaining %d\n",
3069 ha->host_no, ha->isp_abort_cnt);)
3073 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3074 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3075 "- retrying (%d) more times\n",
3076 ha->host_no, ha->isp_abort_cnt);)
3077 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3085 qla_printk(KERN_INFO, ha,
3086 "qla2x00_abort_isp: **** FAILED ****\n");
3088 DEBUG(printk(KERN_INFO
3089 "qla2x00_abort_isp(%ld): exiting.\n",
3097 * qla2x00_restart_isp
3098 * restarts the ISP after a reset
3101 * ha = adapter block pointer.
3107 qla2x00_restart_isp(scsi_qla_host_t *ha)
3110 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3111 unsigned long flags = 0;
3114 /* If firmware needs to be loaded */
3115 if (qla2x00_isp_firmware(ha)) {
3116 ha->flags.online = 0;
3117 if (!(status = ha->isp_ops.chip_diag(ha))) {
3118 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3119 status = qla2x00_setup_chip(ha);
3123 spin_lock_irqsave(&ha->hardware_lock, flags);
3125 if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha)) {
3127 * Disable SRAM, Instruction RAM and GP RAM
3130 WRT_REG_WORD(®->hccr,
3131 (HCCR_ENABLE_PARITY + 0x0));
3132 RD_REG_WORD(®->hccr);
3135 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3137 status = qla2x00_setup_chip(ha);
3139 spin_lock_irqsave(&ha->hardware_lock, flags);
3141 if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha)) {
3142 /* Enable proper parity */
3145 WRT_REG_WORD(®->hccr,
3146 (HCCR_ENABLE_PARITY + 0x1));
3149 * SRAM, Instruction RAM and GP RAM
3152 WRT_REG_WORD(®->hccr,
3153 (HCCR_ENABLE_PARITY + 0x7));
3154 RD_REG_WORD(®->hccr);
3157 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3162 if (!status && !(status = qla2x00_init_rings(ha))) {
3163 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3164 if (!(status = qla2x00_fw_ready(ha))) {
3165 DEBUG(printk("%s(): Start configure loop, "
3166 "status = %d\n", __func__, status);)
3168 /* Issue a marker after FW becomes ready. */
3169 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3171 ha->flags.online = 1;
3172 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3175 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3176 qla2x00_configure_loop(ha);
3178 } while (!atomic_read(&ha->loop_down_timer) &&
3179 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3181 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3184 /* if no cable then assume it's good */
3185 if ((ha->device_flags & DFLG_NO_CABLE))
3188 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3196 * qla2x00_reset_adapter
3200 * ha = adapter block pointer.
3203 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3205 unsigned long flags = 0;
3206 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3208 ha->flags.online = 0;
3209 ha->isp_ops.disable_intrs(ha);
3211 spin_lock_irqsave(&ha->hardware_lock, flags);
3212 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3213 RD_REG_WORD(®->hccr); /* PCI Posting. */
3214 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3215 RD_REG_WORD(®->hccr); /* PCI Posting. */
3216 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3220 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3222 unsigned long flags = 0;
3223 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3225 ha->flags.online = 0;
3226 ha->isp_ops.disable_intrs(ha);
3228 spin_lock_irqsave(&ha->hardware_lock, flags);
3229 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3230 RD_REG_DWORD(®->hccr);
3231 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3232 RD_REG_DWORD(®->hccr);
3233 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3237 qla24xx_nvram_config(scsi_qla_host_t *ha)
3240 struct init_cb_24xx *icb;
3241 struct nvram_24xx *nv;
3243 uint8_t *dptr1, *dptr2;
3248 icb = (struct init_cb_24xx *)ha->init_cb;
3249 nv = (struct nvram_24xx *)ha->request_ring;
3251 /* Determine NVRAM starting address. */
3252 ha->nvram_size = sizeof(struct nvram_24xx);
3253 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3254 if (PCI_FUNC(ha->pdev->devfn))
3255 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3257 /* Get NVRAM data and calculate checksum. */
3258 dptr = (uint32_t *)nv;
3259 ha->isp_ops.read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3261 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3262 chksum += le32_to_cpu(*dptr++);
3264 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3265 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3268 /* Bad NVRAM data, set defaults parameters. */
3269 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3270 || nv->id[3] != ' ' ||
3271 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3272 /* Reset NVRAM data. */
3273 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3274 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3275 le16_to_cpu(nv->nvram_version));
3276 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3277 "invalid -- WWPN) defaults.\n");
3280 * Set default initialization control block.
3282 memset(nv, 0, ha->nvram_size);
3283 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3284 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3285 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3286 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3287 nv->exchange_count = __constant_cpu_to_le16(0);
3288 nv->hard_address = __constant_cpu_to_le16(124);
3289 nv->port_name[0] = 0x21;
3290 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3291 nv->port_name[2] = 0x00;
3292 nv->port_name[3] = 0xe0;
3293 nv->port_name[4] = 0x8b;
3294 nv->port_name[5] = 0x1c;
3295 nv->port_name[6] = 0x55;
3296 nv->port_name[7] = 0x86;
3297 nv->node_name[0] = 0x20;
3298 nv->node_name[1] = 0x00;
3299 nv->node_name[2] = 0x00;
3300 nv->node_name[3] = 0xe0;
3301 nv->node_name[4] = 0x8b;
3302 nv->node_name[5] = 0x1c;
3303 nv->node_name[6] = 0x55;
3304 nv->node_name[7] = 0x86;
3305 nv->login_retry_count = __constant_cpu_to_le16(8);
3306 nv->link_down_timeout = __constant_cpu_to_le16(200);
3307 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3308 nv->login_timeout = __constant_cpu_to_le16(0);
3309 nv->firmware_options_1 =
3310 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3311 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3312 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3313 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3314 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3315 nv->efi_parameters = __constant_cpu_to_le32(0);
3316 nv->reset_delay = 5;
3317 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3318 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3319 nv->link_down_timeout = __constant_cpu_to_le16(30);
3324 /* Reset Initialization control block */
3325 memset(icb, 0, sizeof(struct init_cb_24xx));
3327 /* Copy 1st segment. */
3328 dptr1 = (uint8_t *)icb;
3329 dptr2 = (uint8_t *)&nv->version;
3330 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3332 *dptr1++ = *dptr2++;
3334 icb->login_retry_count = nv->login_retry_count;
3335 icb->link_down_timeout = nv->link_down_timeout;
3337 /* Copy 2nd segment. */
3338 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3339 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3340 cnt = (uint8_t *)&icb->reserved_3 -
3341 (uint8_t *)&icb->interrupt_delay_timer;
3343 *dptr1++ = *dptr2++;
3346 * Setup driver NVRAM options.
3348 if (memcmp(nv->model_name, BINZERO, sizeof(nv->model_name)) != 0) {
3352 strncpy(ha->model_number, nv->model_name,
3353 sizeof(nv->model_name));
3354 st = en = ha->model_number;
3355 en += sizeof(nv->model_name) - 1;
3357 if (*en != 0x20 && *en != 0x00)
3362 index = (ha->pdev->subsystem_device & 0xff);
3363 if (index < QLA_MODEL_NAMES)
3364 ha->model_desc = qla2x00_model_desc[index];
3366 strcpy(ha->model_number, "QLA2462");
3368 /* Prepare nodename */
3369 if ((icb->firmware_options_1 & BIT_14) == 0) {
3371 * Firmware will apply the following mask if the nodename was
3374 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3375 icb->node_name[0] &= 0xF0;
3378 /* Set host adapter parameters. */
3379 ha->flags.disable_risc_code_load = 0;
3380 ha->flags.enable_lip_reset = 1;
3381 ha->flags.enable_lip_full_login = 1;
3382 ha->flags.enable_target_reset = 1;
3383 ha->flags.enable_led_scheme = 0;
3385 ha->operating_mode =
3386 (icb->firmware_options_2 & (BIT_6 | BIT_5 | BIT_4)) >> 4;
3388 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3389 sizeof(ha->fw_seriallink_options24));
3391 /* save HBA serial number */
3392 ha->serial0 = icb->port_name[5];
3393 ha->serial1 = icb->port_name[6];
3394 ha->serial2 = icb->port_name[7];
3395 ha->node_name = icb->node_name;
3396 ha->port_name = icb->port_name;
3398 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3400 /* Set minimum login_timeout to 4 seconds. */
3401 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3402 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3403 if (le16_to_cpu(nv->login_timeout) < 4)
3404 nv->login_timeout = __constant_cpu_to_le16(4);
3405 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3406 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3408 /* Set minimum RATOV to 200 tenths of a second. */
3411 ha->loop_reset_delay = nv->reset_delay;
3413 /* Link Down Timeout = 0:
3415 * When Port Down timer expires we will start returning
3416 * I/O's to OS with "DID_NO_CONNECT".
3418 * Link Down Timeout != 0:
3420 * The driver waits for the link to come up after link down
3421 * before returning I/Os to OS with "DID_NO_CONNECT".
3423 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3424 ha->loop_down_abort_time =
3425 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3427 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3428 ha->loop_down_abort_time =
3429 (LOOP_DOWN_TIME - ha->link_down_timeout);
3432 /* Need enough time to try and get the port back. */
3433 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3434 if (qlport_down_retry)
3435 ha->port_down_retry_count = qlport_down_retry;
3437 /* Set login_retry_count */
3438 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3439 if (ha->port_down_retry_count ==
3440 le16_to_cpu(nv->port_down_retry_count) &&
3441 ha->port_down_retry_count > 3)
3442 ha->login_retry_count = ha->port_down_retry_count;
3443 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3444 ha->login_retry_count = ha->port_down_retry_count;
3445 if (ql2xloginretrycount)
3446 ha->login_retry_count = ql2xloginretrycount;
3449 if (!ha->flags.init_done) {
3450 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3451 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3452 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3453 le16_to_cpu(icb->interrupt_delay_timer): 2;
3455 icb->firmware_options_2 &= __constant_cpu_to_le32(
3456 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3457 ha->flags.process_response_queue = 0;
3458 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3459 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3460 "(%d us).\n", ha->host_no, ha->zio_mode,
3461 ha->zio_timer * 100));
3462 qla_printk(KERN_INFO, ha,
3463 "ZIO mode %d enabled; timer delay (%d us).\n",
3464 ha->zio_mode, ha->zio_timer * 100);
3466 icb->firmware_options_2 |= cpu_to_le32(
3467 (uint32_t)ha->zio_mode);
3468 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3469 ha->flags.process_response_queue = 1;
3473 DEBUG2_3(printk(KERN_WARNING
3474 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3480 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3484 uint16_t *risc_code;
3485 unsigned long risc_address;
3486 unsigned long risc_code_size;
3490 struct qla_fw_info *fw_iter;
3494 /* Load firmware sequences */
3495 fw_iter = ha->brd_info->fw_info;
3496 *srisc_addr = *ha->brd_info->fw_info->fwstart;
3497 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
3498 risc_code = fw_iter->fwcode;
3499 risc_code_size = *fw_iter->fwlen;
3501 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
3502 risc_address = *fw_iter->fwstart;
3504 /* Extended address */
3505 risc_address = *fw_iter->lfwstart;
3510 while (risc_code_size > 0 && !rval) {
3511 cnt = (uint16_t)(ha->fw_transfer_size >> 1);
3512 if (cnt > risc_code_size)
3513 cnt = risc_code_size;
3515 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
3516 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
3517 ha->host_no, risc_code, cnt, risc_address));
3519 req_ring = (uint16_t *)ha->request_ring;
3520 for (i = 0; i < cnt; i++)
3521 req_ring[i] = cpu_to_le16(risc_code[i]);
3523 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
3524 rval = qla2x00_load_ram(ha, ha->request_dma,
3527 rval = qla2x00_load_ram_ext(ha,
3528 ha->request_dma, risc_address, cnt);
3531 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
3532 "load segment %d of firmware\n",
3534 qla_printk(KERN_WARNING, ha,
3535 "[ERROR] Failed to load segment %d of "
3538 qla2x00_dump_regs(ha);
3543 risc_address += cnt;
3544 risc_code_size -= cnt;
3548 /* Next firmware sequence */
3556 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3559 int segments, fragment;
3561 uint32_t *dcode, dlen;
3568 segments = FA_RISC_CODE_SEGMENTS;
3569 faddr = FA_RISC_CODE_ADDR;
3570 dcode = (uint32_t *)ha->request_ring;
3573 /* Validate firmware image by checking version. */
3574 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3575 for (i = 0; i < 4; i++)
3576 dcode[i] = be32_to_cpu(dcode[i]);
3577 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3578 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3579 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3581 qla_printk(KERN_WARNING, ha,
3582 "Unable to verify integrity of flash firmware image!\n");
3583 qla_printk(KERN_WARNING, ha,
3584 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3585 dcode[1], dcode[2], dcode[3]);
3587 return QLA_FUNCTION_FAILED;
3590 while (segments && rval == QLA_SUCCESS) {
3591 /* Read segment's load information. */
3592 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3594 risc_addr = be32_to_cpu(dcode[2]);
3595 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3596 risc_size = be32_to_cpu(dcode[3]);
3599 while (risc_size > 0 && rval == QLA_SUCCESS) {
3600 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3601 if (dlen > risc_size)
3604 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3605 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3606 ha->host_no, risc_addr, dlen, faddr));
3608 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3609 for (i = 0; i < dlen; i++)
3610 dcode[i] = swab32(dcode[i]);
3612 rval = qla2x00_load_ram_ext(ha, ha->request_dma,
3615 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3616 "segment %d of firmware\n", ha->host_no,
3618 qla_printk(KERN_WARNING, ha,
3619 "[ERROR] Failed to load segment %d of "
3620 "firmware\n", fragment);
3638 qla24xx_load_risc_hotplug(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3641 int segments, fragment;
3642 uint32_t *dcode, dlen;
3646 const struct firmware *fw_entry;
3647 uint32_t *fwcode, fwclen;
3649 if (request_firmware(&fw_entry, ha->brd_info->fw_fname,
3651 qla_printk(KERN_ERR, ha,
3652 "Firmware image file not available: '%s'\n",
3653 ha->brd_info->fw_fname);
3654 return QLA_FUNCTION_FAILED;
3659 segments = FA_RISC_CODE_SEGMENTS;
3660 dcode = (uint32_t *)ha->request_ring;
3662 fwcode = (uint32_t *)fw_entry->data;
3665 /* Validate firmware image by checking version. */
3666 if (fw_entry->size < 8 * sizeof(uint32_t)) {
3667 qla_printk(KERN_WARNING, ha,
3668 "Unable to verify integrity of flash firmware image "
3669 "(%Zd)!\n", fw_entry->size);
3670 goto fail_fw_integrity;
3672 for (i = 0; i < 4; i++)
3673 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3674 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3675 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3676 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3678 qla_printk(KERN_WARNING, ha,
3679 "Unable to verify integrity of flash firmware image!\n");
3680 qla_printk(KERN_WARNING, ha,
3681 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3682 dcode[1], dcode[2], dcode[3]);
3683 goto fail_fw_integrity;
3686 while (segments && rval == QLA_SUCCESS) {
3687 risc_addr = be32_to_cpu(fwcode[2]);
3688 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3689 risc_size = be32_to_cpu(fwcode[3]);
3691 /* Validate firmware image size. */
3692 fwclen += risc_size * sizeof(uint32_t);
3693 if (fw_entry->size < fwclen) {
3694 qla_printk(KERN_WARNING, ha,
3695 "Unable to verify integrity of flash firmware "
3696 "image (%Zd)!\n", fw_entry->size);
3697 goto fail_fw_integrity;
3701 while (risc_size > 0 && rval == QLA_SUCCESS) {
3702 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3703 if (dlen > risc_size)
3706 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3707 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3710 for (i = 0; i < dlen; i++)
3711 dcode[i] = swab32(fwcode[i]);
3713 rval = qla2x00_load_ram_ext(ha, ha->request_dma,
3716 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3717 "segment %d of firmware\n", ha->host_no,
3719 qla_printk(KERN_WARNING, ha,
3720 "[ERROR] Failed to load segment %d of "
3721 "firmware\n", fragment);
3735 release_firmware(fw_entry);
3740 release_firmware(fw_entry);
3741 return QLA_FUNCTION_FAILED;