1 // SPDX-License-Identifier: GPL-2.0-only
3 * QLogic Fibre Channel HBA Driver
4 * Copyright (c) 2003-2014 QLogic Corporation
9 #include <linux/delay.h>
10 #include <linux/slab.h>
11 #include <linux/vmalloc.h>
13 #include "qla_devtbl.h"
19 #include "qla_target.h"
22 * QLogic ISP2x00 Hardware Support Function Prototypes.
24 static int qla2x00_isp_firmware(scsi_qla_host_t *);
25 static int qla2x00_setup_chip(scsi_qla_host_t *);
26 static int qla2x00_fw_ready(scsi_qla_host_t *);
27 static int qla2x00_configure_hba(scsi_qla_host_t *);
28 static int qla2x00_configure_loop(scsi_qla_host_t *);
29 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
30 static int qla2x00_configure_fabric(scsi_qla_host_t *);
31 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *);
32 static int qla2x00_restart_isp(scsi_qla_host_t *);
34 static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
35 static int qla84xx_init_chip(scsi_qla_host_t *);
36 static int qla25xx_init_queues(struct qla_hw_data *);
37 static void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha,
38 struct event_arg *ea);
39 static void qla24xx_handle_prli_done_event(struct scsi_qla_host *,
41 static void __qla24xx_handle_gpdb_event(scsi_qla_host_t *, struct event_arg *);
43 /* SRB Extensions ---------------------------------------------------------- */
46 qla2x00_sp_timeout(struct timer_list *t)
48 srb_t *sp = from_timer(sp, t, u.iocb_cmd.timer);
49 struct srb_iocb *iocb;
50 scsi_qla_host_t *vha = sp->vha;
52 WARN_ON(irqs_disabled());
53 iocb = &sp->u.iocb_cmd;
57 kref_put(&sp->cmd_kref, qla2x00_sp_release);
59 if (vha && qla2x00_isp_reg_stat(vha->hw)) {
60 ql_log(ql_log_info, vha, 0x9008,
61 "PCI/Register disconnect.\n");
62 qla_pci_set_eeh_busy(vha);
66 void qla2x00_sp_free(srb_t *sp)
68 struct srb_iocb *iocb = &sp->u.iocb_cmd;
70 del_timer(&iocb->timer);
74 void qla2xxx_rel_done_warning(srb_t *sp, int res)
76 WARN_ONCE(1, "Calling done() of an already freed srb %p object\n", sp);
79 void qla2xxx_rel_free_warning(srb_t *sp)
81 WARN_ONCE(1, "Calling free() of an already freed srb %p object\n", sp);
84 /* Asynchronous Login/Logout Routines -------------------------------------- */
87 qla2x00_get_async_timeout(struct scsi_qla_host *vha)
90 struct qla_hw_data *ha = vha->hw;
92 /* Firmware should use switch negotiated r_a_tov for timeout. */
93 tmo = ha->r_a_tov / 10 * 2;
95 tmo = FX00_DEF_RATOV * 2;
96 } else if (!IS_FWI2_CAPABLE(ha)) {
98 * Except for earlier ISPs where the timeout is seeded from the
99 * initialization control block.
101 tmo = ha->login_timeout;
106 static void qla24xx_abort_iocb_timeout(void *data)
109 struct srb_iocb *abt = &sp->u.iocb_cmd;
110 struct qla_qpair *qpair = sp->qpair;
113 int sp_found = 0, cmdsp_found = 0;
116 ql_dbg(ql_dbg_async, sp->vha, 0x507c,
117 "Abort timeout - cmd hdl=%x, cmd type=%x hdl=%x, type=%x\n",
118 sp->cmd_sp->handle, sp->cmd_sp->type,
119 sp->handle, sp->type);
121 ql_dbg(ql_dbg_async, sp->vha, 0x507c,
122 "Abort timeout 2 - hdl=%x, type=%x\n",
123 sp->handle, sp->type);
125 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
126 for (handle = 1; handle < qpair->req->num_outstanding_cmds; handle++) {
127 if (sp->cmd_sp && (qpair->req->outstanding_cmds[handle] ==
129 qpair->req->outstanding_cmds[handle] = NULL;
131 qla_put_fw_resources(qpair, &sp->cmd_sp->iores);
134 /* removing the abort */
135 if (qpair->req->outstanding_cmds[handle] == sp) {
136 qpair->req->outstanding_cmds[handle] = NULL;
138 qla_put_fw_resources(qpair, &sp->iores);
142 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
144 if (cmdsp_found && sp->cmd_sp) {
146 * This done function should take care of
147 * original command ref: INIT
149 sp->cmd_sp->done(sp->cmd_sp, QLA_OS_TIMER_EXPIRED);
153 abt->u.abt.comp_status = cpu_to_le16(CS_TIMEOUT);
154 sp->done(sp, QLA_OS_TIMER_EXPIRED);
158 static void qla24xx_abort_sp_done(srb_t *sp, int res)
160 struct srb_iocb *abt = &sp->u.iocb_cmd;
161 srb_t *orig_sp = sp->cmd_sp;
164 qla_wait_nvme_release_cmd_kref(orig_sp);
166 if (sp->flags & SRB_WAKEUP_ON_COMP)
167 complete(&abt->u.abt.comp);
170 kref_put(&sp->cmd_kref, qla2x00_sp_release);
173 int qla24xx_async_abort_cmd(srb_t *cmd_sp, bool wait)
175 scsi_qla_host_t *vha = cmd_sp->vha;
176 struct srb_iocb *abt_iocb;
178 int rval = QLA_FUNCTION_FAILED;
180 /* ref: INIT for ABTS command */
181 sp = qla2xxx_get_qpair_sp(cmd_sp->vha, cmd_sp->qpair, cmd_sp->fcport,
184 return QLA_MEMORY_ALLOC_FAILED;
186 qla_vha_mark_busy(vha);
187 abt_iocb = &sp->u.iocb_cmd;
188 sp->type = SRB_ABT_CMD;
190 sp->qpair = cmd_sp->qpair;
193 sp->flags = SRB_WAKEUP_ON_COMP;
195 init_completion(&abt_iocb->u.abt.comp);
196 /* FW can send 2 x ABTS's timeout/20s */
197 qla2x00_init_async_sp(sp, 42, qla24xx_abort_sp_done);
198 sp->u.iocb_cmd.timeout = qla24xx_abort_iocb_timeout;
200 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
201 abt_iocb->u.abt.req_que_no = cpu_to_le16(cmd_sp->qpair->req->id);
203 ql_dbg(ql_dbg_async, vha, 0x507c,
204 "Abort command issued - hdl=%x, type=%x\n", cmd_sp->handle,
207 rval = qla2x00_start_sp(sp);
208 if (rval != QLA_SUCCESS) {
210 kref_put(&sp->cmd_kref, qla2x00_sp_release);
215 wait_for_completion(&abt_iocb->u.abt.comp);
216 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
217 QLA_SUCCESS : QLA_ERR_FROM_FW;
219 kref_put(&sp->cmd_kref, qla2x00_sp_release);
226 qla2x00_async_iocb_timeout(void *data)
229 fc_port_t *fcport = sp->fcport;
230 struct srb_iocb *lio = &sp->u.iocb_cmd;
235 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
236 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
237 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
239 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
241 pr_info("Async-%s timeout - hdl=%x.\n",
242 sp->name, sp->handle);
247 rc = qla24xx_async_abort_cmd(sp, false);
249 /* Retry as needed. */
250 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
251 lio->u.logio.data[1] =
252 lio->u.logio.flags & SRB_LOGIN_RETRIED ?
253 QLA_LOGIO_LOGIN_RETRIED : 0;
254 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
255 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
257 if (sp->qpair->req->outstanding_cmds[h] ==
259 sp->qpair->req->outstanding_cmds[h] =
264 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
265 sp->done(sp, QLA_FUNCTION_TIMEOUT);
269 case SRB_CT_PTHRU_CMD:
276 rc = qla24xx_async_abort_cmd(sp, false);
278 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
279 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
281 if (sp->qpair->req->outstanding_cmds[h] ==
283 sp->qpair->req->outstanding_cmds[h] =
288 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
289 sp->done(sp, QLA_FUNCTION_TIMEOUT);
295 static void qla2x00_async_login_sp_done(srb_t *sp, int res)
297 struct scsi_qla_host *vha = sp->vha;
298 struct srb_iocb *lio = &sp->u.iocb_cmd;
301 ql_dbg(ql_dbg_disc, vha, 0x20dd,
302 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
304 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
306 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
307 memset(&ea, 0, sizeof(ea));
308 ea.fcport = sp->fcport;
309 ea.data[0] = lio->u.logio.data[0];
310 ea.data[1] = lio->u.logio.data[1];
311 ea.iop[0] = lio->u.logio.iop[0];
312 ea.iop[1] = lio->u.logio.iop[1];
315 ea.data[0] = MBS_COMMAND_ERROR;
316 qla24xx_handle_plogi_done_event(vha, &ea);
320 kref_put(&sp->cmd_kref, qla2x00_sp_release);
324 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
328 struct srb_iocb *lio;
329 int rval = QLA_FUNCTION_FAILED;
331 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
332 fcport->loop_id == FC_NO_LOOP_ID) {
333 ql_log(ql_log_warn, vha, 0xffff,
334 "%s: %8phC - not sending command.\n",
335 __func__, fcport->port_name);
340 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
344 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_PEND);
345 fcport->flags |= FCF_ASYNC_SENT;
346 fcport->logout_completed = 0;
348 sp->type = SRB_LOGIN_CMD;
350 sp->gen1 = fcport->rscn_gen;
351 sp->gen2 = fcport->login_gen;
352 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
353 qla2x00_async_login_sp_done);
355 lio = &sp->u.iocb_cmd;
356 if (N2N_TOPO(fcport->vha->hw) && fcport_is_bigger(fcport)) {
357 lio->u.logio.flags |= SRB_LOGIN_PRLI_ONLY;
359 if (vha->hw->flags.edif_enabled &&
361 lio->u.logio.flags |=
362 (SRB_LOGIN_FCSP | SRB_LOGIN_SKIP_PRLI);
364 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
368 if (NVME_TARGET(vha->hw, fcport))
369 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
371 rval = qla2x00_start_sp(sp);
373 ql_dbg(ql_dbg_disc, vha, 0x2072,
374 "Async-login - %8phC hdl=%x, loopid=%x portid=%06x retries=%d %s.\n",
375 fcport->port_name, sp->handle, fcport->loop_id,
376 fcport->d_id.b24, fcport->login_retry,
377 lio->u.logio.flags & SRB_LOGIN_FCSP ? "FCSP" : "");
379 if (rval != QLA_SUCCESS) {
380 fcport->flags |= FCF_LOGIN_NEEDED;
381 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
389 kref_put(&sp->cmd_kref, qla2x00_sp_release);
390 fcport->flags &= ~FCF_ASYNC_SENT;
392 fcport->flags &= ~FCF_ASYNC_ACTIVE;
395 * async login failed. Could be due to iocb/exchange resource
396 * being low. Set state DELETED for re-login process to start again.
398 qla2x00_set_fcport_disc_state(fcport, DSC_DELETED);
402 static void qla2x00_async_logout_sp_done(srb_t *sp, int res)
404 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
405 sp->fcport->login_gen++;
406 qlt_logo_completion_handler(sp->fcport, sp->u.iocb_cmd.u.logio.data[0]);
408 kref_put(&sp->cmd_kref, qla2x00_sp_release);
412 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
415 int rval = QLA_FUNCTION_FAILED;
417 fcport->flags |= FCF_ASYNC_SENT;
419 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
423 sp->type = SRB_LOGOUT_CMD;
425 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
426 qla2x00_async_logout_sp_done),
428 ql_dbg(ql_dbg_disc, vha, 0x2070,
429 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC explicit %d.\n",
430 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
431 fcport->d_id.b.area, fcport->d_id.b.al_pa,
432 fcport->port_name, fcport->explicit_logout);
434 rval = qla2x00_start_sp(sp);
435 if (rval != QLA_SUCCESS)
441 kref_put(&sp->cmd_kref, qla2x00_sp_release);
443 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
448 qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
451 fcport->flags &= ~FCF_ASYNC_ACTIVE;
452 /* Don't re-login in target mode */
453 if (!fcport->tgt_session)
454 qla2x00_mark_device_lost(vha, fcport, 1);
455 qlt_logo_completion_handler(fcport, data[0]);
458 static void qla2x00_async_prlo_sp_done(srb_t *sp, int res)
460 struct srb_iocb *lio = &sp->u.iocb_cmd;
461 struct scsi_qla_host *vha = sp->vha;
463 sp->fcport->flags &= ~FCF_ASYNC_ACTIVE;
464 if (!test_bit(UNLOADING, &vha->dpc_flags))
465 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
468 kref_put(&sp->cmd_kref, qla2x00_sp_release);
472 qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
477 rval = QLA_FUNCTION_FAILED;
479 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
483 sp->type = SRB_PRLO_CMD;
485 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
486 qla2x00_async_prlo_sp_done);
488 ql_dbg(ql_dbg_disc, vha, 0x2070,
489 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
490 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
491 fcport->d_id.b.area, fcport->d_id.b.al_pa);
493 rval = qla2x00_start_sp(sp);
494 if (rval != QLA_SUCCESS)
501 kref_put(&sp->cmd_kref, qla2x00_sp_release);
503 fcport->flags &= ~FCF_ASYNC_ACTIVE;
508 void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
510 struct fc_port *fcport = ea->fcport;
512 ql_dbg(ql_dbg_disc, vha, 0x20d2,
513 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
514 __func__, fcport->port_name, fcport->disc_state,
515 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
516 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
518 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
521 if (ea->data[0] != MBS_COMMAND_COMPLETE) {
522 ql_dbg(ql_dbg_disc, vha, 0x2066,
523 "%s %8phC: adisc fail: post delete\n",
524 __func__, ea->fcport->port_name);
525 /* deleted = 0 & logout_on_delete = force fw cleanup */
527 fcport->logout_on_delete = 1;
528 qlt_schedule_sess_for_deletion(ea->fcport);
532 if (ea->fcport->disc_state == DSC_DELETE_PEND)
535 if (ea->sp->gen2 != ea->fcport->login_gen) {
536 /* target side must have changed it. */
537 ql_dbg(ql_dbg_disc, vha, 0x20d3,
538 "%s %8phC generation changed\n",
539 __func__, ea->fcport->port_name);
541 } else if (ea->sp->gen1 != ea->fcport->rscn_gen) {
542 qla_rscn_replay(fcport);
543 qlt_schedule_sess_for_deletion(fcport);
547 __qla24xx_handle_gpdb_event(vha, ea);
550 static int qla_post_els_plogi_work(struct scsi_qla_host *vha, fc_port_t *fcport)
552 struct qla_work_evt *e;
554 e = qla2x00_alloc_work(vha, QLA_EVT_ELS_PLOGI);
556 return QLA_FUNCTION_FAILED;
558 e->u.fcport.fcport = fcport;
559 fcport->flags |= FCF_ASYNC_ACTIVE;
560 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_PEND);
561 return qla2x00_post_work(vha, e);
564 static void qla2x00_async_adisc_sp_done(srb_t *sp, int res)
566 struct scsi_qla_host *vha = sp->vha;
568 struct srb_iocb *lio = &sp->u.iocb_cmd;
570 ql_dbg(ql_dbg_disc, vha, 0x2066,
571 "Async done-%s res %x %8phC\n",
572 sp->name, res, sp->fcport->port_name);
574 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
576 memset(&ea, 0, sizeof(ea));
578 ea.data[0] = lio->u.logio.data[0];
579 ea.data[1] = lio->u.logio.data[1];
580 ea.iop[0] = lio->u.logio.iop[0];
581 ea.iop[1] = lio->u.logio.iop[1];
582 ea.fcport = sp->fcport;
585 ea.data[0] = MBS_COMMAND_ERROR;
587 qla24xx_handle_adisc_event(vha, &ea);
589 kref_put(&sp->cmd_kref, qla2x00_sp_release);
593 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
597 struct srb_iocb *lio;
598 int rval = QLA_FUNCTION_FAILED;
600 if (IS_SESSION_DELETED(fcport)) {
601 ql_log(ql_log_warn, vha, 0xffff,
602 "%s: %8phC is being delete - not sending command.\n",
603 __func__, fcport->port_name);
604 fcport->flags &= ~FCF_ASYNC_ACTIVE;
608 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
611 fcport->flags |= FCF_ASYNC_SENT;
613 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
617 sp->type = SRB_ADISC_CMD;
619 sp->gen1 = fcport->rscn_gen;
620 sp->gen2 = fcport->login_gen;
621 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
622 qla2x00_async_adisc_sp_done);
624 if (data[1] & QLA_LOGIO_LOGIN_RETRIED) {
625 lio = &sp->u.iocb_cmd;
626 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
629 ql_dbg(ql_dbg_disc, vha, 0x206f,
630 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
631 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
633 rval = qla2x00_start_sp(sp);
634 if (rval != QLA_SUCCESS)
641 kref_put(&sp->cmd_kref, qla2x00_sp_release);
643 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
644 qla2x00_post_async_adisc_work(vha, fcport, data);
648 static bool qla2x00_is_reserved_id(scsi_qla_host_t *vha, uint16_t loop_id)
650 struct qla_hw_data *ha = vha->hw;
652 if (IS_FWI2_CAPABLE(ha))
653 return loop_id > NPH_LAST_HANDLE;
655 return (loop_id > ha->max_loop_id && loop_id < SNS_FIRST_LOOP_ID) ||
656 loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST;
660 * qla2x00_find_new_loop_id - scan through our port list and find a new usable loop ID
661 * @vha: adapter state pointer.
662 * @dev: port structure pointer.
665 * qla2x00 local function return status code.
670 static int qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
673 struct qla_hw_data *ha = vha->hw;
674 unsigned long flags = 0;
678 spin_lock_irqsave(&ha->vport_slock, flags);
680 dev->loop_id = find_first_zero_bit(ha->loop_id_map, LOOPID_MAP_SIZE);
681 if (dev->loop_id >= LOOPID_MAP_SIZE ||
682 qla2x00_is_reserved_id(vha, dev->loop_id)) {
683 dev->loop_id = FC_NO_LOOP_ID;
684 rval = QLA_FUNCTION_FAILED;
686 set_bit(dev->loop_id, ha->loop_id_map);
688 spin_unlock_irqrestore(&ha->vport_slock, flags);
690 if (rval == QLA_SUCCESS)
691 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
692 "Assigning new loopid=%x, portid=%x.\n",
693 dev->loop_id, dev->d_id.b24);
695 ql_log(ql_log_warn, dev->vha, 0x2087,
696 "No loop_id's available, portid=%x.\n",
702 void qla2x00_clear_loop_id(fc_port_t *fcport)
704 struct qla_hw_data *ha = fcport->vha->hw;
706 if (fcport->loop_id == FC_NO_LOOP_ID ||
707 qla2x00_is_reserved_id(fcport->vha, fcport->loop_id))
710 clear_bit(fcport->loop_id, ha->loop_id_map);
711 fcport->loop_id = FC_NO_LOOP_ID;
714 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
715 struct event_arg *ea)
717 fc_port_t *fcport, *conflict_fcport;
718 struct get_name_list_extended *e;
719 u16 i, n, found = 0, loop_id;
723 u8 current_login_state, nvme_cls;
726 ql_dbg(ql_dbg_disc, vha, 0xffff,
727 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d edif %d\n",
728 __func__, fcport->port_name, fcport->disc_state,
729 fcport->fw_login_state, ea->rc,
730 fcport->login_gen, fcport->last_login_gen,
731 fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id, fcport->edif.enable);
733 if (fcport->disc_state == DSC_DELETE_PEND)
736 if (ea->rc) { /* rval */
737 if (fcport->login_retry == 0) {
738 ql_dbg(ql_dbg_disc, vha, 0x20de,
739 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
740 fcport->port_name, fcport->login_retry);
745 if (fcport->last_rscn_gen != fcport->rscn_gen) {
746 qla_rscn_replay(fcport);
747 qlt_schedule_sess_for_deletion(fcport);
749 } else if (fcport->last_login_gen != fcport->login_gen) {
750 ql_dbg(ql_dbg_disc, vha, 0x20e0,
751 "%s %8phC login gen changed\n",
752 __func__, fcport->port_name);
753 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
757 n = ea->data[0] / sizeof(struct get_name_list_extended);
759 ql_dbg(ql_dbg_disc, vha, 0x20e1,
760 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
761 __func__, __LINE__, fcport->port_name, n,
762 fcport->d_id.b.domain, fcport->d_id.b.area,
763 fcport->d_id.b.al_pa, fcport->loop_id);
765 for (i = 0; i < n; i++) {
767 wwn = wwn_to_u64(e->port_name);
768 id.b.domain = e->port_id[2];
769 id.b.area = e->port_id[1];
770 id.b.al_pa = e->port_id[0];
773 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
776 if (IS_SW_RESV_ADDR(id))
781 loop_id = le16_to_cpu(e->nport_handle);
782 loop_id = (loop_id & 0x7fff);
783 nvme_cls = e->current_login_state >> 4;
784 current_login_state = e->current_login_state & 0xf;
786 if (PRLI_PHASE(nvme_cls)) {
787 current_login_state = nvme_cls;
788 fcport->fc4_type &= ~FS_FC4TYPE_FCP;
789 fcport->fc4_type |= FS_FC4TYPE_NVME;
790 } else if (PRLI_PHASE(current_login_state)) {
791 fcport->fc4_type |= FS_FC4TYPE_FCP;
792 fcport->fc4_type &= ~FS_FC4TYPE_NVME;
795 ql_dbg(ql_dbg_disc, vha, 0x20e2,
796 "%s found %8phC CLS [%x|%x] fc4_type %d ID[%06x|%06x] lid[%d|%d]\n",
797 __func__, fcport->port_name,
798 e->current_login_state, fcport->fw_login_state,
799 fcport->fc4_type, id.b24, fcport->d_id.b24,
800 loop_id, fcport->loop_id);
802 switch (fcport->disc_state) {
803 case DSC_DELETE_PEND:
807 if ((id.b24 != fcport->d_id.b24 &&
809 fcport->loop_id != FC_NO_LOOP_ID) ||
810 (fcport->loop_id != FC_NO_LOOP_ID &&
811 fcport->loop_id != loop_id)) {
812 ql_dbg(ql_dbg_disc, vha, 0x20e3,
813 "%s %d %8phC post del sess\n",
814 __func__, __LINE__, fcport->port_name);
815 if (fcport->n2n_flag)
816 fcport->d_id.b24 = 0;
817 qlt_schedule_sess_for_deletion(fcport);
823 fcport->loop_id = loop_id;
824 if (fcport->n2n_flag)
825 fcport->d_id.b24 = id.b24;
827 wwn = wwn_to_u64(fcport->port_name);
828 qlt_find_sess_invalidate_other(vha, wwn,
829 id, loop_id, &conflict_fcport);
831 if (conflict_fcport) {
833 * Another share fcport share the same loop_id &
834 * nport id. Conflict fcport needs to finish
835 * cleanup before this fcport can proceed to login.
837 conflict_fcport->conflict = fcport;
838 fcport->login_pause = 1;
841 switch (vha->hw->current_topology) {
843 switch (current_login_state) {
844 case DSC_LS_PRLI_COMP:
846 vha, 0x20e4, "%s %d %8phC post gpdb\n",
847 __func__, __LINE__, fcport->port_name);
849 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
850 fcport->port_type = FCT_INITIATOR;
852 fcport->port_type = FCT_TARGET;
853 data[0] = data[1] = 0;
854 qla2x00_post_async_adisc_work(vha, fcport,
857 case DSC_LS_PLOGI_COMP:
858 if (vha->hw->flags.edif_enabled) {
859 /* check to see if App support Secure */
860 qla24xx_post_gpdb_work(vha, fcport, 0);
864 case DSC_LS_PORT_UNAVAIL:
866 if (fcport->loop_id == FC_NO_LOOP_ID) {
867 qla2x00_find_new_loop_id(vha, fcport);
868 fcport->fw_login_state =
871 ql_dbg(ql_dbg_disc, vha, 0x20e5,
872 "%s %d %8phC\n", __func__, __LINE__,
874 qla24xx_fcport_handle_login(vha, fcport);
879 fcport->fw_login_state = current_login_state;
881 switch (current_login_state) {
882 case DSC_LS_PRLI_PEND:
884 * In the middle of PRLI. Let it finish.
885 * Allow relogin code to recheck state again
886 * with GNL. Push disc_state back to DELETED
887 * so GNL can go out again
889 qla2x00_set_fcport_disc_state(fcport,
891 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
893 case DSC_LS_PRLI_COMP:
894 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
895 fcport->port_type = FCT_INITIATOR;
897 fcport->port_type = FCT_TARGET;
899 data[0] = data[1] = 0;
900 qla2x00_post_async_adisc_work(vha, fcport,
903 case DSC_LS_PLOGI_COMP:
904 if (vha->hw->flags.edif_enabled &&
906 /* check to see if App support secure or not */
907 qla24xx_post_gpdb_work(vha, fcport, 0);
910 if (fcport_is_bigger(fcport)) {
911 /* local adapter is smaller */
912 if (fcport->loop_id != FC_NO_LOOP_ID)
913 qla2x00_clear_loop_id(fcport);
915 fcport->loop_id = loop_id;
916 qla24xx_fcport_handle_login(vha,
922 if (fcport_is_smaller(fcport)) {
923 /* local adapter is bigger */
924 if (fcport->loop_id != FC_NO_LOOP_ID)
925 qla2x00_clear_loop_id(fcport);
927 fcport->loop_id = loop_id;
928 qla24xx_fcport_handle_login(vha,
934 } /* switch (ha->current_topology) */
938 switch (vha->hw->current_topology) {
941 for (i = 0; i < n; i++) {
943 id.b.domain = e->port_id[0];
944 id.b.area = e->port_id[1];
945 id.b.al_pa = e->port_id[2];
947 loop_id = le16_to_cpu(e->nport_handle);
949 if (fcport->d_id.b24 == id.b24) {
951 qla2x00_find_fcport_by_wwpn(vha,
953 if (conflict_fcport) {
954 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
956 "%s %d %8phC post del sess\n",
958 conflict_fcport->port_name);
959 qlt_schedule_sess_for_deletion
964 * FW already picked this loop id for
967 if (fcport->loop_id == loop_id)
968 fcport->loop_id = FC_NO_LOOP_ID;
970 qla24xx_fcport_handle_login(vha, fcport);
973 qla2x00_set_fcport_disc_state(fcport, DSC_DELETED);
974 if (time_after_eq(jiffies, fcport->dm_login_expire)) {
975 if (fcport->n2n_link_reset_cnt < 2) {
976 fcport->n2n_link_reset_cnt++;
978 * remote port is not sending PLOGI.
979 * Reset link to kick start his state
982 set_bit(N2N_LINK_RESET,
985 if (fcport->n2n_chip_reset < 1) {
986 ql_log(ql_log_info, vha, 0x705d,
987 "Chip reset to bring laser down");
988 set_bit(ISP_ABORT_NEEDED,
990 fcport->n2n_chip_reset++;
992 ql_log(ql_log_info, vha, 0x705d,
993 "Remote port %8ph is not coming back\n",
995 fcport->scan_state = 0;
998 qla2xxx_wake_dpc(vha);
1001 * report port suppose to do PLOGI. Give him
1002 * more time. FW will catch it.
1004 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1008 qla24xx_fcport_handle_login(vha, fcport);
1016 static void qla24xx_async_gnl_sp_done(srb_t *sp, int res)
1018 struct scsi_qla_host *vha = sp->vha;
1019 unsigned long flags;
1020 struct fc_port *fcport = NULL, *tf;
1021 u16 i, n = 0, loop_id;
1022 struct event_arg ea;
1023 struct get_name_list_extended *e;
1028 ql_dbg(ql_dbg_disc, vha, 0x20e7,
1029 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
1030 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
1031 sp->u.iocb_cmd.u.mbx.in_mb[2]);
1034 sp->fcport->flags &= ~(FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE);
1035 memset(&ea, 0, sizeof(ea));
1039 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
1040 sizeof(struct get_name_list_extended)) {
1041 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
1042 sizeof(struct get_name_list_extended);
1043 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
1046 for (i = 0; i < n; i++) {
1048 loop_id = le16_to_cpu(e->nport_handle);
1049 /* mask out reserve bit */
1050 loop_id = (loop_id & 0x7fff);
1051 set_bit(loop_id, vha->hw->loop_id_map);
1052 wwn = wwn_to_u64(e->port_name);
1054 ql_dbg(ql_dbg_disc, vha, 0x20e8,
1055 "%s %8phC %02x:%02x:%02x CLS %x/%x lid %x \n",
1056 __func__, &wwn, e->port_id[2], e->port_id[1],
1057 e->port_id[0], e->current_login_state, e->last_login_state,
1058 (loop_id & 0x7fff));
1061 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1065 if (!list_empty(&vha->gnl.fcports))
1066 list_splice_init(&vha->gnl.fcports, &h);
1067 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1069 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
1070 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1071 list_del_init(&fcport->gnl_entry);
1072 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1073 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1076 qla24xx_handle_gnl_done_event(vha, &ea);
1079 /* create new fcport if fw has knowledge of new sessions */
1080 for (i = 0; i < n; i++) {
1085 wwn = wwn_to_u64(e->port_name);
1088 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
1089 if (!memcmp((u8 *)&wwn, fcport->port_name,
1096 id.b.domain = e->port_id[2];
1097 id.b.area = e->port_id[1];
1098 id.b.al_pa = e->port_id[0];
1101 if (!found && wwn && !IS_SW_RESV_ADDR(id)) {
1102 ql_dbg(ql_dbg_disc, vha, 0x2065,
1103 "%s %d %8phC %06x post new sess\n",
1104 __func__, __LINE__, (u8 *)&wwn, id.b24);
1105 wwnn = wwn_to_u64(e->node_name);
1106 qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn,
1107 (u8 *)&wwnn, NULL, 0);
1111 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1113 if (!list_empty(&vha->gnl.fcports)) {
1115 list_for_each_entry_safe(fcport, tf, &vha->gnl.fcports,
1117 list_del_init(&fcport->gnl_entry);
1118 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1119 if (qla24xx_post_gnl_work(vha, fcport) == QLA_SUCCESS)
1123 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1126 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1129 int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
1132 int rval = QLA_FUNCTION_FAILED;
1133 unsigned long flags;
1136 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
1139 ql_dbg(ql_dbg_disc, vha, 0x20d9,
1140 "Async-gnlist WWPN %8phC \n", fcport->port_name);
1142 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1143 fcport->flags |= FCF_ASYNC_SENT;
1144 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
1145 fcport->last_rscn_gen = fcport->rscn_gen;
1146 fcport->last_login_gen = fcport->login_gen;
1148 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
1149 if (vha->gnl.sent) {
1150 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1154 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1157 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1161 sp->type = SRB_MB_IOCB;
1162 sp->name = "gnlist";
1163 sp->gen1 = fcport->rscn_gen;
1164 sp->gen2 = fcport->login_gen;
1165 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
1166 qla24xx_async_gnl_sp_done);
1168 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1169 mb[0] = MBC_PORT_NODE_NAME_LIST;
1170 mb[1] = BIT_2 | BIT_3;
1171 mb[2] = MSW(vha->gnl.ldma);
1172 mb[3] = LSW(vha->gnl.ldma);
1173 mb[6] = MSW(MSD(vha->gnl.ldma));
1174 mb[7] = LSW(MSD(vha->gnl.ldma));
1175 mb[8] = vha->gnl.size;
1176 mb[9] = vha->vp_idx;
1178 ql_dbg(ql_dbg_disc, vha, 0x20da,
1179 "Async-%s - OUT WWPN %8phC hndl %x\n",
1180 sp->name, fcport->port_name, sp->handle);
1182 rval = qla2x00_start_sp(sp);
1183 if (rval != QLA_SUCCESS)
1190 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1192 fcport->flags &= ~(FCF_ASYNC_ACTIVE | FCF_ASYNC_SENT);
1196 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1198 struct qla_work_evt *e;
1200 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
1202 return QLA_FUNCTION_FAILED;
1204 e->u.fcport.fcport = fcport;
1205 fcport->flags |= FCF_ASYNC_ACTIVE;
1206 return qla2x00_post_work(vha, e);
1209 static void qla24xx_async_gpdb_sp_done(srb_t *sp, int res)
1211 struct scsi_qla_host *vha = sp->vha;
1212 struct qla_hw_data *ha = vha->hw;
1213 fc_port_t *fcport = sp->fcport;
1214 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
1215 struct event_arg ea;
1217 ql_dbg(ql_dbg_disc, vha, 0x20db,
1218 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
1219 sp->name, res, fcport->port_name, mb[1], mb[2]);
1221 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1223 if (res == QLA_FUNCTION_TIMEOUT)
1226 memset(&ea, 0, sizeof(ea));
1230 qla24xx_handle_gpdb_event(vha, &ea);
1233 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
1234 sp->u.iocb_cmd.u.mbx.in_dma);
1236 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1239 int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1241 struct qla_work_evt *e;
1243 if (vha->host->active_mode == MODE_TARGET)
1244 return QLA_FUNCTION_FAILED;
1246 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
1248 return QLA_FUNCTION_FAILED;
1250 e->u.fcport.fcport = fcport;
1252 return qla2x00_post_work(vha, e);
1255 static void qla2x00_async_prli_sp_done(srb_t *sp, int res)
1257 struct scsi_qla_host *vha = sp->vha;
1258 struct srb_iocb *lio = &sp->u.iocb_cmd;
1259 struct event_arg ea;
1261 ql_dbg(ql_dbg_disc, vha, 0x2129,
1262 "%s %8phC res %x\n", __func__,
1263 sp->fcport->port_name, res);
1265 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1267 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
1268 memset(&ea, 0, sizeof(ea));
1269 ea.fcport = sp->fcport;
1270 ea.data[0] = lio->u.logio.data[0];
1271 ea.data[1] = lio->u.logio.data[1];
1272 ea.iop[0] = lio->u.logio.iop[0];
1273 ea.iop[1] = lio->u.logio.iop[1];
1275 if (res == QLA_OS_TIMER_EXPIRED)
1276 ea.data[0] = QLA_OS_TIMER_EXPIRED;
1278 ea.data[0] = MBS_COMMAND_ERROR;
1280 qla24xx_handle_prli_done_event(vha, &ea);
1283 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1287 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
1290 struct srb_iocb *lio;
1291 int rval = QLA_FUNCTION_FAILED;
1293 if (!vha->flags.online) {
1294 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1295 __func__, __LINE__, fcport->port_name);
1299 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
1300 fcport->fw_login_state == DSC_LS_PRLI_PEND) &&
1301 qla_dual_mode_enabled(vha)) {
1302 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1303 __func__, __LINE__, fcport->port_name);
1307 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1311 fcport->flags |= FCF_ASYNC_SENT;
1312 fcport->logout_completed = 0;
1314 sp->type = SRB_PRLI_CMD;
1316 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
1317 qla2x00_async_prli_sp_done);
1319 lio = &sp->u.iocb_cmd;
1320 lio->u.logio.flags = 0;
1322 if (NVME_TARGET(vha->hw, fcport))
1323 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
1325 ql_dbg(ql_dbg_disc, vha, 0x211b,
1326 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d fc4type %x priority %x %s.\n",
1327 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24,
1328 fcport->login_retry, fcport->fc4_type, vha->hw->fc4_type_priority,
1329 NVME_TARGET(vha->hw, fcport) ? "nvme" : "fcp");
1331 rval = qla2x00_start_sp(sp);
1332 if (rval != QLA_SUCCESS) {
1333 fcport->flags |= FCF_LOGIN_NEEDED;
1334 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1342 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1343 fcport->flags &= ~FCF_ASYNC_SENT;
1347 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1349 struct qla_work_evt *e;
1351 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
1353 return QLA_FUNCTION_FAILED;
1355 e->u.fcport.fcport = fcport;
1356 e->u.fcport.opt = opt;
1357 fcport->flags |= FCF_ASYNC_ACTIVE;
1358 return qla2x00_post_work(vha, e);
1361 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1364 struct srb_iocb *mbx;
1365 int rval = QLA_FUNCTION_FAILED;
1368 struct port_database_24xx *pd;
1369 struct qla_hw_data *ha = vha->hw;
1371 if (IS_SESSION_DELETED(fcport)) {
1372 ql_log(ql_log_warn, vha, 0xffff,
1373 "%s: %8phC is being delete - not sending command.\n",
1374 __func__, fcport->port_name);
1375 fcport->flags &= ~FCF_ASYNC_ACTIVE;
1379 if (!vha->flags.online || fcport->flags & FCF_ASYNC_SENT) {
1380 ql_log(ql_log_warn, vha, 0xffff,
1381 "%s: %8phC online %d flags %x - not sending command.\n",
1382 __func__, fcport->port_name, vha->flags.online, fcport->flags);
1386 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1390 qla2x00_set_fcport_disc_state(fcport, DSC_GPDB);
1392 fcport->flags |= FCF_ASYNC_SENT;
1393 sp->type = SRB_MB_IOCB;
1395 sp->gen1 = fcport->rscn_gen;
1396 sp->gen2 = fcport->login_gen;
1397 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
1398 qla24xx_async_gpdb_sp_done);
1400 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1402 ql_log(ql_log_warn, vha, 0xd043,
1403 "Failed to allocate port database structure.\n");
1407 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1408 mb[0] = MBC_GET_PORT_DATABASE;
1409 mb[1] = fcport->loop_id;
1410 mb[2] = MSW(pd_dma);
1411 mb[3] = LSW(pd_dma);
1412 mb[6] = MSW(MSD(pd_dma));
1413 mb[7] = LSW(MSD(pd_dma));
1414 mb[9] = vha->vp_idx;
1417 mbx = &sp->u.iocb_cmd;
1418 mbx->u.mbx.in = (void *)pd;
1419 mbx->u.mbx.in_dma = pd_dma;
1421 ql_dbg(ql_dbg_disc, vha, 0x20dc,
1422 "Async-%s %8phC hndl %x opt %x\n",
1423 sp->name, fcport->port_name, sp->handle, opt);
1425 rval = qla2x00_start_sp(sp);
1426 if (rval != QLA_SUCCESS)
1432 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1434 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1435 fcport->flags &= ~FCF_ASYNC_SENT;
1437 fcport->flags &= ~FCF_ASYNC_ACTIVE;
1438 qla24xx_post_gpdb_work(vha, fcport, opt);
1443 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1445 unsigned long flags;
1447 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1448 ea->fcport->login_gen++;
1449 ea->fcport->deleted = 0;
1450 ea->fcport->logout_on_delete = 1;
1452 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1453 vha->fcport_count++;
1454 ea->fcport->login_succ = 1;
1456 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1457 qla24xx_sched_upd_fcport(ea->fcport);
1458 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1459 } else if (ea->fcport->login_succ) {
1461 * We have an existing session. A late RSCN delivery
1462 * must have triggered the session to be re-validate.
1463 * Session is still valid.
1465 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1466 "%s %d %8phC session revalidate success\n",
1467 __func__, __LINE__, ea->fcport->port_name);
1468 qla2x00_set_fcport_disc_state(ea->fcport, DSC_LOGIN_COMPLETE);
1470 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1473 static int qla_chk_secure_login(scsi_qla_host_t *vha, fc_port_t *fcport,
1474 struct port_database_24xx *pd)
1478 if (pd->secure_login) {
1479 ql_dbg(ql_dbg_disc, vha, 0x104d,
1480 "Secure Login established on %8phC\n",
1482 fcport->flags |= FCF_FCSP_DEVICE;
1484 ql_dbg(ql_dbg_disc, vha, 0x104d,
1485 "non-Secure Login %8phC",
1487 fcport->flags &= ~FCF_FCSP_DEVICE;
1489 if (vha->hw->flags.edif_enabled) {
1490 if (fcport->flags & FCF_FCSP_DEVICE) {
1491 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_AUTH_PEND);
1492 /* Start edif prli timer & ring doorbell for app */
1493 fcport->edif.rx_sa_set = 0;
1494 fcport->edif.tx_sa_set = 0;
1495 fcport->edif.rx_sa_pending = 0;
1496 fcport->edif.tx_sa_pending = 0;
1498 qla2x00_post_aen_work(vha, FCH_EVT_PORT_ONLINE,
1501 if (DBELL_ACTIVE(vha)) {
1502 ql_dbg(ql_dbg_disc, vha, 0x20ef,
1503 "%s %d %8phC EDIF: post DB_AUTH: AUTH needed\n",
1504 __func__, __LINE__, fcport->port_name);
1505 fcport->edif.app_sess_online = 1;
1507 qla_edb_eventcreate(vha, VND_CMD_AUTH_STATE_NEEDED,
1508 fcport->d_id.b24, 0, fcport);
1512 } else if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
1513 ql_dbg(ql_dbg_disc, vha, 0x2117,
1514 "%s %d %8phC post prli\n",
1515 __func__, __LINE__, fcport->port_name);
1516 qla24xx_post_prli_work(vha, fcport);
1524 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1526 fc_port_t *fcport = ea->fcport;
1527 struct port_database_24xx *pd;
1528 struct srb *sp = ea->sp;
1531 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1533 fcport->flags &= ~FCF_ASYNC_SENT;
1535 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1536 "%s %8phC DS %d LS %x fc4_type %x rc %x\n", __func__,
1537 fcport->port_name, fcport->disc_state, pd->current_login_state,
1538 fcport->fc4_type, ea->rc);
1540 if (fcport->disc_state == DSC_DELETE_PEND) {
1541 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC\n",
1542 __func__, __LINE__, fcport->port_name);
1546 if (NVME_TARGET(vha->hw, fcport))
1547 ls = pd->current_login_state >> 4;
1549 ls = pd->current_login_state & 0xf;
1551 if (ea->sp->gen2 != fcport->login_gen) {
1552 /* target side must have changed it. */
1554 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1555 "%s %8phC generation changed\n",
1556 __func__, fcport->port_name);
1558 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1559 qla_rscn_replay(fcport);
1560 qlt_schedule_sess_for_deletion(fcport);
1561 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n",
1562 __func__, __LINE__, fcport->port_name, ls);
1567 case PDS_PRLI_COMPLETE:
1568 __qla24xx_parse_gpdb(vha, fcport, pd);
1570 case PDS_PLOGI_COMPLETE:
1571 if (qla_chk_secure_login(vha, fcport, pd)) {
1572 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n",
1573 __func__, __LINE__, fcport->port_name, ls);
1577 case PDS_PLOGI_PENDING:
1578 case PDS_PRLI_PENDING:
1579 case PDS_PRLI2_PENDING:
1580 /* Set discovery state back to GNL to Relogin attempt */
1581 if (qla_dual_mode_enabled(vha) ||
1582 qla_ini_mode_enabled(vha)) {
1583 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
1584 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1586 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n",
1587 __func__, __LINE__, fcport->port_name, ls);
1589 case PDS_LOGO_PENDING:
1590 case PDS_PORT_UNAVAILABLE:
1592 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1593 __func__, __LINE__, fcport->port_name);
1594 qlt_schedule_sess_for_deletion(fcport);
1597 __qla24xx_handle_gpdb_event(vha, ea);
1600 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1605 ql_dbg(ql_dbg_disc, vha, 0x307b,
1606 "%s %8phC DS %d LS %d lid %d retries=%d\n",
1607 __func__, fcport->port_name, fcport->disc_state,
1608 fcport->fw_login_state, fcport->loop_id, fcport->login_retry);
1610 if (qla_tgt_mode_enabled(vha))
1613 if (qla_dual_mode_enabled(vha)) {
1614 if (N2N_TOPO(vha->hw)) {
1617 mywwn = wwn_to_u64(vha->port_name);
1618 wwn = wwn_to_u64(fcport->port_name);
1621 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1622 && time_after_eq(jiffies,
1623 fcport->plogi_nack_done_deadline))
1629 /* initiator mode */
1633 if (login && fcport->login_retry) {
1634 fcport->login_retry--;
1635 if (fcport->loop_id == FC_NO_LOOP_ID) {
1636 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1637 rc = qla2x00_find_new_loop_id(vha, fcport);
1639 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1640 "%s %d %8phC post del sess - out of loopid\n",
1641 __func__, __LINE__, fcport->port_name);
1642 fcport->scan_state = 0;
1643 qlt_schedule_sess_for_deletion(fcport);
1647 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1648 "%s %d %8phC post login\n",
1649 __func__, __LINE__, fcport->port_name);
1650 qla2x00_post_async_login_work(vha, fcport, NULL);
1654 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1659 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1660 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d fc4type %x\n",
1661 __func__, fcport->port_name, fcport->disc_state,
1662 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1663 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1664 fcport->login_gen, fcport->loop_id, fcport->scan_state,
1667 if (fcport->scan_state != QLA_FCPORT_FOUND ||
1668 fcport->disc_state == DSC_DELETE_PEND)
1671 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1672 qla_dual_mode_enabled(vha) &&
1673 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1674 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1677 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP &&
1678 !N2N_TOPO(vha->hw)) {
1679 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1680 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1685 /* Target won't initiate port login if fabric is present */
1686 if (vha->host->active_mode == MODE_TARGET && !N2N_TOPO(vha->hw))
1689 if (fcport->flags & (FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE)) {
1690 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1694 switch (fcport->disc_state) {
1696 switch (vha->hw->current_topology) {
1698 if (fcport_is_smaller(fcport)) {
1699 /* this adapter is bigger */
1700 if (fcport->login_retry) {
1701 if (fcport->loop_id == FC_NO_LOOP_ID) {
1702 qla2x00_find_new_loop_id(vha,
1704 fcport->fw_login_state =
1705 DSC_LS_PORT_UNAVAIL;
1707 fcport->login_retry--;
1708 qla_post_els_plogi_work(vha, fcport);
1710 ql_log(ql_log_info, vha, 0x705d,
1711 "Unable to reach remote port %8phC",
1715 qla24xx_post_gnl_work(vha, fcport);
1719 if (fcport->loop_id == FC_NO_LOOP_ID) {
1720 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1721 "%s %d %8phC post gnl\n",
1722 __func__, __LINE__, fcport->port_name);
1723 qla24xx_post_gnl_work(vha, fcport);
1725 qla_chk_n2n_b4_login(vha, fcport);
1732 switch (vha->hw->current_topology) {
1734 if ((fcport->current_login_state & 0xf) == 0x6) {
1735 ql_dbg(ql_dbg_disc, vha, 0x2118,
1736 "%s %d %8phC post GPDB work\n",
1737 __func__, __LINE__, fcport->port_name);
1738 fcport->chip_reset =
1739 vha->hw->base_qpair->chip_reset;
1740 qla24xx_post_gpdb_work(vha, fcport, 0);
1742 ql_dbg(ql_dbg_disc, vha, 0x2118,
1743 "%s %d %8phC post %s PRLI\n",
1744 __func__, __LINE__, fcport->port_name,
1745 NVME_TARGET(vha->hw, fcport) ? "NVME" :
1747 qla24xx_post_prli_work(vha, fcport);
1751 if (fcport->login_pause) {
1752 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1753 "%s %d %8phC exit\n",
1756 fcport->last_rscn_gen = fcport->rscn_gen;
1757 fcport->last_login_gen = fcport->login_gen;
1758 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1761 qla_chk_n2n_b4_login(vha, fcport);
1766 case DSC_LOGIN_FAILED:
1767 if (N2N_TOPO(vha->hw))
1768 qla_chk_n2n_b4_login(vha, fcport);
1770 qlt_schedule_sess_for_deletion(fcport);
1773 case DSC_LOGIN_COMPLETE:
1774 /* recheck login state */
1775 data[0] = data[1] = 0;
1776 qla2x00_post_async_adisc_work(vha, fcport, data);
1779 case DSC_LOGIN_PEND:
1780 if (vha->hw->flags.edif_enabled)
1783 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1784 ql_dbg(ql_dbg_disc, vha, 0x2118,
1785 "%s %d %8phC post %s PRLI\n",
1786 __func__, __LINE__, fcport->port_name,
1787 NVME_TARGET(vha->hw, fcport) ? "NVME" : "FC");
1788 qla24xx_post_prli_work(vha, fcport);
1792 case DSC_UPD_FCPORT:
1793 sec = jiffies_to_msecs(jiffies -
1794 fcport->jiffies_at_registration)/1000;
1795 if (fcport->sec_since_registration < sec && sec &&
1797 fcport->sec_since_registration = sec;
1798 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
1799 "%s %8phC - Slow Rport registration(%d Sec)\n",
1800 __func__, fcport->port_name, sec);
1803 if (fcport->next_disc_state != DSC_DELETE_PEND)
1804 fcport->next_disc_state = DSC_ADISC;
1805 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1815 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1816 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1818 struct qla_work_evt *e;
1820 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1822 return QLA_FUNCTION_FAILED;
1824 e->u.new_sess.id = *id;
1825 e->u.new_sess.pla = pla;
1826 e->u.new_sess.fc4_type = fc4_type;
1827 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1829 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1831 return qla2x00_post_work(vha, e);
1834 void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
1837 unsigned long flags;
1839 switch (ea->id.b.rsvd_1) {
1840 case RSCN_PORT_ADDR:
1841 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1843 if (fcport->flags & FCF_FCP2_DEVICE &&
1844 atomic_read(&fcport->state) == FCS_ONLINE) {
1845 ql_dbg(ql_dbg_disc, vha, 0x2115,
1846 "Delaying session delete for FCP2 portid=%06x %8phC ",
1847 fcport->d_id.b24, fcport->port_name);
1851 if (vha->hw->flags.edif_enabled && DBELL_ACTIVE(vha)) {
1853 * On ipsec start by remote port, Target port
1854 * may use RSCN to trigger initiator to
1855 * relogin. If driver is already in the
1856 * process of a relogin, then ignore the RSCN
1857 * and allow the current relogin to continue.
1858 * This reduces thrashing of the connection.
1860 if (atomic_read(&fcport->state) == FCS_ONLINE) {
1862 * If state = online, then set scan_needed=1 to do relogin.
1863 * Otherwise we're already in the middle of a relogin
1865 fcport->scan_needed = 1;
1869 fcport->scan_needed = 1;
1874 case RSCN_AREA_ADDR:
1875 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1876 if (fcport->flags & FCF_FCP2_DEVICE &&
1877 atomic_read(&fcport->state) == FCS_ONLINE)
1880 if ((ea->id.b24 & 0xffff00) == (fcport->d_id.b24 & 0xffff00)) {
1881 fcport->scan_needed = 1;
1887 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1888 if (fcport->flags & FCF_FCP2_DEVICE &&
1889 atomic_read(&fcport->state) == FCS_ONLINE)
1892 if ((ea->id.b24 & 0xff0000) == (fcport->d_id.b24 & 0xff0000)) {
1893 fcport->scan_needed = 1;
1900 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1901 if (fcport->flags & FCF_FCP2_DEVICE &&
1902 atomic_read(&fcport->state) == FCS_ONLINE)
1905 fcport->scan_needed = 1;
1911 spin_lock_irqsave(&vha->work_lock, flags);
1912 if (vha->scan.scan_flags == 0) {
1913 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s: schedule\n", __func__);
1914 vha->scan.scan_flags |= SF_QUEUED;
1915 schedule_delayed_work(&vha->scan.scan_work, 5);
1917 spin_unlock_irqrestore(&vha->work_lock, flags);
1920 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1921 struct event_arg *ea)
1923 fc_port_t *fcport = ea->fcport;
1925 if (test_bit(UNLOADING, &vha->dpc_flags))
1928 ql_dbg(ql_dbg_disc, vha, 0x2102,
1929 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1930 __func__, fcport->port_name, fcport->disc_state,
1931 fcport->fw_login_state, fcport->login_pause,
1932 fcport->deleted, fcport->conflict,
1933 fcport->last_rscn_gen, fcport->rscn_gen,
1934 fcport->last_login_gen, fcport->login_gen,
1937 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1938 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gnl\n",
1939 __func__, __LINE__, fcport->port_name);
1940 qla24xx_post_gnl_work(vha, fcport);
1944 qla24xx_fcport_handle_login(vha, fcport);
1947 void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
1948 struct event_arg *ea)
1950 if (N2N_TOPO(vha->hw) && fcport_is_smaller(ea->fcport) &&
1951 vha->hw->flags.edif_enabled) {
1952 /* check to see if App support Secure */
1953 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1957 /* for pure Target Mode, PRLI will not be initiated */
1958 if (vha->host->active_mode == MODE_TARGET)
1961 ql_dbg(ql_dbg_disc, vha, 0x2118,
1962 "%s %d %8phC post PRLI\n",
1963 __func__, __LINE__, ea->fcport->port_name);
1964 qla24xx_post_prli_work(vha, ea->fcport);
1968 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1969 * to be consumed by the fcport
1971 void qla_rscn_replay(fc_port_t *fcport)
1973 struct event_arg ea;
1975 switch (fcport->disc_state) {
1976 case DSC_DELETE_PEND:
1982 if (fcport->scan_needed) {
1983 memset(&ea, 0, sizeof(ea));
1984 ea.id = fcport->d_id;
1985 ea.id.b.rsvd_1 = RSCN_PORT_ADDR;
1986 qla2x00_handle_rscn(fcport->vha, &ea);
1991 qla2x00_tmf_iocb_timeout(void *data)
1994 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1996 unsigned long flags;
1998 rc = qla24xx_async_abort_cmd(sp, false);
2000 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
2001 for (h = 1; h < sp->qpair->req->num_outstanding_cmds; h++) {
2002 if (sp->qpair->req->outstanding_cmds[h] == sp) {
2003 sp->qpair->req->outstanding_cmds[h] = NULL;
2004 qla_put_fw_resources(sp->qpair, &sp->iores);
2008 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
2009 tmf->u.tmf.comp_status = cpu_to_le16(CS_TIMEOUT);
2010 tmf->u.tmf.data = QLA_FUNCTION_FAILED;
2011 complete(&tmf->u.tmf.comp);
2015 static void qla2x00_tmf_sp_done(srb_t *sp, int res)
2017 struct srb_iocb *tmf = &sp->u.iocb_cmd;
2019 complete(&tmf->u.tmf.comp);
2023 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
2026 struct scsi_qla_host *vha = fcport->vha;
2027 struct srb_iocb *tm_iocb;
2029 int rval = QLA_FUNCTION_FAILED;
2032 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
2036 qla_vha_mark_busy(vha);
2037 sp->type = SRB_TM_CMD;
2039 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha),
2040 qla2x00_tmf_sp_done);
2041 sp->u.iocb_cmd.timeout = qla2x00_tmf_iocb_timeout;
2043 tm_iocb = &sp->u.iocb_cmd;
2044 init_completion(&tm_iocb->u.tmf.comp);
2045 tm_iocb->u.tmf.flags = flags;
2046 tm_iocb->u.tmf.lun = lun;
2048 ql_dbg(ql_dbg_taskm, vha, 0x802f,
2049 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
2050 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
2051 fcport->d_id.b.area, fcport->d_id.b.al_pa);
2053 rval = qla2x00_start_sp(sp);
2054 if (rval != QLA_SUCCESS)
2056 wait_for_completion(&tm_iocb->u.tmf.comp);
2058 rval = tm_iocb->u.tmf.data;
2060 if (rval != QLA_SUCCESS) {
2061 ql_log(ql_log_warn, vha, 0x8030,
2062 "TM IOCB failed (%x).\n", rval);
2065 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
2066 flags = tm_iocb->u.tmf.flags;
2067 lun = (uint16_t)tm_iocb->u.tmf.lun;
2069 /* Issue Marker IOCB */
2070 qla2x00_marker(vha, vha->hw->base_qpair,
2071 fcport->loop_id, lun,
2072 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
2077 kref_put(&sp->cmd_kref, qla2x00_sp_release);
2083 qla24xx_async_abort_command(srb_t *sp)
2085 unsigned long flags = 0;
2088 fc_port_t *fcport = sp->fcport;
2089 struct qla_qpair *qpair = sp->qpair;
2090 struct scsi_qla_host *vha = fcport->vha;
2091 struct req_que *req = qpair->req;
2093 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
2094 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
2095 if (req->outstanding_cmds[handle] == sp)
2098 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
2100 if (handle == req->num_outstanding_cmds) {
2101 /* Command not found. */
2102 return QLA_ERR_NOT_FOUND;
2104 if (sp->type == SRB_FXIOCB_DCMD)
2105 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
2106 FXDISC_ABORT_IOCTL);
2108 return qla24xx_async_abort_cmd(sp, true);
2112 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
2115 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
2118 switch (ea->data[0]) {
2119 case MBS_COMMAND_COMPLETE:
2120 ql_dbg(ql_dbg_disc, vha, 0x2118,
2121 "%s %d %8phC post gpdb\n",
2122 __func__, __LINE__, ea->fcport->port_name);
2124 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2125 ea->fcport->logout_on_delete = 1;
2126 ea->fcport->nvme_prli_service_param = ea->iop[0];
2127 if (ea->iop[0] & NVME_PRLI_SP_FIRST_BURST)
2128 ea->fcport->nvme_first_burst_size =
2129 (ea->iop[1] & 0xffff) * 512;
2131 ea->fcport->nvme_first_burst_size = 0;
2132 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2136 ql_dbg(ql_dbg_disc, vha, 0x2118,
2137 "%s %d %8phC priority %s, fc4type %x prev try %s\n",
2138 __func__, __LINE__, ea->fcport->port_name,
2139 vha->hw->fc4_type_priority == FC4_PRIORITY_FCP ?
2140 "FCP" : "NVMe", ea->fcport->fc4_type,
2141 (sp->u.iocb_cmd.u.logio.flags & SRB_LOGIN_NVME_PRLI) ?
2144 if (NVME_FCP_TARGET(ea->fcport)) {
2145 if (sp->u.iocb_cmd.u.logio.flags & SRB_LOGIN_NVME_PRLI)
2146 ea->fcport->do_prli_nvme = 0;
2148 ea->fcport->do_prli_nvme = 1;
2150 ea->fcport->do_prli_nvme = 0;
2153 if (N2N_TOPO(vha->hw)) {
2154 if (ea->fcport->n2n_link_reset_cnt ==
2155 vha->hw->login_retry_count &&
2156 ea->fcport->flags & FCF_FCSP_DEVICE) {
2157 /* remote authentication app just started */
2158 ea->fcport->n2n_link_reset_cnt = 0;
2161 if (ea->fcport->n2n_link_reset_cnt <
2162 vha->hw->login_retry_count) {
2163 ea->fcport->n2n_link_reset_cnt++;
2164 vha->relogin_jif = jiffies + 2 * HZ;
2166 * PRLI failed. Reset link to kick start
2169 set_bit(N2N_LINK_RESET, &vha->dpc_flags);
2170 qla2xxx_wake_dpc(vha);
2172 ql_log(ql_log_warn, vha, 0x2119,
2173 "%s %d %8phC Unable to reconnect\n",
2175 ea->fcport->port_name);
2179 * switch connect. login failed. Take connection down
2180 * and allow relogin to retrigger
2182 ea->fcport->flags &= ~FCF_ASYNC_SENT;
2183 ea->fcport->keep_nport_handle = 0;
2184 ea->fcport->logout_on_delete = 1;
2185 qlt_schedule_sess_for_deletion(ea->fcport);
2192 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
2194 port_id_t cid; /* conflict Nport id */
2196 struct fc_port *conflict_fcport;
2197 unsigned long flags;
2198 struct fc_port *fcport = ea->fcport;
2200 ql_dbg(ql_dbg_disc, vha, 0xffff,
2201 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
2202 __func__, fcport->port_name, fcport->disc_state,
2203 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
2204 ea->sp->gen1, fcport->rscn_gen,
2205 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
2207 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
2208 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
2209 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2210 "%s %d %8phC Remote is trying to login\n",
2211 __func__, __LINE__, fcport->port_name);
2215 if ((fcport->disc_state == DSC_DELETE_PEND) ||
2216 (fcport->disc_state == DSC_DELETED)) {
2217 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2221 if (ea->sp->gen2 != fcport->login_gen) {
2222 /* target side must have changed it. */
2223 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2224 "%s %8phC generation changed\n",
2225 __func__, fcport->port_name);
2226 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2228 } else if (ea->sp->gen1 != fcport->rscn_gen) {
2229 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2230 "%s %8phC RSCN generation changed\n",
2231 __func__, fcport->port_name);
2232 qla_rscn_replay(fcport);
2233 qlt_schedule_sess_for_deletion(fcport);
2237 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
2240 switch (ea->data[0]) {
2241 case MBS_COMMAND_COMPLETE:
2243 * Driver must validate login state - If PRLI not complete,
2244 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
2247 if (vha->hw->flags.edif_enabled) {
2248 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2249 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2250 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2251 ea->fcport->logout_on_delete = 1;
2252 ea->fcport->send_els_logo = 0;
2253 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
2254 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2256 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2258 if (NVME_TARGET(vha->hw, fcport)) {
2259 ql_dbg(ql_dbg_disc, vha, 0x2117,
2260 "%s %d %8phC post prli\n",
2261 __func__, __LINE__, fcport->port_name);
2262 qla24xx_post_prli_work(vha, fcport);
2264 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2265 "%s %d %8phC LoopID 0x%x in use with %06x. post gpdb\n",
2266 __func__, __LINE__, fcport->port_name,
2267 fcport->loop_id, fcport->d_id.b24);
2269 set_bit(fcport->loop_id, vha->hw->loop_id_map);
2270 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2271 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2272 fcport->logout_on_delete = 1;
2273 fcport->send_els_logo = 0;
2274 fcport->fw_login_state = DSC_LS_PRLI_COMP;
2275 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2277 qla24xx_post_gpdb_work(vha, fcport, 0);
2281 case MBS_COMMAND_ERROR:
2282 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
2283 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
2285 qlt_schedule_sess_for_deletion(ea->fcport);
2287 case MBS_LOOP_ID_USED:
2288 /* data[1] = IO PARAM 1 = nport ID */
2289 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
2290 cid.b.area = (ea->iop[1] >> 8) & 0xff;
2291 cid.b.al_pa = ea->iop[1] & 0xff;
2294 ql_dbg(ql_dbg_disc, vha, 0x20ec,
2295 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2296 __func__, __LINE__, ea->fcport->port_name,
2297 ea->fcport->loop_id, cid.b24);
2299 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2300 ea->fcport->loop_id = FC_NO_LOOP_ID;
2301 qla24xx_post_gnl_work(vha, ea->fcport);
2303 case MBS_PORT_ID_USED:
2304 lid = ea->iop[1] & 0xffff;
2305 qlt_find_sess_invalidate_other(vha,
2306 wwn_to_u64(ea->fcport->port_name),
2307 ea->fcport->d_id, lid, &conflict_fcport);
2309 if (conflict_fcport) {
2311 * Another fcport share the same loop_id/nport id.
2312 * Conflict fcport needs to finish cleanup before this
2313 * fcport can proceed to login.
2315 conflict_fcport->conflict = ea->fcport;
2316 ea->fcport->login_pause = 1;
2318 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2319 "%s %d %8phC NPortId %06x inuse with loopid 0x%x.\n",
2320 __func__, __LINE__, ea->fcport->port_name,
2321 ea->fcport->d_id.b24, lid);
2323 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2324 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2325 __func__, __LINE__, ea->fcport->port_name,
2326 ea->fcport->d_id.b24, lid);
2328 qla2x00_clear_loop_id(ea->fcport);
2329 set_bit(lid, vha->hw->loop_id_map);
2330 ea->fcport->loop_id = lid;
2331 ea->fcport->keep_nport_handle = 0;
2332 ea->fcport->logout_on_delete = 1;
2333 qlt_schedule_sess_for_deletion(ea->fcport);
2340 /****************************************************************************/
2341 /* QLogic ISP2x00 Hardware Support Functions. */
2342 /****************************************************************************/
2345 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
2347 int rval = QLA_SUCCESS;
2348 struct qla_hw_data *ha = vha->hw;
2349 uint32_t idc_major_ver, idc_minor_ver;
2352 qla83xx_idc_lock(vha, 0);
2354 /* SV: TODO: Assign initialization timeout from
2355 * flash-info / other param
2357 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
2358 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
2360 /* Set our fcoe function presence */
2361 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
2362 ql_dbg(ql_dbg_p3p, vha, 0xb077,
2363 "Error while setting DRV-Presence.\n");
2364 rval = QLA_FUNCTION_FAILED;
2368 /* Decide the reset ownership */
2369 qla83xx_reset_ownership(vha);
2372 * On first protocol driver load:
2373 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2375 * Others: Check compatibility with current IDC Major version.
2377 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
2378 if (ha->flags.nic_core_reset_owner) {
2379 /* Set IDC Major version */
2380 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
2381 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
2383 /* Clearing IDC-Lock-Recovery register */
2384 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
2385 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
2387 * Clear further IDC participation if we are not compatible with
2388 * the current IDC Major Version.
2390 ql_log(ql_log_warn, vha, 0xb07d,
2391 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2392 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
2393 __qla83xx_clear_drv_presence(vha);
2394 rval = QLA_FUNCTION_FAILED;
2397 /* Each function sets its supported Minor version. */
2398 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
2399 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
2400 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
2402 if (ha->flags.nic_core_reset_owner) {
2403 memset(config, 0, sizeof(config));
2404 if (!qla81xx_get_port_config(vha, config))
2405 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
2409 rval = qla83xx_idc_state_handler(vha);
2412 qla83xx_idc_unlock(vha, 0);
2418 * qla2x00_initialize_adapter
2422 * ha = adapter block pointer.
2428 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
2431 struct qla_hw_data *ha = vha->hw;
2432 struct req_que *req = ha->req_q_map[0];
2433 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2435 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2436 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2438 /* Clear adapter flags. */
2439 vha->flags.online = 0;
2440 ha->flags.chip_reset_done = 0;
2441 vha->flags.reset_active = 0;
2442 ha->flags.pci_channel_io_perm_failure = 0;
2443 ha->flags.eeh_busy = 0;
2444 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2445 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
2446 atomic_set(&vha->loop_state, LOOP_DOWN);
2447 vha->device_flags = DFLG_NO_CABLE;
2449 vha->flags.management_server_logged_in = 0;
2450 vha->marker_needed = 0;
2451 ha->isp_abort_cnt = 0;
2452 ha->beacon_blink_led = 0;
2454 set_bit(0, ha->req_qid_map);
2455 set_bit(0, ha->rsp_qid_map);
2457 ql_dbg(ql_dbg_init, vha, 0x0040,
2458 "Configuring PCI space...\n");
2459 rval = ha->isp_ops->pci_config(vha);
2461 ql_log(ql_log_warn, vha, 0x0044,
2462 "Unable to configure PCI space.\n");
2466 ha->isp_ops->reset_chip(vha);
2468 /* Check for secure flash support */
2469 if (IS_QLA28XX(ha)) {
2470 if (rd_reg_word(®->mailbox12) & BIT_0)
2471 ha->flags.secure_adapter = 1;
2472 ql_log(ql_log_info, vha, 0xffff, "Secure Adapter: %s\n",
2473 (ha->flags.secure_adapter) ? "Yes" : "No");
2477 rval = qla2xxx_get_flash_info(vha);
2479 ql_log(ql_log_fatal, vha, 0x004f,
2480 "Unable to validate FLASH data.\n");
2484 if (IS_QLA8044(ha)) {
2485 qla8044_read_reset_template(vha);
2487 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2488 * If DONRESET_BIT0 is set, drivers should not set dev_state
2489 * to NEED_RESET. But if NEED_RESET is set, drivers should
2490 * should honor the reset. */
2491 if (ql2xdontresethba == 1)
2492 qla8044_set_idc_dontreset(vha);
2495 ha->isp_ops->get_flash_version(vha, req->ring);
2496 ql_dbg(ql_dbg_init, vha, 0x0061,
2497 "Configure NVRAM parameters...\n");
2499 /* Let priority default to FCP, can be overridden by nvram_config */
2500 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2502 ha->isp_ops->nvram_config(vha);
2504 if (ha->fc4_type_priority != FC4_PRIORITY_FCP &&
2505 ha->fc4_type_priority != FC4_PRIORITY_NVME)
2506 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2508 ql_log(ql_log_info, vha, 0xffff, "FC4 priority set to %s\n",
2509 ha->fc4_type_priority == FC4_PRIORITY_FCP ? "FCP" : "NVMe");
2511 if (ha->flags.disable_serdes) {
2512 /* Mask HBA via NVRAM settings? */
2513 ql_log(ql_log_info, vha, 0x0077,
2514 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
2515 return QLA_FUNCTION_FAILED;
2518 ql_dbg(ql_dbg_init, vha, 0x0078,
2519 "Verifying loaded RISC code...\n");
2521 /* If smartsan enabled then require fdmi and rdp enabled */
2527 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
2528 rval = ha->isp_ops->chip_diag(vha);
2531 rval = qla2x00_setup_chip(vha);
2536 if (IS_QLA84XX(ha)) {
2537 ha->cs84xx = qla84xx_get_chip(vha);
2539 ql_log(ql_log_warn, vha, 0x00d0,
2540 "Unable to configure ISP84XX.\n");
2541 return QLA_FUNCTION_FAILED;
2545 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2546 rval = qla2x00_init_rings(vha);
2548 /* No point in continuing if firmware initialization failed. */
2549 if (rval != QLA_SUCCESS)
2552 ha->flags.chip_reset_done = 1;
2554 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2555 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2556 rval = qla84xx_init_chip(vha);
2557 if (rval != QLA_SUCCESS) {
2558 ql_log(ql_log_warn, vha, 0x00d4,
2559 "Unable to initialize ISP84XX.\n");
2560 qla84xx_put_chip(vha);
2564 /* Load the NIC Core f/w if we are the first protocol driver. */
2565 if (IS_QLA8031(ha)) {
2566 rval = qla83xx_nic_core_fw_load(vha);
2568 ql_log(ql_log_warn, vha, 0x0124,
2569 "Error in initializing NIC Core f/w.\n");
2572 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2573 qla24xx_read_fcp_prio_cfg(vha);
2575 if (IS_P3P_TYPE(ha))
2576 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2578 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2584 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2587 * Returns 0 on success.
2590 qla2100_pci_config(scsi_qla_host_t *vha)
2593 unsigned long flags;
2594 struct qla_hw_data *ha = vha->hw;
2595 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2597 pci_set_master(ha->pdev);
2598 pci_try_set_mwi(ha->pdev);
2600 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2601 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2602 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2604 pci_disable_rom(ha->pdev);
2606 /* Get PCI bus information. */
2607 spin_lock_irqsave(&ha->hardware_lock, flags);
2608 ha->pci_attr = rd_reg_word(®->ctrl_status);
2609 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2615 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2618 * Returns 0 on success.
2621 qla2300_pci_config(scsi_qla_host_t *vha)
2624 unsigned long flags = 0;
2626 struct qla_hw_data *ha = vha->hw;
2627 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2629 pci_set_master(ha->pdev);
2630 pci_try_set_mwi(ha->pdev);
2632 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2633 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2635 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2636 w &= ~PCI_COMMAND_INTX_DISABLE;
2637 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2640 * If this is a 2300 card and not 2312, reset the
2641 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2642 * the 2310 also reports itself as a 2300 so we need to get the
2643 * fb revision level -- a 6 indicates it really is a 2300 and
2646 if (IS_QLA2300(ha)) {
2647 spin_lock_irqsave(&ha->hardware_lock, flags);
2650 wrt_reg_word(®->hccr, HCCR_PAUSE_RISC);
2651 for (cnt = 0; cnt < 30000; cnt++) {
2652 if ((rd_reg_word(®->hccr) & HCCR_RISC_PAUSE) != 0)
2658 /* Select FPM registers. */
2659 wrt_reg_word(®->ctrl_status, 0x20);
2660 rd_reg_word(®->ctrl_status);
2662 /* Get the fb rev level */
2663 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2665 if (ha->fb_rev == FPM_2300)
2666 pci_clear_mwi(ha->pdev);
2668 /* Deselect FPM registers. */
2669 wrt_reg_word(®->ctrl_status, 0x0);
2670 rd_reg_word(®->ctrl_status);
2672 /* Release RISC module. */
2673 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
2674 for (cnt = 0; cnt < 30000; cnt++) {
2675 if ((rd_reg_word(®->hccr) & HCCR_RISC_PAUSE) == 0)
2681 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2684 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2686 pci_disable_rom(ha->pdev);
2688 /* Get PCI bus information. */
2689 spin_lock_irqsave(&ha->hardware_lock, flags);
2690 ha->pci_attr = rd_reg_word(®->ctrl_status);
2691 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2697 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2700 * Returns 0 on success.
2703 qla24xx_pci_config(scsi_qla_host_t *vha)
2706 unsigned long flags = 0;
2707 struct qla_hw_data *ha = vha->hw;
2708 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2710 pci_set_master(ha->pdev);
2711 pci_try_set_mwi(ha->pdev);
2713 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2714 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2715 w &= ~PCI_COMMAND_INTX_DISABLE;
2716 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2718 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2720 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2721 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2722 pcix_set_mmrbc(ha->pdev, 2048);
2724 /* PCIe -- adjust Maximum Read Request Size (2048). */
2725 if (pci_is_pcie(ha->pdev))
2726 pcie_set_readrq(ha->pdev, 4096);
2728 pci_disable_rom(ha->pdev);
2730 ha->chip_revision = ha->pdev->revision;
2732 /* Get PCI bus information. */
2733 spin_lock_irqsave(&ha->hardware_lock, flags);
2734 ha->pci_attr = rd_reg_dword(®->ctrl_status);
2735 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2741 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2744 * Returns 0 on success.
2747 qla25xx_pci_config(scsi_qla_host_t *vha)
2750 struct qla_hw_data *ha = vha->hw;
2752 pci_set_master(ha->pdev);
2753 pci_try_set_mwi(ha->pdev);
2755 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2756 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2757 w &= ~PCI_COMMAND_INTX_DISABLE;
2758 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2760 /* PCIe -- adjust Maximum Read Request Size (2048). */
2761 if (pci_is_pcie(ha->pdev))
2762 pcie_set_readrq(ha->pdev, 4096);
2764 pci_disable_rom(ha->pdev);
2766 ha->chip_revision = ha->pdev->revision;
2772 * qla2x00_isp_firmware() - Choose firmware image.
2775 * Returns 0 on success.
2778 qla2x00_isp_firmware(scsi_qla_host_t *vha)
2781 uint16_t loop_id, topo, sw_cap;
2782 uint8_t domain, area, al_pa;
2783 struct qla_hw_data *ha = vha->hw;
2785 /* Assume loading risc code */
2786 rval = QLA_FUNCTION_FAILED;
2788 if (ha->flags.disable_risc_code_load) {
2789 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
2791 /* Verify checksum of loaded RISC code. */
2792 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
2793 if (rval == QLA_SUCCESS) {
2794 /* And, verify we are not in ROM code. */
2795 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2796 &area, &domain, &topo, &sw_cap);
2801 ql_dbg(ql_dbg_init, vha, 0x007a,
2802 "**** Load RISC code ****.\n");
2808 * qla2x00_reset_chip() - Reset ISP chip.
2811 * Returns 0 on success.
2814 qla2x00_reset_chip(scsi_qla_host_t *vha)
2816 unsigned long flags = 0;
2817 struct qla_hw_data *ha = vha->hw;
2818 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2821 int rval = QLA_FUNCTION_FAILED;
2823 if (unlikely(pci_channel_offline(ha->pdev)))
2826 ha->isp_ops->disable_intrs(ha);
2828 spin_lock_irqsave(&ha->hardware_lock, flags);
2830 /* Turn off master enable */
2832 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2833 cmd &= ~PCI_COMMAND_MASTER;
2834 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2836 if (!IS_QLA2100(ha)) {
2838 wrt_reg_word(®->hccr, HCCR_PAUSE_RISC);
2839 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2840 for (cnt = 0; cnt < 30000; cnt++) {
2841 if ((rd_reg_word(®->hccr) &
2842 HCCR_RISC_PAUSE) != 0)
2847 rd_reg_word(®->hccr); /* PCI Posting. */
2851 /* Select FPM registers. */
2852 wrt_reg_word(®->ctrl_status, 0x20);
2853 rd_reg_word(®->ctrl_status); /* PCI Posting. */
2855 /* FPM Soft Reset. */
2856 wrt_reg_word(®->fpm_diag_config, 0x100);
2857 rd_reg_word(®->fpm_diag_config); /* PCI Posting. */
2859 /* Toggle Fpm Reset. */
2860 if (!IS_QLA2200(ha)) {
2861 wrt_reg_word(®->fpm_diag_config, 0x0);
2862 rd_reg_word(®->fpm_diag_config); /* PCI Posting. */
2865 /* Select frame buffer registers. */
2866 wrt_reg_word(®->ctrl_status, 0x10);
2867 rd_reg_word(®->ctrl_status); /* PCI Posting. */
2869 /* Reset frame buffer FIFOs. */
2870 if (IS_QLA2200(ha)) {
2871 WRT_FB_CMD_REG(ha, reg, 0xa000);
2872 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2874 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2876 /* Read back fb_cmd until zero or 3 seconds max */
2877 for (cnt = 0; cnt < 3000; cnt++) {
2878 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2884 /* Select RISC module registers. */
2885 wrt_reg_word(®->ctrl_status, 0);
2886 rd_reg_word(®->ctrl_status); /* PCI Posting. */
2888 /* Reset RISC processor. */
2889 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
2890 rd_reg_word(®->hccr); /* PCI Posting. */
2892 /* Release RISC processor. */
2893 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
2894 rd_reg_word(®->hccr); /* PCI Posting. */
2897 wrt_reg_word(®->hccr, HCCR_CLR_RISC_INT);
2898 wrt_reg_word(®->hccr, HCCR_CLR_HOST_INT);
2900 /* Reset ISP chip. */
2901 wrt_reg_word(®->ctrl_status, CSR_ISP_SOFT_RESET);
2903 /* Wait for RISC to recover from reset. */
2904 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2906 * It is necessary to for a delay here since the card doesn't
2907 * respond to PCI reads during a reset. On some architectures
2908 * this will result in an MCA.
2911 for (cnt = 30000; cnt; cnt--) {
2912 if ((rd_reg_word(®->ctrl_status) &
2913 CSR_ISP_SOFT_RESET) == 0)
2920 /* Reset RISC processor. */
2921 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
2923 wrt_reg_word(®->semaphore, 0);
2925 /* Release RISC processor. */
2926 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
2927 rd_reg_word(®->hccr); /* PCI Posting. */
2929 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2930 for (cnt = 0; cnt < 30000; cnt++) {
2931 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
2939 /* Turn on master enable */
2940 cmd |= PCI_COMMAND_MASTER;
2941 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2943 /* Disable RISC pause on FPM parity error. */
2944 if (!IS_QLA2100(ha)) {
2945 wrt_reg_word(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
2946 rd_reg_word(®->hccr); /* PCI Posting. */
2949 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2955 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2958 * Returns 0 on success.
2961 qla81xx_reset_mpi(scsi_qla_host_t *vha)
2963 uint16_t mb[4] = {0x1010, 0, 1, 0};
2965 if (!IS_QLA81XX(vha->hw))
2968 return qla81xx_write_mpi_register(vha, mb);
2972 qla_chk_risc_recovery(scsi_qla_host_t *vha)
2974 struct qla_hw_data *ha = vha->hw;
2975 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2976 __le16 __iomem *mbptr = ®->mailbox0;
2979 int rc = QLA_SUCCESS;
2981 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
2984 /* this check is only valid after RISC reset */
2985 mb[0] = rd_reg_word(mbptr);
2988 rc = QLA_FUNCTION_FAILED;
2990 for (i = 1; i < 32; i++) {
2991 mb[i] = rd_reg_word(mbptr);
2995 ql_log(ql_log_warn, vha, 0x1015,
2996 "RISC reset failed. mb[0-7] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
2997 mb[0], mb[1], mb[2], mb[3], mb[4], mb[5], mb[6], mb[7]);
2998 ql_log(ql_log_warn, vha, 0x1015,
2999 "RISC reset failed. mb[8-15] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
3000 mb[8], mb[9], mb[10], mb[11], mb[12], mb[13], mb[14],
3002 ql_log(ql_log_warn, vha, 0x1015,
3003 "RISC reset failed. mb[16-23] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
3004 mb[16], mb[17], mb[18], mb[19], mb[20], mb[21], mb[22],
3006 ql_log(ql_log_warn, vha, 0x1015,
3007 "RISC reset failed. mb[24-31] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
3008 mb[24], mb[25], mb[26], mb[27], mb[28], mb[29], mb[30],
3015 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
3018 * Returns 0 on success.
3021 qla24xx_reset_risc(scsi_qla_host_t *vha)
3023 unsigned long flags = 0;
3024 struct qla_hw_data *ha = vha->hw;
3025 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3028 static int abts_cnt; /* ISP abort retry counts */
3029 int rval = QLA_SUCCESS;
3032 spin_lock_irqsave(&ha->hardware_lock, flags);
3035 wrt_reg_dword(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
3036 for (cnt = 0; cnt < 30000; cnt++) {
3037 if ((rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
3043 if (!(rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE))
3044 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
3046 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
3047 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
3048 rd_reg_dword(®->hccr),
3049 rd_reg_dword(®->ctrl_status),
3050 (rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE));
3052 wrt_reg_dword(®->ctrl_status,
3053 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
3054 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
3058 /* Wait for firmware to complete NVRAM accesses. */
3059 rd_reg_word(®->mailbox0);
3060 for (cnt = 10000; rd_reg_word(®->mailbox0) != 0 &&
3061 rval == QLA_SUCCESS; cnt--) {
3066 rval = QLA_FUNCTION_TIMEOUT;
3069 if (rval == QLA_SUCCESS)
3070 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
3072 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
3073 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
3074 rd_reg_dword(®->hccr),
3075 rd_reg_word(®->mailbox0));
3077 /* Wait for soft-reset to complete. */
3078 rd_reg_dword(®->ctrl_status);
3079 for (cnt = 0; cnt < 60; cnt++) {
3081 if ((rd_reg_dword(®->ctrl_status) &
3082 CSRX_ISP_SOFT_RESET) == 0)
3087 if (!(rd_reg_dword(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
3088 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
3090 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
3091 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
3092 rd_reg_dword(®->hccr),
3093 rd_reg_dword(®->ctrl_status));
3095 /* If required, do an MPI FW reset now */
3096 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
3097 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
3098 if (++abts_cnt < 5) {
3099 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3100 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
3103 * We exhausted the ISP abort retries. We have to
3104 * set the board offline.
3107 vha->flags.online = 0;
3112 wrt_reg_dword(®->hccr, HCCRX_SET_RISC_RESET);
3113 rd_reg_dword(®->hccr);
3115 wrt_reg_dword(®->hccr, HCCRX_REL_RISC_PAUSE);
3116 rd_reg_dword(®->hccr);
3118 wrt_reg_dword(®->hccr, HCCRX_CLR_RISC_RESET);
3120 rd_reg_dword(®->hccr);
3122 wd = rd_reg_word(®->mailbox0);
3123 for (cnt = 300; wd != 0 && rval == QLA_SUCCESS; cnt--) {
3127 if (print && qla_chk_risc_recovery(vha))
3130 wd = rd_reg_word(®->mailbox0);
3132 rval = QLA_FUNCTION_TIMEOUT;
3134 ql_log(ql_log_warn, vha, 0x015e,
3135 "RISC reset timeout\n");
3139 if (rval == QLA_SUCCESS)
3140 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
3142 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
3143 "Host Risc 0x%x, mailbox0 0x%x\n",
3144 rd_reg_dword(®->hccr),
3145 rd_reg_word(®->mailbox0));
3147 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3149 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
3150 "Driver in %s mode\n",
3151 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
3153 if (IS_NOPOLLING_TYPE(ha))
3154 ha->isp_ops->enable_intrs(ha);
3160 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
3162 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
3164 wrt_reg_dword(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
3165 *data = rd_reg_dword(®->iobase_window + RISC_REGISTER_WINDOW_OFFSET);
3169 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
3171 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
3173 wrt_reg_dword(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
3174 wrt_reg_dword(®->iobase_window + RISC_REGISTER_WINDOW_OFFSET, data);
3178 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
3181 uint delta_msec = 100;
3182 uint elapsed_msec = 0;
3186 if (vha->hw->pdev->subsystem_device != 0x0175 &&
3187 vha->hw->pdev->subsystem_device != 0x0240)
3190 wrt_reg_dword(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
3194 timeout_msec = TIMEOUT_SEMAPHORE;
3195 n = timeout_msec / delta_msec;
3197 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
3198 qla25xx_read_risc_sema_reg(vha, &wd32);
3199 if (wd32 & RISC_SEMAPHORE)
3202 elapsed_msec += delta_msec;
3203 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
3207 if (!(wd32 & RISC_SEMAPHORE))
3210 if (!(wd32 & RISC_SEMAPHORE_FORCE))
3213 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
3214 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
3215 n = timeout_msec / delta_msec;
3217 qla25xx_read_risc_sema_reg(vha, &wd32);
3218 if (!(wd32 & RISC_SEMAPHORE_FORCE))
3221 elapsed_msec += delta_msec;
3222 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
3226 if (wd32 & RISC_SEMAPHORE_FORCE)
3227 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
3232 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
3239 * qla24xx_reset_chip() - Reset ISP24xx chip.
3242 * Returns 0 on success.
3245 qla24xx_reset_chip(scsi_qla_host_t *vha)
3247 struct qla_hw_data *ha = vha->hw;
3248 int rval = QLA_FUNCTION_FAILED;
3250 if (pci_channel_offline(ha->pdev) &&
3251 ha->flags.pci_channel_io_perm_failure) {
3255 ha->isp_ops->disable_intrs(ha);
3257 qla25xx_manipulate_risc_semaphore(vha);
3259 /* Perform RISC reset. */
3260 rval = qla24xx_reset_risc(vha);
3266 * qla2x00_chip_diag() - Test chip for proper operation.
3269 * Returns 0 on success.
3272 qla2x00_chip_diag(scsi_qla_host_t *vha)
3275 struct qla_hw_data *ha = vha->hw;
3276 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3277 unsigned long flags = 0;
3281 struct req_que *req = ha->req_q_map[0];
3283 /* Assume a failed state */
3284 rval = QLA_FUNCTION_FAILED;
3286 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
3287 ®->flash_address);
3289 spin_lock_irqsave(&ha->hardware_lock, flags);
3291 /* Reset ISP chip. */
3292 wrt_reg_word(®->ctrl_status, CSR_ISP_SOFT_RESET);
3295 * We need to have a delay here since the card will not respond while
3296 * in reset causing an MCA on some architectures.
3299 data = qla2x00_debounce_register(®->ctrl_status);
3300 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
3302 data = rd_reg_word(®->ctrl_status);
3307 goto chip_diag_failed;
3309 ql_dbg(ql_dbg_init, vha, 0x007c,
3310 "Reset register cleared by chip reset.\n");
3312 /* Reset RISC processor. */
3313 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
3314 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
3316 /* Workaround for QLA2312 PCI parity error */
3317 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
3318 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
3319 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
3321 data = RD_MAILBOX_REG(ha, reg, 0);
3328 goto chip_diag_failed;
3330 /* Check product ID of chip */
3331 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
3333 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
3334 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
3335 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
3336 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
3337 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
3338 mb[3] != PROD_ID_3) {
3339 ql_log(ql_log_warn, vha, 0x0062,
3340 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
3341 mb[1], mb[2], mb[3]);
3343 goto chip_diag_failed;
3345 ha->product_id[0] = mb[1];
3346 ha->product_id[1] = mb[2];
3347 ha->product_id[2] = mb[3];
3348 ha->product_id[3] = mb[4];
3350 /* Adjust fw RISC transfer size */
3351 if (req->length > 1024)
3352 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
3354 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
3357 if (IS_QLA2200(ha) &&
3358 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
3359 /* Limit firmware transfer size with a 2200A */
3360 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
3362 ha->device_type |= DT_ISP2200A;
3363 ha->fw_transfer_size = 128;
3366 /* Wrap Incoming Mailboxes Test. */
3367 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3369 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
3370 rval = qla2x00_mbx_reg_test(vha);
3372 ql_log(ql_log_warn, vha, 0x0080,
3373 "Failed mailbox send register test.\n");
3375 /* Flag a successful rval */
3377 spin_lock_irqsave(&ha->hardware_lock, flags);
3381 ql_log(ql_log_info, vha, 0x0081,
3382 "Chip diagnostics **** FAILED ****.\n");
3384 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3390 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3393 * Returns 0 on success.
3396 qla24xx_chip_diag(scsi_qla_host_t *vha)
3399 struct qla_hw_data *ha = vha->hw;
3400 struct req_que *req = ha->req_q_map[0];
3402 if (IS_P3P_TYPE(ha))
3405 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
3407 rval = qla2x00_mbx_reg_test(vha);
3409 ql_log(ql_log_warn, vha, 0x0082,
3410 "Failed mailbox send register test.\n");
3412 /* Flag a successful rval */
3420 qla2x00_init_fce_trace(scsi_qla_host_t *vha)
3425 struct qla_hw_data *ha = vha->hw;
3427 if (!IS_FWI2_CAPABLE(ha))
3430 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3431 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3435 ql_dbg(ql_dbg_init, vha, 0x00bd,
3436 "%s: FCE Mem is already allocated.\n",
3441 /* Allocate memory for Fibre Channel Event Buffer. */
3442 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3445 ql_log(ql_log_warn, vha, 0x00be,
3446 "Unable to allocate (%d KB) for FCE.\n",
3451 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3452 ha->fce_mb, &ha->fce_bufs);
3454 ql_log(ql_log_warn, vha, 0x00bf,
3455 "Unable to initialize FCE (%d).\n", rval);
3456 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, tc_dma);
3460 ql_dbg(ql_dbg_init, vha, 0x00c0,
3461 "Allocated (%d KB) for FCE...\n", FCE_SIZE / 1024);
3463 ha->flags.fce_enabled = 1;
3464 ha->fce_dma = tc_dma;
3469 qla2x00_init_eft_trace(scsi_qla_host_t *vha)
3474 struct qla_hw_data *ha = vha->hw;
3476 if (!IS_FWI2_CAPABLE(ha))
3480 ql_dbg(ql_dbg_init, vha, 0x00bd,
3481 "%s: EFT Mem is already allocated.\n",
3486 /* Allocate memory for Extended Trace Buffer. */
3487 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3490 ql_log(ql_log_warn, vha, 0x00c1,
3491 "Unable to allocate (%d KB) for EFT.\n",
3496 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3498 ql_log(ql_log_warn, vha, 0x00c2,
3499 "Unable to initialize EFT (%d).\n", rval);
3500 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, tc_dma);
3504 ql_dbg(ql_dbg_init, vha, 0x00c3,
3505 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3507 ha->eft_dma = tc_dma;
3512 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3514 qla2x00_init_fce_trace(vha);
3515 qla2x00_init_eft_trace(vha);
3519 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3521 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
3522 eft_size, fce_size, mq_size;
3523 struct qla_hw_data *ha = vha->hw;
3524 struct req_que *req = ha->req_q_map[0];
3525 struct rsp_que *rsp = ha->rsp_q_map[0];
3526 struct qla2xxx_fw_dump *fw_dump;
3529 ql_dbg(ql_dbg_init, vha, 0x00bd,
3530 "Firmware dump already allocated.\n");
3535 ha->fw_dump_cap_flags = 0;
3536 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
3537 req_q_size = rsp_q_size = 0;
3539 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3540 fixed_size = sizeof(struct qla2100_fw_dump);
3541 } else if (IS_QLA23XX(ha)) {
3542 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
3543 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
3545 } else if (IS_FWI2_CAPABLE(ha)) {
3547 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
3548 else if (IS_QLA81XX(ha))
3549 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
3550 else if (IS_QLA25XX(ha))
3551 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
3553 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
3555 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
3558 if (!IS_QLA83XX(ha))
3559 mq_size = sizeof(struct qla2xxx_mq_chain);
3561 * Allocate maximum buffer size for all queues - Q0.
3562 * Resizing must be done at end-of-dump processing.
3564 mq_size += (ha->max_req_queues - 1) *
3565 (req->length * sizeof(request_t));
3566 mq_size += (ha->max_rsp_queues - 1) *
3567 (rsp->length * sizeof(response_t));
3569 if (ha->tgt.atio_ring)
3570 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3572 qla2x00_init_fce_trace(vha);
3574 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3575 qla2x00_init_eft_trace(vha);
3577 eft_size = EFT_SIZE;
3580 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3581 struct fwdt *fwdt = ha->fwdt;
3584 for (j = 0; j < 2; j++, fwdt++) {
3585 if (!fwdt->template) {
3586 ql_dbg(ql_dbg_init, vha, 0x00ba,
3587 "-> fwdt%u no template\n", j);
3590 ql_dbg(ql_dbg_init, vha, 0x00fa,
3591 "-> fwdt%u calculating fwdump size...\n", j);
3592 fwdt->dump_size = qla27xx_fwdt_calculate_dump_size(
3593 vha, fwdt->template);
3594 ql_dbg(ql_dbg_init, vha, 0x00fa,
3595 "-> fwdt%u calculated fwdump size = %#lx bytes\n",
3596 j, fwdt->dump_size);
3597 dump_size += fwdt->dump_size;
3599 /* Add space for spare MPI fw dump. */
3600 dump_size += ha->fwdt[1].dump_size;
3602 req_q_size = req->length * sizeof(request_t);
3603 rsp_q_size = rsp->length * sizeof(response_t);
3604 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3605 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size
3607 ha->chain_offset = dump_size;
3608 dump_size += mq_size + fce_size;
3609 if (ha->exchoffld_buf)
3610 dump_size += sizeof(struct qla2xxx_offld_chain) +
3612 if (ha->exlogin_buf)
3613 dump_size += sizeof(struct qla2xxx_offld_chain) +
3617 if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) {
3619 ql_dbg(ql_dbg_init, vha, 0x00c5,
3620 "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n",
3621 __func__, dump_size, ha->fw_dump_len,
3622 ha->fw_dump_alloc_len);
3624 fw_dump = vmalloc(dump_size);
3626 ql_log(ql_log_warn, vha, 0x00c4,
3627 "Unable to allocate (%d KB) for firmware dump.\n",
3630 mutex_lock(&ha->optrom_mutex);
3631 if (ha->fw_dumped) {
3632 memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len);
3634 ha->fw_dump = fw_dump;
3635 ha->fw_dump_alloc_len = dump_size;
3636 ql_dbg(ql_dbg_init, vha, 0x00c5,
3637 "Re-Allocated (%d KB) and save firmware dump.\n",
3641 ha->fw_dump = fw_dump;
3643 ha->fw_dump_len = ha->fw_dump_alloc_len =
3645 ql_dbg(ql_dbg_init, vha, 0x00c5,
3646 "Allocated (%d KB) for firmware dump.\n",
3649 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3650 ha->mpi_fw_dump = (char *)fw_dump +
3651 ha->fwdt[1].dump_size;
3652 mutex_unlock(&ha->optrom_mutex);
3656 ha->fw_dump->signature[0] = 'Q';
3657 ha->fw_dump->signature[1] = 'L';
3658 ha->fw_dump->signature[2] = 'G';
3659 ha->fw_dump->signature[3] = 'C';
3660 ha->fw_dump->version = htonl(1);
3662 ha->fw_dump->fixed_size = htonl(fixed_size);
3663 ha->fw_dump->mem_size = htonl(mem_size);
3664 ha->fw_dump->req_q_size = htonl(req_q_size);
3665 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3667 ha->fw_dump->eft_size = htonl(eft_size);
3668 ha->fw_dump->eft_addr_l =
3669 htonl(LSD(ha->eft_dma));
3670 ha->fw_dump->eft_addr_h =
3671 htonl(MSD(ha->eft_dma));
3673 ha->fw_dump->header_size =
3675 (struct qla2xxx_fw_dump, isp));
3677 mutex_unlock(&ha->optrom_mutex);
3683 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3685 #define MPS_MASK 0xe0
3690 if (!IS_QLA81XX(vha->hw))
3693 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3694 if (rval != QLA_SUCCESS) {
3695 ql_log(ql_log_warn, vha, 0x0105,
3696 "Unable to acquire semaphore.\n");
3700 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3701 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3702 if (rval != QLA_SUCCESS) {
3703 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3708 if (dc == (dw & MPS_MASK))
3713 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3714 if (rval != QLA_SUCCESS) {
3715 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3719 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3720 if (rval != QLA_SUCCESS) {
3721 ql_log(ql_log_warn, vha, 0x006d,
3722 "Unable to release semaphore.\n");
3730 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3732 /* Don't try to reallocate the array */
3733 if (req->outstanding_cmds)
3736 if (!IS_FWI2_CAPABLE(ha))
3737 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3739 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3740 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3742 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3745 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3749 if (!req->outstanding_cmds) {
3751 * Try to allocate a minimal size just so we can get through
3754 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
3755 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3759 if (!req->outstanding_cmds) {
3760 ql_log(ql_log_fatal, NULL, 0x0126,
3761 "Failed to allocate memory for "
3762 "outstanding_cmds for req_que %p.\n", req);
3763 req->num_outstanding_cmds = 0;
3764 return QLA_FUNCTION_FAILED;
3771 #define PRINT_FIELD(_field, _flag, _str) { \
3772 if (a0->_field & _flag) {\
3778 len = snprintf(ptr, leftover, "%s", _str); \
3785 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
3788 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
3789 u8 str[STR_LEN], *ptr, p;
3792 memset(str, 0, STR_LEN);
3793 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
3794 ql_dbg(ql_dbg_init, vha, 0x015a,
3795 "SFP MFG Name: %s\n", str);
3797 memset(str, 0, STR_LEN);
3798 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
3799 ql_dbg(ql_dbg_init, vha, 0x015c,
3800 "SFP Part Name: %s\n", str);
3803 memset(str, 0, STR_LEN);
3807 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
3808 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
3809 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
3810 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
3811 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3812 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3813 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3814 ql_dbg(ql_dbg_init, vha, 0x0160,
3815 "SFP Media: %s\n", str);
3818 memset(str, 0, STR_LEN);
3822 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3823 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3824 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3825 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3826 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3827 ql_dbg(ql_dbg_init, vha, 0x0196,
3828 "SFP Link Length: %s\n", str);
3830 memset(str, 0, STR_LEN);
3834 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3835 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3836 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3837 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3838 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3839 ql_dbg(ql_dbg_init, vha, 0x016e,
3840 "SFP FC Link Tech: %s\n", str);
3843 ql_dbg(ql_dbg_init, vha, 0x016f,
3844 "SFP Distant: %d km\n", a0->length_km);
3845 if (a0->length_100m)
3846 ql_dbg(ql_dbg_init, vha, 0x0170,
3847 "SFP Distant: %d m\n", a0->length_100m*100);
3848 if (a0->length_50um_10m)
3849 ql_dbg(ql_dbg_init, vha, 0x0189,
3850 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3851 if (a0->length_62um_10m)
3852 ql_dbg(ql_dbg_init, vha, 0x018a,
3853 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3854 if (a0->length_om4_10m)
3855 ql_dbg(ql_dbg_init, vha, 0x0194,
3856 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3857 if (a0->length_om3_10m)
3858 ql_dbg(ql_dbg_init, vha, 0x0195,
3859 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3864 * qla24xx_detect_sfp()
3866 * @vha: adapter state pointer.
3869 * 0 -- Configure firmware to use short-range settings -- normal
3870 * buffer-to-buffer credits.
3872 * 1 -- Configure firmware to use long-range settings -- extra
3873 * buffer-to-buffer credits should be allocated with
3874 * ha->lr_distance containing distance settings from NVRAM or SFP
3878 qla24xx_detect_sfp(scsi_qla_host_t *vha)
3881 struct sff_8247_a0 *a;
3882 struct qla_hw_data *ha = vha->hw;
3883 struct nvram_81xx *nv = ha->nvram;
3884 #define LR_DISTANCE_UNKNOWN 2
3885 static const char * const types[] = { "Short", "Long" };
3886 static const char * const lengths[] = { "(10km)", "(5km)", "" };
3889 /* Seed with NVRAM settings. */
3891 ha->flags.lr_detected = 0;
3892 if (IS_BPM_RANGE_CAPABLE(ha) &&
3893 (nv->enhanced_features & NEF_LR_DIST_ENABLE)) {
3895 ha->flags.lr_detected = 1;
3897 (nv->enhanced_features >> LR_DIST_NV_POS)
3901 if (!IS_BPM_ENABLED(vha))
3903 /* Determine SR/LR capabilities of SFP/Transceiver. */
3904 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3909 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3910 qla2xxx_print_sfp_info(vha);
3912 ha->flags.lr_detected = 0;
3914 if (ll & FC_LL_VL || ll & FC_LL_L) {
3915 /* Long range, track length. */
3916 ha->flags.lr_detected = 1;
3918 if (a->length_km > 5 || a->length_100m > 50)
3919 ha->lr_distance = LR_DISTANCE_10K;
3921 ha->lr_distance = LR_DISTANCE_5K;
3925 ql_dbg(ql_dbg_async, vha, 0x507b,
3926 "SFP detect: %s-Range SFP %s (nvr=%x ll=%x lr=%x lrd=%x).\n",
3927 types[ha->flags.lr_detected],
3928 ha->flags.lr_detected ? lengths[ha->lr_distance] :
3929 lengths[LR_DISTANCE_UNKNOWN],
3930 used_nvram, ll, ha->flags.lr_detected, ha->lr_distance);
3931 return ha->flags.lr_detected;
3934 void qla_init_iocb_limit(scsi_qla_host_t *vha)
3938 struct qla_hw_data *ha = vha->hw;
3940 num_qps = ha->num_qpairs + 1;
3941 limit = (ha->orig_fw_iocb_count * QLA_IOCB_PCT_LIMIT) / 100;
3943 ha->base_qpair->fwres.iocbs_total = ha->orig_fw_iocb_count;
3944 ha->base_qpair->fwres.iocbs_limit = limit;
3945 ha->base_qpair->fwres.iocbs_qp_limit = limit / num_qps;
3946 ha->base_qpair->fwres.iocbs_used = 0;
3948 ha->base_qpair->fwres.exch_total = ha->orig_fw_xcb_count;
3949 ha->base_qpair->fwres.exch_limit = (ha->orig_fw_xcb_count *
3950 QLA_IOCB_PCT_LIMIT) / 100;
3951 ha->base_qpair->fwres.exch_used = 0;
3953 for (i = 0; i < ha->max_qpairs; i++) {
3954 if (ha->queue_pair_map[i]) {
3955 ha->queue_pair_map[i]->fwres.iocbs_total =
3956 ha->orig_fw_iocb_count;
3957 ha->queue_pair_map[i]->fwres.iocbs_limit = limit;
3958 ha->queue_pair_map[i]->fwres.iocbs_qp_limit =
3960 ha->queue_pair_map[i]->fwres.iocbs_used = 0;
3961 ha->queue_pair_map[i]->fwres.exch_total = ha->orig_fw_xcb_count;
3962 ha->queue_pair_map[i]->fwres.exch_limit =
3963 (ha->orig_fw_xcb_count * QLA_IOCB_PCT_LIMIT) / 100;
3964 ha->queue_pair_map[i]->fwres.exch_used = 0;
3970 * qla2x00_setup_chip() - Load and start RISC firmware.
3973 * Returns 0 on success.
3976 qla2x00_setup_chip(scsi_qla_host_t *vha)
3979 uint32_t srisc_address = 0;
3980 struct qla_hw_data *ha = vha->hw;
3981 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3982 unsigned long flags;
3983 uint16_t fw_major_version;
3986 if (IS_P3P_TYPE(ha)) {
3987 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3988 if (rval == QLA_SUCCESS) {
3989 qla2x00_stop_firmware(vha);
3990 goto enable_82xx_npiv;
3995 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3996 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3997 spin_lock_irqsave(&ha->hardware_lock, flags);
3998 wrt_reg_word(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
3999 rd_reg_word(®->hccr);
4000 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4003 qla81xx_mpi_sync(vha);
4006 /* Load firmware sequences */
4007 rval = ha->isp_ops->load_risc(vha, &srisc_address);
4008 if (rval == QLA_SUCCESS) {
4009 ql_dbg(ql_dbg_init, vha, 0x00c9,
4010 "Verifying Checksum of loaded RISC code.\n");
4012 rval = qla2x00_verify_checksum(vha, srisc_address);
4013 if (rval == QLA_SUCCESS) {
4014 /* Start firmware execution. */
4015 ql_dbg(ql_dbg_init, vha, 0x00ca,
4016 "Starting firmware.\n");
4019 ha->flags.exlogins_enabled = 1;
4021 if (qla_is_exch_offld_enabled(vha))
4022 ha->flags.exchoffld_enabled = 1;
4024 rval = qla2x00_execute_fw(vha, srisc_address);
4025 /* Retrieve firmware information. */
4026 if (rval == QLA_SUCCESS) {
4027 /* Enable BPM support? */
4028 if (!done_once++ && qla24xx_detect_sfp(vha)) {
4029 ql_dbg(ql_dbg_init, vha, 0x00ca,
4030 "Re-starting firmware -- BPM.\n");
4031 /* Best-effort - re-init. */
4032 ha->isp_ops->reset_chip(vha);
4033 ha->isp_ops->chip_diag(vha);
4034 goto execute_fw_with_lr;
4037 if (IS_ZIO_THRESHOLD_CAPABLE(ha))
4038 qla27xx_set_zio_threshold(vha,
4039 ha->last_zio_threshold);
4041 rval = qla2x00_set_exlogins_buffer(vha);
4042 if (rval != QLA_SUCCESS)
4045 rval = qla2x00_set_exchoffld_buffer(vha);
4046 if (rval != QLA_SUCCESS)
4050 fw_major_version = ha->fw_major_version;
4051 if (IS_P3P_TYPE(ha))
4052 qla82xx_check_md_needed(vha);
4054 rval = qla2x00_get_fw_version(vha);
4055 if (rval != QLA_SUCCESS)
4057 ha->flags.npiv_supported = 0;
4058 if (IS_QLA2XXX_MIDTYPE(ha) &&
4059 (ha->fw_attributes & BIT_2)) {
4060 ha->flags.npiv_supported = 1;
4061 if ((!ha->max_npiv_vports) ||
4062 ((ha->max_npiv_vports + 1) %
4063 MIN_MULTI_ID_FABRIC))
4064 ha->max_npiv_vports =
4065 MIN_MULTI_ID_FABRIC - 1;
4067 qla2x00_get_resource_cnts(vha);
4068 qla_init_iocb_limit(vha);
4071 * Allocate the array of outstanding commands
4072 * now that we know the firmware resources.
4074 rval = qla2x00_alloc_outstanding_cmds(ha,
4076 if (rval != QLA_SUCCESS)
4079 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
4080 qla2x00_alloc_offload_mem(vha);
4082 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
4083 qla2x00_alloc_fw_dump(vha);
4089 ql_log(ql_log_fatal, vha, 0x00cd,
4090 "ISP Firmware failed checksum.\n");
4094 /* Enable PUREX PASSTHRU */
4095 if (ql2xrdpenable || ha->flags.scm_supported_f ||
4096 ha->flags.edif_enabled)
4097 qla25xx_set_els_cmds_supported(vha);
4101 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
4102 /* Enable proper parity. */
4103 spin_lock_irqsave(&ha->hardware_lock, flags);
4106 wrt_reg_word(®->hccr, HCCR_ENABLE_PARITY + 0x1);
4108 /* SRAM, Instruction RAM and GP RAM parity */
4109 wrt_reg_word(®->hccr, HCCR_ENABLE_PARITY + 0x7);
4110 rd_reg_word(®->hccr);
4111 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4114 if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
4115 ha->flags.fac_supported = 1;
4116 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
4119 rval = qla81xx_fac_get_sector_size(vha, &size);
4120 if (rval == QLA_SUCCESS) {
4121 ha->flags.fac_supported = 1;
4122 ha->fdt_block_size = size << 2;
4124 ql_log(ql_log_warn, vha, 0x00ce,
4125 "Unsupported FAC firmware (%d.%02d.%02d).\n",
4126 ha->fw_major_version, ha->fw_minor_version,
4127 ha->fw_subminor_version);
4129 if (IS_QLA83XX(ha)) {
4130 ha->flags.fac_supported = 0;
4137 ql_log(ql_log_fatal, vha, 0x00cf,
4138 "Setup chip ****FAILED****.\n");
4145 * qla2x00_init_response_q_entries() - Initializes response queue entries.
4146 * @rsp: response queue
4148 * Beginning of request ring has initialization control block already built
4149 * by nvram config routine.
4151 * Returns 0 on success.
4154 qla2x00_init_response_q_entries(struct rsp_que *rsp)
4159 rsp->ring_ptr = rsp->ring;
4160 rsp->ring_index = 0;
4161 rsp->status_srb = NULL;
4162 pkt = rsp->ring_ptr;
4163 for (cnt = 0; cnt < rsp->length; cnt++) {
4164 pkt->signature = RESPONSE_PROCESSED;
4170 * qla2x00_update_fw_options() - Read and process firmware options.
4173 * Returns 0 on success.
4176 qla2x00_update_fw_options(scsi_qla_host_t *vha)
4178 uint16_t swing, emphasis, tx_sens, rx_sens;
4179 struct qla_hw_data *ha = vha->hw;
4181 memset(ha->fw_options, 0, sizeof(ha->fw_options));
4182 qla2x00_get_fw_options(vha, ha->fw_options);
4184 if (IS_QLA2100(ha) || IS_QLA2200(ha))
4187 /* Serial Link options. */
4188 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
4189 "Serial link options.\n");
4190 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
4191 ha->fw_seriallink_options, sizeof(ha->fw_seriallink_options));
4193 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
4194 if (ha->fw_seriallink_options[3] & BIT_2) {
4195 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
4198 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
4199 emphasis = (ha->fw_seriallink_options[2] &
4200 (BIT_4 | BIT_3)) >> 3;
4201 tx_sens = ha->fw_seriallink_options[0] &
4202 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4203 rx_sens = (ha->fw_seriallink_options[0] &
4204 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
4205 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
4206 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
4209 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
4210 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
4211 ha->fw_options[10] |= BIT_5 |
4212 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
4213 (tx_sens & (BIT_1 | BIT_0));
4216 swing = (ha->fw_seriallink_options[2] &
4217 (BIT_7 | BIT_6 | BIT_5)) >> 5;
4218 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
4219 tx_sens = ha->fw_seriallink_options[1] &
4220 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4221 rx_sens = (ha->fw_seriallink_options[1] &
4222 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
4223 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
4224 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
4227 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
4228 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
4229 ha->fw_options[11] |= BIT_5 |
4230 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
4231 (tx_sens & (BIT_1 | BIT_0));
4235 /* Return command IOCBs without waiting for an ABTS to complete. */
4236 ha->fw_options[3] |= BIT_13;
4239 if (ha->flags.enable_led_scheme)
4240 ha->fw_options[2] |= BIT_12;
4242 /* Detect ISP6312. */
4244 ha->fw_options[2] |= BIT_13;
4246 /* Set Retry FLOGI in case of P2P connection */
4247 if (ha->operating_mode == P2P) {
4248 ha->fw_options[2] |= BIT_3;
4249 ql_dbg(ql_dbg_disc, vha, 0x2100,
4250 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
4251 __func__, ha->fw_options[2]);
4254 /* Update firmware options. */
4255 qla2x00_set_fw_options(vha, ha->fw_options);
4259 qla24xx_update_fw_options(scsi_qla_host_t *vha)
4262 struct qla_hw_data *ha = vha->hw;
4264 if (IS_P3P_TYPE(ha))
4267 /* Hold status IOCBs until ABTS response received. */
4269 ha->fw_options[3] |= BIT_12;
4271 /* Set Retry FLOGI in case of P2P connection */
4272 if (ha->operating_mode == P2P) {
4273 ha->fw_options[2] |= BIT_3;
4274 ql_dbg(ql_dbg_disc, vha, 0x2101,
4275 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
4276 __func__, ha->fw_options[2]);
4279 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
4280 if (ql2xmvasynctoatio && !ha->flags.edif_enabled &&
4281 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
4282 if (qla_tgt_mode_enabled(vha) ||
4283 qla_dual_mode_enabled(vha))
4284 ha->fw_options[2] |= BIT_11;
4286 ha->fw_options[2] &= ~BIT_11;
4289 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4292 * Tell FW to track each exchange to prevent
4293 * driver from using stale exchange.
4295 if (qla_tgt_mode_enabled(vha) ||
4296 qla_dual_mode_enabled(vha))
4297 ha->fw_options[2] |= BIT_4;
4299 ha->fw_options[2] &= ~(BIT_4);
4301 /* Reserve 1/2 of emergency exchanges for ELS.*/
4302 if (qla2xuseresexchforels)
4303 ha->fw_options[2] |= BIT_8;
4305 ha->fw_options[2] &= ~BIT_8;
4308 * N2N: set Secure=1 for PLOGI ACC and
4309 * fw shal not send PRLI after PLOGI Acc
4311 if (ha->flags.edif_enabled &&
4312 DBELL_ACTIVE(vha)) {
4313 ha->fw_options[3] |= BIT_15;
4314 ha->flags.n2n_fw_acc_sec = 1;
4316 ha->fw_options[3] &= ~BIT_15;
4317 ha->flags.n2n_fw_acc_sec = 0;
4321 if (ql2xrdpenable || ha->flags.scm_supported_f ||
4322 ha->flags.edif_enabled)
4323 ha->fw_options[1] |= ADD_FO1_ENABLE_PUREX_IOCB;
4325 /* Enable Async 8130/8131 events -- transceiver insertion/removal */
4326 if (IS_BPM_RANGE_CAPABLE(ha))
4327 ha->fw_options[3] |= BIT_10;
4329 ql_dbg(ql_dbg_init, vha, 0x00e8,
4330 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
4331 __func__, ha->fw_options[1], ha->fw_options[2],
4332 ha->fw_options[3], vha->host->active_mode);
4334 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
4335 qla2x00_set_fw_options(vha, ha->fw_options);
4337 /* Update Serial Link options. */
4338 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
4341 rval = qla2x00_set_serdes_params(vha,
4342 le16_to_cpu(ha->fw_seriallink_options24[1]),
4343 le16_to_cpu(ha->fw_seriallink_options24[2]),
4344 le16_to_cpu(ha->fw_seriallink_options24[3]));
4345 if (rval != QLA_SUCCESS) {
4346 ql_log(ql_log_warn, vha, 0x0104,
4347 "Unable to update Serial Link options (%x).\n", rval);
4352 qla2x00_config_rings(struct scsi_qla_host *vha)
4354 struct qla_hw_data *ha = vha->hw;
4355 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4356 struct req_que *req = ha->req_q_map[0];
4357 struct rsp_que *rsp = ha->rsp_q_map[0];
4359 /* Setup ring parameters in initialization control block. */
4360 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
4361 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
4362 ha->init_cb->request_q_length = cpu_to_le16(req->length);
4363 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
4364 put_unaligned_le64(req->dma, &ha->init_cb->request_q_address);
4365 put_unaligned_le64(rsp->dma, &ha->init_cb->response_q_address);
4367 wrt_reg_word(ISP_REQ_Q_IN(ha, reg), 0);
4368 wrt_reg_word(ISP_REQ_Q_OUT(ha, reg), 0);
4369 wrt_reg_word(ISP_RSP_Q_IN(ha, reg), 0);
4370 wrt_reg_word(ISP_RSP_Q_OUT(ha, reg), 0);
4371 rd_reg_word(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
4375 qla24xx_config_rings(struct scsi_qla_host *vha)
4377 struct qla_hw_data *ha = vha->hw;
4378 device_reg_t *reg = ISP_QUE_REG(ha, 0);
4379 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
4380 struct qla_msix_entry *msix;
4381 struct init_cb_24xx *icb;
4383 struct req_que *req = ha->req_q_map[0];
4384 struct rsp_que *rsp = ha->rsp_q_map[0];
4386 /* Setup ring parameters in initialization control block. */
4387 icb = (struct init_cb_24xx *)ha->init_cb;
4388 icb->request_q_outpointer = cpu_to_le16(0);
4389 icb->response_q_inpointer = cpu_to_le16(0);
4390 icb->request_q_length = cpu_to_le16(req->length);
4391 icb->response_q_length = cpu_to_le16(rsp->length);
4392 put_unaligned_le64(req->dma, &icb->request_q_address);
4393 put_unaligned_le64(rsp->dma, &icb->response_q_address);
4395 /* Setup ATIO queue dma pointers for target mode */
4396 icb->atio_q_inpointer = cpu_to_le16(0);
4397 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
4398 put_unaligned_le64(ha->tgt.atio_dma, &icb->atio_q_address);
4400 if (IS_SHADOW_REG_CAPABLE(ha))
4401 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
4403 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4405 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
4406 icb->rid = cpu_to_le16(rid);
4407 if (ha->flags.msix_enabled) {
4408 msix = &ha->msix_entries[1];
4409 ql_dbg(ql_dbg_init, vha, 0x0019,
4410 "Registering vector 0x%x for base que.\n",
4412 icb->msix = cpu_to_le16(msix->entry);
4414 /* Use alternate PCI bus number */
4416 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
4417 /* Use alternate PCI devfn */
4419 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
4421 /* Use Disable MSIX Handshake mode for capable adapters */
4422 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
4423 (ha->flags.msix_enabled)) {
4424 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
4425 ha->flags.disable_msix_handshake = 1;
4426 ql_dbg(ql_dbg_init, vha, 0x00fe,
4427 "MSIX Handshake Disable Mode turned on.\n");
4429 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
4431 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
4433 wrt_reg_dword(®->isp25mq.req_q_in, 0);
4434 wrt_reg_dword(®->isp25mq.req_q_out, 0);
4435 wrt_reg_dword(®->isp25mq.rsp_q_in, 0);
4436 wrt_reg_dword(®->isp25mq.rsp_q_out, 0);
4438 wrt_reg_dword(®->isp24.req_q_in, 0);
4439 wrt_reg_dword(®->isp24.req_q_out, 0);
4440 wrt_reg_dword(®->isp24.rsp_q_in, 0);
4441 wrt_reg_dword(®->isp24.rsp_q_out, 0);
4444 qlt_24xx_config_rings(vha);
4446 /* If the user has configured the speed, set it here */
4447 if (ha->set_data_rate) {
4448 ql_dbg(ql_dbg_init, vha, 0x00fd,
4449 "Speed set by user : %s Gbps \n",
4450 qla2x00_get_link_speed_str(ha, ha->set_data_rate));
4451 icb->firmware_options_3 = cpu_to_le32(ha->set_data_rate << 13);
4455 rd_reg_word(&ioreg->hccr);
4459 * qla2x00_init_rings() - Initializes firmware.
4462 * Beginning of request ring has initialization control block already built
4463 * by nvram config routine.
4465 * Returns 0 on success.
4468 qla2x00_init_rings(scsi_qla_host_t *vha)
4471 unsigned long flags = 0;
4473 struct qla_hw_data *ha = vha->hw;
4474 struct req_que *req;
4475 struct rsp_que *rsp;
4476 struct mid_init_cb_24xx *mid_init_cb =
4477 (struct mid_init_cb_24xx *) ha->init_cb;
4479 spin_lock_irqsave(&ha->hardware_lock, flags);
4481 /* Clear outstanding commands array. */
4482 for (que = 0; que < ha->max_req_queues; que++) {
4483 req = ha->req_q_map[que];
4484 if (!req || !test_bit(que, ha->req_qid_map))
4486 req->out_ptr = (uint16_t *)(req->ring + req->length);
4488 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
4489 req->outstanding_cmds[cnt] = NULL;
4491 req->current_outstanding_cmd = 1;
4493 /* Initialize firmware. */
4494 req->ring_ptr = req->ring;
4495 req->ring_index = 0;
4496 req->cnt = req->length;
4499 for (que = 0; que < ha->max_rsp_queues; que++) {
4500 rsp = ha->rsp_q_map[que];
4501 if (!rsp || !test_bit(que, ha->rsp_qid_map))
4503 rsp->in_ptr = (uint16_t *)(rsp->ring + rsp->length);
4505 /* Initialize response queue entries */
4507 qlafx00_init_response_q_entries(rsp);
4509 qla2x00_init_response_q_entries(rsp);
4512 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
4513 ha->tgt.atio_ring_index = 0;
4514 /* Initialize ATIO queue entries */
4515 qlt_init_atio_q_entries(vha);
4517 ha->isp_ops->config_rings(vha);
4519 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4521 if (IS_QLAFX00(ha)) {
4522 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
4526 /* Update any ISP specific firmware options before initialization. */
4527 ha->isp_ops->update_fw_options(vha);
4529 ql_dbg(ql_dbg_init, vha, 0x00d1,
4530 "Issue init firmware FW opt 1-3= %08x %08x %08x.\n",
4531 le32_to_cpu(mid_init_cb->init_cb.firmware_options_1),
4532 le32_to_cpu(mid_init_cb->init_cb.firmware_options_2),
4533 le32_to_cpu(mid_init_cb->init_cb.firmware_options_3));
4535 if (ha->flags.npiv_supported) {
4536 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
4537 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
4538 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
4541 if (IS_FWI2_CAPABLE(ha)) {
4542 mid_init_cb->options = cpu_to_le16(BIT_1);
4543 mid_init_cb->init_cb.execution_throttle =
4544 cpu_to_le16(ha->cur_fw_xcb_count);
4545 ha->flags.dport_enabled =
4546 (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) &
4548 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
4549 (ha->flags.dport_enabled) ? "enabled" : "disabled");
4550 /* FA-WWPN Status */
4551 ha->flags.fawwpn_enabled =
4552 (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) &
4554 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
4555 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
4556 /* Init_cb will be reused for other command(s). Save a backup copy of port_name */
4557 memcpy(ha->port_name, ha->init_cb->port_name, WWN_SIZE);
4560 /* ELS pass through payload is limit by frame size. */
4561 if (ha->flags.edif_enabled)
4562 mid_init_cb->init_cb.frame_payload_size = cpu_to_le16(ELS_MAX_PAYLOAD);
4564 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
4567 ql_log(ql_log_fatal, vha, 0x00d2,
4568 "Init Firmware **** FAILED ****.\n");
4570 ql_dbg(ql_dbg_init, vha, 0x00d3,
4571 "Init Firmware -- success.\n");
4573 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0;
4580 * qla2x00_fw_ready() - Waits for firmware ready.
4583 * Returns 0 on success.
4586 qla2x00_fw_ready(scsi_qla_host_t *vha)
4589 unsigned long wtime, mtime, cs84xx_time;
4590 uint16_t min_wait; /* Minimum wait time if loop is down */
4591 uint16_t wait_time; /* Wait time if loop is coming ready */
4593 struct qla_hw_data *ha = vha->hw;
4595 if (IS_QLAFX00(vha->hw))
4596 return qlafx00_fw_ready(vha);
4598 /* Time to wait for loop down */
4599 if (IS_P3P_TYPE(ha))
4605 * Firmware should take at most one RATOV to login, plus 5 seconds for
4606 * our own processing.
4608 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
4609 wait_time = min_wait;
4612 /* Min wait time if loop down */
4613 mtime = jiffies + (min_wait * HZ);
4615 /* wait time before firmware ready */
4616 wtime = jiffies + (wait_time * HZ);
4618 /* Wait for ISP to finish LIP */
4619 if (!vha->flags.init_done)
4620 ql_log(ql_log_info, vha, 0x801e,
4621 "Waiting for LIP to complete.\n");
4624 memset(state, -1, sizeof(state));
4625 rval = qla2x00_get_firmware_state(vha, state);
4626 if (rval == QLA_SUCCESS) {
4627 if (state[0] < FSTATE_LOSS_OF_SYNC) {
4628 vha->device_flags &= ~DFLG_NO_CABLE;
4630 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
4631 ql_dbg(ql_dbg_taskm, vha, 0x801f,
4632 "fw_state=%x 84xx=%x.\n", state[0],
4634 if ((state[2] & FSTATE_LOGGED_IN) &&
4635 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
4636 ql_dbg(ql_dbg_taskm, vha, 0x8028,
4637 "Sending verify iocb.\n");
4639 cs84xx_time = jiffies;
4640 rval = qla84xx_init_chip(vha);
4641 if (rval != QLA_SUCCESS) {
4644 "Init chip failed.\n");
4648 /* Add time taken to initialize. */
4649 cs84xx_time = jiffies - cs84xx_time;
4650 wtime += cs84xx_time;
4651 mtime += cs84xx_time;
4652 ql_dbg(ql_dbg_taskm, vha, 0x8008,
4653 "Increasing wait time by %ld. "
4654 "New time %ld.\n", cs84xx_time,
4657 } else if (state[0] == FSTATE_READY) {
4658 ql_dbg(ql_dbg_taskm, vha, 0x8037,
4659 "F/W Ready - OK.\n");
4661 qla2x00_get_retry_cnt(vha, &ha->retry_count,
4662 &ha->login_timeout, &ha->r_a_tov);
4668 rval = QLA_FUNCTION_FAILED;
4670 if (atomic_read(&vha->loop_down_timer) &&
4671 state[0] != FSTATE_READY) {
4672 /* Loop down. Timeout on min_wait for states
4673 * other than Wait for Login.
4675 if (time_after_eq(jiffies, mtime)) {
4676 ql_log(ql_log_info, vha, 0x8038,
4677 "Cable is unplugged...\n");
4679 vha->device_flags |= DFLG_NO_CABLE;
4684 /* Mailbox cmd failed. Timeout on min_wait. */
4685 if (time_after_eq(jiffies, mtime) ||
4686 ha->flags.isp82xx_fw_hung)
4690 if (time_after_eq(jiffies, wtime))
4693 /* Delay for a while */
4697 ql_dbg(ql_dbg_taskm, vha, 0x803a,
4698 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
4699 state[1], state[2], state[3], state[4], state[5], jiffies);
4701 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
4702 ql_log(ql_log_warn, vha, 0x803b,
4703 "Firmware ready **** FAILED ****.\n");
4710 * qla2x00_configure_hba
4711 * Setup adapter context.
4714 * ha = adapter state pointer.
4723 qla2x00_configure_hba(scsi_qla_host_t *vha)
4732 char connect_type[22];
4733 struct qla_hw_data *ha = vha->hw;
4734 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4736 unsigned long flags;
4738 /* Get host addresses. */
4739 rval = qla2x00_get_adapter_id(vha,
4740 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
4741 if (rval != QLA_SUCCESS) {
4742 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
4743 IS_CNA_CAPABLE(ha) ||
4744 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
4745 ql_dbg(ql_dbg_disc, vha, 0x2008,
4746 "Loop is in a transition state.\n");
4748 ql_log(ql_log_warn, vha, 0x2009,
4749 "Unable to get host loop ID.\n");
4750 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
4751 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
4752 ql_log(ql_log_warn, vha, 0x1151,
4753 "Doing link init.\n");
4754 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
4757 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4763 ql_log(ql_log_info, vha, 0x200a,
4764 "Cannot get topology - retrying.\n");
4765 return (QLA_FUNCTION_FAILED);
4768 vha->loop_id = loop_id;
4771 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
4772 ha->operating_mode = LOOP;
4776 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
4778 ha->current_topology = ISP_CFG_NL;
4779 strcpy(connect_type, "(Loop)");
4783 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
4784 ha->switch_cap = sw_cap;
4785 ha->current_topology = ISP_CFG_FL;
4786 strcpy(connect_type, "(FL_Port)");
4790 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
4792 ha->operating_mode = P2P;
4793 ha->current_topology = ISP_CFG_N;
4794 strcpy(connect_type, "(N_Port-to-N_Port)");
4798 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
4799 ha->switch_cap = sw_cap;
4800 ha->operating_mode = P2P;
4801 ha->current_topology = ISP_CFG_F;
4802 strcpy(connect_type, "(F_Port)");
4806 ql_dbg(ql_dbg_disc, vha, 0x200f,
4807 "HBA in unknown topology %x, using NL.\n", topo);
4809 ha->current_topology = ISP_CFG_NL;
4810 strcpy(connect_type, "(Loop)");
4814 /* Save Host port and loop ID. */
4815 /* byte order - Big Endian */
4816 id.b.domain = domain;
4820 spin_lock_irqsave(&ha->hardware_lock, flags);
4821 if (vha->hw->flags.edif_enabled) {
4823 qla_update_host_map(vha, id);
4824 } else if (!(topo == 2 && ha->flags.n2n_bigger))
4825 qla_update_host_map(vha, id);
4826 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4828 if (!vha->flags.init_done)
4829 ql_log(ql_log_info, vha, 0x2010,
4830 "Topology - %s, Host Loop address 0x%x.\n",
4831 connect_type, vha->loop_id);
4837 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
4842 uint64_t zero[2] = { 0 };
4843 struct qla_hw_data *ha = vha->hw;
4844 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
4845 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
4847 if (len > sizeof(zero))
4849 if (memcmp(model, &zero, len) != 0) {
4850 memcpy(ha->model_number, model, len);
4851 st = en = ha->model_number;
4854 if (*en != 0x20 && *en != 0x00)
4859 index = (ha->pdev->subsystem_device & 0xff);
4861 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4862 index < QLA_MODEL_NAMES)
4863 strlcpy(ha->model_desc,
4864 qla2x00_model_name[index * 2 + 1],
4865 sizeof(ha->model_desc));
4867 index = (ha->pdev->subsystem_device & 0xff);
4869 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4870 index < QLA_MODEL_NAMES) {
4871 strlcpy(ha->model_number,
4872 qla2x00_model_name[index * 2],
4873 sizeof(ha->model_number));
4874 strlcpy(ha->model_desc,
4875 qla2x00_model_name[index * 2 + 1],
4876 sizeof(ha->model_desc));
4878 strlcpy(ha->model_number, def,
4879 sizeof(ha->model_number));
4882 if (IS_FWI2_CAPABLE(ha))
4883 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
4884 sizeof(ha->model_desc));
4887 /* On sparc systems, obtain port and node WWN from firmware
4890 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4893 struct qla_hw_data *ha = vha->hw;
4894 struct pci_dev *pdev = ha->pdev;
4895 struct device_node *dp = pci_device_to_OF_node(pdev);
4899 val = of_get_property(dp, "port-wwn", &len);
4900 if (val && len >= WWN_SIZE)
4901 memcpy(nv->port_name, val, WWN_SIZE);
4903 val = of_get_property(dp, "node-wwn", &len);
4904 if (val && len >= WWN_SIZE)
4905 memcpy(nv->node_name, val, WWN_SIZE);
4910 * NVRAM configuration for ISP 2xxx
4913 * ha = adapter block pointer.
4916 * initialization control block in response_ring
4917 * host adapters parameters in host adapter block
4923 qla2x00_nvram_config(scsi_qla_host_t *vha)
4928 uint8_t *dptr1, *dptr2;
4929 struct qla_hw_data *ha = vha->hw;
4930 init_cb_t *icb = ha->init_cb;
4931 nvram_t *nv = ha->nvram;
4932 uint8_t *ptr = ha->nvram;
4933 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4937 /* Determine NVRAM starting address. */
4938 ha->nvram_size = sizeof(*nv);
4940 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4941 if ((rd_reg_word(®->ctrl_status) >> 14) == 1)
4942 ha->nvram_base = 0x80;
4944 /* Get NVRAM data and calculate checksum. */
4945 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
4946 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4949 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4950 "Contents of NVRAM.\n");
4951 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4952 nv, ha->nvram_size);
4954 /* Bad NVRAM data, set defaults parameters. */
4955 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
4956 nv->nvram_version < 1) {
4957 /* Reset NVRAM data. */
4958 ql_log(ql_log_warn, vha, 0x0064,
4959 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
4960 chksum, nv->id, nv->nvram_version);
4961 ql_log(ql_log_warn, vha, 0x0065,
4963 "functioning (yet invalid -- WWPN) defaults.\n");
4966 * Set default initialization control block.
4968 memset(nv, 0, ha->nvram_size);
4969 nv->parameter_block_version = ICB_VERSION;
4971 if (IS_QLA23XX(ha)) {
4972 nv->firmware_options[0] = BIT_2 | BIT_1;
4973 nv->firmware_options[1] = BIT_7 | BIT_5;
4974 nv->add_firmware_options[0] = BIT_5;
4975 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4976 nv->frame_payload_size = cpu_to_le16(2048);
4977 nv->special_options[1] = BIT_7;
4978 } else if (IS_QLA2200(ha)) {
4979 nv->firmware_options[0] = BIT_2 | BIT_1;
4980 nv->firmware_options[1] = BIT_7 | BIT_5;
4981 nv->add_firmware_options[0] = BIT_5;
4982 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4983 nv->frame_payload_size = cpu_to_le16(1024);
4984 } else if (IS_QLA2100(ha)) {
4985 nv->firmware_options[0] = BIT_3 | BIT_1;
4986 nv->firmware_options[1] = BIT_5;
4987 nv->frame_payload_size = cpu_to_le16(1024);
4990 nv->max_iocb_allocation = cpu_to_le16(256);
4991 nv->execution_throttle = cpu_to_le16(16);
4992 nv->retry_count = 8;
4993 nv->retry_delay = 1;
4995 nv->port_name[0] = 33;
4996 nv->port_name[3] = 224;
4997 nv->port_name[4] = 139;
4999 qla2xxx_nvram_wwn_from_ofw(vha, nv);
5001 nv->login_timeout = 4;
5004 * Set default host adapter parameters
5006 nv->host_p[1] = BIT_2;
5007 nv->reset_delay = 5;
5008 nv->port_down_retry_count = 8;
5009 nv->max_luns_per_target = cpu_to_le16(8);
5010 nv->link_down_timeout = 60;
5015 /* Reset Initialization control block */
5016 memset(icb, 0, ha->init_cb_size);
5019 * Setup driver NVRAM options.
5021 nv->firmware_options[0] |= (BIT_6 | BIT_1);
5022 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
5023 nv->firmware_options[1] |= (BIT_5 | BIT_0);
5024 nv->firmware_options[1] &= ~BIT_4;
5026 if (IS_QLA23XX(ha)) {
5027 nv->firmware_options[0] |= BIT_2;
5028 nv->firmware_options[0] &= ~BIT_3;
5029 nv->special_options[0] &= ~BIT_6;
5030 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
5032 if (IS_QLA2300(ha)) {
5033 if (ha->fb_rev == FPM_2310) {
5034 strcpy(ha->model_number, "QLA2310");
5036 strcpy(ha->model_number, "QLA2300");
5039 qla2x00_set_model_info(vha, nv->model_number,
5040 sizeof(nv->model_number), "QLA23xx");
5042 } else if (IS_QLA2200(ha)) {
5043 nv->firmware_options[0] |= BIT_2;
5045 * 'Point-to-point preferred, else loop' is not a safe
5046 * connection mode setting.
5048 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
5050 /* Force 'loop preferred, else point-to-point'. */
5051 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
5052 nv->add_firmware_options[0] |= BIT_5;
5054 strcpy(ha->model_number, "QLA22xx");
5055 } else /*if (IS_QLA2100(ha))*/ {
5056 strcpy(ha->model_number, "QLA2100");
5060 * Copy over NVRAM RISC parameter block to initialization control block.
5062 dptr1 = (uint8_t *)icb;
5063 dptr2 = (uint8_t *)&nv->parameter_block_version;
5064 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
5066 *dptr1++ = *dptr2++;
5068 /* Copy 2nd half. */
5069 dptr1 = (uint8_t *)icb->add_firmware_options;
5070 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
5072 *dptr1++ = *dptr2++;
5073 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
5074 /* Use alternate WWN? */
5075 if (nv->host_p[1] & BIT_7) {
5076 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5077 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5080 /* Prepare nodename */
5081 if ((icb->firmware_options[1] & BIT_6) == 0) {
5083 * Firmware will apply the following mask if the nodename was
5086 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5087 icb->node_name[0] &= 0xF0;
5091 * Set host adapter parameters.
5095 * BIT_7 in the host-parameters section allows for modification to
5096 * internal driver logging.
5098 if (nv->host_p[0] & BIT_7)
5099 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
5100 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
5101 /* Always load RISC code on non ISP2[12]00 chips. */
5102 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
5103 ha->flags.disable_risc_code_load = 0;
5104 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
5105 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
5106 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
5107 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
5108 ha->flags.disable_serdes = 0;
5110 ha->operating_mode =
5111 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
5113 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
5114 sizeof(ha->fw_seriallink_options));
5116 /* save HBA serial number */
5117 ha->serial0 = icb->port_name[5];
5118 ha->serial1 = icb->port_name[6];
5119 ha->serial2 = icb->port_name[7];
5120 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5121 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5123 icb->execution_throttle = cpu_to_le16(0xFFFF);
5125 ha->retry_count = nv->retry_count;
5127 /* Set minimum login_timeout to 4 seconds. */
5128 if (nv->login_timeout != ql2xlogintimeout)
5129 nv->login_timeout = ql2xlogintimeout;
5130 if (nv->login_timeout < 4)
5131 nv->login_timeout = 4;
5132 ha->login_timeout = nv->login_timeout;
5134 /* Set minimum RATOV to 100 tenths of a second. */
5137 ha->loop_reset_delay = nv->reset_delay;
5139 /* Link Down Timeout = 0:
5141 * When Port Down timer expires we will start returning
5142 * I/O's to OS with "DID_NO_CONNECT".
5144 * Link Down Timeout != 0:
5146 * The driver waits for the link to come up after link down
5147 * before returning I/Os to OS with "DID_NO_CONNECT".
5149 if (nv->link_down_timeout == 0) {
5150 ha->loop_down_abort_time =
5151 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5153 ha->link_down_timeout = nv->link_down_timeout;
5154 ha->loop_down_abort_time =
5155 (LOOP_DOWN_TIME - ha->link_down_timeout);
5159 * Need enough time to try and get the port back.
5161 ha->port_down_retry_count = nv->port_down_retry_count;
5162 if (qlport_down_retry)
5163 ha->port_down_retry_count = qlport_down_retry;
5164 /* Set login_retry_count */
5165 ha->login_retry_count = nv->retry_count;
5166 if (ha->port_down_retry_count == nv->port_down_retry_count &&
5167 ha->port_down_retry_count > 3)
5168 ha->login_retry_count = ha->port_down_retry_count;
5169 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5170 ha->login_retry_count = ha->port_down_retry_count;
5171 if (ql2xloginretrycount)
5172 ha->login_retry_count = ql2xloginretrycount;
5174 icb->lun_enables = cpu_to_le16(0);
5175 icb->command_resource_count = 0;
5176 icb->immediate_notify_resource_count = 0;
5177 icb->timeout = cpu_to_le16(0);
5179 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
5181 icb->firmware_options[0] &= ~BIT_3;
5182 icb->add_firmware_options[0] &=
5183 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
5184 icb->add_firmware_options[0] |= BIT_2;
5185 icb->response_accumulation_timer = 3;
5186 icb->interrupt_delay_timer = 5;
5188 vha->flags.process_response_queue = 1;
5191 if (!vha->flags.init_done) {
5192 ha->zio_mode = icb->add_firmware_options[0] &
5193 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5194 ha->zio_timer = icb->interrupt_delay_timer ?
5195 icb->interrupt_delay_timer : 2;
5197 icb->add_firmware_options[0] &=
5198 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
5199 vha->flags.process_response_queue = 0;
5200 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5201 ha->zio_mode = QLA_ZIO_MODE_6;
5203 ql_log(ql_log_info, vha, 0x0068,
5204 "ZIO mode %d enabled; timer delay (%d us).\n",
5205 ha->zio_mode, ha->zio_timer * 100);
5207 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
5208 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
5209 vha->flags.process_response_queue = 1;
5214 ql_log(ql_log_warn, vha, 0x0069,
5215 "NVRAM configuration failed.\n");
5220 void qla2x00_set_fcport_state(fc_port_t *fcport, int state)
5224 old_state = atomic_read(&fcport->state);
5225 atomic_set(&fcport->state, state);
5227 /* Don't print state transitions during initial allocation of fcport */
5228 if (old_state && old_state != state) {
5229 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
5230 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
5231 fcport->port_name, port_state_str[old_state],
5232 port_state_str[state], fcport->d_id.b.domain,
5233 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5238 * qla2x00_alloc_fcport() - Allocate a generic fcport.
5240 * @flags: allocation flags
5242 * Returns a pointer to the allocated fcport, or NULL, if none available.
5245 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
5249 fcport = kzalloc(sizeof(fc_port_t), flags);
5253 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
5254 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
5256 if (!fcport->ct_desc.ct_sns) {
5257 ql_log(ql_log_warn, vha, 0xd049,
5258 "Failed to allocate ct_sns request.\n");
5263 /* Setup fcport template structure. */
5265 fcport->port_type = FCT_UNKNOWN;
5266 fcport->loop_id = FC_NO_LOOP_ID;
5267 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
5268 fcport->supported_classes = FC_COS_UNSPECIFIED;
5269 fcport->fp_speed = PORT_SPEED_UNKNOWN;
5271 fcport->disc_state = DSC_DELETED;
5272 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
5273 fcport->deleted = QLA_SESS_DELETED;
5274 fcport->login_retry = vha->hw->login_retry_count;
5275 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
5276 fcport->logout_on_delete = 1;
5277 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
5278 fcport->tgt_short_link_down_cnt = 0;
5279 fcport->dev_loss_tmo = 0;
5281 if (!fcport->ct_desc.ct_sns) {
5282 ql_log(ql_log_warn, vha, 0xd049,
5283 "Failed to allocate ct_sns request.\n");
5288 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
5289 INIT_WORK(&fcport->free_work, qlt_free_session_done);
5290 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
5291 INIT_LIST_HEAD(&fcport->gnl_entry);
5292 INIT_LIST_HEAD(&fcport->list);
5294 INIT_LIST_HEAD(&fcport->sess_cmd_list);
5295 spin_lock_init(&fcport->sess_cmd_lock);
5297 spin_lock_init(&fcport->edif.sa_list_lock);
5298 INIT_LIST_HEAD(&fcport->edif.tx_sa_list);
5299 INIT_LIST_HEAD(&fcport->edif.rx_sa_list);
5301 spin_lock_init(&fcport->edif.indx_list_lock);
5302 INIT_LIST_HEAD(&fcport->edif.edif_indx_list);
5308 qla2x00_free_fcport(fc_port_t *fcport)
5310 if (fcport->ct_desc.ct_sns) {
5311 dma_free_coherent(&fcport->vha->hw->pdev->dev,
5312 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
5313 fcport->ct_desc.ct_sns_dma);
5315 fcport->ct_desc.ct_sns = NULL;
5318 qla_edif_flush_sa_ctl_lists(fcport);
5319 list_del(&fcport->list);
5320 qla2x00_clear_loop_id(fcport);
5322 qla_edif_list_del(fcport);
5327 static void qla_get_login_template(scsi_qla_host_t *vha)
5329 struct qla_hw_data *ha = vha->hw;
5334 memset(ha->init_cb, 0, ha->init_cb_size);
5335 sz = min_t(int, sizeof(struct fc_els_flogi), ha->init_cb_size);
5336 rval = qla24xx_get_port_login_templ(vha, ha->init_cb_dma,
5338 if (rval != QLA_SUCCESS) {
5339 ql_dbg(ql_dbg_init, vha, 0x00d1,
5340 "PLOGI ELS param read fail.\n");
5343 q = (__be32 *)&ha->plogi_els_payld.fl_csp;
5345 bp = (uint32_t *)ha->init_cb;
5346 cpu_to_be32_array(q, bp, sz / 4);
5347 ha->flags.plogi_template_valid = 1;
5351 * qla2x00_configure_loop
5352 * Updates Fibre Channel Device Database with what is actually on loop.
5355 * ha = adapter block pointer.
5360 * 2 = database was full and device was not configured.
5363 qla2x00_configure_loop(scsi_qla_host_t *vha)
5366 unsigned long flags, save_flags;
5367 struct qla_hw_data *ha = vha->hw;
5371 /* Get Initiator ID */
5372 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
5373 rval = qla2x00_configure_hba(vha);
5374 if (rval != QLA_SUCCESS) {
5375 ql_dbg(ql_dbg_disc, vha, 0x2013,
5376 "Unable to configure HBA.\n");
5381 save_flags = flags = vha->dpc_flags;
5382 ql_dbg(ql_dbg_disc, vha, 0x2014,
5383 "Configure loop -- dpc flags = 0x%lx.\n", flags);
5386 * If we have both an RSCN and PORT UPDATE pending then handle them
5387 * both at the same time.
5389 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5390 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
5392 qla2x00_get_data_rate(vha);
5393 qla_get_login_template(vha);
5395 /* Determine what we need to do */
5396 if ((ha->current_topology == ISP_CFG_FL ||
5397 ha->current_topology == ISP_CFG_F) &&
5398 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
5400 set_bit(RSCN_UPDATE, &flags);
5401 clear_bit(LOCAL_LOOP_UPDATE, &flags);
5403 } else if (ha->current_topology == ISP_CFG_NL ||
5404 ha->current_topology == ISP_CFG_N) {
5405 clear_bit(RSCN_UPDATE, &flags);
5406 set_bit(LOCAL_LOOP_UPDATE, &flags);
5407 } else if (!vha->flags.online ||
5408 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
5409 set_bit(RSCN_UPDATE, &flags);
5410 set_bit(LOCAL_LOOP_UPDATE, &flags);
5413 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
5414 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5415 ql_dbg(ql_dbg_disc, vha, 0x2015,
5416 "Loop resync needed, failing.\n");
5417 rval = QLA_FUNCTION_FAILED;
5419 rval = qla2x00_configure_local_loop(vha);
5422 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
5423 if (LOOP_TRANSITION(vha)) {
5424 ql_dbg(ql_dbg_disc, vha, 0x2099,
5425 "Needs RSCN update and loop transition.\n");
5426 rval = QLA_FUNCTION_FAILED;
5429 rval = qla2x00_configure_fabric(vha);
5432 if (rval == QLA_SUCCESS) {
5433 if (atomic_read(&vha->loop_down_timer) ||
5434 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5435 rval = QLA_FUNCTION_FAILED;
5437 atomic_set(&vha->loop_state, LOOP_READY);
5438 ql_dbg(ql_dbg_disc, vha, 0x2069,
5440 ha->flags.fw_init_done = 1;
5443 * use link up to wake up app to get ready for
5446 if (ha->flags.edif_enabled && DBELL_INACTIVE(vha))
5447 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP,
5448 ha->link_data_rate);
5451 * Process any ATIO queue entries that came in
5452 * while we weren't online.
5454 if (qla_tgt_mode_enabled(vha) ||
5455 qla_dual_mode_enabled(vha)) {
5456 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
5457 qlt_24xx_process_atio_queue(vha, 0);
5458 spin_unlock_irqrestore(&ha->tgt.atio_lock,
5465 ql_dbg(ql_dbg_disc, vha, 0x206a,
5466 "%s *** FAILED ***.\n", __func__);
5468 ql_dbg(ql_dbg_disc, vha, 0x206b,
5469 "%s: exiting normally. local port wwpn %8phN id %06x)\n",
5470 __func__, vha->port_name, vha->d_id.b24);
5473 /* Restore state if a resync event occurred during processing */
5474 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5475 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
5476 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5477 if (test_bit(RSCN_UPDATE, &save_flags)) {
5478 set_bit(RSCN_UPDATE, &vha->dpc_flags);
5485 static int qla2x00_configure_n2n_loop(scsi_qla_host_t *vha)
5487 unsigned long flags;
5490 ql_dbg(ql_dbg_disc, vha, 0x206a, "%s %d.\n", __func__, __LINE__);
5492 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags))
5493 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5495 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5496 if (fcport->n2n_flag) {
5497 qla24xx_fcport_handle_login(vha, fcport);
5502 spin_lock_irqsave(&vha->work_lock, flags);
5503 vha->scan.scan_retry++;
5504 spin_unlock_irqrestore(&vha->work_lock, flags);
5506 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5507 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5508 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5510 return QLA_FUNCTION_FAILED;
5514 qla_reinitialize_link(scsi_qla_host_t *vha)
5518 atomic_set(&vha->loop_state, LOOP_DOWN);
5519 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
5520 rval = qla2x00_full_login_lip(vha);
5521 if (rval == QLA_SUCCESS) {
5522 ql_dbg(ql_dbg_disc, vha, 0xd050, "Link reinitialized\n");
5524 ql_dbg(ql_dbg_disc, vha, 0xd051,
5525 "Link reinitialization failed (%d)\n", rval);
5530 * qla2x00_configure_local_loop
5531 * Updates Fibre Channel Device Database with local loop devices.
5534 * ha = adapter block pointer.
5540 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
5544 fc_port_t *fcport, *new_fcport;
5547 struct gid_list_info *gid;
5549 uint8_t domain, area, al_pa;
5550 struct qla_hw_data *ha = vha->hw;
5551 unsigned long flags;
5553 /* Inititae N2N login. */
5555 return qla2x00_configure_n2n_loop(vha);
5558 entries = MAX_FIBRE_DEVICES_LOOP;
5560 /* Get list of logged in devices. */
5561 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
5562 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
5564 if (rval != QLA_SUCCESS)
5567 ql_dbg(ql_dbg_disc, vha, 0x2011,
5568 "Entries in ID list (%d).\n", entries);
5569 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
5570 ha->gid_list, entries * sizeof(*ha->gid_list));
5573 spin_lock_irqsave(&vha->work_lock, flags);
5574 vha->scan.scan_retry++;
5575 spin_unlock_irqrestore(&vha->work_lock, flags);
5577 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5578 u8 loop_map_entries = 0;
5581 rc = qla2x00_get_fcal_position_map(vha, NULL,
5583 if (rc == QLA_SUCCESS && loop_map_entries > 1) {
5585 * There are devices that are still not logged
5586 * in. Reinitialize to give them a chance.
5588 qla_reinitialize_link(vha);
5589 return QLA_FUNCTION_FAILED;
5591 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5592 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5595 vha->scan.scan_retry = 0;
5598 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5599 fcport->scan_state = QLA_FCPORT_SCAN;
5602 /* Allocate temporary fcport for any new fcports discovered. */
5603 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5604 if (new_fcport == NULL) {
5605 ql_log(ql_log_warn, vha, 0x2012,
5606 "Memory allocation failed for fcport.\n");
5607 rval = QLA_MEMORY_ALLOC_FAILED;
5610 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5612 /* Add devices to port list. */
5614 for (index = 0; index < entries; index++) {
5615 domain = gid->domain;
5618 if (IS_QLA2100(ha) || IS_QLA2200(ha))
5619 loop_id = gid->loop_id_2100;
5621 loop_id = le16_to_cpu(gid->loop_id);
5622 gid = (void *)gid + ha->gid_list_info_size;
5624 /* Bypass reserved domain fields. */
5625 if ((domain & 0xf0) == 0xf0)
5628 /* Bypass if not same domain and area of adapter. */
5629 if (area && domain && ((area != vha->d_id.b.area) ||
5630 (domain != vha->d_id.b.domain)) &&
5631 (ha->current_topology == ISP_CFG_NL))
5635 /* Bypass invalid local loop ID. */
5636 if (loop_id > LAST_LOCAL_LOOP_ID)
5639 memset(new_fcport->port_name, 0, WWN_SIZE);
5641 /* Fill in member data. */
5642 new_fcport->d_id.b.domain = domain;
5643 new_fcport->d_id.b.area = area;
5644 new_fcport->d_id.b.al_pa = al_pa;
5645 new_fcport->loop_id = loop_id;
5646 new_fcport->scan_state = QLA_FCPORT_FOUND;
5648 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
5649 if (rval2 != QLA_SUCCESS) {
5650 ql_dbg(ql_dbg_disc, vha, 0x2097,
5651 "Failed to retrieve fcport information "
5652 "-- get_port_database=%x, loop_id=0x%04x.\n",
5653 rval2, new_fcport->loop_id);
5654 /* Skip retry if N2N */
5655 if (ha->current_topology != ISP_CFG_N) {
5656 ql_dbg(ql_dbg_disc, vha, 0x2105,
5657 "Scheduling resync.\n");
5658 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5663 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5664 /* Check for matching device in port list. */
5667 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5668 if (memcmp(new_fcport->port_name, fcport->port_name,
5672 fcport->flags &= ~FCF_FABRIC_DEVICE;
5673 fcport->loop_id = new_fcport->loop_id;
5674 fcport->port_type = new_fcport->port_type;
5675 fcport->d_id.b24 = new_fcport->d_id.b24;
5676 memcpy(fcport->node_name, new_fcport->node_name,
5678 fcport->scan_state = QLA_FCPORT_FOUND;
5679 if (fcport->login_retry == 0) {
5680 fcport->login_retry = vha->hw->login_retry_count;
5681 ql_dbg(ql_dbg_disc, vha, 0x2135,
5682 "Port login retry %8phN, lid 0x%04x retry cnt=%d.\n",
5683 fcport->port_name, fcport->loop_id,
5684 fcport->login_retry);
5691 /* New device, add to fcports list. */
5692 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5694 /* Allocate a new replacement fcport. */
5695 fcport = new_fcport;
5697 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5699 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5701 if (new_fcport == NULL) {
5702 ql_log(ql_log_warn, vha, 0xd031,
5703 "Failed to allocate memory for fcport.\n");
5704 rval = QLA_MEMORY_ALLOC_FAILED;
5707 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5708 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5711 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5713 /* Base iIDMA settings on HBA port speed. */
5714 fcport->fp_speed = ha->link_data_rate;
5717 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5718 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5721 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5722 if ((qla_dual_mode_enabled(vha) ||
5723 qla_ini_mode_enabled(vha)) &&
5724 atomic_read(&fcport->state) == FCS_ONLINE) {
5725 qla2x00_mark_device_lost(vha, fcport,
5726 ql2xplogiabsentdevice);
5727 if (fcport->loop_id != FC_NO_LOOP_ID &&
5728 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5729 fcport->port_type != FCT_INITIATOR &&
5730 fcport->port_type != FCT_BROADCAST) {
5731 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5732 "%s %d %8phC post del sess\n",
5736 qlt_schedule_sess_for_deletion(fcport);
5742 if (fcport->scan_state == QLA_FCPORT_FOUND)
5743 qla24xx_fcport_handle_login(vha, fcport);
5746 qla2x00_free_fcport(new_fcport);
5751 ql_dbg(ql_dbg_disc, vha, 0x2098,
5752 "Configure local loop error exit: rval=%x.\n", rval);
5757 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5760 uint16_t mb[MAILBOX_REGISTER_COUNT];
5761 struct qla_hw_data *ha = vha->hw;
5763 if (!IS_IIDMA_CAPABLE(ha))
5766 if (atomic_read(&fcport->state) != FCS_ONLINE)
5769 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
5770 fcport->fp_speed > ha->link_data_rate ||
5771 !ha->flags.gpsc_supported)
5774 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
5776 if (rval != QLA_SUCCESS) {
5777 ql_dbg(ql_dbg_disc, vha, 0x2004,
5778 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5779 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
5781 ql_dbg(ql_dbg_disc, vha, 0x2005,
5782 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5783 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
5784 fcport->fp_speed, fcport->port_name);
5788 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5790 qla2x00_iidma_fcport(vha, fcport);
5791 qla24xx_update_fcport_fcp_prio(vha, fcport);
5794 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5796 struct qla_work_evt *e;
5798 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
5800 return QLA_FUNCTION_FAILED;
5802 e->u.fcport.fcport = fcport;
5803 return qla2x00_post_work(vha, e);
5806 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5808 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
5810 struct fc_rport_identifiers rport_ids;
5811 struct fc_rport *rport;
5812 unsigned long flags;
5814 if (atomic_read(&fcport->state) == FCS_ONLINE)
5817 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5818 rport_ids.port_name = wwn_to_u64(fcport->port_name);
5819 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5820 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5821 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5822 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
5824 ql_log(ql_log_warn, vha, 0x2006,
5825 "Unable to allocate fc remote port.\n");
5829 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5830 *((fc_port_t **)rport->dd_data) = fcport;
5831 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5832 fcport->dev_loss_tmo = rport->dev_loss_tmo;
5834 rport->supported_classes = fcport->supported_classes;
5836 rport_ids.roles = FC_PORT_ROLE_UNKNOWN;
5837 if (fcport->port_type == FCT_INITIATOR)
5838 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
5839 if (fcport->port_type == FCT_TARGET)
5840 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
5841 if (fcport->port_type & FCT_NVME_INITIATOR)
5842 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
5843 if (fcport->port_type & FCT_NVME_TARGET)
5844 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
5845 if (fcport->port_type & FCT_NVME_DISCOVERY)
5846 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
5848 fc_remote_port_rolechg(rport, rport_ids.roles);
5850 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5851 "%s: %8phN. rport %ld:0:%d (%p) is %s mode\n",
5852 __func__, fcport->port_name, vha->host_no,
5853 rport->scsi_target_id, rport,
5854 (fcport->port_type == FCT_TARGET) ? "tgt" :
5855 ((fcport->port_type & FCT_NVME) ? "nvme" : "ini"));
5859 * qla2x00_update_fcport
5860 * Updates device on list.
5863 * ha = adapter block pointer.
5864 * fcport = port structure pointer.
5874 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5876 if (IS_SW_RESV_ADDR(fcport->d_id))
5879 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
5880 __func__, fcport->port_name);
5882 qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT);
5883 fcport->login_retry = vha->hw->login_retry_count;
5884 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5885 fcport->deleted = 0;
5886 if (vha->hw->current_topology == ISP_CFG_NL)
5887 fcport->logout_on_delete = 0;
5889 fcport->logout_on_delete = 1;
5890 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
5892 if (fcport->tgt_link_down_time < fcport->dev_loss_tmo) {
5893 fcport->tgt_short_link_down_cnt++;
5894 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
5897 switch (vha->hw->current_topology) {
5900 fcport->keep_nport_handle = 1;
5906 qla2x00_iidma_fcport(vha, fcport);
5908 qla2x00_dfs_create_rport(vha, fcport);
5910 qla24xx_update_fcport_fcp_prio(vha, fcport);
5912 switch (vha->host->active_mode) {
5913 case MODE_INITIATOR:
5914 qla2x00_reg_remote_port(vha, fcport);
5917 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5918 !vha->vha_tgt.qla_tgt->tgt_stopped)
5919 qlt_fc_port_added(vha, fcport);
5922 qla2x00_reg_remote_port(vha, fcport);
5923 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5924 !vha->vha_tgt.qla_tgt->tgt_stopped)
5925 qlt_fc_port_added(vha, fcport);
5931 if (NVME_TARGET(vha->hw, fcport))
5932 qla_nvme_register_remote(vha, fcport);
5934 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5936 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
5937 if (fcport->id_changed) {
5938 fcport->id_changed = 0;
5939 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5940 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5941 __func__, __LINE__, fcport->port_name,
5943 qla24xx_post_gfpnid_work(vha, fcport);
5945 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5946 "%s %d %8phC post gpsc fcp_cnt %d\n",
5947 __func__, __LINE__, fcport->port_name,
5949 qla24xx_post_gpsc_work(vha, fcport);
5953 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
5956 void qla_register_fcport_fn(struct work_struct *work)
5958 fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
5959 u32 rscn_gen = fcport->rscn_gen;
5962 if (IS_SW_RESV_ADDR(fcport->d_id))
5965 qla2x00_update_fcport(fcport->vha, fcport);
5967 ql_dbg(ql_dbg_disc, fcport->vha, 0x911e,
5968 "%s rscn gen %d/%d next DS %d\n", __func__,
5969 rscn_gen, fcport->rscn_gen, fcport->next_disc_state);
5971 if (rscn_gen != fcport->rscn_gen) {
5972 /* RSCN(s) came in while registration */
5973 switch (fcport->next_disc_state) {
5974 case DSC_DELETE_PEND:
5975 qlt_schedule_sess_for_deletion(fcport);
5978 data[0] = data[1] = 0;
5979 qla2x00_post_async_adisc_work(fcport->vha, fcport,
5989 * qla2x00_configure_fabric
5990 * Setup SNS devices with loop ID's.
5993 * ha = adapter block pointer.
6000 qla2x00_configure_fabric(scsi_qla_host_t *vha)
6004 uint16_t mb[MAILBOX_REGISTER_COUNT];
6006 LIST_HEAD(new_fcports);
6007 struct qla_hw_data *ha = vha->hw;
6010 /* If FL port exists, then SNS is present */
6011 if (IS_FWI2_CAPABLE(ha))
6012 loop_id = NPH_F_PORT;
6014 loop_id = SNS_FL_PORT;
6015 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
6016 if (rval != QLA_SUCCESS) {
6017 ql_dbg(ql_dbg_disc, vha, 0x20a0,
6018 "MBX_GET_PORT_NAME failed, No FL Port.\n");
6020 vha->device_flags &= ~SWITCH_FOUND;
6021 return (QLA_SUCCESS);
6023 vha->device_flags |= SWITCH_FOUND;
6025 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_port_name, 0);
6026 if (rval != QLA_SUCCESS)
6027 ql_dbg(ql_dbg_disc, vha, 0x20ff,
6028 "Failed to get Fabric Port Name\n");
6030 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
6031 rval = qla2x00_send_change_request(vha, 0x3, 0);
6032 if (rval != QLA_SUCCESS)
6033 ql_log(ql_log_warn, vha, 0x121,
6034 "Failed to enable receiving of RSCN requests: 0x%x.\n",
6039 qla2x00_mgmt_svr_login(vha);
6041 /* Ensure we are logged into the SNS. */
6042 loop_id = NPH_SNS_LID(ha);
6043 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
6044 0xfc, mb, BIT_1|BIT_0);
6045 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
6046 ql_dbg(ql_dbg_disc, vha, 0x20a1,
6047 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
6048 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
6049 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6054 if (ql2xfdmienable &&
6055 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
6056 qla2x00_fdmi_register(vha);
6058 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
6059 if (qla2x00_rft_id(vha)) {
6061 ql_dbg(ql_dbg_disc, vha, 0x20a2,
6062 "Register FC-4 TYPE failed.\n");
6063 if (test_bit(LOOP_RESYNC_NEEDED,
6067 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
6069 ql_dbg(ql_dbg_disc, vha, 0x209a,
6070 "Register FC-4 Features failed.\n");
6071 if (test_bit(LOOP_RESYNC_NEEDED,
6075 if (vha->flags.nvme_enabled) {
6076 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
6077 ql_dbg(ql_dbg_disc, vha, 0x2049,
6078 "Register NVME FC Type Features failed.\n");
6081 if (qla2x00_rnn_id(vha)) {
6083 ql_dbg(ql_dbg_disc, vha, 0x2104,
6084 "Register Node Name failed.\n");
6085 if (test_bit(LOOP_RESYNC_NEEDED,
6088 } else if (qla2x00_rsnn_nn(vha)) {
6090 ql_dbg(ql_dbg_disc, vha, 0x209b,
6091 "Register Symbolic Node Name failed.\n");
6092 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6098 /* Mark the time right before querying FW for connected ports.
6099 * This process is long, asynchronous and by the time it's done,
6100 * collected information might not be accurate anymore. E.g.
6101 * disconnected port might have re-connected and a brand new
6102 * session has been created. In this case session's generation
6103 * will be newer than discovery_gen. */
6104 qlt_do_generation_tick(vha, &discovery_gen);
6106 if (USE_ASYNC_SCAN(ha)) {
6107 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
6110 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6112 list_for_each_entry(fcport, &vha->vp_fcports, list)
6113 fcport->scan_state = QLA_FCPORT_SCAN;
6115 rval = qla2x00_find_all_fabric_devs(vha);
6117 if (rval != QLA_SUCCESS)
6121 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
6122 qla_nvme_register_hba(vha);
6125 ql_dbg(ql_dbg_disc, vha, 0x2068,
6126 "Configure fabric error exit rval=%d.\n", rval);
6132 * qla2x00_find_all_fabric_devs
6135 * ha = adapter block pointer.
6136 * dev = database device entry pointer.
6145 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
6149 fc_port_t *fcport, *new_fcport;
6154 int first_dev, last_dev;
6155 port_id_t wrap = {}, nxt_d_id;
6156 struct qla_hw_data *ha = vha->hw;
6157 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6158 unsigned long flags;
6162 /* Try GID_PT to get device list, else GAN. */
6164 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
6169 ql_dbg(ql_dbg_disc, vha, 0x209c,
6170 "GID_PT allocations failed, fallback on GA_NXT.\n");
6172 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
6173 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
6175 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6177 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
6179 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6181 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
6183 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6185 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
6187 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6191 /* If other queries succeeded probe for FC-4 type */
6193 qla2x00_gff_id(vha, swl);
6194 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6200 /* Allocate temporary fcport for any new fcports discovered. */
6201 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
6202 if (new_fcport == NULL) {
6203 ql_log(ql_log_warn, vha, 0x209d,
6204 "Failed to allocate memory for fcport.\n");
6205 return (QLA_MEMORY_ALLOC_FAILED);
6207 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
6208 /* Set start port ID scan at adapter ID. */
6212 /* Starting free loop ID. */
6213 loop_id = ha->min_external_loopid;
6214 for (; loop_id <= ha->max_loop_id; loop_id++) {
6215 if (qla2x00_is_reserved_id(vha, loop_id))
6218 if (ha->current_topology == ISP_CFG_FL &&
6219 (atomic_read(&vha->loop_down_timer) ||
6220 LOOP_TRANSITION(vha))) {
6221 atomic_set(&vha->loop_down_timer, 0);
6222 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6223 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
6229 wrap.b24 = new_fcport->d_id.b24;
6231 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
6232 memcpy(new_fcport->node_name,
6233 swl[swl_idx].node_name, WWN_SIZE);
6234 memcpy(new_fcport->port_name,
6235 swl[swl_idx].port_name, WWN_SIZE);
6236 memcpy(new_fcport->fabric_port_name,
6237 swl[swl_idx].fabric_port_name, WWN_SIZE);
6238 new_fcport->fp_speed = swl[swl_idx].fp_speed;
6239 new_fcport->fc4_type = swl[swl_idx].fc4_type;
6241 new_fcport->nvme_flag = 0;
6242 if (vha->flags.nvme_enabled &&
6243 swl[swl_idx].fc4_type & FS_FC4TYPE_NVME) {
6244 ql_log(ql_log_info, vha, 0x2131,
6245 "FOUND: NVME port %8phC as FC Type 28h\n",
6246 new_fcport->port_name);
6249 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
6255 /* Send GA_NXT to the switch */
6256 rval = qla2x00_ga_nxt(vha, new_fcport);
6257 if (rval != QLA_SUCCESS) {
6258 ql_log(ql_log_warn, vha, 0x209e,
6259 "SNS scan failed -- assuming "
6260 "zero-entry result.\n");
6266 /* If wrap on switch device list, exit. */
6268 wrap.b24 = new_fcport->d_id.b24;
6270 } else if (new_fcport->d_id.b24 == wrap.b24) {
6271 ql_dbg(ql_dbg_disc, vha, 0x209f,
6272 "Device wrap (%02x%02x%02x).\n",
6273 new_fcport->d_id.b.domain,
6274 new_fcport->d_id.b.area,
6275 new_fcport->d_id.b.al_pa);
6279 /* Bypass if same physical adapter. */
6280 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
6283 /* Bypass virtual ports of the same host. */
6284 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
6287 /* Bypass if same domain and area of adapter. */
6288 if (((new_fcport->d_id.b24 & 0xffff00) ==
6289 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
6293 /* Bypass reserved domain fields. */
6294 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
6297 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
6298 if (ql2xgffidenable &&
6299 (!(new_fcport->fc4_type & FS_FC4TYPE_FCP) &&
6300 new_fcport->fc4_type != 0))
6303 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
6305 /* Locate matching device in database. */
6307 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6308 if (memcmp(new_fcport->port_name, fcport->port_name,
6312 fcport->scan_state = QLA_FCPORT_FOUND;
6316 /* Update port state. */
6317 memcpy(fcport->fabric_port_name,
6318 new_fcport->fabric_port_name, WWN_SIZE);
6319 fcport->fp_speed = new_fcport->fp_speed;
6322 * If address the same and state FCS_ONLINE
6323 * (or in target mode), nothing changed.
6325 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
6326 (atomic_read(&fcport->state) == FCS_ONLINE ||
6327 (vha->host->active_mode == MODE_TARGET))) {
6331 if (fcport->login_retry == 0)
6332 fcport->login_retry =
6333 vha->hw->login_retry_count;
6335 * If device was not a fabric device before.
6337 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
6338 fcport->d_id.b24 = new_fcport->d_id.b24;
6339 qla2x00_clear_loop_id(fcport);
6340 fcport->flags |= (FCF_FABRIC_DEVICE |
6346 * Port ID changed or device was marked to be updated;
6347 * Log it out if still logged in and mark it for
6350 if (qla_tgt_mode_enabled(base_vha)) {
6351 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
6352 "port changed FC ID, %8phC"
6353 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
6355 fcport->d_id.b.domain,
6356 fcport->d_id.b.area,
6357 fcport->d_id.b.al_pa,
6359 new_fcport->d_id.b.domain,
6360 new_fcport->d_id.b.area,
6361 new_fcport->d_id.b.al_pa);
6362 fcport->d_id.b24 = new_fcport->d_id.b24;
6366 fcport->d_id.b24 = new_fcport->d_id.b24;
6367 fcport->flags |= FCF_LOGIN_NEEDED;
6371 if (found && NVME_TARGET(vha->hw, fcport)) {
6372 if (fcport->disc_state == DSC_DELETE_PEND) {
6373 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
6374 vha->fcport_count--;
6375 fcport->login_succ = 0;
6380 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6383 /* If device was not in our fcports list, then add it. */
6384 new_fcport->scan_state = QLA_FCPORT_FOUND;
6385 list_add_tail(&new_fcport->list, &vha->vp_fcports);
6387 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6390 /* Allocate a new replacement fcport. */
6391 nxt_d_id.b24 = new_fcport->d_id.b24;
6392 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
6393 if (new_fcport == NULL) {
6394 ql_log(ql_log_warn, vha, 0xd032,
6395 "Memory allocation failed for fcport.\n");
6396 return (QLA_MEMORY_ALLOC_FAILED);
6398 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
6399 new_fcport->d_id.b24 = nxt_d_id.b24;
6402 qla2x00_free_fcport(new_fcport);
6405 * Logout all previous fabric dev marked lost, except FCP2 devices.
6407 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6408 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6411 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
6414 if (fcport->scan_state == QLA_FCPORT_SCAN) {
6415 if ((qla_dual_mode_enabled(vha) ||
6416 qla_ini_mode_enabled(vha)) &&
6417 atomic_read(&fcport->state) == FCS_ONLINE) {
6418 qla2x00_mark_device_lost(vha, fcport,
6419 ql2xplogiabsentdevice);
6420 if (fcport->loop_id != FC_NO_LOOP_ID &&
6421 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
6422 fcport->port_type != FCT_INITIATOR &&
6423 fcport->port_type != FCT_BROADCAST) {
6424 ql_dbg(ql_dbg_disc, vha, 0x20f0,
6425 "%s %d %8phC post del sess\n",
6428 qlt_schedule_sess_for_deletion(fcport);
6434 if (fcport->scan_state == QLA_FCPORT_FOUND &&
6435 (fcport->flags & FCF_LOGIN_NEEDED) != 0)
6436 qla24xx_fcport_handle_login(vha, fcport);
6441 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
6443 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
6445 int loop_id = FC_NO_LOOP_ID;
6446 int lid = NPH_MGMT_SERVER - vha->vp_idx;
6447 unsigned long flags;
6448 struct qla_hw_data *ha = vha->hw;
6450 if (vha->vp_idx == 0) {
6451 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
6452 return NPH_MGMT_SERVER;
6455 /* pick id from high and work down to low */
6456 spin_lock_irqsave(&ha->vport_slock, flags);
6457 for (; lid > 0; lid--) {
6458 if (!test_bit(lid, vha->hw->loop_id_map)) {
6459 set_bit(lid, vha->hw->loop_id_map);
6464 spin_unlock_irqrestore(&ha->vport_slock, flags);
6470 * qla2x00_fabric_login
6471 * Issue fabric login command.
6474 * ha = adapter block pointer.
6475 * device = pointer to FC device type structure.
6478 * 0 - Login successfully
6480 * 2 - Initiator device
6484 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
6485 uint16_t *next_loopid)
6489 uint16_t tmp_loopid;
6490 uint16_t mb[MAILBOX_REGISTER_COUNT];
6491 struct qla_hw_data *ha = vha->hw;
6497 ql_dbg(ql_dbg_disc, vha, 0x2000,
6498 "Trying Fabric Login w/loop id 0x%04x for port "
6500 fcport->loop_id, fcport->d_id.b.domain,
6501 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6503 /* Login fcport on switch. */
6504 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
6505 fcport->d_id.b.domain, fcport->d_id.b.area,
6506 fcport->d_id.b.al_pa, mb, BIT_0);
6507 if (rval != QLA_SUCCESS) {
6510 if (mb[0] == MBS_PORT_ID_USED) {
6512 * Device has another loop ID. The firmware team
6513 * recommends the driver perform an implicit login with
6514 * the specified ID again. The ID we just used is save
6515 * here so we return with an ID that can be tried by
6519 tmp_loopid = fcport->loop_id;
6520 fcport->loop_id = mb[1];
6522 ql_dbg(ql_dbg_disc, vha, 0x2001,
6523 "Fabric Login: port in use - next loop "
6524 "id=0x%04x, port id= %02x%02x%02x.\n",
6525 fcport->loop_id, fcport->d_id.b.domain,
6526 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6528 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
6533 /* A retry occurred before. */
6534 *next_loopid = tmp_loopid;
6537 * No retry occurred before. Just increment the
6538 * ID value for next login.
6540 *next_loopid = (fcport->loop_id + 1);
6543 if (mb[1] & BIT_0) {
6544 fcport->port_type = FCT_INITIATOR;
6546 fcport->port_type = FCT_TARGET;
6547 if (mb[1] & BIT_1) {
6548 fcport->flags |= FCF_FCP2_DEVICE;
6553 fcport->supported_classes |= FC_COS_CLASS2;
6555 fcport->supported_classes |= FC_COS_CLASS3;
6557 if (IS_FWI2_CAPABLE(ha)) {
6560 FCF_CONF_COMP_SUPPORTED;
6565 } else if (mb[0] == MBS_LOOP_ID_USED) {
6567 * Loop ID already used, try next loop ID.
6570 rval = qla2x00_find_new_loop_id(vha, fcport);
6571 if (rval != QLA_SUCCESS) {
6572 /* Ran out of loop IDs to use */
6575 } else if (mb[0] == MBS_COMMAND_ERROR) {
6577 * Firmware possibly timed out during login. If NO
6578 * retries are left to do then the device is declared
6581 *next_loopid = fcport->loop_id;
6582 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6583 fcport->d_id.b.domain, fcport->d_id.b.area,
6584 fcport->d_id.b.al_pa);
6585 qla2x00_mark_device_lost(vha, fcport, 1);
6591 * unrecoverable / not handled error
6593 ql_dbg(ql_dbg_disc, vha, 0x2002,
6594 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6595 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
6596 fcport->d_id.b.area, fcport->d_id.b.al_pa,
6597 fcport->loop_id, jiffies);
6599 *next_loopid = fcport->loop_id;
6600 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6601 fcport->d_id.b.domain, fcport->d_id.b.area,
6602 fcport->d_id.b.al_pa);
6603 qla2x00_clear_loop_id(fcport);
6604 fcport->login_retry = 0;
6615 * qla2x00_local_device_login
6616 * Issue local device login command.
6619 * ha = adapter block pointer.
6620 * loop_id = loop id of device to login to.
6622 * Returns (Where's the #define!!!!):
6623 * 0 - Login successfully
6628 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
6631 uint16_t mb[MAILBOX_REGISTER_COUNT];
6633 memset(mb, 0, sizeof(mb));
6634 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
6635 if (rval == QLA_SUCCESS) {
6636 /* Interrogate mailbox registers for any errors */
6637 if (mb[0] == MBS_COMMAND_ERROR)
6639 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
6640 /* device not in PCB table */
6648 * qla2x00_loop_resync
6649 * Resync with fibre channel devices.
6652 * ha = adapter block pointer.
6658 qla2x00_loop_resync(scsi_qla_host_t *vha)
6660 int rval = QLA_SUCCESS;
6663 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6664 if (vha->flags.online) {
6665 if (!(rval = qla2x00_fw_ready(vha))) {
6666 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6669 if (!IS_QLAFX00(vha->hw)) {
6671 * Issue a marker after FW becomes
6674 qla2x00_marker(vha, vha->hw->base_qpair,
6676 vha->marker_needed = 0;
6679 /* Remap devices on Loop. */
6680 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6682 if (IS_QLAFX00(vha->hw))
6683 qlafx00_configure_devices(vha);
6685 qla2x00_configure_loop(vha);
6688 } while (!atomic_read(&vha->loop_down_timer) &&
6689 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6690 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
6695 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6696 return (QLA_FUNCTION_FAILED);
6699 ql_dbg(ql_dbg_disc, vha, 0x206c,
6700 "%s *** FAILED ***.\n", __func__);
6706 * qla2x00_perform_loop_resync
6707 * Description: This function will set the appropriate flags and call
6708 * qla2x00_loop_resync. If successful loop will be resynced
6709 * Arguments : scsi_qla_host_t pointer
6710 * returm : Success or Failure
6713 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
6717 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
6718 /*Configure the flags so that resync happens properly*/
6719 atomic_set(&ha->loop_down_timer, 0);
6720 if (!(ha->device_flags & DFLG_NO_CABLE)) {
6721 atomic_set(&ha->loop_state, LOOP_UP);
6722 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
6723 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
6724 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
6726 rval = qla2x00_loop_resync(ha);
6728 atomic_set(&ha->loop_state, LOOP_DEAD);
6730 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
6736 /* Assumes idc_lock always held on entry */
6738 qla83xx_reset_ownership(scsi_qla_host_t *vha)
6740 struct qla_hw_data *ha = vha->hw;
6741 uint32_t drv_presence, drv_presence_mask;
6742 uint32_t dev_part_info1, dev_part_info2, class_type;
6743 uint32_t class_type_mask = 0x3;
6744 uint16_t fcoe_other_function = 0xffff, i;
6746 if (IS_QLA8044(ha)) {
6747 drv_presence = qla8044_rd_direct(vha,
6748 QLA8044_CRB_DRV_ACTIVE_INDEX);
6749 dev_part_info1 = qla8044_rd_direct(vha,
6750 QLA8044_CRB_DEV_PART_INFO_INDEX);
6751 dev_part_info2 = qla8044_rd_direct(vha,
6752 QLA8044_CRB_DEV_PART_INFO2);
6754 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6755 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
6756 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
6758 for (i = 0; i < 8; i++) {
6759 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
6760 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6761 (i != ha->portnum)) {
6762 fcoe_other_function = i;
6766 if (fcoe_other_function == 0xffff) {
6767 for (i = 0; i < 8; i++) {
6768 class_type = ((dev_part_info2 >> (i * 4)) &
6770 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6771 ((i + 8) != ha->portnum)) {
6772 fcoe_other_function = i + 8;
6778 * Prepare drv-presence mask based on fcoe functions present.
6779 * However consider only valid physical fcoe function numbers (0-15).
6781 drv_presence_mask = ~((1 << (ha->portnum)) |
6782 ((fcoe_other_function == 0xffff) ?
6783 0 : (1 << (fcoe_other_function))));
6785 /* We are the reset owner iff:
6786 * - No other protocol drivers present.
6787 * - This is the lowest among fcoe functions. */
6788 if (!(drv_presence & drv_presence_mask) &&
6789 (ha->portnum < fcoe_other_function)) {
6790 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
6791 "This host is Reset owner.\n");
6792 ha->flags.nic_core_reset_owner = 1;
6797 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
6799 int rval = QLA_SUCCESS;
6800 struct qla_hw_data *ha = vha->hw;
6803 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6804 if (rval == QLA_SUCCESS) {
6805 drv_ack |= (1 << ha->portnum);
6806 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6813 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
6815 int rval = QLA_SUCCESS;
6816 struct qla_hw_data *ha = vha->hw;
6819 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6820 if (rval == QLA_SUCCESS) {
6821 drv_ack &= ~(1 << ha->portnum);
6822 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6828 /* Assumes idc-lock always held on entry */
6830 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6832 struct qla_hw_data *ha = vha->hw;
6833 uint32_t idc_audit_reg = 0, duration_secs = 0;
6835 switch (audit_type) {
6836 case IDC_AUDIT_TIMESTAMP:
6837 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6838 idc_audit_reg = (ha->portnum) |
6839 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6840 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6843 case IDC_AUDIT_COMPLETION:
6844 duration_secs = ((jiffies_to_msecs(jiffies) -
6845 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6846 idc_audit_reg = (ha->portnum) |
6847 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6848 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6852 ql_log(ql_log_warn, vha, 0xb078,
6853 "Invalid audit type specified.\n");
6858 /* Assumes idc_lock always held on entry */
6860 qla83xx_initiating_reset(scsi_qla_host_t *vha)
6862 struct qla_hw_data *ha = vha->hw;
6863 uint32_t idc_control, dev_state;
6865 __qla83xx_get_idc_control(vha, &idc_control);
6866 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6867 ql_log(ql_log_info, vha, 0xb080,
6868 "NIC Core reset has been disabled. idc-control=0x%x\n",
6870 return QLA_FUNCTION_FAILED;
6873 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6874 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6875 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6876 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6877 QLA8XXX_DEV_NEED_RESET);
6878 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6879 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6881 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n",
6882 qdev_state(dev_state));
6884 /* SV: XXX: Is timeout required here? */
6885 /* Wait for IDC state change READY -> NEED_RESET */
6886 while (dev_state == QLA8XXX_DEV_READY) {
6887 qla83xx_idc_unlock(vha, 0);
6889 qla83xx_idc_lock(vha, 0);
6890 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6894 /* Send IDC ack by writing to drv-ack register */
6895 __qla83xx_set_drv_ack(vha);
6901 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6903 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6907 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6909 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6913 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6915 uint32_t drv_presence = 0;
6916 struct qla_hw_data *ha = vha->hw;
6918 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6919 if (drv_presence & (1 << ha->portnum))
6922 return QLA_TEST_FAILED;
6926 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6928 int rval = QLA_SUCCESS;
6929 struct qla_hw_data *ha = vha->hw;
6931 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6932 "Entered %s().\n", __func__);
6934 if (vha->device_flags & DFLG_DEV_FAILED) {
6935 ql_log(ql_log_warn, vha, 0xb059,
6936 "Device in unrecoverable FAILED state.\n");
6937 return QLA_FUNCTION_FAILED;
6940 qla83xx_idc_lock(vha, 0);
6942 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6943 ql_log(ql_log_warn, vha, 0xb05a,
6944 "Function=0x%x has been removed from IDC participation.\n",
6946 rval = QLA_FUNCTION_FAILED;
6950 qla83xx_reset_ownership(vha);
6952 rval = qla83xx_initiating_reset(vha);
6955 * Perform reset if we are the reset-owner,
6956 * else wait till IDC state changes to READY/FAILED.
6958 if (rval == QLA_SUCCESS) {
6959 rval = qla83xx_idc_state_handler(vha);
6961 if (rval == QLA_SUCCESS)
6962 ha->flags.nic_core_hung = 0;
6963 __qla83xx_clear_drv_ack(vha);
6967 qla83xx_idc_unlock(vha, 0);
6969 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6975 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6977 struct qla_hw_data *ha = vha->hw;
6978 int rval = QLA_FUNCTION_FAILED;
6980 if (!IS_MCTP_CAPABLE(ha)) {
6981 /* This message can be removed from the final version */
6982 ql_log(ql_log_info, vha, 0x506d,
6983 "This board is not MCTP capable\n");
6987 if (!ha->mctp_dump) {
6988 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6989 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6991 if (!ha->mctp_dump) {
6992 ql_log(ql_log_warn, vha, 0x506e,
6993 "Failed to allocate memory for mctp dump\n");
6998 #define MCTP_DUMP_STR_ADDR 0x00000000
6999 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
7000 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
7001 if (rval != QLA_SUCCESS) {
7002 ql_log(ql_log_warn, vha, 0x506f,
7003 "Failed to capture mctp dump\n");
7005 ql_log(ql_log_info, vha, 0x5070,
7006 "Mctp dump capture for host (%ld/%p).\n",
7007 vha->host_no, ha->mctp_dump);
7008 ha->mctp_dumped = 1;
7011 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
7012 ha->flags.nic_core_reset_hdlr_active = 1;
7013 rval = qla83xx_restart_nic_firmware(vha);
7015 /* NIC Core reset failed. */
7016 ql_log(ql_log_warn, vha, 0x5071,
7017 "Failed to restart nic firmware\n");
7019 ql_dbg(ql_dbg_p3p, vha, 0xb084,
7020 "Restarted NIC firmware successfully.\n");
7021 ha->flags.nic_core_reset_hdlr_active = 0;
7029 * qla2x00_quiesce_io
7030 * Description: This function will block the new I/Os
7031 * Its not aborting any I/Os as context
7032 * is not destroyed during quiescence
7033 * Arguments: scsi_qla_host_t
7037 qla2x00_quiesce_io(scsi_qla_host_t *vha)
7039 struct qla_hw_data *ha = vha->hw;
7040 struct scsi_qla_host *vp, *tvp;
7041 unsigned long flags;
7043 ql_dbg(ql_dbg_dpc, vha, 0x401d,
7044 "Quiescing I/O - ha=%p.\n", ha);
7046 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
7047 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
7048 atomic_set(&vha->loop_state, LOOP_DOWN);
7049 qla2x00_mark_all_devices_lost(vha);
7051 spin_lock_irqsave(&ha->vport_slock, flags);
7052 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7053 atomic_inc(&vp->vref_count);
7054 spin_unlock_irqrestore(&ha->vport_slock, flags);
7056 qla2x00_mark_all_devices_lost(vp);
7058 spin_lock_irqsave(&ha->vport_slock, flags);
7059 atomic_dec(&vp->vref_count);
7061 spin_unlock_irqrestore(&ha->vport_slock, flags);
7063 if (!atomic_read(&vha->loop_down_timer))
7064 atomic_set(&vha->loop_down_timer,
7067 /* Wait for pending cmds to complete */
7068 WARN_ON_ONCE(qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST)
7073 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
7075 struct qla_hw_data *ha = vha->hw;
7076 struct scsi_qla_host *vp, *tvp;
7077 unsigned long flags;
7081 /* For ISP82XX, driver waits for completion of the commands.
7082 * online flag should be set.
7084 if (!(IS_P3P_TYPE(ha)))
7085 vha->flags.online = 0;
7086 ha->flags.chip_reset_done = 0;
7087 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
7088 vha->qla_stats.total_isp_aborts++;
7090 ql_log(ql_log_info, vha, 0x00af,
7091 "Performing ISP error recovery - ha=%p.\n", ha);
7093 ha->flags.purge_mbox = 1;
7094 /* For ISP82XX, reset_chip is just disabling interrupts.
7095 * Driver waits for the completion of the commands.
7096 * the interrupts need to be enabled.
7098 if (!(IS_P3P_TYPE(ha)))
7099 ha->isp_ops->reset_chip(vha);
7101 ha->link_data_rate = PORT_SPEED_UNKNOWN;
7103 ha->flags.rida_fmt2 = 0;
7104 ha->flags.n2n_ae = 0;
7105 ha->flags.lip_ae = 0;
7106 ha->current_topology = 0;
7108 ha->flags.fw_init_done = 0;
7110 ha->base_qpair->chip_reset = ha->chip_reset;
7111 ha->base_qpair->cmd_cnt = ha->base_qpair->cmd_completion_cnt = 0;
7112 ha->base_qpair->prev_completion_cnt = 0;
7113 for (i = 0; i < ha->max_qpairs; i++) {
7114 if (ha->queue_pair_map[i]) {
7115 ha->queue_pair_map[i]->chip_reset =
7116 ha->base_qpair->chip_reset;
7117 ha->queue_pair_map[i]->cmd_cnt =
7118 ha->queue_pair_map[i]->cmd_completion_cnt = 0;
7119 ha->base_qpair->prev_completion_cnt = 0;
7123 /* purge MBox commands */
7124 if (atomic_read(&ha->num_pend_mbx_stage3)) {
7125 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
7126 complete(&ha->mbx_intr_comp);
7130 while (atomic_read(&ha->num_pend_mbx_stage3) ||
7131 atomic_read(&ha->num_pend_mbx_stage2) ||
7132 atomic_read(&ha->num_pend_mbx_stage1)) {
7138 ha->flags.purge_mbox = 0;
7140 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
7141 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
7142 atomic_set(&vha->loop_state, LOOP_DOWN);
7143 qla2x00_mark_all_devices_lost(vha);
7145 spin_lock_irqsave(&ha->vport_slock, flags);
7146 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7147 atomic_inc(&vp->vref_count);
7148 spin_unlock_irqrestore(&ha->vport_slock, flags);
7150 qla2x00_mark_all_devices_lost(vp);
7152 spin_lock_irqsave(&ha->vport_slock, flags);
7153 atomic_dec(&vp->vref_count);
7155 spin_unlock_irqrestore(&ha->vport_slock, flags);
7157 if (!atomic_read(&vha->loop_down_timer))
7158 atomic_set(&vha->loop_down_timer,
7162 /* Clear all async request states across all VPs. */
7163 list_for_each_entry(fcport, &vha->vp_fcports, list) {
7164 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7165 fcport->scan_state = 0;
7167 spin_lock_irqsave(&ha->vport_slock, flags);
7168 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7169 atomic_inc(&vp->vref_count);
7170 spin_unlock_irqrestore(&ha->vport_slock, flags);
7172 list_for_each_entry(fcport, &vp->vp_fcports, list)
7173 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7175 spin_lock_irqsave(&ha->vport_slock, flags);
7176 atomic_dec(&vp->vref_count);
7178 spin_unlock_irqrestore(&ha->vport_slock, flags);
7180 /* Make sure for ISP 82XX IO DMA is complete */
7181 if (IS_P3P_TYPE(ha)) {
7182 qla82xx_chip_reset_cleanup(vha);
7183 ql_log(ql_log_info, vha, 0x00b4,
7184 "Done chip reset cleanup.\n");
7186 /* Done waiting for pending commands. Reset online flag */
7187 vha->flags.online = 0;
7190 /* Requeue all commands in outstanding command list. */
7191 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
7192 /* memory barrier */
7198 * Resets ISP and aborts all outstanding commands.
7201 * ha = adapter block pointer.
7207 qla2x00_abort_isp(scsi_qla_host_t *vha)
7211 struct qla_hw_data *ha = vha->hw;
7212 struct scsi_qla_host *vp, *tvp;
7213 struct req_que *req = ha->req_q_map[0];
7214 unsigned long flags;
7216 if (vha->flags.online) {
7217 qla2x00_abort_isp_cleanup(vha);
7219 vha->dport_status |= DPORT_DIAG_CHIP_RESET_IN_PROGRESS;
7220 vha->dport_status &= ~DPORT_DIAG_IN_PROGRESS;
7222 if (vha->hw->flags.port_isolated)
7225 if (qla2x00_isp_reg_stat(ha)) {
7226 ql_log(ql_log_info, vha, 0x803f,
7227 "ISP Abort - ISP reg disconnect, exiting.\n");
7231 if (test_and_clear_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags)) {
7232 ha->flags.chip_reset_done = 1;
7233 vha->flags.online = 1;
7235 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7239 if (IS_QLA8031(ha)) {
7240 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
7241 "Clearing fcoe driver presence.\n");
7242 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
7243 ql_dbg(ql_dbg_p3p, vha, 0xb073,
7244 "Error while clearing DRV-Presence.\n");
7247 if (unlikely(pci_channel_offline(ha->pdev) &&
7248 ha->flags.pci_channel_io_perm_failure)) {
7249 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7254 switch (vha->qlini_mode) {
7255 case QLA2XXX_INI_MODE_DISABLED:
7256 if (!qla_tgt_mode_enabled(vha))
7259 case QLA2XXX_INI_MODE_DUAL:
7260 if (!qla_dual_mode_enabled(vha) &&
7261 !qla_ini_mode_enabled(vha))
7264 case QLA2XXX_INI_MODE_ENABLED:
7269 ha->isp_ops->get_flash_version(vha, req->ring);
7271 if (qla2x00_isp_reg_stat(ha)) {
7272 ql_log(ql_log_info, vha, 0x803f,
7273 "ISP Abort - ISP reg disconnect pre nvram config, exiting.\n");
7276 ha->isp_ops->nvram_config(vha);
7278 if (qla2x00_isp_reg_stat(ha)) {
7279 ql_log(ql_log_info, vha, 0x803f,
7280 "ISP Abort - ISP reg disconnect post nvmram config, exiting.\n");
7283 if (!qla2x00_restart_isp(vha)) {
7284 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7286 if (!atomic_read(&vha->loop_down_timer)) {
7288 * Issue marker command only when we are going
7289 * to start the I/O .
7291 vha->marker_needed = 1;
7294 vha->flags.online = 1;
7296 ha->isp_ops->enable_intrs(ha);
7298 ha->isp_abort_cnt = 0;
7299 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7301 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
7302 qla2x00_get_fw_version(vha);
7304 ha->flags.fce_enabled = 1;
7306 fce_calc_size(ha->fce_bufs));
7307 rval = qla2x00_enable_fce_trace(vha,
7308 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
7311 ql_log(ql_log_warn, vha, 0x8033,
7312 "Unable to reinitialize FCE "
7314 ha->flags.fce_enabled = 0;
7319 memset(ha->eft, 0, EFT_SIZE);
7320 rval = qla2x00_enable_eft_trace(vha,
7321 ha->eft_dma, EFT_NUM_BUFFERS);
7323 ql_log(ql_log_warn, vha, 0x8034,
7324 "Unable to reinitialize EFT "
7328 } else { /* failed the ISP abort */
7329 vha->flags.online = 1;
7330 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
7331 if (ha->isp_abort_cnt == 0) {
7332 ql_log(ql_log_fatal, vha, 0x8035,
7333 "ISP error recover failed - "
7334 "board disabled.\n");
7336 * The next call disables the board
7339 qla2x00_abort_isp_cleanup(vha);
7340 vha->flags.online = 0;
7341 clear_bit(ISP_ABORT_RETRY,
7344 } else { /* schedule another ISP abort */
7345 ha->isp_abort_cnt--;
7346 ql_dbg(ql_dbg_taskm, vha, 0x8020,
7347 "ISP abort - retry remaining %d.\n",
7352 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
7353 ql_dbg(ql_dbg_taskm, vha, 0x8021,
7354 "ISP error recovery - retrying (%d) "
7355 "more times.\n", ha->isp_abort_cnt);
7356 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7363 if (vha->hw->flags.port_isolated) {
7364 qla2x00_abort_isp_cleanup(vha);
7369 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
7370 qla2x00_configure_hba(vha);
7371 spin_lock_irqsave(&ha->vport_slock, flags);
7372 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7374 atomic_inc(&vp->vref_count);
7375 spin_unlock_irqrestore(&ha->vport_slock, flags);
7377 qla2x00_vp_abort_isp(vp);
7379 spin_lock_irqsave(&ha->vport_slock, flags);
7380 atomic_dec(&vp->vref_count);
7383 spin_unlock_irqrestore(&ha->vport_slock, flags);
7385 if (IS_QLA8031(ha)) {
7386 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
7387 "Setting back fcoe driver presence.\n");
7388 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
7389 ql_dbg(ql_dbg_p3p, vha, 0xb074,
7390 "Error while setting DRV-Presence.\n");
7393 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
7401 * qla2x00_restart_isp
7402 * restarts the ISP after a reset
7405 * ha = adapter block pointer.
7411 qla2x00_restart_isp(scsi_qla_host_t *vha)
7414 struct qla_hw_data *ha = vha->hw;
7416 /* If firmware needs to be loaded */
7417 if (qla2x00_isp_firmware(vha)) {
7418 vha->flags.online = 0;
7419 status = ha->isp_ops->chip_diag(vha);
7422 status = qla2x00_setup_chip(vha);
7427 status = qla2x00_init_rings(vha);
7431 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7432 ha->flags.chip_reset_done = 1;
7434 /* Initialize the queues in use */
7435 qla25xx_init_queues(ha);
7437 status = qla2x00_fw_ready(vha);
7439 /* if no cable then assume it's good */
7440 return vha->device_flags & DFLG_NO_CABLE ? 0 : status;
7443 /* Issue a marker after FW becomes ready. */
7444 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
7445 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7451 qla25xx_init_queues(struct qla_hw_data *ha)
7453 struct rsp_que *rsp = NULL;
7454 struct req_que *req = NULL;
7455 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7459 for (i = 1; i < ha->max_rsp_queues; i++) {
7460 rsp = ha->rsp_q_map[i];
7461 if (rsp && test_bit(i, ha->rsp_qid_map)) {
7462 rsp->options &= ~BIT_0;
7463 ret = qla25xx_init_rsp_que(base_vha, rsp);
7464 if (ret != QLA_SUCCESS)
7465 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
7466 "%s Rsp que: %d init failed.\n",
7469 ql_dbg(ql_dbg_init, base_vha, 0x0100,
7470 "%s Rsp que: %d inited.\n",
7474 for (i = 1; i < ha->max_req_queues; i++) {
7475 req = ha->req_q_map[i];
7476 if (req && test_bit(i, ha->req_qid_map)) {
7477 /* Clear outstanding commands array. */
7478 req->options &= ~BIT_0;
7479 ret = qla25xx_init_req_que(base_vha, req);
7480 if (ret != QLA_SUCCESS)
7481 ql_dbg(ql_dbg_init, base_vha, 0x0101,
7482 "%s Req que: %d init failed.\n",
7485 ql_dbg(ql_dbg_init, base_vha, 0x0102,
7486 "%s Req que: %d inited.\n",
7494 * qla2x00_reset_adapter
7498 * ha = adapter block pointer.
7501 qla2x00_reset_adapter(scsi_qla_host_t *vha)
7503 unsigned long flags = 0;
7504 struct qla_hw_data *ha = vha->hw;
7505 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7507 vha->flags.online = 0;
7508 ha->isp_ops->disable_intrs(ha);
7510 spin_lock_irqsave(&ha->hardware_lock, flags);
7511 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
7512 rd_reg_word(®->hccr); /* PCI Posting. */
7513 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
7514 rd_reg_word(®->hccr); /* PCI Posting. */
7515 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7521 qla24xx_reset_adapter(scsi_qla_host_t *vha)
7523 unsigned long flags = 0;
7524 struct qla_hw_data *ha = vha->hw;
7525 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
7527 if (IS_P3P_TYPE(ha))
7530 vha->flags.online = 0;
7531 ha->isp_ops->disable_intrs(ha);
7533 spin_lock_irqsave(&ha->hardware_lock, flags);
7534 wrt_reg_dword(®->hccr, HCCRX_SET_RISC_RESET);
7535 rd_reg_dword(®->hccr);
7536 wrt_reg_dword(®->hccr, HCCRX_REL_RISC_PAUSE);
7537 rd_reg_dword(®->hccr);
7538 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7540 if (IS_NOPOLLING_TYPE(ha))
7541 ha->isp_ops->enable_intrs(ha);
7546 /* On sparc systems, obtain port and node WWN from firmware
7549 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
7550 struct nvram_24xx *nv)
7553 struct qla_hw_data *ha = vha->hw;
7554 struct pci_dev *pdev = ha->pdev;
7555 struct device_node *dp = pci_device_to_OF_node(pdev);
7559 val = of_get_property(dp, "port-wwn", &len);
7560 if (val && len >= WWN_SIZE)
7561 memcpy(nv->port_name, val, WWN_SIZE);
7563 val = of_get_property(dp, "node-wwn", &len);
7564 if (val && len >= WWN_SIZE)
7565 memcpy(nv->node_name, val, WWN_SIZE);
7570 qla24xx_nvram_config(scsi_qla_host_t *vha)
7573 struct init_cb_24xx *icb;
7574 struct nvram_24xx *nv;
7576 uint8_t *dptr1, *dptr2;
7579 struct qla_hw_data *ha = vha->hw;
7582 icb = (struct init_cb_24xx *)ha->init_cb;
7585 /* Determine NVRAM starting address. */
7586 if (ha->port_no == 0) {
7587 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
7588 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
7590 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
7591 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
7594 ha->nvram_size = sizeof(*nv);
7595 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7597 /* Get VPD data into cache */
7598 ha->vpd = ha->nvram + VPD_OFFSET;
7599 ha->isp_ops->read_nvram(vha, ha->vpd,
7600 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
7602 /* Get NVRAM data into cache and calculate checksum. */
7603 dptr = (__force __le32 *)nv;
7604 ha->isp_ops->read_nvram(vha, dptr, ha->nvram_base, ha->nvram_size);
7605 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7606 chksum += le32_to_cpu(*dptr);
7608 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
7609 "Contents of NVRAM\n");
7610 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
7611 nv, ha->nvram_size);
7613 /* Bad NVRAM data, set defaults parameters. */
7614 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
7615 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
7616 /* Reset NVRAM data. */
7617 ql_log(ql_log_warn, vha, 0x006b,
7618 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
7619 chksum, nv->id, nv->nvram_version);
7620 ql_dump_buffer(ql_dbg_init, vha, 0x006b, nv, sizeof(*nv));
7621 ql_log(ql_log_warn, vha, 0x006c,
7622 "Falling back to functioning (yet invalid -- WWPN) "
7626 * Set default initialization control block.
7628 memset(nv, 0, ha->nvram_size);
7629 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7630 nv->version = cpu_to_le16(ICB_VERSION);
7631 nv->frame_payload_size = cpu_to_le16(2048);
7632 nv->execution_throttle = cpu_to_le16(0xFFFF);
7633 nv->exchange_count = cpu_to_le16(0);
7634 nv->hard_address = cpu_to_le16(124);
7635 nv->port_name[0] = 0x21;
7636 nv->port_name[1] = 0x00 + ha->port_no + 1;
7637 nv->port_name[2] = 0x00;
7638 nv->port_name[3] = 0xe0;
7639 nv->port_name[4] = 0x8b;
7640 nv->port_name[5] = 0x1c;
7641 nv->port_name[6] = 0x55;
7642 nv->port_name[7] = 0x86;
7643 nv->node_name[0] = 0x20;
7644 nv->node_name[1] = 0x00;
7645 nv->node_name[2] = 0x00;
7646 nv->node_name[3] = 0xe0;
7647 nv->node_name[4] = 0x8b;
7648 nv->node_name[5] = 0x1c;
7649 nv->node_name[6] = 0x55;
7650 nv->node_name[7] = 0x86;
7651 qla24xx_nvram_wwn_from_ofw(vha, nv);
7652 nv->login_retry_count = cpu_to_le16(8);
7653 nv->interrupt_delay_timer = cpu_to_le16(0);
7654 nv->login_timeout = cpu_to_le16(0);
7655 nv->firmware_options_1 =
7656 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7657 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7658 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7659 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7660 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7661 nv->efi_parameters = cpu_to_le32(0);
7662 nv->reset_delay = 5;
7663 nv->max_luns_per_target = cpu_to_le16(128);
7664 nv->port_down_retry_count = cpu_to_le16(30);
7665 nv->link_down_timeout = cpu_to_le16(30);
7670 if (qla_tgt_mode_enabled(vha)) {
7671 /* Don't enable full login after initial LIP */
7672 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7673 /* Don't enable LIP full login for initiator */
7674 nv->host_p &= cpu_to_le32(~BIT_10);
7677 qlt_24xx_config_nvram_stage1(vha, nv);
7679 /* Reset Initialization control block */
7680 memset(icb, 0, ha->init_cb_size);
7682 /* Copy 1st segment. */
7683 dptr1 = (uint8_t *)icb;
7684 dptr2 = (uint8_t *)&nv->version;
7685 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7687 *dptr1++ = *dptr2++;
7689 icb->login_retry_count = nv->login_retry_count;
7690 icb->link_down_on_nos = nv->link_down_on_nos;
7692 /* Copy 2nd segment. */
7693 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7694 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7695 cnt = (uint8_t *)&icb->reserved_3 -
7696 (uint8_t *)&icb->interrupt_delay_timer;
7698 *dptr1++ = *dptr2++;
7699 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
7701 * Setup driver NVRAM options.
7703 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7706 qlt_24xx_config_nvram_stage2(vha, icb);
7708 if (nv->host_p & cpu_to_le32(BIT_15)) {
7709 /* Use alternate WWN? */
7710 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7711 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7714 /* Prepare nodename */
7715 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7717 * Firmware will apply the following mask if the nodename was
7720 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7721 icb->node_name[0] &= 0xF0;
7724 /* Set host adapter parameters. */
7725 ha->flags.disable_risc_code_load = 0;
7726 ha->flags.enable_lip_reset = 0;
7727 ha->flags.enable_lip_full_login =
7728 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
7729 ha->flags.enable_target_reset =
7730 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
7731 ha->flags.enable_led_scheme = 0;
7732 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
7734 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7735 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7737 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
7738 sizeof(ha->fw_seriallink_options24));
7740 /* save HBA serial number */
7741 ha->serial0 = icb->port_name[5];
7742 ha->serial1 = icb->port_name[6];
7743 ha->serial2 = icb->port_name[7];
7744 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7745 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7747 icb->execution_throttle = cpu_to_le16(0xFFFF);
7749 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7751 /* Set minimum login_timeout to 4 seconds. */
7752 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7753 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7754 if (le16_to_cpu(nv->login_timeout) < 4)
7755 nv->login_timeout = cpu_to_le16(4);
7756 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7758 /* Set minimum RATOV to 100 tenths of a second. */
7761 ha->loop_reset_delay = nv->reset_delay;
7763 /* Link Down Timeout = 0:
7765 * When Port Down timer expires we will start returning
7766 * I/O's to OS with "DID_NO_CONNECT".
7768 * Link Down Timeout != 0:
7770 * The driver waits for the link to come up after link down
7771 * before returning I/Os to OS with "DID_NO_CONNECT".
7773 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7774 ha->loop_down_abort_time =
7775 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7777 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7778 ha->loop_down_abort_time =
7779 (LOOP_DOWN_TIME - ha->link_down_timeout);
7782 /* Need enough time to try and get the port back. */
7783 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7784 if (qlport_down_retry)
7785 ha->port_down_retry_count = qlport_down_retry;
7787 /* Set login_retry_count */
7788 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7789 if (ha->port_down_retry_count ==
7790 le16_to_cpu(nv->port_down_retry_count) &&
7791 ha->port_down_retry_count > 3)
7792 ha->login_retry_count = ha->port_down_retry_count;
7793 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7794 ha->login_retry_count = ha->port_down_retry_count;
7795 if (ql2xloginretrycount)
7796 ha->login_retry_count = ql2xloginretrycount;
7798 /* N2N: driver will initiate Login instead of FW */
7799 icb->firmware_options_3 |= cpu_to_le32(BIT_8);
7802 if (!vha->flags.init_done) {
7803 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7804 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7805 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7806 le16_to_cpu(icb->interrupt_delay_timer) : 2;
7808 icb->firmware_options_2 &= cpu_to_le32(
7809 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7810 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7811 ha->zio_mode = QLA_ZIO_MODE_6;
7813 ql_log(ql_log_info, vha, 0x006f,
7814 "ZIO mode %d enabled; timer delay (%d us).\n",
7815 ha->zio_mode, ha->zio_timer * 100);
7817 icb->firmware_options_2 |= cpu_to_le32(
7818 (uint32_t)ha->zio_mode);
7819 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7823 ql_log(ql_log_warn, vha, 0x0070,
7824 "NVRAM configuration failed.\n");
7830 qla27xx_print_image(struct scsi_qla_host *vha, char *name,
7831 struct qla27xx_image_status *image_status)
7833 ql_dbg(ql_dbg_init, vha, 0x018b,
7834 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
7836 image_status->image_status_mask,
7837 le16_to_cpu(image_status->generation),
7838 image_status->ver_major,
7839 image_status->ver_minor,
7840 image_status->bitmap,
7841 le32_to_cpu(image_status->checksum),
7842 le32_to_cpu(image_status->signature));
7846 qla28xx_check_aux_image_status_signature(
7847 struct qla27xx_image_status *image_status)
7849 ulong signature = le32_to_cpu(image_status->signature);
7851 return signature != QLA28XX_AUX_IMG_STATUS_SIGN;
7855 qla27xx_check_image_status_signature(struct qla27xx_image_status *image_status)
7857 ulong signature = le32_to_cpu(image_status->signature);
7860 signature != QLA27XX_IMG_STATUS_SIGN &&
7861 signature != QLA28XX_IMG_STATUS_SIGN;
7865 qla27xx_image_status_checksum(struct qla27xx_image_status *image_status)
7867 __le32 *p = (__force __le32 *)image_status;
7868 uint n = sizeof(*image_status) / sizeof(*p);
7872 sum += le32_to_cpup(p);
7878 qla28xx_component_bitmask(struct qla27xx_image_status *aux, uint bitmask)
7880 return aux->bitmap & bitmask ?
7881 QLA27XX_SECONDARY_IMAGE : QLA27XX_PRIMARY_IMAGE;
7885 qla28xx_component_status(
7886 struct active_regions *active_regions, struct qla27xx_image_status *aux)
7888 active_regions->aux.board_config =
7889 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_BOARD_CONFIG);
7891 active_regions->aux.vpd_nvram =
7892 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_VPD_NVRAM);
7894 active_regions->aux.npiv_config_0_1 =
7895 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1);
7897 active_regions->aux.npiv_config_2_3 =
7898 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3);
7900 active_regions->aux.nvme_params =
7901 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NVME_PARAMS);
7905 qla27xx_compare_image_generation(
7906 struct qla27xx_image_status *pri_image_status,
7907 struct qla27xx_image_status *sec_image_status)
7909 /* calculate generation delta as uint16 (this accounts for wrap) */
7911 le16_to_cpu(pri_image_status->generation) -
7912 le16_to_cpu(sec_image_status->generation);
7914 ql_dbg(ql_dbg_init, NULL, 0x0180, "generation delta = %d\n", delta);
7920 qla28xx_get_aux_images(
7921 struct scsi_qla_host *vha, struct active_regions *active_regions)
7923 struct qla_hw_data *ha = vha->hw;
7924 struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
7925 bool valid_pri_image = false, valid_sec_image = false;
7926 bool active_pri_image = false, active_sec_image = false;
7928 if (!ha->flt_region_aux_img_status_pri) {
7929 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
7930 goto check_sec_image;
7933 qla24xx_read_flash_data(vha, (uint32_t *)&pri_aux_image_status,
7934 ha->flt_region_aux_img_status_pri,
7935 sizeof(pri_aux_image_status) >> 2);
7936 qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
7938 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
7939 ql_dbg(ql_dbg_init, vha, 0x018b,
7940 "Primary aux image signature (%#x) not valid\n",
7941 le32_to_cpu(pri_aux_image_status.signature));
7942 goto check_sec_image;
7945 if (qla27xx_image_status_checksum(&pri_aux_image_status)) {
7946 ql_dbg(ql_dbg_init, vha, 0x018c,
7947 "Primary aux image checksum failed\n");
7948 goto check_sec_image;
7951 valid_pri_image = true;
7953 if (pri_aux_image_status.image_status_mask & 1) {
7954 ql_dbg(ql_dbg_init, vha, 0x018d,
7955 "Primary aux image is active\n");
7956 active_pri_image = true;
7960 if (!ha->flt_region_aux_img_status_sec) {
7961 ql_dbg(ql_dbg_init, vha, 0x018a,
7962 "Secondary aux image not addressed\n");
7963 goto check_valid_image;
7966 qla24xx_read_flash_data(vha, (uint32_t *)&sec_aux_image_status,
7967 ha->flt_region_aux_img_status_sec,
7968 sizeof(sec_aux_image_status) >> 2);
7969 qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
7971 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
7972 ql_dbg(ql_dbg_init, vha, 0x018b,
7973 "Secondary aux image signature (%#x) not valid\n",
7974 le32_to_cpu(sec_aux_image_status.signature));
7975 goto check_valid_image;
7978 if (qla27xx_image_status_checksum(&sec_aux_image_status)) {
7979 ql_dbg(ql_dbg_init, vha, 0x018c,
7980 "Secondary aux image checksum failed\n");
7981 goto check_valid_image;
7984 valid_sec_image = true;
7986 if (sec_aux_image_status.image_status_mask & 1) {
7987 ql_dbg(ql_dbg_init, vha, 0x018d,
7988 "Secondary aux image is active\n");
7989 active_sec_image = true;
7993 if (valid_pri_image && active_pri_image &&
7994 valid_sec_image && active_sec_image) {
7995 if (qla27xx_compare_image_generation(&pri_aux_image_status,
7996 &sec_aux_image_status) >= 0) {
7997 qla28xx_component_status(active_regions,
7998 &pri_aux_image_status);
8000 qla28xx_component_status(active_regions,
8001 &sec_aux_image_status);
8003 } else if (valid_pri_image && active_pri_image) {
8004 qla28xx_component_status(active_regions, &pri_aux_image_status);
8005 } else if (valid_sec_image && active_sec_image) {
8006 qla28xx_component_status(active_regions, &sec_aux_image_status);
8009 ql_dbg(ql_dbg_init, vha, 0x018f,
8010 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u, NVME=%u\n",
8011 active_regions->aux.board_config,
8012 active_regions->aux.vpd_nvram,
8013 active_regions->aux.npiv_config_0_1,
8014 active_regions->aux.npiv_config_2_3,
8015 active_regions->aux.nvme_params);
8019 qla27xx_get_active_image(struct scsi_qla_host *vha,
8020 struct active_regions *active_regions)
8022 struct qla_hw_data *ha = vha->hw;
8023 struct qla27xx_image_status pri_image_status, sec_image_status;
8024 bool valid_pri_image = false, valid_sec_image = false;
8025 bool active_pri_image = false, active_sec_image = false;
8027 if (!ha->flt_region_img_status_pri) {
8028 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
8029 goto check_sec_image;
8032 if (qla24xx_read_flash_data(vha, (uint32_t *)&pri_image_status,
8033 ha->flt_region_img_status_pri, sizeof(pri_image_status) >> 2) !=
8036 goto check_sec_image;
8038 qla27xx_print_image(vha, "Primary image", &pri_image_status);
8040 if (qla27xx_check_image_status_signature(&pri_image_status)) {
8041 ql_dbg(ql_dbg_init, vha, 0x018b,
8042 "Primary image signature (%#x) not valid\n",
8043 le32_to_cpu(pri_image_status.signature));
8044 goto check_sec_image;
8047 if (qla27xx_image_status_checksum(&pri_image_status)) {
8048 ql_dbg(ql_dbg_init, vha, 0x018c,
8049 "Primary image checksum failed\n");
8050 goto check_sec_image;
8053 valid_pri_image = true;
8055 if (pri_image_status.image_status_mask & 1) {
8056 ql_dbg(ql_dbg_init, vha, 0x018d,
8057 "Primary image is active\n");
8058 active_pri_image = true;
8062 if (!ha->flt_region_img_status_sec) {
8063 ql_dbg(ql_dbg_init, vha, 0x018a, "Secondary image not addressed\n");
8064 goto check_valid_image;
8067 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
8068 ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
8069 qla27xx_print_image(vha, "Secondary image", &sec_image_status);
8071 if (qla27xx_check_image_status_signature(&sec_image_status)) {
8072 ql_dbg(ql_dbg_init, vha, 0x018b,
8073 "Secondary image signature (%#x) not valid\n",
8074 le32_to_cpu(sec_image_status.signature));
8075 goto check_valid_image;
8078 if (qla27xx_image_status_checksum(&sec_image_status)) {
8079 ql_dbg(ql_dbg_init, vha, 0x018c,
8080 "Secondary image checksum failed\n");
8081 goto check_valid_image;
8084 valid_sec_image = true;
8086 if (sec_image_status.image_status_mask & 1) {
8087 ql_dbg(ql_dbg_init, vha, 0x018d,
8088 "Secondary image is active\n");
8089 active_sec_image = true;
8093 if (valid_pri_image && active_pri_image)
8094 active_regions->global = QLA27XX_PRIMARY_IMAGE;
8096 if (valid_sec_image && active_sec_image) {
8097 if (!active_regions->global ||
8098 qla27xx_compare_image_generation(
8099 &pri_image_status, &sec_image_status) < 0) {
8100 active_regions->global = QLA27XX_SECONDARY_IMAGE;
8104 ql_dbg(ql_dbg_init, vha, 0x018f, "active image %s (%u)\n",
8105 active_regions->global == QLA27XX_DEFAULT_IMAGE ?
8106 "default (boot/fw)" :
8107 active_regions->global == QLA27XX_PRIMARY_IMAGE ?
8109 active_regions->global == QLA27XX_SECONDARY_IMAGE ?
8110 "secondary" : "invalid",
8111 active_regions->global);
8114 bool qla24xx_risc_firmware_invalid(uint32_t *dword)
8117 !(dword[4] | dword[5] | dword[6] | dword[7]) ||
8118 !(~dword[4] | ~dword[5] | ~dword[6] | ~dword[7]);
8122 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
8126 uint templates, segments, fragment;
8131 uint32_t risc_addr, risc_size, risc_attr = 0;
8132 struct qla_hw_data *ha = vha->hw;
8133 struct req_que *req = ha->req_q_map[0];
8134 struct fwdt *fwdt = ha->fwdt;
8136 ql_dbg(ql_dbg_init, vha, 0x008b,
8137 "FW: Loading firmware from flash (%x).\n", faddr);
8139 dcode = (uint32_t *)req->ring;
8140 qla24xx_read_flash_data(vha, dcode, faddr, 8);
8141 if (qla24xx_risc_firmware_invalid(dcode)) {
8142 ql_log(ql_log_fatal, vha, 0x008c,
8143 "Unable to verify the integrity of flash firmware "
8145 ql_log(ql_log_fatal, vha, 0x008d,
8146 "Firmware data: %08x %08x %08x %08x.\n",
8147 dcode[0], dcode[1], dcode[2], dcode[3]);
8149 return QLA_FUNCTION_FAILED;
8152 dcode = (uint32_t *)req->ring;
8154 segments = FA_RISC_CODE_SEGMENTS;
8155 for (j = 0; j < segments; j++) {
8156 ql_dbg(ql_dbg_init, vha, 0x008d,
8157 "-> Loading segment %u...\n", j);
8158 qla24xx_read_flash_data(vha, dcode, faddr, 10);
8159 risc_addr = be32_to_cpu((__force __be32)dcode[2]);
8160 risc_size = be32_to_cpu((__force __be32)dcode[3]);
8162 *srisc_addr = risc_addr;
8163 risc_attr = be32_to_cpu((__force __be32)dcode[9]);
8166 dlen = ha->fw_transfer_size >> 2;
8167 for (fragment = 0; risc_size; fragment++) {
8168 if (dlen > risc_size)
8171 ql_dbg(ql_dbg_init, vha, 0x008e,
8172 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
8173 fragment, risc_addr, faddr, dlen);
8174 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
8175 for (i = 0; i < dlen; i++)
8176 dcode[i] = swab32(dcode[i]);
8178 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
8180 ql_log(ql_log_fatal, vha, 0x008f,
8181 "-> Failed load firmware fragment %u.\n",
8183 return QLA_FUNCTION_FAILED;
8192 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8195 templates = (risc_attr & BIT_9) ? 2 : 1;
8196 ql_dbg(ql_dbg_init, vha, 0x0160, "-> templates = %u\n", templates);
8197 for (j = 0; j < templates; j++, fwdt++) {
8198 vfree(fwdt->template);
8199 fwdt->template = NULL;
8202 dcode = (uint32_t *)req->ring;
8203 qla24xx_read_flash_data(vha, dcode, faddr, 7);
8204 risc_size = be32_to_cpu((__force __be32)dcode[2]);
8205 ql_dbg(ql_dbg_init, vha, 0x0161,
8206 "-> fwdt%u template array at %#x (%#x dwords)\n",
8207 j, faddr, risc_size);
8208 if (!risc_size || !~risc_size) {
8209 ql_dbg(ql_dbg_init, vha, 0x0162,
8210 "-> fwdt%u failed to read array\n", j);
8214 /* skip header and ignore checksum */
8218 ql_dbg(ql_dbg_init, vha, 0x0163,
8219 "-> fwdt%u template allocate template %#x words...\n",
8221 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
8222 if (!fwdt->template) {
8223 ql_log(ql_log_warn, vha, 0x0164,
8224 "-> fwdt%u failed allocate template.\n", j);
8228 dcode = fwdt->template;
8229 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
8231 if (!qla27xx_fwdt_template_valid(dcode)) {
8232 ql_log(ql_log_warn, vha, 0x0165,
8233 "-> fwdt%u failed template validate\n", j);
8237 dlen = qla27xx_fwdt_template_size(dcode);
8238 ql_dbg(ql_dbg_init, vha, 0x0166,
8239 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8240 j, dlen, dlen / sizeof(*dcode));
8241 if (dlen > risc_size * sizeof(*dcode)) {
8242 ql_log(ql_log_warn, vha, 0x0167,
8243 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8244 j, dlen - risc_size * sizeof(*dcode));
8248 fwdt->length = dlen;
8249 ql_dbg(ql_dbg_init, vha, 0x0168,
8250 "-> fwdt%u loaded template ok\n", j);
8252 faddr += risc_size + 1;
8258 vfree(fwdt->template);
8259 fwdt->template = NULL;
8265 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
8268 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8274 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
8275 struct fw_blob *blob;
8276 struct qla_hw_data *ha = vha->hw;
8277 struct req_que *req = ha->req_q_map[0];
8279 /* Load firmware blob. */
8280 blob = qla2x00_request_firmware(vha);
8282 ql_log(ql_log_info, vha, 0x0083,
8283 "Firmware image unavailable.\n");
8284 ql_log(ql_log_info, vha, 0x0084,
8285 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
8286 return QLA_FUNCTION_FAILED;
8291 wcode = (uint16_t *)req->ring;
8293 fwcode = (__force __be16 *)blob->fw->data;
8296 /* Validate firmware image by checking version. */
8297 if (blob->fw->size < 8 * sizeof(uint16_t)) {
8298 ql_log(ql_log_fatal, vha, 0x0085,
8299 "Unable to verify integrity of firmware image (%zd).\n",
8301 goto fail_fw_integrity;
8303 for (i = 0; i < 4; i++)
8304 wcode[i] = be16_to_cpu(fwcode[i + 4]);
8305 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
8306 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
8307 wcode[2] == 0 && wcode[3] == 0)) {
8308 ql_log(ql_log_fatal, vha, 0x0086,
8309 "Unable to verify integrity of firmware image.\n");
8310 ql_log(ql_log_fatal, vha, 0x0087,
8311 "Firmware data: %04x %04x %04x %04x.\n",
8312 wcode[0], wcode[1], wcode[2], wcode[3]);
8313 goto fail_fw_integrity;
8317 while (*seg && rval == QLA_SUCCESS) {
8319 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
8320 risc_size = be16_to_cpu(fwcode[3]);
8322 /* Validate firmware image size. */
8323 fwclen += risc_size * sizeof(uint16_t);
8324 if (blob->fw->size < fwclen) {
8325 ql_log(ql_log_fatal, vha, 0x0088,
8326 "Unable to verify integrity of firmware image "
8327 "(%zd).\n", blob->fw->size);
8328 goto fail_fw_integrity;
8332 while (risc_size > 0 && rval == QLA_SUCCESS) {
8333 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
8334 if (wlen > risc_size)
8336 ql_dbg(ql_dbg_init, vha, 0x0089,
8337 "Loading risc segment@ risc addr %x number of "
8338 "words 0x%x.\n", risc_addr, wlen);
8340 for (i = 0; i < wlen; i++)
8341 wcode[i] = swab16((__force u32)fwcode[i]);
8343 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
8346 ql_log(ql_log_fatal, vha, 0x008a,
8347 "Failed to load segment %d of firmware.\n",
8364 return QLA_FUNCTION_FAILED;
8368 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8371 uint templates, segments, fragment;
8374 uint32_t risc_addr, risc_size, risc_attr = 0;
8377 struct fw_blob *blob;
8379 struct qla_hw_data *ha = vha->hw;
8380 struct req_que *req = ha->req_q_map[0];
8381 struct fwdt *fwdt = ha->fwdt;
8383 ql_dbg(ql_dbg_init, vha, 0x0090,
8384 "-> FW: Loading via request-firmware.\n");
8386 blob = qla2x00_request_firmware(vha);
8388 ql_log(ql_log_warn, vha, 0x0092,
8389 "-> Firmware file not found.\n");
8391 return QLA_FUNCTION_FAILED;
8394 fwcode = (__force __be32 *)blob->fw->data;
8395 dcode = (__force uint32_t *)fwcode;
8396 if (qla24xx_risc_firmware_invalid(dcode)) {
8397 ql_log(ql_log_fatal, vha, 0x0093,
8398 "Unable to verify integrity of firmware image (%zd).\n",
8400 ql_log(ql_log_fatal, vha, 0x0095,
8401 "Firmware data: %08x %08x %08x %08x.\n",
8402 dcode[0], dcode[1], dcode[2], dcode[3]);
8403 return QLA_FUNCTION_FAILED;
8406 dcode = (uint32_t *)req->ring;
8408 segments = FA_RISC_CODE_SEGMENTS;
8409 for (j = 0; j < segments; j++) {
8410 ql_dbg(ql_dbg_init, vha, 0x0096,
8411 "-> Loading segment %u...\n", j);
8412 risc_addr = be32_to_cpu(fwcode[2]);
8413 risc_size = be32_to_cpu(fwcode[3]);
8416 *srisc_addr = risc_addr;
8417 risc_attr = be32_to_cpu(fwcode[9]);
8420 dlen = ha->fw_transfer_size >> 2;
8421 for (fragment = 0; risc_size; fragment++) {
8422 if (dlen > risc_size)
8425 ql_dbg(ql_dbg_init, vha, 0x0097,
8426 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
8427 fragment, risc_addr,
8428 (uint32_t)(fwcode - (typeof(fwcode))blob->fw->data),
8431 for (i = 0; i < dlen; i++)
8432 dcode[i] = swab32((__force u32)fwcode[i]);
8434 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
8436 ql_log(ql_log_fatal, vha, 0x0098,
8437 "-> Failed load firmware fragment %u.\n",
8439 return QLA_FUNCTION_FAILED;
8448 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8451 templates = (risc_attr & BIT_9) ? 2 : 1;
8452 ql_dbg(ql_dbg_init, vha, 0x0170, "-> templates = %u\n", templates);
8453 for (j = 0; j < templates; j++, fwdt++) {
8454 vfree(fwdt->template);
8455 fwdt->template = NULL;
8458 risc_size = be32_to_cpu(fwcode[2]);
8459 ql_dbg(ql_dbg_init, vha, 0x0171,
8460 "-> fwdt%u template array at %#x (%#x dwords)\n",
8461 j, (uint32_t)((void *)fwcode - (void *)blob->fw->data),
8463 if (!risc_size || !~risc_size) {
8464 ql_dbg(ql_dbg_init, vha, 0x0172,
8465 "-> fwdt%u failed to read array\n", j);
8469 /* skip header and ignore checksum */
8473 ql_dbg(ql_dbg_init, vha, 0x0173,
8474 "-> fwdt%u template allocate template %#x words...\n",
8476 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
8477 if (!fwdt->template) {
8478 ql_log(ql_log_warn, vha, 0x0174,
8479 "-> fwdt%u failed allocate template.\n", j);
8483 dcode = fwdt->template;
8484 for (i = 0; i < risc_size; i++)
8485 dcode[i] = (__force u32)fwcode[i];
8487 if (!qla27xx_fwdt_template_valid(dcode)) {
8488 ql_log(ql_log_warn, vha, 0x0175,
8489 "-> fwdt%u failed template validate\n", j);
8493 dlen = qla27xx_fwdt_template_size(dcode);
8494 ql_dbg(ql_dbg_init, vha, 0x0176,
8495 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8496 j, dlen, dlen / sizeof(*dcode));
8497 if (dlen > risc_size * sizeof(*dcode)) {
8498 ql_log(ql_log_warn, vha, 0x0177,
8499 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8500 j, dlen - risc_size * sizeof(*dcode));
8504 fwdt->length = dlen;
8505 ql_dbg(ql_dbg_init, vha, 0x0178,
8506 "-> fwdt%u loaded template ok\n", j);
8508 fwcode += risc_size + 1;
8514 vfree(fwdt->template);
8515 fwdt->template = NULL;
8522 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8526 if (ql2xfwloadbin == 1)
8527 return qla81xx_load_risc(vha, srisc_addr);
8531 * 1) Firmware via request-firmware interface (.bin file).
8532 * 2) Firmware residing in flash.
8534 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8535 if (rval == QLA_SUCCESS)
8538 return qla24xx_load_risc_flash(vha, srisc_addr,
8539 vha->hw->flt_region_fw);
8543 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8546 struct qla_hw_data *ha = vha->hw;
8547 struct active_regions active_regions = { };
8549 if (ql2xfwloadbin == 2)
8552 /* FW Load priority:
8553 * 1) Firmware residing in flash.
8554 * 2) Firmware via request-firmware interface (.bin file).
8555 * 3) Golden-Firmware residing in flash -- (limited operation).
8558 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8559 goto try_primary_fw;
8561 qla27xx_get_active_image(vha, &active_regions);
8563 if (active_regions.global != QLA27XX_SECONDARY_IMAGE)
8564 goto try_primary_fw;
8566 ql_dbg(ql_dbg_init, vha, 0x008b,
8567 "Loading secondary firmware image.\n");
8568 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw_sec);
8573 ql_dbg(ql_dbg_init, vha, 0x008b,
8574 "Loading primary firmware image.\n");
8575 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
8580 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8581 if (!rval || !ha->flt_region_gold_fw)
8584 ql_log(ql_log_info, vha, 0x0099,
8585 "Attempting to fallback to golden firmware.\n");
8586 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
8590 ql_log(ql_log_info, vha, 0x009a, "Need firmware flash update.\n");
8591 ha->flags.running_gold_fw = 1;
8596 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
8599 struct qla_hw_data *ha = vha->hw;
8601 if (ha->flags.pci_channel_io_perm_failure)
8603 if (!IS_FWI2_CAPABLE(ha))
8605 if (!ha->fw_major_version)
8607 if (!ha->flags.fw_started)
8610 ret = qla2x00_stop_firmware(vha);
8611 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
8612 ret != QLA_INVALID_COMMAND && retries ; retries--) {
8613 ha->isp_ops->reset_chip(vha);
8614 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
8616 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
8618 ql_log(ql_log_info, vha, 0x8015,
8619 "Attempting retry of stop-firmware command.\n");
8620 ret = qla2x00_stop_firmware(vha);
8624 ha->flags.fw_init_done = 0;
8628 qla24xx_configure_vhba(scsi_qla_host_t *vha)
8630 int rval = QLA_SUCCESS;
8632 uint16_t mb[MAILBOX_REGISTER_COUNT];
8633 struct qla_hw_data *ha = vha->hw;
8634 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
8639 rval = qla2x00_fw_ready(base_vha);
8641 if (rval == QLA_SUCCESS) {
8642 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8643 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8646 vha->flags.management_server_logged_in = 0;
8648 /* Login to SNS first */
8649 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
8651 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
8652 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
8653 ql_dbg(ql_dbg_init, vha, 0x0120,
8654 "Failed SNS login: loop_id=%x, rval2=%d\n",
8657 ql_dbg(ql_dbg_init, vha, 0x0103,
8658 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
8659 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
8660 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
8661 return (QLA_FUNCTION_FAILED);
8664 atomic_set(&vha->loop_down_timer, 0);
8665 atomic_set(&vha->loop_state, LOOP_UP);
8666 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8667 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
8668 rval = qla2x00_loop_resync(base_vha);
8673 /* 84XX Support **************************************************************/
8675 static LIST_HEAD(qla_cs84xx_list);
8676 static DEFINE_MUTEX(qla_cs84xx_mutex);
8678 static struct qla_chip_state_84xx *
8679 qla84xx_get_chip(struct scsi_qla_host *vha)
8681 struct qla_chip_state_84xx *cs84xx;
8682 struct qla_hw_data *ha = vha->hw;
8684 mutex_lock(&qla_cs84xx_mutex);
8686 /* Find any shared 84xx chip. */
8687 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
8688 if (cs84xx->bus == ha->pdev->bus) {
8689 kref_get(&cs84xx->kref);
8694 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
8698 kref_init(&cs84xx->kref);
8699 spin_lock_init(&cs84xx->access_lock);
8700 mutex_init(&cs84xx->fw_update_mutex);
8701 cs84xx->bus = ha->pdev->bus;
8703 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
8705 mutex_unlock(&qla_cs84xx_mutex);
8710 __qla84xx_chip_release(struct kref *kref)
8712 struct qla_chip_state_84xx *cs84xx =
8713 container_of(kref, struct qla_chip_state_84xx, kref);
8715 mutex_lock(&qla_cs84xx_mutex);
8716 list_del(&cs84xx->list);
8717 mutex_unlock(&qla_cs84xx_mutex);
8722 qla84xx_put_chip(struct scsi_qla_host *vha)
8724 struct qla_hw_data *ha = vha->hw;
8727 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
8731 qla84xx_init_chip(scsi_qla_host_t *vha)
8735 struct qla_hw_data *ha = vha->hw;
8737 mutex_lock(&ha->cs84xx->fw_update_mutex);
8739 rval = qla84xx_verify_chip(vha, status);
8741 mutex_unlock(&ha->cs84xx->fw_update_mutex);
8743 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED :
8747 /* 81XX Support **************************************************************/
8750 qla81xx_nvram_config(scsi_qla_host_t *vha)
8753 struct init_cb_81xx *icb;
8754 struct nvram_81xx *nv;
8756 uint8_t *dptr1, *dptr2;
8759 struct qla_hw_data *ha = vha->hw;
8761 struct active_regions active_regions = { };
8764 icb = (struct init_cb_81xx *)ha->init_cb;
8767 /* Determine NVRAM starting address. */
8768 ha->nvram_size = sizeof(*nv);
8769 ha->vpd_size = FA_NVRAM_VPD_SIZE;
8770 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
8771 ha->vpd_size = FA_VPD_SIZE_82XX;
8773 if (IS_QLA28XX(ha) || IS_QLA27XX(ha))
8774 qla28xx_get_aux_images(vha, &active_regions);
8776 /* Get VPD data into cache */
8777 ha->vpd = ha->nvram + VPD_OFFSET;
8779 faddr = ha->flt_region_vpd;
8780 if (IS_QLA28XX(ha)) {
8781 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8782 faddr = ha->flt_region_vpd_sec;
8783 ql_dbg(ql_dbg_init, vha, 0x0110,
8784 "Loading %s nvram image.\n",
8785 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8786 "primary" : "secondary");
8788 ha->isp_ops->read_optrom(vha, ha->vpd, faddr << 2, ha->vpd_size);
8790 /* Get NVRAM data into cache and calculate checksum. */
8791 faddr = ha->flt_region_nvram;
8792 if (IS_QLA28XX(ha)) {
8793 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8794 faddr = ha->flt_region_nvram_sec;
8796 ql_dbg(ql_dbg_init, vha, 0x0110,
8797 "Loading %s nvram image.\n",
8798 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8799 "primary" : "secondary");
8800 ha->isp_ops->read_optrom(vha, ha->nvram, faddr << 2, ha->nvram_size);
8802 dptr = (__force __le32 *)nv;
8803 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
8804 chksum += le32_to_cpu(*dptr);
8806 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
8807 "Contents of NVRAM:\n");
8808 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
8809 nv, ha->nvram_size);
8811 /* Bad NVRAM data, set defaults parameters. */
8812 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
8813 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
8814 /* Reset NVRAM data. */
8815 ql_log(ql_log_info, vha, 0x0073,
8816 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
8817 chksum, nv->id, le16_to_cpu(nv->nvram_version));
8818 ql_dump_buffer(ql_dbg_init, vha, 0x0073, nv, sizeof(*nv));
8819 ql_log(ql_log_info, vha, 0x0074,
8820 "Falling back to functioning (yet invalid -- WWPN) "
8824 * Set default initialization control block.
8826 memset(nv, 0, ha->nvram_size);
8827 nv->nvram_version = cpu_to_le16(ICB_VERSION);
8828 nv->version = cpu_to_le16(ICB_VERSION);
8829 nv->frame_payload_size = cpu_to_le16(2048);
8830 nv->execution_throttle = cpu_to_le16(0xFFFF);
8831 nv->exchange_count = cpu_to_le16(0);
8832 nv->port_name[0] = 0x21;
8833 nv->port_name[1] = 0x00 + ha->port_no + 1;
8834 nv->port_name[2] = 0x00;
8835 nv->port_name[3] = 0xe0;
8836 nv->port_name[4] = 0x8b;
8837 nv->port_name[5] = 0x1c;
8838 nv->port_name[6] = 0x55;
8839 nv->port_name[7] = 0x86;
8840 nv->node_name[0] = 0x20;
8841 nv->node_name[1] = 0x00;
8842 nv->node_name[2] = 0x00;
8843 nv->node_name[3] = 0xe0;
8844 nv->node_name[4] = 0x8b;
8845 nv->node_name[5] = 0x1c;
8846 nv->node_name[6] = 0x55;
8847 nv->node_name[7] = 0x86;
8848 nv->login_retry_count = cpu_to_le16(8);
8849 nv->interrupt_delay_timer = cpu_to_le16(0);
8850 nv->login_timeout = cpu_to_le16(0);
8851 nv->firmware_options_1 =
8852 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
8853 nv->firmware_options_2 = cpu_to_le32(2 << 4);
8854 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
8855 nv->firmware_options_3 = cpu_to_le32(2 << 13);
8856 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
8857 nv->efi_parameters = cpu_to_le32(0);
8858 nv->reset_delay = 5;
8859 nv->max_luns_per_target = cpu_to_le16(128);
8860 nv->port_down_retry_count = cpu_to_le16(30);
8861 nv->link_down_timeout = cpu_to_le16(180);
8862 nv->enode_mac[0] = 0x00;
8863 nv->enode_mac[1] = 0xC0;
8864 nv->enode_mac[2] = 0xDD;
8865 nv->enode_mac[3] = 0x04;
8866 nv->enode_mac[4] = 0x05;
8867 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
8872 if (IS_T10_PI_CAPABLE(ha))
8873 nv->frame_payload_size &= cpu_to_le16(~7);
8875 qlt_81xx_config_nvram_stage1(vha, nv);
8877 /* Reset Initialization control block */
8878 memset(icb, 0, ha->init_cb_size);
8880 /* Copy 1st segment. */
8881 dptr1 = (uint8_t *)icb;
8882 dptr2 = (uint8_t *)&nv->version;
8883 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
8885 *dptr1++ = *dptr2++;
8887 icb->login_retry_count = nv->login_retry_count;
8889 /* Copy 2nd segment. */
8890 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
8891 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
8892 cnt = (uint8_t *)&icb->reserved_5 -
8893 (uint8_t *)&icb->interrupt_delay_timer;
8895 *dptr1++ = *dptr2++;
8897 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
8898 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8899 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
8900 icb->enode_mac[0] = 0x00;
8901 icb->enode_mac[1] = 0xC0;
8902 icb->enode_mac[2] = 0xDD;
8903 icb->enode_mac[3] = 0x04;
8904 icb->enode_mac[4] = 0x05;
8905 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
8908 /* Use extended-initialization control block. */
8909 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
8910 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
8912 * Setup driver NVRAM options.
8914 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
8917 qlt_81xx_config_nvram_stage2(vha, icb);
8919 /* Use alternate WWN? */
8920 if (nv->host_p & cpu_to_le32(BIT_15)) {
8921 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
8922 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
8925 /* Prepare nodename */
8926 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
8928 * Firmware will apply the following mask if the nodename was
8931 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
8932 icb->node_name[0] &= 0xF0;
8935 if (IS_QLA28XX(ha) || IS_QLA27XX(ha)) {
8936 if ((nv->enhanced_features & BIT_7) == 0)
8937 ha->flags.scm_supported_a = 1;
8940 /* Set host adapter parameters. */
8941 ha->flags.disable_risc_code_load = 0;
8942 ha->flags.enable_lip_reset = 0;
8943 ha->flags.enable_lip_full_login =
8944 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
8945 ha->flags.enable_target_reset =
8946 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
8947 ha->flags.enable_led_scheme = 0;
8948 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
8950 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
8951 (BIT_6 | BIT_5 | BIT_4)) >> 4;
8953 /* save HBA serial number */
8954 ha->serial0 = icb->port_name[5];
8955 ha->serial1 = icb->port_name[6];
8956 ha->serial2 = icb->port_name[7];
8957 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
8958 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
8960 icb->execution_throttle = cpu_to_le16(0xFFFF);
8962 ha->retry_count = le16_to_cpu(nv->login_retry_count);
8964 /* Set minimum login_timeout to 4 seconds. */
8965 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
8966 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
8967 if (le16_to_cpu(nv->login_timeout) < 4)
8968 nv->login_timeout = cpu_to_le16(4);
8969 ha->login_timeout = le16_to_cpu(nv->login_timeout);
8971 /* Set minimum RATOV to 100 tenths of a second. */
8974 ha->loop_reset_delay = nv->reset_delay;
8976 /* Link Down Timeout = 0:
8978 * When Port Down timer expires we will start returning
8979 * I/O's to OS with "DID_NO_CONNECT".
8981 * Link Down Timeout != 0:
8983 * The driver waits for the link to come up after link down
8984 * before returning I/Os to OS with "DID_NO_CONNECT".
8986 if (le16_to_cpu(nv->link_down_timeout) == 0) {
8987 ha->loop_down_abort_time =
8988 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
8990 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
8991 ha->loop_down_abort_time =
8992 (LOOP_DOWN_TIME - ha->link_down_timeout);
8995 /* Need enough time to try and get the port back. */
8996 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8997 if (qlport_down_retry)
8998 ha->port_down_retry_count = qlport_down_retry;
9000 /* Set login_retry_count */
9001 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
9002 if (ha->port_down_retry_count ==
9003 le16_to_cpu(nv->port_down_retry_count) &&
9004 ha->port_down_retry_count > 3)
9005 ha->login_retry_count = ha->port_down_retry_count;
9006 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
9007 ha->login_retry_count = ha->port_down_retry_count;
9008 if (ql2xloginretrycount)
9009 ha->login_retry_count = ql2xloginretrycount;
9011 /* if not running MSI-X we need handshaking on interrupts */
9012 if (!vha->hw->flags.msix_enabled &&
9013 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)))
9014 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
9017 if (!vha->flags.init_done) {
9018 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
9019 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
9020 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
9021 le16_to_cpu(icb->interrupt_delay_timer) : 2;
9023 icb->firmware_options_2 &= cpu_to_le32(
9024 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
9025 vha->flags.process_response_queue = 0;
9026 if (ha->zio_mode != QLA_ZIO_DISABLED) {
9027 ha->zio_mode = QLA_ZIO_MODE_6;
9029 ql_log(ql_log_info, vha, 0x0075,
9030 "ZIO mode %d enabled; timer delay (%d us).\n",
9032 ha->zio_timer * 100);
9034 icb->firmware_options_2 |= cpu_to_le32(
9035 (uint32_t)ha->zio_mode);
9036 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
9037 vha->flags.process_response_queue = 1;
9040 /* enable RIDA Format2 */
9041 icb->firmware_options_3 |= cpu_to_le32(BIT_0);
9043 /* N2N: driver will initiate Login instead of FW */
9044 icb->firmware_options_3 |= cpu_to_le32(BIT_8);
9046 /* Determine NVMe/FCP priority for target ports */
9047 ha->fc4_type_priority = qla2xxx_get_fc4_priority(vha);
9050 ql_log(ql_log_warn, vha, 0x0076,
9051 "NVRAM configuration failed.\n");
9057 qla82xx_restart_isp(scsi_qla_host_t *vha)
9060 struct qla_hw_data *ha = vha->hw;
9061 struct scsi_qla_host *vp, *tvp;
9062 unsigned long flags;
9064 status = qla2x00_init_rings(vha);
9066 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
9067 ha->flags.chip_reset_done = 1;
9069 status = qla2x00_fw_ready(vha);
9071 /* Issue a marker after FW becomes ready. */
9072 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
9073 vha->flags.online = 1;
9074 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
9077 /* if no cable then assume it's good */
9078 if ((vha->device_flags & DFLG_NO_CABLE))
9083 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
9085 if (!atomic_read(&vha->loop_down_timer)) {
9087 * Issue marker command only when we are going
9088 * to start the I/O .
9090 vha->marker_needed = 1;
9093 ha->isp_ops->enable_intrs(ha);
9095 ha->isp_abort_cnt = 0;
9096 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
9098 /* Update the firmware version */
9099 status = qla82xx_check_md_needed(vha);
9102 ha->flags.fce_enabled = 1;
9104 fce_calc_size(ha->fce_bufs));
9105 rval = qla2x00_enable_fce_trace(vha,
9106 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
9109 ql_log(ql_log_warn, vha, 0x8001,
9110 "Unable to reinitialize FCE (%d).\n",
9112 ha->flags.fce_enabled = 0;
9117 memset(ha->eft, 0, EFT_SIZE);
9118 rval = qla2x00_enable_eft_trace(vha,
9119 ha->eft_dma, EFT_NUM_BUFFERS);
9121 ql_log(ql_log_warn, vha, 0x8010,
9122 "Unable to reinitialize EFT (%d).\n",
9129 ql_dbg(ql_dbg_taskm, vha, 0x8011,
9130 "qla82xx_restart_isp succeeded.\n");
9132 spin_lock_irqsave(&ha->vport_slock, flags);
9133 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
9135 atomic_inc(&vp->vref_count);
9136 spin_unlock_irqrestore(&ha->vport_slock, flags);
9138 qla2x00_vp_abort_isp(vp);
9140 spin_lock_irqsave(&ha->vport_slock, flags);
9141 atomic_dec(&vp->vref_count);
9144 spin_unlock_irqrestore(&ha->vport_slock, flags);
9147 ql_log(ql_log_warn, vha, 0x8016,
9148 "qla82xx_restart_isp **** FAILED ****.\n");
9155 * qla24xx_get_fcp_prio
9156 * Gets the fcp cmd priority value for the logged in port.
9157 * Looks for a match of the port descriptors within
9158 * each of the fcp prio config entries. If a match is found,
9159 * the tag (priority) value is returned.
9162 * vha = scsi host structure pointer.
9163 * fcport = port structure pointer.
9166 * non-zero (if found)
9173 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
9176 uint8_t pid_match, wwn_match;
9178 uint32_t pid1, pid2;
9179 uint64_t wwn1, wwn2;
9180 struct qla_fcp_prio_entry *pri_entry;
9181 struct qla_hw_data *ha = vha->hw;
9183 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
9187 entries = ha->fcp_prio_cfg->num_entries;
9188 pri_entry = &ha->fcp_prio_cfg->entry[0];
9190 for (i = 0; i < entries; i++) {
9191 pid_match = wwn_match = 0;
9193 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
9198 /* check source pid for a match */
9199 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
9200 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
9201 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
9202 if (pid1 == INVALID_PORT_ID)
9204 else if (pid1 == pid2)
9208 /* check destination pid for a match */
9209 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
9210 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
9211 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
9212 if (pid1 == INVALID_PORT_ID)
9214 else if (pid1 == pid2)
9218 /* check source WWN for a match */
9219 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
9220 wwn1 = wwn_to_u64(vha->port_name);
9221 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
9222 if (wwn2 == (uint64_t)-1)
9224 else if (wwn1 == wwn2)
9228 /* check destination WWN for a match */
9229 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
9230 wwn1 = wwn_to_u64(fcport->port_name);
9231 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
9232 if (wwn2 == (uint64_t)-1)
9234 else if (wwn1 == wwn2)
9238 if (pid_match == 2 || wwn_match == 2) {
9239 /* Found a matching entry */
9240 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
9241 priority = pri_entry->tag;
9252 * qla24xx_update_fcport_fcp_prio
9253 * Activates fcp priority for the logged in fc port
9256 * vha = scsi host structure pointer.
9257 * fcp = port structure pointer.
9260 * QLA_SUCCESS or QLA_FUNCTION_FAILED
9266 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
9272 if (fcport->port_type != FCT_TARGET ||
9273 fcport->loop_id == FC_NO_LOOP_ID)
9274 return QLA_FUNCTION_FAILED;
9276 priority = qla24xx_get_fcp_prio(vha, fcport);
9278 return QLA_FUNCTION_FAILED;
9280 if (IS_P3P_TYPE(vha->hw)) {
9281 fcport->fcp_prio = priority & 0xf;
9285 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
9286 if (ret == QLA_SUCCESS) {
9287 if (fcport->fcp_prio != priority)
9288 ql_dbg(ql_dbg_user, vha, 0x709e,
9289 "Updated FCP_CMND priority - value=%d loop_id=%d "
9290 "port_id=%02x%02x%02x.\n", priority,
9291 fcport->loop_id, fcport->d_id.b.domain,
9292 fcport->d_id.b.area, fcport->d_id.b.al_pa);
9293 fcport->fcp_prio = priority & 0xf;
9295 ql_dbg(ql_dbg_user, vha, 0x704f,
9296 "Unable to update FCP_CMND priority - ret=0x%x for "
9297 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
9298 fcport->d_id.b.domain, fcport->d_id.b.area,
9299 fcport->d_id.b.al_pa);
9304 * qla24xx_update_all_fcp_prio
9305 * Activates fcp priority for all the logged in ports
9308 * ha = adapter block pointer.
9311 * QLA_SUCCESS or QLA_FUNCTION_FAILED
9317 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
9322 ret = QLA_FUNCTION_FAILED;
9323 /* We need to set priority for all logged in ports */
9324 list_for_each_entry(fcport, &vha->vp_fcports, list)
9325 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
9330 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
9331 int vp_idx, bool startqp)
9336 struct qla_hw_data *ha = vha->hw;
9337 uint16_t qpair_id = 0;
9338 struct qla_qpair *qpair = NULL;
9339 struct qla_msix_entry *msix;
9341 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
9342 ql_log(ql_log_warn, vha, 0x00181,
9343 "FW/Driver is not multi-queue capable.\n");
9347 if (ql2xmqsupport || ql2xnvmeenable) {
9348 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
9349 if (qpair == NULL) {
9350 ql_log(ql_log_warn, vha, 0x0182,
9351 "Failed to allocate memory for queue pair.\n");
9355 qpair->hw = vha->hw;
9357 qpair->qp_lock_ptr = &qpair->qp_lock;
9358 spin_lock_init(&qpair->qp_lock);
9359 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
9361 /* Assign available que pair id */
9362 mutex_lock(&ha->mq_lock);
9363 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
9364 if (ha->num_qpairs >= ha->max_qpairs) {
9365 mutex_unlock(&ha->mq_lock);
9366 ql_log(ql_log_warn, vha, 0x0183,
9367 "No resources to create additional q pair.\n");
9371 set_bit(qpair_id, ha->qpair_qid_map);
9372 ha->queue_pair_map[qpair_id] = qpair;
9373 qpair->id = qpair_id;
9374 qpair->vp_idx = vp_idx;
9375 qpair->fw_started = ha->flags.fw_started;
9376 INIT_LIST_HEAD(&qpair->hints_list);
9377 qpair->chip_reset = ha->base_qpair->chip_reset;
9378 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
9379 qpair->enable_explicit_conf =
9380 ha->base_qpair->enable_explicit_conf;
9382 for (i = 0; i < ha->msix_count; i++) {
9383 msix = &ha->msix_entries[i];
9387 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
9388 "Vector %x selected for qpair\n", msix->vector);
9392 ql_log(ql_log_warn, vha, 0x0184,
9393 "Out of MSI-X vectors!.\n");
9397 qpair->msix->in_use = 1;
9398 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
9399 qpair->pdev = ha->pdev;
9400 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
9401 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
9403 mutex_unlock(&ha->mq_lock);
9405 /* Create response queue first */
9406 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
9408 ql_log(ql_log_warn, vha, 0x0185,
9409 "Failed to create response queue.\n");
9413 qpair->rsp = ha->rsp_q_map[rsp_id];
9415 /* Create request queue */
9416 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
9419 ql_log(ql_log_warn, vha, 0x0186,
9420 "Failed to create request queue.\n");
9424 qpair->req = ha->req_q_map[req_id];
9425 qpair->rsp->req = qpair->req;
9426 qpair->rsp->qpair = qpair;
9428 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
9429 if (ha->fw_attributes & BIT_4)
9430 qpair->difdix_supported = 1;
9433 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
9434 if (!qpair->srb_mempool) {
9435 ql_log(ql_log_warn, vha, 0xd036,
9436 "Failed to create srb mempool for qpair %d\n",
9441 if (qla_create_buf_pool(vha, qpair)) {
9442 ql_log(ql_log_warn, vha, 0xd036,
9443 "Failed to initialize buf pool for qpair %d\n",
9448 /* Mark as online */
9451 if (!vha->flags.qpairs_available)
9452 vha->flags.qpairs_available = 1;
9454 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
9455 "Request/Response queue pair created, id %d\n",
9457 ql_dbg(ql_dbg_init, vha, 0x0187,
9458 "Request/Response queue pair created, id %d\n",
9464 mempool_destroy(qpair->srb_mempool);
9466 qla25xx_delete_req_que(vha, qpair->req);
9468 qla25xx_delete_rsp_que(vha, qpair->rsp);
9470 mutex_lock(&ha->mq_lock);
9471 qpair->msix->in_use = 0;
9472 list_del(&qpair->qp_list_elem);
9473 if (list_empty(&vha->qp_list))
9474 vha->flags.qpairs_available = 0;
9476 ha->queue_pair_map[qpair_id] = NULL;
9477 clear_bit(qpair_id, ha->qpair_qid_map);
9479 mutex_unlock(&ha->mq_lock);
9485 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
9487 int ret = QLA_FUNCTION_FAILED;
9488 struct qla_hw_data *ha = qpair->hw;
9490 qpair->delete_in_progress = 1;
9492 qla_free_buf_pool(qpair);
9494 ret = qla25xx_delete_req_que(vha, qpair->req);
9495 if (ret != QLA_SUCCESS)
9498 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
9499 if (ret != QLA_SUCCESS)
9502 mutex_lock(&ha->mq_lock);
9503 ha->queue_pair_map[qpair->id] = NULL;
9504 clear_bit(qpair->id, ha->qpair_qid_map);
9506 list_del(&qpair->qp_list_elem);
9507 if (list_empty(&vha->qp_list)) {
9508 vha->flags.qpairs_available = 0;
9509 vha->flags.qpairs_req_created = 0;
9510 vha->flags.qpairs_rsp_created = 0;
9512 mempool_destroy(qpair->srb_mempool);
9514 mutex_unlock(&ha->mq_lock);
9522 qla2x00_count_set_bits(uint32_t num)
9524 /* Brian Kernighan's Algorithm */
9535 qla2x00_get_num_tgts(scsi_qla_host_t *vha)
9543 list_for_each_entry_safe(f, tf, &vha->vp_fcports, list) {
9544 if (f->port_type != FCT_TARGET)
9551 int qla2xxx_reset_stats(struct Scsi_Host *host, u32 flags)
9553 scsi_qla_host_t *vha = shost_priv(host);
9554 fc_port_t *fcport = NULL;
9555 unsigned long int_flags;
9557 if (flags & QLA2XX_HW_ERROR)
9558 vha->hw_err_cnt = 0;
9559 if (flags & QLA2XX_SHT_LNK_DWN)
9560 vha->short_link_down_cnt = 0;
9561 if (flags & QLA2XX_INT_ERR)
9562 vha->interface_err_cnt = 0;
9563 if (flags & QLA2XX_CMD_TIMEOUT)
9564 vha->cmd_timeout_cnt = 0;
9565 if (flags & QLA2XX_RESET_CMD_ERR)
9566 vha->reset_cmd_err_cnt = 0;
9567 if (flags & QLA2XX_TGT_SHT_LNK_DOWN) {
9568 spin_lock_irqsave(&vha->hw->tgt.sess_lock, int_flags);
9569 list_for_each_entry(fcport, &vha->vp_fcports, list) {
9570 fcport->tgt_short_link_down_cnt = 0;
9571 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
9573 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, int_flags);
9575 vha->link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
9579 int qla2xxx_start_stats(struct Scsi_Host *host, u32 flags)
9581 return qla2xxx_reset_stats(host, flags);
9584 int qla2xxx_stop_stats(struct Scsi_Host *host, u32 flags)
9586 return qla2xxx_reset_stats(host, flags);
9589 int qla2xxx_get_ini_stats(struct Scsi_Host *host, u32 flags,
9590 void *data, u64 size)
9592 scsi_qla_host_t *vha = shost_priv(host);
9593 struct ql_vnd_host_stats_resp *resp = (struct ql_vnd_host_stats_resp *)data;
9594 struct ql_vnd_stats *rsp_data = &resp->stats;
9595 u64 ini_entry_count = 0;
9597 u64 entry_count = 0;
9599 u32 tmp_stat_type = 0;
9600 fc_port_t *fcport = NULL;
9601 unsigned long int_flags;
9603 /* Copy stat type to work on it */
9604 tmp_stat_type = flags;
9606 if (tmp_stat_type & BIT_17) {
9607 num_tgt = qla2x00_get_num_tgts(vha);
9609 tmp_stat_type &= ~(1 << 17);
9611 ini_entry_count = qla2x00_count_set_bits(tmp_stat_type);
9613 entry_count = ini_entry_count + num_tgt;
9615 rsp_data->entry_count = entry_count;
9618 if (flags & QLA2XX_HW_ERROR) {
9619 rsp_data->entry[i].stat_type = QLA2XX_HW_ERROR;
9620 rsp_data->entry[i].tgt_num = 0x0;
9621 rsp_data->entry[i].cnt = vha->hw_err_cnt;
9625 if (flags & QLA2XX_SHT_LNK_DWN) {
9626 rsp_data->entry[i].stat_type = QLA2XX_SHT_LNK_DWN;
9627 rsp_data->entry[i].tgt_num = 0x0;
9628 rsp_data->entry[i].cnt = vha->short_link_down_cnt;
9632 if (flags & QLA2XX_INT_ERR) {
9633 rsp_data->entry[i].stat_type = QLA2XX_INT_ERR;
9634 rsp_data->entry[i].tgt_num = 0x0;
9635 rsp_data->entry[i].cnt = vha->interface_err_cnt;
9639 if (flags & QLA2XX_CMD_TIMEOUT) {
9640 rsp_data->entry[i].stat_type = QLA2XX_CMD_TIMEOUT;
9641 rsp_data->entry[i].tgt_num = 0x0;
9642 rsp_data->entry[i].cnt = vha->cmd_timeout_cnt;
9646 if (flags & QLA2XX_RESET_CMD_ERR) {
9647 rsp_data->entry[i].stat_type = QLA2XX_RESET_CMD_ERR;
9648 rsp_data->entry[i].tgt_num = 0x0;
9649 rsp_data->entry[i].cnt = vha->reset_cmd_err_cnt;
9653 /* i will continue from previous loop, as target
9654 * entries are after initiator
9656 if (flags & QLA2XX_TGT_SHT_LNK_DOWN) {
9657 spin_lock_irqsave(&vha->hw->tgt.sess_lock, int_flags);
9658 list_for_each_entry(fcport, &vha->vp_fcports, list) {
9659 if (fcport->port_type != FCT_TARGET)
9663 rsp_data->entry[i].stat_type = QLA2XX_TGT_SHT_LNK_DOWN;
9664 rsp_data->entry[i].tgt_num = fcport->rport->number;
9665 rsp_data->entry[i].cnt = fcport->tgt_short_link_down_cnt;
9668 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, int_flags);
9670 resp->status = EXT_STATUS_OK;
9675 int qla2xxx_get_tgt_stats(struct Scsi_Host *host, u32 flags,
9676 struct fc_rport *rport, void *data, u64 size)
9678 struct ql_vnd_tgt_stats_resp *tgt_data = data;
9679 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
9681 tgt_data->status = 0;
9682 tgt_data->stats.entry_count = 1;
9683 tgt_data->stats.entry[0].stat_type = flags;
9684 tgt_data->stats.entry[0].tgt_num = rport->number;
9685 tgt_data->stats.entry[0].cnt = fcport->tgt_short_link_down_cnt;
9690 int qla2xxx_disable_port(struct Scsi_Host *host)
9692 scsi_qla_host_t *vha = shost_priv(host);
9694 vha->hw->flags.port_isolated = 1;
9696 if (qla2x00_isp_reg_stat(vha->hw)) {
9697 ql_log(ql_log_info, vha, 0x9006,
9698 "PCI/Register disconnect, exiting.\n");
9699 qla_pci_set_eeh_busy(vha);
9702 if (qla2x00_chip_is_down(vha))
9705 if (vha->flags.online) {
9706 qla2x00_abort_isp_cleanup(vha);
9707 qla2x00_wait_for_sess_deletion(vha);
9713 int qla2xxx_enable_port(struct Scsi_Host *host)
9715 scsi_qla_host_t *vha = shost_priv(host);
9717 if (qla2x00_isp_reg_stat(vha->hw)) {
9718 ql_log(ql_log_info, vha, 0x9001,
9719 "PCI/Register disconnect, exiting.\n");
9720 qla_pci_set_eeh_busy(vha);
9724 vha->hw->flags.port_isolated = 0;
9725 /* Set the flag to 1, so that isp_abort can proceed */
9726 vha->flags.online = 1;
9727 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
9728 qla2xxx_wake_dpc(vha);