2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2005 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>
22 #include <linux/vmalloc.h>
23 #include <linux/firmware.h>
24 #include <scsi/scsi_transport_fc.h>
26 #include "qla_devtbl.h"
28 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
29 #ifndef EXT_IS_LUN_BIT_SET
30 #define EXT_IS_LUN_BIT_SET(P,L) \
31 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
32 #define EXT_SET_LUN_BIT(P,L) \
33 ((P)->mask[L/8] |= (0x80 >> (L%8)))
37 * QLogic ISP2x00 Hardware Support Function Prototypes.
39 static int qla2x00_isp_firmware(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_configure_loop(scsi_qla_host_t *);
47 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
48 static void qla2x00_update_fcport(scsi_qla_host_t *, fc_port_t *);
49 static int qla2x00_configure_fabric(scsi_qla_host_t *);
50 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
51 static int qla2x00_device_resync(scsi_qla_host_t *);
52 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
55 static int qla2x00_restart_isp(scsi_qla_host_t *);
57 /****************************************************************************/
58 /* QLogic ISP2x00 Hardware Support Functions. */
59 /****************************************************************************/
62 * qla2x00_initialize_adapter
66 * ha = adapter block pointer.
72 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
75 uint8_t restart_risc = 0;
79 /* Clear adapter flags. */
81 ha->flags.reset_active = 0;
82 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
83 atomic_set(&ha->loop_state, LOOP_DOWN);
86 ha->flags.management_server_logged_in = 0;
87 ha->marker_needed = 0;
89 ha->isp_abort_cnt = 0;
90 ha->beacon_blink_led = 0;
91 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
93 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
94 rval = ha->isp_ops.pci_config(ha);
96 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
101 ha->isp_ops.reset_chip(ha);
103 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
105 ha->isp_ops.nvram_config(ha);
107 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
111 * Try to configure the loop.
116 /* If firmware needs to be loaded */
117 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
118 if ((rval = ha->isp_ops.chip_diag(ha)) == QLA_SUCCESS) {
119 rval = qla2x00_setup_chip(ha);
123 if (rval == QLA_SUCCESS &&
124 (rval = qla2x00_init_rings(ha)) == QLA_SUCCESS) {
125 check_fw_ready_again:
127 * Wait for a successful LIP up to a maximum
128 * of (in seconds): RISC login timeout value,
129 * RISC retry count value, and port down retry
130 * value OR a minimum of 4 seconds OR If no
131 * cable, only 5 seconds.
133 rval = qla2x00_fw_ready(ha);
134 if (rval == QLA_SUCCESS) {
135 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
137 /* Issue a marker after FW becomes ready. */
138 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
141 * Wait at most MAX_TARGET RSCNs for a stable
146 clear_bit(LOOP_RESYNC_NEEDED,
148 rval = qla2x00_configure_loop(ha);
150 if (test_and_clear_bit(ISP_ABORT_NEEDED,
157 * If loop state change while we were
158 * discoverying devices then wait for
162 if (atomic_read(&ha->loop_state) ==
163 LOOP_DOWN && retry--) {
164 goto check_fw_ready_again;
167 } while (!atomic_read(&ha->loop_down_timer) &&
170 (test_bit(LOOP_RESYNC_NEEDED,
174 rval = QLA_FUNCTION_FAILED;
175 } else if (ha->device_flags & DFLG_NO_CABLE)
176 /* If no cable, then all is good. */
179 } while (restart_risc && retry--);
181 if (rval == QLA_SUCCESS) {
182 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
183 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
184 ha->marker_needed = 0;
186 ha->flags.online = 1;
188 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
195 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
198 * Returns 0 on success.
201 qla2100_pci_config(scsi_qla_host_t *ha)
205 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
207 pci_set_master(ha->pdev);
209 if (pci_set_mwi(ha->pdev))
210 mwi = PCI_COMMAND_INVALIDATE;
211 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
213 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
214 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
215 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
217 /* Reset expansion ROM address decode enable */
218 pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w);
219 w &= ~PCI_ROM_ADDRESS_ENABLE;
220 pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
222 /* Get PCI bus information. */
223 spin_lock_irqsave(&ha->hardware_lock, flags);
224 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
225 spin_unlock_irqrestore(&ha->hardware_lock, flags);
231 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
234 * Returns 0 on success.
237 qla2300_pci_config(scsi_qla_host_t *ha)
240 unsigned long flags = 0;
242 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
244 pci_set_master(ha->pdev);
246 if (pci_set_mwi(ha->pdev))
247 mwi = PCI_COMMAND_INVALIDATE;
248 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
250 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
251 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
253 if (IS_QLA2322(ha) || IS_QLA6322(ha))
254 w &= ~PCI_COMMAND_INTX_DISABLE;
257 * If this is a 2300 card and not 2312, reset the
258 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
259 * the 2310 also reports itself as a 2300 so we need to get the
260 * fb revision level -- a 6 indicates it really is a 2300 and
263 if (IS_QLA2300(ha)) {
264 spin_lock_irqsave(&ha->hardware_lock, flags);
267 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
268 for (cnt = 0; cnt < 30000; cnt++) {
269 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
275 /* Select FPM registers. */
276 WRT_REG_WORD(®->ctrl_status, 0x20);
277 RD_REG_WORD(®->ctrl_status);
279 /* Get the fb rev level */
280 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
282 if (ha->fb_rev == FPM_2300)
283 w &= ~PCI_COMMAND_INVALIDATE;
285 /* Deselect FPM registers. */
286 WRT_REG_WORD(®->ctrl_status, 0x0);
287 RD_REG_WORD(®->ctrl_status);
289 /* Release RISC module. */
290 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
291 for (cnt = 0; cnt < 30000; cnt++) {
292 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
298 spin_unlock_irqrestore(&ha->hardware_lock, flags);
300 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
302 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
304 /* Reset expansion ROM address decode enable */
305 pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w);
306 w &= ~PCI_ROM_ADDRESS_ENABLE;
307 pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
309 /* Get PCI bus information. */
310 spin_lock_irqsave(&ha->hardware_lock, flags);
311 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
312 spin_unlock_irqrestore(&ha->hardware_lock, flags);
318 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
321 * Returns 0 on success.
324 qla24xx_pci_config(scsi_qla_host_t *ha)
327 unsigned long flags = 0;
328 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
329 int pcix_cmd_reg, pcie_dctl_reg;
331 pci_set_master(ha->pdev);
333 if (pci_set_mwi(ha->pdev))
334 mwi = PCI_COMMAND_INVALIDATE;
335 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
337 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
338 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
339 w &= ~PCI_COMMAND_INTX_DISABLE;
340 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
342 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
344 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
345 pcix_cmd_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX);
349 pcix_cmd_reg += PCI_X_CMD;
350 pci_read_config_word(ha->pdev, pcix_cmd_reg, &pcix_cmd);
351 pcix_cmd &= ~PCI_X_CMD_MAX_READ;
353 pci_write_config_word(ha->pdev, pcix_cmd_reg, pcix_cmd);
356 /* PCIe -- adjust Maximum Read Request Size (2048). */
357 pcie_dctl_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
361 pcie_dctl_reg += PCI_EXP_DEVCTL;
362 pci_read_config_word(ha->pdev, pcie_dctl_reg, &pcie_dctl);
363 pcie_dctl &= ~PCI_EXP_DEVCTL_READRQ;
365 pci_write_config_word(ha->pdev, pcie_dctl_reg, pcie_dctl);
368 /* Reset expansion ROM address decode enable */
369 pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w);
370 w &= ~PCI_ROM_ADDRESS_ENABLE;
371 pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
373 /* Get PCI bus information. */
374 spin_lock_irqsave(&ha->hardware_lock, flags);
375 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
376 spin_unlock_irqrestore(&ha->hardware_lock, flags);
382 * qla2x00_isp_firmware() - Choose firmware image.
385 * Returns 0 on success.
388 qla2x00_isp_firmware(scsi_qla_host_t *ha)
392 /* Assume loading risc code */
393 rval = QLA_FUNCTION_FAILED;
395 if (ha->flags.disable_risc_code_load) {
396 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
398 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
400 /* Verify checksum of loaded RISC code. */
401 rval = qla2x00_verify_checksum(ha,
402 IS_QLA24XX(ha) || IS_QLA25XX(ha) ? RISC_SADDRESS :
403 *ha->brd_info->fw_info[0].fwstart);
407 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
415 * qla2x00_reset_chip() - Reset ISP chip.
418 * Returns 0 on success.
421 qla2x00_reset_chip(scsi_qla_host_t *ha)
423 unsigned long flags = 0;
424 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
426 unsigned long mbx_flags = 0;
429 ha->isp_ops.disable_intrs(ha);
431 spin_lock_irqsave(&ha->hardware_lock, flags);
433 /* Turn off master enable */
435 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
436 cmd &= ~PCI_COMMAND_MASTER;
437 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
439 if (!IS_QLA2100(ha)) {
441 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
442 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
443 for (cnt = 0; cnt < 30000; cnt++) {
444 if ((RD_REG_WORD(®->hccr) &
445 HCCR_RISC_PAUSE) != 0)
450 RD_REG_WORD(®->hccr); /* PCI Posting. */
454 /* Select FPM registers. */
455 WRT_REG_WORD(®->ctrl_status, 0x20);
456 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
458 /* FPM Soft Reset. */
459 WRT_REG_WORD(®->fpm_diag_config, 0x100);
460 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
462 /* Toggle Fpm Reset. */
463 if (!IS_QLA2200(ha)) {
464 WRT_REG_WORD(®->fpm_diag_config, 0x0);
465 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
468 /* Select frame buffer registers. */
469 WRT_REG_WORD(®->ctrl_status, 0x10);
470 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
472 /* Reset frame buffer FIFOs. */
473 if (IS_QLA2200(ha)) {
474 WRT_FB_CMD_REG(ha, reg, 0xa000);
475 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
477 WRT_FB_CMD_REG(ha, reg, 0x00fc);
479 /* Read back fb_cmd until zero or 3 seconds max */
480 for (cnt = 0; cnt < 3000; cnt++) {
481 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
487 /* Select RISC module registers. */
488 WRT_REG_WORD(®->ctrl_status, 0);
489 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
491 /* Reset RISC processor. */
492 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
493 RD_REG_WORD(®->hccr); /* PCI Posting. */
495 /* Release RISC processor. */
496 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
497 RD_REG_WORD(®->hccr); /* PCI Posting. */
500 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
501 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
503 /* Reset ISP chip. */
504 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
506 /* Wait for RISC to recover from reset. */
507 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
509 * It is necessary to for a delay here since the card doesn't
510 * respond to PCI reads during a reset. On some architectures
511 * this will result in an MCA.
514 for (cnt = 30000; cnt; cnt--) {
515 if ((RD_REG_WORD(®->ctrl_status) &
516 CSR_ISP_SOFT_RESET) == 0)
523 /* Reset RISC processor. */
524 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
526 WRT_REG_WORD(®->semaphore, 0);
528 /* Release RISC processor. */
529 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
530 RD_REG_WORD(®->hccr); /* PCI Posting. */
532 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
533 for (cnt = 0; cnt < 30000; cnt++) {
534 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
535 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
537 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) {
538 if (!(test_bit(ABORT_ISP_ACTIVE,
540 spin_unlock_irqrestore(
541 &ha->mbx_reg_lock, mbx_flags);
545 if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
546 spin_unlock_irqrestore(&ha->mbx_reg_lock,
554 /* Turn on master enable */
555 cmd |= PCI_COMMAND_MASTER;
556 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
558 /* Disable RISC pause on FPM parity error. */
559 if (!IS_QLA2100(ha)) {
560 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
561 RD_REG_WORD(®->hccr); /* PCI Posting. */
564 spin_unlock_irqrestore(&ha->hardware_lock, flags);
568 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
571 * Returns 0 on success.
574 qla24xx_reset_risc(scsi_qla_host_t *ha)
576 unsigned long flags = 0;
577 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
580 spin_lock_irqsave(&ha->hardware_lock, flags);
583 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
584 for (cnt = 0; cnt < 30000; cnt++) {
585 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
591 WRT_REG_DWORD(®->ctrl_status,
592 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
593 RD_REG_DWORD(®->ctrl_status);
595 /* Wait for firmware to complete NVRAM accesses. */
597 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
598 for (cnt = 10000 ; cnt && d2; cnt--) {
600 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
605 d2 = RD_REG_DWORD(®->ctrl_status);
606 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
608 d2 = RD_REG_DWORD(®->ctrl_status);
612 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
613 RD_REG_DWORD(®->hccr);
615 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
616 RD_REG_DWORD(®->hccr);
618 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
619 RD_REG_DWORD(®->hccr);
621 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
622 for (cnt = 6000000 ; cnt && d2; cnt--) {
624 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
628 spin_unlock_irqrestore(&ha->hardware_lock, flags);
632 * qla24xx_reset_chip() - Reset ISP24xx chip.
635 * Returns 0 on success.
638 qla24xx_reset_chip(scsi_qla_host_t *ha)
640 ha->isp_ops.disable_intrs(ha);
642 /* Perform RISC reset. */
643 qla24xx_reset_risc(ha);
647 * qla2x00_chip_diag() - Test chip for proper operation.
650 * Returns 0 on success.
653 qla2x00_chip_diag(scsi_qla_host_t *ha)
656 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
657 unsigned long flags = 0;
662 /* Assume a failed state */
663 rval = QLA_FUNCTION_FAILED;
665 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
666 ha->host_no, (u_long)®->flash_address));
668 spin_lock_irqsave(&ha->hardware_lock, flags);
670 /* Reset ISP chip. */
671 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
674 * We need to have a delay here since the card will not respond while
675 * in reset causing an MCA on some architectures.
678 data = qla2x00_debounce_register(®->ctrl_status);
679 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
681 data = RD_REG_WORD(®->ctrl_status);
686 goto chip_diag_failed;
688 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
691 /* Reset RISC processor. */
692 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
693 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
695 /* Workaround for QLA2312 PCI parity error */
696 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
697 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
698 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
700 data = RD_MAILBOX_REG(ha, reg, 0);
707 goto chip_diag_failed;
709 /* Check product ID of chip */
710 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
712 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
713 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
714 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
715 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
716 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
717 mb[3] != PROD_ID_3) {
718 qla_printk(KERN_WARNING, ha,
719 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
721 goto chip_diag_failed;
723 ha->product_id[0] = mb[1];
724 ha->product_id[1] = mb[2];
725 ha->product_id[2] = mb[3];
726 ha->product_id[3] = mb[4];
728 /* Adjust fw RISC transfer size */
729 if (ha->request_q_length > 1024)
730 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
732 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
733 ha->request_q_length;
735 if (IS_QLA2200(ha) &&
736 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
737 /* Limit firmware transfer size with a 2200A */
738 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
741 ha->fw_transfer_size = 128;
744 /* Wrap Incoming Mailboxes Test. */
745 spin_unlock_irqrestore(&ha->hardware_lock, flags);
747 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
748 rval = qla2x00_mbx_reg_test(ha);
750 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
752 qla_printk(KERN_WARNING, ha,
753 "Failed mailbox send register test\n");
756 /* Flag a successful rval */
759 spin_lock_irqsave(&ha->hardware_lock, flags);
763 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
764 "****\n", ha->host_no));
766 spin_unlock_irqrestore(&ha->hardware_lock, flags);
772 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
775 * Returns 0 on success.
778 qla24xx_chip_diag(scsi_qla_host_t *ha)
782 /* Perform RISC reset. */
783 qla24xx_reset_risc(ha);
785 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
787 rval = qla2x00_mbx_reg_test(ha);
789 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
791 qla_printk(KERN_WARNING, ha,
792 "Failed mailbox send register test\n");
794 /* Flag a successful rval */
802 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
805 ha->fw_dump24_len = sizeof(struct qla24xx_fw_dump);
806 ha->fw_dump24_len += (ha->fw_memory_size - 0x100000) * sizeof(uint32_t);
807 ha->fw_dump24 = vmalloc(ha->fw_dump24_len);
809 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware "
810 "dump...\n", ha->fw_dump24_len / 1024);
812 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
813 "firmware dump!!!\n", ha->fw_dump24_len / 1024);
817 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
820 * Returns 0 on success.
823 qla2x00_resize_request_q(scsi_qla_host_t *ha)
826 uint16_t fw_iocb_cnt = 0;
827 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
828 dma_addr_t request_dma;
829 request_t *request_ring;
831 /* Valid only on recent ISPs. */
832 if (IS_QLA2100(ha) || IS_QLA2200(ha))
835 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
836 qla2x00_alloc_fw_dump(ha);
838 /* Retrieve IOCB counts available to the firmware. */
839 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
842 /* No point in continuing if current settings are sufficient. */
843 if (fw_iocb_cnt < 1024)
845 if (ha->request_q_length >= request_q_length)
848 /* Attempt to claim larger area for request queue. */
849 request_ring = dma_alloc_coherent(&ha->pdev->dev,
850 (request_q_length + 1) * sizeof(request_t), &request_dma,
852 if (request_ring == NULL)
855 /* Resize successful, report extensions. */
856 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
857 (ha->fw_memory_size + 1) / 1024);
858 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
859 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
861 /* Clear old allocations. */
862 dma_free_coherent(&ha->pdev->dev,
863 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
866 /* Begin using larger queue. */
867 ha->request_q_length = request_q_length;
868 ha->request_ring = request_ring;
869 ha->request_dma = request_dma;
873 * qla2x00_setup_chip() - Load and start RISC firmware.
876 * Returns 0 on success.
879 qla2x00_setup_chip(scsi_qla_host_t *ha)
882 uint32_t srisc_address = 0;
884 /* Load firmware sequences */
885 rval = ha->isp_ops.load_risc(ha, &srisc_address);
886 if (rval == QLA_SUCCESS) {
887 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
888 "code.\n", ha->host_no));
890 rval = qla2x00_verify_checksum(ha, srisc_address);
891 if (rval == QLA_SUCCESS) {
892 /* Start firmware execution. */
893 DEBUG(printk("scsi(%ld): Checksum OK, start "
894 "firmware.\n", ha->host_no));
896 rval = qla2x00_execute_fw(ha, srisc_address);
897 /* Retrieve firmware information. */
898 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
899 qla2x00_get_fw_version(ha,
900 &ha->fw_major_version,
901 &ha->fw_minor_version,
902 &ha->fw_subminor_version,
903 &ha->fw_attributes, &ha->fw_memory_size);
904 qla2x00_resize_request_q(ha);
907 DEBUG2(printk(KERN_INFO
908 "scsi(%ld): ISP Firmware failed checksum.\n",
914 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
922 * qla2x00_init_response_q_entries() - Initializes response queue entries.
925 * Beginning of request ring has initialization control block already built
926 * by nvram config routine.
928 * Returns 0 on success.
931 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
936 pkt = ha->response_ring_ptr;
937 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
938 pkt->signature = RESPONSE_PROCESSED;
945 * qla2x00_update_fw_options() - Read and process firmware options.
948 * Returns 0 on success.
951 qla2x00_update_fw_options(scsi_qla_host_t *ha)
953 uint16_t swing, emphasis, tx_sens, rx_sens;
955 memset(ha->fw_options, 0, sizeof(ha->fw_options));
956 qla2x00_get_fw_options(ha, ha->fw_options);
958 if (IS_QLA2100(ha) || IS_QLA2200(ha))
961 /* Serial Link options. */
962 DEBUG3(printk("scsi(%ld): Serial link options:\n",
964 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
965 sizeof(ha->fw_seriallink_options)));
967 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
968 if (ha->fw_seriallink_options[3] & BIT_2) {
969 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
972 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
973 emphasis = (ha->fw_seriallink_options[2] &
974 (BIT_4 | BIT_3)) >> 3;
975 tx_sens = ha->fw_seriallink_options[0] &
976 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
977 rx_sens = (ha->fw_seriallink_options[0] &
978 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
979 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
980 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
983 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
984 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
985 ha->fw_options[10] |= BIT_5 |
986 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
987 (tx_sens & (BIT_1 | BIT_0));
990 swing = (ha->fw_seriallink_options[2] &
991 (BIT_7 | BIT_6 | BIT_5)) >> 5;
992 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
993 tx_sens = ha->fw_seriallink_options[1] &
994 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
995 rx_sens = (ha->fw_seriallink_options[1] &
996 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
997 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
998 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1001 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1002 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1003 ha->fw_options[11] |= BIT_5 |
1004 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1005 (tx_sens & (BIT_1 | BIT_0));
1009 /* Return command IOCBs without waiting for an ABTS to complete. */
1010 ha->fw_options[3] |= BIT_13;
1013 if (ha->flags.enable_led_scheme)
1014 ha->fw_options[2] |= BIT_12;
1016 /* Update firmware options. */
1017 qla2x00_set_fw_options(ha, ha->fw_options);
1021 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1025 /* Update Serial Link options. */
1026 if ((ha->fw_seriallink_options24[0] & BIT_0) == 0)
1029 rval = qla2x00_set_serdes_params(ha, ha->fw_seriallink_options24[1],
1030 ha->fw_seriallink_options24[2], ha->fw_seriallink_options24[3]);
1031 if (rval != QLA_SUCCESS) {
1032 qla_printk(KERN_WARNING, ha,
1033 "Unable to update Serial Link options (%x).\n", rval);
1038 qla2x00_config_rings(struct scsi_qla_host *ha)
1040 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1042 /* Setup ring parameters in initialization control block. */
1043 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1044 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1045 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1046 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1047 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1048 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1049 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1050 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1052 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1053 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1054 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1055 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1056 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1060 qla24xx_config_rings(struct scsi_qla_host *ha)
1062 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1063 struct init_cb_24xx *icb;
1065 /* Setup ring parameters in initialization control block. */
1066 icb = (struct init_cb_24xx *)ha->init_cb;
1067 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1068 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1069 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1070 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1071 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1072 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1073 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1074 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1076 WRT_REG_DWORD(®->req_q_in, 0);
1077 WRT_REG_DWORD(®->req_q_out, 0);
1078 WRT_REG_DWORD(®->rsp_q_in, 0);
1079 WRT_REG_DWORD(®->rsp_q_out, 0);
1080 RD_REG_DWORD(®->rsp_q_out);
1084 * qla2x00_init_rings() - Initializes firmware.
1087 * Beginning of request ring has initialization control block already built
1088 * by nvram config routine.
1090 * Returns 0 on success.
1093 qla2x00_init_rings(scsi_qla_host_t *ha)
1096 unsigned long flags = 0;
1099 spin_lock_irqsave(&ha->hardware_lock, flags);
1101 /* Clear outstanding commands array. */
1102 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1103 ha->outstanding_cmds[cnt] = NULL;
1105 ha->current_outstanding_cmd = 0;
1107 /* Clear RSCN queue. */
1108 ha->rscn_in_ptr = 0;
1109 ha->rscn_out_ptr = 0;
1111 /* Initialize firmware. */
1112 ha->request_ring_ptr = ha->request_ring;
1113 ha->req_ring_index = 0;
1114 ha->req_q_cnt = ha->request_q_length;
1115 ha->response_ring_ptr = ha->response_ring;
1116 ha->rsp_ring_index = 0;
1118 /* Initialize response queue entries */
1119 qla2x00_init_response_q_entries(ha);
1121 ha->isp_ops.config_rings(ha);
1123 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1125 /* Update any ISP specific firmware options before initialization. */
1126 ha->isp_ops.update_fw_options(ha);
1128 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1129 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1131 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1134 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1142 * qla2x00_fw_ready() - Waits for firmware ready.
1145 * Returns 0 on success.
1148 qla2x00_fw_ready(scsi_qla_host_t *ha)
1151 unsigned long wtime, mtime;
1152 uint16_t min_wait; /* Minimum wait time if loop is down */
1153 uint16_t wait_time; /* Wait time if loop is coming ready */
1158 /* 20 seconds for loop down. */
1162 * Firmware should take at most one RATOV to login, plus 5 seconds for
1163 * our own processing.
1165 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1166 wait_time = min_wait;
1169 /* Min wait time if loop down */
1170 mtime = jiffies + (min_wait * HZ);
1172 /* wait time before firmware ready */
1173 wtime = jiffies + (wait_time * HZ);
1175 /* Wait for ISP to finish LIP */
1176 if (!ha->flags.init_done)
1177 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1179 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1183 rval = qla2x00_get_firmware_state(ha, &fw_state);
1184 if (rval == QLA_SUCCESS) {
1185 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1186 ha->device_flags &= ~DFLG_NO_CABLE;
1188 if (fw_state == FSTATE_READY) {
1189 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1192 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1193 &ha->login_timeout, &ha->r_a_tov);
1199 rval = QLA_FUNCTION_FAILED;
1201 if (atomic_read(&ha->loop_down_timer) &&
1202 (fw_state >= FSTATE_LOSS_OF_SYNC ||
1203 fw_state == FSTATE_WAIT_AL_PA)) {
1204 /* Loop down. Timeout on min_wait for states
1205 * other than Wait for Login.
1207 if (time_after_eq(jiffies, mtime)) {
1208 qla_printk(KERN_INFO, ha,
1209 "Cable is unplugged...\n");
1211 ha->device_flags |= DFLG_NO_CABLE;
1216 /* Mailbox cmd failed. Timeout on min_wait. */
1217 if (time_after_eq(jiffies, mtime))
1221 if (time_after_eq(jiffies, wtime))
1224 /* Delay for a while */
1227 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1228 ha->host_no, fw_state, jiffies));
1231 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1232 ha->host_no, fw_state, jiffies));
1235 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1243 * qla2x00_configure_hba
1244 * Setup adapter context.
1247 * ha = adapter state pointer.
1256 qla2x00_configure_hba(scsi_qla_host_t *ha)
1264 char connect_type[22];
1266 /* Get host addresses. */
1267 rval = qla2x00_get_adapter_id(ha,
1268 &loop_id, &al_pa, &area, &domain, &topo);
1269 if (rval != QLA_SUCCESS) {
1270 qla_printk(KERN_WARNING, ha,
1271 "ERROR -- Unable to get host loop ID.\n");
1272 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1277 qla_printk(KERN_INFO, ha,
1278 "Cannot get topology - retrying.\n");
1279 return (QLA_FUNCTION_FAILED);
1282 ha->loop_id = loop_id;
1285 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1286 ha->operating_mode = LOOP;
1290 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1292 ha->current_topology = ISP_CFG_NL;
1293 strcpy(connect_type, "(Loop)");
1297 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1299 ha->current_topology = ISP_CFG_FL;
1300 strcpy(connect_type, "(FL_Port)");
1304 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1306 ha->operating_mode = P2P;
1307 ha->current_topology = ISP_CFG_N;
1308 strcpy(connect_type, "(N_Port-to-N_Port)");
1312 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1314 ha->operating_mode = P2P;
1315 ha->current_topology = ISP_CFG_F;
1316 strcpy(connect_type, "(F_Port)");
1320 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1322 ha->host_no, topo));
1323 ha->current_topology = ISP_CFG_NL;
1324 strcpy(connect_type, "(Loop)");
1328 /* Save Host port and loop ID. */
1329 /* byte order - Big Endian */
1330 ha->d_id.b.domain = domain;
1331 ha->d_id.b.area = area;
1332 ha->d_id.b.al_pa = al_pa;
1334 if (!ha->flags.init_done)
1335 qla_printk(KERN_INFO, ha,
1336 "Topology - %s, Host Loop address 0x%x\n",
1337 connect_type, ha->loop_id);
1340 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1342 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1349 * NVRAM configuration for ISP 2xxx
1352 * ha = adapter block pointer.
1355 * initialization control block in response_ring
1356 * host adapters parameters in host adapter block
1362 qla2x00_nvram_config(scsi_qla_host_t *ha)
1367 uint8_t *dptr1, *dptr2;
1368 init_cb_t *icb = ha->init_cb;
1369 nvram_t *nv = (nvram_t *)ha->request_ring;
1370 uint8_t *ptr = (uint8_t *)ha->request_ring;
1371 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1376 /* Determine NVRAM starting address. */
1377 ha->nvram_size = sizeof(nvram_t);
1379 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1380 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1381 ha->nvram_base = 0x80;
1383 /* Get NVRAM data and calculate checksum. */
1384 ha->isp_ops.read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1385 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1388 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1389 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1392 /* Bad NVRAM data, set defaults parameters. */
1393 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1394 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1395 /* Reset NVRAM data. */
1396 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1397 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1399 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1400 "invalid -- WWPN) defaults.\n");
1403 * Set default initialization control block.
1405 memset(nv, 0, ha->nvram_size);
1406 nv->parameter_block_version = ICB_VERSION;
1408 if (IS_QLA23XX(ha)) {
1409 nv->firmware_options[0] = BIT_2 | BIT_1;
1410 nv->firmware_options[1] = BIT_7 | BIT_5;
1411 nv->add_firmware_options[0] = BIT_5;
1412 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1413 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1414 nv->special_options[1] = BIT_7;
1415 } else if (IS_QLA2200(ha)) {
1416 nv->firmware_options[0] = BIT_2 | BIT_1;
1417 nv->firmware_options[1] = BIT_7 | BIT_5;
1418 nv->add_firmware_options[0] = BIT_5;
1419 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1420 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1421 } else if (IS_QLA2100(ha)) {
1422 nv->firmware_options[0] = BIT_3 | BIT_1;
1423 nv->firmware_options[1] = BIT_5;
1424 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1427 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1428 nv->execution_throttle = __constant_cpu_to_le16(16);
1429 nv->retry_count = 8;
1430 nv->retry_delay = 1;
1432 nv->port_name[0] = 33;
1433 nv->port_name[3] = 224;
1434 nv->port_name[4] = 139;
1436 nv->login_timeout = 4;
1439 * Set default host adapter parameters
1441 nv->host_p[1] = BIT_2;
1442 nv->reset_delay = 5;
1443 nv->port_down_retry_count = 8;
1444 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1445 nv->link_down_timeout = 60;
1450 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1452 * The SN2 does not provide BIOS emulation which means you can't change
1453 * potentially bogus BIOS settings. Force the use of default settings
1454 * for link rate and frame size. Hope that the rest of the settings
1457 if (ia64_platform_is("sn2")) {
1458 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1460 nv->special_options[1] = BIT_7;
1464 /* Reset Initialization control block */
1465 memset(icb, 0, ha->init_cb_size);
1468 * Setup driver NVRAM options.
1470 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1471 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1472 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1473 nv->firmware_options[1] &= ~BIT_4;
1475 if (IS_QLA23XX(ha)) {
1476 nv->firmware_options[0] |= BIT_2;
1477 nv->firmware_options[0] &= ~BIT_3;
1478 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1480 if (IS_QLA2300(ha)) {
1481 if (ha->fb_rev == FPM_2310) {
1482 strcpy(ha->model_number, "QLA2310");
1484 strcpy(ha->model_number, "QLA2300");
1488 memcmp(nv->model_number, BINZERO,
1489 sizeof(nv->model_number)) != 0) {
1492 strncpy(ha->model_number, nv->model_number,
1493 sizeof(nv->model_number));
1494 st = en = ha->model_number;
1495 en += sizeof(nv->model_number) - 1;
1497 if (*en != 0x20 && *en != 0x00)
1504 index = (ha->pdev->subsystem_device & 0xff);
1505 if (index < QLA_MODEL_NAMES) {
1506 strcpy(ha->model_number,
1507 qla2x00_model_name[index]);
1509 qla2x00_model_desc[index];
1511 strcpy(ha->model_number, "QLA23xx");
1515 } else if (IS_QLA2200(ha)) {
1516 nv->firmware_options[0] |= BIT_2;
1518 * 'Point-to-point preferred, else loop' is not a safe
1519 * connection mode setting.
1521 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1523 /* Force 'loop preferred, else point-to-point'. */
1524 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1525 nv->add_firmware_options[0] |= BIT_5;
1527 strcpy(ha->model_number, "QLA22xx");
1528 } else /*if (IS_QLA2100(ha))*/ {
1529 strcpy(ha->model_number, "QLA2100");
1533 * Copy over NVRAM RISC parameter block to initialization control block.
1535 dptr1 = (uint8_t *)icb;
1536 dptr2 = (uint8_t *)&nv->parameter_block_version;
1537 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1539 *dptr1++ = *dptr2++;
1541 /* Copy 2nd half. */
1542 dptr1 = (uint8_t *)icb->add_firmware_options;
1543 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1545 *dptr1++ = *dptr2++;
1547 /* Prepare nodename */
1548 if ((icb->firmware_options[1] & BIT_6) == 0) {
1550 * Firmware will apply the following mask if the nodename was
1553 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1554 icb->node_name[0] &= 0xF0;
1558 * Set host adapter parameters.
1560 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1561 /* Always load RISC code on non ISP2[12]00 chips. */
1562 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1563 ha->flags.disable_risc_code_load = 0;
1564 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1565 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1566 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1567 ha->flags.enable_led_scheme = ((nv->efi_parameters & BIT_3) ? 1 : 0);
1569 ha->operating_mode =
1570 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1572 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1573 sizeof(ha->fw_seriallink_options));
1575 /* save HBA serial number */
1576 ha->serial0 = icb->port_name[5];
1577 ha->serial1 = icb->port_name[6];
1578 ha->serial2 = icb->port_name[7];
1579 ha->node_name = icb->node_name;
1580 ha->port_name = icb->port_name;
1582 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1584 ha->retry_count = nv->retry_count;
1586 /* Set minimum login_timeout to 4 seconds. */
1587 if (nv->login_timeout < ql2xlogintimeout)
1588 nv->login_timeout = ql2xlogintimeout;
1589 if (nv->login_timeout < 4)
1590 nv->login_timeout = 4;
1591 ha->login_timeout = nv->login_timeout;
1592 icb->login_timeout = nv->login_timeout;
1594 /* Set minimum RATOV to 200 tenths of a second. */
1597 ha->loop_reset_delay = nv->reset_delay;
1599 /* Link Down Timeout = 0:
1601 * When Port Down timer expires we will start returning
1602 * I/O's to OS with "DID_NO_CONNECT".
1604 * Link Down Timeout != 0:
1606 * The driver waits for the link to come up after link down
1607 * before returning I/Os to OS with "DID_NO_CONNECT".
1609 if (nv->link_down_timeout == 0) {
1610 ha->loop_down_abort_time =
1611 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1613 ha->link_down_timeout = nv->link_down_timeout;
1614 ha->loop_down_abort_time =
1615 (LOOP_DOWN_TIME - ha->link_down_timeout);
1619 * Need enough time to try and get the port back.
1621 ha->port_down_retry_count = nv->port_down_retry_count;
1622 if (qlport_down_retry)
1623 ha->port_down_retry_count = qlport_down_retry;
1624 /* Set login_retry_count */
1625 ha->login_retry_count = nv->retry_count;
1626 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1627 ha->port_down_retry_count > 3)
1628 ha->login_retry_count = ha->port_down_retry_count;
1629 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1630 ha->login_retry_count = ha->port_down_retry_count;
1631 if (ql2xloginretrycount)
1632 ha->login_retry_count = ql2xloginretrycount;
1634 icb->lun_enables = __constant_cpu_to_le16(0);
1635 icb->command_resource_count = 0;
1636 icb->immediate_notify_resource_count = 0;
1637 icb->timeout = __constant_cpu_to_le16(0);
1639 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1641 icb->firmware_options[0] &= ~BIT_3;
1642 icb->add_firmware_options[0] &=
1643 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1644 icb->add_firmware_options[0] |= BIT_2;
1645 icb->response_accumulation_timer = 3;
1646 icb->interrupt_delay_timer = 5;
1648 ha->flags.process_response_queue = 1;
1650 /* Enable ZIO -- Support mode 5 only. */
1651 timer_mode = icb->add_firmware_options[0] &
1652 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1653 icb->add_firmware_options[0] &=
1654 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1656 timer_mode = BIT_2 | BIT_0;
1657 if (timer_mode == (BIT_2 | BIT_0)) {
1658 DEBUG2(printk("scsi(%ld): ZIO enabled; timer delay "
1659 "(%d).\n", ha->host_no, ql2xintrdelaytimer));
1660 qla_printk(KERN_INFO, ha,
1661 "ZIO enabled; timer delay (%d).\n",
1662 ql2xintrdelaytimer);
1664 icb->add_firmware_options[0] |= timer_mode;
1665 icb->interrupt_delay_timer = ql2xintrdelaytimer;
1666 ha->flags.process_response_queue = 1;
1671 DEBUG2_3(printk(KERN_WARNING
1672 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1678 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1680 * @flags: allocation flags
1682 * Returns a pointer to the allocated fcport, or NULL, if none available.
1685 qla2x00_alloc_fcport(scsi_qla_host_t *ha, int flags)
1689 fcport = kmalloc(sizeof(fc_port_t), flags);
1693 /* Setup fcport template structure. */
1694 memset(fcport, 0, sizeof (fc_port_t));
1696 fcport->port_type = FCT_UNKNOWN;
1697 fcport->loop_id = FC_NO_LOOP_ID;
1698 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1699 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1700 fcport->flags = FCF_RLC_SUPPORT;
1701 fcport->supported_classes = FC_COS_UNSPECIFIED;
1707 * qla2x00_configure_loop
1708 * Updates Fibre Channel Device Database with what is actually on loop.
1711 * ha = adapter block pointer.
1716 * 2 = database was full and device was not configured.
1719 qla2x00_configure_loop(scsi_qla_host_t *ha)
1722 unsigned long flags, save_flags;
1726 /* Get Initiator ID */
1727 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1728 rval = qla2x00_configure_hba(ha);
1729 if (rval != QLA_SUCCESS) {
1730 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1736 save_flags = flags = ha->dpc_flags;
1737 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1738 ha->host_no, flags));
1741 * If we have both an RSCN and PORT UPDATE pending then handle them
1742 * both at the same time.
1744 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1745 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1747 /* Determine what we need to do */
1748 if (ha->current_topology == ISP_CFG_FL &&
1749 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1751 ha->flags.rscn_queue_overflow = 1;
1752 set_bit(RSCN_UPDATE, &flags);
1754 } else if (ha->current_topology == ISP_CFG_F &&
1755 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1757 ha->flags.rscn_queue_overflow = 1;
1758 set_bit(RSCN_UPDATE, &flags);
1759 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1761 } else if (!ha->flags.online ||
1762 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1764 ha->flags.rscn_queue_overflow = 1;
1765 set_bit(RSCN_UPDATE, &flags);
1766 set_bit(LOCAL_LOOP_UPDATE, &flags);
1769 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1770 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1771 rval = QLA_FUNCTION_FAILED;
1773 rval = qla2x00_configure_local_loop(ha);
1777 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1778 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1779 rval = QLA_FUNCTION_FAILED;
1781 rval = qla2x00_configure_fabric(ha);
1785 if (rval == QLA_SUCCESS) {
1786 if (atomic_read(&ha->loop_down_timer) ||
1787 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1788 rval = QLA_FUNCTION_FAILED;
1790 atomic_set(&ha->loop_state, LOOP_READY);
1792 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1797 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1798 __func__, ha->host_no));
1800 DEBUG3(printk("%s: exiting normally\n", __func__));
1803 /* Restore state if a resync event occured during processing */
1804 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1805 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1806 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1807 if (test_bit(RSCN_UPDATE, &save_flags))
1808 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1817 * qla2x00_configure_local_loop
1818 * Updates Fibre Channel Device Database with local loop devices.
1821 * ha = adapter block pointer.
1827 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1832 fc_port_t *fcport, *new_fcport;
1838 uint8_t domain, area, al_pa;
1842 entries = MAX_FIBRE_DEVICES;
1844 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1845 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1847 /* Get list of logged in devices. */
1848 memset(ha->gid_list, 0, GID_LIST_SIZE);
1849 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1851 if (rval != QLA_SUCCESS)
1852 goto cleanup_allocation;
1854 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1855 ha->host_no, entries));
1856 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1857 entries * sizeof(struct gid_list_info)));
1859 /* Allocate temporary fcport for any new fcports discovered. */
1860 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1861 if (new_fcport == NULL) {
1862 rval = QLA_MEMORY_ALLOC_FAILED;
1863 goto cleanup_allocation;
1865 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1868 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1870 list_for_each_entry(fcport, &ha->fcports, list) {
1871 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1872 fcport->port_type != FCT_BROADCAST &&
1873 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1875 DEBUG(printk("scsi(%ld): Marking port lost, "
1877 ha->host_no, fcport->loop_id));
1879 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1880 fcport->flags &= ~FCF_FARP_DONE;
1884 /* Add devices to port list. */
1885 id_iter = (char *)ha->gid_list;
1886 for (index = 0; index < entries; index++) {
1887 domain = ((struct gid_list_info *)id_iter)->domain;
1888 area = ((struct gid_list_info *)id_iter)->area;
1889 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1890 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1891 loop_id = (uint16_t)
1892 ((struct gid_list_info *)id_iter)->loop_id_2100;
1894 loop_id = le16_to_cpu(
1895 ((struct gid_list_info *)id_iter)->loop_id);
1896 id_iter += ha->gid_list_info_size;
1898 /* Bypass reserved domain fields. */
1899 if ((domain & 0xf0) == 0xf0)
1902 /* Bypass if not same domain and area of adapter. */
1903 if (area && domain &&
1904 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
1907 /* Bypass invalid local loop ID. */
1908 if (loop_id > LAST_LOCAL_LOOP_ID)
1911 /* Fill in member data. */
1912 new_fcport->d_id.b.domain = domain;
1913 new_fcport->d_id.b.area = area;
1914 new_fcport->d_id.b.al_pa = al_pa;
1915 new_fcport->loop_id = loop_id;
1916 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1917 if (rval2 != QLA_SUCCESS) {
1918 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1919 "information -- get_port_database=%x, "
1921 ha->host_no, rval2, new_fcport->loop_id));
1925 /* Check for matching device in port list. */
1928 list_for_each_entry(fcport, &ha->fcports, list) {
1929 if (memcmp(new_fcport->port_name, fcport->port_name,
1933 fcport->flags &= ~(FCF_FABRIC_DEVICE |
1934 FCF_PERSISTENT_BOUND);
1935 fcport->loop_id = new_fcport->loop_id;
1936 fcport->port_type = new_fcport->port_type;
1937 fcport->d_id.b24 = new_fcport->d_id.b24;
1938 memcpy(fcport->node_name, new_fcport->node_name,
1946 /* New device, add to fcports list. */
1947 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
1948 list_add_tail(&new_fcport->list, &ha->fcports);
1950 /* Allocate a new replacement fcport. */
1951 fcport = new_fcport;
1952 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1953 if (new_fcport == NULL) {
1954 rval = QLA_MEMORY_ALLOC_FAILED;
1955 goto cleanup_allocation;
1957 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1960 qla2x00_update_fcport(ha, fcport);
1969 if (rval != QLA_SUCCESS) {
1970 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1971 "rval=%x\n", ha->host_no, rval));
1975 ha->device_flags |= DFLG_LOCAL_DEVICES;
1976 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
1983 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
1987 qla2x00_mark_all_devices_lost(ha);
1988 list_for_each_entry(fcport, &ha->fcports, list) {
1989 if (fcport->port_type != FCT_TARGET)
1992 qla2x00_update_fcport(ha, fcport);
1997 * qla2x00_update_fcport
1998 * Updates device on list.
2001 * ha = adapter block pointer.
2002 * fcport = port structure pointer.
2012 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2015 unsigned long flags;
2019 fcport->login_retry = 0;
2020 fcport->port_login_retry_count = ha->port_down_retry_count *
2022 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2024 fcport->flags &= ~FCF_LOGIN_NEEDED;
2027 * Check for outstanding cmd on tape Bypass LUN discovery if active
2030 if (fcport->flags & FCF_TAPE_PRESENT) {
2031 spin_lock_irqsave(&ha->hardware_lock, flags);
2032 for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
2035 if ((sp = ha->outstanding_cmds[index]) != 0) {
2037 if (sfcp == fcport) {
2038 atomic_set(&fcport->state, FCS_ONLINE);
2039 spin_unlock_irqrestore(
2040 &ha->hardware_lock, flags);
2045 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2048 if (fcport->port_type == FCT_INITIATOR ||
2049 fcport->port_type == FCT_BROADCAST)
2050 fcport->device_type = TYPE_PROCESSOR;
2052 atomic_set(&fcport->state, FCS_ONLINE);
2054 if (ha->flags.init_done)
2055 qla2x00_reg_remote_port(ha, fcport);
2059 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2061 struct fc_rport_identifiers rport_ids;
2062 struct fc_rport *rport;
2064 if (fcport->rport) {
2065 fc_remote_port_unblock(fcport->rport);
2069 rport_ids.node_name = be64_to_cpu(*(uint64_t *)fcport->node_name);
2070 rport_ids.port_name = be64_to_cpu(*(uint64_t *)fcport->port_name);
2071 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2072 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2073 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2074 fcport->rport = rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2076 qla_printk(KERN_WARNING, ha,
2077 "Unable to allocate fc remote port!\n");
2080 rport->dd_data = fcport;
2081 rport->supported_classes = fcport->supported_classes;
2083 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2084 if (fcport->port_type == FCT_INITIATOR)
2085 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2086 if (fcport->port_type == FCT_TARGET)
2087 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2088 fc_remote_port_rolechg(rport, rport_ids.roles);
2090 if (rport->scsi_target_id != -1 &&
2091 rport->scsi_target_id < ha->host->max_id)
2092 fcport->os_target_id = rport->scsi_target_id;
2096 * qla2x00_configure_fabric
2097 * Setup SNS devices with loop ID's.
2100 * ha = adapter block pointer.
2107 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2110 fc_port_t *fcport, *fcptemp;
2111 uint16_t next_loopid;
2112 uint16_t mb[MAILBOX_REGISTER_COUNT];
2114 LIST_HEAD(new_fcports);
2116 /* If FL port exists, then SNS is present */
2117 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
2118 loop_id = NPH_F_PORT;
2120 loop_id = SNS_FL_PORT;
2121 rval = qla2x00_get_port_name(ha, loop_id, NULL, 0);
2122 if (rval != QLA_SUCCESS) {
2123 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2124 "Port\n", ha->host_no));
2126 ha->device_flags &= ~SWITCH_FOUND;
2127 return (QLA_SUCCESS);
2130 /* Mark devices that need re-synchronization. */
2131 rval2 = qla2x00_device_resync(ha);
2132 if (rval2 == QLA_RSCNS_HANDLED) {
2133 /* No point doing the scan, just continue. */
2134 return (QLA_SUCCESS);
2138 if (ql2xfdmienable &&
2139 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2140 qla2x00_fdmi_register(ha);
2142 /* Ensure we are logged into the SNS. */
2143 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
2146 loop_id = SIMPLE_NAME_SERVER;
2147 ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
2148 0xfc, mb, BIT_1 | BIT_0);
2149 if (mb[0] != MBS_COMMAND_COMPLETE) {
2150 DEBUG2(qla_printk(KERN_INFO, ha,
2151 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2152 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2153 mb[0], mb[1], mb[2], mb[6], mb[7]));
2154 return (QLA_SUCCESS);
2157 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2158 if (qla2x00_rft_id(ha)) {
2160 DEBUG2(printk("scsi(%ld): Register FC-4 "
2161 "TYPE failed.\n", ha->host_no));
2163 if (qla2x00_rff_id(ha)) {
2165 DEBUG2(printk("scsi(%ld): Register FC-4 "
2166 "Features failed.\n", ha->host_no));
2168 if (qla2x00_rnn_id(ha)) {
2170 DEBUG2(printk("scsi(%ld): Register Node Name "
2171 "failed.\n", ha->host_no));
2172 } else if (qla2x00_rsnn_nn(ha)) {
2174 DEBUG2(printk("scsi(%ld): Register Symbolic "
2175 "Node Name failed.\n", ha->host_no));
2179 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2180 if (rval != QLA_SUCCESS)
2184 * Logout all previous fabric devices marked lost, except
2187 list_for_each_entry(fcport, &ha->fcports, list) {
2188 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2191 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2194 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2195 qla2x00_mark_device_lost(ha, fcport,
2196 ql2xplogiabsentdevice);
2197 if (fcport->loop_id != FC_NO_LOOP_ID &&
2198 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2199 fcport->port_type != FCT_INITIATOR &&
2200 fcport->port_type != FCT_BROADCAST) {
2202 ha->isp_ops.fabric_logout(ha,
2204 fcport->d_id.b.domain,
2205 fcport->d_id.b.area,
2206 fcport->d_id.b.al_pa);
2207 fcport->loop_id = FC_NO_LOOP_ID;
2212 /* Starting free loop ID. */
2213 next_loopid = ha->min_external_loopid;
2216 * Scan through our port list and login entries that need to be
2219 list_for_each_entry(fcport, &ha->fcports, list) {
2220 if (atomic_read(&ha->loop_down_timer) ||
2221 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2224 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2225 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2228 if (fcport->loop_id == FC_NO_LOOP_ID) {
2229 fcport->loop_id = next_loopid;
2230 rval = qla2x00_find_new_loop_id(ha, fcport);
2231 if (rval != QLA_SUCCESS) {
2232 /* Ran out of IDs to use */
2236 /* Login and update database */
2237 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2240 /* Exit if out of loop IDs. */
2241 if (rval != QLA_SUCCESS) {
2246 * Login and add the new devices to our port list.
2248 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2249 if (atomic_read(&ha->loop_down_timer) ||
2250 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2253 /* Find a new loop ID to use. */
2254 fcport->loop_id = next_loopid;
2255 rval = qla2x00_find_new_loop_id(ha, fcport);
2256 if (rval != QLA_SUCCESS) {
2257 /* Ran out of IDs to use */
2261 /* Remove device from the new list and add it to DB */
2262 list_del(&fcport->list);
2263 list_add_tail(&fcport->list, &ha->fcports);
2265 /* Login and update database */
2266 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2270 /* Free all new device structures not processed. */
2271 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2272 list_del(&fcport->list);
2277 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2278 "rval=%d\n", ha->host_no, rval));
2286 * qla2x00_find_all_fabric_devs
2289 * ha = adapter block pointer.
2290 * dev = database device entry pointer.
2299 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2303 fc_port_t *fcport, *new_fcport, *fcptemp;
2308 int first_dev, last_dev;
2309 port_id_t wrap, nxt_d_id;
2313 /* Try GID_PT to get device list, else GAN. */
2314 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2317 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2318 "on GA_NXT\n", ha->host_no));
2320 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2321 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2324 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2327 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2334 /* Allocate temporary fcport for any new fcports discovered. */
2335 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2336 if (new_fcport == NULL) {
2339 return (QLA_MEMORY_ALLOC_FAILED);
2341 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2343 /* Set start port ID scan at adapter ID. */
2347 /* Starting free loop ID. */
2348 loop_id = ha->min_external_loopid;
2349 for (; loop_id <= ha->last_loop_id; loop_id++) {
2350 if (qla2x00_is_reserved_id(ha, loop_id))
2353 if (atomic_read(&ha->loop_down_timer) ||
2354 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2359 wrap.b24 = new_fcport->d_id.b24;
2361 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2362 memcpy(new_fcport->node_name,
2363 swl[swl_idx].node_name, WWN_SIZE);
2364 memcpy(new_fcport->port_name,
2365 swl[swl_idx].port_name, WWN_SIZE);
2367 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2373 /* Send GA_NXT to the switch */
2374 rval = qla2x00_ga_nxt(ha, new_fcport);
2375 if (rval != QLA_SUCCESS) {
2376 qla_printk(KERN_WARNING, ha,
2377 "SNS scan failed -- assuming zero-entry "
2379 list_for_each_entry_safe(fcport, fcptemp,
2380 new_fcports, list) {
2381 list_del(&fcport->list);
2389 /* If wrap on switch device list, exit. */
2391 wrap.b24 = new_fcport->d_id.b24;
2393 } else if (new_fcport->d_id.b24 == wrap.b24) {
2394 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2395 ha->host_no, new_fcport->d_id.b.domain,
2396 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2400 /* Bypass if host adapter. */
2401 if (new_fcport->d_id.b24 == ha->d_id.b24)
2404 /* Bypass if same domain and area of adapter. */
2405 if (((new_fcport->d_id.b24 & 0xffff00) ==
2406 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2410 /* Bypass reserved domain fields. */
2411 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2414 /* Locate matching device in database. */
2416 list_for_each_entry(fcport, &ha->fcports, list) {
2417 if (memcmp(new_fcport->port_name, fcport->port_name,
2424 * If address the same and state FCS_ONLINE, nothing
2427 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2428 atomic_read(&fcport->state) == FCS_ONLINE) {
2433 * If device was not a fabric device before.
2435 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2436 fcport->d_id.b24 = new_fcport->d_id.b24;
2437 fcport->loop_id = FC_NO_LOOP_ID;
2438 fcport->flags |= (FCF_FABRIC_DEVICE |
2440 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2445 * Port ID changed or device was marked to be updated;
2446 * Log it out if still logged in and mark it for
2449 fcport->d_id.b24 = new_fcport->d_id.b24;
2450 fcport->flags |= FCF_LOGIN_NEEDED;
2451 if (fcport->loop_id != FC_NO_LOOP_ID &&
2452 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2453 fcport->port_type != FCT_INITIATOR &&
2454 fcport->port_type != FCT_BROADCAST) {
2455 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2456 fcport->d_id.b.domain, fcport->d_id.b.area,
2457 fcport->d_id.b.al_pa);
2458 fcport->loop_id = FC_NO_LOOP_ID;
2467 /* If device was not in our fcports list, then add it. */
2468 list_add_tail(&new_fcport->list, new_fcports);
2470 /* Allocate a new replacement fcport. */
2471 nxt_d_id.b24 = new_fcport->d_id.b24;
2472 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2473 if (new_fcport == NULL) {
2476 return (QLA_MEMORY_ALLOC_FAILED);
2478 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2479 new_fcport->d_id.b24 = nxt_d_id.b24;
2488 if (!list_empty(new_fcports))
2489 ha->device_flags |= DFLG_FABRIC_DEVICES;
2495 * qla2x00_find_new_loop_id
2496 * Scan through our port list and find a new usable loop ID.
2499 * ha: adapter state pointer.
2500 * dev: port structure pointer.
2503 * qla2x00 local function return status code.
2509 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2514 uint16_t first_loop_id;
2518 /* Save starting loop ID. */
2519 first_loop_id = dev->loop_id;
2522 /* Skip loop ID if already used by adapter. */
2523 if (dev->loop_id == ha->loop_id) {
2527 /* Skip reserved loop IDs. */
2528 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2532 /* Reset loop ID if passed the end. */
2533 if (dev->loop_id > ha->last_loop_id) {
2534 /* first loop ID. */
2535 dev->loop_id = ha->min_external_loopid;
2538 /* Check for loop ID being already in use. */
2541 list_for_each_entry(fcport, &ha->fcports, list) {
2542 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2543 /* ID possibly in use */
2549 /* If not in use then it is free to use. */
2554 /* ID in use. Try next value. */
2557 /* If wrap around. No free ID to use. */
2558 if (dev->loop_id == first_loop_id) {
2559 dev->loop_id = FC_NO_LOOP_ID;
2560 rval = QLA_FUNCTION_FAILED;
2569 * qla2x00_device_resync
2570 * Marks devices in the database that needs resynchronization.
2573 * ha = adapter block pointer.
2579 qla2x00_device_resync(scsi_qla_host_t *ha)
2585 uint32_t rscn_entry;
2586 uint8_t rscn_out_iter;
2590 rval = QLA_RSCNS_HANDLED;
2592 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2593 ha->flags.rscn_queue_overflow) {
2595 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2596 format = MSB(MSW(rscn_entry));
2597 d_id.b.domain = LSB(MSW(rscn_entry));
2598 d_id.b.area = MSB(LSW(rscn_entry));
2599 d_id.b.al_pa = LSB(LSW(rscn_entry));
2601 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2602 "[%02x/%02x%02x%02x].\n",
2603 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2604 d_id.b.area, d_id.b.al_pa));
2607 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2608 ha->rscn_out_ptr = 0;
2610 /* Skip duplicate entries. */
2611 for (rscn_out_iter = ha->rscn_out_ptr;
2612 !ha->flags.rscn_queue_overflow &&
2613 rscn_out_iter != ha->rscn_in_ptr;
2614 rscn_out_iter = (rscn_out_iter ==
2615 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2617 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2620 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2621 "entry found at [%d].\n", ha->host_no,
2624 ha->rscn_out_ptr = rscn_out_iter;
2627 /* Queue overflow, set switch default case. */
2628 if (ha->flags.rscn_queue_overflow) {
2629 DEBUG(printk("scsi(%ld): device_resync: rscn "
2630 "overflow.\n", ha->host_no));
2633 ha->flags.rscn_queue_overflow = 0;
2638 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) &&
2639 !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
2640 !IS_QLA24XX(ha) && !IS_QLA25XX(ha) &&
2641 ha->flags.init_done) {
2642 /* Handle port RSCN via asyncronous IOCBs */
2643 rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
2645 if (rval2 == QLA_SUCCESS)
2659 ha->rscn_out_ptr = ha->rscn_in_ptr;
2665 /* Abort any outstanding IO descriptors. */
2666 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2667 qla2x00_cancel_io_descriptors(ha);
2669 list_for_each_entry(fcport, &ha->fcports, list) {
2670 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2671 (fcport->d_id.b24 & mask) != d_id.b24 ||
2672 fcport->port_type == FCT_BROADCAST)
2675 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2677 fcport->port_type != FCT_INITIATOR) {
2678 qla2x00_mark_device_lost(ha, fcport, 0);
2681 fcport->flags &= ~FCF_FARP_DONE;
2688 * qla2x00_fabric_dev_login
2689 * Login fabric target device and update FC port database.
2692 * ha: adapter state pointer.
2693 * fcport: port structure list pointer.
2694 * next_loopid: contains value of a new loop ID that can be used
2695 * by the next login attempt.
2698 * qla2x00 local function return status code.
2704 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2705 uint16_t *next_loopid)
2714 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2715 if (rval == QLA_SUCCESS) {
2716 /* Send an ADISC to tape devices.*/
2718 if (fcport->flags & FCF_TAPE_PRESENT)
2720 rval = qla2x00_get_port_database(ha, fcport, opts);
2721 if (rval != QLA_SUCCESS) {
2722 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2723 fcport->d_id.b.domain, fcport->d_id.b.area,
2724 fcport->d_id.b.al_pa);
2725 qla2x00_mark_device_lost(ha, fcport, 1);
2728 qla2x00_update_fcport(ha, fcport);
2736 * qla2x00_fabric_login
2737 * Issue fabric login command.
2740 * ha = adapter block pointer.
2741 * device = pointer to FC device type structure.
2744 * 0 - Login successfully
2746 * 2 - Initiator device
2750 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2751 uint16_t *next_loopid)
2755 uint16_t tmp_loopid;
2756 uint16_t mb[MAILBOX_REGISTER_COUNT];
2762 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2763 "for port %02x%02x%02x.\n",
2764 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2765 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2767 /* Login fcport on switch. */
2768 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2769 fcport->d_id.b.domain, fcport->d_id.b.area,
2770 fcport->d_id.b.al_pa, mb, BIT_0);
2771 if (mb[0] == MBS_PORT_ID_USED) {
2773 * Device has another loop ID. The firmware team
2774 * recommends the driver perform an implicit login with
2775 * the specified ID again. The ID we just used is save
2776 * here so we return with an ID that can be tried by
2780 tmp_loopid = fcport->loop_id;
2781 fcport->loop_id = mb[1];
2783 DEBUG(printk("Fabric Login: port in use - next "
2784 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2785 fcport->loop_id, fcport->d_id.b.domain,
2786 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2788 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2793 /* A retry occurred before. */
2794 *next_loopid = tmp_loopid;
2797 * No retry occurred before. Just increment the
2798 * ID value for next login.
2800 *next_loopid = (fcport->loop_id + 1);
2803 if (mb[1] & BIT_0) {
2804 fcport->port_type = FCT_INITIATOR;
2806 fcport->port_type = FCT_TARGET;
2807 if (mb[1] & BIT_1) {
2808 fcport->flags |= FCF_TAPE_PRESENT;
2813 fcport->supported_classes |= FC_COS_CLASS2;
2815 fcport->supported_classes |= FC_COS_CLASS3;
2819 } else if (mb[0] == MBS_LOOP_ID_USED) {
2821 * Loop ID already used, try next loop ID.
2824 rval = qla2x00_find_new_loop_id(ha, fcport);
2825 if (rval != QLA_SUCCESS) {
2826 /* Ran out of loop IDs to use */
2829 } else if (mb[0] == MBS_COMMAND_ERROR) {
2831 * Firmware possibly timed out during login. If NO
2832 * retries are left to do then the device is declared
2835 *next_loopid = fcport->loop_id;
2836 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2837 fcport->d_id.b.domain, fcport->d_id.b.area,
2838 fcport->d_id.b.al_pa);
2839 qla2x00_mark_device_lost(ha, fcport, 1);
2845 * unrecoverable / not handled error
2847 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2848 "loop_id=%x jiffies=%lx.\n",
2849 __func__, ha->host_no, mb[0],
2850 fcport->d_id.b.domain, fcport->d_id.b.area,
2851 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2853 *next_loopid = fcport->loop_id;
2854 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2855 fcport->d_id.b.domain, fcport->d_id.b.area,
2856 fcport->d_id.b.al_pa);
2857 fcport->loop_id = FC_NO_LOOP_ID;
2858 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
2869 * qla2x00_local_device_login
2870 * Issue local device login command.
2873 * ha = adapter block pointer.
2874 * loop_id = loop id of device to login to.
2876 * Returns (Where's the #define!!!!):
2877 * 0 - Login successfully
2882 qla2x00_local_device_login(scsi_qla_host_t *ha, uint16_t loop_id)
2885 uint16_t mb[MAILBOX_REGISTER_COUNT];
2887 memset(mb, 0, sizeof(mb));
2888 rval = qla2x00_login_local_device(ha, loop_id, mb, BIT_0);
2889 if (rval == QLA_SUCCESS) {
2890 /* Interrogate mailbox registers for any errors */
2891 if (mb[0] == MBS_COMMAND_ERROR)
2893 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
2894 /* device not in PCB table */
2902 * qla2x00_loop_resync
2903 * Resync with fibre channel devices.
2906 * ha = adapter block pointer.
2912 qla2x00_loop_resync(scsi_qla_host_t *ha)
2919 atomic_set(&ha->loop_state, LOOP_UPDATE);
2920 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2921 if (ha->flags.online) {
2922 if (!(rval = qla2x00_fw_ready(ha))) {
2923 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2926 atomic_set(&ha->loop_state, LOOP_UPDATE);
2928 /* Issue a marker after FW becomes ready. */
2929 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
2930 ha->marker_needed = 0;
2932 /* Remap devices on Loop. */
2933 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2935 qla2x00_configure_loop(ha);
2937 } while (!atomic_read(&ha->loop_down_timer) &&
2938 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
2940 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
2944 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2945 return (QLA_FUNCTION_FAILED);
2949 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
2956 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
2962 list_for_each_entry(fcport, &ha->fcports, list) {
2963 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
2966 qla2x00_update_fcport(ha, fcport);
2967 fcport->flags &= ~FCF_RESCAN_NEEDED;
2971 qla2x00_probe_for_all_luns(ha);
2976 * Resets ISP and aborts all outstanding commands.
2979 * ha = adapter block pointer.
2985 qla2x00_abort_isp(scsi_qla_host_t *ha)
2987 unsigned long flags = 0;
2992 if (ha->flags.online) {
2993 ha->flags.online = 0;
2994 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2996 qla_printk(KERN_INFO, ha,
2997 "Performing ISP error recovery - ha= %p.\n", ha);
2998 ha->isp_ops.reset_chip(ha);
3000 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3001 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3002 atomic_set(&ha->loop_state, LOOP_DOWN);
3003 qla2x00_mark_all_devices_lost(ha);
3005 if (!atomic_read(&ha->loop_down_timer))
3006 atomic_set(&ha->loop_down_timer,
3010 spin_lock_irqsave(&ha->hardware_lock, flags);
3011 /* Requeue all commands in outstanding command list. */
3012 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3013 sp = ha->outstanding_cmds[cnt];
3015 ha->outstanding_cmds[cnt] = NULL;
3017 sp->cmd->result = DID_RESET << 16;
3018 sp->cmd->host_scribble = (unsigned char *)NULL;
3019 qla2x00_sp_compl(ha, sp);
3022 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3024 ha->isp_ops.nvram_config(ha);
3026 if (!qla2x00_restart_isp(ha)) {
3027 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3029 if (!atomic_read(&ha->loop_down_timer)) {
3031 * Issue marker command only when we are going
3032 * to start the I/O .
3034 ha->marker_needed = 1;
3037 ha->flags.online = 1;
3039 ha->isp_ops.enable_intrs(ha);
3041 ha->isp_abort_cnt = 0;
3042 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3043 } else { /* failed the ISP abort */
3044 ha->flags.online = 1;
3045 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3046 if (ha->isp_abort_cnt == 0) {
3047 qla_printk(KERN_WARNING, ha,
3048 "ISP error recovery failed - "
3049 "board disabled\n");
3051 * The next call disables the board
3054 ha->isp_ops.reset_adapter(ha);
3055 ha->flags.online = 0;
3056 clear_bit(ISP_ABORT_RETRY,
3059 } else { /* schedule another ISP abort */
3060 ha->isp_abort_cnt--;
3061 DEBUG(printk("qla%ld: ISP abort - "
3062 "retry remaining %d\n",
3063 ha->host_no, ha->isp_abort_cnt);)
3067 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3068 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3069 "- retrying (%d) more times\n",
3070 ha->host_no, ha->isp_abort_cnt);)
3071 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3079 qla_printk(KERN_INFO, ha,
3080 "qla2x00_abort_isp: **** FAILED ****\n");
3082 DEBUG(printk(KERN_INFO
3083 "qla2x00_abort_isp(%ld): exiting.\n",
3091 * qla2x00_restart_isp
3092 * restarts the ISP after a reset
3095 * ha = adapter block pointer.
3101 qla2x00_restart_isp(scsi_qla_host_t *ha)
3104 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;