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)
199 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
201 pci_set_master(ha->pdev);
203 if (pci_set_mwi(ha->pdev))
204 mwi = PCI_COMMAND_INVALIDATE;
205 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
207 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
208 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
209 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
211 /* Reset expansion ROM address decode enable */
212 pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w);
213 w &= ~PCI_ROM_ADDRESS_ENABLE;
214 pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
216 /* Get PCI bus information. */
217 spin_lock_irqsave(&ha->hardware_lock, flags);
218 ha->pci_attr = RD_REG_WORD(&ha->iobase->ctrl_status);
219 spin_unlock_irqrestore(&ha->hardware_lock, flags);
225 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
228 * Returns 0 on success.
231 qla2300_pci_config(scsi_qla_host_t *ha)
234 unsigned long flags = 0;
237 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
239 pci_set_master(ha->pdev);
241 if (pci_set_mwi(ha->pdev))
242 mwi = PCI_COMMAND_INVALIDATE;
243 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
245 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
246 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
248 if (IS_QLA2322(ha) || IS_QLA6322(ha))
249 w &= ~PCI_COMMAND_INTX_DISABLE;
252 * If this is a 2300 card and not 2312, reset the
253 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
254 * the 2310 also reports itself as a 2300 so we need to get the
255 * fb revision level -- a 6 indicates it really is a 2300 and
258 if (IS_QLA2300(ha)) {
259 spin_lock_irqsave(&ha->hardware_lock, flags);
262 WRT_REG_WORD(&ha->iobase->hccr, HCCR_PAUSE_RISC);
263 for (cnt = 0; cnt < 30000; cnt++) {
264 if ((RD_REG_WORD(&ha->iobase->hccr) &
265 HCCR_RISC_PAUSE) != 0)
271 /* Select FPM registers. */
272 WRT_REG_WORD(&ha->iobase->ctrl_status, 0x20);
273 RD_REG_WORD(&ha->iobase->ctrl_status);
275 /* Get the fb rev level */
276 ha->fb_rev = RD_FB_CMD_REG(ha, ha->iobase);
278 if (ha->fb_rev == FPM_2300)
279 w &= ~PCI_COMMAND_INVALIDATE;
281 /* Deselect FPM registers. */
282 WRT_REG_WORD(&ha->iobase->ctrl_status, 0x0);
283 RD_REG_WORD(&ha->iobase->ctrl_status);
285 /* Release RISC module. */
286 WRT_REG_WORD(&ha->iobase->hccr, HCCR_RELEASE_RISC);
287 for (cnt = 0; cnt < 30000; cnt++) {
288 if ((RD_REG_WORD(&ha->iobase->hccr) &
289 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(&ha->iobase->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);
338 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
346 * qla2x00_reset_chip() - Reset ISP chip.
349 * Returns 0 on success.
352 qla2x00_reset_chip(scsi_qla_host_t *ha)
354 unsigned long flags = 0;
355 device_reg_t __iomem *reg = ha->iobase;
357 unsigned long mbx_flags = 0;
360 ha->isp_ops.disable_intrs(ha);
362 spin_lock_irqsave(&ha->hardware_lock, flags);
364 /* Turn off master enable */
366 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
367 cmd &= ~PCI_COMMAND_MASTER;
368 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
370 if (!IS_QLA2100(ha)) {
372 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
373 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
374 for (cnt = 0; cnt < 30000; cnt++) {
375 if ((RD_REG_WORD(®->hccr) &
376 HCCR_RISC_PAUSE) != 0)
381 RD_REG_WORD(®->hccr); /* PCI Posting. */
385 /* Select FPM registers. */
386 WRT_REG_WORD(®->ctrl_status, 0x20);
387 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
389 /* FPM Soft Reset. */
390 WRT_REG_WORD(®->fpm_diag_config, 0x100);
391 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
393 /* Toggle Fpm Reset. */
394 if (!IS_QLA2200(ha)) {
395 WRT_REG_WORD(®->fpm_diag_config, 0x0);
396 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
399 /* Select frame buffer registers. */
400 WRT_REG_WORD(®->ctrl_status, 0x10);
401 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
403 /* Reset frame buffer FIFOs. */
404 if (IS_QLA2200(ha)) {
405 WRT_FB_CMD_REG(ha, reg, 0xa000);
406 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
408 WRT_FB_CMD_REG(ha, reg, 0x00fc);
410 /* Read back fb_cmd until zero or 3 seconds max */
411 for (cnt = 0; cnt < 3000; cnt++) {
412 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
418 /* Select RISC module registers. */
419 WRT_REG_WORD(®->ctrl_status, 0);
420 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
422 /* Reset RISC processor. */
423 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
424 RD_REG_WORD(®->hccr); /* PCI Posting. */
426 /* Release RISC processor. */
427 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
428 RD_REG_WORD(®->hccr); /* PCI Posting. */
431 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
432 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
434 /* Reset ISP chip. */
435 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
437 /* Wait for RISC to recover from reset. */
438 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
440 * It is necessary to for a delay here since the card doesn't
441 * respond to PCI reads during a reset. On some architectures
442 * this will result in an MCA.
445 for (cnt = 30000; cnt; cnt--) {
446 if ((RD_REG_WORD(®->ctrl_status) &
447 CSR_ISP_SOFT_RESET) == 0)
454 /* Reset RISC processor. */
455 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
457 WRT_REG_WORD(®->semaphore, 0);
459 /* Release RISC processor. */
460 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
461 RD_REG_WORD(®->hccr); /* PCI Posting. */
463 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
464 for (cnt = 0; cnt < 30000; cnt++) {
465 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
466 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
468 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) {
469 if (!(test_bit(ABORT_ISP_ACTIVE,
471 spin_unlock_irqrestore(
472 &ha->mbx_reg_lock, mbx_flags);
476 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
477 spin_unlock_irqrestore(&ha->mbx_reg_lock,
485 /* Turn on master enable */
486 cmd |= PCI_COMMAND_MASTER;
487 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
489 /* Disable RISC pause on FPM parity error. */
490 if (!IS_QLA2100(ha)) {
491 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
492 RD_REG_WORD(®->hccr); /* PCI Posting. */
495 spin_unlock_irqrestore(&ha->hardware_lock, flags);
499 * qla2x00_chip_diag() - Test chip for proper operation.
502 * Returns 0 on success.
505 qla2x00_chip_diag(scsi_qla_host_t *ha)
508 device_reg_t __iomem *reg = ha->iobase;
509 unsigned long flags = 0;
514 /* Assume a failed state */
515 rval = QLA_FUNCTION_FAILED;
517 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
518 ha->host_no, (u_long)®->flash_address));
520 spin_lock_irqsave(&ha->hardware_lock, flags);
522 /* Reset ISP chip. */
523 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
526 * We need to have a delay here since the card will not respond while
527 * in reset causing an MCA on some architectures.
530 data = qla2x00_debounce_register(®->ctrl_status);
531 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
533 data = RD_REG_WORD(®->ctrl_status);
538 goto chip_diag_failed;
540 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
543 /* Reset RISC processor. */
544 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
545 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
547 /* Workaround for QLA2312 PCI parity error */
548 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
549 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
550 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
552 data = RD_MAILBOX_REG(ha, reg, 0);
559 goto chip_diag_failed;
561 /* Check product ID of chip */
562 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
564 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
565 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
566 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
567 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
568 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
569 mb[3] != PROD_ID_3) {
570 qla_printk(KERN_WARNING, ha,
571 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
573 goto chip_diag_failed;
575 ha->product_id[0] = mb[1];
576 ha->product_id[1] = mb[2];
577 ha->product_id[2] = mb[3];
578 ha->product_id[3] = mb[4];
580 /* Adjust fw RISC transfer size */
581 if (ha->request_q_length > 1024)
582 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
584 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
585 ha->request_q_length;
587 if (IS_QLA2200(ha) &&
588 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
589 /* Limit firmware transfer size with a 2200A */
590 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
593 ha->fw_transfer_size = 128;
596 /* Wrap Incoming Mailboxes Test. */
597 spin_unlock_irqrestore(&ha->hardware_lock, flags);
599 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
600 rval = qla2x00_mbx_reg_test(ha);
602 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
604 qla_printk(KERN_WARNING, ha,
605 "Failed mailbox send register test\n");
608 /* Flag a successful rval */
611 spin_lock_irqsave(&ha->hardware_lock, flags);
615 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
616 "****\n", ha->host_no));
618 spin_unlock_irqrestore(&ha->hardware_lock, flags);
624 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
627 * Returns 0 on success.
630 qla2x00_resize_request_q(scsi_qla_host_t *ha)
633 uint16_t fw_iocb_cnt = 0;
634 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
635 dma_addr_t request_dma;
636 request_t *request_ring;
638 /* Valid only on recent ISPs. */
639 if (IS_QLA2100(ha) || IS_QLA2200(ha))
642 /* Retrieve IOCB counts available to the firmware. */
643 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
646 /* No point in continuing if current settings are sufficient. */
647 if (fw_iocb_cnt < 1024)
649 if (ha->request_q_length >= request_q_length)
652 /* Attempt to claim larger area for request queue. */
653 request_ring = dma_alloc_coherent(&ha->pdev->dev,
654 (request_q_length + 1) * sizeof(request_t), &request_dma,
656 if (request_ring == NULL)
659 /* Resize successful, report extensions. */
660 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
661 (ha->fw_memory_size + 1) / 1024);
662 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
663 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
665 /* Clear old allocations. */
666 dma_free_coherent(&ha->pdev->dev,
667 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
670 /* Begin using larger queue. */
671 ha->request_q_length = request_q_length;
672 ha->request_ring = request_ring;
673 ha->request_dma = request_dma;
677 * qla2x00_setup_chip() - Load and start RISC firmware.
680 * Returns 0 on success.
683 qla2x00_setup_chip(scsi_qla_host_t *ha)
688 unsigned long risc_address;
689 unsigned long risc_code_size;
693 struct qla_fw_info *fw_iter;
697 /* Load firmware sequences */
698 fw_iter = ha->brd_info->fw_info;
699 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
700 risc_code = fw_iter->fwcode;
701 risc_code_size = *fw_iter->fwlen;
703 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
704 risc_address = *fw_iter->fwstart;
706 /* Extended address */
707 risc_address = *fw_iter->lfwstart;
712 while (risc_code_size > 0 && !rval) {
713 cnt = (uint16_t)(ha->fw_transfer_size >> 1);
714 if (cnt > risc_code_size)
715 cnt = risc_code_size;
717 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
718 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
719 ha->host_no, risc_code, cnt, risc_address));
721 req_ring = (uint16_t *)ha->request_ring;
722 for (i = 0; i < cnt; i++)
723 req_ring[i] = cpu_to_le16(risc_code[i]);
725 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
726 rval = qla2x00_load_ram(ha,
727 ha->request_dma, risc_address, cnt);
729 rval = qla2x00_load_ram_ext(ha,
730 ha->request_dma, risc_address, cnt);
733 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
734 "load segment %d of firmware\n",
736 qla_printk(KERN_WARNING, ha,
737 "[ERROR] Failed to load "
738 "segment %d of firmware\n", num);
740 qla2x00_dump_regs(ha);
746 risc_code_size -= cnt;
750 /* Next firmware sequence */
754 /* Verify checksum of loaded RISC code. */
756 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
757 "code.\n", ha->host_no));
759 rval = qla2x00_verify_checksum(ha);
760 if (rval == QLA_SUCCESS) {
761 /* Start firmware execution. */
762 DEBUG(printk("scsi(%ld): Checksum OK, start "
763 "firmware.\n", ha->host_no));
765 rval = qla2x00_execute_fw(ha);
766 /* Retrieve firmware information. */
767 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
768 qla2x00_get_fw_version(ha,
769 &ha->fw_major_version,
770 &ha->fw_minor_version,
771 &ha->fw_subminor_version,
772 &ha->fw_attributes, &ha->fw_memory_size);
773 qla2x00_resize_request_q(ha);
776 DEBUG2(printk(KERN_INFO
777 "scsi(%ld): ISP Firmware failed checksum.\n",
783 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
791 * qla2x00_init_response_q_entries() - Initializes response queue entries.
794 * Beginning of request ring has initialization control block already built
795 * by nvram config routine.
797 * Returns 0 on success.
800 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
805 pkt = ha->response_ring_ptr;
806 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
807 pkt->signature = RESPONSE_PROCESSED;
814 * qla2x00_update_fw_options() - Read and process firmware options.
817 * Returns 0 on success.
820 qla2x00_update_fw_options(scsi_qla_host_t *ha)
822 uint16_t swing, emphasis, tx_sens, rx_sens;
824 memset(ha->fw_options, 0, sizeof(ha->fw_options));
825 qla2x00_get_fw_options(ha, ha->fw_options);
827 if (IS_QLA2100(ha) || IS_QLA2200(ha))
830 /* Serial Link options. */
831 DEBUG3(printk("scsi(%ld): Serial link options:\n",
833 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
834 sizeof(ha->fw_seriallink_options)));
836 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
837 if (ha->fw_seriallink_options[3] & BIT_2) {
838 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
841 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
842 emphasis = (ha->fw_seriallink_options[2] &
843 (BIT_4 | BIT_3)) >> 3;
844 tx_sens = ha->fw_seriallink_options[0] &
845 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
846 rx_sens = (ha->fw_seriallink_options[0] &
847 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
848 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
849 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
852 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
853 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
854 ha->fw_options[10] |= BIT_5 |
855 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
856 (tx_sens & (BIT_1 | BIT_0));
859 swing = (ha->fw_seriallink_options[2] &
860 (BIT_7 | BIT_6 | BIT_5)) >> 5;
861 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
862 tx_sens = ha->fw_seriallink_options[1] &
863 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
864 rx_sens = (ha->fw_seriallink_options[1] &
865 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
866 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
867 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
870 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
871 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
872 ha->fw_options[11] |= BIT_5 |
873 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
874 (tx_sens & (BIT_1 | BIT_0));
878 /* Return command IOCBs without waiting for an ABTS to complete. */
879 ha->fw_options[3] |= BIT_13;
882 if (ha->flags.enable_led_scheme)
883 ha->fw_options[2] |= BIT_12;
885 /* Update firmware options. */
886 qla2x00_set_fw_options(ha, ha->fw_options);
890 qla2x00_config_rings(struct scsi_qla_host *ha)
892 device_reg_t __iomem *reg = ha->iobase;
894 /* Setup ring parameters in initialization control block. */
895 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
896 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
897 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
898 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
899 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
900 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
901 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
902 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
904 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
905 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
906 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
907 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
908 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
912 * qla2x00_init_rings() - Initializes firmware.
915 * Beginning of request ring has initialization control block already built
916 * by nvram config routine.
918 * Returns 0 on success.
921 qla2x00_init_rings(scsi_qla_host_t *ha)
924 unsigned long flags = 0;
927 spin_lock_irqsave(&ha->hardware_lock, flags);
929 /* Clear outstanding commands array. */
930 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
931 ha->outstanding_cmds[cnt] = NULL;
933 ha->current_outstanding_cmd = 0;
935 /* Clear RSCN queue. */
937 ha->rscn_out_ptr = 0;
939 /* Initialize firmware. */
940 ha->request_ring_ptr = ha->request_ring;
941 ha->req_ring_index = 0;
942 ha->req_q_cnt = ha->request_q_length;
943 ha->response_ring_ptr = ha->response_ring;
944 ha->rsp_ring_index = 0;
946 /* Initialize response queue entries */
947 qla2x00_init_response_q_entries(ha);
949 ha->isp_ops.config_rings(ha);
951 spin_unlock_irqrestore(&ha->hardware_lock, flags);
953 /* Update any ISP specific firmware options before initialization. */
954 ha->isp_ops.update_fw_options(ha);
956 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
957 rval = qla2x00_init_firmware(ha, sizeof(init_cb_t));
959 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
962 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
970 * qla2x00_fw_ready() - Waits for firmware ready.
973 * Returns 0 on success.
976 qla2x00_fw_ready(scsi_qla_host_t *ha)
979 unsigned long wtime, mtime;
980 uint16_t min_wait; /* Minimum wait time if loop is down */
981 uint16_t wait_time; /* Wait time if loop is coming ready */
986 /* 20 seconds for loop down. */
990 * Firmware should take at most one RATOV to login, plus 5 seconds for
991 * our own processing.
993 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
994 wait_time = min_wait;
997 /* Min wait time if loop down */
998 mtime = jiffies + (min_wait * HZ);
1000 /* wait time before firmware ready */
1001 wtime = jiffies + (wait_time * HZ);
1003 /* Wait for ISP to finish LIP */
1004 if (!ha->flags.init_done)
1005 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1007 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1011 rval = qla2x00_get_firmware_state(ha, &fw_state);
1012 if (rval == QLA_SUCCESS) {
1013 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1014 ha->device_flags &= ~DFLG_NO_CABLE;
1016 if (fw_state == FSTATE_READY) {
1017 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1020 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1021 &ha->login_timeout, &ha->r_a_tov);
1027 rval = QLA_FUNCTION_FAILED;
1029 if (atomic_read(&ha->loop_down_timer) &&
1030 (fw_state >= FSTATE_LOSS_OF_SYNC ||
1031 fw_state == FSTATE_WAIT_AL_PA)) {
1032 /* Loop down. Timeout on min_wait for states
1033 * other than Wait for Login.
1035 if (time_after_eq(jiffies, mtime)) {
1036 qla_printk(KERN_INFO, ha,
1037 "Cable is unplugged...\n");
1039 ha->device_flags |= DFLG_NO_CABLE;
1044 /* Mailbox cmd failed. Timeout on min_wait. */
1045 if (time_after_eq(jiffies, mtime))
1049 if (time_after_eq(jiffies, wtime))
1052 /* Delay for a while */
1055 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1056 ha->host_no, fw_state, jiffies));
1059 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1060 ha->host_no, fw_state, jiffies));
1063 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1071 * qla2x00_configure_hba
1072 * Setup adapter context.
1075 * ha = adapter state pointer.
1084 qla2x00_configure_hba(scsi_qla_host_t *ha)
1092 char connect_type[22];
1094 /* Get host addresses. */
1095 rval = qla2x00_get_adapter_id(ha,
1096 &loop_id, &al_pa, &area, &domain, &topo);
1097 if (rval != QLA_SUCCESS) {
1098 qla_printk(KERN_WARNING, ha,
1099 "ERROR -- Unable to get host loop ID.\n");
1100 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1105 qla_printk(KERN_INFO, ha,
1106 "Cannot get topology - retrying.\n");
1107 return (QLA_FUNCTION_FAILED);
1110 ha->loop_id = loop_id;
1113 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1114 ha->operating_mode = LOOP;
1118 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1120 ha->current_topology = ISP_CFG_NL;
1121 strcpy(connect_type, "(Loop)");
1125 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1127 ha->current_topology = ISP_CFG_FL;
1128 strcpy(connect_type, "(FL_Port)");
1132 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1134 ha->operating_mode = P2P;
1135 ha->current_topology = ISP_CFG_N;
1136 strcpy(connect_type, "(N_Port-to-N_Port)");
1140 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1142 ha->operating_mode = P2P;
1143 ha->current_topology = ISP_CFG_F;
1144 strcpy(connect_type, "(F_Port)");
1148 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1150 ha->host_no, topo));
1151 ha->current_topology = ISP_CFG_NL;
1152 strcpy(connect_type, "(Loop)");
1156 /* Save Host port and loop ID. */
1157 /* byte order - Big Endian */
1158 ha->d_id.b.domain = domain;
1159 ha->d_id.b.area = area;
1160 ha->d_id.b.al_pa = al_pa;
1162 if (!ha->flags.init_done)
1163 qla_printk(KERN_INFO, ha,
1164 "Topology - %s, Host Loop address 0x%x\n",
1165 connect_type, ha->loop_id);
1168 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1170 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1177 * NVRAM configuration for ISP 2xxx
1180 * ha = adapter block pointer.
1183 * initialization control block in response_ring
1184 * host adapters parameters in host adapter block
1190 qla2x00_nvram_config(scsi_qla_host_t *ha)
1195 uint8_t *dptr1, *dptr2;
1196 init_cb_t *icb = ha->init_cb;
1197 nvram_t *nv = (nvram_t *)ha->request_ring;
1198 uint16_t *wptr = (uint16_t *)ha->request_ring;
1199 device_reg_t __iomem *reg = ha->iobase;
1204 /* Determine NVRAM starting address. */
1206 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1207 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1208 ha->nvram_base = 0x80;
1210 /* Get NVRAM data and calculate checksum. */
1211 qla2x00_lock_nvram_access(ha);
1212 for (cnt = 0; cnt < sizeof(nvram_t)/2; cnt++) {
1213 *wptr = cpu_to_le16(qla2x00_get_nvram_word(ha,
1214 (cnt+ha->nvram_base)));
1215 chksum += (uint8_t)*wptr;
1216 chksum += (uint8_t)(*wptr >> 8);
1219 qla2x00_unlock_nvram_access(ha);
1221 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1222 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1225 /* Bad NVRAM data, set defaults parameters. */
1226 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1227 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1228 /* Reset NVRAM data. */
1229 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1230 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1232 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1233 "invalid -- WWPN) defaults.\n");
1236 * Set default initialization control block.
1238 memset(nv, 0, sizeof(nvram_t));
1239 nv->parameter_block_version = ICB_VERSION;
1241 if (IS_QLA23XX(ha)) {
1242 nv->firmware_options[0] = BIT_2 | BIT_1;
1243 nv->firmware_options[1] = BIT_7 | BIT_5;
1244 nv->add_firmware_options[0] = BIT_5;
1245 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1246 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1247 nv->special_options[1] = BIT_7;
1248 } else if (IS_QLA2200(ha)) {
1249 nv->firmware_options[0] = BIT_2 | BIT_1;
1250 nv->firmware_options[1] = BIT_7 | BIT_5;
1251 nv->add_firmware_options[0] = BIT_5;
1252 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1253 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1254 } else if (IS_QLA2100(ha)) {
1255 nv->firmware_options[0] = BIT_3 | BIT_1;
1256 nv->firmware_options[1] = BIT_5;
1257 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1260 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1261 nv->execution_throttle = __constant_cpu_to_le16(16);
1262 nv->retry_count = 8;
1263 nv->retry_delay = 1;
1265 nv->port_name[0] = 33;
1266 nv->port_name[3] = 224;
1267 nv->port_name[4] = 139;
1269 nv->login_timeout = 4;
1272 * Set default host adapter parameters
1274 nv->host_p[1] = BIT_2;
1275 nv->reset_delay = 5;
1276 nv->port_down_retry_count = 8;
1277 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1278 nv->link_down_timeout = 60;
1283 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1285 * The SN2 does not provide BIOS emulation which means you can't change
1286 * potentially bogus BIOS settings. Force the use of default settings
1287 * for link rate and frame size. Hope that the rest of the settings
1290 if (ia64_platform_is("sn2")) {
1291 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1293 nv->special_options[1] = BIT_7;
1297 /* Reset Initialization control block */
1298 memset(icb, 0, sizeof(init_cb_t));
1301 * Setup driver NVRAM options.
1303 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1304 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1305 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1306 nv->firmware_options[1] &= ~BIT_4;
1308 if (IS_QLA23XX(ha)) {
1309 nv->firmware_options[0] |= BIT_2;
1310 nv->firmware_options[0] &= ~BIT_3;
1312 if (IS_QLA2300(ha)) {
1313 if (ha->fb_rev == FPM_2310) {
1314 strcpy(ha->model_number, "QLA2310");
1316 strcpy(ha->model_number, "QLA2300");
1320 memcmp(nv->model_number, BINZERO,
1321 sizeof(nv->model_number)) != 0) {
1324 strncpy(ha->model_number, nv->model_number,
1325 sizeof(nv->model_number));
1326 st = en = ha->model_number;
1327 en += sizeof(nv->model_number) - 1;
1329 if (*en != 0x20 && *en != 0x00)
1336 index = (ha->pdev->subsystem_device & 0xff);
1337 if (index < QLA_MODEL_NAMES) {
1338 strcpy(ha->model_number,
1339 qla2x00_model_name[index]);
1341 qla2x00_model_desc[index];
1343 strcpy(ha->model_number, "QLA23xx");
1347 } else if (IS_QLA2200(ha)) {
1348 nv->firmware_options[0] |= BIT_2;
1350 * 'Point-to-point preferred, else loop' is not a safe
1351 * connection mode setting.
1353 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1355 /* Force 'loop preferred, else point-to-point'. */
1356 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1357 nv->add_firmware_options[0] |= BIT_5;
1359 strcpy(ha->model_number, "QLA22xx");
1360 } else /*if (IS_QLA2100(ha))*/ {
1361 strcpy(ha->model_number, "QLA2100");
1365 * Copy over NVRAM RISC parameter block to initialization control block.
1367 dptr1 = (uint8_t *)icb;
1368 dptr2 = (uint8_t *)&nv->parameter_block_version;
1369 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1371 *dptr1++ = *dptr2++;
1373 /* Copy 2nd half. */
1374 dptr1 = (uint8_t *)icb->add_firmware_options;
1375 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1377 *dptr1++ = *dptr2++;
1379 /* Prepare nodename */
1380 if ((icb->firmware_options[1] & BIT_6) == 0) {
1382 * Firmware will apply the following mask if the nodename was
1385 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1386 icb->node_name[0] &= 0xF0;
1390 * Set host adapter parameters.
1392 ha->nvram_version = nv->nvram_version;
1394 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1395 /* Always load RISC code on non ISP2[12]00 chips. */
1396 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1397 ha->flags.disable_risc_code_load = 0;
1398 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1399 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1400 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1401 ha->flags.enable_led_scheme = ((nv->efi_parameters & BIT_3) ? 1 : 0);
1403 ha->operating_mode =
1404 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1406 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1407 sizeof(ha->fw_seriallink_options));
1409 /* save HBA serial number */
1410 ha->serial0 = icb->port_name[5];
1411 ha->serial1 = icb->port_name[6];
1412 ha->serial2 = icb->port_name[7];
1413 memcpy(ha->node_name, icb->node_name, WWN_SIZE);
1415 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1417 ha->retry_count = nv->retry_count;
1419 /* Set minimum login_timeout to 4 seconds. */
1420 if (nv->login_timeout < ql2xlogintimeout)
1421 nv->login_timeout = ql2xlogintimeout;
1422 if (nv->login_timeout < 4)
1423 nv->login_timeout = 4;
1424 ha->login_timeout = nv->login_timeout;
1425 icb->login_timeout = nv->login_timeout;
1427 /* Set minimum RATOV to 200 tenths of a second. */
1430 ha->loop_reset_delay = nv->reset_delay;
1432 /* Link Down Timeout = 0:
1434 * When Port Down timer expires we will start returning
1435 * I/O's to OS with "DID_NO_CONNECT".
1437 * Link Down Timeout != 0:
1439 * The driver waits for the link to come up after link down
1440 * before returning I/Os to OS with "DID_NO_CONNECT".
1442 if (nv->link_down_timeout == 0) {
1443 ha->loop_down_abort_time =
1444 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1446 ha->link_down_timeout = nv->link_down_timeout;
1447 ha->loop_down_abort_time =
1448 (LOOP_DOWN_TIME - ha->link_down_timeout);
1452 * Need enough time to try and get the port back.
1454 ha->port_down_retry_count = nv->port_down_retry_count;
1455 if (qlport_down_retry)
1456 ha->port_down_retry_count = qlport_down_retry;
1457 /* Set login_retry_count */
1458 ha->login_retry_count = nv->retry_count;
1459 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1460 ha->port_down_retry_count > 3)
1461 ha->login_retry_count = ha->port_down_retry_count;
1462 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1463 ha->login_retry_count = ha->port_down_retry_count;
1464 if (ql2xloginretrycount)
1465 ha->login_retry_count = ql2xloginretrycount;
1467 icb->lun_enables = __constant_cpu_to_le16(0);
1468 icb->command_resource_count = 0;
1469 icb->immediate_notify_resource_count = 0;
1470 icb->timeout = __constant_cpu_to_le16(0);
1472 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1474 icb->firmware_options[0] &= ~BIT_3;
1475 icb->add_firmware_options[0] &=
1476 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1477 icb->add_firmware_options[0] |= BIT_2;
1478 icb->response_accumulation_timer = 3;
1479 icb->interrupt_delay_timer = 5;
1481 ha->flags.process_response_queue = 1;
1483 /* Enable ZIO -- Support mode 5 only. */
1484 timer_mode = icb->add_firmware_options[0] &
1485 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1486 icb->add_firmware_options[0] &=
1487 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1489 timer_mode = BIT_2 | BIT_0;
1490 if (timer_mode == (BIT_2 | BIT_0)) {
1491 DEBUG2(printk("scsi(%ld): ZIO enabled; timer delay "
1492 "(%d).\n", ha->host_no, ql2xintrdelaytimer));
1493 qla_printk(KERN_INFO, ha,
1494 "ZIO enabled; timer delay (%d).\n",
1495 ql2xintrdelaytimer);
1497 icb->add_firmware_options[0] |= timer_mode;
1498 icb->interrupt_delay_timer = ql2xintrdelaytimer;
1499 ha->flags.process_response_queue = 1;
1504 DEBUG2_3(printk(KERN_WARNING
1505 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1511 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1513 * @flags: allocation flags
1515 * Returns a pointer to the allocated fcport, or NULL, if none available.
1518 qla2x00_alloc_fcport(scsi_qla_host_t *ha, int flags)
1522 fcport = kmalloc(sizeof(fc_port_t), flags);
1526 /* Setup fcport template structure. */
1527 memset(fcport, 0, sizeof (fc_port_t));
1529 fcport->port_type = FCT_UNKNOWN;
1530 fcport->loop_id = FC_NO_LOOP_ID;
1531 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1532 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1533 fcport->flags = FCF_RLC_SUPPORT;
1539 * qla2x00_configure_loop
1540 * Updates Fibre Channel Device Database with what is actually on loop.
1543 * ha = adapter block pointer.
1548 * 2 = database was full and device was not configured.
1551 qla2x00_configure_loop(scsi_qla_host_t *ha)
1554 unsigned long flags, save_flags;
1558 /* Get Initiator ID */
1559 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1560 rval = qla2x00_configure_hba(ha);
1561 if (rval != QLA_SUCCESS) {
1562 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1568 save_flags = flags = ha->dpc_flags;
1569 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1570 ha->host_no, flags));
1573 * If we have both an RSCN and PORT UPDATE pending then handle them
1574 * both at the same time.
1576 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1577 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1579 /* Determine what we need to do */
1580 if (ha->current_topology == ISP_CFG_FL &&
1581 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1583 ha->flags.rscn_queue_overflow = 1;
1584 set_bit(RSCN_UPDATE, &flags);
1586 } else if (ha->current_topology == ISP_CFG_F &&
1587 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1589 ha->flags.rscn_queue_overflow = 1;
1590 set_bit(RSCN_UPDATE, &flags);
1591 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1593 } else if (!ha->flags.online ||
1594 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1596 ha->flags.rscn_queue_overflow = 1;
1597 set_bit(RSCN_UPDATE, &flags);
1598 set_bit(LOCAL_LOOP_UPDATE, &flags);
1601 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1602 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1603 rval = QLA_FUNCTION_FAILED;
1605 rval = qla2x00_configure_local_loop(ha);
1609 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1610 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1611 rval = QLA_FUNCTION_FAILED;
1613 rval = qla2x00_configure_fabric(ha);
1617 if (rval == QLA_SUCCESS) {
1618 if (atomic_read(&ha->loop_down_timer) ||
1619 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1620 rval = QLA_FUNCTION_FAILED;
1622 atomic_set(&ha->loop_state, LOOP_READY);
1624 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1629 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1630 __func__, ha->host_no));
1632 DEBUG3(printk("%s: exiting normally\n", __func__));
1635 /* Restore state if a resync event occured during processing */
1636 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1637 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1638 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1639 if (test_bit(RSCN_UPDATE, &save_flags))
1640 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1649 * qla2x00_configure_local_loop
1650 * Updates Fibre Channel Device Database with local loop devices.
1653 * ha = adapter block pointer.
1659 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1664 fc_port_t *fcport, *new_fcport;
1670 uint8_t domain, area, al_pa;
1674 entries = MAX_FIBRE_DEVICES;
1676 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1677 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1679 /* Get list of logged in devices. */
1680 memset(ha->gid_list, 0, GID_LIST_SIZE);
1681 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1683 if (rval != QLA_SUCCESS)
1684 goto cleanup_allocation;
1686 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1687 ha->host_no, entries));
1688 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1689 entries * sizeof(struct gid_list_info)));
1691 /* Allocate temporary fcport for any new fcports discovered. */
1692 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1693 if (new_fcport == NULL) {
1694 rval = QLA_MEMORY_ALLOC_FAILED;
1695 goto cleanup_allocation;
1697 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1700 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1702 list_for_each_entry(fcport, &ha->fcports, list) {
1703 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1704 fcport->port_type != FCT_BROADCAST &&
1705 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1707 DEBUG(printk("scsi(%ld): Marking port lost, "
1709 ha->host_no, fcport->loop_id));
1711 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1712 fcport->flags &= ~FCF_FARP_DONE;
1716 /* Add devices to port list. */
1717 id_iter = (char *)ha->gid_list;
1718 for (index = 0; index < entries; index++) {
1719 domain = ((struct gid_list_info *)id_iter)->domain;
1720 area = ((struct gid_list_info *)id_iter)->area;
1721 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1722 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1723 loop_id = (uint16_t)
1724 ((struct gid_list_info *)id_iter)->loop_id_2100;
1726 loop_id = le16_to_cpu(
1727 ((struct gid_list_info *)id_iter)->loop_id);
1728 id_iter += ha->gid_list_info_size;
1730 /* Bypass reserved domain fields. */
1731 if ((domain & 0xf0) == 0xf0)
1734 /* Bypass if not same domain and area of adapter. */
1735 if (area != ha->d_id.b.area || domain != ha->d_id.b.domain)
1738 /* Bypass invalid local loop ID. */
1739 if (loop_id > LAST_LOCAL_LOOP_ID)
1742 /* Fill in member data. */
1743 new_fcport->d_id.b.domain = domain;
1744 new_fcport->d_id.b.area = area;
1745 new_fcport->d_id.b.al_pa = al_pa;
1746 new_fcport->loop_id = loop_id;
1747 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1748 if (rval2 != QLA_SUCCESS) {
1749 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1750 "information -- get_port_database=%x, "
1752 ha->host_no, rval2, new_fcport->loop_id));
1756 /* Check for matching device in port list. */
1759 list_for_each_entry(fcport, &ha->fcports, list) {
1760 if (memcmp(new_fcport->port_name, fcport->port_name,
1764 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1765 FCF_PERSISTENT_BOUND);
1766 fcport->loop_id = new_fcport->loop_id;
1767 fcport->port_type = new_fcport->port_type;
1768 fcport->d_id.b24 = new_fcport->d_id.b24;
1769 memcpy(fcport->node_name, new_fcport->node_name,
1777 /* New device, add to fcports list. */
1778 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1779 list_add_tail(&new_fcport->list, &ha->fcports);
1781 /* Allocate a new replacement fcport. */
1782 fcport = new_fcport;
1783 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1784 if (new_fcport == NULL) {
1785 rval = QLA_MEMORY_ALLOC_FAILED;
1786 goto cleanup_allocation;
1788 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1791 qla2x00_update_fcport(ha, fcport);
1800 if (rval != QLA_SUCCESS) {
1801 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1802 "rval=%x\n", ha->host_no, rval));
1806 ha->device_flags |= DFLG_LOCAL_DEVICES;
1807 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
1814 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
1818 qla2x00_mark_all_devices_lost(ha);
1819 list_for_each_entry(fcport, &ha->fcports, list) {
1820 if (fcport->port_type != FCT_TARGET)
1823 qla2x00_update_fcport(ha, fcport);
1828 * qla2x00_update_fcport
1829 * Updates device on list.
1832 * ha = adapter block pointer.
1833 * fcport = port structure pointer.
1843 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
1846 unsigned long flags;
1850 fcport->login_retry = 0;
1851 fcport->port_login_retry_count = ha->port_down_retry_count *
1853 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
1855 fcport->flags &= ~FCF_LOGIN_NEEDED;
1858 * Check for outstanding cmd on tape Bypass LUN discovery if active
1861 if (fcport->flags & FCF_TAPE_PRESENT) {
1862 spin_lock_irqsave(&ha->hardware_lock, flags);
1863 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
1866 if ((sp = ha->outstanding_cmds[index]) != 0) {
1868 if (sfcp == fcport) {
1869 atomic_set(&fcport->state, FCS_ONLINE);
1870 spin_unlock_irqrestore(
1871 &ha->hardware_lock, flags);
1876 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1879 if (fcport->port_type == FCT_INITIATOR ||
1880 fcport->port_type == FCT_BROADCAST)
1881 fcport->device_type = TYPE_PROCESSOR;
1883 atomic_set(&fcport->state, FCS_ONLINE);
1885 if (ha->flags.init_done)
1886 qla2x00_reg_remote_port(ha, fcport);
1890 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
1892 struct fc_rport_identifiers rport_ids;
1893 struct fc_rport *rport;
1895 if (fcport->rport) {
1896 fc_remote_port_unblock(fcport->rport);
1900 rport_ids.node_name = be64_to_cpu(*(uint64_t *)fcport->node_name);
1901 rport_ids.port_name = be64_to_cpu(*(uint64_t *)fcport->port_name);
1902 rport_ids.port_id = fcport->d_id.b.domain << 16 |
1903 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
1904 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
1905 if (fcport->port_type == FCT_INITIATOR)
1906 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1907 if (fcport->port_type == FCT_TARGET)
1908 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1910 fcport->rport = rport = fc_remote_port_add(ha->host, 0, &rport_ids);
1912 qla_printk(KERN_WARNING, ha,
1913 "Unable to allocate fc remote port!\n");
1915 if (rport->scsi_target_id != -1 && rport->scsi_target_id < MAX_TARGETS)
1916 fcport->os_target_id = rport->scsi_target_id;
1918 rport->dd_data = fcport;
1922 * qla2x00_configure_fabric
1923 * Setup SNS devices with loop ID's.
1926 * ha = adapter block pointer.
1933 qla2x00_configure_fabric(scsi_qla_host_t *ha)
1936 fc_port_t *fcport, *fcptemp;
1937 uint16_t next_loopid;
1938 uint16_t mb[MAILBOX_REGISTER_COUNT];
1939 LIST_HEAD(new_fcports);
1941 /* If FL port exists, then SNS is present */
1942 rval = qla2x00_get_port_name(ha, SNS_FL_PORT, NULL, 0);
1943 if (rval != QLA_SUCCESS) {
1944 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
1945 "Port\n", ha->host_no));
1947 ha->device_flags &= ~SWITCH_FOUND;
1948 return (QLA_SUCCESS);
1951 /* Mark devices that need re-synchronization. */
1952 rval2 = qla2x00_device_resync(ha);
1953 if (rval2 == QLA_RSCNS_HANDLED) {
1954 /* No point doing the scan, just continue. */
1955 return (QLA_SUCCESS);
1958 /* Ensure we are logged into the SNS. */
1959 ha->isp_ops.fabric_login(ha, SIMPLE_NAME_SERVER, 0xff, 0xff,
1960 0xfc, mb, BIT_1 | BIT_0);
1961 if (mb[0] != MBS_COMMAND_COMPLETE) {
1962 DEBUG2(qla_printk(KERN_INFO, ha,
1963 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
1964 "mb[2]=%x mb[6]=%x mb[7]=%x\n", SIMPLE_NAME_SERVER,
1965 mb[0], mb[1], mb[2], mb[6], mb[7]));
1966 return (QLA_SUCCESS);
1969 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
1970 if (qla2x00_rft_id(ha)) {
1972 DEBUG2(printk("scsi(%ld): Register FC-4 "
1973 "TYPE failed.\n", ha->host_no));
1975 if (qla2x00_rff_id(ha)) {
1977 DEBUG2(printk("scsi(%ld): Register FC-4 "
1978 "Features failed.\n", ha->host_no));
1980 if (qla2x00_rnn_id(ha)) {
1982 DEBUG2(printk("scsi(%ld): Register Node Name "
1983 "failed.\n", ha->host_no));
1984 } else if (qla2x00_rsnn_nn(ha)) {
1986 DEBUG2(printk("scsi(%ld): Register Symbolic "
1987 "Node Name failed.\n", ha->host_no));
1991 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
1992 if (rval != QLA_SUCCESS)
1996 * Logout all previous fabric devices marked lost, except
1999 list_for_each_entry(fcport, &ha->fcports, list) {
2000 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2003 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2006 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2007 qla2x00_mark_device_lost(ha, fcport,
2008 ql2xplogiabsentdevice);
2009 if (fcport->loop_id != FC_NO_LOOP_ID &&
2010 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2011 fcport->port_type != FCT_INITIATOR &&
2012 fcport->port_type != FCT_BROADCAST) {
2014 ha->isp_ops.fabric_logout(ha,
2016 fcport->loop_id = FC_NO_LOOP_ID;
2021 /* Starting free loop ID. */
2022 next_loopid = ha->min_external_loopid;
2025 * Scan through our port list and login entries that need to be
2028 list_for_each_entry(fcport, &ha->fcports, list) {
2029 if (atomic_read(&ha->loop_down_timer) ||
2030 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2033 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2034 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2037 if (fcport->loop_id == FC_NO_LOOP_ID) {
2038 fcport->loop_id = next_loopid;
2039 rval = qla2x00_find_new_loop_id(ha, fcport);
2040 if (rval != QLA_SUCCESS) {
2041 /* Ran out of IDs to use */
2046 /* Login and update database */
2047 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2050 /* Exit if out of loop IDs. */
2051 if (rval != QLA_SUCCESS) {
2056 * Login and add the new devices to our port list.
2058 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2059 if (atomic_read(&ha->loop_down_timer) ||
2060 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2063 /* Find a new loop ID to use. */
2064 fcport->loop_id = next_loopid;
2065 rval = qla2x00_find_new_loop_id(ha, fcport);
2066 if (rval != QLA_SUCCESS) {
2067 /* Ran out of IDs to use */
2071 /* Remove device from the new list and add it to DB */
2072 list_del(&fcport->list);
2073 list_add_tail(&fcport->list, &ha->fcports);
2075 /* Login and update database */
2076 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2080 /* Free all new device structures not processed. */
2081 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2082 list_del(&fcport->list);
2087 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2088 "rval=%d\n", ha->host_no, rval));
2096 * qla2x00_find_all_fabric_devs
2099 * ha = adapter block pointer.
2100 * dev = database device entry pointer.
2109 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2113 fc_port_t *fcport, *new_fcport, *fcptemp;
2118 int first_dev, last_dev;
2119 port_id_t wrap, nxt_d_id;
2123 /* Try GID_PT to get device list, else GAN. */
2124 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2127 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2128 "on GA_NXT\n", ha->host_no));
2130 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2131 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2134 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2137 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2144 /* Allocate temporary fcport for any new fcports discovered. */
2145 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2146 if (new_fcport == NULL) {
2149 return (QLA_MEMORY_ALLOC_FAILED);
2151 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2153 /* Set start port ID scan at adapter ID. */
2157 /* Starting free loop ID. */
2158 loop_id = ha->min_external_loopid;
2160 for (; loop_id <= ha->last_loop_id; loop_id++) {
2161 if (RESERVED_LOOP_ID(loop_id))
2164 if (atomic_read(&ha->loop_down_timer) ||
2165 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2170 wrap.b24 = new_fcport->d_id.b24;
2172 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2173 memcpy(new_fcport->node_name,
2174 swl[swl_idx].node_name, WWN_SIZE);
2175 memcpy(new_fcport->port_name,
2176 swl[swl_idx].port_name, WWN_SIZE);
2178 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2184 /* Send GA_NXT to the switch */
2185 rval = qla2x00_ga_nxt(ha, new_fcport);
2186 if (rval != QLA_SUCCESS) {
2187 qla_printk(KERN_WARNING, ha,
2188 "SNS scan failed -- assuming zero-entry "
2190 list_for_each_entry_safe(fcport, fcptemp,
2191 new_fcports, list) {
2192 list_del(&fcport->list);
2200 /* If wrap on switch device list, exit. */
2202 wrap.b24 = new_fcport->d_id.b24;
2204 } else if (new_fcport->d_id.b24 == wrap.b24) {
2205 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2206 ha->host_no, new_fcport->d_id.b.domain,
2207 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2211 /* Bypass if host adapter. */
2212 if (new_fcport->d_id.b24 == ha->d_id.b24)
2215 /* Bypass reserved domain fields. */
2216 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2219 /* Locate matching device in database. */
2221 list_for_each_entry(fcport, &ha->fcports, list) {
2222 if (memcmp(new_fcport->port_name, fcport->port_name,
2229 * If address the same and state FCS_ONLINE, nothing
2232 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2233 atomic_read(&fcport->state) == FCS_ONLINE) {
2238 * If device was not a fabric device before.
2240 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2241 fcport->d_id.b24 = new_fcport->d_id.b24;
2242 fcport->loop_id = FC_NO_LOOP_ID;
2243 fcport->flags |= (FCF_FABRIC_DEVICE |
2245 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2250 * Port ID changed or device was marked to be updated;
2251 * Log it out if still logged in and mark it for
2254 fcport->d_id.b24 = new_fcport->d_id.b24;
2255 fcport->flags |= FCF_LOGIN_NEEDED;
2256 if (fcport->loop_id != FC_NO_LOOP_ID &&
2257 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2258 fcport->port_type != FCT_INITIATOR &&
2259 fcport->port_type != FCT_BROADCAST) {
2260 ha->isp_ops.fabric_logout(ha, fcport->loop_id);
2261 fcport->loop_id = FC_NO_LOOP_ID;
2270 /* If device was not in our fcports list, then add it. */
2271 list_add_tail(&new_fcport->list, new_fcports);
2273 /* Allocate a new replacement fcport. */
2274 nxt_d_id.b24 = new_fcport->d_id.b24;
2275 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2276 if (new_fcport == NULL) {
2279 return (QLA_MEMORY_ALLOC_FAILED);
2281 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2282 new_fcport->d_id.b24 = nxt_d_id.b24;
2291 if (!list_empty(new_fcports))
2292 ha->device_flags |= DFLG_FABRIC_DEVICES;
2298 * qla2x00_find_new_loop_id
2299 * Scan through our port list and find a new usable loop ID.
2302 * ha: adapter state pointer.
2303 * dev: port structure pointer.
2306 * qla2x00 local function return status code.
2312 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2317 uint16_t first_loop_id;
2321 /* Save starting loop ID. */
2322 first_loop_id = dev->loop_id;
2325 /* Skip loop ID if already used by adapter. */
2326 if (dev->loop_id == ha->loop_id) {
2330 /* Skip reserved loop IDs. */
2331 while (RESERVED_LOOP_ID(dev->loop_id)) {
2335 /* Reset loop ID if passed the end. */
2336 if (dev->loop_id > ha->last_loop_id) {
2337 /* first loop ID. */
2338 dev->loop_id = ha->min_external_loopid;
2341 /* Check for loop ID being already in use. */
2344 list_for_each_entry(fcport, &ha->fcports, list) {
2345 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2346 /* ID possibly in use */
2352 /* If not in use then it is free to use. */
2357 /* ID in use. Try next value. */
2360 /* If wrap around. No free ID to use. */
2361 if (dev->loop_id == first_loop_id) {
2362 dev->loop_id = FC_NO_LOOP_ID;
2363 rval = QLA_FUNCTION_FAILED;
2372 * qla2x00_device_resync
2373 * Marks devices in the database that needs resynchronization.
2376 * ha = adapter block pointer.
2382 qla2x00_device_resync(scsi_qla_host_t *ha)
2388 uint32_t rscn_entry;
2389 uint8_t rscn_out_iter;
2393 rval = QLA_RSCNS_HANDLED;
2395 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2396 ha->flags.rscn_queue_overflow) {
2398 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2399 format = MSB(MSW(rscn_entry));
2400 d_id.b.domain = LSB(MSW(rscn_entry));
2401 d_id.b.area = MSB(LSW(rscn_entry));
2402 d_id.b.al_pa = LSB(LSW(rscn_entry));
2404 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2405 "[%02x/%02x%02x%02x].\n",
2406 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2407 d_id.b.area, d_id.b.al_pa));
2410 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2411 ha->rscn_out_ptr = 0;
2413 /* Skip duplicate entries. */
2414 for (rscn_out_iter = ha->rscn_out_ptr;
2415 !ha->flags.rscn_queue_overflow &&
2416 rscn_out_iter != ha->rscn_in_ptr;
2417 rscn_out_iter = (rscn_out_iter ==
2418 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2420 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2423 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2424 "entry found at [%d].\n", ha->host_no,
2427 ha->rscn_out_ptr = rscn_out_iter;
2430 /* Queue overflow, set switch default case. */
2431 if (ha->flags.rscn_queue_overflow) {
2432 DEBUG(printk("scsi(%ld): device_resync: rscn "
2433 "overflow.\n", ha->host_no));
2436 ha->flags.rscn_queue_overflow = 0;
2441 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) &&
2442 !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
2443 ha->flags.init_done) {
2444 /* Handle port RSCN via asyncronous IOCBs */
2445 rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
2447 if (rval2 == QLA_SUCCESS)
2461 ha->rscn_out_ptr = ha->rscn_in_ptr;
2467 /* Abort any outstanding IO descriptors. */
2468 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2469 qla2x00_cancel_io_descriptors(ha);
2471 list_for_each_entry(fcport, &ha->fcports, list) {
2472 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2473 (fcport->d_id.b24 & mask) != d_id.b24 ||
2474 fcport->port_type == FCT_BROADCAST)
2477 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2479 fcport->port_type != FCT_INITIATOR) {
2480 qla2x00_mark_device_lost(ha, fcport, 0);
2483 fcport->flags &= ~FCF_FARP_DONE;
2490 * qla2x00_fabric_dev_login
2491 * Login fabric target device and update FC port database.
2494 * ha: adapter state pointer.
2495 * fcport: port structure list pointer.
2496 * next_loopid: contains value of a new loop ID that can be used
2497 * by the next login attempt.
2500 * qla2x00 local function return status code.
2506 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2507 uint16_t *next_loopid)
2515 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2516 if (rval == QLA_SUCCESS) {
2517 rval = qla2x00_get_port_database(ha, fcport, 0);
2518 if (rval != QLA_SUCCESS) {
2519 ha->isp_ops.fabric_logout(ha, fcport->loop_id);
2521 qla2x00_update_fcport(ha, fcport);
2529 * qla2x00_fabric_login
2530 * Issue fabric login command.
2533 * ha = adapter block pointer.
2534 * device = pointer to FC device type structure.
2537 * 0 - Login successfully
2539 * 2 - Initiator device
2543 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2544 uint16_t *next_loopid)
2548 uint16_t tmp_loopid;
2549 uint16_t mb[MAILBOX_REGISTER_COUNT];
2555 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2556 "for port %02x%02x%02x.\n",
2557 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2558 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2560 /* Login fcport on switch. */
2561 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2562 fcport->d_id.b.domain, fcport->d_id.b.area,
2563 fcport->d_id.b.al_pa, mb, BIT_0);
2564 if (mb[0] == MBS_PORT_ID_USED) {
2566 * Device has another loop ID. The firmware team
2567 * recommends us to perform an implicit login with the
2568 * specified ID again. The ID we just used is save here
2569 * so we return with an ID that can be tried by the
2573 tmp_loopid = fcport->loop_id;
2574 fcport->loop_id = mb[1];
2576 DEBUG(printk("Fabric Login: port in use - next "
2577 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2578 fcport->loop_id, fcport->d_id.b.domain,
2579 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2581 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2586 /* A retry occurred before. */
2587 *next_loopid = tmp_loopid;
2590 * No retry occurred before. Just increment the
2591 * ID value for next login.
2593 *next_loopid = (fcport->loop_id + 1);
2596 if (mb[1] & BIT_0) {
2597 fcport->port_type = FCT_INITIATOR;
2599 fcport->port_type = FCT_TARGET;
2600 if (mb[1] & BIT_1) {
2601 fcport->flags |= FCF_TAPE_PRESENT;
2607 } else if (mb[0] == MBS_LOOP_ID_USED) {
2609 * Loop ID already used, try next loop ID.
2612 rval = qla2x00_find_new_loop_id(ha, fcport);
2613 if (rval != QLA_SUCCESS) {
2614 /* Ran out of loop IDs to use */
2617 } else if (mb[0] == MBS_COMMAND_ERROR) {
2619 * Firmware possibly timed out during login. If NO
2620 * retries are left to do then the device is declared
2623 *next_loopid = fcport->loop_id;
2624 ha->isp_ops.fabric_logout(ha, fcport->loop_id);
2625 qla2x00_mark_device_lost(ha, fcport, 1);
2631 * unrecoverable / not handled error
2633 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2634 "loop_id=%x jiffies=%lx.\n",
2635 __func__, ha->host_no, mb[0],
2636 fcport->d_id.b.domain, fcport->d_id.b.area,
2637 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2639 *next_loopid = fcport->loop_id;
2640 ha->isp_ops.fabric_logout(ha, fcport->loop_id);
2641 fcport->loop_id = FC_NO_LOOP_ID;
2642 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
2653 * qla2x00_local_device_login
2654 * Issue local device login command.
2657 * ha = adapter block pointer.
2658 * loop_id = loop id of device to login to.
2660 * Returns (Where's the #define!!!!):
2661 * 0 - Login successfully
2666 qla2x00_local_device_login(scsi_qla_host_t *ha, uint16_t loop_id)
2669 uint16_t mb[MAILBOX_REGISTER_COUNT];
2671 memset(mb, 0, sizeof(mb));
2672 rval = qla2x00_login_local_device(ha, loop_id, mb, BIT_0);
2673 if (rval == QLA_SUCCESS) {
2674 /* Interrogate mailbox registers for any errors */
2675 if (mb[0] == MBS_COMMAND_ERROR)
2677 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
2678 /* device not in PCB table */
2686 * qla2x00_loop_resync
2687 * Resync with fibre channel devices.
2690 * ha = adapter block pointer.
2696 qla2x00_loop_resync(scsi_qla_host_t *ha)
2703 atomic_set(&ha->loop_state, LOOP_UPDATE);
2704 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2705 if (ha->flags.online) {
2706 if (!(rval = qla2x00_fw_ready(ha))) {
2707 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2711 atomic_set(&ha->loop_state, LOOP_UPDATE);
2714 * Issue marker command only when we are going
2715 * to start the I/O .
2717 ha->marker_needed = 1;
2719 /* Remap devices on Loop. */
2720 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2722 qla2x00_configure_loop(ha);
2724 } while (!atomic_read(&ha->loop_down_timer) &&
2725 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
2727 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
2731 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2732 return (QLA_FUNCTION_FAILED);
2736 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
2743 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
2749 list_for_each_entry(fcport, &ha->fcports, list) {
2750 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
2753 qla2x00_update_fcport(ha, fcport);
2754 fcport->flags &= ~FCF_RESCAN_NEEDED;
2758 qla2x00_probe_for_all_luns(ha);
2763 * Resets ISP and aborts all outstanding commands.
2766 * ha = adapter block pointer.
2772 qla2x00_abort_isp(scsi_qla_host_t *ha)
2774 unsigned long flags = 0;
2779 if (ha->flags.online) {
2780 ha->flags.online = 0;
2781 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2783 qla_printk(KERN_INFO, ha,
2784 "Performing ISP error recovery - ha= %p.\n", ha);
2785 ha->isp_ops.reset_chip(ha);
2787 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
2788 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
2789 atomic_set(&ha->loop_state, LOOP_DOWN);
2790 qla2x00_mark_all_devices_lost(ha);
2792 if (!atomic_read(&ha->loop_down_timer))
2793 atomic_set(&ha->loop_down_timer,
2797 spin_lock_irqsave(&ha->hardware_lock, flags);
2798 /* Requeue all commands in outstanding command list. */
2799 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
2800 sp = ha->outstanding_cmds[cnt];
2802 ha->outstanding_cmds[cnt] = NULL;
2804 sp->cmd->result = DID_RESET << 16;
2805 sp->cmd->host_scribble = (unsigned char *)NULL;
2806 qla2x00_sp_compl(ha, sp);
2809 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2811 ha->isp_ops.nvram_config(ha);
2813 if (!qla2x00_restart_isp(ha)) {
2814 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2816 if (!atomic_read(&ha->loop_down_timer)) {
2818 * Issue marker command only when we are going
2819 * to start the I/O .
2821 ha->marker_needed = 1;
2824 ha->flags.online = 1;
2826 ha->isp_ops.enable_intrs(ha);
2828 ha->isp_abort_cnt = 0;
2829 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2830 } else { /* failed the ISP abort */
2831 ha->flags.online = 1;
2832 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
2833 if (ha->isp_abort_cnt == 0) {
2834 qla_printk(KERN_WARNING, ha,
2835 "ISP error recovery failed - "
2836 "board disabled\n");
2838 * The next call disables the board
2841 ha->isp_ops.reset_adapter(ha);
2842 ha->flags.online = 0;
2843 clear_bit(ISP_ABORT_RETRY,
2846 } else { /* schedule another ISP abort */
2847 ha->isp_abort_cnt--;
2848 DEBUG(printk("qla%ld: ISP abort - "
2849 "retry remainning %d\n",
2850 ha->host_no, ha->isp_abort_cnt);)
2854 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
2855 DEBUG(printk("qla2x00(%ld): ISP error recovery "
2856 "- retrying (%d) more times\n",
2857 ha->host_no, ha->isp_abort_cnt);)
2858 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2866 qla_printk(KERN_INFO, ha,
2867 "qla2x00_abort_isp: **** FAILED ****\n");
2869 DEBUG(printk(KERN_INFO
2870 "qla2x00_abort_isp(%ld): exiting.\n",
2878 * qla2x00_restart_isp
2879 * restarts the ISP after a reset
2882 * ha = adapter block pointer.
2888 qla2x00_restart_isp(scsi_qla_host_t *ha)
2891 device_reg_t __iomem *reg = ha->iobase;
2892 unsigned long flags = 0;
2895 /* If firmware needs to be loaded */
2896 if (qla2x00_isp_firmware(ha)) {
2897 ha->flags.online = 0;
2898 if (!(status = ha->isp_ops.chip_diag(ha))) {
2899 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2900 status = qla2x00_setup_chip(ha);
2906 spin_lock_irqsave(&ha->hardware_lock, flags);
2908 /* Disable SRAM, Instruction RAM and GP RAM parity. */
2909 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
2910 RD_REG_WORD(®->hccr); /* PCI Posting. */
2912 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2914 status = qla2x00_setup_chip(ha);
2916 spin_lock_irqsave(&ha->hardware_lock, flags);
2918 /* Enable proper parity */
2921 WRT_REG_WORD(®->hccr,
2922 (HCCR_ENABLE_PARITY + 0x1));
2924 /* SRAM, Instruction RAM and GP RAM parity */
2925 WRT_REG_WORD(®->hccr,
2926 (HCCR_ENABLE_PARITY + 0x7));
2927 RD_REG_WORD(®->hccr); /* PCI Posting. */
2929 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2934 if (!status && !(status = qla2x00_init_rings(ha))) {
2935 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2936 if (!(status = qla2x00_fw_ready(ha))) {
2937 DEBUG(printk("%s(): Start configure loop, "
2941 ha->flags.online = 1;
2942 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2945 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2946 qla2x00_configure_loop(ha);
2948 } while (!atomic_read(&ha->loop_down_timer) &&
2949 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
2951 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
2954 /* if no cable then assume it's good */
2955 if ((ha->device_flags & DFLG_NO_CABLE))
2958 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
2966 * qla2x00_reset_adapter
2970 * ha = adapter block pointer.
2973 qla2x00_reset_adapter(scsi_qla_host_t *ha)
2975 unsigned long flags = 0;
2976 device_reg_t __iomem *reg = ha->iobase;
2978 ha->flags.online = 0;
2979 ha->isp_ops.disable_intrs(ha);
2981 /* Reset RISC processor. */
2982 spin_lock_irqsave(&ha->hardware_lock, flags);
2983 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2984 RD_REG_WORD(®->hccr); /* PCI Posting. */
2985 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2986 RD_REG_WORD(®->hccr); /* PCI Posting. */
2987 spin_unlock_irqrestore(&ha->hardware_lock, flags);