2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2012 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
10 #include <linux/delay.h>
11 #include <linux/slab.h>
12 #include <linux/vmalloc.h>
14 #include "qla_devtbl.h"
20 #include <target/target_core_base.h>
21 #include "qla_target.h"
24 * QLogic ISP2x00 Hardware Support Function Prototypes.
26 static int qla2x00_isp_firmware(scsi_qla_host_t *);
27 static int qla2x00_setup_chip(scsi_qla_host_t *);
28 static int qla2x00_init_rings(scsi_qla_host_t *);
29 static int qla2x00_fw_ready(scsi_qla_host_t *);
30 static int qla2x00_configure_hba(scsi_qla_host_t *);
31 static int qla2x00_configure_loop(scsi_qla_host_t *);
32 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
33 static int qla2x00_configure_fabric(scsi_qla_host_t *);
34 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
35 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
38 static int qla2x00_restart_isp(scsi_qla_host_t *);
40 static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
41 static int qla84xx_init_chip(scsi_qla_host_t *);
42 static int qla25xx_init_queues(struct qla_hw_data *);
44 /* SRB Extensions ---------------------------------------------------------- */
47 qla2x00_sp_timeout(unsigned long __data)
49 srb_t *sp = (srb_t *)__data;
50 struct srb_iocb *iocb;
51 fc_port_t *fcport = sp->fcport;
52 struct qla_hw_data *ha = fcport->vha->hw;
56 spin_lock_irqsave(&ha->hardware_lock, flags);
57 req = ha->req_q_map[0];
58 req->outstanding_cmds[sp->handle] = NULL;
59 iocb = &sp->u.iocb_cmd;
61 sp->free(fcport->vha, sp);
62 spin_unlock_irqrestore(&ha->hardware_lock, flags);
66 qla2x00_sp_free(void *data, void *ptr)
68 srb_t *sp = (srb_t *)ptr;
69 struct srb_iocb *iocb = &sp->u.iocb_cmd;
70 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
72 del_timer(&iocb->timer);
73 mempool_free(sp, vha->hw->srb_mempool);
75 QLA_VHA_MARK_NOT_BUSY(vha);
78 /* Asynchronous Login/Logout Routines -------------------------------------- */
81 qla2x00_get_async_timeout(struct scsi_qla_host *vha)
84 struct qla_hw_data *ha = vha->hw;
86 /* Firmware should use switch negotiated r_a_tov for timeout. */
87 tmo = ha->r_a_tov / 10 * 2;
88 if (!IS_FWI2_CAPABLE(ha)) {
90 * Except for earlier ISPs where the timeout is seeded from the
91 * initialization control block.
93 tmo = ha->login_timeout;
99 qla2x00_async_iocb_timeout(void *data)
101 srb_t *sp = (srb_t *)data;
102 fc_port_t *fcport = sp->fcport;
104 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
105 "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n",
106 sp->name, sp->handle, fcport->d_id.b.domain, fcport->d_id.b.area,
107 fcport->d_id.b.al_pa);
109 fcport->flags &= ~FCF_ASYNC_SENT;
110 if (sp->type == SRB_LOGIN_CMD) {
111 struct srb_iocb *lio = &sp->u.iocb_cmd;
112 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
113 /* Retry as needed. */
114 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
115 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
116 QLA_LOGIO_LOGIN_RETRIED : 0;
117 qla2x00_post_async_login_done_work(fcport->vha, fcport,
123 qla2x00_async_login_sp_done(void *data, void *ptr, int res)
125 srb_t *sp = (srb_t *)ptr;
126 struct srb_iocb *lio = &sp->u.iocb_cmd;
127 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
129 if (!test_bit(UNLOADING, &vha->dpc_flags))
130 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
132 sp->free(sp->fcport->vha, sp);
136 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
140 struct srb_iocb *lio;
143 rval = QLA_FUNCTION_FAILED;
144 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
148 sp->type = SRB_LOGIN_CMD;
150 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
152 lio = &sp->u.iocb_cmd;
153 lio->timeout = qla2x00_async_iocb_timeout;
154 sp->done = qla2x00_async_login_sp_done;
155 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
156 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
157 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
158 rval = qla2x00_start_sp(sp);
159 if (rval != QLA_SUCCESS)
162 ql_dbg(ql_dbg_disc, vha, 0x2072,
163 "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x "
164 "retries=%d.\n", sp->handle, fcport->loop_id,
165 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
166 fcport->login_retry);
170 sp->free(fcport->vha, sp);
176 qla2x00_async_logout_sp_done(void *data, void *ptr, int res)
178 srb_t *sp = (srb_t *)ptr;
179 struct srb_iocb *lio = &sp->u.iocb_cmd;
180 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
182 if (!test_bit(UNLOADING, &vha->dpc_flags))
183 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
185 sp->free(sp->fcport->vha, sp);
189 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
192 struct srb_iocb *lio;
195 rval = QLA_FUNCTION_FAILED;
196 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
200 sp->type = SRB_LOGOUT_CMD;
202 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
204 lio = &sp->u.iocb_cmd;
205 lio->timeout = qla2x00_async_iocb_timeout;
206 sp->done = qla2x00_async_logout_sp_done;
207 rval = qla2x00_start_sp(sp);
208 if (rval != QLA_SUCCESS)
211 ql_dbg(ql_dbg_disc, vha, 0x2070,
212 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
213 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
214 fcport->d_id.b.area, fcport->d_id.b.al_pa);
218 sp->free(fcport->vha, sp);
224 qla2x00_async_adisc_sp_done(void *data, void *ptr, int res)
226 srb_t *sp = (srb_t *)ptr;
227 struct srb_iocb *lio = &sp->u.iocb_cmd;
228 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
230 if (!test_bit(UNLOADING, &vha->dpc_flags))
231 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
233 sp->free(sp->fcport->vha, sp);
237 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
241 struct srb_iocb *lio;
244 rval = QLA_FUNCTION_FAILED;
245 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
249 sp->type = SRB_ADISC_CMD;
251 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
253 lio = &sp->u.iocb_cmd;
254 lio->timeout = qla2x00_async_iocb_timeout;
255 sp->done = qla2x00_async_adisc_sp_done;
256 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
257 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
258 rval = qla2x00_start_sp(sp);
259 if (rval != QLA_SUCCESS)
262 ql_dbg(ql_dbg_disc, vha, 0x206f,
263 "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
264 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
265 fcport->d_id.b.area, fcport->d_id.b.al_pa);
269 sp->free(fcport->vha, sp);
275 qla2x00_async_tm_cmd_done(void *data, void *ptr, int res)
277 srb_t *sp = (srb_t *)ptr;
278 struct srb_iocb *iocb = &sp->u.iocb_cmd;
279 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
284 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
285 flags = iocb->u.tmf.flags;
286 lun = (uint16_t)iocb->u.tmf.lun;
288 /* Issue Marker IOCB */
289 rval = qla2x00_marker(vha, vha->hw->req_q_map[0],
290 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
291 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
293 if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) {
294 ql_dbg(ql_dbg_taskm, vha, 0x8030,
295 "TM IOCB failed (%x).\n", rval);
298 sp->free(sp->fcport->vha, sp);
302 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t tm_flags, uint32_t lun,
305 struct scsi_qla_host *vha = fcport->vha;
307 struct srb_iocb *tcf;
310 rval = QLA_FUNCTION_FAILED;
311 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
315 sp->type = SRB_TM_CMD;
317 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
319 tcf = &sp->u.iocb_cmd;
320 tcf->u.tmf.flags = tm_flags;
321 tcf->u.tmf.lun = lun;
322 tcf->u.tmf.data = tag;
323 tcf->timeout = qla2x00_async_iocb_timeout;
324 sp->done = qla2x00_async_tm_cmd_done;
326 rval = qla2x00_start_sp(sp);
327 if (rval != QLA_SUCCESS)
330 ql_dbg(ql_dbg_taskm, vha, 0x802f,
331 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
332 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
333 fcport->d_id.b.area, fcport->d_id.b.al_pa);
337 sp->free(fcport->vha, sp);
343 qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
349 case MBS_COMMAND_COMPLETE:
351 * Driver must validate login state - If PRLI not complete,
352 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
355 rval = qla2x00_get_port_database(vha, fcport, 0);
356 if (rval == QLA_NOT_LOGGED_IN) {
357 fcport->flags &= ~FCF_ASYNC_SENT;
358 fcport->flags |= FCF_LOGIN_NEEDED;
359 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
363 if (rval != QLA_SUCCESS) {
364 qla2x00_post_async_logout_work(vha, fcport, NULL);
365 qla2x00_post_async_login_work(vha, fcport, NULL);
368 if (fcport->flags & FCF_FCP2_DEVICE) {
369 qla2x00_post_async_adisc_work(vha, fcport, data);
372 qla2x00_update_fcport(vha, fcport);
374 case MBS_COMMAND_ERROR:
375 fcport->flags &= ~FCF_ASYNC_SENT;
376 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
377 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
379 qla2x00_mark_device_lost(vha, fcport, 1, 0);
381 case MBS_PORT_ID_USED:
382 fcport->loop_id = data[1];
383 qla2x00_post_async_logout_work(vha, fcport, NULL);
384 qla2x00_post_async_login_work(vha, fcport, NULL);
386 case MBS_LOOP_ID_USED:
388 rval = qla2x00_find_new_loop_id(vha, fcport);
389 if (rval != QLA_SUCCESS) {
390 fcport->flags &= ~FCF_ASYNC_SENT;
391 qla2x00_mark_device_lost(vha, fcport, 1, 0);
394 qla2x00_post_async_login_work(vha, fcport, NULL);
401 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
404 qla2x00_mark_device_lost(vha, fcport, 1, 0);
409 qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
412 if (data[0] == MBS_COMMAND_COMPLETE) {
413 qla2x00_update_fcport(vha, fcport);
419 fcport->flags &= ~FCF_ASYNC_SENT;
420 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
421 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
423 qla2x00_mark_device_lost(vha, fcport, 1, 0);
428 /****************************************************************************/
429 /* QLogic ISP2x00 Hardware Support Functions. */
430 /****************************************************************************/
433 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
435 int rval = QLA_SUCCESS;
436 struct qla_hw_data *ha = vha->hw;
437 uint32_t idc_major_ver, idc_minor_ver;
440 qla83xx_idc_lock(vha, 0);
442 /* SV: TODO: Assign initialization timeout from
443 * flash-info / other param
445 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
446 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
448 /* Set our fcoe function presence */
449 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
450 ql_dbg(ql_dbg_p3p, vha, 0xb077,
451 "Error while setting DRV-Presence.\n");
452 rval = QLA_FUNCTION_FAILED;
456 /* Decide the reset ownership */
457 qla83xx_reset_ownership(vha);
460 * On first protocol driver load:
461 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
463 * Others: Check compatibility with current IDC Major version.
465 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
466 if (ha->flags.nic_core_reset_owner) {
467 /* Set IDC Major version */
468 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
469 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
471 /* Clearing IDC-Lock-Recovery register */
472 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
473 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
475 * Clear further IDC participation if we are not compatible with
476 * the current IDC Major Version.
478 ql_log(ql_log_warn, vha, 0xb07d,
479 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
480 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
481 __qla83xx_clear_drv_presence(vha);
482 rval = QLA_FUNCTION_FAILED;
485 /* Each function sets its supported Minor version. */
486 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
487 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
488 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
490 if (ha->flags.nic_core_reset_owner) {
491 memset(config, 0, sizeof(config));
492 if (!qla81xx_get_port_config(vha, config))
493 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
497 rval = qla83xx_idc_state_handler(vha);
500 qla83xx_idc_unlock(vha, 0);
506 * qla2x00_initialize_adapter
510 * ha = adapter block pointer.
516 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
519 struct qla_hw_data *ha = vha->hw;
520 struct req_que *req = ha->req_q_map[0];
522 /* Clear adapter flags. */
523 vha->flags.online = 0;
524 ha->flags.chip_reset_done = 0;
525 vha->flags.reset_active = 0;
526 ha->flags.pci_channel_io_perm_failure = 0;
527 ha->flags.eeh_busy = 0;
528 ha->flags.thermal_supported = 1;
529 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
530 atomic_set(&vha->loop_state, LOOP_DOWN);
531 vha->device_flags = DFLG_NO_CABLE;
533 vha->flags.management_server_logged_in = 0;
534 vha->marker_needed = 0;
535 ha->isp_abort_cnt = 0;
536 ha->beacon_blink_led = 0;
538 set_bit(0, ha->req_qid_map);
539 set_bit(0, ha->rsp_qid_map);
541 ql_dbg(ql_dbg_init, vha, 0x0040,
542 "Configuring PCI space...\n");
543 rval = ha->isp_ops->pci_config(vha);
545 ql_log(ql_log_warn, vha, 0x0044,
546 "Unable to configure PCI space.\n");
550 ha->isp_ops->reset_chip(vha);
552 rval = qla2xxx_get_flash_info(vha);
554 ql_log(ql_log_fatal, vha, 0x004f,
555 "Unable to validate FLASH data.\n");
559 ha->isp_ops->get_flash_version(vha, req->ring);
560 ql_dbg(ql_dbg_init, vha, 0x0061,
561 "Configure NVRAM parameters...\n");
563 ha->isp_ops->nvram_config(vha);
565 if (ha->flags.disable_serdes) {
566 /* Mask HBA via NVRAM settings? */
567 ql_log(ql_log_info, vha, 0x0077,
569 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
570 vha->port_name[0], vha->port_name[1],
571 vha->port_name[2], vha->port_name[3],
572 vha->port_name[4], vha->port_name[5],
573 vha->port_name[6], vha->port_name[7]);
574 return QLA_FUNCTION_FAILED;
577 ql_dbg(ql_dbg_init, vha, 0x0078,
578 "Verifying loaded RISC code...\n");
580 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
581 rval = ha->isp_ops->chip_diag(vha);
584 rval = qla2x00_setup_chip(vha);
589 if (IS_QLA84XX(ha)) {
590 ha->cs84xx = qla84xx_get_chip(vha);
592 ql_log(ql_log_warn, vha, 0x00d0,
593 "Unable to configure ISP84XX.\n");
594 return QLA_FUNCTION_FAILED;
598 if (qla_ini_mode_enabled(vha))
599 rval = qla2x00_init_rings(vha);
601 ha->flags.chip_reset_done = 1;
603 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
604 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
605 rval = qla84xx_init_chip(vha);
606 if (rval != QLA_SUCCESS) {
607 ql_log(ql_log_warn, vha, 0x00d4,
608 "Unable to initialize ISP84XX.\n");
609 qla84xx_put_chip(vha);
613 /* Load the NIC Core f/w if we are the first protocol driver. */
614 if (IS_QLA8031(ha)) {
615 rval = qla83xx_nic_core_fw_load(vha);
617 ql_log(ql_log_warn, vha, 0x0124,
618 "Error in initializing NIC Core f/w.\n");
621 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
622 qla24xx_read_fcp_prio_cfg(vha);
628 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
631 * Returns 0 on success.
634 qla2100_pci_config(scsi_qla_host_t *vha)
638 struct qla_hw_data *ha = vha->hw;
639 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
641 pci_set_master(ha->pdev);
642 pci_try_set_mwi(ha->pdev);
644 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
645 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
646 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
648 pci_disable_rom(ha->pdev);
650 /* Get PCI bus information. */
651 spin_lock_irqsave(&ha->hardware_lock, flags);
652 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
653 spin_unlock_irqrestore(&ha->hardware_lock, flags);
659 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
662 * Returns 0 on success.
665 qla2300_pci_config(scsi_qla_host_t *vha)
668 unsigned long flags = 0;
670 struct qla_hw_data *ha = vha->hw;
671 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
673 pci_set_master(ha->pdev);
674 pci_try_set_mwi(ha->pdev);
676 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
677 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
679 if (IS_QLA2322(ha) || IS_QLA6322(ha))
680 w &= ~PCI_COMMAND_INTX_DISABLE;
681 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
684 * If this is a 2300 card and not 2312, reset the
685 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
686 * the 2310 also reports itself as a 2300 so we need to get the
687 * fb revision level -- a 6 indicates it really is a 2300 and
690 if (IS_QLA2300(ha)) {
691 spin_lock_irqsave(&ha->hardware_lock, flags);
694 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
695 for (cnt = 0; cnt < 30000; cnt++) {
696 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
702 /* Select FPM registers. */
703 WRT_REG_WORD(®->ctrl_status, 0x20);
704 RD_REG_WORD(®->ctrl_status);
706 /* Get the fb rev level */
707 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
709 if (ha->fb_rev == FPM_2300)
710 pci_clear_mwi(ha->pdev);
712 /* Deselect FPM registers. */
713 WRT_REG_WORD(®->ctrl_status, 0x0);
714 RD_REG_WORD(®->ctrl_status);
716 /* Release RISC module. */
717 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
718 for (cnt = 0; cnt < 30000; cnt++) {
719 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
725 spin_unlock_irqrestore(&ha->hardware_lock, flags);
728 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
730 pci_disable_rom(ha->pdev);
732 /* Get PCI bus information. */
733 spin_lock_irqsave(&ha->hardware_lock, flags);
734 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
735 spin_unlock_irqrestore(&ha->hardware_lock, flags);
741 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
744 * Returns 0 on success.
747 qla24xx_pci_config(scsi_qla_host_t *vha)
750 unsigned long flags = 0;
751 struct qla_hw_data *ha = vha->hw;
752 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
754 pci_set_master(ha->pdev);
755 pci_try_set_mwi(ha->pdev);
757 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
758 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
759 w &= ~PCI_COMMAND_INTX_DISABLE;
760 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
762 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
764 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
765 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
766 pcix_set_mmrbc(ha->pdev, 2048);
768 /* PCIe -- adjust Maximum Read Request Size (2048). */
769 if (pci_is_pcie(ha->pdev))
770 pcie_set_readrq(ha->pdev, 4096);
772 pci_disable_rom(ha->pdev);
774 ha->chip_revision = ha->pdev->revision;
776 /* Get PCI bus information. */
777 spin_lock_irqsave(&ha->hardware_lock, flags);
778 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
779 spin_unlock_irqrestore(&ha->hardware_lock, flags);
785 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
788 * Returns 0 on success.
791 qla25xx_pci_config(scsi_qla_host_t *vha)
794 struct qla_hw_data *ha = vha->hw;
796 pci_set_master(ha->pdev);
797 pci_try_set_mwi(ha->pdev);
799 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
800 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
801 w &= ~PCI_COMMAND_INTX_DISABLE;
802 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
804 /* PCIe -- adjust Maximum Read Request Size (2048). */
805 if (pci_is_pcie(ha->pdev))
806 pcie_set_readrq(ha->pdev, 4096);
808 pci_disable_rom(ha->pdev);
810 ha->chip_revision = ha->pdev->revision;
816 * qla2x00_isp_firmware() - Choose firmware image.
819 * Returns 0 on success.
822 qla2x00_isp_firmware(scsi_qla_host_t *vha)
825 uint16_t loop_id, topo, sw_cap;
826 uint8_t domain, area, al_pa;
827 struct qla_hw_data *ha = vha->hw;
829 /* Assume loading risc code */
830 rval = QLA_FUNCTION_FAILED;
832 if (ha->flags.disable_risc_code_load) {
833 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
835 /* Verify checksum of loaded RISC code. */
836 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
837 if (rval == QLA_SUCCESS) {
838 /* And, verify we are not in ROM code. */
839 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
840 &area, &domain, &topo, &sw_cap);
845 ql_dbg(ql_dbg_init, vha, 0x007a,
846 "**** Load RISC code ****.\n");
852 * qla2x00_reset_chip() - Reset ISP chip.
855 * Returns 0 on success.
858 qla2x00_reset_chip(scsi_qla_host_t *vha)
860 unsigned long flags = 0;
861 struct qla_hw_data *ha = vha->hw;
862 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
866 if (unlikely(pci_channel_offline(ha->pdev)))
869 ha->isp_ops->disable_intrs(ha);
871 spin_lock_irqsave(&ha->hardware_lock, flags);
873 /* Turn off master enable */
875 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
876 cmd &= ~PCI_COMMAND_MASTER;
877 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
879 if (!IS_QLA2100(ha)) {
881 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
882 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
883 for (cnt = 0; cnt < 30000; cnt++) {
884 if ((RD_REG_WORD(®->hccr) &
885 HCCR_RISC_PAUSE) != 0)
890 RD_REG_WORD(®->hccr); /* PCI Posting. */
894 /* Select FPM registers. */
895 WRT_REG_WORD(®->ctrl_status, 0x20);
896 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
898 /* FPM Soft Reset. */
899 WRT_REG_WORD(®->fpm_diag_config, 0x100);
900 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
902 /* Toggle Fpm Reset. */
903 if (!IS_QLA2200(ha)) {
904 WRT_REG_WORD(®->fpm_diag_config, 0x0);
905 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
908 /* Select frame buffer registers. */
909 WRT_REG_WORD(®->ctrl_status, 0x10);
910 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
912 /* Reset frame buffer FIFOs. */
913 if (IS_QLA2200(ha)) {
914 WRT_FB_CMD_REG(ha, reg, 0xa000);
915 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
917 WRT_FB_CMD_REG(ha, reg, 0x00fc);
919 /* Read back fb_cmd until zero or 3 seconds max */
920 for (cnt = 0; cnt < 3000; cnt++) {
921 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
927 /* Select RISC module registers. */
928 WRT_REG_WORD(®->ctrl_status, 0);
929 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
931 /* Reset RISC processor. */
932 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
933 RD_REG_WORD(®->hccr); /* PCI Posting. */
935 /* Release RISC processor. */
936 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
937 RD_REG_WORD(®->hccr); /* PCI Posting. */
940 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
941 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
943 /* Reset ISP chip. */
944 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
946 /* Wait for RISC to recover from reset. */
947 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
949 * It is necessary to for a delay here since the card doesn't
950 * respond to PCI reads during a reset. On some architectures
951 * this will result in an MCA.
954 for (cnt = 30000; cnt; cnt--) {
955 if ((RD_REG_WORD(®->ctrl_status) &
956 CSR_ISP_SOFT_RESET) == 0)
963 /* Reset RISC processor. */
964 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
966 WRT_REG_WORD(®->semaphore, 0);
968 /* Release RISC processor. */
969 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
970 RD_REG_WORD(®->hccr); /* PCI Posting. */
972 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
973 for (cnt = 0; cnt < 30000; cnt++) {
974 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
982 /* Turn on master enable */
983 cmd |= PCI_COMMAND_MASTER;
984 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
986 /* Disable RISC pause on FPM parity error. */
987 if (!IS_QLA2100(ha)) {
988 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
989 RD_REG_WORD(®->hccr); /* PCI Posting. */
992 spin_unlock_irqrestore(&ha->hardware_lock, flags);
996 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
998 * Returns 0 on success.
1001 qla81xx_reset_mpi(scsi_qla_host_t *vha)
1003 uint16_t mb[4] = {0x1010, 0, 1, 0};
1005 if (!IS_QLA81XX(vha->hw))
1008 return qla81xx_write_mpi_register(vha, mb);
1012 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
1015 * Returns 0 on success.
1018 qla24xx_reset_risc(scsi_qla_host_t *vha)
1020 unsigned long flags = 0;
1021 struct qla_hw_data *ha = vha->hw;
1022 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1025 static int abts_cnt; /* ISP abort retry counts */
1027 spin_lock_irqsave(&ha->hardware_lock, flags);
1030 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
1031 for (cnt = 0; cnt < 30000; cnt++) {
1032 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
1038 WRT_REG_DWORD(®->ctrl_status,
1039 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
1040 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
1043 /* Wait for firmware to complete NVRAM accesses. */
1044 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
1045 for (cnt = 10000 ; cnt && d2; cnt--) {
1047 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
1051 /* Wait for soft-reset to complete. */
1052 d2 = RD_REG_DWORD(®->ctrl_status);
1053 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
1055 d2 = RD_REG_DWORD(®->ctrl_status);
1059 /* If required, do an MPI FW reset now */
1060 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
1061 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
1062 if (++abts_cnt < 5) {
1063 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1064 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
1067 * We exhausted the ISP abort retries. We have to
1068 * set the board offline.
1071 vha->flags.online = 0;
1076 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
1077 RD_REG_DWORD(®->hccr);
1079 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
1080 RD_REG_DWORD(®->hccr);
1082 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
1083 RD_REG_DWORD(®->hccr);
1085 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
1086 for (cnt = 6000000 ; cnt && d2; cnt--) {
1088 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
1092 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1094 if (IS_NOPOLLING_TYPE(ha))
1095 ha->isp_ops->enable_intrs(ha);
1099 * qla24xx_reset_chip() - Reset ISP24xx chip.
1102 * Returns 0 on success.
1105 qla24xx_reset_chip(scsi_qla_host_t *vha)
1107 struct qla_hw_data *ha = vha->hw;
1109 if (pci_channel_offline(ha->pdev) &&
1110 ha->flags.pci_channel_io_perm_failure) {
1114 ha->isp_ops->disable_intrs(ha);
1116 /* Perform RISC reset. */
1117 qla24xx_reset_risc(vha);
1121 * qla2x00_chip_diag() - Test chip for proper operation.
1124 * Returns 0 on success.
1127 qla2x00_chip_diag(scsi_qla_host_t *vha)
1130 struct qla_hw_data *ha = vha->hw;
1131 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1132 unsigned long flags = 0;
1136 struct req_que *req = ha->req_q_map[0];
1138 /* Assume a failed state */
1139 rval = QLA_FUNCTION_FAILED;
1141 ql_dbg(ql_dbg_init, vha, 0x007b,
1142 "Testing device at %lx.\n", (u_long)®->flash_address);
1144 spin_lock_irqsave(&ha->hardware_lock, flags);
1146 /* Reset ISP chip. */
1147 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
1150 * We need to have a delay here since the card will not respond while
1151 * in reset causing an MCA on some architectures.
1154 data = qla2x00_debounce_register(®->ctrl_status);
1155 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1157 data = RD_REG_WORD(®->ctrl_status);
1162 goto chip_diag_failed;
1164 ql_dbg(ql_dbg_init, vha, 0x007c,
1165 "Reset register cleared by chip reset.\n");
1167 /* Reset RISC processor. */
1168 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
1169 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
1171 /* Workaround for QLA2312 PCI parity error */
1172 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1173 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1174 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1176 data = RD_MAILBOX_REG(ha, reg, 0);
1183 goto chip_diag_failed;
1185 /* Check product ID of chip */
1186 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
1188 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1189 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1190 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1191 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1192 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1193 mb[3] != PROD_ID_3) {
1194 ql_log(ql_log_warn, vha, 0x0062,
1195 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
1196 mb[1], mb[2], mb[3]);
1198 goto chip_diag_failed;
1200 ha->product_id[0] = mb[1];
1201 ha->product_id[1] = mb[2];
1202 ha->product_id[2] = mb[3];
1203 ha->product_id[3] = mb[4];
1205 /* Adjust fw RISC transfer size */
1206 if (req->length > 1024)
1207 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1209 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
1212 if (IS_QLA2200(ha) &&
1213 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1214 /* Limit firmware transfer size with a 2200A */
1215 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
1217 ha->device_type |= DT_ISP2200A;
1218 ha->fw_transfer_size = 128;
1221 /* Wrap Incoming Mailboxes Test. */
1222 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1224 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
1225 rval = qla2x00_mbx_reg_test(vha);
1227 ql_log(ql_log_warn, vha, 0x0080,
1228 "Failed mailbox send register test.\n");
1230 /* Flag a successful rval */
1232 spin_lock_irqsave(&ha->hardware_lock, flags);
1236 ql_log(ql_log_info, vha, 0x0081,
1237 "Chip diagnostics **** FAILED ****.\n");
1239 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1245 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1248 * Returns 0 on success.
1251 qla24xx_chip_diag(scsi_qla_host_t *vha)
1254 struct qla_hw_data *ha = vha->hw;
1255 struct req_que *req = ha->req_q_map[0];
1260 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
1262 rval = qla2x00_mbx_reg_test(vha);
1264 ql_log(ql_log_warn, vha, 0x0082,
1265 "Failed mailbox send register test.\n");
1267 /* Flag a successful rval */
1275 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
1278 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
1279 eft_size, fce_size, mq_size;
1282 struct qla_hw_data *ha = vha->hw;
1283 struct req_que *req = ha->req_q_map[0];
1284 struct rsp_que *rsp = ha->rsp_q_map[0];
1287 ql_dbg(ql_dbg_init, vha, 0x00bd,
1288 "Firmware dump already allocated.\n");
1293 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
1294 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1295 fixed_size = sizeof(struct qla2100_fw_dump);
1296 } else if (IS_QLA23XX(ha)) {
1297 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1298 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1300 } else if (IS_FWI2_CAPABLE(ha)) {
1302 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
1303 else if (IS_QLA81XX(ha))
1304 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1305 else if (IS_QLA25XX(ha))
1306 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1308 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
1309 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1312 if (!IS_QLA83XX(ha))
1313 mq_size = sizeof(struct qla2xxx_mq_chain);
1315 * Allocate maximum buffer size for all queues.
1316 * Resizing must be done at end-of-dump processing.
1318 mq_size += ha->max_req_queues *
1319 (req->length * sizeof(request_t));
1320 mq_size += ha->max_rsp_queues *
1321 (rsp->length * sizeof(response_t));
1323 if (ha->tgt.atio_q_length)
1324 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
1325 /* Allocate memory for Fibre Channel Event Buffer. */
1326 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha))
1329 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1332 ql_log(ql_log_warn, vha, 0x00be,
1333 "Unable to allocate (%d KB) for FCE.\n",
1338 memset(tc, 0, FCE_SIZE);
1339 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
1340 ha->fce_mb, &ha->fce_bufs);
1342 ql_log(ql_log_warn, vha, 0x00bf,
1343 "Unable to initialize FCE (%d).\n", rval);
1344 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1346 ha->flags.fce_enabled = 0;
1349 ql_dbg(ql_dbg_init, vha, 0x00c0,
1350 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
1352 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
1353 ha->flags.fce_enabled = 1;
1354 ha->fce_dma = tc_dma;
1357 /* Allocate memory for Extended Trace Buffer. */
1358 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
1361 ql_log(ql_log_warn, vha, 0x00c1,
1362 "Unable to allocate (%d KB) for EFT.\n",
1367 memset(tc, 0, EFT_SIZE);
1368 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
1370 ql_log(ql_log_warn, vha, 0x00c2,
1371 "Unable to initialize EFT (%d).\n", rval);
1372 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1376 ql_dbg(ql_dbg_init, vha, 0x00c3,
1377 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
1379 eft_size = EFT_SIZE;
1380 ha->eft_dma = tc_dma;
1384 req_q_size = req->length * sizeof(request_t);
1385 rsp_q_size = rsp->length * sizeof(response_t);
1387 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
1388 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
1389 ha->chain_offset = dump_size;
1390 dump_size += mq_size + fce_size;
1392 ha->fw_dump = vmalloc(dump_size);
1394 ql_log(ql_log_warn, vha, 0x00c4,
1395 "Unable to allocate (%d KB) for firmware dump.\n",
1399 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1406 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1413 ql_dbg(ql_dbg_init, vha, 0x00c5,
1414 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
1416 ha->fw_dump_len = dump_size;
1417 ha->fw_dump->signature[0] = 'Q';
1418 ha->fw_dump->signature[1] = 'L';
1419 ha->fw_dump->signature[2] = 'G';
1420 ha->fw_dump->signature[3] = 'C';
1421 ha->fw_dump->version = __constant_htonl(1);
1423 ha->fw_dump->fixed_size = htonl(fixed_size);
1424 ha->fw_dump->mem_size = htonl(mem_size);
1425 ha->fw_dump->req_q_size = htonl(req_q_size);
1426 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1428 ha->fw_dump->eft_size = htonl(eft_size);
1429 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1430 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1432 ha->fw_dump->header_size =
1433 htonl(offsetof(struct qla2xxx_fw_dump, isp));
1437 qla81xx_mpi_sync(scsi_qla_host_t *vha)
1439 #define MPS_MASK 0xe0
1444 if (!IS_QLA81XX(vha->hw))
1447 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1448 if (rval != QLA_SUCCESS) {
1449 ql_log(ql_log_warn, vha, 0x0105,
1450 "Unable to acquire semaphore.\n");
1454 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1455 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1456 if (rval != QLA_SUCCESS) {
1457 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
1462 if (dc == (dw & MPS_MASK))
1467 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1468 if (rval != QLA_SUCCESS) {
1469 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
1473 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1474 if (rval != QLA_SUCCESS) {
1475 ql_log(ql_log_warn, vha, 0x006d,
1476 "Unable to release semaphore.\n");
1484 * qla2x00_setup_chip() - Load and start RISC firmware.
1487 * Returns 0 on success.
1490 qla2x00_setup_chip(scsi_qla_host_t *vha)
1493 uint32_t srisc_address = 0;
1494 struct qla_hw_data *ha = vha->hw;
1495 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1496 unsigned long flags;
1497 uint16_t fw_major_version;
1499 if (IS_QLA82XX(ha)) {
1500 rval = ha->isp_ops->load_risc(vha, &srisc_address);
1501 if (rval == QLA_SUCCESS) {
1502 qla2x00_stop_firmware(vha);
1503 goto enable_82xx_npiv;
1508 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1509 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1510 spin_lock_irqsave(&ha->hardware_lock, flags);
1511 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
1512 RD_REG_WORD(®->hccr);
1513 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1516 qla81xx_mpi_sync(vha);
1518 /* Load firmware sequences */
1519 rval = ha->isp_ops->load_risc(vha, &srisc_address);
1520 if (rval == QLA_SUCCESS) {
1521 ql_dbg(ql_dbg_init, vha, 0x00c9,
1522 "Verifying Checksum of loaded RISC code.\n");
1524 rval = qla2x00_verify_checksum(vha, srisc_address);
1525 if (rval == QLA_SUCCESS) {
1526 /* Start firmware execution. */
1527 ql_dbg(ql_dbg_init, vha, 0x00ca,
1528 "Starting firmware.\n");
1530 rval = qla2x00_execute_fw(vha, srisc_address);
1531 /* Retrieve firmware information. */
1532 if (rval == QLA_SUCCESS) {
1534 fw_major_version = ha->fw_major_version;
1536 qla82xx_check_md_needed(vha);
1538 rval = qla2x00_get_fw_version(vha);
1539 if (rval != QLA_SUCCESS)
1541 ha->flags.npiv_supported = 0;
1542 if (IS_QLA2XXX_MIDTYPE(ha) &&
1543 (ha->fw_attributes & BIT_2)) {
1544 ha->flags.npiv_supported = 1;
1545 if ((!ha->max_npiv_vports) ||
1546 ((ha->max_npiv_vports + 1) %
1547 MIN_MULTI_ID_FABRIC))
1548 ha->max_npiv_vports =
1549 MIN_MULTI_ID_FABRIC - 1;
1551 qla2x00_get_resource_cnts(vha, NULL,
1552 &ha->fw_xcb_count, NULL, NULL,
1553 &ha->max_npiv_vports, NULL);
1555 if (!fw_major_version && ql2xallocfwdump
1557 qla2x00_alloc_fw_dump(vha);
1560 ql_log(ql_log_fatal, vha, 0x00cd,
1561 "ISP Firmware failed checksum.\n");
1567 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1568 /* Enable proper parity. */
1569 spin_lock_irqsave(&ha->hardware_lock, flags);
1572 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
1574 /* SRAM, Instruction RAM and GP RAM parity */
1575 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
1576 RD_REG_WORD(®->hccr);
1577 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1581 goto skip_fac_check;
1583 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1586 rval = qla81xx_fac_get_sector_size(vha, &size);
1587 if (rval == QLA_SUCCESS) {
1588 ha->flags.fac_supported = 1;
1589 ha->fdt_block_size = size << 2;
1591 ql_log(ql_log_warn, vha, 0x00ce,
1592 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1593 ha->fw_major_version, ha->fw_minor_version,
1594 ha->fw_subminor_version);
1596 if (IS_QLA83XX(ha)) {
1597 ha->flags.fac_supported = 0;
1604 ql_log(ql_log_fatal, vha, 0x00cf,
1605 "Setup chip ****FAILED****.\n");
1612 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1615 * Beginning of request ring has initialization control block already built
1616 * by nvram config routine.
1618 * Returns 0 on success.
1621 qla2x00_init_response_q_entries(struct rsp_que *rsp)
1626 rsp->ring_ptr = rsp->ring;
1627 rsp->ring_index = 0;
1628 rsp->status_srb = NULL;
1629 pkt = rsp->ring_ptr;
1630 for (cnt = 0; cnt < rsp->length; cnt++) {
1631 pkt->signature = RESPONSE_PROCESSED;
1637 * qla2x00_update_fw_options() - Read and process firmware options.
1640 * Returns 0 on success.
1643 qla2x00_update_fw_options(scsi_qla_host_t *vha)
1645 uint16_t swing, emphasis, tx_sens, rx_sens;
1646 struct qla_hw_data *ha = vha->hw;
1648 memset(ha->fw_options, 0, sizeof(ha->fw_options));
1649 qla2x00_get_fw_options(vha, ha->fw_options);
1651 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1654 /* Serial Link options. */
1655 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
1656 "Serial link options.\n");
1657 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
1658 (uint8_t *)&ha->fw_seriallink_options,
1659 sizeof(ha->fw_seriallink_options));
1661 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1662 if (ha->fw_seriallink_options[3] & BIT_2) {
1663 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1666 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1667 emphasis = (ha->fw_seriallink_options[2] &
1668 (BIT_4 | BIT_3)) >> 3;
1669 tx_sens = ha->fw_seriallink_options[0] &
1670 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1671 rx_sens = (ha->fw_seriallink_options[0] &
1672 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1673 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1674 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1677 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1678 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1679 ha->fw_options[10] |= BIT_5 |
1680 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1681 (tx_sens & (BIT_1 | BIT_0));
1684 swing = (ha->fw_seriallink_options[2] &
1685 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1686 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1687 tx_sens = ha->fw_seriallink_options[1] &
1688 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1689 rx_sens = (ha->fw_seriallink_options[1] &
1690 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1691 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1692 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1695 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1696 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1697 ha->fw_options[11] |= BIT_5 |
1698 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1699 (tx_sens & (BIT_1 | BIT_0));
1703 /* Return command IOCBs without waiting for an ABTS to complete. */
1704 ha->fw_options[3] |= BIT_13;
1707 if (ha->flags.enable_led_scheme)
1708 ha->fw_options[2] |= BIT_12;
1710 /* Detect ISP6312. */
1712 ha->fw_options[2] |= BIT_13;
1714 /* Update firmware options. */
1715 qla2x00_set_fw_options(vha, ha->fw_options);
1719 qla24xx_update_fw_options(scsi_qla_host_t *vha)
1722 struct qla_hw_data *ha = vha->hw;
1727 /* Update Serial Link options. */
1728 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
1731 rval = qla2x00_set_serdes_params(vha,
1732 le16_to_cpu(ha->fw_seriallink_options24[1]),
1733 le16_to_cpu(ha->fw_seriallink_options24[2]),
1734 le16_to_cpu(ha->fw_seriallink_options24[3]));
1735 if (rval != QLA_SUCCESS) {
1736 ql_log(ql_log_warn, vha, 0x0104,
1737 "Unable to update Serial Link options (%x).\n", rval);
1742 qla2x00_config_rings(struct scsi_qla_host *vha)
1744 struct qla_hw_data *ha = vha->hw;
1745 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1746 struct req_que *req = ha->req_q_map[0];
1747 struct rsp_que *rsp = ha->rsp_q_map[0];
1749 /* Setup ring parameters in initialization control block. */
1750 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1751 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1752 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1753 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1754 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1755 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1756 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1757 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
1759 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1760 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1761 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1762 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1763 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1767 qla24xx_config_rings(struct scsi_qla_host *vha)
1769 struct qla_hw_data *ha = vha->hw;
1770 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1771 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1772 struct qla_msix_entry *msix;
1773 struct init_cb_24xx *icb;
1775 struct req_que *req = ha->req_q_map[0];
1776 struct rsp_que *rsp = ha->rsp_q_map[0];
1778 /* Setup ring parameters in initialization control block. */
1779 icb = (struct init_cb_24xx *)ha->init_cb;
1780 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1781 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1782 icb->request_q_length = cpu_to_le16(req->length);
1783 icb->response_q_length = cpu_to_le16(rsp->length);
1784 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1785 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1786 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1787 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
1789 /* Setup ATIO queue dma pointers for target mode */
1790 icb->atio_q_inpointer = __constant_cpu_to_le16(0);
1791 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
1792 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
1793 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
1795 if (ha->mqenable || IS_QLA83XX(ha)) {
1796 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1797 icb->rid = __constant_cpu_to_le16(rid);
1798 if (ha->flags.msix_enabled) {
1799 msix = &ha->msix_entries[1];
1800 ql_dbg(ql_dbg_init, vha, 0x00fd,
1801 "Registering vector 0x%x for base que.\n",
1803 icb->msix = cpu_to_le16(msix->entry);
1805 /* Use alternate PCI bus number */
1807 icb->firmware_options_2 |=
1808 __constant_cpu_to_le32(BIT_19);
1809 /* Use alternate PCI devfn */
1811 icb->firmware_options_2 |=
1812 __constant_cpu_to_le32(BIT_18);
1814 /* Use Disable MSIX Handshake mode for capable adapters */
1815 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
1816 (ha->flags.msix_enabled)) {
1817 icb->firmware_options_2 &=
1818 __constant_cpu_to_le32(~BIT_22);
1819 ha->flags.disable_msix_handshake = 1;
1820 ql_dbg(ql_dbg_init, vha, 0x00fe,
1821 "MSIX Handshake Disable Mode turned on.\n");
1823 icb->firmware_options_2 |=
1824 __constant_cpu_to_le32(BIT_22);
1826 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
1828 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
1829 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
1830 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
1831 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
1833 WRT_REG_DWORD(®->isp24.req_q_in, 0);
1834 WRT_REG_DWORD(®->isp24.req_q_out, 0);
1835 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
1836 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
1838 qlt_24xx_config_rings(vha, reg);
1841 RD_REG_DWORD(&ioreg->hccr);
1845 * qla2x00_init_rings() - Initializes firmware.
1848 * Beginning of request ring has initialization control block already built
1849 * by nvram config routine.
1851 * Returns 0 on success.
1854 qla2x00_init_rings(scsi_qla_host_t *vha)
1857 unsigned long flags = 0;
1859 struct qla_hw_data *ha = vha->hw;
1860 struct req_que *req;
1861 struct rsp_que *rsp;
1862 struct mid_init_cb_24xx *mid_init_cb =
1863 (struct mid_init_cb_24xx *) ha->init_cb;
1865 spin_lock_irqsave(&ha->hardware_lock, flags);
1867 /* Clear outstanding commands array. */
1868 for (que = 0; que < ha->max_req_queues; que++) {
1869 req = ha->req_q_map[que];
1872 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1873 req->outstanding_cmds[cnt] = NULL;
1875 req->current_outstanding_cmd = 1;
1877 /* Initialize firmware. */
1878 req->ring_ptr = req->ring;
1879 req->ring_index = 0;
1880 req->cnt = req->length;
1883 for (que = 0; que < ha->max_rsp_queues; que++) {
1884 rsp = ha->rsp_q_map[que];
1887 /* Initialize response queue entries */
1888 qla2x00_init_response_q_entries(rsp);
1891 spin_lock(&ha->vport_slock);
1893 spin_unlock(&ha->vport_slock);
1895 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
1896 ha->tgt.atio_ring_index = 0;
1897 /* Initialize ATIO queue entries */
1898 qlt_init_atio_q_entries(vha);
1900 ha->isp_ops->config_rings(vha);
1902 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1904 /* Update any ISP specific firmware options before initialization. */
1905 ha->isp_ops->update_fw_options(vha);
1907 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
1909 if (ha->flags.npiv_supported) {
1910 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
1911 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
1912 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1915 if (IS_FWI2_CAPABLE(ha)) {
1916 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1917 mid_init_cb->init_cb.execution_throttle =
1918 cpu_to_le16(ha->fw_xcb_count);
1921 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
1923 ql_log(ql_log_fatal, vha, 0x00d2,
1924 "Init Firmware **** FAILED ****.\n");
1926 ql_dbg(ql_dbg_init, vha, 0x00d3,
1927 "Init Firmware -- success.\n");
1934 * qla2x00_fw_ready() - Waits for firmware ready.
1937 * Returns 0 on success.
1940 qla2x00_fw_ready(scsi_qla_host_t *vha)
1943 unsigned long wtime, mtime, cs84xx_time;
1944 uint16_t min_wait; /* Minimum wait time if loop is down */
1945 uint16_t wait_time; /* Wait time if loop is coming ready */
1947 struct qla_hw_data *ha = vha->hw;
1951 /* 20 seconds for loop down. */
1955 * Firmware should take at most one RATOV to login, plus 5 seconds for
1956 * our own processing.
1958 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1959 wait_time = min_wait;
1962 /* Min wait time if loop down */
1963 mtime = jiffies + (min_wait * HZ);
1965 /* wait time before firmware ready */
1966 wtime = jiffies + (wait_time * HZ);
1968 /* Wait for ISP to finish LIP */
1969 if (!vha->flags.init_done)
1970 ql_log(ql_log_info, vha, 0x801e,
1971 "Waiting for LIP to complete.\n");
1974 rval = qla2x00_get_firmware_state(vha, state);
1975 if (rval == QLA_SUCCESS) {
1976 if (state[0] < FSTATE_LOSS_OF_SYNC) {
1977 vha->device_flags &= ~DFLG_NO_CABLE;
1979 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1980 ql_dbg(ql_dbg_taskm, vha, 0x801f,
1981 "fw_state=%x 84xx=%x.\n", state[0],
1983 if ((state[2] & FSTATE_LOGGED_IN) &&
1984 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1985 ql_dbg(ql_dbg_taskm, vha, 0x8028,
1986 "Sending verify iocb.\n");
1988 cs84xx_time = jiffies;
1989 rval = qla84xx_init_chip(vha);
1990 if (rval != QLA_SUCCESS) {
1993 "Init chip failed.\n");
1997 /* Add time taken to initialize. */
1998 cs84xx_time = jiffies - cs84xx_time;
1999 wtime += cs84xx_time;
2000 mtime += cs84xx_time;
2001 ql_dbg(ql_dbg_taskm, vha, 0x8008,
2002 "Increasing wait time by %ld. "
2003 "New time %ld.\n", cs84xx_time,
2006 } else if (state[0] == FSTATE_READY) {
2007 ql_dbg(ql_dbg_taskm, vha, 0x8037,
2008 "F/W Ready - OK.\n");
2010 qla2x00_get_retry_cnt(vha, &ha->retry_count,
2011 &ha->login_timeout, &ha->r_a_tov);
2017 rval = QLA_FUNCTION_FAILED;
2019 if (atomic_read(&vha->loop_down_timer) &&
2020 state[0] != FSTATE_READY) {
2021 /* Loop down. Timeout on min_wait for states
2022 * other than Wait for Login.
2024 if (time_after_eq(jiffies, mtime)) {
2025 ql_log(ql_log_info, vha, 0x8038,
2026 "Cable is unplugged...\n");
2028 vha->device_flags |= DFLG_NO_CABLE;
2033 /* Mailbox cmd failed. Timeout on min_wait. */
2034 if (time_after_eq(jiffies, mtime) ||
2035 ha->flags.isp82xx_fw_hung)
2039 if (time_after_eq(jiffies, wtime))
2042 /* Delay for a while */
2046 ql_dbg(ql_dbg_taskm, vha, 0x803a,
2047 "fw_state=%x (%x, %x, %x, %x) " "curr time=%lx.\n", state[0],
2048 state[1], state[2], state[3], state[4], jiffies);
2050 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
2051 ql_log(ql_log_warn, vha, 0x803b,
2052 "Firmware ready **** FAILED ****.\n");
2059 * qla2x00_configure_hba
2060 * Setup adapter context.
2063 * ha = adapter state pointer.
2072 qla2x00_configure_hba(scsi_qla_host_t *vha)
2081 char connect_type[22];
2082 struct qla_hw_data *ha = vha->hw;
2084 /* Get host addresses. */
2085 rval = qla2x00_get_adapter_id(vha,
2086 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
2087 if (rval != QLA_SUCCESS) {
2088 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
2089 IS_CNA_CAPABLE(ha) ||
2090 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
2091 ql_dbg(ql_dbg_disc, vha, 0x2008,
2092 "Loop is in a transition state.\n");
2094 ql_log(ql_log_warn, vha, 0x2009,
2095 "Unable to get host loop ID.\n");
2096 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2102 ql_log(ql_log_info, vha, 0x200a,
2103 "Cannot get topology - retrying.\n");
2104 return (QLA_FUNCTION_FAILED);
2107 vha->loop_id = loop_id;
2110 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2111 ha->operating_mode = LOOP;
2116 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
2117 ha->current_topology = ISP_CFG_NL;
2118 strcpy(connect_type, "(Loop)");
2122 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
2123 ha->switch_cap = sw_cap;
2124 ha->current_topology = ISP_CFG_FL;
2125 strcpy(connect_type, "(FL_Port)");
2129 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
2130 ha->operating_mode = P2P;
2131 ha->current_topology = ISP_CFG_N;
2132 strcpy(connect_type, "(N_Port-to-N_Port)");
2136 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
2137 ha->switch_cap = sw_cap;
2138 ha->operating_mode = P2P;
2139 ha->current_topology = ISP_CFG_F;
2140 strcpy(connect_type, "(F_Port)");
2144 ql_dbg(ql_dbg_disc, vha, 0x200f,
2145 "HBA in unknown topology %x, using NL.\n", topo);
2146 ha->current_topology = ISP_CFG_NL;
2147 strcpy(connect_type, "(Loop)");
2151 /* Save Host port and loop ID. */
2152 /* byte order - Big Endian */
2153 vha->d_id.b.domain = domain;
2154 vha->d_id.b.area = area;
2155 vha->d_id.b.al_pa = al_pa;
2157 spin_lock(&ha->vport_slock);
2158 qlt_update_vp_map(vha, SET_AL_PA);
2159 spin_unlock(&ha->vport_slock);
2161 if (!vha->flags.init_done)
2162 ql_log(ql_log_info, vha, 0x2010,
2163 "Topology - %s, Host Loop address 0x%x.\n",
2164 connect_type, vha->loop_id);
2167 ql_log(ql_log_warn, vha, 0x2011,
2168 "%s FAILED\n", __func__);
2170 ql_dbg(ql_dbg_disc, vha, 0x2012,
2171 "%s success\n", __func__);
2178 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2183 struct qla_hw_data *ha = vha->hw;
2184 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
2185 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
2187 if (memcmp(model, BINZERO, len) != 0) {
2188 strncpy(ha->model_number, model, len);
2189 st = en = ha->model_number;
2192 if (*en != 0x20 && *en != 0x00)
2197 index = (ha->pdev->subsystem_device & 0xff);
2199 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
2200 index < QLA_MODEL_NAMES)
2201 strncpy(ha->model_desc,
2202 qla2x00_model_name[index * 2 + 1],
2203 sizeof(ha->model_desc) - 1);
2205 index = (ha->pdev->subsystem_device & 0xff);
2207 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
2208 index < QLA_MODEL_NAMES) {
2209 strcpy(ha->model_number,
2210 qla2x00_model_name[index * 2]);
2211 strncpy(ha->model_desc,
2212 qla2x00_model_name[index * 2 + 1],
2213 sizeof(ha->model_desc) - 1);
2215 strcpy(ha->model_number, def);
2218 if (IS_FWI2_CAPABLE(ha))
2219 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
2220 sizeof(ha->model_desc));
2223 /* On sparc systems, obtain port and node WWN from firmware
2226 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
2229 struct qla_hw_data *ha = vha->hw;
2230 struct pci_dev *pdev = ha->pdev;
2231 struct device_node *dp = pci_device_to_OF_node(pdev);
2235 val = of_get_property(dp, "port-wwn", &len);
2236 if (val && len >= WWN_SIZE)
2237 memcpy(nv->port_name, val, WWN_SIZE);
2239 val = of_get_property(dp, "node-wwn", &len);
2240 if (val && len >= WWN_SIZE)
2241 memcpy(nv->node_name, val, WWN_SIZE);
2246 * NVRAM configuration for ISP 2xxx
2249 * ha = adapter block pointer.
2252 * initialization control block in response_ring
2253 * host adapters parameters in host adapter block
2259 qla2x00_nvram_config(scsi_qla_host_t *vha)
2264 uint8_t *dptr1, *dptr2;
2265 struct qla_hw_data *ha = vha->hw;
2266 init_cb_t *icb = ha->init_cb;
2267 nvram_t *nv = ha->nvram;
2268 uint8_t *ptr = ha->nvram;
2269 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2273 /* Determine NVRAM starting address. */
2274 ha->nvram_size = sizeof(nvram_t);
2276 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2277 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
2278 ha->nvram_base = 0x80;
2280 /* Get NVRAM data and calculate checksum. */
2281 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
2282 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2285 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
2286 "Contents of NVRAM.\n");
2287 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
2288 (uint8_t *)nv, ha->nvram_size);
2290 /* Bad NVRAM data, set defaults parameters. */
2291 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2292 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2293 /* Reset NVRAM data. */
2294 ql_log(ql_log_warn, vha, 0x0064,
2295 "Inconsistent NVRAM "
2296 "detected: checksum=0x%x id=%c version=0x%x.\n",
2297 chksum, nv->id[0], nv->nvram_version);
2298 ql_log(ql_log_warn, vha, 0x0065,
2300 "functioning (yet invalid -- WWPN) defaults.\n");
2303 * Set default initialization control block.
2305 memset(nv, 0, ha->nvram_size);
2306 nv->parameter_block_version = ICB_VERSION;
2308 if (IS_QLA23XX(ha)) {
2309 nv->firmware_options[0] = BIT_2 | BIT_1;
2310 nv->firmware_options[1] = BIT_7 | BIT_5;
2311 nv->add_firmware_options[0] = BIT_5;
2312 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2313 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2314 nv->special_options[1] = BIT_7;
2315 } else if (IS_QLA2200(ha)) {
2316 nv->firmware_options[0] = BIT_2 | BIT_1;
2317 nv->firmware_options[1] = BIT_7 | BIT_5;
2318 nv->add_firmware_options[0] = BIT_5;
2319 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2320 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2321 } else if (IS_QLA2100(ha)) {
2322 nv->firmware_options[0] = BIT_3 | BIT_1;
2323 nv->firmware_options[1] = BIT_5;
2324 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2327 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2328 nv->execution_throttle = __constant_cpu_to_le16(16);
2329 nv->retry_count = 8;
2330 nv->retry_delay = 1;
2332 nv->port_name[0] = 33;
2333 nv->port_name[3] = 224;
2334 nv->port_name[4] = 139;
2336 qla2xxx_nvram_wwn_from_ofw(vha, nv);
2338 nv->login_timeout = 4;
2341 * Set default host adapter parameters
2343 nv->host_p[1] = BIT_2;
2344 nv->reset_delay = 5;
2345 nv->port_down_retry_count = 8;
2346 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2347 nv->link_down_timeout = 60;
2352 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2354 * The SN2 does not provide BIOS emulation which means you can't change
2355 * potentially bogus BIOS settings. Force the use of default settings
2356 * for link rate and frame size. Hope that the rest of the settings
2359 if (ia64_platform_is("sn2")) {
2360 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2362 nv->special_options[1] = BIT_7;
2366 /* Reset Initialization control block */
2367 memset(icb, 0, ha->init_cb_size);
2370 * Setup driver NVRAM options.
2372 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2373 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2374 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2375 nv->firmware_options[1] &= ~BIT_4;
2377 if (IS_QLA23XX(ha)) {
2378 nv->firmware_options[0] |= BIT_2;
2379 nv->firmware_options[0] &= ~BIT_3;
2380 nv->special_options[0] &= ~BIT_6;
2381 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
2383 if (IS_QLA2300(ha)) {
2384 if (ha->fb_rev == FPM_2310) {
2385 strcpy(ha->model_number, "QLA2310");
2387 strcpy(ha->model_number, "QLA2300");
2390 qla2x00_set_model_info(vha, nv->model_number,
2391 sizeof(nv->model_number), "QLA23xx");
2393 } else if (IS_QLA2200(ha)) {
2394 nv->firmware_options[0] |= BIT_2;
2396 * 'Point-to-point preferred, else loop' is not a safe
2397 * connection mode setting.
2399 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2401 /* Force 'loop preferred, else point-to-point'. */
2402 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2403 nv->add_firmware_options[0] |= BIT_5;
2405 strcpy(ha->model_number, "QLA22xx");
2406 } else /*if (IS_QLA2100(ha))*/ {
2407 strcpy(ha->model_number, "QLA2100");
2411 * Copy over NVRAM RISC parameter block to initialization control block.
2413 dptr1 = (uint8_t *)icb;
2414 dptr2 = (uint8_t *)&nv->parameter_block_version;
2415 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2417 *dptr1++ = *dptr2++;
2419 /* Copy 2nd half. */
2420 dptr1 = (uint8_t *)icb->add_firmware_options;
2421 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2423 *dptr1++ = *dptr2++;
2425 /* Use alternate WWN? */
2426 if (nv->host_p[1] & BIT_7) {
2427 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2428 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2431 /* Prepare nodename */
2432 if ((icb->firmware_options[1] & BIT_6) == 0) {
2434 * Firmware will apply the following mask if the nodename was
2437 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2438 icb->node_name[0] &= 0xF0;
2442 * Set host adapter parameters.
2446 * BIT_7 in the host-parameters section allows for modification to
2447 * internal driver logging.
2449 if (nv->host_p[0] & BIT_7)
2450 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
2451 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2452 /* Always load RISC code on non ISP2[12]00 chips. */
2453 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2454 ha->flags.disable_risc_code_load = 0;
2455 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2456 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2457 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
2458 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
2459 ha->flags.disable_serdes = 0;
2461 ha->operating_mode =
2462 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2464 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2465 sizeof(ha->fw_seriallink_options));
2467 /* save HBA serial number */
2468 ha->serial0 = icb->port_name[5];
2469 ha->serial1 = icb->port_name[6];
2470 ha->serial2 = icb->port_name[7];
2471 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2472 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
2474 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2476 ha->retry_count = nv->retry_count;
2478 /* Set minimum login_timeout to 4 seconds. */
2479 if (nv->login_timeout != ql2xlogintimeout)
2480 nv->login_timeout = ql2xlogintimeout;
2481 if (nv->login_timeout < 4)
2482 nv->login_timeout = 4;
2483 ha->login_timeout = nv->login_timeout;
2484 icb->login_timeout = nv->login_timeout;
2486 /* Set minimum RATOV to 100 tenths of a second. */
2489 ha->loop_reset_delay = nv->reset_delay;
2491 /* Link Down Timeout = 0:
2493 * When Port Down timer expires we will start returning
2494 * I/O's to OS with "DID_NO_CONNECT".
2496 * Link Down Timeout != 0:
2498 * The driver waits for the link to come up after link down
2499 * before returning I/Os to OS with "DID_NO_CONNECT".
2501 if (nv->link_down_timeout == 0) {
2502 ha->loop_down_abort_time =
2503 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
2505 ha->link_down_timeout = nv->link_down_timeout;
2506 ha->loop_down_abort_time =
2507 (LOOP_DOWN_TIME - ha->link_down_timeout);
2511 * Need enough time to try and get the port back.
2513 ha->port_down_retry_count = nv->port_down_retry_count;
2514 if (qlport_down_retry)
2515 ha->port_down_retry_count = qlport_down_retry;
2516 /* Set login_retry_count */
2517 ha->login_retry_count = nv->retry_count;
2518 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2519 ha->port_down_retry_count > 3)
2520 ha->login_retry_count = ha->port_down_retry_count;
2521 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2522 ha->login_retry_count = ha->port_down_retry_count;
2523 if (ql2xloginretrycount)
2524 ha->login_retry_count = ql2xloginretrycount;
2526 icb->lun_enables = __constant_cpu_to_le16(0);
2527 icb->command_resource_count = 0;
2528 icb->immediate_notify_resource_count = 0;
2529 icb->timeout = __constant_cpu_to_le16(0);
2531 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2533 icb->firmware_options[0] &= ~BIT_3;
2534 icb->add_firmware_options[0] &=
2535 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2536 icb->add_firmware_options[0] |= BIT_2;
2537 icb->response_accumulation_timer = 3;
2538 icb->interrupt_delay_timer = 5;
2540 vha->flags.process_response_queue = 1;
2543 if (!vha->flags.init_done) {
2544 ha->zio_mode = icb->add_firmware_options[0] &
2545 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2546 ha->zio_timer = icb->interrupt_delay_timer ?
2547 icb->interrupt_delay_timer: 2;
2549 icb->add_firmware_options[0] &=
2550 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2551 vha->flags.process_response_queue = 0;
2552 if (ha->zio_mode != QLA_ZIO_DISABLED) {
2553 ha->zio_mode = QLA_ZIO_MODE_6;
2555 ql_log(ql_log_info, vha, 0x0068,
2556 "ZIO mode %d enabled; timer delay (%d us).\n",
2557 ha->zio_mode, ha->zio_timer * 100);
2559 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2560 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
2561 vha->flags.process_response_queue = 1;
2566 ql_log(ql_log_warn, vha, 0x0069,
2567 "NVRAM configuration failed.\n");
2573 qla2x00_rport_del(void *data)
2575 fc_port_t *fcport = data;
2576 struct fc_rport *rport;
2577 scsi_qla_host_t *vha = fcport->vha;
2578 unsigned long flags;
2580 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
2581 rport = fcport->drport ? fcport->drport: fcport->rport;
2582 fcport->drport = NULL;
2583 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
2585 fc_remote_port_delete(rport);
2587 * Release the target mode FC NEXUS in qla_target.c code
2588 * if target mod is enabled.
2590 qlt_fc_port_deleted(vha, fcport);
2595 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2597 * @flags: allocation flags
2599 * Returns a pointer to the allocated fcport, or NULL, if none available.
2602 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
2606 fcport = kzalloc(sizeof(fc_port_t), flags);
2610 /* Setup fcport template structure. */
2612 fcport->port_type = FCT_UNKNOWN;
2613 fcport->loop_id = FC_NO_LOOP_ID;
2614 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
2615 fcport->supported_classes = FC_COS_UNSPECIFIED;
2616 fcport->scan_state = QLA_FCPORT_SCAN_NONE;
2622 * qla2x00_configure_loop
2623 * Updates Fibre Channel Device Database with what is actually on loop.
2626 * ha = adapter block pointer.
2631 * 2 = database was full and device was not configured.
2634 qla2x00_configure_loop(scsi_qla_host_t *vha)
2637 unsigned long flags, save_flags;
2638 struct qla_hw_data *ha = vha->hw;
2641 /* Get Initiator ID */
2642 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2643 rval = qla2x00_configure_hba(vha);
2644 if (rval != QLA_SUCCESS) {
2645 ql_dbg(ql_dbg_disc, vha, 0x2013,
2646 "Unable to configure HBA.\n");
2651 save_flags = flags = vha->dpc_flags;
2652 ql_dbg(ql_dbg_disc, vha, 0x2014,
2653 "Configure loop -- dpc flags = 0x%lx.\n", flags);
2656 * If we have both an RSCN and PORT UPDATE pending then handle them
2657 * both at the same time.
2659 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2660 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
2662 qla2x00_get_data_rate(vha);
2664 /* Determine what we need to do */
2665 if (ha->current_topology == ISP_CFG_FL &&
2666 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2668 set_bit(RSCN_UPDATE, &flags);
2670 } else if (ha->current_topology == ISP_CFG_F &&
2671 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2673 set_bit(RSCN_UPDATE, &flags);
2674 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2676 } else if (ha->current_topology == ISP_CFG_N) {
2677 clear_bit(RSCN_UPDATE, &flags);
2679 } else if (!vha->flags.online ||
2680 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2682 set_bit(RSCN_UPDATE, &flags);
2683 set_bit(LOCAL_LOOP_UPDATE, &flags);
2686 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
2687 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2688 ql_dbg(ql_dbg_disc, vha, 0x2015,
2689 "Loop resync needed, failing.\n");
2690 rval = QLA_FUNCTION_FAILED;
2692 rval = qla2x00_configure_local_loop(vha);
2695 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
2696 if (LOOP_TRANSITION(vha)) {
2697 ql_dbg(ql_dbg_disc, vha, 0x201e,
2698 "Needs RSCN update and loop transition.\n");
2699 rval = QLA_FUNCTION_FAILED;
2702 rval = qla2x00_configure_fabric(vha);
2705 if (rval == QLA_SUCCESS) {
2706 if (atomic_read(&vha->loop_down_timer) ||
2707 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2708 rval = QLA_FUNCTION_FAILED;
2710 atomic_set(&vha->loop_state, LOOP_READY);
2711 ql_dbg(ql_dbg_disc, vha, 0x2069,
2717 ql_dbg(ql_dbg_disc, vha, 0x206a,
2718 "%s *** FAILED ***.\n", __func__);
2720 ql_dbg(ql_dbg_disc, vha, 0x206b,
2721 "%s: exiting normally.\n", __func__);
2724 /* Restore state if a resync event occurred during processing */
2725 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2726 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
2727 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2728 if (test_bit(RSCN_UPDATE, &save_flags)) {
2729 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2739 * qla2x00_configure_local_loop
2740 * Updates Fibre Channel Device Database with local loop devices.
2743 * ha = adapter block pointer.
2749 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
2754 fc_port_t *fcport, *new_fcport;
2760 uint8_t domain, area, al_pa;
2761 struct qla_hw_data *ha = vha->hw;
2765 entries = MAX_FIBRE_DEVICES_LOOP;
2767 /* Get list of logged in devices. */
2768 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
2769 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
2771 if (rval != QLA_SUCCESS)
2772 goto cleanup_allocation;
2774 ql_dbg(ql_dbg_disc, vha, 0x2017,
2775 "Entries in ID list (%d).\n", entries);
2776 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
2777 (uint8_t *)ha->gid_list,
2778 entries * sizeof(struct gid_list_info));
2780 /* Allocate temporary fcport for any new fcports discovered. */
2781 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2782 if (new_fcport == NULL) {
2783 ql_log(ql_log_warn, vha, 0x2018,
2784 "Memory allocation failed for fcport.\n");
2785 rval = QLA_MEMORY_ALLOC_FAILED;
2786 goto cleanup_allocation;
2788 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2791 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2793 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2794 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2795 fcport->port_type != FCT_BROADCAST &&
2796 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2798 ql_dbg(ql_dbg_disc, vha, 0x2019,
2799 "Marking port lost loop_id=0x%04x.\n",
2802 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
2806 /* Add devices to port list. */
2807 id_iter = (char *)ha->gid_list;
2808 for (index = 0; index < entries; index++) {
2809 domain = ((struct gid_list_info *)id_iter)->domain;
2810 area = ((struct gid_list_info *)id_iter)->area;
2811 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
2812 if (IS_QLA2100(ha) || IS_QLA2200(ha))
2813 loop_id = (uint16_t)
2814 ((struct gid_list_info *)id_iter)->loop_id_2100;
2816 loop_id = le16_to_cpu(
2817 ((struct gid_list_info *)id_iter)->loop_id);
2818 id_iter += ha->gid_list_info_size;
2820 /* Bypass reserved domain fields. */
2821 if ((domain & 0xf0) == 0xf0)
2824 /* Bypass if not same domain and area of adapter. */
2825 if (area && domain &&
2826 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
2829 /* Bypass invalid local loop ID. */
2830 if (loop_id > LAST_LOCAL_LOOP_ID)
2833 memset(new_fcport, 0, sizeof(fc_port_t));
2835 /* Fill in member data. */
2836 new_fcport->d_id.b.domain = domain;
2837 new_fcport->d_id.b.area = area;
2838 new_fcport->d_id.b.al_pa = al_pa;
2839 new_fcport->loop_id = loop_id;
2840 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
2841 if (rval2 != QLA_SUCCESS) {
2842 ql_dbg(ql_dbg_disc, vha, 0x201a,
2843 "Failed to retrieve fcport information "
2844 "-- get_port_database=%x, loop_id=0x%04x.\n",
2845 rval2, new_fcport->loop_id);
2846 ql_dbg(ql_dbg_disc, vha, 0x201b,
2847 "Scheduling resync.\n");
2848 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2852 /* Check for matching device in port list. */
2855 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2856 if (memcmp(new_fcport->port_name, fcport->port_name,
2860 fcport->flags &= ~FCF_FABRIC_DEVICE;
2861 fcport->loop_id = new_fcport->loop_id;
2862 fcport->port_type = new_fcport->port_type;
2863 fcport->d_id.b24 = new_fcport->d_id.b24;
2864 memcpy(fcport->node_name, new_fcport->node_name,
2872 /* New device, add to fcports list. */
2873 list_add_tail(&new_fcport->list, &vha->vp_fcports);
2875 /* Allocate a new replacement fcport. */
2876 fcport = new_fcport;
2877 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2878 if (new_fcport == NULL) {
2879 ql_log(ql_log_warn, vha, 0x201c,
2880 "Failed to allocate memory for fcport.\n");
2881 rval = QLA_MEMORY_ALLOC_FAILED;
2882 goto cleanup_allocation;
2884 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2887 /* Base iIDMA settings on HBA port speed. */
2888 fcport->fp_speed = ha->link_data_rate;
2890 qla2x00_update_fcport(vha, fcport);
2898 if (rval != QLA_SUCCESS) {
2899 ql_dbg(ql_dbg_disc, vha, 0x201d,
2900 "Configure local loop error exit: rval=%x.\n", rval);
2907 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
2912 struct qla_hw_data *ha = vha->hw;
2914 if (!IS_IIDMA_CAPABLE(ha))
2917 if (atomic_read(&fcport->state) != FCS_ONLINE)
2920 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2921 fcport->fp_speed > ha->link_data_rate)
2924 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
2926 if (rval != QLA_SUCCESS) {
2927 ql_dbg(ql_dbg_disc, vha, 0x2004,
2928 "Unable to adjust iIDMA "
2929 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x "
2930 "%04x.\n", fcport->port_name[0], fcport->port_name[1],
2931 fcport->port_name[2], fcport->port_name[3],
2932 fcport->port_name[4], fcport->port_name[5],
2933 fcport->port_name[6], fcport->port_name[7], rval,
2934 fcport->fp_speed, mb[0], mb[1]);
2936 link_speed = qla2x00_get_link_speed_str(ha);
2937 ql_dbg(ql_dbg_disc, vha, 0x2005,
2938 "iIDMA adjusted to %s GB/s "
2939 "on %02x%02x%02x%02x%02x%02x%02x%02x.\n", link_speed,
2940 fcport->port_name[0], fcport->port_name[1],
2941 fcport->port_name[2], fcport->port_name[3],
2942 fcport->port_name[4], fcport->port_name[5],
2943 fcport->port_name[6], fcport->port_name[7]);
2948 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
2950 struct fc_rport_identifiers rport_ids;
2951 struct fc_rport *rport;
2952 unsigned long flags;
2954 qla2x00_rport_del(fcport);
2956 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2957 rport_ids.port_name = wwn_to_u64(fcport->port_name);
2958 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2959 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2960 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2961 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
2963 ql_log(ql_log_warn, vha, 0x2006,
2964 "Unable to allocate fc remote port.\n");
2968 * Create target mode FC NEXUS in qla_target.c if target mode is
2971 qlt_fc_port_added(vha, fcport);
2973 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
2974 *((fc_port_t **)rport->dd_data) = fcport;
2975 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
2977 rport->supported_classes = fcport->supported_classes;
2979 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2980 if (fcport->port_type == FCT_INITIATOR)
2981 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2982 if (fcport->port_type == FCT_TARGET)
2983 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2984 fc_remote_port_rolechg(rport, rport_ids.roles);
2988 * qla2x00_update_fcport
2989 * Updates device on list.
2992 * ha = adapter block pointer.
2993 * fcport = port structure pointer.
3003 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
3006 fcport->login_retry = 0;
3007 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
3009 qla2x00_iidma_fcport(vha, fcport);
3010 qla24xx_update_fcport_fcp_prio(vha, fcport);
3011 qla2x00_reg_remote_port(vha, fcport);
3012 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
3016 * qla2x00_configure_fabric
3017 * Setup SNS devices with loop ID's.
3020 * ha = adapter block pointer.
3027 qla2x00_configure_fabric(scsi_qla_host_t *vha)
3031 uint16_t next_loopid;
3032 uint16_t mb[MAILBOX_REGISTER_COUNT];
3034 LIST_HEAD(new_fcports);
3035 struct qla_hw_data *ha = vha->hw;
3036 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3038 /* If FL port exists, then SNS is present */
3039 if (IS_FWI2_CAPABLE(ha))
3040 loop_id = NPH_F_PORT;
3042 loop_id = SNS_FL_PORT;
3043 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
3044 if (rval != QLA_SUCCESS) {
3045 ql_dbg(ql_dbg_disc, vha, 0x201f,
3046 "MBX_GET_PORT_NAME failed, No FL Port.\n");
3048 vha->device_flags &= ~SWITCH_FOUND;
3049 return (QLA_SUCCESS);
3051 vha->device_flags |= SWITCH_FOUND;
3055 if (ql2xfdmienable &&
3056 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
3057 qla2x00_fdmi_register(vha);
3059 /* Ensure we are logged into the SNS. */
3060 if (IS_FWI2_CAPABLE(ha))
3063 loop_id = SIMPLE_NAME_SERVER;
3064 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
3065 0xfc, mb, BIT_1|BIT_0);
3066 if (rval != QLA_SUCCESS) {
3067 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3070 if (mb[0] != MBS_COMMAND_COMPLETE) {
3071 ql_dbg(ql_dbg_disc, vha, 0x2042,
3072 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
3073 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
3074 mb[2], mb[6], mb[7]);
3075 return (QLA_SUCCESS);
3078 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3079 if (qla2x00_rft_id(vha)) {
3081 ql_dbg(ql_dbg_disc, vha, 0x2045,
3082 "Register FC-4 TYPE failed.\n");
3084 if (qla2x00_rff_id(vha)) {
3086 ql_dbg(ql_dbg_disc, vha, 0x2049,
3087 "Register FC-4 Features failed.\n");
3089 if (qla2x00_rnn_id(vha)) {
3091 ql_dbg(ql_dbg_disc, vha, 0x204f,
3092 "Register Node Name failed.\n");
3093 } else if (qla2x00_rsnn_nn(vha)) {
3095 ql_dbg(ql_dbg_disc, vha, 0x2053,
3096 "Register Symobilic Node Name failed.\n");
3100 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
3101 if (rval != QLA_SUCCESS)
3104 /* Add new ports to existing port list */
3105 list_splice_tail_init(&new_fcports, &vha->vp_fcports);
3107 /* Starting free loop ID. */
3108 next_loopid = ha->min_external_loopid;
3110 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3111 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3114 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3117 /* Logout lost/gone fabric devices (non-FCP2) */
3118 if (fcport->scan_state != QLA_FCPORT_SCAN_FOUND &&
3119 atomic_read(&fcport->state) == FCS_ONLINE) {
3120 qla2x00_mark_device_lost(vha, fcport,
3121 ql2xplogiabsentdevice, 0);
3122 if (fcport->loop_id != FC_NO_LOOP_ID &&
3123 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
3124 fcport->port_type != FCT_INITIATOR &&
3125 fcport->port_type != FCT_BROADCAST) {
3126 ha->isp_ops->fabric_logout(vha,
3128 fcport->d_id.b.domain,
3129 fcport->d_id.b.area,
3130 fcport->d_id.b.al_pa);
3134 fcport->scan_state = QLA_FCPORT_SCAN_NONE;
3136 /* Login fabric devices that need a login */
3137 if ((fcport->flags & FCF_LOGIN_NEEDED) != 0 &&
3138 atomic_read(&vha->loop_down_timer) == 0) {
3139 if (fcport->loop_id == FC_NO_LOOP_ID) {
3140 fcport->loop_id = next_loopid;
3141 rval = qla2x00_find_new_loop_id(
3143 if (rval != QLA_SUCCESS) {
3144 /* Ran out of IDs to use */
3150 /* Login and update database */
3151 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
3156 ql_dbg(ql_dbg_disc, vha, 0x2068,
3157 "Configure fabric error exit rval=%d.\n", rval);
3164 * qla2x00_find_all_fabric_devs
3167 * ha = adapter block pointer.
3168 * dev = database device entry pointer.
3177 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3178 struct list_head *new_fcports)
3182 fc_port_t *fcport, *new_fcport, *fcptemp;
3187 int first_dev, last_dev;
3188 port_id_t wrap = {}, nxt_d_id;
3189 struct qla_hw_data *ha = vha->hw;
3190 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
3191 struct scsi_qla_host *tvp;
3195 /* Try GID_PT to get device list, else GAN. */
3197 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
3202 ql_dbg(ql_dbg_disc, vha, 0x2054,
3203 "GID_PT allocations failed, fallback on GA_NXT.\n");
3205 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
3206 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
3208 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
3210 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
3212 } else if (ql2xiidmaenable &&
3213 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3214 qla2x00_gpsc(vha, swl);
3217 /* If other queries succeeded probe for FC-4 type */
3219 qla2x00_gff_id(vha, swl);
3223 /* Allocate temporary fcport for any new fcports discovered. */
3224 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
3225 if (new_fcport == NULL) {
3226 ql_log(ql_log_warn, vha, 0x205e,
3227 "Failed to allocate memory for fcport.\n");
3228 return (QLA_MEMORY_ALLOC_FAILED);
3230 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3231 /* Set start port ID scan at adapter ID. */
3235 /* Starting free loop ID. */
3236 loop_id = ha->min_external_loopid;
3237 for (; loop_id <= ha->max_loop_id; loop_id++) {
3238 if (qla2x00_is_reserved_id(vha, loop_id))
3241 if (ha->current_topology == ISP_CFG_FL &&
3242 (atomic_read(&vha->loop_down_timer) ||
3243 LOOP_TRANSITION(vha))) {
3244 atomic_set(&vha->loop_down_timer, 0);
3245 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3246 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
3252 wrap.b24 = new_fcport->d_id.b24;
3254 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3255 memcpy(new_fcport->node_name,
3256 swl[swl_idx].node_name, WWN_SIZE);
3257 memcpy(new_fcport->port_name,
3258 swl[swl_idx].port_name, WWN_SIZE);
3259 memcpy(new_fcport->fabric_port_name,
3260 swl[swl_idx].fabric_port_name, WWN_SIZE);
3261 new_fcport->fp_speed = swl[swl_idx].fp_speed;
3262 new_fcport->fc4_type = swl[swl_idx].fc4_type;
3264 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3270 /* Send GA_NXT to the switch */
3271 rval = qla2x00_ga_nxt(vha, new_fcport);
3272 if (rval != QLA_SUCCESS) {
3273 ql_log(ql_log_warn, vha, 0x2064,
3274 "SNS scan failed -- assuming "
3275 "zero-entry result.\n");
3276 list_for_each_entry_safe(fcport, fcptemp,
3277 new_fcports, list) {
3278 list_del(&fcport->list);
3286 /* If wrap on switch device list, exit. */
3288 wrap.b24 = new_fcport->d_id.b24;
3290 } else if (new_fcport->d_id.b24 == wrap.b24) {
3291 ql_dbg(ql_dbg_disc, vha, 0x2065,
3292 "Device wrap (%02x%02x%02x).\n",
3293 new_fcport->d_id.b.domain,
3294 new_fcport->d_id.b.area,
3295 new_fcport->d_id.b.al_pa);
3299 /* Bypass if same physical adapter. */
3300 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
3303 /* Bypass virtual ports of the same host. */
3305 if (ha->num_vhosts) {
3306 unsigned long flags;
3308 spin_lock_irqsave(&ha->vport_slock, flags);
3309 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
3310 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3315 spin_unlock_irqrestore(&ha->vport_slock, flags);
3321 /* Bypass if same domain and area of adapter. */
3322 if (((new_fcport->d_id.b24 & 0xffff00) ==
3323 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
3327 /* Bypass reserved domain fields. */
3328 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3331 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
3332 if (ql2xgffidenable &&
3333 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3334 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
3337 /* Locate matching device in database. */
3339 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3340 if (memcmp(new_fcport->port_name, fcport->port_name,
3344 fcport->scan_state = QLA_FCPORT_SCAN_FOUND;
3348 /* Update port state. */
3349 memcpy(fcport->fabric_port_name,
3350 new_fcport->fabric_port_name, WWN_SIZE);
3351 fcport->fp_speed = new_fcport->fp_speed;
3354 * If address the same and state FCS_ONLINE, nothing
3357 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3358 atomic_read(&fcport->state) == FCS_ONLINE) {
3363 * If device was not a fabric device before.
3365 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3366 fcport->d_id.b24 = new_fcport->d_id.b24;
3367 qla2x00_clear_loop_id(fcport);
3368 fcport->flags |= (FCF_FABRIC_DEVICE |
3374 * Port ID changed or device was marked to be updated;
3375 * Log it out if still logged in and mark it for
3378 fcport->d_id.b24 = new_fcport->d_id.b24;
3379 fcport->flags |= FCF_LOGIN_NEEDED;
3380 if (fcport->loop_id != FC_NO_LOOP_ID &&
3381 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
3382 (fcport->flags & FCF_ASYNC_SENT) == 0 &&
3383 fcport->port_type != FCT_INITIATOR &&
3384 fcport->port_type != FCT_BROADCAST) {
3385 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3386 fcport->d_id.b.domain, fcport->d_id.b.area,
3387 fcport->d_id.b.al_pa);
3388 qla2x00_clear_loop_id(fcport);
3396 /* If device was not in our fcports list, then add it. */
3397 list_add_tail(&new_fcport->list, new_fcports);
3399 /* Allocate a new replacement fcport. */
3400 nxt_d_id.b24 = new_fcport->d_id.b24;
3401 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
3402 if (new_fcport == NULL) {
3403 ql_log(ql_log_warn, vha, 0x2066,
3404 "Memory allocation failed for fcport.\n");
3405 return (QLA_MEMORY_ALLOC_FAILED);
3407 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3408 new_fcport->d_id.b24 = nxt_d_id.b24;
3417 * qla2x00_find_new_loop_id
3418 * Scan through our port list and find a new usable loop ID.
3421 * ha: adapter state pointer.
3422 * dev: port structure pointer.
3425 * qla2x00 local function return status code.
3431 qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
3434 struct qla_hw_data *ha = vha->hw;
3435 unsigned long flags = 0;
3439 spin_lock_irqsave(&ha->vport_slock, flags);
3441 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
3443 if (dev->loop_id >= LOOPID_MAP_SIZE ||
3444 qla2x00_is_reserved_id(vha, dev->loop_id)) {
3445 dev->loop_id = FC_NO_LOOP_ID;
3446 rval = QLA_FUNCTION_FAILED;
3448 set_bit(dev->loop_id, ha->loop_id_map);
3450 spin_unlock_irqrestore(&ha->vport_slock, flags);
3452 if (rval == QLA_SUCCESS)
3453 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
3454 "Assigning new loopid=%x, portid=%x.\n",
3455 dev->loop_id, dev->d_id.b24);
3457 ql_log(ql_log_warn, dev->vha, 0x2087,
3458 "No loop_id's available, portid=%x.\n",
3465 * qla2x00_fabric_dev_login
3466 * Login fabric target device and update FC port database.
3469 * ha: adapter state pointer.
3470 * fcport: port structure list pointer.
3471 * next_loopid: contains value of a new loop ID that can be used
3472 * by the next login attempt.
3475 * qla2x00 local function return status code.
3481 qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
3482 uint16_t *next_loopid)
3487 struct qla_hw_data *ha = vha->hw;
3492 if (IS_ALOGIO_CAPABLE(ha)) {
3493 if (fcport->flags & FCF_ASYNC_SENT)
3495 fcport->flags |= FCF_ASYNC_SENT;
3496 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3501 fcport->flags &= ~FCF_ASYNC_SENT;
3502 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
3503 if (rval == QLA_SUCCESS) {
3504 /* Send an ADISC to FCP2 devices.*/
3506 if (fcport->flags & FCF_FCP2_DEVICE)
3508 rval = qla2x00_get_port_database(vha, fcport, opts);
3509 if (rval != QLA_SUCCESS) {
3510 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3511 fcport->d_id.b.domain, fcport->d_id.b.area,
3512 fcport->d_id.b.al_pa);
3513 qla2x00_mark_device_lost(vha, fcport, 1, 0);
3515 qla2x00_update_fcport(vha, fcport);
3519 qla2x00_mark_device_lost(vha, fcport, 1, 0);
3526 * qla2x00_fabric_login
3527 * Issue fabric login command.
3530 * ha = adapter block pointer.
3531 * device = pointer to FC device type structure.
3534 * 0 - Login successfully
3536 * 2 - Initiator device
3540 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
3541 uint16_t *next_loopid)
3545 uint16_t tmp_loopid;
3546 uint16_t mb[MAILBOX_REGISTER_COUNT];
3547 struct qla_hw_data *ha = vha->hw;
3553 ql_dbg(ql_dbg_disc, vha, 0x2000,
3554 "Trying Fabric Login w/loop id 0x%04x for port "
3556 fcport->loop_id, fcport->d_id.b.domain,
3557 fcport->d_id.b.area, fcport->d_id.b.al_pa);
3559 /* Login fcport on switch. */
3560 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
3561 fcport->d_id.b.domain, fcport->d_id.b.area,
3562 fcport->d_id.b.al_pa, mb, BIT_0);
3563 if (rval != QLA_SUCCESS) {
3566 if (mb[0] == MBS_PORT_ID_USED) {
3568 * Device has another loop ID. The firmware team
3569 * recommends the driver perform an implicit login with
3570 * the specified ID again. The ID we just used is save
3571 * here so we return with an ID that can be tried by
3575 tmp_loopid = fcport->loop_id;
3576 fcport->loop_id = mb[1];
3578 ql_dbg(ql_dbg_disc, vha, 0x2001,
3579 "Fabric Login: port in use - next loop "
3580 "id=0x%04x, port id= %02x%02x%02x.\n",
3581 fcport->loop_id, fcport->d_id.b.domain,
3582 fcport->d_id.b.area, fcport->d_id.b.al_pa);
3584 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3589 /* A retry occurred before. */
3590 *next_loopid = tmp_loopid;
3593 * No retry occurred before. Just increment the
3594 * ID value for next login.
3596 *next_loopid = (fcport->loop_id + 1);
3599 if (mb[1] & BIT_0) {
3600 fcport->port_type = FCT_INITIATOR;
3602 fcport->port_type = FCT_TARGET;
3603 if (mb[1] & BIT_1) {
3604 fcport->flags |= FCF_FCP2_DEVICE;
3609 fcport->supported_classes |= FC_COS_CLASS2;
3611 fcport->supported_classes |= FC_COS_CLASS3;
3613 if (IS_FWI2_CAPABLE(ha)) {
3616 FCF_CONF_COMP_SUPPORTED;
3621 } else if (mb[0] == MBS_LOOP_ID_USED) {
3623 * Loop ID already used, try next loop ID.
3626 rval = qla2x00_find_new_loop_id(vha, fcport);
3627 if (rval != QLA_SUCCESS) {
3628 /* Ran out of loop IDs to use */
3631 } else if (mb[0] == MBS_COMMAND_ERROR) {
3633 * Firmware possibly timed out during login. If NO
3634 * retries are left to do then the device is declared
3637 *next_loopid = fcport->loop_id;
3638 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3639 fcport->d_id.b.domain, fcport->d_id.b.area,
3640 fcport->d_id.b.al_pa);
3641 qla2x00_mark_device_lost(vha, fcport, 1, 0);
3647 * unrecoverable / not handled error
3649 ql_dbg(ql_dbg_disc, vha, 0x2002,
3650 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
3651 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
3652 fcport->d_id.b.area, fcport->d_id.b.al_pa,
3653 fcport->loop_id, jiffies);
3655 *next_loopid = fcport->loop_id;
3656 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3657 fcport->d_id.b.domain, fcport->d_id.b.area,
3658 fcport->d_id.b.al_pa);
3659 qla2x00_clear_loop_id(fcport);
3660 fcport->login_retry = 0;
3671 * qla2x00_local_device_login
3672 * Issue local device login command.
3675 * ha = adapter block pointer.
3676 * loop_id = loop id of device to login to.
3678 * Returns (Where's the #define!!!!):
3679 * 0 - Login successfully
3684 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
3687 uint16_t mb[MAILBOX_REGISTER_COUNT];
3689 memset(mb, 0, sizeof(mb));
3690 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
3691 if (rval == QLA_SUCCESS) {
3692 /* Interrogate mailbox registers for any errors */
3693 if (mb[0] == MBS_COMMAND_ERROR)
3695 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3696 /* device not in PCB table */
3704 * qla2x00_loop_resync
3705 * Resync with fibre channel devices.
3708 * ha = adapter block pointer.
3714 qla2x00_loop_resync(scsi_qla_host_t *vha)
3716 int rval = QLA_SUCCESS;
3718 struct req_que *req;
3719 struct rsp_que *rsp;
3721 if (vha->hw->flags.cpu_affinity_enabled)
3722 req = vha->hw->req_q_map[0];
3727 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3728 if (vha->flags.online) {
3729 if (!(rval = qla2x00_fw_ready(vha))) {
3730 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3733 /* Issue a marker after FW becomes ready. */
3734 qla2x00_marker(vha, req, rsp, 0, 0,
3736 vha->marker_needed = 0;
3738 /* Remap devices on Loop. */
3739 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3741 qla2x00_configure_loop(vha);
3743 } while (!atomic_read(&vha->loop_down_timer) &&
3744 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3745 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3750 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3751 return (QLA_FUNCTION_FAILED);
3754 ql_dbg(ql_dbg_disc, vha, 0x206c,
3755 "%s *** FAILED ***.\n", __func__);
3761 * qla2x00_perform_loop_resync
3762 * Description: This function will set the appropriate flags and call
3763 * qla2x00_loop_resync. If successful loop will be resynced
3764 * Arguments : scsi_qla_host_t pointer
3765 * returm : Success or Failure
3768 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
3772 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
3773 /*Configure the flags so that resync happens properly*/
3774 atomic_set(&ha->loop_down_timer, 0);
3775 if (!(ha->device_flags & DFLG_NO_CABLE)) {
3776 atomic_set(&ha->loop_state, LOOP_UP);
3777 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
3778 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
3779 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3781 rval = qla2x00_loop_resync(ha);
3783 atomic_set(&ha->loop_state, LOOP_DEAD);
3785 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
3792 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
3795 struct scsi_qla_host *vha;
3796 struct qla_hw_data *ha = base_vha->hw;
3797 unsigned long flags;
3799 spin_lock_irqsave(&ha->vport_slock, flags);
3800 /* Go with deferred removal of rport references. */
3801 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
3802 atomic_inc(&vha->vref_count);
3803 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3804 if (fcport->drport &&
3805 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
3806 spin_unlock_irqrestore(&ha->vport_slock, flags);
3808 qla2x00_rport_del(fcport);
3810 spin_lock_irqsave(&ha->vport_slock, flags);
3813 atomic_dec(&vha->vref_count);
3815 spin_unlock_irqrestore(&ha->vport_slock, flags);
3818 /* Assumes idc_lock always held on entry */
3820 qla83xx_reset_ownership(scsi_qla_host_t *vha)
3822 struct qla_hw_data *ha = vha->hw;
3823 uint32_t drv_presence, drv_presence_mask;
3824 uint32_t dev_part_info1, dev_part_info2, class_type;
3825 uint32_t class_type_mask = 0x3;
3826 uint16_t fcoe_other_function = 0xffff, i;
3828 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
3830 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
3831 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
3832 for (i = 0; i < 8; i++) {
3833 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
3834 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
3835 (i != ha->portnum)) {
3836 fcoe_other_function = i;
3840 if (fcoe_other_function == 0xffff) {
3841 for (i = 0; i < 8; i++) {
3842 class_type = ((dev_part_info2 >> (i * 4)) &
3844 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
3845 ((i + 8) != ha->portnum)) {
3846 fcoe_other_function = i + 8;
3852 * Prepare drv-presence mask based on fcoe functions present.
3853 * However consider only valid physical fcoe function numbers (0-15).
3855 drv_presence_mask = ~((1 << (ha->portnum)) |
3856 ((fcoe_other_function == 0xffff) ?
3857 0 : (1 << (fcoe_other_function))));
3859 /* We are the reset owner iff:
3860 * - No other protocol drivers present.
3861 * - This is the lowest among fcoe functions. */
3862 if (!(drv_presence & drv_presence_mask) &&
3863 (ha->portnum < fcoe_other_function)) {
3864 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
3865 "This host is Reset owner.\n");
3866 ha->flags.nic_core_reset_owner = 1;
3871 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
3873 int rval = QLA_SUCCESS;
3874 struct qla_hw_data *ha = vha->hw;
3877 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
3878 if (rval == QLA_SUCCESS) {
3879 drv_ack |= (1 << ha->portnum);
3880 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
3887 qla83xx_set_drv_ack(scsi_qla_host_t *vha)
3889 int rval = QLA_SUCCESS;
3891 qla83xx_idc_lock(vha, 0);
3892 rval = __qla83xx_set_drv_ack(vha);
3893 qla83xx_idc_unlock(vha, 0);
3899 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
3901 int rval = QLA_SUCCESS;
3902 struct qla_hw_data *ha = vha->hw;
3905 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
3906 if (rval == QLA_SUCCESS) {
3907 drv_ack &= ~(1 << ha->portnum);
3908 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
3915 qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
3917 int rval = QLA_SUCCESS;
3919 qla83xx_idc_lock(vha, 0);
3920 rval = __qla83xx_clear_drv_ack(vha);
3921 qla83xx_idc_unlock(vha, 0);
3927 qla83xx_dev_state_to_string(uint32_t dev_state)
3929 switch (dev_state) {
3930 case QLA8XXX_DEV_COLD:
3931 return "COLD/RE-INIT";
3932 case QLA8XXX_DEV_INITIALIZING:
3933 return "INITIALIZING";
3934 case QLA8XXX_DEV_READY:
3936 case QLA8XXX_DEV_NEED_RESET:
3937 return "NEED RESET";
3938 case QLA8XXX_DEV_NEED_QUIESCENT:
3939 return "NEED QUIESCENT";
3940 case QLA8XXX_DEV_FAILED:
3942 case QLA8XXX_DEV_QUIESCENT:
3949 /* Assumes idc-lock always held on entry */
3951 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
3953 struct qla_hw_data *ha = vha->hw;
3954 uint32_t idc_audit_reg = 0, duration_secs = 0;
3956 switch (audit_type) {
3957 case IDC_AUDIT_TIMESTAMP:
3958 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
3959 idc_audit_reg = (ha->portnum) |
3960 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
3961 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
3964 case IDC_AUDIT_COMPLETION:
3965 duration_secs = ((jiffies_to_msecs(jiffies) -
3966 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
3967 idc_audit_reg = (ha->portnum) |
3968 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
3969 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
3973 ql_log(ql_log_warn, vha, 0xb078,
3974 "Invalid audit type specified.\n");
3979 /* Assumes idc_lock always held on entry */
3981 qla83xx_initiating_reset(scsi_qla_host_t *vha)
3983 struct qla_hw_data *ha = vha->hw;
3984 uint32_t idc_control, dev_state;
3986 __qla83xx_get_idc_control(vha, &idc_control);
3987 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
3988 ql_log(ql_log_info, vha, 0xb080,
3989 "NIC Core reset has been disabled. idc-control=0x%x\n",
3991 return QLA_FUNCTION_FAILED;
3994 /* Set NEED-RESET iff in READY state and we are the reset-owner */
3995 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
3996 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
3997 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
3998 QLA8XXX_DEV_NEED_RESET);
3999 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
4000 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
4002 const char *state = qla83xx_dev_state_to_string(dev_state);
4003 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
4005 /* SV: XXX: Is timeout required here? */
4006 /* Wait for IDC state change READY -> NEED_RESET */
4007 while (dev_state == QLA8XXX_DEV_READY) {
4008 qla83xx_idc_unlock(vha, 0);
4010 qla83xx_idc_lock(vha, 0);
4011 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4015 /* Send IDC ack by writing to drv-ack register */
4016 __qla83xx_set_drv_ack(vha);
4022 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
4024 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4028 qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
4030 int rval = QLA_SUCCESS;
4032 qla83xx_idc_lock(vha, 0);
4033 rval = __qla83xx_set_idc_control(vha, idc_control);
4034 qla83xx_idc_unlock(vha, 0);
4040 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
4042 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4046 qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
4048 int rval = QLA_SUCCESS;
4050 qla83xx_idc_lock(vha, 0);
4051 rval = __qla83xx_get_idc_control(vha, idc_control);
4052 qla83xx_idc_unlock(vha, 0);
4058 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
4060 uint32_t drv_presence = 0;
4061 struct qla_hw_data *ha = vha->hw;
4063 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4064 if (drv_presence & (1 << ha->portnum))
4067 return QLA_TEST_FAILED;
4071 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
4073 int rval = QLA_SUCCESS;
4074 struct qla_hw_data *ha = vha->hw;
4076 ql_dbg(ql_dbg_p3p, vha, 0xb058,
4077 "Entered %s().\n", __func__);
4079 if (vha->device_flags & DFLG_DEV_FAILED) {
4080 ql_log(ql_log_warn, vha, 0xb059,
4081 "Device in unrecoverable FAILED state.\n");
4082 return QLA_FUNCTION_FAILED;
4085 qla83xx_idc_lock(vha, 0);
4087 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
4088 ql_log(ql_log_warn, vha, 0xb05a,
4089 "Function=0x%x has been removed from IDC participation.\n",
4091 rval = QLA_FUNCTION_FAILED;
4095 qla83xx_reset_ownership(vha);
4097 rval = qla83xx_initiating_reset(vha);
4100 * Perform reset if we are the reset-owner,
4101 * else wait till IDC state changes to READY/FAILED.
4103 if (rval == QLA_SUCCESS) {
4104 rval = qla83xx_idc_state_handler(vha);
4106 if (rval == QLA_SUCCESS)
4107 ha->flags.nic_core_hung = 0;
4108 __qla83xx_clear_drv_ack(vha);
4112 qla83xx_idc_unlock(vha, 0);
4114 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
4120 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
4122 struct qla_hw_data *ha = vha->hw;
4123 int rval = QLA_FUNCTION_FAILED;
4125 if (!IS_MCTP_CAPABLE(ha)) {
4126 /* This message can be removed from the final version */
4127 ql_log(ql_log_info, vha, 0x506d,
4128 "This board is not MCTP capable\n");
4132 if (!ha->mctp_dump) {
4133 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
4134 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
4136 if (!ha->mctp_dump) {
4137 ql_log(ql_log_warn, vha, 0x506e,
4138 "Failed to allocate memory for mctp dump\n");
4143 #define MCTP_DUMP_STR_ADDR 0x00000000
4144 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
4145 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
4146 if (rval != QLA_SUCCESS) {
4147 ql_log(ql_log_warn, vha, 0x506f,
4148 "Failed to capture mctp dump\n");
4150 ql_log(ql_log_info, vha, 0x5070,
4151 "Mctp dump capture for host (%ld/%p).\n",
4152 vha->host_no, ha->mctp_dump);
4153 ha->mctp_dumped = 1;
4156 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
4157 ha->flags.nic_core_reset_hdlr_active = 1;
4158 rval = qla83xx_restart_nic_firmware(vha);
4160 /* NIC Core reset failed. */
4161 ql_log(ql_log_warn, vha, 0x5071,
4162 "Failed to restart nic firmware\n");
4164 ql_dbg(ql_dbg_p3p, vha, 0xb084,
4165 "Restarted NIC firmware successfully.\n");
4166 ha->flags.nic_core_reset_hdlr_active = 0;
4174 * qla2x00_quiesce_io
4175 * Description: This function will block the new I/Os
4176 * Its not aborting any I/Os as context
4177 * is not destroyed during quiescence
4178 * Arguments: scsi_qla_host_t
4182 qla2x00_quiesce_io(scsi_qla_host_t *vha)
4184 struct qla_hw_data *ha = vha->hw;
4185 struct scsi_qla_host *vp;
4187 ql_dbg(ql_dbg_dpc, vha, 0x401d,
4188 "Quiescing I/O - ha=%p.\n", ha);
4190 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
4191 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4192 atomic_set(&vha->loop_state, LOOP_DOWN);
4193 qla2x00_mark_all_devices_lost(vha, 0);
4194 list_for_each_entry(vp, &ha->vp_list, list)
4195 qla2x00_mark_all_devices_lost(vp, 0);
4197 if (!atomic_read(&vha->loop_down_timer))
4198 atomic_set(&vha->loop_down_timer,
4201 /* Wait for pending cmds to complete */
4202 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
4206 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
4208 struct qla_hw_data *ha = vha->hw;
4209 struct scsi_qla_host *vp;
4210 unsigned long flags;
4213 /* For ISP82XX, driver waits for completion of the commands.
4214 * online flag should be set.
4216 if (!IS_QLA82XX(ha))
4217 vha->flags.online = 0;
4218 ha->flags.chip_reset_done = 0;
4219 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4220 vha->qla_stats.total_isp_aborts++;
4222 ql_log(ql_log_info, vha, 0x00af,
4223 "Performing ISP error recovery - ha=%p.\n", ha);
4225 /* For ISP82XX, reset_chip is just disabling interrupts.
4226 * Driver waits for the completion of the commands.
4227 * the interrupts need to be enabled.
4229 if (!IS_QLA82XX(ha))
4230 ha->isp_ops->reset_chip(vha);
4232 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
4233 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4234 atomic_set(&vha->loop_state, LOOP_DOWN);
4235 qla2x00_mark_all_devices_lost(vha, 0);
4237 spin_lock_irqsave(&ha->vport_slock, flags);
4238 list_for_each_entry(vp, &ha->vp_list, list) {
4239 atomic_inc(&vp->vref_count);
4240 spin_unlock_irqrestore(&ha->vport_slock, flags);
4242 qla2x00_mark_all_devices_lost(vp, 0);
4244 spin_lock_irqsave(&ha->vport_slock, flags);
4245 atomic_dec(&vp->vref_count);
4247 spin_unlock_irqrestore(&ha->vport_slock, flags);
4249 if (!atomic_read(&vha->loop_down_timer))
4250 atomic_set(&vha->loop_down_timer,
4254 /* Clear all async request states across all VPs. */
4255 list_for_each_entry(fcport, &vha->vp_fcports, list)
4256 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4257 spin_lock_irqsave(&ha->vport_slock, flags);
4258 list_for_each_entry(vp, &ha->vp_list, list) {
4259 atomic_inc(&vp->vref_count);
4260 spin_unlock_irqrestore(&ha->vport_slock, flags);
4262 list_for_each_entry(fcport, &vp->vp_fcports, list)
4263 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4265 spin_lock_irqsave(&ha->vport_slock, flags);
4266 atomic_dec(&vp->vref_count);
4268 spin_unlock_irqrestore(&ha->vport_slock, flags);
4270 if (!ha->flags.eeh_busy) {
4271 /* Make sure for ISP 82XX IO DMA is complete */
4272 if (IS_QLA82XX(ha)) {
4273 qla82xx_chip_reset_cleanup(vha);
4274 ql_log(ql_log_info, vha, 0x00b4,
4275 "Done chip reset cleanup.\n");
4277 /* Done waiting for pending commands.
4278 * Reset the online flag.
4280 vha->flags.online = 0;
4283 /* Requeue all commands in outstanding command list. */
4284 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
4290 * Resets ISP and aborts all outstanding commands.
4293 * ha = adapter block pointer.
4299 qla2x00_abort_isp(scsi_qla_host_t *vha)
4303 struct qla_hw_data *ha = vha->hw;
4304 struct scsi_qla_host *vp;
4305 struct req_que *req = ha->req_q_map[0];
4306 unsigned long flags;
4308 if (vha->flags.online) {
4309 qla2x00_abort_isp_cleanup(vha);
4311 if (IS_QLA8031(ha)) {
4312 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
4313 "Clearing fcoe driver presence.\n");
4314 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
4315 ql_dbg(ql_dbg_p3p, vha, 0xb073,
4316 "Error while clearing DRV-Presence.\n");
4319 if (unlikely(pci_channel_offline(ha->pdev) &&
4320 ha->flags.pci_channel_io_perm_failure)) {
4321 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4326 ha->isp_ops->get_flash_version(vha, req->ring);
4328 ha->isp_ops->nvram_config(vha);
4330 if (!qla2x00_restart_isp(vha)) {
4331 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
4333 if (!atomic_read(&vha->loop_down_timer)) {
4335 * Issue marker command only when we are going
4336 * to start the I/O .
4338 vha->marker_needed = 1;
4341 vha->flags.online = 1;
4343 ha->isp_ops->enable_intrs(ha);
4345 ha->isp_abort_cnt = 0;
4346 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4348 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
4349 qla2x00_get_fw_version(vha);
4351 ha->flags.fce_enabled = 1;
4353 fce_calc_size(ha->fce_bufs));
4354 rval = qla2x00_enable_fce_trace(vha,
4355 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
4358 ql_log(ql_log_warn, vha, 0x8033,
4359 "Unable to reinitialize FCE "
4361 ha->flags.fce_enabled = 0;
4366 memset(ha->eft, 0, EFT_SIZE);
4367 rval = qla2x00_enable_eft_trace(vha,
4368 ha->eft_dma, EFT_NUM_BUFFERS);
4370 ql_log(ql_log_warn, vha, 0x8034,
4371 "Unable to reinitialize EFT "
4375 } else { /* failed the ISP abort */
4376 vha->flags.online = 1;
4377 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
4378 if (ha->isp_abort_cnt == 0) {
4379 ql_log(ql_log_fatal, vha, 0x8035,
4380 "ISP error recover failed - "
4381 "board disabled.\n");
4383 * The next call disables the board
4386 ha->isp_ops->reset_adapter(vha);
4387 vha->flags.online = 0;
4388 clear_bit(ISP_ABORT_RETRY,
4391 } else { /* schedule another ISP abort */
4392 ha->isp_abort_cnt--;
4393 ql_dbg(ql_dbg_taskm, vha, 0x8020,
4394 "ISP abort - retry remaining %d.\n",
4399 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
4400 ql_dbg(ql_dbg_taskm, vha, 0x8021,
4401 "ISP error recovery - retrying (%d) "
4402 "more times.\n", ha->isp_abort_cnt);
4403 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4411 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
4413 spin_lock_irqsave(&ha->vport_slock, flags);
4414 list_for_each_entry(vp, &ha->vp_list, list) {
4416 atomic_inc(&vp->vref_count);
4417 spin_unlock_irqrestore(&ha->vport_slock, flags);
4419 qla2x00_vp_abort_isp(vp);
4421 spin_lock_irqsave(&ha->vport_slock, flags);
4422 atomic_dec(&vp->vref_count);
4425 spin_unlock_irqrestore(&ha->vport_slock, flags);
4427 if (IS_QLA8031(ha)) {
4428 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
4429 "Setting back fcoe driver presence.\n");
4430 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
4431 ql_dbg(ql_dbg_p3p, vha, 0xb074,
4432 "Error while setting DRV-Presence.\n");
4435 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
4443 * qla2x00_restart_isp
4444 * restarts the ISP after a reset
4447 * ha = adapter block pointer.
4453 qla2x00_restart_isp(scsi_qla_host_t *vha)
4457 struct qla_hw_data *ha = vha->hw;
4458 struct req_que *req = ha->req_q_map[0];
4459 struct rsp_que *rsp = ha->rsp_q_map[0];
4460 unsigned long flags;
4462 /* If firmware needs to be loaded */
4463 if (qla2x00_isp_firmware(vha)) {
4464 vha->flags.online = 0;
4465 status = ha->isp_ops->chip_diag(vha);
4467 status = qla2x00_setup_chip(vha);
4470 if (!status && !(status = qla2x00_init_rings(vha))) {
4471 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
4472 ha->flags.chip_reset_done = 1;
4473 /* Initialize the queues in use */
4474 qla25xx_init_queues(ha);
4476 status = qla2x00_fw_ready(vha);
4478 ql_dbg(ql_dbg_taskm, vha, 0x8031,
4479 "Start configure loop status = %d.\n", status);
4481 /* Issue a marker after FW becomes ready. */
4482 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
4484 vha->flags.online = 1;
4487 * Process any ATIO queue entries that came in
4488 * while we weren't online.
4490 spin_lock_irqsave(&ha->hardware_lock, flags);
4491 if (qla_tgt_mode_enabled(vha))
4492 qlt_24xx_process_atio_queue(vha);
4493 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4495 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4498 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4499 qla2x00_configure_loop(vha);
4501 } while (!atomic_read(&vha->loop_down_timer) &&
4502 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4503 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4507 /* if no cable then assume it's good */
4508 if ((vha->device_flags & DFLG_NO_CABLE))
4511 ql_dbg(ql_dbg_taskm, vha, 0x8032,
4512 "Configure loop done, status = 0x%x.\n", status);
4518 qla25xx_init_queues(struct qla_hw_data *ha)
4520 struct rsp_que *rsp = NULL;
4521 struct req_que *req = NULL;
4522 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4526 for (i = 1; i < ha->max_rsp_queues; i++) {
4527 rsp = ha->rsp_q_map[i];
4529 rsp->options &= ~BIT_0;
4530 ret = qla25xx_init_rsp_que(base_vha, rsp);
4531 if (ret != QLA_SUCCESS)
4532 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
4533 "%s Rsp que: %d init failed.\n",
4536 ql_dbg(ql_dbg_init, base_vha, 0x0100,
4537 "%s Rsp que: %d inited.\n",
4541 for (i = 1; i < ha->max_req_queues; i++) {
4542 req = ha->req_q_map[i];
4544 /* Clear outstanding commands array. */
4545 req->options &= ~BIT_0;
4546 ret = qla25xx_init_req_que(base_vha, req);
4547 if (ret != QLA_SUCCESS)
4548 ql_dbg(ql_dbg_init, base_vha, 0x0101,
4549 "%s Req que: %d init failed.\n",
4552 ql_dbg(ql_dbg_init, base_vha, 0x0102,
4553 "%s Req que: %d inited.\n",
4561 * qla2x00_reset_adapter
4565 * ha = adapter block pointer.
4568 qla2x00_reset_adapter(scsi_qla_host_t *vha)
4570 unsigned long flags = 0;
4571 struct qla_hw_data *ha = vha->hw;
4572 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4574 vha->flags.online = 0;
4575 ha->isp_ops->disable_intrs(ha);
4577 spin_lock_irqsave(&ha->hardware_lock, flags);
4578 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
4579 RD_REG_WORD(®->hccr); /* PCI Posting. */
4580 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
4581 RD_REG_WORD(®->hccr); /* PCI Posting. */
4582 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4586 qla24xx_reset_adapter(scsi_qla_host_t *vha)
4588 unsigned long flags = 0;
4589 struct qla_hw_data *ha = vha->hw;
4590 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4595 vha->flags.online = 0;
4596 ha->isp_ops->disable_intrs(ha);
4598 spin_lock_irqsave(&ha->hardware_lock, flags);
4599 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
4600 RD_REG_DWORD(®->hccr);
4601 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
4602 RD_REG_DWORD(®->hccr);
4603 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4605 if (IS_NOPOLLING_TYPE(ha))
4606 ha->isp_ops->enable_intrs(ha);
4609 /* On sparc systems, obtain port and node WWN from firmware
4612 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4613 struct nvram_24xx *nv)
4616 struct qla_hw_data *ha = vha->hw;
4617 struct pci_dev *pdev = ha->pdev;
4618 struct device_node *dp = pci_device_to_OF_node(pdev);
4622 val = of_get_property(dp, "port-wwn", &len);
4623 if (val && len >= WWN_SIZE)
4624 memcpy(nv->port_name, val, WWN_SIZE);
4626 val = of_get_property(dp, "node-wwn", &len);
4627 if (val && len >= WWN_SIZE)
4628 memcpy(nv->node_name, val, WWN_SIZE);
4633 qla24xx_nvram_config(scsi_qla_host_t *vha)
4636 struct init_cb_24xx *icb;
4637 struct nvram_24xx *nv;
4639 uint8_t *dptr1, *dptr2;
4642 struct qla_hw_data *ha = vha->hw;
4645 icb = (struct init_cb_24xx *)ha->init_cb;
4648 /* Determine NVRAM starting address. */
4649 if (ha->flags.port0) {
4650 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4651 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4653 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
4654 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4656 ha->nvram_size = sizeof(struct nvram_24xx);
4657 ha->vpd_size = FA_NVRAM_VPD_SIZE;
4659 ha->vpd_size = FA_VPD_SIZE_82XX;
4661 /* Get VPD data into cache */
4662 ha->vpd = ha->nvram + VPD_OFFSET;
4663 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
4664 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4666 /* Get NVRAM data into cache and calculate checksum. */
4667 dptr = (uint32_t *)nv;
4668 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
4670 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4671 chksum += le32_to_cpu(*dptr++);
4673 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
4674 "Contents of NVRAM\n");
4675 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
4676 (uint8_t *)nv, ha->nvram_size);
4678 /* Bad NVRAM data, set defaults parameters. */
4679 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4680 || nv->id[3] != ' ' ||
4681 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4682 /* Reset NVRAM data. */
4683 ql_log(ql_log_warn, vha, 0x006b,
4684 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
4685 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
4686 ql_log(ql_log_warn, vha, 0x006c,
4687 "Falling back to functioning (yet invalid -- WWPN) "
4691 * Set default initialization control block.
4693 memset(nv, 0, ha->nvram_size);
4694 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4695 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4696 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4697 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4698 nv->exchange_count = __constant_cpu_to_le16(0);
4699 nv->hard_address = __constant_cpu_to_le16(124);
4700 nv->port_name[0] = 0x21;
4701 nv->port_name[1] = 0x00 + ha->port_no;
4702 nv->port_name[2] = 0x00;
4703 nv->port_name[3] = 0xe0;
4704 nv->port_name[4] = 0x8b;
4705 nv->port_name[5] = 0x1c;
4706 nv->port_name[6] = 0x55;
4707 nv->port_name[7] = 0x86;
4708 nv->node_name[0] = 0x20;
4709 nv->node_name[1] = 0x00;
4710 nv->node_name[2] = 0x00;
4711 nv->node_name[3] = 0xe0;
4712 nv->node_name[4] = 0x8b;
4713 nv->node_name[5] = 0x1c;
4714 nv->node_name[6] = 0x55;
4715 nv->node_name[7] = 0x86;
4716 qla24xx_nvram_wwn_from_ofw(vha, nv);
4717 nv->login_retry_count = __constant_cpu_to_le16(8);
4718 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4719 nv->login_timeout = __constant_cpu_to_le16(0);
4720 nv->firmware_options_1 =
4721 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4722 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4723 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4724 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4725 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4726 nv->efi_parameters = __constant_cpu_to_le32(0);
4727 nv->reset_delay = 5;
4728 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4729 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4730 nv->link_down_timeout = __constant_cpu_to_le16(30);
4735 if (!qla_ini_mode_enabled(vha)) {
4736 /* Don't enable full login after initial LIP */
4737 nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13);
4738 /* Don't enable LIP full login for initiator */
4739 nv->host_p &= __constant_cpu_to_le32(~BIT_10);
4742 qlt_24xx_config_nvram_stage1(vha, nv);
4744 /* Reset Initialization control block */
4745 memset(icb, 0, ha->init_cb_size);
4747 /* Copy 1st segment. */
4748 dptr1 = (uint8_t *)icb;
4749 dptr2 = (uint8_t *)&nv->version;
4750 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4752 *dptr1++ = *dptr2++;
4754 icb->login_retry_count = nv->login_retry_count;
4755 icb->link_down_on_nos = nv->link_down_on_nos;
4757 /* Copy 2nd segment. */
4758 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4759 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4760 cnt = (uint8_t *)&icb->reserved_3 -
4761 (uint8_t *)&icb->interrupt_delay_timer;
4763 *dptr1++ = *dptr2++;
4766 * Setup driver NVRAM options.
4768 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4771 qlt_24xx_config_nvram_stage2(vha, icb);
4773 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4774 /* Use alternate WWN? */
4775 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4776 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4779 /* Prepare nodename */
4780 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4782 * Firmware will apply the following mask if the nodename was
4785 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4786 icb->node_name[0] &= 0xF0;
4789 /* Set host adapter parameters. */
4790 ha->flags.disable_risc_code_load = 0;
4791 ha->flags.enable_lip_reset = 0;
4792 ha->flags.enable_lip_full_login =
4793 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4794 ha->flags.enable_target_reset =
4795 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4796 ha->flags.enable_led_scheme = 0;
4797 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4799 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4800 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4802 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4803 sizeof(ha->fw_seriallink_options24));
4805 /* save HBA serial number */
4806 ha->serial0 = icb->port_name[5];
4807 ha->serial1 = icb->port_name[6];
4808 ha->serial2 = icb->port_name[7];
4809 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4810 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4812 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4814 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4816 /* Set minimum login_timeout to 4 seconds. */
4817 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4818 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4819 if (le16_to_cpu(nv->login_timeout) < 4)
4820 nv->login_timeout = __constant_cpu_to_le16(4);
4821 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4822 icb->login_timeout = nv->login_timeout;
4824 /* Set minimum RATOV to 100 tenths of a second. */
4827 ha->loop_reset_delay = nv->reset_delay;
4829 /* Link Down Timeout = 0:
4831 * When Port Down timer expires we will start returning
4832 * I/O's to OS with "DID_NO_CONNECT".
4834 * Link Down Timeout != 0:
4836 * The driver waits for the link to come up after link down
4837 * before returning I/Os to OS with "DID_NO_CONNECT".
4839 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4840 ha->loop_down_abort_time =
4841 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4843 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4844 ha->loop_down_abort_time =
4845 (LOOP_DOWN_TIME - ha->link_down_timeout);
4848 /* Need enough time to try and get the port back. */
4849 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4850 if (qlport_down_retry)
4851 ha->port_down_retry_count = qlport_down_retry;
4853 /* Set login_retry_count */
4854 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4855 if (ha->port_down_retry_count ==
4856 le16_to_cpu(nv->port_down_retry_count) &&
4857 ha->port_down_retry_count > 3)
4858 ha->login_retry_count = ha->port_down_retry_count;
4859 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4860 ha->login_retry_count = ha->port_down_retry_count;
4861 if (ql2xloginretrycount)
4862 ha->login_retry_count = ql2xloginretrycount;
4865 if (!vha->flags.init_done) {
4866 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4867 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4868 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4869 le16_to_cpu(icb->interrupt_delay_timer): 2;
4871 icb->firmware_options_2 &= __constant_cpu_to_le32(
4872 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4873 vha->flags.process_response_queue = 0;
4874 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4875 ha->zio_mode = QLA_ZIO_MODE_6;
4877 ql_log(ql_log_info, vha, 0x006f,
4878 "ZIO mode %d enabled; timer delay (%d us).\n",
4879 ha->zio_mode, ha->zio_timer * 100);
4881 icb->firmware_options_2 |= cpu_to_le32(
4882 (uint32_t)ha->zio_mode);
4883 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4884 vha->flags.process_response_queue = 1;
4888 ql_log(ql_log_warn, vha, 0x0070,
4889 "NVRAM configuration failed.\n");
4895 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4898 int rval = QLA_SUCCESS;
4899 int segments, fragment;
4900 uint32_t *dcode, dlen;
4904 struct qla_hw_data *ha = vha->hw;
4905 struct req_que *req = ha->req_q_map[0];
4907 ql_dbg(ql_dbg_init, vha, 0x008b,
4908 "FW: Loading firmware from flash (%x).\n", faddr);
4912 segments = FA_RISC_CODE_SEGMENTS;
4913 dcode = (uint32_t *)req->ring;
4916 /* Validate firmware image by checking version. */
4917 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
4918 for (i = 0; i < 4; i++)
4919 dcode[i] = be32_to_cpu(dcode[i]);
4920 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4921 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4922 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4924 ql_log(ql_log_fatal, vha, 0x008c,
4925 "Unable to verify the integrity of flash firmware "
4927 ql_log(ql_log_fatal, vha, 0x008d,
4928 "Firmware data: %08x %08x %08x %08x.\n",
4929 dcode[0], dcode[1], dcode[2], dcode[3]);
4931 return QLA_FUNCTION_FAILED;
4934 while (segments && rval == QLA_SUCCESS) {
4935 /* Read segment's load information. */
4936 qla24xx_read_flash_data(vha, dcode, faddr, 4);
4938 risc_addr = be32_to_cpu(dcode[2]);
4939 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4940 risc_size = be32_to_cpu(dcode[3]);
4943 while (risc_size > 0 && rval == QLA_SUCCESS) {
4944 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4945 if (dlen > risc_size)
4948 ql_dbg(ql_dbg_init, vha, 0x008e,
4949 "Loading risc segment@ risc addr %x "
4950 "number of dwords 0x%x offset 0x%x.\n",
4951 risc_addr, dlen, faddr);
4953 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
4954 for (i = 0; i < dlen; i++)
4955 dcode[i] = swab32(dcode[i]);
4957 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
4960 ql_log(ql_log_fatal, vha, 0x008f,
4961 "Failed to load segment %d of firmware.\n",
4979 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4982 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4986 uint16_t *wcode, *fwcode;
4987 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4988 struct fw_blob *blob;
4989 struct qla_hw_data *ha = vha->hw;
4990 struct req_que *req = ha->req_q_map[0];
4992 /* Load firmware blob. */
4993 blob = qla2x00_request_firmware(vha);
4995 ql_log(ql_log_info, vha, 0x0083,
4996 "Fimware image unavailable.\n");
4997 ql_log(ql_log_info, vha, 0x0084,
4998 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
4999 return QLA_FUNCTION_FAILED;
5004 wcode = (uint16_t *)req->ring;
5006 fwcode = (uint16_t *)blob->fw->data;
5009 /* Validate firmware image by checking version. */
5010 if (blob->fw->size < 8 * sizeof(uint16_t)) {
5011 ql_log(ql_log_fatal, vha, 0x0085,
5012 "Unable to verify integrity of firmware image (%Zd).\n",
5014 goto fail_fw_integrity;
5016 for (i = 0; i < 4; i++)
5017 wcode[i] = be16_to_cpu(fwcode[i + 4]);
5018 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
5019 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
5020 wcode[2] == 0 && wcode[3] == 0)) {
5021 ql_log(ql_log_fatal, vha, 0x0086,
5022 "Unable to verify integrity of firmware image.\n");
5023 ql_log(ql_log_fatal, vha, 0x0087,
5024 "Firmware data: %04x %04x %04x %04x.\n",
5025 wcode[0], wcode[1], wcode[2], wcode[3]);
5026 goto fail_fw_integrity;
5030 while (*seg && rval == QLA_SUCCESS) {
5032 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
5033 risc_size = be16_to_cpu(fwcode[3]);
5035 /* Validate firmware image size. */
5036 fwclen += risc_size * sizeof(uint16_t);
5037 if (blob->fw->size < fwclen) {
5038 ql_log(ql_log_fatal, vha, 0x0088,
5039 "Unable to verify integrity of firmware image "
5040 "(%Zd).\n", blob->fw->size);
5041 goto fail_fw_integrity;
5045 while (risc_size > 0 && rval == QLA_SUCCESS) {
5046 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
5047 if (wlen > risc_size)
5049 ql_dbg(ql_dbg_init, vha, 0x0089,
5050 "Loading risc segment@ risc addr %x number of "
5051 "words 0x%x.\n", risc_addr, wlen);
5053 for (i = 0; i < wlen; i++)
5054 wcode[i] = swab16(fwcode[i]);
5056 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
5059 ql_log(ql_log_fatal, vha, 0x008a,
5060 "Failed to load segment %d of firmware.\n",
5077 return QLA_FUNCTION_FAILED;
5081 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5084 int segments, fragment;
5085 uint32_t *dcode, dlen;
5089 struct fw_blob *blob;
5090 uint32_t *fwcode, fwclen;
5091 struct qla_hw_data *ha = vha->hw;
5092 struct req_que *req = ha->req_q_map[0];
5094 /* Load firmware blob. */
5095 blob = qla2x00_request_firmware(vha);
5097 ql_log(ql_log_warn, vha, 0x0090,
5098 "Fimware image unavailable.\n");
5099 ql_log(ql_log_warn, vha, 0x0091,
5100 "Firmware images can be retrieved from: "
5103 return QLA_FUNCTION_FAILED;
5106 ql_dbg(ql_dbg_init, vha, 0x0092,
5107 "FW: Loading via request-firmware.\n");
5111 segments = FA_RISC_CODE_SEGMENTS;
5112 dcode = (uint32_t *)req->ring;
5114 fwcode = (uint32_t *)blob->fw->data;
5117 /* Validate firmware image by checking version. */
5118 if (blob->fw->size < 8 * sizeof(uint32_t)) {
5119 ql_log(ql_log_fatal, vha, 0x0093,
5120 "Unable to verify integrity of firmware image (%Zd).\n",
5122 goto fail_fw_integrity;
5124 for (i = 0; i < 4; i++)
5125 dcode[i] = be32_to_cpu(fwcode[i + 4]);
5126 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5127 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5128 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5130 ql_log(ql_log_fatal, vha, 0x0094,
5131 "Unable to verify integrity of firmware image (%Zd).\n",
5133 ql_log(ql_log_fatal, vha, 0x0095,
5134 "Firmware data: %08x %08x %08x %08x.\n",
5135 dcode[0], dcode[1], dcode[2], dcode[3]);
5136 goto fail_fw_integrity;
5139 while (segments && rval == QLA_SUCCESS) {
5140 risc_addr = be32_to_cpu(fwcode[2]);
5141 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5142 risc_size = be32_to_cpu(fwcode[3]);
5144 /* Validate firmware image size. */
5145 fwclen += risc_size * sizeof(uint32_t);
5146 if (blob->fw->size < fwclen) {
5147 ql_log(ql_log_fatal, vha, 0x0096,
5148 "Unable to verify integrity of firmware image "
5149 "(%Zd).\n", blob->fw->size);
5151 goto fail_fw_integrity;
5155 while (risc_size > 0 && rval == QLA_SUCCESS) {
5156 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5157 if (dlen > risc_size)
5160 ql_dbg(ql_dbg_init, vha, 0x0097,
5161 "Loading risc segment@ risc addr %x "
5162 "number of dwords 0x%x.\n", risc_addr, dlen);
5164 for (i = 0; i < dlen; i++)
5165 dcode[i] = swab32(fwcode[i]);
5167 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
5170 ql_log(ql_log_fatal, vha, 0x0098,
5171 "Failed to load segment %d of firmware.\n",
5188 return QLA_FUNCTION_FAILED;
5192 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5196 if (ql2xfwloadbin == 1)
5197 return qla81xx_load_risc(vha, srisc_addr);
5201 * 1) Firmware via request-firmware interface (.bin file).
5202 * 2) Firmware residing in flash.
5204 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5205 if (rval == QLA_SUCCESS)
5208 return qla24xx_load_risc_flash(vha, srisc_addr,
5209 vha->hw->flt_region_fw);
5213 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5216 struct qla_hw_data *ha = vha->hw;
5218 if (ql2xfwloadbin == 2)
5223 * 1) Firmware residing in flash.
5224 * 2) Firmware via request-firmware interface (.bin file).
5225 * 3) Golden-Firmware residing in flash -- limited operation.
5227 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
5228 if (rval == QLA_SUCCESS)
5232 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5233 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
5236 ql_log(ql_log_info, vha, 0x0099,
5237 "Attempting to fallback to golden firmware.\n");
5238 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
5239 if (rval != QLA_SUCCESS)
5242 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
5243 ha->flags.running_gold_fw = 1;
5248 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
5251 struct qla_hw_data *ha = vha->hw;
5253 if (ha->flags.pci_channel_io_perm_failure)
5255 if (!IS_FWI2_CAPABLE(ha))
5257 if (!ha->fw_major_version)
5260 ret = qla2x00_stop_firmware(vha);
5261 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
5262 ret != QLA_INVALID_COMMAND && retries ; retries--) {
5263 ha->isp_ops->reset_chip(vha);
5264 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
5266 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
5268 ql_log(ql_log_info, vha, 0x8015,
5269 "Attempting retry of stop-firmware command.\n");
5270 ret = qla2x00_stop_firmware(vha);
5275 qla24xx_configure_vhba(scsi_qla_host_t *vha)
5277 int rval = QLA_SUCCESS;
5279 uint16_t mb[MAILBOX_REGISTER_COUNT];
5280 struct qla_hw_data *ha = vha->hw;
5281 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5282 struct req_que *req;
5283 struct rsp_que *rsp;
5288 rval = qla2x00_fw_ready(base_vha);
5289 if (ha->flags.cpu_affinity_enabled)
5290 req = ha->req_q_map[0];
5295 if (rval == QLA_SUCCESS) {
5296 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5297 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5300 vha->flags.management_server_logged_in = 0;
5302 /* Login to SNS first */
5303 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
5305 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5306 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
5307 ql_dbg(ql_dbg_init, vha, 0x0120,
5308 "Failed SNS login: loop_id=%x, rval2=%d\n",
5311 ql_dbg(ql_dbg_init, vha, 0x0103,
5312 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
5313 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
5314 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
5315 return (QLA_FUNCTION_FAILED);
5318 atomic_set(&vha->loop_down_timer, 0);
5319 atomic_set(&vha->loop_state, LOOP_UP);
5320 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5321 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5322 rval = qla2x00_loop_resync(base_vha);
5327 /* 84XX Support **************************************************************/
5329 static LIST_HEAD(qla_cs84xx_list);
5330 static DEFINE_MUTEX(qla_cs84xx_mutex);
5332 static struct qla_chip_state_84xx *
5333 qla84xx_get_chip(struct scsi_qla_host *vha)
5335 struct qla_chip_state_84xx *cs84xx;
5336 struct qla_hw_data *ha = vha->hw;
5338 mutex_lock(&qla_cs84xx_mutex);
5340 /* Find any shared 84xx chip. */
5341 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
5342 if (cs84xx->bus == ha->pdev->bus) {
5343 kref_get(&cs84xx->kref);
5348 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
5352 kref_init(&cs84xx->kref);
5353 spin_lock_init(&cs84xx->access_lock);
5354 mutex_init(&cs84xx->fw_update_mutex);
5355 cs84xx->bus = ha->pdev->bus;
5357 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
5359 mutex_unlock(&qla_cs84xx_mutex);
5364 __qla84xx_chip_release(struct kref *kref)
5366 struct qla_chip_state_84xx *cs84xx =
5367 container_of(kref, struct qla_chip_state_84xx, kref);
5369 mutex_lock(&qla_cs84xx_mutex);
5370 list_del(&cs84xx->list);
5371 mutex_unlock(&qla_cs84xx_mutex);
5376 qla84xx_put_chip(struct scsi_qla_host *vha)
5378 struct qla_hw_data *ha = vha->hw;
5380 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
5384 qla84xx_init_chip(scsi_qla_host_t *vha)
5388 struct qla_hw_data *ha = vha->hw;
5390 mutex_lock(&ha->cs84xx->fw_update_mutex);
5392 rval = qla84xx_verify_chip(vha, status);
5394 mutex_unlock(&ha->cs84xx->fw_update_mutex);
5396 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
5400 /* 81XX Support **************************************************************/
5403 qla81xx_nvram_config(scsi_qla_host_t *vha)
5406 struct init_cb_81xx *icb;
5407 struct nvram_81xx *nv;
5409 uint8_t *dptr1, *dptr2;
5412 struct qla_hw_data *ha = vha->hw;
5415 icb = (struct init_cb_81xx *)ha->init_cb;
5418 /* Determine NVRAM starting address. */
5419 ha->nvram_size = sizeof(struct nvram_81xx);
5420 ha->vpd_size = FA_NVRAM_VPD_SIZE;
5422 /* Get VPD data into cache */
5423 ha->vpd = ha->nvram + VPD_OFFSET;
5424 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
5427 /* Get NVRAM data into cache and calculate checksum. */
5428 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
5430 dptr = (uint32_t *)nv;
5431 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5432 chksum += le32_to_cpu(*dptr++);
5434 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
5435 "Contents of NVRAM:\n");
5436 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
5437 (uint8_t *)nv, ha->nvram_size);
5439 /* Bad NVRAM data, set defaults parameters. */
5440 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5441 || nv->id[3] != ' ' ||
5442 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
5443 /* Reset NVRAM data. */
5444 ql_log(ql_log_info, vha, 0x0073,
5445 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
5446 "version=0x%x.\n", chksum, nv->id[0],
5447 le16_to_cpu(nv->nvram_version));
5448 ql_log(ql_log_info, vha, 0x0074,
5449 "Falling back to functioning (yet invalid -- WWPN) "
5453 * Set default initialization control block.
5455 memset(nv, 0, ha->nvram_size);
5456 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5457 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5458 nv->frame_payload_size = __constant_cpu_to_le16(2048);
5459 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5460 nv->exchange_count = __constant_cpu_to_le16(0);
5461 nv->port_name[0] = 0x21;
5462 nv->port_name[1] = 0x00 + ha->port_no;
5463 nv->port_name[2] = 0x00;
5464 nv->port_name[3] = 0xe0;
5465 nv->port_name[4] = 0x8b;
5466 nv->port_name[5] = 0x1c;
5467 nv->port_name[6] = 0x55;
5468 nv->port_name[7] = 0x86;
5469 nv->node_name[0] = 0x20;
5470 nv->node_name[1] = 0x00;
5471 nv->node_name[2] = 0x00;
5472 nv->node_name[3] = 0xe0;
5473 nv->node_name[4] = 0x8b;
5474 nv->node_name[5] = 0x1c;
5475 nv->node_name[6] = 0x55;
5476 nv->node_name[7] = 0x86;
5477 nv->login_retry_count = __constant_cpu_to_le16(8);
5478 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5479 nv->login_timeout = __constant_cpu_to_le16(0);
5480 nv->firmware_options_1 =
5481 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5482 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5483 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5484 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5485 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5486 nv->efi_parameters = __constant_cpu_to_le32(0);
5487 nv->reset_delay = 5;
5488 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5489 nv->port_down_retry_count = __constant_cpu_to_le16(30);
5490 nv->link_down_timeout = __constant_cpu_to_le16(180);
5491 nv->enode_mac[0] = 0x00;
5492 nv->enode_mac[1] = 0xC0;
5493 nv->enode_mac[2] = 0xDD;
5494 nv->enode_mac[3] = 0x04;
5495 nv->enode_mac[4] = 0x05;
5496 nv->enode_mac[5] = 0x06 + ha->port_no;
5501 if (IS_T10_PI_CAPABLE(ha))
5502 nv->frame_payload_size &= ~7;
5504 /* Reset Initialization control block */
5505 memset(icb, 0, ha->init_cb_size);
5507 /* Copy 1st segment. */
5508 dptr1 = (uint8_t *)icb;
5509 dptr2 = (uint8_t *)&nv->version;
5510 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5512 *dptr1++ = *dptr2++;
5514 icb->login_retry_count = nv->login_retry_count;
5516 /* Copy 2nd segment. */
5517 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5518 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5519 cnt = (uint8_t *)&icb->reserved_5 -
5520 (uint8_t *)&icb->interrupt_delay_timer;
5522 *dptr1++ = *dptr2++;
5524 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5525 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5526 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
5527 icb->enode_mac[0] = 0x00;
5528 icb->enode_mac[1] = 0xC0;
5529 icb->enode_mac[2] = 0xDD;
5530 icb->enode_mac[3] = 0x04;
5531 icb->enode_mac[4] = 0x05;
5532 icb->enode_mac[5] = 0x06 + ha->port_no;
5535 /* Use extended-initialization control block. */
5536 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5539 * Setup driver NVRAM options.
5541 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
5544 /* Use alternate WWN? */
5545 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5546 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5547 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5550 /* Prepare nodename */
5551 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5553 * Firmware will apply the following mask if the nodename was
5556 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5557 icb->node_name[0] &= 0xF0;
5560 /* Set host adapter parameters. */
5561 ha->flags.disable_risc_code_load = 0;
5562 ha->flags.enable_lip_reset = 0;
5563 ha->flags.enable_lip_full_login =
5564 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5565 ha->flags.enable_target_reset =
5566 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5567 ha->flags.enable_led_scheme = 0;
5568 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5570 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5571 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5573 /* save HBA serial number */
5574 ha->serial0 = icb->port_name[5];
5575 ha->serial1 = icb->port_name[6];
5576 ha->serial2 = icb->port_name[7];
5577 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5578 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5580 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5582 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5584 /* Set minimum login_timeout to 4 seconds. */
5585 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5586 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5587 if (le16_to_cpu(nv->login_timeout) < 4)
5588 nv->login_timeout = __constant_cpu_to_le16(4);
5589 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5590 icb->login_timeout = nv->login_timeout;
5592 /* Set minimum RATOV to 100 tenths of a second. */
5595 ha->loop_reset_delay = nv->reset_delay;
5597 /* Link Down Timeout = 0:
5599 * When Port Down timer expires we will start returning
5600 * I/O's to OS with "DID_NO_CONNECT".
5602 * Link Down Timeout != 0:
5604 * The driver waits for the link to come up after link down
5605 * before returning I/Os to OS with "DID_NO_CONNECT".
5607 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5608 ha->loop_down_abort_time =
5609 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5611 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5612 ha->loop_down_abort_time =
5613 (LOOP_DOWN_TIME - ha->link_down_timeout);
5616 /* Need enough time to try and get the port back. */
5617 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5618 if (qlport_down_retry)
5619 ha->port_down_retry_count = qlport_down_retry;
5621 /* Set login_retry_count */
5622 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5623 if (ha->port_down_retry_count ==
5624 le16_to_cpu(nv->port_down_retry_count) &&
5625 ha->port_down_retry_count > 3)
5626 ha->login_retry_count = ha->port_down_retry_count;
5627 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5628 ha->login_retry_count = ha->port_down_retry_count;
5629 if (ql2xloginretrycount)
5630 ha->login_retry_count = ql2xloginretrycount;
5632 /* if not running MSI-X we need handshaking on interrupts */
5633 if (!vha->hw->flags.msix_enabled && IS_QLA83XX(ha))
5634 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
5637 if (!vha->flags.init_done) {
5638 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5639 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5640 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5641 le16_to_cpu(icb->interrupt_delay_timer): 2;
5643 icb->firmware_options_2 &= __constant_cpu_to_le32(
5644 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5645 vha->flags.process_response_queue = 0;
5646 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5647 ha->zio_mode = QLA_ZIO_MODE_6;
5649 ql_log(ql_log_info, vha, 0x0075,
5650 "ZIO mode %d enabled; timer delay (%d us).\n",
5652 ha->zio_timer * 100);
5654 icb->firmware_options_2 |= cpu_to_le32(
5655 (uint32_t)ha->zio_mode);
5656 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5657 vha->flags.process_response_queue = 1;
5661 ql_log(ql_log_warn, vha, 0x0076,
5662 "NVRAM configuration failed.\n");
5668 qla82xx_restart_isp(scsi_qla_host_t *vha)
5672 struct qla_hw_data *ha = vha->hw;
5673 struct req_que *req = ha->req_q_map[0];
5674 struct rsp_que *rsp = ha->rsp_q_map[0];
5675 struct scsi_qla_host *vp;
5676 unsigned long flags;
5678 status = qla2x00_init_rings(vha);
5680 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5681 ha->flags.chip_reset_done = 1;
5683 status = qla2x00_fw_ready(vha);
5685 ql_log(ql_log_info, vha, 0x803c,
5686 "Start configure loop, status =%d.\n", status);
5688 /* Issue a marker after FW becomes ready. */
5689 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5691 vha->flags.online = 1;
5692 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5695 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5696 qla2x00_configure_loop(vha);
5698 } while (!atomic_read(&vha->loop_down_timer) &&
5699 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5701 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5704 /* if no cable then assume it's good */
5705 if ((vha->device_flags & DFLG_NO_CABLE))
5708 ql_log(ql_log_info, vha, 0x8000,
5709 "Configure loop done, status = 0x%x.\n", status);
5713 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5715 if (!atomic_read(&vha->loop_down_timer)) {
5717 * Issue marker command only when we are going
5718 * to start the I/O .
5720 vha->marker_needed = 1;
5723 vha->flags.online = 1;
5725 ha->isp_ops->enable_intrs(ha);
5727 ha->isp_abort_cnt = 0;
5728 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5730 /* Update the firmware version */
5731 status = qla82xx_check_md_needed(vha);
5734 ha->flags.fce_enabled = 1;
5736 fce_calc_size(ha->fce_bufs));
5737 rval = qla2x00_enable_fce_trace(vha,
5738 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5741 ql_log(ql_log_warn, vha, 0x8001,
5742 "Unable to reinitialize FCE (%d).\n",
5744 ha->flags.fce_enabled = 0;
5749 memset(ha->eft, 0, EFT_SIZE);
5750 rval = qla2x00_enable_eft_trace(vha,
5751 ha->eft_dma, EFT_NUM_BUFFERS);
5753 ql_log(ql_log_warn, vha, 0x8010,
5754 "Unable to reinitialize EFT (%d).\n",
5761 ql_dbg(ql_dbg_taskm, vha, 0x8011,
5762 "qla82xx_restart_isp succeeded.\n");
5764 spin_lock_irqsave(&ha->vport_slock, flags);
5765 list_for_each_entry(vp, &ha->vp_list, list) {
5767 atomic_inc(&vp->vref_count);
5768 spin_unlock_irqrestore(&ha->vport_slock, flags);
5770 qla2x00_vp_abort_isp(vp);
5772 spin_lock_irqsave(&ha->vport_slock, flags);
5773 atomic_dec(&vp->vref_count);
5776 spin_unlock_irqrestore(&ha->vport_slock, flags);
5779 ql_log(ql_log_warn, vha, 0x8016,
5780 "qla82xx_restart_isp **** FAILED ****.\n");
5787 qla81xx_update_fw_options(scsi_qla_host_t *vha)
5789 struct qla_hw_data *ha = vha->hw;
5794 /* Enable ETS Burst. */
5795 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5796 ha->fw_options[2] |= BIT_9;
5797 qla2x00_set_fw_options(vha, ha->fw_options);
5801 * qla24xx_get_fcp_prio
5802 * Gets the fcp cmd priority value for the logged in port.
5803 * Looks for a match of the port descriptors within
5804 * each of the fcp prio config entries. If a match is found,
5805 * the tag (priority) value is returned.
5808 * vha = scsi host structure pointer.
5809 * fcport = port structure pointer.
5812 * non-zero (if found)
5819 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5822 uint8_t pid_match, wwn_match;
5824 uint32_t pid1, pid2;
5825 uint64_t wwn1, wwn2;
5826 struct qla_fcp_prio_entry *pri_entry;
5827 struct qla_hw_data *ha = vha->hw;
5829 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
5833 entries = ha->fcp_prio_cfg->num_entries;
5834 pri_entry = &ha->fcp_prio_cfg->entry[0];
5836 for (i = 0; i < entries; i++) {
5837 pid_match = wwn_match = 0;
5839 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5844 /* check source pid for a match */
5845 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5846 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5847 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5848 if (pid1 == INVALID_PORT_ID)
5850 else if (pid1 == pid2)
5854 /* check destination pid for a match */
5855 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5856 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5857 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5858 if (pid1 == INVALID_PORT_ID)
5860 else if (pid1 == pid2)
5864 /* check source WWN for a match */
5865 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5866 wwn1 = wwn_to_u64(vha->port_name);
5867 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5868 if (wwn2 == (uint64_t)-1)
5870 else if (wwn1 == wwn2)
5874 /* check destination WWN for a match */
5875 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5876 wwn1 = wwn_to_u64(fcport->port_name);
5877 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5878 if (wwn2 == (uint64_t)-1)
5880 else if (wwn1 == wwn2)
5884 if (pid_match == 2 || wwn_match == 2) {
5885 /* Found a matching entry */
5886 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5887 priority = pri_entry->tag;
5898 * qla24xx_update_fcport_fcp_prio
5899 * Activates fcp priority for the logged in fc port
5902 * vha = scsi host structure pointer.
5903 * fcp = port structure pointer.
5906 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5912 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5918 if (fcport->port_type != FCT_TARGET ||
5919 fcport->loop_id == FC_NO_LOOP_ID)
5920 return QLA_FUNCTION_FAILED;
5922 priority = qla24xx_get_fcp_prio(vha, fcport);
5924 return QLA_FUNCTION_FAILED;
5926 if (IS_QLA82XX(vha->hw)) {
5927 fcport->fcp_prio = priority & 0xf;
5931 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
5932 if (ret == QLA_SUCCESS) {
5933 if (fcport->fcp_prio != priority)
5934 ql_dbg(ql_dbg_user, vha, 0x709e,
5935 "Updated FCP_CMND priority - value=%d loop_id=%d "
5936 "port_id=%02x%02x%02x.\n", priority,
5937 fcport->loop_id, fcport->d_id.b.domain,
5938 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5939 fcport->fcp_prio = priority & 0xf;
5941 ql_dbg(ql_dbg_user, vha, 0x704f,
5942 "Unable to update FCP_CMND priority - ret=0x%x for "
5943 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
5944 fcport->d_id.b.domain, fcport->d_id.b.area,
5945 fcport->d_id.b.al_pa);
5950 * qla24xx_update_all_fcp_prio
5951 * Activates fcp priority for all the logged in ports
5954 * ha = adapter block pointer.
5957 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5963 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5968 ret = QLA_FUNCTION_FAILED;
5969 /* We need to set priority for all logged in ports */
5970 list_for_each_entry(fcport, &vha->vp_fcports, list)
5971 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);