2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2004 QLogic Corporation
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
21 #include <linux/delay.h>
23 #include "qla_devtbl.h"
25 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
26 #ifndef EXT_IS_LUN_BIT_SET
27 #define EXT_IS_LUN_BIT_SET(P,L) \
28 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
29 #define EXT_SET_LUN_BIT(P,L) \
30 ((P)->mask[L/8] |= (0x80 >> (L%8)))
34 * QLogic ISP2x00 Hardware Support Function Prototypes.
36 static int qla2x00_pci_config(scsi_qla_host_t *);
37 static int qla2x00_isp_firmware(scsi_qla_host_t *);
38 static void qla2x00_reset_chip(scsi_qla_host_t *);
39 static int qla2x00_chip_diag(scsi_qla_host_t *);
40 static int qla2x00_setup_chip(scsi_qla_host_t *);
41 static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
42 static int qla2x00_init_rings(scsi_qla_host_t *);
43 static int qla2x00_fw_ready(scsi_qla_host_t *);
44 static int qla2x00_configure_hba(scsi_qla_host_t *);
45 static int qla2x00_nvram_config(scsi_qla_host_t *);
46 static void qla2x00_init_tgt_map(scsi_qla_host_t *);
47 static int qla2x00_configure_loop(scsi_qla_host_t *);
48 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
49 static void qla2x00_update_fcport(scsi_qla_host_t *, fc_port_t *);
50 static void qla2x00_lun_discovery(scsi_qla_host_t *, fc_port_t *);
51 static int qla2x00_rpt_lun_discovery(scsi_qla_host_t *, fc_port_t *,
52 inq_cmd_rsp_t *, dma_addr_t);
53 static int qla2x00_report_lun(scsi_qla_host_t *, fc_port_t *,
54 rpt_lun_cmd_rsp_t *, dma_addr_t);
55 static fc_lun_t *qla2x00_cfg_lun(scsi_qla_host_t *, fc_port_t *, uint16_t,
56 inq_cmd_rsp_t *, dma_addr_t);
57 static fc_lun_t * qla2x00_add_lun(fc_port_t *, uint16_t);
58 static int qla2x00_inquiry(scsi_qla_host_t *, fc_port_t *, uint16_t,
59 inq_cmd_rsp_t *, dma_addr_t);
60 static int qla2x00_configure_fabric(scsi_qla_host_t *);
61 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
62 static int qla2x00_device_resync(scsi_qla_host_t *);
63 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
65 static void qla2x00_config_os(scsi_qla_host_t *ha);
66 static uint16_t qla2x00_fcport_bind(scsi_qla_host_t *ha, fc_port_t *fcport);
67 static os_lun_t * qla2x00_fclun_bind(scsi_qla_host_t *, fc_port_t *,
69 static void qla2x00_lun_free(scsi_qla_host_t *, uint16_t, uint16_t);
71 static int qla2x00_bstr_to_hex(char *, uint8_t *, int);
72 static int qla2x00_find_propname(scsi_qla_host_t *,
73 char *, char *, char *, int);
75 static void qla2x00_get_lun_mask_from_config(scsi_qla_host_t *, fc_port_t *,
77 static int qla2x00_get_prop_16chars(scsi_qla_host_t *,
78 char *, char *, char *);
79 static void qla2x00_get_properties(scsi_qla_host_t *, char *);
81 static void qla2x00_cfg_persistent_binding(scsi_qla_host_t *);
82 static os_tgt_t *qla2x00_persistent_bind(scsi_qla_host_t *, uint8_t *,
83 uint8_t *, port_id_t *, uint16_t);
86 static int qla2x00_restart_isp(scsi_qla_host_t *);
87 static void qla2x00_reset_adapter(scsi_qla_host_t *);
89 /****************************************************************************/
90 /* QLogic ISP2x00 Hardware Support Functions. */
91 /****************************************************************************/
94 * qla2x00_initialize_adapter
98 * ha = adapter block pointer.
104 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
107 uint8_t restart_risc = 0;
111 /* Clear adapter flags. */
112 ha->flags.online = 0;
113 ha->flags.reset_active = 0;
114 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
115 atomic_set(&ha->loop_state, LOOP_DOWN);
116 ha->device_flags = 0;
117 ha->sns_retry_cnt = 0;
119 ha->failback_delay = 0;
120 ha->flags.management_server_logged_in = 0;
121 ha->marker_needed = 0;
123 ha->isp_abort_cnt = 0;
124 ha->beacon_blink_led = 0;
126 rval = qla2x00_pci_config(ha);
128 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
133 qla2x00_reset_chip(ha);
135 /* Initialize target map database. */
136 qla2x00_init_tgt_map(ha);
138 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
139 qla2x00_nvram_config(ha);
141 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
145 * If the user specified a device configuration on the command line
146 * then use it as the configuration. Otherwise, we scan for all
150 ha->cmdline = ql2xdevconf;
151 qla2x00_get_properties(ha, ql2xdevconf);
157 * Try to configure the loop.
162 /* If firmware needs to be loaded */
163 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
164 if ((rval = qla2x00_chip_diag(ha)) == QLA_SUCCESS) {
165 rval = qla2x00_setup_chip(ha);
169 if (rval == QLA_SUCCESS &&
170 (rval = qla2x00_init_rings(ha)) == QLA_SUCCESS) {
171 check_fw_ready_again:
173 * Wait for a successful LIP up to a maximum
174 * of (in seconds): RISC login timeout value,
175 * RISC retry count value, and port down retry
176 * value OR a minimum of 4 seconds OR If no
177 * cable, only 5 seconds.
179 rval = qla2x00_fw_ready(ha);
180 if (rval == QLA_SUCCESS) {
181 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
184 * Wait at most MAX_TARGET RSCNs for a stable
189 clear_bit(LOOP_RESYNC_NEEDED,
191 rval = qla2x00_configure_loop(ha);
193 if (test_and_clear_bit(ISP_ABORT_NEEDED,
200 * If loop state change while we were
201 * discoverying devices then wait for
205 if (atomic_read(&ha->loop_state) ==
206 LOOP_DOWN && retry--) {
207 goto check_fw_ready_again;
210 } while (!atomic_read(&ha->loop_down_timer) &&
213 (test_bit(LOOP_RESYNC_NEEDED,
217 rval = QLA_FUNCTION_FAILED;
222 } while (restart_risc && retry--);
224 if (rval == QLA_SUCCESS) {
225 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
226 ha->marker_needed = 1;
227 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
228 ha->marker_needed = 0;
230 ha->flags.online = 1;
232 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
239 * qla2x00_pci_config() - Setup device PCI configuration registers.
242 * Returns 0 on success.
245 qla2x00_pci_config(scsi_qla_host_t *ha)
248 unsigned long flags = 0;
251 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
254 * Turn on PCI master; for system BIOSes that don't turn it on by
257 pci_set_master(ha->pdev);
259 if (pci_set_mwi(ha->pdev))
260 mwi = PCI_COMMAND_INVALIDATE;
261 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
264 return (QLA_FUNCTION_FAILED);
267 * We want to respect framework's setting of PCI configuration space
268 * command register and also want to make sure that all bits of
269 * interest to us are properly set in command register.
271 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
272 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
274 /* Get PCI bus information. */
275 spin_lock_irqsave(&ha->hardware_lock, flags);
276 ha->pci_attr = RD_REG_WORD(&ha->iobase->ctrl_status);
277 spin_unlock_irqrestore(&ha->hardware_lock, flags);
279 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
280 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
282 /* PCI Specification Revision 2.3 changes */
283 if (IS_QLA2322(ha) || IS_QLA6322(ha))
284 /* Command Register - Reset Interrupt Disable. */
285 w &= ~PCI_COMMAND_INTX_DISABLE;
288 * If this is a 2300 card and not 2312, reset the
289 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
290 * the 2310 also reports itself as a 2300 so we need to get the
291 * fb revision level -- a 6 indicates it really is a 2300 and
294 if (IS_QLA2300(ha)) {
295 spin_lock_irqsave(&ha->hardware_lock, flags);
298 WRT_REG_WORD(&ha->iobase->hccr, HCCR_PAUSE_RISC);
299 for (cnt = 0; cnt < 30000; cnt++) {
300 if ((RD_REG_WORD(&ha->iobase->hccr) &
301 HCCR_RISC_PAUSE) != 0)
307 /* Select FPM registers. */
308 WRT_REG_WORD(&ha->iobase->ctrl_status, 0x20);
310 /* Get the fb rev level */
311 ha->fb_rev = RD_FB_CMD_REG(ha, ha->iobase);
313 if (ha->fb_rev == FPM_2300)
314 w &= ~PCI_COMMAND_INVALIDATE;
316 /* Deselect FPM registers. */
317 WRT_REG_WORD(&ha->iobase->ctrl_status, 0x0);
319 /* Release RISC module. */
320 WRT_REG_WORD(&ha->iobase->hccr, HCCR_RELEASE_RISC);
321 for (cnt = 0; cnt < 30000; cnt++) {
322 if ((RD_REG_WORD(&ha->iobase->hccr) &
323 HCCR_RISC_PAUSE) == 0)
329 spin_unlock_irqrestore(&ha->hardware_lock, flags);
333 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
335 /* Reset expansion ROM address decode enable */
336 pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w);
337 w &= ~PCI_ROM_ADDRESS_ENABLE;
338 pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
340 return (QLA_SUCCESS);
344 * qla2x00_isp_firmware() - Choose firmware image.
347 * Returns 0 on success.
350 qla2x00_isp_firmware(scsi_qla_host_t *ha)
354 /* Assume loading risc code */
355 rval = QLA_FUNCTION_FAILED;
357 if (ha->flags.disable_risc_code_load) {
358 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
360 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
362 /* Verify checksum of loaded RISC code. */
363 rval = qla2x00_verify_checksum(ha);
367 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
375 * qla2x00_reset_chip() - Reset ISP chip.
378 * Returns 0 on success.
381 qla2x00_reset_chip(scsi_qla_host_t *ha)
383 unsigned long flags = 0;
384 device_reg_t *reg = ha->iobase;
386 unsigned long mbx_flags = 0;
389 /* Disable ISP interrupts. */
390 qla2x00_disable_intrs(ha);
392 spin_lock_irqsave(&ha->hardware_lock, flags);
394 /* Turn off master enable */
396 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
397 cmd &= ~PCI_COMMAND_MASTER;
398 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
400 if (!IS_QLA2100(ha)) {
402 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
403 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
404 for (cnt = 0; cnt < 30000; cnt++) {
405 if ((RD_REG_WORD(®->hccr) &
406 HCCR_RISC_PAUSE) != 0)
414 /* Select FPM registers. */
415 WRT_REG_WORD(®->ctrl_status, 0x20);
417 /* FPM Soft Reset. */
418 WRT_REG_WORD(®->fpm_diag_config, 0x100);
420 /* Toggle Fpm Reset. */
422 WRT_REG_WORD(®->fpm_diag_config, 0x0);
424 /* Select frame buffer registers. */
425 WRT_REG_WORD(®->ctrl_status, 0x10);
427 /* Reset frame buffer FIFOs. */
428 if (IS_QLA2200(ha)) {
429 WRT_FB_CMD_REG(ha, reg, 0xa000);
431 WRT_FB_CMD_REG(ha, reg, 0x00fc);
433 /* Read back fb_cmd until zero or 3 seconds max */
434 for (cnt = 0; cnt < 3000; cnt++) {
435 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
441 /* Select RISC module registers. */
442 WRT_REG_WORD(®->ctrl_status, 0);
444 /* Reset RISC processor. */
445 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
447 /* Release RISC processor. */
448 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
451 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
452 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
454 /* Reset ISP chip. */
455 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
457 /* Wait for RISC to recover from reset. */
458 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
460 * It is necessary to for a delay here since the card doesn't
461 * respond to PCI reads during a reset. On some architectures
462 * this will result in an MCA.
465 for (cnt = 30000; cnt; cnt--) {
466 if ((RD_REG_WORD(®->ctrl_status) &
467 CSR_ISP_SOFT_RESET) == 0)
474 /* Reset RISC processor. */
475 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
477 WRT_REG_WORD(®->semaphore, 0);
479 /* Release RISC processor. */
480 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
481 RD_REG_WORD(®->hccr); /* PCI Posting. */
483 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
484 for (cnt = 0; cnt < 30000; cnt++) {
485 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
486 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
488 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) {
489 if (!(test_bit(ABORT_ISP_ACTIVE,
491 spin_unlock_irqrestore(
492 &ha->mbx_reg_lock, mbx_flags);
496 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
497 spin_unlock_irqrestore(&ha->mbx_reg_lock,
505 /* Turn on master enable */
506 cmd |= PCI_COMMAND_MASTER;
507 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
509 /* Disable RISC pause on FPM parity error. */
511 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
513 spin_unlock_irqrestore(&ha->hardware_lock, flags);
517 * qla2x00_chip_diag() - Test chip for proper operation.
520 * Returns 0 on success.
523 qla2x00_chip_diag(scsi_qla_host_t *ha)
526 device_reg_t *reg = ha->iobase;
527 unsigned long flags = 0;
532 /* Assume a failed state */
533 rval = QLA_FUNCTION_FAILED;
535 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
536 ha->host_no, (u_long)®->flash_address));
538 spin_lock_irqsave(&ha->hardware_lock, flags);
540 /* Reset ISP chip. */
541 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
543 * We need to have a delay here since the card will not respond while
544 * in reset causing an MCA on some architectures.
547 data = qla2x00_debounce_register(®->ctrl_status);
548 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
550 data = RD_REG_WORD(®->ctrl_status);
555 goto chip_diag_failed;
557 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
560 /* Reset RISC processor. */
561 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
562 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
564 /* Workaround for QLA2312 PCI parity error */
565 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
566 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
567 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
569 data = RD_MAILBOX_REG(ha, reg, 0);
576 goto chip_diag_failed;
578 /* Check product ID of chip */
579 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
581 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
582 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
583 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
584 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
585 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
586 mb[3] != PROD_ID_3) {
587 qla_printk(KERN_WARNING, ha,
588 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
590 goto chip_diag_failed;
592 ha->product_id[0] = mb[1];
593 ha->product_id[1] = mb[2];
594 ha->product_id[2] = mb[3];
595 ha->product_id[3] = mb[4];
597 /* Adjust fw RISC transfer size */
598 if (ha->request_q_length > 1024)
599 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
601 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
602 ha->request_q_length;
604 if (IS_QLA2200(ha) &&
605 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
606 /* Limit firmware transfer size with a 2200A */
607 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
610 ha->fw_transfer_size = 128;
613 /* Wrap Incoming Mailboxes Test. */
614 spin_unlock_irqrestore(&ha->hardware_lock, flags);
616 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
617 rval = qla2x00_mbx_reg_test(ha);
619 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
621 qla_printk(KERN_WARNING, ha,
622 "Failed mailbox send register test\n");
625 /* Flag a successful rval */
628 spin_lock_irqsave(&ha->hardware_lock, flags);
632 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
633 "****\n", ha->host_no));
635 spin_unlock_irqrestore(&ha->hardware_lock, flags);
641 * qla2x00_setup_chip() - Load and start RISC firmware.
644 * Returns 0 on success.
647 qla2x00_setup_chip(scsi_qla_host_t *ha)
652 unsigned long risc_address;
653 unsigned long risc_code_size;
657 struct qla_fw_info *fw_iter;
661 /* Load firmware sequences */
662 fw_iter = ha->brd_info->fw_info;
663 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
664 risc_code = fw_iter->fwcode;
665 risc_code_size = *fw_iter->fwlen;
667 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
668 risc_address = *fw_iter->fwstart;
670 /* Extended address */
671 risc_address = *fw_iter->lfwstart;
676 while (risc_code_size > 0 && !rval) {
677 cnt = (uint16_t)(ha->fw_transfer_size >> 1);
678 if (cnt > risc_code_size)
679 cnt = risc_code_size;
681 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
682 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
683 ha->host_no, risc_code, cnt, risc_address));
685 req_ring = (uint16_t *)ha->request_ring;
686 for (i = 0; i < cnt; i++)
687 req_ring[i] = cpu_to_le16(risc_code[i]);
689 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
690 rval = qla2x00_load_ram(ha,
691 ha->request_dma, risc_address, cnt);
693 rval = qla2x00_load_ram_ext(ha,
694 ha->request_dma, risc_address, cnt);
697 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
698 "load segment %d of firmware\n",
700 qla_printk(KERN_WARNING, ha,
701 "[ERROR] Failed to load "
702 "segment %d of firmware\n", num);
704 qla2x00_dump_regs(ha);
710 risc_code_size -= cnt;
714 /* Next firmware sequence */
718 /* Verify checksum of loaded RISC code. */
720 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
721 "code.\n", ha->host_no));
723 rval = qla2x00_verify_checksum(ha);
724 if (rval == QLA_SUCCESS) {
725 /* Start firmware execution. */
726 DEBUG(printk("scsi(%ld): Checksum OK, start "
727 "firmware.\n", ha->host_no));
729 rval = qla2x00_execute_fw(ha);
730 /* Retrieve firmware information. */
731 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
732 qla2x00_get_fw_version(ha,
733 &ha->fw_major_version,
734 &ha->fw_minor_version,
735 &ha->fw_subminor_version,
736 &ha->fw_attributes, &ha->fw_memory_size);
740 DEBUG2(printk(KERN_INFO
741 "scsi(%ld): ISP Firmware failed checksum.\n",
747 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
755 * qla2x00_init_response_q_entries() - Initializes response queue entries.
758 * Beginning of request ring has initialization control block already built
759 * by nvram config routine.
761 * Returns 0 on success.
764 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
769 pkt = ha->response_ring_ptr;
770 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
771 pkt->signature = RESPONSE_PROCESSED;
778 * qla2x00_update_fw_options() - Read and process firmware options.
781 * Returns 0 on success.
784 qla2x00_update_fw_options(scsi_qla_host_t *ha)
786 uint16_t swing, emphasis;
788 memset(ha->fw_options, 0, sizeof(ha->fw_options));
789 qla2x00_get_fw_options(ha, ha->fw_options);
791 if (IS_QLA2100(ha) || IS_QLA2200(ha))
794 /* Serial Link options. */
795 DEBUG3(printk("scsi(%ld): Serial link options:\n",
797 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
798 sizeof(ha->fw_seriallink_options)));
800 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
801 if (ha->fw_seriallink_options[1] & BIT_2)
802 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
805 swing = ha->fw_seriallink_options[0] & (BIT_2 | BIT_1 | BIT_0);
806 emphasis = ha->fw_seriallink_options[0] & (BIT_4 | BIT_3);
808 ha->fw_options[10] = (emphasis << 14) | (swing << 8) | 0x3;
810 swing = ha->fw_seriallink_options[0] & (BIT_7 | BIT_6 | BIT_5);
812 emphasis = ha->fw_seriallink_options[1] & (BIT_1 | BIT_0);
813 ha->fw_options[11] = (emphasis << 14) | (swing << 8) | 0x3;
816 /* Return command IOCBs without waiting for an ABTS to complete. */
817 ha->fw_options[3] |= BIT_13;
819 /* Update firmware options. */
820 qla2x00_set_fw_options(ha, ha->fw_options);
824 * qla2x00_init_rings() - Initializes firmware.
827 * Beginning of request ring has initialization control block already built
828 * by nvram config routine.
830 * Returns 0 on success.
833 qla2x00_init_rings(scsi_qla_host_t *ha)
836 unsigned long flags = 0;
838 device_reg_t *reg = ha->iobase;
840 spin_lock_irqsave(&ha->hardware_lock, flags);
842 /* Clear outstanding commands array. */
843 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
844 ha->outstanding_cmds[cnt] = NULL;
846 ha->current_outstanding_cmd = 0;
848 /* Clear RSCN queue. */
850 ha->rscn_out_ptr = 0;
852 /* Initialize firmware. */
853 ha->request_ring_ptr = ha->request_ring;
854 ha->req_ring_index = 0;
855 ha->req_q_cnt = ha->request_q_length;
856 ha->response_ring_ptr = ha->response_ring;
857 ha->rsp_ring_index = 0;
859 /* Initialize response queue entries */
860 qla2x00_init_response_q_entries(ha);
862 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
863 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
864 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
865 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
866 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg));
868 spin_unlock_irqrestore(&ha->hardware_lock, flags);
870 /* Update any ISP specific firmware options before initialization. */
871 qla2x00_update_fw_options(ha);
873 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
874 rval = qla2x00_init_firmware(ha, sizeof(init_cb_t));
876 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
879 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
887 * qla2x00_fw_ready() - Waits for firmware ready.
890 * Returns 0 on success.
893 qla2x00_fw_ready(scsi_qla_host_t *ha)
896 unsigned long wtime, mtime;
897 uint16_t min_wait; /* Minimum wait time if loop is down */
898 uint16_t wait_time; /* Wait time if loop is coming ready */
903 /* 20 seconds for loop down. */
907 * Firmware should take at most one RATOV to login, plus 5 seconds for
908 * our own processing.
910 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
911 wait_time = min_wait;
914 /* Min wait time if loop down */
915 mtime = jiffies + (min_wait * HZ);
917 /* wait time before firmware ready */
918 wtime = jiffies + (wait_time * HZ);
920 /* Wait for ISP to finish LIP */
921 if (!ha->flags.init_done)
922 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
924 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
928 rval = qla2x00_get_firmware_state(ha, &fw_state);
929 if (rval == QLA_SUCCESS) {
930 if (fw_state < FSTATE_LOSS_OF_SYNC) {
931 ha->device_flags &= ~DFLG_NO_CABLE;
933 if (fw_state == FSTATE_READY) {
934 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
937 qla2x00_get_retry_cnt(ha, &ha->retry_count,
938 &ha->login_timeout, &ha->r_a_tov);
944 rval = QLA_FUNCTION_FAILED;
946 if (atomic_read(&ha->loop_down_timer) &&
947 (fw_state >= FSTATE_LOSS_OF_SYNC ||
948 fw_state == FSTATE_WAIT_AL_PA)) {
949 /* Loop down. Timeout on min_wait for states
950 * other than Wait for Login.
952 if (time_after_eq(jiffies, mtime)) {
953 qla_printk(KERN_INFO, ha,
954 "Cable is unplugged...\n");
956 ha->device_flags |= DFLG_NO_CABLE;
961 /* Mailbox cmd failed. Timeout on min_wait. */
962 if (time_after_eq(jiffies, mtime))
966 if (time_after_eq(jiffies, wtime))
969 /* Delay for a while */
970 set_current_state(TASK_UNINTERRUPTIBLE);
971 schedule_timeout(HZ / 2);
973 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
974 ha->host_no, fw_state, jiffies));
977 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
978 ha->host_no, fw_state, jiffies));
981 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
989 * qla2x00_configure_hba
990 * Setup adapter context.
993 * ha = adapter state pointer.
1002 qla2x00_configure_hba(scsi_qla_host_t *ha)
1010 char connect_type[22];
1012 /* Get host addresses. */
1013 rval = qla2x00_get_adapter_id(ha,
1014 &loop_id, &al_pa, &area, &domain, &topo);
1015 if (rval != QLA_SUCCESS) {
1016 qla_printk(KERN_WARNING, ha,
1017 "ERROR -- Unable to get host loop ID.\n");
1022 qla_printk(KERN_INFO, ha,
1023 "Cannot get topology - retrying.\n");
1024 return (QLA_FUNCTION_FAILED);
1027 ha->loop_id = loop_id;
1030 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1031 ha->operating_mode = LOOP;
1035 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1037 ha->current_topology = ISP_CFG_NL;
1038 strcpy(connect_type, "(Loop)");
1042 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1044 ha->current_topology = ISP_CFG_FL;
1045 strcpy(connect_type, "(FL_Port)");
1049 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1051 ha->operating_mode = P2P;
1052 ha->current_topology = ISP_CFG_N;
1053 strcpy(connect_type, "(N_Port-to-N_Port)");
1057 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1059 ha->operating_mode = P2P;
1060 ha->current_topology = ISP_CFG_F;
1061 strcpy(connect_type, "(F_Port)");
1065 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1067 ha->host_no, topo));
1068 ha->current_topology = ISP_CFG_NL;
1069 strcpy(connect_type, "(Loop)");
1073 /* Save Host port and loop ID. */
1074 /* byte order - Big Endian */
1075 ha->d_id.b.domain = domain;
1076 ha->d_id.b.area = area;
1077 ha->d_id.b.al_pa = al_pa;
1079 if (!ha->flags.init_done)
1080 qla_printk(KERN_INFO, ha,
1081 "Topology - %s, Host Loop address 0x%x\n",
1082 connect_type, ha->loop_id);
1085 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1087 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1094 * NVRAM configuration for ISP 2xxx
1097 * ha = adapter block pointer.
1100 * initialization control block in response_ring
1101 * host adapters parameters in host adapter block
1107 qla2x00_nvram_config(scsi_qla_host_t *ha)
1112 uint8_t *dptr1, *dptr2;
1113 init_cb_t *icb = ha->init_cb;
1114 nvram_t *nv = (nvram_t *)ha->request_ring;
1115 uint16_t *wptr = (uint16_t *)ha->request_ring;
1116 device_reg_t *reg = ha->iobase;
1121 if (ha->flags.init_done)
1124 /* Determine NVRAM starting address. */
1126 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1127 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1128 ha->nvram_base = 0x80;
1130 /* Get NVRAM data and calculate checksum. */
1131 qla2x00_lock_nvram_access(ha);
1132 for (cnt = 0; cnt < sizeof(nvram_t)/2; cnt++) {
1133 *wptr = cpu_to_le16(qla2x00_get_nvram_word(ha,
1134 (cnt+ha->nvram_base)));
1135 chksum += (uint8_t)*wptr;
1136 chksum += (uint8_t)(*wptr >> 8);
1139 qla2x00_unlock_nvram_access(ha);
1141 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1142 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1145 /* Bad NVRAM data, set defaults parameters. */
1146 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1147 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1148 /* Reset NVRAM data. */
1149 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1150 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1152 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1153 "invalid -- WWPN) defaults.\n");
1156 * Set default initialization control block.
1158 memset(nv, 0, sizeof(nvram_t));
1159 nv->parameter_block_version = ICB_VERSION;
1161 if (IS_QLA23XX(ha)) {
1162 nv->firmware_options[0] = BIT_2 | BIT_1;
1163 nv->firmware_options[1] = BIT_7 | BIT_5;
1164 nv->add_firmware_options[0] = BIT_5;
1165 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1166 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1167 nv->special_options[1] = BIT_7;
1168 } else if (IS_QLA2200(ha)) {
1169 nv->firmware_options[0] = BIT_2 | BIT_1;
1170 nv->firmware_options[1] = BIT_7 | BIT_5;
1171 nv->add_firmware_options[0] = BIT_5;
1172 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1173 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1174 } else if (IS_QLA2100(ha)) {
1175 nv->firmware_options[0] = BIT_3 | BIT_1;
1176 nv->firmware_options[1] = BIT_5;
1177 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1180 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1181 nv->execution_throttle = __constant_cpu_to_le16(16);
1182 nv->retry_count = 8;
1183 nv->retry_delay = 1;
1185 nv->port_name[0] = 33;
1186 nv->port_name[3] = 224;
1187 nv->port_name[4] = 139;
1189 nv->login_timeout = 4;
1192 * Set default host adapter parameters
1194 nv->host_p[1] = BIT_2;
1195 nv->reset_delay = 5;
1196 nv->port_down_retry_count = 8;
1197 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1198 nv->link_down_timeout = 60;
1203 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1205 * The SN2 does not provide BIOS emulation which means you can't change
1206 * potentially bogus BIOS settings. Force the use of default settings
1207 * for link rate and frame size. Hope that the rest of the settings
1210 if (ia64_platform_is("sn2")) {
1211 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1213 nv->special_options[1] = BIT_7;
1217 /* Reset Initialization control block */
1218 memset(icb, 0, sizeof(init_cb_t));
1221 * Setup driver NVRAM options.
1223 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1224 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1225 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1226 nv->firmware_options[1] &= ~BIT_4;
1228 if (IS_QLA23XX(ha)) {
1229 nv->firmware_options[0] |= BIT_2;
1230 nv->firmware_options[0] &= ~BIT_3;
1232 if (IS_QLA2300(ha)) {
1233 if (ha->fb_rev == FPM_2310) {
1234 strcpy(ha->model_number, "QLA2310");
1236 strcpy(ha->model_number, "QLA2300");
1240 memcmp(nv->model_number, BINZERO,
1241 sizeof(nv->model_number)) != 0) {
1244 strncpy(ha->model_number, nv->model_number,
1245 sizeof(nv->model_number));
1246 st = en = ha->model_number;
1247 en += sizeof(nv->model_number) - 1;
1249 if (*en != 0x20 && *en != 0x00)
1256 index = (ha->pdev->subsystem_device & 0xff);
1257 if (index < QLA_MODEL_NAMES) {
1258 strcpy(ha->model_number,
1259 qla2x00_model_name[index]);
1261 qla2x00_model_desc[index];
1263 strcpy(ha->model_number, "QLA23xx");
1267 } else if (IS_QLA2200(ha)) {
1268 nv->firmware_options[0] |= BIT_2;
1270 * 'Point-to-point preferred, else loop' is not a safe
1271 * connection mode setting.
1273 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1275 /* Force 'loop preferred, else point-to-point'. */
1276 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1277 nv->add_firmware_options[0] |= BIT_5;
1279 strcpy(ha->model_number, "QLA22xx");
1280 } else /*if (IS_QLA2100(ha))*/ {
1281 strcpy(ha->model_number, "QLA2100");
1285 * Copy over NVRAM RISC parameter block to initialization control block.
1287 dptr1 = (uint8_t *)icb;
1288 dptr2 = (uint8_t *)&nv->parameter_block_version;
1289 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1291 *dptr1++ = *dptr2++;
1293 /* Copy 2nd half. */
1294 dptr1 = (uint8_t *)icb->add_firmware_options;
1295 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1297 *dptr1++ = *dptr2++;
1299 /* Prepare nodename */
1300 if ((icb->firmware_options[1] & BIT_6) == 0) {
1302 * Firmware will apply the following mask if the nodename was
1305 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1306 icb->node_name[0] &= 0xF0;
1310 * Set host adapter parameters.
1312 ha->nvram_version = nv->nvram_version;
1314 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1315 /* Always load RISC code on non ISP2[12]00 chips. */
1316 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1317 ha->flags.disable_risc_code_load = 0;
1318 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1319 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1320 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1322 ha->operating_mode =
1323 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1325 ha->fw_seriallink_options[0] = nv->seriallink_options[0];
1326 ha->fw_seriallink_options[1] = nv->seriallink_options[1];
1328 /* save HBA serial number */
1329 ha->serial0 = icb->port_name[5];
1330 ha->serial1 = icb->port_name[6];
1331 ha->serial2 = icb->port_name[7];
1332 memcpy(ha->node_name, icb->node_name, WWN_SIZE);
1334 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1336 ha->retry_count = nv->retry_count;
1338 /* Set minimum login_timeout to 4 seconds. */
1339 if (nv->login_timeout < ql2xlogintimeout)
1340 nv->login_timeout = ql2xlogintimeout;
1341 if (nv->login_timeout < 4)
1342 nv->login_timeout = 4;
1343 ha->login_timeout = nv->login_timeout;
1344 icb->login_timeout = nv->login_timeout;
1346 /* Set minimum RATOV to 200 tenths of a second. */
1349 ha->minimum_timeout =
1350 (ha->login_timeout * ha->retry_count) + nv->port_down_retry_count;
1351 ha->loop_reset_delay = nv->reset_delay;
1353 /* Will get the value from NVRAM. */
1354 ha->loop_down_timeout = LOOP_DOWN_TIMEOUT;
1356 /* Link Down Timeout = 0:
1358 * When Port Down timer expires we will start returning
1359 * I/O's to OS with "DID_NO_CONNECT".
1361 * Link Down Timeout != 0:
1363 * The driver waits for the link to come up after link down
1364 * before returning I/Os to OS with "DID_NO_CONNECT".
1366 if (nv->link_down_timeout == 0) {
1367 ha->loop_down_abort_time =
1368 (LOOP_DOWN_TIME - ha->loop_down_timeout);
1370 ha->link_down_timeout = nv->link_down_timeout;
1371 ha->loop_down_abort_time =
1372 (LOOP_DOWN_TIME - ha->link_down_timeout);
1375 ha->max_luns = MAX_LUNS;
1376 ha->max_probe_luns = le16_to_cpu(nv->max_luns_per_target);
1377 if (ha->max_probe_luns == 0)
1378 ha->max_probe_luns = MIN_LUNS;
1381 * Need enough time to try and get the port back.
1383 ha->port_down_retry_count = nv->port_down_retry_count;
1384 if (qlport_down_retry)
1385 ha->port_down_retry_count = qlport_down_retry;
1386 /* Set login_retry_count */
1387 ha->login_retry_count = nv->retry_count;
1388 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1389 ha->port_down_retry_count > 3)
1390 ha->login_retry_count = ha->port_down_retry_count;
1391 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1392 ha->login_retry_count = ha->port_down_retry_count;
1393 if (ql2xloginretrycount)
1394 ha->login_retry_count = ql2xloginretrycount;
1396 ha->binding_type = Bind;
1397 if (ha->binding_type != BIND_BY_PORT_NAME &&
1398 ha->binding_type != BIND_BY_PORT_ID) {
1399 qla_printk(KERN_WARNING, ha,
1400 "Invalid binding type specified (%d), "
1401 "defaulting to BIND_BY_PORT_NAME!!!\n", ha->binding_type);
1403 ha->binding_type = BIND_BY_PORT_NAME;
1407 * Setup ring parameters in initialization control block
1409 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1410 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1411 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1412 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1413 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1414 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1415 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1416 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1418 icb->lun_enables = __constant_cpu_to_le16(0);
1419 icb->command_resource_count = 0;
1420 icb->immediate_notify_resource_count = 0;
1421 icb->timeout = __constant_cpu_to_le16(0);
1423 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1425 icb->firmware_options[0] &= ~BIT_3;
1426 icb->add_firmware_options[0] &=
1427 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1428 icb->add_firmware_options[0] |= BIT_2;
1429 icb->response_accumulation_timer = 3;
1430 icb->interrupt_delay_timer = 5;
1432 ha->flags.process_response_queue = 1;
1434 /* Enable ZIO -- Support mode 5 only. */
1435 timer_mode = icb->add_firmware_options[0] &
1436 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1437 icb->add_firmware_options[0] &=
1438 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1440 timer_mode = BIT_2 | BIT_0;
1441 if (timer_mode == (BIT_2 | BIT_0)) {
1442 DEBUG2(printk("scsi(%ld): ZIO enabled; timer delay "
1443 "(%d).\n", ha->host_no, ql2xintrdelaytimer));
1444 qla_printk(KERN_INFO, ha,
1445 "ZIO enabled; timer delay (%d).\n",
1446 ql2xintrdelaytimer);
1448 icb->add_firmware_options[0] |= timer_mode;
1449 icb->interrupt_delay_timer = ql2xintrdelaytimer;
1450 ha->flags.process_response_queue = 1;
1455 DEBUG2_3(printk(KERN_WARNING
1456 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1462 * qla2x00_init_tgt_map
1463 * Initializes target map.
1466 * ha = adapter block pointer.
1472 qla2x00_init_tgt_map(scsi_qla_host_t *ha)
1476 for (t = 0; t < MAX_TARGETS; t++)
1477 TGT_Q(ha, t) = (os_tgt_t *)NULL;
1481 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1483 * @flags: allocation flags
1485 * Returns a pointer to the allocated fcport, or NULL, if none available.
1488 qla2x00_alloc_fcport(scsi_qla_host_t *ha, int flags)
1492 fcport = kmalloc(sizeof(fc_port_t), flags);
1496 /* Setup fcport template structure. */
1497 memset(fcport, 0, sizeof (fc_port_t));
1499 fcport->port_type = FCT_UNKNOWN;
1500 fcport->loop_id = FC_NO_LOOP_ID;
1501 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1502 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1503 fcport->flags = FCF_RLC_SUPPORT;
1504 INIT_LIST_HEAD(&fcport->fcluns);
1510 * qla2x00_configure_loop
1511 * Updates Fibre Channel Device Database with what is actually on loop.
1514 * ha = adapter block pointer.
1519 * 2 = database was full and device was not configured.
1522 qla2x00_configure_loop(scsi_qla_host_t *ha)
1525 unsigned long flags, save_flags;
1529 /* Get Initiator ID */
1530 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1531 rval = qla2x00_configure_hba(ha);
1532 if (rval != QLA_SUCCESS) {
1533 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1539 save_flags = flags = ha->dpc_flags;
1540 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1541 ha->host_no, flags));
1544 * If we have both an RSCN and PORT UPDATE pending then handle them
1545 * both at the same time.
1547 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1548 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1551 /* Determine what we need to do */
1552 if (ha->current_topology == ISP_CFG_FL &&
1553 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1555 ha->flags.rscn_queue_overflow = 1;
1556 set_bit(RSCN_UPDATE, &flags);
1558 } else if (ha->current_topology == ISP_CFG_F &&
1559 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1561 ha->flags.rscn_queue_overflow = 1;
1562 set_bit(RSCN_UPDATE, &flags);
1563 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1565 } else if (!ha->flags.online ||
1566 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1568 ha->flags.rscn_queue_overflow = 1;
1569 set_bit(RSCN_UPDATE, &flags);
1570 set_bit(LOCAL_LOOP_UPDATE, &flags);
1573 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1574 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1575 rval = QLA_FUNCTION_FAILED;
1577 rval = qla2x00_configure_local_loop(ha);
1581 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1582 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1583 rval = QLA_FUNCTION_FAILED;
1585 rval = qla2x00_configure_fabric(ha);
1589 if (rval == QLA_SUCCESS) {
1590 if (atomic_read(&ha->loop_down_timer) ||
1591 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1592 rval = QLA_FUNCTION_FAILED;
1594 qla2x00_config_os(ha);
1595 atomic_set(&ha->loop_state, LOOP_READY);
1597 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1602 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1603 __func__, ha->host_no));
1605 DEBUG3(printk("%s: exiting normally\n", __func__));
1608 /* Restore state if a resync event occured during processing */
1609 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1610 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1611 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1612 if (test_bit(RSCN_UPDATE, &save_flags))
1613 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1622 * qla2x00_configure_local_loop
1623 * Updates Fibre Channel Device Database with local loop devices.
1626 * ha = adapter block pointer.
1632 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1637 fc_port_t *fcport, *new_fcport;
1645 uint8_t loop_id_2100; /* ISP2100/ISP2200 -- 4 bytes. */
1646 uint16_t loop_id; /* ISP23XX -- 6 bytes. */
1648 #define MAX_ID_LIST_SIZE (sizeof(struct dev_id) * MAX_FIBRE_DEVICES)
1649 dma_addr_t id_list_dma;
1652 uint8_t domain, area, al_pa;
1657 entries = MAX_FIBRE_DEVICES;
1658 id_list = pci_alloc_consistent(ha->pdev, MAX_ID_LIST_SIZE,
1660 if (id_list == NULL) {
1661 DEBUG2(printk("scsi(%ld): Failed to allocate memory, No local "
1662 "loop\n", ha->host_no));
1664 qla_printk(KERN_WARNING, ha,
1665 "Memory Allocation failed - port_list");
1668 return (QLA_MEMORY_ALLOC_FAILED);
1670 memset(id_list, 0, MAX_ID_LIST_SIZE);
1672 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1673 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1675 /* Get list of logged in devices. */
1676 rval = qla2x00_get_id_list(ha, id_list, id_list_dma, &entries);
1677 if (rval != QLA_SUCCESS) {
1678 goto cleanup_allocation;
1681 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1682 ha->host_no, entries));
1683 DEBUG3(qla2x00_dump_buffer((uint8_t *)id_list,
1684 entries * sizeof(struct dev_id)));
1686 /* Allocate temporary fcport for any new fcports discovered. */
1687 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1688 if (new_fcport == NULL) {
1689 rval = QLA_MEMORY_ALLOC_FAILED;
1690 goto cleanup_allocation;
1692 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1695 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1697 list_for_each_entry(fcport, &ha->fcports, list) {
1698 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1699 fcport->port_type != FCT_BROADCAST &&
1700 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1702 DEBUG(printk("scsi(%ld): Marking port lost, "
1704 ha->host_no, fcport->loop_id));
1706 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1707 fcport->flags &= ~FCF_FARP_DONE;
1711 /* Add devices to port list. */
1712 id_iter = (char *)id_list;
1713 for (index = 0; index < entries; index++) {
1714 domain = ((struct dev_id *)id_iter)->domain;
1715 area = ((struct dev_id *)id_iter)->area;
1716 al_pa = ((struct dev_id *)id_iter)->al_pa;
1717 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1719 (uint16_t)((struct dev_id *)id_iter)->loop_id_2100;
1723 le16_to_cpu(((struct dev_id *)id_iter)->loop_id);
1727 /* Bypass reserved domain fields. */
1728 if ((domain & 0xf0) == 0xf0)
1731 /* Bypass if not same domain and area of adapter. */
1732 if (area != ha->d_id.b.area || domain != ha->d_id.b.domain)
1735 /* Bypass invalid local loop ID. */
1736 if (loop_id > LAST_LOCAL_LOOP_ID)
1739 /* Fill in member data. */
1740 new_fcport->d_id.b.domain = domain;
1741 new_fcport->d_id.b.area = area;
1742 new_fcport->d_id.b.al_pa = al_pa;
1743 new_fcport->loop_id = loop_id;
1744 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1745 if (rval2 != QLA_SUCCESS) {
1746 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1747 "information -- get_port_database=%x, "
1749 ha->host_no, rval2, new_fcport->loop_id));
1753 /* Check for matching device in port list. */
1756 list_for_each_entry(fcport, &ha->fcports, list) {
1757 if (memcmp(new_fcport->port_name, fcport->port_name,
1761 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1762 FCF_PERSISTENT_BOUND);
1763 fcport->loop_id = new_fcport->loop_id;
1764 fcport->port_type = new_fcport->port_type;
1765 fcport->d_id.b24 = new_fcport->d_id.b24;
1766 memcpy(fcport->node_name, new_fcport->node_name,
1774 /* New device, add to fcports list. */
1775 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1776 list_add_tail(&new_fcport->list, &ha->fcports);
1778 /* Allocate a new replacement fcport. */
1779 fcport = new_fcport;
1780 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1781 if (new_fcport == NULL) {
1782 rval = QLA_MEMORY_ALLOC_FAILED;
1783 goto cleanup_allocation;
1785 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1788 qla2x00_update_fcport(ha, fcport);
1794 pci_free_consistent(ha->pdev, MAX_ID_LIST_SIZE, id_list, id_list_dma);
1799 if (rval != QLA_SUCCESS) {
1800 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1801 "rval=%x\n", ha->host_no, rval));
1805 ha->device_flags |= DFLG_LOCAL_DEVICES;
1806 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
1813 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
1817 qla2x00_mark_all_devices_lost(ha);
1818 list_for_each_entry(fcport, &ha->fcports, list) {
1819 if (fcport->port_type != FCT_TARGET)
1822 qla2x00_update_fcport(ha, fcport);
1827 * qla2x00_update_fcport
1828 * Updates device on list.
1831 * ha = adapter block pointer.
1832 * fcport = port structure pointer.
1842 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
1845 unsigned long flags;
1849 fcport->login_retry = 0;
1850 fcport->port_login_retry_count = ha->port_down_retry_count *
1852 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
1854 fcport->flags &= ~FCF_LOGIN_NEEDED;
1857 * Check for outstanding cmd on tape Bypass LUN discovery if active
1860 if (fcport->flags & FCF_TAPE_PRESENT) {
1861 spin_lock_irqsave(&ha->hardware_lock, flags);
1862 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
1863 if ((sp = ha->outstanding_cmds[index]) != 0) {
1864 if (sp->fclun->fcport == fcport) {
1865 atomic_set(&fcport->state, FCS_ONLINE);
1866 spin_unlock_irqrestore(
1867 &ha->hardware_lock, flags);
1872 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1875 /* Do LUN discovery. */
1876 if (fcport->port_type == FCT_INITIATOR ||
1877 fcport->port_type == FCT_BROADCAST) {
1878 fcport->device_type = TYPE_PROCESSOR;
1880 qla2x00_lun_discovery(ha, fcport);
1882 atomic_set(&fcport->state, FCS_ONLINE);
1886 * qla2x00_lun_discovery
1887 * Issue SCSI inquiry command for LUN discovery.
1890 * ha: adapter state pointer.
1891 * fcport: FC port structure pointer.
1897 qla2x00_lun_discovery(scsi_qla_host_t *ha, fc_port_t *fcport)
1903 inq = pci_alloc_consistent(ha->pdev, sizeof(inq_cmd_rsp_t), &inq_dma);
1905 qla_printk(KERN_WARNING, ha,
1906 "Memory Allocation failed - INQ\n");
1910 /* If report LUN works, exit. */
1911 if (qla2x00_rpt_lun_discovery(ha, fcport, inq, inq_dma) !=
1913 for (lun = 0; lun < ha->max_probe_luns; lun++) {
1914 /* Configure LUN. */
1915 qla2x00_cfg_lun(ha, fcport, lun, inq, inq_dma);
1919 pci_free_consistent(ha->pdev, sizeof(inq_cmd_rsp_t), inq, inq_dma);
1923 * qla2x00_rpt_lun_discovery
1924 * Issue SCSI report LUN command for LUN discovery.
1927 * ha: adapter state pointer.
1928 * fcport: FC port structure pointer.
1931 * qla2x00 local function return status code.
1937 qla2x00_rpt_lun_discovery(scsi_qla_host_t *ha, fc_port_t *fcport,
1938 inq_cmd_rsp_t *inq, dma_addr_t inq_dma)
1943 rpt_lun_cmd_rsp_t *rlc;
1946 /* Assume a failed status */
1947 rval = QLA_FUNCTION_FAILED;
1949 /* No point in continuing if the device doesn't support RLC */
1950 if ((fcport->flags & FCF_RLC_SUPPORT) == 0)
1953 rlc = pci_alloc_consistent(ha->pdev, sizeof(rpt_lun_cmd_rsp_t),
1956 qla_printk(KERN_WARNING, ha,
1957 "Memory Allocation failed - RLC");
1958 return QLA_MEMORY_ALLOC_FAILED;
1961 rval = qla2x00_report_lun(ha, fcport, rlc, rlc_dma);
1962 if (rval != QLA_SUCCESS) {
1963 pci_free_consistent(ha->pdev, sizeof(rpt_lun_cmd_rsp_t), rlc,
1968 /* Always add a fc_lun_t structure for lun 0 -- mid-layer requirement */
1969 qla2x00_add_lun(fcport, 0);
1971 /* Configure LUN list. */
1972 len = be32_to_cpu(rlc->list.hdr.len);
1974 for (cnt = 0; cnt < len; cnt++) {
1975 lun = CHAR_TO_SHORT(rlc->list.lst[cnt].lsb,
1976 rlc->list.lst[cnt].msb.b);
1978 DEBUG3(printk("scsi(%ld): RLC lun = (%d)\n", ha->host_no, lun));
1980 /* We only support 0 through MAX_LUNS-1 range */
1981 if (lun < MAX_LUNS) {
1982 qla2x00_cfg_lun(ha, fcport, lun, inq, inq_dma);
1985 atomic_set(&fcport->state, FCS_ONLINE);
1987 pci_free_consistent(ha->pdev, sizeof(rpt_lun_cmd_rsp_t), rlc, rlc_dma);
1993 * qla2x00_report_lun
1994 * Issue SCSI report LUN command.
1997 * ha: adapter state pointer.
1998 * fcport: FC port structure pointer.
1999 * mem: pointer to dma memory object for report LUN IOCB
2003 * qla2x00 local function return status code.
2009 qla2x00_report_lun(scsi_qla_host_t *ha,
2010 fc_port_t *fcport, rpt_lun_cmd_rsp_t *rlc, dma_addr_t rlc_dma)
2014 uint16_t comp_status;
2015 uint16_t scsi_status;
2017 rval = QLA_FUNCTION_FAILED;
2019 for (retries = 3; retries; retries--) {
2020 memset(rlc, 0, sizeof(rpt_lun_cmd_rsp_t));
2021 rlc->p.cmd.entry_type = COMMAND_A64_TYPE;
2022 rlc->p.cmd.entry_count = 1;
2023 SET_TARGET_ID(ha, rlc->p.cmd.target, fcport->loop_id);
2024 rlc->p.cmd.control_flags =
2025 __constant_cpu_to_le16(CF_READ | CF_SIMPLE_TAG);
2026 rlc->p.cmd.scsi_cdb[0] = REPORT_LUNS;
2027 rlc->p.cmd.scsi_cdb[8] = MSB(sizeof(rpt_lun_lst_t));
2028 rlc->p.cmd.scsi_cdb[9] = LSB(sizeof(rpt_lun_lst_t));
2029 rlc->p.cmd.dseg_count = __constant_cpu_to_le16(1);
2030 rlc->p.cmd.timeout = __constant_cpu_to_le16(10);
2031 rlc->p.cmd.byte_count =
2032 __constant_cpu_to_le32(sizeof(rpt_lun_lst_t));
2033 rlc->p.cmd.dseg_0_address[0] = cpu_to_le32(
2034 LSD(rlc_dma + sizeof(sts_entry_t)));
2035 rlc->p.cmd.dseg_0_address[1] = cpu_to_le32(
2036 MSD(rlc_dma + sizeof(sts_entry_t)));
2037 rlc->p.cmd.dseg_0_length =
2038 __constant_cpu_to_le32(sizeof(rpt_lun_lst_t));
2040 rval = qla2x00_issue_iocb(ha, rlc, rlc_dma,
2041 sizeof(rpt_lun_cmd_rsp_t));
2043 comp_status = le16_to_cpu(rlc->p.rsp.comp_status);
2044 scsi_status = le16_to_cpu(rlc->p.rsp.scsi_status);
2046 if (rval != QLA_SUCCESS || comp_status != CS_COMPLETE ||
2047 scsi_status & SS_CHECK_CONDITION) {
2049 /* Device underrun, treat as OK. */
2050 if (rval == QLA_SUCCESS &&
2051 comp_status == CS_DATA_UNDERRUN &&
2052 scsi_status & SS_RESIDUAL_UNDER) {
2058 DEBUG(printk("scsi(%ld): RLC failed to issue iocb! "
2059 "fcport=[%04x/%p] rval=%x cs=%x ss=%x\n",
2060 ha->host_no, fcport->loop_id, fcport, rval,
2061 comp_status, scsi_status));
2063 rval = QLA_FUNCTION_FAILED;
2064 if (scsi_status & SS_CHECK_CONDITION) {
2065 DEBUG2(printk("scsi(%ld): RLC "
2066 "SS_CHECK_CONDITION Sense Data "
2067 "%02x %02x %02x %02x %02x %02x %02x %02x\n",
2069 rlc->p.rsp.req_sense_data[0],
2070 rlc->p.rsp.req_sense_data[1],
2071 rlc->p.rsp.req_sense_data[2],
2072 rlc->p.rsp.req_sense_data[3],
2073 rlc->p.rsp.req_sense_data[4],
2074 rlc->p.rsp.req_sense_data[5],
2075 rlc->p.rsp.req_sense_data[6],
2076 rlc->p.rsp.req_sense_data[7]));
2077 if (rlc->p.rsp.req_sense_data[2] ==
2079 fcport->flags &= ~(FCF_RLC_SUPPORT);
2093 * Configures LUN into fcport LUN list.
2096 * fcport: FC port structure pointer.
2103 qla2x00_cfg_lun(scsi_qla_host_t *ha, fc_port_t *fcport, uint16_t lun,
2104 inq_cmd_rsp_t *inq, dma_addr_t inq_dma)
2108 /* Bypass LUNs that failed. */
2109 if (qla2x00_inquiry(ha, fcport, lun, inq, inq_dma) != QLA_SUCCESS) {
2110 DEBUG2(printk("scsi(%ld): Failed inquiry - loop id=0x%04x "
2111 "lun=%d\n", ha->host_no, fcport->loop_id, lun));
2116 switch (inq->inq[0]) {
2118 case TYPE_PROCESSOR:
2123 case TYPE_MEDIUM_CHANGER:
2124 case TYPE_ENCLOSURE:
2129 fcport->flags |= FCF_TAPE_PRESENT;
2132 DEBUG2(printk("scsi(%ld): Unsupported lun type -- "
2133 "loop id=0x%04x lun=%d type=%x\n",
2134 ha->host_no, fcport->loop_id, lun, inq->inq[0]));
2138 fcport->device_type = inq->inq[0];
2139 fclun = qla2x00_add_lun(fcport, lun);
2141 if (fclun != NULL) {
2142 atomic_set(&fcport->state, FCS_ONLINE);
2150 * Adds LUN to database
2153 * fcport: FC port structure pointer.
2160 qla2x00_add_lun(fc_port_t *fcport, uint16_t lun)
2165 if (fcport == NULL) {
2166 DEBUG(printk("scsi: Unable to add lun to NULL port\n"));
2170 /* Allocate LUN if not already allocated. */
2172 list_for_each_entry(fclun, &fcport->fcluns, list) {
2173 if (fclun->lun == lun) {
2181 fclun = kmalloc(sizeof(fc_lun_t), GFP_ATOMIC);
2182 if (fclun == NULL) {
2184 "%s(): Memory Allocation failed - FCLUN\n",
2189 /* Setup LUN structure. */
2190 memset(fclun, 0, sizeof(fc_lun_t));
2192 fclun->fcport = fcport;
2193 fclun->o_fcport = fcport;
2194 fclun->device_type = fcport->device_type;
2195 atomic_set(&fcport->state, FCS_UNCONFIGURED);
2197 list_add_tail(&fclun->list, &fcport->fcluns);
2204 * Issue SCSI inquiry command.
2207 * ha = adapter block pointer.
2208 * fcport = FC port structure pointer.
2218 qla2x00_inquiry(scsi_qla_host_t *ha,
2219 fc_port_t *fcport, uint16_t lun, inq_cmd_rsp_t *inq, dma_addr_t inq_dma)
2223 uint16_t comp_status;
2224 uint16_t scsi_status;
2226 rval = QLA_FUNCTION_FAILED;
2228 for (retries = 3; retries; retries--) {
2229 memset(inq, 0, sizeof(inq_cmd_rsp_t));
2230 inq->p.cmd.entry_type = COMMAND_A64_TYPE;
2231 inq->p.cmd.entry_count = 1;
2232 inq->p.cmd.lun = cpu_to_le16(lun);
2233 SET_TARGET_ID(ha, inq->p.cmd.target, fcport->loop_id);
2234 inq->p.cmd.control_flags =
2235 __constant_cpu_to_le16(CF_READ | CF_SIMPLE_TAG);
2236 inq->p.cmd.scsi_cdb[0] = INQUIRY;
2237 inq->p.cmd.scsi_cdb[4] = INQ_DATA_SIZE;
2238 inq->p.cmd.dseg_count = __constant_cpu_to_le16(1);
2239 inq->p.cmd.timeout = __constant_cpu_to_le16(10);
2240 inq->p.cmd.byte_count =
2241 __constant_cpu_to_le32(INQ_DATA_SIZE);
2242 inq->p.cmd.dseg_0_address[0] = cpu_to_le32(
2243 LSD(inq_dma + sizeof(sts_entry_t)));
2244 inq->p.cmd.dseg_0_address[1] = cpu_to_le32(
2245 MSD(inq_dma + sizeof(sts_entry_t)));
2246 inq->p.cmd.dseg_0_length =
2247 __constant_cpu_to_le32(INQ_DATA_SIZE);
2249 DEBUG5(printk("scsi(%ld): Lun Inquiry - fcport=[%04x/%p],"
2251 ha->host_no, fcport->loop_id, fcport, lun));
2253 rval = qla2x00_issue_iocb(ha, inq, inq_dma,
2254 sizeof(inq_cmd_rsp_t));
2256 comp_status = le16_to_cpu(inq->p.rsp.comp_status);
2257 scsi_status = le16_to_cpu(inq->p.rsp.scsi_status);
2259 DEBUG5(printk("scsi(%ld): lun (%d) inquiry - "
2260 "inq[0]= 0x%x, comp status 0x%x, scsi status 0x%x, "
2262 ha->host_no, lun, inq->inq[0], comp_status, scsi_status,
2265 if (rval != QLA_SUCCESS || comp_status != CS_COMPLETE ||
2266 scsi_status & SS_CHECK_CONDITION) {
2268 DEBUG(printk("scsi(%ld): INQ failed to issue iocb! "
2269 "fcport=[%04x/%p] rval=%x cs=%x ss=%x\n",
2270 ha->host_no, fcport->loop_id, fcport, rval,
2271 comp_status, scsi_status));
2273 if (rval == QLA_SUCCESS)
2274 rval = QLA_FUNCTION_FAILED;
2276 if (scsi_status & SS_CHECK_CONDITION) {
2277 DEBUG2(printk("scsi(%ld): INQ "
2278 "SS_CHECK_CONDITION Sense Data "
2279 "%02x %02x %02x %02x %02x %02x %02x %02x\n",
2281 inq->p.rsp.req_sense_data[0],
2282 inq->p.rsp.req_sense_data[1],
2283 inq->p.rsp.req_sense_data[2],
2284 inq->p.rsp.req_sense_data[3],
2285 inq->p.rsp.req_sense_data[4],
2286 inq->p.rsp.req_sense_data[5],
2287 inq->p.rsp.req_sense_data[6],
2288 inq->p.rsp.req_sense_data[7]));
2291 /* Device underrun drop LUN. */
2292 if (comp_status == CS_DATA_UNDERRUN &&
2293 scsi_status & SS_RESIDUAL_UNDER) {
2306 * qla2x00_configure_fabric
2307 * Setup SNS devices with loop ID's.
2310 * ha = adapter block pointer.
2317 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2320 fc_port_t *fcport, *fcptemp;
2321 uint16_t next_loopid;
2322 uint16_t mb[MAILBOX_REGISTER_COUNT];
2323 LIST_HEAD(new_fcports);
2325 /* If FL port exists, then SNS is present */
2326 rval = qla2x00_get_port_name(ha, SNS_FL_PORT, NULL, 0);
2327 if (rval != QLA_SUCCESS) {
2328 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2329 "Port\n", ha->host_no));
2331 ha->device_flags &= ~SWITCH_FOUND;
2332 return (QLA_SUCCESS);
2335 /* Mark devices that need re-synchronization. */
2336 rval2 = qla2x00_device_resync(ha);
2337 if (rval2 == QLA_RSCNS_HANDLED) {
2338 /* No point doing the scan, just continue. */
2339 return (QLA_SUCCESS);
2342 /* Ensure we are logged into the SNS. */
2343 qla2x00_login_fabric(ha, SIMPLE_NAME_SERVER, 0xff, 0xff, 0xfc,
2345 if (mb[0] != MBS_COMMAND_COMPLETE) {
2346 DEBUG2(qla_printk(KERN_INFO, ha,
2347 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2348 "mb[2]=%x mb[6]=%x mb[7]=%x\n", SIMPLE_NAME_SERVER,
2349 mb[0], mb[1], mb[2], mb[6], mb[7]));
2350 return (QLA_SUCCESS);
2353 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2354 if (qla2x00_rft_id(ha)) {
2356 DEBUG2(printk("scsi(%ld): Register FC-4 "
2357 "TYPE failed.\n", ha->host_no));
2359 if (qla2x00_rff_id(ha)) {
2361 DEBUG2(printk("scsi(%ld): Register FC-4 "
2362 "Features failed.\n", ha->host_no));
2364 if (qla2x00_rnn_id(ha)) {
2366 DEBUG2(printk("scsi(%ld): Register Node Name "
2367 "failed.\n", ha->host_no));
2368 } else if (qla2x00_rsnn_nn(ha)) {
2370 DEBUG2(printk("scsi(%ld): Register Symbolic "
2371 "Node Name failed.\n", ha->host_no));
2375 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2376 if (rval != QLA_SUCCESS)
2380 * Logout all previous fabric devices marked lost, except
2383 list_for_each_entry(fcport, &ha->fcports, list) {
2384 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2387 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2390 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2391 qla2x00_mark_device_lost(ha, fcport,
2392 ql2xplogiabsentdevice);
2393 if (fcport->loop_id != FC_NO_LOOP_ID &&
2394 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2395 fcport->port_type != FCT_INITIATOR &&
2396 fcport->port_type != FCT_BROADCAST) {
2398 qla2x00_fabric_logout(ha,
2400 fcport->loop_id = FC_NO_LOOP_ID;
2405 /* Starting free loop ID. */
2406 next_loopid = ha->min_external_loopid;
2409 * Scan through our port list and login entries that need to be
2412 list_for_each_entry(fcport, &ha->fcports, list) {
2413 if (atomic_read(&ha->loop_down_timer) ||
2414 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2417 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2418 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2421 if (fcport->loop_id == FC_NO_LOOP_ID) {
2422 fcport->loop_id = next_loopid;
2423 rval = qla2x00_find_new_loop_id(ha, fcport);
2424 if (rval != QLA_SUCCESS) {
2425 /* Ran out of IDs to use */
2430 /* Login and update database */
2431 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2434 /* Exit if out of loop IDs. */
2435 if (rval != QLA_SUCCESS) {
2440 * Login and add the new devices to our port list.
2442 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2443 if (atomic_read(&ha->loop_down_timer) ||
2444 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2447 /* Find a new loop ID to use. */
2448 fcport->loop_id = next_loopid;
2449 rval = qla2x00_find_new_loop_id(ha, fcport);
2450 if (rval != QLA_SUCCESS) {
2451 /* Ran out of IDs to use */
2455 /* Login and update database */
2456 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2458 /* Remove device from the new list and add it to DB */
2459 list_del(&fcport->list);
2460 list_add_tail(&fcport->list, &ha->fcports);
2464 /* Free all new device structures not processed. */
2465 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2466 list_del(&fcport->list);
2471 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2472 "rval=%d\n", ha->host_no, rval));
2480 * qla2x00_find_all_fabric_devs
2483 * ha = adapter block pointer.
2484 * dev = database device entry pointer.
2493 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2497 fc_port_t *fcport, *new_fcport;
2502 int first_dev, last_dev;
2503 port_id_t wrap, nxt_d_id;
2507 /* Try GID_PT to get device list, else GAN. */
2508 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2511 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2512 "on GA_NXT\n", ha->host_no));
2514 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2515 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2518 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2521 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2528 /* Allocate temporary fcport for any new fcports discovered. */
2529 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2530 if (new_fcport == NULL) {
2533 return (QLA_MEMORY_ALLOC_FAILED);
2535 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2537 /* Set start port ID scan at adapter ID. */
2541 /* Starting free loop ID. */
2542 loop_id = ha->min_external_loopid;
2544 for (; loop_id <= ha->last_loop_id; loop_id++) {
2545 if (RESERVED_LOOP_ID(loop_id))
2548 if (atomic_read(&ha->loop_down_timer) ||
2549 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2554 wrap.b24 = new_fcport->d_id.b24;
2556 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2557 memcpy(new_fcport->node_name,
2558 swl[swl_idx].node_name, WWN_SIZE);
2559 memcpy(new_fcport->port_name,
2560 swl[swl_idx].port_name, WWN_SIZE);
2562 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2568 /* Send GA_NXT to the switch */
2569 rval = qla2x00_ga_nxt(ha, new_fcport);
2570 if (rval != QLA_SUCCESS) {
2575 /* If wrap on switch device list, exit. */
2577 wrap.b24 = new_fcport->d_id.b24;
2579 } else if (new_fcport->d_id.b24 == wrap.b24) {
2580 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2581 ha->host_no, new_fcport->d_id.b.domain,
2582 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2586 /* Bypass if host adapter. */
2587 if (new_fcport->d_id.b24 == ha->d_id.b24)
2590 /* Bypass reserved domain fields. */
2591 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2594 /* Locate matching device in database. */
2596 list_for_each_entry(fcport, &ha->fcports, list) {
2597 if (memcmp(new_fcport->port_name, fcport->port_name,
2604 * If address the same and state FCS_ONLINE, nothing
2607 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2608 atomic_read(&fcport->state) == FCS_ONLINE) {
2613 * If device was not a fabric device before.
2615 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2616 fcport->d_id.b24 = new_fcport->d_id.b24;
2617 fcport->loop_id = FC_NO_LOOP_ID;
2618 fcport->flags |= (FCF_FABRIC_DEVICE |
2620 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2625 * Port ID changed or device was marked to be updated;
2626 * Log it out if still logged in and mark it for
2629 fcport->d_id.b24 = new_fcport->d_id.b24;
2630 fcport->flags |= FCF_LOGIN_NEEDED;
2631 if (fcport->loop_id != FC_NO_LOOP_ID &&
2632 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2633 fcport->port_type != FCT_INITIATOR &&
2634 fcport->port_type != FCT_BROADCAST) {
2635 qla2x00_fabric_logout(ha, fcport->loop_id);
2636 fcport->loop_id = FC_NO_LOOP_ID;
2645 /* If device was not in our fcports list, then add it. */
2646 list_add_tail(&new_fcport->list, new_fcports);
2648 /* Allocate a new replacement fcport. */
2649 nxt_d_id.b24 = new_fcport->d_id.b24;
2650 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2651 if (new_fcport == NULL) {
2654 return (QLA_MEMORY_ALLOC_FAILED);
2656 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2657 new_fcport->d_id.b24 = nxt_d_id.b24;
2666 if (!list_empty(new_fcports))
2667 ha->device_flags |= DFLG_FABRIC_DEVICES;
2673 * qla2x00_find_new_loop_id
2674 * Scan through our port list and find a new usable loop ID.
2677 * ha: adapter state pointer.
2678 * dev: port structure pointer.
2681 * qla2x00 local function return status code.
2687 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2692 uint16_t first_loop_id;
2696 /* Save starting loop ID. */
2697 first_loop_id = dev->loop_id;
2700 /* Skip loop ID if already used by adapter. */
2701 if (dev->loop_id == ha->loop_id) {
2705 /* Skip reserved loop IDs. */
2706 while (RESERVED_LOOP_ID(dev->loop_id)) {
2710 /* Reset loop ID if passed the end. */
2711 if (dev->loop_id > ha->last_loop_id) {
2712 /* first loop ID. */
2713 dev->loop_id = ha->min_external_loopid;
2716 /* Check for loop ID being already in use. */
2719 list_for_each_entry(fcport, &ha->fcports, list) {
2720 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2721 /* ID possibly in use */
2727 /* If not in use then it is free to use. */
2732 /* ID in use. Try next value. */
2735 /* If wrap around. No free ID to use. */
2736 if (dev->loop_id == first_loop_id) {
2737 dev->loop_id = FC_NO_LOOP_ID;
2738 rval = QLA_FUNCTION_FAILED;
2747 * qla2x00_device_resync
2748 * Marks devices in the database that needs resynchronization.
2751 * ha = adapter block pointer.
2757 qla2x00_device_resync(scsi_qla_host_t *ha)
2763 uint32_t rscn_entry;
2764 uint8_t rscn_out_iter;
2768 rval = QLA_RSCNS_HANDLED;
2770 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2771 ha->flags.rscn_queue_overflow) {
2773 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2774 format = MSB(MSW(rscn_entry));
2775 d_id.b.domain = LSB(MSW(rscn_entry));
2776 d_id.b.area = MSB(LSW(rscn_entry));
2777 d_id.b.al_pa = LSB(LSW(rscn_entry));
2779 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2780 "[%02x/%02x%02x%02x].\n",
2781 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2782 d_id.b.area, d_id.b.al_pa));
2785 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2786 ha->rscn_out_ptr = 0;
2788 /* Skip duplicate entries. */
2789 for (rscn_out_iter = ha->rscn_out_ptr;
2790 !ha->flags.rscn_queue_overflow &&
2791 rscn_out_iter != ha->rscn_in_ptr;
2792 rscn_out_iter = (rscn_out_iter ==
2793 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2795 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2798 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2799 "entry found at [%d].\n", ha->host_no,
2802 ha->rscn_out_ptr = rscn_out_iter;
2805 /* Queue overflow, set switch default case. */
2806 if (ha->flags.rscn_queue_overflow) {
2807 DEBUG(printk("scsi(%ld): device_resync: rscn "
2808 "overflow.\n", ha->host_no));
2811 ha->flags.rscn_queue_overflow = 0;
2816 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) &&
2817 !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
2818 ha->flags.init_done) {
2819 /* Handle port RSCN via asyncronous IOCBs */
2820 rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
2822 if (rval2 == QLA_SUCCESS)
2836 ha->rscn_out_ptr = ha->rscn_in_ptr;
2842 /* Abort any outstanding IO descriptors. */
2843 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2844 qla2x00_cancel_io_descriptors(ha);
2846 list_for_each_entry(fcport, &ha->fcports, list) {
2847 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2848 (fcport->d_id.b24 & mask) != d_id.b24 ||
2849 fcport->port_type == FCT_BROADCAST)
2852 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2854 fcport->port_type != FCT_INITIATOR) {
2855 atomic_set(&fcport->state,
2859 fcport->flags &= ~FCF_FARP_DONE;
2866 * qla2x00_fabric_dev_login
2867 * Login fabric target device and update FC port database.
2870 * ha: adapter state pointer.
2871 * fcport: port structure list pointer.
2872 * next_loopid: contains value of a new loop ID that can be used
2873 * by the next login attempt.
2876 * qla2x00 local function return status code.
2882 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2883 uint16_t *next_loopid)
2891 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2892 if (rval == QLA_SUCCESS) {
2893 rval = qla2x00_get_port_database(ha, fcport, 0);
2894 if (rval != QLA_SUCCESS) {
2895 qla2x00_fabric_logout(ha, fcport->loop_id);
2897 qla2x00_update_fcport(ha, fcport);
2905 * qla2x00_fabric_login
2906 * Issue fabric login command.
2909 * ha = adapter block pointer.
2910 * device = pointer to FC device type structure.
2913 * 0 - Login successfully
2915 * 2 - Initiator device
2919 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2920 uint16_t *next_loopid)
2924 uint16_t tmp_loopid;
2925 uint16_t mb[MAILBOX_REGISTER_COUNT];
2931 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2932 "for port %02x%02x%02x.\n",
2933 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2934 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2936 /* Login fcport on switch. */
2937 qla2x00_login_fabric(ha, fcport->loop_id,
2938 fcport->d_id.b.domain, fcport->d_id.b.area,
2939 fcport->d_id.b.al_pa, mb, BIT_0);
2940 if (mb[0] == MBS_PORT_ID_USED) {
2942 * Device has another loop ID. The firmware team
2943 * recommends us to perform an implicit login with the
2944 * specified ID again. The ID we just used is save here
2945 * so we return with an ID that can be tried by the
2949 tmp_loopid = fcport->loop_id;
2950 fcport->loop_id = mb[1];
2952 DEBUG(printk("Fabric Login: port in use - next "
2953 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2954 fcport->loop_id, fcport->d_id.b.domain,
2955 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2957 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2962 /* A retry occurred before. */
2963 *next_loopid = tmp_loopid;
2966 * No retry occurred before. Just increment the
2967 * ID value for next login.
2969 *next_loopid = (fcport->loop_id + 1);
2972 if (mb[1] & BIT_0) {
2973 fcport->port_type = FCT_INITIATOR;
2975 fcport->port_type = FCT_TARGET;
2976 if (mb[1] & BIT_1) {
2977 fcport->flags |= FCF_TAPE_PRESENT;
2983 } else if (mb[0] == MBS_LOOP_ID_USED) {
2985 * Loop ID already used, try next loop ID.
2988 rval = qla2x00_find_new_loop_id(ha, fcport);
2989 if (rval != QLA_SUCCESS) {
2990 /* Ran out of loop IDs to use */
2993 } else if (mb[0] == MBS_COMMAND_ERROR) {
2995 * Firmware possibly timed out during login. If NO
2996 * retries are left to do then the device is declared
2999 *next_loopid = fcport->loop_id;
3000 qla2x00_fabric_logout(ha, fcport->loop_id);
3001 fcport->loop_id = FC_NO_LOOP_ID;
3007 * unrecoverable / not handled error
3009 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3010 "loop_id=%x jiffies=%lx.\n",
3011 __func__, ha->host_no, mb[0],
3012 fcport->d_id.b.domain, fcport->d_id.b.area,
3013 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3015 *next_loopid = fcport->loop_id;
3016 qla2x00_fabric_logout(ha, fcport->loop_id);
3017 fcport->loop_id = FC_NO_LOOP_ID;
3018 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
3029 * qla2x00_local_device_login
3030 * Issue local device login command.
3033 * ha = adapter block pointer.
3034 * loop_id = loop id of device to login to.
3036 * Returns (Where's the #define!!!!):
3037 * 0 - Login successfully
3042 qla2x00_local_device_login(scsi_qla_host_t *ha, uint16_t loop_id)
3045 uint16_t mb[MAILBOX_REGISTER_COUNT];
3047 memset(mb, 0, sizeof(mb));
3048 rval = qla2x00_login_local_device(ha, loop_id, mb, BIT_0);
3049 if (rval == QLA_SUCCESS) {
3050 /* Interrogate mailbox registers for any errors */
3051 if (mb[0] == MBS_COMMAND_ERROR)
3053 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3054 /* device not in PCB table */
3062 * qla2x00_loop_resync
3063 * Resync with fibre channel devices.
3066 * ha = adapter block pointer.
3072 qla2x00_loop_resync(scsi_qla_host_t *ha)
3079 atomic_set(&ha->loop_state, LOOP_UPDATE);
3080 qla2x00_stats.loop_resync++;
3081 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3082 if (ha->flags.online) {
3083 if (!(rval = qla2x00_fw_ready(ha))) {
3084 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3088 atomic_set(&ha->loop_state, LOOP_UPDATE);
3091 * Issue marker command only when we are going
3092 * to start the I/O .
3094 ha->marker_needed = 1;
3096 /* Remap devices on Loop. */
3097 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3099 qla2x00_configure_loop(ha);
3101 } while (!atomic_read(&ha->loop_down_timer) &&
3102 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3104 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3106 qla2x00_restart_queues(ha, 1);
3109 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3110 return (QLA_FUNCTION_FAILED);
3114 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3121 * qla2x00_restart_queues
3122 * Restart device queues.
3125 * ha = adapter block pointer.
3128 * Kernel/Interrupt context.
3131 qla2x00_restart_queues(scsi_qla_host_t *ha, uint8_t flush)
3134 int retry_q_cnt = 0;
3135 int pending_q_cnt = 0;
3136 struct list_head *list, *temp;
3137 unsigned long flags = 0;
3139 clear_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
3141 /* start pending queue */
3142 pending_q_cnt = ha->qthreads;
3144 spin_lock_irqsave(&ha->list_lock,flags);
3145 list_for_each_safe(list, temp, &ha->pending_queue) {
3146 sp = list_entry(list, srb_t, list);
3148 if ((sp->flags & SRB_TAPE))
3152 * When time expire return request back to OS as BUSY
3154 __del_from_pending_queue(ha, sp);
3155 sp->cmd->result = DID_BUS_BUSY << 16;
3156 sp->cmd->host_scribble = (unsigned char *)NULL;
3157 __add_to_done_queue(ha, sp);
3159 spin_unlock_irqrestore(&ha->list_lock, flags);
3161 if (!list_empty(&ha->pending_queue))
3166 * Clear out our retry queue
3169 spin_lock_irqsave(&ha->list_lock, flags);
3170 retry_q_cnt = ha->retry_q_cnt;
3171 list_for_each_safe(list, temp, &ha->retry_queue) {
3172 sp = list_entry(list, srb_t, list);
3173 /* when time expire return request back to OS as BUSY */
3174 __del_from_retry_queue(ha, sp);
3175 sp->cmd->result = DID_BUS_BUSY << 16;
3176 sp->cmd->host_scribble = (unsigned char *)NULL;
3177 __add_to_done_queue(ha, sp);
3179 spin_unlock_irqrestore(&ha->list_lock, flags);
3181 DEBUG2(printk("%s(%ld): callback %d commands.\n",
3187 DEBUG2(printk("%s(%ld): active=%ld, retry=%d, pending=%d, "
3188 "done=%ld, scsi retry=%d commands.\n",
3195 ha->scsi_retry_q_cnt);)
3197 if (!list_empty(&ha->done_queue))
3202 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
3208 list_for_each_entry(fcport, &ha->fcports, list) {
3209 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
3212 qla2x00_update_fcport(ha, fcport);
3213 fcport->flags &= ~FCF_RESCAN_NEEDED;
3217 qla2x00_probe_for_all_luns(ha);
3219 /* Update OS target and lun structures if necessary. */
3221 qla2x00_config_os(ha);
3228 * Setup OS target and LUN structures.
3231 * ha = adapter state pointer.
3237 qla2x00_config_os(scsi_qla_host_t *ha)
3245 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
3246 if ((tq = TGT_Q(ha, tgt)) == NULL)
3249 clear_bit(TQF_ONLINE, &tq->flags);
3252 list_for_each_entry(fcport, &ha->fcports, list) {
3253 if (atomic_read(&fcport->state) != FCS_ONLINE ||
3254 fcport->port_type == FCT_INITIATOR ||
3255 fcport->port_type == FCT_BROADCAST) {
3256 fcport->os_target_id = MAX_TARGETS;
3260 if (fcport->flags & FCF_FO_MASKED) {
3264 /* Bind FC port to OS target number. */
3265 if (qla2x00_fcport_bind(ha, fcport) == MAX_TARGETS) {
3269 /* Bind FC LUN to OS LUN number. */
3270 list_for_each_entry(fclun, &fcport->fcluns, list) {
3271 qla2x00_fclun_bind(ha, fcport, fclun);
3277 * qla2x00_fcport_bind
3278 * Locates a target number for FC port.
3281 * ha = adapter state pointer.
3282 * fcport = FC port structure pointer.
3291 qla2x00_fcport_bind(scsi_qla_host_t *ha, fc_port_t *fcport)
3297 /* Check for persistent binding. */
3298 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
3299 if ((tq = TGT_Q(ha, tgt)) == NULL)
3303 switch (ha->binding_type) {
3304 case BIND_BY_PORT_ID:
3305 if (fcport->d_id.b24 == tq->d_id.b24) {
3306 memcpy(tq->node_name, fcport->node_name,
3308 memcpy(tq->port_name, fcport->port_name,
3313 case BIND_BY_PORT_NAME:
3314 if (memcmp(fcport->port_name, tq->port_name,
3317 * In case of persistent binding, update the
3320 memcpy(tq->node_name, fcport->node_name,
3330 /* TODO: honor the ConfigRequired flag */
3331 if (tgt == MAX_TARGETS) {
3332 /* Check if targetID 0 available. */
3335 if (TGT_Q(ha, tgt) != NULL) {
3336 /* Locate first free target for device. */
3337 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
3338 if (TGT_Q(ha, tgt) == NULL) {
3343 if (tgt != MAX_TARGETS) {
3344 if ((tq = qla2x00_tgt_alloc(ha, tgt)) != NULL) {
3345 memcpy(tq->node_name, fcport->node_name,
3347 memcpy(tq->port_name, fcport->port_name,
3349 tq->d_id.b24 = fcport->d_id.b24;
3354 /* Reset target numbers incase it changed. */
3355 fcport->os_target_id = tgt;
3356 if (tgt != MAX_TARGETS && tq != NULL) {
3357 DEBUG2(printk("scsi(%ld): Assigning target ID=%02d @ %p to "
3358 "loop id=0x%04x, port state=0x%x, port down retry=%d\n",
3359 ha->host_no, tgt, tq, fcport->loop_id,
3360 atomic_read(&fcport->state),
3361 atomic_read(&fcport->port_down_timer)));
3363 fcport->tgt_queue = tq;
3364 fcport->flags |= FCF_PERSISTENT_BOUND;
3365 tq->fcport = fcport;
3366 set_bit(TQF_ONLINE, &tq->flags);
3367 tq->port_down_retry_count = ha->port_down_retry_count;
3370 qla2x00_get_lun_mask_from_config(ha, fcport, tgt, 0);
3374 if (tgt == MAX_TARGETS) {
3375 qla_printk(KERN_WARNING, ha,
3376 "Unable to bind fcport, loop_id=%x\n", fcport->loop_id);
3383 * qla2x00_fclun_bind
3384 * Binds all FC device LUNS to OS LUNS.
3387 * ha: adapter state pointer.
3388 * fcport: FC port structure pointer.
3397 qla2x00_fclun_bind(scsi_qla_host_t *ha, fc_port_t *fcport, fc_lun_t *fclun)
3403 tgt = fcport->os_target_id;
3407 if (lun >= MAX_LUNS) {
3408 DEBUG2(printk("scsi(%ld): Unable to bind lun, invalid "
3409 "lun=(%x).\n", ha->host_no, lun));
3413 /* Always alloc LUN 0 so kernel will scan past LUN 0. */
3414 if (lun != 0 && (EXT_IS_LUN_BIT_SET(&(fcport->lun_mask), lun))) {
3418 if ((lq = qla2x00_lun_alloc(ha, tgt, lun)) == NULL) {
3419 qla_printk(KERN_WARNING, ha,
3420 "Unable to bind fclun, loop_id=%x lun=%x\n",
3421 fcport->loop_id, lun);
3432 * Allocate and pre-initialize target queue.
3435 * ha = adapter block pointer.
3436 * t = SCSI target number.
3445 qla2x00_tgt_alloc(scsi_qla_host_t *ha, uint16_t tgt)
3450 * If SCSI addressing OK, allocate TGT queue and lock.
3452 if (tgt >= MAX_TARGETS) {
3453 DEBUG2(printk("scsi(%ld): Unable to allocate target, invalid "
3454 "target number %d.\n", ha->host_no, tgt));
3458 tq = TGT_Q(ha, tgt);
3460 tq = kmalloc(sizeof(os_tgt_t), GFP_ATOMIC);
3462 DEBUG2(printk("scsi(%ld): Alloc Target %d @ %p\n",
3463 ha->host_no, tgt, tq));
3465 memset(tq, 0, sizeof(os_tgt_t));
3468 TGT_Q(ha, tgt) = tq;
3472 tq->port_down_retry_count = ha->port_down_retry_count;
3474 qla_printk(KERN_WARNING, ha,
3475 "Unable to allocate target.\n");
3484 * Frees target and LUN queues.
3487 * ha = adapter block pointer.
3488 * t = SCSI target number.
3494 qla2x00_tgt_free(scsi_qla_host_t *ha, uint16_t tgt)
3500 * If SCSI addressing OK, allocate TGT queue and lock.
3502 if (tgt >= MAX_TARGETS) {
3503 DEBUG2(printk("scsi(%ld): Unable to de-allocate target, "
3504 "invalid target number %d.\n", ha->host_no, tgt));
3509 tq = TGT_Q(ha, tgt);
3511 TGT_Q(ha, tgt) = NULL;
3513 /* Free LUN structures. */
3514 for (lun = 0; lun < MAX_LUNS; lun++)
3515 qla2x00_lun_free(ha, tgt, lun);
3525 * Allocate and initialize LUN queue.
3528 * ha = adapter block pointer.
3529 * t = SCSI target number.
3539 qla2x00_lun_alloc(scsi_qla_host_t *ha, uint16_t tgt, uint16_t lun)
3544 * If SCSI addressing OK, allocate LUN queue.
3546 if (tgt >= MAX_TARGETS || lun >= MAX_LUNS || TGT_Q(ha, tgt) == NULL) {
3547 DEBUG2(printk("scsi(%ld): Unable to allocate lun, invalid "
3548 "parameter.\n", ha->host_no));
3553 lq = LUN_Q(ha, tgt, lun);
3555 lq = kmalloc(sizeof(os_lun_t), GFP_ATOMIC);
3557 DEBUG2(printk("scsi(%ld): Alloc Lun %d @ tgt %d.\n",
3558 ha->host_no, lun, tgt));
3560 memset(lq, 0, sizeof (os_lun_t));
3561 LUN_Q(ha, tgt, lun) = lq;
3564 * The following lun queue initialization code
3565 * must be duplicated in alloc_ioctl_mem function
3568 lq->q_state = LUN_STATE_READY;
3569 spin_lock_init(&lq->q_lock);
3574 qla_printk(KERN_WARNING, ha, "Unable to allocate lun.\n");
3585 * ha = adapter block pointer.
3586 * t = SCSI target number.
3592 qla2x00_lun_free(scsi_qla_host_t *ha, uint16_t tgt, uint16_t lun)
3597 * If SCSI addressing OK, allocate TGT queue and lock.
3599 if (tgt >= MAX_TARGETS || lun >= MAX_LUNS) {
3600 DEBUG2(printk("scsi(%ld): Unable to deallocate lun, invalid "
3601 "parameter.\n", ha->host_no));
3606 if (TGT_Q(ha, tgt) != NULL && (lq = LUN_Q(ha, tgt, lun)) != NULL) {
3607 LUN_Q(ha, tgt, lun) = NULL;
3617 * qla2x00_get_lun_mask_from_config
3618 * Get lun mask from the configuration parameters.
3619 * Bit order is little endian.
3622 * ha -- Host adapter
3623 * tgt -- target/device number
3624 * port -- pointer to port
3627 qla2x00_get_lun_mask_from_config(scsi_qla_host_t *ha,
3628 fc_port_t *fcport, uint16_t tgt, uint16_t dev_no)
3630 char propbuf[60]; /* size of search string */
3632 lun_bit_mask_t lun_mask, *mask_ptr = &lun_mask;
3634 /* Get "target-N-device-N-lun-mask" as a 256 bit lun_mask*/
3635 sprintf(propbuf, "scsi-qla%ld-tgt-%d-di-%d-lun-disabled",
3636 ha->instance, tgt, dev_no);
3638 rval = qla2x00_get_prop_xstr(ha, propbuf,
3639 (uint8_t *)&lun_mask, sizeof(lun_bit_mask_t));
3640 if (rval == sizeof(lun_bit_mask_t)) {
3641 memset(&fcport->lun_mask, 0, sizeof(lun_bit_mask_t));
3642 for (lun = 8 * sizeof(lun_bit_mask_t) - 1, bit = 0;
3643 lun >= 0; lun--, bit++) {
3644 if (EXT_IS_LUN_BIT_SET(mask_ptr, lun))
3645 EXT_SET_LUN_BIT((&fcport->lun_mask), bit);
3648 DEBUG3(printk("scsi(%ld): returning lun mask for fcport "
3649 "%02x%02x%02x%02x%02x%02x%02x%02x:\n",
3651 fcport->port_name[0], fcport->port_name[1],
3652 fcport->port_name[2], fcport->port_name[3],
3653 fcport->port_name[4], fcport->port_name[5],
3654 fcport->port_name[6], fcport->port_name[7]));
3655 DEBUG3(qla2x00_dump_buffer((uint8_t *)&fcport->lun_mask,
3656 sizeof(lun_bit_mask_t));)
3662 * qla2x00_bstr_to_hex
3663 * Convert hex byte string to number.
3666 * s = byte string pointer.
3667 * bp = byte pointer for number.
3668 * size = number of bytes.
3671 * Kernel/Interrupt context.
3674 qla2x00_bstr_to_hex(char *s, uint8_t *bp, int size)
3679 for (cnt = 0; *s != '\0' && cnt / 2 < size; cnt++) {
3680 if (*s >= 'A' && *s <= 'F') {
3681 n = (*s++ - 'A') + 10;
3682 } else if (*s >= 'a' && *s <= 'f') {
3683 n = (*s++ - 'a') + 10;
3684 } else if (*s >= '0' && *s <= '9') {
3697 /* fixme(dg) Need to swap data little endian */
3703 * qla2x00_get_prop_xstr
3704 * Get a string property value for the specified property name and
3705 * convert from the property string found in the configuration file,
3706 * which are ASCII characters representing nibbles, 2 characters represent
3707 * the hexdecimal value for a byte in the byte array.
3708 * The byte array is initialized to zero.
3709 * The resulting converted value is in big endian format (MSB at byte0).
3712 * ha = adapter state pointer.
3713 * propname = property name pointer.
3714 * propval = pointer where to store converted property val.
3715 * size = max or expected size of 'propval' array.
3718 * 0 = empty value string or invalid character in string
3719 * >0 = count of characters converted
3720 * -1 = property not found
3726 qla2x00_get_prop_xstr(scsi_qla_host_t *ha,
3727 char *propname, uint8_t *propval, int size)
3731 static char buf[LINESIZE];
3733 /* Get the requested property string */
3734 rval = qla2x00_find_propname(ha, propname, buf, ha->cmdline, size*2);
3735 DEBUG3(printk("%s(): Ret rval from find propname = %d\n",
3740 if (*propstr == '=')
3741 propstr++; /* ignore equal sign */
3743 if (rval == 0) { /* not found */
3747 rval = qla2x00_bstr_to_hex(propstr, (uint8_t *)propval, size);
3749 /* Invalid character in value string */
3750 qla_printk(KERN_INFO, ha,
3751 "%s(): %s Invalid hex string for property\n",
3754 qla_printk(KERN_INFO, ha,
3755 " Invalid string - %s\n",
3763 * qla2x00_find_propname
3764 * Get property in database.
3767 * ha = adapter structure pointer.
3768 * db = pointer to database
3769 * propstr = pointer to dest array for string
3770 * propname = name of property to search for.
3771 * siz = size of property
3775 * size = index of property
3781 qla2x00_find_propname(scsi_qla_host_t *ha,
3782 char *propname, char *propstr,
3787 /* find the specified string */
3789 /* find the property name */
3790 if ((cp = strstr(db,propname)) != NULL) {
3791 while ((*cp) && *cp != '=')
3794 strncpy(propstr, cp, siz+1);
3795 propstr[siz+1] = '\0';
3796 DEBUG(printk("qla2x00_find_propname: found "
3797 "property = {%s}\n",
3799 return (siz); /* match */
3809 * qla2x00_get_prop_16chars
3810 * Get an 8-byte property value for the specified property name by
3811 * converting from the property string found in the configuration file.
3812 * The resulting converted value is in big endian format (MSB at byte0).
3815 * ha = adapter state pointer.
3816 * propname = property name pointer.
3817 * propval = pointer to location for the converted property val.
3818 * db = pointer to database
3821 * 0 = value returned successfully.
3827 qla2x00_get_prop_16chars(scsi_qla_host_t *ha,
3828 char *propname, char *propval, char *db)
3837 uint8_t *retval = (uint8_t*)propval;
3838 uint8_t tmpval[8] = {0, 0, 0, 0, 0, 0, 0, 0};
3839 uint16_t max_byte_cnt = 8; /* 16 chars = 8 bytes */
3840 uint16_t max_strlen = 16;
3841 static char buf[LINESIZE];
3843 rval = qla2x00_find_propname(ha, propname, buf, db, max_strlen);
3846 if (*propstr == '=')
3847 propstr++; /* ignore equal sign */
3853 /* Convert string to numbers. */
3854 pchar = (uint8_t *)propstr;
3855 tmp_byte = (uint8_t *)tmpval;
3858 for (i = 0; i < max_strlen; i++) {
3860 * Check for invalid character, two at a time,
3861 * then convert them starting with first byte.
3864 if ((pchar[i] >= '0') && (pchar[i] <= '9')) {
3865 nval = pchar[i] - '0';
3866 } else if ((pchar[i] >= 'A') && (pchar[i] <= 'F')) {
3867 nval = pchar[i] - 'A' + 10;
3868 } else if ((pchar[i] >= 'a') && (pchar[i] <= 'f')) {
3869 nval = pchar[i] - 'a' + 10;
3871 /* invalid character */
3877 *tmp_byte = *tmp_byte | nval;
3880 *tmp_byte = *tmp_byte | nval << 4;
3885 /* Encountered invalid character. */
3889 /* Copy over the converted value. */
3896 *ret_byte++ = *tmp_byte++;
3899 /* big endian retval[0]; */
3904 * qla2x00_get_properties
3905 * Find all properties for the specified adapeter in
3909 * ha = adapter block pointer.
3910 * cmdline = pointer to command line string
3916 qla2x00_get_properties(scsi_qla_host_t *ha, char *cmdline)
3919 static char propbuf[LINESIZE];
3922 /* Adapter FC node names. */
3923 sprintf(propbuf, "scsi-qla%d-adapter-node", (int) ha->instance);
3924 rval = qla2x00_get_prop_16chars(ha, propbuf, fc_name, cmdline);
3925 if (rval == QLA_SUCCESS)
3926 memcpy(ha->init_cb->node_name, fc_name, WWN_SIZE);
3928 /* DG 04/07 check portname of adapter */
3929 sprintf(propbuf, "scsi-qla%d-adapter-port", (int)ha->instance);
3930 rval = qla2x00_get_prop_16chars(ha, propbuf, fc_name, cmdline);
3931 if (rval == QLA_SUCCESS &&
3932 memcmp(ha->init_cb->port_name, fc_name, WWN_SIZE)) {
3934 * Adapter port name is WWN, and cannot be changed.
3935 * Inform users of the mismatch, then just continue driver
3936 * loading using the original adapter port name in NVRAM.
3938 qla_printk(KERN_WARNING, ha,
3939 "Found mismatch in adapter port names.\n");
3940 qla_printk(KERN_INFO, ha,
3941 " qla%ld port name found in NVRAM -> "
3942 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
3944 ha->init_cb->port_name[0],
3945 ha->init_cb->port_name[1],
3946 ha->init_cb->port_name[2],
3947 ha->init_cb->port_name[3],
3948 ha->init_cb->port_name[4],
3949 ha->init_cb->port_name[5],
3950 ha->init_cb->port_name[6],
3951 ha->init_cb->port_name[7]);
3952 qla_printk(KERN_INFO, ha,
3953 " qla%ld port name found on command line -> "
3954 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
3956 fc_name[0], fc_name[1], fc_name[2], fc_name[3],
3957 fc_name[4], fc_name[5], fc_name[6], fc_name[7]);
3958 qla_printk(KERN_INFO, ha,
3959 " Using port name from NVRAM.\n");
3962 qla2x00_cfg_persistent_binding(ha);
3966 * qla2x00_cfg_persistent_binding
3967 * Get driver configuration file target persistent binding entries.
3970 * ha = adapter block pointer.
3976 qla2x00_cfg_persistent_binding(scsi_qla_host_t *ha)
3979 static char propbuf[LINESIZE];
3980 char *cmdline = ha->cmdline;
3984 uint8_t port_name[8];
3986 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
3987 if (ha->binding_type == BIND_BY_PORT_ID) {
3988 sprintf(propbuf, "scsi-qla%d-tgt-%d-di-0-pid",
3989 (int)ha->instance, tgt);
3990 rval = qla2x00_get_prop_xstr(ha,
3991 propbuf, portid, sizeof(portid));
3992 if (rval != sizeof(portid))
3995 memset(&d_id, 0, sizeof(port_id_t));
3996 d_id.r.d_id[0] = portid[2];
3997 d_id.r.d_id[1] = portid[1];
3998 d_id.r.d_id[2] = portid[0];
4000 sprintf(propbuf, "scsi-qla%d-tgt-%d-di-0-port",
4001 (int)ha->instance, tgt);
4002 rval = qla2x00_get_prop_16chars(ha,
4003 propbuf, port_name, cmdline);
4004 if (rval != QLA_SUCCESS)
4007 /* Fallthru since port_name already populated */
4011 * Create target context for device.
4013 if (ha->binding_type == BIND_BY_PORT_ID) {
4014 qla2x00_persistent_bind(ha, NULL, NULL, &d_id, tgt);
4016 qla2x00_persistent_bind(ha, NULL, port_name, NULL, tgt);
4022 * qla2x00_persistent_bind
4023 * Allocates target and fcport.
4026 * ha: adapter state pointer.
4027 * node_name: node name pointer.
4028 * port_name: port name pointer.
4029 * d_id: port ID pointer.
4030 * tgt: OS target number.
4033 * success = target queue pointer.
4040 qla2x00_persistent_bind(scsi_qla_host_t *ha, uint8_t *node_name,
4041 uint8_t *port_name, port_id_t *d_id, uint16_t tgt)
4047 * Check for duplicates.
4049 for (tgt2 = 0; tgt2 < MAX_TARGETS; tgt2++) {
4050 if ((tq = TGT_Q(ha, tgt2)) == NULL) {
4054 if (ha->binding_type == BIND_BY_PORT_ID) {
4055 if (tq->d_id.b24 != d_id->b24) {
4058 } else if (memcmp(tq->port_name, port_name, WWN_SIZE) != 0) {
4062 qla_printk(KERN_WARNING, ha,
4063 "Duplicate persistent bindings found for "
4064 "WWPN: %02x%02x%02x%02x%02x%02x%02x%02x.\n",
4065 port_name[0], port_name[1], port_name[2], port_name[3],
4066 port_name[4], port_name[5], port_name[6], port_name[7]);
4071 tq = qla2x00_tgt_alloc(ha, tgt);
4076 if (node_name != NULL) {
4077 memcpy(tq->node_name, node_name, WWN_SIZE);
4079 if (port_name != NULL) {
4080 memcpy(tq->port_name, port_name, WWN_SIZE);
4083 tq->d_id.b24 = d_id->b24;
4092 * Resets ISP and aborts all outstanding commands.
4095 * ha = adapter block pointer.
4101 qla2x00_abort_isp(scsi_qla_host_t *ha)
4103 unsigned long flags = 0;
4108 if (ha->flags.online) {
4109 ha->flags.online = 0;
4110 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
4111 qla2x00_stats.ispAbort++;
4112 ha->total_isp_aborts++; /* used by ioctl */
4113 ha->sns_retry_cnt = 0;
4115 qla_printk(KERN_INFO, ha,
4116 "Performing ISP error recovery - ha= %p.\n", ha);
4117 qla2x00_reset_chip(ha);
4119 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
4120 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
4121 atomic_set(&ha->loop_state, LOOP_DOWN);
4122 qla2x00_mark_all_devices_lost(ha);
4124 if (!atomic_read(&ha->loop_down_timer))
4125 atomic_set(&ha->loop_down_timer,
4129 spin_lock_irqsave(&ha->hardware_lock, flags);
4130 /* Requeue all commands in outstanding command list. */
4131 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
4132 sp = ha->outstanding_cmds[cnt];
4134 ha->outstanding_cmds[cnt] = NULL;
4137 sp->lun_queue->out_cnt--;
4140 * Set the cmd host_byte status depending on
4141 * whether the scsi_error_handler is
4144 if (sp->flags & SRB_TAPE) {
4145 sp->cmd->result = DID_NO_CONNECT << 16;
4147 if (ha->host->eh_active != EH_ACTIVE)
4155 sp->cmd->host_scribble = (unsigned char *)NULL;
4156 add_to_done_queue(ha, sp);
4159 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4161 qla2x00_nvram_config(ha);
4163 if (!qla2x00_restart_isp(ha)) {
4164 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
4166 if (!atomic_read(&ha->loop_down_timer)) {
4168 * Issue marker command only when we are going
4169 * to start the I/O .
4171 ha->marker_needed = 1;
4174 ha->flags.online = 1;
4176 /* Enable ISP interrupts. */
4177 qla2x00_enable_intrs(ha);
4179 /* v2.19.5b6 Return all commands */
4180 qla2x00_abort_queues(ha, 1);
4182 /* Restart queues that may have been stopped. */
4183 qla2x00_restart_queues(ha, 1);
4184 ha->isp_abort_cnt = 0;
4185 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
4186 } else { /* failed the ISP abort */
4187 ha->flags.online = 1;
4188 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
4189 if (ha->isp_abort_cnt == 0) {
4190 qla_printk(KERN_WARNING, ha,
4191 "ISP error recovery failed - "
4192 "board disabled\n");
4194 * The next call disables the board
4197 qla2x00_reset_adapter(ha);
4198 qla2x00_abort_queues(ha, 0);
4199 ha->flags.online = 0;
4200 clear_bit(ISP_ABORT_RETRY,
4203 } else { /* schedule another ISP abort */
4204 ha->isp_abort_cnt--;
4205 DEBUG(printk("qla%ld: ISP abort - "
4206 "retry remainning %d\n",
4207 ha->host_no, ha->isp_abort_cnt);)
4211 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
4212 DEBUG(printk("qla2x00(%ld): ISP error recovery "
4213 "- retrying (%d) more times\n",
4214 ha->host_no, ha->isp_abort_cnt);)
4215 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
4223 qla_printk(KERN_INFO, ha,
4224 "qla2x00_abort_isp: **** FAILED ****\n");
4226 DEBUG(printk(KERN_INFO
4227 "qla2x00_abort_isp(%ld): exiting.\n",
4235 * qla2x00_restart_isp
4236 * restarts the ISP after a reset
4239 * ha = adapter block pointer.
4245 qla2x00_restart_isp(scsi_qla_host_t *ha)
4249 unsigned long flags = 0;
4252 /* If firmware needs to be loaded */
4253 if (qla2x00_isp_firmware(ha)) {
4254 ha->flags.online = 0;
4255 if (!(status = qla2x00_chip_diag(ha))) {
4256 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4257 status = qla2x00_setup_chip(ha);
4262 spin_lock_irqsave(&ha->hardware_lock, flags);
4263 /* Disable SRAM, Instruction RAM and GP RAM parity. */
4264 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
4265 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4267 status = qla2x00_setup_chip(ha);
4269 spin_lock_irqsave(&ha->hardware_lock, flags);
4271 /* Enable proper parity */
4274 WRT_REG_WORD(®->hccr,
4275 (HCCR_ENABLE_PARITY + 0x1));
4277 /* SRAM, Instruction RAM and GP RAM parity */
4278 WRT_REG_WORD(®->hccr,
4279 (HCCR_ENABLE_PARITY + 0x7));
4281 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4286 if (!status && !(status = qla2x00_init_rings(ha))) {
4287 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
4288 if (!(status = qla2x00_fw_ready(ha))) {
4289 DEBUG(printk("%s(): Start configure loop, "
4293 ha->flags.online = 1;
4294 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4297 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4298 qla2x00_configure_loop(ha);
4300 } while (!atomic_read(&ha->loop_down_timer) &&
4301 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
4303 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
4306 /* if no cable then assume it's good */
4307 if ((ha->device_flags & DFLG_NO_CABLE))
4310 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
4318 * qla2x00_reset_adapter
4322 * ha = adapter block pointer.
4325 qla2x00_reset_adapter(scsi_qla_host_t *ha)
4327 unsigned long flags = 0;
4328 device_reg_t *reg = ha->iobase;
4330 ha->flags.online = 0;
4331 qla2x00_disable_intrs(ha);
4332 /* Reset RISC processor. */
4333 spin_lock_irqsave(&ha->hardware_lock, flags);
4334 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
4335 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
4336 spin_unlock_irqrestore(&ha->hardware_lock, flags);