2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2004 QLogic Corporation
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
21 #include <linux/delay.h>
23 #include "qla_devtbl.h"
25 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
26 #ifndef EXT_IS_LUN_BIT_SET
27 #define EXT_IS_LUN_BIT_SET(P,L) \
28 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
29 #define EXT_SET_LUN_BIT(P,L) \
30 ((P)->mask[L/8] |= (0x80 >> (L%8)))
34 * QLogic ISP2x00 Hardware Support Function Prototypes.
36 static int qla2x00_pci_config(scsi_qla_host_t *);
37 static int qla2x00_isp_firmware(scsi_qla_host_t *);
38 static void qla2x00_reset_chip(scsi_qla_host_t *);
39 static int qla2x00_chip_diag(scsi_qla_host_t *);
40 static void qla2x00_resize_request_q(scsi_qla_host_t *);
41 static int qla2x00_setup_chip(scsi_qla_host_t *);
42 static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
43 static int qla2x00_init_rings(scsi_qla_host_t *);
44 static int qla2x00_fw_ready(scsi_qla_host_t *);
45 static int qla2x00_configure_hba(scsi_qla_host_t *);
46 static int qla2x00_nvram_config(scsi_qla_host_t *);
47 static void qla2x00_init_tgt_map(scsi_qla_host_t *);
48 static int qla2x00_configure_loop(scsi_qla_host_t *);
49 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
50 static void qla2x00_update_fcport(scsi_qla_host_t *, fc_port_t *);
51 static void qla2x00_lun_discovery(scsi_qla_host_t *, fc_port_t *);
52 static int qla2x00_rpt_lun_discovery(scsi_qla_host_t *, fc_port_t *,
53 inq_cmd_rsp_t *, dma_addr_t);
54 static int qla2x00_report_lun(scsi_qla_host_t *, fc_port_t *);
55 static fc_lun_t *qla2x00_cfg_lun(scsi_qla_host_t *, fc_port_t *, uint16_t,
56 inq_cmd_rsp_t *, dma_addr_t);
57 static fc_lun_t * qla2x00_add_lun(fc_port_t *, uint16_t);
58 static int qla2x00_inquiry(scsi_qla_host_t *, fc_port_t *, uint16_t,
59 inq_cmd_rsp_t *, dma_addr_t);
60 static int qla2x00_configure_fabric(scsi_qla_host_t *);
61 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
62 static int qla2x00_device_resync(scsi_qla_host_t *);
63 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
65 static void qla2x00_config_os(scsi_qla_host_t *ha);
66 static uint16_t qla2x00_fcport_bind(scsi_qla_host_t *ha, fc_port_t *fcport);
67 static os_lun_t * qla2x00_fclun_bind(scsi_qla_host_t *, fc_port_t *,
69 static void qla2x00_lun_free(scsi_qla_host_t *, uint16_t, uint16_t);
71 static int qla2x00_bstr_to_hex(char *, uint8_t *, int);
72 static int qla2x00_find_propname(scsi_qla_host_t *,
73 char *, char *, char *, int);
75 static void qla2x00_get_lun_mask_from_config(scsi_qla_host_t *, fc_port_t *,
77 static int qla2x00_get_prop_16chars(scsi_qla_host_t *,
78 char *, char *, char *);
79 static void qla2x00_get_properties(scsi_qla_host_t *, char *);
81 static void qla2x00_cfg_persistent_binding(scsi_qla_host_t *);
82 static os_tgt_t *qla2x00_persistent_bind(scsi_qla_host_t *, uint8_t *,
83 uint8_t *, port_id_t *, uint16_t);
86 static int qla2x00_restart_isp(scsi_qla_host_t *);
87 static void qla2x00_reset_adapter(scsi_qla_host_t *);
89 /****************************************************************************/
90 /* QLogic ISP2x00 Hardware Support Functions. */
91 /****************************************************************************/
94 * qla2x00_initialize_adapter
98 * ha = adapter block pointer.
104 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
107 uint8_t restart_risc = 0;
111 /* Clear adapter flags. */
112 ha->flags.online = 0;
113 ha->flags.reset_active = 0;
114 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
115 atomic_set(&ha->loop_state, LOOP_DOWN);
116 ha->device_flags = 0;
117 ha->sns_retry_cnt = 0;
119 ha->failback_delay = 0;
120 ha->flags.management_server_logged_in = 0;
121 ha->marker_needed = 0;
123 ha->isp_abort_cnt = 0;
124 ha->beacon_blink_led = 0;
126 rval = qla2x00_pci_config(ha);
128 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
133 qla2x00_reset_chip(ha);
135 /* Initialize target map database. */
136 qla2x00_init_tgt_map(ha);
138 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
139 qla2x00_nvram_config(ha);
141 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
145 * If the user specified a device configuration on the command line
146 * then use it as the configuration. Otherwise, we scan for all
150 ha->cmdline = ql2xdevconf;
151 qla2x00_get_properties(ha, ql2xdevconf);
157 * Try to configure the loop.
162 /* If firmware needs to be loaded */
163 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
164 if ((rval = qla2x00_chip_diag(ha)) == QLA_SUCCESS) {
165 rval = qla2x00_setup_chip(ha);
169 if (rval == QLA_SUCCESS &&
170 (rval = qla2x00_init_rings(ha)) == QLA_SUCCESS) {
171 check_fw_ready_again:
173 * Wait for a successful LIP up to a maximum
174 * of (in seconds): RISC login timeout value,
175 * RISC retry count value, and port down retry
176 * value OR a minimum of 4 seconds OR If no
177 * cable, only 5 seconds.
179 rval = qla2x00_fw_ready(ha);
180 if (rval == QLA_SUCCESS) {
181 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
184 * Wait at most MAX_TARGET RSCNs for a stable
189 clear_bit(LOOP_RESYNC_NEEDED,
191 rval = qla2x00_configure_loop(ha);
193 if (test_and_clear_bit(ISP_ABORT_NEEDED,
200 * If loop state change while we were
201 * discoverying devices then wait for
205 if (atomic_read(&ha->loop_state) ==
206 LOOP_DOWN && retry--) {
207 goto check_fw_ready_again;
210 } while (!atomic_read(&ha->loop_down_timer) &&
213 (test_bit(LOOP_RESYNC_NEEDED,
217 rval = QLA_FUNCTION_FAILED;
220 } else if (ha->device_flags & DFLG_NO_CABLE)
221 /* If no cable, then all is good. */
224 } while (restart_risc && retry--);
226 if (rval == QLA_SUCCESS) {
227 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
228 ha->marker_needed = 1;
229 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
230 ha->marker_needed = 0;
232 ha->flags.online = 1;
234 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
241 * qla2x00_pci_config() - Setup device PCI configuration registers.
244 * Returns 0 on success.
247 qla2x00_pci_config(scsi_qla_host_t *ha)
250 unsigned long flags = 0;
253 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
256 * Turn on PCI master; for system BIOSes that don't turn it on by
259 pci_set_master(ha->pdev);
261 if (pci_set_mwi(ha->pdev))
262 mwi = PCI_COMMAND_INVALIDATE;
263 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
266 return (QLA_FUNCTION_FAILED);
269 * We want to respect framework's setting of PCI configuration space
270 * command register and also want to make sure that all bits of
271 * interest to us are properly set in command register.
273 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
274 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
276 /* Get PCI bus information. */
277 spin_lock_irqsave(&ha->hardware_lock, flags);
278 ha->pci_attr = RD_REG_WORD(&ha->iobase->ctrl_status);
279 spin_unlock_irqrestore(&ha->hardware_lock, flags);
281 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
282 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
284 /* PCI Specification Revision 2.3 changes */
285 if (IS_QLA2322(ha) || IS_QLA6322(ha))
286 /* Command Register - Reset Interrupt Disable. */
287 w &= ~PCI_COMMAND_INTX_DISABLE;
290 * If this is a 2300 card and not 2312, reset the
291 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
292 * the 2310 also reports itself as a 2300 so we need to get the
293 * fb revision level -- a 6 indicates it really is a 2300 and
296 if (IS_QLA2300(ha)) {
297 spin_lock_irqsave(&ha->hardware_lock, flags);
300 WRT_REG_WORD(&ha->iobase->hccr, HCCR_PAUSE_RISC);
301 for (cnt = 0; cnt < 30000; cnt++) {
302 if ((RD_REG_WORD(&ha->iobase->hccr) &
303 HCCR_RISC_PAUSE) != 0)
309 /* Select FPM registers. */
310 WRT_REG_WORD(&ha->iobase->ctrl_status, 0x20);
311 RD_REG_WORD(&ha->iobase->ctrl_status);
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);
321 RD_REG_WORD(&ha->iobase->ctrl_status);
323 /* Release RISC module. */
324 WRT_REG_WORD(&ha->iobase->hccr, HCCR_RELEASE_RISC);
325 for (cnt = 0; cnt < 30000; cnt++) {
326 if ((RD_REG_WORD(&ha->iobase->hccr) &
327 HCCR_RISC_PAUSE) == 0)
333 spin_unlock_irqrestore(&ha->hardware_lock, flags);
337 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
339 /* Reset expansion ROM address decode enable */
340 pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w);
341 w &= ~PCI_ROM_ADDRESS_ENABLE;
342 pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
344 return (QLA_SUCCESS);
348 * qla2x00_isp_firmware() - Choose firmware image.
351 * Returns 0 on success.
354 qla2x00_isp_firmware(scsi_qla_host_t *ha)
358 /* Assume loading risc code */
359 rval = QLA_FUNCTION_FAILED;
361 if (ha->flags.disable_risc_code_load) {
362 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
364 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
366 /* Verify checksum of loaded RISC code. */
367 rval = qla2x00_verify_checksum(ha);
371 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
379 * qla2x00_reset_chip() - Reset ISP chip.
382 * Returns 0 on success.
385 qla2x00_reset_chip(scsi_qla_host_t *ha)
387 unsigned long flags = 0;
388 device_reg_t __iomem *reg = ha->iobase;
390 unsigned long mbx_flags = 0;
393 /* Disable ISP interrupts. */
394 qla2x00_disable_intrs(ha);
396 spin_lock_irqsave(&ha->hardware_lock, flags);
398 /* Turn off master enable */
400 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
401 cmd &= ~PCI_COMMAND_MASTER;
402 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
404 if (!IS_QLA2100(ha)) {
406 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
407 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
408 for (cnt = 0; cnt < 30000; cnt++) {
409 if ((RD_REG_WORD(®->hccr) &
410 HCCR_RISC_PAUSE) != 0)
415 RD_REG_WORD(®->hccr); /* PCI Posting. */
419 /* Select FPM registers. */
420 WRT_REG_WORD(®->ctrl_status, 0x20);
421 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
423 /* FPM Soft Reset. */
424 WRT_REG_WORD(®->fpm_diag_config, 0x100);
425 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
427 /* Toggle Fpm Reset. */
428 if (!IS_QLA2200(ha)) {
429 WRT_REG_WORD(®->fpm_diag_config, 0x0);
430 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
433 /* Select frame buffer registers. */
434 WRT_REG_WORD(®->ctrl_status, 0x10);
435 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
437 /* Reset frame buffer FIFOs. */
438 if (IS_QLA2200(ha)) {
439 WRT_FB_CMD_REG(ha, reg, 0xa000);
440 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
442 WRT_FB_CMD_REG(ha, reg, 0x00fc);
444 /* Read back fb_cmd until zero or 3 seconds max */
445 for (cnt = 0; cnt < 3000; cnt++) {
446 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
452 /* Select RISC module registers. */
453 WRT_REG_WORD(®->ctrl_status, 0);
454 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
456 /* Reset RISC processor. */
457 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
458 RD_REG_WORD(®->hccr); /* PCI Posting. */
460 /* Release RISC processor. */
461 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
462 RD_REG_WORD(®->hccr); /* PCI Posting. */
465 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
466 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
468 /* Reset ISP chip. */
469 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
471 /* Wait for RISC to recover from reset. */
472 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
474 * It is necessary to for a delay here since the card doesn't
475 * respond to PCI reads during a reset. On some architectures
476 * this will result in an MCA.
479 for (cnt = 30000; cnt; cnt--) {
480 if ((RD_REG_WORD(®->ctrl_status) &
481 CSR_ISP_SOFT_RESET) == 0)
488 /* Reset RISC processor. */
489 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
491 WRT_REG_WORD(®->semaphore, 0);
493 /* Release RISC processor. */
494 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
495 RD_REG_WORD(®->hccr); /* PCI Posting. */
497 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
498 for (cnt = 0; cnt < 30000; cnt++) {
499 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
500 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
502 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) {
503 if (!(test_bit(ABORT_ISP_ACTIVE,
505 spin_unlock_irqrestore(
506 &ha->mbx_reg_lock, mbx_flags);
510 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
511 spin_unlock_irqrestore(&ha->mbx_reg_lock,
519 /* Turn on master enable */
520 cmd |= PCI_COMMAND_MASTER;
521 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
523 /* Disable RISC pause on FPM parity error. */
524 if (!IS_QLA2100(ha)) {
525 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
526 RD_REG_WORD(®->hccr); /* PCI Posting. */
529 spin_unlock_irqrestore(&ha->hardware_lock, flags);
533 * qla2x00_chip_diag() - Test chip for proper operation.
536 * Returns 0 on success.
539 qla2x00_chip_diag(scsi_qla_host_t *ha)
542 device_reg_t __iomem *reg = ha->iobase;
543 unsigned long flags = 0;
548 /* Assume a failed state */
549 rval = QLA_FUNCTION_FAILED;
551 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
552 ha->host_no, (u_long)®->flash_address));
554 spin_lock_irqsave(&ha->hardware_lock, flags);
556 /* Reset ISP chip. */
557 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
560 * We need to have a delay here since the card will not respond while
561 * in reset causing an MCA on some architectures.
564 data = qla2x00_debounce_register(®->ctrl_status);
565 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
567 data = RD_REG_WORD(®->ctrl_status);
572 goto chip_diag_failed;
574 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
577 /* Reset RISC processor. */
578 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
579 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
581 /* Workaround for QLA2312 PCI parity error */
582 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
583 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
584 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
586 data = RD_MAILBOX_REG(ha, reg, 0);
593 goto chip_diag_failed;
595 /* Check product ID of chip */
596 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
598 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
599 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
600 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
601 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
602 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
603 mb[3] != PROD_ID_3) {
604 qla_printk(KERN_WARNING, ha,
605 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
607 goto chip_diag_failed;
609 ha->product_id[0] = mb[1];
610 ha->product_id[1] = mb[2];
611 ha->product_id[2] = mb[3];
612 ha->product_id[3] = mb[4];
614 /* Adjust fw RISC transfer size */
615 if (ha->request_q_length > 1024)
616 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
618 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
619 ha->request_q_length;
621 if (IS_QLA2200(ha) &&
622 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
623 /* Limit firmware transfer size with a 2200A */
624 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
627 ha->fw_transfer_size = 128;
630 /* Wrap Incoming Mailboxes Test. */
631 spin_unlock_irqrestore(&ha->hardware_lock, flags);
633 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
634 rval = qla2x00_mbx_reg_test(ha);
636 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
638 qla_printk(KERN_WARNING, ha,
639 "Failed mailbox send register test\n");
642 /* Flag a successful rval */
645 spin_lock_irqsave(&ha->hardware_lock, flags);
649 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
650 "****\n", ha->host_no));
652 spin_unlock_irqrestore(&ha->hardware_lock, flags);
658 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
661 * Returns 0 on success.
664 qla2x00_resize_request_q(scsi_qla_host_t *ha)
667 uint16_t fw_iocb_cnt = 0;
668 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
669 dma_addr_t request_dma;
670 request_t *request_ring;
672 /* Valid only on recent ISPs. */
673 if (IS_QLA2100(ha) || IS_QLA2200(ha))
676 /* Retrieve IOCB counts available to the firmware. */
677 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
680 /* No point in continuing if current settings are sufficient. */
681 if (fw_iocb_cnt < 1024)
683 if (ha->request_q_length >= request_q_length)
686 /* Attempt to claim larger area for request queue. */
687 request_ring = dma_alloc_coherent(&ha->pdev->dev,
688 (request_q_length + 1) * sizeof(request_t), &request_dma,
690 if (request_ring == NULL)
693 /* Resize successful, report extensions. */
694 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
695 (ha->fw_memory_size + 1) / 1024);
696 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
697 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
699 /* Clear old allocations. */
700 dma_free_coherent(&ha->pdev->dev,
701 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
704 /* Begin using larger queue. */
705 ha->request_q_length = request_q_length;
706 ha->request_ring = request_ring;
707 ha->request_dma = request_dma;
711 * qla2x00_setup_chip() - Load and start RISC firmware.
714 * Returns 0 on success.
717 qla2x00_setup_chip(scsi_qla_host_t *ha)
722 unsigned long risc_address;
723 unsigned long risc_code_size;
727 struct qla_fw_info *fw_iter;
731 /* Load firmware sequences */
732 fw_iter = ha->brd_info->fw_info;
733 while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
734 risc_code = fw_iter->fwcode;
735 risc_code_size = *fw_iter->fwlen;
737 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
738 risc_address = *fw_iter->fwstart;
740 /* Extended address */
741 risc_address = *fw_iter->lfwstart;
746 while (risc_code_size > 0 && !rval) {
747 cnt = (uint16_t)(ha->fw_transfer_size >> 1);
748 if (cnt > risc_code_size)
749 cnt = risc_code_size;
751 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
752 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
753 ha->host_no, risc_code, cnt, risc_address));
755 req_ring = (uint16_t *)ha->request_ring;
756 for (i = 0; i < cnt; i++)
757 req_ring[i] = cpu_to_le16(risc_code[i]);
759 if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
760 rval = qla2x00_load_ram(ha,
761 ha->request_dma, risc_address, cnt);
763 rval = qla2x00_load_ram_ext(ha,
764 ha->request_dma, risc_address, cnt);
767 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
768 "load segment %d of firmware\n",
770 qla_printk(KERN_WARNING, ha,
771 "[ERROR] Failed to load "
772 "segment %d of firmware\n", num);
774 qla2x00_dump_regs(ha);
780 risc_code_size -= cnt;
784 /* Next firmware sequence */
788 /* Verify checksum of loaded RISC code. */
790 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
791 "code.\n", ha->host_no));
793 rval = qla2x00_verify_checksum(ha);
794 if (rval == QLA_SUCCESS) {
795 /* Start firmware execution. */
796 DEBUG(printk("scsi(%ld): Checksum OK, start "
797 "firmware.\n", ha->host_no));
799 rval = qla2x00_execute_fw(ha);
800 /* Retrieve firmware information. */
801 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
802 qla2x00_get_fw_version(ha,
803 &ha->fw_major_version,
804 &ha->fw_minor_version,
805 &ha->fw_subminor_version,
806 &ha->fw_attributes, &ha->fw_memory_size);
807 qla2x00_resize_request_q(ha);
810 DEBUG2(printk(KERN_INFO
811 "scsi(%ld): ISP Firmware failed checksum.\n",
817 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
825 * qla2x00_init_response_q_entries() - Initializes response queue entries.
828 * Beginning of request ring has initialization control block already built
829 * by nvram config routine.
831 * Returns 0 on success.
834 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
839 pkt = ha->response_ring_ptr;
840 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
841 pkt->signature = RESPONSE_PROCESSED;
848 * qla2x00_update_fw_options() - Read and process firmware options.
851 * Returns 0 on success.
854 qla2x00_update_fw_options(scsi_qla_host_t *ha)
856 uint16_t swing, emphasis;
858 memset(ha->fw_options, 0, sizeof(ha->fw_options));
859 qla2x00_get_fw_options(ha, ha->fw_options);
861 if (IS_QLA2100(ha) || IS_QLA2200(ha))
864 /* Serial Link options. */
865 DEBUG3(printk("scsi(%ld): Serial link options:\n",
867 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
868 sizeof(ha->fw_seriallink_options)));
870 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
871 if (ha->fw_seriallink_options[1] & BIT_2)
872 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
875 swing = ha->fw_seriallink_options[0] & (BIT_2 | BIT_1 | BIT_0);
876 emphasis = ha->fw_seriallink_options[0] & (BIT_4 | BIT_3);
878 ha->fw_options[10] = (emphasis << 14) | (swing << 8) | 0x3;
880 swing = ha->fw_seriallink_options[0] & (BIT_7 | BIT_6 | BIT_5);
882 emphasis = ha->fw_seriallink_options[1] & (BIT_1 | BIT_0);
883 ha->fw_options[11] = (emphasis << 14) | (swing << 8) | 0x3;
886 /* Return command IOCBs without waiting for an ABTS to complete. */
887 ha->fw_options[3] |= BIT_13;
889 /* Update firmware options. */
890 qla2x00_set_fw_options(ha, ha->fw_options);
894 * qla2x00_init_rings() - Initializes firmware.
897 * Beginning of request ring has initialization control block already built
898 * by nvram config routine.
900 * Returns 0 on success.
903 qla2x00_init_rings(scsi_qla_host_t *ha)
906 unsigned long flags = 0;
908 device_reg_t __iomem *reg = ha->iobase;
910 spin_lock_irqsave(&ha->hardware_lock, flags);
912 /* Clear outstanding commands array. */
913 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
914 ha->outstanding_cmds[cnt] = NULL;
916 ha->current_outstanding_cmd = 0;
918 /* Clear RSCN queue. */
920 ha->rscn_out_ptr = 0;
922 /* Initialize firmware. */
923 ha->request_ring_ptr = ha->request_ring;
924 ha->req_ring_index = 0;
925 ha->req_q_cnt = ha->request_q_length;
926 ha->response_ring_ptr = ha->response_ring;
927 ha->rsp_ring_index = 0;
929 /* Setup ring parameters in initialization control block. */
930 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
931 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
932 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
933 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
934 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
935 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
936 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
937 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
939 /* Initialize response queue entries */
940 qla2x00_init_response_q_entries(ha);
942 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
943 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
944 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
945 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
946 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
948 spin_unlock_irqrestore(&ha->hardware_lock, flags);
950 /* Update any ISP specific firmware options before initialization. */
951 qla2x00_update_fw_options(ha);
953 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
954 rval = qla2x00_init_firmware(ha, sizeof(init_cb_t));
956 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
959 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
967 * qla2x00_fw_ready() - Waits for firmware ready.
970 * Returns 0 on success.
973 qla2x00_fw_ready(scsi_qla_host_t *ha)
976 unsigned long wtime, mtime;
977 uint16_t min_wait; /* Minimum wait time if loop is down */
978 uint16_t wait_time; /* Wait time if loop is coming ready */
983 /* 20 seconds for loop down. */
987 * Firmware should take at most one RATOV to login, plus 5 seconds for
988 * our own processing.
990 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
991 wait_time = min_wait;
994 /* Min wait time if loop down */
995 mtime = jiffies + (min_wait * HZ);
997 /* wait time before firmware ready */
998 wtime = jiffies + (wait_time * HZ);
1000 /* Wait for ISP to finish LIP */
1001 if (!ha->flags.init_done)
1002 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1004 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1008 rval = qla2x00_get_firmware_state(ha, &fw_state);
1009 if (rval == QLA_SUCCESS) {
1010 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1011 ha->device_flags &= ~DFLG_NO_CABLE;
1013 if (fw_state == FSTATE_READY) {
1014 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1017 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1018 &ha->login_timeout, &ha->r_a_tov);
1024 rval = QLA_FUNCTION_FAILED;
1026 if (atomic_read(&ha->loop_down_timer) &&
1027 (fw_state >= FSTATE_LOSS_OF_SYNC ||
1028 fw_state == FSTATE_WAIT_AL_PA)) {
1029 /* Loop down. Timeout on min_wait for states
1030 * other than Wait for Login.
1032 if (time_after_eq(jiffies, mtime)) {
1033 qla_printk(KERN_INFO, ha,
1034 "Cable is unplugged...\n");
1036 ha->device_flags |= DFLG_NO_CABLE;
1041 /* Mailbox cmd failed. Timeout on min_wait. */
1042 if (time_after_eq(jiffies, mtime))
1046 if (time_after_eq(jiffies, wtime))
1049 /* Delay for a while */
1052 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1053 ha->host_no, fw_state, jiffies));
1056 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1057 ha->host_no, fw_state, jiffies));
1060 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1068 * qla2x00_configure_hba
1069 * Setup adapter context.
1072 * ha = adapter state pointer.
1081 qla2x00_configure_hba(scsi_qla_host_t *ha)
1089 char connect_type[22];
1091 /* Get host addresses. */
1092 rval = qla2x00_get_adapter_id(ha,
1093 &loop_id, &al_pa, &area, &domain, &topo);
1094 if (rval != QLA_SUCCESS) {
1095 qla_printk(KERN_WARNING, ha,
1096 "ERROR -- Unable to get host loop ID.\n");
1101 qla_printk(KERN_INFO, ha,
1102 "Cannot get topology - retrying.\n");
1103 return (QLA_FUNCTION_FAILED);
1106 ha->loop_id = loop_id;
1109 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1110 ha->operating_mode = LOOP;
1114 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1116 ha->current_topology = ISP_CFG_NL;
1117 strcpy(connect_type, "(Loop)");
1121 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1123 ha->current_topology = ISP_CFG_FL;
1124 strcpy(connect_type, "(FL_Port)");
1128 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1130 ha->operating_mode = P2P;
1131 ha->current_topology = ISP_CFG_N;
1132 strcpy(connect_type, "(N_Port-to-N_Port)");
1136 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1138 ha->operating_mode = P2P;
1139 ha->current_topology = ISP_CFG_F;
1140 strcpy(connect_type, "(F_Port)");
1144 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1146 ha->host_no, topo));
1147 ha->current_topology = ISP_CFG_NL;
1148 strcpy(connect_type, "(Loop)");
1152 /* Save Host port and loop ID. */
1153 /* byte order - Big Endian */
1154 ha->d_id.b.domain = domain;
1155 ha->d_id.b.area = area;
1156 ha->d_id.b.al_pa = al_pa;
1158 if (!ha->flags.init_done)
1159 qla_printk(KERN_INFO, ha,
1160 "Topology - %s, Host Loop address 0x%x\n",
1161 connect_type, ha->loop_id);
1164 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1166 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1173 * NVRAM configuration for ISP 2xxx
1176 * ha = adapter block pointer.
1179 * initialization control block in response_ring
1180 * host adapters parameters in host adapter block
1186 qla2x00_nvram_config(scsi_qla_host_t *ha)
1191 uint8_t *dptr1, *dptr2;
1192 init_cb_t *icb = ha->init_cb;
1193 nvram_t *nv = (nvram_t *)ha->request_ring;
1194 uint16_t *wptr = (uint16_t *)ha->request_ring;
1195 device_reg_t __iomem *reg = ha->iobase;
1200 /* Determine NVRAM starting address. */
1202 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1203 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1204 ha->nvram_base = 0x80;
1206 /* Get NVRAM data and calculate checksum. */
1207 qla2x00_lock_nvram_access(ha);
1208 for (cnt = 0; cnt < sizeof(nvram_t)/2; cnt++) {
1209 *wptr = cpu_to_le16(qla2x00_get_nvram_word(ha,
1210 (cnt+ha->nvram_base)));
1211 chksum += (uint8_t)*wptr;
1212 chksum += (uint8_t)(*wptr >> 8);
1215 qla2x00_unlock_nvram_access(ha);
1217 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1218 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1221 /* Bad NVRAM data, set defaults parameters. */
1222 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1223 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1224 /* Reset NVRAM data. */
1225 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1226 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1228 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1229 "invalid -- WWPN) defaults.\n");
1232 * Set default initialization control block.
1234 memset(nv, 0, sizeof(nvram_t));
1235 nv->parameter_block_version = ICB_VERSION;
1237 if (IS_QLA23XX(ha)) {
1238 nv->firmware_options[0] = BIT_2 | BIT_1;
1239 nv->firmware_options[1] = BIT_7 | BIT_5;
1240 nv->add_firmware_options[0] = BIT_5;
1241 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1242 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1243 nv->special_options[1] = BIT_7;
1244 } else if (IS_QLA2200(ha)) {
1245 nv->firmware_options[0] = BIT_2 | BIT_1;
1246 nv->firmware_options[1] = BIT_7 | BIT_5;
1247 nv->add_firmware_options[0] = BIT_5;
1248 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1249 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1250 } else if (IS_QLA2100(ha)) {
1251 nv->firmware_options[0] = BIT_3 | BIT_1;
1252 nv->firmware_options[1] = BIT_5;
1253 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1256 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1257 nv->execution_throttle = __constant_cpu_to_le16(16);
1258 nv->retry_count = 8;
1259 nv->retry_delay = 1;
1261 nv->port_name[0] = 33;
1262 nv->port_name[3] = 224;
1263 nv->port_name[4] = 139;
1265 nv->login_timeout = 4;
1268 * Set default host adapter parameters
1270 nv->host_p[1] = BIT_2;
1271 nv->reset_delay = 5;
1272 nv->port_down_retry_count = 8;
1273 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1274 nv->link_down_timeout = 60;
1279 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1281 * The SN2 does not provide BIOS emulation which means you can't change
1282 * potentially bogus BIOS settings. Force the use of default settings
1283 * for link rate and frame size. Hope that the rest of the settings
1286 if (ia64_platform_is("sn2")) {
1287 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1289 nv->special_options[1] = BIT_7;
1293 /* Reset Initialization control block */
1294 memset(icb, 0, sizeof(init_cb_t));
1297 * Setup driver NVRAM options.
1299 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1300 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1301 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1302 nv->firmware_options[1] &= ~BIT_4;
1304 if (IS_QLA23XX(ha)) {
1305 nv->firmware_options[0] |= BIT_2;
1306 nv->firmware_options[0] &= ~BIT_3;
1308 if (IS_QLA2300(ha)) {
1309 if (ha->fb_rev == FPM_2310) {
1310 strcpy(ha->model_number, "QLA2310");
1312 strcpy(ha->model_number, "QLA2300");
1316 memcmp(nv->model_number, BINZERO,
1317 sizeof(nv->model_number)) != 0) {
1320 strncpy(ha->model_number, nv->model_number,
1321 sizeof(nv->model_number));
1322 st = en = ha->model_number;
1323 en += sizeof(nv->model_number) - 1;
1325 if (*en != 0x20 && *en != 0x00)
1332 index = (ha->pdev->subsystem_device & 0xff);
1333 if (index < QLA_MODEL_NAMES) {
1334 strcpy(ha->model_number,
1335 qla2x00_model_name[index]);
1337 qla2x00_model_desc[index];
1339 strcpy(ha->model_number, "QLA23xx");
1343 } else if (IS_QLA2200(ha)) {
1344 nv->firmware_options[0] |= BIT_2;
1346 * 'Point-to-point preferred, else loop' is not a safe
1347 * connection mode setting.
1349 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1351 /* Force 'loop preferred, else point-to-point'. */
1352 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1353 nv->add_firmware_options[0] |= BIT_5;
1355 strcpy(ha->model_number, "QLA22xx");
1356 } else /*if (IS_QLA2100(ha))*/ {
1357 strcpy(ha->model_number, "QLA2100");
1361 * Copy over NVRAM RISC parameter block to initialization control block.
1363 dptr1 = (uint8_t *)icb;
1364 dptr2 = (uint8_t *)&nv->parameter_block_version;
1365 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1367 *dptr1++ = *dptr2++;
1369 /* Copy 2nd half. */
1370 dptr1 = (uint8_t *)icb->add_firmware_options;
1371 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1373 *dptr1++ = *dptr2++;
1375 /* Prepare nodename */
1376 if ((icb->firmware_options[1] & BIT_6) == 0) {
1378 * Firmware will apply the following mask if the nodename was
1381 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1382 icb->node_name[0] &= 0xF0;
1386 * Set host adapter parameters.
1388 ha->nvram_version = nv->nvram_version;
1390 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1391 /* Always load RISC code on non ISP2[12]00 chips. */
1392 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1393 ha->flags.disable_risc_code_load = 0;
1394 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1395 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1396 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1398 ha->operating_mode =
1399 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1401 ha->fw_seriallink_options[0] = nv->seriallink_options[0];
1402 ha->fw_seriallink_options[1] = nv->seriallink_options[1];
1404 /* save HBA serial number */
1405 ha->serial0 = icb->port_name[5];
1406 ha->serial1 = icb->port_name[6];
1407 ha->serial2 = icb->port_name[7];
1408 memcpy(ha->node_name, icb->node_name, WWN_SIZE);
1410 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1412 ha->retry_count = nv->retry_count;
1414 /* Set minimum login_timeout to 4 seconds. */
1415 if (nv->login_timeout < ql2xlogintimeout)
1416 nv->login_timeout = ql2xlogintimeout;
1417 if (nv->login_timeout < 4)
1418 nv->login_timeout = 4;
1419 ha->login_timeout = nv->login_timeout;
1420 icb->login_timeout = nv->login_timeout;
1422 /* Set minimum RATOV to 200 tenths of a second. */
1425 ha->minimum_timeout =
1426 (ha->login_timeout * ha->retry_count) + nv->port_down_retry_count;
1427 ha->loop_reset_delay = nv->reset_delay;
1429 /* Will get the value from NVRAM. */
1430 ha->loop_down_timeout = LOOP_DOWN_TIMEOUT;
1432 /* Link Down Timeout = 0:
1434 * When Port Down timer expires we will start returning
1435 * I/O's to OS with "DID_NO_CONNECT".
1437 * Link Down Timeout != 0:
1439 * The driver waits for the link to come up after link down
1440 * before returning I/Os to OS with "DID_NO_CONNECT".
1442 if (nv->link_down_timeout == 0) {
1443 ha->loop_down_abort_time =
1444 (LOOP_DOWN_TIME - ha->loop_down_timeout);
1446 ha->link_down_timeout = nv->link_down_timeout;
1447 ha->loop_down_abort_time =
1448 (LOOP_DOWN_TIME - ha->link_down_timeout);
1451 ha->max_luns = MAX_LUNS;
1452 ha->max_probe_luns = le16_to_cpu(nv->max_luns_per_target);
1453 if (ha->max_probe_luns == 0)
1454 ha->max_probe_luns = MIN_LUNS;
1457 * Need enough time to try and get the port back.
1459 ha->port_down_retry_count = nv->port_down_retry_count;
1460 if (qlport_down_retry)
1461 ha->port_down_retry_count = qlport_down_retry;
1462 /* Set login_retry_count */
1463 ha->login_retry_count = nv->retry_count;
1464 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1465 ha->port_down_retry_count > 3)
1466 ha->login_retry_count = ha->port_down_retry_count;
1467 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1468 ha->login_retry_count = ha->port_down_retry_count;
1469 if (ql2xloginretrycount)
1470 ha->login_retry_count = ql2xloginretrycount;
1472 ha->binding_type = Bind;
1473 if (ha->binding_type != BIND_BY_PORT_NAME &&
1474 ha->binding_type != BIND_BY_PORT_ID) {
1475 qla_printk(KERN_WARNING, ha,
1476 "Invalid binding type specified (%d), "
1477 "defaulting to BIND_BY_PORT_NAME!!!\n", ha->binding_type);
1479 ha->binding_type = BIND_BY_PORT_NAME;
1482 icb->lun_enables = __constant_cpu_to_le16(0);
1483 icb->command_resource_count = 0;
1484 icb->immediate_notify_resource_count = 0;
1485 icb->timeout = __constant_cpu_to_le16(0);
1487 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1489 icb->firmware_options[0] &= ~BIT_3;
1490 icb->add_firmware_options[0] &=
1491 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1492 icb->add_firmware_options[0] |= BIT_2;
1493 icb->response_accumulation_timer = 3;
1494 icb->interrupt_delay_timer = 5;
1496 ha->flags.process_response_queue = 1;
1498 /* Enable ZIO -- Support mode 5 only. */
1499 timer_mode = icb->add_firmware_options[0] &
1500 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1501 icb->add_firmware_options[0] &=
1502 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1504 timer_mode = BIT_2 | BIT_0;
1505 if (timer_mode == (BIT_2 | BIT_0)) {
1506 DEBUG2(printk("scsi(%ld): ZIO enabled; timer delay "
1507 "(%d).\n", ha->host_no, ql2xintrdelaytimer));
1508 qla_printk(KERN_INFO, ha,
1509 "ZIO enabled; timer delay (%d).\n",
1510 ql2xintrdelaytimer);
1512 icb->add_firmware_options[0] |= timer_mode;
1513 icb->interrupt_delay_timer = ql2xintrdelaytimer;
1514 ha->flags.process_response_queue = 1;
1519 DEBUG2_3(printk(KERN_WARNING
1520 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1526 * qla2x00_init_tgt_map
1527 * Initializes target map.
1530 * ha = adapter block pointer.
1536 qla2x00_init_tgt_map(scsi_qla_host_t *ha)
1540 for (t = 0; t < MAX_TARGETS; t++)
1541 TGT_Q(ha, t) = (os_tgt_t *)NULL;
1545 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1547 * @flags: allocation flags
1549 * Returns a pointer to the allocated fcport, or NULL, if none available.
1552 qla2x00_alloc_fcport(scsi_qla_host_t *ha, int flags)
1556 fcport = kmalloc(sizeof(fc_port_t), flags);
1560 /* Setup fcport template structure. */
1561 memset(fcport, 0, sizeof (fc_port_t));
1563 fcport->port_type = FCT_UNKNOWN;
1564 fcport->loop_id = FC_NO_LOOP_ID;
1565 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1566 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1567 fcport->flags = FCF_RLC_SUPPORT;
1568 INIT_LIST_HEAD(&fcport->fcluns);
1574 * qla2x00_configure_loop
1575 * Updates Fibre Channel Device Database with what is actually on loop.
1578 * ha = adapter block pointer.
1583 * 2 = database was full and device was not configured.
1586 qla2x00_configure_loop(scsi_qla_host_t *ha)
1589 unsigned long flags, save_flags;
1593 /* Get Initiator ID */
1594 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1595 rval = qla2x00_configure_hba(ha);
1596 if (rval != QLA_SUCCESS) {
1597 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1603 save_flags = flags = ha->dpc_flags;
1604 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1605 ha->host_no, flags));
1608 * If we have both an RSCN and PORT UPDATE pending then handle them
1609 * both at the same time.
1611 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1612 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1615 /* Determine what we need to do */
1616 if (ha->current_topology == ISP_CFG_FL &&
1617 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1619 ha->flags.rscn_queue_overflow = 1;
1620 set_bit(RSCN_UPDATE, &flags);
1622 } else if (ha->current_topology == ISP_CFG_F &&
1623 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1625 ha->flags.rscn_queue_overflow = 1;
1626 set_bit(RSCN_UPDATE, &flags);
1627 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1629 } else if (!ha->flags.online ||
1630 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1632 ha->flags.rscn_queue_overflow = 1;
1633 set_bit(RSCN_UPDATE, &flags);
1634 set_bit(LOCAL_LOOP_UPDATE, &flags);
1637 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1638 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1639 rval = QLA_FUNCTION_FAILED;
1641 rval = qla2x00_configure_local_loop(ha);
1645 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1646 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1647 rval = QLA_FUNCTION_FAILED;
1649 rval = qla2x00_configure_fabric(ha);
1653 if (rval == QLA_SUCCESS) {
1654 if (atomic_read(&ha->loop_down_timer) ||
1655 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1656 rval = QLA_FUNCTION_FAILED;
1658 qla2x00_config_os(ha);
1659 atomic_set(&ha->loop_state, LOOP_READY);
1661 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1666 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1667 __func__, ha->host_no));
1669 DEBUG3(printk("%s: exiting normally\n", __func__));
1672 /* Restore state if a resync event occured during processing */
1673 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1674 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1675 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1676 if (test_bit(RSCN_UPDATE, &save_flags))
1677 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1686 * qla2x00_configure_local_loop
1687 * Updates Fibre Channel Device Database with local loop devices.
1690 * ha = adapter block pointer.
1696 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1701 fc_port_t *fcport, *new_fcport;
1707 uint8_t domain, area, al_pa;
1711 entries = MAX_FIBRE_DEVICES;
1713 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1714 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1716 /* Get list of logged in devices. */
1717 memset(ha->gid_list, 0, GID_LIST_SIZE);
1718 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1720 if (rval != QLA_SUCCESS)
1721 goto cleanup_allocation;
1723 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1724 ha->host_no, entries));
1725 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1726 entries * sizeof(struct gid_list_info)));
1728 /* Allocate temporary fcport for any new fcports discovered. */
1729 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1730 if (new_fcport == NULL) {
1731 rval = QLA_MEMORY_ALLOC_FAILED;
1732 goto cleanup_allocation;
1734 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1737 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1739 list_for_each_entry(fcport, &ha->fcports, list) {
1740 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1741 fcport->port_type != FCT_BROADCAST &&
1742 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1744 DEBUG(printk("scsi(%ld): Marking port lost, "
1746 ha->host_no, fcport->loop_id));
1748 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1749 fcport->flags &= ~FCF_FARP_DONE;
1753 /* Add devices to port list. */
1754 id_iter = (char *)ha->gid_list;
1755 for (index = 0; index < entries; index++) {
1756 domain = ((struct gid_list_info *)id_iter)->domain;
1757 area = ((struct gid_list_info *)id_iter)->area;
1758 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1759 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1760 loop_id = (uint16_t)
1761 ((struct gid_list_info *)id_iter)->loop_id_2100;
1764 loop_id = le16_to_cpu(
1765 ((struct gid_list_info *)id_iter)->loop_id);
1769 /* Bypass reserved domain fields. */
1770 if ((domain & 0xf0) == 0xf0)
1773 /* Bypass if not same domain and area of adapter. */
1774 if (area != ha->d_id.b.area || domain != ha->d_id.b.domain)
1777 /* Bypass invalid local loop ID. */
1778 if (loop_id > LAST_LOCAL_LOOP_ID)
1781 /* Fill in member data. */
1782 new_fcport->d_id.b.domain = domain;
1783 new_fcport->d_id.b.area = area;
1784 new_fcport->d_id.b.al_pa = al_pa;
1785 new_fcport->loop_id = loop_id;
1786 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1787 if (rval2 != QLA_SUCCESS) {
1788 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1789 "information -- get_port_database=%x, "
1791 ha->host_no, rval2, new_fcport->loop_id));
1795 /* Check for matching device in port list. */
1798 list_for_each_entry(fcport, &ha->fcports, list) {
1799 if (memcmp(new_fcport->port_name, fcport->port_name,
1803 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1804 FCF_PERSISTENT_BOUND);
1805 fcport->loop_id = new_fcport->loop_id;
1806 fcport->port_type = new_fcport->port_type;
1807 fcport->d_id.b24 = new_fcport->d_id.b24;
1808 memcpy(fcport->node_name, new_fcport->node_name,
1816 /* New device, add to fcports list. */
1817 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1818 list_add_tail(&new_fcport->list, &ha->fcports);
1820 /* Allocate a new replacement fcport. */
1821 fcport = new_fcport;
1822 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1823 if (new_fcport == NULL) {
1824 rval = QLA_MEMORY_ALLOC_FAILED;
1825 goto cleanup_allocation;
1827 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1830 qla2x00_update_fcport(ha, fcport);
1839 if (rval != QLA_SUCCESS) {
1840 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1841 "rval=%x\n", ha->host_no, rval));
1845 ha->device_flags |= DFLG_LOCAL_DEVICES;
1846 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
1853 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
1857 qla2x00_mark_all_devices_lost(ha);
1858 list_for_each_entry(fcport, &ha->fcports, list) {
1859 if (fcport->port_type != FCT_TARGET)
1862 qla2x00_update_fcport(ha, fcport);
1867 * qla2x00_update_fcport
1868 * Updates device on list.
1871 * ha = adapter block pointer.
1872 * fcport = port structure pointer.
1882 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
1885 unsigned long flags;
1889 fcport->login_retry = 0;
1890 fcport->port_login_retry_count = ha->port_down_retry_count *
1892 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
1894 fcport->flags &= ~FCF_LOGIN_NEEDED;
1897 * Check for outstanding cmd on tape Bypass LUN discovery if active
1900 if (fcport->flags & FCF_TAPE_PRESENT) {
1901 spin_lock_irqsave(&ha->hardware_lock, flags);
1902 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
1903 if ((sp = ha->outstanding_cmds[index]) != 0) {
1904 if (sp->fclun->fcport == fcport) {
1905 atomic_set(&fcport->state, FCS_ONLINE);
1906 spin_unlock_irqrestore(
1907 &ha->hardware_lock, flags);
1912 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1915 /* Do LUN discovery. */
1916 if (fcport->port_type == FCT_INITIATOR ||
1917 fcport->port_type == FCT_BROADCAST) {
1918 fcport->device_type = TYPE_PROCESSOR;
1920 qla2x00_lun_discovery(ha, fcport);
1922 atomic_set(&fcport->state, FCS_ONLINE);
1926 * qla2x00_lun_discovery
1927 * Issue SCSI inquiry command for LUN discovery.
1930 * ha: adapter state pointer.
1931 * fcport: FC port structure pointer.
1937 qla2x00_lun_discovery(scsi_qla_host_t *ha, fc_port_t *fcport)
1943 inq = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &inq_dma);
1945 qla_printk(KERN_WARNING, ha,
1946 "Memory Allocation failed - INQ\n");
1950 /* If report LUN works, exit. */
1951 if (qla2x00_rpt_lun_discovery(ha, fcport, inq, inq_dma) !=
1953 for (lun = 0; lun < ha->max_probe_luns; lun++) {
1954 /* Configure LUN. */
1955 qla2x00_cfg_lun(ha, fcport, lun, inq, inq_dma);
1959 dma_pool_free(ha->s_dma_pool, inq, inq_dma);
1963 * qla2x00_rpt_lun_discovery
1964 * Issue SCSI report LUN command for LUN discovery.
1967 * ha: adapter state pointer.
1968 * fcport: FC port structure pointer.
1971 * qla2x00 local function return status code.
1977 qla2x00_rpt_lun_discovery(scsi_qla_host_t *ha, fc_port_t *fcport,
1978 inq_cmd_rsp_t *inq, dma_addr_t inq_dma)
1984 /* Assume a failed status */
1985 rval = QLA_FUNCTION_FAILED;
1987 /* No point in continuing if the device doesn't support RLC */
1988 if ((fcport->flags & FCF_RLC_SUPPORT) == 0)
1991 rval = qla2x00_report_lun(ha, fcport);
1992 if (rval != QLA_SUCCESS)
1995 /* Always add a fc_lun_t structure for lun 0 -- mid-layer requirement */
1996 qla2x00_add_lun(fcport, 0);
1998 /* Configure LUN list. */
1999 len = be32_to_cpu(ha->rlc_rsp->list.hdr.len);
2001 for (cnt = 0; cnt < len; cnt++) {
2002 lun = CHAR_TO_SHORT(ha->rlc_rsp->list.lst[cnt].lsb,
2003 ha->rlc_rsp->list.lst[cnt].msb.b);
2005 DEBUG3(printk("scsi(%ld): RLC lun = (%d)\n", ha->host_no, lun));
2007 /* We only support 0 through MAX_LUNS-1 range */
2008 if (lun < MAX_LUNS) {
2009 qla2x00_cfg_lun(ha, fcport, lun, inq, inq_dma);
2012 atomic_set(&fcport->state, FCS_ONLINE);
2018 * qla2x00_report_lun
2019 * Issue SCSI report LUN command.
2022 * ha: adapter state pointer.
2023 * fcport: FC port structure pointer.
2026 * qla2x00 local function return status code.
2032 qla2x00_report_lun(scsi_qla_host_t *ha, fc_port_t *fcport)
2036 uint16_t comp_status;
2037 uint16_t scsi_status;
2038 rpt_lun_cmd_rsp_t *rlc;
2041 rval = QLA_FUNCTION_FAILED;
2043 rlc_dma = ha->rlc_rsp_dma;
2045 for (retries = 3; retries; retries--) {
2046 memset(rlc, 0, sizeof(rpt_lun_cmd_rsp_t));
2047 rlc->p.cmd.entry_type = COMMAND_A64_TYPE;
2048 rlc->p.cmd.entry_count = 1;
2049 SET_TARGET_ID(ha, rlc->p.cmd.target, fcport->loop_id);
2050 rlc->p.cmd.control_flags =
2051 __constant_cpu_to_le16(CF_READ | CF_SIMPLE_TAG);
2052 rlc->p.cmd.scsi_cdb[0] = REPORT_LUNS;
2053 rlc->p.cmd.scsi_cdb[8] = MSB(sizeof(rpt_lun_lst_t));
2054 rlc->p.cmd.scsi_cdb[9] = LSB(sizeof(rpt_lun_lst_t));
2055 rlc->p.cmd.dseg_count = __constant_cpu_to_le16(1);
2056 rlc->p.cmd.timeout = __constant_cpu_to_le16(10);
2057 rlc->p.cmd.byte_count =
2058 __constant_cpu_to_le32(sizeof(rpt_lun_lst_t));
2059 rlc->p.cmd.dseg_0_address[0] = cpu_to_le32(
2060 LSD(rlc_dma + sizeof(sts_entry_t)));
2061 rlc->p.cmd.dseg_0_address[1] = cpu_to_le32(
2062 MSD(rlc_dma + sizeof(sts_entry_t)));
2063 rlc->p.cmd.dseg_0_length =
2064 __constant_cpu_to_le32(sizeof(rpt_lun_lst_t));
2066 rval = qla2x00_issue_iocb(ha, rlc, rlc_dma,
2067 sizeof(rpt_lun_cmd_rsp_t));
2069 comp_status = le16_to_cpu(rlc->p.rsp.comp_status);
2070 scsi_status = le16_to_cpu(rlc->p.rsp.scsi_status);
2072 if (rval != QLA_SUCCESS || comp_status != CS_COMPLETE ||
2073 scsi_status & SS_CHECK_CONDITION) {
2075 /* Device underrun, treat as OK. */
2076 if (rval == QLA_SUCCESS &&
2077 comp_status == CS_DATA_UNDERRUN &&
2078 scsi_status & SS_RESIDUAL_UNDER) {
2084 DEBUG(printk("scsi(%ld): RLC failed to issue iocb! "
2085 "fcport=[%04x/%p] rval=%x cs=%x ss=%x\n",
2086 ha->host_no, fcport->loop_id, fcport, rval,
2087 comp_status, scsi_status));
2089 rval = QLA_FUNCTION_FAILED;
2090 if (scsi_status & SS_CHECK_CONDITION) {
2091 DEBUG2(printk("scsi(%ld): RLC "
2092 "SS_CHECK_CONDITION Sense Data "
2093 "%02x %02x %02x %02x %02x %02x %02x %02x\n",
2095 rlc->p.rsp.req_sense_data[0],
2096 rlc->p.rsp.req_sense_data[1],
2097 rlc->p.rsp.req_sense_data[2],
2098 rlc->p.rsp.req_sense_data[3],
2099 rlc->p.rsp.req_sense_data[4],
2100 rlc->p.rsp.req_sense_data[5],
2101 rlc->p.rsp.req_sense_data[6],
2102 rlc->p.rsp.req_sense_data[7]));
2103 if (rlc->p.rsp.req_sense_data[2] ==
2105 fcport->flags &= ~(FCF_RLC_SUPPORT);
2119 * Configures LUN into fcport LUN list.
2122 * fcport: FC port structure pointer.
2129 qla2x00_cfg_lun(scsi_qla_host_t *ha, fc_port_t *fcport, uint16_t lun,
2130 inq_cmd_rsp_t *inq, dma_addr_t inq_dma)
2134 /* Bypass LUNs that failed. */
2135 if (qla2x00_inquiry(ha, fcport, lun, inq, inq_dma) != QLA_SUCCESS) {
2136 DEBUG2(printk("scsi(%ld): Failed inquiry - loop id=0x%04x "
2137 "lun=%d\n", ha->host_no, fcport->loop_id, lun));
2142 switch (inq->inq[0]) {
2144 case TYPE_PROCESSOR:
2149 case TYPE_MEDIUM_CHANGER:
2150 case TYPE_ENCLOSURE:
2155 fcport->flags |= FCF_TAPE_PRESENT;
2158 DEBUG2(printk("scsi(%ld): Unsupported lun type -- "
2159 "loop id=0x%04x lun=%d type=%x\n",
2160 ha->host_no, fcport->loop_id, lun, inq->inq[0]));
2164 fcport->device_type = inq->inq[0];
2165 fclun = qla2x00_add_lun(fcport, lun);
2167 if (fclun != NULL) {
2168 atomic_set(&fcport->state, FCS_ONLINE);
2176 * Adds LUN to database
2179 * fcport: FC port structure pointer.
2186 qla2x00_add_lun(fc_port_t *fcport, uint16_t lun)
2191 if (fcport == NULL) {
2192 DEBUG(printk("scsi: Unable to add lun to NULL port\n"));
2196 /* Allocate LUN if not already allocated. */
2198 list_for_each_entry(fclun, &fcport->fcluns, list) {
2199 if (fclun->lun == lun) {
2207 fclun = kmalloc(sizeof(fc_lun_t), GFP_ATOMIC);
2208 if (fclun == NULL) {
2210 "%s(): Memory Allocation failed - FCLUN\n",
2215 /* Setup LUN structure. */
2216 memset(fclun, 0, sizeof(fc_lun_t));
2218 fclun->fcport = fcport;
2219 fclun->o_fcport = fcport;
2220 fclun->device_type = fcport->device_type;
2221 atomic_set(&fcport->state, FCS_UNCONFIGURED);
2223 list_add_tail(&fclun->list, &fcport->fcluns);
2230 * Issue SCSI inquiry command.
2233 * ha = adapter block pointer.
2234 * fcport = FC port structure pointer.
2244 qla2x00_inquiry(scsi_qla_host_t *ha,
2245 fc_port_t *fcport, uint16_t lun, inq_cmd_rsp_t *inq, dma_addr_t inq_dma)
2249 uint16_t comp_status;
2250 uint16_t scsi_status;
2252 rval = QLA_FUNCTION_FAILED;
2254 for (retries = 3; retries; retries--) {
2255 memset(inq, 0, sizeof(inq_cmd_rsp_t));
2256 inq->p.cmd.entry_type = COMMAND_A64_TYPE;
2257 inq->p.cmd.entry_count = 1;
2258 inq->p.cmd.lun = cpu_to_le16(lun);
2259 SET_TARGET_ID(ha, inq->p.cmd.target, fcport->loop_id);
2260 inq->p.cmd.control_flags =
2261 __constant_cpu_to_le16(CF_READ | CF_SIMPLE_TAG);
2262 inq->p.cmd.scsi_cdb[0] = INQUIRY;
2263 inq->p.cmd.scsi_cdb[4] = INQ_DATA_SIZE;
2264 inq->p.cmd.dseg_count = __constant_cpu_to_le16(1);
2265 inq->p.cmd.timeout = __constant_cpu_to_le16(10);
2266 inq->p.cmd.byte_count =
2267 __constant_cpu_to_le32(INQ_DATA_SIZE);
2268 inq->p.cmd.dseg_0_address[0] = cpu_to_le32(
2269 LSD(inq_dma + sizeof(sts_entry_t)));
2270 inq->p.cmd.dseg_0_address[1] = cpu_to_le32(
2271 MSD(inq_dma + sizeof(sts_entry_t)));
2272 inq->p.cmd.dseg_0_length =
2273 __constant_cpu_to_le32(INQ_DATA_SIZE);
2275 DEBUG5(printk("scsi(%ld): Lun Inquiry - fcport=[%04x/%p],"
2277 ha->host_no, fcport->loop_id, fcport, lun));
2279 rval = qla2x00_issue_iocb(ha, inq, inq_dma,
2280 sizeof(inq_cmd_rsp_t));
2282 comp_status = le16_to_cpu(inq->p.rsp.comp_status);
2283 scsi_status = le16_to_cpu(inq->p.rsp.scsi_status);
2285 DEBUG5(printk("scsi(%ld): lun (%d) inquiry - "
2286 "inq[0]= 0x%x, comp status 0x%x, scsi status 0x%x, "
2288 ha->host_no, lun, inq->inq[0], comp_status, scsi_status,
2291 if (rval != QLA_SUCCESS || comp_status != CS_COMPLETE ||
2292 scsi_status & SS_CHECK_CONDITION) {
2294 DEBUG(printk("scsi(%ld): INQ failed to issue iocb! "
2295 "fcport=[%04x/%p] rval=%x cs=%x ss=%x\n",
2296 ha->host_no, fcport->loop_id, fcport, rval,
2297 comp_status, scsi_status));
2299 if (rval == QLA_SUCCESS)
2300 rval = QLA_FUNCTION_FAILED;
2302 if (scsi_status & SS_CHECK_CONDITION) {
2303 DEBUG2(printk("scsi(%ld): INQ "
2304 "SS_CHECK_CONDITION Sense Data "
2305 "%02x %02x %02x %02x %02x %02x %02x %02x\n",
2307 inq->p.rsp.req_sense_data[0],
2308 inq->p.rsp.req_sense_data[1],
2309 inq->p.rsp.req_sense_data[2],
2310 inq->p.rsp.req_sense_data[3],
2311 inq->p.rsp.req_sense_data[4],
2312 inq->p.rsp.req_sense_data[5],
2313 inq->p.rsp.req_sense_data[6],
2314 inq->p.rsp.req_sense_data[7]));
2317 /* Device underrun drop LUN. */
2318 if (comp_status == CS_DATA_UNDERRUN &&
2319 scsi_status & SS_RESIDUAL_UNDER) {
2332 * qla2x00_configure_fabric
2333 * Setup SNS devices with loop ID's.
2336 * ha = adapter block pointer.
2343 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2346 fc_port_t *fcport, *fcptemp;
2347 uint16_t next_loopid;
2348 uint16_t mb[MAILBOX_REGISTER_COUNT];
2349 LIST_HEAD(new_fcports);
2351 /* If FL port exists, then SNS is present */
2352 rval = qla2x00_get_port_name(ha, SNS_FL_PORT, NULL, 0);
2353 if (rval != QLA_SUCCESS) {
2354 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2355 "Port\n", ha->host_no));
2357 ha->device_flags &= ~SWITCH_FOUND;
2358 return (QLA_SUCCESS);
2361 /* Mark devices that need re-synchronization. */
2362 rval2 = qla2x00_device_resync(ha);
2363 if (rval2 == QLA_RSCNS_HANDLED) {
2364 /* No point doing the scan, just continue. */
2365 return (QLA_SUCCESS);
2368 /* Ensure we are logged into the SNS. */
2369 qla2x00_login_fabric(ha, SIMPLE_NAME_SERVER, 0xff, 0xff, 0xfc,
2371 if (mb[0] != MBS_COMMAND_COMPLETE) {
2372 DEBUG2(qla_printk(KERN_INFO, ha,
2373 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2374 "mb[2]=%x mb[6]=%x mb[7]=%x\n", SIMPLE_NAME_SERVER,
2375 mb[0], mb[1], mb[2], mb[6], mb[7]));
2376 return (QLA_SUCCESS);
2379 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2380 if (qla2x00_rft_id(ha)) {
2382 DEBUG2(printk("scsi(%ld): Register FC-4 "
2383 "TYPE failed.\n", ha->host_no));
2385 if (qla2x00_rff_id(ha)) {
2387 DEBUG2(printk("scsi(%ld): Register FC-4 "
2388 "Features failed.\n", ha->host_no));
2390 if (qla2x00_rnn_id(ha)) {
2392 DEBUG2(printk("scsi(%ld): Register Node Name "
2393 "failed.\n", ha->host_no));
2394 } else if (qla2x00_rsnn_nn(ha)) {
2396 DEBUG2(printk("scsi(%ld): Register Symbolic "
2397 "Node Name failed.\n", ha->host_no));
2401 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2402 if (rval != QLA_SUCCESS)
2406 * Logout all previous fabric devices marked lost, except
2409 list_for_each_entry(fcport, &ha->fcports, list) {
2410 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2413 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2416 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2417 qla2x00_mark_device_lost(ha, fcport,
2418 ql2xplogiabsentdevice);
2419 if (fcport->loop_id != FC_NO_LOOP_ID &&
2420 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2421 fcport->port_type != FCT_INITIATOR &&
2422 fcport->port_type != FCT_BROADCAST) {
2424 qla2x00_fabric_logout(ha,
2426 fcport->loop_id = FC_NO_LOOP_ID;
2431 /* Starting free loop ID. */
2432 next_loopid = ha->min_external_loopid;
2435 * Scan through our port list and login entries that need to be
2438 list_for_each_entry(fcport, &ha->fcports, list) {
2439 if (atomic_read(&ha->loop_down_timer) ||
2440 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2443 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2444 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2447 if (fcport->loop_id == FC_NO_LOOP_ID) {
2448 fcport->loop_id = next_loopid;
2449 rval = qla2x00_find_new_loop_id(ha, fcport);
2450 if (rval != QLA_SUCCESS) {
2451 /* Ran out of IDs to use */
2456 /* Login and update database */
2457 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2460 /* Exit if out of loop IDs. */
2461 if (rval != QLA_SUCCESS) {
2466 * Login and add the new devices to our port list.
2468 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2469 if (atomic_read(&ha->loop_down_timer) ||
2470 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2473 /* Find a new loop ID to use. */
2474 fcport->loop_id = next_loopid;
2475 rval = qla2x00_find_new_loop_id(ha, fcport);
2476 if (rval != QLA_SUCCESS) {
2477 /* Ran out of IDs to use */
2481 /* Login and update database */
2482 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2484 /* Remove device from the new list and add it to DB */
2485 list_del(&fcport->list);
2486 list_add_tail(&fcport->list, &ha->fcports);
2490 /* Free all new device structures not processed. */
2491 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2492 list_del(&fcport->list);
2497 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2498 "rval=%d\n", ha->host_no, rval));
2506 * qla2x00_find_all_fabric_devs
2509 * ha = adapter block pointer.
2510 * dev = database device entry pointer.
2519 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2523 fc_port_t *fcport, *new_fcport;
2528 int first_dev, last_dev;
2529 port_id_t wrap, nxt_d_id;
2533 /* Try GID_PT to get device list, else GAN. */
2534 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2537 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2538 "on GA_NXT\n", ha->host_no));
2540 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2541 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2544 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2547 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2554 /* Allocate temporary fcport for any new fcports discovered. */
2555 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2556 if (new_fcport == NULL) {
2559 return (QLA_MEMORY_ALLOC_FAILED);
2561 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2563 /* Set start port ID scan at adapter ID. */
2567 /* Starting free loop ID. */
2568 loop_id = ha->min_external_loopid;
2570 for (; loop_id <= ha->last_loop_id; loop_id++) {
2571 if (RESERVED_LOOP_ID(loop_id))
2574 if (atomic_read(&ha->loop_down_timer) ||
2575 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2580 wrap.b24 = new_fcport->d_id.b24;
2582 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2583 memcpy(new_fcport->node_name,
2584 swl[swl_idx].node_name, WWN_SIZE);
2585 memcpy(new_fcport->port_name,
2586 swl[swl_idx].port_name, WWN_SIZE);
2588 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2594 /* Send GA_NXT to the switch */
2595 rval = qla2x00_ga_nxt(ha, new_fcport);
2596 if (rval != QLA_SUCCESS) {
2601 /* If wrap on switch device list, exit. */
2603 wrap.b24 = new_fcport->d_id.b24;
2605 } else if (new_fcport->d_id.b24 == wrap.b24) {
2606 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2607 ha->host_no, new_fcport->d_id.b.domain,
2608 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2612 /* Bypass if host adapter. */
2613 if (new_fcport->d_id.b24 == ha->d_id.b24)
2616 /* Bypass reserved domain fields. */
2617 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2620 /* Locate matching device in database. */
2622 list_for_each_entry(fcport, &ha->fcports, list) {
2623 if (memcmp(new_fcport->port_name, fcport->port_name,
2630 * If address the same and state FCS_ONLINE, nothing
2633 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2634 atomic_read(&fcport->state) == FCS_ONLINE) {
2639 * If device was not a fabric device before.
2641 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2642 fcport->d_id.b24 = new_fcport->d_id.b24;
2643 fcport->loop_id = FC_NO_LOOP_ID;
2644 fcport->flags |= (FCF_FABRIC_DEVICE |
2646 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2651 * Port ID changed or device was marked to be updated;
2652 * Log it out if still logged in and mark it for
2655 fcport->d_id.b24 = new_fcport->d_id.b24;
2656 fcport->flags |= FCF_LOGIN_NEEDED;
2657 if (fcport->loop_id != FC_NO_LOOP_ID &&
2658 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2659 fcport->port_type != FCT_INITIATOR &&
2660 fcport->port_type != FCT_BROADCAST) {
2661 qla2x00_fabric_logout(ha, fcport->loop_id);
2662 fcport->loop_id = FC_NO_LOOP_ID;
2671 /* If device was not in our fcports list, then add it. */
2672 list_add_tail(&new_fcport->list, new_fcports);
2674 /* Allocate a new replacement fcport. */
2675 nxt_d_id.b24 = new_fcport->d_id.b24;
2676 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2677 if (new_fcport == NULL) {
2680 return (QLA_MEMORY_ALLOC_FAILED);
2682 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2683 new_fcport->d_id.b24 = nxt_d_id.b24;
2692 if (!list_empty(new_fcports))
2693 ha->device_flags |= DFLG_FABRIC_DEVICES;
2699 * qla2x00_find_new_loop_id
2700 * Scan through our port list and find a new usable loop ID.
2703 * ha: adapter state pointer.
2704 * dev: port structure pointer.
2707 * qla2x00 local function return status code.
2713 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2718 uint16_t first_loop_id;
2722 /* Save starting loop ID. */
2723 first_loop_id = dev->loop_id;
2726 /* Skip loop ID if already used by adapter. */
2727 if (dev->loop_id == ha->loop_id) {
2731 /* Skip reserved loop IDs. */
2732 while (RESERVED_LOOP_ID(dev->loop_id)) {
2736 /* Reset loop ID if passed the end. */
2737 if (dev->loop_id > ha->last_loop_id) {
2738 /* first loop ID. */
2739 dev->loop_id = ha->min_external_loopid;
2742 /* Check for loop ID being already in use. */
2745 list_for_each_entry(fcport, &ha->fcports, list) {
2746 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2747 /* ID possibly in use */
2753 /* If not in use then it is free to use. */
2758 /* ID in use. Try next value. */
2761 /* If wrap around. No free ID to use. */
2762 if (dev->loop_id == first_loop_id) {
2763 dev->loop_id = FC_NO_LOOP_ID;
2764 rval = QLA_FUNCTION_FAILED;
2773 * qla2x00_device_resync
2774 * Marks devices in the database that needs resynchronization.
2777 * ha = adapter block pointer.
2783 qla2x00_device_resync(scsi_qla_host_t *ha)
2789 uint32_t rscn_entry;
2790 uint8_t rscn_out_iter;
2794 rval = QLA_RSCNS_HANDLED;
2796 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2797 ha->flags.rscn_queue_overflow) {
2799 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2800 format = MSB(MSW(rscn_entry));
2801 d_id.b.domain = LSB(MSW(rscn_entry));
2802 d_id.b.area = MSB(LSW(rscn_entry));
2803 d_id.b.al_pa = LSB(LSW(rscn_entry));
2805 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2806 "[%02x/%02x%02x%02x].\n",
2807 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2808 d_id.b.area, d_id.b.al_pa));
2811 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2812 ha->rscn_out_ptr = 0;
2814 /* Skip duplicate entries. */
2815 for (rscn_out_iter = ha->rscn_out_ptr;
2816 !ha->flags.rscn_queue_overflow &&
2817 rscn_out_iter != ha->rscn_in_ptr;
2818 rscn_out_iter = (rscn_out_iter ==
2819 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2821 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2824 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2825 "entry found at [%d].\n", ha->host_no,
2828 ha->rscn_out_ptr = rscn_out_iter;
2831 /* Queue overflow, set switch default case. */
2832 if (ha->flags.rscn_queue_overflow) {
2833 DEBUG(printk("scsi(%ld): device_resync: rscn "
2834 "overflow.\n", ha->host_no));
2837 ha->flags.rscn_queue_overflow = 0;
2842 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) &&
2843 !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
2844 ha->flags.init_done) {
2845 /* Handle port RSCN via asyncronous IOCBs */
2846 rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
2848 if (rval2 == QLA_SUCCESS)
2862 ha->rscn_out_ptr = ha->rscn_in_ptr;
2868 /* Abort any outstanding IO descriptors. */
2869 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2870 qla2x00_cancel_io_descriptors(ha);
2872 list_for_each_entry(fcport, &ha->fcports, list) {
2873 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2874 (fcport->d_id.b24 & mask) != d_id.b24 ||
2875 fcport->port_type == FCT_BROADCAST)
2878 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2880 fcport->port_type != FCT_INITIATOR) {
2881 atomic_set(&fcport->state,
2885 fcport->flags &= ~FCF_FARP_DONE;
2892 * qla2x00_fabric_dev_login
2893 * Login fabric target device and update FC port database.
2896 * ha: adapter state pointer.
2897 * fcport: port structure list pointer.
2898 * next_loopid: contains value of a new loop ID that can be used
2899 * by the next login attempt.
2902 * qla2x00 local function return status code.
2908 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2909 uint16_t *next_loopid)
2917 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2918 if (rval == QLA_SUCCESS) {
2919 rval = qla2x00_get_port_database(ha, fcport, 0);
2920 if (rval != QLA_SUCCESS) {
2921 qla2x00_fabric_logout(ha, fcport->loop_id);
2923 qla2x00_update_fcport(ha, fcport);
2931 * qla2x00_fabric_login
2932 * Issue fabric login command.
2935 * ha = adapter block pointer.
2936 * device = pointer to FC device type structure.
2939 * 0 - Login successfully
2941 * 2 - Initiator device
2945 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2946 uint16_t *next_loopid)
2950 uint16_t tmp_loopid;
2951 uint16_t mb[MAILBOX_REGISTER_COUNT];
2957 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2958 "for port %02x%02x%02x.\n",
2959 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2960 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2962 /* Login fcport on switch. */
2963 qla2x00_login_fabric(ha, fcport->loop_id,
2964 fcport->d_id.b.domain, fcport->d_id.b.area,
2965 fcport->d_id.b.al_pa, mb, BIT_0);
2966 if (mb[0] == MBS_PORT_ID_USED) {
2968 * Device has another loop ID. The firmware team
2969 * recommends us to perform an implicit login with the
2970 * specified ID again. The ID we just used is save here
2971 * so we return with an ID that can be tried by the
2975 tmp_loopid = fcport->loop_id;
2976 fcport->loop_id = mb[1];
2978 DEBUG(printk("Fabric Login: port in use - next "
2979 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2980 fcport->loop_id, fcport->d_id.b.domain,
2981 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2983 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2988 /* A retry occurred before. */
2989 *next_loopid = tmp_loopid;
2992 * No retry occurred before. Just increment the
2993 * ID value for next login.
2995 *next_loopid = (fcport->loop_id + 1);
2998 if (mb[1] & BIT_0) {
2999 fcport->port_type = FCT_INITIATOR;
3001 fcport->port_type = FCT_TARGET;
3002 if (mb[1] & BIT_1) {
3003 fcport->flags |= FCF_TAPE_PRESENT;
3009 } else if (mb[0] == MBS_LOOP_ID_USED) {
3011 * Loop ID already used, try next loop ID.
3014 rval = qla2x00_find_new_loop_id(ha, fcport);
3015 if (rval != QLA_SUCCESS) {
3016 /* Ran out of loop IDs to use */
3019 } else if (mb[0] == MBS_COMMAND_ERROR) {
3021 * Firmware possibly timed out during login. If NO
3022 * retries are left to do then the device is declared
3025 *next_loopid = fcport->loop_id;
3026 qla2x00_fabric_logout(ha, fcport->loop_id);
3027 fcport->loop_id = FC_NO_LOOP_ID;
3033 * unrecoverable / not handled error
3035 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3036 "loop_id=%x jiffies=%lx.\n",
3037 __func__, ha->host_no, mb[0],
3038 fcport->d_id.b.domain, fcport->d_id.b.area,
3039 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3041 *next_loopid = fcport->loop_id;
3042 qla2x00_fabric_logout(ha, fcport->loop_id);
3043 fcport->loop_id = FC_NO_LOOP_ID;
3044 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
3055 * qla2x00_local_device_login
3056 * Issue local device login command.
3059 * ha = adapter block pointer.
3060 * loop_id = loop id of device to login to.
3062 * Returns (Where's the #define!!!!):
3063 * 0 - Login successfully
3068 qla2x00_local_device_login(scsi_qla_host_t *ha, uint16_t loop_id)
3071 uint16_t mb[MAILBOX_REGISTER_COUNT];
3073 memset(mb, 0, sizeof(mb));
3074 rval = qla2x00_login_local_device(ha, loop_id, mb, BIT_0);
3075 if (rval == QLA_SUCCESS) {
3076 /* Interrogate mailbox registers for any errors */
3077 if (mb[0] == MBS_COMMAND_ERROR)
3079 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3080 /* device not in PCB table */
3088 * qla2x00_loop_resync
3089 * Resync with fibre channel devices.
3092 * ha = adapter block pointer.
3098 qla2x00_loop_resync(scsi_qla_host_t *ha)
3105 atomic_set(&ha->loop_state, LOOP_UPDATE);
3106 qla2x00_stats.loop_resync++;
3107 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3108 if (ha->flags.online) {
3109 if (!(rval = qla2x00_fw_ready(ha))) {
3110 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3114 atomic_set(&ha->loop_state, LOOP_UPDATE);
3117 * Issue marker command only when we are going
3118 * to start the I/O .
3120 ha->marker_needed = 1;
3122 /* Remap devices on Loop. */
3123 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3125 qla2x00_configure_loop(ha);
3127 } while (!atomic_read(&ha->loop_down_timer) &&
3128 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3130 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3132 qla2x00_restart_queues(ha, 1);
3135 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3136 return (QLA_FUNCTION_FAILED);
3140 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3147 * qla2x00_restart_queues
3148 * Restart device queues.
3151 * ha = adapter block pointer.
3154 * Kernel/Interrupt context.
3157 qla2x00_restart_queues(scsi_qla_host_t *ha, uint8_t flush)
3160 int retry_q_cnt = 0;
3161 int pending_q_cnt = 0;
3162 struct list_head *list, *temp;
3163 unsigned long flags = 0;
3165 clear_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
3167 /* start pending queue */
3168 pending_q_cnt = ha->qthreads;
3170 spin_lock_irqsave(&ha->list_lock,flags);
3171 list_for_each_safe(list, temp, &ha->pending_queue) {
3172 sp = list_entry(list, srb_t, list);
3174 if ((sp->flags & SRB_TAPE))
3178 * When time expire return request back to OS as BUSY
3180 __del_from_pending_queue(ha, sp);
3181 sp->cmd->result = DID_BUS_BUSY << 16;
3182 sp->cmd->host_scribble = (unsigned char *)NULL;
3183 __add_to_done_queue(ha, sp);
3185 spin_unlock_irqrestore(&ha->list_lock, flags);
3187 if (!list_empty(&ha->pending_queue))
3192 * Clear out our retry queue
3195 spin_lock_irqsave(&ha->list_lock, flags);
3196 retry_q_cnt = ha->retry_q_cnt;
3197 list_for_each_safe(list, temp, &ha->retry_queue) {
3198 sp = list_entry(list, srb_t, list);
3199 /* when time expire return request back to OS as BUSY */
3200 __del_from_retry_queue(ha, sp);
3201 sp->cmd->result = DID_BUS_BUSY << 16;
3202 sp->cmd->host_scribble = (unsigned char *)NULL;
3203 __add_to_done_queue(ha, sp);
3205 spin_unlock_irqrestore(&ha->list_lock, flags);
3207 DEBUG2(printk("%s(%ld): callback %d commands.\n",
3213 DEBUG2(printk("%s(%ld): active=%ld, retry=%d, pending=%d, "
3214 "done=%ld, scsi retry=%d commands.\n",
3221 ha->scsi_retry_q_cnt);)
3223 if (!list_empty(&ha->done_queue))
3228 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
3234 list_for_each_entry(fcport, &ha->fcports, list) {
3235 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
3238 qla2x00_update_fcport(ha, fcport);
3239 fcport->flags &= ~FCF_RESCAN_NEEDED;
3243 qla2x00_probe_for_all_luns(ha);
3245 /* Update OS target and lun structures if necessary. */
3247 qla2x00_config_os(ha);
3254 * Setup OS target and LUN structures.
3257 * ha = adapter state pointer.
3263 qla2x00_config_os(scsi_qla_host_t *ha)
3271 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
3272 if ((tq = TGT_Q(ha, tgt)) == NULL)
3275 clear_bit(TQF_ONLINE, &tq->flags);
3278 list_for_each_entry(fcport, &ha->fcports, list) {
3279 if (atomic_read(&fcport->state) != FCS_ONLINE ||
3280 fcport->port_type == FCT_INITIATOR ||
3281 fcport->port_type == FCT_BROADCAST) {
3282 fcport->os_target_id = MAX_TARGETS;
3286 if (fcport->flags & FCF_FO_MASKED) {
3290 /* Bind FC port to OS target number. */
3291 if (qla2x00_fcport_bind(ha, fcport) == MAX_TARGETS) {
3295 /* Bind FC LUN to OS LUN number. */
3296 list_for_each_entry(fclun, &fcport->fcluns, list) {
3297 qla2x00_fclun_bind(ha, fcport, fclun);
3303 * qla2x00_fcport_bind
3304 * Locates a target number for FC port.
3307 * ha = adapter state pointer.
3308 * fcport = FC port structure pointer.
3317 qla2x00_fcport_bind(scsi_qla_host_t *ha, fc_port_t *fcport)
3323 /* Check for persistent binding. */
3324 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
3325 if ((tq = TGT_Q(ha, tgt)) == NULL)
3329 switch (ha->binding_type) {
3330 case BIND_BY_PORT_ID:
3331 if (fcport->d_id.b24 == tq->d_id.b24) {
3332 memcpy(tq->node_name, fcport->node_name,
3334 memcpy(tq->port_name, fcport->port_name,
3339 case BIND_BY_PORT_NAME:
3340 if (memcmp(fcport->port_name, tq->port_name,
3343 * In case of persistent binding, update the
3346 memcpy(tq->node_name, fcport->node_name,
3356 /* TODO: honor the ConfigRequired flag */
3357 if (tgt == MAX_TARGETS) {
3358 /* Check if targetID 0 available. */
3361 if (TGT_Q(ha, tgt) != NULL) {
3362 /* Locate first free target for device. */
3363 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
3364 if (TGT_Q(ha, tgt) == NULL) {
3369 if (tgt != MAX_TARGETS) {
3370 if ((tq = qla2x00_tgt_alloc(ha, tgt)) != NULL) {
3371 memcpy(tq->node_name, fcport->node_name,
3373 memcpy(tq->port_name, fcport->port_name,
3375 tq->d_id.b24 = fcport->d_id.b24;
3380 /* Reset target numbers incase it changed. */
3381 fcport->os_target_id = tgt;
3382 if (tgt != MAX_TARGETS && tq != NULL) {
3383 DEBUG2(printk("scsi(%ld): Assigning target ID=%02d @ %p to "
3384 "loop id=0x%04x, port state=0x%x, port down retry=%d\n",
3385 ha->host_no, tgt, tq, fcport->loop_id,
3386 atomic_read(&fcport->state),
3387 atomic_read(&fcport->port_down_timer)));
3389 fcport->tgt_queue = tq;
3390 fcport->flags |= FCF_PERSISTENT_BOUND;
3391 tq->fcport = fcport;
3392 set_bit(TQF_ONLINE, &tq->flags);
3393 tq->port_down_retry_count = ha->port_down_retry_count;
3396 qla2x00_get_lun_mask_from_config(ha, fcport, tgt, 0);
3400 if (tgt == MAX_TARGETS) {
3401 qla_printk(KERN_WARNING, ha,
3402 "Unable to bind fcport, loop_id=%x\n", fcport->loop_id);
3409 * qla2x00_fclun_bind
3410 * Binds all FC device LUNS to OS LUNS.
3413 * ha: adapter state pointer.
3414 * fcport: FC port structure pointer.
3423 qla2x00_fclun_bind(scsi_qla_host_t *ha, fc_port_t *fcport, fc_lun_t *fclun)
3429 tgt = fcport->os_target_id;
3433 if (lun >= MAX_LUNS) {
3434 DEBUG2(printk("scsi(%ld): Unable to bind lun, invalid "
3435 "lun=(%x).\n", ha->host_no, lun));
3439 /* Always alloc LUN 0 so kernel will scan past LUN 0. */
3440 if (lun != 0 && (EXT_IS_LUN_BIT_SET(&(fcport->lun_mask), lun))) {
3444 if ((lq = qla2x00_lun_alloc(ha, tgt, lun)) == NULL) {
3445 qla_printk(KERN_WARNING, ha,
3446 "Unable to bind fclun, loop_id=%x lun=%x\n",
3447 fcport->loop_id, lun);
3458 * Allocate and pre-initialize target queue.
3461 * ha = adapter block pointer.
3462 * t = SCSI target number.
3471 qla2x00_tgt_alloc(scsi_qla_host_t *ha, uint16_t tgt)
3476 * If SCSI addressing OK, allocate TGT queue and lock.
3478 if (tgt >= MAX_TARGETS) {
3479 DEBUG2(printk("scsi(%ld): Unable to allocate target, invalid "
3480 "target number %d.\n", ha->host_no, tgt));
3484 tq = TGT_Q(ha, tgt);
3486 tq = kmalloc(sizeof(os_tgt_t), GFP_ATOMIC);
3488 DEBUG2(printk("scsi(%ld): Alloc Target %d @ %p\n",
3489 ha->host_no, tgt, tq));
3491 memset(tq, 0, sizeof(os_tgt_t));
3494 TGT_Q(ha, tgt) = tq;
3498 tq->port_down_retry_count = ha->port_down_retry_count;
3500 qla_printk(KERN_WARNING, ha,
3501 "Unable to allocate target.\n");
3510 * Frees target and LUN queues.
3513 * ha = adapter block pointer.
3514 * t = SCSI target number.
3520 qla2x00_tgt_free(scsi_qla_host_t *ha, uint16_t tgt)
3526 * If SCSI addressing OK, allocate TGT queue and lock.
3528 if (tgt >= MAX_TARGETS) {
3529 DEBUG2(printk("scsi(%ld): Unable to de-allocate target, "
3530 "invalid target number %d.\n", ha->host_no, tgt));
3535 tq = TGT_Q(ha, tgt);
3537 TGT_Q(ha, tgt) = NULL;
3539 /* Free LUN structures. */
3540 for (lun = 0; lun < MAX_LUNS; lun++)
3541 qla2x00_lun_free(ha, tgt, lun);
3551 * Allocate and initialize LUN queue.
3554 * ha = adapter block pointer.
3555 * t = SCSI target number.
3565 qla2x00_lun_alloc(scsi_qla_host_t *ha, uint16_t tgt, uint16_t lun)
3570 * If SCSI addressing OK, allocate LUN queue.
3572 if (tgt >= MAX_TARGETS || lun >= MAX_LUNS || TGT_Q(ha, tgt) == NULL) {
3573 DEBUG2(printk("scsi(%ld): Unable to allocate lun, invalid "
3574 "parameter.\n", ha->host_no));
3579 lq = LUN_Q(ha, tgt, lun);
3581 lq = kmalloc(sizeof(os_lun_t), GFP_ATOMIC);
3583 DEBUG2(printk("scsi(%ld): Alloc Lun %d @ tgt %d.\n",
3584 ha->host_no, lun, tgt));
3586 memset(lq, 0, sizeof (os_lun_t));
3587 LUN_Q(ha, tgt, lun) = lq;
3590 * The following lun queue initialization code
3591 * must be duplicated in alloc_ioctl_mem function
3594 lq->q_state = LUN_STATE_READY;
3595 spin_lock_init(&lq->q_lock);
3600 qla_printk(KERN_WARNING, ha, "Unable to allocate lun.\n");
3611 * ha = adapter block pointer.
3612 * t = SCSI target number.
3618 qla2x00_lun_free(scsi_qla_host_t *ha, uint16_t tgt, uint16_t lun)
3623 * If SCSI addressing OK, allocate TGT queue and lock.
3625 if (tgt >= MAX_TARGETS || lun >= MAX_LUNS) {
3626 DEBUG2(printk("scsi(%ld): Unable to deallocate lun, invalid "
3627 "parameter.\n", ha->host_no));
3632 if (TGT_Q(ha, tgt) != NULL && (lq = LUN_Q(ha, tgt, lun)) != NULL) {
3633 LUN_Q(ha, tgt, lun) = NULL;
3643 * qla2x00_get_lun_mask_from_config
3644 * Get lun mask from the configuration parameters.
3645 * Bit order is little endian.
3648 * ha -- Host adapter
3649 * tgt -- target/device number
3650 * port -- pointer to port
3653 qla2x00_get_lun_mask_from_config(scsi_qla_host_t *ha,
3654 fc_port_t *fcport, uint16_t tgt, uint16_t dev_no)
3656 char propbuf[60]; /* size of search string */
3658 lun_bit_mask_t lun_mask, *mask_ptr = &lun_mask;
3660 /* Get "target-N-device-N-lun-mask" as a 256 bit lun_mask*/
3661 sprintf(propbuf, "scsi-qla%ld-tgt-%d-di-%d-lun-disabled",
3662 ha->instance, tgt, dev_no);
3664 rval = qla2x00_get_prop_xstr(ha, propbuf,
3665 (uint8_t *)&lun_mask, sizeof(lun_bit_mask_t));
3666 if (rval == sizeof(lun_bit_mask_t)) {
3667 memset(&fcport->lun_mask, 0, sizeof(lun_bit_mask_t));
3668 for (lun = 8 * sizeof(lun_bit_mask_t) - 1, bit = 0;
3669 lun >= 0; lun--, bit++) {
3670 if (EXT_IS_LUN_BIT_SET(mask_ptr, lun))
3671 EXT_SET_LUN_BIT((&fcport->lun_mask), bit);
3674 DEBUG3(printk("scsi(%ld): returning lun mask for fcport "
3675 "%02x%02x%02x%02x%02x%02x%02x%02x:\n",
3677 fcport->port_name[0], fcport->port_name[1],
3678 fcport->port_name[2], fcport->port_name[3],
3679 fcport->port_name[4], fcport->port_name[5],
3680 fcport->port_name[6], fcport->port_name[7]));
3681 DEBUG3(qla2x00_dump_buffer((uint8_t *)&fcport->lun_mask,
3682 sizeof(lun_bit_mask_t));)
3688 * qla2x00_bstr_to_hex
3689 * Convert hex byte string to number.
3692 * s = byte string pointer.
3693 * bp = byte pointer for number.
3694 * size = number of bytes.
3697 * Kernel/Interrupt context.
3700 qla2x00_bstr_to_hex(char *s, uint8_t *bp, int size)
3705 for (cnt = 0; *s != '\0' && cnt / 2 < size; cnt++) {
3706 if (*s >= 'A' && *s <= 'F') {
3707 n = (*s++ - 'A') + 10;
3708 } else if (*s >= 'a' && *s <= 'f') {
3709 n = (*s++ - 'a') + 10;
3710 } else if (*s >= '0' && *s <= '9') {
3723 /* fixme(dg) Need to swap data little endian */
3729 * qla2x00_get_prop_xstr
3730 * Get a string property value for the specified property name and
3731 * convert from the property string found in the configuration file,
3732 * which are ASCII characters representing nibbles, 2 characters represent
3733 * the hexdecimal value for a byte in the byte array.
3734 * The byte array is initialized to zero.
3735 * The resulting converted value is in big endian format (MSB at byte0).
3738 * ha = adapter state pointer.
3739 * propname = property name pointer.
3740 * propval = pointer where to store converted property val.
3741 * size = max or expected size of 'propval' array.
3744 * 0 = empty value string or invalid character in string
3745 * >0 = count of characters converted
3746 * -1 = property not found
3752 qla2x00_get_prop_xstr(scsi_qla_host_t *ha,
3753 char *propname, uint8_t *propval, int size)
3757 static char buf[LINESIZE];
3759 /* Get the requested property string */
3760 rval = qla2x00_find_propname(ha, propname, buf, ha->cmdline, size*2);
3761 DEBUG3(printk("%s(): Ret rval from find propname = %d\n",
3766 if (*propstr == '=')
3767 propstr++; /* ignore equal sign */
3769 if (rval == 0) { /* not found */
3773 rval = qla2x00_bstr_to_hex(propstr, (uint8_t *)propval, size);
3775 /* Invalid character in value string */
3776 qla_printk(KERN_INFO, ha,
3777 "%s(): %s Invalid hex string for property\n",
3780 qla_printk(KERN_INFO, ha,
3781 " Invalid string - %s\n",
3789 * qla2x00_find_propname
3790 * Get property in database.
3793 * ha = adapter structure pointer.
3794 * db = pointer to database
3795 * propstr = pointer to dest array for string
3796 * propname = name of property to search for.
3797 * siz = size of property
3801 * size = index of property
3807 qla2x00_find_propname(scsi_qla_host_t *ha,
3808 char *propname, char *propstr,
3813 /* find the specified string */
3815 /* find the property name */
3816 if ((cp = strstr(db,propname)) != NULL) {
3817 while ((*cp) && *cp != '=')
3820 strncpy(propstr, cp, siz+1);
3821 propstr[siz+1] = '\0';
3822 DEBUG(printk("qla2x00_find_propname: found "
3823 "property = {%s}\n",
3825 return (siz); /* match */
3835 * qla2x00_get_prop_16chars
3836 * Get an 8-byte property value for the specified property name by
3837 * converting from the property string found in the configuration file.
3838 * The resulting converted value is in big endian format (MSB at byte0).
3841 * ha = adapter state pointer.
3842 * propname = property name pointer.
3843 * propval = pointer to location for the converted property val.
3844 * db = pointer to database
3847 * 0 = value returned successfully.
3853 qla2x00_get_prop_16chars(scsi_qla_host_t *ha,
3854 char *propname, char *propval, char *db)
3863 uint8_t *retval = (uint8_t*)propval;
3864 uint8_t tmpval[8] = {0, 0, 0, 0, 0, 0, 0, 0};
3865 uint16_t max_byte_cnt = 8; /* 16 chars = 8 bytes */
3866 uint16_t max_strlen = 16;
3867 static char buf[LINESIZE];
3869 rval = qla2x00_find_propname(ha, propname, buf, db, max_strlen);
3872 if (*propstr == '=')
3873 propstr++; /* ignore equal sign */
3879 /* Convert string to numbers. */
3880 pchar = (uint8_t *)propstr;
3881 tmp_byte = (uint8_t *)tmpval;
3884 for (i = 0; i < max_strlen; i++) {
3886 * Check for invalid character, two at a time,
3887 * then convert them starting with first byte.
3890 if ((pchar[i] >= '0') && (pchar[i] <= '9')) {
3891 nval = pchar[i] - '0';
3892 } else if ((pchar[i] >= 'A') && (pchar[i] <= 'F')) {
3893 nval = pchar[i] - 'A' + 10;
3894 } else if ((pchar[i] >= 'a') && (pchar[i] <= 'f')) {
3895 nval = pchar[i] - 'a' + 10;
3897 /* invalid character */
3903 *tmp_byte = *tmp_byte | nval;
3906 *tmp_byte = *tmp_byte | nval << 4;
3911 /* Encountered invalid character. */
3915 /* Copy over the converted value. */
3922 *ret_byte++ = *tmp_byte++;
3925 /* big endian retval[0]; */
3930 * qla2x00_get_properties
3931 * Find all properties for the specified adapeter in
3935 * ha = adapter block pointer.
3936 * cmdline = pointer to command line string
3942 qla2x00_get_properties(scsi_qla_host_t *ha, char *cmdline)
3945 static char propbuf[LINESIZE];
3948 /* Adapter FC node names. */
3949 sprintf(propbuf, "scsi-qla%d-adapter-node", (int) ha->instance);
3950 rval = qla2x00_get_prop_16chars(ha, propbuf, fc_name, cmdline);
3951 if (rval == QLA_SUCCESS)
3952 memcpy(ha->init_cb->node_name, fc_name, WWN_SIZE);
3954 /* DG 04/07 check portname of adapter */
3955 sprintf(propbuf, "scsi-qla%d-adapter-port", (int)ha->instance);
3956 rval = qla2x00_get_prop_16chars(ha, propbuf, fc_name, cmdline);
3957 if (rval == QLA_SUCCESS &&
3958 memcmp(ha->init_cb->port_name, fc_name, WWN_SIZE)) {
3960 * Adapter port name is WWN, and cannot be changed.
3961 * Inform users of the mismatch, then just continue driver
3962 * loading using the original adapter port name in NVRAM.
3964 qla_printk(KERN_WARNING, ha,
3965 "Found mismatch in adapter port names.\n");
3966 qla_printk(KERN_INFO, ha,
3967 " qla%ld port name found in NVRAM -> "
3968 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
3970 ha->init_cb->port_name[0],
3971 ha->init_cb->port_name[1],
3972 ha->init_cb->port_name[2],
3973 ha->init_cb->port_name[3],
3974 ha->init_cb->port_name[4],
3975 ha->init_cb->port_name[5],
3976 ha->init_cb->port_name[6],
3977 ha->init_cb->port_name[7]);
3978 qla_printk(KERN_INFO, ha,
3979 " qla%ld port name found on command line -> "
3980 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
3982 fc_name[0], fc_name[1], fc_name[2], fc_name[3],
3983 fc_name[4], fc_name[5], fc_name[6], fc_name[7]);
3984 qla_printk(KERN_INFO, ha,
3985 " Using port name from NVRAM.\n");
3988 qla2x00_cfg_persistent_binding(ha);
3992 * qla2x00_cfg_persistent_binding
3993 * Get driver configuration file target persistent binding entries.
3996 * ha = adapter block pointer.
4002 qla2x00_cfg_persistent_binding(scsi_qla_host_t *ha)
4005 static char propbuf[LINESIZE];
4006 char *cmdline = ha->cmdline;
4010 uint8_t port_name[8];
4012 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
4013 if (ha->binding_type == BIND_BY_PORT_ID) {
4014 sprintf(propbuf, "scsi-qla%d-tgt-%d-di-0-pid",
4015 (int)ha->instance, tgt);
4016 rval = qla2x00_get_prop_xstr(ha,
4017 propbuf, portid, sizeof(portid));
4018 if (rval != sizeof(portid))
4021 memset(&d_id, 0, sizeof(port_id_t));
4022 d_id.r.d_id[0] = portid[2];
4023 d_id.r.d_id[1] = portid[1];
4024 d_id.r.d_id[2] = portid[0];
4026 sprintf(propbuf, "scsi-qla%d-tgt-%d-di-0-port",
4027 (int)ha->instance, tgt);
4028 rval = qla2x00_get_prop_16chars(ha,
4029 propbuf, port_name, cmdline);
4030 if (rval != QLA_SUCCESS)
4033 /* Fallthru since port_name already populated */
4037 * Create target context for device.
4039 if (ha->binding_type == BIND_BY_PORT_ID) {
4040 qla2x00_persistent_bind(ha, NULL, NULL, &d_id, tgt);
4042 qla2x00_persistent_bind(ha, NULL, port_name, NULL, tgt);
4048 * qla2x00_persistent_bind
4049 * Allocates target and fcport.
4052 * ha: adapter state pointer.
4053 * node_name: node name pointer.
4054 * port_name: port name pointer.
4055 * d_id: port ID pointer.
4056 * tgt: OS target number.
4059 * success = target queue pointer.
4066 qla2x00_persistent_bind(scsi_qla_host_t *ha, uint8_t *node_name,
4067 uint8_t *port_name, port_id_t *d_id, uint16_t tgt)
4073 * Check for duplicates.
4075 for (tgt2 = 0; tgt2 < MAX_TARGETS; tgt2++) {
4076 if ((tq = TGT_Q(ha, tgt2)) == NULL) {
4080 if (ha->binding_type == BIND_BY_PORT_ID) {
4081 if (tq->d_id.b24 != d_id->b24) {
4084 } else if (memcmp(tq->port_name, port_name, WWN_SIZE) != 0) {
4088 qla_printk(KERN_WARNING, ha,
4089 "Duplicate persistent bindings found for "
4090 "WWPN: %02x%02x%02x%02x%02x%02x%02x%02x.\n",
4091 port_name[0], port_name[1], port_name[2], port_name[3],
4092 port_name[4], port_name[5], port_name[6], port_name[7]);
4097 tq = qla2x00_tgt_alloc(ha, tgt);
4102 if (node_name != NULL) {
4103 memcpy(tq->node_name, node_name, WWN_SIZE);
4105 if (port_name != NULL) {
4106 memcpy(tq->port_name, port_name, WWN_SIZE);
4109 tq->d_id.b24 = d_id->b24;
4118 * Resets ISP and aborts all outstanding commands.
4121 * ha = adapter block pointer.
4127 qla2x00_abort_isp(scsi_qla_host_t *ha)
4129 unsigned long flags = 0;
4134 if (ha->flags.online) {
4135 ha->flags.online = 0;
4136 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
4137 qla2x00_stats.ispAbort++;
4138 ha->total_isp_aborts++; /* used by ioctl */
4139 ha->sns_retry_cnt = 0;
4141 qla_printk(KERN_INFO, ha,
4142 "Performing ISP error recovery - ha= %p.\n", ha);
4143 qla2x00_reset_chip(ha);
4145 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
4146 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
4147 atomic_set(&ha->loop_state, LOOP_DOWN);
4148 qla2x00_mark_all_devices_lost(ha);
4150 if (!atomic_read(&ha->loop_down_timer))
4151 atomic_set(&ha->loop_down_timer,
4155 spin_lock_irqsave(&ha->hardware_lock, flags);
4156 /* Requeue all commands in outstanding command list. */
4157 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
4158 sp = ha->outstanding_cmds[cnt];
4160 ha->outstanding_cmds[cnt] = NULL;
4163 sp->lun_queue->out_cnt--;
4166 * Set the cmd host_byte status depending on
4167 * whether the scsi_error_handler is
4170 if (sp->flags & SRB_TAPE) {
4171 sp->cmd->result = DID_NO_CONNECT << 16;
4173 if (ha->host->eh_active != EH_ACTIVE)
4181 sp->cmd->host_scribble = (unsigned char *)NULL;
4182 add_to_done_queue(ha, sp);
4185 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4187 qla2x00_nvram_config(ha);
4189 if (!qla2x00_restart_isp(ha)) {
4190 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
4192 if (!atomic_read(&ha->loop_down_timer)) {
4194 * Issue marker command only when we are going
4195 * to start the I/O .
4197 ha->marker_needed = 1;
4200 ha->flags.online = 1;
4202 /* Enable ISP interrupts. */
4203 qla2x00_enable_intrs(ha);
4205 /* v2.19.5b6 Return all commands */
4206 qla2x00_abort_queues(ha, 1);
4208 /* Restart queues that may have been stopped. */
4209 qla2x00_restart_queues(ha, 1);
4210 ha->isp_abort_cnt = 0;
4211 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
4212 } else { /* failed the ISP abort */
4213 ha->flags.online = 1;
4214 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
4215 if (ha->isp_abort_cnt == 0) {
4216 qla_printk(KERN_WARNING, ha,
4217 "ISP error recovery failed - "
4218 "board disabled\n");
4220 * The next call disables the board
4223 qla2x00_reset_adapter(ha);
4224 qla2x00_abort_queues(ha, 0);
4225 ha->flags.online = 0;
4226 clear_bit(ISP_ABORT_RETRY,
4229 } else { /* schedule another ISP abort */
4230 ha->isp_abort_cnt--;
4231 DEBUG(printk("qla%ld: ISP abort - "
4232 "retry remainning %d\n",
4233 ha->host_no, ha->isp_abort_cnt);)
4237 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
4238 DEBUG(printk("qla2x00(%ld): ISP error recovery "
4239 "- retrying (%d) more times\n",
4240 ha->host_no, ha->isp_abort_cnt);)
4241 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
4249 qla_printk(KERN_INFO, ha,
4250 "qla2x00_abort_isp: **** FAILED ****\n");
4252 DEBUG(printk(KERN_INFO
4253 "qla2x00_abort_isp(%ld): exiting.\n",
4261 * qla2x00_restart_isp
4262 * restarts the ISP after a reset
4265 * ha = adapter block pointer.
4271 qla2x00_restart_isp(scsi_qla_host_t *ha)
4274 device_reg_t __iomem *reg = ha->iobase;
4275 unsigned long flags = 0;
4278 /* If firmware needs to be loaded */
4279 if (qla2x00_isp_firmware(ha)) {
4280 ha->flags.online = 0;
4281 if (!(status = qla2x00_chip_diag(ha))) {
4282 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4283 status = qla2x00_setup_chip(ha);
4289 spin_lock_irqsave(&ha->hardware_lock, flags);
4291 /* Disable SRAM, Instruction RAM and GP RAM parity. */
4292 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
4293 RD_REG_WORD(®->hccr); /* PCI Posting. */
4295 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4297 status = qla2x00_setup_chip(ha);
4299 spin_lock_irqsave(&ha->hardware_lock, flags);
4301 /* Enable proper parity */
4304 WRT_REG_WORD(®->hccr,
4305 (HCCR_ENABLE_PARITY + 0x1));
4307 /* SRAM, Instruction RAM and GP RAM parity */
4308 WRT_REG_WORD(®->hccr,
4309 (HCCR_ENABLE_PARITY + 0x7));
4310 RD_REG_WORD(®->hccr); /* PCI Posting. */
4312 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4317 if (!status && !(status = qla2x00_init_rings(ha))) {
4318 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
4319 if (!(status = qla2x00_fw_ready(ha))) {
4320 DEBUG(printk("%s(): Start configure loop, "
4324 ha->flags.online = 1;
4325 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4328 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4329 qla2x00_configure_loop(ha);
4331 } while (!atomic_read(&ha->loop_down_timer) &&
4332 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
4334 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
4337 /* if no cable then assume it's good */
4338 if ((ha->device_flags & DFLG_NO_CABLE))
4341 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
4349 * qla2x00_reset_adapter
4353 * ha = adapter block pointer.
4356 qla2x00_reset_adapter(scsi_qla_host_t *ha)
4358 unsigned long flags = 0;
4359 device_reg_t __iomem *reg = ha->iobase;
4361 ha->flags.online = 0;
4362 qla2x00_disable_intrs(ha);
4364 /* Reset RISC processor. */
4365 spin_lock_irqsave(&ha->hardware_lock, flags);
4366 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
4367 RD_REG_WORD(®->hccr); /* PCI Posting. */
4368 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
4369 RD_REG_WORD(®->hccr); /* PCI Posting. */
4370 spin_unlock_irqrestore(&ha->hardware_lock, flags);