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/slab.h>
12 #include <linux/vmalloc.h>
14 #include "qla_devtbl.h"
21 * QLogic ISP2x00 Hardware Support Function Prototypes.
23 static int qla2x00_isp_firmware(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 /* SRB Extensions ---------------------------------------------------------- */
47 qla2x00_ctx_sp_timeout(unsigned long __data)
49 srb_t *sp = (srb_t *)__data;
51 fc_port_t *fcport = sp->fcport;
52 struct qla_hw_data *ha = fcport->vha->hw;
56 spin_lock_irqsave(&ha->hardware_lock, flags);
57 req = ha->req_q_map[0];
58 req->outstanding_cmds[sp->handle] = NULL;
61 spin_unlock_irqrestore(&ha->hardware_lock, flags);
67 qla2x00_ctx_sp_free(srb_t *sp)
69 struct srb_ctx *ctx = sp->ctx;
72 mempool_free(sp, sp->fcport->vha->hw->srb_mempool);
76 qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size,
80 struct qla_hw_data *ha = vha->hw;
83 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
86 ctx = kzalloc(size, GFP_KERNEL);
88 mempool_free(sp, ha->srb_mempool);
92 memset(sp, 0, sizeof(*sp));
95 ctx->free = qla2x00_ctx_sp_free;
97 init_timer(&ctx->timer);
100 ctx->timer.expires = jiffies + tmo * HZ;
101 ctx->timer.data = (unsigned long)sp;
102 ctx->timer.function = qla2x00_ctx_sp_timeout;
103 add_timer(&ctx->timer);
108 /* Asynchronous Login/Logout Routines -------------------------------------- */
110 #define ELS_TMO_2_RATOV(ha) ((ha)->r_a_tov / 10 * 2)
113 qla2x00_async_logio_timeout(srb_t *sp)
115 fc_port_t *fcport = sp->fcport;
116 struct srb_logio *lio = sp->ctx;
118 DEBUG2(printk(KERN_WARNING
119 "scsi(%ld:%x): Async-%s timeout.\n",
120 fcport->vha->host_no, sp->handle,
121 lio->ctx.type == SRB_LOGIN_CMD ? "login": "logout"));
123 if (lio->ctx.type == SRB_LOGIN_CMD)
124 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
128 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
131 struct qla_hw_data *ha = vha->hw;
133 struct srb_logio *lio;
136 rval = QLA_FUNCTION_FAILED;
137 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_logio),
138 ELS_TMO_2_RATOV(ha) + 2);
143 lio->ctx.type = SRB_LOGIN_CMD;
144 lio->ctx.timeout = qla2x00_async_logio_timeout;
145 lio->flags |= SRB_LOGIN_COND_PLOGI;
146 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
147 lio->flags |= SRB_LOGIN_RETRIED;
148 rval = qla2x00_start_sp(sp);
149 if (rval != QLA_SUCCESS)
152 DEBUG2(printk(KERN_DEBUG
153 "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
154 "retries=%d.\n", fcport->vha->host_no, sp->handle, fcport->loop_id,
155 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
156 fcport->login_retry));
160 del_timer_sync(&lio->ctx.timer);
167 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
169 struct qla_hw_data *ha = vha->hw;
171 struct srb_logio *lio;
174 rval = QLA_FUNCTION_FAILED;
175 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_logio),
176 ELS_TMO_2_RATOV(ha) + 2);
181 lio->ctx.type = SRB_LOGOUT_CMD;
182 lio->ctx.timeout = qla2x00_async_logio_timeout;
183 rval = qla2x00_start_sp(sp);
184 if (rval != QLA_SUCCESS)
187 DEBUG2(printk(KERN_DEBUG
188 "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
189 fcport->vha->host_no, sp->handle, fcport->loop_id,
190 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
194 del_timer_sync(&lio->ctx.timer);
201 qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
208 case MBS_COMMAND_COMPLETE:
209 if (fcport->flags & FCF_FCP2_DEVICE)
211 rval = qla2x00_get_port_database(vha, fcport, opts);
212 if (rval != QLA_SUCCESS)
213 qla2x00_mark_device_lost(vha, fcport, 1, 0);
215 qla2x00_update_fcport(vha, fcport);
217 case MBS_COMMAND_ERROR:
218 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
219 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
221 qla2x00_mark_device_lost(vha, fcport, 1, 0);
223 case MBS_PORT_ID_USED:
224 fcport->loop_id = data[1];
225 qla2x00_post_async_login_work(vha, fcport, NULL);
227 case MBS_LOOP_ID_USED:
229 rval = qla2x00_find_new_loop_id(vha, fcport);
230 if (rval != QLA_SUCCESS) {
231 qla2x00_mark_device_lost(vha, fcport, 1, 0);
234 qla2x00_post_async_login_work(vha, fcport, NULL);
241 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
244 qla2x00_mark_device_lost(vha, fcport, 1, 0);
248 /****************************************************************************/
249 /* QLogic ISP2x00 Hardware Support Functions. */
250 /****************************************************************************/
253 * qla2x00_initialize_adapter
257 * ha = adapter block pointer.
263 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
266 struct qla_hw_data *ha = vha->hw;
267 struct req_que *req = ha->req_q_map[0];
269 /* Clear adapter flags. */
270 vha->flags.online = 0;
271 ha->flags.chip_reset_done = 0;
272 vha->flags.reset_active = 0;
273 ha->flags.pci_channel_io_perm_failure = 0;
274 ha->flags.eeh_busy = 0;
275 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
276 atomic_set(&vha->loop_state, LOOP_DOWN);
277 vha->device_flags = DFLG_NO_CABLE;
279 vha->flags.management_server_logged_in = 0;
280 vha->marker_needed = 0;
281 ha->isp_abort_cnt = 0;
282 ha->beacon_blink_led = 0;
284 set_bit(0, ha->req_qid_map);
285 set_bit(0, ha->rsp_qid_map);
287 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
288 rval = ha->isp_ops->pci_config(vha);
290 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
295 ha->isp_ops->reset_chip(vha);
297 rval = qla2xxx_get_flash_info(vha);
299 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
304 ha->isp_ops->get_flash_version(vha, req->ring);
306 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
308 ha->isp_ops->nvram_config(vha);
310 if (ha->flags.disable_serdes) {
311 /* Mask HBA via NVRAM settings? */
312 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
313 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
314 vha->port_name[0], vha->port_name[1],
315 vha->port_name[2], vha->port_name[3],
316 vha->port_name[4], vha->port_name[5],
317 vha->port_name[6], vha->port_name[7]);
318 return QLA_FUNCTION_FAILED;
321 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
323 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
324 rval = ha->isp_ops->chip_diag(vha);
327 rval = qla2x00_setup_chip(vha);
332 if (IS_QLA84XX(ha)) {
333 ha->cs84xx = qla84xx_get_chip(vha);
335 qla_printk(KERN_ERR, ha,
336 "Unable to configure ISP84XX.\n");
337 return QLA_FUNCTION_FAILED;
340 rval = qla2x00_init_rings(vha);
341 ha->flags.chip_reset_done = 1;
343 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
344 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
345 rval = qla84xx_init_chip(vha);
346 if (rval != QLA_SUCCESS) {
347 qla_printk(KERN_ERR, ha,
348 "Unable to initialize ISP84XX.\n");
349 qla84xx_put_chip(vha);
353 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) {
354 if (qla24xx_read_fcp_prio_cfg(vha))
355 qla_printk(KERN_ERR, ha,
356 "Unable to read FCP priority data.\n");
363 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
366 * Returns 0 on success.
369 qla2100_pci_config(scsi_qla_host_t *vha)
373 struct qla_hw_data *ha = vha->hw;
374 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
376 pci_set_master(ha->pdev);
377 pci_try_set_mwi(ha->pdev);
379 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
380 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
381 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
383 pci_disable_rom(ha->pdev);
385 /* Get PCI bus information. */
386 spin_lock_irqsave(&ha->hardware_lock, flags);
387 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
388 spin_unlock_irqrestore(&ha->hardware_lock, flags);
394 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
397 * Returns 0 on success.
400 qla2300_pci_config(scsi_qla_host_t *vha)
403 unsigned long flags = 0;
405 struct qla_hw_data *ha = vha->hw;
406 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
408 pci_set_master(ha->pdev);
409 pci_try_set_mwi(ha->pdev);
411 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
412 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
414 if (IS_QLA2322(ha) || IS_QLA6322(ha))
415 w &= ~PCI_COMMAND_INTX_DISABLE;
416 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
419 * If this is a 2300 card and not 2312, reset the
420 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
421 * the 2310 also reports itself as a 2300 so we need to get the
422 * fb revision level -- a 6 indicates it really is a 2300 and
425 if (IS_QLA2300(ha)) {
426 spin_lock_irqsave(&ha->hardware_lock, flags);
429 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
430 for (cnt = 0; cnt < 30000; cnt++) {
431 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
437 /* Select FPM registers. */
438 WRT_REG_WORD(®->ctrl_status, 0x20);
439 RD_REG_WORD(®->ctrl_status);
441 /* Get the fb rev level */
442 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
444 if (ha->fb_rev == FPM_2300)
445 pci_clear_mwi(ha->pdev);
447 /* Deselect FPM registers. */
448 WRT_REG_WORD(®->ctrl_status, 0x0);
449 RD_REG_WORD(®->ctrl_status);
451 /* Release RISC module. */
452 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
453 for (cnt = 0; cnt < 30000; cnt++) {
454 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
460 spin_unlock_irqrestore(&ha->hardware_lock, flags);
463 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
465 pci_disable_rom(ha->pdev);
467 /* Get PCI bus information. */
468 spin_lock_irqsave(&ha->hardware_lock, flags);
469 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
470 spin_unlock_irqrestore(&ha->hardware_lock, flags);
476 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
479 * Returns 0 on success.
482 qla24xx_pci_config(scsi_qla_host_t *vha)
485 unsigned long flags = 0;
486 struct qla_hw_data *ha = vha->hw;
487 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
489 pci_set_master(ha->pdev);
490 pci_try_set_mwi(ha->pdev);
492 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
493 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
494 w &= ~PCI_COMMAND_INTX_DISABLE;
495 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
497 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
499 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
500 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
501 pcix_set_mmrbc(ha->pdev, 2048);
503 /* PCIe -- adjust Maximum Read Request Size (2048). */
504 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
505 pcie_set_readrq(ha->pdev, 2048);
507 pci_disable_rom(ha->pdev);
509 ha->chip_revision = ha->pdev->revision;
511 /* Get PCI bus information. */
512 spin_lock_irqsave(&ha->hardware_lock, flags);
513 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
514 spin_unlock_irqrestore(&ha->hardware_lock, flags);
520 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
523 * Returns 0 on success.
526 qla25xx_pci_config(scsi_qla_host_t *vha)
529 struct qla_hw_data *ha = vha->hw;
531 pci_set_master(ha->pdev);
532 pci_try_set_mwi(ha->pdev);
534 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
535 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
536 w &= ~PCI_COMMAND_INTX_DISABLE;
537 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
539 /* PCIe -- adjust Maximum Read Request Size (2048). */
540 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
541 pcie_set_readrq(ha->pdev, 2048);
543 pci_disable_rom(ha->pdev);
545 ha->chip_revision = ha->pdev->revision;
551 * qla2x00_isp_firmware() - Choose firmware image.
554 * Returns 0 on success.
557 qla2x00_isp_firmware(scsi_qla_host_t *vha)
560 uint16_t loop_id, topo, sw_cap;
561 uint8_t domain, area, al_pa;
562 struct qla_hw_data *ha = vha->hw;
564 /* Assume loading risc code */
565 rval = QLA_FUNCTION_FAILED;
567 if (ha->flags.disable_risc_code_load) {
568 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
570 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
572 /* Verify checksum of loaded RISC code. */
573 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
574 if (rval == QLA_SUCCESS) {
575 /* And, verify we are not in ROM code. */
576 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
577 &area, &domain, &topo, &sw_cap);
582 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
590 * qla2x00_reset_chip() - Reset ISP chip.
593 * Returns 0 on success.
596 qla2x00_reset_chip(scsi_qla_host_t *vha)
598 unsigned long flags = 0;
599 struct qla_hw_data *ha = vha->hw;
600 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
604 if (unlikely(pci_channel_offline(ha->pdev)))
607 ha->isp_ops->disable_intrs(ha);
609 spin_lock_irqsave(&ha->hardware_lock, flags);
611 /* Turn off master enable */
613 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
614 cmd &= ~PCI_COMMAND_MASTER;
615 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
617 if (!IS_QLA2100(ha)) {
619 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
620 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
621 for (cnt = 0; cnt < 30000; cnt++) {
622 if ((RD_REG_WORD(®->hccr) &
623 HCCR_RISC_PAUSE) != 0)
628 RD_REG_WORD(®->hccr); /* PCI Posting. */
632 /* Select FPM registers. */
633 WRT_REG_WORD(®->ctrl_status, 0x20);
634 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
636 /* FPM Soft Reset. */
637 WRT_REG_WORD(®->fpm_diag_config, 0x100);
638 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
640 /* Toggle Fpm Reset. */
641 if (!IS_QLA2200(ha)) {
642 WRT_REG_WORD(®->fpm_diag_config, 0x0);
643 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
646 /* Select frame buffer registers. */
647 WRT_REG_WORD(®->ctrl_status, 0x10);
648 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
650 /* Reset frame buffer FIFOs. */
651 if (IS_QLA2200(ha)) {
652 WRT_FB_CMD_REG(ha, reg, 0xa000);
653 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
655 WRT_FB_CMD_REG(ha, reg, 0x00fc);
657 /* Read back fb_cmd until zero or 3 seconds max */
658 for (cnt = 0; cnt < 3000; cnt++) {
659 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
665 /* Select RISC module registers. */
666 WRT_REG_WORD(®->ctrl_status, 0);
667 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
669 /* Reset RISC processor. */
670 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
671 RD_REG_WORD(®->hccr); /* PCI Posting. */
673 /* Release RISC processor. */
674 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
675 RD_REG_WORD(®->hccr); /* PCI Posting. */
678 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
679 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
681 /* Reset ISP chip. */
682 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
684 /* Wait for RISC to recover from reset. */
685 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
687 * It is necessary to for a delay here since the card doesn't
688 * respond to PCI reads during a reset. On some architectures
689 * this will result in an MCA.
692 for (cnt = 30000; cnt; cnt--) {
693 if ((RD_REG_WORD(®->ctrl_status) &
694 CSR_ISP_SOFT_RESET) == 0)
701 /* Reset RISC processor. */
702 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
704 WRT_REG_WORD(®->semaphore, 0);
706 /* Release RISC processor. */
707 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
708 RD_REG_WORD(®->hccr); /* PCI Posting. */
710 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
711 for (cnt = 0; cnt < 30000; cnt++) {
712 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
720 /* Turn on master enable */
721 cmd |= PCI_COMMAND_MASTER;
722 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
724 /* Disable RISC pause on FPM parity error. */
725 if (!IS_QLA2100(ha)) {
726 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
727 RD_REG_WORD(®->hccr); /* PCI Posting. */
730 spin_unlock_irqrestore(&ha->hardware_lock, flags);
734 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
737 * Returns 0 on success.
740 qla24xx_reset_risc(scsi_qla_host_t *vha)
742 unsigned long flags = 0;
743 struct qla_hw_data *ha = vha->hw;
744 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
748 spin_lock_irqsave(&ha->hardware_lock, flags);
751 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
752 for (cnt = 0; cnt < 30000; cnt++) {
753 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
759 WRT_REG_DWORD(®->ctrl_status,
760 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
761 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
764 /* Wait for firmware to complete NVRAM accesses. */
765 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
766 for (cnt = 10000 ; cnt && d2; cnt--) {
768 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
772 /* Wait for soft-reset to complete. */
773 d2 = RD_REG_DWORD(®->ctrl_status);
774 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
776 d2 = RD_REG_DWORD(®->ctrl_status);
780 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
781 RD_REG_DWORD(®->hccr);
783 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
784 RD_REG_DWORD(®->hccr);
786 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
787 RD_REG_DWORD(®->hccr);
789 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
790 for (cnt = 6000000 ; cnt && d2; cnt--) {
792 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
796 spin_unlock_irqrestore(&ha->hardware_lock, flags);
798 if (IS_NOPOLLING_TYPE(ha))
799 ha->isp_ops->enable_intrs(ha);
803 * qla24xx_reset_chip() - Reset ISP24xx chip.
806 * Returns 0 on success.
809 qla24xx_reset_chip(scsi_qla_host_t *vha)
811 struct qla_hw_data *ha = vha->hw;
813 if (pci_channel_offline(ha->pdev) &&
814 ha->flags.pci_channel_io_perm_failure) {
818 ha->isp_ops->disable_intrs(ha);
820 /* Perform RISC reset. */
821 qla24xx_reset_risc(vha);
825 * qla2x00_chip_diag() - Test chip for proper operation.
828 * Returns 0 on success.
831 qla2x00_chip_diag(scsi_qla_host_t *vha)
834 struct qla_hw_data *ha = vha->hw;
835 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
836 unsigned long flags = 0;
840 struct req_que *req = ha->req_q_map[0];
842 /* Assume a failed state */
843 rval = QLA_FUNCTION_FAILED;
845 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
846 vha->host_no, (u_long)®->flash_address));
848 spin_lock_irqsave(&ha->hardware_lock, flags);
850 /* Reset ISP chip. */
851 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
854 * We need to have a delay here since the card will not respond while
855 * in reset causing an MCA on some architectures.
858 data = qla2x00_debounce_register(®->ctrl_status);
859 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
861 data = RD_REG_WORD(®->ctrl_status);
866 goto chip_diag_failed;
868 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
871 /* Reset RISC processor. */
872 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
873 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
875 /* Workaround for QLA2312 PCI parity error */
876 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
877 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
878 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
880 data = RD_MAILBOX_REG(ha, reg, 0);
887 goto chip_diag_failed;
889 /* Check product ID of chip */
890 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
892 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
893 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
894 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
895 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
896 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
897 mb[3] != PROD_ID_3) {
898 qla_printk(KERN_WARNING, ha,
899 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
901 goto chip_diag_failed;
903 ha->product_id[0] = mb[1];
904 ha->product_id[1] = mb[2];
905 ha->product_id[2] = mb[3];
906 ha->product_id[3] = mb[4];
908 /* Adjust fw RISC transfer size */
909 if (req->length > 1024)
910 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
912 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
915 if (IS_QLA2200(ha) &&
916 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
917 /* Limit firmware transfer size with a 2200A */
918 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
921 ha->device_type |= DT_ISP2200A;
922 ha->fw_transfer_size = 128;
925 /* Wrap Incoming Mailboxes Test. */
926 spin_unlock_irqrestore(&ha->hardware_lock, flags);
928 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
929 rval = qla2x00_mbx_reg_test(vha);
931 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
933 qla_printk(KERN_WARNING, ha,
934 "Failed mailbox send register test\n");
937 /* Flag a successful rval */
940 spin_lock_irqsave(&ha->hardware_lock, flags);
944 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
945 "****\n", vha->host_no));
947 spin_unlock_irqrestore(&ha->hardware_lock, flags);
953 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
956 * Returns 0 on success.
959 qla24xx_chip_diag(scsi_qla_host_t *vha)
962 struct qla_hw_data *ha = vha->hw;
963 struct req_que *req = ha->req_q_map[0];
968 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
970 rval = qla2x00_mbx_reg_test(vha);
972 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
974 qla_printk(KERN_WARNING, ha,
975 "Failed mailbox send register test\n");
977 /* Flag a successful rval */
985 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
988 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
989 eft_size, fce_size, mq_size;
992 struct qla_hw_data *ha = vha->hw;
993 struct req_que *req = ha->req_q_map[0];
994 struct rsp_que *rsp = ha->rsp_q_map[0];
997 qla_printk(KERN_WARNING, ha,
998 "Firmware dump previously allocated.\n");
1003 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
1004 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1005 fixed_size = sizeof(struct qla2100_fw_dump);
1006 } else if (IS_QLA23XX(ha)) {
1007 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1008 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1010 } else if (IS_FWI2_CAPABLE(ha)) {
1012 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1013 else if (IS_QLA25XX(ha))
1014 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1016 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
1017 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1020 mq_size = sizeof(struct qla2xxx_mq_chain);
1021 /* Allocate memory for Fibre Channel Event Buffer. */
1022 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
1025 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1028 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1029 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
1033 memset(tc, 0, FCE_SIZE);
1034 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
1035 ha->fce_mb, &ha->fce_bufs);
1037 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1038 "FCE (%d).\n", rval);
1039 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1041 ha->flags.fce_enabled = 0;
1045 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
1048 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
1049 ha->flags.fce_enabled = 1;
1050 ha->fce_dma = tc_dma;
1053 /* Allocate memory for Extended Trace Buffer. */
1054 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
1057 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1058 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
1062 memset(tc, 0, EFT_SIZE);
1063 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
1065 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1066 "EFT (%d).\n", rval);
1067 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1072 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
1075 eft_size = EFT_SIZE;
1076 ha->eft_dma = tc_dma;
1080 req_q_size = req->length * sizeof(request_t);
1081 rsp_q_size = rsp->length * sizeof(response_t);
1083 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
1084 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
1085 ha->chain_offset = dump_size;
1086 dump_size += mq_size + fce_size;
1088 ha->fw_dump = vmalloc(dump_size);
1090 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
1091 "firmware dump!!!\n", dump_size / 1024);
1094 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1101 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
1104 ha->fw_dump_len = dump_size;
1105 ha->fw_dump->signature[0] = 'Q';
1106 ha->fw_dump->signature[1] = 'L';
1107 ha->fw_dump->signature[2] = 'G';
1108 ha->fw_dump->signature[3] = 'C';
1109 ha->fw_dump->version = __constant_htonl(1);
1111 ha->fw_dump->fixed_size = htonl(fixed_size);
1112 ha->fw_dump->mem_size = htonl(mem_size);
1113 ha->fw_dump->req_q_size = htonl(req_q_size);
1114 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1116 ha->fw_dump->eft_size = htonl(eft_size);
1117 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1118 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1120 ha->fw_dump->header_size =
1121 htonl(offsetof(struct qla2xxx_fw_dump, isp));
1125 qla81xx_mpi_sync(scsi_qla_host_t *vha)
1127 #define MPS_MASK 0xe0
1131 struct qla_hw_data *ha = vha->hw;
1133 if (!IS_QLA81XX(vha->hw))
1136 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1137 if (rval != QLA_SUCCESS) {
1138 DEBUG2(qla_printk(KERN_WARNING, ha,
1139 "Sync-MPI: Unable to acquire semaphore.\n"));
1143 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1144 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1145 if (rval != QLA_SUCCESS) {
1146 DEBUG2(qla_printk(KERN_WARNING, ha,
1147 "Sync-MPI: Unable to read sync.\n"));
1152 if (dc == (dw & MPS_MASK))
1157 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1158 if (rval != QLA_SUCCESS) {
1159 DEBUG2(qla_printk(KERN_WARNING, ha,
1160 "Sync-MPI: Unable to gain sync.\n"));
1164 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1165 if (rval != QLA_SUCCESS) {
1166 DEBUG2(qla_printk(KERN_WARNING, ha,
1167 "Sync-MPI: Unable to release semaphore.\n"));
1175 * qla2x00_setup_chip() - Load and start RISC firmware.
1178 * Returns 0 on success.
1181 qla2x00_setup_chip(scsi_qla_host_t *vha)
1184 uint32_t srisc_address = 0;
1185 struct qla_hw_data *ha = vha->hw;
1186 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1187 unsigned long flags;
1188 uint16_t fw_major_version;
1190 if (IS_QLA82XX(ha)) {
1191 rval = ha->isp_ops->load_risc(vha, &srisc_address);
1192 if (rval == QLA_SUCCESS)
1193 goto enable_82xx_npiv;
1196 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1197 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1198 spin_lock_irqsave(&ha->hardware_lock, flags);
1199 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
1200 RD_REG_WORD(®->hccr);
1201 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1204 qla81xx_mpi_sync(vha);
1206 /* Load firmware sequences */
1207 rval = ha->isp_ops->load_risc(vha, &srisc_address);
1208 if (rval == QLA_SUCCESS) {
1209 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
1210 "code.\n", vha->host_no));
1212 rval = qla2x00_verify_checksum(vha, srisc_address);
1213 if (rval == QLA_SUCCESS) {
1214 /* Start firmware execution. */
1215 DEBUG(printk("scsi(%ld): Checksum OK, start "
1216 "firmware.\n", vha->host_no));
1218 rval = qla2x00_execute_fw(vha, srisc_address);
1219 /* Retrieve firmware information. */
1220 if (rval == QLA_SUCCESS) {
1222 fw_major_version = ha->fw_major_version;
1223 rval = qla2x00_get_fw_version(vha,
1224 &ha->fw_major_version,
1225 &ha->fw_minor_version,
1226 &ha->fw_subminor_version,
1227 &ha->fw_attributes, &ha->fw_memory_size,
1228 ha->mpi_version, &ha->mpi_capabilities,
1230 if (rval != QLA_SUCCESS)
1232 ha->flags.npiv_supported = 0;
1233 if (IS_QLA2XXX_MIDTYPE(ha) &&
1234 (ha->fw_attributes & BIT_2)) {
1235 ha->flags.npiv_supported = 1;
1236 if ((!ha->max_npiv_vports) ||
1237 ((ha->max_npiv_vports + 1) %
1238 MIN_MULTI_ID_FABRIC))
1239 ha->max_npiv_vports =
1240 MIN_MULTI_ID_FABRIC - 1;
1242 qla2x00_get_resource_cnts(vha, NULL,
1243 &ha->fw_xcb_count, NULL, NULL,
1244 &ha->max_npiv_vports, NULL);
1246 if (!fw_major_version && ql2xallocfwdump) {
1247 if (!IS_QLA82XX(ha))
1248 qla2x00_alloc_fw_dump(vha);
1252 DEBUG2(printk(KERN_INFO
1253 "scsi(%ld): ISP Firmware failed checksum.\n",
1258 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1259 /* Enable proper parity. */
1260 spin_lock_irqsave(&ha->hardware_lock, flags);
1263 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
1265 /* SRAM, Instruction RAM and GP RAM parity */
1266 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
1267 RD_REG_WORD(®->hccr);
1268 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1271 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1274 rval = qla81xx_fac_get_sector_size(vha, &size);
1275 if (rval == QLA_SUCCESS) {
1276 ha->flags.fac_supported = 1;
1277 ha->fdt_block_size = size << 2;
1279 qla_printk(KERN_ERR, ha,
1280 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1281 ha->fw_major_version, ha->fw_minor_version,
1282 ha->fw_subminor_version);
1287 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
1295 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1298 * Beginning of request ring has initialization control block already built
1299 * by nvram config routine.
1301 * Returns 0 on success.
1304 qla2x00_init_response_q_entries(struct rsp_que *rsp)
1309 rsp->ring_ptr = rsp->ring;
1310 rsp->ring_index = 0;
1311 rsp->status_srb = NULL;
1312 pkt = rsp->ring_ptr;
1313 for (cnt = 0; cnt < rsp->length; cnt++) {
1314 pkt->signature = RESPONSE_PROCESSED;
1320 * qla2x00_update_fw_options() - Read and process firmware options.
1323 * Returns 0 on success.
1326 qla2x00_update_fw_options(scsi_qla_host_t *vha)
1328 uint16_t swing, emphasis, tx_sens, rx_sens;
1329 struct qla_hw_data *ha = vha->hw;
1331 memset(ha->fw_options, 0, sizeof(ha->fw_options));
1332 qla2x00_get_fw_options(vha, ha->fw_options);
1334 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1337 /* Serial Link options. */
1338 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1340 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1341 sizeof(ha->fw_seriallink_options)));
1343 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1344 if (ha->fw_seriallink_options[3] & BIT_2) {
1345 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1348 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1349 emphasis = (ha->fw_seriallink_options[2] &
1350 (BIT_4 | BIT_3)) >> 3;
1351 tx_sens = ha->fw_seriallink_options[0] &
1352 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1353 rx_sens = (ha->fw_seriallink_options[0] &
1354 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1355 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1356 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1359 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1360 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1361 ha->fw_options[10] |= BIT_5 |
1362 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1363 (tx_sens & (BIT_1 | BIT_0));
1366 swing = (ha->fw_seriallink_options[2] &
1367 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1368 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1369 tx_sens = ha->fw_seriallink_options[1] &
1370 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1371 rx_sens = (ha->fw_seriallink_options[1] &
1372 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1373 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1374 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1377 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1378 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1379 ha->fw_options[11] |= BIT_5 |
1380 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1381 (tx_sens & (BIT_1 | BIT_0));
1385 /* Return command IOCBs without waiting for an ABTS to complete. */
1386 ha->fw_options[3] |= BIT_13;
1389 if (ha->flags.enable_led_scheme)
1390 ha->fw_options[2] |= BIT_12;
1392 /* Detect ISP6312. */
1394 ha->fw_options[2] |= BIT_13;
1396 /* Update firmware options. */
1397 qla2x00_set_fw_options(vha, ha->fw_options);
1401 qla24xx_update_fw_options(scsi_qla_host_t *vha)
1404 struct qla_hw_data *ha = vha->hw;
1409 /* Update Serial Link options. */
1410 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1413 rval = qla2x00_set_serdes_params(vha,
1414 le16_to_cpu(ha->fw_seriallink_options24[1]),
1415 le16_to_cpu(ha->fw_seriallink_options24[2]),
1416 le16_to_cpu(ha->fw_seriallink_options24[3]));
1417 if (rval != QLA_SUCCESS) {
1418 qla_printk(KERN_WARNING, ha,
1419 "Unable to update Serial Link options (%x).\n", rval);
1424 qla2x00_config_rings(struct scsi_qla_host *vha)
1426 struct qla_hw_data *ha = vha->hw;
1427 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1428 struct req_que *req = ha->req_q_map[0];
1429 struct rsp_que *rsp = ha->rsp_q_map[0];
1431 /* Setup ring parameters in initialization control block. */
1432 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1433 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1434 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1435 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1436 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1437 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1438 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1439 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
1441 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1442 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1443 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1444 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1445 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1449 qla24xx_config_rings(struct scsi_qla_host *vha)
1451 struct qla_hw_data *ha = vha->hw;
1452 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1453 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1454 struct qla_msix_entry *msix;
1455 struct init_cb_24xx *icb;
1457 struct req_que *req = ha->req_q_map[0];
1458 struct rsp_que *rsp = ha->rsp_q_map[0];
1460 /* Setup ring parameters in initialization control block. */
1461 icb = (struct init_cb_24xx *)ha->init_cb;
1462 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1463 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1464 icb->request_q_length = cpu_to_le16(req->length);
1465 icb->response_q_length = cpu_to_le16(rsp->length);
1466 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1467 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1468 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1469 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
1472 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1473 icb->rid = __constant_cpu_to_le16(rid);
1474 if (ha->flags.msix_enabled) {
1475 msix = &ha->msix_entries[1];
1476 DEBUG2_17(printk(KERN_INFO
1477 "Registering vector 0x%x for base que\n", msix->entry));
1478 icb->msix = cpu_to_le16(msix->entry);
1480 /* Use alternate PCI bus number */
1482 icb->firmware_options_2 |=
1483 __constant_cpu_to_le32(BIT_19);
1484 /* Use alternate PCI devfn */
1486 icb->firmware_options_2 |=
1487 __constant_cpu_to_le32(BIT_18);
1489 /* Use Disable MSIX Handshake mode for capable adapters */
1490 if (IS_MSIX_NACK_CAPABLE(ha)) {
1491 icb->firmware_options_2 &=
1492 __constant_cpu_to_le32(~BIT_22);
1493 ha->flags.disable_msix_handshake = 1;
1494 qla_printk(KERN_INFO, ha,
1495 "MSIX Handshake Disable Mode turned on\n");
1497 icb->firmware_options_2 |=
1498 __constant_cpu_to_le32(BIT_22);
1500 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
1502 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
1503 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
1504 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
1505 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
1507 WRT_REG_DWORD(®->isp24.req_q_in, 0);
1508 WRT_REG_DWORD(®->isp24.req_q_out, 0);
1509 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
1510 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
1513 RD_REG_DWORD(&ioreg->hccr);
1517 * qla2x00_init_rings() - Initializes firmware.
1520 * Beginning of request ring has initialization control block already built
1521 * by nvram config routine.
1523 * Returns 0 on success.
1526 qla2x00_init_rings(scsi_qla_host_t *vha)
1529 unsigned long flags = 0;
1531 struct qla_hw_data *ha = vha->hw;
1532 struct req_que *req;
1533 struct rsp_que *rsp;
1534 struct scsi_qla_host *vp;
1535 struct mid_init_cb_24xx *mid_init_cb =
1536 (struct mid_init_cb_24xx *) ha->init_cb;
1538 spin_lock_irqsave(&ha->hardware_lock, flags);
1540 /* Clear outstanding commands array. */
1541 for (que = 0; que < ha->max_req_queues; que++) {
1542 req = ha->req_q_map[que];
1545 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1546 req->outstanding_cmds[cnt] = NULL;
1548 req->current_outstanding_cmd = 1;
1550 /* Initialize firmware. */
1551 req->ring_ptr = req->ring;
1552 req->ring_index = 0;
1553 req->cnt = req->length;
1556 for (que = 0; que < ha->max_rsp_queues; que++) {
1557 rsp = ha->rsp_q_map[que];
1560 /* Initialize response queue entries */
1561 qla2x00_init_response_q_entries(rsp);
1564 /* Clear RSCN queue. */
1565 list_for_each_entry(vp, &ha->vp_list, list) {
1566 vp->rscn_in_ptr = 0;
1567 vp->rscn_out_ptr = 0;
1569 ha->isp_ops->config_rings(vha);
1571 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1573 /* Update any ISP specific firmware options before initialization. */
1574 ha->isp_ops->update_fw_options(vha);
1576 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
1578 if (ha->flags.npiv_supported) {
1579 if (ha->operating_mode == LOOP)
1580 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
1581 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1584 if (IS_FWI2_CAPABLE(ha)) {
1585 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1586 mid_init_cb->init_cb.execution_throttle =
1587 cpu_to_le16(ha->fw_xcb_count);
1590 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
1592 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1595 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1603 * qla2x00_fw_ready() - Waits for firmware ready.
1606 * Returns 0 on success.
1609 qla2x00_fw_ready(scsi_qla_host_t *vha)
1612 unsigned long wtime, mtime, cs84xx_time;
1613 uint16_t min_wait; /* Minimum wait time if loop is down */
1614 uint16_t wait_time; /* Wait time if loop is coming ready */
1616 struct qla_hw_data *ha = vha->hw;
1620 /* 20 seconds for loop down. */
1624 * Firmware should take at most one RATOV to login, plus 5 seconds for
1625 * our own processing.
1627 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1628 wait_time = min_wait;
1631 /* Min wait time if loop down */
1632 mtime = jiffies + (min_wait * HZ);
1634 /* wait time before firmware ready */
1635 wtime = jiffies + (wait_time * HZ);
1637 /* Wait for ISP to finish LIP */
1638 if (!vha->flags.init_done)
1639 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1641 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1645 rval = qla2x00_get_firmware_state(vha, state);
1646 if (rval == QLA_SUCCESS) {
1647 if (state[0] < FSTATE_LOSS_OF_SYNC) {
1648 vha->device_flags &= ~DFLG_NO_CABLE;
1650 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1651 DEBUG16(printk("scsi(%ld): fw_state=%x "
1652 "84xx=%x.\n", vha->host_no, state[0],
1654 if ((state[2] & FSTATE_LOGGED_IN) &&
1655 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1656 DEBUG16(printk("scsi(%ld): Sending "
1657 "verify iocb.\n", vha->host_no));
1659 cs84xx_time = jiffies;
1660 rval = qla84xx_init_chip(vha);
1661 if (rval != QLA_SUCCESS)
1664 /* Add time taken to initialize. */
1665 cs84xx_time = jiffies - cs84xx_time;
1666 wtime += cs84xx_time;
1667 mtime += cs84xx_time;
1668 DEBUG16(printk("scsi(%ld): Increasing "
1669 "wait time by %ld. New time %ld\n",
1670 vha->host_no, cs84xx_time, wtime));
1672 } else if (state[0] == FSTATE_READY) {
1673 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1676 qla2x00_get_retry_cnt(vha, &ha->retry_count,
1677 &ha->login_timeout, &ha->r_a_tov);
1683 rval = QLA_FUNCTION_FAILED;
1685 if (atomic_read(&vha->loop_down_timer) &&
1686 state[0] != FSTATE_READY) {
1687 /* Loop down. Timeout on min_wait for states
1688 * other than Wait for Login.
1690 if (time_after_eq(jiffies, mtime)) {
1691 qla_printk(KERN_INFO, ha,
1692 "Cable is unplugged...\n");
1694 vha->device_flags |= DFLG_NO_CABLE;
1699 /* Mailbox cmd failed. Timeout on min_wait. */
1700 if (time_after_eq(jiffies, mtime))
1704 if (time_after_eq(jiffies, wtime))
1707 /* Delay for a while */
1710 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1711 vha->host_no, state[0], jiffies));
1714 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1715 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1719 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1727 * qla2x00_configure_hba
1728 * Setup adapter context.
1731 * ha = adapter state pointer.
1740 qla2x00_configure_hba(scsi_qla_host_t *vha)
1749 char connect_type[22];
1750 struct qla_hw_data *ha = vha->hw;
1752 /* Get host addresses. */
1753 rval = qla2x00_get_adapter_id(vha,
1754 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
1755 if (rval != QLA_SUCCESS) {
1756 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
1757 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1758 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1759 __func__, vha->host_no));
1761 qla_printk(KERN_WARNING, ha,
1762 "ERROR -- Unable to get host loop ID.\n");
1763 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1769 qla_printk(KERN_INFO, ha,
1770 "Cannot get topology - retrying.\n");
1771 return (QLA_FUNCTION_FAILED);
1774 vha->loop_id = loop_id;
1777 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1778 ha->operating_mode = LOOP;
1783 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1785 ha->current_topology = ISP_CFG_NL;
1786 strcpy(connect_type, "(Loop)");
1790 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1792 ha->switch_cap = sw_cap;
1793 ha->current_topology = ISP_CFG_FL;
1794 strcpy(connect_type, "(FL_Port)");
1798 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1800 ha->operating_mode = P2P;
1801 ha->current_topology = ISP_CFG_N;
1802 strcpy(connect_type, "(N_Port-to-N_Port)");
1806 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1808 ha->switch_cap = sw_cap;
1809 ha->operating_mode = P2P;
1810 ha->current_topology = ISP_CFG_F;
1811 strcpy(connect_type, "(F_Port)");
1815 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1817 vha->host_no, topo));
1818 ha->current_topology = ISP_CFG_NL;
1819 strcpy(connect_type, "(Loop)");
1823 /* Save Host port and loop ID. */
1824 /* byte order - Big Endian */
1825 vha->d_id.b.domain = domain;
1826 vha->d_id.b.area = area;
1827 vha->d_id.b.al_pa = al_pa;
1829 if (!vha->flags.init_done)
1830 qla_printk(KERN_INFO, ha,
1831 "Topology - %s, Host Loop address 0x%x\n",
1832 connect_type, vha->loop_id);
1835 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
1837 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
1844 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1849 struct qla_hw_data *ha = vha->hw;
1850 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
1851 !IS_QLA8XXX_TYPE(ha);
1853 if (memcmp(model, BINZERO, len) != 0) {
1854 strncpy(ha->model_number, model, len);
1855 st = en = ha->model_number;
1858 if (*en != 0x20 && *en != 0x00)
1863 index = (ha->pdev->subsystem_device & 0xff);
1865 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1866 index < QLA_MODEL_NAMES)
1867 strncpy(ha->model_desc,
1868 qla2x00_model_name[index * 2 + 1],
1869 sizeof(ha->model_desc) - 1);
1871 index = (ha->pdev->subsystem_device & 0xff);
1873 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1874 index < QLA_MODEL_NAMES) {
1875 strcpy(ha->model_number,
1876 qla2x00_model_name[index * 2]);
1877 strncpy(ha->model_desc,
1878 qla2x00_model_name[index * 2 + 1],
1879 sizeof(ha->model_desc) - 1);
1881 strcpy(ha->model_number, def);
1884 if (IS_FWI2_CAPABLE(ha))
1885 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
1886 sizeof(ha->model_desc));
1889 /* On sparc systems, obtain port and node WWN from firmware
1892 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
1895 struct qla_hw_data *ha = vha->hw;
1896 struct pci_dev *pdev = ha->pdev;
1897 struct device_node *dp = pci_device_to_OF_node(pdev);
1901 val = of_get_property(dp, "port-wwn", &len);
1902 if (val && len >= WWN_SIZE)
1903 memcpy(nv->port_name, val, WWN_SIZE);
1905 val = of_get_property(dp, "node-wwn", &len);
1906 if (val && len >= WWN_SIZE)
1907 memcpy(nv->node_name, val, WWN_SIZE);
1912 * NVRAM configuration for ISP 2xxx
1915 * ha = adapter block pointer.
1918 * initialization control block in response_ring
1919 * host adapters parameters in host adapter block
1925 qla2x00_nvram_config(scsi_qla_host_t *vha)
1930 uint8_t *dptr1, *dptr2;
1931 struct qla_hw_data *ha = vha->hw;
1932 init_cb_t *icb = ha->init_cb;
1933 nvram_t *nv = ha->nvram;
1934 uint8_t *ptr = ha->nvram;
1935 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1939 /* Determine NVRAM starting address. */
1940 ha->nvram_size = sizeof(nvram_t);
1942 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1943 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1944 ha->nvram_base = 0x80;
1946 /* Get NVRAM data and calculate checksum. */
1947 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
1948 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1951 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
1952 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
1954 /* Bad NVRAM data, set defaults parameters. */
1955 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1956 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1957 /* Reset NVRAM data. */
1958 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1959 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1961 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1962 "invalid -- WWPN) defaults.\n");
1965 * Set default initialization control block.
1967 memset(nv, 0, ha->nvram_size);
1968 nv->parameter_block_version = ICB_VERSION;
1970 if (IS_QLA23XX(ha)) {
1971 nv->firmware_options[0] = BIT_2 | BIT_1;
1972 nv->firmware_options[1] = BIT_7 | BIT_5;
1973 nv->add_firmware_options[0] = BIT_5;
1974 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1975 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1976 nv->special_options[1] = BIT_7;
1977 } else if (IS_QLA2200(ha)) {
1978 nv->firmware_options[0] = BIT_2 | BIT_1;
1979 nv->firmware_options[1] = BIT_7 | BIT_5;
1980 nv->add_firmware_options[0] = BIT_5;
1981 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1982 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1983 } else if (IS_QLA2100(ha)) {
1984 nv->firmware_options[0] = BIT_3 | BIT_1;
1985 nv->firmware_options[1] = BIT_5;
1986 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1989 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1990 nv->execution_throttle = __constant_cpu_to_le16(16);
1991 nv->retry_count = 8;
1992 nv->retry_delay = 1;
1994 nv->port_name[0] = 33;
1995 nv->port_name[3] = 224;
1996 nv->port_name[4] = 139;
1998 qla2xxx_nvram_wwn_from_ofw(vha, nv);
2000 nv->login_timeout = 4;
2003 * Set default host adapter parameters
2005 nv->host_p[1] = BIT_2;
2006 nv->reset_delay = 5;
2007 nv->port_down_retry_count = 8;
2008 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2009 nv->link_down_timeout = 60;
2014 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2016 * The SN2 does not provide BIOS emulation which means you can't change
2017 * potentially bogus BIOS settings. Force the use of default settings
2018 * for link rate and frame size. Hope that the rest of the settings
2021 if (ia64_platform_is("sn2")) {
2022 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2024 nv->special_options[1] = BIT_7;
2028 /* Reset Initialization control block */
2029 memset(icb, 0, ha->init_cb_size);
2032 * Setup driver NVRAM options.
2034 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2035 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2036 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2037 nv->firmware_options[1] &= ~BIT_4;
2039 if (IS_QLA23XX(ha)) {
2040 nv->firmware_options[0] |= BIT_2;
2041 nv->firmware_options[0] &= ~BIT_3;
2042 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
2044 if (IS_QLA2300(ha)) {
2045 if (ha->fb_rev == FPM_2310) {
2046 strcpy(ha->model_number, "QLA2310");
2048 strcpy(ha->model_number, "QLA2300");
2051 qla2x00_set_model_info(vha, nv->model_number,
2052 sizeof(nv->model_number), "QLA23xx");
2054 } else if (IS_QLA2200(ha)) {
2055 nv->firmware_options[0] |= BIT_2;
2057 * 'Point-to-point preferred, else loop' is not a safe
2058 * connection mode setting.
2060 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2062 /* Force 'loop preferred, else point-to-point'. */
2063 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2064 nv->add_firmware_options[0] |= BIT_5;
2066 strcpy(ha->model_number, "QLA22xx");
2067 } else /*if (IS_QLA2100(ha))*/ {
2068 strcpy(ha->model_number, "QLA2100");
2072 * Copy over NVRAM RISC parameter block to initialization control block.
2074 dptr1 = (uint8_t *)icb;
2075 dptr2 = (uint8_t *)&nv->parameter_block_version;
2076 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2078 *dptr1++ = *dptr2++;
2080 /* Copy 2nd half. */
2081 dptr1 = (uint8_t *)icb->add_firmware_options;
2082 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2084 *dptr1++ = *dptr2++;
2086 /* Use alternate WWN? */
2087 if (nv->host_p[1] & BIT_7) {
2088 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2089 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2092 /* Prepare nodename */
2093 if ((icb->firmware_options[1] & BIT_6) == 0) {
2095 * Firmware will apply the following mask if the nodename was
2098 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2099 icb->node_name[0] &= 0xF0;
2103 * Set host adapter parameters.
2105 if (nv->host_p[0] & BIT_7)
2106 ql2xextended_error_logging = 1;
2107 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2108 /* Always load RISC code on non ISP2[12]00 chips. */
2109 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2110 ha->flags.disable_risc_code_load = 0;
2111 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2112 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2113 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
2114 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
2115 ha->flags.disable_serdes = 0;
2117 ha->operating_mode =
2118 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2120 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2121 sizeof(ha->fw_seriallink_options));
2123 /* save HBA serial number */
2124 ha->serial0 = icb->port_name[5];
2125 ha->serial1 = icb->port_name[6];
2126 ha->serial2 = icb->port_name[7];
2127 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2128 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
2130 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2132 ha->retry_count = nv->retry_count;
2134 /* Set minimum login_timeout to 4 seconds. */
2135 if (nv->login_timeout < ql2xlogintimeout)
2136 nv->login_timeout = ql2xlogintimeout;
2137 if (nv->login_timeout < 4)
2138 nv->login_timeout = 4;
2139 ha->login_timeout = nv->login_timeout;
2140 icb->login_timeout = nv->login_timeout;
2142 /* Set minimum RATOV to 100 tenths of a second. */
2145 ha->loop_reset_delay = nv->reset_delay;
2147 /* Link Down Timeout = 0:
2149 * When Port Down timer expires we will start returning
2150 * I/O's to OS with "DID_NO_CONNECT".
2152 * Link Down Timeout != 0:
2154 * The driver waits for the link to come up after link down
2155 * before returning I/Os to OS with "DID_NO_CONNECT".
2157 if (nv->link_down_timeout == 0) {
2158 ha->loop_down_abort_time =
2159 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
2161 ha->link_down_timeout = nv->link_down_timeout;
2162 ha->loop_down_abort_time =
2163 (LOOP_DOWN_TIME - ha->link_down_timeout);
2167 * Need enough time to try and get the port back.
2169 ha->port_down_retry_count = nv->port_down_retry_count;
2170 if (qlport_down_retry)
2171 ha->port_down_retry_count = qlport_down_retry;
2172 /* Set login_retry_count */
2173 ha->login_retry_count = nv->retry_count;
2174 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2175 ha->port_down_retry_count > 3)
2176 ha->login_retry_count = ha->port_down_retry_count;
2177 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2178 ha->login_retry_count = ha->port_down_retry_count;
2179 if (ql2xloginretrycount)
2180 ha->login_retry_count = ql2xloginretrycount;
2182 icb->lun_enables = __constant_cpu_to_le16(0);
2183 icb->command_resource_count = 0;
2184 icb->immediate_notify_resource_count = 0;
2185 icb->timeout = __constant_cpu_to_le16(0);
2187 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2189 icb->firmware_options[0] &= ~BIT_3;
2190 icb->add_firmware_options[0] &=
2191 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2192 icb->add_firmware_options[0] |= BIT_2;
2193 icb->response_accumulation_timer = 3;
2194 icb->interrupt_delay_timer = 5;
2196 vha->flags.process_response_queue = 1;
2199 if (!vha->flags.init_done) {
2200 ha->zio_mode = icb->add_firmware_options[0] &
2201 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2202 ha->zio_timer = icb->interrupt_delay_timer ?
2203 icb->interrupt_delay_timer: 2;
2205 icb->add_firmware_options[0] &=
2206 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2207 vha->flags.process_response_queue = 0;
2208 if (ha->zio_mode != QLA_ZIO_DISABLED) {
2209 ha->zio_mode = QLA_ZIO_MODE_6;
2211 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
2212 "delay (%d us).\n", vha->host_no, ha->zio_mode,
2213 ha->zio_timer * 100));
2214 qla_printk(KERN_INFO, ha,
2215 "ZIO mode %d enabled; timer delay (%d us).\n",
2216 ha->zio_mode, ha->zio_timer * 100);
2218 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2219 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
2220 vha->flags.process_response_queue = 1;
2225 DEBUG2_3(printk(KERN_WARNING
2226 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
2232 qla2x00_rport_del(void *data)
2234 fc_port_t *fcport = data;
2235 struct fc_rport *rport;
2237 spin_lock_irq(fcport->vha->host->host_lock);
2238 rport = fcport->drport ? fcport->drport: fcport->rport;
2239 fcport->drport = NULL;
2240 spin_unlock_irq(fcport->vha->host->host_lock);
2242 fc_remote_port_delete(rport);
2246 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2248 * @flags: allocation flags
2250 * Returns a pointer to the allocated fcport, or NULL, if none available.
2253 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
2257 fcport = kzalloc(sizeof(fc_port_t), flags);
2261 /* Setup fcport template structure. */
2263 fcport->vp_idx = vha->vp_idx;
2264 fcport->port_type = FCT_UNKNOWN;
2265 fcport->loop_id = FC_NO_LOOP_ID;
2266 atomic_set(&fcport->state, FCS_UNCONFIGURED);
2267 fcport->supported_classes = FC_COS_UNSPECIFIED;
2273 * qla2x00_configure_loop
2274 * Updates Fibre Channel Device Database with what is actually on loop.
2277 * ha = adapter block pointer.
2282 * 2 = database was full and device was not configured.
2285 qla2x00_configure_loop(scsi_qla_host_t *vha)
2288 unsigned long flags, save_flags;
2289 struct qla_hw_data *ha = vha->hw;
2292 /* Get Initiator ID */
2293 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2294 rval = qla2x00_configure_hba(vha);
2295 if (rval != QLA_SUCCESS) {
2296 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
2302 save_flags = flags = vha->dpc_flags;
2303 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
2304 vha->host_no, flags));
2307 * If we have both an RSCN and PORT UPDATE pending then handle them
2308 * both at the same time.
2310 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2311 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
2313 qla2x00_get_data_rate(vha);
2315 /* Determine what we need to do */
2316 if (ha->current_topology == ISP_CFG_FL &&
2317 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2319 vha->flags.rscn_queue_overflow = 1;
2320 set_bit(RSCN_UPDATE, &flags);
2322 } else if (ha->current_topology == ISP_CFG_F &&
2323 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2325 vha->flags.rscn_queue_overflow = 1;
2326 set_bit(RSCN_UPDATE, &flags);
2327 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2329 } else if (ha->current_topology == ISP_CFG_N) {
2330 clear_bit(RSCN_UPDATE, &flags);
2332 } else if (!vha->flags.online ||
2333 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2335 vha->flags.rscn_queue_overflow = 1;
2336 set_bit(RSCN_UPDATE, &flags);
2337 set_bit(LOCAL_LOOP_UPDATE, &flags);
2340 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
2341 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2342 rval = QLA_FUNCTION_FAILED;
2344 rval = qla2x00_configure_local_loop(vha);
2347 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
2348 if (LOOP_TRANSITION(vha))
2349 rval = QLA_FUNCTION_FAILED;
2351 rval = qla2x00_configure_fabric(vha);
2354 if (rval == QLA_SUCCESS) {
2355 if (atomic_read(&vha->loop_down_timer) ||
2356 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2357 rval = QLA_FUNCTION_FAILED;
2359 atomic_set(&vha->loop_state, LOOP_READY);
2361 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
2366 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
2367 __func__, vha->host_no));
2369 DEBUG3(printk("%s: exiting normally\n", __func__));
2372 /* Restore state if a resync event occurred during processing */
2373 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2374 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
2375 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2376 if (test_bit(RSCN_UPDATE, &save_flags)) {
2377 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2378 vha->flags.rscn_queue_overflow = 1;
2388 * qla2x00_configure_local_loop
2389 * Updates Fibre Channel Device Database with local loop devices.
2392 * ha = adapter block pointer.
2398 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
2403 fc_port_t *fcport, *new_fcport;
2409 uint8_t domain, area, al_pa;
2410 struct qla_hw_data *ha = vha->hw;
2414 entries = MAX_FIBRE_DEVICES;
2416 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2417 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
2419 /* Get list of logged in devices. */
2420 memset(ha->gid_list, 0, GID_LIST_SIZE);
2421 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
2423 if (rval != QLA_SUCCESS)
2424 goto cleanup_allocation;
2426 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2427 vha->host_no, entries));
2428 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2429 entries * sizeof(struct gid_list_info)));
2431 /* Allocate temporary fcport for any new fcports discovered. */
2432 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2433 if (new_fcport == NULL) {
2434 rval = QLA_MEMORY_ALLOC_FAILED;
2435 goto cleanup_allocation;
2437 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2440 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2442 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2443 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2444 fcport->port_type != FCT_BROADCAST &&
2445 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2447 DEBUG(printk("scsi(%ld): Marking port lost, "
2449 vha->host_no, fcport->loop_id));
2451 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2455 /* Add devices to port list. */
2456 id_iter = (char *)ha->gid_list;
2457 for (index = 0; index < entries; index++) {
2458 domain = ((struct gid_list_info *)id_iter)->domain;
2459 area = ((struct gid_list_info *)id_iter)->area;
2460 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
2461 if (IS_QLA2100(ha) || IS_QLA2200(ha))
2462 loop_id = (uint16_t)
2463 ((struct gid_list_info *)id_iter)->loop_id_2100;
2465 loop_id = le16_to_cpu(
2466 ((struct gid_list_info *)id_iter)->loop_id);
2467 id_iter += ha->gid_list_info_size;
2469 /* Bypass reserved domain fields. */
2470 if ((domain & 0xf0) == 0xf0)
2473 /* Bypass if not same domain and area of adapter. */
2474 if (area && domain &&
2475 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
2478 /* Bypass invalid local loop ID. */
2479 if (loop_id > LAST_LOCAL_LOOP_ID)
2482 /* Fill in member data. */
2483 new_fcport->d_id.b.domain = domain;
2484 new_fcport->d_id.b.area = area;
2485 new_fcport->d_id.b.al_pa = al_pa;
2486 new_fcport->loop_id = loop_id;
2487 new_fcport->vp_idx = vha->vp_idx;
2488 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
2489 if (rval2 != QLA_SUCCESS) {
2490 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2491 "information -- get_port_database=%x, "
2493 vha->host_no, rval2, new_fcport->loop_id));
2494 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2496 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2500 /* Check for matching device in port list. */
2503 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2504 if (memcmp(new_fcport->port_name, fcport->port_name,
2508 fcport->flags &= ~FCF_FABRIC_DEVICE;
2509 fcport->loop_id = new_fcport->loop_id;
2510 fcport->port_type = new_fcport->port_type;
2511 fcport->d_id.b24 = new_fcport->d_id.b24;
2512 memcpy(fcport->node_name, new_fcport->node_name,
2520 /* New device, add to fcports list. */
2522 new_fcport->vha = vha;
2523 new_fcport->vp_idx = vha->vp_idx;
2525 list_add_tail(&new_fcport->list, &vha->vp_fcports);
2527 /* Allocate a new replacement fcport. */
2528 fcport = new_fcport;
2529 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2530 if (new_fcport == NULL) {
2531 rval = QLA_MEMORY_ALLOC_FAILED;
2532 goto cleanup_allocation;
2534 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2537 /* Base iIDMA settings on HBA port speed. */
2538 fcport->fp_speed = ha->link_data_rate;
2540 qla2x00_update_fcport(vha, fcport);
2548 if (rval != QLA_SUCCESS) {
2549 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2550 "rval=%x\n", vha->host_no, rval));
2557 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
2559 #define LS_UNKNOWN 2
2560 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2564 struct qla_hw_data *ha = vha->hw;
2566 if (!IS_IIDMA_CAPABLE(ha))
2569 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2570 fcport->fp_speed > ha->link_data_rate)
2573 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
2575 if (rval != QLA_SUCCESS) {
2576 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2577 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2578 vha->host_no, fcport->port_name[0], fcport->port_name[1],
2579 fcport->port_name[2], fcport->port_name[3],
2580 fcport->port_name[4], fcport->port_name[5],
2581 fcport->port_name[6], fcport->port_name[7], rval,
2582 fcport->fp_speed, mb[0], mb[1]));
2584 link_speed = link_speeds[LS_UNKNOWN];
2585 if (fcport->fp_speed < 5)
2586 link_speed = link_speeds[fcport->fp_speed];
2587 else if (fcport->fp_speed == 0x13)
2588 link_speed = link_speeds[5];
2589 DEBUG2(qla_printk(KERN_INFO, ha,
2590 "iIDMA adjusted to %s GB/s on "
2591 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2592 link_speed, fcport->port_name[0],
2593 fcport->port_name[1], fcport->port_name[2],
2594 fcport->port_name[3], fcport->port_name[4],
2595 fcport->port_name[5], fcport->port_name[6],
2596 fcport->port_name[7]));
2601 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
2603 struct fc_rport_identifiers rport_ids;
2604 struct fc_rport *rport;
2605 struct qla_hw_data *ha = vha->hw;
2607 qla2x00_rport_del(fcport);
2609 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2610 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2611 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2612 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2613 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2614 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
2616 qla_printk(KERN_WARNING, ha,
2617 "Unable to allocate fc remote port!\n");
2620 spin_lock_irq(fcport->vha->host->host_lock);
2621 *((fc_port_t **)rport->dd_data) = fcport;
2622 spin_unlock_irq(fcport->vha->host->host_lock);
2624 rport->supported_classes = fcport->supported_classes;
2626 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2627 if (fcport->port_type == FCT_INITIATOR)
2628 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2629 if (fcport->port_type == FCT_TARGET)
2630 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2631 fc_remote_port_rolechg(rport, rport_ids.roles);
2635 * qla2x00_update_fcport
2636 * Updates device on list.
2639 * ha = adapter block pointer.
2640 * fcport = port structure pointer.
2650 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
2652 struct qla_hw_data *ha = vha->hw;
2655 fcport->login_retry = 0;
2656 fcport->port_login_retry_count = ha->port_down_retry_count *
2658 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2660 fcport->flags &= ~FCF_LOGIN_NEEDED;
2662 qla2x00_iidma_fcport(vha, fcport);
2664 atomic_set(&fcport->state, FCS_ONLINE);
2666 qla2x00_reg_remote_port(vha, fcport);
2670 * qla2x00_configure_fabric
2671 * Setup SNS devices with loop ID's.
2674 * ha = adapter block pointer.
2681 qla2x00_configure_fabric(scsi_qla_host_t *vha)
2684 fc_port_t *fcport, *fcptemp;
2685 uint16_t next_loopid;
2686 uint16_t mb[MAILBOX_REGISTER_COUNT];
2688 LIST_HEAD(new_fcports);
2689 struct qla_hw_data *ha = vha->hw;
2690 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2692 /* If FL port exists, then SNS is present */
2693 if (IS_FWI2_CAPABLE(ha))
2694 loop_id = NPH_F_PORT;
2696 loop_id = SNS_FL_PORT;
2697 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
2698 if (rval != QLA_SUCCESS) {
2699 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2700 "Port\n", vha->host_no));
2702 vha->device_flags &= ~SWITCH_FOUND;
2703 return (QLA_SUCCESS);
2705 vha->device_flags |= SWITCH_FOUND;
2707 /* Mark devices that need re-synchronization. */
2708 rval2 = qla2x00_device_resync(vha);
2709 if (rval2 == QLA_RSCNS_HANDLED) {
2710 /* No point doing the scan, just continue. */
2711 return (QLA_SUCCESS);
2715 if (ql2xfdmienable &&
2716 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2717 qla2x00_fdmi_register(vha);
2719 /* Ensure we are logged into the SNS. */
2720 if (IS_FWI2_CAPABLE(ha))
2723 loop_id = SIMPLE_NAME_SERVER;
2724 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
2725 0xfc, mb, BIT_1 | BIT_0);
2726 if (mb[0] != MBS_COMMAND_COMPLETE) {
2727 DEBUG2(qla_printk(KERN_INFO, ha,
2728 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2729 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2730 mb[0], mb[1], mb[2], mb[6], mb[7]));
2731 return (QLA_SUCCESS);
2734 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2735 if (qla2x00_rft_id(vha)) {
2737 DEBUG2(printk("scsi(%ld): Register FC-4 "
2738 "TYPE failed.\n", vha->host_no));
2740 if (qla2x00_rff_id(vha)) {
2742 DEBUG2(printk("scsi(%ld): Register FC-4 "
2743 "Features failed.\n", vha->host_no));
2745 if (qla2x00_rnn_id(vha)) {
2747 DEBUG2(printk("scsi(%ld): Register Node Name "
2748 "failed.\n", vha->host_no));
2749 } else if (qla2x00_rsnn_nn(vha)) {
2751 DEBUG2(printk("scsi(%ld): Register Symbolic "
2752 "Node Name failed.\n", vha->host_no));
2756 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
2757 if (rval != QLA_SUCCESS)
2761 * Logout all previous fabric devices marked lost, except
2764 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2765 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2768 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2771 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2772 qla2x00_mark_device_lost(vha, fcport,
2773 ql2xplogiabsentdevice, 0);
2774 if (fcport->loop_id != FC_NO_LOOP_ID &&
2775 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
2776 fcport->port_type != FCT_INITIATOR &&
2777 fcport->port_type != FCT_BROADCAST) {
2778 ha->isp_ops->fabric_logout(vha,
2780 fcport->d_id.b.domain,
2781 fcport->d_id.b.area,
2782 fcport->d_id.b.al_pa);
2783 fcport->loop_id = FC_NO_LOOP_ID;
2788 /* Starting free loop ID. */
2789 next_loopid = ha->min_external_loopid;
2792 * Scan through our port list and login entries that need to be
2795 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2796 if (atomic_read(&vha->loop_down_timer) ||
2797 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2800 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2801 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2804 if (fcport->loop_id == FC_NO_LOOP_ID) {
2805 fcport->loop_id = next_loopid;
2806 rval = qla2x00_find_new_loop_id(
2808 if (rval != QLA_SUCCESS) {
2809 /* Ran out of IDs to use */
2813 /* Login and update database */
2814 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
2817 /* Exit if out of loop IDs. */
2818 if (rval != QLA_SUCCESS) {
2823 * Login and add the new devices to our port list.
2825 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2826 if (atomic_read(&vha->loop_down_timer) ||
2827 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2830 /* Find a new loop ID to use. */
2831 fcport->loop_id = next_loopid;
2832 rval = qla2x00_find_new_loop_id(base_vha, fcport);
2833 if (rval != QLA_SUCCESS) {
2834 /* Ran out of IDs to use */
2838 /* Login and update database */
2839 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
2843 fcport->vp_idx = vha->vp_idx;
2845 list_move_tail(&fcport->list, &vha->vp_fcports);
2849 /* Free all new device structures not processed. */
2850 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2851 list_del(&fcport->list);
2856 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2857 "rval=%d\n", vha->host_no, rval));
2865 * qla2x00_find_all_fabric_devs
2868 * ha = adapter block pointer.
2869 * dev = database device entry pointer.
2878 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2879 struct list_head *new_fcports)
2883 fc_port_t *fcport, *new_fcport, *fcptemp;
2888 int first_dev, last_dev;
2889 port_id_t wrap, nxt_d_id;
2890 struct qla_hw_data *ha = vha->hw;
2891 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
2892 struct scsi_qla_host *tvp;
2896 /* Try GID_PT to get device list, else GAN. */
2897 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
2900 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2901 "on GA_NXT\n", vha->host_no));
2903 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
2906 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
2909 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
2912 } else if (ql2xiidmaenable &&
2913 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2914 qla2x00_gpsc(vha, swl);
2919 /* Allocate temporary fcport for any new fcports discovered. */
2920 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2921 if (new_fcport == NULL) {
2923 return (QLA_MEMORY_ALLOC_FAILED);
2925 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2926 /* Set start port ID scan at adapter ID. */
2930 /* Starting free loop ID. */
2931 loop_id = ha->min_external_loopid;
2932 for (; loop_id <= ha->max_loop_id; loop_id++) {
2933 if (qla2x00_is_reserved_id(vha, loop_id))
2936 if (atomic_read(&vha->loop_down_timer) ||
2937 LOOP_TRANSITION(vha)) {
2938 atomic_set(&vha->loop_down_timer, 0);
2939 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2940 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2946 wrap.b24 = new_fcport->d_id.b24;
2948 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2949 memcpy(new_fcport->node_name,
2950 swl[swl_idx].node_name, WWN_SIZE);
2951 memcpy(new_fcport->port_name,
2952 swl[swl_idx].port_name, WWN_SIZE);
2953 memcpy(new_fcport->fabric_port_name,
2954 swl[swl_idx].fabric_port_name, WWN_SIZE);
2955 new_fcport->fp_speed = swl[swl_idx].fp_speed;
2957 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2963 /* Send GA_NXT to the switch */
2964 rval = qla2x00_ga_nxt(vha, new_fcport);
2965 if (rval != QLA_SUCCESS) {
2966 qla_printk(KERN_WARNING, ha,
2967 "SNS scan failed -- assuming zero-entry "
2969 list_for_each_entry_safe(fcport, fcptemp,
2970 new_fcports, list) {
2971 list_del(&fcport->list);
2979 /* If wrap on switch device list, exit. */
2981 wrap.b24 = new_fcport->d_id.b24;
2983 } else if (new_fcport->d_id.b24 == wrap.b24) {
2984 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2985 vha->host_no, new_fcport->d_id.b.domain,
2986 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2990 /* Bypass if same physical adapter. */
2991 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
2994 /* Bypass virtual ports of the same host. */
2996 if (ha->num_vhosts) {
2997 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
2998 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3007 /* Bypass if same domain and area of adapter. */
3008 if (((new_fcport->d_id.b24 & 0xffff00) ==
3009 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
3013 /* Bypass reserved domain fields. */
3014 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3017 /* Locate matching device in database. */
3019 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3020 if (memcmp(new_fcport->port_name, fcport->port_name,
3026 /* Update port state. */
3027 memcpy(fcport->fabric_port_name,
3028 new_fcport->fabric_port_name, WWN_SIZE);
3029 fcport->fp_speed = new_fcport->fp_speed;
3032 * If address the same and state FCS_ONLINE, nothing
3035 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3036 atomic_read(&fcport->state) == FCS_ONLINE) {
3041 * If device was not a fabric device before.
3043 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3044 fcport->d_id.b24 = new_fcport->d_id.b24;
3045 fcport->loop_id = FC_NO_LOOP_ID;
3046 fcport->flags |= (FCF_FABRIC_DEVICE |
3052 * Port ID changed or device was marked to be updated;
3053 * Log it out if still logged in and mark it for
3056 fcport->d_id.b24 = new_fcport->d_id.b24;
3057 fcport->flags |= FCF_LOGIN_NEEDED;
3058 if (fcport->loop_id != FC_NO_LOOP_ID &&
3059 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
3060 fcport->port_type != FCT_INITIATOR &&
3061 fcport->port_type != FCT_BROADCAST) {
3062 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3063 fcport->d_id.b.domain, fcport->d_id.b.area,
3064 fcport->d_id.b.al_pa);
3065 fcport->loop_id = FC_NO_LOOP_ID;
3073 /* If device was not in our fcports list, then add it. */
3074 list_add_tail(&new_fcport->list, new_fcports);
3076 /* Allocate a new replacement fcport. */
3077 nxt_d_id.b24 = new_fcport->d_id.b24;
3078 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
3079 if (new_fcport == NULL) {
3081 return (QLA_MEMORY_ALLOC_FAILED);
3083 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3084 new_fcport->d_id.b24 = nxt_d_id.b24;
3094 * qla2x00_find_new_loop_id
3095 * Scan through our port list and find a new usable loop ID.
3098 * ha: adapter state pointer.
3099 * dev: port structure pointer.
3102 * qla2x00 local function return status code.
3108 qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
3113 uint16_t first_loop_id;
3114 struct qla_hw_data *ha = vha->hw;
3115 struct scsi_qla_host *vp;
3116 struct scsi_qla_host *tvp;
3120 /* Save starting loop ID. */
3121 first_loop_id = dev->loop_id;
3124 /* Skip loop ID if already used by adapter. */
3125 if (dev->loop_id == vha->loop_id)
3128 /* Skip reserved loop IDs. */
3129 while (qla2x00_is_reserved_id(vha, dev->loop_id))
3132 /* Reset loop ID if passed the end. */
3133 if (dev->loop_id > ha->max_loop_id) {
3134 /* first loop ID. */
3135 dev->loop_id = ha->min_external_loopid;
3138 /* Check for loop ID being already in use. */
3141 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
3142 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3143 if (fcport->loop_id == dev->loop_id &&
3145 /* ID possibly in use */
3154 /* If not in use then it is free to use. */
3159 /* ID in use. Try next value. */
3162 /* If wrap around. No free ID to use. */
3163 if (dev->loop_id == first_loop_id) {
3164 dev->loop_id = FC_NO_LOOP_ID;
3165 rval = QLA_FUNCTION_FAILED;
3174 * qla2x00_device_resync
3175 * Marks devices in the database that needs resynchronization.
3178 * ha = adapter block pointer.
3184 qla2x00_device_resync(scsi_qla_host_t *vha)
3189 uint32_t rscn_entry;
3190 uint8_t rscn_out_iter;
3194 rval = QLA_RSCNS_HANDLED;
3196 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3197 vha->flags.rscn_queue_overflow) {
3199 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
3200 format = MSB(MSW(rscn_entry));
3201 d_id.b.domain = LSB(MSW(rscn_entry));
3202 d_id.b.area = MSB(LSW(rscn_entry));
3203 d_id.b.al_pa = LSB(LSW(rscn_entry));
3205 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3206 "[%02x/%02x%02x%02x].\n",
3207 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
3208 d_id.b.area, d_id.b.al_pa));
3210 vha->rscn_out_ptr++;
3211 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3212 vha->rscn_out_ptr = 0;
3214 /* Skip duplicate entries. */
3215 for (rscn_out_iter = vha->rscn_out_ptr;
3216 !vha->flags.rscn_queue_overflow &&
3217 rscn_out_iter != vha->rscn_in_ptr;
3218 rscn_out_iter = (rscn_out_iter ==
3219 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3221 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
3224 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
3225 "entry found at [%d].\n", vha->host_no,
3228 vha->rscn_out_ptr = rscn_out_iter;
3231 /* Queue overflow, set switch default case. */
3232 if (vha->flags.rscn_queue_overflow) {
3233 DEBUG(printk("scsi(%ld): device_resync: rscn "
3234 "overflow.\n", vha->host_no));
3237 vha->flags.rscn_queue_overflow = 0;
3253 vha->rscn_out_ptr = vha->rscn_in_ptr;
3259 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3260 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3261 (fcport->d_id.b24 & mask) != d_id.b24 ||
3262 fcport->port_type == FCT_BROADCAST)
3265 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3267 fcport->port_type != FCT_INITIATOR) {
3268 qla2x00_mark_device_lost(vha, fcport,
3278 * qla2x00_fabric_dev_login
3279 * Login fabric target device and update FC port database.
3282 * ha: adapter state pointer.
3283 * fcport: port structure list pointer.
3284 * next_loopid: contains value of a new loop ID that can be used
3285 * by the next login attempt.
3288 * qla2x00 local function return status code.
3294 qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
3295 uint16_t *next_loopid)
3300 struct qla_hw_data *ha = vha->hw;
3305 if (IS_ALOGIO_CAPABLE(ha)) {
3306 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3311 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
3312 if (rval == QLA_SUCCESS) {
3313 /* Send an ADISC to FCP2 devices.*/
3315 if (fcport->flags & FCF_FCP2_DEVICE)
3317 rval = qla2x00_get_port_database(vha, fcport, opts);
3318 if (rval != QLA_SUCCESS) {
3319 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3320 fcport->d_id.b.domain, fcport->d_id.b.area,
3321 fcport->d_id.b.al_pa);
3322 qla2x00_mark_device_lost(vha, fcport, 1, 0);
3324 qla2x00_update_fcport(vha, fcport);
3332 * qla2x00_fabric_login
3333 * Issue fabric login command.
3336 * ha = adapter block pointer.
3337 * device = pointer to FC device type structure.
3340 * 0 - Login successfully
3342 * 2 - Initiator device
3346 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
3347 uint16_t *next_loopid)
3351 uint16_t tmp_loopid;
3352 uint16_t mb[MAILBOX_REGISTER_COUNT];
3353 struct qla_hw_data *ha = vha->hw;
3359 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3360 "for port %02x%02x%02x.\n",
3361 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
3362 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3364 /* Login fcport on switch. */
3365 ha->isp_ops->fabric_login(vha, fcport->loop_id,
3366 fcport->d_id.b.domain, fcport->d_id.b.area,
3367 fcport->d_id.b.al_pa, mb, BIT_0);
3368 if (mb[0] == MBS_PORT_ID_USED) {
3370 * Device has another loop ID. The firmware team
3371 * recommends the driver perform an implicit login with
3372 * the specified ID again. The ID we just used is save
3373 * here so we return with an ID that can be tried by
3377 tmp_loopid = fcport->loop_id;
3378 fcport->loop_id = mb[1];
3380 DEBUG(printk("Fabric Login: port in use - next "
3381 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3382 fcport->loop_id, fcport->d_id.b.domain,
3383 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3385 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3390 /* A retry occurred before. */
3391 *next_loopid = tmp_loopid;
3394 * No retry occurred before. Just increment the
3395 * ID value for next login.
3397 *next_loopid = (fcport->loop_id + 1);
3400 if (mb[1] & BIT_0) {
3401 fcport->port_type = FCT_INITIATOR;
3403 fcport->port_type = FCT_TARGET;
3404 if (mb[1] & BIT_1) {
3405 fcport->flags |= FCF_FCP2_DEVICE;
3410 fcport->supported_classes |= FC_COS_CLASS2;
3412 fcport->supported_classes |= FC_COS_CLASS3;
3416 } else if (mb[0] == MBS_LOOP_ID_USED) {
3418 * Loop ID already used, try next loop ID.
3421 rval = qla2x00_find_new_loop_id(vha, fcport);
3422 if (rval != QLA_SUCCESS) {
3423 /* Ran out of loop IDs to use */
3426 } else if (mb[0] == MBS_COMMAND_ERROR) {
3428 * Firmware possibly timed out during login. If NO
3429 * retries are left to do then the device is declared
3432 *next_loopid = fcport->loop_id;
3433 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3434 fcport->d_id.b.domain, fcport->d_id.b.area,
3435 fcport->d_id.b.al_pa);
3436 qla2x00_mark_device_lost(vha, fcport, 1, 0);
3442 * unrecoverable / not handled error
3444 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3445 "loop_id=%x jiffies=%lx.\n",
3446 __func__, vha->host_no, mb[0],
3447 fcport->d_id.b.domain, fcport->d_id.b.area,
3448 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3450 *next_loopid = fcport->loop_id;
3451 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3452 fcport->d_id.b.domain, fcport->d_id.b.area,
3453 fcport->d_id.b.al_pa);
3454 fcport->loop_id = FC_NO_LOOP_ID;
3455 fcport->login_retry = 0;
3466 * qla2x00_local_device_login
3467 * Issue local device login command.
3470 * ha = adapter block pointer.
3471 * loop_id = loop id of device to login to.
3473 * Returns (Where's the #define!!!!):
3474 * 0 - Login successfully
3479 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
3482 uint16_t mb[MAILBOX_REGISTER_COUNT];
3484 memset(mb, 0, sizeof(mb));
3485 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
3486 if (rval == QLA_SUCCESS) {
3487 /* Interrogate mailbox registers for any errors */
3488 if (mb[0] == MBS_COMMAND_ERROR)
3490 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3491 /* device not in PCB table */
3499 * qla2x00_loop_resync
3500 * Resync with fibre channel devices.
3503 * ha = adapter block pointer.
3509 qla2x00_loop_resync(scsi_qla_host_t *vha)
3511 int rval = QLA_SUCCESS;
3513 struct req_que *req;
3514 struct rsp_que *rsp;
3516 if (vha->hw->flags.cpu_affinity_enabled)
3517 req = vha->hw->req_q_map[0];
3522 atomic_set(&vha->loop_state, LOOP_UPDATE);
3523 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3524 if (vha->flags.online) {
3525 if (!(rval = qla2x00_fw_ready(vha))) {
3526 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3529 atomic_set(&vha->loop_state, LOOP_UPDATE);
3531 /* Issue a marker after FW becomes ready. */
3532 qla2x00_marker(vha, req, rsp, 0, 0,
3534 vha->marker_needed = 0;
3536 /* Remap devices on Loop. */
3537 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3539 qla2x00_configure_loop(vha);
3541 } while (!atomic_read(&vha->loop_down_timer) &&
3542 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3543 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3548 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3549 return (QLA_FUNCTION_FAILED);
3552 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3558 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
3561 struct scsi_qla_host *tvp, *vha;
3563 /* Go with deferred removal of rport references. */
3564 list_for_each_entry_safe(vha, tvp, &base_vha->hw->vp_list, list)
3565 list_for_each_entry(fcport, &vha->vp_fcports, list)
3566 if (fcport && fcport->drport &&
3567 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
3568 qla2x00_rport_del(fcport);
3572 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3574 struct qla_hw_data *ha = vha->hw;
3575 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
3576 struct scsi_qla_host *tvp;
3578 vha->flags.online = 0;
3579 ha->flags.chip_reset_done = 0;
3580 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3581 ha->qla_stats.total_isp_aborts++;
3583 qla_printk(KERN_INFO, ha,
3584 "Performing ISP error recovery - ha= %p.\n", ha);
3586 /* Chip reset does not apply to 82XX */
3587 if (!IS_QLA82XX(ha))
3588 ha->isp_ops->reset_chip(vha);
3590 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3591 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3592 atomic_set(&vha->loop_state, LOOP_DOWN);
3593 qla2x00_mark_all_devices_lost(vha, 0);
3594 list_for_each_entry_safe(vp, tvp, &base_vha->hw->vp_list, list)
3595 qla2x00_mark_all_devices_lost(vp, 0);
3597 if (!atomic_read(&vha->loop_down_timer))
3598 atomic_set(&vha->loop_down_timer,
3602 /* Make sure for ISP 82XX IO DMA is complete */
3604 qla82xx_wait_for_pending_commands(vha);
3606 /* Requeue all commands in outstanding command list. */
3607 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
3612 * Resets ISP and aborts all outstanding commands.
3615 * ha = adapter block pointer.
3621 qla2x00_abort_isp(scsi_qla_host_t *vha)
3625 struct qla_hw_data *ha = vha->hw;
3626 struct scsi_qla_host *vp;
3627 struct scsi_qla_host *tvp;
3628 struct req_que *req = ha->req_q_map[0];
3630 if (vha->flags.online) {
3631 qla2x00_abort_isp_cleanup(vha);
3633 if (unlikely(pci_channel_offline(ha->pdev) &&
3634 ha->flags.pci_channel_io_perm_failure)) {
3635 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3640 ha->isp_ops->get_flash_version(vha, req->ring);
3642 ha->isp_ops->nvram_config(vha);
3644 if (!qla2x00_restart_isp(vha)) {
3645 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
3647 if (!atomic_read(&vha->loop_down_timer)) {
3649 * Issue marker command only when we are going
3650 * to start the I/O .
3652 vha->marker_needed = 1;
3655 vha->flags.online = 1;
3657 ha->isp_ops->enable_intrs(ha);
3659 ha->isp_abort_cnt = 0;
3660 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3663 qla2x00_get_fw_version(vha,
3664 &ha->fw_major_version,
3665 &ha->fw_minor_version,
3666 &ha->fw_subminor_version,
3667 &ha->fw_attributes, &ha->fw_memory_size,
3668 ha->mpi_version, &ha->mpi_capabilities,
3672 ha->flags.fce_enabled = 1;
3674 fce_calc_size(ha->fce_bufs));
3675 rval = qla2x00_enable_fce_trace(vha,
3676 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3679 qla_printk(KERN_WARNING, ha,
3680 "Unable to reinitialize FCE "
3682 ha->flags.fce_enabled = 0;
3687 memset(ha->eft, 0, EFT_SIZE);
3688 rval = qla2x00_enable_eft_trace(vha,
3689 ha->eft_dma, EFT_NUM_BUFFERS);
3691 qla_printk(KERN_WARNING, ha,
3692 "Unable to reinitialize EFT "
3696 } else { /* failed the ISP abort */
3697 vha->flags.online = 1;
3698 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
3699 if (ha->isp_abort_cnt == 0) {
3700 qla_printk(KERN_WARNING, ha,
3701 "ISP error recovery failed - "
3702 "board disabled\n");
3704 * The next call disables the board
3707 ha->isp_ops->reset_adapter(vha);
3708 vha->flags.online = 0;
3709 clear_bit(ISP_ABORT_RETRY,
3712 } else { /* schedule another ISP abort */
3713 ha->isp_abort_cnt--;
3714 DEBUG(printk("qla%ld: ISP abort - "
3715 "retry remaining %d\n",
3716 vha->host_no, ha->isp_abort_cnt));
3720 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3721 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3722 "- retrying (%d) more times\n",
3723 vha->host_no, ha->isp_abort_cnt));
3724 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3732 DEBUG(printk(KERN_INFO
3733 "qla2x00_abort_isp(%ld): succeeded.\n",
3735 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
3737 qla2x00_vp_abort_isp(vp);
3740 qla_printk(KERN_INFO, ha,
3741 "qla2x00_abort_isp: **** FAILED ****\n");
3748 * qla2x00_restart_isp
3749 * restarts the ISP after a reset
3752 * ha = adapter block pointer.
3758 qla2x00_restart_isp(scsi_qla_host_t *vha)
3762 struct qla_hw_data *ha = vha->hw;
3763 struct req_que *req = ha->req_q_map[0];
3764 struct rsp_que *rsp = ha->rsp_q_map[0];
3766 /* If firmware needs to be loaded */
3767 if (qla2x00_isp_firmware(vha)) {
3768 vha->flags.online = 0;
3769 status = ha->isp_ops->chip_diag(vha);
3771 status = qla2x00_setup_chip(vha);
3774 if (!status && !(status = qla2x00_init_rings(vha))) {
3775 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
3776 ha->flags.chip_reset_done = 1;
3777 /* Initialize the queues in use */
3778 qla25xx_init_queues(ha);
3780 status = qla2x00_fw_ready(vha);
3782 DEBUG(printk("%s(): Start configure loop, "
3783 "status = %d\n", __func__, status));
3785 /* Issue a marker after FW becomes ready. */
3786 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
3788 vha->flags.online = 1;
3789 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3792 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3793 qla2x00_configure_loop(vha);
3795 } while (!atomic_read(&vha->loop_down_timer) &&
3796 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3797 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3801 /* if no cable then assume it's good */
3802 if ((vha->device_flags & DFLG_NO_CABLE))
3805 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3813 qla25xx_init_queues(struct qla_hw_data *ha)
3815 struct rsp_que *rsp = NULL;
3816 struct req_que *req = NULL;
3817 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3821 for (i = 1; i < ha->max_rsp_queues; i++) {
3822 rsp = ha->rsp_q_map[i];
3824 rsp->options &= ~BIT_0;
3825 ret = qla25xx_init_rsp_que(base_vha, rsp);
3826 if (ret != QLA_SUCCESS)
3827 DEBUG2_17(printk(KERN_WARNING
3828 "%s Rsp que:%d init failed\n", __func__,
3831 DEBUG2_17(printk(KERN_INFO
3832 "%s Rsp que:%d inited\n", __func__,
3836 for (i = 1; i < ha->max_req_queues; i++) {
3837 req = ha->req_q_map[i];
3839 /* Clear outstanding commands array. */
3840 req->options &= ~BIT_0;
3841 ret = qla25xx_init_req_que(base_vha, req);
3842 if (ret != QLA_SUCCESS)
3843 DEBUG2_17(printk(KERN_WARNING
3844 "%s Req que:%d init failed\n", __func__,
3847 DEBUG2_17(printk(KERN_WARNING
3848 "%s Req que:%d inited\n", __func__,
3856 * qla2x00_reset_adapter
3860 * ha = adapter block pointer.
3863 qla2x00_reset_adapter(scsi_qla_host_t *vha)
3865 unsigned long flags = 0;
3866 struct qla_hw_data *ha = vha->hw;
3867 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3869 vha->flags.online = 0;
3870 ha->isp_ops->disable_intrs(ha);
3872 spin_lock_irqsave(&ha->hardware_lock, flags);
3873 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3874 RD_REG_WORD(®->hccr); /* PCI Posting. */
3875 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3876 RD_REG_WORD(®->hccr); /* PCI Posting. */
3877 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3881 qla24xx_reset_adapter(scsi_qla_host_t *vha)
3883 unsigned long flags = 0;
3884 struct qla_hw_data *ha = vha->hw;
3885 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3890 vha->flags.online = 0;
3891 ha->isp_ops->disable_intrs(ha);
3893 spin_lock_irqsave(&ha->hardware_lock, flags);
3894 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3895 RD_REG_DWORD(®->hccr);
3896 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3897 RD_REG_DWORD(®->hccr);
3898 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3900 if (IS_NOPOLLING_TYPE(ha))
3901 ha->isp_ops->enable_intrs(ha);
3904 /* On sparc systems, obtain port and node WWN from firmware
3907 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3908 struct nvram_24xx *nv)
3911 struct qla_hw_data *ha = vha->hw;
3912 struct pci_dev *pdev = ha->pdev;
3913 struct device_node *dp = pci_device_to_OF_node(pdev);
3917 val = of_get_property(dp, "port-wwn", &len);
3918 if (val && len >= WWN_SIZE)
3919 memcpy(nv->port_name, val, WWN_SIZE);
3921 val = of_get_property(dp, "node-wwn", &len);
3922 if (val && len >= WWN_SIZE)
3923 memcpy(nv->node_name, val, WWN_SIZE);
3928 qla24xx_nvram_config(scsi_qla_host_t *vha)
3931 struct init_cb_24xx *icb;
3932 struct nvram_24xx *nv;
3934 uint8_t *dptr1, *dptr2;
3937 struct qla_hw_data *ha = vha->hw;
3940 icb = (struct init_cb_24xx *)ha->init_cb;
3943 /* Determine NVRAM starting address. */
3944 if (ha->flags.port0) {
3945 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3946 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3948 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3949 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3951 ha->nvram_size = sizeof(struct nvram_24xx);
3952 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3954 ha->vpd_size = FA_VPD_SIZE_82XX;
3956 /* Get VPD data into cache */
3957 ha->vpd = ha->nvram + VPD_OFFSET;
3958 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
3959 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3961 /* Get NVRAM data into cache and calculate checksum. */
3962 dptr = (uint32_t *)nv;
3963 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
3965 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3966 chksum += le32_to_cpu(*dptr++);
3968 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
3969 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
3971 /* Bad NVRAM data, set defaults parameters. */
3972 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3973 || nv->id[3] != ' ' ||
3974 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3975 /* Reset NVRAM data. */
3976 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3977 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3978 le16_to_cpu(nv->nvram_version));
3979 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3980 "invalid -- WWPN) defaults.\n");
3983 * Set default initialization control block.
3985 memset(nv, 0, ha->nvram_size);
3986 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3987 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3988 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3989 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3990 nv->exchange_count = __constant_cpu_to_le16(0);
3991 nv->hard_address = __constant_cpu_to_le16(124);
3992 nv->port_name[0] = 0x21;
3993 nv->port_name[1] = 0x00 + ha->port_no;
3994 nv->port_name[2] = 0x00;
3995 nv->port_name[3] = 0xe0;
3996 nv->port_name[4] = 0x8b;
3997 nv->port_name[5] = 0x1c;
3998 nv->port_name[6] = 0x55;
3999 nv->port_name[7] = 0x86;
4000 nv->node_name[0] = 0x20;
4001 nv->node_name[1] = 0x00;
4002 nv->node_name[2] = 0x00;
4003 nv->node_name[3] = 0xe0;
4004 nv->node_name[4] = 0x8b;
4005 nv->node_name[5] = 0x1c;
4006 nv->node_name[6] = 0x55;
4007 nv->node_name[7] = 0x86;
4008 qla24xx_nvram_wwn_from_ofw(vha, nv);
4009 nv->login_retry_count = __constant_cpu_to_le16(8);
4010 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4011 nv->login_timeout = __constant_cpu_to_le16(0);
4012 nv->firmware_options_1 =
4013 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4014 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4015 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4016 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4017 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4018 nv->efi_parameters = __constant_cpu_to_le32(0);
4019 nv->reset_delay = 5;
4020 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4021 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4022 nv->link_down_timeout = __constant_cpu_to_le16(30);
4027 /* Reset Initialization control block */
4028 memset(icb, 0, ha->init_cb_size);
4030 /* Copy 1st segment. */
4031 dptr1 = (uint8_t *)icb;
4032 dptr2 = (uint8_t *)&nv->version;
4033 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4035 *dptr1++ = *dptr2++;
4037 icb->login_retry_count = nv->login_retry_count;
4038 icb->link_down_on_nos = nv->link_down_on_nos;
4040 /* Copy 2nd segment. */
4041 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4042 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4043 cnt = (uint8_t *)&icb->reserved_3 -
4044 (uint8_t *)&icb->interrupt_delay_timer;
4046 *dptr1++ = *dptr2++;
4049 * Setup driver NVRAM options.
4051 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4054 /* Use alternate WWN? */
4055 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4056 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4057 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4060 /* Prepare nodename */
4061 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4063 * Firmware will apply the following mask if the nodename was
4066 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4067 icb->node_name[0] &= 0xF0;
4070 /* Set host adapter parameters. */
4071 ha->flags.disable_risc_code_load = 0;
4072 ha->flags.enable_lip_reset = 0;
4073 ha->flags.enable_lip_full_login =
4074 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4075 ha->flags.enable_target_reset =
4076 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4077 ha->flags.enable_led_scheme = 0;
4078 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4080 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4081 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4083 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4084 sizeof(ha->fw_seriallink_options24));
4086 /* save HBA serial number */
4087 ha->serial0 = icb->port_name[5];
4088 ha->serial1 = icb->port_name[6];
4089 ha->serial2 = icb->port_name[7];
4090 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4091 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4093 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4095 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4097 /* Set minimum login_timeout to 4 seconds. */
4098 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4099 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4100 if (le16_to_cpu(nv->login_timeout) < 4)
4101 nv->login_timeout = __constant_cpu_to_le16(4);
4102 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4103 icb->login_timeout = nv->login_timeout;
4105 /* Set minimum RATOV to 100 tenths of a second. */
4108 ha->loop_reset_delay = nv->reset_delay;
4110 /* Link Down Timeout = 0:
4112 * When Port Down timer expires we will start returning
4113 * I/O's to OS with "DID_NO_CONNECT".
4115 * Link Down Timeout != 0:
4117 * The driver waits for the link to come up after link down
4118 * before returning I/Os to OS with "DID_NO_CONNECT".
4120 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4121 ha->loop_down_abort_time =
4122 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4124 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4125 ha->loop_down_abort_time =
4126 (LOOP_DOWN_TIME - ha->link_down_timeout);
4129 /* Need enough time to try and get the port back. */
4130 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4131 if (qlport_down_retry)
4132 ha->port_down_retry_count = qlport_down_retry;
4134 /* Set login_retry_count */
4135 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4136 if (ha->port_down_retry_count ==
4137 le16_to_cpu(nv->port_down_retry_count) &&
4138 ha->port_down_retry_count > 3)
4139 ha->login_retry_count = ha->port_down_retry_count;
4140 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4141 ha->login_retry_count = ha->port_down_retry_count;
4142 if (ql2xloginretrycount)
4143 ha->login_retry_count = ql2xloginretrycount;
4146 if (!vha->flags.init_done) {
4147 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4148 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4149 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4150 le16_to_cpu(icb->interrupt_delay_timer): 2;
4152 icb->firmware_options_2 &= __constant_cpu_to_le32(
4153 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4154 vha->flags.process_response_queue = 0;
4155 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4156 ha->zio_mode = QLA_ZIO_MODE_6;
4158 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4159 "(%d us).\n", vha->host_no, ha->zio_mode,
4160 ha->zio_timer * 100));
4161 qla_printk(KERN_INFO, ha,
4162 "ZIO mode %d enabled; timer delay (%d us).\n",
4163 ha->zio_mode, ha->zio_timer * 100);
4165 icb->firmware_options_2 |= cpu_to_le32(
4166 (uint32_t)ha->zio_mode);
4167 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4168 vha->flags.process_response_queue = 1;
4172 DEBUG2_3(printk(KERN_WARNING
4173 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4179 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4182 int rval = QLA_SUCCESS;
4183 int segments, fragment;
4184 uint32_t *dcode, dlen;
4188 struct qla_hw_data *ha = vha->hw;
4189 struct req_que *req = ha->req_q_map[0];
4191 qla_printk(KERN_INFO, ha,
4192 "FW: Loading from flash (%x)...\n", faddr);
4196 segments = FA_RISC_CODE_SEGMENTS;
4197 dcode = (uint32_t *)req->ring;
4200 /* Validate firmware image by checking version. */
4201 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
4202 for (i = 0; i < 4; i++)
4203 dcode[i] = be32_to_cpu(dcode[i]);
4204 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4205 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4206 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4208 qla_printk(KERN_WARNING, ha,
4209 "Unable to verify integrity of flash firmware image!\n");
4210 qla_printk(KERN_WARNING, ha,
4211 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4212 dcode[1], dcode[2], dcode[3]);
4214 return QLA_FUNCTION_FAILED;
4217 while (segments && rval == QLA_SUCCESS) {
4218 /* Read segment's load information. */
4219 qla24xx_read_flash_data(vha, dcode, faddr, 4);
4221 risc_addr = be32_to_cpu(dcode[2]);
4222 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4223 risc_size = be32_to_cpu(dcode[3]);
4226 while (risc_size > 0 && rval == QLA_SUCCESS) {
4227 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4228 if (dlen > risc_size)
4231 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4232 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
4233 vha->host_no, risc_addr, dlen, faddr));
4235 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
4236 for (i = 0; i < dlen; i++)
4237 dcode[i] = swab32(dcode[i]);
4239 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
4242 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4243 "segment %d of firmware\n", vha->host_no,
4245 qla_printk(KERN_WARNING, ha,
4246 "[ERROR] Failed to load segment %d of "
4247 "firmware\n", fragment);
4264 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4267 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4271 uint16_t *wcode, *fwcode;
4272 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4273 struct fw_blob *blob;
4274 struct qla_hw_data *ha = vha->hw;
4275 struct req_que *req = ha->req_q_map[0];
4277 /* Load firmware blob. */
4278 blob = qla2x00_request_firmware(vha);
4280 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
4281 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4282 "from: " QLA_FW_URL ".\n");
4283 return QLA_FUNCTION_FAILED;
4288 wcode = (uint16_t *)req->ring;
4290 fwcode = (uint16_t *)blob->fw->data;
4293 /* Validate firmware image by checking version. */
4294 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4295 qla_printk(KERN_WARNING, ha,
4296 "Unable to verify integrity of firmware image (%Zd)!\n",
4298 goto fail_fw_integrity;
4300 for (i = 0; i < 4; i++)
4301 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4302 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4303 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4304 wcode[2] == 0 && wcode[3] == 0)) {
4305 qla_printk(KERN_WARNING, ha,
4306 "Unable to verify integrity of firmware image!\n");
4307 qla_printk(KERN_WARNING, ha,
4308 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
4309 wcode[1], wcode[2], wcode[3]);
4310 goto fail_fw_integrity;
4314 while (*seg && rval == QLA_SUCCESS) {
4316 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4317 risc_size = be16_to_cpu(fwcode[3]);
4319 /* Validate firmware image size. */
4320 fwclen += risc_size * sizeof(uint16_t);
4321 if (blob->fw->size < fwclen) {
4322 qla_printk(KERN_WARNING, ha,
4323 "Unable to verify integrity of firmware image "
4324 "(%Zd)!\n", blob->fw->size);
4325 goto fail_fw_integrity;
4329 while (risc_size > 0 && rval == QLA_SUCCESS) {
4330 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4331 if (wlen > risc_size)
4334 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4335 "addr %x, number of words 0x%x.\n", vha->host_no,
4338 for (i = 0; i < wlen; i++)
4339 wcode[i] = swab16(fwcode[i]);
4341 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
4344 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4345 "segment %d of firmware\n", vha->host_no,
4347 qla_printk(KERN_WARNING, ha,
4348 "[ERROR] Failed to load segment %d of "
4349 "firmware\n", fragment);
4365 return QLA_FUNCTION_FAILED;
4369 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4372 int segments, fragment;
4373 uint32_t *dcode, dlen;
4377 struct fw_blob *blob;
4378 uint32_t *fwcode, fwclen;
4379 struct qla_hw_data *ha = vha->hw;
4380 struct req_que *req = ha->req_q_map[0];
4382 /* Load firmware blob. */
4383 blob = qla2x00_request_firmware(vha);
4385 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
4386 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4387 "from: " QLA_FW_URL ".\n");
4389 return QLA_FUNCTION_FAILED;
4392 qla_printk(KERN_INFO, ha,
4393 "FW: Loading via request-firmware...\n");
4397 segments = FA_RISC_CODE_SEGMENTS;
4398 dcode = (uint32_t *)req->ring;
4400 fwcode = (uint32_t *)blob->fw->data;
4403 /* Validate firmware image by checking version. */
4404 if (blob->fw->size < 8 * sizeof(uint32_t)) {
4405 qla_printk(KERN_WARNING, ha,
4406 "Unable to verify integrity of firmware image (%Zd)!\n",
4408 goto fail_fw_integrity;
4410 for (i = 0; i < 4; i++)
4411 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4412 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4413 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4414 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4416 qla_printk(KERN_WARNING, ha,
4417 "Unable to verify integrity of firmware image!\n");
4418 qla_printk(KERN_WARNING, ha,
4419 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4420 dcode[1], dcode[2], dcode[3]);
4421 goto fail_fw_integrity;
4424 while (segments && rval == QLA_SUCCESS) {
4425 risc_addr = be32_to_cpu(fwcode[2]);
4426 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4427 risc_size = be32_to_cpu(fwcode[3]);
4429 /* Validate firmware image size. */
4430 fwclen += risc_size * sizeof(uint32_t);
4431 if (blob->fw->size < fwclen) {
4432 qla_printk(KERN_WARNING, ha,
4433 "Unable to verify integrity of firmware image "
4434 "(%Zd)!\n", blob->fw->size);
4436 goto fail_fw_integrity;
4440 while (risc_size > 0 && rval == QLA_SUCCESS) {
4441 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4442 if (dlen > risc_size)
4445 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4446 "addr %x, number of dwords 0x%x.\n", vha->host_no,
4449 for (i = 0; i < dlen; i++)
4450 dcode[i] = swab32(fwcode[i]);
4452 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
4455 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4456 "segment %d of firmware\n", vha->host_no,
4458 qla_printk(KERN_WARNING, ha,
4459 "[ERROR] Failed to load segment %d of "
4460 "firmware\n", fragment);
4476 return QLA_FUNCTION_FAILED;
4480 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4484 if (ql2xfwloadbin == 1)
4485 return qla81xx_load_risc(vha, srisc_addr);
4489 * 1) Firmware via request-firmware interface (.bin file).
4490 * 2) Firmware residing in flash.
4492 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4493 if (rval == QLA_SUCCESS)
4496 return qla24xx_load_risc_flash(vha, srisc_addr,
4497 vha->hw->flt_region_fw);
4501 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4504 struct qla_hw_data *ha = vha->hw;
4506 if (ql2xfwloadbin == 2)
4511 * 1) Firmware residing in flash.
4512 * 2) Firmware via request-firmware interface (.bin file).
4513 * 3) Golden-Firmware residing in flash -- limited operation.
4515 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
4516 if (rval == QLA_SUCCESS)
4520 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4521 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4524 qla_printk(KERN_ERR, ha,
4525 "FW: Attempting to fallback to golden firmware...\n");
4526 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4527 if (rval != QLA_SUCCESS)
4530 qla_printk(KERN_ERR, ha,
4531 "FW: Please update operational firmware...\n");
4532 ha->flags.running_gold_fw = 1;
4538 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
4541 struct qla_hw_data *ha = vha->hw;
4543 if (ha->flags.pci_channel_io_perm_failure)
4545 if (!IS_FWI2_CAPABLE(ha))
4547 if (!ha->fw_major_version)
4550 ret = qla2x00_stop_firmware(vha);
4551 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4552 ret != QLA_INVALID_COMMAND && retries ; retries--) {
4553 ha->isp_ops->reset_chip(vha);
4554 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
4556 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
4558 qla_printk(KERN_INFO, ha,
4559 "Attempting retry of stop-firmware command...\n");
4560 ret = qla2x00_stop_firmware(vha);
4565 qla24xx_configure_vhba(scsi_qla_host_t *vha)
4567 int rval = QLA_SUCCESS;
4568 uint16_t mb[MAILBOX_REGISTER_COUNT];
4569 struct qla_hw_data *ha = vha->hw;
4570 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4571 struct req_que *req;
4572 struct rsp_que *rsp;
4577 rval = qla2x00_fw_ready(base_vha);
4578 if (ha->flags.cpu_affinity_enabled)
4579 req = ha->req_q_map[0];
4584 if (rval == QLA_SUCCESS) {
4585 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
4586 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
4589 vha->flags.management_server_logged_in = 0;
4591 /* Login to SNS first */
4592 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
4593 if (mb[0] != MBS_COMMAND_COMPLETE) {
4594 DEBUG15(qla_printk(KERN_INFO, ha,
4595 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4596 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4597 mb[0], mb[1], mb[2], mb[6], mb[7]));
4598 return (QLA_FUNCTION_FAILED);
4601 atomic_set(&vha->loop_down_timer, 0);
4602 atomic_set(&vha->loop_state, LOOP_UP);
4603 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4604 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4605 rval = qla2x00_loop_resync(base_vha);
4610 /* 84XX Support **************************************************************/
4612 static LIST_HEAD(qla_cs84xx_list);
4613 static DEFINE_MUTEX(qla_cs84xx_mutex);
4615 static struct qla_chip_state_84xx *
4616 qla84xx_get_chip(struct scsi_qla_host *vha)
4618 struct qla_chip_state_84xx *cs84xx;
4619 struct qla_hw_data *ha = vha->hw;
4621 mutex_lock(&qla_cs84xx_mutex);
4623 /* Find any shared 84xx chip. */
4624 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4625 if (cs84xx->bus == ha->pdev->bus) {
4626 kref_get(&cs84xx->kref);
4631 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4635 kref_init(&cs84xx->kref);
4636 spin_lock_init(&cs84xx->access_lock);
4637 mutex_init(&cs84xx->fw_update_mutex);
4638 cs84xx->bus = ha->pdev->bus;
4640 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4642 mutex_unlock(&qla_cs84xx_mutex);
4647 __qla84xx_chip_release(struct kref *kref)
4649 struct qla_chip_state_84xx *cs84xx =
4650 container_of(kref, struct qla_chip_state_84xx, kref);
4652 mutex_lock(&qla_cs84xx_mutex);
4653 list_del(&cs84xx->list);
4654 mutex_unlock(&qla_cs84xx_mutex);
4659 qla84xx_put_chip(struct scsi_qla_host *vha)
4661 struct qla_hw_data *ha = vha->hw;
4663 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4667 qla84xx_init_chip(scsi_qla_host_t *vha)
4671 struct qla_hw_data *ha = vha->hw;
4673 mutex_lock(&ha->cs84xx->fw_update_mutex);
4675 rval = qla84xx_verify_chip(vha, status);
4677 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4679 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4683 /* 81XX Support **************************************************************/
4686 qla81xx_nvram_config(scsi_qla_host_t *vha)
4689 struct init_cb_81xx *icb;
4690 struct nvram_81xx *nv;
4692 uint8_t *dptr1, *dptr2;
4695 struct qla_hw_data *ha = vha->hw;
4698 icb = (struct init_cb_81xx *)ha->init_cb;
4701 /* Determine NVRAM starting address. */
4702 ha->nvram_size = sizeof(struct nvram_81xx);
4703 ha->vpd_size = FA_NVRAM_VPD_SIZE;
4705 /* Get VPD data into cache */
4706 ha->vpd = ha->nvram + VPD_OFFSET;
4707 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4710 /* Get NVRAM data into cache and calculate checksum. */
4711 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
4713 dptr = (uint32_t *)nv;
4714 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4715 chksum += le32_to_cpu(*dptr++);
4717 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
4718 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4720 /* Bad NVRAM data, set defaults parameters. */
4721 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4722 || nv->id[3] != ' ' ||
4723 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4724 /* Reset NVRAM data. */
4725 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4726 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4727 le16_to_cpu(nv->nvram_version));
4728 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4729 "invalid -- WWPN) defaults.\n");
4732 * Set default initialization control block.
4734 memset(nv, 0, ha->nvram_size);
4735 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4736 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4737 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4738 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4739 nv->exchange_count = __constant_cpu_to_le16(0);
4740 nv->port_name[0] = 0x21;
4741 nv->port_name[1] = 0x00 + ha->port_no;
4742 nv->port_name[2] = 0x00;
4743 nv->port_name[3] = 0xe0;
4744 nv->port_name[4] = 0x8b;
4745 nv->port_name[5] = 0x1c;
4746 nv->port_name[6] = 0x55;
4747 nv->port_name[7] = 0x86;
4748 nv->node_name[0] = 0x20;
4749 nv->node_name[1] = 0x00;
4750 nv->node_name[2] = 0x00;
4751 nv->node_name[3] = 0xe0;
4752 nv->node_name[4] = 0x8b;
4753 nv->node_name[5] = 0x1c;
4754 nv->node_name[6] = 0x55;
4755 nv->node_name[7] = 0x86;
4756 nv->login_retry_count = __constant_cpu_to_le16(8);
4757 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4758 nv->login_timeout = __constant_cpu_to_le16(0);
4759 nv->firmware_options_1 =
4760 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4761 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4762 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4763 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4764 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4765 nv->efi_parameters = __constant_cpu_to_le32(0);
4766 nv->reset_delay = 5;
4767 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4768 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4769 nv->link_down_timeout = __constant_cpu_to_le16(30);
4770 nv->enode_mac[0] = 0x00;
4771 nv->enode_mac[1] = 0x02;
4772 nv->enode_mac[2] = 0x03;
4773 nv->enode_mac[3] = 0x04;
4774 nv->enode_mac[4] = 0x05;
4775 nv->enode_mac[5] = 0x06 + ha->port_no;
4780 /* Reset Initialization control block */
4781 memset(icb, 0, sizeof(struct init_cb_81xx));
4783 /* Copy 1st segment. */
4784 dptr1 = (uint8_t *)icb;
4785 dptr2 = (uint8_t *)&nv->version;
4786 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4788 *dptr1++ = *dptr2++;
4790 icb->login_retry_count = nv->login_retry_count;
4792 /* Copy 2nd segment. */
4793 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4794 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4795 cnt = (uint8_t *)&icb->reserved_5 -
4796 (uint8_t *)&icb->interrupt_delay_timer;
4798 *dptr1++ = *dptr2++;
4800 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4801 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4802 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4803 icb->enode_mac[0] = 0x01;
4804 icb->enode_mac[1] = 0x02;
4805 icb->enode_mac[2] = 0x03;
4806 icb->enode_mac[3] = 0x04;
4807 icb->enode_mac[4] = 0x05;
4808 icb->enode_mac[5] = 0x06 + ha->port_no;
4811 /* Use extended-initialization control block. */
4812 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
4815 * Setup driver NVRAM options.
4817 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4820 /* Use alternate WWN? */
4821 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4822 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4823 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4826 /* Prepare nodename */
4827 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4829 * Firmware will apply the following mask if the nodename was
4832 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4833 icb->node_name[0] &= 0xF0;
4836 /* Set host adapter parameters. */
4837 ha->flags.disable_risc_code_load = 0;
4838 ha->flags.enable_lip_reset = 0;
4839 ha->flags.enable_lip_full_login =
4840 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4841 ha->flags.enable_target_reset =
4842 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4843 ha->flags.enable_led_scheme = 0;
4844 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4846 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4847 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4849 /* save HBA serial number */
4850 ha->serial0 = icb->port_name[5];
4851 ha->serial1 = icb->port_name[6];
4852 ha->serial2 = icb->port_name[7];
4853 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4854 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4856 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4858 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4860 /* Set minimum login_timeout to 4 seconds. */
4861 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4862 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4863 if (le16_to_cpu(nv->login_timeout) < 4)
4864 nv->login_timeout = __constant_cpu_to_le16(4);
4865 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4866 icb->login_timeout = nv->login_timeout;
4868 /* Set minimum RATOV to 100 tenths of a second. */
4871 ha->loop_reset_delay = nv->reset_delay;
4873 /* Link Down Timeout = 0:
4875 * When Port Down timer expires we will start returning
4876 * I/O's to OS with "DID_NO_CONNECT".
4878 * Link Down Timeout != 0:
4880 * The driver waits for the link to come up after link down
4881 * before returning I/Os to OS with "DID_NO_CONNECT".
4883 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4884 ha->loop_down_abort_time =
4885 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4887 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4888 ha->loop_down_abort_time =
4889 (LOOP_DOWN_TIME - ha->link_down_timeout);
4892 /* Need enough time to try and get the port back. */
4893 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4894 if (qlport_down_retry)
4895 ha->port_down_retry_count = qlport_down_retry;
4897 /* Set login_retry_count */
4898 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4899 if (ha->port_down_retry_count ==
4900 le16_to_cpu(nv->port_down_retry_count) &&
4901 ha->port_down_retry_count > 3)
4902 ha->login_retry_count = ha->port_down_retry_count;
4903 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4904 ha->login_retry_count = ha->port_down_retry_count;
4905 if (ql2xloginretrycount)
4906 ha->login_retry_count = ql2xloginretrycount;
4909 if (!vha->flags.init_done) {
4910 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4911 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4912 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4913 le16_to_cpu(icb->interrupt_delay_timer): 2;
4915 icb->firmware_options_2 &= __constant_cpu_to_le32(
4916 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4917 vha->flags.process_response_queue = 0;
4918 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4919 ha->zio_mode = QLA_ZIO_MODE_6;
4921 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4922 "(%d us).\n", vha->host_no, ha->zio_mode,
4923 ha->zio_timer * 100));
4924 qla_printk(KERN_INFO, ha,
4925 "ZIO mode %d enabled; timer delay (%d us).\n",
4926 ha->zio_mode, ha->zio_timer * 100);
4928 icb->firmware_options_2 |= cpu_to_le32(
4929 (uint32_t)ha->zio_mode);
4930 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4931 vha->flags.process_response_queue = 1;
4935 DEBUG2_3(printk(KERN_WARNING
4936 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4942 qla82xx_restart_isp(scsi_qla_host_t *vha)
4946 struct qla_hw_data *ha = vha->hw;
4947 struct req_que *req = ha->req_q_map[0];
4948 struct rsp_que *rsp = ha->rsp_q_map[0];
4949 struct scsi_qla_host *vp;
4950 struct scsi_qla_host *tvp;
4952 status = qla2x00_init_rings(vha);
4954 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
4955 ha->flags.chip_reset_done = 1;
4957 status = qla2x00_fw_ready(vha);
4959 qla_printk(KERN_INFO, ha,
4960 "%s(): Start configure loop, "
4961 "status = %d\n", __func__, status);
4963 /* Issue a marker after FW becomes ready. */
4964 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
4966 vha->flags.online = 1;
4967 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4970 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4971 qla2x00_configure_loop(vha);
4973 } while (!atomic_read(&vha->loop_down_timer) &&
4974 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
4976 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
4979 /* if no cable then assume it's good */
4980 if ((vha->device_flags & DFLG_NO_CABLE))
4983 qla_printk(KERN_INFO, ha,
4984 "%s(): Configure loop done, status = 0x%x\n",
4989 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
4991 if (!atomic_read(&vha->loop_down_timer)) {
4993 * Issue marker command only when we are going
4994 * to start the I/O .
4996 vha->marker_needed = 1;
4999 vha->flags.online = 1;
5001 ha->isp_ops->enable_intrs(ha);
5003 ha->isp_abort_cnt = 0;
5004 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5007 ha->flags.fce_enabled = 1;
5009 fce_calc_size(ha->fce_bufs));
5010 rval = qla2x00_enable_fce_trace(vha,
5011 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5014 qla_printk(KERN_WARNING, ha,
5015 "Unable to reinitialize FCE "
5017 ha->flags.fce_enabled = 0;
5022 memset(ha->eft, 0, EFT_SIZE);
5023 rval = qla2x00_enable_eft_trace(vha,
5024 ha->eft_dma, EFT_NUM_BUFFERS);
5026 qla_printk(KERN_WARNING, ha,
5027 "Unable to reinitialize EFT "
5031 } else { /* failed the ISP abort */
5032 vha->flags.online = 1;
5033 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
5034 if (ha->isp_abort_cnt == 0) {
5035 qla_printk(KERN_WARNING, ha,
5036 "ISP error recovery failed - "
5037 "board disabled\n");
5039 * The next call disables the board
5042 ha->isp_ops->reset_adapter(vha);
5043 vha->flags.online = 0;
5044 clear_bit(ISP_ABORT_RETRY,
5047 } else { /* schedule another ISP abort */
5048 ha->isp_abort_cnt--;
5049 qla_printk(KERN_INFO, ha,
5050 "qla%ld: ISP abort - "
5051 "retry remaining %d\n",
5052 vha->host_no, ha->isp_abort_cnt);
5056 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
5057 qla_printk(KERN_INFO, ha,
5058 "(%ld): ISP error recovery "
5059 "- retrying (%d) more times\n",
5060 vha->host_no, ha->isp_abort_cnt);
5061 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5067 DEBUG(printk(KERN_INFO
5068 "qla82xx_restart_isp(%ld): succeeded.\n",
5070 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
5072 qla2x00_vp_abort_isp(vp);
5075 qla_printk(KERN_INFO, ha,
5076 "qla82xx_restart_isp: **** FAILED ****\n");
5083 qla81xx_update_fw_options(scsi_qla_host_t *vha)
5085 struct qla_hw_data *ha = vha->hw;
5090 /* Enable ETS Burst. */
5091 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5092 ha->fw_options[2] |= BIT_9;
5093 qla2x00_set_fw_options(vha, ha->fw_options);
5097 * qla24xx_get_fcp_prio
5098 * Gets the fcp cmd priority value for the logged in port.
5099 * Looks for a match of the port descriptors within
5100 * each of the fcp prio config entries. If a match is found,
5101 * the tag (priority) value is returned.
5104 * ha = adapter block po
5105 * fcport = port structure pointer.
5108 * non-zero (if found)
5115 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5118 uint8_t pid_match, wwn_match;
5120 uint32_t pid1, pid2;
5121 uint64_t wwn1, wwn2;
5122 struct qla_fcp_prio_entry *pri_entry;
5123 struct qla_hw_data *ha = vha->hw;
5125 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
5129 entries = ha->fcp_prio_cfg->num_entries;
5130 pri_entry = &ha->fcp_prio_cfg->entry[0];
5132 for (i = 0; i < entries; i++) {
5133 pid_match = wwn_match = 0;
5135 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5140 /* check source pid for a match */
5141 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5142 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5143 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5144 if (pid1 == INVALID_PORT_ID)
5146 else if (pid1 == pid2)
5150 /* check destination pid for a match */
5151 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5152 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5153 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5154 if (pid1 == INVALID_PORT_ID)
5156 else if (pid1 == pid2)
5160 /* check source WWN for a match */
5161 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5162 wwn1 = wwn_to_u64(vha->port_name);
5163 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5164 if (wwn2 == (uint64_t)-1)
5166 else if (wwn1 == wwn2)
5170 /* check destination WWN for a match */
5171 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5172 wwn1 = wwn_to_u64(fcport->port_name);
5173 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5174 if (wwn2 == (uint64_t)-1)
5176 else if (wwn1 == wwn2)
5180 if (pid_match == 2 || wwn_match == 2) {
5181 /* Found a matching entry */
5182 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5183 priority = pri_entry->tag;
5194 * qla24xx_update_fcport_fcp_prio
5195 * Activates fcp priority for the logged in fc port
5198 * ha = adapter block pointer.
5199 * fcp = port structure pointer.
5202 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5208 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *ha, fc_port_t *fcport)
5214 if (atomic_read(&fcport->state) == FCS_UNCONFIGURED ||
5215 fcport->port_type != FCT_TARGET ||
5216 fcport->loop_id == FC_NO_LOOP_ID)
5217 return QLA_FUNCTION_FAILED;
5219 priority = qla24xx_get_fcp_prio(ha, fcport);
5220 ret = qla24xx_set_fcp_prio(ha, fcport->loop_id, priority, mb);
5221 if (ret == QLA_SUCCESS)
5222 fcport->fcp_prio = priority;
5224 DEBUG2(printk(KERN_WARNING
5225 "scsi(%ld): Unable to activate fcp priority, "
5226 " ret=0x%x\n", ha->host_no, ret));
5232 * qla24xx_update_all_fcp_prio
5233 * Activates fcp priority for all the logged in ports
5236 * ha = adapter block pointer.
5239 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5245 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5250 ret = QLA_FUNCTION_FAILED;
5251 /* We need to set priority for all logged in ports */
5252 list_for_each_entry(fcport, &vha->vp_fcports, list)
5253 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);