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 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1198 fcport->flags &= ~(FCF_ASYNC_SENT);
1200 fcport->flags &= ~(FCF_ASYNC_ACTIVE);
1204 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1206 struct qla_work_evt *e;
1208 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
1210 return QLA_FUNCTION_FAILED;
1212 e->u.fcport.fcport = fcport;
1213 fcport->flags |= FCF_ASYNC_ACTIVE;
1214 return qla2x00_post_work(vha, e);
1217 static void qla24xx_async_gpdb_sp_done(srb_t *sp, int res)
1219 struct scsi_qla_host *vha = sp->vha;
1220 struct qla_hw_data *ha = vha->hw;
1221 fc_port_t *fcport = sp->fcport;
1222 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
1223 struct event_arg ea;
1225 ql_dbg(ql_dbg_disc, vha, 0x20db,
1226 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
1227 sp->name, res, fcport->port_name, mb[1], mb[2]);
1229 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1231 if (res == QLA_FUNCTION_TIMEOUT)
1234 memset(&ea, 0, sizeof(ea));
1238 qla24xx_handle_gpdb_event(vha, &ea);
1241 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
1242 sp->u.iocb_cmd.u.mbx.in_dma);
1244 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1247 int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1249 struct qla_work_evt *e;
1251 if (vha->host->active_mode == MODE_TARGET)
1252 return QLA_FUNCTION_FAILED;
1254 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
1256 return QLA_FUNCTION_FAILED;
1258 e->u.fcport.fcport = fcport;
1260 return qla2x00_post_work(vha, e);
1263 static void qla2x00_async_prli_sp_done(srb_t *sp, int res)
1265 struct scsi_qla_host *vha = sp->vha;
1266 struct srb_iocb *lio = &sp->u.iocb_cmd;
1267 struct event_arg ea;
1269 ql_dbg(ql_dbg_disc, vha, 0x2129,
1270 "%s %8phC res %x\n", __func__,
1271 sp->fcport->port_name, res);
1273 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1275 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
1276 memset(&ea, 0, sizeof(ea));
1277 ea.fcport = sp->fcport;
1278 ea.data[0] = lio->u.logio.data[0];
1279 ea.data[1] = lio->u.logio.data[1];
1280 ea.iop[0] = lio->u.logio.iop[0];
1281 ea.iop[1] = lio->u.logio.iop[1];
1283 if (res == QLA_OS_TIMER_EXPIRED)
1284 ea.data[0] = QLA_OS_TIMER_EXPIRED;
1286 ea.data[0] = MBS_COMMAND_ERROR;
1288 qla24xx_handle_prli_done_event(vha, &ea);
1291 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1295 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
1298 struct srb_iocb *lio;
1299 int rval = QLA_FUNCTION_FAILED;
1301 if (!vha->flags.online) {
1302 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1303 __func__, __LINE__, fcport->port_name);
1307 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
1308 fcport->fw_login_state == DSC_LS_PRLI_PEND) &&
1309 qla_dual_mode_enabled(vha)) {
1310 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1311 __func__, __LINE__, fcport->port_name);
1315 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1319 fcport->flags |= FCF_ASYNC_SENT;
1320 fcport->logout_completed = 0;
1322 sp->type = SRB_PRLI_CMD;
1324 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
1325 qla2x00_async_prli_sp_done);
1327 lio = &sp->u.iocb_cmd;
1328 lio->u.logio.flags = 0;
1330 if (NVME_TARGET(vha->hw, fcport))
1331 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
1333 ql_dbg(ql_dbg_disc, vha, 0x211b,
1334 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d fc4type %x priority %x %s.\n",
1335 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24,
1336 fcport->login_retry, fcport->fc4_type, vha->hw->fc4_type_priority,
1337 NVME_TARGET(vha->hw, fcport) ? "nvme" : "fcp");
1339 rval = qla2x00_start_sp(sp);
1340 if (rval != QLA_SUCCESS) {
1341 fcport->flags |= FCF_LOGIN_NEEDED;
1342 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1350 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1351 fcport->flags &= ~FCF_ASYNC_SENT;
1355 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1357 struct qla_work_evt *e;
1359 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
1361 return QLA_FUNCTION_FAILED;
1363 e->u.fcport.fcport = fcport;
1364 e->u.fcport.opt = opt;
1365 fcport->flags |= FCF_ASYNC_ACTIVE;
1366 return qla2x00_post_work(vha, e);
1369 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1372 struct srb_iocb *mbx;
1373 int rval = QLA_FUNCTION_FAILED;
1376 struct port_database_24xx *pd;
1377 struct qla_hw_data *ha = vha->hw;
1379 if (IS_SESSION_DELETED(fcport)) {
1380 ql_log(ql_log_warn, vha, 0xffff,
1381 "%s: %8phC is being delete - not sending command.\n",
1382 __func__, fcport->port_name);
1383 fcport->flags &= ~FCF_ASYNC_ACTIVE;
1387 if (!vha->flags.online || fcport->flags & FCF_ASYNC_SENT) {
1388 ql_log(ql_log_warn, vha, 0xffff,
1389 "%s: %8phC online %d flags %x - not sending command.\n",
1390 __func__, fcport->port_name, vha->flags.online, fcport->flags);
1394 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1398 qla2x00_set_fcport_disc_state(fcport, DSC_GPDB);
1400 fcport->flags |= FCF_ASYNC_SENT;
1401 sp->type = SRB_MB_IOCB;
1403 sp->gen1 = fcport->rscn_gen;
1404 sp->gen2 = fcport->login_gen;
1405 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
1406 qla24xx_async_gpdb_sp_done);
1408 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1410 ql_log(ql_log_warn, vha, 0xd043,
1411 "Failed to allocate port database structure.\n");
1415 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1416 mb[0] = MBC_GET_PORT_DATABASE;
1417 mb[1] = fcport->loop_id;
1418 mb[2] = MSW(pd_dma);
1419 mb[3] = LSW(pd_dma);
1420 mb[6] = MSW(MSD(pd_dma));
1421 mb[7] = LSW(MSD(pd_dma));
1422 mb[9] = vha->vp_idx;
1425 mbx = &sp->u.iocb_cmd;
1426 mbx->u.mbx.in = (void *)pd;
1427 mbx->u.mbx.in_dma = pd_dma;
1429 ql_dbg(ql_dbg_disc, vha, 0x20dc,
1430 "Async-%s %8phC hndl %x opt %x\n",
1431 sp->name, fcport->port_name, sp->handle, opt);
1433 rval = qla2x00_start_sp(sp);
1434 if (rval != QLA_SUCCESS)
1440 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1442 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1443 fcport->flags &= ~FCF_ASYNC_SENT;
1445 fcport->flags &= ~FCF_ASYNC_ACTIVE;
1446 qla24xx_post_gpdb_work(vha, fcport, opt);
1451 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1453 unsigned long flags;
1455 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1456 ea->fcport->login_gen++;
1457 ea->fcport->logout_on_delete = 1;
1459 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1460 vha->fcport_count++;
1461 ea->fcport->login_succ = 1;
1463 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1464 qla24xx_sched_upd_fcport(ea->fcport);
1465 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1466 } else if (ea->fcport->login_succ) {
1468 * We have an existing session. A late RSCN delivery
1469 * must have triggered the session to be re-validate.
1470 * Session is still valid.
1472 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1473 "%s %d %8phC session revalidate success\n",
1474 __func__, __LINE__, ea->fcport->port_name);
1475 qla2x00_set_fcport_disc_state(ea->fcport, DSC_LOGIN_COMPLETE);
1477 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1480 static int qla_chk_secure_login(scsi_qla_host_t *vha, fc_port_t *fcport,
1481 struct port_database_24xx *pd)
1485 if (pd->secure_login) {
1486 ql_dbg(ql_dbg_disc, vha, 0x104d,
1487 "Secure Login established on %8phC\n",
1489 fcport->flags |= FCF_FCSP_DEVICE;
1491 ql_dbg(ql_dbg_disc, vha, 0x104d,
1492 "non-Secure Login %8phC",
1494 fcport->flags &= ~FCF_FCSP_DEVICE;
1496 if (vha->hw->flags.edif_enabled) {
1497 if (fcport->flags & FCF_FCSP_DEVICE) {
1498 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_AUTH_PEND);
1499 /* Start edif prli timer & ring doorbell for app */
1500 fcport->edif.rx_sa_set = 0;
1501 fcport->edif.tx_sa_set = 0;
1502 fcport->edif.rx_sa_pending = 0;
1503 fcport->edif.tx_sa_pending = 0;
1505 qla2x00_post_aen_work(vha, FCH_EVT_PORT_ONLINE,
1508 if (DBELL_ACTIVE(vha)) {
1509 ql_dbg(ql_dbg_disc, vha, 0x20ef,
1510 "%s %d %8phC EDIF: post DB_AUTH: AUTH needed\n",
1511 __func__, __LINE__, fcport->port_name);
1512 fcport->edif.app_sess_online = 1;
1514 qla_edb_eventcreate(vha, VND_CMD_AUTH_STATE_NEEDED,
1515 fcport->d_id.b24, 0, fcport);
1519 } else if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
1520 ql_dbg(ql_dbg_disc, vha, 0x2117,
1521 "%s %d %8phC post prli\n",
1522 __func__, __LINE__, fcport->port_name);
1523 qla24xx_post_prli_work(vha, fcport);
1531 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1533 fc_port_t *fcport = ea->fcport;
1534 struct port_database_24xx *pd;
1535 struct srb *sp = ea->sp;
1538 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1540 fcport->flags &= ~FCF_ASYNC_SENT;
1542 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1543 "%s %8phC DS %d LS %x fc4_type %x rc %x\n", __func__,
1544 fcport->port_name, fcport->disc_state, pd->current_login_state,
1545 fcport->fc4_type, ea->rc);
1547 if (fcport->disc_state == DSC_DELETE_PEND) {
1548 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC\n",
1549 __func__, __LINE__, fcport->port_name);
1553 if (NVME_TARGET(vha->hw, fcport))
1554 ls = pd->current_login_state >> 4;
1556 ls = pd->current_login_state & 0xf;
1558 if (ea->sp->gen2 != fcport->login_gen) {
1559 /* target side must have changed it. */
1561 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1562 "%s %8phC generation changed\n",
1563 __func__, fcport->port_name);
1565 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1566 qla_rscn_replay(fcport);
1567 qlt_schedule_sess_for_deletion(fcport);
1568 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n",
1569 __func__, __LINE__, fcport->port_name, ls);
1574 case PDS_PRLI_COMPLETE:
1575 __qla24xx_parse_gpdb(vha, fcport, pd);
1577 case PDS_PLOGI_COMPLETE:
1578 if (qla_chk_secure_login(vha, fcport, pd)) {
1579 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n",
1580 __func__, __LINE__, fcport->port_name, ls);
1584 case PDS_PLOGI_PENDING:
1585 case PDS_PRLI_PENDING:
1586 case PDS_PRLI2_PENDING:
1587 /* Set discovery state back to GNL to Relogin attempt */
1588 if (qla_dual_mode_enabled(vha) ||
1589 qla_ini_mode_enabled(vha)) {
1590 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
1591 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1593 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n",
1594 __func__, __LINE__, fcport->port_name, ls);
1596 case PDS_LOGO_PENDING:
1597 case PDS_PORT_UNAVAILABLE:
1599 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1600 __func__, __LINE__, fcport->port_name);
1601 qlt_schedule_sess_for_deletion(fcport);
1604 __qla24xx_handle_gpdb_event(vha, ea);
1607 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1612 ql_dbg(ql_dbg_disc, vha, 0x307b,
1613 "%s %8phC DS %d LS %d lid %d retries=%d\n",
1614 __func__, fcport->port_name, fcport->disc_state,
1615 fcport->fw_login_state, fcport->loop_id, fcport->login_retry);
1617 if (qla_tgt_mode_enabled(vha))
1620 if (qla_dual_mode_enabled(vha)) {
1621 if (N2N_TOPO(vha->hw)) {
1624 mywwn = wwn_to_u64(vha->port_name);
1625 wwn = wwn_to_u64(fcport->port_name);
1628 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1629 && time_after_eq(jiffies,
1630 fcport->plogi_nack_done_deadline))
1636 /* initiator mode */
1640 if (login && fcport->login_retry) {
1641 fcport->login_retry--;
1642 if (fcport->loop_id == FC_NO_LOOP_ID) {
1643 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1644 rc = qla2x00_find_new_loop_id(vha, fcport);
1646 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1647 "%s %d %8phC post del sess - out of loopid\n",
1648 __func__, __LINE__, fcport->port_name);
1649 fcport->scan_state = 0;
1650 qlt_schedule_sess_for_deletion(fcport);
1654 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1655 "%s %d %8phC post login\n",
1656 __func__, __LINE__, fcport->port_name);
1657 qla2x00_post_async_login_work(vha, fcport, NULL);
1661 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1666 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1667 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d fc4type %x\n",
1668 __func__, fcport->port_name, fcport->disc_state,
1669 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1670 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1671 fcport->login_gen, fcport->loop_id, fcport->scan_state,
1674 if (fcport->scan_state != QLA_FCPORT_FOUND ||
1675 fcport->disc_state == DSC_DELETE_PEND)
1678 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1679 qla_dual_mode_enabled(vha) &&
1680 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1681 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1684 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP &&
1685 !N2N_TOPO(vha->hw)) {
1686 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1687 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1692 /* Target won't initiate port login if fabric is present */
1693 if (vha->host->active_mode == MODE_TARGET && !N2N_TOPO(vha->hw))
1696 if (fcport->flags & (FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE)) {
1697 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1701 switch (fcport->disc_state) {
1703 switch (vha->hw->current_topology) {
1705 if (fcport_is_smaller(fcport)) {
1706 /* this adapter is bigger */
1707 if (fcport->login_retry) {
1708 if (fcport->loop_id == FC_NO_LOOP_ID) {
1709 qla2x00_find_new_loop_id(vha,
1711 fcport->fw_login_state =
1712 DSC_LS_PORT_UNAVAIL;
1714 fcport->login_retry--;
1715 qla_post_els_plogi_work(vha, fcport);
1717 ql_log(ql_log_info, vha, 0x705d,
1718 "Unable to reach remote port %8phC",
1722 qla24xx_post_gnl_work(vha, fcport);
1726 if (fcport->loop_id == FC_NO_LOOP_ID) {
1727 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1728 "%s %d %8phC post gnl\n",
1729 __func__, __LINE__, fcport->port_name);
1730 qla24xx_post_gnl_work(vha, fcport);
1732 qla_chk_n2n_b4_login(vha, fcport);
1739 switch (vha->hw->current_topology) {
1741 if ((fcport->current_login_state & 0xf) == 0x6) {
1742 ql_dbg(ql_dbg_disc, vha, 0x2118,
1743 "%s %d %8phC post GPDB work\n",
1744 __func__, __LINE__, fcport->port_name);
1745 fcport->chip_reset =
1746 vha->hw->base_qpair->chip_reset;
1747 qla24xx_post_gpdb_work(vha, fcport, 0);
1749 ql_dbg(ql_dbg_disc, vha, 0x2118,
1750 "%s %d %8phC post %s PRLI\n",
1751 __func__, __LINE__, fcport->port_name,
1752 NVME_TARGET(vha->hw, fcport) ? "NVME" :
1754 qla24xx_post_prli_work(vha, fcport);
1758 if (fcport->login_pause) {
1759 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1760 "%s %d %8phC exit\n",
1763 fcport->last_rscn_gen = fcport->rscn_gen;
1764 fcport->last_login_gen = fcport->login_gen;
1765 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1768 qla_chk_n2n_b4_login(vha, fcport);
1773 case DSC_LOGIN_FAILED:
1774 if (N2N_TOPO(vha->hw))
1775 qla_chk_n2n_b4_login(vha, fcport);
1777 qlt_schedule_sess_for_deletion(fcport);
1780 case DSC_LOGIN_COMPLETE:
1781 /* recheck login state */
1782 data[0] = data[1] = 0;
1783 qla2x00_post_async_adisc_work(vha, fcport, data);
1786 case DSC_LOGIN_PEND:
1787 if (vha->hw->flags.edif_enabled)
1790 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1791 ql_dbg(ql_dbg_disc, vha, 0x2118,
1792 "%s %d %8phC post %s PRLI\n",
1793 __func__, __LINE__, fcport->port_name,
1794 NVME_TARGET(vha->hw, fcport) ? "NVME" : "FC");
1795 qla24xx_post_prli_work(vha, fcport);
1799 case DSC_UPD_FCPORT:
1800 sec = jiffies_to_msecs(jiffies -
1801 fcport->jiffies_at_registration)/1000;
1802 if (fcport->sec_since_registration < sec && sec &&
1804 fcport->sec_since_registration = sec;
1805 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
1806 "%s %8phC - Slow Rport registration(%d Sec)\n",
1807 __func__, fcport->port_name, sec);
1810 if (fcport->next_disc_state != DSC_DELETE_PEND)
1811 fcport->next_disc_state = DSC_ADISC;
1812 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1822 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1823 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1825 struct qla_work_evt *e;
1827 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1829 return QLA_FUNCTION_FAILED;
1831 e->u.new_sess.id = *id;
1832 e->u.new_sess.pla = pla;
1833 e->u.new_sess.fc4_type = fc4_type;
1834 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1836 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1838 return qla2x00_post_work(vha, e);
1841 void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
1844 unsigned long flags;
1846 switch (ea->id.b.rsvd_1) {
1847 case RSCN_PORT_ADDR:
1848 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1850 if (ql2xfc2target &&
1851 fcport->flags & FCF_FCP2_DEVICE &&
1852 atomic_read(&fcport->state) == FCS_ONLINE) {
1853 ql_dbg(ql_dbg_disc, vha, 0x2115,
1854 "Delaying session delete for FCP2 portid=%06x %8phC ",
1855 fcport->d_id.b24, fcport->port_name);
1859 if (vha->hw->flags.edif_enabled && DBELL_ACTIVE(vha)) {
1861 * On ipsec start by remote port, Target port
1862 * may use RSCN to trigger initiator to
1863 * relogin. If driver is already in the
1864 * process of a relogin, then ignore the RSCN
1865 * and allow the current relogin to continue.
1866 * This reduces thrashing of the connection.
1868 if (atomic_read(&fcport->state) == FCS_ONLINE) {
1870 * If state = online, then set scan_needed=1 to do relogin.
1871 * Otherwise we're already in the middle of a relogin
1873 fcport->scan_needed = 1;
1877 fcport->scan_needed = 1;
1882 case RSCN_AREA_ADDR:
1883 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1884 if (fcport->flags & FCF_FCP2_DEVICE &&
1885 atomic_read(&fcport->state) == FCS_ONLINE)
1888 if ((ea->id.b24 & 0xffff00) == (fcport->d_id.b24 & 0xffff00)) {
1889 fcport->scan_needed = 1;
1895 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1896 if (fcport->flags & FCF_FCP2_DEVICE &&
1897 atomic_read(&fcport->state) == FCS_ONLINE)
1900 if ((ea->id.b24 & 0xff0000) == (fcport->d_id.b24 & 0xff0000)) {
1901 fcport->scan_needed = 1;
1908 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1909 if (fcport->flags & FCF_FCP2_DEVICE &&
1910 atomic_read(&fcport->state) == FCS_ONLINE)
1913 fcport->scan_needed = 1;
1919 spin_lock_irqsave(&vha->work_lock, flags);
1920 if (vha->scan.scan_flags == 0) {
1921 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s: schedule\n", __func__);
1922 vha->scan.scan_flags |= SF_QUEUED;
1923 schedule_delayed_work(&vha->scan.scan_work, 5);
1925 spin_unlock_irqrestore(&vha->work_lock, flags);
1928 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1929 struct event_arg *ea)
1931 fc_port_t *fcport = ea->fcport;
1933 if (test_bit(UNLOADING, &vha->dpc_flags))
1936 ql_dbg(ql_dbg_disc, vha, 0x2102,
1937 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1938 __func__, fcport->port_name, fcport->disc_state,
1939 fcport->fw_login_state, fcport->login_pause,
1940 fcport->deleted, fcport->conflict,
1941 fcport->last_rscn_gen, fcport->rscn_gen,
1942 fcport->last_login_gen, fcport->login_gen,
1945 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1946 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gnl\n",
1947 __func__, __LINE__, fcport->port_name);
1948 qla24xx_post_gnl_work(vha, fcport);
1952 qla24xx_fcport_handle_login(vha, fcport);
1955 void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
1956 struct event_arg *ea)
1958 if (N2N_TOPO(vha->hw) && fcport_is_smaller(ea->fcport) &&
1959 vha->hw->flags.edif_enabled) {
1960 /* check to see if App support Secure */
1961 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1965 /* for pure Target Mode, PRLI will not be initiated */
1966 if (vha->host->active_mode == MODE_TARGET)
1969 ql_dbg(ql_dbg_disc, vha, 0x2118,
1970 "%s %d %8phC post PRLI\n",
1971 __func__, __LINE__, ea->fcport->port_name);
1972 qla24xx_post_prli_work(vha, ea->fcport);
1976 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1977 * to be consumed by the fcport
1979 void qla_rscn_replay(fc_port_t *fcport)
1981 struct event_arg ea;
1983 switch (fcport->disc_state) {
1984 case DSC_DELETE_PEND:
1990 if (fcport->scan_needed) {
1991 memset(&ea, 0, sizeof(ea));
1992 ea.id = fcport->d_id;
1993 ea.id.b.rsvd_1 = RSCN_PORT_ADDR;
1994 qla2x00_handle_rscn(fcport->vha, &ea);
1999 qla2x00_tmf_iocb_timeout(void *data)
2002 struct srb_iocb *tmf = &sp->u.iocb_cmd;
2004 unsigned long flags;
2006 if (sp->type == SRB_MARKER)
2007 rc = QLA_FUNCTION_FAILED;
2009 rc = qla24xx_async_abort_cmd(sp, false);
2012 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
2013 for (h = 1; h < sp->qpair->req->num_outstanding_cmds; h++) {
2014 if (sp->qpair->req->outstanding_cmds[h] == sp) {
2015 sp->qpair->req->outstanding_cmds[h] = NULL;
2016 qla_put_fw_resources(sp->qpair, &sp->iores);
2020 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
2021 tmf->u.tmf.comp_status = cpu_to_le16(CS_TIMEOUT);
2022 tmf->u.tmf.data = QLA_FUNCTION_FAILED;
2023 complete(&tmf->u.tmf.comp);
2027 static void qla_marker_sp_done(srb_t *sp, int res)
2029 struct srb_iocb *tmf = &sp->u.iocb_cmd;
2031 if (res != QLA_SUCCESS)
2032 ql_dbg(ql_dbg_taskm, sp->vha, 0x8004,
2033 "Async-marker fail hdl=%x portid=%06x ctrl=%x lun=%lld qp=%d.\n",
2034 sp->handle, sp->fcport->d_id.b24, sp->u.iocb_cmd.u.tmf.flags,
2035 sp->u.iocb_cmd.u.tmf.lun, sp->qpair->id);
2037 sp->u.iocb_cmd.u.tmf.data = res;
2038 complete(&tmf->u.tmf.comp);
2041 #define START_SP_W_RETRIES(_sp, _rval, _chip_gen, _login_gen) \
2045 if (_chip_gen != sp->vha->hw->chip_reset || _login_gen != sp->fcport->login_gen) {\
2049 _rval = qla2x00_start_sp(_sp); \
2050 if (_rval == EAGAIN) \
2059 * qla26xx_marker: send marker IOCB and wait for the completion of it.
2060 * @arg: pointer to argument list.
2061 * It is assume caller will provide an fcport pointer and modifier
2064 qla26xx_marker(struct tmf_arg *arg)
2066 struct scsi_qla_host *vha = arg->vha;
2067 struct srb_iocb *tm_iocb;
2069 int rval = QLA_FUNCTION_FAILED;
2070 fc_port_t *fcport = arg->fcport;
2071 u32 chip_gen, login_gen;
2073 if (TMF_NOT_READY(arg->fcport)) {
2074 ql_dbg(ql_dbg_taskm, vha, 0x8039,
2075 "FC port not ready for marker loop-id=%x portid=%06x modifier=%x lun=%lld qp=%d.\n",
2076 fcport->loop_id, fcport->d_id.b24,
2077 arg->modifier, arg->lun, arg->qpair->id);
2078 return QLA_SUSPENDED;
2081 chip_gen = vha->hw->chip_reset;
2082 login_gen = fcport->login_gen;
2085 sp = qla2xxx_get_qpair_sp(vha, arg->qpair, fcport, GFP_KERNEL);
2089 sp->type = SRB_MARKER;
2090 sp->name = "marker";
2091 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha), qla_marker_sp_done);
2092 sp->u.iocb_cmd.timeout = qla2x00_tmf_iocb_timeout;
2094 tm_iocb = &sp->u.iocb_cmd;
2095 init_completion(&tm_iocb->u.tmf.comp);
2096 tm_iocb->u.tmf.modifier = arg->modifier;
2097 tm_iocb->u.tmf.lun = arg->lun;
2098 tm_iocb->u.tmf.loop_id = fcport->loop_id;
2099 tm_iocb->u.tmf.vp_index = vha->vp_idx;
2101 START_SP_W_RETRIES(sp, rval, chip_gen, login_gen);
2103 ql_dbg(ql_dbg_taskm, vha, 0x8006,
2104 "Async-marker hdl=%x loop-id=%x portid=%06x modifier=%x lun=%lld qp=%d rval %d.\n",
2105 sp->handle, fcport->loop_id, fcport->d_id.b24,
2106 arg->modifier, arg->lun, sp->qpair->id, rval);
2108 if (rval != QLA_SUCCESS) {
2109 ql_log(ql_log_warn, vha, 0x8031,
2110 "Marker IOCB send failure (%x).\n", rval);
2114 wait_for_completion(&tm_iocb->u.tmf.comp);
2115 rval = tm_iocb->u.tmf.data;
2117 if (rval != QLA_SUCCESS) {
2118 ql_log(ql_log_warn, vha, 0x8019,
2119 "Marker failed hdl=%x loop-id=%x portid=%06x modifier=%x lun=%lld qp=%d rval %d.\n",
2120 sp->handle, fcport->loop_id, fcport->d_id.b24,
2121 arg->modifier, arg->lun, sp->qpair->id, rval);
2126 kref_put(&sp->cmd_kref, qla2x00_sp_release);
2131 static void qla2x00_tmf_sp_done(srb_t *sp, int res)
2133 struct srb_iocb *tmf = &sp->u.iocb_cmd;
2136 tmf->u.tmf.data = res;
2137 complete(&tmf->u.tmf.comp);
2140 static int qla_tmf_wait(struct tmf_arg *arg)
2142 /* there are only 2 types of error handling that reaches here, lun or target reset */
2143 if (arg->flags & (TCF_LUN_RESET | TCF_ABORT_TASK_SET | TCF_CLEAR_TASK_SET))
2144 return qla2x00_eh_wait_for_pending_commands(arg->vha,
2145 arg->fcport->d_id.b24, arg->lun, WAIT_LUN);
2147 return qla2x00_eh_wait_for_pending_commands(arg->vha,
2148 arg->fcport->d_id.b24, arg->lun, WAIT_TARGET);
2152 __qla2x00_async_tm_cmd(struct tmf_arg *arg)
2154 struct scsi_qla_host *vha = arg->vha;
2155 struct srb_iocb *tm_iocb;
2157 int rval = QLA_FUNCTION_FAILED;
2158 fc_port_t *fcport = arg->fcport;
2159 u32 chip_gen, login_gen;
2162 if (TMF_NOT_READY(arg->fcport)) {
2163 ql_dbg(ql_dbg_taskm, vha, 0x8032,
2164 "FC port not ready for TM command loop-id=%x portid=%06x modifier=%x lun=%lld qp=%d.\n",
2165 fcport->loop_id, fcport->d_id.b24,
2166 arg->modifier, arg->lun, arg->qpair->id);
2167 return QLA_SUSPENDED;
2170 chip_gen = vha->hw->chip_reset;
2171 login_gen = fcport->login_gen;
2174 sp = qla2xxx_get_qpair_sp(vha, arg->qpair, fcport, GFP_KERNEL);
2178 qla_vha_mark_busy(vha);
2179 sp->type = SRB_TM_CMD;
2181 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha),
2182 qla2x00_tmf_sp_done);
2183 sp->u.iocb_cmd.timeout = qla2x00_tmf_iocb_timeout;
2185 tm_iocb = &sp->u.iocb_cmd;
2186 init_completion(&tm_iocb->u.tmf.comp);
2187 tm_iocb->u.tmf.flags = arg->flags;
2188 tm_iocb->u.tmf.lun = arg->lun;
2190 START_SP_W_RETRIES(sp, rval, chip_gen, login_gen);
2192 ql_dbg(ql_dbg_taskm, vha, 0x802f,
2193 "Async-tmf hdl=%x loop-id=%x portid=%06x ctrl=%x lun=%lld qp=%d rval=%x.\n",
2194 sp->handle, fcport->loop_id, fcport->d_id.b24,
2195 arg->flags, arg->lun, sp->qpair->id, rval);
2197 if (rval != QLA_SUCCESS)
2199 wait_for_completion(&tm_iocb->u.tmf.comp);
2201 rval = tm_iocb->u.tmf.data;
2203 if (rval != QLA_SUCCESS) {
2204 ql_log(ql_log_warn, vha, 0x8030,
2205 "TM IOCB failed (%x).\n", rval);
2208 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
2210 if (qla_tmf_wait(arg)) {
2211 ql_log(ql_log_info, vha, 0x803e,
2212 "Waited %u ms Nexus=%ld:%06x:%llu.\n",
2213 jiffies_to_msecs(jiffies - jif), vha->host_no,
2214 fcport->d_id.b24, arg->lun);
2217 if (chip_gen == vha->hw->chip_reset && login_gen == fcport->login_gen) {
2218 rval = qla26xx_marker(arg);
2220 ql_log(ql_log_info, vha, 0x803e,
2221 "Skip Marker due to disruption. Nexus=%ld:%06x:%llu.\n",
2222 vha->host_no, fcport->d_id.b24, arg->lun);
2223 rval = QLA_FUNCTION_FAILED;
2229 kref_put(&sp->cmd_kref, qla2x00_sp_release);
2234 static void qla_put_tmf(struct tmf_arg *arg)
2236 struct scsi_qla_host *vha = arg->vha;
2237 struct qla_hw_data *ha = vha->hw;
2238 unsigned long flags;
2240 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
2242 list_del(&arg->tmf_elem);
2243 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
2247 int qla_get_tmf(struct tmf_arg *arg)
2249 struct scsi_qla_host *vha = arg->vha;
2250 struct qla_hw_data *ha = vha->hw;
2251 unsigned long flags;
2252 fc_port_t *fcport = arg->fcport;
2256 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
2257 list_for_each_entry(t, &ha->tmf_active, tmf_elem) {
2258 if (t->fcport == arg->fcport && t->lun == arg->lun) {
2259 /* reject duplicate TMF */
2260 ql_log(ql_log_warn, vha, 0x802c,
2261 "found duplicate TMF. Nexus=%ld:%06x:%llu.\n",
2262 vha->host_no, fcport->d_id.b24, arg->lun);
2263 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
2268 list_add_tail(&arg->tmf_elem, &ha->tmf_pending);
2269 while (ha->active_tmf >= MAX_ACTIVE_TMF) {
2270 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
2274 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
2275 if (TMF_NOT_READY(fcport)) {
2276 ql_log(ql_log_warn, vha, 0x802c,
2277 "Unable to acquire TM resource due to disruption.\n");
2281 if (ha->active_tmf < MAX_ACTIVE_TMF &&
2282 list_is_first(&arg->tmf_elem, &ha->tmf_pending))
2286 list_del(&arg->tmf_elem);
2290 list_add_tail(&arg->tmf_elem, &ha->tmf_active);
2293 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
2299 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint64_t lun,
2302 struct scsi_qla_host *vha = fcport->vha;
2304 int rval = QLA_SUCCESS;
2306 if (TMF_NOT_READY(fcport))
2307 return QLA_SUSPENDED;
2309 a.vha = fcport->vha;
2313 INIT_LIST_HEAD(&a.tmf_elem);
2315 if (flags & (TCF_LUN_RESET|TCF_ABORT_TASK_SET|TCF_CLEAR_TASK_SET|TCF_CLEAR_ACA)) {
2316 a.modifier = MK_SYNC_ID_LUN;
2318 a.modifier = MK_SYNC_ID;
2321 if (qla_get_tmf(&a))
2322 return QLA_FUNCTION_FAILED;
2324 a.qpair = vha->hw->base_qpair;
2325 rval = __qla2x00_async_tm_cmd(&a);
2332 qla24xx_async_abort_command(srb_t *sp)
2334 unsigned long flags = 0;
2337 fc_port_t *fcport = sp->fcport;
2338 struct qla_qpair *qpair = sp->qpair;
2339 struct scsi_qla_host *vha = fcport->vha;
2340 struct req_que *req = qpair->req;
2342 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
2343 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
2344 if (req->outstanding_cmds[handle] == sp)
2347 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
2349 if (handle == req->num_outstanding_cmds) {
2350 /* Command not found. */
2351 return QLA_ERR_NOT_FOUND;
2353 if (sp->type == SRB_FXIOCB_DCMD)
2354 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
2355 FXDISC_ABORT_IOCTL);
2357 return qla24xx_async_abort_cmd(sp, true);
2361 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
2364 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
2367 switch (ea->data[0]) {
2368 case MBS_COMMAND_COMPLETE:
2369 ql_dbg(ql_dbg_disc, vha, 0x2118,
2370 "%s %d %8phC post gpdb\n",
2371 __func__, __LINE__, ea->fcport->port_name);
2373 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2374 ea->fcport->logout_on_delete = 1;
2375 ea->fcport->nvme_prli_service_param = ea->iop[0];
2376 if (ea->iop[0] & NVME_PRLI_SP_FIRST_BURST)
2377 ea->fcport->nvme_first_burst_size =
2378 (ea->iop[1] & 0xffff) * 512;
2380 ea->fcport->nvme_first_burst_size = 0;
2381 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2385 ql_dbg(ql_dbg_disc, vha, 0x2118,
2386 "%s %d %8phC priority %s, fc4type %x prev try %s\n",
2387 __func__, __LINE__, ea->fcport->port_name,
2388 vha->hw->fc4_type_priority == FC4_PRIORITY_FCP ?
2389 "FCP" : "NVMe", ea->fcport->fc4_type,
2390 (sp->u.iocb_cmd.u.logio.flags & SRB_LOGIN_NVME_PRLI) ?
2393 if (NVME_FCP_TARGET(ea->fcport)) {
2394 if (sp->u.iocb_cmd.u.logio.flags & SRB_LOGIN_NVME_PRLI)
2395 ea->fcport->do_prli_nvme = 0;
2397 ea->fcport->do_prli_nvme = 1;
2399 ea->fcport->do_prli_nvme = 0;
2402 if (N2N_TOPO(vha->hw)) {
2403 if (ea->fcport->n2n_link_reset_cnt ==
2404 vha->hw->login_retry_count &&
2405 ea->fcport->flags & FCF_FCSP_DEVICE) {
2406 /* remote authentication app just started */
2407 ea->fcport->n2n_link_reset_cnt = 0;
2410 if (ea->fcport->n2n_link_reset_cnt <
2411 vha->hw->login_retry_count) {
2412 ea->fcport->n2n_link_reset_cnt++;
2413 vha->relogin_jif = jiffies + 2 * HZ;
2415 * PRLI failed. Reset link to kick start
2418 set_bit(N2N_LINK_RESET, &vha->dpc_flags);
2419 qla2xxx_wake_dpc(vha);
2421 ql_log(ql_log_warn, vha, 0x2119,
2422 "%s %d %8phC Unable to reconnect\n",
2424 ea->fcport->port_name);
2428 * switch connect. login failed. Take connection down
2429 * and allow relogin to retrigger
2431 ea->fcport->flags &= ~FCF_ASYNC_SENT;
2432 ea->fcport->keep_nport_handle = 0;
2433 ea->fcport->logout_on_delete = 1;
2434 qlt_schedule_sess_for_deletion(ea->fcport);
2441 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
2443 port_id_t cid; /* conflict Nport id */
2445 struct fc_port *conflict_fcport;
2446 unsigned long flags;
2447 struct fc_port *fcport = ea->fcport;
2449 ql_dbg(ql_dbg_disc, vha, 0xffff,
2450 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
2451 __func__, fcport->port_name, fcport->disc_state,
2452 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
2453 ea->sp->gen1, fcport->rscn_gen,
2454 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
2456 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
2457 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
2458 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2459 "%s %d %8phC Remote is trying to login\n",
2460 __func__, __LINE__, fcport->port_name);
2464 if ((fcport->disc_state == DSC_DELETE_PEND) ||
2465 (fcport->disc_state == DSC_DELETED)) {
2466 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2470 if (ea->sp->gen2 != fcport->login_gen) {
2471 /* target side must have changed it. */
2472 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2473 "%s %8phC generation changed\n",
2474 __func__, fcport->port_name);
2475 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2477 } else if (ea->sp->gen1 != fcport->rscn_gen) {
2478 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2479 "%s %8phC RSCN generation changed\n",
2480 __func__, fcport->port_name);
2481 qla_rscn_replay(fcport);
2482 qlt_schedule_sess_for_deletion(fcport);
2486 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
2489 switch (ea->data[0]) {
2490 case MBS_COMMAND_COMPLETE:
2492 * Driver must validate login state - If PRLI not complete,
2493 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
2496 if (vha->hw->flags.edif_enabled) {
2497 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2498 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2499 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2500 ea->fcport->logout_on_delete = 1;
2501 ea->fcport->send_els_logo = 0;
2502 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
2503 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2505 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2507 if (NVME_TARGET(vha->hw, fcport)) {
2508 ql_dbg(ql_dbg_disc, vha, 0x2117,
2509 "%s %d %8phC post prli\n",
2510 __func__, __LINE__, fcport->port_name);
2511 qla24xx_post_prli_work(vha, fcport);
2513 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2514 "%s %d %8phC LoopID 0x%x in use with %06x. post gpdb\n",
2515 __func__, __LINE__, fcport->port_name,
2516 fcport->loop_id, fcport->d_id.b24);
2518 set_bit(fcport->loop_id, vha->hw->loop_id_map);
2519 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2520 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2521 fcport->logout_on_delete = 1;
2522 fcport->send_els_logo = 0;
2523 fcport->fw_login_state = DSC_LS_PRLI_COMP;
2524 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2526 qla24xx_post_gpdb_work(vha, fcport, 0);
2530 case MBS_COMMAND_ERROR:
2531 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
2532 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
2534 qlt_schedule_sess_for_deletion(ea->fcport);
2536 case MBS_LOOP_ID_USED:
2537 /* data[1] = IO PARAM 1 = nport ID */
2538 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
2539 cid.b.area = (ea->iop[1] >> 8) & 0xff;
2540 cid.b.al_pa = ea->iop[1] & 0xff;
2543 ql_dbg(ql_dbg_disc, vha, 0x20ec,
2544 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2545 __func__, __LINE__, ea->fcport->port_name,
2546 ea->fcport->loop_id, cid.b24);
2548 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2549 ea->fcport->loop_id = FC_NO_LOOP_ID;
2550 qla24xx_post_gnl_work(vha, ea->fcport);
2552 case MBS_PORT_ID_USED:
2553 lid = ea->iop[1] & 0xffff;
2554 qlt_find_sess_invalidate_other(vha,
2555 wwn_to_u64(ea->fcport->port_name),
2556 ea->fcport->d_id, lid, &conflict_fcport);
2558 if (conflict_fcport) {
2560 * Another fcport share the same loop_id/nport id.
2561 * Conflict fcport needs to finish cleanup before this
2562 * fcport can proceed to login.
2564 conflict_fcport->conflict = ea->fcport;
2565 ea->fcport->login_pause = 1;
2567 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2568 "%s %d %8phC NPortId %06x inuse with loopid 0x%x.\n",
2569 __func__, __LINE__, ea->fcport->port_name,
2570 ea->fcport->d_id.b24, lid);
2572 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2573 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2574 __func__, __LINE__, ea->fcport->port_name,
2575 ea->fcport->d_id.b24, lid);
2577 qla2x00_clear_loop_id(ea->fcport);
2578 set_bit(lid, vha->hw->loop_id_map);
2579 ea->fcport->loop_id = lid;
2580 ea->fcport->keep_nport_handle = 0;
2581 ea->fcport->logout_on_delete = 1;
2582 qlt_schedule_sess_for_deletion(ea->fcport);
2589 /****************************************************************************/
2590 /* QLogic ISP2x00 Hardware Support Functions. */
2591 /****************************************************************************/
2594 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
2596 int rval = QLA_SUCCESS;
2597 struct qla_hw_data *ha = vha->hw;
2598 uint32_t idc_major_ver, idc_minor_ver;
2601 qla83xx_idc_lock(vha, 0);
2603 /* SV: TODO: Assign initialization timeout from
2604 * flash-info / other param
2606 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
2607 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
2609 /* Set our fcoe function presence */
2610 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
2611 ql_dbg(ql_dbg_p3p, vha, 0xb077,
2612 "Error while setting DRV-Presence.\n");
2613 rval = QLA_FUNCTION_FAILED;
2617 /* Decide the reset ownership */
2618 qla83xx_reset_ownership(vha);
2621 * On first protocol driver load:
2622 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2624 * Others: Check compatibility with current IDC Major version.
2626 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
2627 if (ha->flags.nic_core_reset_owner) {
2628 /* Set IDC Major version */
2629 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
2630 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
2632 /* Clearing IDC-Lock-Recovery register */
2633 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
2634 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
2636 * Clear further IDC participation if we are not compatible with
2637 * the current IDC Major Version.
2639 ql_log(ql_log_warn, vha, 0xb07d,
2640 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2641 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
2642 __qla83xx_clear_drv_presence(vha);
2643 rval = QLA_FUNCTION_FAILED;
2646 /* Each function sets its supported Minor version. */
2647 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
2648 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
2649 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
2651 if (ha->flags.nic_core_reset_owner) {
2652 memset(config, 0, sizeof(config));
2653 if (!qla81xx_get_port_config(vha, config))
2654 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
2658 rval = qla83xx_idc_state_handler(vha);
2661 qla83xx_idc_unlock(vha, 0);
2667 * qla2x00_initialize_adapter
2671 * ha = adapter block pointer.
2677 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
2680 struct qla_hw_data *ha = vha->hw;
2681 struct req_que *req = ha->req_q_map[0];
2682 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2684 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2685 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2687 /* Clear adapter flags. */
2688 vha->flags.online = 0;
2689 ha->flags.chip_reset_done = 0;
2690 vha->flags.reset_active = 0;
2691 ha->flags.pci_channel_io_perm_failure = 0;
2692 ha->flags.eeh_busy = 0;
2693 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2694 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
2695 atomic_set(&vha->loop_state, LOOP_DOWN);
2696 vha->device_flags = DFLG_NO_CABLE;
2698 vha->flags.management_server_logged_in = 0;
2699 vha->marker_needed = 0;
2700 ha->isp_abort_cnt = 0;
2701 ha->beacon_blink_led = 0;
2703 set_bit(0, ha->req_qid_map);
2704 set_bit(0, ha->rsp_qid_map);
2706 ql_dbg(ql_dbg_init, vha, 0x0040,
2707 "Configuring PCI space...\n");
2708 rval = ha->isp_ops->pci_config(vha);
2710 ql_log(ql_log_warn, vha, 0x0044,
2711 "Unable to configure PCI space.\n");
2715 ha->isp_ops->reset_chip(vha);
2717 /* Check for secure flash support */
2718 if (IS_QLA28XX(ha)) {
2719 if (rd_reg_word(®->mailbox12) & BIT_0)
2720 ha->flags.secure_adapter = 1;
2721 ql_log(ql_log_info, vha, 0xffff, "Secure Adapter: %s\n",
2722 (ha->flags.secure_adapter) ? "Yes" : "No");
2726 rval = qla2xxx_get_flash_info(vha);
2728 ql_log(ql_log_fatal, vha, 0x004f,
2729 "Unable to validate FLASH data.\n");
2733 if (IS_QLA8044(ha)) {
2734 qla8044_read_reset_template(vha);
2736 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2737 * If DONRESET_BIT0 is set, drivers should not set dev_state
2738 * to NEED_RESET. But if NEED_RESET is set, drivers should
2739 * should honor the reset. */
2740 if (ql2xdontresethba == 1)
2741 qla8044_set_idc_dontreset(vha);
2744 ha->isp_ops->get_flash_version(vha, req->ring);
2745 ql_dbg(ql_dbg_init, vha, 0x0061,
2746 "Configure NVRAM parameters...\n");
2748 /* Let priority default to FCP, can be overridden by nvram_config */
2749 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2751 ha->isp_ops->nvram_config(vha);
2753 if (ha->fc4_type_priority != FC4_PRIORITY_FCP &&
2754 ha->fc4_type_priority != FC4_PRIORITY_NVME)
2755 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2757 ql_log(ql_log_info, vha, 0xffff, "FC4 priority set to %s\n",
2758 ha->fc4_type_priority == FC4_PRIORITY_FCP ? "FCP" : "NVMe");
2760 if (ha->flags.disable_serdes) {
2761 /* Mask HBA via NVRAM settings? */
2762 ql_log(ql_log_info, vha, 0x0077,
2763 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
2764 return QLA_FUNCTION_FAILED;
2767 ql_dbg(ql_dbg_init, vha, 0x0078,
2768 "Verifying loaded RISC code...\n");
2770 /* If smartsan enabled then require fdmi and rdp enabled */
2776 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
2777 rval = ha->isp_ops->chip_diag(vha);
2780 rval = qla2x00_setup_chip(vha);
2785 if (IS_QLA84XX(ha)) {
2786 ha->cs84xx = qla84xx_get_chip(vha);
2788 ql_log(ql_log_warn, vha, 0x00d0,
2789 "Unable to configure ISP84XX.\n");
2790 return QLA_FUNCTION_FAILED;
2794 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2795 rval = qla2x00_init_rings(vha);
2797 /* No point in continuing if firmware initialization failed. */
2798 if (rval != QLA_SUCCESS)
2801 ha->flags.chip_reset_done = 1;
2803 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2804 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2805 rval = qla84xx_init_chip(vha);
2806 if (rval != QLA_SUCCESS) {
2807 ql_log(ql_log_warn, vha, 0x00d4,
2808 "Unable to initialize ISP84XX.\n");
2809 qla84xx_put_chip(vha);
2813 /* Load the NIC Core f/w if we are the first protocol driver. */
2814 if (IS_QLA8031(ha)) {
2815 rval = qla83xx_nic_core_fw_load(vha);
2817 ql_log(ql_log_warn, vha, 0x0124,
2818 "Error in initializing NIC Core f/w.\n");
2821 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2822 qla24xx_read_fcp_prio_cfg(vha);
2824 if (IS_P3P_TYPE(ha))
2825 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2827 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2833 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2836 * Returns 0 on success.
2839 qla2100_pci_config(scsi_qla_host_t *vha)
2842 unsigned long flags;
2843 struct qla_hw_data *ha = vha->hw;
2844 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2846 pci_set_master(ha->pdev);
2847 pci_try_set_mwi(ha->pdev);
2849 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2850 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2851 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2853 pci_disable_rom(ha->pdev);
2855 /* Get PCI bus information. */
2856 spin_lock_irqsave(&ha->hardware_lock, flags);
2857 ha->pci_attr = rd_reg_word(®->ctrl_status);
2858 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2864 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2867 * Returns 0 on success.
2870 qla2300_pci_config(scsi_qla_host_t *vha)
2873 unsigned long flags = 0;
2875 struct qla_hw_data *ha = vha->hw;
2876 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2878 pci_set_master(ha->pdev);
2879 pci_try_set_mwi(ha->pdev);
2881 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2882 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2884 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2885 w &= ~PCI_COMMAND_INTX_DISABLE;
2886 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2889 * If this is a 2300 card and not 2312, reset the
2890 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2891 * the 2310 also reports itself as a 2300 so we need to get the
2892 * fb revision level -- a 6 indicates it really is a 2300 and
2895 if (IS_QLA2300(ha)) {
2896 spin_lock_irqsave(&ha->hardware_lock, flags);
2899 wrt_reg_word(®->hccr, HCCR_PAUSE_RISC);
2900 for (cnt = 0; cnt < 30000; cnt++) {
2901 if ((rd_reg_word(®->hccr) & HCCR_RISC_PAUSE) != 0)
2907 /* Select FPM registers. */
2908 wrt_reg_word(®->ctrl_status, 0x20);
2909 rd_reg_word(®->ctrl_status);
2911 /* Get the fb rev level */
2912 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2914 if (ha->fb_rev == FPM_2300)
2915 pci_clear_mwi(ha->pdev);
2917 /* Deselect FPM registers. */
2918 wrt_reg_word(®->ctrl_status, 0x0);
2919 rd_reg_word(®->ctrl_status);
2921 /* Release RISC module. */
2922 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
2923 for (cnt = 0; cnt < 30000; cnt++) {
2924 if ((rd_reg_word(®->hccr) & HCCR_RISC_PAUSE) == 0)
2930 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2933 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2935 pci_disable_rom(ha->pdev);
2937 /* Get PCI bus information. */
2938 spin_lock_irqsave(&ha->hardware_lock, flags);
2939 ha->pci_attr = rd_reg_word(®->ctrl_status);
2940 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2946 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2949 * Returns 0 on success.
2952 qla24xx_pci_config(scsi_qla_host_t *vha)
2955 unsigned long flags = 0;
2956 struct qla_hw_data *ha = vha->hw;
2957 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2959 pci_set_master(ha->pdev);
2960 pci_try_set_mwi(ha->pdev);
2962 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2963 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2964 w &= ~PCI_COMMAND_INTX_DISABLE;
2965 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2967 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2969 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2970 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2971 pcix_set_mmrbc(ha->pdev, 2048);
2973 /* PCIe -- adjust Maximum Read Request Size (2048). */
2974 if (pci_is_pcie(ha->pdev))
2975 pcie_set_readrq(ha->pdev, 4096);
2977 pci_disable_rom(ha->pdev);
2979 ha->chip_revision = ha->pdev->revision;
2981 /* Get PCI bus information. */
2982 spin_lock_irqsave(&ha->hardware_lock, flags);
2983 ha->pci_attr = rd_reg_dword(®->ctrl_status);
2984 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2990 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2993 * Returns 0 on success.
2996 qla25xx_pci_config(scsi_qla_host_t *vha)
2999 struct qla_hw_data *ha = vha->hw;
3001 pci_set_master(ha->pdev);
3002 pci_try_set_mwi(ha->pdev);
3004 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
3005 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
3006 w &= ~PCI_COMMAND_INTX_DISABLE;
3007 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
3009 /* PCIe -- adjust Maximum Read Request Size (2048). */
3010 if (pci_is_pcie(ha->pdev))
3011 pcie_set_readrq(ha->pdev, 4096);
3013 pci_disable_rom(ha->pdev);
3015 ha->chip_revision = ha->pdev->revision;
3021 * qla2x00_isp_firmware() - Choose firmware image.
3024 * Returns 0 on success.
3027 qla2x00_isp_firmware(scsi_qla_host_t *vha)
3030 uint16_t loop_id, topo, sw_cap;
3031 uint8_t domain, area, al_pa;
3032 struct qla_hw_data *ha = vha->hw;
3034 /* Assume loading risc code */
3035 rval = QLA_FUNCTION_FAILED;
3037 if (ha->flags.disable_risc_code_load) {
3038 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
3040 /* Verify checksum of loaded RISC code. */
3041 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
3042 if (rval == QLA_SUCCESS) {
3043 /* And, verify we are not in ROM code. */
3044 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
3045 &area, &domain, &topo, &sw_cap);
3050 ql_dbg(ql_dbg_init, vha, 0x007a,
3051 "**** Load RISC code ****.\n");
3057 * qla2x00_reset_chip() - Reset ISP chip.
3060 * Returns 0 on success.
3063 qla2x00_reset_chip(scsi_qla_host_t *vha)
3065 unsigned long flags = 0;
3066 struct qla_hw_data *ha = vha->hw;
3067 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3070 int rval = QLA_FUNCTION_FAILED;
3072 if (unlikely(pci_channel_offline(ha->pdev)))
3075 ha->isp_ops->disable_intrs(ha);
3077 spin_lock_irqsave(&ha->hardware_lock, flags);
3079 /* Turn off master enable */
3081 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
3082 cmd &= ~PCI_COMMAND_MASTER;
3083 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
3085 if (!IS_QLA2100(ha)) {
3087 wrt_reg_word(®->hccr, HCCR_PAUSE_RISC);
3088 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
3089 for (cnt = 0; cnt < 30000; cnt++) {
3090 if ((rd_reg_word(®->hccr) &
3091 HCCR_RISC_PAUSE) != 0)
3096 rd_reg_word(®->hccr); /* PCI Posting. */
3100 /* Select FPM registers. */
3101 wrt_reg_word(®->ctrl_status, 0x20);
3102 rd_reg_word(®->ctrl_status); /* PCI Posting. */
3104 /* FPM Soft Reset. */
3105 wrt_reg_word(®->fpm_diag_config, 0x100);
3106 rd_reg_word(®->fpm_diag_config); /* PCI Posting. */
3108 /* Toggle Fpm Reset. */
3109 if (!IS_QLA2200(ha)) {
3110 wrt_reg_word(®->fpm_diag_config, 0x0);
3111 rd_reg_word(®->fpm_diag_config); /* PCI Posting. */
3114 /* Select frame buffer registers. */
3115 wrt_reg_word(®->ctrl_status, 0x10);
3116 rd_reg_word(®->ctrl_status); /* PCI Posting. */
3118 /* Reset frame buffer FIFOs. */
3119 if (IS_QLA2200(ha)) {
3120 WRT_FB_CMD_REG(ha, reg, 0xa000);
3121 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
3123 WRT_FB_CMD_REG(ha, reg, 0x00fc);
3125 /* Read back fb_cmd until zero or 3 seconds max */
3126 for (cnt = 0; cnt < 3000; cnt++) {
3127 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
3133 /* Select RISC module registers. */
3134 wrt_reg_word(®->ctrl_status, 0);
3135 rd_reg_word(®->ctrl_status); /* PCI Posting. */
3137 /* Reset RISC processor. */
3138 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
3139 rd_reg_word(®->hccr); /* PCI Posting. */
3141 /* Release RISC processor. */
3142 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
3143 rd_reg_word(®->hccr); /* PCI Posting. */
3146 wrt_reg_word(®->hccr, HCCR_CLR_RISC_INT);
3147 wrt_reg_word(®->hccr, HCCR_CLR_HOST_INT);
3149 /* Reset ISP chip. */
3150 wrt_reg_word(®->ctrl_status, CSR_ISP_SOFT_RESET);
3152 /* Wait for RISC to recover from reset. */
3153 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
3155 * It is necessary to for a delay here since the card doesn't
3156 * respond to PCI reads during a reset. On some architectures
3157 * this will result in an MCA.
3160 for (cnt = 30000; cnt; cnt--) {
3161 if ((rd_reg_word(®->ctrl_status) &
3162 CSR_ISP_SOFT_RESET) == 0)
3169 /* Reset RISC processor. */
3170 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
3172 wrt_reg_word(®->semaphore, 0);
3174 /* Release RISC processor. */
3175 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
3176 rd_reg_word(®->hccr); /* PCI Posting. */
3178 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
3179 for (cnt = 0; cnt < 30000; cnt++) {
3180 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
3188 /* Turn on master enable */
3189 cmd |= PCI_COMMAND_MASTER;
3190 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
3192 /* Disable RISC pause on FPM parity error. */
3193 if (!IS_QLA2100(ha)) {
3194 wrt_reg_word(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
3195 rd_reg_word(®->hccr); /* PCI Posting. */
3198 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3204 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
3207 * Returns 0 on success.
3210 qla81xx_reset_mpi(scsi_qla_host_t *vha)
3212 uint16_t mb[4] = {0x1010, 0, 1, 0};
3214 if (!IS_QLA81XX(vha->hw))
3217 return qla81xx_write_mpi_register(vha, mb);
3221 qla_chk_risc_recovery(scsi_qla_host_t *vha)
3223 struct qla_hw_data *ha = vha->hw;
3224 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3225 __le16 __iomem *mbptr = ®->mailbox0;
3228 int rc = QLA_SUCCESS;
3230 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3233 /* this check is only valid after RISC reset */
3234 mb[0] = rd_reg_word(mbptr);
3237 rc = QLA_FUNCTION_FAILED;
3239 for (i = 1; i < 32; i++) {
3240 mb[i] = rd_reg_word(mbptr);
3244 ql_log(ql_log_warn, vha, 0x1015,
3245 "RISC reset failed. mb[0-7] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
3246 mb[0], mb[1], mb[2], mb[3], mb[4], mb[5], mb[6], mb[7]);
3247 ql_log(ql_log_warn, vha, 0x1015,
3248 "RISC reset failed. mb[8-15] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
3249 mb[8], mb[9], mb[10], mb[11], mb[12], mb[13], mb[14],
3251 ql_log(ql_log_warn, vha, 0x1015,
3252 "RISC reset failed. mb[16-23] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
3253 mb[16], mb[17], mb[18], mb[19], mb[20], mb[21], mb[22],
3255 ql_log(ql_log_warn, vha, 0x1015,
3256 "RISC reset failed. mb[24-31] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
3257 mb[24], mb[25], mb[26], mb[27], mb[28], mb[29], mb[30],
3264 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
3267 * Returns 0 on success.
3270 qla24xx_reset_risc(scsi_qla_host_t *vha)
3272 unsigned long flags = 0;
3273 struct qla_hw_data *ha = vha->hw;
3274 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3277 static int abts_cnt; /* ISP abort retry counts */
3278 int rval = QLA_SUCCESS;
3281 spin_lock_irqsave(&ha->hardware_lock, flags);
3284 wrt_reg_dword(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
3285 for (cnt = 0; cnt < 30000; cnt++) {
3286 if ((rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
3292 if (!(rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE))
3293 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
3295 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
3296 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
3297 rd_reg_dword(®->hccr),
3298 rd_reg_dword(®->ctrl_status),
3299 (rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE));
3301 wrt_reg_dword(®->ctrl_status,
3302 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
3303 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
3307 /* Wait for firmware to complete NVRAM accesses. */
3308 rd_reg_word(®->mailbox0);
3309 for (cnt = 10000; rd_reg_word(®->mailbox0) != 0 &&
3310 rval == QLA_SUCCESS; cnt--) {
3315 rval = QLA_FUNCTION_TIMEOUT;
3318 if (rval == QLA_SUCCESS)
3319 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
3321 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
3322 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
3323 rd_reg_dword(®->hccr),
3324 rd_reg_word(®->mailbox0));
3326 /* Wait for soft-reset to complete. */
3327 rd_reg_dword(®->ctrl_status);
3328 for (cnt = 0; cnt < 60; cnt++) {
3330 if ((rd_reg_dword(®->ctrl_status) &
3331 CSRX_ISP_SOFT_RESET) == 0)
3336 if (!(rd_reg_dword(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
3337 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
3339 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
3340 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
3341 rd_reg_dword(®->hccr),
3342 rd_reg_dword(®->ctrl_status));
3344 /* If required, do an MPI FW reset now */
3345 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
3346 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
3347 if (++abts_cnt < 5) {
3348 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3349 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
3352 * We exhausted the ISP abort retries. We have to
3353 * set the board offline.
3356 vha->flags.online = 0;
3361 wrt_reg_dword(®->hccr, HCCRX_SET_RISC_RESET);
3362 rd_reg_dword(®->hccr);
3364 wrt_reg_dword(®->hccr, HCCRX_REL_RISC_PAUSE);
3365 rd_reg_dword(®->hccr);
3367 wrt_reg_dword(®->hccr, HCCRX_CLR_RISC_RESET);
3369 rd_reg_dword(®->hccr);
3371 wd = rd_reg_word(®->mailbox0);
3372 for (cnt = 300; wd != 0 && rval == QLA_SUCCESS; cnt--) {
3376 if (print && qla_chk_risc_recovery(vha))
3379 wd = rd_reg_word(®->mailbox0);
3381 rval = QLA_FUNCTION_TIMEOUT;
3383 ql_log(ql_log_warn, vha, 0x015e,
3384 "RISC reset timeout\n");
3388 if (rval == QLA_SUCCESS)
3389 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
3391 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
3392 "Host Risc 0x%x, mailbox0 0x%x\n",
3393 rd_reg_dword(®->hccr),
3394 rd_reg_word(®->mailbox0));
3396 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3398 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
3399 "Driver in %s mode\n",
3400 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
3402 if (IS_NOPOLLING_TYPE(ha))
3403 ha->isp_ops->enable_intrs(ha);
3409 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
3411 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
3413 wrt_reg_dword(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
3414 *data = rd_reg_dword(®->iobase_window + RISC_REGISTER_WINDOW_OFFSET);
3418 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
3420 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
3422 wrt_reg_dword(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
3423 wrt_reg_dword(®->iobase_window + RISC_REGISTER_WINDOW_OFFSET, data);
3427 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
3430 uint delta_msec = 100;
3431 uint elapsed_msec = 0;
3435 if (vha->hw->pdev->subsystem_device != 0x0175 &&
3436 vha->hw->pdev->subsystem_device != 0x0240)
3439 wrt_reg_dword(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
3443 timeout_msec = TIMEOUT_SEMAPHORE;
3444 n = timeout_msec / delta_msec;
3446 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
3447 qla25xx_read_risc_sema_reg(vha, &wd32);
3448 if (wd32 & RISC_SEMAPHORE)
3451 elapsed_msec += delta_msec;
3452 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
3456 if (!(wd32 & RISC_SEMAPHORE))
3459 if (!(wd32 & RISC_SEMAPHORE_FORCE))
3462 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
3463 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
3464 n = timeout_msec / delta_msec;
3466 qla25xx_read_risc_sema_reg(vha, &wd32);
3467 if (!(wd32 & RISC_SEMAPHORE_FORCE))
3470 elapsed_msec += delta_msec;
3471 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
3475 if (wd32 & RISC_SEMAPHORE_FORCE)
3476 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
3481 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
3488 * qla24xx_reset_chip() - Reset ISP24xx chip.
3491 * Returns 0 on success.
3494 qla24xx_reset_chip(scsi_qla_host_t *vha)
3496 struct qla_hw_data *ha = vha->hw;
3497 int rval = QLA_FUNCTION_FAILED;
3499 if (pci_channel_offline(ha->pdev) &&
3500 ha->flags.pci_channel_io_perm_failure) {
3504 ha->isp_ops->disable_intrs(ha);
3506 qla25xx_manipulate_risc_semaphore(vha);
3508 /* Perform RISC reset. */
3509 rval = qla24xx_reset_risc(vha);
3515 * qla2x00_chip_diag() - Test chip for proper operation.
3518 * Returns 0 on success.
3521 qla2x00_chip_diag(scsi_qla_host_t *vha)
3524 struct qla_hw_data *ha = vha->hw;
3525 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3526 unsigned long flags = 0;
3530 struct req_que *req = ha->req_q_map[0];
3532 /* Assume a failed state */
3533 rval = QLA_FUNCTION_FAILED;
3535 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
3536 ®->flash_address);
3538 spin_lock_irqsave(&ha->hardware_lock, flags);
3540 /* Reset ISP chip. */
3541 wrt_reg_word(®->ctrl_status, CSR_ISP_SOFT_RESET);
3544 * We need to have a delay here since the card will not respond while
3545 * in reset causing an MCA on some architectures.
3548 data = qla2x00_debounce_register(®->ctrl_status);
3549 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
3551 data = rd_reg_word(®->ctrl_status);
3556 goto chip_diag_failed;
3558 ql_dbg(ql_dbg_init, vha, 0x007c,
3559 "Reset register cleared by chip reset.\n");
3561 /* Reset RISC processor. */
3562 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
3563 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
3565 /* Workaround for QLA2312 PCI parity error */
3566 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
3567 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
3568 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
3570 data = RD_MAILBOX_REG(ha, reg, 0);
3577 goto chip_diag_failed;
3579 /* Check product ID of chip */
3580 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
3582 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
3583 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
3584 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
3585 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
3586 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
3587 mb[3] != PROD_ID_3) {
3588 ql_log(ql_log_warn, vha, 0x0062,
3589 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
3590 mb[1], mb[2], mb[3]);
3592 goto chip_diag_failed;
3594 ha->product_id[0] = mb[1];
3595 ha->product_id[1] = mb[2];
3596 ha->product_id[2] = mb[3];
3597 ha->product_id[3] = mb[4];
3599 /* Adjust fw RISC transfer size */
3600 if (req->length > 1024)
3601 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
3603 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
3606 if (IS_QLA2200(ha) &&
3607 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
3608 /* Limit firmware transfer size with a 2200A */
3609 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
3611 ha->device_type |= DT_ISP2200A;
3612 ha->fw_transfer_size = 128;
3615 /* Wrap Incoming Mailboxes Test. */
3616 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3618 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
3619 rval = qla2x00_mbx_reg_test(vha);
3621 ql_log(ql_log_warn, vha, 0x0080,
3622 "Failed mailbox send register test.\n");
3624 /* Flag a successful rval */
3626 spin_lock_irqsave(&ha->hardware_lock, flags);
3630 ql_log(ql_log_info, vha, 0x0081,
3631 "Chip diagnostics **** FAILED ****.\n");
3633 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3639 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3642 * Returns 0 on success.
3645 qla24xx_chip_diag(scsi_qla_host_t *vha)
3648 struct qla_hw_data *ha = vha->hw;
3649 struct req_que *req = ha->req_q_map[0];
3651 if (IS_P3P_TYPE(ha))
3654 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
3656 rval = qla2x00_mbx_reg_test(vha);
3658 ql_log(ql_log_warn, vha, 0x0082,
3659 "Failed mailbox send register test.\n");
3661 /* Flag a successful rval */
3669 qla2x00_init_fce_trace(scsi_qla_host_t *vha)
3674 struct qla_hw_data *ha = vha->hw;
3676 if (!IS_FWI2_CAPABLE(ha))
3679 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3680 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3684 ql_dbg(ql_dbg_init, vha, 0x00bd,
3685 "%s: FCE Mem is already allocated.\n",
3690 /* Allocate memory for Fibre Channel Event Buffer. */
3691 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3694 ql_log(ql_log_warn, vha, 0x00be,
3695 "Unable to allocate (%d KB) for FCE.\n",
3700 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3701 ha->fce_mb, &ha->fce_bufs);
3703 ql_log(ql_log_warn, vha, 0x00bf,
3704 "Unable to initialize FCE (%d).\n", rval);
3705 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, tc_dma);
3709 ql_dbg(ql_dbg_init, vha, 0x00c0,
3710 "Allocated (%d KB) for FCE...\n", FCE_SIZE / 1024);
3712 ha->flags.fce_enabled = 1;
3713 ha->fce_dma = tc_dma;
3718 qla2x00_init_eft_trace(scsi_qla_host_t *vha)
3723 struct qla_hw_data *ha = vha->hw;
3725 if (!IS_FWI2_CAPABLE(ha))
3729 ql_dbg(ql_dbg_init, vha, 0x00bd,
3730 "%s: EFT Mem is already allocated.\n",
3735 /* Allocate memory for Extended Trace Buffer. */
3736 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3739 ql_log(ql_log_warn, vha, 0x00c1,
3740 "Unable to allocate (%d KB) for EFT.\n",
3745 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3747 ql_log(ql_log_warn, vha, 0x00c2,
3748 "Unable to initialize EFT (%d).\n", rval);
3749 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, tc_dma);
3753 ql_dbg(ql_dbg_init, vha, 0x00c3,
3754 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3756 ha->eft_dma = tc_dma;
3761 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3763 qla2x00_init_fce_trace(vha);
3764 qla2x00_init_eft_trace(vha);
3768 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3770 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
3771 eft_size, fce_size, mq_size;
3772 struct qla_hw_data *ha = vha->hw;
3773 struct req_que *req = ha->req_q_map[0];
3774 struct rsp_que *rsp = ha->rsp_q_map[0];
3775 struct qla2xxx_fw_dump *fw_dump;
3778 ql_dbg(ql_dbg_init, vha, 0x00bd,
3779 "Firmware dump already allocated.\n");
3784 ha->fw_dump_cap_flags = 0;
3785 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
3786 req_q_size = rsp_q_size = 0;
3788 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3789 fixed_size = sizeof(struct qla2100_fw_dump);
3790 } else if (IS_QLA23XX(ha)) {
3791 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
3792 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
3794 } else if (IS_FWI2_CAPABLE(ha)) {
3796 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
3797 else if (IS_QLA81XX(ha))
3798 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
3799 else if (IS_QLA25XX(ha))
3800 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
3802 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
3804 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
3807 if (!IS_QLA83XX(ha))
3808 mq_size = sizeof(struct qla2xxx_mq_chain);
3810 * Allocate maximum buffer size for all queues - Q0.
3811 * Resizing must be done at end-of-dump processing.
3813 mq_size += (ha->max_req_queues - 1) *
3814 (req->length * sizeof(request_t));
3815 mq_size += (ha->max_rsp_queues - 1) *
3816 (rsp->length * sizeof(response_t));
3818 if (ha->tgt.atio_ring)
3819 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3821 qla2x00_init_fce_trace(vha);
3823 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3824 qla2x00_init_eft_trace(vha);
3826 eft_size = EFT_SIZE;
3829 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3830 struct fwdt *fwdt = ha->fwdt;
3833 for (j = 0; j < 2; j++, fwdt++) {
3834 if (!fwdt->template) {
3835 ql_dbg(ql_dbg_init, vha, 0x00ba,
3836 "-> fwdt%u no template\n", j);
3839 ql_dbg(ql_dbg_init, vha, 0x00fa,
3840 "-> fwdt%u calculating fwdump size...\n", j);
3841 fwdt->dump_size = qla27xx_fwdt_calculate_dump_size(
3842 vha, fwdt->template);
3843 ql_dbg(ql_dbg_init, vha, 0x00fa,
3844 "-> fwdt%u calculated fwdump size = %#lx bytes\n",
3845 j, fwdt->dump_size);
3846 dump_size += fwdt->dump_size;
3848 /* Add space for spare MPI fw dump. */
3849 dump_size += ha->fwdt[1].dump_size;
3851 req_q_size = req->length * sizeof(request_t);
3852 rsp_q_size = rsp->length * sizeof(response_t);
3853 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3854 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size
3856 ha->chain_offset = dump_size;
3857 dump_size += mq_size + fce_size;
3858 if (ha->exchoffld_buf)
3859 dump_size += sizeof(struct qla2xxx_offld_chain) +
3861 if (ha->exlogin_buf)
3862 dump_size += sizeof(struct qla2xxx_offld_chain) +
3866 if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) {
3868 ql_dbg(ql_dbg_init, vha, 0x00c5,
3869 "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n",
3870 __func__, dump_size, ha->fw_dump_len,
3871 ha->fw_dump_alloc_len);
3873 fw_dump = vmalloc(dump_size);
3875 ql_log(ql_log_warn, vha, 0x00c4,
3876 "Unable to allocate (%d KB) for firmware dump.\n",
3879 mutex_lock(&ha->optrom_mutex);
3880 if (ha->fw_dumped) {
3881 memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len);
3883 ha->fw_dump = fw_dump;
3884 ha->fw_dump_alloc_len = dump_size;
3885 ql_dbg(ql_dbg_init, vha, 0x00c5,
3886 "Re-Allocated (%d KB) and save firmware dump.\n",
3890 ha->fw_dump = fw_dump;
3892 ha->fw_dump_len = ha->fw_dump_alloc_len =
3894 ql_dbg(ql_dbg_init, vha, 0x00c5,
3895 "Allocated (%d KB) for firmware dump.\n",
3898 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3899 ha->mpi_fw_dump = (char *)fw_dump +
3900 ha->fwdt[1].dump_size;
3901 mutex_unlock(&ha->optrom_mutex);
3905 ha->fw_dump->signature[0] = 'Q';
3906 ha->fw_dump->signature[1] = 'L';
3907 ha->fw_dump->signature[2] = 'G';
3908 ha->fw_dump->signature[3] = 'C';
3909 ha->fw_dump->version = htonl(1);
3911 ha->fw_dump->fixed_size = htonl(fixed_size);
3912 ha->fw_dump->mem_size = htonl(mem_size);
3913 ha->fw_dump->req_q_size = htonl(req_q_size);
3914 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3916 ha->fw_dump->eft_size = htonl(eft_size);
3917 ha->fw_dump->eft_addr_l =
3918 htonl(LSD(ha->eft_dma));
3919 ha->fw_dump->eft_addr_h =
3920 htonl(MSD(ha->eft_dma));
3922 ha->fw_dump->header_size =
3924 (struct qla2xxx_fw_dump, isp));
3926 mutex_unlock(&ha->optrom_mutex);
3932 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3934 #define MPS_MASK 0xe0
3939 if (!IS_QLA81XX(vha->hw))
3942 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3943 if (rval != QLA_SUCCESS) {
3944 ql_log(ql_log_warn, vha, 0x0105,
3945 "Unable to acquire semaphore.\n");
3949 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3950 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3951 if (rval != QLA_SUCCESS) {
3952 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3957 if (dc == (dw & MPS_MASK))
3962 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3963 if (rval != QLA_SUCCESS) {
3964 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3968 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3969 if (rval != QLA_SUCCESS) {
3970 ql_log(ql_log_warn, vha, 0x006d,
3971 "Unable to release semaphore.\n");
3979 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3981 /* Don't try to reallocate the array */
3982 if (req->outstanding_cmds)
3985 if (!IS_FWI2_CAPABLE(ha))
3986 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3988 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3989 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3991 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3994 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3998 if (!req->outstanding_cmds) {
4000 * Try to allocate a minimal size just so we can get through
4003 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
4004 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
4008 if (!req->outstanding_cmds) {
4009 ql_log(ql_log_fatal, NULL, 0x0126,
4010 "Failed to allocate memory for "
4011 "outstanding_cmds for req_que %p.\n", req);
4012 req->num_outstanding_cmds = 0;
4013 return QLA_FUNCTION_FAILED;
4020 #define PRINT_FIELD(_field, _flag, _str) { \
4021 if (a0->_field & _flag) {\
4027 len = snprintf(ptr, leftover, "%s", _str); \
4034 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
4037 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
4038 u8 str[STR_LEN], *ptr, p;
4041 memset(str, 0, STR_LEN);
4042 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
4043 ql_dbg(ql_dbg_init, vha, 0x015a,
4044 "SFP MFG Name: %s\n", str);
4046 memset(str, 0, STR_LEN);
4047 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
4048 ql_dbg(ql_dbg_init, vha, 0x015c,
4049 "SFP Part Name: %s\n", str);
4052 memset(str, 0, STR_LEN);
4056 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
4057 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
4058 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
4059 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
4060 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
4061 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
4062 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
4063 ql_dbg(ql_dbg_init, vha, 0x0160,
4064 "SFP Media: %s\n", str);
4067 memset(str, 0, STR_LEN);
4071 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
4072 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
4073 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
4074 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
4075 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
4076 ql_dbg(ql_dbg_init, vha, 0x0196,
4077 "SFP Link Length: %s\n", str);
4079 memset(str, 0, STR_LEN);
4083 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
4084 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
4085 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
4086 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
4087 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
4088 ql_dbg(ql_dbg_init, vha, 0x016e,
4089 "SFP FC Link Tech: %s\n", str);
4092 ql_dbg(ql_dbg_init, vha, 0x016f,
4093 "SFP Distant: %d km\n", a0->length_km);
4094 if (a0->length_100m)
4095 ql_dbg(ql_dbg_init, vha, 0x0170,
4096 "SFP Distant: %d m\n", a0->length_100m*100);
4097 if (a0->length_50um_10m)
4098 ql_dbg(ql_dbg_init, vha, 0x0189,
4099 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
4100 if (a0->length_62um_10m)
4101 ql_dbg(ql_dbg_init, vha, 0x018a,
4102 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
4103 if (a0->length_om4_10m)
4104 ql_dbg(ql_dbg_init, vha, 0x0194,
4105 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
4106 if (a0->length_om3_10m)
4107 ql_dbg(ql_dbg_init, vha, 0x0195,
4108 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
4113 * qla24xx_detect_sfp()
4115 * @vha: adapter state pointer.
4118 * 0 -- Configure firmware to use short-range settings -- normal
4119 * buffer-to-buffer credits.
4121 * 1 -- Configure firmware to use long-range settings -- extra
4122 * buffer-to-buffer credits should be allocated with
4123 * ha->lr_distance containing distance settings from NVRAM or SFP
4127 qla24xx_detect_sfp(scsi_qla_host_t *vha)
4130 struct sff_8247_a0 *a;
4131 struct qla_hw_data *ha = vha->hw;
4132 struct nvram_81xx *nv = ha->nvram;
4133 #define LR_DISTANCE_UNKNOWN 2
4134 static const char * const types[] = { "Short", "Long" };
4135 static const char * const lengths[] = { "(10km)", "(5km)", "" };
4138 /* Seed with NVRAM settings. */
4140 ha->flags.lr_detected = 0;
4141 if (IS_BPM_RANGE_CAPABLE(ha) &&
4142 (nv->enhanced_features & NEF_LR_DIST_ENABLE)) {
4144 ha->flags.lr_detected = 1;
4146 (nv->enhanced_features >> LR_DIST_NV_POS)
4150 if (!IS_BPM_ENABLED(vha))
4152 /* Determine SR/LR capabilities of SFP/Transceiver. */
4153 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
4158 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
4159 qla2xxx_print_sfp_info(vha);
4161 ha->flags.lr_detected = 0;
4163 if (ll & FC_LL_VL || ll & FC_LL_L) {
4164 /* Long range, track length. */
4165 ha->flags.lr_detected = 1;
4167 if (a->length_km > 5 || a->length_100m > 50)
4168 ha->lr_distance = LR_DISTANCE_10K;
4170 ha->lr_distance = LR_DISTANCE_5K;
4174 ql_dbg(ql_dbg_async, vha, 0x507b,
4175 "SFP detect: %s-Range SFP %s (nvr=%x ll=%x lr=%x lrd=%x).\n",
4176 types[ha->flags.lr_detected],
4177 ha->flags.lr_detected ? lengths[ha->lr_distance] :
4178 lengths[LR_DISTANCE_UNKNOWN],
4179 used_nvram, ll, ha->flags.lr_detected, ha->lr_distance);
4180 return ha->flags.lr_detected;
4183 static void __qla_adjust_iocb_limit(struct qla_qpair *qpair)
4187 struct qla_hw_data *ha = qpair->vha->hw;
4189 num_qps = ha->num_qpairs + 1;
4190 limit = (ha->orig_fw_iocb_count * QLA_IOCB_PCT_LIMIT) / 100;
4192 qpair->fwres.iocbs_total = ha->orig_fw_iocb_count;
4193 qpair->fwres.iocbs_limit = limit;
4194 qpair->fwres.iocbs_qp_limit = limit / num_qps;
4196 qpair->fwres.exch_total = ha->orig_fw_xcb_count;
4197 qpair->fwres.exch_limit = (ha->orig_fw_xcb_count *
4198 QLA_IOCB_PCT_LIMIT) / 100;
4201 void qla_init_iocb_limit(scsi_qla_host_t *vha)
4204 struct qla_hw_data *ha = vha->hw;
4206 __qla_adjust_iocb_limit(ha->base_qpair);
4207 ha->base_qpair->fwres.iocbs_used = 0;
4208 ha->base_qpair->fwres.exch_used = 0;
4210 for (i = 0; i < ha->max_qpairs; i++) {
4211 if (ha->queue_pair_map[i]) {
4212 __qla_adjust_iocb_limit(ha->queue_pair_map[i]);
4213 ha->queue_pair_map[i]->fwres.iocbs_used = 0;
4214 ha->queue_pair_map[i]->fwres.exch_used = 0;
4218 ha->fwres.iocb_total = ha->orig_fw_iocb_count;
4219 ha->fwres.iocb_limit = (ha->orig_fw_iocb_count * QLA_IOCB_PCT_LIMIT) / 100;
4220 ha->fwres.exch_total = ha->orig_fw_xcb_count;
4221 ha->fwres.exch_limit = (ha->orig_fw_xcb_count * QLA_IOCB_PCT_LIMIT) / 100;
4223 atomic_set(&ha->fwres.iocb_used, 0);
4224 atomic_set(&ha->fwres.exch_used, 0);
4227 void qla_adjust_iocb_limit(scsi_qla_host_t *vha)
4230 struct qla_hw_data *ha = vha->hw;
4232 __qla_adjust_iocb_limit(ha->base_qpair);
4234 for (i = 0; i < ha->max_qpairs; i++) {
4235 if (ha->queue_pair_map[i])
4236 __qla_adjust_iocb_limit(ha->queue_pair_map[i]);
4241 * qla2x00_setup_chip() - Load and start RISC firmware.
4244 * Returns 0 on success.
4247 qla2x00_setup_chip(scsi_qla_host_t *vha)
4250 uint32_t srisc_address = 0;
4251 struct qla_hw_data *ha = vha->hw;
4252 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4253 unsigned long flags;
4254 uint16_t fw_major_version;
4257 if (IS_P3P_TYPE(ha)) {
4258 rval = ha->isp_ops->load_risc(vha, &srisc_address);
4259 if (rval == QLA_SUCCESS) {
4260 qla2x00_stop_firmware(vha);
4261 goto enable_82xx_npiv;
4266 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
4267 /* Disable SRAM, Instruction RAM and GP RAM parity. */
4268 spin_lock_irqsave(&ha->hardware_lock, flags);
4269 wrt_reg_word(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
4270 rd_reg_word(®->hccr);
4271 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4274 qla81xx_mpi_sync(vha);
4277 /* Load firmware sequences */
4278 rval = ha->isp_ops->load_risc(vha, &srisc_address);
4279 if (rval == QLA_SUCCESS) {
4280 ql_dbg(ql_dbg_init, vha, 0x00c9,
4281 "Verifying Checksum of loaded RISC code.\n");
4283 rval = qla2x00_verify_checksum(vha, srisc_address);
4284 if (rval == QLA_SUCCESS) {
4285 /* Start firmware execution. */
4286 ql_dbg(ql_dbg_init, vha, 0x00ca,
4287 "Starting firmware.\n");
4290 ha->flags.exlogins_enabled = 1;
4292 if (qla_is_exch_offld_enabled(vha))
4293 ha->flags.exchoffld_enabled = 1;
4295 rval = qla2x00_execute_fw(vha, srisc_address);
4296 /* Retrieve firmware information. */
4297 if (rval == QLA_SUCCESS) {
4298 /* Enable BPM support? */
4299 if (!done_once++ && qla24xx_detect_sfp(vha)) {
4300 ql_dbg(ql_dbg_init, vha, 0x00ca,
4301 "Re-starting firmware -- BPM.\n");
4302 /* Best-effort - re-init. */
4303 ha->isp_ops->reset_chip(vha);
4304 ha->isp_ops->chip_diag(vha);
4305 goto execute_fw_with_lr;
4308 if (IS_ZIO_THRESHOLD_CAPABLE(ha))
4309 qla27xx_set_zio_threshold(vha,
4310 ha->last_zio_threshold);
4312 rval = qla2x00_set_exlogins_buffer(vha);
4313 if (rval != QLA_SUCCESS)
4316 rval = qla2x00_set_exchoffld_buffer(vha);
4317 if (rval != QLA_SUCCESS)
4321 fw_major_version = ha->fw_major_version;
4322 if (IS_P3P_TYPE(ha))
4323 qla82xx_check_md_needed(vha);
4325 rval = qla2x00_get_fw_version(vha);
4326 if (rval != QLA_SUCCESS)
4328 ha->flags.npiv_supported = 0;
4329 if (IS_QLA2XXX_MIDTYPE(ha) &&
4330 (ha->fw_attributes & BIT_2)) {
4331 ha->flags.npiv_supported = 1;
4332 if ((!ha->max_npiv_vports) ||
4333 ((ha->max_npiv_vports + 1) %
4334 MIN_MULTI_ID_FABRIC))
4335 ha->max_npiv_vports =
4336 MIN_MULTI_ID_FABRIC - 1;
4338 qla2x00_get_resource_cnts(vha);
4339 qla_init_iocb_limit(vha);
4342 * Allocate the array of outstanding commands
4343 * now that we know the firmware resources.
4345 rval = qla2x00_alloc_outstanding_cmds(ha,
4347 if (rval != QLA_SUCCESS)
4350 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
4351 qla2x00_alloc_offload_mem(vha);
4353 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
4354 qla2x00_alloc_fw_dump(vha);
4360 ql_log(ql_log_fatal, vha, 0x00cd,
4361 "ISP Firmware failed checksum.\n");
4365 /* Enable PUREX PASSTHRU */
4366 if (ql2xrdpenable || ha->flags.scm_supported_f ||
4367 ha->flags.edif_enabled)
4368 qla25xx_set_els_cmds_supported(vha);
4372 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
4373 /* Enable proper parity. */
4374 spin_lock_irqsave(&ha->hardware_lock, flags);
4377 wrt_reg_word(®->hccr, HCCR_ENABLE_PARITY + 0x1);
4379 /* SRAM, Instruction RAM and GP RAM parity */
4380 wrt_reg_word(®->hccr, HCCR_ENABLE_PARITY + 0x7);
4381 rd_reg_word(®->hccr);
4382 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4385 if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
4386 ha->flags.fac_supported = 1;
4387 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
4390 rval = qla81xx_fac_get_sector_size(vha, &size);
4391 if (rval == QLA_SUCCESS) {
4392 ha->flags.fac_supported = 1;
4393 ha->fdt_block_size = size << 2;
4395 ql_log(ql_log_warn, vha, 0x00ce,
4396 "Unsupported FAC firmware (%d.%02d.%02d).\n",
4397 ha->fw_major_version, ha->fw_minor_version,
4398 ha->fw_subminor_version);
4400 if (IS_QLA83XX(ha)) {
4401 ha->flags.fac_supported = 0;
4408 ql_log(ql_log_fatal, vha, 0x00cf,
4409 "Setup chip ****FAILED****.\n");
4416 * qla2x00_init_response_q_entries() - Initializes response queue entries.
4417 * @rsp: response queue
4419 * Beginning of request ring has initialization control block already built
4420 * by nvram config routine.
4422 * Returns 0 on success.
4425 qla2x00_init_response_q_entries(struct rsp_que *rsp)
4430 rsp->ring_ptr = rsp->ring;
4431 rsp->ring_index = 0;
4432 rsp->status_srb = NULL;
4433 pkt = rsp->ring_ptr;
4434 for (cnt = 0; cnt < rsp->length; cnt++) {
4435 pkt->signature = RESPONSE_PROCESSED;
4441 * qla2x00_update_fw_options() - Read and process firmware options.
4444 * Returns 0 on success.
4447 qla2x00_update_fw_options(scsi_qla_host_t *vha)
4449 uint16_t swing, emphasis, tx_sens, rx_sens;
4450 struct qla_hw_data *ha = vha->hw;
4452 memset(ha->fw_options, 0, sizeof(ha->fw_options));
4453 qla2x00_get_fw_options(vha, ha->fw_options);
4455 if (IS_QLA2100(ha) || IS_QLA2200(ha))
4458 /* Serial Link options. */
4459 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
4460 "Serial link options.\n");
4461 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
4462 ha->fw_seriallink_options, sizeof(ha->fw_seriallink_options));
4464 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
4465 if (ha->fw_seriallink_options[3] & BIT_2) {
4466 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
4469 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
4470 emphasis = (ha->fw_seriallink_options[2] &
4471 (BIT_4 | BIT_3)) >> 3;
4472 tx_sens = ha->fw_seriallink_options[0] &
4473 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4474 rx_sens = (ha->fw_seriallink_options[0] &
4475 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
4476 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
4477 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
4480 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
4481 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
4482 ha->fw_options[10] |= BIT_5 |
4483 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
4484 (tx_sens & (BIT_1 | BIT_0));
4487 swing = (ha->fw_seriallink_options[2] &
4488 (BIT_7 | BIT_6 | BIT_5)) >> 5;
4489 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
4490 tx_sens = ha->fw_seriallink_options[1] &
4491 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4492 rx_sens = (ha->fw_seriallink_options[1] &
4493 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
4494 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
4495 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
4498 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
4499 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
4500 ha->fw_options[11] |= BIT_5 |
4501 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
4502 (tx_sens & (BIT_1 | BIT_0));
4506 /* Return command IOCBs without waiting for an ABTS to complete. */
4507 ha->fw_options[3] |= BIT_13;
4510 if (ha->flags.enable_led_scheme)
4511 ha->fw_options[2] |= BIT_12;
4513 /* Detect ISP6312. */
4515 ha->fw_options[2] |= BIT_13;
4517 /* Set Retry FLOGI in case of P2P connection */
4518 if (ha->operating_mode == P2P) {
4519 ha->fw_options[2] |= BIT_3;
4520 ql_dbg(ql_dbg_disc, vha, 0x2100,
4521 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
4522 __func__, ha->fw_options[2]);
4525 /* Update firmware options. */
4526 qla2x00_set_fw_options(vha, ha->fw_options);
4530 qla24xx_update_fw_options(scsi_qla_host_t *vha)
4533 struct qla_hw_data *ha = vha->hw;
4535 if (IS_P3P_TYPE(ha))
4538 /* Hold status IOCBs until ABTS response received. */
4540 ha->fw_options[3] |= BIT_12;
4542 /* Set Retry FLOGI in case of P2P connection */
4543 if (ha->operating_mode == P2P) {
4544 ha->fw_options[2] |= BIT_3;
4545 ql_dbg(ql_dbg_disc, vha, 0x2101,
4546 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
4547 __func__, ha->fw_options[2]);
4550 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
4551 if (ql2xmvasynctoatio && !ha->flags.edif_enabled &&
4552 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
4553 if (qla_tgt_mode_enabled(vha) ||
4554 qla_dual_mode_enabled(vha))
4555 ha->fw_options[2] |= BIT_11;
4557 ha->fw_options[2] &= ~BIT_11;
4560 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4563 * Tell FW to track each exchange to prevent
4564 * driver from using stale exchange.
4566 if (qla_tgt_mode_enabled(vha) ||
4567 qla_dual_mode_enabled(vha))
4568 ha->fw_options[2] |= BIT_4;
4570 ha->fw_options[2] &= ~(BIT_4);
4572 /* Reserve 1/2 of emergency exchanges for ELS.*/
4573 if (qla2xuseresexchforels)
4574 ha->fw_options[2] |= BIT_8;
4576 ha->fw_options[2] &= ~BIT_8;
4579 * N2N: set Secure=1 for PLOGI ACC and
4580 * fw shal not send PRLI after PLOGI Acc
4582 if (ha->flags.edif_enabled &&
4583 DBELL_ACTIVE(vha)) {
4584 ha->fw_options[3] |= BIT_15;
4585 ha->flags.n2n_fw_acc_sec = 1;
4587 ha->fw_options[3] &= ~BIT_15;
4588 ha->flags.n2n_fw_acc_sec = 0;
4592 if (ql2xrdpenable || ha->flags.scm_supported_f ||
4593 ha->flags.edif_enabled)
4594 ha->fw_options[1] |= ADD_FO1_ENABLE_PUREX_IOCB;
4596 /* Enable Async 8130/8131 events -- transceiver insertion/removal */
4597 if (IS_BPM_RANGE_CAPABLE(ha))
4598 ha->fw_options[3] |= BIT_10;
4600 ql_dbg(ql_dbg_init, vha, 0x00e8,
4601 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
4602 __func__, ha->fw_options[1], ha->fw_options[2],
4603 ha->fw_options[3], vha->host->active_mode);
4605 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
4606 qla2x00_set_fw_options(vha, ha->fw_options);
4608 /* Update Serial Link options. */
4609 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
4612 rval = qla2x00_set_serdes_params(vha,
4613 le16_to_cpu(ha->fw_seriallink_options24[1]),
4614 le16_to_cpu(ha->fw_seriallink_options24[2]),
4615 le16_to_cpu(ha->fw_seriallink_options24[3]));
4616 if (rval != QLA_SUCCESS) {
4617 ql_log(ql_log_warn, vha, 0x0104,
4618 "Unable to update Serial Link options (%x).\n", rval);
4623 qla2x00_config_rings(struct scsi_qla_host *vha)
4625 struct qla_hw_data *ha = vha->hw;
4626 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4627 struct req_que *req = ha->req_q_map[0];
4628 struct rsp_que *rsp = ha->rsp_q_map[0];
4630 /* Setup ring parameters in initialization control block. */
4631 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
4632 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
4633 ha->init_cb->request_q_length = cpu_to_le16(req->length);
4634 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
4635 put_unaligned_le64(req->dma, &ha->init_cb->request_q_address);
4636 put_unaligned_le64(rsp->dma, &ha->init_cb->response_q_address);
4638 wrt_reg_word(ISP_REQ_Q_IN(ha, reg), 0);
4639 wrt_reg_word(ISP_REQ_Q_OUT(ha, reg), 0);
4640 wrt_reg_word(ISP_RSP_Q_IN(ha, reg), 0);
4641 wrt_reg_word(ISP_RSP_Q_OUT(ha, reg), 0);
4642 rd_reg_word(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
4646 qla24xx_config_rings(struct scsi_qla_host *vha)
4648 struct qla_hw_data *ha = vha->hw;
4649 device_reg_t *reg = ISP_QUE_REG(ha, 0);
4650 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
4651 struct qla_msix_entry *msix;
4652 struct init_cb_24xx *icb;
4654 struct req_que *req = ha->req_q_map[0];
4655 struct rsp_que *rsp = ha->rsp_q_map[0];
4657 /* Setup ring parameters in initialization control block. */
4658 icb = (struct init_cb_24xx *)ha->init_cb;
4659 icb->request_q_outpointer = cpu_to_le16(0);
4660 icb->response_q_inpointer = cpu_to_le16(0);
4661 icb->request_q_length = cpu_to_le16(req->length);
4662 icb->response_q_length = cpu_to_le16(rsp->length);
4663 put_unaligned_le64(req->dma, &icb->request_q_address);
4664 put_unaligned_le64(rsp->dma, &icb->response_q_address);
4666 /* Setup ATIO queue dma pointers for target mode */
4667 icb->atio_q_inpointer = cpu_to_le16(0);
4668 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
4669 put_unaligned_le64(ha->tgt.atio_dma, &icb->atio_q_address);
4671 if (IS_SHADOW_REG_CAPABLE(ha))
4672 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
4674 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4676 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
4677 icb->rid = cpu_to_le16(rid);
4678 if (ha->flags.msix_enabled) {
4679 msix = &ha->msix_entries[1];
4680 ql_dbg(ql_dbg_init, vha, 0x0019,
4681 "Registering vector 0x%x for base que.\n",
4683 icb->msix = cpu_to_le16(msix->entry);
4685 /* Use alternate PCI bus number */
4687 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
4688 /* Use alternate PCI devfn */
4690 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
4692 /* Use Disable MSIX Handshake mode for capable adapters */
4693 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
4694 (ha->flags.msix_enabled)) {
4695 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
4696 ha->flags.disable_msix_handshake = 1;
4697 ql_dbg(ql_dbg_init, vha, 0x00fe,
4698 "MSIX Handshake Disable Mode turned on.\n");
4700 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
4702 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
4704 wrt_reg_dword(®->isp25mq.req_q_in, 0);
4705 wrt_reg_dword(®->isp25mq.req_q_out, 0);
4706 wrt_reg_dword(®->isp25mq.rsp_q_in, 0);
4707 wrt_reg_dword(®->isp25mq.rsp_q_out, 0);
4709 wrt_reg_dword(®->isp24.req_q_in, 0);
4710 wrt_reg_dword(®->isp24.req_q_out, 0);
4711 wrt_reg_dword(®->isp24.rsp_q_in, 0);
4712 wrt_reg_dword(®->isp24.rsp_q_out, 0);
4715 qlt_24xx_config_rings(vha);
4717 /* If the user has configured the speed, set it here */
4718 if (ha->set_data_rate) {
4719 ql_dbg(ql_dbg_init, vha, 0x00fd,
4720 "Speed set by user : %s Gbps \n",
4721 qla2x00_get_link_speed_str(ha, ha->set_data_rate));
4722 icb->firmware_options_3 = cpu_to_le32(ha->set_data_rate << 13);
4726 rd_reg_word(&ioreg->hccr);
4730 * qla2x00_init_rings() - Initializes firmware.
4733 * Beginning of request ring has initialization control block already built
4734 * by nvram config routine.
4736 * Returns 0 on success.
4739 qla2x00_init_rings(scsi_qla_host_t *vha)
4742 unsigned long flags = 0;
4744 struct qla_hw_data *ha = vha->hw;
4745 struct req_que *req;
4746 struct rsp_que *rsp;
4747 struct mid_init_cb_24xx *mid_init_cb =
4748 (struct mid_init_cb_24xx *) ha->init_cb;
4750 spin_lock_irqsave(&ha->hardware_lock, flags);
4752 /* Clear outstanding commands array. */
4753 for (que = 0; que < ha->max_req_queues; que++) {
4754 req = ha->req_q_map[que];
4755 if (!req || !test_bit(que, ha->req_qid_map))
4757 req->out_ptr = (uint16_t *)(req->ring + req->length);
4759 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
4760 req->outstanding_cmds[cnt] = NULL;
4762 req->current_outstanding_cmd = 1;
4764 /* Initialize firmware. */
4765 req->ring_ptr = req->ring;
4766 req->ring_index = 0;
4767 req->cnt = req->length;
4770 for (que = 0; que < ha->max_rsp_queues; que++) {
4771 rsp = ha->rsp_q_map[que];
4772 if (!rsp || !test_bit(que, ha->rsp_qid_map))
4774 rsp->in_ptr = (uint16_t *)(rsp->ring + rsp->length);
4776 /* Initialize response queue entries */
4778 qlafx00_init_response_q_entries(rsp);
4780 qla2x00_init_response_q_entries(rsp);
4783 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
4784 ha->tgt.atio_ring_index = 0;
4785 /* Initialize ATIO queue entries */
4786 qlt_init_atio_q_entries(vha);
4788 ha->isp_ops->config_rings(vha);
4790 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4792 if (IS_QLAFX00(ha)) {
4793 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
4797 /* Update any ISP specific firmware options before initialization. */
4798 ha->isp_ops->update_fw_options(vha);
4800 ql_dbg(ql_dbg_init, vha, 0x00d1,
4801 "Issue init firmware FW opt 1-3= %08x %08x %08x.\n",
4802 le32_to_cpu(mid_init_cb->init_cb.firmware_options_1),
4803 le32_to_cpu(mid_init_cb->init_cb.firmware_options_2),
4804 le32_to_cpu(mid_init_cb->init_cb.firmware_options_3));
4806 if (ha->flags.npiv_supported) {
4807 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
4808 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
4809 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
4812 if (IS_FWI2_CAPABLE(ha)) {
4813 mid_init_cb->options = cpu_to_le16(BIT_1);
4814 mid_init_cb->init_cb.execution_throttle =
4815 cpu_to_le16(ha->cur_fw_xcb_count);
4816 ha->flags.dport_enabled =
4817 (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) &
4819 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
4820 (ha->flags.dport_enabled) ? "enabled" : "disabled");
4821 /* FA-WWPN Status */
4822 ha->flags.fawwpn_enabled =
4823 (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) &
4825 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
4826 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
4827 /* Init_cb will be reused for other command(s). Save a backup copy of port_name */
4828 memcpy(ha->port_name, ha->init_cb->port_name, WWN_SIZE);
4831 /* ELS pass through payload is limit by frame size. */
4832 if (ha->flags.edif_enabled)
4833 mid_init_cb->init_cb.frame_payload_size = cpu_to_le16(ELS_MAX_PAYLOAD);
4836 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
4840 ql_log(ql_log_fatal, vha, 0x00d2,
4841 "Init Firmware **** FAILED ****.\n");
4843 ql_dbg(ql_dbg_init, vha, 0x00d3,
4844 "Init Firmware -- success.\n");
4845 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0;
4852 * qla2x00_fw_ready() - Waits for firmware ready.
4855 * Returns 0 on success.
4858 qla2x00_fw_ready(scsi_qla_host_t *vha)
4861 unsigned long wtime, mtime, cs84xx_time;
4862 uint16_t min_wait; /* Minimum wait time if loop is down */
4863 uint16_t wait_time; /* Wait time if loop is coming ready */
4865 struct qla_hw_data *ha = vha->hw;
4867 if (IS_QLAFX00(vha->hw))
4868 return qlafx00_fw_ready(vha);
4870 /* Time to wait for loop down */
4871 if (IS_P3P_TYPE(ha))
4877 * Firmware should take at most one RATOV to login, plus 5 seconds for
4878 * our own processing.
4880 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
4881 wait_time = min_wait;
4884 /* Min wait time if loop down */
4885 mtime = jiffies + (min_wait * HZ);
4887 /* wait time before firmware ready */
4888 wtime = jiffies + (wait_time * HZ);
4890 /* Wait for ISP to finish LIP */
4891 if (!vha->flags.init_done)
4892 ql_log(ql_log_info, vha, 0x801e,
4893 "Waiting for LIP to complete.\n");
4896 memset(state, -1, sizeof(state));
4897 rval = qla2x00_get_firmware_state(vha, state);
4898 if (rval == QLA_SUCCESS) {
4899 if (state[0] < FSTATE_LOSS_OF_SYNC) {
4900 vha->device_flags &= ~DFLG_NO_CABLE;
4902 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
4903 ql_dbg(ql_dbg_taskm, vha, 0x801f,
4904 "fw_state=%x 84xx=%x.\n", state[0],
4906 if ((state[2] & FSTATE_LOGGED_IN) &&
4907 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
4908 ql_dbg(ql_dbg_taskm, vha, 0x8028,
4909 "Sending verify iocb.\n");
4911 cs84xx_time = jiffies;
4912 rval = qla84xx_init_chip(vha);
4913 if (rval != QLA_SUCCESS) {
4916 "Init chip failed.\n");
4920 /* Add time taken to initialize. */
4921 cs84xx_time = jiffies - cs84xx_time;
4922 wtime += cs84xx_time;
4923 mtime += cs84xx_time;
4924 ql_dbg(ql_dbg_taskm, vha, 0x8008,
4925 "Increasing wait time by %ld. "
4926 "New time %ld.\n", cs84xx_time,
4929 } else if (state[0] == FSTATE_READY) {
4930 ql_dbg(ql_dbg_taskm, vha, 0x8037,
4931 "F/W Ready - OK.\n");
4933 qla2x00_get_retry_cnt(vha, &ha->retry_count,
4934 &ha->login_timeout, &ha->r_a_tov);
4940 rval = QLA_FUNCTION_FAILED;
4942 if (atomic_read(&vha->loop_down_timer) &&
4943 state[0] != FSTATE_READY) {
4944 /* Loop down. Timeout on min_wait for states
4945 * other than Wait for Login.
4947 if (time_after_eq(jiffies, mtime)) {
4948 ql_log(ql_log_info, vha, 0x8038,
4949 "Cable is unplugged...\n");
4951 vha->device_flags |= DFLG_NO_CABLE;
4956 /* Mailbox cmd failed. Timeout on min_wait. */
4957 if (time_after_eq(jiffies, mtime) ||
4958 ha->flags.isp82xx_fw_hung)
4962 if (time_after_eq(jiffies, wtime))
4965 /* Delay for a while */
4969 ql_dbg(ql_dbg_taskm, vha, 0x803a,
4970 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
4971 state[1], state[2], state[3], state[4], state[5], jiffies);
4973 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
4974 ql_log(ql_log_warn, vha, 0x803b,
4975 "Firmware ready **** FAILED ****.\n");
4982 * qla2x00_configure_hba
4983 * Setup adapter context.
4986 * ha = adapter state pointer.
4995 qla2x00_configure_hba(scsi_qla_host_t *vha)
5004 char connect_type[22];
5005 struct qla_hw_data *ha = vha->hw;
5006 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5008 unsigned long flags;
5010 /* Get host addresses. */
5011 rval = qla2x00_get_adapter_id(vha,
5012 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
5013 if (rval != QLA_SUCCESS) {
5014 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
5015 IS_CNA_CAPABLE(ha) ||
5016 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
5017 ql_dbg(ql_dbg_disc, vha, 0x2008,
5018 "Loop is in a transition state.\n");
5020 ql_log(ql_log_warn, vha, 0x2009,
5021 "Unable to get host loop ID.\n");
5022 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
5023 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
5024 ql_log(ql_log_warn, vha, 0x1151,
5025 "Doing link init.\n");
5026 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
5029 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
5035 ql_log(ql_log_info, vha, 0x200a,
5036 "Cannot get topology - retrying.\n");
5037 return (QLA_FUNCTION_FAILED);
5040 vha->loop_id = loop_id;
5043 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
5044 ha->operating_mode = LOOP;
5048 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
5050 ha->current_topology = ISP_CFG_NL;
5051 strcpy(connect_type, "(Loop)");
5055 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
5056 ha->switch_cap = sw_cap;
5057 ha->current_topology = ISP_CFG_FL;
5058 strcpy(connect_type, "(FL_Port)");
5062 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
5064 ha->operating_mode = P2P;
5065 ha->current_topology = ISP_CFG_N;
5066 strcpy(connect_type, "(N_Port-to-N_Port)");
5070 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
5071 ha->switch_cap = sw_cap;
5072 ha->operating_mode = P2P;
5073 ha->current_topology = ISP_CFG_F;
5074 strcpy(connect_type, "(F_Port)");
5078 ql_dbg(ql_dbg_disc, vha, 0x200f,
5079 "HBA in unknown topology %x, using NL.\n", topo);
5081 ha->current_topology = ISP_CFG_NL;
5082 strcpy(connect_type, "(Loop)");
5086 /* Save Host port and loop ID. */
5087 /* byte order - Big Endian */
5088 id.b.domain = domain;
5092 spin_lock_irqsave(&ha->hardware_lock, flags);
5093 if (vha->hw->flags.edif_enabled) {
5095 qla_update_host_map(vha, id);
5096 } else if (!(topo == 2 && ha->flags.n2n_bigger))
5097 qla_update_host_map(vha, id);
5098 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5100 if (!vha->flags.init_done)
5101 ql_log(ql_log_info, vha, 0x2010,
5102 "Topology - %s, Host Loop address 0x%x.\n",
5103 connect_type, vha->loop_id);
5109 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
5114 uint64_t zero[2] = { 0 };
5115 struct qla_hw_data *ha = vha->hw;
5116 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
5117 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
5119 if (len > sizeof(zero))
5121 if (memcmp(model, &zero, len) != 0) {
5122 memcpy(ha->model_number, model, len);
5123 st = en = ha->model_number;
5126 if (*en != 0x20 && *en != 0x00)
5131 index = (ha->pdev->subsystem_device & 0xff);
5133 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
5134 index < QLA_MODEL_NAMES)
5135 strscpy(ha->model_desc,
5136 qla2x00_model_name[index * 2 + 1],
5137 sizeof(ha->model_desc));
5139 index = (ha->pdev->subsystem_device & 0xff);
5141 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
5142 index < QLA_MODEL_NAMES) {
5143 strscpy(ha->model_number,
5144 qla2x00_model_name[index * 2],
5145 sizeof(ha->model_number));
5146 strscpy(ha->model_desc,
5147 qla2x00_model_name[index * 2 + 1],
5148 sizeof(ha->model_desc));
5150 strscpy(ha->model_number, def,
5151 sizeof(ha->model_number));
5154 if (IS_FWI2_CAPABLE(ha))
5155 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
5156 sizeof(ha->model_desc));
5159 /* On sparc systems, obtain port and node WWN from firmware
5162 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
5165 struct qla_hw_data *ha = vha->hw;
5166 struct pci_dev *pdev = ha->pdev;
5167 struct device_node *dp = pci_device_to_OF_node(pdev);
5171 val = of_get_property(dp, "port-wwn", &len);
5172 if (val && len >= WWN_SIZE)
5173 memcpy(nv->port_name, val, WWN_SIZE);
5175 val = of_get_property(dp, "node-wwn", &len);
5176 if (val && len >= WWN_SIZE)
5177 memcpy(nv->node_name, val, WWN_SIZE);
5182 * NVRAM configuration for ISP 2xxx
5185 * ha = adapter block pointer.
5188 * initialization control block in response_ring
5189 * host adapters parameters in host adapter block
5195 qla2x00_nvram_config(scsi_qla_host_t *vha)
5200 uint8_t *dptr1, *dptr2;
5201 struct qla_hw_data *ha = vha->hw;
5202 init_cb_t *icb = ha->init_cb;
5203 nvram_t *nv = ha->nvram;
5204 uint8_t *ptr = ha->nvram;
5205 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
5209 /* Determine NVRAM starting address. */
5210 ha->nvram_size = sizeof(*nv);
5212 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
5213 if ((rd_reg_word(®->ctrl_status) >> 14) == 1)
5214 ha->nvram_base = 0x80;
5216 /* Get NVRAM data and calculate checksum. */
5217 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
5218 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
5221 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
5222 "Contents of NVRAM.\n");
5223 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
5224 nv, ha->nvram_size);
5226 /* Bad NVRAM data, set defaults parameters. */
5227 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
5228 nv->nvram_version < 1) {
5229 /* Reset NVRAM data. */
5230 ql_log(ql_log_warn, vha, 0x0064,
5231 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
5232 chksum, nv->id, nv->nvram_version);
5233 ql_log(ql_log_warn, vha, 0x0065,
5235 "functioning (yet invalid -- WWPN) defaults.\n");
5238 * Set default initialization control block.
5240 memset(nv, 0, ha->nvram_size);
5241 nv->parameter_block_version = ICB_VERSION;
5243 if (IS_QLA23XX(ha)) {
5244 nv->firmware_options[0] = BIT_2 | BIT_1;
5245 nv->firmware_options[1] = BIT_7 | BIT_5;
5246 nv->add_firmware_options[0] = BIT_5;
5247 nv->add_firmware_options[1] = BIT_5 | BIT_4;
5248 nv->frame_payload_size = cpu_to_le16(2048);
5249 nv->special_options[1] = BIT_7;
5250 } else if (IS_QLA2200(ha)) {
5251 nv->firmware_options[0] = BIT_2 | BIT_1;
5252 nv->firmware_options[1] = BIT_7 | BIT_5;
5253 nv->add_firmware_options[0] = BIT_5;
5254 nv->add_firmware_options[1] = BIT_5 | BIT_4;
5255 nv->frame_payload_size = cpu_to_le16(1024);
5256 } else if (IS_QLA2100(ha)) {
5257 nv->firmware_options[0] = BIT_3 | BIT_1;
5258 nv->firmware_options[1] = BIT_5;
5259 nv->frame_payload_size = cpu_to_le16(1024);
5262 nv->max_iocb_allocation = cpu_to_le16(256);
5263 nv->execution_throttle = cpu_to_le16(16);
5264 nv->retry_count = 8;
5265 nv->retry_delay = 1;
5267 nv->port_name[0] = 33;
5268 nv->port_name[3] = 224;
5269 nv->port_name[4] = 139;
5271 qla2xxx_nvram_wwn_from_ofw(vha, nv);
5273 nv->login_timeout = 4;
5276 * Set default host adapter parameters
5278 nv->host_p[1] = BIT_2;
5279 nv->reset_delay = 5;
5280 nv->port_down_retry_count = 8;
5281 nv->max_luns_per_target = cpu_to_le16(8);
5282 nv->link_down_timeout = 60;
5287 /* Reset Initialization control block */
5288 memset(icb, 0, ha->init_cb_size);
5291 * Setup driver NVRAM options.
5293 nv->firmware_options[0] |= (BIT_6 | BIT_1);
5294 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
5295 nv->firmware_options[1] |= (BIT_5 | BIT_0);
5296 nv->firmware_options[1] &= ~BIT_4;
5298 if (IS_QLA23XX(ha)) {
5299 nv->firmware_options[0] |= BIT_2;
5300 nv->firmware_options[0] &= ~BIT_3;
5301 nv->special_options[0] &= ~BIT_6;
5302 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
5304 if (IS_QLA2300(ha)) {
5305 if (ha->fb_rev == FPM_2310) {
5306 strcpy(ha->model_number, "QLA2310");
5308 strcpy(ha->model_number, "QLA2300");
5311 qla2x00_set_model_info(vha, nv->model_number,
5312 sizeof(nv->model_number), "QLA23xx");
5314 } else if (IS_QLA2200(ha)) {
5315 nv->firmware_options[0] |= BIT_2;
5317 * 'Point-to-point preferred, else loop' is not a safe
5318 * connection mode setting.
5320 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
5322 /* Force 'loop preferred, else point-to-point'. */
5323 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
5324 nv->add_firmware_options[0] |= BIT_5;
5326 strcpy(ha->model_number, "QLA22xx");
5327 } else /*if (IS_QLA2100(ha))*/ {
5328 strcpy(ha->model_number, "QLA2100");
5332 * Copy over NVRAM RISC parameter block to initialization control block.
5334 dptr1 = (uint8_t *)icb;
5335 dptr2 = (uint8_t *)&nv->parameter_block_version;
5336 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
5338 *dptr1++ = *dptr2++;
5340 /* Copy 2nd half. */
5341 dptr1 = (uint8_t *)icb->add_firmware_options;
5342 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
5344 *dptr1++ = *dptr2++;
5345 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
5346 /* Use alternate WWN? */
5347 if (nv->host_p[1] & BIT_7) {
5348 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5349 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5352 /* Prepare nodename */
5353 if ((icb->firmware_options[1] & BIT_6) == 0) {
5355 * Firmware will apply the following mask if the nodename was
5358 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5359 icb->node_name[0] &= 0xF0;
5363 * Set host adapter parameters.
5367 * BIT_7 in the host-parameters section allows for modification to
5368 * internal driver logging.
5370 if (nv->host_p[0] & BIT_7)
5371 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
5372 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
5373 /* Always load RISC code on non ISP2[12]00 chips. */
5374 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
5375 ha->flags.disable_risc_code_load = 0;
5376 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
5377 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
5378 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
5379 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
5380 ha->flags.disable_serdes = 0;
5382 ha->operating_mode =
5383 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
5385 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
5386 sizeof(ha->fw_seriallink_options));
5388 /* save HBA serial number */
5389 ha->serial0 = icb->port_name[5];
5390 ha->serial1 = icb->port_name[6];
5391 ha->serial2 = icb->port_name[7];
5392 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5393 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5395 icb->execution_throttle = cpu_to_le16(0xFFFF);
5397 ha->retry_count = nv->retry_count;
5399 /* Set minimum login_timeout to 4 seconds. */
5400 if (nv->login_timeout != ql2xlogintimeout)
5401 nv->login_timeout = ql2xlogintimeout;
5402 if (nv->login_timeout < 4)
5403 nv->login_timeout = 4;
5404 ha->login_timeout = nv->login_timeout;
5406 /* Set minimum RATOV to 100 tenths of a second. */
5409 ha->loop_reset_delay = nv->reset_delay;
5411 /* Link Down Timeout = 0:
5413 * When Port Down timer expires we will start returning
5414 * I/O's to OS with "DID_NO_CONNECT".
5416 * Link Down Timeout != 0:
5418 * The driver waits for the link to come up after link down
5419 * before returning I/Os to OS with "DID_NO_CONNECT".
5421 if (nv->link_down_timeout == 0) {
5422 ha->loop_down_abort_time =
5423 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5425 ha->link_down_timeout = nv->link_down_timeout;
5426 ha->loop_down_abort_time =
5427 (LOOP_DOWN_TIME - ha->link_down_timeout);
5431 * Need enough time to try and get the port back.
5433 ha->port_down_retry_count = nv->port_down_retry_count;
5434 if (qlport_down_retry)
5435 ha->port_down_retry_count = qlport_down_retry;
5436 /* Set login_retry_count */
5437 ha->login_retry_count = nv->retry_count;
5438 if (ha->port_down_retry_count == nv->port_down_retry_count &&
5439 ha->port_down_retry_count > 3)
5440 ha->login_retry_count = ha->port_down_retry_count;
5441 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5442 ha->login_retry_count = ha->port_down_retry_count;
5443 if (ql2xloginretrycount)
5444 ha->login_retry_count = ql2xloginretrycount;
5446 icb->lun_enables = cpu_to_le16(0);
5447 icb->command_resource_count = 0;
5448 icb->immediate_notify_resource_count = 0;
5449 icb->timeout = cpu_to_le16(0);
5451 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
5453 icb->firmware_options[0] &= ~BIT_3;
5454 icb->add_firmware_options[0] &=
5455 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
5456 icb->add_firmware_options[0] |= BIT_2;
5457 icb->response_accumulation_timer = 3;
5458 icb->interrupt_delay_timer = 5;
5460 vha->flags.process_response_queue = 1;
5463 if (!vha->flags.init_done) {
5464 ha->zio_mode = icb->add_firmware_options[0] &
5465 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5466 ha->zio_timer = icb->interrupt_delay_timer ?
5467 icb->interrupt_delay_timer : 2;
5469 icb->add_firmware_options[0] &=
5470 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
5471 vha->flags.process_response_queue = 0;
5472 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5473 ha->zio_mode = QLA_ZIO_MODE_6;
5475 ql_log(ql_log_info, vha, 0x0068,
5476 "ZIO mode %d enabled; timer delay (%d us).\n",
5477 ha->zio_mode, ha->zio_timer * 100);
5479 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
5480 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
5481 vha->flags.process_response_queue = 1;
5486 ql_log(ql_log_warn, vha, 0x0069,
5487 "NVRAM configuration failed.\n");
5492 void qla2x00_set_fcport_state(fc_port_t *fcport, int state)
5496 old_state = atomic_read(&fcport->state);
5497 atomic_set(&fcport->state, state);
5499 /* Don't print state transitions during initial allocation of fcport */
5500 if (old_state && old_state != state) {
5501 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
5502 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
5503 fcport->port_name, port_state_str[old_state],
5504 port_state_str[state], fcport->d_id.b.domain,
5505 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5510 * qla2x00_alloc_fcport() - Allocate a generic fcport.
5512 * @flags: allocation flags
5514 * Returns a pointer to the allocated fcport, or NULL, if none available.
5517 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
5521 fcport = kzalloc(sizeof(fc_port_t), flags);
5525 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
5526 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
5528 if (!fcport->ct_desc.ct_sns) {
5529 ql_log(ql_log_warn, vha, 0xd049,
5530 "Failed to allocate ct_sns request.\n");
5535 /* Setup fcport template structure. */
5537 fcport->port_type = FCT_UNKNOWN;
5538 fcport->loop_id = FC_NO_LOOP_ID;
5539 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
5540 fcport->supported_classes = FC_COS_UNSPECIFIED;
5541 fcport->fp_speed = PORT_SPEED_UNKNOWN;
5543 fcport->disc_state = DSC_DELETED;
5544 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
5545 fcport->deleted = QLA_SESS_DELETED;
5546 fcport->login_retry = vha->hw->login_retry_count;
5547 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
5548 fcport->logout_on_delete = 1;
5549 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
5550 fcport->tgt_short_link_down_cnt = 0;
5551 fcport->dev_loss_tmo = 0;
5553 if (!fcport->ct_desc.ct_sns) {
5554 ql_log(ql_log_warn, vha, 0xd049,
5555 "Failed to allocate ct_sns request.\n");
5560 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
5561 INIT_WORK(&fcport->free_work, qlt_free_session_done);
5562 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
5563 INIT_LIST_HEAD(&fcport->gnl_entry);
5564 INIT_LIST_HEAD(&fcport->list);
5565 INIT_LIST_HEAD(&fcport->unsol_ctx_head);
5567 INIT_LIST_HEAD(&fcport->sess_cmd_list);
5568 spin_lock_init(&fcport->sess_cmd_lock);
5570 spin_lock_init(&fcport->edif.sa_list_lock);
5571 INIT_LIST_HEAD(&fcport->edif.tx_sa_list);
5572 INIT_LIST_HEAD(&fcport->edif.rx_sa_list);
5574 spin_lock_init(&fcport->edif.indx_list_lock);
5575 INIT_LIST_HEAD(&fcport->edif.edif_indx_list);
5581 qla2x00_free_fcport(fc_port_t *fcport)
5583 if (fcport->ct_desc.ct_sns) {
5584 dma_free_coherent(&fcport->vha->hw->pdev->dev,
5585 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
5586 fcport->ct_desc.ct_sns_dma);
5588 fcport->ct_desc.ct_sns = NULL;
5591 qla_edif_flush_sa_ctl_lists(fcport);
5592 list_del(&fcport->list);
5593 qla2x00_clear_loop_id(fcport);
5595 qla_edif_list_del(fcport);
5600 static void qla_get_login_template(scsi_qla_host_t *vha)
5602 struct qla_hw_data *ha = vha->hw;
5607 memset(ha->init_cb, 0, ha->init_cb_size);
5608 sz = min_t(int, sizeof(struct fc_els_csp), ha->init_cb_size);
5609 rval = qla24xx_get_port_login_templ(vha, ha->init_cb_dma,
5611 if (rval != QLA_SUCCESS) {
5612 ql_dbg(ql_dbg_init, vha, 0x00d1,
5613 "PLOGI ELS param read fail.\n");
5616 q = (__be32 *)&ha->plogi_els_payld.fl_csp;
5618 bp = (uint32_t *)ha->init_cb;
5619 cpu_to_be32_array(q, bp, sz / 4);
5620 ha->flags.plogi_template_valid = 1;
5624 * qla2x00_configure_loop
5625 * Updates Fibre Channel Device Database with what is actually on loop.
5628 * ha = adapter block pointer.
5633 * 2 = database was full and device was not configured.
5636 qla2x00_configure_loop(scsi_qla_host_t *vha)
5639 unsigned long flags, save_flags;
5640 struct qla_hw_data *ha = vha->hw;
5644 /* Get Initiator ID */
5645 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
5646 rval = qla2x00_configure_hba(vha);
5647 if (rval != QLA_SUCCESS) {
5648 ql_dbg(ql_dbg_disc, vha, 0x2013,
5649 "Unable to configure HBA.\n");
5654 save_flags = flags = vha->dpc_flags;
5655 ql_dbg(ql_dbg_disc, vha, 0x2014,
5656 "Configure loop -- dpc flags = 0x%lx.\n", flags);
5659 * If we have both an RSCN and PORT UPDATE pending then handle them
5660 * both at the same time.
5662 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5663 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
5665 qla2x00_get_data_rate(vha);
5666 qla_get_login_template(vha);
5668 /* Determine what we need to do */
5669 if ((ha->current_topology == ISP_CFG_FL ||
5670 ha->current_topology == ISP_CFG_F) &&
5671 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
5673 set_bit(RSCN_UPDATE, &flags);
5674 clear_bit(LOCAL_LOOP_UPDATE, &flags);
5676 } else if (ha->current_topology == ISP_CFG_NL ||
5677 ha->current_topology == ISP_CFG_N) {
5678 clear_bit(RSCN_UPDATE, &flags);
5679 set_bit(LOCAL_LOOP_UPDATE, &flags);
5680 } else if (!vha->flags.online ||
5681 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
5682 set_bit(RSCN_UPDATE, &flags);
5683 set_bit(LOCAL_LOOP_UPDATE, &flags);
5686 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
5687 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5688 ql_dbg(ql_dbg_disc, vha, 0x2015,
5689 "Loop resync needed, failing.\n");
5690 rval = QLA_FUNCTION_FAILED;
5692 rval = qla2x00_configure_local_loop(vha);
5695 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
5696 if (LOOP_TRANSITION(vha)) {
5697 ql_dbg(ql_dbg_disc, vha, 0x2099,
5698 "Needs RSCN update and loop transition.\n");
5699 rval = QLA_FUNCTION_FAILED;
5702 rval = qla2x00_configure_fabric(vha);
5705 if (rval == QLA_SUCCESS) {
5706 if (atomic_read(&vha->loop_down_timer) ||
5707 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5708 rval = QLA_FUNCTION_FAILED;
5710 atomic_set(&vha->loop_state, LOOP_READY);
5711 ql_dbg(ql_dbg_disc, vha, 0x2069,
5713 ha->flags.fw_init_done = 1;
5716 * use link up to wake up app to get ready for
5719 if (ha->flags.edif_enabled && DBELL_INACTIVE(vha))
5720 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP,
5721 ha->link_data_rate);
5724 * Process any ATIO queue entries that came in
5725 * while we weren't online.
5727 if (qla_tgt_mode_enabled(vha) ||
5728 qla_dual_mode_enabled(vha)) {
5729 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
5730 qlt_24xx_process_atio_queue(vha, 0);
5731 spin_unlock_irqrestore(&ha->tgt.atio_lock,
5738 ql_dbg(ql_dbg_disc, vha, 0x206a,
5739 "%s *** FAILED ***.\n", __func__);
5741 ql_dbg(ql_dbg_disc, vha, 0x206b,
5742 "%s: exiting normally. local port wwpn %8phN id %06x)\n",
5743 __func__, vha->port_name, vha->d_id.b24);
5746 /* Restore state if a resync event occurred during processing */
5747 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5748 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
5749 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5750 if (test_bit(RSCN_UPDATE, &save_flags)) {
5751 set_bit(RSCN_UPDATE, &vha->dpc_flags);
5758 static int qla2x00_configure_n2n_loop(scsi_qla_host_t *vha)
5760 unsigned long flags;
5763 ql_dbg(ql_dbg_disc, vha, 0x206a, "%s %d.\n", __func__, __LINE__);
5765 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags))
5766 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5768 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5769 if (fcport->n2n_flag) {
5770 qla24xx_fcport_handle_login(vha, fcport);
5775 spin_lock_irqsave(&vha->work_lock, flags);
5776 vha->scan.scan_retry++;
5777 spin_unlock_irqrestore(&vha->work_lock, flags);
5779 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5780 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5781 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5783 return QLA_FUNCTION_FAILED;
5787 qla_reinitialize_link(scsi_qla_host_t *vha)
5791 atomic_set(&vha->loop_state, LOOP_DOWN);
5792 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
5793 rval = qla2x00_full_login_lip(vha);
5794 if (rval == QLA_SUCCESS) {
5795 ql_dbg(ql_dbg_disc, vha, 0xd050, "Link reinitialized\n");
5797 ql_dbg(ql_dbg_disc, vha, 0xd051,
5798 "Link reinitialization failed (%d)\n", rval);
5803 * qla2x00_configure_local_loop
5804 * Updates Fibre Channel Device Database with local loop devices.
5807 * ha = adapter block pointer.
5813 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
5817 fc_port_t *fcport, *new_fcport;
5820 struct gid_list_info *gid;
5822 uint8_t domain, area, al_pa;
5823 struct qla_hw_data *ha = vha->hw;
5824 unsigned long flags;
5826 /* Inititae N2N login. */
5828 return qla2x00_configure_n2n_loop(vha);
5831 entries = MAX_FIBRE_DEVICES_LOOP;
5833 /* Get list of logged in devices. */
5834 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
5835 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
5837 if (rval != QLA_SUCCESS)
5840 ql_dbg(ql_dbg_disc, vha, 0x2011,
5841 "Entries in ID list (%d).\n", entries);
5842 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
5843 ha->gid_list, entries * sizeof(*ha->gid_list));
5846 spin_lock_irqsave(&vha->work_lock, flags);
5847 vha->scan.scan_retry++;
5848 spin_unlock_irqrestore(&vha->work_lock, flags);
5850 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5851 u8 loop_map_entries = 0;
5854 rc = qla2x00_get_fcal_position_map(vha, NULL,
5856 if (rc == QLA_SUCCESS && loop_map_entries > 1) {
5858 * There are devices that are still not logged
5859 * in. Reinitialize to give them a chance.
5861 qla_reinitialize_link(vha);
5862 return QLA_FUNCTION_FAILED;
5864 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5865 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5868 vha->scan.scan_retry = 0;
5871 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5872 fcport->scan_state = QLA_FCPORT_SCAN;
5875 /* Allocate temporary fcport for any new fcports discovered. */
5876 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5877 if (new_fcport == NULL) {
5878 ql_log(ql_log_warn, vha, 0x2012,
5879 "Memory allocation failed for fcport.\n");
5880 rval = QLA_MEMORY_ALLOC_FAILED;
5883 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5885 /* Add devices to port list. */
5887 for (index = 0; index < entries; index++) {
5888 domain = gid->domain;
5891 if (IS_QLA2100(ha) || IS_QLA2200(ha))
5892 loop_id = gid->loop_id_2100;
5894 loop_id = le16_to_cpu(gid->loop_id);
5895 gid = (void *)gid + ha->gid_list_info_size;
5897 /* Bypass reserved domain fields. */
5898 if ((domain & 0xf0) == 0xf0)
5901 /* Bypass if not same domain and area of adapter. */
5902 if (area && domain && ((area != vha->d_id.b.area) ||
5903 (domain != vha->d_id.b.domain)) &&
5904 (ha->current_topology == ISP_CFG_NL))
5908 /* Bypass invalid local loop ID. */
5909 if (loop_id > LAST_LOCAL_LOOP_ID)
5912 memset(new_fcport->port_name, 0, WWN_SIZE);
5914 /* Fill in member data. */
5915 new_fcport->d_id.b.domain = domain;
5916 new_fcport->d_id.b.area = area;
5917 new_fcport->d_id.b.al_pa = al_pa;
5918 new_fcport->loop_id = loop_id;
5919 new_fcport->scan_state = QLA_FCPORT_FOUND;
5921 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
5922 if (rval2 != QLA_SUCCESS) {
5923 ql_dbg(ql_dbg_disc, vha, 0x2097,
5924 "Failed to retrieve fcport information "
5925 "-- get_port_database=%x, loop_id=0x%04x.\n",
5926 rval2, new_fcport->loop_id);
5927 /* Skip retry if N2N */
5928 if (ha->current_topology != ISP_CFG_N) {
5929 ql_dbg(ql_dbg_disc, vha, 0x2105,
5930 "Scheduling resync.\n");
5931 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5936 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5937 /* Check for matching device in port list. */
5940 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5941 if (memcmp(new_fcport->port_name, fcport->port_name,
5945 fcport->flags &= ~FCF_FABRIC_DEVICE;
5946 fcport->loop_id = new_fcport->loop_id;
5947 fcport->port_type = new_fcport->port_type;
5948 fcport->d_id.b24 = new_fcport->d_id.b24;
5949 memcpy(fcport->node_name, new_fcport->node_name,
5951 fcport->scan_state = QLA_FCPORT_FOUND;
5952 if (fcport->login_retry == 0) {
5953 fcport->login_retry = vha->hw->login_retry_count;
5954 ql_dbg(ql_dbg_disc, vha, 0x2135,
5955 "Port login retry %8phN, lid 0x%04x retry cnt=%d.\n",
5956 fcport->port_name, fcport->loop_id,
5957 fcport->login_retry);
5964 /* New device, add to fcports list. */
5965 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5967 /* Allocate a new replacement fcport. */
5968 fcport = new_fcport;
5970 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5972 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5974 if (new_fcport == NULL) {
5975 ql_log(ql_log_warn, vha, 0xd031,
5976 "Failed to allocate memory for fcport.\n");
5977 rval = QLA_MEMORY_ALLOC_FAILED;
5980 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5981 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5984 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5986 /* Base iIDMA settings on HBA port speed. */
5987 fcport->fp_speed = ha->link_data_rate;
5990 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5991 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5994 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5995 if ((qla_dual_mode_enabled(vha) ||
5996 qla_ini_mode_enabled(vha)) &&
5997 atomic_read(&fcport->state) == FCS_ONLINE) {
5998 qla2x00_mark_device_lost(vha, fcport,
5999 ql2xplogiabsentdevice);
6000 if (fcport->loop_id != FC_NO_LOOP_ID &&
6001 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
6002 fcport->port_type != FCT_INITIATOR &&
6003 fcport->port_type != FCT_BROADCAST) {
6004 ql_dbg(ql_dbg_disc, vha, 0x20f0,
6005 "%s %d %8phC post del sess\n",
6009 qlt_schedule_sess_for_deletion(fcport);
6015 if (fcport->scan_state == QLA_FCPORT_FOUND)
6016 qla24xx_fcport_handle_login(vha, fcport);
6019 qla2x00_free_fcport(new_fcport);
6024 ql_dbg(ql_dbg_disc, vha, 0x2098,
6025 "Configure local loop error exit: rval=%x.\n", rval);
6030 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
6033 uint16_t mb[MAILBOX_REGISTER_COUNT];
6034 struct qla_hw_data *ha = vha->hw;
6036 if (!IS_IIDMA_CAPABLE(ha))
6039 if (atomic_read(&fcport->state) != FCS_ONLINE)
6042 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
6043 fcport->fp_speed > ha->link_data_rate ||
6044 !ha->flags.gpsc_supported)
6047 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
6049 if (rval != QLA_SUCCESS) {
6050 ql_dbg(ql_dbg_disc, vha, 0x2004,
6051 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
6052 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
6054 ql_dbg(ql_dbg_disc, vha, 0x2005,
6055 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
6056 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
6057 fcport->fp_speed, fcport->port_name);
6061 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
6063 qla2x00_iidma_fcport(vha, fcport);
6064 qla24xx_update_fcport_fcp_prio(vha, fcport);
6067 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
6069 struct qla_work_evt *e;
6071 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
6073 return QLA_FUNCTION_FAILED;
6075 e->u.fcport.fcport = fcport;
6076 return qla2x00_post_work(vha, e);
6079 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
6081 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
6083 struct fc_rport_identifiers rport_ids;
6084 struct fc_rport *rport;
6085 unsigned long flags;
6087 if (atomic_read(&fcport->state) == FCS_ONLINE)
6090 rport_ids.node_name = wwn_to_u64(fcport->node_name);
6091 rport_ids.port_name = wwn_to_u64(fcport->port_name);
6092 rport_ids.port_id = fcport->d_id.b.domain << 16 |
6093 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
6094 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
6095 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
6097 ql_log(ql_log_warn, vha, 0x2006,
6098 "Unable to allocate fc remote port.\n");
6102 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
6103 *((fc_port_t **)rport->dd_data) = fcport;
6104 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
6105 fcport->dev_loss_tmo = rport->dev_loss_tmo;
6107 rport->supported_classes = fcport->supported_classes;
6109 rport_ids.roles = FC_PORT_ROLE_UNKNOWN;
6110 if (fcport->port_type == FCT_INITIATOR)
6111 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
6112 if (fcport->port_type == FCT_TARGET)
6113 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
6114 if (fcport->port_type & FCT_NVME_INITIATOR)
6115 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
6116 if (fcport->port_type & FCT_NVME_TARGET)
6117 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
6118 if (fcport->port_type & FCT_NVME_DISCOVERY)
6119 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
6121 fc_remote_port_rolechg(rport, rport_ids.roles);
6123 ql_dbg(ql_dbg_disc, vha, 0x20ee,
6124 "%s: %8phN. rport %ld:0:%d (%p) is %s mode\n",
6125 __func__, fcport->port_name, vha->host_no,
6126 rport->scsi_target_id, rport,
6127 (fcport->port_type == FCT_TARGET) ? "tgt" :
6128 ((fcport->port_type & FCT_NVME) ? "nvme" : "ini"));
6132 * qla2x00_update_fcport
6133 * Updates device on list.
6136 * ha = adapter block pointer.
6137 * fcport = port structure pointer.
6147 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
6149 unsigned long flags;
6151 if (IS_SW_RESV_ADDR(fcport->d_id))
6154 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
6155 __func__, fcport->port_name);
6157 qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT);
6158 fcport->login_retry = vha->hw->login_retry_count;
6159 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6161 spin_lock_irqsave(&vha->work_lock, flags);
6162 fcport->deleted = 0;
6163 spin_unlock_irqrestore(&vha->work_lock, flags);
6165 if (vha->hw->current_topology == ISP_CFG_NL)
6166 fcport->logout_on_delete = 0;
6168 fcport->logout_on_delete = 1;
6169 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
6171 if (fcport->tgt_link_down_time < fcport->dev_loss_tmo) {
6172 fcport->tgt_short_link_down_cnt++;
6173 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
6176 switch (vha->hw->current_topology) {
6179 fcport->keep_nport_handle = 1;
6185 qla2x00_iidma_fcport(vha, fcport);
6187 qla2x00_dfs_create_rport(vha, fcport);
6189 qla24xx_update_fcport_fcp_prio(vha, fcport);
6191 switch (vha->host->active_mode) {
6192 case MODE_INITIATOR:
6193 qla2x00_reg_remote_port(vha, fcport);
6196 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
6197 !vha->vha_tgt.qla_tgt->tgt_stopped)
6198 qlt_fc_port_added(vha, fcport);
6201 qla2x00_reg_remote_port(vha, fcport);
6202 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
6203 !vha->vha_tgt.qla_tgt->tgt_stopped)
6204 qlt_fc_port_added(vha, fcport);
6210 if (NVME_TARGET(vha->hw, fcport))
6211 qla_nvme_register_remote(vha, fcport);
6213 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
6215 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
6216 if (fcport->id_changed) {
6217 fcport->id_changed = 0;
6218 ql_dbg(ql_dbg_disc, vha, 0x20d7,
6219 "%s %d %8phC post gfpnid fcp_cnt %d\n",
6220 __func__, __LINE__, fcport->port_name,
6222 qla24xx_post_gfpnid_work(vha, fcport);
6224 ql_dbg(ql_dbg_disc, vha, 0x20d7,
6225 "%s %d %8phC post gpsc fcp_cnt %d\n",
6226 __func__, __LINE__, fcport->port_name,
6228 qla24xx_post_gpsc_work(vha, fcport);
6232 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
6235 void qla_register_fcport_fn(struct work_struct *work)
6237 fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
6238 u32 rscn_gen = fcport->rscn_gen;
6241 if (IS_SW_RESV_ADDR(fcport->d_id))
6244 qla2x00_update_fcport(fcport->vha, fcport);
6246 ql_dbg(ql_dbg_disc, fcport->vha, 0x911e,
6247 "%s rscn gen %d/%d next DS %d\n", __func__,
6248 rscn_gen, fcport->rscn_gen, fcport->next_disc_state);
6250 if (rscn_gen != fcport->rscn_gen) {
6251 /* RSCN(s) came in while registration */
6252 switch (fcport->next_disc_state) {
6253 case DSC_DELETE_PEND:
6254 qlt_schedule_sess_for_deletion(fcport);
6257 data[0] = data[1] = 0;
6258 qla2x00_post_async_adisc_work(fcport->vha, fcport,
6268 * qla2x00_configure_fabric
6269 * Setup SNS devices with loop ID's.
6272 * ha = adapter block pointer.
6279 qla2x00_configure_fabric(scsi_qla_host_t *vha)
6283 uint16_t mb[MAILBOX_REGISTER_COUNT];
6285 struct qla_hw_data *ha = vha->hw;
6288 /* If FL port exists, then SNS is present */
6289 if (IS_FWI2_CAPABLE(ha))
6290 loop_id = NPH_F_PORT;
6292 loop_id = SNS_FL_PORT;
6293 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
6294 if (rval != QLA_SUCCESS) {
6295 ql_dbg(ql_dbg_disc, vha, 0x20a0,
6296 "MBX_GET_PORT_NAME failed, No FL Port.\n");
6298 vha->device_flags &= ~SWITCH_FOUND;
6299 return (QLA_SUCCESS);
6301 vha->device_flags |= SWITCH_FOUND;
6303 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_port_name, 0);
6304 if (rval != QLA_SUCCESS)
6305 ql_dbg(ql_dbg_disc, vha, 0x20ff,
6306 "Failed to get Fabric Port Name\n");
6308 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
6309 rval = qla2x00_send_change_request(vha, 0x3, 0);
6310 if (rval != QLA_SUCCESS)
6311 ql_log(ql_log_warn, vha, 0x121,
6312 "Failed to enable receiving of RSCN requests: 0x%x.\n",
6317 qla2x00_mgmt_svr_login(vha);
6319 /* Ensure we are logged into the SNS. */
6320 loop_id = NPH_SNS_LID(ha);
6321 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
6322 0xfc, mb, BIT_1|BIT_0);
6323 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
6324 ql_dbg(ql_dbg_disc, vha, 0x20a1,
6325 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
6326 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
6327 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6332 if (ql2xfdmienable &&
6333 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
6334 qla2x00_fdmi_register(vha);
6336 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
6337 if (qla2x00_rft_id(vha)) {
6339 ql_dbg(ql_dbg_disc, vha, 0x20a2,
6340 "Register FC-4 TYPE failed.\n");
6341 if (test_bit(LOOP_RESYNC_NEEDED,
6345 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
6347 ql_dbg(ql_dbg_disc, vha, 0x209a,
6348 "Register FC-4 Features failed.\n");
6349 if (test_bit(LOOP_RESYNC_NEEDED,
6353 if (vha->flags.nvme_enabled) {
6354 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
6355 ql_dbg(ql_dbg_disc, vha, 0x2049,
6356 "Register NVME FC Type Features failed.\n");
6359 if (qla2x00_rnn_id(vha)) {
6361 ql_dbg(ql_dbg_disc, vha, 0x2104,
6362 "Register Node Name failed.\n");
6363 if (test_bit(LOOP_RESYNC_NEEDED,
6366 } else if (qla2x00_rsnn_nn(vha)) {
6368 ql_dbg(ql_dbg_disc, vha, 0x209b,
6369 "Register Symbolic Node Name failed.\n");
6370 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6376 /* Mark the time right before querying FW for connected ports.
6377 * This process is long, asynchronous and by the time it's done,
6378 * collected information might not be accurate anymore. E.g.
6379 * disconnected port might have re-connected and a brand new
6380 * session has been created. In this case session's generation
6381 * will be newer than discovery_gen. */
6382 qlt_do_generation_tick(vha, &discovery_gen);
6384 if (USE_ASYNC_SCAN(ha)) {
6385 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
6388 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6390 list_for_each_entry(fcport, &vha->vp_fcports, list)
6391 fcport->scan_state = QLA_FCPORT_SCAN;
6393 rval = qla2x00_find_all_fabric_devs(vha);
6395 if (rval != QLA_SUCCESS)
6399 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
6400 qla_nvme_register_hba(vha);
6403 ql_dbg(ql_dbg_disc, vha, 0x2068,
6404 "Configure fabric error exit rval=%d.\n", rval);
6410 * qla2x00_find_all_fabric_devs
6413 * ha = adapter block pointer.
6414 * dev = database device entry pointer.
6423 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
6427 fc_port_t *fcport, *new_fcport;
6432 int first_dev, last_dev;
6433 port_id_t wrap = {}, nxt_d_id;
6434 struct qla_hw_data *ha = vha->hw;
6435 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6436 unsigned long flags;
6440 /* Try GID_PT to get device list, else GAN. */
6442 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
6447 ql_dbg(ql_dbg_disc, vha, 0x209c,
6448 "GID_PT allocations failed, fallback on GA_NXT.\n");
6450 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
6451 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
6453 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6455 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
6457 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6459 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
6461 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6463 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
6465 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6469 /* If other queries succeeded probe for FC-4 type */
6471 qla2x00_gff_id(vha, swl);
6472 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6478 /* Allocate temporary fcport for any new fcports discovered. */
6479 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
6480 if (new_fcport == NULL) {
6481 ql_log(ql_log_warn, vha, 0x209d,
6482 "Failed to allocate memory for fcport.\n");
6483 return (QLA_MEMORY_ALLOC_FAILED);
6485 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
6486 /* Set start port ID scan at adapter ID. */
6490 /* Starting free loop ID. */
6491 loop_id = ha->min_external_loopid;
6492 for (; loop_id <= ha->max_loop_id; loop_id++) {
6493 if (qla2x00_is_reserved_id(vha, loop_id))
6496 if (ha->current_topology == ISP_CFG_FL &&
6497 (atomic_read(&vha->loop_down_timer) ||
6498 LOOP_TRANSITION(vha))) {
6499 atomic_set(&vha->loop_down_timer, 0);
6500 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6501 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
6507 wrap.b24 = new_fcport->d_id.b24;
6509 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
6510 memcpy(new_fcport->node_name,
6511 swl[swl_idx].node_name, WWN_SIZE);
6512 memcpy(new_fcport->port_name,
6513 swl[swl_idx].port_name, WWN_SIZE);
6514 memcpy(new_fcport->fabric_port_name,
6515 swl[swl_idx].fabric_port_name, WWN_SIZE);
6516 new_fcport->fp_speed = swl[swl_idx].fp_speed;
6517 new_fcport->fc4_type = swl[swl_idx].fc4_type;
6519 new_fcport->nvme_flag = 0;
6520 if (vha->flags.nvme_enabled &&
6521 swl[swl_idx].fc4_type & FS_FC4TYPE_NVME) {
6522 ql_log(ql_log_info, vha, 0x2131,
6523 "FOUND: NVME port %8phC as FC Type 28h\n",
6524 new_fcport->port_name);
6527 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
6533 /* Send GA_NXT to the switch */
6534 rval = qla2x00_ga_nxt(vha, new_fcport);
6535 if (rval != QLA_SUCCESS) {
6536 ql_log(ql_log_warn, vha, 0x209e,
6537 "SNS scan failed -- assuming "
6538 "zero-entry result.\n");
6544 /* If wrap on switch device list, exit. */
6546 wrap.b24 = new_fcport->d_id.b24;
6548 } else if (new_fcport->d_id.b24 == wrap.b24) {
6549 ql_dbg(ql_dbg_disc, vha, 0x209f,
6550 "Device wrap (%02x%02x%02x).\n",
6551 new_fcport->d_id.b.domain,
6552 new_fcport->d_id.b.area,
6553 new_fcport->d_id.b.al_pa);
6557 /* Bypass if same physical adapter. */
6558 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
6561 /* Bypass virtual ports of the same host. */
6562 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
6565 /* Bypass if same domain and area of adapter. */
6566 if (((new_fcport->d_id.b24 & 0xffff00) ==
6567 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
6571 /* Bypass reserved domain fields. */
6572 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
6575 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
6576 if (ql2xgffidenable &&
6577 (!(new_fcport->fc4_type & FS_FC4TYPE_FCP) &&
6578 new_fcport->fc4_type != 0))
6581 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
6583 /* Locate matching device in database. */
6585 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6586 if (memcmp(new_fcport->port_name, fcport->port_name,
6590 fcport->scan_state = QLA_FCPORT_FOUND;
6594 /* Update port state. */
6595 memcpy(fcport->fabric_port_name,
6596 new_fcport->fabric_port_name, WWN_SIZE);
6597 fcport->fp_speed = new_fcport->fp_speed;
6600 * If address the same and state FCS_ONLINE
6601 * (or in target mode), nothing changed.
6603 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
6604 (atomic_read(&fcport->state) == FCS_ONLINE ||
6605 (vha->host->active_mode == MODE_TARGET))) {
6609 if (fcport->login_retry == 0)
6610 fcport->login_retry =
6611 vha->hw->login_retry_count;
6613 * If device was not a fabric device before.
6615 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
6616 fcport->d_id.b24 = new_fcport->d_id.b24;
6617 qla2x00_clear_loop_id(fcport);
6618 fcport->flags |= (FCF_FABRIC_DEVICE |
6624 * Port ID changed or device was marked to be updated;
6625 * Log it out if still logged in and mark it for
6628 if (qla_tgt_mode_enabled(base_vha)) {
6629 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
6630 "port changed FC ID, %8phC"
6631 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
6633 fcport->d_id.b.domain,
6634 fcport->d_id.b.area,
6635 fcport->d_id.b.al_pa,
6637 new_fcport->d_id.b.domain,
6638 new_fcport->d_id.b.area,
6639 new_fcport->d_id.b.al_pa);
6640 fcport->d_id.b24 = new_fcport->d_id.b24;
6644 fcport->d_id.b24 = new_fcport->d_id.b24;
6645 fcport->flags |= FCF_LOGIN_NEEDED;
6649 if (found && NVME_TARGET(vha->hw, fcport)) {
6650 if (fcport->disc_state == DSC_DELETE_PEND) {
6651 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
6652 vha->fcport_count--;
6653 fcport->login_succ = 0;
6658 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6661 /* If device was not in our fcports list, then add it. */
6662 new_fcport->scan_state = QLA_FCPORT_FOUND;
6663 list_add_tail(&new_fcport->list, &vha->vp_fcports);
6665 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6668 /* Allocate a new replacement fcport. */
6669 nxt_d_id.b24 = new_fcport->d_id.b24;
6670 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
6671 if (new_fcport == NULL) {
6672 ql_log(ql_log_warn, vha, 0xd032,
6673 "Memory allocation failed for fcport.\n");
6674 return (QLA_MEMORY_ALLOC_FAILED);
6676 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
6677 new_fcport->d_id.b24 = nxt_d_id.b24;
6680 qla2x00_free_fcport(new_fcport);
6683 * Logout all previous fabric dev marked lost, except FCP2 devices.
6685 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6686 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6689 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
6692 if (fcport->scan_state == QLA_FCPORT_SCAN) {
6693 if ((qla_dual_mode_enabled(vha) ||
6694 qla_ini_mode_enabled(vha)) &&
6695 atomic_read(&fcport->state) == FCS_ONLINE) {
6696 qla2x00_mark_device_lost(vha, fcport,
6697 ql2xplogiabsentdevice);
6698 if (fcport->loop_id != FC_NO_LOOP_ID &&
6699 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
6700 fcport->port_type != FCT_INITIATOR &&
6701 fcport->port_type != FCT_BROADCAST) {
6702 ql_dbg(ql_dbg_disc, vha, 0x20f0,
6703 "%s %d %8phC post del sess\n",
6706 qlt_schedule_sess_for_deletion(fcport);
6712 if (fcport->scan_state == QLA_FCPORT_FOUND &&
6713 (fcport->flags & FCF_LOGIN_NEEDED) != 0)
6714 qla24xx_fcport_handle_login(vha, fcport);
6719 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
6721 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
6723 int loop_id = FC_NO_LOOP_ID;
6724 int lid = NPH_MGMT_SERVER - vha->vp_idx;
6725 unsigned long flags;
6726 struct qla_hw_data *ha = vha->hw;
6728 if (vha->vp_idx == 0) {
6729 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
6730 return NPH_MGMT_SERVER;
6733 /* pick id from high and work down to low */
6734 spin_lock_irqsave(&ha->vport_slock, flags);
6735 for (; lid > 0; lid--) {
6736 if (!test_bit(lid, vha->hw->loop_id_map)) {
6737 set_bit(lid, vha->hw->loop_id_map);
6742 spin_unlock_irqrestore(&ha->vport_slock, flags);
6748 * qla2x00_fabric_login
6749 * Issue fabric login command.
6752 * ha = adapter block pointer.
6753 * device = pointer to FC device type structure.
6756 * 0 - Login successfully
6758 * 2 - Initiator device
6762 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
6763 uint16_t *next_loopid)
6767 uint16_t tmp_loopid;
6768 uint16_t mb[MAILBOX_REGISTER_COUNT];
6769 struct qla_hw_data *ha = vha->hw;
6775 ql_dbg(ql_dbg_disc, vha, 0x2000,
6776 "Trying Fabric Login w/loop id 0x%04x for port "
6778 fcport->loop_id, fcport->d_id.b.domain,
6779 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6781 /* Login fcport on switch. */
6782 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
6783 fcport->d_id.b.domain, fcport->d_id.b.area,
6784 fcport->d_id.b.al_pa, mb, BIT_0);
6785 if (rval != QLA_SUCCESS) {
6788 if (mb[0] == MBS_PORT_ID_USED) {
6790 * Device has another loop ID. The firmware team
6791 * recommends the driver perform an implicit login with
6792 * the specified ID again. The ID we just used is save
6793 * here so we return with an ID that can be tried by
6797 tmp_loopid = fcport->loop_id;
6798 fcport->loop_id = mb[1];
6800 ql_dbg(ql_dbg_disc, vha, 0x2001,
6801 "Fabric Login: port in use - next loop "
6802 "id=0x%04x, port id= %02x%02x%02x.\n",
6803 fcport->loop_id, fcport->d_id.b.domain,
6804 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6806 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
6811 /* A retry occurred before. */
6812 *next_loopid = tmp_loopid;
6815 * No retry occurred before. Just increment the
6816 * ID value for next login.
6818 *next_loopid = (fcport->loop_id + 1);
6821 if (mb[1] & BIT_0) {
6822 fcport->port_type = FCT_INITIATOR;
6824 fcport->port_type = FCT_TARGET;
6825 if (mb[1] & BIT_1) {
6826 fcport->flags |= FCF_FCP2_DEVICE;
6831 fcport->supported_classes |= FC_COS_CLASS2;
6833 fcport->supported_classes |= FC_COS_CLASS3;
6835 if (IS_FWI2_CAPABLE(ha)) {
6838 FCF_CONF_COMP_SUPPORTED;
6843 } else if (mb[0] == MBS_LOOP_ID_USED) {
6845 * Loop ID already used, try next loop ID.
6848 rval = qla2x00_find_new_loop_id(vha, fcport);
6849 if (rval != QLA_SUCCESS) {
6850 /* Ran out of loop IDs to use */
6853 } else if (mb[0] == MBS_COMMAND_ERROR) {
6855 * Firmware possibly timed out during login. If NO
6856 * retries are left to do then the device is declared
6859 *next_loopid = fcport->loop_id;
6860 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6861 fcport->d_id.b.domain, fcport->d_id.b.area,
6862 fcport->d_id.b.al_pa);
6863 qla2x00_mark_device_lost(vha, fcport, 1);
6869 * unrecoverable / not handled error
6871 ql_dbg(ql_dbg_disc, vha, 0x2002,
6872 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6873 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
6874 fcport->d_id.b.area, fcport->d_id.b.al_pa,
6875 fcport->loop_id, jiffies);
6877 *next_loopid = fcport->loop_id;
6878 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6879 fcport->d_id.b.domain, fcport->d_id.b.area,
6880 fcport->d_id.b.al_pa);
6881 qla2x00_clear_loop_id(fcport);
6882 fcport->login_retry = 0;
6893 * qla2x00_local_device_login
6894 * Issue local device login command.
6897 * ha = adapter block pointer.
6898 * loop_id = loop id of device to login to.
6900 * Returns (Where's the #define!!!!):
6901 * 0 - Login successfully
6906 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
6909 uint16_t mb[MAILBOX_REGISTER_COUNT];
6911 memset(mb, 0, sizeof(mb));
6912 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
6913 if (rval == QLA_SUCCESS) {
6914 /* Interrogate mailbox registers for any errors */
6915 if (mb[0] == MBS_COMMAND_ERROR)
6917 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
6918 /* device not in PCB table */
6926 * qla2x00_loop_resync
6927 * Resync with fibre channel devices.
6930 * ha = adapter block pointer.
6936 qla2x00_loop_resync(scsi_qla_host_t *vha)
6938 int rval = QLA_SUCCESS;
6941 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6942 if (vha->flags.online) {
6943 if (!(rval = qla2x00_fw_ready(vha))) {
6944 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6947 if (!IS_QLAFX00(vha->hw)) {
6949 * Issue a marker after FW becomes
6952 qla2x00_marker(vha, vha->hw->base_qpair,
6954 vha->marker_needed = 0;
6957 /* Remap devices on Loop. */
6958 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6960 if (IS_QLAFX00(vha->hw))
6961 qlafx00_configure_devices(vha);
6963 qla2x00_configure_loop(vha);
6966 } while (!atomic_read(&vha->loop_down_timer) &&
6967 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6968 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
6973 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6974 return (QLA_FUNCTION_FAILED);
6977 ql_dbg(ql_dbg_disc, vha, 0x206c,
6978 "%s *** FAILED ***.\n", __func__);
6984 * qla2x00_perform_loop_resync
6985 * Description: This function will set the appropriate flags and call
6986 * qla2x00_loop_resync. If successful loop will be resynced
6987 * Arguments : scsi_qla_host_t pointer
6988 * returm : Success or Failure
6991 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
6995 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
6996 /*Configure the flags so that resync happens properly*/
6997 atomic_set(&ha->loop_down_timer, 0);
6998 if (!(ha->device_flags & DFLG_NO_CABLE)) {
6999 atomic_set(&ha->loop_state, LOOP_UP);
7000 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
7001 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
7002 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
7004 rval = qla2x00_loop_resync(ha);
7006 atomic_set(&ha->loop_state, LOOP_DEAD);
7008 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
7014 /* Assumes idc_lock always held on entry */
7016 qla83xx_reset_ownership(scsi_qla_host_t *vha)
7018 struct qla_hw_data *ha = vha->hw;
7019 uint32_t drv_presence, drv_presence_mask;
7020 uint32_t dev_part_info1, dev_part_info2, class_type;
7021 uint32_t class_type_mask = 0x3;
7022 uint16_t fcoe_other_function = 0xffff, i;
7024 if (IS_QLA8044(ha)) {
7025 drv_presence = qla8044_rd_direct(vha,
7026 QLA8044_CRB_DRV_ACTIVE_INDEX);
7027 dev_part_info1 = qla8044_rd_direct(vha,
7028 QLA8044_CRB_DEV_PART_INFO_INDEX);
7029 dev_part_info2 = qla8044_rd_direct(vha,
7030 QLA8044_CRB_DEV_PART_INFO2);
7032 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
7033 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
7034 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
7036 for (i = 0; i < 8; i++) {
7037 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
7038 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
7039 (i != ha->portnum)) {
7040 fcoe_other_function = i;
7044 if (fcoe_other_function == 0xffff) {
7045 for (i = 0; i < 8; i++) {
7046 class_type = ((dev_part_info2 >> (i * 4)) &
7048 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
7049 ((i + 8) != ha->portnum)) {
7050 fcoe_other_function = i + 8;
7056 * Prepare drv-presence mask based on fcoe functions present.
7057 * However consider only valid physical fcoe function numbers (0-15).
7059 drv_presence_mask = ~((1 << (ha->portnum)) |
7060 ((fcoe_other_function == 0xffff) ?
7061 0 : (1 << (fcoe_other_function))));
7063 /* We are the reset owner iff:
7064 * - No other protocol drivers present.
7065 * - This is the lowest among fcoe functions. */
7066 if (!(drv_presence & drv_presence_mask) &&
7067 (ha->portnum < fcoe_other_function)) {
7068 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
7069 "This host is Reset owner.\n");
7070 ha->flags.nic_core_reset_owner = 1;
7075 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
7077 int rval = QLA_SUCCESS;
7078 struct qla_hw_data *ha = vha->hw;
7081 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
7082 if (rval == QLA_SUCCESS) {
7083 drv_ack |= (1 << ha->portnum);
7084 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
7091 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
7093 int rval = QLA_SUCCESS;
7094 struct qla_hw_data *ha = vha->hw;
7097 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
7098 if (rval == QLA_SUCCESS) {
7099 drv_ack &= ~(1 << ha->portnum);
7100 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
7106 /* Assumes idc-lock always held on entry */
7108 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
7110 struct qla_hw_data *ha = vha->hw;
7111 uint32_t idc_audit_reg = 0, duration_secs = 0;
7113 switch (audit_type) {
7114 case IDC_AUDIT_TIMESTAMP:
7115 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
7116 idc_audit_reg = (ha->portnum) |
7117 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
7118 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
7121 case IDC_AUDIT_COMPLETION:
7122 duration_secs = ((jiffies_to_msecs(jiffies) -
7123 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
7124 idc_audit_reg = (ha->portnum) |
7125 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
7126 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
7130 ql_log(ql_log_warn, vha, 0xb078,
7131 "Invalid audit type specified.\n");
7136 /* Assumes idc_lock always held on entry */
7138 qla83xx_initiating_reset(scsi_qla_host_t *vha)
7140 struct qla_hw_data *ha = vha->hw;
7141 uint32_t idc_control, dev_state;
7143 __qla83xx_get_idc_control(vha, &idc_control);
7144 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
7145 ql_log(ql_log_info, vha, 0xb080,
7146 "NIC Core reset has been disabled. idc-control=0x%x\n",
7148 return QLA_FUNCTION_FAILED;
7151 /* Set NEED-RESET iff in READY state and we are the reset-owner */
7152 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
7153 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
7154 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
7155 QLA8XXX_DEV_NEED_RESET);
7156 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
7157 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
7159 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n",
7160 qdev_state(dev_state));
7162 /* SV: XXX: Is timeout required here? */
7163 /* Wait for IDC state change READY -> NEED_RESET */
7164 while (dev_state == QLA8XXX_DEV_READY) {
7165 qla83xx_idc_unlock(vha, 0);
7167 qla83xx_idc_lock(vha, 0);
7168 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
7172 /* Send IDC ack by writing to drv-ack register */
7173 __qla83xx_set_drv_ack(vha);
7179 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
7181 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
7185 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
7187 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
7191 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
7193 uint32_t drv_presence = 0;
7194 struct qla_hw_data *ha = vha->hw;
7196 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
7197 if (drv_presence & (1 << ha->portnum))
7200 return QLA_TEST_FAILED;
7204 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
7206 int rval = QLA_SUCCESS;
7207 struct qla_hw_data *ha = vha->hw;
7209 ql_dbg(ql_dbg_p3p, vha, 0xb058,
7210 "Entered %s().\n", __func__);
7212 if (vha->device_flags & DFLG_DEV_FAILED) {
7213 ql_log(ql_log_warn, vha, 0xb059,
7214 "Device in unrecoverable FAILED state.\n");
7215 return QLA_FUNCTION_FAILED;
7218 qla83xx_idc_lock(vha, 0);
7220 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
7221 ql_log(ql_log_warn, vha, 0xb05a,
7222 "Function=0x%x has been removed from IDC participation.\n",
7224 rval = QLA_FUNCTION_FAILED;
7228 qla83xx_reset_ownership(vha);
7230 rval = qla83xx_initiating_reset(vha);
7233 * Perform reset if we are the reset-owner,
7234 * else wait till IDC state changes to READY/FAILED.
7236 if (rval == QLA_SUCCESS) {
7237 rval = qla83xx_idc_state_handler(vha);
7239 if (rval == QLA_SUCCESS)
7240 ha->flags.nic_core_hung = 0;
7241 __qla83xx_clear_drv_ack(vha);
7245 qla83xx_idc_unlock(vha, 0);
7247 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
7253 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
7255 struct qla_hw_data *ha = vha->hw;
7256 int rval = QLA_FUNCTION_FAILED;
7258 if (!IS_MCTP_CAPABLE(ha)) {
7259 /* This message can be removed from the final version */
7260 ql_log(ql_log_info, vha, 0x506d,
7261 "This board is not MCTP capable\n");
7265 if (!ha->mctp_dump) {
7266 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
7267 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
7269 if (!ha->mctp_dump) {
7270 ql_log(ql_log_warn, vha, 0x506e,
7271 "Failed to allocate memory for mctp dump\n");
7276 #define MCTP_DUMP_STR_ADDR 0x00000000
7277 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
7278 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
7279 if (rval != QLA_SUCCESS) {
7280 ql_log(ql_log_warn, vha, 0x506f,
7281 "Failed to capture mctp dump\n");
7283 ql_log(ql_log_info, vha, 0x5070,
7284 "Mctp dump capture for host (%ld/%p).\n",
7285 vha->host_no, ha->mctp_dump);
7286 ha->mctp_dumped = 1;
7289 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
7290 ha->flags.nic_core_reset_hdlr_active = 1;
7291 rval = qla83xx_restart_nic_firmware(vha);
7293 /* NIC Core reset failed. */
7294 ql_log(ql_log_warn, vha, 0x5071,
7295 "Failed to restart nic firmware\n");
7297 ql_dbg(ql_dbg_p3p, vha, 0xb084,
7298 "Restarted NIC firmware successfully.\n");
7299 ha->flags.nic_core_reset_hdlr_active = 0;
7307 * qla2x00_quiesce_io
7308 * Description: This function will block the new I/Os
7309 * Its not aborting any I/Os as context
7310 * is not destroyed during quiescence
7311 * Arguments: scsi_qla_host_t
7315 qla2x00_quiesce_io(scsi_qla_host_t *vha)
7317 struct qla_hw_data *ha = vha->hw;
7318 struct scsi_qla_host *vp, *tvp;
7319 unsigned long flags;
7321 ql_dbg(ql_dbg_dpc, vha, 0x401d,
7322 "Quiescing I/O - ha=%p.\n", ha);
7324 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
7325 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
7326 atomic_set(&vha->loop_state, LOOP_DOWN);
7327 qla2x00_mark_all_devices_lost(vha);
7329 spin_lock_irqsave(&ha->vport_slock, flags);
7330 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7331 atomic_inc(&vp->vref_count);
7332 spin_unlock_irqrestore(&ha->vport_slock, flags);
7334 qla2x00_mark_all_devices_lost(vp);
7336 spin_lock_irqsave(&ha->vport_slock, flags);
7337 atomic_dec(&vp->vref_count);
7339 spin_unlock_irqrestore(&ha->vport_slock, flags);
7341 if (!atomic_read(&vha->loop_down_timer))
7342 atomic_set(&vha->loop_down_timer,
7345 /* Wait for pending cmds to complete */
7346 WARN_ON_ONCE(qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST)
7351 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
7353 struct qla_hw_data *ha = vha->hw;
7354 struct scsi_qla_host *vp, *tvp;
7355 unsigned long flags;
7359 /* For ISP82XX, driver waits for completion of the commands.
7360 * online flag should be set.
7362 if (!(IS_P3P_TYPE(ha)))
7363 vha->flags.online = 0;
7364 ha->flags.chip_reset_done = 0;
7365 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
7366 vha->qla_stats.total_isp_aborts++;
7368 ql_log(ql_log_info, vha, 0x00af,
7369 "Performing ISP error recovery - ha=%p.\n", ha);
7371 ha->flags.purge_mbox = 1;
7372 /* For ISP82XX, reset_chip is just disabling interrupts.
7373 * Driver waits for the completion of the commands.
7374 * the interrupts need to be enabled.
7376 if (!(IS_P3P_TYPE(ha)))
7377 ha->isp_ops->reset_chip(vha);
7379 ha->link_data_rate = PORT_SPEED_UNKNOWN;
7381 ha->flags.rida_fmt2 = 0;
7382 ha->flags.n2n_ae = 0;
7383 ha->flags.lip_ae = 0;
7384 ha->current_topology = 0;
7386 ha->flags.fw_init_done = 0;
7388 ha->base_qpair->chip_reset = ha->chip_reset;
7389 ha->base_qpair->cmd_cnt = ha->base_qpair->cmd_completion_cnt = 0;
7390 ha->base_qpair->prev_completion_cnt = 0;
7391 for (i = 0; i < ha->max_qpairs; i++) {
7392 if (ha->queue_pair_map[i]) {
7393 ha->queue_pair_map[i]->chip_reset =
7394 ha->base_qpair->chip_reset;
7395 ha->queue_pair_map[i]->cmd_cnt =
7396 ha->queue_pair_map[i]->cmd_completion_cnt = 0;
7397 ha->base_qpair->prev_completion_cnt = 0;
7401 /* purge MBox commands */
7402 spin_lock_irqsave(&ha->hardware_lock, flags);
7403 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags)) {
7404 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
7405 complete(&ha->mbx_intr_comp);
7407 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7410 while (atomic_read(&ha->num_pend_mbx_stage2) ||
7411 atomic_read(&ha->num_pend_mbx_stage1)) {
7417 ha->flags.purge_mbox = 0;
7419 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
7420 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
7421 atomic_set(&vha->loop_state, LOOP_DOWN);
7422 qla2x00_mark_all_devices_lost(vha);
7424 spin_lock_irqsave(&ha->vport_slock, flags);
7425 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7426 atomic_inc(&vp->vref_count);
7427 spin_unlock_irqrestore(&ha->vport_slock, flags);
7429 qla2x00_mark_all_devices_lost(vp);
7431 spin_lock_irqsave(&ha->vport_slock, flags);
7432 atomic_dec(&vp->vref_count);
7434 spin_unlock_irqrestore(&ha->vport_slock, flags);
7436 if (!atomic_read(&vha->loop_down_timer))
7437 atomic_set(&vha->loop_down_timer,
7441 /* Clear all async request states across all VPs. */
7442 list_for_each_entry(fcport, &vha->vp_fcports, list) {
7443 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7444 fcport->scan_state = 0;
7446 spin_lock_irqsave(&ha->vport_slock, flags);
7447 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7448 atomic_inc(&vp->vref_count);
7449 spin_unlock_irqrestore(&ha->vport_slock, flags);
7451 list_for_each_entry(fcport, &vp->vp_fcports, list)
7452 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7454 spin_lock_irqsave(&ha->vport_slock, flags);
7455 atomic_dec(&vp->vref_count);
7457 spin_unlock_irqrestore(&ha->vport_slock, flags);
7459 /* Make sure for ISP 82XX IO DMA is complete */
7460 if (IS_P3P_TYPE(ha)) {
7461 qla82xx_chip_reset_cleanup(vha);
7462 ql_log(ql_log_info, vha, 0x00b4,
7463 "Done chip reset cleanup.\n");
7465 /* Done waiting for pending commands. Reset online flag */
7466 vha->flags.online = 0;
7469 /* Requeue all commands in outstanding command list. */
7470 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
7471 /* memory barrier */
7477 * Resets ISP and aborts all outstanding commands.
7480 * ha = adapter block pointer.
7486 qla2x00_abort_isp(scsi_qla_host_t *vha)
7490 struct qla_hw_data *ha = vha->hw;
7491 struct scsi_qla_host *vp, *tvp;
7492 struct req_que *req = ha->req_q_map[0];
7493 unsigned long flags;
7495 if (vha->flags.online) {
7496 qla2x00_abort_isp_cleanup(vha);
7498 vha->dport_status |= DPORT_DIAG_CHIP_RESET_IN_PROGRESS;
7499 vha->dport_status &= ~DPORT_DIAG_IN_PROGRESS;
7501 if (vha->hw->flags.port_isolated)
7504 if (qla2x00_isp_reg_stat(ha)) {
7505 ql_log(ql_log_info, vha, 0x803f,
7506 "ISP Abort - ISP reg disconnect, exiting.\n");
7510 if (test_and_clear_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags)) {
7511 ha->flags.chip_reset_done = 1;
7512 vha->flags.online = 1;
7514 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7518 if (IS_QLA8031(ha)) {
7519 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
7520 "Clearing fcoe driver presence.\n");
7521 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
7522 ql_dbg(ql_dbg_p3p, vha, 0xb073,
7523 "Error while clearing DRV-Presence.\n");
7526 if (unlikely(pci_channel_offline(ha->pdev) &&
7527 ha->flags.pci_channel_io_perm_failure)) {
7528 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7533 switch (vha->qlini_mode) {
7534 case QLA2XXX_INI_MODE_DISABLED:
7535 if (!qla_tgt_mode_enabled(vha))
7538 case QLA2XXX_INI_MODE_DUAL:
7539 if (!qla_dual_mode_enabled(vha) &&
7540 !qla_ini_mode_enabled(vha))
7543 case QLA2XXX_INI_MODE_ENABLED:
7548 ha->isp_ops->get_flash_version(vha, req->ring);
7550 if (qla2x00_isp_reg_stat(ha)) {
7551 ql_log(ql_log_info, vha, 0x803f,
7552 "ISP Abort - ISP reg disconnect pre nvram config, exiting.\n");
7555 ha->isp_ops->nvram_config(vha);
7557 if (qla2x00_isp_reg_stat(ha)) {
7558 ql_log(ql_log_info, vha, 0x803f,
7559 "ISP Abort - ISP reg disconnect post nvmram config, exiting.\n");
7562 if (!qla2x00_restart_isp(vha)) {
7563 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7565 if (!atomic_read(&vha->loop_down_timer)) {
7567 * Issue marker command only when we are going
7568 * to start the I/O .
7570 vha->marker_needed = 1;
7573 vha->flags.online = 1;
7575 ha->isp_ops->enable_intrs(ha);
7577 ha->isp_abort_cnt = 0;
7578 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7580 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
7581 qla2x00_get_fw_version(vha);
7583 ha->flags.fce_enabled = 1;
7585 fce_calc_size(ha->fce_bufs));
7586 rval = qla2x00_enable_fce_trace(vha,
7587 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
7590 ql_log(ql_log_warn, vha, 0x8033,
7591 "Unable to reinitialize FCE "
7593 ha->flags.fce_enabled = 0;
7598 memset(ha->eft, 0, EFT_SIZE);
7599 rval = qla2x00_enable_eft_trace(vha,
7600 ha->eft_dma, EFT_NUM_BUFFERS);
7602 ql_log(ql_log_warn, vha, 0x8034,
7603 "Unable to reinitialize EFT "
7607 } else { /* failed the ISP abort */
7608 vha->flags.online = 1;
7609 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
7610 if (ha->isp_abort_cnt == 0) {
7611 ql_log(ql_log_fatal, vha, 0x8035,
7612 "ISP error recover failed - "
7613 "board disabled.\n");
7615 * The next call disables the board
7618 qla2x00_abort_isp_cleanup(vha);
7619 vha->flags.online = 0;
7620 clear_bit(ISP_ABORT_RETRY,
7623 } else { /* schedule another ISP abort */
7624 ha->isp_abort_cnt--;
7625 ql_dbg(ql_dbg_taskm, vha, 0x8020,
7626 "ISP abort - retry remaining %d.\n",
7631 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
7632 ql_dbg(ql_dbg_taskm, vha, 0x8021,
7633 "ISP error recovery - retrying (%d) "
7634 "more times.\n", ha->isp_abort_cnt);
7635 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7642 if (vha->hw->flags.port_isolated) {
7643 qla2x00_abort_isp_cleanup(vha);
7648 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
7649 qla2x00_configure_hba(vha);
7650 spin_lock_irqsave(&ha->vport_slock, flags);
7651 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7653 atomic_inc(&vp->vref_count);
7654 spin_unlock_irqrestore(&ha->vport_slock, flags);
7656 qla2x00_vp_abort_isp(vp);
7658 spin_lock_irqsave(&ha->vport_slock, flags);
7659 atomic_dec(&vp->vref_count);
7662 spin_unlock_irqrestore(&ha->vport_slock, flags);
7664 if (IS_QLA8031(ha)) {
7665 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
7666 "Setting back fcoe driver presence.\n");
7667 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
7668 ql_dbg(ql_dbg_p3p, vha, 0xb074,
7669 "Error while setting DRV-Presence.\n");
7672 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
7680 * qla2x00_restart_isp
7681 * restarts the ISP after a reset
7684 * ha = adapter block pointer.
7690 qla2x00_restart_isp(scsi_qla_host_t *vha)
7693 struct qla_hw_data *ha = vha->hw;
7695 /* If firmware needs to be loaded */
7696 if (qla2x00_isp_firmware(vha)) {
7697 vha->flags.online = 0;
7698 status = ha->isp_ops->chip_diag(vha);
7701 status = qla2x00_setup_chip(vha);
7706 status = qla2x00_init_rings(vha);
7710 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7711 ha->flags.chip_reset_done = 1;
7713 /* Initialize the queues in use */
7714 qla25xx_init_queues(ha);
7716 status = qla2x00_fw_ready(vha);
7718 /* if no cable then assume it's good */
7719 return vha->device_flags & DFLG_NO_CABLE ? 0 : status;
7722 /* Issue a marker after FW becomes ready. */
7723 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
7724 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7730 qla25xx_init_queues(struct qla_hw_data *ha)
7732 struct rsp_que *rsp = NULL;
7733 struct req_que *req = NULL;
7734 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7738 for (i = 1; i < ha->max_rsp_queues; i++) {
7739 rsp = ha->rsp_q_map[i];
7740 if (rsp && test_bit(i, ha->rsp_qid_map)) {
7741 rsp->options &= ~BIT_0;
7742 ret = qla25xx_init_rsp_que(base_vha, rsp);
7743 if (ret != QLA_SUCCESS)
7744 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
7745 "%s Rsp que: %d init failed.\n",
7748 ql_dbg(ql_dbg_init, base_vha, 0x0100,
7749 "%s Rsp que: %d inited.\n",
7753 for (i = 1; i < ha->max_req_queues; i++) {
7754 req = ha->req_q_map[i];
7755 if (req && test_bit(i, ha->req_qid_map)) {
7756 /* Clear outstanding commands array. */
7757 req->options &= ~BIT_0;
7758 ret = qla25xx_init_req_que(base_vha, req);
7759 if (ret != QLA_SUCCESS)
7760 ql_dbg(ql_dbg_init, base_vha, 0x0101,
7761 "%s Req que: %d init failed.\n",
7764 ql_dbg(ql_dbg_init, base_vha, 0x0102,
7765 "%s Req que: %d inited.\n",
7773 * qla2x00_reset_adapter
7777 * ha = adapter block pointer.
7780 qla2x00_reset_adapter(scsi_qla_host_t *vha)
7782 unsigned long flags = 0;
7783 struct qla_hw_data *ha = vha->hw;
7784 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7786 vha->flags.online = 0;
7787 ha->isp_ops->disable_intrs(ha);
7789 spin_lock_irqsave(&ha->hardware_lock, flags);
7790 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
7791 rd_reg_word(®->hccr); /* PCI Posting. */
7792 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
7793 rd_reg_word(®->hccr); /* PCI Posting. */
7794 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7800 qla24xx_reset_adapter(scsi_qla_host_t *vha)
7802 unsigned long flags = 0;
7803 struct qla_hw_data *ha = vha->hw;
7804 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
7806 if (IS_P3P_TYPE(ha))
7809 vha->flags.online = 0;
7810 ha->isp_ops->disable_intrs(ha);
7812 spin_lock_irqsave(&ha->hardware_lock, flags);
7813 wrt_reg_dword(®->hccr, HCCRX_SET_RISC_RESET);
7814 rd_reg_dword(®->hccr);
7815 wrt_reg_dword(®->hccr, HCCRX_REL_RISC_PAUSE);
7816 rd_reg_dword(®->hccr);
7817 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7819 if (IS_NOPOLLING_TYPE(ha))
7820 ha->isp_ops->enable_intrs(ha);
7825 /* On sparc systems, obtain port and node WWN from firmware
7828 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
7829 struct nvram_24xx *nv)
7832 struct qla_hw_data *ha = vha->hw;
7833 struct pci_dev *pdev = ha->pdev;
7834 struct device_node *dp = pci_device_to_OF_node(pdev);
7838 val = of_get_property(dp, "port-wwn", &len);
7839 if (val && len >= WWN_SIZE)
7840 memcpy(nv->port_name, val, WWN_SIZE);
7842 val = of_get_property(dp, "node-wwn", &len);
7843 if (val && len >= WWN_SIZE)
7844 memcpy(nv->node_name, val, WWN_SIZE);
7849 qla24xx_nvram_config(scsi_qla_host_t *vha)
7852 struct init_cb_24xx *icb;
7853 struct nvram_24xx *nv;
7855 uint8_t *dptr1, *dptr2;
7858 struct qla_hw_data *ha = vha->hw;
7861 icb = (struct init_cb_24xx *)ha->init_cb;
7864 /* Determine NVRAM starting address. */
7865 if (ha->port_no == 0) {
7866 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
7867 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
7869 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
7870 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
7873 ha->nvram_size = sizeof(*nv);
7874 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7876 /* Get VPD data into cache */
7877 ha->vpd = ha->nvram + VPD_OFFSET;
7878 ha->isp_ops->read_nvram(vha, ha->vpd,
7879 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
7881 /* Get NVRAM data into cache and calculate checksum. */
7882 dptr = (__force __le32 *)nv;
7883 ha->isp_ops->read_nvram(vha, dptr, ha->nvram_base, ha->nvram_size);
7884 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7885 chksum += le32_to_cpu(*dptr);
7887 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
7888 "Contents of NVRAM\n");
7889 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
7890 nv, ha->nvram_size);
7892 /* Bad NVRAM data, set defaults parameters. */
7893 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
7894 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
7895 /* Reset NVRAM data. */
7896 ql_log(ql_log_warn, vha, 0x006b,
7897 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
7898 chksum, nv->id, nv->nvram_version);
7899 ql_dump_buffer(ql_dbg_init, vha, 0x006b, nv, sizeof(*nv));
7900 ql_log(ql_log_warn, vha, 0x006c,
7901 "Falling back to functioning (yet invalid -- WWPN) "
7905 * Set default initialization control block.
7907 memset(nv, 0, ha->nvram_size);
7908 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7909 nv->version = cpu_to_le16(ICB_VERSION);
7910 nv->frame_payload_size = cpu_to_le16(2048);
7911 nv->execution_throttle = cpu_to_le16(0xFFFF);
7912 nv->exchange_count = cpu_to_le16(0);
7913 nv->hard_address = cpu_to_le16(124);
7914 nv->port_name[0] = 0x21;
7915 nv->port_name[1] = 0x00 + ha->port_no + 1;
7916 nv->port_name[2] = 0x00;
7917 nv->port_name[3] = 0xe0;
7918 nv->port_name[4] = 0x8b;
7919 nv->port_name[5] = 0x1c;
7920 nv->port_name[6] = 0x55;
7921 nv->port_name[7] = 0x86;
7922 nv->node_name[0] = 0x20;
7923 nv->node_name[1] = 0x00;
7924 nv->node_name[2] = 0x00;
7925 nv->node_name[3] = 0xe0;
7926 nv->node_name[4] = 0x8b;
7927 nv->node_name[5] = 0x1c;
7928 nv->node_name[6] = 0x55;
7929 nv->node_name[7] = 0x86;
7930 qla24xx_nvram_wwn_from_ofw(vha, nv);
7931 nv->login_retry_count = cpu_to_le16(8);
7932 nv->interrupt_delay_timer = cpu_to_le16(0);
7933 nv->login_timeout = cpu_to_le16(0);
7934 nv->firmware_options_1 =
7935 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7936 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7937 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7938 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7939 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7940 nv->efi_parameters = cpu_to_le32(0);
7941 nv->reset_delay = 5;
7942 nv->max_luns_per_target = cpu_to_le16(128);
7943 nv->port_down_retry_count = cpu_to_le16(30);
7944 nv->link_down_timeout = cpu_to_le16(30);
7949 if (qla_tgt_mode_enabled(vha)) {
7950 /* Don't enable full login after initial LIP */
7951 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7952 /* Don't enable LIP full login for initiator */
7953 nv->host_p &= cpu_to_le32(~BIT_10);
7956 qlt_24xx_config_nvram_stage1(vha, nv);
7958 /* Reset Initialization control block */
7959 memset(icb, 0, ha->init_cb_size);
7961 /* Copy 1st segment. */
7962 dptr1 = (uint8_t *)icb;
7963 dptr2 = (uint8_t *)&nv->version;
7964 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7966 *dptr1++ = *dptr2++;
7968 icb->login_retry_count = nv->login_retry_count;
7969 icb->link_down_on_nos = nv->link_down_on_nos;
7971 /* Copy 2nd segment. */
7972 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7973 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7974 cnt = (uint8_t *)&icb->reserved_3 -
7975 (uint8_t *)&icb->interrupt_delay_timer;
7977 *dptr1++ = *dptr2++;
7978 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
7980 * Setup driver NVRAM options.
7982 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7985 qlt_24xx_config_nvram_stage2(vha, icb);
7987 if (nv->host_p & cpu_to_le32(BIT_15)) {
7988 /* Use alternate WWN? */
7989 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7990 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7993 /* Prepare nodename */
7994 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7996 * Firmware will apply the following mask if the nodename was
7999 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
8000 icb->node_name[0] &= 0xF0;
8003 /* Set host adapter parameters. */
8004 ha->flags.disable_risc_code_load = 0;
8005 ha->flags.enable_lip_reset = 0;
8006 ha->flags.enable_lip_full_login =
8007 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
8008 ha->flags.enable_target_reset =
8009 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
8010 ha->flags.enable_led_scheme = 0;
8011 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
8013 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
8014 (BIT_6 | BIT_5 | BIT_4)) >> 4;
8016 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
8017 sizeof(ha->fw_seriallink_options24));
8019 /* save HBA serial number */
8020 ha->serial0 = icb->port_name[5];
8021 ha->serial1 = icb->port_name[6];
8022 ha->serial2 = icb->port_name[7];
8023 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
8024 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
8026 icb->execution_throttle = cpu_to_le16(0xFFFF);
8028 ha->retry_count = le16_to_cpu(nv->login_retry_count);
8030 /* Set minimum login_timeout to 4 seconds. */
8031 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
8032 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
8033 if (le16_to_cpu(nv->login_timeout) < 4)
8034 nv->login_timeout = cpu_to_le16(4);
8035 ha->login_timeout = le16_to_cpu(nv->login_timeout);
8037 /* Set minimum RATOV to 100 tenths of a second. */
8040 ha->loop_reset_delay = nv->reset_delay;
8042 /* Link Down Timeout = 0:
8044 * When Port Down timer expires we will start returning
8045 * I/O's to OS with "DID_NO_CONNECT".
8047 * Link Down Timeout != 0:
8049 * The driver waits for the link to come up after link down
8050 * before returning I/Os to OS with "DID_NO_CONNECT".
8052 if (le16_to_cpu(nv->link_down_timeout) == 0) {
8053 ha->loop_down_abort_time =
8054 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
8056 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
8057 ha->loop_down_abort_time =
8058 (LOOP_DOWN_TIME - ha->link_down_timeout);
8061 /* Need enough time to try and get the port back. */
8062 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8063 if (qlport_down_retry)
8064 ha->port_down_retry_count = qlport_down_retry;
8066 /* Set login_retry_count */
8067 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8068 if (ha->port_down_retry_count ==
8069 le16_to_cpu(nv->port_down_retry_count) &&
8070 ha->port_down_retry_count > 3)
8071 ha->login_retry_count = ha->port_down_retry_count;
8072 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8073 ha->login_retry_count = ha->port_down_retry_count;
8074 if (ql2xloginretrycount)
8075 ha->login_retry_count = ql2xloginretrycount;
8077 /* N2N: driver will initiate Login instead of FW */
8078 icb->firmware_options_3 |= cpu_to_le32(BIT_8);
8081 if (!vha->flags.init_done) {
8082 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8083 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8084 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8085 le16_to_cpu(icb->interrupt_delay_timer) : 2;
8087 icb->firmware_options_2 &= cpu_to_le32(
8088 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8089 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8090 ha->zio_mode = QLA_ZIO_MODE_6;
8092 ql_log(ql_log_info, vha, 0x006f,
8093 "ZIO mode %d enabled; timer delay (%d us).\n",
8094 ha->zio_mode, ha->zio_timer * 100);
8096 icb->firmware_options_2 |= cpu_to_le32(
8097 (uint32_t)ha->zio_mode);
8098 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8102 ql_log(ql_log_warn, vha, 0x0070,
8103 "NVRAM configuration failed.\n");
8109 qla27xx_print_image(struct scsi_qla_host *vha, char *name,
8110 struct qla27xx_image_status *image_status)
8112 ql_dbg(ql_dbg_init, vha, 0x018b,
8113 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
8115 image_status->image_status_mask,
8116 le16_to_cpu(image_status->generation),
8117 image_status->ver_major,
8118 image_status->ver_minor,
8119 image_status->bitmap,
8120 le32_to_cpu(image_status->checksum),
8121 le32_to_cpu(image_status->signature));
8125 qla28xx_check_aux_image_status_signature(
8126 struct qla27xx_image_status *image_status)
8128 ulong signature = le32_to_cpu(image_status->signature);
8130 return signature != QLA28XX_AUX_IMG_STATUS_SIGN;
8134 qla27xx_check_image_status_signature(struct qla27xx_image_status *image_status)
8136 ulong signature = le32_to_cpu(image_status->signature);
8139 signature != QLA27XX_IMG_STATUS_SIGN &&
8140 signature != QLA28XX_IMG_STATUS_SIGN;
8144 qla27xx_image_status_checksum(struct qla27xx_image_status *image_status)
8146 __le32 *p = (__force __le32 *)image_status;
8147 uint n = sizeof(*image_status) / sizeof(*p);
8151 sum += le32_to_cpup(p);
8157 qla28xx_component_bitmask(struct qla27xx_image_status *aux, uint bitmask)
8159 return aux->bitmap & bitmask ?
8160 QLA27XX_SECONDARY_IMAGE : QLA27XX_PRIMARY_IMAGE;
8164 qla28xx_component_status(
8165 struct active_regions *active_regions, struct qla27xx_image_status *aux)
8167 active_regions->aux.board_config =
8168 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_BOARD_CONFIG);
8170 active_regions->aux.vpd_nvram =
8171 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_VPD_NVRAM);
8173 active_regions->aux.npiv_config_0_1 =
8174 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1);
8176 active_regions->aux.npiv_config_2_3 =
8177 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3);
8179 active_regions->aux.nvme_params =
8180 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NVME_PARAMS);
8184 qla27xx_compare_image_generation(
8185 struct qla27xx_image_status *pri_image_status,
8186 struct qla27xx_image_status *sec_image_status)
8188 /* calculate generation delta as uint16 (this accounts for wrap) */
8190 le16_to_cpu(pri_image_status->generation) -
8191 le16_to_cpu(sec_image_status->generation);
8193 ql_dbg(ql_dbg_init, NULL, 0x0180, "generation delta = %d\n", delta);
8199 qla28xx_get_aux_images(
8200 struct scsi_qla_host *vha, struct active_regions *active_regions)
8202 struct qla_hw_data *ha = vha->hw;
8203 struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
8204 bool valid_pri_image = false, valid_sec_image = false;
8205 bool active_pri_image = false, active_sec_image = false;
8207 if (!ha->flt_region_aux_img_status_pri) {
8208 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
8209 goto check_sec_image;
8212 qla24xx_read_flash_data(vha, (uint32_t *)&pri_aux_image_status,
8213 ha->flt_region_aux_img_status_pri,
8214 sizeof(pri_aux_image_status) >> 2);
8215 qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
8217 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
8218 ql_dbg(ql_dbg_init, vha, 0x018b,
8219 "Primary aux image signature (%#x) not valid\n",
8220 le32_to_cpu(pri_aux_image_status.signature));
8221 goto check_sec_image;
8224 if (qla27xx_image_status_checksum(&pri_aux_image_status)) {
8225 ql_dbg(ql_dbg_init, vha, 0x018c,
8226 "Primary aux image checksum failed\n");
8227 goto check_sec_image;
8230 valid_pri_image = true;
8232 if (pri_aux_image_status.image_status_mask & 1) {
8233 ql_dbg(ql_dbg_init, vha, 0x018d,
8234 "Primary aux image is active\n");
8235 active_pri_image = true;
8239 if (!ha->flt_region_aux_img_status_sec) {
8240 ql_dbg(ql_dbg_init, vha, 0x018a,
8241 "Secondary aux image not addressed\n");
8242 goto check_valid_image;
8245 qla24xx_read_flash_data(vha, (uint32_t *)&sec_aux_image_status,
8246 ha->flt_region_aux_img_status_sec,
8247 sizeof(sec_aux_image_status) >> 2);
8248 qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
8250 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
8251 ql_dbg(ql_dbg_init, vha, 0x018b,
8252 "Secondary aux image signature (%#x) not valid\n",
8253 le32_to_cpu(sec_aux_image_status.signature));
8254 goto check_valid_image;
8257 if (qla27xx_image_status_checksum(&sec_aux_image_status)) {
8258 ql_dbg(ql_dbg_init, vha, 0x018c,
8259 "Secondary aux image checksum failed\n");
8260 goto check_valid_image;
8263 valid_sec_image = true;
8265 if (sec_aux_image_status.image_status_mask & 1) {
8266 ql_dbg(ql_dbg_init, vha, 0x018d,
8267 "Secondary aux image is active\n");
8268 active_sec_image = true;
8272 if (valid_pri_image && active_pri_image &&
8273 valid_sec_image && active_sec_image) {
8274 if (qla27xx_compare_image_generation(&pri_aux_image_status,
8275 &sec_aux_image_status) >= 0) {
8276 qla28xx_component_status(active_regions,
8277 &pri_aux_image_status);
8279 qla28xx_component_status(active_regions,
8280 &sec_aux_image_status);
8282 } else if (valid_pri_image && active_pri_image) {
8283 qla28xx_component_status(active_regions, &pri_aux_image_status);
8284 } else if (valid_sec_image && active_sec_image) {
8285 qla28xx_component_status(active_regions, &sec_aux_image_status);
8288 ql_dbg(ql_dbg_init, vha, 0x018f,
8289 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u, NVME=%u\n",
8290 active_regions->aux.board_config,
8291 active_regions->aux.vpd_nvram,
8292 active_regions->aux.npiv_config_0_1,
8293 active_regions->aux.npiv_config_2_3,
8294 active_regions->aux.nvme_params);
8298 qla27xx_get_active_image(struct scsi_qla_host *vha,
8299 struct active_regions *active_regions)
8301 struct qla_hw_data *ha = vha->hw;
8302 struct qla27xx_image_status pri_image_status, sec_image_status;
8303 bool valid_pri_image = false, valid_sec_image = false;
8304 bool active_pri_image = false, active_sec_image = false;
8306 if (!ha->flt_region_img_status_pri) {
8307 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
8308 goto check_sec_image;
8311 if (qla24xx_read_flash_data(vha, (uint32_t *)&pri_image_status,
8312 ha->flt_region_img_status_pri, sizeof(pri_image_status) >> 2) !=
8315 goto check_sec_image;
8317 qla27xx_print_image(vha, "Primary image", &pri_image_status);
8319 if (qla27xx_check_image_status_signature(&pri_image_status)) {
8320 ql_dbg(ql_dbg_init, vha, 0x018b,
8321 "Primary image signature (%#x) not valid\n",
8322 le32_to_cpu(pri_image_status.signature));
8323 goto check_sec_image;
8326 if (qla27xx_image_status_checksum(&pri_image_status)) {
8327 ql_dbg(ql_dbg_init, vha, 0x018c,
8328 "Primary image checksum failed\n");
8329 goto check_sec_image;
8332 valid_pri_image = true;
8334 if (pri_image_status.image_status_mask & 1) {
8335 ql_dbg(ql_dbg_init, vha, 0x018d,
8336 "Primary image is active\n");
8337 active_pri_image = true;
8341 if (!ha->flt_region_img_status_sec) {
8342 ql_dbg(ql_dbg_init, vha, 0x018a, "Secondary image not addressed\n");
8343 goto check_valid_image;
8346 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
8347 ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
8348 qla27xx_print_image(vha, "Secondary image", &sec_image_status);
8350 if (qla27xx_check_image_status_signature(&sec_image_status)) {
8351 ql_dbg(ql_dbg_init, vha, 0x018b,
8352 "Secondary image signature (%#x) not valid\n",
8353 le32_to_cpu(sec_image_status.signature));
8354 goto check_valid_image;
8357 if (qla27xx_image_status_checksum(&sec_image_status)) {
8358 ql_dbg(ql_dbg_init, vha, 0x018c,
8359 "Secondary image checksum failed\n");
8360 goto check_valid_image;
8363 valid_sec_image = true;
8365 if (sec_image_status.image_status_mask & 1) {
8366 ql_dbg(ql_dbg_init, vha, 0x018d,
8367 "Secondary image is active\n");
8368 active_sec_image = true;
8372 if (valid_pri_image && active_pri_image)
8373 active_regions->global = QLA27XX_PRIMARY_IMAGE;
8375 if (valid_sec_image && active_sec_image) {
8376 if (!active_regions->global ||
8377 qla27xx_compare_image_generation(
8378 &pri_image_status, &sec_image_status) < 0) {
8379 active_regions->global = QLA27XX_SECONDARY_IMAGE;
8383 ql_dbg(ql_dbg_init, vha, 0x018f, "active image %s (%u)\n",
8384 active_regions->global == QLA27XX_DEFAULT_IMAGE ?
8385 "default (boot/fw)" :
8386 active_regions->global == QLA27XX_PRIMARY_IMAGE ?
8388 active_regions->global == QLA27XX_SECONDARY_IMAGE ?
8389 "secondary" : "invalid",
8390 active_regions->global);
8393 bool qla24xx_risc_firmware_invalid(uint32_t *dword)
8396 !(dword[4] | dword[5] | dword[6] | dword[7]) ||
8397 !(~dword[4] | ~dword[5] | ~dword[6] | ~dword[7]);
8401 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
8405 uint templates, segments, fragment;
8410 uint32_t risc_addr, risc_size, risc_attr = 0;
8411 struct qla_hw_data *ha = vha->hw;
8412 struct req_que *req = ha->req_q_map[0];
8413 struct fwdt *fwdt = ha->fwdt;
8415 ql_dbg(ql_dbg_init, vha, 0x008b,
8416 "FW: Loading firmware from flash (%x).\n", faddr);
8418 dcode = (uint32_t *)req->ring;
8419 qla24xx_read_flash_data(vha, dcode, faddr, 8);
8420 if (qla24xx_risc_firmware_invalid(dcode)) {
8421 ql_log(ql_log_fatal, vha, 0x008c,
8422 "Unable to verify the integrity of flash firmware "
8424 ql_log(ql_log_fatal, vha, 0x008d,
8425 "Firmware data: %08x %08x %08x %08x.\n",
8426 dcode[0], dcode[1], dcode[2], dcode[3]);
8428 return QLA_FUNCTION_FAILED;
8431 dcode = (uint32_t *)req->ring;
8433 segments = FA_RISC_CODE_SEGMENTS;
8434 for (j = 0; j < segments; j++) {
8435 ql_dbg(ql_dbg_init, vha, 0x008d,
8436 "-> Loading segment %u...\n", j);
8437 qla24xx_read_flash_data(vha, dcode, faddr, 10);
8438 risc_addr = be32_to_cpu((__force __be32)dcode[2]);
8439 risc_size = be32_to_cpu((__force __be32)dcode[3]);
8441 *srisc_addr = risc_addr;
8442 risc_attr = be32_to_cpu((__force __be32)dcode[9]);
8445 dlen = ha->fw_transfer_size >> 2;
8446 for (fragment = 0; risc_size; fragment++) {
8447 if (dlen > risc_size)
8450 ql_dbg(ql_dbg_init, vha, 0x008e,
8451 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
8452 fragment, risc_addr, faddr, dlen);
8453 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
8454 for (i = 0; i < dlen; i++)
8455 dcode[i] = swab32(dcode[i]);
8457 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
8459 ql_log(ql_log_fatal, vha, 0x008f,
8460 "-> Failed load firmware fragment %u.\n",
8462 return QLA_FUNCTION_FAILED;
8471 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8474 templates = (risc_attr & BIT_9) ? 2 : 1;
8475 ql_dbg(ql_dbg_init, vha, 0x0160, "-> templates = %u\n", templates);
8476 for (j = 0; j < templates; j++, fwdt++) {
8477 vfree(fwdt->template);
8478 fwdt->template = NULL;
8481 dcode = (uint32_t *)req->ring;
8482 qla24xx_read_flash_data(vha, dcode, faddr, 7);
8483 risc_size = be32_to_cpu((__force __be32)dcode[2]);
8484 ql_dbg(ql_dbg_init, vha, 0x0161,
8485 "-> fwdt%u template array at %#x (%#x dwords)\n",
8486 j, faddr, risc_size);
8487 if (!risc_size || !~risc_size) {
8488 ql_dbg(ql_dbg_init, vha, 0x0162,
8489 "-> fwdt%u failed to read array\n", j);
8493 /* skip header and ignore checksum */
8497 ql_dbg(ql_dbg_init, vha, 0x0163,
8498 "-> fwdt%u template allocate template %#x words...\n",
8500 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
8501 if (!fwdt->template) {
8502 ql_log(ql_log_warn, vha, 0x0164,
8503 "-> fwdt%u failed allocate template.\n", j);
8507 dcode = fwdt->template;
8508 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
8510 if (!qla27xx_fwdt_template_valid(dcode)) {
8511 ql_log(ql_log_warn, vha, 0x0165,
8512 "-> fwdt%u failed template validate\n", j);
8516 dlen = qla27xx_fwdt_template_size(dcode);
8517 ql_dbg(ql_dbg_init, vha, 0x0166,
8518 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8519 j, dlen, dlen / sizeof(*dcode));
8520 if (dlen > risc_size * sizeof(*dcode)) {
8521 ql_log(ql_log_warn, vha, 0x0167,
8522 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8523 j, dlen - risc_size * sizeof(*dcode));
8527 fwdt->length = dlen;
8528 ql_dbg(ql_dbg_init, vha, 0x0168,
8529 "-> fwdt%u loaded template ok\n", j);
8531 faddr += risc_size + 1;
8537 vfree(fwdt->template);
8538 fwdt->template = NULL;
8544 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
8547 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8553 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
8554 struct fw_blob *blob;
8555 struct qla_hw_data *ha = vha->hw;
8556 struct req_que *req = ha->req_q_map[0];
8558 /* Load firmware blob. */
8559 blob = qla2x00_request_firmware(vha);
8561 ql_log(ql_log_info, vha, 0x0083,
8562 "Firmware image unavailable.\n");
8563 ql_log(ql_log_info, vha, 0x0084,
8564 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
8565 return QLA_FUNCTION_FAILED;
8570 wcode = (uint16_t *)req->ring;
8572 fwcode = (__force __be16 *)blob->fw->data;
8575 /* Validate firmware image by checking version. */
8576 if (blob->fw->size < 8 * sizeof(uint16_t)) {
8577 ql_log(ql_log_fatal, vha, 0x0085,
8578 "Unable to verify integrity of firmware image (%zd).\n",
8580 goto fail_fw_integrity;
8582 for (i = 0; i < 4; i++)
8583 wcode[i] = be16_to_cpu(fwcode[i + 4]);
8584 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
8585 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
8586 wcode[2] == 0 && wcode[3] == 0)) {
8587 ql_log(ql_log_fatal, vha, 0x0086,
8588 "Unable to verify integrity of firmware image.\n");
8589 ql_log(ql_log_fatal, vha, 0x0087,
8590 "Firmware data: %04x %04x %04x %04x.\n",
8591 wcode[0], wcode[1], wcode[2], wcode[3]);
8592 goto fail_fw_integrity;
8596 while (*seg && rval == QLA_SUCCESS) {
8598 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
8599 risc_size = be16_to_cpu(fwcode[3]);
8601 /* Validate firmware image size. */
8602 fwclen += risc_size * sizeof(uint16_t);
8603 if (blob->fw->size < fwclen) {
8604 ql_log(ql_log_fatal, vha, 0x0088,
8605 "Unable to verify integrity of firmware image "
8606 "(%zd).\n", blob->fw->size);
8607 goto fail_fw_integrity;
8611 while (risc_size > 0 && rval == QLA_SUCCESS) {
8612 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
8613 if (wlen > risc_size)
8615 ql_dbg(ql_dbg_init, vha, 0x0089,
8616 "Loading risc segment@ risc addr %x number of "
8617 "words 0x%x.\n", risc_addr, wlen);
8619 for (i = 0; i < wlen; i++)
8620 wcode[i] = swab16((__force u32)fwcode[i]);
8622 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
8625 ql_log(ql_log_fatal, vha, 0x008a,
8626 "Failed to load segment %d of firmware.\n",
8643 return QLA_FUNCTION_FAILED;
8647 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8650 uint templates, segments, fragment;
8653 uint32_t risc_addr, risc_size, risc_attr = 0;
8656 struct fw_blob *blob;
8658 struct qla_hw_data *ha = vha->hw;
8659 struct req_que *req = ha->req_q_map[0];
8660 struct fwdt *fwdt = ha->fwdt;
8662 ql_dbg(ql_dbg_init, vha, 0x0090,
8663 "-> FW: Loading via request-firmware.\n");
8665 blob = qla2x00_request_firmware(vha);
8667 ql_log(ql_log_warn, vha, 0x0092,
8668 "-> Firmware file not found.\n");
8670 return QLA_FUNCTION_FAILED;
8673 fwcode = (__force __be32 *)blob->fw->data;
8674 dcode = (__force uint32_t *)fwcode;
8675 if (qla24xx_risc_firmware_invalid(dcode)) {
8676 ql_log(ql_log_fatal, vha, 0x0093,
8677 "Unable to verify integrity of firmware image (%zd).\n",
8679 ql_log(ql_log_fatal, vha, 0x0095,
8680 "Firmware data: %08x %08x %08x %08x.\n",
8681 dcode[0], dcode[1], dcode[2], dcode[3]);
8682 return QLA_FUNCTION_FAILED;
8685 dcode = (uint32_t *)req->ring;
8687 segments = FA_RISC_CODE_SEGMENTS;
8688 for (j = 0; j < segments; j++) {
8689 ql_dbg(ql_dbg_init, vha, 0x0096,
8690 "-> Loading segment %u...\n", j);
8691 risc_addr = be32_to_cpu(fwcode[2]);
8692 risc_size = be32_to_cpu(fwcode[3]);
8695 *srisc_addr = risc_addr;
8696 risc_attr = be32_to_cpu(fwcode[9]);
8699 dlen = ha->fw_transfer_size >> 2;
8700 for (fragment = 0; risc_size; fragment++) {
8701 if (dlen > risc_size)
8704 ql_dbg(ql_dbg_init, vha, 0x0097,
8705 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
8706 fragment, risc_addr,
8707 (uint32_t)(fwcode - (typeof(fwcode))blob->fw->data),
8710 for (i = 0; i < dlen; i++)
8711 dcode[i] = swab32((__force u32)fwcode[i]);
8713 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
8715 ql_log(ql_log_fatal, vha, 0x0098,
8716 "-> Failed load firmware fragment %u.\n",
8718 return QLA_FUNCTION_FAILED;
8727 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8730 templates = (risc_attr & BIT_9) ? 2 : 1;
8731 ql_dbg(ql_dbg_init, vha, 0x0170, "-> templates = %u\n", templates);
8732 for (j = 0; j < templates; j++, fwdt++) {
8733 vfree(fwdt->template);
8734 fwdt->template = NULL;
8737 risc_size = be32_to_cpu(fwcode[2]);
8738 ql_dbg(ql_dbg_init, vha, 0x0171,
8739 "-> fwdt%u template array at %#x (%#x dwords)\n",
8740 j, (uint32_t)((void *)fwcode - (void *)blob->fw->data),
8742 if (!risc_size || !~risc_size) {
8743 ql_dbg(ql_dbg_init, vha, 0x0172,
8744 "-> fwdt%u failed to read array\n", j);
8748 /* skip header and ignore checksum */
8752 ql_dbg(ql_dbg_init, vha, 0x0173,
8753 "-> fwdt%u template allocate template %#x words...\n",
8755 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
8756 if (!fwdt->template) {
8757 ql_log(ql_log_warn, vha, 0x0174,
8758 "-> fwdt%u failed allocate template.\n", j);
8762 dcode = fwdt->template;
8763 for (i = 0; i < risc_size; i++)
8764 dcode[i] = (__force u32)fwcode[i];
8766 if (!qla27xx_fwdt_template_valid(dcode)) {
8767 ql_log(ql_log_warn, vha, 0x0175,
8768 "-> fwdt%u failed template validate\n", j);
8772 dlen = qla27xx_fwdt_template_size(dcode);
8773 ql_dbg(ql_dbg_init, vha, 0x0176,
8774 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8775 j, dlen, dlen / sizeof(*dcode));
8776 if (dlen > risc_size * sizeof(*dcode)) {
8777 ql_log(ql_log_warn, vha, 0x0177,
8778 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8779 j, dlen - risc_size * sizeof(*dcode));
8783 fwdt->length = dlen;
8784 ql_dbg(ql_dbg_init, vha, 0x0178,
8785 "-> fwdt%u loaded template ok\n", j);
8787 fwcode += risc_size + 1;
8793 vfree(fwdt->template);
8794 fwdt->template = NULL;
8801 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8805 if (ql2xfwloadbin == 1)
8806 return qla81xx_load_risc(vha, srisc_addr);
8810 * 1) Firmware via request-firmware interface (.bin file).
8811 * 2) Firmware residing in flash.
8813 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8814 if (rval == QLA_SUCCESS)
8817 return qla24xx_load_risc_flash(vha, srisc_addr,
8818 vha->hw->flt_region_fw);
8822 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8825 struct qla_hw_data *ha = vha->hw;
8826 struct active_regions active_regions = { };
8828 if (ql2xfwloadbin == 2)
8831 /* FW Load priority:
8832 * 1) Firmware residing in flash.
8833 * 2) Firmware via request-firmware interface (.bin file).
8834 * 3) Golden-Firmware residing in flash -- (limited operation).
8837 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8838 goto try_primary_fw;
8840 qla27xx_get_active_image(vha, &active_regions);
8842 if (active_regions.global != QLA27XX_SECONDARY_IMAGE)
8843 goto try_primary_fw;
8845 ql_dbg(ql_dbg_init, vha, 0x008b,
8846 "Loading secondary firmware image.\n");
8847 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw_sec);
8852 ql_dbg(ql_dbg_init, vha, 0x008b,
8853 "Loading primary firmware image.\n");
8854 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
8859 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8860 if (!rval || !ha->flt_region_gold_fw)
8863 ql_log(ql_log_info, vha, 0x0099,
8864 "Attempting to fallback to golden firmware.\n");
8865 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
8869 ql_log(ql_log_info, vha, 0x009a, "Need firmware flash update.\n");
8870 ha->flags.running_gold_fw = 1;
8875 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
8878 struct qla_hw_data *ha = vha->hw;
8880 if (ha->flags.pci_channel_io_perm_failure)
8882 if (!IS_FWI2_CAPABLE(ha))
8884 if (!ha->fw_major_version)
8886 if (!ha->flags.fw_started)
8889 ret = qla2x00_stop_firmware(vha);
8890 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
8891 ret != QLA_INVALID_COMMAND && retries ; retries--) {
8892 ha->isp_ops->reset_chip(vha);
8893 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
8895 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
8897 ql_log(ql_log_info, vha, 0x8015,
8898 "Attempting retry of stop-firmware command.\n");
8899 ret = qla2x00_stop_firmware(vha);
8903 ha->flags.fw_init_done = 0;
8907 qla24xx_configure_vhba(scsi_qla_host_t *vha)
8909 int rval = QLA_SUCCESS;
8911 uint16_t mb[MAILBOX_REGISTER_COUNT];
8912 struct qla_hw_data *ha = vha->hw;
8913 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
8918 rval = qla2x00_fw_ready(base_vha);
8920 if (rval == QLA_SUCCESS) {
8921 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8922 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8925 vha->flags.management_server_logged_in = 0;
8927 /* Login to SNS first */
8928 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
8930 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
8931 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
8932 ql_dbg(ql_dbg_init, vha, 0x0120,
8933 "Failed SNS login: loop_id=%x, rval2=%d\n",
8936 ql_dbg(ql_dbg_init, vha, 0x0103,
8937 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
8938 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
8939 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
8940 return (QLA_FUNCTION_FAILED);
8943 atomic_set(&vha->loop_down_timer, 0);
8944 atomic_set(&vha->loop_state, LOOP_UP);
8945 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8946 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
8947 rval = qla2x00_loop_resync(base_vha);
8952 /* 84XX Support **************************************************************/
8954 static LIST_HEAD(qla_cs84xx_list);
8955 static DEFINE_MUTEX(qla_cs84xx_mutex);
8957 static struct qla_chip_state_84xx *
8958 qla84xx_get_chip(struct scsi_qla_host *vha)
8960 struct qla_chip_state_84xx *cs84xx;
8961 struct qla_hw_data *ha = vha->hw;
8963 mutex_lock(&qla_cs84xx_mutex);
8965 /* Find any shared 84xx chip. */
8966 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
8967 if (cs84xx->bus == ha->pdev->bus) {
8968 kref_get(&cs84xx->kref);
8973 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
8977 kref_init(&cs84xx->kref);
8978 spin_lock_init(&cs84xx->access_lock);
8979 mutex_init(&cs84xx->fw_update_mutex);
8980 cs84xx->bus = ha->pdev->bus;
8982 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
8984 mutex_unlock(&qla_cs84xx_mutex);
8989 __qla84xx_chip_release(struct kref *kref)
8991 struct qla_chip_state_84xx *cs84xx =
8992 container_of(kref, struct qla_chip_state_84xx, kref);
8994 mutex_lock(&qla_cs84xx_mutex);
8995 list_del(&cs84xx->list);
8996 mutex_unlock(&qla_cs84xx_mutex);
9001 qla84xx_put_chip(struct scsi_qla_host *vha)
9003 struct qla_hw_data *ha = vha->hw;
9006 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
9010 qla84xx_init_chip(scsi_qla_host_t *vha)
9014 struct qla_hw_data *ha = vha->hw;
9016 mutex_lock(&ha->cs84xx->fw_update_mutex);
9018 rval = qla84xx_verify_chip(vha, status);
9020 mutex_unlock(&ha->cs84xx->fw_update_mutex);
9022 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED :
9026 /* 81XX Support **************************************************************/
9029 qla81xx_nvram_config(scsi_qla_host_t *vha)
9032 struct init_cb_81xx *icb;
9033 struct nvram_81xx *nv;
9035 uint8_t *dptr1, *dptr2;
9038 struct qla_hw_data *ha = vha->hw;
9040 struct active_regions active_regions = { };
9043 icb = (struct init_cb_81xx *)ha->init_cb;
9046 /* Determine NVRAM starting address. */
9047 ha->nvram_size = sizeof(*nv);
9048 ha->vpd_size = FA_NVRAM_VPD_SIZE;
9049 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
9050 ha->vpd_size = FA_VPD_SIZE_82XX;
9052 if (IS_QLA28XX(ha) || IS_QLA27XX(ha))
9053 qla28xx_get_aux_images(vha, &active_regions);
9055 /* Get VPD data into cache */
9056 ha->vpd = ha->nvram + VPD_OFFSET;
9058 faddr = ha->flt_region_vpd;
9059 if (IS_QLA28XX(ha)) {
9060 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
9061 faddr = ha->flt_region_vpd_sec;
9062 ql_dbg(ql_dbg_init, vha, 0x0110,
9063 "Loading %s nvram image.\n",
9064 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
9065 "primary" : "secondary");
9067 ha->isp_ops->read_optrom(vha, ha->vpd, faddr << 2, ha->vpd_size);
9069 /* Get NVRAM data into cache and calculate checksum. */
9070 faddr = ha->flt_region_nvram;
9071 if (IS_QLA28XX(ha)) {
9072 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
9073 faddr = ha->flt_region_nvram_sec;
9075 ql_dbg(ql_dbg_init, vha, 0x0110,
9076 "Loading %s nvram image.\n",
9077 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
9078 "primary" : "secondary");
9079 ha->isp_ops->read_optrom(vha, ha->nvram, faddr << 2, ha->nvram_size);
9081 dptr = (__force __le32 *)nv;
9082 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
9083 chksum += le32_to_cpu(*dptr);
9085 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
9086 "Contents of NVRAM:\n");
9087 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
9088 nv, ha->nvram_size);
9090 /* Bad NVRAM data, set defaults parameters. */
9091 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
9092 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
9093 /* Reset NVRAM data. */
9094 ql_log(ql_log_info, vha, 0x0073,
9095 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
9096 chksum, nv->id, le16_to_cpu(nv->nvram_version));
9097 ql_dump_buffer(ql_dbg_init, vha, 0x0073, nv, sizeof(*nv));
9098 ql_log(ql_log_info, vha, 0x0074,
9099 "Falling back to functioning (yet invalid -- WWPN) "
9103 * Set default initialization control block.
9105 memset(nv, 0, ha->nvram_size);
9106 nv->nvram_version = cpu_to_le16(ICB_VERSION);
9107 nv->version = cpu_to_le16(ICB_VERSION);
9108 nv->frame_payload_size = cpu_to_le16(2048);
9109 nv->execution_throttle = cpu_to_le16(0xFFFF);
9110 nv->exchange_count = cpu_to_le16(0);
9111 nv->port_name[0] = 0x21;
9112 nv->port_name[1] = 0x00 + ha->port_no + 1;
9113 nv->port_name[2] = 0x00;
9114 nv->port_name[3] = 0xe0;
9115 nv->port_name[4] = 0x8b;
9116 nv->port_name[5] = 0x1c;
9117 nv->port_name[6] = 0x55;
9118 nv->port_name[7] = 0x86;
9119 nv->node_name[0] = 0x20;
9120 nv->node_name[1] = 0x00;
9121 nv->node_name[2] = 0x00;
9122 nv->node_name[3] = 0xe0;
9123 nv->node_name[4] = 0x8b;
9124 nv->node_name[5] = 0x1c;
9125 nv->node_name[6] = 0x55;
9126 nv->node_name[7] = 0x86;
9127 nv->login_retry_count = cpu_to_le16(8);
9128 nv->interrupt_delay_timer = cpu_to_le16(0);
9129 nv->login_timeout = cpu_to_le16(0);
9130 nv->firmware_options_1 =
9131 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
9132 nv->firmware_options_2 = cpu_to_le32(2 << 4);
9133 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
9134 nv->firmware_options_3 = cpu_to_le32(2 << 13);
9135 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
9136 nv->efi_parameters = cpu_to_le32(0);
9137 nv->reset_delay = 5;
9138 nv->max_luns_per_target = cpu_to_le16(128);
9139 nv->port_down_retry_count = cpu_to_le16(30);
9140 nv->link_down_timeout = cpu_to_le16(180);
9141 nv->enode_mac[0] = 0x00;
9142 nv->enode_mac[1] = 0xC0;
9143 nv->enode_mac[2] = 0xDD;
9144 nv->enode_mac[3] = 0x04;
9145 nv->enode_mac[4] = 0x05;
9146 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
9151 if (IS_T10_PI_CAPABLE(ha))
9152 nv->frame_payload_size &= cpu_to_le16(~7);
9154 qlt_81xx_config_nvram_stage1(vha, nv);
9156 /* Reset Initialization control block */
9157 memset(icb, 0, ha->init_cb_size);
9159 /* Copy 1st segment. */
9160 dptr1 = (uint8_t *)icb;
9161 dptr2 = (uint8_t *)&nv->version;
9162 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
9164 *dptr1++ = *dptr2++;
9166 icb->login_retry_count = nv->login_retry_count;
9168 /* Copy 2nd segment. */
9169 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
9170 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
9171 cnt = (uint8_t *)&icb->reserved_5 -
9172 (uint8_t *)&icb->interrupt_delay_timer;
9174 *dptr1++ = *dptr2++;
9176 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
9177 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
9178 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
9179 icb->enode_mac[0] = 0x00;
9180 icb->enode_mac[1] = 0xC0;
9181 icb->enode_mac[2] = 0xDD;
9182 icb->enode_mac[3] = 0x04;
9183 icb->enode_mac[4] = 0x05;
9184 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
9187 /* Use extended-initialization control block. */
9188 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
9189 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
9191 * Setup driver NVRAM options.
9193 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
9196 qlt_81xx_config_nvram_stage2(vha, icb);
9198 /* Use alternate WWN? */
9199 if (nv->host_p & cpu_to_le32(BIT_15)) {
9200 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
9201 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
9204 /* Prepare nodename */
9205 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
9207 * Firmware will apply the following mask if the nodename was
9210 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
9211 icb->node_name[0] &= 0xF0;
9214 if (IS_QLA28XX(ha) || IS_QLA27XX(ha)) {
9215 if ((nv->enhanced_features & BIT_7) == 0)
9216 ha->flags.scm_supported_a = 1;
9219 /* Set host adapter parameters. */
9220 ha->flags.disable_risc_code_load = 0;
9221 ha->flags.enable_lip_reset = 0;
9222 ha->flags.enable_lip_full_login =
9223 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
9224 ha->flags.enable_target_reset =
9225 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
9226 ha->flags.enable_led_scheme = 0;
9227 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
9229 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
9230 (BIT_6 | BIT_5 | BIT_4)) >> 4;
9232 /* save HBA serial number */
9233 ha->serial0 = icb->port_name[5];
9234 ha->serial1 = icb->port_name[6];
9235 ha->serial2 = icb->port_name[7];
9236 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
9237 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
9239 icb->execution_throttle = cpu_to_le16(0xFFFF);
9241 ha->retry_count = le16_to_cpu(nv->login_retry_count);
9243 /* Set minimum login_timeout to 4 seconds. */
9244 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
9245 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
9246 if (le16_to_cpu(nv->login_timeout) < 4)
9247 nv->login_timeout = cpu_to_le16(4);
9248 ha->login_timeout = le16_to_cpu(nv->login_timeout);
9250 /* Set minimum RATOV to 100 tenths of a second. */
9253 ha->loop_reset_delay = nv->reset_delay;
9255 /* Link Down Timeout = 0:
9257 * When Port Down timer expires we will start returning
9258 * I/O's to OS with "DID_NO_CONNECT".
9260 * Link Down Timeout != 0:
9262 * The driver waits for the link to come up after link down
9263 * before returning I/Os to OS with "DID_NO_CONNECT".
9265 if (le16_to_cpu(nv->link_down_timeout) == 0) {
9266 ha->loop_down_abort_time =
9267 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
9269 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
9270 ha->loop_down_abort_time =
9271 (LOOP_DOWN_TIME - ha->link_down_timeout);
9274 /* Need enough time to try and get the port back. */
9275 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
9276 if (qlport_down_retry)
9277 ha->port_down_retry_count = qlport_down_retry;
9279 /* Set login_retry_count */
9280 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
9281 if (ha->port_down_retry_count ==
9282 le16_to_cpu(nv->port_down_retry_count) &&
9283 ha->port_down_retry_count > 3)
9284 ha->login_retry_count = ha->port_down_retry_count;
9285 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
9286 ha->login_retry_count = ha->port_down_retry_count;
9287 if (ql2xloginretrycount)
9288 ha->login_retry_count = ql2xloginretrycount;
9290 /* if not running MSI-X we need handshaking on interrupts */
9291 if (!vha->hw->flags.msix_enabled &&
9292 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)))
9293 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
9296 if (!vha->flags.init_done) {
9297 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
9298 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
9299 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
9300 le16_to_cpu(icb->interrupt_delay_timer) : 2;
9302 icb->firmware_options_2 &= cpu_to_le32(
9303 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
9304 vha->flags.process_response_queue = 0;
9305 if (ha->zio_mode != QLA_ZIO_DISABLED) {
9306 ha->zio_mode = QLA_ZIO_MODE_6;
9308 ql_log(ql_log_info, vha, 0x0075,
9309 "ZIO mode %d enabled; timer delay (%d us).\n",
9311 ha->zio_timer * 100);
9313 icb->firmware_options_2 |= cpu_to_le32(
9314 (uint32_t)ha->zio_mode);
9315 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
9316 vha->flags.process_response_queue = 1;
9319 /* enable RIDA Format2 */
9320 icb->firmware_options_3 |= cpu_to_le32(BIT_0);
9322 /* N2N: driver will initiate Login instead of FW */
9323 icb->firmware_options_3 |= cpu_to_le32(BIT_8);
9325 /* Determine NVMe/FCP priority for target ports */
9326 ha->fc4_type_priority = qla2xxx_get_fc4_priority(vha);
9329 ql_log(ql_log_warn, vha, 0x0076,
9330 "NVRAM configuration failed.\n");
9336 qla82xx_restart_isp(scsi_qla_host_t *vha)
9339 struct qla_hw_data *ha = vha->hw;
9340 struct scsi_qla_host *vp, *tvp;
9341 unsigned long flags;
9343 status = qla2x00_init_rings(vha);
9345 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
9346 ha->flags.chip_reset_done = 1;
9348 status = qla2x00_fw_ready(vha);
9350 /* Issue a marker after FW becomes ready. */
9351 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
9352 vha->flags.online = 1;
9353 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
9356 /* if no cable then assume it's good */
9357 if ((vha->device_flags & DFLG_NO_CABLE))
9362 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
9364 if (!atomic_read(&vha->loop_down_timer)) {
9366 * Issue marker command only when we are going
9367 * to start the I/O .
9369 vha->marker_needed = 1;
9372 ha->isp_ops->enable_intrs(ha);
9374 ha->isp_abort_cnt = 0;
9375 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
9377 /* Update the firmware version */
9378 status = qla82xx_check_md_needed(vha);
9381 ha->flags.fce_enabled = 1;
9383 fce_calc_size(ha->fce_bufs));
9384 rval = qla2x00_enable_fce_trace(vha,
9385 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
9388 ql_log(ql_log_warn, vha, 0x8001,
9389 "Unable to reinitialize FCE (%d).\n",
9391 ha->flags.fce_enabled = 0;
9396 memset(ha->eft, 0, EFT_SIZE);
9397 rval = qla2x00_enable_eft_trace(vha,
9398 ha->eft_dma, EFT_NUM_BUFFERS);
9400 ql_log(ql_log_warn, vha, 0x8010,
9401 "Unable to reinitialize EFT (%d).\n",
9408 ql_dbg(ql_dbg_taskm, vha, 0x8011,
9409 "qla82xx_restart_isp succeeded.\n");
9411 spin_lock_irqsave(&ha->vport_slock, flags);
9412 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
9414 atomic_inc(&vp->vref_count);
9415 spin_unlock_irqrestore(&ha->vport_slock, flags);
9417 qla2x00_vp_abort_isp(vp);
9419 spin_lock_irqsave(&ha->vport_slock, flags);
9420 atomic_dec(&vp->vref_count);
9423 spin_unlock_irqrestore(&ha->vport_slock, flags);
9426 ql_log(ql_log_warn, vha, 0x8016,
9427 "qla82xx_restart_isp **** FAILED ****.\n");
9434 * qla24xx_get_fcp_prio
9435 * Gets the fcp cmd priority value for the logged in port.
9436 * Looks for a match of the port descriptors within
9437 * each of the fcp prio config entries. If a match is found,
9438 * the tag (priority) value is returned.
9441 * vha = scsi host structure pointer.
9442 * fcport = port structure pointer.
9445 * non-zero (if found)
9452 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
9455 uint8_t pid_match, wwn_match;
9457 uint32_t pid1, pid2;
9458 uint64_t wwn1, wwn2;
9459 struct qla_fcp_prio_entry *pri_entry;
9460 struct qla_hw_data *ha = vha->hw;
9462 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
9466 entries = ha->fcp_prio_cfg->num_entries;
9467 pri_entry = &ha->fcp_prio_cfg->entry[0];
9469 for (i = 0; i < entries; i++) {
9470 pid_match = wwn_match = 0;
9472 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
9477 /* check source pid for a match */
9478 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
9479 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
9480 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
9481 if (pid1 == INVALID_PORT_ID)
9483 else if (pid1 == pid2)
9487 /* check destination pid for a match */
9488 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
9489 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
9490 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
9491 if (pid1 == INVALID_PORT_ID)
9493 else if (pid1 == pid2)
9497 /* check source WWN for a match */
9498 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
9499 wwn1 = wwn_to_u64(vha->port_name);
9500 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
9501 if (wwn2 == (uint64_t)-1)
9503 else if (wwn1 == wwn2)
9507 /* check destination WWN for a match */
9508 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
9509 wwn1 = wwn_to_u64(fcport->port_name);
9510 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
9511 if (wwn2 == (uint64_t)-1)
9513 else if (wwn1 == wwn2)
9517 if (pid_match == 2 || wwn_match == 2) {
9518 /* Found a matching entry */
9519 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
9520 priority = pri_entry->tag;
9531 * qla24xx_update_fcport_fcp_prio
9532 * Activates fcp priority for the logged in fc port
9535 * vha = scsi host structure pointer.
9536 * fcp = port structure pointer.
9539 * QLA_SUCCESS or QLA_FUNCTION_FAILED
9545 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
9551 if (fcport->port_type != FCT_TARGET ||
9552 fcport->loop_id == FC_NO_LOOP_ID)
9553 return QLA_FUNCTION_FAILED;
9555 priority = qla24xx_get_fcp_prio(vha, fcport);
9557 return QLA_FUNCTION_FAILED;
9559 if (IS_P3P_TYPE(vha->hw)) {
9560 fcport->fcp_prio = priority & 0xf;
9564 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
9565 if (ret == QLA_SUCCESS) {
9566 if (fcport->fcp_prio != priority)
9567 ql_dbg(ql_dbg_user, vha, 0x709e,
9568 "Updated FCP_CMND priority - value=%d loop_id=%d "
9569 "port_id=%02x%02x%02x.\n", priority,
9570 fcport->loop_id, fcport->d_id.b.domain,
9571 fcport->d_id.b.area, fcport->d_id.b.al_pa);
9572 fcport->fcp_prio = priority & 0xf;
9574 ql_dbg(ql_dbg_user, vha, 0x704f,
9575 "Unable to update FCP_CMND priority - ret=0x%x for "
9576 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
9577 fcport->d_id.b.domain, fcport->d_id.b.area,
9578 fcport->d_id.b.al_pa);
9583 * qla24xx_update_all_fcp_prio
9584 * Activates fcp priority for all the logged in ports
9587 * ha = adapter block pointer.
9590 * QLA_SUCCESS or QLA_FUNCTION_FAILED
9596 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
9601 ret = QLA_FUNCTION_FAILED;
9602 /* We need to set priority for all logged in ports */
9603 list_for_each_entry(fcport, &vha->vp_fcports, list)
9604 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
9609 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
9610 int vp_idx, bool startqp)
9615 struct qla_hw_data *ha = vha->hw;
9616 uint16_t qpair_id = 0;
9617 struct qla_qpair *qpair = NULL;
9618 struct qla_msix_entry *msix;
9620 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
9621 ql_log(ql_log_warn, vha, 0x00181,
9622 "FW/Driver is not multi-queue capable.\n");
9626 if (ql2xmqsupport || ql2xnvmeenable) {
9627 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
9628 if (qpair == NULL) {
9629 ql_log(ql_log_warn, vha, 0x0182,
9630 "Failed to allocate memory for queue pair.\n");
9634 qpair->hw = vha->hw;
9636 qpair->qp_lock_ptr = &qpair->qp_lock;
9637 spin_lock_init(&qpair->qp_lock);
9638 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
9640 /* Assign available que pair id */
9641 mutex_lock(&ha->mq_lock);
9642 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
9643 if (ha->num_qpairs >= ha->max_qpairs) {
9644 mutex_unlock(&ha->mq_lock);
9645 ql_log(ql_log_warn, vha, 0x0183,
9646 "No resources to create additional q pair.\n");
9650 set_bit(qpair_id, ha->qpair_qid_map);
9651 ha->queue_pair_map[qpair_id] = qpair;
9652 qpair->id = qpair_id;
9653 qpair->vp_idx = vp_idx;
9654 qpair->fw_started = ha->flags.fw_started;
9655 INIT_LIST_HEAD(&qpair->hints_list);
9656 INIT_LIST_HEAD(&qpair->dsd_list);
9657 qpair->chip_reset = ha->base_qpair->chip_reset;
9658 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
9659 qpair->enable_explicit_conf =
9660 ha->base_qpair->enable_explicit_conf;
9662 for (i = 0; i < ha->msix_count; i++) {
9663 msix = &ha->msix_entries[i];
9667 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
9668 "Vector %x selected for qpair\n", msix->vector);
9672 ql_log(ql_log_warn, vha, 0x0184,
9673 "Out of MSI-X vectors!.\n");
9677 qpair->msix->in_use = 1;
9678 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
9679 qpair->pdev = ha->pdev;
9680 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
9681 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
9683 mutex_unlock(&ha->mq_lock);
9685 /* Create response queue first */
9686 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
9688 ql_log(ql_log_warn, vha, 0x0185,
9689 "Failed to create response queue.\n");
9693 qpair->rsp = ha->rsp_q_map[rsp_id];
9695 /* Create request queue */
9696 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
9699 ql_log(ql_log_warn, vha, 0x0186,
9700 "Failed to create request queue.\n");
9704 qpair->req = ha->req_q_map[req_id];
9705 qpair->rsp->req = qpair->req;
9706 qpair->rsp->qpair = qpair;
9708 if (!qpair->cpu_mapped)
9709 qla_cpu_update(qpair, raw_smp_processor_id());
9711 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
9712 if (ha->fw_attributes & BIT_4)
9713 qpair->difdix_supported = 1;
9716 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
9717 if (!qpair->srb_mempool) {
9718 ql_log(ql_log_warn, vha, 0xd036,
9719 "Failed to create srb mempool for qpair %d\n",
9724 if (qla_create_buf_pool(vha, qpair)) {
9725 ql_log(ql_log_warn, vha, 0xd036,
9726 "Failed to initialize buf pool for qpair %d\n",
9731 /* Mark as online */
9734 if (!vha->flags.qpairs_available)
9735 vha->flags.qpairs_available = 1;
9737 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
9738 "Request/Response queue pair created, id %d\n",
9740 ql_dbg(ql_dbg_init, vha, 0x0187,
9741 "Request/Response queue pair created, id %d\n",
9747 mempool_destroy(qpair->srb_mempool);
9749 qla25xx_delete_req_que(vha, qpair->req);
9751 qla25xx_delete_rsp_que(vha, qpair->rsp);
9753 mutex_lock(&ha->mq_lock);
9754 qpair->msix->in_use = 0;
9755 list_del(&qpair->qp_list_elem);
9756 if (list_empty(&vha->qp_list))
9757 vha->flags.qpairs_available = 0;
9759 ha->queue_pair_map[qpair_id] = NULL;
9760 clear_bit(qpair_id, ha->qpair_qid_map);
9762 mutex_unlock(&ha->mq_lock);
9768 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
9770 int ret = QLA_FUNCTION_FAILED;
9771 struct qla_hw_data *ha = qpair->hw;
9773 qpair->delete_in_progress = 1;
9775 qla_free_buf_pool(qpair);
9777 ret = qla25xx_delete_req_que(vha, qpair->req);
9778 if (ret != QLA_SUCCESS)
9781 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
9782 if (ret != QLA_SUCCESS)
9785 if (!list_empty(&qpair->dsd_list)) {
9786 struct dsd_dma *dsd_ptr, *tdsd_ptr;
9788 /* clean up allocated prev pool */
9789 list_for_each_entry_safe(dsd_ptr, tdsd_ptr,
9790 &qpair->dsd_list, list) {
9791 dma_pool_free(ha->dl_dma_pool, dsd_ptr->dsd_addr,
9792 dsd_ptr->dsd_list_dma);
9793 list_del(&dsd_ptr->list);
9798 mutex_lock(&ha->mq_lock);
9799 ha->queue_pair_map[qpair->id] = NULL;
9800 clear_bit(qpair->id, ha->qpair_qid_map);
9802 list_del(&qpair->qp_list_elem);
9803 if (list_empty(&vha->qp_list)) {
9804 vha->flags.qpairs_available = 0;
9805 vha->flags.qpairs_req_created = 0;
9806 vha->flags.qpairs_rsp_created = 0;
9808 mempool_destroy(qpair->srb_mempool);
9810 mutex_unlock(&ha->mq_lock);
9818 qla2x00_count_set_bits(uint32_t num)
9820 /* Brian Kernighan's Algorithm */
9831 qla2x00_get_num_tgts(scsi_qla_host_t *vha)
9839 list_for_each_entry_safe(f, tf, &vha->vp_fcports, list) {
9840 if (f->port_type != FCT_TARGET)
9847 int qla2xxx_reset_stats(struct Scsi_Host *host, u32 flags)
9849 scsi_qla_host_t *vha = shost_priv(host);
9850 fc_port_t *fcport = NULL;
9851 unsigned long int_flags;
9853 if (flags & QLA2XX_HW_ERROR)
9854 vha->hw_err_cnt = 0;
9855 if (flags & QLA2XX_SHT_LNK_DWN)
9856 vha->short_link_down_cnt = 0;
9857 if (flags & QLA2XX_INT_ERR)
9858 vha->interface_err_cnt = 0;
9859 if (flags & QLA2XX_CMD_TIMEOUT)
9860 vha->cmd_timeout_cnt = 0;
9861 if (flags & QLA2XX_RESET_CMD_ERR)
9862 vha->reset_cmd_err_cnt = 0;
9863 if (flags & QLA2XX_TGT_SHT_LNK_DOWN) {
9864 spin_lock_irqsave(&vha->hw->tgt.sess_lock, int_flags);
9865 list_for_each_entry(fcport, &vha->vp_fcports, list) {
9866 fcport->tgt_short_link_down_cnt = 0;
9867 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
9869 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, int_flags);
9871 vha->link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
9875 int qla2xxx_start_stats(struct Scsi_Host *host, u32 flags)
9877 return qla2xxx_reset_stats(host, flags);
9880 int qla2xxx_stop_stats(struct Scsi_Host *host, u32 flags)
9882 return qla2xxx_reset_stats(host, flags);
9885 int qla2xxx_get_ini_stats(struct Scsi_Host *host, u32 flags,
9886 void *data, u64 size)
9888 scsi_qla_host_t *vha = shost_priv(host);
9889 struct ql_vnd_host_stats_resp *resp = (struct ql_vnd_host_stats_resp *)data;
9890 struct ql_vnd_stats *rsp_data = &resp->stats;
9891 u64 ini_entry_count = 0;
9893 u64 entry_count = 0;
9895 u32 tmp_stat_type = 0;
9896 fc_port_t *fcport = NULL;
9897 unsigned long int_flags;
9899 /* Copy stat type to work on it */
9900 tmp_stat_type = flags;
9902 if (tmp_stat_type & BIT_17) {
9903 num_tgt = qla2x00_get_num_tgts(vha);
9905 tmp_stat_type &= ~(1 << 17);
9907 ini_entry_count = qla2x00_count_set_bits(tmp_stat_type);
9909 entry_count = ini_entry_count + num_tgt;
9911 rsp_data->entry_count = entry_count;
9914 if (flags & QLA2XX_HW_ERROR) {
9915 rsp_data->entry[i].stat_type = QLA2XX_HW_ERROR;
9916 rsp_data->entry[i].tgt_num = 0x0;
9917 rsp_data->entry[i].cnt = vha->hw_err_cnt;
9921 if (flags & QLA2XX_SHT_LNK_DWN) {
9922 rsp_data->entry[i].stat_type = QLA2XX_SHT_LNK_DWN;
9923 rsp_data->entry[i].tgt_num = 0x0;
9924 rsp_data->entry[i].cnt = vha->short_link_down_cnt;
9928 if (flags & QLA2XX_INT_ERR) {
9929 rsp_data->entry[i].stat_type = QLA2XX_INT_ERR;
9930 rsp_data->entry[i].tgt_num = 0x0;
9931 rsp_data->entry[i].cnt = vha->interface_err_cnt;
9935 if (flags & QLA2XX_CMD_TIMEOUT) {
9936 rsp_data->entry[i].stat_type = QLA2XX_CMD_TIMEOUT;
9937 rsp_data->entry[i].tgt_num = 0x0;
9938 rsp_data->entry[i].cnt = vha->cmd_timeout_cnt;
9942 if (flags & QLA2XX_RESET_CMD_ERR) {
9943 rsp_data->entry[i].stat_type = QLA2XX_RESET_CMD_ERR;
9944 rsp_data->entry[i].tgt_num = 0x0;
9945 rsp_data->entry[i].cnt = vha->reset_cmd_err_cnt;
9949 /* i will continue from previous loop, as target
9950 * entries are after initiator
9952 if (flags & QLA2XX_TGT_SHT_LNK_DOWN) {
9953 spin_lock_irqsave(&vha->hw->tgt.sess_lock, int_flags);
9954 list_for_each_entry(fcport, &vha->vp_fcports, list) {
9955 if (fcport->port_type != FCT_TARGET)
9959 rsp_data->entry[i].stat_type = QLA2XX_TGT_SHT_LNK_DOWN;
9960 rsp_data->entry[i].tgt_num = fcport->rport->number;
9961 rsp_data->entry[i].cnt = fcport->tgt_short_link_down_cnt;
9964 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, int_flags);
9966 resp->status = EXT_STATUS_OK;
9971 int qla2xxx_get_tgt_stats(struct Scsi_Host *host, u32 flags,
9972 struct fc_rport *rport, void *data, u64 size)
9974 struct ql_vnd_tgt_stats_resp *tgt_data = data;
9975 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
9977 tgt_data->status = 0;
9978 tgt_data->stats.entry_count = 1;
9979 tgt_data->stats.entry[0].stat_type = flags;
9980 tgt_data->stats.entry[0].tgt_num = rport->number;
9981 tgt_data->stats.entry[0].cnt = fcport->tgt_short_link_down_cnt;
9986 int qla2xxx_disable_port(struct Scsi_Host *host)
9988 scsi_qla_host_t *vha = shost_priv(host);
9990 vha->hw->flags.port_isolated = 1;
9992 if (qla2x00_isp_reg_stat(vha->hw)) {
9993 ql_log(ql_log_info, vha, 0x9006,
9994 "PCI/Register disconnect, exiting.\n");
9995 qla_pci_set_eeh_busy(vha);
9998 if (qla2x00_chip_is_down(vha))
10001 if (vha->flags.online) {
10002 qla2x00_abort_isp_cleanup(vha);
10003 qla2x00_wait_for_sess_deletion(vha);
10009 int qla2xxx_enable_port(struct Scsi_Host *host)
10011 scsi_qla_host_t *vha = shost_priv(host);
10013 if (qla2x00_isp_reg_stat(vha->hw)) {
10014 ql_log(ql_log_info, vha, 0x9001,
10015 "PCI/Register disconnect, exiting.\n");
10016 qla_pci_set_eeh_busy(vha);
10020 vha->hw->flags.port_isolated = 0;
10021 /* Set the flag to 1, so that isp_abort can proceed */
10022 vha->flags.online = 1;
10023 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
10024 qla2xxx_wake_dpc(vha);