2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2008 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
10 #include <linux/delay.h>
11 #include <linux/vmalloc.h>
13 #include "qla_devtbl.h"
20 * QLogic ISP2x00 Hardware Support Function Prototypes.
22 static int qla2x00_isp_firmware(scsi_qla_host_t *);
23 static int qla2x00_setup_chip(scsi_qla_host_t *);
24 static int qla2x00_init_rings(scsi_qla_host_t *);
25 static int qla2x00_fw_ready(scsi_qla_host_t *);
26 static int qla2x00_configure_hba(scsi_qla_host_t *);
27 static int qla2x00_configure_loop(scsi_qla_host_t *);
28 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
29 static int qla2x00_configure_fabric(scsi_qla_host_t *);
30 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
31 static int qla2x00_device_resync(scsi_qla_host_t *);
32 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
35 static int qla2x00_restart_isp(scsi_qla_host_t *);
37 static int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *);
39 static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
40 static int qla84xx_init_chip(scsi_qla_host_t *);
41 static int qla25xx_init_queues(struct qla_hw_data *);
43 /* SRB Extensions ---------------------------------------------------------- */
46 qla2x00_ctx_sp_timeout(unsigned long __data)
48 srb_t *sp = (srb_t *)__data;
50 fc_port_t *fcport = sp->fcport;
51 struct qla_hw_data *ha = fcport->vha->hw;
55 spin_lock_irqsave(&ha->hardware_lock, flags);
56 req = ha->req_q_map[0];
57 req->outstanding_cmds[sp->handle] = NULL;
60 spin_unlock_irqrestore(&ha->hardware_lock, flags);
66 qla2x00_ctx_sp_free(srb_t *sp)
68 struct srb_ctx *ctx = sp->ctx;
71 mempool_free(sp, sp->fcport->vha->hw->srb_mempool);
75 qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size,
79 struct qla_hw_data *ha = vha->hw;
82 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
85 ctx = kzalloc(size, GFP_KERNEL);
87 mempool_free(sp, ha->srb_mempool);
91 memset(sp, 0, sizeof(*sp));
94 ctx->free = qla2x00_ctx_sp_free;
96 init_timer(&ctx->timer);
99 ctx->timer.expires = jiffies + tmo * HZ;
100 ctx->timer.data = (unsigned long)sp;
101 ctx->timer.function = qla2x00_ctx_sp_timeout;
102 add_timer(&ctx->timer);
107 /* Asynchronous Login/Logout Routines -------------------------------------- */
109 #define ELS_TMO_2_RATOV(ha) ((ha)->r_a_tov / 10 * 2)
112 qla2x00_async_logio_timeout(srb_t *sp)
114 fc_port_t *fcport = sp->fcport;
115 struct srb_logio *lio = sp->ctx;
117 DEBUG2(printk(KERN_WARNING
118 "scsi(%ld:%x): Async-%s timeout.\n",
119 fcport->vha->host_no, sp->handle,
120 lio->ctx.type == SRB_LOGIN_CMD ? "login": "logout"));
122 if (lio->ctx.type == SRB_LOGIN_CMD)
123 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
127 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
130 struct qla_hw_data *ha = vha->hw;
132 struct srb_logio *lio;
135 rval = QLA_FUNCTION_FAILED;
136 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_logio),
137 ELS_TMO_2_RATOV(ha) + 2);
142 lio->ctx.type = SRB_LOGIN_CMD;
143 lio->ctx.timeout = qla2x00_async_logio_timeout;
144 lio->flags |= SRB_LOGIN_COND_PLOGI;
145 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
146 lio->flags |= SRB_LOGIN_RETRIED;
147 rval = qla2x00_start_sp(sp);
148 if (rval != QLA_SUCCESS)
151 DEBUG2(printk(KERN_DEBUG
152 "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
153 "retries=%d.\n", fcport->vha->host_no, sp->handle, fcport->loop_id,
154 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
155 fcport->login_retry));
159 del_timer_sync(&lio->ctx.timer);
166 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
168 struct qla_hw_data *ha = vha->hw;
170 struct srb_logio *lio;
173 rval = QLA_FUNCTION_FAILED;
174 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_logio),
175 ELS_TMO_2_RATOV(ha) + 2);
180 lio->ctx.type = SRB_LOGOUT_CMD;
181 lio->ctx.timeout = qla2x00_async_logio_timeout;
182 rval = qla2x00_start_sp(sp);
183 if (rval != QLA_SUCCESS)
186 DEBUG2(printk(KERN_DEBUG
187 "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
188 fcport->vha->host_no, sp->handle, fcport->loop_id,
189 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
193 del_timer_sync(&lio->ctx.timer);
200 qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
207 case MBS_COMMAND_COMPLETE:
208 if (fcport->flags & FCF_TAPE_PRESENT)
210 rval = qla2x00_get_port_database(vha, fcport, opts);
211 if (rval != QLA_SUCCESS)
212 qla2x00_mark_device_lost(vha, fcport, 1, 0);
214 qla2x00_update_fcport(vha, fcport);
216 case MBS_COMMAND_ERROR:
217 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
218 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
220 qla2x00_mark_device_lost(vha, fcport, 1, 0);
222 case MBS_PORT_ID_USED:
223 fcport->loop_id = data[1];
224 qla2x00_post_async_login_work(vha, fcport, NULL);
226 case MBS_LOOP_ID_USED:
228 rval = qla2x00_find_new_loop_id(vha, fcport);
229 if (rval != QLA_SUCCESS) {
230 qla2x00_mark_device_lost(vha, fcport, 1, 0);
233 qla2x00_post_async_login_work(vha, fcport, NULL);
240 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
243 qla2x00_mark_device_lost(vha, fcport, 1, 0);
247 /****************************************************************************/
248 /* QLogic ISP2x00 Hardware Support Functions. */
249 /****************************************************************************/
252 * qla2x00_initialize_adapter
256 * ha = adapter block pointer.
262 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
265 struct qla_hw_data *ha = vha->hw;
266 struct req_que *req = ha->req_q_map[0];
268 /* Clear adapter flags. */
269 vha->flags.online = 0;
270 ha->flags.chip_reset_done = 0;
271 vha->flags.reset_active = 0;
272 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
273 atomic_set(&vha->loop_state, LOOP_DOWN);
274 vha->device_flags = DFLG_NO_CABLE;
276 vha->flags.management_server_logged_in = 0;
277 vha->marker_needed = 0;
278 ha->isp_abort_cnt = 0;
279 ha->beacon_blink_led = 0;
281 set_bit(0, ha->req_qid_map);
282 set_bit(0, ha->rsp_qid_map);
284 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
285 rval = ha->isp_ops->pci_config(vha);
287 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
292 ha->isp_ops->reset_chip(vha);
294 rval = qla2xxx_get_flash_info(vha);
296 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
301 ha->isp_ops->get_flash_version(vha, req->ring);
303 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
305 ha->isp_ops->nvram_config(vha);
307 if (ha->flags.disable_serdes) {
308 /* Mask HBA via NVRAM settings? */
309 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
310 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
311 vha->port_name[0], vha->port_name[1],
312 vha->port_name[2], vha->port_name[3],
313 vha->port_name[4], vha->port_name[5],
314 vha->port_name[6], vha->port_name[7]);
315 return QLA_FUNCTION_FAILED;
318 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
320 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
321 rval = ha->isp_ops->chip_diag(vha);
324 rval = qla2x00_setup_chip(vha);
328 if (IS_QLA84XX(ha)) {
329 ha->cs84xx = qla84xx_get_chip(vha);
331 qla_printk(KERN_ERR, ha,
332 "Unable to configure ISP84XX.\n");
333 return QLA_FUNCTION_FAILED;
336 rval = qla2x00_init_rings(vha);
337 ha->flags.chip_reset_done = 1;
343 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
346 * Returns 0 on success.
349 qla2100_pci_config(scsi_qla_host_t *vha)
353 struct qla_hw_data *ha = vha->hw;
354 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
356 pci_set_master(ha->pdev);
357 pci_try_set_mwi(ha->pdev);
359 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
360 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
361 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
363 pci_disable_rom(ha->pdev);
365 /* Get PCI bus information. */
366 spin_lock_irqsave(&ha->hardware_lock, flags);
367 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
368 spin_unlock_irqrestore(&ha->hardware_lock, flags);
374 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
377 * Returns 0 on success.
380 qla2300_pci_config(scsi_qla_host_t *vha)
383 unsigned long flags = 0;
385 struct qla_hw_data *ha = vha->hw;
386 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
388 pci_set_master(ha->pdev);
389 pci_try_set_mwi(ha->pdev);
391 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
392 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
394 if (IS_QLA2322(ha) || IS_QLA6322(ha))
395 w &= ~PCI_COMMAND_INTX_DISABLE;
396 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
399 * If this is a 2300 card and not 2312, reset the
400 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
401 * the 2310 also reports itself as a 2300 so we need to get the
402 * fb revision level -- a 6 indicates it really is a 2300 and
405 if (IS_QLA2300(ha)) {
406 spin_lock_irqsave(&ha->hardware_lock, flags);
409 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
410 for (cnt = 0; cnt < 30000; cnt++) {
411 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
417 /* Select FPM registers. */
418 WRT_REG_WORD(®->ctrl_status, 0x20);
419 RD_REG_WORD(®->ctrl_status);
421 /* Get the fb rev level */
422 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
424 if (ha->fb_rev == FPM_2300)
425 pci_clear_mwi(ha->pdev);
427 /* Deselect FPM registers. */
428 WRT_REG_WORD(®->ctrl_status, 0x0);
429 RD_REG_WORD(®->ctrl_status);
431 /* Release RISC module. */
432 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
433 for (cnt = 0; cnt < 30000; cnt++) {
434 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
440 spin_unlock_irqrestore(&ha->hardware_lock, flags);
443 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
445 pci_disable_rom(ha->pdev);
447 /* Get PCI bus information. */
448 spin_lock_irqsave(&ha->hardware_lock, flags);
449 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
450 spin_unlock_irqrestore(&ha->hardware_lock, flags);
456 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
459 * Returns 0 on success.
462 qla24xx_pci_config(scsi_qla_host_t *vha)
465 unsigned long flags = 0;
466 struct qla_hw_data *ha = vha->hw;
467 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
469 pci_set_master(ha->pdev);
470 pci_try_set_mwi(ha->pdev);
472 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
473 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
474 w &= ~PCI_COMMAND_INTX_DISABLE;
475 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
477 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
479 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
480 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
481 pcix_set_mmrbc(ha->pdev, 2048);
483 /* PCIe -- adjust Maximum Read Request Size (2048). */
484 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
485 pcie_set_readrq(ha->pdev, 2048);
487 pci_disable_rom(ha->pdev);
489 ha->chip_revision = ha->pdev->revision;
491 /* Get PCI bus information. */
492 spin_lock_irqsave(&ha->hardware_lock, flags);
493 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
494 spin_unlock_irqrestore(&ha->hardware_lock, flags);
500 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
503 * Returns 0 on success.
506 qla25xx_pci_config(scsi_qla_host_t *vha)
509 struct qla_hw_data *ha = vha->hw;
511 pci_set_master(ha->pdev);
512 pci_try_set_mwi(ha->pdev);
514 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
515 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
516 w &= ~PCI_COMMAND_INTX_DISABLE;
517 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
519 /* PCIe -- adjust Maximum Read Request Size (2048). */
520 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
521 pcie_set_readrq(ha->pdev, 2048);
523 pci_disable_rom(ha->pdev);
525 ha->chip_revision = ha->pdev->revision;
531 * qla2x00_isp_firmware() - Choose firmware image.
534 * Returns 0 on success.
537 qla2x00_isp_firmware(scsi_qla_host_t *vha)
540 uint16_t loop_id, topo, sw_cap;
541 uint8_t domain, area, al_pa;
542 struct qla_hw_data *ha = vha->hw;
544 /* Assume loading risc code */
545 rval = QLA_FUNCTION_FAILED;
547 if (ha->flags.disable_risc_code_load) {
548 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
550 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
552 /* Verify checksum of loaded RISC code. */
553 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
554 if (rval == QLA_SUCCESS) {
555 /* And, verify we are not in ROM code. */
556 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
557 &area, &domain, &topo, &sw_cap);
562 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
570 * qla2x00_reset_chip() - Reset ISP chip.
573 * Returns 0 on success.
576 qla2x00_reset_chip(scsi_qla_host_t *vha)
578 unsigned long flags = 0;
579 struct qla_hw_data *ha = vha->hw;
580 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
584 ha->isp_ops->disable_intrs(ha);
586 spin_lock_irqsave(&ha->hardware_lock, flags);
588 /* Turn off master enable */
590 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
591 cmd &= ~PCI_COMMAND_MASTER;
592 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
594 if (!IS_QLA2100(ha)) {
596 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
597 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
598 for (cnt = 0; cnt < 30000; cnt++) {
599 if ((RD_REG_WORD(®->hccr) &
600 HCCR_RISC_PAUSE) != 0)
605 RD_REG_WORD(®->hccr); /* PCI Posting. */
609 /* Select FPM registers. */
610 WRT_REG_WORD(®->ctrl_status, 0x20);
611 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
613 /* FPM Soft Reset. */
614 WRT_REG_WORD(®->fpm_diag_config, 0x100);
615 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
617 /* Toggle Fpm Reset. */
618 if (!IS_QLA2200(ha)) {
619 WRT_REG_WORD(®->fpm_diag_config, 0x0);
620 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
623 /* Select frame buffer registers. */
624 WRT_REG_WORD(®->ctrl_status, 0x10);
625 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
627 /* Reset frame buffer FIFOs. */
628 if (IS_QLA2200(ha)) {
629 WRT_FB_CMD_REG(ha, reg, 0xa000);
630 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
632 WRT_FB_CMD_REG(ha, reg, 0x00fc);
634 /* Read back fb_cmd until zero or 3 seconds max */
635 for (cnt = 0; cnt < 3000; cnt++) {
636 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
642 /* Select RISC module registers. */
643 WRT_REG_WORD(®->ctrl_status, 0);
644 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
646 /* Reset RISC processor. */
647 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
648 RD_REG_WORD(®->hccr); /* PCI Posting. */
650 /* Release RISC processor. */
651 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
652 RD_REG_WORD(®->hccr); /* PCI Posting. */
655 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
656 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
658 /* Reset ISP chip. */
659 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
661 /* Wait for RISC to recover from reset. */
662 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
664 * It is necessary to for a delay here since the card doesn't
665 * respond to PCI reads during a reset. On some architectures
666 * this will result in an MCA.
669 for (cnt = 30000; cnt; cnt--) {
670 if ((RD_REG_WORD(®->ctrl_status) &
671 CSR_ISP_SOFT_RESET) == 0)
678 /* Reset RISC processor. */
679 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
681 WRT_REG_WORD(®->semaphore, 0);
683 /* Release RISC processor. */
684 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
685 RD_REG_WORD(®->hccr); /* PCI Posting. */
687 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
688 for (cnt = 0; cnt < 30000; cnt++) {
689 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
697 /* Turn on master enable */
698 cmd |= PCI_COMMAND_MASTER;
699 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
701 /* Disable RISC pause on FPM parity error. */
702 if (!IS_QLA2100(ha)) {
703 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
704 RD_REG_WORD(®->hccr); /* PCI Posting. */
707 spin_unlock_irqrestore(&ha->hardware_lock, flags);
711 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
714 * Returns 0 on success.
717 qla24xx_reset_risc(scsi_qla_host_t *vha)
719 unsigned long flags = 0;
720 struct qla_hw_data *ha = vha->hw;
721 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
725 spin_lock_irqsave(&ha->hardware_lock, flags);
728 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
729 for (cnt = 0; cnt < 30000; cnt++) {
730 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
736 WRT_REG_DWORD(®->ctrl_status,
737 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
738 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
741 /* Wait for firmware to complete NVRAM accesses. */
742 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
743 for (cnt = 10000 ; cnt && d2; cnt--) {
745 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
749 /* Wait for soft-reset to complete. */
750 d2 = RD_REG_DWORD(®->ctrl_status);
751 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
753 d2 = RD_REG_DWORD(®->ctrl_status);
757 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
758 RD_REG_DWORD(®->hccr);
760 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
761 RD_REG_DWORD(®->hccr);
763 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
764 RD_REG_DWORD(®->hccr);
766 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
767 for (cnt = 6000000 ; cnt && d2; cnt--) {
769 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
773 spin_unlock_irqrestore(&ha->hardware_lock, flags);
775 if (IS_NOPOLLING_TYPE(ha))
776 ha->isp_ops->enable_intrs(ha);
780 * qla24xx_reset_chip() - Reset ISP24xx chip.
783 * Returns 0 on success.
786 qla24xx_reset_chip(scsi_qla_host_t *vha)
788 struct qla_hw_data *ha = vha->hw;
789 ha->isp_ops->disable_intrs(ha);
791 /* Perform RISC reset. */
792 qla24xx_reset_risc(vha);
796 * qla2x00_chip_diag() - Test chip for proper operation.
799 * Returns 0 on success.
802 qla2x00_chip_diag(scsi_qla_host_t *vha)
805 struct qla_hw_data *ha = vha->hw;
806 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
807 unsigned long flags = 0;
811 struct req_que *req = ha->req_q_map[0];
813 /* Assume a failed state */
814 rval = QLA_FUNCTION_FAILED;
816 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
817 vha->host_no, (u_long)®->flash_address));
819 spin_lock_irqsave(&ha->hardware_lock, flags);
821 /* Reset ISP chip. */
822 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
825 * We need to have a delay here since the card will not respond while
826 * in reset causing an MCA on some architectures.
829 data = qla2x00_debounce_register(®->ctrl_status);
830 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
832 data = RD_REG_WORD(®->ctrl_status);
837 goto chip_diag_failed;
839 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
842 /* Reset RISC processor. */
843 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
844 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
846 /* Workaround for QLA2312 PCI parity error */
847 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
848 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
849 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
851 data = RD_MAILBOX_REG(ha, reg, 0);
858 goto chip_diag_failed;
860 /* Check product ID of chip */
861 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
863 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
864 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
865 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
866 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
867 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
868 mb[3] != PROD_ID_3) {
869 qla_printk(KERN_WARNING, ha,
870 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
872 goto chip_diag_failed;
874 ha->product_id[0] = mb[1];
875 ha->product_id[1] = mb[2];
876 ha->product_id[2] = mb[3];
877 ha->product_id[3] = mb[4];
879 /* Adjust fw RISC transfer size */
880 if (req->length > 1024)
881 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
883 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
886 if (IS_QLA2200(ha) &&
887 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
888 /* Limit firmware transfer size with a 2200A */
889 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
892 ha->device_type |= DT_ISP2200A;
893 ha->fw_transfer_size = 128;
896 /* Wrap Incoming Mailboxes Test. */
897 spin_unlock_irqrestore(&ha->hardware_lock, flags);
899 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
900 rval = qla2x00_mbx_reg_test(vha);
902 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
904 qla_printk(KERN_WARNING, ha,
905 "Failed mailbox send register test\n");
908 /* Flag a successful rval */
911 spin_lock_irqsave(&ha->hardware_lock, flags);
915 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
916 "****\n", vha->host_no));
918 spin_unlock_irqrestore(&ha->hardware_lock, flags);
924 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
927 * Returns 0 on success.
930 qla24xx_chip_diag(scsi_qla_host_t *vha)
933 struct qla_hw_data *ha = vha->hw;
934 struct req_que *req = ha->req_q_map[0];
936 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
938 rval = qla2x00_mbx_reg_test(vha);
940 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
942 qla_printk(KERN_WARNING, ha,
943 "Failed mailbox send register test\n");
945 /* Flag a successful rval */
953 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
956 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
957 eft_size, fce_size, mq_size;
960 struct qla_hw_data *ha = vha->hw;
961 struct req_que *req = ha->req_q_map[0];
962 struct rsp_que *rsp = ha->rsp_q_map[0];
965 qla_printk(KERN_WARNING, ha,
966 "Firmware dump previously allocated.\n");
971 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
972 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
973 fixed_size = sizeof(struct qla2100_fw_dump);
974 } else if (IS_QLA23XX(ha)) {
975 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
976 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
978 } else if (IS_FWI2_CAPABLE(ha)) {
980 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
981 else if (IS_QLA25XX(ha))
982 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
984 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
985 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
988 mq_size = sizeof(struct qla2xxx_mq_chain);
989 /* Allocate memory for Fibre Channel Event Buffer. */
990 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
993 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
996 qla_printk(KERN_WARNING, ha, "Unable to allocate "
997 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
1001 memset(tc, 0, FCE_SIZE);
1002 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
1003 ha->fce_mb, &ha->fce_bufs);
1005 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1006 "FCE (%d).\n", rval);
1007 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1009 ha->flags.fce_enabled = 0;
1013 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
1016 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
1017 ha->flags.fce_enabled = 1;
1018 ha->fce_dma = tc_dma;
1021 /* Allocate memory for Extended Trace Buffer. */
1022 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
1025 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1026 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
1030 memset(tc, 0, EFT_SIZE);
1031 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
1033 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1034 "EFT (%d).\n", rval);
1035 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1040 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
1043 eft_size = EFT_SIZE;
1044 ha->eft_dma = tc_dma;
1048 req_q_size = req->length * sizeof(request_t);
1049 rsp_q_size = rsp->length * sizeof(response_t);
1051 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
1052 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
1053 ha->chain_offset = dump_size;
1054 dump_size += mq_size + fce_size;
1056 ha->fw_dump = vmalloc(dump_size);
1058 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
1059 "firmware dump!!!\n", dump_size / 1024);
1062 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1069 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
1072 ha->fw_dump_len = dump_size;
1073 ha->fw_dump->signature[0] = 'Q';
1074 ha->fw_dump->signature[1] = 'L';
1075 ha->fw_dump->signature[2] = 'G';
1076 ha->fw_dump->signature[3] = 'C';
1077 ha->fw_dump->version = __constant_htonl(1);
1079 ha->fw_dump->fixed_size = htonl(fixed_size);
1080 ha->fw_dump->mem_size = htonl(mem_size);
1081 ha->fw_dump->req_q_size = htonl(req_q_size);
1082 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1084 ha->fw_dump->eft_size = htonl(eft_size);
1085 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1086 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1088 ha->fw_dump->header_size =
1089 htonl(offsetof(struct qla2xxx_fw_dump, isp));
1093 qla81xx_mpi_sync(scsi_qla_host_t *vha)
1095 #define MPS_MASK 0xe0
1099 struct qla_hw_data *ha = vha->hw;
1101 if (!IS_QLA81XX(vha->hw))
1104 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1105 if (rval != QLA_SUCCESS) {
1106 DEBUG2(qla_printk(KERN_WARNING, ha,
1107 "Sync-MPI: Unable to acquire semaphore.\n"));
1111 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1112 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1113 if (rval != QLA_SUCCESS) {
1114 DEBUG2(qla_printk(KERN_WARNING, ha,
1115 "Sync-MPI: Unable to read sync.\n"));
1120 if (dc == (dw & MPS_MASK))
1125 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1126 if (rval != QLA_SUCCESS) {
1127 DEBUG2(qla_printk(KERN_WARNING, ha,
1128 "Sync-MPI: Unable to gain sync.\n"));
1132 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1133 if (rval != QLA_SUCCESS) {
1134 DEBUG2(qla_printk(KERN_WARNING, ha,
1135 "Sync-MPI: Unable to release semaphore.\n"));
1143 * qla2x00_setup_chip() - Load and start RISC firmware.
1146 * Returns 0 on success.
1149 qla2x00_setup_chip(scsi_qla_host_t *vha)
1152 uint32_t srisc_address = 0;
1153 struct qla_hw_data *ha = vha->hw;
1154 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1155 unsigned long flags;
1156 uint16_t fw_major_version;
1158 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1159 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1160 spin_lock_irqsave(&ha->hardware_lock, flags);
1161 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
1162 RD_REG_WORD(®->hccr);
1163 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1166 qla81xx_mpi_sync(vha);
1168 /* Load firmware sequences */
1169 rval = ha->isp_ops->load_risc(vha, &srisc_address);
1170 if (rval == QLA_SUCCESS) {
1171 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
1172 "code.\n", vha->host_no));
1174 rval = qla2x00_verify_checksum(vha, srisc_address);
1175 if (rval == QLA_SUCCESS) {
1176 /* Start firmware execution. */
1177 DEBUG(printk("scsi(%ld): Checksum OK, start "
1178 "firmware.\n", vha->host_no));
1180 rval = qla2x00_execute_fw(vha, srisc_address);
1181 /* Retrieve firmware information. */
1182 if (rval == QLA_SUCCESS) {
1183 fw_major_version = ha->fw_major_version;
1184 rval = qla2x00_get_fw_version(vha,
1185 &ha->fw_major_version,
1186 &ha->fw_minor_version,
1187 &ha->fw_subminor_version,
1188 &ha->fw_attributes, &ha->fw_memory_size,
1189 ha->mpi_version, &ha->mpi_capabilities,
1191 if (rval != QLA_SUCCESS)
1193 ha->flags.npiv_supported = 0;
1194 if (IS_QLA2XXX_MIDTYPE(ha) &&
1195 (ha->fw_attributes & BIT_2)) {
1196 ha->flags.npiv_supported = 1;
1197 if ((!ha->max_npiv_vports) ||
1198 ((ha->max_npiv_vports + 1) %
1199 MIN_MULTI_ID_FABRIC))
1200 ha->max_npiv_vports =
1201 MIN_MULTI_ID_FABRIC - 1;
1203 qla2x00_get_resource_cnts(vha, NULL,
1204 &ha->fw_xcb_count, NULL, NULL,
1205 &ha->max_npiv_vports, NULL);
1207 if (!fw_major_version && ql2xallocfwdump)
1208 qla2x00_alloc_fw_dump(vha);
1211 DEBUG2(printk(KERN_INFO
1212 "scsi(%ld): ISP Firmware failed checksum.\n",
1217 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1218 /* Enable proper parity. */
1219 spin_lock_irqsave(&ha->hardware_lock, flags);
1222 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
1224 /* SRAM, Instruction RAM and GP RAM parity */
1225 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
1226 RD_REG_WORD(®->hccr);
1227 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1230 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1233 rval = qla81xx_fac_get_sector_size(vha, &size);
1234 if (rval == QLA_SUCCESS) {
1235 ha->flags.fac_supported = 1;
1236 ha->fdt_block_size = size << 2;
1238 qla_printk(KERN_ERR, ha,
1239 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1240 ha->fw_major_version, ha->fw_minor_version,
1241 ha->fw_subminor_version);
1246 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
1254 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1257 * Beginning of request ring has initialization control block already built
1258 * by nvram config routine.
1260 * Returns 0 on success.
1263 qla2x00_init_response_q_entries(struct rsp_que *rsp)
1268 rsp->ring_ptr = rsp->ring;
1269 rsp->ring_index = 0;
1270 rsp->status_srb = NULL;
1271 pkt = rsp->ring_ptr;
1272 for (cnt = 0; cnt < rsp->length; cnt++) {
1273 pkt->signature = RESPONSE_PROCESSED;
1279 * qla2x00_update_fw_options() - Read and process firmware options.
1282 * Returns 0 on success.
1285 qla2x00_update_fw_options(scsi_qla_host_t *vha)
1287 uint16_t swing, emphasis, tx_sens, rx_sens;
1288 struct qla_hw_data *ha = vha->hw;
1290 memset(ha->fw_options, 0, sizeof(ha->fw_options));
1291 qla2x00_get_fw_options(vha, ha->fw_options);
1293 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1296 /* Serial Link options. */
1297 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1299 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1300 sizeof(ha->fw_seriallink_options)));
1302 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1303 if (ha->fw_seriallink_options[3] & BIT_2) {
1304 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1307 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1308 emphasis = (ha->fw_seriallink_options[2] &
1309 (BIT_4 | BIT_3)) >> 3;
1310 tx_sens = ha->fw_seriallink_options[0] &
1311 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1312 rx_sens = (ha->fw_seriallink_options[0] &
1313 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1314 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1315 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1318 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1319 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1320 ha->fw_options[10] |= BIT_5 |
1321 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1322 (tx_sens & (BIT_1 | BIT_0));
1325 swing = (ha->fw_seriallink_options[2] &
1326 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1327 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1328 tx_sens = ha->fw_seriallink_options[1] &
1329 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1330 rx_sens = (ha->fw_seriallink_options[1] &
1331 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1332 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1333 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1336 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1337 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1338 ha->fw_options[11] |= BIT_5 |
1339 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1340 (tx_sens & (BIT_1 | BIT_0));
1344 /* Return command IOCBs without waiting for an ABTS to complete. */
1345 ha->fw_options[3] |= BIT_13;
1348 if (ha->flags.enable_led_scheme)
1349 ha->fw_options[2] |= BIT_12;
1351 /* Detect ISP6312. */
1353 ha->fw_options[2] |= BIT_13;
1355 /* Update firmware options. */
1356 qla2x00_set_fw_options(vha, ha->fw_options);
1360 qla24xx_update_fw_options(scsi_qla_host_t *vha)
1363 struct qla_hw_data *ha = vha->hw;
1365 /* Update Serial Link options. */
1366 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1369 rval = qla2x00_set_serdes_params(vha,
1370 le16_to_cpu(ha->fw_seriallink_options24[1]),
1371 le16_to_cpu(ha->fw_seriallink_options24[2]),
1372 le16_to_cpu(ha->fw_seriallink_options24[3]));
1373 if (rval != QLA_SUCCESS) {
1374 qla_printk(KERN_WARNING, ha,
1375 "Unable to update Serial Link options (%x).\n", rval);
1380 qla2x00_config_rings(struct scsi_qla_host *vha)
1382 struct qla_hw_data *ha = vha->hw;
1383 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1384 struct req_que *req = ha->req_q_map[0];
1385 struct rsp_que *rsp = ha->rsp_q_map[0];
1387 /* Setup ring parameters in initialization control block. */
1388 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1389 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1390 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1391 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1392 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1393 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1394 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1395 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
1397 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1398 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1399 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1400 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1401 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1405 qla24xx_config_rings(struct scsi_qla_host *vha)
1407 struct qla_hw_data *ha = vha->hw;
1408 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1409 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1410 struct qla_msix_entry *msix;
1411 struct init_cb_24xx *icb;
1413 struct req_que *req = ha->req_q_map[0];
1414 struct rsp_que *rsp = ha->rsp_q_map[0];
1416 /* Setup ring parameters in initialization control block. */
1417 icb = (struct init_cb_24xx *)ha->init_cb;
1418 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1419 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1420 icb->request_q_length = cpu_to_le16(req->length);
1421 icb->response_q_length = cpu_to_le16(rsp->length);
1422 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1423 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1424 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1425 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
1428 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1429 icb->rid = __constant_cpu_to_le16(rid);
1430 if (ha->flags.msix_enabled) {
1431 msix = &ha->msix_entries[1];
1432 DEBUG2_17(printk(KERN_INFO
1433 "Registering vector 0x%x for base que\n", msix->entry));
1434 icb->msix = cpu_to_le16(msix->entry);
1436 /* Use alternate PCI bus number */
1438 icb->firmware_options_2 |=
1439 __constant_cpu_to_le32(BIT_19);
1440 /* Use alternate PCI devfn */
1442 icb->firmware_options_2 |=
1443 __constant_cpu_to_le32(BIT_18);
1445 /* Use Disable MSIX Handshake mode for capable adapters */
1446 if (IS_MSIX_NACK_CAPABLE(ha)) {
1447 icb->firmware_options_2 &=
1448 __constant_cpu_to_le32(~BIT_22);
1449 ha->flags.disable_msix_handshake = 1;
1450 qla_printk(KERN_INFO, ha,
1451 "MSIX Handshake Disable Mode turned on\n");
1453 icb->firmware_options_2 |=
1454 __constant_cpu_to_le32(BIT_22);
1456 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
1458 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
1459 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
1460 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
1461 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
1463 WRT_REG_DWORD(®->isp24.req_q_in, 0);
1464 WRT_REG_DWORD(®->isp24.req_q_out, 0);
1465 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
1466 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
1469 RD_REG_DWORD(&ioreg->hccr);
1473 * qla2x00_init_rings() - Initializes firmware.
1476 * Beginning of request ring has initialization control block already built
1477 * by nvram config routine.
1479 * Returns 0 on success.
1482 qla2x00_init_rings(scsi_qla_host_t *vha)
1485 unsigned long flags = 0;
1487 struct qla_hw_data *ha = vha->hw;
1488 struct req_que *req;
1489 struct rsp_que *rsp;
1490 struct scsi_qla_host *vp;
1491 struct mid_init_cb_24xx *mid_init_cb =
1492 (struct mid_init_cb_24xx *) ha->init_cb;
1494 spin_lock_irqsave(&ha->hardware_lock, flags);
1496 /* Clear outstanding commands array. */
1497 for (que = 0; que < ha->max_req_queues; que++) {
1498 req = ha->req_q_map[que];
1501 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1502 req->outstanding_cmds[cnt] = NULL;
1504 req->current_outstanding_cmd = 1;
1506 /* Initialize firmware. */
1507 req->ring_ptr = req->ring;
1508 req->ring_index = 0;
1509 req->cnt = req->length;
1512 for (que = 0; que < ha->max_rsp_queues; que++) {
1513 rsp = ha->rsp_q_map[que];
1516 /* Initialize response queue entries */
1517 qla2x00_init_response_q_entries(rsp);
1520 /* Clear RSCN queue. */
1521 list_for_each_entry(vp, &ha->vp_list, list) {
1522 vp->rscn_in_ptr = 0;
1523 vp->rscn_out_ptr = 0;
1525 ha->isp_ops->config_rings(vha);
1527 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1529 /* Update any ISP specific firmware options before initialization. */
1530 ha->isp_ops->update_fw_options(vha);
1532 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
1534 if (ha->flags.npiv_supported) {
1535 if (ha->operating_mode == LOOP)
1536 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
1537 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1540 if (IS_FWI2_CAPABLE(ha)) {
1541 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1542 mid_init_cb->init_cb.execution_throttle =
1543 cpu_to_le16(ha->fw_xcb_count);
1546 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
1548 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1551 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1559 * qla2x00_fw_ready() - Waits for firmware ready.
1562 * Returns 0 on success.
1565 qla2x00_fw_ready(scsi_qla_host_t *vha)
1568 unsigned long wtime, mtime, cs84xx_time;
1569 uint16_t min_wait; /* Minimum wait time if loop is down */
1570 uint16_t wait_time; /* Wait time if loop is coming ready */
1572 struct qla_hw_data *ha = vha->hw;
1576 /* 20 seconds for loop down. */
1580 * Firmware should take at most one RATOV to login, plus 5 seconds for
1581 * our own processing.
1583 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1584 wait_time = min_wait;
1587 /* Min wait time if loop down */
1588 mtime = jiffies + (min_wait * HZ);
1590 /* wait time before firmware ready */
1591 wtime = jiffies + (wait_time * HZ);
1593 /* Wait for ISP to finish LIP */
1594 if (!vha->flags.init_done)
1595 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1597 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1601 rval = qla2x00_get_firmware_state(vha, state);
1602 if (rval == QLA_SUCCESS) {
1603 if (state[0] < FSTATE_LOSS_OF_SYNC) {
1604 vha->device_flags &= ~DFLG_NO_CABLE;
1606 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1607 DEBUG16(printk("scsi(%ld): fw_state=%x "
1608 "84xx=%x.\n", vha->host_no, state[0],
1610 if ((state[2] & FSTATE_LOGGED_IN) &&
1611 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1612 DEBUG16(printk("scsi(%ld): Sending "
1613 "verify iocb.\n", vha->host_no));
1615 cs84xx_time = jiffies;
1616 rval = qla84xx_init_chip(vha);
1617 if (rval != QLA_SUCCESS)
1620 /* Add time taken to initialize. */
1621 cs84xx_time = jiffies - cs84xx_time;
1622 wtime += cs84xx_time;
1623 mtime += cs84xx_time;
1624 DEBUG16(printk("scsi(%ld): Increasing "
1625 "wait time by %ld. New time %ld\n",
1626 vha->host_no, cs84xx_time, wtime));
1628 } else if (state[0] == FSTATE_READY) {
1629 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1632 qla2x00_get_retry_cnt(vha, &ha->retry_count,
1633 &ha->login_timeout, &ha->r_a_tov);
1639 rval = QLA_FUNCTION_FAILED;
1641 if (atomic_read(&vha->loop_down_timer) &&
1642 state[0] != FSTATE_READY) {
1643 /* Loop down. Timeout on min_wait for states
1644 * other than Wait for Login.
1646 if (time_after_eq(jiffies, mtime)) {
1647 qla_printk(KERN_INFO, ha,
1648 "Cable is unplugged...\n");
1650 vha->device_flags |= DFLG_NO_CABLE;
1655 /* Mailbox cmd failed. Timeout on min_wait. */
1656 if (time_after_eq(jiffies, mtime))
1660 if (time_after_eq(jiffies, wtime))
1663 /* Delay for a while */
1666 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1667 vha->host_no, state[0], jiffies));
1670 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1671 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1675 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1683 * qla2x00_configure_hba
1684 * Setup adapter context.
1687 * ha = adapter state pointer.
1696 qla2x00_configure_hba(scsi_qla_host_t *vha)
1705 char connect_type[22];
1706 struct qla_hw_data *ha = vha->hw;
1708 /* Get host addresses. */
1709 rval = qla2x00_get_adapter_id(vha,
1710 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
1711 if (rval != QLA_SUCCESS) {
1712 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
1713 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1714 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1715 __func__, vha->host_no));
1717 qla_printk(KERN_WARNING, ha,
1718 "ERROR -- Unable to get host loop ID.\n");
1719 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1725 qla_printk(KERN_INFO, ha,
1726 "Cannot get topology - retrying.\n");
1727 return (QLA_FUNCTION_FAILED);
1730 vha->loop_id = loop_id;
1733 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1734 ha->operating_mode = LOOP;
1739 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1741 ha->current_topology = ISP_CFG_NL;
1742 strcpy(connect_type, "(Loop)");
1746 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1748 ha->switch_cap = sw_cap;
1749 ha->current_topology = ISP_CFG_FL;
1750 strcpy(connect_type, "(FL_Port)");
1754 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1756 ha->operating_mode = P2P;
1757 ha->current_topology = ISP_CFG_N;
1758 strcpy(connect_type, "(N_Port-to-N_Port)");
1762 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1764 ha->switch_cap = sw_cap;
1765 ha->operating_mode = P2P;
1766 ha->current_topology = ISP_CFG_F;
1767 strcpy(connect_type, "(F_Port)");
1771 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1773 vha->host_no, topo));
1774 ha->current_topology = ISP_CFG_NL;
1775 strcpy(connect_type, "(Loop)");
1779 /* Save Host port and loop ID. */
1780 /* byte order - Big Endian */
1781 vha->d_id.b.domain = domain;
1782 vha->d_id.b.area = area;
1783 vha->d_id.b.al_pa = al_pa;
1785 if (!vha->flags.init_done)
1786 qla_printk(KERN_INFO, ha,
1787 "Topology - %s, Host Loop address 0x%x\n",
1788 connect_type, vha->loop_id);
1791 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
1793 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
1800 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1805 struct qla_hw_data *ha = vha->hw;
1806 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
1809 if (memcmp(model, BINZERO, len) != 0) {
1810 strncpy(ha->model_number, model, len);
1811 st = en = ha->model_number;
1814 if (*en != 0x20 && *en != 0x00)
1819 index = (ha->pdev->subsystem_device & 0xff);
1821 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1822 index < QLA_MODEL_NAMES)
1823 strncpy(ha->model_desc,
1824 qla2x00_model_name[index * 2 + 1],
1825 sizeof(ha->model_desc) - 1);
1827 index = (ha->pdev->subsystem_device & 0xff);
1829 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1830 index < QLA_MODEL_NAMES) {
1831 strcpy(ha->model_number,
1832 qla2x00_model_name[index * 2]);
1833 strncpy(ha->model_desc,
1834 qla2x00_model_name[index * 2 + 1],
1835 sizeof(ha->model_desc) - 1);
1837 strcpy(ha->model_number, def);
1840 if (IS_FWI2_CAPABLE(ha))
1841 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
1842 sizeof(ha->model_desc));
1845 /* On sparc systems, obtain port and node WWN from firmware
1848 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
1851 struct qla_hw_data *ha = vha->hw;
1852 struct pci_dev *pdev = ha->pdev;
1853 struct device_node *dp = pci_device_to_OF_node(pdev);
1857 val = of_get_property(dp, "port-wwn", &len);
1858 if (val && len >= WWN_SIZE)
1859 memcpy(nv->port_name, val, WWN_SIZE);
1861 val = of_get_property(dp, "node-wwn", &len);
1862 if (val && len >= WWN_SIZE)
1863 memcpy(nv->node_name, val, WWN_SIZE);
1868 * NVRAM configuration for ISP 2xxx
1871 * ha = adapter block pointer.
1874 * initialization control block in response_ring
1875 * host adapters parameters in host adapter block
1881 qla2x00_nvram_config(scsi_qla_host_t *vha)
1886 uint8_t *dptr1, *dptr2;
1887 struct qla_hw_data *ha = vha->hw;
1888 init_cb_t *icb = ha->init_cb;
1889 nvram_t *nv = ha->nvram;
1890 uint8_t *ptr = ha->nvram;
1891 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1895 /* Determine NVRAM starting address. */
1896 ha->nvram_size = sizeof(nvram_t);
1898 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1899 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
1900 ha->nvram_base = 0x80;
1902 /* Get NVRAM data and calculate checksum. */
1903 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
1904 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1907 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
1908 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
1910 /* Bad NVRAM data, set defaults parameters. */
1911 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1912 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1913 /* Reset NVRAM data. */
1914 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1915 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1917 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1918 "invalid -- WWPN) defaults.\n");
1921 * Set default initialization control block.
1923 memset(nv, 0, ha->nvram_size);
1924 nv->parameter_block_version = ICB_VERSION;
1926 if (IS_QLA23XX(ha)) {
1927 nv->firmware_options[0] = BIT_2 | BIT_1;
1928 nv->firmware_options[1] = BIT_7 | BIT_5;
1929 nv->add_firmware_options[0] = BIT_5;
1930 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1931 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1932 nv->special_options[1] = BIT_7;
1933 } else if (IS_QLA2200(ha)) {
1934 nv->firmware_options[0] = BIT_2 | BIT_1;
1935 nv->firmware_options[1] = BIT_7 | BIT_5;
1936 nv->add_firmware_options[0] = BIT_5;
1937 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1938 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1939 } else if (IS_QLA2100(ha)) {
1940 nv->firmware_options[0] = BIT_3 | BIT_1;
1941 nv->firmware_options[1] = BIT_5;
1942 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1945 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1946 nv->execution_throttle = __constant_cpu_to_le16(16);
1947 nv->retry_count = 8;
1948 nv->retry_delay = 1;
1950 nv->port_name[0] = 33;
1951 nv->port_name[3] = 224;
1952 nv->port_name[4] = 139;
1954 qla2xxx_nvram_wwn_from_ofw(vha, nv);
1956 nv->login_timeout = 4;
1959 * Set default host adapter parameters
1961 nv->host_p[1] = BIT_2;
1962 nv->reset_delay = 5;
1963 nv->port_down_retry_count = 8;
1964 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1965 nv->link_down_timeout = 60;
1970 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1972 * The SN2 does not provide BIOS emulation which means you can't change
1973 * potentially bogus BIOS settings. Force the use of default settings
1974 * for link rate and frame size. Hope that the rest of the settings
1977 if (ia64_platform_is("sn2")) {
1978 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1980 nv->special_options[1] = BIT_7;
1984 /* Reset Initialization control block */
1985 memset(icb, 0, ha->init_cb_size);
1988 * Setup driver NVRAM options.
1990 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1991 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1992 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1993 nv->firmware_options[1] &= ~BIT_4;
1995 if (IS_QLA23XX(ha)) {
1996 nv->firmware_options[0] |= BIT_2;
1997 nv->firmware_options[0] &= ~BIT_3;
1998 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
2000 if (IS_QLA2300(ha)) {
2001 if (ha->fb_rev == FPM_2310) {
2002 strcpy(ha->model_number, "QLA2310");
2004 strcpy(ha->model_number, "QLA2300");
2007 qla2x00_set_model_info(vha, nv->model_number,
2008 sizeof(nv->model_number), "QLA23xx");
2010 } else if (IS_QLA2200(ha)) {
2011 nv->firmware_options[0] |= BIT_2;
2013 * 'Point-to-point preferred, else loop' is not a safe
2014 * connection mode setting.
2016 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2018 /* Force 'loop preferred, else point-to-point'. */
2019 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2020 nv->add_firmware_options[0] |= BIT_5;
2022 strcpy(ha->model_number, "QLA22xx");
2023 } else /*if (IS_QLA2100(ha))*/ {
2024 strcpy(ha->model_number, "QLA2100");
2028 * Copy over NVRAM RISC parameter block to initialization control block.
2030 dptr1 = (uint8_t *)icb;
2031 dptr2 = (uint8_t *)&nv->parameter_block_version;
2032 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2034 *dptr1++ = *dptr2++;
2036 /* Copy 2nd half. */
2037 dptr1 = (uint8_t *)icb->add_firmware_options;
2038 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2040 *dptr1++ = *dptr2++;
2042 /* Use alternate WWN? */
2043 if (nv->host_p[1] & BIT_7) {
2044 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2045 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2048 /* Prepare nodename */
2049 if ((icb->firmware_options[1] & BIT_6) == 0) {
2051 * Firmware will apply the following mask if the nodename was
2054 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2055 icb->node_name[0] &= 0xF0;
2059 * Set host adapter parameters.
2061 if (nv->host_p[0] & BIT_7)
2062 ql2xextended_error_logging = 1;
2063 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2064 /* Always load RISC code on non ISP2[12]00 chips. */
2065 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2066 ha->flags.disable_risc_code_load = 0;
2067 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2068 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2069 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
2070 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
2071 ha->flags.disable_serdes = 0;
2073 ha->operating_mode =
2074 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2076 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2077 sizeof(ha->fw_seriallink_options));
2079 /* save HBA serial number */
2080 ha->serial0 = icb->port_name[5];
2081 ha->serial1 = icb->port_name[6];
2082 ha->serial2 = icb->port_name[7];
2083 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2084 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
2086 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2088 ha->retry_count = nv->retry_count;
2090 /* Set minimum login_timeout to 4 seconds. */
2091 if (nv->login_timeout < ql2xlogintimeout)
2092 nv->login_timeout = ql2xlogintimeout;
2093 if (nv->login_timeout < 4)
2094 nv->login_timeout = 4;
2095 ha->login_timeout = nv->login_timeout;
2096 icb->login_timeout = nv->login_timeout;
2098 /* Set minimum RATOV to 100 tenths of a second. */
2101 ha->loop_reset_delay = nv->reset_delay;
2103 /* Link Down Timeout = 0:
2105 * When Port Down timer expires we will start returning
2106 * I/O's to OS with "DID_NO_CONNECT".
2108 * Link Down Timeout != 0:
2110 * The driver waits for the link to come up after link down
2111 * before returning I/Os to OS with "DID_NO_CONNECT".
2113 if (nv->link_down_timeout == 0) {
2114 ha->loop_down_abort_time =
2115 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
2117 ha->link_down_timeout = nv->link_down_timeout;
2118 ha->loop_down_abort_time =
2119 (LOOP_DOWN_TIME - ha->link_down_timeout);
2123 * Need enough time to try and get the port back.
2125 ha->port_down_retry_count = nv->port_down_retry_count;
2126 if (qlport_down_retry)
2127 ha->port_down_retry_count = qlport_down_retry;
2128 /* Set login_retry_count */
2129 ha->login_retry_count = nv->retry_count;
2130 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2131 ha->port_down_retry_count > 3)
2132 ha->login_retry_count = ha->port_down_retry_count;
2133 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2134 ha->login_retry_count = ha->port_down_retry_count;
2135 if (ql2xloginretrycount)
2136 ha->login_retry_count = ql2xloginretrycount;
2138 icb->lun_enables = __constant_cpu_to_le16(0);
2139 icb->command_resource_count = 0;
2140 icb->immediate_notify_resource_count = 0;
2141 icb->timeout = __constant_cpu_to_le16(0);
2143 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2145 icb->firmware_options[0] &= ~BIT_3;
2146 icb->add_firmware_options[0] &=
2147 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2148 icb->add_firmware_options[0] |= BIT_2;
2149 icb->response_accumulation_timer = 3;
2150 icb->interrupt_delay_timer = 5;
2152 vha->flags.process_response_queue = 1;
2155 if (!vha->flags.init_done) {
2156 ha->zio_mode = icb->add_firmware_options[0] &
2157 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2158 ha->zio_timer = icb->interrupt_delay_timer ?
2159 icb->interrupt_delay_timer: 2;
2161 icb->add_firmware_options[0] &=
2162 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2163 vha->flags.process_response_queue = 0;
2164 if (ha->zio_mode != QLA_ZIO_DISABLED) {
2165 ha->zio_mode = QLA_ZIO_MODE_6;
2167 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
2168 "delay (%d us).\n", vha->host_no, ha->zio_mode,
2169 ha->zio_timer * 100));
2170 qla_printk(KERN_INFO, ha,
2171 "ZIO mode %d enabled; timer delay (%d us).\n",
2172 ha->zio_mode, ha->zio_timer * 100);
2174 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2175 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
2176 vha->flags.process_response_queue = 1;
2181 DEBUG2_3(printk(KERN_WARNING
2182 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
2188 qla2x00_rport_del(void *data)
2190 fc_port_t *fcport = data;
2191 struct fc_rport *rport;
2193 spin_lock_irq(fcport->vha->host->host_lock);
2194 rport = fcport->drport ? fcport->drport: fcport->rport;
2195 fcport->drport = NULL;
2196 spin_unlock_irq(fcport->vha->host->host_lock);
2198 fc_remote_port_delete(rport);
2202 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2204 * @flags: allocation flags
2206 * Returns a pointer to the allocated fcport, or NULL, if none available.
2209 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
2213 fcport = kzalloc(sizeof(fc_port_t), flags);
2217 /* Setup fcport template structure. */
2219 fcport->vp_idx = vha->vp_idx;
2220 fcport->port_type = FCT_UNKNOWN;
2221 fcport->loop_id = FC_NO_LOOP_ID;
2222 atomic_set(&fcport->state, FCS_UNCONFIGURED);
2223 fcport->supported_classes = FC_COS_UNSPECIFIED;
2229 * qla2x00_configure_loop
2230 * Updates Fibre Channel Device Database with what is actually on loop.
2233 * ha = adapter block pointer.
2238 * 2 = database was full and device was not configured.
2241 qla2x00_configure_loop(scsi_qla_host_t *vha)
2244 unsigned long flags, save_flags;
2245 struct qla_hw_data *ha = vha->hw;
2248 /* Get Initiator ID */
2249 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2250 rval = qla2x00_configure_hba(vha);
2251 if (rval != QLA_SUCCESS) {
2252 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
2258 save_flags = flags = vha->dpc_flags;
2259 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
2260 vha->host_no, flags));
2263 * If we have both an RSCN and PORT UPDATE pending then handle them
2264 * both at the same time.
2266 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2267 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
2269 qla2x00_get_data_rate(vha);
2271 /* Determine what we need to do */
2272 if (ha->current_topology == ISP_CFG_FL &&
2273 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2275 vha->flags.rscn_queue_overflow = 1;
2276 set_bit(RSCN_UPDATE, &flags);
2278 } else if (ha->current_topology == ISP_CFG_F &&
2279 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2281 vha->flags.rscn_queue_overflow = 1;
2282 set_bit(RSCN_UPDATE, &flags);
2283 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2285 } else if (ha->current_topology == ISP_CFG_N) {
2286 clear_bit(RSCN_UPDATE, &flags);
2288 } else if (!vha->flags.online ||
2289 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2291 vha->flags.rscn_queue_overflow = 1;
2292 set_bit(RSCN_UPDATE, &flags);
2293 set_bit(LOCAL_LOOP_UPDATE, &flags);
2296 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
2297 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2298 rval = QLA_FUNCTION_FAILED;
2300 rval = qla2x00_configure_local_loop(vha);
2303 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
2304 if (LOOP_TRANSITION(vha))
2305 rval = QLA_FUNCTION_FAILED;
2307 rval = qla2x00_configure_fabric(vha);
2310 if (rval == QLA_SUCCESS) {
2311 if (atomic_read(&vha->loop_down_timer) ||
2312 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2313 rval = QLA_FUNCTION_FAILED;
2315 atomic_set(&vha->loop_state, LOOP_READY);
2317 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
2322 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
2323 __func__, vha->host_no));
2325 DEBUG3(printk("%s: exiting normally\n", __func__));
2328 /* Restore state if a resync event occurred during processing */
2329 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2330 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
2331 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2332 if (test_bit(RSCN_UPDATE, &save_flags)) {
2333 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2334 vha->flags.rscn_queue_overflow = 1;
2344 * qla2x00_configure_local_loop
2345 * Updates Fibre Channel Device Database with local loop devices.
2348 * ha = adapter block pointer.
2354 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
2359 fc_port_t *fcport, *new_fcport;
2365 uint8_t domain, area, al_pa;
2366 struct qla_hw_data *ha = vha->hw;
2370 entries = MAX_FIBRE_DEVICES;
2372 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2373 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
2375 /* Get list of logged in devices. */
2376 memset(ha->gid_list, 0, GID_LIST_SIZE);
2377 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
2379 if (rval != QLA_SUCCESS)
2380 goto cleanup_allocation;
2382 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2383 vha->host_no, entries));
2384 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2385 entries * sizeof(struct gid_list_info)));
2387 /* Allocate temporary fcport for any new fcports discovered. */
2388 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2389 if (new_fcport == NULL) {
2390 rval = QLA_MEMORY_ALLOC_FAILED;
2391 goto cleanup_allocation;
2393 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2396 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2398 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2399 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2400 fcport->port_type != FCT_BROADCAST &&
2401 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2403 DEBUG(printk("scsi(%ld): Marking port lost, "
2405 vha->host_no, fcport->loop_id));
2407 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2411 /* Add devices to port list. */
2412 id_iter = (char *)ha->gid_list;
2413 for (index = 0; index < entries; index++) {
2414 domain = ((struct gid_list_info *)id_iter)->domain;
2415 area = ((struct gid_list_info *)id_iter)->area;
2416 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
2417 if (IS_QLA2100(ha) || IS_QLA2200(ha))
2418 loop_id = (uint16_t)
2419 ((struct gid_list_info *)id_iter)->loop_id_2100;
2421 loop_id = le16_to_cpu(
2422 ((struct gid_list_info *)id_iter)->loop_id);
2423 id_iter += ha->gid_list_info_size;
2425 /* Bypass reserved domain fields. */
2426 if ((domain & 0xf0) == 0xf0)
2429 /* Bypass if not same domain and area of adapter. */
2430 if (area && domain &&
2431 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
2434 /* Bypass invalid local loop ID. */
2435 if (loop_id > LAST_LOCAL_LOOP_ID)
2438 /* Fill in member data. */
2439 new_fcport->d_id.b.domain = domain;
2440 new_fcport->d_id.b.area = area;
2441 new_fcport->d_id.b.al_pa = al_pa;
2442 new_fcport->loop_id = loop_id;
2443 new_fcport->vp_idx = vha->vp_idx;
2444 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
2445 if (rval2 != QLA_SUCCESS) {
2446 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2447 "information -- get_port_database=%x, "
2449 vha->host_no, rval2, new_fcport->loop_id));
2450 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2452 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2456 /* Check for matching device in port list. */
2459 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2460 if (memcmp(new_fcport->port_name, fcport->port_name,
2464 fcport->flags &= ~FCF_FABRIC_DEVICE;
2465 fcport->loop_id = new_fcport->loop_id;
2466 fcport->port_type = new_fcport->port_type;
2467 fcport->d_id.b24 = new_fcport->d_id.b24;
2468 memcpy(fcport->node_name, new_fcport->node_name,
2476 /* New device, add to fcports list. */
2478 new_fcport->vha = vha;
2479 new_fcport->vp_idx = vha->vp_idx;
2481 list_add_tail(&new_fcport->list, &vha->vp_fcports);
2483 /* Allocate a new replacement fcport. */
2484 fcport = new_fcport;
2485 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2486 if (new_fcport == NULL) {
2487 rval = QLA_MEMORY_ALLOC_FAILED;
2488 goto cleanup_allocation;
2490 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2493 /* Base iIDMA settings on HBA port speed. */
2494 fcport->fp_speed = ha->link_data_rate;
2496 qla2x00_update_fcport(vha, fcport);
2504 if (rval != QLA_SUCCESS) {
2505 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2506 "rval=%x\n", vha->host_no, rval));
2513 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
2515 #define LS_UNKNOWN 2
2516 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2520 struct qla_hw_data *ha = vha->hw;
2522 if (!IS_IIDMA_CAPABLE(ha))
2525 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2526 fcport->fp_speed > ha->link_data_rate)
2529 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
2531 if (rval != QLA_SUCCESS) {
2532 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2533 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2534 vha->host_no, fcport->port_name[0], fcport->port_name[1],
2535 fcport->port_name[2], fcport->port_name[3],
2536 fcport->port_name[4], fcport->port_name[5],
2537 fcport->port_name[6], fcport->port_name[7], rval,
2538 fcport->fp_speed, mb[0], mb[1]));
2540 link_speed = link_speeds[LS_UNKNOWN];
2541 if (fcport->fp_speed < 5)
2542 link_speed = link_speeds[fcport->fp_speed];
2543 else if (fcport->fp_speed == 0x13)
2544 link_speed = link_speeds[5];
2545 DEBUG2(qla_printk(KERN_INFO, ha,
2546 "iIDMA adjusted to %s GB/s on "
2547 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2548 link_speed, fcport->port_name[0],
2549 fcport->port_name[1], fcport->port_name[2],
2550 fcport->port_name[3], fcport->port_name[4],
2551 fcport->port_name[5], fcport->port_name[6],
2552 fcport->port_name[7]));
2557 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
2559 struct fc_rport_identifiers rport_ids;
2560 struct fc_rport *rport;
2561 struct qla_hw_data *ha = vha->hw;
2563 qla2x00_rport_del(fcport);
2565 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2566 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2567 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2568 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2569 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2570 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
2572 qla_printk(KERN_WARNING, ha,
2573 "Unable to allocate fc remote port!\n");
2576 spin_lock_irq(fcport->vha->host->host_lock);
2577 *((fc_port_t **)rport->dd_data) = fcport;
2578 spin_unlock_irq(fcport->vha->host->host_lock);
2580 rport->supported_classes = fcport->supported_classes;
2582 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2583 if (fcport->port_type == FCT_INITIATOR)
2584 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2585 if (fcport->port_type == FCT_TARGET)
2586 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2587 fc_remote_port_rolechg(rport, rport_ids.roles);
2591 * qla2x00_update_fcport
2592 * Updates device on list.
2595 * ha = adapter block pointer.
2596 * fcport = port structure pointer.
2606 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
2608 struct qla_hw_data *ha = vha->hw;
2611 fcport->login_retry = 0;
2612 fcport->port_login_retry_count = ha->port_down_retry_count *
2614 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2616 fcport->flags &= ~FCF_LOGIN_NEEDED;
2618 qla2x00_iidma_fcport(vha, fcport);
2620 atomic_set(&fcport->state, FCS_ONLINE);
2622 qla2x00_reg_remote_port(vha, fcport);
2626 * qla2x00_configure_fabric
2627 * Setup SNS devices with loop ID's.
2630 * ha = adapter block pointer.
2637 qla2x00_configure_fabric(scsi_qla_host_t *vha)
2640 fc_port_t *fcport, *fcptemp;
2641 uint16_t next_loopid;
2642 uint16_t mb[MAILBOX_REGISTER_COUNT];
2644 LIST_HEAD(new_fcports);
2645 struct qla_hw_data *ha = vha->hw;
2646 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2648 /* If FL port exists, then SNS is present */
2649 if (IS_FWI2_CAPABLE(ha))
2650 loop_id = NPH_F_PORT;
2652 loop_id = SNS_FL_PORT;
2653 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
2654 if (rval != QLA_SUCCESS) {
2655 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2656 "Port\n", vha->host_no));
2658 vha->device_flags &= ~SWITCH_FOUND;
2659 return (QLA_SUCCESS);
2661 vha->device_flags |= SWITCH_FOUND;
2663 /* Mark devices that need re-synchronization. */
2664 rval2 = qla2x00_device_resync(vha);
2665 if (rval2 == QLA_RSCNS_HANDLED) {
2666 /* No point doing the scan, just continue. */
2667 return (QLA_SUCCESS);
2671 if (ql2xfdmienable &&
2672 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2673 qla2x00_fdmi_register(vha);
2675 /* Ensure we are logged into the SNS. */
2676 if (IS_FWI2_CAPABLE(ha))
2679 loop_id = SIMPLE_NAME_SERVER;
2680 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
2681 0xfc, mb, BIT_1 | BIT_0);
2682 if (mb[0] != MBS_COMMAND_COMPLETE) {
2683 DEBUG2(qla_printk(KERN_INFO, ha,
2684 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2685 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
2686 mb[0], mb[1], mb[2], mb[6], mb[7]));
2687 return (QLA_SUCCESS);
2690 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2691 if (qla2x00_rft_id(vha)) {
2693 DEBUG2(printk("scsi(%ld): Register FC-4 "
2694 "TYPE failed.\n", vha->host_no));
2696 if (qla2x00_rff_id(vha)) {
2698 DEBUG2(printk("scsi(%ld): Register FC-4 "
2699 "Features failed.\n", vha->host_no));
2701 if (qla2x00_rnn_id(vha)) {
2703 DEBUG2(printk("scsi(%ld): Register Node Name "
2704 "failed.\n", vha->host_no));
2705 } else if (qla2x00_rsnn_nn(vha)) {
2707 DEBUG2(printk("scsi(%ld): Register Symbolic "
2708 "Node Name failed.\n", vha->host_no));
2712 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
2713 if (rval != QLA_SUCCESS)
2717 * Logout all previous fabric devices marked lost, except
2720 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2721 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2724 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2727 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2728 qla2x00_mark_device_lost(vha, fcport,
2729 ql2xplogiabsentdevice, 0);
2730 if (fcport->loop_id != FC_NO_LOOP_ID &&
2731 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2732 fcport->port_type != FCT_INITIATOR &&
2733 fcport->port_type != FCT_BROADCAST) {
2734 ha->isp_ops->fabric_logout(vha,
2736 fcport->d_id.b.domain,
2737 fcport->d_id.b.area,
2738 fcport->d_id.b.al_pa);
2739 fcport->loop_id = FC_NO_LOOP_ID;
2744 /* Starting free loop ID. */
2745 next_loopid = ha->min_external_loopid;
2748 * Scan through our port list and login entries that need to be
2751 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2752 if (atomic_read(&vha->loop_down_timer) ||
2753 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2756 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2757 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2760 if (fcport->loop_id == FC_NO_LOOP_ID) {
2761 fcport->loop_id = next_loopid;
2762 rval = qla2x00_find_new_loop_id(
2764 if (rval != QLA_SUCCESS) {
2765 /* Ran out of IDs to use */
2769 /* Login and update database */
2770 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
2773 /* Exit if out of loop IDs. */
2774 if (rval != QLA_SUCCESS) {
2779 * Login and add the new devices to our port list.
2781 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2782 if (atomic_read(&vha->loop_down_timer) ||
2783 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2786 /* Find a new loop ID to use. */
2787 fcport->loop_id = next_loopid;
2788 rval = qla2x00_find_new_loop_id(base_vha, fcport);
2789 if (rval != QLA_SUCCESS) {
2790 /* Ran out of IDs to use */
2794 /* Login and update database */
2795 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
2799 fcport->vp_idx = vha->vp_idx;
2801 list_move_tail(&fcport->list, &vha->vp_fcports);
2805 /* Free all new device structures not processed. */
2806 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2807 list_del(&fcport->list);
2812 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2813 "rval=%d\n", vha->host_no, rval));
2821 * qla2x00_find_all_fabric_devs
2824 * ha = adapter block pointer.
2825 * dev = database device entry pointer.
2834 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2835 struct list_head *new_fcports)
2839 fc_port_t *fcport, *new_fcport, *fcptemp;
2844 int first_dev, last_dev;
2845 port_id_t wrap, nxt_d_id;
2846 struct qla_hw_data *ha = vha->hw;
2847 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
2848 struct scsi_qla_host *tvp;
2852 /* Try GID_PT to get device list, else GAN. */
2853 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
2856 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2857 "on GA_NXT\n", vha->host_no));
2859 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
2862 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
2865 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
2868 } else if (ql2xiidmaenable &&
2869 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2870 qla2x00_gpsc(vha, swl);
2875 /* Allocate temporary fcport for any new fcports discovered. */
2876 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2877 if (new_fcport == NULL) {
2879 return (QLA_MEMORY_ALLOC_FAILED);
2881 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2882 /* Set start port ID scan at adapter ID. */
2886 /* Starting free loop ID. */
2887 loop_id = ha->min_external_loopid;
2888 for (; loop_id <= ha->max_loop_id; loop_id++) {
2889 if (qla2x00_is_reserved_id(vha, loop_id))
2892 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
2897 wrap.b24 = new_fcport->d_id.b24;
2899 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2900 memcpy(new_fcport->node_name,
2901 swl[swl_idx].node_name, WWN_SIZE);
2902 memcpy(new_fcport->port_name,
2903 swl[swl_idx].port_name, WWN_SIZE);
2904 memcpy(new_fcport->fabric_port_name,
2905 swl[swl_idx].fabric_port_name, WWN_SIZE);
2906 new_fcport->fp_speed = swl[swl_idx].fp_speed;
2908 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2914 /* Send GA_NXT to the switch */
2915 rval = qla2x00_ga_nxt(vha, new_fcport);
2916 if (rval != QLA_SUCCESS) {
2917 qla_printk(KERN_WARNING, ha,
2918 "SNS scan failed -- assuming zero-entry "
2920 list_for_each_entry_safe(fcport, fcptemp,
2921 new_fcports, list) {
2922 list_del(&fcport->list);
2930 /* If wrap on switch device list, exit. */
2932 wrap.b24 = new_fcport->d_id.b24;
2934 } else if (new_fcport->d_id.b24 == wrap.b24) {
2935 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2936 vha->host_no, new_fcport->d_id.b.domain,
2937 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2941 /* Bypass if same physical adapter. */
2942 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
2945 /* Bypass virtual ports of the same host. */
2947 if (ha->num_vhosts) {
2948 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
2949 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2958 /* Bypass if same domain and area of adapter. */
2959 if (((new_fcport->d_id.b24 & 0xffff00) ==
2960 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2964 /* Bypass reserved domain fields. */
2965 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2968 /* Locate matching device in database. */
2970 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2971 if (memcmp(new_fcport->port_name, fcport->port_name,
2977 /* Update port state. */
2978 memcpy(fcport->fabric_port_name,
2979 new_fcport->fabric_port_name, WWN_SIZE);
2980 fcport->fp_speed = new_fcport->fp_speed;
2983 * If address the same and state FCS_ONLINE, nothing
2986 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2987 atomic_read(&fcport->state) == FCS_ONLINE) {
2992 * If device was not a fabric device before.
2994 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2995 fcport->d_id.b24 = new_fcport->d_id.b24;
2996 fcport->loop_id = FC_NO_LOOP_ID;
2997 fcport->flags |= (FCF_FABRIC_DEVICE |
3003 * Port ID changed or device was marked to be updated;
3004 * Log it out if still logged in and mark it for
3007 fcport->d_id.b24 = new_fcport->d_id.b24;
3008 fcport->flags |= FCF_LOGIN_NEEDED;
3009 if (fcport->loop_id != FC_NO_LOOP_ID &&
3010 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
3011 fcport->port_type != FCT_INITIATOR &&
3012 fcport->port_type != FCT_BROADCAST) {
3013 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3014 fcport->d_id.b.domain, fcport->d_id.b.area,
3015 fcport->d_id.b.al_pa);
3016 fcport->loop_id = FC_NO_LOOP_ID;
3024 /* If device was not in our fcports list, then add it. */
3025 list_add_tail(&new_fcport->list, new_fcports);
3027 /* Allocate a new replacement fcport. */
3028 nxt_d_id.b24 = new_fcport->d_id.b24;
3029 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
3030 if (new_fcport == NULL) {
3032 return (QLA_MEMORY_ALLOC_FAILED);
3034 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3035 new_fcport->d_id.b24 = nxt_d_id.b24;
3045 * qla2x00_find_new_loop_id
3046 * Scan through our port list and find a new usable loop ID.
3049 * ha: adapter state pointer.
3050 * dev: port structure pointer.
3053 * qla2x00 local function return status code.
3059 qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
3064 uint16_t first_loop_id;
3065 struct qla_hw_data *ha = vha->hw;
3066 struct scsi_qla_host *vp;
3067 struct scsi_qla_host *tvp;
3071 /* Save starting loop ID. */
3072 first_loop_id = dev->loop_id;
3075 /* Skip loop ID if already used by adapter. */
3076 if (dev->loop_id == vha->loop_id)
3079 /* Skip reserved loop IDs. */
3080 while (qla2x00_is_reserved_id(vha, dev->loop_id))
3083 /* Reset loop ID if passed the end. */
3084 if (dev->loop_id > ha->max_loop_id) {
3085 /* first loop ID. */
3086 dev->loop_id = ha->min_external_loopid;
3089 /* Check for loop ID being already in use. */
3092 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
3093 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3094 if (fcport->loop_id == dev->loop_id &&
3096 /* ID possibly in use */
3105 /* If not in use then it is free to use. */
3110 /* ID in use. Try next value. */
3113 /* If wrap around. No free ID to use. */
3114 if (dev->loop_id == first_loop_id) {
3115 dev->loop_id = FC_NO_LOOP_ID;
3116 rval = QLA_FUNCTION_FAILED;
3125 * qla2x00_device_resync
3126 * Marks devices in the database that needs resynchronization.
3129 * ha = adapter block pointer.
3135 qla2x00_device_resync(scsi_qla_host_t *vha)
3140 uint32_t rscn_entry;
3141 uint8_t rscn_out_iter;
3145 rval = QLA_RSCNS_HANDLED;
3147 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3148 vha->flags.rscn_queue_overflow) {
3150 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
3151 format = MSB(MSW(rscn_entry));
3152 d_id.b.domain = LSB(MSW(rscn_entry));
3153 d_id.b.area = MSB(LSW(rscn_entry));
3154 d_id.b.al_pa = LSB(LSW(rscn_entry));
3156 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3157 "[%02x/%02x%02x%02x].\n",
3158 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
3159 d_id.b.area, d_id.b.al_pa));
3161 vha->rscn_out_ptr++;
3162 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3163 vha->rscn_out_ptr = 0;
3165 /* Skip duplicate entries. */
3166 for (rscn_out_iter = vha->rscn_out_ptr;
3167 !vha->flags.rscn_queue_overflow &&
3168 rscn_out_iter != vha->rscn_in_ptr;
3169 rscn_out_iter = (rscn_out_iter ==
3170 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3172 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
3175 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
3176 "entry found at [%d].\n", vha->host_no,
3179 vha->rscn_out_ptr = rscn_out_iter;
3182 /* Queue overflow, set switch default case. */
3183 if (vha->flags.rscn_queue_overflow) {
3184 DEBUG(printk("scsi(%ld): device_resync: rscn "
3185 "overflow.\n", vha->host_no));
3188 vha->flags.rscn_queue_overflow = 0;
3204 vha->rscn_out_ptr = vha->rscn_in_ptr;
3210 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3211 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3212 (fcport->d_id.b24 & mask) != d_id.b24 ||
3213 fcport->port_type == FCT_BROADCAST)
3216 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3218 fcport->port_type != FCT_INITIATOR) {
3219 qla2x00_mark_device_lost(vha, fcport,
3229 * qla2x00_fabric_dev_login
3230 * Login fabric target device and update FC port database.
3233 * ha: adapter state pointer.
3234 * fcport: port structure list pointer.
3235 * next_loopid: contains value of a new loop ID that can be used
3236 * by the next login attempt.
3239 * qla2x00 local function return status code.
3245 qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
3246 uint16_t *next_loopid)
3251 struct qla_hw_data *ha = vha->hw;
3256 if (IS_ALOGIO_CAPABLE(ha)) {
3257 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3262 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
3263 if (rval == QLA_SUCCESS) {
3264 /* Send an ADISC to tape devices.*/
3266 if (fcport->flags & FCF_TAPE_PRESENT)
3268 rval = qla2x00_get_port_database(vha, fcport, opts);
3269 if (rval != QLA_SUCCESS) {
3270 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3271 fcport->d_id.b.domain, fcport->d_id.b.area,
3272 fcport->d_id.b.al_pa);
3273 qla2x00_mark_device_lost(vha, fcport, 1, 0);
3275 qla2x00_update_fcport(vha, fcport);
3283 * qla2x00_fabric_login
3284 * Issue fabric login command.
3287 * ha = adapter block pointer.
3288 * device = pointer to FC device type structure.
3291 * 0 - Login successfully
3293 * 2 - Initiator device
3297 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
3298 uint16_t *next_loopid)
3302 uint16_t tmp_loopid;
3303 uint16_t mb[MAILBOX_REGISTER_COUNT];
3304 struct qla_hw_data *ha = vha->hw;
3310 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3311 "for port %02x%02x%02x.\n",
3312 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
3313 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3315 /* Login fcport on switch. */
3316 ha->isp_ops->fabric_login(vha, fcport->loop_id,
3317 fcport->d_id.b.domain, fcport->d_id.b.area,
3318 fcport->d_id.b.al_pa, mb, BIT_0);
3319 if (mb[0] == MBS_PORT_ID_USED) {
3321 * Device has another loop ID. The firmware team
3322 * recommends the driver perform an implicit login with
3323 * the specified ID again. The ID we just used is save
3324 * here so we return with an ID that can be tried by
3328 tmp_loopid = fcport->loop_id;
3329 fcport->loop_id = mb[1];
3331 DEBUG(printk("Fabric Login: port in use - next "
3332 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3333 fcport->loop_id, fcport->d_id.b.domain,
3334 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3336 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3341 /* A retry occurred before. */
3342 *next_loopid = tmp_loopid;
3345 * No retry occurred before. Just increment the
3346 * ID value for next login.
3348 *next_loopid = (fcport->loop_id + 1);
3351 if (mb[1] & BIT_0) {
3352 fcport->port_type = FCT_INITIATOR;
3354 fcport->port_type = FCT_TARGET;
3355 if (mb[1] & BIT_1) {
3356 fcport->flags |= FCF_FCP2_DEVICE;
3361 fcport->supported_classes |= FC_COS_CLASS2;
3363 fcport->supported_classes |= FC_COS_CLASS3;
3367 } else if (mb[0] == MBS_LOOP_ID_USED) {
3369 * Loop ID already used, try next loop ID.
3372 rval = qla2x00_find_new_loop_id(vha, fcport);
3373 if (rval != QLA_SUCCESS) {
3374 /* Ran out of loop IDs to use */
3377 } else if (mb[0] == MBS_COMMAND_ERROR) {
3379 * Firmware possibly timed out during login. If NO
3380 * retries are left to do then the device is declared
3383 *next_loopid = fcport->loop_id;
3384 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3385 fcport->d_id.b.domain, fcport->d_id.b.area,
3386 fcport->d_id.b.al_pa);
3387 qla2x00_mark_device_lost(vha, fcport, 1, 0);
3393 * unrecoverable / not handled error
3395 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3396 "loop_id=%x jiffies=%lx.\n",
3397 __func__, vha->host_no, mb[0],
3398 fcport->d_id.b.domain, fcport->d_id.b.area,
3399 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3401 *next_loopid = fcport->loop_id;
3402 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3403 fcport->d_id.b.domain, fcport->d_id.b.area,
3404 fcport->d_id.b.al_pa);
3405 fcport->loop_id = FC_NO_LOOP_ID;
3406 fcport->login_retry = 0;
3417 * qla2x00_local_device_login
3418 * Issue local device login command.
3421 * ha = adapter block pointer.
3422 * loop_id = loop id of device to login to.
3424 * Returns (Where's the #define!!!!):
3425 * 0 - Login successfully
3430 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
3433 uint16_t mb[MAILBOX_REGISTER_COUNT];
3435 memset(mb, 0, sizeof(mb));
3436 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
3437 if (rval == QLA_SUCCESS) {
3438 /* Interrogate mailbox registers for any errors */
3439 if (mb[0] == MBS_COMMAND_ERROR)
3441 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3442 /* device not in PCB table */
3450 * qla2x00_loop_resync
3451 * Resync with fibre channel devices.
3454 * ha = adapter block pointer.
3460 qla2x00_loop_resync(scsi_qla_host_t *vha)
3462 int rval = QLA_SUCCESS;
3464 struct req_que *req;
3465 struct rsp_que *rsp;
3467 if (vha->hw->flags.cpu_affinity_enabled)
3468 req = vha->hw->req_q_map[0];
3473 atomic_set(&vha->loop_state, LOOP_UPDATE);
3474 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3475 if (vha->flags.online) {
3476 if (!(rval = qla2x00_fw_ready(vha))) {
3477 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3480 atomic_set(&vha->loop_state, LOOP_UPDATE);
3482 /* Issue a marker after FW becomes ready. */
3483 qla2x00_marker(vha, req, rsp, 0, 0,
3485 vha->marker_needed = 0;
3487 /* Remap devices on Loop. */
3488 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3490 qla2x00_configure_loop(vha);
3492 } while (!atomic_read(&vha->loop_down_timer) &&
3493 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3494 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3499 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3500 return (QLA_FUNCTION_FAILED);
3503 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3509 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
3512 struct scsi_qla_host *tvp, *vha;
3514 /* Go with deferred removal of rport references. */
3515 list_for_each_entry_safe(vha, tvp, &base_vha->hw->vp_list, list)
3516 list_for_each_entry(fcport, &vha->vp_fcports, list)
3517 if (fcport && fcport->drport &&
3518 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
3519 qla2x00_rport_del(fcport);
3524 * Resets ISP and aborts all outstanding commands.
3527 * ha = adapter block pointer.
3533 qla2x00_abort_isp(scsi_qla_host_t *vha)
3537 struct qla_hw_data *ha = vha->hw;
3538 struct scsi_qla_host *vp;
3539 struct scsi_qla_host *tvp;
3540 struct req_que *req = ha->req_q_map[0];
3542 if (vha->flags.online) {
3543 vha->flags.online = 0;
3544 ha->flags.chip_reset_done = 0;
3545 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3546 ha->qla_stats.total_isp_aborts++;
3548 qla_printk(KERN_INFO, ha,
3549 "Performing ISP error recovery - ha= %p.\n", ha);
3550 ha->isp_ops->reset_chip(vha);
3552 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3553 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3554 atomic_set(&vha->loop_state, LOOP_DOWN);
3555 qla2x00_mark_all_devices_lost(vha, 0);
3557 if (!atomic_read(&vha->loop_down_timer))
3558 atomic_set(&vha->loop_down_timer,
3562 /* Requeue all commands in outstanding command list. */
3563 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
3565 ha->isp_ops->get_flash_version(vha, req->ring);
3567 ha->isp_ops->nvram_config(vha);
3569 if (!qla2x00_restart_isp(vha)) {
3570 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
3572 if (!atomic_read(&vha->loop_down_timer)) {
3574 * Issue marker command only when we are going
3575 * to start the I/O .
3577 vha->marker_needed = 1;
3580 vha->flags.online = 1;
3582 ha->isp_ops->enable_intrs(ha);
3584 ha->isp_abort_cnt = 0;
3585 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3588 qla2x00_get_fw_version(vha,
3589 &ha->fw_major_version,
3590 &ha->fw_minor_version,
3591 &ha->fw_subminor_version,
3592 &ha->fw_attributes, &ha->fw_memory_size,
3593 ha->mpi_version, &ha->mpi_capabilities,
3597 ha->flags.fce_enabled = 1;
3599 fce_calc_size(ha->fce_bufs));
3600 rval = qla2x00_enable_fce_trace(vha,
3601 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3604 qla_printk(KERN_WARNING, ha,
3605 "Unable to reinitialize FCE "
3607 ha->flags.fce_enabled = 0;
3612 memset(ha->eft, 0, EFT_SIZE);
3613 rval = qla2x00_enable_eft_trace(vha,
3614 ha->eft_dma, EFT_NUM_BUFFERS);
3616 qla_printk(KERN_WARNING, ha,
3617 "Unable to reinitialize EFT "
3621 } else { /* failed the ISP abort */
3622 vha->flags.online = 1;
3623 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
3624 if (ha->isp_abort_cnt == 0) {
3625 qla_printk(KERN_WARNING, ha,
3626 "ISP error recovery failed - "
3627 "board disabled\n");
3629 * The next call disables the board
3632 ha->isp_ops->reset_adapter(vha);
3633 vha->flags.online = 0;
3634 clear_bit(ISP_ABORT_RETRY,
3637 } else { /* schedule another ISP abort */
3638 ha->isp_abort_cnt--;
3639 DEBUG(printk("qla%ld: ISP abort - "
3640 "retry remaining %d\n",
3641 vha->host_no, ha->isp_abort_cnt));
3645 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3646 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3647 "- retrying (%d) more times\n",
3648 vha->host_no, ha->isp_abort_cnt));
3649 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3657 DEBUG(printk(KERN_INFO
3658 "qla2x00_abort_isp(%ld): succeeded.\n",
3660 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
3662 qla2x00_vp_abort_isp(vp);
3665 qla_printk(KERN_INFO, ha,
3666 "qla2x00_abort_isp: **** FAILED ****\n");
3673 * qla2x00_restart_isp
3674 * restarts the ISP after a reset
3677 * ha = adapter block pointer.
3683 qla2x00_restart_isp(scsi_qla_host_t *vha)
3687 struct qla_hw_data *ha = vha->hw;
3688 struct req_que *req = ha->req_q_map[0];
3689 struct rsp_que *rsp = ha->rsp_q_map[0];
3691 /* If firmware needs to be loaded */
3692 if (qla2x00_isp_firmware(vha)) {
3693 vha->flags.online = 0;
3694 status = ha->isp_ops->chip_diag(vha);
3696 status = qla2x00_setup_chip(vha);
3699 if (!status && !(status = qla2x00_init_rings(vha))) {
3700 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
3701 ha->flags.chip_reset_done = 1;
3702 /* Initialize the queues in use */
3703 qla25xx_init_queues(ha);
3705 status = qla2x00_fw_ready(vha);
3707 DEBUG(printk("%s(): Start configure loop, "
3708 "status = %d\n", __func__, status));
3710 /* Issue a marker after FW becomes ready. */
3711 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
3713 vha->flags.online = 1;
3714 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3717 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3718 qla2x00_configure_loop(vha);
3720 } while (!atomic_read(&vha->loop_down_timer) &&
3721 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3722 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3726 /* if no cable then assume it's good */
3727 if ((vha->device_flags & DFLG_NO_CABLE))
3730 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3738 qla25xx_init_queues(struct qla_hw_data *ha)
3740 struct rsp_que *rsp = NULL;
3741 struct req_que *req = NULL;
3742 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3746 for (i = 1; i < ha->max_rsp_queues; i++) {
3747 rsp = ha->rsp_q_map[i];
3749 rsp->options &= ~BIT_0;
3750 ret = qla25xx_init_rsp_que(base_vha, rsp);
3751 if (ret != QLA_SUCCESS)
3752 DEBUG2_17(printk(KERN_WARNING
3753 "%s Rsp que:%d init failed\n", __func__,
3756 DEBUG2_17(printk(KERN_INFO
3757 "%s Rsp que:%d inited\n", __func__,
3761 for (i = 1; i < ha->max_req_queues; i++) {
3762 req = ha->req_q_map[i];
3764 /* Clear outstanding commands array. */
3765 req->options &= ~BIT_0;
3766 ret = qla25xx_init_req_que(base_vha, req);
3767 if (ret != QLA_SUCCESS)
3768 DEBUG2_17(printk(KERN_WARNING
3769 "%s Req que:%d init failed\n", __func__,
3772 DEBUG2_17(printk(KERN_WARNING
3773 "%s Req que:%d inited\n", __func__,
3781 * qla2x00_reset_adapter
3785 * ha = adapter block pointer.
3788 qla2x00_reset_adapter(scsi_qla_host_t *vha)
3790 unsigned long flags = 0;
3791 struct qla_hw_data *ha = vha->hw;
3792 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3794 vha->flags.online = 0;
3795 ha->isp_ops->disable_intrs(ha);
3797 spin_lock_irqsave(&ha->hardware_lock, flags);
3798 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3799 RD_REG_WORD(®->hccr); /* PCI Posting. */
3800 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3801 RD_REG_WORD(®->hccr); /* PCI Posting. */
3802 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3806 qla24xx_reset_adapter(scsi_qla_host_t *vha)
3808 unsigned long flags = 0;
3809 struct qla_hw_data *ha = vha->hw;
3810 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3812 vha->flags.online = 0;
3813 ha->isp_ops->disable_intrs(ha);
3815 spin_lock_irqsave(&ha->hardware_lock, flags);
3816 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
3817 RD_REG_DWORD(®->hccr);
3818 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
3819 RD_REG_DWORD(®->hccr);
3820 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3822 if (IS_NOPOLLING_TYPE(ha))
3823 ha->isp_ops->enable_intrs(ha);
3826 /* On sparc systems, obtain port and node WWN from firmware
3829 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3830 struct nvram_24xx *nv)
3833 struct qla_hw_data *ha = vha->hw;
3834 struct pci_dev *pdev = ha->pdev;
3835 struct device_node *dp = pci_device_to_OF_node(pdev);
3839 val = of_get_property(dp, "port-wwn", &len);
3840 if (val && len >= WWN_SIZE)
3841 memcpy(nv->port_name, val, WWN_SIZE);
3843 val = of_get_property(dp, "node-wwn", &len);
3844 if (val && len >= WWN_SIZE)
3845 memcpy(nv->node_name, val, WWN_SIZE);
3850 qla24xx_nvram_config(scsi_qla_host_t *vha)
3853 struct init_cb_24xx *icb;
3854 struct nvram_24xx *nv;
3856 uint8_t *dptr1, *dptr2;
3859 struct qla_hw_data *ha = vha->hw;
3862 icb = (struct init_cb_24xx *)ha->init_cb;
3865 /* Determine NVRAM starting address. */
3866 if (ha->flags.port0) {
3867 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3868 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3870 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
3871 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3873 ha->nvram_size = sizeof(struct nvram_24xx);
3874 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3876 /* Get VPD data into cache */
3877 ha->vpd = ha->nvram + VPD_OFFSET;
3878 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
3879 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3881 /* Get NVRAM data into cache and calculate checksum. */
3882 dptr = (uint32_t *)nv;
3883 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
3885 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3886 chksum += le32_to_cpu(*dptr++);
3888 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
3889 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
3891 /* Bad NVRAM data, set defaults parameters. */
3892 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3893 || nv->id[3] != ' ' ||
3894 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3895 /* Reset NVRAM data. */
3896 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3897 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3898 le16_to_cpu(nv->nvram_version));
3899 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3900 "invalid -- WWPN) defaults.\n");
3903 * Set default initialization control block.
3905 memset(nv, 0, ha->nvram_size);
3906 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3907 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3908 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3909 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3910 nv->exchange_count = __constant_cpu_to_le16(0);
3911 nv->hard_address = __constant_cpu_to_le16(124);
3912 nv->port_name[0] = 0x21;
3913 nv->port_name[1] = 0x00 + ha->port_no;
3914 nv->port_name[2] = 0x00;
3915 nv->port_name[3] = 0xe0;
3916 nv->port_name[4] = 0x8b;
3917 nv->port_name[5] = 0x1c;
3918 nv->port_name[6] = 0x55;
3919 nv->port_name[7] = 0x86;
3920 nv->node_name[0] = 0x20;
3921 nv->node_name[1] = 0x00;
3922 nv->node_name[2] = 0x00;
3923 nv->node_name[3] = 0xe0;
3924 nv->node_name[4] = 0x8b;
3925 nv->node_name[5] = 0x1c;
3926 nv->node_name[6] = 0x55;
3927 nv->node_name[7] = 0x86;
3928 qla24xx_nvram_wwn_from_ofw(vha, nv);
3929 nv->login_retry_count = __constant_cpu_to_le16(8);
3930 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3931 nv->login_timeout = __constant_cpu_to_le16(0);
3932 nv->firmware_options_1 =
3933 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3934 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3935 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3936 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3937 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3938 nv->efi_parameters = __constant_cpu_to_le32(0);
3939 nv->reset_delay = 5;
3940 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3941 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3942 nv->link_down_timeout = __constant_cpu_to_le16(30);
3947 /* Reset Initialization control block */
3948 memset(icb, 0, ha->init_cb_size);
3950 /* Copy 1st segment. */
3951 dptr1 = (uint8_t *)icb;
3952 dptr2 = (uint8_t *)&nv->version;
3953 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3955 *dptr1++ = *dptr2++;
3957 icb->login_retry_count = nv->login_retry_count;
3958 icb->link_down_on_nos = nv->link_down_on_nos;
3960 /* Copy 2nd segment. */
3961 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3962 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3963 cnt = (uint8_t *)&icb->reserved_3 -
3964 (uint8_t *)&icb->interrupt_delay_timer;
3966 *dptr1++ = *dptr2++;
3969 * Setup driver NVRAM options.
3971 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
3974 /* Use alternate WWN? */
3975 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3976 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3977 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3980 /* Prepare nodename */
3981 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
3983 * Firmware will apply the following mask if the nodename was
3986 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3987 icb->node_name[0] &= 0xF0;
3990 /* Set host adapter parameters. */
3991 ha->flags.disable_risc_code_load = 0;
3992 ha->flags.enable_lip_reset = 0;
3993 ha->flags.enable_lip_full_login =
3994 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3995 ha->flags.enable_target_reset =
3996 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
3997 ha->flags.enable_led_scheme = 0;
3998 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4000 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4001 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4003 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4004 sizeof(ha->fw_seriallink_options24));
4006 /* save HBA serial number */
4007 ha->serial0 = icb->port_name[5];
4008 ha->serial1 = icb->port_name[6];
4009 ha->serial2 = icb->port_name[7];
4010 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4011 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4013 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4015 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4017 /* Set minimum login_timeout to 4 seconds. */
4018 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4019 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4020 if (le16_to_cpu(nv->login_timeout) < 4)
4021 nv->login_timeout = __constant_cpu_to_le16(4);
4022 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4023 icb->login_timeout = nv->login_timeout;
4025 /* Set minimum RATOV to 100 tenths of a second. */
4028 ha->loop_reset_delay = nv->reset_delay;
4030 /* Link Down Timeout = 0:
4032 * When Port Down timer expires we will start returning
4033 * I/O's to OS with "DID_NO_CONNECT".
4035 * Link Down Timeout != 0:
4037 * The driver waits for the link to come up after link down
4038 * before returning I/Os to OS with "DID_NO_CONNECT".
4040 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4041 ha->loop_down_abort_time =
4042 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4044 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4045 ha->loop_down_abort_time =
4046 (LOOP_DOWN_TIME - ha->link_down_timeout);
4049 /* Need enough time to try and get the port back. */
4050 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4051 if (qlport_down_retry)
4052 ha->port_down_retry_count = qlport_down_retry;
4054 /* Set login_retry_count */
4055 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4056 if (ha->port_down_retry_count ==
4057 le16_to_cpu(nv->port_down_retry_count) &&
4058 ha->port_down_retry_count > 3)
4059 ha->login_retry_count = ha->port_down_retry_count;
4060 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4061 ha->login_retry_count = ha->port_down_retry_count;
4062 if (ql2xloginretrycount)
4063 ha->login_retry_count = ql2xloginretrycount;
4066 if (!vha->flags.init_done) {
4067 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4068 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4069 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4070 le16_to_cpu(icb->interrupt_delay_timer): 2;
4072 icb->firmware_options_2 &= __constant_cpu_to_le32(
4073 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4074 vha->flags.process_response_queue = 0;
4075 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4076 ha->zio_mode = QLA_ZIO_MODE_6;
4078 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4079 "(%d us).\n", vha->host_no, ha->zio_mode,
4080 ha->zio_timer * 100));
4081 qla_printk(KERN_INFO, ha,
4082 "ZIO mode %d enabled; timer delay (%d us).\n",
4083 ha->zio_mode, ha->zio_timer * 100);
4085 icb->firmware_options_2 |= cpu_to_le32(
4086 (uint32_t)ha->zio_mode);
4087 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4088 vha->flags.process_response_queue = 1;
4092 DEBUG2_3(printk(KERN_WARNING
4093 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4099 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4102 int rval = QLA_SUCCESS;
4103 int segments, fragment;
4104 uint32_t *dcode, dlen;
4108 struct qla_hw_data *ha = vha->hw;
4109 struct req_que *req = ha->req_q_map[0];
4111 qla_printk(KERN_INFO, ha,
4112 "FW: Loading from flash (%x)...\n", faddr);
4116 segments = FA_RISC_CODE_SEGMENTS;
4117 dcode = (uint32_t *)req->ring;
4120 /* Validate firmware image by checking version. */
4121 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
4122 for (i = 0; i < 4; i++)
4123 dcode[i] = be32_to_cpu(dcode[i]);
4124 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4125 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4126 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4128 qla_printk(KERN_WARNING, ha,
4129 "Unable to verify integrity of flash firmware image!\n");
4130 qla_printk(KERN_WARNING, ha,
4131 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4132 dcode[1], dcode[2], dcode[3]);
4134 return QLA_FUNCTION_FAILED;
4137 while (segments && rval == QLA_SUCCESS) {
4138 /* Read segment's load information. */
4139 qla24xx_read_flash_data(vha, dcode, faddr, 4);
4141 risc_addr = be32_to_cpu(dcode[2]);
4142 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4143 risc_size = be32_to_cpu(dcode[3]);
4146 while (risc_size > 0 && rval == QLA_SUCCESS) {
4147 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4148 if (dlen > risc_size)
4151 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4152 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
4153 vha->host_no, risc_addr, dlen, faddr));
4155 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
4156 for (i = 0; i < dlen; i++)
4157 dcode[i] = swab32(dcode[i]);
4159 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
4162 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4163 "segment %d of firmware\n", vha->host_no,
4165 qla_printk(KERN_WARNING, ha,
4166 "[ERROR] Failed to load segment %d of "
4167 "firmware\n", fragment);
4184 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4187 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4191 uint16_t *wcode, *fwcode;
4192 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4193 struct fw_blob *blob;
4194 struct qla_hw_data *ha = vha->hw;
4195 struct req_que *req = ha->req_q_map[0];
4197 /* Load firmware blob. */
4198 blob = qla2x00_request_firmware(vha);
4200 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
4201 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4202 "from: " QLA_FW_URL ".\n");
4203 return QLA_FUNCTION_FAILED;
4208 wcode = (uint16_t *)req->ring;
4210 fwcode = (uint16_t *)blob->fw->data;
4213 /* Validate firmware image by checking version. */
4214 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4215 qla_printk(KERN_WARNING, ha,
4216 "Unable to verify integrity of firmware image (%Zd)!\n",
4218 goto fail_fw_integrity;
4220 for (i = 0; i < 4; i++)
4221 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4222 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4223 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4224 wcode[2] == 0 && wcode[3] == 0)) {
4225 qla_printk(KERN_WARNING, ha,
4226 "Unable to verify integrity of firmware image!\n");
4227 qla_printk(KERN_WARNING, ha,
4228 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
4229 wcode[1], wcode[2], wcode[3]);
4230 goto fail_fw_integrity;
4234 while (*seg && rval == QLA_SUCCESS) {
4236 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4237 risc_size = be16_to_cpu(fwcode[3]);
4239 /* Validate firmware image size. */
4240 fwclen += risc_size * sizeof(uint16_t);
4241 if (blob->fw->size < fwclen) {
4242 qla_printk(KERN_WARNING, ha,
4243 "Unable to verify integrity of firmware image "
4244 "(%Zd)!\n", blob->fw->size);
4245 goto fail_fw_integrity;
4249 while (risc_size > 0 && rval == QLA_SUCCESS) {
4250 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4251 if (wlen > risc_size)
4254 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4255 "addr %x, number of words 0x%x.\n", vha->host_no,
4258 for (i = 0; i < wlen; i++)
4259 wcode[i] = swab16(fwcode[i]);
4261 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
4264 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4265 "segment %d of firmware\n", vha->host_no,
4267 qla_printk(KERN_WARNING, ha,
4268 "[ERROR] Failed to load segment %d of "
4269 "firmware\n", fragment);
4285 return QLA_FUNCTION_FAILED;
4289 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4292 int segments, fragment;
4293 uint32_t *dcode, dlen;
4297 struct fw_blob *blob;
4298 uint32_t *fwcode, fwclen;
4299 struct qla_hw_data *ha = vha->hw;
4300 struct req_que *req = ha->req_q_map[0];
4302 /* Load firmware blob. */
4303 blob = qla2x00_request_firmware(vha);
4305 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
4306 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4307 "from: " QLA_FW_URL ".\n");
4309 return QLA_FUNCTION_FAILED;
4312 qla_printk(KERN_INFO, ha,
4313 "FW: Loading via request-firmware...\n");
4317 segments = FA_RISC_CODE_SEGMENTS;
4318 dcode = (uint32_t *)req->ring;
4320 fwcode = (uint32_t *)blob->fw->data;
4323 /* Validate firmware image by checking version. */
4324 if (blob->fw->size < 8 * sizeof(uint32_t)) {
4325 qla_printk(KERN_WARNING, ha,
4326 "Unable to verify integrity of firmware image (%Zd)!\n",
4328 goto fail_fw_integrity;
4330 for (i = 0; i < 4; i++)
4331 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4332 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4333 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4334 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4336 qla_printk(KERN_WARNING, ha,
4337 "Unable to verify integrity of firmware image!\n");
4338 qla_printk(KERN_WARNING, ha,
4339 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4340 dcode[1], dcode[2], dcode[3]);
4341 goto fail_fw_integrity;
4344 while (segments && rval == QLA_SUCCESS) {
4345 risc_addr = be32_to_cpu(fwcode[2]);
4346 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4347 risc_size = be32_to_cpu(fwcode[3]);
4349 /* Validate firmware image size. */
4350 fwclen += risc_size * sizeof(uint32_t);
4351 if (blob->fw->size < fwclen) {
4352 qla_printk(KERN_WARNING, ha,
4353 "Unable to verify integrity of firmware image "
4354 "(%Zd)!\n", blob->fw->size);
4356 goto fail_fw_integrity;
4360 while (risc_size > 0 && rval == QLA_SUCCESS) {
4361 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4362 if (dlen > risc_size)
4365 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4366 "addr %x, number of dwords 0x%x.\n", vha->host_no,
4369 for (i = 0; i < dlen; i++)
4370 dcode[i] = swab32(fwcode[i]);
4372 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
4375 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4376 "segment %d of firmware\n", vha->host_no,
4378 qla_printk(KERN_WARNING, ha,
4379 "[ERROR] Failed to load segment %d of "
4380 "firmware\n", fragment);
4396 return QLA_FUNCTION_FAILED;
4400 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4404 if (ql2xfwloadbin == 1)
4405 return qla81xx_load_risc(vha, srisc_addr);
4409 * 1) Firmware via request-firmware interface (.bin file).
4410 * 2) Firmware residing in flash.
4412 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4413 if (rval == QLA_SUCCESS)
4416 return qla24xx_load_risc_flash(vha, srisc_addr,
4417 vha->hw->flt_region_fw);
4421 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4424 struct qla_hw_data *ha = vha->hw;
4426 if (ql2xfwloadbin == 2)
4431 * 1) Firmware residing in flash.
4432 * 2) Firmware via request-firmware interface (.bin file).
4433 * 3) Golden-Firmware residing in flash -- limited operation.
4435 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
4436 if (rval == QLA_SUCCESS)
4440 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4441 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4444 qla_printk(KERN_ERR, ha,
4445 "FW: Attempting to fallback to golden firmware...\n");
4446 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4447 if (rval != QLA_SUCCESS)
4450 qla_printk(KERN_ERR, ha,
4451 "FW: Please update operational firmware...\n");
4452 ha->flags.running_gold_fw = 1;
4458 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
4461 struct qla_hw_data *ha = vha->hw;
4463 if (!IS_FWI2_CAPABLE(ha))
4465 if (!ha->fw_major_version)
4468 ret = qla2x00_stop_firmware(vha);
4469 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4470 ret != QLA_INVALID_COMMAND && retries ; retries--) {
4471 ha->isp_ops->reset_chip(vha);
4472 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
4474 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
4476 qla_printk(KERN_INFO, ha,
4477 "Attempting retry of stop-firmware command...\n");
4478 ret = qla2x00_stop_firmware(vha);
4483 qla24xx_configure_vhba(scsi_qla_host_t *vha)
4485 int rval = QLA_SUCCESS;
4486 uint16_t mb[MAILBOX_REGISTER_COUNT];
4487 struct qla_hw_data *ha = vha->hw;
4488 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4489 struct req_que *req;
4490 struct rsp_que *rsp;
4495 rval = qla2x00_fw_ready(base_vha);
4496 if (ha->flags.cpu_affinity_enabled)
4497 req = ha->req_q_map[0];
4502 if (rval == QLA_SUCCESS) {
4503 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
4504 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
4507 vha->flags.management_server_logged_in = 0;
4509 /* Login to SNS first */
4510 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
4511 if (mb[0] != MBS_COMMAND_COMPLETE) {
4512 DEBUG15(qla_printk(KERN_INFO, ha,
4513 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4514 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4515 mb[0], mb[1], mb[2], mb[6], mb[7]));
4516 return (QLA_FUNCTION_FAILED);
4519 atomic_set(&vha->loop_down_timer, 0);
4520 atomic_set(&vha->loop_state, LOOP_UP);
4521 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4522 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4523 rval = qla2x00_loop_resync(base_vha);
4528 /* 84XX Support **************************************************************/
4530 static LIST_HEAD(qla_cs84xx_list);
4531 static DEFINE_MUTEX(qla_cs84xx_mutex);
4533 static struct qla_chip_state_84xx *
4534 qla84xx_get_chip(struct scsi_qla_host *vha)
4536 struct qla_chip_state_84xx *cs84xx;
4537 struct qla_hw_data *ha = vha->hw;
4539 mutex_lock(&qla_cs84xx_mutex);
4541 /* Find any shared 84xx chip. */
4542 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4543 if (cs84xx->bus == ha->pdev->bus) {
4544 kref_get(&cs84xx->kref);
4549 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4553 kref_init(&cs84xx->kref);
4554 spin_lock_init(&cs84xx->access_lock);
4555 mutex_init(&cs84xx->fw_update_mutex);
4556 cs84xx->bus = ha->pdev->bus;
4558 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4560 mutex_unlock(&qla_cs84xx_mutex);
4565 __qla84xx_chip_release(struct kref *kref)
4567 struct qla_chip_state_84xx *cs84xx =
4568 container_of(kref, struct qla_chip_state_84xx, kref);
4570 mutex_lock(&qla_cs84xx_mutex);
4571 list_del(&cs84xx->list);
4572 mutex_unlock(&qla_cs84xx_mutex);
4577 qla84xx_put_chip(struct scsi_qla_host *vha)
4579 struct qla_hw_data *ha = vha->hw;
4581 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4585 qla84xx_init_chip(scsi_qla_host_t *vha)
4589 struct qla_hw_data *ha = vha->hw;
4591 mutex_lock(&ha->cs84xx->fw_update_mutex);
4593 rval = qla84xx_verify_chip(vha, status);
4595 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4597 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4601 /* 81XX Support **************************************************************/
4604 qla81xx_nvram_config(scsi_qla_host_t *vha)
4607 struct init_cb_81xx *icb;
4608 struct nvram_81xx *nv;
4610 uint8_t *dptr1, *dptr2;
4613 struct qla_hw_data *ha = vha->hw;
4616 icb = (struct init_cb_81xx *)ha->init_cb;
4619 /* Determine NVRAM starting address. */
4620 ha->nvram_size = sizeof(struct nvram_81xx);
4621 ha->vpd_size = FA_NVRAM_VPD_SIZE;
4623 /* Get VPD data into cache */
4624 ha->vpd = ha->nvram + VPD_OFFSET;
4625 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4628 /* Get NVRAM data into cache and calculate checksum. */
4629 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
4631 dptr = (uint32_t *)nv;
4632 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4633 chksum += le32_to_cpu(*dptr++);
4635 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
4636 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4638 /* Bad NVRAM data, set defaults parameters. */
4639 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4640 || nv->id[3] != ' ' ||
4641 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4642 /* Reset NVRAM data. */
4643 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4644 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4645 le16_to_cpu(nv->nvram_version));
4646 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4647 "invalid -- WWPN) defaults.\n");
4650 * Set default initialization control block.
4652 memset(nv, 0, ha->nvram_size);
4653 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4654 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4655 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4656 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4657 nv->exchange_count = __constant_cpu_to_le16(0);
4658 nv->port_name[0] = 0x21;
4659 nv->port_name[1] = 0x00 + ha->port_no;
4660 nv->port_name[2] = 0x00;
4661 nv->port_name[3] = 0xe0;
4662 nv->port_name[4] = 0x8b;
4663 nv->port_name[5] = 0x1c;
4664 nv->port_name[6] = 0x55;
4665 nv->port_name[7] = 0x86;
4666 nv->node_name[0] = 0x20;
4667 nv->node_name[1] = 0x00;
4668 nv->node_name[2] = 0x00;
4669 nv->node_name[3] = 0xe0;
4670 nv->node_name[4] = 0x8b;
4671 nv->node_name[5] = 0x1c;
4672 nv->node_name[6] = 0x55;
4673 nv->node_name[7] = 0x86;
4674 nv->login_retry_count = __constant_cpu_to_le16(8);
4675 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4676 nv->login_timeout = __constant_cpu_to_le16(0);
4677 nv->firmware_options_1 =
4678 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4679 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4680 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4681 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4682 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4683 nv->efi_parameters = __constant_cpu_to_le32(0);
4684 nv->reset_delay = 5;
4685 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4686 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4687 nv->link_down_timeout = __constant_cpu_to_le16(30);
4688 nv->enode_mac[0] = 0x00;
4689 nv->enode_mac[1] = 0x02;
4690 nv->enode_mac[2] = 0x03;
4691 nv->enode_mac[3] = 0x04;
4692 nv->enode_mac[4] = 0x05;
4693 nv->enode_mac[5] = 0x06 + ha->port_no;
4698 /* Reset Initialization control block */
4699 memset(icb, 0, sizeof(struct init_cb_81xx));
4701 /* Copy 1st segment. */
4702 dptr1 = (uint8_t *)icb;
4703 dptr2 = (uint8_t *)&nv->version;
4704 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4706 *dptr1++ = *dptr2++;
4708 icb->login_retry_count = nv->login_retry_count;
4710 /* Copy 2nd segment. */
4711 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4712 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4713 cnt = (uint8_t *)&icb->reserved_5 -
4714 (uint8_t *)&icb->interrupt_delay_timer;
4716 *dptr1++ = *dptr2++;
4718 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4719 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4720 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4721 icb->enode_mac[0] = 0x01;
4722 icb->enode_mac[1] = 0x02;
4723 icb->enode_mac[2] = 0x03;
4724 icb->enode_mac[3] = 0x04;
4725 icb->enode_mac[4] = 0x05;
4726 icb->enode_mac[5] = 0x06 + ha->port_no;
4729 /* Use extended-initialization control block. */
4730 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
4733 * Setup driver NVRAM options.
4735 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4738 /* Use alternate WWN? */
4739 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4740 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4741 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4744 /* Prepare nodename */
4745 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4747 * Firmware will apply the following mask if the nodename was
4750 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4751 icb->node_name[0] &= 0xF0;
4754 /* Set host adapter parameters. */
4755 ha->flags.disable_risc_code_load = 0;
4756 ha->flags.enable_lip_reset = 0;
4757 ha->flags.enable_lip_full_login =
4758 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4759 ha->flags.enable_target_reset =
4760 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4761 ha->flags.enable_led_scheme = 0;
4762 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4764 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4765 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4767 /* save HBA serial number */
4768 ha->serial0 = icb->port_name[5];
4769 ha->serial1 = icb->port_name[6];
4770 ha->serial2 = icb->port_name[7];
4771 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4772 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4774 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4776 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4778 /* Set minimum login_timeout to 4 seconds. */
4779 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4780 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4781 if (le16_to_cpu(nv->login_timeout) < 4)
4782 nv->login_timeout = __constant_cpu_to_le16(4);
4783 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4784 icb->login_timeout = nv->login_timeout;
4786 /* Set minimum RATOV to 100 tenths of a second. */
4789 ha->loop_reset_delay = nv->reset_delay;
4791 /* Link Down Timeout = 0:
4793 * When Port Down timer expires we will start returning
4794 * I/O's to OS with "DID_NO_CONNECT".
4796 * Link Down Timeout != 0:
4798 * The driver waits for the link to come up after link down
4799 * before returning I/Os to OS with "DID_NO_CONNECT".
4801 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4802 ha->loop_down_abort_time =
4803 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4805 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4806 ha->loop_down_abort_time =
4807 (LOOP_DOWN_TIME - ha->link_down_timeout);
4810 /* Need enough time to try and get the port back. */
4811 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4812 if (qlport_down_retry)
4813 ha->port_down_retry_count = qlport_down_retry;
4815 /* Set login_retry_count */
4816 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4817 if (ha->port_down_retry_count ==
4818 le16_to_cpu(nv->port_down_retry_count) &&
4819 ha->port_down_retry_count > 3)
4820 ha->login_retry_count = ha->port_down_retry_count;
4821 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4822 ha->login_retry_count = ha->port_down_retry_count;
4823 if (ql2xloginretrycount)
4824 ha->login_retry_count = ql2xloginretrycount;
4827 if (!vha->flags.init_done) {
4828 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4829 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4830 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4831 le16_to_cpu(icb->interrupt_delay_timer): 2;
4833 icb->firmware_options_2 &= __constant_cpu_to_le32(
4834 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4835 vha->flags.process_response_queue = 0;
4836 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4837 ha->zio_mode = QLA_ZIO_MODE_6;
4839 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4840 "(%d us).\n", vha->host_no, ha->zio_mode,
4841 ha->zio_timer * 100));
4842 qla_printk(KERN_INFO, ha,
4843 "ZIO mode %d enabled; timer delay (%d us).\n",
4844 ha->zio_mode, ha->zio_timer * 100);
4846 icb->firmware_options_2 |= cpu_to_le32(
4847 (uint32_t)ha->zio_mode);
4848 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4849 vha->flags.process_response_queue = 1;
4853 DEBUG2_3(printk(KERN_WARNING
4854 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4860 qla81xx_update_fw_options(scsi_qla_host_t *ha)