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_pci_config(scsi_qla_host_t *);
38 static int qla2x00_isp_firmware(scsi_qla_host_t *);
39 static void qla2x00_reset_chip(scsi_qla_host_t *);
40 static int qla2x00_chip_diag(scsi_qla_host_t *);
41 static void qla2x00_resize_request_q(scsi_qla_host_t *);
42 static int qla2x00_setup_chip(scsi_qla_host_t *);
43 static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
44 static int qla2x00_init_rings(scsi_qla_host_t *);
45 static int qla2x00_fw_ready(scsi_qla_host_t *);
46 static int qla2x00_configure_hba(scsi_qla_host_t *);
47 static int qla2x00_nvram_config(scsi_qla_host_t *);
48 static int qla2x00_configure_loop(scsi_qla_host_t *);
49 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
50 static void qla2x00_update_fcport(scsi_qla_host_t *, fc_port_t *);
51 static int qla2x00_configure_fabric(scsi_qla_host_t *);
52 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
53 static int qla2x00_device_resync(scsi_qla_host_t *);
54 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
57 static int qla2x00_restart_isp(scsi_qla_host_t *);
58 static void qla2x00_reset_adapter(scsi_qla_host_t *);
60 /****************************************************************************/
61 /* QLogic ISP2x00 Hardware Support Functions. */
62 /****************************************************************************/
65 * qla2x00_initialize_adapter
69 * ha = adapter block pointer.
75 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
78 uint8_t restart_risc = 0;
82 /* Clear adapter flags. */
84 ha->flags.reset_active = 0;
85 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
86 atomic_set(&ha->loop_state, LOOP_DOWN);
88 ha->sns_retry_cnt = 0;
90 ha->failback_delay = 0;
91 ha->flags.management_server_logged_in = 0;
92 ha->marker_needed = 0;
94 ha->isp_abort_cnt = 0;
95 ha->beacon_blink_led = 0;
97 rval = qla2x00_pci_config(ha);
99 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
104 qla2x00_reset_chip(ha);
106 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
107 qla2x00_nvram_config(ha);
109 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
113 * Try to configure the loop.
118 /* If firmware needs to be loaded */
119 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
120 if ((rval = qla2x00_chip_diag(ha)) == QLA_SUCCESS) {
121 rval = qla2x00_setup_chip(ha);
125 if (rval == QLA_SUCCESS &&
126 (rval = qla2x00_init_rings(ha)) == QLA_SUCCESS) {
127 check_fw_ready_again:
129 * Wait for a successful LIP up to a maximum
130 * of (in seconds): RISC login timeout value,
131 * RISC retry count value, and port down retry
132 * value OR a minimum of 4 seconds OR If no
133 * cable, only 5 seconds.
135 rval = qla2x00_fw_ready(ha);
136 if (rval == QLA_SUCCESS) {
137 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
140 * Wait at most MAX_TARGET RSCNs for a stable
145 clear_bit(LOOP_RESYNC_NEEDED,
147 rval = qla2x00_configure_loop(ha);
149 if (test_and_clear_bit(ISP_ABORT_NEEDED,
156 * If loop state change while we were
157 * discoverying devices then wait for
161 if (atomic_read(&ha->loop_state) ==
162 LOOP_DOWN && retry--) {
163 goto check_fw_ready_again;
166 } while (!atomic_read(&ha->loop_down_timer) &&
169 (test_bit(LOOP_RESYNC_NEEDED,
173 rval = QLA_FUNCTION_FAILED;
176 } else if (ha->device_flags & DFLG_NO_CABLE)
177 /* If no cable, then all is good. */
180 } while (restart_risc && retry--);
182 if (rval == QLA_SUCCESS) {
183 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
184 ha->marker_needed = 1;
185 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
186 ha->marker_needed = 0;
188 ha->flags.online = 1;
190 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
197 * qla2x00_pci_config() - Setup device PCI configuration registers.
200 * Returns 0 on success.
203 qla2x00_pci_config(scsi_qla_host_t *ha)
206 unsigned long flags = 0;
209 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
212 * Turn on PCI master; for system BIOSes that don't turn it on by
215 pci_set_master(ha->pdev);
217 if (pci_set_mwi(ha->pdev))
218 mwi = PCI_COMMAND_INVALIDATE;
219 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
222 return (QLA_FUNCTION_FAILED);
225 * We want to respect framework's setting of PCI configuration space
226 * command register and also want to make sure that all bits of
227 * interest to us are properly set in command register.
229 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
230 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
232 /* Get PCI bus information. */
233 spin_lock_irqsave(&ha->hardware_lock, flags);
234 ha->pci_attr = RD_REG_WORD(&ha->iobase->ctrl_status);
235 spin_unlock_irqrestore(&ha->hardware_lock, flags);
237 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
238 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
240 /* PCI Specification Revision 2.3 changes */
241 if (IS_QLA2322(ha) || IS_QLA6322(ha))
242 /* Command Register - Reset Interrupt Disable. */
243 w &= ~PCI_COMMAND_INTX_DISABLE;
246 * If this is a 2300 card and not 2312, reset the
247 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
248 * the 2310 also reports itself as a 2300 so we need to get the
249 * fb revision level -- a 6 indicates it really is a 2300 and
252 if (IS_QLA2300(ha)) {
253 spin_lock_irqsave(&ha->hardware_lock, flags);
256 WRT_REG_WORD(&ha->iobase->hccr, HCCR_PAUSE_RISC);
257 for (cnt = 0; cnt < 30000; cnt++) {
258 if ((RD_REG_WORD(&ha->iobase->hccr) &
259 HCCR_RISC_PAUSE) != 0)
265 /* Select FPM registers. */
266 WRT_REG_WORD(&ha->iobase->ctrl_status, 0x20);
267 RD_REG_WORD(&ha->iobase->ctrl_status);
269 /* Get the fb rev level */
270 ha->fb_rev = RD_FB_CMD_REG(ha, ha->iobase);
272 if (ha->fb_rev == FPM_2300)
273 w &= ~PCI_COMMAND_INVALIDATE;
275 /* Deselect FPM registers. */
276 WRT_REG_WORD(&ha->iobase->ctrl_status, 0x0);
277 RD_REG_WORD(&ha->iobase->ctrl_status);
279 /* Release RISC module. */
280 WRT_REG_WORD(&ha->iobase->hccr, HCCR_RELEASE_RISC);
281 for (cnt = 0; cnt < 30000; cnt++) {
282 if ((RD_REG_WORD(&ha->iobase->hccr) &
283 HCCR_RISC_PAUSE) == 0)
289 spin_unlock_irqrestore(&ha->hardware_lock, flags);
293 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
295 /* Reset expansion ROM address decode enable */
296 pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w);
297 w &= ~PCI_ROM_ADDRESS_ENABLE;
298 pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
300 return (QLA_SUCCESS);
304 * qla2x00_isp_firmware() - Choose firmware image.
307 * Returns 0 on success.
310 qla2x00_isp_firmware(scsi_qla_host_t *ha)
314 /* Assume loading risc code */
315 rval = QLA_FUNCTION_FAILED;
317 if (ha->flags.disable_risc_code_load) {
318 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
320 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
322 /* Verify checksum of loaded RISC code. */
323 rval = qla2x00_verify_checksum(ha);
327 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
335 * qla2x00_reset_chip() - Reset ISP chip.
338 * Returns 0 on success.
341 qla2x00_reset_chip(scsi_qla_host_t *ha)
343 unsigned long flags = 0;
344 device_reg_t __iomem *reg = ha->iobase;
346 unsigned long mbx_flags = 0;
349 /* Disable ISP interrupts. */
350 qla2x00_disable_intrs(ha);
352 spin_lock_irqsave(&ha->hardware_lock, flags);
354 /* Turn off master enable */
356 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
357 cmd &= ~PCI_COMMAND_MASTER;
358 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
360 if (!IS_QLA2100(ha)) {
362 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
363 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
364 for (cnt = 0; cnt < 30000; cnt++) {
365 if ((RD_REG_WORD(®->hccr) &
366 HCCR_RISC_PAUSE) != 0)
371 RD_REG_WORD(®->hccr); /* PCI Posting. */
375 /* Select FPM registers. */
376 WRT_REG_WORD(®->ctrl_status, 0x20);
377 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
379 /* FPM Soft Reset. */
380 WRT_REG_WORD(®->fpm_diag_config, 0x100);
381 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
383 /* Toggle Fpm Reset. */
384 if (!IS_QLA2200(ha)) {
385 WRT_REG_WORD(®->fpm_diag_config, 0x0);
386 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
389 /* Select frame buffer registers. */
390 WRT_REG_WORD(®->ctrl_status, 0x10);
391 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
393 /* Reset frame buffer FIFOs. */
394 if (IS_QLA2200(ha)) {
395 WRT_FB_CMD_REG(ha, reg, 0xa000);
396 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
398 WRT_FB_CMD_REG(ha, reg, 0x00fc);
400 /* Read back fb_cmd until zero or 3 seconds max */
401 for (cnt = 0; cnt < 3000; cnt++) {
402 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
408 /* Select RISC module registers. */
409 WRT_REG_WORD(®->ctrl_status, 0);
410 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
412 /* Reset RISC processor. */
413 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
414 RD_REG_WORD(®->hccr); /* PCI Posting. */
416 /* Release RISC processor. */
417 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
418 RD_REG_WORD(®->hccr); /* PCI Posting. */
421 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
422 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
424 /* Reset ISP chip. */
425 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
427 /* Wait for RISC to recover from reset. */
428 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
430 * It is necessary to for a delay here since the card doesn't
431 * respond to PCI reads during a reset. On some architectures
432 * this will result in an MCA.
435 for (cnt = 30000; cnt; cnt--) {
436 if ((RD_REG_WORD(®->ctrl_status) &
437 CSR_ISP_SOFT_RESET) == 0)
444 /* Reset RISC processor. */
445 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
447 WRT_REG_WORD(®->semaphore, 0);
449 /* Release RISC processor. */
450 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
451 RD_REG_WORD(®->hccr); /* PCI Posting. */
453 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
454 for (cnt = 0; cnt < 30000; cnt++) {
455 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
456 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
458 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) {
459 if (!(test_bit(ABORT_ISP_ACTIVE,
461 spin_unlock_irqrestore(
462 &ha->mbx_reg_lock, mbx_flags);
466 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
467 spin_unlock_irqrestore(&ha->mbx_reg_lock,
475 /* Turn on master enable */
476 cmd |= PCI_COMMAND_MASTER;
477 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
479 /* Disable RISC pause on FPM parity error. */
480 if (!IS_QLA2100(ha)) {
481 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
482 RD_REG_WORD(®->hccr); /* PCI Posting. */
485 spin_unlock_irqrestore(&ha->hardware_lock, flags);
489 * qla2x00_chip_diag() - Test chip for proper operation.
492 * Returns 0 on success.
495 qla2x00_chip_diag(scsi_qla_host_t *ha)
498 device_reg_t __iomem *reg = ha->iobase;
499 unsigned long flags = 0;
504 /* Assume a failed state */
505 rval = QLA_FUNCTION_FAILED;
507 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
508 ha->host_no, (u_long)®->flash_address));
510 spin_lock_irqsave(&ha->hardware_lock, flags);
512 /* Reset ISP chip. */
513 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
516 * We need to have a delay here since the card will not respond while
517 * in reset causing an MCA on some architectures.
520 data = qla2x00_debounce_register(®->ctrl_status);
521 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
523 data = RD_REG_WORD(®->ctrl_status);
528 goto chip_diag_failed;
530 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
533 /* Reset RISC processor. */
534 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
535 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
537 /* Workaround for QLA2312 PCI parity error */
538 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
539 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
540 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
542 data = RD_MAILBOX_REG(ha, reg, 0);
549 goto chip_diag_failed;
551 /* Check product ID of chip */
552 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
554 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
555 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
556 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
557 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
558 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
559 mb[3] != PROD_ID_3) {
560 qla_printk(KERN_WARNING, ha,
561 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
563 goto chip_diag_failed;
565 ha->product_id[0] = mb[1];
566 ha->product_id[1] = mb[2];
567 ha->product_id[2] = mb[3];
568 ha->product_id[3] = mb[4];
570 /* Adjust fw RISC transfer size */
571 if (ha->request_q_length > 1024)
572 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
574 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
575 ha->request_q_length;
577 if (IS_QLA2200(ha) &&
578 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
579 /* Limit firmware transfer size with a 2200A */
580 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
583 ha->fw_transfer_size = 128;
586 /* Wrap Incoming Mailboxes Test. */
587 spin_unlock_irqrestore(&ha->hardware_lock, flags);
589 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
590 rval = qla2x00_mbx_reg_test(ha);
592 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
594 qla_printk(KERN_WARNING, ha,
595 "Failed mailbox send register test\n");
598 /* Flag a successful rval */
601 spin_lock_irqsave(&ha->hardware_lock, flags);
605 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
606 "****\n", ha->host_no));
608 spin_unlock_irqrestore(&ha->hardware_lock, flags);
614 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
617 * Returns 0 on success.
620 qla2x00_resize_request_q(scsi_qla_host_t *ha)
623 uint16_t fw_iocb_cnt = 0;
624 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
625 dma_addr_t request_dma;
626 request_t *request_ring;
628 /* Valid only on recent ISPs. */
629 if (IS_QLA2100(ha) || IS_QLA2200(ha))
632 /* Retrieve IOCB counts available to the firmware. */
633 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
636 /* No point in continuing if current settings are sufficient. */
637 if (fw_iocb_cnt < 1024)
639 if (ha->request_q_length >= request_q_length)
642 /* Attempt to claim larger area for request queue. */
643 request_ring = dma_alloc_coherent(&ha->pdev->dev,
644 (request_q_length + 1) * sizeof(request_t), &request_dma,
646 if (request_ring == NULL)
649 /* Resize successful, report extensions. */
650 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
651 (ha->fw_memory_size + 1) / 1024);
652 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
653 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
655 /* Clear old allocations. */
656 dma_free_coherent(&ha->pdev->dev,
657 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
660 /* Begin using larger queue. */
661 ha->request_q_length = request_q_length;
662 ha->request_ring = request_ring;
663 ha->request_dma = request_dma;
667 * qla2x00_setup_chip() - Load and start RISC firmware.
670 * Returns 0 on success.
673 qla2x00_setup_chip(scsi_qla_host_t *ha)
678 unsigned long risc_address;
679 unsigned long risc_code_size;
683 struct qla_fw_info *fw_iter;
687 /* Load firmware sequences */
688 fw_iter = ha->brd_info->fw_info;
689 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
690 risc_code = fw_iter->fwcode;
691 risc_code_size = *fw_iter->fwlen;
693 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
694 risc_address = *fw_iter->fwstart;
696 /* Extended address */
697 risc_address = *fw_iter->lfwstart;
702 while (risc_code_size > 0 && !rval) {
703 cnt = (uint16_t)(ha->fw_transfer_size >> 1);
704 if (cnt > risc_code_size)
705 cnt = risc_code_size;
707 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
708 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
709 ha->host_no, risc_code, cnt, risc_address));
711 req_ring = (uint16_t *)ha->request_ring;
712 for (i = 0; i < cnt; i++)
713 req_ring[i] = cpu_to_le16(risc_code[i]);
715 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
716 rval = qla2x00_load_ram(ha,
717 ha->request_dma, risc_address, cnt);
719 rval = qla2x00_load_ram_ext(ha,
720 ha->request_dma, risc_address, cnt);
723 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
724 "load segment %d of firmware\n",
726 qla_printk(KERN_WARNING, ha,
727 "[ERROR] Failed to load "
728 "segment %d of firmware\n", num);
730 qla2x00_dump_regs(ha);
736 risc_code_size -= cnt;
740 /* Next firmware sequence */
744 /* Verify checksum of loaded RISC code. */
746 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
747 "code.\n", ha->host_no));
749 rval = qla2x00_verify_checksum(ha);
750 if (rval == QLA_SUCCESS) {
751 /* Start firmware execution. */
752 DEBUG(printk("scsi(%ld): Checksum OK, start "
753 "firmware.\n", ha->host_no));
755 rval = qla2x00_execute_fw(ha);
756 /* Retrieve firmware information. */
757 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
758 qla2x00_get_fw_version(ha,
759 &ha->fw_major_version,
760 &ha->fw_minor_version,
761 &ha->fw_subminor_version,
762 &ha->fw_attributes, &ha->fw_memory_size);
763 qla2x00_resize_request_q(ha);
766 DEBUG2(printk(KERN_INFO
767 "scsi(%ld): ISP Firmware failed checksum.\n",
773 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
781 * qla2x00_init_response_q_entries() - Initializes response queue entries.
784 * Beginning of request ring has initialization control block already built
785 * by nvram config routine.
787 * Returns 0 on success.
790 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
795 pkt = ha->response_ring_ptr;
796 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
797 pkt->signature = RESPONSE_PROCESSED;
804 * qla2x00_update_fw_options() - Read and process firmware options.
807 * Returns 0 on success.
810 qla2x00_update_fw_options(scsi_qla_host_t *ha)
812 uint16_t swing, emphasis, tx_sens, rx_sens;
814 memset(ha->fw_options, 0, sizeof(ha->fw_options));
815 qla2x00_get_fw_options(ha, ha->fw_options);
817 if (IS_QLA2100(ha) || IS_QLA2200(ha))
820 /* Serial Link options. */
821 DEBUG3(printk("scsi(%ld): Serial link options:\n",
823 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
824 sizeof(ha->fw_seriallink_options)));
826 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
827 if (ha->fw_seriallink_options[3] & BIT_2) {
828 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
831 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
832 emphasis = (ha->fw_seriallink_options[2] &
833 (BIT_4 | BIT_3)) >> 3;
834 tx_sens = ha->fw_seriallink_options[0] &
835 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
836 rx_sens = (ha->fw_seriallink_options[0] &
837 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
838 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
839 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
842 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
843 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
844 ha->fw_options[10] |= BIT_5 |
845 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
846 (tx_sens & (BIT_1 | BIT_0));
849 swing = (ha->fw_seriallink_options[2] &
850 (BIT_7 | BIT_6 | BIT_5)) >> 5;
851 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
852 tx_sens = ha->fw_seriallink_options[1] &
853 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
854 rx_sens = (ha->fw_seriallink_options[1] &
855 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
856 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
857 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
860 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
861 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
862 ha->fw_options[11] |= BIT_5 |
863 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
864 (tx_sens & (BIT_1 | BIT_0));
868 /* Return command IOCBs without waiting for an ABTS to complete. */
869 ha->fw_options[3] |= BIT_13;
872 if (ha->flags.enable_led_scheme)
873 ha->fw_options[2] |= BIT_12;
875 /* Update firmware options. */
876 qla2x00_set_fw_options(ha, ha->fw_options);
880 * qla2x00_init_rings() - Initializes firmware.
883 * Beginning of request ring has initialization control block already built
884 * by nvram config routine.
886 * Returns 0 on success.
889 qla2x00_init_rings(scsi_qla_host_t *ha)
892 unsigned long flags = 0;
894 device_reg_t __iomem *reg = ha->iobase;
896 spin_lock_irqsave(&ha->hardware_lock, flags);
898 /* Clear outstanding commands array. */
899 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
900 ha->outstanding_cmds[cnt] = NULL;
902 ha->current_outstanding_cmd = 0;
904 /* Clear RSCN queue. */
906 ha->rscn_out_ptr = 0;
908 /* Initialize firmware. */
909 ha->request_ring_ptr = ha->request_ring;
910 ha->req_ring_index = 0;
911 ha->req_q_cnt = ha->request_q_length;
912 ha->response_ring_ptr = ha->response_ring;
913 ha->rsp_ring_index = 0;
915 /* Setup ring parameters in initialization control block. */
916 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
917 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
918 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
919 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
920 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
921 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
922 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
923 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
925 /* Initialize response queue entries */
926 qla2x00_init_response_q_entries(ha);
928 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
929 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
930 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
931 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
932 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
934 spin_unlock_irqrestore(&ha->hardware_lock, flags);
936 /* Update any ISP specific firmware options before initialization. */
937 qla2x00_update_fw_options(ha);
939 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
940 rval = qla2x00_init_firmware(ha, sizeof(init_cb_t));
942 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
945 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
953 * qla2x00_fw_ready() - Waits for firmware ready.
956 * Returns 0 on success.
959 qla2x00_fw_ready(scsi_qla_host_t *ha)
962 unsigned long wtime, mtime;
963 uint16_t min_wait; /* Minimum wait time if loop is down */
964 uint16_t wait_time; /* Wait time if loop is coming ready */
969 /* 20 seconds for loop down. */
973 * Firmware should take at most one RATOV to login, plus 5 seconds for
974 * our own processing.
976 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
977 wait_time = min_wait;
980 /* Min wait time if loop down */
981 mtime = jiffies + (min_wait * HZ);
983 /* wait time before firmware ready */
984 wtime = jiffies + (wait_time * HZ);
986 /* Wait for ISP to finish LIP */
987 if (!ha->flags.init_done)
988 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
990 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
994 rval = qla2x00_get_firmware_state(ha, &fw_state);
995 if (rval == QLA_SUCCESS) {
996 if (fw_state < FSTATE_LOSS_OF_SYNC) {
997 ha->device_flags &= ~DFLG_NO_CABLE;
999 if (fw_state == FSTATE_READY) {
1000 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1003 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1004 &ha->login_timeout, &ha->r_a_tov);
1010 rval = QLA_FUNCTION_FAILED;
1012 if (atomic_read(&ha->loop_down_timer) &&
1013 (fw_state >= FSTATE_LOSS_OF_SYNC ||
1014 fw_state == FSTATE_WAIT_AL_PA)) {
1015 /* Loop down. Timeout on min_wait for states
1016 * other than Wait for Login.
1018 if (time_after_eq(jiffies, mtime)) {
1019 qla_printk(KERN_INFO, ha,
1020 "Cable is unplugged...\n");
1022 ha->device_flags |= DFLG_NO_CABLE;
1027 /* Mailbox cmd failed. Timeout on min_wait. */
1028 if (time_after_eq(jiffies, mtime))
1032 if (time_after_eq(jiffies, wtime))
1035 /* Delay for a while */
1038 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1039 ha->host_no, fw_state, jiffies));
1042 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1043 ha->host_no, fw_state, jiffies));
1046 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1054 * qla2x00_configure_hba
1055 * Setup adapter context.
1058 * ha = adapter state pointer.
1067 qla2x00_configure_hba(scsi_qla_host_t *ha)
1075 char connect_type[22];
1077 /* Get host addresses. */
1078 rval = qla2x00_get_adapter_id(ha,
1079 &loop_id, &al_pa, &area, &domain, &topo);
1080 if (rval != QLA_SUCCESS) {
1081 qla_printk(KERN_WARNING, ha,
1082 "ERROR -- Unable to get host loop ID.\n");
1083 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1088 qla_printk(KERN_INFO, ha,
1089 "Cannot get topology - retrying.\n");
1090 return (QLA_FUNCTION_FAILED);
1093 ha->loop_id = loop_id;
1096 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1097 ha->operating_mode = LOOP;
1101 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1103 ha->current_topology = ISP_CFG_NL;
1104 strcpy(connect_type, "(Loop)");
1108 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1110 ha->current_topology = ISP_CFG_FL;
1111 strcpy(connect_type, "(FL_Port)");
1115 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1117 ha->operating_mode = P2P;
1118 ha->current_topology = ISP_CFG_N;
1119 strcpy(connect_type, "(N_Port-to-N_Port)");
1123 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1125 ha->operating_mode = P2P;
1126 ha->current_topology = ISP_CFG_F;
1127 strcpy(connect_type, "(F_Port)");
1131 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1133 ha->host_no, topo));
1134 ha->current_topology = ISP_CFG_NL;
1135 strcpy(connect_type, "(Loop)");
1139 /* Save Host port and loop ID. */
1140 /* byte order - Big Endian */
1141 ha->d_id.b.domain = domain;
1142 ha->d_id.b.area = area;
1143 ha->d_id.b.al_pa = al_pa;
1145 if (!ha->flags.init_done)
1146 qla_printk(KERN_INFO, ha,
1147 "Topology - %s, Host Loop address 0x%x\n",
1148 connect_type, ha->loop_id);
1151 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1153 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1160 * NVRAM configuration for ISP 2xxx
1163 * ha = adapter block pointer.
1166 * initialization control block in response_ring
1167 * host adapters parameters in host adapter block
1173 qla2x00_nvram_config(scsi_qla_host_t *ha)
1178 uint8_t *dptr1, *dptr2;
1179 init_cb_t *icb = ha->init_cb;
1180 nvram_t *nv = (nvram_t *)ha->request_ring;
1181 uint16_t *wptr = (uint16_t *)ha->request_ring;
1182 device_reg_t __iomem *reg = ha->iobase;
1187 /* Determine NVRAM starting address. */
1189 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1190 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1191 ha->nvram_base = 0x80;
1193 /* Get NVRAM data and calculate checksum. */
1194 qla2x00_lock_nvram_access(ha);
1195 for (cnt = 0; cnt < sizeof(nvram_t)/2; cnt++) {
1196 *wptr = cpu_to_le16(qla2x00_get_nvram_word(ha,
1197 (cnt+ha->nvram_base)));
1198 chksum += (uint8_t)*wptr;
1199 chksum += (uint8_t)(*wptr >> 8);
1202 qla2x00_unlock_nvram_access(ha);
1204 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1205 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1208 /* Bad NVRAM data, set defaults parameters. */
1209 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1210 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1211 /* Reset NVRAM data. */
1212 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1213 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1215 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1216 "invalid -- WWPN) defaults.\n");
1219 * Set default initialization control block.
1221 memset(nv, 0, sizeof(nvram_t));
1222 nv->parameter_block_version = ICB_VERSION;
1224 if (IS_QLA23XX(ha)) {
1225 nv->firmware_options[0] = BIT_2 | BIT_1;
1226 nv->firmware_options[1] = BIT_7 | BIT_5;
1227 nv->add_firmware_options[0] = BIT_5;
1228 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1229 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1230 nv->special_options[1] = BIT_7;
1231 } else if (IS_QLA2200(ha)) {
1232 nv->firmware_options[0] = BIT_2 | BIT_1;
1233 nv->firmware_options[1] = BIT_7 | BIT_5;
1234 nv->add_firmware_options[0] = BIT_5;
1235 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1236 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1237 } else if (IS_QLA2100(ha)) {
1238 nv->firmware_options[0] = BIT_3 | BIT_1;
1239 nv->firmware_options[1] = BIT_5;
1240 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1243 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1244 nv->execution_throttle = __constant_cpu_to_le16(16);
1245 nv->retry_count = 8;
1246 nv->retry_delay = 1;
1248 nv->port_name[0] = 33;
1249 nv->port_name[3] = 224;
1250 nv->port_name[4] = 139;
1252 nv->login_timeout = 4;
1255 * Set default host adapter parameters
1257 nv->host_p[1] = BIT_2;
1258 nv->reset_delay = 5;
1259 nv->port_down_retry_count = 8;
1260 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1261 nv->link_down_timeout = 60;
1266 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1268 * The SN2 does not provide BIOS emulation which means you can't change
1269 * potentially bogus BIOS settings. Force the use of default settings
1270 * for link rate and frame size. Hope that the rest of the settings
1273 if (ia64_platform_is("sn2")) {
1274 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1276 nv->special_options[1] = BIT_7;
1280 /* Reset Initialization control block */
1281 memset(icb, 0, sizeof(init_cb_t));
1284 * Setup driver NVRAM options.
1286 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1287 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1288 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1289 nv->firmware_options[1] &= ~BIT_4;
1291 if (IS_QLA23XX(ha)) {
1292 nv->firmware_options[0] |= BIT_2;
1293 nv->firmware_options[0] &= ~BIT_3;
1295 if (IS_QLA2300(ha)) {
1296 if (ha->fb_rev == FPM_2310) {
1297 strcpy(ha->model_number, "QLA2310");
1299 strcpy(ha->model_number, "QLA2300");
1303 memcmp(nv->model_number, BINZERO,
1304 sizeof(nv->model_number)) != 0) {
1307 strncpy(ha->model_number, nv->model_number,
1308 sizeof(nv->model_number));
1309 st = en = ha->model_number;
1310 en += sizeof(nv->model_number) - 1;
1312 if (*en != 0x20 && *en != 0x00)
1319 index = (ha->pdev->subsystem_device & 0xff);
1320 if (index < QLA_MODEL_NAMES) {
1321 strcpy(ha->model_number,
1322 qla2x00_model_name[index]);
1324 qla2x00_model_desc[index];
1326 strcpy(ha->model_number, "QLA23xx");
1330 } else if (IS_QLA2200(ha)) {
1331 nv->firmware_options[0] |= BIT_2;
1333 * 'Point-to-point preferred, else loop' is not a safe
1334 * connection mode setting.
1336 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1338 /* Force 'loop preferred, else point-to-point'. */
1339 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1340 nv->add_firmware_options[0] |= BIT_5;
1342 strcpy(ha->model_number, "QLA22xx");
1343 } else /*if (IS_QLA2100(ha))*/ {
1344 strcpy(ha->model_number, "QLA2100");
1348 * Copy over NVRAM RISC parameter block to initialization control block.
1350 dptr1 = (uint8_t *)icb;
1351 dptr2 = (uint8_t *)&nv->parameter_block_version;
1352 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1354 *dptr1++ = *dptr2++;
1356 /* Copy 2nd half. */
1357 dptr1 = (uint8_t *)icb->add_firmware_options;
1358 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1360 *dptr1++ = *dptr2++;
1362 /* Prepare nodename */
1363 if ((icb->firmware_options[1] & BIT_6) == 0) {
1365 * Firmware will apply the following mask if the nodename was
1368 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1369 icb->node_name[0] &= 0xF0;
1373 * Set host adapter parameters.
1375 ha->nvram_version = nv->nvram_version;
1377 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1378 /* Always load RISC code on non ISP2[12]00 chips. */
1379 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1380 ha->flags.disable_risc_code_load = 0;
1381 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1382 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1383 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1384 ha->flags.enable_led_scheme = ((nv->efi_parameters & BIT_3) ? 1 : 0);
1386 ha->operating_mode =
1387 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1389 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1390 sizeof(ha->fw_seriallink_options));
1392 /* save HBA serial number */
1393 ha->serial0 = icb->port_name[5];
1394 ha->serial1 = icb->port_name[6];
1395 ha->serial2 = icb->port_name[7];
1396 memcpy(ha->node_name, icb->node_name, WWN_SIZE);
1398 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1400 ha->retry_count = nv->retry_count;
1402 /* Set minimum login_timeout to 4 seconds. */
1403 if (nv->login_timeout < ql2xlogintimeout)
1404 nv->login_timeout = ql2xlogintimeout;
1405 if (nv->login_timeout < 4)
1406 nv->login_timeout = 4;
1407 ha->login_timeout = nv->login_timeout;
1408 icb->login_timeout = nv->login_timeout;
1410 /* Set minimum RATOV to 200 tenths of a second. */
1413 ha->minimum_timeout =
1414 (ha->login_timeout * ha->retry_count) + nv->port_down_retry_count;
1415 ha->loop_reset_delay = nv->reset_delay;
1417 /* Will get the value from NVRAM. */
1418 ha->loop_down_timeout = LOOP_DOWN_TIMEOUT;
1420 /* Link Down Timeout = 0:
1422 * When Port Down timer expires we will start returning
1423 * I/O's to OS with "DID_NO_CONNECT".
1425 * Link Down Timeout != 0:
1427 * The driver waits for the link to come up after link down
1428 * before returning I/Os to OS with "DID_NO_CONNECT".
1430 if (nv->link_down_timeout == 0) {
1431 ha->loop_down_abort_time =
1432 (LOOP_DOWN_TIME - ha->loop_down_timeout);
1434 ha->link_down_timeout = nv->link_down_timeout;
1435 ha->loop_down_abort_time =
1436 (LOOP_DOWN_TIME - ha->link_down_timeout);
1439 ha->max_luns = MAX_LUNS;
1440 ha->max_probe_luns = le16_to_cpu(nv->max_luns_per_target);
1441 if (ha->max_probe_luns == 0)
1442 ha->max_probe_luns = MIN_LUNS;
1445 * Need enough time to try and get the port back.
1447 ha->port_down_retry_count = nv->port_down_retry_count;
1448 if (qlport_down_retry)
1449 ha->port_down_retry_count = qlport_down_retry;
1450 /* Set login_retry_count */
1451 ha->login_retry_count = nv->retry_count;
1452 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1453 ha->port_down_retry_count > 3)
1454 ha->login_retry_count = ha->port_down_retry_count;
1455 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1456 ha->login_retry_count = ha->port_down_retry_count;
1457 if (ql2xloginretrycount)
1458 ha->login_retry_count = ql2xloginretrycount;
1460 ha->binding_type = Bind;
1461 if (ha->binding_type != BIND_BY_PORT_NAME &&
1462 ha->binding_type != BIND_BY_PORT_ID) {
1463 qla_printk(KERN_WARNING, ha,
1464 "Invalid binding type specified (%d), "
1465 "defaulting to BIND_BY_PORT_NAME!!!\n", ha->binding_type);
1467 ha->binding_type = BIND_BY_PORT_NAME;
1470 icb->lun_enables = __constant_cpu_to_le16(0);
1471 icb->command_resource_count = 0;
1472 icb->immediate_notify_resource_count = 0;
1473 icb->timeout = __constant_cpu_to_le16(0);
1475 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1477 icb->firmware_options[0] &= ~BIT_3;
1478 icb->add_firmware_options[0] &=
1479 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1480 icb->add_firmware_options[0] |= BIT_2;
1481 icb->response_accumulation_timer = 3;
1482 icb->interrupt_delay_timer = 5;
1484 ha->flags.process_response_queue = 1;
1486 /* Enable ZIO -- Support mode 5 only. */
1487 timer_mode = icb->add_firmware_options[0] &
1488 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1489 icb->add_firmware_options[0] &=
1490 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1492 timer_mode = BIT_2 | BIT_0;
1493 if (timer_mode == (BIT_2 | BIT_0)) {
1494 DEBUG2(printk("scsi(%ld): ZIO enabled; timer delay "
1495 "(%d).\n", ha->host_no, ql2xintrdelaytimer));
1496 qla_printk(KERN_INFO, ha,
1497 "ZIO enabled; timer delay (%d).\n",
1498 ql2xintrdelaytimer);
1500 icb->add_firmware_options[0] |= timer_mode;
1501 icb->interrupt_delay_timer = ql2xintrdelaytimer;
1502 ha->flags.process_response_queue = 1;
1507 DEBUG2_3(printk(KERN_WARNING
1508 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1514 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1516 * @flags: allocation flags
1518 * Returns a pointer to the allocated fcport, or NULL, if none available.
1521 qla2x00_alloc_fcport(scsi_qla_host_t *ha, int flags)
1525 fcport = kmalloc(sizeof(fc_port_t), flags);
1529 /* Setup fcport template structure. */
1530 memset(fcport, 0, sizeof (fc_port_t));
1532 fcport->port_type = FCT_UNKNOWN;
1533 fcport->loop_id = FC_NO_LOOP_ID;
1534 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1535 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1536 fcport->flags = FCF_RLC_SUPPORT;
1542 * qla2x00_configure_loop
1543 * Updates Fibre Channel Device Database with what is actually on loop.
1546 * ha = adapter block pointer.
1551 * 2 = database was full and device was not configured.
1554 qla2x00_configure_loop(scsi_qla_host_t *ha)
1557 unsigned long flags, save_flags;
1561 /* Get Initiator ID */
1562 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1563 rval = qla2x00_configure_hba(ha);
1564 if (rval != QLA_SUCCESS) {
1565 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1571 save_flags = flags = ha->dpc_flags;
1572 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1573 ha->host_no, flags));
1576 * If we have both an RSCN and PORT UPDATE pending then handle them
1577 * both at the same time.
1579 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1580 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1583 /* Determine what we need to do */
1584 if (ha->current_topology == ISP_CFG_FL &&
1585 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1587 ha->flags.rscn_queue_overflow = 1;
1588 set_bit(RSCN_UPDATE, &flags);
1590 } else if (ha->current_topology == ISP_CFG_F &&
1591 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1593 ha->flags.rscn_queue_overflow = 1;
1594 set_bit(RSCN_UPDATE, &flags);
1595 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1597 } else if (!ha->flags.online ||
1598 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1600 ha->flags.rscn_queue_overflow = 1;
1601 set_bit(RSCN_UPDATE, &flags);
1602 set_bit(LOCAL_LOOP_UPDATE, &flags);
1605 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1606 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1607 rval = QLA_FUNCTION_FAILED;
1609 rval = qla2x00_configure_local_loop(ha);
1613 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1614 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1615 rval = QLA_FUNCTION_FAILED;
1617 rval = qla2x00_configure_fabric(ha);
1621 if (rval == QLA_SUCCESS) {
1622 if (atomic_read(&ha->loop_down_timer) ||
1623 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1624 rval = QLA_FUNCTION_FAILED;
1626 atomic_set(&ha->loop_state, LOOP_READY);
1628 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1633 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1634 __func__, ha->host_no));
1636 DEBUG3(printk("%s: exiting normally\n", __func__));
1639 /* Restore state if a resync event occured during processing */
1640 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1641 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1642 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1643 if (test_bit(RSCN_UPDATE, &save_flags))
1644 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1653 * qla2x00_configure_local_loop
1654 * Updates Fibre Channel Device Database with local loop devices.
1657 * ha = adapter block pointer.
1663 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1668 fc_port_t *fcport, *new_fcport;
1674 uint8_t domain, area, al_pa;
1678 entries = MAX_FIBRE_DEVICES;
1680 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1681 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1683 /* Get list of logged in devices. */
1684 memset(ha->gid_list, 0, GID_LIST_SIZE);
1685 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1687 if (rval != QLA_SUCCESS)
1688 goto cleanup_allocation;
1690 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1691 ha->host_no, entries));
1692 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1693 entries * sizeof(struct gid_list_info)));
1695 /* Allocate temporary fcport for any new fcports discovered. */
1696 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1697 if (new_fcport == NULL) {
1698 rval = QLA_MEMORY_ALLOC_FAILED;
1699 goto cleanup_allocation;
1701 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1704 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1706 list_for_each_entry(fcport, &ha->fcports, list) {
1707 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1708 fcport->port_type != FCT_BROADCAST &&
1709 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1711 DEBUG(printk("scsi(%ld): Marking port lost, "
1713 ha->host_no, fcport->loop_id));
1715 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1716 fcport->flags &= ~FCF_FARP_DONE;
1720 /* Add devices to port list. */
1721 id_iter = (char *)ha->gid_list;
1722 for (index = 0; index < entries; index++) {
1723 domain = ((struct gid_list_info *)id_iter)->domain;
1724 area = ((struct gid_list_info *)id_iter)->area;
1725 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1726 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1727 loop_id = (uint16_t)
1728 ((struct gid_list_info *)id_iter)->loop_id_2100;
1731 loop_id = le16_to_cpu(
1732 ((struct gid_list_info *)id_iter)->loop_id);
1736 /* Bypass reserved domain fields. */
1737 if ((domain & 0xf0) == 0xf0)
1740 /* Bypass if not same domain and area of adapter. */
1741 if (area != ha->d_id.b.area || domain != ha->d_id.b.domain)
1744 /* Bypass invalid local loop ID. */
1745 if (loop_id > LAST_LOCAL_LOOP_ID)
1748 /* Fill in member data. */
1749 new_fcport->d_id.b.domain = domain;
1750 new_fcport->d_id.b.area = area;
1751 new_fcport->d_id.b.al_pa = al_pa;
1752 new_fcport->loop_id = loop_id;
1753 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1754 if (rval2 != QLA_SUCCESS) {
1755 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1756 "information -- get_port_database=%x, "
1758 ha->host_no, rval2, new_fcport->loop_id));
1762 /* Check for matching device in port list. */
1765 list_for_each_entry(fcport, &ha->fcports, list) {
1766 if (memcmp(new_fcport->port_name, fcport->port_name,
1770 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1771 FCF_PERSISTENT_BOUND);
1772 fcport->loop_id = new_fcport->loop_id;
1773 fcport->port_type = new_fcport->port_type;
1774 fcport->d_id.b24 = new_fcport->d_id.b24;
1775 memcpy(fcport->node_name, new_fcport->node_name,
1783 /* New device, add to fcports list. */
1784 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1785 list_add_tail(&new_fcport->list, &ha->fcports);
1787 /* Allocate a new replacement fcport. */
1788 fcport = new_fcport;
1789 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1790 if (new_fcport == NULL) {
1791 rval = QLA_MEMORY_ALLOC_FAILED;
1792 goto cleanup_allocation;
1794 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1797 qla2x00_update_fcport(ha, fcport);
1806 if (rval != QLA_SUCCESS) {
1807 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1808 "rval=%x\n", ha->host_no, rval));
1812 ha->device_flags |= DFLG_LOCAL_DEVICES;
1813 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
1820 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
1824 qla2x00_mark_all_devices_lost(ha);
1825 list_for_each_entry(fcport, &ha->fcports, list) {
1826 if (fcport->port_type != FCT_TARGET)
1829 qla2x00_update_fcport(ha, fcport);
1834 * qla2x00_update_fcport
1835 * Updates device on list.
1838 * ha = adapter block pointer.
1839 * fcport = port structure pointer.
1849 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
1852 unsigned long flags;
1856 fcport->login_retry = 0;
1857 fcport->port_login_retry_count = ha->port_down_retry_count *
1859 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
1861 fcport->flags &= ~FCF_LOGIN_NEEDED;
1864 * Check for outstanding cmd on tape Bypass LUN discovery if active
1867 if (fcport->flags & FCF_TAPE_PRESENT) {
1868 spin_lock_irqsave(&ha->hardware_lock, flags);
1869 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
1872 if ((sp = ha->outstanding_cmds[index]) != 0) {
1874 if (sfcp == fcport) {
1875 atomic_set(&fcport->state, FCS_ONLINE);
1876 spin_unlock_irqrestore(
1877 &ha->hardware_lock, flags);
1882 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1885 if (fcport->port_type == FCT_INITIATOR ||
1886 fcport->port_type == FCT_BROADCAST)
1887 fcport->device_type = TYPE_PROCESSOR;
1889 atomic_set(&fcport->state, FCS_ONLINE);
1891 if (ha->flags.init_done)
1892 qla2x00_reg_remote_port(ha, fcport);
1896 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
1898 struct fc_rport_identifiers rport_ids;
1899 struct fc_rport *rport;
1901 if (fcport->rport) {
1902 fc_remote_port_unblock(fcport->rport);
1906 rport_ids.node_name = be64_to_cpu(*(uint64_t *)fcport->node_name);
1907 rport_ids.port_name = be64_to_cpu(*(uint64_t *)fcport->port_name);
1908 rport_ids.port_id = fcport->d_id.b.domain << 16 |
1909 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
1910 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
1911 if (fcport->port_type == FCT_INITIATOR)
1912 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1913 if (fcport->port_type == FCT_TARGET)
1914 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1916 fcport->rport = rport = fc_remote_port_add(ha->host, 0, &rport_ids);
1918 qla_printk(KERN_WARNING, ha,
1919 "Unable to allocate fc remote port!\n");
1921 if (rport->scsi_target_id != -1 && rport->scsi_target_id < MAX_TARGETS)
1922 fcport->os_target_id = rport->scsi_target_id;
1924 rport->dd_data = fcport;
1928 * qla2x00_configure_fabric
1929 * Setup SNS devices with loop ID's.
1932 * ha = adapter block pointer.
1939 qla2x00_configure_fabric(scsi_qla_host_t *ha)
1942 fc_port_t *fcport, *fcptemp;
1943 uint16_t next_loopid;
1944 uint16_t mb[MAILBOX_REGISTER_COUNT];
1945 LIST_HEAD(new_fcports);
1947 /* If FL port exists, then SNS is present */
1948 rval = qla2x00_get_port_name(ha, SNS_FL_PORT, NULL, 0);
1949 if (rval != QLA_SUCCESS) {
1950 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
1951 "Port\n", ha->host_no));
1953 ha->device_flags &= ~SWITCH_FOUND;
1954 return (QLA_SUCCESS);
1957 /* Mark devices that need re-synchronization. */
1958 rval2 = qla2x00_device_resync(ha);
1959 if (rval2 == QLA_RSCNS_HANDLED) {
1960 /* No point doing the scan, just continue. */
1961 return (QLA_SUCCESS);
1964 /* Ensure we are logged into the SNS. */
1965 qla2x00_login_fabric(ha, SIMPLE_NAME_SERVER, 0xff, 0xff, 0xfc,
1967 if (mb[0] != MBS_COMMAND_COMPLETE) {
1968 DEBUG2(qla_printk(KERN_INFO, ha,
1969 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
1970 "mb[2]=%x mb[6]=%x mb[7]=%x\n", SIMPLE_NAME_SERVER,
1971 mb[0], mb[1], mb[2], mb[6], mb[7]));
1972 return (QLA_SUCCESS);
1975 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
1976 if (qla2x00_rft_id(ha)) {
1978 DEBUG2(printk("scsi(%ld): Register FC-4 "
1979 "TYPE failed.\n", ha->host_no));
1981 if (qla2x00_rff_id(ha)) {
1983 DEBUG2(printk("scsi(%ld): Register FC-4 "
1984 "Features failed.\n", ha->host_no));
1986 if (qla2x00_rnn_id(ha)) {
1988 DEBUG2(printk("scsi(%ld): Register Node Name "
1989 "failed.\n", ha->host_no));
1990 } else if (qla2x00_rsnn_nn(ha)) {
1992 DEBUG2(printk("scsi(%ld): Register Symbolic "
1993 "Node Name failed.\n", ha->host_no));
1997 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
1998 if (rval != QLA_SUCCESS)
2002 * Logout all previous fabric devices marked lost, except
2005 list_for_each_entry(fcport, &ha->fcports, list) {
2006 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2009 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2012 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2013 qla2x00_mark_device_lost(ha, fcport,
2014 ql2xplogiabsentdevice);
2015 if (fcport->loop_id != FC_NO_LOOP_ID &&
2016 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2017 fcport->port_type != FCT_INITIATOR &&
2018 fcport->port_type != FCT_BROADCAST) {
2020 qla2x00_fabric_logout(ha,
2022 fcport->loop_id = FC_NO_LOOP_ID;
2027 /* Starting free loop ID. */
2028 next_loopid = ha->min_external_loopid;
2031 * Scan through our port list and login entries that need to be
2034 list_for_each_entry(fcport, &ha->fcports, list) {
2035 if (atomic_read(&ha->loop_down_timer) ||
2036 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2039 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2040 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2043 if (fcport->loop_id == FC_NO_LOOP_ID) {
2044 fcport->loop_id = next_loopid;
2045 rval = qla2x00_find_new_loop_id(ha, fcport);
2046 if (rval != QLA_SUCCESS) {
2047 /* Ran out of IDs to use */
2052 /* Login and update database */
2053 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2056 /* Exit if out of loop IDs. */
2057 if (rval != QLA_SUCCESS) {
2062 * Login and add the new devices to our port list.
2064 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2065 if (atomic_read(&ha->loop_down_timer) ||
2066 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2069 /* Find a new loop ID to use. */
2070 fcport->loop_id = next_loopid;
2071 rval = qla2x00_find_new_loop_id(ha, fcport);
2072 if (rval != QLA_SUCCESS) {
2073 /* Ran out of IDs to use */
2077 /* Remove device from the new list and add it to DB */
2078 list_del(&fcport->list);
2079 list_add_tail(&fcport->list, &ha->fcports);
2081 /* Login and update database */
2082 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2086 /* Free all new device structures not processed. */
2087 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2088 list_del(&fcport->list);
2093 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2094 "rval=%d\n", ha->host_no, rval));
2102 * qla2x00_find_all_fabric_devs
2105 * ha = adapter block pointer.
2106 * dev = database device entry pointer.
2115 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2119 fc_port_t *fcport, *new_fcport, *fcptemp;
2124 int first_dev, last_dev;
2125 port_id_t wrap, nxt_d_id;
2129 /* Try GID_PT to get device list, else GAN. */
2130 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2133 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2134 "on GA_NXT\n", ha->host_no));
2136 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2137 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2140 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2143 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2150 /* Allocate temporary fcport for any new fcports discovered. */
2151 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2152 if (new_fcport == NULL) {
2155 return (QLA_MEMORY_ALLOC_FAILED);
2157 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2159 /* Set start port ID scan at adapter ID. */
2163 /* Starting free loop ID. */
2164 loop_id = ha->min_external_loopid;
2166 for (; loop_id <= ha->last_loop_id; loop_id++) {
2167 if (RESERVED_LOOP_ID(loop_id))
2170 if (atomic_read(&ha->loop_down_timer) ||
2171 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2176 wrap.b24 = new_fcport->d_id.b24;
2178 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2179 memcpy(new_fcport->node_name,
2180 swl[swl_idx].node_name, WWN_SIZE);
2181 memcpy(new_fcport->port_name,
2182 swl[swl_idx].port_name, WWN_SIZE);
2184 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2190 /* Send GA_NXT to the switch */
2191 rval = qla2x00_ga_nxt(ha, new_fcport);
2192 if (rval != QLA_SUCCESS) {
2193 qla_printk(KERN_WARNING, ha,
2194 "SNS scan failed -- assuming zero-entry "
2196 list_for_each_entry_safe(fcport, fcptemp,
2197 new_fcports, list) {
2198 list_del(&fcport->list);
2206 /* If wrap on switch device list, exit. */
2208 wrap.b24 = new_fcport->d_id.b24;
2210 } else if (new_fcport->d_id.b24 == wrap.b24) {
2211 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2212 ha->host_no, new_fcport->d_id.b.domain,
2213 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2217 /* Bypass if host adapter. */
2218 if (new_fcport->d_id.b24 == ha->d_id.b24)
2221 /* Bypass reserved domain fields. */
2222 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2225 /* Locate matching device in database. */
2227 list_for_each_entry(fcport, &ha->fcports, list) {
2228 if (memcmp(new_fcport->port_name, fcport->port_name,
2235 * If address the same and state FCS_ONLINE, nothing
2238 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2239 atomic_read(&fcport->state) == FCS_ONLINE) {
2244 * If device was not a fabric device before.
2246 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2247 fcport->d_id.b24 = new_fcport->d_id.b24;
2248 fcport->loop_id = FC_NO_LOOP_ID;
2249 fcport->flags |= (FCF_FABRIC_DEVICE |
2251 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2256 * Port ID changed or device was marked to be updated;
2257 * Log it out if still logged in and mark it for
2260 fcport->d_id.b24 = new_fcport->d_id.b24;
2261 fcport->flags |= FCF_LOGIN_NEEDED;
2262 if (fcport->loop_id != FC_NO_LOOP_ID &&
2263 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2264 fcport->port_type != FCT_INITIATOR &&
2265 fcport->port_type != FCT_BROADCAST) {
2266 qla2x00_fabric_logout(ha, fcport->loop_id);
2267 fcport->loop_id = FC_NO_LOOP_ID;
2276 /* If device was not in our fcports list, then add it. */
2277 list_add_tail(&new_fcport->list, new_fcports);
2279 /* Allocate a new replacement fcport. */
2280 nxt_d_id.b24 = new_fcport->d_id.b24;
2281 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2282 if (new_fcport == NULL) {
2285 return (QLA_MEMORY_ALLOC_FAILED);
2287 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2288 new_fcport->d_id.b24 = nxt_d_id.b24;
2297 if (!list_empty(new_fcports))
2298 ha->device_flags |= DFLG_FABRIC_DEVICES;
2304 * qla2x00_find_new_loop_id
2305 * Scan through our port list and find a new usable loop ID.
2308 * ha: adapter state pointer.
2309 * dev: port structure pointer.
2312 * qla2x00 local function return status code.
2318 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2323 uint16_t first_loop_id;
2327 /* Save starting loop ID. */
2328 first_loop_id = dev->loop_id;
2331 /* Skip loop ID if already used by adapter. */
2332 if (dev->loop_id == ha->loop_id) {
2336 /* Skip reserved loop IDs. */
2337 while (RESERVED_LOOP_ID(dev->loop_id)) {
2341 /* Reset loop ID if passed the end. */
2342 if (dev->loop_id > ha->last_loop_id) {
2343 /* first loop ID. */
2344 dev->loop_id = ha->min_external_loopid;
2347 /* Check for loop ID being already in use. */
2350 list_for_each_entry(fcport, &ha->fcports, list) {
2351 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2352 /* ID possibly in use */
2358 /* If not in use then it is free to use. */
2363 /* ID in use. Try next value. */
2366 /* If wrap around. No free ID to use. */
2367 if (dev->loop_id == first_loop_id) {
2368 dev->loop_id = FC_NO_LOOP_ID;
2369 rval = QLA_FUNCTION_FAILED;
2378 * qla2x00_device_resync
2379 * Marks devices in the database that needs resynchronization.
2382 * ha = adapter block pointer.
2388 qla2x00_device_resync(scsi_qla_host_t *ha)
2394 uint32_t rscn_entry;
2395 uint8_t rscn_out_iter;
2399 rval = QLA_RSCNS_HANDLED;
2401 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2402 ha->flags.rscn_queue_overflow) {
2404 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2405 format = MSB(MSW(rscn_entry));
2406 d_id.b.domain = LSB(MSW(rscn_entry));
2407 d_id.b.area = MSB(LSW(rscn_entry));
2408 d_id.b.al_pa = LSB(LSW(rscn_entry));
2410 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2411 "[%02x/%02x%02x%02x].\n",
2412 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2413 d_id.b.area, d_id.b.al_pa));
2416 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2417 ha->rscn_out_ptr = 0;
2419 /* Skip duplicate entries. */
2420 for (rscn_out_iter = ha->rscn_out_ptr;
2421 !ha->flags.rscn_queue_overflow &&
2422 rscn_out_iter != ha->rscn_in_ptr;
2423 rscn_out_iter = (rscn_out_iter ==
2424 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2426 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2429 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2430 "entry found at [%d].\n", ha->host_no,
2433 ha->rscn_out_ptr = rscn_out_iter;
2436 /* Queue overflow, set switch default case. */
2437 if (ha->flags.rscn_queue_overflow) {
2438 DEBUG(printk("scsi(%ld): device_resync: rscn "
2439 "overflow.\n", ha->host_no));
2442 ha->flags.rscn_queue_overflow = 0;
2447 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) &&
2448 !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
2449 ha->flags.init_done) {
2450 /* Handle port RSCN via asyncronous IOCBs */
2451 rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
2453 if (rval2 == QLA_SUCCESS)
2467 ha->rscn_out_ptr = ha->rscn_in_ptr;
2473 /* Abort any outstanding IO descriptors. */
2474 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2475 qla2x00_cancel_io_descriptors(ha);
2477 list_for_each_entry(fcport, &ha->fcports, list) {
2478 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2479 (fcport->d_id.b24 & mask) != d_id.b24 ||
2480 fcport->port_type == FCT_BROADCAST)
2483 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2485 fcport->port_type != FCT_INITIATOR) {
2486 qla2x00_mark_device_lost(ha, fcport, 0);
2489 fcport->flags &= ~FCF_FARP_DONE;
2496 * qla2x00_fabric_dev_login
2497 * Login fabric target device and update FC port database.
2500 * ha: adapter state pointer.
2501 * fcport: port structure list pointer.
2502 * next_loopid: contains value of a new loop ID that can be used
2503 * by the next login attempt.
2506 * qla2x00 local function return status code.
2512 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2513 uint16_t *next_loopid)
2521 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2522 if (rval == QLA_SUCCESS) {
2523 rval = qla2x00_get_port_database(ha, fcport, 0);
2524 if (rval != QLA_SUCCESS) {
2525 qla2x00_fabric_logout(ha, fcport->loop_id);
2527 qla2x00_update_fcport(ha, fcport);
2535 * qla2x00_fabric_login
2536 * Issue fabric login command.
2539 * ha = adapter block pointer.
2540 * device = pointer to FC device type structure.
2543 * 0 - Login successfully
2545 * 2 - Initiator device
2549 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2550 uint16_t *next_loopid)
2554 uint16_t tmp_loopid;
2555 uint16_t mb[MAILBOX_REGISTER_COUNT];
2561 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2562 "for port %02x%02x%02x.\n",
2563 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2564 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2566 /* Login fcport on switch. */
2567 qla2x00_login_fabric(ha, fcport->loop_id,
2568 fcport->d_id.b.domain, fcport->d_id.b.area,
2569 fcport->d_id.b.al_pa, mb, BIT_0);
2570 if (mb[0] == MBS_PORT_ID_USED) {
2572 * Device has another loop ID. The firmware team
2573 * recommends us to perform an implicit login with the
2574 * specified ID again. The ID we just used is save here
2575 * so we return with an ID that can be tried by the
2579 tmp_loopid = fcport->loop_id;
2580 fcport->loop_id = mb[1];
2582 DEBUG(printk("Fabric Login: port in use - next "
2583 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2584 fcport->loop_id, fcport->d_id.b.domain,
2585 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2587 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2592 /* A retry occurred before. */
2593 *next_loopid = tmp_loopid;
2596 * No retry occurred before. Just increment the
2597 * ID value for next login.
2599 *next_loopid = (fcport->loop_id + 1);
2602 if (mb[1] & BIT_0) {
2603 fcport->port_type = FCT_INITIATOR;
2605 fcport->port_type = FCT_TARGET;
2606 if (mb[1] & BIT_1) {
2607 fcport->flags |= FCF_TAPE_PRESENT;
2613 } else if (mb[0] == MBS_LOOP_ID_USED) {
2615 * Loop ID already used, try next loop ID.
2618 rval = qla2x00_find_new_loop_id(ha, fcport);
2619 if (rval != QLA_SUCCESS) {
2620 /* Ran out of loop IDs to use */
2623 } else if (mb[0] == MBS_COMMAND_ERROR) {
2625 * Firmware possibly timed out during login. If NO
2626 * retries are left to do then the device is declared
2629 *next_loopid = fcport->loop_id;
2630 qla2x00_fabric_logout(ha, fcport->loop_id);
2631 qla2x00_mark_device_lost(ha, fcport, 1);
2637 * unrecoverable / not handled error
2639 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2640 "loop_id=%x jiffies=%lx.\n",
2641 __func__, ha->host_no, mb[0],
2642 fcport->d_id.b.domain, fcport->d_id.b.area,
2643 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2645 *next_loopid = fcport->loop_id;
2646 qla2x00_fabric_logout(ha, fcport->loop_id);
2647 fcport->loop_id = FC_NO_LOOP_ID;
2648 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
2659 * qla2x00_local_device_login
2660 * Issue local device login command.
2663 * ha = adapter block pointer.
2664 * loop_id = loop id of device to login to.
2666 * Returns (Where's the #define!!!!):
2667 * 0 - Login successfully
2672 qla2x00_local_device_login(scsi_qla_host_t *ha, uint16_t loop_id)
2675 uint16_t mb[MAILBOX_REGISTER_COUNT];
2677 memset(mb, 0, sizeof(mb));
2678 rval = qla2x00_login_local_device(ha, loop_id, mb, BIT_0);
2679 if (rval == QLA_SUCCESS) {
2680 /* Interrogate mailbox registers for any errors */
2681 if (mb[0] == MBS_COMMAND_ERROR)
2683 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
2684 /* device not in PCB table */
2692 * qla2x00_loop_resync
2693 * Resync with fibre channel devices.
2696 * ha = adapter block pointer.
2702 qla2x00_loop_resync(scsi_qla_host_t *ha)
2709 atomic_set(&ha->loop_state, LOOP_UPDATE);
2710 qla2x00_stats.loop_resync++;
2711 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2712 if (ha->flags.online) {
2713 if (!(rval = qla2x00_fw_ready(ha))) {
2714 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2718 atomic_set(&ha->loop_state, LOOP_UPDATE);
2721 * Issue marker command only when we are going
2722 * to start the I/O .
2724 ha->marker_needed = 1;
2726 /* Remap devices on Loop. */
2727 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2729 qla2x00_configure_loop(ha);
2731 } while (!atomic_read(&ha->loop_down_timer) &&
2732 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
2734 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
2738 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2739 return (QLA_FUNCTION_FAILED);
2743 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
2750 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
2756 list_for_each_entry(fcport, &ha->fcports, list) {
2757 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
2760 qla2x00_update_fcport(ha, fcport);
2761 fcport->flags &= ~FCF_RESCAN_NEEDED;
2765 qla2x00_probe_for_all_luns(ha);
2770 * Resets ISP and aborts all outstanding commands.
2773 * ha = adapter block pointer.
2779 qla2x00_abort_isp(scsi_qla_host_t *ha)
2781 unsigned long flags = 0;
2786 if (ha->flags.online) {
2787 ha->flags.online = 0;
2788 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2789 qla2x00_stats.ispAbort++;
2790 ha->total_isp_aborts++; /* used by ioctl */
2791 ha->sns_retry_cnt = 0;
2793 qla_printk(KERN_INFO, ha,
2794 "Performing ISP error recovery - ha= %p.\n", ha);
2795 qla2x00_reset_chip(ha);
2797 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
2798 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
2799 atomic_set(&ha->loop_state, LOOP_DOWN);
2800 qla2x00_mark_all_devices_lost(ha);
2802 if (!atomic_read(&ha->loop_down_timer))
2803 atomic_set(&ha->loop_down_timer,
2807 spin_lock_irqsave(&ha->hardware_lock, flags);
2808 /* Requeue all commands in outstanding command list. */
2809 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
2810 sp = ha->outstanding_cmds[cnt];
2812 ha->outstanding_cmds[cnt] = NULL;
2816 sp->cmd->result = DID_RESET << 16;
2817 sp->cmd->host_scribble = (unsigned char *)NULL;
2818 qla2x00_sp_compl(ha, sp);
2821 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2823 qla2x00_nvram_config(ha);
2825 if (!qla2x00_restart_isp(ha)) {
2826 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2828 if (!atomic_read(&ha->loop_down_timer)) {
2830 * Issue marker command only when we are going
2831 * to start the I/O .
2833 ha->marker_needed = 1;
2836 ha->flags.online = 1;
2838 /* Enable ISP interrupts. */
2839 qla2x00_enable_intrs(ha);
2841 ha->isp_abort_cnt = 0;
2842 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2843 } else { /* failed the ISP abort */
2844 ha->flags.online = 1;
2845 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
2846 if (ha->isp_abort_cnt == 0) {
2847 qla_printk(KERN_WARNING, ha,
2848 "ISP error recovery failed - "
2849 "board disabled\n");
2851 * The next call disables the board
2854 qla2x00_reset_adapter(ha);
2855 ha->flags.online = 0;
2856 clear_bit(ISP_ABORT_RETRY,
2859 } else { /* schedule another ISP abort */
2860 ha->isp_abort_cnt--;
2861 DEBUG(printk("qla%ld: ISP abort - "
2862 "retry remainning %d\n",
2863 ha->host_no, ha->isp_abort_cnt);)
2867 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
2868 DEBUG(printk("qla2x00(%ld): ISP error recovery "
2869 "- retrying (%d) more times\n",
2870 ha->host_no, ha->isp_abort_cnt);)
2871 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2879 qla_printk(KERN_INFO, ha,
2880 "qla2x00_abort_isp: **** FAILED ****\n");
2882 DEBUG(printk(KERN_INFO
2883 "qla2x00_abort_isp(%ld): exiting.\n",
2891 * qla2x00_restart_isp
2892 * restarts the ISP after a reset
2895 * ha = adapter block pointer.
2901 qla2x00_restart_isp(scsi_qla_host_t *ha)
2904 device_reg_t __iomem *reg = ha->iobase;
2905 unsigned long flags = 0;
2908 /* If firmware needs to be loaded */
2909 if (qla2x00_isp_firmware(ha)) {
2910 ha->flags.online = 0;
2911 if (!(status = qla2x00_chip_diag(ha))) {
2912 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2913 status = qla2x00_setup_chip(ha);
2919 spin_lock_irqsave(&ha->hardware_lock, flags);
2921 /* Disable SRAM, Instruction RAM and GP RAM parity. */
2922 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
2923 RD_REG_WORD(®->hccr); /* PCI Posting. */
2925 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2927 status = qla2x00_setup_chip(ha);
2929 spin_lock_irqsave(&ha->hardware_lock, flags);
2931 /* Enable proper parity */
2934 WRT_REG_WORD(®->hccr,
2935 (HCCR_ENABLE_PARITY + 0x1));
2937 /* SRAM, Instruction RAM and GP RAM parity */
2938 WRT_REG_WORD(®->hccr,
2939 (HCCR_ENABLE_PARITY + 0x7));
2940 RD_REG_WORD(®->hccr); /* PCI Posting. */
2942 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2947 if (!status && !(status = qla2x00_init_rings(ha))) {
2948 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2949 if (!(status = qla2x00_fw_ready(ha))) {
2950 DEBUG(printk("%s(): Start configure loop, "
2954 ha->flags.online = 1;
2955 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2958 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2959 qla2x00_configure_loop(ha);
2961 } while (!atomic_read(&ha->loop_down_timer) &&
2962 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
2964 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
2967 /* if no cable then assume it's good */
2968 if ((ha->device_flags & DFLG_NO_CABLE))
2971 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
2979 * qla2x00_reset_adapter
2983 * ha = adapter block pointer.
2986 qla2x00_reset_adapter(scsi_qla_host_t *ha)
2988 unsigned long flags = 0;
2989 device_reg_t __iomem *reg = ha->iobase;
2991 ha->flags.online = 0;
2992 qla2x00_disable_intrs(ha);
2994 /* Reset RISC processor. */
2995 spin_lock_irqsave(&ha->hardware_lock, flags);
2996 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2997 RD_REG_WORD(®->hccr); /* PCI Posting. */
2998 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2999 RD_REG_WORD(®->hccr); /* PCI Posting. */
3000 spin_unlock_irqrestore(&ha->hardware_lock, flags);