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 /* Base iIDMA settings on HBA port speed. */
2078 switch (ha->link_data_rate) {
2079 case PORT_SPEED_1GB:
2080 fcport->fp_speed = cpu_to_be16(BIT_15);
2082 case PORT_SPEED_2GB:
2083 fcport->fp_speed = cpu_to_be16(BIT_14);
2085 case PORT_SPEED_4GB:
2086 fcport->fp_speed = cpu_to_be16(BIT_13);
2090 qla2x00_update_fcport(ha, fcport);
2098 if (rval != QLA_SUCCESS) {
2099 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2100 "rval=%x\n", ha->host_no, rval));
2104 ha->device_flags |= DFLG_LOCAL_DEVICES;
2105 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2112 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
2116 qla2x00_mark_all_devices_lost(ha, 0);
2117 list_for_each_entry(fcport, &ha->fcports, list) {
2118 if (fcport->port_type != FCT_TARGET)
2121 qla2x00_update_fcport(ha, fcport);
2126 qla2x00_iidma_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2128 #define LS_UNKNOWN 2
2129 static char *link_speeds[5] = { "1", "2", "?", "4" };
2131 uint16_t port_speed, mb[6];
2133 if (!IS_QLA24XX(ha))
2136 switch (be16_to_cpu(fcport->fp_speed)) {
2138 port_speed = PORT_SPEED_1GB;
2141 port_speed = PORT_SPEED_2GB;
2144 port_speed = PORT_SPEED_4GB;
2147 DEBUG2(printk("scsi(%ld): %02x%02x%02x%02x%02x%02x%02x%02x -- "
2148 "unsupported FM port operating speed (%04x).\n",
2149 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2150 fcport->port_name[2], fcport->port_name[3],
2151 fcport->port_name[4], fcport->port_name[5],
2152 fcport->port_name[6], fcport->port_name[7],
2153 be16_to_cpu(fcport->fp_speed)));
2154 port_speed = PORT_SPEED_UNKNOWN;
2157 if (port_speed == PORT_SPEED_UNKNOWN)
2160 rval = qla2x00_set_idma_speed(ha, fcport->loop_id, port_speed, mb);
2161 if (rval != QLA_SUCCESS) {
2162 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2163 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2164 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2165 fcport->port_name[2], fcport->port_name[3],
2166 fcport->port_name[4], fcport->port_name[5],
2167 fcport->port_name[6], fcport->port_name[7], rval,
2168 port_speed, mb[0], mb[1]));
2170 DEBUG2(qla_printk(KERN_INFO, ha,
2171 "iIDMA adjusted to %s GB/s on "
2172 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2173 link_speeds[port_speed], fcport->port_name[0],
2174 fcport->port_name[1], fcport->port_name[2],
2175 fcport->port_name[3], fcport->port_name[4],
2176 fcport->port_name[5], fcport->port_name[6],
2177 fcport->port_name[7]));
2182 * qla2x00_update_fcport
2183 * Updates device on list.
2186 * ha = adapter block pointer.
2187 * fcport = port structure pointer.
2197 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2200 fcport->login_retry = 0;
2201 fcport->port_login_retry_count = ha->port_down_retry_count *
2203 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2205 fcport->flags &= ~FCF_LOGIN_NEEDED;
2207 qla2x00_iidma_fcport(ha, fcport);
2209 atomic_set(&fcport->state, FCS_ONLINE);
2211 if (ha->flags.init_done)
2212 qla2x00_reg_remote_port(ha, fcport);
2216 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2218 struct fc_rport_identifiers rport_ids;
2219 struct fc_rport *rport;
2220 unsigned long flags;
2223 qla2x00_rport_del(fcport);
2227 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2228 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2229 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2230 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2231 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2232 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2234 qla_printk(KERN_WARNING, ha,
2235 "Unable to allocate fc remote port!\n");
2238 spin_lock_irqsave(&fcport->rport_lock, flags);
2239 fcport->rport = rport;
2240 *((fc_port_t **)rport->dd_data) = fcport;
2241 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2243 rport->supported_classes = fcport->supported_classes;
2245 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2246 if (fcport->port_type == FCT_INITIATOR)
2247 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2248 if (fcport->port_type == FCT_TARGET)
2249 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2250 fc_remote_port_rolechg(rport, rport_ids.roles);
2252 if (rport->scsi_target_id != -1 &&
2253 rport->scsi_target_id < ha->host->max_id)
2254 fcport->os_target_id = rport->scsi_target_id;
2258 * qla2x00_configure_fabric
2259 * Setup SNS devices with loop ID's.
2262 * ha = adapter block pointer.
2269 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2272 fc_port_t *fcport, *fcptemp;
2273 uint16_t next_loopid;
2274 uint16_t mb[MAILBOX_REGISTER_COUNT];
2276 LIST_HEAD(new_fcports);
2278 /* If FL port exists, then SNS is present */
2279 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2280 loop_id = NPH_F_PORT;
2282 loop_id = SNS_FL_PORT;
2283 rval = qla2x00_get_port_name(ha, loop_id, ha->fabric_node_name, 1);
2284 if (rval != QLA_SUCCESS) {
2285 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2286 "Port\n", ha->host_no));
2288 ha->device_flags &= ~SWITCH_FOUND;
2289 return (QLA_SUCCESS);
2291 ha->device_flags |= SWITCH_FOUND;
2293 /* Mark devices that need re-synchronization. */
2294 rval2 = qla2x00_device_resync(ha);
2295 if (rval2 == QLA_RSCNS_HANDLED) {
2296 /* No point doing the scan, just continue. */
2297 return (QLA_SUCCESS);
2301 if (ql2xfdmienable &&
2302 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2303 qla2x00_fdmi_register(ha);
2305 /* Ensure we are logged into the SNS. */
2306 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
2309 loop_id = SIMPLE_NAME_SERVER;
2310 ha->isp_ops.fabric_login(ha, loop_id, 0xff, 0xff,
2311 0xfc, mb, BIT_1 | BIT_0);
2312 if (mb[0] != MBS_COMMAND_COMPLETE) {
2313 DEBUG2(qla_printk(KERN_INFO, ha,
2314 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2315 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2316 mb[0], mb[1], mb[2], mb[6], mb[7]));
2317 return (QLA_SUCCESS);
2320 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2321 if (qla2x00_rft_id(ha)) {
2323 DEBUG2(printk("scsi(%ld): Register FC-4 "
2324 "TYPE failed.\n", ha->host_no));
2326 if (qla2x00_rff_id(ha)) {
2328 DEBUG2(printk("scsi(%ld): Register FC-4 "
2329 "Features failed.\n", ha->host_no));
2331 if (qla2x00_rnn_id(ha)) {
2333 DEBUG2(printk("scsi(%ld): Register Node Name "
2334 "failed.\n", ha->host_no));
2335 } else if (qla2x00_rsnn_nn(ha)) {
2337 DEBUG2(printk("scsi(%ld): Register Symbolic "
2338 "Node Name failed.\n", ha->host_no));
2342 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2343 if (rval != QLA_SUCCESS)
2347 * Logout all previous fabric devices marked lost, except
2350 list_for_each_entry(fcport, &ha->fcports, list) {
2351 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2354 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2357 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2358 qla2x00_mark_device_lost(ha, fcport,
2359 ql2xplogiabsentdevice, 0);
2360 if (fcport->loop_id != FC_NO_LOOP_ID &&
2361 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2362 fcport->port_type != FCT_INITIATOR &&
2363 fcport->port_type != FCT_BROADCAST) {
2364 ha->isp_ops.fabric_logout(ha,
2366 fcport->d_id.b.domain,
2367 fcport->d_id.b.area,
2368 fcport->d_id.b.al_pa);
2369 fcport->loop_id = FC_NO_LOOP_ID;
2374 /* Starting free loop ID. */
2375 next_loopid = ha->min_external_loopid;
2378 * Scan through our port list and login entries that need to be
2381 list_for_each_entry(fcport, &ha->fcports, list) {
2382 if (atomic_read(&ha->loop_down_timer) ||
2383 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2386 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2387 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2390 if (fcport->loop_id == FC_NO_LOOP_ID) {
2391 fcport->loop_id = next_loopid;
2392 rval = qla2x00_find_new_loop_id(ha, fcport);
2393 if (rval != QLA_SUCCESS) {
2394 /* Ran out of IDs to use */
2398 /* Login and update database */
2399 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2402 /* Exit if out of loop IDs. */
2403 if (rval != QLA_SUCCESS) {
2408 * Login and add the new devices to our port list.
2410 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2411 if (atomic_read(&ha->loop_down_timer) ||
2412 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2415 /* Find a new loop ID to use. */
2416 fcport->loop_id = next_loopid;
2417 rval = qla2x00_find_new_loop_id(ha, fcport);
2418 if (rval != QLA_SUCCESS) {
2419 /* Ran out of IDs to use */
2423 /* Remove device from the new list and add it to DB */
2424 list_move_tail(&fcport->list, &ha->fcports);
2426 /* Login and update database */
2427 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2431 /* Free all new device structures not processed. */
2432 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2433 list_del(&fcport->list);
2438 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2439 "rval=%d\n", ha->host_no, rval));
2447 * qla2x00_find_all_fabric_devs
2450 * ha = adapter block pointer.
2451 * dev = database device entry pointer.
2460 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2464 fc_port_t *fcport, *new_fcport, *fcptemp;
2469 int first_dev, last_dev;
2470 port_id_t wrap, nxt_d_id;
2474 /* Try GID_PT to get device list, else GAN. */
2475 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2478 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2479 "on GA_NXT\n", ha->host_no));
2481 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2482 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2485 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2488 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2491 } else if (qla2x00_gfpn_id(ha, swl) == QLA_SUCCESS) {
2492 qla2x00_gpsc(ha, swl);
2497 /* Allocate temporary fcport for any new fcports discovered. */
2498 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2499 if (new_fcport == NULL) {
2501 return (QLA_MEMORY_ALLOC_FAILED);
2503 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2505 /* Set start port ID scan at adapter ID. */
2509 /* Starting free loop ID. */
2510 loop_id = ha->min_external_loopid;
2511 for (; loop_id <= ha->last_loop_id; loop_id++) {
2512 if (qla2x00_is_reserved_id(ha, loop_id))
2515 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2520 wrap.b24 = new_fcport->d_id.b24;
2522 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2523 memcpy(new_fcport->node_name,
2524 swl[swl_idx].node_name, WWN_SIZE);
2525 memcpy(new_fcport->port_name,
2526 swl[swl_idx].port_name, WWN_SIZE);
2527 memcpy(new_fcport->fabric_port_name,
2528 swl[swl_idx].fabric_port_name, WWN_SIZE);
2529 new_fcport->fp_speed = swl[swl_idx].fp_speed;
2531 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2537 /* Send GA_NXT to the switch */
2538 rval = qla2x00_ga_nxt(ha, new_fcport);
2539 if (rval != QLA_SUCCESS) {
2540 qla_printk(KERN_WARNING, ha,
2541 "SNS scan failed -- assuming zero-entry "
2543 list_for_each_entry_safe(fcport, fcptemp,
2544 new_fcports, list) {
2545 list_del(&fcport->list);
2553 /* If wrap on switch device list, exit. */
2555 wrap.b24 = new_fcport->d_id.b24;
2557 } else if (new_fcport->d_id.b24 == wrap.b24) {
2558 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2559 ha->host_no, new_fcport->d_id.b.domain,
2560 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2564 /* Bypass if host adapter. */
2565 if (new_fcport->d_id.b24 == ha->d_id.b24)
2568 /* Bypass if same domain and area of adapter. */
2569 if (((new_fcport->d_id.b24 & 0xffff00) ==
2570 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2574 /* Bypass reserved domain fields. */
2575 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2578 /* Locate matching device in database. */
2580 list_for_each_entry(fcport, &ha->fcports, list) {
2581 if (memcmp(new_fcport->port_name, fcport->port_name,
2587 /* Update port state. */
2588 memcpy(fcport->fabric_port_name,
2589 new_fcport->fabric_port_name, WWN_SIZE);
2590 fcport->fp_speed = new_fcport->fp_speed;
2593 * If address the same and state FCS_ONLINE, nothing
2596 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2597 atomic_read(&fcport->state) == FCS_ONLINE) {
2602 * If device was not a fabric device before.
2604 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2605 fcport->d_id.b24 = new_fcport->d_id.b24;
2606 fcport->loop_id = FC_NO_LOOP_ID;
2607 fcport->flags |= (FCF_FABRIC_DEVICE |
2609 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2614 * Port ID changed or device was marked to be updated;
2615 * Log it out if still logged in and mark it for
2618 fcport->d_id.b24 = new_fcport->d_id.b24;
2619 fcport->flags |= FCF_LOGIN_NEEDED;
2620 if (fcport->loop_id != FC_NO_LOOP_ID &&
2621 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2622 fcport->port_type != FCT_INITIATOR &&
2623 fcport->port_type != FCT_BROADCAST) {
2624 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2625 fcport->d_id.b.domain, fcport->d_id.b.area,
2626 fcport->d_id.b.al_pa);
2627 fcport->loop_id = FC_NO_LOOP_ID;
2636 /* If device was not in our fcports list, then add it. */
2637 list_add_tail(&new_fcport->list, new_fcports);
2639 /* Allocate a new replacement fcport. */
2640 nxt_d_id.b24 = new_fcport->d_id.b24;
2641 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2642 if (new_fcport == NULL) {
2644 return (QLA_MEMORY_ALLOC_FAILED);
2646 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2647 new_fcport->d_id.b24 = nxt_d_id.b24;
2653 if (!list_empty(new_fcports))
2654 ha->device_flags |= DFLG_FABRIC_DEVICES;
2660 * qla2x00_find_new_loop_id
2661 * Scan through our port list and find a new usable loop ID.
2664 * ha: adapter state pointer.
2665 * dev: port structure pointer.
2668 * qla2x00 local function return status code.
2674 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2679 uint16_t first_loop_id;
2683 /* Save starting loop ID. */
2684 first_loop_id = dev->loop_id;
2687 /* Skip loop ID if already used by adapter. */
2688 if (dev->loop_id == ha->loop_id) {
2692 /* Skip reserved loop IDs. */
2693 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2697 /* Reset loop ID if passed the end. */
2698 if (dev->loop_id > ha->last_loop_id) {
2699 /* first loop ID. */
2700 dev->loop_id = ha->min_external_loopid;
2703 /* Check for loop ID being already in use. */
2706 list_for_each_entry(fcport, &ha->fcports, list) {
2707 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2708 /* ID possibly in use */
2714 /* If not in use then it is free to use. */
2719 /* ID in use. Try next value. */
2722 /* If wrap around. No free ID to use. */
2723 if (dev->loop_id == first_loop_id) {
2724 dev->loop_id = FC_NO_LOOP_ID;
2725 rval = QLA_FUNCTION_FAILED;
2734 * qla2x00_device_resync
2735 * Marks devices in the database that needs resynchronization.
2738 * ha = adapter block pointer.
2744 qla2x00_device_resync(scsi_qla_host_t *ha)
2749 uint32_t rscn_entry;
2750 uint8_t rscn_out_iter;
2754 rval = QLA_RSCNS_HANDLED;
2756 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2757 ha->flags.rscn_queue_overflow) {
2759 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2760 format = MSB(MSW(rscn_entry));
2761 d_id.b.domain = LSB(MSW(rscn_entry));
2762 d_id.b.area = MSB(LSW(rscn_entry));
2763 d_id.b.al_pa = LSB(LSW(rscn_entry));
2765 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2766 "[%02x/%02x%02x%02x].\n",
2767 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2768 d_id.b.area, d_id.b.al_pa));
2771 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2772 ha->rscn_out_ptr = 0;
2774 /* Skip duplicate entries. */
2775 for (rscn_out_iter = ha->rscn_out_ptr;
2776 !ha->flags.rscn_queue_overflow &&
2777 rscn_out_iter != ha->rscn_in_ptr;
2778 rscn_out_iter = (rscn_out_iter ==
2779 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2781 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2784 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2785 "entry found at [%d].\n", ha->host_no,
2788 ha->rscn_out_ptr = rscn_out_iter;
2791 /* Queue overflow, set switch default case. */
2792 if (ha->flags.rscn_queue_overflow) {
2793 DEBUG(printk("scsi(%ld): device_resync: rscn "
2794 "overflow.\n", ha->host_no));
2797 ha->flags.rscn_queue_overflow = 0;
2813 ha->rscn_out_ptr = ha->rscn_in_ptr;
2819 list_for_each_entry(fcport, &ha->fcports, list) {
2820 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2821 (fcport->d_id.b24 & mask) != d_id.b24 ||
2822 fcport->port_type == FCT_BROADCAST)
2825 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2827 fcport->port_type != FCT_INITIATOR) {
2828 qla2x00_mark_device_lost(ha, fcport,
2832 fcport->flags &= ~FCF_FARP_DONE;
2839 * qla2x00_fabric_dev_login
2840 * Login fabric target device and update FC port database.
2843 * ha: adapter state pointer.
2844 * fcport: port structure list pointer.
2845 * next_loopid: contains value of a new loop ID that can be used
2846 * by the next login attempt.
2849 * qla2x00 local function return status code.
2855 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2856 uint16_t *next_loopid)
2865 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2866 if (rval == QLA_SUCCESS) {
2867 /* Send an ADISC to tape devices.*/
2869 if (fcport->flags & FCF_TAPE_PRESENT)
2871 rval = qla2x00_get_port_database(ha, fcport, opts);
2872 if (rval != QLA_SUCCESS) {
2873 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2874 fcport->d_id.b.domain, fcport->d_id.b.area,
2875 fcport->d_id.b.al_pa);
2876 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2878 qla2x00_update_fcport(ha, fcport);
2886 * qla2x00_fabric_login
2887 * Issue fabric login command.
2890 * ha = adapter block pointer.
2891 * device = pointer to FC device type structure.
2894 * 0 - Login successfully
2896 * 2 - Initiator device
2900 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2901 uint16_t *next_loopid)
2905 uint16_t tmp_loopid;
2906 uint16_t mb[MAILBOX_REGISTER_COUNT];
2912 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2913 "for port %02x%02x%02x.\n",
2914 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2915 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2917 /* Login fcport on switch. */
2918 ha->isp_ops.fabric_login(ha, fcport->loop_id,
2919 fcport->d_id.b.domain, fcport->d_id.b.area,
2920 fcport->d_id.b.al_pa, mb, BIT_0);
2921 if (mb[0] == MBS_PORT_ID_USED) {
2923 * Device has another loop ID. The firmware team
2924 * recommends the driver perform an implicit login with
2925 * the specified ID again. The ID we just used is save
2926 * here so we return with an ID that can be tried by
2930 tmp_loopid = fcport->loop_id;
2931 fcport->loop_id = mb[1];
2933 DEBUG(printk("Fabric Login: port in use - next "
2934 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2935 fcport->loop_id, fcport->d_id.b.domain,
2936 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2938 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2943 /* A retry occurred before. */
2944 *next_loopid = tmp_loopid;
2947 * No retry occurred before. Just increment the
2948 * ID value for next login.
2950 *next_loopid = (fcport->loop_id + 1);
2953 if (mb[1] & BIT_0) {
2954 fcport->port_type = FCT_INITIATOR;
2956 fcport->port_type = FCT_TARGET;
2957 if (mb[1] & BIT_1) {
2958 fcport->flags |= FCF_TAPE_PRESENT;
2963 fcport->supported_classes |= FC_COS_CLASS2;
2965 fcport->supported_classes |= FC_COS_CLASS3;
2969 } else if (mb[0] == MBS_LOOP_ID_USED) {
2971 * Loop ID already used, try next loop ID.
2974 rval = qla2x00_find_new_loop_id(ha, fcport);
2975 if (rval != QLA_SUCCESS) {
2976 /* Ran out of loop IDs to use */
2979 } else if (mb[0] == MBS_COMMAND_ERROR) {
2981 * Firmware possibly timed out during login. If NO
2982 * retries are left to do then the device is declared
2985 *next_loopid = fcport->loop_id;
2986 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
2987 fcport->d_id.b.domain, fcport->d_id.b.area,
2988 fcport->d_id.b.al_pa);
2989 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2995 * unrecoverable / not handled error
2997 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2998 "loop_id=%x jiffies=%lx.\n",
2999 __func__, ha->host_no, mb[0],
3000 fcport->d_id.b.domain, fcport->d_id.b.area,
3001 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3003 *next_loopid = fcport->loop_id;
3004 ha->isp_ops.fabric_logout(ha, fcport->loop_id,
3005 fcport->d_id.b.domain, fcport->d_id.b.area,
3006 fcport->d_id.b.al_pa);
3007 fcport->loop_id = FC_NO_LOOP_ID;
3008 fcport->login_retry = 0;
3019 * qla2x00_local_device_login
3020 * Issue local device login command.
3023 * ha = adapter block pointer.
3024 * loop_id = loop id of device to login to.
3026 * Returns (Where's the #define!!!!):
3027 * 0 - Login successfully
3032 qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
3035 uint16_t mb[MAILBOX_REGISTER_COUNT];
3037 memset(mb, 0, sizeof(mb));
3038 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
3039 if (rval == QLA_SUCCESS) {
3040 /* Interrogate mailbox registers for any errors */
3041 if (mb[0] == MBS_COMMAND_ERROR)
3043 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3044 /* device not in PCB table */
3052 * qla2x00_loop_resync
3053 * Resync with fibre channel devices.
3056 * ha = adapter block pointer.
3062 qla2x00_loop_resync(scsi_qla_host_t *ha)
3069 atomic_set(&ha->loop_state, LOOP_UPDATE);
3070 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3071 if (ha->flags.online) {
3072 if (!(rval = qla2x00_fw_ready(ha))) {
3073 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3076 atomic_set(&ha->loop_state, LOOP_UPDATE);
3078 /* Issue a marker after FW becomes ready. */
3079 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3080 ha->marker_needed = 0;
3082 /* Remap devices on Loop. */
3083 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3085 qla2x00_configure_loop(ha);
3087 } while (!atomic_read(&ha->loop_down_timer) &&
3088 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3090 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3094 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3095 return (QLA_FUNCTION_FAILED);
3099 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3106 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
3112 list_for_each_entry(fcport, &ha->fcports, list) {
3113 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
3116 qla2x00_update_fcport(ha, fcport);
3117 fcport->flags &= ~FCF_RESCAN_NEEDED;
3121 qla2x00_probe_for_all_luns(ha);
3125 qla2x00_update_fcports(scsi_qla_host_t *ha)
3129 /* Go with deferred removal of rport references. */
3130 list_for_each_entry(fcport, &ha->fcports, list)
3132 qla2x00_rport_del(fcport);
3137 * Resets ISP and aborts all outstanding commands.
3140 * ha = adapter block pointer.
3146 qla2x00_abort_isp(scsi_qla_host_t *ha)
3149 unsigned long flags = 0;
3154 if (ha->flags.online) {
3155 ha->flags.online = 0;
3156 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3158 qla_printk(KERN_INFO, ha,
3159 "Performing ISP error recovery - ha= %p.\n", ha);
3160 ha->isp_ops.reset_chip(ha);
3162 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3163 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3164 atomic_set(&ha->loop_state, LOOP_DOWN);
3165 qla2x00_mark_all_devices_lost(ha, 0);
3167 if (!atomic_read(&ha->loop_down_timer))
3168 atomic_set(&ha->loop_down_timer,
3172 spin_lock_irqsave(&ha->hardware_lock, flags);
3173 /* Requeue all commands in outstanding command list. */
3174 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3175 sp = ha->outstanding_cmds[cnt];
3177 ha->outstanding_cmds[cnt] = NULL;
3179 sp->cmd->result = DID_RESET << 16;
3180 sp->cmd->host_scribble = (unsigned char *)NULL;
3181 qla2x00_sp_compl(ha, sp);
3184 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3186 ha->isp_ops.nvram_config(ha);
3188 if (!qla2x00_restart_isp(ha)) {
3189 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3191 if (!atomic_read(&ha->loop_down_timer)) {
3193 * Issue marker command only when we are going
3194 * to start the I/O .
3196 ha->marker_needed = 1;
3199 ha->flags.online = 1;
3201 ha->isp_ops.enable_intrs(ha);
3203 ha->isp_abort_cnt = 0;
3204 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3207 rval = qla2x00_trace_control(ha, TC_ENABLE,
3208 ha->eft_dma, EFT_NUM_BUFFERS);
3210 qla_printk(KERN_WARNING, ha,
3211 "Unable to reinitialize EFT "
3215 } else { /* failed the ISP abort */
3216 ha->flags.online = 1;
3217 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3218 if (ha->isp_abort_cnt == 0) {
3219 qla_printk(KERN_WARNING, ha,
3220 "ISP error recovery failed - "
3221 "board disabled\n");
3223 * The next call disables the board
3226 ha->isp_ops.reset_adapter(ha);
3227 ha->flags.online = 0;
3228 clear_bit(ISP_ABORT_RETRY,
3231 } else { /* schedule another ISP abort */
3232 ha->isp_abort_cnt--;
3233 DEBUG(printk("qla%ld: ISP abort - "
3234 "retry remaining %d\n",
3235 ha->host_no, ha->isp_abort_cnt));
3239 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3240 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3241 "- retrying (%d) more times\n",
3242 ha->host_no, ha->isp_abort_cnt));
3243 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3251 qla_printk(KERN_INFO, ha,
3252 "qla2x00_abort_isp: **** FAILED ****\n");
3254 DEBUG(printk(KERN_INFO
3255 "qla2x00_abort_isp(%ld): exiting.\n",
3263 * qla2x00_restart_isp
3264 * restarts the ISP after a reset
3267 * ha = adapter block pointer.
3273 qla2x00_restart_isp(scsi_qla_host_t *ha)
3276 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3277 unsigned long flags = 0;
3280 /* If firmware needs to be loaded */
3281 if (qla2x00_isp_firmware(ha)) {
3282 ha->flags.online = 0;
3283 if (!(status = ha->isp_ops.chip_diag(ha))) {
3284 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3285 status = qla2x00_setup_chip(ha);
3289 spin_lock_irqsave(&ha->hardware_lock, flags);
3291 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3293 * Disable SRAM, Instruction RAM and GP RAM
3296 WRT_REG_WORD(®->hccr,
3297 (HCCR_ENABLE_PARITY + 0x0));
3298 RD_REG_WORD(®->hccr);
3301 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3303 status = qla2x00_setup_chip(ha);
3305 spin_lock_irqsave(&ha->hardware_lock, flags);
3307 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3308 /* Enable proper parity */
3311 WRT_REG_WORD(®->hccr,
3312 (HCCR_ENABLE_PARITY + 0x1));
3315 * SRAM, Instruction RAM and GP RAM
3318 WRT_REG_WORD(®->hccr,
3319 (HCCR_ENABLE_PARITY + 0x7));
3320 RD_REG_WORD(®->hccr);
3323 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3328 if (!status && !(status = qla2x00_init_rings(ha))) {
3329 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3330 if (!(status = qla2x00_fw_ready(ha))) {
3331 DEBUG(printk("%s(): Start configure loop, "
3332 "status = %d\n", __func__, status));
3334 /* Issue a marker after FW becomes ready. */
3335 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3337 ha->flags.online = 1;
3338 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3341 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3342 qla2x00_configure_loop(ha);
3344 } while (!atomic_read(&ha->loop_down_timer) &&
3345 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3347 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3350 /* if no cable then assume it's good */
3351 if ((ha->device_flags & DFLG_NO_CABLE))
3354 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3362 * qla2x00_reset_adapter
3366 * ha = adapter block pointer.
3369 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3371 unsigned long flags = 0;
3372 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3374 ha->flags.online = 0;
3375 ha->isp_ops.disable_intrs(ha);
3377 spin_lock_irqsave(&ha->hardware_lock, flags);
3378 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3379 RD_REG_WORD(®->hccr); /* PCI Posting. */
3380 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3381 RD_REG_WORD(®->hccr); /* PCI Posting. */
3382 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3386 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3388 unsigned long flags = 0;
3389 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3391 ha->flags.online = 0;
3392 ha->isp_ops.disable_intrs(ha);
3394 spin_lock_irqsave(&ha->hardware_lock, flags);
3395 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3396 RD_REG_DWORD(®->hccr);
3397 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3398 RD_REG_DWORD(®->hccr);
3399 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3403 qla24xx_nvram_config(scsi_qla_host_t *ha)
3406 struct init_cb_24xx *icb;
3407 struct nvram_24xx *nv;
3409 uint8_t *dptr1, *dptr2;
3414 icb = (struct init_cb_24xx *)ha->init_cb;
3415 nv = (struct nvram_24xx *)ha->request_ring;
3417 /* Determine NVRAM starting address. */
3418 ha->nvram_size = sizeof(struct nvram_24xx);
3419 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3420 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3421 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3422 if (PCI_FUNC(ha->pdev->devfn)) {
3423 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3424 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3427 /* Get NVRAM data and calculate checksum. */
3428 dptr = (uint32_t *)nv;
3429 ha->isp_ops.read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3431 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3432 chksum += le32_to_cpu(*dptr++);
3434 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3435 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3438 /* Bad NVRAM data, set defaults parameters. */
3439 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3440 || nv->id[3] != ' ' ||
3441 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3442 /* Reset NVRAM data. */
3443 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3444 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3445 le16_to_cpu(nv->nvram_version));
3446 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3447 "invalid -- WWPN) defaults.\n");
3450 * Set default initialization control block.
3452 memset(nv, 0, ha->nvram_size);
3453 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3454 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3455 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3456 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3457 nv->exchange_count = __constant_cpu_to_le16(0);
3458 nv->hard_address = __constant_cpu_to_le16(124);
3459 nv->port_name[0] = 0x21;
3460 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3461 nv->port_name[2] = 0x00;
3462 nv->port_name[3] = 0xe0;
3463 nv->port_name[4] = 0x8b;
3464 nv->port_name[5] = 0x1c;
3465 nv->port_name[6] = 0x55;
3466 nv->port_name[7] = 0x86;
3467 nv->node_name[0] = 0x20;
3468 nv->node_name[1] = 0x00;
3469 nv->node_name[2] = 0x00;
3470 nv->node_name[3] = 0xe0;
3471 nv->node_name[4] = 0x8b;
3472 nv->node_name[5] = 0x1c;
3473 nv->node_name[6] = 0x55;
3474 nv->node_name[7] = 0x86;
3475 nv->login_retry_count = __constant_cpu_to_le16(8);
3476 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3477 nv->login_timeout = __constant_cpu_to_le16(0);
3478 nv->firmware_options_1 =
3479 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3480 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3481 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3482 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3483 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3484 nv->efi_parameters = __constant_cpu_to_le32(0);
3485 nv->reset_delay = 5;
3486 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3487 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3488 nv->link_down_timeout = __constant_cpu_to_le16(30);
3493 /* Reset Initialization control block */
3494 memset(icb, 0, sizeof(struct init_cb_24xx));
3496 /* Copy 1st segment. */
3497 dptr1 = (uint8_t *)icb;
3498 dptr2 = (uint8_t *)&nv->version;
3499 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3501 *dptr1++ = *dptr2++;
3503 icb->login_retry_count = nv->login_retry_count;
3504 icb->link_down_on_nos = nv->link_down_on_nos;
3506 /* Copy 2nd segment. */
3507 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3508 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3509 cnt = (uint8_t *)&icb->reserved_3 -
3510 (uint8_t *)&icb->interrupt_delay_timer;
3512 *dptr1++ = *dptr2++;
3515 * Setup driver NVRAM options.
3517 if (memcmp(nv->model_name, BINZERO, sizeof(nv->model_name)) != 0) {
3521 strncpy(ha->model_number, nv->model_name,
3522 sizeof(nv->model_name));
3523 st = en = ha->model_number;
3524 en += sizeof(nv->model_name) - 1;
3526 if (*en != 0x20 && *en != 0x00)
3531 index = (ha->pdev->subsystem_device & 0xff);
3532 if (index < QLA_MODEL_NAMES)
3533 ha->model_desc = qla2x00_model_name[index * 2 + 1];
3535 strcpy(ha->model_number, "QLA2462");
3537 /* Use alternate WWN? */
3538 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3539 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3540 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3543 /* Prepare nodename */
3544 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3546 * Firmware will apply the following mask if the nodename was
3549 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3550 icb->node_name[0] &= 0xF0;
3553 /* Set host adapter parameters. */
3554 ha->flags.disable_risc_code_load = 0;
3555 ha->flags.enable_lip_reset = 1;
3556 ha->flags.enable_lip_full_login = 1;
3557 ha->flags.enable_target_reset = 1;
3558 ha->flags.enable_led_scheme = 0;
3559 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
3561 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3562 (BIT_6 | BIT_5 | BIT_4)) >> 4;
3564 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3565 sizeof(ha->fw_seriallink_options24));
3567 /* save HBA serial number */
3568 ha->serial0 = icb->port_name[5];
3569 ha->serial1 = icb->port_name[6];
3570 ha->serial2 = icb->port_name[7];
3571 ha->node_name = icb->node_name;
3572 ha->port_name = icb->port_name;
3574 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3576 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3578 /* Set minimum login_timeout to 4 seconds. */
3579 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3580 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3581 if (le16_to_cpu(nv->login_timeout) < 4)
3582 nv->login_timeout = __constant_cpu_to_le16(4);
3583 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3584 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3586 /* Set minimum RATOV to 200 tenths of a second. */
3589 ha->loop_reset_delay = nv->reset_delay;
3591 /* Link Down Timeout = 0:
3593 * When Port Down timer expires we will start returning
3594 * I/O's to OS with "DID_NO_CONNECT".
3596 * Link Down Timeout != 0:
3598 * The driver waits for the link to come up after link down
3599 * before returning I/Os to OS with "DID_NO_CONNECT".
3601 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3602 ha->loop_down_abort_time =
3603 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3605 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3606 ha->loop_down_abort_time =
3607 (LOOP_DOWN_TIME - ha->link_down_timeout);
3610 /* Need enough time to try and get the port back. */
3611 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3612 if (qlport_down_retry)
3613 ha->port_down_retry_count = qlport_down_retry;
3615 /* Set login_retry_count */
3616 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3617 if (ha->port_down_retry_count ==
3618 le16_to_cpu(nv->port_down_retry_count) &&
3619 ha->port_down_retry_count > 3)
3620 ha->login_retry_count = ha->port_down_retry_count;
3621 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3622 ha->login_retry_count = ha->port_down_retry_count;
3623 if (ql2xloginretrycount)
3624 ha->login_retry_count = ql2xloginretrycount;
3627 if (!ha->flags.init_done) {
3628 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3629 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3630 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3631 le16_to_cpu(icb->interrupt_delay_timer): 2;
3633 icb->firmware_options_2 &= __constant_cpu_to_le32(
3634 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3635 ha->flags.process_response_queue = 0;
3636 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3637 ha->zio_mode = QLA_ZIO_MODE_6;
3639 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3640 "(%d us).\n", ha->host_no, ha->zio_mode,
3641 ha->zio_timer * 100));
3642 qla_printk(KERN_INFO, ha,
3643 "ZIO mode %d enabled; timer delay (%d us).\n",
3644 ha->zio_mode, ha->zio_timer * 100);
3646 icb->firmware_options_2 |= cpu_to_le32(
3647 (uint32_t)ha->zio_mode);
3648 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3649 ha->flags.process_response_queue = 1;
3653 DEBUG2_3(printk(KERN_WARNING
3654 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3660 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3663 int segments, fragment;
3665 uint32_t *dcode, dlen;
3672 segments = FA_RISC_CODE_SEGMENTS;
3673 faddr = FA_RISC_CODE_ADDR;
3674 dcode = (uint32_t *)ha->request_ring;
3677 /* Validate firmware image by checking version. */
3678 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3679 for (i = 0; i < 4; i++)
3680 dcode[i] = be32_to_cpu(dcode[i]);
3681 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3682 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3683 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3685 qla_printk(KERN_WARNING, ha,
3686 "Unable to verify integrity of flash firmware image!\n");
3687 qla_printk(KERN_WARNING, ha,
3688 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3689 dcode[1], dcode[2], dcode[3]);
3691 return QLA_FUNCTION_FAILED;
3694 while (segments && rval == QLA_SUCCESS) {
3695 /* Read segment's load information. */
3696 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3698 risc_addr = be32_to_cpu(dcode[2]);
3699 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3700 risc_size = be32_to_cpu(dcode[3]);
3703 while (risc_size > 0 && rval == QLA_SUCCESS) {
3704 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3705 if (dlen > risc_size)
3708 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3709 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3710 ha->host_no, risc_addr, dlen, faddr));
3712 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3713 for (i = 0; i < dlen; i++)
3714 dcode[i] = swab32(dcode[i]);
3716 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3719 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3720 "segment %d of firmware\n", ha->host_no,
3722 qla_printk(KERN_WARNING, ha,
3723 "[ERROR] Failed to load segment %d of "
3724 "firmware\n", fragment);
3741 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3744 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3748 uint16_t *wcode, *fwcode;
3749 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3750 struct fw_blob *blob;
3752 /* Load firmware blob. */
3753 blob = qla2x00_request_firmware(ha);
3755 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3756 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3757 "from: " QLA_FW_URL ".\n");
3758 return QLA_FUNCTION_FAILED;
3763 wcode = (uint16_t *)ha->request_ring;
3765 fwcode = (uint16_t *)blob->fw->data;
3768 /* Validate firmware image by checking version. */
3769 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3770 qla_printk(KERN_WARNING, ha,
3771 "Unable to verify integrity of firmware image (%Zd)!\n",
3773 goto fail_fw_integrity;
3775 for (i = 0; i < 4; i++)
3776 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3777 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3778 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3779 wcode[2] == 0 && wcode[3] == 0)) {
3780 qla_printk(KERN_WARNING, ha,
3781 "Unable to verify integrity of firmware image!\n");
3782 qla_printk(KERN_WARNING, ha,
3783 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3784 wcode[1], wcode[2], wcode[3]);
3785 goto fail_fw_integrity;
3789 while (*seg && rval == QLA_SUCCESS) {
3791 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3792 risc_size = be16_to_cpu(fwcode[3]);
3794 /* Validate firmware image size. */
3795 fwclen += risc_size * sizeof(uint16_t);
3796 if (blob->fw->size < fwclen) {
3797 qla_printk(KERN_WARNING, ha,
3798 "Unable to verify integrity of firmware image "
3799 "(%Zd)!\n", blob->fw->size);
3800 goto fail_fw_integrity;
3804 while (risc_size > 0 && rval == QLA_SUCCESS) {
3805 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3806 if (wlen > risc_size)
3809 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3810 "addr %x, number of words 0x%x.\n", ha->host_no,
3813 for (i = 0; i < wlen; i++)
3814 wcode[i] = swab16(fwcode[i]);
3816 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3819 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3820 "segment %d of firmware\n", ha->host_no,
3822 qla_printk(KERN_WARNING, ha,
3823 "[ERROR] Failed to load segment %d of "
3824 "firmware\n", fragment);
3840 return QLA_FUNCTION_FAILED;
3844 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3847 int segments, fragment;
3848 uint32_t *dcode, dlen;
3852 struct fw_blob *blob;
3853 uint32_t *fwcode, fwclen;
3855 /* Load firmware blob. */
3856 blob = qla2x00_request_firmware(ha);
3858 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3859 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3860 "from: " QLA_FW_URL ".\n");
3862 /* Try to load RISC code from flash. */
3863 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3864 "outdated) firmware from flash.\n");
3865 return qla24xx_load_risc_flash(ha, srisc_addr);
3870 segments = FA_RISC_CODE_SEGMENTS;
3871 dcode = (uint32_t *)ha->request_ring;
3873 fwcode = (uint32_t *)blob->fw->data;
3876 /* Validate firmware image by checking version. */
3877 if (blob->fw->size < 8 * sizeof(uint32_t)) {
3878 qla_printk(KERN_WARNING, ha,
3879 "Unable to verify integrity of firmware image (%Zd)!\n",
3881 goto fail_fw_integrity;
3883 for (i = 0; i < 4; i++)
3884 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3885 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3886 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3887 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3889 qla_printk(KERN_WARNING, ha,
3890 "Unable to verify integrity of firmware image!\n");
3891 qla_printk(KERN_WARNING, ha,
3892 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3893 dcode[1], dcode[2], dcode[3]);
3894 goto fail_fw_integrity;
3897 while (segments && rval == QLA_SUCCESS) {
3898 risc_addr = be32_to_cpu(fwcode[2]);
3899 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3900 risc_size = be32_to_cpu(fwcode[3]);
3902 /* Validate firmware image size. */
3903 fwclen += risc_size * sizeof(uint32_t);
3904 if (blob->fw->size < fwclen) {
3905 qla_printk(KERN_WARNING, ha,
3906 "Unable to verify integrity of firmware image "
3907 "(%Zd)!\n", blob->fw->size);
3909 goto fail_fw_integrity;
3913 while (risc_size > 0 && rval == QLA_SUCCESS) {
3914 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3915 if (dlen > risc_size)
3918 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3919 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3922 for (i = 0; i < dlen; i++)
3923 dcode[i] = swab32(fwcode[i]);
3925 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3928 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3929 "segment %d of firmware\n", ha->host_no,
3931 qla_printk(KERN_WARNING, ha,
3932 "[ERROR] Failed to load segment %d of "
3933 "firmware\n", fragment);
3949 return QLA_FUNCTION_FAILED;