2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2004 QLogic Corporation
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
21 #include "qla_devtbl.h"
23 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
24 #ifndef EXT_IS_LUN_BIT_SET
25 #define EXT_IS_LUN_BIT_SET(P,L) \
26 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
27 #define EXT_SET_LUN_BIT(P,L) \
28 ((P)->mask[L/8] |= (0x80 >> (L%8)))
32 * QLogic ISP2x00 Hardware Support Function Prototypes.
34 static int qla2x00_pci_config(scsi_qla_host_t *);
35 static int qla2x00_isp_firmware(scsi_qla_host_t *);
36 static void qla2x00_reset_chip(scsi_qla_host_t *);
37 static int qla2x00_chip_diag(scsi_qla_host_t *);
38 static int qla2x00_setup_chip(scsi_qla_host_t *);
39 static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
40 static int qla2x00_init_rings(scsi_qla_host_t *);
41 static int qla2x00_fw_ready(scsi_qla_host_t *);
42 static int qla2x00_configure_hba(scsi_qla_host_t *);
43 static int qla2x00_nvram_config(scsi_qla_host_t *);
44 static void qla2x00_init_tgt_map(scsi_qla_host_t *);
45 static int qla2x00_configure_loop(scsi_qla_host_t *);
46 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
47 static void qla2x00_update_fcport(scsi_qla_host_t *, fc_port_t *);
48 static void qla2x00_lun_discovery(scsi_qla_host_t *, fc_port_t *);
49 static int qla2x00_rpt_lun_discovery(scsi_qla_host_t *, fc_port_t *,
50 inq_cmd_rsp_t *, dma_addr_t);
51 static int qla2x00_report_lun(scsi_qla_host_t *, fc_port_t *,
52 rpt_lun_cmd_rsp_t *, dma_addr_t);
53 static fc_lun_t *qla2x00_cfg_lun(scsi_qla_host_t *, fc_port_t *, uint16_t,
54 inq_cmd_rsp_t *, dma_addr_t);
55 static fc_lun_t * qla2x00_add_lun(fc_port_t *, uint16_t);
56 static int qla2x00_inquiry(scsi_qla_host_t *, fc_port_t *, uint16_t,
57 inq_cmd_rsp_t *, dma_addr_t);
58 static int qla2x00_configure_fabric(scsi_qla_host_t *);
59 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
60 static int qla2x00_device_resync(scsi_qla_host_t *);
61 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
63 static void qla2x00_config_os(scsi_qla_host_t *ha);
64 static uint16_t qla2x00_fcport_bind(scsi_qla_host_t *ha, fc_port_t *fcport);
65 static os_lun_t * qla2x00_fclun_bind(scsi_qla_host_t *, fc_port_t *,
67 static void qla2x00_lun_free(scsi_qla_host_t *, uint16_t, uint16_t);
69 static int qla2x00_bstr_to_hex(char *, uint8_t *, int);
70 static int qla2x00_find_propname(scsi_qla_host_t *,
71 char *, char *, char *, int);
73 static void qla2x00_get_lun_mask_from_config(scsi_qla_host_t *, fc_port_t *,
75 static int qla2x00_get_prop_16chars(scsi_qla_host_t *,
76 char *, char *, char *);
77 static void qla2x00_get_properties(scsi_qla_host_t *, char *);
79 static void qla2x00_cfg_persistent_binding(scsi_qla_host_t *);
80 static os_tgt_t *qla2x00_persistent_bind(scsi_qla_host_t *, uint8_t *,
81 uint8_t *, port_id_t *, uint16_t);
84 static int qla2x00_restart_isp(scsi_qla_host_t *);
85 static void qla2x00_reset_adapter(scsi_qla_host_t *);
87 /****************************************************************************/
88 /* QLogic ISP2x00 Hardware Support Functions. */
89 /****************************************************************************/
92 * qla2x00_initialize_adapter
96 * ha = adapter block pointer.
102 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
105 uint8_t restart_risc = 0;
109 /* Clear adapter flags. */
110 ha->flags.online = FALSE;
111 ha->flags.reset_active = FALSE;
112 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
113 atomic_set(&ha->loop_state, LOOP_DOWN);
114 ha->device_flags = 0;
115 ha->sns_retry_cnt = 0;
117 ha->failback_delay = 0;
118 ha->flags.management_server_logged_in = 0;
119 ha->marker_needed = 0;
121 ha->isp_abort_cnt = 0;
122 ha->beacon_blink_led = 0;
124 rval = qla2x00_pci_config(ha);
126 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
131 qla2x00_reset_chip(ha);
133 /* Initialize target map database. */
134 qla2x00_init_tgt_map(ha);
136 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
137 qla2x00_nvram_config(ha);
139 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
143 * If the user specified a device configuration on the command line
144 * then use it as the configuration. Otherwise, we scan for all
148 ha->cmdline = ql2xdevconf;
149 qla2x00_get_properties(ha, ql2xdevconf);
155 * Try to configure the loop.
160 /* If firmware needs to be loaded */
161 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
162 if ((rval = qla2x00_chip_diag(ha)) == QLA_SUCCESS) {
163 rval = qla2x00_setup_chip(ha);
167 if (rval == QLA_SUCCESS &&
168 (rval = qla2x00_init_rings(ha)) == QLA_SUCCESS) {
169 check_fw_ready_again:
171 * Wait for a successful LIP up to a maximum
172 * of (in seconds): RISC login timeout value,
173 * RISC retry count value, and port down retry
174 * value OR a minimum of 4 seconds OR If no
175 * cable, only 5 seconds.
177 rval = qla2x00_fw_ready(ha);
178 if (rval == QLA_SUCCESS) {
179 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
182 * Wait at most MAX_TARGET RSCNs for a stable
187 clear_bit(LOOP_RESYNC_NEEDED,
189 rval = qla2x00_configure_loop(ha);
191 if (test_and_clear_bit(ISP_ABORT_NEEDED,
198 * If loop state change while we were
199 * discoverying devices then wait for
203 if (atomic_read(&ha->loop_state) ==
204 LOOP_DOWN && retry--) {
205 goto check_fw_ready_again;
208 } while (!atomic_read(&ha->loop_down_timer) &&
211 (test_bit(LOOP_RESYNC_NEEDED,
215 rval = QLA_FUNCTION_FAILED;
220 } while (restart_risc && retry--);
222 if (rval == QLA_SUCCESS) {
223 /* Retrieve firmware information */
224 qla2x00_get_fw_version(ha, &ha->fw_major_version,
225 &ha->fw_minor_version, &ha->fw_subminor_version,
228 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
229 ha->marker_needed = 1;
230 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
231 ha->marker_needed = 0;
233 ha->flags.online = TRUE;
235 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
242 * qla2x00_pci_config() - Setup device PCI configuration registers.
245 * Returns 0 on success.
248 qla2x00_pci_config(scsi_qla_host_t *ha)
251 unsigned long flags = 0;
254 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
257 * Turn on PCI master; for system BIOSes that don't turn it on by
260 pci_set_master(ha->pdev);
262 if (pci_set_mwi(ha->pdev))
263 mwi = PCI_COMMAND_INVALIDATE;
264 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
267 return (QLA_FUNCTION_FAILED);
270 * We want to respect framework's setting of PCI configuration space
271 * command register and also want to make sure that all bits of
272 * interest to us are properly set in command register.
274 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
275 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
277 /* Get PCI bus information. */
278 spin_lock_irqsave(&ha->hardware_lock, flags);
279 ha->pci_attr = RD_REG_WORD(&ha->iobase->ctrl_status);
280 spin_unlock_irqrestore(&ha->hardware_lock, flags);
282 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
283 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
285 /* PCI Specification Revision 2.3 changes */
286 if (IS_QLA2322(ha) || IS_QLA6322(ha))
287 /* Command Register - Reset Interrupt Disable. */
288 w &= ~PCI_COMMAND_INTX_DISABLE;
291 * If this is a 2300 card and not 2312, reset the
292 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
293 * the 2310 also reports itself as a 2300 so we need to get the
294 * fb revision level -- a 6 indicates it really is a 2300 and
297 if (IS_QLA2300(ha)) {
298 spin_lock_irqsave(&ha->hardware_lock, flags);
301 WRT_REG_WORD(&ha->iobase->hccr, HCCR_PAUSE_RISC);
302 for (cnt = 0; cnt < 30000; cnt++) {
303 if ((RD_REG_WORD(&ha->iobase->hccr) &
304 HCCR_RISC_PAUSE) != 0)
310 /* Select FPM registers. */
311 WRT_REG_WORD(&ha->iobase->ctrl_status, 0x20);
313 /* Get the fb rev level */
314 ha->fb_rev = RD_FB_CMD_REG(ha, ha->iobase);
316 if (ha->fb_rev == FPM_2300)
317 w &= ~PCI_COMMAND_INVALIDATE;
319 /* Deselect FPM registers. */
320 WRT_REG_WORD(&ha->iobase->ctrl_status, 0x0);
322 /* Release RISC module. */
323 WRT_REG_WORD(&ha->iobase->hccr, HCCR_RELEASE_RISC);
324 for (cnt = 0; cnt < 30000; cnt++) {
325 if ((RD_REG_WORD(&ha->iobase->hccr) &
326 HCCR_RISC_PAUSE) == 0)
332 spin_unlock_irqrestore(&ha->hardware_lock, flags);
336 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
338 /* Reset expansion ROM address decode enable */
339 pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w);
340 w &= ~PCI_ROM_ADDRESS_ENABLE;
341 pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
343 return (QLA_SUCCESS);
347 * qla2x00_isp_firmware() - Choose firmware image.
350 * Returns 0 on success.
353 qla2x00_isp_firmware(scsi_qla_host_t *ha)
357 /* Assume loading risc code */
358 rval = QLA_FUNCTION_FAILED;
360 if (ha->flags.disable_risc_code_load) {
361 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
363 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
365 /* Verify checksum of loaded RISC code. */
366 rval = qla2x00_verify_checksum(ha);
370 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
378 * qla2x00_reset_chip() - Reset ISP chip.
381 * Returns 0 on success.
384 qla2x00_reset_chip(scsi_qla_host_t *ha)
386 unsigned long flags = 0;
387 device_reg_t *reg = ha->iobase;
389 unsigned long mbx_flags = 0;
392 /* Disable ISP interrupts. */
393 qla2x00_disable_intrs(ha);
395 spin_lock_irqsave(&ha->hardware_lock, flags);
397 /* Turn off master enable */
399 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
400 cmd &= ~PCI_COMMAND_MASTER;
401 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
403 if (!IS_QLA2100(ha)) {
405 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
406 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
407 for (cnt = 0; cnt < 30000; cnt++) {
408 if ((RD_REG_WORD(®->hccr) &
409 HCCR_RISC_PAUSE) != 0)
417 /* Select FPM registers. */
418 WRT_REG_WORD(®->ctrl_status, 0x20);
420 /* FPM Soft Reset. */
421 WRT_REG_WORD(®->fpm_diag_config, 0x100);
423 /* Toggle Fpm Reset. */
425 WRT_REG_WORD(®->fpm_diag_config, 0x0);
427 /* Select frame buffer registers. */
428 WRT_REG_WORD(®->ctrl_status, 0x10);
430 /* Reset frame buffer FIFOs. */
431 if (IS_QLA2200(ha)) {
432 WRT_FB_CMD_REG(ha, reg, 0xa000);
434 WRT_FB_CMD_REG(ha, reg, 0x00fc);
436 /* Read back fb_cmd until zero or 3 seconds max */
437 for (cnt = 0; cnt < 3000; cnt++) {
438 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
444 /* Select RISC module registers. */
445 WRT_REG_WORD(®->ctrl_status, 0);
447 /* Reset RISC processor. */
448 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
450 /* Release RISC processor. */
451 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
454 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
455 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
457 /* Reset ISP chip. */
458 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
460 /* Wait for RISC to recover from reset. */
461 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
463 * It is necessary to for a delay here since the card doesn't
464 * respond to PCI reads during a reset. On some architectures
465 * this will result in an MCA.
468 for (cnt = 30000; cnt; cnt--) {
469 if ((RD_REG_WORD(®->ctrl_status) &
470 CSR_ISP_SOFT_RESET) == 0)
477 /* Reset RISC processor. */
478 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
480 WRT_REG_WORD(®->semaphore, 0);
482 /* Release RISC processor. */
483 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
484 RD_REG_WORD(®->hccr); /* PCI Posting. */
486 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
487 for (cnt = 0; cnt < 30000; cnt++) {
488 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
489 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
491 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) {
492 if (!(test_bit(ABORT_ISP_ACTIVE,
494 spin_unlock_irqrestore(
495 &ha->mbx_reg_lock, mbx_flags);
499 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
500 spin_unlock_irqrestore(&ha->mbx_reg_lock,
508 /* Turn on master enable */
509 cmd |= PCI_COMMAND_MASTER;
510 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
512 /* Disable RISC pause on FPM parity error. */
514 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
516 spin_unlock_irqrestore(&ha->hardware_lock, flags);
520 * qla2x00_chip_diag() - Test chip for proper operation.
523 * Returns 0 on success.
526 qla2x00_chip_diag(scsi_qla_host_t *ha)
529 device_reg_t *reg = ha->iobase;
530 unsigned long flags = 0;
535 /* Assume a failed state */
536 rval = QLA_FUNCTION_FAILED;
538 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
539 ha->host_no, (u_long)®->flash_address));
541 spin_lock_irqsave(&ha->hardware_lock, flags);
543 /* Reset ISP chip. */
544 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
546 * We need to have a delay here since the card will not respond while
547 * in reset causing an MCA on some architectures.
550 data = qla2x00_debounce_register(®->ctrl_status);
551 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
553 data = RD_REG_WORD(®->ctrl_status);
558 goto chip_diag_failed;
560 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
563 /* Reset RISC processor. */
564 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
565 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
567 /* Workaround for QLA2312 PCI parity error */
568 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
569 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
570 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
572 data = RD_MAILBOX_REG(ha, reg, 0);
579 goto chip_diag_failed;
581 /* Check product ID of chip */
582 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
584 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
585 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
586 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
587 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
588 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
589 mb[3] != PROD_ID_3) {
590 qla_printk(KERN_WARNING, ha,
591 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
593 goto chip_diag_failed;
595 ha->product_id[0] = mb[1];
596 ha->product_id[1] = mb[2];
597 ha->product_id[2] = mb[3];
598 ha->product_id[3] = mb[4];
600 /* Adjust fw RISC transfer size */
601 if (ha->request_q_length > 1024)
602 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
604 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
605 ha->request_q_length;
607 if (IS_QLA2200(ha) &&
608 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
609 /* Limit firmware transfer size with a 2200A */
610 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
613 ha->fw_transfer_size = 128;
616 /* Wrap Incoming Mailboxes Test. */
617 spin_unlock_irqrestore(&ha->hardware_lock, flags);
619 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
620 rval = qla2x00_mbx_reg_test(ha);
622 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
624 qla_printk(KERN_WARNING, ha,
625 "Failed mailbox send register test\n");
628 /* Flag a successful rval */
631 spin_lock_irqsave(&ha->hardware_lock, flags);
635 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
636 "****\n", ha->host_no));
638 spin_unlock_irqrestore(&ha->hardware_lock, flags);
644 * qla2x00_setup_chip() - Load and start RISC firmware.
647 * Returns 0 on success.
650 qla2x00_setup_chip(scsi_qla_host_t *ha)
655 unsigned long risc_address;
656 unsigned long risc_code_size;
660 struct qla_fw_info *fw_iter;
664 /* Load firmware sequences */
665 fw_iter = ha->brd_info->fw_info;
666 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
667 risc_code = fw_iter->fwcode;
668 risc_code_size = *fw_iter->fwlen;
670 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
671 risc_address = *fw_iter->fwstart;
673 /* Extended address */
674 risc_address = *fw_iter->lfwstart;
679 while (risc_code_size > 0 && !rval) {
680 cnt = (uint16_t)(ha->fw_transfer_size >> 1);
681 if (cnt > risc_code_size)
682 cnt = risc_code_size;
684 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
685 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
686 ha->host_no, risc_code, cnt, risc_address));
688 req_ring = (uint16_t *)ha->request_ring;
689 for (i = 0; i < cnt; i++)
690 req_ring[i] = cpu_to_le16(risc_code[i]);
692 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
693 rval = qla2x00_load_ram(ha,
694 ha->request_dma, risc_address, cnt);
696 rval = qla2x00_load_ram_ext(ha,
697 ha->request_dma, risc_address, cnt);
700 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
701 "load segment %d of firmware\n",
703 qla_printk(KERN_WARNING, ha,
704 "[ERROR] Failed to load "
705 "segment %d of firmware\n", num);
707 qla2x00_dump_regs(ha);
713 risc_code_size -= cnt;
717 /* Next firmware sequence */
721 /* Verify checksum of loaded RISC code. */
723 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
724 "code.\n", ha->host_no));
726 rval = qla2x00_verify_checksum(ha);
727 if (rval == QLA_SUCCESS) {
728 /* Start firmware execution. */
729 DEBUG(printk("scsi(%ld): Checksum OK, start "
730 "firmware.\n", ha->host_no));
732 rval = qla2x00_execute_fw(ha);
735 DEBUG2(printk(KERN_INFO
736 "scsi(%ld): ISP Firmware failed checksum.\n",
742 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
750 * qla2x00_init_response_q_entries() - Initializes response queue entries.
753 * Beginning of request ring has initialization control block already built
754 * by nvram config routine.
756 * Returns 0 on success.
759 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
764 pkt = ha->response_ring_ptr;
765 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
766 pkt->signature = RESPONSE_PROCESSED;
773 * qla2x00_update_fw_options() - Read and process firmware options.
776 * Returns 0 on success.
779 qla2x00_update_fw_options(scsi_qla_host_t *ha)
781 /* Setup seriallink options */
782 uint16_t swing, emphasis;
784 memset(ha->fw_options, 0, sizeof(ha->fw_options));
785 qla2x00_get_fw_options(ha, ha->fw_options);
787 if (IS_QLA2100(ha) || IS_QLA2200(ha))
790 /* Serial Link options. */
791 DEBUG3(printk("scsi(%ld): Serial link options:\n",
793 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
794 sizeof(ha->fw_seriallink_options)));
796 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
797 if (ha->fw_seriallink_options[1] & BIT_2)
798 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
801 swing = ha->fw_seriallink_options[0] & (BIT_2 | BIT_1 | BIT_0);
802 emphasis = ha->fw_seriallink_options[0] & (BIT_4 | BIT_3);
804 ha->fw_options[10] = (emphasis << 14) | (swing << 8) | 0x3;
807 swing = ha->fw_seriallink_options[0] & (BIT_7 | BIT_6 | BIT_5);
809 emphasis = ha->fw_seriallink_options[1] & (BIT_1 | BIT_0);
810 ha->fw_options[11] = (emphasis << 14) | (swing << 8) | 0x3;
813 /* Return command IOCBs without waiting for an ABTS to complete. */
814 ha->fw_options[3] |= BIT_13;
816 /* Update Serial Link options. */
817 qla2x00_set_fw_options(ha, ha->fw_options);
821 * qla2x00_init_rings() - Initializes firmware.
824 * Beginning of request ring has initialization control block already built
825 * by nvram config routine.
827 * Returns 0 on success.
830 qla2x00_init_rings(scsi_qla_host_t *ha)
833 unsigned long flags = 0;
835 device_reg_t *reg = ha->iobase;
837 spin_lock_irqsave(&ha->hardware_lock, flags);
839 /* Clear outstanding commands array. */
840 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
841 ha->outstanding_cmds[cnt] = 0;
843 ha->current_outstanding_cmd = 0;
845 /* Clear RSCN queue. */
847 ha->rscn_out_ptr = 0;
849 /* Initialize firmware. */
850 ha->request_ring_ptr = ha->request_ring;
851 ha->req_ring_index = 0;
852 ha->req_q_cnt = ha->request_q_length;
853 ha->response_ring_ptr = ha->response_ring;
854 ha->rsp_ring_index = 0;
856 /* Initialize response queue entries */
857 qla2x00_init_response_q_entries(ha);
859 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
860 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
861 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
862 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
863 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg));
865 spin_unlock_irqrestore(&ha->hardware_lock, flags);
867 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
868 rval = qla2x00_init_firmware(ha, sizeof(init_cb_t));
870 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
873 /* Update any ISP specific firmware options. */
874 qla2x00_update_fw_options(ha);
876 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
884 * qla2x00_fw_ready() - Waits for firmware ready.
887 * Returns 0 on success.
890 qla2x00_fw_ready(scsi_qla_host_t *ha)
893 unsigned long wtime, mtime;
894 uint16_t min_wait; /* Minimum wait time if loop is down */
895 uint16_t wait_time; /* Wait time if loop is coming ready */
900 /* 20 seconds for loop down. */
904 * Firmware should take at most one RATOV to login, plus 5 seconds for
905 * our own processing.
907 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
908 wait_time = min_wait;
911 /* Min wait time if loop down */
912 mtime = jiffies + (min_wait * HZ);
914 /* wait time before firmware ready */
915 wtime = jiffies + (wait_time * HZ);
917 /* Wait for ISP to finish LIP */
918 if (!ha->flags.init_done)
919 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
921 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
925 rval = qla2x00_get_firmware_state(ha, &fw_state);
926 if (rval == QLA_SUCCESS) {
927 if (fw_state < FSTATE_LOSS_OF_SYNC) {
928 ha->device_flags &= ~DFLG_NO_CABLE;
930 if (fw_state == FSTATE_READY) {
931 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
934 qla2x00_get_retry_cnt(ha, &ha->retry_count,
935 &ha->login_timeout, &ha->r_a_tov);
941 rval = QLA_FUNCTION_FAILED;
943 if (atomic_read(&ha->loop_down_timer) &&
944 fw_state >= FSTATE_LOSS_OF_SYNC) {
945 /* Loop down. Timeout on min_wait for states
946 * other than Wait for Login.
948 if (time_after_eq(jiffies, mtime)) {
949 qla_printk(KERN_INFO, ha,
950 "Cable is unplugged...\n");
952 ha->device_flags |= DFLG_NO_CABLE;
957 /* Mailbox cmd failed. Timeout on min_wait. */
958 if (time_after_eq(jiffies, mtime))
962 if (time_after_eq(jiffies, wtime))
965 /* Delay for a while */
966 set_current_state(TASK_UNINTERRUPTIBLE);
967 schedule_timeout(HZ / 2);
969 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
970 ha->host_no, fw_state, jiffies));
973 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
974 ha->host_no, fw_state, jiffies));
977 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
985 * qla2x00_configure_hba
986 * Setup adapter context.
989 * ha = adapter state pointer.
998 qla2x00_configure_hba(scsi_qla_host_t *ha)
1006 char connect_type[22];
1008 /* Get host addresses. */
1009 rval = qla2x00_get_adapter_id(ha,
1010 &loop_id, &al_pa, &area, &domain, &topo);
1011 if (rval != QLA_SUCCESS) {
1012 qla_printk(KERN_WARNING, ha,
1013 "ERROR -- Unable to get host loop ID.\n");
1018 qla_printk(KERN_INFO, ha,
1019 "Cannot get topology - retrying.\n");
1020 return (QLA_FUNCTION_FAILED);
1023 ha->loop_id = loop_id;
1026 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1027 ha->operating_mode = LOOP;
1031 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1033 ha->current_topology = ISP_CFG_NL;
1034 strcpy(connect_type, "(Loop)");
1038 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1040 ha->current_topology = ISP_CFG_FL;
1041 strcpy(connect_type, "(FL_Port)");
1045 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1047 ha->operating_mode = P2P;
1048 ha->current_topology = ISP_CFG_N;
1049 strcpy(connect_type, "(N_Port-to-N_Port)");
1053 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1055 ha->operating_mode = P2P;
1056 ha->current_topology = ISP_CFG_F;
1057 strcpy(connect_type, "(F_Port)");
1061 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1063 ha->host_no, topo));
1064 ha->current_topology = ISP_CFG_NL;
1065 strcpy(connect_type, "(Loop)");
1069 /* Save Host port and loop ID. */
1070 /* byte order - Big Endian */
1071 ha->d_id.b.domain = domain;
1072 ha->d_id.b.area = area;
1073 ha->d_id.b.al_pa = al_pa;
1075 if (!ha->flags.init_done)
1076 qla_printk(KERN_INFO, ha,
1077 "Topology - %s, Host Loop address 0x%x\n",
1078 connect_type, ha->loop_id);
1081 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1083 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1090 * NVRAM configuration for ISP 2xxx
1093 * ha = adapter block pointer.
1096 * initialization control block in response_ring
1097 * host adapters parameters in host adapter block
1103 qla2x00_nvram_config(scsi_qla_host_t *ha)
1108 uint8_t *dptr1, *dptr2;
1109 init_cb_t *icb = ha->init_cb;
1110 nvram_t *nv = (nvram_t *)ha->request_ring;
1111 uint16_t *wptr = (uint16_t *)ha->request_ring;
1112 device_reg_t *reg = ha->iobase;
1113 uint16_t timer_mode;
1117 if (ha->flags.init_done)
1120 /* Determine NVRAM starting address. */
1122 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1123 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1124 ha->nvram_base = 0x80;
1126 /* Get NVRAM data and calculate checksum. */
1127 qla2x00_lock_nvram_access(ha);
1128 for (cnt = 0; cnt < sizeof(nvram_t)/2; cnt++) {
1129 *wptr = cpu_to_le16(qla2x00_get_nvram_word(ha,
1130 (cnt+ha->nvram_base)));
1131 chksum += (uint8_t)*wptr;
1132 chksum += (uint8_t)(*wptr >> 8);
1135 qla2x00_unlock_nvram_access(ha);
1137 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1138 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1141 /* Bad NVRAM data, set defaults parameters. */
1142 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1143 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1144 /* Reset NVRAM data. */
1145 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1146 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1148 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1149 "invalid -- WWPN) defaults.\n");
1152 * Set default initialization control block.
1154 memset(nv, 0, sizeof(nvram_t));
1155 nv->parameter_block_version = ICB_VERSION;
1157 if (IS_QLA23XX(ha)) {
1158 nv->firmware_options[0] = BIT_2 | BIT_1;
1159 nv->firmware_options[1] = BIT_7 | BIT_5;
1160 nv->add_firmware_options[0] = BIT_5;
1161 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1162 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1163 nv->special_options[1] = BIT_7;
1164 } else if (IS_QLA2200(ha)) {
1165 nv->firmware_options[0] = BIT_2 | BIT_1;
1166 nv->firmware_options[1] = BIT_7 | BIT_5;
1167 nv->add_firmware_options[0] = BIT_5 | BIT_4;
1168 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1169 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1170 } else if (IS_QLA2100(ha)) {
1171 nv->firmware_options[0] = BIT_3 | BIT_1;
1172 nv->firmware_options[1] = BIT_5;
1173 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1176 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1177 nv->execution_throttle = __constant_cpu_to_le16(16);
1178 nv->retry_count = 8;
1179 nv->retry_delay = 1;
1181 nv->port_name[0] = 33;
1182 nv->port_name[3] = 224;
1183 nv->port_name[4] = 139;
1185 nv->login_timeout = 4;
1188 * Set default host adapter parameters
1190 nv->host_p[1] = BIT_2;
1191 nv->reset_delay = 5;
1192 nv->port_down_retry_count = 8;
1193 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1194 nv->link_down_timeout = 60;
1199 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1201 * The SN2 does not provide BIOS emulation which means you can't change
1202 * potentially bogus BIOS settings. Force the use of default settings
1203 * for link rate and frame size. Hope that the rest of the settings
1206 if (ia64_platform_is("sn2")) {
1207 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1209 nv->special_options[1] = BIT_7;
1213 /* Reset Initialization control block */
1214 memset(icb, 0, sizeof(init_cb_t));
1217 * Setup driver NVRAM options.
1219 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1220 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1221 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1222 nv->firmware_options[1] &= ~BIT_4;
1224 if (IS_QLA23XX(ha)) {
1225 nv->firmware_options[0] |= BIT_2;
1226 nv->firmware_options[0] &= ~BIT_3;
1228 if (IS_QLA2300(ha)) {
1229 if (ha->fb_rev == FPM_2310) {
1230 strcpy(ha->model_number, "QLA2310");
1232 strcpy(ha->model_number, "QLA2300");
1236 memcmp(nv->model_number, BINZERO,
1237 sizeof(nv->model_number)) != 0) {
1240 strncpy(ha->model_number, nv->model_number,
1241 sizeof(nv->model_number));
1242 st = en = ha->model_number;
1243 en += sizeof(nv->model_number) - 1;
1245 if (*en != 0x20 && *en != 0x00)
1252 index = (ha->pdev->subsystem_device & 0xff);
1253 if (index < QLA_MODEL_NAMES) {
1254 strcpy(ha->model_number,
1255 qla2x00_model_name[index]);
1257 qla2x00_model_desc[index];
1259 strcpy(ha->model_number, "QLA23xx");
1263 } else if (IS_QLA2200(ha)) {
1264 nv->firmware_options[0] |= BIT_2;
1265 strcpy(ha->model_number, "QLA22xx");
1266 } else /*if (IS_QLA2100(ha))*/ {
1267 strcpy(ha->model_number, "QLA2100");
1271 * Copy over NVRAM RISC parameter block to initialization control block.
1273 dptr1 = (uint8_t *)icb;
1274 dptr2 = (uint8_t *)&nv->parameter_block_version;
1275 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1277 *dptr1++ = *dptr2++;
1279 /* Copy 2nd half. */
1280 dptr1 = (uint8_t *)icb->add_firmware_options;
1281 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1283 *dptr1++ = *dptr2++;
1285 /* Prepare nodename */
1286 if ((icb->firmware_options[1] & BIT_6) == 0) {
1288 * Firmware will apply the following mask if the nodename was
1291 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1292 icb->node_name[0] &= 0xF0;
1296 * Set host adapter parameters.
1298 ha->nvram_version = nv->nvram_version;
1300 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1301 /* Always load RISC code on non ISP2[12]00 chips. */
1302 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1303 ha->flags.disable_risc_code_load = 0;
1304 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1305 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1306 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1308 ha->operating_mode =
1309 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1311 ha->fw_seriallink_options[0] = nv->seriallink_options[0];
1312 ha->fw_seriallink_options[1] = nv->seriallink_options[1];
1314 /* save HBA serial number */
1315 ha->serial0 = icb->port_name[5];
1316 ha->serial1 = icb->port_name[6];
1317 ha->serial2 = icb->port_name[7];
1318 memcpy(ha->node_name, icb->node_name, WWN_SIZE);
1320 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1322 ha->retry_count = nv->retry_count;
1324 /* Set minimum login_timeout to 4 seconds. */
1325 if (nv->login_timeout < ql2xlogintimeout)
1326 nv->login_timeout = ql2xlogintimeout;
1327 if (nv->login_timeout < 4)
1328 nv->login_timeout = 4;
1329 ha->login_timeout = nv->login_timeout;
1330 icb->login_timeout = nv->login_timeout;
1332 /* Set minimum RATOV to 200 tenths of a second. */
1335 ha->minimum_timeout =
1336 (ha->login_timeout * ha->retry_count) + nv->port_down_retry_count;
1337 ha->loop_reset_delay = nv->reset_delay;
1339 /* Will get the value from NVRAM. */
1340 ha->loop_down_timeout = LOOP_DOWN_TIMEOUT;
1342 /* Link Down Timeout = 0:
1344 * When Port Down timer expires we will start returning
1345 * I/O's to OS with "DID_NO_CONNECT".
1347 * Link Down Timeout != 0:
1349 * The driver waits for the link to come up after link down
1350 * before returning I/Os to OS with "DID_NO_CONNECT".
1352 if (nv->link_down_timeout == 0) {
1353 ha->loop_down_abort_time =
1354 (LOOP_DOWN_TIME - ha->loop_down_timeout);
1356 ha->link_down_timeout = nv->link_down_timeout;
1357 ha->loop_down_abort_time =
1358 (LOOP_DOWN_TIME - ha->link_down_timeout);
1361 ha->max_luns = MAX_LUNS;
1362 ha->max_probe_luns = le16_to_cpu(nv->max_luns_per_target);
1363 if (ha->max_probe_luns == 0)
1364 ha->max_probe_luns = MIN_LUNS;
1367 * Need enough time to try and get the port back.
1369 ha->port_down_retry_count = nv->port_down_retry_count;
1370 if (qlport_down_retry)
1371 ha->port_down_retry_count = qlport_down_retry;
1372 /* Set login_retry_count */
1373 ha->login_retry_count = nv->retry_count;
1374 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1375 ha->port_down_retry_count > 3)
1376 ha->login_retry_count = ha->port_down_retry_count;
1377 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1378 ha->login_retry_count = ha->port_down_retry_count;
1379 if (ql2xloginretrycount)
1380 ha->login_retry_count = ql2xloginretrycount;
1382 ha->binding_type = Bind;
1383 if (ha->binding_type != BIND_BY_PORT_NAME &&
1384 ha->binding_type != BIND_BY_PORT_ID) {
1385 qla_printk(KERN_WARNING, ha,
1386 "Invalid binding type specified (%d), "
1387 "defaulting to BIND_BY_PORT_NAME!!!\n", ha->binding_type);
1389 ha->binding_type = BIND_BY_PORT_NAME;
1393 * Setup ring parameters in initialization control block
1395 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1396 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1397 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1398 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1399 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1400 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1401 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1402 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1404 icb->lun_enables = __constant_cpu_to_le16(0);
1405 icb->command_resource_count = 0;
1406 icb->immediate_notify_resource_count = 0;
1407 icb->timeout = __constant_cpu_to_le16(0);
1409 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1411 icb->firmware_options[0] &= ~BIT_3;
1412 icb->add_firmware_options[0] &=
1413 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1414 icb->add_firmware_options[0] |= BIT_2;
1415 icb->response_accumulation_timer = 3;
1416 icb->interrupt_delay_timer = 5;
1418 ha->flags.process_response_queue = 1;
1422 * icb->add_firmware_options[0] &=
1423 * ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1424 * icb->add_firmware_options[0] |= (BIT_2 | BIT_0);
1426 timer_mode = icb->add_firmware_options[0] &
1427 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1428 if (timer_mode == 5) {
1429 DEBUG2(printk("scsi(%ld): ZIO enabled; timer delay "
1430 "(%d).\n", ha->host_no, ql2xintrdelaytimer));
1431 qla_printk(KERN_INFO, ha,
1432 "ZIO enabled; timer delay (%d).\n",
1433 ql2xintrdelaytimer);
1435 icb->interrupt_delay_timer = ql2xintrdelaytimer;
1437 ha->flags.process_response_queue = 1;
1442 DEBUG2_3(printk(KERN_WARNING
1443 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1449 * qla2x00_init_tgt_map
1450 * Initializes target map.
1453 * ha = adapter block pointer.
1459 qla2x00_init_tgt_map(scsi_qla_host_t *ha)
1463 for (t = 0; t < MAX_TARGETS; t++)
1464 TGT_Q(ha, t) = (os_tgt_t *)NULL;
1468 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1470 * @flags: allocation flags
1472 * Returns a pointer to the allocated fcport, or NULL, if none available.
1475 qla2x00_alloc_fcport(scsi_qla_host_t *ha, int flags)
1479 fcport = kmalloc(sizeof(fc_port_t), flags);
1483 /* Setup fcport template structure. */
1484 memset(fcport, 0, sizeof (fc_port_t));
1486 fcport->port_type = FCT_UNKNOWN;
1487 fcport->loop_id = FC_NO_LOOP_ID;
1488 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1489 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1490 fcport->flags = FCF_RLC_SUPPORT;
1491 INIT_LIST_HEAD(&fcport->fcluns);
1497 * qla2x00_configure_loop
1498 * Updates Fibre Channel Device Database with what is actually on loop.
1501 * ha = adapter block pointer.
1506 * 2 = database was full and device was not configured.
1509 qla2x00_configure_loop(scsi_qla_host_t *ha)
1512 unsigned long flags, save_flags;
1516 /* Get Initiator ID */
1517 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1518 rval = qla2x00_configure_hba(ha);
1519 if (rval != QLA_SUCCESS) {
1520 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1526 save_flags = flags = ha->dpc_flags;
1527 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1528 ha->host_no, flags));
1531 * If we have both an RSCN and PORT UPDATE pending then handle them
1532 * both at the same time.
1534 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1535 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1538 /* Determine what we need to do */
1539 if (ha->current_topology == ISP_CFG_FL &&
1540 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1542 ha->flags.rscn_queue_overflow = TRUE;
1543 set_bit(RSCN_UPDATE, &flags);
1545 } else if (ha->current_topology == ISP_CFG_F &&
1546 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1548 ha->flags.rscn_queue_overflow = TRUE;
1549 set_bit(RSCN_UPDATE, &flags);
1550 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1552 } else if (!ha->flags.online ||
1553 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1555 ha->flags.rscn_queue_overflow = TRUE;
1556 set_bit(RSCN_UPDATE, &flags);
1557 set_bit(LOCAL_LOOP_UPDATE, &flags);
1560 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1561 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1562 rval = QLA_FUNCTION_FAILED;
1564 rval = qla2x00_configure_local_loop(ha);
1568 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1569 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1570 rval = QLA_FUNCTION_FAILED;
1572 rval = qla2x00_configure_fabric(ha);
1576 if (rval == QLA_SUCCESS) {
1577 if (atomic_read(&ha->loop_down_timer) ||
1578 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1579 rval = QLA_FUNCTION_FAILED;
1581 qla2x00_config_os(ha);
1582 atomic_set(&ha->loop_state, LOOP_READY);
1584 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1589 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1590 __func__, ha->host_no));
1592 DEBUG3(printk("%s: exiting normally\n", __func__));
1595 /* Restore state if a resync event occured during processing */
1596 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1597 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1598 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1599 if (test_bit(RSCN_UPDATE, &save_flags))
1600 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1609 * qla2x00_configure_local_loop
1610 * Updates Fibre Channel Device Database with local loop devices.
1613 * ha = adapter block pointer.
1619 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1624 fc_port_t *fcport, *new_fcport;
1632 uint8_t loop_id_2100; /* ISP2100/ISP2200 -- 4 bytes. */
1633 uint16_t loop_id; /* ISP23XX -- 6 bytes. */
1635 #define MAX_ID_LIST_SIZE (sizeof(struct dev_id) * MAX_FIBRE_DEVICES)
1636 dma_addr_t id_list_dma;
1639 uint8_t domain, area, al_pa;
1644 entries = MAX_FIBRE_DEVICES;
1645 id_list = pci_alloc_consistent(ha->pdev, MAX_ID_LIST_SIZE,
1647 if (id_list == NULL) {
1648 DEBUG2(printk("scsi(%ld): Failed to allocate memory, No local "
1649 "loop\n", ha->host_no));
1651 qla_printk(KERN_WARNING, ha,
1652 "Memory Allocation failed - port_list");
1655 return (QLA_MEMORY_ALLOC_FAILED);
1657 memset(id_list, 0, MAX_ID_LIST_SIZE);
1659 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1660 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1662 /* Get list of logged in devices. */
1663 rval = qla2x00_get_id_list(ha, id_list, id_list_dma, &entries);
1664 if (rval != QLA_SUCCESS) {
1665 goto cleanup_allocation;
1668 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1669 ha->host_no, entries));
1670 DEBUG3(qla2x00_dump_buffer((uint8_t *)id_list,
1671 entries * sizeof(struct dev_id)));
1673 /* Allocate temporary fcport for any new fcports discovered. */
1674 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1675 if (new_fcport == NULL) {
1676 rval = QLA_MEMORY_ALLOC_FAILED;
1677 goto cleanup_allocation;
1679 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1682 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1684 list_for_each_entry(fcport, &ha->fcports, list) {
1685 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1686 fcport->port_type != FCT_BROADCAST &&
1687 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1689 DEBUG(printk("scsi(%ld): Marking port lost, "
1691 ha->host_no, fcport->loop_id));
1693 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1694 fcport->flags &= ~FCF_FARP_DONE;
1698 /* Add devices to port list. */
1699 id_iter = (char *)id_list;
1700 for (index = 0; index < entries; index++) {
1701 domain = ((struct dev_id *)id_iter)->domain;
1702 area = ((struct dev_id *)id_iter)->area;
1703 al_pa = ((struct dev_id *)id_iter)->al_pa;
1704 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1706 (uint16_t)((struct dev_id *)id_iter)->loop_id_2100;
1710 le16_to_cpu(((struct dev_id *)id_iter)->loop_id);
1714 /* Bypass reserved domain fields. */
1715 if ((domain & 0xf0) == 0xf0)
1718 /* Bypass if not same domain and area of adapter. */
1719 if (area != ha->d_id.b.area || domain != ha->d_id.b.domain)
1722 /* Bypass invalid local loop ID. */
1723 if (loop_id > LAST_LOCAL_LOOP_ID)
1726 /* Fill in member data. */
1727 new_fcport->d_id.b.domain = domain;
1728 new_fcport->d_id.b.area = area;
1729 new_fcport->d_id.b.al_pa = al_pa;
1730 new_fcport->loop_id = loop_id;
1731 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1732 if (rval2 != QLA_SUCCESS) {
1733 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1734 "information -- get_port_database=%x, "
1736 ha->host_no, rval2, new_fcport->loop_id));
1740 /* Check for matching device in port list. */
1743 list_for_each_entry(fcport, &ha->fcports, list) {
1744 if (memcmp(new_fcport->port_name, fcport->port_name,
1748 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1749 FCF_PERSISTENT_BOUND);
1750 fcport->loop_id = new_fcport->loop_id;
1751 fcport->port_type = new_fcport->port_type;
1752 fcport->d_id.b24 = new_fcport->d_id.b24;
1753 memcpy(fcport->node_name, new_fcport->node_name,
1761 /* New device, add to fcports list. */
1762 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1763 list_add_tail(&new_fcport->list, &ha->fcports);
1765 /* Allocate a new replacement fcport. */
1766 fcport = new_fcport;
1767 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1768 if (new_fcport == NULL) {
1769 rval = QLA_MEMORY_ALLOC_FAILED;
1770 goto cleanup_allocation;
1772 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1775 qla2x00_update_fcport(ha, fcport);
1781 pci_free_consistent(ha->pdev, MAX_ID_LIST_SIZE, id_list, id_list_dma);
1786 if (rval != QLA_SUCCESS) {
1787 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1788 "rval=%x\n", ha->host_no, rval));
1792 ha->device_flags |= DFLG_LOCAL_DEVICES;
1793 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
1800 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
1804 qla2x00_mark_all_devices_lost(ha);
1805 list_for_each_entry(fcport, &ha->fcports, list) {
1806 if (fcport->port_type != FCT_TARGET)
1809 qla2x00_update_fcport(ha, fcport);
1814 * qla2x00_update_fcport
1815 * Updates device on list.
1818 * ha = adapter block pointer.
1819 * fcport = port structure pointer.
1829 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
1832 unsigned long flags;
1836 fcport->login_retry = 0;
1837 fcport->port_login_retry_count = ha->port_down_retry_count *
1839 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
1841 fcport->flags &= ~FCF_LOGIN_NEEDED;
1844 * Check for outstanding cmd on tape Bypass LUN discovery if active
1847 if (fcport->flags & FCF_TAPE_PRESENT) {
1848 spin_lock_irqsave(&ha->hardware_lock, flags);
1849 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
1850 if ((sp = ha->outstanding_cmds[index]) != 0) {
1851 if (sp->fclun->fcport == fcport) {
1852 atomic_set(&fcport->state, FCS_ONLINE);
1853 spin_unlock_irqrestore(
1854 &ha->hardware_lock, flags);
1859 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1862 /* Do LUN discovery. */
1863 if (fcport->port_type == FCT_INITIATOR ||
1864 fcport->port_type == FCT_BROADCAST) {
1865 fcport->device_type = TYPE_PROCESSOR;
1867 qla2x00_lun_discovery(ha, fcport);
1869 atomic_set(&fcport->state, FCS_ONLINE);
1873 * qla2x00_lun_discovery
1874 * Issue SCSI inquiry command for LUN discovery.
1877 * ha: adapter state pointer.
1878 * fcport: FC port structure pointer.
1884 qla2x00_lun_discovery(scsi_qla_host_t *ha, fc_port_t *fcport)
1890 inq = pci_alloc_consistent(ha->pdev, sizeof(inq_cmd_rsp_t), &inq_dma);
1892 qla_printk(KERN_WARNING, ha,
1893 "Memory Allocation failed - INQ\n");
1897 /* If report LUN works, exit. */
1898 if (qla2x00_rpt_lun_discovery(ha, fcport, inq, inq_dma) !=
1900 for (lun = 0; lun < ha->max_probe_luns; lun++) {
1901 /* Configure LUN. */
1902 qla2x00_cfg_lun(ha, fcport, lun, inq, inq_dma);
1906 pci_free_consistent(ha->pdev, sizeof(inq_cmd_rsp_t), inq, inq_dma);
1910 * qla2x00_rpt_lun_discovery
1911 * Issue SCSI report LUN command for LUN discovery.
1914 * ha: adapter state pointer.
1915 * fcport: FC port structure pointer.
1918 * qla2x00 local function return status code.
1924 qla2x00_rpt_lun_discovery(scsi_qla_host_t *ha, fc_port_t *fcport,
1925 inq_cmd_rsp_t *inq, dma_addr_t inq_dma)
1930 rpt_lun_cmd_rsp_t *rlc;
1933 /* Assume a failed status */
1934 rval = QLA_FUNCTION_FAILED;
1936 /* No point in continuing if the device doesn't support RLC */
1937 if ((fcport->flags & FCF_RLC_SUPPORT) == 0)
1940 rlc = pci_alloc_consistent(ha->pdev, sizeof(rpt_lun_cmd_rsp_t),
1943 qla_printk(KERN_WARNING, ha,
1944 "Memory Allocation failed - RLC");
1945 return QLA_MEMORY_ALLOC_FAILED;
1948 rval = qla2x00_report_lun(ha, fcport, rlc, rlc_dma);
1949 if (rval != QLA_SUCCESS) {
1950 pci_free_consistent(ha->pdev, sizeof(rpt_lun_cmd_rsp_t), rlc,
1955 /* Always add a fc_lun_t structure for lun 0 -- mid-layer requirement */
1956 qla2x00_add_lun(fcport, 0);
1958 /* Configure LUN list. */
1959 len = be32_to_cpu(rlc->list.hdr.len);
1961 for (cnt = 0; cnt < len; cnt++) {
1962 lun = CHAR_TO_SHORT(rlc->list.lst[cnt].lsb,
1963 rlc->list.lst[cnt].msb.b);
1965 DEBUG3(printk("scsi(%ld): RLC lun = (%d)\n", ha->host_no, lun));
1967 /* We only support 0 through MAX_LUNS-1 range */
1968 if (lun < MAX_LUNS) {
1969 qla2x00_cfg_lun(ha, fcport, lun, inq, inq_dma);
1972 atomic_set(&fcport->state, FCS_ONLINE);
1974 pci_free_consistent(ha->pdev, sizeof(rpt_lun_cmd_rsp_t), rlc, rlc_dma);
1980 * qla2x00_report_lun
1981 * Issue SCSI report LUN command.
1984 * ha: adapter state pointer.
1985 * fcport: FC port structure pointer.
1986 * mem: pointer to dma memory object for report LUN IOCB
1990 * qla2x00 local function return status code.
1996 qla2x00_report_lun(scsi_qla_host_t *ha,
1997 fc_port_t *fcport, rpt_lun_cmd_rsp_t *rlc, dma_addr_t rlc_dma)
2001 uint16_t comp_status;
2002 uint16_t scsi_status;
2004 rval = QLA_FUNCTION_FAILED;
2006 for (retries = 3; retries; retries--) {
2007 memset(rlc, 0, sizeof(rpt_lun_cmd_rsp_t));
2008 rlc->p.cmd.entry_type = COMMAND_A64_TYPE;
2009 rlc->p.cmd.entry_count = 1;
2010 SET_TARGET_ID(ha, rlc->p.cmd.target, fcport->loop_id);
2011 rlc->p.cmd.control_flags =
2012 __constant_cpu_to_le16(CF_READ | CF_SIMPLE_TAG);
2013 rlc->p.cmd.scsi_cdb[0] = REPORT_LUNS;
2014 rlc->p.cmd.scsi_cdb[8] = MSB(sizeof(rpt_lun_lst_t));
2015 rlc->p.cmd.scsi_cdb[9] = LSB(sizeof(rpt_lun_lst_t));
2016 rlc->p.cmd.dseg_count = __constant_cpu_to_le16(1);
2017 rlc->p.cmd.timeout = __constant_cpu_to_le16(10);
2018 rlc->p.cmd.byte_count =
2019 __constant_cpu_to_le32(sizeof(rpt_lun_lst_t));
2020 rlc->p.cmd.dseg_0_address[0] = cpu_to_le32(
2021 LSD(rlc_dma + sizeof(sts_entry_t)));
2022 rlc->p.cmd.dseg_0_address[1] = cpu_to_le32(
2023 MSD(rlc_dma + sizeof(sts_entry_t)));
2024 rlc->p.cmd.dseg_0_length =
2025 __constant_cpu_to_le32(sizeof(rpt_lun_lst_t));
2027 rval = qla2x00_issue_iocb(ha, rlc, rlc_dma,
2028 sizeof(rpt_lun_cmd_rsp_t));
2030 comp_status = le16_to_cpu(rlc->p.rsp.comp_status);
2031 scsi_status = le16_to_cpu(rlc->p.rsp.scsi_status);
2033 if (rval != QLA_SUCCESS || comp_status != CS_COMPLETE ||
2034 scsi_status & SS_CHECK_CONDITION) {
2036 /* Device underrun, treat as OK. */
2037 if (rval == QLA_SUCCESS &&
2038 comp_status == CS_DATA_UNDERRUN &&
2039 scsi_status & SS_RESIDUAL_UNDER) {
2045 DEBUG(printk("scsi(%ld): RLC failed to issue iocb! "
2046 "fcport=[%04x/%p] rval=%x cs=%x ss=%x\n",
2047 ha->host_no, fcport->loop_id, fcport, rval,
2048 comp_status, scsi_status));
2050 rval = QLA_FUNCTION_FAILED;
2051 if (scsi_status & SS_CHECK_CONDITION) {
2052 DEBUG2(printk("scsi(%ld): RLC "
2053 "SS_CHECK_CONDITION Sense Data "
2054 "%02x %02x %02x %02x %02x %02x %02x %02x\n",
2056 rlc->p.rsp.req_sense_data[0],
2057 rlc->p.rsp.req_sense_data[1],
2058 rlc->p.rsp.req_sense_data[2],
2059 rlc->p.rsp.req_sense_data[3],
2060 rlc->p.rsp.req_sense_data[4],
2061 rlc->p.rsp.req_sense_data[5],
2062 rlc->p.rsp.req_sense_data[6],
2063 rlc->p.rsp.req_sense_data[7]));
2064 if (rlc->p.rsp.req_sense_data[2] ==
2066 fcport->flags &= ~(FCF_RLC_SUPPORT);
2080 * Configures LUN into fcport LUN list.
2083 * fcport: FC port structure pointer.
2090 qla2x00_cfg_lun(scsi_qla_host_t *ha, fc_port_t *fcport, uint16_t lun,
2091 inq_cmd_rsp_t *inq, dma_addr_t inq_dma)
2095 /* Bypass LUNs that failed. */
2096 if (qla2x00_inquiry(ha, fcport, lun, inq, inq_dma) != QLA_SUCCESS) {
2097 DEBUG2(printk("scsi(%ld): Failed inquiry - loop id=0x%04x "
2098 "lun=%d\n", ha->host_no, fcport->loop_id, lun));
2103 switch (inq->inq[0]) {
2105 case TYPE_PROCESSOR:
2110 case TYPE_MEDIUM_CHANGER:
2111 case TYPE_ENCLOSURE:
2116 fcport->flags |= FCF_TAPE_PRESENT;
2119 DEBUG2(printk("scsi(%ld): Unsupported lun type -- "
2120 "loop id=0x%04x lun=%d type=%x\n",
2121 ha->host_no, fcport->loop_id, lun, inq->inq[0]));
2125 fcport->device_type = inq->inq[0];
2126 fclun = qla2x00_add_lun(fcport, lun);
2128 if (fclun != NULL) {
2129 atomic_set(&fcport->state, FCS_ONLINE);
2137 * Adds LUN to database
2140 * fcport: FC port structure pointer.
2147 qla2x00_add_lun(fc_port_t *fcport, uint16_t lun)
2152 if (fcport == NULL) {
2153 DEBUG(printk("scsi: Unable to add lun to NULL port\n"));
2157 /* Allocate LUN if not already allocated. */
2159 list_for_each_entry(fclun, &fcport->fcluns, list) {
2160 if (fclun->lun == lun) {
2168 fclun = kmalloc(sizeof(fc_lun_t), GFP_ATOMIC);
2169 if (fclun == NULL) {
2171 "%s(): Memory Allocation failed - FCLUN\n",
2176 /* Setup LUN structure. */
2177 memset(fclun, 0, sizeof(fc_lun_t));
2179 fclun->fcport = fcport;
2180 fclun->o_fcport = fcport;
2181 fclun->device_type = fcport->device_type;
2182 atomic_set(&fcport->state, FCS_UNCONFIGURED);
2184 list_add_tail(&fclun->list, &fcport->fcluns);
2191 * Issue SCSI inquiry command.
2194 * ha = adapter block pointer.
2195 * fcport = FC port structure pointer.
2205 qla2x00_inquiry(scsi_qla_host_t *ha,
2206 fc_port_t *fcport, uint16_t lun, inq_cmd_rsp_t *inq, dma_addr_t inq_dma)
2210 uint16_t comp_status;
2211 uint16_t scsi_status;
2213 rval = QLA_FUNCTION_FAILED;
2215 for (retries = 3; retries; retries--) {
2216 memset(inq, 0, sizeof(inq_cmd_rsp_t));
2217 inq->p.cmd.entry_type = COMMAND_A64_TYPE;
2218 inq->p.cmd.entry_count = 1;
2219 inq->p.cmd.lun = cpu_to_le16(lun);
2220 SET_TARGET_ID(ha, inq->p.cmd.target, fcport->loop_id);
2221 inq->p.cmd.control_flags =
2222 __constant_cpu_to_le16(CF_READ | CF_SIMPLE_TAG);
2223 inq->p.cmd.scsi_cdb[0] = INQUIRY;
2224 inq->p.cmd.scsi_cdb[4] = INQ_DATA_SIZE;
2225 inq->p.cmd.dseg_count = __constant_cpu_to_le16(1);
2226 inq->p.cmd.timeout = __constant_cpu_to_le16(10);
2227 inq->p.cmd.byte_count =
2228 __constant_cpu_to_le32(INQ_DATA_SIZE);
2229 inq->p.cmd.dseg_0_address[0] = cpu_to_le32(
2230 LSD(inq_dma + sizeof(sts_entry_t)));
2231 inq->p.cmd.dseg_0_address[1] = cpu_to_le32(
2232 MSD(inq_dma + sizeof(sts_entry_t)));
2233 inq->p.cmd.dseg_0_length =
2234 __constant_cpu_to_le32(INQ_DATA_SIZE);
2236 DEBUG5(printk("scsi(%ld): Lun Inquiry - fcport=[%04x/%p],"
2238 ha->host_no, fcport->loop_id, fcport, lun));
2240 rval = qla2x00_issue_iocb(ha, inq, inq_dma,
2241 sizeof(inq_cmd_rsp_t));
2243 comp_status = le16_to_cpu(inq->p.rsp.comp_status);
2244 scsi_status = le16_to_cpu(inq->p.rsp.scsi_status);
2246 DEBUG5(printk("scsi(%ld): lun (%d) inquiry - "
2247 "inq[0]= 0x%x, comp status 0x%x, scsi status 0x%x, "
2249 ha->host_no, lun, inq->inq[0], comp_status, scsi_status,
2252 if (rval != QLA_SUCCESS || comp_status != CS_COMPLETE ||
2253 scsi_status & SS_CHECK_CONDITION) {
2255 DEBUG(printk("scsi(%ld): INQ failed to issue iocb! "
2256 "fcport=[%04x/%p] rval=%x cs=%x ss=%x\n",
2257 ha->host_no, fcport->loop_id, fcport, rval,
2258 comp_status, scsi_status));
2260 if (rval == QLA_SUCCESS)
2261 rval = QLA_FUNCTION_FAILED;
2263 if (scsi_status & SS_CHECK_CONDITION) {
2264 DEBUG2(printk("scsi(%ld): INQ "
2265 "SS_CHECK_CONDITION Sense Data "
2266 "%02x %02x %02x %02x %02x %02x %02x %02x\n",
2268 inq->p.rsp.req_sense_data[0],
2269 inq->p.rsp.req_sense_data[1],
2270 inq->p.rsp.req_sense_data[2],
2271 inq->p.rsp.req_sense_data[3],
2272 inq->p.rsp.req_sense_data[4],
2273 inq->p.rsp.req_sense_data[5],
2274 inq->p.rsp.req_sense_data[6],
2275 inq->p.rsp.req_sense_data[7]));
2278 /* Device underrun drop LUN. */
2279 if (comp_status == CS_DATA_UNDERRUN &&
2280 scsi_status & SS_RESIDUAL_UNDER) {
2293 * qla2x00_configure_fabric
2294 * Setup SNS devices with loop ID's.
2297 * ha = adapter block pointer.
2304 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2307 fc_port_t *fcport, *fcptemp;
2308 uint16_t next_loopid;
2309 uint16_t mb[MAILBOX_REGISTER_COUNT];
2310 LIST_HEAD(new_fcports);
2312 /* If FL port exists, then SNS is present */
2313 rval = qla2x00_get_port_name(ha, SNS_FL_PORT, NULL, 0);
2314 if (rval != QLA_SUCCESS) {
2315 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2316 "Port\n", ha->host_no));
2318 ha->device_flags &= ~SWITCH_FOUND;
2319 return (QLA_SUCCESS);
2322 /* Mark devices that need re-synchronization. */
2323 rval2 = qla2x00_device_resync(ha);
2324 if (rval2 == QLA_RSCNS_HANDLED) {
2325 /* No point doing the scan, just continue. */
2326 return (QLA_SUCCESS);
2329 /* Ensure we are logged into the SNS. */
2330 qla2x00_login_fabric(ha, SIMPLE_NAME_SERVER, 0xff, 0xff, 0xfc,
2332 if (mb[0] != MBS_COMMAND_COMPLETE) {
2333 qla_printk(KERN_INFO, ha,
2334 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2335 "mb[2]=%x mb[6]=%x mb[7]=%x\n", SIMPLE_NAME_SERVER,
2336 mb[0], mb[1], mb[2], mb[6], mb[7]);
2337 return (QLA_FUNCTION_FAILED);
2340 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2341 if (qla2x00_rft_id(ha)) {
2343 DEBUG2(printk("scsi(%ld): Register FC-4 "
2344 "TYPE failed.\n", ha->host_no));
2346 if (qla2x00_rff_id(ha)) {
2348 DEBUG2(printk("scsi(%ld): Register FC-4 "
2349 "Features failed.\n", ha->host_no));
2351 if (qla2x00_rnn_id(ha)) {
2353 DEBUG2(printk("scsi(%ld): Register Node Name "
2354 "failed.\n", ha->host_no));
2355 } else if (qla2x00_rsnn_nn(ha)) {
2357 DEBUG2(printk("scsi(%ld): Register Symbolic "
2358 "Node Name failed.\n", ha->host_no));
2362 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2363 if (rval != QLA_SUCCESS)
2367 * Logout all previous fabric devices marked lost, except
2370 list_for_each_entry(fcport, &ha->fcports, list) {
2371 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2374 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2377 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2378 qla2x00_mark_device_lost(ha, fcport,
2379 ql2xplogiabsentdevice);
2380 if (fcport->loop_id != FC_NO_LOOP_ID &&
2381 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2382 fcport->port_type != FCT_INITIATOR &&
2383 fcport->port_type != FCT_BROADCAST) {
2385 qla2x00_fabric_logout(ha,
2387 fcport->loop_id = FC_NO_LOOP_ID;
2392 /* Starting free loop ID. */
2393 next_loopid = ha->min_external_loopid;
2396 * Scan through our port list and login entries that need to be
2399 list_for_each_entry(fcport, &ha->fcports, list) {
2400 if (atomic_read(&ha->loop_down_timer) ||
2401 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2404 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2405 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2408 if (fcport->loop_id == FC_NO_LOOP_ID) {
2409 fcport->loop_id = next_loopid;
2410 rval = qla2x00_find_new_loop_id(ha, fcport);
2411 if (rval != QLA_SUCCESS) {
2412 /* Ran out of IDs to use */
2417 /* Login and update database */
2418 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2421 /* Exit if out of loop IDs. */
2422 if (rval != QLA_SUCCESS) {
2427 * Login and add the new devices to our port list.
2429 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2430 if (atomic_read(&ha->loop_down_timer) ||
2431 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2434 /* Find a new loop ID to use. */
2435 fcport->loop_id = next_loopid;
2436 rval = qla2x00_find_new_loop_id(ha, fcport);
2437 if (rval != QLA_SUCCESS) {
2438 /* Ran out of IDs to use */
2442 /* Login and update database */
2443 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2445 /* Remove device from the new list and add it to DB */
2446 list_del(&fcport->list);
2447 list_add_tail(&fcport->list, &ha->fcports);
2451 /* Free all new device structures not processed. */
2452 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2453 list_del(&fcport->list);
2458 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2459 "rval=%d\n", ha->host_no, rval));
2467 * qla2x00_find_all_fabric_devs
2470 * ha = adapter block pointer.
2471 * dev = database device entry pointer.
2480 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2484 fc_port_t *fcport, *new_fcport;
2489 int first_dev, last_dev;
2490 port_id_t wrap, nxt_d_id;
2494 /* Try GID_PT to get device list, else GAN. */
2495 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2498 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2499 "on GA_NXT\n", ha->host_no));
2501 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2502 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2505 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2508 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2515 /* Allocate temporary fcport for any new fcports discovered. */
2516 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2517 if (new_fcport == NULL) {
2520 return (QLA_MEMORY_ALLOC_FAILED);
2522 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2524 /* Set start port ID scan at adapter ID. */
2528 /* Starting free loop ID. */
2529 loop_id = ha->min_external_loopid;
2531 for (; loop_id <= ha->last_loop_id; loop_id++) {
2532 if (RESERVED_LOOP_ID(loop_id))
2535 if (atomic_read(&ha->loop_down_timer) ||
2536 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2541 wrap.b24 = new_fcport->d_id.b24;
2543 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2544 memcpy(new_fcport->node_name,
2545 swl[swl_idx].node_name, WWN_SIZE);
2546 memcpy(new_fcport->port_name,
2547 swl[swl_idx].port_name, WWN_SIZE);
2549 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2555 /* Send GA_NXT to the switch */
2556 rval = qla2x00_ga_nxt(ha, new_fcport);
2557 if (rval != QLA_SUCCESS) {
2562 /* If wrap on switch device list, exit. */
2564 wrap.b24 = new_fcport->d_id.b24;
2566 } else if (new_fcport->d_id.b24 == wrap.b24) {
2567 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2568 ha->host_no, new_fcport->d_id.b.domain,
2569 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2573 /* Bypass if host adapter. */
2574 if (new_fcport->d_id.b24 == ha->d_id.b24)
2577 /* Bypass reserved domain fields. */
2578 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2581 /* Bypass if same domain and area of adapter. */
2582 if ((new_fcport->d_id.b24 & 0xffff00) ==
2583 (ha->d_id.b24 & 0xffff00))
2586 /* Locate matching device in database. */
2588 list_for_each_entry(fcport, &ha->fcports, list) {
2589 if (memcmp(new_fcport->port_name, fcport->port_name,
2596 * If device was not a fabric device before.
2598 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2599 fcport->d_id.b24 = new_fcport->d_id.b24;
2600 fcport->loop_id = FC_NO_LOOP_ID;
2601 fcport->flags |= (FCF_FABRIC_DEVICE |
2603 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2608 * If address the same and state FCS_ONLINE, nothing
2611 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2612 atomic_read(&fcport->state) == FCS_ONLINE) {
2617 * Port ID changed or device was marked to be updated;
2618 * Log it out if still logged in and mark it for
2621 fcport->d_id.b24 = new_fcport->d_id.b24;
2622 fcport->flags |= FCF_LOGIN_NEEDED;
2623 if (fcport->loop_id != FC_NO_LOOP_ID &&
2624 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2625 fcport->port_type != FCT_INITIATOR &&
2626 fcport->port_type != FCT_BROADCAST) {
2627 qla2x00_fabric_logout(ha, fcport->loop_id);
2628 fcport->loop_id = FC_NO_LOOP_ID;
2637 /* If device was not in our fcports list, then add it. */
2638 list_add_tail(&new_fcport->list, new_fcports);
2640 /* Allocate a new replacement fcport. */
2641 nxt_d_id.b24 = new_fcport->d_id.b24;
2642 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2643 if (new_fcport == NULL) {
2646 return (QLA_MEMORY_ALLOC_FAILED);
2648 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2649 new_fcport->d_id.b24 = nxt_d_id.b24;
2658 if (!list_empty(new_fcports))
2659 ha->device_flags |= DFLG_FABRIC_DEVICES;
2665 * qla2x00_find_new_loop_id
2666 * Scan through our port list and find a new usable loop ID.
2669 * ha: adapter state pointer.
2670 * dev: port structure pointer.
2673 * qla2x00 local function return status code.
2679 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2684 uint16_t first_loop_id;
2688 /* Save starting loop ID. */
2689 first_loop_id = dev->loop_id;
2692 /* Skip loop ID if already used by adapter. */
2693 if (dev->loop_id == ha->loop_id) {
2697 /* Skip reserved loop IDs. */
2698 while (RESERVED_LOOP_ID(dev->loop_id)) {
2702 /* Reset loop ID if passed the end. */
2703 if (dev->loop_id > ha->last_loop_id) {
2704 /* first loop ID. */
2705 dev->loop_id = ha->min_external_loopid;
2708 /* Check for loop ID being already in use. */
2711 list_for_each_entry(fcport, &ha->fcports, list) {
2712 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2713 /* ID possibly in use */
2719 /* If not in use then it is free to use. */
2724 /* ID in use. Try next value. */
2727 /* If wrap around. No free ID to use. */
2728 if (dev->loop_id == first_loop_id) {
2729 dev->loop_id = FC_NO_LOOP_ID;
2730 rval = QLA_FUNCTION_FAILED;
2739 * qla2x00_device_resync
2740 * Marks devices in the database that needs resynchronization.
2743 * ha = adapter block pointer.
2749 qla2x00_device_resync(scsi_qla_host_t *ha)
2755 uint32_t rscn_entry;
2756 uint8_t rscn_out_iter;
2760 rval = QLA_RSCNS_HANDLED;
2762 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2763 ha->flags.rscn_queue_overflow) {
2765 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2766 format = MSB(MSW(rscn_entry));
2767 d_id.b.domain = LSB(MSW(rscn_entry));
2768 d_id.b.area = MSB(LSW(rscn_entry));
2769 d_id.b.al_pa = LSB(LSW(rscn_entry));
2771 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2772 "[%02x/%02x%02x%02x].\n",
2773 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2774 d_id.b.area, d_id.b.al_pa));
2777 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2778 ha->rscn_out_ptr = 0;
2780 /* Skip duplicate entries. */
2781 for (rscn_out_iter = ha->rscn_out_ptr;
2782 !ha->flags.rscn_queue_overflow &&
2783 rscn_out_iter != ha->rscn_in_ptr;
2784 rscn_out_iter = (rscn_out_iter ==
2785 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2787 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2790 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2791 "entry found at [%d].\n", ha->host_no,
2794 ha->rscn_out_ptr = rscn_out_iter;
2797 /* Queue overflow, set switch default case. */
2798 if (ha->flags.rscn_queue_overflow) {
2799 DEBUG(printk("scsi(%ld): device_resync: rscn "
2800 "overflow.\n", ha->host_no));
2803 ha->flags.rscn_queue_overflow = 0;
2808 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) &&
2809 !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
2810 ha->flags.init_done) {
2811 /* Handle port RSCN via asyncronous IOCBs */
2812 rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
2814 if (rval2 == QLA_SUCCESS)
2828 ha->rscn_out_ptr = ha->rscn_in_ptr;
2834 /* Abort any outstanding IO descriptors. */
2835 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2836 qla2x00_cancel_io_descriptors(ha);
2838 list_for_each_entry(fcport, &ha->fcports, list) {
2839 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2840 (fcport->d_id.b24 & mask) != d_id.b24 ||
2841 fcport->port_type == FCT_BROADCAST)
2844 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2846 fcport->port_type != FCT_INITIATOR) {
2847 atomic_set(&fcport->state,
2851 fcport->flags &= ~FCF_FARP_DONE;
2858 * qla2x00_fabric_dev_login
2859 * Login fabric target device and update FC port database.
2862 * ha: adapter state pointer.
2863 * fcport: port structure list pointer.
2864 * next_loopid: contains value of a new loop ID that can be used
2865 * by the next login attempt.
2868 * qla2x00 local function return status code.
2874 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2875 uint16_t *next_loopid)
2883 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2884 if (rval == QLA_SUCCESS) {
2885 rval = qla2x00_get_port_database(ha, fcport, BIT_1 | BIT_0);
2886 if (rval != QLA_SUCCESS) {
2887 qla2x00_fabric_logout(ha, fcport->loop_id);
2889 qla2x00_update_fcport(ha, fcport);
2897 * qla2x00_fabric_login
2898 * Issue fabric login command.
2901 * ha = adapter block pointer.
2902 * device = pointer to FC device type structure.
2905 * 0 - Login successfully
2907 * 2 - Initiator device
2911 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2912 uint16_t *next_loopid)
2916 uint16_t tmp_loopid;
2917 uint16_t mb[MAILBOX_REGISTER_COUNT];
2923 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2924 "for port %02x%02x%02x.\n",
2925 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2926 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2928 /* Login fcport on switch. */
2929 qla2x00_login_fabric(ha, fcport->loop_id,
2930 fcport->d_id.b.domain, fcport->d_id.b.area,
2931 fcport->d_id.b.al_pa, mb, BIT_0);
2932 if (mb[0] == MBS_PORT_ID_USED) {
2934 * Device has another loop ID. The firmware team
2935 * recommends us to perform an implicit login with the
2936 * specified ID again. The ID we just used is save here
2937 * so we return with an ID that can be tried by the
2941 tmp_loopid = fcport->loop_id;
2942 fcport->loop_id = mb[1];
2944 DEBUG(printk("Fabric Login: port in use - next "
2945 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2946 fcport->loop_id, fcport->d_id.b.domain,
2947 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2949 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2954 /* A retry occurred before. */
2955 *next_loopid = tmp_loopid;
2958 * No retry occurred before. Just increment the
2959 * ID value for next login.
2961 *next_loopid = (fcport->loop_id + 1);
2964 if (mb[1] & BIT_0) {
2965 fcport->port_type = FCT_INITIATOR;
2967 fcport->port_type = FCT_TARGET;
2968 if (mb[1] & BIT_1) {
2969 fcport->flags |= FCF_TAPE_PRESENT;
2975 } else if (mb[0] == MBS_LOOP_ID_USED) {
2977 * Loop ID already used, try next loop ID.
2980 rval = qla2x00_find_new_loop_id(ha, fcport);
2981 if (rval != QLA_SUCCESS) {
2982 /* Ran out of loop IDs to use */
2985 } else if (mb[0] == MBS_COMMAND_ERROR) {
2987 * Firmware possibly timed out during login. If NO
2988 * retries are left to do then the device is declared
2991 *next_loopid = fcport->loop_id;
2992 qla2x00_fabric_logout(ha, fcport->loop_id);
2993 fcport->loop_id = FC_NO_LOOP_ID;
2999 * unrecoverable / not handled error
3001 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3002 "loop_id=%x jiffies=%lx.\n",
3003 __func__, ha->host_no, mb[0],
3004 fcport->d_id.b.domain, fcport->d_id.b.area,
3005 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3007 *next_loopid = fcport->loop_id;
3008 qla2x00_fabric_logout(ha, fcport->loop_id);
3009 fcport->loop_id = FC_NO_LOOP_ID;
3010 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
3021 * qla2x00_local_device_login
3022 * Issue local device login command.
3025 * ha = adapter block pointer.
3026 * loop_id = loop id of device to login to.
3028 * Returns (Where's the #define!!!!):
3029 * 0 - Login successfully
3034 qla2x00_local_device_login(scsi_qla_host_t *ha, uint16_t loop_id)
3037 uint16_t mb[MAILBOX_REGISTER_COUNT];
3039 memset(mb, 0, sizeof(mb));
3040 rval = qla2x00_login_local_device(ha, loop_id, mb, BIT_0);
3041 if (rval == QLA_SUCCESS) {
3042 /* Interrogate mailbox registers for any errors */
3043 if (mb[0] == MBS_COMMAND_ERROR)
3045 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3046 /* device not in PCB table */
3054 * qla2x00_loop_resync
3055 * Resync with fibre channel devices.
3058 * ha = adapter block pointer.
3064 qla2x00_loop_resync(scsi_qla_host_t *ha)
3071 atomic_set(&ha->loop_state, LOOP_UPDATE);
3072 qla2x00_stats.loop_resync++;
3073 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3074 if (ha->flags.online) {
3075 if (!(rval = qla2x00_fw_ready(ha))) {
3076 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3080 atomic_set(&ha->loop_state, LOOP_UPDATE);
3083 * Issue marker command only when we are going
3084 * to start the I/O .
3086 ha->marker_needed = 1;
3088 /* Remap devices on Loop. */
3089 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3091 qla2x00_configure_loop(ha);
3093 } while (!atomic_read(&ha->loop_down_timer) &&
3094 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3096 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3098 qla2x00_restart_queues(ha, TRUE);
3101 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3102 return (QLA_FUNCTION_FAILED);
3106 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3113 * qla2x00_restart_queues
3114 * Restart device queues.
3117 * ha = adapter block pointer.
3120 * Kernel/Interrupt context.
3123 qla2x00_restart_queues(scsi_qla_host_t *ha, uint8_t flush)
3126 int retry_q_cnt = 0;
3127 int pending_q_cnt = 0;
3128 struct list_head *list, *temp;
3129 unsigned long flags = 0;
3131 clear_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
3133 /* start pending queue */
3134 pending_q_cnt = ha->qthreads;
3136 spin_lock_irqsave(&ha->list_lock,flags);
3137 list_for_each_safe(list, temp, &ha->pending_queue) {
3138 sp = list_entry(list, srb_t, list);
3140 if ((sp->flags & SRB_TAPE))
3144 * When time expire return request back to OS as BUSY
3146 __del_from_pending_queue(ha, sp);
3147 sp->cmd->result = DID_BUS_BUSY << 16;
3148 sp->cmd->host_scribble = (unsigned char *)NULL;
3149 __add_to_done_queue(ha, sp);
3151 spin_unlock_irqrestore(&ha->list_lock, flags);
3153 if (!list_empty(&ha->pending_queue))
3158 * Clear out our retry queue
3161 spin_lock_irqsave(&ha->list_lock, flags);
3162 retry_q_cnt = ha->retry_q_cnt;
3163 list_for_each_safe(list, temp, &ha->retry_queue) {
3164 sp = list_entry(list, srb_t, list);
3165 /* when time expire return request back to OS as BUSY */
3166 __del_from_retry_queue(ha, sp);
3167 sp->cmd->result = DID_BUS_BUSY << 16;
3168 sp->cmd->host_scribble = (unsigned char *)NULL;
3169 __add_to_done_queue(ha, sp);
3171 spin_unlock_irqrestore(&ha->list_lock, flags);
3173 DEBUG2(printk("%s(%ld): callback %d commands.\n",
3179 DEBUG2(printk("%s(%ld): active=%ld, retry=%d, pending=%d, "
3180 "done=%ld, scsi retry=%d commands.\n",
3187 ha->scsi_retry_q_cnt);)
3189 if (!list_empty(&ha->done_queue))
3194 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
3200 list_for_each_entry(fcport, &ha->fcports, list) {
3201 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
3204 qla2x00_update_fcport(ha, fcport);
3205 fcport->flags &= ~FCF_RESCAN_NEEDED;
3209 qla2x00_probe_for_all_luns(ha);
3211 /* Update OS target and lun structures if necessary. */
3213 qla2x00_config_os(ha);
3220 * Setup OS target and LUN structures.
3223 * ha = adapter state pointer.
3229 qla2x00_config_os(scsi_qla_host_t *ha)
3237 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
3238 if ((tq = TGT_Q(ha, tgt)) == NULL)
3241 clear_bit(TQF_ONLINE, &tq->flags);
3244 list_for_each_entry(fcport, &ha->fcports, list) {
3245 if (atomic_read(&fcport->state) != FCS_ONLINE ||
3246 fcport->port_type == FCT_INITIATOR ||
3247 fcport->port_type == FCT_BROADCAST) {
3248 fcport->os_target_id = MAX_TARGETS;
3252 if (fcport->flags & FCF_FO_MASKED) {
3256 /* Bind FC port to OS target number. */
3257 if (qla2x00_fcport_bind(ha, fcport) == MAX_TARGETS) {
3261 /* Bind FC LUN to OS LUN number. */
3262 list_for_each_entry(fclun, &fcport->fcluns, list) {
3263 qla2x00_fclun_bind(ha, fcport, fclun);
3269 * qla2x00_fcport_bind
3270 * Locates a target number for FC port.
3273 * ha = adapter state pointer.
3274 * fcport = FC port structure pointer.
3283 qla2x00_fcport_bind(scsi_qla_host_t *ha, fc_port_t *fcport)
3289 /* Check for persistent binding. */
3290 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
3291 if ((tq = TGT_Q(ha, tgt)) == NULL)
3295 switch (ha->binding_type) {
3296 case BIND_BY_PORT_ID:
3297 if (fcport->d_id.b24 == tq->d_id.b24) {
3298 memcpy(tq->node_name, fcport->node_name,
3300 memcpy(tq->port_name, fcport->port_name,
3305 case BIND_BY_PORT_NAME:
3306 if (memcmp(fcport->port_name, tq->port_name,
3309 * In case of persistent binding, update the
3312 memcpy(tq->node_name, fcport->node_name,
3322 /* TODO: honor the ConfigRequired flag */
3323 if (tgt == MAX_TARGETS) {
3324 /* Check if targetID 0 available. */
3327 if (TGT_Q(ha, tgt) != NULL) {
3328 /* Locate first free target for device. */
3329 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
3330 if (TGT_Q(ha, tgt) == NULL) {
3335 if (tgt != MAX_TARGETS) {
3336 if ((tq = qla2x00_tgt_alloc(ha, tgt)) != NULL) {
3337 memcpy(tq->node_name, fcport->node_name,
3339 memcpy(tq->port_name, fcport->port_name,
3341 tq->d_id.b24 = fcport->d_id.b24;
3346 /* Reset target numbers incase it changed. */
3347 fcport->os_target_id = tgt;
3348 if (tgt != MAX_TARGETS && tq != NULL) {
3349 DEBUG2(printk("scsi(%ld): Assigning target ID=%02d @ %p to "
3350 "loop id=0x%04x, port state=0x%x, port down retry=%d\n",
3351 ha->host_no, tgt, tq, fcport->loop_id,
3352 atomic_read(&fcport->state),
3353 atomic_read(&fcport->port_down_timer)));
3355 fcport->tgt_queue = tq;
3356 fcport->flags |= FCF_PERSISTENT_BOUND;
3357 tq->fcport = fcport;
3358 set_bit(TQF_ONLINE, &tq->flags);
3359 tq->port_down_retry_count = ha->port_down_retry_count;
3362 qla2x00_get_lun_mask_from_config(ha, fcport, tgt, 0);
3366 if (tgt == MAX_TARGETS) {
3367 qla_printk(KERN_WARNING, ha,
3368 "Unable to bind fcport, loop_id=%x\n", fcport->loop_id);
3375 * qla2x00_fclun_bind
3376 * Binds all FC device LUNS to OS LUNS.
3379 * ha: adapter state pointer.
3380 * fcport: FC port structure pointer.
3389 qla2x00_fclun_bind(scsi_qla_host_t *ha, fc_port_t *fcport, fc_lun_t *fclun)
3395 tgt = fcport->os_target_id;
3399 if (lun >= MAX_LUNS) {
3400 DEBUG2(printk("scsi(%ld): Unable to bind lun, invalid "
3401 "lun=(%x).\n", ha->host_no, lun));
3405 /* Always alloc LUN 0 so kernel will scan past LUN 0. */
3406 if (lun != 0 && (EXT_IS_LUN_BIT_SET(&(fcport->lun_mask), lun))) {
3410 if ((lq = qla2x00_lun_alloc(ha, tgt, lun)) == NULL) {
3411 qla_printk(KERN_WARNING, ha,
3412 "Unable to bind fclun, loop_id=%x lun=%x\n",
3413 fcport->loop_id, lun);
3424 * Allocate and pre-initialize target queue.
3427 * ha = adapter block pointer.
3428 * t = SCSI target number.
3437 qla2x00_tgt_alloc(scsi_qla_host_t *ha, uint16_t tgt)
3442 * If SCSI addressing OK, allocate TGT queue and lock.
3444 if (tgt >= MAX_TARGETS) {
3445 DEBUG2(printk("scsi(%ld): Unable to allocate target, invalid "
3446 "target number %d.\n", ha->host_no, tgt));
3450 tq = TGT_Q(ha, tgt);
3452 tq = kmalloc(sizeof(os_tgt_t), GFP_ATOMIC);
3454 DEBUG2(printk("scsi(%ld): Alloc Target %d @ %p\n",
3455 ha->host_no, tgt, tq));
3457 memset(tq, 0, sizeof(os_tgt_t));
3460 TGT_Q(ha, tgt) = tq;
3464 tq->port_down_retry_count = ha->port_down_retry_count;
3466 qla_printk(KERN_WARNING, ha,
3467 "Unable to allocate target.\n");
3476 * Frees target and LUN queues.
3479 * ha = adapter block pointer.
3480 * t = SCSI target number.
3486 qla2x00_tgt_free(scsi_qla_host_t *ha, uint16_t tgt)
3492 * If SCSI addressing OK, allocate TGT queue and lock.
3494 if (tgt >= MAX_TARGETS) {
3495 DEBUG2(printk("scsi(%ld): Unable to de-allocate target, "
3496 "invalid target number %d.\n", ha->host_no, tgt));
3501 tq = TGT_Q(ha, tgt);
3503 TGT_Q(ha, tgt) = NULL;
3505 /* Free LUN structures. */
3506 for (lun = 0; lun < MAX_LUNS; lun++)
3507 qla2x00_lun_free(ha, tgt, lun);
3517 * Allocate and initialize LUN queue.
3520 * ha = adapter block pointer.
3521 * t = SCSI target number.
3531 qla2x00_lun_alloc(scsi_qla_host_t *ha, uint16_t tgt, uint16_t lun)
3536 * If SCSI addressing OK, allocate LUN queue.
3538 if (tgt >= MAX_TARGETS || lun >= MAX_LUNS || TGT_Q(ha, tgt) == NULL) {
3539 DEBUG2(printk("scsi(%ld): Unable to allocate lun, invalid "
3540 "parameter.\n", ha->host_no));
3545 lq = LUN_Q(ha, tgt, lun);
3547 lq = kmalloc(sizeof(os_lun_t), GFP_ATOMIC);
3549 DEBUG2(printk("scsi(%ld): Alloc Lun %d @ tgt %d.\n",
3550 ha->host_no, lun, tgt));
3552 memset(lq, 0, sizeof (os_lun_t));
3553 LUN_Q(ha, tgt, lun) = lq;
3556 * The following lun queue initialization code
3557 * must be duplicated in alloc_ioctl_mem function
3560 lq->q_state = LUN_STATE_READY;
3561 spin_lock_init(&lq->q_lock);
3566 qla_printk(KERN_WARNING, ha, "Unable to allocate lun.\n");
3577 * ha = adapter block pointer.
3578 * t = SCSI target number.
3584 qla2x00_lun_free(scsi_qla_host_t *ha, uint16_t tgt, uint16_t lun)
3589 * If SCSI addressing OK, allocate TGT queue and lock.
3591 if (tgt >= MAX_TARGETS || lun >= MAX_LUNS) {
3592 DEBUG2(printk("scsi(%ld): Unable to deallocate lun, invalid "
3593 "parameter.\n", ha->host_no));
3598 if (TGT_Q(ha, tgt) != NULL && (lq = LUN_Q(ha, tgt, lun)) != NULL) {
3599 LUN_Q(ha, tgt, lun) = NULL;
3609 * qla2x00_get_lun_mask_from_config
3610 * Get lun mask from the configuration parameters.
3611 * Bit order is little endian.
3614 * ha -- Host adapter
3615 * tgt -- target/device number
3616 * port -- pointer to port
3619 qla2x00_get_lun_mask_from_config(scsi_qla_host_t *ha,
3620 fc_port_t *fcport, uint16_t tgt, uint16_t dev_no)
3622 char propbuf[60]; /* size of search string */
3624 lun_bit_mask_t lun_mask, *mask_ptr = &lun_mask;
3626 /* Get "target-N-device-N-lun-mask" as a 256 bit lun_mask*/
3627 sprintf(propbuf, "scsi-qla%ld-tgt-%d-di-%d-lun-disabled",
3628 ha->instance, tgt, dev_no);
3630 rval = qla2x00_get_prop_xstr(ha, propbuf,
3631 (uint8_t *)&lun_mask, sizeof(lun_bit_mask_t));
3632 if (rval == sizeof(lun_bit_mask_t)) {
3633 memset(&fcport->lun_mask, 0, sizeof(lun_bit_mask_t));
3634 for (lun = 8 * sizeof(lun_bit_mask_t) - 1, bit = 0;
3635 lun >= 0; lun--, bit++) {
3636 if (EXT_IS_LUN_BIT_SET(mask_ptr, lun))
3637 EXT_SET_LUN_BIT((&fcport->lun_mask), bit);
3640 DEBUG3(printk("scsi(%ld): returning lun mask for fcport "
3641 "%02x%02x%02x%02x%02x%02x%02x%02x:\n",
3643 fcport->port_name[0], fcport->port_name[1],
3644 fcport->port_name[2], fcport->port_name[3],
3645 fcport->port_name[4], fcport->port_name[5],
3646 fcport->port_name[6], fcport->port_name[7]));
3647 DEBUG3(qla2x00_dump_buffer((uint8_t *)&fcport->lun_mask,
3648 sizeof(lun_bit_mask_t));)
3654 * qla2x00_bstr_to_hex
3655 * Convert hex byte string to number.
3658 * s = byte string pointer.
3659 * bp = byte pointer for number.
3660 * size = number of bytes.
3663 * Kernel/Interrupt context.
3666 qla2x00_bstr_to_hex(char *s, uint8_t *bp, int size)
3671 for (cnt = 0; *s != '\0' && cnt / 2 < size; cnt++) {
3672 if (*s >= 'A' && *s <= 'F') {
3673 n = (*s++ - 'A') + 10;
3674 } else if (*s >= 'a' && *s <= 'f') {
3675 n = (*s++ - 'a') + 10;
3676 } else if (*s >= '0' && *s <= '9') {
3689 /* fixme(dg) Need to swap data little endian */
3695 * qla2x00_get_prop_xstr
3696 * Get a string property value for the specified property name and
3697 * convert from the property string found in the configuration file,
3698 * which are ASCII characters representing nibbles, 2 characters represent
3699 * the hexdecimal value for a byte in the byte array.
3700 * The byte array is initialized to zero.
3701 * The resulting converted value is in big endian format (MSB at byte0).
3704 * ha = adapter state pointer.
3705 * propname = property name pointer.
3706 * propval = pointer where to store converted property val.
3707 * size = max or expected size of 'propval' array.
3710 * 0 = empty value string or invalid character in string
3711 * >0 = count of characters converted
3712 * -1 = property not found
3718 qla2x00_get_prop_xstr(scsi_qla_host_t *ha,
3719 char *propname, uint8_t *propval, int size)
3723 static char buf[LINESIZE];
3725 /* Get the requested property string */
3726 rval = qla2x00_find_propname(ha, propname, buf, ha->cmdline, size*2);
3727 DEBUG3(printk("%s(): Ret rval from find propname = %d\n",
3732 if (*propstr == '=')
3733 propstr++; /* ignore equal sign */
3735 if (rval == 0) { /* not found */
3739 rval = qla2x00_bstr_to_hex(propstr, (uint8_t *)propval, size);
3741 /* Invalid character in value string */
3742 qla_printk(KERN_INFO, ha,
3743 "%s(): %s Invalid hex string for property\n",
3746 qla_printk(KERN_INFO, ha,
3747 " Invalid string - %s\n",
3755 * qla2x00_find_propname
3756 * Get property in database.
3759 * ha = adapter structure pointer.
3760 * db = pointer to database
3761 * propstr = pointer to dest array for string
3762 * propname = name of property to search for.
3763 * siz = size of property
3767 * size = index of property
3773 qla2x00_find_propname(scsi_qla_host_t *ha,
3774 char *propname, char *propstr,
3779 /* find the specified string */
3781 /* find the property name */
3782 if ((cp = strstr(db,propname)) != NULL) {
3783 while ((*cp) && *cp != '=')
3786 strncpy(propstr, cp, siz+1);
3787 propstr[siz+1] = '\0';
3788 DEBUG(printk("qla2x00_find_propname: found "
3789 "property = {%s}\n",
3791 return (siz); /* match */
3801 * qla2x00_get_prop_16chars
3802 * Get an 8-byte property value for the specified property name by
3803 * converting from the property string found in the configuration file.
3804 * The resulting converted value is in big endian format (MSB at byte0).
3807 * ha = adapter state pointer.
3808 * propname = property name pointer.
3809 * propval = pointer to location for the converted property val.
3810 * db = pointer to database
3813 * 0 = value returned successfully.
3819 qla2x00_get_prop_16chars(scsi_qla_host_t *ha,
3820 char *propname, char *propval, char *db)
3829 uint8_t *retval = (uint8_t*)propval;
3830 uint8_t tmpval[8] = {0, 0, 0, 0, 0, 0, 0, 0};
3831 uint16_t max_byte_cnt = 8; /* 16 chars = 8 bytes */
3832 uint16_t max_strlen = 16;
3833 static char buf[LINESIZE];
3835 rval = qla2x00_find_propname(ha, propname, buf, db, max_strlen);
3838 if (*propstr == '=')
3839 propstr++; /* ignore equal sign */
3845 /* Convert string to numbers. */
3846 pchar = (uint8_t *)propstr;
3847 tmp_byte = (uint8_t *)tmpval;
3850 for (i = 0; i < max_strlen; i++) {
3852 * Check for invalid character, two at a time,
3853 * then convert them starting with first byte.
3856 if ((pchar[i] >= '0') && (pchar[i] <= '9')) {
3857 nval = pchar[i] - '0';
3858 } else if ((pchar[i] >= 'A') && (pchar[i] <= 'F')) {
3859 nval = pchar[i] - 'A' + 10;
3860 } else if ((pchar[i] >= 'a') && (pchar[i] <= 'f')) {
3861 nval = pchar[i] - 'a' + 10;
3863 /* invalid character */
3869 *tmp_byte = *tmp_byte | nval;
3872 *tmp_byte = *tmp_byte | nval << 4;
3877 /* Encountered invalid character. */
3881 /* Copy over the converted value. */
3888 *ret_byte++ = *tmp_byte++;
3891 /* big endian retval[0]; */
3896 * qla2x00_get_properties
3897 * Find all properties for the specified adapeter in
3901 * ha = adapter block pointer.
3902 * cmdline = pointer to command line string
3908 qla2x00_get_properties(scsi_qla_host_t *ha, char *cmdline)
3911 static char propbuf[LINESIZE];
3914 /* Adapter FC node names. */
3915 sprintf(propbuf, "scsi-qla%d-adapter-node", (int) ha->instance);
3916 rval = qla2x00_get_prop_16chars(ha, propbuf, fc_name, cmdline);
3917 if (rval == QLA_SUCCESS)
3918 memcpy(ha->init_cb->node_name, fc_name, WWN_SIZE);
3920 /* DG 04/07 check portname of adapter */
3921 sprintf(propbuf, "scsi-qla%d-adapter-port", (int)ha->instance);
3922 rval = qla2x00_get_prop_16chars(ha, propbuf, fc_name, cmdline);
3923 if (rval == QLA_SUCCESS &&
3924 memcmp(ha->init_cb->port_name, fc_name, WWN_SIZE)) {
3926 * Adapter port name is WWN, and cannot be changed.
3927 * Inform users of the mismatch, then just continue driver
3928 * loading using the original adapter port name in NVRAM.
3930 qla_printk(KERN_WARNING, ha,
3931 "Found mismatch in adapter port names.\n");
3932 qla_printk(KERN_INFO, ha,
3933 " qla%ld port name found in NVRAM -> "
3934 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
3936 ha->init_cb->port_name[0],
3937 ha->init_cb->port_name[1],
3938 ha->init_cb->port_name[2],
3939 ha->init_cb->port_name[3],
3940 ha->init_cb->port_name[4],
3941 ha->init_cb->port_name[5],
3942 ha->init_cb->port_name[6],
3943 ha->init_cb->port_name[7]);
3944 qla_printk(KERN_INFO, ha,
3945 " qla%ld port name found on command line -> "
3946 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
3948 fc_name[0], fc_name[1], fc_name[2], fc_name[3],
3949 fc_name[4], fc_name[5], fc_name[6], fc_name[7]);
3950 qla_printk(KERN_INFO, ha,
3951 " Using port name from NVRAM.\n");
3954 qla2x00_cfg_persistent_binding(ha);
3958 * qla2x00_cfg_persistent_binding
3959 * Get driver configuration file target persistent binding entries.
3962 * ha = adapter block pointer.
3968 qla2x00_cfg_persistent_binding(scsi_qla_host_t *ha)
3971 static char propbuf[LINESIZE];
3972 char *cmdline = ha->cmdline;
3976 uint8_t port_name[8];
3978 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
3979 if (ha->binding_type == BIND_BY_PORT_ID) {
3980 sprintf(propbuf, "scsi-qla%d-tgt-%d-di-0-pid",
3981 (int)ha->instance, tgt);
3982 rval = qla2x00_get_prop_xstr(ha,
3983 propbuf, portid, sizeof(portid));
3984 if (rval != sizeof(portid))
3987 memset(&d_id, 0, sizeof(port_id_t));
3988 d_id.r.d_id[0] = portid[2];
3989 d_id.r.d_id[1] = portid[1];
3990 d_id.r.d_id[2] = portid[0];
3992 sprintf(propbuf, "scsi-qla%d-tgt-%d-di-0-port",
3993 (int)ha->instance, tgt);
3994 rval = qla2x00_get_prop_16chars(ha,
3995 propbuf, port_name, cmdline);
3996 if (rval != QLA_SUCCESS)
3999 /* Fallthru since port_name already populated */
4003 * Create target context for device.
4005 if (ha->binding_type == BIND_BY_PORT_ID) {
4006 qla2x00_persistent_bind(ha, NULL, NULL, &d_id, tgt);
4008 qla2x00_persistent_bind(ha, NULL, port_name, NULL, tgt);
4014 * qla2x00_persistent_bind
4015 * Allocates target and fcport.
4018 * ha: adapter state pointer.
4019 * node_name: node name pointer.
4020 * port_name: port name pointer.
4021 * d_id: port ID pointer.
4022 * tgt: OS target number.
4025 * success = target queue pointer.
4032 qla2x00_persistent_bind(scsi_qla_host_t *ha, uint8_t *node_name,
4033 uint8_t *port_name, port_id_t *d_id, uint16_t tgt)
4039 * Check for duplicates.
4041 for (tgt2 = 0; tgt2 < MAX_TARGETS; tgt2++) {
4042 if ((tq = TGT_Q(ha, tgt2)) == NULL) {
4046 if (ha->binding_type == BIND_BY_PORT_ID) {
4047 if (tq->d_id.b24 != d_id->b24) {
4050 } else if (memcmp(tq->port_name, port_name, WWN_SIZE) != 0) {
4054 qla_printk(KERN_WARNING, ha,
4055 "Duplicate persistent bindings found for "
4056 "WWPN: %02x%02x%02x%02x%02x%02x%02x%02x.\n",
4057 port_name[0], port_name[1], port_name[2], port_name[3],
4058 port_name[4], port_name[5], port_name[6], port_name[7]);
4063 tq = qla2x00_tgt_alloc(ha, tgt);
4068 if (node_name != NULL) {
4069 memcpy(tq->node_name, node_name, WWN_SIZE);
4071 if (port_name != NULL) {
4072 memcpy(tq->port_name, port_name, WWN_SIZE);
4075 tq->d_id.b24 = d_id->b24;
4084 * Resets ISP and aborts all outstanding commands.
4087 * ha = adapter block pointer.
4093 qla2x00_abort_isp(scsi_qla_host_t *ha)
4095 unsigned long flags = 0;
4100 if (ha->flags.online) {
4101 ha->flags.online = FALSE;
4102 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
4103 qla2x00_stats.ispAbort++;
4104 ha->total_isp_aborts++; /* used by ioctl */
4105 ha->sns_retry_cnt = 0;
4107 qla_printk(KERN_INFO, ha,
4108 "Performing ISP error recovery - ha= %p.\n", ha);
4109 qla2x00_reset_chip(ha);
4111 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
4112 atomic_set(&ha->loop_state, LOOP_DOWN);
4113 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
4114 qla2x00_mark_all_devices_lost(ha);
4117 spin_lock_irqsave(&ha->hardware_lock, flags);
4118 /* Requeue all commands in outstanding command list. */
4119 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
4120 sp = ha->outstanding_cmds[cnt];
4122 ha->outstanding_cmds[cnt] = 0;
4125 sp->lun_queue->out_cnt--;
4129 * Set the cmd host_byte status depending on
4130 * whether the scsi_error_handler is
4133 if (ha->host->eh_active != EH_ACTIVE) {
4134 sp->cmd->result = DID_BUS_BUSY << 16;
4136 sp->cmd->result = DID_RESET << 16;
4138 sp->cmd->host_scribble = (unsigned char *)NULL;
4139 add_to_done_queue(ha, sp);
4143 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4145 qla2x00_nvram_config(ha);
4147 if (!qla2x00_restart_isp(ha)) {
4148 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
4150 if (!atomic_read(&ha->loop_down_timer)) {
4152 * Issue marker command only when we are going
4153 * to start the I/O .
4155 ha->marker_needed = 1;
4158 ha->flags.online = TRUE;
4160 /* Enable ISP interrupts. */
4161 qla2x00_enable_intrs(ha);
4163 /* v2.19.5b6 Return all commands */
4164 qla2x00_abort_queues(ha, TRUE);
4166 /* Restart queues that may have been stopped. */
4167 qla2x00_restart_queues(ha,TRUE);
4168 ha->isp_abort_cnt = 0;
4169 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
4170 } else { /* failed the ISP abort */
4171 ha->flags.online = TRUE;
4172 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
4173 if (ha->isp_abort_cnt == 0) {
4174 qla_printk(KERN_WARNING, ha,
4175 "ISP error recovery failed - "
4176 "board disabled\n");
4178 * The next call disables the board
4181 qla2x00_reset_adapter(ha);
4182 qla2x00_abort_queues(ha, FALSE);
4183 ha->flags.online = FALSE;
4184 clear_bit(ISP_ABORT_RETRY,
4187 } else { /* schedule another ISP abort */
4188 ha->isp_abort_cnt--;
4189 DEBUG(printk("qla%ld: ISP abort - "
4190 "retry remainning %d\n",
4191 ha->host_no, ha->isp_abort_cnt);)
4195 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
4196 DEBUG(printk("qla2x00(%ld): ISP error recovery "
4197 "- retrying (%d) more times\n",
4198 ha->host_no, ha->isp_abort_cnt);)
4199 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
4207 qla_printk(KERN_INFO, ha,
4208 "qla2x00_abort_isp: **** FAILED ****\n");
4210 DEBUG(printk(KERN_INFO
4211 "qla2x00_abort_isp(%ld): exiting.\n",
4219 * qla2x00_restart_isp
4220 * restarts the ISP after a reset
4223 * ha = adapter block pointer.
4229 qla2x00_restart_isp(scsi_qla_host_t *ha)
4233 unsigned long flags = 0;
4236 /* If firmware needs to be loaded */
4237 if (qla2x00_isp_firmware(ha)) {
4238 ha->flags.online = FALSE;
4239 if (!(status = qla2x00_chip_diag(ha))) {
4240 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4241 status = qla2x00_setup_chip(ha);
4246 spin_lock_irqsave(&ha->hardware_lock, flags);
4247 /* Disable SRAM, Instruction RAM and GP RAM parity. */
4248 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
4249 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4251 status = qla2x00_setup_chip(ha);
4253 spin_lock_irqsave(&ha->hardware_lock, flags);
4255 /* Enable proper parity */
4258 WRT_REG_WORD(®->hccr,
4259 (HCCR_ENABLE_PARITY + 0x1));
4261 /* SRAM, Instruction RAM and GP RAM parity */
4262 WRT_REG_WORD(®->hccr,
4263 (HCCR_ENABLE_PARITY + 0x7));
4265 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4270 if (!status && !(status = qla2x00_init_rings(ha))) {
4271 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
4272 if (!(status = qla2x00_fw_ready(ha))) {
4273 DEBUG(printk("%s(): Start configure loop, "
4277 ha->flags.online = TRUE;
4278 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4281 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4282 qla2x00_configure_loop(ha);
4284 } while (!atomic_read(&ha->loop_down_timer) &&
4285 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
4287 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
4290 /* if no cable then assume it's good */
4291 if ((ha->device_flags & DFLG_NO_CABLE))
4294 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
4302 * qla2x00_reset_adapter
4306 * ha = adapter block pointer.
4309 qla2x00_reset_adapter(scsi_qla_host_t *ha)
4311 unsigned long flags = 0;
4312 device_reg_t *reg = ha->iobase;
4314 ha->flags.online = FALSE;
4315 qla2x00_disable_intrs(ha);
4316 /* Reset RISC processor. */
4317 spin_lock_irqsave(&ha->hardware_lock, flags);
4318 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
4319 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
4320 spin_unlock_irqrestore(&ha->hardware_lock, flags);