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;
1379 /* Determine NVRAM starting address. */
1380 ha->nvram_size = sizeof(nvram_t);
1382 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1383 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1384 ha->nvram_base = 0x80;
1386 /* Get NVRAM data and calculate checksum. */
1387 ha->isp_ops.read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1388 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1391 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1392 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1395 /* Bad NVRAM data, set defaults parameters. */
1396 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1397 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1398 /* Reset NVRAM data. */
1399 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1400 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1402 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1403 "invalid -- WWPN) defaults.\n");
1406 * Set default initialization control block.
1408 memset(nv, 0, ha->nvram_size);
1409 nv->parameter_block_version = ICB_VERSION;
1411 if (IS_QLA23XX(ha)) {
1412 nv->firmware_options[0] = BIT_2 | BIT_1;
1413 nv->firmware_options[1] = BIT_7 | BIT_5;
1414 nv->add_firmware_options[0] = BIT_5;
1415 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1416 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1417 nv->special_options[1] = BIT_7;
1418 } else if (IS_QLA2200(ha)) {
1419 nv->firmware_options[0] = BIT_2 | BIT_1;
1420 nv->firmware_options[1] = BIT_7 | BIT_5;
1421 nv->add_firmware_options[0] = BIT_5;
1422 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1423 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1424 } else if (IS_QLA2100(ha)) {
1425 nv->firmware_options[0] = BIT_3 | BIT_1;
1426 nv->firmware_options[1] = BIT_5;
1427 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1430 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1431 nv->execution_throttle = __constant_cpu_to_le16(16);
1432 nv->retry_count = 8;
1433 nv->retry_delay = 1;
1435 nv->port_name[0] = 33;
1436 nv->port_name[3] = 224;
1437 nv->port_name[4] = 139;
1439 nv->login_timeout = 4;
1442 * Set default host adapter parameters
1444 nv->host_p[1] = BIT_2;
1445 nv->reset_delay = 5;
1446 nv->port_down_retry_count = 8;
1447 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1448 nv->link_down_timeout = 60;
1453 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1455 * The SN2 does not provide BIOS emulation which means you can't change
1456 * potentially bogus BIOS settings. Force the use of default settings
1457 * for link rate and frame size. Hope that the rest of the settings
1460 if (ia64_platform_is("sn2")) {
1461 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1463 nv->special_options[1] = BIT_7;
1467 /* Reset Initialization control block */
1468 memset(icb, 0, ha->init_cb_size);
1471 * Setup driver NVRAM options.
1473 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1474 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1475 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1476 nv->firmware_options[1] &= ~BIT_4;
1478 if (IS_QLA23XX(ha)) {
1479 nv->firmware_options[0] |= BIT_2;
1480 nv->firmware_options[0] &= ~BIT_3;
1481 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1483 if (IS_QLA2300(ha)) {
1484 if (ha->fb_rev == FPM_2310) {
1485 strcpy(ha->model_number, "QLA2310");
1487 strcpy(ha->model_number, "QLA2300");
1491 memcmp(nv->model_number, BINZERO,
1492 sizeof(nv->model_number)) != 0) {
1495 strncpy(ha->model_number, nv->model_number,
1496 sizeof(nv->model_number));
1497 st = en = ha->model_number;
1498 en += sizeof(nv->model_number) - 1;
1500 if (*en != 0x20 && *en != 0x00)
1507 index = (ha->pdev->subsystem_device & 0xff);
1508 if (index < QLA_MODEL_NAMES) {
1509 strcpy(ha->model_number,
1510 qla2x00_model_name[index]);
1512 qla2x00_model_desc[index];
1514 strcpy(ha->model_number, "QLA23xx");
1518 } else if (IS_QLA2200(ha)) {
1519 nv->firmware_options[0] |= BIT_2;
1521 * 'Point-to-point preferred, else loop' is not a safe
1522 * connection mode setting.
1524 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1526 /* Force 'loop preferred, else point-to-point'. */
1527 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1528 nv->add_firmware_options[0] |= BIT_5;
1530 strcpy(ha->model_number, "QLA22xx");
1531 } else /*if (IS_QLA2100(ha))*/ {
1532 strcpy(ha->model_number, "QLA2100");
1536 * Copy over NVRAM RISC parameter block to initialization control block.
1538 dptr1 = (uint8_t *)icb;
1539 dptr2 = (uint8_t *)&nv->parameter_block_version;
1540 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1542 *dptr1++ = *dptr2++;
1544 /* Copy 2nd half. */
1545 dptr1 = (uint8_t *)icb->add_firmware_options;
1546 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1548 *dptr1++ = *dptr2++;
1550 /* Prepare nodename */
1551 if ((icb->firmware_options[1] & BIT_6) == 0) {
1553 * Firmware will apply the following mask if the nodename was
1556 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1557 icb->node_name[0] &= 0xF0;
1561 * Set host adapter parameters.
1563 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1564 /* Always load RISC code on non ISP2[12]00 chips. */
1565 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1566 ha->flags.disable_risc_code_load = 0;
1567 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1568 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1569 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1570 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1572 ha->operating_mode =
1573 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1575 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1576 sizeof(ha->fw_seriallink_options));
1578 /* save HBA serial number */
1579 ha->serial0 = icb->port_name[5];
1580 ha->serial1 = icb->port_name[6];
1581 ha->serial2 = icb->port_name[7];
1582 ha->node_name = icb->node_name;
1583 ha->port_name = icb->port_name;
1585 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1587 ha->retry_count = nv->retry_count;
1589 /* Set minimum login_timeout to 4 seconds. */
1590 if (nv->login_timeout < ql2xlogintimeout)
1591 nv->login_timeout = ql2xlogintimeout;
1592 if (nv->login_timeout < 4)
1593 nv->login_timeout = 4;
1594 ha->login_timeout = nv->login_timeout;
1595 icb->login_timeout = nv->login_timeout;
1597 /* Set minimum RATOV to 200 tenths of a second. */
1600 ha->loop_reset_delay = nv->reset_delay;
1602 /* Link Down Timeout = 0:
1604 * When Port Down timer expires we will start returning
1605 * I/O's to OS with "DID_NO_CONNECT".
1607 * Link Down Timeout != 0:
1609 * The driver waits for the link to come up after link down
1610 * before returning I/Os to OS with "DID_NO_CONNECT".
1612 if (nv->link_down_timeout == 0) {
1613 ha->loop_down_abort_time =
1614 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1616 ha->link_down_timeout = nv->link_down_timeout;
1617 ha->loop_down_abort_time =
1618 (LOOP_DOWN_TIME - ha->link_down_timeout);
1622 * Need enough time to try and get the port back.
1624 ha->port_down_retry_count = nv->port_down_retry_count;
1625 if (qlport_down_retry)
1626 ha->port_down_retry_count = qlport_down_retry;
1627 /* Set login_retry_count */
1628 ha->login_retry_count = nv->retry_count;
1629 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1630 ha->port_down_retry_count > 3)
1631 ha->login_retry_count = ha->port_down_retry_count;
1632 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1633 ha->login_retry_count = ha->port_down_retry_count;
1634 if (ql2xloginretrycount)
1635 ha->login_retry_count = ql2xloginretrycount;
1637 icb->lun_enables = __constant_cpu_to_le16(0);
1638 icb->command_resource_count = 0;
1639 icb->immediate_notify_resource_count = 0;
1640 icb->timeout = __constant_cpu_to_le16(0);
1642 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1644 icb->firmware_options[0] &= ~BIT_3;
1645 icb->add_firmware_options[0] &=
1646 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1647 icb->add_firmware_options[0] |= BIT_2;
1648 icb->response_accumulation_timer = 3;
1649 icb->interrupt_delay_timer = 5;
1651 ha->flags.process_response_queue = 1;
1653 /* Enable ZIO -- Support mode 5 only. */
1654 timer_mode = icb->add_firmware_options[0] &
1655 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1656 icb->add_firmware_options[0] &=
1657 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1659 timer_mode = BIT_2 | BIT_0;
1660 if (timer_mode == (BIT_2 | BIT_0)) {
1661 DEBUG2(printk("scsi(%ld): ZIO enabled; timer delay "
1662 "(%d).\n", ha->host_no, ql2xintrdelaytimer));
1663 qla_printk(KERN_INFO, ha,
1664 "ZIO enabled; timer delay (%d).\n",
1665 ql2xintrdelaytimer);
1667 icb->add_firmware_options[0] |= timer_mode;
1668 icb->interrupt_delay_timer = ql2xintrdelaytimer;
1669 ha->flags.process_response_queue = 1;
1674 DEBUG2_3(printk(KERN_WARNING
1675 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1681 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1683 * @flags: allocation flags
1685 * Returns a pointer to the allocated fcport, or NULL, if none available.
1688 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1692 fcport = kmalloc(sizeof(fc_port_t), flags);
1696 /* Setup fcport template structure. */
1697 memset(fcport, 0, sizeof (fc_port_t));
1699 fcport->port_type = FCT_UNKNOWN;
1700 fcport->loop_id = FC_NO_LOOP_ID;
1701 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1702 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1703 fcport->flags = FCF_RLC_SUPPORT;
1704 fcport->supported_classes = FC_COS_UNSPECIFIED;
1710 * qla2x00_configure_loop
1711 * Updates Fibre Channel Device Database with what is actually on loop.
1714 * ha = adapter block pointer.
1719 * 2 = database was full and device was not configured.
1722 qla2x00_configure_loop(scsi_qla_host_t *ha)
1725 unsigned long flags, save_flags;
1729 /* Get Initiator ID */
1730 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1731 rval = qla2x00_configure_hba(ha);
1732 if (rval != QLA_SUCCESS) {
1733 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1739 save_flags = flags = ha->dpc_flags;
1740 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1741 ha->host_no, flags));
1744 * If we have both an RSCN and PORT UPDATE pending then handle them
1745 * both at the same time.
1747 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1748 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1750 /* Determine what we need to do */
1751 if (ha->current_topology == ISP_CFG_FL &&
1752 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1754 ha->flags.rscn_queue_overflow = 1;
1755 set_bit(RSCN_UPDATE, &flags);
1757 } else if (ha->current_topology == ISP_CFG_F &&
1758 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1760 ha->flags.rscn_queue_overflow = 1;
1761 set_bit(RSCN_UPDATE, &flags);
1762 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1764 } else if (!ha->flags.online ||
1765 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1767 ha->flags.rscn_queue_overflow = 1;
1768 set_bit(RSCN_UPDATE, &flags);
1769 set_bit(LOCAL_LOOP_UPDATE, &flags);
1772 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1773 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1774 rval = QLA_FUNCTION_FAILED;
1776 rval = qla2x00_configure_local_loop(ha);
1780 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1781 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1782 rval = QLA_FUNCTION_FAILED;
1784 rval = qla2x00_configure_fabric(ha);
1788 if (rval == QLA_SUCCESS) {
1789 if (atomic_read(&ha->loop_down_timer) ||
1790 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1791 rval = QLA_FUNCTION_FAILED;
1793 atomic_set(&ha->loop_state, LOOP_READY);
1795 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1800 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1801 __func__, ha->host_no));
1803 DEBUG3(printk("%s: exiting normally\n", __func__));
1806 /* Restore state if a resync event occured during processing */
1807 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1808 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1809 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1810 if (test_bit(RSCN_UPDATE, &save_flags))
1811 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1820 * qla2x00_configure_local_loop
1821 * Updates Fibre Channel Device Database with local loop devices.
1824 * ha = adapter block pointer.
1830 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1835 fc_port_t *fcport, *new_fcport;
1841 uint8_t domain, area, al_pa;
1845 entries = MAX_FIBRE_DEVICES;
1847 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1848 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1850 /* Get list of logged in devices. */
1851 memset(ha->gid_list, 0, GID_LIST_SIZE);
1852 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1854 if (rval != QLA_SUCCESS)
1855 goto cleanup_allocation;
1857 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1858 ha->host_no, entries));
1859 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1860 entries * sizeof(struct gid_list_info)));
1862 /* Allocate temporary fcport for any new fcports discovered. */
1863 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1864 if (new_fcport == NULL) {
1865 rval = QLA_MEMORY_ALLOC_FAILED;
1866 goto cleanup_allocation;
1868 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1871 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1873 list_for_each_entry(fcport, &ha->fcports, list) {
1874 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1875 fcport->port_type != FCT_BROADCAST &&
1876 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1878 DEBUG(printk("scsi(%ld): Marking port lost, "
1880 ha->host_no, fcport->loop_id));
1882 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1883 fcport->flags &= ~FCF_FARP_DONE;
1887 /* Add devices to port list. */
1888 id_iter = (char *)ha->gid_list;
1889 for (index = 0; index < entries; index++) {
1890 domain = ((struct gid_list_info *)id_iter)->domain;
1891 area = ((struct gid_list_info *)id_iter)->area;
1892 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1893 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1894 loop_id = (uint16_t)
1895 ((struct gid_list_info *)id_iter)->loop_id_2100;
1897 loop_id = le16_to_cpu(
1898 ((struct gid_list_info *)id_iter)->loop_id);
1899 id_iter += ha->gid_list_info_size;
1901 /* Bypass reserved domain fields. */
1902 if ((domain & 0xf0) == 0xf0)
1905 /* Bypass if not same domain and area of adapter. */
1906 if (area && domain &&
1907 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
1910 /* Bypass invalid local loop ID. */
1911 if (loop_id > LAST_LOCAL_LOOP_ID)
1914 /* Fill in member data. */
1915 new_fcport->d_id.b.domain = domain;
1916 new_fcport->d_id.b.area = area;
1917 new_fcport->d_id.b.al_pa = al_pa;
1918 new_fcport->loop_id = loop_id;
1919 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1920 if (rval2 != QLA_SUCCESS) {
1921 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1922 "information -- get_port_database=%x, "
1924 ha->host_no, rval2, new_fcport->loop_id));
1928 /* Check for matching device in port list. */
1931 list_for_each_entry(fcport, &ha->fcports, list) {
1932 if (memcmp(new_fcport->port_name, fcport->port_name,
1936 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1937 FCF_PERSISTENT_BOUND);
1938 fcport->loop_id = new_fcport->loop_id;
1939 fcport->port_type = new_fcport->port_type;
1940 fcport->d_id.b24 = new_fcport->d_id.b24;
1941 memcpy(fcport->node_name, new_fcport->node_name,
1949 /* New device, add to fcports list. */
1950 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1951 list_add_tail(&new_fcport->list, &ha->fcports);
1953 /* Allocate a new replacement fcport. */
1954 fcport = new_fcport;
1955 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1956 if (new_fcport == NULL) {
1957 rval = QLA_MEMORY_ALLOC_FAILED;
1958 goto cleanup_allocation;
1960 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1963 qla2x00_update_fcport(ha, fcport);
1972 if (rval != QLA_SUCCESS) {
1973 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1974 "rval=%x\n", ha->host_no, rval));
1978 ha->device_flags |= DFLG_LOCAL_DEVICES;
1979 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
1986 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
1990 qla2x00_mark_all_devices_lost(ha);
1991 list_for_each_entry(fcport, &ha->fcports, list) {
1992 if (fcport->port_type != FCT_TARGET)
1995 qla2x00_update_fcport(ha, fcport);
2000 * qla2x00_update_fcport
2001 * Updates device on list.
2004 * ha = adapter block pointer.
2005 * fcport = port structure pointer.
2015 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2018 unsigned long flags;
2022 fcport->login_retry = 0;
2023 fcport->port_login_retry_count = ha->port_down_retry_count *
2025 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2027 fcport->flags &= ~FCF_LOGIN_NEEDED;
2030 * Check for outstanding cmd on tape Bypass LUN discovery if active
2033 if (fcport->flags & FCF_TAPE_PRESENT) {
2034 spin_lock_irqsave(&ha->hardware_lock, flags);
2035 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
2038 if ((sp = ha->outstanding_cmds[index]) != 0) {
2040 if (sfcp == fcport) {
2041 atomic_set(&fcport->state, FCS_ONLINE);
2042 spin_unlock_irqrestore(
2043 &ha->hardware_lock, flags);
2048 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2051 if (fcport->port_type == FCT_INITIATOR ||
2052 fcport->port_type == FCT_BROADCAST)
2053 fcport->device_type = TYPE_PROCESSOR;
2055 atomic_set(&fcport->state, FCS_ONLINE);
2057 if (ha->flags.init_done)
2058 qla2x00_reg_remote_port(ha, fcport);
2062 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2064 struct fc_rport_identifiers rport_ids;
2065 struct fc_rport *rport;
2067 if (fcport->rport) {
2068 fc_remote_port_unblock(fcport->rport);
2072 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2073 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2074 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2075 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2076 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2077 fcport->rport = rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2079 qla_printk(KERN_WARNING, ha,
2080 "Unable to allocate fc remote port!\n");
2083 rport->dd_data = fcport;
2084 rport->supported_classes = fcport->supported_classes;
2086 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2087 if (fcport->port_type == FCT_INITIATOR)
2088 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2089 if (fcport->port_type == FCT_TARGET)
2090 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2091 fc_remote_port_rolechg(rport, rport_ids.roles);
2093 if (rport->scsi_target_id != -1 &&
2094 rport->scsi_target_id < ha->host->max_id)
2095 fcport->os_target_id = rport->scsi_target_id;
2099 * qla2x00_configure_fabric
2100 * Setup SNS devices with loop ID's.
2103 * ha = adapter block pointer.
2110 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2113 fc_port_t *fcport, *fcptemp;
2114 uint16_t next_loopid;
2115 uint16_t mb[MAILBOX_REGISTER_COUNT];
2117 LIST_HEAD(new_fcports);
2119 /* If FL port exists, then SNS is present */
2120 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
2121 loop_id = NPH_F_PORT;
2123 loop_id = SNS_FL_PORT;
2124 rval = qla2x00_get_port_name(ha, loop_id, NULL, 0);
2125 if (rval != QLA_SUCCESS) {
2126 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2127 "Port\n", ha->host_no));
2129 ha->device_flags &= ~SWITCH_FOUND;
2130 return (QLA_SUCCESS);
2133 /* Mark devices that need re-synchronization. */
2134 rval2 = qla2x00_device_resync(ha);
2135 if (rval2 == QLA_RSCNS_HANDLED) {
2136 /* No point doing the scan, just continue. */
2137 return (QLA_SUCCESS);
2141 if (ql2xfdmienable &&
2142 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2143 qla2x00_fdmi_register(ha);
2145 /* Ensure we are logged into the SNS. */
2146 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
2149 loop_id = SIMPLE_NAME_SERVER;
2150 ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
2151 0xfc, mb, BIT_1 | BIT_0);
2152 if (mb[0] != MBS_COMMAND_COMPLETE) {
2153 DEBUG2(qla_printk(KERN_INFO, ha,
2154 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2155 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2156 mb[0], mb[1], mb[2], mb[6], mb[7]));
2157 return (QLA_SUCCESS);
2160 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2161 if (qla2x00_rft_id(ha)) {
2163 DEBUG2(printk("scsi(%ld): Register FC-4 "
2164 "TYPE failed.\n", ha->host_no));
2166 if (qla2x00_rff_id(ha)) {
2168 DEBUG2(printk("scsi(%ld): Register FC-4 "
2169 "Features failed.\n", ha->host_no));
2171 if (qla2x00_rnn_id(ha)) {
2173 DEBUG2(printk("scsi(%ld): Register Node Name "
2174 "failed.\n", ha->host_no));
2175 } else if (qla2x00_rsnn_nn(ha)) {
2177 DEBUG2(printk("scsi(%ld): Register Symbolic "
2178 "Node Name failed.\n", ha->host_no));
2182 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2183 if (rval != QLA_SUCCESS)
2187 * Logout all previous fabric devices marked lost, except
2190 list_for_each_entry(fcport, &ha->fcports, list) {
2191 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2194 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2197 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2198 qla2x00_mark_device_lost(ha, fcport,
2199 ql2xplogiabsentdevice);
2200 if (fcport->loop_id != FC_NO_LOOP_ID &&
2201 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2202 fcport->port_type != FCT_INITIATOR &&
2203 fcport->port_type != FCT_BROADCAST) {
2205 ha->isp_ops.fabric_logout(ha,
2207 fcport->d_id.b.domain,
2208 fcport->d_id.b.area,
2209 fcport->d_id.b.al_pa);
2210 fcport->loop_id = FC_NO_LOOP_ID;
2215 /* Starting free loop ID. */
2216 next_loopid = ha->min_external_loopid;
2219 * Scan through our port list and login entries that need to be
2222 list_for_each_entry(fcport, &ha->fcports, list) {
2223 if (atomic_read(&ha->loop_down_timer) ||
2224 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2227 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2228 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2231 if (fcport->loop_id == FC_NO_LOOP_ID) {
2232 fcport->loop_id = next_loopid;
2233 rval = qla2x00_find_new_loop_id(ha, fcport);
2234 if (rval != QLA_SUCCESS) {
2235 /* Ran out of IDs to use */
2239 /* Login and update database */
2240 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2243 /* Exit if out of loop IDs. */
2244 if (rval != QLA_SUCCESS) {
2249 * Login and add the new devices to our port list.
2251 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2252 if (atomic_read(&ha->loop_down_timer) ||
2253 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2256 /* Find a new loop ID to use. */
2257 fcport->loop_id = next_loopid;
2258 rval = qla2x00_find_new_loop_id(ha, fcport);
2259 if (rval != QLA_SUCCESS) {
2260 /* Ran out of IDs to use */
2264 /* Remove device from the new list and add it to DB */
2265 list_del(&fcport->list);
2266 list_add_tail(&fcport->list, &ha->fcports);
2268 /* Login and update database */
2269 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2273 /* Free all new device structures not processed. */
2274 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2275 list_del(&fcport->list);
2280 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2281 "rval=%d\n", ha->host_no, rval));
2289 * qla2x00_find_all_fabric_devs
2292 * ha = adapter block pointer.
2293 * dev = database device entry pointer.
2302 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2306 fc_port_t *fcport, *new_fcport, *fcptemp;
2311 int first_dev, last_dev;
2312 port_id_t wrap, nxt_d_id;
2316 /* Try GID_PT to get device list, else GAN. */
2317 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2320 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2321 "on GA_NXT\n", ha->host_no));
2323 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2324 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2327 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2330 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2337 /* Allocate temporary fcport for any new fcports discovered. */
2338 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2339 if (new_fcport == NULL) {
2342 return (QLA_MEMORY_ALLOC_FAILED);
2344 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2346 /* Set start port ID scan at adapter ID. */
2350 /* Starting free loop ID. */
2351 loop_id = ha->min_external_loopid;
2352 for (; loop_id <= ha->last_loop_id; loop_id++) {
2353 if (qla2x00_is_reserved_id(ha, loop_id))
2356 if (atomic_read(&ha->loop_down_timer) ||
2357 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2362 wrap.b24 = new_fcport->d_id.b24;
2364 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2365 memcpy(new_fcport->node_name,
2366 swl[swl_idx].node_name, WWN_SIZE);
2367 memcpy(new_fcport->port_name,
2368 swl[swl_idx].port_name, WWN_SIZE);
2370 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2376 /* Send GA_NXT to the switch */
2377 rval = qla2x00_ga_nxt(ha, new_fcport);
2378 if (rval != QLA_SUCCESS) {
2379 qla_printk(KERN_WARNING, ha,
2380 "SNS scan failed -- assuming zero-entry "
2382 list_for_each_entry_safe(fcport, fcptemp,
2383 new_fcports, list) {
2384 list_del(&fcport->list);
2392 /* If wrap on switch device list, exit. */
2394 wrap.b24 = new_fcport->d_id.b24;
2396 } else if (new_fcport->d_id.b24 == wrap.b24) {
2397 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2398 ha->host_no, new_fcport->d_id.b.domain,
2399 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2403 /* Bypass if host adapter. */
2404 if (new_fcport->d_id.b24 == ha->d_id.b24)
2407 /* Bypass if same domain and area of adapter. */
2408 if (((new_fcport->d_id.b24 & 0xffff00) ==
2409 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2413 /* Bypass reserved domain fields. */
2414 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2417 /* Locate matching device in database. */
2419 list_for_each_entry(fcport, &ha->fcports, list) {
2420 if (memcmp(new_fcport->port_name, fcport->port_name,
2427 * If address the same and state FCS_ONLINE, nothing
2430 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2431 atomic_read(&fcport->state) == FCS_ONLINE) {
2436 * If device was not a fabric device before.
2438 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2439 fcport->d_id.b24 = new_fcport->d_id.b24;
2440 fcport->loop_id = FC_NO_LOOP_ID;
2441 fcport->flags |= (FCF_FABRIC_DEVICE |
2443 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2448 * Port ID changed or device was marked to be updated;
2449 * Log it out if still logged in and mark it for
2452 fcport->d_id.b24 = new_fcport->d_id.b24;
2453 fcport->flags |= FCF_LOGIN_NEEDED;
2454 if (fcport->loop_id != FC_NO_LOOP_ID &&
2455 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2456 fcport->port_type != FCT_INITIATOR &&
2457 fcport->port_type != FCT_BROADCAST) {
2458 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2459 fcport->d_id.b.domain, fcport->d_id.b.area,
2460 fcport->d_id.b.al_pa);
2461 fcport->loop_id = FC_NO_LOOP_ID;
2470 /* If device was not in our fcports list, then add it. */
2471 list_add_tail(&new_fcport->list, new_fcports);
2473 /* Allocate a new replacement fcport. */
2474 nxt_d_id.b24 = new_fcport->d_id.b24;
2475 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2476 if (new_fcport == NULL) {
2479 return (QLA_MEMORY_ALLOC_FAILED);
2481 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2482 new_fcport->d_id.b24 = nxt_d_id.b24;
2491 if (!list_empty(new_fcports))
2492 ha->device_flags |= DFLG_FABRIC_DEVICES;
2498 * qla2x00_find_new_loop_id
2499 * Scan through our port list and find a new usable loop ID.
2502 * ha: adapter state pointer.
2503 * dev: port structure pointer.
2506 * qla2x00 local function return status code.
2512 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2517 uint16_t first_loop_id;
2521 /* Save starting loop ID. */
2522 first_loop_id = dev->loop_id;
2525 /* Skip loop ID if already used by adapter. */
2526 if (dev->loop_id == ha->loop_id) {
2530 /* Skip reserved loop IDs. */
2531 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2535 /* Reset loop ID if passed the end. */
2536 if (dev->loop_id > ha->last_loop_id) {
2537 /* first loop ID. */
2538 dev->loop_id = ha->min_external_loopid;
2541 /* Check for loop ID being already in use. */
2544 list_for_each_entry(fcport, &ha->fcports, list) {
2545 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2546 /* ID possibly in use */
2552 /* If not in use then it is free to use. */
2557 /* ID in use. Try next value. */
2560 /* If wrap around. No free ID to use. */
2561 if (dev->loop_id == first_loop_id) {
2562 dev->loop_id = FC_NO_LOOP_ID;
2563 rval = QLA_FUNCTION_FAILED;
2572 * qla2x00_device_resync
2573 * Marks devices in the database that needs resynchronization.
2576 * ha = adapter block pointer.
2582 qla2x00_device_resync(scsi_qla_host_t *ha)
2588 uint32_t rscn_entry;
2589 uint8_t rscn_out_iter;
2593 rval = QLA_RSCNS_HANDLED;
2595 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2596 ha->flags.rscn_queue_overflow) {
2598 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2599 format = MSB(MSW(rscn_entry));
2600 d_id.b.domain = LSB(MSW(rscn_entry));
2601 d_id.b.area = MSB(LSW(rscn_entry));
2602 d_id.b.al_pa = LSB(LSW(rscn_entry));
2604 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2605 "[%02x/%02x%02x%02x].\n",
2606 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2607 d_id.b.area, d_id.b.al_pa));
2610 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2611 ha->rscn_out_ptr = 0;
2613 /* Skip duplicate entries. */
2614 for (rscn_out_iter = ha->rscn_out_ptr;
2615 !ha->flags.rscn_queue_overflow &&
2616 rscn_out_iter != ha->rscn_in_ptr;
2617 rscn_out_iter = (rscn_out_iter ==
2618 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2620 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2623 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2624 "entry found at [%d].\n", ha->host_no,
2627 ha->rscn_out_ptr = rscn_out_iter;
2630 /* Queue overflow, set switch default case. */
2631 if (ha->flags.rscn_queue_overflow) {
2632 DEBUG(printk("scsi(%ld): device_resync: rscn "
2633 "overflow.\n", ha->host_no));
2636 ha->flags.rscn_queue_overflow = 0;
2641 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) &&
2642 !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
2643 !IS_QLA24XX(ha) && !IS_QLA25XX(ha) &&
2644 ha->flags.init_done) {
2645 /* Handle port RSCN via asyncronous IOCBs */
2646 rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
2648 if (rval2 == QLA_SUCCESS)
2662 ha->rscn_out_ptr = ha->rscn_in_ptr;
2668 /* Abort any outstanding IO descriptors. */
2669 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2670 qla2x00_cancel_io_descriptors(ha);
2672 list_for_each_entry(fcport, &ha->fcports, list) {
2673 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2674 (fcport->d_id.b24 & mask) != d_id.b24 ||
2675 fcport->port_type == FCT_BROADCAST)
2678 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2680 fcport->port_type != FCT_INITIATOR) {
2681 qla2x00_mark_device_lost(ha, fcport, 0);
2684 fcport->flags &= ~FCF_FARP_DONE;
2691 * qla2x00_fabric_dev_login
2692 * Login fabric target device and update FC port database.
2695 * ha: adapter state pointer.
2696 * fcport: port structure list pointer.
2697 * next_loopid: contains value of a new loop ID that can be used
2698 * by the next login attempt.
2701 * qla2x00 local function return status code.
2707 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2708 uint16_t *next_loopid)
2717 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2718 if (rval == QLA_SUCCESS) {
2719 /* Send an ADISC to tape devices.*/
2721 if (fcport->flags & FCF_TAPE_PRESENT)
2723 rval = qla2x00_get_port_database(ha, fcport, opts);
2724 if (rval != QLA_SUCCESS) {
2725 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2726 fcport->d_id.b.domain, fcport->d_id.b.area,
2727 fcport->d_id.b.al_pa);
2728 qla2x00_mark_device_lost(ha, fcport, 1);
2731 qla2x00_update_fcport(ha, fcport);
2739 * qla2x00_fabric_login
2740 * Issue fabric login command.
2743 * ha = adapter block pointer.
2744 * device = pointer to FC device type structure.
2747 * 0 - Login successfully
2749 * 2 - Initiator device
2753 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2754 uint16_t *next_loopid)
2758 uint16_t tmp_loopid;
2759 uint16_t mb[MAILBOX_REGISTER_COUNT];
2765 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2766 "for port %02x%02x%02x.\n",
2767 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2768 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2770 /* Login fcport on switch. */
2771 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2772 fcport->d_id.b.domain, fcport->d_id.b.area,
2773 fcport->d_id.b.al_pa, mb, BIT_0);
2774 if (mb[0] == MBS_PORT_ID_USED) {
2776 * Device has another loop ID. The firmware team
2777 * recommends the driver perform an implicit login with
2778 * the specified ID again. The ID we just used is save
2779 * here so we return with an ID that can be tried by
2783 tmp_loopid = fcport->loop_id;
2784 fcport->loop_id = mb[1];
2786 DEBUG(printk("Fabric Login: port in use - next "
2787 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2788 fcport->loop_id, fcport->d_id.b.domain,
2789 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2791 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2796 /* A retry occurred before. */
2797 *next_loopid = tmp_loopid;
2800 * No retry occurred before. Just increment the
2801 * ID value for next login.
2803 *next_loopid = (fcport->loop_id + 1);
2806 if (mb[1] & BIT_0) {
2807 fcport->port_type = FCT_INITIATOR;
2809 fcport->port_type = FCT_TARGET;
2810 if (mb[1] & BIT_1) {
2811 fcport->flags |= FCF_TAPE_PRESENT;
2816 fcport->supported_classes |= FC_COS_CLASS2;
2818 fcport->supported_classes |= FC_COS_CLASS3;
2822 } else if (mb[0] == MBS_LOOP_ID_USED) {
2824 * Loop ID already used, try next loop ID.
2827 rval = qla2x00_find_new_loop_id(ha, fcport);
2828 if (rval != QLA_SUCCESS) {
2829 /* Ran out of loop IDs to use */
2832 } else if (mb[0] == MBS_COMMAND_ERROR) {
2834 * Firmware possibly timed out during login. If NO
2835 * retries are left to do then the device is declared
2838 *next_loopid = fcport->loop_id;
2839 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2840 fcport->d_id.b.domain, fcport->d_id.b.area,
2841 fcport->d_id.b.al_pa);
2842 qla2x00_mark_device_lost(ha, fcport, 1);
2848 * unrecoverable / not handled error
2850 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2851 "loop_id=%x jiffies=%lx.\n",
2852 __func__, ha->host_no, mb[0],
2853 fcport->d_id.b.domain, fcport->d_id.b.area,
2854 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2856 *next_loopid = fcport->loop_id;
2857 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2858 fcport->d_id.b.domain, fcport->d_id.b.area,
2859 fcport->d_id.b.al_pa);
2860 fcport->loop_id = FC_NO_LOOP_ID;
2861 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
2872 * qla2x00_local_device_login
2873 * Issue local device login command.
2876 * ha = adapter block pointer.
2877 * loop_id = loop id of device to login to.
2879 * Returns (Where's the #define!!!!):
2880 * 0 - Login successfully
2885 qla2x00_local_device_login(scsi_qla_host_t *ha, uint16_t loop_id)
2888 uint16_t mb[MAILBOX_REGISTER_COUNT];
2890 memset(mb, 0, sizeof(mb));
2891 rval = qla2x00_login_local_device(ha, loop_id, mb, BIT_0);
2892 if (rval == QLA_SUCCESS) {
2893 /* Interrogate mailbox registers for any errors */
2894 if (mb[0] == MBS_COMMAND_ERROR)
2896 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
2897 /* device not in PCB table */
2905 * qla2x00_loop_resync
2906 * Resync with fibre channel devices.
2909 * ha = adapter block pointer.
2915 qla2x00_loop_resync(scsi_qla_host_t *ha)
2922 atomic_set(&ha->loop_state, LOOP_UPDATE);
2923 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2924 if (ha->flags.online) {
2925 if (!(rval = qla2x00_fw_ready(ha))) {
2926 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2929 atomic_set(&ha->loop_state, LOOP_UPDATE);
2931 /* Issue a marker after FW becomes ready. */
2932 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
2933 ha->marker_needed = 0;
2935 /* Remap devices on Loop. */
2936 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2938 qla2x00_configure_loop(ha);
2940 } while (!atomic_read(&ha->loop_down_timer) &&
2941 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
2943 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
2947 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2948 return (QLA_FUNCTION_FAILED);
2952 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
2959 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
2965 list_for_each_entry(fcport, &ha->fcports, list) {
2966 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
2969 qla2x00_update_fcport(ha, fcport);
2970 fcport->flags &= ~FCF_RESCAN_NEEDED;
2974 qla2x00_probe_for_all_luns(ha);
2979 * Resets ISP and aborts all outstanding commands.
2982 * ha = adapter block pointer.
2988 qla2x00_abort_isp(scsi_qla_host_t *ha)
2990 unsigned long flags = 0;
2995 if (ha->flags.online) {
2996 ha->flags.online = 0;
2997 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2999 qla_printk(KERN_INFO, ha,
3000 "Performing ISP error recovery - ha= %p.\n", ha);
3001 ha->isp_ops.reset_chip(ha);
3003 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3004 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3005 atomic_set(&ha->loop_state, LOOP_DOWN);
3006 qla2x00_mark_all_devices_lost(ha);
3008 if (!atomic_read(&ha->loop_down_timer))
3009 atomic_set(&ha->loop_down_timer,
3013 spin_lock_irqsave(&ha->hardware_lock, flags);
3014 /* Requeue all commands in outstanding command list. */
3015 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3016 sp = ha->outstanding_cmds[cnt];
3018 ha->outstanding_cmds[cnt] = NULL;
3020 sp->cmd->result = DID_RESET << 16;
3021 sp->cmd->host_scribble = (unsigned char *)NULL;
3022 qla2x00_sp_compl(ha, sp);
3025 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3027 ha->isp_ops.nvram_config(ha);
3029 if (!qla2x00_restart_isp(ha)) {
3030 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3032 if (!atomic_read(&ha->loop_down_timer)) {
3034 * Issue marker command only when we are going
3035 * to start the I/O .
3037 ha->marker_needed = 1;
3040 ha->flags.online = 1;
3042 ha->isp_ops.enable_intrs(ha);
3044 ha->isp_abort_cnt = 0;
3045 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3046 } else { /* failed the ISP abort */
3047 ha->flags.online = 1;
3048 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3049 if (ha->isp_abort_cnt == 0) {
3050 qla_printk(KERN_WARNING, ha,
3051 "ISP error recovery failed - "
3052 "board disabled\n");
3054 * The next call disables the board
3057 ha->isp_ops.reset_adapter(ha);
3058 ha->flags.online = 0;
3059 clear_bit(ISP_ABORT_RETRY,
3062 } else { /* schedule another ISP abort */
3063 ha->isp_abort_cnt--;
3064 DEBUG(printk("qla%ld: ISP abort - "
3065 "retry remaining %d\n",
3066 ha->host_no, ha->isp_abort_cnt);)
3070 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3071 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3072 "- retrying (%d) more times\n",
3073 ha->host_no, ha->isp_abort_cnt);)
3074 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3082 qla_printk(KERN_INFO, ha,
3083 "qla2x00_abort_isp: **** FAILED ****\n");
3085 DEBUG(printk(KERN_INFO
3086 "qla2x00_abort_isp(%ld): exiting.\n",
3094 * qla2x00_restart_isp
3095 * restarts the ISP after a reset
3098 * ha = adapter block pointer.
3104 qla2x00_restart_isp(scsi_qla_host_t *ha)
3107 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3108 unsigned long flags = 0;
3111 /* If firmware needs to be loaded */
3112 if (qla2x00_isp_firmware(ha)) {
3113 ha->flags.online = 0;
3114 if (!(status = ha->isp_ops.chip_diag(ha))) {
3115 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3116 status = qla2x00_setup_chip(ha);
3120 spin_lock_irqsave(&ha->hardware_lock, flags);
3122 if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha)) {
3124 * Disable SRAM, Instruction RAM and GP RAM
3127 WRT_REG_WORD(®->hccr,
3128 (HCCR_ENABLE_PARITY + 0x0));
3129 RD_REG_WORD(®->hccr);
3132 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3134 status = qla2x00_setup_chip(ha);
3136 spin_lock_irqsave(&ha->hardware_lock, flags);
3138 if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha)) {
3139 /* Enable proper parity */
3142 WRT_REG_WORD(®->hccr,
3143 (HCCR_ENABLE_PARITY + 0x1));
3146 * SRAM, Instruction RAM and GP RAM
3149 WRT_REG_WORD(®->hccr,
3150 (HCCR_ENABLE_PARITY + 0x7));
3151 RD_REG_WORD(®->hccr);
3154 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3159 if (!status && !(status = qla2x00_init_rings(ha))) {
3160 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3161 if (!(status = qla2x00_fw_ready(ha))) {
3162 DEBUG(printk("%s(): Start configure loop, "
3163 "status = %d\n", __func__, status);)
3165 /* Issue a marker after FW becomes ready. */
3166 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3168 ha->flags.online = 1;
3169 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3172 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3173 qla2x00_configure_loop(ha);
3175 } while (!atomic_read(&ha->loop_down_timer) &&
3176 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3178 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3181 /* if no cable then assume it's good */
3182 if ((ha->device_flags & DFLG_NO_CABLE))
3185 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3193 * qla2x00_reset_adapter
3197 * ha = adapter block pointer.
3200 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3202 unsigned long flags = 0;
3203 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3205 ha->flags.online = 0;
3206 ha->isp_ops.disable_intrs(ha);
3208 spin_lock_irqsave(&ha->hardware_lock, flags);
3209 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3210 RD_REG_WORD(®->hccr); /* PCI Posting. */
3211 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3212 RD_REG_WORD(®->hccr); /* PCI Posting. */
3213 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3217 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3219 unsigned long flags = 0;
3220 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3222 ha->flags.online = 0;
3223 ha->isp_ops.disable_intrs(ha);
3225 spin_lock_irqsave(&ha->hardware_lock, flags);
3226 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3227 RD_REG_DWORD(®->hccr);
3228 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3229 RD_REG_DWORD(®->hccr);
3230 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3234 qla24xx_nvram_config(scsi_qla_host_t *ha)
3237 struct init_cb_24xx *icb;
3238 struct nvram_24xx *nv;
3240 uint8_t *dptr1, *dptr2;
3245 icb = (struct init_cb_24xx *)ha->init_cb;
3246 nv = (struct nvram_24xx *)ha->request_ring;
3248 /* Determine NVRAM starting address. */
3249 ha->nvram_size = sizeof(struct nvram_24xx);
3250 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3251 if (PCI_FUNC(ha->pdev->devfn))
3252 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3254 /* Get NVRAM data and calculate checksum. */
3255 dptr = (uint32_t *)nv;
3256 ha->isp_ops.read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3258 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3259 chksum += le32_to_cpu(*dptr++);
3261 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3262 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3265 /* Bad NVRAM data, set defaults parameters. */
3266 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3267 || nv->id[3] != ' ' ||
3268 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3269 /* Reset NVRAM data. */
3270 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3271 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3272 le16_to_cpu(nv->nvram_version));
3273 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3274 "invalid -- WWPN) defaults.\n");
3277 * Set default initialization control block.
3279 memset(nv, 0, ha->nvram_size);
3280 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3281 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3282 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3283 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3284 nv->exchange_count = __constant_cpu_to_le16(0);
3285 nv->hard_address = __constant_cpu_to_le16(124);
3286 nv->port_name[0] = 0x21;
3287 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3288 nv->port_name[2] = 0x00;
3289 nv->port_name[3] = 0xe0;
3290 nv->port_name[4] = 0x8b;
3291 nv->port_name[5] = 0x1c;
3292 nv->port_name[6] = 0x55;
3293 nv->port_name[7] = 0x86;
3294 nv->node_name[0] = 0x20;
3295 nv->node_name[1] = 0x00;
3296 nv->node_name[2] = 0x00;
3297 nv->node_name[3] = 0xe0;
3298 nv->node_name[4] = 0x8b;
3299 nv->node_name[5] = 0x1c;
3300 nv->node_name[6] = 0x55;
3301 nv->node_name[7] = 0x86;
3302 nv->login_retry_count = __constant_cpu_to_le16(8);
3303 nv->link_down_timeout = __constant_cpu_to_le16(200);
3304 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3305 nv->login_timeout = __constant_cpu_to_le16(0);
3306 nv->firmware_options_1 =
3307 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3308 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3309 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3310 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3311 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3312 nv->efi_parameters = __constant_cpu_to_le32(0);
3313 nv->reset_delay = 5;
3314 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3315 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3316 nv->link_down_timeout = __constant_cpu_to_le16(30);
3321 /* Reset Initialization control block */
3322 memset(icb, 0, sizeof(struct init_cb_24xx));
3324 /* Copy 1st segment. */
3325 dptr1 = (uint8_t *)icb;
3326 dptr2 = (uint8_t *)&nv->version;
3327 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3329 *dptr1++ = *dptr2++;
3331 icb->login_retry_count = nv->login_retry_count;
3332 icb->link_down_timeout = nv->link_down_timeout;
3334 /* Copy 2nd segment. */
3335 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3336 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3337 cnt = (uint8_t *)&icb->reserved_3 -
3338 (uint8_t *)&icb->interrupt_delay_timer;
3340 *dptr1++ = *dptr2++;
3343 * Setup driver NVRAM options.
3345 if (memcmp(nv->model_name, BINZERO, sizeof(nv->model_name)) != 0) {
3349 strncpy(ha->model_number, nv->model_name,
3350 sizeof(nv->model_name));
3351 st = en = ha->model_number;
3352 en += sizeof(nv->model_name) - 1;
3354 if (*en != 0x20 && *en != 0x00)
3359 index = (ha->pdev->subsystem_device & 0xff);
3360 if (index < QLA_MODEL_NAMES)
3361 ha->model_desc = qla2x00_model_desc[index];
3363 strcpy(ha->model_number, "QLA2462");
3365 /* Prepare nodename */
3366 if ((icb->firmware_options_1 & BIT_14) == 0) {
3368 * Firmware will apply the following mask if the nodename was
3371 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3372 icb->node_name[0] &= 0xF0;
3375 /* Set host adapter parameters. */
3376 ha->flags.disable_risc_code_load = 0;
3377 ha->flags.enable_lip_reset = 1;
3378 ha->flags.enable_lip_full_login = 1;
3379 ha->flags.enable_target_reset = 1;
3380 ha->flags.enable_led_scheme = 0;
3382 ha->operating_mode =
3383 (icb->firmware_options_2 & (BIT_6 | BIT_5 | BIT_4)) >> 4;
3385 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3386 sizeof(ha->fw_seriallink_options24));
3388 /* save HBA serial number */
3389 ha->serial0 = icb->port_name[5];
3390 ha->serial1 = icb->port_name[6];
3391 ha->serial2 = icb->port_name[7];
3392 ha->node_name = icb->node_name;
3393 ha->port_name = icb->port_name;
3395 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3397 /* Set minimum login_timeout to 4 seconds. */
3398 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3399 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3400 if (le16_to_cpu(nv->login_timeout) < 4)
3401 nv->login_timeout = __constant_cpu_to_le16(4);
3402 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3403 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3405 /* Set minimum RATOV to 200 tenths of a second. */
3408 ha->loop_reset_delay = nv->reset_delay;
3410 /* Link Down Timeout = 0:
3412 * When Port Down timer expires we will start returning
3413 * I/O's to OS with "DID_NO_CONNECT".
3415 * Link Down Timeout != 0:
3417 * The driver waits for the link to come up after link down
3418 * before returning I/Os to OS with "DID_NO_CONNECT".
3420 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3421 ha->loop_down_abort_time =
3422 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3424 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3425 ha->loop_down_abort_time =
3426 (LOOP_DOWN_TIME - ha->link_down_timeout);
3429 /* Need enough time to try and get the port back. */
3430 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3431 if (qlport_down_retry)
3432 ha->port_down_retry_count = qlport_down_retry;
3434 /* Set login_retry_count */
3435 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3436 if (ha->port_down_retry_count ==
3437 le16_to_cpu(nv->port_down_retry_count) &&
3438 ha->port_down_retry_count > 3)
3439 ha->login_retry_count = ha->port_down_retry_count;
3440 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3441 ha->login_retry_count = ha->port_down_retry_count;
3442 if (ql2xloginretrycount)
3443 ha->login_retry_count = ql2xloginretrycount;
3446 DEBUG2_3(printk(KERN_WARNING
3447 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3453 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3457 uint16_t *risc_code;
3458 unsigned long risc_address;
3459 unsigned long risc_code_size;
3463 struct qla_fw_info *fw_iter;
3467 /* Load firmware sequences */
3468 fw_iter = ha->brd_info->fw_info;
3469 *srisc_addr = *ha->brd_info->fw_info->fwstart;
3470 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
3471 risc_code = fw_iter->fwcode;
3472 risc_code_size = *fw_iter->fwlen;
3474 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
3475 risc_address = *fw_iter->fwstart;
3477 /* Extended address */
3478 risc_address = *fw_iter->lfwstart;
3483 while (risc_code_size > 0 && !rval) {
3484 cnt = (uint16_t)(ha->fw_transfer_size >> 1);
3485 if (cnt > risc_code_size)
3486 cnt = risc_code_size;
3488 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
3489 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
3490 ha->host_no, risc_code, cnt, risc_address));
3492 req_ring = (uint16_t *)ha->request_ring;
3493 for (i = 0; i < cnt; i++)
3494 req_ring[i] = cpu_to_le16(risc_code[i]);
3496 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
3497 rval = qla2x00_load_ram(ha, ha->request_dma,
3500 rval = qla2x00_load_ram_ext(ha,
3501 ha->request_dma, risc_address, cnt);
3504 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
3505 "load segment %d of firmware\n",
3507 qla_printk(KERN_WARNING, ha,
3508 "[ERROR] Failed to load segment %d of "
3511 qla2x00_dump_regs(ha);
3516 risc_address += cnt;
3517 risc_code_size -= cnt;
3521 /* Next firmware sequence */
3529 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3532 int segments, fragment;
3534 uint32_t *dcode, dlen;
3541 segments = FA_RISC_CODE_SEGMENTS;
3542 faddr = FA_RISC_CODE_ADDR;
3543 dcode = (uint32_t *)ha->request_ring;
3546 /* Validate firmware image by checking version. */
3547 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3548 for (i = 0; i < 4; i++)
3549 dcode[i] = be32_to_cpu(dcode[i]);
3550 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3551 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3552 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3554 qla_printk(KERN_WARNING, ha,
3555 "Unable to verify integrity of flash firmware image!\n");
3556 qla_printk(KERN_WARNING, ha,
3557 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3558 dcode[1], dcode[2], dcode[3]);
3560 return QLA_FUNCTION_FAILED;
3563 while (segments && rval == QLA_SUCCESS) {
3564 /* Read segment's load information. */
3565 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3567 risc_addr = be32_to_cpu(dcode[2]);
3568 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3569 risc_size = be32_to_cpu(dcode[3]);
3572 while (risc_size > 0 && rval == QLA_SUCCESS) {
3573 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3574 if (dlen > risc_size)
3577 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3578 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3579 ha->host_no, risc_addr, dlen, faddr));
3581 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3582 for (i = 0; i < dlen; i++)
3583 dcode[i] = swab32(dcode[i]);
3585 rval = qla2x00_load_ram_ext(ha, ha->request_dma,
3588 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3589 "segment %d of firmware\n", ha->host_no,
3591 qla_printk(KERN_WARNING, ha,
3592 "[ERROR] Failed to load segment %d of "
3593 "firmware\n", fragment);
3611 qla24xx_load_risc_hotplug(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3614 int segments, fragment;
3615 uint32_t *dcode, dlen;
3619 const struct firmware *fw_entry;
3620 uint32_t *fwcode, fwclen;
3622 if (request_firmware(&fw_entry, ha->brd_info->fw_fname,
3624 qla_printk(KERN_ERR, ha,
3625 "Firmware image file not available: '%s'\n",
3626 ha->brd_info->fw_fname);
3627 return QLA_FUNCTION_FAILED;
3632 segments = FA_RISC_CODE_SEGMENTS;
3633 dcode = (uint32_t *)ha->request_ring;
3635 fwcode = (uint32_t *)fw_entry->data;
3638 /* Validate firmware image by checking version. */
3639 if (fw_entry->size < 8 * sizeof(uint32_t)) {
3640 qla_printk(KERN_WARNING, ha,
3641 "Unable to verify integrity of flash firmware image "
3642 "(%Zd)!\n", fw_entry->size);
3643 goto fail_fw_integrity;
3645 for (i = 0; i < 4; i++)
3646 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3647 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3648 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3649 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3651 qla_printk(KERN_WARNING, ha,
3652 "Unable to verify integrity of flash firmware image!\n");
3653 qla_printk(KERN_WARNING, ha,
3654 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3655 dcode[1], dcode[2], dcode[3]);
3656 goto fail_fw_integrity;
3659 while (segments && rval == QLA_SUCCESS) {
3660 risc_addr = be32_to_cpu(fwcode[2]);
3661 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3662 risc_size = be32_to_cpu(fwcode[3]);
3664 /* Validate firmware image size. */
3665 fwclen += risc_size * sizeof(uint32_t);
3666 if (fw_entry->size < fwclen) {
3667 qla_printk(KERN_WARNING, ha,
3668 "Unable to verify integrity of flash firmware "
3669 "image (%Zd)!\n", fw_entry->size);
3670 goto fail_fw_integrity;
3674 while (risc_size > 0 && rval == QLA_SUCCESS) {
3675 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3676 if (dlen > risc_size)
3679 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3680 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3683 for (i = 0; i < dlen; i++)
3684 dcode[i] = swab32(fwcode[i]);
3686 rval = qla2x00_load_ram_ext(ha, ha->request_dma,
3689 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3690 "segment %d of firmware\n", ha->host_no,
3692 qla_printk(KERN_WARNING, ha,
3693 "[ERROR] Failed to load segment %d of "
3694 "firmware\n", fragment);
3708 release_firmware(fw_entry);
3713 release_firmware(fw_entry);
3714 return QLA_FUNCTION_FAILED;