1 // SPDX-License-Identifier: GPL-2.0-only
3 * QLogic Fibre Channel HBA Driver
4 * Copyright (c) 2003-2014 QLogic Corporation
9 #include <linux/delay.h>
10 #include <linux/slab.h>
11 #include <linux/vmalloc.h>
13 #include "qla_devtbl.h"
19 #include "qla_target.h"
22 * QLogic ISP2x00 Hardware Support Function Prototypes.
24 static int qla2x00_isp_firmware(scsi_qla_host_t *);
25 static int qla2x00_setup_chip(scsi_qla_host_t *);
26 static int qla2x00_fw_ready(scsi_qla_host_t *);
27 static int qla2x00_configure_hba(scsi_qla_host_t *);
28 static int qla2x00_configure_loop(scsi_qla_host_t *);
29 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
30 static int qla2x00_configure_fabric(scsi_qla_host_t *);
31 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *);
32 static int qla2x00_restart_isp(scsi_qla_host_t *);
34 static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
35 static int qla84xx_init_chip(scsi_qla_host_t *);
36 static int qla25xx_init_queues(struct qla_hw_data *);
37 static void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha,
38 struct event_arg *ea);
39 static void qla24xx_handle_prli_done_event(struct scsi_qla_host *,
41 static void __qla24xx_handle_gpdb_event(scsi_qla_host_t *, struct event_arg *);
43 /* SRB Extensions ---------------------------------------------------------- */
46 qla2x00_sp_timeout(struct timer_list *t)
48 srb_t *sp = from_timer(sp, t, u.iocb_cmd.timer);
49 struct srb_iocb *iocb;
50 scsi_qla_host_t *vha = sp->vha;
52 WARN_ON(irqs_disabled());
53 iocb = &sp->u.iocb_cmd;
57 kref_put(&sp->cmd_kref, qla2x00_sp_release);
59 if (vha && qla2x00_isp_reg_stat(vha->hw)) {
60 ql_log(ql_log_info, vha, 0x9008,
61 "PCI/Register disconnect.\n");
62 qla_pci_set_eeh_busy(vha);
66 void qla2x00_sp_free(srb_t *sp)
68 struct srb_iocb *iocb = &sp->u.iocb_cmd;
70 del_timer(&iocb->timer);
74 void qla2xxx_rel_done_warning(srb_t *sp, int res)
76 WARN_ONCE(1, "Calling done() of an already freed srb %p object\n", sp);
79 void qla2xxx_rel_free_warning(srb_t *sp)
81 WARN_ONCE(1, "Calling free() of an already freed srb %p object\n", sp);
84 /* Asynchronous Login/Logout Routines -------------------------------------- */
87 qla2x00_get_async_timeout(struct scsi_qla_host *vha)
90 struct qla_hw_data *ha = vha->hw;
92 /* Firmware should use switch negotiated r_a_tov for timeout. */
93 tmo = ha->r_a_tov / 10 * 2;
95 tmo = FX00_DEF_RATOV * 2;
96 } else if (!IS_FWI2_CAPABLE(ha)) {
98 * Except for earlier ISPs where the timeout is seeded from the
99 * initialization control block.
101 tmo = ha->login_timeout;
106 static void qla24xx_abort_iocb_timeout(void *data)
109 struct srb_iocb *abt = &sp->u.iocb_cmd;
110 struct qla_qpair *qpair = sp->qpair;
113 int sp_found = 0, cmdsp_found = 0;
116 ql_dbg(ql_dbg_async, sp->vha, 0x507c,
117 "Abort timeout - cmd hdl=%x, cmd type=%x hdl=%x, type=%x\n",
118 sp->cmd_sp->handle, sp->cmd_sp->type,
119 sp->handle, sp->type);
121 ql_dbg(ql_dbg_async, sp->vha, 0x507c,
122 "Abort timeout 2 - hdl=%x, type=%x\n",
123 sp->handle, sp->type);
125 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
126 for (handle = 1; handle < qpair->req->num_outstanding_cmds; handle++) {
127 if (sp->cmd_sp && (qpair->req->outstanding_cmds[handle] ==
129 qpair->req->outstanding_cmds[handle] = NULL;
131 qla_put_fw_resources(qpair, &sp->cmd_sp->iores);
134 /* removing the abort */
135 if (qpair->req->outstanding_cmds[handle] == sp) {
136 qpair->req->outstanding_cmds[handle] = NULL;
138 qla_put_fw_resources(qpair, &sp->iores);
142 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
144 if (cmdsp_found && sp->cmd_sp) {
146 * This done function should take care of
147 * original command ref: INIT
149 sp->cmd_sp->done(sp->cmd_sp, QLA_OS_TIMER_EXPIRED);
153 abt->u.abt.comp_status = cpu_to_le16(CS_TIMEOUT);
154 sp->done(sp, QLA_OS_TIMER_EXPIRED);
158 static void qla24xx_abort_sp_done(srb_t *sp, int res)
160 struct srb_iocb *abt = &sp->u.iocb_cmd;
161 srb_t *orig_sp = sp->cmd_sp;
164 qla_wait_nvme_release_cmd_kref(orig_sp);
166 if (sp->flags & SRB_WAKEUP_ON_COMP)
167 complete(&abt->u.abt.comp);
170 kref_put(&sp->cmd_kref, qla2x00_sp_release);
173 int qla24xx_async_abort_cmd(srb_t *cmd_sp, bool wait)
175 scsi_qla_host_t *vha = cmd_sp->vha;
176 struct srb_iocb *abt_iocb;
178 int rval = QLA_FUNCTION_FAILED;
180 /* ref: INIT for ABTS command */
181 sp = qla2xxx_get_qpair_sp(cmd_sp->vha, cmd_sp->qpair, cmd_sp->fcport,
184 return QLA_MEMORY_ALLOC_FAILED;
186 qla_vha_mark_busy(vha);
187 abt_iocb = &sp->u.iocb_cmd;
188 sp->type = SRB_ABT_CMD;
190 sp->qpair = cmd_sp->qpair;
193 sp->flags = SRB_WAKEUP_ON_COMP;
195 init_completion(&abt_iocb->u.abt.comp);
196 /* FW can send 2 x ABTS's timeout/20s */
197 qla2x00_init_async_sp(sp, 42, qla24xx_abort_sp_done);
198 sp->u.iocb_cmd.timeout = qla24xx_abort_iocb_timeout;
200 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
201 abt_iocb->u.abt.req_que_no = cpu_to_le16(cmd_sp->qpair->req->id);
203 ql_dbg(ql_dbg_async, vha, 0x507c,
204 "Abort command issued - hdl=%x, type=%x\n", cmd_sp->handle,
207 rval = qla2x00_start_sp(sp);
208 if (rval != QLA_SUCCESS) {
210 kref_put(&sp->cmd_kref, qla2x00_sp_release);
215 wait_for_completion(&abt_iocb->u.abt.comp);
216 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
217 QLA_SUCCESS : QLA_ERR_FROM_FW;
219 kref_put(&sp->cmd_kref, qla2x00_sp_release);
226 qla2x00_async_iocb_timeout(void *data)
229 fc_port_t *fcport = sp->fcport;
230 struct srb_iocb *lio = &sp->u.iocb_cmd;
235 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
236 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
237 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
239 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
241 pr_info("Async-%s timeout - hdl=%x.\n",
242 sp->name, sp->handle);
247 rc = qla24xx_async_abort_cmd(sp, false);
249 /* Retry as needed. */
250 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
251 lio->u.logio.data[1] =
252 lio->u.logio.flags & SRB_LOGIN_RETRIED ?
253 QLA_LOGIO_LOGIN_RETRIED : 0;
254 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
255 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
257 if (sp->qpair->req->outstanding_cmds[h] ==
259 sp->qpair->req->outstanding_cmds[h] =
264 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
265 sp->done(sp, QLA_FUNCTION_TIMEOUT);
269 case SRB_CT_PTHRU_CMD:
276 rc = qla24xx_async_abort_cmd(sp, false);
278 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
279 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
281 if (sp->qpair->req->outstanding_cmds[h] ==
283 sp->qpair->req->outstanding_cmds[h] =
288 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
289 sp->done(sp, QLA_FUNCTION_TIMEOUT);
295 static void qla2x00_async_login_sp_done(srb_t *sp, int res)
297 struct scsi_qla_host *vha = sp->vha;
298 struct srb_iocb *lio = &sp->u.iocb_cmd;
301 ql_dbg(ql_dbg_disc, vha, 0x20dd,
302 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
304 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
306 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
307 memset(&ea, 0, sizeof(ea));
308 ea.fcport = sp->fcport;
309 ea.data[0] = lio->u.logio.data[0];
310 ea.data[1] = lio->u.logio.data[1];
311 ea.iop[0] = lio->u.logio.iop[0];
312 ea.iop[1] = lio->u.logio.iop[1];
315 ea.data[0] = MBS_COMMAND_ERROR;
316 qla24xx_handle_plogi_done_event(vha, &ea);
320 kref_put(&sp->cmd_kref, qla2x00_sp_release);
324 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
328 struct srb_iocb *lio;
329 int rval = QLA_FUNCTION_FAILED;
331 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
332 fcport->loop_id == FC_NO_LOOP_ID) {
333 ql_log(ql_log_warn, vha, 0xffff,
334 "%s: %8phC - not sending command.\n",
335 __func__, fcport->port_name);
340 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
344 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_PEND);
345 fcport->flags |= FCF_ASYNC_SENT;
346 fcport->logout_completed = 0;
348 sp->type = SRB_LOGIN_CMD;
350 sp->gen1 = fcport->rscn_gen;
351 sp->gen2 = fcport->login_gen;
352 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
353 qla2x00_async_login_sp_done);
355 lio = &sp->u.iocb_cmd;
356 if (N2N_TOPO(fcport->vha->hw) && fcport_is_bigger(fcport)) {
357 lio->u.logio.flags |= SRB_LOGIN_PRLI_ONLY;
359 if (vha->hw->flags.edif_enabled &&
361 lio->u.logio.flags |=
362 (SRB_LOGIN_FCSP | SRB_LOGIN_SKIP_PRLI);
364 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
368 if (NVME_TARGET(vha->hw, fcport))
369 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
371 rval = qla2x00_start_sp(sp);
373 ql_dbg(ql_dbg_disc, vha, 0x2072,
374 "Async-login - %8phC hdl=%x, loopid=%x portid=%06x retries=%d %s.\n",
375 fcport->port_name, sp->handle, fcport->loop_id,
376 fcport->d_id.b24, fcport->login_retry,
377 lio->u.logio.flags & SRB_LOGIN_FCSP ? "FCSP" : "");
379 if (rval != QLA_SUCCESS) {
380 fcport->flags |= FCF_LOGIN_NEEDED;
381 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
389 kref_put(&sp->cmd_kref, qla2x00_sp_release);
390 fcport->flags &= ~FCF_ASYNC_SENT;
392 fcport->flags &= ~FCF_ASYNC_ACTIVE;
395 * async login failed. Could be due to iocb/exchange resource
396 * being low. Set state DELETED for re-login process to start again.
398 qla2x00_set_fcport_disc_state(fcport, DSC_DELETED);
402 static void qla2x00_async_logout_sp_done(srb_t *sp, int res)
404 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
405 sp->fcport->login_gen++;
406 qlt_logo_completion_handler(sp->fcport, sp->u.iocb_cmd.u.logio.data[0]);
408 kref_put(&sp->cmd_kref, qla2x00_sp_release);
412 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
415 int rval = QLA_FUNCTION_FAILED;
417 fcport->flags |= FCF_ASYNC_SENT;
419 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
423 sp->type = SRB_LOGOUT_CMD;
425 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
426 qla2x00_async_logout_sp_done),
428 ql_dbg(ql_dbg_disc, vha, 0x2070,
429 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC explicit %d.\n",
430 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
431 fcport->d_id.b.area, fcport->d_id.b.al_pa,
432 fcport->port_name, fcport->explicit_logout);
434 rval = qla2x00_start_sp(sp);
435 if (rval != QLA_SUCCESS)
441 kref_put(&sp->cmd_kref, qla2x00_sp_release);
443 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
448 qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
451 fcport->flags &= ~FCF_ASYNC_ACTIVE;
452 /* Don't re-login in target mode */
453 if (!fcport->tgt_session)
454 qla2x00_mark_device_lost(vha, fcport, 1);
455 qlt_logo_completion_handler(fcport, data[0]);
458 static void qla2x00_async_prlo_sp_done(srb_t *sp, int res)
460 struct srb_iocb *lio = &sp->u.iocb_cmd;
461 struct scsi_qla_host *vha = sp->vha;
463 sp->fcport->flags &= ~FCF_ASYNC_ACTIVE;
464 if (!test_bit(UNLOADING, &vha->dpc_flags))
465 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
468 kref_put(&sp->cmd_kref, qla2x00_sp_release);
472 qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
477 rval = QLA_FUNCTION_FAILED;
479 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
483 sp->type = SRB_PRLO_CMD;
485 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
486 qla2x00_async_prlo_sp_done);
488 ql_dbg(ql_dbg_disc, vha, 0x2070,
489 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
490 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
491 fcport->d_id.b.area, fcport->d_id.b.al_pa);
493 rval = qla2x00_start_sp(sp);
494 if (rval != QLA_SUCCESS)
501 kref_put(&sp->cmd_kref, qla2x00_sp_release);
503 fcport->flags &= ~FCF_ASYNC_ACTIVE;
508 void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
510 struct fc_port *fcport = ea->fcport;
513 ql_dbg(ql_dbg_disc, vha, 0x20d2,
514 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
515 __func__, fcport->port_name, fcport->disc_state,
516 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
517 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
519 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
522 if (ea->data[0] != MBS_COMMAND_COMPLETE) {
523 ql_dbg(ql_dbg_disc, vha, 0x2066,
524 "%s %8phC: adisc fail: post delete\n",
525 __func__, ea->fcport->port_name);
527 spin_lock_irqsave(&vha->work_lock, flags);
528 /* deleted = 0 & logout_on_delete = force fw cleanup */
529 if (fcport->deleted == QLA_SESS_DELETED)
532 fcport->logout_on_delete = 1;
533 spin_unlock_irqrestore(&vha->work_lock, flags);
535 qlt_schedule_sess_for_deletion(ea->fcport);
539 if (ea->fcport->disc_state == DSC_DELETE_PEND)
542 if (ea->sp->gen2 != ea->fcport->login_gen) {
543 /* target side must have changed it. */
544 ql_dbg(ql_dbg_disc, vha, 0x20d3,
545 "%s %8phC generation changed\n",
546 __func__, ea->fcport->port_name);
548 } else if (ea->sp->gen1 != ea->fcport->rscn_gen) {
549 qla_rscn_replay(fcport);
550 qlt_schedule_sess_for_deletion(fcport);
554 __qla24xx_handle_gpdb_event(vha, ea);
557 static int qla_post_els_plogi_work(struct scsi_qla_host *vha, fc_port_t *fcport)
559 struct qla_work_evt *e;
561 e = qla2x00_alloc_work(vha, QLA_EVT_ELS_PLOGI);
563 return QLA_FUNCTION_FAILED;
565 e->u.fcport.fcport = fcport;
566 fcport->flags |= FCF_ASYNC_ACTIVE;
567 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_PEND);
568 return qla2x00_post_work(vha, e);
571 static void qla2x00_async_adisc_sp_done(srb_t *sp, int res)
573 struct scsi_qla_host *vha = sp->vha;
575 struct srb_iocb *lio = &sp->u.iocb_cmd;
577 ql_dbg(ql_dbg_disc, vha, 0x2066,
578 "Async done-%s res %x %8phC\n",
579 sp->name, res, sp->fcport->port_name);
581 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
583 memset(&ea, 0, sizeof(ea));
585 ea.data[0] = lio->u.logio.data[0];
586 ea.data[1] = lio->u.logio.data[1];
587 ea.iop[0] = lio->u.logio.iop[0];
588 ea.iop[1] = lio->u.logio.iop[1];
589 ea.fcport = sp->fcport;
592 ea.data[0] = MBS_COMMAND_ERROR;
594 qla24xx_handle_adisc_event(vha, &ea);
596 kref_put(&sp->cmd_kref, qla2x00_sp_release);
600 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
604 struct srb_iocb *lio;
605 int rval = QLA_FUNCTION_FAILED;
607 if (IS_SESSION_DELETED(fcport)) {
608 ql_log(ql_log_warn, vha, 0xffff,
609 "%s: %8phC is being delete - not sending command.\n",
610 __func__, fcport->port_name);
611 fcport->flags &= ~FCF_ASYNC_ACTIVE;
615 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
618 fcport->flags |= FCF_ASYNC_SENT;
620 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
624 sp->type = SRB_ADISC_CMD;
626 sp->gen1 = fcport->rscn_gen;
627 sp->gen2 = fcport->login_gen;
628 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
629 qla2x00_async_adisc_sp_done);
631 if (data[1] & QLA_LOGIO_LOGIN_RETRIED) {
632 lio = &sp->u.iocb_cmd;
633 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
636 ql_dbg(ql_dbg_disc, vha, 0x206f,
637 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
638 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
640 rval = qla2x00_start_sp(sp);
641 if (rval != QLA_SUCCESS)
648 kref_put(&sp->cmd_kref, qla2x00_sp_release);
650 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
651 qla2x00_post_async_adisc_work(vha, fcport, data);
655 static bool qla2x00_is_reserved_id(scsi_qla_host_t *vha, uint16_t loop_id)
657 struct qla_hw_data *ha = vha->hw;
659 if (IS_FWI2_CAPABLE(ha))
660 return loop_id > NPH_LAST_HANDLE;
662 return (loop_id > ha->max_loop_id && loop_id < SNS_FIRST_LOOP_ID) ||
663 loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST;
667 * qla2x00_find_new_loop_id - scan through our port list and find a new usable loop ID
668 * @vha: adapter state pointer.
669 * @dev: port structure pointer.
672 * qla2x00 local function return status code.
677 static int qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
680 struct qla_hw_data *ha = vha->hw;
681 unsigned long flags = 0;
685 spin_lock_irqsave(&ha->vport_slock, flags);
687 dev->loop_id = find_first_zero_bit(ha->loop_id_map, LOOPID_MAP_SIZE);
688 if (dev->loop_id >= LOOPID_MAP_SIZE ||
689 qla2x00_is_reserved_id(vha, dev->loop_id)) {
690 dev->loop_id = FC_NO_LOOP_ID;
691 rval = QLA_FUNCTION_FAILED;
693 set_bit(dev->loop_id, ha->loop_id_map);
695 spin_unlock_irqrestore(&ha->vport_slock, flags);
697 if (rval == QLA_SUCCESS)
698 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
699 "Assigning new loopid=%x, portid=%x.\n",
700 dev->loop_id, dev->d_id.b24);
702 ql_log(ql_log_warn, dev->vha, 0x2087,
703 "No loop_id's available, portid=%x.\n",
709 void qla2x00_clear_loop_id(fc_port_t *fcport)
711 struct qla_hw_data *ha = fcport->vha->hw;
713 if (fcport->loop_id == FC_NO_LOOP_ID ||
714 qla2x00_is_reserved_id(fcport->vha, fcport->loop_id))
717 clear_bit(fcport->loop_id, ha->loop_id_map);
718 fcport->loop_id = FC_NO_LOOP_ID;
721 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
722 struct event_arg *ea)
724 fc_port_t *fcport, *conflict_fcport;
725 struct get_name_list_extended *e;
726 u16 i, n, found = 0, loop_id;
730 u8 current_login_state, nvme_cls;
733 ql_dbg(ql_dbg_disc, vha, 0xffff,
734 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d edif %d\n",
735 __func__, fcport->port_name, fcport->disc_state,
736 fcport->fw_login_state, ea->rc,
737 fcport->login_gen, fcport->last_login_gen,
738 fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id, fcport->edif.enable);
740 if (fcport->disc_state == DSC_DELETE_PEND)
743 if (ea->rc) { /* rval */
744 if (fcport->login_retry == 0) {
745 ql_dbg(ql_dbg_disc, vha, 0x20de,
746 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
747 fcport->port_name, fcport->login_retry);
752 if (fcport->last_rscn_gen != fcport->rscn_gen) {
753 qla_rscn_replay(fcport);
754 qlt_schedule_sess_for_deletion(fcport);
756 } else if (fcport->last_login_gen != fcport->login_gen) {
757 ql_dbg(ql_dbg_disc, vha, 0x20e0,
758 "%s %8phC login gen changed\n",
759 __func__, fcport->port_name);
760 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
764 n = ea->data[0] / sizeof(struct get_name_list_extended);
766 ql_dbg(ql_dbg_disc, vha, 0x20e1,
767 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
768 __func__, __LINE__, fcport->port_name, n,
769 fcport->d_id.b.domain, fcport->d_id.b.area,
770 fcport->d_id.b.al_pa, fcport->loop_id);
772 for (i = 0; i < n; i++) {
774 wwn = wwn_to_u64(e->port_name);
775 id.b.domain = e->port_id[2];
776 id.b.area = e->port_id[1];
777 id.b.al_pa = e->port_id[0];
780 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
783 if (IS_SW_RESV_ADDR(id))
788 loop_id = le16_to_cpu(e->nport_handle);
789 loop_id = (loop_id & 0x7fff);
790 nvme_cls = e->current_login_state >> 4;
791 current_login_state = e->current_login_state & 0xf;
793 if (PRLI_PHASE(nvme_cls)) {
794 current_login_state = nvme_cls;
795 fcport->fc4_type &= ~FS_FC4TYPE_FCP;
796 fcport->fc4_type |= FS_FC4TYPE_NVME;
797 } else if (PRLI_PHASE(current_login_state)) {
798 fcport->fc4_type |= FS_FC4TYPE_FCP;
799 fcport->fc4_type &= ~FS_FC4TYPE_NVME;
802 ql_dbg(ql_dbg_disc, vha, 0x20e2,
803 "%s found %8phC CLS [%x|%x] fc4_type %d ID[%06x|%06x] lid[%d|%d]\n",
804 __func__, fcport->port_name,
805 e->current_login_state, fcport->fw_login_state,
806 fcport->fc4_type, id.b24, fcport->d_id.b24,
807 loop_id, fcport->loop_id);
809 switch (fcport->disc_state) {
810 case DSC_DELETE_PEND:
814 if ((id.b24 != fcport->d_id.b24 &&
816 fcport->loop_id != FC_NO_LOOP_ID) ||
817 (fcport->loop_id != FC_NO_LOOP_ID &&
818 fcport->loop_id != loop_id)) {
819 ql_dbg(ql_dbg_disc, vha, 0x20e3,
820 "%s %d %8phC post del sess\n",
821 __func__, __LINE__, fcport->port_name);
822 if (fcport->n2n_flag)
823 fcport->d_id.b24 = 0;
824 qlt_schedule_sess_for_deletion(fcport);
830 fcport->loop_id = loop_id;
831 if (fcport->n2n_flag)
832 fcport->d_id.b24 = id.b24;
834 wwn = wwn_to_u64(fcport->port_name);
835 qlt_find_sess_invalidate_other(vha, wwn,
836 id, loop_id, &conflict_fcport);
838 if (conflict_fcport) {
840 * Another share fcport share the same loop_id &
841 * nport id. Conflict fcport needs to finish
842 * cleanup before this fcport can proceed to login.
844 conflict_fcport->conflict = fcport;
845 fcport->login_pause = 1;
848 switch (vha->hw->current_topology) {
850 switch (current_login_state) {
851 case DSC_LS_PRLI_COMP:
853 vha, 0x20e4, "%s %d %8phC post gpdb\n",
854 __func__, __LINE__, fcport->port_name);
856 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
857 fcport->port_type = FCT_INITIATOR;
859 fcport->port_type = FCT_TARGET;
860 data[0] = data[1] = 0;
861 qla2x00_post_async_adisc_work(vha, fcport,
864 case DSC_LS_PLOGI_COMP:
865 if (vha->hw->flags.edif_enabled) {
866 /* check to see if App support Secure */
867 qla24xx_post_gpdb_work(vha, fcport, 0);
871 case DSC_LS_PORT_UNAVAIL:
873 if (fcport->loop_id == FC_NO_LOOP_ID) {
874 qla2x00_find_new_loop_id(vha, fcport);
875 fcport->fw_login_state =
878 ql_dbg(ql_dbg_disc, vha, 0x20e5,
879 "%s %d %8phC\n", __func__, __LINE__,
881 qla24xx_fcport_handle_login(vha, fcport);
886 fcport->fw_login_state = current_login_state;
888 switch (current_login_state) {
889 case DSC_LS_PRLI_PEND:
891 * In the middle of PRLI. Let it finish.
892 * Allow relogin code to recheck state again
893 * with GNL. Push disc_state back to DELETED
894 * so GNL can go out again
896 qla2x00_set_fcport_disc_state(fcport,
898 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
900 case DSC_LS_PRLI_COMP:
901 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
902 fcport->port_type = FCT_INITIATOR;
904 fcport->port_type = FCT_TARGET;
906 data[0] = data[1] = 0;
907 qla2x00_post_async_adisc_work(vha, fcport,
910 case DSC_LS_PLOGI_COMP:
911 if (vha->hw->flags.edif_enabled &&
913 /* check to see if App support secure or not */
914 qla24xx_post_gpdb_work(vha, fcport, 0);
917 if (fcport_is_bigger(fcport)) {
918 /* local adapter is smaller */
919 if (fcport->loop_id != FC_NO_LOOP_ID)
920 qla2x00_clear_loop_id(fcport);
922 fcport->loop_id = loop_id;
923 qla24xx_fcport_handle_login(vha,
929 if (fcport_is_smaller(fcport)) {
930 /* local adapter is bigger */
931 if (fcport->loop_id != FC_NO_LOOP_ID)
932 qla2x00_clear_loop_id(fcport);
934 fcport->loop_id = loop_id;
935 qla24xx_fcport_handle_login(vha,
941 } /* switch (ha->current_topology) */
945 switch (vha->hw->current_topology) {
948 for (i = 0; i < n; i++) {
950 id.b.domain = e->port_id[0];
951 id.b.area = e->port_id[1];
952 id.b.al_pa = e->port_id[2];
954 loop_id = le16_to_cpu(e->nport_handle);
956 if (fcport->d_id.b24 == id.b24) {
958 qla2x00_find_fcport_by_wwpn(vha,
960 if (conflict_fcport) {
961 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
963 "%s %d %8phC post del sess\n",
965 conflict_fcport->port_name);
966 qlt_schedule_sess_for_deletion
971 * FW already picked this loop id for
974 if (fcport->loop_id == loop_id)
975 fcport->loop_id = FC_NO_LOOP_ID;
977 qla24xx_fcport_handle_login(vha, fcport);
980 qla2x00_set_fcport_disc_state(fcport, DSC_DELETED);
981 if (time_after_eq(jiffies, fcport->dm_login_expire)) {
982 if (fcport->n2n_link_reset_cnt < 2) {
983 fcport->n2n_link_reset_cnt++;
985 * remote port is not sending PLOGI.
986 * Reset link to kick start his state
989 set_bit(N2N_LINK_RESET,
992 if (fcport->n2n_chip_reset < 1) {
993 ql_log(ql_log_info, vha, 0x705d,
994 "Chip reset to bring laser down");
995 set_bit(ISP_ABORT_NEEDED,
997 fcport->n2n_chip_reset++;
999 ql_log(ql_log_info, vha, 0x705d,
1000 "Remote port %8ph is not coming back\n",
1002 fcport->scan_state = 0;
1005 qla2xxx_wake_dpc(vha);
1008 * report port suppose to do PLOGI. Give him
1009 * more time. FW will catch it.
1011 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1015 qla24xx_fcport_handle_login(vha, fcport);
1023 static void qla24xx_async_gnl_sp_done(srb_t *sp, int res)
1025 struct scsi_qla_host *vha = sp->vha;
1026 unsigned long flags;
1027 struct fc_port *fcport = NULL, *tf;
1028 u16 i, n = 0, loop_id;
1029 struct event_arg ea;
1030 struct get_name_list_extended *e;
1035 ql_dbg(ql_dbg_disc, vha, 0x20e7,
1036 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
1037 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
1038 sp->u.iocb_cmd.u.mbx.in_mb[2]);
1041 sp->fcport->flags &= ~(FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE);
1042 memset(&ea, 0, sizeof(ea));
1046 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
1047 sizeof(struct get_name_list_extended)) {
1048 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
1049 sizeof(struct get_name_list_extended);
1050 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
1053 for (i = 0; i < n; i++) {
1055 loop_id = le16_to_cpu(e->nport_handle);
1056 /* mask out reserve bit */
1057 loop_id = (loop_id & 0x7fff);
1058 set_bit(loop_id, vha->hw->loop_id_map);
1059 wwn = wwn_to_u64(e->port_name);
1061 ql_dbg(ql_dbg_disc, vha, 0x20e8,
1062 "%s %8phC %02x:%02x:%02x CLS %x/%x lid %x \n",
1063 __func__, &wwn, e->port_id[2], e->port_id[1],
1064 e->port_id[0], e->current_login_state, e->last_login_state,
1065 (loop_id & 0x7fff));
1068 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1072 if (!list_empty(&vha->gnl.fcports))
1073 list_splice_init(&vha->gnl.fcports, &h);
1074 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1076 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
1077 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1078 list_del_init(&fcport->gnl_entry);
1079 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1080 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1083 qla24xx_handle_gnl_done_event(vha, &ea);
1086 /* create new fcport if fw has knowledge of new sessions */
1087 for (i = 0; i < n; i++) {
1092 wwn = wwn_to_u64(e->port_name);
1095 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
1096 if (!memcmp((u8 *)&wwn, fcport->port_name,
1103 id.b.domain = e->port_id[2];
1104 id.b.area = e->port_id[1];
1105 id.b.al_pa = e->port_id[0];
1108 if (!found && wwn && !IS_SW_RESV_ADDR(id)) {
1109 ql_dbg(ql_dbg_disc, vha, 0x2065,
1110 "%s %d %8phC %06x post new sess\n",
1111 __func__, __LINE__, (u8 *)&wwn, id.b24);
1112 wwnn = wwn_to_u64(e->node_name);
1113 qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn,
1114 (u8 *)&wwnn, NULL, 0);
1118 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1120 if (!list_empty(&vha->gnl.fcports)) {
1122 list_for_each_entry_safe(fcport, tf, &vha->gnl.fcports,
1124 list_del_init(&fcport->gnl_entry);
1125 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1126 if (qla24xx_post_gnl_work(vha, fcport) == QLA_SUCCESS)
1130 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1133 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1136 int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
1139 int rval = QLA_FUNCTION_FAILED;
1140 unsigned long flags;
1143 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
1146 ql_dbg(ql_dbg_disc, vha, 0x20d9,
1147 "Async-gnlist WWPN %8phC \n", fcport->port_name);
1149 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1150 fcport->flags |= FCF_ASYNC_SENT;
1151 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
1152 fcport->last_rscn_gen = fcport->rscn_gen;
1153 fcport->last_login_gen = fcport->login_gen;
1155 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
1156 if (vha->gnl.sent) {
1157 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1161 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1164 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1168 sp->type = SRB_MB_IOCB;
1169 sp->name = "gnlist";
1170 sp->gen1 = fcport->rscn_gen;
1171 sp->gen2 = fcport->login_gen;
1172 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
1173 qla24xx_async_gnl_sp_done);
1175 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1176 mb[0] = MBC_PORT_NODE_NAME_LIST;
1177 mb[1] = BIT_2 | BIT_3;
1178 mb[2] = MSW(vha->gnl.ldma);
1179 mb[3] = LSW(vha->gnl.ldma);
1180 mb[6] = MSW(MSD(vha->gnl.ldma));
1181 mb[7] = LSW(MSD(vha->gnl.ldma));
1182 mb[8] = vha->gnl.size;
1183 mb[9] = vha->vp_idx;
1185 ql_dbg(ql_dbg_disc, vha, 0x20da,
1186 "Async-%s - OUT WWPN %8phC hndl %x\n",
1187 sp->name, fcport->port_name, sp->handle);
1189 rval = qla2x00_start_sp(sp);
1190 if (rval != QLA_SUCCESS)
1197 * use qla24xx_async_gnl_sp_done to purge all pending gnl request.
1198 * kref_put is call behind the scene.
1200 sp->u.iocb_cmd.u.mbx.in_mb[0] = MBS_COMMAND_ERROR;
1201 qla24xx_async_gnl_sp_done(sp, QLA_COMMAND_ERROR);
1202 fcport->flags &= ~(FCF_ASYNC_SENT);
1204 fcport->flags &= ~(FCF_ASYNC_ACTIVE);
1208 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1210 struct qla_work_evt *e;
1212 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
1214 return QLA_FUNCTION_FAILED;
1216 e->u.fcport.fcport = fcport;
1217 fcport->flags |= FCF_ASYNC_ACTIVE;
1218 return qla2x00_post_work(vha, e);
1221 static void qla24xx_async_gpdb_sp_done(srb_t *sp, int res)
1223 struct scsi_qla_host *vha = sp->vha;
1224 struct qla_hw_data *ha = vha->hw;
1225 fc_port_t *fcport = sp->fcport;
1226 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
1227 struct event_arg ea;
1229 ql_dbg(ql_dbg_disc, vha, 0x20db,
1230 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
1231 sp->name, res, fcport->port_name, mb[1], mb[2]);
1233 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1235 if (res == QLA_FUNCTION_TIMEOUT)
1238 memset(&ea, 0, sizeof(ea));
1242 qla24xx_handle_gpdb_event(vha, &ea);
1245 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
1246 sp->u.iocb_cmd.u.mbx.in_dma);
1248 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1251 int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1253 struct qla_work_evt *e;
1255 if (vha->host->active_mode == MODE_TARGET)
1256 return QLA_FUNCTION_FAILED;
1258 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
1260 return QLA_FUNCTION_FAILED;
1262 e->u.fcport.fcport = fcport;
1264 return qla2x00_post_work(vha, e);
1267 static void qla2x00_async_prli_sp_done(srb_t *sp, int res)
1269 struct scsi_qla_host *vha = sp->vha;
1270 struct srb_iocb *lio = &sp->u.iocb_cmd;
1271 struct event_arg ea;
1273 ql_dbg(ql_dbg_disc, vha, 0x2129,
1274 "%s %8phC res %x\n", __func__,
1275 sp->fcport->port_name, res);
1277 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1279 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
1280 memset(&ea, 0, sizeof(ea));
1281 ea.fcport = sp->fcport;
1282 ea.data[0] = lio->u.logio.data[0];
1283 ea.data[1] = lio->u.logio.data[1];
1284 ea.iop[0] = lio->u.logio.iop[0];
1285 ea.iop[1] = lio->u.logio.iop[1];
1287 if (res == QLA_OS_TIMER_EXPIRED)
1288 ea.data[0] = QLA_OS_TIMER_EXPIRED;
1290 ea.data[0] = MBS_COMMAND_ERROR;
1292 qla24xx_handle_prli_done_event(vha, &ea);
1295 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1299 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
1302 struct srb_iocb *lio;
1303 int rval = QLA_FUNCTION_FAILED;
1305 if (!vha->flags.online) {
1306 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1307 __func__, __LINE__, fcport->port_name);
1311 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
1312 fcport->fw_login_state == DSC_LS_PRLI_PEND) &&
1313 qla_dual_mode_enabled(vha)) {
1314 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1315 __func__, __LINE__, fcport->port_name);
1319 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1323 fcport->flags |= FCF_ASYNC_SENT;
1324 fcport->logout_completed = 0;
1326 sp->type = SRB_PRLI_CMD;
1328 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
1329 qla2x00_async_prli_sp_done);
1331 lio = &sp->u.iocb_cmd;
1332 lio->u.logio.flags = 0;
1334 if (NVME_TARGET(vha->hw, fcport))
1335 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
1337 ql_dbg(ql_dbg_disc, vha, 0x211b,
1338 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d fc4type %x priority %x %s.\n",
1339 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24,
1340 fcport->login_retry, fcport->fc4_type, vha->hw->fc4_type_priority,
1341 NVME_TARGET(vha->hw, fcport) ? "nvme" : "fcp");
1343 rval = qla2x00_start_sp(sp);
1344 if (rval != QLA_SUCCESS) {
1345 fcport->flags |= FCF_LOGIN_NEEDED;
1346 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1354 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1355 fcport->flags &= ~FCF_ASYNC_SENT;
1359 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1361 struct qla_work_evt *e;
1363 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
1365 return QLA_FUNCTION_FAILED;
1367 e->u.fcport.fcport = fcport;
1368 e->u.fcport.opt = opt;
1369 fcport->flags |= FCF_ASYNC_ACTIVE;
1370 return qla2x00_post_work(vha, e);
1373 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1376 struct srb_iocb *mbx;
1377 int rval = QLA_FUNCTION_FAILED;
1380 struct port_database_24xx *pd;
1381 struct qla_hw_data *ha = vha->hw;
1383 if (IS_SESSION_DELETED(fcport)) {
1384 ql_log(ql_log_warn, vha, 0xffff,
1385 "%s: %8phC is being delete - not sending command.\n",
1386 __func__, fcport->port_name);
1387 fcport->flags &= ~FCF_ASYNC_ACTIVE;
1391 if (!vha->flags.online || fcport->flags & FCF_ASYNC_SENT) {
1392 ql_log(ql_log_warn, vha, 0xffff,
1393 "%s: %8phC online %d flags %x - not sending command.\n",
1394 __func__, fcport->port_name, vha->flags.online, fcport->flags);
1398 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1402 qla2x00_set_fcport_disc_state(fcport, DSC_GPDB);
1404 fcport->flags |= FCF_ASYNC_SENT;
1405 sp->type = SRB_MB_IOCB;
1407 sp->gen1 = fcport->rscn_gen;
1408 sp->gen2 = fcport->login_gen;
1409 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
1410 qla24xx_async_gpdb_sp_done);
1412 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1414 ql_log(ql_log_warn, vha, 0xd043,
1415 "Failed to allocate port database structure.\n");
1419 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1420 mb[0] = MBC_GET_PORT_DATABASE;
1421 mb[1] = fcport->loop_id;
1422 mb[2] = MSW(pd_dma);
1423 mb[3] = LSW(pd_dma);
1424 mb[6] = MSW(MSD(pd_dma));
1425 mb[7] = LSW(MSD(pd_dma));
1426 mb[9] = vha->vp_idx;
1429 mbx = &sp->u.iocb_cmd;
1430 mbx->u.mbx.in = (void *)pd;
1431 mbx->u.mbx.in_dma = pd_dma;
1433 ql_dbg(ql_dbg_disc, vha, 0x20dc,
1434 "Async-%s %8phC hndl %x opt %x\n",
1435 sp->name, fcport->port_name, sp->handle, opt);
1437 rval = qla2x00_start_sp(sp);
1438 if (rval != QLA_SUCCESS)
1444 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1446 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1447 fcport->flags &= ~FCF_ASYNC_SENT;
1449 fcport->flags &= ~FCF_ASYNC_ACTIVE;
1450 qla24xx_post_gpdb_work(vha, fcport, opt);
1455 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1457 unsigned long flags;
1459 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1460 ea->fcport->login_gen++;
1461 ea->fcport->logout_on_delete = 1;
1463 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1464 vha->fcport_count++;
1465 ea->fcport->login_succ = 1;
1467 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1468 qla24xx_sched_upd_fcport(ea->fcport);
1469 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1470 } else if (ea->fcport->login_succ) {
1472 * We have an existing session. A late RSCN delivery
1473 * must have triggered the session to be re-validate.
1474 * Session is still valid.
1476 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1477 "%s %d %8phC session revalidate success\n",
1478 __func__, __LINE__, ea->fcport->port_name);
1479 qla2x00_set_fcport_disc_state(ea->fcport, DSC_LOGIN_COMPLETE);
1481 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1484 static int qla_chk_secure_login(scsi_qla_host_t *vha, fc_port_t *fcport,
1485 struct port_database_24xx *pd)
1489 if (pd->secure_login) {
1490 ql_dbg(ql_dbg_disc, vha, 0x104d,
1491 "Secure Login established on %8phC\n",
1493 fcport->flags |= FCF_FCSP_DEVICE;
1495 ql_dbg(ql_dbg_disc, vha, 0x104d,
1496 "non-Secure Login %8phC",
1498 fcport->flags &= ~FCF_FCSP_DEVICE;
1500 if (vha->hw->flags.edif_enabled) {
1501 if (fcport->flags & FCF_FCSP_DEVICE) {
1502 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_AUTH_PEND);
1503 /* Start edif prli timer & ring doorbell for app */
1504 fcport->edif.rx_sa_set = 0;
1505 fcport->edif.tx_sa_set = 0;
1506 fcport->edif.rx_sa_pending = 0;
1507 fcport->edif.tx_sa_pending = 0;
1509 qla2x00_post_aen_work(vha, FCH_EVT_PORT_ONLINE,
1512 if (DBELL_ACTIVE(vha)) {
1513 ql_dbg(ql_dbg_disc, vha, 0x20ef,
1514 "%s %d %8phC EDIF: post DB_AUTH: AUTH needed\n",
1515 __func__, __LINE__, fcport->port_name);
1516 fcport->edif.app_sess_online = 1;
1518 qla_edb_eventcreate(vha, VND_CMD_AUTH_STATE_NEEDED,
1519 fcport->d_id.b24, 0, fcport);
1523 } else if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
1524 ql_dbg(ql_dbg_disc, vha, 0x2117,
1525 "%s %d %8phC post prli\n",
1526 __func__, __LINE__, fcport->port_name);
1527 qla24xx_post_prli_work(vha, fcport);
1535 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1537 fc_port_t *fcport = ea->fcport;
1538 struct port_database_24xx *pd;
1539 struct srb *sp = ea->sp;
1542 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1544 fcport->flags &= ~FCF_ASYNC_SENT;
1546 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1547 "%s %8phC DS %d LS %x fc4_type %x rc %x\n", __func__,
1548 fcport->port_name, fcport->disc_state, pd->current_login_state,
1549 fcport->fc4_type, ea->rc);
1551 if (fcport->disc_state == DSC_DELETE_PEND) {
1552 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC\n",
1553 __func__, __LINE__, fcport->port_name);
1557 if (NVME_TARGET(vha->hw, fcport))
1558 ls = pd->current_login_state >> 4;
1560 ls = pd->current_login_state & 0xf;
1562 if (ea->sp->gen2 != fcport->login_gen) {
1563 /* target side must have changed it. */
1565 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1566 "%s %8phC generation changed\n",
1567 __func__, fcport->port_name);
1569 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1570 qla_rscn_replay(fcport);
1571 qlt_schedule_sess_for_deletion(fcport);
1572 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n",
1573 __func__, __LINE__, fcport->port_name, ls);
1578 case PDS_PRLI_COMPLETE:
1579 __qla24xx_parse_gpdb(vha, fcport, pd);
1581 case PDS_PLOGI_COMPLETE:
1582 if (qla_chk_secure_login(vha, fcport, pd)) {
1583 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n",
1584 __func__, __LINE__, fcport->port_name, ls);
1588 case PDS_PLOGI_PENDING:
1589 case PDS_PRLI_PENDING:
1590 case PDS_PRLI2_PENDING:
1591 /* Set discovery state back to GNL to Relogin attempt */
1592 if (qla_dual_mode_enabled(vha) ||
1593 qla_ini_mode_enabled(vha)) {
1594 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
1595 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1597 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n",
1598 __func__, __LINE__, fcport->port_name, ls);
1600 case PDS_LOGO_PENDING:
1601 case PDS_PORT_UNAVAILABLE:
1603 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1604 __func__, __LINE__, fcport->port_name);
1605 qlt_schedule_sess_for_deletion(fcport);
1608 __qla24xx_handle_gpdb_event(vha, ea);
1611 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1616 ql_dbg(ql_dbg_disc, vha, 0x307b,
1617 "%s %8phC DS %d LS %d lid %d retries=%d\n",
1618 __func__, fcport->port_name, fcport->disc_state,
1619 fcport->fw_login_state, fcport->loop_id, fcport->login_retry);
1621 if (qla_tgt_mode_enabled(vha))
1624 if (qla_dual_mode_enabled(vha)) {
1625 if (N2N_TOPO(vha->hw)) {
1628 mywwn = wwn_to_u64(vha->port_name);
1629 wwn = wwn_to_u64(fcport->port_name);
1632 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1633 && time_after_eq(jiffies,
1634 fcport->plogi_nack_done_deadline))
1640 /* initiator mode */
1644 if (login && fcport->login_retry) {
1645 fcport->login_retry--;
1646 if (fcport->loop_id == FC_NO_LOOP_ID) {
1647 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1648 rc = qla2x00_find_new_loop_id(vha, fcport);
1650 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1651 "%s %d %8phC post del sess - out of loopid\n",
1652 __func__, __LINE__, fcport->port_name);
1653 fcport->scan_state = 0;
1654 qlt_schedule_sess_for_deletion(fcport);
1658 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1659 "%s %d %8phC post login\n",
1660 __func__, __LINE__, fcport->port_name);
1661 qla2x00_post_async_login_work(vha, fcport, NULL);
1665 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1670 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1671 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d fc4type %x\n",
1672 __func__, fcport->port_name, fcport->disc_state,
1673 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1674 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1675 fcport->login_gen, fcport->loop_id, fcport->scan_state,
1678 if (fcport->scan_state != QLA_FCPORT_FOUND ||
1679 fcport->disc_state == DSC_DELETE_PEND)
1682 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1683 qla_dual_mode_enabled(vha) &&
1684 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1685 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1688 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP &&
1689 !N2N_TOPO(vha->hw)) {
1690 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1691 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1696 /* Target won't initiate port login if fabric is present */
1697 if (vha->host->active_mode == MODE_TARGET && !N2N_TOPO(vha->hw))
1700 if (fcport->flags & (FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE)) {
1701 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1705 switch (fcport->disc_state) {
1707 switch (vha->hw->current_topology) {
1709 if (fcport_is_smaller(fcport)) {
1710 /* this adapter is bigger */
1711 if (fcport->login_retry) {
1712 if (fcport->loop_id == FC_NO_LOOP_ID) {
1713 qla2x00_find_new_loop_id(vha,
1715 fcport->fw_login_state =
1716 DSC_LS_PORT_UNAVAIL;
1718 fcport->login_retry--;
1719 qla_post_els_plogi_work(vha, fcport);
1721 ql_log(ql_log_info, vha, 0x705d,
1722 "Unable to reach remote port %8phC",
1726 qla24xx_post_gnl_work(vha, fcport);
1730 if (fcport->loop_id == FC_NO_LOOP_ID) {
1731 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1732 "%s %d %8phC post gnl\n",
1733 __func__, __LINE__, fcport->port_name);
1734 qla24xx_post_gnl_work(vha, fcport);
1736 qla_chk_n2n_b4_login(vha, fcport);
1743 switch (vha->hw->current_topology) {
1745 if ((fcport->current_login_state & 0xf) == 0x6) {
1746 ql_dbg(ql_dbg_disc, vha, 0x2118,
1747 "%s %d %8phC post GPDB work\n",
1748 __func__, __LINE__, fcport->port_name);
1749 fcport->chip_reset =
1750 vha->hw->base_qpair->chip_reset;
1751 qla24xx_post_gpdb_work(vha, fcport, 0);
1753 ql_dbg(ql_dbg_disc, vha, 0x2118,
1754 "%s %d %8phC post %s PRLI\n",
1755 __func__, __LINE__, fcport->port_name,
1756 NVME_TARGET(vha->hw, fcport) ? "NVME" :
1758 qla24xx_post_prli_work(vha, fcport);
1762 if (fcport->login_pause) {
1763 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1764 "%s %d %8phC exit\n",
1767 fcport->last_rscn_gen = fcport->rscn_gen;
1768 fcport->last_login_gen = fcport->login_gen;
1769 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1772 qla_chk_n2n_b4_login(vha, fcport);
1777 case DSC_LOGIN_FAILED:
1778 if (N2N_TOPO(vha->hw))
1779 qla_chk_n2n_b4_login(vha, fcport);
1781 qlt_schedule_sess_for_deletion(fcport);
1784 case DSC_LOGIN_COMPLETE:
1785 /* recheck login state */
1786 data[0] = data[1] = 0;
1787 qla2x00_post_async_adisc_work(vha, fcport, data);
1790 case DSC_LOGIN_PEND:
1791 if (vha->hw->flags.edif_enabled)
1794 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1795 ql_dbg(ql_dbg_disc, vha, 0x2118,
1796 "%s %d %8phC post %s PRLI\n",
1797 __func__, __LINE__, fcport->port_name,
1798 NVME_TARGET(vha->hw, fcport) ? "NVME" : "FC");
1799 qla24xx_post_prli_work(vha, fcport);
1803 case DSC_UPD_FCPORT:
1804 sec = jiffies_to_msecs(jiffies -
1805 fcport->jiffies_at_registration)/1000;
1806 if (fcport->sec_since_registration < sec && sec &&
1808 fcport->sec_since_registration = sec;
1809 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
1810 "%s %8phC - Slow Rport registration(%d Sec)\n",
1811 __func__, fcport->port_name, sec);
1814 if (fcport->next_disc_state != DSC_DELETE_PEND)
1815 fcport->next_disc_state = DSC_ADISC;
1816 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1826 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1827 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1829 struct qla_work_evt *e;
1831 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1833 return QLA_FUNCTION_FAILED;
1835 e->u.new_sess.id = *id;
1836 e->u.new_sess.pla = pla;
1837 e->u.new_sess.fc4_type = fc4_type;
1838 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1840 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1842 return qla2x00_post_work(vha, e);
1845 void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
1848 unsigned long flags;
1850 switch (ea->id.b.rsvd_1) {
1851 case RSCN_PORT_ADDR:
1852 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1854 if (ql2xfc2target &&
1855 fcport->flags & FCF_FCP2_DEVICE &&
1856 atomic_read(&fcport->state) == FCS_ONLINE) {
1857 ql_dbg(ql_dbg_disc, vha, 0x2115,
1858 "Delaying session delete for FCP2 portid=%06x %8phC ",
1859 fcport->d_id.b24, fcport->port_name);
1863 if (vha->hw->flags.edif_enabled && DBELL_ACTIVE(vha)) {
1865 * On ipsec start by remote port, Target port
1866 * may use RSCN to trigger initiator to
1867 * relogin. If driver is already in the
1868 * process of a relogin, then ignore the RSCN
1869 * and allow the current relogin to continue.
1870 * This reduces thrashing of the connection.
1872 if (atomic_read(&fcport->state) == FCS_ONLINE) {
1874 * If state = online, then set scan_needed=1 to do relogin.
1875 * Otherwise we're already in the middle of a relogin
1877 fcport->scan_needed = 1;
1881 fcport->scan_needed = 1;
1886 case RSCN_AREA_ADDR:
1887 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1888 if (fcport->flags & FCF_FCP2_DEVICE &&
1889 atomic_read(&fcport->state) == FCS_ONLINE)
1892 if ((ea->id.b24 & 0xffff00) == (fcport->d_id.b24 & 0xffff00)) {
1893 fcport->scan_needed = 1;
1899 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1900 if (fcport->flags & FCF_FCP2_DEVICE &&
1901 atomic_read(&fcport->state) == FCS_ONLINE)
1904 if ((ea->id.b24 & 0xff0000) == (fcport->d_id.b24 & 0xff0000)) {
1905 fcport->scan_needed = 1;
1912 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1913 if (fcport->flags & FCF_FCP2_DEVICE &&
1914 atomic_read(&fcport->state) == FCS_ONLINE)
1917 fcport->scan_needed = 1;
1923 spin_lock_irqsave(&vha->work_lock, flags);
1924 if (vha->scan.scan_flags == 0) {
1925 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s: schedule\n", __func__);
1926 vha->scan.scan_flags |= SF_QUEUED;
1927 schedule_delayed_work(&vha->scan.scan_work, 5);
1929 spin_unlock_irqrestore(&vha->work_lock, flags);
1932 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1933 struct event_arg *ea)
1935 fc_port_t *fcport = ea->fcport;
1937 if (test_bit(UNLOADING, &vha->dpc_flags))
1940 ql_dbg(ql_dbg_disc, vha, 0x2102,
1941 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1942 __func__, fcport->port_name, fcport->disc_state,
1943 fcport->fw_login_state, fcport->login_pause,
1944 fcport->deleted, fcport->conflict,
1945 fcport->last_rscn_gen, fcport->rscn_gen,
1946 fcport->last_login_gen, fcport->login_gen,
1949 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1950 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gnl\n",
1951 __func__, __LINE__, fcport->port_name);
1952 qla24xx_post_gnl_work(vha, fcport);
1956 qla24xx_fcport_handle_login(vha, fcport);
1959 void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
1960 struct event_arg *ea)
1962 if (N2N_TOPO(vha->hw) && fcport_is_smaller(ea->fcport) &&
1963 vha->hw->flags.edif_enabled) {
1964 /* check to see if App support Secure */
1965 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1969 /* for pure Target Mode, PRLI will not be initiated */
1970 if (vha->host->active_mode == MODE_TARGET)
1973 ql_dbg(ql_dbg_disc, vha, 0x2118,
1974 "%s %d %8phC post PRLI\n",
1975 __func__, __LINE__, ea->fcport->port_name);
1976 qla24xx_post_prli_work(vha, ea->fcport);
1980 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1981 * to be consumed by the fcport
1983 void qla_rscn_replay(fc_port_t *fcport)
1985 struct event_arg ea;
1987 switch (fcport->disc_state) {
1988 case DSC_DELETE_PEND:
1994 if (fcport->scan_needed) {
1995 memset(&ea, 0, sizeof(ea));
1996 ea.id = fcport->d_id;
1997 ea.id.b.rsvd_1 = RSCN_PORT_ADDR;
1998 qla2x00_handle_rscn(fcport->vha, &ea);
2003 qla2x00_tmf_iocb_timeout(void *data)
2006 struct srb_iocb *tmf = &sp->u.iocb_cmd;
2008 unsigned long flags;
2010 if (sp->type == SRB_MARKER)
2011 rc = QLA_FUNCTION_FAILED;
2013 rc = qla24xx_async_abort_cmd(sp, false);
2016 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
2017 for (h = 1; h < sp->qpair->req->num_outstanding_cmds; h++) {
2018 if (sp->qpair->req->outstanding_cmds[h] == sp) {
2019 sp->qpair->req->outstanding_cmds[h] = NULL;
2020 qla_put_fw_resources(sp->qpair, &sp->iores);
2024 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
2025 tmf->u.tmf.comp_status = cpu_to_le16(CS_TIMEOUT);
2026 tmf->u.tmf.data = QLA_FUNCTION_FAILED;
2027 complete(&tmf->u.tmf.comp);
2031 static void qla_marker_sp_done(srb_t *sp, int res)
2033 struct srb_iocb *tmf = &sp->u.iocb_cmd;
2035 if (res != QLA_SUCCESS)
2036 ql_dbg(ql_dbg_taskm, sp->vha, 0x8004,
2037 "Async-marker fail hdl=%x portid=%06x ctrl=%x lun=%lld qp=%d.\n",
2038 sp->handle, sp->fcport->d_id.b24, sp->u.iocb_cmd.u.tmf.flags,
2039 sp->u.iocb_cmd.u.tmf.lun, sp->qpair->id);
2041 sp->u.iocb_cmd.u.tmf.data = res;
2042 complete(&tmf->u.tmf.comp);
2045 #define START_SP_W_RETRIES(_sp, _rval, _chip_gen, _login_gen) \
2049 if (_chip_gen != sp->vha->hw->chip_reset || _login_gen != sp->fcport->login_gen) {\
2053 _rval = qla2x00_start_sp(_sp); \
2054 if (_rval == EAGAIN) \
2063 * qla26xx_marker: send marker IOCB and wait for the completion of it.
2064 * @arg: pointer to argument list.
2065 * It is assume caller will provide an fcport pointer and modifier
2068 qla26xx_marker(struct tmf_arg *arg)
2070 struct scsi_qla_host *vha = arg->vha;
2071 struct srb_iocb *tm_iocb;
2073 int rval = QLA_FUNCTION_FAILED;
2074 fc_port_t *fcport = arg->fcport;
2075 u32 chip_gen, login_gen;
2077 if (TMF_NOT_READY(arg->fcport)) {
2078 ql_dbg(ql_dbg_taskm, vha, 0x8039,
2079 "FC port not ready for marker loop-id=%x portid=%06x modifier=%x lun=%lld qp=%d.\n",
2080 fcport->loop_id, fcport->d_id.b24,
2081 arg->modifier, arg->lun, arg->qpair->id);
2082 return QLA_SUSPENDED;
2085 chip_gen = vha->hw->chip_reset;
2086 login_gen = fcport->login_gen;
2089 sp = qla2xxx_get_qpair_sp(vha, arg->qpair, fcport, GFP_KERNEL);
2093 sp->type = SRB_MARKER;
2094 sp->name = "marker";
2095 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha), qla_marker_sp_done);
2096 sp->u.iocb_cmd.timeout = qla2x00_tmf_iocb_timeout;
2098 tm_iocb = &sp->u.iocb_cmd;
2099 init_completion(&tm_iocb->u.tmf.comp);
2100 tm_iocb->u.tmf.modifier = arg->modifier;
2101 tm_iocb->u.tmf.lun = arg->lun;
2102 tm_iocb->u.tmf.loop_id = fcport->loop_id;
2103 tm_iocb->u.tmf.vp_index = vha->vp_idx;
2105 START_SP_W_RETRIES(sp, rval, chip_gen, login_gen);
2107 ql_dbg(ql_dbg_taskm, vha, 0x8006,
2108 "Async-marker hdl=%x loop-id=%x portid=%06x modifier=%x lun=%lld qp=%d rval %d.\n",
2109 sp->handle, fcport->loop_id, fcport->d_id.b24,
2110 arg->modifier, arg->lun, sp->qpair->id, rval);
2112 if (rval != QLA_SUCCESS) {
2113 ql_log(ql_log_warn, vha, 0x8031,
2114 "Marker IOCB send failure (%x).\n", rval);
2118 wait_for_completion(&tm_iocb->u.tmf.comp);
2119 rval = tm_iocb->u.tmf.data;
2121 if (rval != QLA_SUCCESS) {
2122 ql_log(ql_log_warn, vha, 0x8019,
2123 "Marker failed hdl=%x loop-id=%x portid=%06x modifier=%x lun=%lld qp=%d rval %d.\n",
2124 sp->handle, fcport->loop_id, fcport->d_id.b24,
2125 arg->modifier, arg->lun, sp->qpair->id, rval);
2130 kref_put(&sp->cmd_kref, qla2x00_sp_release);
2135 static void qla2x00_tmf_sp_done(srb_t *sp, int res)
2137 struct srb_iocb *tmf = &sp->u.iocb_cmd;
2140 tmf->u.tmf.data = res;
2141 complete(&tmf->u.tmf.comp);
2144 static int qla_tmf_wait(struct tmf_arg *arg)
2146 /* there are only 2 types of error handling that reaches here, lun or target reset */
2147 if (arg->flags & (TCF_LUN_RESET | TCF_ABORT_TASK_SET | TCF_CLEAR_TASK_SET))
2148 return qla2x00_eh_wait_for_pending_commands(arg->vha,
2149 arg->fcport->d_id.b24, arg->lun, WAIT_LUN);
2151 return qla2x00_eh_wait_for_pending_commands(arg->vha,
2152 arg->fcport->d_id.b24, arg->lun, WAIT_TARGET);
2156 __qla2x00_async_tm_cmd(struct tmf_arg *arg)
2158 struct scsi_qla_host *vha = arg->vha;
2159 struct srb_iocb *tm_iocb;
2161 int rval = QLA_FUNCTION_FAILED;
2162 fc_port_t *fcport = arg->fcport;
2163 u32 chip_gen, login_gen;
2166 if (TMF_NOT_READY(arg->fcport)) {
2167 ql_dbg(ql_dbg_taskm, vha, 0x8032,
2168 "FC port not ready for TM command loop-id=%x portid=%06x modifier=%x lun=%lld qp=%d.\n",
2169 fcport->loop_id, fcport->d_id.b24,
2170 arg->modifier, arg->lun, arg->qpair->id);
2171 return QLA_SUSPENDED;
2174 chip_gen = vha->hw->chip_reset;
2175 login_gen = fcport->login_gen;
2178 sp = qla2xxx_get_qpair_sp(vha, arg->qpair, fcport, GFP_KERNEL);
2182 qla_vha_mark_busy(vha);
2183 sp->type = SRB_TM_CMD;
2185 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha),
2186 qla2x00_tmf_sp_done);
2187 sp->u.iocb_cmd.timeout = qla2x00_tmf_iocb_timeout;
2189 tm_iocb = &sp->u.iocb_cmd;
2190 init_completion(&tm_iocb->u.tmf.comp);
2191 tm_iocb->u.tmf.flags = arg->flags;
2192 tm_iocb->u.tmf.lun = arg->lun;
2194 START_SP_W_RETRIES(sp, rval, chip_gen, login_gen);
2196 ql_dbg(ql_dbg_taskm, vha, 0x802f,
2197 "Async-tmf hdl=%x loop-id=%x portid=%06x ctrl=%x lun=%lld qp=%d rval=%x.\n",
2198 sp->handle, fcport->loop_id, fcport->d_id.b24,
2199 arg->flags, arg->lun, sp->qpair->id, rval);
2201 if (rval != QLA_SUCCESS)
2203 wait_for_completion(&tm_iocb->u.tmf.comp);
2205 rval = tm_iocb->u.tmf.data;
2207 if (rval != QLA_SUCCESS) {
2208 ql_log(ql_log_warn, vha, 0x8030,
2209 "TM IOCB failed (%x).\n", rval);
2212 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
2214 if (qla_tmf_wait(arg)) {
2215 ql_log(ql_log_info, vha, 0x803e,
2216 "Waited %u ms Nexus=%ld:%06x:%llu.\n",
2217 jiffies_to_msecs(jiffies - jif), vha->host_no,
2218 fcport->d_id.b24, arg->lun);
2221 if (chip_gen == vha->hw->chip_reset && login_gen == fcport->login_gen) {
2222 rval = qla26xx_marker(arg);
2224 ql_log(ql_log_info, vha, 0x803e,
2225 "Skip Marker due to disruption. Nexus=%ld:%06x:%llu.\n",
2226 vha->host_no, fcport->d_id.b24, arg->lun);
2227 rval = QLA_FUNCTION_FAILED;
2230 if (tm_iocb->u.tmf.data)
2231 rval = tm_iocb->u.tmf.data;
2235 kref_put(&sp->cmd_kref, qla2x00_sp_release);
2240 static void qla_put_tmf(struct tmf_arg *arg)
2242 struct scsi_qla_host *vha = arg->vha;
2243 struct qla_hw_data *ha = vha->hw;
2244 unsigned long flags;
2246 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
2248 list_del(&arg->tmf_elem);
2249 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
2253 int qla_get_tmf(struct tmf_arg *arg)
2255 struct scsi_qla_host *vha = arg->vha;
2256 struct qla_hw_data *ha = vha->hw;
2257 unsigned long flags;
2258 fc_port_t *fcport = arg->fcport;
2262 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
2263 list_for_each_entry(t, &ha->tmf_active, tmf_elem) {
2264 if (t->fcport == arg->fcport && t->lun == arg->lun) {
2265 /* reject duplicate TMF */
2266 ql_log(ql_log_warn, vha, 0x802c,
2267 "found duplicate TMF. Nexus=%ld:%06x:%llu.\n",
2268 vha->host_no, fcport->d_id.b24, arg->lun);
2269 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
2274 list_add_tail(&arg->tmf_elem, &ha->tmf_pending);
2275 while (ha->active_tmf >= MAX_ACTIVE_TMF) {
2276 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
2280 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
2281 if (TMF_NOT_READY(fcport)) {
2282 ql_log(ql_log_warn, vha, 0x802c,
2283 "Unable to acquire TM resource due to disruption.\n");
2287 if (ha->active_tmf < MAX_ACTIVE_TMF &&
2288 list_is_first(&arg->tmf_elem, &ha->tmf_pending))
2292 list_del(&arg->tmf_elem);
2296 list_add_tail(&arg->tmf_elem, &ha->tmf_active);
2299 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
2305 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint64_t lun,
2308 struct scsi_qla_host *vha = fcport->vha;
2310 int rval = QLA_SUCCESS;
2312 if (TMF_NOT_READY(fcport))
2313 return QLA_SUSPENDED;
2315 a.vha = fcport->vha;
2319 INIT_LIST_HEAD(&a.tmf_elem);
2321 if (flags & (TCF_LUN_RESET|TCF_ABORT_TASK_SET|TCF_CLEAR_TASK_SET|TCF_CLEAR_ACA)) {
2322 a.modifier = MK_SYNC_ID_LUN;
2324 a.modifier = MK_SYNC_ID;
2327 if (qla_get_tmf(&a))
2328 return QLA_FUNCTION_FAILED;
2330 a.qpair = vha->hw->base_qpair;
2331 rval = __qla2x00_async_tm_cmd(&a);
2338 qla24xx_async_abort_command(srb_t *sp)
2340 unsigned long flags = 0;
2343 fc_port_t *fcport = sp->fcport;
2344 struct qla_qpair *qpair = sp->qpair;
2345 struct scsi_qla_host *vha = fcport->vha;
2346 struct req_que *req = qpair->req;
2348 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
2349 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
2350 if (req->outstanding_cmds[handle] == sp)
2353 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
2355 if (handle == req->num_outstanding_cmds) {
2356 /* Command not found. */
2357 return QLA_ERR_NOT_FOUND;
2359 if (sp->type == SRB_FXIOCB_DCMD)
2360 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
2361 FXDISC_ABORT_IOCTL);
2363 return qla24xx_async_abort_cmd(sp, true);
2367 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
2370 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
2373 switch (ea->data[0]) {
2374 case MBS_COMMAND_COMPLETE:
2375 ql_dbg(ql_dbg_disc, vha, 0x2118,
2376 "%s %d %8phC post gpdb\n",
2377 __func__, __LINE__, ea->fcport->port_name);
2379 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2380 ea->fcport->logout_on_delete = 1;
2381 ea->fcport->nvme_prli_service_param = ea->iop[0];
2382 if (ea->iop[0] & NVME_PRLI_SP_FIRST_BURST)
2383 ea->fcport->nvme_first_burst_size =
2384 (ea->iop[1] & 0xffff) * 512;
2386 ea->fcport->nvme_first_burst_size = 0;
2387 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2391 ql_dbg(ql_dbg_disc, vha, 0x2118,
2392 "%s %d %8phC priority %s, fc4type %x prev try %s\n",
2393 __func__, __LINE__, ea->fcport->port_name,
2394 vha->hw->fc4_type_priority == FC4_PRIORITY_FCP ?
2395 "FCP" : "NVMe", ea->fcport->fc4_type,
2396 (sp->u.iocb_cmd.u.logio.flags & SRB_LOGIN_NVME_PRLI) ?
2399 if (NVME_FCP_TARGET(ea->fcport)) {
2400 if (sp->u.iocb_cmd.u.logio.flags & SRB_LOGIN_NVME_PRLI)
2401 ea->fcport->do_prli_nvme = 0;
2403 ea->fcport->do_prli_nvme = 1;
2405 ea->fcport->do_prli_nvme = 0;
2408 if (N2N_TOPO(vha->hw)) {
2409 if (ea->fcport->n2n_link_reset_cnt ==
2410 vha->hw->login_retry_count &&
2411 ea->fcport->flags & FCF_FCSP_DEVICE) {
2412 /* remote authentication app just started */
2413 ea->fcport->n2n_link_reset_cnt = 0;
2416 if (ea->fcport->n2n_link_reset_cnt <
2417 vha->hw->login_retry_count) {
2418 ea->fcport->n2n_link_reset_cnt++;
2419 vha->relogin_jif = jiffies + 2 * HZ;
2421 * PRLI failed. Reset link to kick start
2424 set_bit(N2N_LINK_RESET, &vha->dpc_flags);
2425 qla2xxx_wake_dpc(vha);
2427 ql_log(ql_log_warn, vha, 0x2119,
2428 "%s %d %8phC Unable to reconnect\n",
2430 ea->fcport->port_name);
2434 * switch connect. login failed. Take connection down
2435 * and allow relogin to retrigger
2437 ea->fcport->flags &= ~FCF_ASYNC_SENT;
2438 ea->fcport->keep_nport_handle = 0;
2439 ea->fcport->logout_on_delete = 1;
2440 qlt_schedule_sess_for_deletion(ea->fcport);
2447 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
2449 port_id_t cid; /* conflict Nport id */
2451 struct fc_port *conflict_fcport;
2452 unsigned long flags;
2453 struct fc_port *fcport = ea->fcport;
2455 ql_dbg(ql_dbg_disc, vha, 0xffff,
2456 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
2457 __func__, fcport->port_name, fcport->disc_state,
2458 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
2459 ea->sp->gen1, fcport->rscn_gen,
2460 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
2462 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
2463 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
2464 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2465 "%s %d %8phC Remote is trying to login\n",
2466 __func__, __LINE__, fcport->port_name);
2470 if ((fcport->disc_state == DSC_DELETE_PEND) ||
2471 (fcport->disc_state == DSC_DELETED)) {
2472 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2476 if (ea->sp->gen2 != fcport->login_gen) {
2477 /* target side must have changed it. */
2478 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2479 "%s %8phC generation changed\n",
2480 __func__, fcport->port_name);
2481 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2483 } else if (ea->sp->gen1 != fcport->rscn_gen) {
2484 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2485 "%s %8phC RSCN generation changed\n",
2486 __func__, fcport->port_name);
2487 qla_rscn_replay(fcport);
2488 qlt_schedule_sess_for_deletion(fcport);
2492 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
2495 switch (ea->data[0]) {
2496 case MBS_COMMAND_COMPLETE:
2498 * Driver must validate login state - If PRLI not complete,
2499 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
2502 if (vha->hw->flags.edif_enabled) {
2503 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2504 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2505 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2506 ea->fcport->logout_on_delete = 1;
2507 ea->fcport->send_els_logo = 0;
2508 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
2509 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2511 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2513 if (NVME_TARGET(vha->hw, fcport)) {
2514 ql_dbg(ql_dbg_disc, vha, 0x2117,
2515 "%s %d %8phC post prli\n",
2516 __func__, __LINE__, fcport->port_name);
2517 qla24xx_post_prli_work(vha, fcport);
2519 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2520 "%s %d %8phC LoopID 0x%x in use with %06x. post gpdb\n",
2521 __func__, __LINE__, fcport->port_name,
2522 fcport->loop_id, fcport->d_id.b24);
2524 set_bit(fcport->loop_id, vha->hw->loop_id_map);
2525 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2526 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2527 fcport->logout_on_delete = 1;
2528 fcport->send_els_logo = 0;
2529 fcport->fw_login_state = DSC_LS_PRLI_COMP;
2530 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2532 qla24xx_post_gpdb_work(vha, fcport, 0);
2536 case MBS_COMMAND_ERROR:
2537 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
2538 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
2540 qlt_schedule_sess_for_deletion(ea->fcport);
2542 case MBS_LOOP_ID_USED:
2543 /* data[1] = IO PARAM 1 = nport ID */
2544 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
2545 cid.b.area = (ea->iop[1] >> 8) & 0xff;
2546 cid.b.al_pa = ea->iop[1] & 0xff;
2549 ql_dbg(ql_dbg_disc, vha, 0x20ec,
2550 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2551 __func__, __LINE__, ea->fcport->port_name,
2552 ea->fcport->loop_id, cid.b24);
2554 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2555 ea->fcport->loop_id = FC_NO_LOOP_ID;
2556 qla24xx_post_gnl_work(vha, ea->fcport);
2558 case MBS_PORT_ID_USED:
2559 lid = ea->iop[1] & 0xffff;
2560 qlt_find_sess_invalidate_other(vha,
2561 wwn_to_u64(ea->fcport->port_name),
2562 ea->fcport->d_id, lid, &conflict_fcport);
2564 if (conflict_fcport) {
2566 * Another fcport share the same loop_id/nport id.
2567 * Conflict fcport needs to finish cleanup before this
2568 * fcport can proceed to login.
2570 conflict_fcport->conflict = ea->fcport;
2571 ea->fcport->login_pause = 1;
2573 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2574 "%s %d %8phC NPortId %06x inuse with loopid 0x%x.\n",
2575 __func__, __LINE__, ea->fcport->port_name,
2576 ea->fcport->d_id.b24, lid);
2578 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2579 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2580 __func__, __LINE__, ea->fcport->port_name,
2581 ea->fcport->d_id.b24, lid);
2583 qla2x00_clear_loop_id(ea->fcport);
2584 set_bit(lid, vha->hw->loop_id_map);
2585 ea->fcport->loop_id = lid;
2586 ea->fcport->keep_nport_handle = 0;
2587 ea->fcport->logout_on_delete = 1;
2588 qlt_schedule_sess_for_deletion(ea->fcport);
2595 /****************************************************************************/
2596 /* QLogic ISP2x00 Hardware Support Functions. */
2597 /****************************************************************************/
2600 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
2602 int rval = QLA_SUCCESS;
2603 struct qla_hw_data *ha = vha->hw;
2604 uint32_t idc_major_ver, idc_minor_ver;
2607 qla83xx_idc_lock(vha, 0);
2609 /* SV: TODO: Assign initialization timeout from
2610 * flash-info / other param
2612 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
2613 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
2615 /* Set our fcoe function presence */
2616 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
2617 ql_dbg(ql_dbg_p3p, vha, 0xb077,
2618 "Error while setting DRV-Presence.\n");
2619 rval = QLA_FUNCTION_FAILED;
2623 /* Decide the reset ownership */
2624 qla83xx_reset_ownership(vha);
2627 * On first protocol driver load:
2628 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2630 * Others: Check compatibility with current IDC Major version.
2632 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
2633 if (ha->flags.nic_core_reset_owner) {
2634 /* Set IDC Major version */
2635 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
2636 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
2638 /* Clearing IDC-Lock-Recovery register */
2639 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
2640 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
2642 * Clear further IDC participation if we are not compatible with
2643 * the current IDC Major Version.
2645 ql_log(ql_log_warn, vha, 0xb07d,
2646 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2647 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
2648 __qla83xx_clear_drv_presence(vha);
2649 rval = QLA_FUNCTION_FAILED;
2652 /* Each function sets its supported Minor version. */
2653 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
2654 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
2655 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
2657 if (ha->flags.nic_core_reset_owner) {
2658 memset(config, 0, sizeof(config));
2659 if (!qla81xx_get_port_config(vha, config))
2660 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
2664 rval = qla83xx_idc_state_handler(vha);
2667 qla83xx_idc_unlock(vha, 0);
2672 static void qla_enable_fce_trace(scsi_qla_host_t *vha)
2675 struct qla_hw_data *ha = vha->hw;
2678 ha->flags.fce_enabled = 1;
2679 memset(ha->fce, 0, fce_calc_size(ha->fce_bufs));
2680 rval = qla2x00_enable_fce_trace(vha,
2681 ha->fce_dma, ha->fce_bufs, ha->fce_mb, &ha->fce_bufs);
2684 ql_log(ql_log_warn, vha, 0x8033,
2685 "Unable to reinitialize FCE (%d).\n", rval);
2686 ha->flags.fce_enabled = 0;
2691 static void qla_enable_eft_trace(scsi_qla_host_t *vha)
2694 struct qla_hw_data *ha = vha->hw;
2697 memset(ha->eft, 0, EFT_SIZE);
2698 rval = qla2x00_enable_eft_trace(vha, ha->eft_dma, EFT_NUM_BUFFERS);
2701 ql_log(ql_log_warn, vha, 0x8034,
2702 "Unable to reinitialize EFT (%d).\n", rval);
2707 * qla2x00_initialize_adapter
2711 * ha = adapter block pointer.
2717 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
2720 struct qla_hw_data *ha = vha->hw;
2721 struct req_que *req = ha->req_q_map[0];
2722 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2724 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2725 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2727 /* Clear adapter flags. */
2728 vha->flags.online = 0;
2729 ha->flags.chip_reset_done = 0;
2730 vha->flags.reset_active = 0;
2731 ha->flags.pci_channel_io_perm_failure = 0;
2732 ha->flags.eeh_busy = 0;
2733 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2734 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
2735 atomic_set(&vha->loop_state, LOOP_DOWN);
2736 vha->device_flags = DFLG_NO_CABLE;
2738 vha->flags.management_server_logged_in = 0;
2739 vha->marker_needed = 0;
2740 ha->isp_abort_cnt = 0;
2741 ha->beacon_blink_led = 0;
2743 set_bit(0, ha->req_qid_map);
2744 set_bit(0, ha->rsp_qid_map);
2746 ql_dbg(ql_dbg_init, vha, 0x0040,
2747 "Configuring PCI space...\n");
2748 rval = ha->isp_ops->pci_config(vha);
2750 ql_log(ql_log_warn, vha, 0x0044,
2751 "Unable to configure PCI space.\n");
2755 ha->isp_ops->reset_chip(vha);
2757 /* Check for secure flash support */
2758 if (IS_QLA28XX(ha)) {
2759 if (rd_reg_word(®->mailbox12) & BIT_0)
2760 ha->flags.secure_adapter = 1;
2761 ql_log(ql_log_info, vha, 0xffff, "Secure Adapter: %s\n",
2762 (ha->flags.secure_adapter) ? "Yes" : "No");
2766 rval = qla2xxx_get_flash_info(vha);
2768 ql_log(ql_log_fatal, vha, 0x004f,
2769 "Unable to validate FLASH data.\n");
2773 if (IS_QLA8044(ha)) {
2774 qla8044_read_reset_template(vha);
2776 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2777 * If DONRESET_BIT0 is set, drivers should not set dev_state
2778 * to NEED_RESET. But if NEED_RESET is set, drivers should
2779 * should honor the reset. */
2780 if (ql2xdontresethba == 1)
2781 qla8044_set_idc_dontreset(vha);
2784 ha->isp_ops->get_flash_version(vha, req->ring);
2785 ql_dbg(ql_dbg_init, vha, 0x0061,
2786 "Configure NVRAM parameters...\n");
2788 /* Let priority default to FCP, can be overridden by nvram_config */
2789 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2791 ha->isp_ops->nvram_config(vha);
2793 if (ha->fc4_type_priority != FC4_PRIORITY_FCP &&
2794 ha->fc4_type_priority != FC4_PRIORITY_NVME)
2795 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2797 ql_log(ql_log_info, vha, 0xffff, "FC4 priority set to %s\n",
2798 ha->fc4_type_priority == FC4_PRIORITY_FCP ? "FCP" : "NVMe");
2800 if (ha->flags.disable_serdes) {
2801 /* Mask HBA via NVRAM settings? */
2802 ql_log(ql_log_info, vha, 0x0077,
2803 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
2804 return QLA_FUNCTION_FAILED;
2807 ql_dbg(ql_dbg_init, vha, 0x0078,
2808 "Verifying loaded RISC code...\n");
2810 /* If smartsan enabled then require fdmi and rdp enabled */
2816 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
2817 rval = ha->isp_ops->chip_diag(vha);
2820 rval = qla2x00_setup_chip(vha);
2825 if (IS_QLA84XX(ha)) {
2826 ha->cs84xx = qla84xx_get_chip(vha);
2828 ql_log(ql_log_warn, vha, 0x00d0,
2829 "Unable to configure ISP84XX.\n");
2830 return QLA_FUNCTION_FAILED;
2834 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2835 rval = qla2x00_init_rings(vha);
2837 /* No point in continuing if firmware initialization failed. */
2838 if (rval != QLA_SUCCESS)
2841 ha->flags.chip_reset_done = 1;
2843 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2844 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2845 rval = qla84xx_init_chip(vha);
2846 if (rval != QLA_SUCCESS) {
2847 ql_log(ql_log_warn, vha, 0x00d4,
2848 "Unable to initialize ISP84XX.\n");
2849 qla84xx_put_chip(vha);
2853 /* Load the NIC Core f/w if we are the first protocol driver. */
2854 if (IS_QLA8031(ha)) {
2855 rval = qla83xx_nic_core_fw_load(vha);
2857 ql_log(ql_log_warn, vha, 0x0124,
2858 "Error in initializing NIC Core f/w.\n");
2861 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2862 qla24xx_read_fcp_prio_cfg(vha);
2864 if (IS_P3P_TYPE(ha))
2865 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2867 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2873 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2876 * Returns 0 on success.
2879 qla2100_pci_config(scsi_qla_host_t *vha)
2882 unsigned long flags;
2883 struct qla_hw_data *ha = vha->hw;
2884 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2886 pci_set_master(ha->pdev);
2887 pci_try_set_mwi(ha->pdev);
2889 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2890 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2891 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2893 pci_disable_rom(ha->pdev);
2895 /* Get PCI bus information. */
2896 spin_lock_irqsave(&ha->hardware_lock, flags);
2897 ha->pci_attr = rd_reg_word(®->ctrl_status);
2898 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2904 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2907 * Returns 0 on success.
2910 qla2300_pci_config(scsi_qla_host_t *vha)
2913 unsigned long flags = 0;
2915 struct qla_hw_data *ha = vha->hw;
2916 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2918 pci_set_master(ha->pdev);
2919 pci_try_set_mwi(ha->pdev);
2921 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2922 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2924 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2925 w &= ~PCI_COMMAND_INTX_DISABLE;
2926 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2929 * If this is a 2300 card and not 2312, reset the
2930 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2931 * the 2310 also reports itself as a 2300 so we need to get the
2932 * fb revision level -- a 6 indicates it really is a 2300 and
2935 if (IS_QLA2300(ha)) {
2936 spin_lock_irqsave(&ha->hardware_lock, flags);
2939 wrt_reg_word(®->hccr, HCCR_PAUSE_RISC);
2940 for (cnt = 0; cnt < 30000; cnt++) {
2941 if ((rd_reg_word(®->hccr) & HCCR_RISC_PAUSE) != 0)
2947 /* Select FPM registers. */
2948 wrt_reg_word(®->ctrl_status, 0x20);
2949 rd_reg_word(®->ctrl_status);
2951 /* Get the fb rev level */
2952 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2954 if (ha->fb_rev == FPM_2300)
2955 pci_clear_mwi(ha->pdev);
2957 /* Deselect FPM registers. */
2958 wrt_reg_word(®->ctrl_status, 0x0);
2959 rd_reg_word(®->ctrl_status);
2961 /* Release RISC module. */
2962 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
2963 for (cnt = 0; cnt < 30000; cnt++) {
2964 if ((rd_reg_word(®->hccr) & HCCR_RISC_PAUSE) == 0)
2970 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2973 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2975 pci_disable_rom(ha->pdev);
2977 /* Get PCI bus information. */
2978 spin_lock_irqsave(&ha->hardware_lock, flags);
2979 ha->pci_attr = rd_reg_word(®->ctrl_status);
2980 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2986 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2989 * Returns 0 on success.
2992 qla24xx_pci_config(scsi_qla_host_t *vha)
2995 unsigned long flags = 0;
2996 struct qla_hw_data *ha = vha->hw;
2997 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2999 pci_set_master(ha->pdev);
3000 pci_try_set_mwi(ha->pdev);
3002 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
3003 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
3004 w &= ~PCI_COMMAND_INTX_DISABLE;
3005 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
3007 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
3009 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
3010 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
3011 pcix_set_mmrbc(ha->pdev, 2048);
3013 /* PCIe -- adjust Maximum Read Request Size (2048). */
3014 if (pci_is_pcie(ha->pdev))
3015 pcie_set_readrq(ha->pdev, 4096);
3017 pci_disable_rom(ha->pdev);
3019 ha->chip_revision = ha->pdev->revision;
3021 /* Get PCI bus information. */
3022 spin_lock_irqsave(&ha->hardware_lock, flags);
3023 ha->pci_attr = rd_reg_dword(®->ctrl_status);
3024 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3030 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
3033 * Returns 0 on success.
3036 qla25xx_pci_config(scsi_qla_host_t *vha)
3039 struct qla_hw_data *ha = vha->hw;
3041 pci_set_master(ha->pdev);
3042 pci_try_set_mwi(ha->pdev);
3044 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
3045 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
3046 w &= ~PCI_COMMAND_INTX_DISABLE;
3047 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
3049 /* PCIe -- adjust Maximum Read Request Size (2048). */
3050 if (pci_is_pcie(ha->pdev))
3051 pcie_set_readrq(ha->pdev, 4096);
3053 pci_disable_rom(ha->pdev);
3055 ha->chip_revision = ha->pdev->revision;
3061 * qla2x00_isp_firmware() - Choose firmware image.
3064 * Returns 0 on success.
3067 qla2x00_isp_firmware(scsi_qla_host_t *vha)
3070 uint16_t loop_id, topo, sw_cap;
3071 uint8_t domain, area, al_pa;
3072 struct qla_hw_data *ha = vha->hw;
3074 /* Assume loading risc code */
3075 rval = QLA_FUNCTION_FAILED;
3077 if (ha->flags.disable_risc_code_load) {
3078 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
3080 /* Verify checksum of loaded RISC code. */
3081 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
3082 if (rval == QLA_SUCCESS) {
3083 /* And, verify we are not in ROM code. */
3084 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
3085 &area, &domain, &topo, &sw_cap);
3090 ql_dbg(ql_dbg_init, vha, 0x007a,
3091 "**** Load RISC code ****.\n");
3097 * qla2x00_reset_chip() - Reset ISP chip.
3100 * Returns 0 on success.
3103 qla2x00_reset_chip(scsi_qla_host_t *vha)
3105 unsigned long flags = 0;
3106 struct qla_hw_data *ha = vha->hw;
3107 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3110 int rval = QLA_FUNCTION_FAILED;
3112 if (unlikely(pci_channel_offline(ha->pdev)))
3115 ha->isp_ops->disable_intrs(ha);
3117 spin_lock_irqsave(&ha->hardware_lock, flags);
3119 /* Turn off master enable */
3121 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
3122 cmd &= ~PCI_COMMAND_MASTER;
3123 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
3125 if (!IS_QLA2100(ha)) {
3127 wrt_reg_word(®->hccr, HCCR_PAUSE_RISC);
3128 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
3129 for (cnt = 0; cnt < 30000; cnt++) {
3130 if ((rd_reg_word(®->hccr) &
3131 HCCR_RISC_PAUSE) != 0)
3136 rd_reg_word(®->hccr); /* PCI Posting. */
3140 /* Select FPM registers. */
3141 wrt_reg_word(®->ctrl_status, 0x20);
3142 rd_reg_word(®->ctrl_status); /* PCI Posting. */
3144 /* FPM Soft Reset. */
3145 wrt_reg_word(®->fpm_diag_config, 0x100);
3146 rd_reg_word(®->fpm_diag_config); /* PCI Posting. */
3148 /* Toggle Fpm Reset. */
3149 if (!IS_QLA2200(ha)) {
3150 wrt_reg_word(®->fpm_diag_config, 0x0);
3151 rd_reg_word(®->fpm_diag_config); /* PCI Posting. */
3154 /* Select frame buffer registers. */
3155 wrt_reg_word(®->ctrl_status, 0x10);
3156 rd_reg_word(®->ctrl_status); /* PCI Posting. */
3158 /* Reset frame buffer FIFOs. */
3159 if (IS_QLA2200(ha)) {
3160 WRT_FB_CMD_REG(ha, reg, 0xa000);
3161 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
3163 WRT_FB_CMD_REG(ha, reg, 0x00fc);
3165 /* Read back fb_cmd until zero or 3 seconds max */
3166 for (cnt = 0; cnt < 3000; cnt++) {
3167 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
3173 /* Select RISC module registers. */
3174 wrt_reg_word(®->ctrl_status, 0);
3175 rd_reg_word(®->ctrl_status); /* PCI Posting. */
3177 /* Reset RISC processor. */
3178 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
3179 rd_reg_word(®->hccr); /* PCI Posting. */
3181 /* Release RISC processor. */
3182 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
3183 rd_reg_word(®->hccr); /* PCI Posting. */
3186 wrt_reg_word(®->hccr, HCCR_CLR_RISC_INT);
3187 wrt_reg_word(®->hccr, HCCR_CLR_HOST_INT);
3189 /* Reset ISP chip. */
3190 wrt_reg_word(®->ctrl_status, CSR_ISP_SOFT_RESET);
3192 /* Wait for RISC to recover from reset. */
3193 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
3195 * It is necessary to for a delay here since the card doesn't
3196 * respond to PCI reads during a reset. On some architectures
3197 * this will result in an MCA.
3200 for (cnt = 30000; cnt; cnt--) {
3201 if ((rd_reg_word(®->ctrl_status) &
3202 CSR_ISP_SOFT_RESET) == 0)
3209 /* Reset RISC processor. */
3210 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
3212 wrt_reg_word(®->semaphore, 0);
3214 /* Release RISC processor. */
3215 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
3216 rd_reg_word(®->hccr); /* PCI Posting. */
3218 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
3219 for (cnt = 0; cnt < 30000; cnt++) {
3220 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
3228 /* Turn on master enable */
3229 cmd |= PCI_COMMAND_MASTER;
3230 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
3232 /* Disable RISC pause on FPM parity error. */
3233 if (!IS_QLA2100(ha)) {
3234 wrt_reg_word(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
3235 rd_reg_word(®->hccr); /* PCI Posting. */
3238 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3244 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
3247 * Returns 0 on success.
3250 qla81xx_reset_mpi(scsi_qla_host_t *vha)
3252 uint16_t mb[4] = {0x1010, 0, 1, 0};
3254 if (!IS_QLA81XX(vha->hw))
3257 return qla81xx_write_mpi_register(vha, mb);
3261 qla_chk_risc_recovery(scsi_qla_host_t *vha)
3263 struct qla_hw_data *ha = vha->hw;
3264 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3265 __le16 __iomem *mbptr = ®->mailbox0;
3268 int rc = QLA_SUCCESS;
3270 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3273 /* this check is only valid after RISC reset */
3274 mb[0] = rd_reg_word(mbptr);
3277 rc = QLA_FUNCTION_FAILED;
3279 for (i = 1; i < 32; i++) {
3280 mb[i] = rd_reg_word(mbptr);
3284 ql_log(ql_log_warn, vha, 0x1015,
3285 "RISC reset failed. mb[0-7] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
3286 mb[0], mb[1], mb[2], mb[3], mb[4], mb[5], mb[6], mb[7]);
3287 ql_log(ql_log_warn, vha, 0x1015,
3288 "RISC reset failed. mb[8-15] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
3289 mb[8], mb[9], mb[10], mb[11], mb[12], mb[13], mb[14],
3291 ql_log(ql_log_warn, vha, 0x1015,
3292 "RISC reset failed. mb[16-23] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
3293 mb[16], mb[17], mb[18], mb[19], mb[20], mb[21], mb[22],
3295 ql_log(ql_log_warn, vha, 0x1015,
3296 "RISC reset failed. mb[24-31] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
3297 mb[24], mb[25], mb[26], mb[27], mb[28], mb[29], mb[30],
3304 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
3307 * Returns 0 on success.
3310 qla24xx_reset_risc(scsi_qla_host_t *vha)
3312 unsigned long flags = 0;
3313 struct qla_hw_data *ha = vha->hw;
3314 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3317 static int abts_cnt; /* ISP abort retry counts */
3318 int rval = QLA_SUCCESS;
3321 spin_lock_irqsave(&ha->hardware_lock, flags);
3324 wrt_reg_dword(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
3325 for (cnt = 0; cnt < 30000; cnt++) {
3326 if ((rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
3332 if (!(rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE))
3333 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
3335 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
3336 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
3337 rd_reg_dword(®->hccr),
3338 rd_reg_dword(®->ctrl_status),
3339 (rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE));
3341 wrt_reg_dword(®->ctrl_status,
3342 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
3343 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
3347 /* Wait for firmware to complete NVRAM accesses. */
3348 rd_reg_word(®->mailbox0);
3349 for (cnt = 10000; rd_reg_word(®->mailbox0) != 0 &&
3350 rval == QLA_SUCCESS; cnt--) {
3355 rval = QLA_FUNCTION_TIMEOUT;
3358 if (rval == QLA_SUCCESS)
3359 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
3361 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
3362 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
3363 rd_reg_dword(®->hccr),
3364 rd_reg_word(®->mailbox0));
3366 /* Wait for soft-reset to complete. */
3367 rd_reg_dword(®->ctrl_status);
3368 for (cnt = 0; cnt < 60; cnt++) {
3370 if ((rd_reg_dword(®->ctrl_status) &
3371 CSRX_ISP_SOFT_RESET) == 0)
3376 if (!(rd_reg_dword(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
3377 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
3379 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
3380 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
3381 rd_reg_dword(®->hccr),
3382 rd_reg_dword(®->ctrl_status));
3384 /* If required, do an MPI FW reset now */
3385 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
3386 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
3387 if (++abts_cnt < 5) {
3388 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3389 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
3392 * We exhausted the ISP abort retries. We have to
3393 * set the board offline.
3396 vha->flags.online = 0;
3401 wrt_reg_dword(®->hccr, HCCRX_SET_RISC_RESET);
3402 rd_reg_dword(®->hccr);
3404 wrt_reg_dword(®->hccr, HCCRX_REL_RISC_PAUSE);
3405 rd_reg_dword(®->hccr);
3407 wrt_reg_dword(®->hccr, HCCRX_CLR_RISC_RESET);
3409 rd_reg_dword(®->hccr);
3411 wd = rd_reg_word(®->mailbox0);
3412 for (cnt = 300; wd != 0 && rval == QLA_SUCCESS; cnt--) {
3416 if (print && qla_chk_risc_recovery(vha))
3419 wd = rd_reg_word(®->mailbox0);
3421 rval = QLA_FUNCTION_TIMEOUT;
3423 ql_log(ql_log_warn, vha, 0x015e,
3424 "RISC reset timeout\n");
3428 if (rval == QLA_SUCCESS)
3429 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
3431 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
3432 "Host Risc 0x%x, mailbox0 0x%x\n",
3433 rd_reg_dword(®->hccr),
3434 rd_reg_word(®->mailbox0));
3436 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3438 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
3439 "Driver in %s mode\n",
3440 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
3442 if (IS_NOPOLLING_TYPE(ha))
3443 ha->isp_ops->enable_intrs(ha);
3449 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
3451 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
3453 wrt_reg_dword(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
3454 *data = rd_reg_dword(®->iobase_window + RISC_REGISTER_WINDOW_OFFSET);
3458 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
3460 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
3462 wrt_reg_dword(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
3463 wrt_reg_dword(®->iobase_window + RISC_REGISTER_WINDOW_OFFSET, data);
3467 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
3470 uint delta_msec = 100;
3471 uint elapsed_msec = 0;
3475 if (vha->hw->pdev->subsystem_device != 0x0175 &&
3476 vha->hw->pdev->subsystem_device != 0x0240)
3479 wrt_reg_dword(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
3483 timeout_msec = TIMEOUT_SEMAPHORE;
3484 n = timeout_msec / delta_msec;
3486 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
3487 qla25xx_read_risc_sema_reg(vha, &wd32);
3488 if (wd32 & RISC_SEMAPHORE)
3491 elapsed_msec += delta_msec;
3492 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
3496 if (!(wd32 & RISC_SEMAPHORE))
3499 if (!(wd32 & RISC_SEMAPHORE_FORCE))
3502 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
3503 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
3504 n = timeout_msec / delta_msec;
3506 qla25xx_read_risc_sema_reg(vha, &wd32);
3507 if (!(wd32 & RISC_SEMAPHORE_FORCE))
3510 elapsed_msec += delta_msec;
3511 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
3515 if (wd32 & RISC_SEMAPHORE_FORCE)
3516 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
3521 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
3528 * qla24xx_reset_chip() - Reset ISP24xx chip.
3531 * Returns 0 on success.
3534 qla24xx_reset_chip(scsi_qla_host_t *vha)
3536 struct qla_hw_data *ha = vha->hw;
3537 int rval = QLA_FUNCTION_FAILED;
3539 if (pci_channel_offline(ha->pdev) &&
3540 ha->flags.pci_channel_io_perm_failure) {
3544 ha->isp_ops->disable_intrs(ha);
3546 qla25xx_manipulate_risc_semaphore(vha);
3548 /* Perform RISC reset. */
3549 rval = qla24xx_reset_risc(vha);
3555 * qla2x00_chip_diag() - Test chip for proper operation.
3558 * Returns 0 on success.
3561 qla2x00_chip_diag(scsi_qla_host_t *vha)
3564 struct qla_hw_data *ha = vha->hw;
3565 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3566 unsigned long flags = 0;
3570 struct req_que *req = ha->req_q_map[0];
3572 /* Assume a failed state */
3573 rval = QLA_FUNCTION_FAILED;
3575 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
3576 ®->flash_address);
3578 spin_lock_irqsave(&ha->hardware_lock, flags);
3580 /* Reset ISP chip. */
3581 wrt_reg_word(®->ctrl_status, CSR_ISP_SOFT_RESET);
3584 * We need to have a delay here since the card will not respond while
3585 * in reset causing an MCA on some architectures.
3588 data = qla2x00_debounce_register(®->ctrl_status);
3589 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
3591 data = rd_reg_word(®->ctrl_status);
3596 goto chip_diag_failed;
3598 ql_dbg(ql_dbg_init, vha, 0x007c,
3599 "Reset register cleared by chip reset.\n");
3601 /* Reset RISC processor. */
3602 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
3603 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
3605 /* Workaround for QLA2312 PCI parity error */
3606 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
3607 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
3608 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
3610 data = RD_MAILBOX_REG(ha, reg, 0);
3617 goto chip_diag_failed;
3619 /* Check product ID of chip */
3620 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
3622 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
3623 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
3624 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
3625 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
3626 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
3627 mb[3] != PROD_ID_3) {
3628 ql_log(ql_log_warn, vha, 0x0062,
3629 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
3630 mb[1], mb[2], mb[3]);
3632 goto chip_diag_failed;
3634 ha->product_id[0] = mb[1];
3635 ha->product_id[1] = mb[2];
3636 ha->product_id[2] = mb[3];
3637 ha->product_id[3] = mb[4];
3639 /* Adjust fw RISC transfer size */
3640 if (req->length > 1024)
3641 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
3643 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
3646 if (IS_QLA2200(ha) &&
3647 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
3648 /* Limit firmware transfer size with a 2200A */
3649 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
3651 ha->device_type |= DT_ISP2200A;
3652 ha->fw_transfer_size = 128;
3655 /* Wrap Incoming Mailboxes Test. */
3656 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3658 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
3659 rval = qla2x00_mbx_reg_test(vha);
3661 ql_log(ql_log_warn, vha, 0x0080,
3662 "Failed mailbox send register test.\n");
3664 /* Flag a successful rval */
3666 spin_lock_irqsave(&ha->hardware_lock, flags);
3670 ql_log(ql_log_info, vha, 0x0081,
3671 "Chip diagnostics **** FAILED ****.\n");
3673 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3679 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3682 * Returns 0 on success.
3685 qla24xx_chip_diag(scsi_qla_host_t *vha)
3688 struct qla_hw_data *ha = vha->hw;
3689 struct req_que *req = ha->req_q_map[0];
3691 if (IS_P3P_TYPE(ha))
3694 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
3696 rval = qla2x00_mbx_reg_test(vha);
3698 ql_log(ql_log_warn, vha, 0x0082,
3699 "Failed mailbox send register test.\n");
3701 /* Flag a successful rval */
3709 qla2x00_alloc_fce_trace(scsi_qla_host_t *vha)
3713 struct qla_hw_data *ha = vha->hw;
3715 if (!IS_FWI2_CAPABLE(ha))
3718 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3719 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3723 ql_dbg(ql_dbg_init, vha, 0x00bd,
3724 "%s: FCE Mem is already allocated.\n",
3729 /* Allocate memory for Fibre Channel Event Buffer. */
3730 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3733 ql_log(ql_log_warn, vha, 0x00be,
3734 "Unable to allocate (%d KB) for FCE.\n",
3739 ql_dbg(ql_dbg_init, vha, 0x00c0,
3740 "Allocated (%d KB) for FCE...\n", FCE_SIZE / 1024);
3742 ha->fce_dma = tc_dma;
3744 ha->fce_bufs = FCE_NUM_BUFFERS;
3748 qla2x00_alloc_eft_trace(scsi_qla_host_t *vha)
3752 struct qla_hw_data *ha = vha->hw;
3754 if (!IS_FWI2_CAPABLE(ha))
3758 ql_dbg(ql_dbg_init, vha, 0x00bd,
3759 "%s: EFT Mem is already allocated.\n",
3764 /* Allocate memory for Extended Trace Buffer. */
3765 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3768 ql_log(ql_log_warn, vha, 0x00c1,
3769 "Unable to allocate (%d KB) for EFT.\n",
3774 ql_dbg(ql_dbg_init, vha, 0x00c3,
3775 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3777 ha->eft_dma = tc_dma;
3782 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3784 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
3785 eft_size, fce_size, mq_size;
3786 struct qla_hw_data *ha = vha->hw;
3787 struct req_que *req = ha->req_q_map[0];
3788 struct rsp_que *rsp = ha->rsp_q_map[0];
3789 struct qla2xxx_fw_dump *fw_dump;
3792 ql_dbg(ql_dbg_init, vha, 0x00bd,
3793 "Firmware dump already allocated.\n");
3798 ha->fw_dump_cap_flags = 0;
3799 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
3800 req_q_size = rsp_q_size = 0;
3802 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3803 fixed_size = sizeof(struct qla2100_fw_dump);
3804 } else if (IS_QLA23XX(ha)) {
3805 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
3806 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
3808 } else if (IS_FWI2_CAPABLE(ha)) {
3810 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
3811 else if (IS_QLA81XX(ha))
3812 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
3813 else if (IS_QLA25XX(ha))
3814 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
3816 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
3818 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
3821 if (!IS_QLA83XX(ha))
3822 mq_size = sizeof(struct qla2xxx_mq_chain);
3824 * Allocate maximum buffer size for all queues - Q0.
3825 * Resizing must be done at end-of-dump processing.
3827 mq_size += (ha->max_req_queues - 1) *
3828 (req->length * sizeof(request_t));
3829 mq_size += (ha->max_rsp_queues - 1) *
3830 (rsp->length * sizeof(response_t));
3832 if (ha->tgt.atio_ring)
3833 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3835 qla2x00_alloc_fce_trace(vha);
3837 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3838 qla2x00_alloc_eft_trace(vha);
3840 eft_size = EFT_SIZE;
3843 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3844 struct fwdt *fwdt = ha->fwdt;
3847 for (j = 0; j < 2; j++, fwdt++) {
3848 if (!fwdt->template) {
3849 ql_dbg(ql_dbg_init, vha, 0x00ba,
3850 "-> fwdt%u no template\n", j);
3853 ql_dbg(ql_dbg_init, vha, 0x00fa,
3854 "-> fwdt%u calculating fwdump size...\n", j);
3855 fwdt->dump_size = qla27xx_fwdt_calculate_dump_size(
3856 vha, fwdt->template);
3857 ql_dbg(ql_dbg_init, vha, 0x00fa,
3858 "-> fwdt%u calculated fwdump size = %#lx bytes\n",
3859 j, fwdt->dump_size);
3860 dump_size += fwdt->dump_size;
3862 /* Add space for spare MPI fw dump. */
3863 dump_size += ha->fwdt[1].dump_size;
3865 req_q_size = req->length * sizeof(request_t);
3866 rsp_q_size = rsp->length * sizeof(response_t);
3867 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3868 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size
3870 ha->chain_offset = dump_size;
3871 dump_size += mq_size + fce_size;
3872 if (ha->exchoffld_buf)
3873 dump_size += sizeof(struct qla2xxx_offld_chain) +
3875 if (ha->exlogin_buf)
3876 dump_size += sizeof(struct qla2xxx_offld_chain) +
3880 if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) {
3882 ql_dbg(ql_dbg_init, vha, 0x00c5,
3883 "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n",
3884 __func__, dump_size, ha->fw_dump_len,
3885 ha->fw_dump_alloc_len);
3887 fw_dump = vmalloc(dump_size);
3889 ql_log(ql_log_warn, vha, 0x00c4,
3890 "Unable to allocate (%d KB) for firmware dump.\n",
3893 mutex_lock(&ha->optrom_mutex);
3894 if (ha->fw_dumped) {
3895 memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len);
3897 ha->fw_dump = fw_dump;
3898 ha->fw_dump_alloc_len = dump_size;
3899 ql_dbg(ql_dbg_init, vha, 0x00c5,
3900 "Re-Allocated (%d KB) and save firmware dump.\n",
3904 ha->fw_dump = fw_dump;
3906 ha->fw_dump_len = ha->fw_dump_alloc_len =
3908 ql_dbg(ql_dbg_init, vha, 0x00c5,
3909 "Allocated (%d KB) for firmware dump.\n",
3912 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3913 ha->mpi_fw_dump = (char *)fw_dump +
3914 ha->fwdt[1].dump_size;
3915 mutex_unlock(&ha->optrom_mutex);
3919 ha->fw_dump->signature[0] = 'Q';
3920 ha->fw_dump->signature[1] = 'L';
3921 ha->fw_dump->signature[2] = 'G';
3922 ha->fw_dump->signature[3] = 'C';
3923 ha->fw_dump->version = htonl(1);
3925 ha->fw_dump->fixed_size = htonl(fixed_size);
3926 ha->fw_dump->mem_size = htonl(mem_size);
3927 ha->fw_dump->req_q_size = htonl(req_q_size);
3928 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3930 ha->fw_dump->eft_size = htonl(eft_size);
3931 ha->fw_dump->eft_addr_l =
3932 htonl(LSD(ha->eft_dma));
3933 ha->fw_dump->eft_addr_h =
3934 htonl(MSD(ha->eft_dma));
3936 ha->fw_dump->header_size =
3938 (struct qla2xxx_fw_dump, isp));
3940 mutex_unlock(&ha->optrom_mutex);
3946 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3948 #define MPS_MASK 0xe0
3953 if (!IS_QLA81XX(vha->hw))
3956 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3957 if (rval != QLA_SUCCESS) {
3958 ql_log(ql_log_warn, vha, 0x0105,
3959 "Unable to acquire semaphore.\n");
3963 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3964 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3965 if (rval != QLA_SUCCESS) {
3966 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3971 if (dc == (dw & MPS_MASK))
3976 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3977 if (rval != QLA_SUCCESS) {
3978 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3982 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3983 if (rval != QLA_SUCCESS) {
3984 ql_log(ql_log_warn, vha, 0x006d,
3985 "Unable to release semaphore.\n");
3993 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3995 /* Don't try to reallocate the array */
3996 if (req->outstanding_cmds)
3999 if (!IS_FWI2_CAPABLE(ha))
4000 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
4002 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
4003 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
4005 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
4008 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
4012 if (!req->outstanding_cmds) {
4014 * Try to allocate a minimal size just so we can get through
4017 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
4018 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
4022 if (!req->outstanding_cmds) {
4023 ql_log(ql_log_fatal, NULL, 0x0126,
4024 "Failed to allocate memory for "
4025 "outstanding_cmds for req_que %p.\n", req);
4026 req->num_outstanding_cmds = 0;
4027 return QLA_FUNCTION_FAILED;
4034 #define PRINT_FIELD(_field, _flag, _str) { \
4035 if (a0->_field & _flag) {\
4041 len = snprintf(ptr, leftover, "%s", _str); \
4048 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
4051 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
4052 u8 str[STR_LEN], *ptr, p;
4055 memset(str, 0, STR_LEN);
4056 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
4057 ql_dbg(ql_dbg_init, vha, 0x015a,
4058 "SFP MFG Name: %s\n", str);
4060 memset(str, 0, STR_LEN);
4061 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
4062 ql_dbg(ql_dbg_init, vha, 0x015c,
4063 "SFP Part Name: %s\n", str);
4066 memset(str, 0, STR_LEN);
4070 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
4071 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
4072 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
4073 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
4074 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
4075 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
4076 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
4077 ql_dbg(ql_dbg_init, vha, 0x0160,
4078 "SFP Media: %s\n", str);
4081 memset(str, 0, STR_LEN);
4085 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
4086 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
4087 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
4088 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
4089 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
4090 ql_dbg(ql_dbg_init, vha, 0x0196,
4091 "SFP Link Length: %s\n", str);
4093 memset(str, 0, STR_LEN);
4097 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
4098 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
4099 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
4100 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
4101 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
4102 ql_dbg(ql_dbg_init, vha, 0x016e,
4103 "SFP FC Link Tech: %s\n", str);
4106 ql_dbg(ql_dbg_init, vha, 0x016f,
4107 "SFP Distant: %d km\n", a0->length_km);
4108 if (a0->length_100m)
4109 ql_dbg(ql_dbg_init, vha, 0x0170,
4110 "SFP Distant: %d m\n", a0->length_100m*100);
4111 if (a0->length_50um_10m)
4112 ql_dbg(ql_dbg_init, vha, 0x0189,
4113 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
4114 if (a0->length_62um_10m)
4115 ql_dbg(ql_dbg_init, vha, 0x018a,
4116 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
4117 if (a0->length_om4_10m)
4118 ql_dbg(ql_dbg_init, vha, 0x0194,
4119 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
4120 if (a0->length_om3_10m)
4121 ql_dbg(ql_dbg_init, vha, 0x0195,
4122 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
4127 * qla24xx_detect_sfp()
4129 * @vha: adapter state pointer.
4132 * 0 -- Configure firmware to use short-range settings -- normal
4133 * buffer-to-buffer credits.
4135 * 1 -- Configure firmware to use long-range settings -- extra
4136 * buffer-to-buffer credits should be allocated with
4137 * ha->lr_distance containing distance settings from NVRAM or SFP
4141 qla24xx_detect_sfp(scsi_qla_host_t *vha)
4144 struct sff_8247_a0 *a;
4145 struct qla_hw_data *ha = vha->hw;
4146 struct nvram_81xx *nv = ha->nvram;
4147 #define LR_DISTANCE_UNKNOWN 2
4148 static const char * const types[] = { "Short", "Long" };
4149 static const char * const lengths[] = { "(10km)", "(5km)", "" };
4152 /* Seed with NVRAM settings. */
4154 ha->flags.lr_detected = 0;
4155 if (IS_BPM_RANGE_CAPABLE(ha) &&
4156 (nv->enhanced_features & NEF_LR_DIST_ENABLE)) {
4158 ha->flags.lr_detected = 1;
4160 (nv->enhanced_features >> LR_DIST_NV_POS)
4164 if (!IS_BPM_ENABLED(vha))
4166 /* Determine SR/LR capabilities of SFP/Transceiver. */
4167 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
4172 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
4173 qla2xxx_print_sfp_info(vha);
4175 ha->flags.lr_detected = 0;
4177 if (ll & FC_LL_VL || ll & FC_LL_L) {
4178 /* Long range, track length. */
4179 ha->flags.lr_detected = 1;
4181 if (a->length_km > 5 || a->length_100m > 50)
4182 ha->lr_distance = LR_DISTANCE_10K;
4184 ha->lr_distance = LR_DISTANCE_5K;
4188 ql_dbg(ql_dbg_async, vha, 0x507b,
4189 "SFP detect: %s-Range SFP %s (nvr=%x ll=%x lr=%x lrd=%x).\n",
4190 types[ha->flags.lr_detected],
4191 ha->flags.lr_detected ? lengths[ha->lr_distance] :
4192 lengths[LR_DISTANCE_UNKNOWN],
4193 used_nvram, ll, ha->flags.lr_detected, ha->lr_distance);
4194 return ha->flags.lr_detected;
4197 static void __qla_adjust_iocb_limit(struct qla_qpair *qpair)
4201 struct qla_hw_data *ha = qpair->vha->hw;
4203 num_qps = ha->num_qpairs + 1;
4204 limit = (ha->orig_fw_iocb_count * QLA_IOCB_PCT_LIMIT) / 100;
4206 qpair->fwres.iocbs_total = ha->orig_fw_iocb_count;
4207 qpair->fwres.iocbs_limit = limit;
4208 qpair->fwres.iocbs_qp_limit = limit / num_qps;
4210 qpair->fwres.exch_total = ha->orig_fw_xcb_count;
4211 qpair->fwres.exch_limit = (ha->orig_fw_xcb_count *
4212 QLA_IOCB_PCT_LIMIT) / 100;
4215 void qla_init_iocb_limit(scsi_qla_host_t *vha)
4218 struct qla_hw_data *ha = vha->hw;
4220 __qla_adjust_iocb_limit(ha->base_qpair);
4221 ha->base_qpair->fwres.iocbs_used = 0;
4222 ha->base_qpair->fwres.exch_used = 0;
4224 for (i = 0; i < ha->max_qpairs; i++) {
4225 if (ha->queue_pair_map[i]) {
4226 __qla_adjust_iocb_limit(ha->queue_pair_map[i]);
4227 ha->queue_pair_map[i]->fwres.iocbs_used = 0;
4228 ha->queue_pair_map[i]->fwres.exch_used = 0;
4232 ha->fwres.iocb_total = ha->orig_fw_iocb_count;
4233 ha->fwres.iocb_limit = (ha->orig_fw_iocb_count * QLA_IOCB_PCT_LIMIT) / 100;
4234 ha->fwres.exch_total = ha->orig_fw_xcb_count;
4235 ha->fwres.exch_limit = (ha->orig_fw_xcb_count * QLA_IOCB_PCT_LIMIT) / 100;
4237 atomic_set(&ha->fwres.iocb_used, 0);
4238 atomic_set(&ha->fwres.exch_used, 0);
4241 void qla_adjust_iocb_limit(scsi_qla_host_t *vha)
4244 struct qla_hw_data *ha = vha->hw;
4246 __qla_adjust_iocb_limit(ha->base_qpair);
4248 for (i = 0; i < ha->max_qpairs; i++) {
4249 if (ha->queue_pair_map[i])
4250 __qla_adjust_iocb_limit(ha->queue_pair_map[i]);
4255 * qla2x00_setup_chip() - Load and start RISC firmware.
4258 * Returns 0 on success.
4261 qla2x00_setup_chip(scsi_qla_host_t *vha)
4264 uint32_t srisc_address = 0;
4265 struct qla_hw_data *ha = vha->hw;
4266 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4267 unsigned long flags;
4270 if (IS_P3P_TYPE(ha)) {
4271 rval = ha->isp_ops->load_risc(vha, &srisc_address);
4272 if (rval == QLA_SUCCESS) {
4273 qla2x00_stop_firmware(vha);
4274 goto enable_82xx_npiv;
4279 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
4280 /* Disable SRAM, Instruction RAM and GP RAM parity. */
4281 spin_lock_irqsave(&ha->hardware_lock, flags);
4282 wrt_reg_word(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
4283 rd_reg_word(®->hccr);
4284 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4287 qla81xx_mpi_sync(vha);
4290 /* Load firmware sequences */
4291 rval = ha->isp_ops->load_risc(vha, &srisc_address);
4292 if (rval == QLA_SUCCESS) {
4293 ql_dbg(ql_dbg_init, vha, 0x00c9,
4294 "Verifying Checksum of loaded RISC code.\n");
4296 rval = qla2x00_verify_checksum(vha, srisc_address);
4297 if (rval == QLA_SUCCESS) {
4298 /* Start firmware execution. */
4299 ql_dbg(ql_dbg_init, vha, 0x00ca,
4300 "Starting firmware.\n");
4303 ha->flags.exlogins_enabled = 1;
4305 if (qla_is_exch_offld_enabled(vha))
4306 ha->flags.exchoffld_enabled = 1;
4308 rval = qla2x00_execute_fw(vha, srisc_address);
4309 /* Retrieve firmware information. */
4310 if (rval == QLA_SUCCESS) {
4311 /* Enable BPM support? */
4312 if (!done_once++ && qla24xx_detect_sfp(vha)) {
4313 ql_dbg(ql_dbg_init, vha, 0x00ca,
4314 "Re-starting firmware -- BPM.\n");
4315 /* Best-effort - re-init. */
4316 ha->isp_ops->reset_chip(vha);
4317 ha->isp_ops->chip_diag(vha);
4318 goto execute_fw_with_lr;
4321 if (IS_ZIO_THRESHOLD_CAPABLE(ha))
4322 qla27xx_set_zio_threshold(vha,
4323 ha->last_zio_threshold);
4325 rval = qla2x00_set_exlogins_buffer(vha);
4326 if (rval != QLA_SUCCESS)
4329 rval = qla2x00_set_exchoffld_buffer(vha);
4330 if (rval != QLA_SUCCESS)
4334 if (IS_P3P_TYPE(ha))
4335 qla82xx_check_md_needed(vha);
4337 rval = qla2x00_get_fw_version(vha);
4338 if (rval != QLA_SUCCESS)
4340 ha->flags.npiv_supported = 0;
4341 if (IS_QLA2XXX_MIDTYPE(ha) &&
4342 (ha->fw_attributes & BIT_2)) {
4343 ha->flags.npiv_supported = 1;
4344 if ((!ha->max_npiv_vports) ||
4345 ((ha->max_npiv_vports + 1) %
4346 MIN_MULTI_ID_FABRIC))
4347 ha->max_npiv_vports =
4348 MIN_MULTI_ID_FABRIC - 1;
4350 qla2x00_get_resource_cnts(vha);
4351 qla_init_iocb_limit(vha);
4354 * Allocate the array of outstanding commands
4355 * now that we know the firmware resources.
4357 rval = qla2x00_alloc_outstanding_cmds(ha,
4359 if (rval != QLA_SUCCESS)
4362 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
4363 qla2x00_alloc_fw_dump(vha);
4365 qla_enable_fce_trace(vha);
4366 qla_enable_eft_trace(vha);
4371 ql_log(ql_log_fatal, vha, 0x00cd,
4372 "ISP Firmware failed checksum.\n");
4376 /* Enable PUREX PASSTHRU */
4377 if (ql2xrdpenable || ha->flags.scm_supported_f ||
4378 ha->flags.edif_enabled)
4379 qla25xx_set_els_cmds_supported(vha);
4383 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
4384 /* Enable proper parity. */
4385 spin_lock_irqsave(&ha->hardware_lock, flags);
4388 wrt_reg_word(®->hccr, HCCR_ENABLE_PARITY + 0x1);
4390 /* SRAM, Instruction RAM and GP RAM parity */
4391 wrt_reg_word(®->hccr, HCCR_ENABLE_PARITY + 0x7);
4392 rd_reg_word(®->hccr);
4393 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4396 if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
4397 ha->flags.fac_supported = 1;
4398 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
4401 rval = qla81xx_fac_get_sector_size(vha, &size);
4402 if (rval == QLA_SUCCESS) {
4403 ha->flags.fac_supported = 1;
4404 ha->fdt_block_size = size << 2;
4406 ql_log(ql_log_warn, vha, 0x00ce,
4407 "Unsupported FAC firmware (%d.%02d.%02d).\n",
4408 ha->fw_major_version, ha->fw_minor_version,
4409 ha->fw_subminor_version);
4411 if (IS_QLA83XX(ha)) {
4412 ha->flags.fac_supported = 0;
4419 ql_log(ql_log_fatal, vha, 0x00cf,
4420 "Setup chip ****FAILED****.\n");
4427 * qla2x00_init_response_q_entries() - Initializes response queue entries.
4428 * @rsp: response queue
4430 * Beginning of request ring has initialization control block already built
4431 * by nvram config routine.
4433 * Returns 0 on success.
4436 qla2x00_init_response_q_entries(struct rsp_que *rsp)
4441 rsp->ring_ptr = rsp->ring;
4442 rsp->ring_index = 0;
4443 rsp->status_srb = NULL;
4444 pkt = rsp->ring_ptr;
4445 for (cnt = 0; cnt < rsp->length; cnt++) {
4446 pkt->signature = RESPONSE_PROCESSED;
4452 * qla2x00_update_fw_options() - Read and process firmware options.
4455 * Returns 0 on success.
4458 qla2x00_update_fw_options(scsi_qla_host_t *vha)
4460 uint16_t swing, emphasis, tx_sens, rx_sens;
4461 struct qla_hw_data *ha = vha->hw;
4463 memset(ha->fw_options, 0, sizeof(ha->fw_options));
4464 qla2x00_get_fw_options(vha, ha->fw_options);
4466 if (IS_QLA2100(ha) || IS_QLA2200(ha))
4469 /* Serial Link options. */
4470 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
4471 "Serial link options.\n");
4472 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
4473 ha->fw_seriallink_options, sizeof(ha->fw_seriallink_options));
4475 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
4476 if (ha->fw_seriallink_options[3] & BIT_2) {
4477 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
4480 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
4481 emphasis = (ha->fw_seriallink_options[2] &
4482 (BIT_4 | BIT_3)) >> 3;
4483 tx_sens = ha->fw_seriallink_options[0] &
4484 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4485 rx_sens = (ha->fw_seriallink_options[0] &
4486 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
4487 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
4488 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
4491 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
4492 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
4493 ha->fw_options[10] |= BIT_5 |
4494 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
4495 (tx_sens & (BIT_1 | BIT_0));
4498 swing = (ha->fw_seriallink_options[2] &
4499 (BIT_7 | BIT_6 | BIT_5)) >> 5;
4500 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
4501 tx_sens = ha->fw_seriallink_options[1] &
4502 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4503 rx_sens = (ha->fw_seriallink_options[1] &
4504 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
4505 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
4506 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
4509 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
4510 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
4511 ha->fw_options[11] |= BIT_5 |
4512 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
4513 (tx_sens & (BIT_1 | BIT_0));
4517 /* Return command IOCBs without waiting for an ABTS to complete. */
4518 ha->fw_options[3] |= BIT_13;
4521 if (ha->flags.enable_led_scheme)
4522 ha->fw_options[2] |= BIT_12;
4524 /* Detect ISP6312. */
4526 ha->fw_options[2] |= BIT_13;
4528 /* Set Retry FLOGI in case of P2P connection */
4529 if (ha->operating_mode == P2P) {
4530 ha->fw_options[2] |= BIT_3;
4531 ql_dbg(ql_dbg_disc, vha, 0x2100,
4532 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
4533 __func__, ha->fw_options[2]);
4536 /* Update firmware options. */
4537 qla2x00_set_fw_options(vha, ha->fw_options);
4541 qla24xx_update_fw_options(scsi_qla_host_t *vha)
4544 struct qla_hw_data *ha = vha->hw;
4546 if (IS_P3P_TYPE(ha))
4549 /* Hold status IOCBs until ABTS response received. */
4551 ha->fw_options[3] |= BIT_12;
4553 /* Set Retry FLOGI in case of P2P connection */
4554 if (ha->operating_mode == P2P) {
4555 ha->fw_options[2] |= BIT_3;
4556 ql_dbg(ql_dbg_disc, vha, 0x2101,
4557 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
4558 __func__, ha->fw_options[2]);
4561 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
4562 if (ql2xmvasynctoatio && !ha->flags.edif_enabled &&
4563 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
4564 if (qla_tgt_mode_enabled(vha) ||
4565 qla_dual_mode_enabled(vha))
4566 ha->fw_options[2] |= BIT_11;
4568 ha->fw_options[2] &= ~BIT_11;
4571 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4574 * Tell FW to track each exchange to prevent
4575 * driver from using stale exchange.
4577 if (qla_tgt_mode_enabled(vha) ||
4578 qla_dual_mode_enabled(vha))
4579 ha->fw_options[2] |= BIT_4;
4581 ha->fw_options[2] &= ~(BIT_4);
4583 /* Reserve 1/2 of emergency exchanges for ELS.*/
4584 if (qla2xuseresexchforels)
4585 ha->fw_options[2] |= BIT_8;
4587 ha->fw_options[2] &= ~BIT_8;
4590 * N2N: set Secure=1 for PLOGI ACC and
4591 * fw shal not send PRLI after PLOGI Acc
4593 if (ha->flags.edif_enabled &&
4594 DBELL_ACTIVE(vha)) {
4595 ha->fw_options[3] |= BIT_15;
4596 ha->flags.n2n_fw_acc_sec = 1;
4598 ha->fw_options[3] &= ~BIT_15;
4599 ha->flags.n2n_fw_acc_sec = 0;
4603 if (ql2xrdpenable || ha->flags.scm_supported_f ||
4604 ha->flags.edif_enabled)
4605 ha->fw_options[1] |= ADD_FO1_ENABLE_PUREX_IOCB;
4607 /* Enable Async 8130/8131 events -- transceiver insertion/removal */
4608 if (IS_BPM_RANGE_CAPABLE(ha))
4609 ha->fw_options[3] |= BIT_10;
4611 ql_dbg(ql_dbg_init, vha, 0x00e8,
4612 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
4613 __func__, ha->fw_options[1], ha->fw_options[2],
4614 ha->fw_options[3], vha->host->active_mode);
4616 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
4617 qla2x00_set_fw_options(vha, ha->fw_options);
4619 /* Update Serial Link options. */
4620 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
4623 rval = qla2x00_set_serdes_params(vha,
4624 le16_to_cpu(ha->fw_seriallink_options24[1]),
4625 le16_to_cpu(ha->fw_seriallink_options24[2]),
4626 le16_to_cpu(ha->fw_seriallink_options24[3]));
4627 if (rval != QLA_SUCCESS) {
4628 ql_log(ql_log_warn, vha, 0x0104,
4629 "Unable to update Serial Link options (%x).\n", rval);
4634 qla2x00_config_rings(struct scsi_qla_host *vha)
4636 struct qla_hw_data *ha = vha->hw;
4637 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4638 struct req_que *req = ha->req_q_map[0];
4639 struct rsp_que *rsp = ha->rsp_q_map[0];
4641 /* Setup ring parameters in initialization control block. */
4642 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
4643 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
4644 ha->init_cb->request_q_length = cpu_to_le16(req->length);
4645 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
4646 put_unaligned_le64(req->dma, &ha->init_cb->request_q_address);
4647 put_unaligned_le64(rsp->dma, &ha->init_cb->response_q_address);
4649 wrt_reg_word(ISP_REQ_Q_IN(ha, reg), 0);
4650 wrt_reg_word(ISP_REQ_Q_OUT(ha, reg), 0);
4651 wrt_reg_word(ISP_RSP_Q_IN(ha, reg), 0);
4652 wrt_reg_word(ISP_RSP_Q_OUT(ha, reg), 0);
4653 rd_reg_word(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
4657 qla24xx_config_rings(struct scsi_qla_host *vha)
4659 struct qla_hw_data *ha = vha->hw;
4660 device_reg_t *reg = ISP_QUE_REG(ha, 0);
4661 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
4662 struct qla_msix_entry *msix;
4663 struct init_cb_24xx *icb;
4665 struct req_que *req = ha->req_q_map[0];
4666 struct rsp_que *rsp = ha->rsp_q_map[0];
4668 /* Setup ring parameters in initialization control block. */
4669 icb = (struct init_cb_24xx *)ha->init_cb;
4670 icb->request_q_outpointer = cpu_to_le16(0);
4671 icb->response_q_inpointer = cpu_to_le16(0);
4672 icb->request_q_length = cpu_to_le16(req->length);
4673 icb->response_q_length = cpu_to_le16(rsp->length);
4674 put_unaligned_le64(req->dma, &icb->request_q_address);
4675 put_unaligned_le64(rsp->dma, &icb->response_q_address);
4677 /* Setup ATIO queue dma pointers for target mode */
4678 icb->atio_q_inpointer = cpu_to_le16(0);
4679 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
4680 put_unaligned_le64(ha->tgt.atio_dma, &icb->atio_q_address);
4682 if (IS_SHADOW_REG_CAPABLE(ha))
4683 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
4685 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4687 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
4688 icb->rid = cpu_to_le16(rid);
4689 if (ha->flags.msix_enabled) {
4690 msix = &ha->msix_entries[1];
4691 ql_dbg(ql_dbg_init, vha, 0x0019,
4692 "Registering vector 0x%x for base que.\n",
4694 icb->msix = cpu_to_le16(msix->entry);
4696 /* Use alternate PCI bus number */
4698 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
4699 /* Use alternate PCI devfn */
4701 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
4703 /* Use Disable MSIX Handshake mode for capable adapters */
4704 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
4705 (ha->flags.msix_enabled)) {
4706 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
4707 ha->flags.disable_msix_handshake = 1;
4708 ql_dbg(ql_dbg_init, vha, 0x00fe,
4709 "MSIX Handshake Disable Mode turned on.\n");
4711 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
4713 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
4715 wrt_reg_dword(®->isp25mq.req_q_in, 0);
4716 wrt_reg_dword(®->isp25mq.req_q_out, 0);
4717 wrt_reg_dword(®->isp25mq.rsp_q_in, 0);
4718 wrt_reg_dword(®->isp25mq.rsp_q_out, 0);
4720 wrt_reg_dword(®->isp24.req_q_in, 0);
4721 wrt_reg_dword(®->isp24.req_q_out, 0);
4722 wrt_reg_dword(®->isp24.rsp_q_in, 0);
4723 wrt_reg_dword(®->isp24.rsp_q_out, 0);
4726 qlt_24xx_config_rings(vha);
4728 /* If the user has configured the speed, set it here */
4729 if (ha->set_data_rate) {
4730 ql_dbg(ql_dbg_init, vha, 0x00fd,
4731 "Speed set by user : %s Gbps \n",
4732 qla2x00_get_link_speed_str(ha, ha->set_data_rate));
4733 icb->firmware_options_3 = cpu_to_le32(ha->set_data_rate << 13);
4737 rd_reg_word(&ioreg->hccr);
4741 * qla2x00_init_rings() - Initializes firmware.
4744 * Beginning of request ring has initialization control block already built
4745 * by nvram config routine.
4747 * Returns 0 on success.
4750 qla2x00_init_rings(scsi_qla_host_t *vha)
4753 unsigned long flags = 0;
4755 struct qla_hw_data *ha = vha->hw;
4756 struct req_que *req;
4757 struct rsp_que *rsp;
4758 struct mid_init_cb_24xx *mid_init_cb =
4759 (struct mid_init_cb_24xx *) ha->init_cb;
4761 spin_lock_irqsave(&ha->hardware_lock, flags);
4763 /* Clear outstanding commands array. */
4764 for (que = 0; que < ha->max_req_queues; que++) {
4765 req = ha->req_q_map[que];
4766 if (!req || !test_bit(que, ha->req_qid_map))
4768 req->out_ptr = (uint16_t *)(req->ring + req->length);
4770 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
4771 req->outstanding_cmds[cnt] = NULL;
4773 req->current_outstanding_cmd = 1;
4775 /* Initialize firmware. */
4776 req->ring_ptr = req->ring;
4777 req->ring_index = 0;
4778 req->cnt = req->length;
4781 for (que = 0; que < ha->max_rsp_queues; que++) {
4782 rsp = ha->rsp_q_map[que];
4783 if (!rsp || !test_bit(que, ha->rsp_qid_map))
4785 rsp->in_ptr = (uint16_t *)(rsp->ring + rsp->length);
4787 /* Initialize response queue entries */
4789 qlafx00_init_response_q_entries(rsp);
4791 qla2x00_init_response_q_entries(rsp);
4794 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
4795 ha->tgt.atio_ring_index = 0;
4796 /* Initialize ATIO queue entries */
4797 qlt_init_atio_q_entries(vha);
4799 ha->isp_ops->config_rings(vha);
4801 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4803 if (IS_QLAFX00(ha)) {
4804 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
4808 /* Update any ISP specific firmware options before initialization. */
4809 ha->isp_ops->update_fw_options(vha);
4811 ql_dbg(ql_dbg_init, vha, 0x00d1,
4812 "Issue init firmware FW opt 1-3= %08x %08x %08x.\n",
4813 le32_to_cpu(mid_init_cb->init_cb.firmware_options_1),
4814 le32_to_cpu(mid_init_cb->init_cb.firmware_options_2),
4815 le32_to_cpu(mid_init_cb->init_cb.firmware_options_3));
4817 if (ha->flags.npiv_supported) {
4818 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
4819 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
4820 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
4823 if (IS_FWI2_CAPABLE(ha)) {
4824 mid_init_cb->options = cpu_to_le16(BIT_1);
4825 mid_init_cb->init_cb.execution_throttle =
4826 cpu_to_le16(ha->cur_fw_xcb_count);
4827 ha->flags.dport_enabled =
4828 (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) &
4830 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
4831 (ha->flags.dport_enabled) ? "enabled" : "disabled");
4832 /* FA-WWPN Status */
4833 ha->flags.fawwpn_enabled =
4834 (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) &
4836 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
4837 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
4838 /* Init_cb will be reused for other command(s). Save a backup copy of port_name */
4839 memcpy(ha->port_name, ha->init_cb->port_name, WWN_SIZE);
4842 /* ELS pass through payload is limit by frame size. */
4843 if (ha->flags.edif_enabled)
4844 mid_init_cb->init_cb.frame_payload_size = cpu_to_le16(ELS_MAX_PAYLOAD);
4847 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
4851 ql_log(ql_log_fatal, vha, 0x00d2,
4852 "Init Firmware **** FAILED ****.\n");
4854 ql_dbg(ql_dbg_init, vha, 0x00d3,
4855 "Init Firmware -- success.\n");
4856 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0;
4863 * qla2x00_fw_ready() - Waits for firmware ready.
4866 * Returns 0 on success.
4869 qla2x00_fw_ready(scsi_qla_host_t *vha)
4872 unsigned long wtime, mtime, cs84xx_time;
4873 uint16_t min_wait; /* Minimum wait time if loop is down */
4874 uint16_t wait_time; /* Wait time if loop is coming ready */
4876 struct qla_hw_data *ha = vha->hw;
4878 if (IS_QLAFX00(vha->hw))
4879 return qlafx00_fw_ready(vha);
4881 /* Time to wait for loop down */
4882 if (IS_P3P_TYPE(ha))
4888 * Firmware should take at most one RATOV to login, plus 5 seconds for
4889 * our own processing.
4891 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
4892 wait_time = min_wait;
4895 /* Min wait time if loop down */
4896 mtime = jiffies + (min_wait * HZ);
4898 /* wait time before firmware ready */
4899 wtime = jiffies + (wait_time * HZ);
4901 /* Wait for ISP to finish LIP */
4902 if (!vha->flags.init_done)
4903 ql_log(ql_log_info, vha, 0x801e,
4904 "Waiting for LIP to complete.\n");
4907 memset(state, -1, sizeof(state));
4908 rval = qla2x00_get_firmware_state(vha, state);
4909 if (rval == QLA_SUCCESS) {
4910 if (state[0] < FSTATE_LOSS_OF_SYNC) {
4911 vha->device_flags &= ~DFLG_NO_CABLE;
4913 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
4914 ql_dbg(ql_dbg_taskm, vha, 0x801f,
4915 "fw_state=%x 84xx=%x.\n", state[0],
4917 if ((state[2] & FSTATE_LOGGED_IN) &&
4918 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
4919 ql_dbg(ql_dbg_taskm, vha, 0x8028,
4920 "Sending verify iocb.\n");
4922 cs84xx_time = jiffies;
4923 rval = qla84xx_init_chip(vha);
4924 if (rval != QLA_SUCCESS) {
4927 "Init chip failed.\n");
4931 /* Add time taken to initialize. */
4932 cs84xx_time = jiffies - cs84xx_time;
4933 wtime += cs84xx_time;
4934 mtime += cs84xx_time;
4935 ql_dbg(ql_dbg_taskm, vha, 0x8008,
4936 "Increasing wait time by %ld. "
4937 "New time %ld.\n", cs84xx_time,
4940 } else if (state[0] == FSTATE_READY) {
4941 ql_dbg(ql_dbg_taskm, vha, 0x8037,
4942 "F/W Ready - OK.\n");
4944 qla2x00_get_retry_cnt(vha, &ha->retry_count,
4945 &ha->login_timeout, &ha->r_a_tov);
4951 rval = QLA_FUNCTION_FAILED;
4953 if (atomic_read(&vha->loop_down_timer) &&
4954 state[0] != FSTATE_READY) {
4955 /* Loop down. Timeout on min_wait for states
4956 * other than Wait for Login.
4958 if (time_after_eq(jiffies, mtime)) {
4959 ql_log(ql_log_info, vha, 0x8038,
4960 "Cable is unplugged...\n");
4962 vha->device_flags |= DFLG_NO_CABLE;
4967 /* Mailbox cmd failed. Timeout on min_wait. */
4968 if (time_after_eq(jiffies, mtime) ||
4969 ha->flags.isp82xx_fw_hung)
4973 if (time_after_eq(jiffies, wtime))
4976 /* Delay for a while */
4980 ql_dbg(ql_dbg_taskm, vha, 0x803a,
4981 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
4982 state[1], state[2], state[3], state[4], state[5], jiffies);
4984 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
4985 ql_log(ql_log_warn, vha, 0x803b,
4986 "Firmware ready **** FAILED ****.\n");
4993 * qla2x00_configure_hba
4994 * Setup adapter context.
4997 * ha = adapter state pointer.
5006 qla2x00_configure_hba(scsi_qla_host_t *vha)
5015 char connect_type[22];
5016 struct qla_hw_data *ha = vha->hw;
5017 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5019 unsigned long flags;
5021 /* Get host addresses. */
5022 rval = qla2x00_get_adapter_id(vha,
5023 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
5024 if (rval != QLA_SUCCESS) {
5025 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
5026 IS_CNA_CAPABLE(ha) ||
5027 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
5028 ql_dbg(ql_dbg_disc, vha, 0x2008,
5029 "Loop is in a transition state.\n");
5031 ql_log(ql_log_warn, vha, 0x2009,
5032 "Unable to get host loop ID.\n");
5033 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
5034 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
5035 ql_log(ql_log_warn, vha, 0x1151,
5036 "Doing link init.\n");
5037 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
5040 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
5046 ql_log(ql_log_info, vha, 0x200a,
5047 "Cannot get topology - retrying.\n");
5048 return (QLA_FUNCTION_FAILED);
5051 vha->loop_id = loop_id;
5054 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
5055 ha->operating_mode = LOOP;
5059 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
5061 ha->current_topology = ISP_CFG_NL;
5062 strcpy(connect_type, "(Loop)");
5066 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
5067 ha->switch_cap = sw_cap;
5068 ha->current_topology = ISP_CFG_FL;
5069 strcpy(connect_type, "(FL_Port)");
5073 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
5075 ha->operating_mode = P2P;
5076 ha->current_topology = ISP_CFG_N;
5077 strcpy(connect_type, "(N_Port-to-N_Port)");
5081 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
5082 ha->switch_cap = sw_cap;
5083 ha->operating_mode = P2P;
5084 ha->current_topology = ISP_CFG_F;
5085 strcpy(connect_type, "(F_Port)");
5089 ql_dbg(ql_dbg_disc, vha, 0x200f,
5090 "HBA in unknown topology %x, using NL.\n", topo);
5092 ha->current_topology = ISP_CFG_NL;
5093 strcpy(connect_type, "(Loop)");
5097 /* Save Host port and loop ID. */
5098 /* byte order - Big Endian */
5099 id.b.domain = domain;
5103 spin_lock_irqsave(&ha->hardware_lock, flags);
5104 if (vha->hw->flags.edif_enabled) {
5106 qla_update_host_map(vha, id);
5107 } else if (!(topo == 2 && ha->flags.n2n_bigger))
5108 qla_update_host_map(vha, id);
5109 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5111 if (!vha->flags.init_done)
5112 ql_log(ql_log_info, vha, 0x2010,
5113 "Topology - %s, Host Loop address 0x%x.\n",
5114 connect_type, vha->loop_id);
5120 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
5125 uint64_t zero[2] = { 0 };
5126 struct qla_hw_data *ha = vha->hw;
5127 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
5128 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
5130 if (len > sizeof(zero))
5132 if (memcmp(model, &zero, len) != 0) {
5133 memcpy(ha->model_number, model, len);
5134 st = en = ha->model_number;
5137 if (*en != 0x20 && *en != 0x00)
5142 index = (ha->pdev->subsystem_device & 0xff);
5144 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
5145 index < QLA_MODEL_NAMES)
5146 strscpy(ha->model_desc,
5147 qla2x00_model_name[index * 2 + 1],
5148 sizeof(ha->model_desc));
5150 index = (ha->pdev->subsystem_device & 0xff);
5152 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
5153 index < QLA_MODEL_NAMES) {
5154 strscpy(ha->model_number,
5155 qla2x00_model_name[index * 2],
5156 sizeof(ha->model_number));
5157 strscpy(ha->model_desc,
5158 qla2x00_model_name[index * 2 + 1],
5159 sizeof(ha->model_desc));
5161 strscpy(ha->model_number, def,
5162 sizeof(ha->model_number));
5165 if (IS_FWI2_CAPABLE(ha))
5166 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
5167 sizeof(ha->model_desc));
5170 /* On sparc systems, obtain port and node WWN from firmware
5173 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
5176 struct qla_hw_data *ha = vha->hw;
5177 struct pci_dev *pdev = ha->pdev;
5178 struct device_node *dp = pci_device_to_OF_node(pdev);
5182 val = of_get_property(dp, "port-wwn", &len);
5183 if (val && len >= WWN_SIZE)
5184 memcpy(nv->port_name, val, WWN_SIZE);
5186 val = of_get_property(dp, "node-wwn", &len);
5187 if (val && len >= WWN_SIZE)
5188 memcpy(nv->node_name, val, WWN_SIZE);
5193 * NVRAM configuration for ISP 2xxx
5196 * ha = adapter block pointer.
5199 * initialization control block in response_ring
5200 * host adapters parameters in host adapter block
5206 qla2x00_nvram_config(scsi_qla_host_t *vha)
5211 uint8_t *dptr1, *dptr2;
5212 struct qla_hw_data *ha = vha->hw;
5213 init_cb_t *icb = ha->init_cb;
5214 nvram_t *nv = ha->nvram;
5215 uint8_t *ptr = ha->nvram;
5216 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
5220 /* Determine NVRAM starting address. */
5221 ha->nvram_size = sizeof(*nv);
5223 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
5224 if ((rd_reg_word(®->ctrl_status) >> 14) == 1)
5225 ha->nvram_base = 0x80;
5227 /* Get NVRAM data and calculate checksum. */
5228 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
5229 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
5232 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
5233 "Contents of NVRAM.\n");
5234 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
5235 nv, ha->nvram_size);
5237 /* Bad NVRAM data, set defaults parameters. */
5238 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
5239 nv->nvram_version < 1) {
5240 /* Reset NVRAM data. */
5241 ql_log(ql_log_warn, vha, 0x0064,
5242 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
5243 chksum, nv->id, nv->nvram_version);
5244 ql_log(ql_log_warn, vha, 0x0065,
5246 "functioning (yet invalid -- WWPN) defaults.\n");
5249 * Set default initialization control block.
5251 memset(nv, 0, ha->nvram_size);
5252 nv->parameter_block_version = ICB_VERSION;
5254 if (IS_QLA23XX(ha)) {
5255 nv->firmware_options[0] = BIT_2 | BIT_1;
5256 nv->firmware_options[1] = BIT_7 | BIT_5;
5257 nv->add_firmware_options[0] = BIT_5;
5258 nv->add_firmware_options[1] = BIT_5 | BIT_4;
5259 nv->frame_payload_size = cpu_to_le16(2048);
5260 nv->special_options[1] = BIT_7;
5261 } else if (IS_QLA2200(ha)) {
5262 nv->firmware_options[0] = BIT_2 | BIT_1;
5263 nv->firmware_options[1] = BIT_7 | BIT_5;
5264 nv->add_firmware_options[0] = BIT_5;
5265 nv->add_firmware_options[1] = BIT_5 | BIT_4;
5266 nv->frame_payload_size = cpu_to_le16(1024);
5267 } else if (IS_QLA2100(ha)) {
5268 nv->firmware_options[0] = BIT_3 | BIT_1;
5269 nv->firmware_options[1] = BIT_5;
5270 nv->frame_payload_size = cpu_to_le16(1024);
5273 nv->max_iocb_allocation = cpu_to_le16(256);
5274 nv->execution_throttle = cpu_to_le16(16);
5275 nv->retry_count = 8;
5276 nv->retry_delay = 1;
5278 nv->port_name[0] = 33;
5279 nv->port_name[3] = 224;
5280 nv->port_name[4] = 139;
5282 qla2xxx_nvram_wwn_from_ofw(vha, nv);
5284 nv->login_timeout = 4;
5287 * Set default host adapter parameters
5289 nv->host_p[1] = BIT_2;
5290 nv->reset_delay = 5;
5291 nv->port_down_retry_count = 8;
5292 nv->max_luns_per_target = cpu_to_le16(8);
5293 nv->link_down_timeout = 60;
5298 /* Reset Initialization control block */
5299 memset(icb, 0, ha->init_cb_size);
5302 * Setup driver NVRAM options.
5304 nv->firmware_options[0] |= (BIT_6 | BIT_1);
5305 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
5306 nv->firmware_options[1] |= (BIT_5 | BIT_0);
5307 nv->firmware_options[1] &= ~BIT_4;
5309 if (IS_QLA23XX(ha)) {
5310 nv->firmware_options[0] |= BIT_2;
5311 nv->firmware_options[0] &= ~BIT_3;
5312 nv->special_options[0] &= ~BIT_6;
5313 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
5315 if (IS_QLA2300(ha)) {
5316 if (ha->fb_rev == FPM_2310) {
5317 strcpy(ha->model_number, "QLA2310");
5319 strcpy(ha->model_number, "QLA2300");
5322 qla2x00_set_model_info(vha, nv->model_number,
5323 sizeof(nv->model_number), "QLA23xx");
5325 } else if (IS_QLA2200(ha)) {
5326 nv->firmware_options[0] |= BIT_2;
5328 * 'Point-to-point preferred, else loop' is not a safe
5329 * connection mode setting.
5331 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
5333 /* Force 'loop preferred, else point-to-point'. */
5334 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
5335 nv->add_firmware_options[0] |= BIT_5;
5337 strcpy(ha->model_number, "QLA22xx");
5338 } else /*if (IS_QLA2100(ha))*/ {
5339 strcpy(ha->model_number, "QLA2100");
5343 * Copy over NVRAM RISC parameter block to initialization control block.
5345 dptr1 = (uint8_t *)icb;
5346 dptr2 = (uint8_t *)&nv->parameter_block_version;
5347 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
5349 *dptr1++ = *dptr2++;
5351 /* Copy 2nd half. */
5352 dptr1 = (uint8_t *)icb->add_firmware_options;
5353 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
5355 *dptr1++ = *dptr2++;
5356 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
5357 /* Use alternate WWN? */
5358 if (nv->host_p[1] & BIT_7) {
5359 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5360 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5363 /* Prepare nodename */
5364 if ((icb->firmware_options[1] & BIT_6) == 0) {
5366 * Firmware will apply the following mask if the nodename was
5369 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5370 icb->node_name[0] &= 0xF0;
5374 * Set host adapter parameters.
5378 * BIT_7 in the host-parameters section allows for modification to
5379 * internal driver logging.
5381 if (nv->host_p[0] & BIT_7)
5382 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
5383 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
5384 /* Always load RISC code on non ISP2[12]00 chips. */
5385 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
5386 ha->flags.disable_risc_code_load = 0;
5387 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
5388 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
5389 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
5390 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
5391 ha->flags.disable_serdes = 0;
5393 ha->operating_mode =
5394 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
5396 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
5397 sizeof(ha->fw_seriallink_options));
5399 /* save HBA serial number */
5400 ha->serial0 = icb->port_name[5];
5401 ha->serial1 = icb->port_name[6];
5402 ha->serial2 = icb->port_name[7];
5403 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5404 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5406 icb->execution_throttle = cpu_to_le16(0xFFFF);
5408 ha->retry_count = nv->retry_count;
5410 /* Set minimum login_timeout to 4 seconds. */
5411 if (nv->login_timeout != ql2xlogintimeout)
5412 nv->login_timeout = ql2xlogintimeout;
5413 if (nv->login_timeout < 4)
5414 nv->login_timeout = 4;
5415 ha->login_timeout = nv->login_timeout;
5417 /* Set minimum RATOV to 100 tenths of a second. */
5420 ha->loop_reset_delay = nv->reset_delay;
5422 /* Link Down Timeout = 0:
5424 * When Port Down timer expires we will start returning
5425 * I/O's to OS with "DID_NO_CONNECT".
5427 * Link Down Timeout != 0:
5429 * The driver waits for the link to come up after link down
5430 * before returning I/Os to OS with "DID_NO_CONNECT".
5432 if (nv->link_down_timeout == 0) {
5433 ha->loop_down_abort_time =
5434 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5436 ha->link_down_timeout = nv->link_down_timeout;
5437 ha->loop_down_abort_time =
5438 (LOOP_DOWN_TIME - ha->link_down_timeout);
5442 * Need enough time to try and get the port back.
5444 ha->port_down_retry_count = nv->port_down_retry_count;
5445 if (qlport_down_retry)
5446 ha->port_down_retry_count = qlport_down_retry;
5447 /* Set login_retry_count */
5448 ha->login_retry_count = nv->retry_count;
5449 if (ha->port_down_retry_count == nv->port_down_retry_count &&
5450 ha->port_down_retry_count > 3)
5451 ha->login_retry_count = ha->port_down_retry_count;
5452 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5453 ha->login_retry_count = ha->port_down_retry_count;
5454 if (ql2xloginretrycount)
5455 ha->login_retry_count = ql2xloginretrycount;
5457 icb->lun_enables = cpu_to_le16(0);
5458 icb->command_resource_count = 0;
5459 icb->immediate_notify_resource_count = 0;
5460 icb->timeout = cpu_to_le16(0);
5462 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
5464 icb->firmware_options[0] &= ~BIT_3;
5465 icb->add_firmware_options[0] &=
5466 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
5467 icb->add_firmware_options[0] |= BIT_2;
5468 icb->response_accumulation_timer = 3;
5469 icb->interrupt_delay_timer = 5;
5471 vha->flags.process_response_queue = 1;
5474 if (!vha->flags.init_done) {
5475 ha->zio_mode = icb->add_firmware_options[0] &
5476 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5477 ha->zio_timer = icb->interrupt_delay_timer ?
5478 icb->interrupt_delay_timer : 2;
5480 icb->add_firmware_options[0] &=
5481 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
5482 vha->flags.process_response_queue = 0;
5483 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5484 ha->zio_mode = QLA_ZIO_MODE_6;
5486 ql_log(ql_log_info, vha, 0x0068,
5487 "ZIO mode %d enabled; timer delay (%d us).\n",
5488 ha->zio_mode, ha->zio_timer * 100);
5490 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
5491 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
5492 vha->flags.process_response_queue = 1;
5497 ql_log(ql_log_warn, vha, 0x0069,
5498 "NVRAM configuration failed.\n");
5503 void qla2x00_set_fcport_state(fc_port_t *fcport, int state)
5507 old_state = atomic_read(&fcport->state);
5508 atomic_set(&fcport->state, state);
5510 /* Don't print state transitions during initial allocation of fcport */
5511 if (old_state && old_state != state) {
5512 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
5513 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
5514 fcport->port_name, port_state_str[old_state],
5515 port_state_str[state], fcport->d_id.b.domain,
5516 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5521 * qla2x00_alloc_fcport() - Allocate a generic fcport.
5523 * @flags: allocation flags
5525 * Returns a pointer to the allocated fcport, or NULL, if none available.
5528 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
5532 fcport = kzalloc(sizeof(fc_port_t), flags);
5536 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
5537 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
5539 if (!fcport->ct_desc.ct_sns) {
5540 ql_log(ql_log_warn, vha, 0xd049,
5541 "Failed to allocate ct_sns request.\n");
5546 /* Setup fcport template structure. */
5548 fcport->port_type = FCT_UNKNOWN;
5549 fcport->loop_id = FC_NO_LOOP_ID;
5550 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
5551 fcport->supported_classes = FC_COS_UNSPECIFIED;
5552 fcport->fp_speed = PORT_SPEED_UNKNOWN;
5554 fcport->disc_state = DSC_DELETED;
5555 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
5556 fcport->deleted = QLA_SESS_DELETED;
5557 fcport->login_retry = vha->hw->login_retry_count;
5558 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
5559 fcport->logout_on_delete = 1;
5560 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
5561 fcport->tgt_short_link_down_cnt = 0;
5562 fcport->dev_loss_tmo = 0;
5564 if (!fcport->ct_desc.ct_sns) {
5565 ql_log(ql_log_warn, vha, 0xd049,
5566 "Failed to allocate ct_sns request.\n");
5571 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
5572 INIT_WORK(&fcport->free_work, qlt_free_session_done);
5573 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
5574 INIT_LIST_HEAD(&fcport->gnl_entry);
5575 INIT_LIST_HEAD(&fcport->list);
5576 INIT_LIST_HEAD(&fcport->unsol_ctx_head);
5578 INIT_LIST_HEAD(&fcport->sess_cmd_list);
5579 spin_lock_init(&fcport->sess_cmd_lock);
5581 spin_lock_init(&fcport->edif.sa_list_lock);
5582 INIT_LIST_HEAD(&fcport->edif.tx_sa_list);
5583 INIT_LIST_HEAD(&fcport->edif.rx_sa_list);
5585 spin_lock_init(&fcport->edif.indx_list_lock);
5586 INIT_LIST_HEAD(&fcport->edif.edif_indx_list);
5592 qla2x00_free_fcport(fc_port_t *fcport)
5594 if (fcport->ct_desc.ct_sns) {
5595 dma_free_coherent(&fcport->vha->hw->pdev->dev,
5596 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
5597 fcport->ct_desc.ct_sns_dma);
5599 fcport->ct_desc.ct_sns = NULL;
5602 qla_edif_flush_sa_ctl_lists(fcport);
5603 list_del(&fcport->list);
5604 qla2x00_clear_loop_id(fcport);
5606 qla_edif_list_del(fcport);
5611 static void qla_get_login_template(scsi_qla_host_t *vha)
5613 struct qla_hw_data *ha = vha->hw;
5618 memset(ha->init_cb, 0, ha->init_cb_size);
5619 sz = min_t(int, sizeof(struct fc_els_flogi), ha->init_cb_size);
5620 rval = qla24xx_get_port_login_templ(vha, ha->init_cb_dma,
5622 if (rval != QLA_SUCCESS) {
5623 ql_dbg(ql_dbg_init, vha, 0x00d1,
5624 "PLOGI ELS param read fail.\n");
5627 q = (__be32 *)&ha->plogi_els_payld.fl_csp;
5629 bp = (uint32_t *)ha->init_cb;
5630 cpu_to_be32_array(q, bp, sz / 4);
5631 ha->flags.plogi_template_valid = 1;
5635 * qla2x00_configure_loop
5636 * Updates Fibre Channel Device Database with what is actually on loop.
5639 * ha = adapter block pointer.
5644 * 2 = database was full and device was not configured.
5647 qla2x00_configure_loop(scsi_qla_host_t *vha)
5650 unsigned long flags, save_flags;
5651 struct qla_hw_data *ha = vha->hw;
5655 /* Get Initiator ID */
5656 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
5657 rval = qla2x00_configure_hba(vha);
5658 if (rval != QLA_SUCCESS) {
5659 ql_dbg(ql_dbg_disc, vha, 0x2013,
5660 "Unable to configure HBA.\n");
5665 save_flags = flags = vha->dpc_flags;
5666 ql_dbg(ql_dbg_disc, vha, 0x2014,
5667 "Configure loop -- dpc flags = 0x%lx.\n", flags);
5670 * If we have both an RSCN and PORT UPDATE pending then handle them
5671 * both at the same time.
5673 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5674 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
5676 qla2x00_get_data_rate(vha);
5677 qla_get_login_template(vha);
5679 /* Determine what we need to do */
5680 if ((ha->current_topology == ISP_CFG_FL ||
5681 ha->current_topology == ISP_CFG_F) &&
5682 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
5684 set_bit(RSCN_UPDATE, &flags);
5685 clear_bit(LOCAL_LOOP_UPDATE, &flags);
5687 } else if (ha->current_topology == ISP_CFG_NL ||
5688 ha->current_topology == ISP_CFG_N) {
5689 clear_bit(RSCN_UPDATE, &flags);
5690 set_bit(LOCAL_LOOP_UPDATE, &flags);
5691 } else if (!vha->flags.online ||
5692 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
5693 set_bit(RSCN_UPDATE, &flags);
5694 set_bit(LOCAL_LOOP_UPDATE, &flags);
5697 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
5698 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5699 ql_dbg(ql_dbg_disc, vha, 0x2015,
5700 "Loop resync needed, failing.\n");
5701 rval = QLA_FUNCTION_FAILED;
5703 rval = qla2x00_configure_local_loop(vha);
5706 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
5707 if (LOOP_TRANSITION(vha)) {
5708 ql_dbg(ql_dbg_disc, vha, 0x2099,
5709 "Needs RSCN update and loop transition.\n");
5710 rval = QLA_FUNCTION_FAILED;
5713 rval = qla2x00_configure_fabric(vha);
5716 if (rval == QLA_SUCCESS) {
5717 if (atomic_read(&vha->loop_down_timer) ||
5718 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5719 rval = QLA_FUNCTION_FAILED;
5721 atomic_set(&vha->loop_state, LOOP_READY);
5722 ql_dbg(ql_dbg_disc, vha, 0x2069,
5724 ha->flags.fw_init_done = 1;
5727 * use link up to wake up app to get ready for
5730 if (ha->flags.edif_enabled && DBELL_INACTIVE(vha))
5731 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP,
5732 ha->link_data_rate);
5735 * Process any ATIO queue entries that came in
5736 * while we weren't online.
5738 if (qla_tgt_mode_enabled(vha) ||
5739 qla_dual_mode_enabled(vha)) {
5740 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
5741 qlt_24xx_process_atio_queue(vha, 0);
5742 spin_unlock_irqrestore(&ha->tgt.atio_lock,
5749 ql_dbg(ql_dbg_disc, vha, 0x206a,
5750 "%s *** FAILED ***.\n", __func__);
5752 ql_dbg(ql_dbg_disc, vha, 0x206b,
5753 "%s: exiting normally. local port wwpn %8phN id %06x)\n",
5754 __func__, vha->port_name, vha->d_id.b24);
5757 /* Restore state if a resync event occurred during processing */
5758 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5759 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
5760 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5761 if (test_bit(RSCN_UPDATE, &save_flags)) {
5762 set_bit(RSCN_UPDATE, &vha->dpc_flags);
5769 static int qla2x00_configure_n2n_loop(scsi_qla_host_t *vha)
5771 unsigned long flags;
5774 ql_dbg(ql_dbg_disc, vha, 0x206a, "%s %d.\n", __func__, __LINE__);
5776 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags))
5777 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5779 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5780 if (fcport->n2n_flag) {
5781 qla24xx_fcport_handle_login(vha, fcport);
5786 spin_lock_irqsave(&vha->work_lock, flags);
5787 vha->scan.scan_retry++;
5788 spin_unlock_irqrestore(&vha->work_lock, flags);
5790 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5791 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5792 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5794 return QLA_FUNCTION_FAILED;
5798 qla_reinitialize_link(scsi_qla_host_t *vha)
5802 atomic_set(&vha->loop_state, LOOP_DOWN);
5803 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
5804 rval = qla2x00_full_login_lip(vha);
5805 if (rval == QLA_SUCCESS) {
5806 ql_dbg(ql_dbg_disc, vha, 0xd050, "Link reinitialized\n");
5808 ql_dbg(ql_dbg_disc, vha, 0xd051,
5809 "Link reinitialization failed (%d)\n", rval);
5814 * qla2x00_configure_local_loop
5815 * Updates Fibre Channel Device Database with local loop devices.
5818 * ha = adapter block pointer.
5824 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
5828 fc_port_t *fcport, *new_fcport;
5831 struct gid_list_info *gid;
5833 uint8_t domain, area, al_pa;
5834 struct qla_hw_data *ha = vha->hw;
5835 unsigned long flags;
5837 /* Inititae N2N login. */
5839 return qla2x00_configure_n2n_loop(vha);
5842 entries = MAX_FIBRE_DEVICES_LOOP;
5844 /* Get list of logged in devices. */
5845 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
5846 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
5848 if (rval != QLA_SUCCESS)
5851 ql_dbg(ql_dbg_disc, vha, 0x2011,
5852 "Entries in ID list (%d).\n", entries);
5853 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
5854 ha->gid_list, entries * sizeof(*ha->gid_list));
5857 spin_lock_irqsave(&vha->work_lock, flags);
5858 vha->scan.scan_retry++;
5859 spin_unlock_irqrestore(&vha->work_lock, flags);
5861 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5862 u8 loop_map_entries = 0;
5865 rc = qla2x00_get_fcal_position_map(vha, NULL,
5867 if (rc == QLA_SUCCESS && loop_map_entries > 1) {
5869 * There are devices that are still not logged
5870 * in. Reinitialize to give them a chance.
5872 qla_reinitialize_link(vha);
5873 return QLA_FUNCTION_FAILED;
5875 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5876 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5879 vha->scan.scan_retry = 0;
5882 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5883 fcport->scan_state = QLA_FCPORT_SCAN;
5886 /* Allocate temporary fcport for any new fcports discovered. */
5887 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5888 if (new_fcport == NULL) {
5889 ql_log(ql_log_warn, vha, 0x2012,
5890 "Memory allocation failed for fcport.\n");
5891 rval = QLA_MEMORY_ALLOC_FAILED;
5894 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5896 /* Add devices to port list. */
5898 for (index = 0; index < entries; index++) {
5899 domain = gid->domain;
5902 if (IS_QLA2100(ha) || IS_QLA2200(ha))
5903 loop_id = gid->loop_id_2100;
5905 loop_id = le16_to_cpu(gid->loop_id);
5906 gid = (void *)gid + ha->gid_list_info_size;
5908 /* Bypass reserved domain fields. */
5909 if ((domain & 0xf0) == 0xf0)
5912 /* Bypass if not same domain and area of adapter. */
5913 if (area && domain && ((area != vha->d_id.b.area) ||
5914 (domain != vha->d_id.b.domain)) &&
5915 (ha->current_topology == ISP_CFG_NL))
5919 /* Bypass invalid local loop ID. */
5920 if (loop_id > LAST_LOCAL_LOOP_ID)
5923 memset(new_fcport->port_name, 0, WWN_SIZE);
5925 /* Fill in member data. */
5926 new_fcport->d_id.b.domain = domain;
5927 new_fcport->d_id.b.area = area;
5928 new_fcport->d_id.b.al_pa = al_pa;
5929 new_fcport->loop_id = loop_id;
5930 new_fcport->scan_state = QLA_FCPORT_FOUND;
5932 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
5933 if (rval2 != QLA_SUCCESS) {
5934 ql_dbg(ql_dbg_disc, vha, 0x2097,
5935 "Failed to retrieve fcport information "
5936 "-- get_port_database=%x, loop_id=0x%04x.\n",
5937 rval2, new_fcport->loop_id);
5938 /* Skip retry if N2N */
5939 if (ha->current_topology != ISP_CFG_N) {
5940 ql_dbg(ql_dbg_disc, vha, 0x2105,
5941 "Scheduling resync.\n");
5942 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5947 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5948 /* Check for matching device in port list. */
5951 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5952 if (memcmp(new_fcport->port_name, fcport->port_name,
5956 fcport->flags &= ~FCF_FABRIC_DEVICE;
5957 fcport->loop_id = new_fcport->loop_id;
5958 fcport->port_type = new_fcport->port_type;
5959 fcport->d_id.b24 = new_fcport->d_id.b24;
5960 memcpy(fcport->node_name, new_fcport->node_name,
5962 fcport->scan_state = QLA_FCPORT_FOUND;
5963 if (fcport->login_retry == 0) {
5964 fcport->login_retry = vha->hw->login_retry_count;
5965 ql_dbg(ql_dbg_disc, vha, 0x2135,
5966 "Port login retry %8phN, lid 0x%04x retry cnt=%d.\n",
5967 fcport->port_name, fcport->loop_id,
5968 fcport->login_retry);
5975 /* New device, add to fcports list. */
5976 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5978 /* Allocate a new replacement fcport. */
5979 fcport = new_fcport;
5981 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5983 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5985 if (new_fcport == NULL) {
5986 ql_log(ql_log_warn, vha, 0xd031,
5987 "Failed to allocate memory for fcport.\n");
5988 rval = QLA_MEMORY_ALLOC_FAILED;
5991 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5992 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5995 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5997 /* Base iIDMA settings on HBA port speed. */
5998 fcport->fp_speed = ha->link_data_rate;
6001 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6002 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6005 if (fcport->scan_state == QLA_FCPORT_SCAN) {
6006 if ((qla_dual_mode_enabled(vha) ||
6007 qla_ini_mode_enabled(vha)) &&
6008 atomic_read(&fcport->state) == FCS_ONLINE) {
6009 qla2x00_mark_device_lost(vha, fcport,
6010 ql2xplogiabsentdevice);
6011 if (fcport->loop_id != FC_NO_LOOP_ID &&
6012 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
6013 fcport->port_type != FCT_INITIATOR &&
6014 fcport->port_type != FCT_BROADCAST) {
6015 ql_dbg(ql_dbg_disc, vha, 0x20f0,
6016 "%s %d %8phC post del sess\n",
6020 qlt_schedule_sess_for_deletion(fcport);
6026 if (fcport->scan_state == QLA_FCPORT_FOUND)
6027 qla24xx_fcport_handle_login(vha, fcport);
6030 qla2x00_free_fcport(new_fcport);
6035 ql_dbg(ql_dbg_disc, vha, 0x2098,
6036 "Configure local loop error exit: rval=%x.\n", rval);
6041 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
6044 uint16_t mb[MAILBOX_REGISTER_COUNT];
6045 struct qla_hw_data *ha = vha->hw;
6047 if (!IS_IIDMA_CAPABLE(ha))
6050 if (atomic_read(&fcport->state) != FCS_ONLINE)
6053 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
6054 fcport->fp_speed > ha->link_data_rate ||
6055 !ha->flags.gpsc_supported)
6058 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
6060 if (rval != QLA_SUCCESS) {
6061 ql_dbg(ql_dbg_disc, vha, 0x2004,
6062 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
6063 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
6065 ql_dbg(ql_dbg_disc, vha, 0x2005,
6066 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
6067 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
6068 fcport->fp_speed, fcport->port_name);
6072 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
6074 qla2x00_iidma_fcport(vha, fcport);
6075 qla24xx_update_fcport_fcp_prio(vha, fcport);
6078 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
6080 struct qla_work_evt *e;
6082 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
6084 return QLA_FUNCTION_FAILED;
6086 e->u.fcport.fcport = fcport;
6087 return qla2x00_post_work(vha, e);
6090 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
6092 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
6094 struct fc_rport_identifiers rport_ids;
6095 struct fc_rport *rport;
6096 unsigned long flags;
6098 if (atomic_read(&fcport->state) == FCS_ONLINE)
6101 rport_ids.node_name = wwn_to_u64(fcport->node_name);
6102 rport_ids.port_name = wwn_to_u64(fcport->port_name);
6103 rport_ids.port_id = fcport->d_id.b.domain << 16 |
6104 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
6105 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
6106 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
6108 ql_log(ql_log_warn, vha, 0x2006,
6109 "Unable to allocate fc remote port.\n");
6113 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
6114 *((fc_port_t **)rport->dd_data) = fcport;
6115 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
6116 fcport->dev_loss_tmo = rport->dev_loss_tmo;
6118 rport->supported_classes = fcport->supported_classes;
6120 rport_ids.roles = FC_PORT_ROLE_UNKNOWN;
6121 if (fcport->port_type == FCT_INITIATOR)
6122 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
6123 if (fcport->port_type == FCT_TARGET)
6124 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
6125 if (fcport->port_type & FCT_NVME_INITIATOR)
6126 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
6127 if (fcport->port_type & FCT_NVME_TARGET)
6128 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
6129 if (fcport->port_type & FCT_NVME_DISCOVERY)
6130 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
6132 fc_remote_port_rolechg(rport, rport_ids.roles);
6134 ql_dbg(ql_dbg_disc, vha, 0x20ee,
6135 "%s: %8phN. rport %ld:0:%d (%p) is %s mode\n",
6136 __func__, fcport->port_name, vha->host_no,
6137 rport->scsi_target_id, rport,
6138 (fcport->port_type == FCT_TARGET) ? "tgt" :
6139 ((fcport->port_type & FCT_NVME) ? "nvme" : "ini"));
6143 * qla2x00_update_fcport
6144 * Updates device on list.
6147 * ha = adapter block pointer.
6148 * fcport = port structure pointer.
6158 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
6160 unsigned long flags;
6162 if (IS_SW_RESV_ADDR(fcport->d_id))
6165 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
6166 __func__, fcport->port_name);
6168 qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT);
6169 fcport->login_retry = vha->hw->login_retry_count;
6170 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6172 spin_lock_irqsave(&vha->work_lock, flags);
6173 fcport->deleted = 0;
6174 spin_unlock_irqrestore(&vha->work_lock, flags);
6176 if (vha->hw->current_topology == ISP_CFG_NL)
6177 fcport->logout_on_delete = 0;
6179 fcport->logout_on_delete = 1;
6180 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
6182 if (fcport->tgt_link_down_time < fcport->dev_loss_tmo) {
6183 fcport->tgt_short_link_down_cnt++;
6184 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
6187 switch (vha->hw->current_topology) {
6190 fcport->keep_nport_handle = 1;
6196 qla2x00_iidma_fcport(vha, fcport);
6198 qla2x00_dfs_create_rport(vha, fcport);
6200 qla24xx_update_fcport_fcp_prio(vha, fcport);
6202 switch (vha->host->active_mode) {
6203 case MODE_INITIATOR:
6204 qla2x00_reg_remote_port(vha, fcport);
6207 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
6208 !vha->vha_tgt.qla_tgt->tgt_stopped)
6209 qlt_fc_port_added(vha, fcport);
6212 qla2x00_reg_remote_port(vha, fcport);
6213 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
6214 !vha->vha_tgt.qla_tgt->tgt_stopped)
6215 qlt_fc_port_added(vha, fcport);
6221 if (NVME_TARGET(vha->hw, fcport))
6222 qla_nvme_register_remote(vha, fcport);
6224 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
6226 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
6227 if (fcport->id_changed) {
6228 fcport->id_changed = 0;
6229 ql_dbg(ql_dbg_disc, vha, 0x20d7,
6230 "%s %d %8phC post gfpnid fcp_cnt %d\n",
6231 __func__, __LINE__, fcport->port_name,
6233 qla24xx_post_gfpnid_work(vha, fcport);
6235 ql_dbg(ql_dbg_disc, vha, 0x20d7,
6236 "%s %d %8phC post gpsc fcp_cnt %d\n",
6237 __func__, __LINE__, fcport->port_name,
6239 qla24xx_post_gpsc_work(vha, fcport);
6243 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
6246 void qla_register_fcport_fn(struct work_struct *work)
6248 fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
6249 u32 rscn_gen = fcport->rscn_gen;
6252 if (IS_SW_RESV_ADDR(fcport->d_id))
6255 qla2x00_update_fcport(fcport->vha, fcport);
6257 ql_dbg(ql_dbg_disc, fcport->vha, 0x911e,
6258 "%s rscn gen %d/%d next DS %d\n", __func__,
6259 rscn_gen, fcport->rscn_gen, fcport->next_disc_state);
6261 if (rscn_gen != fcport->rscn_gen) {
6262 /* RSCN(s) came in while registration */
6263 switch (fcport->next_disc_state) {
6264 case DSC_DELETE_PEND:
6265 qlt_schedule_sess_for_deletion(fcport);
6268 data[0] = data[1] = 0;
6269 qla2x00_post_async_adisc_work(fcport->vha, fcport,
6279 * qla2x00_configure_fabric
6280 * Setup SNS devices with loop ID's.
6283 * ha = adapter block pointer.
6290 qla2x00_configure_fabric(scsi_qla_host_t *vha)
6294 uint16_t mb[MAILBOX_REGISTER_COUNT];
6296 struct qla_hw_data *ha = vha->hw;
6299 /* If FL port exists, then SNS is present */
6300 if (IS_FWI2_CAPABLE(ha))
6301 loop_id = NPH_F_PORT;
6303 loop_id = SNS_FL_PORT;
6304 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
6305 if (rval != QLA_SUCCESS) {
6306 ql_dbg(ql_dbg_disc, vha, 0x20a0,
6307 "MBX_GET_PORT_NAME failed, No FL Port.\n");
6309 vha->device_flags &= ~SWITCH_FOUND;
6310 return (QLA_SUCCESS);
6312 vha->device_flags |= SWITCH_FOUND;
6314 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_port_name, 0);
6315 if (rval != QLA_SUCCESS)
6316 ql_dbg(ql_dbg_disc, vha, 0x20ff,
6317 "Failed to get Fabric Port Name\n");
6319 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
6320 rval = qla2x00_send_change_request(vha, 0x3, 0);
6321 if (rval != QLA_SUCCESS)
6322 ql_log(ql_log_warn, vha, 0x121,
6323 "Failed to enable receiving of RSCN requests: 0x%x.\n",
6328 qla2x00_mgmt_svr_login(vha);
6330 /* Ensure we are logged into the SNS. */
6331 loop_id = NPH_SNS_LID(ha);
6332 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
6333 0xfc, mb, BIT_1|BIT_0);
6334 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
6335 ql_dbg(ql_dbg_disc, vha, 0x20a1,
6336 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
6337 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
6338 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6343 if (ql2xfdmienable &&
6344 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
6345 qla2x00_fdmi_register(vha);
6347 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
6348 if (qla2x00_rft_id(vha)) {
6350 ql_dbg(ql_dbg_disc, vha, 0x20a2,
6351 "Register FC-4 TYPE failed.\n");
6352 if (test_bit(LOOP_RESYNC_NEEDED,
6356 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
6358 ql_dbg(ql_dbg_disc, vha, 0x209a,
6359 "Register FC-4 Features failed.\n");
6360 if (test_bit(LOOP_RESYNC_NEEDED,
6364 if (vha->flags.nvme_enabled) {
6365 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
6366 ql_dbg(ql_dbg_disc, vha, 0x2049,
6367 "Register NVME FC Type Features failed.\n");
6370 if (qla2x00_rnn_id(vha)) {
6372 ql_dbg(ql_dbg_disc, vha, 0x2104,
6373 "Register Node Name failed.\n");
6374 if (test_bit(LOOP_RESYNC_NEEDED,
6377 } else if (qla2x00_rsnn_nn(vha)) {
6379 ql_dbg(ql_dbg_disc, vha, 0x209b,
6380 "Register Symbolic Node Name failed.\n");
6381 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6387 /* Mark the time right before querying FW for connected ports.
6388 * This process is long, asynchronous and by the time it's done,
6389 * collected information might not be accurate anymore. E.g.
6390 * disconnected port might have re-connected and a brand new
6391 * session has been created. In this case session's generation
6392 * will be newer than discovery_gen. */
6393 qlt_do_generation_tick(vha, &discovery_gen);
6395 if (USE_ASYNC_SCAN(ha)) {
6396 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
6399 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6401 list_for_each_entry(fcport, &vha->vp_fcports, list)
6402 fcport->scan_state = QLA_FCPORT_SCAN;
6404 rval = qla2x00_find_all_fabric_devs(vha);
6406 if (rval != QLA_SUCCESS)
6410 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
6411 qla_nvme_register_hba(vha);
6414 ql_dbg(ql_dbg_disc, vha, 0x2068,
6415 "Configure fabric error exit rval=%d.\n", rval);
6421 * qla2x00_find_all_fabric_devs
6424 * ha = adapter block pointer.
6425 * dev = database device entry pointer.
6434 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
6438 fc_port_t *fcport, *new_fcport;
6443 int first_dev, last_dev;
6444 port_id_t wrap = {}, nxt_d_id;
6445 struct qla_hw_data *ha = vha->hw;
6446 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6447 unsigned long flags;
6451 /* Try GID_PT to get device list, else GAN. */
6453 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
6458 ql_dbg(ql_dbg_disc, vha, 0x209c,
6459 "GID_PT allocations failed, fallback on GA_NXT.\n");
6461 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
6462 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
6464 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6466 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
6468 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6470 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
6472 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6474 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
6476 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6480 /* If other queries succeeded probe for FC-4 type */
6482 qla2x00_gff_id(vha, swl);
6483 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6489 /* Allocate temporary fcport for any new fcports discovered. */
6490 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
6491 if (new_fcport == NULL) {
6492 ql_log(ql_log_warn, vha, 0x209d,
6493 "Failed to allocate memory for fcport.\n");
6494 return (QLA_MEMORY_ALLOC_FAILED);
6496 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
6497 /* Set start port ID scan at adapter ID. */
6501 /* Starting free loop ID. */
6502 loop_id = ha->min_external_loopid;
6503 for (; loop_id <= ha->max_loop_id; loop_id++) {
6504 if (qla2x00_is_reserved_id(vha, loop_id))
6507 if (ha->current_topology == ISP_CFG_FL &&
6508 (atomic_read(&vha->loop_down_timer) ||
6509 LOOP_TRANSITION(vha))) {
6510 atomic_set(&vha->loop_down_timer, 0);
6511 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6512 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
6518 wrap.b24 = new_fcport->d_id.b24;
6520 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
6521 memcpy(new_fcport->node_name,
6522 swl[swl_idx].node_name, WWN_SIZE);
6523 memcpy(new_fcport->port_name,
6524 swl[swl_idx].port_name, WWN_SIZE);
6525 memcpy(new_fcport->fabric_port_name,
6526 swl[swl_idx].fabric_port_name, WWN_SIZE);
6527 new_fcport->fp_speed = swl[swl_idx].fp_speed;
6528 new_fcport->fc4_type = swl[swl_idx].fc4_type;
6530 new_fcport->nvme_flag = 0;
6531 if (vha->flags.nvme_enabled &&
6532 swl[swl_idx].fc4_type & FS_FC4TYPE_NVME) {
6533 ql_log(ql_log_info, vha, 0x2131,
6534 "FOUND: NVME port %8phC as FC Type 28h\n",
6535 new_fcport->port_name);
6538 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
6544 /* Send GA_NXT to the switch */
6545 rval = qla2x00_ga_nxt(vha, new_fcport);
6546 if (rval != QLA_SUCCESS) {
6547 ql_log(ql_log_warn, vha, 0x209e,
6548 "SNS scan failed -- assuming "
6549 "zero-entry result.\n");
6555 /* If wrap on switch device list, exit. */
6557 wrap.b24 = new_fcport->d_id.b24;
6559 } else if (new_fcport->d_id.b24 == wrap.b24) {
6560 ql_dbg(ql_dbg_disc, vha, 0x209f,
6561 "Device wrap (%02x%02x%02x).\n",
6562 new_fcport->d_id.b.domain,
6563 new_fcport->d_id.b.area,
6564 new_fcport->d_id.b.al_pa);
6568 /* Bypass if same physical adapter. */
6569 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
6572 /* Bypass virtual ports of the same host. */
6573 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
6576 /* Bypass if same domain and area of adapter. */
6577 if (((new_fcport->d_id.b24 & 0xffff00) ==
6578 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
6582 /* Bypass reserved domain fields. */
6583 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
6586 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
6587 if (ql2xgffidenable &&
6588 (!(new_fcport->fc4_type & FS_FC4TYPE_FCP) &&
6589 new_fcport->fc4_type != 0))
6592 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
6594 /* Locate matching device in database. */
6596 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6597 if (memcmp(new_fcport->port_name, fcport->port_name,
6601 fcport->scan_state = QLA_FCPORT_FOUND;
6605 /* Update port state. */
6606 memcpy(fcport->fabric_port_name,
6607 new_fcport->fabric_port_name, WWN_SIZE);
6608 fcport->fp_speed = new_fcport->fp_speed;
6611 * If address the same and state FCS_ONLINE
6612 * (or in target mode), nothing changed.
6614 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
6615 (atomic_read(&fcport->state) == FCS_ONLINE ||
6616 (vha->host->active_mode == MODE_TARGET))) {
6620 if (fcport->login_retry == 0)
6621 fcport->login_retry =
6622 vha->hw->login_retry_count;
6624 * If device was not a fabric device before.
6626 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
6627 fcport->d_id.b24 = new_fcport->d_id.b24;
6628 qla2x00_clear_loop_id(fcport);
6629 fcport->flags |= (FCF_FABRIC_DEVICE |
6635 * Port ID changed or device was marked to be updated;
6636 * Log it out if still logged in and mark it for
6639 if (qla_tgt_mode_enabled(base_vha)) {
6640 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
6641 "port changed FC ID, %8phC"
6642 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
6644 fcport->d_id.b.domain,
6645 fcport->d_id.b.area,
6646 fcport->d_id.b.al_pa,
6648 new_fcport->d_id.b.domain,
6649 new_fcport->d_id.b.area,
6650 new_fcport->d_id.b.al_pa);
6651 fcport->d_id.b24 = new_fcport->d_id.b24;
6655 fcport->d_id.b24 = new_fcport->d_id.b24;
6656 fcport->flags |= FCF_LOGIN_NEEDED;
6660 if (found && NVME_TARGET(vha->hw, fcport)) {
6661 if (fcport->disc_state == DSC_DELETE_PEND) {
6662 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
6663 vha->fcport_count--;
6664 fcport->login_succ = 0;
6669 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6672 /* If device was not in our fcports list, then add it. */
6673 new_fcport->scan_state = QLA_FCPORT_FOUND;
6674 list_add_tail(&new_fcport->list, &vha->vp_fcports);
6676 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6679 /* Allocate a new replacement fcport. */
6680 nxt_d_id.b24 = new_fcport->d_id.b24;
6681 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
6682 if (new_fcport == NULL) {
6683 ql_log(ql_log_warn, vha, 0xd032,
6684 "Memory allocation failed for fcport.\n");
6685 return (QLA_MEMORY_ALLOC_FAILED);
6687 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
6688 new_fcport->d_id.b24 = nxt_d_id.b24;
6691 qla2x00_free_fcport(new_fcport);
6694 * Logout all previous fabric dev marked lost, except FCP2 devices.
6696 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6697 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6700 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
6703 if (fcport->scan_state == QLA_FCPORT_SCAN) {
6704 if ((qla_dual_mode_enabled(vha) ||
6705 qla_ini_mode_enabled(vha)) &&
6706 atomic_read(&fcport->state) == FCS_ONLINE) {
6707 qla2x00_mark_device_lost(vha, fcport,
6708 ql2xplogiabsentdevice);
6709 if (fcport->loop_id != FC_NO_LOOP_ID &&
6710 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
6711 fcport->port_type != FCT_INITIATOR &&
6712 fcport->port_type != FCT_BROADCAST) {
6713 ql_dbg(ql_dbg_disc, vha, 0x20f0,
6714 "%s %d %8phC post del sess\n",
6717 qlt_schedule_sess_for_deletion(fcport);
6723 if (fcport->scan_state == QLA_FCPORT_FOUND &&
6724 (fcport->flags & FCF_LOGIN_NEEDED) != 0)
6725 qla24xx_fcport_handle_login(vha, fcport);
6730 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
6732 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
6734 int loop_id = FC_NO_LOOP_ID;
6735 int lid = NPH_MGMT_SERVER - vha->vp_idx;
6736 unsigned long flags;
6737 struct qla_hw_data *ha = vha->hw;
6739 if (vha->vp_idx == 0) {
6740 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
6741 return NPH_MGMT_SERVER;
6744 /* pick id from high and work down to low */
6745 spin_lock_irqsave(&ha->vport_slock, flags);
6746 for (; lid > 0; lid--) {
6747 if (!test_bit(lid, vha->hw->loop_id_map)) {
6748 set_bit(lid, vha->hw->loop_id_map);
6753 spin_unlock_irqrestore(&ha->vport_slock, flags);
6759 * qla2x00_fabric_login
6760 * Issue fabric login command.
6763 * ha = adapter block pointer.
6764 * device = pointer to FC device type structure.
6767 * 0 - Login successfully
6769 * 2 - Initiator device
6773 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
6774 uint16_t *next_loopid)
6778 uint16_t tmp_loopid;
6779 uint16_t mb[MAILBOX_REGISTER_COUNT];
6780 struct qla_hw_data *ha = vha->hw;
6786 ql_dbg(ql_dbg_disc, vha, 0x2000,
6787 "Trying Fabric Login w/loop id 0x%04x for port "
6789 fcport->loop_id, fcport->d_id.b.domain,
6790 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6792 /* Login fcport on switch. */
6793 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
6794 fcport->d_id.b.domain, fcport->d_id.b.area,
6795 fcport->d_id.b.al_pa, mb, BIT_0);
6796 if (rval != QLA_SUCCESS) {
6799 if (mb[0] == MBS_PORT_ID_USED) {
6801 * Device has another loop ID. The firmware team
6802 * recommends the driver perform an implicit login with
6803 * the specified ID again. The ID we just used is save
6804 * here so we return with an ID that can be tried by
6808 tmp_loopid = fcport->loop_id;
6809 fcport->loop_id = mb[1];
6811 ql_dbg(ql_dbg_disc, vha, 0x2001,
6812 "Fabric Login: port in use - next loop "
6813 "id=0x%04x, port id= %02x%02x%02x.\n",
6814 fcport->loop_id, fcport->d_id.b.domain,
6815 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6817 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
6822 /* A retry occurred before. */
6823 *next_loopid = tmp_loopid;
6826 * No retry occurred before. Just increment the
6827 * ID value for next login.
6829 *next_loopid = (fcport->loop_id + 1);
6832 if (mb[1] & BIT_0) {
6833 fcport->port_type = FCT_INITIATOR;
6835 fcport->port_type = FCT_TARGET;
6836 if (mb[1] & BIT_1) {
6837 fcport->flags |= FCF_FCP2_DEVICE;
6842 fcport->supported_classes |= FC_COS_CLASS2;
6844 fcport->supported_classes |= FC_COS_CLASS3;
6846 if (IS_FWI2_CAPABLE(ha)) {
6849 FCF_CONF_COMP_SUPPORTED;
6854 } else if (mb[0] == MBS_LOOP_ID_USED) {
6856 * Loop ID already used, try next loop ID.
6859 rval = qla2x00_find_new_loop_id(vha, fcport);
6860 if (rval != QLA_SUCCESS) {
6861 /* Ran out of loop IDs to use */
6864 } else if (mb[0] == MBS_COMMAND_ERROR) {
6866 * Firmware possibly timed out during login. If NO
6867 * retries are left to do then the device is declared
6870 *next_loopid = fcport->loop_id;
6871 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6872 fcport->d_id.b.domain, fcport->d_id.b.area,
6873 fcport->d_id.b.al_pa);
6874 qla2x00_mark_device_lost(vha, fcport, 1);
6880 * unrecoverable / not handled error
6882 ql_dbg(ql_dbg_disc, vha, 0x2002,
6883 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6884 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
6885 fcport->d_id.b.area, fcport->d_id.b.al_pa,
6886 fcport->loop_id, jiffies);
6888 *next_loopid = fcport->loop_id;
6889 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6890 fcport->d_id.b.domain, fcport->d_id.b.area,
6891 fcport->d_id.b.al_pa);
6892 qla2x00_clear_loop_id(fcport);
6893 fcport->login_retry = 0;
6904 * qla2x00_local_device_login
6905 * Issue local device login command.
6908 * ha = adapter block pointer.
6909 * loop_id = loop id of device to login to.
6911 * Returns (Where's the #define!!!!):
6912 * 0 - Login successfully
6917 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
6920 uint16_t mb[MAILBOX_REGISTER_COUNT];
6922 memset(mb, 0, sizeof(mb));
6923 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
6924 if (rval == QLA_SUCCESS) {
6925 /* Interrogate mailbox registers for any errors */
6926 if (mb[0] == MBS_COMMAND_ERROR)
6928 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
6929 /* device not in PCB table */
6937 * qla2x00_loop_resync
6938 * Resync with fibre channel devices.
6941 * ha = adapter block pointer.
6947 qla2x00_loop_resync(scsi_qla_host_t *vha)
6949 int rval = QLA_SUCCESS;
6952 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6953 if (vha->flags.online) {
6954 if (!(rval = qla2x00_fw_ready(vha))) {
6955 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6958 if (!IS_QLAFX00(vha->hw)) {
6960 * Issue a marker after FW becomes
6963 qla2x00_marker(vha, vha->hw->base_qpair,
6965 vha->marker_needed = 0;
6968 /* Remap devices on Loop. */
6969 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6971 if (IS_QLAFX00(vha->hw))
6972 qlafx00_configure_devices(vha);
6974 qla2x00_configure_loop(vha);
6977 } while (!atomic_read(&vha->loop_down_timer) &&
6978 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6979 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
6984 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6985 return (QLA_FUNCTION_FAILED);
6988 ql_dbg(ql_dbg_disc, vha, 0x206c,
6989 "%s *** FAILED ***.\n", __func__);
6995 * qla2x00_perform_loop_resync
6996 * Description: This function will set the appropriate flags and call
6997 * qla2x00_loop_resync. If successful loop will be resynced
6998 * Arguments : scsi_qla_host_t pointer
6999 * returm : Success or Failure
7002 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
7006 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
7007 /*Configure the flags so that resync happens properly*/
7008 atomic_set(&ha->loop_down_timer, 0);
7009 if (!(ha->device_flags & DFLG_NO_CABLE)) {
7010 atomic_set(&ha->loop_state, LOOP_UP);
7011 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
7012 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
7013 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
7015 rval = qla2x00_loop_resync(ha);
7017 atomic_set(&ha->loop_state, LOOP_DEAD);
7019 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
7025 /* Assumes idc_lock always held on entry */
7027 qla83xx_reset_ownership(scsi_qla_host_t *vha)
7029 struct qla_hw_data *ha = vha->hw;
7030 uint32_t drv_presence, drv_presence_mask;
7031 uint32_t dev_part_info1, dev_part_info2, class_type;
7032 uint32_t class_type_mask = 0x3;
7033 uint16_t fcoe_other_function = 0xffff, i;
7035 if (IS_QLA8044(ha)) {
7036 drv_presence = qla8044_rd_direct(vha,
7037 QLA8044_CRB_DRV_ACTIVE_INDEX);
7038 dev_part_info1 = qla8044_rd_direct(vha,
7039 QLA8044_CRB_DEV_PART_INFO_INDEX);
7040 dev_part_info2 = qla8044_rd_direct(vha,
7041 QLA8044_CRB_DEV_PART_INFO2);
7043 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
7044 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
7045 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
7047 for (i = 0; i < 8; i++) {
7048 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
7049 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
7050 (i != ha->portnum)) {
7051 fcoe_other_function = i;
7055 if (fcoe_other_function == 0xffff) {
7056 for (i = 0; i < 8; i++) {
7057 class_type = ((dev_part_info2 >> (i * 4)) &
7059 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
7060 ((i + 8) != ha->portnum)) {
7061 fcoe_other_function = i + 8;
7067 * Prepare drv-presence mask based on fcoe functions present.
7068 * However consider only valid physical fcoe function numbers (0-15).
7070 drv_presence_mask = ~((1 << (ha->portnum)) |
7071 ((fcoe_other_function == 0xffff) ?
7072 0 : (1 << (fcoe_other_function))));
7074 /* We are the reset owner iff:
7075 * - No other protocol drivers present.
7076 * - This is the lowest among fcoe functions. */
7077 if (!(drv_presence & drv_presence_mask) &&
7078 (ha->portnum < fcoe_other_function)) {
7079 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
7080 "This host is Reset owner.\n");
7081 ha->flags.nic_core_reset_owner = 1;
7086 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
7088 int rval = QLA_SUCCESS;
7089 struct qla_hw_data *ha = vha->hw;
7092 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
7093 if (rval == QLA_SUCCESS) {
7094 drv_ack |= (1 << ha->portnum);
7095 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
7102 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
7104 int rval = QLA_SUCCESS;
7105 struct qla_hw_data *ha = vha->hw;
7108 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
7109 if (rval == QLA_SUCCESS) {
7110 drv_ack &= ~(1 << ha->portnum);
7111 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
7117 /* Assumes idc-lock always held on entry */
7119 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
7121 struct qla_hw_data *ha = vha->hw;
7122 uint32_t idc_audit_reg = 0, duration_secs = 0;
7124 switch (audit_type) {
7125 case IDC_AUDIT_TIMESTAMP:
7126 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
7127 idc_audit_reg = (ha->portnum) |
7128 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
7129 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
7132 case IDC_AUDIT_COMPLETION:
7133 duration_secs = ((jiffies_to_msecs(jiffies) -
7134 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
7135 idc_audit_reg = (ha->portnum) |
7136 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
7137 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
7141 ql_log(ql_log_warn, vha, 0xb078,
7142 "Invalid audit type specified.\n");
7147 /* Assumes idc_lock always held on entry */
7149 qla83xx_initiating_reset(scsi_qla_host_t *vha)
7151 struct qla_hw_data *ha = vha->hw;
7152 uint32_t idc_control, dev_state;
7154 __qla83xx_get_idc_control(vha, &idc_control);
7155 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
7156 ql_log(ql_log_info, vha, 0xb080,
7157 "NIC Core reset has been disabled. idc-control=0x%x\n",
7159 return QLA_FUNCTION_FAILED;
7162 /* Set NEED-RESET iff in READY state and we are the reset-owner */
7163 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
7164 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
7165 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
7166 QLA8XXX_DEV_NEED_RESET);
7167 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
7168 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
7170 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n",
7171 qdev_state(dev_state));
7173 /* SV: XXX: Is timeout required here? */
7174 /* Wait for IDC state change READY -> NEED_RESET */
7175 while (dev_state == QLA8XXX_DEV_READY) {
7176 qla83xx_idc_unlock(vha, 0);
7178 qla83xx_idc_lock(vha, 0);
7179 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
7183 /* Send IDC ack by writing to drv-ack register */
7184 __qla83xx_set_drv_ack(vha);
7190 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
7192 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
7196 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
7198 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
7202 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
7204 uint32_t drv_presence = 0;
7205 struct qla_hw_data *ha = vha->hw;
7207 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
7208 if (drv_presence & (1 << ha->portnum))
7211 return QLA_TEST_FAILED;
7215 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
7217 int rval = QLA_SUCCESS;
7218 struct qla_hw_data *ha = vha->hw;
7220 ql_dbg(ql_dbg_p3p, vha, 0xb058,
7221 "Entered %s().\n", __func__);
7223 if (vha->device_flags & DFLG_DEV_FAILED) {
7224 ql_log(ql_log_warn, vha, 0xb059,
7225 "Device in unrecoverable FAILED state.\n");
7226 return QLA_FUNCTION_FAILED;
7229 qla83xx_idc_lock(vha, 0);
7231 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
7232 ql_log(ql_log_warn, vha, 0xb05a,
7233 "Function=0x%x has been removed from IDC participation.\n",
7235 rval = QLA_FUNCTION_FAILED;
7239 qla83xx_reset_ownership(vha);
7241 rval = qla83xx_initiating_reset(vha);
7244 * Perform reset if we are the reset-owner,
7245 * else wait till IDC state changes to READY/FAILED.
7247 if (rval == QLA_SUCCESS) {
7248 rval = qla83xx_idc_state_handler(vha);
7250 if (rval == QLA_SUCCESS)
7251 ha->flags.nic_core_hung = 0;
7252 __qla83xx_clear_drv_ack(vha);
7256 qla83xx_idc_unlock(vha, 0);
7258 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
7264 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
7266 struct qla_hw_data *ha = vha->hw;
7267 int rval = QLA_FUNCTION_FAILED;
7269 if (!IS_MCTP_CAPABLE(ha)) {
7270 /* This message can be removed from the final version */
7271 ql_log(ql_log_info, vha, 0x506d,
7272 "This board is not MCTP capable\n");
7276 if (!ha->mctp_dump) {
7277 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
7278 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
7280 if (!ha->mctp_dump) {
7281 ql_log(ql_log_warn, vha, 0x506e,
7282 "Failed to allocate memory for mctp dump\n");
7287 #define MCTP_DUMP_STR_ADDR 0x00000000
7288 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
7289 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
7290 if (rval != QLA_SUCCESS) {
7291 ql_log(ql_log_warn, vha, 0x506f,
7292 "Failed to capture mctp dump\n");
7294 ql_log(ql_log_info, vha, 0x5070,
7295 "Mctp dump capture for host (%ld/%p).\n",
7296 vha->host_no, ha->mctp_dump);
7297 ha->mctp_dumped = 1;
7300 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
7301 ha->flags.nic_core_reset_hdlr_active = 1;
7302 rval = qla83xx_restart_nic_firmware(vha);
7304 /* NIC Core reset failed. */
7305 ql_log(ql_log_warn, vha, 0x5071,
7306 "Failed to restart nic firmware\n");
7308 ql_dbg(ql_dbg_p3p, vha, 0xb084,
7309 "Restarted NIC firmware successfully.\n");
7310 ha->flags.nic_core_reset_hdlr_active = 0;
7318 * qla2x00_quiesce_io
7319 * Description: This function will block the new I/Os
7320 * Its not aborting any I/Os as context
7321 * is not destroyed during quiescence
7322 * Arguments: scsi_qla_host_t
7326 qla2x00_quiesce_io(scsi_qla_host_t *vha)
7328 struct qla_hw_data *ha = vha->hw;
7329 struct scsi_qla_host *vp, *tvp;
7330 unsigned long flags;
7332 ql_dbg(ql_dbg_dpc, vha, 0x401d,
7333 "Quiescing I/O - ha=%p.\n", ha);
7335 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
7336 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
7337 atomic_set(&vha->loop_state, LOOP_DOWN);
7338 qla2x00_mark_all_devices_lost(vha);
7340 spin_lock_irqsave(&ha->vport_slock, flags);
7341 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7342 atomic_inc(&vp->vref_count);
7343 spin_unlock_irqrestore(&ha->vport_slock, flags);
7345 qla2x00_mark_all_devices_lost(vp);
7347 spin_lock_irqsave(&ha->vport_slock, flags);
7348 atomic_dec(&vp->vref_count);
7350 spin_unlock_irqrestore(&ha->vport_slock, flags);
7352 if (!atomic_read(&vha->loop_down_timer))
7353 atomic_set(&vha->loop_down_timer,
7356 /* Wait for pending cmds to complete */
7357 WARN_ON_ONCE(qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST)
7362 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
7364 struct qla_hw_data *ha = vha->hw;
7365 struct scsi_qla_host *vp, *tvp;
7366 unsigned long flags;
7370 /* For ISP82XX, driver waits for completion of the commands.
7371 * online flag should be set.
7373 if (!(IS_P3P_TYPE(ha)))
7374 vha->flags.online = 0;
7375 ha->flags.chip_reset_done = 0;
7376 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
7377 vha->qla_stats.total_isp_aborts++;
7379 ql_log(ql_log_info, vha, 0x00af,
7380 "Performing ISP error recovery - ha=%p.\n", ha);
7382 ha->flags.purge_mbox = 1;
7383 /* For ISP82XX, reset_chip is just disabling interrupts.
7384 * Driver waits for the completion of the commands.
7385 * the interrupts need to be enabled.
7387 if (!(IS_P3P_TYPE(ha)))
7388 ha->isp_ops->reset_chip(vha);
7390 ha->link_data_rate = PORT_SPEED_UNKNOWN;
7392 ha->flags.rida_fmt2 = 0;
7393 ha->flags.n2n_ae = 0;
7394 ha->flags.lip_ae = 0;
7395 ha->current_topology = 0;
7397 ha->flags.fw_init_done = 0;
7399 ha->base_qpair->chip_reset = ha->chip_reset;
7400 ha->base_qpair->cmd_cnt = ha->base_qpair->cmd_completion_cnt = 0;
7401 ha->base_qpair->prev_completion_cnt = 0;
7402 for (i = 0; i < ha->max_qpairs; i++) {
7403 if (ha->queue_pair_map[i]) {
7404 ha->queue_pair_map[i]->chip_reset =
7405 ha->base_qpair->chip_reset;
7406 ha->queue_pair_map[i]->cmd_cnt =
7407 ha->queue_pair_map[i]->cmd_completion_cnt = 0;
7408 ha->base_qpair->prev_completion_cnt = 0;
7412 /* purge MBox commands */
7413 spin_lock_irqsave(&ha->hardware_lock, flags);
7414 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags)) {
7415 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
7416 complete(&ha->mbx_intr_comp);
7418 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7421 while (atomic_read(&ha->num_pend_mbx_stage2) ||
7422 atomic_read(&ha->num_pend_mbx_stage1)) {
7428 ha->flags.purge_mbox = 0;
7430 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
7431 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
7432 atomic_set(&vha->loop_state, LOOP_DOWN);
7433 qla2x00_mark_all_devices_lost(vha);
7435 spin_lock_irqsave(&ha->vport_slock, flags);
7436 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7437 atomic_inc(&vp->vref_count);
7438 spin_unlock_irqrestore(&ha->vport_slock, flags);
7440 qla2x00_mark_all_devices_lost(vp);
7442 spin_lock_irqsave(&ha->vport_slock, flags);
7443 atomic_dec(&vp->vref_count);
7445 spin_unlock_irqrestore(&ha->vport_slock, flags);
7447 if (!atomic_read(&vha->loop_down_timer))
7448 atomic_set(&vha->loop_down_timer,
7452 /* Clear all async request states across all VPs. */
7453 list_for_each_entry(fcport, &vha->vp_fcports, list) {
7454 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7455 fcport->scan_state = 0;
7457 spin_lock_irqsave(&ha->vport_slock, flags);
7458 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7459 atomic_inc(&vp->vref_count);
7460 spin_unlock_irqrestore(&ha->vport_slock, flags);
7462 list_for_each_entry(fcport, &vp->vp_fcports, list)
7463 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7465 spin_lock_irqsave(&ha->vport_slock, flags);
7466 atomic_dec(&vp->vref_count);
7468 spin_unlock_irqrestore(&ha->vport_slock, flags);
7470 /* Make sure for ISP 82XX IO DMA is complete */
7471 if (IS_P3P_TYPE(ha)) {
7472 qla82xx_chip_reset_cleanup(vha);
7473 ql_log(ql_log_info, vha, 0x00b4,
7474 "Done chip reset cleanup.\n");
7476 /* Done waiting for pending commands. Reset online flag */
7477 vha->flags.online = 0;
7480 /* Requeue all commands in outstanding command list. */
7481 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
7482 /* memory barrier */
7488 * Resets ISP and aborts all outstanding commands.
7491 * ha = adapter block pointer.
7497 qla2x00_abort_isp(scsi_qla_host_t *vha)
7500 struct qla_hw_data *ha = vha->hw;
7501 struct scsi_qla_host *vp, *tvp;
7502 struct req_que *req = ha->req_q_map[0];
7503 unsigned long flags;
7506 if (vha->flags.online) {
7507 qla2x00_abort_isp_cleanup(vha);
7509 vha->dport_status |= DPORT_DIAG_CHIP_RESET_IN_PROGRESS;
7510 vha->dport_status &= ~DPORT_DIAG_IN_PROGRESS;
7512 if (vha->hw->flags.port_isolated)
7515 if (qla2x00_isp_reg_stat(ha)) {
7516 ql_log(ql_log_info, vha, 0x803f,
7517 "ISP Abort - ISP reg disconnect, exiting.\n");
7521 if (test_and_clear_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags)) {
7522 ha->flags.chip_reset_done = 1;
7523 vha->flags.online = 1;
7525 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7529 if (IS_QLA8031(ha)) {
7530 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
7531 "Clearing fcoe driver presence.\n");
7532 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
7533 ql_dbg(ql_dbg_p3p, vha, 0xb073,
7534 "Error while clearing DRV-Presence.\n");
7537 if (unlikely(pci_channel_offline(ha->pdev) &&
7538 ha->flags.pci_channel_io_perm_failure)) {
7539 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7544 switch (vha->qlini_mode) {
7545 case QLA2XXX_INI_MODE_DISABLED:
7546 if (!qla_tgt_mode_enabled(vha))
7549 case QLA2XXX_INI_MODE_DUAL:
7550 if (!qla_dual_mode_enabled(vha) &&
7551 !qla_ini_mode_enabled(vha))
7554 case QLA2XXX_INI_MODE_ENABLED:
7559 ha->isp_ops->get_flash_version(vha, req->ring);
7561 if (qla2x00_isp_reg_stat(ha)) {
7562 ql_log(ql_log_info, vha, 0x803f,
7563 "ISP Abort - ISP reg disconnect pre nvram config, exiting.\n");
7566 ha->isp_ops->nvram_config(vha);
7568 if (qla2x00_isp_reg_stat(ha)) {
7569 ql_log(ql_log_info, vha, 0x803f,
7570 "ISP Abort - ISP reg disconnect post nvmram config, exiting.\n");
7574 /* User may have updated [fcp|nvme] prefer in flash */
7575 list_for_each_entry(fcport, &vha->vp_fcports, list) {
7576 if (NVME_PRIORITY(ha, fcport))
7577 fcport->do_prli_nvme = 1;
7579 fcport->do_prli_nvme = 0;
7582 if (!qla2x00_restart_isp(vha)) {
7583 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7585 if (!atomic_read(&vha->loop_down_timer)) {
7587 * Issue marker command only when we are going
7588 * to start the I/O .
7590 vha->marker_needed = 1;
7593 vha->flags.online = 1;
7595 ha->isp_ops->enable_intrs(ha);
7597 ha->isp_abort_cnt = 0;
7598 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7600 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
7601 qla2x00_get_fw_version(vha);
7603 } else { /* failed the ISP abort */
7604 vha->flags.online = 1;
7605 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
7606 if (ha->isp_abort_cnt == 0) {
7607 ql_log(ql_log_fatal, vha, 0x8035,
7608 "ISP error recover failed - "
7609 "board disabled.\n");
7611 * The next call disables the board
7614 qla2x00_abort_isp_cleanup(vha);
7615 vha->flags.online = 0;
7616 clear_bit(ISP_ABORT_RETRY,
7619 } else { /* schedule another ISP abort */
7620 ha->isp_abort_cnt--;
7621 ql_dbg(ql_dbg_taskm, vha, 0x8020,
7622 "ISP abort - retry remaining %d.\n",
7627 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
7628 ql_dbg(ql_dbg_taskm, vha, 0x8021,
7629 "ISP error recovery - retrying (%d) "
7630 "more times.\n", ha->isp_abort_cnt);
7631 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7638 if (vha->hw->flags.port_isolated) {
7639 qla2x00_abort_isp_cleanup(vha);
7644 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
7645 qla2x00_configure_hba(vha);
7646 spin_lock_irqsave(&ha->vport_slock, flags);
7647 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7649 atomic_inc(&vp->vref_count);
7650 spin_unlock_irqrestore(&ha->vport_slock, flags);
7652 /* User may have updated [fcp|nvme] prefer in flash */
7653 list_for_each_entry(fcport, &vp->vp_fcports, list) {
7654 if (NVME_PRIORITY(ha, fcport))
7655 fcport->do_prli_nvme = 1;
7657 fcport->do_prli_nvme = 0;
7660 qla2x00_vp_abort_isp(vp);
7662 spin_lock_irqsave(&ha->vport_slock, flags);
7663 atomic_dec(&vp->vref_count);
7666 spin_unlock_irqrestore(&ha->vport_slock, flags);
7668 if (IS_QLA8031(ha)) {
7669 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
7670 "Setting back fcoe driver presence.\n");
7671 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
7672 ql_dbg(ql_dbg_p3p, vha, 0xb074,
7673 "Error while setting DRV-Presence.\n");
7676 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
7684 * qla2x00_restart_isp
7685 * restarts the ISP after a reset
7688 * ha = adapter block pointer.
7694 qla2x00_restart_isp(scsi_qla_host_t *vha)
7697 struct qla_hw_data *ha = vha->hw;
7699 /* If firmware needs to be loaded */
7700 if (qla2x00_isp_firmware(vha)) {
7701 vha->flags.online = 0;
7702 status = ha->isp_ops->chip_diag(vha);
7705 status = qla2x00_setup_chip(vha);
7710 status = qla2x00_init_rings(vha);
7714 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7715 ha->flags.chip_reset_done = 1;
7717 /* Initialize the queues in use */
7718 qla25xx_init_queues(ha);
7720 status = qla2x00_fw_ready(vha);
7722 /* if no cable then assume it's good */
7723 return vha->device_flags & DFLG_NO_CABLE ? 0 : status;
7726 /* Issue a marker after FW becomes ready. */
7727 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
7728 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7734 qla25xx_init_queues(struct qla_hw_data *ha)
7736 struct rsp_que *rsp = NULL;
7737 struct req_que *req = NULL;
7738 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7742 for (i = 1; i < ha->max_rsp_queues; i++) {
7743 rsp = ha->rsp_q_map[i];
7744 if (rsp && test_bit(i, ha->rsp_qid_map)) {
7745 rsp->options &= ~BIT_0;
7746 ret = qla25xx_init_rsp_que(base_vha, rsp);
7747 if (ret != QLA_SUCCESS)
7748 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
7749 "%s Rsp que: %d init failed.\n",
7752 ql_dbg(ql_dbg_init, base_vha, 0x0100,
7753 "%s Rsp que: %d inited.\n",
7757 for (i = 1; i < ha->max_req_queues; i++) {
7758 req = ha->req_q_map[i];
7759 if (req && test_bit(i, ha->req_qid_map)) {
7760 /* Clear outstanding commands array. */
7761 req->options &= ~BIT_0;
7762 ret = qla25xx_init_req_que(base_vha, req);
7763 if (ret != QLA_SUCCESS)
7764 ql_dbg(ql_dbg_init, base_vha, 0x0101,
7765 "%s Req que: %d init failed.\n",
7768 ql_dbg(ql_dbg_init, base_vha, 0x0102,
7769 "%s Req que: %d inited.\n",
7777 * qla2x00_reset_adapter
7781 * ha = adapter block pointer.
7784 qla2x00_reset_adapter(scsi_qla_host_t *vha)
7786 unsigned long flags = 0;
7787 struct qla_hw_data *ha = vha->hw;
7788 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7790 vha->flags.online = 0;
7791 ha->isp_ops->disable_intrs(ha);
7793 spin_lock_irqsave(&ha->hardware_lock, flags);
7794 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
7795 rd_reg_word(®->hccr); /* PCI Posting. */
7796 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
7797 rd_reg_word(®->hccr); /* PCI Posting. */
7798 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7804 qla24xx_reset_adapter(scsi_qla_host_t *vha)
7806 unsigned long flags = 0;
7807 struct qla_hw_data *ha = vha->hw;
7808 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
7810 if (IS_P3P_TYPE(ha))
7813 vha->flags.online = 0;
7814 ha->isp_ops->disable_intrs(ha);
7816 spin_lock_irqsave(&ha->hardware_lock, flags);
7817 wrt_reg_dword(®->hccr, HCCRX_SET_RISC_RESET);
7818 rd_reg_dword(®->hccr);
7819 wrt_reg_dword(®->hccr, HCCRX_REL_RISC_PAUSE);
7820 rd_reg_dword(®->hccr);
7821 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7823 if (IS_NOPOLLING_TYPE(ha))
7824 ha->isp_ops->enable_intrs(ha);
7829 /* On sparc systems, obtain port and node WWN from firmware
7832 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
7833 struct nvram_24xx *nv)
7836 struct qla_hw_data *ha = vha->hw;
7837 struct pci_dev *pdev = ha->pdev;
7838 struct device_node *dp = pci_device_to_OF_node(pdev);
7842 val = of_get_property(dp, "port-wwn", &len);
7843 if (val && len >= WWN_SIZE)
7844 memcpy(nv->port_name, val, WWN_SIZE);
7846 val = of_get_property(dp, "node-wwn", &len);
7847 if (val && len >= WWN_SIZE)
7848 memcpy(nv->node_name, val, WWN_SIZE);
7853 qla24xx_nvram_config(scsi_qla_host_t *vha)
7856 struct init_cb_24xx *icb;
7857 struct nvram_24xx *nv;
7859 uint8_t *dptr1, *dptr2;
7862 struct qla_hw_data *ha = vha->hw;
7865 icb = (struct init_cb_24xx *)ha->init_cb;
7868 /* Determine NVRAM starting address. */
7869 if (ha->port_no == 0) {
7870 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
7871 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
7873 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
7874 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
7877 ha->nvram_size = sizeof(*nv);
7878 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7880 /* Get VPD data into cache */
7881 ha->vpd = ha->nvram + VPD_OFFSET;
7882 ha->isp_ops->read_nvram(vha, ha->vpd,
7883 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
7885 /* Get NVRAM data into cache and calculate checksum. */
7886 dptr = (__force __le32 *)nv;
7887 ha->isp_ops->read_nvram(vha, dptr, ha->nvram_base, ha->nvram_size);
7888 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7889 chksum += le32_to_cpu(*dptr);
7891 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
7892 "Contents of NVRAM\n");
7893 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
7894 nv, ha->nvram_size);
7896 /* Bad NVRAM data, set defaults parameters. */
7897 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
7898 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
7899 /* Reset NVRAM data. */
7900 ql_log(ql_log_warn, vha, 0x006b,
7901 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
7902 chksum, nv->id, nv->nvram_version);
7903 ql_dump_buffer(ql_dbg_init, vha, 0x006b, nv, sizeof(*nv));
7904 ql_log(ql_log_warn, vha, 0x006c,
7905 "Falling back to functioning (yet invalid -- WWPN) "
7909 * Set default initialization control block.
7911 memset(nv, 0, ha->nvram_size);
7912 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7913 nv->version = cpu_to_le16(ICB_VERSION);
7914 nv->frame_payload_size = cpu_to_le16(2048);
7915 nv->execution_throttle = cpu_to_le16(0xFFFF);
7916 nv->exchange_count = cpu_to_le16(0);
7917 nv->hard_address = cpu_to_le16(124);
7918 nv->port_name[0] = 0x21;
7919 nv->port_name[1] = 0x00 + ha->port_no + 1;
7920 nv->port_name[2] = 0x00;
7921 nv->port_name[3] = 0xe0;
7922 nv->port_name[4] = 0x8b;
7923 nv->port_name[5] = 0x1c;
7924 nv->port_name[6] = 0x55;
7925 nv->port_name[7] = 0x86;
7926 nv->node_name[0] = 0x20;
7927 nv->node_name[1] = 0x00;
7928 nv->node_name[2] = 0x00;
7929 nv->node_name[3] = 0xe0;
7930 nv->node_name[4] = 0x8b;
7931 nv->node_name[5] = 0x1c;
7932 nv->node_name[6] = 0x55;
7933 nv->node_name[7] = 0x86;
7934 qla24xx_nvram_wwn_from_ofw(vha, nv);
7935 nv->login_retry_count = cpu_to_le16(8);
7936 nv->interrupt_delay_timer = cpu_to_le16(0);
7937 nv->login_timeout = cpu_to_le16(0);
7938 nv->firmware_options_1 =
7939 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7940 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7941 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7942 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7943 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7944 nv->efi_parameters = cpu_to_le32(0);
7945 nv->reset_delay = 5;
7946 nv->max_luns_per_target = cpu_to_le16(128);
7947 nv->port_down_retry_count = cpu_to_le16(30);
7948 nv->link_down_timeout = cpu_to_le16(30);
7953 if (qla_tgt_mode_enabled(vha)) {
7954 /* Don't enable full login after initial LIP */
7955 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7956 /* Don't enable LIP full login for initiator */
7957 nv->host_p &= cpu_to_le32(~BIT_10);
7960 qlt_24xx_config_nvram_stage1(vha, nv);
7962 /* Reset Initialization control block */
7963 memset(icb, 0, ha->init_cb_size);
7965 /* Copy 1st segment. */
7966 dptr1 = (uint8_t *)icb;
7967 dptr2 = (uint8_t *)&nv->version;
7968 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7970 *dptr1++ = *dptr2++;
7972 icb->login_retry_count = nv->login_retry_count;
7973 icb->link_down_on_nos = nv->link_down_on_nos;
7975 /* Copy 2nd segment. */
7976 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7977 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7978 cnt = (uint8_t *)&icb->reserved_3 -
7979 (uint8_t *)&icb->interrupt_delay_timer;
7981 *dptr1++ = *dptr2++;
7982 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
7984 * Setup driver NVRAM options.
7986 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7989 qlt_24xx_config_nvram_stage2(vha, icb);
7991 if (nv->host_p & cpu_to_le32(BIT_15)) {
7992 /* Use alternate WWN? */
7993 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7994 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7997 /* Prepare nodename */
7998 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
8000 * Firmware will apply the following mask if the nodename was
8003 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
8004 icb->node_name[0] &= 0xF0;
8007 /* Set host adapter parameters. */
8008 ha->flags.disable_risc_code_load = 0;
8009 ha->flags.enable_lip_reset = 0;
8010 ha->flags.enable_lip_full_login =
8011 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
8012 ha->flags.enable_target_reset =
8013 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
8014 ha->flags.enable_led_scheme = 0;
8015 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
8017 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
8018 (BIT_6 | BIT_5 | BIT_4)) >> 4;
8020 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
8021 sizeof(ha->fw_seriallink_options24));
8023 /* save HBA serial number */
8024 ha->serial0 = icb->port_name[5];
8025 ha->serial1 = icb->port_name[6];
8026 ha->serial2 = icb->port_name[7];
8027 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
8028 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
8030 icb->execution_throttle = cpu_to_le16(0xFFFF);
8032 ha->retry_count = le16_to_cpu(nv->login_retry_count);
8034 /* Set minimum login_timeout to 4 seconds. */
8035 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
8036 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
8037 if (le16_to_cpu(nv->login_timeout) < 4)
8038 nv->login_timeout = cpu_to_le16(4);
8039 ha->login_timeout = le16_to_cpu(nv->login_timeout);
8041 /* Set minimum RATOV to 100 tenths of a second. */
8044 ha->loop_reset_delay = nv->reset_delay;
8046 /* Link Down Timeout = 0:
8048 * When Port Down timer expires we will start returning
8049 * I/O's to OS with "DID_NO_CONNECT".
8051 * Link Down Timeout != 0:
8053 * The driver waits for the link to come up after link down
8054 * before returning I/Os to OS with "DID_NO_CONNECT".
8056 if (le16_to_cpu(nv->link_down_timeout) == 0) {
8057 ha->loop_down_abort_time =
8058 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
8060 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
8061 ha->loop_down_abort_time =
8062 (LOOP_DOWN_TIME - ha->link_down_timeout);
8065 /* Need enough time to try and get the port back. */
8066 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8067 if (qlport_down_retry)
8068 ha->port_down_retry_count = qlport_down_retry;
8070 /* Set login_retry_count */
8071 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8072 if (ha->port_down_retry_count ==
8073 le16_to_cpu(nv->port_down_retry_count) &&
8074 ha->port_down_retry_count > 3)
8075 ha->login_retry_count = ha->port_down_retry_count;
8076 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8077 ha->login_retry_count = ha->port_down_retry_count;
8078 if (ql2xloginretrycount)
8079 ha->login_retry_count = ql2xloginretrycount;
8081 /* N2N: driver will initiate Login instead of FW */
8082 icb->firmware_options_3 |= cpu_to_le32(BIT_8);
8085 if (!vha->flags.init_done) {
8086 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8087 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8088 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8089 le16_to_cpu(icb->interrupt_delay_timer) : 2;
8091 icb->firmware_options_2 &= cpu_to_le32(
8092 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8093 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8094 ha->zio_mode = QLA_ZIO_MODE_6;
8096 ql_log(ql_log_info, vha, 0x006f,
8097 "ZIO mode %d enabled; timer delay (%d us).\n",
8098 ha->zio_mode, ha->zio_timer * 100);
8100 icb->firmware_options_2 |= cpu_to_le32(
8101 (uint32_t)ha->zio_mode);
8102 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8106 ql_log(ql_log_warn, vha, 0x0070,
8107 "NVRAM configuration failed.\n");
8113 qla27xx_print_image(struct scsi_qla_host *vha, char *name,
8114 struct qla27xx_image_status *image_status)
8116 ql_dbg(ql_dbg_init, vha, 0x018b,
8117 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
8119 image_status->image_status_mask,
8120 le16_to_cpu(image_status->generation),
8121 image_status->ver_major,
8122 image_status->ver_minor,
8123 image_status->bitmap,
8124 le32_to_cpu(image_status->checksum),
8125 le32_to_cpu(image_status->signature));
8129 qla28xx_check_aux_image_status_signature(
8130 struct qla27xx_image_status *image_status)
8132 ulong signature = le32_to_cpu(image_status->signature);
8134 return signature != QLA28XX_AUX_IMG_STATUS_SIGN;
8138 qla27xx_check_image_status_signature(struct qla27xx_image_status *image_status)
8140 ulong signature = le32_to_cpu(image_status->signature);
8143 signature != QLA27XX_IMG_STATUS_SIGN &&
8144 signature != QLA28XX_IMG_STATUS_SIGN;
8148 qla27xx_image_status_checksum(struct qla27xx_image_status *image_status)
8150 __le32 *p = (__force __le32 *)image_status;
8151 uint n = sizeof(*image_status) / sizeof(*p);
8155 sum += le32_to_cpup(p);
8161 qla28xx_component_bitmask(struct qla27xx_image_status *aux, uint bitmask)
8163 return aux->bitmap & bitmask ?
8164 QLA27XX_SECONDARY_IMAGE : QLA27XX_PRIMARY_IMAGE;
8168 qla28xx_component_status(
8169 struct active_regions *active_regions, struct qla27xx_image_status *aux)
8171 active_regions->aux.board_config =
8172 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_BOARD_CONFIG);
8174 active_regions->aux.vpd_nvram =
8175 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_VPD_NVRAM);
8177 active_regions->aux.npiv_config_0_1 =
8178 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1);
8180 active_regions->aux.npiv_config_2_3 =
8181 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3);
8183 active_regions->aux.nvme_params =
8184 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NVME_PARAMS);
8188 qla27xx_compare_image_generation(
8189 struct qla27xx_image_status *pri_image_status,
8190 struct qla27xx_image_status *sec_image_status)
8192 /* calculate generation delta as uint16 (this accounts for wrap) */
8194 le16_to_cpu(pri_image_status->generation) -
8195 le16_to_cpu(sec_image_status->generation);
8197 ql_dbg(ql_dbg_init, NULL, 0x0180, "generation delta = %d\n", delta);
8203 qla28xx_get_aux_images(
8204 struct scsi_qla_host *vha, struct active_regions *active_regions)
8206 struct qla_hw_data *ha = vha->hw;
8207 struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
8208 bool valid_pri_image = false, valid_sec_image = false;
8209 bool active_pri_image = false, active_sec_image = false;
8211 if (!ha->flt_region_aux_img_status_pri) {
8212 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
8213 goto check_sec_image;
8216 qla24xx_read_flash_data(vha, (uint32_t *)&pri_aux_image_status,
8217 ha->flt_region_aux_img_status_pri,
8218 sizeof(pri_aux_image_status) >> 2);
8219 qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
8221 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
8222 ql_dbg(ql_dbg_init, vha, 0x018b,
8223 "Primary aux image signature (%#x) not valid\n",
8224 le32_to_cpu(pri_aux_image_status.signature));
8225 goto check_sec_image;
8228 if (qla27xx_image_status_checksum(&pri_aux_image_status)) {
8229 ql_dbg(ql_dbg_init, vha, 0x018c,
8230 "Primary aux image checksum failed\n");
8231 goto check_sec_image;
8234 valid_pri_image = true;
8236 if (pri_aux_image_status.image_status_mask & 1) {
8237 ql_dbg(ql_dbg_init, vha, 0x018d,
8238 "Primary aux image is active\n");
8239 active_pri_image = true;
8243 if (!ha->flt_region_aux_img_status_sec) {
8244 ql_dbg(ql_dbg_init, vha, 0x018a,
8245 "Secondary aux image not addressed\n");
8246 goto check_valid_image;
8249 qla24xx_read_flash_data(vha, (uint32_t *)&sec_aux_image_status,
8250 ha->flt_region_aux_img_status_sec,
8251 sizeof(sec_aux_image_status) >> 2);
8252 qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
8254 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
8255 ql_dbg(ql_dbg_init, vha, 0x018b,
8256 "Secondary aux image signature (%#x) not valid\n",
8257 le32_to_cpu(sec_aux_image_status.signature));
8258 goto check_valid_image;
8261 if (qla27xx_image_status_checksum(&sec_aux_image_status)) {
8262 ql_dbg(ql_dbg_init, vha, 0x018c,
8263 "Secondary aux image checksum failed\n");
8264 goto check_valid_image;
8267 valid_sec_image = true;
8269 if (sec_aux_image_status.image_status_mask & 1) {
8270 ql_dbg(ql_dbg_init, vha, 0x018d,
8271 "Secondary aux image is active\n");
8272 active_sec_image = true;
8276 if (valid_pri_image && active_pri_image &&
8277 valid_sec_image && active_sec_image) {
8278 if (qla27xx_compare_image_generation(&pri_aux_image_status,
8279 &sec_aux_image_status) >= 0) {
8280 qla28xx_component_status(active_regions,
8281 &pri_aux_image_status);
8283 qla28xx_component_status(active_regions,
8284 &sec_aux_image_status);
8286 } else if (valid_pri_image && active_pri_image) {
8287 qla28xx_component_status(active_regions, &pri_aux_image_status);
8288 } else if (valid_sec_image && active_sec_image) {
8289 qla28xx_component_status(active_regions, &sec_aux_image_status);
8292 ql_dbg(ql_dbg_init, vha, 0x018f,
8293 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u, NVME=%u\n",
8294 active_regions->aux.board_config,
8295 active_regions->aux.vpd_nvram,
8296 active_regions->aux.npiv_config_0_1,
8297 active_regions->aux.npiv_config_2_3,
8298 active_regions->aux.nvme_params);
8302 qla27xx_get_active_image(struct scsi_qla_host *vha,
8303 struct active_regions *active_regions)
8305 struct qla_hw_data *ha = vha->hw;
8306 struct qla27xx_image_status pri_image_status, sec_image_status;
8307 bool valid_pri_image = false, valid_sec_image = false;
8308 bool active_pri_image = false, active_sec_image = false;
8310 if (!ha->flt_region_img_status_pri) {
8311 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
8312 goto check_sec_image;
8315 if (qla24xx_read_flash_data(vha, (uint32_t *)&pri_image_status,
8316 ha->flt_region_img_status_pri, sizeof(pri_image_status) >> 2) !=
8319 goto check_sec_image;
8321 qla27xx_print_image(vha, "Primary image", &pri_image_status);
8323 if (qla27xx_check_image_status_signature(&pri_image_status)) {
8324 ql_dbg(ql_dbg_init, vha, 0x018b,
8325 "Primary image signature (%#x) not valid\n",
8326 le32_to_cpu(pri_image_status.signature));
8327 goto check_sec_image;
8330 if (qla27xx_image_status_checksum(&pri_image_status)) {
8331 ql_dbg(ql_dbg_init, vha, 0x018c,
8332 "Primary image checksum failed\n");
8333 goto check_sec_image;
8336 valid_pri_image = true;
8338 if (pri_image_status.image_status_mask & 1) {
8339 ql_dbg(ql_dbg_init, vha, 0x018d,
8340 "Primary image is active\n");
8341 active_pri_image = true;
8345 if (!ha->flt_region_img_status_sec) {
8346 ql_dbg(ql_dbg_init, vha, 0x018a, "Secondary image not addressed\n");
8347 goto check_valid_image;
8350 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
8351 ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
8352 qla27xx_print_image(vha, "Secondary image", &sec_image_status);
8354 if (qla27xx_check_image_status_signature(&sec_image_status)) {
8355 ql_dbg(ql_dbg_init, vha, 0x018b,
8356 "Secondary image signature (%#x) not valid\n",
8357 le32_to_cpu(sec_image_status.signature));
8358 goto check_valid_image;
8361 if (qla27xx_image_status_checksum(&sec_image_status)) {
8362 ql_dbg(ql_dbg_init, vha, 0x018c,
8363 "Secondary image checksum failed\n");
8364 goto check_valid_image;
8367 valid_sec_image = true;
8369 if (sec_image_status.image_status_mask & 1) {
8370 ql_dbg(ql_dbg_init, vha, 0x018d,
8371 "Secondary image is active\n");
8372 active_sec_image = true;
8376 if (valid_pri_image && active_pri_image)
8377 active_regions->global = QLA27XX_PRIMARY_IMAGE;
8379 if (valid_sec_image && active_sec_image) {
8380 if (!active_regions->global ||
8381 qla27xx_compare_image_generation(
8382 &pri_image_status, &sec_image_status) < 0) {
8383 active_regions->global = QLA27XX_SECONDARY_IMAGE;
8387 ql_dbg(ql_dbg_init, vha, 0x018f, "active image %s (%u)\n",
8388 active_regions->global == QLA27XX_DEFAULT_IMAGE ?
8389 "default (boot/fw)" :
8390 active_regions->global == QLA27XX_PRIMARY_IMAGE ?
8392 active_regions->global == QLA27XX_SECONDARY_IMAGE ?
8393 "secondary" : "invalid",
8394 active_regions->global);
8397 bool qla24xx_risc_firmware_invalid(uint32_t *dword)
8400 !(dword[4] | dword[5] | dword[6] | dword[7]) ||
8401 !(~dword[4] | ~dword[5] | ~dword[6] | ~dword[7]);
8405 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
8409 uint templates, segments, fragment;
8414 uint32_t risc_addr, risc_size, risc_attr = 0;
8415 struct qla_hw_data *ha = vha->hw;
8416 struct req_que *req = ha->req_q_map[0];
8417 struct fwdt *fwdt = ha->fwdt;
8419 ql_dbg(ql_dbg_init, vha, 0x008b,
8420 "FW: Loading firmware from flash (%x).\n", faddr);
8422 dcode = (uint32_t *)req->ring;
8423 qla24xx_read_flash_data(vha, dcode, faddr, 8);
8424 if (qla24xx_risc_firmware_invalid(dcode)) {
8425 ql_log(ql_log_fatal, vha, 0x008c,
8426 "Unable to verify the integrity of flash firmware "
8428 ql_log(ql_log_fatal, vha, 0x008d,
8429 "Firmware data: %08x %08x %08x %08x.\n",
8430 dcode[0], dcode[1], dcode[2], dcode[3]);
8432 return QLA_FUNCTION_FAILED;
8435 dcode = (uint32_t *)req->ring;
8437 segments = FA_RISC_CODE_SEGMENTS;
8438 for (j = 0; j < segments; j++) {
8439 ql_dbg(ql_dbg_init, vha, 0x008d,
8440 "-> Loading segment %u...\n", j);
8441 qla24xx_read_flash_data(vha, dcode, faddr, 10);
8442 risc_addr = be32_to_cpu((__force __be32)dcode[2]);
8443 risc_size = be32_to_cpu((__force __be32)dcode[3]);
8445 *srisc_addr = risc_addr;
8446 risc_attr = be32_to_cpu((__force __be32)dcode[9]);
8449 dlen = ha->fw_transfer_size >> 2;
8450 for (fragment = 0; risc_size; fragment++) {
8451 if (dlen > risc_size)
8454 ql_dbg(ql_dbg_init, vha, 0x008e,
8455 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
8456 fragment, risc_addr, faddr, dlen);
8457 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
8458 for (i = 0; i < dlen; i++)
8459 dcode[i] = swab32(dcode[i]);
8461 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
8463 ql_log(ql_log_fatal, vha, 0x008f,
8464 "-> Failed load firmware fragment %u.\n",
8466 return QLA_FUNCTION_FAILED;
8475 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8478 templates = (risc_attr & BIT_9) ? 2 : 1;
8479 ql_dbg(ql_dbg_init, vha, 0x0160, "-> templates = %u\n", templates);
8480 for (j = 0; j < templates; j++, fwdt++) {
8481 vfree(fwdt->template);
8482 fwdt->template = NULL;
8485 dcode = (uint32_t *)req->ring;
8486 qla24xx_read_flash_data(vha, dcode, faddr, 7);
8487 risc_size = be32_to_cpu((__force __be32)dcode[2]);
8488 ql_dbg(ql_dbg_init, vha, 0x0161,
8489 "-> fwdt%u template array at %#x (%#x dwords)\n",
8490 j, faddr, risc_size);
8491 if (!risc_size || !~risc_size) {
8492 ql_dbg(ql_dbg_init, vha, 0x0162,
8493 "-> fwdt%u failed to read array\n", j);
8497 /* skip header and ignore checksum */
8501 ql_dbg(ql_dbg_init, vha, 0x0163,
8502 "-> fwdt%u template allocate template %#x words...\n",
8504 fwdt->template = vmalloc_array(risc_size, sizeof(*dcode));
8505 if (!fwdt->template) {
8506 ql_log(ql_log_warn, vha, 0x0164,
8507 "-> fwdt%u failed allocate template.\n", j);
8511 dcode = fwdt->template;
8512 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
8514 if (!qla27xx_fwdt_template_valid(dcode)) {
8515 ql_log(ql_log_warn, vha, 0x0165,
8516 "-> fwdt%u failed template validate\n", j);
8520 dlen = qla27xx_fwdt_template_size(dcode);
8521 ql_dbg(ql_dbg_init, vha, 0x0166,
8522 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8523 j, dlen, dlen / sizeof(*dcode));
8524 if (dlen > risc_size * sizeof(*dcode)) {
8525 ql_log(ql_log_warn, vha, 0x0167,
8526 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8527 j, dlen - risc_size * sizeof(*dcode));
8531 fwdt->length = dlen;
8532 ql_dbg(ql_dbg_init, vha, 0x0168,
8533 "-> fwdt%u loaded template ok\n", j);
8535 faddr += risc_size + 1;
8541 vfree(fwdt->template);
8542 fwdt->template = NULL;
8548 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
8551 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8557 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
8558 struct fw_blob *blob;
8559 struct qla_hw_data *ha = vha->hw;
8560 struct req_que *req = ha->req_q_map[0];
8562 /* Load firmware blob. */
8563 blob = qla2x00_request_firmware(vha);
8565 ql_log(ql_log_info, vha, 0x0083,
8566 "Firmware image unavailable.\n");
8567 ql_log(ql_log_info, vha, 0x0084,
8568 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
8569 return QLA_FUNCTION_FAILED;
8574 wcode = (uint16_t *)req->ring;
8576 fwcode = (__force __be16 *)blob->fw->data;
8579 /* Validate firmware image by checking version. */
8580 if (blob->fw->size < 8 * sizeof(uint16_t)) {
8581 ql_log(ql_log_fatal, vha, 0x0085,
8582 "Unable to verify integrity of firmware image (%zd).\n",
8584 goto fail_fw_integrity;
8586 for (i = 0; i < 4; i++)
8587 wcode[i] = be16_to_cpu(fwcode[i + 4]);
8588 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
8589 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
8590 wcode[2] == 0 && wcode[3] == 0)) {
8591 ql_log(ql_log_fatal, vha, 0x0086,
8592 "Unable to verify integrity of firmware image.\n");
8593 ql_log(ql_log_fatal, vha, 0x0087,
8594 "Firmware data: %04x %04x %04x %04x.\n",
8595 wcode[0], wcode[1], wcode[2], wcode[3]);
8596 goto fail_fw_integrity;
8600 while (*seg && rval == QLA_SUCCESS) {
8602 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
8603 risc_size = be16_to_cpu(fwcode[3]);
8605 /* Validate firmware image size. */
8606 fwclen += risc_size * sizeof(uint16_t);
8607 if (blob->fw->size < fwclen) {
8608 ql_log(ql_log_fatal, vha, 0x0088,
8609 "Unable to verify integrity of firmware image "
8610 "(%zd).\n", blob->fw->size);
8611 goto fail_fw_integrity;
8615 while (risc_size > 0 && rval == QLA_SUCCESS) {
8616 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
8617 if (wlen > risc_size)
8619 ql_dbg(ql_dbg_init, vha, 0x0089,
8620 "Loading risc segment@ risc addr %x number of "
8621 "words 0x%x.\n", risc_addr, wlen);
8623 for (i = 0; i < wlen; i++)
8624 wcode[i] = swab16((__force u32)fwcode[i]);
8626 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
8629 ql_log(ql_log_fatal, vha, 0x008a,
8630 "Failed to load segment %d of firmware.\n",
8647 return QLA_FUNCTION_FAILED;
8651 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8654 uint templates, segments, fragment;
8657 uint32_t risc_addr, risc_size, risc_attr = 0;
8660 struct fw_blob *blob;
8662 struct qla_hw_data *ha = vha->hw;
8663 struct req_que *req = ha->req_q_map[0];
8664 struct fwdt *fwdt = ha->fwdt;
8666 ql_dbg(ql_dbg_init, vha, 0x0090,
8667 "-> FW: Loading via request-firmware.\n");
8669 blob = qla2x00_request_firmware(vha);
8671 ql_log(ql_log_warn, vha, 0x0092,
8672 "-> Firmware file not found.\n");
8674 return QLA_FUNCTION_FAILED;
8677 fwcode = (__force __be32 *)blob->fw->data;
8678 dcode = (__force uint32_t *)fwcode;
8679 if (qla24xx_risc_firmware_invalid(dcode)) {
8680 ql_log(ql_log_fatal, vha, 0x0093,
8681 "Unable to verify integrity of firmware image (%zd).\n",
8683 ql_log(ql_log_fatal, vha, 0x0095,
8684 "Firmware data: %08x %08x %08x %08x.\n",
8685 dcode[0], dcode[1], dcode[2], dcode[3]);
8686 return QLA_FUNCTION_FAILED;
8689 dcode = (uint32_t *)req->ring;
8691 segments = FA_RISC_CODE_SEGMENTS;
8692 for (j = 0; j < segments; j++) {
8693 ql_dbg(ql_dbg_init, vha, 0x0096,
8694 "-> Loading segment %u...\n", j);
8695 risc_addr = be32_to_cpu(fwcode[2]);
8696 risc_size = be32_to_cpu(fwcode[3]);
8699 *srisc_addr = risc_addr;
8700 risc_attr = be32_to_cpu(fwcode[9]);
8703 dlen = ha->fw_transfer_size >> 2;
8704 for (fragment = 0; risc_size; fragment++) {
8705 if (dlen > risc_size)
8708 ql_dbg(ql_dbg_init, vha, 0x0097,
8709 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
8710 fragment, risc_addr,
8711 (uint32_t)(fwcode - (typeof(fwcode))blob->fw->data),
8714 for (i = 0; i < dlen; i++)
8715 dcode[i] = swab32((__force u32)fwcode[i]);
8717 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
8719 ql_log(ql_log_fatal, vha, 0x0098,
8720 "-> Failed load firmware fragment %u.\n",
8722 return QLA_FUNCTION_FAILED;
8731 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8734 templates = (risc_attr & BIT_9) ? 2 : 1;
8735 ql_dbg(ql_dbg_init, vha, 0x0170, "-> templates = %u\n", templates);
8736 for (j = 0; j < templates; j++, fwdt++) {
8737 vfree(fwdt->template);
8738 fwdt->template = NULL;
8741 risc_size = be32_to_cpu(fwcode[2]);
8742 ql_dbg(ql_dbg_init, vha, 0x0171,
8743 "-> fwdt%u template array at %#x (%#x dwords)\n",
8744 j, (uint32_t)((void *)fwcode - (void *)blob->fw->data),
8746 if (!risc_size || !~risc_size) {
8747 ql_dbg(ql_dbg_init, vha, 0x0172,
8748 "-> fwdt%u failed to read array\n", j);
8752 /* skip header and ignore checksum */
8756 ql_dbg(ql_dbg_init, vha, 0x0173,
8757 "-> fwdt%u template allocate template %#x words...\n",
8759 fwdt->template = vmalloc_array(risc_size, sizeof(*dcode));
8760 if (!fwdt->template) {
8761 ql_log(ql_log_warn, vha, 0x0174,
8762 "-> fwdt%u failed allocate template.\n", j);
8766 dcode = fwdt->template;
8767 for (i = 0; i < risc_size; i++)
8768 dcode[i] = (__force u32)fwcode[i];
8770 if (!qla27xx_fwdt_template_valid(dcode)) {
8771 ql_log(ql_log_warn, vha, 0x0175,
8772 "-> fwdt%u failed template validate\n", j);
8776 dlen = qla27xx_fwdt_template_size(dcode);
8777 ql_dbg(ql_dbg_init, vha, 0x0176,
8778 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8779 j, dlen, dlen / sizeof(*dcode));
8780 if (dlen > risc_size * sizeof(*dcode)) {
8781 ql_log(ql_log_warn, vha, 0x0177,
8782 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8783 j, dlen - risc_size * sizeof(*dcode));
8787 fwdt->length = dlen;
8788 ql_dbg(ql_dbg_init, vha, 0x0178,
8789 "-> fwdt%u loaded template ok\n", j);
8791 fwcode += risc_size + 1;
8797 vfree(fwdt->template);
8798 fwdt->template = NULL;
8805 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8809 if (ql2xfwloadbin == 1)
8810 return qla81xx_load_risc(vha, srisc_addr);
8814 * 1) Firmware via request-firmware interface (.bin file).
8815 * 2) Firmware residing in flash.
8817 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8818 if (rval == QLA_SUCCESS)
8821 return qla24xx_load_risc_flash(vha, srisc_addr,
8822 vha->hw->flt_region_fw);
8826 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8829 struct qla_hw_data *ha = vha->hw;
8830 struct active_regions active_regions = { };
8832 if (ql2xfwloadbin == 2)
8835 /* FW Load priority:
8836 * 1) Firmware residing in flash.
8837 * 2) Firmware via request-firmware interface (.bin file).
8838 * 3) Golden-Firmware residing in flash -- (limited operation).
8841 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8842 goto try_primary_fw;
8844 qla27xx_get_active_image(vha, &active_regions);
8846 if (active_regions.global != QLA27XX_SECONDARY_IMAGE)
8847 goto try_primary_fw;
8849 ql_dbg(ql_dbg_init, vha, 0x008b,
8850 "Loading secondary firmware image.\n");
8851 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw_sec);
8856 ql_dbg(ql_dbg_init, vha, 0x008b,
8857 "Loading primary firmware image.\n");
8858 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
8863 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8864 if (!rval || !ha->flt_region_gold_fw)
8867 ql_log(ql_log_info, vha, 0x0099,
8868 "Attempting to fallback to golden firmware.\n");
8869 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
8873 ql_log(ql_log_info, vha, 0x009a, "Need firmware flash update.\n");
8874 ha->flags.running_gold_fw = 1;
8879 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
8882 struct qla_hw_data *ha = vha->hw;
8884 if (ha->flags.pci_channel_io_perm_failure)
8886 if (!IS_FWI2_CAPABLE(ha))
8888 if (!ha->fw_major_version)
8890 if (!ha->flags.fw_started)
8893 ret = qla2x00_stop_firmware(vha);
8894 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
8895 ret != QLA_INVALID_COMMAND && retries ; retries--) {
8896 ha->isp_ops->reset_chip(vha);
8897 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
8899 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
8901 ql_log(ql_log_info, vha, 0x8015,
8902 "Attempting retry of stop-firmware command.\n");
8903 ret = qla2x00_stop_firmware(vha);
8907 ha->flags.fw_init_done = 0;
8911 qla24xx_configure_vhba(scsi_qla_host_t *vha)
8913 int rval = QLA_SUCCESS;
8915 uint16_t mb[MAILBOX_REGISTER_COUNT];
8916 struct qla_hw_data *ha = vha->hw;
8917 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
8922 rval = qla2x00_fw_ready(base_vha);
8924 if (rval == QLA_SUCCESS) {
8925 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8926 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8929 vha->flags.management_server_logged_in = 0;
8931 /* Login to SNS first */
8932 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
8934 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
8935 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
8936 ql_dbg(ql_dbg_init, vha, 0x0120,
8937 "Failed SNS login: loop_id=%x, rval2=%d\n",
8940 ql_dbg(ql_dbg_init, vha, 0x0103,
8941 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
8942 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
8943 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
8944 return (QLA_FUNCTION_FAILED);
8947 atomic_set(&vha->loop_down_timer, 0);
8948 atomic_set(&vha->loop_state, LOOP_UP);
8949 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8950 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
8951 rval = qla2x00_loop_resync(base_vha);
8956 /* 84XX Support **************************************************************/
8958 static LIST_HEAD(qla_cs84xx_list);
8959 static DEFINE_MUTEX(qla_cs84xx_mutex);
8961 static struct qla_chip_state_84xx *
8962 qla84xx_get_chip(struct scsi_qla_host *vha)
8964 struct qla_chip_state_84xx *cs84xx;
8965 struct qla_hw_data *ha = vha->hw;
8967 mutex_lock(&qla_cs84xx_mutex);
8969 /* Find any shared 84xx chip. */
8970 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
8971 if (cs84xx->bus == ha->pdev->bus) {
8972 kref_get(&cs84xx->kref);
8977 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
8981 kref_init(&cs84xx->kref);
8982 spin_lock_init(&cs84xx->access_lock);
8983 mutex_init(&cs84xx->fw_update_mutex);
8984 cs84xx->bus = ha->pdev->bus;
8986 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
8988 mutex_unlock(&qla_cs84xx_mutex);
8993 __qla84xx_chip_release(struct kref *kref)
8995 struct qla_chip_state_84xx *cs84xx =
8996 container_of(kref, struct qla_chip_state_84xx, kref);
8998 mutex_lock(&qla_cs84xx_mutex);
8999 list_del(&cs84xx->list);
9000 mutex_unlock(&qla_cs84xx_mutex);
9005 qla84xx_put_chip(struct scsi_qla_host *vha)
9007 struct qla_hw_data *ha = vha->hw;
9010 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
9014 qla84xx_init_chip(scsi_qla_host_t *vha)
9018 struct qla_hw_data *ha = vha->hw;
9020 mutex_lock(&ha->cs84xx->fw_update_mutex);
9022 rval = qla84xx_verify_chip(vha, status);
9024 mutex_unlock(&ha->cs84xx->fw_update_mutex);
9026 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED :
9030 /* 81XX Support **************************************************************/
9033 qla81xx_nvram_config(scsi_qla_host_t *vha)
9036 struct init_cb_81xx *icb;
9037 struct nvram_81xx *nv;
9039 uint8_t *dptr1, *dptr2;
9042 struct qla_hw_data *ha = vha->hw;
9044 struct active_regions active_regions = { };
9047 icb = (struct init_cb_81xx *)ha->init_cb;
9050 /* Determine NVRAM starting address. */
9051 ha->nvram_size = sizeof(*nv);
9052 ha->vpd_size = FA_NVRAM_VPD_SIZE;
9053 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
9054 ha->vpd_size = FA_VPD_SIZE_82XX;
9056 if (IS_QLA28XX(ha) || IS_QLA27XX(ha))
9057 qla28xx_get_aux_images(vha, &active_regions);
9059 /* Get VPD data into cache */
9060 ha->vpd = ha->nvram + VPD_OFFSET;
9062 faddr = ha->flt_region_vpd;
9063 if (IS_QLA28XX(ha)) {
9064 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
9065 faddr = ha->flt_region_vpd_sec;
9066 ql_dbg(ql_dbg_init, vha, 0x0110,
9067 "Loading %s nvram image.\n",
9068 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
9069 "primary" : "secondary");
9071 ha->isp_ops->read_optrom(vha, ha->vpd, faddr << 2, ha->vpd_size);
9073 /* Get NVRAM data into cache and calculate checksum. */
9074 faddr = ha->flt_region_nvram;
9075 if (IS_QLA28XX(ha)) {
9076 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
9077 faddr = ha->flt_region_nvram_sec;
9079 ql_dbg(ql_dbg_init, vha, 0x0110,
9080 "Loading %s nvram image.\n",
9081 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
9082 "primary" : "secondary");
9083 ha->isp_ops->read_optrom(vha, ha->nvram, faddr << 2, ha->nvram_size);
9085 dptr = (__force __le32 *)nv;
9086 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
9087 chksum += le32_to_cpu(*dptr);
9089 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
9090 "Contents of NVRAM:\n");
9091 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
9092 nv, ha->nvram_size);
9094 /* Bad NVRAM data, set defaults parameters. */
9095 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
9096 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
9097 /* Reset NVRAM data. */
9098 ql_log(ql_log_info, vha, 0x0073,
9099 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
9100 chksum, nv->id, le16_to_cpu(nv->nvram_version));
9101 ql_dump_buffer(ql_dbg_init, vha, 0x0073, nv, sizeof(*nv));
9102 ql_log(ql_log_info, vha, 0x0074,
9103 "Falling back to functioning (yet invalid -- WWPN) "
9107 * Set default initialization control block.
9109 memset(nv, 0, ha->nvram_size);
9110 nv->nvram_version = cpu_to_le16(ICB_VERSION);
9111 nv->version = cpu_to_le16(ICB_VERSION);
9112 nv->frame_payload_size = cpu_to_le16(2048);
9113 nv->execution_throttle = cpu_to_le16(0xFFFF);
9114 nv->exchange_count = cpu_to_le16(0);
9115 nv->port_name[0] = 0x21;
9116 nv->port_name[1] = 0x00 + ha->port_no + 1;
9117 nv->port_name[2] = 0x00;
9118 nv->port_name[3] = 0xe0;
9119 nv->port_name[4] = 0x8b;
9120 nv->port_name[5] = 0x1c;
9121 nv->port_name[6] = 0x55;
9122 nv->port_name[7] = 0x86;
9123 nv->node_name[0] = 0x20;
9124 nv->node_name[1] = 0x00;
9125 nv->node_name[2] = 0x00;
9126 nv->node_name[3] = 0xe0;
9127 nv->node_name[4] = 0x8b;
9128 nv->node_name[5] = 0x1c;
9129 nv->node_name[6] = 0x55;
9130 nv->node_name[7] = 0x86;
9131 nv->login_retry_count = cpu_to_le16(8);
9132 nv->interrupt_delay_timer = cpu_to_le16(0);
9133 nv->login_timeout = cpu_to_le16(0);
9134 nv->firmware_options_1 =
9135 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
9136 nv->firmware_options_2 = cpu_to_le32(2 << 4);
9137 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
9138 nv->firmware_options_3 = cpu_to_le32(2 << 13);
9139 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
9140 nv->efi_parameters = cpu_to_le32(0);
9141 nv->reset_delay = 5;
9142 nv->max_luns_per_target = cpu_to_le16(128);
9143 nv->port_down_retry_count = cpu_to_le16(30);
9144 nv->link_down_timeout = cpu_to_le16(180);
9145 nv->enode_mac[0] = 0x00;
9146 nv->enode_mac[1] = 0xC0;
9147 nv->enode_mac[2] = 0xDD;
9148 nv->enode_mac[3] = 0x04;
9149 nv->enode_mac[4] = 0x05;
9150 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
9155 if (IS_T10_PI_CAPABLE(ha))
9156 nv->frame_payload_size &= cpu_to_le16(~7);
9158 qlt_81xx_config_nvram_stage1(vha, nv);
9160 /* Reset Initialization control block */
9161 memset(icb, 0, ha->init_cb_size);
9163 /* Copy 1st segment. */
9164 dptr1 = (uint8_t *)icb;
9165 dptr2 = (uint8_t *)&nv->version;
9166 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
9168 *dptr1++ = *dptr2++;
9170 icb->login_retry_count = nv->login_retry_count;
9172 /* Copy 2nd segment. */
9173 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
9174 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
9175 cnt = (uint8_t *)&icb->reserved_5 -
9176 (uint8_t *)&icb->interrupt_delay_timer;
9178 *dptr1++ = *dptr2++;
9180 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
9181 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
9182 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
9183 icb->enode_mac[0] = 0x00;
9184 icb->enode_mac[1] = 0xC0;
9185 icb->enode_mac[2] = 0xDD;
9186 icb->enode_mac[3] = 0x04;
9187 icb->enode_mac[4] = 0x05;
9188 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
9191 /* Use extended-initialization control block. */
9192 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
9193 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
9195 * Setup driver NVRAM options.
9197 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
9200 qlt_81xx_config_nvram_stage2(vha, icb);
9202 /* Use alternate WWN? */
9203 if (nv->host_p & cpu_to_le32(BIT_15)) {
9204 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
9205 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
9208 /* Prepare nodename */
9209 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
9211 * Firmware will apply the following mask if the nodename was
9214 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
9215 icb->node_name[0] &= 0xF0;
9218 if (IS_QLA28XX(ha) || IS_QLA27XX(ha)) {
9219 if ((nv->enhanced_features & BIT_7) == 0)
9220 ha->flags.scm_supported_a = 1;
9223 /* Set host adapter parameters. */
9224 ha->flags.disable_risc_code_load = 0;
9225 ha->flags.enable_lip_reset = 0;
9226 ha->flags.enable_lip_full_login =
9227 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
9228 ha->flags.enable_target_reset =
9229 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
9230 ha->flags.enable_led_scheme = 0;
9231 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
9233 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
9234 (BIT_6 | BIT_5 | BIT_4)) >> 4;
9236 /* save HBA serial number */
9237 ha->serial0 = icb->port_name[5];
9238 ha->serial1 = icb->port_name[6];
9239 ha->serial2 = icb->port_name[7];
9240 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
9241 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
9243 icb->execution_throttle = cpu_to_le16(0xFFFF);
9245 ha->retry_count = le16_to_cpu(nv->login_retry_count);
9247 /* Set minimum login_timeout to 4 seconds. */
9248 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
9249 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
9250 if (le16_to_cpu(nv->login_timeout) < 4)
9251 nv->login_timeout = cpu_to_le16(4);
9252 ha->login_timeout = le16_to_cpu(nv->login_timeout);
9254 /* Set minimum RATOV to 100 tenths of a second. */
9257 ha->loop_reset_delay = nv->reset_delay;
9259 /* Link Down Timeout = 0:
9261 * When Port Down timer expires we will start returning
9262 * I/O's to OS with "DID_NO_CONNECT".
9264 * Link Down Timeout != 0:
9266 * The driver waits for the link to come up after link down
9267 * before returning I/Os to OS with "DID_NO_CONNECT".
9269 if (le16_to_cpu(nv->link_down_timeout) == 0) {
9270 ha->loop_down_abort_time =
9271 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
9273 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
9274 ha->loop_down_abort_time =
9275 (LOOP_DOWN_TIME - ha->link_down_timeout);
9278 /* Need enough time to try and get the port back. */
9279 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
9280 if (qlport_down_retry)
9281 ha->port_down_retry_count = qlport_down_retry;
9283 /* Set login_retry_count */
9284 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
9285 if (ha->port_down_retry_count ==
9286 le16_to_cpu(nv->port_down_retry_count) &&
9287 ha->port_down_retry_count > 3)
9288 ha->login_retry_count = ha->port_down_retry_count;
9289 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
9290 ha->login_retry_count = ha->port_down_retry_count;
9291 if (ql2xloginretrycount)
9292 ha->login_retry_count = ql2xloginretrycount;
9294 /* if not running MSI-X we need handshaking on interrupts */
9295 if (!vha->hw->flags.msix_enabled &&
9296 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)))
9297 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
9300 if (!vha->flags.init_done) {
9301 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
9302 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
9303 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
9304 le16_to_cpu(icb->interrupt_delay_timer) : 2;
9306 icb->firmware_options_2 &= cpu_to_le32(
9307 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
9308 vha->flags.process_response_queue = 0;
9309 if (ha->zio_mode != QLA_ZIO_DISABLED) {
9310 ha->zio_mode = QLA_ZIO_MODE_6;
9312 ql_log(ql_log_info, vha, 0x0075,
9313 "ZIO mode %d enabled; timer delay (%d us).\n",
9315 ha->zio_timer * 100);
9317 icb->firmware_options_2 |= cpu_to_le32(
9318 (uint32_t)ha->zio_mode);
9319 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
9320 vha->flags.process_response_queue = 1;
9323 /* enable RIDA Format2 */
9324 icb->firmware_options_3 |= cpu_to_le32(BIT_0);
9326 /* N2N: driver will initiate Login instead of FW */
9327 icb->firmware_options_3 |= cpu_to_le32(BIT_8);
9329 /* Determine NVMe/FCP priority for target ports */
9330 ha->fc4_type_priority = qla2xxx_get_fc4_priority(vha);
9333 ql_log(ql_log_warn, vha, 0x0076,
9334 "NVRAM configuration failed.\n");
9340 qla82xx_restart_isp(scsi_qla_host_t *vha)
9343 struct qla_hw_data *ha = vha->hw;
9344 struct scsi_qla_host *vp, *tvp;
9345 unsigned long flags;
9347 status = qla2x00_init_rings(vha);
9349 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
9350 ha->flags.chip_reset_done = 1;
9352 status = qla2x00_fw_ready(vha);
9354 /* Issue a marker after FW becomes ready. */
9355 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
9356 vha->flags.online = 1;
9357 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
9360 /* if no cable then assume it's good */
9361 if ((vha->device_flags & DFLG_NO_CABLE))
9366 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
9368 if (!atomic_read(&vha->loop_down_timer)) {
9370 * Issue marker command only when we are going
9371 * to start the I/O .
9373 vha->marker_needed = 1;
9376 ha->isp_ops->enable_intrs(ha);
9378 ha->isp_abort_cnt = 0;
9379 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
9381 /* Update the firmware version */
9382 status = qla82xx_check_md_needed(vha);
9385 ha->flags.fce_enabled = 1;
9387 fce_calc_size(ha->fce_bufs));
9388 rval = qla2x00_enable_fce_trace(vha,
9389 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
9392 ql_log(ql_log_warn, vha, 0x8001,
9393 "Unable to reinitialize FCE (%d).\n",
9395 ha->flags.fce_enabled = 0;
9400 memset(ha->eft, 0, EFT_SIZE);
9401 rval = qla2x00_enable_eft_trace(vha,
9402 ha->eft_dma, EFT_NUM_BUFFERS);
9404 ql_log(ql_log_warn, vha, 0x8010,
9405 "Unable to reinitialize EFT (%d).\n",
9412 ql_dbg(ql_dbg_taskm, vha, 0x8011,
9413 "qla82xx_restart_isp succeeded.\n");
9415 spin_lock_irqsave(&ha->vport_slock, flags);
9416 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
9418 atomic_inc(&vp->vref_count);
9419 spin_unlock_irqrestore(&ha->vport_slock, flags);
9421 qla2x00_vp_abort_isp(vp);
9423 spin_lock_irqsave(&ha->vport_slock, flags);
9424 atomic_dec(&vp->vref_count);
9427 spin_unlock_irqrestore(&ha->vport_slock, flags);
9430 ql_log(ql_log_warn, vha, 0x8016,
9431 "qla82xx_restart_isp **** FAILED ****.\n");
9438 * qla24xx_get_fcp_prio
9439 * Gets the fcp cmd priority value for the logged in port.
9440 * Looks for a match of the port descriptors within
9441 * each of the fcp prio config entries. If a match is found,
9442 * the tag (priority) value is returned.
9445 * vha = scsi host structure pointer.
9446 * fcport = port structure pointer.
9449 * non-zero (if found)
9456 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
9459 uint8_t pid_match, wwn_match;
9461 uint32_t pid1, pid2;
9462 uint64_t wwn1, wwn2;
9463 struct qla_fcp_prio_entry *pri_entry;
9464 struct qla_hw_data *ha = vha->hw;
9466 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
9470 entries = ha->fcp_prio_cfg->num_entries;
9471 pri_entry = &ha->fcp_prio_cfg->entry[0];
9473 for (i = 0; i < entries; i++) {
9474 pid_match = wwn_match = 0;
9476 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
9481 /* check source pid for a match */
9482 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
9483 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
9484 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
9485 if (pid1 == INVALID_PORT_ID)
9487 else if (pid1 == pid2)
9491 /* check destination pid for a match */
9492 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
9493 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
9494 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
9495 if (pid1 == INVALID_PORT_ID)
9497 else if (pid1 == pid2)
9501 /* check source WWN for a match */
9502 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
9503 wwn1 = wwn_to_u64(vha->port_name);
9504 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
9505 if (wwn2 == (uint64_t)-1)
9507 else if (wwn1 == wwn2)
9511 /* check destination WWN for a match */
9512 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
9513 wwn1 = wwn_to_u64(fcport->port_name);
9514 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
9515 if (wwn2 == (uint64_t)-1)
9517 else if (wwn1 == wwn2)
9521 if (pid_match == 2 || wwn_match == 2) {
9522 /* Found a matching entry */
9523 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
9524 priority = pri_entry->tag;
9535 * qla24xx_update_fcport_fcp_prio
9536 * Activates fcp priority for the logged in fc port
9539 * vha = scsi host structure pointer.
9540 * fcp = port structure pointer.
9543 * QLA_SUCCESS or QLA_FUNCTION_FAILED
9549 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
9555 if (fcport->port_type != FCT_TARGET ||
9556 fcport->loop_id == FC_NO_LOOP_ID)
9557 return QLA_FUNCTION_FAILED;
9559 priority = qla24xx_get_fcp_prio(vha, fcport);
9561 return QLA_FUNCTION_FAILED;
9563 if (IS_P3P_TYPE(vha->hw)) {
9564 fcport->fcp_prio = priority & 0xf;
9568 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
9569 if (ret == QLA_SUCCESS) {
9570 if (fcport->fcp_prio != priority)
9571 ql_dbg(ql_dbg_user, vha, 0x709e,
9572 "Updated FCP_CMND priority - value=%d loop_id=%d "
9573 "port_id=%02x%02x%02x.\n", priority,
9574 fcport->loop_id, fcport->d_id.b.domain,
9575 fcport->d_id.b.area, fcport->d_id.b.al_pa);
9576 fcport->fcp_prio = priority & 0xf;
9578 ql_dbg(ql_dbg_user, vha, 0x704f,
9579 "Unable to update FCP_CMND priority - ret=0x%x for "
9580 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
9581 fcport->d_id.b.domain, fcport->d_id.b.area,
9582 fcport->d_id.b.al_pa);
9587 * qla24xx_update_all_fcp_prio
9588 * Activates fcp priority for all the logged in ports
9591 * ha = adapter block pointer.
9594 * QLA_SUCCESS or QLA_FUNCTION_FAILED
9600 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
9605 ret = QLA_FUNCTION_FAILED;
9606 /* We need to set priority for all logged in ports */
9607 list_for_each_entry(fcport, &vha->vp_fcports, list)
9608 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
9613 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
9614 int vp_idx, bool startqp)
9619 struct qla_hw_data *ha = vha->hw;
9620 uint16_t qpair_id = 0;
9621 struct qla_qpair *qpair = NULL;
9622 struct qla_msix_entry *msix;
9624 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
9625 ql_log(ql_log_warn, vha, 0x00181,
9626 "FW/Driver is not multi-queue capable.\n");
9630 if (ql2xmqsupport || ql2xnvmeenable) {
9631 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
9632 if (qpair == NULL) {
9633 ql_log(ql_log_warn, vha, 0x0182,
9634 "Failed to allocate memory for queue pair.\n");
9638 qpair->hw = vha->hw;
9640 qpair->qp_lock_ptr = &qpair->qp_lock;
9641 spin_lock_init(&qpair->qp_lock);
9642 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
9644 /* Assign available que pair id */
9645 mutex_lock(&ha->mq_lock);
9646 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
9647 if (ha->num_qpairs >= ha->max_qpairs) {
9648 mutex_unlock(&ha->mq_lock);
9649 ql_log(ql_log_warn, vha, 0x0183,
9650 "No resources to create additional q pair.\n");
9654 set_bit(qpair_id, ha->qpair_qid_map);
9655 ha->queue_pair_map[qpair_id] = qpair;
9656 qpair->id = qpair_id;
9657 qpair->vp_idx = vp_idx;
9658 qpair->fw_started = ha->flags.fw_started;
9659 INIT_LIST_HEAD(&qpair->hints_list);
9660 INIT_LIST_HEAD(&qpair->dsd_list);
9661 qpair->chip_reset = ha->base_qpair->chip_reset;
9662 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
9663 qpair->enable_explicit_conf =
9664 ha->base_qpair->enable_explicit_conf;
9666 for (i = 0; i < ha->msix_count; i++) {
9667 msix = &ha->msix_entries[i];
9671 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
9672 "Vector %x selected for qpair\n", msix->vector);
9676 ql_log(ql_log_warn, vha, 0x0184,
9677 "Out of MSI-X vectors!.\n");
9681 qpair->msix->in_use = 1;
9682 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
9683 qpair->pdev = ha->pdev;
9684 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
9685 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
9687 mutex_unlock(&ha->mq_lock);
9689 /* Create response queue first */
9690 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
9692 ql_log(ql_log_warn, vha, 0x0185,
9693 "Failed to create response queue.\n");
9697 qpair->rsp = ha->rsp_q_map[rsp_id];
9699 /* Create request queue */
9700 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
9703 ql_log(ql_log_warn, vha, 0x0186,
9704 "Failed to create request queue.\n");
9708 qpair->req = ha->req_q_map[req_id];
9709 qpair->rsp->req = qpair->req;
9710 qpair->rsp->qpair = qpair;
9712 if (!qpair->cpu_mapped)
9713 qla_cpu_update(qpair, raw_smp_processor_id());
9715 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
9716 if (ha->fw_attributes & BIT_4)
9717 qpair->difdix_supported = 1;
9720 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
9721 if (!qpair->srb_mempool) {
9722 ql_log(ql_log_warn, vha, 0xd036,
9723 "Failed to create srb mempool for qpair %d\n",
9728 if (qla_create_buf_pool(vha, qpair)) {
9729 ql_log(ql_log_warn, vha, 0xd036,
9730 "Failed to initialize buf pool for qpair %d\n",
9735 /* Mark as online */
9738 if (!vha->flags.qpairs_available)
9739 vha->flags.qpairs_available = 1;
9741 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
9742 "Request/Response queue pair created, id %d\n",
9744 ql_dbg(ql_dbg_init, vha, 0x0187,
9745 "Request/Response queue pair created, id %d\n",
9751 mempool_destroy(qpair->srb_mempool);
9753 qla25xx_delete_req_que(vha, qpair->req);
9755 qla25xx_delete_rsp_que(vha, qpair->rsp);
9757 mutex_lock(&ha->mq_lock);
9758 qpair->msix->in_use = 0;
9759 list_del(&qpair->qp_list_elem);
9760 if (list_empty(&vha->qp_list))
9761 vha->flags.qpairs_available = 0;
9763 ha->queue_pair_map[qpair_id] = NULL;
9764 clear_bit(qpair_id, ha->qpair_qid_map);
9766 mutex_unlock(&ha->mq_lock);
9772 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
9774 int ret = QLA_FUNCTION_FAILED;
9775 struct qla_hw_data *ha = qpair->hw;
9777 qpair->delete_in_progress = 1;
9779 qla_free_buf_pool(qpair);
9781 ret = qla25xx_delete_req_que(vha, qpair->req);
9782 if (ret != QLA_SUCCESS)
9785 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
9786 if (ret != QLA_SUCCESS)
9789 if (!list_empty(&qpair->dsd_list)) {
9790 struct dsd_dma *dsd_ptr, *tdsd_ptr;
9792 /* clean up allocated prev pool */
9793 list_for_each_entry_safe(dsd_ptr, tdsd_ptr,
9794 &qpair->dsd_list, list) {
9795 dma_pool_free(ha->dl_dma_pool, dsd_ptr->dsd_addr,
9796 dsd_ptr->dsd_list_dma);
9797 list_del(&dsd_ptr->list);
9802 mutex_lock(&ha->mq_lock);
9803 ha->queue_pair_map[qpair->id] = NULL;
9804 clear_bit(qpair->id, ha->qpair_qid_map);
9806 list_del(&qpair->qp_list_elem);
9807 if (list_empty(&vha->qp_list)) {
9808 vha->flags.qpairs_available = 0;
9809 vha->flags.qpairs_req_created = 0;
9810 vha->flags.qpairs_rsp_created = 0;
9812 mempool_destroy(qpair->srb_mempool);
9814 mutex_unlock(&ha->mq_lock);
9822 qla2x00_count_set_bits(uint32_t num)
9824 /* Brian Kernighan's Algorithm */
9835 qla2x00_get_num_tgts(scsi_qla_host_t *vha)
9843 list_for_each_entry_safe(f, tf, &vha->vp_fcports, list) {
9844 if (f->port_type != FCT_TARGET)
9851 int qla2xxx_reset_stats(struct Scsi_Host *host, u32 flags)
9853 scsi_qla_host_t *vha = shost_priv(host);
9854 fc_port_t *fcport = NULL;
9855 unsigned long int_flags;
9857 if (flags & QLA2XX_HW_ERROR)
9858 vha->hw_err_cnt = 0;
9859 if (flags & QLA2XX_SHT_LNK_DWN)
9860 vha->short_link_down_cnt = 0;
9861 if (flags & QLA2XX_INT_ERR)
9862 vha->interface_err_cnt = 0;
9863 if (flags & QLA2XX_CMD_TIMEOUT)
9864 vha->cmd_timeout_cnt = 0;
9865 if (flags & QLA2XX_RESET_CMD_ERR)
9866 vha->reset_cmd_err_cnt = 0;
9867 if (flags & QLA2XX_TGT_SHT_LNK_DOWN) {
9868 spin_lock_irqsave(&vha->hw->tgt.sess_lock, int_flags);
9869 list_for_each_entry(fcport, &vha->vp_fcports, list) {
9870 fcport->tgt_short_link_down_cnt = 0;
9871 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
9873 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, int_flags);
9875 vha->link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
9879 int qla2xxx_start_stats(struct Scsi_Host *host, u32 flags)
9881 return qla2xxx_reset_stats(host, flags);
9884 int qla2xxx_stop_stats(struct Scsi_Host *host, u32 flags)
9886 return qla2xxx_reset_stats(host, flags);
9889 int qla2xxx_get_ini_stats(struct Scsi_Host *host, u32 flags,
9890 void *data, u64 size)
9892 scsi_qla_host_t *vha = shost_priv(host);
9893 struct ql_vnd_host_stats_resp *resp = (struct ql_vnd_host_stats_resp *)data;
9894 struct ql_vnd_stats *rsp_data = &resp->stats;
9895 u64 ini_entry_count = 0;
9897 u64 entry_count = 0;
9899 u32 tmp_stat_type = 0;
9900 fc_port_t *fcport = NULL;
9901 unsigned long int_flags;
9903 /* Copy stat type to work on it */
9904 tmp_stat_type = flags;
9906 if (tmp_stat_type & BIT_17) {
9907 num_tgt = qla2x00_get_num_tgts(vha);
9909 tmp_stat_type &= ~(1 << 17);
9911 ini_entry_count = qla2x00_count_set_bits(tmp_stat_type);
9913 entry_count = ini_entry_count + num_tgt;
9915 rsp_data->entry_count = entry_count;
9918 if (flags & QLA2XX_HW_ERROR) {
9919 rsp_data->entry[i].stat_type = QLA2XX_HW_ERROR;
9920 rsp_data->entry[i].tgt_num = 0x0;
9921 rsp_data->entry[i].cnt = vha->hw_err_cnt;
9925 if (flags & QLA2XX_SHT_LNK_DWN) {
9926 rsp_data->entry[i].stat_type = QLA2XX_SHT_LNK_DWN;
9927 rsp_data->entry[i].tgt_num = 0x0;
9928 rsp_data->entry[i].cnt = vha->short_link_down_cnt;
9932 if (flags & QLA2XX_INT_ERR) {
9933 rsp_data->entry[i].stat_type = QLA2XX_INT_ERR;
9934 rsp_data->entry[i].tgt_num = 0x0;
9935 rsp_data->entry[i].cnt = vha->interface_err_cnt;
9939 if (flags & QLA2XX_CMD_TIMEOUT) {
9940 rsp_data->entry[i].stat_type = QLA2XX_CMD_TIMEOUT;
9941 rsp_data->entry[i].tgt_num = 0x0;
9942 rsp_data->entry[i].cnt = vha->cmd_timeout_cnt;
9946 if (flags & QLA2XX_RESET_CMD_ERR) {
9947 rsp_data->entry[i].stat_type = QLA2XX_RESET_CMD_ERR;
9948 rsp_data->entry[i].tgt_num = 0x0;
9949 rsp_data->entry[i].cnt = vha->reset_cmd_err_cnt;
9953 /* i will continue from previous loop, as target
9954 * entries are after initiator
9956 if (flags & QLA2XX_TGT_SHT_LNK_DOWN) {
9957 spin_lock_irqsave(&vha->hw->tgt.sess_lock, int_flags);
9958 list_for_each_entry(fcport, &vha->vp_fcports, list) {
9959 if (fcport->port_type != FCT_TARGET)
9963 rsp_data->entry[i].stat_type = QLA2XX_TGT_SHT_LNK_DOWN;
9964 rsp_data->entry[i].tgt_num = fcport->rport->number;
9965 rsp_data->entry[i].cnt = fcport->tgt_short_link_down_cnt;
9968 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, int_flags);
9970 resp->status = EXT_STATUS_OK;
9975 int qla2xxx_get_tgt_stats(struct Scsi_Host *host, u32 flags,
9976 struct fc_rport *rport, void *data, u64 size)
9978 struct ql_vnd_tgt_stats_resp *tgt_data = data;
9979 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
9981 tgt_data->status = 0;
9982 tgt_data->stats.entry_count = 1;
9983 tgt_data->stats.entry[0].stat_type = flags;
9984 tgt_data->stats.entry[0].tgt_num = rport->number;
9985 tgt_data->stats.entry[0].cnt = fcport->tgt_short_link_down_cnt;
9990 int qla2xxx_disable_port(struct Scsi_Host *host)
9992 scsi_qla_host_t *vha = shost_priv(host);
9994 vha->hw->flags.port_isolated = 1;
9996 if (qla2x00_isp_reg_stat(vha->hw)) {
9997 ql_log(ql_log_info, vha, 0x9006,
9998 "PCI/Register disconnect, exiting.\n");
9999 qla_pci_set_eeh_busy(vha);
10002 if (qla2x00_chip_is_down(vha))
10005 if (vha->flags.online) {
10006 qla2x00_abort_isp_cleanup(vha);
10007 qla2x00_wait_for_sess_deletion(vha);
10013 int qla2xxx_enable_port(struct Scsi_Host *host)
10015 scsi_qla_host_t *vha = shost_priv(host);
10017 if (qla2x00_isp_reg_stat(vha->hw)) {
10018 ql_log(ql_log_info, vha, 0x9001,
10019 "PCI/Register disconnect, exiting.\n");
10020 qla_pci_set_eeh_busy(vha);
10024 vha->hw->flags.port_isolated = 0;
10025 /* Set the flag to 1, so that isp_abort can proceed */
10026 vha->flags.online = 1;
10027 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
10028 qla2xxx_wake_dpc(vha);