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;
51 WARN_ON(irqs_disabled());
52 iocb = &sp->u.iocb_cmd;
56 kref_put(&sp->cmd_kref, qla2x00_sp_release);
59 void qla2x00_sp_free(srb_t *sp)
61 struct srb_iocb *iocb = &sp->u.iocb_cmd;
63 del_timer(&iocb->timer);
67 void qla2xxx_rel_done_warning(srb_t *sp, int res)
69 WARN_ONCE(1, "Calling done() of an already freed srb %p object\n", sp);
72 void qla2xxx_rel_free_warning(srb_t *sp)
74 WARN_ONCE(1, "Calling free() of an already freed srb %p object\n", sp);
77 /* Asynchronous Login/Logout Routines -------------------------------------- */
80 qla2x00_get_async_timeout(struct scsi_qla_host *vha)
83 struct qla_hw_data *ha = vha->hw;
85 /* Firmware should use switch negotiated r_a_tov for timeout. */
86 tmo = ha->r_a_tov / 10 * 2;
88 tmo = FX00_DEF_RATOV * 2;
89 } else if (!IS_FWI2_CAPABLE(ha)) {
91 * Except for earlier ISPs where the timeout is seeded from the
92 * initialization control block.
94 tmo = ha->login_timeout;
99 static void qla24xx_abort_iocb_timeout(void *data)
102 struct srb_iocb *abt = &sp->u.iocb_cmd;
103 struct qla_qpair *qpair = sp->qpair;
108 ql_dbg(ql_dbg_async, sp->vha, 0x507c,
109 "Abort timeout - cmd hdl=%x, cmd type=%x hdl=%x, type=%x\n",
110 sp->cmd_sp->handle, sp->cmd_sp->type,
111 sp->handle, sp->type);
113 ql_dbg(ql_dbg_async, sp->vha, 0x507c,
114 "Abort timeout 2 - hdl=%x, type=%x\n",
115 sp->handle, sp->type);
117 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
118 for (handle = 1; handle < qpair->req->num_outstanding_cmds; handle++) {
119 if (sp->cmd_sp && (qpair->req->outstanding_cmds[handle] ==
121 qpair->req->outstanding_cmds[handle] = NULL;
123 /* removing the abort */
124 if (qpair->req->outstanding_cmds[handle] == sp) {
125 qpair->req->outstanding_cmds[handle] = NULL;
129 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
133 * This done function should take care of
134 * original command ref: INIT
136 sp->cmd_sp->done(sp->cmd_sp, QLA_OS_TIMER_EXPIRED);
139 abt->u.abt.comp_status = cpu_to_le16(CS_TIMEOUT);
140 sp->done(sp, QLA_OS_TIMER_EXPIRED);
143 static void qla24xx_abort_sp_done(srb_t *sp, int res)
145 struct srb_iocb *abt = &sp->u.iocb_cmd;
146 srb_t *orig_sp = sp->cmd_sp;
149 qla_wait_nvme_release_cmd_kref(orig_sp);
151 if (sp->flags & SRB_WAKEUP_ON_COMP)
152 complete(&abt->u.abt.comp);
155 kref_put(&sp->cmd_kref, qla2x00_sp_release);
158 int qla24xx_async_abort_cmd(srb_t *cmd_sp, bool wait)
160 scsi_qla_host_t *vha = cmd_sp->vha;
161 struct srb_iocb *abt_iocb;
163 int rval = QLA_FUNCTION_FAILED;
165 /* ref: INIT for ABTS command */
166 sp = qla2xxx_get_qpair_sp(cmd_sp->vha, cmd_sp->qpair, cmd_sp->fcport,
169 return QLA_MEMORY_ALLOC_FAILED;
171 abt_iocb = &sp->u.iocb_cmd;
172 sp->type = SRB_ABT_CMD;
174 sp->qpair = cmd_sp->qpair;
177 sp->flags = SRB_WAKEUP_ON_COMP;
179 init_completion(&abt_iocb->u.abt.comp);
180 /* FW can send 2 x ABTS's timeout/20s */
181 qla2x00_init_async_sp(sp, 42, qla24xx_abort_sp_done);
182 sp->u.iocb_cmd.timeout = qla24xx_abort_iocb_timeout;
184 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
185 abt_iocb->u.abt.req_que_no = cpu_to_le16(cmd_sp->qpair->req->id);
187 ql_dbg(ql_dbg_async, vha, 0x507c,
188 "Abort command issued - hdl=%x, type=%x\n", cmd_sp->handle,
191 rval = qla2x00_start_sp(sp);
192 if (rval != QLA_SUCCESS) {
194 kref_put(&sp->cmd_kref, qla2x00_sp_release);
199 wait_for_completion(&abt_iocb->u.abt.comp);
200 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
201 QLA_SUCCESS : QLA_ERR_FROM_FW;
203 kref_put(&sp->cmd_kref, qla2x00_sp_release);
210 qla2x00_async_iocb_timeout(void *data)
213 fc_port_t *fcport = sp->fcport;
214 struct srb_iocb *lio = &sp->u.iocb_cmd;
219 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
220 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
221 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
223 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
225 pr_info("Async-%s timeout - hdl=%x.\n",
226 sp->name, sp->handle);
231 rc = qla24xx_async_abort_cmd(sp, false);
233 /* Retry as needed. */
234 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
235 lio->u.logio.data[1] =
236 lio->u.logio.flags & SRB_LOGIN_RETRIED ?
237 QLA_LOGIO_LOGIN_RETRIED : 0;
238 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
239 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
241 if (sp->qpair->req->outstanding_cmds[h] ==
243 sp->qpair->req->outstanding_cmds[h] =
248 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
249 sp->done(sp, QLA_FUNCTION_TIMEOUT);
253 case SRB_CT_PTHRU_CMD:
260 rc = qla24xx_async_abort_cmd(sp, false);
262 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
263 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
265 if (sp->qpair->req->outstanding_cmds[h] ==
267 sp->qpair->req->outstanding_cmds[h] =
272 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
273 sp->done(sp, QLA_FUNCTION_TIMEOUT);
279 static void qla2x00_async_login_sp_done(srb_t *sp, int res)
281 struct scsi_qla_host *vha = sp->vha;
282 struct srb_iocb *lio = &sp->u.iocb_cmd;
285 ql_dbg(ql_dbg_disc, vha, 0x20dd,
286 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
288 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
290 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
291 memset(&ea, 0, sizeof(ea));
292 ea.fcport = sp->fcport;
293 ea.data[0] = lio->u.logio.data[0];
294 ea.data[1] = lio->u.logio.data[1];
295 ea.iop[0] = lio->u.logio.iop[0];
296 ea.iop[1] = lio->u.logio.iop[1];
299 ea.data[0] = MBS_COMMAND_ERROR;
300 qla24xx_handle_plogi_done_event(vha, &ea);
304 kref_put(&sp->cmd_kref, qla2x00_sp_release);
308 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
312 struct srb_iocb *lio;
313 int rval = QLA_FUNCTION_FAILED;
315 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
316 fcport->loop_id == FC_NO_LOOP_ID) {
317 ql_log(ql_log_warn, vha, 0xffff,
318 "%s: %8phC - not sending command.\n",
319 __func__, fcport->port_name);
324 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
328 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_PEND);
329 fcport->flags |= FCF_ASYNC_SENT;
330 fcport->logout_completed = 0;
332 sp->type = SRB_LOGIN_CMD;
334 sp->gen1 = fcport->rscn_gen;
335 sp->gen2 = fcport->login_gen;
336 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
337 qla2x00_async_login_sp_done);
339 lio = &sp->u.iocb_cmd;
340 if (N2N_TOPO(fcport->vha->hw) && fcport_is_bigger(fcport)) {
341 lio->u.logio.flags |= SRB_LOGIN_PRLI_ONLY;
343 if (vha->hw->flags.edif_enabled &&
345 lio->u.logio.flags |=
346 (SRB_LOGIN_FCSP | SRB_LOGIN_SKIP_PRLI);
348 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
352 if (NVME_TARGET(vha->hw, fcport))
353 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
355 rval = qla2x00_start_sp(sp);
357 ql_dbg(ql_dbg_disc, vha, 0x2072,
358 "Async-login - %8phC hdl=%x, loopid=%x portid=%06x retries=%d %s.\n",
359 fcport->port_name, sp->handle, fcport->loop_id,
360 fcport->d_id.b24, fcport->login_retry,
361 lio->u.logio.flags & SRB_LOGIN_FCSP ? "FCSP" : "");
363 if (rval != QLA_SUCCESS) {
364 fcport->flags |= FCF_LOGIN_NEEDED;
365 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
373 kref_put(&sp->cmd_kref, qla2x00_sp_release);
374 fcport->flags &= ~FCF_ASYNC_SENT;
376 fcport->flags &= ~FCF_ASYNC_ACTIVE;
380 static void qla2x00_async_logout_sp_done(srb_t *sp, int res)
382 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
383 sp->fcport->login_gen++;
384 qlt_logo_completion_handler(sp->fcport, sp->u.iocb_cmd.u.logio.data[0]);
386 kref_put(&sp->cmd_kref, qla2x00_sp_release);
390 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
393 int rval = QLA_FUNCTION_FAILED;
395 fcport->flags |= FCF_ASYNC_SENT;
397 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
401 sp->type = SRB_LOGOUT_CMD;
403 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
404 qla2x00_async_logout_sp_done),
406 ql_dbg(ql_dbg_disc, vha, 0x2070,
407 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC explicit %d.\n",
408 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
409 fcport->d_id.b.area, fcport->d_id.b.al_pa,
410 fcport->port_name, fcport->explicit_logout);
412 rval = qla2x00_start_sp(sp);
413 if (rval != QLA_SUCCESS)
419 kref_put(&sp->cmd_kref, qla2x00_sp_release);
421 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
426 qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
429 fcport->flags &= ~FCF_ASYNC_ACTIVE;
430 /* Don't re-login in target mode */
431 if (!fcport->tgt_session)
432 qla2x00_mark_device_lost(vha, fcport, 1);
433 qlt_logo_completion_handler(fcport, data[0]);
436 static void qla2x00_async_prlo_sp_done(srb_t *sp, int res)
438 struct srb_iocb *lio = &sp->u.iocb_cmd;
439 struct scsi_qla_host *vha = sp->vha;
441 sp->fcport->flags &= ~FCF_ASYNC_ACTIVE;
442 if (!test_bit(UNLOADING, &vha->dpc_flags))
443 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
446 kref_put(&sp->cmd_kref, qla2x00_sp_release);
450 qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
455 rval = QLA_FUNCTION_FAILED;
457 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
461 sp->type = SRB_PRLO_CMD;
463 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
464 qla2x00_async_prlo_sp_done);
466 ql_dbg(ql_dbg_disc, vha, 0x2070,
467 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
468 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
469 fcport->d_id.b.area, fcport->d_id.b.al_pa);
471 rval = qla2x00_start_sp(sp);
472 if (rval != QLA_SUCCESS)
479 kref_put(&sp->cmd_kref, qla2x00_sp_release);
481 fcport->flags &= ~FCF_ASYNC_ACTIVE;
486 void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
488 struct fc_port *fcport = ea->fcport;
490 ql_dbg(ql_dbg_disc, vha, 0x20d2,
491 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
492 __func__, fcport->port_name, fcport->disc_state,
493 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
494 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
496 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
499 if (ea->data[0] != MBS_COMMAND_COMPLETE) {
500 ql_dbg(ql_dbg_disc, vha, 0x2066,
501 "%s %8phC: adisc fail: post delete\n",
502 __func__, ea->fcport->port_name);
503 /* deleted = 0 & logout_on_delete = force fw cleanup */
505 fcport->logout_on_delete = 1;
506 qlt_schedule_sess_for_deletion(ea->fcport);
510 if (ea->fcport->disc_state == DSC_DELETE_PEND)
513 if (ea->sp->gen2 != ea->fcport->login_gen) {
514 /* target side must have changed it. */
515 ql_dbg(ql_dbg_disc, vha, 0x20d3,
516 "%s %8phC generation changed\n",
517 __func__, ea->fcport->port_name);
519 } else if (ea->sp->gen1 != ea->fcport->rscn_gen) {
520 qla_rscn_replay(fcport);
521 qlt_schedule_sess_for_deletion(fcport);
525 __qla24xx_handle_gpdb_event(vha, ea);
528 static int qla_post_els_plogi_work(struct scsi_qla_host *vha, fc_port_t *fcport)
530 struct qla_work_evt *e;
532 e = qla2x00_alloc_work(vha, QLA_EVT_ELS_PLOGI);
534 return QLA_FUNCTION_FAILED;
536 e->u.fcport.fcport = fcport;
537 fcport->flags |= FCF_ASYNC_ACTIVE;
538 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_PEND);
539 return qla2x00_post_work(vha, e);
542 static void qla2x00_async_adisc_sp_done(srb_t *sp, int res)
544 struct scsi_qla_host *vha = sp->vha;
546 struct srb_iocb *lio = &sp->u.iocb_cmd;
548 ql_dbg(ql_dbg_disc, vha, 0x2066,
549 "Async done-%s res %x %8phC\n",
550 sp->name, res, sp->fcport->port_name);
552 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
554 memset(&ea, 0, sizeof(ea));
556 ea.data[0] = lio->u.logio.data[0];
557 ea.data[1] = lio->u.logio.data[1];
558 ea.iop[0] = lio->u.logio.iop[0];
559 ea.iop[1] = lio->u.logio.iop[1];
560 ea.fcport = sp->fcport;
563 ea.data[0] = MBS_COMMAND_ERROR;
565 qla24xx_handle_adisc_event(vha, &ea);
567 kref_put(&sp->cmd_kref, qla2x00_sp_release);
571 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
575 struct srb_iocb *lio;
576 int rval = QLA_FUNCTION_FAILED;
578 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
581 fcport->flags |= FCF_ASYNC_SENT;
583 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
587 sp->type = SRB_ADISC_CMD;
589 sp->gen1 = fcport->rscn_gen;
590 sp->gen2 = fcport->login_gen;
591 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
592 qla2x00_async_adisc_sp_done);
594 if (data[1] & QLA_LOGIO_LOGIN_RETRIED) {
595 lio = &sp->u.iocb_cmd;
596 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
599 ql_dbg(ql_dbg_disc, vha, 0x206f,
600 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
601 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
603 rval = qla2x00_start_sp(sp);
604 if (rval != QLA_SUCCESS)
611 kref_put(&sp->cmd_kref, qla2x00_sp_release);
613 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
614 qla2x00_post_async_adisc_work(vha, fcport, data);
618 static bool qla2x00_is_reserved_id(scsi_qla_host_t *vha, uint16_t loop_id)
620 struct qla_hw_data *ha = vha->hw;
622 if (IS_FWI2_CAPABLE(ha))
623 return loop_id > NPH_LAST_HANDLE;
625 return (loop_id > ha->max_loop_id && loop_id < SNS_FIRST_LOOP_ID) ||
626 loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST;
630 * qla2x00_find_new_loop_id - scan through our port list and find a new usable loop ID
631 * @vha: adapter state pointer.
632 * @dev: port structure pointer.
635 * qla2x00 local function return status code.
640 static int qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
643 struct qla_hw_data *ha = vha->hw;
644 unsigned long flags = 0;
648 spin_lock_irqsave(&ha->vport_slock, flags);
650 dev->loop_id = find_first_zero_bit(ha->loop_id_map, LOOPID_MAP_SIZE);
651 if (dev->loop_id >= LOOPID_MAP_SIZE ||
652 qla2x00_is_reserved_id(vha, dev->loop_id)) {
653 dev->loop_id = FC_NO_LOOP_ID;
654 rval = QLA_FUNCTION_FAILED;
656 set_bit(dev->loop_id, ha->loop_id_map);
658 spin_unlock_irqrestore(&ha->vport_slock, flags);
660 if (rval == QLA_SUCCESS)
661 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
662 "Assigning new loopid=%x, portid=%x.\n",
663 dev->loop_id, dev->d_id.b24);
665 ql_log(ql_log_warn, dev->vha, 0x2087,
666 "No loop_id's available, portid=%x.\n",
672 void qla2x00_clear_loop_id(fc_port_t *fcport)
674 struct qla_hw_data *ha = fcport->vha->hw;
676 if (fcport->loop_id == FC_NO_LOOP_ID ||
677 qla2x00_is_reserved_id(fcport->vha, fcport->loop_id))
680 clear_bit(fcport->loop_id, ha->loop_id_map);
681 fcport->loop_id = FC_NO_LOOP_ID;
684 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
685 struct event_arg *ea)
687 fc_port_t *fcport, *conflict_fcport;
688 struct get_name_list_extended *e;
689 u16 i, n, found = 0, loop_id;
693 u8 current_login_state, nvme_cls;
696 ql_dbg(ql_dbg_disc, vha, 0xffff,
697 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d edif %d\n",
698 __func__, fcport->port_name, fcport->disc_state,
699 fcport->fw_login_state, ea->rc,
700 fcport->login_gen, fcport->last_login_gen,
701 fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id, fcport->edif.enable);
703 if (fcport->disc_state == DSC_DELETE_PEND)
706 if (ea->rc) { /* rval */
707 if (fcport->login_retry == 0) {
708 ql_dbg(ql_dbg_disc, vha, 0x20de,
709 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
710 fcport->port_name, fcport->login_retry);
715 if (fcport->last_rscn_gen != fcport->rscn_gen) {
716 qla_rscn_replay(fcport);
717 qlt_schedule_sess_for_deletion(fcport);
719 } else if (fcport->last_login_gen != fcport->login_gen) {
720 ql_dbg(ql_dbg_disc, vha, 0x20e0,
721 "%s %8phC login gen changed\n",
722 __func__, fcport->port_name);
723 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
727 n = ea->data[0] / sizeof(struct get_name_list_extended);
729 ql_dbg(ql_dbg_disc, vha, 0x20e1,
730 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
731 __func__, __LINE__, fcport->port_name, n,
732 fcport->d_id.b.domain, fcport->d_id.b.area,
733 fcport->d_id.b.al_pa, fcport->loop_id);
735 for (i = 0; i < n; i++) {
737 wwn = wwn_to_u64(e->port_name);
738 id.b.domain = e->port_id[2];
739 id.b.area = e->port_id[1];
740 id.b.al_pa = e->port_id[0];
743 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
746 if (IS_SW_RESV_ADDR(id))
751 loop_id = le16_to_cpu(e->nport_handle);
752 loop_id = (loop_id & 0x7fff);
753 nvme_cls = e->current_login_state >> 4;
754 current_login_state = e->current_login_state & 0xf;
756 if (PRLI_PHASE(nvme_cls)) {
757 current_login_state = nvme_cls;
758 fcport->fc4_type &= ~FS_FC4TYPE_FCP;
759 fcport->fc4_type |= FS_FC4TYPE_NVME;
760 } else if (PRLI_PHASE(current_login_state)) {
761 fcport->fc4_type |= FS_FC4TYPE_FCP;
762 fcport->fc4_type &= ~FS_FC4TYPE_NVME;
765 ql_dbg(ql_dbg_disc, vha, 0x20e2,
766 "%s found %8phC CLS [%x|%x] fc4_type %d ID[%06x|%06x] lid[%d|%d]\n",
767 __func__, fcport->port_name,
768 e->current_login_state, fcport->fw_login_state,
769 fcport->fc4_type, id.b24, fcport->d_id.b24,
770 loop_id, fcport->loop_id);
772 switch (fcport->disc_state) {
773 case DSC_DELETE_PEND:
777 if ((id.b24 != fcport->d_id.b24 &&
779 fcport->loop_id != FC_NO_LOOP_ID) ||
780 (fcport->loop_id != FC_NO_LOOP_ID &&
781 fcport->loop_id != loop_id)) {
782 ql_dbg(ql_dbg_disc, vha, 0x20e3,
783 "%s %d %8phC post del sess\n",
784 __func__, __LINE__, fcport->port_name);
785 if (fcport->n2n_flag)
786 fcport->d_id.b24 = 0;
787 qlt_schedule_sess_for_deletion(fcport);
793 fcport->loop_id = loop_id;
794 if (fcport->n2n_flag)
795 fcport->d_id.b24 = id.b24;
797 wwn = wwn_to_u64(fcport->port_name);
798 qlt_find_sess_invalidate_other(vha, wwn,
799 id, loop_id, &conflict_fcport);
801 if (conflict_fcport) {
803 * Another share fcport share the same loop_id &
804 * nport id. Conflict fcport needs to finish
805 * cleanup before this fcport can proceed to login.
807 conflict_fcport->conflict = fcport;
808 fcport->login_pause = 1;
811 switch (vha->hw->current_topology) {
813 switch (current_login_state) {
814 case DSC_LS_PRLI_COMP:
816 vha, 0x20e4, "%s %d %8phC post gpdb\n",
817 __func__, __LINE__, fcport->port_name);
819 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
820 fcport->port_type = FCT_INITIATOR;
822 fcport->port_type = FCT_TARGET;
823 data[0] = data[1] = 0;
824 qla2x00_post_async_adisc_work(vha, fcport,
827 case DSC_LS_PLOGI_COMP:
828 if (vha->hw->flags.edif_enabled) {
829 /* check to see if App support Secure */
830 qla24xx_post_gpdb_work(vha, fcport, 0);
834 case DSC_LS_PORT_UNAVAIL:
836 if (fcport->loop_id == FC_NO_LOOP_ID) {
837 qla2x00_find_new_loop_id(vha, fcport);
838 fcport->fw_login_state =
841 ql_dbg(ql_dbg_disc, vha, 0x20e5,
842 "%s %d %8phC\n", __func__, __LINE__,
844 qla24xx_fcport_handle_login(vha, fcport);
849 fcport->fw_login_state = current_login_state;
851 switch (current_login_state) {
852 case DSC_LS_PRLI_PEND:
854 * In the middle of PRLI. Let it finish.
855 * Allow relogin code to recheck state again
856 * with GNL. Push disc_state back to DELETED
857 * so GNL can go out again
859 qla2x00_set_fcport_disc_state(fcport,
861 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
863 case DSC_LS_PRLI_COMP:
864 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
865 fcport->port_type = FCT_INITIATOR;
867 fcport->port_type = FCT_TARGET;
869 data[0] = data[1] = 0;
870 qla2x00_post_async_adisc_work(vha, fcport,
873 case DSC_LS_PLOGI_COMP:
874 if (vha->hw->flags.edif_enabled &&
876 /* check to see if App support secure or not */
877 qla24xx_post_gpdb_work(vha, fcport, 0);
880 if (fcport_is_bigger(fcport)) {
881 /* local adapter is smaller */
882 if (fcport->loop_id != FC_NO_LOOP_ID)
883 qla2x00_clear_loop_id(fcport);
885 fcport->loop_id = loop_id;
886 qla24xx_fcport_handle_login(vha,
892 if (fcport_is_smaller(fcport)) {
893 /* local adapter is bigger */
894 if (fcport->loop_id != FC_NO_LOOP_ID)
895 qla2x00_clear_loop_id(fcport);
897 fcport->loop_id = loop_id;
898 qla24xx_fcport_handle_login(vha,
904 } /* switch (ha->current_topology) */
908 switch (vha->hw->current_topology) {
911 for (i = 0; i < n; i++) {
913 id.b.domain = e->port_id[0];
914 id.b.area = e->port_id[1];
915 id.b.al_pa = e->port_id[2];
917 loop_id = le16_to_cpu(e->nport_handle);
919 if (fcport->d_id.b24 == id.b24) {
921 qla2x00_find_fcport_by_wwpn(vha,
923 if (conflict_fcport) {
924 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
926 "%s %d %8phC post del sess\n",
928 conflict_fcport->port_name);
929 qlt_schedule_sess_for_deletion
934 * FW already picked this loop id for
937 if (fcport->loop_id == loop_id)
938 fcport->loop_id = FC_NO_LOOP_ID;
940 qla24xx_fcport_handle_login(vha, fcport);
943 qla2x00_set_fcport_disc_state(fcport, DSC_DELETED);
944 if (time_after_eq(jiffies, fcport->dm_login_expire)) {
945 if (fcport->n2n_link_reset_cnt < 2) {
946 fcport->n2n_link_reset_cnt++;
948 * remote port is not sending PLOGI.
949 * Reset link to kick start his state
952 set_bit(N2N_LINK_RESET,
955 if (fcport->n2n_chip_reset < 1) {
956 ql_log(ql_log_info, vha, 0x705d,
957 "Chip reset to bring laser down");
958 set_bit(ISP_ABORT_NEEDED,
960 fcport->n2n_chip_reset++;
962 ql_log(ql_log_info, vha, 0x705d,
963 "Remote port %8ph is not coming back\n",
965 fcport->scan_state = 0;
968 qla2xxx_wake_dpc(vha);
971 * report port suppose to do PLOGI. Give him
972 * more time. FW will catch it.
974 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
983 static void qla24xx_async_gnl_sp_done(srb_t *sp, int res)
985 struct scsi_qla_host *vha = sp->vha;
987 struct fc_port *fcport = NULL, *tf;
988 u16 i, n = 0, loop_id;
990 struct get_name_list_extended *e;
995 ql_dbg(ql_dbg_disc, vha, 0x20e7,
996 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
997 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
998 sp->u.iocb_cmd.u.mbx.in_mb[2]);
1001 sp->fcport->flags &= ~(FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE);
1002 memset(&ea, 0, sizeof(ea));
1006 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
1007 sizeof(struct get_name_list_extended)) {
1008 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
1009 sizeof(struct get_name_list_extended);
1010 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
1013 for (i = 0; i < n; i++) {
1015 loop_id = le16_to_cpu(e->nport_handle);
1016 /* mask out reserve bit */
1017 loop_id = (loop_id & 0x7fff);
1018 set_bit(loop_id, vha->hw->loop_id_map);
1019 wwn = wwn_to_u64(e->port_name);
1021 ql_dbg(ql_dbg_disc, vha, 0x20e8,
1022 "%s %8phC %02x:%02x:%02x CLS %x/%x lid %x \n",
1023 __func__, &wwn, e->port_id[2], e->port_id[1],
1024 e->port_id[0], e->current_login_state, e->last_login_state,
1025 (loop_id & 0x7fff));
1028 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1032 if (!list_empty(&vha->gnl.fcports))
1033 list_splice_init(&vha->gnl.fcports, &h);
1034 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1036 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
1037 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1038 list_del_init(&fcport->gnl_entry);
1039 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1040 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1043 qla24xx_handle_gnl_done_event(vha, &ea);
1046 /* create new fcport if fw has knowledge of new sessions */
1047 for (i = 0; i < n; i++) {
1052 wwn = wwn_to_u64(e->port_name);
1055 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
1056 if (!memcmp((u8 *)&wwn, fcport->port_name,
1063 id.b.domain = e->port_id[2];
1064 id.b.area = e->port_id[1];
1065 id.b.al_pa = e->port_id[0];
1068 if (!found && wwn && !IS_SW_RESV_ADDR(id)) {
1069 ql_dbg(ql_dbg_disc, vha, 0x2065,
1070 "%s %d %8phC %06x post new sess\n",
1071 __func__, __LINE__, (u8 *)&wwn, id.b24);
1072 wwnn = wwn_to_u64(e->node_name);
1073 qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn,
1074 (u8 *)&wwnn, NULL, 0);
1078 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1080 if (!list_empty(&vha->gnl.fcports)) {
1082 list_for_each_entry_safe(fcport, tf, &vha->gnl.fcports,
1084 list_del_init(&fcport->gnl_entry);
1085 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1086 if (qla24xx_post_gnl_work(vha, fcport) == QLA_SUCCESS)
1090 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1093 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1096 int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
1099 int rval = QLA_FUNCTION_FAILED;
1100 unsigned long flags;
1103 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
1106 ql_dbg(ql_dbg_disc, vha, 0x20d9,
1107 "Async-gnlist WWPN %8phC \n", fcport->port_name);
1109 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1110 fcport->flags |= FCF_ASYNC_SENT;
1111 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
1112 fcport->last_rscn_gen = fcport->rscn_gen;
1113 fcport->last_login_gen = fcport->login_gen;
1115 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
1116 if (vha->gnl.sent) {
1117 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1121 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1124 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1128 sp->type = SRB_MB_IOCB;
1129 sp->name = "gnlist";
1130 sp->gen1 = fcport->rscn_gen;
1131 sp->gen2 = fcport->login_gen;
1132 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
1133 qla24xx_async_gnl_sp_done);
1135 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1136 mb[0] = MBC_PORT_NODE_NAME_LIST;
1137 mb[1] = BIT_2 | BIT_3;
1138 mb[2] = MSW(vha->gnl.ldma);
1139 mb[3] = LSW(vha->gnl.ldma);
1140 mb[6] = MSW(MSD(vha->gnl.ldma));
1141 mb[7] = LSW(MSD(vha->gnl.ldma));
1142 mb[8] = vha->gnl.size;
1143 mb[9] = vha->vp_idx;
1145 ql_dbg(ql_dbg_disc, vha, 0x20da,
1146 "Async-%s - OUT WWPN %8phC hndl %x\n",
1147 sp->name, fcport->port_name, sp->handle);
1149 rval = qla2x00_start_sp(sp);
1150 if (rval != QLA_SUCCESS)
1157 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1159 fcport->flags &= ~(FCF_ASYNC_ACTIVE | FCF_ASYNC_SENT);
1163 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1165 struct qla_work_evt *e;
1167 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
1169 return QLA_FUNCTION_FAILED;
1171 e->u.fcport.fcport = fcport;
1172 fcport->flags |= FCF_ASYNC_ACTIVE;
1173 return qla2x00_post_work(vha, e);
1176 static void qla24xx_async_gpdb_sp_done(srb_t *sp, int res)
1178 struct scsi_qla_host *vha = sp->vha;
1179 struct qla_hw_data *ha = vha->hw;
1180 fc_port_t *fcport = sp->fcport;
1181 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
1182 struct event_arg ea;
1184 ql_dbg(ql_dbg_disc, vha, 0x20db,
1185 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
1186 sp->name, res, fcport->port_name, mb[1], mb[2]);
1188 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1190 if (res == QLA_FUNCTION_TIMEOUT)
1193 memset(&ea, 0, sizeof(ea));
1197 qla24xx_handle_gpdb_event(vha, &ea);
1200 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
1201 sp->u.iocb_cmd.u.mbx.in_dma);
1203 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1206 int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1208 struct qla_work_evt *e;
1210 if (vha->host->active_mode == MODE_TARGET)
1211 return QLA_FUNCTION_FAILED;
1213 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
1215 return QLA_FUNCTION_FAILED;
1217 e->u.fcport.fcport = fcport;
1219 return qla2x00_post_work(vha, e);
1222 static void qla2x00_async_prli_sp_done(srb_t *sp, int res)
1224 struct scsi_qla_host *vha = sp->vha;
1225 struct srb_iocb *lio = &sp->u.iocb_cmd;
1226 struct event_arg ea;
1228 ql_dbg(ql_dbg_disc, vha, 0x2129,
1229 "%s %8phC res %x\n", __func__,
1230 sp->fcport->port_name, res);
1232 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1234 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
1235 memset(&ea, 0, sizeof(ea));
1236 ea.fcport = sp->fcport;
1237 ea.data[0] = lio->u.logio.data[0];
1238 ea.data[1] = lio->u.logio.data[1];
1239 ea.iop[0] = lio->u.logio.iop[0];
1240 ea.iop[1] = lio->u.logio.iop[1];
1242 if (res == QLA_OS_TIMER_EXPIRED)
1243 ea.data[0] = QLA_OS_TIMER_EXPIRED;
1245 ea.data[0] = MBS_COMMAND_ERROR;
1247 qla24xx_handle_prli_done_event(vha, &ea);
1250 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1254 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
1257 struct srb_iocb *lio;
1258 int rval = QLA_FUNCTION_FAILED;
1260 if (!vha->flags.online) {
1261 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1262 __func__, __LINE__, fcport->port_name);
1266 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
1267 fcport->fw_login_state == DSC_LS_PRLI_PEND) &&
1268 qla_dual_mode_enabled(vha)) {
1269 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1270 __func__, __LINE__, fcport->port_name);
1274 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1278 fcport->flags |= FCF_ASYNC_SENT;
1279 fcport->logout_completed = 0;
1281 sp->type = SRB_PRLI_CMD;
1283 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
1284 qla2x00_async_prli_sp_done);
1286 lio = &sp->u.iocb_cmd;
1287 lio->u.logio.flags = 0;
1289 if (NVME_TARGET(vha->hw, fcport))
1290 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
1292 ql_dbg(ql_dbg_disc, vha, 0x211b,
1293 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d fc4type %x priority %x %s.\n",
1294 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24,
1295 fcport->login_retry, fcport->fc4_type, vha->hw->fc4_type_priority,
1296 NVME_TARGET(vha->hw, fcport) ? "nvme" : "fcp");
1298 rval = qla2x00_start_sp(sp);
1299 if (rval != QLA_SUCCESS) {
1300 fcport->flags |= FCF_LOGIN_NEEDED;
1301 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1309 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1310 fcport->flags &= ~FCF_ASYNC_SENT;
1314 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1316 struct qla_work_evt *e;
1318 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
1320 return QLA_FUNCTION_FAILED;
1322 e->u.fcport.fcport = fcport;
1323 e->u.fcport.opt = opt;
1324 fcport->flags |= FCF_ASYNC_ACTIVE;
1325 return qla2x00_post_work(vha, e);
1328 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1331 struct srb_iocb *mbx;
1332 int rval = QLA_FUNCTION_FAILED;
1335 struct port_database_24xx *pd;
1336 struct qla_hw_data *ha = vha->hw;
1338 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
1339 fcport->loop_id == FC_NO_LOOP_ID) {
1340 ql_log(ql_log_warn, vha, 0xffff,
1341 "%s: %8phC online %d flags %x - not sending command.\n",
1342 __func__, fcport->port_name, vha->flags.online, fcport->flags);
1346 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1350 qla2x00_set_fcport_disc_state(fcport, DSC_GPDB);
1352 fcport->flags |= FCF_ASYNC_SENT;
1353 sp->type = SRB_MB_IOCB;
1355 sp->gen1 = fcport->rscn_gen;
1356 sp->gen2 = fcport->login_gen;
1357 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
1358 qla24xx_async_gpdb_sp_done);
1360 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1362 ql_log(ql_log_warn, vha, 0xd043,
1363 "Failed to allocate port database structure.\n");
1367 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1368 mb[0] = MBC_GET_PORT_DATABASE;
1369 mb[1] = fcport->loop_id;
1370 mb[2] = MSW(pd_dma);
1371 mb[3] = LSW(pd_dma);
1372 mb[6] = MSW(MSD(pd_dma));
1373 mb[7] = LSW(MSD(pd_dma));
1374 mb[9] = vha->vp_idx;
1377 mbx = &sp->u.iocb_cmd;
1378 mbx->u.mbx.in = (void *)pd;
1379 mbx->u.mbx.in_dma = pd_dma;
1381 ql_dbg(ql_dbg_disc, vha, 0x20dc,
1382 "Async-%s %8phC hndl %x opt %x\n",
1383 sp->name, fcport->port_name, sp->handle, opt);
1385 rval = qla2x00_start_sp(sp);
1386 if (rval != QLA_SUCCESS)
1392 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1394 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1395 fcport->flags &= ~FCF_ASYNC_SENT;
1397 fcport->flags &= ~FCF_ASYNC_ACTIVE;
1398 qla24xx_post_gpdb_work(vha, fcport, opt);
1403 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1405 unsigned long flags;
1407 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1408 ea->fcport->login_gen++;
1409 ea->fcport->deleted = 0;
1410 ea->fcport->logout_on_delete = 1;
1412 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1413 vha->fcport_count++;
1414 ea->fcport->login_succ = 1;
1416 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1417 qla24xx_sched_upd_fcport(ea->fcport);
1418 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1419 } else if (ea->fcport->login_succ) {
1421 * We have an existing session. A late RSCN delivery
1422 * must have triggered the session to be re-validate.
1423 * Session is still valid.
1425 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1426 "%s %d %8phC session revalidate success\n",
1427 __func__, __LINE__, ea->fcport->port_name);
1428 qla2x00_set_fcport_disc_state(ea->fcport, DSC_LOGIN_COMPLETE);
1430 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1433 static int qla_chk_secure_login(scsi_qla_host_t *vha, fc_port_t *fcport,
1434 struct port_database_24xx *pd)
1438 if (pd->secure_login) {
1439 ql_dbg(ql_dbg_disc, vha, 0x104d,
1440 "Secure Login established on %8phC\n",
1442 fcport->flags |= FCF_FCSP_DEVICE;
1444 ql_dbg(ql_dbg_disc, vha, 0x104d,
1445 "non-Secure Login %8phC",
1447 fcport->flags &= ~FCF_FCSP_DEVICE;
1449 if (vha->hw->flags.edif_enabled) {
1450 if (fcport->flags & FCF_FCSP_DEVICE) {
1451 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_AUTH_PEND);
1452 /* Start edif prli timer & ring doorbell for app */
1453 fcport->edif.rx_sa_set = 0;
1454 fcport->edif.tx_sa_set = 0;
1455 fcport->edif.rx_sa_pending = 0;
1456 fcport->edif.tx_sa_pending = 0;
1458 qla2x00_post_aen_work(vha, FCH_EVT_PORT_ONLINE,
1461 if (DBELL_ACTIVE(vha)) {
1462 ql_dbg(ql_dbg_disc, vha, 0x20ef,
1463 "%s %d %8phC EDIF: post DB_AUTH: AUTH needed\n",
1464 __func__, __LINE__, fcport->port_name);
1465 fcport->edif.app_started = 1;
1466 fcport->edif.app_sess_online = 1;
1468 qla_edb_eventcreate(vha, VND_CMD_AUTH_STATE_NEEDED,
1469 fcport->d_id.b24, 0, fcport);
1473 } else if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
1474 ql_dbg(ql_dbg_disc, vha, 0x2117,
1475 "%s %d %8phC post prli\n",
1476 __func__, __LINE__, fcport->port_name);
1477 qla24xx_post_prli_work(vha, fcport);
1485 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1487 fc_port_t *fcport = ea->fcport;
1488 struct port_database_24xx *pd;
1489 struct srb *sp = ea->sp;
1492 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1494 fcport->flags &= ~FCF_ASYNC_SENT;
1496 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1497 "%s %8phC DS %d LS %x fc4_type %x rc %x\n", __func__,
1498 fcport->port_name, fcport->disc_state, pd->current_login_state,
1499 fcport->fc4_type, ea->rc);
1501 if (fcport->disc_state == DSC_DELETE_PEND) {
1502 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC\n",
1503 __func__, __LINE__, fcport->port_name);
1507 if (NVME_TARGET(vha->hw, fcport))
1508 ls = pd->current_login_state >> 4;
1510 ls = pd->current_login_state & 0xf;
1512 if (ea->sp->gen2 != fcport->login_gen) {
1513 /* target side must have changed it. */
1515 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1516 "%s %8phC generation changed\n",
1517 __func__, fcport->port_name);
1519 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1520 qla_rscn_replay(fcport);
1521 qlt_schedule_sess_for_deletion(fcport);
1522 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n",
1523 __func__, __LINE__, fcport->port_name, ls);
1528 case PDS_PRLI_COMPLETE:
1529 __qla24xx_parse_gpdb(vha, fcport, pd);
1531 case PDS_PLOGI_COMPLETE:
1532 if (qla_chk_secure_login(vha, fcport, pd)) {
1533 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n",
1534 __func__, __LINE__, fcport->port_name, ls);
1538 case PDS_PLOGI_PENDING:
1539 case PDS_PRLI_PENDING:
1540 case PDS_PRLI2_PENDING:
1541 /* Set discovery state back to GNL to Relogin attempt */
1542 if (qla_dual_mode_enabled(vha) ||
1543 qla_ini_mode_enabled(vha)) {
1544 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
1545 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1547 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n",
1548 __func__, __LINE__, fcport->port_name, ls);
1550 case PDS_LOGO_PENDING:
1551 case PDS_PORT_UNAVAILABLE:
1553 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1554 __func__, __LINE__, fcport->port_name);
1555 qlt_schedule_sess_for_deletion(fcport);
1558 __qla24xx_handle_gpdb_event(vha, ea);
1561 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1566 if (qla_tgt_mode_enabled(vha))
1569 if (qla_dual_mode_enabled(vha)) {
1570 if (N2N_TOPO(vha->hw)) {
1573 mywwn = wwn_to_u64(vha->port_name);
1574 wwn = wwn_to_u64(fcport->port_name);
1577 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1578 && time_after_eq(jiffies,
1579 fcport->plogi_nack_done_deadline))
1585 /* initiator mode */
1589 if (login && fcport->login_retry) {
1590 fcport->login_retry--;
1591 if (fcport->loop_id == FC_NO_LOOP_ID) {
1592 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1593 rc = qla2x00_find_new_loop_id(vha, fcport);
1595 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1596 "%s %d %8phC post del sess - out of loopid\n",
1597 __func__, __LINE__, fcport->port_name);
1598 fcport->scan_state = 0;
1599 qlt_schedule_sess_for_deletion(fcport);
1603 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1604 "%s %d %8phC post login\n",
1605 __func__, __LINE__, fcport->port_name);
1606 qla2x00_post_async_login_work(vha, fcport, NULL);
1610 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1616 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1617 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d fc4type %x\n",
1618 __func__, fcport->port_name, fcport->disc_state,
1619 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1620 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1621 fcport->login_gen, fcport->loop_id, fcport->scan_state,
1624 if (fcport->scan_state != QLA_FCPORT_FOUND)
1627 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1628 qla_dual_mode_enabled(vha) &&
1629 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1630 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1633 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP &&
1634 !N2N_TOPO(vha->hw)) {
1635 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1636 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1641 /* Target won't initiate port login if fabric is present */
1642 if (vha->host->active_mode == MODE_TARGET && !N2N_TOPO(vha->hw))
1645 if (fcport->flags & FCF_ASYNC_SENT) {
1646 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1650 switch (fcport->disc_state) {
1652 wwn = wwn_to_u64(fcport->node_name);
1653 switch (vha->hw->current_topology) {
1655 if (fcport_is_smaller(fcport)) {
1656 /* this adapter is bigger */
1657 if (fcport->login_retry) {
1658 if (fcport->loop_id == FC_NO_LOOP_ID) {
1659 qla2x00_find_new_loop_id(vha,
1661 fcport->fw_login_state =
1662 DSC_LS_PORT_UNAVAIL;
1664 fcport->login_retry--;
1665 qla_post_els_plogi_work(vha, fcport);
1667 ql_log(ql_log_info, vha, 0x705d,
1668 "Unable to reach remote port %8phC",
1672 qla24xx_post_gnl_work(vha, fcport);
1677 ql_dbg(ql_dbg_disc, vha, 0xffff,
1678 "%s %d %8phC post GNNID\n",
1679 __func__, __LINE__, fcport->port_name);
1680 qla24xx_post_gnnid_work(vha, fcport);
1681 } else if (fcport->loop_id == FC_NO_LOOP_ID) {
1682 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1683 "%s %d %8phC post gnl\n",
1684 __func__, __LINE__, fcport->port_name);
1685 qla24xx_post_gnl_work(vha, fcport);
1687 qla_chk_n2n_b4_login(vha, fcport);
1694 switch (vha->hw->current_topology) {
1696 if ((fcport->current_login_state & 0xf) == 0x6) {
1697 ql_dbg(ql_dbg_disc, vha, 0x2118,
1698 "%s %d %8phC post GPDB work\n",
1699 __func__, __LINE__, fcport->port_name);
1700 fcport->chip_reset =
1701 vha->hw->base_qpair->chip_reset;
1702 qla24xx_post_gpdb_work(vha, fcport, 0);
1704 ql_dbg(ql_dbg_disc, vha, 0x2118,
1705 "%s %d %8phC post %s PRLI\n",
1706 __func__, __LINE__, fcport->port_name,
1707 NVME_TARGET(vha->hw, fcport) ? "NVME" :
1709 qla24xx_post_prli_work(vha, fcport);
1713 if (fcport->login_pause) {
1714 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1715 "%s %d %8phC exit\n",
1718 fcport->last_rscn_gen = fcport->rscn_gen;
1719 fcport->last_login_gen = fcport->login_gen;
1720 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1723 qla_chk_n2n_b4_login(vha, fcport);
1728 case DSC_LOGIN_FAILED:
1729 if (N2N_TOPO(vha->hw))
1730 qla_chk_n2n_b4_login(vha, fcport);
1732 qlt_schedule_sess_for_deletion(fcport);
1735 case DSC_LOGIN_COMPLETE:
1736 /* recheck login state */
1737 data[0] = data[1] = 0;
1738 qla2x00_post_async_adisc_work(vha, fcport, data);
1741 case DSC_LOGIN_PEND:
1742 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1743 qla24xx_post_prli_work(vha, fcport);
1746 case DSC_UPD_FCPORT:
1747 sec = jiffies_to_msecs(jiffies -
1748 fcport->jiffies_at_registration)/1000;
1749 if (fcport->sec_since_registration < sec && sec &&
1751 fcport->sec_since_registration = sec;
1752 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
1753 "%s %8phC - Slow Rport registration(%d Sec)\n",
1754 __func__, fcport->port_name, sec);
1757 if (fcport->next_disc_state != DSC_DELETE_PEND)
1758 fcport->next_disc_state = DSC_ADISC;
1759 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1769 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1770 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1772 struct qla_work_evt *e;
1774 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1776 return QLA_FUNCTION_FAILED;
1778 e->u.new_sess.id = *id;
1779 e->u.new_sess.pla = pla;
1780 e->u.new_sess.fc4_type = fc4_type;
1781 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1783 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1785 return qla2x00_post_work(vha, e);
1788 void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
1791 unsigned long flags;
1793 switch (ea->id.b.rsvd_1) {
1794 case RSCN_PORT_ADDR:
1795 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1797 if (fcport->flags & FCF_FCP2_DEVICE) {
1798 ql_dbg(ql_dbg_disc, vha, 0x2115,
1799 "Delaying session delete for FCP2 portid=%06x %8phC ",
1800 fcport->d_id.b24, fcport->port_name);
1804 if (vha->hw->flags.edif_enabled && DBELL_ACTIVE(vha)) {
1806 * On ipsec start by remote port, Target port
1807 * may use RSCN to trigger initiator to
1808 * relogin. If driver is already in the
1809 * process of a relogin, then ignore the RSCN
1810 * and allow the current relogin to continue.
1811 * This reduces thrashing of the connection.
1813 if (atomic_read(&fcport->state) == FCS_ONLINE) {
1815 * If state = online, then set scan_needed=1 to do relogin.
1816 * Otherwise we're already in the middle of a relogin
1818 fcport->scan_needed = 1;
1822 fcport->scan_needed = 1;
1827 case RSCN_AREA_ADDR:
1828 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1829 if (fcport->flags & FCF_FCP2_DEVICE)
1832 if ((ea->id.b24 & 0xffff00) == (fcport->d_id.b24 & 0xffff00)) {
1833 fcport->scan_needed = 1;
1839 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1840 if (fcport->flags & FCF_FCP2_DEVICE)
1843 if ((ea->id.b24 & 0xff0000) == (fcport->d_id.b24 & 0xff0000)) {
1844 fcport->scan_needed = 1;
1851 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1852 if (fcport->flags & FCF_FCP2_DEVICE)
1855 fcport->scan_needed = 1;
1861 spin_lock_irqsave(&vha->work_lock, flags);
1862 if (vha->scan.scan_flags == 0) {
1863 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s: schedule\n", __func__);
1864 vha->scan.scan_flags |= SF_QUEUED;
1865 schedule_delayed_work(&vha->scan.scan_work, 5);
1867 spin_unlock_irqrestore(&vha->work_lock, flags);
1870 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1871 struct event_arg *ea)
1873 fc_port_t *fcport = ea->fcport;
1875 if (test_bit(UNLOADING, &vha->dpc_flags))
1878 ql_dbg(ql_dbg_disc, vha, 0x2102,
1879 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1880 __func__, fcport->port_name, fcport->disc_state,
1881 fcport->fw_login_state, fcport->login_pause,
1882 fcport->deleted, fcport->conflict,
1883 fcport->last_rscn_gen, fcport->rscn_gen,
1884 fcport->last_login_gen, fcport->login_gen,
1887 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1888 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gnl\n",
1889 __func__, __LINE__, fcport->port_name);
1890 qla24xx_post_gnl_work(vha, fcport);
1894 qla24xx_fcport_handle_login(vha, fcport);
1897 void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
1898 struct event_arg *ea)
1900 if (N2N_TOPO(vha->hw) && fcport_is_smaller(ea->fcport) &&
1901 vha->hw->flags.edif_enabled) {
1902 /* check to see if App support Secure */
1903 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1907 /* for pure Target Mode, PRLI will not be initiated */
1908 if (vha->host->active_mode == MODE_TARGET)
1911 ql_dbg(ql_dbg_disc, vha, 0x2118,
1912 "%s %d %8phC post PRLI\n",
1913 __func__, __LINE__, ea->fcport->port_name);
1914 qla24xx_post_prli_work(vha, ea->fcport);
1918 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1919 * to be consumed by the fcport
1921 void qla_rscn_replay(fc_port_t *fcport)
1923 struct event_arg ea;
1925 switch (fcport->disc_state) {
1926 case DSC_DELETE_PEND:
1932 if (fcport->scan_needed) {
1933 memset(&ea, 0, sizeof(ea));
1934 ea.id = fcport->d_id;
1935 ea.id.b.rsvd_1 = RSCN_PORT_ADDR;
1936 qla2x00_handle_rscn(fcport->vha, &ea);
1941 qla2x00_tmf_iocb_timeout(void *data)
1944 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1946 unsigned long flags;
1948 rc = qla24xx_async_abort_cmd(sp, false);
1950 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
1951 for (h = 1; h < sp->qpair->req->num_outstanding_cmds; h++) {
1952 if (sp->qpair->req->outstanding_cmds[h] == sp) {
1953 sp->qpair->req->outstanding_cmds[h] = NULL;
1957 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
1958 tmf->u.tmf.comp_status = cpu_to_le16(CS_TIMEOUT);
1959 tmf->u.tmf.data = QLA_FUNCTION_FAILED;
1960 complete(&tmf->u.tmf.comp);
1964 static void qla2x00_tmf_sp_done(srb_t *sp, int res)
1966 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1968 complete(&tmf->u.tmf.comp);
1972 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
1975 struct scsi_qla_host *vha = fcport->vha;
1976 struct srb_iocb *tm_iocb;
1978 int rval = QLA_FUNCTION_FAILED;
1981 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1985 sp->type = SRB_TM_CMD;
1987 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha),
1988 qla2x00_tmf_sp_done);
1989 sp->u.iocb_cmd.timeout = qla2x00_tmf_iocb_timeout;
1991 tm_iocb = &sp->u.iocb_cmd;
1992 init_completion(&tm_iocb->u.tmf.comp);
1993 tm_iocb->u.tmf.flags = flags;
1994 tm_iocb->u.tmf.lun = lun;
1996 ql_dbg(ql_dbg_taskm, vha, 0x802f,
1997 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1998 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1999 fcport->d_id.b.area, fcport->d_id.b.al_pa);
2001 rval = qla2x00_start_sp(sp);
2002 if (rval != QLA_SUCCESS)
2004 wait_for_completion(&tm_iocb->u.tmf.comp);
2006 rval = tm_iocb->u.tmf.data;
2008 if (rval != QLA_SUCCESS) {
2009 ql_log(ql_log_warn, vha, 0x8030,
2010 "TM IOCB failed (%x).\n", rval);
2013 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
2014 flags = tm_iocb->u.tmf.flags;
2015 lun = (uint16_t)tm_iocb->u.tmf.lun;
2017 /* Issue Marker IOCB */
2018 qla2x00_marker(vha, vha->hw->base_qpair,
2019 fcport->loop_id, lun,
2020 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
2025 kref_put(&sp->cmd_kref, qla2x00_sp_release);
2026 fcport->flags &= ~FCF_ASYNC_SENT;
2032 qla24xx_async_abort_command(srb_t *sp)
2034 unsigned long flags = 0;
2037 fc_port_t *fcport = sp->fcport;
2038 struct qla_qpair *qpair = sp->qpair;
2039 struct scsi_qla_host *vha = fcport->vha;
2040 struct req_que *req = qpair->req;
2042 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
2043 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
2044 if (req->outstanding_cmds[handle] == sp)
2047 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
2049 if (handle == req->num_outstanding_cmds) {
2050 /* Command not found. */
2051 return QLA_ERR_NOT_FOUND;
2053 if (sp->type == SRB_FXIOCB_DCMD)
2054 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
2055 FXDISC_ABORT_IOCTL);
2057 return qla24xx_async_abort_cmd(sp, true);
2061 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
2064 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
2067 switch (ea->data[0]) {
2068 case MBS_COMMAND_COMPLETE:
2069 ql_dbg(ql_dbg_disc, vha, 0x2118,
2070 "%s %d %8phC post gpdb\n",
2071 __func__, __LINE__, ea->fcport->port_name);
2073 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2074 ea->fcport->logout_on_delete = 1;
2075 ea->fcport->nvme_prli_service_param = ea->iop[0];
2076 if (ea->iop[0] & NVME_PRLI_SP_FIRST_BURST)
2077 ea->fcport->nvme_first_burst_size =
2078 (ea->iop[1] & 0xffff) * 512;
2080 ea->fcport->nvme_first_burst_size = 0;
2081 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2084 if ((ea->iop[0] == LSC_SCODE_ELS_REJECT) &&
2085 (ea->iop[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
2086 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2087 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
2092 ql_dbg(ql_dbg_disc, vha, 0x2118,
2093 "%s %d %8phC priority %s, fc4type %x prev try %s\n",
2094 __func__, __LINE__, ea->fcport->port_name,
2095 vha->hw->fc4_type_priority == FC4_PRIORITY_FCP ?
2096 "FCP" : "NVMe", ea->fcport->fc4_type,
2097 (sp->u.iocb_cmd.u.logio.flags & SRB_LOGIN_NVME_PRLI) ?
2100 if (NVME_FCP_TARGET(ea->fcport)) {
2101 if (sp->u.iocb_cmd.u.logio.flags & SRB_LOGIN_NVME_PRLI)
2102 ea->fcport->do_prli_nvme = 0;
2104 ea->fcport->do_prli_nvme = 1;
2106 ea->fcport->do_prli_nvme = 0;
2109 if (N2N_TOPO(vha->hw)) {
2110 if (ea->fcport->n2n_link_reset_cnt <
2111 vha->hw->login_retry_count) {
2112 ea->fcport->n2n_link_reset_cnt++;
2113 vha->relogin_jif = jiffies + 2 * HZ;
2115 * PRLI failed. Reset link to kick start
2118 set_bit(N2N_LINK_RESET, &vha->dpc_flags);
2119 qla2xxx_wake_dpc(vha);
2121 ql_log(ql_log_warn, vha, 0x2119,
2122 "%s %d %8phC Unable to reconnect\n",
2124 ea->fcport->port_name);
2128 * switch connect. login failed. Take connection down
2129 * and allow relogin to retrigger
2131 ea->fcport->flags &= ~FCF_ASYNC_SENT;
2132 ea->fcport->keep_nport_handle = 0;
2133 ea->fcport->logout_on_delete = 1;
2134 qlt_schedule_sess_for_deletion(ea->fcport);
2141 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
2143 port_id_t cid; /* conflict Nport id */
2145 struct fc_port *conflict_fcport;
2146 unsigned long flags;
2147 struct fc_port *fcport = ea->fcport;
2149 ql_dbg(ql_dbg_disc, vha, 0xffff,
2150 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
2151 __func__, fcport->port_name, fcport->disc_state,
2152 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
2153 ea->sp->gen1, fcport->rscn_gen,
2154 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
2156 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
2157 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
2158 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2159 "%s %d %8phC Remote is trying to login\n",
2160 __func__, __LINE__, fcport->port_name);
2164 if ((fcport->disc_state == DSC_DELETE_PEND) ||
2165 (fcport->disc_state == DSC_DELETED)) {
2166 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2170 if (ea->sp->gen2 != fcport->login_gen) {
2171 /* target side must have changed it. */
2172 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2173 "%s %8phC generation changed\n",
2174 __func__, fcport->port_name);
2175 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2177 } else if (ea->sp->gen1 != fcport->rscn_gen) {
2178 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2179 "%s %8phC RSCN generation changed\n",
2180 __func__, fcport->port_name);
2181 qla_rscn_replay(fcport);
2182 qlt_schedule_sess_for_deletion(fcport);
2186 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
2189 switch (ea->data[0]) {
2190 case MBS_COMMAND_COMPLETE:
2192 * Driver must validate login state - If PRLI not complete,
2193 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
2196 if (vha->hw->flags.edif_enabled) {
2197 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2198 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2199 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2200 ea->fcport->logout_on_delete = 1;
2201 ea->fcport->send_els_logo = 0;
2202 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
2203 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2205 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2207 if (NVME_TARGET(vha->hw, fcport)) {
2208 ql_dbg(ql_dbg_disc, vha, 0x2117,
2209 "%s %d %8phC post prli\n",
2210 __func__, __LINE__, fcport->port_name);
2211 qla24xx_post_prli_work(vha, fcport);
2213 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2214 "%s %d %8phC LoopID 0x%x in use with %06x. post gpdb\n",
2215 __func__, __LINE__, fcport->port_name,
2216 fcport->loop_id, fcport->d_id.b24);
2218 set_bit(fcport->loop_id, vha->hw->loop_id_map);
2219 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2220 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2221 fcport->logout_on_delete = 1;
2222 fcport->send_els_logo = 0;
2223 fcport->fw_login_state = DSC_LS_PRLI_COMP;
2224 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2226 qla24xx_post_gpdb_work(vha, fcport, 0);
2230 case MBS_COMMAND_ERROR:
2231 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
2232 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
2234 qlt_schedule_sess_for_deletion(ea->fcport);
2236 case MBS_LOOP_ID_USED:
2237 /* data[1] = IO PARAM 1 = nport ID */
2238 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
2239 cid.b.area = (ea->iop[1] >> 8) & 0xff;
2240 cid.b.al_pa = ea->iop[1] & 0xff;
2243 ql_dbg(ql_dbg_disc, vha, 0x20ec,
2244 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2245 __func__, __LINE__, ea->fcport->port_name,
2246 ea->fcport->loop_id, cid.b24);
2248 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2249 ea->fcport->loop_id = FC_NO_LOOP_ID;
2250 qla24xx_post_gnl_work(vha, ea->fcport);
2252 case MBS_PORT_ID_USED:
2253 lid = ea->iop[1] & 0xffff;
2254 qlt_find_sess_invalidate_other(vha,
2255 wwn_to_u64(ea->fcport->port_name),
2256 ea->fcport->d_id, lid, &conflict_fcport);
2258 if (conflict_fcport) {
2260 * Another fcport share the same loop_id/nport id.
2261 * Conflict fcport needs to finish cleanup before this
2262 * fcport can proceed to login.
2264 conflict_fcport->conflict = ea->fcport;
2265 ea->fcport->login_pause = 1;
2267 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2268 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
2269 __func__, __LINE__, ea->fcport->port_name,
2270 ea->fcport->d_id.b24, lid);
2272 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2273 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2274 __func__, __LINE__, ea->fcport->port_name,
2275 ea->fcport->d_id.b24, lid);
2277 qla2x00_clear_loop_id(ea->fcport);
2278 set_bit(lid, vha->hw->loop_id_map);
2279 ea->fcport->loop_id = lid;
2280 ea->fcport->keep_nport_handle = 0;
2281 ea->fcport->logout_on_delete = 1;
2282 qlt_schedule_sess_for_deletion(ea->fcport);
2289 /****************************************************************************/
2290 /* QLogic ISP2x00 Hardware Support Functions. */
2291 /****************************************************************************/
2294 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
2296 int rval = QLA_SUCCESS;
2297 struct qla_hw_data *ha = vha->hw;
2298 uint32_t idc_major_ver, idc_minor_ver;
2301 qla83xx_idc_lock(vha, 0);
2303 /* SV: TODO: Assign initialization timeout from
2304 * flash-info / other param
2306 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
2307 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
2309 /* Set our fcoe function presence */
2310 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
2311 ql_dbg(ql_dbg_p3p, vha, 0xb077,
2312 "Error while setting DRV-Presence.\n");
2313 rval = QLA_FUNCTION_FAILED;
2317 /* Decide the reset ownership */
2318 qla83xx_reset_ownership(vha);
2321 * On first protocol driver load:
2322 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2324 * Others: Check compatibility with current IDC Major version.
2326 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
2327 if (ha->flags.nic_core_reset_owner) {
2328 /* Set IDC Major version */
2329 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
2330 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
2332 /* Clearing IDC-Lock-Recovery register */
2333 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
2334 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
2336 * Clear further IDC participation if we are not compatible with
2337 * the current IDC Major Version.
2339 ql_log(ql_log_warn, vha, 0xb07d,
2340 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2341 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
2342 __qla83xx_clear_drv_presence(vha);
2343 rval = QLA_FUNCTION_FAILED;
2346 /* Each function sets its supported Minor version. */
2347 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
2348 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
2349 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
2351 if (ha->flags.nic_core_reset_owner) {
2352 memset(config, 0, sizeof(config));
2353 if (!qla81xx_get_port_config(vha, config))
2354 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
2358 rval = qla83xx_idc_state_handler(vha);
2361 qla83xx_idc_unlock(vha, 0);
2367 * qla2x00_initialize_adapter
2371 * ha = adapter block pointer.
2377 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
2380 struct qla_hw_data *ha = vha->hw;
2381 struct req_que *req = ha->req_q_map[0];
2382 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2384 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2385 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2387 /* Clear adapter flags. */
2388 vha->flags.online = 0;
2389 ha->flags.chip_reset_done = 0;
2390 vha->flags.reset_active = 0;
2391 ha->flags.pci_channel_io_perm_failure = 0;
2392 ha->flags.eeh_busy = 0;
2393 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2394 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
2395 atomic_set(&vha->loop_state, LOOP_DOWN);
2396 vha->device_flags = DFLG_NO_CABLE;
2398 vha->flags.management_server_logged_in = 0;
2399 vha->marker_needed = 0;
2400 ha->isp_abort_cnt = 0;
2401 ha->beacon_blink_led = 0;
2403 set_bit(0, ha->req_qid_map);
2404 set_bit(0, ha->rsp_qid_map);
2406 ql_dbg(ql_dbg_init, vha, 0x0040,
2407 "Configuring PCI space...\n");
2408 rval = ha->isp_ops->pci_config(vha);
2410 ql_log(ql_log_warn, vha, 0x0044,
2411 "Unable to configure PCI space.\n");
2415 ha->isp_ops->reset_chip(vha);
2417 /* Check for secure flash support */
2418 if (IS_QLA28XX(ha)) {
2419 if (rd_reg_word(®->mailbox12) & BIT_0)
2420 ha->flags.secure_adapter = 1;
2421 ql_log(ql_log_info, vha, 0xffff, "Secure Adapter: %s\n",
2422 (ha->flags.secure_adapter) ? "Yes" : "No");
2426 rval = qla2xxx_get_flash_info(vha);
2428 ql_log(ql_log_fatal, vha, 0x004f,
2429 "Unable to validate FLASH data.\n");
2433 if (IS_QLA8044(ha)) {
2434 qla8044_read_reset_template(vha);
2436 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2437 * If DONRESET_BIT0 is set, drivers should not set dev_state
2438 * to NEED_RESET. But if NEED_RESET is set, drivers should
2439 * should honor the reset. */
2440 if (ql2xdontresethba == 1)
2441 qla8044_set_idc_dontreset(vha);
2444 ha->isp_ops->get_flash_version(vha, req->ring);
2445 ql_dbg(ql_dbg_init, vha, 0x0061,
2446 "Configure NVRAM parameters...\n");
2448 /* Let priority default to FCP, can be overridden by nvram_config */
2449 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2451 ha->isp_ops->nvram_config(vha);
2453 if (ha->fc4_type_priority != FC4_PRIORITY_FCP &&
2454 ha->fc4_type_priority != FC4_PRIORITY_NVME)
2455 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2457 ql_log(ql_log_info, vha, 0xffff, "FC4 priority set to %s\n",
2458 ha->fc4_type_priority == FC4_PRIORITY_FCP ? "FCP" : "NVMe");
2460 if (ha->flags.disable_serdes) {
2461 /* Mask HBA via NVRAM settings? */
2462 ql_log(ql_log_info, vha, 0x0077,
2463 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
2464 return QLA_FUNCTION_FAILED;
2467 ql_dbg(ql_dbg_init, vha, 0x0078,
2468 "Verifying loaded RISC code...\n");
2470 /* If smartsan enabled then require fdmi and rdp enabled */
2476 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
2477 rval = ha->isp_ops->chip_diag(vha);
2480 rval = qla2x00_setup_chip(vha);
2485 if (IS_QLA84XX(ha)) {
2486 ha->cs84xx = qla84xx_get_chip(vha);
2488 ql_log(ql_log_warn, vha, 0x00d0,
2489 "Unable to configure ISP84XX.\n");
2490 return QLA_FUNCTION_FAILED;
2494 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2495 rval = qla2x00_init_rings(vha);
2497 /* No point in continuing if firmware initialization failed. */
2498 if (rval != QLA_SUCCESS)
2501 ha->flags.chip_reset_done = 1;
2503 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2504 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2505 rval = qla84xx_init_chip(vha);
2506 if (rval != QLA_SUCCESS) {
2507 ql_log(ql_log_warn, vha, 0x00d4,
2508 "Unable to initialize ISP84XX.\n");
2509 qla84xx_put_chip(vha);
2513 /* Load the NIC Core f/w if we are the first protocol driver. */
2514 if (IS_QLA8031(ha)) {
2515 rval = qla83xx_nic_core_fw_load(vha);
2517 ql_log(ql_log_warn, vha, 0x0124,
2518 "Error in initializing NIC Core f/w.\n");
2521 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2522 qla24xx_read_fcp_prio_cfg(vha);
2524 if (IS_P3P_TYPE(ha))
2525 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2527 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2533 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2536 * Returns 0 on success.
2539 qla2100_pci_config(scsi_qla_host_t *vha)
2542 unsigned long flags;
2543 struct qla_hw_data *ha = vha->hw;
2544 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2546 pci_set_master(ha->pdev);
2547 pci_try_set_mwi(ha->pdev);
2549 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2550 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2551 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2553 pci_disable_rom(ha->pdev);
2555 /* Get PCI bus information. */
2556 spin_lock_irqsave(&ha->hardware_lock, flags);
2557 ha->pci_attr = rd_reg_word(®->ctrl_status);
2558 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2564 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2567 * Returns 0 on success.
2570 qla2300_pci_config(scsi_qla_host_t *vha)
2573 unsigned long flags = 0;
2575 struct qla_hw_data *ha = vha->hw;
2576 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2578 pci_set_master(ha->pdev);
2579 pci_try_set_mwi(ha->pdev);
2581 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2582 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2584 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2585 w &= ~PCI_COMMAND_INTX_DISABLE;
2586 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2589 * If this is a 2300 card and not 2312, reset the
2590 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2591 * the 2310 also reports itself as a 2300 so we need to get the
2592 * fb revision level -- a 6 indicates it really is a 2300 and
2595 if (IS_QLA2300(ha)) {
2596 spin_lock_irqsave(&ha->hardware_lock, flags);
2599 wrt_reg_word(®->hccr, HCCR_PAUSE_RISC);
2600 for (cnt = 0; cnt < 30000; cnt++) {
2601 if ((rd_reg_word(®->hccr) & HCCR_RISC_PAUSE) != 0)
2607 /* Select FPM registers. */
2608 wrt_reg_word(®->ctrl_status, 0x20);
2609 rd_reg_word(®->ctrl_status);
2611 /* Get the fb rev level */
2612 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2614 if (ha->fb_rev == FPM_2300)
2615 pci_clear_mwi(ha->pdev);
2617 /* Deselect FPM registers. */
2618 wrt_reg_word(®->ctrl_status, 0x0);
2619 rd_reg_word(®->ctrl_status);
2621 /* Release RISC module. */
2622 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
2623 for (cnt = 0; cnt < 30000; cnt++) {
2624 if ((rd_reg_word(®->hccr) & HCCR_RISC_PAUSE) == 0)
2630 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2633 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2635 pci_disable_rom(ha->pdev);
2637 /* Get PCI bus information. */
2638 spin_lock_irqsave(&ha->hardware_lock, flags);
2639 ha->pci_attr = rd_reg_word(®->ctrl_status);
2640 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2646 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2649 * Returns 0 on success.
2652 qla24xx_pci_config(scsi_qla_host_t *vha)
2655 unsigned long flags = 0;
2656 struct qla_hw_data *ha = vha->hw;
2657 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2659 pci_set_master(ha->pdev);
2660 pci_try_set_mwi(ha->pdev);
2662 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2663 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2664 w &= ~PCI_COMMAND_INTX_DISABLE;
2665 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2667 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2669 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2670 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2671 pcix_set_mmrbc(ha->pdev, 2048);
2673 /* PCIe -- adjust Maximum Read Request Size (2048). */
2674 if (pci_is_pcie(ha->pdev))
2675 pcie_set_readrq(ha->pdev, 4096);
2677 pci_disable_rom(ha->pdev);
2679 ha->chip_revision = ha->pdev->revision;
2681 /* Get PCI bus information. */
2682 spin_lock_irqsave(&ha->hardware_lock, flags);
2683 ha->pci_attr = rd_reg_dword(®->ctrl_status);
2684 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2690 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2693 * Returns 0 on success.
2696 qla25xx_pci_config(scsi_qla_host_t *vha)
2699 struct qla_hw_data *ha = vha->hw;
2701 pci_set_master(ha->pdev);
2702 pci_try_set_mwi(ha->pdev);
2704 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2705 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2706 w &= ~PCI_COMMAND_INTX_DISABLE;
2707 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2709 /* PCIe -- adjust Maximum Read Request Size (2048). */
2710 if (pci_is_pcie(ha->pdev))
2711 pcie_set_readrq(ha->pdev, 4096);
2713 pci_disable_rom(ha->pdev);
2715 ha->chip_revision = ha->pdev->revision;
2721 * qla2x00_isp_firmware() - Choose firmware image.
2724 * Returns 0 on success.
2727 qla2x00_isp_firmware(scsi_qla_host_t *vha)
2730 uint16_t loop_id, topo, sw_cap;
2731 uint8_t domain, area, al_pa;
2732 struct qla_hw_data *ha = vha->hw;
2734 /* Assume loading risc code */
2735 rval = QLA_FUNCTION_FAILED;
2737 if (ha->flags.disable_risc_code_load) {
2738 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
2740 /* Verify checksum of loaded RISC code. */
2741 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
2742 if (rval == QLA_SUCCESS) {
2743 /* And, verify we are not in ROM code. */
2744 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2745 &area, &domain, &topo, &sw_cap);
2750 ql_dbg(ql_dbg_init, vha, 0x007a,
2751 "**** Load RISC code ****.\n");
2757 * qla2x00_reset_chip() - Reset ISP chip.
2760 * Returns 0 on success.
2763 qla2x00_reset_chip(scsi_qla_host_t *vha)
2765 unsigned long flags = 0;
2766 struct qla_hw_data *ha = vha->hw;
2767 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2770 int rval = QLA_FUNCTION_FAILED;
2772 if (unlikely(pci_channel_offline(ha->pdev)))
2775 ha->isp_ops->disable_intrs(ha);
2777 spin_lock_irqsave(&ha->hardware_lock, flags);
2779 /* Turn off master enable */
2781 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2782 cmd &= ~PCI_COMMAND_MASTER;
2783 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2785 if (!IS_QLA2100(ha)) {
2787 wrt_reg_word(®->hccr, HCCR_PAUSE_RISC);
2788 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2789 for (cnt = 0; cnt < 30000; cnt++) {
2790 if ((rd_reg_word(®->hccr) &
2791 HCCR_RISC_PAUSE) != 0)
2796 rd_reg_word(®->hccr); /* PCI Posting. */
2800 /* Select FPM registers. */
2801 wrt_reg_word(®->ctrl_status, 0x20);
2802 rd_reg_word(®->ctrl_status); /* PCI Posting. */
2804 /* FPM Soft Reset. */
2805 wrt_reg_word(®->fpm_diag_config, 0x100);
2806 rd_reg_word(®->fpm_diag_config); /* PCI Posting. */
2808 /* Toggle Fpm Reset. */
2809 if (!IS_QLA2200(ha)) {
2810 wrt_reg_word(®->fpm_diag_config, 0x0);
2811 rd_reg_word(®->fpm_diag_config); /* PCI Posting. */
2814 /* Select frame buffer registers. */
2815 wrt_reg_word(®->ctrl_status, 0x10);
2816 rd_reg_word(®->ctrl_status); /* PCI Posting. */
2818 /* Reset frame buffer FIFOs. */
2819 if (IS_QLA2200(ha)) {
2820 WRT_FB_CMD_REG(ha, reg, 0xa000);
2821 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2823 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2825 /* Read back fb_cmd until zero or 3 seconds max */
2826 for (cnt = 0; cnt < 3000; cnt++) {
2827 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2833 /* Select RISC module registers. */
2834 wrt_reg_word(®->ctrl_status, 0);
2835 rd_reg_word(®->ctrl_status); /* PCI Posting. */
2837 /* Reset RISC processor. */
2838 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
2839 rd_reg_word(®->hccr); /* PCI Posting. */
2841 /* Release RISC processor. */
2842 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
2843 rd_reg_word(®->hccr); /* PCI Posting. */
2846 wrt_reg_word(®->hccr, HCCR_CLR_RISC_INT);
2847 wrt_reg_word(®->hccr, HCCR_CLR_HOST_INT);
2849 /* Reset ISP chip. */
2850 wrt_reg_word(®->ctrl_status, CSR_ISP_SOFT_RESET);
2852 /* Wait for RISC to recover from reset. */
2853 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2855 * It is necessary to for a delay here since the card doesn't
2856 * respond to PCI reads during a reset. On some architectures
2857 * this will result in an MCA.
2860 for (cnt = 30000; cnt; cnt--) {
2861 if ((rd_reg_word(®->ctrl_status) &
2862 CSR_ISP_SOFT_RESET) == 0)
2869 /* Reset RISC processor. */
2870 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
2872 wrt_reg_word(®->semaphore, 0);
2874 /* Release RISC processor. */
2875 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
2876 rd_reg_word(®->hccr); /* PCI Posting. */
2878 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2879 for (cnt = 0; cnt < 30000; cnt++) {
2880 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
2888 /* Turn on master enable */
2889 cmd |= PCI_COMMAND_MASTER;
2890 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2892 /* Disable RISC pause on FPM parity error. */
2893 if (!IS_QLA2100(ha)) {
2894 wrt_reg_word(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
2895 rd_reg_word(®->hccr); /* PCI Posting. */
2898 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2904 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2907 * Returns 0 on success.
2910 qla81xx_reset_mpi(scsi_qla_host_t *vha)
2912 uint16_t mb[4] = {0x1010, 0, 1, 0};
2914 if (!IS_QLA81XX(vha->hw))
2917 return qla81xx_write_mpi_register(vha, mb);
2921 qla_chk_risc_recovery(scsi_qla_host_t *vha)
2923 struct qla_hw_data *ha = vha->hw;
2924 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2925 __le16 __iomem *mbptr = ®->mailbox0;
2928 int rc = QLA_SUCCESS;
2930 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
2933 /* this check is only valid after RISC reset */
2934 mb[0] = rd_reg_word(mbptr);
2937 rc = QLA_FUNCTION_FAILED;
2939 for (i = 1; i < 32; i++) {
2940 mb[i] = rd_reg_word(mbptr);
2944 ql_log(ql_log_warn, vha, 0x1015,
2945 "RISC reset failed. mb[0-7] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
2946 mb[0], mb[1], mb[2], mb[3], mb[4], mb[5], mb[6], mb[7]);
2947 ql_log(ql_log_warn, vha, 0x1015,
2948 "RISC reset failed. mb[8-15] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
2949 mb[8], mb[9], mb[10], mb[11], mb[12], mb[13], mb[14],
2951 ql_log(ql_log_warn, vha, 0x1015,
2952 "RISC reset failed. mb[16-23] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
2953 mb[16], mb[17], mb[18], mb[19], mb[20], mb[21], mb[22],
2955 ql_log(ql_log_warn, vha, 0x1015,
2956 "RISC reset failed. mb[24-31] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
2957 mb[24], mb[25], mb[26], mb[27], mb[28], mb[29], mb[30],
2964 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2967 * Returns 0 on success.
2970 qla24xx_reset_risc(scsi_qla_host_t *vha)
2972 unsigned long flags = 0;
2973 struct qla_hw_data *ha = vha->hw;
2974 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2977 static int abts_cnt; /* ISP abort retry counts */
2978 int rval = QLA_SUCCESS;
2981 spin_lock_irqsave(&ha->hardware_lock, flags);
2984 wrt_reg_dword(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2985 for (cnt = 0; cnt < 30000; cnt++) {
2986 if ((rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2992 if (!(rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE))
2993 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2995 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2996 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2997 rd_reg_dword(®->hccr),
2998 rd_reg_dword(®->ctrl_status),
2999 (rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE));
3001 wrt_reg_dword(®->ctrl_status,
3002 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
3003 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
3007 /* Wait for firmware to complete NVRAM accesses. */
3008 rd_reg_word(®->mailbox0);
3009 for (cnt = 10000; rd_reg_word(®->mailbox0) != 0 &&
3010 rval == QLA_SUCCESS; cnt--) {
3015 rval = QLA_FUNCTION_TIMEOUT;
3018 if (rval == QLA_SUCCESS)
3019 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
3021 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
3022 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
3023 rd_reg_dword(®->hccr),
3024 rd_reg_word(®->mailbox0));
3026 /* Wait for soft-reset to complete. */
3027 rd_reg_dword(®->ctrl_status);
3028 for (cnt = 0; cnt < 60; cnt++) {
3030 if ((rd_reg_dword(®->ctrl_status) &
3031 CSRX_ISP_SOFT_RESET) == 0)
3036 if (!(rd_reg_dword(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
3037 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
3039 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
3040 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
3041 rd_reg_dword(®->hccr),
3042 rd_reg_dword(®->ctrl_status));
3044 /* If required, do an MPI FW reset now */
3045 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
3046 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
3047 if (++abts_cnt < 5) {
3048 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3049 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
3052 * We exhausted the ISP abort retries. We have to
3053 * set the board offline.
3056 vha->flags.online = 0;
3061 wrt_reg_dword(®->hccr, HCCRX_SET_RISC_RESET);
3062 rd_reg_dword(®->hccr);
3064 wrt_reg_dword(®->hccr, HCCRX_REL_RISC_PAUSE);
3065 rd_reg_dword(®->hccr);
3067 wrt_reg_dword(®->hccr, HCCRX_CLR_RISC_RESET);
3069 rd_reg_dword(®->hccr);
3071 wd = rd_reg_word(®->mailbox0);
3072 for (cnt = 300; wd != 0 && rval == QLA_SUCCESS; cnt--) {
3076 if (print && qla_chk_risc_recovery(vha))
3079 wd = rd_reg_word(®->mailbox0);
3081 rval = QLA_FUNCTION_TIMEOUT;
3083 ql_log(ql_log_warn, vha, 0x015e,
3084 "RISC reset timeout\n");
3088 if (rval == QLA_SUCCESS)
3089 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
3091 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
3092 "Host Risc 0x%x, mailbox0 0x%x\n",
3093 rd_reg_dword(®->hccr),
3094 rd_reg_word(®->mailbox0));
3096 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3098 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
3099 "Driver in %s mode\n",
3100 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
3102 if (IS_NOPOLLING_TYPE(ha))
3103 ha->isp_ops->enable_intrs(ha);
3109 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
3111 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
3113 wrt_reg_dword(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
3114 *data = rd_reg_dword(®->iobase_window + RISC_REGISTER_WINDOW_OFFSET);
3118 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
3120 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
3122 wrt_reg_dword(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
3123 wrt_reg_dword(®->iobase_window + RISC_REGISTER_WINDOW_OFFSET, data);
3127 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
3130 uint delta_msec = 100;
3131 uint elapsed_msec = 0;
3135 if (vha->hw->pdev->subsystem_device != 0x0175 &&
3136 vha->hw->pdev->subsystem_device != 0x0240)
3139 wrt_reg_dword(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
3143 timeout_msec = TIMEOUT_SEMAPHORE;
3144 n = timeout_msec / delta_msec;
3146 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
3147 qla25xx_read_risc_sema_reg(vha, &wd32);
3148 if (wd32 & RISC_SEMAPHORE)
3151 elapsed_msec += delta_msec;
3152 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
3156 if (!(wd32 & RISC_SEMAPHORE))
3159 if (!(wd32 & RISC_SEMAPHORE_FORCE))
3162 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
3163 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
3164 n = timeout_msec / delta_msec;
3166 qla25xx_read_risc_sema_reg(vha, &wd32);
3167 if (!(wd32 & RISC_SEMAPHORE_FORCE))
3170 elapsed_msec += delta_msec;
3171 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
3175 if (wd32 & RISC_SEMAPHORE_FORCE)
3176 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
3181 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
3188 * qla24xx_reset_chip() - Reset ISP24xx chip.
3191 * Returns 0 on success.
3194 qla24xx_reset_chip(scsi_qla_host_t *vha)
3196 struct qla_hw_data *ha = vha->hw;
3197 int rval = QLA_FUNCTION_FAILED;
3199 if (pci_channel_offline(ha->pdev) &&
3200 ha->flags.pci_channel_io_perm_failure) {
3204 ha->isp_ops->disable_intrs(ha);
3206 qla25xx_manipulate_risc_semaphore(vha);
3208 /* Perform RISC reset. */
3209 rval = qla24xx_reset_risc(vha);
3215 * qla2x00_chip_diag() - Test chip for proper operation.
3218 * Returns 0 on success.
3221 qla2x00_chip_diag(scsi_qla_host_t *vha)
3224 struct qla_hw_data *ha = vha->hw;
3225 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3226 unsigned long flags = 0;
3230 struct req_que *req = ha->req_q_map[0];
3232 /* Assume a failed state */
3233 rval = QLA_FUNCTION_FAILED;
3235 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
3236 ®->flash_address);
3238 spin_lock_irqsave(&ha->hardware_lock, flags);
3240 /* Reset ISP chip. */
3241 wrt_reg_word(®->ctrl_status, CSR_ISP_SOFT_RESET);
3244 * We need to have a delay here since the card will not respond while
3245 * in reset causing an MCA on some architectures.
3248 data = qla2x00_debounce_register(®->ctrl_status);
3249 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
3251 data = rd_reg_word(®->ctrl_status);
3256 goto chip_diag_failed;
3258 ql_dbg(ql_dbg_init, vha, 0x007c,
3259 "Reset register cleared by chip reset.\n");
3261 /* Reset RISC processor. */
3262 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
3263 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
3265 /* Workaround for QLA2312 PCI parity error */
3266 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
3267 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
3268 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
3270 data = RD_MAILBOX_REG(ha, reg, 0);
3277 goto chip_diag_failed;
3279 /* Check product ID of chip */
3280 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
3282 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
3283 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
3284 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
3285 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
3286 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
3287 mb[3] != PROD_ID_3) {
3288 ql_log(ql_log_warn, vha, 0x0062,
3289 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
3290 mb[1], mb[2], mb[3]);
3292 goto chip_diag_failed;
3294 ha->product_id[0] = mb[1];
3295 ha->product_id[1] = mb[2];
3296 ha->product_id[2] = mb[3];
3297 ha->product_id[3] = mb[4];
3299 /* Adjust fw RISC transfer size */
3300 if (req->length > 1024)
3301 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
3303 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
3306 if (IS_QLA2200(ha) &&
3307 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
3308 /* Limit firmware transfer size with a 2200A */
3309 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
3311 ha->device_type |= DT_ISP2200A;
3312 ha->fw_transfer_size = 128;
3315 /* Wrap Incoming Mailboxes Test. */
3316 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3318 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
3319 rval = qla2x00_mbx_reg_test(vha);
3321 ql_log(ql_log_warn, vha, 0x0080,
3322 "Failed mailbox send register test.\n");
3324 /* Flag a successful rval */
3326 spin_lock_irqsave(&ha->hardware_lock, flags);
3330 ql_log(ql_log_info, vha, 0x0081,
3331 "Chip diagnostics **** FAILED ****.\n");
3333 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3339 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3342 * Returns 0 on success.
3345 qla24xx_chip_diag(scsi_qla_host_t *vha)
3348 struct qla_hw_data *ha = vha->hw;
3349 struct req_que *req = ha->req_q_map[0];
3351 if (IS_P3P_TYPE(ha))
3354 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
3356 rval = qla2x00_mbx_reg_test(vha);
3358 ql_log(ql_log_warn, vha, 0x0082,
3359 "Failed mailbox send register test.\n");
3361 /* Flag a successful rval */
3369 qla2x00_init_fce_trace(scsi_qla_host_t *vha)
3374 struct qla_hw_data *ha = vha->hw;
3376 if (!IS_FWI2_CAPABLE(ha))
3379 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3380 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3384 ql_dbg(ql_dbg_init, vha, 0x00bd,
3385 "%s: FCE Mem is already allocated.\n",
3390 /* Allocate memory for Fibre Channel Event Buffer. */
3391 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3394 ql_log(ql_log_warn, vha, 0x00be,
3395 "Unable to allocate (%d KB) for FCE.\n",
3400 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3401 ha->fce_mb, &ha->fce_bufs);
3403 ql_log(ql_log_warn, vha, 0x00bf,
3404 "Unable to initialize FCE (%d).\n", rval);
3405 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, tc_dma);
3409 ql_dbg(ql_dbg_init, vha, 0x00c0,
3410 "Allocated (%d KB) for FCE...\n", FCE_SIZE / 1024);
3412 ha->flags.fce_enabled = 1;
3413 ha->fce_dma = tc_dma;
3418 qla2x00_init_eft_trace(scsi_qla_host_t *vha)
3423 struct qla_hw_data *ha = vha->hw;
3425 if (!IS_FWI2_CAPABLE(ha))
3429 ql_dbg(ql_dbg_init, vha, 0x00bd,
3430 "%s: EFT Mem is already allocated.\n",
3435 /* Allocate memory for Extended Trace Buffer. */
3436 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3439 ql_log(ql_log_warn, vha, 0x00c1,
3440 "Unable to allocate (%d KB) for EFT.\n",
3445 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3447 ql_log(ql_log_warn, vha, 0x00c2,
3448 "Unable to initialize EFT (%d).\n", rval);
3449 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, tc_dma);
3453 ql_dbg(ql_dbg_init, vha, 0x00c3,
3454 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3456 ha->eft_dma = tc_dma;
3461 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3463 qla2x00_init_fce_trace(vha);
3464 qla2x00_init_eft_trace(vha);
3468 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3470 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
3471 eft_size, fce_size, mq_size;
3472 struct qla_hw_data *ha = vha->hw;
3473 struct req_que *req = ha->req_q_map[0];
3474 struct rsp_que *rsp = ha->rsp_q_map[0];
3475 struct qla2xxx_fw_dump *fw_dump;
3477 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
3478 req_q_size = rsp_q_size = 0;
3480 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3481 fixed_size = sizeof(struct qla2100_fw_dump);
3482 } else if (IS_QLA23XX(ha)) {
3483 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
3484 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
3486 } else if (IS_FWI2_CAPABLE(ha)) {
3487 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
3488 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
3489 else if (IS_QLA81XX(ha))
3490 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
3491 else if (IS_QLA25XX(ha))
3492 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
3494 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
3496 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
3499 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) &&
3501 mq_size = sizeof(struct qla2xxx_mq_chain);
3503 * Allocate maximum buffer size for all queues - Q0.
3504 * Resizing must be done at end-of-dump processing.
3506 mq_size += (ha->max_req_queues - 1) *
3507 (req->length * sizeof(request_t));
3508 mq_size += (ha->max_rsp_queues - 1) *
3509 (rsp->length * sizeof(response_t));
3511 if (ha->tgt.atio_ring)
3512 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3514 qla2x00_init_fce_trace(vha);
3516 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3517 qla2x00_init_eft_trace(vha);
3519 eft_size = EFT_SIZE;
3522 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3523 struct fwdt *fwdt = ha->fwdt;
3526 for (j = 0; j < 2; j++, fwdt++) {
3527 if (!fwdt->template) {
3528 ql_dbg(ql_dbg_init, vha, 0x00ba,
3529 "-> fwdt%u no template\n", j);
3532 ql_dbg(ql_dbg_init, vha, 0x00fa,
3533 "-> fwdt%u calculating fwdump size...\n", j);
3534 fwdt->dump_size = qla27xx_fwdt_calculate_dump_size(
3535 vha, fwdt->template);
3536 ql_dbg(ql_dbg_init, vha, 0x00fa,
3537 "-> fwdt%u calculated fwdump size = %#lx bytes\n",
3538 j, fwdt->dump_size);
3539 dump_size += fwdt->dump_size;
3541 /* Add space for spare MPI fw dump. */
3542 dump_size += ha->fwdt[1].dump_size;
3544 req_q_size = req->length * sizeof(request_t);
3545 rsp_q_size = rsp->length * sizeof(response_t);
3546 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3547 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size
3549 ha->chain_offset = dump_size;
3550 dump_size += mq_size + fce_size;
3551 if (ha->exchoffld_buf)
3552 dump_size += sizeof(struct qla2xxx_offld_chain) +
3554 if (ha->exlogin_buf)
3555 dump_size += sizeof(struct qla2xxx_offld_chain) +
3559 if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) {
3561 ql_dbg(ql_dbg_init, vha, 0x00c5,
3562 "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n",
3563 __func__, dump_size, ha->fw_dump_len,
3564 ha->fw_dump_alloc_len);
3566 fw_dump = vmalloc(dump_size);
3568 ql_log(ql_log_warn, vha, 0x00c4,
3569 "Unable to allocate (%d KB) for firmware dump.\n",
3572 mutex_lock(&ha->optrom_mutex);
3573 if (ha->fw_dumped) {
3574 memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len);
3576 ha->fw_dump = fw_dump;
3577 ha->fw_dump_alloc_len = dump_size;
3578 ql_dbg(ql_dbg_init, vha, 0x00c5,
3579 "Re-Allocated (%d KB) and save firmware dump.\n",
3583 ha->fw_dump = fw_dump;
3585 ha->fw_dump_len = ha->fw_dump_alloc_len =
3587 ql_dbg(ql_dbg_init, vha, 0x00c5,
3588 "Allocated (%d KB) for firmware dump.\n",
3591 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3592 ha->mpi_fw_dump = (char *)fw_dump +
3593 ha->fwdt[1].dump_size;
3594 mutex_unlock(&ha->optrom_mutex);
3598 ha->fw_dump->signature[0] = 'Q';
3599 ha->fw_dump->signature[1] = 'L';
3600 ha->fw_dump->signature[2] = 'G';
3601 ha->fw_dump->signature[3] = 'C';
3602 ha->fw_dump->version = htonl(1);
3604 ha->fw_dump->fixed_size = htonl(fixed_size);
3605 ha->fw_dump->mem_size = htonl(mem_size);
3606 ha->fw_dump->req_q_size = htonl(req_q_size);
3607 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3609 ha->fw_dump->eft_size = htonl(eft_size);
3610 ha->fw_dump->eft_addr_l =
3611 htonl(LSD(ha->eft_dma));
3612 ha->fw_dump->eft_addr_h =
3613 htonl(MSD(ha->eft_dma));
3615 ha->fw_dump->header_size =
3617 (struct qla2xxx_fw_dump, isp));
3619 mutex_unlock(&ha->optrom_mutex);
3625 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3627 #define MPS_MASK 0xe0
3632 if (!IS_QLA81XX(vha->hw))
3635 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3636 if (rval != QLA_SUCCESS) {
3637 ql_log(ql_log_warn, vha, 0x0105,
3638 "Unable to acquire semaphore.\n");
3642 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3643 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3644 if (rval != QLA_SUCCESS) {
3645 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3650 if (dc == (dw & MPS_MASK))
3655 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3656 if (rval != QLA_SUCCESS) {
3657 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3661 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3662 if (rval != QLA_SUCCESS) {
3663 ql_log(ql_log_warn, vha, 0x006d,
3664 "Unable to release semaphore.\n");
3672 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3674 /* Don't try to reallocate the array */
3675 if (req->outstanding_cmds)
3678 if (!IS_FWI2_CAPABLE(ha))
3679 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3681 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3682 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3684 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3687 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3691 if (!req->outstanding_cmds) {
3693 * Try to allocate a minimal size just so we can get through
3696 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
3697 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3701 if (!req->outstanding_cmds) {
3702 ql_log(ql_log_fatal, NULL, 0x0126,
3703 "Failed to allocate memory for "
3704 "outstanding_cmds for req_que %p.\n", req);
3705 req->num_outstanding_cmds = 0;
3706 return QLA_FUNCTION_FAILED;
3713 #define PRINT_FIELD(_field, _flag, _str) { \
3714 if (a0->_field & _flag) {\
3720 len = snprintf(ptr, leftover, "%s", _str); \
3727 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
3730 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
3731 u8 str[STR_LEN], *ptr, p;
3734 memset(str, 0, STR_LEN);
3735 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
3736 ql_dbg(ql_dbg_init, vha, 0x015a,
3737 "SFP MFG Name: %s\n", str);
3739 memset(str, 0, STR_LEN);
3740 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
3741 ql_dbg(ql_dbg_init, vha, 0x015c,
3742 "SFP Part Name: %s\n", str);
3745 memset(str, 0, STR_LEN);
3749 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
3750 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
3751 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
3752 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
3753 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3754 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3755 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3756 ql_dbg(ql_dbg_init, vha, 0x0160,
3757 "SFP Media: %s\n", str);
3760 memset(str, 0, STR_LEN);
3764 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3765 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3766 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3767 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3768 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3769 ql_dbg(ql_dbg_init, vha, 0x0196,
3770 "SFP Link Length: %s\n", str);
3772 memset(str, 0, STR_LEN);
3776 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3777 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3778 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3779 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3780 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3781 ql_dbg(ql_dbg_init, vha, 0x016e,
3782 "SFP FC Link Tech: %s\n", str);
3785 ql_dbg(ql_dbg_init, vha, 0x016f,
3786 "SFP Distant: %d km\n", a0->length_km);
3787 if (a0->length_100m)
3788 ql_dbg(ql_dbg_init, vha, 0x0170,
3789 "SFP Distant: %d m\n", a0->length_100m*100);
3790 if (a0->length_50um_10m)
3791 ql_dbg(ql_dbg_init, vha, 0x0189,
3792 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3793 if (a0->length_62um_10m)
3794 ql_dbg(ql_dbg_init, vha, 0x018a,
3795 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3796 if (a0->length_om4_10m)
3797 ql_dbg(ql_dbg_init, vha, 0x0194,
3798 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3799 if (a0->length_om3_10m)
3800 ql_dbg(ql_dbg_init, vha, 0x0195,
3801 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3806 * qla24xx_detect_sfp()
3808 * @vha: adapter state pointer.
3811 * 0 -- Configure firmware to use short-range settings -- normal
3812 * buffer-to-buffer credits.
3814 * 1 -- Configure firmware to use long-range settings -- extra
3815 * buffer-to-buffer credits should be allocated with
3816 * ha->lr_distance containing distance settings from NVRAM or SFP
3820 qla24xx_detect_sfp(scsi_qla_host_t *vha)
3823 struct sff_8247_a0 *a;
3824 struct qla_hw_data *ha = vha->hw;
3825 struct nvram_81xx *nv = ha->nvram;
3826 #define LR_DISTANCE_UNKNOWN 2
3827 static const char * const types[] = { "Short", "Long" };
3828 static const char * const lengths[] = { "(10km)", "(5km)", "" };
3831 /* Seed with NVRAM settings. */
3833 ha->flags.lr_detected = 0;
3834 if (IS_BPM_RANGE_CAPABLE(ha) &&
3835 (nv->enhanced_features & NEF_LR_DIST_ENABLE)) {
3837 ha->flags.lr_detected = 1;
3839 (nv->enhanced_features >> LR_DIST_NV_POS)
3843 if (!IS_BPM_ENABLED(vha))
3845 /* Determine SR/LR capabilities of SFP/Transceiver. */
3846 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3851 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3852 qla2xxx_print_sfp_info(vha);
3854 ha->flags.lr_detected = 0;
3856 if (ll & FC_LL_VL || ll & FC_LL_L) {
3857 /* Long range, track length. */
3858 ha->flags.lr_detected = 1;
3860 if (a->length_km > 5 || a->length_100m > 50)
3861 ha->lr_distance = LR_DISTANCE_10K;
3863 ha->lr_distance = LR_DISTANCE_5K;
3867 ql_dbg(ql_dbg_async, vha, 0x507b,
3868 "SFP detect: %s-Range SFP %s (nvr=%x ll=%x lr=%x lrd=%x).\n",
3869 types[ha->flags.lr_detected],
3870 ha->flags.lr_detected ? lengths[ha->lr_distance] :
3871 lengths[LR_DISTANCE_UNKNOWN],
3872 used_nvram, ll, ha->flags.lr_detected, ha->lr_distance);
3873 return ha->flags.lr_detected;
3876 void qla_init_iocb_limit(scsi_qla_host_t *vha)
3880 struct qla_hw_data *ha = vha->hw;
3882 num_qps = ha->num_qpairs + 1;
3883 limit = (ha->orig_fw_iocb_count * QLA_IOCB_PCT_LIMIT) / 100;
3885 ha->base_qpair->fwres.iocbs_total = ha->orig_fw_iocb_count;
3886 ha->base_qpair->fwres.iocbs_limit = limit;
3887 ha->base_qpair->fwres.iocbs_qp_limit = limit / num_qps;
3888 ha->base_qpair->fwres.iocbs_used = 0;
3889 for (i = 0; i < ha->max_qpairs; i++) {
3890 if (ha->queue_pair_map[i]) {
3891 ha->queue_pair_map[i]->fwres.iocbs_total =
3892 ha->orig_fw_iocb_count;
3893 ha->queue_pair_map[i]->fwres.iocbs_limit = limit;
3894 ha->queue_pair_map[i]->fwres.iocbs_qp_limit =
3896 ha->queue_pair_map[i]->fwres.iocbs_used = 0;
3902 * qla2x00_setup_chip() - Load and start RISC firmware.
3905 * Returns 0 on success.
3908 qla2x00_setup_chip(scsi_qla_host_t *vha)
3911 uint32_t srisc_address = 0;
3912 struct qla_hw_data *ha = vha->hw;
3913 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3914 unsigned long flags;
3915 uint16_t fw_major_version;
3918 if (IS_P3P_TYPE(ha)) {
3919 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3920 if (rval == QLA_SUCCESS) {
3921 qla2x00_stop_firmware(vha);
3922 goto enable_82xx_npiv;
3927 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3928 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3929 spin_lock_irqsave(&ha->hardware_lock, flags);
3930 wrt_reg_word(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
3931 rd_reg_word(®->hccr);
3932 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3935 qla81xx_mpi_sync(vha);
3938 /* Load firmware sequences */
3939 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3940 if (rval == QLA_SUCCESS) {
3941 ql_dbg(ql_dbg_init, vha, 0x00c9,
3942 "Verifying Checksum of loaded RISC code.\n");
3944 rval = qla2x00_verify_checksum(vha, srisc_address);
3945 if (rval == QLA_SUCCESS) {
3946 /* Start firmware execution. */
3947 ql_dbg(ql_dbg_init, vha, 0x00ca,
3948 "Starting firmware.\n");
3951 ha->flags.exlogins_enabled = 1;
3953 if (qla_is_exch_offld_enabled(vha))
3954 ha->flags.exchoffld_enabled = 1;
3956 rval = qla2x00_execute_fw(vha, srisc_address);
3957 /* Retrieve firmware information. */
3958 if (rval == QLA_SUCCESS) {
3959 /* Enable BPM support? */
3960 if (!done_once++ && qla24xx_detect_sfp(vha)) {
3961 ql_dbg(ql_dbg_init, vha, 0x00ca,
3962 "Re-starting firmware -- BPM.\n");
3963 /* Best-effort - re-init. */
3964 ha->isp_ops->reset_chip(vha);
3965 ha->isp_ops->chip_diag(vha);
3966 goto execute_fw_with_lr;
3969 if (IS_ZIO_THRESHOLD_CAPABLE(ha))
3970 qla27xx_set_zio_threshold(vha,
3971 ha->last_zio_threshold);
3973 rval = qla2x00_set_exlogins_buffer(vha);
3974 if (rval != QLA_SUCCESS)
3977 rval = qla2x00_set_exchoffld_buffer(vha);
3978 if (rval != QLA_SUCCESS)
3982 fw_major_version = ha->fw_major_version;
3983 if (IS_P3P_TYPE(ha))
3984 qla82xx_check_md_needed(vha);
3986 rval = qla2x00_get_fw_version(vha);
3987 if (rval != QLA_SUCCESS)
3989 ha->flags.npiv_supported = 0;
3990 if (IS_QLA2XXX_MIDTYPE(ha) &&
3991 (ha->fw_attributes & BIT_2)) {
3992 ha->flags.npiv_supported = 1;
3993 if ((!ha->max_npiv_vports) ||
3994 ((ha->max_npiv_vports + 1) %
3995 MIN_MULTI_ID_FABRIC))
3996 ha->max_npiv_vports =
3997 MIN_MULTI_ID_FABRIC - 1;
3999 qla2x00_get_resource_cnts(vha);
4000 qla_init_iocb_limit(vha);
4003 * Allocate the array of outstanding commands
4004 * now that we know the firmware resources.
4006 rval = qla2x00_alloc_outstanding_cmds(ha,
4008 if (rval != QLA_SUCCESS)
4011 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
4012 qla2x00_alloc_offload_mem(vha);
4014 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
4015 qla2x00_alloc_fw_dump(vha);
4021 ql_log(ql_log_fatal, vha, 0x00cd,
4022 "ISP Firmware failed checksum.\n");
4026 /* Enable PUREX PASSTHRU */
4027 if (ql2xrdpenable || ha->flags.scm_supported_f ||
4028 ha->flags.edif_enabled)
4029 qla25xx_set_els_cmds_supported(vha);
4033 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
4034 /* Enable proper parity. */
4035 spin_lock_irqsave(&ha->hardware_lock, flags);
4038 wrt_reg_word(®->hccr, HCCR_ENABLE_PARITY + 0x1);
4040 /* SRAM, Instruction RAM and GP RAM parity */
4041 wrt_reg_word(®->hccr, HCCR_ENABLE_PARITY + 0x7);
4042 rd_reg_word(®->hccr);
4043 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4046 if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
4047 ha->flags.fac_supported = 1;
4048 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
4051 rval = qla81xx_fac_get_sector_size(vha, &size);
4052 if (rval == QLA_SUCCESS) {
4053 ha->flags.fac_supported = 1;
4054 ha->fdt_block_size = size << 2;
4056 ql_log(ql_log_warn, vha, 0x00ce,
4057 "Unsupported FAC firmware (%d.%02d.%02d).\n",
4058 ha->fw_major_version, ha->fw_minor_version,
4059 ha->fw_subminor_version);
4061 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4063 ha->flags.fac_supported = 0;
4070 ql_log(ql_log_fatal, vha, 0x00cf,
4071 "Setup chip ****FAILED****.\n");
4078 * qla2x00_init_response_q_entries() - Initializes response queue entries.
4079 * @rsp: response queue
4081 * Beginning of request ring has initialization control block already built
4082 * by nvram config routine.
4084 * Returns 0 on success.
4087 qla2x00_init_response_q_entries(struct rsp_que *rsp)
4092 rsp->ring_ptr = rsp->ring;
4093 rsp->ring_index = 0;
4094 rsp->status_srb = NULL;
4095 pkt = rsp->ring_ptr;
4096 for (cnt = 0; cnt < rsp->length; cnt++) {
4097 pkt->signature = RESPONSE_PROCESSED;
4103 * qla2x00_update_fw_options() - Read and process firmware options.
4106 * Returns 0 on success.
4109 qla2x00_update_fw_options(scsi_qla_host_t *vha)
4111 uint16_t swing, emphasis, tx_sens, rx_sens;
4112 struct qla_hw_data *ha = vha->hw;
4114 memset(ha->fw_options, 0, sizeof(ha->fw_options));
4115 qla2x00_get_fw_options(vha, ha->fw_options);
4117 if (IS_QLA2100(ha) || IS_QLA2200(ha))
4120 /* Serial Link options. */
4121 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
4122 "Serial link options.\n");
4123 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
4124 ha->fw_seriallink_options, sizeof(ha->fw_seriallink_options));
4126 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
4127 if (ha->fw_seriallink_options[3] & BIT_2) {
4128 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
4131 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
4132 emphasis = (ha->fw_seriallink_options[2] &
4133 (BIT_4 | BIT_3)) >> 3;
4134 tx_sens = ha->fw_seriallink_options[0] &
4135 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4136 rx_sens = (ha->fw_seriallink_options[0] &
4137 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
4138 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
4139 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
4142 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
4143 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
4144 ha->fw_options[10] |= BIT_5 |
4145 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
4146 (tx_sens & (BIT_1 | BIT_0));
4149 swing = (ha->fw_seriallink_options[2] &
4150 (BIT_7 | BIT_6 | BIT_5)) >> 5;
4151 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
4152 tx_sens = ha->fw_seriallink_options[1] &
4153 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4154 rx_sens = (ha->fw_seriallink_options[1] &
4155 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
4156 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
4157 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
4160 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
4161 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
4162 ha->fw_options[11] |= BIT_5 |
4163 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
4164 (tx_sens & (BIT_1 | BIT_0));
4168 /* Return command IOCBs without waiting for an ABTS to complete. */
4169 ha->fw_options[3] |= BIT_13;
4172 if (ha->flags.enable_led_scheme)
4173 ha->fw_options[2] |= BIT_12;
4175 /* Detect ISP6312. */
4177 ha->fw_options[2] |= BIT_13;
4179 /* Set Retry FLOGI in case of P2P connection */
4180 if (ha->operating_mode == P2P) {
4181 ha->fw_options[2] |= BIT_3;
4182 ql_dbg(ql_dbg_disc, vha, 0x2100,
4183 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
4184 __func__, ha->fw_options[2]);
4187 /* Update firmware options. */
4188 qla2x00_set_fw_options(vha, ha->fw_options);
4192 qla24xx_update_fw_options(scsi_qla_host_t *vha)
4195 struct qla_hw_data *ha = vha->hw;
4197 if (IS_P3P_TYPE(ha))
4200 /* Hold status IOCBs until ABTS response received. */
4202 ha->fw_options[3] |= BIT_12;
4204 /* Set Retry FLOGI in case of P2P connection */
4205 if (ha->operating_mode == P2P) {
4206 ha->fw_options[2] |= BIT_3;
4207 ql_dbg(ql_dbg_disc, vha, 0x2101,
4208 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
4209 __func__, ha->fw_options[2]);
4212 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
4213 if (ql2xmvasynctoatio && !ha->flags.edif_enabled &&
4214 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
4215 if (qla_tgt_mode_enabled(vha) ||
4216 qla_dual_mode_enabled(vha))
4217 ha->fw_options[2] |= BIT_11;
4219 ha->fw_options[2] &= ~BIT_11;
4222 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4225 * Tell FW to track each exchange to prevent
4226 * driver from using stale exchange.
4228 if (qla_tgt_mode_enabled(vha) ||
4229 qla_dual_mode_enabled(vha))
4230 ha->fw_options[2] |= BIT_4;
4232 ha->fw_options[2] &= ~(BIT_4);
4234 /* Reserve 1/2 of emergency exchanges for ELS.*/
4235 if (qla2xuseresexchforels)
4236 ha->fw_options[2] |= BIT_8;
4238 ha->fw_options[2] &= ~BIT_8;
4241 * N2N: set Secure=1 for PLOGI ACC and
4242 * fw shal not send PRLI after PLOGI Acc
4244 if (ha->flags.edif_enabled &&
4245 DBELL_ACTIVE(vha)) {
4246 ha->fw_options[3] |= BIT_15;
4247 ha->flags.n2n_fw_acc_sec = 1;
4249 ha->fw_options[3] &= ~BIT_15;
4250 ha->flags.n2n_fw_acc_sec = 0;
4254 if (ql2xrdpenable || ha->flags.scm_supported_f ||
4255 ha->flags.edif_enabled)
4256 ha->fw_options[1] |= ADD_FO1_ENABLE_PUREX_IOCB;
4258 /* Enable Async 8130/8131 events -- transceiver insertion/removal */
4259 if (IS_BPM_RANGE_CAPABLE(ha))
4260 ha->fw_options[3] |= BIT_10;
4262 ql_dbg(ql_dbg_init, vha, 0x00e8,
4263 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
4264 __func__, ha->fw_options[1], ha->fw_options[2],
4265 ha->fw_options[3], vha->host->active_mode);
4267 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
4268 qla2x00_set_fw_options(vha, ha->fw_options);
4270 /* Update Serial Link options. */
4271 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
4274 rval = qla2x00_set_serdes_params(vha,
4275 le16_to_cpu(ha->fw_seriallink_options24[1]),
4276 le16_to_cpu(ha->fw_seriallink_options24[2]),
4277 le16_to_cpu(ha->fw_seriallink_options24[3]));
4278 if (rval != QLA_SUCCESS) {
4279 ql_log(ql_log_warn, vha, 0x0104,
4280 "Unable to update Serial Link options (%x).\n", rval);
4285 qla2x00_config_rings(struct scsi_qla_host *vha)
4287 struct qla_hw_data *ha = vha->hw;
4288 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4289 struct req_que *req = ha->req_q_map[0];
4290 struct rsp_que *rsp = ha->rsp_q_map[0];
4292 /* Setup ring parameters in initialization control block. */
4293 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
4294 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
4295 ha->init_cb->request_q_length = cpu_to_le16(req->length);
4296 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
4297 put_unaligned_le64(req->dma, &ha->init_cb->request_q_address);
4298 put_unaligned_le64(rsp->dma, &ha->init_cb->response_q_address);
4300 wrt_reg_word(ISP_REQ_Q_IN(ha, reg), 0);
4301 wrt_reg_word(ISP_REQ_Q_OUT(ha, reg), 0);
4302 wrt_reg_word(ISP_RSP_Q_IN(ha, reg), 0);
4303 wrt_reg_word(ISP_RSP_Q_OUT(ha, reg), 0);
4304 rd_reg_word(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
4308 qla24xx_config_rings(struct scsi_qla_host *vha)
4310 struct qla_hw_data *ha = vha->hw;
4311 device_reg_t *reg = ISP_QUE_REG(ha, 0);
4312 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
4313 struct qla_msix_entry *msix;
4314 struct init_cb_24xx *icb;
4316 struct req_que *req = ha->req_q_map[0];
4317 struct rsp_que *rsp = ha->rsp_q_map[0];
4319 /* Setup ring parameters in initialization control block. */
4320 icb = (struct init_cb_24xx *)ha->init_cb;
4321 icb->request_q_outpointer = cpu_to_le16(0);
4322 icb->response_q_inpointer = cpu_to_le16(0);
4323 icb->request_q_length = cpu_to_le16(req->length);
4324 icb->response_q_length = cpu_to_le16(rsp->length);
4325 put_unaligned_le64(req->dma, &icb->request_q_address);
4326 put_unaligned_le64(rsp->dma, &icb->response_q_address);
4328 /* Setup ATIO queue dma pointers for target mode */
4329 icb->atio_q_inpointer = cpu_to_le16(0);
4330 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
4331 put_unaligned_le64(ha->tgt.atio_dma, &icb->atio_q_address);
4333 if (IS_SHADOW_REG_CAPABLE(ha))
4334 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
4336 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4338 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
4339 icb->rid = cpu_to_le16(rid);
4340 if (ha->flags.msix_enabled) {
4341 msix = &ha->msix_entries[1];
4342 ql_dbg(ql_dbg_init, vha, 0x0019,
4343 "Registering vector 0x%x for base que.\n",
4345 icb->msix = cpu_to_le16(msix->entry);
4347 /* Use alternate PCI bus number */
4349 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
4350 /* Use alternate PCI devfn */
4352 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
4354 /* Use Disable MSIX Handshake mode for capable adapters */
4355 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
4356 (ha->flags.msix_enabled)) {
4357 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
4358 ha->flags.disable_msix_handshake = 1;
4359 ql_dbg(ql_dbg_init, vha, 0x00fe,
4360 "MSIX Handshake Disable Mode turned on.\n");
4362 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
4364 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
4366 wrt_reg_dword(®->isp25mq.req_q_in, 0);
4367 wrt_reg_dword(®->isp25mq.req_q_out, 0);
4368 wrt_reg_dword(®->isp25mq.rsp_q_in, 0);
4369 wrt_reg_dword(®->isp25mq.rsp_q_out, 0);
4371 wrt_reg_dword(®->isp24.req_q_in, 0);
4372 wrt_reg_dword(®->isp24.req_q_out, 0);
4373 wrt_reg_dword(®->isp24.rsp_q_in, 0);
4374 wrt_reg_dword(®->isp24.rsp_q_out, 0);
4377 qlt_24xx_config_rings(vha);
4379 /* If the user has configured the speed, set it here */
4380 if (ha->set_data_rate) {
4381 ql_dbg(ql_dbg_init, vha, 0x00fd,
4382 "Speed set by user : %s Gbps \n",
4383 qla2x00_get_link_speed_str(ha, ha->set_data_rate));
4384 icb->firmware_options_3 = cpu_to_le32(ha->set_data_rate << 13);
4388 rd_reg_word(&ioreg->hccr);
4392 * qla2x00_init_rings() - Initializes firmware.
4395 * Beginning of request ring has initialization control block already built
4396 * by nvram config routine.
4398 * Returns 0 on success.
4401 qla2x00_init_rings(scsi_qla_host_t *vha)
4404 unsigned long flags = 0;
4406 struct qla_hw_data *ha = vha->hw;
4407 struct req_que *req;
4408 struct rsp_que *rsp;
4409 struct mid_init_cb_24xx *mid_init_cb =
4410 (struct mid_init_cb_24xx *) ha->init_cb;
4412 spin_lock_irqsave(&ha->hardware_lock, flags);
4414 /* Clear outstanding commands array. */
4415 for (que = 0; que < ha->max_req_queues; que++) {
4416 req = ha->req_q_map[que];
4417 if (!req || !test_bit(que, ha->req_qid_map))
4419 req->out_ptr = (uint16_t *)(req->ring + req->length);
4421 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
4422 req->outstanding_cmds[cnt] = NULL;
4424 req->current_outstanding_cmd = 1;
4426 /* Initialize firmware. */
4427 req->ring_ptr = req->ring;
4428 req->ring_index = 0;
4429 req->cnt = req->length;
4432 for (que = 0; que < ha->max_rsp_queues; que++) {
4433 rsp = ha->rsp_q_map[que];
4434 if (!rsp || !test_bit(que, ha->rsp_qid_map))
4436 rsp->in_ptr = (uint16_t *)(rsp->ring + rsp->length);
4438 /* Initialize response queue entries */
4440 qlafx00_init_response_q_entries(rsp);
4442 qla2x00_init_response_q_entries(rsp);
4445 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
4446 ha->tgt.atio_ring_index = 0;
4447 /* Initialize ATIO queue entries */
4448 qlt_init_atio_q_entries(vha);
4450 ha->isp_ops->config_rings(vha);
4452 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4454 if (IS_QLAFX00(ha)) {
4455 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
4459 /* Update any ISP specific firmware options before initialization. */
4460 ha->isp_ops->update_fw_options(vha);
4462 ql_dbg(ql_dbg_init, vha, 0x00d1,
4463 "Issue init firmware FW opt 1-3= %08x %08x %08x.\n",
4464 le32_to_cpu(mid_init_cb->init_cb.firmware_options_1),
4465 le32_to_cpu(mid_init_cb->init_cb.firmware_options_2),
4466 le32_to_cpu(mid_init_cb->init_cb.firmware_options_3));
4468 if (ha->flags.npiv_supported) {
4469 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
4470 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
4471 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
4474 if (IS_FWI2_CAPABLE(ha)) {
4475 mid_init_cb->options = cpu_to_le16(BIT_1);
4476 mid_init_cb->init_cb.execution_throttle =
4477 cpu_to_le16(ha->cur_fw_xcb_count);
4478 ha->flags.dport_enabled =
4479 (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) &
4481 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
4482 (ha->flags.dport_enabled) ? "enabled" : "disabled");
4483 /* FA-WWPN Status */
4484 ha->flags.fawwpn_enabled =
4485 (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) &
4487 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
4488 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
4491 /* ELS pass through payload is limit by frame size. */
4492 if (ha->flags.edif_enabled)
4493 mid_init_cb->init_cb.frame_payload_size = cpu_to_le16(ELS_MAX_PAYLOAD);
4495 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
4498 ql_log(ql_log_fatal, vha, 0x00d2,
4499 "Init Firmware **** FAILED ****.\n");
4501 ql_dbg(ql_dbg_init, vha, 0x00d3,
4502 "Init Firmware -- success.\n");
4504 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0;
4511 * qla2x00_fw_ready() - Waits for firmware ready.
4514 * Returns 0 on success.
4517 qla2x00_fw_ready(scsi_qla_host_t *vha)
4520 unsigned long wtime, mtime, cs84xx_time;
4521 uint16_t min_wait; /* Minimum wait time if loop is down */
4522 uint16_t wait_time; /* Wait time if loop is coming ready */
4524 struct qla_hw_data *ha = vha->hw;
4526 if (IS_QLAFX00(vha->hw))
4527 return qlafx00_fw_ready(vha);
4529 /* Time to wait for loop down */
4530 if (IS_P3P_TYPE(ha))
4536 * Firmware should take at most one RATOV to login, plus 5 seconds for
4537 * our own processing.
4539 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
4540 wait_time = min_wait;
4543 /* Min wait time if loop down */
4544 mtime = jiffies + (min_wait * HZ);
4546 /* wait time before firmware ready */
4547 wtime = jiffies + (wait_time * HZ);
4549 /* Wait for ISP to finish LIP */
4550 if (!vha->flags.init_done)
4551 ql_log(ql_log_info, vha, 0x801e,
4552 "Waiting for LIP to complete.\n");
4555 memset(state, -1, sizeof(state));
4556 rval = qla2x00_get_firmware_state(vha, state);
4557 if (rval == QLA_SUCCESS) {
4558 if (state[0] < FSTATE_LOSS_OF_SYNC) {
4559 vha->device_flags &= ~DFLG_NO_CABLE;
4561 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
4562 ql_dbg(ql_dbg_taskm, vha, 0x801f,
4563 "fw_state=%x 84xx=%x.\n", state[0],
4565 if ((state[2] & FSTATE_LOGGED_IN) &&
4566 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
4567 ql_dbg(ql_dbg_taskm, vha, 0x8028,
4568 "Sending verify iocb.\n");
4570 cs84xx_time = jiffies;
4571 rval = qla84xx_init_chip(vha);
4572 if (rval != QLA_SUCCESS) {
4575 "Init chip failed.\n");
4579 /* Add time taken to initialize. */
4580 cs84xx_time = jiffies - cs84xx_time;
4581 wtime += cs84xx_time;
4582 mtime += cs84xx_time;
4583 ql_dbg(ql_dbg_taskm, vha, 0x8008,
4584 "Increasing wait time by %ld. "
4585 "New time %ld.\n", cs84xx_time,
4588 } else if (state[0] == FSTATE_READY) {
4589 ql_dbg(ql_dbg_taskm, vha, 0x8037,
4590 "F/W Ready - OK.\n");
4592 qla2x00_get_retry_cnt(vha, &ha->retry_count,
4593 &ha->login_timeout, &ha->r_a_tov);
4599 rval = QLA_FUNCTION_FAILED;
4601 if (atomic_read(&vha->loop_down_timer) &&
4602 state[0] != FSTATE_READY) {
4603 /* Loop down. Timeout on min_wait for states
4604 * other than Wait for Login.
4606 if (time_after_eq(jiffies, mtime)) {
4607 ql_log(ql_log_info, vha, 0x8038,
4608 "Cable is unplugged...\n");
4610 vha->device_flags |= DFLG_NO_CABLE;
4615 /* Mailbox cmd failed. Timeout on min_wait. */
4616 if (time_after_eq(jiffies, mtime) ||
4617 ha->flags.isp82xx_fw_hung)
4621 if (time_after_eq(jiffies, wtime))
4624 /* Delay for a while */
4628 ql_dbg(ql_dbg_taskm, vha, 0x803a,
4629 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
4630 state[1], state[2], state[3], state[4], state[5], jiffies);
4632 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
4633 ql_log(ql_log_warn, vha, 0x803b,
4634 "Firmware ready **** FAILED ****.\n");
4641 * qla2x00_configure_hba
4642 * Setup adapter context.
4645 * ha = adapter state pointer.
4654 qla2x00_configure_hba(scsi_qla_host_t *vha)
4663 char connect_type[22];
4664 struct qla_hw_data *ha = vha->hw;
4665 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4667 unsigned long flags;
4669 /* Get host addresses. */
4670 rval = qla2x00_get_adapter_id(vha,
4671 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
4672 if (rval != QLA_SUCCESS) {
4673 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
4674 IS_CNA_CAPABLE(ha) ||
4675 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
4676 ql_dbg(ql_dbg_disc, vha, 0x2008,
4677 "Loop is in a transition state.\n");
4679 ql_log(ql_log_warn, vha, 0x2009,
4680 "Unable to get host loop ID.\n");
4681 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
4682 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
4683 ql_log(ql_log_warn, vha, 0x1151,
4684 "Doing link init.\n");
4685 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
4688 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4694 ql_log(ql_log_info, vha, 0x200a,
4695 "Cannot get topology - retrying.\n");
4696 return (QLA_FUNCTION_FAILED);
4699 vha->loop_id = loop_id;
4702 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
4703 ha->operating_mode = LOOP;
4707 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
4709 ha->current_topology = ISP_CFG_NL;
4710 strcpy(connect_type, "(Loop)");
4714 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
4715 ha->switch_cap = sw_cap;
4716 ha->current_topology = ISP_CFG_FL;
4717 strcpy(connect_type, "(FL_Port)");
4721 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
4723 ha->operating_mode = P2P;
4724 ha->current_topology = ISP_CFG_N;
4725 strcpy(connect_type, "(N_Port-to-N_Port)");
4729 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
4730 ha->switch_cap = sw_cap;
4731 ha->operating_mode = P2P;
4732 ha->current_topology = ISP_CFG_F;
4733 strcpy(connect_type, "(F_Port)");
4737 ql_dbg(ql_dbg_disc, vha, 0x200f,
4738 "HBA in unknown topology %x, using NL.\n", topo);
4740 ha->current_topology = ISP_CFG_NL;
4741 strcpy(connect_type, "(Loop)");
4745 /* Save Host port and loop ID. */
4746 /* byte order - Big Endian */
4747 id.b.domain = domain;
4751 spin_lock_irqsave(&ha->hardware_lock, flags);
4752 if (vha->hw->flags.edif_enabled) {
4754 qlt_update_host_map(vha, id);
4755 } else if (!(topo == 2 && ha->flags.n2n_bigger))
4756 qlt_update_host_map(vha, id);
4757 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4759 if (!vha->flags.init_done)
4760 ql_log(ql_log_info, vha, 0x2010,
4761 "Topology - %s, Host Loop address 0x%x.\n",
4762 connect_type, vha->loop_id);
4768 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
4773 uint64_t zero[2] = { 0 };
4774 struct qla_hw_data *ha = vha->hw;
4775 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
4776 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
4778 if (len > sizeof(zero))
4780 if (memcmp(model, &zero, len) != 0) {
4781 memcpy(ha->model_number, model, len);
4782 st = en = ha->model_number;
4785 if (*en != 0x20 && *en != 0x00)
4790 index = (ha->pdev->subsystem_device & 0xff);
4792 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4793 index < QLA_MODEL_NAMES)
4794 strlcpy(ha->model_desc,
4795 qla2x00_model_name[index * 2 + 1],
4796 sizeof(ha->model_desc));
4798 index = (ha->pdev->subsystem_device & 0xff);
4800 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4801 index < QLA_MODEL_NAMES) {
4802 strlcpy(ha->model_number,
4803 qla2x00_model_name[index * 2],
4804 sizeof(ha->model_number));
4805 strlcpy(ha->model_desc,
4806 qla2x00_model_name[index * 2 + 1],
4807 sizeof(ha->model_desc));
4809 strlcpy(ha->model_number, def,
4810 sizeof(ha->model_number));
4813 if (IS_FWI2_CAPABLE(ha))
4814 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
4815 sizeof(ha->model_desc));
4818 /* On sparc systems, obtain port and node WWN from firmware
4821 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4824 struct qla_hw_data *ha = vha->hw;
4825 struct pci_dev *pdev = ha->pdev;
4826 struct device_node *dp = pci_device_to_OF_node(pdev);
4830 val = of_get_property(dp, "port-wwn", &len);
4831 if (val && len >= WWN_SIZE)
4832 memcpy(nv->port_name, val, WWN_SIZE);
4834 val = of_get_property(dp, "node-wwn", &len);
4835 if (val && len >= WWN_SIZE)
4836 memcpy(nv->node_name, val, WWN_SIZE);
4841 * NVRAM configuration for ISP 2xxx
4844 * ha = adapter block pointer.
4847 * initialization control block in response_ring
4848 * host adapters parameters in host adapter block
4854 qla2x00_nvram_config(scsi_qla_host_t *vha)
4859 uint8_t *dptr1, *dptr2;
4860 struct qla_hw_data *ha = vha->hw;
4861 init_cb_t *icb = ha->init_cb;
4862 nvram_t *nv = ha->nvram;
4863 uint8_t *ptr = ha->nvram;
4864 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4868 /* Determine NVRAM starting address. */
4869 ha->nvram_size = sizeof(*nv);
4871 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4872 if ((rd_reg_word(®->ctrl_status) >> 14) == 1)
4873 ha->nvram_base = 0x80;
4875 /* Get NVRAM data and calculate checksum. */
4876 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
4877 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4880 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4881 "Contents of NVRAM.\n");
4882 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4883 nv, ha->nvram_size);
4885 /* Bad NVRAM data, set defaults parameters. */
4886 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
4887 nv->nvram_version < 1) {
4888 /* Reset NVRAM data. */
4889 ql_log(ql_log_warn, vha, 0x0064,
4890 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
4891 chksum, nv->id, nv->nvram_version);
4892 ql_log(ql_log_warn, vha, 0x0065,
4894 "functioning (yet invalid -- WWPN) defaults.\n");
4897 * Set default initialization control block.
4899 memset(nv, 0, ha->nvram_size);
4900 nv->parameter_block_version = ICB_VERSION;
4902 if (IS_QLA23XX(ha)) {
4903 nv->firmware_options[0] = BIT_2 | BIT_1;
4904 nv->firmware_options[1] = BIT_7 | BIT_5;
4905 nv->add_firmware_options[0] = BIT_5;
4906 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4907 nv->frame_payload_size = cpu_to_le16(2048);
4908 nv->special_options[1] = BIT_7;
4909 } else if (IS_QLA2200(ha)) {
4910 nv->firmware_options[0] = BIT_2 | BIT_1;
4911 nv->firmware_options[1] = BIT_7 | BIT_5;
4912 nv->add_firmware_options[0] = BIT_5;
4913 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4914 nv->frame_payload_size = cpu_to_le16(1024);
4915 } else if (IS_QLA2100(ha)) {
4916 nv->firmware_options[0] = BIT_3 | BIT_1;
4917 nv->firmware_options[1] = BIT_5;
4918 nv->frame_payload_size = cpu_to_le16(1024);
4921 nv->max_iocb_allocation = cpu_to_le16(256);
4922 nv->execution_throttle = cpu_to_le16(16);
4923 nv->retry_count = 8;
4924 nv->retry_delay = 1;
4926 nv->port_name[0] = 33;
4927 nv->port_name[3] = 224;
4928 nv->port_name[4] = 139;
4930 qla2xxx_nvram_wwn_from_ofw(vha, nv);
4932 nv->login_timeout = 4;
4935 * Set default host adapter parameters
4937 nv->host_p[1] = BIT_2;
4938 nv->reset_delay = 5;
4939 nv->port_down_retry_count = 8;
4940 nv->max_luns_per_target = cpu_to_le16(8);
4941 nv->link_down_timeout = 60;
4946 /* Reset Initialization control block */
4947 memset(icb, 0, ha->init_cb_size);
4950 * Setup driver NVRAM options.
4952 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4953 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4954 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4955 nv->firmware_options[1] &= ~BIT_4;
4957 if (IS_QLA23XX(ha)) {
4958 nv->firmware_options[0] |= BIT_2;
4959 nv->firmware_options[0] &= ~BIT_3;
4960 nv->special_options[0] &= ~BIT_6;
4961 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
4963 if (IS_QLA2300(ha)) {
4964 if (ha->fb_rev == FPM_2310) {
4965 strcpy(ha->model_number, "QLA2310");
4967 strcpy(ha->model_number, "QLA2300");
4970 qla2x00_set_model_info(vha, nv->model_number,
4971 sizeof(nv->model_number), "QLA23xx");
4973 } else if (IS_QLA2200(ha)) {
4974 nv->firmware_options[0] |= BIT_2;
4976 * 'Point-to-point preferred, else loop' is not a safe
4977 * connection mode setting.
4979 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4981 /* Force 'loop preferred, else point-to-point'. */
4982 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4983 nv->add_firmware_options[0] |= BIT_5;
4985 strcpy(ha->model_number, "QLA22xx");
4986 } else /*if (IS_QLA2100(ha))*/ {
4987 strcpy(ha->model_number, "QLA2100");
4991 * Copy over NVRAM RISC parameter block to initialization control block.
4993 dptr1 = (uint8_t *)icb;
4994 dptr2 = (uint8_t *)&nv->parameter_block_version;
4995 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4997 *dptr1++ = *dptr2++;
4999 /* Copy 2nd half. */
5000 dptr1 = (uint8_t *)icb->add_firmware_options;
5001 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
5003 *dptr1++ = *dptr2++;
5004 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
5005 /* Use alternate WWN? */
5006 if (nv->host_p[1] & BIT_7) {
5007 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5008 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5011 /* Prepare nodename */
5012 if ((icb->firmware_options[1] & BIT_6) == 0) {
5014 * Firmware will apply the following mask if the nodename was
5017 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5018 icb->node_name[0] &= 0xF0;
5022 * Set host adapter parameters.
5026 * BIT_7 in the host-parameters section allows for modification to
5027 * internal driver logging.
5029 if (nv->host_p[0] & BIT_7)
5030 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
5031 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
5032 /* Always load RISC code on non ISP2[12]00 chips. */
5033 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
5034 ha->flags.disable_risc_code_load = 0;
5035 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
5036 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
5037 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
5038 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
5039 ha->flags.disable_serdes = 0;
5041 ha->operating_mode =
5042 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
5044 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
5045 sizeof(ha->fw_seriallink_options));
5047 /* save HBA serial number */
5048 ha->serial0 = icb->port_name[5];
5049 ha->serial1 = icb->port_name[6];
5050 ha->serial2 = icb->port_name[7];
5051 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5052 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5054 icb->execution_throttle = cpu_to_le16(0xFFFF);
5056 ha->retry_count = nv->retry_count;
5058 /* Set minimum login_timeout to 4 seconds. */
5059 if (nv->login_timeout != ql2xlogintimeout)
5060 nv->login_timeout = ql2xlogintimeout;
5061 if (nv->login_timeout < 4)
5062 nv->login_timeout = 4;
5063 ha->login_timeout = nv->login_timeout;
5065 /* Set minimum RATOV to 100 tenths of a second. */
5068 ha->loop_reset_delay = nv->reset_delay;
5070 /* Link Down Timeout = 0:
5072 * When Port Down timer expires we will start returning
5073 * I/O's to OS with "DID_NO_CONNECT".
5075 * Link Down Timeout != 0:
5077 * The driver waits for the link to come up after link down
5078 * before returning I/Os to OS with "DID_NO_CONNECT".
5080 if (nv->link_down_timeout == 0) {
5081 ha->loop_down_abort_time =
5082 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5084 ha->link_down_timeout = nv->link_down_timeout;
5085 ha->loop_down_abort_time =
5086 (LOOP_DOWN_TIME - ha->link_down_timeout);
5090 * Need enough time to try and get the port back.
5092 ha->port_down_retry_count = nv->port_down_retry_count;
5093 if (qlport_down_retry)
5094 ha->port_down_retry_count = qlport_down_retry;
5095 /* Set login_retry_count */
5096 ha->login_retry_count = nv->retry_count;
5097 if (ha->port_down_retry_count == nv->port_down_retry_count &&
5098 ha->port_down_retry_count > 3)
5099 ha->login_retry_count = ha->port_down_retry_count;
5100 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5101 ha->login_retry_count = ha->port_down_retry_count;
5102 if (ql2xloginretrycount)
5103 ha->login_retry_count = ql2xloginretrycount;
5105 icb->lun_enables = cpu_to_le16(0);
5106 icb->command_resource_count = 0;
5107 icb->immediate_notify_resource_count = 0;
5108 icb->timeout = cpu_to_le16(0);
5110 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
5112 icb->firmware_options[0] &= ~BIT_3;
5113 icb->add_firmware_options[0] &=
5114 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
5115 icb->add_firmware_options[0] |= BIT_2;
5116 icb->response_accumulation_timer = 3;
5117 icb->interrupt_delay_timer = 5;
5119 vha->flags.process_response_queue = 1;
5122 if (!vha->flags.init_done) {
5123 ha->zio_mode = icb->add_firmware_options[0] &
5124 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5125 ha->zio_timer = icb->interrupt_delay_timer ?
5126 icb->interrupt_delay_timer : 2;
5128 icb->add_firmware_options[0] &=
5129 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
5130 vha->flags.process_response_queue = 0;
5131 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5132 ha->zio_mode = QLA_ZIO_MODE_6;
5134 ql_log(ql_log_info, vha, 0x0068,
5135 "ZIO mode %d enabled; timer delay (%d us).\n",
5136 ha->zio_mode, ha->zio_timer * 100);
5138 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
5139 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
5140 vha->flags.process_response_queue = 1;
5145 ql_log(ql_log_warn, vha, 0x0069,
5146 "NVRAM configuration failed.\n");
5152 qla2x00_rport_del(void *data)
5154 fc_port_t *fcport = data;
5155 struct fc_rport *rport;
5156 unsigned long flags;
5158 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5159 rport = fcport->drport ? fcport->drport : fcport->rport;
5160 fcport->drport = NULL;
5161 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5163 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
5164 "%s %8phN. rport %p roles %x\n",
5165 __func__, fcport->port_name, rport,
5168 fc_remote_port_delete(rport);
5172 void qla2x00_set_fcport_state(fc_port_t *fcport, int state)
5176 old_state = atomic_read(&fcport->state);
5177 atomic_set(&fcport->state, state);
5179 /* Don't print state transitions during initial allocation of fcport */
5180 if (old_state && old_state != state) {
5181 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
5182 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
5183 fcport->port_name, port_state_str[old_state],
5184 port_state_str[state], fcport->d_id.b.domain,
5185 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5190 * qla2x00_alloc_fcport() - Allocate a generic fcport.
5192 * @flags: allocation flags
5194 * Returns a pointer to the allocated fcport, or NULL, if none available.
5197 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
5201 fcport = kzalloc(sizeof(fc_port_t), flags);
5205 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
5206 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
5208 if (!fcport->ct_desc.ct_sns) {
5209 ql_log(ql_log_warn, vha, 0xd049,
5210 "Failed to allocate ct_sns request.\n");
5215 /* Setup fcport template structure. */
5217 fcport->port_type = FCT_UNKNOWN;
5218 fcport->loop_id = FC_NO_LOOP_ID;
5219 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
5220 fcport->supported_classes = FC_COS_UNSPECIFIED;
5221 fcport->fp_speed = PORT_SPEED_UNKNOWN;
5223 fcport->disc_state = DSC_DELETED;
5224 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
5225 fcport->deleted = QLA_SESS_DELETED;
5226 fcport->login_retry = vha->hw->login_retry_count;
5227 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
5228 fcport->logout_on_delete = 1;
5229 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
5230 fcport->tgt_short_link_down_cnt = 0;
5231 fcport->dev_loss_tmo = 0;
5233 if (!fcport->ct_desc.ct_sns) {
5234 ql_log(ql_log_warn, vha, 0xd049,
5235 "Failed to allocate ct_sns request.\n");
5240 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
5241 INIT_WORK(&fcport->free_work, qlt_free_session_done);
5242 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
5243 INIT_LIST_HEAD(&fcport->gnl_entry);
5244 INIT_LIST_HEAD(&fcport->list);
5246 INIT_LIST_HEAD(&fcport->sess_cmd_list);
5247 spin_lock_init(&fcport->sess_cmd_lock);
5249 spin_lock_init(&fcport->edif.sa_list_lock);
5250 INIT_LIST_HEAD(&fcport->edif.tx_sa_list);
5251 INIT_LIST_HEAD(&fcport->edif.rx_sa_list);
5253 if (vha->e_dbell.db_flags == EDB_ACTIVE)
5254 fcport->edif.app_started = 1;
5256 spin_lock_init(&fcport->edif.indx_list_lock);
5257 INIT_LIST_HEAD(&fcport->edif.edif_indx_list);
5263 qla2x00_free_fcport(fc_port_t *fcport)
5265 if (fcport->ct_desc.ct_sns) {
5266 dma_free_coherent(&fcport->vha->hw->pdev->dev,
5267 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
5268 fcport->ct_desc.ct_sns_dma);
5270 fcport->ct_desc.ct_sns = NULL;
5273 qla_edif_flush_sa_ctl_lists(fcport);
5274 list_del(&fcport->list);
5275 qla2x00_clear_loop_id(fcport);
5277 qla_edif_list_del(fcport);
5282 static void qla_get_login_template(scsi_qla_host_t *vha)
5284 struct qla_hw_data *ha = vha->hw;
5289 memset(ha->init_cb, 0, ha->init_cb_size);
5290 sz = min_t(int, sizeof(struct fc_els_flogi), ha->init_cb_size);
5291 rval = qla24xx_get_port_login_templ(vha, ha->init_cb_dma,
5293 if (rval != QLA_SUCCESS) {
5294 ql_dbg(ql_dbg_init, vha, 0x00d1,
5295 "PLOGI ELS param read fail.\n");
5298 q = (__be32 *)&ha->plogi_els_payld.fl_csp;
5300 bp = (uint32_t *)ha->init_cb;
5301 cpu_to_be32_array(q, bp, sz / 4);
5302 ha->flags.plogi_template_valid = 1;
5306 * qla2x00_configure_loop
5307 * Updates Fibre Channel Device Database with what is actually on loop.
5310 * ha = adapter block pointer.
5315 * 2 = database was full and device was not configured.
5318 qla2x00_configure_loop(scsi_qla_host_t *vha)
5321 unsigned long flags, save_flags;
5322 struct qla_hw_data *ha = vha->hw;
5326 /* Get Initiator ID */
5327 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
5328 rval = qla2x00_configure_hba(vha);
5329 if (rval != QLA_SUCCESS) {
5330 ql_dbg(ql_dbg_disc, vha, 0x2013,
5331 "Unable to configure HBA.\n");
5336 save_flags = flags = vha->dpc_flags;
5337 ql_dbg(ql_dbg_disc, vha, 0x2014,
5338 "Configure loop -- dpc flags = 0x%lx.\n", flags);
5341 * If we have both an RSCN and PORT UPDATE pending then handle them
5342 * both at the same time.
5344 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5345 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
5347 qla2x00_get_data_rate(vha);
5348 qla_get_login_template(vha);
5350 /* Determine what we need to do */
5351 if ((ha->current_topology == ISP_CFG_FL ||
5352 ha->current_topology == ISP_CFG_F) &&
5353 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
5355 set_bit(RSCN_UPDATE, &flags);
5356 clear_bit(LOCAL_LOOP_UPDATE, &flags);
5358 } else if (ha->current_topology == ISP_CFG_NL ||
5359 ha->current_topology == ISP_CFG_N) {
5360 clear_bit(RSCN_UPDATE, &flags);
5361 set_bit(LOCAL_LOOP_UPDATE, &flags);
5362 } else if (!vha->flags.online ||
5363 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
5364 set_bit(RSCN_UPDATE, &flags);
5365 set_bit(LOCAL_LOOP_UPDATE, &flags);
5368 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
5369 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5370 ql_dbg(ql_dbg_disc, vha, 0x2015,
5371 "Loop resync needed, failing.\n");
5372 rval = QLA_FUNCTION_FAILED;
5374 rval = qla2x00_configure_local_loop(vha);
5377 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
5378 if (LOOP_TRANSITION(vha)) {
5379 ql_dbg(ql_dbg_disc, vha, 0x2099,
5380 "Needs RSCN update and loop transition.\n");
5381 rval = QLA_FUNCTION_FAILED;
5384 rval = qla2x00_configure_fabric(vha);
5387 if (rval == QLA_SUCCESS) {
5388 if (atomic_read(&vha->loop_down_timer) ||
5389 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5390 rval = QLA_FUNCTION_FAILED;
5392 atomic_set(&vha->loop_state, LOOP_READY);
5393 ql_dbg(ql_dbg_disc, vha, 0x2069,
5395 ha->flags.fw_init_done = 1;
5398 * use link up to wake up app to get ready for
5401 if (ha->flags.edif_enabled && DBELL_INACTIVE(vha))
5402 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP,
5403 ha->link_data_rate);
5406 * Process any ATIO queue entries that came in
5407 * while we weren't online.
5409 if (qla_tgt_mode_enabled(vha) ||
5410 qla_dual_mode_enabled(vha)) {
5411 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
5412 qlt_24xx_process_atio_queue(vha, 0);
5413 spin_unlock_irqrestore(&ha->tgt.atio_lock,
5420 ql_dbg(ql_dbg_disc, vha, 0x206a,
5421 "%s *** FAILED ***.\n", __func__);
5423 ql_dbg(ql_dbg_disc, vha, 0x206b,
5424 "%s: exiting normally. local port wwpn %8phN id %06x)\n",
5425 __func__, vha->port_name, vha->d_id.b24);
5428 /* Restore state if a resync event occurred during processing */
5429 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5430 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
5431 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5432 if (test_bit(RSCN_UPDATE, &save_flags)) {
5433 set_bit(RSCN_UPDATE, &vha->dpc_flags);
5440 static int qla2x00_configure_n2n_loop(scsi_qla_host_t *vha)
5442 unsigned long flags;
5445 ql_dbg(ql_dbg_disc, vha, 0x206a, "%s %d.\n", __func__, __LINE__);
5447 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags))
5448 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5450 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5451 if (fcport->n2n_flag) {
5452 qla24xx_fcport_handle_login(vha, fcport);
5457 spin_lock_irqsave(&vha->work_lock, flags);
5458 vha->scan.scan_retry++;
5459 spin_unlock_irqrestore(&vha->work_lock, flags);
5461 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5462 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5463 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5465 return QLA_FUNCTION_FAILED;
5469 * qla2x00_configure_local_loop
5470 * Updates Fibre Channel Device Database with local loop devices.
5473 * ha = adapter block pointer.
5479 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
5484 fc_port_t *fcport, *new_fcport;
5487 struct gid_list_info *gid;
5489 uint8_t domain, area, al_pa;
5490 struct qla_hw_data *ha = vha->hw;
5491 unsigned long flags;
5493 /* Inititae N2N login. */
5495 return qla2x00_configure_n2n_loop(vha);
5499 entries = MAX_FIBRE_DEVICES_LOOP;
5501 /* Get list of logged in devices. */
5502 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
5503 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
5505 if (rval != QLA_SUCCESS)
5508 ql_dbg(ql_dbg_disc, vha, 0x2011,
5509 "Entries in ID list (%d).\n", entries);
5510 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
5511 ha->gid_list, entries * sizeof(*ha->gid_list));
5514 spin_lock_irqsave(&vha->work_lock, flags);
5515 vha->scan.scan_retry++;
5516 spin_unlock_irqrestore(&vha->work_lock, flags);
5518 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5519 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5520 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5523 vha->scan.scan_retry = 0;
5526 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5527 fcport->scan_state = QLA_FCPORT_SCAN;
5530 /* Allocate temporary fcport for any new fcports discovered. */
5531 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5532 if (new_fcport == NULL) {
5533 ql_log(ql_log_warn, vha, 0x2012,
5534 "Memory allocation failed for fcport.\n");
5535 rval = QLA_MEMORY_ALLOC_FAILED;
5538 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5540 /* Add devices to port list. */
5542 for (index = 0; index < entries; index++) {
5543 domain = gid->domain;
5546 if (IS_QLA2100(ha) || IS_QLA2200(ha))
5547 loop_id = gid->loop_id_2100;
5549 loop_id = le16_to_cpu(gid->loop_id);
5550 gid = (void *)gid + ha->gid_list_info_size;
5552 /* Bypass reserved domain fields. */
5553 if ((domain & 0xf0) == 0xf0)
5556 /* Bypass if not same domain and area of adapter. */
5557 if (area && domain && ((area != vha->d_id.b.area) ||
5558 (domain != vha->d_id.b.domain)) &&
5559 (ha->current_topology == ISP_CFG_NL))
5563 /* Bypass invalid local loop ID. */
5564 if (loop_id > LAST_LOCAL_LOOP_ID)
5567 memset(new_fcport->port_name, 0, WWN_SIZE);
5569 /* Fill in member data. */
5570 new_fcport->d_id.b.domain = domain;
5571 new_fcport->d_id.b.area = area;
5572 new_fcport->d_id.b.al_pa = al_pa;
5573 new_fcport->loop_id = loop_id;
5574 new_fcport->scan_state = QLA_FCPORT_FOUND;
5576 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
5577 if (rval2 != QLA_SUCCESS) {
5578 ql_dbg(ql_dbg_disc, vha, 0x2097,
5579 "Failed to retrieve fcport information "
5580 "-- get_port_database=%x, loop_id=0x%04x.\n",
5581 rval2, new_fcport->loop_id);
5582 /* Skip retry if N2N */
5583 if (ha->current_topology != ISP_CFG_N) {
5584 ql_dbg(ql_dbg_disc, vha, 0x2105,
5585 "Scheduling resync.\n");
5586 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5591 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5592 /* Check for matching device in port list. */
5595 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5596 if (memcmp(new_fcport->port_name, fcport->port_name,
5600 fcport->flags &= ~FCF_FABRIC_DEVICE;
5601 fcport->loop_id = new_fcport->loop_id;
5602 fcport->port_type = new_fcport->port_type;
5603 fcport->d_id.b24 = new_fcport->d_id.b24;
5604 memcpy(fcport->node_name, new_fcport->node_name,
5606 fcport->scan_state = QLA_FCPORT_FOUND;
5612 /* New device, add to fcports list. */
5613 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5615 /* Allocate a new replacement fcport. */
5616 fcport = new_fcport;
5618 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5620 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5622 if (new_fcport == NULL) {
5623 ql_log(ql_log_warn, vha, 0xd031,
5624 "Failed to allocate memory for fcport.\n");
5625 rval = QLA_MEMORY_ALLOC_FAILED;
5628 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5629 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5632 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5634 /* Base iIDMA settings on HBA port speed. */
5635 fcport->fp_speed = ha->link_data_rate;
5640 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5641 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5644 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5645 if ((qla_dual_mode_enabled(vha) ||
5646 qla_ini_mode_enabled(vha)) &&
5647 atomic_read(&fcport->state) == FCS_ONLINE) {
5648 qla2x00_mark_device_lost(vha, fcport,
5649 ql2xplogiabsentdevice);
5650 if (fcport->loop_id != FC_NO_LOOP_ID &&
5651 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5652 fcport->port_type != FCT_INITIATOR &&
5653 fcport->port_type != FCT_BROADCAST) {
5654 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5655 "%s %d %8phC post del sess\n",
5659 qlt_schedule_sess_for_deletion(fcport);
5665 if (fcport->scan_state == QLA_FCPORT_FOUND)
5666 qla24xx_fcport_handle_login(vha, fcport);
5669 qla2x00_free_fcport(new_fcport);
5674 ql_dbg(ql_dbg_disc, vha, 0x2098,
5675 "Configure local loop error exit: rval=%x.\n", rval);
5680 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5683 uint16_t mb[MAILBOX_REGISTER_COUNT];
5684 struct qla_hw_data *ha = vha->hw;
5686 if (!IS_IIDMA_CAPABLE(ha))
5689 if (atomic_read(&fcport->state) != FCS_ONLINE)
5692 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
5693 fcport->fp_speed > ha->link_data_rate ||
5694 !ha->flags.gpsc_supported)
5697 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
5699 if (rval != QLA_SUCCESS) {
5700 ql_dbg(ql_dbg_disc, vha, 0x2004,
5701 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5702 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
5704 ql_dbg(ql_dbg_disc, vha, 0x2005,
5705 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5706 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
5707 fcport->fp_speed, fcport->port_name);
5711 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5713 qla2x00_iidma_fcport(vha, fcport);
5714 qla24xx_update_fcport_fcp_prio(vha, fcport);
5717 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5719 struct qla_work_evt *e;
5721 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
5723 return QLA_FUNCTION_FAILED;
5725 e->u.fcport.fcport = fcport;
5726 return qla2x00_post_work(vha, e);
5729 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5731 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
5733 struct fc_rport_identifiers rport_ids;
5734 struct fc_rport *rport;
5735 unsigned long flags;
5737 if (atomic_read(&fcport->state) == FCS_ONLINE)
5740 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5741 rport_ids.port_name = wwn_to_u64(fcport->port_name);
5742 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5743 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5744 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5745 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
5747 ql_log(ql_log_warn, vha, 0x2006,
5748 "Unable to allocate fc remote port.\n");
5752 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5753 *((fc_port_t **)rport->dd_data) = fcport;
5754 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5755 fcport->dev_loss_tmo = rport->dev_loss_tmo;
5757 rport->supported_classes = fcport->supported_classes;
5759 rport_ids.roles = FC_PORT_ROLE_UNKNOWN;
5760 if (fcport->port_type == FCT_INITIATOR)
5761 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
5762 if (fcport->port_type == FCT_TARGET)
5763 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
5764 if (fcport->port_type & FCT_NVME_INITIATOR)
5765 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
5766 if (fcport->port_type & FCT_NVME_TARGET)
5767 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
5768 if (fcport->port_type & FCT_NVME_DISCOVERY)
5769 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
5771 fc_remote_port_rolechg(rport, rport_ids.roles);
5773 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5774 "%s: %8phN. rport %ld:0:%d (%p) is %s mode\n",
5775 __func__, fcport->port_name, vha->host_no,
5776 rport->scsi_target_id, rport,
5777 (fcport->port_type == FCT_TARGET) ? "tgt" :
5778 ((fcport->port_type & FCT_NVME) ? "nvme" : "ini"));
5782 * qla2x00_update_fcport
5783 * Updates device on list.
5786 * ha = adapter block pointer.
5787 * fcport = port structure pointer.
5797 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5799 if (IS_SW_RESV_ADDR(fcport->d_id))
5802 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
5803 __func__, fcport->port_name);
5805 qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT);
5806 fcport->login_retry = vha->hw->login_retry_count;
5807 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5808 fcport->deleted = 0;
5809 if (vha->hw->current_topology == ISP_CFG_NL)
5810 fcport->logout_on_delete = 0;
5812 fcport->logout_on_delete = 1;
5813 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
5815 if (fcport->tgt_link_down_time < fcport->dev_loss_tmo) {
5816 fcport->tgt_short_link_down_cnt++;
5817 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
5820 switch (vha->hw->current_topology) {
5823 fcport->keep_nport_handle = 1;
5829 qla2x00_iidma_fcport(vha, fcport);
5831 qla2x00_dfs_create_rport(vha, fcport);
5833 qla24xx_update_fcport_fcp_prio(vha, fcport);
5835 switch (vha->host->active_mode) {
5836 case MODE_INITIATOR:
5837 qla2x00_reg_remote_port(vha, fcport);
5840 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5841 !vha->vha_tgt.qla_tgt->tgt_stopped)
5842 qlt_fc_port_added(vha, fcport);
5845 qla2x00_reg_remote_port(vha, fcport);
5846 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5847 !vha->vha_tgt.qla_tgt->tgt_stopped)
5848 qlt_fc_port_added(vha, fcport);
5854 if (NVME_TARGET(vha->hw, fcport))
5855 qla_nvme_register_remote(vha, fcport);
5857 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5859 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
5860 if (fcport->id_changed) {
5861 fcport->id_changed = 0;
5862 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5863 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5864 __func__, __LINE__, fcport->port_name,
5866 qla24xx_post_gfpnid_work(vha, fcport);
5868 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5869 "%s %d %8phC post gpsc fcp_cnt %d\n",
5870 __func__, __LINE__, fcport->port_name,
5872 qla24xx_post_gpsc_work(vha, fcport);
5876 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
5879 void qla_register_fcport_fn(struct work_struct *work)
5881 fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
5882 u32 rscn_gen = fcport->rscn_gen;
5885 if (IS_SW_RESV_ADDR(fcport->d_id))
5888 qla2x00_update_fcport(fcport->vha, fcport);
5890 ql_dbg(ql_dbg_disc, fcport->vha, 0x911e,
5891 "%s rscn gen %d/%d next DS %d\n", __func__,
5892 rscn_gen, fcport->rscn_gen, fcport->next_disc_state);
5894 if (rscn_gen != fcport->rscn_gen) {
5895 /* RSCN(s) came in while registration */
5896 switch (fcport->next_disc_state) {
5897 case DSC_DELETE_PEND:
5898 qlt_schedule_sess_for_deletion(fcport);
5901 data[0] = data[1] = 0;
5902 qla2x00_post_async_adisc_work(fcport->vha, fcport,
5912 * qla2x00_configure_fabric
5913 * Setup SNS devices with loop ID's.
5916 * ha = adapter block pointer.
5923 qla2x00_configure_fabric(scsi_qla_host_t *vha)
5927 uint16_t mb[MAILBOX_REGISTER_COUNT];
5929 LIST_HEAD(new_fcports);
5930 struct qla_hw_data *ha = vha->hw;
5933 /* If FL port exists, then SNS is present */
5934 if (IS_FWI2_CAPABLE(ha))
5935 loop_id = NPH_F_PORT;
5937 loop_id = SNS_FL_PORT;
5938 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
5939 if (rval != QLA_SUCCESS) {
5940 ql_dbg(ql_dbg_disc, vha, 0x20a0,
5941 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5943 vha->device_flags &= ~SWITCH_FOUND;
5944 return (QLA_SUCCESS);
5946 vha->device_flags |= SWITCH_FOUND;
5948 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_port_name, 0);
5949 if (rval != QLA_SUCCESS)
5950 ql_dbg(ql_dbg_disc, vha, 0x20ff,
5951 "Failed to get Fabric Port Name\n");
5953 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
5954 rval = qla2x00_send_change_request(vha, 0x3, 0);
5955 if (rval != QLA_SUCCESS)
5956 ql_log(ql_log_warn, vha, 0x121,
5957 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5962 qla2x00_mgmt_svr_login(vha);
5964 /* Ensure we are logged into the SNS. */
5965 loop_id = NPH_SNS_LID(ha);
5966 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5967 0xfc, mb, BIT_1|BIT_0);
5968 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5969 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5970 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5971 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
5972 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5977 if (ql2xfdmienable &&
5978 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5979 qla2x00_fdmi_register(vha);
5981 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5982 if (qla2x00_rft_id(vha)) {
5984 ql_dbg(ql_dbg_disc, vha, 0x20a2,
5985 "Register FC-4 TYPE failed.\n");
5986 if (test_bit(LOOP_RESYNC_NEEDED,
5990 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
5992 ql_dbg(ql_dbg_disc, vha, 0x209a,
5993 "Register FC-4 Features failed.\n");
5994 if (test_bit(LOOP_RESYNC_NEEDED,
5998 if (vha->flags.nvme_enabled) {
5999 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
6000 ql_dbg(ql_dbg_disc, vha, 0x2049,
6001 "Register NVME FC Type Features failed.\n");
6004 if (qla2x00_rnn_id(vha)) {
6006 ql_dbg(ql_dbg_disc, vha, 0x2104,
6007 "Register Node Name failed.\n");
6008 if (test_bit(LOOP_RESYNC_NEEDED,
6011 } else if (qla2x00_rsnn_nn(vha)) {
6013 ql_dbg(ql_dbg_disc, vha, 0x209b,
6014 "Register Symbolic Node Name failed.\n");
6015 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6021 /* Mark the time right before querying FW for connected ports.
6022 * This process is long, asynchronous and by the time it's done,
6023 * collected information might not be accurate anymore. E.g.
6024 * disconnected port might have re-connected and a brand new
6025 * session has been created. In this case session's generation
6026 * will be newer than discovery_gen. */
6027 qlt_do_generation_tick(vha, &discovery_gen);
6029 if (USE_ASYNC_SCAN(ha)) {
6030 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
6033 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6035 list_for_each_entry(fcport, &vha->vp_fcports, list)
6036 fcport->scan_state = QLA_FCPORT_SCAN;
6038 rval = qla2x00_find_all_fabric_devs(vha);
6040 if (rval != QLA_SUCCESS)
6044 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
6045 qla_nvme_register_hba(vha);
6048 ql_dbg(ql_dbg_disc, vha, 0x2068,
6049 "Configure fabric error exit rval=%d.\n", rval);
6055 * qla2x00_find_all_fabric_devs
6058 * ha = adapter block pointer.
6059 * dev = database device entry pointer.
6068 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
6072 fc_port_t *fcport, *new_fcport;
6077 int first_dev, last_dev;
6078 port_id_t wrap = {}, nxt_d_id;
6079 struct qla_hw_data *ha = vha->hw;
6080 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6081 unsigned long flags;
6085 /* Try GID_PT to get device list, else GAN. */
6087 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
6092 ql_dbg(ql_dbg_disc, vha, 0x209c,
6093 "GID_PT allocations failed, fallback on GA_NXT.\n");
6095 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
6096 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
6098 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6100 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
6102 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6104 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
6106 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6108 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
6110 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6114 /* If other queries succeeded probe for FC-4 type */
6116 qla2x00_gff_id(vha, swl);
6117 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6123 /* Allocate temporary fcport for any new fcports discovered. */
6124 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
6125 if (new_fcport == NULL) {
6126 ql_log(ql_log_warn, vha, 0x209d,
6127 "Failed to allocate memory for fcport.\n");
6128 return (QLA_MEMORY_ALLOC_FAILED);
6130 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
6131 /* Set start port ID scan at adapter ID. */
6135 /* Starting free loop ID. */
6136 loop_id = ha->min_external_loopid;
6137 for (; loop_id <= ha->max_loop_id; loop_id++) {
6138 if (qla2x00_is_reserved_id(vha, loop_id))
6141 if (ha->current_topology == ISP_CFG_FL &&
6142 (atomic_read(&vha->loop_down_timer) ||
6143 LOOP_TRANSITION(vha))) {
6144 atomic_set(&vha->loop_down_timer, 0);
6145 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6146 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
6152 wrap.b24 = new_fcport->d_id.b24;
6154 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
6155 memcpy(new_fcport->node_name,
6156 swl[swl_idx].node_name, WWN_SIZE);
6157 memcpy(new_fcport->port_name,
6158 swl[swl_idx].port_name, WWN_SIZE);
6159 memcpy(new_fcport->fabric_port_name,
6160 swl[swl_idx].fabric_port_name, WWN_SIZE);
6161 new_fcport->fp_speed = swl[swl_idx].fp_speed;
6162 new_fcport->fc4_type = swl[swl_idx].fc4_type;
6164 new_fcport->nvme_flag = 0;
6165 if (vha->flags.nvme_enabled &&
6166 swl[swl_idx].fc4_type & FS_FC4TYPE_NVME) {
6167 ql_log(ql_log_info, vha, 0x2131,
6168 "FOUND: NVME port %8phC as FC Type 28h\n",
6169 new_fcport->port_name);
6172 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
6178 /* Send GA_NXT to the switch */
6179 rval = qla2x00_ga_nxt(vha, new_fcport);
6180 if (rval != QLA_SUCCESS) {
6181 ql_log(ql_log_warn, vha, 0x209e,
6182 "SNS scan failed -- assuming "
6183 "zero-entry result.\n");
6189 /* If wrap on switch device list, exit. */
6191 wrap.b24 = new_fcport->d_id.b24;
6193 } else if (new_fcport->d_id.b24 == wrap.b24) {
6194 ql_dbg(ql_dbg_disc, vha, 0x209f,
6195 "Device wrap (%02x%02x%02x).\n",
6196 new_fcport->d_id.b.domain,
6197 new_fcport->d_id.b.area,
6198 new_fcport->d_id.b.al_pa);
6202 /* Bypass if same physical adapter. */
6203 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
6206 /* Bypass virtual ports of the same host. */
6207 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
6210 /* Bypass if same domain and area of adapter. */
6211 if (((new_fcport->d_id.b24 & 0xffff00) ==
6212 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
6216 /* Bypass reserved domain fields. */
6217 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
6220 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
6221 if (ql2xgffidenable &&
6222 (!(new_fcport->fc4_type & FS_FC4TYPE_FCP) &&
6223 new_fcport->fc4_type != 0))
6226 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
6228 /* Locate matching device in database. */
6230 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6231 if (memcmp(new_fcport->port_name, fcport->port_name,
6235 fcport->scan_state = QLA_FCPORT_FOUND;
6239 /* Update port state. */
6240 memcpy(fcport->fabric_port_name,
6241 new_fcport->fabric_port_name, WWN_SIZE);
6242 fcport->fp_speed = new_fcport->fp_speed;
6245 * If address the same and state FCS_ONLINE
6246 * (or in target mode), nothing changed.
6248 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
6249 (atomic_read(&fcport->state) == FCS_ONLINE ||
6250 (vha->host->active_mode == MODE_TARGET))) {
6254 if (fcport->login_retry == 0)
6255 fcport->login_retry =
6256 vha->hw->login_retry_count;
6258 * If device was not a fabric device before.
6260 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
6261 fcport->d_id.b24 = new_fcport->d_id.b24;
6262 qla2x00_clear_loop_id(fcport);
6263 fcport->flags |= (FCF_FABRIC_DEVICE |
6269 * Port ID changed or device was marked to be updated;
6270 * Log it out if still logged in and mark it for
6273 if (qla_tgt_mode_enabled(base_vha)) {
6274 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
6275 "port changed FC ID, %8phC"
6276 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
6278 fcport->d_id.b.domain,
6279 fcport->d_id.b.area,
6280 fcport->d_id.b.al_pa,
6282 new_fcport->d_id.b.domain,
6283 new_fcport->d_id.b.area,
6284 new_fcport->d_id.b.al_pa);
6285 fcport->d_id.b24 = new_fcport->d_id.b24;
6289 fcport->d_id.b24 = new_fcport->d_id.b24;
6290 fcport->flags |= FCF_LOGIN_NEEDED;
6294 if (found && NVME_TARGET(vha->hw, fcport)) {
6295 if (fcport->disc_state == DSC_DELETE_PEND) {
6296 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
6297 vha->fcport_count--;
6298 fcport->login_succ = 0;
6303 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6306 /* If device was not in our fcports list, then add it. */
6307 new_fcport->scan_state = QLA_FCPORT_FOUND;
6308 list_add_tail(&new_fcport->list, &vha->vp_fcports);
6310 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6313 /* Allocate a new replacement fcport. */
6314 nxt_d_id.b24 = new_fcport->d_id.b24;
6315 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
6316 if (new_fcport == NULL) {
6317 ql_log(ql_log_warn, vha, 0xd032,
6318 "Memory allocation failed for fcport.\n");
6319 return (QLA_MEMORY_ALLOC_FAILED);
6321 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
6322 new_fcport->d_id.b24 = nxt_d_id.b24;
6325 qla2x00_free_fcport(new_fcport);
6328 * Logout all previous fabric dev marked lost, except FCP2 devices.
6330 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6331 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6334 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
6337 if (fcport->scan_state == QLA_FCPORT_SCAN) {
6338 if ((qla_dual_mode_enabled(vha) ||
6339 qla_ini_mode_enabled(vha)) &&
6340 atomic_read(&fcport->state) == FCS_ONLINE) {
6341 qla2x00_mark_device_lost(vha, fcport,
6342 ql2xplogiabsentdevice);
6343 if (fcport->loop_id != FC_NO_LOOP_ID &&
6344 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
6345 fcport->port_type != FCT_INITIATOR &&
6346 fcport->port_type != FCT_BROADCAST) {
6347 ql_dbg(ql_dbg_disc, vha, 0x20f0,
6348 "%s %d %8phC post del sess\n",
6351 qlt_schedule_sess_for_deletion(fcport);
6357 if (fcport->scan_state == QLA_FCPORT_FOUND &&
6358 (fcport->flags & FCF_LOGIN_NEEDED) != 0)
6359 qla24xx_fcport_handle_login(vha, fcport);
6364 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
6366 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
6368 int loop_id = FC_NO_LOOP_ID;
6369 int lid = NPH_MGMT_SERVER - vha->vp_idx;
6370 unsigned long flags;
6371 struct qla_hw_data *ha = vha->hw;
6373 if (vha->vp_idx == 0) {
6374 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
6375 return NPH_MGMT_SERVER;
6378 /* pick id from high and work down to low */
6379 spin_lock_irqsave(&ha->vport_slock, flags);
6380 for (; lid > 0; lid--) {
6381 if (!test_bit(lid, vha->hw->loop_id_map)) {
6382 set_bit(lid, vha->hw->loop_id_map);
6387 spin_unlock_irqrestore(&ha->vport_slock, flags);
6393 * qla2x00_fabric_login
6394 * Issue fabric login command.
6397 * ha = adapter block pointer.
6398 * device = pointer to FC device type structure.
6401 * 0 - Login successfully
6403 * 2 - Initiator device
6407 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
6408 uint16_t *next_loopid)
6412 uint16_t tmp_loopid;
6413 uint16_t mb[MAILBOX_REGISTER_COUNT];
6414 struct qla_hw_data *ha = vha->hw;
6420 ql_dbg(ql_dbg_disc, vha, 0x2000,
6421 "Trying Fabric Login w/loop id 0x%04x for port "
6423 fcport->loop_id, fcport->d_id.b.domain,
6424 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6426 /* Login fcport on switch. */
6427 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
6428 fcport->d_id.b.domain, fcport->d_id.b.area,
6429 fcport->d_id.b.al_pa, mb, BIT_0);
6430 if (rval != QLA_SUCCESS) {
6433 if (mb[0] == MBS_PORT_ID_USED) {
6435 * Device has another loop ID. The firmware team
6436 * recommends the driver perform an implicit login with
6437 * the specified ID again. The ID we just used is save
6438 * here so we return with an ID that can be tried by
6442 tmp_loopid = fcport->loop_id;
6443 fcport->loop_id = mb[1];
6445 ql_dbg(ql_dbg_disc, vha, 0x2001,
6446 "Fabric Login: port in use - next loop "
6447 "id=0x%04x, port id= %02x%02x%02x.\n",
6448 fcport->loop_id, fcport->d_id.b.domain,
6449 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6451 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
6456 /* A retry occurred before. */
6457 *next_loopid = tmp_loopid;
6460 * No retry occurred before. Just increment the
6461 * ID value for next login.
6463 *next_loopid = (fcport->loop_id + 1);
6466 if (mb[1] & BIT_0) {
6467 fcport->port_type = FCT_INITIATOR;
6469 fcport->port_type = FCT_TARGET;
6470 if (mb[1] & BIT_1) {
6471 fcport->flags |= FCF_FCP2_DEVICE;
6476 fcport->supported_classes |= FC_COS_CLASS2;
6478 fcport->supported_classes |= FC_COS_CLASS3;
6480 if (IS_FWI2_CAPABLE(ha)) {
6483 FCF_CONF_COMP_SUPPORTED;
6488 } else if (mb[0] == MBS_LOOP_ID_USED) {
6490 * Loop ID already used, try next loop ID.
6493 rval = qla2x00_find_new_loop_id(vha, fcport);
6494 if (rval != QLA_SUCCESS) {
6495 /* Ran out of loop IDs to use */
6498 } else if (mb[0] == MBS_COMMAND_ERROR) {
6500 * Firmware possibly timed out during login. If NO
6501 * retries are left to do then the device is declared
6504 *next_loopid = fcport->loop_id;
6505 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6506 fcport->d_id.b.domain, fcport->d_id.b.area,
6507 fcport->d_id.b.al_pa);
6508 qla2x00_mark_device_lost(vha, fcport, 1);
6514 * unrecoverable / not handled error
6516 ql_dbg(ql_dbg_disc, vha, 0x2002,
6517 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6518 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
6519 fcport->d_id.b.area, fcport->d_id.b.al_pa,
6520 fcport->loop_id, jiffies);
6522 *next_loopid = fcport->loop_id;
6523 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6524 fcport->d_id.b.domain, fcport->d_id.b.area,
6525 fcport->d_id.b.al_pa);
6526 qla2x00_clear_loop_id(fcport);
6527 fcport->login_retry = 0;
6538 * qla2x00_local_device_login
6539 * Issue local device login command.
6542 * ha = adapter block pointer.
6543 * loop_id = loop id of device to login to.
6545 * Returns (Where's the #define!!!!):
6546 * 0 - Login successfully
6551 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
6554 uint16_t mb[MAILBOX_REGISTER_COUNT];
6556 memset(mb, 0, sizeof(mb));
6557 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
6558 if (rval == QLA_SUCCESS) {
6559 /* Interrogate mailbox registers for any errors */
6560 if (mb[0] == MBS_COMMAND_ERROR)
6562 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
6563 /* device not in PCB table */
6571 * qla2x00_loop_resync
6572 * Resync with fibre channel devices.
6575 * ha = adapter block pointer.
6581 qla2x00_loop_resync(scsi_qla_host_t *vha)
6583 int rval = QLA_SUCCESS;
6586 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6587 if (vha->flags.online) {
6588 if (!(rval = qla2x00_fw_ready(vha))) {
6589 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6592 if (!IS_QLAFX00(vha->hw)) {
6594 * Issue a marker after FW becomes
6597 qla2x00_marker(vha, vha->hw->base_qpair,
6599 vha->marker_needed = 0;
6602 /* Remap devices on Loop. */
6603 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6605 if (IS_QLAFX00(vha->hw))
6606 qlafx00_configure_devices(vha);
6608 qla2x00_configure_loop(vha);
6611 } while (!atomic_read(&vha->loop_down_timer) &&
6612 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6613 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
6618 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6619 return (QLA_FUNCTION_FAILED);
6622 ql_dbg(ql_dbg_disc, vha, 0x206c,
6623 "%s *** FAILED ***.\n", __func__);
6629 * qla2x00_perform_loop_resync
6630 * Description: This function will set the appropriate flags and call
6631 * qla2x00_loop_resync. If successful loop will be resynced
6632 * Arguments : scsi_qla_host_t pointer
6633 * returm : Success or Failure
6636 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
6640 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
6641 /*Configure the flags so that resync happens properly*/
6642 atomic_set(&ha->loop_down_timer, 0);
6643 if (!(ha->device_flags & DFLG_NO_CABLE)) {
6644 atomic_set(&ha->loop_state, LOOP_UP);
6645 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
6646 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
6647 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
6649 rval = qla2x00_loop_resync(ha);
6651 atomic_set(&ha->loop_state, LOOP_DEAD);
6653 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
6660 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
6663 struct scsi_qla_host *vha, *tvp;
6664 struct qla_hw_data *ha = base_vha->hw;
6665 unsigned long flags;
6667 spin_lock_irqsave(&ha->vport_slock, flags);
6668 /* Go with deferred removal of rport references. */
6669 list_for_each_entry_safe(vha, tvp, &base_vha->hw->vp_list, list) {
6670 atomic_inc(&vha->vref_count);
6671 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6672 if (fcport->drport &&
6673 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
6674 spin_unlock_irqrestore(&ha->vport_slock, flags);
6675 qla2x00_rport_del(fcport);
6677 spin_lock_irqsave(&ha->vport_slock, flags);
6680 atomic_dec(&vha->vref_count);
6681 wake_up(&vha->vref_waitq);
6683 spin_unlock_irqrestore(&ha->vport_slock, flags);
6686 /* Assumes idc_lock always held on entry */
6688 qla83xx_reset_ownership(scsi_qla_host_t *vha)
6690 struct qla_hw_data *ha = vha->hw;
6691 uint32_t drv_presence, drv_presence_mask;
6692 uint32_t dev_part_info1, dev_part_info2, class_type;
6693 uint32_t class_type_mask = 0x3;
6694 uint16_t fcoe_other_function = 0xffff, i;
6696 if (IS_QLA8044(ha)) {
6697 drv_presence = qla8044_rd_direct(vha,
6698 QLA8044_CRB_DRV_ACTIVE_INDEX);
6699 dev_part_info1 = qla8044_rd_direct(vha,
6700 QLA8044_CRB_DEV_PART_INFO_INDEX);
6701 dev_part_info2 = qla8044_rd_direct(vha,
6702 QLA8044_CRB_DEV_PART_INFO2);
6704 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6705 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
6706 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
6708 for (i = 0; i < 8; i++) {
6709 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
6710 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6711 (i != ha->portnum)) {
6712 fcoe_other_function = i;
6716 if (fcoe_other_function == 0xffff) {
6717 for (i = 0; i < 8; i++) {
6718 class_type = ((dev_part_info2 >> (i * 4)) &
6720 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6721 ((i + 8) != ha->portnum)) {
6722 fcoe_other_function = i + 8;
6728 * Prepare drv-presence mask based on fcoe functions present.
6729 * However consider only valid physical fcoe function numbers (0-15).
6731 drv_presence_mask = ~((1 << (ha->portnum)) |
6732 ((fcoe_other_function == 0xffff) ?
6733 0 : (1 << (fcoe_other_function))));
6735 /* We are the reset owner iff:
6736 * - No other protocol drivers present.
6737 * - This is the lowest among fcoe functions. */
6738 if (!(drv_presence & drv_presence_mask) &&
6739 (ha->portnum < fcoe_other_function)) {
6740 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
6741 "This host is Reset owner.\n");
6742 ha->flags.nic_core_reset_owner = 1;
6747 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
6749 int rval = QLA_SUCCESS;
6750 struct qla_hw_data *ha = vha->hw;
6753 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6754 if (rval == QLA_SUCCESS) {
6755 drv_ack |= (1 << ha->portnum);
6756 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6763 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
6765 int rval = QLA_SUCCESS;
6766 struct qla_hw_data *ha = vha->hw;
6769 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6770 if (rval == QLA_SUCCESS) {
6771 drv_ack &= ~(1 << ha->portnum);
6772 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6779 qla83xx_dev_state_to_string(uint32_t dev_state)
6781 switch (dev_state) {
6782 case QLA8XXX_DEV_COLD:
6783 return "COLD/RE-INIT";
6784 case QLA8XXX_DEV_INITIALIZING:
6785 return "INITIALIZING";
6786 case QLA8XXX_DEV_READY:
6788 case QLA8XXX_DEV_NEED_RESET:
6789 return "NEED RESET";
6790 case QLA8XXX_DEV_NEED_QUIESCENT:
6791 return "NEED QUIESCENT";
6792 case QLA8XXX_DEV_FAILED:
6794 case QLA8XXX_DEV_QUIESCENT:
6801 /* Assumes idc-lock always held on entry */
6803 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6805 struct qla_hw_data *ha = vha->hw;
6806 uint32_t idc_audit_reg = 0, duration_secs = 0;
6808 switch (audit_type) {
6809 case IDC_AUDIT_TIMESTAMP:
6810 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6811 idc_audit_reg = (ha->portnum) |
6812 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6813 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6816 case IDC_AUDIT_COMPLETION:
6817 duration_secs = ((jiffies_to_msecs(jiffies) -
6818 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6819 idc_audit_reg = (ha->portnum) |
6820 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6821 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6825 ql_log(ql_log_warn, vha, 0xb078,
6826 "Invalid audit type specified.\n");
6831 /* Assumes idc_lock always held on entry */
6833 qla83xx_initiating_reset(scsi_qla_host_t *vha)
6835 struct qla_hw_data *ha = vha->hw;
6836 uint32_t idc_control, dev_state;
6838 __qla83xx_get_idc_control(vha, &idc_control);
6839 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6840 ql_log(ql_log_info, vha, 0xb080,
6841 "NIC Core reset has been disabled. idc-control=0x%x\n",
6843 return QLA_FUNCTION_FAILED;
6846 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6847 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6848 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6849 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6850 QLA8XXX_DEV_NEED_RESET);
6851 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6852 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6854 const char *state = qla83xx_dev_state_to_string(dev_state);
6856 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
6858 /* SV: XXX: Is timeout required here? */
6859 /* Wait for IDC state change READY -> NEED_RESET */
6860 while (dev_state == QLA8XXX_DEV_READY) {
6861 qla83xx_idc_unlock(vha, 0);
6863 qla83xx_idc_lock(vha, 0);
6864 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6868 /* Send IDC ack by writing to drv-ack register */
6869 __qla83xx_set_drv_ack(vha);
6875 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6877 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6881 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6883 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6887 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6889 uint32_t drv_presence = 0;
6890 struct qla_hw_data *ha = vha->hw;
6892 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6893 if (drv_presence & (1 << ha->portnum))
6896 return QLA_TEST_FAILED;
6900 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6902 int rval = QLA_SUCCESS;
6903 struct qla_hw_data *ha = vha->hw;
6905 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6906 "Entered %s().\n", __func__);
6908 if (vha->device_flags & DFLG_DEV_FAILED) {
6909 ql_log(ql_log_warn, vha, 0xb059,
6910 "Device in unrecoverable FAILED state.\n");
6911 return QLA_FUNCTION_FAILED;
6914 qla83xx_idc_lock(vha, 0);
6916 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6917 ql_log(ql_log_warn, vha, 0xb05a,
6918 "Function=0x%x has been removed from IDC participation.\n",
6920 rval = QLA_FUNCTION_FAILED;
6924 qla83xx_reset_ownership(vha);
6926 rval = qla83xx_initiating_reset(vha);
6929 * Perform reset if we are the reset-owner,
6930 * else wait till IDC state changes to READY/FAILED.
6932 if (rval == QLA_SUCCESS) {
6933 rval = qla83xx_idc_state_handler(vha);
6935 if (rval == QLA_SUCCESS)
6936 ha->flags.nic_core_hung = 0;
6937 __qla83xx_clear_drv_ack(vha);
6941 qla83xx_idc_unlock(vha, 0);
6943 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6949 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6951 struct qla_hw_data *ha = vha->hw;
6952 int rval = QLA_FUNCTION_FAILED;
6954 if (!IS_MCTP_CAPABLE(ha)) {
6955 /* This message can be removed from the final version */
6956 ql_log(ql_log_info, vha, 0x506d,
6957 "This board is not MCTP capable\n");
6961 if (!ha->mctp_dump) {
6962 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6963 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6965 if (!ha->mctp_dump) {
6966 ql_log(ql_log_warn, vha, 0x506e,
6967 "Failed to allocate memory for mctp dump\n");
6972 #define MCTP_DUMP_STR_ADDR 0x00000000
6973 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6974 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6975 if (rval != QLA_SUCCESS) {
6976 ql_log(ql_log_warn, vha, 0x506f,
6977 "Failed to capture mctp dump\n");
6979 ql_log(ql_log_info, vha, 0x5070,
6980 "Mctp dump capture for host (%ld/%p).\n",
6981 vha->host_no, ha->mctp_dump);
6982 ha->mctp_dumped = 1;
6985 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
6986 ha->flags.nic_core_reset_hdlr_active = 1;
6987 rval = qla83xx_restart_nic_firmware(vha);
6989 /* NIC Core reset failed. */
6990 ql_log(ql_log_warn, vha, 0x5071,
6991 "Failed to restart nic firmware\n");
6993 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6994 "Restarted NIC firmware successfully.\n");
6995 ha->flags.nic_core_reset_hdlr_active = 0;
7003 * qla2x00_quiesce_io
7004 * Description: This function will block the new I/Os
7005 * Its not aborting any I/Os as context
7006 * is not destroyed during quiescence
7007 * Arguments: scsi_qla_host_t
7011 qla2x00_quiesce_io(scsi_qla_host_t *vha)
7013 struct qla_hw_data *ha = vha->hw;
7014 struct scsi_qla_host *vp, *tvp;
7015 unsigned long flags;
7017 ql_dbg(ql_dbg_dpc, vha, 0x401d,
7018 "Quiescing I/O - ha=%p.\n", ha);
7020 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
7021 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
7022 atomic_set(&vha->loop_state, LOOP_DOWN);
7023 qla2x00_mark_all_devices_lost(vha);
7025 spin_lock_irqsave(&ha->vport_slock, flags);
7026 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7027 atomic_inc(&vp->vref_count);
7028 spin_unlock_irqrestore(&ha->vport_slock, flags);
7030 qla2x00_mark_all_devices_lost(vp);
7032 spin_lock_irqsave(&ha->vport_slock, flags);
7033 atomic_dec(&vp->vref_count);
7035 spin_unlock_irqrestore(&ha->vport_slock, flags);
7037 if (!atomic_read(&vha->loop_down_timer))
7038 atomic_set(&vha->loop_down_timer,
7041 /* Wait for pending cmds to complete */
7042 WARN_ON_ONCE(qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST)
7047 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
7049 struct qla_hw_data *ha = vha->hw;
7050 struct scsi_qla_host *vp, *tvp;
7051 unsigned long flags;
7055 /* For ISP82XX, driver waits for completion of the commands.
7056 * online flag should be set.
7058 if (!(IS_P3P_TYPE(ha)))
7059 vha->flags.online = 0;
7060 ha->flags.chip_reset_done = 0;
7061 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
7062 vha->qla_stats.total_isp_aborts++;
7064 ql_log(ql_log_info, vha, 0x00af,
7065 "Performing ISP error recovery - ha=%p.\n", ha);
7067 ha->flags.purge_mbox = 1;
7068 /* For ISP82XX, reset_chip is just disabling interrupts.
7069 * Driver waits for the completion of the commands.
7070 * the interrupts need to be enabled.
7072 if (!(IS_P3P_TYPE(ha)))
7073 ha->isp_ops->reset_chip(vha);
7075 ha->link_data_rate = PORT_SPEED_UNKNOWN;
7077 ha->flags.rida_fmt2 = 0;
7078 ha->flags.n2n_ae = 0;
7079 ha->flags.lip_ae = 0;
7080 ha->current_topology = 0;
7082 ha->flags.fw_init_done = 0;
7084 ha->base_qpair->chip_reset = ha->chip_reset;
7085 ha->base_qpair->cmd_cnt = ha->base_qpair->cmd_completion_cnt = 0;
7086 ha->base_qpair->prev_completion_cnt = 0;
7087 for (i = 0; i < ha->max_qpairs; i++) {
7088 if (ha->queue_pair_map[i]) {
7089 ha->queue_pair_map[i]->chip_reset =
7090 ha->base_qpair->chip_reset;
7091 ha->queue_pair_map[i]->cmd_cnt =
7092 ha->queue_pair_map[i]->cmd_completion_cnt = 0;
7093 ha->base_qpair->prev_completion_cnt = 0;
7097 /* purge MBox commands */
7098 if (atomic_read(&ha->num_pend_mbx_stage3)) {
7099 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
7100 complete(&ha->mbx_intr_comp);
7104 while (atomic_read(&ha->num_pend_mbx_stage3) ||
7105 atomic_read(&ha->num_pend_mbx_stage2) ||
7106 atomic_read(&ha->num_pend_mbx_stage1)) {
7112 ha->flags.purge_mbox = 0;
7114 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
7115 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
7116 atomic_set(&vha->loop_state, LOOP_DOWN);
7117 qla2x00_mark_all_devices_lost(vha);
7119 spin_lock_irqsave(&ha->vport_slock, flags);
7120 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7121 atomic_inc(&vp->vref_count);
7122 spin_unlock_irqrestore(&ha->vport_slock, flags);
7124 qla2x00_mark_all_devices_lost(vp);
7126 spin_lock_irqsave(&ha->vport_slock, flags);
7127 atomic_dec(&vp->vref_count);
7129 spin_unlock_irqrestore(&ha->vport_slock, flags);
7131 if (!atomic_read(&vha->loop_down_timer))
7132 atomic_set(&vha->loop_down_timer,
7136 /* Clear all async request states across all VPs. */
7137 list_for_each_entry(fcport, &vha->vp_fcports, list) {
7138 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7139 fcport->scan_state = 0;
7141 spin_lock_irqsave(&ha->vport_slock, flags);
7142 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7143 atomic_inc(&vp->vref_count);
7144 spin_unlock_irqrestore(&ha->vport_slock, flags);
7146 list_for_each_entry(fcport, &vp->vp_fcports, list)
7147 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7149 spin_lock_irqsave(&ha->vport_slock, flags);
7150 atomic_dec(&vp->vref_count);
7152 spin_unlock_irqrestore(&ha->vport_slock, flags);
7154 /* Make sure for ISP 82XX IO DMA is complete */
7155 if (IS_P3P_TYPE(ha)) {
7156 qla82xx_chip_reset_cleanup(vha);
7157 ql_log(ql_log_info, vha, 0x00b4,
7158 "Done chip reset cleanup.\n");
7160 /* Done waiting for pending commands. Reset online flag */
7161 vha->flags.online = 0;
7164 /* Requeue all commands in outstanding command list. */
7165 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
7166 /* memory barrier */
7172 * Resets ISP and aborts all outstanding commands.
7175 * ha = adapter block pointer.
7181 qla2x00_abort_isp(scsi_qla_host_t *vha)
7185 struct qla_hw_data *ha = vha->hw;
7186 struct scsi_qla_host *vp, *tvp;
7187 struct req_que *req = ha->req_q_map[0];
7188 unsigned long flags;
7190 if (vha->flags.online) {
7191 qla2x00_abort_isp_cleanup(vha);
7193 if (vha->hw->flags.port_isolated)
7196 if (qla2x00_isp_reg_stat(ha)) {
7197 ql_log(ql_log_info, vha, 0x803f,
7198 "ISP Abort - ISP reg disconnect, exiting.\n");
7202 if (test_and_clear_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags)) {
7203 ha->flags.chip_reset_done = 1;
7204 vha->flags.online = 1;
7206 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7210 if (IS_QLA8031(ha)) {
7211 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
7212 "Clearing fcoe driver presence.\n");
7213 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
7214 ql_dbg(ql_dbg_p3p, vha, 0xb073,
7215 "Error while clearing DRV-Presence.\n");
7218 if (unlikely(pci_channel_offline(ha->pdev) &&
7219 ha->flags.pci_channel_io_perm_failure)) {
7220 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7225 switch (vha->qlini_mode) {
7226 case QLA2XXX_INI_MODE_DISABLED:
7227 if (!qla_tgt_mode_enabled(vha))
7230 case QLA2XXX_INI_MODE_DUAL:
7231 if (!qla_dual_mode_enabled(vha) &&
7232 !qla_ini_mode_enabled(vha))
7235 case QLA2XXX_INI_MODE_ENABLED:
7240 ha->isp_ops->get_flash_version(vha, req->ring);
7242 if (qla2x00_isp_reg_stat(ha)) {
7243 ql_log(ql_log_info, vha, 0x803f,
7244 "ISP Abort - ISP reg disconnect pre nvram config, exiting.\n");
7247 ha->isp_ops->nvram_config(vha);
7249 if (qla2x00_isp_reg_stat(ha)) {
7250 ql_log(ql_log_info, vha, 0x803f,
7251 "ISP Abort - ISP reg disconnect post nvmram config, exiting.\n");
7254 if (!qla2x00_restart_isp(vha)) {
7255 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7257 if (!atomic_read(&vha->loop_down_timer)) {
7259 * Issue marker command only when we are going
7260 * to start the I/O .
7262 vha->marker_needed = 1;
7265 vha->flags.online = 1;
7267 ha->isp_ops->enable_intrs(ha);
7269 ha->isp_abort_cnt = 0;
7270 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7272 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
7273 qla2x00_get_fw_version(vha);
7275 ha->flags.fce_enabled = 1;
7277 fce_calc_size(ha->fce_bufs));
7278 rval = qla2x00_enable_fce_trace(vha,
7279 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
7282 ql_log(ql_log_warn, vha, 0x8033,
7283 "Unable to reinitialize FCE "
7285 ha->flags.fce_enabled = 0;
7290 memset(ha->eft, 0, EFT_SIZE);
7291 rval = qla2x00_enable_eft_trace(vha,
7292 ha->eft_dma, EFT_NUM_BUFFERS);
7294 ql_log(ql_log_warn, vha, 0x8034,
7295 "Unable to reinitialize EFT "
7299 } else { /* failed the ISP abort */
7300 vha->flags.online = 1;
7301 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
7302 if (ha->isp_abort_cnt == 0) {
7303 ql_log(ql_log_fatal, vha, 0x8035,
7304 "ISP error recover failed - "
7305 "board disabled.\n");
7307 * The next call disables the board
7310 qla2x00_abort_isp_cleanup(vha);
7311 vha->flags.online = 0;
7312 clear_bit(ISP_ABORT_RETRY,
7315 } else { /* schedule another ISP abort */
7316 ha->isp_abort_cnt--;
7317 ql_dbg(ql_dbg_taskm, vha, 0x8020,
7318 "ISP abort - retry remaining %d.\n",
7323 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
7324 ql_dbg(ql_dbg_taskm, vha, 0x8021,
7325 "ISP error recovery - retrying (%d) "
7326 "more times.\n", ha->isp_abort_cnt);
7327 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7334 if (vha->hw->flags.port_isolated) {
7335 qla2x00_abort_isp_cleanup(vha);
7340 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
7341 qla2x00_configure_hba(vha);
7342 spin_lock_irqsave(&ha->vport_slock, flags);
7343 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7345 atomic_inc(&vp->vref_count);
7346 spin_unlock_irqrestore(&ha->vport_slock, flags);
7348 qla2x00_vp_abort_isp(vp);
7350 spin_lock_irqsave(&ha->vport_slock, flags);
7351 atomic_dec(&vp->vref_count);
7354 spin_unlock_irqrestore(&ha->vport_slock, flags);
7356 if (IS_QLA8031(ha)) {
7357 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
7358 "Setting back fcoe driver presence.\n");
7359 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
7360 ql_dbg(ql_dbg_p3p, vha, 0xb074,
7361 "Error while setting DRV-Presence.\n");
7364 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
7372 * qla2x00_restart_isp
7373 * restarts the ISP after a reset
7376 * ha = adapter block pointer.
7382 qla2x00_restart_isp(scsi_qla_host_t *vha)
7385 struct qla_hw_data *ha = vha->hw;
7387 /* If firmware needs to be loaded */
7388 if (qla2x00_isp_firmware(vha)) {
7389 vha->flags.online = 0;
7390 status = ha->isp_ops->chip_diag(vha);
7393 status = qla2x00_setup_chip(vha);
7398 status = qla2x00_init_rings(vha);
7402 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7403 ha->flags.chip_reset_done = 1;
7405 /* Initialize the queues in use */
7406 qla25xx_init_queues(ha);
7408 status = qla2x00_fw_ready(vha);
7410 /* if no cable then assume it's good */
7411 return vha->device_flags & DFLG_NO_CABLE ? 0 : status;
7414 /* Issue a marker after FW becomes ready. */
7415 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
7416 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7422 qla25xx_init_queues(struct qla_hw_data *ha)
7424 struct rsp_que *rsp = NULL;
7425 struct req_que *req = NULL;
7426 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7430 for (i = 1; i < ha->max_rsp_queues; i++) {
7431 rsp = ha->rsp_q_map[i];
7432 if (rsp && test_bit(i, ha->rsp_qid_map)) {
7433 rsp->options &= ~BIT_0;
7434 ret = qla25xx_init_rsp_que(base_vha, rsp);
7435 if (ret != QLA_SUCCESS)
7436 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
7437 "%s Rsp que: %d init failed.\n",
7440 ql_dbg(ql_dbg_init, base_vha, 0x0100,
7441 "%s Rsp que: %d inited.\n",
7445 for (i = 1; i < ha->max_req_queues; i++) {
7446 req = ha->req_q_map[i];
7447 if (req && test_bit(i, ha->req_qid_map)) {
7448 /* Clear outstanding commands array. */
7449 req->options &= ~BIT_0;
7450 ret = qla25xx_init_req_que(base_vha, req);
7451 if (ret != QLA_SUCCESS)
7452 ql_dbg(ql_dbg_init, base_vha, 0x0101,
7453 "%s Req que: %d init failed.\n",
7456 ql_dbg(ql_dbg_init, base_vha, 0x0102,
7457 "%s Req que: %d inited.\n",
7465 * qla2x00_reset_adapter
7469 * ha = adapter block pointer.
7472 qla2x00_reset_adapter(scsi_qla_host_t *vha)
7474 unsigned long flags = 0;
7475 struct qla_hw_data *ha = vha->hw;
7476 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7478 vha->flags.online = 0;
7479 ha->isp_ops->disable_intrs(ha);
7481 spin_lock_irqsave(&ha->hardware_lock, flags);
7482 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
7483 rd_reg_word(®->hccr); /* PCI Posting. */
7484 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
7485 rd_reg_word(®->hccr); /* PCI Posting. */
7486 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7492 qla24xx_reset_adapter(scsi_qla_host_t *vha)
7494 unsigned long flags = 0;
7495 struct qla_hw_data *ha = vha->hw;
7496 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
7498 if (IS_P3P_TYPE(ha))
7501 vha->flags.online = 0;
7502 ha->isp_ops->disable_intrs(ha);
7504 spin_lock_irqsave(&ha->hardware_lock, flags);
7505 wrt_reg_dword(®->hccr, HCCRX_SET_RISC_RESET);
7506 rd_reg_dword(®->hccr);
7507 wrt_reg_dword(®->hccr, HCCRX_REL_RISC_PAUSE);
7508 rd_reg_dword(®->hccr);
7509 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7511 if (IS_NOPOLLING_TYPE(ha))
7512 ha->isp_ops->enable_intrs(ha);
7517 /* On sparc systems, obtain port and node WWN from firmware
7520 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
7521 struct nvram_24xx *nv)
7524 struct qla_hw_data *ha = vha->hw;
7525 struct pci_dev *pdev = ha->pdev;
7526 struct device_node *dp = pci_device_to_OF_node(pdev);
7530 val = of_get_property(dp, "port-wwn", &len);
7531 if (val && len >= WWN_SIZE)
7532 memcpy(nv->port_name, val, WWN_SIZE);
7534 val = of_get_property(dp, "node-wwn", &len);
7535 if (val && len >= WWN_SIZE)
7536 memcpy(nv->node_name, val, WWN_SIZE);
7541 qla24xx_nvram_config(scsi_qla_host_t *vha)
7544 struct init_cb_24xx *icb;
7545 struct nvram_24xx *nv;
7547 uint8_t *dptr1, *dptr2;
7550 struct qla_hw_data *ha = vha->hw;
7553 icb = (struct init_cb_24xx *)ha->init_cb;
7556 /* Determine NVRAM starting address. */
7557 if (ha->port_no == 0) {
7558 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
7559 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
7561 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
7562 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
7565 ha->nvram_size = sizeof(*nv);
7566 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7568 /* Get VPD data into cache */
7569 ha->vpd = ha->nvram + VPD_OFFSET;
7570 ha->isp_ops->read_nvram(vha, ha->vpd,
7571 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
7573 /* Get NVRAM data into cache and calculate checksum. */
7574 dptr = (__force __le32 *)nv;
7575 ha->isp_ops->read_nvram(vha, dptr, ha->nvram_base, ha->nvram_size);
7576 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7577 chksum += le32_to_cpu(*dptr);
7579 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
7580 "Contents of NVRAM\n");
7581 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
7582 nv, ha->nvram_size);
7584 /* Bad NVRAM data, set defaults parameters. */
7585 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
7586 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
7587 /* Reset NVRAM data. */
7588 ql_log(ql_log_warn, vha, 0x006b,
7589 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
7590 chksum, nv->id, nv->nvram_version);
7591 ql_dump_buffer(ql_dbg_init, vha, 0x006b, nv, sizeof(*nv));
7592 ql_log(ql_log_warn, vha, 0x006c,
7593 "Falling back to functioning (yet invalid -- WWPN) "
7597 * Set default initialization control block.
7599 memset(nv, 0, ha->nvram_size);
7600 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7601 nv->version = cpu_to_le16(ICB_VERSION);
7602 nv->frame_payload_size = cpu_to_le16(2048);
7603 nv->execution_throttle = cpu_to_le16(0xFFFF);
7604 nv->exchange_count = cpu_to_le16(0);
7605 nv->hard_address = cpu_to_le16(124);
7606 nv->port_name[0] = 0x21;
7607 nv->port_name[1] = 0x00 + ha->port_no + 1;
7608 nv->port_name[2] = 0x00;
7609 nv->port_name[3] = 0xe0;
7610 nv->port_name[4] = 0x8b;
7611 nv->port_name[5] = 0x1c;
7612 nv->port_name[6] = 0x55;
7613 nv->port_name[7] = 0x86;
7614 nv->node_name[0] = 0x20;
7615 nv->node_name[1] = 0x00;
7616 nv->node_name[2] = 0x00;
7617 nv->node_name[3] = 0xe0;
7618 nv->node_name[4] = 0x8b;
7619 nv->node_name[5] = 0x1c;
7620 nv->node_name[6] = 0x55;
7621 nv->node_name[7] = 0x86;
7622 qla24xx_nvram_wwn_from_ofw(vha, nv);
7623 nv->login_retry_count = cpu_to_le16(8);
7624 nv->interrupt_delay_timer = cpu_to_le16(0);
7625 nv->login_timeout = cpu_to_le16(0);
7626 nv->firmware_options_1 =
7627 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7628 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7629 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7630 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7631 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7632 nv->efi_parameters = cpu_to_le32(0);
7633 nv->reset_delay = 5;
7634 nv->max_luns_per_target = cpu_to_le16(128);
7635 nv->port_down_retry_count = cpu_to_le16(30);
7636 nv->link_down_timeout = cpu_to_le16(30);
7641 if (qla_tgt_mode_enabled(vha)) {
7642 /* Don't enable full login after initial LIP */
7643 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7644 /* Don't enable LIP full login for initiator */
7645 nv->host_p &= cpu_to_le32(~BIT_10);
7648 qlt_24xx_config_nvram_stage1(vha, nv);
7650 /* Reset Initialization control block */
7651 memset(icb, 0, ha->init_cb_size);
7653 /* Copy 1st segment. */
7654 dptr1 = (uint8_t *)icb;
7655 dptr2 = (uint8_t *)&nv->version;
7656 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7658 *dptr1++ = *dptr2++;
7660 icb->login_retry_count = nv->login_retry_count;
7661 icb->link_down_on_nos = nv->link_down_on_nos;
7663 /* Copy 2nd segment. */
7664 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7665 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7666 cnt = (uint8_t *)&icb->reserved_3 -
7667 (uint8_t *)&icb->interrupt_delay_timer;
7669 *dptr1++ = *dptr2++;
7670 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
7672 * Setup driver NVRAM options.
7674 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7677 qlt_24xx_config_nvram_stage2(vha, icb);
7679 if (nv->host_p & cpu_to_le32(BIT_15)) {
7680 /* Use alternate WWN? */
7681 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7682 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7685 /* Prepare nodename */
7686 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7688 * Firmware will apply the following mask if the nodename was
7691 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7692 icb->node_name[0] &= 0xF0;
7695 /* Set host adapter parameters. */
7696 ha->flags.disable_risc_code_load = 0;
7697 ha->flags.enable_lip_reset = 0;
7698 ha->flags.enable_lip_full_login =
7699 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
7700 ha->flags.enable_target_reset =
7701 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
7702 ha->flags.enable_led_scheme = 0;
7703 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
7705 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7706 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7708 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
7709 sizeof(ha->fw_seriallink_options24));
7711 /* save HBA serial number */
7712 ha->serial0 = icb->port_name[5];
7713 ha->serial1 = icb->port_name[6];
7714 ha->serial2 = icb->port_name[7];
7715 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7716 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7718 icb->execution_throttle = cpu_to_le16(0xFFFF);
7720 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7722 /* Set minimum login_timeout to 4 seconds. */
7723 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7724 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7725 if (le16_to_cpu(nv->login_timeout) < 4)
7726 nv->login_timeout = cpu_to_le16(4);
7727 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7729 /* Set minimum RATOV to 100 tenths of a second. */
7732 ha->loop_reset_delay = nv->reset_delay;
7734 /* Link Down Timeout = 0:
7736 * When Port Down timer expires we will start returning
7737 * I/O's to OS with "DID_NO_CONNECT".
7739 * Link Down Timeout != 0:
7741 * The driver waits for the link to come up after link down
7742 * before returning I/Os to OS with "DID_NO_CONNECT".
7744 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7745 ha->loop_down_abort_time =
7746 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7748 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7749 ha->loop_down_abort_time =
7750 (LOOP_DOWN_TIME - ha->link_down_timeout);
7753 /* Need enough time to try and get the port back. */
7754 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7755 if (qlport_down_retry)
7756 ha->port_down_retry_count = qlport_down_retry;
7758 /* Set login_retry_count */
7759 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7760 if (ha->port_down_retry_count ==
7761 le16_to_cpu(nv->port_down_retry_count) &&
7762 ha->port_down_retry_count > 3)
7763 ha->login_retry_count = ha->port_down_retry_count;
7764 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7765 ha->login_retry_count = ha->port_down_retry_count;
7766 if (ql2xloginretrycount)
7767 ha->login_retry_count = ql2xloginretrycount;
7769 /* N2N: driver will initiate Login instead of FW */
7770 icb->firmware_options_3 |= cpu_to_le32(BIT_8);
7773 if (!vha->flags.init_done) {
7774 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7775 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7776 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7777 le16_to_cpu(icb->interrupt_delay_timer) : 2;
7779 icb->firmware_options_2 &= cpu_to_le32(
7780 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7781 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7782 ha->zio_mode = QLA_ZIO_MODE_6;
7784 ql_log(ql_log_info, vha, 0x006f,
7785 "ZIO mode %d enabled; timer delay (%d us).\n",
7786 ha->zio_mode, ha->zio_timer * 100);
7788 icb->firmware_options_2 |= cpu_to_le32(
7789 (uint32_t)ha->zio_mode);
7790 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7794 ql_log(ql_log_warn, vha, 0x0070,
7795 "NVRAM configuration failed.\n");
7801 qla27xx_print_image(struct scsi_qla_host *vha, char *name,
7802 struct qla27xx_image_status *image_status)
7804 ql_dbg(ql_dbg_init, vha, 0x018b,
7805 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
7807 image_status->image_status_mask,
7808 le16_to_cpu(image_status->generation),
7809 image_status->ver_major,
7810 image_status->ver_minor,
7811 image_status->bitmap,
7812 le32_to_cpu(image_status->checksum),
7813 le32_to_cpu(image_status->signature));
7817 qla28xx_check_aux_image_status_signature(
7818 struct qla27xx_image_status *image_status)
7820 ulong signature = le32_to_cpu(image_status->signature);
7822 return signature != QLA28XX_AUX_IMG_STATUS_SIGN;
7826 qla27xx_check_image_status_signature(struct qla27xx_image_status *image_status)
7828 ulong signature = le32_to_cpu(image_status->signature);
7831 signature != QLA27XX_IMG_STATUS_SIGN &&
7832 signature != QLA28XX_IMG_STATUS_SIGN;
7836 qla27xx_image_status_checksum(struct qla27xx_image_status *image_status)
7838 __le32 *p = (__force __le32 *)image_status;
7839 uint n = sizeof(*image_status) / sizeof(*p);
7843 sum += le32_to_cpup(p);
7849 qla28xx_component_bitmask(struct qla27xx_image_status *aux, uint bitmask)
7851 return aux->bitmap & bitmask ?
7852 QLA27XX_SECONDARY_IMAGE : QLA27XX_PRIMARY_IMAGE;
7856 qla28xx_component_status(
7857 struct active_regions *active_regions, struct qla27xx_image_status *aux)
7859 active_regions->aux.board_config =
7860 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_BOARD_CONFIG);
7862 active_regions->aux.vpd_nvram =
7863 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_VPD_NVRAM);
7865 active_regions->aux.npiv_config_0_1 =
7866 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1);
7868 active_regions->aux.npiv_config_2_3 =
7869 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3);
7873 qla27xx_compare_image_generation(
7874 struct qla27xx_image_status *pri_image_status,
7875 struct qla27xx_image_status *sec_image_status)
7877 /* calculate generation delta as uint16 (this accounts for wrap) */
7879 le16_to_cpu(pri_image_status->generation) -
7880 le16_to_cpu(sec_image_status->generation);
7882 ql_dbg(ql_dbg_init, NULL, 0x0180, "generation delta = %d\n", delta);
7888 qla28xx_get_aux_images(
7889 struct scsi_qla_host *vha, struct active_regions *active_regions)
7891 struct qla_hw_data *ha = vha->hw;
7892 struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
7893 bool valid_pri_image = false, valid_sec_image = false;
7894 bool active_pri_image = false, active_sec_image = false;
7896 if (!ha->flt_region_aux_img_status_pri) {
7897 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
7898 goto check_sec_image;
7901 qla24xx_read_flash_data(vha, (uint32_t *)&pri_aux_image_status,
7902 ha->flt_region_aux_img_status_pri,
7903 sizeof(pri_aux_image_status) >> 2);
7904 qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
7906 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
7907 ql_dbg(ql_dbg_init, vha, 0x018b,
7908 "Primary aux image signature (%#x) not valid\n",
7909 le32_to_cpu(pri_aux_image_status.signature));
7910 goto check_sec_image;
7913 if (qla27xx_image_status_checksum(&pri_aux_image_status)) {
7914 ql_dbg(ql_dbg_init, vha, 0x018c,
7915 "Primary aux image checksum failed\n");
7916 goto check_sec_image;
7919 valid_pri_image = true;
7921 if (pri_aux_image_status.image_status_mask & 1) {
7922 ql_dbg(ql_dbg_init, vha, 0x018d,
7923 "Primary aux image is active\n");
7924 active_pri_image = true;
7928 if (!ha->flt_region_aux_img_status_sec) {
7929 ql_dbg(ql_dbg_init, vha, 0x018a,
7930 "Secondary aux image not addressed\n");
7931 goto check_valid_image;
7934 qla24xx_read_flash_data(vha, (uint32_t *)&sec_aux_image_status,
7935 ha->flt_region_aux_img_status_sec,
7936 sizeof(sec_aux_image_status) >> 2);
7937 qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
7939 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
7940 ql_dbg(ql_dbg_init, vha, 0x018b,
7941 "Secondary aux image signature (%#x) not valid\n",
7942 le32_to_cpu(sec_aux_image_status.signature));
7943 goto check_valid_image;
7946 if (qla27xx_image_status_checksum(&sec_aux_image_status)) {
7947 ql_dbg(ql_dbg_init, vha, 0x018c,
7948 "Secondary aux image checksum failed\n");
7949 goto check_valid_image;
7952 valid_sec_image = true;
7954 if (sec_aux_image_status.image_status_mask & 1) {
7955 ql_dbg(ql_dbg_init, vha, 0x018d,
7956 "Secondary aux image is active\n");
7957 active_sec_image = true;
7961 if (valid_pri_image && active_pri_image &&
7962 valid_sec_image && active_sec_image) {
7963 if (qla27xx_compare_image_generation(&pri_aux_image_status,
7964 &sec_aux_image_status) >= 0) {
7965 qla28xx_component_status(active_regions,
7966 &pri_aux_image_status);
7968 qla28xx_component_status(active_regions,
7969 &sec_aux_image_status);
7971 } else if (valid_pri_image && active_pri_image) {
7972 qla28xx_component_status(active_regions, &pri_aux_image_status);
7973 } else if (valid_sec_image && active_sec_image) {
7974 qla28xx_component_status(active_regions, &sec_aux_image_status);
7977 ql_dbg(ql_dbg_init, vha, 0x018f,
7978 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u\n",
7979 active_regions->aux.board_config,
7980 active_regions->aux.vpd_nvram,
7981 active_regions->aux.npiv_config_0_1,
7982 active_regions->aux.npiv_config_2_3);
7986 qla27xx_get_active_image(struct scsi_qla_host *vha,
7987 struct active_regions *active_regions)
7989 struct qla_hw_data *ha = vha->hw;
7990 struct qla27xx_image_status pri_image_status, sec_image_status;
7991 bool valid_pri_image = false, valid_sec_image = false;
7992 bool active_pri_image = false, active_sec_image = false;
7994 if (!ha->flt_region_img_status_pri) {
7995 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
7996 goto check_sec_image;
7999 if (qla24xx_read_flash_data(vha, (uint32_t *)&pri_image_status,
8000 ha->flt_region_img_status_pri, sizeof(pri_image_status) >> 2) !=
8003 goto check_sec_image;
8005 qla27xx_print_image(vha, "Primary image", &pri_image_status);
8007 if (qla27xx_check_image_status_signature(&pri_image_status)) {
8008 ql_dbg(ql_dbg_init, vha, 0x018b,
8009 "Primary image signature (%#x) not valid\n",
8010 le32_to_cpu(pri_image_status.signature));
8011 goto check_sec_image;
8014 if (qla27xx_image_status_checksum(&pri_image_status)) {
8015 ql_dbg(ql_dbg_init, vha, 0x018c,
8016 "Primary image checksum failed\n");
8017 goto check_sec_image;
8020 valid_pri_image = true;
8022 if (pri_image_status.image_status_mask & 1) {
8023 ql_dbg(ql_dbg_init, vha, 0x018d,
8024 "Primary image is active\n");
8025 active_pri_image = true;
8029 if (!ha->flt_region_img_status_sec) {
8030 ql_dbg(ql_dbg_init, vha, 0x018a, "Secondary image not addressed\n");
8031 goto check_valid_image;
8034 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
8035 ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
8036 qla27xx_print_image(vha, "Secondary image", &sec_image_status);
8038 if (qla27xx_check_image_status_signature(&sec_image_status)) {
8039 ql_dbg(ql_dbg_init, vha, 0x018b,
8040 "Secondary image signature (%#x) not valid\n",
8041 le32_to_cpu(sec_image_status.signature));
8042 goto check_valid_image;
8045 if (qla27xx_image_status_checksum(&sec_image_status)) {
8046 ql_dbg(ql_dbg_init, vha, 0x018c,
8047 "Secondary image checksum failed\n");
8048 goto check_valid_image;
8051 valid_sec_image = true;
8053 if (sec_image_status.image_status_mask & 1) {
8054 ql_dbg(ql_dbg_init, vha, 0x018d,
8055 "Secondary image is active\n");
8056 active_sec_image = true;
8060 if (valid_pri_image && active_pri_image)
8061 active_regions->global = QLA27XX_PRIMARY_IMAGE;
8063 if (valid_sec_image && active_sec_image) {
8064 if (!active_regions->global ||
8065 qla27xx_compare_image_generation(
8066 &pri_image_status, &sec_image_status) < 0) {
8067 active_regions->global = QLA27XX_SECONDARY_IMAGE;
8071 ql_dbg(ql_dbg_init, vha, 0x018f, "active image %s (%u)\n",
8072 active_regions->global == QLA27XX_DEFAULT_IMAGE ?
8073 "default (boot/fw)" :
8074 active_regions->global == QLA27XX_PRIMARY_IMAGE ?
8076 active_regions->global == QLA27XX_SECONDARY_IMAGE ?
8077 "secondary" : "invalid",
8078 active_regions->global);
8081 bool qla24xx_risc_firmware_invalid(uint32_t *dword)
8084 !(dword[4] | dword[5] | dword[6] | dword[7]) ||
8085 !(~dword[4] | ~dword[5] | ~dword[6] | ~dword[7]);
8089 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
8093 uint templates, segments, fragment;
8098 uint32_t risc_addr, risc_size, risc_attr = 0;
8099 struct qla_hw_data *ha = vha->hw;
8100 struct req_que *req = ha->req_q_map[0];
8101 struct fwdt *fwdt = ha->fwdt;
8103 ql_dbg(ql_dbg_init, vha, 0x008b,
8104 "FW: Loading firmware from flash (%x).\n", faddr);
8106 dcode = (uint32_t *)req->ring;
8107 qla24xx_read_flash_data(vha, dcode, faddr, 8);
8108 if (qla24xx_risc_firmware_invalid(dcode)) {
8109 ql_log(ql_log_fatal, vha, 0x008c,
8110 "Unable to verify the integrity of flash firmware "
8112 ql_log(ql_log_fatal, vha, 0x008d,
8113 "Firmware data: %08x %08x %08x %08x.\n",
8114 dcode[0], dcode[1], dcode[2], dcode[3]);
8116 return QLA_FUNCTION_FAILED;
8119 dcode = (uint32_t *)req->ring;
8121 segments = FA_RISC_CODE_SEGMENTS;
8122 for (j = 0; j < segments; j++) {
8123 ql_dbg(ql_dbg_init, vha, 0x008d,
8124 "-> Loading segment %u...\n", j);
8125 qla24xx_read_flash_data(vha, dcode, faddr, 10);
8126 risc_addr = be32_to_cpu((__force __be32)dcode[2]);
8127 risc_size = be32_to_cpu((__force __be32)dcode[3]);
8129 *srisc_addr = risc_addr;
8130 risc_attr = be32_to_cpu((__force __be32)dcode[9]);
8133 dlen = ha->fw_transfer_size >> 2;
8134 for (fragment = 0; risc_size; fragment++) {
8135 if (dlen > risc_size)
8138 ql_dbg(ql_dbg_init, vha, 0x008e,
8139 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
8140 fragment, risc_addr, faddr, dlen);
8141 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
8142 for (i = 0; i < dlen; i++)
8143 dcode[i] = swab32(dcode[i]);
8145 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
8147 ql_log(ql_log_fatal, vha, 0x008f,
8148 "-> Failed load firmware fragment %u.\n",
8150 return QLA_FUNCTION_FAILED;
8159 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8162 templates = (risc_attr & BIT_9) ? 2 : 1;
8163 ql_dbg(ql_dbg_init, vha, 0x0160, "-> templates = %u\n", templates);
8164 for (j = 0; j < templates; j++, fwdt++) {
8165 vfree(fwdt->template);
8166 fwdt->template = NULL;
8169 dcode = (uint32_t *)req->ring;
8170 qla24xx_read_flash_data(vha, dcode, faddr, 7);
8171 risc_size = be32_to_cpu((__force __be32)dcode[2]);
8172 ql_dbg(ql_dbg_init, vha, 0x0161,
8173 "-> fwdt%u template array at %#x (%#x dwords)\n",
8174 j, faddr, risc_size);
8175 if (!risc_size || !~risc_size) {
8176 ql_dbg(ql_dbg_init, vha, 0x0162,
8177 "-> fwdt%u failed to read array\n", j);
8181 /* skip header and ignore checksum */
8185 ql_dbg(ql_dbg_init, vha, 0x0163,
8186 "-> fwdt%u template allocate template %#x words...\n",
8188 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
8189 if (!fwdt->template) {
8190 ql_log(ql_log_warn, vha, 0x0164,
8191 "-> fwdt%u failed allocate template.\n", j);
8195 dcode = fwdt->template;
8196 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
8198 if (!qla27xx_fwdt_template_valid(dcode)) {
8199 ql_log(ql_log_warn, vha, 0x0165,
8200 "-> fwdt%u failed template validate\n", j);
8204 dlen = qla27xx_fwdt_template_size(dcode);
8205 ql_dbg(ql_dbg_init, vha, 0x0166,
8206 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8207 j, dlen, dlen / sizeof(*dcode));
8208 if (dlen > risc_size * sizeof(*dcode)) {
8209 ql_log(ql_log_warn, vha, 0x0167,
8210 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8211 j, dlen - risc_size * sizeof(*dcode));
8215 fwdt->length = dlen;
8216 ql_dbg(ql_dbg_init, vha, 0x0168,
8217 "-> fwdt%u loaded template ok\n", j);
8219 faddr += risc_size + 1;
8225 vfree(fwdt->template);
8226 fwdt->template = NULL;
8232 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
8235 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8241 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
8242 struct fw_blob *blob;
8243 struct qla_hw_data *ha = vha->hw;
8244 struct req_que *req = ha->req_q_map[0];
8246 /* Load firmware blob. */
8247 blob = qla2x00_request_firmware(vha);
8249 ql_log(ql_log_info, vha, 0x0083,
8250 "Firmware image unavailable.\n");
8251 ql_log(ql_log_info, vha, 0x0084,
8252 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
8253 return QLA_FUNCTION_FAILED;
8258 wcode = (uint16_t *)req->ring;
8260 fwcode = (__force __be16 *)blob->fw->data;
8263 /* Validate firmware image by checking version. */
8264 if (blob->fw->size < 8 * sizeof(uint16_t)) {
8265 ql_log(ql_log_fatal, vha, 0x0085,
8266 "Unable to verify integrity of firmware image (%zd).\n",
8268 goto fail_fw_integrity;
8270 for (i = 0; i < 4; i++)
8271 wcode[i] = be16_to_cpu(fwcode[i + 4]);
8272 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
8273 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
8274 wcode[2] == 0 && wcode[3] == 0)) {
8275 ql_log(ql_log_fatal, vha, 0x0086,
8276 "Unable to verify integrity of firmware image.\n");
8277 ql_log(ql_log_fatal, vha, 0x0087,
8278 "Firmware data: %04x %04x %04x %04x.\n",
8279 wcode[0], wcode[1], wcode[2], wcode[3]);
8280 goto fail_fw_integrity;
8284 while (*seg && rval == QLA_SUCCESS) {
8286 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
8287 risc_size = be16_to_cpu(fwcode[3]);
8289 /* Validate firmware image size. */
8290 fwclen += risc_size * sizeof(uint16_t);
8291 if (blob->fw->size < fwclen) {
8292 ql_log(ql_log_fatal, vha, 0x0088,
8293 "Unable to verify integrity of firmware image "
8294 "(%zd).\n", blob->fw->size);
8295 goto fail_fw_integrity;
8299 while (risc_size > 0 && rval == QLA_SUCCESS) {
8300 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
8301 if (wlen > risc_size)
8303 ql_dbg(ql_dbg_init, vha, 0x0089,
8304 "Loading risc segment@ risc addr %x number of "
8305 "words 0x%x.\n", risc_addr, wlen);
8307 for (i = 0; i < wlen; i++)
8308 wcode[i] = swab16((__force u32)fwcode[i]);
8310 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
8313 ql_log(ql_log_fatal, vha, 0x008a,
8314 "Failed to load segment %d of firmware.\n",
8331 return QLA_FUNCTION_FAILED;
8335 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8338 uint templates, segments, fragment;
8341 uint32_t risc_addr, risc_size, risc_attr = 0;
8344 struct fw_blob *blob;
8346 struct qla_hw_data *ha = vha->hw;
8347 struct req_que *req = ha->req_q_map[0];
8348 struct fwdt *fwdt = ha->fwdt;
8350 ql_dbg(ql_dbg_init, vha, 0x0090,
8351 "-> FW: Loading via request-firmware.\n");
8353 blob = qla2x00_request_firmware(vha);
8355 ql_log(ql_log_warn, vha, 0x0092,
8356 "-> Firmware file not found.\n");
8358 return QLA_FUNCTION_FAILED;
8361 fwcode = (__force __be32 *)blob->fw->data;
8362 dcode = (__force uint32_t *)fwcode;
8363 if (qla24xx_risc_firmware_invalid(dcode)) {
8364 ql_log(ql_log_fatal, vha, 0x0093,
8365 "Unable to verify integrity of firmware image (%zd).\n",
8367 ql_log(ql_log_fatal, vha, 0x0095,
8368 "Firmware data: %08x %08x %08x %08x.\n",
8369 dcode[0], dcode[1], dcode[2], dcode[3]);
8370 return QLA_FUNCTION_FAILED;
8373 dcode = (uint32_t *)req->ring;
8375 segments = FA_RISC_CODE_SEGMENTS;
8376 for (j = 0; j < segments; j++) {
8377 ql_dbg(ql_dbg_init, vha, 0x0096,
8378 "-> Loading segment %u...\n", j);
8379 risc_addr = be32_to_cpu(fwcode[2]);
8380 risc_size = be32_to_cpu(fwcode[3]);
8383 *srisc_addr = risc_addr;
8384 risc_attr = be32_to_cpu(fwcode[9]);
8387 dlen = ha->fw_transfer_size >> 2;
8388 for (fragment = 0; risc_size; fragment++) {
8389 if (dlen > risc_size)
8392 ql_dbg(ql_dbg_init, vha, 0x0097,
8393 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
8394 fragment, risc_addr,
8395 (uint32_t)(fwcode - (typeof(fwcode))blob->fw->data),
8398 for (i = 0; i < dlen; i++)
8399 dcode[i] = swab32((__force u32)fwcode[i]);
8401 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
8403 ql_log(ql_log_fatal, vha, 0x0098,
8404 "-> Failed load firmware fragment %u.\n",
8406 return QLA_FUNCTION_FAILED;
8415 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8418 templates = (risc_attr & BIT_9) ? 2 : 1;
8419 ql_dbg(ql_dbg_init, vha, 0x0170, "-> templates = %u\n", templates);
8420 for (j = 0; j < templates; j++, fwdt++) {
8421 vfree(fwdt->template);
8422 fwdt->template = NULL;
8425 risc_size = be32_to_cpu(fwcode[2]);
8426 ql_dbg(ql_dbg_init, vha, 0x0171,
8427 "-> fwdt%u template array at %#x (%#x dwords)\n",
8428 j, (uint32_t)((void *)fwcode - (void *)blob->fw->data),
8430 if (!risc_size || !~risc_size) {
8431 ql_dbg(ql_dbg_init, vha, 0x0172,
8432 "-> fwdt%u failed to read array\n", j);
8436 /* skip header and ignore checksum */
8440 ql_dbg(ql_dbg_init, vha, 0x0173,
8441 "-> fwdt%u template allocate template %#x words...\n",
8443 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
8444 if (!fwdt->template) {
8445 ql_log(ql_log_warn, vha, 0x0174,
8446 "-> fwdt%u failed allocate template.\n", j);
8450 dcode = fwdt->template;
8451 for (i = 0; i < risc_size; i++)
8452 dcode[i] = (__force u32)fwcode[i];
8454 if (!qla27xx_fwdt_template_valid(dcode)) {
8455 ql_log(ql_log_warn, vha, 0x0175,
8456 "-> fwdt%u failed template validate\n", j);
8460 dlen = qla27xx_fwdt_template_size(dcode);
8461 ql_dbg(ql_dbg_init, vha, 0x0176,
8462 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8463 j, dlen, dlen / sizeof(*dcode));
8464 if (dlen > risc_size * sizeof(*dcode)) {
8465 ql_log(ql_log_warn, vha, 0x0177,
8466 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8467 j, dlen - risc_size * sizeof(*dcode));
8471 fwdt->length = dlen;
8472 ql_dbg(ql_dbg_init, vha, 0x0178,
8473 "-> fwdt%u loaded template ok\n", j);
8475 fwcode += risc_size + 1;
8481 vfree(fwdt->template);
8482 fwdt->template = NULL;
8489 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8493 if (ql2xfwloadbin == 1)
8494 return qla81xx_load_risc(vha, srisc_addr);
8498 * 1) Firmware via request-firmware interface (.bin file).
8499 * 2) Firmware residing in flash.
8501 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8502 if (rval == QLA_SUCCESS)
8505 return qla24xx_load_risc_flash(vha, srisc_addr,
8506 vha->hw->flt_region_fw);
8510 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8513 struct qla_hw_data *ha = vha->hw;
8514 struct active_regions active_regions = { };
8516 if (ql2xfwloadbin == 2)
8519 /* FW Load priority:
8520 * 1) Firmware residing in flash.
8521 * 2) Firmware via request-firmware interface (.bin file).
8522 * 3) Golden-Firmware residing in flash -- (limited operation).
8525 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8526 goto try_primary_fw;
8528 qla27xx_get_active_image(vha, &active_regions);
8530 if (active_regions.global != QLA27XX_SECONDARY_IMAGE)
8531 goto try_primary_fw;
8533 ql_dbg(ql_dbg_init, vha, 0x008b,
8534 "Loading secondary firmware image.\n");
8535 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw_sec);
8540 ql_dbg(ql_dbg_init, vha, 0x008b,
8541 "Loading primary firmware image.\n");
8542 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
8547 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8548 if (!rval || !ha->flt_region_gold_fw)
8551 ql_log(ql_log_info, vha, 0x0099,
8552 "Attempting to fallback to golden firmware.\n");
8553 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
8557 ql_log(ql_log_info, vha, 0x009a, "Need firmware flash update.\n");
8558 ha->flags.running_gold_fw = 1;
8563 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
8566 struct qla_hw_data *ha = vha->hw;
8568 if (ha->flags.pci_channel_io_perm_failure)
8570 if (!IS_FWI2_CAPABLE(ha))
8572 if (!ha->fw_major_version)
8574 if (!ha->flags.fw_started)
8577 ret = qla2x00_stop_firmware(vha);
8578 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
8579 ret != QLA_INVALID_COMMAND && retries ; retries--) {
8580 ha->isp_ops->reset_chip(vha);
8581 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
8583 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
8585 ql_log(ql_log_info, vha, 0x8015,
8586 "Attempting retry of stop-firmware command.\n");
8587 ret = qla2x00_stop_firmware(vha);
8591 ha->flags.fw_init_done = 0;
8595 qla24xx_configure_vhba(scsi_qla_host_t *vha)
8597 int rval = QLA_SUCCESS;
8599 uint16_t mb[MAILBOX_REGISTER_COUNT];
8600 struct qla_hw_data *ha = vha->hw;
8601 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
8606 rval = qla2x00_fw_ready(base_vha);
8608 if (rval == QLA_SUCCESS) {
8609 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8610 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8613 vha->flags.management_server_logged_in = 0;
8615 /* Login to SNS first */
8616 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
8618 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
8619 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
8620 ql_dbg(ql_dbg_init, vha, 0x0120,
8621 "Failed SNS login: loop_id=%x, rval2=%d\n",
8624 ql_dbg(ql_dbg_init, vha, 0x0103,
8625 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
8626 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
8627 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
8628 return (QLA_FUNCTION_FAILED);
8631 atomic_set(&vha->loop_down_timer, 0);
8632 atomic_set(&vha->loop_state, LOOP_UP);
8633 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8634 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
8635 rval = qla2x00_loop_resync(base_vha);
8640 /* 84XX Support **************************************************************/
8642 static LIST_HEAD(qla_cs84xx_list);
8643 static DEFINE_MUTEX(qla_cs84xx_mutex);
8645 static struct qla_chip_state_84xx *
8646 qla84xx_get_chip(struct scsi_qla_host *vha)
8648 struct qla_chip_state_84xx *cs84xx;
8649 struct qla_hw_data *ha = vha->hw;
8651 mutex_lock(&qla_cs84xx_mutex);
8653 /* Find any shared 84xx chip. */
8654 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
8655 if (cs84xx->bus == ha->pdev->bus) {
8656 kref_get(&cs84xx->kref);
8661 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
8665 kref_init(&cs84xx->kref);
8666 spin_lock_init(&cs84xx->access_lock);
8667 mutex_init(&cs84xx->fw_update_mutex);
8668 cs84xx->bus = ha->pdev->bus;
8670 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
8672 mutex_unlock(&qla_cs84xx_mutex);
8677 __qla84xx_chip_release(struct kref *kref)
8679 struct qla_chip_state_84xx *cs84xx =
8680 container_of(kref, struct qla_chip_state_84xx, kref);
8682 mutex_lock(&qla_cs84xx_mutex);
8683 list_del(&cs84xx->list);
8684 mutex_unlock(&qla_cs84xx_mutex);
8689 qla84xx_put_chip(struct scsi_qla_host *vha)
8691 struct qla_hw_data *ha = vha->hw;
8694 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
8698 qla84xx_init_chip(scsi_qla_host_t *vha)
8702 struct qla_hw_data *ha = vha->hw;
8704 mutex_lock(&ha->cs84xx->fw_update_mutex);
8706 rval = qla84xx_verify_chip(vha, status);
8708 mutex_unlock(&ha->cs84xx->fw_update_mutex);
8710 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED :
8714 /* 81XX Support **************************************************************/
8717 qla81xx_nvram_config(scsi_qla_host_t *vha)
8720 struct init_cb_81xx *icb;
8721 struct nvram_81xx *nv;
8723 uint8_t *dptr1, *dptr2;
8726 struct qla_hw_data *ha = vha->hw;
8728 struct active_regions active_regions = { };
8731 icb = (struct init_cb_81xx *)ha->init_cb;
8734 /* Determine NVRAM starting address. */
8735 ha->nvram_size = sizeof(*nv);
8736 ha->vpd_size = FA_NVRAM_VPD_SIZE;
8737 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
8738 ha->vpd_size = FA_VPD_SIZE_82XX;
8740 if (IS_QLA28XX(ha) || IS_QLA27XX(ha))
8741 qla28xx_get_aux_images(vha, &active_regions);
8743 /* Get VPD data into cache */
8744 ha->vpd = ha->nvram + VPD_OFFSET;
8746 faddr = ha->flt_region_vpd;
8747 if (IS_QLA28XX(ha)) {
8748 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8749 faddr = ha->flt_region_vpd_sec;
8750 ql_dbg(ql_dbg_init, vha, 0x0110,
8751 "Loading %s nvram image.\n",
8752 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8753 "primary" : "secondary");
8755 ha->isp_ops->read_optrom(vha, ha->vpd, faddr << 2, ha->vpd_size);
8757 /* Get NVRAM data into cache and calculate checksum. */
8758 faddr = ha->flt_region_nvram;
8759 if (IS_QLA28XX(ha)) {
8760 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8761 faddr = ha->flt_region_nvram_sec;
8763 ql_dbg(ql_dbg_init, vha, 0x0110,
8764 "Loading %s nvram image.\n",
8765 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8766 "primary" : "secondary");
8767 ha->isp_ops->read_optrom(vha, ha->nvram, faddr << 2, ha->nvram_size);
8769 dptr = (__force __le32 *)nv;
8770 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
8771 chksum += le32_to_cpu(*dptr);
8773 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
8774 "Contents of NVRAM:\n");
8775 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
8776 nv, ha->nvram_size);
8778 /* Bad NVRAM data, set defaults parameters. */
8779 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
8780 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
8781 /* Reset NVRAM data. */
8782 ql_log(ql_log_info, vha, 0x0073,
8783 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
8784 chksum, nv->id, le16_to_cpu(nv->nvram_version));
8785 ql_dump_buffer(ql_dbg_init, vha, 0x0073, nv, sizeof(*nv));
8786 ql_log(ql_log_info, vha, 0x0074,
8787 "Falling back to functioning (yet invalid -- WWPN) "
8791 * Set default initialization control block.
8793 memset(nv, 0, ha->nvram_size);
8794 nv->nvram_version = cpu_to_le16(ICB_VERSION);
8795 nv->version = cpu_to_le16(ICB_VERSION);
8796 nv->frame_payload_size = cpu_to_le16(2048);
8797 nv->execution_throttle = cpu_to_le16(0xFFFF);
8798 nv->exchange_count = cpu_to_le16(0);
8799 nv->port_name[0] = 0x21;
8800 nv->port_name[1] = 0x00 + ha->port_no + 1;
8801 nv->port_name[2] = 0x00;
8802 nv->port_name[3] = 0xe0;
8803 nv->port_name[4] = 0x8b;
8804 nv->port_name[5] = 0x1c;
8805 nv->port_name[6] = 0x55;
8806 nv->port_name[7] = 0x86;
8807 nv->node_name[0] = 0x20;
8808 nv->node_name[1] = 0x00;
8809 nv->node_name[2] = 0x00;
8810 nv->node_name[3] = 0xe0;
8811 nv->node_name[4] = 0x8b;
8812 nv->node_name[5] = 0x1c;
8813 nv->node_name[6] = 0x55;
8814 nv->node_name[7] = 0x86;
8815 nv->login_retry_count = cpu_to_le16(8);
8816 nv->interrupt_delay_timer = cpu_to_le16(0);
8817 nv->login_timeout = cpu_to_le16(0);
8818 nv->firmware_options_1 =
8819 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
8820 nv->firmware_options_2 = cpu_to_le32(2 << 4);
8821 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
8822 nv->firmware_options_3 = cpu_to_le32(2 << 13);
8823 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
8824 nv->efi_parameters = cpu_to_le32(0);
8825 nv->reset_delay = 5;
8826 nv->max_luns_per_target = cpu_to_le16(128);
8827 nv->port_down_retry_count = cpu_to_le16(30);
8828 nv->link_down_timeout = cpu_to_le16(180);
8829 nv->enode_mac[0] = 0x00;
8830 nv->enode_mac[1] = 0xC0;
8831 nv->enode_mac[2] = 0xDD;
8832 nv->enode_mac[3] = 0x04;
8833 nv->enode_mac[4] = 0x05;
8834 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
8839 if (IS_T10_PI_CAPABLE(ha))
8840 nv->frame_payload_size &= cpu_to_le16(~7);
8842 qlt_81xx_config_nvram_stage1(vha, nv);
8844 /* Reset Initialization control block */
8845 memset(icb, 0, ha->init_cb_size);
8847 /* Copy 1st segment. */
8848 dptr1 = (uint8_t *)icb;
8849 dptr2 = (uint8_t *)&nv->version;
8850 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
8852 *dptr1++ = *dptr2++;
8854 icb->login_retry_count = nv->login_retry_count;
8856 /* Copy 2nd segment. */
8857 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
8858 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
8859 cnt = (uint8_t *)&icb->reserved_5 -
8860 (uint8_t *)&icb->interrupt_delay_timer;
8862 *dptr1++ = *dptr2++;
8864 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
8865 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8866 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
8867 icb->enode_mac[0] = 0x00;
8868 icb->enode_mac[1] = 0xC0;
8869 icb->enode_mac[2] = 0xDD;
8870 icb->enode_mac[3] = 0x04;
8871 icb->enode_mac[4] = 0x05;
8872 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
8875 /* Use extended-initialization control block. */
8876 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
8877 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
8879 * Setup driver NVRAM options.
8881 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
8884 qlt_81xx_config_nvram_stage2(vha, icb);
8886 /* Use alternate WWN? */
8887 if (nv->host_p & cpu_to_le32(BIT_15)) {
8888 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
8889 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
8892 /* Prepare nodename */
8893 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
8895 * Firmware will apply the following mask if the nodename was
8898 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
8899 icb->node_name[0] &= 0xF0;
8902 if (IS_QLA28XX(ha) || IS_QLA27XX(ha)) {
8903 if ((nv->enhanced_features & BIT_7) == 0)
8904 ha->flags.scm_supported_a = 1;
8907 /* Set host adapter parameters. */
8908 ha->flags.disable_risc_code_load = 0;
8909 ha->flags.enable_lip_reset = 0;
8910 ha->flags.enable_lip_full_login =
8911 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
8912 ha->flags.enable_target_reset =
8913 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
8914 ha->flags.enable_led_scheme = 0;
8915 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
8917 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
8918 (BIT_6 | BIT_5 | BIT_4)) >> 4;
8920 /* save HBA serial number */
8921 ha->serial0 = icb->port_name[5];
8922 ha->serial1 = icb->port_name[6];
8923 ha->serial2 = icb->port_name[7];
8924 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
8925 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
8927 icb->execution_throttle = cpu_to_le16(0xFFFF);
8929 ha->retry_count = le16_to_cpu(nv->login_retry_count);
8931 /* Set minimum login_timeout to 4 seconds. */
8932 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
8933 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
8934 if (le16_to_cpu(nv->login_timeout) < 4)
8935 nv->login_timeout = cpu_to_le16(4);
8936 ha->login_timeout = le16_to_cpu(nv->login_timeout);
8938 /* Set minimum RATOV to 100 tenths of a second. */
8941 ha->loop_reset_delay = nv->reset_delay;
8943 /* Link Down Timeout = 0:
8945 * When Port Down timer expires we will start returning
8946 * I/O's to OS with "DID_NO_CONNECT".
8948 * Link Down Timeout != 0:
8950 * The driver waits for the link to come up after link down
8951 * before returning I/Os to OS with "DID_NO_CONNECT".
8953 if (le16_to_cpu(nv->link_down_timeout) == 0) {
8954 ha->loop_down_abort_time =
8955 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
8957 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
8958 ha->loop_down_abort_time =
8959 (LOOP_DOWN_TIME - ha->link_down_timeout);
8962 /* Need enough time to try and get the port back. */
8963 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8964 if (qlport_down_retry)
8965 ha->port_down_retry_count = qlport_down_retry;
8967 /* Set login_retry_count */
8968 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8969 if (ha->port_down_retry_count ==
8970 le16_to_cpu(nv->port_down_retry_count) &&
8971 ha->port_down_retry_count > 3)
8972 ha->login_retry_count = ha->port_down_retry_count;
8973 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8974 ha->login_retry_count = ha->port_down_retry_count;
8975 if (ql2xloginretrycount)
8976 ha->login_retry_count = ql2xloginretrycount;
8978 /* if not running MSI-X we need handshaking on interrupts */
8979 if (!vha->hw->flags.msix_enabled &&
8980 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)))
8981 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
8984 if (!vha->flags.init_done) {
8985 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8986 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8987 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8988 le16_to_cpu(icb->interrupt_delay_timer) : 2;
8990 icb->firmware_options_2 &= cpu_to_le32(
8991 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8992 vha->flags.process_response_queue = 0;
8993 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8994 ha->zio_mode = QLA_ZIO_MODE_6;
8996 ql_log(ql_log_info, vha, 0x0075,
8997 "ZIO mode %d enabled; timer delay (%d us).\n",
8999 ha->zio_timer * 100);
9001 icb->firmware_options_2 |= cpu_to_le32(
9002 (uint32_t)ha->zio_mode);
9003 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
9004 vha->flags.process_response_queue = 1;
9007 /* enable RIDA Format2 */
9008 icb->firmware_options_3 |= cpu_to_le32(BIT_0);
9010 /* N2N: driver will initiate Login instead of FW */
9011 icb->firmware_options_3 |= cpu_to_le32(BIT_8);
9013 /* Determine NVMe/FCP priority for target ports */
9014 ha->fc4_type_priority = qla2xxx_get_fc4_priority(vha);
9017 ql_log(ql_log_warn, vha, 0x0076,
9018 "NVRAM configuration failed.\n");
9024 qla82xx_restart_isp(scsi_qla_host_t *vha)
9027 struct qla_hw_data *ha = vha->hw;
9028 struct scsi_qla_host *vp, *tvp;
9029 unsigned long flags;
9031 status = qla2x00_init_rings(vha);
9033 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
9034 ha->flags.chip_reset_done = 1;
9036 status = qla2x00_fw_ready(vha);
9038 /* Issue a marker after FW becomes ready. */
9039 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
9040 vha->flags.online = 1;
9041 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
9044 /* if no cable then assume it's good */
9045 if ((vha->device_flags & DFLG_NO_CABLE))
9050 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
9052 if (!atomic_read(&vha->loop_down_timer)) {
9054 * Issue marker command only when we are going
9055 * to start the I/O .
9057 vha->marker_needed = 1;
9060 ha->isp_ops->enable_intrs(ha);
9062 ha->isp_abort_cnt = 0;
9063 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
9065 /* Update the firmware version */
9066 status = qla82xx_check_md_needed(vha);
9069 ha->flags.fce_enabled = 1;
9071 fce_calc_size(ha->fce_bufs));
9072 rval = qla2x00_enable_fce_trace(vha,
9073 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
9076 ql_log(ql_log_warn, vha, 0x8001,
9077 "Unable to reinitialize FCE (%d).\n",
9079 ha->flags.fce_enabled = 0;
9084 memset(ha->eft, 0, EFT_SIZE);
9085 rval = qla2x00_enable_eft_trace(vha,
9086 ha->eft_dma, EFT_NUM_BUFFERS);
9088 ql_log(ql_log_warn, vha, 0x8010,
9089 "Unable to reinitialize EFT (%d).\n",
9096 ql_dbg(ql_dbg_taskm, vha, 0x8011,
9097 "qla82xx_restart_isp succeeded.\n");
9099 spin_lock_irqsave(&ha->vport_slock, flags);
9100 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
9102 atomic_inc(&vp->vref_count);
9103 spin_unlock_irqrestore(&ha->vport_slock, flags);
9105 qla2x00_vp_abort_isp(vp);
9107 spin_lock_irqsave(&ha->vport_slock, flags);
9108 atomic_dec(&vp->vref_count);
9111 spin_unlock_irqrestore(&ha->vport_slock, flags);
9114 ql_log(ql_log_warn, vha, 0x8016,
9115 "qla82xx_restart_isp **** FAILED ****.\n");
9122 * qla24xx_get_fcp_prio
9123 * Gets the fcp cmd priority value for the logged in port.
9124 * Looks for a match of the port descriptors within
9125 * each of the fcp prio config entries. If a match is found,
9126 * the tag (priority) value is returned.
9129 * vha = scsi host structure pointer.
9130 * fcport = port structure pointer.
9133 * non-zero (if found)
9140 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
9143 uint8_t pid_match, wwn_match;
9145 uint32_t pid1, pid2;
9146 uint64_t wwn1, wwn2;
9147 struct qla_fcp_prio_entry *pri_entry;
9148 struct qla_hw_data *ha = vha->hw;
9150 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
9154 entries = ha->fcp_prio_cfg->num_entries;
9155 pri_entry = &ha->fcp_prio_cfg->entry[0];
9157 for (i = 0; i < entries; i++) {
9158 pid_match = wwn_match = 0;
9160 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
9165 /* check source pid for a match */
9166 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
9167 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
9168 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
9169 if (pid1 == INVALID_PORT_ID)
9171 else if (pid1 == pid2)
9175 /* check destination pid for a match */
9176 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
9177 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
9178 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
9179 if (pid1 == INVALID_PORT_ID)
9181 else if (pid1 == pid2)
9185 /* check source WWN for a match */
9186 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
9187 wwn1 = wwn_to_u64(vha->port_name);
9188 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
9189 if (wwn2 == (uint64_t)-1)
9191 else if (wwn1 == wwn2)
9195 /* check destination WWN for a match */
9196 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
9197 wwn1 = wwn_to_u64(fcport->port_name);
9198 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
9199 if (wwn2 == (uint64_t)-1)
9201 else if (wwn1 == wwn2)
9205 if (pid_match == 2 || wwn_match == 2) {
9206 /* Found a matching entry */
9207 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
9208 priority = pri_entry->tag;
9219 * qla24xx_update_fcport_fcp_prio
9220 * Activates fcp priority for the logged in fc port
9223 * vha = scsi host structure pointer.
9224 * fcp = port structure pointer.
9227 * QLA_SUCCESS or QLA_FUNCTION_FAILED
9233 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
9239 if (fcport->port_type != FCT_TARGET ||
9240 fcport->loop_id == FC_NO_LOOP_ID)
9241 return QLA_FUNCTION_FAILED;
9243 priority = qla24xx_get_fcp_prio(vha, fcport);
9245 return QLA_FUNCTION_FAILED;
9247 if (IS_P3P_TYPE(vha->hw)) {
9248 fcport->fcp_prio = priority & 0xf;
9252 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
9253 if (ret == QLA_SUCCESS) {
9254 if (fcport->fcp_prio != priority)
9255 ql_dbg(ql_dbg_user, vha, 0x709e,
9256 "Updated FCP_CMND priority - value=%d loop_id=%d "
9257 "port_id=%02x%02x%02x.\n", priority,
9258 fcport->loop_id, fcport->d_id.b.domain,
9259 fcport->d_id.b.area, fcport->d_id.b.al_pa);
9260 fcport->fcp_prio = priority & 0xf;
9262 ql_dbg(ql_dbg_user, vha, 0x704f,
9263 "Unable to update FCP_CMND priority - ret=0x%x for "
9264 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
9265 fcport->d_id.b.domain, fcport->d_id.b.area,
9266 fcport->d_id.b.al_pa);
9271 * qla24xx_update_all_fcp_prio
9272 * Activates fcp priority for all the logged in ports
9275 * ha = adapter block pointer.
9278 * QLA_SUCCESS or QLA_FUNCTION_FAILED
9284 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
9289 ret = QLA_FUNCTION_FAILED;
9290 /* We need to set priority for all logged in ports */
9291 list_for_each_entry(fcport, &vha->vp_fcports, list)
9292 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
9297 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
9298 int vp_idx, bool startqp)
9303 struct qla_hw_data *ha = vha->hw;
9304 uint16_t qpair_id = 0;
9305 struct qla_qpair *qpair = NULL;
9306 struct qla_msix_entry *msix;
9308 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
9309 ql_log(ql_log_warn, vha, 0x00181,
9310 "FW/Driver is not multi-queue capable.\n");
9314 if (ql2xmqsupport || ql2xnvmeenable) {
9315 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
9316 if (qpair == NULL) {
9317 ql_log(ql_log_warn, vha, 0x0182,
9318 "Failed to allocate memory for queue pair.\n");
9322 qpair->hw = vha->hw;
9324 qpair->qp_lock_ptr = &qpair->qp_lock;
9325 spin_lock_init(&qpair->qp_lock);
9326 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
9328 /* Assign available que pair id */
9329 mutex_lock(&ha->mq_lock);
9330 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
9331 if (ha->num_qpairs >= ha->max_qpairs) {
9332 mutex_unlock(&ha->mq_lock);
9333 ql_log(ql_log_warn, vha, 0x0183,
9334 "No resources to create additional q pair.\n");
9338 set_bit(qpair_id, ha->qpair_qid_map);
9339 ha->queue_pair_map[qpair_id] = qpair;
9340 qpair->id = qpair_id;
9341 qpair->vp_idx = vp_idx;
9342 qpair->fw_started = ha->flags.fw_started;
9343 INIT_LIST_HEAD(&qpair->hints_list);
9344 qpair->chip_reset = ha->base_qpair->chip_reset;
9345 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
9346 qpair->enable_explicit_conf =
9347 ha->base_qpair->enable_explicit_conf;
9349 for (i = 0; i < ha->msix_count; i++) {
9350 msix = &ha->msix_entries[i];
9354 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
9355 "Vector %x selected for qpair\n", msix->vector);
9359 ql_log(ql_log_warn, vha, 0x0184,
9360 "Out of MSI-X vectors!.\n");
9364 qpair->msix->in_use = 1;
9365 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
9366 qpair->pdev = ha->pdev;
9367 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
9368 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
9370 mutex_unlock(&ha->mq_lock);
9372 /* Create response queue first */
9373 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
9375 ql_log(ql_log_warn, vha, 0x0185,
9376 "Failed to create response queue.\n");
9380 qpair->rsp = ha->rsp_q_map[rsp_id];
9382 /* Create request queue */
9383 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
9386 ql_log(ql_log_warn, vha, 0x0186,
9387 "Failed to create request queue.\n");
9391 qpair->req = ha->req_q_map[req_id];
9392 qpair->rsp->req = qpair->req;
9393 qpair->rsp->qpair = qpair;
9394 /* init qpair to this cpu. Will adjust at run time. */
9395 qla_cpu_update(qpair, smp_processor_id());
9397 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
9398 if (ha->fw_attributes & BIT_4)
9399 qpair->difdix_supported = 1;
9402 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
9403 if (!qpair->srb_mempool) {
9404 ql_log(ql_log_warn, vha, 0xd036,
9405 "Failed to create srb mempool for qpair %d\n",
9410 /* Mark as online */
9413 if (!vha->flags.qpairs_available)
9414 vha->flags.qpairs_available = 1;
9416 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
9417 "Request/Response queue pair created, id %d\n",
9419 ql_dbg(ql_dbg_init, vha, 0x0187,
9420 "Request/Response queue pair created, id %d\n",
9427 qla25xx_delete_rsp_que(vha, qpair->rsp);
9429 mutex_lock(&ha->mq_lock);
9430 qpair->msix->in_use = 0;
9431 list_del(&qpair->qp_list_elem);
9432 if (list_empty(&vha->qp_list))
9433 vha->flags.qpairs_available = 0;
9435 ha->queue_pair_map[qpair_id] = NULL;
9436 clear_bit(qpair_id, ha->qpair_qid_map);
9438 mutex_unlock(&ha->mq_lock);
9444 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
9446 int ret = QLA_FUNCTION_FAILED;
9447 struct qla_hw_data *ha = qpair->hw;
9449 qpair->delete_in_progress = 1;
9451 ret = qla25xx_delete_req_que(vha, qpair->req);
9452 if (ret != QLA_SUCCESS)
9455 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
9456 if (ret != QLA_SUCCESS)
9459 mutex_lock(&ha->mq_lock);
9460 ha->queue_pair_map[qpair->id] = NULL;
9461 clear_bit(qpair->id, ha->qpair_qid_map);
9463 list_del(&qpair->qp_list_elem);
9464 if (list_empty(&vha->qp_list)) {
9465 vha->flags.qpairs_available = 0;
9466 vha->flags.qpairs_req_created = 0;
9467 vha->flags.qpairs_rsp_created = 0;
9469 mempool_destroy(qpair->srb_mempool);
9471 mutex_unlock(&ha->mq_lock);
9479 qla2x00_count_set_bits(uint32_t num)
9481 /* Brian Kernighan's Algorithm */
9492 qla2x00_get_num_tgts(scsi_qla_host_t *vha)
9500 list_for_each_entry_safe(f, tf, &vha->vp_fcports, list) {
9501 if (f->port_type != FCT_TARGET)
9508 int qla2xxx_reset_stats(struct Scsi_Host *host, u32 flags)
9510 scsi_qla_host_t *vha = shost_priv(host);
9511 fc_port_t *fcport = NULL;
9512 unsigned long int_flags;
9514 if (flags & QLA2XX_HW_ERROR)
9515 vha->hw_err_cnt = 0;
9516 if (flags & QLA2XX_SHT_LNK_DWN)
9517 vha->short_link_down_cnt = 0;
9518 if (flags & QLA2XX_INT_ERR)
9519 vha->interface_err_cnt = 0;
9520 if (flags & QLA2XX_CMD_TIMEOUT)
9521 vha->cmd_timeout_cnt = 0;
9522 if (flags & QLA2XX_RESET_CMD_ERR)
9523 vha->reset_cmd_err_cnt = 0;
9524 if (flags & QLA2XX_TGT_SHT_LNK_DOWN) {
9525 spin_lock_irqsave(&vha->hw->tgt.sess_lock, int_flags);
9526 list_for_each_entry(fcport, &vha->vp_fcports, list) {
9527 fcport->tgt_short_link_down_cnt = 0;
9528 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
9530 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, int_flags);
9532 vha->link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
9536 int qla2xxx_start_stats(struct Scsi_Host *host, u32 flags)
9538 return qla2xxx_reset_stats(host, flags);
9541 int qla2xxx_stop_stats(struct Scsi_Host *host, u32 flags)
9543 return qla2xxx_reset_stats(host, flags);
9546 int qla2xxx_get_ini_stats(struct Scsi_Host *host, u32 flags,
9547 void *data, u64 size)
9549 scsi_qla_host_t *vha = shost_priv(host);
9550 struct ql_vnd_host_stats_resp *resp = (struct ql_vnd_host_stats_resp *)data;
9551 struct ql_vnd_stats *rsp_data = &resp->stats;
9552 u64 ini_entry_count = 0;
9554 u64 entry_count = 0;
9556 u32 tmp_stat_type = 0;
9557 fc_port_t *fcport = NULL;
9558 unsigned long int_flags;
9560 /* Copy stat type to work on it */
9561 tmp_stat_type = flags;
9563 if (tmp_stat_type & BIT_17) {
9564 num_tgt = qla2x00_get_num_tgts(vha);
9566 tmp_stat_type &= ~(1 << 17);
9568 ini_entry_count = qla2x00_count_set_bits(tmp_stat_type);
9570 entry_count = ini_entry_count + num_tgt;
9572 rsp_data->entry_count = entry_count;
9575 if (flags & QLA2XX_HW_ERROR) {
9576 rsp_data->entry[i].stat_type = QLA2XX_HW_ERROR;
9577 rsp_data->entry[i].tgt_num = 0x0;
9578 rsp_data->entry[i].cnt = vha->hw_err_cnt;
9582 if (flags & QLA2XX_SHT_LNK_DWN) {
9583 rsp_data->entry[i].stat_type = QLA2XX_SHT_LNK_DWN;
9584 rsp_data->entry[i].tgt_num = 0x0;
9585 rsp_data->entry[i].cnt = vha->short_link_down_cnt;
9589 if (flags & QLA2XX_INT_ERR) {
9590 rsp_data->entry[i].stat_type = QLA2XX_INT_ERR;
9591 rsp_data->entry[i].tgt_num = 0x0;
9592 rsp_data->entry[i].cnt = vha->interface_err_cnt;
9596 if (flags & QLA2XX_CMD_TIMEOUT) {
9597 rsp_data->entry[i].stat_type = QLA2XX_CMD_TIMEOUT;
9598 rsp_data->entry[i].tgt_num = 0x0;
9599 rsp_data->entry[i].cnt = vha->cmd_timeout_cnt;
9603 if (flags & QLA2XX_RESET_CMD_ERR) {
9604 rsp_data->entry[i].stat_type = QLA2XX_RESET_CMD_ERR;
9605 rsp_data->entry[i].tgt_num = 0x0;
9606 rsp_data->entry[i].cnt = vha->reset_cmd_err_cnt;
9610 /* i will continue from previous loop, as target
9611 * entries are after initiator
9613 if (flags & QLA2XX_TGT_SHT_LNK_DOWN) {
9614 spin_lock_irqsave(&vha->hw->tgt.sess_lock, int_flags);
9615 list_for_each_entry(fcport, &vha->vp_fcports, list) {
9616 if (fcport->port_type != FCT_TARGET)
9620 rsp_data->entry[i].stat_type = QLA2XX_TGT_SHT_LNK_DOWN;
9621 rsp_data->entry[i].tgt_num = fcport->rport->number;
9622 rsp_data->entry[i].cnt = fcport->tgt_short_link_down_cnt;
9625 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, int_flags);
9627 resp->status = EXT_STATUS_OK;
9632 int qla2xxx_get_tgt_stats(struct Scsi_Host *host, u32 flags,
9633 struct fc_rport *rport, void *data, u64 size)
9635 struct ql_vnd_tgt_stats_resp *tgt_data = data;
9636 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
9638 tgt_data->status = 0;
9639 tgt_data->stats.entry_count = 1;
9640 tgt_data->stats.entry[0].stat_type = flags;
9641 tgt_data->stats.entry[0].tgt_num = rport->number;
9642 tgt_data->stats.entry[0].cnt = fcport->tgt_short_link_down_cnt;
9647 int qla2xxx_disable_port(struct Scsi_Host *host)
9649 scsi_qla_host_t *vha = shost_priv(host);
9651 vha->hw->flags.port_isolated = 1;
9653 if (qla2x00_chip_is_down(vha))
9656 if (vha->flags.online) {
9657 qla2x00_abort_isp_cleanup(vha);
9658 qla2x00_wait_for_sess_deletion(vha);
9664 int qla2xxx_enable_port(struct Scsi_Host *host)
9666 scsi_qla_host_t *vha = shost_priv(host);
9668 vha->hw->flags.port_isolated = 0;
9669 /* Set the flag to 1, so that isp_abort can proceed */
9670 vha->flags.online = 1;
9671 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
9672 qla2xxx_wake_dpc(vha);