2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 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_fw_ready(scsi_qla_host_t *);
29 static int qla2x00_configure_hba(scsi_qla_host_t *);
30 static int qla2x00_configure_loop(scsi_qla_host_t *);
31 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
32 static int qla2x00_configure_fabric(scsi_qla_host_t *);
33 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
34 static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
37 static int qla2x00_restart_isp(scsi_qla_host_t *);
39 static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
40 static int qla84xx_init_chip(scsi_qla_host_t *);
41 static int qla25xx_init_queues(struct qla_hw_data *);
43 /* SRB Extensions ---------------------------------------------------------- */
46 qla2x00_sp_timeout(unsigned long __data)
48 srb_t *sp = (srb_t *)__data;
49 struct srb_iocb *iocb;
50 fc_port_t *fcport = sp->fcport;
51 struct qla_hw_data *ha = fcport->vha->hw;
55 spin_lock_irqsave(&ha->hardware_lock, flags);
56 req = ha->req_q_map[0];
57 req->outstanding_cmds[sp->handle] = NULL;
58 iocb = &sp->u.iocb_cmd;
60 sp->free(fcport->vha, sp);
61 spin_unlock_irqrestore(&ha->hardware_lock, flags);
65 qla2x00_sp_free(void *data, void *ptr)
67 srb_t *sp = (srb_t *)ptr;
68 struct srb_iocb *iocb = &sp->u.iocb_cmd;
69 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
71 del_timer(&iocb->timer);
72 qla2x00_rel_sp(vha, sp);
75 /* Asynchronous Login/Logout Routines -------------------------------------- */
78 qla2x00_get_async_timeout(struct scsi_qla_host *vha)
81 struct qla_hw_data *ha = vha->hw;
83 /* Firmware should use switch negotiated r_a_tov for timeout. */
84 tmo = ha->r_a_tov / 10 * 2;
86 tmo = FX00_DEF_RATOV * 2;
87 } else if (!IS_FWI2_CAPABLE(ha)) {
89 * Except for earlier ISPs where the timeout is seeded from the
90 * initialization control block.
92 tmo = ha->login_timeout;
98 qla2x00_async_iocb_timeout(void *data)
100 srb_t *sp = (srb_t *)data;
101 fc_port_t *fcport = sp->fcport;
103 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
104 "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n",
105 sp->name, sp->handle, fcport->d_id.b.domain, fcport->d_id.b.area,
106 fcport->d_id.b.al_pa);
108 fcport->flags &= ~FCF_ASYNC_SENT;
109 if (sp->type == SRB_LOGIN_CMD) {
110 struct srb_iocb *lio = &sp->u.iocb_cmd;
111 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
112 /* Retry as needed. */
113 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
114 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
115 QLA_LOGIO_LOGIN_RETRIED : 0;
116 qla2x00_post_async_login_done_work(fcport->vha, fcport,
122 qla2x00_async_login_sp_done(void *data, void *ptr, int res)
124 srb_t *sp = (srb_t *)ptr;
125 struct srb_iocb *lio = &sp->u.iocb_cmd;
126 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
128 if (!test_bit(UNLOADING, &vha->dpc_flags))
129 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
131 sp->free(sp->fcport->vha, sp);
135 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
139 struct srb_iocb *lio;
142 rval = QLA_FUNCTION_FAILED;
143 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
147 sp->type = SRB_LOGIN_CMD;
149 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
151 lio = &sp->u.iocb_cmd;
152 lio->timeout = qla2x00_async_iocb_timeout;
153 sp->done = qla2x00_async_login_sp_done;
154 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
155 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
156 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
157 rval = qla2x00_start_sp(sp);
158 if (rval != QLA_SUCCESS)
161 ql_dbg(ql_dbg_disc, vha, 0x2072,
162 "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x "
163 "retries=%d.\n", sp->handle, fcport->loop_id,
164 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
165 fcport->login_retry);
169 sp->free(fcport->vha, sp);
175 qla2x00_async_logout_sp_done(void *data, void *ptr, int res)
177 srb_t *sp = (srb_t *)ptr;
178 struct srb_iocb *lio = &sp->u.iocb_cmd;
179 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
181 if (!test_bit(UNLOADING, &vha->dpc_flags))
182 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
184 sp->free(sp->fcport->vha, sp);
188 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
191 struct srb_iocb *lio;
194 rval = QLA_FUNCTION_FAILED;
195 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
199 sp->type = SRB_LOGOUT_CMD;
201 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
203 lio = &sp->u.iocb_cmd;
204 lio->timeout = qla2x00_async_iocb_timeout;
205 sp->done = qla2x00_async_logout_sp_done;
206 rval = qla2x00_start_sp(sp);
207 if (rval != QLA_SUCCESS)
210 ql_dbg(ql_dbg_disc, vha, 0x2070,
211 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
212 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
213 fcport->d_id.b.area, fcport->d_id.b.al_pa);
217 sp->free(fcport->vha, sp);
223 qla2x00_async_adisc_sp_done(void *data, void *ptr, int res)
225 srb_t *sp = (srb_t *)ptr;
226 struct srb_iocb *lio = &sp->u.iocb_cmd;
227 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
229 if (!test_bit(UNLOADING, &vha->dpc_flags))
230 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
232 sp->free(sp->fcport->vha, sp);
236 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
240 struct srb_iocb *lio;
243 rval = QLA_FUNCTION_FAILED;
244 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
248 sp->type = SRB_ADISC_CMD;
250 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
252 lio = &sp->u.iocb_cmd;
253 lio->timeout = qla2x00_async_iocb_timeout;
254 sp->done = qla2x00_async_adisc_sp_done;
255 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
256 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
257 rval = qla2x00_start_sp(sp);
258 if (rval != QLA_SUCCESS)
261 ql_dbg(ql_dbg_disc, vha, 0x206f,
262 "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
263 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
264 fcport->d_id.b.area, fcport->d_id.b.al_pa);
268 sp->free(fcport->vha, sp);
274 qla2x00_tmf_iocb_timeout(void *data)
276 srb_t *sp = (srb_t *)data;
277 struct srb_iocb *tmf = &sp->u.iocb_cmd;
279 tmf->u.tmf.comp_status = CS_TIMEOUT;
280 complete(&tmf->u.tmf.comp);
284 qla2x00_tmf_sp_done(void *data, void *ptr, int res)
286 srb_t *sp = (srb_t *)ptr;
287 struct srb_iocb *tmf = &sp->u.iocb_cmd;
288 complete(&tmf->u.tmf.comp);
292 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
295 struct scsi_qla_host *vha = fcport->vha;
296 struct srb_iocb *tm_iocb;
298 int rval = QLA_FUNCTION_FAILED;
300 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
304 tm_iocb = &sp->u.iocb_cmd;
305 sp->type = SRB_TM_CMD;
307 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
308 tm_iocb->u.tmf.flags = flags;
309 tm_iocb->u.tmf.lun = lun;
310 tm_iocb->u.tmf.data = tag;
311 sp->done = qla2x00_tmf_sp_done;
312 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
313 init_completion(&tm_iocb->u.tmf.comp);
315 rval = qla2x00_start_sp(sp);
316 if (rval != QLA_SUCCESS)
319 ql_dbg(ql_dbg_taskm, vha, 0x802f,
320 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
321 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
322 fcport->d_id.b.area, fcport->d_id.b.al_pa);
324 wait_for_completion(&tm_iocb->u.tmf.comp);
326 rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ?
327 QLA_SUCCESS : QLA_FUNCTION_FAILED;
329 if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) {
330 ql_dbg(ql_dbg_taskm, vha, 0x8030,
331 "TM IOCB failed (%x).\n", rval);
334 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
335 flags = tm_iocb->u.tmf.flags;
336 lun = (uint16_t)tm_iocb->u.tmf.lun;
338 /* Issue Marker IOCB */
339 qla2x00_marker(vha, vha->hw->req_q_map[0],
340 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
341 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
351 qla24xx_abort_iocb_timeout(void *data)
353 srb_t *sp = (srb_t *)data;
354 struct srb_iocb *abt = &sp->u.iocb_cmd;
356 abt->u.abt.comp_status = CS_TIMEOUT;
357 complete(&abt->u.abt.comp);
361 qla24xx_abort_sp_done(void *data, void *ptr, int res)
363 srb_t *sp = (srb_t *)ptr;
364 struct srb_iocb *abt = &sp->u.iocb_cmd;
366 complete(&abt->u.abt.comp);
370 qla24xx_async_abort_cmd(srb_t *cmd_sp)
372 scsi_qla_host_t *vha = cmd_sp->fcport->vha;
373 fc_port_t *fcport = cmd_sp->fcport;
374 struct srb_iocb *abt_iocb;
376 int rval = QLA_FUNCTION_FAILED;
378 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
382 abt_iocb = &sp->u.iocb_cmd;
383 sp->type = SRB_ABT_CMD;
385 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
386 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
387 sp->done = qla24xx_abort_sp_done;
388 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
389 init_completion(&abt_iocb->u.abt.comp);
391 rval = qla2x00_start_sp(sp);
392 if (rval != QLA_SUCCESS)
395 ql_dbg(ql_dbg_async, vha, 0x507c,
396 "Abort command issued - hdl=%x, target_id=%x\n",
397 cmd_sp->handle, fcport->tgt_id);
399 wait_for_completion(&abt_iocb->u.abt.comp);
401 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
402 QLA_SUCCESS : QLA_FUNCTION_FAILED;
411 qla24xx_async_abort_command(srb_t *sp)
413 unsigned long flags = 0;
416 fc_port_t *fcport = sp->fcport;
417 struct scsi_qla_host *vha = fcport->vha;
418 struct qla_hw_data *ha = vha->hw;
419 struct req_que *req = vha->req;
421 spin_lock_irqsave(&ha->hardware_lock, flags);
422 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
423 if (req->outstanding_cmds[handle] == sp)
426 spin_unlock_irqrestore(&ha->hardware_lock, flags);
427 if (handle == req->num_outstanding_cmds) {
428 /* Command not found. */
429 return QLA_FUNCTION_FAILED;
431 if (sp->type == SRB_FXIOCB_DCMD)
432 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
435 return qla24xx_async_abort_cmd(sp);
439 qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
445 case MBS_COMMAND_COMPLETE:
447 * Driver must validate login state - If PRLI not complete,
448 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
451 rval = qla2x00_get_port_database(vha, fcport, 0);
452 if (rval == QLA_NOT_LOGGED_IN) {
453 fcport->flags &= ~FCF_ASYNC_SENT;
454 fcport->flags |= FCF_LOGIN_NEEDED;
455 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
459 if (rval != QLA_SUCCESS) {
460 qla2x00_post_async_logout_work(vha, fcport, NULL);
461 qla2x00_post_async_login_work(vha, fcport, NULL);
464 if (fcport->flags & FCF_FCP2_DEVICE) {
465 qla2x00_post_async_adisc_work(vha, fcport, data);
468 qla2x00_update_fcport(vha, fcport);
470 case MBS_COMMAND_ERROR:
471 fcport->flags &= ~FCF_ASYNC_SENT;
472 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
473 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
475 qla2x00_mark_device_lost(vha, fcport, 1, 0);
477 case MBS_PORT_ID_USED:
478 fcport->loop_id = data[1];
479 qla2x00_post_async_logout_work(vha, fcport, NULL);
480 qla2x00_post_async_login_work(vha, fcport, NULL);
482 case MBS_LOOP_ID_USED:
484 rval = qla2x00_find_new_loop_id(vha, fcport);
485 if (rval != QLA_SUCCESS) {
486 fcport->flags &= ~FCF_ASYNC_SENT;
487 qla2x00_mark_device_lost(vha, fcport, 1, 0);
490 qla2x00_post_async_login_work(vha, fcport, NULL);
497 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
500 qla2x00_mark_device_lost(vha, fcport, 1, 0);
505 qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
508 if (data[0] == MBS_COMMAND_COMPLETE) {
509 qla2x00_update_fcport(vha, fcport);
515 fcport->flags &= ~FCF_ASYNC_SENT;
516 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
517 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
519 qla2x00_mark_device_lost(vha, fcport, 1, 0);
524 /****************************************************************************/
525 /* QLogic ISP2x00 Hardware Support Functions. */
526 /****************************************************************************/
529 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
531 int rval = QLA_SUCCESS;
532 struct qla_hw_data *ha = vha->hw;
533 uint32_t idc_major_ver, idc_minor_ver;
536 qla83xx_idc_lock(vha, 0);
538 /* SV: TODO: Assign initialization timeout from
539 * flash-info / other param
541 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
542 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
544 /* Set our fcoe function presence */
545 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
546 ql_dbg(ql_dbg_p3p, vha, 0xb077,
547 "Error while setting DRV-Presence.\n");
548 rval = QLA_FUNCTION_FAILED;
552 /* Decide the reset ownership */
553 qla83xx_reset_ownership(vha);
556 * On first protocol driver load:
557 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
559 * Others: Check compatibility with current IDC Major version.
561 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
562 if (ha->flags.nic_core_reset_owner) {
563 /* Set IDC Major version */
564 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
565 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
567 /* Clearing IDC-Lock-Recovery register */
568 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
569 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
571 * Clear further IDC participation if we are not compatible with
572 * the current IDC Major Version.
574 ql_log(ql_log_warn, vha, 0xb07d,
575 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
576 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
577 __qla83xx_clear_drv_presence(vha);
578 rval = QLA_FUNCTION_FAILED;
581 /* Each function sets its supported Minor version. */
582 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
583 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
584 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
586 if (ha->flags.nic_core_reset_owner) {
587 memset(config, 0, sizeof(config));
588 if (!qla81xx_get_port_config(vha, config))
589 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
593 rval = qla83xx_idc_state_handler(vha);
596 qla83xx_idc_unlock(vha, 0);
602 * qla2x00_initialize_adapter
606 * ha = adapter block pointer.
612 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
615 struct qla_hw_data *ha = vha->hw;
616 struct req_que *req = ha->req_q_map[0];
618 /* Clear adapter flags. */
619 vha->flags.online = 0;
620 ha->flags.chip_reset_done = 0;
621 vha->flags.reset_active = 0;
622 ha->flags.pci_channel_io_perm_failure = 0;
623 ha->flags.eeh_busy = 0;
624 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
625 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
626 atomic_set(&vha->loop_state, LOOP_DOWN);
627 vha->device_flags = DFLG_NO_CABLE;
629 vha->flags.management_server_logged_in = 0;
630 vha->marker_needed = 0;
631 ha->isp_abort_cnt = 0;
632 ha->beacon_blink_led = 0;
634 set_bit(0, ha->req_qid_map);
635 set_bit(0, ha->rsp_qid_map);
637 ql_dbg(ql_dbg_init, vha, 0x0040,
638 "Configuring PCI space...\n");
639 rval = ha->isp_ops->pci_config(vha);
641 ql_log(ql_log_warn, vha, 0x0044,
642 "Unable to configure PCI space.\n");
646 ha->isp_ops->reset_chip(vha);
648 rval = qla2xxx_get_flash_info(vha);
650 ql_log(ql_log_fatal, vha, 0x004f,
651 "Unable to validate FLASH data.\n");
655 if (IS_QLA8044(ha)) {
656 qla8044_read_reset_template(vha);
658 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
659 * If DONRESET_BIT0 is set, drivers should not set dev_state
660 * to NEED_RESET. But if NEED_RESET is set, drivers should
661 * should honor the reset. */
662 if (ql2xdontresethba == 1)
663 qla8044_set_idc_dontreset(vha);
666 ha->isp_ops->get_flash_version(vha, req->ring);
667 ql_dbg(ql_dbg_init, vha, 0x0061,
668 "Configure NVRAM parameters...\n");
670 ha->isp_ops->nvram_config(vha);
672 if (ha->flags.disable_serdes) {
673 /* Mask HBA via NVRAM settings? */
674 ql_log(ql_log_info, vha, 0x0077,
675 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
676 return QLA_FUNCTION_FAILED;
679 ql_dbg(ql_dbg_init, vha, 0x0078,
680 "Verifying loaded RISC code...\n");
682 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
683 rval = ha->isp_ops->chip_diag(vha);
686 rval = qla2x00_setup_chip(vha);
691 if (IS_QLA84XX(ha)) {
692 ha->cs84xx = qla84xx_get_chip(vha);
694 ql_log(ql_log_warn, vha, 0x00d0,
695 "Unable to configure ISP84XX.\n");
696 return QLA_FUNCTION_FAILED;
700 if (qla_ini_mode_enabled(vha))
701 rval = qla2x00_init_rings(vha);
703 ha->flags.chip_reset_done = 1;
705 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
706 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
707 rval = qla84xx_init_chip(vha);
708 if (rval != QLA_SUCCESS) {
709 ql_log(ql_log_warn, vha, 0x00d4,
710 "Unable to initialize ISP84XX.\n");
711 qla84xx_put_chip(vha);
715 /* Load the NIC Core f/w if we are the first protocol driver. */
716 if (IS_QLA8031(ha)) {
717 rval = qla83xx_nic_core_fw_load(vha);
719 ql_log(ql_log_warn, vha, 0x0124,
720 "Error in initializing NIC Core f/w.\n");
723 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
724 qla24xx_read_fcp_prio_cfg(vha);
727 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
729 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
735 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
738 * Returns 0 on success.
741 qla2100_pci_config(scsi_qla_host_t *vha)
745 struct qla_hw_data *ha = vha->hw;
746 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
748 pci_set_master(ha->pdev);
749 pci_try_set_mwi(ha->pdev);
751 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
752 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
753 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
755 pci_disable_rom(ha->pdev);
757 /* Get PCI bus information. */
758 spin_lock_irqsave(&ha->hardware_lock, flags);
759 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
760 spin_unlock_irqrestore(&ha->hardware_lock, flags);
766 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
769 * Returns 0 on success.
772 qla2300_pci_config(scsi_qla_host_t *vha)
775 unsigned long flags = 0;
777 struct qla_hw_data *ha = vha->hw;
778 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
780 pci_set_master(ha->pdev);
781 pci_try_set_mwi(ha->pdev);
783 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
784 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
786 if (IS_QLA2322(ha) || IS_QLA6322(ha))
787 w &= ~PCI_COMMAND_INTX_DISABLE;
788 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
791 * If this is a 2300 card and not 2312, reset the
792 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
793 * the 2310 also reports itself as a 2300 so we need to get the
794 * fb revision level -- a 6 indicates it really is a 2300 and
797 if (IS_QLA2300(ha)) {
798 spin_lock_irqsave(&ha->hardware_lock, flags);
801 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
802 for (cnt = 0; cnt < 30000; cnt++) {
803 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
809 /* Select FPM registers. */
810 WRT_REG_WORD(®->ctrl_status, 0x20);
811 RD_REG_WORD(®->ctrl_status);
813 /* Get the fb rev level */
814 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
816 if (ha->fb_rev == FPM_2300)
817 pci_clear_mwi(ha->pdev);
819 /* Deselect FPM registers. */
820 WRT_REG_WORD(®->ctrl_status, 0x0);
821 RD_REG_WORD(®->ctrl_status);
823 /* Release RISC module. */
824 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
825 for (cnt = 0; cnt < 30000; cnt++) {
826 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
832 spin_unlock_irqrestore(&ha->hardware_lock, flags);
835 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
837 pci_disable_rom(ha->pdev);
839 /* Get PCI bus information. */
840 spin_lock_irqsave(&ha->hardware_lock, flags);
841 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
842 spin_unlock_irqrestore(&ha->hardware_lock, flags);
848 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
851 * Returns 0 on success.
854 qla24xx_pci_config(scsi_qla_host_t *vha)
857 unsigned long flags = 0;
858 struct qla_hw_data *ha = vha->hw;
859 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
861 pci_set_master(ha->pdev);
862 pci_try_set_mwi(ha->pdev);
864 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
865 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
866 w &= ~PCI_COMMAND_INTX_DISABLE;
867 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
869 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
871 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
872 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
873 pcix_set_mmrbc(ha->pdev, 2048);
875 /* PCIe -- adjust Maximum Read Request Size (2048). */
876 if (pci_is_pcie(ha->pdev))
877 pcie_set_readrq(ha->pdev, 4096);
879 pci_disable_rom(ha->pdev);
881 ha->chip_revision = ha->pdev->revision;
883 /* Get PCI bus information. */
884 spin_lock_irqsave(&ha->hardware_lock, flags);
885 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
886 spin_unlock_irqrestore(&ha->hardware_lock, flags);
892 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
895 * Returns 0 on success.
898 qla25xx_pci_config(scsi_qla_host_t *vha)
901 struct qla_hw_data *ha = vha->hw;
903 pci_set_master(ha->pdev);
904 pci_try_set_mwi(ha->pdev);
906 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
907 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
908 w &= ~PCI_COMMAND_INTX_DISABLE;
909 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
911 /* PCIe -- adjust Maximum Read Request Size (2048). */
912 if (pci_is_pcie(ha->pdev))
913 pcie_set_readrq(ha->pdev, 4096);
915 pci_disable_rom(ha->pdev);
917 ha->chip_revision = ha->pdev->revision;
923 * qla2x00_isp_firmware() - Choose firmware image.
926 * Returns 0 on success.
929 qla2x00_isp_firmware(scsi_qla_host_t *vha)
932 uint16_t loop_id, topo, sw_cap;
933 uint8_t domain, area, al_pa;
934 struct qla_hw_data *ha = vha->hw;
936 /* Assume loading risc code */
937 rval = QLA_FUNCTION_FAILED;
939 if (ha->flags.disable_risc_code_load) {
940 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
942 /* Verify checksum of loaded RISC code. */
943 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
944 if (rval == QLA_SUCCESS) {
945 /* And, verify we are not in ROM code. */
946 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
947 &area, &domain, &topo, &sw_cap);
952 ql_dbg(ql_dbg_init, vha, 0x007a,
953 "**** Load RISC code ****.\n");
959 * qla2x00_reset_chip() - Reset ISP chip.
962 * Returns 0 on success.
965 qla2x00_reset_chip(scsi_qla_host_t *vha)
967 unsigned long flags = 0;
968 struct qla_hw_data *ha = vha->hw;
969 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
973 if (unlikely(pci_channel_offline(ha->pdev)))
976 ha->isp_ops->disable_intrs(ha);
978 spin_lock_irqsave(&ha->hardware_lock, flags);
980 /* Turn off master enable */
982 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
983 cmd &= ~PCI_COMMAND_MASTER;
984 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
986 if (!IS_QLA2100(ha)) {
988 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
989 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
990 for (cnt = 0; cnt < 30000; cnt++) {
991 if ((RD_REG_WORD(®->hccr) &
992 HCCR_RISC_PAUSE) != 0)
997 RD_REG_WORD(®->hccr); /* PCI Posting. */
1001 /* Select FPM registers. */
1002 WRT_REG_WORD(®->ctrl_status, 0x20);
1003 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1005 /* FPM Soft Reset. */
1006 WRT_REG_WORD(®->fpm_diag_config, 0x100);
1007 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
1009 /* Toggle Fpm Reset. */
1010 if (!IS_QLA2200(ha)) {
1011 WRT_REG_WORD(®->fpm_diag_config, 0x0);
1012 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
1015 /* Select frame buffer registers. */
1016 WRT_REG_WORD(®->ctrl_status, 0x10);
1017 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1019 /* Reset frame buffer FIFOs. */
1020 if (IS_QLA2200(ha)) {
1021 WRT_FB_CMD_REG(ha, reg, 0xa000);
1022 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
1024 WRT_FB_CMD_REG(ha, reg, 0x00fc);
1026 /* Read back fb_cmd until zero or 3 seconds max */
1027 for (cnt = 0; cnt < 3000; cnt++) {
1028 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
1034 /* Select RISC module registers. */
1035 WRT_REG_WORD(®->ctrl_status, 0);
1036 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
1038 /* Reset RISC processor. */
1039 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
1040 RD_REG_WORD(®->hccr); /* PCI Posting. */
1042 /* Release RISC processor. */
1043 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
1044 RD_REG_WORD(®->hccr); /* PCI Posting. */
1047 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
1048 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
1050 /* Reset ISP chip. */
1051 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
1053 /* Wait for RISC to recover from reset. */
1054 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1056 * It is necessary to for a delay here since the card doesn't
1057 * respond to PCI reads during a reset. On some architectures
1058 * this will result in an MCA.
1061 for (cnt = 30000; cnt; cnt--) {
1062 if ((RD_REG_WORD(®->ctrl_status) &
1063 CSR_ISP_SOFT_RESET) == 0)
1070 /* Reset RISC processor. */
1071 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
1073 WRT_REG_WORD(®->semaphore, 0);
1075 /* Release RISC processor. */
1076 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
1077 RD_REG_WORD(®->hccr); /* PCI Posting. */
1079 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1080 for (cnt = 0; cnt < 30000; cnt++) {
1081 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
1089 /* Turn on master enable */
1090 cmd |= PCI_COMMAND_MASTER;
1091 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
1093 /* Disable RISC pause on FPM parity error. */
1094 if (!IS_QLA2100(ha)) {
1095 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
1096 RD_REG_WORD(®->hccr); /* PCI Posting. */
1099 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1103 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
1105 * Returns 0 on success.
1108 qla81xx_reset_mpi(scsi_qla_host_t *vha)
1110 uint16_t mb[4] = {0x1010, 0, 1, 0};
1112 if (!IS_QLA81XX(vha->hw))
1115 return qla81xx_write_mpi_register(vha, mb);
1119 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
1122 * Returns 0 on success.
1125 qla24xx_reset_risc(scsi_qla_host_t *vha)
1127 unsigned long flags = 0;
1128 struct qla_hw_data *ha = vha->hw;
1129 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1132 static int abts_cnt; /* ISP abort retry counts */
1133 int rval = QLA_SUCCESS;
1135 spin_lock_irqsave(&ha->hardware_lock, flags);
1138 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
1139 for (cnt = 0; cnt < 30000; cnt++) {
1140 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
1146 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE))
1147 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
1149 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
1150 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
1151 RD_REG_DWORD(®->hccr),
1152 RD_REG_DWORD(®->ctrl_status),
1153 (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE));
1155 WRT_REG_DWORD(®->ctrl_status,
1156 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
1157 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
1161 /* Wait for firmware to complete NVRAM accesses. */
1162 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
1163 for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 &&
1164 rval == QLA_SUCCESS; cnt--) {
1169 rval = QLA_FUNCTION_TIMEOUT;
1172 if (rval == QLA_SUCCESS)
1173 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
1175 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
1176 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
1177 RD_REG_DWORD(®->hccr),
1178 RD_REG_DWORD(®->mailbox0));
1180 /* Wait for soft-reset to complete. */
1181 d2 = RD_REG_DWORD(®->ctrl_status);
1182 for (cnt = 0; cnt < 6000000; cnt++) {
1184 if ((RD_REG_DWORD(®->ctrl_status) &
1185 CSRX_ISP_SOFT_RESET) == 0)
1190 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
1191 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
1193 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
1194 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
1195 RD_REG_DWORD(®->hccr),
1196 RD_REG_DWORD(®->ctrl_status));
1198 /* If required, do an MPI FW reset now */
1199 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
1200 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
1201 if (++abts_cnt < 5) {
1202 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1203 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
1206 * We exhausted the ISP abort retries. We have to
1207 * set the board offline.
1210 vha->flags.online = 0;
1215 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
1216 RD_REG_DWORD(®->hccr);
1218 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
1219 RD_REG_DWORD(®->hccr);
1221 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
1222 RD_REG_DWORD(®->hccr);
1224 d2 = (uint32_t) RD_REG_WORD(®->mailbox0);
1225 for (cnt = 6000000; RD_REG_WORD(®->mailbox0) != 0 &&
1226 rval == QLA_SUCCESS; cnt--) {
1231 rval = QLA_FUNCTION_TIMEOUT;
1233 if (rval == QLA_SUCCESS)
1234 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
1236 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
1237 "Host Risc 0x%x, mailbox0 0x%x\n",
1238 RD_REG_DWORD(®->hccr),
1239 RD_REG_WORD(®->mailbox0));
1241 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1243 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
1244 "Driver in %s mode\n",
1245 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
1247 if (IS_NOPOLLING_TYPE(ha))
1248 ha->isp_ops->enable_intrs(ha);
1254 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
1256 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
1258 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
1259 *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET);
1264 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
1266 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
1268 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
1269 WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
1273 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
1275 struct qla_hw_data *ha = vha->hw;
1277 uint delta_msec = 100;
1278 uint elapsed_msec = 0;
1282 if (!IS_QLA25XX(ha) && !IS_QLA2031(ha))
1286 timeout_msec = TIMEOUT_SEMAPHORE;
1287 n = timeout_msec / delta_msec;
1289 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
1290 qla25xx_read_risc_sema_reg(vha, &wd32);
1291 if (wd32 & RISC_SEMAPHORE)
1294 elapsed_msec += delta_msec;
1295 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
1299 if (!(wd32 & RISC_SEMAPHORE))
1302 if (!(wd32 & RISC_SEMAPHORE_FORCE))
1305 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
1306 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
1307 n = timeout_msec / delta_msec;
1309 qla25xx_read_risc_sema_reg(vha, &wd32);
1310 if (!(wd32 & RISC_SEMAPHORE_FORCE))
1313 elapsed_msec += delta_msec;
1314 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
1318 if (wd32 & RISC_SEMAPHORE_FORCE)
1319 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
1324 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
1331 * qla24xx_reset_chip() - Reset ISP24xx chip.
1334 * Returns 0 on success.
1337 qla24xx_reset_chip(scsi_qla_host_t *vha)
1339 struct qla_hw_data *ha = vha->hw;
1341 if (pci_channel_offline(ha->pdev) &&
1342 ha->flags.pci_channel_io_perm_failure) {
1346 ha->isp_ops->disable_intrs(ha);
1348 qla25xx_manipulate_risc_semaphore(vha);
1350 /* Perform RISC reset. */
1351 qla24xx_reset_risc(vha);
1355 * qla2x00_chip_diag() - Test chip for proper operation.
1358 * Returns 0 on success.
1361 qla2x00_chip_diag(scsi_qla_host_t *vha)
1364 struct qla_hw_data *ha = vha->hw;
1365 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1366 unsigned long flags = 0;
1370 struct req_que *req = ha->req_q_map[0];
1372 /* Assume a failed state */
1373 rval = QLA_FUNCTION_FAILED;
1375 ql_dbg(ql_dbg_init, vha, 0x007b,
1376 "Testing device at %lx.\n", (u_long)®->flash_address);
1378 spin_lock_irqsave(&ha->hardware_lock, flags);
1380 /* Reset ISP chip. */
1381 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
1384 * We need to have a delay here since the card will not respond while
1385 * in reset causing an MCA on some architectures.
1388 data = qla2x00_debounce_register(®->ctrl_status);
1389 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1391 data = RD_REG_WORD(®->ctrl_status);
1396 goto chip_diag_failed;
1398 ql_dbg(ql_dbg_init, vha, 0x007c,
1399 "Reset register cleared by chip reset.\n");
1401 /* Reset RISC processor. */
1402 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
1403 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
1405 /* Workaround for QLA2312 PCI parity error */
1406 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1407 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1408 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1410 data = RD_MAILBOX_REG(ha, reg, 0);
1417 goto chip_diag_failed;
1419 /* Check product ID of chip */
1420 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
1422 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1423 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1424 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1425 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1426 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1427 mb[3] != PROD_ID_3) {
1428 ql_log(ql_log_warn, vha, 0x0062,
1429 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
1430 mb[1], mb[2], mb[3]);
1432 goto chip_diag_failed;
1434 ha->product_id[0] = mb[1];
1435 ha->product_id[1] = mb[2];
1436 ha->product_id[2] = mb[3];
1437 ha->product_id[3] = mb[4];
1439 /* Adjust fw RISC transfer size */
1440 if (req->length > 1024)
1441 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1443 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
1446 if (IS_QLA2200(ha) &&
1447 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1448 /* Limit firmware transfer size with a 2200A */
1449 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
1451 ha->device_type |= DT_ISP2200A;
1452 ha->fw_transfer_size = 128;
1455 /* Wrap Incoming Mailboxes Test. */
1456 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1458 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
1459 rval = qla2x00_mbx_reg_test(vha);
1461 ql_log(ql_log_warn, vha, 0x0080,
1462 "Failed mailbox send register test.\n");
1464 /* Flag a successful rval */
1466 spin_lock_irqsave(&ha->hardware_lock, flags);
1470 ql_log(ql_log_info, vha, 0x0081,
1471 "Chip diagnostics **** FAILED ****.\n");
1473 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1479 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1482 * Returns 0 on success.
1485 qla24xx_chip_diag(scsi_qla_host_t *vha)
1488 struct qla_hw_data *ha = vha->hw;
1489 struct req_que *req = ha->req_q_map[0];
1491 if (IS_P3P_TYPE(ha))
1494 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
1496 rval = qla2x00_mbx_reg_test(vha);
1498 ql_log(ql_log_warn, vha, 0x0082,
1499 "Failed mailbox send register test.\n");
1501 /* Flag a successful rval */
1509 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
1512 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
1513 eft_size, fce_size, mq_size;
1516 struct qla_hw_data *ha = vha->hw;
1517 struct req_que *req = ha->req_q_map[0];
1518 struct rsp_que *rsp = ha->rsp_q_map[0];
1521 ql_dbg(ql_dbg_init, vha, 0x00bd,
1522 "Firmware dump already allocated.\n");
1527 ha->fw_dump_cap_flags = 0;
1528 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
1529 req_q_size = rsp_q_size = 0;
1534 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1535 fixed_size = sizeof(struct qla2100_fw_dump);
1536 } else if (IS_QLA23XX(ha)) {
1537 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1538 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1540 } else if (IS_FWI2_CAPABLE(ha)) {
1542 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
1543 else if (IS_QLA81XX(ha))
1544 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1545 else if (IS_QLA25XX(ha))
1546 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1548 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
1550 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1553 if (!IS_QLA83XX(ha))
1554 mq_size = sizeof(struct qla2xxx_mq_chain);
1556 * Allocate maximum buffer size for all queues.
1557 * Resizing must be done at end-of-dump processing.
1559 mq_size += ha->max_req_queues *
1560 (req->length * sizeof(request_t));
1561 mq_size += ha->max_rsp_queues *
1562 (rsp->length * sizeof(response_t));
1564 if (ha->tgt.atio_ring)
1565 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
1566 /* Allocate memory for Fibre Channel Event Buffer. */
1567 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
1573 dma_free_coherent(&ha->pdev->dev,
1574 FCE_SIZE, ha->fce, ha->fce_dma);
1576 /* Allocate memory for Fibre Channel Event Buffer. */
1577 tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1580 ql_log(ql_log_warn, vha, 0x00be,
1581 "Unable to allocate (%d KB) for FCE.\n",
1586 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
1587 ha->fce_mb, &ha->fce_bufs);
1589 ql_log(ql_log_warn, vha, 0x00bf,
1590 "Unable to initialize FCE (%d).\n", rval);
1591 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1593 ha->flags.fce_enabled = 0;
1596 ql_dbg(ql_dbg_init, vha, 0x00c0,
1597 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
1599 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
1600 ha->flags.fce_enabled = 1;
1601 ha->fce_dma = tc_dma;
1606 dma_free_coherent(&ha->pdev->dev,
1607 EFT_SIZE, ha->eft, ha->eft_dma);
1609 /* Allocate memory for Extended Trace Buffer. */
1610 tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
1613 ql_log(ql_log_warn, vha, 0x00c1,
1614 "Unable to allocate (%d KB) for EFT.\n",
1619 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
1621 ql_log(ql_log_warn, vha, 0x00c2,
1622 "Unable to initialize EFT (%d).\n", rval);
1623 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1627 ql_dbg(ql_dbg_init, vha, 0x00c3,
1628 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
1630 eft_size = EFT_SIZE;
1631 ha->eft_dma = tc_dma;
1636 if (IS_QLA27XX(ha)) {
1637 if (!ha->fw_dump_template) {
1638 ql_log(ql_log_warn, vha, 0x00ba,
1639 "Failed missing fwdump template\n");
1642 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
1643 ql_dbg(ql_dbg_init, vha, 0x00fa,
1644 "-> allocating fwdump (%x bytes)...\n", dump_size);
1648 req_q_size = req->length * sizeof(request_t);
1649 rsp_q_size = rsp->length * sizeof(response_t);
1650 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
1651 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
1652 ha->chain_offset = dump_size;
1653 dump_size += mq_size + fce_size;
1656 ha->fw_dump = vmalloc(dump_size);
1658 ql_log(ql_log_warn, vha, 0x00c4,
1659 "Unable to allocate (%d KB) for firmware dump.\n",
1663 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1670 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1677 ha->fw_dump_len = dump_size;
1678 ql_dbg(ql_dbg_init, vha, 0x00c5,
1679 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
1684 ha->fw_dump->signature[0] = 'Q';
1685 ha->fw_dump->signature[1] = 'L';
1686 ha->fw_dump->signature[2] = 'G';
1687 ha->fw_dump->signature[3] = 'C';
1688 ha->fw_dump->version = __constant_htonl(1);
1690 ha->fw_dump->fixed_size = htonl(fixed_size);
1691 ha->fw_dump->mem_size = htonl(mem_size);
1692 ha->fw_dump->req_q_size = htonl(req_q_size);
1693 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1695 ha->fw_dump->eft_size = htonl(eft_size);
1696 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1697 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1699 ha->fw_dump->header_size =
1700 htonl(offsetof(struct qla2xxx_fw_dump, isp));
1704 qla81xx_mpi_sync(scsi_qla_host_t *vha)
1706 #define MPS_MASK 0xe0
1711 if (!IS_QLA81XX(vha->hw))
1714 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1715 if (rval != QLA_SUCCESS) {
1716 ql_log(ql_log_warn, vha, 0x0105,
1717 "Unable to acquire semaphore.\n");
1721 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1722 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1723 if (rval != QLA_SUCCESS) {
1724 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
1729 if (dc == (dw & MPS_MASK))
1734 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1735 if (rval != QLA_SUCCESS) {
1736 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
1740 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1741 if (rval != QLA_SUCCESS) {
1742 ql_log(ql_log_warn, vha, 0x006d,
1743 "Unable to release semaphore.\n");
1751 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
1753 /* Don't try to reallocate the array */
1754 if (req->outstanding_cmds)
1757 if (!IS_FWI2_CAPABLE(ha) || (ha->mqiobase &&
1758 (ql2xmultique_tag || ql2xmaxqueues > 1)))
1759 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
1761 if (ha->fw_xcb_count <= ha->fw_iocb_count)
1762 req->num_outstanding_cmds = ha->fw_xcb_count;
1764 req->num_outstanding_cmds = ha->fw_iocb_count;
1767 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
1768 req->num_outstanding_cmds, GFP_KERNEL);
1770 if (!req->outstanding_cmds) {
1772 * Try to allocate a minimal size just so we can get through
1775 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
1776 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
1777 req->num_outstanding_cmds, GFP_KERNEL);
1779 if (!req->outstanding_cmds) {
1780 ql_log(ql_log_fatal, NULL, 0x0126,
1781 "Failed to allocate memory for "
1782 "outstanding_cmds for req_que %p.\n", req);
1783 req->num_outstanding_cmds = 0;
1784 return QLA_FUNCTION_FAILED;
1792 * qla2x00_setup_chip() - Load and start RISC firmware.
1795 * Returns 0 on success.
1798 qla2x00_setup_chip(scsi_qla_host_t *vha)
1801 uint32_t srisc_address = 0;
1802 struct qla_hw_data *ha = vha->hw;
1803 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1804 unsigned long flags;
1805 uint16_t fw_major_version;
1807 if (IS_P3P_TYPE(ha)) {
1808 rval = ha->isp_ops->load_risc(vha, &srisc_address);
1809 if (rval == QLA_SUCCESS) {
1810 qla2x00_stop_firmware(vha);
1811 goto enable_82xx_npiv;
1816 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1817 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1818 spin_lock_irqsave(&ha->hardware_lock, flags);
1819 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
1820 RD_REG_WORD(®->hccr);
1821 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1824 qla81xx_mpi_sync(vha);
1826 /* Load firmware sequences */
1827 rval = ha->isp_ops->load_risc(vha, &srisc_address);
1828 if (rval == QLA_SUCCESS) {
1829 ql_dbg(ql_dbg_init, vha, 0x00c9,
1830 "Verifying Checksum of loaded RISC code.\n");
1832 rval = qla2x00_verify_checksum(vha, srisc_address);
1833 if (rval == QLA_SUCCESS) {
1834 /* Start firmware execution. */
1835 ql_dbg(ql_dbg_init, vha, 0x00ca,
1836 "Starting firmware.\n");
1838 rval = qla2x00_execute_fw(vha, srisc_address);
1839 /* Retrieve firmware information. */
1840 if (rval == QLA_SUCCESS) {
1842 fw_major_version = ha->fw_major_version;
1843 if (IS_P3P_TYPE(ha))
1844 qla82xx_check_md_needed(vha);
1846 rval = qla2x00_get_fw_version(vha);
1847 if (rval != QLA_SUCCESS)
1849 ha->flags.npiv_supported = 0;
1850 if (IS_QLA2XXX_MIDTYPE(ha) &&
1851 (ha->fw_attributes & BIT_2)) {
1852 ha->flags.npiv_supported = 1;
1853 if ((!ha->max_npiv_vports) ||
1854 ((ha->max_npiv_vports + 1) %
1855 MIN_MULTI_ID_FABRIC))
1856 ha->max_npiv_vports =
1857 MIN_MULTI_ID_FABRIC - 1;
1859 qla2x00_get_resource_cnts(vha, NULL,
1860 &ha->fw_xcb_count, NULL, &ha->fw_iocb_count,
1861 &ha->max_npiv_vports, NULL);
1864 * Allocate the array of outstanding commands
1865 * now that we know the firmware resources.
1867 rval = qla2x00_alloc_outstanding_cmds(ha,
1869 if (rval != QLA_SUCCESS)
1872 if (!fw_major_version && ql2xallocfwdump
1873 && !(IS_P3P_TYPE(ha)))
1874 qla2x00_alloc_fw_dump(vha);
1879 ql_log(ql_log_fatal, vha, 0x00cd,
1880 "ISP Firmware failed checksum.\n");
1886 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1887 /* Enable proper parity. */
1888 spin_lock_irqsave(&ha->hardware_lock, flags);
1891 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
1893 /* SRAM, Instruction RAM and GP RAM parity */
1894 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
1895 RD_REG_WORD(®->hccr);
1896 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1900 ha->flags.fac_supported = 1;
1901 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1904 rval = qla81xx_fac_get_sector_size(vha, &size);
1905 if (rval == QLA_SUCCESS) {
1906 ha->flags.fac_supported = 1;
1907 ha->fdt_block_size = size << 2;
1909 ql_log(ql_log_warn, vha, 0x00ce,
1910 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1911 ha->fw_major_version, ha->fw_minor_version,
1912 ha->fw_subminor_version);
1914 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
1915 ha->flags.fac_supported = 0;
1922 ql_log(ql_log_fatal, vha, 0x00cf,
1923 "Setup chip ****FAILED****.\n");
1930 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1933 * Beginning of request ring has initialization control block already built
1934 * by nvram config routine.
1936 * Returns 0 on success.
1939 qla2x00_init_response_q_entries(struct rsp_que *rsp)
1944 rsp->ring_ptr = rsp->ring;
1945 rsp->ring_index = 0;
1946 rsp->status_srb = NULL;
1947 pkt = rsp->ring_ptr;
1948 for (cnt = 0; cnt < rsp->length; cnt++) {
1949 pkt->signature = RESPONSE_PROCESSED;
1955 * qla2x00_update_fw_options() - Read and process firmware options.
1958 * Returns 0 on success.
1961 qla2x00_update_fw_options(scsi_qla_host_t *vha)
1963 uint16_t swing, emphasis, tx_sens, rx_sens;
1964 struct qla_hw_data *ha = vha->hw;
1966 memset(ha->fw_options, 0, sizeof(ha->fw_options));
1967 qla2x00_get_fw_options(vha, ha->fw_options);
1969 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1972 /* Serial Link options. */
1973 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
1974 "Serial link options.\n");
1975 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
1976 (uint8_t *)&ha->fw_seriallink_options,
1977 sizeof(ha->fw_seriallink_options));
1979 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1980 if (ha->fw_seriallink_options[3] & BIT_2) {
1981 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1984 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1985 emphasis = (ha->fw_seriallink_options[2] &
1986 (BIT_4 | BIT_3)) >> 3;
1987 tx_sens = ha->fw_seriallink_options[0] &
1988 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1989 rx_sens = (ha->fw_seriallink_options[0] &
1990 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1991 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1992 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1995 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1996 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1997 ha->fw_options[10] |= BIT_5 |
1998 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1999 (tx_sens & (BIT_1 | BIT_0));
2002 swing = (ha->fw_seriallink_options[2] &
2003 (BIT_7 | BIT_6 | BIT_5)) >> 5;
2004 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
2005 tx_sens = ha->fw_seriallink_options[1] &
2006 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2007 rx_sens = (ha->fw_seriallink_options[1] &
2008 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
2009 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
2010 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
2013 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
2014 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
2015 ha->fw_options[11] |= BIT_5 |
2016 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
2017 (tx_sens & (BIT_1 | BIT_0));
2021 /* Return command IOCBs without waiting for an ABTS to complete. */
2022 ha->fw_options[3] |= BIT_13;
2025 if (ha->flags.enable_led_scheme)
2026 ha->fw_options[2] |= BIT_12;
2028 /* Detect ISP6312. */
2030 ha->fw_options[2] |= BIT_13;
2032 /* Update firmware options. */
2033 qla2x00_set_fw_options(vha, ha->fw_options);
2037 qla24xx_update_fw_options(scsi_qla_host_t *vha)
2040 struct qla_hw_data *ha = vha->hw;
2042 if (IS_P3P_TYPE(ha))
2045 /* Update Serial Link options. */
2046 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
2049 rval = qla2x00_set_serdes_params(vha,
2050 le16_to_cpu(ha->fw_seriallink_options24[1]),
2051 le16_to_cpu(ha->fw_seriallink_options24[2]),
2052 le16_to_cpu(ha->fw_seriallink_options24[3]));
2053 if (rval != QLA_SUCCESS) {
2054 ql_log(ql_log_warn, vha, 0x0104,
2055 "Unable to update Serial Link options (%x).\n", rval);
2060 qla2x00_config_rings(struct scsi_qla_host *vha)
2062 struct qla_hw_data *ha = vha->hw;
2063 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2064 struct req_que *req = ha->req_q_map[0];
2065 struct rsp_que *rsp = ha->rsp_q_map[0];
2067 /* Setup ring parameters in initialization control block. */
2068 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
2069 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
2070 ha->init_cb->request_q_length = cpu_to_le16(req->length);
2071 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
2072 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
2073 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
2074 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
2075 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
2077 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
2078 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
2079 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
2080 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
2081 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
2085 qla24xx_config_rings(struct scsi_qla_host *vha)
2087 struct qla_hw_data *ha = vha->hw;
2088 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
2089 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
2090 struct qla_msix_entry *msix;
2091 struct init_cb_24xx *icb;
2093 struct req_que *req = ha->req_q_map[0];
2094 struct rsp_que *rsp = ha->rsp_q_map[0];
2096 /* Setup ring parameters in initialization control block. */
2097 icb = (struct init_cb_24xx *)ha->init_cb;
2098 icb->request_q_outpointer = __constant_cpu_to_le16(0);
2099 icb->response_q_inpointer = __constant_cpu_to_le16(0);
2100 icb->request_q_length = cpu_to_le16(req->length);
2101 icb->response_q_length = cpu_to_le16(rsp->length);
2102 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
2103 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
2104 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
2105 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
2107 /* Setup ATIO queue dma pointers for target mode */
2108 icb->atio_q_inpointer = __constant_cpu_to_le16(0);
2109 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
2110 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
2111 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
2113 if (IS_SHADOW_REG_CAPABLE(ha))
2114 icb->firmware_options_2 |=
2115 __constant_cpu_to_le32(BIT_30|BIT_29);
2117 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
2118 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
2119 icb->rid = __constant_cpu_to_le16(rid);
2120 if (ha->flags.msix_enabled) {
2121 msix = &ha->msix_entries[1];
2122 ql_dbg(ql_dbg_init, vha, 0x00fd,
2123 "Registering vector 0x%x for base que.\n",
2125 icb->msix = cpu_to_le16(msix->entry);
2127 /* Use alternate PCI bus number */
2129 icb->firmware_options_2 |=
2130 __constant_cpu_to_le32(BIT_19);
2131 /* Use alternate PCI devfn */
2133 icb->firmware_options_2 |=
2134 __constant_cpu_to_le32(BIT_18);
2136 /* Use Disable MSIX Handshake mode for capable adapters */
2137 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
2138 (ha->flags.msix_enabled)) {
2139 icb->firmware_options_2 &=
2140 __constant_cpu_to_le32(~BIT_22);
2141 ha->flags.disable_msix_handshake = 1;
2142 ql_dbg(ql_dbg_init, vha, 0x00fe,
2143 "MSIX Handshake Disable Mode turned on.\n");
2145 icb->firmware_options_2 |=
2146 __constant_cpu_to_le32(BIT_22);
2148 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
2150 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
2151 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
2152 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
2153 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
2155 WRT_REG_DWORD(®->isp24.req_q_in, 0);
2156 WRT_REG_DWORD(®->isp24.req_q_out, 0);
2157 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
2158 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
2160 qlt_24xx_config_rings(vha);
2163 RD_REG_DWORD(&ioreg->hccr);
2167 * qla2x00_init_rings() - Initializes firmware.
2170 * Beginning of request ring has initialization control block already built
2171 * by nvram config routine.
2173 * Returns 0 on success.
2176 qla2x00_init_rings(scsi_qla_host_t *vha)
2179 unsigned long flags = 0;
2181 struct qla_hw_data *ha = vha->hw;
2182 struct req_que *req;
2183 struct rsp_que *rsp;
2184 struct mid_init_cb_24xx *mid_init_cb =
2185 (struct mid_init_cb_24xx *) ha->init_cb;
2187 spin_lock_irqsave(&ha->hardware_lock, flags);
2189 /* Clear outstanding commands array. */
2190 for (que = 0; que < ha->max_req_queues; que++) {
2191 req = ha->req_q_map[que];
2194 req->out_ptr = (void *)(req->ring + req->length);
2196 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
2197 req->outstanding_cmds[cnt] = NULL;
2199 req->current_outstanding_cmd = 1;
2201 /* Initialize firmware. */
2202 req->ring_ptr = req->ring;
2203 req->ring_index = 0;
2204 req->cnt = req->length;
2207 for (que = 0; que < ha->max_rsp_queues; que++) {
2208 rsp = ha->rsp_q_map[que];
2211 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
2213 /* Initialize response queue entries */
2215 qlafx00_init_response_q_entries(rsp);
2217 qla2x00_init_response_q_entries(rsp);
2220 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
2221 ha->tgt.atio_ring_index = 0;
2222 /* Initialize ATIO queue entries */
2223 qlt_init_atio_q_entries(vha);
2225 ha->isp_ops->config_rings(vha);
2227 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2229 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
2231 if (IS_QLAFX00(ha)) {
2232 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
2236 /* Update any ISP specific firmware options before initialization. */
2237 ha->isp_ops->update_fw_options(vha);
2239 if (ha->flags.npiv_supported) {
2240 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
2241 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
2242 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
2245 if (IS_FWI2_CAPABLE(ha)) {
2246 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
2247 mid_init_cb->init_cb.execution_throttle =
2248 cpu_to_le16(ha->fw_xcb_count);
2250 if (IS_DPORT_CAPABLE(ha))
2251 mid_init_cb->init_cb.firmware_options_1 |=
2253 /* Enable FA-WWPN */
2254 ha->flags.fawwpn_enabled =
2255 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) ? 1 : 0;
2256 ql_dbg(ql_dbg_init, vha, 0x0141, "FA-WWPN Support: %s.\n",
2257 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
2260 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
2263 ql_log(ql_log_fatal, vha, 0x00d2,
2264 "Init Firmware **** FAILED ****.\n");
2266 ql_dbg(ql_dbg_init, vha, 0x00d3,
2267 "Init Firmware -- success.\n");
2274 * qla2x00_fw_ready() - Waits for firmware ready.
2277 * Returns 0 on success.
2280 qla2x00_fw_ready(scsi_qla_host_t *vha)
2283 unsigned long wtime, mtime, cs84xx_time;
2284 uint16_t min_wait; /* Minimum wait time if loop is down */
2285 uint16_t wait_time; /* Wait time if loop is coming ready */
2287 struct qla_hw_data *ha = vha->hw;
2289 if (IS_QLAFX00(vha->hw))
2290 return qlafx00_fw_ready(vha);
2294 /* Time to wait for loop down */
2295 if (IS_P3P_TYPE(ha))
2301 * Firmware should take at most one RATOV to login, plus 5 seconds for
2302 * our own processing.
2304 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
2305 wait_time = min_wait;
2308 /* Min wait time if loop down */
2309 mtime = jiffies + (min_wait * HZ);
2311 /* wait time before firmware ready */
2312 wtime = jiffies + (wait_time * HZ);
2314 /* Wait for ISP to finish LIP */
2315 if (!vha->flags.init_done)
2316 ql_log(ql_log_info, vha, 0x801e,
2317 "Waiting for LIP to complete.\n");
2320 memset(state, -1, sizeof(state));
2321 rval = qla2x00_get_firmware_state(vha, state);
2322 if (rval == QLA_SUCCESS) {
2323 if (state[0] < FSTATE_LOSS_OF_SYNC) {
2324 vha->device_flags &= ~DFLG_NO_CABLE;
2326 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
2327 ql_dbg(ql_dbg_taskm, vha, 0x801f,
2328 "fw_state=%x 84xx=%x.\n", state[0],
2330 if ((state[2] & FSTATE_LOGGED_IN) &&
2331 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
2332 ql_dbg(ql_dbg_taskm, vha, 0x8028,
2333 "Sending verify iocb.\n");
2335 cs84xx_time = jiffies;
2336 rval = qla84xx_init_chip(vha);
2337 if (rval != QLA_SUCCESS) {
2340 "Init chip failed.\n");
2344 /* Add time taken to initialize. */
2345 cs84xx_time = jiffies - cs84xx_time;
2346 wtime += cs84xx_time;
2347 mtime += cs84xx_time;
2348 ql_dbg(ql_dbg_taskm, vha, 0x8008,
2349 "Increasing wait time by %ld. "
2350 "New time %ld.\n", cs84xx_time,
2353 } else if (state[0] == FSTATE_READY) {
2354 ql_dbg(ql_dbg_taskm, vha, 0x8037,
2355 "F/W Ready - OK.\n");
2357 qla2x00_get_retry_cnt(vha, &ha->retry_count,
2358 &ha->login_timeout, &ha->r_a_tov);
2364 rval = QLA_FUNCTION_FAILED;
2366 if (atomic_read(&vha->loop_down_timer) &&
2367 state[0] != FSTATE_READY) {
2368 /* Loop down. Timeout on min_wait for states
2369 * other than Wait for Login.
2371 if (time_after_eq(jiffies, mtime)) {
2372 ql_log(ql_log_info, vha, 0x8038,
2373 "Cable is unplugged...\n");
2375 vha->device_flags |= DFLG_NO_CABLE;
2380 /* Mailbox cmd failed. Timeout on min_wait. */
2381 if (time_after_eq(jiffies, mtime) ||
2382 ha->flags.isp82xx_fw_hung)
2386 if (time_after_eq(jiffies, wtime))
2389 /* Delay for a while */
2393 ql_dbg(ql_dbg_taskm, vha, 0x803a,
2394 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
2395 state[1], state[2], state[3], state[4], state[5], jiffies);
2397 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
2398 ql_log(ql_log_warn, vha, 0x803b,
2399 "Firmware ready **** FAILED ****.\n");
2406 * qla2x00_configure_hba
2407 * Setup adapter context.
2410 * ha = adapter state pointer.
2419 qla2x00_configure_hba(scsi_qla_host_t *vha)
2428 char connect_type[22];
2429 struct qla_hw_data *ha = vha->hw;
2430 unsigned long flags;
2431 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
2433 /* Get host addresses. */
2434 rval = qla2x00_get_adapter_id(vha,
2435 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
2436 if (rval != QLA_SUCCESS) {
2437 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
2438 IS_CNA_CAPABLE(ha) ||
2439 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
2440 ql_dbg(ql_dbg_disc, vha, 0x2008,
2441 "Loop is in a transition state.\n");
2443 ql_log(ql_log_warn, vha, 0x2009,
2444 "Unable to get host loop ID.\n");
2445 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
2446 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
2447 ql_log(ql_log_warn, vha, 0x1151,
2448 "Doing link init.\n");
2449 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
2452 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2458 ql_log(ql_log_info, vha, 0x200a,
2459 "Cannot get topology - retrying.\n");
2460 return (QLA_FUNCTION_FAILED);
2463 vha->loop_id = loop_id;
2466 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2467 ha->operating_mode = LOOP;
2472 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
2473 ha->current_topology = ISP_CFG_NL;
2474 strcpy(connect_type, "(Loop)");
2478 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
2479 ha->switch_cap = sw_cap;
2480 ha->current_topology = ISP_CFG_FL;
2481 strcpy(connect_type, "(FL_Port)");
2485 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
2486 ha->operating_mode = P2P;
2487 ha->current_topology = ISP_CFG_N;
2488 strcpy(connect_type, "(N_Port-to-N_Port)");
2492 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
2493 ha->switch_cap = sw_cap;
2494 ha->operating_mode = P2P;
2495 ha->current_topology = ISP_CFG_F;
2496 strcpy(connect_type, "(F_Port)");
2500 ql_dbg(ql_dbg_disc, vha, 0x200f,
2501 "HBA in unknown topology %x, using NL.\n", topo);
2502 ha->current_topology = ISP_CFG_NL;
2503 strcpy(connect_type, "(Loop)");
2507 /* Save Host port and loop ID. */
2508 /* byte order - Big Endian */
2509 vha->d_id.b.domain = domain;
2510 vha->d_id.b.area = area;
2511 vha->d_id.b.al_pa = al_pa;
2513 spin_lock_irqsave(&ha->vport_slock, flags);
2514 qlt_update_vp_map(vha, SET_AL_PA);
2515 spin_unlock_irqrestore(&ha->vport_slock, flags);
2517 if (!vha->flags.init_done)
2518 ql_log(ql_log_info, vha, 0x2010,
2519 "Topology - %s, Host Loop address 0x%x.\n",
2520 connect_type, vha->loop_id);
2526 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2531 struct qla_hw_data *ha = vha->hw;
2532 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
2533 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
2535 if (memcmp(model, BINZERO, len) != 0) {
2536 strncpy(ha->model_number, model, len);
2537 st = en = ha->model_number;
2540 if (*en != 0x20 && *en != 0x00)
2545 index = (ha->pdev->subsystem_device & 0xff);
2547 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
2548 index < QLA_MODEL_NAMES)
2549 strncpy(ha->model_desc,
2550 qla2x00_model_name[index * 2 + 1],
2551 sizeof(ha->model_desc) - 1);
2553 index = (ha->pdev->subsystem_device & 0xff);
2555 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
2556 index < QLA_MODEL_NAMES) {
2557 strcpy(ha->model_number,
2558 qla2x00_model_name[index * 2]);
2559 strncpy(ha->model_desc,
2560 qla2x00_model_name[index * 2 + 1],
2561 sizeof(ha->model_desc) - 1);
2563 strcpy(ha->model_number, def);
2566 if (IS_FWI2_CAPABLE(ha))
2567 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
2568 sizeof(ha->model_desc));
2571 /* On sparc systems, obtain port and node WWN from firmware
2574 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
2577 struct qla_hw_data *ha = vha->hw;
2578 struct pci_dev *pdev = ha->pdev;
2579 struct device_node *dp = pci_device_to_OF_node(pdev);
2583 val = of_get_property(dp, "port-wwn", &len);
2584 if (val && len >= WWN_SIZE)
2585 memcpy(nv->port_name, val, WWN_SIZE);
2587 val = of_get_property(dp, "node-wwn", &len);
2588 if (val && len >= WWN_SIZE)
2589 memcpy(nv->node_name, val, WWN_SIZE);
2594 * NVRAM configuration for ISP 2xxx
2597 * ha = adapter block pointer.
2600 * initialization control block in response_ring
2601 * host adapters parameters in host adapter block
2607 qla2x00_nvram_config(scsi_qla_host_t *vha)
2612 uint8_t *dptr1, *dptr2;
2613 struct qla_hw_data *ha = vha->hw;
2614 init_cb_t *icb = ha->init_cb;
2615 nvram_t *nv = ha->nvram;
2616 uint8_t *ptr = ha->nvram;
2617 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2621 /* Determine NVRAM starting address. */
2622 ha->nvram_size = sizeof(nvram_t);
2624 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2625 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
2626 ha->nvram_base = 0x80;
2628 /* Get NVRAM data and calculate checksum. */
2629 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
2630 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2633 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
2634 "Contents of NVRAM.\n");
2635 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
2636 (uint8_t *)nv, ha->nvram_size);
2638 /* Bad NVRAM data, set defaults parameters. */
2639 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2640 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2641 /* Reset NVRAM data. */
2642 ql_log(ql_log_warn, vha, 0x0064,
2643 "Inconsistent NVRAM "
2644 "detected: checksum=0x%x id=%c version=0x%x.\n",
2645 chksum, nv->id[0], nv->nvram_version);
2646 ql_log(ql_log_warn, vha, 0x0065,
2648 "functioning (yet invalid -- WWPN) defaults.\n");
2651 * Set default initialization control block.
2653 memset(nv, 0, ha->nvram_size);
2654 nv->parameter_block_version = ICB_VERSION;
2656 if (IS_QLA23XX(ha)) {
2657 nv->firmware_options[0] = BIT_2 | BIT_1;
2658 nv->firmware_options[1] = BIT_7 | BIT_5;
2659 nv->add_firmware_options[0] = BIT_5;
2660 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2661 nv->frame_payload_size = 2048;
2662 nv->special_options[1] = BIT_7;
2663 } else if (IS_QLA2200(ha)) {
2664 nv->firmware_options[0] = BIT_2 | BIT_1;
2665 nv->firmware_options[1] = BIT_7 | BIT_5;
2666 nv->add_firmware_options[0] = BIT_5;
2667 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2668 nv->frame_payload_size = 1024;
2669 } else if (IS_QLA2100(ha)) {
2670 nv->firmware_options[0] = BIT_3 | BIT_1;
2671 nv->firmware_options[1] = BIT_5;
2672 nv->frame_payload_size = 1024;
2675 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2676 nv->execution_throttle = __constant_cpu_to_le16(16);
2677 nv->retry_count = 8;
2678 nv->retry_delay = 1;
2680 nv->port_name[0] = 33;
2681 nv->port_name[3] = 224;
2682 nv->port_name[4] = 139;
2684 qla2xxx_nvram_wwn_from_ofw(vha, nv);
2686 nv->login_timeout = 4;
2689 * Set default host adapter parameters
2691 nv->host_p[1] = BIT_2;
2692 nv->reset_delay = 5;
2693 nv->port_down_retry_count = 8;
2694 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2695 nv->link_down_timeout = 60;
2700 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2702 * The SN2 does not provide BIOS emulation which means you can't change
2703 * potentially bogus BIOS settings. Force the use of default settings
2704 * for link rate and frame size. Hope that the rest of the settings
2707 if (ia64_platform_is("sn2")) {
2708 nv->frame_payload_size = 2048;
2710 nv->special_options[1] = BIT_7;
2714 /* Reset Initialization control block */
2715 memset(icb, 0, ha->init_cb_size);
2718 * Setup driver NVRAM options.
2720 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2721 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2722 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2723 nv->firmware_options[1] &= ~BIT_4;
2725 if (IS_QLA23XX(ha)) {
2726 nv->firmware_options[0] |= BIT_2;
2727 nv->firmware_options[0] &= ~BIT_3;
2728 nv->special_options[0] &= ~BIT_6;
2729 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
2731 if (IS_QLA2300(ha)) {
2732 if (ha->fb_rev == FPM_2310) {
2733 strcpy(ha->model_number, "QLA2310");
2735 strcpy(ha->model_number, "QLA2300");
2738 qla2x00_set_model_info(vha, nv->model_number,
2739 sizeof(nv->model_number), "QLA23xx");
2741 } else if (IS_QLA2200(ha)) {
2742 nv->firmware_options[0] |= BIT_2;
2744 * 'Point-to-point preferred, else loop' is not a safe
2745 * connection mode setting.
2747 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2749 /* Force 'loop preferred, else point-to-point'. */
2750 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2751 nv->add_firmware_options[0] |= BIT_5;
2753 strcpy(ha->model_number, "QLA22xx");
2754 } else /*if (IS_QLA2100(ha))*/ {
2755 strcpy(ha->model_number, "QLA2100");
2759 * Copy over NVRAM RISC parameter block to initialization control block.
2761 dptr1 = (uint8_t *)icb;
2762 dptr2 = (uint8_t *)&nv->parameter_block_version;
2763 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2765 *dptr1++ = *dptr2++;
2767 /* Copy 2nd half. */
2768 dptr1 = (uint8_t *)icb->add_firmware_options;
2769 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2771 *dptr1++ = *dptr2++;
2773 /* Use alternate WWN? */
2774 if (nv->host_p[1] & BIT_7) {
2775 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2776 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2779 /* Prepare nodename */
2780 if ((icb->firmware_options[1] & BIT_6) == 0) {
2782 * Firmware will apply the following mask if the nodename was
2785 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2786 icb->node_name[0] &= 0xF0;
2790 * Set host adapter parameters.
2794 * BIT_7 in the host-parameters section allows for modification to
2795 * internal driver logging.
2797 if (nv->host_p[0] & BIT_7)
2798 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
2799 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2800 /* Always load RISC code on non ISP2[12]00 chips. */
2801 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2802 ha->flags.disable_risc_code_load = 0;
2803 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2804 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2805 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
2806 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
2807 ha->flags.disable_serdes = 0;
2809 ha->operating_mode =
2810 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2812 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2813 sizeof(ha->fw_seriallink_options));
2815 /* save HBA serial number */
2816 ha->serial0 = icb->port_name[5];
2817 ha->serial1 = icb->port_name[6];
2818 ha->serial2 = icb->port_name[7];
2819 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2820 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
2822 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2824 ha->retry_count = nv->retry_count;
2826 /* Set minimum login_timeout to 4 seconds. */
2827 if (nv->login_timeout != ql2xlogintimeout)
2828 nv->login_timeout = ql2xlogintimeout;
2829 if (nv->login_timeout < 4)
2830 nv->login_timeout = 4;
2831 ha->login_timeout = nv->login_timeout;
2832 icb->login_timeout = nv->login_timeout;
2834 /* Set minimum RATOV to 100 tenths of a second. */
2837 ha->loop_reset_delay = nv->reset_delay;
2839 /* Link Down Timeout = 0:
2841 * When Port Down timer expires we will start returning
2842 * I/O's to OS with "DID_NO_CONNECT".
2844 * Link Down Timeout != 0:
2846 * The driver waits for the link to come up after link down
2847 * before returning I/Os to OS with "DID_NO_CONNECT".
2849 if (nv->link_down_timeout == 0) {
2850 ha->loop_down_abort_time =
2851 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
2853 ha->link_down_timeout = nv->link_down_timeout;
2854 ha->loop_down_abort_time =
2855 (LOOP_DOWN_TIME - ha->link_down_timeout);
2859 * Need enough time to try and get the port back.
2861 ha->port_down_retry_count = nv->port_down_retry_count;
2862 if (qlport_down_retry)
2863 ha->port_down_retry_count = qlport_down_retry;
2864 /* Set login_retry_count */
2865 ha->login_retry_count = nv->retry_count;
2866 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2867 ha->port_down_retry_count > 3)
2868 ha->login_retry_count = ha->port_down_retry_count;
2869 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2870 ha->login_retry_count = ha->port_down_retry_count;
2871 if (ql2xloginretrycount)
2872 ha->login_retry_count = ql2xloginretrycount;
2874 icb->lun_enables = __constant_cpu_to_le16(0);
2875 icb->command_resource_count = 0;
2876 icb->immediate_notify_resource_count = 0;
2877 icb->timeout = __constant_cpu_to_le16(0);
2879 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2881 icb->firmware_options[0] &= ~BIT_3;
2882 icb->add_firmware_options[0] &=
2883 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2884 icb->add_firmware_options[0] |= BIT_2;
2885 icb->response_accumulation_timer = 3;
2886 icb->interrupt_delay_timer = 5;
2888 vha->flags.process_response_queue = 1;
2891 if (!vha->flags.init_done) {
2892 ha->zio_mode = icb->add_firmware_options[0] &
2893 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2894 ha->zio_timer = icb->interrupt_delay_timer ?
2895 icb->interrupt_delay_timer: 2;
2897 icb->add_firmware_options[0] &=
2898 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2899 vha->flags.process_response_queue = 0;
2900 if (ha->zio_mode != QLA_ZIO_DISABLED) {
2901 ha->zio_mode = QLA_ZIO_MODE_6;
2903 ql_log(ql_log_info, vha, 0x0068,
2904 "ZIO mode %d enabled; timer delay (%d us).\n",
2905 ha->zio_mode, ha->zio_timer * 100);
2907 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2908 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
2909 vha->flags.process_response_queue = 1;
2914 ql_log(ql_log_warn, vha, 0x0069,
2915 "NVRAM configuration failed.\n");
2921 qla2x00_rport_del(void *data)
2923 fc_port_t *fcport = data;
2924 struct fc_rport *rport;
2925 scsi_qla_host_t *vha = fcport->vha;
2926 unsigned long flags;
2927 unsigned long vha_flags;
2929 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
2930 rport = fcport->drport ? fcport->drport: fcport->rport;
2931 fcport->drport = NULL;
2932 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
2934 fc_remote_port_delete(rport);
2936 * Release the target mode FC NEXUS in qla_target.c code
2937 * if target mod is enabled.
2939 spin_lock_irqsave(&vha->hw->hardware_lock, vha_flags);
2940 qlt_fc_port_deleted(vha, fcport);
2941 spin_unlock_irqrestore(&vha->hw->hardware_lock, vha_flags);
2946 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2948 * @flags: allocation flags
2950 * Returns a pointer to the allocated fcport, or NULL, if none available.
2953 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
2957 fcport = kzalloc(sizeof(fc_port_t), flags);
2961 /* Setup fcport template structure. */
2963 fcport->port_type = FCT_UNKNOWN;
2964 fcport->loop_id = FC_NO_LOOP_ID;
2965 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
2966 fcport->supported_classes = FC_COS_UNSPECIFIED;
2972 * qla2x00_configure_loop
2973 * Updates Fibre Channel Device Database with what is actually on loop.
2976 * ha = adapter block pointer.
2981 * 2 = database was full and device was not configured.
2984 qla2x00_configure_loop(scsi_qla_host_t *vha)
2987 unsigned long flags, save_flags;
2988 struct qla_hw_data *ha = vha->hw;
2991 /* Get Initiator ID */
2992 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2993 rval = qla2x00_configure_hba(vha);
2994 if (rval != QLA_SUCCESS) {
2995 ql_dbg(ql_dbg_disc, vha, 0x2013,
2996 "Unable to configure HBA.\n");
3001 save_flags = flags = vha->dpc_flags;
3002 ql_dbg(ql_dbg_disc, vha, 0x2014,
3003 "Configure loop -- dpc flags = 0x%lx.\n", flags);
3006 * If we have both an RSCN and PORT UPDATE pending then handle them
3007 * both at the same time.
3009 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
3010 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
3012 qla2x00_get_data_rate(vha);
3014 /* Determine what we need to do */
3015 if (ha->current_topology == ISP_CFG_FL &&
3016 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
3018 set_bit(RSCN_UPDATE, &flags);
3020 } else if (ha->current_topology == ISP_CFG_F &&
3021 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
3023 set_bit(RSCN_UPDATE, &flags);
3024 clear_bit(LOCAL_LOOP_UPDATE, &flags);
3026 } else if (ha->current_topology == ISP_CFG_N) {
3027 clear_bit(RSCN_UPDATE, &flags);
3029 } else if (!vha->flags.online ||
3030 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
3032 set_bit(RSCN_UPDATE, &flags);
3033 set_bit(LOCAL_LOOP_UPDATE, &flags);
3036 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
3037 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
3038 ql_dbg(ql_dbg_disc, vha, 0x2015,
3039 "Loop resync needed, failing.\n");
3040 rval = QLA_FUNCTION_FAILED;
3042 rval = qla2x00_configure_local_loop(vha);
3045 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
3046 if (LOOP_TRANSITION(vha)) {
3047 ql_dbg(ql_dbg_disc, vha, 0x201e,
3048 "Needs RSCN update and loop transition.\n");
3049 rval = QLA_FUNCTION_FAILED;
3052 rval = qla2x00_configure_fabric(vha);
3055 if (rval == QLA_SUCCESS) {
3056 if (atomic_read(&vha->loop_down_timer) ||
3057 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
3058 rval = QLA_FUNCTION_FAILED;
3060 atomic_set(&vha->loop_state, LOOP_READY);
3061 ql_dbg(ql_dbg_disc, vha, 0x2069,
3067 ql_dbg(ql_dbg_disc, vha, 0x206a,
3068 "%s *** FAILED ***.\n", __func__);
3070 ql_dbg(ql_dbg_disc, vha, 0x206b,
3071 "%s: exiting normally.\n", __func__);
3074 /* Restore state if a resync event occurred during processing */
3075 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
3076 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
3077 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
3078 if (test_bit(RSCN_UPDATE, &save_flags)) {
3079 set_bit(RSCN_UPDATE, &vha->dpc_flags);
3089 * qla2x00_configure_local_loop
3090 * Updates Fibre Channel Device Database with local loop devices.
3093 * ha = adapter block pointer.
3099 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
3104 fc_port_t *fcport, *new_fcport;
3110 uint8_t domain, area, al_pa;
3111 struct qla_hw_data *ha = vha->hw;
3115 entries = MAX_FIBRE_DEVICES_LOOP;
3117 /* Get list of logged in devices. */
3118 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
3119 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
3121 if (rval != QLA_SUCCESS)
3122 goto cleanup_allocation;
3124 ql_dbg(ql_dbg_disc, vha, 0x2017,
3125 "Entries in ID list (%d).\n", entries);
3126 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
3127 (uint8_t *)ha->gid_list,
3128 entries * sizeof(struct gid_list_info));
3130 /* Allocate temporary fcport for any new fcports discovered. */
3131 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
3132 if (new_fcport == NULL) {
3133 ql_log(ql_log_warn, vha, 0x2018,
3134 "Memory allocation failed for fcport.\n");
3135 rval = QLA_MEMORY_ALLOC_FAILED;
3136 goto cleanup_allocation;
3138 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
3141 * Mark local devices that were present with FCF_DEVICE_LOST for now.
3143 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3144 if (atomic_read(&fcport->state) == FCS_ONLINE &&
3145 fcport->port_type != FCT_BROADCAST &&
3146 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3148 ql_dbg(ql_dbg_disc, vha, 0x2019,
3149 "Marking port lost loop_id=0x%04x.\n",
3152 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3156 /* Add devices to port list. */
3157 id_iter = (char *)ha->gid_list;
3158 for (index = 0; index < entries; index++) {
3159 domain = ((struct gid_list_info *)id_iter)->domain;
3160 area = ((struct gid_list_info *)id_iter)->area;
3161 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
3162 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3163 loop_id = (uint16_t)
3164 ((struct gid_list_info *)id_iter)->loop_id_2100;
3166 loop_id = le16_to_cpu(
3167 ((struct gid_list_info *)id_iter)->loop_id);
3168 id_iter += ha->gid_list_info_size;
3170 /* Bypass reserved domain fields. */
3171 if ((domain & 0xf0) == 0xf0)
3174 /* Bypass if not same domain and area of adapter. */
3175 if (area && domain &&
3176 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
3179 /* Bypass invalid local loop ID. */
3180 if (loop_id > LAST_LOCAL_LOOP_ID)
3183 memset(new_fcport, 0, sizeof(fc_port_t));
3185 /* Fill in member data. */
3186 new_fcport->d_id.b.domain = domain;
3187 new_fcport->d_id.b.area = area;
3188 new_fcport->d_id.b.al_pa = al_pa;
3189 new_fcport->loop_id = loop_id;
3190 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
3191 if (rval2 != QLA_SUCCESS) {
3192 ql_dbg(ql_dbg_disc, vha, 0x201a,
3193 "Failed to retrieve fcport information "
3194 "-- get_port_database=%x, loop_id=0x%04x.\n",
3195 rval2, new_fcport->loop_id);
3196 ql_dbg(ql_dbg_disc, vha, 0x201b,
3197 "Scheduling resync.\n");
3198 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3202 /* Check for matching device in port list. */
3205 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3206 if (memcmp(new_fcport->port_name, fcport->port_name,
3210 fcport->flags &= ~FCF_FABRIC_DEVICE;
3211 fcport->loop_id = new_fcport->loop_id;
3212 fcport->port_type = new_fcport->port_type;
3213 fcport->d_id.b24 = new_fcport->d_id.b24;
3214 memcpy(fcport->node_name, new_fcport->node_name,
3222 /* New device, add to fcports list. */
3223 list_add_tail(&new_fcport->list, &vha->vp_fcports);
3225 /* Allocate a new replacement fcport. */
3226 fcport = new_fcport;
3227 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
3228 if (new_fcport == NULL) {
3229 ql_log(ql_log_warn, vha, 0x201c,
3230 "Failed to allocate memory for fcport.\n");
3231 rval = QLA_MEMORY_ALLOC_FAILED;
3232 goto cleanup_allocation;
3234 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
3237 /* Base iIDMA settings on HBA port speed. */
3238 fcport->fp_speed = ha->link_data_rate;
3240 qla2x00_update_fcport(vha, fcport);
3248 if (rval != QLA_SUCCESS) {
3249 ql_dbg(ql_dbg_disc, vha, 0x201d,
3250 "Configure local loop error exit: rval=%x.\n", rval);
3257 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
3260 uint16_t mb[MAILBOX_REGISTER_COUNT];
3261 struct qla_hw_data *ha = vha->hw;
3263 if (!IS_IIDMA_CAPABLE(ha))
3266 if (atomic_read(&fcport->state) != FCS_ONLINE)
3269 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
3270 fcport->fp_speed > ha->link_data_rate)
3273 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
3275 if (rval != QLA_SUCCESS) {
3276 ql_dbg(ql_dbg_disc, vha, 0x2004,
3277 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
3278 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
3280 ql_dbg(ql_dbg_disc, vha, 0x2005,
3281 "iIDMA adjusted to %s GB/s on %8phN.\n",
3282 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
3288 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
3290 struct fc_rport_identifiers rport_ids;
3291 struct fc_rport *rport;
3292 unsigned long flags;
3294 rport_ids.node_name = wwn_to_u64(fcport->node_name);
3295 rport_ids.port_name = wwn_to_u64(fcport->port_name);
3296 rport_ids.port_id = fcport->d_id.b.domain << 16 |
3297 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
3298 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
3299 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
3301 ql_log(ql_log_warn, vha, 0x2006,
3302 "Unable to allocate fc remote port.\n");
3306 * Create target mode FC NEXUS in qla_target.c if target mode is
3310 qlt_fc_port_added(vha, fcport);
3312 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
3313 *((fc_port_t **)rport->dd_data) = fcport;
3314 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
3316 rport->supported_classes = fcport->supported_classes;
3318 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
3319 if (fcport->port_type == FCT_INITIATOR)
3320 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
3321 if (fcport->port_type == FCT_TARGET)
3322 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
3323 fc_remote_port_rolechg(rport, rport_ids.roles);
3327 * qla2x00_update_fcport
3328 * Updates device on list.
3331 * ha = adapter block pointer.
3332 * fcport = port structure pointer.
3342 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
3346 if (IS_QLAFX00(vha->hw)) {
3347 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
3348 qla2x00_reg_remote_port(vha, fcport);
3351 fcport->login_retry = 0;
3352 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
3354 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
3355 qla2x00_iidma_fcport(vha, fcport);
3356 qla24xx_update_fcport_fcp_prio(vha, fcport);
3357 qla2x00_reg_remote_port(vha, fcport);
3361 * qla2x00_configure_fabric
3362 * Setup SNS devices with loop ID's.
3365 * ha = adapter block pointer.
3372 qla2x00_configure_fabric(scsi_qla_host_t *vha)
3375 fc_port_t *fcport, *fcptemp;
3376 uint16_t next_loopid;
3377 uint16_t mb[MAILBOX_REGISTER_COUNT];
3379 LIST_HEAD(new_fcports);
3380 struct qla_hw_data *ha = vha->hw;
3381 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3383 /* If FL port exists, then SNS is present */
3384 if (IS_FWI2_CAPABLE(ha))
3385 loop_id = NPH_F_PORT;
3387 loop_id = SNS_FL_PORT;
3388 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
3389 if (rval != QLA_SUCCESS) {
3390 ql_dbg(ql_dbg_disc, vha, 0x201f,
3391 "MBX_GET_PORT_NAME failed, No FL Port.\n");
3393 vha->device_flags &= ~SWITCH_FOUND;
3394 return (QLA_SUCCESS);
3396 vha->device_flags |= SWITCH_FOUND;
3400 if (ql2xfdmienable &&
3401 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
3402 qla2x00_fdmi_register(vha);
3404 /* Ensure we are logged into the SNS. */
3405 if (IS_FWI2_CAPABLE(ha))
3408 loop_id = SIMPLE_NAME_SERVER;
3409 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
3410 0xfc, mb, BIT_1|BIT_0);
3411 if (rval != QLA_SUCCESS) {
3412 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3415 if (mb[0] != MBS_COMMAND_COMPLETE) {
3416 ql_dbg(ql_dbg_disc, vha, 0x2042,
3417 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
3418 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
3419 mb[2], mb[6], mb[7]);
3420 return (QLA_SUCCESS);
3423 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3424 if (qla2x00_rft_id(vha)) {
3426 ql_dbg(ql_dbg_disc, vha, 0x2045,
3427 "Register FC-4 TYPE failed.\n");
3429 if (qla2x00_rff_id(vha)) {
3431 ql_dbg(ql_dbg_disc, vha, 0x2049,
3432 "Register FC-4 Features failed.\n");
3434 if (qla2x00_rnn_id(vha)) {
3436 ql_dbg(ql_dbg_disc, vha, 0x204f,
3437 "Register Node Name failed.\n");
3438 } else if (qla2x00_rsnn_nn(vha)) {
3440 ql_dbg(ql_dbg_disc, vha, 0x2053,
3441 "Register Symobilic Node Name failed.\n");
3445 #define QLA_FCPORT_SCAN 1
3446 #define QLA_FCPORT_FOUND 2
3448 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3449 fcport->scan_state = QLA_FCPORT_SCAN;
3452 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
3453 if (rval != QLA_SUCCESS)
3457 * Logout all previous fabric devices marked lost, except
3460 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3461 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3464 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3467 if (fcport->scan_state == QLA_FCPORT_SCAN) {
3468 if (qla_ini_mode_enabled(base_vha) &&
3469 atomic_read(&fcport->state) == FCS_ONLINE) {
3470 qla2x00_mark_device_lost(vha, fcport,
3471 ql2xplogiabsentdevice, 0);
3472 if (fcport->loop_id != FC_NO_LOOP_ID &&
3473 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
3474 fcport->port_type != FCT_INITIATOR &&
3475 fcport->port_type != FCT_BROADCAST) {
3476 ha->isp_ops->fabric_logout(vha,
3478 fcport->d_id.b.domain,
3479 fcport->d_id.b.area,
3480 fcport->d_id.b.al_pa);
3481 qla2x00_clear_loop_id(fcport);
3483 } else if (!qla_ini_mode_enabled(base_vha)) {
3485 * In target mode, explicitly kill
3486 * sessions and log out of devices
3487 * that are gone, so that we don't
3488 * end up with an initiator using the
3489 * wrong ACL (if the fabric recycles
3490 * an FC address and we have a stale
3491 * session around) and so that we don't
3492 * report initiators that are no longer
3495 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf077,
3496 "port gone, logging out/killing session: "
3497 "%8phC state 0x%x flags 0x%x fc4_type 0x%x "
3500 atomic_read(&fcport->state),
3501 fcport->flags, fcport->fc4_type,
3502 fcport->scan_state);
3503 qlt_fc_port_deleted(vha, fcport);
3508 /* Starting free loop ID. */
3509 next_loopid = ha->min_external_loopid;
3512 * Scan through our port list and login entries that need to be
3515 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3516 if (atomic_read(&vha->loop_down_timer) ||
3517 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3520 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3521 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3525 * If we're not an initiator, skip looking for devices
3526 * and logging in. There's no reason for us to do it,
3527 * and it seems to actively cause problems in target
3528 * mode if we race with the initiator logging into us
3529 * (we might get the "port ID used" status back from
3530 * our login command and log out the initiator, which
3531 * seems to cause havoc).
3533 if (!qla_ini_mode_enabled(base_vha)) {
3534 if (fcport->scan_state == QLA_FCPORT_FOUND) {
3535 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf078,
3536 "port %8phC state 0x%x flags 0x%x fc4_type 0x%x "
3537 "scan_state %d (initiator mode disabled; skipping "
3538 "login)\n", fcport->port_name,
3539 atomic_read(&fcport->state),
3540 fcport->flags, fcport->fc4_type,
3541 fcport->scan_state);
3546 if (fcport->loop_id == FC_NO_LOOP_ID) {
3547 fcport->loop_id = next_loopid;
3548 rval = qla2x00_find_new_loop_id(
3550 if (rval != QLA_SUCCESS) {
3551 /* Ran out of IDs to use */
3555 /* Login and update database */
3556 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
3559 /* Exit if out of loop IDs. */
3560 if (rval != QLA_SUCCESS) {
3565 * Login and add the new devices to our port list.
3567 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3568 if (atomic_read(&vha->loop_down_timer) ||
3569 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3573 * If we're not an initiator, skip looking for devices
3574 * and logging in. There's no reason for us to do it,
3575 * and it seems to actively cause problems in target
3576 * mode if we race with the initiator logging into us
3577 * (we might get the "port ID used" status back from
3578 * our login command and log out the initiator, which
3579 * seems to cause havoc).
3581 if (qla_ini_mode_enabled(base_vha)) {
3582 /* Find a new loop ID to use. */
3583 fcport->loop_id = next_loopid;
3584 rval = qla2x00_find_new_loop_id(base_vha,
3586 if (rval != QLA_SUCCESS) {
3587 /* Ran out of IDs to use */
3591 /* Login and update database */
3592 qla2x00_fabric_dev_login(vha, fcport,
3595 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf079,
3596 "new port %8phC state 0x%x flags 0x%x fc4_type "
3597 "0x%x scan_state %d (initiator mode disabled; "
3598 "skipping login)\n",
3600 atomic_read(&fcport->state),
3601 fcport->flags, fcport->fc4_type,
3602 fcport->scan_state);
3605 list_move_tail(&fcport->list, &vha->vp_fcports);
3609 /* Free all new device structures not processed. */
3610 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3611 list_del(&fcport->list);
3616 ql_dbg(ql_dbg_disc, vha, 0x2068,
3617 "Configure fabric error exit rval=%d.\n", rval);
3624 * qla2x00_find_all_fabric_devs
3627 * ha = adapter block pointer.
3628 * dev = database device entry pointer.
3637 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3638 struct list_head *new_fcports)
3642 fc_port_t *fcport, *new_fcport, *fcptemp;
3647 int first_dev, last_dev;
3648 port_id_t wrap = {}, nxt_d_id;
3649 struct qla_hw_data *ha = vha->hw;
3650 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3654 /* Try GID_PT to get device list, else GAN. */
3656 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
3661 ql_dbg(ql_dbg_disc, vha, 0x2054,
3662 "GID_PT allocations failed, fallback on GA_NXT.\n");
3664 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
3665 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
3667 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
3669 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
3671 } else if (ql2xiidmaenable &&
3672 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3673 qla2x00_gpsc(vha, swl);
3676 /* If other queries succeeded probe for FC-4 type */
3678 qla2x00_gff_id(vha, swl);
3682 /* Allocate temporary fcport for any new fcports discovered. */
3683 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
3684 if (new_fcport == NULL) {
3685 ql_log(ql_log_warn, vha, 0x205e,
3686 "Failed to allocate memory for fcport.\n");
3687 return (QLA_MEMORY_ALLOC_FAILED);
3689 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3690 /* Set start port ID scan at adapter ID. */
3694 /* Starting free loop ID. */
3695 loop_id = ha->min_external_loopid;
3696 for (; loop_id <= ha->max_loop_id; loop_id++) {
3697 if (qla2x00_is_reserved_id(vha, loop_id))
3700 if (ha->current_topology == ISP_CFG_FL &&
3701 (atomic_read(&vha->loop_down_timer) ||
3702 LOOP_TRANSITION(vha))) {
3703 atomic_set(&vha->loop_down_timer, 0);
3704 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3705 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
3711 wrap.b24 = new_fcport->d_id.b24;
3713 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3714 memcpy(new_fcport->node_name,
3715 swl[swl_idx].node_name, WWN_SIZE);
3716 memcpy(new_fcport->port_name,
3717 swl[swl_idx].port_name, WWN_SIZE);
3718 memcpy(new_fcport->fabric_port_name,
3719 swl[swl_idx].fabric_port_name, WWN_SIZE);
3720 new_fcport->fp_speed = swl[swl_idx].fp_speed;
3721 new_fcport->fc4_type = swl[swl_idx].fc4_type;
3723 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3729 /* Send GA_NXT to the switch */
3730 rval = qla2x00_ga_nxt(vha, new_fcport);
3731 if (rval != QLA_SUCCESS) {
3732 ql_log(ql_log_warn, vha, 0x2064,
3733 "SNS scan failed -- assuming "
3734 "zero-entry result.\n");
3735 list_for_each_entry_safe(fcport, fcptemp,
3736 new_fcports, list) {
3737 list_del(&fcport->list);
3745 /* If wrap on switch device list, exit. */
3747 wrap.b24 = new_fcport->d_id.b24;
3749 } else if (new_fcport->d_id.b24 == wrap.b24) {
3750 ql_dbg(ql_dbg_disc, vha, 0x2065,
3751 "Device wrap (%02x%02x%02x).\n",
3752 new_fcport->d_id.b.domain,
3753 new_fcport->d_id.b.area,
3754 new_fcport->d_id.b.al_pa);
3758 /* Bypass if same physical adapter. */
3759 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
3762 /* Bypass virtual ports of the same host. */
3763 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
3766 /* Bypass if same domain and area of adapter. */
3767 if (((new_fcport->d_id.b24 & 0xffff00) ==
3768 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
3772 /* Bypass reserved domain fields. */
3773 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3776 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
3777 if (ql2xgffidenable &&
3778 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3779 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
3782 /* Locate matching device in database. */
3784 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3785 if (memcmp(new_fcport->port_name, fcport->port_name,
3789 fcport->scan_state = QLA_FCPORT_FOUND;
3793 /* Update port state. */
3794 memcpy(fcport->fabric_port_name,
3795 new_fcport->fabric_port_name, WWN_SIZE);
3796 fcport->fp_speed = new_fcport->fp_speed;
3799 * If address the same and state FCS_ONLINE
3800 * (or in target mode), nothing changed.
3802 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3803 (atomic_read(&fcport->state) == FCS_ONLINE ||
3804 !qla_ini_mode_enabled(base_vha))) {
3809 * If device was not a fabric device before.
3811 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3812 fcport->d_id.b24 = new_fcport->d_id.b24;
3813 qla2x00_clear_loop_id(fcport);
3814 fcport->flags |= (FCF_FABRIC_DEVICE |
3820 * Port ID changed or device was marked to be updated;
3821 * Log it out if still logged in and mark it for
3824 if (!qla_ini_mode_enabled(base_vha)) {
3825 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
3826 "port changed FC ID, %8phC"
3827 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
3829 fcport->d_id.b.domain,
3830 fcport->d_id.b.area,
3831 fcport->d_id.b.al_pa,
3833 new_fcport->d_id.b.domain,
3834 new_fcport->d_id.b.area,
3835 new_fcport->d_id.b.al_pa);
3836 fcport->d_id.b24 = new_fcport->d_id.b24;
3840 fcport->d_id.b24 = new_fcport->d_id.b24;
3841 fcport->flags |= FCF_LOGIN_NEEDED;
3842 if (fcport->loop_id != FC_NO_LOOP_ID &&
3843 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
3844 (fcport->flags & FCF_ASYNC_SENT) == 0 &&
3845 fcport->port_type != FCT_INITIATOR &&
3846 fcport->port_type != FCT_BROADCAST) {
3847 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3848 fcport->d_id.b.domain, fcport->d_id.b.area,
3849 fcport->d_id.b.al_pa);
3850 qla2x00_clear_loop_id(fcport);
3858 /* If device was not in our fcports list, then add it. */
3859 new_fcport->scan_state = QLA_FCPORT_FOUND;
3860 list_add_tail(&new_fcport->list, new_fcports);
3862 /* Allocate a new replacement fcport. */
3863 nxt_d_id.b24 = new_fcport->d_id.b24;
3864 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
3865 if (new_fcport == NULL) {
3866 ql_log(ql_log_warn, vha, 0x2066,
3867 "Memory allocation failed for fcport.\n");
3868 return (QLA_MEMORY_ALLOC_FAILED);
3870 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3871 new_fcport->d_id.b24 = nxt_d_id.b24;
3880 * qla2x00_find_new_loop_id
3881 * Scan through our port list and find a new usable loop ID.
3884 * ha: adapter state pointer.
3885 * dev: port structure pointer.
3888 * qla2x00 local function return status code.
3894 qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
3897 struct qla_hw_data *ha = vha->hw;
3898 unsigned long flags = 0;
3902 spin_lock_irqsave(&ha->vport_slock, flags);
3904 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
3906 if (dev->loop_id >= LOOPID_MAP_SIZE ||
3907 qla2x00_is_reserved_id(vha, dev->loop_id)) {
3908 dev->loop_id = FC_NO_LOOP_ID;
3909 rval = QLA_FUNCTION_FAILED;
3911 set_bit(dev->loop_id, ha->loop_id_map);
3913 spin_unlock_irqrestore(&ha->vport_slock, flags);
3915 if (rval == QLA_SUCCESS)
3916 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
3917 "Assigning new loopid=%x, portid=%x.\n",
3918 dev->loop_id, dev->d_id.b24);
3920 ql_log(ql_log_warn, dev->vha, 0x2087,
3921 "No loop_id's available, portid=%x.\n",
3928 * qla2x00_fabric_dev_login
3929 * Login fabric target device and update FC port database.
3932 * ha: adapter state pointer.
3933 * fcport: port structure list pointer.
3934 * next_loopid: contains value of a new loop ID that can be used
3935 * by the next login attempt.
3938 * qla2x00 local function return status code.
3944 qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
3945 uint16_t *next_loopid)
3950 struct qla_hw_data *ha = vha->hw;
3955 if (IS_ALOGIO_CAPABLE(ha)) {
3956 if (fcport->flags & FCF_ASYNC_SENT)
3958 fcport->flags |= FCF_ASYNC_SENT;
3959 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3964 fcport->flags &= ~FCF_ASYNC_SENT;
3965 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
3966 if (rval == QLA_SUCCESS) {
3967 /* Send an ADISC to FCP2 devices.*/
3969 if (fcport->flags & FCF_FCP2_DEVICE)
3971 rval = qla2x00_get_port_database(vha, fcport, opts);
3972 if (rval != QLA_SUCCESS) {
3973 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
3974 fcport->d_id.b.domain, fcport->d_id.b.area,
3975 fcport->d_id.b.al_pa);
3976 qla2x00_mark_device_lost(vha, fcport, 1, 0);
3978 qla2x00_update_fcport(vha, fcport);
3982 qla2x00_mark_device_lost(vha, fcport, 1, 0);
3989 * qla2x00_fabric_login
3990 * Issue fabric login command.
3993 * ha = adapter block pointer.
3994 * device = pointer to FC device type structure.
3997 * 0 - Login successfully
3999 * 2 - Initiator device
4003 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
4004 uint16_t *next_loopid)
4008 uint16_t tmp_loopid;
4009 uint16_t mb[MAILBOX_REGISTER_COUNT];
4010 struct qla_hw_data *ha = vha->hw;
4016 ql_dbg(ql_dbg_disc, vha, 0x2000,
4017 "Trying Fabric Login w/loop id 0x%04x for port "
4019 fcport->loop_id, fcport->d_id.b.domain,
4020 fcport->d_id.b.area, fcport->d_id.b.al_pa);
4022 /* Login fcport on switch. */
4023 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
4024 fcport->d_id.b.domain, fcport->d_id.b.area,
4025 fcport->d_id.b.al_pa, mb, BIT_0);
4026 if (rval != QLA_SUCCESS) {
4029 if (mb[0] == MBS_PORT_ID_USED) {
4031 * Device has another loop ID. The firmware team
4032 * recommends the driver perform an implicit login with
4033 * the specified ID again. The ID we just used is save
4034 * here so we return with an ID that can be tried by
4038 tmp_loopid = fcport->loop_id;
4039 fcport->loop_id = mb[1];
4041 ql_dbg(ql_dbg_disc, vha, 0x2001,
4042 "Fabric Login: port in use - next loop "
4043 "id=0x%04x, port id= %02x%02x%02x.\n",
4044 fcport->loop_id, fcport->d_id.b.domain,
4045 fcport->d_id.b.area, fcport->d_id.b.al_pa);
4047 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
4052 /* A retry occurred before. */
4053 *next_loopid = tmp_loopid;
4056 * No retry occurred before. Just increment the
4057 * ID value for next login.
4059 *next_loopid = (fcport->loop_id + 1);
4062 if (mb[1] & BIT_0) {
4063 fcport->port_type = FCT_INITIATOR;
4065 fcport->port_type = FCT_TARGET;
4066 if (mb[1] & BIT_1) {
4067 fcport->flags |= FCF_FCP2_DEVICE;
4072 fcport->supported_classes |= FC_COS_CLASS2;
4074 fcport->supported_classes |= FC_COS_CLASS3;
4076 if (IS_FWI2_CAPABLE(ha)) {
4079 FCF_CONF_COMP_SUPPORTED;
4084 } else if (mb[0] == MBS_LOOP_ID_USED) {
4086 * Loop ID already used, try next loop ID.
4089 rval = qla2x00_find_new_loop_id(vha, fcport);
4090 if (rval != QLA_SUCCESS) {
4091 /* Ran out of loop IDs to use */
4094 } else if (mb[0] == MBS_COMMAND_ERROR) {
4096 * Firmware possibly timed out during login. If NO
4097 * retries are left to do then the device is declared
4100 *next_loopid = fcport->loop_id;
4101 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
4102 fcport->d_id.b.domain, fcport->d_id.b.area,
4103 fcport->d_id.b.al_pa);
4104 qla2x00_mark_device_lost(vha, fcport, 1, 0);
4110 * unrecoverable / not handled error
4112 ql_dbg(ql_dbg_disc, vha, 0x2002,
4113 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
4114 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
4115 fcport->d_id.b.area, fcport->d_id.b.al_pa,
4116 fcport->loop_id, jiffies);
4118 *next_loopid = fcport->loop_id;
4119 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
4120 fcport->d_id.b.domain, fcport->d_id.b.area,
4121 fcport->d_id.b.al_pa);
4122 qla2x00_clear_loop_id(fcport);
4123 fcport->login_retry = 0;
4134 * qla2x00_local_device_login
4135 * Issue local device login command.
4138 * ha = adapter block pointer.
4139 * loop_id = loop id of device to login to.
4141 * Returns (Where's the #define!!!!):
4142 * 0 - Login successfully
4147 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
4150 uint16_t mb[MAILBOX_REGISTER_COUNT];
4152 memset(mb, 0, sizeof(mb));
4153 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
4154 if (rval == QLA_SUCCESS) {
4155 /* Interrogate mailbox registers for any errors */
4156 if (mb[0] == MBS_COMMAND_ERROR)
4158 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
4159 /* device not in PCB table */
4167 * qla2x00_loop_resync
4168 * Resync with fibre channel devices.
4171 * ha = adapter block pointer.
4177 qla2x00_loop_resync(scsi_qla_host_t *vha)
4179 int rval = QLA_SUCCESS;
4181 struct req_que *req;
4182 struct rsp_que *rsp;
4184 if (vha->hw->flags.cpu_affinity_enabled)
4185 req = vha->hw->req_q_map[0];
4190 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4191 if (vha->flags.online) {
4192 if (!(rval = qla2x00_fw_ready(vha))) {
4193 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4196 if (!IS_QLAFX00(vha->hw)) {
4198 * Issue a marker after FW becomes
4201 qla2x00_marker(vha, req, rsp, 0, 0,
4203 vha->marker_needed = 0;
4206 /* Remap devices on Loop. */
4207 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4209 if (IS_QLAFX00(vha->hw))
4210 qlafx00_configure_devices(vha);
4212 qla2x00_configure_loop(vha);
4215 } while (!atomic_read(&vha->loop_down_timer) &&
4216 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4217 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4222 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4223 return (QLA_FUNCTION_FAILED);
4226 ql_dbg(ql_dbg_disc, vha, 0x206c,
4227 "%s *** FAILED ***.\n", __func__);
4233 * qla2x00_perform_loop_resync
4234 * Description: This function will set the appropriate flags and call
4235 * qla2x00_loop_resync. If successful loop will be resynced
4236 * Arguments : scsi_qla_host_t pointer
4237 * returm : Success or Failure
4240 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
4244 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
4245 /*Configure the flags so that resync happens properly*/
4246 atomic_set(&ha->loop_down_timer, 0);
4247 if (!(ha->device_flags & DFLG_NO_CABLE)) {
4248 atomic_set(&ha->loop_state, LOOP_UP);
4249 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
4250 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
4251 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4253 rval = qla2x00_loop_resync(ha);
4255 atomic_set(&ha->loop_state, LOOP_DEAD);
4257 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
4264 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
4267 struct scsi_qla_host *vha;
4268 struct qla_hw_data *ha = base_vha->hw;
4269 unsigned long flags;
4271 spin_lock_irqsave(&ha->vport_slock, flags);
4272 /* Go with deferred removal of rport references. */
4273 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
4274 atomic_inc(&vha->vref_count);
4275 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4276 if (fcport->drport &&
4277 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
4278 spin_unlock_irqrestore(&ha->vport_slock, flags);
4279 qla2x00_rport_del(fcport);
4280 spin_lock_irqsave(&ha->vport_slock, flags);
4283 atomic_dec(&vha->vref_count);
4285 spin_unlock_irqrestore(&ha->vport_slock, flags);
4288 /* Assumes idc_lock always held on entry */
4290 qla83xx_reset_ownership(scsi_qla_host_t *vha)
4292 struct qla_hw_data *ha = vha->hw;
4293 uint32_t drv_presence, drv_presence_mask;
4294 uint32_t dev_part_info1, dev_part_info2, class_type;
4295 uint32_t class_type_mask = 0x3;
4296 uint16_t fcoe_other_function = 0xffff, i;
4298 if (IS_QLA8044(ha)) {
4299 drv_presence = qla8044_rd_direct(vha,
4300 QLA8044_CRB_DRV_ACTIVE_INDEX);
4301 dev_part_info1 = qla8044_rd_direct(vha,
4302 QLA8044_CRB_DEV_PART_INFO_INDEX);
4303 dev_part_info2 = qla8044_rd_direct(vha,
4304 QLA8044_CRB_DEV_PART_INFO2);
4306 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4307 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
4308 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
4310 for (i = 0; i < 8; i++) {
4311 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
4312 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4313 (i != ha->portnum)) {
4314 fcoe_other_function = i;
4318 if (fcoe_other_function == 0xffff) {
4319 for (i = 0; i < 8; i++) {
4320 class_type = ((dev_part_info2 >> (i * 4)) &
4322 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4323 ((i + 8) != ha->portnum)) {
4324 fcoe_other_function = i + 8;
4330 * Prepare drv-presence mask based on fcoe functions present.
4331 * However consider only valid physical fcoe function numbers (0-15).
4333 drv_presence_mask = ~((1 << (ha->portnum)) |
4334 ((fcoe_other_function == 0xffff) ?
4335 0 : (1 << (fcoe_other_function))));
4337 /* We are the reset owner iff:
4338 * - No other protocol drivers present.
4339 * - This is the lowest among fcoe functions. */
4340 if (!(drv_presence & drv_presence_mask) &&
4341 (ha->portnum < fcoe_other_function)) {
4342 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
4343 "This host is Reset owner.\n");
4344 ha->flags.nic_core_reset_owner = 1;
4349 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
4351 int rval = QLA_SUCCESS;
4352 struct qla_hw_data *ha = vha->hw;
4355 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4356 if (rval == QLA_SUCCESS) {
4357 drv_ack |= (1 << ha->portnum);
4358 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4365 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
4367 int rval = QLA_SUCCESS;
4368 struct qla_hw_data *ha = vha->hw;
4371 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4372 if (rval == QLA_SUCCESS) {
4373 drv_ack &= ~(1 << ha->portnum);
4374 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4381 qla83xx_dev_state_to_string(uint32_t dev_state)
4383 switch (dev_state) {
4384 case QLA8XXX_DEV_COLD:
4385 return "COLD/RE-INIT";
4386 case QLA8XXX_DEV_INITIALIZING:
4387 return "INITIALIZING";
4388 case QLA8XXX_DEV_READY:
4390 case QLA8XXX_DEV_NEED_RESET:
4391 return "NEED RESET";
4392 case QLA8XXX_DEV_NEED_QUIESCENT:
4393 return "NEED QUIESCENT";
4394 case QLA8XXX_DEV_FAILED:
4396 case QLA8XXX_DEV_QUIESCENT:
4403 /* Assumes idc-lock always held on entry */
4405 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
4407 struct qla_hw_data *ha = vha->hw;
4408 uint32_t idc_audit_reg = 0, duration_secs = 0;
4410 switch (audit_type) {
4411 case IDC_AUDIT_TIMESTAMP:
4412 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
4413 idc_audit_reg = (ha->portnum) |
4414 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
4415 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4418 case IDC_AUDIT_COMPLETION:
4419 duration_secs = ((jiffies_to_msecs(jiffies) -
4420 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
4421 idc_audit_reg = (ha->portnum) |
4422 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
4423 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4427 ql_log(ql_log_warn, vha, 0xb078,
4428 "Invalid audit type specified.\n");
4433 /* Assumes idc_lock always held on entry */
4435 qla83xx_initiating_reset(scsi_qla_host_t *vha)
4437 struct qla_hw_data *ha = vha->hw;
4438 uint32_t idc_control, dev_state;
4440 __qla83xx_get_idc_control(vha, &idc_control);
4441 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
4442 ql_log(ql_log_info, vha, 0xb080,
4443 "NIC Core reset has been disabled. idc-control=0x%x\n",
4445 return QLA_FUNCTION_FAILED;
4448 /* Set NEED-RESET iff in READY state and we are the reset-owner */
4449 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4450 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
4451 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
4452 QLA8XXX_DEV_NEED_RESET);
4453 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
4454 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
4456 const char *state = qla83xx_dev_state_to_string(dev_state);
4457 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
4459 /* SV: XXX: Is timeout required here? */
4460 /* Wait for IDC state change READY -> NEED_RESET */
4461 while (dev_state == QLA8XXX_DEV_READY) {
4462 qla83xx_idc_unlock(vha, 0);
4464 qla83xx_idc_lock(vha, 0);
4465 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4469 /* Send IDC ack by writing to drv-ack register */
4470 __qla83xx_set_drv_ack(vha);
4476 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
4478 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4482 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
4484 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4488 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
4490 uint32_t drv_presence = 0;
4491 struct qla_hw_data *ha = vha->hw;
4493 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4494 if (drv_presence & (1 << ha->portnum))
4497 return QLA_TEST_FAILED;
4501 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
4503 int rval = QLA_SUCCESS;
4504 struct qla_hw_data *ha = vha->hw;
4506 ql_dbg(ql_dbg_p3p, vha, 0xb058,
4507 "Entered %s().\n", __func__);
4509 if (vha->device_flags & DFLG_DEV_FAILED) {
4510 ql_log(ql_log_warn, vha, 0xb059,
4511 "Device in unrecoverable FAILED state.\n");
4512 return QLA_FUNCTION_FAILED;
4515 qla83xx_idc_lock(vha, 0);
4517 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
4518 ql_log(ql_log_warn, vha, 0xb05a,
4519 "Function=0x%x has been removed from IDC participation.\n",
4521 rval = QLA_FUNCTION_FAILED;
4525 qla83xx_reset_ownership(vha);
4527 rval = qla83xx_initiating_reset(vha);
4530 * Perform reset if we are the reset-owner,
4531 * else wait till IDC state changes to READY/FAILED.
4533 if (rval == QLA_SUCCESS) {
4534 rval = qla83xx_idc_state_handler(vha);
4536 if (rval == QLA_SUCCESS)
4537 ha->flags.nic_core_hung = 0;
4538 __qla83xx_clear_drv_ack(vha);
4542 qla83xx_idc_unlock(vha, 0);
4544 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
4550 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
4552 struct qla_hw_data *ha = vha->hw;
4553 int rval = QLA_FUNCTION_FAILED;
4555 if (!IS_MCTP_CAPABLE(ha)) {
4556 /* This message can be removed from the final version */
4557 ql_log(ql_log_info, vha, 0x506d,
4558 "This board is not MCTP capable\n");
4562 if (!ha->mctp_dump) {
4563 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
4564 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
4566 if (!ha->mctp_dump) {
4567 ql_log(ql_log_warn, vha, 0x506e,
4568 "Failed to allocate memory for mctp dump\n");
4573 #define MCTP_DUMP_STR_ADDR 0x00000000
4574 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
4575 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
4576 if (rval != QLA_SUCCESS) {
4577 ql_log(ql_log_warn, vha, 0x506f,
4578 "Failed to capture mctp dump\n");
4580 ql_log(ql_log_info, vha, 0x5070,
4581 "Mctp dump capture for host (%ld/%p).\n",
4582 vha->host_no, ha->mctp_dump);
4583 ha->mctp_dumped = 1;
4586 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
4587 ha->flags.nic_core_reset_hdlr_active = 1;
4588 rval = qla83xx_restart_nic_firmware(vha);
4590 /* NIC Core reset failed. */
4591 ql_log(ql_log_warn, vha, 0x5071,
4592 "Failed to restart nic firmware\n");
4594 ql_dbg(ql_dbg_p3p, vha, 0xb084,
4595 "Restarted NIC firmware successfully.\n");
4596 ha->flags.nic_core_reset_hdlr_active = 0;
4604 * qla2x00_quiesce_io
4605 * Description: This function will block the new I/Os
4606 * Its not aborting any I/Os as context
4607 * is not destroyed during quiescence
4608 * Arguments: scsi_qla_host_t
4612 qla2x00_quiesce_io(scsi_qla_host_t *vha)
4614 struct qla_hw_data *ha = vha->hw;
4615 struct scsi_qla_host *vp;
4617 ql_dbg(ql_dbg_dpc, vha, 0x401d,
4618 "Quiescing I/O - ha=%p.\n", ha);
4620 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
4621 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4622 atomic_set(&vha->loop_state, LOOP_DOWN);
4623 qla2x00_mark_all_devices_lost(vha, 0);
4624 list_for_each_entry(vp, &ha->vp_list, list)
4625 qla2x00_mark_all_devices_lost(vp, 0);
4627 if (!atomic_read(&vha->loop_down_timer))
4628 atomic_set(&vha->loop_down_timer,
4631 /* Wait for pending cmds to complete */
4632 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
4636 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
4638 struct qla_hw_data *ha = vha->hw;
4639 struct scsi_qla_host *vp;
4640 unsigned long flags;
4643 /* For ISP82XX, driver waits for completion of the commands.
4644 * online flag should be set.
4646 if (!(IS_P3P_TYPE(ha)))
4647 vha->flags.online = 0;
4648 ha->flags.chip_reset_done = 0;
4649 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4650 vha->qla_stats.total_isp_aborts++;
4652 ql_log(ql_log_info, vha, 0x00af,
4653 "Performing ISP error recovery - ha=%p.\n", ha);
4655 /* For ISP82XX, reset_chip is just disabling interrupts.
4656 * Driver waits for the completion of the commands.
4657 * the interrupts need to be enabled.
4659 if (!(IS_P3P_TYPE(ha)))
4660 ha->isp_ops->reset_chip(vha);
4662 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
4663 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4664 atomic_set(&vha->loop_state, LOOP_DOWN);
4665 qla2x00_mark_all_devices_lost(vha, 0);
4667 spin_lock_irqsave(&ha->vport_slock, flags);
4668 list_for_each_entry(vp, &ha->vp_list, list) {
4669 atomic_inc(&vp->vref_count);
4670 spin_unlock_irqrestore(&ha->vport_slock, flags);
4672 qla2x00_mark_all_devices_lost(vp, 0);
4674 spin_lock_irqsave(&ha->vport_slock, flags);
4675 atomic_dec(&vp->vref_count);
4677 spin_unlock_irqrestore(&ha->vport_slock, flags);
4679 if (!atomic_read(&vha->loop_down_timer))
4680 atomic_set(&vha->loop_down_timer,
4684 /* Clear all async request states across all VPs. */
4685 list_for_each_entry(fcport, &vha->vp_fcports, list)
4686 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4687 spin_lock_irqsave(&ha->vport_slock, flags);
4688 list_for_each_entry(vp, &ha->vp_list, list) {
4689 atomic_inc(&vp->vref_count);
4690 spin_unlock_irqrestore(&ha->vport_slock, flags);
4692 list_for_each_entry(fcport, &vp->vp_fcports, list)
4693 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4695 spin_lock_irqsave(&ha->vport_slock, flags);
4696 atomic_dec(&vp->vref_count);
4698 spin_unlock_irqrestore(&ha->vport_slock, flags);
4700 if (!ha->flags.eeh_busy) {
4701 /* Make sure for ISP 82XX IO DMA is complete */
4702 if (IS_P3P_TYPE(ha)) {
4703 qla82xx_chip_reset_cleanup(vha);
4704 ql_log(ql_log_info, vha, 0x00b4,
4705 "Done chip reset cleanup.\n");
4707 /* Done waiting for pending commands.
4708 * Reset the online flag.
4710 vha->flags.online = 0;
4713 /* Requeue all commands in outstanding command list. */
4714 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
4718 /* memory barrier */
4724 * Resets ISP and aborts all outstanding commands.
4727 * ha = adapter block pointer.
4733 qla2x00_abort_isp(scsi_qla_host_t *vha)
4737 struct qla_hw_data *ha = vha->hw;
4738 struct scsi_qla_host *vp;
4739 struct req_que *req = ha->req_q_map[0];
4740 unsigned long flags;
4742 if (vha->flags.online) {
4743 qla2x00_abort_isp_cleanup(vha);
4745 if (IS_QLA8031(ha)) {
4746 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
4747 "Clearing fcoe driver presence.\n");
4748 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
4749 ql_dbg(ql_dbg_p3p, vha, 0xb073,
4750 "Error while clearing DRV-Presence.\n");
4753 if (unlikely(pci_channel_offline(ha->pdev) &&
4754 ha->flags.pci_channel_io_perm_failure)) {
4755 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4760 ha->isp_ops->get_flash_version(vha, req->ring);
4762 ha->isp_ops->nvram_config(vha);
4764 if (!qla2x00_restart_isp(vha)) {
4765 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
4767 if (!atomic_read(&vha->loop_down_timer)) {
4769 * Issue marker command only when we are going
4770 * to start the I/O .
4772 vha->marker_needed = 1;
4775 vha->flags.online = 1;
4777 ha->isp_ops->enable_intrs(ha);
4779 ha->isp_abort_cnt = 0;
4780 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4782 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
4783 qla2x00_get_fw_version(vha);
4785 ha->flags.fce_enabled = 1;
4787 fce_calc_size(ha->fce_bufs));
4788 rval = qla2x00_enable_fce_trace(vha,
4789 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
4792 ql_log(ql_log_warn, vha, 0x8033,
4793 "Unable to reinitialize FCE "
4795 ha->flags.fce_enabled = 0;
4800 memset(ha->eft, 0, EFT_SIZE);
4801 rval = qla2x00_enable_eft_trace(vha,
4802 ha->eft_dma, EFT_NUM_BUFFERS);
4804 ql_log(ql_log_warn, vha, 0x8034,
4805 "Unable to reinitialize EFT "
4809 } else { /* failed the ISP abort */
4810 vha->flags.online = 1;
4811 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
4812 if (ha->isp_abort_cnt == 0) {
4813 ql_log(ql_log_fatal, vha, 0x8035,
4814 "ISP error recover failed - "
4815 "board disabled.\n");
4817 * The next call disables the board
4820 ha->isp_ops->reset_adapter(vha);
4821 vha->flags.online = 0;
4822 clear_bit(ISP_ABORT_RETRY,
4825 } else { /* schedule another ISP abort */
4826 ha->isp_abort_cnt--;
4827 ql_dbg(ql_dbg_taskm, vha, 0x8020,
4828 "ISP abort - retry remaining %d.\n",
4833 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
4834 ql_dbg(ql_dbg_taskm, vha, 0x8021,
4835 "ISP error recovery - retrying (%d) "
4836 "more times.\n", ha->isp_abort_cnt);
4837 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4845 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
4847 spin_lock_irqsave(&ha->vport_slock, flags);
4848 list_for_each_entry(vp, &ha->vp_list, list) {
4850 atomic_inc(&vp->vref_count);
4851 spin_unlock_irqrestore(&ha->vport_slock, flags);
4853 qla2x00_vp_abort_isp(vp);
4855 spin_lock_irqsave(&ha->vport_slock, flags);
4856 atomic_dec(&vp->vref_count);
4859 spin_unlock_irqrestore(&ha->vport_slock, flags);
4861 if (IS_QLA8031(ha)) {
4862 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
4863 "Setting back fcoe driver presence.\n");
4864 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
4865 ql_dbg(ql_dbg_p3p, vha, 0xb074,
4866 "Error while setting DRV-Presence.\n");
4869 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
4877 * qla2x00_restart_isp
4878 * restarts the ISP after a reset
4881 * ha = adapter block pointer.
4887 qla2x00_restart_isp(scsi_qla_host_t *vha)
4890 struct qla_hw_data *ha = vha->hw;
4891 struct req_que *req = ha->req_q_map[0];
4892 struct rsp_que *rsp = ha->rsp_q_map[0];
4893 unsigned long flags;
4895 /* If firmware needs to be loaded */
4896 if (qla2x00_isp_firmware(vha)) {
4897 vha->flags.online = 0;
4898 status = ha->isp_ops->chip_diag(vha);
4900 status = qla2x00_setup_chip(vha);
4903 if (!status && !(status = qla2x00_init_rings(vha))) {
4904 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
4905 ha->flags.chip_reset_done = 1;
4907 /* Initialize the queues in use */
4908 qla25xx_init_queues(ha);
4910 status = qla2x00_fw_ready(vha);
4912 /* Issue a marker after FW becomes ready. */
4913 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
4915 vha->flags.online = 1;
4918 * Process any ATIO queue entries that came in
4919 * while we weren't online.
4921 spin_lock_irqsave(&ha->hardware_lock, flags);
4922 if (qla_tgt_mode_enabled(vha))
4923 qlt_24xx_process_atio_queue(vha);
4924 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4926 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4929 /* if no cable then assume it's good */
4930 if ((vha->device_flags & DFLG_NO_CABLE))
4937 qla25xx_init_queues(struct qla_hw_data *ha)
4939 struct rsp_que *rsp = NULL;
4940 struct req_que *req = NULL;
4941 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4945 for (i = 1; i < ha->max_rsp_queues; i++) {
4946 rsp = ha->rsp_q_map[i];
4948 rsp->options &= ~BIT_0;
4949 ret = qla25xx_init_rsp_que(base_vha, rsp);
4950 if (ret != QLA_SUCCESS)
4951 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
4952 "%s Rsp que: %d init failed.\n",
4955 ql_dbg(ql_dbg_init, base_vha, 0x0100,
4956 "%s Rsp que: %d inited.\n",
4960 for (i = 1; i < ha->max_req_queues; i++) {
4961 req = ha->req_q_map[i];
4963 /* Clear outstanding commands array. */
4964 req->options &= ~BIT_0;
4965 ret = qla25xx_init_req_que(base_vha, req);
4966 if (ret != QLA_SUCCESS)
4967 ql_dbg(ql_dbg_init, base_vha, 0x0101,
4968 "%s Req que: %d init failed.\n",
4971 ql_dbg(ql_dbg_init, base_vha, 0x0102,
4972 "%s Req que: %d inited.\n",
4980 * qla2x00_reset_adapter
4984 * ha = adapter block pointer.
4987 qla2x00_reset_adapter(scsi_qla_host_t *vha)
4989 unsigned long flags = 0;
4990 struct qla_hw_data *ha = vha->hw;
4991 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4993 vha->flags.online = 0;
4994 ha->isp_ops->disable_intrs(ha);
4996 spin_lock_irqsave(&ha->hardware_lock, flags);
4997 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
4998 RD_REG_WORD(®->hccr); /* PCI Posting. */
4999 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
5000 RD_REG_WORD(®->hccr); /* PCI Posting. */
5001 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5005 qla24xx_reset_adapter(scsi_qla_host_t *vha)
5007 unsigned long flags = 0;
5008 struct qla_hw_data *ha = vha->hw;
5009 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
5011 if (IS_P3P_TYPE(ha))
5014 vha->flags.online = 0;
5015 ha->isp_ops->disable_intrs(ha);
5017 spin_lock_irqsave(&ha->hardware_lock, flags);
5018 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
5019 RD_REG_DWORD(®->hccr);
5020 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
5021 RD_REG_DWORD(®->hccr);
5022 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5024 if (IS_NOPOLLING_TYPE(ha))
5025 ha->isp_ops->enable_intrs(ha);
5028 /* On sparc systems, obtain port and node WWN from firmware
5031 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
5032 struct nvram_24xx *nv)
5035 struct qla_hw_data *ha = vha->hw;
5036 struct pci_dev *pdev = ha->pdev;
5037 struct device_node *dp = pci_device_to_OF_node(pdev);
5041 val = of_get_property(dp, "port-wwn", &len);
5042 if (val && len >= WWN_SIZE)
5043 memcpy(nv->port_name, val, WWN_SIZE);
5045 val = of_get_property(dp, "node-wwn", &len);
5046 if (val && len >= WWN_SIZE)
5047 memcpy(nv->node_name, val, WWN_SIZE);
5052 qla24xx_nvram_config(scsi_qla_host_t *vha)
5055 struct init_cb_24xx *icb;
5056 struct nvram_24xx *nv;
5058 uint8_t *dptr1, *dptr2;
5061 struct qla_hw_data *ha = vha->hw;
5064 icb = (struct init_cb_24xx *)ha->init_cb;
5067 /* Determine NVRAM starting address. */
5068 if (ha->port_no == 0) {
5069 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
5070 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
5072 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
5073 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
5076 ha->nvram_size = sizeof(struct nvram_24xx);
5077 ha->vpd_size = FA_NVRAM_VPD_SIZE;
5079 /* Get VPD data into cache */
5080 ha->vpd = ha->nvram + VPD_OFFSET;
5081 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
5082 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
5084 /* Get NVRAM data into cache and calculate checksum. */
5085 dptr = (uint32_t *)nv;
5086 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
5088 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5089 chksum += le32_to_cpu(*dptr++);
5091 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
5092 "Contents of NVRAM\n");
5093 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
5094 (uint8_t *)nv, ha->nvram_size);
5096 /* Bad NVRAM data, set defaults parameters. */
5097 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5098 || nv->id[3] != ' ' ||
5099 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
5100 /* Reset NVRAM data. */
5101 ql_log(ql_log_warn, vha, 0x006b,
5102 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
5103 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
5104 ql_log(ql_log_warn, vha, 0x006c,
5105 "Falling back to functioning (yet invalid -- WWPN) "
5109 * Set default initialization control block.
5111 memset(nv, 0, ha->nvram_size);
5112 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5113 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5114 nv->frame_payload_size = 2048;
5115 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5116 nv->exchange_count = __constant_cpu_to_le16(0);
5117 nv->hard_address = __constant_cpu_to_le16(124);
5118 nv->port_name[0] = 0x21;
5119 nv->port_name[1] = 0x00 + ha->port_no + 1;
5120 nv->port_name[2] = 0x00;
5121 nv->port_name[3] = 0xe0;
5122 nv->port_name[4] = 0x8b;
5123 nv->port_name[5] = 0x1c;
5124 nv->port_name[6] = 0x55;
5125 nv->port_name[7] = 0x86;
5126 nv->node_name[0] = 0x20;
5127 nv->node_name[1] = 0x00;
5128 nv->node_name[2] = 0x00;
5129 nv->node_name[3] = 0xe0;
5130 nv->node_name[4] = 0x8b;
5131 nv->node_name[5] = 0x1c;
5132 nv->node_name[6] = 0x55;
5133 nv->node_name[7] = 0x86;
5134 qla24xx_nvram_wwn_from_ofw(vha, nv);
5135 nv->login_retry_count = __constant_cpu_to_le16(8);
5136 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5137 nv->login_timeout = __constant_cpu_to_le16(0);
5138 nv->firmware_options_1 =
5139 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5140 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5141 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5142 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5143 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5144 nv->efi_parameters = __constant_cpu_to_le32(0);
5145 nv->reset_delay = 5;
5146 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5147 nv->port_down_retry_count = __constant_cpu_to_le16(30);
5148 nv->link_down_timeout = __constant_cpu_to_le16(30);
5153 if (!qla_ini_mode_enabled(vha)) {
5154 /* Don't enable full login after initial LIP */
5155 nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13);
5156 /* Don't enable LIP full login for initiator */
5157 nv->host_p &= __constant_cpu_to_le32(~BIT_10);
5160 qlt_24xx_config_nvram_stage1(vha, nv);
5162 /* Reset Initialization control block */
5163 memset(icb, 0, ha->init_cb_size);
5165 /* Copy 1st segment. */
5166 dptr1 = (uint8_t *)icb;
5167 dptr2 = (uint8_t *)&nv->version;
5168 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5170 *dptr1++ = *dptr2++;
5172 icb->login_retry_count = nv->login_retry_count;
5173 icb->link_down_on_nos = nv->link_down_on_nos;
5175 /* Copy 2nd segment. */
5176 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5177 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5178 cnt = (uint8_t *)&icb->reserved_3 -
5179 (uint8_t *)&icb->interrupt_delay_timer;
5181 *dptr1++ = *dptr2++;
5184 * Setup driver NVRAM options.
5186 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
5189 qlt_24xx_config_nvram_stage2(vha, icb);
5191 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5192 /* Use alternate WWN? */
5193 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5194 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5197 /* Prepare nodename */
5198 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5200 * Firmware will apply the following mask if the nodename was
5203 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5204 icb->node_name[0] &= 0xF0;
5207 /* Set host adapter parameters. */
5208 ha->flags.disable_risc_code_load = 0;
5209 ha->flags.enable_lip_reset = 0;
5210 ha->flags.enable_lip_full_login =
5211 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5212 ha->flags.enable_target_reset =
5213 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5214 ha->flags.enable_led_scheme = 0;
5215 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5217 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5218 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5220 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
5221 sizeof(ha->fw_seriallink_options24));
5223 /* save HBA serial number */
5224 ha->serial0 = icb->port_name[5];
5225 ha->serial1 = icb->port_name[6];
5226 ha->serial2 = icb->port_name[7];
5227 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5228 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5230 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5232 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5234 /* Set minimum login_timeout to 4 seconds. */
5235 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5236 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5237 if (le16_to_cpu(nv->login_timeout) < 4)
5238 nv->login_timeout = __constant_cpu_to_le16(4);
5239 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5240 icb->login_timeout = nv->login_timeout;
5242 /* Set minimum RATOV to 100 tenths of a second. */
5245 ha->loop_reset_delay = nv->reset_delay;
5247 /* Link Down Timeout = 0:
5249 * When Port Down timer expires we will start returning
5250 * I/O's to OS with "DID_NO_CONNECT".
5252 * Link Down Timeout != 0:
5254 * The driver waits for the link to come up after link down
5255 * before returning I/Os to OS with "DID_NO_CONNECT".
5257 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5258 ha->loop_down_abort_time =
5259 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5261 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5262 ha->loop_down_abort_time =
5263 (LOOP_DOWN_TIME - ha->link_down_timeout);
5266 /* Need enough time to try and get the port back. */
5267 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5268 if (qlport_down_retry)
5269 ha->port_down_retry_count = qlport_down_retry;
5271 /* Set login_retry_count */
5272 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5273 if (ha->port_down_retry_count ==
5274 le16_to_cpu(nv->port_down_retry_count) &&
5275 ha->port_down_retry_count > 3)
5276 ha->login_retry_count = ha->port_down_retry_count;
5277 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5278 ha->login_retry_count = ha->port_down_retry_count;
5279 if (ql2xloginretrycount)
5280 ha->login_retry_count = ql2xloginretrycount;
5283 if (!vha->flags.init_done) {
5284 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5285 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5286 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5287 le16_to_cpu(icb->interrupt_delay_timer): 2;
5289 icb->firmware_options_2 &= __constant_cpu_to_le32(
5290 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5291 vha->flags.process_response_queue = 0;
5292 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5293 ha->zio_mode = QLA_ZIO_MODE_6;
5295 ql_log(ql_log_info, vha, 0x006f,
5296 "ZIO mode %d enabled; timer delay (%d us).\n",
5297 ha->zio_mode, ha->zio_timer * 100);
5299 icb->firmware_options_2 |= cpu_to_le32(
5300 (uint32_t)ha->zio_mode);
5301 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5302 vha->flags.process_response_queue = 1;
5306 ql_log(ql_log_warn, vha, 0x0070,
5307 "NVRAM configuration failed.\n");
5313 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
5316 int rval = QLA_SUCCESS;
5317 int segments, fragment;
5318 uint32_t *dcode, dlen;
5322 struct qla_hw_data *ha = vha->hw;
5323 struct req_que *req = ha->req_q_map[0];
5325 ql_dbg(ql_dbg_init, vha, 0x008b,
5326 "FW: Loading firmware from flash (%x).\n", faddr);
5330 segments = FA_RISC_CODE_SEGMENTS;
5331 dcode = (uint32_t *)req->ring;
5334 /* Validate firmware image by checking version. */
5335 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
5336 for (i = 0; i < 4; i++)
5337 dcode[i] = be32_to_cpu(dcode[i]);
5338 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5339 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5340 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5342 ql_log(ql_log_fatal, vha, 0x008c,
5343 "Unable to verify the integrity of flash firmware "
5345 ql_log(ql_log_fatal, vha, 0x008d,
5346 "Firmware data: %08x %08x %08x %08x.\n",
5347 dcode[0], dcode[1], dcode[2], dcode[3]);
5349 return QLA_FUNCTION_FAILED;
5352 while (segments && rval == QLA_SUCCESS) {
5353 /* Read segment's load information. */
5354 qla24xx_read_flash_data(vha, dcode, faddr, 4);
5356 risc_addr = be32_to_cpu(dcode[2]);
5357 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5358 risc_size = be32_to_cpu(dcode[3]);
5361 while (risc_size > 0 && rval == QLA_SUCCESS) {
5362 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5363 if (dlen > risc_size)
5366 ql_dbg(ql_dbg_init, vha, 0x008e,
5367 "Loading risc segment@ risc addr %x "
5368 "number of dwords 0x%x offset 0x%x.\n",
5369 risc_addr, dlen, faddr);
5371 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
5372 for (i = 0; i < dlen; i++)
5373 dcode[i] = swab32(dcode[i]);
5375 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
5378 ql_log(ql_log_fatal, vha, 0x008f,
5379 "Failed to load segment %d of firmware.\n",
5381 return QLA_FUNCTION_FAILED;
5394 if (!IS_QLA27XX(ha))
5397 if (ha->fw_dump_template)
5398 vfree(ha->fw_dump_template);
5399 ha->fw_dump_template = NULL;
5400 ha->fw_dump_template_len = 0;
5402 ql_dbg(ql_dbg_init, vha, 0x0161,
5403 "Loading fwdump template from %x\n", faddr);
5404 qla24xx_read_flash_data(vha, dcode, faddr, 7);
5405 risc_size = be32_to_cpu(dcode[2]);
5406 ql_dbg(ql_dbg_init, vha, 0x0162,
5407 "-> array size %x dwords\n", risc_size);
5408 if (risc_size == 0 || risc_size == ~0)
5409 goto default_template;
5411 dlen = (risc_size - 8) * sizeof(*dcode);
5412 ql_dbg(ql_dbg_init, vha, 0x0163,
5413 "-> template allocating %x bytes...\n", dlen);
5414 ha->fw_dump_template = vmalloc(dlen);
5415 if (!ha->fw_dump_template) {
5416 ql_log(ql_log_warn, vha, 0x0164,
5417 "Failed fwdump template allocate %x bytes.\n", risc_size);
5418 goto default_template;
5423 dcode = ha->fw_dump_template;
5424 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
5425 for (i = 0; i < risc_size; i++)
5426 dcode[i] = le32_to_cpu(dcode[i]);
5428 if (!qla27xx_fwdt_template_valid(dcode)) {
5429 ql_log(ql_log_warn, vha, 0x0165,
5430 "Failed fwdump template validate\n");
5431 goto default_template;
5434 dlen = qla27xx_fwdt_template_size(dcode);
5435 ql_dbg(ql_dbg_init, vha, 0x0166,
5436 "-> template size %x bytes\n", dlen);
5437 if (dlen > risc_size * sizeof(*dcode)) {
5438 ql_log(ql_log_warn, vha, 0x0167,
5439 "Failed fwdump template exceeds array by %x bytes\n",
5440 (uint32_t)(dlen - risc_size * sizeof(*dcode)));
5441 goto default_template;
5443 ha->fw_dump_template_len = dlen;
5447 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
5448 if (ha->fw_dump_template)
5449 vfree(ha->fw_dump_template);
5450 ha->fw_dump_template = NULL;
5451 ha->fw_dump_template_len = 0;
5453 dlen = qla27xx_fwdt_template_default_size();
5454 ql_dbg(ql_dbg_init, vha, 0x0169,
5455 "-> template allocating %x bytes...\n", dlen);
5456 ha->fw_dump_template = vmalloc(dlen);
5457 if (!ha->fw_dump_template) {
5458 ql_log(ql_log_warn, vha, 0x016a,
5459 "Failed fwdump template allocate %x bytes.\n", risc_size);
5460 goto failed_template;
5463 dcode = ha->fw_dump_template;
5464 risc_size = dlen / sizeof(*dcode);
5465 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
5466 for (i = 0; i < risc_size; i++)
5467 dcode[i] = be32_to_cpu(dcode[i]);
5469 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
5470 ql_log(ql_log_warn, vha, 0x016b,
5471 "Failed fwdump template validate\n");
5472 goto failed_template;
5475 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
5476 ql_dbg(ql_dbg_init, vha, 0x016c,
5477 "-> template size %x bytes\n", dlen);
5478 ha->fw_dump_template_len = dlen;
5482 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
5483 if (ha->fw_dump_template)
5484 vfree(ha->fw_dump_template);
5485 ha->fw_dump_template = NULL;
5486 ha->fw_dump_template_len = 0;
5490 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
5493 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5497 uint16_t *wcode, *fwcode;
5498 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
5499 struct fw_blob *blob;
5500 struct qla_hw_data *ha = vha->hw;
5501 struct req_que *req = ha->req_q_map[0];
5503 /* Load firmware blob. */
5504 blob = qla2x00_request_firmware(vha);
5506 ql_log(ql_log_info, vha, 0x0083,
5507 "Firmware image unavailable.\n");
5508 ql_log(ql_log_info, vha, 0x0084,
5509 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
5510 return QLA_FUNCTION_FAILED;
5515 wcode = (uint16_t *)req->ring;
5517 fwcode = (uint16_t *)blob->fw->data;
5520 /* Validate firmware image by checking version. */
5521 if (blob->fw->size < 8 * sizeof(uint16_t)) {
5522 ql_log(ql_log_fatal, vha, 0x0085,
5523 "Unable to verify integrity of firmware image (%Zd).\n",
5525 goto fail_fw_integrity;
5527 for (i = 0; i < 4; i++)
5528 wcode[i] = be16_to_cpu(fwcode[i + 4]);
5529 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
5530 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
5531 wcode[2] == 0 && wcode[3] == 0)) {
5532 ql_log(ql_log_fatal, vha, 0x0086,
5533 "Unable to verify integrity of firmware image.\n");
5534 ql_log(ql_log_fatal, vha, 0x0087,
5535 "Firmware data: %04x %04x %04x %04x.\n",
5536 wcode[0], wcode[1], wcode[2], wcode[3]);
5537 goto fail_fw_integrity;
5541 while (*seg && rval == QLA_SUCCESS) {
5543 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
5544 risc_size = be16_to_cpu(fwcode[3]);
5546 /* Validate firmware image size. */
5547 fwclen += risc_size * sizeof(uint16_t);
5548 if (blob->fw->size < fwclen) {
5549 ql_log(ql_log_fatal, vha, 0x0088,
5550 "Unable to verify integrity of firmware image "
5551 "(%Zd).\n", blob->fw->size);
5552 goto fail_fw_integrity;
5556 while (risc_size > 0 && rval == QLA_SUCCESS) {
5557 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
5558 if (wlen > risc_size)
5560 ql_dbg(ql_dbg_init, vha, 0x0089,
5561 "Loading risc segment@ risc addr %x number of "
5562 "words 0x%x.\n", risc_addr, wlen);
5564 for (i = 0; i < wlen; i++)
5565 wcode[i] = swab16(fwcode[i]);
5567 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
5570 ql_log(ql_log_fatal, vha, 0x008a,
5571 "Failed to load segment %d of firmware.\n",
5588 return QLA_FUNCTION_FAILED;
5592 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5595 int segments, fragment;
5596 uint32_t *dcode, dlen;
5600 struct fw_blob *blob;
5601 const uint32_t *fwcode;
5603 struct qla_hw_data *ha = vha->hw;
5604 struct req_que *req = ha->req_q_map[0];
5606 /* Load firmware blob. */
5607 blob = qla2x00_request_firmware(vha);
5609 ql_log(ql_log_warn, vha, 0x0090,
5610 "Firmware image unavailable.\n");
5611 ql_log(ql_log_warn, vha, 0x0091,
5612 "Firmware images can be retrieved from: "
5615 return QLA_FUNCTION_FAILED;
5618 ql_dbg(ql_dbg_init, vha, 0x0092,
5619 "FW: Loading via request-firmware.\n");
5623 segments = FA_RISC_CODE_SEGMENTS;
5624 dcode = (uint32_t *)req->ring;
5626 fwcode = (uint32_t *)blob->fw->data;
5629 /* Validate firmware image by checking version. */
5630 if (blob->fw->size < 8 * sizeof(uint32_t)) {
5631 ql_log(ql_log_fatal, vha, 0x0093,
5632 "Unable to verify integrity of firmware image (%Zd).\n",
5634 return QLA_FUNCTION_FAILED;
5636 for (i = 0; i < 4; i++)
5637 dcode[i] = be32_to_cpu(fwcode[i + 4]);
5638 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5639 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5640 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5642 ql_log(ql_log_fatal, vha, 0x0094,
5643 "Unable to verify integrity of firmware image (%Zd).\n",
5645 ql_log(ql_log_fatal, vha, 0x0095,
5646 "Firmware data: %08x %08x %08x %08x.\n",
5647 dcode[0], dcode[1], dcode[2], dcode[3]);
5648 return QLA_FUNCTION_FAILED;
5651 while (segments && rval == QLA_SUCCESS) {
5652 risc_addr = be32_to_cpu(fwcode[2]);
5653 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5654 risc_size = be32_to_cpu(fwcode[3]);
5656 /* Validate firmware image size. */
5657 fwclen += risc_size * sizeof(uint32_t);
5658 if (blob->fw->size < fwclen) {
5659 ql_log(ql_log_fatal, vha, 0x0096,
5660 "Unable to verify integrity of firmware image "
5661 "(%Zd).\n", blob->fw->size);
5662 return QLA_FUNCTION_FAILED;
5666 while (risc_size > 0 && rval == QLA_SUCCESS) {
5667 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5668 if (dlen > risc_size)
5671 ql_dbg(ql_dbg_init, vha, 0x0097,
5672 "Loading risc segment@ risc addr %x "
5673 "number of dwords 0x%x.\n", risc_addr, dlen);
5675 for (i = 0; i < dlen; i++)
5676 dcode[i] = swab32(fwcode[i]);
5678 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
5681 ql_log(ql_log_fatal, vha, 0x0098,
5682 "Failed to load segment %d of firmware.\n",
5684 return QLA_FUNCTION_FAILED;
5697 if (!IS_QLA27XX(ha))
5700 if (ha->fw_dump_template)
5701 vfree(ha->fw_dump_template);
5702 ha->fw_dump_template = NULL;
5703 ha->fw_dump_template_len = 0;
5705 ql_dbg(ql_dbg_init, vha, 0x171,
5706 "Loading fwdump template from %x\n",
5707 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
5708 risc_size = be32_to_cpu(fwcode[2]);
5709 ql_dbg(ql_dbg_init, vha, 0x172,
5710 "-> array size %x dwords\n", risc_size);
5711 if (risc_size == 0 || risc_size == ~0)
5712 goto default_template;
5714 dlen = (risc_size - 8) * sizeof(*fwcode);
5715 ql_dbg(ql_dbg_init, vha, 0x0173,
5716 "-> template allocating %x bytes...\n", dlen);
5717 ha->fw_dump_template = vmalloc(dlen);
5718 if (!ha->fw_dump_template) {
5719 ql_log(ql_log_warn, vha, 0x0174,
5720 "Failed fwdump template allocate %x bytes.\n", risc_size);
5721 goto default_template;
5726 dcode = ha->fw_dump_template;
5727 for (i = 0; i < risc_size; i++)
5728 dcode[i] = le32_to_cpu(fwcode[i]);
5730 if (!qla27xx_fwdt_template_valid(dcode)) {
5731 ql_log(ql_log_warn, vha, 0x0175,
5732 "Failed fwdump template validate\n");
5733 goto default_template;
5736 dlen = qla27xx_fwdt_template_size(dcode);
5737 ql_dbg(ql_dbg_init, vha, 0x0176,
5738 "-> template size %x bytes\n", dlen);
5739 if (dlen > risc_size * sizeof(*fwcode)) {
5740 ql_log(ql_log_warn, vha, 0x0177,
5741 "Failed fwdump template exceeds array by %x bytes\n",
5742 (uint32_t)(dlen - risc_size * sizeof(*fwcode)));
5743 goto default_template;
5745 ha->fw_dump_template_len = dlen;
5749 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
5750 if (ha->fw_dump_template)
5751 vfree(ha->fw_dump_template);
5752 ha->fw_dump_template = NULL;
5753 ha->fw_dump_template_len = 0;
5755 dlen = qla27xx_fwdt_template_default_size();
5756 ql_dbg(ql_dbg_init, vha, 0x0179,
5757 "-> template allocating %x bytes...\n", dlen);
5758 ha->fw_dump_template = vmalloc(dlen);
5759 if (!ha->fw_dump_template) {
5760 ql_log(ql_log_warn, vha, 0x017a,
5761 "Failed fwdump template allocate %x bytes.\n", risc_size);
5762 goto failed_template;
5765 dcode = ha->fw_dump_template;
5766 risc_size = dlen / sizeof(*fwcode);
5767 fwcode = qla27xx_fwdt_template_default();
5768 for (i = 0; i < risc_size; i++)
5769 dcode[i] = be32_to_cpu(fwcode[i]);
5771 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
5772 ql_log(ql_log_warn, vha, 0x017b,
5773 "Failed fwdump template validate\n");
5774 goto failed_template;
5777 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
5778 ql_dbg(ql_dbg_init, vha, 0x017c,
5779 "-> template size %x bytes\n", dlen);
5780 ha->fw_dump_template_len = dlen;
5784 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
5785 if (ha->fw_dump_template)
5786 vfree(ha->fw_dump_template);
5787 ha->fw_dump_template = NULL;
5788 ha->fw_dump_template_len = 0;
5793 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5797 if (ql2xfwloadbin == 1)
5798 return qla81xx_load_risc(vha, srisc_addr);
5802 * 1) Firmware via request-firmware interface (.bin file).
5803 * 2) Firmware residing in flash.
5805 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5806 if (rval == QLA_SUCCESS)
5809 return qla24xx_load_risc_flash(vha, srisc_addr,
5810 vha->hw->flt_region_fw);
5814 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5817 struct qla_hw_data *ha = vha->hw;
5819 if (ql2xfwloadbin == 2)
5824 * 1) Firmware residing in flash.
5825 * 2) Firmware via request-firmware interface (.bin file).
5826 * 3) Golden-Firmware residing in flash -- limited operation.
5828 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
5829 if (rval == QLA_SUCCESS)
5833 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5834 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
5837 ql_log(ql_log_info, vha, 0x0099,
5838 "Attempting to fallback to golden firmware.\n");
5839 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
5840 if (rval != QLA_SUCCESS)
5843 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
5844 ha->flags.running_gold_fw = 1;
5849 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
5852 struct qla_hw_data *ha = vha->hw;
5854 if (ha->flags.pci_channel_io_perm_failure)
5856 if (!IS_FWI2_CAPABLE(ha))
5858 if (!ha->fw_major_version)
5861 ret = qla2x00_stop_firmware(vha);
5862 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
5863 ret != QLA_INVALID_COMMAND && retries ; retries--) {
5864 ha->isp_ops->reset_chip(vha);
5865 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
5867 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
5869 ql_log(ql_log_info, vha, 0x8015,
5870 "Attempting retry of stop-firmware command.\n");
5871 ret = qla2x00_stop_firmware(vha);
5876 qla24xx_configure_vhba(scsi_qla_host_t *vha)
5878 int rval = QLA_SUCCESS;
5880 uint16_t mb[MAILBOX_REGISTER_COUNT];
5881 struct qla_hw_data *ha = vha->hw;
5882 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5883 struct req_que *req;
5884 struct rsp_que *rsp;
5889 rval = qla2x00_fw_ready(base_vha);
5890 if (ha->flags.cpu_affinity_enabled)
5891 req = ha->req_q_map[0];
5896 if (rval == QLA_SUCCESS) {
5897 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5898 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5901 vha->flags.management_server_logged_in = 0;
5903 /* Login to SNS first */
5904 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
5906 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5907 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
5908 ql_dbg(ql_dbg_init, vha, 0x0120,
5909 "Failed SNS login: loop_id=%x, rval2=%d\n",
5912 ql_dbg(ql_dbg_init, vha, 0x0103,
5913 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
5914 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
5915 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
5916 return (QLA_FUNCTION_FAILED);
5919 atomic_set(&vha->loop_down_timer, 0);
5920 atomic_set(&vha->loop_state, LOOP_UP);
5921 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5922 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5923 rval = qla2x00_loop_resync(base_vha);
5928 /* 84XX Support **************************************************************/
5930 static LIST_HEAD(qla_cs84xx_list);
5931 static DEFINE_MUTEX(qla_cs84xx_mutex);
5933 static struct qla_chip_state_84xx *
5934 qla84xx_get_chip(struct scsi_qla_host *vha)
5936 struct qla_chip_state_84xx *cs84xx;
5937 struct qla_hw_data *ha = vha->hw;
5939 mutex_lock(&qla_cs84xx_mutex);
5941 /* Find any shared 84xx chip. */
5942 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
5943 if (cs84xx->bus == ha->pdev->bus) {
5944 kref_get(&cs84xx->kref);
5949 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
5953 kref_init(&cs84xx->kref);
5954 spin_lock_init(&cs84xx->access_lock);
5955 mutex_init(&cs84xx->fw_update_mutex);
5956 cs84xx->bus = ha->pdev->bus;
5958 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
5960 mutex_unlock(&qla_cs84xx_mutex);
5965 __qla84xx_chip_release(struct kref *kref)
5967 struct qla_chip_state_84xx *cs84xx =
5968 container_of(kref, struct qla_chip_state_84xx, kref);
5970 mutex_lock(&qla_cs84xx_mutex);
5971 list_del(&cs84xx->list);
5972 mutex_unlock(&qla_cs84xx_mutex);
5977 qla84xx_put_chip(struct scsi_qla_host *vha)
5979 struct qla_hw_data *ha = vha->hw;
5981 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
5985 qla84xx_init_chip(scsi_qla_host_t *vha)
5989 struct qla_hw_data *ha = vha->hw;
5991 mutex_lock(&ha->cs84xx->fw_update_mutex);
5993 rval = qla84xx_verify_chip(vha, status);
5995 mutex_unlock(&ha->cs84xx->fw_update_mutex);
5997 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
6001 /* 81XX Support **************************************************************/
6004 qla81xx_nvram_config(scsi_qla_host_t *vha)
6007 struct init_cb_81xx *icb;
6008 struct nvram_81xx *nv;
6010 uint8_t *dptr1, *dptr2;
6013 struct qla_hw_data *ha = vha->hw;
6016 icb = (struct init_cb_81xx *)ha->init_cb;
6019 /* Determine NVRAM starting address. */
6020 ha->nvram_size = sizeof(struct nvram_81xx);
6021 ha->vpd_size = FA_NVRAM_VPD_SIZE;
6022 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
6023 ha->vpd_size = FA_VPD_SIZE_82XX;
6025 /* Get VPD data into cache */
6026 ha->vpd = ha->nvram + VPD_OFFSET;
6027 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
6030 /* Get NVRAM data into cache and calculate checksum. */
6031 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
6033 dptr = (uint32_t *)nv;
6034 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
6035 chksum += le32_to_cpu(*dptr++);
6037 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
6038 "Contents of NVRAM:\n");
6039 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
6040 (uint8_t *)nv, ha->nvram_size);
6042 /* Bad NVRAM data, set defaults parameters. */
6043 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
6044 || nv->id[3] != ' ' ||
6045 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
6046 /* Reset NVRAM data. */
6047 ql_log(ql_log_info, vha, 0x0073,
6048 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
6049 "version=0x%x.\n", chksum, nv->id[0],
6050 le16_to_cpu(nv->nvram_version));
6051 ql_log(ql_log_info, vha, 0x0074,
6052 "Falling back to functioning (yet invalid -- WWPN) "
6056 * Set default initialization control block.
6058 memset(nv, 0, ha->nvram_size);
6059 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
6060 nv->version = __constant_cpu_to_le16(ICB_VERSION);
6061 nv->frame_payload_size = 2048;
6062 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
6063 nv->exchange_count = __constant_cpu_to_le16(0);
6064 nv->port_name[0] = 0x21;
6065 nv->port_name[1] = 0x00 + ha->port_no + 1;
6066 nv->port_name[2] = 0x00;
6067 nv->port_name[3] = 0xe0;
6068 nv->port_name[4] = 0x8b;
6069 nv->port_name[5] = 0x1c;
6070 nv->port_name[6] = 0x55;
6071 nv->port_name[7] = 0x86;
6072 nv->node_name[0] = 0x20;
6073 nv->node_name[1] = 0x00;
6074 nv->node_name[2] = 0x00;
6075 nv->node_name[3] = 0xe0;
6076 nv->node_name[4] = 0x8b;
6077 nv->node_name[5] = 0x1c;
6078 nv->node_name[6] = 0x55;
6079 nv->node_name[7] = 0x86;
6080 nv->login_retry_count = __constant_cpu_to_le16(8);
6081 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
6082 nv->login_timeout = __constant_cpu_to_le16(0);
6083 nv->firmware_options_1 =
6084 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
6085 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
6086 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
6087 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
6088 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
6089 nv->efi_parameters = __constant_cpu_to_le32(0);
6090 nv->reset_delay = 5;
6091 nv->max_luns_per_target = __constant_cpu_to_le16(128);
6092 nv->port_down_retry_count = __constant_cpu_to_le16(30);
6093 nv->link_down_timeout = __constant_cpu_to_le16(180);
6094 nv->enode_mac[0] = 0x00;
6095 nv->enode_mac[1] = 0xC0;
6096 nv->enode_mac[2] = 0xDD;
6097 nv->enode_mac[3] = 0x04;
6098 nv->enode_mac[4] = 0x05;
6099 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
6104 if (IS_T10_PI_CAPABLE(ha))
6105 nv->frame_payload_size &= ~7;
6107 qlt_81xx_config_nvram_stage1(vha, nv);
6109 /* Reset Initialization control block */
6110 memset(icb, 0, ha->init_cb_size);
6112 /* Copy 1st segment. */
6113 dptr1 = (uint8_t *)icb;
6114 dptr2 = (uint8_t *)&nv->version;
6115 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
6117 *dptr1++ = *dptr2++;
6119 icb->login_retry_count = nv->login_retry_count;
6121 /* Copy 2nd segment. */
6122 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
6123 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
6124 cnt = (uint8_t *)&icb->reserved_5 -
6125 (uint8_t *)&icb->interrupt_delay_timer;
6127 *dptr1++ = *dptr2++;
6129 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
6130 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
6131 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
6132 icb->enode_mac[0] = 0x00;
6133 icb->enode_mac[1] = 0xC0;
6134 icb->enode_mac[2] = 0xDD;
6135 icb->enode_mac[3] = 0x04;
6136 icb->enode_mac[4] = 0x05;
6137 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
6140 /* Use extended-initialization control block. */
6141 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
6144 * Setup driver NVRAM options.
6146 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
6149 qlt_81xx_config_nvram_stage2(vha, icb);
6151 /* Use alternate WWN? */
6152 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
6153 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
6154 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
6157 /* Prepare nodename */
6158 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
6160 * Firmware will apply the following mask if the nodename was
6163 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
6164 icb->node_name[0] &= 0xF0;
6167 /* Set host adapter parameters. */
6168 ha->flags.disable_risc_code_load = 0;
6169 ha->flags.enable_lip_reset = 0;
6170 ha->flags.enable_lip_full_login =
6171 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
6172 ha->flags.enable_target_reset =
6173 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
6174 ha->flags.enable_led_scheme = 0;
6175 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
6177 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
6178 (BIT_6 | BIT_5 | BIT_4)) >> 4;
6180 /* save HBA serial number */
6181 ha->serial0 = icb->port_name[5];
6182 ha->serial1 = icb->port_name[6];
6183 ha->serial2 = icb->port_name[7];
6184 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
6185 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
6187 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
6189 ha->retry_count = le16_to_cpu(nv->login_retry_count);
6191 /* Set minimum login_timeout to 4 seconds. */
6192 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
6193 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
6194 if (le16_to_cpu(nv->login_timeout) < 4)
6195 nv->login_timeout = __constant_cpu_to_le16(4);
6196 ha->login_timeout = le16_to_cpu(nv->login_timeout);
6197 icb->login_timeout = nv->login_timeout;
6199 /* Set minimum RATOV to 100 tenths of a second. */
6202 ha->loop_reset_delay = nv->reset_delay;
6204 /* Link Down Timeout = 0:
6206 * When Port Down timer expires we will start returning
6207 * I/O's to OS with "DID_NO_CONNECT".
6209 * Link Down Timeout != 0:
6211 * The driver waits for the link to come up after link down
6212 * before returning I/Os to OS with "DID_NO_CONNECT".
6214 if (le16_to_cpu(nv->link_down_timeout) == 0) {
6215 ha->loop_down_abort_time =
6216 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
6218 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
6219 ha->loop_down_abort_time =
6220 (LOOP_DOWN_TIME - ha->link_down_timeout);
6223 /* Need enough time to try and get the port back. */
6224 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
6225 if (qlport_down_retry)
6226 ha->port_down_retry_count = qlport_down_retry;
6228 /* Set login_retry_count */
6229 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
6230 if (ha->port_down_retry_count ==
6231 le16_to_cpu(nv->port_down_retry_count) &&
6232 ha->port_down_retry_count > 3)
6233 ha->login_retry_count = ha->port_down_retry_count;
6234 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6235 ha->login_retry_count = ha->port_down_retry_count;
6236 if (ql2xloginretrycount)
6237 ha->login_retry_count = ql2xloginretrycount;
6239 /* if not running MSI-X we need handshaking on interrupts */
6240 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
6241 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
6244 if (!vha->flags.init_done) {
6245 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6246 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6247 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6248 le16_to_cpu(icb->interrupt_delay_timer): 2;
6250 icb->firmware_options_2 &= __constant_cpu_to_le32(
6251 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
6252 vha->flags.process_response_queue = 0;
6253 if (ha->zio_mode != QLA_ZIO_DISABLED) {
6254 ha->zio_mode = QLA_ZIO_MODE_6;
6256 ql_log(ql_log_info, vha, 0x0075,
6257 "ZIO mode %d enabled; timer delay (%d us).\n",
6259 ha->zio_timer * 100);
6261 icb->firmware_options_2 |= cpu_to_le32(
6262 (uint32_t)ha->zio_mode);
6263 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
6264 vha->flags.process_response_queue = 1;
6268 ql_log(ql_log_warn, vha, 0x0076,
6269 "NVRAM configuration failed.\n");
6275 qla82xx_restart_isp(scsi_qla_host_t *vha)
6278 struct qla_hw_data *ha = vha->hw;
6279 struct req_que *req = ha->req_q_map[0];
6280 struct rsp_que *rsp = ha->rsp_q_map[0];
6281 struct scsi_qla_host *vp;
6282 unsigned long flags;
6284 status = qla2x00_init_rings(vha);
6286 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6287 ha->flags.chip_reset_done = 1;
6289 status = qla2x00_fw_ready(vha);
6291 /* Issue a marker after FW becomes ready. */
6292 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
6293 vha->flags.online = 1;
6294 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6297 /* if no cable then assume it's good */
6298 if ((vha->device_flags & DFLG_NO_CABLE))
6303 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6305 if (!atomic_read(&vha->loop_down_timer)) {
6307 * Issue marker command only when we are going
6308 * to start the I/O .
6310 vha->marker_needed = 1;
6313 ha->isp_ops->enable_intrs(ha);
6315 ha->isp_abort_cnt = 0;
6316 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6318 /* Update the firmware version */
6319 status = qla82xx_check_md_needed(vha);
6322 ha->flags.fce_enabled = 1;
6324 fce_calc_size(ha->fce_bufs));
6325 rval = qla2x00_enable_fce_trace(vha,
6326 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6329 ql_log(ql_log_warn, vha, 0x8001,
6330 "Unable to reinitialize FCE (%d).\n",
6332 ha->flags.fce_enabled = 0;
6337 memset(ha->eft, 0, EFT_SIZE);
6338 rval = qla2x00_enable_eft_trace(vha,
6339 ha->eft_dma, EFT_NUM_BUFFERS);
6341 ql_log(ql_log_warn, vha, 0x8010,
6342 "Unable to reinitialize EFT (%d).\n",
6349 ql_dbg(ql_dbg_taskm, vha, 0x8011,
6350 "qla82xx_restart_isp succeeded.\n");
6352 spin_lock_irqsave(&ha->vport_slock, flags);
6353 list_for_each_entry(vp, &ha->vp_list, list) {
6355 atomic_inc(&vp->vref_count);
6356 spin_unlock_irqrestore(&ha->vport_slock, flags);
6358 qla2x00_vp_abort_isp(vp);
6360 spin_lock_irqsave(&ha->vport_slock, flags);
6361 atomic_dec(&vp->vref_count);
6364 spin_unlock_irqrestore(&ha->vport_slock, flags);
6367 ql_log(ql_log_warn, vha, 0x8016,
6368 "qla82xx_restart_isp **** FAILED ****.\n");
6375 qla81xx_update_fw_options(scsi_qla_host_t *vha)
6377 struct qla_hw_data *ha = vha->hw;
6382 /* Enable ETS Burst. */
6383 memset(ha->fw_options, 0, sizeof(ha->fw_options));
6384 ha->fw_options[2] |= BIT_9;
6385 qla2x00_set_fw_options(vha, ha->fw_options);
6389 * qla24xx_get_fcp_prio
6390 * Gets the fcp cmd priority value for the logged in port.
6391 * Looks for a match of the port descriptors within
6392 * each of the fcp prio config entries. If a match is found,
6393 * the tag (priority) value is returned.
6396 * vha = scsi host structure pointer.
6397 * fcport = port structure pointer.
6400 * non-zero (if found)
6407 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
6410 uint8_t pid_match, wwn_match;
6412 uint32_t pid1, pid2;
6413 uint64_t wwn1, wwn2;
6414 struct qla_fcp_prio_entry *pri_entry;
6415 struct qla_hw_data *ha = vha->hw;
6417 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
6421 entries = ha->fcp_prio_cfg->num_entries;
6422 pri_entry = &ha->fcp_prio_cfg->entry[0];
6424 for (i = 0; i < entries; i++) {
6425 pid_match = wwn_match = 0;
6427 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
6432 /* check source pid for a match */
6433 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
6434 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
6435 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
6436 if (pid1 == INVALID_PORT_ID)
6438 else if (pid1 == pid2)
6442 /* check destination pid for a match */
6443 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
6444 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
6445 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
6446 if (pid1 == INVALID_PORT_ID)
6448 else if (pid1 == pid2)
6452 /* check source WWN for a match */
6453 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
6454 wwn1 = wwn_to_u64(vha->port_name);
6455 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
6456 if (wwn2 == (uint64_t)-1)
6458 else if (wwn1 == wwn2)
6462 /* check destination WWN for a match */
6463 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
6464 wwn1 = wwn_to_u64(fcport->port_name);
6465 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
6466 if (wwn2 == (uint64_t)-1)
6468 else if (wwn1 == wwn2)
6472 if (pid_match == 2 || wwn_match == 2) {
6473 /* Found a matching entry */
6474 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
6475 priority = pri_entry->tag;
6486 * qla24xx_update_fcport_fcp_prio
6487 * Activates fcp priority for the logged in fc port
6490 * vha = scsi host structure pointer.
6491 * fcp = port structure pointer.
6494 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6500 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
6506 if (fcport->port_type != FCT_TARGET ||
6507 fcport->loop_id == FC_NO_LOOP_ID)
6508 return QLA_FUNCTION_FAILED;
6510 priority = qla24xx_get_fcp_prio(vha, fcport);
6512 return QLA_FUNCTION_FAILED;
6514 if (IS_P3P_TYPE(vha->hw)) {
6515 fcport->fcp_prio = priority & 0xf;
6519 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
6520 if (ret == QLA_SUCCESS) {
6521 if (fcport->fcp_prio != priority)
6522 ql_dbg(ql_dbg_user, vha, 0x709e,
6523 "Updated FCP_CMND priority - value=%d loop_id=%d "
6524 "port_id=%02x%02x%02x.\n", priority,
6525 fcport->loop_id, fcport->d_id.b.domain,
6526 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6527 fcport->fcp_prio = priority & 0xf;
6529 ql_dbg(ql_dbg_user, vha, 0x704f,
6530 "Unable to update FCP_CMND priority - ret=0x%x for "
6531 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
6532 fcport->d_id.b.domain, fcport->d_id.b.area,
6533 fcport->d_id.b.al_pa);
6538 * qla24xx_update_all_fcp_prio
6539 * Activates fcp priority for all the logged in ports
6542 * ha = adapter block pointer.
6545 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6551 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
6556 ret = QLA_FUNCTION_FAILED;
6557 /* We need to set priority for all logged in ports */
6558 list_for_each_entry(fcport, &vha->vp_fcports, list)
6559 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);