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 /* Setup seriallink options */
787 uint16_t swing, emphasis;
789 memset(ha->fw_options, 0, sizeof(ha->fw_options));
790 qla2x00_get_fw_options(ha, ha->fw_options);
792 if (IS_QLA2100(ha) || IS_QLA2200(ha))
795 /* Serial Link options. */
796 DEBUG3(printk("scsi(%ld): Serial link options:\n",
798 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
799 sizeof(ha->fw_seriallink_options)));
801 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
802 if (ha->fw_seriallink_options[1] & BIT_2)
803 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
806 swing = ha->fw_seriallink_options[0] & (BIT_2 | BIT_1 | BIT_0);
807 emphasis = ha->fw_seriallink_options[0] & (BIT_4 | BIT_3);
809 ha->fw_options[10] = (emphasis << 14) | (swing << 8) | 0x3;
812 swing = ha->fw_seriallink_options[0] & (BIT_7 | BIT_6 | BIT_5);
814 emphasis = ha->fw_seriallink_options[1] & (BIT_1 | BIT_0);
815 ha->fw_options[11] = (emphasis << 14) | (swing << 8) | 0x3;
818 /* Return command IOCBs without waiting for an ABTS to complete. */
819 ha->fw_options[3] |= BIT_13;
821 /* Update Serial Link options. */
822 qla2x00_set_fw_options(ha, ha->fw_options);
826 * qla2x00_init_rings() - Initializes firmware.
829 * Beginning of request ring has initialization control block already built
830 * by nvram config routine.
832 * Returns 0 on success.
835 qla2x00_init_rings(scsi_qla_host_t *ha)
838 unsigned long flags = 0;
840 device_reg_t *reg = ha->iobase;
842 spin_lock_irqsave(&ha->hardware_lock, flags);
844 /* Clear outstanding commands array. */
845 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
846 ha->outstanding_cmds[cnt] = 0;
848 ha->current_outstanding_cmd = 0;
850 /* Clear RSCN queue. */
852 ha->rscn_out_ptr = 0;
854 /* Initialize firmware. */
855 ha->request_ring_ptr = ha->request_ring;
856 ha->req_ring_index = 0;
857 ha->req_q_cnt = ha->request_q_length;
858 ha->response_ring_ptr = ha->response_ring;
859 ha->rsp_ring_index = 0;
861 /* Initialize response queue entries */
862 qla2x00_init_response_q_entries(ha);
864 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
865 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
866 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
867 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
868 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg));
870 spin_unlock_irqrestore(&ha->hardware_lock, flags);
872 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
873 rval = qla2x00_init_firmware(ha, sizeof(init_cb_t));
875 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
878 /* Update any ISP specific firmware options. */
879 qla2x00_update_fw_options(ha);
881 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
889 * qla2x00_fw_ready() - Waits for firmware ready.
892 * Returns 0 on success.
895 qla2x00_fw_ready(scsi_qla_host_t *ha)
898 unsigned long wtime, mtime;
899 uint16_t min_wait; /* Minimum wait time if loop is down */
900 uint16_t wait_time; /* Wait time if loop is coming ready */
905 /* 20 seconds for loop down. */
909 * Firmware should take at most one RATOV to login, plus 5 seconds for
910 * our own processing.
912 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
913 wait_time = min_wait;
916 /* Min wait time if loop down */
917 mtime = jiffies + (min_wait * HZ);
919 /* wait time before firmware ready */
920 wtime = jiffies + (wait_time * HZ);
922 /* Wait for ISP to finish LIP */
923 if (!ha->flags.init_done)
924 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
926 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
930 rval = qla2x00_get_firmware_state(ha, &fw_state);
931 if (rval == QLA_SUCCESS) {
932 if (fw_state < FSTATE_LOSS_OF_SYNC) {
933 ha->device_flags &= ~DFLG_NO_CABLE;
935 if (fw_state == FSTATE_READY) {
936 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
939 qla2x00_get_retry_cnt(ha, &ha->retry_count,
940 &ha->login_timeout, &ha->r_a_tov);
946 rval = QLA_FUNCTION_FAILED;
948 if (atomic_read(&ha->loop_down_timer) &&
949 (fw_state >= FSTATE_LOSS_OF_SYNC ||
950 fw_state == FSTATE_WAIT_AL_PA)) {
951 /* Loop down. Timeout on min_wait for states
952 * other than Wait for Login.
954 if (time_after_eq(jiffies, mtime)) {
955 qla_printk(KERN_INFO, ha,
956 "Cable is unplugged...\n");
958 ha->device_flags |= DFLG_NO_CABLE;
963 /* Mailbox cmd failed. Timeout on min_wait. */
964 if (time_after_eq(jiffies, mtime))
968 if (time_after_eq(jiffies, wtime))
971 /* Delay for a while */
972 set_current_state(TASK_UNINTERRUPTIBLE);
973 schedule_timeout(HZ / 2);
975 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
976 ha->host_no, fw_state, jiffies));
979 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
980 ha->host_no, fw_state, jiffies));
983 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
991 * qla2x00_configure_hba
992 * Setup adapter context.
995 * ha = adapter state pointer.
1004 qla2x00_configure_hba(scsi_qla_host_t *ha)
1012 char connect_type[22];
1014 /* Get host addresses. */
1015 rval = qla2x00_get_adapter_id(ha,
1016 &loop_id, &al_pa, &area, &domain, &topo);
1017 if (rval != QLA_SUCCESS) {
1018 qla_printk(KERN_WARNING, ha,
1019 "ERROR -- Unable to get host loop ID.\n");
1024 qla_printk(KERN_INFO, ha,
1025 "Cannot get topology - retrying.\n");
1026 return (QLA_FUNCTION_FAILED);
1029 ha->loop_id = loop_id;
1032 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1033 ha->operating_mode = LOOP;
1037 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1039 ha->current_topology = ISP_CFG_NL;
1040 strcpy(connect_type, "(Loop)");
1044 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1046 ha->current_topology = ISP_CFG_FL;
1047 strcpy(connect_type, "(FL_Port)");
1051 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1053 ha->operating_mode = P2P;
1054 ha->current_topology = ISP_CFG_N;
1055 strcpy(connect_type, "(N_Port-to-N_Port)");
1059 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1061 ha->operating_mode = P2P;
1062 ha->current_topology = ISP_CFG_F;
1063 strcpy(connect_type, "(F_Port)");
1067 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1069 ha->host_no, topo));
1070 ha->current_topology = ISP_CFG_NL;
1071 strcpy(connect_type, "(Loop)");
1075 /* Save Host port and loop ID. */
1076 /* byte order - Big Endian */
1077 ha->d_id.b.domain = domain;
1078 ha->d_id.b.area = area;
1079 ha->d_id.b.al_pa = al_pa;
1081 if (!ha->flags.init_done)
1082 qla_printk(KERN_INFO, ha,
1083 "Topology - %s, Host Loop address 0x%x\n",
1084 connect_type, ha->loop_id);
1087 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1089 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1096 * NVRAM configuration for ISP 2xxx
1099 * ha = adapter block pointer.
1102 * initialization control block in response_ring
1103 * host adapters parameters in host adapter block
1109 qla2x00_nvram_config(scsi_qla_host_t *ha)
1114 uint8_t *dptr1, *dptr2;
1115 init_cb_t *icb = ha->init_cb;
1116 nvram_t *nv = (nvram_t *)ha->request_ring;
1117 uint16_t *wptr = (uint16_t *)ha->request_ring;
1118 device_reg_t *reg = ha->iobase;
1123 if (ha->flags.init_done)
1126 /* Determine NVRAM starting address. */
1128 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1129 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1130 ha->nvram_base = 0x80;
1132 /* Get NVRAM data and calculate checksum. */
1133 qla2x00_lock_nvram_access(ha);
1134 for (cnt = 0; cnt < sizeof(nvram_t)/2; cnt++) {
1135 *wptr = cpu_to_le16(qla2x00_get_nvram_word(ha,
1136 (cnt+ha->nvram_base)));
1137 chksum += (uint8_t)*wptr;
1138 chksum += (uint8_t)(*wptr >> 8);
1141 qla2x00_unlock_nvram_access(ha);
1143 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1144 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1147 /* Bad NVRAM data, set defaults parameters. */
1148 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1149 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1150 /* Reset NVRAM data. */
1151 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1152 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1154 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1155 "invalid -- WWPN) defaults.\n");
1158 * Set default initialization control block.
1160 memset(nv, 0, sizeof(nvram_t));
1161 nv->parameter_block_version = ICB_VERSION;
1163 if (IS_QLA23XX(ha)) {
1164 nv->firmware_options[0] = BIT_2 | BIT_1;
1165 nv->firmware_options[1] = BIT_7 | BIT_5;
1166 nv->add_firmware_options[0] = BIT_5;
1167 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1168 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1169 nv->special_options[1] = BIT_7;
1170 } else if (IS_QLA2200(ha)) {
1171 nv->firmware_options[0] = BIT_2 | BIT_1;
1172 nv->firmware_options[1] = BIT_7 | BIT_5;
1173 nv->add_firmware_options[0] = BIT_5;
1174 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1175 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1176 } else if (IS_QLA2100(ha)) {
1177 nv->firmware_options[0] = BIT_3 | BIT_1;
1178 nv->firmware_options[1] = BIT_5;
1179 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1182 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1183 nv->execution_throttle = __constant_cpu_to_le16(16);
1184 nv->retry_count = 8;
1185 nv->retry_delay = 1;
1187 nv->port_name[0] = 33;
1188 nv->port_name[3] = 224;
1189 nv->port_name[4] = 139;
1191 nv->login_timeout = 4;
1194 * Set default host adapter parameters
1196 nv->host_p[1] = BIT_2;
1197 nv->reset_delay = 5;
1198 nv->port_down_retry_count = 8;
1199 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1200 nv->link_down_timeout = 60;
1205 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1207 * The SN2 does not provide BIOS emulation which means you can't change
1208 * potentially bogus BIOS settings. Force the use of default settings
1209 * for link rate and frame size. Hope that the rest of the settings
1212 if (ia64_platform_is("sn2")) {
1213 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1215 nv->special_options[1] = BIT_7;
1219 /* Reset Initialization control block */
1220 memset(icb, 0, sizeof(init_cb_t));
1223 * Setup driver NVRAM options.
1225 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1226 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1227 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1228 nv->firmware_options[1] &= ~BIT_4;
1230 if (IS_QLA23XX(ha)) {
1231 nv->firmware_options[0] |= BIT_2;
1232 nv->firmware_options[0] &= ~BIT_3;
1234 if (IS_QLA2300(ha)) {
1235 if (ha->fb_rev == FPM_2310) {
1236 strcpy(ha->model_number, "QLA2310");
1238 strcpy(ha->model_number, "QLA2300");
1242 memcmp(nv->model_number, BINZERO,
1243 sizeof(nv->model_number)) != 0) {
1246 strncpy(ha->model_number, nv->model_number,
1247 sizeof(nv->model_number));
1248 st = en = ha->model_number;
1249 en += sizeof(nv->model_number) - 1;
1251 if (*en != 0x20 && *en != 0x00)
1258 index = (ha->pdev->subsystem_device & 0xff);
1259 if (index < QLA_MODEL_NAMES) {
1260 strcpy(ha->model_number,
1261 qla2x00_model_name[index]);
1263 qla2x00_model_desc[index];
1265 strcpy(ha->model_number, "QLA23xx");
1269 } else if (IS_QLA2200(ha)) {
1270 nv->firmware_options[0] |= BIT_2;
1272 * 'Point-to-point preferred, else loop' is not a safe
1273 * connection mode setting.
1275 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1277 /* Force 'loop preferred, else point-to-point'. */
1278 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1279 nv->add_firmware_options[0] |= BIT_5;
1281 strcpy(ha->model_number, "QLA22xx");
1282 } else /*if (IS_QLA2100(ha))*/ {
1283 strcpy(ha->model_number, "QLA2100");
1287 * Copy over NVRAM RISC parameter block to initialization control block.
1289 dptr1 = (uint8_t *)icb;
1290 dptr2 = (uint8_t *)&nv->parameter_block_version;
1291 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1293 *dptr1++ = *dptr2++;
1295 /* Copy 2nd half. */
1296 dptr1 = (uint8_t *)icb->add_firmware_options;
1297 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1299 *dptr1++ = *dptr2++;
1301 /* Prepare nodename */
1302 if ((icb->firmware_options[1] & BIT_6) == 0) {
1304 * Firmware will apply the following mask if the nodename was
1307 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1308 icb->node_name[0] &= 0xF0;
1312 * Set host adapter parameters.
1314 ha->nvram_version = nv->nvram_version;
1316 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1317 /* Always load RISC code on non ISP2[12]00 chips. */
1318 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1319 ha->flags.disable_risc_code_load = 0;
1320 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1321 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1322 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1324 ha->operating_mode =
1325 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1327 ha->fw_seriallink_options[0] = nv->seriallink_options[0];
1328 ha->fw_seriallink_options[1] = nv->seriallink_options[1];
1330 /* save HBA serial number */
1331 ha->serial0 = icb->port_name[5];
1332 ha->serial1 = icb->port_name[6];
1333 ha->serial2 = icb->port_name[7];
1334 memcpy(ha->node_name, icb->node_name, WWN_SIZE);
1336 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1338 ha->retry_count = nv->retry_count;
1340 /* Set minimum login_timeout to 4 seconds. */
1341 if (nv->login_timeout < ql2xlogintimeout)
1342 nv->login_timeout = ql2xlogintimeout;
1343 if (nv->login_timeout < 4)
1344 nv->login_timeout = 4;
1345 ha->login_timeout = nv->login_timeout;
1346 icb->login_timeout = nv->login_timeout;
1348 /* Set minimum RATOV to 200 tenths of a second. */
1351 ha->minimum_timeout =
1352 (ha->login_timeout * ha->retry_count) + nv->port_down_retry_count;
1353 ha->loop_reset_delay = nv->reset_delay;
1355 /* Will get the value from NVRAM. */
1356 ha->loop_down_timeout = LOOP_DOWN_TIMEOUT;
1358 /* Link Down Timeout = 0:
1360 * When Port Down timer expires we will start returning
1361 * I/O's to OS with "DID_NO_CONNECT".
1363 * Link Down Timeout != 0:
1365 * The driver waits for the link to come up after link down
1366 * before returning I/Os to OS with "DID_NO_CONNECT".
1368 if (nv->link_down_timeout == 0) {
1369 ha->loop_down_abort_time =
1370 (LOOP_DOWN_TIME - ha->loop_down_timeout);
1372 ha->link_down_timeout = nv->link_down_timeout;
1373 ha->loop_down_abort_time =
1374 (LOOP_DOWN_TIME - ha->link_down_timeout);
1377 ha->max_luns = MAX_LUNS;
1378 ha->max_probe_luns = le16_to_cpu(nv->max_luns_per_target);
1379 if (ha->max_probe_luns == 0)
1380 ha->max_probe_luns = MIN_LUNS;
1383 * Need enough time to try and get the port back.
1385 ha->port_down_retry_count = nv->port_down_retry_count;
1386 if (qlport_down_retry)
1387 ha->port_down_retry_count = qlport_down_retry;
1388 /* Set login_retry_count */
1389 ha->login_retry_count = nv->retry_count;
1390 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1391 ha->port_down_retry_count > 3)
1392 ha->login_retry_count = ha->port_down_retry_count;
1393 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1394 ha->login_retry_count = ha->port_down_retry_count;
1395 if (ql2xloginretrycount)
1396 ha->login_retry_count = ql2xloginretrycount;
1398 ha->binding_type = Bind;
1399 if (ha->binding_type != BIND_BY_PORT_NAME &&
1400 ha->binding_type != BIND_BY_PORT_ID) {
1401 qla_printk(KERN_WARNING, ha,
1402 "Invalid binding type specified (%d), "
1403 "defaulting to BIND_BY_PORT_NAME!!!\n", ha->binding_type);
1405 ha->binding_type = BIND_BY_PORT_NAME;
1409 * Setup ring parameters in initialization control block
1411 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1412 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1413 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1414 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1415 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1416 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1417 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1418 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1420 icb->lun_enables = __constant_cpu_to_le16(0);
1421 icb->command_resource_count = 0;
1422 icb->immediate_notify_resource_count = 0;
1423 icb->timeout = __constant_cpu_to_le16(0);
1425 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1427 icb->firmware_options[0] &= ~BIT_3;
1428 icb->add_firmware_options[0] &=
1429 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1430 icb->add_firmware_options[0] |= BIT_2;
1431 icb->response_accumulation_timer = 3;
1432 icb->interrupt_delay_timer = 5;
1434 ha->flags.process_response_queue = 1;
1436 /* Enable ZIO -- Support mode 5 only. */
1437 timer_mode = icb->add_firmware_options[0] &
1438 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1439 icb->add_firmware_options[0] &=
1440 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1442 timer_mode = BIT_2 | BIT_0;
1443 if (timer_mode == (BIT_2 | BIT_0)) {
1444 DEBUG2(printk("scsi(%ld): ZIO enabled; timer delay "
1445 "(%d).\n", ha->host_no, ql2xintrdelaytimer));
1446 qla_printk(KERN_INFO, ha,
1447 "ZIO enabled; timer delay (%d).\n",
1448 ql2xintrdelaytimer);
1450 icb->add_firmware_options[0] |= timer_mode;
1451 icb->interrupt_delay_timer = ql2xintrdelaytimer;
1452 ha->flags.process_response_queue = 1;
1457 DEBUG2_3(printk(KERN_WARNING
1458 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1464 * qla2x00_init_tgt_map
1465 * Initializes target map.
1468 * ha = adapter block pointer.
1474 qla2x00_init_tgt_map(scsi_qla_host_t *ha)
1478 for (t = 0; t < MAX_TARGETS; t++)
1479 TGT_Q(ha, t) = (os_tgt_t *)NULL;
1483 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1485 * @flags: allocation flags
1487 * Returns a pointer to the allocated fcport, or NULL, if none available.
1490 qla2x00_alloc_fcport(scsi_qla_host_t *ha, int flags)
1494 fcport = kmalloc(sizeof(fc_port_t), flags);
1498 /* Setup fcport template structure. */
1499 memset(fcport, 0, sizeof (fc_port_t));
1501 fcport->port_type = FCT_UNKNOWN;
1502 fcport->loop_id = FC_NO_LOOP_ID;
1503 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1504 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1505 fcport->flags = FCF_RLC_SUPPORT;
1506 INIT_LIST_HEAD(&fcport->fcluns);
1512 * qla2x00_configure_loop
1513 * Updates Fibre Channel Device Database with what is actually on loop.
1516 * ha = adapter block pointer.
1521 * 2 = database was full and device was not configured.
1524 qla2x00_configure_loop(scsi_qla_host_t *ha)
1527 unsigned long flags, save_flags;
1531 /* Get Initiator ID */
1532 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1533 rval = qla2x00_configure_hba(ha);
1534 if (rval != QLA_SUCCESS) {
1535 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1541 save_flags = flags = ha->dpc_flags;
1542 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1543 ha->host_no, flags));
1546 * If we have both an RSCN and PORT UPDATE pending then handle them
1547 * both at the same time.
1549 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1550 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1553 /* Determine what we need to do */
1554 if (ha->current_topology == ISP_CFG_FL &&
1555 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1557 ha->flags.rscn_queue_overflow = 1;
1558 set_bit(RSCN_UPDATE, &flags);
1560 } else if (ha->current_topology == ISP_CFG_F &&
1561 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1563 ha->flags.rscn_queue_overflow = 1;
1564 set_bit(RSCN_UPDATE, &flags);
1565 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1567 } else if (!ha->flags.online ||
1568 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1570 ha->flags.rscn_queue_overflow = 1;
1571 set_bit(RSCN_UPDATE, &flags);
1572 set_bit(LOCAL_LOOP_UPDATE, &flags);
1575 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1576 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1577 rval = QLA_FUNCTION_FAILED;
1579 rval = qla2x00_configure_local_loop(ha);
1583 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1584 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1585 rval = QLA_FUNCTION_FAILED;
1587 rval = qla2x00_configure_fabric(ha);
1591 if (rval == QLA_SUCCESS) {
1592 if (atomic_read(&ha->loop_down_timer) ||
1593 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1594 rval = QLA_FUNCTION_FAILED;
1596 qla2x00_config_os(ha);
1597 atomic_set(&ha->loop_state, LOOP_READY);
1599 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1604 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1605 __func__, ha->host_no));
1607 DEBUG3(printk("%s: exiting normally\n", __func__));
1610 /* Restore state if a resync event occured during processing */
1611 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1612 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1613 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1614 if (test_bit(RSCN_UPDATE, &save_flags))
1615 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1624 * qla2x00_configure_local_loop
1625 * Updates Fibre Channel Device Database with local loop devices.
1628 * ha = adapter block pointer.
1634 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1639 fc_port_t *fcport, *new_fcport;
1647 uint8_t loop_id_2100; /* ISP2100/ISP2200 -- 4 bytes. */
1648 uint16_t loop_id; /* ISP23XX -- 6 bytes. */
1650 #define MAX_ID_LIST_SIZE (sizeof(struct dev_id) * MAX_FIBRE_DEVICES)
1651 dma_addr_t id_list_dma;
1654 uint8_t domain, area, al_pa;
1659 entries = MAX_FIBRE_DEVICES;
1660 id_list = pci_alloc_consistent(ha->pdev, MAX_ID_LIST_SIZE,
1662 if (id_list == NULL) {
1663 DEBUG2(printk("scsi(%ld): Failed to allocate memory, No local "
1664 "loop\n", ha->host_no));
1666 qla_printk(KERN_WARNING, ha,
1667 "Memory Allocation failed - port_list");
1670 return (QLA_MEMORY_ALLOC_FAILED);
1672 memset(id_list, 0, MAX_ID_LIST_SIZE);
1674 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1675 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1677 /* Get list of logged in devices. */
1678 rval = qla2x00_get_id_list(ha, id_list, id_list_dma, &entries);
1679 if (rval != QLA_SUCCESS) {
1680 goto cleanup_allocation;
1683 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1684 ha->host_no, entries));
1685 DEBUG3(qla2x00_dump_buffer((uint8_t *)id_list,
1686 entries * sizeof(struct dev_id)));
1688 /* Allocate temporary fcport for any new fcports discovered. */
1689 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1690 if (new_fcport == NULL) {
1691 rval = QLA_MEMORY_ALLOC_FAILED;
1692 goto cleanup_allocation;
1694 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1697 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1699 list_for_each_entry(fcport, &ha->fcports, list) {
1700 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1701 fcport->port_type != FCT_BROADCAST &&
1702 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1704 DEBUG(printk("scsi(%ld): Marking port lost, "
1706 ha->host_no, fcport->loop_id));
1708 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1709 fcport->flags &= ~FCF_FARP_DONE;
1713 /* Add devices to port list. */
1714 id_iter = (char *)id_list;
1715 for (index = 0; index < entries; index++) {
1716 domain = ((struct dev_id *)id_iter)->domain;
1717 area = ((struct dev_id *)id_iter)->area;
1718 al_pa = ((struct dev_id *)id_iter)->al_pa;
1719 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1721 (uint16_t)((struct dev_id *)id_iter)->loop_id_2100;
1725 le16_to_cpu(((struct dev_id *)id_iter)->loop_id);
1729 /* Bypass reserved domain fields. */
1730 if ((domain & 0xf0) == 0xf0)
1733 /* Bypass if not same domain and area of adapter. */
1734 if (area != ha->d_id.b.area || domain != ha->d_id.b.domain)
1737 /* Bypass invalid local loop ID. */
1738 if (loop_id > LAST_LOCAL_LOOP_ID)
1741 /* Fill in member data. */
1742 new_fcport->d_id.b.domain = domain;
1743 new_fcport->d_id.b.area = area;
1744 new_fcport->d_id.b.al_pa = al_pa;
1745 new_fcport->loop_id = loop_id;
1746 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1747 if (rval2 != QLA_SUCCESS) {
1748 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1749 "information -- get_port_database=%x, "
1751 ha->host_no, rval2, new_fcport->loop_id));
1755 /* Check for matching device in port list. */
1758 list_for_each_entry(fcport, &ha->fcports, list) {
1759 if (memcmp(new_fcport->port_name, fcport->port_name,
1763 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1764 FCF_PERSISTENT_BOUND);
1765 fcport->loop_id = new_fcport->loop_id;
1766 fcport->port_type = new_fcport->port_type;
1767 fcport->d_id.b24 = new_fcport->d_id.b24;
1768 memcpy(fcport->node_name, new_fcport->node_name,
1776 /* New device, add to fcports list. */
1777 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1778 list_add_tail(&new_fcport->list, &ha->fcports);
1780 /* Allocate a new replacement fcport. */
1781 fcport = new_fcport;
1782 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1783 if (new_fcport == NULL) {
1784 rval = QLA_MEMORY_ALLOC_FAILED;
1785 goto cleanup_allocation;
1787 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1790 qla2x00_update_fcport(ha, fcport);
1796 pci_free_consistent(ha->pdev, MAX_ID_LIST_SIZE, id_list, id_list_dma);
1801 if (rval != QLA_SUCCESS) {
1802 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1803 "rval=%x\n", ha->host_no, rval));
1807 ha->device_flags |= DFLG_LOCAL_DEVICES;
1808 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
1815 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
1819 qla2x00_mark_all_devices_lost(ha);
1820 list_for_each_entry(fcport, &ha->fcports, list) {
1821 if (fcport->port_type != FCT_TARGET)
1824 qla2x00_update_fcport(ha, fcport);
1829 * qla2x00_update_fcport
1830 * Updates device on list.
1833 * ha = adapter block pointer.
1834 * fcport = port structure pointer.
1844 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
1847 unsigned long flags;
1851 fcport->login_retry = 0;
1852 fcport->port_login_retry_count = ha->port_down_retry_count *
1854 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
1856 fcport->flags &= ~FCF_LOGIN_NEEDED;
1859 * Check for outstanding cmd on tape Bypass LUN discovery if active
1862 if (fcport->flags & FCF_TAPE_PRESENT) {
1863 spin_lock_irqsave(&ha->hardware_lock, flags);
1864 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
1865 if ((sp = ha->outstanding_cmds[index]) != 0) {
1866 if (sp->fclun->fcport == fcport) {
1867 atomic_set(&fcport->state, FCS_ONLINE);
1868 spin_unlock_irqrestore(
1869 &ha->hardware_lock, flags);
1874 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1877 /* Do LUN discovery. */
1878 if (fcport->port_type == FCT_INITIATOR ||
1879 fcport->port_type == FCT_BROADCAST) {
1880 fcport->device_type = TYPE_PROCESSOR;
1882 qla2x00_lun_discovery(ha, fcport);
1884 atomic_set(&fcport->state, FCS_ONLINE);
1888 * qla2x00_lun_discovery
1889 * Issue SCSI inquiry command for LUN discovery.
1892 * ha: adapter state pointer.
1893 * fcport: FC port structure pointer.
1899 qla2x00_lun_discovery(scsi_qla_host_t *ha, fc_port_t *fcport)
1905 inq = pci_alloc_consistent(ha->pdev, sizeof(inq_cmd_rsp_t), &inq_dma);
1907 qla_printk(KERN_WARNING, ha,
1908 "Memory Allocation failed - INQ\n");
1912 /* If report LUN works, exit. */
1913 if (qla2x00_rpt_lun_discovery(ha, fcport, inq, inq_dma) !=
1915 for (lun = 0; lun < ha->max_probe_luns; lun++) {
1916 /* Configure LUN. */
1917 qla2x00_cfg_lun(ha, fcport, lun, inq, inq_dma);
1921 pci_free_consistent(ha->pdev, sizeof(inq_cmd_rsp_t), inq, inq_dma);
1925 * qla2x00_rpt_lun_discovery
1926 * Issue SCSI report LUN command for LUN discovery.
1929 * ha: adapter state pointer.
1930 * fcport: FC port structure pointer.
1933 * qla2x00 local function return status code.
1939 qla2x00_rpt_lun_discovery(scsi_qla_host_t *ha, fc_port_t *fcport,
1940 inq_cmd_rsp_t *inq, dma_addr_t inq_dma)
1945 rpt_lun_cmd_rsp_t *rlc;
1948 /* Assume a failed status */
1949 rval = QLA_FUNCTION_FAILED;
1951 /* No point in continuing if the device doesn't support RLC */
1952 if ((fcport->flags & FCF_RLC_SUPPORT) == 0)
1955 rlc = pci_alloc_consistent(ha->pdev, sizeof(rpt_lun_cmd_rsp_t),
1958 qla_printk(KERN_WARNING, ha,
1959 "Memory Allocation failed - RLC");
1960 return QLA_MEMORY_ALLOC_FAILED;
1963 rval = qla2x00_report_lun(ha, fcport, rlc, rlc_dma);
1964 if (rval != QLA_SUCCESS) {
1965 pci_free_consistent(ha->pdev, sizeof(rpt_lun_cmd_rsp_t), rlc,
1970 /* Always add a fc_lun_t structure for lun 0 -- mid-layer requirement */
1971 qla2x00_add_lun(fcport, 0);
1973 /* Configure LUN list. */
1974 len = be32_to_cpu(rlc->list.hdr.len);
1976 for (cnt = 0; cnt < len; cnt++) {
1977 lun = CHAR_TO_SHORT(rlc->list.lst[cnt].lsb,
1978 rlc->list.lst[cnt].msb.b);
1980 DEBUG3(printk("scsi(%ld): RLC lun = (%d)\n", ha->host_no, lun));
1982 /* We only support 0 through MAX_LUNS-1 range */
1983 if (lun < MAX_LUNS) {
1984 qla2x00_cfg_lun(ha, fcport, lun, inq, inq_dma);
1987 atomic_set(&fcport->state, FCS_ONLINE);
1989 pci_free_consistent(ha->pdev, sizeof(rpt_lun_cmd_rsp_t), rlc, rlc_dma);
1995 * qla2x00_report_lun
1996 * Issue SCSI report LUN command.
1999 * ha: adapter state pointer.
2000 * fcport: FC port structure pointer.
2001 * mem: pointer to dma memory object for report LUN IOCB
2005 * qla2x00 local function return status code.
2011 qla2x00_report_lun(scsi_qla_host_t *ha,
2012 fc_port_t *fcport, rpt_lun_cmd_rsp_t *rlc, dma_addr_t rlc_dma)
2016 uint16_t comp_status;
2017 uint16_t scsi_status;
2019 rval = QLA_FUNCTION_FAILED;
2021 for (retries = 3; retries; retries--) {
2022 memset(rlc, 0, sizeof(rpt_lun_cmd_rsp_t));
2023 rlc->p.cmd.entry_type = COMMAND_A64_TYPE;
2024 rlc->p.cmd.entry_count = 1;
2025 SET_TARGET_ID(ha, rlc->p.cmd.target, fcport->loop_id);
2026 rlc->p.cmd.control_flags =
2027 __constant_cpu_to_le16(CF_READ | CF_SIMPLE_TAG);
2028 rlc->p.cmd.scsi_cdb[0] = REPORT_LUNS;
2029 rlc->p.cmd.scsi_cdb[8] = MSB(sizeof(rpt_lun_lst_t));
2030 rlc->p.cmd.scsi_cdb[9] = LSB(sizeof(rpt_lun_lst_t));
2031 rlc->p.cmd.dseg_count = __constant_cpu_to_le16(1);
2032 rlc->p.cmd.timeout = __constant_cpu_to_le16(10);
2033 rlc->p.cmd.byte_count =
2034 __constant_cpu_to_le32(sizeof(rpt_lun_lst_t));
2035 rlc->p.cmd.dseg_0_address[0] = cpu_to_le32(
2036 LSD(rlc_dma + sizeof(sts_entry_t)));
2037 rlc->p.cmd.dseg_0_address[1] = cpu_to_le32(
2038 MSD(rlc_dma + sizeof(sts_entry_t)));
2039 rlc->p.cmd.dseg_0_length =
2040 __constant_cpu_to_le32(sizeof(rpt_lun_lst_t));
2042 rval = qla2x00_issue_iocb(ha, rlc, rlc_dma,
2043 sizeof(rpt_lun_cmd_rsp_t));
2045 comp_status = le16_to_cpu(rlc->p.rsp.comp_status);
2046 scsi_status = le16_to_cpu(rlc->p.rsp.scsi_status);
2048 if (rval != QLA_SUCCESS || comp_status != CS_COMPLETE ||
2049 scsi_status & SS_CHECK_CONDITION) {
2051 /* Device underrun, treat as OK. */
2052 if (rval == QLA_SUCCESS &&
2053 comp_status == CS_DATA_UNDERRUN &&
2054 scsi_status & SS_RESIDUAL_UNDER) {
2060 DEBUG(printk("scsi(%ld): RLC failed to issue iocb! "
2061 "fcport=[%04x/%p] rval=%x cs=%x ss=%x\n",
2062 ha->host_no, fcport->loop_id, fcport, rval,
2063 comp_status, scsi_status));
2065 rval = QLA_FUNCTION_FAILED;
2066 if (scsi_status & SS_CHECK_CONDITION) {
2067 DEBUG2(printk("scsi(%ld): RLC "
2068 "SS_CHECK_CONDITION Sense Data "
2069 "%02x %02x %02x %02x %02x %02x %02x %02x\n",
2071 rlc->p.rsp.req_sense_data[0],
2072 rlc->p.rsp.req_sense_data[1],
2073 rlc->p.rsp.req_sense_data[2],
2074 rlc->p.rsp.req_sense_data[3],
2075 rlc->p.rsp.req_sense_data[4],
2076 rlc->p.rsp.req_sense_data[5],
2077 rlc->p.rsp.req_sense_data[6],
2078 rlc->p.rsp.req_sense_data[7]));
2079 if (rlc->p.rsp.req_sense_data[2] ==
2081 fcport->flags &= ~(FCF_RLC_SUPPORT);
2095 * Configures LUN into fcport LUN list.
2098 * fcport: FC port structure pointer.
2105 qla2x00_cfg_lun(scsi_qla_host_t *ha, fc_port_t *fcport, uint16_t lun,
2106 inq_cmd_rsp_t *inq, dma_addr_t inq_dma)
2110 /* Bypass LUNs that failed. */
2111 if (qla2x00_inquiry(ha, fcport, lun, inq, inq_dma) != QLA_SUCCESS) {
2112 DEBUG2(printk("scsi(%ld): Failed inquiry - loop id=0x%04x "
2113 "lun=%d\n", ha->host_no, fcport->loop_id, lun));
2118 switch (inq->inq[0]) {
2120 case TYPE_PROCESSOR:
2125 case TYPE_MEDIUM_CHANGER:
2126 case TYPE_ENCLOSURE:
2131 fcport->flags |= FCF_TAPE_PRESENT;
2134 DEBUG2(printk("scsi(%ld): Unsupported lun type -- "
2135 "loop id=0x%04x lun=%d type=%x\n",
2136 ha->host_no, fcport->loop_id, lun, inq->inq[0]));
2140 fcport->device_type = inq->inq[0];
2141 fclun = qla2x00_add_lun(fcport, lun);
2143 if (fclun != NULL) {
2144 atomic_set(&fcport->state, FCS_ONLINE);
2152 * Adds LUN to database
2155 * fcport: FC port structure pointer.
2162 qla2x00_add_lun(fc_port_t *fcport, uint16_t lun)
2167 if (fcport == NULL) {
2168 DEBUG(printk("scsi: Unable to add lun to NULL port\n"));
2172 /* Allocate LUN if not already allocated. */
2174 list_for_each_entry(fclun, &fcport->fcluns, list) {
2175 if (fclun->lun == lun) {
2183 fclun = kmalloc(sizeof(fc_lun_t), GFP_ATOMIC);
2184 if (fclun == NULL) {
2186 "%s(): Memory Allocation failed - FCLUN\n",
2191 /* Setup LUN structure. */
2192 memset(fclun, 0, sizeof(fc_lun_t));
2194 fclun->fcport = fcport;
2195 fclun->o_fcport = fcport;
2196 fclun->device_type = fcport->device_type;
2197 atomic_set(&fcport->state, FCS_UNCONFIGURED);
2199 list_add_tail(&fclun->list, &fcport->fcluns);
2206 * Issue SCSI inquiry command.
2209 * ha = adapter block pointer.
2210 * fcport = FC port structure pointer.
2220 qla2x00_inquiry(scsi_qla_host_t *ha,
2221 fc_port_t *fcport, uint16_t lun, inq_cmd_rsp_t *inq, dma_addr_t inq_dma)
2225 uint16_t comp_status;
2226 uint16_t scsi_status;
2228 rval = QLA_FUNCTION_FAILED;
2230 for (retries = 3; retries; retries--) {
2231 memset(inq, 0, sizeof(inq_cmd_rsp_t));
2232 inq->p.cmd.entry_type = COMMAND_A64_TYPE;
2233 inq->p.cmd.entry_count = 1;
2234 inq->p.cmd.lun = cpu_to_le16(lun);
2235 SET_TARGET_ID(ha, inq->p.cmd.target, fcport->loop_id);
2236 inq->p.cmd.control_flags =
2237 __constant_cpu_to_le16(CF_READ | CF_SIMPLE_TAG);
2238 inq->p.cmd.scsi_cdb[0] = INQUIRY;
2239 inq->p.cmd.scsi_cdb[4] = INQ_DATA_SIZE;
2240 inq->p.cmd.dseg_count = __constant_cpu_to_le16(1);
2241 inq->p.cmd.timeout = __constant_cpu_to_le16(10);
2242 inq->p.cmd.byte_count =
2243 __constant_cpu_to_le32(INQ_DATA_SIZE);
2244 inq->p.cmd.dseg_0_address[0] = cpu_to_le32(
2245 LSD(inq_dma + sizeof(sts_entry_t)));
2246 inq->p.cmd.dseg_0_address[1] = cpu_to_le32(
2247 MSD(inq_dma + sizeof(sts_entry_t)));
2248 inq->p.cmd.dseg_0_length =
2249 __constant_cpu_to_le32(INQ_DATA_SIZE);
2251 DEBUG5(printk("scsi(%ld): Lun Inquiry - fcport=[%04x/%p],"
2253 ha->host_no, fcport->loop_id, fcport, lun));
2255 rval = qla2x00_issue_iocb(ha, inq, inq_dma,
2256 sizeof(inq_cmd_rsp_t));
2258 comp_status = le16_to_cpu(inq->p.rsp.comp_status);
2259 scsi_status = le16_to_cpu(inq->p.rsp.scsi_status);
2261 DEBUG5(printk("scsi(%ld): lun (%d) inquiry - "
2262 "inq[0]= 0x%x, comp status 0x%x, scsi status 0x%x, "
2264 ha->host_no, lun, inq->inq[0], comp_status, scsi_status,
2267 if (rval != QLA_SUCCESS || comp_status != CS_COMPLETE ||
2268 scsi_status & SS_CHECK_CONDITION) {
2270 DEBUG(printk("scsi(%ld): INQ failed to issue iocb! "
2271 "fcport=[%04x/%p] rval=%x cs=%x ss=%x\n",
2272 ha->host_no, fcport->loop_id, fcport, rval,
2273 comp_status, scsi_status));
2275 if (rval == QLA_SUCCESS)
2276 rval = QLA_FUNCTION_FAILED;
2278 if (scsi_status & SS_CHECK_CONDITION) {
2279 DEBUG2(printk("scsi(%ld): INQ "
2280 "SS_CHECK_CONDITION Sense Data "
2281 "%02x %02x %02x %02x %02x %02x %02x %02x\n",
2283 inq->p.rsp.req_sense_data[0],
2284 inq->p.rsp.req_sense_data[1],
2285 inq->p.rsp.req_sense_data[2],
2286 inq->p.rsp.req_sense_data[3],
2287 inq->p.rsp.req_sense_data[4],
2288 inq->p.rsp.req_sense_data[5],
2289 inq->p.rsp.req_sense_data[6],
2290 inq->p.rsp.req_sense_data[7]));
2293 /* Device underrun drop LUN. */
2294 if (comp_status == CS_DATA_UNDERRUN &&
2295 scsi_status & SS_RESIDUAL_UNDER) {
2308 * qla2x00_configure_fabric
2309 * Setup SNS devices with loop ID's.
2312 * ha = adapter block pointer.
2319 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2322 fc_port_t *fcport, *fcptemp;
2323 uint16_t next_loopid;
2324 uint16_t mb[MAILBOX_REGISTER_COUNT];
2325 LIST_HEAD(new_fcports);
2327 /* If FL port exists, then SNS is present */
2328 rval = qla2x00_get_port_name(ha, SNS_FL_PORT, NULL, 0);
2329 if (rval != QLA_SUCCESS) {
2330 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2331 "Port\n", ha->host_no));
2333 ha->device_flags &= ~SWITCH_FOUND;
2334 return (QLA_SUCCESS);
2337 /* Mark devices that need re-synchronization. */
2338 rval2 = qla2x00_device_resync(ha);
2339 if (rval2 == QLA_RSCNS_HANDLED) {
2340 /* No point doing the scan, just continue. */
2341 return (QLA_SUCCESS);
2344 /* Ensure we are logged into the SNS. */
2345 qla2x00_login_fabric(ha, SIMPLE_NAME_SERVER, 0xff, 0xff, 0xfc,
2347 if (mb[0] != MBS_COMMAND_COMPLETE) {
2348 DEBUG2(qla_printk(KERN_INFO, ha,
2349 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2350 "mb[2]=%x mb[6]=%x mb[7]=%x\n", SIMPLE_NAME_SERVER,
2351 mb[0], mb[1], mb[2], mb[6], mb[7]));
2352 return (QLA_SUCCESS);
2355 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2356 if (qla2x00_rft_id(ha)) {
2358 DEBUG2(printk("scsi(%ld): Register FC-4 "
2359 "TYPE failed.\n", ha->host_no));
2361 if (qla2x00_rff_id(ha)) {
2363 DEBUG2(printk("scsi(%ld): Register FC-4 "
2364 "Features failed.\n", ha->host_no));
2366 if (qla2x00_rnn_id(ha)) {
2368 DEBUG2(printk("scsi(%ld): Register Node Name "
2369 "failed.\n", ha->host_no));
2370 } else if (qla2x00_rsnn_nn(ha)) {
2372 DEBUG2(printk("scsi(%ld): Register Symbolic "
2373 "Node Name failed.\n", ha->host_no));
2377 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2378 if (rval != QLA_SUCCESS)
2382 * Logout all previous fabric devices marked lost, except
2385 list_for_each_entry(fcport, &ha->fcports, list) {
2386 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2389 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2392 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2393 qla2x00_mark_device_lost(ha, fcport,
2394 ql2xplogiabsentdevice);
2395 if (fcport->loop_id != FC_NO_LOOP_ID &&
2396 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2397 fcport->port_type != FCT_INITIATOR &&
2398 fcport->port_type != FCT_BROADCAST) {
2400 qla2x00_fabric_logout(ha,
2402 fcport->loop_id = FC_NO_LOOP_ID;
2407 /* Starting free loop ID. */
2408 next_loopid = ha->min_external_loopid;
2411 * Scan through our port list and login entries that need to be
2414 list_for_each_entry(fcport, &ha->fcports, list) {
2415 if (atomic_read(&ha->loop_down_timer) ||
2416 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2419 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2420 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2423 if (fcport->loop_id == FC_NO_LOOP_ID) {
2424 fcport->loop_id = next_loopid;
2425 rval = qla2x00_find_new_loop_id(ha, fcport);
2426 if (rval != QLA_SUCCESS) {
2427 /* Ran out of IDs to use */
2432 /* Login and update database */
2433 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2436 /* Exit if out of loop IDs. */
2437 if (rval != QLA_SUCCESS) {
2442 * Login and add the new devices to our port list.
2444 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2445 if (atomic_read(&ha->loop_down_timer) ||
2446 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2449 /* Find a new loop ID to use. */
2450 fcport->loop_id = next_loopid;
2451 rval = qla2x00_find_new_loop_id(ha, fcport);
2452 if (rval != QLA_SUCCESS) {
2453 /* Ran out of IDs to use */
2457 /* Login and update database */
2458 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2460 /* Remove device from the new list and add it to DB */
2461 list_del(&fcport->list);
2462 list_add_tail(&fcport->list, &ha->fcports);
2466 /* Free all new device structures not processed. */
2467 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2468 list_del(&fcport->list);
2473 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2474 "rval=%d\n", ha->host_no, rval));
2482 * qla2x00_find_all_fabric_devs
2485 * ha = adapter block pointer.
2486 * dev = database device entry pointer.
2495 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2499 fc_port_t *fcport, *new_fcport;
2504 int first_dev, last_dev;
2505 port_id_t wrap, nxt_d_id;
2509 /* Try GID_PT to get device list, else GAN. */
2510 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2513 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2514 "on GA_NXT\n", ha->host_no));
2516 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2517 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2520 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2523 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2530 /* Allocate temporary fcport for any new fcports discovered. */
2531 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2532 if (new_fcport == NULL) {
2535 return (QLA_MEMORY_ALLOC_FAILED);
2537 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2539 /* Set start port ID scan at adapter ID. */
2543 /* Starting free loop ID. */
2544 loop_id = ha->min_external_loopid;
2546 for (; loop_id <= ha->last_loop_id; loop_id++) {
2547 if (RESERVED_LOOP_ID(loop_id))
2550 if (atomic_read(&ha->loop_down_timer) ||
2551 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2556 wrap.b24 = new_fcport->d_id.b24;
2558 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2559 memcpy(new_fcport->node_name,
2560 swl[swl_idx].node_name, WWN_SIZE);
2561 memcpy(new_fcport->port_name,
2562 swl[swl_idx].port_name, WWN_SIZE);
2564 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2570 /* Send GA_NXT to the switch */
2571 rval = qla2x00_ga_nxt(ha, new_fcport);
2572 if (rval != QLA_SUCCESS) {
2577 /* If wrap on switch device list, exit. */
2579 wrap.b24 = new_fcport->d_id.b24;
2581 } else if (new_fcport->d_id.b24 == wrap.b24) {
2582 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2583 ha->host_no, new_fcport->d_id.b.domain,
2584 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2588 /* Bypass if host adapter. */
2589 if (new_fcport->d_id.b24 == ha->d_id.b24)
2592 /* Bypass reserved domain fields. */
2593 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2596 /* Locate matching device in database. */
2598 list_for_each_entry(fcport, &ha->fcports, list) {
2599 if (memcmp(new_fcport->port_name, fcport->port_name,
2606 * If address the same and state FCS_ONLINE, nothing
2609 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2610 atomic_read(&fcport->state) == FCS_ONLINE) {
2615 * If device was not a fabric device before.
2617 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2618 fcport->d_id.b24 = new_fcport->d_id.b24;
2619 fcport->loop_id = FC_NO_LOOP_ID;
2620 fcport->flags |= (FCF_FABRIC_DEVICE |
2622 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2627 * Port ID changed or device was marked to be updated;
2628 * Log it out if still logged in and mark it for
2631 fcport->d_id.b24 = new_fcport->d_id.b24;
2632 fcport->flags |= FCF_LOGIN_NEEDED;
2633 if (fcport->loop_id != FC_NO_LOOP_ID &&
2634 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2635 fcport->port_type != FCT_INITIATOR &&
2636 fcport->port_type != FCT_BROADCAST) {
2637 qla2x00_fabric_logout(ha, fcport->loop_id);
2638 fcport->loop_id = FC_NO_LOOP_ID;
2647 /* If device was not in our fcports list, then add it. */
2648 list_add_tail(&new_fcport->list, new_fcports);
2650 /* Allocate a new replacement fcport. */
2651 nxt_d_id.b24 = new_fcport->d_id.b24;
2652 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2653 if (new_fcport == NULL) {
2656 return (QLA_MEMORY_ALLOC_FAILED);
2658 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2659 new_fcport->d_id.b24 = nxt_d_id.b24;
2668 if (!list_empty(new_fcports))
2669 ha->device_flags |= DFLG_FABRIC_DEVICES;
2675 * qla2x00_find_new_loop_id
2676 * Scan through our port list and find a new usable loop ID.
2679 * ha: adapter state pointer.
2680 * dev: port structure pointer.
2683 * qla2x00 local function return status code.
2689 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2694 uint16_t first_loop_id;
2698 /* Save starting loop ID. */
2699 first_loop_id = dev->loop_id;
2702 /* Skip loop ID if already used by adapter. */
2703 if (dev->loop_id == ha->loop_id) {
2707 /* Skip reserved loop IDs. */
2708 while (RESERVED_LOOP_ID(dev->loop_id)) {
2712 /* Reset loop ID if passed the end. */
2713 if (dev->loop_id > ha->last_loop_id) {
2714 /* first loop ID. */
2715 dev->loop_id = ha->min_external_loopid;
2718 /* Check for loop ID being already in use. */
2721 list_for_each_entry(fcport, &ha->fcports, list) {
2722 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2723 /* ID possibly in use */
2729 /* If not in use then it is free to use. */
2734 /* ID in use. Try next value. */
2737 /* If wrap around. No free ID to use. */
2738 if (dev->loop_id == first_loop_id) {
2739 dev->loop_id = FC_NO_LOOP_ID;
2740 rval = QLA_FUNCTION_FAILED;
2749 * qla2x00_device_resync
2750 * Marks devices in the database that needs resynchronization.
2753 * ha = adapter block pointer.
2759 qla2x00_device_resync(scsi_qla_host_t *ha)
2765 uint32_t rscn_entry;
2766 uint8_t rscn_out_iter;
2770 rval = QLA_RSCNS_HANDLED;
2772 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2773 ha->flags.rscn_queue_overflow) {
2775 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2776 format = MSB(MSW(rscn_entry));
2777 d_id.b.domain = LSB(MSW(rscn_entry));
2778 d_id.b.area = MSB(LSW(rscn_entry));
2779 d_id.b.al_pa = LSB(LSW(rscn_entry));
2781 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2782 "[%02x/%02x%02x%02x].\n",
2783 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2784 d_id.b.area, d_id.b.al_pa));
2787 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2788 ha->rscn_out_ptr = 0;
2790 /* Skip duplicate entries. */
2791 for (rscn_out_iter = ha->rscn_out_ptr;
2792 !ha->flags.rscn_queue_overflow &&
2793 rscn_out_iter != ha->rscn_in_ptr;
2794 rscn_out_iter = (rscn_out_iter ==
2795 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2797 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2800 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2801 "entry found at [%d].\n", ha->host_no,
2804 ha->rscn_out_ptr = rscn_out_iter;
2807 /* Queue overflow, set switch default case. */
2808 if (ha->flags.rscn_queue_overflow) {
2809 DEBUG(printk("scsi(%ld): device_resync: rscn "
2810 "overflow.\n", ha->host_no));
2813 ha->flags.rscn_queue_overflow = 0;
2818 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) &&
2819 !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
2820 ha->flags.init_done) {
2821 /* Handle port RSCN via asyncronous IOCBs */
2822 rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
2824 if (rval2 == QLA_SUCCESS)
2838 ha->rscn_out_ptr = ha->rscn_in_ptr;
2844 /* Abort any outstanding IO descriptors. */
2845 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2846 qla2x00_cancel_io_descriptors(ha);
2848 list_for_each_entry(fcport, &ha->fcports, list) {
2849 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2850 (fcport->d_id.b24 & mask) != d_id.b24 ||
2851 fcport->port_type == FCT_BROADCAST)
2854 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2856 fcport->port_type != FCT_INITIATOR) {
2857 atomic_set(&fcport->state,
2861 fcport->flags &= ~FCF_FARP_DONE;
2868 * qla2x00_fabric_dev_login
2869 * Login fabric target device and update FC port database.
2872 * ha: adapter state pointer.
2873 * fcport: port structure list pointer.
2874 * next_loopid: contains value of a new loop ID that can be used
2875 * by the next login attempt.
2878 * qla2x00 local function return status code.
2884 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2885 uint16_t *next_loopid)
2893 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2894 if (rval == QLA_SUCCESS) {
2895 rval = qla2x00_get_port_database(ha, fcport, 0);
2896 if (rval != QLA_SUCCESS) {
2897 qla2x00_fabric_logout(ha, fcport->loop_id);
2899 qla2x00_update_fcport(ha, fcport);
2907 * qla2x00_fabric_login
2908 * Issue fabric login command.
2911 * ha = adapter block pointer.
2912 * device = pointer to FC device type structure.
2915 * 0 - Login successfully
2917 * 2 - Initiator device
2921 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2922 uint16_t *next_loopid)
2926 uint16_t tmp_loopid;
2927 uint16_t mb[MAILBOX_REGISTER_COUNT];
2933 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2934 "for port %02x%02x%02x.\n",
2935 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2936 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2938 /* Login fcport on switch. */
2939 qla2x00_login_fabric(ha, fcport->loop_id,
2940 fcport->d_id.b.domain, fcport->d_id.b.area,
2941 fcport->d_id.b.al_pa, mb, BIT_0);
2942 if (mb[0] == MBS_PORT_ID_USED) {
2944 * Device has another loop ID. The firmware team
2945 * recommends us to perform an implicit login with the
2946 * specified ID again. The ID we just used is save here
2947 * so we return with an ID that can be tried by the
2951 tmp_loopid = fcport->loop_id;
2952 fcport->loop_id = mb[1];
2954 DEBUG(printk("Fabric Login: port in use - next "
2955 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2956 fcport->loop_id, fcport->d_id.b.domain,
2957 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2959 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2964 /* A retry occurred before. */
2965 *next_loopid = tmp_loopid;
2968 * No retry occurred before. Just increment the
2969 * ID value for next login.
2971 *next_loopid = (fcport->loop_id + 1);
2974 if (mb[1] & BIT_0) {
2975 fcport->port_type = FCT_INITIATOR;
2977 fcport->port_type = FCT_TARGET;
2978 if (mb[1] & BIT_1) {
2979 fcport->flags |= FCF_TAPE_PRESENT;
2985 } else if (mb[0] == MBS_LOOP_ID_USED) {
2987 * Loop ID already used, try next loop ID.
2990 rval = qla2x00_find_new_loop_id(ha, fcport);
2991 if (rval != QLA_SUCCESS) {
2992 /* Ran out of loop IDs to use */
2995 } else if (mb[0] == MBS_COMMAND_ERROR) {
2997 * Firmware possibly timed out during login. If NO
2998 * retries are left to do then the device is declared
3001 *next_loopid = fcport->loop_id;
3002 qla2x00_fabric_logout(ha, fcport->loop_id);
3003 fcport->loop_id = FC_NO_LOOP_ID;
3009 * unrecoverable / not handled error
3011 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3012 "loop_id=%x jiffies=%lx.\n",
3013 __func__, ha->host_no, mb[0],
3014 fcport->d_id.b.domain, fcport->d_id.b.area,
3015 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3017 *next_loopid = fcport->loop_id;
3018 qla2x00_fabric_logout(ha, fcport->loop_id);
3019 fcport->loop_id = FC_NO_LOOP_ID;
3020 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
3031 * qla2x00_local_device_login
3032 * Issue local device login command.
3035 * ha = adapter block pointer.
3036 * loop_id = loop id of device to login to.
3038 * Returns (Where's the #define!!!!):
3039 * 0 - Login successfully
3044 qla2x00_local_device_login(scsi_qla_host_t *ha, uint16_t loop_id)
3047 uint16_t mb[MAILBOX_REGISTER_COUNT];
3049 memset(mb, 0, sizeof(mb));
3050 rval = qla2x00_login_local_device(ha, loop_id, mb, BIT_0);
3051 if (rval == QLA_SUCCESS) {
3052 /* Interrogate mailbox registers for any errors */
3053 if (mb[0] == MBS_COMMAND_ERROR)
3055 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3056 /* device not in PCB table */
3064 * qla2x00_loop_resync
3065 * Resync with fibre channel devices.
3068 * ha = adapter block pointer.
3074 qla2x00_loop_resync(scsi_qla_host_t *ha)
3081 atomic_set(&ha->loop_state, LOOP_UPDATE);
3082 qla2x00_stats.loop_resync++;
3083 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3084 if (ha->flags.online) {
3085 if (!(rval = qla2x00_fw_ready(ha))) {
3086 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3090 atomic_set(&ha->loop_state, LOOP_UPDATE);
3093 * Issue marker command only when we are going
3094 * to start the I/O .
3096 ha->marker_needed = 1;
3098 /* Remap devices on Loop. */
3099 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3101 qla2x00_configure_loop(ha);
3103 } while (!atomic_read(&ha->loop_down_timer) &&
3104 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3106 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3108 qla2x00_restart_queues(ha, 1);
3111 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3112 return (QLA_FUNCTION_FAILED);
3116 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3123 * qla2x00_restart_queues
3124 * Restart device queues.
3127 * ha = adapter block pointer.
3130 * Kernel/Interrupt context.
3133 qla2x00_restart_queues(scsi_qla_host_t *ha, uint8_t flush)
3136 int retry_q_cnt = 0;
3137 int pending_q_cnt = 0;
3138 struct list_head *list, *temp;
3139 unsigned long flags = 0;
3141 clear_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
3143 /* start pending queue */
3144 pending_q_cnt = ha->qthreads;
3146 spin_lock_irqsave(&ha->list_lock,flags);
3147 list_for_each_safe(list, temp, &ha->pending_queue) {
3148 sp = list_entry(list, srb_t, list);
3150 if ((sp->flags & SRB_TAPE))
3154 * When time expire return request back to OS as BUSY
3156 __del_from_pending_queue(ha, sp);
3157 sp->cmd->result = DID_BUS_BUSY << 16;
3158 sp->cmd->host_scribble = (unsigned char *)NULL;
3159 __add_to_done_queue(ha, sp);
3161 spin_unlock_irqrestore(&ha->list_lock, flags);
3163 if (!list_empty(&ha->pending_queue))
3168 * Clear out our retry queue
3171 spin_lock_irqsave(&ha->list_lock, flags);
3172 retry_q_cnt = ha->retry_q_cnt;
3173 list_for_each_safe(list, temp, &ha->retry_queue) {
3174 sp = list_entry(list, srb_t, list);
3175 /* when time expire return request back to OS as BUSY */
3176 __del_from_retry_queue(ha, sp);
3177 sp->cmd->result = DID_BUS_BUSY << 16;
3178 sp->cmd->host_scribble = (unsigned char *)NULL;
3179 __add_to_done_queue(ha, sp);
3181 spin_unlock_irqrestore(&ha->list_lock, flags);
3183 DEBUG2(printk("%s(%ld): callback %d commands.\n",
3189 DEBUG2(printk("%s(%ld): active=%ld, retry=%d, pending=%d, "
3190 "done=%ld, scsi retry=%d commands.\n",
3197 ha->scsi_retry_q_cnt);)
3199 if (!list_empty(&ha->done_queue))
3204 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
3210 list_for_each_entry(fcport, &ha->fcports, list) {
3211 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
3214 qla2x00_update_fcport(ha, fcport);
3215 fcport->flags &= ~FCF_RESCAN_NEEDED;
3219 qla2x00_probe_for_all_luns(ha);
3221 /* Update OS target and lun structures if necessary. */
3223 qla2x00_config_os(ha);
3230 * Setup OS target and LUN structures.
3233 * ha = adapter state pointer.
3239 qla2x00_config_os(scsi_qla_host_t *ha)
3247 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
3248 if ((tq = TGT_Q(ha, tgt)) == NULL)
3251 clear_bit(TQF_ONLINE, &tq->flags);
3254 list_for_each_entry(fcport, &ha->fcports, list) {
3255 if (atomic_read(&fcport->state) != FCS_ONLINE ||
3256 fcport->port_type == FCT_INITIATOR ||
3257 fcport->port_type == FCT_BROADCAST) {
3258 fcport->os_target_id = MAX_TARGETS;
3262 if (fcport->flags & FCF_FO_MASKED) {
3266 /* Bind FC port to OS target number. */
3267 if (qla2x00_fcport_bind(ha, fcport) == MAX_TARGETS) {
3271 /* Bind FC LUN to OS LUN number. */
3272 list_for_each_entry(fclun, &fcport->fcluns, list) {
3273 qla2x00_fclun_bind(ha, fcport, fclun);
3279 * qla2x00_fcport_bind
3280 * Locates a target number for FC port.
3283 * ha = adapter state pointer.
3284 * fcport = FC port structure pointer.
3293 qla2x00_fcport_bind(scsi_qla_host_t *ha, fc_port_t *fcport)
3299 /* Check for persistent binding. */
3300 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
3301 if ((tq = TGT_Q(ha, tgt)) == NULL)
3305 switch (ha->binding_type) {
3306 case BIND_BY_PORT_ID:
3307 if (fcport->d_id.b24 == tq->d_id.b24) {
3308 memcpy(tq->node_name, fcport->node_name,
3310 memcpy(tq->port_name, fcport->port_name,
3315 case BIND_BY_PORT_NAME:
3316 if (memcmp(fcport->port_name, tq->port_name,
3319 * In case of persistent binding, update the
3322 memcpy(tq->node_name, fcport->node_name,
3332 /* TODO: honor the ConfigRequired flag */
3333 if (tgt == MAX_TARGETS) {
3334 /* Check if targetID 0 available. */
3337 if (TGT_Q(ha, tgt) != NULL) {
3338 /* Locate first free target for device. */
3339 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
3340 if (TGT_Q(ha, tgt) == NULL) {
3345 if (tgt != MAX_TARGETS) {
3346 if ((tq = qla2x00_tgt_alloc(ha, tgt)) != NULL) {
3347 memcpy(tq->node_name, fcport->node_name,
3349 memcpy(tq->port_name, fcport->port_name,
3351 tq->d_id.b24 = fcport->d_id.b24;
3356 /* Reset target numbers incase it changed. */
3357 fcport->os_target_id = tgt;
3358 if (tgt != MAX_TARGETS && tq != NULL) {
3359 DEBUG2(printk("scsi(%ld): Assigning target ID=%02d @ %p to "
3360 "loop id=0x%04x, port state=0x%x, port down retry=%d\n",
3361 ha->host_no, tgt, tq, fcport->loop_id,
3362 atomic_read(&fcport->state),
3363 atomic_read(&fcport->port_down_timer)));
3365 fcport->tgt_queue = tq;
3366 fcport->flags |= FCF_PERSISTENT_BOUND;
3367 tq->fcport = fcport;
3368 set_bit(TQF_ONLINE, &tq->flags);
3369 tq->port_down_retry_count = ha->port_down_retry_count;
3372 qla2x00_get_lun_mask_from_config(ha, fcport, tgt, 0);
3376 if (tgt == MAX_TARGETS) {
3377 qla_printk(KERN_WARNING, ha,
3378 "Unable to bind fcport, loop_id=%x\n", fcport->loop_id);
3385 * qla2x00_fclun_bind
3386 * Binds all FC device LUNS to OS LUNS.
3389 * ha: adapter state pointer.
3390 * fcport: FC port structure pointer.
3399 qla2x00_fclun_bind(scsi_qla_host_t *ha, fc_port_t *fcport, fc_lun_t *fclun)
3405 tgt = fcport->os_target_id;
3409 if (lun >= MAX_LUNS) {
3410 DEBUG2(printk("scsi(%ld): Unable to bind lun, invalid "
3411 "lun=(%x).\n", ha->host_no, lun));
3415 /* Always alloc LUN 0 so kernel will scan past LUN 0. */
3416 if (lun != 0 && (EXT_IS_LUN_BIT_SET(&(fcport->lun_mask), lun))) {
3420 if ((lq = qla2x00_lun_alloc(ha, tgt, lun)) == NULL) {
3421 qla_printk(KERN_WARNING, ha,
3422 "Unable to bind fclun, loop_id=%x lun=%x\n",
3423 fcport->loop_id, lun);
3434 * Allocate and pre-initialize target queue.
3437 * ha = adapter block pointer.
3438 * t = SCSI target number.
3447 qla2x00_tgt_alloc(scsi_qla_host_t *ha, uint16_t tgt)
3452 * If SCSI addressing OK, allocate TGT queue and lock.
3454 if (tgt >= MAX_TARGETS) {
3455 DEBUG2(printk("scsi(%ld): Unable to allocate target, invalid "
3456 "target number %d.\n", ha->host_no, tgt));
3460 tq = TGT_Q(ha, tgt);
3462 tq = kmalloc(sizeof(os_tgt_t), GFP_ATOMIC);
3464 DEBUG2(printk("scsi(%ld): Alloc Target %d @ %p\n",
3465 ha->host_no, tgt, tq));
3467 memset(tq, 0, sizeof(os_tgt_t));
3470 TGT_Q(ha, tgt) = tq;
3474 tq->port_down_retry_count = ha->port_down_retry_count;
3476 qla_printk(KERN_WARNING, ha,
3477 "Unable to allocate target.\n");
3486 * Frees target and LUN queues.
3489 * ha = adapter block pointer.
3490 * t = SCSI target number.
3496 qla2x00_tgt_free(scsi_qla_host_t *ha, uint16_t tgt)
3502 * If SCSI addressing OK, allocate TGT queue and lock.
3504 if (tgt >= MAX_TARGETS) {
3505 DEBUG2(printk("scsi(%ld): Unable to de-allocate target, "
3506 "invalid target number %d.\n", ha->host_no, tgt));
3511 tq = TGT_Q(ha, tgt);
3513 TGT_Q(ha, tgt) = NULL;
3515 /* Free LUN structures. */
3516 for (lun = 0; lun < MAX_LUNS; lun++)
3517 qla2x00_lun_free(ha, tgt, lun);
3527 * Allocate and initialize LUN queue.
3530 * ha = adapter block pointer.
3531 * t = SCSI target number.
3541 qla2x00_lun_alloc(scsi_qla_host_t *ha, uint16_t tgt, uint16_t lun)
3546 * If SCSI addressing OK, allocate LUN queue.
3548 if (tgt >= MAX_TARGETS || lun >= MAX_LUNS || TGT_Q(ha, tgt) == NULL) {
3549 DEBUG2(printk("scsi(%ld): Unable to allocate lun, invalid "
3550 "parameter.\n", ha->host_no));
3555 lq = LUN_Q(ha, tgt, lun);
3557 lq = kmalloc(sizeof(os_lun_t), GFP_ATOMIC);
3559 DEBUG2(printk("scsi(%ld): Alloc Lun %d @ tgt %d.\n",
3560 ha->host_no, lun, tgt));
3562 memset(lq, 0, sizeof (os_lun_t));
3563 LUN_Q(ha, tgt, lun) = lq;
3566 * The following lun queue initialization code
3567 * must be duplicated in alloc_ioctl_mem function
3570 lq->q_state = LUN_STATE_READY;
3571 spin_lock_init(&lq->q_lock);
3576 qla_printk(KERN_WARNING, ha, "Unable to allocate lun.\n");
3587 * ha = adapter block pointer.
3588 * t = SCSI target number.
3594 qla2x00_lun_free(scsi_qla_host_t *ha, uint16_t tgt, uint16_t lun)
3599 * If SCSI addressing OK, allocate TGT queue and lock.
3601 if (tgt >= MAX_TARGETS || lun >= MAX_LUNS) {
3602 DEBUG2(printk("scsi(%ld): Unable to deallocate lun, invalid "
3603 "parameter.\n", ha->host_no));
3608 if (TGT_Q(ha, tgt) != NULL && (lq = LUN_Q(ha, tgt, lun)) != NULL) {
3609 LUN_Q(ha, tgt, lun) = NULL;
3619 * qla2x00_get_lun_mask_from_config
3620 * Get lun mask from the configuration parameters.
3621 * Bit order is little endian.
3624 * ha -- Host adapter
3625 * tgt -- target/device number
3626 * port -- pointer to port
3629 qla2x00_get_lun_mask_from_config(scsi_qla_host_t *ha,
3630 fc_port_t *fcport, uint16_t tgt, uint16_t dev_no)
3632 char propbuf[60]; /* size of search string */
3634 lun_bit_mask_t lun_mask, *mask_ptr = &lun_mask;
3636 /* Get "target-N-device-N-lun-mask" as a 256 bit lun_mask*/
3637 sprintf(propbuf, "scsi-qla%ld-tgt-%d-di-%d-lun-disabled",
3638 ha->instance, tgt, dev_no);
3640 rval = qla2x00_get_prop_xstr(ha, propbuf,
3641 (uint8_t *)&lun_mask, sizeof(lun_bit_mask_t));
3642 if (rval == sizeof(lun_bit_mask_t)) {
3643 memset(&fcport->lun_mask, 0, sizeof(lun_bit_mask_t));
3644 for (lun = 8 * sizeof(lun_bit_mask_t) - 1, bit = 0;
3645 lun >= 0; lun--, bit++) {
3646 if (EXT_IS_LUN_BIT_SET(mask_ptr, lun))
3647 EXT_SET_LUN_BIT((&fcport->lun_mask), bit);
3650 DEBUG3(printk("scsi(%ld): returning lun mask for fcport "
3651 "%02x%02x%02x%02x%02x%02x%02x%02x:\n",
3653 fcport->port_name[0], fcport->port_name[1],
3654 fcport->port_name[2], fcport->port_name[3],
3655 fcport->port_name[4], fcport->port_name[5],
3656 fcport->port_name[6], fcport->port_name[7]));
3657 DEBUG3(qla2x00_dump_buffer((uint8_t *)&fcport->lun_mask,
3658 sizeof(lun_bit_mask_t));)
3664 * qla2x00_bstr_to_hex
3665 * Convert hex byte string to number.
3668 * s = byte string pointer.
3669 * bp = byte pointer for number.
3670 * size = number of bytes.
3673 * Kernel/Interrupt context.
3676 qla2x00_bstr_to_hex(char *s, uint8_t *bp, int size)
3681 for (cnt = 0; *s != '\0' && cnt / 2 < size; cnt++) {
3682 if (*s >= 'A' && *s <= 'F') {
3683 n = (*s++ - 'A') + 10;
3684 } else if (*s >= 'a' && *s <= 'f') {
3685 n = (*s++ - 'a') + 10;
3686 } else if (*s >= '0' && *s <= '9') {
3699 /* fixme(dg) Need to swap data little endian */
3705 * qla2x00_get_prop_xstr
3706 * Get a string property value for the specified property name and
3707 * convert from the property string found in the configuration file,
3708 * which are ASCII characters representing nibbles, 2 characters represent
3709 * the hexdecimal value for a byte in the byte array.
3710 * The byte array is initialized to zero.
3711 * The resulting converted value is in big endian format (MSB at byte0).
3714 * ha = adapter state pointer.
3715 * propname = property name pointer.
3716 * propval = pointer where to store converted property val.
3717 * size = max or expected size of 'propval' array.
3720 * 0 = empty value string or invalid character in string
3721 * >0 = count of characters converted
3722 * -1 = property not found
3728 qla2x00_get_prop_xstr(scsi_qla_host_t *ha,
3729 char *propname, uint8_t *propval, int size)
3733 static char buf[LINESIZE];
3735 /* Get the requested property string */
3736 rval = qla2x00_find_propname(ha, propname, buf, ha->cmdline, size*2);
3737 DEBUG3(printk("%s(): Ret rval from find propname = %d\n",
3742 if (*propstr == '=')
3743 propstr++; /* ignore equal sign */
3745 if (rval == 0) { /* not found */
3749 rval = qla2x00_bstr_to_hex(propstr, (uint8_t *)propval, size);
3751 /* Invalid character in value string */
3752 qla_printk(KERN_INFO, ha,
3753 "%s(): %s Invalid hex string for property\n",
3756 qla_printk(KERN_INFO, ha,
3757 " Invalid string - %s\n",
3765 * qla2x00_find_propname
3766 * Get property in database.
3769 * ha = adapter structure pointer.
3770 * db = pointer to database
3771 * propstr = pointer to dest array for string
3772 * propname = name of property to search for.
3773 * siz = size of property
3777 * size = index of property
3783 qla2x00_find_propname(scsi_qla_host_t *ha,
3784 char *propname, char *propstr,
3789 /* find the specified string */
3791 /* find the property name */
3792 if ((cp = strstr(db,propname)) != NULL) {
3793 while ((*cp) && *cp != '=')
3796 strncpy(propstr, cp, siz+1);
3797 propstr[siz+1] = '\0';
3798 DEBUG(printk("qla2x00_find_propname: found "
3799 "property = {%s}\n",
3801 return (siz); /* match */
3811 * qla2x00_get_prop_16chars
3812 * Get an 8-byte property value for the specified property name by
3813 * converting from the property string found in the configuration file.
3814 * The resulting converted value is in big endian format (MSB at byte0).
3817 * ha = adapter state pointer.
3818 * propname = property name pointer.
3819 * propval = pointer to location for the converted property val.
3820 * db = pointer to database
3823 * 0 = value returned successfully.
3829 qla2x00_get_prop_16chars(scsi_qla_host_t *ha,
3830 char *propname, char *propval, char *db)
3839 uint8_t *retval = (uint8_t*)propval;
3840 uint8_t tmpval[8] = {0, 0, 0, 0, 0, 0, 0, 0};
3841 uint16_t max_byte_cnt = 8; /* 16 chars = 8 bytes */
3842 uint16_t max_strlen = 16;
3843 static char buf[LINESIZE];
3845 rval = qla2x00_find_propname(ha, propname, buf, db, max_strlen);
3848 if (*propstr == '=')
3849 propstr++; /* ignore equal sign */
3855 /* Convert string to numbers. */
3856 pchar = (uint8_t *)propstr;
3857 tmp_byte = (uint8_t *)tmpval;
3860 for (i = 0; i < max_strlen; i++) {
3862 * Check for invalid character, two at a time,
3863 * then convert them starting with first byte.
3866 if ((pchar[i] >= '0') && (pchar[i] <= '9')) {
3867 nval = pchar[i] - '0';
3868 } else if ((pchar[i] >= 'A') && (pchar[i] <= 'F')) {
3869 nval = pchar[i] - 'A' + 10;
3870 } else if ((pchar[i] >= 'a') && (pchar[i] <= 'f')) {
3871 nval = pchar[i] - 'a' + 10;
3873 /* invalid character */
3879 *tmp_byte = *tmp_byte | nval;
3882 *tmp_byte = *tmp_byte | nval << 4;
3887 /* Encountered invalid character. */
3891 /* Copy over the converted value. */
3898 *ret_byte++ = *tmp_byte++;
3901 /* big endian retval[0]; */
3906 * qla2x00_get_properties
3907 * Find all properties for the specified adapeter in
3911 * ha = adapter block pointer.
3912 * cmdline = pointer to command line string
3918 qla2x00_get_properties(scsi_qla_host_t *ha, char *cmdline)
3921 static char propbuf[LINESIZE];
3924 /* Adapter FC node names. */
3925 sprintf(propbuf, "scsi-qla%d-adapter-node", (int) ha->instance);
3926 rval = qla2x00_get_prop_16chars(ha, propbuf, fc_name, cmdline);
3927 if (rval == QLA_SUCCESS)
3928 memcpy(ha->init_cb->node_name, fc_name, WWN_SIZE);
3930 /* DG 04/07 check portname of adapter */
3931 sprintf(propbuf, "scsi-qla%d-adapter-port", (int)ha->instance);
3932 rval = qla2x00_get_prop_16chars(ha, propbuf, fc_name, cmdline);
3933 if (rval == QLA_SUCCESS &&
3934 memcmp(ha->init_cb->port_name, fc_name, WWN_SIZE)) {
3936 * Adapter port name is WWN, and cannot be changed.
3937 * Inform users of the mismatch, then just continue driver
3938 * loading using the original adapter port name in NVRAM.
3940 qla_printk(KERN_WARNING, ha,
3941 "Found mismatch in adapter port names.\n");
3942 qla_printk(KERN_INFO, ha,
3943 " qla%ld port name found in NVRAM -> "
3944 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
3946 ha->init_cb->port_name[0],
3947 ha->init_cb->port_name[1],
3948 ha->init_cb->port_name[2],
3949 ha->init_cb->port_name[3],
3950 ha->init_cb->port_name[4],
3951 ha->init_cb->port_name[5],
3952 ha->init_cb->port_name[6],
3953 ha->init_cb->port_name[7]);
3954 qla_printk(KERN_INFO, ha,
3955 " qla%ld port name found on command line -> "
3956 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
3958 fc_name[0], fc_name[1], fc_name[2], fc_name[3],
3959 fc_name[4], fc_name[5], fc_name[6], fc_name[7]);
3960 qla_printk(KERN_INFO, ha,
3961 " Using port name from NVRAM.\n");
3964 qla2x00_cfg_persistent_binding(ha);
3968 * qla2x00_cfg_persistent_binding
3969 * Get driver configuration file target persistent binding entries.
3972 * ha = adapter block pointer.
3978 qla2x00_cfg_persistent_binding(scsi_qla_host_t *ha)
3981 static char propbuf[LINESIZE];
3982 char *cmdline = ha->cmdline;
3986 uint8_t port_name[8];
3988 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
3989 if (ha->binding_type == BIND_BY_PORT_ID) {
3990 sprintf(propbuf, "scsi-qla%d-tgt-%d-di-0-pid",
3991 (int)ha->instance, tgt);
3992 rval = qla2x00_get_prop_xstr(ha,
3993 propbuf, portid, sizeof(portid));
3994 if (rval != sizeof(portid))
3997 memset(&d_id, 0, sizeof(port_id_t));
3998 d_id.r.d_id[0] = portid[2];
3999 d_id.r.d_id[1] = portid[1];
4000 d_id.r.d_id[2] = portid[0];
4002 sprintf(propbuf, "scsi-qla%d-tgt-%d-di-0-port",
4003 (int)ha->instance, tgt);
4004 rval = qla2x00_get_prop_16chars(ha,
4005 propbuf, port_name, cmdline);
4006 if (rval != QLA_SUCCESS)
4009 /* Fallthru since port_name already populated */
4013 * Create target context for device.
4015 if (ha->binding_type == BIND_BY_PORT_ID) {
4016 qla2x00_persistent_bind(ha, NULL, NULL, &d_id, tgt);
4018 qla2x00_persistent_bind(ha, NULL, port_name, NULL, tgt);
4024 * qla2x00_persistent_bind
4025 * Allocates target and fcport.
4028 * ha: adapter state pointer.
4029 * node_name: node name pointer.
4030 * port_name: port name pointer.
4031 * d_id: port ID pointer.
4032 * tgt: OS target number.
4035 * success = target queue pointer.
4042 qla2x00_persistent_bind(scsi_qla_host_t *ha, uint8_t *node_name,
4043 uint8_t *port_name, port_id_t *d_id, uint16_t tgt)
4049 * Check for duplicates.
4051 for (tgt2 = 0; tgt2 < MAX_TARGETS; tgt2++) {
4052 if ((tq = TGT_Q(ha, tgt2)) == NULL) {
4056 if (ha->binding_type == BIND_BY_PORT_ID) {
4057 if (tq->d_id.b24 != d_id->b24) {
4060 } else if (memcmp(tq->port_name, port_name, WWN_SIZE) != 0) {
4064 qla_printk(KERN_WARNING, ha,
4065 "Duplicate persistent bindings found for "
4066 "WWPN: %02x%02x%02x%02x%02x%02x%02x%02x.\n",
4067 port_name[0], port_name[1], port_name[2], port_name[3],
4068 port_name[4], port_name[5], port_name[6], port_name[7]);
4073 tq = qla2x00_tgt_alloc(ha, tgt);
4078 if (node_name != NULL) {
4079 memcpy(tq->node_name, node_name, WWN_SIZE);
4081 if (port_name != NULL) {
4082 memcpy(tq->port_name, port_name, WWN_SIZE);
4085 tq->d_id.b24 = d_id->b24;
4094 * Resets ISP and aborts all outstanding commands.
4097 * ha = adapter block pointer.
4103 qla2x00_abort_isp(scsi_qla_host_t *ha)
4105 unsigned long flags = 0;
4110 if (ha->flags.online) {
4111 ha->flags.online = 0;
4112 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
4113 qla2x00_stats.ispAbort++;
4114 ha->total_isp_aborts++; /* used by ioctl */
4115 ha->sns_retry_cnt = 0;
4117 qla_printk(KERN_INFO, ha,
4118 "Performing ISP error recovery - ha= %p.\n", ha);
4119 qla2x00_reset_chip(ha);
4121 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
4122 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
4123 atomic_set(&ha->loop_state, LOOP_DOWN);
4124 qla2x00_mark_all_devices_lost(ha);
4126 if (!atomic_read(&ha->loop_down_timer))
4127 atomic_set(&ha->loop_down_timer,
4131 spin_lock_irqsave(&ha->hardware_lock, flags);
4132 /* Requeue all commands in outstanding command list. */
4133 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
4134 sp = ha->outstanding_cmds[cnt];
4136 ha->outstanding_cmds[cnt] = 0;
4139 sp->lun_queue->out_cnt--;
4142 * Set the cmd host_byte status depending on
4143 * whether the scsi_error_handler is
4146 if (sp->flags & SRB_TAPE) {
4147 sp->cmd->result = DID_NO_CONNECT << 16;
4149 if (ha->host->eh_active != EH_ACTIVE)
4157 sp->cmd->host_scribble = (unsigned char *)NULL;
4158 add_to_done_queue(ha, sp);
4161 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4163 qla2x00_nvram_config(ha);
4165 if (!qla2x00_restart_isp(ha)) {
4166 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
4168 if (!atomic_read(&ha->loop_down_timer)) {
4170 * Issue marker command only when we are going
4171 * to start the I/O .
4173 ha->marker_needed = 1;
4176 ha->flags.online = 1;
4178 /* Enable ISP interrupts. */
4179 qla2x00_enable_intrs(ha);
4181 /* v2.19.5b6 Return all commands */
4182 qla2x00_abort_queues(ha, 1);
4184 /* Restart queues that may have been stopped. */
4185 qla2x00_restart_queues(ha, 1);
4186 ha->isp_abort_cnt = 0;
4187 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
4188 } else { /* failed the ISP abort */
4189 ha->flags.online = 1;
4190 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
4191 if (ha->isp_abort_cnt == 0) {
4192 qla_printk(KERN_WARNING, ha,
4193 "ISP error recovery failed - "
4194 "board disabled\n");
4196 * The next call disables the board
4199 qla2x00_reset_adapter(ha);
4200 qla2x00_abort_queues(ha, 0);
4201 ha->flags.online = 0;
4202 clear_bit(ISP_ABORT_RETRY,
4205 } else { /* schedule another ISP abort */
4206 ha->isp_abort_cnt--;
4207 DEBUG(printk("qla%ld: ISP abort - "
4208 "retry remainning %d\n",
4209 ha->host_no, ha->isp_abort_cnt);)
4213 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
4214 DEBUG(printk("qla2x00(%ld): ISP error recovery "
4215 "- retrying (%d) more times\n",
4216 ha->host_no, ha->isp_abort_cnt);)
4217 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
4225 qla_printk(KERN_INFO, ha,
4226 "qla2x00_abort_isp: **** FAILED ****\n");
4228 DEBUG(printk(KERN_INFO
4229 "qla2x00_abort_isp(%ld): exiting.\n",
4237 * qla2x00_restart_isp
4238 * restarts the ISP after a reset
4241 * ha = adapter block pointer.
4247 qla2x00_restart_isp(scsi_qla_host_t *ha)
4251 unsigned long flags = 0;
4254 /* If firmware needs to be loaded */
4255 if (qla2x00_isp_firmware(ha)) {
4256 ha->flags.online = 0;
4257 if (!(status = qla2x00_chip_diag(ha))) {
4258 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4259 status = qla2x00_setup_chip(ha);
4264 spin_lock_irqsave(&ha->hardware_lock, flags);
4265 /* Disable SRAM, Instruction RAM and GP RAM parity. */
4266 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
4267 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4269 status = qla2x00_setup_chip(ha);
4271 spin_lock_irqsave(&ha->hardware_lock, flags);
4273 /* Enable proper parity */
4276 WRT_REG_WORD(®->hccr,
4277 (HCCR_ENABLE_PARITY + 0x1));
4279 /* SRAM, Instruction RAM and GP RAM parity */
4280 WRT_REG_WORD(®->hccr,
4281 (HCCR_ENABLE_PARITY + 0x7));
4283 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4288 if (!status && !(status = qla2x00_init_rings(ha))) {
4289 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
4290 if (!(status = qla2x00_fw_ready(ha))) {
4291 DEBUG(printk("%s(): Start configure loop, "
4295 ha->flags.online = 1;
4296 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4299 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4300 qla2x00_configure_loop(ha);
4302 } while (!atomic_read(&ha->loop_down_timer) &&
4303 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
4305 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
4308 /* if no cable then assume it's good */
4309 if ((ha->device_flags & DFLG_NO_CABLE))
4312 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
4320 * qla2x00_reset_adapter
4324 * ha = adapter block pointer.
4327 qla2x00_reset_adapter(scsi_qla_host_t *ha)
4329 unsigned long flags = 0;
4330 device_reg_t *reg = ha->iobase;
4332 ha->flags.online = 0;
4333 qla2x00_disable_intrs(ha);
4334 /* Reset RISC processor. */
4335 spin_lock_irqsave(&ha->hardware_lock, flags);
4336 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
4337 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
4338 spin_unlock_irqrestore(&ha->hardware_lock, flags);