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 "qla_devtbl.h"
23 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
24 #ifndef EXT_IS_LUN_BIT_SET
25 #define EXT_IS_LUN_BIT_SET(P,L) \
26 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
27 #define EXT_SET_LUN_BIT(P,L) \
28 ((P)->mask[L/8] |= (0x80 >> (L%8)))
32 * QLogic ISP2x00 Hardware Support Function Prototypes.
34 static int qla2x00_pci_config(scsi_qla_host_t *);
35 static int qla2x00_isp_firmware(scsi_qla_host_t *);
36 static void qla2x00_reset_chip(scsi_qla_host_t *);
37 static int qla2x00_chip_diag(scsi_qla_host_t *);
38 static int qla2x00_setup_chip(scsi_qla_host_t *);
39 static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
40 static int qla2x00_init_rings(scsi_qla_host_t *);
41 static int qla2x00_fw_ready(scsi_qla_host_t *);
42 static int qla2x00_configure_hba(scsi_qla_host_t *);
43 static int qla2x00_nvram_config(scsi_qla_host_t *);
44 static void qla2x00_init_tgt_map(scsi_qla_host_t *);
45 static int qla2x00_configure_loop(scsi_qla_host_t *);
46 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
47 static void qla2x00_update_fcport(scsi_qla_host_t *, fc_port_t *);
48 static void qla2x00_lun_discovery(scsi_qla_host_t *, fc_port_t *);
49 static int qla2x00_rpt_lun_discovery(scsi_qla_host_t *, fc_port_t *,
50 inq_cmd_rsp_t *, dma_addr_t);
51 static int qla2x00_report_lun(scsi_qla_host_t *, fc_port_t *,
52 rpt_lun_cmd_rsp_t *, dma_addr_t);
53 static fc_lun_t *qla2x00_cfg_lun(scsi_qla_host_t *, fc_port_t *, uint16_t,
54 inq_cmd_rsp_t *, dma_addr_t);
55 static fc_lun_t * qla2x00_add_lun(fc_port_t *, uint16_t);
56 static int qla2x00_inquiry(scsi_qla_host_t *, fc_port_t *, uint16_t,
57 inq_cmd_rsp_t *, dma_addr_t);
58 static int qla2x00_configure_fabric(scsi_qla_host_t *);
59 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
60 static int qla2x00_device_resync(scsi_qla_host_t *);
61 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
63 static void qla2x00_config_os(scsi_qla_host_t *ha);
64 static uint16_t qla2x00_fcport_bind(scsi_qla_host_t *ha, fc_port_t *fcport);
65 static os_lun_t * qla2x00_fclun_bind(scsi_qla_host_t *, fc_port_t *,
67 static void qla2x00_lun_free(scsi_qla_host_t *, uint16_t, uint16_t);
69 static int qla2x00_bstr_to_hex(char *, uint8_t *, int);
70 static int qla2x00_find_propname(scsi_qla_host_t *,
71 char *, char *, char *, int);
73 static void qla2x00_get_lun_mask_from_config(scsi_qla_host_t *, fc_port_t *,
75 static int qla2x00_get_prop_16chars(scsi_qla_host_t *,
76 char *, char *, char *);
77 static void qla2x00_get_properties(scsi_qla_host_t *, char *);
79 static void qla2x00_cfg_persistent_binding(scsi_qla_host_t *);
80 static os_tgt_t *qla2x00_persistent_bind(scsi_qla_host_t *, uint8_t *,
81 uint8_t *, port_id_t *, uint16_t);
84 static int qla2x00_restart_isp(scsi_qla_host_t *);
85 static void qla2x00_reset_adapter(scsi_qla_host_t *);
87 /****************************************************************************/
88 /* QLogic ISP2x00 Hardware Support Functions. */
89 /****************************************************************************/
92 * qla2x00_initialize_adapter
96 * ha = adapter block pointer.
102 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
105 uint8_t isp_init = 0;
106 uint8_t restart_risc = 0;
109 /* Clear adapter flags. */
110 ha->flags.online = FALSE;
111 ha->flags.reset_active = FALSE;
112 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
113 atomic_set(&ha->loop_state, LOOP_DOWN);
114 ha->device_flags = 0;
115 ha->sns_retry_cnt = 0;
117 ha->failback_delay = 0;
118 ha->flags.management_server_logged_in = 0;
119 ha->marker_needed = 0;
121 ha->isp_abort_cnt = 0;
122 ha->beacon_blink_led = 0;
124 rval = qla2x00_pci_config(ha);
126 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
131 qla2x00_reset_chip(ha);
133 /* Initialize target map database. */
134 qla2x00_init_tgt_map(ha);
136 /* Get Flash Version */
137 qla2x00_get_flash_version(ha);
139 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
140 qla2x00_nvram_config(ha);
142 ha->retry_count = ql2xretrycount;
144 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
148 * If the user specified a device configuration on the command line
149 * then use it as the configuration. Otherwise, we scan for all
153 ha->cmdline = ql2xdevconf;
154 qla2x00_get_properties(ha, ql2xdevconf);
160 * Try to configure the loop.
166 /* If firmware needs to be loaded */
167 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
168 if ((rval = qla2x00_chip_diag(ha)) == QLA_SUCCESS) {
169 rval = qla2x00_setup_chip(ha);
173 if (rval == QLA_SUCCESS &&
174 (rval = qla2x00_init_rings(ha)) == QLA_SUCCESS) {
175 check_fw_ready_again:
177 * Wait for a successful LIP up to a maximum
178 * of (in seconds): RISC login timeout value,
179 * RISC retry count value, and port down retry
180 * value OR a minimum of 4 seconds OR If no
181 * cable, only 5 seconds.
183 if (!qla2x00_fw_ready(ha)) {
184 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
187 * Go setup flash database devices with proper
191 clear_bit(LOOP_RESYNC_NEEDED,
193 rval = qla2x00_configure_loop(ha);
195 if (test_bit(ISP_ABORT_NEEDED,
203 * If loop state change while we were
204 * discoverying devices then wait for
208 if (atomic_read(&ha->loop_state) ==
209 LOOP_DOWN && retry--) {
210 goto check_fw_ready_again;
212 } while (!atomic_read(&ha->loop_down_timer) &&
214 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
223 } while (restart_risc && retry--);
226 /* Retrieve firmware information */
227 qla2x00_get_fw_version(ha, &ha->fw_major_version,
228 &ha->fw_minor_version, &ha->fw_subminor_version,
231 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
232 ha->marker_needed = 1;
233 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
234 ha->marker_needed = 0;
236 ha->flags.online = TRUE;
240 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
247 * qla2x00_pci_config() - Setup device PCI configuration registers.
250 * Returns 0 on success.
253 qla2x00_pci_config(scsi_qla_host_t *ha)
256 unsigned long flags = 0;
259 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
262 * Turn on PCI master; for system BIOSes that don't turn it on by
265 pci_set_master(ha->pdev);
267 if (pci_set_mwi(ha->pdev))
268 mwi = PCI_COMMAND_INVALIDATE;
269 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
272 return (QLA_FUNCTION_FAILED);
275 * We want to respect framework's setting of PCI configuration space
276 * command register and also want to make sure that all bits of
277 * interest to us are properly set in command register.
279 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
280 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
282 /* Get PCI bus information. */
283 spin_lock_irqsave(&ha->hardware_lock, flags);
284 ha->pci_attr = RD_REG_WORD(&ha->iobase->ctrl_status);
285 spin_unlock_irqrestore(&ha->hardware_lock, flags);
287 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
288 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
290 /* PCI Specification Revision 2.3 changes */
291 if (IS_QLA2322(ha) || IS_QLA6322(ha))
292 /* Command Register - Reset Interrupt Disable. */
296 * If this is a 2300 card and not 2312, reset the
297 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
298 * the 2310 also reports itself as a 2300 so we need to get the
299 * fb revision level -- a 6 indicates it really is a 2300 and
302 if (IS_QLA2300(ha)) {
303 spin_lock_irqsave(&ha->hardware_lock, flags);
306 WRT_REG_WORD(&ha->iobase->hccr, HCCR_PAUSE_RISC);
307 for (cnt = 0; cnt < 30000; cnt++) {
308 if ((RD_REG_WORD(&ha->iobase->hccr) &
309 HCCR_RISC_PAUSE) != 0)
315 /* Select FPM registers. */
316 WRT_REG_WORD(&ha->iobase->ctrl_status, 0x20);
318 /* Get the fb rev level */
319 ha->fb_rev = RD_FB_CMD_REG(ha, ha->iobase);
321 if (ha->fb_rev == FPM_2300)
322 w &= ~PCI_COMMAND_INVALIDATE;
324 /* Deselect FPM registers. */
325 WRT_REG_WORD(&ha->iobase->ctrl_status, 0x0);
327 /* Release RISC module. */
328 WRT_REG_WORD(&ha->iobase->hccr, HCCR_RELEASE_RISC);
329 for (cnt = 0; cnt < 30000; cnt++) {
330 if ((RD_REG_WORD(&ha->iobase->hccr) &
331 HCCR_RISC_PAUSE) == 0)
337 spin_unlock_irqrestore(&ha->hardware_lock, flags);
341 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
343 /* Reset expansion ROM address decode enable */
344 pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w);
345 w &= ~PCI_ROM_ADDRESS_ENABLE;
346 pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
348 return (QLA_SUCCESS);
352 * qla2x00_isp_firmware() - Choose firmware image.
355 * Returns 0 on success.
358 qla2x00_isp_firmware(scsi_qla_host_t *ha)
362 /* Assume loading risc code */
363 rval = QLA_FUNCTION_FAILED;
365 if (ha->flags.disable_risc_code_load) {
366 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
368 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
370 /* Verify checksum of loaded RISC code. */
371 rval = qla2x00_verify_checksum(ha);
375 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
383 * qla2x00_reset_chip() - Reset ISP chip.
386 * Returns 0 on success.
389 qla2x00_reset_chip(scsi_qla_host_t *ha)
391 unsigned long flags = 0;
392 device_reg_t *reg = ha->iobase;
394 unsigned long mbx_flags = 0;
397 /* Disable ISP interrupts. */
398 qla2x00_disable_intrs(ha);
400 spin_lock_irqsave(&ha->hardware_lock, flags);
402 /* Turn off master enable */
404 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
405 cmd &= ~PCI_COMMAND_MASTER;
406 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
408 if (!IS_QLA2100(ha)) {
410 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
411 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
412 for (cnt = 0; cnt < 30000; cnt++) {
413 if ((RD_REG_WORD(®->hccr) &
414 HCCR_RISC_PAUSE) != 0)
422 /* Select FPM registers. */
423 WRT_REG_WORD(®->ctrl_status, 0x20);
425 /* FPM Soft Reset. */
426 WRT_REG_WORD(®->fpm_diag_config, 0x100);
428 /* Toggle Fpm Reset. */
430 WRT_REG_WORD(®->fpm_diag_config, 0x0);
432 /* Select frame buffer registers. */
433 WRT_REG_WORD(®->ctrl_status, 0x10);
435 /* Reset frame buffer FIFOs. */
436 if (IS_QLA2200(ha)) {
437 WRT_FB_CMD_REG(ha, reg, 0xa000);
439 WRT_FB_CMD_REG(ha, reg, 0x00fc);
441 /* Read back fb_cmd until zero or 3 seconds max */
442 for (cnt = 0; cnt < 3000; cnt++) {
443 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
449 /* Select RISC module registers. */
450 WRT_REG_WORD(®->ctrl_status, 0);
452 /* Reset RISC processor. */
453 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
455 /* Release RISC processor. */
456 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
459 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
460 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
462 /* Reset ISP chip. */
463 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
465 /* Wait for RISC to recover from reset. */
466 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
468 * It is necessary to for a delay here since the card doesn't
469 * respond to PCI reads during a reset. On some architectures
470 * this will result in an MCA.
473 for (cnt = 30000; cnt; cnt--) {
474 if ((RD_REG_WORD(®->ctrl_status) &
475 CSR_ISP_SOFT_RESET) == 0)
482 /* Reset RISC processor. */
483 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
485 WRT_REG_WORD(®->semaphore, 0);
487 /* Release RISC processor. */
488 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
489 RD_REG_WORD(®->hccr); /* PCI Posting. */
491 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
492 for (cnt = 0; cnt < 30000; cnt++) {
493 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
494 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
496 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) {
497 if (!(test_bit(ABORT_ISP_ACTIVE,
499 spin_unlock_irqrestore(
500 &ha->mbx_reg_lock, mbx_flags);
504 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
505 spin_unlock_irqrestore(&ha->mbx_reg_lock,
513 /* Turn on master enable */
514 cmd |= PCI_COMMAND_MASTER;
515 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
517 /* Disable RISC pause on FPM parity error. */
519 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
521 spin_unlock_irqrestore(&ha->hardware_lock, flags);
525 * qla2x00_chip_diag() - Test chip for proper operation.
528 * Returns 0 on success.
531 qla2x00_chip_diag(scsi_qla_host_t *ha)
534 device_reg_t *reg = ha->iobase;
535 unsigned long flags = 0;
540 /* Assume a failed state */
541 rval = QLA_FUNCTION_FAILED;
543 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
544 ha->host_no, (u_long)®->flash_address));
546 spin_lock_irqsave(&ha->hardware_lock, flags);
548 /* Reset ISP chip. */
549 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
551 * We need to have a delay here since the card will not respond while
552 * in reset causing an MCA on some architectures.
555 data = qla2x00_debounce_register(®->ctrl_status);
556 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
558 data = RD_REG_WORD(®->ctrl_status);
563 goto chip_diag_failed;
565 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
568 /* Reset RISC processor. */
569 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
570 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
572 /* Workaround for QLA2312 PCI parity error */
573 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
574 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
575 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
577 data = RD_MAILBOX_REG(ha, reg, 0);
584 goto chip_diag_failed;
586 /* Check product ID of chip */
587 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
589 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
590 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
591 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
592 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
593 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
594 mb[3] != PROD_ID_3) {
595 qla_printk(KERN_WARNING, ha,
596 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
598 goto chip_diag_failed;
600 ha->product_id[0] = mb[1];
601 ha->product_id[1] = mb[2];
602 ha->product_id[2] = mb[3];
603 ha->product_id[3] = mb[4];
605 /* Adjust fw RISC transfer size */
606 if (REQUEST_ENTRY_CNT > 1024)
607 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
609 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * REQUEST_ENTRY_CNT;
611 if (IS_QLA2200(ha) &&
612 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
613 /* Limit firmware transfer size with a 2200A */
614 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
617 ha->fw_transfer_size = 128;
620 /* Wrap Incoming Mailboxes Test. */
621 spin_unlock_irqrestore(&ha->hardware_lock, flags);
623 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
624 rval = qla2x00_mbx_reg_test(ha);
626 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
628 qla_printk(KERN_WARNING, ha,
629 "Failed mailbox send register test\n");
632 /* Flag a successful rval */
635 spin_lock_irqsave(&ha->hardware_lock, flags);
639 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
640 "****\n", ha->host_no));
642 spin_unlock_irqrestore(&ha->hardware_lock, flags);
648 * qla2x00_setup_chip() - Load and start RISC firmware.
651 * Returns 0 on success.
654 qla2x00_setup_chip(scsi_qla_host_t *ha)
659 unsigned long risc_address;
660 unsigned long risc_code_size;
664 struct qla_fw_info *fw_iter;
668 /* Load firmware sequences */
669 fw_iter = ha->brd_info->fw_info;
670 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
671 risc_code = fw_iter->fwcode;
672 risc_code_size = *fw_iter->fwlen;
674 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
675 risc_address = *fw_iter->fwstart;
677 /* Extended address */
678 risc_address = *fw_iter->lfwstart;
683 while (risc_code_size > 0 && !rval) {
684 cnt = (uint16_t)(ha->fw_transfer_size >> 1);
685 if (cnt > risc_code_size)
686 cnt = risc_code_size;
688 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
689 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
690 ha->host_no, risc_code, cnt, risc_address));
692 req_ring = (uint16_t *)ha->request_ring;
693 for (i = 0; i < cnt; i++)
694 req_ring[i] = cpu_to_le16(risc_code[i]);
696 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
697 rval = qla2x00_load_ram(ha,
698 ha->request_dma, risc_address, cnt);
700 rval = qla2x00_load_ram_ext(ha,
701 ha->request_dma, risc_address, cnt);
704 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
705 "load segment %d of firmware\n",
707 qla_printk(KERN_WARNING, ha,
708 "[ERROR] Failed to load "
709 "segment %d of firmware\n", num);
711 qla2x00_dump_regs(ha);
717 risc_code_size -= cnt;
721 /* Next firmware sequence */
725 /* Verify checksum of loaded RISC code. */
727 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
728 "code.\n", ha->host_no));
730 rval = qla2x00_verify_checksum(ha);
731 if (rval == QLA_SUCCESS) {
732 /* Start firmware execution. */
733 DEBUG(printk("scsi(%ld): Checksum OK, start "
734 "firmware.\n", ha->host_no));
736 rval = qla2x00_execute_fw(ha);
739 DEBUG2(printk(KERN_INFO
740 "scsi(%ld): ISP Firmware failed checksum.\n",
746 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
754 * qla2x00_init_response_q_entries() - Initializes response queue entries.
757 * Beginning of request ring has initialization control block already built
758 * by nvram config routine.
760 * Returns 0 on success.
763 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
768 pkt = ha->response_ring_ptr;
769 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
770 pkt->signature = RESPONSE_PROCESSED;
777 * qla2x00_init_rings() - Initializes firmware.
780 * Beginning of request ring has initialization control block already built
781 * by nvram config routine.
783 * Returns 0 on success.
786 qla2x00_init_rings(scsi_qla_host_t *ha)
789 unsigned long flags = 0;
791 device_reg_t *reg = ha->iobase;
793 spin_lock_irqsave(&ha->hardware_lock, flags);
795 /* Clear outstanding commands array. */
796 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
797 ha->outstanding_cmds[cnt] = 0;
799 ha->current_outstanding_cmd = 0;
801 /* Clear RSCN queue. */
803 ha->rscn_out_ptr = 0;
805 /* Initialize firmware. */
806 ha->request_ring_ptr = ha->request_ring;
807 ha->req_ring_index = 0;
808 ha->req_q_cnt = REQUEST_ENTRY_CNT;
809 ha->response_ring_ptr = ha->response_ring;
810 ha->rsp_ring_index = 0;
812 /* Initialize response queue entries */
813 qla2x00_init_response_q_entries(ha);
815 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
816 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
817 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
818 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
819 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg));
821 spin_unlock_irqrestore(&ha->hardware_lock, flags);
823 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
824 rval = qla2x00_init_firmware(ha, sizeof(init_cb_t));
826 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
829 /* Setup seriallink options */
830 uint16_t swing, emphasis;
832 DEBUG3(printk("scsi(%ld): Serial link options:\n",
834 DEBUG3(qla2x00_dump_buffer(
835 (uint8_t *)&ha->fw_seriallink_options,
836 sizeof(ha->fw_seriallink_options)));
838 memset(ha->fw_options, 0, sizeof(ha->fw_options));
839 qla2x00_get_fw_options(ha, ha->fw_options);
841 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
842 if (ha->fw_seriallink_options[1] & BIT_2)
843 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
846 swing = ha->fw_seriallink_options[0] & (BIT_2 | BIT_1 | BIT_0);
847 emphasis = ha->fw_seriallink_options[0] & (BIT_4 | BIT_3);
849 ha->fw_options[10] = (emphasis << 14) | (swing << 8) | 0x3;
852 swing = ha->fw_seriallink_options[0] & (BIT_7 | BIT_6 | BIT_5);
854 emphasis = ha->fw_seriallink_options[1] & (BIT_1 | BIT_0);
855 ha->fw_options[11] = (emphasis << 14) | (swing << 8) | 0x3;
857 qla2x00_set_fw_options(ha, ha->fw_options);
859 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
867 * qla2x00_fw_ready() - Waits for firmware ready.
870 * Returns 0 on success.
873 qla2x00_fw_ready(scsi_qla_host_t *ha)
876 unsigned long wtime, mtime;
877 uint16_t min_wait; /* Minimum wait time if loop is down */
878 uint16_t wait_time; /* Wait time if loop is coming ready */
883 /* 20 seconds for loop down. */
887 * Firmware should take at most one RATOV to login, plus 5 seconds for
888 * our own processing.
890 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
891 wait_time = min_wait;
894 /* Min wait time if loop down */
895 mtime = jiffies + (min_wait * HZ);
897 /* wait time before firmware ready */
898 wtime = jiffies + (wait_time * HZ);
900 /* Wait for ISP to finish LIP */
901 if (!ha->flags.init_done)
902 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
904 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
908 rval = qla2x00_get_firmware_state(ha, &fw_state);
909 if (rval == QLA_SUCCESS) {
910 if (fw_state < FSTATE_LOSS_OF_SYNC) {
911 ha->device_flags &= ~DFLG_NO_CABLE;
913 if (fw_state == FSTATE_READY) {
914 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
917 qla2x00_get_retry_cnt(ha, &ha->retry_count,
918 &ha->login_timeout, &ha->r_a_tov);
924 rval = QLA_FUNCTION_FAILED;
926 if (atomic_read(&ha->loop_down_timer) &&
927 fw_state >= FSTATE_LOSS_OF_SYNC) {
928 /* Loop down. Timeout on min_wait for states
929 * other than Wait for Login.
931 if (time_after_eq(jiffies, mtime)) {
932 qla_printk(KERN_INFO, ha,
933 "Cable is unplugged...\n");
935 ha->device_flags |= DFLG_NO_CABLE;
940 /* Mailbox cmd failed. Timeout on min_wait. */
941 if (time_after_eq(jiffies, mtime))
945 if (time_after_eq(jiffies, wtime))
948 /* Delay for a while */
949 set_current_state(TASK_INTERRUPTIBLE);
950 schedule_timeout(HZ / 2);
952 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
953 ha->host_no, fw_state, jiffies));
956 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
957 ha->host_no, fw_state, jiffies));
960 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
968 * qla2x00_configure_hba
969 * Setup adapter context.
972 * ha = adapter state pointer.
981 qla2x00_configure_hba(scsi_qla_host_t *ha)
989 char connect_type[22];
991 /* Get host addresses. */
992 rval = qla2x00_get_adapter_id(ha,
993 &loop_id, &al_pa, &area, &domain, &topo);
994 if (rval != QLA_SUCCESS) {
995 qla_printk(KERN_WARNING, ha,
996 "ERROR -- Unable to get host loop ID.\n");
1001 qla_printk(KERN_INFO, ha,
1002 "Cannot get topology - retrying.\n");
1003 return (QLA_FUNCTION_FAILED);
1006 ha->loop_id = loop_id;
1008 /* Make sure 2100 only has loop, in case of any firmware bug. */
1013 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1014 ha->operating_mode = LOOP;
1018 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1020 ha->current_topology = ISP_CFG_NL;
1021 strcpy(connect_type, "(Loop)");
1025 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1027 ha->current_topology = ISP_CFG_FL;
1028 strcpy(connect_type, "(FL_Port)");
1032 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1034 ha->operating_mode = P2P;
1035 ha->current_topology = ISP_CFG_N;
1036 strcpy(connect_type, "(N_Port-to-N_Port)");
1040 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1042 ha->operating_mode = P2P;
1043 ha->current_topology = ISP_CFG_F;
1044 strcpy(connect_type, "(F_Port)");
1048 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1050 ha->host_no, topo));
1051 ha->current_topology = ISP_CFG_NL;
1052 strcpy(connect_type, "(Loop)");
1056 /* Save Host port and loop ID. */
1057 /* byte order - Big Endian */
1058 ha->d_id.b.domain = domain;
1059 ha->d_id.b.area = area;
1060 ha->d_id.b.al_pa = al_pa;
1062 if (!ha->flags.init_done)
1063 qla_printk(KERN_INFO, ha,
1064 "Topology - %s, Host Loop address 0x%x\n",
1065 connect_type, ha->loop_id);
1068 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1070 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1077 * NVRAM configuration for ISP 2xxx
1080 * ha = adapter block pointer.
1083 * initialization control block in response_ring
1084 * host adapters parameters in host adapter block
1090 qla2x00_nvram_config(scsi_qla_host_t *ha)
1095 uint8_t *dptr1, *dptr2;
1096 init_cb_t *icb = ha->init_cb;
1097 nvram_t *nv = (nvram_t *)ha->request_ring;
1098 uint16_t *wptr = (uint16_t *)ha->request_ring;
1099 device_reg_t *reg = ha->iobase;
1100 uint16_t timer_mode;
1104 if (ha->flags.init_done)
1107 /* Determine NVRAM starting address. */
1109 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1110 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1111 ha->nvram_base = 0x80;
1113 /* Get NVRAM data and calculate checksum. */
1114 qla2x00_lock_nvram_access(ha);
1115 for (cnt = 0; cnt < sizeof(nvram_t)/2; cnt++) {
1116 *wptr = cpu_to_le16(qla2x00_get_nvram_word(ha,
1117 (cnt+ha->nvram_base)));
1118 chksum += (uint8_t)*wptr;
1119 chksum += (uint8_t)(*wptr >> 8);
1122 qla2x00_unlock_nvram_access(ha);
1124 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1125 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1128 /* Bad NVRAM data, set defaults parameters. */
1129 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1130 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1131 /* Reset NVRAM data. */
1132 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1133 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1135 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1136 "invalid -- WWPN) defaults.\n");
1139 * Set default initialization control block.
1141 memset(nv, 0, sizeof(nvram_t));
1142 nv->parameter_block_version = ICB_VERSION;
1144 if (IS_QLA23XX(ha)) {
1145 nv->firmware_options[0] = BIT_2 | BIT_1;
1146 nv->firmware_options[1] = BIT_7 | BIT_5;
1147 nv->add_firmware_options[0] = BIT_5;
1148 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1149 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1150 nv->special_options[1] = BIT_7;
1151 } else if (IS_QLA2200(ha)) {
1152 nv->firmware_options[0] = BIT_2 | BIT_1;
1153 nv->firmware_options[1] = BIT_7 | BIT_5;
1154 nv->add_firmware_options[0] = BIT_5 | BIT_4;
1155 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1156 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1157 } else if (IS_QLA2100(ha)) {
1158 nv->firmware_options[0] = BIT_3 | BIT_1;
1159 nv->firmware_options[1] = BIT_5;
1160 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1163 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1164 nv->execution_throttle = __constant_cpu_to_le16(16);
1165 nv->retry_count = 8;
1166 nv->retry_delay = 1;
1168 nv->port_name[0] = 33;
1169 nv->port_name[3] = 224;
1170 nv->port_name[4] = 139;
1172 nv->login_timeout = 4;
1175 * Set default host adapter parameters
1177 nv->host_p[1] = BIT_2;
1178 nv->reset_delay = 5;
1179 nv->port_down_retry_count = 8;
1180 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1181 nv->link_down_timeout = 60;
1186 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1188 * The SN2 does not provide BIOS emulation which means you can't change
1189 * potentially bogus BIOS settings. Force the use of default settings
1190 * for link rate and frame size. Hope that the rest of the settings
1193 if (ia64_platform_is("sn2")) {
1194 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1196 nv->special_options[1] = BIT_7;
1200 /* Reset Initialization control block */
1201 memset(icb, 0, sizeof(init_cb_t));
1204 * Setup driver NVRAM options.
1206 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1207 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1208 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1209 nv->firmware_options[1] &= ~BIT_4;
1211 if (IS_QLA23XX(ha)) {
1212 nv->firmware_options[0] |= BIT_2;
1213 nv->firmware_options[0] &= ~BIT_3;
1215 if (IS_QLA2300(ha)) {
1216 if (ha->fb_rev == FPM_2310) {
1217 strcpy(ha->model_number, "QLA2310");
1219 strcpy(ha->model_number, "QLA2300");
1223 memcmp(nv->model_number, BINZERO,
1224 sizeof(nv->model_number)) != 0) {
1227 strncpy(ha->model_number, nv->model_number,
1228 sizeof(nv->model_number));
1229 st = en = ha->model_number;
1230 en += sizeof(nv->model_number) - 1;
1232 if (*en != 0x20 && *en != 0x00)
1239 index = (ha->pdev->subsystem_device & 0xff);
1240 if (index < QLA_MODEL_NAMES) {
1241 strcpy(ha->model_number,
1242 qla2x00_model_name[index]);
1244 qla2x00_model_desc[index];
1246 strcpy(ha->model_number, "QLA23xx");
1250 } else if (IS_QLA2200(ha)) {
1251 nv->firmware_options[0] |= BIT_2;
1252 strcpy(ha->model_number, "QLA22xx");
1253 } else /*if (IS_QLA2100(ha))*/ {
1254 strcpy(ha->model_number, "QLA2100");
1258 * Copy over NVRAM RISC parameter block to initialization control block.
1260 dptr1 = (uint8_t *)icb;
1261 dptr2 = (uint8_t *)&nv->parameter_block_version;
1262 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1264 *dptr1++ = *dptr2++;
1266 /* Copy 2nd half. */
1267 dptr1 = (uint8_t *)icb->add_firmware_options;
1268 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1270 *dptr1++ = *dptr2++;
1272 /* Prepare nodename */
1273 if ((icb->firmware_options[1] & BIT_6) == 0) {
1275 * Firmware will apply the following mask if the nodename was
1278 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1279 icb->node_name[0] &= 0xF0;
1283 * Set host adapter parameters.
1285 ha->nvram_version = nv->nvram_version;
1287 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1288 /* Always load RISC code on non ISP2[12]00 chips. */
1289 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1290 ha->flags.disable_risc_code_load = 0;
1291 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1292 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1293 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1295 ha->operating_mode =
1296 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1298 ha->fw_seriallink_options[0] = nv->seriallink_options[0];
1299 ha->fw_seriallink_options[1] = nv->seriallink_options[1];
1301 /* save HBA serial number */
1302 ha->serial0 = icb->port_name[5];
1303 ha->serial1 = icb->port_name[6];
1304 ha->serial2 = icb->port_name[7];
1305 memcpy(ha->node_name, icb->node_name, WWN_SIZE);
1307 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1309 ha->retry_count = nv->retry_count;
1311 /* Set minimum login_timeout to 4 seconds. */
1312 if (nv->login_timeout < ql2xlogintimeout)
1313 nv->login_timeout = ql2xlogintimeout;
1314 if (nv->login_timeout < 4)
1315 nv->login_timeout = 4;
1316 ha->login_timeout = nv->login_timeout;
1317 icb->login_timeout = nv->login_timeout;
1319 /* Set minimum RATOV to 200 tenths of a second. */
1322 ha->minimum_timeout =
1323 (ha->login_timeout * ha->retry_count) + nv->port_down_retry_count;
1324 ha->loop_reset_delay = nv->reset_delay;
1326 /* Will get the value from NVRAM. */
1327 ha->loop_down_timeout = LOOP_DOWN_TIMEOUT;
1329 /* Link Down Timeout = 0:
1331 * When Port Down timer expires we will start returning
1332 * I/O's to OS with "DID_NO_CONNECT".
1334 * Link Down Timeout != 0:
1336 * The driver waits for the link to come up after link down
1337 * before returning I/Os to OS with "DID_NO_CONNECT".
1339 if (nv->link_down_timeout == 0) {
1340 ha->loop_down_abort_time =
1341 (LOOP_DOWN_TIME - ha->loop_down_timeout);
1343 ha->link_down_timeout = nv->link_down_timeout;
1344 ha->loop_down_abort_time =
1345 (LOOP_DOWN_TIME - ha->link_down_timeout);
1348 ha->max_luns = MAX_LUNS;
1349 ha->max_probe_luns = le16_to_cpu(nv->max_luns_per_target);
1350 if (ha->max_probe_luns == 0)
1351 ha->max_probe_luns = MIN_LUNS;
1354 * Need enough time to try and get the port back.
1356 ha->port_down_retry_count = nv->port_down_retry_count;
1357 if (qlport_down_retry)
1358 ha->port_down_retry_count = qlport_down_retry;
1359 /* Set login_retry_count */
1360 ha->login_retry_count = nv->retry_count;
1361 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1362 ha->port_down_retry_count > 3)
1363 ha->login_retry_count = ha->port_down_retry_count;
1364 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1365 ha->login_retry_count = ha->port_down_retry_count;
1366 if (ql2xloginretrycount)
1367 ha->login_retry_count = ql2xloginretrycount;
1369 ha->binding_type = Bind;
1370 if (ha->binding_type != BIND_BY_PORT_NAME &&
1371 ha->binding_type != BIND_BY_PORT_ID) {
1372 qla_printk(KERN_WARNING, ha,
1373 "Invalid binding type specified (%d), "
1374 "defaulting to BIND_BY_PORT_NAME!!!\n", ha->binding_type);
1376 ha->binding_type = BIND_BY_PORT_NAME;
1380 * Setup ring parameters in initialization control block
1382 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1383 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1384 icb->request_q_length = __constant_cpu_to_le16(REQUEST_ENTRY_CNT);
1385 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1386 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1387 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1388 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1389 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1391 icb->lun_enables = __constant_cpu_to_le16(0);
1392 icb->command_resource_count = 0;
1393 icb->immediate_notify_resource_count = 0;
1394 icb->timeout = __constant_cpu_to_le16(0);
1396 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1398 icb->firmware_options[0] &= ~BIT_3;
1399 icb->add_firmware_options[0] &=
1400 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1401 icb->add_firmware_options[0] |= BIT_2;
1402 icb->response_accumulation_timer = 3;
1403 icb->interrupt_delay_timer = 5;
1405 ha->flags.process_response_queue = 1;
1409 * icb->add_firmware_options[0] &=
1410 * ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1411 * icb->add_firmware_options[0] |= (BIT_2 | BIT_0);
1413 timer_mode = icb->add_firmware_options[0] &
1414 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1415 if (timer_mode == 5) {
1416 DEBUG2(printk("scsi(%ld): ZIO enabled; timer delay "
1417 "(%d).\n", ha->host_no, ql2xintrdelaytimer));
1418 qla_printk(KERN_INFO, ha,
1419 "ZIO enabled; timer delay (%d).\n",
1420 ql2xintrdelaytimer);
1422 icb->interrupt_delay_timer = ql2xintrdelaytimer;
1424 ha->flags.process_response_queue = 1;
1429 DEBUG2_3(printk(KERN_WARNING
1430 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1436 * qla2x00_init_tgt_map
1437 * Initializes target map.
1440 * ha = adapter block pointer.
1446 qla2x00_init_tgt_map(scsi_qla_host_t *ha)
1450 for (t = 0; t < MAX_TARGETS; t++)
1451 TGT_Q(ha, t) = (os_tgt_t *)NULL;
1455 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1457 * @flags: allocation flags
1459 * Returns a pointer to the allocated fcport, or NULL, if none available.
1462 qla2x00_alloc_fcport(scsi_qla_host_t *ha, int flags)
1466 fcport = kmalloc(sizeof(fc_port_t), flags);
1470 /* Setup fcport template structure. */
1471 memset(fcport, 0, sizeof (fc_port_t));
1473 fcport->port_type = FCT_UNKNOWN;
1474 fcport->loop_id = FC_NO_LOOP_ID;
1475 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1476 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1477 fcport->flags = FCF_RLC_SUPPORT;
1478 INIT_LIST_HEAD(&fcport->fcluns);
1484 * qla2x00_configure_loop
1485 * Updates Fibre Channel Device Database with what is actually on loop.
1488 * ha = adapter block pointer.
1493 * 2 = database was full and device was not configured.
1496 qla2x00_configure_loop(scsi_qla_host_t *ha)
1500 unsigned long flags, save_flags;
1504 /* Get Initiator ID */
1505 if (qla2x00_configure_hba(ha)) {
1506 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1508 return (QLA_FUNCTION_FAILED);
1511 save_flags = flags = ha->dpc_flags;
1512 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1513 ha->host_no, flags));
1515 /* dg 02/26/02 ha->dpc_flags &= ~(LOCAL_LOOP_UPDATE | RSCN_UPDATE); */
1518 * If we have both an RSCN and PORT UPDATE pending then handle them
1519 * both at the same time.
1521 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1522 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1525 /* Determine what we need to do */
1526 if (ha->current_topology == ISP_CFG_FL &&
1527 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1529 ha->flags.rscn_queue_overflow = TRUE;
1530 set_bit(RSCN_UPDATE, &flags);
1532 } else if (ha->current_topology == ISP_CFG_F &&
1533 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1535 ha->flags.rscn_queue_overflow = TRUE;
1536 set_bit(RSCN_UPDATE, &flags);
1537 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1539 } else if (!ha->flags.online ||
1540 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1542 ha->flags.rscn_queue_overflow = TRUE;
1543 set_bit(RSCN_UPDATE, &flags);
1544 set_bit(LOCAL_LOOP_UPDATE, &flags);
1548 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1549 rval = rval | qla2x00_configure_local_loop(ha);
1552 if (test_bit(RSCN_UPDATE, &flags)) {
1553 rval1 = qla2x00_configure_fabric(ha);
1554 if ((rval1 & BIT_0) && ha->sns_retry_cnt < 8) {
1555 ha->sns_retry_cnt++;
1556 set_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
1560 /* Isolate error status. */
1567 } while (rval != QLA_SUCCESS);
1569 if (!atomic_read(&ha->loop_down_timer) &&
1570 !(test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))) {
1572 qla2x00_config_os(ha);
1574 /* If we found all devices then go ready */
1575 if (!(test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags))) {
1576 atomic_set(&ha->loop_state, LOOP_READY);
1578 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1580 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1581 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1582 if (test_bit(RSCN_UPDATE, &save_flags))
1583 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1586 DEBUG(printk("scsi(%ld): Loop down counter running= %d or "
1587 "Resync needed- dpc flags= %ld\n",
1589 atomic_read(&ha->loop_down_timer), ha->dpc_flags));
1590 /* ???? dg 02/26/02 rval = 1; */
1594 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1595 __func__, ha->host_no));
1597 DEBUG3(printk("%s: exiting normally\n", __func__));
1600 /* Restore state if a resync event occured during processing */
1601 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1602 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1603 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1604 if (test_bit(RSCN_UPDATE, &save_flags))
1605 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1614 * qla2x00_configure_local_loop
1615 * Updates Fibre Channel Device Database with local loop devices.
1618 * ha = adapter block pointer.
1625 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1630 fc_port_t *fcport, *new_fcport;
1638 uint8_t loop_id_2100; /* ISP2100/ISP2200 -- 4 bytes. */
1639 uint16_t loop_id; /* ISP23XX -- 6 bytes. */
1641 #define MAX_ID_LIST_SIZE (sizeof(struct dev_id) * MAX_FIBRE_DEVICES)
1642 dma_addr_t id_list_dma;
1645 uint8_t domain, area, al_pa;
1652 * No point in continuing if the loop is in a volatile state --
1653 * reschedule LOCAL_LOOP_UPDATE for later processing
1655 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1656 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1660 entries = MAX_FIBRE_DEVICES;
1661 id_list = pci_alloc_consistent(ha->pdev, MAX_ID_LIST_SIZE,
1663 if (id_list == NULL) {
1664 DEBUG2(printk("scsi(%ld): Failed to allocate memory, No local "
1665 "loop\n", ha->host_no));
1667 qla_printk(KERN_WARNING, ha,
1668 "Memory Allocation failed - port_list");
1673 memset(id_list, 0, MAX_ID_LIST_SIZE);
1675 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1676 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1678 /* Get list of logged in devices. */
1679 rval = qla2x00_get_id_list(ha, id_list, id_list_dma, &entries);
1682 goto cleanup_allocation;
1685 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1686 ha->host_no, entries));
1687 DEBUG3(qla2x00_dump_buffer((uint8_t *)id_list,
1688 entries * sizeof(struct dev_id)));
1690 /* Allocate temporary fcport for any new fcports discovered. */
1691 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1692 if (new_fcport == NULL) {
1694 goto cleanup_allocation;
1696 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1699 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1701 list_for_each_entry(fcport, &ha->fcports, list) {
1702 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1703 fcport->port_type != FCT_BROADCAST &&
1704 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1706 DEBUG(printk("scsi(%ld): Marking port lost, "
1708 ha->host_no, fcport->loop_id));
1710 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1711 fcport->flags &= ~FCF_FARP_DONE;
1715 /* Add devices to port list. */
1716 id_iter = (char *)id_list;
1717 for (index = 0; index < entries; index++) {
1718 domain = ((struct dev_id *)id_iter)->domain;
1719 area = ((struct dev_id *)id_iter)->area;
1720 al_pa = ((struct dev_id *)id_iter)->al_pa;
1721 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1723 (uint16_t)((struct dev_id *)id_iter)->loop_id_2100;
1727 le16_to_cpu(((struct dev_id *)id_iter)->loop_id);
1731 /* Bypass reserved domain fields. */
1732 if ((domain & 0xf0) == 0xf0)
1735 /* Bypass if not same domain and area of adapter. */
1736 if (area != ha->d_id.b.area || domain != ha->d_id.b.domain)
1739 /* Bypass invalid local loop ID. */
1740 if (loop_id > LAST_LOCAL_LOOP_ID)
1743 /* Fill in member data. */
1744 new_fcport->d_id.b.domain = domain;
1745 new_fcport->d_id.b.area = area;
1746 new_fcport->d_id.b.al_pa = al_pa;
1747 new_fcport->loop_id = loop_id;
1748 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1749 if (rval2 != QLA_SUCCESS) {
1750 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1751 "information -- get_port_database=%x, "
1753 ha->host_no, rval2, new_fcport->loop_id));
1757 /* Check for matching device in port list. */
1760 list_for_each_entry(fcport, &ha->fcports, list) {
1761 if (memcmp(new_fcport->port_name, fcport->port_name,
1765 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1766 FCF_PERSISTENT_BOUND);
1767 fcport->loop_id = new_fcport->loop_id;
1768 fcport->port_type = new_fcport->port_type;
1769 fcport->d_id.b24 = new_fcport->d_id.b24;
1770 memcpy(fcport->node_name, new_fcport->node_name,
1778 /* New device, add to fcports list. */
1779 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1780 list_add_tail(&new_fcport->list, &ha->fcports);
1782 /* Allocate a new replacement fcport. */
1783 fcport = new_fcport;
1784 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1785 if (new_fcport == NULL) {
1787 goto cleanup_allocation;
1789 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1792 qla2x00_update_fcport(ha, fcport);
1798 pci_free_consistent(ha->pdev, MAX_ID_LIST_SIZE, id_list, id_list_dma);
1804 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1805 "rval=%x\n", ha->host_no, rval));
1809 ha->device_flags |= DFLG_LOCAL_DEVICES;
1810 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
1817 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
1821 qla2x00_mark_all_devices_lost(ha);
1822 list_for_each_entry(fcport, &ha->fcports, list) {
1823 if (fcport->port_type != FCT_TARGET)
1826 qla2x00_update_fcport(ha, fcport);
1831 * qla2x00_update_fcport
1832 * Updates device on list.
1835 * ha = adapter block pointer.
1836 * fcport = port structure pointer.
1846 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
1849 unsigned long flags;
1853 fcport->login_retry = 0;
1854 fcport->port_login_retry_count = ha->port_down_retry_count *
1856 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
1858 fcport->flags &= ~FCF_LOGIN_NEEDED;
1861 * Check for outstanding cmd on tape Bypass LUN discovery if active
1864 if (fcport->flags & FCF_TAPE_PRESENT) {
1865 spin_lock_irqsave(&ha->hardware_lock, flags);
1866 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
1867 if ((sp = ha->outstanding_cmds[index]) != 0) {
1868 if (sp->fclun->fcport == 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 /* Do LUN discovery. */
1880 if (fcport->port_type == FCT_INITIATOR ||
1881 fcport->port_type == FCT_BROADCAST) {
1882 fcport->device_type = TYPE_PROCESSOR;
1884 qla2x00_lun_discovery(ha, fcport);
1886 atomic_set(&fcport->state, FCS_ONLINE);
1890 * qla2x00_lun_discovery
1891 * Issue SCSI inquiry command for LUN discovery.
1894 * ha: adapter state pointer.
1895 * fcport: FC port structure pointer.
1901 qla2x00_lun_discovery(scsi_qla_host_t *ha, fc_port_t *fcport)
1907 inq = pci_alloc_consistent(ha->pdev, sizeof(inq_cmd_rsp_t), &inq_dma);
1909 qla_printk(KERN_WARNING, ha,
1910 "Memory Allocation failed - INQ\n");
1914 /* If report LUN works, exit. */
1915 if (qla2x00_rpt_lun_discovery(ha, fcport, inq, inq_dma) !=
1917 for (lun = 0; lun < ha->max_probe_luns; lun++) {
1918 /* Configure LUN. */
1919 qla2x00_cfg_lun(ha, fcport, lun, inq, inq_dma);
1923 pci_free_consistent(ha->pdev, sizeof(inq_cmd_rsp_t), inq, inq_dma);
1927 * qla2x00_rpt_lun_discovery
1928 * Issue SCSI report LUN command for LUN discovery.
1931 * ha: adapter state pointer.
1932 * fcport: FC port structure pointer.
1935 * qla2x00 local function return status code.
1941 qla2x00_rpt_lun_discovery(scsi_qla_host_t *ha, fc_port_t *fcport,
1942 inq_cmd_rsp_t *inq, dma_addr_t inq_dma)
1947 rpt_lun_cmd_rsp_t *rlc;
1950 /* Assume a failed status */
1951 rval = QLA_FUNCTION_FAILED;
1953 /* No point in continuing if the device doesn't support RLC */
1954 if ((fcport->flags & FCF_RLC_SUPPORT) == 0)
1957 rlc = pci_alloc_consistent(ha->pdev, sizeof(rpt_lun_cmd_rsp_t),
1960 qla_printk(KERN_WARNING, ha,
1961 "Memory Allocation failed - RLC");
1962 return QLA_MEMORY_ALLOC_FAILED;
1965 rval = qla2x00_report_lun(ha, fcport, rlc, rlc_dma);
1966 if (rval != QLA_SUCCESS) {
1967 pci_free_consistent(ha->pdev, sizeof(rpt_lun_cmd_rsp_t), rlc,
1972 /* Always add a fc_lun_t structure for lun 0 -- mid-layer requirement */
1973 qla2x00_add_lun(fcport, 0);
1975 /* Configure LUN list. */
1976 len = be32_to_cpu(rlc->list.hdr.len);
1978 for (cnt = 0; cnt < len; cnt++) {
1979 lun = CHAR_TO_SHORT(rlc->list.lst[cnt].lsb,
1980 rlc->list.lst[cnt].msb.b);
1982 DEBUG3(printk("scsi(%ld): RLC lun = (%d)\n", ha->host_no, lun));
1984 /* We only support 0 through MAX_LUNS-1 range */
1985 if (lun < MAX_LUNS) {
1986 qla2x00_cfg_lun(ha, fcport, lun, inq, inq_dma);
1989 atomic_set(&fcport->state, FCS_ONLINE);
1991 pci_free_consistent(ha->pdev, sizeof(rpt_lun_cmd_rsp_t), rlc, rlc_dma);
1997 * qla2x00_report_lun
1998 * Issue SCSI report LUN command.
2001 * ha: adapter state pointer.
2002 * fcport: FC port structure pointer.
2003 * mem: pointer to dma memory object for report LUN IOCB
2007 * qla2x00 local function return status code.
2013 qla2x00_report_lun(scsi_qla_host_t *ha,
2014 fc_port_t *fcport, rpt_lun_cmd_rsp_t *rlc, dma_addr_t rlc_dma)
2018 uint16_t comp_status;
2019 uint16_t scsi_status;
2021 rval = QLA_FUNCTION_FAILED;
2023 for (retries = 3; retries; retries--) {
2024 memset(rlc, 0, sizeof(rpt_lun_cmd_rsp_t));
2025 rlc->p.cmd.entry_type = COMMAND_A64_TYPE;
2026 rlc->p.cmd.entry_count = 1;
2027 SET_TARGET_ID(ha, rlc->p.cmd.target, fcport->loop_id);
2028 rlc->p.cmd.control_flags =
2029 __constant_cpu_to_le16(CF_READ | CF_SIMPLE_TAG);
2030 rlc->p.cmd.scsi_cdb[0] = REPORT_LUNS;
2031 rlc->p.cmd.scsi_cdb[8] = MSB(sizeof(rpt_lun_lst_t));
2032 rlc->p.cmd.scsi_cdb[9] = LSB(sizeof(rpt_lun_lst_t));
2033 rlc->p.cmd.dseg_count = __constant_cpu_to_le16(1);
2034 rlc->p.cmd.timeout = __constant_cpu_to_le16(10);
2035 rlc->p.cmd.byte_count =
2036 __constant_cpu_to_le32(sizeof(rpt_lun_lst_t));
2037 rlc->p.cmd.dseg_0_address[0] = cpu_to_le32(
2038 LSD(rlc_dma + sizeof(sts_entry_t)));
2039 rlc->p.cmd.dseg_0_address[1] = cpu_to_le32(
2040 MSD(rlc_dma + sizeof(sts_entry_t)));
2041 rlc->p.cmd.dseg_0_length =
2042 __constant_cpu_to_le32(sizeof(rpt_lun_lst_t));
2044 rval = qla2x00_issue_iocb(ha, rlc, rlc_dma,
2045 sizeof(rpt_lun_cmd_rsp_t));
2047 comp_status = le16_to_cpu(rlc->p.rsp.comp_status);
2048 scsi_status = le16_to_cpu(rlc->p.rsp.scsi_status);
2050 if (rval != QLA_SUCCESS || comp_status != CS_COMPLETE ||
2051 scsi_status & SS_CHECK_CONDITION) {
2053 /* Device underrun, treat as OK. */
2054 if (rval == QLA_SUCCESS &&
2055 comp_status == CS_DATA_UNDERRUN &&
2056 scsi_status & SS_RESIDUAL_UNDER) {
2062 DEBUG(printk("scsi(%ld): RLC failed to issue iocb! "
2063 "fcport=[%04x/%p] rval=%x cs=%x ss=%x\n",
2064 ha->host_no, fcport->loop_id, fcport, rval,
2065 comp_status, scsi_status));
2067 rval = QLA_FUNCTION_FAILED;
2068 if (scsi_status & SS_CHECK_CONDITION) {
2069 DEBUG2(printk("scsi(%ld): RLC "
2070 "SS_CHECK_CONDITION Sense Data "
2071 "%02x %02x %02x %02x %02x %02x %02x %02x\n",
2073 rlc->p.rsp.req_sense_data[0],
2074 rlc->p.rsp.req_sense_data[1],
2075 rlc->p.rsp.req_sense_data[2],
2076 rlc->p.rsp.req_sense_data[3],
2077 rlc->p.rsp.req_sense_data[4],
2078 rlc->p.rsp.req_sense_data[5],
2079 rlc->p.rsp.req_sense_data[6],
2080 rlc->p.rsp.req_sense_data[7]));
2081 if (rlc->p.rsp.req_sense_data[2] ==
2083 fcport->flags &= ~(FCF_RLC_SUPPORT);
2097 * Configures LUN into fcport LUN list.
2100 * fcport: FC port structure pointer.
2107 qla2x00_cfg_lun(scsi_qla_host_t *ha, fc_port_t *fcport, uint16_t lun,
2108 inq_cmd_rsp_t *inq, dma_addr_t inq_dma)
2112 /* Bypass LUNs that failed. */
2113 if (qla2x00_inquiry(ha, fcport, lun, inq, inq_dma) != QLA_SUCCESS) {
2114 DEBUG2(printk("scsi(%ld): Failed inquiry - loop id=0x%04x "
2115 "lun=%d\n", ha->host_no, fcport->loop_id, lun));
2120 switch (inq->inq[0]) {
2122 case TYPE_PROCESSOR:
2127 case TYPE_MEDIUM_CHANGER:
2128 case TYPE_ENCLOSURE:
2133 fcport->flags |= FCF_TAPE_PRESENT;
2136 DEBUG2(printk("scsi(%ld): Unsupported lun type -- "
2137 "loop id=0x%04x lun=%d type=%x\n",
2138 ha->host_no, fcport->loop_id, lun, inq->inq[0]));
2142 fcport->device_type = inq->inq[0];
2143 fclun = qla2x00_add_lun(fcport, lun);
2145 if (fclun != NULL) {
2146 atomic_set(&fcport->state, FCS_ONLINE);
2154 * Adds LUN to database
2157 * fcport: FC port structure pointer.
2164 qla2x00_add_lun(fc_port_t *fcport, uint16_t lun)
2169 if (fcport == NULL) {
2170 DEBUG(printk("scsi: Unable to add lun to NULL port\n"));
2174 /* Allocate LUN if not already allocated. */
2176 list_for_each_entry(fclun, &fcport->fcluns, list) {
2177 if (fclun->lun == lun) {
2185 fclun = kmalloc(sizeof(fc_lun_t), GFP_ATOMIC);
2186 if (fclun == NULL) {
2188 "%s(): Memory Allocation failed - FCLUN\n",
2193 /* Setup LUN structure. */
2194 memset(fclun, 0, sizeof(fc_lun_t));
2196 fclun->fcport = fcport;
2197 fclun->o_fcport = fcport;
2198 fclun->device_type = fcport->device_type;
2199 atomic_set(&fcport->state, FCS_UNCONFIGURED);
2201 list_add_tail(&fclun->list, &fcport->fcluns);
2208 * Issue SCSI inquiry command.
2211 * ha = adapter block pointer.
2212 * fcport = FC port structure pointer.
2222 qla2x00_inquiry(scsi_qla_host_t *ha,
2223 fc_port_t *fcport, uint16_t lun, inq_cmd_rsp_t *inq, dma_addr_t inq_dma)
2227 uint16_t comp_status;
2228 uint16_t scsi_status;
2230 rval = QLA_FUNCTION_FAILED;
2232 for (retries = 3; retries; retries--) {
2233 memset(inq, 0, sizeof(inq_cmd_rsp_t));
2234 inq->p.cmd.entry_type = COMMAND_A64_TYPE;
2235 inq->p.cmd.entry_count = 1;
2236 inq->p.cmd.lun = cpu_to_le16(lun);
2237 SET_TARGET_ID(ha, inq->p.cmd.target, fcport->loop_id);
2238 inq->p.cmd.control_flags =
2239 __constant_cpu_to_le16(CF_READ | CF_SIMPLE_TAG);
2240 inq->p.cmd.scsi_cdb[0] = INQUIRY;
2241 inq->p.cmd.scsi_cdb[4] = INQ_DATA_SIZE;
2242 inq->p.cmd.dseg_count = __constant_cpu_to_le16(1);
2243 inq->p.cmd.timeout = __constant_cpu_to_le16(10);
2244 inq->p.cmd.byte_count =
2245 __constant_cpu_to_le32(INQ_DATA_SIZE);
2246 inq->p.cmd.dseg_0_address[0] = cpu_to_le32(
2247 LSD(inq_dma + sizeof(sts_entry_t)));
2248 inq->p.cmd.dseg_0_address[1] = cpu_to_le32(
2249 MSD(inq_dma + sizeof(sts_entry_t)));
2250 inq->p.cmd.dseg_0_length =
2251 __constant_cpu_to_le32(INQ_DATA_SIZE);
2253 DEBUG5(printk("scsi(%ld): Lun Inquiry - fcport=[%04x/%p],"
2255 ha->host_no, fcport->loop_id, fcport, lun));
2257 rval = qla2x00_issue_iocb(ha, inq, inq_dma,
2258 sizeof(inq_cmd_rsp_t));
2260 comp_status = le16_to_cpu(inq->p.rsp.comp_status);
2261 scsi_status = le16_to_cpu(inq->p.rsp.scsi_status);
2263 DEBUG5(printk("scsi(%ld): lun (%d) inquiry - "
2264 "inq[0]= 0x%x, comp status 0x%x, scsi status 0x%x, "
2266 ha->host_no, lun, inq->inq[0], comp_status, scsi_status,
2269 if (rval != QLA_SUCCESS || comp_status != CS_COMPLETE ||
2270 scsi_status & SS_CHECK_CONDITION) {
2272 DEBUG(printk("scsi(%ld): INQ failed to issue iocb! "
2273 "fcport=[%04x/%p] rval=%x cs=%x ss=%x\n",
2274 ha->host_no, fcport->loop_id, fcport, rval,
2275 comp_status, scsi_status));
2277 if (rval == QLA_SUCCESS)
2278 rval = QLA_FUNCTION_FAILED;
2280 if (scsi_status & SS_CHECK_CONDITION) {
2281 DEBUG2(printk("scsi(%ld): INQ "
2282 "SS_CHECK_CONDITION Sense Data "
2283 "%02x %02x %02x %02x %02x %02x %02x %02x\n",
2285 inq->p.rsp.req_sense_data[0],
2286 inq->p.rsp.req_sense_data[1],
2287 inq->p.rsp.req_sense_data[2],
2288 inq->p.rsp.req_sense_data[3],
2289 inq->p.rsp.req_sense_data[4],
2290 inq->p.rsp.req_sense_data[5],
2291 inq->p.rsp.req_sense_data[6],
2292 inq->p.rsp.req_sense_data[7]));
2295 /* Device underrun drop LUN. */
2296 if (comp_status == CS_DATA_UNDERRUN &&
2297 scsi_status & SS_RESIDUAL_UNDER) {
2310 * qla2x00_configure_fabric
2311 * Setup SNS devices with loop ID's.
2314 * ha = adapter block pointer.
2321 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2324 fc_port_t *fcport, *fcptemp;
2325 uint16_t next_loopid;
2326 uint16_t mb[MAILBOX_REGISTER_COUNT];
2327 LIST_HEAD(new_fcports);
2329 /* If FL port exists, then SNS is present */
2330 rval = qla2x00_get_port_name(ha, SNS_FL_PORT, NULL, 0);
2331 if (rval != QLA_SUCCESS) {
2332 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2333 "Port\n", ha->host_no));
2335 ha->device_flags &= ~SWITCH_FOUND;
2336 return (QLA_SUCCESS);
2339 /* Mark devices that need re-synchronization. */
2340 rval2 = qla2x00_device_resync(ha);
2341 if (rval2 == QLA_RSCNS_HANDLED) {
2342 /* No, point doing the scan, just continue. */
2343 return (QLA_SUCCESS);
2346 /* Ensure we are logged into the SNS. */
2347 qla2x00_login_fabric(ha, SIMPLE_NAME_SERVER, 0xff, 0xff, 0xfc,
2349 if (mb[0] != MBS_COMMAND_COMPLETE) {
2350 qla_printk(KERN_INFO, ha,
2351 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2352 "mb[2]=%x mb[6]=%x mb[7]=%x\n", SIMPLE_NAME_SERVER,
2353 mb[0], mb[1], mb[2], mb[6], mb[7]);
2354 return (QLA_FUNCTION_FAILED);
2357 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2358 if (qla2x00_rft_id(ha)) {
2360 DEBUG2(printk("scsi(%ld): Register FC-4 "
2361 "TYPE failed.\n", ha->host_no));
2363 if (qla2x00_rff_id(ha)) {
2365 DEBUG2(printk("scsi(%ld): Register FC-4 "
2366 "Features failed.\n", ha->host_no));
2368 if (qla2x00_rnn_id(ha)) {
2370 DEBUG2(printk("scsi(%ld): Register Node Name "
2371 "failed.\n", ha->host_no));
2372 } else if (qla2x00_rsnn_nn(ha)) {
2374 DEBUG2(printk("scsi(%ld): Register Symbolic "
2375 "Node Name failed.\n", ha->host_no));
2379 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2380 if (rval != QLA_SUCCESS)
2384 * Logout all previous fabric devices marked lost, except
2387 list_for_each_entry(fcport, &ha->fcports, list) {
2388 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2391 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2394 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2395 qla2x00_mark_device_lost(ha, fcport,
2396 ql2xplogiabsentdevice);
2397 if (fcport->loop_id != FC_NO_LOOP_ID &&
2398 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2399 fcport->port_type != FCT_INITIATOR &&
2400 fcport->port_type != FCT_BROADCAST) {
2402 qla2x00_fabric_logout(ha,
2404 fcport->loop_id = FC_NO_LOOP_ID;
2409 /* Starting free loop ID. */
2410 next_loopid = ha->min_external_loopid;
2413 * Scan through our port list and login entries that need to be
2416 list_for_each_entry(fcport, &ha->fcports, list) {
2417 if (atomic_read(&ha->loop_down_timer) ||
2418 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2421 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2422 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2425 if (fcport->loop_id == FC_NO_LOOP_ID) {
2426 fcport->loop_id = next_loopid;
2427 rval = qla2x00_find_new_loop_id(ha, fcport);
2428 if (rval != QLA_SUCCESS) {
2429 /* Ran out of IDs to use */
2434 /* Login and update database */
2435 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2438 /* Exit if out of loop IDs. */
2439 if (rval != QLA_SUCCESS) {
2444 * Login and add the new devices to our port list.
2446 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2447 if (atomic_read(&ha->loop_down_timer) ||
2448 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2451 /* Find a new loop ID to use. */
2452 fcport->loop_id = next_loopid;
2453 rval = qla2x00_find_new_loop_id(ha, fcport);
2454 if (rval != QLA_SUCCESS) {
2455 /* Ran out of IDs to use */
2459 /* Login and update database */
2460 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2462 /* Remove device from the new list and add it to DB */
2463 list_del(&fcport->list);
2464 list_add_tail(&fcport->list, &ha->fcports);
2468 /* Free all new device structures not processed. */
2469 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2470 list_del(&fcport->list);
2475 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2476 "rval=%d\n", ha->host_no, rval));
2484 * qla2x00_find_all_fabric_devs
2487 * ha = adapter block pointer.
2488 * dev = database device entry pointer.
2498 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2502 fc_port_t *fcport, *new_fcport;
2507 int first_dev, last_dev;
2508 port_id_t wrap, nxt_d_id;
2512 /* Try GID_PT to get device list, else GAN. */
2513 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2516 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2517 "on GA_NXT\n", ha->host_no));
2519 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2520 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2523 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2526 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2533 /* Allocate temporary fcport for any new fcports discovered. */
2534 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2535 if (new_fcport == NULL) {
2538 return (QLA_MEMORY_ALLOC_FAILED);
2540 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2542 /* Set start port ID scan at adapter ID. */
2546 /* Starting free loop ID. */
2547 loop_id = ha->min_external_loopid;
2549 for (; loop_id <= ha->last_loop_id; loop_id++) {
2550 if (RESERVED_LOOP_ID(loop_id))
2553 if (atomic_read(&ha->loop_down_timer) ||
2554 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2559 wrap.b24 = new_fcport->d_id.b24;
2561 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2562 memcpy(new_fcport->node_name,
2563 swl[swl_idx].node_name, WWN_SIZE);
2564 memcpy(new_fcport->port_name,
2565 swl[swl_idx].port_name, WWN_SIZE);
2567 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2573 /* Send GA_NXT to the switch */
2574 rval = qla2x00_ga_nxt(ha, new_fcport);
2575 if (rval != QLA_SUCCESS) {
2580 /* If wrap on switch device list, exit. */
2582 wrap.b24 = new_fcport->d_id.b24;
2584 } else if (new_fcport->d_id.b24 == wrap.b24) {
2585 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2586 ha->host_no, new_fcport->d_id.b.domain,
2587 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2591 /* Bypass if host adapter. */
2592 if (new_fcport->d_id.b24 == ha->d_id.b24)
2595 /* Bypass reserved domain fields. */
2596 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2599 /* Bypass if same domain and area of adapter. */
2600 if ((new_fcport->d_id.b24 & 0xffff00) ==
2601 (ha->d_id.b24 & 0xffff00))
2604 /* Locate matching device in database. */
2606 list_for_each_entry(fcport, &ha->fcports, list) {
2607 if (memcmp(new_fcport->port_name, fcport->port_name,
2614 * If device was not a fabric device before.
2616 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2617 fcport->d_id.b24 = new_fcport->d_id.b24;
2618 fcport->loop_id = FC_NO_LOOP_ID;
2619 fcport->flags |= (FCF_FABRIC_DEVICE |
2621 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2626 * If address the same and state FCS_ONLINE, nothing
2629 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2630 atomic_read(&fcport->state) == FCS_ONLINE) {
2635 * Port ID changed or device was marked to be updated;
2636 * Log it out if still logged in and mark it for
2639 fcport->d_id.b24 = new_fcport->d_id.b24;
2640 fcport->flags |= FCF_LOGIN_NEEDED;
2641 if (fcport->loop_id != FC_NO_LOOP_ID &&
2642 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2643 fcport->port_type != FCT_INITIATOR &&
2644 fcport->port_type != FCT_BROADCAST) {
2645 qla2x00_fabric_logout(ha, fcport->loop_id);
2646 fcport->loop_id = FC_NO_LOOP_ID;
2655 /* If device was not in our fcports list, then add it. */
2656 list_add_tail(&new_fcport->list, new_fcports);
2658 /* Allocate a new replacement fcport. */
2659 nxt_d_id.b24 = new_fcport->d_id.b24;
2660 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2661 if (new_fcport == NULL) {
2664 return (QLA_MEMORY_ALLOC_FAILED);
2666 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2667 new_fcport->d_id.b24 = nxt_d_id.b24;
2676 if (!list_empty(new_fcports))
2677 ha->device_flags |= DFLG_FABRIC_DEVICES;
2683 * qla2x00_find_new_loop_id
2684 * Scan through our port list and find a new usable loop ID.
2687 * ha: adapter state pointer.
2688 * dev: port structure pointer.
2691 * qla2x00 local function return status code.
2697 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2702 uint16_t first_loop_id;
2706 /* Save starting loop ID. */
2707 first_loop_id = dev->loop_id;
2710 /* Skip loop ID if already used by adapter. */
2711 if (dev->loop_id == ha->loop_id) {
2715 /* Skip reserved loop IDs. */
2716 while (RESERVED_LOOP_ID(dev->loop_id)) {
2720 /* Reset loop ID if passed the end. */
2721 if (dev->loop_id > ha->last_loop_id) {
2722 /* first loop ID. */
2723 dev->loop_id = ha->min_external_loopid;
2726 /* Check for loop ID being already in use. */
2729 list_for_each_entry(fcport, &ha->fcports, list) {
2730 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2731 /* ID possibly in use */
2737 /* If not in use then it is free to use. */
2742 /* ID in use. Try next value. */
2745 /* If wrap around. No free ID to use. */
2746 if (dev->loop_id == first_loop_id) {
2747 dev->loop_id = FC_NO_LOOP_ID;
2748 rval = QLA_FUNCTION_FAILED;
2757 * qla2x00_device_resync
2758 * Marks devices in the database that needs resynchronization.
2761 * ha = adapter block pointer.
2767 qla2x00_device_resync(scsi_qla_host_t *ha)
2773 uint32_t rscn_entry;
2774 uint8_t rscn_out_iter;
2778 rval = QLA_RSCNS_HANDLED;
2780 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2781 ha->flags.rscn_queue_overflow) {
2783 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2784 format = MSB(MSW(rscn_entry));
2785 d_id.b.domain = LSB(MSW(rscn_entry));
2786 d_id.b.area = MSB(LSW(rscn_entry));
2787 d_id.b.al_pa = LSB(LSW(rscn_entry));
2789 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2790 "[%02x/%02x%02x%02x].\n",
2791 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2792 d_id.b.area, d_id.b.al_pa));
2795 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2796 ha->rscn_out_ptr = 0;
2798 /* Skip duplicate entries. */
2799 for (rscn_out_iter = ha->rscn_out_ptr;
2800 !ha->flags.rscn_queue_overflow &&
2801 rscn_out_iter != ha->rscn_in_ptr;
2802 rscn_out_iter = (rscn_out_iter ==
2803 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2805 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2808 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2809 "entry found at [%d].\n", ha->host_no,
2812 ha->rscn_out_ptr = rscn_out_iter;
2815 /* Queue overflow, set switch default case. */
2816 if (ha->flags.rscn_queue_overflow) {
2817 DEBUG(printk("scsi(%ld): device_resync: rscn "
2818 "overflow.\n", ha->host_no));
2821 ha->flags.rscn_queue_overflow = 0;
2826 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) &&
2827 !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
2828 ha->flags.init_done) {
2829 /* Handle port RSCN via asyncronous IOCBs */
2830 rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
2832 if (rval2 == QLA_SUCCESS)
2846 ha->rscn_out_ptr = ha->rscn_in_ptr;
2852 /* Abort any outstanding IO descriptors. */
2853 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2854 qla2x00_cancel_io_descriptors(ha);
2856 list_for_each_entry(fcport, &ha->fcports, list) {
2857 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2858 (fcport->d_id.b24 & mask) != d_id.b24 ||
2859 fcport->port_type == FCT_BROADCAST)
2862 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2864 fcport->port_type != FCT_INITIATOR) {
2865 atomic_set(&fcport->state,
2869 fcport->flags &= ~FCF_FARP_DONE;
2876 * qla2x00_fabric_dev_login
2877 * Login fabric target device and update FC port database.
2880 * ha: adapter state pointer.
2881 * fcport: port structure list pointer.
2882 * next_loopid: contains value of a new loop ID that can be used
2883 * by the next login attempt.
2886 * qla2x00 local function return status code.
2892 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2893 uint16_t *next_loopid)
2901 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2902 if (rval == QLA_SUCCESS) {
2903 rval = qla2x00_get_port_database(ha, fcport, BIT_1 | BIT_0);
2904 if (rval != QLA_SUCCESS) {
2905 qla2x00_fabric_logout(ha, fcport->loop_id);
2907 qla2x00_update_fcport(ha, fcport);
2915 * qla2x00_fabric_login
2916 * Issue fabric login command.
2919 * ha = adapter block pointer.
2920 * device = pointer to FC device type structure.
2923 * 0 - Login successfully
2925 * 2 - Initiator device
2929 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2930 uint16_t *next_loopid)
2934 uint16_t tmp_loopid;
2935 uint16_t mb[MAILBOX_REGISTER_COUNT];
2941 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2942 "for port %02x%02x%02x.\n",
2943 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2944 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2946 /* Login fcport on switch. */
2947 qla2x00_login_fabric(ha, fcport->loop_id,
2948 fcport->d_id.b.domain, fcport->d_id.b.area,
2949 fcport->d_id.b.al_pa, mb, BIT_0);
2950 if (mb[0] == MBS_PORT_ID_USED) {
2952 * Device has another loop ID. The firmware team
2953 * recommends us to perform an implicit login with the
2954 * specified ID again. The ID we just used is save here
2955 * so we return with an ID that can be tried by the
2959 tmp_loopid = fcport->loop_id;
2960 fcport->loop_id = mb[1];
2962 DEBUG(printk("Fabric Login: port in use - next "
2963 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2964 fcport->loop_id, fcport->d_id.b.domain,
2965 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2967 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2972 /* A retry occurred before. */
2973 *next_loopid = tmp_loopid;
2976 * No retry occurred before. Just increment the
2977 * ID value for next login.
2979 *next_loopid = (fcport->loop_id + 1);
2982 if (mb[1] & BIT_0) {
2983 fcport->port_type = FCT_INITIATOR;
2985 fcport->port_type = FCT_TARGET;
2986 if (mb[1] & BIT_1) {
2987 fcport->flags |= FCF_TAPE_PRESENT;
2993 } else if (mb[0] == MBS_LOOP_ID_USED) {
2995 * Loop ID already used, try next loop ID.
2998 rval = qla2x00_find_new_loop_id(ha, fcport);
2999 if (rval != QLA_SUCCESS) {
3000 /* Ran out of loop IDs to use */
3003 } else if (mb[0] == MBS_COMMAND_ERROR) {
3005 * Firmware possibly timed out during login. If NO
3006 * retries are left to do then the device is declared
3009 *next_loopid = fcport->loop_id;
3010 qla2x00_fabric_logout(ha, fcport->loop_id);
3011 fcport->loop_id = FC_NO_LOOP_ID;
3017 * unrecoverable / not handled error
3019 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3020 "loop_id=%x jiffies=%lx.\n",
3021 __func__, ha->host_no, mb[0],
3022 fcport->d_id.b.domain, fcport->d_id.b.area,
3023 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3025 *next_loopid = fcport->loop_id;
3026 qla2x00_fabric_logout(ha, fcport->loop_id);
3027 fcport->loop_id = FC_NO_LOOP_ID;
3028 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
3039 * qla2x00_local_device_login
3040 * Issue local device login command.
3043 * ha = adapter block pointer.
3044 * loop_id = loop id of device to login to.
3046 * Returns (Where's the #define!!!!):
3047 * 0 - Login successfully
3052 qla2x00_local_device_login(scsi_qla_host_t *ha, uint16_t loop_id)
3055 uint16_t mb[MAILBOX_REGISTER_COUNT];
3057 memset(mb, 0, sizeof(mb));
3058 rval = qla2x00_login_local_device(ha, loop_id, mb, BIT_0);
3059 if (rval == QLA_SUCCESS) {
3060 /* Interrogate mailbox registers for any errors */
3061 if (mb[0] == MBS_COMMAND_ERROR)
3063 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3064 /* device not in PCB table */
3072 * qla2x00_loop_resync
3073 * Resync with fibre channel devices.
3076 * ha = adapter block pointer.
3082 qla2x00_loop_resync(scsi_qla_host_t *ha)
3088 atomic_set(&ha->loop_state, LOOP_UPDATE);
3089 qla2x00_stats.loop_resync++;
3090 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3091 if (ha->flags.online) {
3092 if (!(rval = qla2x00_fw_ready(ha))) {
3095 atomic_set(&ha->loop_state, LOOP_UPDATE);
3098 * Issue marker command only when we are going
3099 * to start the I/O .
3101 ha->marker_needed = 1;
3103 /* Remap devices on Loop. */
3104 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3106 qla2x00_configure_loop(ha);
3108 } while (!atomic_read(&ha->loop_down_timer) &&
3109 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3110 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3112 qla2x00_restart_queues(ha,TRUE);
3115 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3116 return (QLA_FUNCTION_FAILED);
3120 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3127 * qla2x00_restart_queues
3128 * Restart device queues.
3131 * ha = adapter block pointer.
3134 * Kernel/Interrupt context.
3137 qla2x00_restart_queues(scsi_qla_host_t *ha, uint8_t flush)
3140 int retry_q_cnt = 0;
3141 int pending_q_cnt = 0;
3142 struct list_head *list, *temp;
3143 unsigned long flags = 0;
3145 clear_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
3147 /* start pending queue */
3148 pending_q_cnt = ha->qthreads;
3150 spin_lock_irqsave(&ha->list_lock,flags);
3151 list_for_each_safe(list, temp, &ha->pending_queue) {
3152 sp = list_entry(list, srb_t, list);
3154 * When time expire return request back to OS as BUSY
3156 __del_from_pending_queue(ha, sp);
3157 sp->cmd->result = DID_BUS_BUSY << 16;
3158 sp->cmd->host_scribble = (unsigned char *)NULL;
3159 __add_to_done_queue(ha, sp);
3161 spin_unlock_irqrestore(&ha->list_lock, flags);
3163 if (!list_empty(&ha->pending_queue))
3168 * Clear out our retry queue
3171 spin_lock_irqsave(&ha->list_lock, flags);
3172 retry_q_cnt = ha->retry_q_cnt;
3173 list_for_each_safe(list, temp, &ha->retry_queue) {
3174 sp = list_entry(list, srb_t, list);
3175 /* when time expire return request back to OS as BUSY */
3176 __del_from_retry_queue(ha, sp);
3177 sp->cmd->result = DID_BUS_BUSY << 16;
3178 sp->cmd->host_scribble = (unsigned char *)NULL;
3179 __add_to_done_queue(ha, sp);
3181 spin_unlock_irqrestore(&ha->list_lock, flags);
3183 DEBUG2(printk("%s(%ld): callback %d commands.\n",
3189 DEBUG2(printk("%s(%ld): active=%ld, retry=%d, pending=%d, "
3190 "done=%ld, scsi retry=%d commands.\n",
3197 ha->scsi_retry_q_cnt);)
3199 if (!list_empty(&ha->done_queue))
3204 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
3210 list_for_each_entry(fcport, &ha->fcports, list) {
3211 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
3214 qla2x00_update_fcport(ha, fcport);
3215 fcport->flags &= ~FCF_RESCAN_NEEDED;
3219 qla2x00_probe_for_all_luns(ha);
3221 /* Update OS target and lun structures if necessary. */
3223 qla2x00_config_os(ha);
3230 * Setup OS target and LUN structures.
3233 * ha = adapter state pointer.
3239 qla2x00_config_os(scsi_qla_host_t *ha)
3247 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
3248 if ((tq = TGT_Q(ha, tgt)) == NULL)
3251 clear_bit(TQF_ONLINE, &tq->flags);
3254 list_for_each_entry(fcport, &ha->fcports, list) {
3255 if (atomic_read(&fcport->state) != FCS_ONLINE ||
3256 fcport->port_type == FCT_INITIATOR ||
3257 fcport->port_type == FCT_BROADCAST) {
3258 fcport->os_target_id = MAX_TARGETS;
3262 if (fcport->flags & FCF_FO_MASKED) {
3266 /* Bind FC port to OS target number. */
3267 if (qla2x00_fcport_bind(ha, fcport) == MAX_TARGETS) {
3271 /* Bind FC LUN to OS LUN number. */
3272 list_for_each_entry(fclun, &fcport->fcluns, list) {
3273 qla2x00_fclun_bind(ha, fcport, fclun);
3279 * qla2x00_fcport_bind
3280 * Locates a target number for FC port.
3283 * ha = adapter state pointer.
3284 * fcport = FC port structure pointer.
3293 qla2x00_fcport_bind(scsi_qla_host_t *ha, fc_port_t *fcport)
3298 /* Check for persistent binding. */
3299 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
3300 if ((tq = TGT_Q(ha, tgt)) == NULL)
3303 if (ha->binding_type == BIND_BY_PORT_ID &&
3304 fcport->d_id.b24 == tq->d_id.b24) {
3305 memcpy(tq->node_name, fcport->node_name, WWN_SIZE);
3306 memcpy(tq->port_name, fcport->port_name, WWN_SIZE);
3310 if (memcmp(fcport->port_name, tq->port_name, WWN_SIZE) == 0) {
3311 /* In case of persistent binding, update the WWNN */
3312 memcpy(tq->node_name, fcport->node_name, WWN_SIZE);
3317 /* TODO: honor the ConfigRequired flag */
3318 if (tgt == MAX_TARGETS) {
3319 /* Check if targetID 0 available. */
3322 if (TGT_Q(ha, tgt) != NULL) {
3323 /* Locate first free target for device. */
3324 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
3325 if (TGT_Q(ha, tgt) == NULL) {
3330 if (tgt != MAX_TARGETS) {
3331 if ((tq = qla2x00_tgt_alloc(ha, tgt)) != NULL) {
3332 memcpy(tq->node_name, fcport->node_name,
3334 memcpy(tq->port_name, fcport->port_name,
3336 tq->d_id.b24 = fcport->d_id.b24;
3341 /* Reset target numbers incase it changed. */
3342 fcport->os_target_id = tgt;
3343 if (tgt != MAX_TARGETS && tq != NULL) {
3344 DEBUG2(printk("scsi(%ld): Assigning target ID=%02d @ %p to "
3345 "loop id=0x%04x, port state=0x%x, port down retry=%d\n",
3346 ha->host_no, tgt, tq, fcport->loop_id,
3347 atomic_read(&fcport->state),
3348 atomic_read(&fcport->port_down_timer)));
3350 fcport->tgt_queue = tq;
3351 fcport->flags |= FCF_PERSISTENT_BOUND;
3352 tq->fcport = fcport;
3353 set_bit(TQF_ONLINE, &tq->flags);
3354 tq->port_down_retry_count = ha->port_down_retry_count;
3357 qla2x00_get_lun_mask_from_config(ha, fcport, tgt, 0);
3361 if (tgt == MAX_TARGETS) {
3362 qla_printk(KERN_WARNING, ha,
3363 "Unable to bind fcport, loop_id=%x\n", fcport->loop_id);
3370 * qla2x00_fclun_bind
3371 * Binds all FC device LUNS to OS LUNS.
3374 * ha: adapter state pointer.
3375 * fcport: FC port structure pointer.
3384 qla2x00_fclun_bind(scsi_qla_host_t *ha, fc_port_t *fcport, fc_lun_t *fclun)
3390 tgt = fcport->os_target_id;
3394 if (lun >= MAX_LUNS) {
3395 DEBUG2(printk("scsi(%ld): Unable to bind lun, invalid "
3396 "lun=(%x).\n", ha->host_no, lun));
3400 /* Always alloc LUN 0 so kernel will scan past LUN 0. */
3401 if (lun != 0 && (EXT_IS_LUN_BIT_SET(&(fcport->lun_mask), lun))) {
3405 if ((lq = qla2x00_lun_alloc(ha, tgt, lun)) == NULL) {
3406 qla_printk(KERN_WARNING, ha,
3407 "Unable to bind fclun, loop_id=%x lun=%x\n",
3408 fcport->loop_id, lun);
3419 * Allocate and pre-initialize target queue.
3422 * ha = adapter block pointer.
3423 * t = SCSI target number.
3432 qla2x00_tgt_alloc(scsi_qla_host_t *ha, uint16_t tgt)
3437 * If SCSI addressing OK, allocate TGT queue and lock.
3439 if (tgt >= MAX_TARGETS) {
3440 DEBUG2(printk("scsi(%ld): Unable to allocate target, invalid "
3441 "target number %d.\n", ha->host_no, tgt));
3445 tq = TGT_Q(ha, tgt);
3447 tq = kmalloc(sizeof(os_tgt_t), GFP_ATOMIC);
3449 DEBUG2(printk("scsi(%ld): Alloc Target %d @ %p\n",
3450 ha->host_no, tgt, tq));
3452 memset(tq, 0, sizeof(os_tgt_t));
3455 TGT_Q(ha, tgt) = tq;
3459 tq->port_down_retry_count = ha->port_down_retry_count;
3461 qla_printk(KERN_WARNING, ha,
3462 "Unable to allocate target.\n");
3471 * Frees target and LUN queues.
3474 * ha = adapter block pointer.
3475 * t = SCSI target number.
3481 qla2x00_tgt_free(scsi_qla_host_t *ha, uint16_t tgt)
3487 * If SCSI addressing OK, allocate TGT queue and lock.
3489 if (tgt >= MAX_TARGETS) {
3490 DEBUG2(printk("scsi(%ld): Unable to de-allocate target, "
3491 "invalid target number %d.\n", ha->host_no, tgt));
3496 tq = TGT_Q(ha, tgt);
3498 TGT_Q(ha, tgt) = NULL;
3500 /* Free LUN structures. */
3501 for (lun = 0; lun < MAX_LUNS; lun++)
3502 qla2x00_lun_free(ha, tgt, lun);
3512 * Allocate and initialize LUN queue.
3515 * ha = adapter block pointer.
3516 * t = SCSI target number.
3526 qla2x00_lun_alloc(scsi_qla_host_t *ha, uint16_t tgt, uint16_t lun)
3531 * If SCSI addressing OK, allocate LUN queue.
3533 if (tgt >= MAX_TARGETS || lun >= MAX_LUNS || TGT_Q(ha, tgt) == NULL) {
3534 DEBUG2(printk("scsi(%ld): Unable to allocate lun, invalid "
3535 "parameter.\n", ha->host_no));
3540 lq = LUN_Q(ha, tgt, lun);
3542 lq = kmalloc(sizeof(os_lun_t), GFP_ATOMIC);
3544 DEBUG2(printk("scsi(%ld): Alloc Lun %d @ tgt %d.\n",
3545 ha->host_no, lun, tgt));
3547 memset(lq, 0, sizeof (os_lun_t));
3548 LUN_Q(ha, tgt, lun) = lq;
3551 * The following lun queue initialization code
3552 * must be duplicated in alloc_ioctl_mem function
3555 lq->q_state = LUN_STATE_READY;
3556 spin_lock_init(&lq->q_lock);
3561 qla_printk(KERN_WARNING, ha, "Unable to allocate lun.\n");
3572 * ha = adapter block pointer.
3573 * t = SCSI target number.
3579 qla2x00_lun_free(scsi_qla_host_t *ha, uint16_t tgt, uint16_t lun)
3584 * If SCSI addressing OK, allocate TGT queue and lock.
3586 if (tgt >= MAX_TARGETS || lun >= MAX_LUNS) {
3587 DEBUG2(printk("scsi(%ld): Unable to deallocate lun, invalid "
3588 "parameter.\n", ha->host_no));
3593 if (TGT_Q(ha, tgt) != NULL && (lq = LUN_Q(ha, tgt, lun)) != NULL) {
3594 LUN_Q(ha, tgt, lun) = NULL;
3604 * qla2x00_get_lun_mask_from_config
3605 * Get lun mask from the configuration parameters.
3606 * Bit order is little endian.
3609 * ha -- Host adapter
3610 * tgt -- target/device number
3611 * port -- pointer to port
3614 qla2x00_get_lun_mask_from_config(scsi_qla_host_t *ha,
3615 fc_port_t *fcport, uint16_t tgt, uint16_t dev_no)
3617 char propbuf[60]; /* size of search string */
3619 lun_bit_mask_t lun_mask, *mask_ptr = &lun_mask;
3621 /* Get "target-N-device-N-lun-mask" as a 256 bit lun_mask*/
3622 sprintf(propbuf, "scsi-qla%ld-tgt-%d-di-%d-lun-disabled",
3623 ha->instance, tgt, dev_no);
3625 rval = qla2x00_get_prop_xstr(ha, propbuf,
3626 (uint8_t *)&lun_mask, sizeof(lun_bit_mask_t));
3627 if (rval == sizeof(lun_bit_mask_t)) {
3628 memset(&fcport->lun_mask, 0, sizeof(lun_bit_mask_t));
3629 for (lun = 8 * sizeof(lun_bit_mask_t) - 1, bit = 0;
3630 lun >= 0; lun--, bit++) {
3631 if (EXT_IS_LUN_BIT_SET(mask_ptr, lun))
3632 EXT_SET_LUN_BIT((&fcport->lun_mask), bit);
3635 DEBUG3(printk("scsi(%ld): returning lun mask for fcport "
3636 "%02x%02x%02x%02x%02x%02x%02x%02x:\n",
3638 fcport->port_name[0], fcport->port_name[1],
3639 fcport->port_name[2], fcport->port_name[3],
3640 fcport->port_name[4], fcport->port_name[5],
3641 fcport->port_name[6], fcport->port_name[7]));
3642 DEBUG3(qla2x00_dump_buffer((uint8_t *)&fcport->lun_mask,
3643 sizeof(lun_bit_mask_t));)
3649 * qla2x00_bstr_to_hex
3650 * Convert hex byte string to number.
3653 * s = byte string pointer.
3654 * bp = byte pointer for number.
3655 * size = number of bytes.
3658 * Kernel/Interrupt context.
3661 qla2x00_bstr_to_hex(char *s, uint8_t *bp, int size)
3666 for (cnt = 0; *s != '\0' && cnt / 2 < size; cnt++) {
3667 if (*s >= 'A' && *s <= 'F') {
3668 n = (*s++ - 'A') + 10;
3669 } else if (*s >= 'a' && *s <= 'f') {
3670 n = (*s++ - 'a') + 10;
3671 } else if (*s >= '0' && *s <= '9') {
3684 /* fixme(dg) Need to swap data little endian */
3690 * qla2x00_get_prop_xstr
3691 * Get a string property value for the specified property name and
3692 * convert from the property string found in the configuration file,
3693 * which are ASCII characters representing nibbles, 2 characters represent
3694 * the hexdecimal value for a byte in the byte array.
3695 * The byte array is initialized to zero.
3696 * The resulting converted value is in big endian format (MSB at byte0).
3699 * ha = adapter state pointer.
3700 * propname = property name pointer.
3701 * propval = pointer where to store converted property val.
3702 * size = max or expected size of 'propval' array.
3705 * 0 = empty value string or invalid character in string
3706 * >0 = count of characters converted
3707 * -1 = property not found
3713 qla2x00_get_prop_xstr(scsi_qla_host_t *ha,
3714 char *propname, uint8_t *propval, int size)
3718 static char buf[LINESIZE];
3720 /* Get the requested property string */
3721 rval = qla2x00_find_propname(ha, propname, buf, ha->cmdline, size*2);
3722 DEBUG3(printk("%s(): Ret rval from find propname = %d\n",
3727 if (*propstr == '=')
3728 propstr++; /* ignore equal sign */
3730 if (rval == 0) { /* not found */
3734 rval = qla2x00_bstr_to_hex(propstr, (uint8_t *)propval, size);
3736 /* Invalid character in value string */
3737 qla_printk(KERN_INFO, ha,
3738 "%s(): %s Invalid hex string for property\n",
3741 qla_printk(KERN_INFO, ha,
3742 " Invalid string - %s\n",
3750 * qla2x00_find_propname
3751 * Get property in database.
3754 * ha = adapter structure pointer.
3755 * db = pointer to database
3756 * propstr = pointer to dest array for string
3757 * propname = name of property to search for.
3758 * siz = size of property
3762 * size = index of property
3768 qla2x00_find_propname(scsi_qla_host_t *ha,
3769 char *propname, char *propstr,
3774 /* find the specified string */
3776 /* find the property name */
3777 if ((cp = strstr(db,propname)) != NULL) {
3778 while ((*cp) && *cp != '=')
3781 strncpy(propstr, cp, siz+1);
3782 propstr[siz+1] = '\0';
3783 DEBUG(printk("qla2x00_find_propname: found "
3784 "property = {%s}\n",
3786 return (siz); /* match */
3796 * qla2x00_get_prop_16chars
3797 * Get an 8-byte property value for the specified property name by
3798 * converting from the property string found in the configuration file.
3799 * The resulting converted value is in big endian format (MSB at byte0).
3802 * ha = adapter state pointer.
3803 * propname = property name pointer.
3804 * propval = pointer to location for the converted property val.
3805 * db = pointer to database
3808 * 0 = value returned successfully.
3814 qla2x00_get_prop_16chars(scsi_qla_host_t *ha,
3815 char *propname, char *propval, char *db)
3824 uint8_t *retval = (uint8_t*)propval;
3825 uint8_t tmpval[8] = {0, 0, 0, 0, 0, 0, 0, 0};
3826 uint16_t max_byte_cnt = 8; /* 16 chars = 8 bytes */
3827 uint16_t max_strlen = 16;
3828 static char buf[LINESIZE];
3830 rval = qla2x00_find_propname(ha, propname, buf, db, max_strlen);
3833 if (*propstr == '=')
3834 propstr++; /* ignore equal sign */
3840 /* Convert string to numbers. */
3841 pchar = (uint8_t *)propstr;
3842 tmp_byte = (uint8_t *)tmpval;
3845 for (i = 0; i < max_strlen; i++) {
3847 * Check for invalid character, two at a time,
3848 * then convert them starting with first byte.
3851 if ((pchar[i] >= '0') && (pchar[i] <= '9')) {
3852 nval = pchar[i] - '0';
3853 } else if ((pchar[i] >= 'A') && (pchar[i] <= 'F')) {
3854 nval = pchar[i] - 'A' + 10;
3855 } else if ((pchar[i] >= 'a') && (pchar[i] <= 'f')) {
3856 nval = pchar[i] - 'a' + 10;
3858 /* invalid character */
3864 *tmp_byte = *tmp_byte | nval;
3867 *tmp_byte = *tmp_byte | nval << 4;
3872 /* Encountered invalid character. */
3876 /* Copy over the converted value. */
3883 *ret_byte++ = *tmp_byte++;
3886 /* big endian retval[0]; */
3891 * qla2x00_get_properties
3892 * Find all properties for the specified adapeter in
3896 * ha = adapter block pointer.
3897 * cmdline = pointer to command line string
3903 qla2x00_get_properties(scsi_qla_host_t *ha, char *cmdline)
3906 static char propbuf[LINESIZE];
3909 /* Adapter FC node names. */
3910 sprintf(propbuf, "scsi-qla%d-adapter-node", (int) ha->instance);
3911 rval = qla2x00_get_prop_16chars(ha, propbuf, fc_name, cmdline);
3912 if (rval == QLA_SUCCESS)
3913 memcpy(ha->init_cb->node_name, fc_name, WWN_SIZE);
3915 /* DG 04/07 check portname of adapter */
3916 sprintf(propbuf, "scsi-qla%d-adapter-port", (int)ha->instance);
3917 rval = qla2x00_get_prop_16chars(ha, propbuf, fc_name, cmdline);
3918 if (rval == QLA_SUCCESS &&
3919 memcmp(ha->init_cb->port_name, fc_name, WWN_SIZE)) {
3921 * Adapter port name is WWN, and cannot be changed.
3922 * Inform users of the mismatch, then just continue driver
3923 * loading using the original adapter port name in NVRAM.
3925 qla_printk(KERN_WARNING, ha,
3926 "Found mismatch in adapter port names.\n");
3927 qla_printk(KERN_INFO, ha,
3928 " qla%ld port name found in NVRAM -> "
3929 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
3931 ha->init_cb->port_name[0],
3932 ha->init_cb->port_name[1],
3933 ha->init_cb->port_name[2],
3934 ha->init_cb->port_name[3],
3935 ha->init_cb->port_name[4],
3936 ha->init_cb->port_name[5],
3937 ha->init_cb->port_name[6],
3938 ha->init_cb->port_name[7]);
3939 qla_printk(KERN_INFO, ha,
3940 " qla%ld port name found on command line -> "
3941 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
3943 fc_name[0], fc_name[1], fc_name[2], fc_name[3],
3944 fc_name[4], fc_name[5], fc_name[6], fc_name[7]);
3945 qla_printk(KERN_INFO, ha,
3946 " Using port name from NVRAM.\n");
3949 qla2x00_cfg_persistent_binding(ha);
3953 * qla2x00_cfg_persistent_binding
3954 * Get driver configuration file target persistent binding entries.
3957 * ha = adapter block pointer.
3963 qla2x00_cfg_persistent_binding(scsi_qla_host_t *ha)
3966 static char propbuf[LINESIZE];
3967 char *cmdline = ha->cmdline;
3971 uint8_t port_name[8];
3973 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
3974 if (ha->binding_type == BIND_BY_PORT_ID) {
3975 sprintf(propbuf, "scsi-qla%d-tgt-%d-di-0-pid",
3976 (int)ha->instance, tgt);
3977 rval = qla2x00_get_prop_xstr(ha,
3978 propbuf, portid, sizeof(portid));
3979 if (rval != sizeof(portid))
3982 memset(&d_id, 0, sizeof(port_id_t));
3983 d_id.r.d_id[0] = portid[2];
3984 d_id.r.d_id[1] = portid[1];
3985 d_id.r.d_id[2] = portid[0];
3987 sprintf(propbuf, "scsi-qla%d-tgt-%d-di-0-port",
3988 (int)ha->instance, tgt);
3989 rval = qla2x00_get_prop_16chars(ha,
3990 propbuf, port_name, cmdline);
3991 if (rval != QLA_SUCCESS)
3994 /* Fallthru since port_name already populated */
3998 * Create target context for device.
4000 if (ha->binding_type == BIND_BY_PORT_ID) {
4001 qla2x00_persistent_bind(ha, NULL, NULL, &d_id, tgt);
4003 qla2x00_persistent_bind(ha, NULL, port_name, NULL, tgt);
4009 * qla2x00_persistent_bind
4010 * Allocates target and fcport.
4013 * ha: adapter state pointer.
4014 * node_name: node name pointer.
4015 * port_name: port name pointer.
4016 * d_id: port ID pointer.
4017 * tgt: OS target number.
4020 * success = target queue pointer.
4027 qla2x00_persistent_bind(scsi_qla_host_t *ha, uint8_t *node_name,
4028 uint8_t *port_name, port_id_t *d_id, uint16_t tgt)
4034 * Check for duplicates.
4036 for (tgt2 = 0; tgt2 < MAX_TARGETS; tgt2++) {
4037 if ((tq = TGT_Q(ha, tgt2)) == NULL) {
4041 if (ha->binding_type == BIND_BY_PORT_ID) {
4042 if (tq->d_id.b24 != d_id->b24) {
4045 } else if (memcmp(tq->port_name, port_name, WWN_SIZE) != 0) {
4049 qla_printk(KERN_WARNING, ha,
4050 "Duplicate persistent bindings found for "
4051 "WWPN: %02x%02x%02x%02x%02x%02x%02x%02x.\n",
4052 port_name[0], port_name[1], port_name[2], port_name[3],
4053 port_name[4], port_name[5], port_name[6], port_name[7]);
4058 tq = qla2x00_tgt_alloc(ha, tgt);
4063 if (node_name != NULL) {
4064 memcpy(tq->node_name, node_name, WWN_SIZE);
4066 if (port_name != NULL) {
4067 memcpy(tq->port_name, port_name, WWN_SIZE);
4070 tq->d_id.b24 = d_id->b24;
4079 * Resets ISP and aborts all outstanding commands.
4082 * ha = adapter block pointer.
4088 qla2x00_abort_isp(scsi_qla_host_t *ha)
4090 unsigned long flags = 0;
4095 if (ha->flags.online) {
4096 ha->flags.online = FALSE;
4097 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
4098 qla2x00_stats.ispAbort++;
4099 ha->total_isp_aborts++; /* used by ioctl */
4100 ha->sns_retry_cnt = 0;
4102 qla_printk(KERN_INFO, ha,
4103 "Performing ISP error recovery - ha= %p.\n", ha);
4104 qla2x00_reset_chip(ha);
4106 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
4107 atomic_set(&ha->loop_state, LOOP_DOWN);
4108 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
4109 qla2x00_mark_all_devices_lost(ha);
4112 spin_lock_irqsave(&ha->hardware_lock, flags);
4113 /* Requeue all commands in outstanding command list. */
4114 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
4115 sp = ha->outstanding_cmds[cnt];
4117 ha->outstanding_cmds[cnt] = 0;
4120 sp->lun_queue->out_cnt--;
4124 * Set the cmd host_byte status depending on
4125 * whether the scsi_error_handler is
4128 if (ha->host->eh_active != EH_ACTIVE) {
4129 sp->cmd->result = DID_BUS_BUSY << 16;
4131 sp->cmd->result = DID_RESET << 16;
4133 sp->cmd->host_scribble = (unsigned char *)NULL;
4134 add_to_done_queue(ha, sp);
4138 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4140 qla2x00_nvram_config(ha);
4142 if (!qla2x00_restart_isp(ha)) {
4143 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
4145 if (!atomic_read(&ha->loop_down_timer)) {
4147 * Issue marker command only when we are going
4148 * to start the I/O .
4150 ha->marker_needed = 1;
4153 ha->flags.online = TRUE;
4155 /* Enable ISP interrupts. */
4156 qla2x00_enable_intrs(ha);
4158 /* v2.19.5b6 Return all commands */
4159 qla2x00_abort_queues(ha, TRUE);
4161 /* Restart queues that may have been stopped. */
4162 qla2x00_restart_queues(ha,TRUE);
4163 ha->isp_abort_cnt = 0;
4164 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
4165 } else { /* failed the ISP abort */
4166 ha->flags.online = TRUE;
4167 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
4168 if (ha->isp_abort_cnt == 0) {
4169 qla_printk(KERN_WARNING, ha,
4170 "ISP error recovery failed - "
4171 "board disabled\n");
4173 * The next call disables the board
4176 qla2x00_reset_adapter(ha);
4177 qla2x00_abort_queues(ha, FALSE);
4178 ha->flags.online = FALSE;
4179 clear_bit(ISP_ABORT_RETRY,
4182 } else { /* schedule another ISP abort */
4183 ha->isp_abort_cnt--;
4184 DEBUG(printk("qla%ld: ISP abort - "
4185 "retry remainning %d\n",
4186 ha->host_no, ha->isp_abort_cnt);)
4190 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
4191 DEBUG(printk("qla2x00(%ld): ISP error recovery "
4192 "- retrying (%d) more times\n",
4193 ha->host_no, ha->isp_abort_cnt);)
4194 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
4202 qla_printk(KERN_INFO, ha,
4203 "qla2x00_abort_isp: **** FAILED ****\n");
4205 DEBUG(printk(KERN_INFO
4206 "qla2x00_abort_isp(%ld): exiting.\n",
4214 * qla2x00_restart_isp
4215 * restarts the ISP after a reset
4218 * ha = adapter block pointer.
4224 qla2x00_restart_isp(scsi_qla_host_t *ha)
4228 unsigned long flags = 0;
4230 /* If firmware needs to be loaded */
4231 if (qla2x00_isp_firmware(ha)) {
4232 ha->flags.online = FALSE;
4233 if (!(status = qla2x00_chip_diag(ha))) {
4234 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4235 status = qla2x00_setup_chip(ha);
4240 spin_lock_irqsave(&ha->hardware_lock, flags);
4241 /* Disable SRAM, Instruction RAM and GP RAM parity. */
4242 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
4243 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4245 status = qla2x00_setup_chip(ha);
4247 spin_lock_irqsave(&ha->hardware_lock, flags);
4249 /* Enable proper parity */
4252 WRT_REG_WORD(®->hccr,
4253 (HCCR_ENABLE_PARITY + 0x1));
4255 /* SRAM, Instruction RAM and GP RAM parity */
4256 WRT_REG_WORD(®->hccr,
4257 (HCCR_ENABLE_PARITY + 0x7));
4259 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4264 if (!status && !(status = qla2x00_init_rings(ha))) {
4265 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
4266 if (!(status = qla2x00_fw_ready(ha))) {
4267 DEBUG(printk("%s(): Start configure loop, "
4271 ha->flags.online = TRUE;
4273 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4274 qla2x00_configure_loop(ha);
4275 } while (!atomic_read(&ha->loop_down_timer) &&
4276 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
4277 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
4280 /* if no cable then assume it's good */
4281 if ((ha->device_flags & DFLG_NO_CABLE))
4284 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
4292 * qla2x00_reset_adapter
4296 * ha = adapter block pointer.
4299 qla2x00_reset_adapter(scsi_qla_host_t *ha)
4301 unsigned long flags = 0;
4302 device_reg_t *reg = ha->iobase;
4304 ha->flags.online = FALSE;
4305 qla2x00_disable_intrs(ha);
4306 /* Reset RISC processor. */
4307 spin_lock_irqsave(&ha->hardware_lock, flags);
4308 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
4309 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
4310 spin_unlock_irqrestore(&ha->hardware_lock, flags);