2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/delay.h>
10 #include <linux/vmalloc.h>
12 #include "qla_devtbl.h"
14 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
15 #ifndef EXT_IS_LUN_BIT_SET
16 #define EXT_IS_LUN_BIT_SET(P,L) \
17 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
18 #define EXT_SET_LUN_BIT(P,L) \
19 ((P)->mask[L/8] |= (0x80 >> (L%8)))
23 * QLogic ISP2x00 Hardware Support Function Prototypes.
25 static int qla2x00_isp_firmware(scsi_qla_host_t *);
26 static void qla2x00_resize_request_q(scsi_qla_host_t *);
27 static int qla2x00_setup_chip(scsi_qla_host_t *);
28 static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
29 static int qla2x00_init_rings(scsi_qla_host_t *);
30 static int qla2x00_fw_ready(scsi_qla_host_t *);
31 static int qla2x00_configure_hba(scsi_qla_host_t *);
32 static int qla2x00_configure_loop(scsi_qla_host_t *);
33 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
34 static int qla2x00_configure_fabric(scsi_qla_host_t *);
35 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
36 static int qla2x00_device_resync(scsi_qla_host_t *);
37 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
40 static int qla2x00_restart_isp(scsi_qla_host_t *);
42 static int qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev);
44 /****************************************************************************/
45 /* QLogic ISP2x00 Hardware Support Functions. */
46 /****************************************************************************/
49 * qla2x00_initialize_adapter
53 * ha = adapter block pointer.
59 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
62 uint8_t restart_risc = 0;
66 /* Clear adapter flags. */
68 ha->flags.reset_active = 0;
69 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
70 atomic_set(&ha->loop_state, LOOP_DOWN);
73 ha->flags.management_server_logged_in = 0;
74 ha->marker_needed = 0;
76 ha->isp_abort_cnt = 0;
77 ha->beacon_blink_led = 0;
78 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
80 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
81 rval = ha->isp_ops.pci_config(ha);
83 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
88 ha->isp_ops.reset_chip(ha);
90 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
92 ha->isp_ops.nvram_config(ha);
94 if (ha->flags.disable_serdes) {
95 /* Mask HBA via NVRAM settings? */
96 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
97 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
98 ha->port_name[0], ha->port_name[1],
99 ha->port_name[2], ha->port_name[3],
100 ha->port_name[4], ha->port_name[5],
101 ha->port_name[6], ha->port_name[7]);
102 return QLA_FUNCTION_FAILED;
105 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
109 * Try to configure the loop.
114 /* If firmware needs to be loaded */
115 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
116 if ((rval = ha->isp_ops.chip_diag(ha)) == QLA_SUCCESS) {
117 rval = qla2x00_setup_chip(ha);
121 if (rval == QLA_SUCCESS &&
122 (rval = qla2x00_init_rings(ha)) == QLA_SUCCESS) {
123 check_fw_ready_again:
125 * Wait for a successful LIP up to a maximum
126 * of (in seconds): RISC login timeout value,
127 * RISC retry count value, and port down retry
128 * value OR a minimum of 4 seconds OR If no
129 * cable, only 5 seconds.
131 rval = qla2x00_fw_ready(ha);
132 if (rval == QLA_SUCCESS) {
133 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
135 /* Issue a marker after FW becomes ready. */
136 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
139 * Wait at most MAX_TARGET RSCNs for a stable
144 clear_bit(LOOP_RESYNC_NEEDED,
146 rval = qla2x00_configure_loop(ha);
148 if (test_and_clear_bit(ISP_ABORT_NEEDED,
155 * If loop state change while we were
156 * discoverying devices then wait for
160 if (atomic_read(&ha->loop_state) !=
161 LOOP_READY && retry--) {
162 goto check_fw_ready_again;
165 } while (!atomic_read(&ha->loop_down_timer) &&
168 (test_bit(LOOP_RESYNC_NEEDED,
172 rval = QLA_FUNCTION_FAILED;
173 } else if (ha->device_flags & DFLG_NO_CABLE)
174 /* If no cable, then all is good. */
177 } while (restart_risc && retry--);
179 if (rval == QLA_SUCCESS) {
180 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
181 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
182 ha->marker_needed = 0;
184 ha->flags.online = 1;
186 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
193 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
196 * Returns 0 on success.
199 qla2100_pci_config(scsi_qla_host_t *ha)
204 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
206 pci_set_master(ha->pdev);
208 if (pci_set_mwi(ha->pdev))
209 mwi = PCI_COMMAND_INVALIDATE;
211 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
212 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
213 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
215 /* Reset expansion ROM address decode enable */
216 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
217 d &= ~PCI_ROM_ADDRESS_ENABLE;
218 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
220 /* Get PCI bus information. */
221 spin_lock_irqsave(&ha->hardware_lock, flags);
222 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
223 spin_unlock_irqrestore(&ha->hardware_lock, flags);
229 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
232 * Returns 0 on success.
235 qla2300_pci_config(scsi_qla_host_t *ha)
239 unsigned long flags = 0;
241 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
243 pci_set_master(ha->pdev);
245 if (pci_set_mwi(ha->pdev))
246 mwi = PCI_COMMAND_INVALIDATE;
248 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
249 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
251 if (IS_QLA2322(ha) || IS_QLA6322(ha))
252 w &= ~PCI_COMMAND_INTX_DISABLE;
255 * If this is a 2300 card and not 2312, reset the
256 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
257 * the 2310 also reports itself as a 2300 so we need to get the
258 * fb revision level -- a 6 indicates it really is a 2300 and
261 if (IS_QLA2300(ha)) {
262 spin_lock_irqsave(&ha->hardware_lock, flags);
265 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
266 for (cnt = 0; cnt < 30000; cnt++) {
267 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
273 /* Select FPM registers. */
274 WRT_REG_WORD(®->ctrl_status, 0x20);
275 RD_REG_WORD(®->ctrl_status);
277 /* Get the fb rev level */
278 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
280 if (ha->fb_rev == FPM_2300)
281 w &= ~PCI_COMMAND_INVALIDATE;
283 /* Deselect FPM registers. */
284 WRT_REG_WORD(®->ctrl_status, 0x0);
285 RD_REG_WORD(®->ctrl_status);
287 /* Release RISC module. */
288 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
289 for (cnt = 0; cnt < 30000; cnt++) {
290 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
296 spin_unlock_irqrestore(&ha->hardware_lock, flags);
298 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
300 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
302 /* Reset expansion ROM address decode enable */
303 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
304 d &= ~PCI_ROM_ADDRESS_ENABLE;
305 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
307 /* Get PCI bus information. */
308 spin_lock_irqsave(&ha->hardware_lock, flags);
309 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
310 spin_unlock_irqrestore(&ha->hardware_lock, flags);
316 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
319 * Returns 0 on success.
322 qla24xx_pci_config(scsi_qla_host_t *ha)
326 unsigned long flags = 0;
327 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
328 int pcix_cmd_reg, pcie_dctl_reg;
330 pci_set_master(ha->pdev);
332 if (pci_set_mwi(ha->pdev))
333 mwi = PCI_COMMAND_INVALIDATE;
335 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
336 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
337 w &= ~PCI_COMMAND_INTX_DISABLE;
338 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
340 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
342 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
343 pcix_cmd_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX);
347 pcix_cmd_reg += PCI_X_CMD;
348 pci_read_config_word(ha->pdev, pcix_cmd_reg, &pcix_cmd);
349 pcix_cmd &= ~PCI_X_CMD_MAX_READ;
351 pci_write_config_word(ha->pdev, pcix_cmd_reg, pcix_cmd);
354 /* PCIe -- adjust Maximum Read Request Size (2048). */
355 pcie_dctl_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
359 pcie_dctl_reg += PCI_EXP_DEVCTL;
360 pci_read_config_word(ha->pdev, pcie_dctl_reg, &pcie_dctl);
361 pcie_dctl &= ~PCI_EXP_DEVCTL_READRQ;
363 pci_write_config_word(ha->pdev, pcie_dctl_reg, pcie_dctl);
366 /* Reset expansion ROM address decode enable */
367 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
368 d &= ~PCI_ROM_ADDRESS_ENABLE;
369 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
371 /* Get PCI bus information. */
372 spin_lock_irqsave(&ha->hardware_lock, flags);
373 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
374 spin_unlock_irqrestore(&ha->hardware_lock, flags);
380 * qla2x00_isp_firmware() - Choose firmware image.
383 * Returns 0 on success.
386 qla2x00_isp_firmware(scsi_qla_host_t *ha)
390 /* Assume loading risc code */
391 rval = QLA_FUNCTION_FAILED;
393 if (ha->flags.disable_risc_code_load) {
394 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
396 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
398 /* Verify checksum of loaded RISC code. */
399 rval = qla2x00_verify_checksum(ha, ha->fw_srisc_address);
403 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
411 * qla2x00_reset_chip() - Reset ISP chip.
414 * Returns 0 on success.
417 qla2x00_reset_chip(scsi_qla_host_t *ha)
419 unsigned long flags = 0;
420 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
424 ha->isp_ops.disable_intrs(ha);
426 spin_lock_irqsave(&ha->hardware_lock, flags);
428 /* Turn off master enable */
430 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
431 cmd &= ~PCI_COMMAND_MASTER;
432 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
434 if (!IS_QLA2100(ha)) {
436 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
437 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
438 for (cnt = 0; cnt < 30000; cnt++) {
439 if ((RD_REG_WORD(®->hccr) &
440 HCCR_RISC_PAUSE) != 0)
445 RD_REG_WORD(®->hccr); /* PCI Posting. */
449 /* Select FPM registers. */
450 WRT_REG_WORD(®->ctrl_status, 0x20);
451 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
453 /* FPM Soft Reset. */
454 WRT_REG_WORD(®->fpm_diag_config, 0x100);
455 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
457 /* Toggle Fpm Reset. */
458 if (!IS_QLA2200(ha)) {
459 WRT_REG_WORD(®->fpm_diag_config, 0x0);
460 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
463 /* Select frame buffer registers. */
464 WRT_REG_WORD(®->ctrl_status, 0x10);
465 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
467 /* Reset frame buffer FIFOs. */
468 if (IS_QLA2200(ha)) {
469 WRT_FB_CMD_REG(ha, reg, 0xa000);
470 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
472 WRT_FB_CMD_REG(ha, reg, 0x00fc);
474 /* Read back fb_cmd until zero or 3 seconds max */
475 for (cnt = 0; cnt < 3000; cnt++) {
476 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
482 /* Select RISC module registers. */
483 WRT_REG_WORD(®->ctrl_status, 0);
484 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
486 /* Reset RISC processor. */
487 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
488 RD_REG_WORD(®->hccr); /* PCI Posting. */
490 /* Release RISC processor. */
491 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
492 RD_REG_WORD(®->hccr); /* PCI Posting. */
495 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
496 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
498 /* Reset ISP chip. */
499 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
501 /* Wait for RISC to recover from reset. */
502 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
504 * It is necessary to for a delay here since the card doesn't
505 * respond to PCI reads during a reset. On some architectures
506 * this will result in an MCA.
509 for (cnt = 30000; cnt; cnt--) {
510 if ((RD_REG_WORD(®->ctrl_status) &
511 CSR_ISP_SOFT_RESET) == 0)
518 /* Reset RISC processor. */
519 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
521 WRT_REG_WORD(®->semaphore, 0);
523 /* Release RISC processor. */
524 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
525 RD_REG_WORD(®->hccr); /* PCI Posting. */
527 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
528 for (cnt = 0; cnt < 30000; cnt++) {
529 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
537 /* Turn on master enable */
538 cmd |= PCI_COMMAND_MASTER;
539 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
541 /* Disable RISC pause on FPM parity error. */
542 if (!IS_QLA2100(ha)) {
543 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
544 RD_REG_WORD(®->hccr); /* PCI Posting. */
547 spin_unlock_irqrestore(&ha->hardware_lock, flags);
551 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
554 * Returns 0 on success.
557 qla24xx_reset_risc(scsi_qla_host_t *ha)
559 unsigned long flags = 0;
560 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
564 spin_lock_irqsave(&ha->hardware_lock, flags);
567 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
568 for (cnt = 0; cnt < 30000; cnt++) {
569 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
575 WRT_REG_DWORD(®->ctrl_status,
576 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
577 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
580 /* Wait for firmware to complete NVRAM accesses. */
581 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
582 for (cnt = 10000 ; cnt && d2; cnt--) {
584 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
588 /* Wait for soft-reset to complete. */
589 d2 = RD_REG_DWORD(®->ctrl_status);
590 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
592 d2 = RD_REG_DWORD(®->ctrl_status);
596 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
597 RD_REG_DWORD(®->hccr);
599 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
600 RD_REG_DWORD(®->hccr);
602 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
603 RD_REG_DWORD(®->hccr);
605 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
606 for (cnt = 6000000 ; cnt && d2; cnt--) {
608 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
612 spin_unlock_irqrestore(&ha->hardware_lock, flags);
616 * qla24xx_reset_chip() - Reset ISP24xx chip.
619 * Returns 0 on success.
622 qla24xx_reset_chip(scsi_qla_host_t *ha)
624 ha->isp_ops.disable_intrs(ha);
626 /* Perform RISC reset. */
627 qla24xx_reset_risc(ha);
631 * qla2x00_chip_diag() - Test chip for proper operation.
634 * Returns 0 on success.
637 qla2x00_chip_diag(scsi_qla_host_t *ha)
640 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
641 unsigned long flags = 0;
646 /* Assume a failed state */
647 rval = QLA_FUNCTION_FAILED;
649 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
650 ha->host_no, (u_long)®->flash_address));
652 spin_lock_irqsave(&ha->hardware_lock, flags);
654 /* Reset ISP chip. */
655 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
658 * We need to have a delay here since the card will not respond while
659 * in reset causing an MCA on some architectures.
662 data = qla2x00_debounce_register(®->ctrl_status);
663 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
665 data = RD_REG_WORD(®->ctrl_status);
670 goto chip_diag_failed;
672 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
675 /* Reset RISC processor. */
676 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
677 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
679 /* Workaround for QLA2312 PCI parity error */
680 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
681 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
682 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
684 data = RD_MAILBOX_REG(ha, reg, 0);
691 goto chip_diag_failed;
693 /* Check product ID of chip */
694 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
696 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
697 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
698 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
699 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
700 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
701 mb[3] != PROD_ID_3) {
702 qla_printk(KERN_WARNING, ha,
703 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
705 goto chip_diag_failed;
707 ha->product_id[0] = mb[1];
708 ha->product_id[1] = mb[2];
709 ha->product_id[2] = mb[3];
710 ha->product_id[3] = mb[4];
712 /* Adjust fw RISC transfer size */
713 if (ha->request_q_length > 1024)
714 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
716 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
717 ha->request_q_length;
719 if (IS_QLA2200(ha) &&
720 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
721 /* Limit firmware transfer size with a 2200A */
722 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
725 ha->device_type |= DT_ISP2200A;
726 ha->fw_transfer_size = 128;
729 /* Wrap Incoming Mailboxes Test. */
730 spin_unlock_irqrestore(&ha->hardware_lock, flags);
732 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
733 rval = qla2x00_mbx_reg_test(ha);
735 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
737 qla_printk(KERN_WARNING, ha,
738 "Failed mailbox send register test\n");
741 /* Flag a successful rval */
744 spin_lock_irqsave(&ha->hardware_lock, flags);
748 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
749 "****\n", ha->host_no));
751 spin_unlock_irqrestore(&ha->hardware_lock, flags);
757 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
760 * Returns 0 on success.
763 qla24xx_chip_diag(scsi_qla_host_t *ha)
767 /* Perform RISC reset. */
768 qla24xx_reset_risc(ha);
770 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
772 rval = qla2x00_mbx_reg_test(ha);
774 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
776 qla_printk(KERN_WARNING, ha,
777 "Failed mailbox send register test\n");
779 /* Flag a successful rval */
787 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
790 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
796 qla_printk(KERN_WARNING, ha,
797 "Firmware dump previously allocated.\n");
802 fixed_size = mem_size = eft_size = 0;
803 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
804 fixed_size = sizeof(struct qla2100_fw_dump);
805 } else if (IS_QLA23XX(ha)) {
806 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
807 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
809 } else if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
810 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
811 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
814 /* Allocate memory for Extended Trace Buffer. */
815 eft = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &eft_dma,
818 qla_printk(KERN_WARNING, ha, "Unable to allocate "
819 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
823 rval = qla2x00_trace_control(ha, TC_ENABLE, eft_dma,
826 qla_printk(KERN_WARNING, ha, "Unable to initialize "
827 "EFT (%d).\n", rval);
828 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, eft,
833 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
837 memset(eft, 0, eft_size);
838 ha->eft_dma = eft_dma;
842 req_q_size = ha->request_q_length * sizeof(request_t);
843 rsp_q_size = ha->response_q_length * sizeof(response_t);
845 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
846 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
849 ha->fw_dump = vmalloc(dump_size);
851 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
852 "firmware dump!!!\n", dump_size / 1024);
855 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
863 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
866 ha->fw_dump_len = dump_size;
867 ha->fw_dump->signature[0] = 'Q';
868 ha->fw_dump->signature[1] = 'L';
869 ha->fw_dump->signature[2] = 'G';
870 ha->fw_dump->signature[3] = 'C';
871 ha->fw_dump->version = __constant_htonl(1);
873 ha->fw_dump->fixed_size = htonl(fixed_size);
874 ha->fw_dump->mem_size = htonl(mem_size);
875 ha->fw_dump->req_q_size = htonl(req_q_size);
876 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
878 ha->fw_dump->eft_size = htonl(eft_size);
879 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
880 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
882 ha->fw_dump->header_size =
883 htonl(offsetof(struct qla2xxx_fw_dump, isp));
887 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
890 * Returns 0 on success.
893 qla2x00_resize_request_q(scsi_qla_host_t *ha)
896 uint16_t fw_iocb_cnt = 0;
897 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
898 dma_addr_t request_dma;
899 request_t *request_ring;
901 /* Valid only on recent ISPs. */
902 if (IS_QLA2100(ha) || IS_QLA2200(ha))
905 /* Retrieve IOCB counts available to the firmware. */
906 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
909 /* No point in continuing if current settings are sufficient. */
910 if (fw_iocb_cnt < 1024)
912 if (ha->request_q_length >= request_q_length)
915 /* Attempt to claim larger area for request queue. */
916 request_ring = dma_alloc_coherent(&ha->pdev->dev,
917 (request_q_length + 1) * sizeof(request_t), &request_dma,
919 if (request_ring == NULL)
922 /* Resize successful, report extensions. */
923 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
924 (ha->fw_memory_size + 1) / 1024);
925 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
926 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
928 /* Clear old allocations. */
929 dma_free_coherent(&ha->pdev->dev,
930 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
933 /* Begin using larger queue. */
934 ha->request_q_length = request_q_length;
935 ha->request_ring = request_ring;
936 ha->request_dma = request_dma;
940 * qla2x00_setup_chip() - Load and start RISC firmware.
943 * Returns 0 on success.
946 qla2x00_setup_chip(scsi_qla_host_t *ha)
949 uint32_t srisc_address = 0;
951 /* Load firmware sequences */
952 rval = ha->isp_ops.load_risc(ha, &srisc_address);
953 if (rval == QLA_SUCCESS) {
954 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
955 "code.\n", ha->host_no));
957 rval = qla2x00_verify_checksum(ha, srisc_address);
958 if (rval == QLA_SUCCESS) {
959 /* Start firmware execution. */
960 DEBUG(printk("scsi(%ld): Checksum OK, start "
961 "firmware.\n", ha->host_no));
963 rval = qla2x00_execute_fw(ha, srisc_address);
964 /* Retrieve firmware information. */
965 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
966 qla2x00_get_fw_version(ha,
967 &ha->fw_major_version,
968 &ha->fw_minor_version,
969 &ha->fw_subminor_version,
970 &ha->fw_attributes, &ha->fw_memory_size);
971 qla2x00_resize_request_q(ha);
974 qla2x00_alloc_fw_dump(ha);
977 DEBUG2(printk(KERN_INFO
978 "scsi(%ld): ISP Firmware failed checksum.\n",
984 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
992 * qla2x00_init_response_q_entries() - Initializes response queue entries.
995 * Beginning of request ring has initialization control block already built
996 * by nvram config routine.
998 * Returns 0 on success.
1001 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
1006 pkt = ha->response_ring_ptr;
1007 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
1008 pkt->signature = RESPONSE_PROCESSED;
1015 * qla2x00_update_fw_options() - Read and process firmware options.
1018 * Returns 0 on success.
1021 qla2x00_update_fw_options(scsi_qla_host_t *ha)
1023 uint16_t swing, emphasis, tx_sens, rx_sens;
1025 memset(ha->fw_options, 0, sizeof(ha->fw_options));
1026 qla2x00_get_fw_options(ha, ha->fw_options);
1028 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1031 /* Serial Link options. */
1032 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1034 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1035 sizeof(ha->fw_seriallink_options)));
1037 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1038 if (ha->fw_seriallink_options[3] & BIT_2) {
1039 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1042 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1043 emphasis = (ha->fw_seriallink_options[2] &
1044 (BIT_4 | BIT_3)) >> 3;
1045 tx_sens = ha->fw_seriallink_options[0] &
1046 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1047 rx_sens = (ha->fw_seriallink_options[0] &
1048 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1049 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1050 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1053 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1054 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1055 ha->fw_options[10] |= BIT_5 |
1056 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1057 (tx_sens & (BIT_1 | BIT_0));
1060 swing = (ha->fw_seriallink_options[2] &
1061 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1062 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1063 tx_sens = ha->fw_seriallink_options[1] &
1064 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1065 rx_sens = (ha->fw_seriallink_options[1] &
1066 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1067 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1068 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1071 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1072 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1073 ha->fw_options[11] |= BIT_5 |
1074 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1075 (tx_sens & (BIT_1 | BIT_0));
1079 /* Return command IOCBs without waiting for an ABTS to complete. */
1080 ha->fw_options[3] |= BIT_13;
1083 if (ha->flags.enable_led_scheme)
1084 ha->fw_options[2] |= BIT_12;
1086 /* Detect ISP6312. */
1088 ha->fw_options[2] |= BIT_13;
1090 /* Update firmware options. */
1091 qla2x00_set_fw_options(ha, ha->fw_options);
1095 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1099 /* Update Serial Link options. */
1100 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1103 rval = qla2x00_set_serdes_params(ha,
1104 le16_to_cpu(ha->fw_seriallink_options24[1]),
1105 le16_to_cpu(ha->fw_seriallink_options24[2]),
1106 le16_to_cpu(ha->fw_seriallink_options24[3]));
1107 if (rval != QLA_SUCCESS) {
1108 qla_printk(KERN_WARNING, ha,
1109 "Unable to update Serial Link options (%x).\n", rval);
1114 qla2x00_config_rings(struct scsi_qla_host *ha)
1116 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1118 /* Setup ring parameters in initialization control block. */
1119 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1120 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1121 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1122 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1123 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1124 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1125 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1126 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1128 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1129 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1130 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1131 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1132 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1136 qla24xx_config_rings(struct scsi_qla_host *ha)
1138 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1139 struct init_cb_24xx *icb;
1141 /* Setup ring parameters in initialization control block. */
1142 icb = (struct init_cb_24xx *)ha->init_cb;
1143 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1144 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1145 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1146 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1147 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1148 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1149 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1150 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1152 WRT_REG_DWORD(®->req_q_in, 0);
1153 WRT_REG_DWORD(®->req_q_out, 0);
1154 WRT_REG_DWORD(®->rsp_q_in, 0);
1155 WRT_REG_DWORD(®->rsp_q_out, 0);
1156 RD_REG_DWORD(®->rsp_q_out);
1160 * qla2x00_init_rings() - Initializes firmware.
1163 * Beginning of request ring has initialization control block already built
1164 * by nvram config routine.
1166 * Returns 0 on success.
1169 qla2x00_init_rings(scsi_qla_host_t *ha)
1172 unsigned long flags = 0;
1175 spin_lock_irqsave(&ha->hardware_lock, flags);
1177 /* Clear outstanding commands array. */
1178 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1179 ha->outstanding_cmds[cnt] = NULL;
1181 ha->current_outstanding_cmd = 0;
1183 /* Clear RSCN queue. */
1184 ha->rscn_in_ptr = 0;
1185 ha->rscn_out_ptr = 0;
1187 /* Initialize firmware. */
1188 ha->request_ring_ptr = ha->request_ring;
1189 ha->req_ring_index = 0;
1190 ha->req_q_cnt = ha->request_q_length;
1191 ha->response_ring_ptr = ha->response_ring;
1192 ha->rsp_ring_index = 0;
1194 /* Initialize response queue entries */
1195 qla2x00_init_response_q_entries(ha);
1197 ha->isp_ops.config_rings(ha);
1199 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1201 /* Update any ISP specific firmware options before initialization. */
1202 ha->isp_ops.update_fw_options(ha);
1204 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1205 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1207 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1210 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1218 * qla2x00_fw_ready() - Waits for firmware ready.
1221 * Returns 0 on success.
1224 qla2x00_fw_ready(scsi_qla_host_t *ha)
1227 unsigned long wtime, mtime;
1228 uint16_t min_wait; /* Minimum wait time if loop is down */
1229 uint16_t wait_time; /* Wait time if loop is coming ready */
1234 /* 20 seconds for loop down. */
1238 * Firmware should take at most one RATOV to login, plus 5 seconds for
1239 * our own processing.
1241 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1242 wait_time = min_wait;
1245 /* Min wait time if loop down */
1246 mtime = jiffies + (min_wait * HZ);
1248 /* wait time before firmware ready */
1249 wtime = jiffies + (wait_time * HZ);
1251 /* Wait for ISP to finish LIP */
1252 if (!ha->flags.init_done)
1253 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1255 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1259 rval = qla2x00_get_firmware_state(ha, &fw_state);
1260 if (rval == QLA_SUCCESS) {
1261 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1262 ha->device_flags &= ~DFLG_NO_CABLE;
1264 if (fw_state == FSTATE_READY) {
1265 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1268 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1269 &ha->login_timeout, &ha->r_a_tov);
1275 rval = QLA_FUNCTION_FAILED;
1277 if (atomic_read(&ha->loop_down_timer) &&
1278 fw_state != FSTATE_READY) {
1279 /* Loop down. Timeout on min_wait for states
1280 * other than Wait for Login.
1282 if (time_after_eq(jiffies, mtime)) {
1283 qla_printk(KERN_INFO, ha,
1284 "Cable is unplugged...\n");
1286 ha->device_flags |= DFLG_NO_CABLE;
1291 /* Mailbox cmd failed. Timeout on min_wait. */
1292 if (time_after_eq(jiffies, mtime))
1296 if (time_after_eq(jiffies, wtime))
1299 /* Delay for a while */
1302 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1303 ha->host_no, fw_state, jiffies));
1306 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1307 ha->host_no, fw_state, jiffies));
1310 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1318 * qla2x00_configure_hba
1319 * Setup adapter context.
1322 * ha = adapter state pointer.
1331 qla2x00_configure_hba(scsi_qla_host_t *ha)
1339 char connect_type[22];
1341 /* Get host addresses. */
1342 rval = qla2x00_get_adapter_id(ha,
1343 &loop_id, &al_pa, &area, &domain, &topo);
1344 if (rval != QLA_SUCCESS) {
1345 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
1346 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1347 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1348 __func__, ha->host_no));
1350 qla_printk(KERN_WARNING, ha,
1351 "ERROR -- Unable to get host loop ID.\n");
1352 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1358 qla_printk(KERN_INFO, ha,
1359 "Cannot get topology - retrying.\n");
1360 return (QLA_FUNCTION_FAILED);
1363 ha->loop_id = loop_id;
1366 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1367 ha->operating_mode = LOOP;
1371 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1373 ha->current_topology = ISP_CFG_NL;
1374 strcpy(connect_type, "(Loop)");
1378 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1380 ha->current_topology = ISP_CFG_FL;
1381 strcpy(connect_type, "(FL_Port)");
1385 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1387 ha->operating_mode = P2P;
1388 ha->current_topology = ISP_CFG_N;
1389 strcpy(connect_type, "(N_Port-to-N_Port)");
1393 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1395 ha->operating_mode = P2P;
1396 ha->current_topology = ISP_CFG_F;
1397 strcpy(connect_type, "(F_Port)");
1401 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1403 ha->host_no, topo));
1404 ha->current_topology = ISP_CFG_NL;
1405 strcpy(connect_type, "(Loop)");
1409 /* Save Host port and loop ID. */
1410 /* byte order - Big Endian */
1411 ha->d_id.b.domain = domain;
1412 ha->d_id.b.area = area;
1413 ha->d_id.b.al_pa = al_pa;
1415 if (!ha->flags.init_done)
1416 qla_printk(KERN_INFO, ha,
1417 "Topology - %s, Host Loop address 0x%x\n",
1418 connect_type, ha->loop_id);
1421 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1423 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1430 * NVRAM configuration for ISP 2xxx
1433 * ha = adapter block pointer.
1436 * initialization control block in response_ring
1437 * host adapters parameters in host adapter block
1443 qla2x00_nvram_config(scsi_qla_host_t *ha)
1448 uint8_t *dptr1, *dptr2;
1449 init_cb_t *icb = ha->init_cb;
1450 nvram_t *nv = (nvram_t *)ha->request_ring;
1451 uint8_t *ptr = (uint8_t *)ha->request_ring;
1452 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1456 /* Determine NVRAM starting address. */
1457 ha->nvram_size = sizeof(nvram_t);
1459 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1460 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1461 ha->nvram_base = 0x80;
1463 /* Get NVRAM data and calculate checksum. */
1464 ha->isp_ops.read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1465 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1468 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1469 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1472 /* Bad NVRAM data, set defaults parameters. */
1473 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1474 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1475 /* Reset NVRAM data. */
1476 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1477 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1479 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1480 "invalid -- WWPN) defaults.\n");
1483 * Set default initialization control block.
1485 memset(nv, 0, ha->nvram_size);
1486 nv->parameter_block_version = ICB_VERSION;
1488 if (IS_QLA23XX(ha)) {
1489 nv->firmware_options[0] = BIT_2 | BIT_1;
1490 nv->firmware_options[1] = BIT_7 | BIT_5;
1491 nv->add_firmware_options[0] = BIT_5;
1492 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1493 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1494 nv->special_options[1] = BIT_7;
1495 } else if (IS_QLA2200(ha)) {
1496 nv->firmware_options[0] = BIT_2 | BIT_1;
1497 nv->firmware_options[1] = BIT_7 | BIT_5;
1498 nv->add_firmware_options[0] = BIT_5;
1499 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1500 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1501 } else if (IS_QLA2100(ha)) {
1502 nv->firmware_options[0] = BIT_3 | BIT_1;
1503 nv->firmware_options[1] = BIT_5;
1504 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1507 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1508 nv->execution_throttle = __constant_cpu_to_le16(16);
1509 nv->retry_count = 8;
1510 nv->retry_delay = 1;
1512 nv->port_name[0] = 33;
1513 nv->port_name[3] = 224;
1514 nv->port_name[4] = 139;
1516 nv->login_timeout = 4;
1519 * Set default host adapter parameters
1521 nv->host_p[1] = BIT_2;
1522 nv->reset_delay = 5;
1523 nv->port_down_retry_count = 8;
1524 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1525 nv->link_down_timeout = 60;
1530 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1532 * The SN2 does not provide BIOS emulation which means you can't change
1533 * potentially bogus BIOS settings. Force the use of default settings
1534 * for link rate and frame size. Hope that the rest of the settings
1537 if (ia64_platform_is("sn2")) {
1538 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1540 nv->special_options[1] = BIT_7;
1544 /* Reset Initialization control block */
1545 memset(icb, 0, ha->init_cb_size);
1548 * Setup driver NVRAM options.
1550 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1551 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1552 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1553 nv->firmware_options[1] &= ~BIT_4;
1555 if (IS_QLA23XX(ha)) {
1556 nv->firmware_options[0] |= BIT_2;
1557 nv->firmware_options[0] &= ~BIT_3;
1558 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1560 if (IS_QLA2300(ha)) {
1561 if (ha->fb_rev == FPM_2310) {
1562 strcpy(ha->model_number, "QLA2310");
1564 strcpy(ha->model_number, "QLA2300");
1568 memcmp(nv->model_number, BINZERO,
1569 sizeof(nv->model_number)) != 0) {
1572 strncpy(ha->model_number, nv->model_number,
1573 sizeof(nv->model_number));
1574 st = en = ha->model_number;
1575 en += sizeof(nv->model_number) - 1;
1577 if (*en != 0x20 && *en != 0x00)
1584 index = (ha->pdev->subsystem_device & 0xff);
1585 if (index < QLA_MODEL_NAMES) {
1586 strcpy(ha->model_number,
1587 qla2x00_model_name[index * 2]);
1589 qla2x00_model_name[index * 2 + 1];
1591 strcpy(ha->model_number, "QLA23xx");
1595 } else if (IS_QLA2200(ha)) {
1596 nv->firmware_options[0] |= BIT_2;
1598 * 'Point-to-point preferred, else loop' is not a safe
1599 * connection mode setting.
1601 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1603 /* Force 'loop preferred, else point-to-point'. */
1604 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1605 nv->add_firmware_options[0] |= BIT_5;
1607 strcpy(ha->model_number, "QLA22xx");
1608 } else /*if (IS_QLA2100(ha))*/ {
1609 strcpy(ha->model_number, "QLA2100");
1613 * Copy over NVRAM RISC parameter block to initialization control block.
1615 dptr1 = (uint8_t *)icb;
1616 dptr2 = (uint8_t *)&nv->parameter_block_version;
1617 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1619 *dptr1++ = *dptr2++;
1621 /* Copy 2nd half. */
1622 dptr1 = (uint8_t *)icb->add_firmware_options;
1623 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1625 *dptr1++ = *dptr2++;
1627 /* Use alternate WWN? */
1628 if (nv->host_p[1] & BIT_7) {
1629 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1630 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1633 /* Prepare nodename */
1634 if ((icb->firmware_options[1] & BIT_6) == 0) {
1636 * Firmware will apply the following mask if the nodename was
1639 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1640 icb->node_name[0] &= 0xF0;
1644 * Set host adapter parameters.
1646 if (nv->host_p[0] & BIT_7)
1647 extended_error_logging = 1;
1648 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1649 /* Always load RISC code on non ISP2[12]00 chips. */
1650 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1651 ha->flags.disable_risc_code_load = 0;
1652 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1653 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1654 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1655 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1656 ha->flags.disable_serdes = 0;
1658 ha->operating_mode =
1659 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1661 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1662 sizeof(ha->fw_seriallink_options));
1664 /* save HBA serial number */
1665 ha->serial0 = icb->port_name[5];
1666 ha->serial1 = icb->port_name[6];
1667 ha->serial2 = icb->port_name[7];
1668 ha->node_name = icb->node_name;
1669 ha->port_name = icb->port_name;
1671 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1673 ha->retry_count = nv->retry_count;
1675 /* Set minimum login_timeout to 4 seconds. */
1676 if (nv->login_timeout < ql2xlogintimeout)
1677 nv->login_timeout = ql2xlogintimeout;
1678 if (nv->login_timeout < 4)
1679 nv->login_timeout = 4;
1680 ha->login_timeout = nv->login_timeout;
1681 icb->login_timeout = nv->login_timeout;
1683 /* Set minimum RATOV to 200 tenths of a second. */
1686 ha->loop_reset_delay = nv->reset_delay;
1688 /* Link Down Timeout = 0:
1690 * When Port Down timer expires we will start returning
1691 * I/O's to OS with "DID_NO_CONNECT".
1693 * Link Down Timeout != 0:
1695 * The driver waits for the link to come up after link down
1696 * before returning I/Os to OS with "DID_NO_CONNECT".
1698 if (nv->link_down_timeout == 0) {
1699 ha->loop_down_abort_time =
1700 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1702 ha->link_down_timeout = nv->link_down_timeout;
1703 ha->loop_down_abort_time =
1704 (LOOP_DOWN_TIME - ha->link_down_timeout);
1708 * Need enough time to try and get the port back.
1710 ha->port_down_retry_count = nv->port_down_retry_count;
1711 if (qlport_down_retry)
1712 ha->port_down_retry_count = qlport_down_retry;
1713 /* Set login_retry_count */
1714 ha->login_retry_count = nv->retry_count;
1715 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1716 ha->port_down_retry_count > 3)
1717 ha->login_retry_count = ha->port_down_retry_count;
1718 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1719 ha->login_retry_count = ha->port_down_retry_count;
1720 if (ql2xloginretrycount)
1721 ha->login_retry_count = ql2xloginretrycount;
1723 icb->lun_enables = __constant_cpu_to_le16(0);
1724 icb->command_resource_count = 0;
1725 icb->immediate_notify_resource_count = 0;
1726 icb->timeout = __constant_cpu_to_le16(0);
1728 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1730 icb->firmware_options[0] &= ~BIT_3;
1731 icb->add_firmware_options[0] &=
1732 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1733 icb->add_firmware_options[0] |= BIT_2;
1734 icb->response_accumulation_timer = 3;
1735 icb->interrupt_delay_timer = 5;
1737 ha->flags.process_response_queue = 1;
1740 if (!ha->flags.init_done) {
1741 ha->zio_mode = icb->add_firmware_options[0] &
1742 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1743 ha->zio_timer = icb->interrupt_delay_timer ?
1744 icb->interrupt_delay_timer: 2;
1746 icb->add_firmware_options[0] &=
1747 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1748 ha->flags.process_response_queue = 0;
1749 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1750 ha->zio_mode = QLA_ZIO_MODE_6;
1752 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1753 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1754 ha->zio_timer * 100));
1755 qla_printk(KERN_INFO, ha,
1756 "ZIO mode %d enabled; timer delay (%d us).\n",
1757 ha->zio_mode, ha->zio_timer * 100);
1759 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1760 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1761 ha->flags.process_response_queue = 1;
1766 DEBUG2_3(printk(KERN_WARNING
1767 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1773 qla2x00_rport_del(void *data)
1775 fc_port_t *fcport = data;
1776 struct fc_rport *rport;
1777 unsigned long flags;
1779 spin_lock_irqsave(&fcport->rport_lock, flags);
1780 rport = fcport->drport;
1781 fcport->drport = NULL;
1782 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1784 fc_remote_port_delete(rport);
1789 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1791 * @flags: allocation flags
1793 * Returns a pointer to the allocated fcport, or NULL, if none available.
1796 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1800 fcport = kmalloc(sizeof(fc_port_t), flags);
1804 /* Setup fcport template structure. */
1805 memset(fcport, 0, sizeof (fc_port_t));
1807 fcport->port_type = FCT_UNKNOWN;
1808 fcport->loop_id = FC_NO_LOOP_ID;
1809 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1810 fcport->flags = FCF_RLC_SUPPORT;
1811 fcport->supported_classes = FC_COS_UNSPECIFIED;
1812 spin_lock_init(&fcport->rport_lock);
1818 * qla2x00_configure_loop
1819 * Updates Fibre Channel Device Database with what is actually on loop.
1822 * ha = adapter block pointer.
1827 * 2 = database was full and device was not configured.
1830 qla2x00_configure_loop(scsi_qla_host_t *ha)
1833 unsigned long flags, save_flags;
1837 /* Get Initiator ID */
1838 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1839 rval = qla2x00_configure_hba(ha);
1840 if (rval != QLA_SUCCESS) {
1841 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1847 save_flags = flags = ha->dpc_flags;
1848 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1849 ha->host_no, flags));
1852 * If we have both an RSCN and PORT UPDATE pending then handle them
1853 * both at the same time.
1855 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1856 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1858 /* Determine what we need to do */
1859 if (ha->current_topology == ISP_CFG_FL &&
1860 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1862 ha->flags.rscn_queue_overflow = 1;
1863 set_bit(RSCN_UPDATE, &flags);
1865 } else if (ha->current_topology == ISP_CFG_F &&
1866 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1868 ha->flags.rscn_queue_overflow = 1;
1869 set_bit(RSCN_UPDATE, &flags);
1870 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1872 } else if (ha->current_topology == ISP_CFG_N) {
1873 clear_bit(RSCN_UPDATE, &flags);
1875 } else if (!ha->flags.online ||
1876 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1878 ha->flags.rscn_queue_overflow = 1;
1879 set_bit(RSCN_UPDATE, &flags);
1880 set_bit(LOCAL_LOOP_UPDATE, &flags);
1883 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1884 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1885 rval = QLA_FUNCTION_FAILED;
1887 rval = qla2x00_configure_local_loop(ha);
1891 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1892 if (LOOP_TRANSITION(ha)) {
1893 rval = QLA_FUNCTION_FAILED;
1895 rval = qla2x00_configure_fabric(ha);
1899 if (rval == QLA_SUCCESS) {
1900 if (atomic_read(&ha->loop_down_timer) ||
1901 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1902 rval = QLA_FUNCTION_FAILED;
1904 atomic_set(&ha->loop_state, LOOP_READY);
1906 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1911 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1912 __func__, ha->host_no));
1914 DEBUG3(printk("%s: exiting normally\n", __func__));
1917 /* Restore state if a resync event occured during processing */
1918 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1919 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1920 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1921 if (test_bit(RSCN_UPDATE, &save_flags))
1922 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1931 * qla2x00_configure_local_loop
1932 * Updates Fibre Channel Device Database with local loop devices.
1935 * ha = adapter block pointer.
1941 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1946 fc_port_t *fcport, *new_fcport;
1952 uint8_t domain, area, al_pa;
1956 entries = MAX_FIBRE_DEVICES;
1958 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1959 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1961 /* Get list of logged in devices. */
1962 memset(ha->gid_list, 0, GID_LIST_SIZE);
1963 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1965 if (rval != QLA_SUCCESS)
1966 goto cleanup_allocation;
1968 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1969 ha->host_no, entries));
1970 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1971 entries * sizeof(struct gid_list_info)));
1973 /* Allocate temporary fcport for any new fcports discovered. */
1974 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1975 if (new_fcport == NULL) {
1976 rval = QLA_MEMORY_ALLOC_FAILED;
1977 goto cleanup_allocation;
1979 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1982 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1984 list_for_each_entry(fcport, &ha->fcports, list) {
1985 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1986 fcport->port_type != FCT_BROADCAST &&
1987 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1989 DEBUG(printk("scsi(%ld): Marking port lost, "
1991 ha->host_no, fcport->loop_id));
1993 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1994 fcport->flags &= ~FCF_FARP_DONE;
1998 /* Add devices to port list. */
1999 id_iter = (char *)ha->gid_list;
2000 for (index = 0; index < entries; index++) {
2001 domain = ((struct gid_list_info *)id_iter)->domain;
2002 area = ((struct gid_list_info *)id_iter)->area;
2003 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
2004 if (IS_QLA2100(ha) || IS_QLA2200(ha))
2005 loop_id = (uint16_t)
2006 ((struct gid_list_info *)id_iter)->loop_id_2100;
2008 loop_id = le16_to_cpu(
2009 ((struct gid_list_info *)id_iter)->loop_id);
2010 id_iter += ha->gid_list_info_size;
2012 /* Bypass reserved domain fields. */
2013 if ((domain & 0xf0) == 0xf0)
2016 /* Bypass if not same domain and area of adapter. */
2017 if (area && domain &&
2018 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
2021 /* Bypass invalid local loop ID. */
2022 if (loop_id > LAST_LOCAL_LOOP_ID)
2025 /* Fill in member data. */
2026 new_fcport->d_id.b.domain = domain;
2027 new_fcport->d_id.b.area = area;
2028 new_fcport->d_id.b.al_pa = al_pa;
2029 new_fcport->loop_id = loop_id;
2030 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
2031 if (rval2 != QLA_SUCCESS) {
2032 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2033 "information -- get_port_database=%x, "
2035 ha->host_no, rval2, new_fcport->loop_id));
2036 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2038 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2042 /* Check for matching device in port list. */
2045 list_for_each_entry(fcport, &ha->fcports, list) {
2046 if (memcmp(new_fcport->port_name, fcport->port_name,
2050 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2051 FCF_PERSISTENT_BOUND);
2052 fcport->loop_id = new_fcport->loop_id;
2053 fcport->port_type = new_fcport->port_type;
2054 fcport->d_id.b24 = new_fcport->d_id.b24;
2055 memcpy(fcport->node_name, new_fcport->node_name,
2063 /* New device, add to fcports list. */
2064 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
2065 list_add_tail(&new_fcport->list, &ha->fcports);
2067 /* Allocate a new replacement fcport. */
2068 fcport = new_fcport;
2069 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2070 if (new_fcport == NULL) {
2071 rval = QLA_MEMORY_ALLOC_FAILED;
2072 goto cleanup_allocation;
2074 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2077 qla2x00_update_fcport(ha, fcport);
2085 if (rval != QLA_SUCCESS) {
2086 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2087 "rval=%x\n", ha->host_no, rval));
2091 ha->device_flags |= DFLG_LOCAL_DEVICES;
2092 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2099 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
2103 qla2x00_mark_all_devices_lost(ha, 0);
2104 list_for_each_entry(fcport, &ha->fcports, list) {
2105 if (fcport->port_type != FCT_TARGET)
2108 qla2x00_update_fcport(ha, fcport);
2113 * qla2x00_update_fcport
2114 * Updates device on list.
2117 * ha = adapter block pointer.
2118 * fcport = port structure pointer.
2128 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2131 fcport->login_retry = 0;
2132 fcport->port_login_retry_count = ha->port_down_retry_count *
2134 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2136 fcport->flags &= ~FCF_LOGIN_NEEDED;
2138 atomic_set(&fcport->state, FCS_ONLINE);
2140 if (ha->flags.init_done)
2141 qla2x00_reg_remote_port(ha, fcport);
2145 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2147 struct fc_rport_identifiers rport_ids;
2148 struct fc_rport *rport;
2149 unsigned long flags;
2152 qla2x00_rport_del(fcport);
2156 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2157 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2158 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2159 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2160 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2161 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2163 qla_printk(KERN_WARNING, ha,
2164 "Unable to allocate fc remote port!\n");
2167 spin_lock_irqsave(&fcport->rport_lock, flags);
2168 fcport->rport = rport;
2169 *((fc_port_t **)rport->dd_data) = fcport;
2170 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2172 rport->supported_classes = fcport->supported_classes;
2174 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2175 if (fcport->port_type == FCT_INITIATOR)
2176 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2177 if (fcport->port_type == FCT_TARGET)
2178 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2179 fc_remote_port_rolechg(rport, rport_ids.roles);
2181 if (rport->scsi_target_id != -1 &&
2182 rport->scsi_target_id < ha->host->max_id)
2183 fcport->os_target_id = rport->scsi_target_id;
2187 * qla2x00_configure_fabric
2188 * Setup SNS devices with loop ID's.
2191 * ha = adapter block pointer.
2198 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2201 fc_port_t *fcport, *fcptemp;
2202 uint16_t next_loopid;
2203 uint16_t mb[MAILBOX_REGISTER_COUNT];
2205 LIST_HEAD(new_fcports);
2207 /* If FL port exists, then SNS is present */
2208 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2209 loop_id = NPH_F_PORT;
2211 loop_id = SNS_FL_PORT;
2212 rval = qla2x00_get_port_name(ha, loop_id, NULL, 0);
2213 if (rval != QLA_SUCCESS) {
2214 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2215 "Port\n", ha->host_no));
2217 ha->device_flags &= ~SWITCH_FOUND;
2218 return (QLA_SUCCESS);
2221 /* Mark devices that need re-synchronization. */
2222 rval2 = qla2x00_device_resync(ha);
2223 if (rval2 == QLA_RSCNS_HANDLED) {
2224 /* No point doing the scan, just continue. */
2225 return (QLA_SUCCESS);
2229 if (ql2xfdmienable &&
2230 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2231 qla2x00_fdmi_register(ha);
2233 /* Ensure we are logged into the SNS. */
2234 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2237 loop_id = SIMPLE_NAME_SERVER;
2238 ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
2239 0xfc, mb, BIT_1 | BIT_0);
2240 if (mb[0] != MBS_COMMAND_COMPLETE) {
2241 DEBUG2(qla_printk(KERN_INFO, ha,
2242 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2243 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2244 mb[0], mb[1], mb[2], mb[6], mb[7]));
2245 return (QLA_SUCCESS);
2248 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2249 if (qla2x00_rft_id(ha)) {
2251 DEBUG2(printk("scsi(%ld): Register FC-4 "
2252 "TYPE failed.\n", ha->host_no));
2254 if (qla2x00_rff_id(ha)) {
2256 DEBUG2(printk("scsi(%ld): Register FC-4 "
2257 "Features failed.\n", ha->host_no));
2259 if (qla2x00_rnn_id(ha)) {
2261 DEBUG2(printk("scsi(%ld): Register Node Name "
2262 "failed.\n", ha->host_no));
2263 } else if (qla2x00_rsnn_nn(ha)) {
2265 DEBUG2(printk("scsi(%ld): Register Symbolic "
2266 "Node Name failed.\n", ha->host_no));
2270 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2271 if (rval != QLA_SUCCESS)
2275 * Logout all previous fabric devices marked lost, except
2278 list_for_each_entry(fcport, &ha->fcports, list) {
2279 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2282 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2285 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2286 qla2x00_mark_device_lost(ha, fcport,
2287 ql2xplogiabsentdevice, 0);
2288 if (fcport->loop_id != FC_NO_LOOP_ID &&
2289 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2290 fcport->port_type != FCT_INITIATOR &&
2291 fcport->port_type != FCT_BROADCAST) {
2292 ha->isp_ops.fabric_logout(ha,
2294 fcport->d_id.b.domain,
2295 fcport->d_id.b.area,
2296 fcport->d_id.b.al_pa);
2297 fcport->loop_id = FC_NO_LOOP_ID;
2302 /* Starting free loop ID. */
2303 next_loopid = ha->min_external_loopid;
2306 * Scan through our port list and login entries that need to be
2309 list_for_each_entry(fcport, &ha->fcports, list) {
2310 if (atomic_read(&ha->loop_down_timer) ||
2311 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2314 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2315 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2318 if (fcport->loop_id == FC_NO_LOOP_ID) {
2319 fcport->loop_id = next_loopid;
2320 rval = qla2x00_find_new_loop_id(ha, fcport);
2321 if (rval != QLA_SUCCESS) {
2322 /* Ran out of IDs to use */
2326 /* Login and update database */
2327 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2330 /* Exit if out of loop IDs. */
2331 if (rval != QLA_SUCCESS) {
2336 * Login and add the new devices to our port list.
2338 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2339 if (atomic_read(&ha->loop_down_timer) ||
2340 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2343 /* Find a new loop ID to use. */
2344 fcport->loop_id = next_loopid;
2345 rval = qla2x00_find_new_loop_id(ha, fcport);
2346 if (rval != QLA_SUCCESS) {
2347 /* Ran out of IDs to use */
2351 /* Remove device from the new list and add it to DB */
2352 list_move_tail(&fcport->list, &ha->fcports);
2354 /* Login and update database */
2355 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2359 /* Free all new device structures not processed. */
2360 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2361 list_del(&fcport->list);
2366 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2367 "rval=%d\n", ha->host_no, rval));
2375 * qla2x00_find_all_fabric_devs
2378 * ha = adapter block pointer.
2379 * dev = database device entry pointer.
2388 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2392 fc_port_t *fcport, *new_fcport, *fcptemp;
2397 int first_dev, last_dev;
2398 port_id_t wrap, nxt_d_id;
2402 /* Try GID_PT to get device list, else GAN. */
2403 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2406 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2407 "on GA_NXT\n", ha->host_no));
2409 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2410 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2413 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2416 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2423 /* Allocate temporary fcport for any new fcports discovered. */
2424 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2425 if (new_fcport == NULL) {
2427 return (QLA_MEMORY_ALLOC_FAILED);
2429 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2431 /* Set start port ID scan at adapter ID. */
2435 /* Starting free loop ID. */
2436 loop_id = ha->min_external_loopid;
2437 for (; loop_id <= ha->last_loop_id; loop_id++) {
2438 if (qla2x00_is_reserved_id(ha, loop_id))
2441 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2446 wrap.b24 = new_fcport->d_id.b24;
2448 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2449 memcpy(new_fcport->node_name,
2450 swl[swl_idx].node_name, WWN_SIZE);
2451 memcpy(new_fcport->port_name,
2452 swl[swl_idx].port_name, WWN_SIZE);
2454 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2460 /* Send GA_NXT to the switch */
2461 rval = qla2x00_ga_nxt(ha, new_fcport);
2462 if (rval != QLA_SUCCESS) {
2463 qla_printk(KERN_WARNING, ha,
2464 "SNS scan failed -- assuming zero-entry "
2466 list_for_each_entry_safe(fcport, fcptemp,
2467 new_fcports, list) {
2468 list_del(&fcport->list);
2476 /* If wrap on switch device list, exit. */
2478 wrap.b24 = new_fcport->d_id.b24;
2480 } else if (new_fcport->d_id.b24 == wrap.b24) {
2481 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2482 ha->host_no, new_fcport->d_id.b.domain,
2483 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2487 /* Bypass if host adapter. */
2488 if (new_fcport->d_id.b24 == ha->d_id.b24)
2491 /* Bypass if same domain and area of adapter. */
2492 if (((new_fcport->d_id.b24 & 0xffff00) ==
2493 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2497 /* Bypass reserved domain fields. */
2498 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2501 /* Locate matching device in database. */
2503 list_for_each_entry(fcport, &ha->fcports, list) {
2504 if (memcmp(new_fcport->port_name, fcport->port_name,
2511 * If address the same and state FCS_ONLINE, nothing
2514 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2515 atomic_read(&fcport->state) == FCS_ONLINE) {
2520 * If device was not a fabric device before.
2522 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2523 fcport->d_id.b24 = new_fcport->d_id.b24;
2524 fcport->loop_id = FC_NO_LOOP_ID;
2525 fcport->flags |= (FCF_FABRIC_DEVICE |
2527 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2532 * Port ID changed or device was marked to be updated;
2533 * Log it out if still logged in and mark it for
2536 fcport->d_id.b24 = new_fcport->d_id.b24;
2537 fcport->flags |= FCF_LOGIN_NEEDED;
2538 if (fcport->loop_id != FC_NO_LOOP_ID &&
2539 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2540 fcport->port_type != FCT_INITIATOR &&
2541 fcport->port_type != FCT_BROADCAST) {
2542 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2543 fcport->d_id.b.domain, fcport->d_id.b.area,
2544 fcport->d_id.b.al_pa);
2545 fcport->loop_id = FC_NO_LOOP_ID;
2554 /* If device was not in our fcports list, then add it. */
2555 list_add_tail(&new_fcport->list, new_fcports);
2557 /* Allocate a new replacement fcport. */
2558 nxt_d_id.b24 = new_fcport->d_id.b24;
2559 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2560 if (new_fcport == NULL) {
2562 return (QLA_MEMORY_ALLOC_FAILED);
2564 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2565 new_fcport->d_id.b24 = nxt_d_id.b24;
2571 if (!list_empty(new_fcports))
2572 ha->device_flags |= DFLG_FABRIC_DEVICES;
2578 * qla2x00_find_new_loop_id
2579 * Scan through our port list and find a new usable loop ID.
2582 * ha: adapter state pointer.
2583 * dev: port structure pointer.
2586 * qla2x00 local function return status code.
2592 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2597 uint16_t first_loop_id;
2601 /* Save starting loop ID. */
2602 first_loop_id = dev->loop_id;
2605 /* Skip loop ID if already used by adapter. */
2606 if (dev->loop_id == ha->loop_id) {
2610 /* Skip reserved loop IDs. */
2611 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2615 /* Reset loop ID if passed the end. */
2616 if (dev->loop_id > ha->last_loop_id) {
2617 /* first loop ID. */
2618 dev->loop_id = ha->min_external_loopid;
2621 /* Check for loop ID being already in use. */
2624 list_for_each_entry(fcport, &ha->fcports, list) {
2625 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2626 /* ID possibly in use */
2632 /* If not in use then it is free to use. */
2637 /* ID in use. Try next value. */
2640 /* If wrap around. No free ID to use. */
2641 if (dev->loop_id == first_loop_id) {
2642 dev->loop_id = FC_NO_LOOP_ID;
2643 rval = QLA_FUNCTION_FAILED;
2652 * qla2x00_device_resync
2653 * Marks devices in the database that needs resynchronization.
2656 * ha = adapter block pointer.
2662 qla2x00_device_resync(scsi_qla_host_t *ha)
2667 uint32_t rscn_entry;
2668 uint8_t rscn_out_iter;
2672 rval = QLA_RSCNS_HANDLED;
2674 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2675 ha->flags.rscn_queue_overflow) {
2677 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2678 format = MSB(MSW(rscn_entry));
2679 d_id.b.domain = LSB(MSW(rscn_entry));
2680 d_id.b.area = MSB(LSW(rscn_entry));
2681 d_id.b.al_pa = LSB(LSW(rscn_entry));
2683 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2684 "[%02x/%02x%02x%02x].\n",
2685 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2686 d_id.b.area, d_id.b.al_pa));
2689 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2690 ha->rscn_out_ptr = 0;
2692 /* Skip duplicate entries. */
2693 for (rscn_out_iter = ha->rscn_out_ptr;
2694 !ha->flags.rscn_queue_overflow &&
2695 rscn_out_iter != ha->rscn_in_ptr;
2696 rscn_out_iter = (rscn_out_iter ==
2697 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2699 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2702 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2703 "entry found at [%d].\n", ha->host_no,
2706 ha->rscn_out_ptr = rscn_out_iter;
2709 /* Queue overflow, set switch default case. */
2710 if (ha->flags.rscn_queue_overflow) {
2711 DEBUG(printk("scsi(%ld): device_resync: rscn "
2712 "overflow.\n", ha->host_no));
2715 ha->flags.rscn_queue_overflow = 0;
2731 ha->rscn_out_ptr = ha->rscn_in_ptr;
2737 list_for_each_entry(fcport, &ha->fcports, list) {
2738 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2739 (fcport->d_id.b24 & mask) != d_id.b24 ||
2740 fcport->port_type == FCT_BROADCAST)
2743 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2745 fcport->port_type != FCT_INITIATOR) {
2746 qla2x00_mark_device_lost(ha, fcport,
2750 fcport->flags &= ~FCF_FARP_DONE;
2757 * qla2x00_fabric_dev_login
2758 * Login fabric target device and update FC port database.
2761 * ha: adapter state pointer.
2762 * fcport: port structure list pointer.
2763 * next_loopid: contains value of a new loop ID that can be used
2764 * by the next login attempt.
2767 * qla2x00 local function return status code.
2773 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2774 uint16_t *next_loopid)
2783 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2784 if (rval == QLA_SUCCESS) {
2785 /* Send an ADISC to tape devices.*/
2787 if (fcport->flags & FCF_TAPE_PRESENT)
2789 rval = qla2x00_get_port_database(ha, fcport, opts);
2790 if (rval != QLA_SUCCESS) {
2791 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2792 fcport->d_id.b.domain, fcport->d_id.b.area,
2793 fcport->d_id.b.al_pa);
2794 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2796 qla2x00_update_fcport(ha, fcport);
2804 * qla2x00_fabric_login
2805 * Issue fabric login command.
2808 * ha = adapter block pointer.
2809 * device = pointer to FC device type structure.
2812 * 0 - Login successfully
2814 * 2 - Initiator device
2818 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2819 uint16_t *next_loopid)
2823 uint16_t tmp_loopid;
2824 uint16_t mb[MAILBOX_REGISTER_COUNT];
2830 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2831 "for port %02x%02x%02x.\n",
2832 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2833 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2835 /* Login fcport on switch. */
2836 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2837 fcport->d_id.b.domain, fcport->d_id.b.area,
2838 fcport->d_id.b.al_pa, mb, BIT_0);
2839 if (mb[0] == MBS_PORT_ID_USED) {
2841 * Device has another loop ID. The firmware team
2842 * recommends the driver perform an implicit login with
2843 * the specified ID again. The ID we just used is save
2844 * here so we return with an ID that can be tried by
2848 tmp_loopid = fcport->loop_id;
2849 fcport->loop_id = mb[1];
2851 DEBUG(printk("Fabric Login: port in use - next "
2852 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2853 fcport->loop_id, fcport->d_id.b.domain,
2854 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2856 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2861 /* A retry occurred before. */
2862 *next_loopid = tmp_loopid;
2865 * No retry occurred before. Just increment the
2866 * ID value for next login.
2868 *next_loopid = (fcport->loop_id + 1);
2871 if (mb[1] & BIT_0) {
2872 fcport->port_type = FCT_INITIATOR;
2874 fcport->port_type = FCT_TARGET;
2875 if (mb[1] & BIT_1) {
2876 fcport->flags |= FCF_TAPE_PRESENT;
2881 fcport->supported_classes |= FC_COS_CLASS2;
2883 fcport->supported_classes |= FC_COS_CLASS3;
2887 } else if (mb[0] == MBS_LOOP_ID_USED) {
2889 * Loop ID already used, try next loop ID.
2892 rval = qla2x00_find_new_loop_id(ha, fcport);
2893 if (rval != QLA_SUCCESS) {
2894 /* Ran out of loop IDs to use */
2897 } else if (mb[0] == MBS_COMMAND_ERROR) {
2899 * Firmware possibly timed out during login. If NO
2900 * retries are left to do then the device is declared
2903 *next_loopid = fcport->loop_id;
2904 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2905 fcport->d_id.b.domain, fcport->d_id.b.area,
2906 fcport->d_id.b.al_pa);
2907 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2913 * unrecoverable / not handled error
2915 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2916 "loop_id=%x jiffies=%lx.\n",
2917 __func__, ha->host_no, mb[0],
2918 fcport->d_id.b.domain, fcport->d_id.b.area,
2919 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
2921 *next_loopid = fcport->loop_id;
2922 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2923 fcport->d_id.b.domain, fcport->d_id.b.area,
2924 fcport->d_id.b.al_pa);
2925 fcport->loop_id = FC_NO_LOOP_ID;
2926 fcport->login_retry = 0;
2937 * qla2x00_local_device_login
2938 * Issue local device login command.
2941 * ha = adapter block pointer.
2942 * loop_id = loop id of device to login to.
2944 * Returns (Where's the #define!!!!):
2945 * 0 - Login successfully
2950 qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
2953 uint16_t mb[MAILBOX_REGISTER_COUNT];
2955 memset(mb, 0, sizeof(mb));
2956 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
2957 if (rval == QLA_SUCCESS) {
2958 /* Interrogate mailbox registers for any errors */
2959 if (mb[0] == MBS_COMMAND_ERROR)
2961 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
2962 /* device not in PCB table */
2970 * qla2x00_loop_resync
2971 * Resync with fibre channel devices.
2974 * ha = adapter block pointer.
2980 qla2x00_loop_resync(scsi_qla_host_t *ha)
2987 atomic_set(&ha->loop_state, LOOP_UPDATE);
2988 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
2989 if (ha->flags.online) {
2990 if (!(rval = qla2x00_fw_ready(ha))) {
2991 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2994 atomic_set(&ha->loop_state, LOOP_UPDATE);
2996 /* Issue a marker after FW becomes ready. */
2997 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
2998 ha->marker_needed = 0;
3000 /* Remap devices on Loop. */
3001 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3003 qla2x00_configure_loop(ha);
3005 } while (!atomic_read(&ha->loop_down_timer) &&
3006 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3008 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3012 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3013 return (QLA_FUNCTION_FAILED);
3017 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3024 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
3030 list_for_each_entry(fcport, &ha->fcports, list) {
3031 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
3034 qla2x00_update_fcport(ha, fcport);
3035 fcport->flags &= ~FCF_RESCAN_NEEDED;
3039 qla2x00_probe_for_all_luns(ha);
3043 qla2x00_update_fcports(scsi_qla_host_t *ha)
3047 /* Go with deferred removal of rport references. */
3048 list_for_each_entry(fcport, &ha->fcports, list)
3050 qla2x00_rport_del(fcport);
3055 * Resets ISP and aborts all outstanding commands.
3058 * ha = adapter block pointer.
3064 qla2x00_abort_isp(scsi_qla_host_t *ha)
3066 unsigned long flags = 0;
3071 if (ha->flags.online) {
3072 ha->flags.online = 0;
3073 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3075 qla_printk(KERN_INFO, ha,
3076 "Performing ISP error recovery - ha= %p.\n", ha);
3077 ha->isp_ops.reset_chip(ha);
3079 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3080 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3081 atomic_set(&ha->loop_state, LOOP_DOWN);
3082 qla2x00_mark_all_devices_lost(ha, 0);
3084 if (!atomic_read(&ha->loop_down_timer))
3085 atomic_set(&ha->loop_down_timer,
3089 spin_lock_irqsave(&ha->hardware_lock, flags);
3090 /* Requeue all commands in outstanding command list. */
3091 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3092 sp = ha->outstanding_cmds[cnt];
3094 ha->outstanding_cmds[cnt] = NULL;
3096 sp->cmd->result = DID_RESET << 16;
3097 sp->cmd->host_scribble = (unsigned char *)NULL;
3098 qla2x00_sp_compl(ha, sp);
3101 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3103 ha->isp_ops.nvram_config(ha);
3105 if (!qla2x00_restart_isp(ha)) {
3106 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3108 if (!atomic_read(&ha->loop_down_timer)) {
3110 * Issue marker command only when we are going
3111 * to start the I/O .
3113 ha->marker_needed = 1;
3116 ha->flags.online = 1;
3118 ha->isp_ops.enable_intrs(ha);
3120 ha->isp_abort_cnt = 0;
3121 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3122 } else { /* failed the ISP abort */
3123 ha->flags.online = 1;
3124 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3125 if (ha->isp_abort_cnt == 0) {
3126 qla_printk(KERN_WARNING, ha,
3127 "ISP error recovery failed - "
3128 "board disabled\n");
3130 * The next call disables the board
3133 ha->isp_ops.reset_adapter(ha);
3134 ha->flags.online = 0;
3135 clear_bit(ISP_ABORT_RETRY,
3138 } else { /* schedule another ISP abort */
3139 ha->isp_abort_cnt--;
3140 DEBUG(printk("qla%ld: ISP abort - "
3141 "retry remaining %d\n",
3142 ha->host_no, ha->isp_abort_cnt));
3146 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3147 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3148 "- retrying (%d) more times\n",
3149 ha->host_no, ha->isp_abort_cnt));
3150 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3158 qla_printk(KERN_INFO, ha,
3159 "qla2x00_abort_isp: **** FAILED ****\n");
3161 DEBUG(printk(KERN_INFO
3162 "qla2x00_abort_isp(%ld): exiting.\n",
3170 * qla2x00_restart_isp
3171 * restarts the ISP after a reset
3174 * ha = adapter block pointer.
3180 qla2x00_restart_isp(scsi_qla_host_t *ha)
3183 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3184 unsigned long flags = 0;
3187 /* If firmware needs to be loaded */
3188 if (qla2x00_isp_firmware(ha)) {
3189 ha->flags.online = 0;
3190 if (!(status = ha->isp_ops.chip_diag(ha))) {
3191 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3192 status = qla2x00_setup_chip(ha);
3196 spin_lock_irqsave(&ha->hardware_lock, flags);
3198 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3200 * Disable SRAM, Instruction RAM and GP RAM
3203 WRT_REG_WORD(®->hccr,
3204 (HCCR_ENABLE_PARITY + 0x0));
3205 RD_REG_WORD(®->hccr);
3208 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3210 status = qla2x00_setup_chip(ha);
3212 spin_lock_irqsave(&ha->hardware_lock, flags);
3214 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3215 /* Enable proper parity */
3218 WRT_REG_WORD(®->hccr,
3219 (HCCR_ENABLE_PARITY + 0x1));
3222 * SRAM, Instruction RAM and GP RAM
3225 WRT_REG_WORD(®->hccr,
3226 (HCCR_ENABLE_PARITY + 0x7));
3227 RD_REG_WORD(®->hccr);
3230 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3235 if (!status && !(status = qla2x00_init_rings(ha))) {
3236 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3237 if (!(status = qla2x00_fw_ready(ha))) {
3238 DEBUG(printk("%s(): Start configure loop, "
3239 "status = %d\n", __func__, status));
3241 /* Issue a marker after FW becomes ready. */
3242 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3244 ha->flags.online = 1;
3245 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3248 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3249 qla2x00_configure_loop(ha);
3251 } while (!atomic_read(&ha->loop_down_timer) &&
3252 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3254 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3257 /* if no cable then assume it's good */
3258 if ((ha->device_flags & DFLG_NO_CABLE))
3261 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3269 * qla2x00_reset_adapter
3273 * ha = adapter block pointer.
3276 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3278 unsigned long flags = 0;
3279 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3281 ha->flags.online = 0;
3282 ha->isp_ops.disable_intrs(ha);
3284 spin_lock_irqsave(&ha->hardware_lock, flags);
3285 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3286 RD_REG_WORD(®->hccr); /* PCI Posting. */
3287 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3288 RD_REG_WORD(®->hccr); /* PCI Posting. */
3289 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3293 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3295 unsigned long flags = 0;
3296 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3298 ha->flags.online = 0;
3299 ha->isp_ops.disable_intrs(ha);
3301 spin_lock_irqsave(&ha->hardware_lock, flags);
3302 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3303 RD_REG_DWORD(®->hccr);
3304 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3305 RD_REG_DWORD(®->hccr);
3306 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3310 qla24xx_nvram_config(scsi_qla_host_t *ha)
3313 struct init_cb_24xx *icb;
3314 struct nvram_24xx *nv;
3316 uint8_t *dptr1, *dptr2;
3321 icb = (struct init_cb_24xx *)ha->init_cb;
3322 nv = (struct nvram_24xx *)ha->request_ring;
3324 /* Determine NVRAM starting address. */
3325 ha->nvram_size = sizeof(struct nvram_24xx);
3326 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3327 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3328 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3329 if (PCI_FUNC(ha->pdev->devfn)) {
3330 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3331 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3334 /* Get NVRAM data and calculate checksum. */
3335 dptr = (uint32_t *)nv;
3336 ha->isp_ops.read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3338 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3339 chksum += le32_to_cpu(*dptr++);
3341 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3342 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3345 /* Bad NVRAM data, set defaults parameters. */
3346 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3347 || nv->id[3] != ' ' ||
3348 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3349 /* Reset NVRAM data. */
3350 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3351 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3352 le16_to_cpu(nv->nvram_version));
3353 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3354 "invalid -- WWPN) defaults.\n");
3357 * Set default initialization control block.
3359 memset(nv, 0, ha->nvram_size);
3360 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3361 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3362 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3363 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3364 nv->exchange_count = __constant_cpu_to_le16(0);
3365 nv->hard_address = __constant_cpu_to_le16(124);
3366 nv->port_name[0] = 0x21;
3367 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3368 nv->port_name[2] = 0x00;
3369 nv->port_name[3] = 0xe0;
3370 nv->port_name[4] = 0x8b;
3371 nv->port_name[5] = 0x1c;
3372 nv->port_name[6] = 0x55;
3373 nv->port_name[7] = 0x86;
3374 nv->node_name[0] = 0x20;
3375 nv->node_name[1] = 0x00;
3376 nv->node_name[2] = 0x00;
3377 nv->node_name[3] = 0xe0;
3378 nv->node_name[4] = 0x8b;
3379 nv->node_name[5] = 0x1c;
3380 nv->node_name[6] = 0x55;
3381 nv->node_name[7] = 0x86;
3382 nv->login_retry_count = __constant_cpu_to_le16(8);
3383 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3384 nv->login_timeout = __constant_cpu_to_le16(0);
3385 nv->firmware_options_1 =
3386 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3387 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3388 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3389 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3390 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3391 nv->efi_parameters = __constant_cpu_to_le32(0);
3392 nv->reset_delay = 5;
3393 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3394 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3395 nv->link_down_timeout = __constant_cpu_to_le16(30);
3400 /* Reset Initialization control block */
3401 memset(icb, 0, sizeof(struct init_cb_24xx));
3403 /* Copy 1st segment. */
3404 dptr1 = (uint8_t *)icb;
3405 dptr2 = (uint8_t *)&nv->version;
3406 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3408 *dptr1++ = *dptr2++;
3410 icb->login_retry_count = nv->login_retry_count;
3411 icb->link_down_on_nos = nv->link_down_on_nos;
3413 /* Copy 2nd segment. */
3414 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3415 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3416 cnt = (uint8_t *)&icb->reserved_3 -
3417 (uint8_t *)&icb->interrupt_delay_timer;
3419 *dptr1++ = *dptr2++;
3422 * Setup driver NVRAM options.
3424 if (memcmp(nv->model_name, BINZERO, sizeof(nv->model_name)) != 0) {
3428 strncpy(ha->model_number, nv->model_name,
3429 sizeof(nv->model_name));
3430 st = en = ha->model_number;
3431 en += sizeof(nv->model_name) - 1;
3433 if (*en != 0x20 && *en != 0x00)
3438 index = (ha->pdev->subsystem_device & 0xff);
3439 if (index < QLA_MODEL_NAMES)
3440 ha->model_desc = qla2x00_model_name[index * 2 + 1];
3442 strcpy(ha->model_number, "QLA2462");
3444 /* Use alternate WWN? */
3445 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3446 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3447 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3450 /* Prepare nodename */
3451 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3453 * Firmware will apply the following mask if the nodename was
3456 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3457 icb->node_name[0] &= 0xF0;
3460 /* Set host adapter parameters. */
3461 ha->flags.disable_risc_code_load = 0;
3462 ha->flags.enable_lip_reset = 1;
3463 ha->flags.enable_lip_full_login = 1;
3464 ha->flags.enable_target_reset = 1;
3465 ha->flags.enable_led_scheme = 0;
3466 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
3468 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3469 (BIT_6 | BIT_5 | BIT_4)) >> 4;
3471 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3472 sizeof(ha->fw_seriallink_options24));
3474 /* save HBA serial number */
3475 ha->serial0 = icb->port_name[5];
3476 ha->serial1 = icb->port_name[6];
3477 ha->serial2 = icb->port_name[7];
3478 ha->node_name = icb->node_name;
3479 ha->port_name = icb->port_name;
3481 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3483 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3485 /* Set minimum login_timeout to 4 seconds. */
3486 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3487 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3488 if (le16_to_cpu(nv->login_timeout) < 4)
3489 nv->login_timeout = __constant_cpu_to_le16(4);
3490 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3491 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3493 /* Set minimum RATOV to 200 tenths of a second. */
3496 ha->loop_reset_delay = nv->reset_delay;
3498 /* Link Down Timeout = 0:
3500 * When Port Down timer expires we will start returning
3501 * I/O's to OS with "DID_NO_CONNECT".
3503 * Link Down Timeout != 0:
3505 * The driver waits for the link to come up after link down
3506 * before returning I/Os to OS with "DID_NO_CONNECT".
3508 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3509 ha->loop_down_abort_time =
3510 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3512 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3513 ha->loop_down_abort_time =
3514 (LOOP_DOWN_TIME - ha->link_down_timeout);
3517 /* Need enough time to try and get the port back. */
3518 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3519 if (qlport_down_retry)
3520 ha->port_down_retry_count = qlport_down_retry;
3522 /* Set login_retry_count */
3523 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3524 if (ha->port_down_retry_count ==
3525 le16_to_cpu(nv->port_down_retry_count) &&
3526 ha->port_down_retry_count > 3)
3527 ha->login_retry_count = ha->port_down_retry_count;
3528 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3529 ha->login_retry_count = ha->port_down_retry_count;
3530 if (ql2xloginretrycount)
3531 ha->login_retry_count = ql2xloginretrycount;
3534 if (!ha->flags.init_done) {
3535 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3536 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3537 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3538 le16_to_cpu(icb->interrupt_delay_timer): 2;
3540 icb->firmware_options_2 &= __constant_cpu_to_le32(
3541 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3542 ha->flags.process_response_queue = 0;
3543 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3544 ha->zio_mode = QLA_ZIO_MODE_6;
3546 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3547 "(%d us).\n", ha->host_no, ha->zio_mode,
3548 ha->zio_timer * 100));
3549 qla_printk(KERN_INFO, ha,
3550 "ZIO mode %d enabled; timer delay (%d us).\n",
3551 ha->zio_mode, ha->zio_timer * 100);
3553 icb->firmware_options_2 |= cpu_to_le32(
3554 (uint32_t)ha->zio_mode);
3555 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3556 ha->flags.process_response_queue = 1;
3560 DEBUG2_3(printk(KERN_WARNING
3561 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3567 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3570 int segments, fragment;
3572 uint32_t *dcode, dlen;
3579 segments = FA_RISC_CODE_SEGMENTS;
3580 faddr = FA_RISC_CODE_ADDR;
3581 dcode = (uint32_t *)ha->request_ring;
3584 /* Validate firmware image by checking version. */
3585 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3586 for (i = 0; i < 4; i++)
3587 dcode[i] = be32_to_cpu(dcode[i]);
3588 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3589 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3590 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3592 qla_printk(KERN_WARNING, ha,
3593 "Unable to verify integrity of flash firmware image!\n");
3594 qla_printk(KERN_WARNING, ha,
3595 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3596 dcode[1], dcode[2], dcode[3]);
3598 return QLA_FUNCTION_FAILED;
3601 while (segments && rval == QLA_SUCCESS) {
3602 /* Read segment's load information. */
3603 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3605 risc_addr = be32_to_cpu(dcode[2]);
3606 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3607 risc_size = be32_to_cpu(dcode[3]);
3610 while (risc_size > 0 && rval == QLA_SUCCESS) {
3611 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3612 if (dlen > risc_size)
3615 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3616 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3617 ha->host_no, risc_addr, dlen, faddr));
3619 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3620 for (i = 0; i < dlen; i++)
3621 dcode[i] = swab32(dcode[i]);
3623 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3626 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3627 "segment %d of firmware\n", ha->host_no,
3629 qla_printk(KERN_WARNING, ha,
3630 "[ERROR] Failed to load segment %d of "
3631 "firmware\n", fragment);
3648 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3651 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3655 uint16_t *wcode, *fwcode;
3656 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3657 struct fw_blob *blob;
3659 /* Load firmware blob. */
3660 blob = qla2x00_request_firmware(ha);
3662 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3663 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3664 "from: " QLA_FW_URL ".\n");
3665 return QLA_FUNCTION_FAILED;
3670 wcode = (uint16_t *)ha->request_ring;
3672 fwcode = (uint16_t *)blob->fw->data;
3675 /* Validate firmware image by checking version. */
3676 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3677 qla_printk(KERN_WARNING, ha,
3678 "Unable to verify integrity of firmware image (%Zd)!\n",
3680 goto fail_fw_integrity;
3682 for (i = 0; i < 4; i++)
3683 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3684 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3685 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3686 wcode[2] == 0 && wcode[3] == 0)) {
3687 qla_printk(KERN_WARNING, ha,
3688 "Unable to verify integrity of firmware image!\n");
3689 qla_printk(KERN_WARNING, ha,
3690 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3691 wcode[1], wcode[2], wcode[3]);
3692 goto fail_fw_integrity;
3696 while (*seg && rval == QLA_SUCCESS) {
3698 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3699 risc_size = be16_to_cpu(fwcode[3]);
3701 /* Validate firmware image size. */
3702 fwclen += risc_size * sizeof(uint16_t);
3703 if (blob->fw->size < fwclen) {
3704 qla_printk(KERN_WARNING, ha,
3705 "Unable to verify integrity of firmware image "
3706 "(%Zd)!\n", blob->fw->size);
3707 goto fail_fw_integrity;
3711 while (risc_size > 0 && rval == QLA_SUCCESS) {
3712 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3713 if (wlen > risc_size)
3716 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3717 "addr %x, number of words 0x%x.\n", ha->host_no,
3720 for (i = 0; i < wlen; i++)
3721 wcode[i] = swab16(fwcode[i]);
3723 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3726 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3727 "segment %d of firmware\n", ha->host_no,
3729 qla_printk(KERN_WARNING, ha,
3730 "[ERROR] Failed to load segment %d of "
3731 "firmware\n", fragment);
3747 return QLA_FUNCTION_FAILED;
3751 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3754 int segments, fragment;
3755 uint32_t *dcode, dlen;
3759 struct fw_blob *blob;
3760 uint32_t *fwcode, fwclen;
3762 /* Load firmware blob. */
3763 blob = qla2x00_request_firmware(ha);
3765 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3766 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3767 "from: " QLA_FW_URL ".\n");
3769 /* Try to load RISC code from flash. */
3770 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3771 "outdated) firmware from flash.\n");
3772 return qla24xx_load_risc_flash(ha, srisc_addr);
3777 segments = FA_RISC_CODE_SEGMENTS;
3778 dcode = (uint32_t *)ha->request_ring;
3780 fwcode = (uint32_t *)blob->fw->data;
3783 /* Validate firmware image by checking version. */
3784 if (blob->fw->size < 8 * sizeof(uint32_t)) {
3785 qla_printk(KERN_WARNING, ha,
3786 "Unable to verify integrity of firmware image (%Zd)!\n",
3788 goto fail_fw_integrity;
3790 for (i = 0; i < 4; i++)
3791 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3792 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3793 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3794 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3796 qla_printk(KERN_WARNING, ha,
3797 "Unable to verify integrity of firmware image!\n");
3798 qla_printk(KERN_WARNING, ha,
3799 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3800 dcode[1], dcode[2], dcode[3]);
3801 goto fail_fw_integrity;
3804 while (segments && rval == QLA_SUCCESS) {
3805 risc_addr = be32_to_cpu(fwcode[2]);
3806 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3807 risc_size = be32_to_cpu(fwcode[3]);
3809 /* Validate firmware image size. */
3810 fwclen += risc_size * sizeof(uint32_t);
3811 if (blob->fw->size < fwclen) {
3812 qla_printk(KERN_WARNING, ha,
3813 "Unable to verify integrity of firmware image "
3814 "(%Zd)!\n", blob->fw->size);
3816 goto fail_fw_integrity;
3820 while (risc_size > 0 && rval == QLA_SUCCESS) {
3821 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3822 if (dlen > risc_size)
3825 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3826 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3829 for (i = 0; i < dlen; i++)
3830 dcode[i] = swab32(fwcode[i]);
3832 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3835 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3836 "segment %d of firmware\n", ha->host_no,
3838 qla_printk(KERN_WARNING, ha,
3839 "[ERROR] Failed to load segment %d of "
3840 "firmware\n", fragment);
3856 return QLA_FUNCTION_FAILED;