2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2008 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
10 #include <linux/delay.h>
11 #include <linux/vmalloc.h>
13 #include "qla_devtbl.h"
20 * QLogic ISP2x00 Hardware Support Function Prototypes.
22 static int qla2x00_isp_firmware(scsi_qla_host_t *);
23 static void qla2x00_resize_request_q(scsi_qla_host_t *);
24 static int qla2x00_setup_chip(scsi_qla_host_t *);
25 static int qla2x00_init_rings(scsi_qla_host_t *);
26 static int qla2x00_fw_ready(scsi_qla_host_t *);
27 static int qla2x00_configure_hba(scsi_qla_host_t *);
28 static int qla2x00_configure_loop(scsi_qla_host_t *);
29 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
30 static int qla2x00_configure_fabric(scsi_qla_host_t *);
31 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
32 static int qla2x00_device_resync(scsi_qla_host_t *);
33 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
36 static int qla2x00_restart_isp(scsi_qla_host_t *);
38 static int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *);
40 static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
41 static int qla84xx_init_chip(scsi_qla_host_t *);
42 static int qla25xx_init_queues(struct qla_hw_data *);
44 /****************************************************************************/
45 /* QLogic ISP2x00 Hardware Support Functions. */
46 /****************************************************************************/
49 * qla2x00_initialize_adapter
53 * ha = adapter block pointer.
59 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
62 struct qla_hw_data *ha = vha->hw;
63 struct req_que *req = ha->req_q_map[0];
64 /* Clear adapter flags. */
65 vha->flags.online = 0;
66 vha->flags.reset_active = 0;
67 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
68 atomic_set(&vha->loop_state, LOOP_DOWN);
69 vha->device_flags = DFLG_NO_CABLE;
71 vha->flags.management_server_logged_in = 0;
72 vha->marker_needed = 0;
74 ha->isp_abort_cnt = 0;
75 ha->beacon_blink_led = 0;
76 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
78 set_bit(0, ha->req_qid_map);
79 set_bit(0, ha->rsp_qid_map);
81 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
82 rval = ha->isp_ops->pci_config(vha);
84 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
89 ha->isp_ops->reset_chip(vha);
91 rval = qla2xxx_get_flash_info(vha);
93 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
98 ha->isp_ops->get_flash_version(vha, req->ring);
100 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
102 ha->isp_ops->nvram_config(vha);
104 if (ha->flags.disable_serdes) {
105 /* Mask HBA via NVRAM settings? */
106 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
107 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
108 vha->port_name[0], vha->port_name[1],
109 vha->port_name[2], vha->port_name[3],
110 vha->port_name[4], vha->port_name[5],
111 vha->port_name[6], vha->port_name[7]);
112 return QLA_FUNCTION_FAILED;
115 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
117 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
118 rval = ha->isp_ops->chip_diag(vha);
121 rval = qla2x00_setup_chip(vha);
125 if (IS_QLA84XX(ha)) {
126 ha->cs84xx = qla84xx_get_chip(vha);
128 qla_printk(KERN_ERR, ha,
129 "Unable to configure ISP84XX.\n");
130 return QLA_FUNCTION_FAILED;
133 rval = qla2x00_init_rings(vha);
139 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
142 * Returns 0 on success.
145 qla2100_pci_config(scsi_qla_host_t *vha)
149 struct qla_hw_data *ha = vha->hw;
150 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
152 pci_set_master(ha->pdev);
153 pci_try_set_mwi(ha->pdev);
155 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
156 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
157 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
159 pci_disable_rom(ha->pdev);
161 /* Get PCI bus information. */
162 spin_lock_irqsave(&ha->hardware_lock, flags);
163 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
164 spin_unlock_irqrestore(&ha->hardware_lock, flags);
170 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
173 * Returns 0 on success.
176 qla2300_pci_config(scsi_qla_host_t *vha)
179 unsigned long flags = 0;
181 struct qla_hw_data *ha = vha->hw;
182 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
184 pci_set_master(ha->pdev);
185 pci_try_set_mwi(ha->pdev);
187 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
188 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
190 if (IS_QLA2322(ha) || IS_QLA6322(ha))
191 w &= ~PCI_COMMAND_INTX_DISABLE;
192 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
195 * If this is a 2300 card and not 2312, reset the
196 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
197 * the 2310 also reports itself as a 2300 so we need to get the
198 * fb revision level -- a 6 indicates it really is a 2300 and
201 if (IS_QLA2300(ha)) {
202 spin_lock_irqsave(&ha->hardware_lock, flags);
205 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
206 for (cnt = 0; cnt < 30000; cnt++) {
207 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
213 /* Select FPM registers. */
214 WRT_REG_WORD(®->ctrl_status, 0x20);
215 RD_REG_WORD(®->ctrl_status);
217 /* Get the fb rev level */
218 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
220 if (ha->fb_rev == FPM_2300)
221 pci_clear_mwi(ha->pdev);
223 /* Deselect FPM registers. */
224 WRT_REG_WORD(®->ctrl_status, 0x0);
225 RD_REG_WORD(®->ctrl_status);
227 /* Release RISC module. */
228 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
229 for (cnt = 0; cnt < 30000; cnt++) {
230 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
236 spin_unlock_irqrestore(&ha->hardware_lock, flags);
239 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
241 pci_disable_rom(ha->pdev);
243 /* Get PCI bus information. */
244 spin_lock_irqsave(&ha->hardware_lock, flags);
245 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
246 spin_unlock_irqrestore(&ha->hardware_lock, flags);
252 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
255 * Returns 0 on success.
258 qla24xx_pci_config(scsi_qla_host_t *vha)
261 unsigned long flags = 0;
262 struct qla_hw_data *ha = vha->hw;
263 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
265 pci_set_master(ha->pdev);
266 pci_try_set_mwi(ha->pdev);
268 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
269 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
270 w &= ~PCI_COMMAND_INTX_DISABLE;
271 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
273 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
275 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
276 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
277 pcix_set_mmrbc(ha->pdev, 2048);
279 /* PCIe -- adjust Maximum Read Request Size (2048). */
280 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
281 pcie_set_readrq(ha->pdev, 2048);
283 pci_disable_rom(ha->pdev);
285 ha->chip_revision = ha->pdev->revision;
287 /* Get PCI bus information. */
288 spin_lock_irqsave(&ha->hardware_lock, flags);
289 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
290 spin_unlock_irqrestore(&ha->hardware_lock, flags);
296 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
299 * Returns 0 on success.
302 qla25xx_pci_config(scsi_qla_host_t *vha)
305 struct qla_hw_data *ha = vha->hw;
307 pci_set_master(ha->pdev);
308 pci_try_set_mwi(ha->pdev);
310 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
311 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
312 w &= ~PCI_COMMAND_INTX_DISABLE;
313 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
315 /* PCIe -- adjust Maximum Read Request Size (2048). */
316 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
317 pcie_set_readrq(ha->pdev, 2048);
319 pci_disable_rom(ha->pdev);
321 ha->chip_revision = ha->pdev->revision;
327 * qla2x00_isp_firmware() - Choose firmware image.
330 * Returns 0 on success.
333 qla2x00_isp_firmware(scsi_qla_host_t *vha)
336 uint16_t loop_id, topo, sw_cap;
337 uint8_t domain, area, al_pa;
338 struct qla_hw_data *ha = vha->hw;
340 /* Assume loading risc code */
341 rval = QLA_FUNCTION_FAILED;
343 if (ha->flags.disable_risc_code_load) {
344 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
346 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
348 /* Verify checksum of loaded RISC code. */
349 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
350 if (rval == QLA_SUCCESS) {
351 /* And, verify we are not in ROM code. */
352 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
353 &area, &domain, &topo, &sw_cap);
358 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
366 * qla2x00_reset_chip() - Reset ISP chip.
369 * Returns 0 on success.
372 qla2x00_reset_chip(scsi_qla_host_t *vha)
374 unsigned long flags = 0;
375 struct qla_hw_data *ha = vha->hw;
376 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
380 ha->isp_ops->disable_intrs(ha);
382 spin_lock_irqsave(&ha->hardware_lock, flags);
384 /* Turn off master enable */
386 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
387 cmd &= ~PCI_COMMAND_MASTER;
388 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
390 if (!IS_QLA2100(ha)) {
392 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
393 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
394 for (cnt = 0; cnt < 30000; cnt++) {
395 if ((RD_REG_WORD(®->hccr) &
396 HCCR_RISC_PAUSE) != 0)
401 RD_REG_WORD(®->hccr); /* PCI Posting. */
405 /* Select FPM registers. */
406 WRT_REG_WORD(®->ctrl_status, 0x20);
407 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
409 /* FPM Soft Reset. */
410 WRT_REG_WORD(®->fpm_diag_config, 0x100);
411 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
413 /* Toggle Fpm Reset. */
414 if (!IS_QLA2200(ha)) {
415 WRT_REG_WORD(®->fpm_diag_config, 0x0);
416 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
419 /* Select frame buffer registers. */
420 WRT_REG_WORD(®->ctrl_status, 0x10);
421 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
423 /* Reset frame buffer FIFOs. */
424 if (IS_QLA2200(ha)) {
425 WRT_FB_CMD_REG(ha, reg, 0xa000);
426 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
428 WRT_FB_CMD_REG(ha, reg, 0x00fc);
430 /* Read back fb_cmd until zero or 3 seconds max */
431 for (cnt = 0; cnt < 3000; cnt++) {
432 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
438 /* Select RISC module registers. */
439 WRT_REG_WORD(®->ctrl_status, 0);
440 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
442 /* Reset RISC processor. */
443 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
444 RD_REG_WORD(®->hccr); /* PCI Posting. */
446 /* Release RISC processor. */
447 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
448 RD_REG_WORD(®->hccr); /* PCI Posting. */
451 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
452 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
454 /* Reset ISP chip. */
455 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
457 /* Wait for RISC to recover from reset. */
458 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
460 * It is necessary to for a delay here since the card doesn't
461 * respond to PCI reads during a reset. On some architectures
462 * this will result in an MCA.
465 for (cnt = 30000; cnt; cnt--) {
466 if ((RD_REG_WORD(®->ctrl_status) &
467 CSR_ISP_SOFT_RESET) == 0)
474 /* Reset RISC processor. */
475 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
477 WRT_REG_WORD(®->semaphore, 0);
479 /* Release RISC processor. */
480 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
481 RD_REG_WORD(®->hccr); /* PCI Posting. */
483 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
484 for (cnt = 0; cnt < 30000; cnt++) {
485 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
493 /* Turn on master enable */
494 cmd |= PCI_COMMAND_MASTER;
495 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
497 /* Disable RISC pause on FPM parity error. */
498 if (!IS_QLA2100(ha)) {
499 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
500 RD_REG_WORD(®->hccr); /* PCI Posting. */
503 spin_unlock_irqrestore(&ha->hardware_lock, flags);
507 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
510 * Returns 0 on success.
513 qla24xx_reset_risc(scsi_qla_host_t *vha)
516 unsigned long flags = 0;
517 struct qla_hw_data *ha = vha->hw;
518 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
522 spin_lock_irqsave(&ha->hardware_lock, flags);
525 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
526 for (cnt = 0; cnt < 30000; cnt++) {
527 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
533 WRT_REG_DWORD(®->ctrl_status,
534 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
535 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
538 /* Wait for firmware to complete NVRAM accesses. */
539 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
540 for (cnt = 10000 ; cnt && d2; cnt--) {
542 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
548 /* Wait for soft-reset to complete. */
549 d2 = RD_REG_DWORD(®->ctrl_status);
550 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
552 d2 = RD_REG_DWORD(®->ctrl_status);
556 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
557 RD_REG_DWORD(®->hccr);
559 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
560 RD_REG_DWORD(®->hccr);
562 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
563 RD_REG_DWORD(®->hccr);
565 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
566 for (cnt = 6000000 ; cnt && d2; cnt--) {
568 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
572 spin_unlock_irqrestore(&ha->hardware_lock, flags);
574 if (IS_NOPOLLING_TYPE(ha))
575 ha->isp_ops->enable_intrs(ha);
579 * qla24xx_reset_chip() - Reset ISP24xx chip.
582 * Returns 0 on success.
585 qla24xx_reset_chip(scsi_qla_host_t *vha)
587 struct qla_hw_data *ha = vha->hw;
588 ha->isp_ops->disable_intrs(ha);
590 /* Perform RISC reset. */
591 qla24xx_reset_risc(vha);
595 * qla2x00_chip_diag() - Test chip for proper operation.
598 * Returns 0 on success.
601 qla2x00_chip_diag(scsi_qla_host_t *vha)
604 struct qla_hw_data *ha = vha->hw;
605 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
606 unsigned long flags = 0;
610 struct req_que *req = ha->req_q_map[0];
612 /* Assume a failed state */
613 rval = QLA_FUNCTION_FAILED;
615 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
616 vha->host_no, (u_long)®->flash_address));
618 spin_lock_irqsave(&ha->hardware_lock, flags);
620 /* Reset ISP chip. */
621 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
624 * We need to have a delay here since the card will not respond while
625 * in reset causing an MCA on some architectures.
628 data = qla2x00_debounce_register(®->ctrl_status);
629 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
631 data = RD_REG_WORD(®->ctrl_status);
636 goto chip_diag_failed;
638 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
641 /* Reset RISC processor. */
642 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
643 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
645 /* Workaround for QLA2312 PCI parity error */
646 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
647 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
648 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
650 data = RD_MAILBOX_REG(ha, reg, 0);
657 goto chip_diag_failed;
659 /* Check product ID of chip */
660 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
662 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
663 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
664 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
665 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
666 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
667 mb[3] != PROD_ID_3) {
668 qla_printk(KERN_WARNING, ha,
669 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
671 goto chip_diag_failed;
673 ha->product_id[0] = mb[1];
674 ha->product_id[1] = mb[2];
675 ha->product_id[2] = mb[3];
676 ha->product_id[3] = mb[4];
678 /* Adjust fw RISC transfer size */
679 if (req->length > 1024)
680 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
682 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
685 if (IS_QLA2200(ha) &&
686 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
687 /* Limit firmware transfer size with a 2200A */
688 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
691 ha->device_type |= DT_ISP2200A;
692 ha->fw_transfer_size = 128;
695 /* Wrap Incoming Mailboxes Test. */
696 spin_unlock_irqrestore(&ha->hardware_lock, flags);
698 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
699 rval = qla2x00_mbx_reg_test(vha);
701 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
703 qla_printk(KERN_WARNING, ha,
704 "Failed mailbox send register test\n");
707 /* Flag a successful rval */
710 spin_lock_irqsave(&ha->hardware_lock, flags);
714 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
715 "****\n", vha->host_no));
717 spin_unlock_irqrestore(&ha->hardware_lock, flags);
723 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
726 * Returns 0 on success.
729 qla24xx_chip_diag(scsi_qla_host_t *vha)
732 struct qla_hw_data *ha = vha->hw;
733 struct req_que *req = ha->req_q_map[0];
735 /* Perform RISC reset. */
736 qla24xx_reset_risc(vha);
738 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
740 rval = qla2x00_mbx_reg_test(vha);
742 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
744 qla_printk(KERN_WARNING, ha,
745 "Failed mailbox send register test\n");
747 /* Flag a successful rval */
755 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
758 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
759 eft_size, fce_size, mq_size;
762 struct qla_hw_data *ha = vha->hw;
763 struct req_que *req = ha->req_q_map[0];
764 struct rsp_que *rsp = ha->rsp_q_map[0];
767 qla_printk(KERN_WARNING, ha,
768 "Firmware dump previously allocated.\n");
773 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
774 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
775 fixed_size = sizeof(struct qla2100_fw_dump);
776 } else if (IS_QLA23XX(ha)) {
777 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
778 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
780 } else if (IS_FWI2_CAPABLE(ha)) {
782 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
783 else if (IS_QLA25XX(ha))
784 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
786 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
787 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
790 mq_size = sizeof(struct qla2xxx_mq_chain);
792 /* Allocate memory for Fibre Channel Event Buffer. */
793 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
796 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
799 qla_printk(KERN_WARNING, ha, "Unable to allocate "
800 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
804 memset(tc, 0, FCE_SIZE);
805 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
806 ha->fce_mb, &ha->fce_bufs);
808 qla_printk(KERN_WARNING, ha, "Unable to initialize "
809 "FCE (%d).\n", rval);
810 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
812 ha->flags.fce_enabled = 0;
816 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
819 fce_size = sizeof(struct qla2xxx_fce_chain) + EFT_SIZE;
820 ha->flags.fce_enabled = 1;
821 ha->fce_dma = tc_dma;
824 /* Allocate memory for Extended Trace Buffer. */
825 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
828 qla_printk(KERN_WARNING, ha, "Unable to allocate "
829 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
833 memset(tc, 0, EFT_SIZE);
834 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
836 qla_printk(KERN_WARNING, ha, "Unable to initialize "
837 "EFT (%d).\n", rval);
838 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
843 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
847 ha->eft_dma = tc_dma;
851 req_q_size = req->length * sizeof(request_t);
852 rsp_q_size = rsp->length * sizeof(response_t);
854 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
855 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
857 ha->chain_offset = dump_size;
858 dump_size += mq_size + fce_size;
860 ha->fw_dump = vmalloc(dump_size);
862 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
863 "firmware dump!!!\n", dump_size / 1024);
866 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
873 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
876 ha->fw_dump_len = dump_size;
877 ha->fw_dump->signature[0] = 'Q';
878 ha->fw_dump->signature[1] = 'L';
879 ha->fw_dump->signature[2] = 'G';
880 ha->fw_dump->signature[3] = 'C';
881 ha->fw_dump->version = __constant_htonl(1);
883 ha->fw_dump->fixed_size = htonl(fixed_size);
884 ha->fw_dump->mem_size = htonl(mem_size);
885 ha->fw_dump->req_q_size = htonl(req_q_size);
886 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
888 ha->fw_dump->eft_size = htonl(eft_size);
889 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
890 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
892 ha->fw_dump->header_size =
893 htonl(offsetof(struct qla2xxx_fw_dump, isp));
897 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
900 * Returns 0 on success.
903 qla2x00_resize_request_q(scsi_qla_host_t *vha)
906 uint16_t fw_iocb_cnt = 0;
907 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
908 dma_addr_t request_dma;
909 request_t *request_ring;
910 struct qla_hw_data *ha = vha->hw;
911 struct req_que *req = ha->req_q_map[0];
913 /* Valid only on recent ISPs. */
914 if (IS_QLA2100(ha) || IS_QLA2200(ha))
917 /* Retrieve IOCB counts available to the firmware. */
918 rval = qla2x00_get_resource_cnts(vha, NULL, NULL, NULL, &fw_iocb_cnt,
919 &ha->max_npiv_vports);
922 /* No point in continuing if current settings are sufficient. */
923 if (fw_iocb_cnt < 1024)
925 if (req->length >= request_q_length)
928 /* Attempt to claim larger area for request queue. */
929 request_ring = dma_alloc_coherent(&ha->pdev->dev,
930 (request_q_length + 1) * sizeof(request_t), &request_dma,
932 if (request_ring == NULL)
935 /* Resize successful, report extensions. */
936 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
937 (ha->fw_memory_size + 1) / 1024);
938 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
939 "(%d -> %d)...\n", req->length, request_q_length);
941 /* Clear old allocations. */
942 dma_free_coherent(&ha->pdev->dev,
943 (req->length + 1) * sizeof(request_t), req->ring,
946 /* Begin using larger queue. */
947 req->length = request_q_length;
948 req->ring = request_ring;
949 req->dma = request_dma;
953 * qla2x00_setup_chip() - Load and start RISC firmware.
956 * Returns 0 on success.
959 qla2x00_setup_chip(scsi_qla_host_t *vha)
962 uint32_t srisc_address = 0;
963 struct qla_hw_data *ha = vha->hw;
964 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
967 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
968 /* Disable SRAM, Instruction RAM and GP RAM parity. */
969 spin_lock_irqsave(&ha->hardware_lock, flags);
970 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
971 RD_REG_WORD(®->hccr);
972 spin_unlock_irqrestore(&ha->hardware_lock, flags);
975 /* Load firmware sequences */
976 rval = ha->isp_ops->load_risc(vha, &srisc_address);
977 if (rval == QLA_SUCCESS) {
978 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
979 "code.\n", vha->host_no));
981 rval = qla2x00_verify_checksum(vha, srisc_address);
982 if (rval == QLA_SUCCESS) {
983 /* Start firmware execution. */
984 DEBUG(printk("scsi(%ld): Checksum OK, start "
985 "firmware.\n", vha->host_no));
987 rval = qla2x00_execute_fw(vha, srisc_address);
988 /* Retrieve firmware information. */
989 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
990 qla2x00_get_fw_version(vha,
991 &ha->fw_major_version,
992 &ha->fw_minor_version,
993 &ha->fw_subminor_version,
994 &ha->fw_attributes, &ha->fw_memory_size,
995 ha->mpi_version, &ha->mpi_capabilities);
996 ha->flags.npiv_supported = 0;
997 if (IS_QLA2XXX_MIDTYPE(ha) &&
998 (ha->fw_attributes & BIT_2)) {
999 ha->flags.npiv_supported = 1;
1000 if ((!ha->max_npiv_vports) ||
1001 ((ha->max_npiv_vports + 1) %
1002 MIN_MULTI_ID_FABRIC))
1003 ha->max_npiv_vports =
1004 MIN_MULTI_ID_FABRIC - 1;
1006 qla2x00_resize_request_q(vha);
1008 if (ql2xallocfwdump)
1009 qla2x00_alloc_fw_dump(vha);
1012 DEBUG2(printk(KERN_INFO
1013 "scsi(%ld): ISP Firmware failed checksum.\n",
1018 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1019 /* Enable proper parity. */
1020 spin_lock_irqsave(&ha->hardware_lock, flags);
1023 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
1025 /* SRAM, Instruction RAM and GP RAM parity */
1026 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
1027 RD_REG_WORD(®->hccr);
1028 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1032 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
1040 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1043 * Beginning of request ring has initialization control block already built
1044 * by nvram config routine.
1046 * Returns 0 on success.
1049 qla2x00_init_response_q_entries(struct rsp_que *rsp)
1054 pkt = rsp->ring_ptr;
1055 for (cnt = 0; cnt < rsp->length; cnt++) {
1056 pkt->signature = RESPONSE_PROCESSED;
1063 * qla2x00_update_fw_options() - Read and process firmware options.
1066 * Returns 0 on success.
1069 qla2x00_update_fw_options(scsi_qla_host_t *vha)
1071 uint16_t swing, emphasis, tx_sens, rx_sens;
1072 struct qla_hw_data *ha = vha->hw;
1074 memset(ha->fw_options, 0, sizeof(ha->fw_options));
1075 qla2x00_get_fw_options(vha, ha->fw_options);
1077 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1080 /* Serial Link options. */
1081 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1083 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1084 sizeof(ha->fw_seriallink_options)));
1086 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1087 if (ha->fw_seriallink_options[3] & BIT_2) {
1088 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1091 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1092 emphasis = (ha->fw_seriallink_options[2] &
1093 (BIT_4 | BIT_3)) >> 3;
1094 tx_sens = ha->fw_seriallink_options[0] &
1095 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1096 rx_sens = (ha->fw_seriallink_options[0] &
1097 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1098 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1099 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1102 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1103 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1104 ha->fw_options[10] |= BIT_5 |
1105 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1106 (tx_sens & (BIT_1 | BIT_0));
1109 swing = (ha->fw_seriallink_options[2] &
1110 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1111 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1112 tx_sens = ha->fw_seriallink_options[1] &
1113 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1114 rx_sens = (ha->fw_seriallink_options[1] &
1115 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1116 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1117 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1120 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1121 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1122 ha->fw_options[11] |= BIT_5 |
1123 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1124 (tx_sens & (BIT_1 | BIT_0));
1128 /* Return command IOCBs without waiting for an ABTS to complete. */
1129 ha->fw_options[3] |= BIT_13;
1132 if (ha->flags.enable_led_scheme)
1133 ha->fw_options[2] |= BIT_12;
1135 /* Detect ISP6312. */
1137 ha->fw_options[2] |= BIT_13;
1139 /* Update firmware options. */
1140 qla2x00_set_fw_options(vha, ha->fw_options);
1144 qla24xx_update_fw_options(scsi_qla_host_t *vha)
1147 struct qla_hw_data *ha = vha->hw;
1149 /* Update Serial Link options. */
1150 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1153 rval = qla2x00_set_serdes_params(vha,
1154 le16_to_cpu(ha->fw_seriallink_options24[1]),
1155 le16_to_cpu(ha->fw_seriallink_options24[2]),
1156 le16_to_cpu(ha->fw_seriallink_options24[3]));
1157 if (rval != QLA_SUCCESS) {
1158 qla_printk(KERN_WARNING, ha,
1159 "Unable to update Serial Link options (%x).\n", rval);
1164 qla2x00_config_rings(struct scsi_qla_host *vha)
1166 struct qla_hw_data *ha = vha->hw;
1167 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1168 struct req_que *req = ha->req_q_map[0];
1169 struct rsp_que *rsp = ha->rsp_q_map[0];
1171 /* Setup ring parameters in initialization control block. */
1172 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1173 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1174 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1175 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1176 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1177 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1178 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1179 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
1181 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1182 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1183 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1184 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1185 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1189 qla24xx_config_rings(struct scsi_qla_host *vha)
1191 struct qla_hw_data *ha = vha->hw;
1192 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1193 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1194 struct qla_msix_entry *msix;
1195 struct init_cb_24xx *icb;
1197 struct req_que *req = ha->req_q_map[0];
1198 struct rsp_que *rsp = ha->rsp_q_map[0];
1200 /* Setup ring parameters in initialization control block. */
1201 icb = (struct init_cb_24xx *)ha->init_cb;
1202 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1203 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1204 icb->request_q_length = cpu_to_le16(req->length);
1205 icb->response_q_length = cpu_to_le16(rsp->length);
1206 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1207 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1208 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1209 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
1212 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1213 icb->rid = __constant_cpu_to_le16(rid);
1214 if (ha->flags.msix_enabled) {
1215 msix = &ha->msix_entries[1];
1216 DEBUG2_17(printk(KERN_INFO
1217 "Reistering vector 0x%x for base que\n", msix->entry));
1218 icb->msix = cpu_to_le16(msix->entry);
1220 /* Use alternate PCI bus number */
1222 icb->firmware_options_2 |=
1223 __constant_cpu_to_le32(BIT_19);
1224 /* Use alternate PCI devfn */
1226 icb->firmware_options_2 |=
1227 __constant_cpu_to_le32(BIT_18);
1229 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
1230 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
1231 ha->rsp_q_map[0]->options = icb->firmware_options_2;
1233 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
1234 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
1235 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
1236 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
1238 WRT_REG_DWORD(®->isp24.req_q_in, 0);
1239 WRT_REG_DWORD(®->isp24.req_q_out, 0);
1240 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
1241 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
1244 RD_REG_DWORD(&ioreg->hccr);
1248 * qla2x00_init_rings() - Initializes firmware.
1251 * Beginning of request ring has initialization control block already built
1252 * by nvram config routine.
1254 * Returns 0 on success.
1257 qla2x00_init_rings(scsi_qla_host_t *vha)
1260 unsigned long flags = 0;
1262 struct qla_hw_data *ha = vha->hw;
1263 struct req_que *req;
1264 struct rsp_que *rsp;
1265 struct scsi_qla_host *vp;
1266 struct mid_init_cb_24xx *mid_init_cb =
1267 (struct mid_init_cb_24xx *) ha->init_cb;
1269 spin_lock_irqsave(&ha->hardware_lock, flags);
1271 /* Clear outstanding commands array. */
1272 for (que = 0; que < ha->max_queues; que++) {
1273 req = ha->req_q_map[que];
1276 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1277 req->outstanding_cmds[cnt] = NULL;
1279 req->current_outstanding_cmd = 0;
1281 /* Initialize firmware. */
1282 req->ring_ptr = req->ring;
1283 req->ring_index = 0;
1284 req->cnt = req->length;
1287 for (que = 0; que < ha->max_queues; que++) {
1288 rsp = ha->rsp_q_map[que];
1291 rsp->ring_ptr = rsp->ring;
1292 rsp->ring_index = 0;
1294 /* Initialize response queue entries */
1295 qla2x00_init_response_q_entries(rsp);
1298 /* Clear RSCN queue. */
1299 list_for_each_entry(vp, &ha->vp_list, list) {
1300 vp->rscn_in_ptr = 0;
1301 vp->rscn_out_ptr = 0;
1303 ha->isp_ops->config_rings(vha);
1305 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1307 /* Update any ISP specific firmware options before initialization. */
1308 ha->isp_ops->update_fw_options(vha);
1310 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
1312 if (ha->flags.npiv_supported)
1313 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1315 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1317 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
1319 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1322 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1330 * qla2x00_fw_ready() - Waits for firmware ready.
1333 * Returns 0 on success.
1336 qla2x00_fw_ready(scsi_qla_host_t *vha)
1339 unsigned long wtime, mtime, cs84xx_time;
1340 uint16_t min_wait; /* Minimum wait time if loop is down */
1341 uint16_t wait_time; /* Wait time if loop is coming ready */
1343 struct qla_hw_data *ha = vha->hw;
1347 /* 20 seconds for loop down. */
1351 * Firmware should take at most one RATOV to login, plus 5 seconds for
1352 * our own processing.
1354 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1355 wait_time = min_wait;
1358 /* Min wait time if loop down */
1359 mtime = jiffies + (min_wait * HZ);
1361 /* wait time before firmware ready */
1362 wtime = jiffies + (wait_time * HZ);
1364 /* Wait for ISP to finish LIP */
1365 if (!vha->flags.init_done)
1366 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1368 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1372 rval = qla2x00_get_firmware_state(vha, state);
1373 if (rval == QLA_SUCCESS) {
1374 if (state[0] < FSTATE_LOSS_OF_SYNC) {
1375 vha->device_flags &= ~DFLG_NO_CABLE;
1377 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1378 DEBUG16(printk("scsi(%ld): fw_state=%x "
1379 "84xx=%x.\n", vha->host_no, state[0],
1381 if ((state[2] & FSTATE_LOGGED_IN) &&
1382 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1383 DEBUG16(printk("scsi(%ld): Sending "
1384 "verify iocb.\n", vha->host_no));
1386 cs84xx_time = jiffies;
1387 rval = qla84xx_init_chip(vha);
1388 if (rval != QLA_SUCCESS)
1391 /* Add time taken to initialize. */
1392 cs84xx_time = jiffies - cs84xx_time;
1393 wtime += cs84xx_time;
1394 mtime += cs84xx_time;
1395 DEBUG16(printk("scsi(%ld): Increasing "
1396 "wait time by %ld. New time %ld\n",
1397 vha->host_no, cs84xx_time, wtime));
1399 } else if (state[0] == FSTATE_READY) {
1400 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1403 qla2x00_get_retry_cnt(vha, &ha->retry_count,
1404 &ha->login_timeout, &ha->r_a_tov);
1410 rval = QLA_FUNCTION_FAILED;
1412 if (atomic_read(&vha->loop_down_timer) &&
1413 state[0] != FSTATE_READY) {
1414 /* Loop down. Timeout on min_wait for states
1415 * other than Wait for Login.
1417 if (time_after_eq(jiffies, mtime)) {
1418 qla_printk(KERN_INFO, ha,
1419 "Cable is unplugged...\n");
1421 vha->device_flags |= DFLG_NO_CABLE;
1426 /* Mailbox cmd failed. Timeout on min_wait. */
1427 if (time_after_eq(jiffies, mtime))
1431 if (time_after_eq(jiffies, wtime))
1434 /* Delay for a while */
1437 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1438 vha->host_no, state[0], jiffies));
1441 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1442 vha->host_no, state[0], jiffies));
1445 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1453 * qla2x00_configure_hba
1454 * Setup adapter context.
1457 * ha = adapter state pointer.
1466 qla2x00_configure_hba(scsi_qla_host_t *vha)
1475 char connect_type[22];
1476 struct qla_hw_data *ha = vha->hw;
1478 /* Get host addresses. */
1479 rval = qla2x00_get_adapter_id(vha,
1480 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
1481 if (rval != QLA_SUCCESS) {
1482 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
1483 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1484 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1485 __func__, vha->host_no));
1487 qla_printk(KERN_WARNING, ha,
1488 "ERROR -- Unable to get host loop ID.\n");
1489 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1495 qla_printk(KERN_INFO, ha,
1496 "Cannot get topology - retrying.\n");
1497 return (QLA_FUNCTION_FAILED);
1500 vha->loop_id = loop_id;
1503 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1504 ha->operating_mode = LOOP;
1509 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1511 ha->current_topology = ISP_CFG_NL;
1512 strcpy(connect_type, "(Loop)");
1516 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1518 ha->switch_cap = sw_cap;
1519 ha->current_topology = ISP_CFG_FL;
1520 strcpy(connect_type, "(FL_Port)");
1524 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1526 ha->operating_mode = P2P;
1527 ha->current_topology = ISP_CFG_N;
1528 strcpy(connect_type, "(N_Port-to-N_Port)");
1532 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1534 ha->switch_cap = sw_cap;
1535 ha->operating_mode = P2P;
1536 ha->current_topology = ISP_CFG_F;
1537 strcpy(connect_type, "(F_Port)");
1541 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1543 vha->host_no, topo));
1544 ha->current_topology = ISP_CFG_NL;
1545 strcpy(connect_type, "(Loop)");
1549 /* Save Host port and loop ID. */
1550 /* byte order - Big Endian */
1551 vha->d_id.b.domain = domain;
1552 vha->d_id.b.area = area;
1553 vha->d_id.b.al_pa = al_pa;
1555 if (!vha->flags.init_done)
1556 qla_printk(KERN_INFO, ha,
1557 "Topology - %s, Host Loop address 0x%x\n",
1558 connect_type, vha->loop_id);
1561 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
1563 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
1570 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1575 struct qla_hw_data *ha = vha->hw;
1577 if (memcmp(model, BINZERO, len) != 0) {
1578 strncpy(ha->model_number, model, len);
1579 st = en = ha->model_number;
1582 if (*en != 0x20 && *en != 0x00)
1587 index = (ha->pdev->subsystem_device & 0xff);
1588 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1589 index < QLA_MODEL_NAMES)
1590 strncpy(ha->model_desc,
1591 qla2x00_model_name[index * 2 + 1],
1592 sizeof(ha->model_desc) - 1);
1594 index = (ha->pdev->subsystem_device & 0xff);
1595 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1596 index < QLA_MODEL_NAMES) {
1597 strcpy(ha->model_number,
1598 qla2x00_model_name[index * 2]);
1599 strncpy(ha->model_desc,
1600 qla2x00_model_name[index * 2 + 1],
1601 sizeof(ha->model_desc) - 1);
1603 strcpy(ha->model_number, def);
1606 if (IS_FWI2_CAPABLE(ha))
1607 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
1608 sizeof(ha->model_desc));
1611 /* On sparc systems, obtain port and node WWN from firmware
1614 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
1617 struct qla_hw_data *ha = vha->hw;
1618 struct pci_dev *pdev = ha->pdev;
1619 struct device_node *dp = pci_device_to_OF_node(pdev);
1623 val = of_get_property(dp, "port-wwn", &len);
1624 if (val && len >= WWN_SIZE)
1625 memcpy(nv->port_name, val, WWN_SIZE);
1627 val = of_get_property(dp, "node-wwn", &len);
1628 if (val && len >= WWN_SIZE)
1629 memcpy(nv->node_name, val, WWN_SIZE);
1634 * NVRAM configuration for ISP 2xxx
1637 * ha = adapter block pointer.
1640 * initialization control block in response_ring
1641 * host adapters parameters in host adapter block
1647 qla2x00_nvram_config(scsi_qla_host_t *vha)
1652 uint8_t *dptr1, *dptr2;
1653 struct qla_hw_data *ha = vha->hw;
1654 init_cb_t *icb = ha->init_cb;
1655 nvram_t *nv = ha->nvram;
1656 uint8_t *ptr = ha->nvram;
1657 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1661 /* Determine NVRAM starting address. */
1662 ha->nvram_size = sizeof(nvram_t);
1664 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1665 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1666 ha->nvram_base = 0x80;
1668 /* Get NVRAM data and calculate checksum. */
1669 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
1670 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1673 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
1674 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
1676 /* Bad NVRAM data, set defaults parameters. */
1677 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1678 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1679 /* Reset NVRAM data. */
1680 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1681 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1683 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1684 "invalid -- WWPN) defaults.\n");
1687 * Set default initialization control block.
1689 memset(nv, 0, ha->nvram_size);
1690 nv->parameter_block_version = ICB_VERSION;
1692 if (IS_QLA23XX(ha)) {
1693 nv->firmware_options[0] = BIT_2 | BIT_1;
1694 nv->firmware_options[1] = BIT_7 | BIT_5;
1695 nv->add_firmware_options[0] = BIT_5;
1696 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1697 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1698 nv->special_options[1] = BIT_7;
1699 } else if (IS_QLA2200(ha)) {
1700 nv->firmware_options[0] = BIT_2 | BIT_1;
1701 nv->firmware_options[1] = BIT_7 | BIT_5;
1702 nv->add_firmware_options[0] = BIT_5;
1703 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1704 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1705 } else if (IS_QLA2100(ha)) {
1706 nv->firmware_options[0] = BIT_3 | BIT_1;
1707 nv->firmware_options[1] = BIT_5;
1708 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1711 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1712 nv->execution_throttle = __constant_cpu_to_le16(16);
1713 nv->retry_count = 8;
1714 nv->retry_delay = 1;
1716 nv->port_name[0] = 33;
1717 nv->port_name[3] = 224;
1718 nv->port_name[4] = 139;
1720 qla2xxx_nvram_wwn_from_ofw(vha, nv);
1722 nv->login_timeout = 4;
1725 * Set default host adapter parameters
1727 nv->host_p[1] = BIT_2;
1728 nv->reset_delay = 5;
1729 nv->port_down_retry_count = 8;
1730 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1731 nv->link_down_timeout = 60;
1736 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1738 * The SN2 does not provide BIOS emulation which means you can't change
1739 * potentially bogus BIOS settings. Force the use of default settings
1740 * for link rate and frame size. Hope that the rest of the settings
1743 if (ia64_platform_is("sn2")) {
1744 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1746 nv->special_options[1] = BIT_7;
1750 /* Reset Initialization control block */
1751 memset(icb, 0, ha->init_cb_size);
1754 * Setup driver NVRAM options.
1756 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1757 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1758 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1759 nv->firmware_options[1] &= ~BIT_4;
1761 if (IS_QLA23XX(ha)) {
1762 nv->firmware_options[0] |= BIT_2;
1763 nv->firmware_options[0] &= ~BIT_3;
1764 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1766 if (IS_QLA2300(ha)) {
1767 if (ha->fb_rev == FPM_2310) {
1768 strcpy(ha->model_number, "QLA2310");
1770 strcpy(ha->model_number, "QLA2300");
1773 qla2x00_set_model_info(vha, nv->model_number,
1774 sizeof(nv->model_number), "QLA23xx");
1776 } else if (IS_QLA2200(ha)) {
1777 nv->firmware_options[0] |= BIT_2;
1779 * 'Point-to-point preferred, else loop' is not a safe
1780 * connection mode setting.
1782 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1784 /* Force 'loop preferred, else point-to-point'. */
1785 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1786 nv->add_firmware_options[0] |= BIT_5;
1788 strcpy(ha->model_number, "QLA22xx");
1789 } else /*if (IS_QLA2100(ha))*/ {
1790 strcpy(ha->model_number, "QLA2100");
1794 * Copy over NVRAM RISC parameter block to initialization control block.
1796 dptr1 = (uint8_t *)icb;
1797 dptr2 = (uint8_t *)&nv->parameter_block_version;
1798 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1800 *dptr1++ = *dptr2++;
1802 /* Copy 2nd half. */
1803 dptr1 = (uint8_t *)icb->add_firmware_options;
1804 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1806 *dptr1++ = *dptr2++;
1808 /* Use alternate WWN? */
1809 if (nv->host_p[1] & BIT_7) {
1810 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1811 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1814 /* Prepare nodename */
1815 if ((icb->firmware_options[1] & BIT_6) == 0) {
1817 * Firmware will apply the following mask if the nodename was
1820 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1821 icb->node_name[0] &= 0xF0;
1825 * Set host adapter parameters.
1827 if (nv->host_p[0] & BIT_7)
1828 ql2xextended_error_logging = 1;
1829 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1830 /* Always load RISC code on non ISP2[12]00 chips. */
1831 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1832 ha->flags.disable_risc_code_load = 0;
1833 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1834 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1835 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1836 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1837 ha->flags.disable_serdes = 0;
1839 ha->operating_mode =
1840 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1842 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1843 sizeof(ha->fw_seriallink_options));
1845 /* save HBA serial number */
1846 ha->serial0 = icb->port_name[5];
1847 ha->serial1 = icb->port_name[6];
1848 ha->serial2 = icb->port_name[7];
1849 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
1850 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
1852 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1854 ha->retry_count = nv->retry_count;
1856 /* Set minimum login_timeout to 4 seconds. */
1857 if (nv->login_timeout < ql2xlogintimeout)
1858 nv->login_timeout = ql2xlogintimeout;
1859 if (nv->login_timeout < 4)
1860 nv->login_timeout = 4;
1861 ha->login_timeout = nv->login_timeout;
1862 icb->login_timeout = nv->login_timeout;
1864 /* Set minimum RATOV to 100 tenths of a second. */
1867 ha->loop_reset_delay = nv->reset_delay;
1869 /* Link Down Timeout = 0:
1871 * When Port Down timer expires we will start returning
1872 * I/O's to OS with "DID_NO_CONNECT".
1874 * Link Down Timeout != 0:
1876 * The driver waits for the link to come up after link down
1877 * before returning I/Os to OS with "DID_NO_CONNECT".
1879 if (nv->link_down_timeout == 0) {
1880 ha->loop_down_abort_time =
1881 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1883 ha->link_down_timeout = nv->link_down_timeout;
1884 ha->loop_down_abort_time =
1885 (LOOP_DOWN_TIME - ha->link_down_timeout);
1889 * Need enough time to try and get the port back.
1891 ha->port_down_retry_count = nv->port_down_retry_count;
1892 if (qlport_down_retry)
1893 ha->port_down_retry_count = qlport_down_retry;
1894 /* Set login_retry_count */
1895 ha->login_retry_count = nv->retry_count;
1896 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1897 ha->port_down_retry_count > 3)
1898 ha->login_retry_count = ha->port_down_retry_count;
1899 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1900 ha->login_retry_count = ha->port_down_retry_count;
1901 if (ql2xloginretrycount)
1902 ha->login_retry_count = ql2xloginretrycount;
1904 icb->lun_enables = __constant_cpu_to_le16(0);
1905 icb->command_resource_count = 0;
1906 icb->immediate_notify_resource_count = 0;
1907 icb->timeout = __constant_cpu_to_le16(0);
1909 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1911 icb->firmware_options[0] &= ~BIT_3;
1912 icb->add_firmware_options[0] &=
1913 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1914 icb->add_firmware_options[0] |= BIT_2;
1915 icb->response_accumulation_timer = 3;
1916 icb->interrupt_delay_timer = 5;
1918 vha->flags.process_response_queue = 1;
1921 if (!vha->flags.init_done) {
1922 ha->zio_mode = icb->add_firmware_options[0] &
1923 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1924 ha->zio_timer = icb->interrupt_delay_timer ?
1925 icb->interrupt_delay_timer: 2;
1927 icb->add_firmware_options[0] &=
1928 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1929 vha->flags.process_response_queue = 0;
1930 if (ha->zio_mode != QLA_ZIO_DISABLED) {
1931 ha->zio_mode = QLA_ZIO_MODE_6;
1933 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1934 "delay (%d us).\n", vha->host_no, ha->zio_mode,
1935 ha->zio_timer * 100));
1936 qla_printk(KERN_INFO, ha,
1937 "ZIO mode %d enabled; timer delay (%d us).\n",
1938 ha->zio_mode, ha->zio_timer * 100);
1940 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1941 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
1942 vha->flags.process_response_queue = 1;
1947 DEBUG2_3(printk(KERN_WARNING
1948 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
1954 qla2x00_rport_del(void *data)
1956 fc_port_t *fcport = data;
1957 struct fc_rport *rport;
1959 spin_lock_irq(fcport->vha->host->host_lock);
1960 rport = fcport->drport;
1961 fcport->drport = NULL;
1962 spin_unlock_irq(fcport->vha->host->host_lock);
1964 fc_remote_port_delete(rport);
1968 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1970 * @flags: allocation flags
1972 * Returns a pointer to the allocated fcport, or NULL, if none available.
1975 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
1979 fcport = kzalloc(sizeof(fc_port_t), flags);
1983 /* Setup fcport template structure. */
1985 fcport->vp_idx = vha->vp_idx;
1986 fcport->port_type = FCT_UNKNOWN;
1987 fcport->loop_id = FC_NO_LOOP_ID;
1988 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1989 fcport->flags = FCF_RLC_SUPPORT;
1990 fcport->supported_classes = FC_COS_UNSPECIFIED;
1996 * qla2x00_configure_loop
1997 * Updates Fibre Channel Device Database with what is actually on loop.
2000 * ha = adapter block pointer.
2005 * 2 = database was full and device was not configured.
2008 qla2x00_configure_loop(scsi_qla_host_t *vha)
2011 unsigned long flags, save_flags;
2012 struct qla_hw_data *ha = vha->hw;
2015 /* Get Initiator ID */
2016 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2017 rval = qla2x00_configure_hba(vha);
2018 if (rval != QLA_SUCCESS) {
2019 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
2025 save_flags = flags = vha->dpc_flags;
2026 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
2027 vha->host_no, flags));
2030 * If we have both an RSCN and PORT UPDATE pending then handle them
2031 * both at the same time.
2033 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2034 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
2036 /* Determine what we need to do */
2037 if (ha->current_topology == ISP_CFG_FL &&
2038 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2040 vha->flags.rscn_queue_overflow = 1;
2041 set_bit(RSCN_UPDATE, &flags);
2043 } else if (ha->current_topology == ISP_CFG_F &&
2044 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2046 vha->flags.rscn_queue_overflow = 1;
2047 set_bit(RSCN_UPDATE, &flags);
2048 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2050 } else if (ha->current_topology == ISP_CFG_N) {
2051 clear_bit(RSCN_UPDATE, &flags);
2053 } else if (!vha->flags.online ||
2054 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2056 vha->flags.rscn_queue_overflow = 1;
2057 set_bit(RSCN_UPDATE, &flags);
2058 set_bit(LOCAL_LOOP_UPDATE, &flags);
2061 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
2062 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2063 rval = QLA_FUNCTION_FAILED;
2065 rval = qla2x00_configure_local_loop(vha);
2068 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
2069 if (LOOP_TRANSITION(vha))
2070 rval = QLA_FUNCTION_FAILED;
2072 rval = qla2x00_configure_fabric(vha);
2075 if (rval == QLA_SUCCESS) {
2076 if (atomic_read(&vha->loop_down_timer) ||
2077 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2078 rval = QLA_FUNCTION_FAILED;
2080 atomic_set(&vha->loop_state, LOOP_READY);
2082 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
2087 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
2088 __func__, vha->host_no));
2090 DEBUG3(printk("%s: exiting normally\n", __func__));
2093 /* Restore state if a resync event occurred during processing */
2094 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2095 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
2096 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2097 if (test_bit(RSCN_UPDATE, &save_flags))
2098 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2107 * qla2x00_configure_local_loop
2108 * Updates Fibre Channel Device Database with local loop devices.
2111 * ha = adapter block pointer.
2117 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
2122 fc_port_t *fcport, *new_fcport;
2128 uint8_t domain, area, al_pa;
2129 struct qla_hw_data *ha = vha->hw;
2133 entries = MAX_FIBRE_DEVICES;
2135 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2136 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
2138 /* Get list of logged in devices. */
2139 memset(ha->gid_list, 0, GID_LIST_SIZE);
2140 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
2142 if (rval != QLA_SUCCESS)
2143 goto cleanup_allocation;
2145 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2146 ha->host_no, entries));
2147 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2148 entries * sizeof(struct gid_list_info)));
2150 /* Allocate temporary fcport for any new fcports discovered. */
2151 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2152 if (new_fcport == NULL) {
2153 rval = QLA_MEMORY_ALLOC_FAILED;
2154 goto cleanup_allocation;
2156 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2159 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2161 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2162 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2163 fcport->port_type != FCT_BROADCAST &&
2164 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2166 DEBUG(printk("scsi(%ld): Marking port lost, "
2168 vha->host_no, fcport->loop_id));
2170 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2171 fcport->flags &= ~FCF_FARP_DONE;
2175 /* Add devices to port list. */
2176 id_iter = (char *)ha->gid_list;
2177 for (index = 0; index < entries; index++) {
2178 domain = ((struct gid_list_info *)id_iter)->domain;
2179 area = ((struct gid_list_info *)id_iter)->area;
2180 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
2181 if (IS_QLA2100(ha) || IS_QLA2200(ha))
2182 loop_id = (uint16_t)
2183 ((struct gid_list_info *)id_iter)->loop_id_2100;
2185 loop_id = le16_to_cpu(
2186 ((struct gid_list_info *)id_iter)->loop_id);
2187 id_iter += ha->gid_list_info_size;
2189 /* Bypass reserved domain fields. */
2190 if ((domain & 0xf0) == 0xf0)
2193 /* Bypass if not same domain and area of adapter. */
2194 if (area && domain &&
2195 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
2198 /* Bypass invalid local loop ID. */
2199 if (loop_id > LAST_LOCAL_LOOP_ID)
2202 /* Fill in member data. */
2203 new_fcport->d_id.b.domain = domain;
2204 new_fcport->d_id.b.area = area;
2205 new_fcport->d_id.b.al_pa = al_pa;
2206 new_fcport->loop_id = loop_id;
2207 new_fcport->vp_idx = vha->vp_idx;
2208 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
2209 if (rval2 != QLA_SUCCESS) {
2210 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2211 "information -- get_port_database=%x, "
2213 vha->host_no, rval2, new_fcport->loop_id));
2214 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2216 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2220 /* Check for matching device in port list. */
2223 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2224 if (memcmp(new_fcport->port_name, fcport->port_name,
2228 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2229 FCF_PERSISTENT_BOUND);
2230 fcport->loop_id = new_fcport->loop_id;
2231 fcport->port_type = new_fcport->port_type;
2232 fcport->d_id.b24 = new_fcport->d_id.b24;
2233 memcpy(fcport->node_name, new_fcport->node_name,
2241 /* New device, add to fcports list. */
2242 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
2244 new_fcport->vha = vha;
2245 new_fcport->vp_idx = vha->vp_idx;
2247 list_add_tail(&new_fcport->list, &vha->vp_fcports);
2249 /* Allocate a new replacement fcport. */
2250 fcport = new_fcport;
2251 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2252 if (new_fcport == NULL) {
2253 rval = QLA_MEMORY_ALLOC_FAILED;
2254 goto cleanup_allocation;
2256 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2259 /* Base iIDMA settings on HBA port speed. */
2260 fcport->fp_speed = ha->link_data_rate;
2262 qla2x00_update_fcport(vha, fcport);
2270 if (rval != QLA_SUCCESS) {
2271 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2272 "rval=%x\n", vha->host_no, rval));
2276 vha->device_flags |= DFLG_LOCAL_DEVICES;
2277 vha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2284 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
2286 #define LS_UNKNOWN 2
2287 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
2290 struct qla_hw_data *ha = vha->hw;
2292 if (!IS_IIDMA_CAPABLE(ha))
2295 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2296 fcport->fp_speed > ha->link_data_rate)
2299 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
2301 if (rval != QLA_SUCCESS) {
2302 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2303 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2304 vha->host_no, fcport->port_name[0], fcport->port_name[1],
2305 fcport->port_name[2], fcport->port_name[3],
2306 fcport->port_name[4], fcport->port_name[5],
2307 fcport->port_name[6], fcport->port_name[7], rval,
2308 fcport->fp_speed, mb[0], mb[1]));
2310 DEBUG2(qla_printk(KERN_INFO, ha,
2311 "iIDMA adjusted to %s GB/s on "
2312 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2313 link_speeds[fcport->fp_speed], fcport->port_name[0],
2314 fcport->port_name[1], fcport->port_name[2],
2315 fcport->port_name[3], fcport->port_name[4],
2316 fcport->port_name[5], fcport->port_name[6],
2317 fcport->port_name[7]));
2322 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
2324 struct fc_rport_identifiers rport_ids;
2325 struct fc_rport *rport;
2326 struct qla_hw_data *ha = vha->hw;
2329 qla2x00_rport_del(fcport);
2331 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2332 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2333 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2334 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2335 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2336 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
2338 qla_printk(KERN_WARNING, ha,
2339 "Unable to allocate fc remote port!\n");
2342 spin_lock_irq(fcport->vha->host->host_lock);
2343 *((fc_port_t **)rport->dd_data) = fcport;
2344 spin_unlock_irq(fcport->vha->host->host_lock);
2346 rport->supported_classes = fcport->supported_classes;
2348 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2349 if (fcport->port_type == FCT_INITIATOR)
2350 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2351 if (fcport->port_type == FCT_TARGET)
2352 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2353 fc_remote_port_rolechg(rport, rport_ids.roles);
2357 * qla2x00_update_fcport
2358 * Updates device on list.
2361 * ha = adapter block pointer.
2362 * fcport = port structure pointer.
2372 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
2374 struct qla_hw_data *ha = vha->hw;
2377 fcport->login_retry = 0;
2378 fcport->port_login_retry_count = ha->port_down_retry_count *
2380 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2382 fcport->flags &= ~FCF_LOGIN_NEEDED;
2384 qla2x00_iidma_fcport(vha, fcport);
2386 atomic_set(&fcport->state, FCS_ONLINE);
2388 qla2x00_reg_remote_port(vha, fcport);
2392 * qla2x00_configure_fabric
2393 * Setup SNS devices with loop ID's.
2396 * ha = adapter block pointer.
2403 qla2x00_configure_fabric(scsi_qla_host_t *vha)
2406 fc_port_t *fcport, *fcptemp;
2407 uint16_t next_loopid;
2408 uint16_t mb[MAILBOX_REGISTER_COUNT];
2410 LIST_HEAD(new_fcports);
2411 struct qla_hw_data *ha = vha->hw;
2412 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2414 /* If FL port exists, then SNS is present */
2415 if (IS_FWI2_CAPABLE(ha))
2416 loop_id = NPH_F_PORT;
2418 loop_id = SNS_FL_PORT;
2419 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
2420 if (rval != QLA_SUCCESS) {
2421 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2422 "Port\n", vha->host_no));
2424 vha->device_flags &= ~SWITCH_FOUND;
2425 return (QLA_SUCCESS);
2427 vha->device_flags |= SWITCH_FOUND;
2429 /* Mark devices that need re-synchronization. */
2430 rval2 = qla2x00_device_resync(vha);
2431 if (rval2 == QLA_RSCNS_HANDLED) {
2432 /* No point doing the scan, just continue. */
2433 return (QLA_SUCCESS);
2437 if (ql2xfdmienable &&
2438 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2439 qla2x00_fdmi_register(vha);
2441 /* Ensure we are logged into the SNS. */
2442 if (IS_FWI2_CAPABLE(ha))
2445 loop_id = SIMPLE_NAME_SERVER;
2446 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
2447 0xfc, mb, BIT_1 | BIT_0);
2448 if (mb[0] != MBS_COMMAND_COMPLETE) {
2449 DEBUG2(qla_printk(KERN_INFO, ha,
2450 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2451 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2452 mb[0], mb[1], mb[2], mb[6], mb[7]));
2453 return (QLA_SUCCESS);
2456 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2457 if (qla2x00_rft_id(vha)) {
2459 DEBUG2(printk("scsi(%ld): Register FC-4 "
2460 "TYPE failed.\n", vha->host_no));
2462 if (qla2x00_rff_id(vha)) {
2464 DEBUG2(printk("scsi(%ld): Register FC-4 "
2465 "Features failed.\n", vha->host_no));
2467 if (qla2x00_rnn_id(vha)) {
2469 DEBUG2(printk("scsi(%ld): Register Node Name "
2470 "failed.\n", vha->host_no));
2471 } else if (qla2x00_rsnn_nn(vha)) {
2473 DEBUG2(printk("scsi(%ld): Register Symbolic "
2474 "Node Name failed.\n", vha->host_no));
2478 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
2479 if (rval != QLA_SUCCESS)
2483 * Logout all previous fabric devices marked lost, except
2486 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2487 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2490 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2493 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2494 qla2x00_mark_device_lost(vha, fcport,
2495 ql2xplogiabsentdevice, 0);
2496 if (fcport->loop_id != FC_NO_LOOP_ID &&
2497 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2498 fcport->port_type != FCT_INITIATOR &&
2499 fcport->port_type != FCT_BROADCAST) {
2500 ha->isp_ops->fabric_logout(vha,
2502 fcport->d_id.b.domain,
2503 fcport->d_id.b.area,
2504 fcport->d_id.b.al_pa);
2505 fcport->loop_id = FC_NO_LOOP_ID;
2510 /* Starting free loop ID. */
2511 next_loopid = ha->min_external_loopid;
2514 * Scan through our port list and login entries that need to be
2517 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2518 if (atomic_read(&vha->loop_down_timer) ||
2519 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2522 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2523 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2526 if (fcport->loop_id == FC_NO_LOOP_ID) {
2527 fcport->loop_id = next_loopid;
2528 rval = qla2x00_find_new_loop_id(
2530 if (rval != QLA_SUCCESS) {
2531 /* Ran out of IDs to use */
2535 /* Login and update database */
2536 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
2539 /* Exit if out of loop IDs. */
2540 if (rval != QLA_SUCCESS) {
2545 * Login and add the new devices to our port list.
2547 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2548 if (atomic_read(&vha->loop_down_timer) ||
2549 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2552 /* Find a new loop ID to use. */
2553 fcport->loop_id = next_loopid;
2554 rval = qla2x00_find_new_loop_id(base_vha, fcport);
2555 if (rval != QLA_SUCCESS) {
2556 /* Ran out of IDs to use */
2560 /* Login and update database */
2561 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
2565 fcport->vp_idx = vha->vp_idx;
2567 list_move_tail(&fcport->list, &vha->vp_fcports);
2571 /* Free all new device structures not processed. */
2572 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2573 list_del(&fcport->list);
2578 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2579 "rval=%d\n", vha->host_no, rval));
2587 * qla2x00_find_all_fabric_devs
2590 * ha = adapter block pointer.
2591 * dev = database device entry pointer.
2600 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2601 struct list_head *new_fcports)
2605 fc_port_t *fcport, *new_fcport, *fcptemp;
2610 int first_dev, last_dev;
2611 port_id_t wrap, nxt_d_id;
2612 struct qla_hw_data *ha = vha->hw;
2613 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
2617 /* Try GID_PT to get device list, else GAN. */
2618 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
2621 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2622 "on GA_NXT\n", vha->host_no));
2624 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
2627 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
2630 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
2633 } else if (ql2xiidmaenable &&
2634 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2635 qla2x00_gpsc(vha, swl);
2640 /* Allocate temporary fcport for any new fcports discovered. */
2641 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2642 if (new_fcport == NULL) {
2644 return (QLA_MEMORY_ALLOC_FAILED);
2646 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2647 /* Set start port ID scan at adapter ID. */
2651 /* Starting free loop ID. */
2652 loop_id = ha->min_external_loopid;
2653 for (; loop_id <= ha->max_loop_id; loop_id++) {
2654 if (qla2x00_is_reserved_id(vha, loop_id))
2657 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
2662 wrap.b24 = new_fcport->d_id.b24;
2664 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2665 memcpy(new_fcport->node_name,
2666 swl[swl_idx].node_name, WWN_SIZE);
2667 memcpy(new_fcport->port_name,
2668 swl[swl_idx].port_name, WWN_SIZE);
2669 memcpy(new_fcport->fabric_port_name,
2670 swl[swl_idx].fabric_port_name, WWN_SIZE);
2671 new_fcport->fp_speed = swl[swl_idx].fp_speed;
2673 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2679 /* Send GA_NXT to the switch */
2680 rval = qla2x00_ga_nxt(vha, new_fcport);
2681 if (rval != QLA_SUCCESS) {
2682 qla_printk(KERN_WARNING, ha,
2683 "SNS scan failed -- assuming zero-entry "
2685 list_for_each_entry_safe(fcport, fcptemp,
2686 new_fcports, list) {
2687 list_del(&fcport->list);
2695 /* If wrap on switch device list, exit. */
2697 wrap.b24 = new_fcport->d_id.b24;
2699 } else if (new_fcport->d_id.b24 == wrap.b24) {
2700 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2701 vha->host_no, new_fcport->d_id.b.domain,
2702 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2706 /* Bypass if same physical adapter. */
2707 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
2710 /* Bypass virtual ports of the same host. */
2712 if (ha->num_vhosts) {
2713 list_for_each_entry(vp, &ha->vp_list, list) {
2714 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2723 /* Bypass if same domain and area of adapter. */
2724 if (((new_fcport->d_id.b24 & 0xffff00) ==
2725 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2729 /* Bypass reserved domain fields. */
2730 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2733 /* Locate matching device in database. */
2735 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2736 if (memcmp(new_fcport->port_name, fcport->port_name,
2742 /* Update port state. */
2743 memcpy(fcport->fabric_port_name,
2744 new_fcport->fabric_port_name, WWN_SIZE);
2745 fcport->fp_speed = new_fcport->fp_speed;
2748 * If address the same and state FCS_ONLINE, nothing
2751 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2752 atomic_read(&fcport->state) == FCS_ONLINE) {
2757 * If device was not a fabric device before.
2759 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2760 fcport->d_id.b24 = new_fcport->d_id.b24;
2761 fcport->loop_id = FC_NO_LOOP_ID;
2762 fcport->flags |= (FCF_FABRIC_DEVICE |
2764 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2769 * Port ID changed or device was marked to be updated;
2770 * Log it out if still logged in and mark it for
2773 fcport->d_id.b24 = new_fcport->d_id.b24;
2774 fcport->flags |= FCF_LOGIN_NEEDED;
2775 if (fcport->loop_id != FC_NO_LOOP_ID &&
2776 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2777 fcport->port_type != FCT_INITIATOR &&
2778 fcport->port_type != FCT_BROADCAST) {
2779 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
2780 fcport->d_id.b.domain, fcport->d_id.b.area,
2781 fcport->d_id.b.al_pa);
2782 fcport->loop_id = FC_NO_LOOP_ID;
2790 /* If device was not in our fcports list, then add it. */
2791 list_add_tail(&new_fcport->list, new_fcports);
2793 /* Allocate a new replacement fcport. */
2794 nxt_d_id.b24 = new_fcport->d_id.b24;
2795 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2796 if (new_fcport == NULL) {
2798 return (QLA_MEMORY_ALLOC_FAILED);
2800 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2801 new_fcport->d_id.b24 = nxt_d_id.b24;
2807 if (!list_empty(new_fcports))
2808 vha->device_flags |= DFLG_FABRIC_DEVICES;
2814 * qla2x00_find_new_loop_id
2815 * Scan through our port list and find a new usable loop ID.
2818 * ha: adapter state pointer.
2819 * dev: port structure pointer.
2822 * qla2x00 local function return status code.
2828 qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
2833 uint16_t first_loop_id;
2834 struct qla_hw_data *ha = vha->hw;
2835 struct scsi_qla_host *vp;
2839 /* Save starting loop ID. */
2840 first_loop_id = dev->loop_id;
2843 /* Skip loop ID if already used by adapter. */
2844 if (dev->loop_id == vha->loop_id)
2847 /* Skip reserved loop IDs. */
2848 while (qla2x00_is_reserved_id(vha, dev->loop_id))
2851 /* Reset loop ID if passed the end. */
2852 if (dev->loop_id > ha->max_loop_id) {
2853 /* first loop ID. */
2854 dev->loop_id = ha->min_external_loopid;
2857 /* Check for loop ID being already in use. */
2860 list_for_each_entry(vp, &ha->vp_list, list) {
2861 list_for_each_entry(fcport, &vp->vp_fcports, list) {
2862 if (fcport->loop_id == dev->loop_id &&
2864 /* ID possibly in use */
2873 /* If not in use then it is free to use. */
2878 /* ID in use. Try next value. */
2881 /* If wrap around. No free ID to use. */
2882 if (dev->loop_id == first_loop_id) {
2883 dev->loop_id = FC_NO_LOOP_ID;
2884 rval = QLA_FUNCTION_FAILED;
2893 * qla2x00_device_resync
2894 * Marks devices in the database that needs resynchronization.
2897 * ha = adapter block pointer.
2903 qla2x00_device_resync(scsi_qla_host_t *vha)
2908 uint32_t rscn_entry;
2909 uint8_t rscn_out_iter;
2913 rval = QLA_RSCNS_HANDLED;
2915 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
2916 vha->flags.rscn_queue_overflow) {
2918 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
2919 format = MSB(MSW(rscn_entry));
2920 d_id.b.domain = LSB(MSW(rscn_entry));
2921 d_id.b.area = MSB(LSW(rscn_entry));
2922 d_id.b.al_pa = LSB(LSW(rscn_entry));
2924 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2925 "[%02x/%02x%02x%02x].\n",
2926 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
2927 d_id.b.area, d_id.b.al_pa));
2929 vha->rscn_out_ptr++;
2930 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
2931 vha->rscn_out_ptr = 0;
2933 /* Skip duplicate entries. */
2934 for (rscn_out_iter = vha->rscn_out_ptr;
2935 !vha->flags.rscn_queue_overflow &&
2936 rscn_out_iter != vha->rscn_in_ptr;
2937 rscn_out_iter = (rscn_out_iter ==
2938 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2940 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
2943 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2944 "entry found at [%d].\n", vha->host_no,
2947 vha->rscn_out_ptr = rscn_out_iter;
2950 /* Queue overflow, set switch default case. */
2951 if (vha->flags.rscn_queue_overflow) {
2952 DEBUG(printk("scsi(%ld): device_resync: rscn "
2953 "overflow.\n", vha->host_no));
2956 vha->flags.rscn_queue_overflow = 0;
2972 vha->rscn_out_ptr = vha->rscn_in_ptr;
2978 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2979 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2980 (fcport->d_id.b24 & mask) != d_id.b24 ||
2981 fcport->port_type == FCT_BROADCAST)
2984 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2986 fcport->port_type != FCT_INITIATOR) {
2987 qla2x00_mark_device_lost(vha, fcport,
2991 fcport->flags &= ~FCF_FARP_DONE;
2998 * qla2x00_fabric_dev_login
2999 * Login fabric target device and update FC port database.
3002 * ha: adapter state pointer.
3003 * fcport: port structure list pointer.
3004 * next_loopid: contains value of a new loop ID that can be used
3005 * by the next login attempt.
3008 * qla2x00 local function return status code.
3014 qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
3015 uint16_t *next_loopid)
3020 struct qla_hw_data *ha = vha->hw;
3025 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
3026 if (rval == QLA_SUCCESS) {
3027 /* Send an ADISC to tape devices.*/
3029 if (fcport->flags & FCF_TAPE_PRESENT)
3031 rval = qla2x00_get_port_database(vha, fcport, opts);
3032 if (rval != QLA_SUCCESS) {
3033 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3034 fcport->d_id.b.domain, fcport->d_id.b.area,
3035 fcport->d_id.b.al_pa);
3036 qla2x00_mark_device_lost(vha, fcport, 1, 0);
3038 qla2x00_update_fcport(vha, fcport);
3046 * qla2x00_fabric_login
3047 * Issue fabric login command.
3050 * ha = adapter block pointer.
3051 * device = pointer to FC device type structure.
3054 * 0 - Login successfully
3056 * 2 - Initiator device
3060 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
3061 uint16_t *next_loopid)
3065 uint16_t tmp_loopid;
3066 uint16_t mb[MAILBOX_REGISTER_COUNT];
3067 struct qla_hw_data *ha = vha->hw;
3073 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3074 "for port %02x%02x%02x.\n",
3075 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
3076 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3078 /* Login fcport on switch. */
3079 ha->isp_ops->fabric_login(vha, fcport->loop_id,
3080 fcport->d_id.b.domain, fcport->d_id.b.area,
3081 fcport->d_id.b.al_pa, mb, BIT_0);
3082 if (mb[0] == MBS_PORT_ID_USED) {
3084 * Device has another loop ID. The firmware team
3085 * recommends the driver perform an implicit login with
3086 * the specified ID again. The ID we just used is save
3087 * here so we return with an ID that can be tried by
3091 tmp_loopid = fcport->loop_id;
3092 fcport->loop_id = mb[1];
3094 DEBUG(printk("Fabric Login: port in use - next "
3095 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3096 fcport->loop_id, fcport->d_id.b.domain,
3097 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3099 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3104 /* A retry occurred before. */
3105 *next_loopid = tmp_loopid;
3108 * No retry occurred before. Just increment the
3109 * ID value for next login.
3111 *next_loopid = (fcport->loop_id + 1);
3114 if (mb[1] & BIT_0) {
3115 fcport->port_type = FCT_INITIATOR;
3117 fcport->port_type = FCT_TARGET;
3118 if (mb[1] & BIT_1) {
3119 fcport->flags |= FCF_TAPE_PRESENT;
3124 fcport->supported_classes |= FC_COS_CLASS2;
3126 fcport->supported_classes |= FC_COS_CLASS3;
3130 } else if (mb[0] == MBS_LOOP_ID_USED) {
3132 * Loop ID already used, try next loop ID.
3135 rval = qla2x00_find_new_loop_id(vha, fcport);
3136 if (rval != QLA_SUCCESS) {
3137 /* Ran out of loop IDs to use */
3140 } else if (mb[0] == MBS_COMMAND_ERROR) {
3142 * Firmware possibly timed out during login. If NO
3143 * retries are left to do then the device is declared
3146 *next_loopid = fcport->loop_id;
3147 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3148 fcport->d_id.b.domain, fcport->d_id.b.area,
3149 fcport->d_id.b.al_pa);
3150 qla2x00_mark_device_lost(vha, fcport, 1, 0);
3156 * unrecoverable / not handled error
3158 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3159 "loop_id=%x jiffies=%lx.\n",
3160 __func__, vha->host_no, mb[0],
3161 fcport->d_id.b.domain, fcport->d_id.b.area,
3162 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3164 *next_loopid = fcport->loop_id;
3165 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3166 fcport->d_id.b.domain, fcport->d_id.b.area,
3167 fcport->d_id.b.al_pa);
3168 fcport->loop_id = FC_NO_LOOP_ID;
3169 fcport->login_retry = 0;
3180 * qla2x00_local_device_login
3181 * Issue local device login command.
3184 * ha = adapter block pointer.
3185 * loop_id = loop id of device to login to.
3187 * Returns (Where's the #define!!!!):
3188 * 0 - Login successfully
3193 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
3196 uint16_t mb[MAILBOX_REGISTER_COUNT];
3198 memset(mb, 0, sizeof(mb));
3199 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
3200 if (rval == QLA_SUCCESS) {
3201 /* Interrogate mailbox registers for any errors */
3202 if (mb[0] == MBS_COMMAND_ERROR)
3204 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3205 /* device not in PCB table */
3213 * qla2x00_loop_resync
3214 * Resync with fibre channel devices.
3217 * ha = adapter block pointer.
3223 qla2x00_loop_resync(scsi_qla_host_t *vha)
3225 int rval = QLA_SUCCESS;
3227 struct qla_hw_data *ha = vha->hw;
3228 struct req_que *req = ha->req_q_map[vha->req_ques[0]];
3229 struct rsp_que *rsp = req->rsp;
3231 atomic_set(&vha->loop_state, LOOP_UPDATE);
3232 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3233 if (vha->flags.online) {
3234 if (!(rval = qla2x00_fw_ready(vha))) {
3235 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3238 atomic_set(&vha->loop_state, LOOP_UPDATE);
3240 /* Issue a marker after FW becomes ready. */
3241 qla2x00_marker(vha, req, rsp, 0, 0,
3243 vha->marker_needed = 0;
3245 /* Remap devices on Loop. */
3246 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3248 qla2x00_configure_loop(vha);
3250 } while (!atomic_read(&vha->loop_down_timer) &&
3251 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3252 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3257 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3258 return (QLA_FUNCTION_FAILED);
3261 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3267 qla2x00_update_fcports(scsi_qla_host_t *vha)
3271 /* Go with deferred removal of rport references. */
3272 list_for_each_entry(fcport, &vha->vp_fcports, list)
3273 if (fcport && fcport->drport &&
3274 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
3275 qla2x00_rport_del(fcport);
3280 * Resets ISP and aborts all outstanding commands.
3283 * ha = adapter block pointer.
3289 qla2x00_abort_isp(scsi_qla_host_t *vha)
3293 struct qla_hw_data *ha = vha->hw;
3294 struct scsi_qla_host *vp;
3295 struct req_que *req = ha->req_q_map[0];
3297 if (vha->flags.online) {
3298 vha->flags.online = 0;
3299 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3300 ha->qla_stats.total_isp_aborts++;
3302 qla_printk(KERN_INFO, ha,
3303 "Performing ISP error recovery - ha= %p.\n", ha);
3304 ha->isp_ops->reset_chip(vha);
3306 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3307 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3308 atomic_set(&vha->loop_state, LOOP_DOWN);
3309 qla2x00_mark_all_devices_lost(vha, 0);
3310 list_for_each_entry(vp, &ha->vp_list, list)
3311 qla2x00_mark_all_devices_lost(vp, 0);
3313 if (!atomic_read(&vha->loop_down_timer))
3314 atomic_set(&vha->loop_down_timer,
3318 /* Requeue all commands in outstanding command list. */
3319 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
3321 ha->isp_ops->get_flash_version(vha, req->ring);
3323 ha->isp_ops->nvram_config(vha);
3325 if (!qla2x00_restart_isp(vha)) {
3326 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
3328 if (!atomic_read(&vha->loop_down_timer)) {
3330 * Issue marker command only when we are going
3331 * to start the I/O .
3333 vha->marker_needed = 1;
3336 vha->flags.online = 1;
3338 ha->isp_ops->enable_intrs(ha);
3340 ha->isp_abort_cnt = 0;
3341 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3344 ha->flags.fce_enabled = 1;
3346 fce_calc_size(ha->fce_bufs));
3347 rval = qla2x00_enable_fce_trace(vha,
3348 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3351 qla_printk(KERN_WARNING, ha,
3352 "Unable to reinitialize FCE "
3354 ha->flags.fce_enabled = 0;
3359 memset(ha->eft, 0, EFT_SIZE);
3360 rval = qla2x00_enable_eft_trace(vha,
3361 ha->eft_dma, EFT_NUM_BUFFERS);
3363 qla_printk(KERN_WARNING, ha,
3364 "Unable to reinitialize EFT "
3368 } else { /* failed the ISP abort */
3369 vha->flags.online = 1;
3370 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
3371 if (ha->isp_abort_cnt == 0) {
3372 qla_printk(KERN_WARNING, ha,
3373 "ISP error recovery failed - "
3374 "board disabled\n");
3376 * The next call disables the board
3379 ha->isp_ops->reset_adapter(vha);
3380 vha->flags.online = 0;
3381 clear_bit(ISP_ABORT_RETRY,
3384 } else { /* schedule another ISP abort */
3385 ha->isp_abort_cnt--;
3386 DEBUG(printk("qla%ld: ISP abort - "
3387 "retry remaining %d\n",
3388 vha->host_no, ha->isp_abort_cnt));
3392 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3393 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3394 "- retrying (%d) more times\n",
3395 vha->host_no, ha->isp_abort_cnt));
3396 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3404 DEBUG(printk(KERN_INFO
3405 "qla2x00_abort_isp(%ld): succeeded.\n",
3407 list_for_each_entry(vp, &ha->vp_list, list) {
3409 qla2x00_vp_abort_isp(vp);
3412 qla_printk(KERN_INFO, ha,
3413 "qla2x00_abort_isp: **** FAILED ****\n");
3420 * qla2x00_restart_isp
3421 * restarts the ISP after a reset
3424 * ha = adapter block pointer.
3430 qla2x00_restart_isp(scsi_qla_host_t *vha)
3434 struct qla_hw_data *ha = vha->hw;
3435 struct req_que *req = ha->req_q_map[0];
3436 struct rsp_que *rsp = ha->rsp_q_map[0];
3438 /* If firmware needs to be loaded */
3439 if (qla2x00_isp_firmware(vha)) {
3440 vha->flags.online = 0;
3441 status = ha->isp_ops->chip_diag(vha);
3443 status = qla2x00_setup_chip(vha);
3446 if (!status && !(status = qla2x00_init_rings(vha))) {
3447 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
3448 /* Initialize the queues in use */
3449 qla25xx_init_queues(ha);
3451 status = qla2x00_fw_ready(vha);
3453 DEBUG(printk("%s(): Start configure loop, "
3454 "status = %d\n", __func__, status));
3456 /* Issue a marker after FW becomes ready. */
3457 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
3459 vha->flags.online = 1;
3460 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3463 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3464 qla2x00_configure_loop(vha);
3466 } while (!atomic_read(&vha->loop_down_timer) &&
3467 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3468 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3472 /* if no cable then assume it's good */
3473 if ((vha->device_flags & DFLG_NO_CABLE))
3476 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3484 qla25xx_init_queues(struct qla_hw_data *ha)
3486 struct rsp_que *rsp = NULL;
3487 struct req_que *req = NULL;
3488 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3492 for (i = 1; i < ha->max_queues; i++) {
3493 rsp = ha->rsp_q_map[i];
3495 rsp->options &= ~BIT_0;
3496 ret = qla25xx_init_rsp_que(base_vha, rsp, rsp->options);
3497 if (ret != QLA_SUCCESS)
3498 DEBUG2_17(printk(KERN_WARNING
3499 "%s Rsp que:%d init failed\n", __func__,
3502 DEBUG2_17(printk(KERN_INFO
3503 "%s Rsp que:%d inited\n", __func__,
3506 req = ha->req_q_map[i];
3508 /* Clear outstanding commands array. */
3509 req->options &= ~BIT_0;
3510 ret = qla25xx_init_req_que(base_vha, req, req->options);
3511 if (ret != QLA_SUCCESS)
3512 DEBUG2_17(printk(KERN_WARNING
3513 "%s Req que:%d init failed\n", __func__,
3516 DEBUG2_17(printk(KERN_WARNING
3517 "%s Req que:%d inited\n", __func__,
3525 * qla2x00_reset_adapter
3529 * ha = adapter block pointer.
3532 qla2x00_reset_adapter(scsi_qla_host_t *vha)
3534 unsigned long flags = 0;
3535 struct qla_hw_data *ha = vha->hw;
3536 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3538 vha->flags.online = 0;
3539 ha->isp_ops->disable_intrs(ha);
3541 spin_lock_irqsave(&ha->hardware_lock, flags);
3542 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3543 RD_REG_WORD(®->hccr); /* PCI Posting. */
3544 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3545 RD_REG_WORD(®->hccr); /* PCI Posting. */
3546 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3550 qla24xx_reset_adapter(scsi_qla_host_t *vha)
3552 unsigned long flags = 0;
3553 struct qla_hw_data *ha = vha->hw;
3554 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3556 vha->flags.online = 0;
3557 ha->isp_ops->disable_intrs(ha);
3559 spin_lock_irqsave(&ha->hardware_lock, flags);
3560 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3561 RD_REG_DWORD(®->hccr);
3562 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3563 RD_REG_DWORD(®->hccr);
3564 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3566 if (IS_NOPOLLING_TYPE(ha))
3567 ha->isp_ops->enable_intrs(ha);
3570 /* On sparc systems, obtain port and node WWN from firmware
3573 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3574 struct nvram_24xx *nv)
3577 struct qla_hw_data *ha = vha->hw;
3578 struct pci_dev *pdev = ha->pdev;
3579 struct device_node *dp = pci_device_to_OF_node(pdev);
3583 val = of_get_property(dp, "port-wwn", &len);
3584 if (val && len >= WWN_SIZE)
3585 memcpy(nv->port_name, val, WWN_SIZE);
3587 val = of_get_property(dp, "node-wwn", &len);
3588 if (val && len >= WWN_SIZE)
3589 memcpy(nv->node_name, val, WWN_SIZE);
3594 qla24xx_nvram_config(scsi_qla_host_t *vha)
3597 struct init_cb_24xx *icb;
3598 struct nvram_24xx *nv;
3600 uint8_t *dptr1, *dptr2;
3603 struct qla_hw_data *ha = vha->hw;
3606 icb = (struct init_cb_24xx *)ha->init_cb;
3609 /* Determine NVRAM starting address. */
3610 ha->nvram_size = sizeof(struct nvram_24xx);
3611 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3612 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3613 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3614 if (PCI_FUNC(ha->pdev->devfn)) {
3615 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3616 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3619 /* Get VPD data into cache */
3620 ha->vpd = ha->nvram + VPD_OFFSET;
3621 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
3622 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3624 /* Get NVRAM data into cache and calculate checksum. */
3625 dptr = (uint32_t *)nv;
3626 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
3628 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3629 chksum += le32_to_cpu(*dptr++);
3631 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
3632 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
3634 /* Bad NVRAM data, set defaults parameters. */
3635 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3636 || nv->id[3] != ' ' ||
3637 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3638 /* Reset NVRAM data. */
3639 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3640 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3641 le16_to_cpu(nv->nvram_version));
3642 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3643 "invalid -- WWPN) defaults.\n");
3646 * Set default initialization control block.
3648 memset(nv, 0, ha->nvram_size);
3649 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3650 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3651 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3652 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3653 nv->exchange_count = __constant_cpu_to_le16(0);
3654 nv->hard_address = __constant_cpu_to_le16(124);
3655 nv->port_name[0] = 0x21;
3656 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3657 nv->port_name[2] = 0x00;
3658 nv->port_name[3] = 0xe0;
3659 nv->port_name[4] = 0x8b;
3660 nv->port_name[5] = 0x1c;
3661 nv->port_name[6] = 0x55;
3662 nv->port_name[7] = 0x86;
3663 nv->node_name[0] = 0x20;
3664 nv->node_name[1] = 0x00;
3665 nv->node_name[2] = 0x00;
3666 nv->node_name[3] = 0xe0;
3667 nv->node_name[4] = 0x8b;
3668 nv->node_name[5] = 0x1c;
3669 nv->node_name[6] = 0x55;
3670 nv->node_name[7] = 0x86;
3671 qla24xx_nvram_wwn_from_ofw(vha, nv);
3672 nv->login_retry_count = __constant_cpu_to_le16(8);
3673 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3674 nv->login_timeout = __constant_cpu_to_le16(0);
3675 nv->firmware_options_1 =
3676 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3677 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3678 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3679 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3680 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3681 nv->efi_parameters = __constant_cpu_to_le32(0);
3682 nv->reset_delay = 5;
3683 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3684 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3685 nv->link_down_timeout = __constant_cpu_to_le16(30);
3690 /* Reset Initialization control block */
3691 memset(icb, 0, ha->init_cb_size);
3693 /* Copy 1st segment. */
3694 dptr1 = (uint8_t *)icb;
3695 dptr2 = (uint8_t *)&nv->version;
3696 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3698 *dptr1++ = *dptr2++;
3700 icb->login_retry_count = nv->login_retry_count;
3701 icb->link_down_on_nos = nv->link_down_on_nos;
3703 /* Copy 2nd segment. */
3704 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3705 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3706 cnt = (uint8_t *)&icb->reserved_3 -
3707 (uint8_t *)&icb->interrupt_delay_timer;
3709 *dptr1++ = *dptr2++;
3712 * Setup driver NVRAM options.
3714 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
3717 /* Use alternate WWN? */
3718 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3719 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3720 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3723 /* Prepare nodename */
3724 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3726 * Firmware will apply the following mask if the nodename was
3729 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3730 icb->node_name[0] &= 0xF0;
3733 /* Set host adapter parameters. */
3734 ha->flags.disable_risc_code_load = 0;
3735 ha->flags.enable_lip_reset = 0;
3736 ha->flags.enable_lip_full_login =
3737 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3738 ha->flags.enable_target_reset =
3739 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
3740 ha->flags.enable_led_scheme = 0;
3741 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
3743 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3744 (BIT_6 | BIT_5 | BIT_4)) >> 4;
3746 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3747 sizeof(ha->fw_seriallink_options24));
3749 /* save HBA serial number */
3750 ha->serial0 = icb->port_name[5];
3751 ha->serial1 = icb->port_name[6];
3752 ha->serial2 = icb->port_name[7];
3753 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3754 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
3756 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3758 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3760 /* Set minimum login_timeout to 4 seconds. */
3761 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3762 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3763 if (le16_to_cpu(nv->login_timeout) < 4)
3764 nv->login_timeout = __constant_cpu_to_le16(4);
3765 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3766 icb->login_timeout = nv->login_timeout;
3768 /* Set minimum RATOV to 100 tenths of a second. */
3771 ha->loop_reset_delay = nv->reset_delay;
3773 /* Link Down Timeout = 0:
3775 * When Port Down timer expires we will start returning
3776 * I/O's to OS with "DID_NO_CONNECT".
3778 * Link Down Timeout != 0:
3780 * The driver waits for the link to come up after link down
3781 * before returning I/Os to OS with "DID_NO_CONNECT".
3783 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3784 ha->loop_down_abort_time =
3785 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3787 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3788 ha->loop_down_abort_time =
3789 (LOOP_DOWN_TIME - ha->link_down_timeout);
3792 /* Need enough time to try and get the port back. */
3793 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3794 if (qlport_down_retry)
3795 ha->port_down_retry_count = qlport_down_retry;
3797 /* Set login_retry_count */
3798 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3799 if (ha->port_down_retry_count ==
3800 le16_to_cpu(nv->port_down_retry_count) &&
3801 ha->port_down_retry_count > 3)
3802 ha->login_retry_count = ha->port_down_retry_count;
3803 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3804 ha->login_retry_count = ha->port_down_retry_count;
3805 if (ql2xloginretrycount)
3806 ha->login_retry_count = ql2xloginretrycount;
3809 if (!vha->flags.init_done) {
3810 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3811 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3812 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3813 le16_to_cpu(icb->interrupt_delay_timer): 2;
3815 icb->firmware_options_2 &= __constant_cpu_to_le32(
3816 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3817 vha->flags.process_response_queue = 0;
3818 if (ha->zio_mode != QLA_ZIO_DISABLED) {
3819 ha->zio_mode = QLA_ZIO_MODE_6;
3821 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3822 "(%d us).\n", vha->host_no, ha->zio_mode,
3823 ha->zio_timer * 100));
3824 qla_printk(KERN_INFO, ha,
3825 "ZIO mode %d enabled; timer delay (%d us).\n",
3826 ha->zio_mode, ha->zio_timer * 100);
3828 icb->firmware_options_2 |= cpu_to_le32(
3829 (uint32_t)ha->zio_mode);
3830 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3831 vha->flags.process_response_queue = 1;
3835 DEBUG2_3(printk(KERN_WARNING
3836 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
3842 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr)
3844 int rval = QLA_SUCCESS;
3845 int segments, fragment;
3847 uint32_t *dcode, dlen;
3851 struct qla_hw_data *ha = vha->hw;
3852 struct req_que *req = ha->req_q_map[0];
3854 qla_printk(KERN_INFO, ha,
3855 "FW: Loading from flash (%x)...\n", ha->flt_region_fw);
3859 segments = FA_RISC_CODE_SEGMENTS;
3860 faddr = ha->flt_region_fw;
3861 dcode = (uint32_t *)req->ring;
3864 /* Validate firmware image by checking version. */
3865 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
3866 for (i = 0; i < 4; i++)
3867 dcode[i] = be32_to_cpu(dcode[i]);
3868 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3869 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3870 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3872 qla_printk(KERN_WARNING, ha,
3873 "Unable to verify integrity of flash firmware image!\n");
3874 qla_printk(KERN_WARNING, ha,
3875 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3876 dcode[1], dcode[2], dcode[3]);
3878 return QLA_FUNCTION_FAILED;
3881 while (segments && rval == QLA_SUCCESS) {
3882 /* Read segment's load information. */
3883 qla24xx_read_flash_data(vha, dcode, faddr, 4);
3885 risc_addr = be32_to_cpu(dcode[2]);
3886 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3887 risc_size = be32_to_cpu(dcode[3]);
3890 while (risc_size > 0 && rval == QLA_SUCCESS) {
3891 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3892 if (dlen > risc_size)
3895 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3896 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3897 vha->host_no, risc_addr, dlen, faddr));
3899 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
3900 for (i = 0; i < dlen; i++)
3901 dcode[i] = swab32(dcode[i]);
3903 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
3906 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3907 "segment %d of firmware\n", vha->host_no,
3909 qla_printk(KERN_WARNING, ha,
3910 "[ERROR] Failed to load segment %d of "
3911 "firmware\n", fragment);
3928 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3931 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
3935 uint16_t *wcode, *fwcode;
3936 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3937 struct fw_blob *blob;
3938 struct qla_hw_data *ha = vha->hw;
3939 struct req_que *req = ha->req_q_map[0];
3941 /* Load firmware blob. */
3942 blob = qla2x00_request_firmware(vha);
3944 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
3945 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3946 "from: " QLA_FW_URL ".\n");
3947 return QLA_FUNCTION_FAILED;
3952 wcode = (uint16_t *)req->ring;
3954 fwcode = (uint16_t *)blob->fw->data;
3957 /* Validate firmware image by checking version. */
3958 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3959 qla_printk(KERN_WARNING, ha,
3960 "Unable to verify integrity of firmware image (%Zd)!\n",
3962 goto fail_fw_integrity;
3964 for (i = 0; i < 4; i++)
3965 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3966 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3967 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3968 wcode[2] == 0 && wcode[3] == 0)) {
3969 qla_printk(KERN_WARNING, ha,
3970 "Unable to verify integrity of firmware image!\n");
3971 qla_printk(KERN_WARNING, ha,
3972 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3973 wcode[1], wcode[2], wcode[3]);
3974 goto fail_fw_integrity;
3978 while (*seg && rval == QLA_SUCCESS) {
3980 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3981 risc_size = be16_to_cpu(fwcode[3]);
3983 /* Validate firmware image size. */
3984 fwclen += risc_size * sizeof(uint16_t);
3985 if (blob->fw->size < fwclen) {
3986 qla_printk(KERN_WARNING, ha,
3987 "Unable to verify integrity of firmware image "
3988 "(%Zd)!\n", blob->fw->size);
3989 goto fail_fw_integrity;
3993 while (risc_size > 0 && rval == QLA_SUCCESS) {
3994 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3995 if (wlen > risc_size)
3998 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3999 "addr %x, number of words 0x%x.\n", vha->host_no,
4002 for (i = 0; i < wlen; i++)
4003 wcode[i] = swab16(fwcode[i]);
4005 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
4008 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4009 "segment %d of firmware\n", vha->host_no,
4011 qla_printk(KERN_WARNING, ha,
4012 "[ERROR] Failed to load segment %d of "
4013 "firmware\n", fragment);
4029 return QLA_FUNCTION_FAILED;
4033 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4036 int segments, fragment;
4037 uint32_t *dcode, dlen;
4041 struct fw_blob *blob;
4042 uint32_t *fwcode, fwclen;
4043 struct qla_hw_data *ha = vha->hw;
4044 struct req_que *req = ha->req_q_map[0];
4046 /* Load firmware blob. */
4047 blob = qla2x00_request_firmware(vha);
4049 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
4050 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4051 "from: " QLA_FW_URL ".\n");
4053 return QLA_FUNCTION_FAILED;
4056 qla_printk(KERN_INFO, ha,
4057 "FW: Loading via request-firmware...\n");
4061 segments = FA_RISC_CODE_SEGMENTS;
4062 dcode = (uint32_t *)req->ring;
4064 fwcode = (uint32_t *)blob->fw->data;
4067 /* Validate firmware image by checking version. */
4068 if (blob->fw->size < 8 * sizeof(uint32_t)) {
4069 qla_printk(KERN_WARNING, ha,
4070 "Unable to verify integrity of firmware image (%Zd)!\n",
4072 goto fail_fw_integrity;
4074 for (i = 0; i < 4; i++)
4075 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4076 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4077 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4078 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4080 qla_printk(KERN_WARNING, ha,
4081 "Unable to verify integrity of firmware image!\n");
4082 qla_printk(KERN_WARNING, ha,
4083 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4084 dcode[1], dcode[2], dcode[3]);
4085 goto fail_fw_integrity;
4088 while (segments && rval == QLA_SUCCESS) {
4089 risc_addr = be32_to_cpu(fwcode[2]);
4090 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4091 risc_size = be32_to_cpu(fwcode[3]);
4093 /* Validate firmware image size. */
4094 fwclen += risc_size * sizeof(uint32_t);
4095 if (blob->fw->size < fwclen) {
4096 qla_printk(KERN_WARNING, ha,
4097 "Unable to verify integrity of firmware image "
4098 "(%Zd)!\n", blob->fw->size);
4100 goto fail_fw_integrity;
4104 while (risc_size > 0 && rval == QLA_SUCCESS) {
4105 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4106 if (dlen > risc_size)
4109 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4110 "addr %x, number of dwords 0x%x.\n", vha->host_no,
4113 for (i = 0; i < dlen; i++)
4114 dcode[i] = swab32(fwcode[i]);
4116 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
4119 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4120 "segment %d of firmware\n", vha->host_no,
4122 qla_printk(KERN_WARNING, ha,
4123 "[ERROR] Failed to load segment %d of "
4124 "firmware\n", fragment);
4140 return QLA_FUNCTION_FAILED;
4144 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4150 * 1) Firmware via request-firmware interface (.bin file).
4151 * 2) Firmware residing in flash.
4153 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4154 if (rval == QLA_SUCCESS)
4157 return qla24xx_load_risc_flash(vha, srisc_addr);
4161 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4167 * 1) Firmware residing in flash.
4168 * 2) Firmware via request-firmware interface (.bin file).
4170 rval = qla24xx_load_risc_flash(vha, srisc_addr);
4171 if (rval == QLA_SUCCESS)
4174 return qla24xx_load_risc_blob(vha, srisc_addr);
4178 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
4181 struct qla_hw_data *ha = vha->hw;
4183 if (!IS_FWI2_CAPABLE(ha))
4185 if (!ha->fw_major_version)
4188 ret = qla2x00_stop_firmware(vha);
4189 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4190 retries ; retries--) {
4191 ha->isp_ops->reset_chip(vha);
4192 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
4194 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
4196 qla_printk(KERN_INFO, ha,
4197 "Attempting retry of stop-firmware command...\n");
4198 ret = qla2x00_stop_firmware(vha);
4203 qla24xx_configure_vhba(scsi_qla_host_t *vha)
4205 int rval = QLA_SUCCESS;
4206 uint16_t mb[MAILBOX_REGISTER_COUNT];
4207 struct qla_hw_data *ha = vha->hw;
4208 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4209 struct req_que *req = ha->req_q_map[vha->req_ques[0]];
4210 struct rsp_que *rsp = req->rsp;
4215 rval = qla2x00_fw_ready(base_vha);
4216 if (rval == QLA_SUCCESS) {
4217 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
4218 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
4221 vha->flags.management_server_logged_in = 0;
4223 /* Login to SNS first */
4224 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
4225 if (mb[0] != MBS_COMMAND_COMPLETE) {
4226 DEBUG15(qla_printk(KERN_INFO, ha,
4227 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4228 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4229 mb[0], mb[1], mb[2], mb[6], mb[7]));
4230 return (QLA_FUNCTION_FAILED);
4233 atomic_set(&vha->loop_down_timer, 0);
4234 atomic_set(&vha->loop_state, LOOP_UP);
4235 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4236 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4237 rval = qla2x00_loop_resync(base_vha);
4242 /* 84XX Support **************************************************************/
4244 static LIST_HEAD(qla_cs84xx_list);
4245 static DEFINE_MUTEX(qla_cs84xx_mutex);
4247 static struct qla_chip_state_84xx *
4248 qla84xx_get_chip(struct scsi_qla_host *vha)
4250 struct qla_chip_state_84xx *cs84xx;
4251 struct qla_hw_data *ha = vha->hw;
4253 mutex_lock(&qla_cs84xx_mutex);
4255 /* Find any shared 84xx chip. */
4256 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4257 if (cs84xx->bus == ha->pdev->bus) {
4258 kref_get(&cs84xx->kref);
4263 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4267 kref_init(&cs84xx->kref);
4268 spin_lock_init(&cs84xx->access_lock);
4269 mutex_init(&cs84xx->fw_update_mutex);
4270 cs84xx->bus = ha->pdev->bus;
4272 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4274 mutex_unlock(&qla_cs84xx_mutex);
4279 __qla84xx_chip_release(struct kref *kref)
4281 struct qla_chip_state_84xx *cs84xx =
4282 container_of(kref, struct qla_chip_state_84xx, kref);
4284 mutex_lock(&qla_cs84xx_mutex);
4285 list_del(&cs84xx->list);
4286 mutex_unlock(&qla_cs84xx_mutex);
4291 qla84xx_put_chip(struct scsi_qla_host *vha)
4293 struct qla_hw_data *ha = vha->hw;
4295 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4299 qla84xx_init_chip(scsi_qla_host_t *vha)
4303 struct qla_hw_data *ha = vha->hw;
4305 mutex_lock(&ha->cs84xx->fw_update_mutex);
4307 rval = qla84xx_verify_chip(vha, status);
4309 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4311 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4315 /* 81XX Support **************************************************************/
4318 qla81xx_nvram_config(scsi_qla_host_t *vha)
4321 struct init_cb_81xx *icb;
4322 struct nvram_81xx *nv;
4324 uint8_t *dptr1, *dptr2;
4327 struct qla_hw_data *ha = vha->hw;
4330 icb = (struct init_cb_81xx *)ha->init_cb;
4333 /* Determine NVRAM starting address. */
4334 ha->nvram_size = sizeof(struct nvram_81xx);
4335 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4336 ha->vpd_size = FA_NVRAM_VPD_SIZE;
4337 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4338 if (PCI_FUNC(ha->pdev->devfn) & 1) {
4339 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
4340 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4343 /* Get VPD data into cache */
4344 ha->vpd = ha->nvram + VPD_OFFSET;
4345 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
4346 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4348 /* Get NVRAM data into cache and calculate checksum. */
4349 dptr = (uint32_t *)nv;
4350 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
4352 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4353 chksum += le32_to_cpu(*dptr++);
4355 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
4356 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4358 /* Bad NVRAM data, set defaults parameters. */
4359 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4360 || nv->id[3] != ' ' ||
4361 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4362 /* Reset NVRAM data. */
4363 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4364 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4365 le16_to_cpu(nv->nvram_version));
4366 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4367 "invalid -- WWPN) defaults.\n");
4370 * Set default initialization control block.
4372 memset(nv, 0, ha->nvram_size);
4373 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4374 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4375 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4376 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4377 nv->exchange_count = __constant_cpu_to_le16(0);
4378 nv->port_name[0] = 0x21;
4379 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
4380 nv->port_name[2] = 0x00;
4381 nv->port_name[3] = 0xe0;
4382 nv->port_name[4] = 0x8b;
4383 nv->port_name[5] = 0x1c;
4384 nv->port_name[6] = 0x55;
4385 nv->port_name[7] = 0x86;
4386 nv->node_name[0] = 0x20;
4387 nv->node_name[1] = 0x00;
4388 nv->node_name[2] = 0x00;
4389 nv->node_name[3] = 0xe0;
4390 nv->node_name[4] = 0x8b;
4391 nv->node_name[5] = 0x1c;
4392 nv->node_name[6] = 0x55;
4393 nv->node_name[7] = 0x86;
4394 nv->login_retry_count = __constant_cpu_to_le16(8);
4395 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4396 nv->login_timeout = __constant_cpu_to_le16(0);
4397 nv->firmware_options_1 =
4398 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4399 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4400 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4401 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4402 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4403 nv->efi_parameters = __constant_cpu_to_le32(0);
4404 nv->reset_delay = 5;
4405 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4406 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4407 nv->link_down_timeout = __constant_cpu_to_le16(30);
4408 nv->enode_mac[0] = 0x01;
4409 nv->enode_mac[1] = 0x02;
4410 nv->enode_mac[2] = 0x03;
4411 nv->enode_mac[3] = 0x04;
4412 nv->enode_mac[4] = 0x05;
4413 nv->enode_mac[5] = 0x06 + PCI_FUNC(ha->pdev->devfn);
4418 /* Reset Initialization control block */
4419 memset(icb, 0, sizeof(struct init_cb_81xx));
4421 /* Copy 1st segment. */
4422 dptr1 = (uint8_t *)icb;
4423 dptr2 = (uint8_t *)&nv->version;
4424 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4426 *dptr1++ = *dptr2++;
4428 icb->login_retry_count = nv->login_retry_count;
4430 /* Copy 2nd segment. */
4431 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4432 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4433 cnt = (uint8_t *)&icb->reserved_5 -
4434 (uint8_t *)&icb->interrupt_delay_timer;
4436 *dptr1++ = *dptr2++;
4438 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4439 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4440 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4441 icb->enode_mac[0] = 0x01;
4442 icb->enode_mac[1] = 0x02;
4443 icb->enode_mac[2] = 0x03;
4444 icb->enode_mac[3] = 0x04;
4445 icb->enode_mac[4] = 0x05;
4446 icb->enode_mac[5] = 0x06 + PCI_FUNC(ha->pdev->devfn);
4450 * Setup driver NVRAM options.
4452 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4455 /* Use alternate WWN? */
4456 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4457 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4458 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4461 /* Prepare nodename */
4462 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4464 * Firmware will apply the following mask if the nodename was
4467 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4468 icb->node_name[0] &= 0xF0;
4471 /* Set host adapter parameters. */
4472 ha->flags.disable_risc_code_load = 0;
4473 ha->flags.enable_lip_reset = 0;
4474 ha->flags.enable_lip_full_login =
4475 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4476 ha->flags.enable_target_reset =
4477 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4478 ha->flags.enable_led_scheme = 0;
4479 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4481 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4482 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4484 /* save HBA serial number */
4485 ha->serial0 = icb->port_name[5];
4486 ha->serial1 = icb->port_name[6];
4487 ha->serial2 = icb->port_name[7];
4488 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4489 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4491 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4493 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4495 /* Set minimum login_timeout to 4 seconds. */
4496 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4497 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4498 if (le16_to_cpu(nv->login_timeout) < 4)
4499 nv->login_timeout = __constant_cpu_to_le16(4);
4500 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4501 icb->login_timeout = nv->login_timeout;
4503 /* Set minimum RATOV to 100 tenths of a second. */
4506 ha->loop_reset_delay = nv->reset_delay;
4508 /* Link Down Timeout = 0:
4510 * When Port Down timer expires we will start returning
4511 * I/O's to OS with "DID_NO_CONNECT".
4513 * Link Down Timeout != 0:
4515 * The driver waits for the link to come up after link down
4516 * before returning I/Os to OS with "DID_NO_CONNECT".
4518 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4519 ha->loop_down_abort_time =
4520 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4522 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4523 ha->loop_down_abort_time =
4524 (LOOP_DOWN_TIME - ha->link_down_timeout);
4527 /* Need enough time to try and get the port back. */
4528 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4529 if (qlport_down_retry)
4530 ha->port_down_retry_count = qlport_down_retry;
4532 /* Set login_retry_count */
4533 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4534 if (ha->port_down_retry_count ==
4535 le16_to_cpu(nv->port_down_retry_count) &&
4536 ha->port_down_retry_count > 3)
4537 ha->login_retry_count = ha->port_down_retry_count;
4538 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4539 ha->login_retry_count = ha->port_down_retry_count;
4540 if (ql2xloginretrycount)
4541 ha->login_retry_count = ql2xloginretrycount;
4544 if (!vha->flags.init_done) {
4545 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4546 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4547 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4548 le16_to_cpu(icb->interrupt_delay_timer): 2;
4550 icb->firmware_options_2 &= __constant_cpu_to_le32(
4551 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4552 vha->flags.process_response_queue = 0;
4553 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4554 ha->zio_mode = QLA_ZIO_MODE_6;
4556 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4557 "(%d us).\n", vha->host_no, ha->zio_mode,
4558 ha->zio_timer * 100));
4559 qla_printk(KERN_INFO, ha,
4560 "ZIO mode %d enabled; timer delay (%d us).\n",
4561 ha->zio_mode, ha->zio_timer * 100);
4563 icb->firmware_options_2 |= cpu_to_le32(
4564 (uint32_t)ha->zio_mode);
4565 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4566 vha->flags.process_response_queue = 1;
4570 DEBUG2_3(printk(KERN_WARNING
4571 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4577 qla81xx_update_fw_options(scsi_qla_host_t *ha)