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);
1199 fcport->flags &= ~(FCF_ASYNC_ACTIVE | FCF_ASYNC_SENT);
1203 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1205 struct qla_work_evt *e;
1207 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
1209 return QLA_FUNCTION_FAILED;
1211 e->u.fcport.fcport = fcport;
1212 fcport->flags |= FCF_ASYNC_ACTIVE;
1213 return qla2x00_post_work(vha, e);
1216 static void qla24xx_async_gpdb_sp_done(srb_t *sp, int res)
1218 struct scsi_qla_host *vha = sp->vha;
1219 struct qla_hw_data *ha = vha->hw;
1220 fc_port_t *fcport = sp->fcport;
1221 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
1222 struct event_arg ea;
1224 ql_dbg(ql_dbg_disc, vha, 0x20db,
1225 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
1226 sp->name, res, fcport->port_name, mb[1], mb[2]);
1228 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1230 if (res == QLA_FUNCTION_TIMEOUT)
1233 memset(&ea, 0, sizeof(ea));
1237 qla24xx_handle_gpdb_event(vha, &ea);
1240 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
1241 sp->u.iocb_cmd.u.mbx.in_dma);
1243 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1246 int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1248 struct qla_work_evt *e;
1250 if (vha->host->active_mode == MODE_TARGET)
1251 return QLA_FUNCTION_FAILED;
1253 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
1255 return QLA_FUNCTION_FAILED;
1257 e->u.fcport.fcport = fcport;
1259 return qla2x00_post_work(vha, e);
1262 static void qla2x00_async_prli_sp_done(srb_t *sp, int res)
1264 struct scsi_qla_host *vha = sp->vha;
1265 struct srb_iocb *lio = &sp->u.iocb_cmd;
1266 struct event_arg ea;
1268 ql_dbg(ql_dbg_disc, vha, 0x2129,
1269 "%s %8phC res %x\n", __func__,
1270 sp->fcport->port_name, res);
1272 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1274 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
1275 memset(&ea, 0, sizeof(ea));
1276 ea.fcport = sp->fcport;
1277 ea.data[0] = lio->u.logio.data[0];
1278 ea.data[1] = lio->u.logio.data[1];
1279 ea.iop[0] = lio->u.logio.iop[0];
1280 ea.iop[1] = lio->u.logio.iop[1];
1282 if (res == QLA_OS_TIMER_EXPIRED)
1283 ea.data[0] = QLA_OS_TIMER_EXPIRED;
1285 ea.data[0] = MBS_COMMAND_ERROR;
1287 qla24xx_handle_prli_done_event(vha, &ea);
1290 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1294 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
1297 struct srb_iocb *lio;
1298 int rval = QLA_FUNCTION_FAILED;
1300 if (!vha->flags.online) {
1301 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1302 __func__, __LINE__, fcport->port_name);
1306 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
1307 fcport->fw_login_state == DSC_LS_PRLI_PEND) &&
1308 qla_dual_mode_enabled(vha)) {
1309 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1310 __func__, __LINE__, fcport->port_name);
1314 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1318 fcport->flags |= FCF_ASYNC_SENT;
1319 fcport->logout_completed = 0;
1321 sp->type = SRB_PRLI_CMD;
1323 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
1324 qla2x00_async_prli_sp_done);
1326 lio = &sp->u.iocb_cmd;
1327 lio->u.logio.flags = 0;
1329 if (NVME_TARGET(vha->hw, fcport))
1330 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
1332 ql_dbg(ql_dbg_disc, vha, 0x211b,
1333 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d fc4type %x priority %x %s.\n",
1334 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24,
1335 fcport->login_retry, fcport->fc4_type, vha->hw->fc4_type_priority,
1336 NVME_TARGET(vha->hw, fcport) ? "nvme" : "fcp");
1338 rval = qla2x00_start_sp(sp);
1339 if (rval != QLA_SUCCESS) {
1340 fcport->flags |= FCF_LOGIN_NEEDED;
1341 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1349 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1350 fcport->flags &= ~FCF_ASYNC_SENT;
1354 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1356 struct qla_work_evt *e;
1358 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
1360 return QLA_FUNCTION_FAILED;
1362 e->u.fcport.fcport = fcport;
1363 e->u.fcport.opt = opt;
1364 fcport->flags |= FCF_ASYNC_ACTIVE;
1365 return qla2x00_post_work(vha, e);
1368 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1371 struct srb_iocb *mbx;
1372 int rval = QLA_FUNCTION_FAILED;
1375 struct port_database_24xx *pd;
1376 struct qla_hw_data *ha = vha->hw;
1378 if (IS_SESSION_DELETED(fcport)) {
1379 ql_log(ql_log_warn, vha, 0xffff,
1380 "%s: %8phC is being delete - not sending command.\n",
1381 __func__, fcport->port_name);
1382 fcport->flags &= ~FCF_ASYNC_ACTIVE;
1386 if (!vha->flags.online || fcport->flags & FCF_ASYNC_SENT) {
1387 ql_log(ql_log_warn, vha, 0xffff,
1388 "%s: %8phC online %d flags %x - not sending command.\n",
1389 __func__, fcport->port_name, vha->flags.online, fcport->flags);
1393 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1397 qla2x00_set_fcport_disc_state(fcport, DSC_GPDB);
1399 fcport->flags |= FCF_ASYNC_SENT;
1400 sp->type = SRB_MB_IOCB;
1402 sp->gen1 = fcport->rscn_gen;
1403 sp->gen2 = fcport->login_gen;
1404 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
1405 qla24xx_async_gpdb_sp_done);
1407 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1409 ql_log(ql_log_warn, vha, 0xd043,
1410 "Failed to allocate port database structure.\n");
1414 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1415 mb[0] = MBC_GET_PORT_DATABASE;
1416 mb[1] = fcport->loop_id;
1417 mb[2] = MSW(pd_dma);
1418 mb[3] = LSW(pd_dma);
1419 mb[6] = MSW(MSD(pd_dma));
1420 mb[7] = LSW(MSD(pd_dma));
1421 mb[9] = vha->vp_idx;
1424 mbx = &sp->u.iocb_cmd;
1425 mbx->u.mbx.in = (void *)pd;
1426 mbx->u.mbx.in_dma = pd_dma;
1428 ql_dbg(ql_dbg_disc, vha, 0x20dc,
1429 "Async-%s %8phC hndl %x opt %x\n",
1430 sp->name, fcport->port_name, sp->handle, opt);
1432 rval = qla2x00_start_sp(sp);
1433 if (rval != QLA_SUCCESS)
1439 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1441 kref_put(&sp->cmd_kref, qla2x00_sp_release);
1442 fcport->flags &= ~FCF_ASYNC_SENT;
1444 fcport->flags &= ~FCF_ASYNC_ACTIVE;
1445 qla24xx_post_gpdb_work(vha, fcport, opt);
1450 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1452 unsigned long flags;
1454 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1455 ea->fcport->login_gen++;
1456 ea->fcport->logout_on_delete = 1;
1458 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1459 vha->fcport_count++;
1460 ea->fcport->login_succ = 1;
1462 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1463 qla24xx_sched_upd_fcport(ea->fcport);
1464 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1465 } else if (ea->fcport->login_succ) {
1467 * We have an existing session. A late RSCN delivery
1468 * must have triggered the session to be re-validate.
1469 * Session is still valid.
1471 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1472 "%s %d %8phC session revalidate success\n",
1473 __func__, __LINE__, ea->fcport->port_name);
1474 qla2x00_set_fcport_disc_state(ea->fcport, DSC_LOGIN_COMPLETE);
1476 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1479 static int qla_chk_secure_login(scsi_qla_host_t *vha, fc_port_t *fcport,
1480 struct port_database_24xx *pd)
1484 if (pd->secure_login) {
1485 ql_dbg(ql_dbg_disc, vha, 0x104d,
1486 "Secure Login established on %8phC\n",
1488 fcport->flags |= FCF_FCSP_DEVICE;
1490 ql_dbg(ql_dbg_disc, vha, 0x104d,
1491 "non-Secure Login %8phC",
1493 fcport->flags &= ~FCF_FCSP_DEVICE;
1495 if (vha->hw->flags.edif_enabled) {
1496 if (fcport->flags & FCF_FCSP_DEVICE) {
1497 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_AUTH_PEND);
1498 /* Start edif prli timer & ring doorbell for app */
1499 fcport->edif.rx_sa_set = 0;
1500 fcport->edif.tx_sa_set = 0;
1501 fcport->edif.rx_sa_pending = 0;
1502 fcport->edif.tx_sa_pending = 0;
1504 qla2x00_post_aen_work(vha, FCH_EVT_PORT_ONLINE,
1507 if (DBELL_ACTIVE(vha)) {
1508 ql_dbg(ql_dbg_disc, vha, 0x20ef,
1509 "%s %d %8phC EDIF: post DB_AUTH: AUTH needed\n",
1510 __func__, __LINE__, fcport->port_name);
1511 fcport->edif.app_sess_online = 1;
1513 qla_edb_eventcreate(vha, VND_CMD_AUTH_STATE_NEEDED,
1514 fcport->d_id.b24, 0, fcport);
1518 } else if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
1519 ql_dbg(ql_dbg_disc, vha, 0x2117,
1520 "%s %d %8phC post prli\n",
1521 __func__, __LINE__, fcport->port_name);
1522 qla24xx_post_prli_work(vha, fcport);
1530 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1532 fc_port_t *fcport = ea->fcport;
1533 struct port_database_24xx *pd;
1534 struct srb *sp = ea->sp;
1537 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1539 fcport->flags &= ~FCF_ASYNC_SENT;
1541 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1542 "%s %8phC DS %d LS %x fc4_type %x rc %x\n", __func__,
1543 fcport->port_name, fcport->disc_state, pd->current_login_state,
1544 fcport->fc4_type, ea->rc);
1546 if (fcport->disc_state == DSC_DELETE_PEND) {
1547 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC\n",
1548 __func__, __LINE__, fcport->port_name);
1552 if (NVME_TARGET(vha->hw, fcport))
1553 ls = pd->current_login_state >> 4;
1555 ls = pd->current_login_state & 0xf;
1557 if (ea->sp->gen2 != fcport->login_gen) {
1558 /* target side must have changed it. */
1560 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1561 "%s %8phC generation changed\n",
1562 __func__, fcport->port_name);
1564 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1565 qla_rscn_replay(fcport);
1566 qlt_schedule_sess_for_deletion(fcport);
1567 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n",
1568 __func__, __LINE__, fcport->port_name, ls);
1573 case PDS_PRLI_COMPLETE:
1574 __qla24xx_parse_gpdb(vha, fcport, pd);
1576 case PDS_PLOGI_COMPLETE:
1577 if (qla_chk_secure_login(vha, fcport, pd)) {
1578 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n",
1579 __func__, __LINE__, fcport->port_name, ls);
1583 case PDS_PLOGI_PENDING:
1584 case PDS_PRLI_PENDING:
1585 case PDS_PRLI2_PENDING:
1586 /* Set discovery state back to GNL to Relogin attempt */
1587 if (qla_dual_mode_enabled(vha) ||
1588 qla_ini_mode_enabled(vha)) {
1589 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
1590 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1592 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n",
1593 __func__, __LINE__, fcport->port_name, ls);
1595 case PDS_LOGO_PENDING:
1596 case PDS_PORT_UNAVAILABLE:
1598 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1599 __func__, __LINE__, fcport->port_name);
1600 qlt_schedule_sess_for_deletion(fcport);
1603 __qla24xx_handle_gpdb_event(vha, ea);
1606 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1611 ql_dbg(ql_dbg_disc, vha, 0x307b,
1612 "%s %8phC DS %d LS %d lid %d retries=%d\n",
1613 __func__, fcport->port_name, fcport->disc_state,
1614 fcport->fw_login_state, fcport->loop_id, fcport->login_retry);
1616 if (qla_tgt_mode_enabled(vha))
1619 if (qla_dual_mode_enabled(vha)) {
1620 if (N2N_TOPO(vha->hw)) {
1623 mywwn = wwn_to_u64(vha->port_name);
1624 wwn = wwn_to_u64(fcport->port_name);
1627 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1628 && time_after_eq(jiffies,
1629 fcport->plogi_nack_done_deadline))
1635 /* initiator mode */
1639 if (login && fcport->login_retry) {
1640 fcport->login_retry--;
1641 if (fcport->loop_id == FC_NO_LOOP_ID) {
1642 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1643 rc = qla2x00_find_new_loop_id(vha, fcport);
1645 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1646 "%s %d %8phC post del sess - out of loopid\n",
1647 __func__, __LINE__, fcport->port_name);
1648 fcport->scan_state = 0;
1649 qlt_schedule_sess_for_deletion(fcport);
1653 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1654 "%s %d %8phC post login\n",
1655 __func__, __LINE__, fcport->port_name);
1656 qla2x00_post_async_login_work(vha, fcport, NULL);
1660 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1665 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1666 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d fc4type %x\n",
1667 __func__, fcport->port_name, fcport->disc_state,
1668 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1669 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1670 fcport->login_gen, fcport->loop_id, fcport->scan_state,
1673 if (fcport->scan_state != QLA_FCPORT_FOUND ||
1674 fcport->disc_state == DSC_DELETE_PEND)
1677 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1678 qla_dual_mode_enabled(vha) &&
1679 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1680 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1683 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP &&
1684 !N2N_TOPO(vha->hw)) {
1685 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1686 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1691 /* Target won't initiate port login if fabric is present */
1692 if (vha->host->active_mode == MODE_TARGET && !N2N_TOPO(vha->hw))
1695 if (fcport->flags & (FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE)) {
1696 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1700 switch (fcport->disc_state) {
1702 switch (vha->hw->current_topology) {
1704 if (fcport_is_smaller(fcport)) {
1705 /* this adapter is bigger */
1706 if (fcport->login_retry) {
1707 if (fcport->loop_id == FC_NO_LOOP_ID) {
1708 qla2x00_find_new_loop_id(vha,
1710 fcport->fw_login_state =
1711 DSC_LS_PORT_UNAVAIL;
1713 fcport->login_retry--;
1714 qla_post_els_plogi_work(vha, fcport);
1716 ql_log(ql_log_info, vha, 0x705d,
1717 "Unable to reach remote port %8phC",
1721 qla24xx_post_gnl_work(vha, fcport);
1725 if (fcport->loop_id == FC_NO_LOOP_ID) {
1726 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1727 "%s %d %8phC post gnl\n",
1728 __func__, __LINE__, fcport->port_name);
1729 qla24xx_post_gnl_work(vha, fcport);
1731 qla_chk_n2n_b4_login(vha, fcport);
1738 switch (vha->hw->current_topology) {
1740 if ((fcport->current_login_state & 0xf) == 0x6) {
1741 ql_dbg(ql_dbg_disc, vha, 0x2118,
1742 "%s %d %8phC post GPDB work\n",
1743 __func__, __LINE__, fcport->port_name);
1744 fcport->chip_reset =
1745 vha->hw->base_qpair->chip_reset;
1746 qla24xx_post_gpdb_work(vha, fcport, 0);
1748 ql_dbg(ql_dbg_disc, vha, 0x2118,
1749 "%s %d %8phC post %s PRLI\n",
1750 __func__, __LINE__, fcport->port_name,
1751 NVME_TARGET(vha->hw, fcport) ? "NVME" :
1753 qla24xx_post_prli_work(vha, fcport);
1757 if (fcport->login_pause) {
1758 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1759 "%s %d %8phC exit\n",
1762 fcport->last_rscn_gen = fcport->rscn_gen;
1763 fcport->last_login_gen = fcport->login_gen;
1764 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1767 qla_chk_n2n_b4_login(vha, fcport);
1772 case DSC_LOGIN_FAILED:
1773 if (N2N_TOPO(vha->hw))
1774 qla_chk_n2n_b4_login(vha, fcport);
1776 qlt_schedule_sess_for_deletion(fcport);
1779 case DSC_LOGIN_COMPLETE:
1780 /* recheck login state */
1781 data[0] = data[1] = 0;
1782 qla2x00_post_async_adisc_work(vha, fcport, data);
1785 case DSC_LOGIN_PEND:
1786 if (vha->hw->flags.edif_enabled)
1789 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1790 ql_dbg(ql_dbg_disc, vha, 0x2118,
1791 "%s %d %8phC post %s PRLI\n",
1792 __func__, __LINE__, fcport->port_name,
1793 NVME_TARGET(vha->hw, fcport) ? "NVME" : "FC");
1794 qla24xx_post_prli_work(vha, fcport);
1798 case DSC_UPD_FCPORT:
1799 sec = jiffies_to_msecs(jiffies -
1800 fcport->jiffies_at_registration)/1000;
1801 if (fcport->sec_since_registration < sec && sec &&
1803 fcport->sec_since_registration = sec;
1804 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
1805 "%s %8phC - Slow Rport registration(%d Sec)\n",
1806 __func__, fcport->port_name, sec);
1809 if (fcport->next_disc_state != DSC_DELETE_PEND)
1810 fcport->next_disc_state = DSC_ADISC;
1811 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1821 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1822 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1824 struct qla_work_evt *e;
1826 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1828 return QLA_FUNCTION_FAILED;
1830 e->u.new_sess.id = *id;
1831 e->u.new_sess.pla = pla;
1832 e->u.new_sess.fc4_type = fc4_type;
1833 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1835 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1837 return qla2x00_post_work(vha, e);
1840 void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
1843 unsigned long flags;
1845 switch (ea->id.b.rsvd_1) {
1846 case RSCN_PORT_ADDR:
1847 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1849 if (ql2xfc2target &&
1850 fcport->flags & FCF_FCP2_DEVICE &&
1851 atomic_read(&fcport->state) == FCS_ONLINE) {
1852 ql_dbg(ql_dbg_disc, vha, 0x2115,
1853 "Delaying session delete for FCP2 portid=%06x %8phC ",
1854 fcport->d_id.b24, fcport->port_name);
1858 if (vha->hw->flags.edif_enabled && DBELL_ACTIVE(vha)) {
1860 * On ipsec start by remote port, Target port
1861 * may use RSCN to trigger initiator to
1862 * relogin. If driver is already in the
1863 * process of a relogin, then ignore the RSCN
1864 * and allow the current relogin to continue.
1865 * This reduces thrashing of the connection.
1867 if (atomic_read(&fcport->state) == FCS_ONLINE) {
1869 * If state = online, then set scan_needed=1 to do relogin.
1870 * Otherwise we're already in the middle of a relogin
1872 fcport->scan_needed = 1;
1876 fcport->scan_needed = 1;
1881 case RSCN_AREA_ADDR:
1882 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1883 if (fcport->flags & FCF_FCP2_DEVICE &&
1884 atomic_read(&fcport->state) == FCS_ONLINE)
1887 if ((ea->id.b24 & 0xffff00) == (fcport->d_id.b24 & 0xffff00)) {
1888 fcport->scan_needed = 1;
1894 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1895 if (fcport->flags & FCF_FCP2_DEVICE &&
1896 atomic_read(&fcport->state) == FCS_ONLINE)
1899 if ((ea->id.b24 & 0xff0000) == (fcport->d_id.b24 & 0xff0000)) {
1900 fcport->scan_needed = 1;
1907 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1908 if (fcport->flags & FCF_FCP2_DEVICE &&
1909 atomic_read(&fcport->state) == FCS_ONLINE)
1912 fcport->scan_needed = 1;
1918 spin_lock_irqsave(&vha->work_lock, flags);
1919 if (vha->scan.scan_flags == 0) {
1920 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s: schedule\n", __func__);
1921 vha->scan.scan_flags |= SF_QUEUED;
1922 schedule_delayed_work(&vha->scan.scan_work, 5);
1924 spin_unlock_irqrestore(&vha->work_lock, flags);
1927 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1928 struct event_arg *ea)
1930 fc_port_t *fcport = ea->fcport;
1932 if (test_bit(UNLOADING, &vha->dpc_flags))
1935 ql_dbg(ql_dbg_disc, vha, 0x2102,
1936 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1937 __func__, fcport->port_name, fcport->disc_state,
1938 fcport->fw_login_state, fcport->login_pause,
1939 fcport->deleted, fcport->conflict,
1940 fcport->last_rscn_gen, fcport->rscn_gen,
1941 fcport->last_login_gen, fcport->login_gen,
1944 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1945 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gnl\n",
1946 __func__, __LINE__, fcport->port_name);
1947 qla24xx_post_gnl_work(vha, fcport);
1951 qla24xx_fcport_handle_login(vha, fcport);
1954 void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
1955 struct event_arg *ea)
1957 if (N2N_TOPO(vha->hw) && fcport_is_smaller(ea->fcport) &&
1958 vha->hw->flags.edif_enabled) {
1959 /* check to see if App support Secure */
1960 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1964 /* for pure Target Mode, PRLI will not be initiated */
1965 if (vha->host->active_mode == MODE_TARGET)
1968 ql_dbg(ql_dbg_disc, vha, 0x2118,
1969 "%s %d %8phC post PRLI\n",
1970 __func__, __LINE__, ea->fcport->port_name);
1971 qla24xx_post_prli_work(vha, ea->fcport);
1975 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1976 * to be consumed by the fcport
1978 void qla_rscn_replay(fc_port_t *fcport)
1980 struct event_arg ea;
1982 switch (fcport->disc_state) {
1983 case DSC_DELETE_PEND:
1989 if (fcport->scan_needed) {
1990 memset(&ea, 0, sizeof(ea));
1991 ea.id = fcport->d_id;
1992 ea.id.b.rsvd_1 = RSCN_PORT_ADDR;
1993 qla2x00_handle_rscn(fcport->vha, &ea);
1998 qla2x00_tmf_iocb_timeout(void *data)
2001 struct srb_iocb *tmf = &sp->u.iocb_cmd;
2003 unsigned long flags;
2005 if (sp->type == SRB_MARKER) {
2006 complete(&tmf->u.tmf.comp);
2010 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) \
2045 _rval = qla2x00_start_sp(_sp); \
2046 if (_rval == EAGAIN) \
2055 * qla26xx_marker: send marker IOCB and wait for the completion of it.
2056 * @arg: pointer to argument list.
2057 * It is assume caller will provide an fcport pointer and modifier
2060 qla26xx_marker(struct tmf_arg *arg)
2062 struct scsi_qla_host *vha = arg->vha;
2063 struct srb_iocb *tm_iocb;
2065 int rval = QLA_FUNCTION_FAILED;
2066 fc_port_t *fcport = arg->fcport;
2068 if (TMF_NOT_READY(arg->fcport)) {
2069 ql_dbg(ql_dbg_taskm, vha, 0x8039,
2070 "FC port not ready for marker loop-id=%x portid=%06x modifier=%x lun=%lld qp=%d.\n",
2071 fcport->loop_id, fcport->d_id.b24,
2072 arg->modifier, arg->lun, arg->qpair->id);
2073 return QLA_SUSPENDED;
2077 sp = qla2xxx_get_qpair_sp(vha, arg->qpair, fcport, GFP_KERNEL);
2081 sp->type = SRB_MARKER;
2082 sp->name = "marker";
2083 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha), qla_marker_sp_done);
2084 sp->u.iocb_cmd.timeout = qla2x00_tmf_iocb_timeout;
2086 tm_iocb = &sp->u.iocb_cmd;
2087 init_completion(&tm_iocb->u.tmf.comp);
2088 tm_iocb->u.tmf.modifier = arg->modifier;
2089 tm_iocb->u.tmf.lun = arg->lun;
2090 tm_iocb->u.tmf.loop_id = fcport->loop_id;
2091 tm_iocb->u.tmf.vp_index = vha->vp_idx;
2093 START_SP_W_RETRIES(sp, rval);
2095 ql_dbg(ql_dbg_taskm, vha, 0x8006,
2096 "Async-marker hdl=%x loop-id=%x portid=%06x modifier=%x lun=%lld qp=%d rval %d.\n",
2097 sp->handle, fcport->loop_id, fcport->d_id.b24,
2098 arg->modifier, arg->lun, sp->qpair->id, rval);
2100 if (rval != QLA_SUCCESS) {
2101 ql_log(ql_log_warn, vha, 0x8031,
2102 "Marker IOCB send failure (%x).\n", rval);
2106 wait_for_completion(&tm_iocb->u.tmf.comp);
2107 rval = tm_iocb->u.tmf.data;
2109 if (rval != QLA_SUCCESS) {
2110 ql_log(ql_log_warn, vha, 0x8019,
2111 "Marker failed hdl=%x loop-id=%x portid=%06x modifier=%x lun=%lld qp=%d rval %d.\n",
2112 sp->handle, fcport->loop_id, fcport->d_id.b24,
2113 arg->modifier, arg->lun, sp->qpair->id, rval);
2118 kref_put(&sp->cmd_kref, qla2x00_sp_release);
2123 static void qla2x00_tmf_sp_done(srb_t *sp, int res)
2125 struct srb_iocb *tmf = &sp->u.iocb_cmd;
2128 tmf->u.tmf.data = res;
2129 complete(&tmf->u.tmf.comp);
2133 __qla2x00_async_tm_cmd(struct tmf_arg *arg)
2135 struct scsi_qla_host *vha = arg->vha;
2136 struct srb_iocb *tm_iocb;
2138 int rval = QLA_FUNCTION_FAILED;
2140 fc_port_t *fcport = arg->fcport;
2142 if (TMF_NOT_READY(arg->fcport)) {
2143 ql_dbg(ql_dbg_taskm, vha, 0x8032,
2144 "FC port not ready for TM command loop-id=%x portid=%06x modifier=%x lun=%lld qp=%d.\n",
2145 fcport->loop_id, fcport->d_id.b24,
2146 arg->modifier, arg->lun, arg->qpair->id);
2147 return QLA_SUSPENDED;
2151 sp = qla2xxx_get_qpair_sp(vha, arg->qpair, fcport, GFP_KERNEL);
2155 qla_vha_mark_busy(vha);
2156 sp->type = SRB_TM_CMD;
2158 qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha),
2159 qla2x00_tmf_sp_done);
2160 sp->u.iocb_cmd.timeout = qla2x00_tmf_iocb_timeout;
2162 tm_iocb = &sp->u.iocb_cmd;
2163 init_completion(&tm_iocb->u.tmf.comp);
2164 tm_iocb->u.tmf.flags = arg->flags;
2165 tm_iocb->u.tmf.lun = arg->lun;
2167 START_SP_W_RETRIES(sp, rval);
2169 ql_dbg(ql_dbg_taskm, vha, 0x802f,
2170 "Async-tmf hdl=%x loop-id=%x portid=%06x ctrl=%x lun=%lld qp=%d rval=%x.\n",
2171 sp->handle, fcport->loop_id, fcport->d_id.b24,
2172 arg->flags, arg->lun, sp->qpair->id, rval);
2174 if (rval != QLA_SUCCESS)
2176 wait_for_completion(&tm_iocb->u.tmf.comp);
2178 rval = tm_iocb->u.tmf.data;
2180 if (rval != QLA_SUCCESS) {
2181 ql_log(ql_log_warn, vha, 0x8030,
2182 "TM IOCB failed (%x).\n", rval);
2185 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw))
2186 rval = qla26xx_marker(arg);
2190 kref_put(&sp->cmd_kref, qla2x00_sp_release);
2195 static void qla_put_tmf(fc_port_t *fcport)
2197 struct scsi_qla_host *vha = fcport->vha;
2198 struct qla_hw_data *ha = vha->hw;
2199 unsigned long flags;
2201 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
2202 fcport->active_tmf--;
2203 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
2207 int qla_get_tmf(fc_port_t *fcport)
2209 struct scsi_qla_host *vha = fcport->vha;
2210 struct qla_hw_data *ha = vha->hw;
2211 unsigned long flags;
2213 LIST_HEAD(tmf_elem);
2215 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
2216 list_add_tail(&tmf_elem, &fcport->tmf_pending);
2218 while (fcport->active_tmf >= MAX_ACTIVE_TMF) {
2219 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
2223 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
2224 if (TMF_NOT_READY(fcport)) {
2225 ql_log(ql_log_warn, vha, 0x802c,
2226 "Unable to acquire TM resource due to disruption.\n");
2230 if (fcport->active_tmf < MAX_ACTIVE_TMF &&
2231 list_is_first(&tmf_elem, &fcport->tmf_pending))
2235 list_del(&tmf_elem);
2238 fcport->active_tmf++;
2240 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
2246 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint64_t lun,
2249 struct scsi_qla_host *vha = fcport->vha;
2250 struct qla_qpair *qpair;
2252 int i, rval = QLA_SUCCESS;
2254 if (TMF_NOT_READY(fcport))
2255 return QLA_SUSPENDED;
2257 a.vha = fcport->vha;
2260 if (flags & (TCF_LUN_RESET|TCF_ABORT_TASK_SET|TCF_CLEAR_TASK_SET|TCF_CLEAR_ACA)) {
2261 a.modifier = MK_SYNC_ID_LUN;
2263 if (qla_get_tmf(fcport))
2264 return QLA_FUNCTION_FAILED;
2266 a.modifier = MK_SYNC_ID;
2269 if (vha->hw->mqenable) {
2270 for (i = 0; i < vha->hw->num_qpairs; i++) {
2271 qpair = vha->hw->queue_pair_map[i];
2275 if (TMF_NOT_READY(fcport)) {
2276 ql_log(ql_log_warn, vha, 0x8026,
2277 "Unable to send TM due to disruption.\n");
2278 rval = QLA_SUSPENDED;
2283 a.flags = flags|TCF_NOTMCMD_TO_TARGET;
2284 rval = __qla2x00_async_tm_cmd(&a);
2293 a.qpair = vha->hw->base_qpair;
2295 rval = __qla2x00_async_tm_cmd(&a);
2298 if (a.modifier == MK_SYNC_ID_LUN)
2299 qla_put_tmf(fcport);
2305 qla24xx_async_abort_command(srb_t *sp)
2307 unsigned long flags = 0;
2310 fc_port_t *fcport = sp->fcport;
2311 struct qla_qpair *qpair = sp->qpair;
2312 struct scsi_qla_host *vha = fcport->vha;
2313 struct req_que *req = qpair->req;
2315 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
2316 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
2317 if (req->outstanding_cmds[handle] == sp)
2320 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
2322 if (handle == req->num_outstanding_cmds) {
2323 /* Command not found. */
2324 return QLA_ERR_NOT_FOUND;
2326 if (sp->type == SRB_FXIOCB_DCMD)
2327 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
2328 FXDISC_ABORT_IOCTL);
2330 return qla24xx_async_abort_cmd(sp, true);
2334 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
2337 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
2340 switch (ea->data[0]) {
2341 case MBS_COMMAND_COMPLETE:
2342 ql_dbg(ql_dbg_disc, vha, 0x2118,
2343 "%s %d %8phC post gpdb\n",
2344 __func__, __LINE__, ea->fcport->port_name);
2346 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2347 ea->fcport->logout_on_delete = 1;
2348 ea->fcport->nvme_prli_service_param = ea->iop[0];
2349 if (ea->iop[0] & NVME_PRLI_SP_FIRST_BURST)
2350 ea->fcport->nvme_first_burst_size =
2351 (ea->iop[1] & 0xffff) * 512;
2353 ea->fcport->nvme_first_burst_size = 0;
2354 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2358 ql_dbg(ql_dbg_disc, vha, 0x2118,
2359 "%s %d %8phC priority %s, fc4type %x prev try %s\n",
2360 __func__, __LINE__, ea->fcport->port_name,
2361 vha->hw->fc4_type_priority == FC4_PRIORITY_FCP ?
2362 "FCP" : "NVMe", ea->fcport->fc4_type,
2363 (sp->u.iocb_cmd.u.logio.flags & SRB_LOGIN_NVME_PRLI) ?
2366 if (NVME_FCP_TARGET(ea->fcport)) {
2367 if (sp->u.iocb_cmd.u.logio.flags & SRB_LOGIN_NVME_PRLI)
2368 ea->fcport->do_prli_nvme = 0;
2370 ea->fcport->do_prli_nvme = 1;
2372 ea->fcport->do_prli_nvme = 0;
2375 if (N2N_TOPO(vha->hw)) {
2376 if (ea->fcport->n2n_link_reset_cnt ==
2377 vha->hw->login_retry_count &&
2378 ea->fcport->flags & FCF_FCSP_DEVICE) {
2379 /* remote authentication app just started */
2380 ea->fcport->n2n_link_reset_cnt = 0;
2383 if (ea->fcport->n2n_link_reset_cnt <
2384 vha->hw->login_retry_count) {
2385 ea->fcport->n2n_link_reset_cnt++;
2386 vha->relogin_jif = jiffies + 2 * HZ;
2388 * PRLI failed. Reset link to kick start
2391 set_bit(N2N_LINK_RESET, &vha->dpc_flags);
2392 qla2xxx_wake_dpc(vha);
2394 ql_log(ql_log_warn, vha, 0x2119,
2395 "%s %d %8phC Unable to reconnect\n",
2397 ea->fcport->port_name);
2401 * switch connect. login failed. Take connection down
2402 * and allow relogin to retrigger
2404 ea->fcport->flags &= ~FCF_ASYNC_SENT;
2405 ea->fcport->keep_nport_handle = 0;
2406 ea->fcport->logout_on_delete = 1;
2407 qlt_schedule_sess_for_deletion(ea->fcport);
2414 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
2416 port_id_t cid; /* conflict Nport id */
2418 struct fc_port *conflict_fcport;
2419 unsigned long flags;
2420 struct fc_port *fcport = ea->fcport;
2422 ql_dbg(ql_dbg_disc, vha, 0xffff,
2423 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
2424 __func__, fcport->port_name, fcport->disc_state,
2425 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
2426 ea->sp->gen1, fcport->rscn_gen,
2427 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
2429 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
2430 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
2431 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2432 "%s %d %8phC Remote is trying to login\n",
2433 __func__, __LINE__, fcport->port_name);
2437 if ((fcport->disc_state == DSC_DELETE_PEND) ||
2438 (fcport->disc_state == DSC_DELETED)) {
2439 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2443 if (ea->sp->gen2 != fcport->login_gen) {
2444 /* target side must have changed it. */
2445 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2446 "%s %8phC generation changed\n",
2447 __func__, fcport->port_name);
2448 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2450 } else if (ea->sp->gen1 != fcport->rscn_gen) {
2451 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2452 "%s %8phC RSCN generation changed\n",
2453 __func__, fcport->port_name);
2454 qla_rscn_replay(fcport);
2455 qlt_schedule_sess_for_deletion(fcport);
2459 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
2462 switch (ea->data[0]) {
2463 case MBS_COMMAND_COMPLETE:
2465 * Driver must validate login state - If PRLI not complete,
2466 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
2469 if (vha->hw->flags.edif_enabled) {
2470 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2471 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2472 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2473 ea->fcport->logout_on_delete = 1;
2474 ea->fcport->send_els_logo = 0;
2475 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
2476 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2478 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2480 if (NVME_TARGET(vha->hw, fcport)) {
2481 ql_dbg(ql_dbg_disc, vha, 0x2117,
2482 "%s %d %8phC post prli\n",
2483 __func__, __LINE__, fcport->port_name);
2484 qla24xx_post_prli_work(vha, fcport);
2486 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2487 "%s %d %8phC LoopID 0x%x in use with %06x. post gpdb\n",
2488 __func__, __LINE__, fcport->port_name,
2489 fcport->loop_id, fcport->d_id.b24);
2491 set_bit(fcport->loop_id, vha->hw->loop_id_map);
2492 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2493 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2494 fcport->logout_on_delete = 1;
2495 fcport->send_els_logo = 0;
2496 fcport->fw_login_state = DSC_LS_PRLI_COMP;
2497 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2499 qla24xx_post_gpdb_work(vha, fcport, 0);
2503 case MBS_COMMAND_ERROR:
2504 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
2505 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
2507 qlt_schedule_sess_for_deletion(ea->fcport);
2509 case MBS_LOOP_ID_USED:
2510 /* data[1] = IO PARAM 1 = nport ID */
2511 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
2512 cid.b.area = (ea->iop[1] >> 8) & 0xff;
2513 cid.b.al_pa = ea->iop[1] & 0xff;
2516 ql_dbg(ql_dbg_disc, vha, 0x20ec,
2517 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2518 __func__, __LINE__, ea->fcport->port_name,
2519 ea->fcport->loop_id, cid.b24);
2521 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2522 ea->fcport->loop_id = FC_NO_LOOP_ID;
2523 qla24xx_post_gnl_work(vha, ea->fcport);
2525 case MBS_PORT_ID_USED:
2526 lid = ea->iop[1] & 0xffff;
2527 qlt_find_sess_invalidate_other(vha,
2528 wwn_to_u64(ea->fcport->port_name),
2529 ea->fcport->d_id, lid, &conflict_fcport);
2531 if (conflict_fcport) {
2533 * Another fcport share the same loop_id/nport id.
2534 * Conflict fcport needs to finish cleanup before this
2535 * fcport can proceed to login.
2537 conflict_fcport->conflict = ea->fcport;
2538 ea->fcport->login_pause = 1;
2540 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2541 "%s %d %8phC NPortId %06x inuse with loopid 0x%x.\n",
2542 __func__, __LINE__, ea->fcport->port_name,
2543 ea->fcport->d_id.b24, lid);
2545 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2546 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2547 __func__, __LINE__, ea->fcport->port_name,
2548 ea->fcport->d_id.b24, lid);
2550 qla2x00_clear_loop_id(ea->fcport);
2551 set_bit(lid, vha->hw->loop_id_map);
2552 ea->fcport->loop_id = lid;
2553 ea->fcport->keep_nport_handle = 0;
2554 ea->fcport->logout_on_delete = 1;
2555 qlt_schedule_sess_for_deletion(ea->fcport);
2562 /****************************************************************************/
2563 /* QLogic ISP2x00 Hardware Support Functions. */
2564 /****************************************************************************/
2567 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
2569 int rval = QLA_SUCCESS;
2570 struct qla_hw_data *ha = vha->hw;
2571 uint32_t idc_major_ver, idc_minor_ver;
2574 qla83xx_idc_lock(vha, 0);
2576 /* SV: TODO: Assign initialization timeout from
2577 * flash-info / other param
2579 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
2580 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
2582 /* Set our fcoe function presence */
2583 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
2584 ql_dbg(ql_dbg_p3p, vha, 0xb077,
2585 "Error while setting DRV-Presence.\n");
2586 rval = QLA_FUNCTION_FAILED;
2590 /* Decide the reset ownership */
2591 qla83xx_reset_ownership(vha);
2594 * On first protocol driver load:
2595 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2597 * Others: Check compatibility with current IDC Major version.
2599 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
2600 if (ha->flags.nic_core_reset_owner) {
2601 /* Set IDC Major version */
2602 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
2603 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
2605 /* Clearing IDC-Lock-Recovery register */
2606 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
2607 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
2609 * Clear further IDC participation if we are not compatible with
2610 * the current IDC Major Version.
2612 ql_log(ql_log_warn, vha, 0xb07d,
2613 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2614 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
2615 __qla83xx_clear_drv_presence(vha);
2616 rval = QLA_FUNCTION_FAILED;
2619 /* Each function sets its supported Minor version. */
2620 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
2621 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
2622 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
2624 if (ha->flags.nic_core_reset_owner) {
2625 memset(config, 0, sizeof(config));
2626 if (!qla81xx_get_port_config(vha, config))
2627 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
2631 rval = qla83xx_idc_state_handler(vha);
2634 qla83xx_idc_unlock(vha, 0);
2640 * qla2x00_initialize_adapter
2644 * ha = adapter block pointer.
2650 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
2653 struct qla_hw_data *ha = vha->hw;
2654 struct req_que *req = ha->req_q_map[0];
2655 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2657 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2658 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2660 /* Clear adapter flags. */
2661 vha->flags.online = 0;
2662 ha->flags.chip_reset_done = 0;
2663 vha->flags.reset_active = 0;
2664 ha->flags.pci_channel_io_perm_failure = 0;
2665 ha->flags.eeh_busy = 0;
2666 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2667 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
2668 atomic_set(&vha->loop_state, LOOP_DOWN);
2669 vha->device_flags = DFLG_NO_CABLE;
2671 vha->flags.management_server_logged_in = 0;
2672 vha->marker_needed = 0;
2673 ha->isp_abort_cnt = 0;
2674 ha->beacon_blink_led = 0;
2676 set_bit(0, ha->req_qid_map);
2677 set_bit(0, ha->rsp_qid_map);
2679 ql_dbg(ql_dbg_init, vha, 0x0040,
2680 "Configuring PCI space...\n");
2681 rval = ha->isp_ops->pci_config(vha);
2683 ql_log(ql_log_warn, vha, 0x0044,
2684 "Unable to configure PCI space.\n");
2688 ha->isp_ops->reset_chip(vha);
2690 /* Check for secure flash support */
2691 if (IS_QLA28XX(ha)) {
2692 if (rd_reg_word(®->mailbox12) & BIT_0)
2693 ha->flags.secure_adapter = 1;
2694 ql_log(ql_log_info, vha, 0xffff, "Secure Adapter: %s\n",
2695 (ha->flags.secure_adapter) ? "Yes" : "No");
2699 rval = qla2xxx_get_flash_info(vha);
2701 ql_log(ql_log_fatal, vha, 0x004f,
2702 "Unable to validate FLASH data.\n");
2706 if (IS_QLA8044(ha)) {
2707 qla8044_read_reset_template(vha);
2709 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2710 * If DONRESET_BIT0 is set, drivers should not set dev_state
2711 * to NEED_RESET. But if NEED_RESET is set, drivers should
2712 * should honor the reset. */
2713 if (ql2xdontresethba == 1)
2714 qla8044_set_idc_dontreset(vha);
2717 ha->isp_ops->get_flash_version(vha, req->ring);
2718 ql_dbg(ql_dbg_init, vha, 0x0061,
2719 "Configure NVRAM parameters...\n");
2721 /* Let priority default to FCP, can be overridden by nvram_config */
2722 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2724 ha->isp_ops->nvram_config(vha);
2726 if (ha->fc4_type_priority != FC4_PRIORITY_FCP &&
2727 ha->fc4_type_priority != FC4_PRIORITY_NVME)
2728 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2730 ql_log(ql_log_info, vha, 0xffff, "FC4 priority set to %s\n",
2731 ha->fc4_type_priority == FC4_PRIORITY_FCP ? "FCP" : "NVMe");
2733 if (ha->flags.disable_serdes) {
2734 /* Mask HBA via NVRAM settings? */
2735 ql_log(ql_log_info, vha, 0x0077,
2736 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
2737 return QLA_FUNCTION_FAILED;
2740 ql_dbg(ql_dbg_init, vha, 0x0078,
2741 "Verifying loaded RISC code...\n");
2743 /* If smartsan enabled then require fdmi and rdp enabled */
2749 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
2750 rval = ha->isp_ops->chip_diag(vha);
2753 rval = qla2x00_setup_chip(vha);
2758 if (IS_QLA84XX(ha)) {
2759 ha->cs84xx = qla84xx_get_chip(vha);
2761 ql_log(ql_log_warn, vha, 0x00d0,
2762 "Unable to configure ISP84XX.\n");
2763 return QLA_FUNCTION_FAILED;
2767 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2768 rval = qla2x00_init_rings(vha);
2770 /* No point in continuing if firmware initialization failed. */
2771 if (rval != QLA_SUCCESS)
2774 ha->flags.chip_reset_done = 1;
2776 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2777 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2778 rval = qla84xx_init_chip(vha);
2779 if (rval != QLA_SUCCESS) {
2780 ql_log(ql_log_warn, vha, 0x00d4,
2781 "Unable to initialize ISP84XX.\n");
2782 qla84xx_put_chip(vha);
2786 /* Load the NIC Core f/w if we are the first protocol driver. */
2787 if (IS_QLA8031(ha)) {
2788 rval = qla83xx_nic_core_fw_load(vha);
2790 ql_log(ql_log_warn, vha, 0x0124,
2791 "Error in initializing NIC Core f/w.\n");
2794 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2795 qla24xx_read_fcp_prio_cfg(vha);
2797 if (IS_P3P_TYPE(ha))
2798 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2800 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2806 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2809 * Returns 0 on success.
2812 qla2100_pci_config(scsi_qla_host_t *vha)
2815 unsigned long flags;
2816 struct qla_hw_data *ha = vha->hw;
2817 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2819 pci_set_master(ha->pdev);
2820 pci_try_set_mwi(ha->pdev);
2822 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2823 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2824 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2826 pci_disable_rom(ha->pdev);
2828 /* Get PCI bus information. */
2829 spin_lock_irqsave(&ha->hardware_lock, flags);
2830 ha->pci_attr = rd_reg_word(®->ctrl_status);
2831 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2837 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2840 * Returns 0 on success.
2843 qla2300_pci_config(scsi_qla_host_t *vha)
2846 unsigned long flags = 0;
2848 struct qla_hw_data *ha = vha->hw;
2849 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2851 pci_set_master(ha->pdev);
2852 pci_try_set_mwi(ha->pdev);
2854 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2855 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2857 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2858 w &= ~PCI_COMMAND_INTX_DISABLE;
2859 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2862 * If this is a 2300 card and not 2312, reset the
2863 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2864 * the 2310 also reports itself as a 2300 so we need to get the
2865 * fb revision level -- a 6 indicates it really is a 2300 and
2868 if (IS_QLA2300(ha)) {
2869 spin_lock_irqsave(&ha->hardware_lock, flags);
2872 wrt_reg_word(®->hccr, HCCR_PAUSE_RISC);
2873 for (cnt = 0; cnt < 30000; cnt++) {
2874 if ((rd_reg_word(®->hccr) & HCCR_RISC_PAUSE) != 0)
2880 /* Select FPM registers. */
2881 wrt_reg_word(®->ctrl_status, 0x20);
2882 rd_reg_word(®->ctrl_status);
2884 /* Get the fb rev level */
2885 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2887 if (ha->fb_rev == FPM_2300)
2888 pci_clear_mwi(ha->pdev);
2890 /* Deselect FPM registers. */
2891 wrt_reg_word(®->ctrl_status, 0x0);
2892 rd_reg_word(®->ctrl_status);
2894 /* Release RISC module. */
2895 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
2896 for (cnt = 0; cnt < 30000; cnt++) {
2897 if ((rd_reg_word(®->hccr) & HCCR_RISC_PAUSE) == 0)
2903 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2906 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2908 pci_disable_rom(ha->pdev);
2910 /* Get PCI bus information. */
2911 spin_lock_irqsave(&ha->hardware_lock, flags);
2912 ha->pci_attr = rd_reg_word(®->ctrl_status);
2913 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2919 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2922 * Returns 0 on success.
2925 qla24xx_pci_config(scsi_qla_host_t *vha)
2928 unsigned long flags = 0;
2929 struct qla_hw_data *ha = vha->hw;
2930 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2932 pci_set_master(ha->pdev);
2933 pci_try_set_mwi(ha->pdev);
2935 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2936 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2937 w &= ~PCI_COMMAND_INTX_DISABLE;
2938 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2940 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2942 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2943 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2944 pcix_set_mmrbc(ha->pdev, 2048);
2946 /* PCIe -- adjust Maximum Read Request Size (2048). */
2947 if (pci_is_pcie(ha->pdev))
2948 pcie_set_readrq(ha->pdev, 4096);
2950 pci_disable_rom(ha->pdev);
2952 ha->chip_revision = ha->pdev->revision;
2954 /* Get PCI bus information. */
2955 spin_lock_irqsave(&ha->hardware_lock, flags);
2956 ha->pci_attr = rd_reg_dword(®->ctrl_status);
2957 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2963 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2966 * Returns 0 on success.
2969 qla25xx_pci_config(scsi_qla_host_t *vha)
2972 struct qla_hw_data *ha = vha->hw;
2974 pci_set_master(ha->pdev);
2975 pci_try_set_mwi(ha->pdev);
2977 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2978 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2979 w &= ~PCI_COMMAND_INTX_DISABLE;
2980 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2982 /* PCIe -- adjust Maximum Read Request Size (2048). */
2983 if (pci_is_pcie(ha->pdev))
2984 pcie_set_readrq(ha->pdev, 4096);
2986 pci_disable_rom(ha->pdev);
2988 ha->chip_revision = ha->pdev->revision;
2994 * qla2x00_isp_firmware() - Choose firmware image.
2997 * Returns 0 on success.
3000 qla2x00_isp_firmware(scsi_qla_host_t *vha)
3003 uint16_t loop_id, topo, sw_cap;
3004 uint8_t domain, area, al_pa;
3005 struct qla_hw_data *ha = vha->hw;
3007 /* Assume loading risc code */
3008 rval = QLA_FUNCTION_FAILED;
3010 if (ha->flags.disable_risc_code_load) {
3011 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
3013 /* Verify checksum of loaded RISC code. */
3014 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
3015 if (rval == QLA_SUCCESS) {
3016 /* And, verify we are not in ROM code. */
3017 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
3018 &area, &domain, &topo, &sw_cap);
3023 ql_dbg(ql_dbg_init, vha, 0x007a,
3024 "**** Load RISC code ****.\n");
3030 * qla2x00_reset_chip() - Reset ISP chip.
3033 * Returns 0 on success.
3036 qla2x00_reset_chip(scsi_qla_host_t *vha)
3038 unsigned long flags = 0;
3039 struct qla_hw_data *ha = vha->hw;
3040 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3043 int rval = QLA_FUNCTION_FAILED;
3045 if (unlikely(pci_channel_offline(ha->pdev)))
3048 ha->isp_ops->disable_intrs(ha);
3050 spin_lock_irqsave(&ha->hardware_lock, flags);
3052 /* Turn off master enable */
3054 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
3055 cmd &= ~PCI_COMMAND_MASTER;
3056 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
3058 if (!IS_QLA2100(ha)) {
3060 wrt_reg_word(®->hccr, HCCR_PAUSE_RISC);
3061 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
3062 for (cnt = 0; cnt < 30000; cnt++) {
3063 if ((rd_reg_word(®->hccr) &
3064 HCCR_RISC_PAUSE) != 0)
3069 rd_reg_word(®->hccr); /* PCI Posting. */
3073 /* Select FPM registers. */
3074 wrt_reg_word(®->ctrl_status, 0x20);
3075 rd_reg_word(®->ctrl_status); /* PCI Posting. */
3077 /* FPM Soft Reset. */
3078 wrt_reg_word(®->fpm_diag_config, 0x100);
3079 rd_reg_word(®->fpm_diag_config); /* PCI Posting. */
3081 /* Toggle Fpm Reset. */
3082 if (!IS_QLA2200(ha)) {
3083 wrt_reg_word(®->fpm_diag_config, 0x0);
3084 rd_reg_word(®->fpm_diag_config); /* PCI Posting. */
3087 /* Select frame buffer registers. */
3088 wrt_reg_word(®->ctrl_status, 0x10);
3089 rd_reg_word(®->ctrl_status); /* PCI Posting. */
3091 /* Reset frame buffer FIFOs. */
3092 if (IS_QLA2200(ha)) {
3093 WRT_FB_CMD_REG(ha, reg, 0xa000);
3094 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
3096 WRT_FB_CMD_REG(ha, reg, 0x00fc);
3098 /* Read back fb_cmd until zero or 3 seconds max */
3099 for (cnt = 0; cnt < 3000; cnt++) {
3100 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
3106 /* Select RISC module registers. */
3107 wrt_reg_word(®->ctrl_status, 0);
3108 rd_reg_word(®->ctrl_status); /* PCI Posting. */
3110 /* Reset RISC processor. */
3111 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
3112 rd_reg_word(®->hccr); /* PCI Posting. */
3114 /* Release RISC processor. */
3115 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
3116 rd_reg_word(®->hccr); /* PCI Posting. */
3119 wrt_reg_word(®->hccr, HCCR_CLR_RISC_INT);
3120 wrt_reg_word(®->hccr, HCCR_CLR_HOST_INT);
3122 /* Reset ISP chip. */
3123 wrt_reg_word(®->ctrl_status, CSR_ISP_SOFT_RESET);
3125 /* Wait for RISC to recover from reset. */
3126 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
3128 * It is necessary to for a delay here since the card doesn't
3129 * respond to PCI reads during a reset. On some architectures
3130 * this will result in an MCA.
3133 for (cnt = 30000; cnt; cnt--) {
3134 if ((rd_reg_word(®->ctrl_status) &
3135 CSR_ISP_SOFT_RESET) == 0)
3142 /* Reset RISC processor. */
3143 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
3145 wrt_reg_word(®->semaphore, 0);
3147 /* Release RISC processor. */
3148 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
3149 rd_reg_word(®->hccr); /* PCI Posting. */
3151 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
3152 for (cnt = 0; cnt < 30000; cnt++) {
3153 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
3161 /* Turn on master enable */
3162 cmd |= PCI_COMMAND_MASTER;
3163 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
3165 /* Disable RISC pause on FPM parity error. */
3166 if (!IS_QLA2100(ha)) {
3167 wrt_reg_word(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
3168 rd_reg_word(®->hccr); /* PCI Posting. */
3171 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3177 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
3180 * Returns 0 on success.
3183 qla81xx_reset_mpi(scsi_qla_host_t *vha)
3185 uint16_t mb[4] = {0x1010, 0, 1, 0};
3187 if (!IS_QLA81XX(vha->hw))
3190 return qla81xx_write_mpi_register(vha, mb);
3194 qla_chk_risc_recovery(scsi_qla_host_t *vha)
3196 struct qla_hw_data *ha = vha->hw;
3197 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3198 __le16 __iomem *mbptr = ®->mailbox0;
3201 int rc = QLA_SUCCESS;
3203 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3206 /* this check is only valid after RISC reset */
3207 mb[0] = rd_reg_word(mbptr);
3210 rc = QLA_FUNCTION_FAILED;
3212 for (i = 1; i < 32; i++) {
3213 mb[i] = rd_reg_word(mbptr);
3217 ql_log(ql_log_warn, vha, 0x1015,
3218 "RISC reset failed. mb[0-7] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
3219 mb[0], mb[1], mb[2], mb[3], mb[4], mb[5], mb[6], mb[7]);
3220 ql_log(ql_log_warn, vha, 0x1015,
3221 "RISC reset failed. mb[8-15] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
3222 mb[8], mb[9], mb[10], mb[11], mb[12], mb[13], mb[14],
3224 ql_log(ql_log_warn, vha, 0x1015,
3225 "RISC reset failed. mb[16-23] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
3226 mb[16], mb[17], mb[18], mb[19], mb[20], mb[21], mb[22],
3228 ql_log(ql_log_warn, vha, 0x1015,
3229 "RISC reset failed. mb[24-31] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
3230 mb[24], mb[25], mb[26], mb[27], mb[28], mb[29], mb[30],
3237 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
3240 * Returns 0 on success.
3243 qla24xx_reset_risc(scsi_qla_host_t *vha)
3245 unsigned long flags = 0;
3246 struct qla_hw_data *ha = vha->hw;
3247 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3250 static int abts_cnt; /* ISP abort retry counts */
3251 int rval = QLA_SUCCESS;
3254 spin_lock_irqsave(&ha->hardware_lock, flags);
3257 wrt_reg_dword(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
3258 for (cnt = 0; cnt < 30000; cnt++) {
3259 if ((rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
3265 if (!(rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE))
3266 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
3268 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
3269 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
3270 rd_reg_dword(®->hccr),
3271 rd_reg_dword(®->ctrl_status),
3272 (rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE));
3274 wrt_reg_dword(®->ctrl_status,
3275 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
3276 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
3280 /* Wait for firmware to complete NVRAM accesses. */
3281 rd_reg_word(®->mailbox0);
3282 for (cnt = 10000; rd_reg_word(®->mailbox0) != 0 &&
3283 rval == QLA_SUCCESS; cnt--) {
3288 rval = QLA_FUNCTION_TIMEOUT;
3291 if (rval == QLA_SUCCESS)
3292 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
3294 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
3295 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
3296 rd_reg_dword(®->hccr),
3297 rd_reg_word(®->mailbox0));
3299 /* Wait for soft-reset to complete. */
3300 rd_reg_dword(®->ctrl_status);
3301 for (cnt = 0; cnt < 60; cnt++) {
3303 if ((rd_reg_dword(®->ctrl_status) &
3304 CSRX_ISP_SOFT_RESET) == 0)
3309 if (!(rd_reg_dword(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
3310 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
3312 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
3313 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
3314 rd_reg_dword(®->hccr),
3315 rd_reg_dword(®->ctrl_status));
3317 /* If required, do an MPI FW reset now */
3318 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
3319 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
3320 if (++abts_cnt < 5) {
3321 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3322 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
3325 * We exhausted the ISP abort retries. We have to
3326 * set the board offline.
3329 vha->flags.online = 0;
3334 wrt_reg_dword(®->hccr, HCCRX_SET_RISC_RESET);
3335 rd_reg_dword(®->hccr);
3337 wrt_reg_dword(®->hccr, HCCRX_REL_RISC_PAUSE);
3338 rd_reg_dword(®->hccr);
3340 wrt_reg_dword(®->hccr, HCCRX_CLR_RISC_RESET);
3342 rd_reg_dword(®->hccr);
3344 wd = rd_reg_word(®->mailbox0);
3345 for (cnt = 300; wd != 0 && rval == QLA_SUCCESS; cnt--) {
3349 if (print && qla_chk_risc_recovery(vha))
3352 wd = rd_reg_word(®->mailbox0);
3354 rval = QLA_FUNCTION_TIMEOUT;
3356 ql_log(ql_log_warn, vha, 0x015e,
3357 "RISC reset timeout\n");
3361 if (rval == QLA_SUCCESS)
3362 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
3364 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
3365 "Host Risc 0x%x, mailbox0 0x%x\n",
3366 rd_reg_dword(®->hccr),
3367 rd_reg_word(®->mailbox0));
3369 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3371 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
3372 "Driver in %s mode\n",
3373 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
3375 if (IS_NOPOLLING_TYPE(ha))
3376 ha->isp_ops->enable_intrs(ha);
3382 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
3384 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
3386 wrt_reg_dword(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
3387 *data = rd_reg_dword(®->iobase_window + RISC_REGISTER_WINDOW_OFFSET);
3391 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
3393 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
3395 wrt_reg_dword(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
3396 wrt_reg_dword(®->iobase_window + RISC_REGISTER_WINDOW_OFFSET, data);
3400 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
3403 uint delta_msec = 100;
3404 uint elapsed_msec = 0;
3408 if (vha->hw->pdev->subsystem_device != 0x0175 &&
3409 vha->hw->pdev->subsystem_device != 0x0240)
3412 wrt_reg_dword(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
3416 timeout_msec = TIMEOUT_SEMAPHORE;
3417 n = timeout_msec / delta_msec;
3419 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
3420 qla25xx_read_risc_sema_reg(vha, &wd32);
3421 if (wd32 & RISC_SEMAPHORE)
3424 elapsed_msec += delta_msec;
3425 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
3429 if (!(wd32 & RISC_SEMAPHORE))
3432 if (!(wd32 & RISC_SEMAPHORE_FORCE))
3435 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
3436 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
3437 n = timeout_msec / delta_msec;
3439 qla25xx_read_risc_sema_reg(vha, &wd32);
3440 if (!(wd32 & RISC_SEMAPHORE_FORCE))
3443 elapsed_msec += delta_msec;
3444 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
3448 if (wd32 & RISC_SEMAPHORE_FORCE)
3449 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
3454 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
3461 * qla24xx_reset_chip() - Reset ISP24xx chip.
3464 * Returns 0 on success.
3467 qla24xx_reset_chip(scsi_qla_host_t *vha)
3469 struct qla_hw_data *ha = vha->hw;
3470 int rval = QLA_FUNCTION_FAILED;
3472 if (pci_channel_offline(ha->pdev) &&
3473 ha->flags.pci_channel_io_perm_failure) {
3477 ha->isp_ops->disable_intrs(ha);
3479 qla25xx_manipulate_risc_semaphore(vha);
3481 /* Perform RISC reset. */
3482 rval = qla24xx_reset_risc(vha);
3488 * qla2x00_chip_diag() - Test chip for proper operation.
3491 * Returns 0 on success.
3494 qla2x00_chip_diag(scsi_qla_host_t *vha)
3497 struct qla_hw_data *ha = vha->hw;
3498 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3499 unsigned long flags = 0;
3503 struct req_que *req = ha->req_q_map[0];
3505 /* Assume a failed state */
3506 rval = QLA_FUNCTION_FAILED;
3508 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
3509 ®->flash_address);
3511 spin_lock_irqsave(&ha->hardware_lock, flags);
3513 /* Reset ISP chip. */
3514 wrt_reg_word(®->ctrl_status, CSR_ISP_SOFT_RESET);
3517 * We need to have a delay here since the card will not respond while
3518 * in reset causing an MCA on some architectures.
3521 data = qla2x00_debounce_register(®->ctrl_status);
3522 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
3524 data = rd_reg_word(®->ctrl_status);
3529 goto chip_diag_failed;
3531 ql_dbg(ql_dbg_init, vha, 0x007c,
3532 "Reset register cleared by chip reset.\n");
3534 /* Reset RISC processor. */
3535 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
3536 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
3538 /* Workaround for QLA2312 PCI parity error */
3539 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
3540 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
3541 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
3543 data = RD_MAILBOX_REG(ha, reg, 0);
3550 goto chip_diag_failed;
3552 /* Check product ID of chip */
3553 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
3555 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
3556 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
3557 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
3558 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
3559 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
3560 mb[3] != PROD_ID_3) {
3561 ql_log(ql_log_warn, vha, 0x0062,
3562 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
3563 mb[1], mb[2], mb[3]);
3565 goto chip_diag_failed;
3567 ha->product_id[0] = mb[1];
3568 ha->product_id[1] = mb[2];
3569 ha->product_id[2] = mb[3];
3570 ha->product_id[3] = mb[4];
3572 /* Adjust fw RISC transfer size */
3573 if (req->length > 1024)
3574 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
3576 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
3579 if (IS_QLA2200(ha) &&
3580 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
3581 /* Limit firmware transfer size with a 2200A */
3582 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
3584 ha->device_type |= DT_ISP2200A;
3585 ha->fw_transfer_size = 128;
3588 /* Wrap Incoming Mailboxes Test. */
3589 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3591 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
3592 rval = qla2x00_mbx_reg_test(vha);
3594 ql_log(ql_log_warn, vha, 0x0080,
3595 "Failed mailbox send register test.\n");
3597 /* Flag a successful rval */
3599 spin_lock_irqsave(&ha->hardware_lock, flags);
3603 ql_log(ql_log_info, vha, 0x0081,
3604 "Chip diagnostics **** FAILED ****.\n");
3606 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3612 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3615 * Returns 0 on success.
3618 qla24xx_chip_diag(scsi_qla_host_t *vha)
3621 struct qla_hw_data *ha = vha->hw;
3622 struct req_que *req = ha->req_q_map[0];
3624 if (IS_P3P_TYPE(ha))
3627 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
3629 rval = qla2x00_mbx_reg_test(vha);
3631 ql_log(ql_log_warn, vha, 0x0082,
3632 "Failed mailbox send register test.\n");
3634 /* Flag a successful rval */
3642 qla2x00_init_fce_trace(scsi_qla_host_t *vha)
3647 struct qla_hw_data *ha = vha->hw;
3649 if (!IS_FWI2_CAPABLE(ha))
3652 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3653 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3657 ql_dbg(ql_dbg_init, vha, 0x00bd,
3658 "%s: FCE Mem is already allocated.\n",
3663 /* Allocate memory for Fibre Channel Event Buffer. */
3664 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3667 ql_log(ql_log_warn, vha, 0x00be,
3668 "Unable to allocate (%d KB) for FCE.\n",
3673 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3674 ha->fce_mb, &ha->fce_bufs);
3676 ql_log(ql_log_warn, vha, 0x00bf,
3677 "Unable to initialize FCE (%d).\n", rval);
3678 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, tc_dma);
3682 ql_dbg(ql_dbg_init, vha, 0x00c0,
3683 "Allocated (%d KB) for FCE...\n", FCE_SIZE / 1024);
3685 ha->flags.fce_enabled = 1;
3686 ha->fce_dma = tc_dma;
3691 qla2x00_init_eft_trace(scsi_qla_host_t *vha)
3696 struct qla_hw_data *ha = vha->hw;
3698 if (!IS_FWI2_CAPABLE(ha))
3702 ql_dbg(ql_dbg_init, vha, 0x00bd,
3703 "%s: EFT Mem is already allocated.\n",
3708 /* Allocate memory for Extended Trace Buffer. */
3709 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3712 ql_log(ql_log_warn, vha, 0x00c1,
3713 "Unable to allocate (%d KB) for EFT.\n",
3718 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3720 ql_log(ql_log_warn, vha, 0x00c2,
3721 "Unable to initialize EFT (%d).\n", rval);
3722 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, tc_dma);
3726 ql_dbg(ql_dbg_init, vha, 0x00c3,
3727 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3729 ha->eft_dma = tc_dma;
3734 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3736 qla2x00_init_fce_trace(vha);
3737 qla2x00_init_eft_trace(vha);
3741 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3743 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
3744 eft_size, fce_size, mq_size;
3745 struct qla_hw_data *ha = vha->hw;
3746 struct req_que *req = ha->req_q_map[0];
3747 struct rsp_que *rsp = ha->rsp_q_map[0];
3748 struct qla2xxx_fw_dump *fw_dump;
3751 ql_dbg(ql_dbg_init, vha, 0x00bd,
3752 "Firmware dump already allocated.\n");
3757 ha->fw_dump_cap_flags = 0;
3758 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
3759 req_q_size = rsp_q_size = 0;
3761 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3762 fixed_size = sizeof(struct qla2100_fw_dump);
3763 } else if (IS_QLA23XX(ha)) {
3764 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
3765 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
3767 } else if (IS_FWI2_CAPABLE(ha)) {
3769 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
3770 else if (IS_QLA81XX(ha))
3771 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
3772 else if (IS_QLA25XX(ha))
3773 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
3775 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
3777 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
3780 if (!IS_QLA83XX(ha))
3781 mq_size = sizeof(struct qla2xxx_mq_chain);
3783 * Allocate maximum buffer size for all queues - Q0.
3784 * Resizing must be done at end-of-dump processing.
3786 mq_size += (ha->max_req_queues - 1) *
3787 (req->length * sizeof(request_t));
3788 mq_size += (ha->max_rsp_queues - 1) *
3789 (rsp->length * sizeof(response_t));
3791 if (ha->tgt.atio_ring)
3792 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3794 qla2x00_init_fce_trace(vha);
3796 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3797 qla2x00_init_eft_trace(vha);
3799 eft_size = EFT_SIZE;
3802 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3803 struct fwdt *fwdt = ha->fwdt;
3806 for (j = 0; j < 2; j++, fwdt++) {
3807 if (!fwdt->template) {
3808 ql_dbg(ql_dbg_init, vha, 0x00ba,
3809 "-> fwdt%u no template\n", j);
3812 ql_dbg(ql_dbg_init, vha, 0x00fa,
3813 "-> fwdt%u calculating fwdump size...\n", j);
3814 fwdt->dump_size = qla27xx_fwdt_calculate_dump_size(
3815 vha, fwdt->template);
3816 ql_dbg(ql_dbg_init, vha, 0x00fa,
3817 "-> fwdt%u calculated fwdump size = %#lx bytes\n",
3818 j, fwdt->dump_size);
3819 dump_size += fwdt->dump_size;
3821 /* Add space for spare MPI fw dump. */
3822 dump_size += ha->fwdt[1].dump_size;
3824 req_q_size = req->length * sizeof(request_t);
3825 rsp_q_size = rsp->length * sizeof(response_t);
3826 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3827 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size
3829 ha->chain_offset = dump_size;
3830 dump_size += mq_size + fce_size;
3831 if (ha->exchoffld_buf)
3832 dump_size += sizeof(struct qla2xxx_offld_chain) +
3834 if (ha->exlogin_buf)
3835 dump_size += sizeof(struct qla2xxx_offld_chain) +
3839 if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) {
3841 ql_dbg(ql_dbg_init, vha, 0x00c5,
3842 "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n",
3843 __func__, dump_size, ha->fw_dump_len,
3844 ha->fw_dump_alloc_len);
3846 fw_dump = vmalloc(dump_size);
3848 ql_log(ql_log_warn, vha, 0x00c4,
3849 "Unable to allocate (%d KB) for firmware dump.\n",
3852 mutex_lock(&ha->optrom_mutex);
3853 if (ha->fw_dumped) {
3854 memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len);
3856 ha->fw_dump = fw_dump;
3857 ha->fw_dump_alloc_len = dump_size;
3858 ql_dbg(ql_dbg_init, vha, 0x00c5,
3859 "Re-Allocated (%d KB) and save firmware dump.\n",
3863 ha->fw_dump = fw_dump;
3865 ha->fw_dump_len = ha->fw_dump_alloc_len =
3867 ql_dbg(ql_dbg_init, vha, 0x00c5,
3868 "Allocated (%d KB) for firmware dump.\n",
3871 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3872 ha->mpi_fw_dump = (char *)fw_dump +
3873 ha->fwdt[1].dump_size;
3874 mutex_unlock(&ha->optrom_mutex);
3878 ha->fw_dump->signature[0] = 'Q';
3879 ha->fw_dump->signature[1] = 'L';
3880 ha->fw_dump->signature[2] = 'G';
3881 ha->fw_dump->signature[3] = 'C';
3882 ha->fw_dump->version = htonl(1);
3884 ha->fw_dump->fixed_size = htonl(fixed_size);
3885 ha->fw_dump->mem_size = htonl(mem_size);
3886 ha->fw_dump->req_q_size = htonl(req_q_size);
3887 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3889 ha->fw_dump->eft_size = htonl(eft_size);
3890 ha->fw_dump->eft_addr_l =
3891 htonl(LSD(ha->eft_dma));
3892 ha->fw_dump->eft_addr_h =
3893 htonl(MSD(ha->eft_dma));
3895 ha->fw_dump->header_size =
3897 (struct qla2xxx_fw_dump, isp));
3899 mutex_unlock(&ha->optrom_mutex);
3905 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3907 #define MPS_MASK 0xe0
3912 if (!IS_QLA81XX(vha->hw))
3915 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3916 if (rval != QLA_SUCCESS) {
3917 ql_log(ql_log_warn, vha, 0x0105,
3918 "Unable to acquire semaphore.\n");
3922 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3923 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3924 if (rval != QLA_SUCCESS) {
3925 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3930 if (dc == (dw & MPS_MASK))
3935 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3936 if (rval != QLA_SUCCESS) {
3937 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3941 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3942 if (rval != QLA_SUCCESS) {
3943 ql_log(ql_log_warn, vha, 0x006d,
3944 "Unable to release semaphore.\n");
3952 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3954 /* Don't try to reallocate the array */
3955 if (req->outstanding_cmds)
3958 if (!IS_FWI2_CAPABLE(ha))
3959 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3961 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3962 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3964 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3967 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3971 if (!req->outstanding_cmds) {
3973 * Try to allocate a minimal size just so we can get through
3976 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
3977 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3981 if (!req->outstanding_cmds) {
3982 ql_log(ql_log_fatal, NULL, 0x0126,
3983 "Failed to allocate memory for "
3984 "outstanding_cmds for req_que %p.\n", req);
3985 req->num_outstanding_cmds = 0;
3986 return QLA_FUNCTION_FAILED;
3993 #define PRINT_FIELD(_field, _flag, _str) { \
3994 if (a0->_field & _flag) {\
4000 len = snprintf(ptr, leftover, "%s", _str); \
4007 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
4010 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
4011 u8 str[STR_LEN], *ptr, p;
4014 memset(str, 0, STR_LEN);
4015 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
4016 ql_dbg(ql_dbg_init, vha, 0x015a,
4017 "SFP MFG Name: %s\n", str);
4019 memset(str, 0, STR_LEN);
4020 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
4021 ql_dbg(ql_dbg_init, vha, 0x015c,
4022 "SFP Part Name: %s\n", str);
4025 memset(str, 0, STR_LEN);
4029 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
4030 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
4031 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
4032 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
4033 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
4034 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
4035 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
4036 ql_dbg(ql_dbg_init, vha, 0x0160,
4037 "SFP Media: %s\n", str);
4040 memset(str, 0, STR_LEN);
4044 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
4045 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
4046 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
4047 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
4048 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
4049 ql_dbg(ql_dbg_init, vha, 0x0196,
4050 "SFP Link Length: %s\n", str);
4052 memset(str, 0, STR_LEN);
4056 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
4057 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
4058 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
4059 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
4060 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
4061 ql_dbg(ql_dbg_init, vha, 0x016e,
4062 "SFP FC Link Tech: %s\n", str);
4065 ql_dbg(ql_dbg_init, vha, 0x016f,
4066 "SFP Distant: %d km\n", a0->length_km);
4067 if (a0->length_100m)
4068 ql_dbg(ql_dbg_init, vha, 0x0170,
4069 "SFP Distant: %d m\n", a0->length_100m*100);
4070 if (a0->length_50um_10m)
4071 ql_dbg(ql_dbg_init, vha, 0x0189,
4072 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
4073 if (a0->length_62um_10m)
4074 ql_dbg(ql_dbg_init, vha, 0x018a,
4075 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
4076 if (a0->length_om4_10m)
4077 ql_dbg(ql_dbg_init, vha, 0x0194,
4078 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
4079 if (a0->length_om3_10m)
4080 ql_dbg(ql_dbg_init, vha, 0x0195,
4081 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
4086 * qla24xx_detect_sfp()
4088 * @vha: adapter state pointer.
4091 * 0 -- Configure firmware to use short-range settings -- normal
4092 * buffer-to-buffer credits.
4094 * 1 -- Configure firmware to use long-range settings -- extra
4095 * buffer-to-buffer credits should be allocated with
4096 * ha->lr_distance containing distance settings from NVRAM or SFP
4100 qla24xx_detect_sfp(scsi_qla_host_t *vha)
4103 struct sff_8247_a0 *a;
4104 struct qla_hw_data *ha = vha->hw;
4105 struct nvram_81xx *nv = ha->nvram;
4106 #define LR_DISTANCE_UNKNOWN 2
4107 static const char * const types[] = { "Short", "Long" };
4108 static const char * const lengths[] = { "(10km)", "(5km)", "" };
4111 /* Seed with NVRAM settings. */
4113 ha->flags.lr_detected = 0;
4114 if (IS_BPM_RANGE_CAPABLE(ha) &&
4115 (nv->enhanced_features & NEF_LR_DIST_ENABLE)) {
4117 ha->flags.lr_detected = 1;
4119 (nv->enhanced_features >> LR_DIST_NV_POS)
4123 if (!IS_BPM_ENABLED(vha))
4125 /* Determine SR/LR capabilities of SFP/Transceiver. */
4126 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
4131 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
4132 qla2xxx_print_sfp_info(vha);
4134 ha->flags.lr_detected = 0;
4136 if (ll & FC_LL_VL || ll & FC_LL_L) {
4137 /* Long range, track length. */
4138 ha->flags.lr_detected = 1;
4140 if (a->length_km > 5 || a->length_100m > 50)
4141 ha->lr_distance = LR_DISTANCE_10K;
4143 ha->lr_distance = LR_DISTANCE_5K;
4147 ql_dbg(ql_dbg_async, vha, 0x507b,
4148 "SFP detect: %s-Range SFP %s (nvr=%x ll=%x lr=%x lrd=%x).\n",
4149 types[ha->flags.lr_detected],
4150 ha->flags.lr_detected ? lengths[ha->lr_distance] :
4151 lengths[LR_DISTANCE_UNKNOWN],
4152 used_nvram, ll, ha->flags.lr_detected, ha->lr_distance);
4153 return ha->flags.lr_detected;
4156 void qla_init_iocb_limit(scsi_qla_host_t *vha)
4160 struct qla_hw_data *ha = vha->hw;
4162 num_qps = ha->num_qpairs + 1;
4163 limit = (ha->orig_fw_iocb_count * QLA_IOCB_PCT_LIMIT) / 100;
4165 ha->base_qpair->fwres.iocbs_total = ha->orig_fw_iocb_count;
4166 ha->base_qpair->fwres.iocbs_limit = limit;
4167 ha->base_qpair->fwres.iocbs_qp_limit = limit / num_qps;
4168 ha->base_qpair->fwres.iocbs_used = 0;
4170 ha->base_qpair->fwres.exch_total = ha->orig_fw_xcb_count;
4171 ha->base_qpair->fwres.exch_limit = (ha->orig_fw_xcb_count *
4172 QLA_IOCB_PCT_LIMIT) / 100;
4173 ha->base_qpair->fwres.exch_used = 0;
4175 for (i = 0; i < ha->max_qpairs; i++) {
4176 if (ha->queue_pair_map[i]) {
4177 ha->queue_pair_map[i]->fwres.iocbs_total =
4178 ha->orig_fw_iocb_count;
4179 ha->queue_pair_map[i]->fwres.iocbs_limit = limit;
4180 ha->queue_pair_map[i]->fwres.iocbs_qp_limit =
4182 ha->queue_pair_map[i]->fwres.iocbs_used = 0;
4183 ha->queue_pair_map[i]->fwres.exch_total = ha->orig_fw_xcb_count;
4184 ha->queue_pair_map[i]->fwres.exch_limit =
4185 (ha->orig_fw_xcb_count * QLA_IOCB_PCT_LIMIT) / 100;
4186 ha->queue_pair_map[i]->fwres.exch_used = 0;
4192 * qla2x00_setup_chip() - Load and start RISC firmware.
4195 * Returns 0 on success.
4198 qla2x00_setup_chip(scsi_qla_host_t *vha)
4201 uint32_t srisc_address = 0;
4202 struct qla_hw_data *ha = vha->hw;
4203 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4204 unsigned long flags;
4205 uint16_t fw_major_version;
4208 if (IS_P3P_TYPE(ha)) {
4209 rval = ha->isp_ops->load_risc(vha, &srisc_address);
4210 if (rval == QLA_SUCCESS) {
4211 qla2x00_stop_firmware(vha);
4212 goto enable_82xx_npiv;
4217 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
4218 /* Disable SRAM, Instruction RAM and GP RAM parity. */
4219 spin_lock_irqsave(&ha->hardware_lock, flags);
4220 wrt_reg_word(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
4221 rd_reg_word(®->hccr);
4222 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4225 qla81xx_mpi_sync(vha);
4228 /* Load firmware sequences */
4229 rval = ha->isp_ops->load_risc(vha, &srisc_address);
4230 if (rval == QLA_SUCCESS) {
4231 ql_dbg(ql_dbg_init, vha, 0x00c9,
4232 "Verifying Checksum of loaded RISC code.\n");
4234 rval = qla2x00_verify_checksum(vha, srisc_address);
4235 if (rval == QLA_SUCCESS) {
4236 /* Start firmware execution. */
4237 ql_dbg(ql_dbg_init, vha, 0x00ca,
4238 "Starting firmware.\n");
4241 ha->flags.exlogins_enabled = 1;
4243 if (qla_is_exch_offld_enabled(vha))
4244 ha->flags.exchoffld_enabled = 1;
4246 rval = qla2x00_execute_fw(vha, srisc_address);
4247 /* Retrieve firmware information. */
4248 if (rval == QLA_SUCCESS) {
4249 /* Enable BPM support? */
4250 if (!done_once++ && qla24xx_detect_sfp(vha)) {
4251 ql_dbg(ql_dbg_init, vha, 0x00ca,
4252 "Re-starting firmware -- BPM.\n");
4253 /* Best-effort - re-init. */
4254 ha->isp_ops->reset_chip(vha);
4255 ha->isp_ops->chip_diag(vha);
4256 goto execute_fw_with_lr;
4259 if (IS_ZIO_THRESHOLD_CAPABLE(ha))
4260 qla27xx_set_zio_threshold(vha,
4261 ha->last_zio_threshold);
4263 rval = qla2x00_set_exlogins_buffer(vha);
4264 if (rval != QLA_SUCCESS)
4267 rval = qla2x00_set_exchoffld_buffer(vha);
4268 if (rval != QLA_SUCCESS)
4272 fw_major_version = ha->fw_major_version;
4273 if (IS_P3P_TYPE(ha))
4274 qla82xx_check_md_needed(vha);
4276 rval = qla2x00_get_fw_version(vha);
4277 if (rval != QLA_SUCCESS)
4279 ha->flags.npiv_supported = 0;
4280 if (IS_QLA2XXX_MIDTYPE(ha) &&
4281 (ha->fw_attributes & BIT_2)) {
4282 ha->flags.npiv_supported = 1;
4283 if ((!ha->max_npiv_vports) ||
4284 ((ha->max_npiv_vports + 1) %
4285 MIN_MULTI_ID_FABRIC))
4286 ha->max_npiv_vports =
4287 MIN_MULTI_ID_FABRIC - 1;
4289 qla2x00_get_resource_cnts(vha);
4290 qla_init_iocb_limit(vha);
4293 * Allocate the array of outstanding commands
4294 * now that we know the firmware resources.
4296 rval = qla2x00_alloc_outstanding_cmds(ha,
4298 if (rval != QLA_SUCCESS)
4301 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
4302 qla2x00_alloc_offload_mem(vha);
4304 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
4305 qla2x00_alloc_fw_dump(vha);
4311 ql_log(ql_log_fatal, vha, 0x00cd,
4312 "ISP Firmware failed checksum.\n");
4316 /* Enable PUREX PASSTHRU */
4317 if (ql2xrdpenable || ha->flags.scm_supported_f ||
4318 ha->flags.edif_enabled)
4319 qla25xx_set_els_cmds_supported(vha);
4323 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
4324 /* Enable proper parity. */
4325 spin_lock_irqsave(&ha->hardware_lock, flags);
4328 wrt_reg_word(®->hccr, HCCR_ENABLE_PARITY + 0x1);
4330 /* SRAM, Instruction RAM and GP RAM parity */
4331 wrt_reg_word(®->hccr, HCCR_ENABLE_PARITY + 0x7);
4332 rd_reg_word(®->hccr);
4333 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4336 if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
4337 ha->flags.fac_supported = 1;
4338 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
4341 rval = qla81xx_fac_get_sector_size(vha, &size);
4342 if (rval == QLA_SUCCESS) {
4343 ha->flags.fac_supported = 1;
4344 ha->fdt_block_size = size << 2;
4346 ql_log(ql_log_warn, vha, 0x00ce,
4347 "Unsupported FAC firmware (%d.%02d.%02d).\n",
4348 ha->fw_major_version, ha->fw_minor_version,
4349 ha->fw_subminor_version);
4351 if (IS_QLA83XX(ha)) {
4352 ha->flags.fac_supported = 0;
4359 ql_log(ql_log_fatal, vha, 0x00cf,
4360 "Setup chip ****FAILED****.\n");
4367 * qla2x00_init_response_q_entries() - Initializes response queue entries.
4368 * @rsp: response queue
4370 * Beginning of request ring has initialization control block already built
4371 * by nvram config routine.
4373 * Returns 0 on success.
4376 qla2x00_init_response_q_entries(struct rsp_que *rsp)
4381 rsp->ring_ptr = rsp->ring;
4382 rsp->ring_index = 0;
4383 rsp->status_srb = NULL;
4384 pkt = rsp->ring_ptr;
4385 for (cnt = 0; cnt < rsp->length; cnt++) {
4386 pkt->signature = RESPONSE_PROCESSED;
4392 * qla2x00_update_fw_options() - Read and process firmware options.
4395 * Returns 0 on success.
4398 qla2x00_update_fw_options(scsi_qla_host_t *vha)
4400 uint16_t swing, emphasis, tx_sens, rx_sens;
4401 struct qla_hw_data *ha = vha->hw;
4403 memset(ha->fw_options, 0, sizeof(ha->fw_options));
4404 qla2x00_get_fw_options(vha, ha->fw_options);
4406 if (IS_QLA2100(ha) || IS_QLA2200(ha))
4409 /* Serial Link options. */
4410 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
4411 "Serial link options.\n");
4412 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
4413 ha->fw_seriallink_options, sizeof(ha->fw_seriallink_options));
4415 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
4416 if (ha->fw_seriallink_options[3] & BIT_2) {
4417 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
4420 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
4421 emphasis = (ha->fw_seriallink_options[2] &
4422 (BIT_4 | BIT_3)) >> 3;
4423 tx_sens = ha->fw_seriallink_options[0] &
4424 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4425 rx_sens = (ha->fw_seriallink_options[0] &
4426 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
4427 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
4428 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
4431 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
4432 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
4433 ha->fw_options[10] |= BIT_5 |
4434 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
4435 (tx_sens & (BIT_1 | BIT_0));
4438 swing = (ha->fw_seriallink_options[2] &
4439 (BIT_7 | BIT_6 | BIT_5)) >> 5;
4440 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
4441 tx_sens = ha->fw_seriallink_options[1] &
4442 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4443 rx_sens = (ha->fw_seriallink_options[1] &
4444 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
4445 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
4446 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
4449 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
4450 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
4451 ha->fw_options[11] |= BIT_5 |
4452 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
4453 (tx_sens & (BIT_1 | BIT_0));
4457 /* Return command IOCBs without waiting for an ABTS to complete. */
4458 ha->fw_options[3] |= BIT_13;
4461 if (ha->flags.enable_led_scheme)
4462 ha->fw_options[2] |= BIT_12;
4464 /* Detect ISP6312. */
4466 ha->fw_options[2] |= BIT_13;
4468 /* Set Retry FLOGI in case of P2P connection */
4469 if (ha->operating_mode == P2P) {
4470 ha->fw_options[2] |= BIT_3;
4471 ql_dbg(ql_dbg_disc, vha, 0x2100,
4472 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
4473 __func__, ha->fw_options[2]);
4476 /* Update firmware options. */
4477 qla2x00_set_fw_options(vha, ha->fw_options);
4481 qla24xx_update_fw_options(scsi_qla_host_t *vha)
4484 struct qla_hw_data *ha = vha->hw;
4486 if (IS_P3P_TYPE(ha))
4489 /* Hold status IOCBs until ABTS response received. */
4491 ha->fw_options[3] |= BIT_12;
4493 /* Set Retry FLOGI in case of P2P connection */
4494 if (ha->operating_mode == P2P) {
4495 ha->fw_options[2] |= BIT_3;
4496 ql_dbg(ql_dbg_disc, vha, 0x2101,
4497 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
4498 __func__, ha->fw_options[2]);
4501 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
4502 if (ql2xmvasynctoatio && !ha->flags.edif_enabled &&
4503 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
4504 if (qla_tgt_mode_enabled(vha) ||
4505 qla_dual_mode_enabled(vha))
4506 ha->fw_options[2] |= BIT_11;
4508 ha->fw_options[2] &= ~BIT_11;
4511 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4514 * Tell FW to track each exchange to prevent
4515 * driver from using stale exchange.
4517 if (qla_tgt_mode_enabled(vha) ||
4518 qla_dual_mode_enabled(vha))
4519 ha->fw_options[2] |= BIT_4;
4521 ha->fw_options[2] &= ~(BIT_4);
4523 /* Reserve 1/2 of emergency exchanges for ELS.*/
4524 if (qla2xuseresexchforels)
4525 ha->fw_options[2] |= BIT_8;
4527 ha->fw_options[2] &= ~BIT_8;
4530 * N2N: set Secure=1 for PLOGI ACC and
4531 * fw shal not send PRLI after PLOGI Acc
4533 if (ha->flags.edif_enabled &&
4534 DBELL_ACTIVE(vha)) {
4535 ha->fw_options[3] |= BIT_15;
4536 ha->flags.n2n_fw_acc_sec = 1;
4538 ha->fw_options[3] &= ~BIT_15;
4539 ha->flags.n2n_fw_acc_sec = 0;
4543 if (ql2xrdpenable || ha->flags.scm_supported_f ||
4544 ha->flags.edif_enabled)
4545 ha->fw_options[1] |= ADD_FO1_ENABLE_PUREX_IOCB;
4547 /* Enable Async 8130/8131 events -- transceiver insertion/removal */
4548 if (IS_BPM_RANGE_CAPABLE(ha))
4549 ha->fw_options[3] |= BIT_10;
4551 ql_dbg(ql_dbg_init, vha, 0x00e8,
4552 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
4553 __func__, ha->fw_options[1], ha->fw_options[2],
4554 ha->fw_options[3], vha->host->active_mode);
4556 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
4557 qla2x00_set_fw_options(vha, ha->fw_options);
4559 /* Update Serial Link options. */
4560 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
4563 rval = qla2x00_set_serdes_params(vha,
4564 le16_to_cpu(ha->fw_seriallink_options24[1]),
4565 le16_to_cpu(ha->fw_seriallink_options24[2]),
4566 le16_to_cpu(ha->fw_seriallink_options24[3]));
4567 if (rval != QLA_SUCCESS) {
4568 ql_log(ql_log_warn, vha, 0x0104,
4569 "Unable to update Serial Link options (%x).\n", rval);
4574 qla2x00_config_rings(struct scsi_qla_host *vha)
4576 struct qla_hw_data *ha = vha->hw;
4577 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4578 struct req_que *req = ha->req_q_map[0];
4579 struct rsp_que *rsp = ha->rsp_q_map[0];
4581 /* Setup ring parameters in initialization control block. */
4582 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
4583 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
4584 ha->init_cb->request_q_length = cpu_to_le16(req->length);
4585 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
4586 put_unaligned_le64(req->dma, &ha->init_cb->request_q_address);
4587 put_unaligned_le64(rsp->dma, &ha->init_cb->response_q_address);
4589 wrt_reg_word(ISP_REQ_Q_IN(ha, reg), 0);
4590 wrt_reg_word(ISP_REQ_Q_OUT(ha, reg), 0);
4591 wrt_reg_word(ISP_RSP_Q_IN(ha, reg), 0);
4592 wrt_reg_word(ISP_RSP_Q_OUT(ha, reg), 0);
4593 rd_reg_word(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
4597 qla24xx_config_rings(struct scsi_qla_host *vha)
4599 struct qla_hw_data *ha = vha->hw;
4600 device_reg_t *reg = ISP_QUE_REG(ha, 0);
4601 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
4602 struct qla_msix_entry *msix;
4603 struct init_cb_24xx *icb;
4605 struct req_que *req = ha->req_q_map[0];
4606 struct rsp_que *rsp = ha->rsp_q_map[0];
4608 /* Setup ring parameters in initialization control block. */
4609 icb = (struct init_cb_24xx *)ha->init_cb;
4610 icb->request_q_outpointer = cpu_to_le16(0);
4611 icb->response_q_inpointer = cpu_to_le16(0);
4612 icb->request_q_length = cpu_to_le16(req->length);
4613 icb->response_q_length = cpu_to_le16(rsp->length);
4614 put_unaligned_le64(req->dma, &icb->request_q_address);
4615 put_unaligned_le64(rsp->dma, &icb->response_q_address);
4617 /* Setup ATIO queue dma pointers for target mode */
4618 icb->atio_q_inpointer = cpu_to_le16(0);
4619 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
4620 put_unaligned_le64(ha->tgt.atio_dma, &icb->atio_q_address);
4622 if (IS_SHADOW_REG_CAPABLE(ha))
4623 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
4625 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4627 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
4628 icb->rid = cpu_to_le16(rid);
4629 if (ha->flags.msix_enabled) {
4630 msix = &ha->msix_entries[1];
4631 ql_dbg(ql_dbg_init, vha, 0x0019,
4632 "Registering vector 0x%x for base que.\n",
4634 icb->msix = cpu_to_le16(msix->entry);
4636 /* Use alternate PCI bus number */
4638 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
4639 /* Use alternate PCI devfn */
4641 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
4643 /* Use Disable MSIX Handshake mode for capable adapters */
4644 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
4645 (ha->flags.msix_enabled)) {
4646 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
4647 ha->flags.disable_msix_handshake = 1;
4648 ql_dbg(ql_dbg_init, vha, 0x00fe,
4649 "MSIX Handshake Disable Mode turned on.\n");
4651 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
4653 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
4655 wrt_reg_dword(®->isp25mq.req_q_in, 0);
4656 wrt_reg_dword(®->isp25mq.req_q_out, 0);
4657 wrt_reg_dword(®->isp25mq.rsp_q_in, 0);
4658 wrt_reg_dword(®->isp25mq.rsp_q_out, 0);
4660 wrt_reg_dword(®->isp24.req_q_in, 0);
4661 wrt_reg_dword(®->isp24.req_q_out, 0);
4662 wrt_reg_dword(®->isp24.rsp_q_in, 0);
4663 wrt_reg_dword(®->isp24.rsp_q_out, 0);
4666 qlt_24xx_config_rings(vha);
4668 /* If the user has configured the speed, set it here */
4669 if (ha->set_data_rate) {
4670 ql_dbg(ql_dbg_init, vha, 0x00fd,
4671 "Speed set by user : %s Gbps \n",
4672 qla2x00_get_link_speed_str(ha, ha->set_data_rate));
4673 icb->firmware_options_3 = cpu_to_le32(ha->set_data_rate << 13);
4677 rd_reg_word(&ioreg->hccr);
4681 * qla2x00_init_rings() - Initializes firmware.
4684 * Beginning of request ring has initialization control block already built
4685 * by nvram config routine.
4687 * Returns 0 on success.
4690 qla2x00_init_rings(scsi_qla_host_t *vha)
4693 unsigned long flags = 0;
4695 struct qla_hw_data *ha = vha->hw;
4696 struct req_que *req;
4697 struct rsp_que *rsp;
4698 struct mid_init_cb_24xx *mid_init_cb =
4699 (struct mid_init_cb_24xx *) ha->init_cb;
4701 spin_lock_irqsave(&ha->hardware_lock, flags);
4703 /* Clear outstanding commands array. */
4704 for (que = 0; que < ha->max_req_queues; que++) {
4705 req = ha->req_q_map[que];
4706 if (!req || !test_bit(que, ha->req_qid_map))
4708 req->out_ptr = (uint16_t *)(req->ring + req->length);
4710 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
4711 req->outstanding_cmds[cnt] = NULL;
4713 req->current_outstanding_cmd = 1;
4715 /* Initialize firmware. */
4716 req->ring_ptr = req->ring;
4717 req->ring_index = 0;
4718 req->cnt = req->length;
4721 for (que = 0; que < ha->max_rsp_queues; que++) {
4722 rsp = ha->rsp_q_map[que];
4723 if (!rsp || !test_bit(que, ha->rsp_qid_map))
4725 rsp->in_ptr = (uint16_t *)(rsp->ring + rsp->length);
4727 /* Initialize response queue entries */
4729 qlafx00_init_response_q_entries(rsp);
4731 qla2x00_init_response_q_entries(rsp);
4734 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
4735 ha->tgt.atio_ring_index = 0;
4736 /* Initialize ATIO queue entries */
4737 qlt_init_atio_q_entries(vha);
4739 ha->isp_ops->config_rings(vha);
4741 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4743 if (IS_QLAFX00(ha)) {
4744 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
4748 /* Update any ISP specific firmware options before initialization. */
4749 ha->isp_ops->update_fw_options(vha);
4751 ql_dbg(ql_dbg_init, vha, 0x00d1,
4752 "Issue init firmware FW opt 1-3= %08x %08x %08x.\n",
4753 le32_to_cpu(mid_init_cb->init_cb.firmware_options_1),
4754 le32_to_cpu(mid_init_cb->init_cb.firmware_options_2),
4755 le32_to_cpu(mid_init_cb->init_cb.firmware_options_3));
4757 if (ha->flags.npiv_supported) {
4758 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
4759 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
4760 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
4763 if (IS_FWI2_CAPABLE(ha)) {
4764 mid_init_cb->options = cpu_to_le16(BIT_1);
4765 mid_init_cb->init_cb.execution_throttle =
4766 cpu_to_le16(ha->cur_fw_xcb_count);
4767 ha->flags.dport_enabled =
4768 (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) &
4770 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
4771 (ha->flags.dport_enabled) ? "enabled" : "disabled");
4772 /* FA-WWPN Status */
4773 ha->flags.fawwpn_enabled =
4774 (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) &
4776 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
4777 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
4778 /* Init_cb will be reused for other command(s). Save a backup copy of port_name */
4779 memcpy(ha->port_name, ha->init_cb->port_name, WWN_SIZE);
4782 /* ELS pass through payload is limit by frame size. */
4783 if (ha->flags.edif_enabled)
4784 mid_init_cb->init_cb.frame_payload_size = cpu_to_le16(ELS_MAX_PAYLOAD);
4786 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
4789 ql_log(ql_log_fatal, vha, 0x00d2,
4790 "Init Firmware **** FAILED ****.\n");
4792 ql_dbg(ql_dbg_init, vha, 0x00d3,
4793 "Init Firmware -- success.\n");
4795 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0;
4802 * qla2x00_fw_ready() - Waits for firmware ready.
4805 * Returns 0 on success.
4808 qla2x00_fw_ready(scsi_qla_host_t *vha)
4811 unsigned long wtime, mtime, cs84xx_time;
4812 uint16_t min_wait; /* Minimum wait time if loop is down */
4813 uint16_t wait_time; /* Wait time if loop is coming ready */
4815 struct qla_hw_data *ha = vha->hw;
4817 if (IS_QLAFX00(vha->hw))
4818 return qlafx00_fw_ready(vha);
4820 /* Time to wait for loop down */
4821 if (IS_P3P_TYPE(ha))
4827 * Firmware should take at most one RATOV to login, plus 5 seconds for
4828 * our own processing.
4830 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
4831 wait_time = min_wait;
4834 /* Min wait time if loop down */
4835 mtime = jiffies + (min_wait * HZ);
4837 /* wait time before firmware ready */
4838 wtime = jiffies + (wait_time * HZ);
4840 /* Wait for ISP to finish LIP */
4841 if (!vha->flags.init_done)
4842 ql_log(ql_log_info, vha, 0x801e,
4843 "Waiting for LIP to complete.\n");
4846 memset(state, -1, sizeof(state));
4847 rval = qla2x00_get_firmware_state(vha, state);
4848 if (rval == QLA_SUCCESS) {
4849 if (state[0] < FSTATE_LOSS_OF_SYNC) {
4850 vha->device_flags &= ~DFLG_NO_CABLE;
4852 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
4853 ql_dbg(ql_dbg_taskm, vha, 0x801f,
4854 "fw_state=%x 84xx=%x.\n", state[0],
4856 if ((state[2] & FSTATE_LOGGED_IN) &&
4857 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
4858 ql_dbg(ql_dbg_taskm, vha, 0x8028,
4859 "Sending verify iocb.\n");
4861 cs84xx_time = jiffies;
4862 rval = qla84xx_init_chip(vha);
4863 if (rval != QLA_SUCCESS) {
4866 "Init chip failed.\n");
4870 /* Add time taken to initialize. */
4871 cs84xx_time = jiffies - cs84xx_time;
4872 wtime += cs84xx_time;
4873 mtime += cs84xx_time;
4874 ql_dbg(ql_dbg_taskm, vha, 0x8008,
4875 "Increasing wait time by %ld. "
4876 "New time %ld.\n", cs84xx_time,
4879 } else if (state[0] == FSTATE_READY) {
4880 ql_dbg(ql_dbg_taskm, vha, 0x8037,
4881 "F/W Ready - OK.\n");
4883 qla2x00_get_retry_cnt(vha, &ha->retry_count,
4884 &ha->login_timeout, &ha->r_a_tov);
4890 rval = QLA_FUNCTION_FAILED;
4892 if (atomic_read(&vha->loop_down_timer) &&
4893 state[0] != FSTATE_READY) {
4894 /* Loop down. Timeout on min_wait for states
4895 * other than Wait for Login.
4897 if (time_after_eq(jiffies, mtime)) {
4898 ql_log(ql_log_info, vha, 0x8038,
4899 "Cable is unplugged...\n");
4901 vha->device_flags |= DFLG_NO_CABLE;
4906 /* Mailbox cmd failed. Timeout on min_wait. */
4907 if (time_after_eq(jiffies, mtime) ||
4908 ha->flags.isp82xx_fw_hung)
4912 if (time_after_eq(jiffies, wtime))
4915 /* Delay for a while */
4919 ql_dbg(ql_dbg_taskm, vha, 0x803a,
4920 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
4921 state[1], state[2], state[3], state[4], state[5], jiffies);
4923 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
4924 ql_log(ql_log_warn, vha, 0x803b,
4925 "Firmware ready **** FAILED ****.\n");
4932 * qla2x00_configure_hba
4933 * Setup adapter context.
4936 * ha = adapter state pointer.
4945 qla2x00_configure_hba(scsi_qla_host_t *vha)
4954 char connect_type[22];
4955 struct qla_hw_data *ha = vha->hw;
4956 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4958 unsigned long flags;
4960 /* Get host addresses. */
4961 rval = qla2x00_get_adapter_id(vha,
4962 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
4963 if (rval != QLA_SUCCESS) {
4964 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
4965 IS_CNA_CAPABLE(ha) ||
4966 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
4967 ql_dbg(ql_dbg_disc, vha, 0x2008,
4968 "Loop is in a transition state.\n");
4970 ql_log(ql_log_warn, vha, 0x2009,
4971 "Unable to get host loop ID.\n");
4972 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
4973 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
4974 ql_log(ql_log_warn, vha, 0x1151,
4975 "Doing link init.\n");
4976 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
4979 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4985 ql_log(ql_log_info, vha, 0x200a,
4986 "Cannot get topology - retrying.\n");
4987 return (QLA_FUNCTION_FAILED);
4990 vha->loop_id = loop_id;
4993 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
4994 ha->operating_mode = LOOP;
4998 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
5000 ha->current_topology = ISP_CFG_NL;
5001 strcpy(connect_type, "(Loop)");
5005 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
5006 ha->switch_cap = sw_cap;
5007 ha->current_topology = ISP_CFG_FL;
5008 strcpy(connect_type, "(FL_Port)");
5012 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
5014 ha->operating_mode = P2P;
5015 ha->current_topology = ISP_CFG_N;
5016 strcpy(connect_type, "(N_Port-to-N_Port)");
5020 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
5021 ha->switch_cap = sw_cap;
5022 ha->operating_mode = P2P;
5023 ha->current_topology = ISP_CFG_F;
5024 strcpy(connect_type, "(F_Port)");
5028 ql_dbg(ql_dbg_disc, vha, 0x200f,
5029 "HBA in unknown topology %x, using NL.\n", topo);
5031 ha->current_topology = ISP_CFG_NL;
5032 strcpy(connect_type, "(Loop)");
5036 /* Save Host port and loop ID. */
5037 /* byte order - Big Endian */
5038 id.b.domain = domain;
5042 spin_lock_irqsave(&ha->hardware_lock, flags);
5043 if (vha->hw->flags.edif_enabled) {
5045 qla_update_host_map(vha, id);
5046 } else if (!(topo == 2 && ha->flags.n2n_bigger))
5047 qla_update_host_map(vha, id);
5048 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5050 if (!vha->flags.init_done)
5051 ql_log(ql_log_info, vha, 0x2010,
5052 "Topology - %s, Host Loop address 0x%x.\n",
5053 connect_type, vha->loop_id);
5059 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
5064 uint64_t zero[2] = { 0 };
5065 struct qla_hw_data *ha = vha->hw;
5066 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
5067 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
5069 if (len > sizeof(zero))
5071 if (memcmp(model, &zero, len) != 0) {
5072 memcpy(ha->model_number, model, len);
5073 st = en = ha->model_number;
5076 if (*en != 0x20 && *en != 0x00)
5081 index = (ha->pdev->subsystem_device & 0xff);
5083 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
5084 index < QLA_MODEL_NAMES)
5085 strscpy(ha->model_desc,
5086 qla2x00_model_name[index * 2 + 1],
5087 sizeof(ha->model_desc));
5089 index = (ha->pdev->subsystem_device & 0xff);
5091 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
5092 index < QLA_MODEL_NAMES) {
5093 strscpy(ha->model_number,
5094 qla2x00_model_name[index * 2],
5095 sizeof(ha->model_number));
5096 strscpy(ha->model_desc,
5097 qla2x00_model_name[index * 2 + 1],
5098 sizeof(ha->model_desc));
5100 strscpy(ha->model_number, def,
5101 sizeof(ha->model_number));
5104 if (IS_FWI2_CAPABLE(ha))
5105 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
5106 sizeof(ha->model_desc));
5109 /* On sparc systems, obtain port and node WWN from firmware
5112 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
5115 struct qla_hw_data *ha = vha->hw;
5116 struct pci_dev *pdev = ha->pdev;
5117 struct device_node *dp = pci_device_to_OF_node(pdev);
5121 val = of_get_property(dp, "port-wwn", &len);
5122 if (val && len >= WWN_SIZE)
5123 memcpy(nv->port_name, val, WWN_SIZE);
5125 val = of_get_property(dp, "node-wwn", &len);
5126 if (val && len >= WWN_SIZE)
5127 memcpy(nv->node_name, val, WWN_SIZE);
5132 * NVRAM configuration for ISP 2xxx
5135 * ha = adapter block pointer.
5138 * initialization control block in response_ring
5139 * host adapters parameters in host adapter block
5145 qla2x00_nvram_config(scsi_qla_host_t *vha)
5150 uint8_t *dptr1, *dptr2;
5151 struct qla_hw_data *ha = vha->hw;
5152 init_cb_t *icb = ha->init_cb;
5153 nvram_t *nv = ha->nvram;
5154 uint8_t *ptr = ha->nvram;
5155 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
5159 /* Determine NVRAM starting address. */
5160 ha->nvram_size = sizeof(*nv);
5162 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
5163 if ((rd_reg_word(®->ctrl_status) >> 14) == 1)
5164 ha->nvram_base = 0x80;
5166 /* Get NVRAM data and calculate checksum. */
5167 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
5168 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
5171 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
5172 "Contents of NVRAM.\n");
5173 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
5174 nv, ha->nvram_size);
5176 /* Bad NVRAM data, set defaults parameters. */
5177 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
5178 nv->nvram_version < 1) {
5179 /* Reset NVRAM data. */
5180 ql_log(ql_log_warn, vha, 0x0064,
5181 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
5182 chksum, nv->id, nv->nvram_version);
5183 ql_log(ql_log_warn, vha, 0x0065,
5185 "functioning (yet invalid -- WWPN) defaults.\n");
5188 * Set default initialization control block.
5190 memset(nv, 0, ha->nvram_size);
5191 nv->parameter_block_version = ICB_VERSION;
5193 if (IS_QLA23XX(ha)) {
5194 nv->firmware_options[0] = BIT_2 | BIT_1;
5195 nv->firmware_options[1] = BIT_7 | BIT_5;
5196 nv->add_firmware_options[0] = BIT_5;
5197 nv->add_firmware_options[1] = BIT_5 | BIT_4;
5198 nv->frame_payload_size = cpu_to_le16(2048);
5199 nv->special_options[1] = BIT_7;
5200 } else if (IS_QLA2200(ha)) {
5201 nv->firmware_options[0] = BIT_2 | BIT_1;
5202 nv->firmware_options[1] = BIT_7 | BIT_5;
5203 nv->add_firmware_options[0] = BIT_5;
5204 nv->add_firmware_options[1] = BIT_5 | BIT_4;
5205 nv->frame_payload_size = cpu_to_le16(1024);
5206 } else if (IS_QLA2100(ha)) {
5207 nv->firmware_options[0] = BIT_3 | BIT_1;
5208 nv->firmware_options[1] = BIT_5;
5209 nv->frame_payload_size = cpu_to_le16(1024);
5212 nv->max_iocb_allocation = cpu_to_le16(256);
5213 nv->execution_throttle = cpu_to_le16(16);
5214 nv->retry_count = 8;
5215 nv->retry_delay = 1;
5217 nv->port_name[0] = 33;
5218 nv->port_name[3] = 224;
5219 nv->port_name[4] = 139;
5221 qla2xxx_nvram_wwn_from_ofw(vha, nv);
5223 nv->login_timeout = 4;
5226 * Set default host adapter parameters
5228 nv->host_p[1] = BIT_2;
5229 nv->reset_delay = 5;
5230 nv->port_down_retry_count = 8;
5231 nv->max_luns_per_target = cpu_to_le16(8);
5232 nv->link_down_timeout = 60;
5237 /* Reset Initialization control block */
5238 memset(icb, 0, ha->init_cb_size);
5241 * Setup driver NVRAM options.
5243 nv->firmware_options[0] |= (BIT_6 | BIT_1);
5244 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
5245 nv->firmware_options[1] |= (BIT_5 | BIT_0);
5246 nv->firmware_options[1] &= ~BIT_4;
5248 if (IS_QLA23XX(ha)) {
5249 nv->firmware_options[0] |= BIT_2;
5250 nv->firmware_options[0] &= ~BIT_3;
5251 nv->special_options[0] &= ~BIT_6;
5252 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
5254 if (IS_QLA2300(ha)) {
5255 if (ha->fb_rev == FPM_2310) {
5256 strcpy(ha->model_number, "QLA2310");
5258 strcpy(ha->model_number, "QLA2300");
5261 qla2x00_set_model_info(vha, nv->model_number,
5262 sizeof(nv->model_number), "QLA23xx");
5264 } else if (IS_QLA2200(ha)) {
5265 nv->firmware_options[0] |= BIT_2;
5267 * 'Point-to-point preferred, else loop' is not a safe
5268 * connection mode setting.
5270 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
5272 /* Force 'loop preferred, else point-to-point'. */
5273 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
5274 nv->add_firmware_options[0] |= BIT_5;
5276 strcpy(ha->model_number, "QLA22xx");
5277 } else /*if (IS_QLA2100(ha))*/ {
5278 strcpy(ha->model_number, "QLA2100");
5282 * Copy over NVRAM RISC parameter block to initialization control block.
5284 dptr1 = (uint8_t *)icb;
5285 dptr2 = (uint8_t *)&nv->parameter_block_version;
5286 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
5288 *dptr1++ = *dptr2++;
5290 /* Copy 2nd half. */
5291 dptr1 = (uint8_t *)icb->add_firmware_options;
5292 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
5294 *dptr1++ = *dptr2++;
5295 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
5296 /* Use alternate WWN? */
5297 if (nv->host_p[1] & BIT_7) {
5298 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5299 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5302 /* Prepare nodename */
5303 if ((icb->firmware_options[1] & BIT_6) == 0) {
5305 * Firmware will apply the following mask if the nodename was
5308 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5309 icb->node_name[0] &= 0xF0;
5313 * Set host adapter parameters.
5317 * BIT_7 in the host-parameters section allows for modification to
5318 * internal driver logging.
5320 if (nv->host_p[0] & BIT_7)
5321 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
5322 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
5323 /* Always load RISC code on non ISP2[12]00 chips. */
5324 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
5325 ha->flags.disable_risc_code_load = 0;
5326 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
5327 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
5328 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
5329 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
5330 ha->flags.disable_serdes = 0;
5332 ha->operating_mode =
5333 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
5335 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
5336 sizeof(ha->fw_seriallink_options));
5338 /* save HBA serial number */
5339 ha->serial0 = icb->port_name[5];
5340 ha->serial1 = icb->port_name[6];
5341 ha->serial2 = icb->port_name[7];
5342 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5343 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5345 icb->execution_throttle = cpu_to_le16(0xFFFF);
5347 ha->retry_count = nv->retry_count;
5349 /* Set minimum login_timeout to 4 seconds. */
5350 if (nv->login_timeout != ql2xlogintimeout)
5351 nv->login_timeout = ql2xlogintimeout;
5352 if (nv->login_timeout < 4)
5353 nv->login_timeout = 4;
5354 ha->login_timeout = nv->login_timeout;
5356 /* Set minimum RATOV to 100 tenths of a second. */
5359 ha->loop_reset_delay = nv->reset_delay;
5361 /* Link Down Timeout = 0:
5363 * When Port Down timer expires we will start returning
5364 * I/O's to OS with "DID_NO_CONNECT".
5366 * Link Down Timeout != 0:
5368 * The driver waits for the link to come up after link down
5369 * before returning I/Os to OS with "DID_NO_CONNECT".
5371 if (nv->link_down_timeout == 0) {
5372 ha->loop_down_abort_time =
5373 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5375 ha->link_down_timeout = nv->link_down_timeout;
5376 ha->loop_down_abort_time =
5377 (LOOP_DOWN_TIME - ha->link_down_timeout);
5381 * Need enough time to try and get the port back.
5383 ha->port_down_retry_count = nv->port_down_retry_count;
5384 if (qlport_down_retry)
5385 ha->port_down_retry_count = qlport_down_retry;
5386 /* Set login_retry_count */
5387 ha->login_retry_count = nv->retry_count;
5388 if (ha->port_down_retry_count == nv->port_down_retry_count &&
5389 ha->port_down_retry_count > 3)
5390 ha->login_retry_count = ha->port_down_retry_count;
5391 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5392 ha->login_retry_count = ha->port_down_retry_count;
5393 if (ql2xloginretrycount)
5394 ha->login_retry_count = ql2xloginretrycount;
5396 icb->lun_enables = cpu_to_le16(0);
5397 icb->command_resource_count = 0;
5398 icb->immediate_notify_resource_count = 0;
5399 icb->timeout = cpu_to_le16(0);
5401 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
5403 icb->firmware_options[0] &= ~BIT_3;
5404 icb->add_firmware_options[0] &=
5405 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
5406 icb->add_firmware_options[0] |= BIT_2;
5407 icb->response_accumulation_timer = 3;
5408 icb->interrupt_delay_timer = 5;
5410 vha->flags.process_response_queue = 1;
5413 if (!vha->flags.init_done) {
5414 ha->zio_mode = icb->add_firmware_options[0] &
5415 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5416 ha->zio_timer = icb->interrupt_delay_timer ?
5417 icb->interrupt_delay_timer : 2;
5419 icb->add_firmware_options[0] &=
5420 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
5421 vha->flags.process_response_queue = 0;
5422 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5423 ha->zio_mode = QLA_ZIO_MODE_6;
5425 ql_log(ql_log_info, vha, 0x0068,
5426 "ZIO mode %d enabled; timer delay (%d us).\n",
5427 ha->zio_mode, ha->zio_timer * 100);
5429 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
5430 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
5431 vha->flags.process_response_queue = 1;
5436 ql_log(ql_log_warn, vha, 0x0069,
5437 "NVRAM configuration failed.\n");
5442 void qla2x00_set_fcport_state(fc_port_t *fcport, int state)
5446 old_state = atomic_read(&fcport->state);
5447 atomic_set(&fcport->state, state);
5449 /* Don't print state transitions during initial allocation of fcport */
5450 if (old_state && old_state != state) {
5451 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
5452 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
5453 fcport->port_name, port_state_str[old_state],
5454 port_state_str[state], fcport->d_id.b.domain,
5455 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5460 * qla2x00_alloc_fcport() - Allocate a generic fcport.
5462 * @flags: allocation flags
5464 * Returns a pointer to the allocated fcport, or NULL, if none available.
5467 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
5471 fcport = kzalloc(sizeof(fc_port_t), flags);
5475 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
5476 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
5478 if (!fcport->ct_desc.ct_sns) {
5479 ql_log(ql_log_warn, vha, 0xd049,
5480 "Failed to allocate ct_sns request.\n");
5485 /* Setup fcport template structure. */
5487 fcport->port_type = FCT_UNKNOWN;
5488 fcport->loop_id = FC_NO_LOOP_ID;
5489 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
5490 fcport->supported_classes = FC_COS_UNSPECIFIED;
5491 fcport->fp_speed = PORT_SPEED_UNKNOWN;
5493 fcport->disc_state = DSC_DELETED;
5494 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
5495 fcport->deleted = QLA_SESS_DELETED;
5496 fcport->login_retry = vha->hw->login_retry_count;
5497 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
5498 fcport->logout_on_delete = 1;
5499 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
5500 fcport->tgt_short_link_down_cnt = 0;
5501 fcport->dev_loss_tmo = 0;
5503 if (!fcport->ct_desc.ct_sns) {
5504 ql_log(ql_log_warn, vha, 0xd049,
5505 "Failed to allocate ct_sns request.\n");
5510 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
5511 INIT_WORK(&fcport->free_work, qlt_free_session_done);
5512 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
5513 INIT_LIST_HEAD(&fcport->gnl_entry);
5514 INIT_LIST_HEAD(&fcport->list);
5515 INIT_LIST_HEAD(&fcport->tmf_pending);
5517 INIT_LIST_HEAD(&fcport->sess_cmd_list);
5518 spin_lock_init(&fcport->sess_cmd_lock);
5520 spin_lock_init(&fcport->edif.sa_list_lock);
5521 INIT_LIST_HEAD(&fcport->edif.tx_sa_list);
5522 INIT_LIST_HEAD(&fcport->edif.rx_sa_list);
5524 spin_lock_init(&fcport->edif.indx_list_lock);
5525 INIT_LIST_HEAD(&fcport->edif.edif_indx_list);
5531 qla2x00_free_fcport(fc_port_t *fcport)
5533 if (fcport->ct_desc.ct_sns) {
5534 dma_free_coherent(&fcport->vha->hw->pdev->dev,
5535 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
5536 fcport->ct_desc.ct_sns_dma);
5538 fcport->ct_desc.ct_sns = NULL;
5541 qla_edif_flush_sa_ctl_lists(fcport);
5542 list_del(&fcport->list);
5543 qla2x00_clear_loop_id(fcport);
5545 qla_edif_list_del(fcport);
5550 static void qla_get_login_template(scsi_qla_host_t *vha)
5552 struct qla_hw_data *ha = vha->hw;
5557 memset(ha->init_cb, 0, ha->init_cb_size);
5558 sz = min_t(int, sizeof(struct fc_els_csp), ha->init_cb_size);
5559 rval = qla24xx_get_port_login_templ(vha, ha->init_cb_dma,
5561 if (rval != QLA_SUCCESS) {
5562 ql_dbg(ql_dbg_init, vha, 0x00d1,
5563 "PLOGI ELS param read fail.\n");
5566 q = (__be32 *)&ha->plogi_els_payld.fl_csp;
5568 bp = (uint32_t *)ha->init_cb;
5569 cpu_to_be32_array(q, bp, sz / 4);
5570 ha->flags.plogi_template_valid = 1;
5574 * qla2x00_configure_loop
5575 * Updates Fibre Channel Device Database with what is actually on loop.
5578 * ha = adapter block pointer.
5583 * 2 = database was full and device was not configured.
5586 qla2x00_configure_loop(scsi_qla_host_t *vha)
5589 unsigned long flags, save_flags;
5590 struct qla_hw_data *ha = vha->hw;
5594 /* Get Initiator ID */
5595 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
5596 rval = qla2x00_configure_hba(vha);
5597 if (rval != QLA_SUCCESS) {
5598 ql_dbg(ql_dbg_disc, vha, 0x2013,
5599 "Unable to configure HBA.\n");
5604 save_flags = flags = vha->dpc_flags;
5605 ql_dbg(ql_dbg_disc, vha, 0x2014,
5606 "Configure loop -- dpc flags = 0x%lx.\n", flags);
5609 * If we have both an RSCN and PORT UPDATE pending then handle them
5610 * both at the same time.
5612 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5613 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
5615 qla2x00_get_data_rate(vha);
5616 qla_get_login_template(vha);
5618 /* Determine what we need to do */
5619 if ((ha->current_topology == ISP_CFG_FL ||
5620 ha->current_topology == ISP_CFG_F) &&
5621 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
5623 set_bit(RSCN_UPDATE, &flags);
5624 clear_bit(LOCAL_LOOP_UPDATE, &flags);
5626 } else if (ha->current_topology == ISP_CFG_NL ||
5627 ha->current_topology == ISP_CFG_N) {
5628 clear_bit(RSCN_UPDATE, &flags);
5629 set_bit(LOCAL_LOOP_UPDATE, &flags);
5630 } else if (!vha->flags.online ||
5631 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
5632 set_bit(RSCN_UPDATE, &flags);
5633 set_bit(LOCAL_LOOP_UPDATE, &flags);
5636 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
5637 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5638 ql_dbg(ql_dbg_disc, vha, 0x2015,
5639 "Loop resync needed, failing.\n");
5640 rval = QLA_FUNCTION_FAILED;
5642 rval = qla2x00_configure_local_loop(vha);
5645 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
5646 if (LOOP_TRANSITION(vha)) {
5647 ql_dbg(ql_dbg_disc, vha, 0x2099,
5648 "Needs RSCN update and loop transition.\n");
5649 rval = QLA_FUNCTION_FAILED;
5652 rval = qla2x00_configure_fabric(vha);
5655 if (rval == QLA_SUCCESS) {
5656 if (atomic_read(&vha->loop_down_timer) ||
5657 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5658 rval = QLA_FUNCTION_FAILED;
5660 atomic_set(&vha->loop_state, LOOP_READY);
5661 ql_dbg(ql_dbg_disc, vha, 0x2069,
5663 ha->flags.fw_init_done = 1;
5666 * use link up to wake up app to get ready for
5669 if (ha->flags.edif_enabled && DBELL_INACTIVE(vha))
5670 qla2x00_post_aen_work(vha, FCH_EVT_LINKUP,
5671 ha->link_data_rate);
5674 * Process any ATIO queue entries that came in
5675 * while we weren't online.
5677 if (qla_tgt_mode_enabled(vha) ||
5678 qla_dual_mode_enabled(vha)) {
5679 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
5680 qlt_24xx_process_atio_queue(vha, 0);
5681 spin_unlock_irqrestore(&ha->tgt.atio_lock,
5688 ql_dbg(ql_dbg_disc, vha, 0x206a,
5689 "%s *** FAILED ***.\n", __func__);
5691 ql_dbg(ql_dbg_disc, vha, 0x206b,
5692 "%s: exiting normally. local port wwpn %8phN id %06x)\n",
5693 __func__, vha->port_name, vha->d_id.b24);
5696 /* Restore state if a resync event occurred during processing */
5697 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5698 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
5699 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5700 if (test_bit(RSCN_UPDATE, &save_flags)) {
5701 set_bit(RSCN_UPDATE, &vha->dpc_flags);
5708 static int qla2x00_configure_n2n_loop(scsi_qla_host_t *vha)
5710 unsigned long flags;
5713 ql_dbg(ql_dbg_disc, vha, 0x206a, "%s %d.\n", __func__, __LINE__);
5715 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags))
5716 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5718 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5719 if (fcport->n2n_flag) {
5720 qla24xx_fcport_handle_login(vha, fcport);
5725 spin_lock_irqsave(&vha->work_lock, flags);
5726 vha->scan.scan_retry++;
5727 spin_unlock_irqrestore(&vha->work_lock, flags);
5729 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5730 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5731 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5733 return QLA_FUNCTION_FAILED;
5737 qla_reinitialize_link(scsi_qla_host_t *vha)
5741 atomic_set(&vha->loop_state, LOOP_DOWN);
5742 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
5743 rval = qla2x00_full_login_lip(vha);
5744 if (rval == QLA_SUCCESS) {
5745 ql_dbg(ql_dbg_disc, vha, 0xd050, "Link reinitialized\n");
5747 ql_dbg(ql_dbg_disc, vha, 0xd051,
5748 "Link reinitialization failed (%d)\n", rval);
5753 * qla2x00_configure_local_loop
5754 * Updates Fibre Channel Device Database with local loop devices.
5757 * ha = adapter block pointer.
5763 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
5767 fc_port_t *fcport, *new_fcport;
5770 struct gid_list_info *gid;
5772 uint8_t domain, area, al_pa;
5773 struct qla_hw_data *ha = vha->hw;
5774 unsigned long flags;
5776 /* Inititae N2N login. */
5778 return qla2x00_configure_n2n_loop(vha);
5781 entries = MAX_FIBRE_DEVICES_LOOP;
5783 /* Get list of logged in devices. */
5784 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
5785 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
5787 if (rval != QLA_SUCCESS)
5790 ql_dbg(ql_dbg_disc, vha, 0x2011,
5791 "Entries in ID list (%d).\n", entries);
5792 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
5793 ha->gid_list, entries * sizeof(*ha->gid_list));
5796 spin_lock_irqsave(&vha->work_lock, flags);
5797 vha->scan.scan_retry++;
5798 spin_unlock_irqrestore(&vha->work_lock, flags);
5800 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5801 u8 loop_map_entries = 0;
5804 rc = qla2x00_get_fcal_position_map(vha, NULL,
5806 if (rc == QLA_SUCCESS && loop_map_entries > 1) {
5808 * There are devices that are still not logged
5809 * in. Reinitialize to give them a chance.
5811 qla_reinitialize_link(vha);
5812 return QLA_FUNCTION_FAILED;
5814 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5815 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5818 vha->scan.scan_retry = 0;
5821 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5822 fcport->scan_state = QLA_FCPORT_SCAN;
5825 /* Allocate temporary fcport for any new fcports discovered. */
5826 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5827 if (new_fcport == NULL) {
5828 ql_log(ql_log_warn, vha, 0x2012,
5829 "Memory allocation failed for fcport.\n");
5830 rval = QLA_MEMORY_ALLOC_FAILED;
5833 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5835 /* Add devices to port list. */
5837 for (index = 0; index < entries; index++) {
5838 domain = gid->domain;
5841 if (IS_QLA2100(ha) || IS_QLA2200(ha))
5842 loop_id = gid->loop_id_2100;
5844 loop_id = le16_to_cpu(gid->loop_id);
5845 gid = (void *)gid + ha->gid_list_info_size;
5847 /* Bypass reserved domain fields. */
5848 if ((domain & 0xf0) == 0xf0)
5851 /* Bypass if not same domain and area of adapter. */
5852 if (area && domain && ((area != vha->d_id.b.area) ||
5853 (domain != vha->d_id.b.domain)) &&
5854 (ha->current_topology == ISP_CFG_NL))
5858 /* Bypass invalid local loop ID. */
5859 if (loop_id > LAST_LOCAL_LOOP_ID)
5862 memset(new_fcport->port_name, 0, WWN_SIZE);
5864 /* Fill in member data. */
5865 new_fcport->d_id.b.domain = domain;
5866 new_fcport->d_id.b.area = area;
5867 new_fcport->d_id.b.al_pa = al_pa;
5868 new_fcport->loop_id = loop_id;
5869 new_fcport->scan_state = QLA_FCPORT_FOUND;
5871 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
5872 if (rval2 != QLA_SUCCESS) {
5873 ql_dbg(ql_dbg_disc, vha, 0x2097,
5874 "Failed to retrieve fcport information "
5875 "-- get_port_database=%x, loop_id=0x%04x.\n",
5876 rval2, new_fcport->loop_id);
5877 /* Skip retry if N2N */
5878 if (ha->current_topology != ISP_CFG_N) {
5879 ql_dbg(ql_dbg_disc, vha, 0x2105,
5880 "Scheduling resync.\n");
5881 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5886 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5887 /* Check for matching device in port list. */
5890 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5891 if (memcmp(new_fcport->port_name, fcport->port_name,
5895 fcport->flags &= ~FCF_FABRIC_DEVICE;
5896 fcport->loop_id = new_fcport->loop_id;
5897 fcport->port_type = new_fcport->port_type;
5898 fcport->d_id.b24 = new_fcport->d_id.b24;
5899 memcpy(fcport->node_name, new_fcport->node_name,
5901 fcport->scan_state = QLA_FCPORT_FOUND;
5902 if (fcport->login_retry == 0) {
5903 fcport->login_retry = vha->hw->login_retry_count;
5904 ql_dbg(ql_dbg_disc, vha, 0x2135,
5905 "Port login retry %8phN, lid 0x%04x retry cnt=%d.\n",
5906 fcport->port_name, fcport->loop_id,
5907 fcport->login_retry);
5914 /* New device, add to fcports list. */
5915 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5917 /* Allocate a new replacement fcport. */
5918 fcport = new_fcport;
5920 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5922 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5924 if (new_fcport == NULL) {
5925 ql_log(ql_log_warn, vha, 0xd031,
5926 "Failed to allocate memory for fcport.\n");
5927 rval = QLA_MEMORY_ALLOC_FAILED;
5930 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5931 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5934 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5936 /* Base iIDMA settings on HBA port speed. */
5937 fcport->fp_speed = ha->link_data_rate;
5940 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5941 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5944 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5945 if ((qla_dual_mode_enabled(vha) ||
5946 qla_ini_mode_enabled(vha)) &&
5947 atomic_read(&fcport->state) == FCS_ONLINE) {
5948 qla2x00_mark_device_lost(vha, fcport,
5949 ql2xplogiabsentdevice);
5950 if (fcport->loop_id != FC_NO_LOOP_ID &&
5951 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5952 fcport->port_type != FCT_INITIATOR &&
5953 fcport->port_type != FCT_BROADCAST) {
5954 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5955 "%s %d %8phC post del sess\n",
5959 qlt_schedule_sess_for_deletion(fcport);
5965 if (fcport->scan_state == QLA_FCPORT_FOUND)
5966 qla24xx_fcport_handle_login(vha, fcport);
5969 qla2x00_free_fcport(new_fcport);
5974 ql_dbg(ql_dbg_disc, vha, 0x2098,
5975 "Configure local loop error exit: rval=%x.\n", rval);
5980 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5983 uint16_t mb[MAILBOX_REGISTER_COUNT];
5984 struct qla_hw_data *ha = vha->hw;
5986 if (!IS_IIDMA_CAPABLE(ha))
5989 if (atomic_read(&fcport->state) != FCS_ONLINE)
5992 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
5993 fcport->fp_speed > ha->link_data_rate ||
5994 !ha->flags.gpsc_supported)
5997 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
5999 if (rval != QLA_SUCCESS) {
6000 ql_dbg(ql_dbg_disc, vha, 0x2004,
6001 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
6002 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
6004 ql_dbg(ql_dbg_disc, vha, 0x2005,
6005 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
6006 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
6007 fcport->fp_speed, fcport->port_name);
6011 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
6013 qla2x00_iidma_fcport(vha, fcport);
6014 qla24xx_update_fcport_fcp_prio(vha, fcport);
6017 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
6019 struct qla_work_evt *e;
6021 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
6023 return QLA_FUNCTION_FAILED;
6025 e->u.fcport.fcport = fcport;
6026 return qla2x00_post_work(vha, e);
6029 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
6031 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
6033 struct fc_rport_identifiers rport_ids;
6034 struct fc_rport *rport;
6035 unsigned long flags;
6037 if (atomic_read(&fcport->state) == FCS_ONLINE)
6040 rport_ids.node_name = wwn_to_u64(fcport->node_name);
6041 rport_ids.port_name = wwn_to_u64(fcport->port_name);
6042 rport_ids.port_id = fcport->d_id.b.domain << 16 |
6043 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
6044 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
6045 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
6047 ql_log(ql_log_warn, vha, 0x2006,
6048 "Unable to allocate fc remote port.\n");
6052 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
6053 *((fc_port_t **)rport->dd_data) = fcport;
6054 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
6055 fcport->dev_loss_tmo = rport->dev_loss_tmo;
6057 rport->supported_classes = fcport->supported_classes;
6059 rport_ids.roles = FC_PORT_ROLE_UNKNOWN;
6060 if (fcport->port_type == FCT_INITIATOR)
6061 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
6062 if (fcport->port_type == FCT_TARGET)
6063 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
6064 if (fcport->port_type & FCT_NVME_INITIATOR)
6065 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
6066 if (fcport->port_type & FCT_NVME_TARGET)
6067 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
6068 if (fcport->port_type & FCT_NVME_DISCOVERY)
6069 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
6071 fc_remote_port_rolechg(rport, rport_ids.roles);
6073 ql_dbg(ql_dbg_disc, vha, 0x20ee,
6074 "%s: %8phN. rport %ld:0:%d (%p) is %s mode\n",
6075 __func__, fcport->port_name, vha->host_no,
6076 rport->scsi_target_id, rport,
6077 (fcport->port_type == FCT_TARGET) ? "tgt" :
6078 ((fcport->port_type & FCT_NVME) ? "nvme" : "ini"));
6082 * qla2x00_update_fcport
6083 * Updates device on list.
6086 * ha = adapter block pointer.
6087 * fcport = port structure pointer.
6097 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
6099 unsigned long flags;
6101 if (IS_SW_RESV_ADDR(fcport->d_id))
6104 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
6105 __func__, fcport->port_name);
6107 qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT);
6108 fcport->login_retry = vha->hw->login_retry_count;
6109 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6111 spin_lock_irqsave(&vha->work_lock, flags);
6112 fcport->deleted = 0;
6113 spin_unlock_irqrestore(&vha->work_lock, flags);
6115 if (vha->hw->current_topology == ISP_CFG_NL)
6116 fcport->logout_on_delete = 0;
6118 fcport->logout_on_delete = 1;
6119 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
6121 if (fcport->tgt_link_down_time < fcport->dev_loss_tmo) {
6122 fcport->tgt_short_link_down_cnt++;
6123 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
6126 switch (vha->hw->current_topology) {
6129 fcport->keep_nport_handle = 1;
6135 qla2x00_iidma_fcport(vha, fcport);
6137 qla2x00_dfs_create_rport(vha, fcport);
6139 qla24xx_update_fcport_fcp_prio(vha, fcport);
6141 switch (vha->host->active_mode) {
6142 case MODE_INITIATOR:
6143 qla2x00_reg_remote_port(vha, fcport);
6146 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
6147 !vha->vha_tgt.qla_tgt->tgt_stopped)
6148 qlt_fc_port_added(vha, fcport);
6151 qla2x00_reg_remote_port(vha, fcport);
6152 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
6153 !vha->vha_tgt.qla_tgt->tgt_stopped)
6154 qlt_fc_port_added(vha, fcport);
6160 if (NVME_TARGET(vha->hw, fcport))
6161 qla_nvme_register_remote(vha, fcport);
6163 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
6165 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
6166 if (fcport->id_changed) {
6167 fcport->id_changed = 0;
6168 ql_dbg(ql_dbg_disc, vha, 0x20d7,
6169 "%s %d %8phC post gfpnid fcp_cnt %d\n",
6170 __func__, __LINE__, fcport->port_name,
6172 qla24xx_post_gfpnid_work(vha, fcport);
6174 ql_dbg(ql_dbg_disc, vha, 0x20d7,
6175 "%s %d %8phC post gpsc fcp_cnt %d\n",
6176 __func__, __LINE__, fcport->port_name,
6178 qla24xx_post_gpsc_work(vha, fcport);
6182 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
6185 void qla_register_fcport_fn(struct work_struct *work)
6187 fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
6188 u32 rscn_gen = fcport->rscn_gen;
6191 if (IS_SW_RESV_ADDR(fcport->d_id))
6194 qla2x00_update_fcport(fcport->vha, fcport);
6196 ql_dbg(ql_dbg_disc, fcport->vha, 0x911e,
6197 "%s rscn gen %d/%d next DS %d\n", __func__,
6198 rscn_gen, fcport->rscn_gen, fcport->next_disc_state);
6200 if (rscn_gen != fcport->rscn_gen) {
6201 /* RSCN(s) came in while registration */
6202 switch (fcport->next_disc_state) {
6203 case DSC_DELETE_PEND:
6204 qlt_schedule_sess_for_deletion(fcport);
6207 data[0] = data[1] = 0;
6208 qla2x00_post_async_adisc_work(fcport->vha, fcport,
6218 * qla2x00_configure_fabric
6219 * Setup SNS devices with loop ID's.
6222 * ha = adapter block pointer.
6229 qla2x00_configure_fabric(scsi_qla_host_t *vha)
6233 uint16_t mb[MAILBOX_REGISTER_COUNT];
6235 struct qla_hw_data *ha = vha->hw;
6238 /* If FL port exists, then SNS is present */
6239 if (IS_FWI2_CAPABLE(ha))
6240 loop_id = NPH_F_PORT;
6242 loop_id = SNS_FL_PORT;
6243 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
6244 if (rval != QLA_SUCCESS) {
6245 ql_dbg(ql_dbg_disc, vha, 0x20a0,
6246 "MBX_GET_PORT_NAME failed, No FL Port.\n");
6248 vha->device_flags &= ~SWITCH_FOUND;
6249 return (QLA_SUCCESS);
6251 vha->device_flags |= SWITCH_FOUND;
6253 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_port_name, 0);
6254 if (rval != QLA_SUCCESS)
6255 ql_dbg(ql_dbg_disc, vha, 0x20ff,
6256 "Failed to get Fabric Port Name\n");
6258 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
6259 rval = qla2x00_send_change_request(vha, 0x3, 0);
6260 if (rval != QLA_SUCCESS)
6261 ql_log(ql_log_warn, vha, 0x121,
6262 "Failed to enable receiving of RSCN requests: 0x%x.\n",
6267 qla2x00_mgmt_svr_login(vha);
6269 /* Ensure we are logged into the SNS. */
6270 loop_id = NPH_SNS_LID(ha);
6271 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
6272 0xfc, mb, BIT_1|BIT_0);
6273 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
6274 ql_dbg(ql_dbg_disc, vha, 0x20a1,
6275 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
6276 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
6277 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6282 if (ql2xfdmienable &&
6283 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
6284 qla2x00_fdmi_register(vha);
6286 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
6287 if (qla2x00_rft_id(vha)) {
6289 ql_dbg(ql_dbg_disc, vha, 0x20a2,
6290 "Register FC-4 TYPE failed.\n");
6291 if (test_bit(LOOP_RESYNC_NEEDED,
6295 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
6297 ql_dbg(ql_dbg_disc, vha, 0x209a,
6298 "Register FC-4 Features failed.\n");
6299 if (test_bit(LOOP_RESYNC_NEEDED,
6303 if (vha->flags.nvme_enabled) {
6304 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
6305 ql_dbg(ql_dbg_disc, vha, 0x2049,
6306 "Register NVME FC Type Features failed.\n");
6309 if (qla2x00_rnn_id(vha)) {
6311 ql_dbg(ql_dbg_disc, vha, 0x2104,
6312 "Register Node Name failed.\n");
6313 if (test_bit(LOOP_RESYNC_NEEDED,
6316 } else if (qla2x00_rsnn_nn(vha)) {
6318 ql_dbg(ql_dbg_disc, vha, 0x209b,
6319 "Register Symbolic Node Name failed.\n");
6320 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6326 /* Mark the time right before querying FW for connected ports.
6327 * This process is long, asynchronous and by the time it's done,
6328 * collected information might not be accurate anymore. E.g.
6329 * disconnected port might have re-connected and a brand new
6330 * session has been created. In this case session's generation
6331 * will be newer than discovery_gen. */
6332 qlt_do_generation_tick(vha, &discovery_gen);
6334 if (USE_ASYNC_SCAN(ha)) {
6335 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
6338 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6340 list_for_each_entry(fcport, &vha->vp_fcports, list)
6341 fcport->scan_state = QLA_FCPORT_SCAN;
6343 rval = qla2x00_find_all_fabric_devs(vha);
6345 if (rval != QLA_SUCCESS)
6349 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
6350 qla_nvme_register_hba(vha);
6353 ql_dbg(ql_dbg_disc, vha, 0x2068,
6354 "Configure fabric error exit rval=%d.\n", rval);
6360 * qla2x00_find_all_fabric_devs
6363 * ha = adapter block pointer.
6364 * dev = database device entry pointer.
6373 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
6377 fc_port_t *fcport, *new_fcport;
6382 int first_dev, last_dev;
6383 port_id_t wrap = {}, nxt_d_id;
6384 struct qla_hw_data *ha = vha->hw;
6385 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6386 unsigned long flags;
6390 /* Try GID_PT to get device list, else GAN. */
6392 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
6397 ql_dbg(ql_dbg_disc, vha, 0x209c,
6398 "GID_PT allocations failed, fallback on GA_NXT.\n");
6400 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
6401 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
6403 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6405 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
6407 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6409 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
6411 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6413 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
6415 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6419 /* If other queries succeeded probe for FC-4 type */
6421 qla2x00_gff_id(vha, swl);
6422 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6428 /* Allocate temporary fcport for any new fcports discovered. */
6429 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
6430 if (new_fcport == NULL) {
6431 ql_log(ql_log_warn, vha, 0x209d,
6432 "Failed to allocate memory for fcport.\n");
6433 return (QLA_MEMORY_ALLOC_FAILED);
6435 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
6436 /* Set start port ID scan at adapter ID. */
6440 /* Starting free loop ID. */
6441 loop_id = ha->min_external_loopid;
6442 for (; loop_id <= ha->max_loop_id; loop_id++) {
6443 if (qla2x00_is_reserved_id(vha, loop_id))
6446 if (ha->current_topology == ISP_CFG_FL &&
6447 (atomic_read(&vha->loop_down_timer) ||
6448 LOOP_TRANSITION(vha))) {
6449 atomic_set(&vha->loop_down_timer, 0);
6450 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6451 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
6457 wrap.b24 = new_fcport->d_id.b24;
6459 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
6460 memcpy(new_fcport->node_name,
6461 swl[swl_idx].node_name, WWN_SIZE);
6462 memcpy(new_fcport->port_name,
6463 swl[swl_idx].port_name, WWN_SIZE);
6464 memcpy(new_fcport->fabric_port_name,
6465 swl[swl_idx].fabric_port_name, WWN_SIZE);
6466 new_fcport->fp_speed = swl[swl_idx].fp_speed;
6467 new_fcport->fc4_type = swl[swl_idx].fc4_type;
6469 new_fcport->nvme_flag = 0;
6470 if (vha->flags.nvme_enabled &&
6471 swl[swl_idx].fc4_type & FS_FC4TYPE_NVME) {
6472 ql_log(ql_log_info, vha, 0x2131,
6473 "FOUND: NVME port %8phC as FC Type 28h\n",
6474 new_fcport->port_name);
6477 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
6483 /* Send GA_NXT to the switch */
6484 rval = qla2x00_ga_nxt(vha, new_fcport);
6485 if (rval != QLA_SUCCESS) {
6486 ql_log(ql_log_warn, vha, 0x209e,
6487 "SNS scan failed -- assuming "
6488 "zero-entry result.\n");
6494 /* If wrap on switch device list, exit. */
6496 wrap.b24 = new_fcport->d_id.b24;
6498 } else if (new_fcport->d_id.b24 == wrap.b24) {
6499 ql_dbg(ql_dbg_disc, vha, 0x209f,
6500 "Device wrap (%02x%02x%02x).\n",
6501 new_fcport->d_id.b.domain,
6502 new_fcport->d_id.b.area,
6503 new_fcport->d_id.b.al_pa);
6507 /* Bypass if same physical adapter. */
6508 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
6511 /* Bypass virtual ports of the same host. */
6512 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
6515 /* Bypass if same domain and area of adapter. */
6516 if (((new_fcport->d_id.b24 & 0xffff00) ==
6517 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
6521 /* Bypass reserved domain fields. */
6522 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
6525 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
6526 if (ql2xgffidenable &&
6527 (!(new_fcport->fc4_type & FS_FC4TYPE_FCP) &&
6528 new_fcport->fc4_type != 0))
6531 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
6533 /* Locate matching device in database. */
6535 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6536 if (memcmp(new_fcport->port_name, fcport->port_name,
6540 fcport->scan_state = QLA_FCPORT_FOUND;
6544 /* Update port state. */
6545 memcpy(fcport->fabric_port_name,
6546 new_fcport->fabric_port_name, WWN_SIZE);
6547 fcport->fp_speed = new_fcport->fp_speed;
6550 * If address the same and state FCS_ONLINE
6551 * (or in target mode), nothing changed.
6553 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
6554 (atomic_read(&fcport->state) == FCS_ONLINE ||
6555 (vha->host->active_mode == MODE_TARGET))) {
6559 if (fcport->login_retry == 0)
6560 fcport->login_retry =
6561 vha->hw->login_retry_count;
6563 * If device was not a fabric device before.
6565 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
6566 fcport->d_id.b24 = new_fcport->d_id.b24;
6567 qla2x00_clear_loop_id(fcport);
6568 fcport->flags |= (FCF_FABRIC_DEVICE |
6574 * Port ID changed or device was marked to be updated;
6575 * Log it out if still logged in and mark it for
6578 if (qla_tgt_mode_enabled(base_vha)) {
6579 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
6580 "port changed FC ID, %8phC"
6581 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
6583 fcport->d_id.b.domain,
6584 fcport->d_id.b.area,
6585 fcport->d_id.b.al_pa,
6587 new_fcport->d_id.b.domain,
6588 new_fcport->d_id.b.area,
6589 new_fcport->d_id.b.al_pa);
6590 fcport->d_id.b24 = new_fcport->d_id.b24;
6594 fcport->d_id.b24 = new_fcport->d_id.b24;
6595 fcport->flags |= FCF_LOGIN_NEEDED;
6599 if (found && NVME_TARGET(vha->hw, fcport)) {
6600 if (fcport->disc_state == DSC_DELETE_PEND) {
6601 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
6602 vha->fcport_count--;
6603 fcport->login_succ = 0;
6608 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6611 /* If device was not in our fcports list, then add it. */
6612 new_fcport->scan_state = QLA_FCPORT_FOUND;
6613 list_add_tail(&new_fcport->list, &vha->vp_fcports);
6615 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6618 /* Allocate a new replacement fcport. */
6619 nxt_d_id.b24 = new_fcport->d_id.b24;
6620 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
6621 if (new_fcport == NULL) {
6622 ql_log(ql_log_warn, vha, 0xd032,
6623 "Memory allocation failed for fcport.\n");
6624 return (QLA_MEMORY_ALLOC_FAILED);
6626 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
6627 new_fcport->d_id.b24 = nxt_d_id.b24;
6630 qla2x00_free_fcport(new_fcport);
6633 * Logout all previous fabric dev marked lost, except FCP2 devices.
6635 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6636 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6639 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
6642 if (fcport->scan_state == QLA_FCPORT_SCAN) {
6643 if ((qla_dual_mode_enabled(vha) ||
6644 qla_ini_mode_enabled(vha)) &&
6645 atomic_read(&fcport->state) == FCS_ONLINE) {
6646 qla2x00_mark_device_lost(vha, fcport,
6647 ql2xplogiabsentdevice);
6648 if (fcport->loop_id != FC_NO_LOOP_ID &&
6649 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
6650 fcport->port_type != FCT_INITIATOR &&
6651 fcport->port_type != FCT_BROADCAST) {
6652 ql_dbg(ql_dbg_disc, vha, 0x20f0,
6653 "%s %d %8phC post del sess\n",
6656 qlt_schedule_sess_for_deletion(fcport);
6662 if (fcport->scan_state == QLA_FCPORT_FOUND &&
6663 (fcport->flags & FCF_LOGIN_NEEDED) != 0)
6664 qla24xx_fcport_handle_login(vha, fcport);
6669 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
6671 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
6673 int loop_id = FC_NO_LOOP_ID;
6674 int lid = NPH_MGMT_SERVER - vha->vp_idx;
6675 unsigned long flags;
6676 struct qla_hw_data *ha = vha->hw;
6678 if (vha->vp_idx == 0) {
6679 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
6680 return NPH_MGMT_SERVER;
6683 /* pick id from high and work down to low */
6684 spin_lock_irqsave(&ha->vport_slock, flags);
6685 for (; lid > 0; lid--) {
6686 if (!test_bit(lid, vha->hw->loop_id_map)) {
6687 set_bit(lid, vha->hw->loop_id_map);
6692 spin_unlock_irqrestore(&ha->vport_slock, flags);
6698 * qla2x00_fabric_login
6699 * Issue fabric login command.
6702 * ha = adapter block pointer.
6703 * device = pointer to FC device type structure.
6706 * 0 - Login successfully
6708 * 2 - Initiator device
6712 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
6713 uint16_t *next_loopid)
6717 uint16_t tmp_loopid;
6718 uint16_t mb[MAILBOX_REGISTER_COUNT];
6719 struct qla_hw_data *ha = vha->hw;
6725 ql_dbg(ql_dbg_disc, vha, 0x2000,
6726 "Trying Fabric Login w/loop id 0x%04x for port "
6728 fcport->loop_id, fcport->d_id.b.domain,
6729 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6731 /* Login fcport on switch. */
6732 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
6733 fcport->d_id.b.domain, fcport->d_id.b.area,
6734 fcport->d_id.b.al_pa, mb, BIT_0);
6735 if (rval != QLA_SUCCESS) {
6738 if (mb[0] == MBS_PORT_ID_USED) {
6740 * Device has another loop ID. The firmware team
6741 * recommends the driver perform an implicit login with
6742 * the specified ID again. The ID we just used is save
6743 * here so we return with an ID that can be tried by
6747 tmp_loopid = fcport->loop_id;
6748 fcport->loop_id = mb[1];
6750 ql_dbg(ql_dbg_disc, vha, 0x2001,
6751 "Fabric Login: port in use - next loop "
6752 "id=0x%04x, port id= %02x%02x%02x.\n",
6753 fcport->loop_id, fcport->d_id.b.domain,
6754 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6756 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
6761 /* A retry occurred before. */
6762 *next_loopid = tmp_loopid;
6765 * No retry occurred before. Just increment the
6766 * ID value for next login.
6768 *next_loopid = (fcport->loop_id + 1);
6771 if (mb[1] & BIT_0) {
6772 fcport->port_type = FCT_INITIATOR;
6774 fcport->port_type = FCT_TARGET;
6775 if (mb[1] & BIT_1) {
6776 fcport->flags |= FCF_FCP2_DEVICE;
6781 fcport->supported_classes |= FC_COS_CLASS2;
6783 fcport->supported_classes |= FC_COS_CLASS3;
6785 if (IS_FWI2_CAPABLE(ha)) {
6788 FCF_CONF_COMP_SUPPORTED;
6793 } else if (mb[0] == MBS_LOOP_ID_USED) {
6795 * Loop ID already used, try next loop ID.
6798 rval = qla2x00_find_new_loop_id(vha, fcport);
6799 if (rval != QLA_SUCCESS) {
6800 /* Ran out of loop IDs to use */
6803 } else if (mb[0] == MBS_COMMAND_ERROR) {
6805 * Firmware possibly timed out during login. If NO
6806 * retries are left to do then the device is declared
6809 *next_loopid = fcport->loop_id;
6810 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6811 fcport->d_id.b.domain, fcport->d_id.b.area,
6812 fcport->d_id.b.al_pa);
6813 qla2x00_mark_device_lost(vha, fcport, 1);
6819 * unrecoverable / not handled error
6821 ql_dbg(ql_dbg_disc, vha, 0x2002,
6822 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6823 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
6824 fcport->d_id.b.area, fcport->d_id.b.al_pa,
6825 fcport->loop_id, jiffies);
6827 *next_loopid = fcport->loop_id;
6828 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6829 fcport->d_id.b.domain, fcport->d_id.b.area,
6830 fcport->d_id.b.al_pa);
6831 qla2x00_clear_loop_id(fcport);
6832 fcport->login_retry = 0;
6843 * qla2x00_local_device_login
6844 * Issue local device login command.
6847 * ha = adapter block pointer.
6848 * loop_id = loop id of device to login to.
6850 * Returns (Where's the #define!!!!):
6851 * 0 - Login successfully
6856 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
6859 uint16_t mb[MAILBOX_REGISTER_COUNT];
6861 memset(mb, 0, sizeof(mb));
6862 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
6863 if (rval == QLA_SUCCESS) {
6864 /* Interrogate mailbox registers for any errors */
6865 if (mb[0] == MBS_COMMAND_ERROR)
6867 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
6868 /* device not in PCB table */
6876 * qla2x00_loop_resync
6877 * Resync with fibre channel devices.
6880 * ha = adapter block pointer.
6886 qla2x00_loop_resync(scsi_qla_host_t *vha)
6888 int rval = QLA_SUCCESS;
6891 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6892 if (vha->flags.online) {
6893 if (!(rval = qla2x00_fw_ready(vha))) {
6894 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6897 if (!IS_QLAFX00(vha->hw)) {
6899 * Issue a marker after FW becomes
6902 qla2x00_marker(vha, vha->hw->base_qpair,
6904 vha->marker_needed = 0;
6907 /* Remap devices on Loop. */
6908 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6910 if (IS_QLAFX00(vha->hw))
6911 qlafx00_configure_devices(vha);
6913 qla2x00_configure_loop(vha);
6916 } while (!atomic_read(&vha->loop_down_timer) &&
6917 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6918 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
6923 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6924 return (QLA_FUNCTION_FAILED);
6927 ql_dbg(ql_dbg_disc, vha, 0x206c,
6928 "%s *** FAILED ***.\n", __func__);
6934 * qla2x00_perform_loop_resync
6935 * Description: This function will set the appropriate flags and call
6936 * qla2x00_loop_resync. If successful loop will be resynced
6937 * Arguments : scsi_qla_host_t pointer
6938 * returm : Success or Failure
6941 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
6945 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
6946 /*Configure the flags so that resync happens properly*/
6947 atomic_set(&ha->loop_down_timer, 0);
6948 if (!(ha->device_flags & DFLG_NO_CABLE)) {
6949 atomic_set(&ha->loop_state, LOOP_UP);
6950 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
6951 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
6952 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
6954 rval = qla2x00_loop_resync(ha);
6956 atomic_set(&ha->loop_state, LOOP_DEAD);
6958 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
6964 /* Assumes idc_lock always held on entry */
6966 qla83xx_reset_ownership(scsi_qla_host_t *vha)
6968 struct qla_hw_data *ha = vha->hw;
6969 uint32_t drv_presence, drv_presence_mask;
6970 uint32_t dev_part_info1, dev_part_info2, class_type;
6971 uint32_t class_type_mask = 0x3;
6972 uint16_t fcoe_other_function = 0xffff, i;
6974 if (IS_QLA8044(ha)) {
6975 drv_presence = qla8044_rd_direct(vha,
6976 QLA8044_CRB_DRV_ACTIVE_INDEX);
6977 dev_part_info1 = qla8044_rd_direct(vha,
6978 QLA8044_CRB_DEV_PART_INFO_INDEX);
6979 dev_part_info2 = qla8044_rd_direct(vha,
6980 QLA8044_CRB_DEV_PART_INFO2);
6982 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6983 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
6984 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
6986 for (i = 0; i < 8; i++) {
6987 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
6988 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6989 (i != ha->portnum)) {
6990 fcoe_other_function = i;
6994 if (fcoe_other_function == 0xffff) {
6995 for (i = 0; i < 8; i++) {
6996 class_type = ((dev_part_info2 >> (i * 4)) &
6998 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6999 ((i + 8) != ha->portnum)) {
7000 fcoe_other_function = i + 8;
7006 * Prepare drv-presence mask based on fcoe functions present.
7007 * However consider only valid physical fcoe function numbers (0-15).
7009 drv_presence_mask = ~((1 << (ha->portnum)) |
7010 ((fcoe_other_function == 0xffff) ?
7011 0 : (1 << (fcoe_other_function))));
7013 /* We are the reset owner iff:
7014 * - No other protocol drivers present.
7015 * - This is the lowest among fcoe functions. */
7016 if (!(drv_presence & drv_presence_mask) &&
7017 (ha->portnum < fcoe_other_function)) {
7018 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
7019 "This host is Reset owner.\n");
7020 ha->flags.nic_core_reset_owner = 1;
7025 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
7027 int rval = QLA_SUCCESS;
7028 struct qla_hw_data *ha = vha->hw;
7031 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
7032 if (rval == QLA_SUCCESS) {
7033 drv_ack |= (1 << ha->portnum);
7034 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
7041 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
7043 int rval = QLA_SUCCESS;
7044 struct qla_hw_data *ha = vha->hw;
7047 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
7048 if (rval == QLA_SUCCESS) {
7049 drv_ack &= ~(1 << ha->portnum);
7050 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
7056 /* Assumes idc-lock always held on entry */
7058 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
7060 struct qla_hw_data *ha = vha->hw;
7061 uint32_t idc_audit_reg = 0, duration_secs = 0;
7063 switch (audit_type) {
7064 case IDC_AUDIT_TIMESTAMP:
7065 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
7066 idc_audit_reg = (ha->portnum) |
7067 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
7068 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
7071 case IDC_AUDIT_COMPLETION:
7072 duration_secs = ((jiffies_to_msecs(jiffies) -
7073 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
7074 idc_audit_reg = (ha->portnum) |
7075 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
7076 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
7080 ql_log(ql_log_warn, vha, 0xb078,
7081 "Invalid audit type specified.\n");
7086 /* Assumes idc_lock always held on entry */
7088 qla83xx_initiating_reset(scsi_qla_host_t *vha)
7090 struct qla_hw_data *ha = vha->hw;
7091 uint32_t idc_control, dev_state;
7093 __qla83xx_get_idc_control(vha, &idc_control);
7094 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
7095 ql_log(ql_log_info, vha, 0xb080,
7096 "NIC Core reset has been disabled. idc-control=0x%x\n",
7098 return QLA_FUNCTION_FAILED;
7101 /* Set NEED-RESET iff in READY state and we are the reset-owner */
7102 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
7103 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
7104 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
7105 QLA8XXX_DEV_NEED_RESET);
7106 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
7107 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
7109 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n",
7110 qdev_state(dev_state));
7112 /* SV: XXX: Is timeout required here? */
7113 /* Wait for IDC state change READY -> NEED_RESET */
7114 while (dev_state == QLA8XXX_DEV_READY) {
7115 qla83xx_idc_unlock(vha, 0);
7117 qla83xx_idc_lock(vha, 0);
7118 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
7122 /* Send IDC ack by writing to drv-ack register */
7123 __qla83xx_set_drv_ack(vha);
7129 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
7131 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
7135 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
7137 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
7141 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
7143 uint32_t drv_presence = 0;
7144 struct qla_hw_data *ha = vha->hw;
7146 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
7147 if (drv_presence & (1 << ha->portnum))
7150 return QLA_TEST_FAILED;
7154 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
7156 int rval = QLA_SUCCESS;
7157 struct qla_hw_data *ha = vha->hw;
7159 ql_dbg(ql_dbg_p3p, vha, 0xb058,
7160 "Entered %s().\n", __func__);
7162 if (vha->device_flags & DFLG_DEV_FAILED) {
7163 ql_log(ql_log_warn, vha, 0xb059,
7164 "Device in unrecoverable FAILED state.\n");
7165 return QLA_FUNCTION_FAILED;
7168 qla83xx_idc_lock(vha, 0);
7170 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
7171 ql_log(ql_log_warn, vha, 0xb05a,
7172 "Function=0x%x has been removed from IDC participation.\n",
7174 rval = QLA_FUNCTION_FAILED;
7178 qla83xx_reset_ownership(vha);
7180 rval = qla83xx_initiating_reset(vha);
7183 * Perform reset if we are the reset-owner,
7184 * else wait till IDC state changes to READY/FAILED.
7186 if (rval == QLA_SUCCESS) {
7187 rval = qla83xx_idc_state_handler(vha);
7189 if (rval == QLA_SUCCESS)
7190 ha->flags.nic_core_hung = 0;
7191 __qla83xx_clear_drv_ack(vha);
7195 qla83xx_idc_unlock(vha, 0);
7197 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
7203 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
7205 struct qla_hw_data *ha = vha->hw;
7206 int rval = QLA_FUNCTION_FAILED;
7208 if (!IS_MCTP_CAPABLE(ha)) {
7209 /* This message can be removed from the final version */
7210 ql_log(ql_log_info, vha, 0x506d,
7211 "This board is not MCTP capable\n");
7215 if (!ha->mctp_dump) {
7216 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
7217 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
7219 if (!ha->mctp_dump) {
7220 ql_log(ql_log_warn, vha, 0x506e,
7221 "Failed to allocate memory for mctp dump\n");
7226 #define MCTP_DUMP_STR_ADDR 0x00000000
7227 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
7228 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
7229 if (rval != QLA_SUCCESS) {
7230 ql_log(ql_log_warn, vha, 0x506f,
7231 "Failed to capture mctp dump\n");
7233 ql_log(ql_log_info, vha, 0x5070,
7234 "Mctp dump capture for host (%ld/%p).\n",
7235 vha->host_no, ha->mctp_dump);
7236 ha->mctp_dumped = 1;
7239 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
7240 ha->flags.nic_core_reset_hdlr_active = 1;
7241 rval = qla83xx_restart_nic_firmware(vha);
7243 /* NIC Core reset failed. */
7244 ql_log(ql_log_warn, vha, 0x5071,
7245 "Failed to restart nic firmware\n");
7247 ql_dbg(ql_dbg_p3p, vha, 0xb084,
7248 "Restarted NIC firmware successfully.\n");
7249 ha->flags.nic_core_reset_hdlr_active = 0;
7257 * qla2x00_quiesce_io
7258 * Description: This function will block the new I/Os
7259 * Its not aborting any I/Os as context
7260 * is not destroyed during quiescence
7261 * Arguments: scsi_qla_host_t
7265 qla2x00_quiesce_io(scsi_qla_host_t *vha)
7267 struct qla_hw_data *ha = vha->hw;
7268 struct scsi_qla_host *vp, *tvp;
7269 unsigned long flags;
7271 ql_dbg(ql_dbg_dpc, vha, 0x401d,
7272 "Quiescing I/O - ha=%p.\n", ha);
7274 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
7275 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
7276 atomic_set(&vha->loop_state, LOOP_DOWN);
7277 qla2x00_mark_all_devices_lost(vha);
7279 spin_lock_irqsave(&ha->vport_slock, flags);
7280 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7281 atomic_inc(&vp->vref_count);
7282 spin_unlock_irqrestore(&ha->vport_slock, flags);
7284 qla2x00_mark_all_devices_lost(vp);
7286 spin_lock_irqsave(&ha->vport_slock, flags);
7287 atomic_dec(&vp->vref_count);
7289 spin_unlock_irqrestore(&ha->vport_slock, flags);
7291 if (!atomic_read(&vha->loop_down_timer))
7292 atomic_set(&vha->loop_down_timer,
7295 /* Wait for pending cmds to complete */
7296 WARN_ON_ONCE(qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST)
7301 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
7303 struct qla_hw_data *ha = vha->hw;
7304 struct scsi_qla_host *vp, *tvp;
7305 unsigned long flags;
7309 /* For ISP82XX, driver waits for completion of the commands.
7310 * online flag should be set.
7312 if (!(IS_P3P_TYPE(ha)))
7313 vha->flags.online = 0;
7314 ha->flags.chip_reset_done = 0;
7315 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
7316 vha->qla_stats.total_isp_aborts++;
7318 ql_log(ql_log_info, vha, 0x00af,
7319 "Performing ISP error recovery - ha=%p.\n", ha);
7321 ha->flags.purge_mbox = 1;
7322 /* For ISP82XX, reset_chip is just disabling interrupts.
7323 * Driver waits for the completion of the commands.
7324 * the interrupts need to be enabled.
7326 if (!(IS_P3P_TYPE(ha)))
7327 ha->isp_ops->reset_chip(vha);
7329 ha->link_data_rate = PORT_SPEED_UNKNOWN;
7331 ha->flags.rida_fmt2 = 0;
7332 ha->flags.n2n_ae = 0;
7333 ha->flags.lip_ae = 0;
7334 ha->current_topology = 0;
7336 ha->flags.fw_init_done = 0;
7338 ha->base_qpair->chip_reset = ha->chip_reset;
7339 ha->base_qpair->cmd_cnt = ha->base_qpair->cmd_completion_cnt = 0;
7340 ha->base_qpair->prev_completion_cnt = 0;
7341 for (i = 0; i < ha->max_qpairs; i++) {
7342 if (ha->queue_pair_map[i]) {
7343 ha->queue_pair_map[i]->chip_reset =
7344 ha->base_qpair->chip_reset;
7345 ha->queue_pair_map[i]->cmd_cnt =
7346 ha->queue_pair_map[i]->cmd_completion_cnt = 0;
7347 ha->base_qpair->prev_completion_cnt = 0;
7351 /* purge MBox commands */
7352 if (atomic_read(&ha->num_pend_mbx_stage3)) {
7353 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
7354 complete(&ha->mbx_intr_comp);
7358 while (atomic_read(&ha->num_pend_mbx_stage3) ||
7359 atomic_read(&ha->num_pend_mbx_stage2) ||
7360 atomic_read(&ha->num_pend_mbx_stage1)) {
7366 ha->flags.purge_mbox = 0;
7368 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
7369 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
7370 atomic_set(&vha->loop_state, LOOP_DOWN);
7371 qla2x00_mark_all_devices_lost(vha);
7373 spin_lock_irqsave(&ha->vport_slock, flags);
7374 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7375 atomic_inc(&vp->vref_count);
7376 spin_unlock_irqrestore(&ha->vport_slock, flags);
7378 qla2x00_mark_all_devices_lost(vp);
7380 spin_lock_irqsave(&ha->vport_slock, flags);
7381 atomic_dec(&vp->vref_count);
7383 spin_unlock_irqrestore(&ha->vport_slock, flags);
7385 if (!atomic_read(&vha->loop_down_timer))
7386 atomic_set(&vha->loop_down_timer,
7390 /* Clear all async request states across all VPs. */
7391 list_for_each_entry(fcport, &vha->vp_fcports, list) {
7392 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7393 fcport->scan_state = 0;
7395 spin_lock_irqsave(&ha->vport_slock, flags);
7396 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7397 atomic_inc(&vp->vref_count);
7398 spin_unlock_irqrestore(&ha->vport_slock, flags);
7400 list_for_each_entry(fcport, &vp->vp_fcports, list)
7401 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7403 spin_lock_irqsave(&ha->vport_slock, flags);
7404 atomic_dec(&vp->vref_count);
7406 spin_unlock_irqrestore(&ha->vport_slock, flags);
7408 /* Make sure for ISP 82XX IO DMA is complete */
7409 if (IS_P3P_TYPE(ha)) {
7410 qla82xx_chip_reset_cleanup(vha);
7411 ql_log(ql_log_info, vha, 0x00b4,
7412 "Done chip reset cleanup.\n");
7414 /* Done waiting for pending commands. Reset online flag */
7415 vha->flags.online = 0;
7418 /* Requeue all commands in outstanding command list. */
7419 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
7420 /* memory barrier */
7426 * Resets ISP and aborts all outstanding commands.
7429 * ha = adapter block pointer.
7435 qla2x00_abort_isp(scsi_qla_host_t *vha)
7439 struct qla_hw_data *ha = vha->hw;
7440 struct scsi_qla_host *vp, *tvp;
7441 struct req_que *req = ha->req_q_map[0];
7442 unsigned long flags;
7444 if (vha->flags.online) {
7445 qla2x00_abort_isp_cleanup(vha);
7447 vha->dport_status |= DPORT_DIAG_CHIP_RESET_IN_PROGRESS;
7448 vha->dport_status &= ~DPORT_DIAG_IN_PROGRESS;
7450 if (vha->hw->flags.port_isolated)
7453 if (qla2x00_isp_reg_stat(ha)) {
7454 ql_log(ql_log_info, vha, 0x803f,
7455 "ISP Abort - ISP reg disconnect, exiting.\n");
7459 if (test_and_clear_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags)) {
7460 ha->flags.chip_reset_done = 1;
7461 vha->flags.online = 1;
7463 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7467 if (IS_QLA8031(ha)) {
7468 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
7469 "Clearing fcoe driver presence.\n");
7470 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
7471 ql_dbg(ql_dbg_p3p, vha, 0xb073,
7472 "Error while clearing DRV-Presence.\n");
7475 if (unlikely(pci_channel_offline(ha->pdev) &&
7476 ha->flags.pci_channel_io_perm_failure)) {
7477 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7482 switch (vha->qlini_mode) {
7483 case QLA2XXX_INI_MODE_DISABLED:
7484 if (!qla_tgt_mode_enabled(vha))
7487 case QLA2XXX_INI_MODE_DUAL:
7488 if (!qla_dual_mode_enabled(vha) &&
7489 !qla_ini_mode_enabled(vha))
7492 case QLA2XXX_INI_MODE_ENABLED:
7497 ha->isp_ops->get_flash_version(vha, req->ring);
7499 if (qla2x00_isp_reg_stat(ha)) {
7500 ql_log(ql_log_info, vha, 0x803f,
7501 "ISP Abort - ISP reg disconnect pre nvram config, exiting.\n");
7504 ha->isp_ops->nvram_config(vha);
7506 if (qla2x00_isp_reg_stat(ha)) {
7507 ql_log(ql_log_info, vha, 0x803f,
7508 "ISP Abort - ISP reg disconnect post nvmram config, exiting.\n");
7511 if (!qla2x00_restart_isp(vha)) {
7512 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7514 if (!atomic_read(&vha->loop_down_timer)) {
7516 * Issue marker command only when we are going
7517 * to start the I/O .
7519 vha->marker_needed = 1;
7522 vha->flags.online = 1;
7524 ha->isp_ops->enable_intrs(ha);
7526 ha->isp_abort_cnt = 0;
7527 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7529 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
7530 qla2x00_get_fw_version(vha);
7532 ha->flags.fce_enabled = 1;
7534 fce_calc_size(ha->fce_bufs));
7535 rval = qla2x00_enable_fce_trace(vha,
7536 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
7539 ql_log(ql_log_warn, vha, 0x8033,
7540 "Unable to reinitialize FCE "
7542 ha->flags.fce_enabled = 0;
7547 memset(ha->eft, 0, EFT_SIZE);
7548 rval = qla2x00_enable_eft_trace(vha,
7549 ha->eft_dma, EFT_NUM_BUFFERS);
7551 ql_log(ql_log_warn, vha, 0x8034,
7552 "Unable to reinitialize EFT "
7556 } else { /* failed the ISP abort */
7557 vha->flags.online = 1;
7558 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
7559 if (ha->isp_abort_cnt == 0) {
7560 ql_log(ql_log_fatal, vha, 0x8035,
7561 "ISP error recover failed - "
7562 "board disabled.\n");
7564 * The next call disables the board
7567 qla2x00_abort_isp_cleanup(vha);
7568 vha->flags.online = 0;
7569 clear_bit(ISP_ABORT_RETRY,
7572 } else { /* schedule another ISP abort */
7573 ha->isp_abort_cnt--;
7574 ql_dbg(ql_dbg_taskm, vha, 0x8020,
7575 "ISP abort - retry remaining %d.\n",
7580 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
7581 ql_dbg(ql_dbg_taskm, vha, 0x8021,
7582 "ISP error recovery - retrying (%d) "
7583 "more times.\n", ha->isp_abort_cnt);
7584 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7591 if (vha->hw->flags.port_isolated) {
7592 qla2x00_abort_isp_cleanup(vha);
7597 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
7598 qla2x00_configure_hba(vha);
7599 spin_lock_irqsave(&ha->vport_slock, flags);
7600 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7602 atomic_inc(&vp->vref_count);
7603 spin_unlock_irqrestore(&ha->vport_slock, flags);
7605 qla2x00_vp_abort_isp(vp);
7607 spin_lock_irqsave(&ha->vport_slock, flags);
7608 atomic_dec(&vp->vref_count);
7611 spin_unlock_irqrestore(&ha->vport_slock, flags);
7613 if (IS_QLA8031(ha)) {
7614 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
7615 "Setting back fcoe driver presence.\n");
7616 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
7617 ql_dbg(ql_dbg_p3p, vha, 0xb074,
7618 "Error while setting DRV-Presence.\n");
7621 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
7629 * qla2x00_restart_isp
7630 * restarts the ISP after a reset
7633 * ha = adapter block pointer.
7639 qla2x00_restart_isp(scsi_qla_host_t *vha)
7642 struct qla_hw_data *ha = vha->hw;
7644 /* If firmware needs to be loaded */
7645 if (qla2x00_isp_firmware(vha)) {
7646 vha->flags.online = 0;
7647 status = ha->isp_ops->chip_diag(vha);
7650 status = qla2x00_setup_chip(vha);
7655 status = qla2x00_init_rings(vha);
7659 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7660 ha->flags.chip_reset_done = 1;
7662 /* Initialize the queues in use */
7663 qla25xx_init_queues(ha);
7665 status = qla2x00_fw_ready(vha);
7667 /* if no cable then assume it's good */
7668 return vha->device_flags & DFLG_NO_CABLE ? 0 : status;
7671 /* Issue a marker after FW becomes ready. */
7672 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
7673 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7679 qla25xx_init_queues(struct qla_hw_data *ha)
7681 struct rsp_que *rsp = NULL;
7682 struct req_que *req = NULL;
7683 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7687 for (i = 1; i < ha->max_rsp_queues; i++) {
7688 rsp = ha->rsp_q_map[i];
7689 if (rsp && test_bit(i, ha->rsp_qid_map)) {
7690 rsp->options &= ~BIT_0;
7691 ret = qla25xx_init_rsp_que(base_vha, rsp);
7692 if (ret != QLA_SUCCESS)
7693 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
7694 "%s Rsp que: %d init failed.\n",
7697 ql_dbg(ql_dbg_init, base_vha, 0x0100,
7698 "%s Rsp que: %d inited.\n",
7702 for (i = 1; i < ha->max_req_queues; i++) {
7703 req = ha->req_q_map[i];
7704 if (req && test_bit(i, ha->req_qid_map)) {
7705 /* Clear outstanding commands array. */
7706 req->options &= ~BIT_0;
7707 ret = qla25xx_init_req_que(base_vha, req);
7708 if (ret != QLA_SUCCESS)
7709 ql_dbg(ql_dbg_init, base_vha, 0x0101,
7710 "%s Req que: %d init failed.\n",
7713 ql_dbg(ql_dbg_init, base_vha, 0x0102,
7714 "%s Req que: %d inited.\n",
7722 * qla2x00_reset_adapter
7726 * ha = adapter block pointer.
7729 qla2x00_reset_adapter(scsi_qla_host_t *vha)
7731 unsigned long flags = 0;
7732 struct qla_hw_data *ha = vha->hw;
7733 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7735 vha->flags.online = 0;
7736 ha->isp_ops->disable_intrs(ha);
7738 spin_lock_irqsave(&ha->hardware_lock, flags);
7739 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
7740 rd_reg_word(®->hccr); /* PCI Posting. */
7741 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
7742 rd_reg_word(®->hccr); /* PCI Posting. */
7743 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7749 qla24xx_reset_adapter(scsi_qla_host_t *vha)
7751 unsigned long flags = 0;
7752 struct qla_hw_data *ha = vha->hw;
7753 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
7755 if (IS_P3P_TYPE(ha))
7758 vha->flags.online = 0;
7759 ha->isp_ops->disable_intrs(ha);
7761 spin_lock_irqsave(&ha->hardware_lock, flags);
7762 wrt_reg_dword(®->hccr, HCCRX_SET_RISC_RESET);
7763 rd_reg_dword(®->hccr);
7764 wrt_reg_dword(®->hccr, HCCRX_REL_RISC_PAUSE);
7765 rd_reg_dword(®->hccr);
7766 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7768 if (IS_NOPOLLING_TYPE(ha))
7769 ha->isp_ops->enable_intrs(ha);
7774 /* On sparc systems, obtain port and node WWN from firmware
7777 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
7778 struct nvram_24xx *nv)
7781 struct qla_hw_data *ha = vha->hw;
7782 struct pci_dev *pdev = ha->pdev;
7783 struct device_node *dp = pci_device_to_OF_node(pdev);
7787 val = of_get_property(dp, "port-wwn", &len);
7788 if (val && len >= WWN_SIZE)
7789 memcpy(nv->port_name, val, WWN_SIZE);
7791 val = of_get_property(dp, "node-wwn", &len);
7792 if (val && len >= WWN_SIZE)
7793 memcpy(nv->node_name, val, WWN_SIZE);
7798 qla24xx_nvram_config(scsi_qla_host_t *vha)
7801 struct init_cb_24xx *icb;
7802 struct nvram_24xx *nv;
7804 uint8_t *dptr1, *dptr2;
7807 struct qla_hw_data *ha = vha->hw;
7810 icb = (struct init_cb_24xx *)ha->init_cb;
7813 /* Determine NVRAM starting address. */
7814 if (ha->port_no == 0) {
7815 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
7816 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
7818 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
7819 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
7822 ha->nvram_size = sizeof(*nv);
7823 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7825 /* Get VPD data into cache */
7826 ha->vpd = ha->nvram + VPD_OFFSET;
7827 ha->isp_ops->read_nvram(vha, ha->vpd,
7828 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
7830 /* Get NVRAM data into cache and calculate checksum. */
7831 dptr = (__force __le32 *)nv;
7832 ha->isp_ops->read_nvram(vha, dptr, ha->nvram_base, ha->nvram_size);
7833 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7834 chksum += le32_to_cpu(*dptr);
7836 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
7837 "Contents of NVRAM\n");
7838 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
7839 nv, ha->nvram_size);
7841 /* Bad NVRAM data, set defaults parameters. */
7842 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
7843 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
7844 /* Reset NVRAM data. */
7845 ql_log(ql_log_warn, vha, 0x006b,
7846 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
7847 chksum, nv->id, nv->nvram_version);
7848 ql_dump_buffer(ql_dbg_init, vha, 0x006b, nv, sizeof(*nv));
7849 ql_log(ql_log_warn, vha, 0x006c,
7850 "Falling back to functioning (yet invalid -- WWPN) "
7854 * Set default initialization control block.
7856 memset(nv, 0, ha->nvram_size);
7857 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7858 nv->version = cpu_to_le16(ICB_VERSION);
7859 nv->frame_payload_size = cpu_to_le16(2048);
7860 nv->execution_throttle = cpu_to_le16(0xFFFF);
7861 nv->exchange_count = cpu_to_le16(0);
7862 nv->hard_address = cpu_to_le16(124);
7863 nv->port_name[0] = 0x21;
7864 nv->port_name[1] = 0x00 + ha->port_no + 1;
7865 nv->port_name[2] = 0x00;
7866 nv->port_name[3] = 0xe0;
7867 nv->port_name[4] = 0x8b;
7868 nv->port_name[5] = 0x1c;
7869 nv->port_name[6] = 0x55;
7870 nv->port_name[7] = 0x86;
7871 nv->node_name[0] = 0x20;
7872 nv->node_name[1] = 0x00;
7873 nv->node_name[2] = 0x00;
7874 nv->node_name[3] = 0xe0;
7875 nv->node_name[4] = 0x8b;
7876 nv->node_name[5] = 0x1c;
7877 nv->node_name[6] = 0x55;
7878 nv->node_name[7] = 0x86;
7879 qla24xx_nvram_wwn_from_ofw(vha, nv);
7880 nv->login_retry_count = cpu_to_le16(8);
7881 nv->interrupt_delay_timer = cpu_to_le16(0);
7882 nv->login_timeout = cpu_to_le16(0);
7883 nv->firmware_options_1 =
7884 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7885 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7886 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7887 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7888 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7889 nv->efi_parameters = cpu_to_le32(0);
7890 nv->reset_delay = 5;
7891 nv->max_luns_per_target = cpu_to_le16(128);
7892 nv->port_down_retry_count = cpu_to_le16(30);
7893 nv->link_down_timeout = cpu_to_le16(30);
7898 if (qla_tgt_mode_enabled(vha)) {
7899 /* Don't enable full login after initial LIP */
7900 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7901 /* Don't enable LIP full login for initiator */
7902 nv->host_p &= cpu_to_le32(~BIT_10);
7905 qlt_24xx_config_nvram_stage1(vha, nv);
7907 /* Reset Initialization control block */
7908 memset(icb, 0, ha->init_cb_size);
7910 /* Copy 1st segment. */
7911 dptr1 = (uint8_t *)icb;
7912 dptr2 = (uint8_t *)&nv->version;
7913 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7915 *dptr1++ = *dptr2++;
7917 icb->login_retry_count = nv->login_retry_count;
7918 icb->link_down_on_nos = nv->link_down_on_nos;
7920 /* Copy 2nd segment. */
7921 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7922 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7923 cnt = (uint8_t *)&icb->reserved_3 -
7924 (uint8_t *)&icb->interrupt_delay_timer;
7926 *dptr1++ = *dptr2++;
7927 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
7929 * Setup driver NVRAM options.
7931 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7934 qlt_24xx_config_nvram_stage2(vha, icb);
7936 if (nv->host_p & cpu_to_le32(BIT_15)) {
7937 /* Use alternate WWN? */
7938 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7939 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7942 /* Prepare nodename */
7943 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7945 * Firmware will apply the following mask if the nodename was
7948 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7949 icb->node_name[0] &= 0xF0;
7952 /* Set host adapter parameters. */
7953 ha->flags.disable_risc_code_load = 0;
7954 ha->flags.enable_lip_reset = 0;
7955 ha->flags.enable_lip_full_login =
7956 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
7957 ha->flags.enable_target_reset =
7958 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
7959 ha->flags.enable_led_scheme = 0;
7960 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
7962 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7963 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7965 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
7966 sizeof(ha->fw_seriallink_options24));
7968 /* save HBA serial number */
7969 ha->serial0 = icb->port_name[5];
7970 ha->serial1 = icb->port_name[6];
7971 ha->serial2 = icb->port_name[7];
7972 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7973 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7975 icb->execution_throttle = cpu_to_le16(0xFFFF);
7977 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7979 /* Set minimum login_timeout to 4 seconds. */
7980 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7981 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7982 if (le16_to_cpu(nv->login_timeout) < 4)
7983 nv->login_timeout = cpu_to_le16(4);
7984 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7986 /* Set minimum RATOV to 100 tenths of a second. */
7989 ha->loop_reset_delay = nv->reset_delay;
7991 /* Link Down Timeout = 0:
7993 * When Port Down timer expires we will start returning
7994 * I/O's to OS with "DID_NO_CONNECT".
7996 * Link Down Timeout != 0:
7998 * The driver waits for the link to come up after link down
7999 * before returning I/Os to OS with "DID_NO_CONNECT".
8001 if (le16_to_cpu(nv->link_down_timeout) == 0) {
8002 ha->loop_down_abort_time =
8003 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
8005 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
8006 ha->loop_down_abort_time =
8007 (LOOP_DOWN_TIME - ha->link_down_timeout);
8010 /* Need enough time to try and get the port back. */
8011 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8012 if (qlport_down_retry)
8013 ha->port_down_retry_count = qlport_down_retry;
8015 /* Set login_retry_count */
8016 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8017 if (ha->port_down_retry_count ==
8018 le16_to_cpu(nv->port_down_retry_count) &&
8019 ha->port_down_retry_count > 3)
8020 ha->login_retry_count = ha->port_down_retry_count;
8021 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8022 ha->login_retry_count = ha->port_down_retry_count;
8023 if (ql2xloginretrycount)
8024 ha->login_retry_count = ql2xloginretrycount;
8026 /* N2N: driver will initiate Login instead of FW */
8027 icb->firmware_options_3 |= cpu_to_le32(BIT_8);
8030 if (!vha->flags.init_done) {
8031 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8032 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8033 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8034 le16_to_cpu(icb->interrupt_delay_timer) : 2;
8036 icb->firmware_options_2 &= cpu_to_le32(
8037 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8038 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8039 ha->zio_mode = QLA_ZIO_MODE_6;
8041 ql_log(ql_log_info, vha, 0x006f,
8042 "ZIO mode %d enabled; timer delay (%d us).\n",
8043 ha->zio_mode, ha->zio_timer * 100);
8045 icb->firmware_options_2 |= cpu_to_le32(
8046 (uint32_t)ha->zio_mode);
8047 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8051 ql_log(ql_log_warn, vha, 0x0070,
8052 "NVRAM configuration failed.\n");
8058 qla27xx_print_image(struct scsi_qla_host *vha, char *name,
8059 struct qla27xx_image_status *image_status)
8061 ql_dbg(ql_dbg_init, vha, 0x018b,
8062 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
8064 image_status->image_status_mask,
8065 le16_to_cpu(image_status->generation),
8066 image_status->ver_major,
8067 image_status->ver_minor,
8068 image_status->bitmap,
8069 le32_to_cpu(image_status->checksum),
8070 le32_to_cpu(image_status->signature));
8074 qla28xx_check_aux_image_status_signature(
8075 struct qla27xx_image_status *image_status)
8077 ulong signature = le32_to_cpu(image_status->signature);
8079 return signature != QLA28XX_AUX_IMG_STATUS_SIGN;
8083 qla27xx_check_image_status_signature(struct qla27xx_image_status *image_status)
8085 ulong signature = le32_to_cpu(image_status->signature);
8088 signature != QLA27XX_IMG_STATUS_SIGN &&
8089 signature != QLA28XX_IMG_STATUS_SIGN;
8093 qla27xx_image_status_checksum(struct qla27xx_image_status *image_status)
8095 __le32 *p = (__force __le32 *)image_status;
8096 uint n = sizeof(*image_status) / sizeof(*p);
8100 sum += le32_to_cpup(p);
8106 qla28xx_component_bitmask(struct qla27xx_image_status *aux, uint bitmask)
8108 return aux->bitmap & bitmask ?
8109 QLA27XX_SECONDARY_IMAGE : QLA27XX_PRIMARY_IMAGE;
8113 qla28xx_component_status(
8114 struct active_regions *active_regions, struct qla27xx_image_status *aux)
8116 active_regions->aux.board_config =
8117 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_BOARD_CONFIG);
8119 active_regions->aux.vpd_nvram =
8120 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_VPD_NVRAM);
8122 active_regions->aux.npiv_config_0_1 =
8123 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1);
8125 active_regions->aux.npiv_config_2_3 =
8126 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3);
8128 active_regions->aux.nvme_params =
8129 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NVME_PARAMS);
8133 qla27xx_compare_image_generation(
8134 struct qla27xx_image_status *pri_image_status,
8135 struct qla27xx_image_status *sec_image_status)
8137 /* calculate generation delta as uint16 (this accounts for wrap) */
8139 le16_to_cpu(pri_image_status->generation) -
8140 le16_to_cpu(sec_image_status->generation);
8142 ql_dbg(ql_dbg_init, NULL, 0x0180, "generation delta = %d\n", delta);
8148 qla28xx_get_aux_images(
8149 struct scsi_qla_host *vha, struct active_regions *active_regions)
8151 struct qla_hw_data *ha = vha->hw;
8152 struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
8153 bool valid_pri_image = false, valid_sec_image = false;
8154 bool active_pri_image = false, active_sec_image = false;
8156 if (!ha->flt_region_aux_img_status_pri) {
8157 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
8158 goto check_sec_image;
8161 qla24xx_read_flash_data(vha, (uint32_t *)&pri_aux_image_status,
8162 ha->flt_region_aux_img_status_pri,
8163 sizeof(pri_aux_image_status) >> 2);
8164 qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
8166 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
8167 ql_dbg(ql_dbg_init, vha, 0x018b,
8168 "Primary aux image signature (%#x) not valid\n",
8169 le32_to_cpu(pri_aux_image_status.signature));
8170 goto check_sec_image;
8173 if (qla27xx_image_status_checksum(&pri_aux_image_status)) {
8174 ql_dbg(ql_dbg_init, vha, 0x018c,
8175 "Primary aux image checksum failed\n");
8176 goto check_sec_image;
8179 valid_pri_image = true;
8181 if (pri_aux_image_status.image_status_mask & 1) {
8182 ql_dbg(ql_dbg_init, vha, 0x018d,
8183 "Primary aux image is active\n");
8184 active_pri_image = true;
8188 if (!ha->flt_region_aux_img_status_sec) {
8189 ql_dbg(ql_dbg_init, vha, 0x018a,
8190 "Secondary aux image not addressed\n");
8191 goto check_valid_image;
8194 qla24xx_read_flash_data(vha, (uint32_t *)&sec_aux_image_status,
8195 ha->flt_region_aux_img_status_sec,
8196 sizeof(sec_aux_image_status) >> 2);
8197 qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
8199 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
8200 ql_dbg(ql_dbg_init, vha, 0x018b,
8201 "Secondary aux image signature (%#x) not valid\n",
8202 le32_to_cpu(sec_aux_image_status.signature));
8203 goto check_valid_image;
8206 if (qla27xx_image_status_checksum(&sec_aux_image_status)) {
8207 ql_dbg(ql_dbg_init, vha, 0x018c,
8208 "Secondary aux image checksum failed\n");
8209 goto check_valid_image;
8212 valid_sec_image = true;
8214 if (sec_aux_image_status.image_status_mask & 1) {
8215 ql_dbg(ql_dbg_init, vha, 0x018d,
8216 "Secondary aux image is active\n");
8217 active_sec_image = true;
8221 if (valid_pri_image && active_pri_image &&
8222 valid_sec_image && active_sec_image) {
8223 if (qla27xx_compare_image_generation(&pri_aux_image_status,
8224 &sec_aux_image_status) >= 0) {
8225 qla28xx_component_status(active_regions,
8226 &pri_aux_image_status);
8228 qla28xx_component_status(active_regions,
8229 &sec_aux_image_status);
8231 } else if (valid_pri_image && active_pri_image) {
8232 qla28xx_component_status(active_regions, &pri_aux_image_status);
8233 } else if (valid_sec_image && active_sec_image) {
8234 qla28xx_component_status(active_regions, &sec_aux_image_status);
8237 ql_dbg(ql_dbg_init, vha, 0x018f,
8238 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u, NVME=%u\n",
8239 active_regions->aux.board_config,
8240 active_regions->aux.vpd_nvram,
8241 active_regions->aux.npiv_config_0_1,
8242 active_regions->aux.npiv_config_2_3,
8243 active_regions->aux.nvme_params);
8247 qla27xx_get_active_image(struct scsi_qla_host *vha,
8248 struct active_regions *active_regions)
8250 struct qla_hw_data *ha = vha->hw;
8251 struct qla27xx_image_status pri_image_status, sec_image_status;
8252 bool valid_pri_image = false, valid_sec_image = false;
8253 bool active_pri_image = false, active_sec_image = false;
8255 if (!ha->flt_region_img_status_pri) {
8256 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
8257 goto check_sec_image;
8260 if (qla24xx_read_flash_data(vha, (uint32_t *)&pri_image_status,
8261 ha->flt_region_img_status_pri, sizeof(pri_image_status) >> 2) !=
8264 goto check_sec_image;
8266 qla27xx_print_image(vha, "Primary image", &pri_image_status);
8268 if (qla27xx_check_image_status_signature(&pri_image_status)) {
8269 ql_dbg(ql_dbg_init, vha, 0x018b,
8270 "Primary image signature (%#x) not valid\n",
8271 le32_to_cpu(pri_image_status.signature));
8272 goto check_sec_image;
8275 if (qla27xx_image_status_checksum(&pri_image_status)) {
8276 ql_dbg(ql_dbg_init, vha, 0x018c,
8277 "Primary image checksum failed\n");
8278 goto check_sec_image;
8281 valid_pri_image = true;
8283 if (pri_image_status.image_status_mask & 1) {
8284 ql_dbg(ql_dbg_init, vha, 0x018d,
8285 "Primary image is active\n");
8286 active_pri_image = true;
8290 if (!ha->flt_region_img_status_sec) {
8291 ql_dbg(ql_dbg_init, vha, 0x018a, "Secondary image not addressed\n");
8292 goto check_valid_image;
8295 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
8296 ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
8297 qla27xx_print_image(vha, "Secondary image", &sec_image_status);
8299 if (qla27xx_check_image_status_signature(&sec_image_status)) {
8300 ql_dbg(ql_dbg_init, vha, 0x018b,
8301 "Secondary image signature (%#x) not valid\n",
8302 le32_to_cpu(sec_image_status.signature));
8303 goto check_valid_image;
8306 if (qla27xx_image_status_checksum(&sec_image_status)) {
8307 ql_dbg(ql_dbg_init, vha, 0x018c,
8308 "Secondary image checksum failed\n");
8309 goto check_valid_image;
8312 valid_sec_image = true;
8314 if (sec_image_status.image_status_mask & 1) {
8315 ql_dbg(ql_dbg_init, vha, 0x018d,
8316 "Secondary image is active\n");
8317 active_sec_image = true;
8321 if (valid_pri_image && active_pri_image)
8322 active_regions->global = QLA27XX_PRIMARY_IMAGE;
8324 if (valid_sec_image && active_sec_image) {
8325 if (!active_regions->global ||
8326 qla27xx_compare_image_generation(
8327 &pri_image_status, &sec_image_status) < 0) {
8328 active_regions->global = QLA27XX_SECONDARY_IMAGE;
8332 ql_dbg(ql_dbg_init, vha, 0x018f, "active image %s (%u)\n",
8333 active_regions->global == QLA27XX_DEFAULT_IMAGE ?
8334 "default (boot/fw)" :
8335 active_regions->global == QLA27XX_PRIMARY_IMAGE ?
8337 active_regions->global == QLA27XX_SECONDARY_IMAGE ?
8338 "secondary" : "invalid",
8339 active_regions->global);
8342 bool qla24xx_risc_firmware_invalid(uint32_t *dword)
8345 !(dword[4] | dword[5] | dword[6] | dword[7]) ||
8346 !(~dword[4] | ~dword[5] | ~dword[6] | ~dword[7]);
8350 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
8354 uint templates, segments, fragment;
8359 uint32_t risc_addr, risc_size, risc_attr = 0;
8360 struct qla_hw_data *ha = vha->hw;
8361 struct req_que *req = ha->req_q_map[0];
8362 struct fwdt *fwdt = ha->fwdt;
8364 ql_dbg(ql_dbg_init, vha, 0x008b,
8365 "FW: Loading firmware from flash (%x).\n", faddr);
8367 dcode = (uint32_t *)req->ring;
8368 qla24xx_read_flash_data(vha, dcode, faddr, 8);
8369 if (qla24xx_risc_firmware_invalid(dcode)) {
8370 ql_log(ql_log_fatal, vha, 0x008c,
8371 "Unable to verify the integrity of flash firmware "
8373 ql_log(ql_log_fatal, vha, 0x008d,
8374 "Firmware data: %08x %08x %08x %08x.\n",
8375 dcode[0], dcode[1], dcode[2], dcode[3]);
8377 return QLA_FUNCTION_FAILED;
8380 dcode = (uint32_t *)req->ring;
8382 segments = FA_RISC_CODE_SEGMENTS;
8383 for (j = 0; j < segments; j++) {
8384 ql_dbg(ql_dbg_init, vha, 0x008d,
8385 "-> Loading segment %u...\n", j);
8386 qla24xx_read_flash_data(vha, dcode, faddr, 10);
8387 risc_addr = be32_to_cpu((__force __be32)dcode[2]);
8388 risc_size = be32_to_cpu((__force __be32)dcode[3]);
8390 *srisc_addr = risc_addr;
8391 risc_attr = be32_to_cpu((__force __be32)dcode[9]);
8394 dlen = ha->fw_transfer_size >> 2;
8395 for (fragment = 0; risc_size; fragment++) {
8396 if (dlen > risc_size)
8399 ql_dbg(ql_dbg_init, vha, 0x008e,
8400 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
8401 fragment, risc_addr, faddr, dlen);
8402 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
8403 for (i = 0; i < dlen; i++)
8404 dcode[i] = swab32(dcode[i]);
8406 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
8408 ql_log(ql_log_fatal, vha, 0x008f,
8409 "-> Failed load firmware fragment %u.\n",
8411 return QLA_FUNCTION_FAILED;
8420 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8423 templates = (risc_attr & BIT_9) ? 2 : 1;
8424 ql_dbg(ql_dbg_init, vha, 0x0160, "-> templates = %u\n", templates);
8425 for (j = 0; j < templates; j++, fwdt++) {
8426 vfree(fwdt->template);
8427 fwdt->template = NULL;
8430 dcode = (uint32_t *)req->ring;
8431 qla24xx_read_flash_data(vha, dcode, faddr, 7);
8432 risc_size = be32_to_cpu((__force __be32)dcode[2]);
8433 ql_dbg(ql_dbg_init, vha, 0x0161,
8434 "-> fwdt%u template array at %#x (%#x dwords)\n",
8435 j, faddr, risc_size);
8436 if (!risc_size || !~risc_size) {
8437 ql_dbg(ql_dbg_init, vha, 0x0162,
8438 "-> fwdt%u failed to read array\n", j);
8442 /* skip header and ignore checksum */
8446 ql_dbg(ql_dbg_init, vha, 0x0163,
8447 "-> fwdt%u template allocate template %#x words...\n",
8449 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
8450 if (!fwdt->template) {
8451 ql_log(ql_log_warn, vha, 0x0164,
8452 "-> fwdt%u failed allocate template.\n", j);
8456 dcode = fwdt->template;
8457 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
8459 if (!qla27xx_fwdt_template_valid(dcode)) {
8460 ql_log(ql_log_warn, vha, 0x0165,
8461 "-> fwdt%u failed template validate\n", j);
8465 dlen = qla27xx_fwdt_template_size(dcode);
8466 ql_dbg(ql_dbg_init, vha, 0x0166,
8467 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8468 j, dlen, dlen / sizeof(*dcode));
8469 if (dlen > risc_size * sizeof(*dcode)) {
8470 ql_log(ql_log_warn, vha, 0x0167,
8471 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8472 j, dlen - risc_size * sizeof(*dcode));
8476 fwdt->length = dlen;
8477 ql_dbg(ql_dbg_init, vha, 0x0168,
8478 "-> fwdt%u loaded template ok\n", j);
8480 faddr += risc_size + 1;
8486 vfree(fwdt->template);
8487 fwdt->template = NULL;
8493 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
8496 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8502 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
8503 struct fw_blob *blob;
8504 struct qla_hw_data *ha = vha->hw;
8505 struct req_que *req = ha->req_q_map[0];
8507 /* Load firmware blob. */
8508 blob = qla2x00_request_firmware(vha);
8510 ql_log(ql_log_info, vha, 0x0083,
8511 "Firmware image unavailable.\n");
8512 ql_log(ql_log_info, vha, 0x0084,
8513 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
8514 return QLA_FUNCTION_FAILED;
8519 wcode = (uint16_t *)req->ring;
8521 fwcode = (__force __be16 *)blob->fw->data;
8524 /* Validate firmware image by checking version. */
8525 if (blob->fw->size < 8 * sizeof(uint16_t)) {
8526 ql_log(ql_log_fatal, vha, 0x0085,
8527 "Unable to verify integrity of firmware image (%zd).\n",
8529 goto fail_fw_integrity;
8531 for (i = 0; i < 4; i++)
8532 wcode[i] = be16_to_cpu(fwcode[i + 4]);
8533 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
8534 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
8535 wcode[2] == 0 && wcode[3] == 0)) {
8536 ql_log(ql_log_fatal, vha, 0x0086,
8537 "Unable to verify integrity of firmware image.\n");
8538 ql_log(ql_log_fatal, vha, 0x0087,
8539 "Firmware data: %04x %04x %04x %04x.\n",
8540 wcode[0], wcode[1], wcode[2], wcode[3]);
8541 goto fail_fw_integrity;
8545 while (*seg && rval == QLA_SUCCESS) {
8547 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
8548 risc_size = be16_to_cpu(fwcode[3]);
8550 /* Validate firmware image size. */
8551 fwclen += risc_size * sizeof(uint16_t);
8552 if (blob->fw->size < fwclen) {
8553 ql_log(ql_log_fatal, vha, 0x0088,
8554 "Unable to verify integrity of firmware image "
8555 "(%zd).\n", blob->fw->size);
8556 goto fail_fw_integrity;
8560 while (risc_size > 0 && rval == QLA_SUCCESS) {
8561 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
8562 if (wlen > risc_size)
8564 ql_dbg(ql_dbg_init, vha, 0x0089,
8565 "Loading risc segment@ risc addr %x number of "
8566 "words 0x%x.\n", risc_addr, wlen);
8568 for (i = 0; i < wlen; i++)
8569 wcode[i] = swab16((__force u32)fwcode[i]);
8571 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
8574 ql_log(ql_log_fatal, vha, 0x008a,
8575 "Failed to load segment %d of firmware.\n",
8592 return QLA_FUNCTION_FAILED;
8596 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8599 uint templates, segments, fragment;
8602 uint32_t risc_addr, risc_size, risc_attr = 0;
8605 struct fw_blob *blob;
8607 struct qla_hw_data *ha = vha->hw;
8608 struct req_que *req = ha->req_q_map[0];
8609 struct fwdt *fwdt = ha->fwdt;
8611 ql_dbg(ql_dbg_init, vha, 0x0090,
8612 "-> FW: Loading via request-firmware.\n");
8614 blob = qla2x00_request_firmware(vha);
8616 ql_log(ql_log_warn, vha, 0x0092,
8617 "-> Firmware file not found.\n");
8619 return QLA_FUNCTION_FAILED;
8622 fwcode = (__force __be32 *)blob->fw->data;
8623 dcode = (__force uint32_t *)fwcode;
8624 if (qla24xx_risc_firmware_invalid(dcode)) {
8625 ql_log(ql_log_fatal, vha, 0x0093,
8626 "Unable to verify integrity of firmware image (%zd).\n",
8628 ql_log(ql_log_fatal, vha, 0x0095,
8629 "Firmware data: %08x %08x %08x %08x.\n",
8630 dcode[0], dcode[1], dcode[2], dcode[3]);
8631 return QLA_FUNCTION_FAILED;
8634 dcode = (uint32_t *)req->ring;
8636 segments = FA_RISC_CODE_SEGMENTS;
8637 for (j = 0; j < segments; j++) {
8638 ql_dbg(ql_dbg_init, vha, 0x0096,
8639 "-> Loading segment %u...\n", j);
8640 risc_addr = be32_to_cpu(fwcode[2]);
8641 risc_size = be32_to_cpu(fwcode[3]);
8644 *srisc_addr = risc_addr;
8645 risc_attr = be32_to_cpu(fwcode[9]);
8648 dlen = ha->fw_transfer_size >> 2;
8649 for (fragment = 0; risc_size; fragment++) {
8650 if (dlen > risc_size)
8653 ql_dbg(ql_dbg_init, vha, 0x0097,
8654 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
8655 fragment, risc_addr,
8656 (uint32_t)(fwcode - (typeof(fwcode))blob->fw->data),
8659 for (i = 0; i < dlen; i++)
8660 dcode[i] = swab32((__force u32)fwcode[i]);
8662 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
8664 ql_log(ql_log_fatal, vha, 0x0098,
8665 "-> Failed load firmware fragment %u.\n",
8667 return QLA_FUNCTION_FAILED;
8676 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8679 templates = (risc_attr & BIT_9) ? 2 : 1;
8680 ql_dbg(ql_dbg_init, vha, 0x0170, "-> templates = %u\n", templates);
8681 for (j = 0; j < templates; j++, fwdt++) {
8682 vfree(fwdt->template);
8683 fwdt->template = NULL;
8686 risc_size = be32_to_cpu(fwcode[2]);
8687 ql_dbg(ql_dbg_init, vha, 0x0171,
8688 "-> fwdt%u template array at %#x (%#x dwords)\n",
8689 j, (uint32_t)((void *)fwcode - (void *)blob->fw->data),
8691 if (!risc_size || !~risc_size) {
8692 ql_dbg(ql_dbg_init, vha, 0x0172,
8693 "-> fwdt%u failed to read array\n", j);
8697 /* skip header and ignore checksum */
8701 ql_dbg(ql_dbg_init, vha, 0x0173,
8702 "-> fwdt%u template allocate template %#x words...\n",
8704 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
8705 if (!fwdt->template) {
8706 ql_log(ql_log_warn, vha, 0x0174,
8707 "-> fwdt%u failed allocate template.\n", j);
8711 dcode = fwdt->template;
8712 for (i = 0; i < risc_size; i++)
8713 dcode[i] = (__force u32)fwcode[i];
8715 if (!qla27xx_fwdt_template_valid(dcode)) {
8716 ql_log(ql_log_warn, vha, 0x0175,
8717 "-> fwdt%u failed template validate\n", j);
8721 dlen = qla27xx_fwdt_template_size(dcode);
8722 ql_dbg(ql_dbg_init, vha, 0x0176,
8723 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8724 j, dlen, dlen / sizeof(*dcode));
8725 if (dlen > risc_size * sizeof(*dcode)) {
8726 ql_log(ql_log_warn, vha, 0x0177,
8727 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8728 j, dlen - risc_size * sizeof(*dcode));
8732 fwdt->length = dlen;
8733 ql_dbg(ql_dbg_init, vha, 0x0178,
8734 "-> fwdt%u loaded template ok\n", j);
8736 fwcode += risc_size + 1;
8742 vfree(fwdt->template);
8743 fwdt->template = NULL;
8750 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8754 if (ql2xfwloadbin == 1)
8755 return qla81xx_load_risc(vha, srisc_addr);
8759 * 1) Firmware via request-firmware interface (.bin file).
8760 * 2) Firmware residing in flash.
8762 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8763 if (rval == QLA_SUCCESS)
8766 return qla24xx_load_risc_flash(vha, srisc_addr,
8767 vha->hw->flt_region_fw);
8771 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8774 struct qla_hw_data *ha = vha->hw;
8775 struct active_regions active_regions = { };
8777 if (ql2xfwloadbin == 2)
8780 /* FW Load priority:
8781 * 1) Firmware residing in flash.
8782 * 2) Firmware via request-firmware interface (.bin file).
8783 * 3) Golden-Firmware residing in flash -- (limited operation).
8786 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8787 goto try_primary_fw;
8789 qla27xx_get_active_image(vha, &active_regions);
8791 if (active_regions.global != QLA27XX_SECONDARY_IMAGE)
8792 goto try_primary_fw;
8794 ql_dbg(ql_dbg_init, vha, 0x008b,
8795 "Loading secondary firmware image.\n");
8796 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw_sec);
8801 ql_dbg(ql_dbg_init, vha, 0x008b,
8802 "Loading primary firmware image.\n");
8803 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
8808 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8809 if (!rval || !ha->flt_region_gold_fw)
8812 ql_log(ql_log_info, vha, 0x0099,
8813 "Attempting to fallback to golden firmware.\n");
8814 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
8818 ql_log(ql_log_info, vha, 0x009a, "Need firmware flash update.\n");
8819 ha->flags.running_gold_fw = 1;
8824 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
8827 struct qla_hw_data *ha = vha->hw;
8829 if (ha->flags.pci_channel_io_perm_failure)
8831 if (!IS_FWI2_CAPABLE(ha))
8833 if (!ha->fw_major_version)
8835 if (!ha->flags.fw_started)
8838 ret = qla2x00_stop_firmware(vha);
8839 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
8840 ret != QLA_INVALID_COMMAND && retries ; retries--) {
8841 ha->isp_ops->reset_chip(vha);
8842 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
8844 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
8846 ql_log(ql_log_info, vha, 0x8015,
8847 "Attempting retry of stop-firmware command.\n");
8848 ret = qla2x00_stop_firmware(vha);
8852 ha->flags.fw_init_done = 0;
8856 qla24xx_configure_vhba(scsi_qla_host_t *vha)
8858 int rval = QLA_SUCCESS;
8860 uint16_t mb[MAILBOX_REGISTER_COUNT];
8861 struct qla_hw_data *ha = vha->hw;
8862 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
8867 rval = qla2x00_fw_ready(base_vha);
8869 if (rval == QLA_SUCCESS) {
8870 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8871 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8874 vha->flags.management_server_logged_in = 0;
8876 /* Login to SNS first */
8877 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
8879 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
8880 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
8881 ql_dbg(ql_dbg_init, vha, 0x0120,
8882 "Failed SNS login: loop_id=%x, rval2=%d\n",
8885 ql_dbg(ql_dbg_init, vha, 0x0103,
8886 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
8887 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
8888 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
8889 return (QLA_FUNCTION_FAILED);
8892 atomic_set(&vha->loop_down_timer, 0);
8893 atomic_set(&vha->loop_state, LOOP_UP);
8894 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8895 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
8896 rval = qla2x00_loop_resync(base_vha);
8901 /* 84XX Support **************************************************************/
8903 static LIST_HEAD(qla_cs84xx_list);
8904 static DEFINE_MUTEX(qla_cs84xx_mutex);
8906 static struct qla_chip_state_84xx *
8907 qla84xx_get_chip(struct scsi_qla_host *vha)
8909 struct qla_chip_state_84xx *cs84xx;
8910 struct qla_hw_data *ha = vha->hw;
8912 mutex_lock(&qla_cs84xx_mutex);
8914 /* Find any shared 84xx chip. */
8915 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
8916 if (cs84xx->bus == ha->pdev->bus) {
8917 kref_get(&cs84xx->kref);
8922 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
8926 kref_init(&cs84xx->kref);
8927 spin_lock_init(&cs84xx->access_lock);
8928 mutex_init(&cs84xx->fw_update_mutex);
8929 cs84xx->bus = ha->pdev->bus;
8931 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
8933 mutex_unlock(&qla_cs84xx_mutex);
8938 __qla84xx_chip_release(struct kref *kref)
8940 struct qla_chip_state_84xx *cs84xx =
8941 container_of(kref, struct qla_chip_state_84xx, kref);
8943 mutex_lock(&qla_cs84xx_mutex);
8944 list_del(&cs84xx->list);
8945 mutex_unlock(&qla_cs84xx_mutex);
8950 qla84xx_put_chip(struct scsi_qla_host *vha)
8952 struct qla_hw_data *ha = vha->hw;
8955 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
8959 qla84xx_init_chip(scsi_qla_host_t *vha)
8963 struct qla_hw_data *ha = vha->hw;
8965 mutex_lock(&ha->cs84xx->fw_update_mutex);
8967 rval = qla84xx_verify_chip(vha, status);
8969 mutex_unlock(&ha->cs84xx->fw_update_mutex);
8971 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED :
8975 /* 81XX Support **************************************************************/
8978 qla81xx_nvram_config(scsi_qla_host_t *vha)
8981 struct init_cb_81xx *icb;
8982 struct nvram_81xx *nv;
8984 uint8_t *dptr1, *dptr2;
8987 struct qla_hw_data *ha = vha->hw;
8989 struct active_regions active_regions = { };
8992 icb = (struct init_cb_81xx *)ha->init_cb;
8995 /* Determine NVRAM starting address. */
8996 ha->nvram_size = sizeof(*nv);
8997 ha->vpd_size = FA_NVRAM_VPD_SIZE;
8998 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
8999 ha->vpd_size = FA_VPD_SIZE_82XX;
9001 if (IS_QLA28XX(ha) || IS_QLA27XX(ha))
9002 qla28xx_get_aux_images(vha, &active_regions);
9004 /* Get VPD data into cache */
9005 ha->vpd = ha->nvram + VPD_OFFSET;
9007 faddr = ha->flt_region_vpd;
9008 if (IS_QLA28XX(ha)) {
9009 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
9010 faddr = ha->flt_region_vpd_sec;
9011 ql_dbg(ql_dbg_init, vha, 0x0110,
9012 "Loading %s nvram image.\n",
9013 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
9014 "primary" : "secondary");
9016 ha->isp_ops->read_optrom(vha, ha->vpd, faddr << 2, ha->vpd_size);
9018 /* Get NVRAM data into cache and calculate checksum. */
9019 faddr = ha->flt_region_nvram;
9020 if (IS_QLA28XX(ha)) {
9021 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
9022 faddr = ha->flt_region_nvram_sec;
9024 ql_dbg(ql_dbg_init, vha, 0x0110,
9025 "Loading %s nvram image.\n",
9026 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
9027 "primary" : "secondary");
9028 ha->isp_ops->read_optrom(vha, ha->nvram, faddr << 2, ha->nvram_size);
9030 dptr = (__force __le32 *)nv;
9031 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
9032 chksum += le32_to_cpu(*dptr);
9034 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
9035 "Contents of NVRAM:\n");
9036 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
9037 nv, ha->nvram_size);
9039 /* Bad NVRAM data, set defaults parameters. */
9040 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
9041 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
9042 /* Reset NVRAM data. */
9043 ql_log(ql_log_info, vha, 0x0073,
9044 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
9045 chksum, nv->id, le16_to_cpu(nv->nvram_version));
9046 ql_dump_buffer(ql_dbg_init, vha, 0x0073, nv, sizeof(*nv));
9047 ql_log(ql_log_info, vha, 0x0074,
9048 "Falling back to functioning (yet invalid -- WWPN) "
9052 * Set default initialization control block.
9054 memset(nv, 0, ha->nvram_size);
9055 nv->nvram_version = cpu_to_le16(ICB_VERSION);
9056 nv->version = cpu_to_le16(ICB_VERSION);
9057 nv->frame_payload_size = cpu_to_le16(2048);
9058 nv->execution_throttle = cpu_to_le16(0xFFFF);
9059 nv->exchange_count = cpu_to_le16(0);
9060 nv->port_name[0] = 0x21;
9061 nv->port_name[1] = 0x00 + ha->port_no + 1;
9062 nv->port_name[2] = 0x00;
9063 nv->port_name[3] = 0xe0;
9064 nv->port_name[4] = 0x8b;
9065 nv->port_name[5] = 0x1c;
9066 nv->port_name[6] = 0x55;
9067 nv->port_name[7] = 0x86;
9068 nv->node_name[0] = 0x20;
9069 nv->node_name[1] = 0x00;
9070 nv->node_name[2] = 0x00;
9071 nv->node_name[3] = 0xe0;
9072 nv->node_name[4] = 0x8b;
9073 nv->node_name[5] = 0x1c;
9074 nv->node_name[6] = 0x55;
9075 nv->node_name[7] = 0x86;
9076 nv->login_retry_count = cpu_to_le16(8);
9077 nv->interrupt_delay_timer = cpu_to_le16(0);
9078 nv->login_timeout = cpu_to_le16(0);
9079 nv->firmware_options_1 =
9080 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
9081 nv->firmware_options_2 = cpu_to_le32(2 << 4);
9082 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
9083 nv->firmware_options_3 = cpu_to_le32(2 << 13);
9084 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
9085 nv->efi_parameters = cpu_to_le32(0);
9086 nv->reset_delay = 5;
9087 nv->max_luns_per_target = cpu_to_le16(128);
9088 nv->port_down_retry_count = cpu_to_le16(30);
9089 nv->link_down_timeout = cpu_to_le16(180);
9090 nv->enode_mac[0] = 0x00;
9091 nv->enode_mac[1] = 0xC0;
9092 nv->enode_mac[2] = 0xDD;
9093 nv->enode_mac[3] = 0x04;
9094 nv->enode_mac[4] = 0x05;
9095 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
9100 if (IS_T10_PI_CAPABLE(ha))
9101 nv->frame_payload_size &= cpu_to_le16(~7);
9103 qlt_81xx_config_nvram_stage1(vha, nv);
9105 /* Reset Initialization control block */
9106 memset(icb, 0, ha->init_cb_size);
9108 /* Copy 1st segment. */
9109 dptr1 = (uint8_t *)icb;
9110 dptr2 = (uint8_t *)&nv->version;
9111 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
9113 *dptr1++ = *dptr2++;
9115 icb->login_retry_count = nv->login_retry_count;
9117 /* Copy 2nd segment. */
9118 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
9119 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
9120 cnt = (uint8_t *)&icb->reserved_5 -
9121 (uint8_t *)&icb->interrupt_delay_timer;
9123 *dptr1++ = *dptr2++;
9125 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
9126 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
9127 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
9128 icb->enode_mac[0] = 0x00;
9129 icb->enode_mac[1] = 0xC0;
9130 icb->enode_mac[2] = 0xDD;
9131 icb->enode_mac[3] = 0x04;
9132 icb->enode_mac[4] = 0x05;
9133 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
9136 /* Use extended-initialization control block. */
9137 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
9138 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
9140 * Setup driver NVRAM options.
9142 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
9145 qlt_81xx_config_nvram_stage2(vha, icb);
9147 /* Use alternate WWN? */
9148 if (nv->host_p & cpu_to_le32(BIT_15)) {
9149 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
9150 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
9153 /* Prepare nodename */
9154 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
9156 * Firmware will apply the following mask if the nodename was
9159 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
9160 icb->node_name[0] &= 0xF0;
9163 if (IS_QLA28XX(ha) || IS_QLA27XX(ha)) {
9164 if ((nv->enhanced_features & BIT_7) == 0)
9165 ha->flags.scm_supported_a = 1;
9168 /* Set host adapter parameters. */
9169 ha->flags.disable_risc_code_load = 0;
9170 ha->flags.enable_lip_reset = 0;
9171 ha->flags.enable_lip_full_login =
9172 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
9173 ha->flags.enable_target_reset =
9174 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
9175 ha->flags.enable_led_scheme = 0;
9176 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
9178 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
9179 (BIT_6 | BIT_5 | BIT_4)) >> 4;
9181 /* save HBA serial number */
9182 ha->serial0 = icb->port_name[5];
9183 ha->serial1 = icb->port_name[6];
9184 ha->serial2 = icb->port_name[7];
9185 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
9186 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
9188 icb->execution_throttle = cpu_to_le16(0xFFFF);
9190 ha->retry_count = le16_to_cpu(nv->login_retry_count);
9192 /* Set minimum login_timeout to 4 seconds. */
9193 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
9194 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
9195 if (le16_to_cpu(nv->login_timeout) < 4)
9196 nv->login_timeout = cpu_to_le16(4);
9197 ha->login_timeout = le16_to_cpu(nv->login_timeout);
9199 /* Set minimum RATOV to 100 tenths of a second. */
9202 ha->loop_reset_delay = nv->reset_delay;
9204 /* Link Down Timeout = 0:
9206 * When Port Down timer expires we will start returning
9207 * I/O's to OS with "DID_NO_CONNECT".
9209 * Link Down Timeout != 0:
9211 * The driver waits for the link to come up after link down
9212 * before returning I/Os to OS with "DID_NO_CONNECT".
9214 if (le16_to_cpu(nv->link_down_timeout) == 0) {
9215 ha->loop_down_abort_time =
9216 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
9218 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
9219 ha->loop_down_abort_time =
9220 (LOOP_DOWN_TIME - ha->link_down_timeout);
9223 /* Need enough time to try and get the port back. */
9224 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
9225 if (qlport_down_retry)
9226 ha->port_down_retry_count = qlport_down_retry;
9228 /* Set login_retry_count */
9229 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
9230 if (ha->port_down_retry_count ==
9231 le16_to_cpu(nv->port_down_retry_count) &&
9232 ha->port_down_retry_count > 3)
9233 ha->login_retry_count = ha->port_down_retry_count;
9234 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
9235 ha->login_retry_count = ha->port_down_retry_count;
9236 if (ql2xloginretrycount)
9237 ha->login_retry_count = ql2xloginretrycount;
9239 /* if not running MSI-X we need handshaking on interrupts */
9240 if (!vha->hw->flags.msix_enabled &&
9241 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)))
9242 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
9245 if (!vha->flags.init_done) {
9246 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
9247 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
9248 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
9249 le16_to_cpu(icb->interrupt_delay_timer) : 2;
9251 icb->firmware_options_2 &= cpu_to_le32(
9252 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
9253 vha->flags.process_response_queue = 0;
9254 if (ha->zio_mode != QLA_ZIO_DISABLED) {
9255 ha->zio_mode = QLA_ZIO_MODE_6;
9257 ql_log(ql_log_info, vha, 0x0075,
9258 "ZIO mode %d enabled; timer delay (%d us).\n",
9260 ha->zio_timer * 100);
9262 icb->firmware_options_2 |= cpu_to_le32(
9263 (uint32_t)ha->zio_mode);
9264 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
9265 vha->flags.process_response_queue = 1;
9268 /* enable RIDA Format2 */
9269 icb->firmware_options_3 |= cpu_to_le32(BIT_0);
9271 /* N2N: driver will initiate Login instead of FW */
9272 icb->firmware_options_3 |= cpu_to_le32(BIT_8);
9274 /* Determine NVMe/FCP priority for target ports */
9275 ha->fc4_type_priority = qla2xxx_get_fc4_priority(vha);
9278 ql_log(ql_log_warn, vha, 0x0076,
9279 "NVRAM configuration failed.\n");
9285 qla82xx_restart_isp(scsi_qla_host_t *vha)
9288 struct qla_hw_data *ha = vha->hw;
9289 struct scsi_qla_host *vp, *tvp;
9290 unsigned long flags;
9292 status = qla2x00_init_rings(vha);
9294 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
9295 ha->flags.chip_reset_done = 1;
9297 status = qla2x00_fw_ready(vha);
9299 /* Issue a marker after FW becomes ready. */
9300 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
9301 vha->flags.online = 1;
9302 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
9305 /* if no cable then assume it's good */
9306 if ((vha->device_flags & DFLG_NO_CABLE))
9311 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
9313 if (!atomic_read(&vha->loop_down_timer)) {
9315 * Issue marker command only when we are going
9316 * to start the I/O .
9318 vha->marker_needed = 1;
9321 ha->isp_ops->enable_intrs(ha);
9323 ha->isp_abort_cnt = 0;
9324 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
9326 /* Update the firmware version */
9327 status = qla82xx_check_md_needed(vha);
9330 ha->flags.fce_enabled = 1;
9332 fce_calc_size(ha->fce_bufs));
9333 rval = qla2x00_enable_fce_trace(vha,
9334 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
9337 ql_log(ql_log_warn, vha, 0x8001,
9338 "Unable to reinitialize FCE (%d).\n",
9340 ha->flags.fce_enabled = 0;
9345 memset(ha->eft, 0, EFT_SIZE);
9346 rval = qla2x00_enable_eft_trace(vha,
9347 ha->eft_dma, EFT_NUM_BUFFERS);
9349 ql_log(ql_log_warn, vha, 0x8010,
9350 "Unable to reinitialize EFT (%d).\n",
9357 ql_dbg(ql_dbg_taskm, vha, 0x8011,
9358 "qla82xx_restart_isp succeeded.\n");
9360 spin_lock_irqsave(&ha->vport_slock, flags);
9361 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
9363 atomic_inc(&vp->vref_count);
9364 spin_unlock_irqrestore(&ha->vport_slock, flags);
9366 qla2x00_vp_abort_isp(vp);
9368 spin_lock_irqsave(&ha->vport_slock, flags);
9369 atomic_dec(&vp->vref_count);
9372 spin_unlock_irqrestore(&ha->vport_slock, flags);
9375 ql_log(ql_log_warn, vha, 0x8016,
9376 "qla82xx_restart_isp **** FAILED ****.\n");
9383 * qla24xx_get_fcp_prio
9384 * Gets the fcp cmd priority value for the logged in port.
9385 * Looks for a match of the port descriptors within
9386 * each of the fcp prio config entries. If a match is found,
9387 * the tag (priority) value is returned.
9390 * vha = scsi host structure pointer.
9391 * fcport = port structure pointer.
9394 * non-zero (if found)
9401 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
9404 uint8_t pid_match, wwn_match;
9406 uint32_t pid1, pid2;
9407 uint64_t wwn1, wwn2;
9408 struct qla_fcp_prio_entry *pri_entry;
9409 struct qla_hw_data *ha = vha->hw;
9411 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
9415 entries = ha->fcp_prio_cfg->num_entries;
9416 pri_entry = &ha->fcp_prio_cfg->entry[0];
9418 for (i = 0; i < entries; i++) {
9419 pid_match = wwn_match = 0;
9421 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
9426 /* check source pid for a match */
9427 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
9428 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
9429 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
9430 if (pid1 == INVALID_PORT_ID)
9432 else if (pid1 == pid2)
9436 /* check destination pid for a match */
9437 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
9438 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
9439 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
9440 if (pid1 == INVALID_PORT_ID)
9442 else if (pid1 == pid2)
9446 /* check source WWN for a match */
9447 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
9448 wwn1 = wwn_to_u64(vha->port_name);
9449 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
9450 if (wwn2 == (uint64_t)-1)
9452 else if (wwn1 == wwn2)
9456 /* check destination WWN for a match */
9457 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
9458 wwn1 = wwn_to_u64(fcport->port_name);
9459 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
9460 if (wwn2 == (uint64_t)-1)
9462 else if (wwn1 == wwn2)
9466 if (pid_match == 2 || wwn_match == 2) {
9467 /* Found a matching entry */
9468 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
9469 priority = pri_entry->tag;
9480 * qla24xx_update_fcport_fcp_prio
9481 * Activates fcp priority for the logged in fc port
9484 * vha = scsi host structure pointer.
9485 * fcp = port structure pointer.
9488 * QLA_SUCCESS or QLA_FUNCTION_FAILED
9494 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
9500 if (fcport->port_type != FCT_TARGET ||
9501 fcport->loop_id == FC_NO_LOOP_ID)
9502 return QLA_FUNCTION_FAILED;
9504 priority = qla24xx_get_fcp_prio(vha, fcport);
9506 return QLA_FUNCTION_FAILED;
9508 if (IS_P3P_TYPE(vha->hw)) {
9509 fcport->fcp_prio = priority & 0xf;
9513 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
9514 if (ret == QLA_SUCCESS) {
9515 if (fcport->fcp_prio != priority)
9516 ql_dbg(ql_dbg_user, vha, 0x709e,
9517 "Updated FCP_CMND priority - value=%d loop_id=%d "
9518 "port_id=%02x%02x%02x.\n", priority,
9519 fcport->loop_id, fcport->d_id.b.domain,
9520 fcport->d_id.b.area, fcport->d_id.b.al_pa);
9521 fcport->fcp_prio = priority & 0xf;
9523 ql_dbg(ql_dbg_user, vha, 0x704f,
9524 "Unable to update FCP_CMND priority - ret=0x%x for "
9525 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
9526 fcport->d_id.b.domain, fcport->d_id.b.area,
9527 fcport->d_id.b.al_pa);
9532 * qla24xx_update_all_fcp_prio
9533 * Activates fcp priority for all the logged in ports
9536 * ha = adapter block pointer.
9539 * QLA_SUCCESS or QLA_FUNCTION_FAILED
9545 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
9550 ret = QLA_FUNCTION_FAILED;
9551 /* We need to set priority for all logged in ports */
9552 list_for_each_entry(fcport, &vha->vp_fcports, list)
9553 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
9558 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
9559 int vp_idx, bool startqp)
9564 struct qla_hw_data *ha = vha->hw;
9565 uint16_t qpair_id = 0;
9566 struct qla_qpair *qpair = NULL;
9567 struct qla_msix_entry *msix;
9569 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
9570 ql_log(ql_log_warn, vha, 0x00181,
9571 "FW/Driver is not multi-queue capable.\n");
9575 if (ql2xmqsupport || ql2xnvmeenable) {
9576 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
9577 if (qpair == NULL) {
9578 ql_log(ql_log_warn, vha, 0x0182,
9579 "Failed to allocate memory for queue pair.\n");
9583 qpair->hw = vha->hw;
9585 qpair->qp_lock_ptr = &qpair->qp_lock;
9586 spin_lock_init(&qpair->qp_lock);
9587 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
9589 /* Assign available que pair id */
9590 mutex_lock(&ha->mq_lock);
9591 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
9592 if (ha->num_qpairs >= ha->max_qpairs) {
9593 mutex_unlock(&ha->mq_lock);
9594 ql_log(ql_log_warn, vha, 0x0183,
9595 "No resources to create additional q pair.\n");
9599 set_bit(qpair_id, ha->qpair_qid_map);
9600 ha->queue_pair_map[qpair_id] = qpair;
9601 qpair->id = qpair_id;
9602 qpair->vp_idx = vp_idx;
9603 qpair->fw_started = ha->flags.fw_started;
9604 INIT_LIST_HEAD(&qpair->hints_list);
9605 qpair->chip_reset = ha->base_qpair->chip_reset;
9606 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
9607 qpair->enable_explicit_conf =
9608 ha->base_qpair->enable_explicit_conf;
9610 for (i = 0; i < ha->msix_count; i++) {
9611 msix = &ha->msix_entries[i];
9615 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
9616 "Vector %x selected for qpair\n", msix->vector);
9620 ql_log(ql_log_warn, vha, 0x0184,
9621 "Out of MSI-X vectors!.\n");
9625 qpair->msix->in_use = 1;
9626 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
9627 qpair->pdev = ha->pdev;
9628 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
9629 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
9631 mutex_unlock(&ha->mq_lock);
9633 /* Create response queue first */
9634 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
9636 ql_log(ql_log_warn, vha, 0x0185,
9637 "Failed to create response queue.\n");
9641 qpair->rsp = ha->rsp_q_map[rsp_id];
9643 /* Create request queue */
9644 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
9647 ql_log(ql_log_warn, vha, 0x0186,
9648 "Failed to create request queue.\n");
9652 qpair->req = ha->req_q_map[req_id];
9653 qpair->rsp->req = qpair->req;
9654 qpair->rsp->qpair = qpair;
9656 if (!qpair->cpu_mapped)
9657 qla_cpu_update(qpair, raw_smp_processor_id());
9659 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
9660 if (ha->fw_attributes & BIT_4)
9661 qpair->difdix_supported = 1;
9664 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
9665 if (!qpair->srb_mempool) {
9666 ql_log(ql_log_warn, vha, 0xd036,
9667 "Failed to create srb mempool for qpair %d\n",
9672 if (qla_create_buf_pool(vha, qpair)) {
9673 ql_log(ql_log_warn, vha, 0xd036,
9674 "Failed to initialize buf pool for qpair %d\n",
9679 /* Mark as online */
9682 if (!vha->flags.qpairs_available)
9683 vha->flags.qpairs_available = 1;
9685 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
9686 "Request/Response queue pair created, id %d\n",
9688 ql_dbg(ql_dbg_init, vha, 0x0187,
9689 "Request/Response queue pair created, id %d\n",
9695 mempool_destroy(qpair->srb_mempool);
9697 qla25xx_delete_req_que(vha, qpair->req);
9699 qla25xx_delete_rsp_que(vha, qpair->rsp);
9701 mutex_lock(&ha->mq_lock);
9702 qpair->msix->in_use = 0;
9703 list_del(&qpair->qp_list_elem);
9704 if (list_empty(&vha->qp_list))
9705 vha->flags.qpairs_available = 0;
9707 ha->queue_pair_map[qpair_id] = NULL;
9708 clear_bit(qpair_id, ha->qpair_qid_map);
9710 mutex_unlock(&ha->mq_lock);
9716 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
9718 int ret = QLA_FUNCTION_FAILED;
9719 struct qla_hw_data *ha = qpair->hw;
9721 qpair->delete_in_progress = 1;
9723 qla_free_buf_pool(qpair);
9725 ret = qla25xx_delete_req_que(vha, qpair->req);
9726 if (ret != QLA_SUCCESS)
9729 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
9730 if (ret != QLA_SUCCESS)
9733 mutex_lock(&ha->mq_lock);
9734 ha->queue_pair_map[qpair->id] = NULL;
9735 clear_bit(qpair->id, ha->qpair_qid_map);
9737 list_del(&qpair->qp_list_elem);
9738 if (list_empty(&vha->qp_list)) {
9739 vha->flags.qpairs_available = 0;
9740 vha->flags.qpairs_req_created = 0;
9741 vha->flags.qpairs_rsp_created = 0;
9743 mempool_destroy(qpair->srb_mempool);
9745 mutex_unlock(&ha->mq_lock);
9753 qla2x00_count_set_bits(uint32_t num)
9755 /* Brian Kernighan's Algorithm */
9766 qla2x00_get_num_tgts(scsi_qla_host_t *vha)
9774 list_for_each_entry_safe(f, tf, &vha->vp_fcports, list) {
9775 if (f->port_type != FCT_TARGET)
9782 int qla2xxx_reset_stats(struct Scsi_Host *host, u32 flags)
9784 scsi_qla_host_t *vha = shost_priv(host);
9785 fc_port_t *fcport = NULL;
9786 unsigned long int_flags;
9788 if (flags & QLA2XX_HW_ERROR)
9789 vha->hw_err_cnt = 0;
9790 if (flags & QLA2XX_SHT_LNK_DWN)
9791 vha->short_link_down_cnt = 0;
9792 if (flags & QLA2XX_INT_ERR)
9793 vha->interface_err_cnt = 0;
9794 if (flags & QLA2XX_CMD_TIMEOUT)
9795 vha->cmd_timeout_cnt = 0;
9796 if (flags & QLA2XX_RESET_CMD_ERR)
9797 vha->reset_cmd_err_cnt = 0;
9798 if (flags & QLA2XX_TGT_SHT_LNK_DOWN) {
9799 spin_lock_irqsave(&vha->hw->tgt.sess_lock, int_flags);
9800 list_for_each_entry(fcport, &vha->vp_fcports, list) {
9801 fcport->tgt_short_link_down_cnt = 0;
9802 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
9804 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, int_flags);
9806 vha->link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
9810 int qla2xxx_start_stats(struct Scsi_Host *host, u32 flags)
9812 return qla2xxx_reset_stats(host, flags);
9815 int qla2xxx_stop_stats(struct Scsi_Host *host, u32 flags)
9817 return qla2xxx_reset_stats(host, flags);
9820 int qla2xxx_get_ini_stats(struct Scsi_Host *host, u32 flags,
9821 void *data, u64 size)
9823 scsi_qla_host_t *vha = shost_priv(host);
9824 struct ql_vnd_host_stats_resp *resp = (struct ql_vnd_host_stats_resp *)data;
9825 struct ql_vnd_stats *rsp_data = &resp->stats;
9826 u64 ini_entry_count = 0;
9828 u64 entry_count = 0;
9830 u32 tmp_stat_type = 0;
9831 fc_port_t *fcport = NULL;
9832 unsigned long int_flags;
9834 /* Copy stat type to work on it */
9835 tmp_stat_type = flags;
9837 if (tmp_stat_type & BIT_17) {
9838 num_tgt = qla2x00_get_num_tgts(vha);
9840 tmp_stat_type &= ~(1 << 17);
9842 ini_entry_count = qla2x00_count_set_bits(tmp_stat_type);
9844 entry_count = ini_entry_count + num_tgt;
9846 rsp_data->entry_count = entry_count;
9849 if (flags & QLA2XX_HW_ERROR) {
9850 rsp_data->entry[i].stat_type = QLA2XX_HW_ERROR;
9851 rsp_data->entry[i].tgt_num = 0x0;
9852 rsp_data->entry[i].cnt = vha->hw_err_cnt;
9856 if (flags & QLA2XX_SHT_LNK_DWN) {
9857 rsp_data->entry[i].stat_type = QLA2XX_SHT_LNK_DWN;
9858 rsp_data->entry[i].tgt_num = 0x0;
9859 rsp_data->entry[i].cnt = vha->short_link_down_cnt;
9863 if (flags & QLA2XX_INT_ERR) {
9864 rsp_data->entry[i].stat_type = QLA2XX_INT_ERR;
9865 rsp_data->entry[i].tgt_num = 0x0;
9866 rsp_data->entry[i].cnt = vha->interface_err_cnt;
9870 if (flags & QLA2XX_CMD_TIMEOUT) {
9871 rsp_data->entry[i].stat_type = QLA2XX_CMD_TIMEOUT;
9872 rsp_data->entry[i].tgt_num = 0x0;
9873 rsp_data->entry[i].cnt = vha->cmd_timeout_cnt;
9877 if (flags & QLA2XX_RESET_CMD_ERR) {
9878 rsp_data->entry[i].stat_type = QLA2XX_RESET_CMD_ERR;
9879 rsp_data->entry[i].tgt_num = 0x0;
9880 rsp_data->entry[i].cnt = vha->reset_cmd_err_cnt;
9884 /* i will continue from previous loop, as target
9885 * entries are after initiator
9887 if (flags & QLA2XX_TGT_SHT_LNK_DOWN) {
9888 spin_lock_irqsave(&vha->hw->tgt.sess_lock, int_flags);
9889 list_for_each_entry(fcport, &vha->vp_fcports, list) {
9890 if (fcport->port_type != FCT_TARGET)
9894 rsp_data->entry[i].stat_type = QLA2XX_TGT_SHT_LNK_DOWN;
9895 rsp_data->entry[i].tgt_num = fcport->rport->number;
9896 rsp_data->entry[i].cnt = fcport->tgt_short_link_down_cnt;
9899 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, int_flags);
9901 resp->status = EXT_STATUS_OK;
9906 int qla2xxx_get_tgt_stats(struct Scsi_Host *host, u32 flags,
9907 struct fc_rport *rport, void *data, u64 size)
9909 struct ql_vnd_tgt_stats_resp *tgt_data = data;
9910 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
9912 tgt_data->status = 0;
9913 tgt_data->stats.entry_count = 1;
9914 tgt_data->stats.entry[0].stat_type = flags;
9915 tgt_data->stats.entry[0].tgt_num = rport->number;
9916 tgt_data->stats.entry[0].cnt = fcport->tgt_short_link_down_cnt;
9921 int qla2xxx_disable_port(struct Scsi_Host *host)
9923 scsi_qla_host_t *vha = shost_priv(host);
9925 vha->hw->flags.port_isolated = 1;
9927 if (qla2x00_isp_reg_stat(vha->hw)) {
9928 ql_log(ql_log_info, vha, 0x9006,
9929 "PCI/Register disconnect, exiting.\n");
9930 qla_pci_set_eeh_busy(vha);
9933 if (qla2x00_chip_is_down(vha))
9936 if (vha->flags.online) {
9937 qla2x00_abort_isp_cleanup(vha);
9938 qla2x00_wait_for_sess_deletion(vha);
9944 int qla2xxx_enable_port(struct Scsi_Host *host)
9946 scsi_qla_host_t *vha = shost_priv(host);
9948 if (qla2x00_isp_reg_stat(vha->hw)) {
9949 ql_log(ql_log_info, vha, 0x9001,
9950 "PCI/Register disconnect, exiting.\n");
9951 qla_pci_set_eeh_busy(vha);
9955 vha->hw->flags.port_isolated = 0;
9956 /* Set the flag to 1, so that isp_abort can proceed */
9957 vha->flags.online = 1;
9958 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
9959 qla2xxx_wake_dpc(vha);