2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2004 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 <scsi/scsi_transport_fc.h>
24 #include "qla_devtbl.h"
26 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
27 #ifndef EXT_IS_LUN_BIT_SET
28 #define EXT_IS_LUN_BIT_SET(P,L) \
29 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
30 #define EXT_SET_LUN_BIT(P,L) \
31 ((P)->mask[L/8] |= (0x80 >> (L%8)))
35 * QLogic ISP2x00 Hardware Support Function Prototypes.
37 static int qla2x00_isp_firmware(scsi_qla_host_t *);
38 static void qla2x00_resize_request_q(scsi_qla_host_t *);
39 static int qla2x00_setup_chip(scsi_qla_host_t *);
40 static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
41 static int qla2x00_init_rings(scsi_qla_host_t *);
42 static int qla2x00_fw_ready(scsi_qla_host_t *);
43 static int qla2x00_configure_hba(scsi_qla_host_t *);
44 static int qla2x00_configure_loop(scsi_qla_host_t *);
45 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
46 static void qla2x00_update_fcport(scsi_qla_host_t *, fc_port_t *);
47 static int qla2x00_configure_fabric(scsi_qla_host_t *);
48 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
49 static int qla2x00_device_resync(scsi_qla_host_t *);
50 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
53 static int qla2x00_restart_isp(scsi_qla_host_t *);
55 /****************************************************************************/
56 /* QLogic ISP2x00 Hardware Support Functions. */
57 /****************************************************************************/
60 * qla2x00_initialize_adapter
64 * ha = adapter block pointer.
70 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
73 uint8_t restart_risc = 0;
77 /* Clear adapter flags. */
79 ha->flags.reset_active = 0;
80 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
81 atomic_set(&ha->loop_state, LOOP_DOWN);
84 ha->flags.management_server_logged_in = 0;
85 ha->marker_needed = 0;
87 ha->isp_abort_cnt = 0;
88 ha->beacon_blink_led = 0;
90 rval = ha->isp_ops.pci_config(ha);
92 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
97 ha->isp_ops.reset_chip(ha);
99 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
100 ha->isp_ops.nvram_config(ha);
102 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
106 * Try to configure the loop.
111 /* If firmware needs to be loaded */
112 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
113 if ((rval = ha->isp_ops.chip_diag(ha)) == QLA_SUCCESS) {
114 rval = qla2x00_setup_chip(ha);
118 if (rval == QLA_SUCCESS &&
119 (rval = qla2x00_init_rings(ha)) == QLA_SUCCESS) {
120 check_fw_ready_again:
122 * Wait for a successful LIP up to a maximum
123 * of (in seconds): RISC login timeout value,
124 * RISC retry count value, and port down retry
125 * value OR a minimum of 4 seconds OR If no
126 * cable, only 5 seconds.
128 rval = qla2x00_fw_ready(ha);
129 if (rval == QLA_SUCCESS) {
130 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
133 * Wait at most MAX_TARGET RSCNs for a stable
138 clear_bit(LOOP_RESYNC_NEEDED,
140 rval = qla2x00_configure_loop(ha);
142 if (test_and_clear_bit(ISP_ABORT_NEEDED,
149 * If loop state change while we were
150 * discoverying devices then wait for
154 if (atomic_read(&ha->loop_state) ==
155 LOOP_DOWN && retry--) {
156 goto check_fw_ready_again;
159 } while (!atomic_read(&ha->loop_down_timer) &&
162 (test_bit(LOOP_RESYNC_NEEDED,
166 rval = QLA_FUNCTION_FAILED;
167 } else if (ha->device_flags & DFLG_NO_CABLE)
168 /* If no cable, then all is good. */
171 } while (restart_risc && retry--);
173 if (rval == QLA_SUCCESS) {
174 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
175 ha->marker_needed = 1;
176 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
177 ha->marker_needed = 0;
179 ha->flags.online = 1;
181 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
188 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
191 * Returns 0 on success.
194 qla2100_pci_config(scsi_qla_host_t *ha)
198 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
200 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
202 pci_set_master(ha->pdev);
204 if (pci_set_mwi(ha->pdev))
205 mwi = PCI_COMMAND_INVALIDATE;
206 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
208 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
209 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
210 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
212 /* Reset expansion ROM address decode enable */
213 pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w);
214 w &= ~PCI_ROM_ADDRESS_ENABLE;
215 pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
217 /* Get PCI bus information. */
218 spin_lock_irqsave(&ha->hardware_lock, flags);
219 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
220 spin_unlock_irqrestore(&ha->hardware_lock, flags);
226 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
229 * Returns 0 on success.
232 qla2300_pci_config(scsi_qla_host_t *ha)
235 unsigned long flags = 0;
237 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
239 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
241 pci_set_master(ha->pdev);
243 if (pci_set_mwi(ha->pdev))
244 mwi = PCI_COMMAND_INVALIDATE;
245 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
247 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
248 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
250 if (IS_QLA2322(ha) || IS_QLA6322(ha))
251 w &= ~PCI_COMMAND_INTX_DISABLE;
254 * If this is a 2300 card and not 2312, reset the
255 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
256 * the 2310 also reports itself as a 2300 so we need to get the
257 * fb revision level -- a 6 indicates it really is a 2300 and
260 if (IS_QLA2300(ha)) {
261 spin_lock_irqsave(&ha->hardware_lock, flags);
264 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
265 for (cnt = 0; cnt < 30000; cnt++) {
266 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
272 /* Select FPM registers. */
273 WRT_REG_WORD(®->ctrl_status, 0x20);
274 RD_REG_WORD(®->ctrl_status);
276 /* Get the fb rev level */
277 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
279 if (ha->fb_rev == FPM_2300)
280 w &= ~PCI_COMMAND_INVALIDATE;
282 /* Deselect FPM registers. */
283 WRT_REG_WORD(®->ctrl_status, 0x0);
284 RD_REG_WORD(®->ctrl_status);
286 /* Release RISC module. */
287 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
288 for (cnt = 0; cnt < 30000; cnt++) {
289 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
295 spin_unlock_irqrestore(&ha->hardware_lock, flags);
297 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
299 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
301 /* Reset expansion ROM address decode enable */
302 pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w);
303 w &= ~PCI_ROM_ADDRESS_ENABLE;
304 pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
306 /* Get PCI bus information. */
307 spin_lock_irqsave(&ha->hardware_lock, flags);
308 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
309 spin_unlock_irqrestore(&ha->hardware_lock, flags);
315 * qla2x00_isp_firmware() - Choose firmware image.
318 * Returns 0 on success.
321 qla2x00_isp_firmware(scsi_qla_host_t *ha)
325 /* Assume loading risc code */
326 rval = QLA_FUNCTION_FAILED;
328 if (ha->flags.disable_risc_code_load) {
329 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
331 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
333 /* Verify checksum of loaded RISC code. */
334 rval = qla2x00_verify_checksum(ha,
335 IS_QLA24XX(ha) || IS_QLA25XX(ha) ? RISC_SADDRESS :
336 *ha->brd_info->fw_info[0].fwstart);
340 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
348 * qla2x00_reset_chip() - Reset ISP chip.
351 * Returns 0 on success.
354 qla2x00_reset_chip(scsi_qla_host_t *ha)
356 unsigned long flags = 0;
357 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
359 unsigned long mbx_flags = 0;
362 ha->isp_ops.disable_intrs(ha);
364 spin_lock_irqsave(&ha->hardware_lock, flags);
366 /* Turn off master enable */
368 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
369 cmd &= ~PCI_COMMAND_MASTER;
370 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
372 if (!IS_QLA2100(ha)) {
374 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
375 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
376 for (cnt = 0; cnt < 30000; cnt++) {
377 if ((RD_REG_WORD(®->hccr) &
378 HCCR_RISC_PAUSE) != 0)
383 RD_REG_WORD(®->hccr); /* PCI Posting. */
387 /* Select FPM registers. */
388 WRT_REG_WORD(®->ctrl_status, 0x20);
389 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
391 /* FPM Soft Reset. */
392 WRT_REG_WORD(®->fpm_diag_config, 0x100);
393 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
395 /* Toggle Fpm Reset. */
396 if (!IS_QLA2200(ha)) {
397 WRT_REG_WORD(®->fpm_diag_config, 0x0);
398 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
401 /* Select frame buffer registers. */
402 WRT_REG_WORD(®->ctrl_status, 0x10);
403 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
405 /* Reset frame buffer FIFOs. */
406 if (IS_QLA2200(ha)) {
407 WRT_FB_CMD_REG(ha, reg, 0xa000);
408 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
410 WRT_FB_CMD_REG(ha, reg, 0x00fc);
412 /* Read back fb_cmd until zero or 3 seconds max */
413 for (cnt = 0; cnt < 3000; cnt++) {
414 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
420 /* Select RISC module registers. */
421 WRT_REG_WORD(®->ctrl_status, 0);
422 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
424 /* Reset RISC processor. */
425 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
426 RD_REG_WORD(®->hccr); /* PCI Posting. */
428 /* Release RISC processor. */
429 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
430 RD_REG_WORD(®->hccr); /* PCI Posting. */
433 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
434 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
436 /* Reset ISP chip. */
437 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
439 /* Wait for RISC to recover from reset. */
440 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
442 * It is necessary to for a delay here since the card doesn't
443 * respond to PCI reads during a reset. On some architectures
444 * this will result in an MCA.
447 for (cnt = 30000; cnt; cnt--) {
448 if ((RD_REG_WORD(®->ctrl_status) &
449 CSR_ISP_SOFT_RESET) == 0)
456 /* Reset RISC processor. */
457 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
459 WRT_REG_WORD(®->semaphore, 0);
461 /* Release RISC processor. */
462 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
463 RD_REG_WORD(®->hccr); /* PCI Posting. */
465 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
466 for (cnt = 0; cnt < 30000; cnt++) {
467 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
468 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
470 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) {
471 if (!(test_bit(ABORT_ISP_ACTIVE,
473 spin_unlock_irqrestore(
474 &ha->mbx_reg_lock, mbx_flags);
478 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
479 spin_unlock_irqrestore(&ha->mbx_reg_lock,
487 /* Turn on master enable */
488 cmd |= PCI_COMMAND_MASTER;
489 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
491 /* Disable RISC pause on FPM parity error. */
492 if (!IS_QLA2100(ha)) {
493 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
494 RD_REG_WORD(®->hccr); /* PCI Posting. */
497 spin_unlock_irqrestore(&ha->hardware_lock, flags);
501 * qla2x00_chip_diag() - Test chip for proper operation.
504 * Returns 0 on success.
507 qla2x00_chip_diag(scsi_qla_host_t *ha)
510 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
511 unsigned long flags = 0;
516 /* Assume a failed state */
517 rval = QLA_FUNCTION_FAILED;
519 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
520 ha->host_no, (u_long)®->flash_address));
522 spin_lock_irqsave(&ha->hardware_lock, flags);
524 /* Reset ISP chip. */
525 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
528 * We need to have a delay here since the card will not respond while
529 * in reset causing an MCA on some architectures.
532 data = qla2x00_debounce_register(®->ctrl_status);
533 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
535 data = RD_REG_WORD(®->ctrl_status);
540 goto chip_diag_failed;
542 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
545 /* Reset RISC processor. */
546 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
547 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
549 /* Workaround for QLA2312 PCI parity error */
550 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
551 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
552 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
554 data = RD_MAILBOX_REG(ha, reg, 0);
561 goto chip_diag_failed;
563 /* Check product ID of chip */
564 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
566 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
567 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
568 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
569 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
570 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
571 mb[3] != PROD_ID_3) {
572 qla_printk(KERN_WARNING, ha,
573 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
575 goto chip_diag_failed;
577 ha->product_id[0] = mb[1];
578 ha->product_id[1] = mb[2];
579 ha->product_id[2] = mb[3];
580 ha->product_id[3] = mb[4];
582 /* Adjust fw RISC transfer size */
583 if (ha->request_q_length > 1024)
584 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
586 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
587 ha->request_q_length;
589 if (IS_QLA2200(ha) &&
590 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
591 /* Limit firmware transfer size with a 2200A */
592 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
595 ha->fw_transfer_size = 128;
598 /* Wrap Incoming Mailboxes Test. */
599 spin_unlock_irqrestore(&ha->hardware_lock, flags);
601 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
602 rval = qla2x00_mbx_reg_test(ha);
604 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
606 qla_printk(KERN_WARNING, ha,
607 "Failed mailbox send register test\n");
610 /* Flag a successful rval */
613 spin_lock_irqsave(&ha->hardware_lock, flags);
617 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
618 "****\n", ha->host_no));
620 spin_unlock_irqrestore(&ha->hardware_lock, flags);
626 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
629 * Returns 0 on success.
632 qla2x00_resize_request_q(scsi_qla_host_t *ha)
635 uint16_t fw_iocb_cnt = 0;
636 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
637 dma_addr_t request_dma;
638 request_t *request_ring;
640 /* Valid only on recent ISPs. */
641 if (IS_QLA2100(ha) || IS_QLA2200(ha))
644 /* Retrieve IOCB counts available to the firmware. */
645 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
648 /* No point in continuing if current settings are sufficient. */
649 if (fw_iocb_cnt < 1024)
651 if (ha->request_q_length >= request_q_length)
654 /* Attempt to claim larger area for request queue. */
655 request_ring = dma_alloc_coherent(&ha->pdev->dev,
656 (request_q_length + 1) * sizeof(request_t), &request_dma,
658 if (request_ring == NULL)
661 /* Resize successful, report extensions. */
662 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
663 (ha->fw_memory_size + 1) / 1024);
664 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
665 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
667 /* Clear old allocations. */
668 dma_free_coherent(&ha->pdev->dev,
669 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
672 /* Begin using larger queue. */
673 ha->request_q_length = request_q_length;
674 ha->request_ring = request_ring;
675 ha->request_dma = request_dma;
679 * qla2x00_setup_chip() - Load and start RISC firmware.
682 * Returns 0 on success.
685 qla2x00_setup_chip(scsi_qla_host_t *ha)
690 unsigned long risc_address;
691 unsigned long risc_code_size;
695 struct qla_fw_info *fw_iter;
699 /* Load firmware sequences */
700 fw_iter = ha->brd_info->fw_info;
701 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
702 risc_code = fw_iter->fwcode;
703 risc_code_size = *fw_iter->fwlen;
705 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
706 risc_address = *fw_iter->fwstart;
708 /* Extended address */
709 risc_address = *fw_iter->lfwstart;
714 while (risc_code_size > 0 && !rval) {
715 cnt = (uint16_t)(ha->fw_transfer_size >> 1);
716 if (cnt > risc_code_size)
717 cnt = risc_code_size;
719 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
720 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
721 ha->host_no, risc_code, cnt, risc_address));
723 req_ring = (uint16_t *)ha->request_ring;
724 for (i = 0; i < cnt; i++)
725 req_ring[i] = cpu_to_le16(risc_code[i]);
727 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
728 rval = qla2x00_load_ram(ha,
729 ha->request_dma, risc_address, cnt);
731 rval = qla2x00_load_ram_ext(ha,
732 ha->request_dma, risc_address, cnt);
735 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
736 "load segment %d of firmware\n",
738 qla_printk(KERN_WARNING, ha,
739 "[ERROR] Failed to load "
740 "segment %d of firmware\n", num);
742 qla2x00_dump_regs(ha);
748 risc_code_size -= cnt;
752 /* Next firmware sequence */
756 /* Verify checksum of loaded RISC code. */
758 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
759 "code.\n", ha->host_no));
761 rval = qla2x00_verify_checksum(ha,
762 IS_QLA24XX(ha) || IS_QLA25XX(ha) ? RISC_SADDRESS :
763 *ha->brd_info->fw_info[0].fwstart);
764 if (rval == QLA_SUCCESS) {
765 /* Start firmware execution. */
766 DEBUG(printk("scsi(%ld): Checksum OK, start "
767 "firmware.\n", ha->host_no));
769 rval = qla2x00_execute_fw(ha,
770 IS_QLA24XX(ha) || IS_QLA25XX(ha) ? RISC_SADDRESS :
771 *ha->brd_info->fw_info[0].fwstart);
772 /* Retrieve firmware information. */
773 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
774 qla2x00_get_fw_version(ha,
775 &ha->fw_major_version,
776 &ha->fw_minor_version,
777 &ha->fw_subminor_version,
778 &ha->fw_attributes, &ha->fw_memory_size);
779 qla2x00_resize_request_q(ha);
782 DEBUG2(printk(KERN_INFO
783 "scsi(%ld): ISP Firmware failed checksum.\n",
789 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
797 * qla2x00_init_response_q_entries() - Initializes response queue entries.
800 * Beginning of request ring has initialization control block already built
801 * by nvram config routine.
803 * Returns 0 on success.
806 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
811 pkt = ha->response_ring_ptr;
812 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
813 pkt->signature = RESPONSE_PROCESSED;
820 * qla2x00_update_fw_options() - Read and process firmware options.
823 * Returns 0 on success.
826 qla2x00_update_fw_options(scsi_qla_host_t *ha)
828 uint16_t swing, emphasis, tx_sens, rx_sens;
830 memset(ha->fw_options, 0, sizeof(ha->fw_options));
831 qla2x00_get_fw_options(ha, ha->fw_options);
833 if (IS_QLA2100(ha) || IS_QLA2200(ha))
836 /* Serial Link options. */
837 DEBUG3(printk("scsi(%ld): Serial link options:\n",
839 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
840 sizeof(ha->fw_seriallink_options)));
842 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
843 if (ha->fw_seriallink_options[3] & BIT_2) {
844 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
847 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
848 emphasis = (ha->fw_seriallink_options[2] &
849 (BIT_4 | BIT_3)) >> 3;
850 tx_sens = ha->fw_seriallink_options[0] &
851 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
852 rx_sens = (ha->fw_seriallink_options[0] &
853 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
854 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
855 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
858 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
859 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
860 ha->fw_options[10] |= BIT_5 |
861 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
862 (tx_sens & (BIT_1 | BIT_0));
865 swing = (ha->fw_seriallink_options[2] &
866 (BIT_7 | BIT_6 | BIT_5)) >> 5;
867 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
868 tx_sens = ha->fw_seriallink_options[1] &
869 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
870 rx_sens = (ha->fw_seriallink_options[1] &
871 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
872 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
873 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
876 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
877 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
878 ha->fw_options[11] |= BIT_5 |
879 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
880 (tx_sens & (BIT_1 | BIT_0));
884 /* Return command IOCBs without waiting for an ABTS to complete. */
885 ha->fw_options[3] |= BIT_13;
888 if (ha->flags.enable_led_scheme)
889 ha->fw_options[2] |= BIT_12;
891 /* Update firmware options. */
892 qla2x00_set_fw_options(ha, ha->fw_options);
896 qla2x00_config_rings(struct scsi_qla_host *ha)
898 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
900 /* Setup ring parameters in initialization control block. */
901 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
902 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
903 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
904 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
905 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
906 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
907 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
908 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
910 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
911 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
912 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
913 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
914 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
918 * qla2x00_init_rings() - Initializes firmware.
921 * Beginning of request ring has initialization control block already built
922 * by nvram config routine.
924 * Returns 0 on success.
927 qla2x00_init_rings(scsi_qla_host_t *ha)
930 unsigned long flags = 0;
933 spin_lock_irqsave(&ha->hardware_lock, flags);
935 /* Clear outstanding commands array. */
936 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
937 ha->outstanding_cmds[cnt] = NULL;
939 ha->current_outstanding_cmd = 0;
941 /* Clear RSCN queue. */
943 ha->rscn_out_ptr = 0;
945 /* Initialize firmware. */
946 ha->request_ring_ptr = ha->request_ring;
947 ha->req_ring_index = 0;
948 ha->req_q_cnt = ha->request_q_length;
949 ha->response_ring_ptr = ha->response_ring;
950 ha->rsp_ring_index = 0;
952 /* Initialize response queue entries */
953 qla2x00_init_response_q_entries(ha);
955 ha->isp_ops.config_rings(ha);
957 spin_unlock_irqrestore(&ha->hardware_lock, flags);
959 /* Update any ISP specific firmware options before initialization. */
960 ha->isp_ops.update_fw_options(ha);
962 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
963 rval = qla2x00_init_firmware(ha, sizeof(init_cb_t));
965 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
968 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
976 * qla2x00_fw_ready() - Waits for firmware ready.
979 * Returns 0 on success.
982 qla2x00_fw_ready(scsi_qla_host_t *ha)
985 unsigned long wtime, mtime;
986 uint16_t min_wait; /* Minimum wait time if loop is down */
987 uint16_t wait_time; /* Wait time if loop is coming ready */
992 /* 20 seconds for loop down. */
996 * Firmware should take at most one RATOV to login, plus 5 seconds for
997 * our own processing.
999 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1000 wait_time = min_wait;
1003 /* Min wait time if loop down */
1004 mtime = jiffies + (min_wait * HZ);
1006 /* wait time before firmware ready */
1007 wtime = jiffies + (wait_time * HZ);
1009 /* Wait for ISP to finish LIP */
1010 if (!ha->flags.init_done)
1011 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1013 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1017 rval = qla2x00_get_firmware_state(ha, &fw_state);
1018 if (rval == QLA_SUCCESS) {
1019 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1020 ha->device_flags &= ~DFLG_NO_CABLE;
1022 if (fw_state == FSTATE_READY) {
1023 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1026 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1027 &ha->login_timeout, &ha->r_a_tov);
1033 rval = QLA_FUNCTION_FAILED;
1035 if (atomic_read(&ha->loop_down_timer) &&
1036 (fw_state >= FSTATE_LOSS_OF_SYNC ||
1037 fw_state == FSTATE_WAIT_AL_PA)) {
1038 /* Loop down. Timeout on min_wait for states
1039 * other than Wait for Login.
1041 if (time_after_eq(jiffies, mtime)) {
1042 qla_printk(KERN_INFO, ha,
1043 "Cable is unplugged...\n");
1045 ha->device_flags |= DFLG_NO_CABLE;
1050 /* Mailbox cmd failed. Timeout on min_wait. */
1051 if (time_after_eq(jiffies, mtime))
1055 if (time_after_eq(jiffies, wtime))
1058 /* Delay for a while */
1061 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1062 ha->host_no, fw_state, jiffies));
1065 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1066 ha->host_no, fw_state, jiffies));
1069 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1077 * qla2x00_configure_hba
1078 * Setup adapter context.
1081 * ha = adapter state pointer.
1090 qla2x00_configure_hba(scsi_qla_host_t *ha)
1098 char connect_type[22];
1100 /* Get host addresses. */
1101 rval = qla2x00_get_adapter_id(ha,
1102 &loop_id, &al_pa, &area, &domain, &topo);
1103 if (rval != QLA_SUCCESS) {
1104 qla_printk(KERN_WARNING, ha,
1105 "ERROR -- Unable to get host loop ID.\n");
1106 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1111 qla_printk(KERN_INFO, ha,
1112 "Cannot get topology - retrying.\n");
1113 return (QLA_FUNCTION_FAILED);
1116 ha->loop_id = loop_id;
1119 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1120 ha->operating_mode = LOOP;
1124 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1126 ha->current_topology = ISP_CFG_NL;
1127 strcpy(connect_type, "(Loop)");
1131 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1133 ha->current_topology = ISP_CFG_FL;
1134 strcpy(connect_type, "(FL_Port)");
1138 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1140 ha->operating_mode = P2P;
1141 ha->current_topology = ISP_CFG_N;
1142 strcpy(connect_type, "(N_Port-to-N_Port)");
1146 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1148 ha->operating_mode = P2P;
1149 ha->current_topology = ISP_CFG_F;
1150 strcpy(connect_type, "(F_Port)");
1154 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1156 ha->host_no, topo));
1157 ha->current_topology = ISP_CFG_NL;
1158 strcpy(connect_type, "(Loop)");
1162 /* Save Host port and loop ID. */
1163 /* byte order - Big Endian */
1164 ha->d_id.b.domain = domain;
1165 ha->d_id.b.area = area;
1166 ha->d_id.b.al_pa = al_pa;
1168 if (!ha->flags.init_done)
1169 qla_printk(KERN_INFO, ha,
1170 "Topology - %s, Host Loop address 0x%x\n",
1171 connect_type, ha->loop_id);
1174 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1176 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1183 * NVRAM configuration for ISP 2xxx
1186 * ha = adapter block pointer.
1189 * initialization control block in response_ring
1190 * host adapters parameters in host adapter block
1196 qla2x00_nvram_config(scsi_qla_host_t *ha)
1201 uint8_t *dptr1, *dptr2;
1202 init_cb_t *icb = ha->init_cb;
1203 nvram_t *nv = (nvram_t *)ha->request_ring;
1204 uint16_t *wptr = (uint16_t *)ha->request_ring;
1205 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1210 /* Determine NVRAM starting address. */
1212 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1213 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1214 ha->nvram_base = 0x80;
1216 /* Get NVRAM data and calculate checksum. */
1217 qla2x00_lock_nvram_access(ha);
1218 for (cnt = 0; cnt < sizeof(nvram_t)/2; cnt++) {
1219 *wptr = cpu_to_le16(qla2x00_get_nvram_word(ha,
1220 (cnt+ha->nvram_base)));
1221 chksum += (uint8_t)*wptr;
1222 chksum += (uint8_t)(*wptr >> 8);
1225 qla2x00_unlock_nvram_access(ha);
1227 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1228 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1231 /* Bad NVRAM data, set defaults parameters. */
1232 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1233 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1234 /* Reset NVRAM data. */
1235 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1236 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1238 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1239 "invalid -- WWPN) defaults.\n");
1242 * Set default initialization control block.
1244 memset(nv, 0, sizeof(nvram_t));
1245 nv->parameter_block_version = ICB_VERSION;
1247 if (IS_QLA23XX(ha)) {
1248 nv->firmware_options[0] = BIT_2 | BIT_1;
1249 nv->firmware_options[1] = BIT_7 | BIT_5;
1250 nv->add_firmware_options[0] = BIT_5;
1251 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1252 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1253 nv->special_options[1] = BIT_7;
1254 } else if (IS_QLA2200(ha)) {
1255 nv->firmware_options[0] = BIT_2 | BIT_1;
1256 nv->firmware_options[1] = BIT_7 | BIT_5;
1257 nv->add_firmware_options[0] = BIT_5;
1258 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1259 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1260 } else if (IS_QLA2100(ha)) {
1261 nv->firmware_options[0] = BIT_3 | BIT_1;
1262 nv->firmware_options[1] = BIT_5;
1263 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1266 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1267 nv->execution_throttle = __constant_cpu_to_le16(16);
1268 nv->retry_count = 8;
1269 nv->retry_delay = 1;
1271 nv->port_name[0] = 33;
1272 nv->port_name[3] = 224;
1273 nv->port_name[4] = 139;
1275 nv->login_timeout = 4;
1278 * Set default host adapter parameters
1280 nv->host_p[1] = BIT_2;
1281 nv->reset_delay = 5;
1282 nv->port_down_retry_count = 8;
1283 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1284 nv->link_down_timeout = 60;
1289 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1291 * The SN2 does not provide BIOS emulation which means you can't change
1292 * potentially bogus BIOS settings. Force the use of default settings
1293 * for link rate and frame size. Hope that the rest of the settings
1296 if (ia64_platform_is("sn2")) {
1297 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1299 nv->special_options[1] = BIT_7;
1303 /* Reset Initialization control block */
1304 memset(icb, 0, sizeof(init_cb_t));
1307 * Setup driver NVRAM options.
1309 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1310 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1311 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1312 nv->firmware_options[1] &= ~BIT_4;
1314 if (IS_QLA23XX(ha)) {
1315 nv->firmware_options[0] |= BIT_2;
1316 nv->firmware_options[0] &= ~BIT_3;
1318 if (IS_QLA2300(ha)) {
1319 if (ha->fb_rev == FPM_2310) {
1320 strcpy(ha->model_number, "QLA2310");
1322 strcpy(ha->model_number, "QLA2300");
1326 memcmp(nv->model_number, BINZERO,
1327 sizeof(nv->model_number)) != 0) {
1330 strncpy(ha->model_number, nv->model_number,
1331 sizeof(nv->model_number));
1332 st = en = ha->model_number;
1333 en += sizeof(nv->model_number) - 1;
1335 if (*en != 0x20 && *en != 0x00)
1342 index = (ha->pdev->subsystem_device & 0xff);
1343 if (index < QLA_MODEL_NAMES) {
1344 strcpy(ha->model_number,
1345 qla2x00_model_name[index]);
1347 qla2x00_model_desc[index];
1349 strcpy(ha->model_number, "QLA23xx");
1353 } else if (IS_QLA2200(ha)) {
1354 nv->firmware_options[0] |= BIT_2;
1356 * 'Point-to-point preferred, else loop' is not a safe
1357 * connection mode setting.
1359 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1361 /* Force 'loop preferred, else point-to-point'. */
1362 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1363 nv->add_firmware_options[0] |= BIT_5;
1365 strcpy(ha->model_number, "QLA22xx");
1366 } else /*if (IS_QLA2100(ha))*/ {
1367 strcpy(ha->model_number, "QLA2100");
1371 * Copy over NVRAM RISC parameter block to initialization control block.
1373 dptr1 = (uint8_t *)icb;
1374 dptr2 = (uint8_t *)&nv->parameter_block_version;
1375 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1377 *dptr1++ = *dptr2++;
1379 /* Copy 2nd half. */
1380 dptr1 = (uint8_t *)icb->add_firmware_options;
1381 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1383 *dptr1++ = *dptr2++;
1385 /* Prepare nodename */
1386 if ((icb->firmware_options[1] & BIT_6) == 0) {
1388 * Firmware will apply the following mask if the nodename was
1391 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1392 icb->node_name[0] &= 0xF0;
1396 * Set host adapter parameters.
1398 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1399 /* Always load RISC code on non ISP2[12]00 chips. */
1400 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1401 ha->flags.disable_risc_code_load = 0;
1402 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1403 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1404 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1405 ha->flags.enable_led_scheme = ((nv->efi_parameters & BIT_3) ? 1 : 0);
1407 ha->operating_mode =
1408 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1410 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1411 sizeof(ha->fw_seriallink_options));
1413 /* save HBA serial number */
1414 ha->serial0 = icb->port_name[5];
1415 ha->serial1 = icb->port_name[6];
1416 ha->serial2 = icb->port_name[7];
1417 ha->node_name = icb->node_name;
1418 ha->port_name = icb->port_name;
1420 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1422 ha->retry_count = nv->retry_count;
1424 /* Set minimum login_timeout to 4 seconds. */
1425 if (nv->login_timeout < ql2xlogintimeout)
1426 nv->login_timeout = ql2xlogintimeout;
1427 if (nv->login_timeout < 4)
1428 nv->login_timeout = 4;
1429 ha->login_timeout = nv->login_timeout;
1430 icb->login_timeout = nv->login_timeout;
1432 /* Set minimum RATOV to 200 tenths of a second. */
1435 ha->loop_reset_delay = nv->reset_delay;
1437 /* Link Down Timeout = 0:
1439 * When Port Down timer expires we will start returning
1440 * I/O's to OS with "DID_NO_CONNECT".
1442 * Link Down Timeout != 0:
1444 * The driver waits for the link to come up after link down
1445 * before returning I/Os to OS with "DID_NO_CONNECT".
1447 if (nv->link_down_timeout == 0) {
1448 ha->loop_down_abort_time =
1449 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1451 ha->link_down_timeout = nv->link_down_timeout;
1452 ha->loop_down_abort_time =
1453 (LOOP_DOWN_TIME - ha->link_down_timeout);
1457 * Need enough time to try and get the port back.
1459 ha->port_down_retry_count = nv->port_down_retry_count;
1460 if (qlport_down_retry)
1461 ha->port_down_retry_count = qlport_down_retry;
1462 /* Set login_retry_count */
1463 ha->login_retry_count = nv->retry_count;
1464 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1465 ha->port_down_retry_count > 3)
1466 ha->login_retry_count = ha->port_down_retry_count;
1467 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1468 ha->login_retry_count = ha->port_down_retry_count;
1469 if (ql2xloginretrycount)
1470 ha->login_retry_count = ql2xloginretrycount;
1472 icb->lun_enables = __constant_cpu_to_le16(0);
1473 icb->command_resource_count = 0;
1474 icb->immediate_notify_resource_count = 0;
1475 icb->timeout = __constant_cpu_to_le16(0);
1477 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1479 icb->firmware_options[0] &= ~BIT_3;
1480 icb->add_firmware_options[0] &=
1481 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1482 icb->add_firmware_options[0] |= BIT_2;
1483 icb->response_accumulation_timer = 3;
1484 icb->interrupt_delay_timer = 5;
1486 ha->flags.process_response_queue = 1;
1488 /* Enable ZIO -- Support mode 5 only. */
1489 timer_mode = icb->add_firmware_options[0] &
1490 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1491 icb->add_firmware_options[0] &=
1492 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1494 timer_mode = BIT_2 | BIT_0;
1495 if (timer_mode == (BIT_2 | BIT_0)) {
1496 DEBUG2(printk("scsi(%ld): ZIO enabled; timer delay "
1497 "(%d).\n", ha->host_no, ql2xintrdelaytimer));
1498 qla_printk(KERN_INFO, ha,
1499 "ZIO enabled; timer delay (%d).\n",
1500 ql2xintrdelaytimer);
1502 icb->add_firmware_options[0] |= timer_mode;
1503 icb->interrupt_delay_timer = ql2xintrdelaytimer;
1504 ha->flags.process_response_queue = 1;
1509 DEBUG2_3(printk(KERN_WARNING
1510 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1516 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1518 * @flags: allocation flags
1520 * Returns a pointer to the allocated fcport, or NULL, if none available.
1523 qla2x00_alloc_fcport(scsi_qla_host_t *ha, int flags)
1527 fcport = kmalloc(sizeof(fc_port_t), flags);
1531 /* Setup fcport template structure. */
1532 memset(fcport, 0, sizeof (fc_port_t));
1534 fcport->port_type = FCT_UNKNOWN;
1535 fcport->loop_id = FC_NO_LOOP_ID;
1536 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1537 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1538 fcport->flags = FCF_RLC_SUPPORT;
1544 * qla2x00_configure_loop
1545 * Updates Fibre Channel Device Database with what is actually on loop.
1548 * ha = adapter block pointer.
1553 * 2 = database was full and device was not configured.
1556 qla2x00_configure_loop(scsi_qla_host_t *ha)
1559 unsigned long flags, save_flags;
1563 /* Get Initiator ID */
1564 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1565 rval = qla2x00_configure_hba(ha);
1566 if (rval != QLA_SUCCESS) {
1567 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1573 save_flags = flags = ha->dpc_flags;
1574 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1575 ha->host_no, flags));
1578 * If we have both an RSCN and PORT UPDATE pending then handle them
1579 * both at the same time.
1581 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1582 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1584 /* Determine what we need to do */
1585 if (ha->current_topology == ISP_CFG_FL &&
1586 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1588 ha->flags.rscn_queue_overflow = 1;
1589 set_bit(RSCN_UPDATE, &flags);
1591 } else if (ha->current_topology == ISP_CFG_F &&
1592 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1594 ha->flags.rscn_queue_overflow = 1;
1595 set_bit(RSCN_UPDATE, &flags);
1596 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1598 } else if (!ha->flags.online ||
1599 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1601 ha->flags.rscn_queue_overflow = 1;
1602 set_bit(RSCN_UPDATE, &flags);
1603 set_bit(LOCAL_LOOP_UPDATE, &flags);
1606 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1607 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1608 rval = QLA_FUNCTION_FAILED;
1610 rval = qla2x00_configure_local_loop(ha);
1614 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1615 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1616 rval = QLA_FUNCTION_FAILED;
1618 rval = qla2x00_configure_fabric(ha);
1622 if (rval == QLA_SUCCESS) {
1623 if (atomic_read(&ha->loop_down_timer) ||
1624 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1625 rval = QLA_FUNCTION_FAILED;
1627 atomic_set(&ha->loop_state, LOOP_READY);
1629 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1634 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1635 __func__, ha->host_no));
1637 DEBUG3(printk("%s: exiting normally\n", __func__));
1640 /* Restore state if a resync event occured during processing */
1641 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1642 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1643 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1644 if (test_bit(RSCN_UPDATE, &save_flags))
1645 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1654 * qla2x00_configure_local_loop
1655 * Updates Fibre Channel Device Database with local loop devices.
1658 * ha = adapter block pointer.
1664 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1669 fc_port_t *fcport, *new_fcport;
1675 uint8_t domain, area, al_pa;
1679 entries = MAX_FIBRE_DEVICES;
1681 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1682 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1684 /* Get list of logged in devices. */
1685 memset(ha->gid_list, 0, GID_LIST_SIZE);
1686 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1688 if (rval != QLA_SUCCESS)
1689 goto cleanup_allocation;
1691 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1692 ha->host_no, entries));
1693 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1694 entries * sizeof(struct gid_list_info)));
1696 /* Allocate temporary fcport for any new fcports discovered. */
1697 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1698 if (new_fcport == NULL) {
1699 rval = QLA_MEMORY_ALLOC_FAILED;
1700 goto cleanup_allocation;
1702 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1705 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1707 list_for_each_entry(fcport, &ha->fcports, list) {
1708 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1709 fcport->port_type != FCT_BROADCAST &&
1710 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1712 DEBUG(printk("scsi(%ld): Marking port lost, "
1714 ha->host_no, fcport->loop_id));
1716 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1717 fcport->flags &= ~FCF_FARP_DONE;
1721 /* Add devices to port list. */
1722 id_iter = (char *)ha->gid_list;
1723 for (index = 0; index < entries; index++) {
1724 domain = ((struct gid_list_info *)id_iter)->domain;
1725 area = ((struct gid_list_info *)id_iter)->area;
1726 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1727 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1728 loop_id = (uint16_t)
1729 ((struct gid_list_info *)id_iter)->loop_id_2100;
1731 loop_id = le16_to_cpu(
1732 ((struct gid_list_info *)id_iter)->loop_id);
1733 id_iter += ha->gid_list_info_size;
1735 /* Bypass reserved domain fields. */
1736 if ((domain & 0xf0) == 0xf0)
1739 /* Bypass if not same domain and area of adapter. */
1740 if (area != ha->d_id.b.area || domain != ha->d_id.b.domain)
1743 /* Bypass invalid local loop ID. */
1744 if (loop_id > LAST_LOCAL_LOOP_ID)
1747 /* Fill in member data. */
1748 new_fcport->d_id.b.domain = domain;
1749 new_fcport->d_id.b.area = area;
1750 new_fcport->d_id.b.al_pa = al_pa;
1751 new_fcport->loop_id = loop_id;
1752 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1753 if (rval2 != QLA_SUCCESS) {
1754 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1755 "information -- get_port_database=%x, "
1757 ha->host_no, rval2, new_fcport->loop_id));
1761 /* Check for matching device in port list. */
1764 list_for_each_entry(fcport, &ha->fcports, list) {
1765 if (memcmp(new_fcport->port_name, fcport->port_name,
1769 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1770 FCF_PERSISTENT_BOUND);
1771 fcport->loop_id = new_fcport->loop_id;
1772 fcport->port_type = new_fcport->port_type;
1773 fcport->d_id.b24 = new_fcport->d_id.b24;
1774 memcpy(fcport->node_name, new_fcport->node_name,
1782 /* New device, add to fcports list. */
1783 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1784 list_add_tail(&new_fcport->list, &ha->fcports);
1786 /* Allocate a new replacement fcport. */
1787 fcport = new_fcport;
1788 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1789 if (new_fcport == NULL) {
1790 rval = QLA_MEMORY_ALLOC_FAILED;
1791 goto cleanup_allocation;
1793 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1796 qla2x00_update_fcport(ha, fcport);
1805 if (rval != QLA_SUCCESS) {
1806 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1807 "rval=%x\n", ha->host_no, rval));
1811 ha->device_flags |= DFLG_LOCAL_DEVICES;
1812 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
1819 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
1823 qla2x00_mark_all_devices_lost(ha);
1824 list_for_each_entry(fcport, &ha->fcports, list) {
1825 if (fcport->port_type != FCT_TARGET)
1828 qla2x00_update_fcport(ha, fcport);
1833 * qla2x00_update_fcport
1834 * Updates device on list.
1837 * ha = adapter block pointer.
1838 * fcport = port structure pointer.
1848 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
1851 unsigned long flags;
1855 fcport->login_retry = 0;
1856 fcport->port_login_retry_count = ha->port_down_retry_count *
1858 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
1860 fcport->flags &= ~FCF_LOGIN_NEEDED;
1863 * Check for outstanding cmd on tape Bypass LUN discovery if active
1866 if (fcport->flags & FCF_TAPE_PRESENT) {
1867 spin_lock_irqsave(&ha->hardware_lock, flags);
1868 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
1871 if ((sp = ha->outstanding_cmds[index]) != 0) {
1873 if (sfcp == fcport) {
1874 atomic_set(&fcport->state, FCS_ONLINE);
1875 spin_unlock_irqrestore(
1876 &ha->hardware_lock, flags);
1881 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1884 if (fcport->port_type == FCT_INITIATOR ||
1885 fcport->port_type == FCT_BROADCAST)
1886 fcport->device_type = TYPE_PROCESSOR;
1888 atomic_set(&fcport->state, FCS_ONLINE);
1890 if (ha->flags.init_done)
1891 qla2x00_reg_remote_port(ha, fcport);
1895 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
1897 struct fc_rport_identifiers rport_ids;
1898 struct fc_rport *rport;
1900 if (fcport->rport) {
1901 fc_remote_port_unblock(fcport->rport);
1905 rport_ids.node_name = be64_to_cpu(*(uint64_t *)fcport->node_name);
1906 rport_ids.port_name = be64_to_cpu(*(uint64_t *)fcport->port_name);
1907 rport_ids.port_id = fcport->d_id.b.domain << 16 |
1908 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
1909 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
1910 if (fcport->port_type == FCT_INITIATOR)
1911 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1912 if (fcport->port_type == FCT_TARGET)
1913 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1915 fcport->rport = rport = fc_remote_port_add(ha->host, 0, &rport_ids);
1917 qla_printk(KERN_WARNING, ha,
1918 "Unable to allocate fc remote port!\n");
1920 if (rport->scsi_target_id != -1 && rport->scsi_target_id < MAX_TARGETS)
1921 fcport->os_target_id = rport->scsi_target_id;
1923 rport->dd_data = fcport;
1927 * qla2x00_configure_fabric
1928 * Setup SNS devices with loop ID's.
1931 * ha = adapter block pointer.
1938 qla2x00_configure_fabric(scsi_qla_host_t *ha)
1941 fc_port_t *fcport, *fcptemp;
1942 uint16_t next_loopid;
1943 uint16_t mb[MAILBOX_REGISTER_COUNT];
1944 LIST_HEAD(new_fcports);
1946 /* If FL port exists, then SNS is present */
1947 rval = qla2x00_get_port_name(ha, SNS_FL_PORT, NULL, 0);
1948 if (rval != QLA_SUCCESS) {
1949 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
1950 "Port\n", ha->host_no));
1952 ha->device_flags &= ~SWITCH_FOUND;
1953 return (QLA_SUCCESS);
1956 /* Mark devices that need re-synchronization. */
1957 rval2 = qla2x00_device_resync(ha);
1958 if (rval2 == QLA_RSCNS_HANDLED) {
1959 /* No point doing the scan, just continue. */
1960 return (QLA_SUCCESS);
1963 /* Ensure we are logged into the SNS. */
1964 ha->isp_ops.fabric_login(ha, SIMPLE_NAME_SERVER, 0xff, 0xff,
1965 0xfc, mb, BIT_1 | BIT_0);
1966 if (mb[0] != MBS_COMMAND_COMPLETE) {
1967 DEBUG2(qla_printk(KERN_INFO, ha,
1968 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
1969 "mb[2]=%x mb[6]=%x mb[7]=%x\n", SIMPLE_NAME_SERVER,
1970 mb[0], mb[1], mb[2], mb[6], mb[7]));
1971 return (QLA_SUCCESS);
1974 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
1975 if (qla2x00_rft_id(ha)) {
1977 DEBUG2(printk("scsi(%ld): Register FC-4 "
1978 "TYPE failed.\n", ha->host_no));
1980 if (qla2x00_rff_id(ha)) {
1982 DEBUG2(printk("scsi(%ld): Register FC-4 "
1983 "Features failed.\n", ha->host_no));
1985 if (qla2x00_rnn_id(ha)) {
1987 DEBUG2(printk("scsi(%ld): Register Node Name "
1988 "failed.\n", ha->host_no));
1989 } else if (qla2x00_rsnn_nn(ha)) {
1991 DEBUG2(printk("scsi(%ld): Register Symbolic "
1992 "Node Name failed.\n", ha->host_no));
1996 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
1997 if (rval != QLA_SUCCESS)
2001 * Logout all previous fabric devices marked lost, except
2004 list_for_each_entry(fcport, &ha->fcports, list) {
2005 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2008 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2011 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2012 qla2x00_mark_device_lost(ha, fcport,
2013 ql2xplogiabsentdevice);
2014 if (fcport->loop_id != FC_NO_LOOP_ID &&
2015 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2016 fcport->port_type != FCT_INITIATOR &&
2017 fcport->port_type != FCT_BROADCAST) {
2019 ha->isp_ops.fabric_logout(ha,
2021 fcport->d_id.b.domain,
2022 fcport->d_id.b.area,
2023 fcport->d_id.b.al_pa);
2024 fcport->loop_id = FC_NO_LOOP_ID;
2029 /* Starting free loop ID. */
2030 next_loopid = ha->min_external_loopid;
2033 * Scan through our port list and login entries that need to be
2036 list_for_each_entry(fcport, &ha->fcports, list) {
2037 if (atomic_read(&ha->loop_down_timer) ||
2038 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2041 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2042 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2045 if (fcport->loop_id == FC_NO_LOOP_ID) {
2046 fcport->loop_id = next_loopid;
2047 rval = qla2x00_find_new_loop_id(ha, fcport);
2048 if (rval != QLA_SUCCESS) {
2049 /* Ran out of IDs to use */
2054 /* Login and update database */
2055 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2058 /* Exit if out of loop IDs. */
2059 if (rval != QLA_SUCCESS) {
2064 * Login and add the new devices to our port list.
2066 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2067 if (atomic_read(&ha->loop_down_timer) ||
2068 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2071 /* Find a new loop ID to use. */
2072 fcport->loop_id = next_loopid;
2073 rval = qla2x00_find_new_loop_id(ha, fcport);
2074 if (rval != QLA_SUCCESS) {
2075 /* Ran out of IDs to use */
2079 /* Remove device from the new list and add it to DB */
2080 list_del(&fcport->list);
2081 list_add_tail(&fcport->list, &ha->fcports);
2083 /* Login and update database */
2084 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2088 /* Free all new device structures not processed. */
2089 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2090 list_del(&fcport->list);
2095 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2096 "rval=%d\n", ha->host_no, rval));
2104 * qla2x00_find_all_fabric_devs
2107 * ha = adapter block pointer.
2108 * dev = database device entry pointer.
2117 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2121 fc_port_t *fcport, *new_fcport, *fcptemp;
2126 int first_dev, last_dev;
2127 port_id_t wrap, nxt_d_id;
2131 /* Try GID_PT to get device list, else GAN. */
2132 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2135 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2136 "on GA_NXT\n", ha->host_no));
2138 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2139 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2142 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2145 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2152 /* Allocate temporary fcport for any new fcports discovered. */
2153 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2154 if (new_fcport == NULL) {
2157 return (QLA_MEMORY_ALLOC_FAILED);
2159 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2161 /* Set start port ID scan at adapter ID. */
2165 /* Starting free loop ID. */
2166 loop_id = ha->min_external_loopid;
2168 for (; loop_id <= ha->last_loop_id; loop_id++) {
2169 if (qla2x00_is_reserved_id(ha, loop_id))
2172 if (atomic_read(&ha->loop_down_timer) ||
2173 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2178 wrap.b24 = new_fcport->d_id.b24;
2180 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2181 memcpy(new_fcport->node_name,
2182 swl[swl_idx].node_name, WWN_SIZE);
2183 memcpy(new_fcport->port_name,
2184 swl[swl_idx].port_name, WWN_SIZE);
2186 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2192 /* Send GA_NXT to the switch */
2193 rval = qla2x00_ga_nxt(ha, new_fcport);
2194 if (rval != QLA_SUCCESS) {
2195 qla_printk(KERN_WARNING, ha,
2196 "SNS scan failed -- assuming zero-entry "
2198 list_for_each_entry_safe(fcport, fcptemp,
2199 new_fcports, list) {
2200 list_del(&fcport->list);
2208 /* If wrap on switch device list, exit. */
2210 wrap.b24 = new_fcport->d_id.b24;
2212 } else if (new_fcport->d_id.b24 == wrap.b24) {
2213 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2214 ha->host_no, new_fcport->d_id.b.domain,
2215 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2219 /* Bypass if host adapter. */
2220 if (new_fcport->d_id.b24 == ha->d_id.b24)
2223 /* Bypass reserved domain fields. */
2224 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2227 /* Locate matching device in database. */
2229 list_for_each_entry(fcport, &ha->fcports, list) {
2230 if (memcmp(new_fcport->port_name, fcport->port_name,
2237 * If address the same and state FCS_ONLINE, nothing
2240 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2241 atomic_read(&fcport->state) == FCS_ONLINE) {
2246 * If device was not a fabric device before.
2248 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2249 fcport->d_id.b24 = new_fcport->d_id.b24;
2250 fcport->loop_id = FC_NO_LOOP_ID;
2251 fcport->flags |= (FCF_FABRIC_DEVICE |
2253 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2258 * Port ID changed or device was marked to be updated;
2259 * Log it out if still logged in and mark it for
2262 fcport->d_id.b24 = new_fcport->d_id.b24;
2263 fcport->flags |= FCF_LOGIN_NEEDED;
2264 if (fcport->loop_id != FC_NO_LOOP_ID &&
2265 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2266 fcport->port_type != FCT_INITIATOR &&
2267 fcport->port_type != FCT_BROADCAST) {
2268 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2269 fcport->d_id.b.domain, fcport->d_id.b.area,
2270 fcport->d_id.b.al_pa);
2271 fcport->loop_id = FC_NO_LOOP_ID;
2280 /* If device was not in our fcports list, then add it. */
2281 list_add_tail(&new_fcport->list, new_fcports);
2283 /* Allocate a new replacement fcport. */
2284 nxt_d_id.b24 = new_fcport->d_id.b24;
2285 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2286 if (new_fcport == NULL) {
2289 return (QLA_MEMORY_ALLOC_FAILED);
2291 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2292 new_fcport->d_id.b24 = nxt_d_id.b24;
2301 if (!list_empty(new_fcports))
2302 ha->device_flags |= DFLG_FABRIC_DEVICES;
2308 * qla2x00_find_new_loop_id
2309 * Scan through our port list and find a new usable loop ID.
2312 * ha: adapter state pointer.
2313 * dev: port structure pointer.
2316 * qla2x00 local function return status code.
2322 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2327 uint16_t first_loop_id;
2331 /* Save starting loop ID. */
2332 first_loop_id = dev->loop_id;
2335 /* Skip loop ID if already used by adapter. */
2336 if (dev->loop_id == ha->loop_id) {
2340 /* Skip reserved loop IDs. */
2341 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2345 /* Reset loop ID if passed the end. */
2346 if (dev->loop_id > ha->last_loop_id) {
2347 /* first loop ID. */
2348 dev->loop_id = ha->min_external_loopid;
2351 /* Check for loop ID being already in use. */
2354 list_for_each_entry(fcport, &ha->fcports, list) {
2355 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2356 /* ID possibly in use */
2362 /* If not in use then it is free to use. */
2367 /* ID in use. Try next value. */
2370 /* If wrap around. No free ID to use. */
2371 if (dev->loop_id == first_loop_id) {
2372 dev->loop_id = FC_NO_LOOP_ID;
2373 rval = QLA_FUNCTION_FAILED;
2382 * qla2x00_device_resync
2383 * Marks devices in the database that needs resynchronization.
2386 * ha = adapter block pointer.
2392 qla2x00_device_resync(scsi_qla_host_t *ha)
2398 uint32_t rscn_entry;
2399 uint8_t rscn_out_iter;
2403 rval = QLA_RSCNS_HANDLED;
2405 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2406 ha->flags.rscn_queue_overflow) {
2408 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2409 format = MSB(MSW(rscn_entry));
2410 d_id.b.domain = LSB(MSW(rscn_entry));
2411 d_id.b.area = MSB(LSW(rscn_entry));
2412 d_id.b.al_pa = LSB(LSW(rscn_entry));
2414 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2415 "[%02x/%02x%02x%02x].\n",
2416 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2417 d_id.b.area, d_id.b.al_pa));
2420 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2421 ha->rscn_out_ptr = 0;
2423 /* Skip duplicate entries. */
2424 for (rscn_out_iter = ha->rscn_out_ptr;
2425 !ha->flags.rscn_queue_overflow &&
2426 rscn_out_iter != ha->rscn_in_ptr;
2427 rscn_out_iter = (rscn_out_iter ==
2428 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2430 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2433 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2434 "entry found at [%d].\n", ha->host_no,
2437 ha->rscn_out_ptr = rscn_out_iter;
2440 /* Queue overflow, set switch default case. */
2441 if (ha->flags.rscn_queue_overflow) {
2442 DEBUG(printk("scsi(%ld): device_resync: rscn "
2443 "overflow.\n", ha->host_no));
2446 ha->flags.rscn_queue_overflow = 0;
2451 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) &&
2452 !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
2453 ha->flags.init_done) {
2454 /* Handle port RSCN via asyncronous IOCBs */
2455 rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
2457 if (rval2 == QLA_SUCCESS)
2471 ha->rscn_out_ptr = ha->rscn_in_ptr;
2477 /* Abort any outstanding IO descriptors. */
2478 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2479 qla2x00_cancel_io_descriptors(ha);
2481 list_for_each_entry(fcport, &ha->fcports, list) {
2482 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2483 (fcport->d_id.b24 & mask) != d_id.b24 ||
2484 fcport->port_type == FCT_BROADCAST)
2487 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2489 fcport->port_type != FCT_INITIATOR) {
2490 qla2x00_mark_device_lost(ha, fcport, 0);
2493 fcport->flags &= ~FCF_FARP_DONE;
2500 * qla2x00_fabric_dev_login
2501 * Login fabric target device and update FC port database.
2504 * ha: adapter state pointer.
2505 * fcport: port structure list pointer.
2506 * next_loopid: contains value of a new loop ID that can be used
2507 * by the next login attempt.
2510 * qla2x00 local function return status code.
2516 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2517 uint16_t *next_loopid)
2525 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2526 if (rval == QLA_SUCCESS) {
2527 rval = qla2x00_get_port_database(ha, fcport, 0);
2528 if (rval != QLA_SUCCESS) {
2529 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2530 fcport->d_id.b.domain, fcport->d_id.b.area,
2531 fcport->d_id.b.al_pa);
2533 qla2x00_update_fcport(ha, fcport);
2541 * qla2x00_fabric_login
2542 * Issue fabric login command.
2545 * ha = adapter block pointer.
2546 * device = pointer to FC device type structure.
2549 * 0 - Login successfully
2551 * 2 - Initiator device
2555 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2556 uint16_t *next_loopid)
2560 uint16_t tmp_loopid;
2561 uint16_t mb[MAILBOX_REGISTER_COUNT];
2567 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2568 "for port %02x%02x%02x.\n",
2569 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2570 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2572 /* Login fcport on switch. */
2573 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2574 fcport->d_id.b.domain, fcport->d_id.b.area,
2575 fcport->d_id.b.al_pa, mb, BIT_0);
2576 if (mb[0] == MBS_PORT_ID_USED) {
2578 * Device has another loop ID. The firmware team
2579 * recommends us to perform an implicit login with the
2580 * specified ID again. The ID we just used is save here
2581 * so we return with an ID that can be tried by the
2585 tmp_loopid = fcport->loop_id;
2586 fcport->loop_id = mb[1];
2588 DEBUG(printk("Fabric Login: port in use - next "
2589 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2590 fcport->loop_id, fcport->d_id.b.domain,
2591 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2593 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2598 /* A retry occurred before. */
2599 *next_loopid = tmp_loopid;
2602 * No retry occurred before. Just increment the
2603 * ID value for next login.
2605 *next_loopid = (fcport->loop_id + 1);
2608 if (mb[1] & BIT_0) {
2609 fcport->port_type = FCT_INITIATOR;
2611 fcport->port_type = FCT_TARGET;
2612 if (mb[1] & BIT_1) {
2613 fcport->flags |= FCF_TAPE_PRESENT;
2619 } else if (mb[0] == MBS_LOOP_ID_USED) {
2621 * Loop ID already used, try next loop ID.
2624 rval = qla2x00_find_new_loop_id(ha, fcport);
2625 if (rval != QLA_SUCCESS) {
2626 /* Ran out of loop IDs to use */
2629 } else if (mb[0] == MBS_COMMAND_ERROR) {
2631 * Firmware possibly timed out during login. If NO
2632 * retries are left to do then the device is declared
2635 *next_loopid = fcport->loop_id;
2636 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2637 fcport->d_id.b.domain, fcport->d_id.b.area,
2638 fcport->d_id.b.al_pa);
2639 qla2x00_mark_device_lost(ha, fcport, 1);
2645 * unrecoverable / not handled error
2647 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2648 "loop_id=%x jiffies=%lx.\n",
2649 __func__, ha->host_no, mb[0],
2650 fcport->d_id.b.domain, fcport->d_id.b.area,
2651 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2653 *next_loopid = fcport->loop_id;
2654 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2655 fcport->d_id.b.domain, fcport->d_id.b.area,
2656 fcport->d_id.b.al_pa);
2657 fcport->loop_id = FC_NO_LOOP_ID;
2658 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
2669 * qla2x00_local_device_login
2670 * Issue local device login command.
2673 * ha = adapter block pointer.
2674 * loop_id = loop id of device to login to.
2676 * Returns (Where's the #define!!!!):
2677 * 0 - Login successfully
2682 qla2x00_local_device_login(scsi_qla_host_t *ha, uint16_t loop_id)
2685 uint16_t mb[MAILBOX_REGISTER_COUNT];
2687 memset(mb, 0, sizeof(mb));
2688 rval = qla2x00_login_local_device(ha, loop_id, mb, BIT_0);
2689 if (rval == QLA_SUCCESS) {
2690 /* Interrogate mailbox registers for any errors */
2691 if (mb[0] == MBS_COMMAND_ERROR)
2693 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
2694 /* device not in PCB table */
2702 * qla2x00_loop_resync
2703 * Resync with fibre channel devices.
2706 * ha = adapter block pointer.
2712 qla2x00_loop_resync(scsi_qla_host_t *ha)
2719 atomic_set(&ha->loop_state, LOOP_UPDATE);
2720 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2721 if (ha->flags.online) {
2722 if (!(rval = qla2x00_fw_ready(ha))) {
2723 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2727 atomic_set(&ha->loop_state, LOOP_UPDATE);
2730 * Issue marker command only when we are going
2731 * to start the I/O .
2733 ha->marker_needed = 1;
2735 /* Remap devices on Loop. */
2736 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2738 qla2x00_configure_loop(ha);
2740 } while (!atomic_read(&ha->loop_down_timer) &&
2741 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
2743 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
2747 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2748 return (QLA_FUNCTION_FAILED);
2752 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
2759 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
2765 list_for_each_entry(fcport, &ha->fcports, list) {
2766 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
2769 qla2x00_update_fcport(ha, fcport);
2770 fcport->flags &= ~FCF_RESCAN_NEEDED;
2774 qla2x00_probe_for_all_luns(ha);
2779 * Resets ISP and aborts all outstanding commands.
2782 * ha = adapter block pointer.
2788 qla2x00_abort_isp(scsi_qla_host_t *ha)
2790 unsigned long flags = 0;
2795 if (ha->flags.online) {
2796 ha->flags.online = 0;
2797 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2799 qla_printk(KERN_INFO, ha,
2800 "Performing ISP error recovery - ha= %p.\n", ha);
2801 ha->isp_ops.reset_chip(ha);
2803 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
2804 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
2805 atomic_set(&ha->loop_state, LOOP_DOWN);
2806 qla2x00_mark_all_devices_lost(ha);
2808 if (!atomic_read(&ha->loop_down_timer))
2809 atomic_set(&ha->loop_down_timer,
2813 spin_lock_irqsave(&ha->hardware_lock, flags);
2814 /* Requeue all commands in outstanding command list. */
2815 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
2816 sp = ha->outstanding_cmds[cnt];
2818 ha->outstanding_cmds[cnt] = NULL;
2820 sp->cmd->result = DID_RESET << 16;
2821 sp->cmd->host_scribble = (unsigned char *)NULL;
2822 qla2x00_sp_compl(ha, sp);
2825 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2827 ha->isp_ops.nvram_config(ha);
2829 if (!qla2x00_restart_isp(ha)) {
2830 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2832 if (!atomic_read(&ha->loop_down_timer)) {
2834 * Issue marker command only when we are going
2835 * to start the I/O .
2837 ha->marker_needed = 1;
2840 ha->flags.online = 1;
2842 ha->isp_ops.enable_intrs(ha);
2844 ha->isp_abort_cnt = 0;
2845 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2846 } else { /* failed the ISP abort */
2847 ha->flags.online = 1;
2848 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
2849 if (ha->isp_abort_cnt == 0) {
2850 qla_printk(KERN_WARNING, ha,
2851 "ISP error recovery failed - "
2852 "board disabled\n");
2854 * The next call disables the board
2857 ha->isp_ops.reset_adapter(ha);
2858 ha->flags.online = 0;
2859 clear_bit(ISP_ABORT_RETRY,
2862 } else { /* schedule another ISP abort */
2863 ha->isp_abort_cnt--;
2864 DEBUG(printk("qla%ld: ISP abort - "
2865 "retry remainning %d\n",
2866 ha->host_no, ha->isp_abort_cnt);)
2870 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
2871 DEBUG(printk("qla2x00(%ld): ISP error recovery "
2872 "- retrying (%d) more times\n",
2873 ha->host_no, ha->isp_abort_cnt);)
2874 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2882 qla_printk(KERN_INFO, ha,
2883 "qla2x00_abort_isp: **** FAILED ****\n");
2885 DEBUG(printk(KERN_INFO
2886 "qla2x00_abort_isp(%ld): exiting.\n",
2894 * qla2x00_restart_isp
2895 * restarts the ISP after a reset
2898 * ha = adapter block pointer.
2904 qla2x00_restart_isp(scsi_qla_host_t *ha)
2907 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2908 unsigned long flags = 0;
2911 /* If firmware needs to be loaded */
2912 if (qla2x00_isp_firmware(ha)) {
2913 ha->flags.online = 0;
2914 if (!(status = ha->isp_ops.chip_diag(ha))) {
2915 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2916 status = qla2x00_setup_chip(ha);
2920 spin_lock_irqsave(&ha->hardware_lock, flags);
2922 /* Disable SRAM, Instruction RAM and GP RAM parity. */
2923 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
2924 RD_REG_WORD(®->hccr); /* PCI Posting. */
2926 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2928 status = qla2x00_setup_chip(ha);
2930 spin_lock_irqsave(&ha->hardware_lock, flags);
2932 /* Enable proper parity */
2935 WRT_REG_WORD(®->hccr,
2936 (HCCR_ENABLE_PARITY + 0x1));
2938 /* SRAM, Instruction RAM and GP RAM parity */
2939 WRT_REG_WORD(®->hccr,
2940 (HCCR_ENABLE_PARITY + 0x7));
2941 RD_REG_WORD(®->hccr); /* PCI Posting. */
2943 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2948 if (!status && !(status = qla2x00_init_rings(ha))) {
2949 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2950 if (!(status = qla2x00_fw_ready(ha))) {
2951 DEBUG(printk("%s(): Start configure loop, "
2955 ha->flags.online = 1;
2956 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2959 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2960 qla2x00_configure_loop(ha);
2962 } while (!atomic_read(&ha->loop_down_timer) &&
2963 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
2965 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
2968 /* if no cable then assume it's good */
2969 if ((ha->device_flags & DFLG_NO_CABLE))
2972 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
2980 * qla2x00_reset_adapter
2984 * ha = adapter block pointer.
2987 qla2x00_reset_adapter(scsi_qla_host_t *ha)
2989 unsigned long flags = 0;
2990 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2992 ha->flags.online = 0;
2993 ha->isp_ops.disable_intrs(ha);
2995 /* Reset RISC processor. */
2996 spin_lock_irqsave(&ha->hardware_lock, flags);
2997 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2998 RD_REG_WORD(®->hccr); /* PCI Posting. */
2999 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3000 RD_REG_WORD(®->hccr); /* PCI Posting. */
3001 spin_unlock_irqrestore(&ha->hardware_lock, flags);