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"
18 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
19 #ifndef EXT_IS_LUN_BIT_SET
20 #define EXT_IS_LUN_BIT_SET(P,L) \
21 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
22 #define EXT_SET_LUN_BIT(P,L) \
23 ((P)->mask[L/8] |= (0x80 >> (L%8)))
27 * QLogic ISP2x00 Hardware Support Function Prototypes.
29 static int qla2x00_isp_firmware(scsi_qla_host_t *);
30 static void qla2x00_resize_request_q(scsi_qla_host_t *);
31 static int qla2x00_setup_chip(scsi_qla_host_t *);
32 static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
33 static int qla2x00_init_rings(scsi_qla_host_t *);
34 static int qla2x00_fw_ready(scsi_qla_host_t *);
35 static int qla2x00_configure_hba(scsi_qla_host_t *);
36 static int qla2x00_configure_loop(scsi_qla_host_t *);
37 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
38 static int qla2x00_configure_fabric(scsi_qla_host_t *);
39 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
40 static int qla2x00_device_resync(scsi_qla_host_t *);
41 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
44 static int qla2x00_restart_isp(scsi_qla_host_t *);
46 static int qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev);
48 /****************************************************************************/
49 /* QLogic ISP2x00 Hardware Support Functions. */
50 /****************************************************************************/
53 * qla2x00_initialize_adapter
57 * ha = adapter block pointer.
63 qla2x00_initialize_adapter(scsi_qla_host_t *ha)
67 /* Clear adapter flags. */
69 ha->flags.reset_active = 0;
70 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
71 atomic_set(&ha->loop_state, LOOP_DOWN);
72 ha->device_flags = DFLG_NO_CABLE;
74 ha->flags.management_server_logged_in = 0;
75 ha->marker_needed = 0;
77 ha->isp_abort_cnt = 0;
78 ha->beacon_blink_led = 0;
79 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
81 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
82 rval = ha->isp_ops->pci_config(ha);
84 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
89 ha->isp_ops->reset_chip(ha);
91 ha->isp_ops->get_flash_version(ha, ha->request_ring);
93 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
95 ha->isp_ops->nvram_config(ha);
97 if (ha->flags.disable_serdes) {
98 /* Mask HBA via NVRAM settings? */
99 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
100 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
101 ha->port_name[0], ha->port_name[1],
102 ha->port_name[2], ha->port_name[3],
103 ha->port_name[4], ha->port_name[5],
104 ha->port_name[6], ha->port_name[7]);
105 return QLA_FUNCTION_FAILED;
108 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
110 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
111 rval = ha->isp_ops->chip_diag(ha);
114 rval = qla2x00_setup_chip(ha);
118 rval = qla2x00_init_rings(ha);
124 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
127 * Returns 0 on success.
130 qla2100_pci_config(scsi_qla_host_t *ha)
136 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
138 pci_set_master(ha->pdev);
139 ret = pci_set_mwi(ha->pdev);
141 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
142 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
143 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
145 /* Reset expansion ROM address decode enable */
146 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
147 d &= ~PCI_ROM_ADDRESS_ENABLE;
148 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
150 /* Get PCI bus information. */
151 spin_lock_irqsave(&ha->hardware_lock, flags);
152 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
153 spin_unlock_irqrestore(&ha->hardware_lock, flags);
159 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
162 * Returns 0 on success.
165 qla2300_pci_config(scsi_qla_host_t *ha)
170 unsigned long flags = 0;
172 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
174 pci_set_master(ha->pdev);
175 ret = pci_set_mwi(ha->pdev);
177 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
178 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
180 if (IS_QLA2322(ha) || IS_QLA6322(ha))
181 w &= ~PCI_COMMAND_INTX_DISABLE;
182 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
185 * If this is a 2300 card and not 2312, reset the
186 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
187 * the 2310 also reports itself as a 2300 so we need to get the
188 * fb revision level -- a 6 indicates it really is a 2300 and
191 if (IS_QLA2300(ha)) {
192 spin_lock_irqsave(&ha->hardware_lock, flags);
195 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
196 for (cnt = 0; cnt < 30000; cnt++) {
197 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
203 /* Select FPM registers. */
204 WRT_REG_WORD(®->ctrl_status, 0x20);
205 RD_REG_WORD(®->ctrl_status);
207 /* Get the fb rev level */
208 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
210 if (ha->fb_rev == FPM_2300)
211 pci_clear_mwi(ha->pdev);
213 /* Deselect FPM registers. */
214 WRT_REG_WORD(®->ctrl_status, 0x0);
215 RD_REG_WORD(®->ctrl_status);
217 /* Release RISC module. */
218 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
219 for (cnt = 0; cnt < 30000; cnt++) {
220 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
226 spin_unlock_irqrestore(&ha->hardware_lock, flags);
229 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
231 /* Reset expansion ROM address decode enable */
232 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
233 d &= ~PCI_ROM_ADDRESS_ENABLE;
234 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
236 /* Get PCI bus information. */
237 spin_lock_irqsave(&ha->hardware_lock, flags);
238 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
239 spin_unlock_irqrestore(&ha->hardware_lock, flags);
245 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
248 * Returns 0 on success.
251 qla24xx_pci_config(scsi_qla_host_t *ha)
256 unsigned long flags = 0;
257 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
259 pci_set_master(ha->pdev);
260 ret = pci_set_mwi(ha->pdev);
262 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
263 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
264 w &= ~PCI_COMMAND_INTX_DISABLE;
265 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
267 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
269 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
270 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
271 pcix_set_mmrbc(ha->pdev, 2048);
273 /* PCIe -- adjust Maximum Read Request Size (2048). */
274 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
275 pcie_set_readrq(ha->pdev, 2048);
277 /* Reset expansion ROM address decode enable */
278 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
279 d &= ~PCI_ROM_ADDRESS_ENABLE;
280 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
282 ha->chip_revision = ha->pdev->revision;
284 /* Get PCI bus information. */
285 spin_lock_irqsave(&ha->hardware_lock, flags);
286 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
287 spin_unlock_irqrestore(&ha->hardware_lock, flags);
293 * qla2x00_isp_firmware() - Choose firmware image.
296 * Returns 0 on success.
299 qla2x00_isp_firmware(scsi_qla_host_t *ha)
303 /* Assume loading risc code */
304 rval = QLA_FUNCTION_FAILED;
306 if (ha->flags.disable_risc_code_load) {
307 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
309 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
311 /* Verify checksum of loaded RISC code. */
312 rval = qla2x00_verify_checksum(ha, ha->fw_srisc_address);
316 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
324 * qla2x00_reset_chip() - Reset ISP chip.
327 * Returns 0 on success.
330 qla2x00_reset_chip(scsi_qla_host_t *ha)
332 unsigned long flags = 0;
333 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
337 ha->isp_ops->disable_intrs(ha);
339 spin_lock_irqsave(&ha->hardware_lock, flags);
341 /* Turn off master enable */
343 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
344 cmd &= ~PCI_COMMAND_MASTER;
345 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
347 if (!IS_QLA2100(ha)) {
349 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
350 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
351 for (cnt = 0; cnt < 30000; cnt++) {
352 if ((RD_REG_WORD(®->hccr) &
353 HCCR_RISC_PAUSE) != 0)
358 RD_REG_WORD(®->hccr); /* PCI Posting. */
362 /* Select FPM registers. */
363 WRT_REG_WORD(®->ctrl_status, 0x20);
364 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
366 /* FPM Soft Reset. */
367 WRT_REG_WORD(®->fpm_diag_config, 0x100);
368 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
370 /* Toggle Fpm Reset. */
371 if (!IS_QLA2200(ha)) {
372 WRT_REG_WORD(®->fpm_diag_config, 0x0);
373 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
376 /* Select frame buffer registers. */
377 WRT_REG_WORD(®->ctrl_status, 0x10);
378 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
380 /* Reset frame buffer FIFOs. */
381 if (IS_QLA2200(ha)) {
382 WRT_FB_CMD_REG(ha, reg, 0xa000);
383 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
385 WRT_FB_CMD_REG(ha, reg, 0x00fc);
387 /* Read back fb_cmd until zero or 3 seconds max */
388 for (cnt = 0; cnt < 3000; cnt++) {
389 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
395 /* Select RISC module registers. */
396 WRT_REG_WORD(®->ctrl_status, 0);
397 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
399 /* Reset RISC processor. */
400 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
401 RD_REG_WORD(®->hccr); /* PCI Posting. */
403 /* Release RISC processor. */
404 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
405 RD_REG_WORD(®->hccr); /* PCI Posting. */
408 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
409 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
411 /* Reset ISP chip. */
412 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
414 /* Wait for RISC to recover from reset. */
415 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
417 * It is necessary to for a delay here since the card doesn't
418 * respond to PCI reads during a reset. On some architectures
419 * this will result in an MCA.
422 for (cnt = 30000; cnt; cnt--) {
423 if ((RD_REG_WORD(®->ctrl_status) &
424 CSR_ISP_SOFT_RESET) == 0)
431 /* Reset RISC processor. */
432 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
434 WRT_REG_WORD(®->semaphore, 0);
436 /* Release RISC processor. */
437 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
438 RD_REG_WORD(®->hccr); /* PCI Posting. */
440 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
441 for (cnt = 0; cnt < 30000; cnt++) {
442 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
450 /* Turn on master enable */
451 cmd |= PCI_COMMAND_MASTER;
452 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
454 /* Disable RISC pause on FPM parity error. */
455 if (!IS_QLA2100(ha)) {
456 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
457 RD_REG_WORD(®->hccr); /* PCI Posting. */
460 spin_unlock_irqrestore(&ha->hardware_lock, flags);
464 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
467 * Returns 0 on success.
470 qla24xx_reset_risc(scsi_qla_host_t *ha)
472 unsigned long flags = 0;
473 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
477 spin_lock_irqsave(&ha->hardware_lock, flags);
480 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
481 for (cnt = 0; cnt < 30000; cnt++) {
482 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
488 WRT_REG_DWORD(®->ctrl_status,
489 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
490 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
493 /* Wait for firmware to complete NVRAM accesses. */
494 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
495 for (cnt = 10000 ; cnt && d2; cnt--) {
497 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
501 /* Wait for soft-reset to complete. */
502 d2 = RD_REG_DWORD(®->ctrl_status);
503 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
505 d2 = RD_REG_DWORD(®->ctrl_status);
509 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
510 RD_REG_DWORD(®->hccr);
512 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
513 RD_REG_DWORD(®->hccr);
515 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
516 RD_REG_DWORD(®->hccr);
518 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
519 for (cnt = 6000000 ; cnt && d2; cnt--) {
521 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
525 spin_unlock_irqrestore(&ha->hardware_lock, flags);
529 * qla24xx_reset_chip() - Reset ISP24xx chip.
532 * Returns 0 on success.
535 qla24xx_reset_chip(scsi_qla_host_t *ha)
537 ha->isp_ops->disable_intrs(ha);
539 /* Perform RISC reset. */
540 qla24xx_reset_risc(ha);
544 * qla2x00_chip_diag() - Test chip for proper operation.
547 * Returns 0 on success.
550 qla2x00_chip_diag(scsi_qla_host_t *ha)
553 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
554 unsigned long flags = 0;
559 /* Assume a failed state */
560 rval = QLA_FUNCTION_FAILED;
562 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
563 ha->host_no, (u_long)®->flash_address));
565 spin_lock_irqsave(&ha->hardware_lock, flags);
567 /* Reset ISP chip. */
568 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
571 * We need to have a delay here since the card will not respond while
572 * in reset causing an MCA on some architectures.
575 data = qla2x00_debounce_register(®->ctrl_status);
576 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
578 data = RD_REG_WORD(®->ctrl_status);
583 goto chip_diag_failed;
585 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
588 /* Reset RISC processor. */
589 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
590 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
592 /* Workaround for QLA2312 PCI parity error */
593 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
594 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
595 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
597 data = RD_MAILBOX_REG(ha, reg, 0);
604 goto chip_diag_failed;
606 /* Check product ID of chip */
607 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
609 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
610 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
611 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
612 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
613 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
614 mb[3] != PROD_ID_3) {
615 qla_printk(KERN_WARNING, ha,
616 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
618 goto chip_diag_failed;
620 ha->product_id[0] = mb[1];
621 ha->product_id[1] = mb[2];
622 ha->product_id[2] = mb[3];
623 ha->product_id[3] = mb[4];
625 /* Adjust fw RISC transfer size */
626 if (ha->request_q_length > 1024)
627 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
629 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
630 ha->request_q_length;
632 if (IS_QLA2200(ha) &&
633 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
634 /* Limit firmware transfer size with a 2200A */
635 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
638 ha->device_type |= DT_ISP2200A;
639 ha->fw_transfer_size = 128;
642 /* Wrap Incoming Mailboxes Test. */
643 spin_unlock_irqrestore(&ha->hardware_lock, flags);
645 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
646 rval = qla2x00_mbx_reg_test(ha);
648 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
650 qla_printk(KERN_WARNING, ha,
651 "Failed mailbox send register test\n");
654 /* Flag a successful rval */
657 spin_lock_irqsave(&ha->hardware_lock, flags);
661 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
662 "****\n", ha->host_no));
664 spin_unlock_irqrestore(&ha->hardware_lock, flags);
670 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
673 * Returns 0 on success.
676 qla24xx_chip_diag(scsi_qla_host_t *ha)
680 /* Perform RISC reset. */
681 qla24xx_reset_risc(ha);
683 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
685 rval = qla2x00_mbx_reg_test(ha);
687 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
689 qla_printk(KERN_WARNING, ha,
690 "Failed mailbox send register test\n");
692 /* Flag a successful rval */
700 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
703 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
709 qla_printk(KERN_WARNING, ha,
710 "Firmware dump previously allocated.\n");
715 fixed_size = mem_size = eft_size = 0;
716 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
717 fixed_size = sizeof(struct qla2100_fw_dump);
718 } else if (IS_QLA23XX(ha)) {
719 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
720 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
722 } else if (IS_FWI2_CAPABLE(ha)) {
723 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
724 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
727 /* Allocate memory for Extended Trace Buffer. */
728 eft = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &eft_dma,
731 qla_printk(KERN_WARNING, ha, "Unable to allocate "
732 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
736 rval = qla2x00_trace_control(ha, TC_ENABLE, eft_dma,
739 qla_printk(KERN_WARNING, ha, "Unable to initialize "
740 "EFT (%d).\n", rval);
741 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, eft,
746 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
750 memset(eft, 0, eft_size);
751 ha->eft_dma = eft_dma;
755 req_q_size = ha->request_q_length * sizeof(request_t);
756 rsp_q_size = ha->response_q_length * sizeof(response_t);
758 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
759 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
762 ha->fw_dump = vmalloc(dump_size);
764 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
765 "firmware dump!!!\n", dump_size / 1024);
768 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
776 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
779 ha->fw_dump_len = dump_size;
780 ha->fw_dump->signature[0] = 'Q';
781 ha->fw_dump->signature[1] = 'L';
782 ha->fw_dump->signature[2] = 'G';
783 ha->fw_dump->signature[3] = 'C';
784 ha->fw_dump->version = __constant_htonl(1);
786 ha->fw_dump->fixed_size = htonl(fixed_size);
787 ha->fw_dump->mem_size = htonl(mem_size);
788 ha->fw_dump->req_q_size = htonl(req_q_size);
789 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
791 ha->fw_dump->eft_size = htonl(eft_size);
792 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
793 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
795 ha->fw_dump->header_size =
796 htonl(offsetof(struct qla2xxx_fw_dump, isp));
800 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
803 * Returns 0 on success.
806 qla2x00_resize_request_q(scsi_qla_host_t *ha)
809 uint16_t fw_iocb_cnt = 0;
810 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
811 dma_addr_t request_dma;
812 request_t *request_ring;
814 /* Valid only on recent ISPs. */
815 if (IS_QLA2100(ha) || IS_QLA2200(ha))
818 /* Retrieve IOCB counts available to the firmware. */
819 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
822 /* No point in continuing if current settings are sufficient. */
823 if (fw_iocb_cnt < 1024)
825 if (ha->request_q_length >= request_q_length)
828 /* Attempt to claim larger area for request queue. */
829 request_ring = dma_alloc_coherent(&ha->pdev->dev,
830 (request_q_length + 1) * sizeof(request_t), &request_dma,
832 if (request_ring == NULL)
835 /* Resize successful, report extensions. */
836 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
837 (ha->fw_memory_size + 1) / 1024);
838 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
839 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
841 /* Clear old allocations. */
842 dma_free_coherent(&ha->pdev->dev,
843 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
846 /* Begin using larger queue. */
847 ha->request_q_length = request_q_length;
848 ha->request_ring = request_ring;
849 ha->request_dma = request_dma;
853 * qla2x00_setup_chip() - Load and start RISC firmware.
856 * Returns 0 on success.
859 qla2x00_setup_chip(scsi_qla_host_t *ha)
862 uint32_t srisc_address = 0;
864 /* Load firmware sequences */
865 rval = ha->isp_ops->load_risc(ha, &srisc_address);
866 if (rval == QLA_SUCCESS) {
867 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
868 "code.\n", ha->host_no));
870 rval = qla2x00_verify_checksum(ha, srisc_address);
871 if (rval == QLA_SUCCESS) {
872 /* Start firmware execution. */
873 DEBUG(printk("scsi(%ld): Checksum OK, start "
874 "firmware.\n", ha->host_no));
876 rval = qla2x00_execute_fw(ha, srisc_address);
877 /* Retrieve firmware information. */
878 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
879 qla2x00_get_fw_version(ha,
880 &ha->fw_major_version,
881 &ha->fw_minor_version,
882 &ha->fw_subminor_version,
883 &ha->fw_attributes, &ha->fw_memory_size);
884 qla2x00_resize_request_q(ha);
885 ha->flags.npiv_supported = 0;
886 if (IS_QLA24XX(ha) &&
887 (ha->fw_attributes & BIT_2))
888 ha->flags.npiv_supported = 1;
891 qla2x00_alloc_fw_dump(ha);
894 DEBUG2(printk(KERN_INFO
895 "scsi(%ld): ISP Firmware failed checksum.\n",
901 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
909 * qla2x00_init_response_q_entries() - Initializes response queue entries.
912 * Beginning of request ring has initialization control block already built
913 * by nvram config routine.
915 * Returns 0 on success.
918 qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
923 pkt = ha->response_ring_ptr;
924 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
925 pkt->signature = RESPONSE_PROCESSED;
932 * qla2x00_update_fw_options() - Read and process firmware options.
935 * Returns 0 on success.
938 qla2x00_update_fw_options(scsi_qla_host_t *ha)
940 uint16_t swing, emphasis, tx_sens, rx_sens;
942 memset(ha->fw_options, 0, sizeof(ha->fw_options));
943 qla2x00_get_fw_options(ha, ha->fw_options);
945 if (IS_QLA2100(ha) || IS_QLA2200(ha))
948 /* Serial Link options. */
949 DEBUG3(printk("scsi(%ld): Serial link options:\n",
951 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
952 sizeof(ha->fw_seriallink_options)));
954 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
955 if (ha->fw_seriallink_options[3] & BIT_2) {
956 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
959 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
960 emphasis = (ha->fw_seriallink_options[2] &
961 (BIT_4 | BIT_3)) >> 3;
962 tx_sens = ha->fw_seriallink_options[0] &
963 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
964 rx_sens = (ha->fw_seriallink_options[0] &
965 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
966 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
967 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
970 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
971 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
972 ha->fw_options[10] |= BIT_5 |
973 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
974 (tx_sens & (BIT_1 | BIT_0));
977 swing = (ha->fw_seriallink_options[2] &
978 (BIT_7 | BIT_6 | BIT_5)) >> 5;
979 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
980 tx_sens = ha->fw_seriallink_options[1] &
981 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
982 rx_sens = (ha->fw_seriallink_options[1] &
983 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
984 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
985 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
988 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
989 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
990 ha->fw_options[11] |= BIT_5 |
991 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
992 (tx_sens & (BIT_1 | BIT_0));
996 /* Return command IOCBs without waiting for an ABTS to complete. */
997 ha->fw_options[3] |= BIT_13;
1000 if (ha->flags.enable_led_scheme)
1001 ha->fw_options[2] |= BIT_12;
1003 /* Detect ISP6312. */
1005 ha->fw_options[2] |= BIT_13;
1007 /* Update firmware options. */
1008 qla2x00_set_fw_options(ha, ha->fw_options);
1012 qla24xx_update_fw_options(scsi_qla_host_t *ha)
1016 /* Update Serial Link options. */
1017 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1020 rval = qla2x00_set_serdes_params(ha,
1021 le16_to_cpu(ha->fw_seriallink_options24[1]),
1022 le16_to_cpu(ha->fw_seriallink_options24[2]),
1023 le16_to_cpu(ha->fw_seriallink_options24[3]));
1024 if (rval != QLA_SUCCESS) {
1025 qla_printk(KERN_WARNING, ha,
1026 "Unable to update Serial Link options (%x).\n", rval);
1031 qla2x00_config_rings(struct scsi_qla_host *ha)
1033 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1035 /* Setup ring parameters in initialization control block. */
1036 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1037 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1038 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1039 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1040 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1041 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1042 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1043 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1045 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1046 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1047 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1048 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1049 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1053 qla24xx_config_rings(struct scsi_qla_host *ha)
1055 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1056 struct init_cb_24xx *icb;
1058 /* Setup ring parameters in initialization control block. */
1059 icb = (struct init_cb_24xx *)ha->init_cb;
1060 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1061 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1062 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1063 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1064 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1065 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1066 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1067 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1069 WRT_REG_DWORD(®->req_q_in, 0);
1070 WRT_REG_DWORD(®->req_q_out, 0);
1071 WRT_REG_DWORD(®->rsp_q_in, 0);
1072 WRT_REG_DWORD(®->rsp_q_out, 0);
1073 RD_REG_DWORD(®->rsp_q_out);
1077 * qla2x00_init_rings() - Initializes firmware.
1080 * Beginning of request ring has initialization control block already built
1081 * by nvram config routine.
1083 * Returns 0 on success.
1086 qla2x00_init_rings(scsi_qla_host_t *ha)
1089 unsigned long flags = 0;
1091 struct mid_init_cb_24xx *mid_init_cb =
1092 (struct mid_init_cb_24xx *) ha->init_cb;
1094 spin_lock_irqsave(&ha->hardware_lock, flags);
1096 /* Clear outstanding commands array. */
1097 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1098 ha->outstanding_cmds[cnt] = NULL;
1100 ha->current_outstanding_cmd = 0;
1102 /* Clear RSCN queue. */
1103 ha->rscn_in_ptr = 0;
1104 ha->rscn_out_ptr = 0;
1106 /* Initialize firmware. */
1107 ha->request_ring_ptr = ha->request_ring;
1108 ha->req_ring_index = 0;
1109 ha->req_q_cnt = ha->request_q_length;
1110 ha->response_ring_ptr = ha->response_ring;
1111 ha->rsp_ring_index = 0;
1113 /* Initialize response queue entries */
1114 qla2x00_init_response_q_entries(ha);
1116 ha->isp_ops->config_rings(ha);
1118 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1120 /* Update any ISP specific firmware options before initialization. */
1121 ha->isp_ops->update_fw_options(ha);
1123 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
1125 mid_init_cb->count = MAX_NUM_VPORT_FABRIC;
1126 ha->max_npiv_vports = MAX_NUM_VPORT_FABRIC;
1128 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
1130 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1133 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1141 * qla2x00_fw_ready() - Waits for firmware ready.
1144 * Returns 0 on success.
1147 qla2x00_fw_ready(scsi_qla_host_t *ha)
1150 unsigned long wtime, mtime;
1151 uint16_t min_wait; /* Minimum wait time if loop is down */
1152 uint16_t wait_time; /* Wait time if loop is coming ready */
1157 /* 20 seconds for loop down. */
1161 * Firmware should take at most one RATOV to login, plus 5 seconds for
1162 * our own processing.
1164 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1165 wait_time = min_wait;
1168 /* Min wait time if loop down */
1169 mtime = jiffies + (min_wait * HZ);
1171 /* wait time before firmware ready */
1172 wtime = jiffies + (wait_time * HZ);
1174 /* Wait for ISP to finish LIP */
1175 if (!ha->flags.init_done)
1176 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1178 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1182 rval = qla2x00_get_firmware_state(ha, &fw_state);
1183 if (rval == QLA_SUCCESS) {
1184 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1185 ha->device_flags &= ~DFLG_NO_CABLE;
1187 if (fw_state == FSTATE_READY) {
1188 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1191 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1192 &ha->login_timeout, &ha->r_a_tov);
1198 rval = QLA_FUNCTION_FAILED;
1200 if (atomic_read(&ha->loop_down_timer) &&
1201 fw_state != FSTATE_READY) {
1202 /* Loop down. Timeout on min_wait for states
1203 * other than Wait for Login.
1205 if (time_after_eq(jiffies, mtime)) {
1206 qla_printk(KERN_INFO, ha,
1207 "Cable is unplugged...\n");
1209 ha->device_flags |= DFLG_NO_CABLE;
1214 /* Mailbox cmd failed. Timeout on min_wait. */
1215 if (time_after_eq(jiffies, mtime))
1219 if (time_after_eq(jiffies, wtime))
1222 /* Delay for a while */
1225 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1226 ha->host_no, fw_state, jiffies));
1229 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1230 ha->host_no, fw_state, jiffies));
1233 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1241 * qla2x00_configure_hba
1242 * Setup adapter context.
1245 * ha = adapter state pointer.
1254 qla2x00_configure_hba(scsi_qla_host_t *ha)
1263 char connect_type[22];
1265 /* Get host addresses. */
1266 rval = qla2x00_get_adapter_id(ha,
1267 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
1268 if (rval != QLA_SUCCESS) {
1269 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
1270 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1271 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1272 __func__, ha->host_no));
1274 qla_printk(KERN_WARNING, ha,
1275 "ERROR -- Unable to get host loop ID.\n");
1276 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1282 qla_printk(KERN_INFO, ha,
1283 "Cannot get topology - retrying.\n");
1284 return (QLA_FUNCTION_FAILED);
1287 ha->loop_id = loop_id;
1290 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1291 ha->operating_mode = LOOP;
1296 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1298 ha->current_topology = ISP_CFG_NL;
1299 strcpy(connect_type, "(Loop)");
1303 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1305 ha->switch_cap = sw_cap;
1306 ha->current_topology = ISP_CFG_FL;
1307 strcpy(connect_type, "(FL_Port)");
1311 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1313 ha->operating_mode = P2P;
1314 ha->current_topology = ISP_CFG_N;
1315 strcpy(connect_type, "(N_Port-to-N_Port)");
1319 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1321 ha->switch_cap = sw_cap;
1322 ha->operating_mode = P2P;
1323 ha->current_topology = ISP_CFG_F;
1324 strcpy(connect_type, "(F_Port)");
1328 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1330 ha->host_no, topo));
1331 ha->current_topology = ISP_CFG_NL;
1332 strcpy(connect_type, "(Loop)");
1336 /* Save Host port and loop ID. */
1337 /* byte order - Big Endian */
1338 ha->d_id.b.domain = domain;
1339 ha->d_id.b.area = area;
1340 ha->d_id.b.al_pa = al_pa;
1342 if (!ha->flags.init_done)
1343 qla_printk(KERN_INFO, ha,
1344 "Topology - %s, Host Loop address 0x%x\n",
1345 connect_type, ha->loop_id);
1348 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1350 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1357 qla2x00_set_model_info(scsi_qla_host_t *ha, uint8_t *model, size_t len, char *def)
1362 if (memcmp(model, BINZERO, len) != 0) {
1363 strncpy(ha->model_number, model, len);
1364 st = en = ha->model_number;
1367 if (*en != 0x20 && *en != 0x00)
1372 index = (ha->pdev->subsystem_device & 0xff);
1373 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1374 index < QLA_MODEL_NAMES)
1375 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1377 index = (ha->pdev->subsystem_device & 0xff);
1378 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1379 index < QLA_MODEL_NAMES) {
1380 strcpy(ha->model_number,
1381 qla2x00_model_name[index * 2]);
1382 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1384 strcpy(ha->model_number, def);
1389 /* On sparc systems, obtain port and node WWN from firmware
1392 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, nvram_t *nv)
1395 struct pci_dev *pdev = ha->pdev;
1396 struct device_node *dp = pci_device_to_OF_node(pdev);
1400 val = of_get_property(dp, "port-wwn", &len);
1401 if (val && len >= WWN_SIZE)
1402 memcpy(nv->port_name, val, WWN_SIZE);
1404 val = of_get_property(dp, "node-wwn", &len);
1405 if (val && len >= WWN_SIZE)
1406 memcpy(nv->node_name, val, WWN_SIZE);
1411 * NVRAM configuration for ISP 2xxx
1414 * ha = adapter block pointer.
1417 * initialization control block in response_ring
1418 * host adapters parameters in host adapter block
1424 qla2x00_nvram_config(scsi_qla_host_t *ha)
1429 uint8_t *dptr1, *dptr2;
1430 init_cb_t *icb = ha->init_cb;
1431 nvram_t *nv = (nvram_t *)ha->request_ring;
1432 uint8_t *ptr = (uint8_t *)ha->request_ring;
1433 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1437 /* Determine NVRAM starting address. */
1438 ha->nvram_size = sizeof(nvram_t);
1440 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1441 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1442 ha->nvram_base = 0x80;
1444 /* Get NVRAM data and calculate checksum. */
1445 ha->isp_ops->read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
1446 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1449 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
1450 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
1453 /* Bad NVRAM data, set defaults parameters. */
1454 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1455 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1456 /* Reset NVRAM data. */
1457 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1458 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1460 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1461 "invalid -- WWPN) defaults.\n");
1464 * Set default initialization control block.
1466 memset(nv, 0, ha->nvram_size);
1467 nv->parameter_block_version = ICB_VERSION;
1469 if (IS_QLA23XX(ha)) {
1470 nv->firmware_options[0] = BIT_2 | BIT_1;
1471 nv->firmware_options[1] = BIT_7 | BIT_5;
1472 nv->add_firmware_options[0] = BIT_5;
1473 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1474 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1475 nv->special_options[1] = BIT_7;
1476 } else if (IS_QLA2200(ha)) {
1477 nv->firmware_options[0] = BIT_2 | BIT_1;
1478 nv->firmware_options[1] = BIT_7 | BIT_5;
1479 nv->add_firmware_options[0] = BIT_5;
1480 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1481 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1482 } else if (IS_QLA2100(ha)) {
1483 nv->firmware_options[0] = BIT_3 | BIT_1;
1484 nv->firmware_options[1] = BIT_5;
1485 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1488 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1489 nv->execution_throttle = __constant_cpu_to_le16(16);
1490 nv->retry_count = 8;
1491 nv->retry_delay = 1;
1493 nv->port_name[0] = 33;
1494 nv->port_name[3] = 224;
1495 nv->port_name[4] = 139;
1497 qla2xxx_nvram_wwn_from_ofw(ha, nv);
1499 nv->login_timeout = 4;
1502 * Set default host adapter parameters
1504 nv->host_p[1] = BIT_2;
1505 nv->reset_delay = 5;
1506 nv->port_down_retry_count = 8;
1507 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1508 nv->link_down_timeout = 60;
1513 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1515 * The SN2 does not provide BIOS emulation which means you can't change
1516 * potentially bogus BIOS settings. Force the use of default settings
1517 * for link rate and frame size. Hope that the rest of the settings
1520 if (ia64_platform_is("sn2")) {
1521 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1523 nv->special_options[1] = BIT_7;
1527 /* Reset Initialization control block */
1528 memset(icb, 0, ha->init_cb_size);
1531 * Setup driver NVRAM options.
1533 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1534 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1535 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1536 nv->firmware_options[1] &= ~BIT_4;
1538 if (IS_QLA23XX(ha)) {
1539 nv->firmware_options[0] |= BIT_2;
1540 nv->firmware_options[0] &= ~BIT_3;
1541 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1543 if (IS_QLA2300(ha)) {
1544 if (ha->fb_rev == FPM_2310) {
1545 strcpy(ha->model_number, "QLA2310");
1547 strcpy(ha->model_number, "QLA2300");
1550 qla2x00_set_model_info(ha, nv->model_number,
1551 sizeof(nv->model_number), "QLA23xx");
1553 } else if (IS_QLA2200(ha)) {
1554 nv->firmware_options[0] |= BIT_2;
1556 * 'Point-to-point preferred, else loop' is not a safe
1557 * connection mode setting.
1559 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1561 /* Force 'loop preferred, else point-to-point'. */
1562 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1563 nv->add_firmware_options[0] |= BIT_5;
1565 strcpy(ha->model_number, "QLA22xx");
1566 } else /*if (IS_QLA2100(ha))*/ {
1567 strcpy(ha->model_number, "QLA2100");
1571 * Copy over NVRAM RISC parameter block to initialization control block.
1573 dptr1 = (uint8_t *)icb;
1574 dptr2 = (uint8_t *)&nv->parameter_block_version;
1575 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1577 *dptr1++ = *dptr2++;
1579 /* Copy 2nd half. */
1580 dptr1 = (uint8_t *)icb->add_firmware_options;
1581 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1583 *dptr1++ = *dptr2++;
1585 /* Use alternate WWN? */
1586 if (nv->host_p[1] & BIT_7) {
1587 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1588 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1591 /* Prepare nodename */
1592 if ((icb->firmware_options[1] & BIT_6) == 0) {
1594 * Firmware will apply the following mask if the nodename was
1597 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1598 icb->node_name[0] &= 0xF0;
1602 * Set host adapter parameters.
1604 if (nv->host_p[0] & BIT_7)
1605 ql2xextended_error_logging = 1;
1606 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1607 /* Always load RISC code on non ISP2[12]00 chips. */
1608 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1609 ha->flags.disable_risc_code_load = 0;
1610 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1611 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1612 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1613 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1614 ha->flags.disable_serdes = 0;
1616 ha->operating_mode =
1617 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1619 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1620 sizeof(ha->fw_seriallink_options));
1622 /* save HBA serial number */
1623 ha->serial0 = icb->port_name[5];
1624 ha->serial1 = icb->port_name[6];
1625 ha->serial2 = icb->port_name[7];
1626 ha->node_name = icb->node_name;
1627 ha->port_name = icb->port_name;
1629 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1631 ha->retry_count = nv->retry_count;
1633 /* Set minimum login_timeout to 4 seconds. */
1634 if (nv->login_timeout < ql2xlogintimeout)
1635 nv->login_timeout = ql2xlogintimeout;
1636 if (nv->login_timeout < 4)
1637 nv->login_timeout = 4;
1638 ha->login_timeout = nv->login_timeout;
1639 icb->login_timeout = nv->login_timeout;
1641 /* Set minimum RATOV to 200 tenths of a second. */
1644 ha->loop_reset_delay = nv->reset_delay;
1646 /* Link Down Timeout = 0:
1648 * When Port Down timer expires we will start returning
1649 * I/O's to OS with "DID_NO_CONNECT".
1651 * Link Down Timeout != 0:
1653 * The driver waits for the link to come up after link down
1654 * before returning I/Os to OS with "DID_NO_CONNECT".
1656 if (nv->link_down_timeout == 0) {
1657 ha->loop_down_abort_time =
1658 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1660 ha->link_down_timeout = nv->link_down_timeout;
1661 ha->loop_down_abort_time =
1662 (LOOP_DOWN_TIME - ha->link_down_timeout);
1666 * Need enough time to try and get the port back.
1668 ha->port_down_retry_count = nv->port_down_retry_count;
1669 if (qlport_down_retry)
1670 ha->port_down_retry_count = qlport_down_retry;
1671 /* Set login_retry_count */
1672 ha->login_retry_count = nv->retry_count;
1673 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1674 ha->port_down_retry_count > 3)
1675 ha->login_retry_count = ha->port_down_retry_count;
1676 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1677 ha->login_retry_count = ha->port_down_retry_count;
1678 if (ql2xloginretrycount)
1679 ha->login_retry_count = ql2xloginretrycount;
1681 icb->lun_enables = __constant_cpu_to_le16(0);
1682 icb->command_resource_count = 0;
1683 icb->immediate_notify_resource_count = 0;
1684 icb->timeout = __constant_cpu_to_le16(0);
1686 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1688 icb->firmware_options[0] &= ~BIT_3;
1689 icb->add_firmware_options[0] &=
1690 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1691 icb->add_firmware_options[0] |= BIT_2;
1692 icb->response_accumulation_timer = 3;
1693 icb->interrupt_delay_timer = 5;
1695 ha->flags.process_response_queue = 1;
1698 if (!ha->flags.init_done) {
1699 ha->zio_mode = icb->add_firmware_options[0] &
1700 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1701 ha->zio_timer = icb->interrupt_delay_timer ?
1702 icb->interrupt_delay_timer: 2;
1704 icb->add_firmware_options[0] &=
1705 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1706 ha->flags.process_response_queue = 0;
1707 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1708 ha->zio_mode = QLA_ZIO_MODE_6;
1710 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1711 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1712 ha->zio_timer * 100));
1713 qla_printk(KERN_INFO, ha,
1714 "ZIO mode %d enabled; timer delay (%d us).\n",
1715 ha->zio_mode, ha->zio_timer * 100);
1717 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1718 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1719 ha->flags.process_response_queue = 1;
1724 DEBUG2_3(printk(KERN_WARNING
1725 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1731 qla2x00_rport_del(void *data)
1733 fc_port_t *fcport = data;
1734 struct fc_rport *rport;
1735 unsigned long flags;
1737 spin_lock_irqsave(&fcport->rport_lock, flags);
1738 rport = fcport->drport;
1739 fcport->drport = NULL;
1740 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1742 fc_remote_port_delete(rport);
1746 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1748 * @flags: allocation flags
1750 * Returns a pointer to the allocated fcport, or NULL, if none available.
1753 qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1757 fcport = kmalloc(sizeof(fc_port_t), flags);
1761 /* Setup fcport template structure. */
1762 memset(fcport, 0, sizeof (fc_port_t));
1764 fcport->vp_idx = ha->vp_idx;
1765 fcport->port_type = FCT_UNKNOWN;
1766 fcport->loop_id = FC_NO_LOOP_ID;
1767 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1768 fcport->flags = FCF_RLC_SUPPORT;
1769 fcport->supported_classes = FC_COS_UNSPECIFIED;
1770 spin_lock_init(&fcport->rport_lock);
1776 * qla2x00_configure_loop
1777 * Updates Fibre Channel Device Database with what is actually on loop.
1780 * ha = adapter block pointer.
1785 * 2 = database was full and device was not configured.
1788 qla2x00_configure_loop(scsi_qla_host_t *ha)
1791 unsigned long flags, save_flags;
1795 /* Get Initiator ID */
1796 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1797 rval = qla2x00_configure_hba(ha);
1798 if (rval != QLA_SUCCESS) {
1799 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1805 save_flags = flags = ha->dpc_flags;
1806 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1807 ha->host_no, flags));
1810 * If we have both an RSCN and PORT UPDATE pending then handle them
1811 * both at the same time.
1813 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1814 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
1816 /* Determine what we need to do */
1817 if (ha->current_topology == ISP_CFG_FL &&
1818 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1820 ha->flags.rscn_queue_overflow = 1;
1821 set_bit(RSCN_UPDATE, &flags);
1823 } else if (ha->current_topology == ISP_CFG_F &&
1824 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1826 ha->flags.rscn_queue_overflow = 1;
1827 set_bit(RSCN_UPDATE, &flags);
1828 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1830 } else if (ha->current_topology == ISP_CFG_N) {
1831 clear_bit(RSCN_UPDATE, &flags);
1833 } else if (!ha->flags.online ||
1834 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1836 ha->flags.rscn_queue_overflow = 1;
1837 set_bit(RSCN_UPDATE, &flags);
1838 set_bit(LOCAL_LOOP_UPDATE, &flags);
1841 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1842 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1843 rval = QLA_FUNCTION_FAILED;
1845 rval = qla2x00_configure_local_loop(ha);
1849 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
1850 if (LOOP_TRANSITION(ha)) {
1851 rval = QLA_FUNCTION_FAILED;
1853 rval = qla2x00_configure_fabric(ha);
1857 if (rval == QLA_SUCCESS) {
1858 if (atomic_read(&ha->loop_down_timer) ||
1859 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1860 rval = QLA_FUNCTION_FAILED;
1862 atomic_set(&ha->loop_state, LOOP_READY);
1864 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1869 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1870 __func__, ha->host_no));
1872 DEBUG3(printk("%s: exiting normally\n", __func__));
1875 /* Restore state if a resync event occured during processing */
1876 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1877 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1878 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1879 if (test_bit(RSCN_UPDATE, &save_flags))
1880 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1889 * qla2x00_configure_local_loop
1890 * Updates Fibre Channel Device Database with local loop devices.
1893 * ha = adapter block pointer.
1899 qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1904 fc_port_t *fcport, *new_fcport;
1910 uint8_t domain, area, al_pa;
1911 scsi_qla_host_t *pha = to_qla_parent(ha);
1915 entries = MAX_FIBRE_DEVICES;
1917 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1918 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1920 /* Get list of logged in devices. */
1921 memset(ha->gid_list, 0, GID_LIST_SIZE);
1922 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1924 if (rval != QLA_SUCCESS)
1925 goto cleanup_allocation;
1927 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1928 ha->host_no, entries));
1929 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1930 entries * sizeof(struct gid_list_info)));
1932 /* Allocate temporary fcport for any new fcports discovered. */
1933 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1934 if (new_fcport == NULL) {
1935 rval = QLA_MEMORY_ALLOC_FAILED;
1936 goto cleanup_allocation;
1938 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1941 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1943 list_for_each_entry(fcport, &pha->fcports, list) {
1944 if (fcport->vp_idx != ha->vp_idx)
1947 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1948 fcport->port_type != FCT_BROADCAST &&
1949 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1951 DEBUG(printk("scsi(%ld): Marking port lost, "
1953 ha->host_no, fcport->loop_id));
1955 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1956 fcport->flags &= ~FCF_FARP_DONE;
1960 /* Add devices to port list. */
1961 id_iter = (char *)ha->gid_list;
1962 for (index = 0; index < entries; index++) {
1963 domain = ((struct gid_list_info *)id_iter)->domain;
1964 area = ((struct gid_list_info *)id_iter)->area;
1965 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
1966 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1967 loop_id = (uint16_t)
1968 ((struct gid_list_info *)id_iter)->loop_id_2100;
1970 loop_id = le16_to_cpu(
1971 ((struct gid_list_info *)id_iter)->loop_id);
1972 id_iter += ha->gid_list_info_size;
1974 /* Bypass reserved domain fields. */
1975 if ((domain & 0xf0) == 0xf0)
1978 /* Bypass if not same domain and area of adapter. */
1979 if (area && domain &&
1980 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
1983 /* Bypass invalid local loop ID. */
1984 if (loop_id > LAST_LOCAL_LOOP_ID)
1987 /* Fill in member data. */
1988 new_fcport->d_id.b.domain = domain;
1989 new_fcport->d_id.b.area = area;
1990 new_fcport->d_id.b.al_pa = al_pa;
1991 new_fcport->loop_id = loop_id;
1992 new_fcport->vp_idx = ha->vp_idx;
1993 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
1994 if (rval2 != QLA_SUCCESS) {
1995 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1996 "information -- get_port_database=%x, "
1998 ha->host_no, rval2, new_fcport->loop_id));
1999 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2001 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2005 /* Check for matching device in port list. */
2008 list_for_each_entry(fcport, &pha->fcports, list) {
2009 if (fcport->vp_idx != ha->vp_idx)
2012 if (memcmp(new_fcport->port_name, fcport->port_name,
2016 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2017 FCF_PERSISTENT_BOUND);
2018 fcport->loop_id = new_fcport->loop_id;
2019 fcport->port_type = new_fcport->port_type;
2020 fcport->d_id.b24 = new_fcport->d_id.b24;
2021 memcpy(fcport->node_name, new_fcport->node_name,
2029 /* New device, add to fcports list. */
2030 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
2032 new_fcport->ha = ha;
2033 new_fcport->vp_idx = ha->vp_idx;
2034 list_add_tail(&new_fcport->vp_fcport,
2037 list_add_tail(&new_fcport->list, &pha->fcports);
2039 /* Allocate a new replacement fcport. */
2040 fcport = new_fcport;
2041 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2042 if (new_fcport == NULL) {
2043 rval = QLA_MEMORY_ALLOC_FAILED;
2044 goto cleanup_allocation;
2046 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2049 /* Base iIDMA settings on HBA port speed. */
2050 switch (ha->link_data_rate) {
2051 case PORT_SPEED_1GB:
2052 fcport->fp_speed = cpu_to_be16(BIT_15);
2054 case PORT_SPEED_2GB:
2055 fcport->fp_speed = cpu_to_be16(BIT_14);
2057 case PORT_SPEED_4GB:
2058 fcport->fp_speed = cpu_to_be16(BIT_13);
2062 qla2x00_update_fcport(ha, fcport);
2070 if (rval != QLA_SUCCESS) {
2071 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2072 "rval=%x\n", ha->host_no, rval));
2076 ha->device_flags |= DFLG_LOCAL_DEVICES;
2077 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2084 qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
2088 qla2x00_mark_all_devices_lost(ha, 0);
2089 list_for_each_entry(fcport, &ha->fcports, list) {
2090 if (fcport->port_type != FCT_TARGET)
2093 qla2x00_update_fcport(ha, fcport);
2098 qla2x00_iidma_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2100 #define LS_UNKNOWN 2
2101 static char *link_speeds[5] = { "1", "2", "?", "4" };
2103 uint16_t port_speed, mb[6];
2105 if (!IS_IIDMA_CAPABLE(ha))
2108 switch (be16_to_cpu(fcport->fp_speed)) {
2110 port_speed = PORT_SPEED_1GB;
2113 port_speed = PORT_SPEED_2GB;
2116 port_speed = PORT_SPEED_4GB;
2119 DEBUG2(printk("scsi(%ld): %02x%02x%02x%02x%02x%02x%02x%02x -- "
2120 "unsupported FM port operating speed (%04x).\n",
2121 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2122 fcport->port_name[2], fcport->port_name[3],
2123 fcport->port_name[4], fcport->port_name[5],
2124 fcport->port_name[6], fcport->port_name[7],
2125 be16_to_cpu(fcport->fp_speed)));
2126 port_speed = PORT_SPEED_UNKNOWN;
2129 if (port_speed == PORT_SPEED_UNKNOWN)
2132 rval = qla2x00_set_idma_speed(ha, fcport->loop_id, port_speed, mb);
2133 if (rval != QLA_SUCCESS) {
2134 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2135 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2136 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2137 fcport->port_name[2], fcport->port_name[3],
2138 fcport->port_name[4], fcport->port_name[5],
2139 fcport->port_name[6], fcport->port_name[7], rval,
2140 port_speed, mb[0], mb[1]));
2142 DEBUG2(qla_printk(KERN_INFO, ha,
2143 "iIDMA adjusted to %s GB/s on "
2144 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2145 link_speeds[port_speed], fcport->port_name[0],
2146 fcport->port_name[1], fcport->port_name[2],
2147 fcport->port_name[3], fcport->port_name[4],
2148 fcport->port_name[5], fcport->port_name[6],
2149 fcport->port_name[7]));
2154 qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2156 struct fc_rport_identifiers rport_ids;
2157 struct fc_rport *rport;
2158 unsigned long flags;
2161 qla2x00_rport_del(fcport);
2165 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2166 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2167 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2168 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2169 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2170 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
2172 qla_printk(KERN_WARNING, ha,
2173 "Unable to allocate fc remote port!\n");
2176 spin_lock_irqsave(&fcport->rport_lock, flags);
2177 fcport->rport = rport;
2178 *((fc_port_t **)rport->dd_data) = fcport;
2179 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2181 rport->supported_classes = fcport->supported_classes;
2183 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2184 if (fcport->port_type == FCT_INITIATOR)
2185 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2186 if (fcport->port_type == FCT_TARGET)
2187 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2188 fc_remote_port_rolechg(rport, rport_ids.roles);
2190 if (rport->scsi_target_id != -1 &&
2191 rport->scsi_target_id < ha->host->max_id)
2192 fcport->os_target_id = rport->scsi_target_id;
2196 * qla2x00_update_fcport
2197 * Updates device on list.
2200 * ha = adapter block pointer.
2201 * fcport = port structure pointer.
2211 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2213 scsi_qla_host_t *pha = to_qla_parent(ha);
2216 fcport->login_retry = 0;
2217 fcport->port_login_retry_count = pha->port_down_retry_count *
2219 atomic_set(&fcport->port_down_timer, pha->port_down_retry_count *
2221 fcport->flags &= ~FCF_LOGIN_NEEDED;
2223 qla2x00_iidma_fcport(ha, fcport);
2225 atomic_set(&fcport->state, FCS_ONLINE);
2227 qla2x00_reg_remote_port(ha, fcport);
2231 * qla2x00_configure_fabric
2232 * Setup SNS devices with loop ID's.
2235 * ha = adapter block pointer.
2242 qla2x00_configure_fabric(scsi_qla_host_t *ha)
2245 fc_port_t *fcport, *fcptemp;
2246 uint16_t next_loopid;
2247 uint16_t mb[MAILBOX_REGISTER_COUNT];
2249 LIST_HEAD(new_fcports);
2250 scsi_qla_host_t *pha = to_qla_parent(ha);
2252 /* If FL port exists, then SNS is present */
2253 if (IS_FWI2_CAPABLE(ha))
2254 loop_id = NPH_F_PORT;
2256 loop_id = SNS_FL_PORT;
2257 rval = qla2x00_get_port_name(ha, loop_id, ha->fabric_node_name, 1);
2258 if (rval != QLA_SUCCESS) {
2259 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2260 "Port\n", ha->host_no));
2262 ha->device_flags &= ~SWITCH_FOUND;
2263 return (QLA_SUCCESS);
2265 ha->device_flags |= SWITCH_FOUND;
2267 /* Mark devices that need re-synchronization. */
2268 rval2 = qla2x00_device_resync(ha);
2269 if (rval2 == QLA_RSCNS_HANDLED) {
2270 /* No point doing the scan, just continue. */
2271 return (QLA_SUCCESS);
2275 if (ql2xfdmienable &&
2276 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2277 qla2x00_fdmi_register(ha);
2279 /* Ensure we are logged into the SNS. */
2280 if (IS_FWI2_CAPABLE(ha))
2283 loop_id = SIMPLE_NAME_SERVER;
2284 ha->isp_ops->fabric_login(ha, loop_id, 0xff, 0xff,
2285 0xfc, mb, BIT_1 | BIT_0);
2286 if (mb[0] != MBS_COMMAND_COMPLETE) {
2287 DEBUG2(qla_printk(KERN_INFO, ha,
2288 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2289 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2290 mb[0], mb[1], mb[2], mb[6], mb[7]));
2291 return (QLA_SUCCESS);
2294 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2295 if (qla2x00_rft_id(ha)) {
2297 DEBUG2(printk("scsi(%ld): Register FC-4 "
2298 "TYPE failed.\n", ha->host_no));
2300 if (qla2x00_rff_id(ha)) {
2302 DEBUG2(printk("scsi(%ld): Register FC-4 "
2303 "Features failed.\n", ha->host_no));
2305 if (qla2x00_rnn_id(ha)) {
2307 DEBUG2(printk("scsi(%ld): Register Node Name "
2308 "failed.\n", ha->host_no));
2309 } else if (qla2x00_rsnn_nn(ha)) {
2311 DEBUG2(printk("scsi(%ld): Register Symbolic "
2312 "Node Name failed.\n", ha->host_no));
2316 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2317 if (rval != QLA_SUCCESS)
2321 * Logout all previous fabric devices marked lost, except
2324 list_for_each_entry(fcport, &pha->fcports, list) {
2325 if (fcport->vp_idx !=ha->vp_idx)
2328 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2331 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2334 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2335 qla2x00_mark_device_lost(ha, fcport,
2336 ql2xplogiabsentdevice, 0);
2337 if (fcport->loop_id != FC_NO_LOOP_ID &&
2338 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2339 fcport->port_type != FCT_INITIATOR &&
2340 fcport->port_type != FCT_BROADCAST) {
2341 ha->isp_ops->fabric_logout(ha,
2343 fcport->d_id.b.domain,
2344 fcport->d_id.b.area,
2345 fcport->d_id.b.al_pa);
2346 fcport->loop_id = FC_NO_LOOP_ID;
2351 /* Starting free loop ID. */
2352 next_loopid = pha->min_external_loopid;
2355 * Scan through our port list and login entries that need to be
2358 list_for_each_entry(fcport, &pha->fcports, list) {
2359 if (fcport->vp_idx != ha->vp_idx)
2362 if (atomic_read(&ha->loop_down_timer) ||
2363 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2366 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2367 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2370 if (fcport->loop_id == FC_NO_LOOP_ID) {
2371 fcport->loop_id = next_loopid;
2372 rval = qla2x00_find_new_loop_id(ha, fcport);
2373 if (rval != QLA_SUCCESS) {
2374 /* Ran out of IDs to use */
2378 /* Login and update database */
2379 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2382 /* Exit if out of loop IDs. */
2383 if (rval != QLA_SUCCESS) {
2388 * Login and add the new devices to our port list.
2390 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2391 if (atomic_read(&ha->loop_down_timer) ||
2392 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2395 /* Find a new loop ID to use. */
2396 fcport->loop_id = next_loopid;
2397 rval = qla2x00_find_new_loop_id(ha, fcport);
2398 if (rval != QLA_SUCCESS) {
2399 /* Ran out of IDs to use */
2403 /* Login and update database */
2404 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2408 fcport->vp_idx = ha->vp_idx;
2409 list_add_tail(&fcport->vp_fcport,
2411 list_move_tail(&fcport->list,
2412 &ha->parent->fcports);
2414 list_move_tail(&fcport->list, &ha->fcports);
2418 /* Free all new device structures not processed. */
2419 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2420 list_del(&fcport->list);
2425 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2426 "rval=%d\n", ha->host_no, rval));
2434 * qla2x00_find_all_fabric_devs
2437 * ha = adapter block pointer.
2438 * dev = database device entry pointer.
2447 qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2451 fc_port_t *fcport, *new_fcport, *fcptemp;
2456 int first_dev, last_dev;
2457 port_id_t wrap, nxt_d_id;
2461 scsi_qla_host_t *vha;
2462 scsi_qla_host_t *pha = to_qla_parent(ha);
2466 /* Try GID_PT to get device list, else GAN. */
2467 swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);
2470 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2471 "on GA_NXT\n", ha->host_no));
2473 memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);
2474 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2477 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2480 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2483 } else if (qla2x00_gfpn_id(ha, swl) == QLA_SUCCESS) {
2484 qla2x00_gpsc(ha, swl);
2489 /* Allocate temporary fcport for any new fcports discovered. */
2490 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2491 if (new_fcport == NULL) {
2493 return (QLA_MEMORY_ALLOC_FAILED);
2495 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2496 new_fcport->vp_idx = ha->vp_idx;
2497 /* Set start port ID scan at adapter ID. */
2501 /* Starting free loop ID. */
2502 loop_id = pha->min_external_loopid;
2503 for (; loop_id <= ha->last_loop_id; loop_id++) {
2504 if (qla2x00_is_reserved_id(ha, loop_id))
2507 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
2512 wrap.b24 = new_fcport->d_id.b24;
2514 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2515 memcpy(new_fcport->node_name,
2516 swl[swl_idx].node_name, WWN_SIZE);
2517 memcpy(new_fcport->port_name,
2518 swl[swl_idx].port_name, WWN_SIZE);
2519 memcpy(new_fcport->fabric_port_name,
2520 swl[swl_idx].fabric_port_name, WWN_SIZE);
2521 new_fcport->fp_speed = swl[swl_idx].fp_speed;
2523 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2529 /* Send GA_NXT to the switch */
2530 rval = qla2x00_ga_nxt(ha, new_fcport);
2531 if (rval != QLA_SUCCESS) {
2532 qla_printk(KERN_WARNING, ha,
2533 "SNS scan failed -- assuming zero-entry "
2535 list_for_each_entry_safe(fcport, fcptemp,
2536 new_fcports, list) {
2537 list_del(&fcport->list);
2545 /* If wrap on switch device list, exit. */
2547 wrap.b24 = new_fcport->d_id.b24;
2549 } else if (new_fcport->d_id.b24 == wrap.b24) {
2550 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2551 ha->host_no, new_fcport->d_id.b.domain,
2552 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2556 /* Bypass if same physical adapter. */
2557 if (new_fcport->d_id.b24 == pha->d_id.b24)
2560 /* Bypass virtual ports of the same host. */
2561 if (pha->num_vhosts) {
2562 vp_index = find_next_bit(
2563 (unsigned long *)pha->vp_idx_map,
2564 MAX_MULTI_ID_FABRIC + 1, 1);
2566 for (;vp_index <= MAX_MULTI_ID_FABRIC;
2567 vp_index = find_next_bit(
2568 (unsigned long *)pha->vp_idx_map,
2569 MAX_MULTI_ID_FABRIC + 1, vp_index + 1)) {
2572 list_for_each_entry(vha, &pha->vp_list,
2574 if (vp_index == vha->vp_idx) {
2585 new_fcport->d_id.b24 == vha->d_id.b24)
2588 if (vp_index <= MAX_MULTI_ID_FABRIC)
2592 /* Bypass if same domain and area of adapter. */
2593 if (((new_fcport->d_id.b24 & 0xffff00) ==
2594 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2598 /* Bypass reserved domain fields. */
2599 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2602 /* Locate matching device in database. */
2604 list_for_each_entry(fcport, &pha->fcports, list) {
2605 if (new_fcport->vp_idx != fcport->vp_idx)
2607 if (memcmp(new_fcport->port_name, fcport->port_name,
2613 /* Update port state. */
2614 memcpy(fcport->fabric_port_name,
2615 new_fcport->fabric_port_name, WWN_SIZE);
2616 fcport->fp_speed = new_fcport->fp_speed;
2619 * If address the same and state FCS_ONLINE, nothing
2622 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2623 atomic_read(&fcport->state) == FCS_ONLINE) {
2628 * If device was not a fabric device before.
2630 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2631 fcport->d_id.b24 = new_fcport->d_id.b24;
2632 fcport->loop_id = FC_NO_LOOP_ID;
2633 fcport->flags |= (FCF_FABRIC_DEVICE |
2635 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2640 * Port ID changed or device was marked to be updated;
2641 * Log it out if still logged in and mark it for
2644 fcport->d_id.b24 = new_fcport->d_id.b24;
2645 fcport->flags |= FCF_LOGIN_NEEDED;
2646 if (fcport->loop_id != FC_NO_LOOP_ID &&
2647 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2648 fcport->port_type != FCT_INITIATOR &&
2649 fcport->port_type != FCT_BROADCAST) {
2650 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
2651 fcport->d_id.b.domain, fcport->d_id.b.area,
2652 fcport->d_id.b.al_pa);
2653 fcport->loop_id = FC_NO_LOOP_ID;
2662 /* If device was not in our fcports list, then add it. */
2663 list_add_tail(&new_fcport->list, new_fcports);
2665 /* Allocate a new replacement fcport. */
2666 nxt_d_id.b24 = new_fcport->d_id.b24;
2667 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2668 if (new_fcport == NULL) {
2670 return (QLA_MEMORY_ALLOC_FAILED);
2672 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2673 new_fcport->d_id.b24 = nxt_d_id.b24;
2674 new_fcport->vp_idx = ha->vp_idx;
2680 if (!list_empty(new_fcports))
2681 ha->device_flags |= DFLG_FABRIC_DEVICES;
2687 * qla2x00_find_new_loop_id
2688 * Scan through our port list and find a new usable loop ID.
2691 * ha: adapter state pointer.
2692 * dev: port structure pointer.
2695 * qla2x00 local function return status code.
2701 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2706 uint16_t first_loop_id;
2707 scsi_qla_host_t *pha = to_qla_parent(ha);
2711 /* Save starting loop ID. */
2712 first_loop_id = dev->loop_id;
2715 /* Skip loop ID if already used by adapter. */
2716 if (dev->loop_id == ha->loop_id) {
2720 /* Skip reserved loop IDs. */
2721 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
2725 /* Reset loop ID if passed the end. */
2726 if (dev->loop_id > ha->last_loop_id) {
2727 /* first loop ID. */
2728 dev->loop_id = ha->min_external_loopid;
2731 /* Check for loop ID being already in use. */
2734 list_for_each_entry(fcport, &pha->fcports, list) {
2735 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2736 /* ID possibly in use */
2742 /* If not in use then it is free to use. */
2747 /* ID in use. Try next value. */
2750 /* If wrap around. No free ID to use. */
2751 if (dev->loop_id == first_loop_id) {
2752 dev->loop_id = FC_NO_LOOP_ID;
2753 rval = QLA_FUNCTION_FAILED;
2762 * qla2x00_device_resync
2763 * Marks devices in the database that needs resynchronization.
2766 * ha = adapter block pointer.
2772 qla2x00_device_resync(scsi_qla_host_t *ha)
2777 uint32_t rscn_entry;
2778 uint8_t rscn_out_iter;
2781 scsi_qla_host_t *pha = to_qla_parent(ha);
2783 rval = QLA_RSCNS_HANDLED;
2785 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2786 ha->flags.rscn_queue_overflow) {
2788 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2789 format = MSB(MSW(rscn_entry));
2790 d_id.b.domain = LSB(MSW(rscn_entry));
2791 d_id.b.area = MSB(LSW(rscn_entry));
2792 d_id.b.al_pa = LSB(LSW(rscn_entry));
2794 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2795 "[%02x/%02x%02x%02x].\n",
2796 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2797 d_id.b.area, d_id.b.al_pa));
2800 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2801 ha->rscn_out_ptr = 0;
2803 /* Skip duplicate entries. */
2804 for (rscn_out_iter = ha->rscn_out_ptr;
2805 !ha->flags.rscn_queue_overflow &&
2806 rscn_out_iter != ha->rscn_in_ptr;
2807 rscn_out_iter = (rscn_out_iter ==
2808 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2810 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2813 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2814 "entry found at [%d].\n", ha->host_no,
2817 ha->rscn_out_ptr = rscn_out_iter;
2820 /* Queue overflow, set switch default case. */
2821 if (ha->flags.rscn_queue_overflow) {
2822 DEBUG(printk("scsi(%ld): device_resync: rscn "
2823 "overflow.\n", ha->host_no));
2826 ha->flags.rscn_queue_overflow = 0;
2842 ha->rscn_out_ptr = ha->rscn_in_ptr;
2848 list_for_each_entry(fcport, &pha->fcports, list) {
2849 if (fcport->vp_idx != ha->vp_idx)
2852 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2853 (fcport->d_id.b24 & mask) != d_id.b24 ||
2854 fcport->port_type == FCT_BROADCAST)
2857 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2859 fcport->port_type != FCT_INITIATOR) {
2860 qla2x00_mark_device_lost(ha, fcport,
2864 fcport->flags &= ~FCF_FARP_DONE;
2871 * qla2x00_fabric_dev_login
2872 * Login fabric target device and update FC port database.
2875 * ha: adapter state pointer.
2876 * fcport: port structure list pointer.
2877 * next_loopid: contains value of a new loop ID that can be used
2878 * by the next login attempt.
2881 * qla2x00 local function return status code.
2887 qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2888 uint16_t *next_loopid)
2897 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2898 if (rval == QLA_SUCCESS) {
2899 /* Send an ADISC to tape devices.*/
2901 if (fcport->flags & FCF_TAPE_PRESENT)
2903 rval = qla2x00_get_port_database(ha, fcport, opts);
2904 if (rval != QLA_SUCCESS) {
2905 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
2906 fcport->d_id.b.domain, fcport->d_id.b.area,
2907 fcport->d_id.b.al_pa);
2908 qla2x00_mark_device_lost(ha, fcport, 1, 0);
2910 qla2x00_update_fcport(ha, fcport);
2918 * qla2x00_fabric_login
2919 * Issue fabric login command.
2922 * ha = adapter block pointer.
2923 * device = pointer to FC device type structure.
2926 * 0 - Login successfully
2928 * 2 - Initiator device
2932 qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2933 uint16_t *next_loopid)
2937 uint16_t tmp_loopid;
2938 uint16_t mb[MAILBOX_REGISTER_COUNT];
2944 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2945 "for port %02x%02x%02x.\n",
2946 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2947 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2949 /* Login fcport on switch. */
2950 ha->isp_ops->fabric_login(ha, fcport->loop_id,
2951 fcport->d_id.b.domain, fcport->d_id.b.area,
2952 fcport->d_id.b.al_pa, mb, BIT_0);
2953 if (mb[0] == MBS_PORT_ID_USED) {
2955 * Device has another loop ID. The firmware team
2956 * recommends the driver perform an implicit login with
2957 * the specified ID again. The ID we just used is save
2958 * here so we return with an ID that can be tried by
2962 tmp_loopid = fcport->loop_id;
2963 fcport->loop_id = mb[1];
2965 DEBUG(printk("Fabric Login: port in use - next "
2966 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2967 fcport->loop_id, fcport->d_id.b.domain,
2968 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2970 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2975 /* A retry occurred before. */
2976 *next_loopid = tmp_loopid;
2979 * No retry occurred before. Just increment the
2980 * ID value for next login.
2982 *next_loopid = (fcport->loop_id + 1);
2985 if (mb[1] & BIT_0) {
2986 fcport->port_type = FCT_INITIATOR;
2988 fcport->port_type = FCT_TARGET;
2989 if (mb[1] & BIT_1) {
2990 fcport->flags |= FCF_TAPE_PRESENT;
2995 fcport->supported_classes |= FC_COS_CLASS2;
2997 fcport->supported_classes |= FC_COS_CLASS3;
3001 } else if (mb[0] == MBS_LOOP_ID_USED) {
3003 * Loop ID already used, try next loop ID.
3006 rval = qla2x00_find_new_loop_id(ha, fcport);
3007 if (rval != QLA_SUCCESS) {
3008 /* Ran out of loop IDs to use */
3011 } else if (mb[0] == MBS_COMMAND_ERROR) {
3013 * Firmware possibly timed out during login. If NO
3014 * retries are left to do then the device is declared
3017 *next_loopid = fcport->loop_id;
3018 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
3019 fcport->d_id.b.domain, fcport->d_id.b.area,
3020 fcport->d_id.b.al_pa);
3021 qla2x00_mark_device_lost(ha, fcport, 1, 0);
3027 * unrecoverable / not handled error
3029 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3030 "loop_id=%x jiffies=%lx.\n",
3031 __func__, ha->host_no, mb[0],
3032 fcport->d_id.b.domain, fcport->d_id.b.area,
3033 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3035 *next_loopid = fcport->loop_id;
3036 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
3037 fcport->d_id.b.domain, fcport->d_id.b.area,
3038 fcport->d_id.b.al_pa);
3039 fcport->loop_id = FC_NO_LOOP_ID;
3040 fcport->login_retry = 0;
3051 * qla2x00_local_device_login
3052 * Issue local device login command.
3055 * ha = adapter block pointer.
3056 * loop_id = loop id of device to login to.
3058 * Returns (Where's the #define!!!!):
3059 * 0 - Login successfully
3064 qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
3067 uint16_t mb[MAILBOX_REGISTER_COUNT];
3069 memset(mb, 0, sizeof(mb));
3070 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
3071 if (rval == QLA_SUCCESS) {
3072 /* Interrogate mailbox registers for any errors */
3073 if (mb[0] == MBS_COMMAND_ERROR)
3075 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3076 /* device not in PCB table */
3084 * qla2x00_loop_resync
3085 * Resync with fibre channel devices.
3088 * ha = adapter block pointer.
3094 qla2x00_loop_resync(scsi_qla_host_t *ha)
3101 atomic_set(&ha->loop_state, LOOP_UPDATE);
3102 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3103 if (ha->flags.online) {
3104 if (!(rval = qla2x00_fw_ready(ha))) {
3105 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3108 atomic_set(&ha->loop_state, LOOP_UPDATE);
3110 /* Issue a marker after FW becomes ready. */
3111 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3112 ha->marker_needed = 0;
3114 /* Remap devices on Loop. */
3115 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3117 qla2x00_configure_loop(ha);
3119 } while (!atomic_read(&ha->loop_down_timer) &&
3120 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3122 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3126 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3127 return (QLA_FUNCTION_FAILED);
3131 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3138 qla2x00_rescan_fcports(scsi_qla_host_t *ha)
3144 list_for_each_entry(fcport, &ha->fcports, list) {
3145 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
3148 qla2x00_update_fcport(ha, fcport);
3149 fcport->flags &= ~FCF_RESCAN_NEEDED;
3153 qla2x00_probe_for_all_luns(ha);
3157 qla2x00_update_fcports(scsi_qla_host_t *ha)
3161 /* Go with deferred removal of rport references. */
3162 list_for_each_entry(fcport, &ha->fcports, list)
3164 qla2x00_rport_del(fcport);
3169 * Resets ISP and aborts all outstanding commands.
3172 * ha = adapter block pointer.
3178 qla2x00_abort_isp(scsi_qla_host_t *ha)
3181 unsigned long flags = 0;
3186 if (ha->flags.online) {
3187 ha->flags.online = 0;
3188 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3190 qla_printk(KERN_INFO, ha,
3191 "Performing ISP error recovery - ha= %p.\n", ha);
3192 ha->isp_ops->reset_chip(ha);
3194 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3195 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3196 atomic_set(&ha->loop_state, LOOP_DOWN);
3197 qla2x00_mark_all_devices_lost(ha, 0);
3199 if (!atomic_read(&ha->loop_down_timer))
3200 atomic_set(&ha->loop_down_timer,
3204 spin_lock_irqsave(&ha->hardware_lock, flags);
3205 /* Requeue all commands in outstanding command list. */
3206 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3207 sp = ha->outstanding_cmds[cnt];
3209 ha->outstanding_cmds[cnt] = NULL;
3211 sp->cmd->result = DID_RESET << 16;
3212 sp->cmd->host_scribble = (unsigned char *)NULL;
3213 qla2x00_sp_compl(ha, sp);
3216 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3218 ha->isp_ops->get_flash_version(ha, ha->request_ring);
3220 ha->isp_ops->nvram_config(ha);
3222 if (!qla2x00_restart_isp(ha)) {
3223 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3225 if (!atomic_read(&ha->loop_down_timer)) {
3227 * Issue marker command only when we are going
3228 * to start the I/O .
3230 ha->marker_needed = 1;
3233 ha->flags.online = 1;
3235 ha->isp_ops->enable_intrs(ha);
3237 ha->isp_abort_cnt = 0;
3238 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3241 rval = qla2x00_trace_control(ha, TC_ENABLE,
3242 ha->eft_dma, EFT_NUM_BUFFERS);
3244 qla_printk(KERN_WARNING, ha,
3245 "Unable to reinitialize EFT "
3249 } else { /* failed the ISP abort */
3250 ha->flags.online = 1;
3251 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3252 if (ha->isp_abort_cnt == 0) {
3253 qla_printk(KERN_WARNING, ha,
3254 "ISP error recovery failed - "
3255 "board disabled\n");
3257 * The next call disables the board
3260 ha->isp_ops->reset_adapter(ha);
3261 ha->flags.online = 0;
3262 clear_bit(ISP_ABORT_RETRY,
3265 } else { /* schedule another ISP abort */
3266 ha->isp_abort_cnt--;
3267 DEBUG(printk("qla%ld: ISP abort - "
3268 "retry remaining %d\n",
3269 ha->host_no, ha->isp_abort_cnt));
3273 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3274 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3275 "- retrying (%d) more times\n",
3276 ha->host_no, ha->isp_abort_cnt));
3277 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3285 qla_printk(KERN_INFO, ha,
3286 "qla2x00_abort_isp: **** FAILED ****\n");
3288 DEBUG(printk(KERN_INFO
3289 "qla2x00_abort_isp(%ld): exiting.\n",
3297 * qla2x00_restart_isp
3298 * restarts the ISP after a reset
3301 * ha = adapter block pointer.
3307 qla2x00_restart_isp(scsi_qla_host_t *ha)
3310 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3311 unsigned long flags = 0;
3314 /* If firmware needs to be loaded */
3315 if (qla2x00_isp_firmware(ha)) {
3316 ha->flags.online = 0;
3317 if (!(status = ha->isp_ops->chip_diag(ha))) {
3318 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3319 status = qla2x00_setup_chip(ha);
3323 spin_lock_irqsave(&ha->hardware_lock, flags);
3325 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3327 * Disable SRAM, Instruction RAM and GP RAM
3330 WRT_REG_WORD(®->hccr,
3331 (HCCR_ENABLE_PARITY + 0x0));
3332 RD_REG_WORD(®->hccr);
3335 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3337 status = qla2x00_setup_chip(ha);
3339 spin_lock_irqsave(&ha->hardware_lock, flags);
3341 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
3342 /* Enable proper parity */
3345 WRT_REG_WORD(®->hccr,
3346 (HCCR_ENABLE_PARITY + 0x1));
3349 * SRAM, Instruction RAM and GP RAM
3352 WRT_REG_WORD(®->hccr,
3353 (HCCR_ENABLE_PARITY + 0x7));
3354 RD_REG_WORD(®->hccr);
3357 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3362 if (!status && !(status = qla2x00_init_rings(ha))) {
3363 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3364 if (!(status = qla2x00_fw_ready(ha))) {
3365 DEBUG(printk("%s(): Start configure loop, "
3366 "status = %d\n", __func__, status));
3368 /* Issue a marker after FW becomes ready. */
3369 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3371 ha->flags.online = 1;
3372 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3375 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3376 qla2x00_configure_loop(ha);
3378 } while (!atomic_read(&ha->loop_down_timer) &&
3379 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3381 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3384 /* if no cable then assume it's good */
3385 if ((ha->device_flags & DFLG_NO_CABLE))
3388 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3396 * qla2x00_reset_adapter
3400 * ha = adapter block pointer.
3403 qla2x00_reset_adapter(scsi_qla_host_t *ha)
3405 unsigned long flags = 0;
3406 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3408 ha->flags.online = 0;
3409 ha->isp_ops->disable_intrs(ha);
3411 spin_lock_irqsave(&ha->hardware_lock, flags);
3412 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3413 RD_REG_WORD(®->hccr); /* PCI Posting. */
3414 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3415 RD_REG_WORD(®->hccr); /* PCI Posting. */
3416 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3420 qla24xx_reset_adapter(scsi_qla_host_t *ha)
3422 unsigned long flags = 0;
3423 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3425 ha->flags.online = 0;
3426 ha->isp_ops->disable_intrs(ha);
3428 spin_lock_irqsave(&ha->hardware_lock, flags);
3429 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3430 RD_REG_DWORD(®->hccr);
3431 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3432 RD_REG_DWORD(®->hccr);
3433 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3436 /* On sparc systems, obtain port and node WWN from firmware
3439 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, struct nvram_24xx *nv)
3442 struct pci_dev *pdev = ha->pdev;
3443 struct device_node *dp = pci_device_to_OF_node(pdev);
3447 val = of_get_property(dp, "port-wwn", &len);
3448 if (val && len >= WWN_SIZE)
3449 memcpy(nv->port_name, val, WWN_SIZE);
3451 val = of_get_property(dp, "node-wwn", &len);
3452 if (val && len >= WWN_SIZE)
3453 memcpy(nv->node_name, val, WWN_SIZE);
3458 qla24xx_nvram_config(scsi_qla_host_t *ha)
3461 struct init_cb_24xx *icb;
3462 struct nvram_24xx *nv;
3464 uint8_t *dptr1, *dptr2;
3469 icb = (struct init_cb_24xx *)ha->init_cb;
3470 nv = (struct nvram_24xx *)ha->request_ring;
3472 /* Determine NVRAM starting address. */
3473 ha->nvram_size = sizeof(struct nvram_24xx);
3474 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3475 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3476 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3477 if (PCI_FUNC(ha->pdev->devfn)) {
3478 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3479 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3482 /* Get NVRAM data and calculate checksum. */
3483 dptr = (uint32_t *)nv;
3484 ha->isp_ops->read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
3486 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3487 chksum += le32_to_cpu(*dptr++);
3489 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3490 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha->request_ring,
3493 /* Bad NVRAM data, set defaults parameters. */
3494 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3495 || nv->id[3] != ' ' ||
3496 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3497 /* Reset NVRAM data. */
3498 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3499 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3500 le16_to_cpu(nv->nvram_version));
3501 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3502 "invalid -- WWPN) defaults.\n");
3505 * Set default initialization control block.
3507 memset(nv, 0, ha->nvram_size);
3508 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3509 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3510 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3511 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3512 nv->exchange_count = __constant_cpu_to_le16(0);
3513 nv->hard_address = __constant_cpu_to_le16(124);
3514 nv->port_name[0] = 0x21;
3515 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3516 nv->port_name[2] = 0x00;
3517 nv->port_name[3] = 0xe0;
3518 nv->port_name[4] = 0x8b;
3519 nv->port_name[5] = 0x1c;
3520 nv->port_name[6] = 0x55;
3521 nv->port_name[7] = 0x86;
3522 nv->node_name[0] = 0x20;
3523 nv->node_name[1] = 0x00;
3524 nv->node_name[2] = 0x00;
3525 nv->node_name[3] = 0xe0;
3526 nv->node_name[4] = 0x8b;
3527 nv->node_name[5] = 0x1c;
3528 nv->node_name[6] = 0x55;
3529 nv->node_name[7] = 0x86;
3530 qla24xx_nvram_wwn_from_ofw(ha, nv);
3531 nv->login_retry_count = __constant_cpu_to_le16(8);
3532 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3533 nv->login_timeout = __constant_cpu_to_le16(0);
3534 nv->firmware_options_1 =
3535 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3536 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3537 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3538 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3539 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3540 nv->efi_parameters = __constant_cpu_to_le32(0);
3541 nv->reset_delay = 5;
3542 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3543 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3544 nv->link_down_timeout = __constant_cpu_to_le16(30);
3549 /* Reset Initialization control block */
3550 memset(icb, 0, sizeof(struct init_cb_24xx));
3552 /* Copy 1st segment. */
3553 dptr1 = (uint8_t *)icb;
3554 dptr2 = (uint8_t *)&nv->version;
3555 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3557 *dptr1++ = *dptr2++;
3559 icb->login_retry_count = nv->login_retry_count;
3560 icb->link_down_on_nos = nv->link_down_on_nos;
3562 /* Copy 2nd segment. */
3563 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3564 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3565 cnt = (uint8_t *)&icb->reserved_3 -
3566 (uint8_t *)&icb->interrupt_delay_timer;
3568 *dptr1++ = *dptr2++;
3571 * Setup driver NVRAM options.
3573 qla2x00_set_model_info(ha, nv->model_name, sizeof(nv->model_name),
3576 /* Use alternate WWN? */
3577 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3578 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3579 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3582 /* Prepare nodename */
3583 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3585 * Firmware will apply the following mask if the nodename was
3588 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3589 icb->node_name[0] &= 0xF0;
3592 /* Set host adapter parameters. */
3593 ha->flags.disable_risc_code_load = 0;
3594 ha->flags.enable_lip_reset = 0;
3595 ha->flags.enable_lip_full_login =
3596 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3597 ha->flags.enable_target_reset =
3598 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
3599 ha->flags.enable_led_scheme = 0;
3600 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
3602 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3603 (BIT_6 | BIT_5 | BIT_4)) >> 4;
3605 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3606 sizeof(ha->fw_seriallink_options24));
3608 /* save HBA serial number */
3609 ha->serial0 = icb->port_name[5];
3610 ha->serial1 = icb->port_name[6];
3611 ha->serial2 = icb->port_name[7];
3612 ha->node_name = icb->node_name;
3613 ha->port_name = icb->port_name;
3615 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3617 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3619 /* Set minimum login_timeout to 4 seconds. */
3620 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3621 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3622 if (le16_to_cpu(nv->login_timeout) < 4)
3623 nv->login_timeout = __constant_cpu_to_le16(4);
3624 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3625 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3627 /* Set minimum RATOV to 200 tenths of a second. */
3630 ha->loop_reset_delay = nv->reset_delay;
3632 /* Link Down Timeout = 0:
3634 * When Port Down timer expires we will start returning
3635 * I/O's to OS with "DID_NO_CONNECT".
3637 * Link Down Timeout != 0:
3639 * The driver waits for the link to come up after link down
3640 * before returning I/Os to OS with "DID_NO_CONNECT".
3642 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3643 ha->loop_down_abort_time =
3644 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3646 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3647 ha->loop_down_abort_time =
3648 (LOOP_DOWN_TIME - ha->link_down_timeout);
3651 /* Need enough time to try and get the port back. */
3652 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3653 if (qlport_down_retry)
3654 ha->port_down_retry_count = qlport_down_retry;
3656 /* Set login_retry_count */
3657 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3658 if (ha->port_down_retry_count ==
3659 le16_to_cpu(nv->port_down_retry_count) &&
3660 ha->port_down_retry_count > 3)
3661 ha->login_retry_count = ha->port_down_retry_count;
3662 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3663 ha->login_retry_count = ha->port_down_retry_count;
3664 if (ql2xloginretrycount)
3665 ha->login_retry_count = ql2xloginretrycount;
3668 if (!ha->flags.init_done) {
3669 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3670 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3671 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3672 le16_to_cpu(icb->interrupt_delay_timer): 2;
3674 icb->firmware_options_2 &= __constant_cpu_to_le32(
3675 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3676 ha->flags.process_response_queue = 0;
3677 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3678 ha->zio_mode = QLA_ZIO_MODE_6;
3680 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3681 "(%d us).\n", ha->host_no, ha->zio_mode,
3682 ha->zio_timer * 100));
3683 qla_printk(KERN_INFO, ha,
3684 "ZIO mode %d enabled; timer delay (%d us).\n",
3685 ha->zio_mode, ha->zio_timer * 100);
3687 icb->firmware_options_2 |= cpu_to_le32(
3688 (uint32_t)ha->zio_mode);
3689 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3690 ha->flags.process_response_queue = 1;
3694 DEBUG2_3(printk(KERN_WARNING
3695 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3701 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3704 int segments, fragment;
3706 uint32_t *dcode, dlen;
3713 segments = FA_RISC_CODE_SEGMENTS;
3714 faddr = FA_RISC_CODE_ADDR;
3715 dcode = (uint32_t *)ha->request_ring;
3718 /* Validate firmware image by checking version. */
3719 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3720 for (i = 0; i < 4; i++)
3721 dcode[i] = be32_to_cpu(dcode[i]);
3722 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3723 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3724 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3726 qla_printk(KERN_WARNING, ha,
3727 "Unable to verify integrity of flash firmware image!\n");
3728 qla_printk(KERN_WARNING, ha,
3729 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3730 dcode[1], dcode[2], dcode[3]);
3732 return QLA_FUNCTION_FAILED;
3735 while (segments && rval == QLA_SUCCESS) {
3736 /* Read segment's load information. */
3737 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3739 risc_addr = be32_to_cpu(dcode[2]);
3740 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3741 risc_size = be32_to_cpu(dcode[3]);
3744 while (risc_size > 0 && rval == QLA_SUCCESS) {
3745 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3746 if (dlen > risc_size)
3749 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3750 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3751 ha->host_no, risc_addr, dlen, faddr));
3753 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3754 for (i = 0; i < dlen; i++)
3755 dcode[i] = swab32(dcode[i]);
3757 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3760 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3761 "segment %d of firmware\n", ha->host_no,
3763 qla_printk(KERN_WARNING, ha,
3764 "[ERROR] Failed to load segment %d of "
3765 "firmware\n", fragment);
3782 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3785 qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3789 uint16_t *wcode, *fwcode;
3790 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3791 struct fw_blob *blob;
3793 /* Load firmware blob. */
3794 blob = qla2x00_request_firmware(ha);
3796 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3797 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3798 "from: " QLA_FW_URL ".\n");
3799 return QLA_FUNCTION_FAILED;
3804 wcode = (uint16_t *)ha->request_ring;
3806 fwcode = (uint16_t *)blob->fw->data;
3809 /* Validate firmware image by checking version. */
3810 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3811 qla_printk(KERN_WARNING, ha,
3812 "Unable to verify integrity of firmware image (%Zd)!\n",
3814 goto fail_fw_integrity;
3816 for (i = 0; i < 4; i++)
3817 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3818 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3819 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3820 wcode[2] == 0 && wcode[3] == 0)) {
3821 qla_printk(KERN_WARNING, ha,
3822 "Unable to verify integrity of firmware image!\n");
3823 qla_printk(KERN_WARNING, ha,
3824 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3825 wcode[1], wcode[2], wcode[3]);
3826 goto fail_fw_integrity;
3830 while (*seg && rval == QLA_SUCCESS) {
3832 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3833 risc_size = be16_to_cpu(fwcode[3]);
3835 /* Validate firmware image size. */
3836 fwclen += risc_size * sizeof(uint16_t);
3837 if (blob->fw->size < fwclen) {
3838 qla_printk(KERN_WARNING, ha,
3839 "Unable to verify integrity of firmware image "
3840 "(%Zd)!\n", blob->fw->size);
3841 goto fail_fw_integrity;
3845 while (risc_size > 0 && rval == QLA_SUCCESS) {
3846 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3847 if (wlen > risc_size)
3850 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3851 "addr %x, number of words 0x%x.\n", ha->host_no,
3854 for (i = 0; i < wlen; i++)
3855 wcode[i] = swab16(fwcode[i]);
3857 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3860 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3861 "segment %d of firmware\n", ha->host_no,
3863 qla_printk(KERN_WARNING, ha,
3864 "[ERROR] Failed to load segment %d of "
3865 "firmware\n", fragment);
3881 return QLA_FUNCTION_FAILED;
3885 qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3888 int segments, fragment;
3889 uint32_t *dcode, dlen;
3893 struct fw_blob *blob;
3894 uint32_t *fwcode, fwclen;
3896 /* Load firmware blob. */
3897 blob = qla2x00_request_firmware(ha);
3899 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3900 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3901 "from: " QLA_FW_URL ".\n");
3903 /* Try to load RISC code from flash. */
3904 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3905 "outdated) firmware from flash.\n");
3906 return qla24xx_load_risc_flash(ha, srisc_addr);
3911 segments = FA_RISC_CODE_SEGMENTS;
3912 dcode = (uint32_t *)ha->request_ring;
3914 fwcode = (uint32_t *)blob->fw->data;
3917 /* Validate firmware image by checking version. */
3918 if (blob->fw->size < 8 * sizeof(uint32_t)) {
3919 qla_printk(KERN_WARNING, ha,
3920 "Unable to verify integrity of firmware image (%Zd)!\n",
3922 goto fail_fw_integrity;
3924 for (i = 0; i < 4; i++)
3925 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3926 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3927 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3928 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3930 qla_printk(KERN_WARNING, ha,
3931 "Unable to verify integrity of firmware image!\n");
3932 qla_printk(KERN_WARNING, ha,
3933 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3934 dcode[1], dcode[2], dcode[3]);
3935 goto fail_fw_integrity;
3938 while (segments && rval == QLA_SUCCESS) {
3939 risc_addr = be32_to_cpu(fwcode[2]);
3940 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3941 risc_size = be32_to_cpu(fwcode[3]);
3943 /* Validate firmware image size. */
3944 fwclen += risc_size * sizeof(uint32_t);
3945 if (blob->fw->size < fwclen) {
3946 qla_printk(KERN_WARNING, ha,
3947 "Unable to verify integrity of firmware image "
3948 "(%Zd)!\n", blob->fw->size);
3950 goto fail_fw_integrity;
3954 while (risc_size > 0 && rval == QLA_SUCCESS) {
3955 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3956 if (dlen > risc_size)
3959 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3960 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3963 for (i = 0; i < dlen; i++)
3964 dcode[i] = swab32(fwcode[i]);
3966 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3969 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3970 "segment %d of firmware\n", ha->host_no,
3972 qla_printk(KERN_WARNING, ha,
3973 "[ERROR] Failed to load segment %d of "
3974 "firmware\n", fragment);
3990 return QLA_FUNCTION_FAILED;
3994 qla2x00_try_to_stop_firmware(scsi_qla_host_t *ha)
3998 if (!IS_FWI2_CAPABLE(ha))
4000 if (!ha->fw_major_version)
4003 ret = qla2x00_stop_firmware(ha);
4004 for (retries = 5; ret != QLA_SUCCESS && retries ; retries--) {
4005 qla2x00_reset_chip(ha);
4006 if (qla2x00_chip_diag(ha) != QLA_SUCCESS)
4008 if (qla2x00_setup_chip(ha) != QLA_SUCCESS)
4010 qla_printk(KERN_INFO, ha,
4011 "Attempting retry of stop-firmware command...\n");
4012 ret = qla2x00_stop_firmware(ha);
4017 qla24xx_configure_vhba(scsi_qla_host_t *ha)
4019 int rval = QLA_SUCCESS;
4020 uint16_t mb[MAILBOX_REGISTER_COUNT];
4025 rval = qla2x00_fw_ready(ha);
4026 if (rval == QLA_SUCCESS) {
4027 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
4028 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
4031 ha->flags.management_server_logged_in = 0;
4033 /* Login to SNS first */
4034 qla24xx_login_fabric(ha, NPH_SNS, 0xff, 0xff, 0xfc,
4036 if (mb[0] != MBS_COMMAND_COMPLETE) {
4037 DEBUG15(qla_printk(KERN_INFO, ha,
4038 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4039 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4040 mb[0], mb[1], mb[2], mb[6], mb[7]));
4041 return (QLA_FUNCTION_FAILED);
4044 atomic_set(&ha->loop_down_timer, 0);
4045 atomic_set(&ha->loop_state, LOOP_UP);
4046 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4047 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
4048 rval = qla2x00_loop_resync(ha);