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 int qla24xx_post_prli_work(struct scsi_qla_host*, fc_port_t *);
38 static void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha,
39 struct event_arg *ea);
40 static void qla24xx_handle_prli_done_event(struct scsi_qla_host *,
42 static void __qla24xx_handle_gpdb_event(scsi_qla_host_t *, struct event_arg *);
44 /* SRB Extensions ---------------------------------------------------------- */
47 qla2x00_sp_timeout(struct timer_list *t)
49 srb_t *sp = from_timer(sp, t, u.iocb_cmd.timer);
50 struct srb_iocb *iocb;
52 WARN_ON(irqs_disabled());
53 iocb = &sp->u.iocb_cmd;
57 void qla2x00_sp_free(srb_t *sp)
59 struct srb_iocb *iocb = &sp->u.iocb_cmd;
61 del_timer(&iocb->timer);
65 void qla2xxx_rel_done_warning(srb_t *sp, int res)
67 WARN_ONCE(1, "Calling done() of an already freed srb %p object\n", sp);
70 void qla2xxx_rel_free_warning(srb_t *sp)
72 WARN_ONCE(1, "Calling free() of an already freed srb %p object\n", sp);
75 /* Asynchronous Login/Logout Routines -------------------------------------- */
78 qla2x00_get_async_timeout(struct scsi_qla_host *vha)
81 struct qla_hw_data *ha = vha->hw;
83 /* Firmware should use switch negotiated r_a_tov for timeout. */
84 tmo = ha->r_a_tov / 10 * 2;
86 tmo = FX00_DEF_RATOV * 2;
87 } else if (!IS_FWI2_CAPABLE(ha)) {
89 * Except for earlier ISPs where the timeout is seeded from the
90 * initialization control block.
92 tmo = ha->login_timeout;
97 static void qla24xx_abort_iocb_timeout(void *data)
100 struct srb_iocb *abt = &sp->u.iocb_cmd;
101 struct qla_qpair *qpair = sp->qpair;
106 ql_dbg(ql_dbg_async, sp->vha, 0x507c,
107 "Abort timeout - cmd hdl=%x, cmd type=%x hdl=%x, type=%x\n",
108 sp->cmd_sp->handle, sp->cmd_sp->type,
109 sp->handle, sp->type);
111 ql_dbg(ql_dbg_async, sp->vha, 0x507c,
112 "Abort timeout 2 - hdl=%x, type=%x\n",
113 sp->handle, sp->type);
115 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
116 for (handle = 1; handle < qpair->req->num_outstanding_cmds; handle++) {
117 if (sp->cmd_sp && (qpair->req->outstanding_cmds[handle] ==
119 qpair->req->outstanding_cmds[handle] = NULL;
121 /* removing the abort */
122 if (qpair->req->outstanding_cmds[handle] == sp) {
123 qpair->req->outstanding_cmds[handle] = NULL;
127 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
130 sp->cmd_sp->done(sp->cmd_sp, QLA_OS_TIMER_EXPIRED);
132 abt->u.abt.comp_status = cpu_to_le16(CS_TIMEOUT);
133 sp->done(sp, QLA_OS_TIMER_EXPIRED);
136 static void qla24xx_abort_sp_done(srb_t *sp, int res)
138 struct srb_iocb *abt = &sp->u.iocb_cmd;
140 del_timer(&sp->u.iocb_cmd.timer);
141 if (sp->flags & SRB_WAKEUP_ON_COMP)
142 complete(&abt->u.abt.comp);
147 int qla24xx_async_abort_cmd(srb_t *cmd_sp, bool wait)
149 scsi_qla_host_t *vha = cmd_sp->vha;
150 struct srb_iocb *abt_iocb;
152 int rval = QLA_FUNCTION_FAILED;
154 sp = qla2xxx_get_qpair_sp(cmd_sp->vha, cmd_sp->qpair, cmd_sp->fcport,
159 abt_iocb = &sp->u.iocb_cmd;
160 sp->type = SRB_ABT_CMD;
162 sp->qpair = cmd_sp->qpair;
165 sp->flags = SRB_WAKEUP_ON_COMP;
167 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
168 init_completion(&abt_iocb->u.abt.comp);
169 /* FW can send 2 x ABTS's timeout/20s */
170 qla2x00_init_timer(sp, 42);
172 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
173 abt_iocb->u.abt.req_que_no = cpu_to_le16(cmd_sp->qpair->req->id);
175 sp->done = qla24xx_abort_sp_done;
177 ql_dbg(ql_dbg_async, vha, 0x507c,
178 "Abort command issued - hdl=%x, type=%x\n", cmd_sp->handle,
181 rval = qla2x00_start_sp(sp);
182 if (rval != QLA_SUCCESS) {
188 wait_for_completion(&abt_iocb->u.abt.comp);
189 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
190 QLA_SUCCESS : QLA_FUNCTION_FAILED;
198 qla2x00_async_iocb_timeout(void *data)
201 fc_port_t *fcport = sp->fcport;
202 struct srb_iocb *lio = &sp->u.iocb_cmd;
207 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
208 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
209 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
211 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
213 pr_info("Async-%s timeout - hdl=%x.\n",
214 sp->name, sp->handle);
219 rc = qla24xx_async_abort_cmd(sp, false);
221 /* Retry as needed. */
222 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
223 lio->u.logio.data[1] =
224 lio->u.logio.flags & SRB_LOGIN_RETRIED ?
225 QLA_LOGIO_LOGIN_RETRIED : 0;
226 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
227 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
229 if (sp->qpair->req->outstanding_cmds[h] ==
231 sp->qpair->req->outstanding_cmds[h] =
236 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
237 sp->done(sp, QLA_FUNCTION_TIMEOUT);
241 case SRB_CT_PTHRU_CMD:
248 rc = qla24xx_async_abort_cmd(sp, false);
250 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
251 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
253 if (sp->qpair->req->outstanding_cmds[h] ==
255 sp->qpair->req->outstanding_cmds[h] =
260 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
261 sp->done(sp, QLA_FUNCTION_TIMEOUT);
267 static void qla2x00_async_login_sp_done(srb_t *sp, int res)
269 struct scsi_qla_host *vha = sp->vha;
270 struct srb_iocb *lio = &sp->u.iocb_cmd;
273 ql_dbg(ql_dbg_disc, vha, 0x20dd,
274 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
276 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
278 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
279 memset(&ea, 0, sizeof(ea));
280 ea.fcport = sp->fcport;
281 ea.data[0] = lio->u.logio.data[0];
282 ea.data[1] = lio->u.logio.data[1];
283 ea.iop[0] = lio->u.logio.iop[0];
284 ea.iop[1] = lio->u.logio.iop[1];
286 qla24xx_handle_plogi_done_event(vha, &ea);
293 fcport_is_smaller(fc_port_t *fcport)
295 if (wwn_to_u64(fcport->port_name) <
296 wwn_to_u64(fcport->vha->port_name))
303 fcport_is_bigger(fc_port_t *fcport)
305 return !fcport_is_smaller(fcport);
309 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
313 struct srb_iocb *lio;
314 int rval = QLA_FUNCTION_FAILED;
316 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
317 fcport->loop_id == FC_NO_LOOP_ID) {
318 ql_log(ql_log_warn, vha, 0xffff,
319 "%s: %8phC - not sending command.\n",
320 __func__, fcport->port_name);
324 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
328 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_PEND);
329 fcport->flags |= FCF_ASYNC_SENT;
330 fcport->logout_completed = 0;
332 sp->type = SRB_LOGIN_CMD;
334 sp->gen1 = fcport->rscn_gen;
335 sp->gen2 = fcport->login_gen;
337 lio = &sp->u.iocb_cmd;
338 lio->timeout = qla2x00_async_iocb_timeout;
339 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
341 sp->done = qla2x00_async_login_sp_done;
342 if (N2N_TOPO(fcport->vha->hw) && fcport_is_bigger(fcport))
343 lio->u.logio.flags |= SRB_LOGIN_PRLI_ONLY;
345 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
347 if (NVME_TARGET(vha->hw, fcport))
348 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
350 ql_dbg(ql_dbg_disc, vha, 0x2072,
351 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
352 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
353 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
354 fcport->login_retry);
356 rval = qla2x00_start_sp(sp);
357 if (rval != QLA_SUCCESS) {
358 fcport->flags |= FCF_LOGIN_NEEDED;
359 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
367 fcport->flags &= ~FCF_ASYNC_SENT;
369 fcport->flags &= ~FCF_ASYNC_ACTIVE;
373 static void qla2x00_async_logout_sp_done(srb_t *sp, int res)
375 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
376 sp->fcport->login_gen++;
377 qlt_logo_completion_handler(sp->fcport, res);
382 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
385 struct srb_iocb *lio;
386 int rval = QLA_FUNCTION_FAILED;
388 fcport->flags |= FCF_ASYNC_SENT;
389 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
393 sp->type = SRB_LOGOUT_CMD;
396 lio = &sp->u.iocb_cmd;
397 lio->timeout = qla2x00_async_iocb_timeout;
398 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
400 sp->done = qla2x00_async_logout_sp_done;
402 ql_dbg(ql_dbg_disc, vha, 0x2070,
403 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
404 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
405 fcport->d_id.b.area, fcport->d_id.b.al_pa,
408 rval = qla2x00_start_sp(sp);
409 if (rval != QLA_SUCCESS)
416 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
421 qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
424 fcport->flags &= ~FCF_ASYNC_ACTIVE;
425 /* Don't re-login in target mode */
426 if (!fcport->tgt_session)
427 qla2x00_mark_device_lost(vha, fcport, 1);
428 qlt_logo_completion_handler(fcport, data[0]);
431 static void qla2x00_async_prlo_sp_done(srb_t *sp, int res)
433 struct srb_iocb *lio = &sp->u.iocb_cmd;
434 struct scsi_qla_host *vha = sp->vha;
436 sp->fcport->flags &= ~FCF_ASYNC_ACTIVE;
437 if (!test_bit(UNLOADING, &vha->dpc_flags))
438 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
444 qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
447 struct srb_iocb *lio;
450 rval = QLA_FUNCTION_FAILED;
451 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
455 sp->type = SRB_PRLO_CMD;
458 lio = &sp->u.iocb_cmd;
459 lio->timeout = qla2x00_async_iocb_timeout;
460 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
462 sp->done = qla2x00_async_prlo_sp_done;
464 ql_dbg(ql_dbg_disc, vha, 0x2070,
465 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
466 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
467 fcport->d_id.b.area, fcport->d_id.b.al_pa);
469 rval = qla2x00_start_sp(sp);
470 if (rval != QLA_SUCCESS)
478 fcport->flags &= ~FCF_ASYNC_ACTIVE;
483 void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
485 struct fc_port *fcport = ea->fcport;
488 ql_dbg(ql_dbg_disc, vha, 0x20d2,
489 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
490 __func__, fcport->port_name, fcport->disc_state,
491 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
492 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
494 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
497 if (ea->data[0] != MBS_COMMAND_COMPLETE) {
498 ql_dbg(ql_dbg_disc, vha, 0x2066,
499 "%s %8phC: adisc fail: post delete\n",
500 __func__, ea->fcport->port_name);
502 spin_lock_irqsave(&vha->work_lock, flags);
503 /* deleted = 0 & logout_on_delete = force fw cleanup */
504 if (fcport->deleted == QLA_SESS_DELETED)
507 fcport->logout_on_delete = 1;
508 spin_unlock_irqrestore(&vha->work_lock, flags);
510 qlt_schedule_sess_for_deletion(ea->fcport);
514 if (ea->fcport->disc_state == DSC_DELETE_PEND)
517 if (ea->sp->gen2 != ea->fcport->login_gen) {
518 /* target side must have changed it. */
519 ql_dbg(ql_dbg_disc, vha, 0x20d3,
520 "%s %8phC generation changed\n",
521 __func__, ea->fcport->port_name);
523 } else if (ea->sp->gen1 != ea->fcport->rscn_gen) {
524 qla_rscn_replay(fcport);
525 qlt_schedule_sess_for_deletion(fcport);
529 __qla24xx_handle_gpdb_event(vha, ea);
532 static int qla_post_els_plogi_work(struct scsi_qla_host *vha, fc_port_t *fcport)
534 struct qla_work_evt *e;
536 e = qla2x00_alloc_work(vha, QLA_EVT_ELS_PLOGI);
538 return QLA_FUNCTION_FAILED;
540 e->u.fcport.fcport = fcport;
541 fcport->flags |= FCF_ASYNC_ACTIVE;
542 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_PEND);
543 return qla2x00_post_work(vha, e);
546 static void qla2x00_async_adisc_sp_done(srb_t *sp, int res)
548 struct scsi_qla_host *vha = sp->vha;
550 struct srb_iocb *lio = &sp->u.iocb_cmd;
552 ql_dbg(ql_dbg_disc, vha, 0x2066,
553 "Async done-%s res %x %8phC\n",
554 sp->name, res, sp->fcport->port_name);
556 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
558 memset(&ea, 0, sizeof(ea));
560 ea.data[0] = lio->u.logio.data[0];
561 ea.data[1] = lio->u.logio.data[1];
562 ea.iop[0] = lio->u.logio.iop[0];
563 ea.iop[1] = lio->u.logio.iop[1];
564 ea.fcport = sp->fcport;
567 qla24xx_handle_adisc_event(vha, &ea);
573 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
577 struct srb_iocb *lio;
578 int rval = QLA_FUNCTION_FAILED;
580 if (IS_SESSION_DELETED(fcport)) {
581 ql_log(ql_log_warn, vha, 0xffff,
582 "%s: %8phC is being delete - not sending command.\n",
583 __func__, fcport->port_name);
584 fcport->flags &= ~FCF_ASYNC_ACTIVE;
588 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
591 fcport->flags |= FCF_ASYNC_SENT;
592 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
596 sp->type = SRB_ADISC_CMD;
599 lio = &sp->u.iocb_cmd;
600 lio->timeout = qla2x00_async_iocb_timeout;
601 sp->gen1 = fcport->rscn_gen;
602 sp->gen2 = fcport->login_gen;
603 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
605 sp->done = qla2x00_async_adisc_sp_done;
606 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
607 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
609 ql_dbg(ql_dbg_disc, vha, 0x206f,
610 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
611 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
613 rval = qla2x00_start_sp(sp);
614 if (rval != QLA_SUCCESS)
622 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
623 qla2x00_post_async_adisc_work(vha, fcport, data);
627 static bool qla2x00_is_reserved_id(scsi_qla_host_t *vha, uint16_t loop_id)
629 struct qla_hw_data *ha = vha->hw;
631 if (IS_FWI2_CAPABLE(ha))
632 return loop_id > NPH_LAST_HANDLE;
634 return (loop_id > ha->max_loop_id && loop_id < SNS_FIRST_LOOP_ID) ||
635 loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST;
639 * qla2x00_find_new_loop_id - scan through our port list and find a new usable loop ID
640 * @vha: adapter state pointer.
641 * @dev: port structure pointer.
644 * qla2x00 local function return status code.
649 static int qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
652 struct qla_hw_data *ha = vha->hw;
653 unsigned long flags = 0;
657 spin_lock_irqsave(&ha->vport_slock, flags);
659 dev->loop_id = find_first_zero_bit(ha->loop_id_map, LOOPID_MAP_SIZE);
660 if (dev->loop_id >= LOOPID_MAP_SIZE ||
661 qla2x00_is_reserved_id(vha, dev->loop_id)) {
662 dev->loop_id = FC_NO_LOOP_ID;
663 rval = QLA_FUNCTION_FAILED;
665 set_bit(dev->loop_id, ha->loop_id_map);
667 spin_unlock_irqrestore(&ha->vport_slock, flags);
669 if (rval == QLA_SUCCESS)
670 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
671 "Assigning new loopid=%x, portid=%x.\n",
672 dev->loop_id, dev->d_id.b24);
674 ql_log(ql_log_warn, dev->vha, 0x2087,
675 "No loop_id's available, portid=%x.\n",
681 void qla2x00_clear_loop_id(fc_port_t *fcport)
683 struct qla_hw_data *ha = fcport->vha->hw;
685 if (fcport->loop_id == FC_NO_LOOP_ID ||
686 qla2x00_is_reserved_id(fcport->vha, fcport->loop_id))
689 clear_bit(fcport->loop_id, ha->loop_id_map);
690 fcport->loop_id = FC_NO_LOOP_ID;
693 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
694 struct event_arg *ea)
696 fc_port_t *fcport, *conflict_fcport;
697 struct get_name_list_extended *e;
698 u16 i, n, found = 0, loop_id;
702 u8 current_login_state, nvme_cls;
705 ql_dbg(ql_dbg_disc, vha, 0xffff,
706 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
707 __func__, fcport->port_name, fcport->disc_state,
708 fcport->fw_login_state, ea->rc,
709 fcport->login_gen, fcport->last_login_gen,
710 fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id);
712 if (fcport->disc_state == DSC_DELETE_PEND)
715 if (ea->rc) { /* rval */
716 if (fcport->login_retry == 0) {
717 ql_dbg(ql_dbg_disc, vha, 0x20de,
718 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
719 fcport->port_name, fcport->login_retry);
724 if (fcport->last_rscn_gen != fcport->rscn_gen) {
725 qla_rscn_replay(fcport);
726 qlt_schedule_sess_for_deletion(fcport);
728 } else if (fcport->last_login_gen != fcport->login_gen) {
729 ql_dbg(ql_dbg_disc, vha, 0x20e0,
730 "%s %8phC login gen changed\n",
731 __func__, fcport->port_name);
735 n = ea->data[0] / sizeof(struct get_name_list_extended);
737 ql_dbg(ql_dbg_disc, vha, 0x20e1,
738 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
739 __func__, __LINE__, fcport->port_name, n,
740 fcport->d_id.b.domain, fcport->d_id.b.area,
741 fcport->d_id.b.al_pa, fcport->loop_id);
743 for (i = 0; i < n; i++) {
745 wwn = wwn_to_u64(e->port_name);
746 id.b.domain = e->port_id[2];
747 id.b.area = e->port_id[1];
748 id.b.al_pa = e->port_id[0];
751 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
754 if (IS_SW_RESV_ADDR(id))
759 loop_id = le16_to_cpu(e->nport_handle);
760 loop_id = (loop_id & 0x7fff);
761 nvme_cls = e->current_login_state >> 4;
762 current_login_state = e->current_login_state & 0xf;
764 if (PRLI_PHASE(nvme_cls)) {
765 current_login_state = nvme_cls;
766 fcport->fc4_type &= ~FS_FC4TYPE_FCP;
767 fcport->fc4_type |= FS_FC4TYPE_NVME;
768 } else if (PRLI_PHASE(current_login_state)) {
769 fcport->fc4_type |= FS_FC4TYPE_FCP;
770 fcport->fc4_type &= ~FS_FC4TYPE_NVME;
773 ql_dbg(ql_dbg_disc, vha, 0x20e2,
774 "%s found %8phC CLS [%x|%x] fc4_type %d ID[%06x|%06x] lid[%d|%d]\n",
775 __func__, fcport->port_name,
776 e->current_login_state, fcport->fw_login_state,
777 fcport->fc4_type, id.b24, fcport->d_id.b24,
778 loop_id, fcport->loop_id);
780 switch (fcport->disc_state) {
781 case DSC_DELETE_PEND:
785 if ((id.b24 != fcport->d_id.b24 &&
787 fcport->loop_id != FC_NO_LOOP_ID) ||
788 (fcport->loop_id != FC_NO_LOOP_ID &&
789 fcport->loop_id != loop_id)) {
790 ql_dbg(ql_dbg_disc, vha, 0x20e3,
791 "%s %d %8phC post del sess\n",
792 __func__, __LINE__, fcport->port_name);
793 if (fcport->n2n_flag)
794 fcport->d_id.b24 = 0;
795 qlt_schedule_sess_for_deletion(fcport);
801 fcport->loop_id = loop_id;
802 if (fcport->n2n_flag)
803 fcport->d_id.b24 = id.b24;
805 wwn = wwn_to_u64(fcport->port_name);
806 qlt_find_sess_invalidate_other(vha, wwn,
807 id, loop_id, &conflict_fcport);
809 if (conflict_fcport) {
811 * Another share fcport share the same loop_id &
812 * nport id. Conflict fcport needs to finish
813 * cleanup before this fcport can proceed to login.
815 conflict_fcport->conflict = fcport;
816 fcport->login_pause = 1;
819 switch (vha->hw->current_topology) {
821 switch (current_login_state) {
822 case DSC_LS_PRLI_COMP:
823 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
824 vha, 0x20e4, "%s %d %8phC post gpdb\n",
825 __func__, __LINE__, fcport->port_name);
827 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
828 fcport->port_type = FCT_INITIATOR;
830 fcport->port_type = FCT_TARGET;
831 data[0] = data[1] = 0;
832 qla2x00_post_async_adisc_work(vha, fcport,
835 case DSC_LS_PORT_UNAVAIL:
837 if (fcport->loop_id == FC_NO_LOOP_ID) {
838 qla2x00_find_new_loop_id(vha, fcport);
839 fcport->fw_login_state =
842 ql_dbg(ql_dbg_disc, vha, 0x20e5,
843 "%s %d %8phC\n", __func__, __LINE__,
845 qla24xx_fcport_handle_login(vha, fcport);
850 fcport->fw_login_state = current_login_state;
852 switch (current_login_state) {
853 case DSC_LS_PRLI_PEND:
855 * In the middle of PRLI. Let it finish.
856 * Allow relogin code to recheck state again
857 * with GNL. Push disc_state back to DELETED
858 * so GNL can go out again
860 qla2x00_set_fcport_disc_state(fcport,
863 case DSC_LS_PRLI_COMP:
864 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
865 fcport->port_type = FCT_INITIATOR;
867 fcport->port_type = FCT_TARGET;
869 data[0] = data[1] = 0;
870 qla2x00_post_async_adisc_work(vha, fcport,
873 case DSC_LS_PLOGI_COMP:
874 if (fcport_is_bigger(fcport)) {
875 /* local adapter is smaller */
876 if (fcport->loop_id != FC_NO_LOOP_ID)
877 qla2x00_clear_loop_id(fcport);
879 fcport->loop_id = loop_id;
880 qla24xx_fcport_handle_login(vha,
886 if (fcport_is_smaller(fcport)) {
887 /* local adapter is bigger */
888 if (fcport->loop_id != FC_NO_LOOP_ID)
889 qla2x00_clear_loop_id(fcport);
891 fcport->loop_id = loop_id;
892 qla24xx_fcport_handle_login(vha,
898 } /* switch (ha->current_topology) */
902 switch (vha->hw->current_topology) {
905 for (i = 0; i < n; i++) {
907 id.b.domain = e->port_id[0];
908 id.b.area = e->port_id[1];
909 id.b.al_pa = e->port_id[2];
911 loop_id = le16_to_cpu(e->nport_handle);
913 if (fcport->d_id.b24 == id.b24) {
915 qla2x00_find_fcport_by_wwpn(vha,
917 if (conflict_fcport) {
918 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
920 "%s %d %8phC post del sess\n",
922 conflict_fcport->port_name);
923 qlt_schedule_sess_for_deletion
928 * FW already picked this loop id for
931 if (fcport->loop_id == loop_id)
932 fcport->loop_id = FC_NO_LOOP_ID;
934 qla24xx_fcport_handle_login(vha, fcport);
937 qla2x00_set_fcport_disc_state(fcport, DSC_DELETED);
938 if (time_after_eq(jiffies, fcport->dm_login_expire)) {
939 if (fcport->n2n_link_reset_cnt < 2) {
940 fcport->n2n_link_reset_cnt++;
942 * remote port is not sending PLOGI.
943 * Reset link to kick start his state
946 set_bit(N2N_LINK_RESET,
949 if (fcport->n2n_chip_reset < 1) {
950 ql_log(ql_log_info, vha, 0x705d,
951 "Chip reset to bring laser down");
952 set_bit(ISP_ABORT_NEEDED,
954 fcport->n2n_chip_reset++;
956 ql_log(ql_log_info, vha, 0x705d,
957 "Remote port %8ph is not coming back\n",
959 fcport->scan_state = 0;
962 qla2xxx_wake_dpc(vha);
965 * report port suppose to do PLOGI. Give him
966 * more time. FW will catch it.
968 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
972 qla24xx_fcport_handle_login(vha, fcport);
980 static void qla24xx_async_gnl_sp_done(srb_t *sp, int res)
982 struct scsi_qla_host *vha = sp->vha;
984 struct fc_port *fcport = NULL, *tf;
985 u16 i, n = 0, loop_id;
987 struct get_name_list_extended *e;
992 ql_dbg(ql_dbg_disc, vha, 0x20e7,
993 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
994 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
995 sp->u.iocb_cmd.u.mbx.in_mb[2]);
998 sp->fcport->flags &= ~(FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE);
999 memset(&ea, 0, sizeof(ea));
1003 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
1004 sizeof(struct get_name_list_extended)) {
1005 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
1006 sizeof(struct get_name_list_extended);
1007 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
1010 for (i = 0; i < n; i++) {
1012 loop_id = le16_to_cpu(e->nport_handle);
1013 /* mask out reserve bit */
1014 loop_id = (loop_id & 0x7fff);
1015 set_bit(loop_id, vha->hw->loop_id_map);
1016 wwn = wwn_to_u64(e->port_name);
1018 ql_dbg(ql_dbg_disc, vha, 0x20e8,
1019 "%s %8phC %02x:%02x:%02x CLS %x/%x lid %x \n",
1020 __func__, &wwn, e->port_id[2], e->port_id[1],
1021 e->port_id[0], e->current_login_state, e->last_login_state,
1022 (loop_id & 0x7fff));
1025 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1029 if (!list_empty(&vha->gnl.fcports))
1030 list_splice_init(&vha->gnl.fcports, &h);
1031 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1033 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
1034 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1035 list_del_init(&fcport->gnl_entry);
1036 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1037 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1040 qla24xx_handle_gnl_done_event(vha, &ea);
1043 /* create new fcport if fw has knowledge of new sessions */
1044 for (i = 0; i < n; i++) {
1049 wwn = wwn_to_u64(e->port_name);
1052 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
1053 if (!memcmp((u8 *)&wwn, fcport->port_name,
1060 id.b.domain = e->port_id[2];
1061 id.b.area = e->port_id[1];
1062 id.b.al_pa = e->port_id[0];
1065 if (!found && wwn && !IS_SW_RESV_ADDR(id)) {
1066 ql_dbg(ql_dbg_disc, vha, 0x2065,
1067 "%s %d %8phC %06x post new sess\n",
1068 __func__, __LINE__, (u8 *)&wwn, id.b24);
1069 wwnn = wwn_to_u64(e->node_name);
1070 qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn,
1071 (u8 *)&wwnn, NULL, 0);
1075 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1077 if (!list_empty(&vha->gnl.fcports)) {
1079 list_for_each_entry_safe(fcport, tf, &vha->gnl.fcports,
1081 list_del_init(&fcport->gnl_entry);
1082 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1083 if (qla24xx_post_gnl_work(vha, fcport) == QLA_SUCCESS)
1087 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1092 int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
1095 struct srb_iocb *mbx;
1096 int rval = QLA_FUNCTION_FAILED;
1097 unsigned long flags;
1100 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
1103 ql_dbg(ql_dbg_disc, vha, 0x20d9,
1104 "Async-gnlist WWPN %8phC \n", fcport->port_name);
1106 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1107 fcport->flags |= FCF_ASYNC_SENT;
1108 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
1109 fcport->last_rscn_gen = fcport->rscn_gen;
1110 fcport->last_login_gen = fcport->login_gen;
1112 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
1113 if (vha->gnl.sent) {
1114 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1118 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1120 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1124 sp->type = SRB_MB_IOCB;
1125 sp->name = "gnlist";
1126 sp->gen1 = fcport->rscn_gen;
1127 sp->gen2 = fcport->login_gen;
1129 mbx = &sp->u.iocb_cmd;
1130 mbx->timeout = qla2x00_async_iocb_timeout;
1131 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
1133 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1134 mb[0] = MBC_PORT_NODE_NAME_LIST;
1135 mb[1] = BIT_2 | BIT_3;
1136 mb[2] = MSW(vha->gnl.ldma);
1137 mb[3] = LSW(vha->gnl.ldma);
1138 mb[6] = MSW(MSD(vha->gnl.ldma));
1139 mb[7] = LSW(MSD(vha->gnl.ldma));
1140 mb[8] = vha->gnl.size;
1141 mb[9] = vha->vp_idx;
1143 sp->done = qla24xx_async_gnl_sp_done;
1145 ql_dbg(ql_dbg_disc, vha, 0x20da,
1146 "Async-%s - OUT WWPN %8phC hndl %x\n",
1147 sp->name, fcport->port_name, sp->handle);
1149 rval = qla2x00_start_sp(sp);
1150 if (rval != QLA_SUCCESS)
1158 fcport->flags &= ~(FCF_ASYNC_ACTIVE | FCF_ASYNC_SENT);
1162 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1164 struct qla_work_evt *e;
1166 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
1168 return QLA_FUNCTION_FAILED;
1170 e->u.fcport.fcport = fcport;
1171 fcport->flags |= FCF_ASYNC_ACTIVE;
1172 return qla2x00_post_work(vha, e);
1175 static void qla24xx_async_gpdb_sp_done(srb_t *sp, int res)
1177 struct scsi_qla_host *vha = sp->vha;
1178 struct qla_hw_data *ha = vha->hw;
1179 fc_port_t *fcport = sp->fcport;
1180 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
1181 struct event_arg ea;
1183 ql_dbg(ql_dbg_disc, vha, 0x20db,
1184 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
1185 sp->name, res, fcport->port_name, mb[1], mb[2]);
1187 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1189 if (res == QLA_FUNCTION_TIMEOUT)
1192 memset(&ea, 0, sizeof(ea));
1196 qla24xx_handle_gpdb_event(vha, &ea);
1199 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
1200 sp->u.iocb_cmd.u.mbx.in_dma);
1205 static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1207 struct qla_work_evt *e;
1209 if (vha->host->active_mode == MODE_TARGET)
1210 return QLA_FUNCTION_FAILED;
1212 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
1214 return QLA_FUNCTION_FAILED;
1216 e->u.fcport.fcport = fcport;
1218 return qla2x00_post_work(vha, e);
1221 static void qla2x00_async_prli_sp_done(srb_t *sp, int res)
1223 struct scsi_qla_host *vha = sp->vha;
1224 struct srb_iocb *lio = &sp->u.iocb_cmd;
1225 struct event_arg ea;
1227 ql_dbg(ql_dbg_disc, vha, 0x2129,
1228 "%s %8phC res %d \n", __func__,
1229 sp->fcport->port_name, res);
1231 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1233 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
1234 memset(&ea, 0, sizeof(ea));
1235 ea.fcport = sp->fcport;
1236 ea.data[0] = lio->u.logio.data[0];
1237 ea.data[1] = lio->u.logio.data[1];
1238 ea.iop[0] = lio->u.logio.iop[0];
1239 ea.iop[1] = lio->u.logio.iop[1];
1242 qla24xx_handle_prli_done_event(vha, &ea);
1249 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
1252 struct srb_iocb *lio;
1253 int rval = QLA_FUNCTION_FAILED;
1255 if (!vha->flags.online) {
1256 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1257 __func__, __LINE__, fcport->port_name);
1261 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
1262 fcport->fw_login_state == DSC_LS_PRLI_PEND) &&
1263 qla_dual_mode_enabled(vha)) {
1264 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1265 __func__, __LINE__, fcport->port_name);
1269 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1273 fcport->flags |= FCF_ASYNC_SENT;
1274 fcport->logout_completed = 0;
1276 sp->type = SRB_PRLI_CMD;
1279 lio = &sp->u.iocb_cmd;
1280 lio->timeout = qla2x00_async_iocb_timeout;
1281 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1283 sp->done = qla2x00_async_prli_sp_done;
1284 lio->u.logio.flags = 0;
1286 if (NVME_TARGET(vha->hw, fcport))
1287 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
1289 ql_dbg(ql_dbg_disc, vha, 0x211b,
1290 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d fc4type %x priority %x %s.\n",
1291 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24,
1292 fcport->login_retry, fcport->fc4_type, vha->hw->fc4_type_priority,
1293 NVME_TARGET(vha->hw, fcport) ? "nvme" : "fcp");
1295 rval = qla2x00_start_sp(sp);
1296 if (rval != QLA_SUCCESS) {
1297 fcport->flags |= FCF_LOGIN_NEEDED;
1298 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1306 fcport->flags &= ~FCF_ASYNC_SENT;
1310 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1312 struct qla_work_evt *e;
1314 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
1316 return QLA_FUNCTION_FAILED;
1318 e->u.fcport.fcport = fcport;
1319 e->u.fcport.opt = opt;
1320 fcport->flags |= FCF_ASYNC_ACTIVE;
1321 return qla2x00_post_work(vha, e);
1324 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1327 struct srb_iocb *mbx;
1328 int rval = QLA_FUNCTION_FAILED;
1331 struct port_database_24xx *pd;
1332 struct qla_hw_data *ha = vha->hw;
1334 if (IS_SESSION_DELETED(fcport)) {
1335 ql_log(ql_log_warn, vha, 0xffff,
1336 "%s: %8phC is being delete - not sending command.\n",
1337 __func__, fcport->port_name);
1338 fcport->flags &= ~FCF_ASYNC_ACTIVE;
1342 if (!vha->flags.online || fcport->flags & FCF_ASYNC_SENT) {
1343 ql_log(ql_log_warn, vha, 0xffff,
1344 "%s: %8phC online %d flags %x - not sending command.\n",
1345 __func__, fcport->port_name, vha->flags.online, fcport->flags);
1349 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1353 qla2x00_set_fcport_disc_state(fcport, DSC_GPDB);
1355 fcport->flags |= FCF_ASYNC_SENT;
1356 sp->type = SRB_MB_IOCB;
1358 sp->gen1 = fcport->rscn_gen;
1359 sp->gen2 = fcport->login_gen;
1361 mbx = &sp->u.iocb_cmd;
1362 mbx->timeout = qla2x00_async_iocb_timeout;
1363 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1365 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1367 ql_log(ql_log_warn, vha, 0xd043,
1368 "Failed to allocate port database structure.\n");
1372 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1373 mb[0] = MBC_GET_PORT_DATABASE;
1374 mb[1] = fcport->loop_id;
1375 mb[2] = MSW(pd_dma);
1376 mb[3] = LSW(pd_dma);
1377 mb[6] = MSW(MSD(pd_dma));
1378 mb[7] = LSW(MSD(pd_dma));
1379 mb[9] = vha->vp_idx;
1383 mbx->u.mbx.in_dma = pd_dma;
1385 sp->done = qla24xx_async_gpdb_sp_done;
1387 ql_dbg(ql_dbg_disc, vha, 0x20dc,
1388 "Async-%s %8phC hndl %x opt %x\n",
1389 sp->name, fcport->port_name, sp->handle, opt);
1391 rval = qla2x00_start_sp(sp);
1392 if (rval != QLA_SUCCESS)
1398 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1401 fcport->flags &= ~FCF_ASYNC_SENT;
1403 fcport->flags &= ~FCF_ASYNC_ACTIVE;
1404 qla24xx_post_gpdb_work(vha, fcport, opt);
1409 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1411 unsigned long flags;
1413 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1414 ea->fcport->login_gen++;
1415 ea->fcport->logout_on_delete = 1;
1417 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1418 vha->fcport_count++;
1419 ea->fcport->login_succ = 1;
1421 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1422 qla24xx_sched_upd_fcport(ea->fcport);
1423 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1424 } else if (ea->fcport->login_succ) {
1426 * We have an existing session. A late RSCN delivery
1427 * must have triggered the session to be re-validate.
1428 * Session is still valid.
1430 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1431 "%s %d %8phC session revalidate success\n",
1432 __func__, __LINE__, ea->fcport->port_name);
1433 qla2x00_set_fcport_disc_state(ea->fcport, DSC_LOGIN_COMPLETE);
1435 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1439 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1441 fc_port_t *fcport = ea->fcport;
1442 struct port_database_24xx *pd;
1443 struct srb *sp = ea->sp;
1446 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1448 fcport->flags &= ~FCF_ASYNC_SENT;
1450 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1451 "%s %8phC DS %d LS %d fc4_type %x rc %d\n", __func__,
1452 fcport->port_name, fcport->disc_state, pd->current_login_state,
1453 fcport->fc4_type, ea->rc);
1455 if (fcport->disc_state == DSC_DELETE_PEND)
1458 if (NVME_TARGET(vha->hw, fcport))
1459 ls = pd->current_login_state >> 4;
1461 ls = pd->current_login_state & 0xf;
1463 if (ea->sp->gen2 != fcport->login_gen) {
1464 /* target side must have changed it. */
1466 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1467 "%s %8phC generation changed\n",
1468 __func__, fcport->port_name);
1470 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1471 qla_rscn_replay(fcport);
1472 qlt_schedule_sess_for_deletion(fcport);
1477 case PDS_PRLI_COMPLETE:
1478 __qla24xx_parse_gpdb(vha, fcport, pd);
1480 case PDS_PLOGI_PENDING:
1481 case PDS_PLOGI_COMPLETE:
1482 case PDS_PRLI_PENDING:
1483 case PDS_PRLI2_PENDING:
1484 /* Set discovery state back to GNL to Relogin attempt */
1485 if (qla_dual_mode_enabled(vha) ||
1486 qla_ini_mode_enabled(vha)) {
1487 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
1488 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1491 case PDS_LOGO_PENDING:
1492 case PDS_PORT_UNAVAILABLE:
1494 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1495 __func__, __LINE__, fcport->port_name);
1496 qlt_schedule_sess_for_deletion(fcport);
1499 __qla24xx_handle_gpdb_event(vha, ea);
1502 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1507 ql_dbg(ql_dbg_disc, vha, 0x307b,
1508 "%s %8phC DS %d LS %d lid %d retries=%d\n",
1509 __func__, fcport->port_name, fcport->disc_state,
1510 fcport->fw_login_state, fcport->loop_id, fcport->login_retry);
1512 if (qla_tgt_mode_enabled(vha))
1515 if (qla_dual_mode_enabled(vha)) {
1516 if (N2N_TOPO(vha->hw)) {
1519 mywwn = wwn_to_u64(vha->port_name);
1520 wwn = wwn_to_u64(fcport->port_name);
1523 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1524 && time_after_eq(jiffies,
1525 fcport->plogi_nack_done_deadline))
1531 /* initiator mode */
1535 if (login && fcport->login_retry) {
1536 fcport->login_retry--;
1537 if (fcport->loop_id == FC_NO_LOOP_ID) {
1538 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1539 rc = qla2x00_find_new_loop_id(vha, fcport);
1541 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1542 "%s %d %8phC post del sess - out of loopid\n",
1543 __func__, __LINE__, fcport->port_name);
1544 fcport->scan_state = 0;
1545 qlt_schedule_sess_for_deletion(fcport);
1549 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1550 "%s %d %8phC post login\n",
1551 __func__, __LINE__, fcport->port_name);
1552 qla2x00_post_async_login_work(vha, fcport, NULL);
1556 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1562 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1563 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d\n",
1564 __func__, fcport->port_name, fcport->disc_state,
1565 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1566 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1567 fcport->login_gen, fcport->loop_id, fcport->scan_state);
1569 if (fcport->scan_state != QLA_FCPORT_FOUND ||
1570 fcport->disc_state == DSC_DELETE_PEND)
1573 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1574 qla_dual_mode_enabled(vha) &&
1575 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1576 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1579 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP &&
1580 !N2N_TOPO(vha->hw)) {
1581 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1582 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1587 /* Target won't initiate port login if fabric is present */
1588 if (vha->host->active_mode == MODE_TARGET && !N2N_TOPO(vha->hw))
1591 if (fcport->flags & (FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE)) {
1592 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1596 switch (fcport->disc_state) {
1598 wwn = wwn_to_u64(fcport->node_name);
1599 switch (vha->hw->current_topology) {
1601 if (fcport_is_smaller(fcport)) {
1602 /* this adapter is bigger */
1603 if (fcport->login_retry) {
1604 if (fcport->loop_id == FC_NO_LOOP_ID) {
1605 qla2x00_find_new_loop_id(vha,
1607 fcport->fw_login_state =
1608 DSC_LS_PORT_UNAVAIL;
1610 fcport->login_retry--;
1611 qla_post_els_plogi_work(vha, fcport);
1613 ql_log(ql_log_info, vha, 0x705d,
1614 "Unable to reach remote port %8phC",
1618 qla24xx_post_gnl_work(vha, fcport);
1623 ql_dbg(ql_dbg_disc, vha, 0xffff,
1624 "%s %d %8phC post GNNID\n",
1625 __func__, __LINE__, fcport->port_name);
1626 qla24xx_post_gnnid_work(vha, fcport);
1627 } else if (fcport->loop_id == FC_NO_LOOP_ID) {
1628 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1629 "%s %d %8phC post gnl\n",
1630 __func__, __LINE__, fcport->port_name);
1631 qla24xx_post_gnl_work(vha, fcport);
1633 qla_chk_n2n_b4_login(vha, fcport);
1640 switch (vha->hw->current_topology) {
1642 if ((fcport->current_login_state & 0xf) == 0x6) {
1643 ql_dbg(ql_dbg_disc, vha, 0x2118,
1644 "%s %d %8phC post GPDB work\n",
1645 __func__, __LINE__, fcport->port_name);
1646 fcport->chip_reset =
1647 vha->hw->base_qpair->chip_reset;
1648 qla24xx_post_gpdb_work(vha, fcport, 0);
1650 ql_dbg(ql_dbg_disc, vha, 0x2118,
1651 "%s %d %8phC post %s PRLI\n",
1652 __func__, __LINE__, fcport->port_name,
1653 NVME_TARGET(vha->hw, fcport) ? "NVME" :
1655 qla24xx_post_prli_work(vha, fcport);
1659 if (fcport->login_pause) {
1660 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1661 "%s %d %8phC exit\n",
1664 fcport->last_rscn_gen = fcport->rscn_gen;
1665 fcport->last_login_gen = fcport->login_gen;
1666 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1669 qla_chk_n2n_b4_login(vha, fcport);
1674 case DSC_LOGIN_FAILED:
1675 if (N2N_TOPO(vha->hw))
1676 qla_chk_n2n_b4_login(vha, fcport);
1678 qlt_schedule_sess_for_deletion(fcport);
1681 case DSC_LOGIN_COMPLETE:
1682 /* recheck login state */
1683 data[0] = data[1] = 0;
1684 qla2x00_post_async_adisc_work(vha, fcport, data);
1687 case DSC_LOGIN_PEND:
1688 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1689 qla24xx_post_prli_work(vha, fcport);
1692 case DSC_UPD_FCPORT:
1693 sec = jiffies_to_msecs(jiffies -
1694 fcport->jiffies_at_registration)/1000;
1695 if (fcport->sec_since_registration < sec && sec &&
1697 fcport->sec_since_registration = sec;
1698 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
1699 "%s %8phC - Slow Rport registration(%d Sec)\n",
1700 __func__, fcport->port_name, sec);
1703 if (fcport->next_disc_state != DSC_DELETE_PEND)
1704 fcport->next_disc_state = DSC_ADISC;
1705 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1715 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1716 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1718 struct qla_work_evt *e;
1720 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1722 return QLA_FUNCTION_FAILED;
1724 e->u.new_sess.id = *id;
1725 e->u.new_sess.pla = pla;
1726 e->u.new_sess.fc4_type = fc4_type;
1727 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1729 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1731 return qla2x00_post_work(vha, e);
1734 void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
1737 unsigned long flags;
1739 switch (ea->id.b.rsvd_1) {
1740 case RSCN_PORT_ADDR:
1741 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1743 if (fcport->flags & FCF_FCP2_DEVICE &&
1744 atomic_read(&fcport->state) == FCS_ONLINE) {
1745 ql_dbg(ql_dbg_disc, vha, 0x2115,
1746 "Delaying session delete for FCP2 portid=%06x %8phC ",
1747 fcport->d_id.b24, fcport->port_name);
1750 fcport->scan_needed = 1;
1754 case RSCN_AREA_ADDR:
1755 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1756 if (fcport->flags & FCF_FCP2_DEVICE &&
1757 atomic_read(&fcport->state) == FCS_ONLINE)
1760 if ((ea->id.b24 & 0xffff00) == (fcport->d_id.b24 & 0xffff00)) {
1761 fcport->scan_needed = 1;
1767 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1768 if (fcport->flags & FCF_FCP2_DEVICE &&
1769 atomic_read(&fcport->state) == FCS_ONLINE)
1772 if ((ea->id.b24 & 0xff0000) == (fcport->d_id.b24 & 0xff0000)) {
1773 fcport->scan_needed = 1;
1780 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1781 if (fcport->flags & FCF_FCP2_DEVICE &&
1782 atomic_read(&fcport->state) == FCS_ONLINE)
1785 fcport->scan_needed = 1;
1791 spin_lock_irqsave(&vha->work_lock, flags);
1792 if (vha->scan.scan_flags == 0) {
1793 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s: schedule\n", __func__);
1794 vha->scan.scan_flags |= SF_QUEUED;
1795 schedule_delayed_work(&vha->scan.scan_work, 5);
1797 spin_unlock_irqrestore(&vha->work_lock, flags);
1800 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1801 struct event_arg *ea)
1803 fc_port_t *fcport = ea->fcport;
1805 if (test_bit(UNLOADING, &vha->dpc_flags))
1808 ql_dbg(ql_dbg_disc, vha, 0x2102,
1809 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1810 __func__, fcport->port_name, fcport->disc_state,
1811 fcport->fw_login_state, fcport->login_pause,
1812 fcport->deleted, fcport->conflict,
1813 fcport->last_rscn_gen, fcport->rscn_gen,
1814 fcport->last_login_gen, fcport->login_gen,
1817 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1818 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gnl\n",
1819 __func__, __LINE__, fcport->port_name);
1820 qla24xx_post_gnl_work(vha, fcport);
1824 qla24xx_fcport_handle_login(vha, fcport);
1827 void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
1828 struct event_arg *ea)
1830 /* for pure Target Mode, PRLI will not be initiated */
1831 if (vha->host->active_mode == MODE_TARGET)
1834 ql_dbg(ql_dbg_disc, vha, 0x2118,
1835 "%s %d %8phC post PRLI\n",
1836 __func__, __LINE__, ea->fcport->port_name);
1837 qla24xx_post_prli_work(vha, ea->fcport);
1841 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1842 * to be consumed by the fcport
1844 void qla_rscn_replay(fc_port_t *fcport)
1846 struct event_arg ea;
1848 switch (fcport->disc_state) {
1849 case DSC_DELETE_PEND:
1855 if (fcport->scan_needed) {
1856 memset(&ea, 0, sizeof(ea));
1857 ea.id = fcport->d_id;
1858 ea.id.b.rsvd_1 = RSCN_PORT_ADDR;
1859 qla2x00_handle_rscn(fcport->vha, &ea);
1864 qla2x00_tmf_iocb_timeout(void *data)
1867 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1869 unsigned long flags;
1871 rc = qla24xx_async_abort_cmd(sp, false);
1873 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
1874 for (h = 1; h < sp->qpair->req->num_outstanding_cmds; h++) {
1875 if (sp->qpair->req->outstanding_cmds[h] == sp) {
1876 sp->qpair->req->outstanding_cmds[h] = NULL;
1880 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
1881 tmf->u.tmf.comp_status = cpu_to_le16(CS_TIMEOUT);
1882 tmf->u.tmf.data = QLA_FUNCTION_FAILED;
1883 complete(&tmf->u.tmf.comp);
1887 static void qla2x00_tmf_sp_done(srb_t *sp, int res)
1889 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1891 complete(&tmf->u.tmf.comp);
1895 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
1898 struct scsi_qla_host *vha = fcport->vha;
1899 struct srb_iocb *tm_iocb;
1901 int rval = QLA_FUNCTION_FAILED;
1903 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1907 tm_iocb = &sp->u.iocb_cmd;
1908 sp->type = SRB_TM_CMD;
1911 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1912 init_completion(&tm_iocb->u.tmf.comp);
1913 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1915 tm_iocb->u.tmf.flags = flags;
1916 tm_iocb->u.tmf.lun = lun;
1917 tm_iocb->u.tmf.data = tag;
1918 sp->done = qla2x00_tmf_sp_done;
1920 ql_dbg(ql_dbg_taskm, vha, 0x802f,
1921 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1922 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1923 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1925 rval = qla2x00_start_sp(sp);
1926 if (rval != QLA_SUCCESS)
1928 wait_for_completion(&tm_iocb->u.tmf.comp);
1930 rval = tm_iocb->u.tmf.data;
1932 if (rval != QLA_SUCCESS) {
1933 ql_log(ql_log_warn, vha, 0x8030,
1934 "TM IOCB failed (%x).\n", rval);
1937 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1938 flags = tm_iocb->u.tmf.flags;
1939 lun = (uint16_t)tm_iocb->u.tmf.lun;
1941 /* Issue Marker IOCB */
1942 qla2x00_marker(vha, vha->hw->base_qpair,
1943 fcport->loop_id, lun,
1944 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1949 fcport->flags &= ~FCF_ASYNC_SENT;
1955 qla24xx_async_abort_command(srb_t *sp)
1957 unsigned long flags = 0;
1960 fc_port_t *fcport = sp->fcport;
1961 struct qla_qpair *qpair = sp->qpair;
1962 struct scsi_qla_host *vha = fcport->vha;
1963 struct req_que *req = qpair->req;
1965 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1966 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1967 if (req->outstanding_cmds[handle] == sp)
1970 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1972 if (handle == req->num_outstanding_cmds) {
1973 /* Command not found. */
1974 return QLA_FUNCTION_FAILED;
1976 if (sp->type == SRB_FXIOCB_DCMD)
1977 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1978 FXDISC_ABORT_IOCTL);
1980 return qla24xx_async_abort_cmd(sp, true);
1984 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1986 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
1989 switch (ea->data[0]) {
1990 case MBS_COMMAND_COMPLETE:
1991 ql_dbg(ql_dbg_disc, vha, 0x2118,
1992 "%s %d %8phC post gpdb\n",
1993 __func__, __LINE__, ea->fcport->port_name);
1995 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1996 ea->fcport->logout_on_delete = 1;
1997 ea->fcport->nvme_prli_service_param = ea->iop[0];
1998 if (ea->iop[0] & NVME_PRLI_SP_FIRST_BURST)
1999 ea->fcport->nvme_first_burst_size =
2000 (ea->iop[1] & 0xffff) * 512;
2002 ea->fcport->nvme_first_burst_size = 0;
2003 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2006 if ((ea->iop[0] == LSC_SCODE_ELS_REJECT) &&
2007 (ea->iop[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
2008 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2009 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
2013 ql_dbg(ql_dbg_disc, vha, 0x2118,
2014 "%s %d %8phC priority %s, fc4type %x\n",
2015 __func__, __LINE__, ea->fcport->port_name,
2016 vha->hw->fc4_type_priority == FC4_PRIORITY_FCP ?
2017 "FCP" : "NVMe", ea->fcport->fc4_type);
2019 if (N2N_TOPO(vha->hw)) {
2020 if (vha->hw->fc4_type_priority == FC4_PRIORITY_NVME) {
2021 ea->fcport->fc4_type &= ~FS_FC4TYPE_NVME;
2022 ea->fcport->fc4_type |= FS_FC4TYPE_FCP;
2024 ea->fcport->fc4_type &= ~FS_FC4TYPE_FCP;
2025 ea->fcport->fc4_type |= FS_FC4TYPE_NVME;
2028 if (ea->fcport->n2n_link_reset_cnt < 3) {
2029 ea->fcport->n2n_link_reset_cnt++;
2030 vha->relogin_jif = jiffies + 2 * HZ;
2032 * PRLI failed. Reset link to kick start
2035 set_bit(N2N_LINK_RESET, &vha->dpc_flags);
2037 ql_log(ql_log_warn, vha, 0x2119,
2038 "%s %d %8phC Unable to reconnect\n",
2040 ea->fcport->port_name);
2044 * switch connect. login failed. Take connection down
2045 * and allow relogin to retrigger
2047 if (NVME_FCP_TARGET(ea->fcport)) {
2048 ql_dbg(ql_dbg_disc, vha, 0x2118,
2049 "%s %d %8phC post %s prli\n",
2051 ea->fcport->port_name,
2052 (ea->fcport->fc4_type & FS_FC4TYPE_NVME)
2054 if (vha->hw->fc4_type_priority == FC4_PRIORITY_NVME)
2055 ea->fcport->fc4_type &= ~FS_FC4TYPE_NVME;
2057 ea->fcport->fc4_type &= ~FS_FC4TYPE_FCP;
2060 ea->fcport->flags &= ~FCF_ASYNC_SENT;
2061 ea->fcport->keep_nport_handle = 0;
2062 ea->fcport->logout_on_delete = 1;
2063 qlt_schedule_sess_for_deletion(ea->fcport);
2070 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
2072 port_id_t cid; /* conflict Nport id */
2074 struct fc_port *conflict_fcport;
2075 unsigned long flags;
2076 struct fc_port *fcport = ea->fcport;
2078 ql_dbg(ql_dbg_disc, vha, 0xffff,
2079 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
2080 __func__, fcport->port_name, fcport->disc_state,
2081 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
2082 ea->sp->gen1, fcport->rscn_gen,
2083 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
2085 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
2086 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
2087 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2088 "%s %d %8phC Remote is trying to login\n",
2089 __func__, __LINE__, fcport->port_name);
2093 if ((fcport->disc_state == DSC_DELETE_PEND) ||
2094 (fcport->disc_state == DSC_DELETED)) {
2095 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2099 if (ea->sp->gen2 != fcport->login_gen) {
2100 /* target side must have changed it. */
2101 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2102 "%s %8phC generation changed\n",
2103 __func__, fcport->port_name);
2104 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2106 } else if (ea->sp->gen1 != fcport->rscn_gen) {
2107 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2108 "%s %8phC RSCN generation changed\n",
2109 __func__, fcport->port_name);
2110 qla_rscn_replay(fcport);
2111 qlt_schedule_sess_for_deletion(fcport);
2115 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
2118 switch (ea->data[0]) {
2119 case MBS_COMMAND_COMPLETE:
2121 * Driver must validate login state - If PRLI not complete,
2122 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
2125 if (NVME_TARGET(vha->hw, ea->fcport)) {
2126 ql_dbg(ql_dbg_disc, vha, 0x2117,
2127 "%s %d %8phC post prli\n",
2128 __func__, __LINE__, ea->fcport->port_name);
2129 qla24xx_post_prli_work(vha, ea->fcport);
2131 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2132 "%s %d %8phC LoopID 0x%x in use with %06x. post gpdb\n",
2133 __func__, __LINE__, ea->fcport->port_name,
2134 ea->fcport->loop_id, ea->fcport->d_id.b24);
2136 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2137 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2138 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2139 ea->fcport->logout_on_delete = 1;
2140 ea->fcport->send_els_logo = 0;
2141 ea->fcport->fw_login_state = DSC_LS_PRLI_COMP;
2142 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2144 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2147 case MBS_COMMAND_ERROR:
2148 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
2149 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
2151 qlt_schedule_sess_for_deletion(ea->fcport);
2153 case MBS_LOOP_ID_USED:
2154 /* data[1] = IO PARAM 1 = nport ID */
2155 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
2156 cid.b.area = (ea->iop[1] >> 8) & 0xff;
2157 cid.b.al_pa = ea->iop[1] & 0xff;
2160 ql_dbg(ql_dbg_disc, vha, 0x20ec,
2161 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2162 __func__, __LINE__, ea->fcport->port_name,
2163 ea->fcport->loop_id, cid.b24);
2165 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2166 ea->fcport->loop_id = FC_NO_LOOP_ID;
2167 qla24xx_post_gnl_work(vha, ea->fcport);
2169 case MBS_PORT_ID_USED:
2170 lid = ea->iop[1] & 0xffff;
2171 qlt_find_sess_invalidate_other(vha,
2172 wwn_to_u64(ea->fcport->port_name),
2173 ea->fcport->d_id, lid, &conflict_fcport);
2175 if (conflict_fcport) {
2177 * Another fcport share the same loop_id/nport id.
2178 * Conflict fcport needs to finish cleanup before this
2179 * fcport can proceed to login.
2181 conflict_fcport->conflict = ea->fcport;
2182 ea->fcport->login_pause = 1;
2184 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2185 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
2186 __func__, __LINE__, ea->fcport->port_name,
2187 ea->fcport->d_id.b24, lid);
2189 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2190 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2191 __func__, __LINE__, ea->fcport->port_name,
2192 ea->fcport->d_id.b24, lid);
2194 qla2x00_clear_loop_id(ea->fcport);
2195 set_bit(lid, vha->hw->loop_id_map);
2196 ea->fcport->loop_id = lid;
2197 ea->fcport->keep_nport_handle = 0;
2198 ea->fcport->logout_on_delete = 1;
2199 qlt_schedule_sess_for_deletion(ea->fcport);
2206 /****************************************************************************/
2207 /* QLogic ISP2x00 Hardware Support Functions. */
2208 /****************************************************************************/
2211 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
2213 int rval = QLA_SUCCESS;
2214 struct qla_hw_data *ha = vha->hw;
2215 uint32_t idc_major_ver, idc_minor_ver;
2218 qla83xx_idc_lock(vha, 0);
2220 /* SV: TODO: Assign initialization timeout from
2221 * flash-info / other param
2223 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
2224 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
2226 /* Set our fcoe function presence */
2227 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
2228 ql_dbg(ql_dbg_p3p, vha, 0xb077,
2229 "Error while setting DRV-Presence.\n");
2230 rval = QLA_FUNCTION_FAILED;
2234 /* Decide the reset ownership */
2235 qla83xx_reset_ownership(vha);
2238 * On first protocol driver load:
2239 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2241 * Others: Check compatibility with current IDC Major version.
2243 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
2244 if (ha->flags.nic_core_reset_owner) {
2245 /* Set IDC Major version */
2246 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
2247 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
2249 /* Clearing IDC-Lock-Recovery register */
2250 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
2251 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
2253 * Clear further IDC participation if we are not compatible with
2254 * the current IDC Major Version.
2256 ql_log(ql_log_warn, vha, 0xb07d,
2257 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2258 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
2259 __qla83xx_clear_drv_presence(vha);
2260 rval = QLA_FUNCTION_FAILED;
2263 /* Each function sets its supported Minor version. */
2264 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
2265 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
2266 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
2268 if (ha->flags.nic_core_reset_owner) {
2269 memset(config, 0, sizeof(config));
2270 if (!qla81xx_get_port_config(vha, config))
2271 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
2275 rval = qla83xx_idc_state_handler(vha);
2278 qla83xx_idc_unlock(vha, 0);
2283 static void qla_enable_fce_trace(scsi_qla_host_t *vha)
2286 struct qla_hw_data *ha = vha->hw;
2289 ha->flags.fce_enabled = 1;
2290 memset(ha->fce, 0, fce_calc_size(ha->fce_bufs));
2291 rval = qla2x00_enable_fce_trace(vha,
2292 ha->fce_dma, ha->fce_bufs, ha->fce_mb, &ha->fce_bufs);
2295 ql_log(ql_log_warn, vha, 0x8033,
2296 "Unable to reinitialize FCE (%d).\n", rval);
2297 ha->flags.fce_enabled = 0;
2302 static void qla_enable_eft_trace(scsi_qla_host_t *vha)
2305 struct qla_hw_data *ha = vha->hw;
2308 memset(ha->eft, 0, EFT_SIZE);
2309 rval = qla2x00_enable_eft_trace(vha, ha->eft_dma, EFT_NUM_BUFFERS);
2312 ql_log(ql_log_warn, vha, 0x8034,
2313 "Unable to reinitialize EFT (%d).\n", rval);
2318 * qla2x00_initialize_adapter
2322 * ha = adapter block pointer.
2328 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
2331 struct qla_hw_data *ha = vha->hw;
2332 struct req_que *req = ha->req_q_map[0];
2333 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2335 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2336 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2338 /* Clear adapter flags. */
2339 vha->flags.online = 0;
2340 ha->flags.chip_reset_done = 0;
2341 vha->flags.reset_active = 0;
2342 ha->flags.pci_channel_io_perm_failure = 0;
2343 ha->flags.eeh_busy = 0;
2344 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2345 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
2346 atomic_set(&vha->loop_state, LOOP_DOWN);
2347 vha->device_flags = DFLG_NO_CABLE;
2349 vha->flags.management_server_logged_in = 0;
2350 vha->marker_needed = 0;
2351 ha->isp_abort_cnt = 0;
2352 ha->beacon_blink_led = 0;
2354 set_bit(0, ha->req_qid_map);
2355 set_bit(0, ha->rsp_qid_map);
2357 ql_dbg(ql_dbg_init, vha, 0x0040,
2358 "Configuring PCI space...\n");
2359 rval = ha->isp_ops->pci_config(vha);
2361 ql_log(ql_log_warn, vha, 0x0044,
2362 "Unable to configure PCI space.\n");
2366 ha->isp_ops->reset_chip(vha);
2368 /* Check for secure flash support */
2369 if (IS_QLA28XX(ha)) {
2370 if (rd_reg_word(®->mailbox12) & BIT_0)
2371 ha->flags.secure_adapter = 1;
2372 ql_log(ql_log_info, vha, 0xffff, "Secure Adapter: %s\n",
2373 (ha->flags.secure_adapter) ? "Yes" : "No");
2377 rval = qla2xxx_get_flash_info(vha);
2379 ql_log(ql_log_fatal, vha, 0x004f,
2380 "Unable to validate FLASH data.\n");
2384 if (IS_QLA8044(ha)) {
2385 qla8044_read_reset_template(vha);
2387 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2388 * If DONRESET_BIT0 is set, drivers should not set dev_state
2389 * to NEED_RESET. But if NEED_RESET is set, drivers should
2390 * should honor the reset. */
2391 if (ql2xdontresethba == 1)
2392 qla8044_set_idc_dontreset(vha);
2395 ha->isp_ops->get_flash_version(vha, req->ring);
2396 ql_dbg(ql_dbg_init, vha, 0x0061,
2397 "Configure NVRAM parameters...\n");
2399 /* Let priority default to FCP, can be overridden by nvram_config */
2400 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2402 ha->isp_ops->nvram_config(vha);
2404 if (ha->fc4_type_priority != FC4_PRIORITY_FCP &&
2405 ha->fc4_type_priority != FC4_PRIORITY_NVME)
2406 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2408 ql_log(ql_log_info, vha, 0xffff, "FC4 priority set to %s\n",
2409 ha->fc4_type_priority == FC4_PRIORITY_FCP ? "FCP" : "NVMe");
2411 if (ha->flags.disable_serdes) {
2412 /* Mask HBA via NVRAM settings? */
2413 ql_log(ql_log_info, vha, 0x0077,
2414 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
2415 return QLA_FUNCTION_FAILED;
2418 ql_dbg(ql_dbg_init, vha, 0x0078,
2419 "Verifying loaded RISC code...\n");
2421 /* If smartsan enabled then require fdmi and rdp enabled */
2427 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
2428 rval = ha->isp_ops->chip_diag(vha);
2431 rval = qla2x00_setup_chip(vha);
2436 if (IS_QLA84XX(ha)) {
2437 ha->cs84xx = qla84xx_get_chip(vha);
2439 ql_log(ql_log_warn, vha, 0x00d0,
2440 "Unable to configure ISP84XX.\n");
2441 return QLA_FUNCTION_FAILED;
2445 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2446 rval = qla2x00_init_rings(vha);
2448 /* No point in continuing if firmware initialization failed. */
2449 if (rval != QLA_SUCCESS)
2452 ha->flags.chip_reset_done = 1;
2454 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2455 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2456 rval = qla84xx_init_chip(vha);
2457 if (rval != QLA_SUCCESS) {
2458 ql_log(ql_log_warn, vha, 0x00d4,
2459 "Unable to initialize ISP84XX.\n");
2460 qla84xx_put_chip(vha);
2464 /* Load the NIC Core f/w if we are the first protocol driver. */
2465 if (IS_QLA8031(ha)) {
2466 rval = qla83xx_nic_core_fw_load(vha);
2468 ql_log(ql_log_warn, vha, 0x0124,
2469 "Error in initializing NIC Core f/w.\n");
2472 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2473 qla24xx_read_fcp_prio_cfg(vha);
2475 if (IS_P3P_TYPE(ha))
2476 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2478 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2484 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2487 * Returns 0 on success.
2490 qla2100_pci_config(scsi_qla_host_t *vha)
2493 unsigned long flags;
2494 struct qla_hw_data *ha = vha->hw;
2495 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2497 pci_set_master(ha->pdev);
2498 pci_try_set_mwi(ha->pdev);
2500 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2501 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2502 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2504 pci_disable_rom(ha->pdev);
2506 /* Get PCI bus information. */
2507 spin_lock_irqsave(&ha->hardware_lock, flags);
2508 ha->pci_attr = rd_reg_word(®->ctrl_status);
2509 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2515 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2518 * Returns 0 on success.
2521 qla2300_pci_config(scsi_qla_host_t *vha)
2524 unsigned long flags = 0;
2526 struct qla_hw_data *ha = vha->hw;
2527 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2529 pci_set_master(ha->pdev);
2530 pci_try_set_mwi(ha->pdev);
2532 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2533 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2535 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2536 w &= ~PCI_COMMAND_INTX_DISABLE;
2537 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2540 * If this is a 2300 card and not 2312, reset the
2541 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2542 * the 2310 also reports itself as a 2300 so we need to get the
2543 * fb revision level -- a 6 indicates it really is a 2300 and
2546 if (IS_QLA2300(ha)) {
2547 spin_lock_irqsave(&ha->hardware_lock, flags);
2550 wrt_reg_word(®->hccr, HCCR_PAUSE_RISC);
2551 for (cnt = 0; cnt < 30000; cnt++) {
2552 if ((rd_reg_word(®->hccr) & HCCR_RISC_PAUSE) != 0)
2558 /* Select FPM registers. */
2559 wrt_reg_word(®->ctrl_status, 0x20);
2560 rd_reg_word(®->ctrl_status);
2562 /* Get the fb rev level */
2563 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2565 if (ha->fb_rev == FPM_2300)
2566 pci_clear_mwi(ha->pdev);
2568 /* Deselect FPM registers. */
2569 wrt_reg_word(®->ctrl_status, 0x0);
2570 rd_reg_word(®->ctrl_status);
2572 /* Release RISC module. */
2573 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
2574 for (cnt = 0; cnt < 30000; cnt++) {
2575 if ((rd_reg_word(®->hccr) & HCCR_RISC_PAUSE) == 0)
2581 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2584 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2586 pci_disable_rom(ha->pdev);
2588 /* Get PCI bus information. */
2589 spin_lock_irqsave(&ha->hardware_lock, flags);
2590 ha->pci_attr = rd_reg_word(®->ctrl_status);
2591 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2597 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2600 * Returns 0 on success.
2603 qla24xx_pci_config(scsi_qla_host_t *vha)
2606 unsigned long flags = 0;
2607 struct qla_hw_data *ha = vha->hw;
2608 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2610 pci_set_master(ha->pdev);
2611 pci_try_set_mwi(ha->pdev);
2613 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2614 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2615 w &= ~PCI_COMMAND_INTX_DISABLE;
2616 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2618 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2620 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2621 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2622 pcix_set_mmrbc(ha->pdev, 2048);
2624 /* PCIe -- adjust Maximum Read Request Size (2048). */
2625 if (pci_is_pcie(ha->pdev))
2626 pcie_set_readrq(ha->pdev, 4096);
2628 pci_disable_rom(ha->pdev);
2630 ha->chip_revision = ha->pdev->revision;
2632 /* Get PCI bus information. */
2633 spin_lock_irqsave(&ha->hardware_lock, flags);
2634 ha->pci_attr = rd_reg_dword(®->ctrl_status);
2635 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2641 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2644 * Returns 0 on success.
2647 qla25xx_pci_config(scsi_qla_host_t *vha)
2650 struct qla_hw_data *ha = vha->hw;
2652 pci_set_master(ha->pdev);
2653 pci_try_set_mwi(ha->pdev);
2655 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2656 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2657 w &= ~PCI_COMMAND_INTX_DISABLE;
2658 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2660 /* PCIe -- adjust Maximum Read Request Size (2048). */
2661 if (pci_is_pcie(ha->pdev))
2662 pcie_set_readrq(ha->pdev, 4096);
2664 pci_disable_rom(ha->pdev);
2666 ha->chip_revision = ha->pdev->revision;
2672 * qla2x00_isp_firmware() - Choose firmware image.
2675 * Returns 0 on success.
2678 qla2x00_isp_firmware(scsi_qla_host_t *vha)
2681 uint16_t loop_id, topo, sw_cap;
2682 uint8_t domain, area, al_pa;
2683 struct qla_hw_data *ha = vha->hw;
2685 /* Assume loading risc code */
2686 rval = QLA_FUNCTION_FAILED;
2688 if (ha->flags.disable_risc_code_load) {
2689 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
2691 /* Verify checksum of loaded RISC code. */
2692 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
2693 if (rval == QLA_SUCCESS) {
2694 /* And, verify we are not in ROM code. */
2695 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2696 &area, &domain, &topo, &sw_cap);
2701 ql_dbg(ql_dbg_init, vha, 0x007a,
2702 "**** Load RISC code ****.\n");
2708 * qla2x00_reset_chip() - Reset ISP chip.
2711 * Returns 0 on success.
2714 qla2x00_reset_chip(scsi_qla_host_t *vha)
2716 unsigned long flags = 0;
2717 struct qla_hw_data *ha = vha->hw;
2718 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2721 int rval = QLA_FUNCTION_FAILED;
2723 if (unlikely(pci_channel_offline(ha->pdev)))
2726 ha->isp_ops->disable_intrs(ha);
2728 spin_lock_irqsave(&ha->hardware_lock, flags);
2730 /* Turn off master enable */
2732 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2733 cmd &= ~PCI_COMMAND_MASTER;
2734 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2736 if (!IS_QLA2100(ha)) {
2738 wrt_reg_word(®->hccr, HCCR_PAUSE_RISC);
2739 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2740 for (cnt = 0; cnt < 30000; cnt++) {
2741 if ((rd_reg_word(®->hccr) &
2742 HCCR_RISC_PAUSE) != 0)
2747 rd_reg_word(®->hccr); /* PCI Posting. */
2751 /* Select FPM registers. */
2752 wrt_reg_word(®->ctrl_status, 0x20);
2753 rd_reg_word(®->ctrl_status); /* PCI Posting. */
2755 /* FPM Soft Reset. */
2756 wrt_reg_word(®->fpm_diag_config, 0x100);
2757 rd_reg_word(®->fpm_diag_config); /* PCI Posting. */
2759 /* Toggle Fpm Reset. */
2760 if (!IS_QLA2200(ha)) {
2761 wrt_reg_word(®->fpm_diag_config, 0x0);
2762 rd_reg_word(®->fpm_diag_config); /* PCI Posting. */
2765 /* Select frame buffer registers. */
2766 wrt_reg_word(®->ctrl_status, 0x10);
2767 rd_reg_word(®->ctrl_status); /* PCI Posting. */
2769 /* Reset frame buffer FIFOs. */
2770 if (IS_QLA2200(ha)) {
2771 WRT_FB_CMD_REG(ha, reg, 0xa000);
2772 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2774 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2776 /* Read back fb_cmd until zero or 3 seconds max */
2777 for (cnt = 0; cnt < 3000; cnt++) {
2778 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2784 /* Select RISC module registers. */
2785 wrt_reg_word(®->ctrl_status, 0);
2786 rd_reg_word(®->ctrl_status); /* PCI Posting. */
2788 /* Reset RISC processor. */
2789 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
2790 rd_reg_word(®->hccr); /* PCI Posting. */
2792 /* Release RISC processor. */
2793 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
2794 rd_reg_word(®->hccr); /* PCI Posting. */
2797 wrt_reg_word(®->hccr, HCCR_CLR_RISC_INT);
2798 wrt_reg_word(®->hccr, HCCR_CLR_HOST_INT);
2800 /* Reset ISP chip. */
2801 wrt_reg_word(®->ctrl_status, CSR_ISP_SOFT_RESET);
2803 /* Wait for RISC to recover from reset. */
2804 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2806 * It is necessary to for a delay here since the card doesn't
2807 * respond to PCI reads during a reset. On some architectures
2808 * this will result in an MCA.
2811 for (cnt = 30000; cnt; cnt--) {
2812 if ((rd_reg_word(®->ctrl_status) &
2813 CSR_ISP_SOFT_RESET) == 0)
2820 /* Reset RISC processor. */
2821 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
2823 wrt_reg_word(®->semaphore, 0);
2825 /* Release RISC processor. */
2826 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
2827 rd_reg_word(®->hccr); /* PCI Posting. */
2829 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2830 for (cnt = 0; cnt < 30000; cnt++) {
2831 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
2839 /* Turn on master enable */
2840 cmd |= PCI_COMMAND_MASTER;
2841 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2843 /* Disable RISC pause on FPM parity error. */
2844 if (!IS_QLA2100(ha)) {
2845 wrt_reg_word(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
2846 rd_reg_word(®->hccr); /* PCI Posting. */
2849 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2855 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2858 * Returns 0 on success.
2861 qla81xx_reset_mpi(scsi_qla_host_t *vha)
2863 uint16_t mb[4] = {0x1010, 0, 1, 0};
2865 if (!IS_QLA81XX(vha->hw))
2868 return qla81xx_write_mpi_register(vha, mb);
2872 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2875 * Returns 0 on success.
2878 qla24xx_reset_risc(scsi_qla_host_t *vha)
2880 unsigned long flags = 0;
2881 struct qla_hw_data *ha = vha->hw;
2882 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2885 static int abts_cnt; /* ISP abort retry counts */
2886 int rval = QLA_SUCCESS;
2888 spin_lock_irqsave(&ha->hardware_lock, flags);
2891 wrt_reg_dword(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2892 for (cnt = 0; cnt < 30000; cnt++) {
2893 if ((rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2899 if (!(rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE))
2900 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2902 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2903 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2904 rd_reg_dword(®->hccr),
2905 rd_reg_dword(®->ctrl_status),
2906 (rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE));
2908 wrt_reg_dword(®->ctrl_status,
2909 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2910 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
2914 /* Wait for firmware to complete NVRAM accesses. */
2915 rd_reg_word(®->mailbox0);
2916 for (cnt = 10000; rd_reg_word(®->mailbox0) != 0 &&
2917 rval == QLA_SUCCESS; cnt--) {
2922 rval = QLA_FUNCTION_TIMEOUT;
2925 if (rval == QLA_SUCCESS)
2926 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2928 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2929 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2930 rd_reg_dword(®->hccr),
2931 rd_reg_word(®->mailbox0));
2933 /* Wait for soft-reset to complete. */
2934 rd_reg_dword(®->ctrl_status);
2935 for (cnt = 0; cnt < 60; cnt++) {
2937 if ((rd_reg_dword(®->ctrl_status) &
2938 CSRX_ISP_SOFT_RESET) == 0)
2943 if (!(rd_reg_dword(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
2944 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2946 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2947 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2948 rd_reg_dword(®->hccr),
2949 rd_reg_dword(®->ctrl_status));
2951 /* If required, do an MPI FW reset now */
2952 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2953 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2954 if (++abts_cnt < 5) {
2955 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2956 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2959 * We exhausted the ISP abort retries. We have to
2960 * set the board offline.
2963 vha->flags.online = 0;
2968 wrt_reg_dword(®->hccr, HCCRX_SET_RISC_RESET);
2969 rd_reg_dword(®->hccr);
2971 wrt_reg_dword(®->hccr, HCCRX_REL_RISC_PAUSE);
2972 rd_reg_dword(®->hccr);
2974 wrt_reg_dword(®->hccr, HCCRX_CLR_RISC_RESET);
2975 rd_reg_dword(®->hccr);
2977 rd_reg_word(®->mailbox0);
2978 for (cnt = 60; rd_reg_word(®->mailbox0) != 0 &&
2979 rval == QLA_SUCCESS; cnt--) {
2984 rval = QLA_FUNCTION_TIMEOUT;
2986 if (rval == QLA_SUCCESS)
2987 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2989 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2990 "Host Risc 0x%x, mailbox0 0x%x\n",
2991 rd_reg_dword(®->hccr),
2992 rd_reg_word(®->mailbox0));
2994 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2996 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2997 "Driver in %s mode\n",
2998 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
3000 if (IS_NOPOLLING_TYPE(ha))
3001 ha->isp_ops->enable_intrs(ha);
3007 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
3009 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
3011 wrt_reg_dword(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
3012 *data = rd_reg_dword(®->iobase_window + RISC_REGISTER_WINDOW_OFFSET);
3016 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
3018 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
3020 wrt_reg_dword(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
3021 wrt_reg_dword(®->iobase_window + RISC_REGISTER_WINDOW_OFFSET, data);
3025 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
3028 uint delta_msec = 100;
3029 uint elapsed_msec = 0;
3033 if (vha->hw->pdev->subsystem_device != 0x0175 &&
3034 vha->hw->pdev->subsystem_device != 0x0240)
3037 wrt_reg_dword(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
3041 timeout_msec = TIMEOUT_SEMAPHORE;
3042 n = timeout_msec / delta_msec;
3044 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
3045 qla25xx_read_risc_sema_reg(vha, &wd32);
3046 if (wd32 & RISC_SEMAPHORE)
3049 elapsed_msec += delta_msec;
3050 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
3054 if (!(wd32 & RISC_SEMAPHORE))
3057 if (!(wd32 & RISC_SEMAPHORE_FORCE))
3060 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
3061 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
3062 n = timeout_msec / delta_msec;
3064 qla25xx_read_risc_sema_reg(vha, &wd32);
3065 if (!(wd32 & RISC_SEMAPHORE_FORCE))
3068 elapsed_msec += delta_msec;
3069 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
3073 if (wd32 & RISC_SEMAPHORE_FORCE)
3074 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
3079 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
3086 * qla24xx_reset_chip() - Reset ISP24xx chip.
3089 * Returns 0 on success.
3092 qla24xx_reset_chip(scsi_qla_host_t *vha)
3094 struct qla_hw_data *ha = vha->hw;
3095 int rval = QLA_FUNCTION_FAILED;
3097 if (pci_channel_offline(ha->pdev) &&
3098 ha->flags.pci_channel_io_perm_failure) {
3102 ha->isp_ops->disable_intrs(ha);
3104 qla25xx_manipulate_risc_semaphore(vha);
3106 /* Perform RISC reset. */
3107 rval = qla24xx_reset_risc(vha);
3113 * qla2x00_chip_diag() - Test chip for proper operation.
3116 * Returns 0 on success.
3119 qla2x00_chip_diag(scsi_qla_host_t *vha)
3122 struct qla_hw_data *ha = vha->hw;
3123 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3124 unsigned long flags = 0;
3128 struct req_que *req = ha->req_q_map[0];
3130 /* Assume a failed state */
3131 rval = QLA_FUNCTION_FAILED;
3133 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
3134 ®->flash_address);
3136 spin_lock_irqsave(&ha->hardware_lock, flags);
3138 /* Reset ISP chip. */
3139 wrt_reg_word(®->ctrl_status, CSR_ISP_SOFT_RESET);
3142 * We need to have a delay here since the card will not respond while
3143 * in reset causing an MCA on some architectures.
3146 data = qla2x00_debounce_register(®->ctrl_status);
3147 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
3149 data = rd_reg_word(®->ctrl_status);
3154 goto chip_diag_failed;
3156 ql_dbg(ql_dbg_init, vha, 0x007c,
3157 "Reset register cleared by chip reset.\n");
3159 /* Reset RISC processor. */
3160 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
3161 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
3163 /* Workaround for QLA2312 PCI parity error */
3164 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
3165 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
3166 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
3168 data = RD_MAILBOX_REG(ha, reg, 0);
3175 goto chip_diag_failed;
3177 /* Check product ID of chip */
3178 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
3180 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
3181 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
3182 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
3183 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
3184 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
3185 mb[3] != PROD_ID_3) {
3186 ql_log(ql_log_warn, vha, 0x0062,
3187 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
3188 mb[1], mb[2], mb[3]);
3190 goto chip_diag_failed;
3192 ha->product_id[0] = mb[1];
3193 ha->product_id[1] = mb[2];
3194 ha->product_id[2] = mb[3];
3195 ha->product_id[3] = mb[4];
3197 /* Adjust fw RISC transfer size */
3198 if (req->length > 1024)
3199 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
3201 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
3204 if (IS_QLA2200(ha) &&
3205 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
3206 /* Limit firmware transfer size with a 2200A */
3207 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
3209 ha->device_type |= DT_ISP2200A;
3210 ha->fw_transfer_size = 128;
3213 /* Wrap Incoming Mailboxes Test. */
3214 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3216 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
3217 rval = qla2x00_mbx_reg_test(vha);
3219 ql_log(ql_log_warn, vha, 0x0080,
3220 "Failed mailbox send register test.\n");
3222 /* Flag a successful rval */
3224 spin_lock_irqsave(&ha->hardware_lock, flags);
3228 ql_log(ql_log_info, vha, 0x0081,
3229 "Chip diagnostics **** FAILED ****.\n");
3231 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3237 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3240 * Returns 0 on success.
3243 qla24xx_chip_diag(scsi_qla_host_t *vha)
3246 struct qla_hw_data *ha = vha->hw;
3247 struct req_que *req = ha->req_q_map[0];
3249 if (IS_P3P_TYPE(ha))
3252 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
3254 rval = qla2x00_mbx_reg_test(vha);
3256 ql_log(ql_log_warn, vha, 0x0082,
3257 "Failed mailbox send register test.\n");
3259 /* Flag a successful rval */
3267 qla2x00_alloc_fce_trace(scsi_qla_host_t *vha)
3271 struct qla_hw_data *ha = vha->hw;
3273 if (!IS_FWI2_CAPABLE(ha))
3276 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3277 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3281 ql_dbg(ql_dbg_init, vha, 0x00bd,
3282 "%s: FCE Mem is already allocated.\n",
3287 /* Allocate memory for Fibre Channel Event Buffer. */
3288 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3291 ql_log(ql_log_warn, vha, 0x00be,
3292 "Unable to allocate (%d KB) for FCE.\n",
3297 ql_dbg(ql_dbg_init, vha, 0x00c0,
3298 "Allocated (%d KB) for FCE...\n", FCE_SIZE / 1024);
3300 ha->fce_dma = tc_dma;
3302 ha->fce_bufs = FCE_NUM_BUFFERS;
3306 qla2x00_alloc_eft_trace(scsi_qla_host_t *vha)
3310 struct qla_hw_data *ha = vha->hw;
3312 if (!IS_FWI2_CAPABLE(ha))
3316 ql_dbg(ql_dbg_init, vha, 0x00bd,
3317 "%s: EFT Mem is already allocated.\n",
3322 /* Allocate memory for Extended Trace Buffer. */
3323 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3326 ql_log(ql_log_warn, vha, 0x00c1,
3327 "Unable to allocate (%d KB) for EFT.\n",
3332 ql_dbg(ql_dbg_init, vha, 0x00c3,
3333 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3335 ha->eft_dma = tc_dma;
3340 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3342 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
3343 eft_size, fce_size, mq_size;
3344 struct qla_hw_data *ha = vha->hw;
3345 struct req_que *req = ha->req_q_map[0];
3346 struct rsp_que *rsp = ha->rsp_q_map[0];
3347 struct qla2xxx_fw_dump *fw_dump;
3350 ql_dbg(ql_dbg_init, vha, 0x00bd,
3351 "Firmware dump already allocated.\n");
3356 ha->fw_dump_cap_flags = 0;
3357 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
3358 req_q_size = rsp_q_size = 0;
3360 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3361 fixed_size = sizeof(struct qla2100_fw_dump);
3362 } else if (IS_QLA23XX(ha)) {
3363 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
3364 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
3366 } else if (IS_FWI2_CAPABLE(ha)) {
3368 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
3369 else if (IS_QLA81XX(ha))
3370 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
3371 else if (IS_QLA25XX(ha))
3372 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
3374 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
3376 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
3379 if (!IS_QLA83XX(ha))
3380 mq_size = sizeof(struct qla2xxx_mq_chain);
3382 * Allocate maximum buffer size for all queues - Q0.
3383 * Resizing must be done at end-of-dump processing.
3385 mq_size += (ha->max_req_queues - 1) *
3386 (req->length * sizeof(request_t));
3387 mq_size += (ha->max_rsp_queues - 1) *
3388 (rsp->length * sizeof(response_t));
3390 if (ha->tgt.atio_ring)
3391 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3393 qla2x00_alloc_fce_trace(vha);
3395 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3396 qla2x00_alloc_eft_trace(vha);
3398 eft_size = EFT_SIZE;
3401 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3402 struct fwdt *fwdt = ha->fwdt;
3405 for (j = 0; j < 2; j++, fwdt++) {
3406 if (!fwdt->template) {
3407 ql_dbg(ql_dbg_init, vha, 0x00ba,
3408 "-> fwdt%u no template\n", j);
3411 ql_dbg(ql_dbg_init, vha, 0x00fa,
3412 "-> fwdt%u calculating fwdump size...\n", j);
3413 fwdt->dump_size = qla27xx_fwdt_calculate_dump_size(
3414 vha, fwdt->template);
3415 ql_dbg(ql_dbg_init, vha, 0x00fa,
3416 "-> fwdt%u calculated fwdump size = %#lx bytes\n",
3417 j, fwdt->dump_size);
3418 dump_size += fwdt->dump_size;
3420 /* Add space for spare MPI fw dump. */
3421 dump_size += ha->fwdt[1].dump_size;
3423 req_q_size = req->length * sizeof(request_t);
3424 rsp_q_size = rsp->length * sizeof(response_t);
3425 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3426 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size
3428 ha->chain_offset = dump_size;
3429 dump_size += mq_size + fce_size;
3430 if (ha->exchoffld_buf)
3431 dump_size += sizeof(struct qla2xxx_offld_chain) +
3433 if (ha->exlogin_buf)
3434 dump_size += sizeof(struct qla2xxx_offld_chain) +
3438 if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) {
3440 ql_dbg(ql_dbg_init, vha, 0x00c5,
3441 "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n",
3442 __func__, dump_size, ha->fw_dump_len,
3443 ha->fw_dump_alloc_len);
3445 fw_dump = vmalloc(dump_size);
3447 ql_log(ql_log_warn, vha, 0x00c4,
3448 "Unable to allocate (%d KB) for firmware dump.\n",
3451 mutex_lock(&ha->optrom_mutex);
3452 if (ha->fw_dumped) {
3453 memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len);
3455 ha->fw_dump = fw_dump;
3456 ha->fw_dump_alloc_len = dump_size;
3457 ql_dbg(ql_dbg_init, vha, 0x00c5,
3458 "Re-Allocated (%d KB) and save firmware dump.\n",
3463 ha->fw_dump = fw_dump;
3465 ha->fw_dump_len = ha->fw_dump_alloc_len =
3467 ql_dbg(ql_dbg_init, vha, 0x00c5,
3468 "Allocated (%d KB) for firmware dump.\n",
3471 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3472 ha->mpi_fw_dump = (char *)fw_dump +
3473 ha->fwdt[1].dump_size;
3474 mutex_unlock(&ha->optrom_mutex);
3478 ha->fw_dump->signature[0] = 'Q';
3479 ha->fw_dump->signature[1] = 'L';
3480 ha->fw_dump->signature[2] = 'G';
3481 ha->fw_dump->signature[3] = 'C';
3482 ha->fw_dump->version = htonl(1);
3484 ha->fw_dump->fixed_size = htonl(fixed_size);
3485 ha->fw_dump->mem_size = htonl(mem_size);
3486 ha->fw_dump->req_q_size = htonl(req_q_size);
3487 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3489 ha->fw_dump->eft_size = htonl(eft_size);
3490 ha->fw_dump->eft_addr_l =
3491 htonl(LSD(ha->eft_dma));
3492 ha->fw_dump->eft_addr_h =
3493 htonl(MSD(ha->eft_dma));
3495 ha->fw_dump->header_size =
3497 (struct qla2xxx_fw_dump, isp));
3499 mutex_unlock(&ha->optrom_mutex);
3505 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3507 #define MPS_MASK 0xe0
3512 if (!IS_QLA81XX(vha->hw))
3515 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3516 if (rval != QLA_SUCCESS) {
3517 ql_log(ql_log_warn, vha, 0x0105,
3518 "Unable to acquire semaphore.\n");
3522 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3523 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3524 if (rval != QLA_SUCCESS) {
3525 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3530 if (dc == (dw & MPS_MASK))
3535 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3536 if (rval != QLA_SUCCESS) {
3537 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3541 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3542 if (rval != QLA_SUCCESS) {
3543 ql_log(ql_log_warn, vha, 0x006d,
3544 "Unable to release semaphore.\n");
3552 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3554 /* Don't try to reallocate the array */
3555 if (req->outstanding_cmds)
3558 if (!IS_FWI2_CAPABLE(ha))
3559 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3561 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3562 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3564 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3567 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3571 if (!req->outstanding_cmds) {
3573 * Try to allocate a minimal size just so we can get through
3576 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
3577 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3581 if (!req->outstanding_cmds) {
3582 ql_log(ql_log_fatal, NULL, 0x0126,
3583 "Failed to allocate memory for "
3584 "outstanding_cmds for req_que %p.\n", req);
3585 req->num_outstanding_cmds = 0;
3586 return QLA_FUNCTION_FAILED;
3593 #define PRINT_FIELD(_field, _flag, _str) { \
3594 if (a0->_field & _flag) {\
3600 len = snprintf(ptr, leftover, "%s", _str); \
3607 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
3610 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
3611 u8 str[STR_LEN], *ptr, p;
3614 memset(str, 0, STR_LEN);
3615 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
3616 ql_dbg(ql_dbg_init, vha, 0x015a,
3617 "SFP MFG Name: %s\n", str);
3619 memset(str, 0, STR_LEN);
3620 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
3621 ql_dbg(ql_dbg_init, vha, 0x015c,
3622 "SFP Part Name: %s\n", str);
3625 memset(str, 0, STR_LEN);
3629 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
3630 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
3631 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
3632 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
3633 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3634 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3635 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3636 ql_dbg(ql_dbg_init, vha, 0x0160,
3637 "SFP Media: %s\n", str);
3640 memset(str, 0, STR_LEN);
3644 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3645 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3646 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3647 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3648 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3649 ql_dbg(ql_dbg_init, vha, 0x0196,
3650 "SFP Link Length: %s\n", str);
3652 memset(str, 0, STR_LEN);
3656 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3657 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3658 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3659 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3660 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3661 ql_dbg(ql_dbg_init, vha, 0x016e,
3662 "SFP FC Link Tech: %s\n", str);
3665 ql_dbg(ql_dbg_init, vha, 0x016f,
3666 "SFP Distant: %d km\n", a0->length_km);
3667 if (a0->length_100m)
3668 ql_dbg(ql_dbg_init, vha, 0x0170,
3669 "SFP Distant: %d m\n", a0->length_100m*100);
3670 if (a0->length_50um_10m)
3671 ql_dbg(ql_dbg_init, vha, 0x0189,
3672 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3673 if (a0->length_62um_10m)
3674 ql_dbg(ql_dbg_init, vha, 0x018a,
3675 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3676 if (a0->length_om4_10m)
3677 ql_dbg(ql_dbg_init, vha, 0x0194,
3678 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3679 if (a0->length_om3_10m)
3680 ql_dbg(ql_dbg_init, vha, 0x0195,
3681 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3686 * qla24xx_detect_sfp()
3688 * @vha: adapter state pointer.
3691 * 0 -- Configure firmware to use short-range settings -- normal
3692 * buffer-to-buffer credits.
3694 * 1 -- Configure firmware to use long-range settings -- extra
3695 * buffer-to-buffer credits should be allocated with
3696 * ha->lr_distance containing distance settings from NVRAM or SFP
3700 qla24xx_detect_sfp(scsi_qla_host_t *vha)
3703 struct sff_8247_a0 *a;
3704 struct qla_hw_data *ha = vha->hw;
3705 struct nvram_81xx *nv = ha->nvram;
3706 #define LR_DISTANCE_UNKNOWN 2
3707 static const char * const types[] = { "Short", "Long" };
3708 static const char * const lengths[] = { "(10km)", "(5km)", "" };
3711 /* Seed with NVRAM settings. */
3713 ha->flags.lr_detected = 0;
3714 if (IS_BPM_RANGE_CAPABLE(ha) &&
3715 (nv->enhanced_features & NEF_LR_DIST_ENABLE)) {
3717 ha->flags.lr_detected = 1;
3719 (nv->enhanced_features >> LR_DIST_NV_POS)
3723 if (!IS_BPM_ENABLED(vha))
3725 /* Determine SR/LR capabilities of SFP/Transceiver. */
3726 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3731 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3732 qla2xxx_print_sfp_info(vha);
3734 ha->flags.lr_detected = 0;
3736 if (ll & FC_LL_VL || ll & FC_LL_L) {
3737 /* Long range, track length. */
3738 ha->flags.lr_detected = 1;
3740 if (a->length_km > 5 || a->length_100m > 50)
3741 ha->lr_distance = LR_DISTANCE_10K;
3743 ha->lr_distance = LR_DISTANCE_5K;
3747 ql_dbg(ql_dbg_async, vha, 0x507b,
3748 "SFP detect: %s-Range SFP %s (nvr=%x ll=%x lr=%x lrd=%x).\n",
3749 types[ha->flags.lr_detected],
3750 ha->flags.lr_detected ? lengths[ha->lr_distance] :
3751 lengths[LR_DISTANCE_UNKNOWN],
3752 used_nvram, ll, ha->flags.lr_detected, ha->lr_distance);
3753 return ha->flags.lr_detected;
3756 void qla_init_iocb_limit(scsi_qla_host_t *vha)
3760 struct qla_hw_data *ha = vha->hw;
3762 num_qps = ha->num_qpairs + 1;
3763 limit = (ha->orig_fw_iocb_count * QLA_IOCB_PCT_LIMIT) / 100;
3765 ha->base_qpair->fwres.iocbs_total = ha->orig_fw_iocb_count;
3766 ha->base_qpair->fwres.iocbs_limit = limit;
3767 ha->base_qpair->fwres.iocbs_qp_limit = limit / num_qps;
3768 ha->base_qpair->fwres.iocbs_used = 0;
3769 for (i = 0; i < ha->max_qpairs; i++) {
3770 if (ha->queue_pair_map[i]) {
3771 ha->queue_pair_map[i]->fwres.iocbs_total =
3772 ha->orig_fw_iocb_count;
3773 ha->queue_pair_map[i]->fwres.iocbs_limit = limit;
3774 ha->queue_pair_map[i]->fwres.iocbs_qp_limit =
3776 ha->queue_pair_map[i]->fwres.iocbs_used = 0;
3782 * qla2x00_setup_chip() - Load and start RISC firmware.
3785 * Returns 0 on success.
3788 qla2x00_setup_chip(scsi_qla_host_t *vha)
3791 uint32_t srisc_address = 0;
3792 struct qla_hw_data *ha = vha->hw;
3793 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3794 unsigned long flags;
3797 if (IS_P3P_TYPE(ha)) {
3798 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3799 if (rval == QLA_SUCCESS) {
3800 qla2x00_stop_firmware(vha);
3801 goto enable_82xx_npiv;
3806 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3807 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3808 spin_lock_irqsave(&ha->hardware_lock, flags);
3809 wrt_reg_word(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
3810 rd_reg_word(®->hccr);
3811 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3814 qla81xx_mpi_sync(vha);
3817 /* Load firmware sequences */
3818 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3819 if (rval == QLA_SUCCESS) {
3820 ql_dbg(ql_dbg_init, vha, 0x00c9,
3821 "Verifying Checksum of loaded RISC code.\n");
3823 rval = qla2x00_verify_checksum(vha, srisc_address);
3824 if (rval == QLA_SUCCESS) {
3825 /* Start firmware execution. */
3826 ql_dbg(ql_dbg_init, vha, 0x00ca,
3827 "Starting firmware.\n");
3830 ha->flags.exlogins_enabled = 1;
3832 if (qla_is_exch_offld_enabled(vha))
3833 ha->flags.exchoffld_enabled = 1;
3835 rval = qla2x00_execute_fw(vha, srisc_address);
3836 /* Retrieve firmware information. */
3837 if (rval == QLA_SUCCESS) {
3838 /* Enable BPM support? */
3839 if (!done_once++ && qla24xx_detect_sfp(vha)) {
3840 ql_dbg(ql_dbg_init, vha, 0x00ca,
3841 "Re-starting firmware -- BPM.\n");
3842 /* Best-effort - re-init. */
3843 ha->isp_ops->reset_chip(vha);
3844 ha->isp_ops->chip_diag(vha);
3845 goto execute_fw_with_lr;
3848 if (IS_ZIO_THRESHOLD_CAPABLE(ha))
3849 qla27xx_set_zio_threshold(vha,
3850 ha->last_zio_threshold);
3852 rval = qla2x00_set_exlogins_buffer(vha);
3853 if (rval != QLA_SUCCESS)
3856 rval = qla2x00_set_exchoffld_buffer(vha);
3857 if (rval != QLA_SUCCESS)
3861 if (IS_P3P_TYPE(ha))
3862 qla82xx_check_md_needed(vha);
3864 rval = qla2x00_get_fw_version(vha);
3865 if (rval != QLA_SUCCESS)
3867 ha->flags.npiv_supported = 0;
3868 if (IS_QLA2XXX_MIDTYPE(ha) &&
3869 (ha->fw_attributes & BIT_2)) {
3870 ha->flags.npiv_supported = 1;
3871 if ((!ha->max_npiv_vports) ||
3872 ((ha->max_npiv_vports + 1) %
3873 MIN_MULTI_ID_FABRIC))
3874 ha->max_npiv_vports =
3875 MIN_MULTI_ID_FABRIC - 1;
3877 qla2x00_get_resource_cnts(vha);
3878 qla_init_iocb_limit(vha);
3881 * Allocate the array of outstanding commands
3882 * now that we know the firmware resources.
3884 rval = qla2x00_alloc_outstanding_cmds(ha,
3886 if (rval != QLA_SUCCESS)
3889 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
3890 qla2x00_alloc_fw_dump(vha);
3892 qla_enable_fce_trace(vha);
3893 qla_enable_eft_trace(vha);
3898 ql_log(ql_log_fatal, vha, 0x00cd,
3899 "ISP Firmware failed checksum.\n");
3903 /* Enable PUREX PASSTHRU */
3904 if (ql2xrdpenable || ha->flags.scm_supported_f)
3905 qla25xx_set_els_cmds_supported(vha);
3909 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3910 /* Enable proper parity. */
3911 spin_lock_irqsave(&ha->hardware_lock, flags);
3914 wrt_reg_word(®->hccr, HCCR_ENABLE_PARITY + 0x1);
3916 /* SRAM, Instruction RAM and GP RAM parity */
3917 wrt_reg_word(®->hccr, HCCR_ENABLE_PARITY + 0x7);
3918 rd_reg_word(®->hccr);
3919 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3922 if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
3923 ha->flags.fac_supported = 1;
3924 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
3927 rval = qla81xx_fac_get_sector_size(vha, &size);
3928 if (rval == QLA_SUCCESS) {
3929 ha->flags.fac_supported = 1;
3930 ha->fdt_block_size = size << 2;
3932 ql_log(ql_log_warn, vha, 0x00ce,
3933 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3934 ha->fw_major_version, ha->fw_minor_version,
3935 ha->fw_subminor_version);
3937 if (IS_QLA83XX(ha)) {
3938 ha->flags.fac_supported = 0;
3945 ql_log(ql_log_fatal, vha, 0x00cf,
3946 "Setup chip ****FAILED****.\n");
3953 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3954 * @rsp: response queue
3956 * Beginning of request ring has initialization control block already built
3957 * by nvram config routine.
3959 * Returns 0 on success.
3962 qla2x00_init_response_q_entries(struct rsp_que *rsp)
3967 rsp->ring_ptr = rsp->ring;
3968 rsp->ring_index = 0;
3969 rsp->status_srb = NULL;
3970 pkt = rsp->ring_ptr;
3971 for (cnt = 0; cnt < rsp->length; cnt++) {
3972 pkt->signature = RESPONSE_PROCESSED;
3978 * qla2x00_update_fw_options() - Read and process firmware options.
3981 * Returns 0 on success.
3984 qla2x00_update_fw_options(scsi_qla_host_t *vha)
3986 uint16_t swing, emphasis, tx_sens, rx_sens;
3987 struct qla_hw_data *ha = vha->hw;
3989 memset(ha->fw_options, 0, sizeof(ha->fw_options));
3990 qla2x00_get_fw_options(vha, ha->fw_options);
3992 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3995 /* Serial Link options. */
3996 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3997 "Serial link options.\n");
3998 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3999 ha->fw_seriallink_options, sizeof(ha->fw_seriallink_options));
4001 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
4002 if (ha->fw_seriallink_options[3] & BIT_2) {
4003 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
4006 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
4007 emphasis = (ha->fw_seriallink_options[2] &
4008 (BIT_4 | BIT_3)) >> 3;
4009 tx_sens = ha->fw_seriallink_options[0] &
4010 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4011 rx_sens = (ha->fw_seriallink_options[0] &
4012 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
4013 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
4014 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
4017 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
4018 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
4019 ha->fw_options[10] |= BIT_5 |
4020 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
4021 (tx_sens & (BIT_1 | BIT_0));
4024 swing = (ha->fw_seriallink_options[2] &
4025 (BIT_7 | BIT_6 | BIT_5)) >> 5;
4026 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
4027 tx_sens = ha->fw_seriallink_options[1] &
4028 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4029 rx_sens = (ha->fw_seriallink_options[1] &
4030 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
4031 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
4032 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
4035 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
4036 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
4037 ha->fw_options[11] |= BIT_5 |
4038 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
4039 (tx_sens & (BIT_1 | BIT_0));
4043 /* Return command IOCBs without waiting for an ABTS to complete. */
4044 ha->fw_options[3] |= BIT_13;
4047 if (ha->flags.enable_led_scheme)
4048 ha->fw_options[2] |= BIT_12;
4050 /* Detect ISP6312. */
4052 ha->fw_options[2] |= BIT_13;
4054 /* Set Retry FLOGI in case of P2P connection */
4055 if (ha->operating_mode == P2P) {
4056 ha->fw_options[2] |= BIT_3;
4057 ql_dbg(ql_dbg_disc, vha, 0x2100,
4058 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
4059 __func__, ha->fw_options[2]);
4062 /* Update firmware options. */
4063 qla2x00_set_fw_options(vha, ha->fw_options);
4067 qla24xx_update_fw_options(scsi_qla_host_t *vha)
4070 struct qla_hw_data *ha = vha->hw;
4072 if (IS_P3P_TYPE(ha))
4075 /* Hold status IOCBs until ABTS response received. */
4077 ha->fw_options[3] |= BIT_12;
4079 /* Set Retry FLOGI in case of P2P connection */
4080 if (ha->operating_mode == P2P) {
4081 ha->fw_options[2] |= BIT_3;
4082 ql_dbg(ql_dbg_disc, vha, 0x2101,
4083 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
4084 __func__, ha->fw_options[2]);
4087 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
4088 if (ql2xmvasynctoatio &&
4089 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
4090 if (qla_tgt_mode_enabled(vha) ||
4091 qla_dual_mode_enabled(vha))
4092 ha->fw_options[2] |= BIT_11;
4094 ha->fw_options[2] &= ~BIT_11;
4097 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4100 * Tell FW to track each exchange to prevent
4101 * driver from using stale exchange.
4103 if (qla_tgt_mode_enabled(vha) ||
4104 qla_dual_mode_enabled(vha))
4105 ha->fw_options[2] |= BIT_4;
4107 ha->fw_options[2] &= ~BIT_4;
4109 /* Reserve 1/2 of emergency exchanges for ELS.*/
4110 if (qla2xuseresexchforels)
4111 ha->fw_options[2] |= BIT_8;
4113 ha->fw_options[2] &= ~BIT_8;
4116 if (ql2xrdpenable || ha->flags.scm_supported_f)
4117 ha->fw_options[1] |= ADD_FO1_ENABLE_PUREX_IOCB;
4119 /* Enable Async 8130/8131 events -- transceiver insertion/removal */
4120 if (IS_BPM_RANGE_CAPABLE(ha))
4121 ha->fw_options[3] |= BIT_10;
4123 ql_dbg(ql_dbg_init, vha, 0x00e8,
4124 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
4125 __func__, ha->fw_options[1], ha->fw_options[2],
4126 ha->fw_options[3], vha->host->active_mode);
4128 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
4129 qla2x00_set_fw_options(vha, ha->fw_options);
4131 /* Update Serial Link options. */
4132 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
4135 rval = qla2x00_set_serdes_params(vha,
4136 le16_to_cpu(ha->fw_seriallink_options24[1]),
4137 le16_to_cpu(ha->fw_seriallink_options24[2]),
4138 le16_to_cpu(ha->fw_seriallink_options24[3]));
4139 if (rval != QLA_SUCCESS) {
4140 ql_log(ql_log_warn, vha, 0x0104,
4141 "Unable to update Serial Link options (%x).\n", rval);
4146 qla2x00_config_rings(struct scsi_qla_host *vha)
4148 struct qla_hw_data *ha = vha->hw;
4149 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4150 struct req_que *req = ha->req_q_map[0];
4151 struct rsp_que *rsp = ha->rsp_q_map[0];
4153 /* Setup ring parameters in initialization control block. */
4154 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
4155 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
4156 ha->init_cb->request_q_length = cpu_to_le16(req->length);
4157 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
4158 put_unaligned_le64(req->dma, &ha->init_cb->request_q_address);
4159 put_unaligned_le64(rsp->dma, &ha->init_cb->response_q_address);
4161 wrt_reg_word(ISP_REQ_Q_IN(ha, reg), 0);
4162 wrt_reg_word(ISP_REQ_Q_OUT(ha, reg), 0);
4163 wrt_reg_word(ISP_RSP_Q_IN(ha, reg), 0);
4164 wrt_reg_word(ISP_RSP_Q_OUT(ha, reg), 0);
4165 rd_reg_word(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
4169 qla24xx_config_rings(struct scsi_qla_host *vha)
4171 struct qla_hw_data *ha = vha->hw;
4172 device_reg_t *reg = ISP_QUE_REG(ha, 0);
4173 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
4174 struct qla_msix_entry *msix;
4175 struct init_cb_24xx *icb;
4177 struct req_que *req = ha->req_q_map[0];
4178 struct rsp_que *rsp = ha->rsp_q_map[0];
4180 /* Setup ring parameters in initialization control block. */
4181 icb = (struct init_cb_24xx *)ha->init_cb;
4182 icb->request_q_outpointer = cpu_to_le16(0);
4183 icb->response_q_inpointer = cpu_to_le16(0);
4184 icb->request_q_length = cpu_to_le16(req->length);
4185 icb->response_q_length = cpu_to_le16(rsp->length);
4186 put_unaligned_le64(req->dma, &icb->request_q_address);
4187 put_unaligned_le64(rsp->dma, &icb->response_q_address);
4189 /* Setup ATIO queue dma pointers for target mode */
4190 icb->atio_q_inpointer = cpu_to_le16(0);
4191 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
4192 put_unaligned_le64(ha->tgt.atio_dma, &icb->atio_q_address);
4194 if (IS_SHADOW_REG_CAPABLE(ha))
4195 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
4197 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4199 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
4200 icb->rid = cpu_to_le16(rid);
4201 if (ha->flags.msix_enabled) {
4202 msix = &ha->msix_entries[1];
4203 ql_dbg(ql_dbg_init, vha, 0x0019,
4204 "Registering vector 0x%x for base que.\n",
4206 icb->msix = cpu_to_le16(msix->entry);
4208 /* Use alternate PCI bus number */
4210 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
4211 /* Use alternate PCI devfn */
4213 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
4215 /* Use Disable MSIX Handshake mode for capable adapters */
4216 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
4217 (ha->flags.msix_enabled)) {
4218 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
4219 ha->flags.disable_msix_handshake = 1;
4220 ql_dbg(ql_dbg_init, vha, 0x00fe,
4221 "MSIX Handshake Disable Mode turned on.\n");
4223 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
4225 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
4227 wrt_reg_dword(®->isp25mq.req_q_in, 0);
4228 wrt_reg_dword(®->isp25mq.req_q_out, 0);
4229 wrt_reg_dword(®->isp25mq.rsp_q_in, 0);
4230 wrt_reg_dword(®->isp25mq.rsp_q_out, 0);
4232 wrt_reg_dword(®->isp24.req_q_in, 0);
4233 wrt_reg_dword(®->isp24.req_q_out, 0);
4234 wrt_reg_dword(®->isp24.rsp_q_in, 0);
4235 wrt_reg_dword(®->isp24.rsp_q_out, 0);
4238 qlt_24xx_config_rings(vha);
4240 /* If the user has configured the speed, set it here */
4241 if (ha->set_data_rate) {
4242 ql_dbg(ql_dbg_init, vha, 0x00fd,
4243 "Speed set by user : %s Gbps \n",
4244 qla2x00_get_link_speed_str(ha, ha->set_data_rate));
4245 icb->firmware_options_3 = cpu_to_le32(ha->set_data_rate << 13);
4249 rd_reg_word(&ioreg->hccr);
4253 * qla2x00_init_rings() - Initializes firmware.
4256 * Beginning of request ring has initialization control block already built
4257 * by nvram config routine.
4259 * Returns 0 on success.
4262 qla2x00_init_rings(scsi_qla_host_t *vha)
4265 unsigned long flags = 0;
4267 struct qla_hw_data *ha = vha->hw;
4268 struct req_que *req;
4269 struct rsp_que *rsp;
4270 struct mid_init_cb_24xx *mid_init_cb =
4271 (struct mid_init_cb_24xx *) ha->init_cb;
4273 spin_lock_irqsave(&ha->hardware_lock, flags);
4275 /* Clear outstanding commands array. */
4276 for (que = 0; que < ha->max_req_queues; que++) {
4277 req = ha->req_q_map[que];
4278 if (!req || !test_bit(que, ha->req_qid_map))
4280 req->out_ptr = (uint16_t *)(req->ring + req->length);
4282 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
4283 req->outstanding_cmds[cnt] = NULL;
4285 req->current_outstanding_cmd = 1;
4287 /* Initialize firmware. */
4288 req->ring_ptr = req->ring;
4289 req->ring_index = 0;
4290 req->cnt = req->length;
4293 for (que = 0; que < ha->max_rsp_queues; que++) {
4294 rsp = ha->rsp_q_map[que];
4295 if (!rsp || !test_bit(que, ha->rsp_qid_map))
4297 rsp->in_ptr = (uint16_t *)(rsp->ring + rsp->length);
4299 /* Initialize response queue entries */
4301 qlafx00_init_response_q_entries(rsp);
4303 qla2x00_init_response_q_entries(rsp);
4306 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
4307 ha->tgt.atio_ring_index = 0;
4308 /* Initialize ATIO queue entries */
4309 qlt_init_atio_q_entries(vha);
4311 ha->isp_ops->config_rings(vha);
4313 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4315 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
4317 if (IS_QLAFX00(ha)) {
4318 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
4322 /* Update any ISP specific firmware options before initialization. */
4323 ha->isp_ops->update_fw_options(vha);
4325 if (ha->flags.npiv_supported) {
4326 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
4327 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
4328 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
4331 if (IS_FWI2_CAPABLE(ha)) {
4332 mid_init_cb->options = cpu_to_le16(BIT_1);
4333 mid_init_cb->init_cb.execution_throttle =
4334 cpu_to_le16(ha->cur_fw_xcb_count);
4335 ha->flags.dport_enabled =
4336 (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) &
4338 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
4339 (ha->flags.dport_enabled) ? "enabled" : "disabled");
4340 /* FA-WWPN Status */
4341 ha->flags.fawwpn_enabled =
4342 (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) &
4344 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
4345 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
4346 /* Init_cb will be reused for other command(s). Save a backup copy of port_name */
4347 memcpy(ha->port_name, ha->init_cb->port_name, WWN_SIZE);
4351 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
4355 ql_log(ql_log_fatal, vha, 0x00d2,
4356 "Init Firmware **** FAILED ****.\n");
4358 ql_dbg(ql_dbg_init, vha, 0x00d3,
4359 "Init Firmware -- success.\n");
4360 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0;
4367 * qla2x00_fw_ready() - Waits for firmware ready.
4370 * Returns 0 on success.
4373 qla2x00_fw_ready(scsi_qla_host_t *vha)
4376 unsigned long wtime, mtime, cs84xx_time;
4377 uint16_t min_wait; /* Minimum wait time if loop is down */
4378 uint16_t wait_time; /* Wait time if loop is coming ready */
4380 struct qla_hw_data *ha = vha->hw;
4382 if (IS_QLAFX00(vha->hw))
4383 return qlafx00_fw_ready(vha);
4387 /* Time to wait for loop down */
4388 if (IS_P3P_TYPE(ha))
4394 * Firmware should take at most one RATOV to login, plus 5 seconds for
4395 * our own processing.
4397 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
4398 wait_time = min_wait;
4401 /* Min wait time if loop down */
4402 mtime = jiffies + (min_wait * HZ);
4404 /* wait time before firmware ready */
4405 wtime = jiffies + (wait_time * HZ);
4407 /* Wait for ISP to finish LIP */
4408 if (!vha->flags.init_done)
4409 ql_log(ql_log_info, vha, 0x801e,
4410 "Waiting for LIP to complete.\n");
4413 memset(state, -1, sizeof(state));
4414 rval = qla2x00_get_firmware_state(vha, state);
4415 if (rval == QLA_SUCCESS) {
4416 if (state[0] < FSTATE_LOSS_OF_SYNC) {
4417 vha->device_flags &= ~DFLG_NO_CABLE;
4419 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
4420 ql_dbg(ql_dbg_taskm, vha, 0x801f,
4421 "fw_state=%x 84xx=%x.\n", state[0],
4423 if ((state[2] & FSTATE_LOGGED_IN) &&
4424 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
4425 ql_dbg(ql_dbg_taskm, vha, 0x8028,
4426 "Sending verify iocb.\n");
4428 cs84xx_time = jiffies;
4429 rval = qla84xx_init_chip(vha);
4430 if (rval != QLA_SUCCESS) {
4433 "Init chip failed.\n");
4437 /* Add time taken to initialize. */
4438 cs84xx_time = jiffies - cs84xx_time;
4439 wtime += cs84xx_time;
4440 mtime += cs84xx_time;
4441 ql_dbg(ql_dbg_taskm, vha, 0x8008,
4442 "Increasing wait time by %ld. "
4443 "New time %ld.\n", cs84xx_time,
4446 } else if (state[0] == FSTATE_READY) {
4447 ql_dbg(ql_dbg_taskm, vha, 0x8037,
4448 "F/W Ready - OK.\n");
4450 qla2x00_get_retry_cnt(vha, &ha->retry_count,
4451 &ha->login_timeout, &ha->r_a_tov);
4457 rval = QLA_FUNCTION_FAILED;
4459 if (atomic_read(&vha->loop_down_timer) &&
4460 state[0] != FSTATE_READY) {
4461 /* Loop down. Timeout on min_wait for states
4462 * other than Wait for Login.
4464 if (time_after_eq(jiffies, mtime)) {
4465 ql_log(ql_log_info, vha, 0x8038,
4466 "Cable is unplugged...\n");
4468 vha->device_flags |= DFLG_NO_CABLE;
4473 /* Mailbox cmd failed. Timeout on min_wait. */
4474 if (time_after_eq(jiffies, mtime) ||
4475 ha->flags.isp82xx_fw_hung)
4479 if (time_after_eq(jiffies, wtime))
4482 /* Delay for a while */
4486 ql_dbg(ql_dbg_taskm, vha, 0x803a,
4487 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
4488 state[1], state[2], state[3], state[4], state[5], jiffies);
4490 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
4491 ql_log(ql_log_warn, vha, 0x803b,
4492 "Firmware ready **** FAILED ****.\n");
4499 * qla2x00_configure_hba
4500 * Setup adapter context.
4503 * ha = adapter state pointer.
4512 qla2x00_configure_hba(scsi_qla_host_t *vha)
4521 char connect_type[22];
4522 struct qla_hw_data *ha = vha->hw;
4523 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4525 unsigned long flags;
4527 /* Get host addresses. */
4528 rval = qla2x00_get_adapter_id(vha,
4529 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
4530 if (rval != QLA_SUCCESS) {
4531 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
4532 IS_CNA_CAPABLE(ha) ||
4533 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
4534 ql_dbg(ql_dbg_disc, vha, 0x2008,
4535 "Loop is in a transition state.\n");
4537 ql_log(ql_log_warn, vha, 0x2009,
4538 "Unable to get host loop ID.\n");
4539 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
4540 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
4541 ql_log(ql_log_warn, vha, 0x1151,
4542 "Doing link init.\n");
4543 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
4546 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4552 ql_log(ql_log_info, vha, 0x200a,
4553 "Cannot get topology - retrying.\n");
4554 return (QLA_FUNCTION_FAILED);
4557 vha->loop_id = loop_id;
4560 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
4561 ha->operating_mode = LOOP;
4566 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
4567 ha->current_topology = ISP_CFG_NL;
4568 strcpy(connect_type, "(Loop)");
4572 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
4573 ha->switch_cap = sw_cap;
4574 ha->current_topology = ISP_CFG_FL;
4575 strcpy(connect_type, "(FL_Port)");
4579 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
4580 ha->operating_mode = P2P;
4581 ha->current_topology = ISP_CFG_N;
4582 strcpy(connect_type, "(N_Port-to-N_Port)");
4586 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
4587 ha->switch_cap = sw_cap;
4588 ha->operating_mode = P2P;
4589 ha->current_topology = ISP_CFG_F;
4590 strcpy(connect_type, "(F_Port)");
4594 ql_dbg(ql_dbg_disc, vha, 0x200f,
4595 "HBA in unknown topology %x, using NL.\n", topo);
4596 ha->current_topology = ISP_CFG_NL;
4597 strcpy(connect_type, "(Loop)");
4601 /* Save Host port and loop ID. */
4602 /* byte order - Big Endian */
4603 id.b.domain = domain;
4607 spin_lock_irqsave(&ha->hardware_lock, flags);
4608 if (!(topo == 2 && ha->flags.n2n_bigger))
4609 qlt_update_host_map(vha, id);
4610 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4612 if (!vha->flags.init_done)
4613 ql_log(ql_log_info, vha, 0x2010,
4614 "Topology - %s, Host Loop address 0x%x.\n",
4615 connect_type, vha->loop_id);
4621 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
4626 uint64_t zero[2] = { 0 };
4627 struct qla_hw_data *ha = vha->hw;
4628 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
4629 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
4631 if (len > sizeof(zero))
4633 if (memcmp(model, &zero, len) != 0) {
4634 memcpy(ha->model_number, model, len);
4635 st = en = ha->model_number;
4638 if (*en != 0x20 && *en != 0x00)
4643 index = (ha->pdev->subsystem_device & 0xff);
4645 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4646 index < QLA_MODEL_NAMES)
4647 strlcpy(ha->model_desc,
4648 qla2x00_model_name[index * 2 + 1],
4649 sizeof(ha->model_desc));
4651 index = (ha->pdev->subsystem_device & 0xff);
4653 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4654 index < QLA_MODEL_NAMES) {
4655 strlcpy(ha->model_number,
4656 qla2x00_model_name[index * 2],
4657 sizeof(ha->model_number));
4658 strlcpy(ha->model_desc,
4659 qla2x00_model_name[index * 2 + 1],
4660 sizeof(ha->model_desc));
4662 strlcpy(ha->model_number, def,
4663 sizeof(ha->model_number));
4666 if (IS_FWI2_CAPABLE(ha))
4667 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
4668 sizeof(ha->model_desc));
4671 /* On sparc systems, obtain port and node WWN from firmware
4674 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4677 struct qla_hw_data *ha = vha->hw;
4678 struct pci_dev *pdev = ha->pdev;
4679 struct device_node *dp = pci_device_to_OF_node(pdev);
4683 val = of_get_property(dp, "port-wwn", &len);
4684 if (val && len >= WWN_SIZE)
4685 memcpy(nv->port_name, val, WWN_SIZE);
4687 val = of_get_property(dp, "node-wwn", &len);
4688 if (val && len >= WWN_SIZE)
4689 memcpy(nv->node_name, val, WWN_SIZE);
4694 * NVRAM configuration for ISP 2xxx
4697 * ha = adapter block pointer.
4700 * initialization control block in response_ring
4701 * host adapters parameters in host adapter block
4707 qla2x00_nvram_config(scsi_qla_host_t *vha)
4712 uint8_t *dptr1, *dptr2;
4713 struct qla_hw_data *ha = vha->hw;
4714 init_cb_t *icb = ha->init_cb;
4715 nvram_t *nv = ha->nvram;
4716 uint8_t *ptr = ha->nvram;
4717 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4721 /* Determine NVRAM starting address. */
4722 ha->nvram_size = sizeof(*nv);
4724 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4725 if ((rd_reg_word(®->ctrl_status) >> 14) == 1)
4726 ha->nvram_base = 0x80;
4728 /* Get NVRAM data and calculate checksum. */
4729 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
4730 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4733 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4734 "Contents of NVRAM.\n");
4735 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4736 nv, ha->nvram_size);
4738 /* Bad NVRAM data, set defaults parameters. */
4739 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
4740 nv->nvram_version < 1) {
4741 /* Reset NVRAM data. */
4742 ql_log(ql_log_warn, vha, 0x0064,
4743 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
4744 chksum, nv->id, nv->nvram_version);
4745 ql_log(ql_log_warn, vha, 0x0065,
4747 "functioning (yet invalid -- WWPN) defaults.\n");
4750 * Set default initialization control block.
4752 memset(nv, 0, ha->nvram_size);
4753 nv->parameter_block_version = ICB_VERSION;
4755 if (IS_QLA23XX(ha)) {
4756 nv->firmware_options[0] = BIT_2 | BIT_1;
4757 nv->firmware_options[1] = BIT_7 | BIT_5;
4758 nv->add_firmware_options[0] = BIT_5;
4759 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4760 nv->frame_payload_size = cpu_to_le16(2048);
4761 nv->special_options[1] = BIT_7;
4762 } else if (IS_QLA2200(ha)) {
4763 nv->firmware_options[0] = BIT_2 | BIT_1;
4764 nv->firmware_options[1] = BIT_7 | BIT_5;
4765 nv->add_firmware_options[0] = BIT_5;
4766 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4767 nv->frame_payload_size = cpu_to_le16(1024);
4768 } else if (IS_QLA2100(ha)) {
4769 nv->firmware_options[0] = BIT_3 | BIT_1;
4770 nv->firmware_options[1] = BIT_5;
4771 nv->frame_payload_size = cpu_to_le16(1024);
4774 nv->max_iocb_allocation = cpu_to_le16(256);
4775 nv->execution_throttle = cpu_to_le16(16);
4776 nv->retry_count = 8;
4777 nv->retry_delay = 1;
4779 nv->port_name[0] = 33;
4780 nv->port_name[3] = 224;
4781 nv->port_name[4] = 139;
4783 qla2xxx_nvram_wwn_from_ofw(vha, nv);
4785 nv->login_timeout = 4;
4788 * Set default host adapter parameters
4790 nv->host_p[1] = BIT_2;
4791 nv->reset_delay = 5;
4792 nv->port_down_retry_count = 8;
4793 nv->max_luns_per_target = cpu_to_le16(8);
4794 nv->link_down_timeout = 60;
4799 /* Reset Initialization control block */
4800 memset(icb, 0, ha->init_cb_size);
4803 * Setup driver NVRAM options.
4805 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4806 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4807 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4808 nv->firmware_options[1] &= ~BIT_4;
4810 if (IS_QLA23XX(ha)) {
4811 nv->firmware_options[0] |= BIT_2;
4812 nv->firmware_options[0] &= ~BIT_3;
4813 nv->special_options[0] &= ~BIT_6;
4814 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
4816 if (IS_QLA2300(ha)) {
4817 if (ha->fb_rev == FPM_2310) {
4818 strcpy(ha->model_number, "QLA2310");
4820 strcpy(ha->model_number, "QLA2300");
4823 qla2x00_set_model_info(vha, nv->model_number,
4824 sizeof(nv->model_number), "QLA23xx");
4826 } else if (IS_QLA2200(ha)) {
4827 nv->firmware_options[0] |= BIT_2;
4829 * 'Point-to-point preferred, else loop' is not a safe
4830 * connection mode setting.
4832 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4834 /* Force 'loop preferred, else point-to-point'. */
4835 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4836 nv->add_firmware_options[0] |= BIT_5;
4838 strcpy(ha->model_number, "QLA22xx");
4839 } else /*if (IS_QLA2100(ha))*/ {
4840 strcpy(ha->model_number, "QLA2100");
4844 * Copy over NVRAM RISC parameter block to initialization control block.
4846 dptr1 = (uint8_t *)icb;
4847 dptr2 = (uint8_t *)&nv->parameter_block_version;
4848 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4850 *dptr1++ = *dptr2++;
4852 /* Copy 2nd half. */
4853 dptr1 = (uint8_t *)icb->add_firmware_options;
4854 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4856 *dptr1++ = *dptr2++;
4857 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
4858 /* Use alternate WWN? */
4859 if (nv->host_p[1] & BIT_7) {
4860 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4861 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4864 /* Prepare nodename */
4865 if ((icb->firmware_options[1] & BIT_6) == 0) {
4867 * Firmware will apply the following mask if the nodename was
4870 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4871 icb->node_name[0] &= 0xF0;
4875 * Set host adapter parameters.
4879 * BIT_7 in the host-parameters section allows for modification to
4880 * internal driver logging.
4882 if (nv->host_p[0] & BIT_7)
4883 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
4884 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4885 /* Always load RISC code on non ISP2[12]00 chips. */
4886 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4887 ha->flags.disable_risc_code_load = 0;
4888 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4889 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4890 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
4891 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
4892 ha->flags.disable_serdes = 0;
4894 ha->operating_mode =
4895 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4897 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4898 sizeof(ha->fw_seriallink_options));
4900 /* save HBA serial number */
4901 ha->serial0 = icb->port_name[5];
4902 ha->serial1 = icb->port_name[6];
4903 ha->serial2 = icb->port_name[7];
4904 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4905 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4907 icb->execution_throttle = cpu_to_le16(0xFFFF);
4909 ha->retry_count = nv->retry_count;
4911 /* Set minimum login_timeout to 4 seconds. */
4912 if (nv->login_timeout != ql2xlogintimeout)
4913 nv->login_timeout = ql2xlogintimeout;
4914 if (nv->login_timeout < 4)
4915 nv->login_timeout = 4;
4916 ha->login_timeout = nv->login_timeout;
4918 /* Set minimum RATOV to 100 tenths of a second. */
4921 ha->loop_reset_delay = nv->reset_delay;
4923 /* Link Down Timeout = 0:
4925 * When Port Down timer expires we will start returning
4926 * I/O's to OS with "DID_NO_CONNECT".
4928 * Link Down Timeout != 0:
4930 * The driver waits for the link to come up after link down
4931 * before returning I/Os to OS with "DID_NO_CONNECT".
4933 if (nv->link_down_timeout == 0) {
4934 ha->loop_down_abort_time =
4935 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4937 ha->link_down_timeout = nv->link_down_timeout;
4938 ha->loop_down_abort_time =
4939 (LOOP_DOWN_TIME - ha->link_down_timeout);
4943 * Need enough time to try and get the port back.
4945 ha->port_down_retry_count = nv->port_down_retry_count;
4946 if (qlport_down_retry)
4947 ha->port_down_retry_count = qlport_down_retry;
4948 /* Set login_retry_count */
4949 ha->login_retry_count = nv->retry_count;
4950 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4951 ha->port_down_retry_count > 3)
4952 ha->login_retry_count = ha->port_down_retry_count;
4953 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4954 ha->login_retry_count = ha->port_down_retry_count;
4955 if (ql2xloginretrycount)
4956 ha->login_retry_count = ql2xloginretrycount;
4958 icb->lun_enables = cpu_to_le16(0);
4959 icb->command_resource_count = 0;
4960 icb->immediate_notify_resource_count = 0;
4961 icb->timeout = cpu_to_le16(0);
4963 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4965 icb->firmware_options[0] &= ~BIT_3;
4966 icb->add_firmware_options[0] &=
4967 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4968 icb->add_firmware_options[0] |= BIT_2;
4969 icb->response_accumulation_timer = 3;
4970 icb->interrupt_delay_timer = 5;
4972 vha->flags.process_response_queue = 1;
4975 if (!vha->flags.init_done) {
4976 ha->zio_mode = icb->add_firmware_options[0] &
4977 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4978 ha->zio_timer = icb->interrupt_delay_timer ?
4979 icb->interrupt_delay_timer : 2;
4981 icb->add_firmware_options[0] &=
4982 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4983 vha->flags.process_response_queue = 0;
4984 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4985 ha->zio_mode = QLA_ZIO_MODE_6;
4987 ql_log(ql_log_info, vha, 0x0068,
4988 "ZIO mode %d enabled; timer delay (%d us).\n",
4989 ha->zio_mode, ha->zio_timer * 100);
4991 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4992 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
4993 vha->flags.process_response_queue = 1;
4998 ql_log(ql_log_warn, vha, 0x0069,
4999 "NVRAM configuration failed.\n");
5005 qla2x00_rport_del(void *data)
5007 fc_port_t *fcport = data;
5008 struct fc_rport *rport;
5009 unsigned long flags;
5011 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5012 rport = fcport->drport ? fcport->drport : fcport->rport;
5013 fcport->drport = NULL;
5014 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5016 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
5017 "%s %8phN. rport %p roles %x\n",
5018 __func__, fcport->port_name, rport,
5021 fc_remote_port_delete(rport);
5025 void qla2x00_set_fcport_state(fc_port_t *fcport, int state)
5029 old_state = atomic_read(&fcport->state);
5030 atomic_set(&fcport->state, state);
5032 /* Don't print state transitions during initial allocation of fcport */
5033 if (old_state && old_state != state) {
5034 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
5035 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
5036 fcport->port_name, port_state_str[old_state],
5037 port_state_str[state], fcport->d_id.b.domain,
5038 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5043 * qla2x00_alloc_fcport() - Allocate a generic fcport.
5045 * @flags: allocation flags
5047 * Returns a pointer to the allocated fcport, or NULL, if none available.
5050 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
5054 fcport = kzalloc(sizeof(fc_port_t), flags);
5058 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
5059 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
5061 if (!fcport->ct_desc.ct_sns) {
5062 ql_log(ql_log_warn, vha, 0xd049,
5063 "Failed to allocate ct_sns request.\n");
5068 /* Setup fcport template structure. */
5070 fcport->port_type = FCT_UNKNOWN;
5071 fcport->loop_id = FC_NO_LOOP_ID;
5072 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
5073 fcport->supported_classes = FC_COS_UNSPECIFIED;
5074 fcport->fp_speed = PORT_SPEED_UNKNOWN;
5076 fcport->disc_state = DSC_DELETED;
5077 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
5078 fcport->deleted = QLA_SESS_DELETED;
5079 fcport->login_retry = vha->hw->login_retry_count;
5080 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
5081 fcport->logout_on_delete = 1;
5083 if (!fcport->ct_desc.ct_sns) {
5084 ql_log(ql_log_warn, vha, 0xd049,
5085 "Failed to allocate ct_sns request.\n");
5090 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
5091 INIT_WORK(&fcport->free_work, qlt_free_session_done);
5092 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
5093 INIT_LIST_HEAD(&fcport->gnl_entry);
5094 INIT_LIST_HEAD(&fcport->list);
5100 qla2x00_free_fcport(fc_port_t *fcport)
5102 if (fcport->ct_desc.ct_sns) {
5103 dma_free_coherent(&fcport->vha->hw->pdev->dev,
5104 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
5105 fcport->ct_desc.ct_sns_dma);
5107 fcport->ct_desc.ct_sns = NULL;
5109 list_del(&fcport->list);
5110 qla2x00_clear_loop_id(fcport);
5114 static void qla_get_login_template(scsi_qla_host_t *vha)
5116 struct qla_hw_data *ha = vha->hw;
5121 memset(ha->init_cb, 0, ha->init_cb_size);
5122 sz = min_t(int, sizeof(struct fc_els_flogi), ha->init_cb_size);
5123 rval = qla24xx_get_port_login_templ(vha, ha->init_cb_dma,
5125 if (rval != QLA_SUCCESS) {
5126 ql_dbg(ql_dbg_init, vha, 0x00d1,
5127 "PLOGI ELS param read fail.\n");
5130 q = (__be32 *)&ha->plogi_els_payld.fl_csp;
5132 bp = (uint32_t *)ha->init_cb;
5133 cpu_to_be32_array(q, bp, sz / 4);
5134 ha->flags.plogi_template_valid = 1;
5138 * qla2x00_configure_loop
5139 * Updates Fibre Channel Device Database with what is actually on loop.
5142 * ha = adapter block pointer.
5147 * 2 = database was full and device was not configured.
5150 qla2x00_configure_loop(scsi_qla_host_t *vha)
5153 unsigned long flags, save_flags;
5154 struct qla_hw_data *ha = vha->hw;
5158 /* Get Initiator ID */
5159 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
5160 rval = qla2x00_configure_hba(vha);
5161 if (rval != QLA_SUCCESS) {
5162 ql_dbg(ql_dbg_disc, vha, 0x2013,
5163 "Unable to configure HBA.\n");
5168 save_flags = flags = vha->dpc_flags;
5169 ql_dbg(ql_dbg_disc, vha, 0x2014,
5170 "Configure loop -- dpc flags = 0x%lx.\n", flags);
5173 * If we have both an RSCN and PORT UPDATE pending then handle them
5174 * both at the same time.
5176 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5177 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
5179 qla2x00_get_data_rate(vha);
5180 qla_get_login_template(vha);
5182 /* Determine what we need to do */
5183 if ((ha->current_topology == ISP_CFG_FL ||
5184 ha->current_topology == ISP_CFG_F) &&
5185 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
5187 set_bit(RSCN_UPDATE, &flags);
5188 clear_bit(LOCAL_LOOP_UPDATE, &flags);
5190 } else if (ha->current_topology == ISP_CFG_NL ||
5191 ha->current_topology == ISP_CFG_N) {
5192 clear_bit(RSCN_UPDATE, &flags);
5193 set_bit(LOCAL_LOOP_UPDATE, &flags);
5194 } else if (!vha->flags.online ||
5195 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
5196 set_bit(RSCN_UPDATE, &flags);
5197 set_bit(LOCAL_LOOP_UPDATE, &flags);
5200 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
5201 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5202 ql_dbg(ql_dbg_disc, vha, 0x2015,
5203 "Loop resync needed, failing.\n");
5204 rval = QLA_FUNCTION_FAILED;
5206 rval = qla2x00_configure_local_loop(vha);
5209 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
5210 if (LOOP_TRANSITION(vha)) {
5211 ql_dbg(ql_dbg_disc, vha, 0x2099,
5212 "Needs RSCN update and loop transition.\n");
5213 rval = QLA_FUNCTION_FAILED;
5216 rval = qla2x00_configure_fabric(vha);
5219 if (rval == QLA_SUCCESS) {
5220 if (atomic_read(&vha->loop_down_timer) ||
5221 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5222 rval = QLA_FUNCTION_FAILED;
5224 atomic_set(&vha->loop_state, LOOP_READY);
5225 ql_dbg(ql_dbg_disc, vha, 0x2069,
5227 ha->flags.fw_init_done = 1;
5230 * Process any ATIO queue entries that came in
5231 * while we weren't online.
5233 if (qla_tgt_mode_enabled(vha) ||
5234 qla_dual_mode_enabled(vha)) {
5235 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
5236 qlt_24xx_process_atio_queue(vha, 0);
5237 spin_unlock_irqrestore(&ha->tgt.atio_lock,
5244 ql_dbg(ql_dbg_disc, vha, 0x206a,
5245 "%s *** FAILED ***.\n", __func__);
5247 ql_dbg(ql_dbg_disc, vha, 0x206b,
5248 "%s: exiting normally.\n", __func__);
5251 /* Restore state if a resync event occurred during processing */
5252 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5253 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
5254 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5255 if (test_bit(RSCN_UPDATE, &save_flags)) {
5256 set_bit(RSCN_UPDATE, &vha->dpc_flags);
5263 static int qla2x00_configure_n2n_loop(scsi_qla_host_t *vha)
5265 unsigned long flags;
5268 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags))
5269 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5271 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5272 if (fcport->n2n_flag) {
5273 qla24xx_fcport_handle_login(vha, fcport);
5278 spin_lock_irqsave(&vha->work_lock, flags);
5279 vha->scan.scan_retry++;
5280 spin_unlock_irqrestore(&vha->work_lock, flags);
5282 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5283 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5284 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5286 return QLA_FUNCTION_FAILED;
5290 qla_reinitialize_link(scsi_qla_host_t *vha)
5294 atomic_set(&vha->loop_state, LOOP_DOWN);
5295 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
5296 rval = qla2x00_full_login_lip(vha);
5297 if (rval == QLA_SUCCESS) {
5298 ql_dbg(ql_dbg_disc, vha, 0xd050, "Link reinitialized\n");
5300 ql_dbg(ql_dbg_disc, vha, 0xd051,
5301 "Link reinitialization failed (%d)\n", rval);
5306 * qla2x00_configure_local_loop
5307 * Updates Fibre Channel Device Database with local loop devices.
5310 * ha = adapter block pointer.
5316 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
5321 fc_port_t *fcport, *new_fcport;
5324 struct gid_list_info *gid;
5326 uint8_t domain, area, al_pa;
5327 struct qla_hw_data *ha = vha->hw;
5328 unsigned long flags;
5330 /* Inititae N2N login. */
5332 return qla2x00_configure_n2n_loop(vha);
5336 entries = MAX_FIBRE_DEVICES_LOOP;
5338 /* Get list of logged in devices. */
5339 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
5340 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
5342 if (rval != QLA_SUCCESS)
5345 ql_dbg(ql_dbg_disc, vha, 0x2011,
5346 "Entries in ID list (%d).\n", entries);
5347 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
5348 ha->gid_list, entries * sizeof(*ha->gid_list));
5351 spin_lock_irqsave(&vha->work_lock, flags);
5352 vha->scan.scan_retry++;
5353 spin_unlock_irqrestore(&vha->work_lock, flags);
5355 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5356 u8 loop_map_entries = 0;
5359 rc = qla2x00_get_fcal_position_map(vha, NULL,
5361 if (rc == QLA_SUCCESS && loop_map_entries > 1) {
5363 * There are devices that are still not logged
5364 * in. Reinitialize to give them a chance.
5366 qla_reinitialize_link(vha);
5367 return QLA_FUNCTION_FAILED;
5369 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5370 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5373 vha->scan.scan_retry = 0;
5376 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5377 fcport->scan_state = QLA_FCPORT_SCAN;
5380 /* Allocate temporary fcport for any new fcports discovered. */
5381 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5382 if (new_fcport == NULL) {
5383 ql_log(ql_log_warn, vha, 0x2012,
5384 "Memory allocation failed for fcport.\n");
5385 rval = QLA_MEMORY_ALLOC_FAILED;
5388 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5390 /* Add devices to port list. */
5392 for (index = 0; index < entries; index++) {
5393 domain = gid->domain;
5396 if (IS_QLA2100(ha) || IS_QLA2200(ha))
5397 loop_id = gid->loop_id_2100;
5399 loop_id = le16_to_cpu(gid->loop_id);
5400 gid = (void *)gid + ha->gid_list_info_size;
5402 /* Bypass reserved domain fields. */
5403 if ((domain & 0xf0) == 0xf0)
5406 /* Bypass if not same domain and area of adapter. */
5407 if (area && domain && ((area != vha->d_id.b.area) ||
5408 (domain != vha->d_id.b.domain)) &&
5409 (ha->current_topology == ISP_CFG_NL))
5413 /* Bypass invalid local loop ID. */
5414 if (loop_id > LAST_LOCAL_LOOP_ID)
5417 memset(new_fcport->port_name, 0, WWN_SIZE);
5419 /* Fill in member data. */
5420 new_fcport->d_id.b.domain = domain;
5421 new_fcport->d_id.b.area = area;
5422 new_fcport->d_id.b.al_pa = al_pa;
5423 new_fcport->loop_id = loop_id;
5424 new_fcport->scan_state = QLA_FCPORT_FOUND;
5426 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
5427 if (rval2 != QLA_SUCCESS) {
5428 ql_dbg(ql_dbg_disc, vha, 0x2097,
5429 "Failed to retrieve fcport information "
5430 "-- get_port_database=%x, loop_id=0x%04x.\n",
5431 rval2, new_fcport->loop_id);
5432 /* Skip retry if N2N */
5433 if (ha->current_topology != ISP_CFG_N) {
5434 ql_dbg(ql_dbg_disc, vha, 0x2105,
5435 "Scheduling resync.\n");
5436 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5441 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5442 /* Check for matching device in port list. */
5445 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5446 if (memcmp(new_fcport->port_name, fcport->port_name,
5450 fcport->flags &= ~FCF_FABRIC_DEVICE;
5451 fcport->loop_id = new_fcport->loop_id;
5452 fcport->port_type = new_fcport->port_type;
5453 fcport->d_id.b24 = new_fcport->d_id.b24;
5454 memcpy(fcport->node_name, new_fcport->node_name,
5456 fcport->scan_state = QLA_FCPORT_FOUND;
5457 if (fcport->login_retry == 0) {
5458 fcport->login_retry = vha->hw->login_retry_count;
5459 ql_dbg(ql_dbg_disc, vha, 0x2135,
5460 "Port login retry %8phN, lid 0x%04x retry cnt=%d.\n",
5461 fcport->port_name, fcport->loop_id,
5462 fcport->login_retry);
5469 /* New device, add to fcports list. */
5470 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5472 /* Allocate a new replacement fcport. */
5473 fcport = new_fcport;
5475 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5477 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5479 if (new_fcport == NULL) {
5480 ql_log(ql_log_warn, vha, 0xd031,
5481 "Failed to allocate memory for fcport.\n");
5482 rval = QLA_MEMORY_ALLOC_FAILED;
5485 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5486 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5489 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5491 /* Base iIDMA settings on HBA port speed. */
5492 fcport->fp_speed = ha->link_data_rate;
5497 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5498 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5501 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5502 if ((qla_dual_mode_enabled(vha) ||
5503 qla_ini_mode_enabled(vha)) &&
5504 atomic_read(&fcport->state) == FCS_ONLINE) {
5505 qla2x00_mark_device_lost(vha, fcport,
5506 ql2xplogiabsentdevice);
5507 if (fcport->loop_id != FC_NO_LOOP_ID &&
5508 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5509 fcport->port_type != FCT_INITIATOR &&
5510 fcport->port_type != FCT_BROADCAST) {
5511 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5512 "%s %d %8phC post del sess\n",
5516 qlt_schedule_sess_for_deletion(fcport);
5522 if (fcport->scan_state == QLA_FCPORT_FOUND)
5523 qla24xx_fcport_handle_login(vha, fcport);
5526 qla2x00_free_fcport(new_fcport);
5531 ql_dbg(ql_dbg_disc, vha, 0x2098,
5532 "Configure local loop error exit: rval=%x.\n", rval);
5537 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5540 uint16_t mb[MAILBOX_REGISTER_COUNT];
5541 struct qla_hw_data *ha = vha->hw;
5543 if (!IS_IIDMA_CAPABLE(ha))
5546 if (atomic_read(&fcport->state) != FCS_ONLINE)
5549 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
5550 fcport->fp_speed > ha->link_data_rate ||
5551 !ha->flags.gpsc_supported)
5554 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
5556 if (rval != QLA_SUCCESS) {
5557 ql_dbg(ql_dbg_disc, vha, 0x2004,
5558 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5559 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
5561 ql_dbg(ql_dbg_disc, vha, 0x2005,
5562 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5563 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
5564 fcport->fp_speed, fcport->port_name);
5568 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5570 qla2x00_iidma_fcport(vha, fcport);
5571 qla24xx_update_fcport_fcp_prio(vha, fcport);
5574 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5576 struct qla_work_evt *e;
5578 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
5580 return QLA_FUNCTION_FAILED;
5582 e->u.fcport.fcport = fcport;
5583 return qla2x00_post_work(vha, e);
5586 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5588 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
5590 struct fc_rport_identifiers rport_ids;
5591 struct fc_rport *rport;
5592 unsigned long flags;
5594 if (atomic_read(&fcport->state) == FCS_ONLINE)
5597 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5598 rport_ids.port_name = wwn_to_u64(fcport->port_name);
5599 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5600 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5601 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5602 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
5604 ql_log(ql_log_warn, vha, 0x2006,
5605 "Unable to allocate fc remote port.\n");
5609 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5610 *((fc_port_t **)rport->dd_data) = fcport;
5611 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5613 rport->supported_classes = fcport->supported_classes;
5615 rport_ids.roles = FC_PORT_ROLE_UNKNOWN;
5616 if (fcport->port_type == FCT_INITIATOR)
5617 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
5618 if (fcport->port_type == FCT_TARGET)
5619 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
5620 if (fcport->port_type & FCT_NVME_INITIATOR)
5621 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
5622 if (fcport->port_type & FCT_NVME_TARGET)
5623 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
5624 if (fcport->port_type & FCT_NVME_DISCOVERY)
5625 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
5627 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5628 "%s %8phN. rport %p is %s mode\n",
5629 __func__, fcport->port_name, rport,
5630 (fcport->port_type == FCT_TARGET) ? "tgt" :
5631 ((fcport->port_type & FCT_NVME) ? "nvme" : "ini"));
5633 fc_remote_port_rolechg(rport, rport_ids.roles);
5637 * qla2x00_update_fcport
5638 * Updates device on list.
5641 * ha = adapter block pointer.
5642 * fcport = port structure pointer.
5652 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5654 unsigned long flags;
5656 if (IS_SW_RESV_ADDR(fcport->d_id))
5659 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
5660 __func__, fcport->port_name);
5662 qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT);
5663 fcport->login_retry = vha->hw->login_retry_count;
5664 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5666 spin_lock_irqsave(&vha->work_lock, flags);
5667 fcport->deleted = 0;
5668 spin_unlock_irqrestore(&vha->work_lock, flags);
5670 if (vha->hw->current_topology == ISP_CFG_NL)
5671 fcport->logout_on_delete = 0;
5673 fcport->logout_on_delete = 1;
5674 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
5676 switch (vha->hw->current_topology) {
5679 fcport->keep_nport_handle = 1;
5685 qla2x00_iidma_fcport(vha, fcport);
5687 qla2x00_dfs_create_rport(vha, fcport);
5689 if (NVME_TARGET(vha->hw, fcport)) {
5690 qla_nvme_register_remote(vha, fcport);
5691 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
5692 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5696 qla24xx_update_fcport_fcp_prio(vha, fcport);
5698 switch (vha->host->active_mode) {
5699 case MODE_INITIATOR:
5700 qla2x00_reg_remote_port(vha, fcport);
5703 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5704 !vha->vha_tgt.qla_tgt->tgt_stopped)
5705 qlt_fc_port_added(vha, fcport);
5708 qla2x00_reg_remote_port(vha, fcport);
5709 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5710 !vha->vha_tgt.qla_tgt->tgt_stopped)
5711 qlt_fc_port_added(vha, fcport);
5717 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5719 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
5720 if (fcport->id_changed) {
5721 fcport->id_changed = 0;
5722 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5723 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5724 __func__, __LINE__, fcport->port_name,
5726 qla24xx_post_gfpnid_work(vha, fcport);
5728 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5729 "%s %d %8phC post gpsc fcp_cnt %d\n",
5730 __func__, __LINE__, fcport->port_name,
5732 qla24xx_post_gpsc_work(vha, fcport);
5736 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
5739 void qla_register_fcport_fn(struct work_struct *work)
5741 fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
5742 u32 rscn_gen = fcport->rscn_gen;
5745 if (IS_SW_RESV_ADDR(fcport->d_id))
5748 qla2x00_update_fcport(fcport->vha, fcport);
5750 if (rscn_gen != fcport->rscn_gen) {
5751 /* RSCN(s) came in while registration */
5752 switch (fcport->next_disc_state) {
5753 case DSC_DELETE_PEND:
5754 qlt_schedule_sess_for_deletion(fcport);
5757 data[0] = data[1] = 0;
5758 qla2x00_post_async_adisc_work(fcport->vha, fcport,
5768 * qla2x00_configure_fabric
5769 * Setup SNS devices with loop ID's.
5772 * ha = adapter block pointer.
5779 qla2x00_configure_fabric(scsi_qla_host_t *vha)
5783 uint16_t mb[MAILBOX_REGISTER_COUNT];
5785 LIST_HEAD(new_fcports);
5786 struct qla_hw_data *ha = vha->hw;
5789 /* If FL port exists, then SNS is present */
5790 if (IS_FWI2_CAPABLE(ha))
5791 loop_id = NPH_F_PORT;
5793 loop_id = SNS_FL_PORT;
5794 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
5795 if (rval != QLA_SUCCESS) {
5796 ql_dbg(ql_dbg_disc, vha, 0x20a0,
5797 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5799 vha->device_flags &= ~SWITCH_FOUND;
5800 return (QLA_SUCCESS);
5802 vha->device_flags |= SWITCH_FOUND;
5804 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_port_name, 0);
5805 if (rval != QLA_SUCCESS)
5806 ql_dbg(ql_dbg_disc, vha, 0x20ff,
5807 "Failed to get Fabric Port Name\n");
5809 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
5810 rval = qla2x00_send_change_request(vha, 0x3, 0);
5811 if (rval != QLA_SUCCESS)
5812 ql_log(ql_log_warn, vha, 0x121,
5813 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5818 qla2x00_mgmt_svr_login(vha);
5820 /* Ensure we are logged into the SNS. */
5821 loop_id = NPH_SNS_LID(ha);
5822 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5823 0xfc, mb, BIT_1|BIT_0);
5824 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5825 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5826 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5827 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
5828 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5833 if (ql2xfdmienable &&
5834 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5835 qla2x00_fdmi_register(vha);
5837 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5838 if (qla2x00_rft_id(vha)) {
5840 ql_dbg(ql_dbg_disc, vha, 0x20a2,
5841 "Register FC-4 TYPE failed.\n");
5842 if (test_bit(LOOP_RESYNC_NEEDED,
5846 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
5848 ql_dbg(ql_dbg_disc, vha, 0x209a,
5849 "Register FC-4 Features failed.\n");
5850 if (test_bit(LOOP_RESYNC_NEEDED,
5854 if (vha->flags.nvme_enabled) {
5855 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5856 ql_dbg(ql_dbg_disc, vha, 0x2049,
5857 "Register NVME FC Type Features failed.\n");
5860 if (qla2x00_rnn_id(vha)) {
5862 ql_dbg(ql_dbg_disc, vha, 0x2104,
5863 "Register Node Name failed.\n");
5864 if (test_bit(LOOP_RESYNC_NEEDED,
5867 } else if (qla2x00_rsnn_nn(vha)) {
5869 ql_dbg(ql_dbg_disc, vha, 0x209b,
5870 "Register Symbolic Node Name failed.\n");
5871 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5877 /* Mark the time right before querying FW for connected ports.
5878 * This process is long, asynchronous and by the time it's done,
5879 * collected information might not be accurate anymore. E.g.
5880 * disconnected port might have re-connected and a brand new
5881 * session has been created. In this case session's generation
5882 * will be newer than discovery_gen. */
5883 qlt_do_generation_tick(vha, &discovery_gen);
5885 if (USE_ASYNC_SCAN(ha)) {
5886 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
5889 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5891 list_for_each_entry(fcport, &vha->vp_fcports, list)
5892 fcport->scan_state = QLA_FCPORT_SCAN;
5894 rval = qla2x00_find_all_fabric_devs(vha);
5896 if (rval != QLA_SUCCESS)
5900 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5901 qla_nvme_register_hba(vha);
5904 ql_dbg(ql_dbg_disc, vha, 0x2068,
5905 "Configure fabric error exit rval=%d.\n", rval);
5911 * qla2x00_find_all_fabric_devs
5914 * ha = adapter block pointer.
5915 * dev = database device entry pointer.
5924 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
5928 fc_port_t *fcport, *new_fcport;
5933 int first_dev, last_dev;
5934 port_id_t wrap = {}, nxt_d_id;
5935 struct qla_hw_data *ha = vha->hw;
5936 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5937 unsigned long flags;
5941 /* Try GID_PT to get device list, else GAN. */
5943 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
5948 ql_dbg(ql_dbg_disc, vha, 0x209c,
5949 "GID_PT allocations failed, fallback on GA_NXT.\n");
5951 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
5952 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
5954 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5956 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
5958 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5960 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
5962 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5964 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5966 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5970 /* If other queries succeeded probe for FC-4 type */
5972 qla2x00_gff_id(vha, swl);
5973 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5979 /* Allocate temporary fcport for any new fcports discovered. */
5980 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5981 if (new_fcport == NULL) {
5982 ql_log(ql_log_warn, vha, 0x209d,
5983 "Failed to allocate memory for fcport.\n");
5984 return (QLA_MEMORY_ALLOC_FAILED);
5986 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5987 /* Set start port ID scan at adapter ID. */
5991 /* Starting free loop ID. */
5992 loop_id = ha->min_external_loopid;
5993 for (; loop_id <= ha->max_loop_id; loop_id++) {
5994 if (qla2x00_is_reserved_id(vha, loop_id))
5997 if (ha->current_topology == ISP_CFG_FL &&
5998 (atomic_read(&vha->loop_down_timer) ||
5999 LOOP_TRANSITION(vha))) {
6000 atomic_set(&vha->loop_down_timer, 0);
6001 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6002 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
6008 wrap.b24 = new_fcport->d_id.b24;
6010 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
6011 memcpy(new_fcport->node_name,
6012 swl[swl_idx].node_name, WWN_SIZE);
6013 memcpy(new_fcport->port_name,
6014 swl[swl_idx].port_name, WWN_SIZE);
6015 memcpy(new_fcport->fabric_port_name,
6016 swl[swl_idx].fabric_port_name, WWN_SIZE);
6017 new_fcport->fp_speed = swl[swl_idx].fp_speed;
6018 new_fcport->fc4_type = swl[swl_idx].fc4_type;
6020 new_fcport->nvme_flag = 0;
6021 if (vha->flags.nvme_enabled &&
6022 swl[swl_idx].fc4_type & FS_FC4TYPE_NVME) {
6023 ql_log(ql_log_info, vha, 0x2131,
6024 "FOUND: NVME port %8phC as FC Type 28h\n",
6025 new_fcport->port_name);
6028 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
6034 /* Send GA_NXT to the switch */
6035 rval = qla2x00_ga_nxt(vha, new_fcport);
6036 if (rval != QLA_SUCCESS) {
6037 ql_log(ql_log_warn, vha, 0x209e,
6038 "SNS scan failed -- assuming "
6039 "zero-entry result.\n");
6045 /* If wrap on switch device list, exit. */
6047 wrap.b24 = new_fcport->d_id.b24;
6049 } else if (new_fcport->d_id.b24 == wrap.b24) {
6050 ql_dbg(ql_dbg_disc, vha, 0x209f,
6051 "Device wrap (%02x%02x%02x).\n",
6052 new_fcport->d_id.b.domain,
6053 new_fcport->d_id.b.area,
6054 new_fcport->d_id.b.al_pa);
6058 /* Bypass if same physical adapter. */
6059 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
6062 /* Bypass virtual ports of the same host. */
6063 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
6066 /* Bypass if same domain and area of adapter. */
6067 if (((new_fcport->d_id.b24 & 0xffff00) ==
6068 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
6072 /* Bypass reserved domain fields. */
6073 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
6076 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
6077 if (ql2xgffidenable &&
6078 (!(new_fcport->fc4_type & FS_FC4TYPE_FCP) &&
6079 new_fcport->fc4_type != 0))
6082 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
6084 /* Locate matching device in database. */
6086 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6087 if (memcmp(new_fcport->port_name, fcport->port_name,
6091 fcport->scan_state = QLA_FCPORT_FOUND;
6095 /* Update port state. */
6096 memcpy(fcport->fabric_port_name,
6097 new_fcport->fabric_port_name, WWN_SIZE);
6098 fcport->fp_speed = new_fcport->fp_speed;
6101 * If address the same and state FCS_ONLINE
6102 * (or in target mode), nothing changed.
6104 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
6105 (atomic_read(&fcport->state) == FCS_ONLINE ||
6106 (vha->host->active_mode == MODE_TARGET))) {
6111 * If device was not a fabric device before.
6113 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
6114 fcport->d_id.b24 = new_fcport->d_id.b24;
6115 qla2x00_clear_loop_id(fcport);
6116 fcport->flags |= (FCF_FABRIC_DEVICE |
6122 * Port ID changed or device was marked to be updated;
6123 * Log it out if still logged in and mark it for
6126 if (qla_tgt_mode_enabled(base_vha)) {
6127 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
6128 "port changed FC ID, %8phC"
6129 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
6131 fcport->d_id.b.domain,
6132 fcport->d_id.b.area,
6133 fcport->d_id.b.al_pa,
6135 new_fcport->d_id.b.domain,
6136 new_fcport->d_id.b.area,
6137 new_fcport->d_id.b.al_pa);
6138 fcport->d_id.b24 = new_fcport->d_id.b24;
6142 fcport->d_id.b24 = new_fcport->d_id.b24;
6143 fcport->flags |= FCF_LOGIN_NEEDED;
6147 if (found && NVME_TARGET(vha->hw, fcport)) {
6148 if (fcport->disc_state == DSC_DELETE_PEND) {
6149 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
6150 vha->fcport_count--;
6151 fcport->login_succ = 0;
6156 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6159 /* If device was not in our fcports list, then add it. */
6160 new_fcport->scan_state = QLA_FCPORT_FOUND;
6161 list_add_tail(&new_fcport->list, &vha->vp_fcports);
6163 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6166 /* Allocate a new replacement fcport. */
6167 nxt_d_id.b24 = new_fcport->d_id.b24;
6168 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
6169 if (new_fcport == NULL) {
6170 ql_log(ql_log_warn, vha, 0xd032,
6171 "Memory allocation failed for fcport.\n");
6172 return (QLA_MEMORY_ALLOC_FAILED);
6174 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
6175 new_fcport->d_id.b24 = nxt_d_id.b24;
6178 qla2x00_free_fcport(new_fcport);
6181 * Logout all previous fabric dev marked lost, except FCP2 devices.
6183 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6184 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6187 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
6190 if (fcport->scan_state == QLA_FCPORT_SCAN) {
6191 if ((qla_dual_mode_enabled(vha) ||
6192 qla_ini_mode_enabled(vha)) &&
6193 atomic_read(&fcport->state) == FCS_ONLINE) {
6194 qla2x00_mark_device_lost(vha, fcport,
6195 ql2xplogiabsentdevice);
6196 if (fcport->loop_id != FC_NO_LOOP_ID &&
6197 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
6198 fcport->port_type != FCT_INITIATOR &&
6199 fcport->port_type != FCT_BROADCAST) {
6200 ql_dbg(ql_dbg_disc, vha, 0x20f0,
6201 "%s %d %8phC post del sess\n",
6204 qlt_schedule_sess_for_deletion(fcport);
6210 if (fcport->scan_state == QLA_FCPORT_FOUND &&
6211 (fcport->flags & FCF_LOGIN_NEEDED) != 0)
6212 qla24xx_fcport_handle_login(vha, fcport);
6217 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
6219 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
6221 int loop_id = FC_NO_LOOP_ID;
6222 int lid = NPH_MGMT_SERVER - vha->vp_idx;
6223 unsigned long flags;
6224 struct qla_hw_data *ha = vha->hw;
6226 if (vha->vp_idx == 0) {
6227 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
6228 return NPH_MGMT_SERVER;
6231 /* pick id from high and work down to low */
6232 spin_lock_irqsave(&ha->vport_slock, flags);
6233 for (; lid > 0; lid--) {
6234 if (!test_bit(lid, vha->hw->loop_id_map)) {
6235 set_bit(lid, vha->hw->loop_id_map);
6240 spin_unlock_irqrestore(&ha->vport_slock, flags);
6246 * qla2x00_fabric_login
6247 * Issue fabric login command.
6250 * ha = adapter block pointer.
6251 * device = pointer to FC device type structure.
6254 * 0 - Login successfully
6256 * 2 - Initiator device
6260 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
6261 uint16_t *next_loopid)
6265 uint16_t tmp_loopid;
6266 uint16_t mb[MAILBOX_REGISTER_COUNT];
6267 struct qla_hw_data *ha = vha->hw;
6273 ql_dbg(ql_dbg_disc, vha, 0x2000,
6274 "Trying Fabric Login w/loop id 0x%04x for port "
6276 fcport->loop_id, fcport->d_id.b.domain,
6277 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6279 /* Login fcport on switch. */
6280 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
6281 fcport->d_id.b.domain, fcport->d_id.b.area,
6282 fcport->d_id.b.al_pa, mb, BIT_0);
6283 if (rval != QLA_SUCCESS) {
6286 if (mb[0] == MBS_PORT_ID_USED) {
6288 * Device has another loop ID. The firmware team
6289 * recommends the driver perform an implicit login with
6290 * the specified ID again. The ID we just used is save
6291 * here so we return with an ID that can be tried by
6295 tmp_loopid = fcport->loop_id;
6296 fcport->loop_id = mb[1];
6298 ql_dbg(ql_dbg_disc, vha, 0x2001,
6299 "Fabric Login: port in use - next loop "
6300 "id=0x%04x, port id= %02x%02x%02x.\n",
6301 fcport->loop_id, fcport->d_id.b.domain,
6302 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6304 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
6309 /* A retry occurred before. */
6310 *next_loopid = tmp_loopid;
6313 * No retry occurred before. Just increment the
6314 * ID value for next login.
6316 *next_loopid = (fcport->loop_id + 1);
6319 if (mb[1] & BIT_0) {
6320 fcport->port_type = FCT_INITIATOR;
6322 fcport->port_type = FCT_TARGET;
6323 if (mb[1] & BIT_1) {
6324 fcport->flags |= FCF_FCP2_DEVICE;
6329 fcport->supported_classes |= FC_COS_CLASS2;
6331 fcport->supported_classes |= FC_COS_CLASS3;
6333 if (IS_FWI2_CAPABLE(ha)) {
6336 FCF_CONF_COMP_SUPPORTED;
6341 } else if (mb[0] == MBS_LOOP_ID_USED) {
6343 * Loop ID already used, try next loop ID.
6346 rval = qla2x00_find_new_loop_id(vha, fcport);
6347 if (rval != QLA_SUCCESS) {
6348 /* Ran out of loop IDs to use */
6351 } else if (mb[0] == MBS_COMMAND_ERROR) {
6353 * Firmware possibly timed out during login. If NO
6354 * retries are left to do then the device is declared
6357 *next_loopid = fcport->loop_id;
6358 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6359 fcport->d_id.b.domain, fcport->d_id.b.area,
6360 fcport->d_id.b.al_pa);
6361 qla2x00_mark_device_lost(vha, fcport, 1);
6367 * unrecoverable / not handled error
6369 ql_dbg(ql_dbg_disc, vha, 0x2002,
6370 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6371 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
6372 fcport->d_id.b.area, fcport->d_id.b.al_pa,
6373 fcport->loop_id, jiffies);
6375 *next_loopid = fcport->loop_id;
6376 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6377 fcport->d_id.b.domain, fcport->d_id.b.area,
6378 fcport->d_id.b.al_pa);
6379 qla2x00_clear_loop_id(fcport);
6380 fcport->login_retry = 0;
6391 * qla2x00_local_device_login
6392 * Issue local device login command.
6395 * ha = adapter block pointer.
6396 * loop_id = loop id of device to login to.
6398 * Returns (Where's the #define!!!!):
6399 * 0 - Login successfully
6404 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
6407 uint16_t mb[MAILBOX_REGISTER_COUNT];
6409 memset(mb, 0, sizeof(mb));
6410 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
6411 if (rval == QLA_SUCCESS) {
6412 /* Interrogate mailbox registers for any errors */
6413 if (mb[0] == MBS_COMMAND_ERROR)
6415 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
6416 /* device not in PCB table */
6424 * qla2x00_loop_resync
6425 * Resync with fibre channel devices.
6428 * ha = adapter block pointer.
6434 qla2x00_loop_resync(scsi_qla_host_t *vha)
6436 int rval = QLA_SUCCESS;
6439 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6440 if (vha->flags.online) {
6441 if (!(rval = qla2x00_fw_ready(vha))) {
6442 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6445 if (!IS_QLAFX00(vha->hw)) {
6447 * Issue a marker after FW becomes
6450 qla2x00_marker(vha, vha->hw->base_qpair,
6452 vha->marker_needed = 0;
6455 /* Remap devices on Loop. */
6456 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6458 if (IS_QLAFX00(vha->hw))
6459 qlafx00_configure_devices(vha);
6461 qla2x00_configure_loop(vha);
6464 } while (!atomic_read(&vha->loop_down_timer) &&
6465 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6466 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
6471 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6472 return (QLA_FUNCTION_FAILED);
6475 ql_dbg(ql_dbg_disc, vha, 0x206c,
6476 "%s *** FAILED ***.\n", __func__);
6482 * qla2x00_perform_loop_resync
6483 * Description: This function will set the appropriate flags and call
6484 * qla2x00_loop_resync. If successful loop will be resynced
6485 * Arguments : scsi_qla_host_t pointer
6486 * returm : Success or Failure
6489 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
6493 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
6494 /*Configure the flags so that resync happens properly*/
6495 atomic_set(&ha->loop_down_timer, 0);
6496 if (!(ha->device_flags & DFLG_NO_CABLE)) {
6497 atomic_set(&ha->loop_state, LOOP_UP);
6498 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
6499 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
6500 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
6502 rval = qla2x00_loop_resync(ha);
6504 atomic_set(&ha->loop_state, LOOP_DEAD);
6506 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
6513 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
6516 struct scsi_qla_host *vha;
6517 struct qla_hw_data *ha = base_vha->hw;
6518 unsigned long flags;
6520 spin_lock_irqsave(&ha->vport_slock, flags);
6521 /* Go with deferred removal of rport references. */
6522 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
6523 atomic_inc(&vha->vref_count);
6524 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6525 if (fcport->drport &&
6526 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
6527 spin_unlock_irqrestore(&ha->vport_slock, flags);
6528 qla2x00_rport_del(fcport);
6530 spin_lock_irqsave(&ha->vport_slock, flags);
6533 atomic_dec(&vha->vref_count);
6534 wake_up(&vha->vref_waitq);
6536 spin_unlock_irqrestore(&ha->vport_slock, flags);
6539 /* Assumes idc_lock always held on entry */
6541 qla83xx_reset_ownership(scsi_qla_host_t *vha)
6543 struct qla_hw_data *ha = vha->hw;
6544 uint32_t drv_presence, drv_presence_mask;
6545 uint32_t dev_part_info1, dev_part_info2, class_type;
6546 uint32_t class_type_mask = 0x3;
6547 uint16_t fcoe_other_function = 0xffff, i;
6549 if (IS_QLA8044(ha)) {
6550 drv_presence = qla8044_rd_direct(vha,
6551 QLA8044_CRB_DRV_ACTIVE_INDEX);
6552 dev_part_info1 = qla8044_rd_direct(vha,
6553 QLA8044_CRB_DEV_PART_INFO_INDEX);
6554 dev_part_info2 = qla8044_rd_direct(vha,
6555 QLA8044_CRB_DEV_PART_INFO2);
6557 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6558 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
6559 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
6561 for (i = 0; i < 8; i++) {
6562 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
6563 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6564 (i != ha->portnum)) {
6565 fcoe_other_function = i;
6569 if (fcoe_other_function == 0xffff) {
6570 for (i = 0; i < 8; i++) {
6571 class_type = ((dev_part_info2 >> (i * 4)) &
6573 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6574 ((i + 8) != ha->portnum)) {
6575 fcoe_other_function = i + 8;
6581 * Prepare drv-presence mask based on fcoe functions present.
6582 * However consider only valid physical fcoe function numbers (0-15).
6584 drv_presence_mask = ~((1 << (ha->portnum)) |
6585 ((fcoe_other_function == 0xffff) ?
6586 0 : (1 << (fcoe_other_function))));
6588 /* We are the reset owner iff:
6589 * - No other protocol drivers present.
6590 * - This is the lowest among fcoe functions. */
6591 if (!(drv_presence & drv_presence_mask) &&
6592 (ha->portnum < fcoe_other_function)) {
6593 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
6594 "This host is Reset owner.\n");
6595 ha->flags.nic_core_reset_owner = 1;
6600 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
6602 int rval = QLA_SUCCESS;
6603 struct qla_hw_data *ha = vha->hw;
6606 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6607 if (rval == QLA_SUCCESS) {
6608 drv_ack |= (1 << ha->portnum);
6609 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6616 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
6618 int rval = QLA_SUCCESS;
6619 struct qla_hw_data *ha = vha->hw;
6622 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6623 if (rval == QLA_SUCCESS) {
6624 drv_ack &= ~(1 << ha->portnum);
6625 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6632 qla83xx_dev_state_to_string(uint32_t dev_state)
6634 switch (dev_state) {
6635 case QLA8XXX_DEV_COLD:
6636 return "COLD/RE-INIT";
6637 case QLA8XXX_DEV_INITIALIZING:
6638 return "INITIALIZING";
6639 case QLA8XXX_DEV_READY:
6641 case QLA8XXX_DEV_NEED_RESET:
6642 return "NEED RESET";
6643 case QLA8XXX_DEV_NEED_QUIESCENT:
6644 return "NEED QUIESCENT";
6645 case QLA8XXX_DEV_FAILED:
6647 case QLA8XXX_DEV_QUIESCENT:
6654 /* Assumes idc-lock always held on entry */
6656 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6658 struct qla_hw_data *ha = vha->hw;
6659 uint32_t idc_audit_reg = 0, duration_secs = 0;
6661 switch (audit_type) {
6662 case IDC_AUDIT_TIMESTAMP:
6663 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6664 idc_audit_reg = (ha->portnum) |
6665 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6666 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6669 case IDC_AUDIT_COMPLETION:
6670 duration_secs = ((jiffies_to_msecs(jiffies) -
6671 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6672 idc_audit_reg = (ha->portnum) |
6673 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6674 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6678 ql_log(ql_log_warn, vha, 0xb078,
6679 "Invalid audit type specified.\n");
6684 /* Assumes idc_lock always held on entry */
6686 qla83xx_initiating_reset(scsi_qla_host_t *vha)
6688 struct qla_hw_data *ha = vha->hw;
6689 uint32_t idc_control, dev_state;
6691 __qla83xx_get_idc_control(vha, &idc_control);
6692 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6693 ql_log(ql_log_info, vha, 0xb080,
6694 "NIC Core reset has been disabled. idc-control=0x%x\n",
6696 return QLA_FUNCTION_FAILED;
6699 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6700 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6701 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6702 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6703 QLA8XXX_DEV_NEED_RESET);
6704 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6705 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6707 const char *state = qla83xx_dev_state_to_string(dev_state);
6709 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
6711 /* SV: XXX: Is timeout required here? */
6712 /* Wait for IDC state change READY -> NEED_RESET */
6713 while (dev_state == QLA8XXX_DEV_READY) {
6714 qla83xx_idc_unlock(vha, 0);
6716 qla83xx_idc_lock(vha, 0);
6717 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6721 /* Send IDC ack by writing to drv-ack register */
6722 __qla83xx_set_drv_ack(vha);
6728 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6730 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6734 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6736 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6740 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6742 uint32_t drv_presence = 0;
6743 struct qla_hw_data *ha = vha->hw;
6745 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6746 if (drv_presence & (1 << ha->portnum))
6749 return QLA_TEST_FAILED;
6753 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6755 int rval = QLA_SUCCESS;
6756 struct qla_hw_data *ha = vha->hw;
6758 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6759 "Entered %s().\n", __func__);
6761 if (vha->device_flags & DFLG_DEV_FAILED) {
6762 ql_log(ql_log_warn, vha, 0xb059,
6763 "Device in unrecoverable FAILED state.\n");
6764 return QLA_FUNCTION_FAILED;
6767 qla83xx_idc_lock(vha, 0);
6769 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6770 ql_log(ql_log_warn, vha, 0xb05a,
6771 "Function=0x%x has been removed from IDC participation.\n",
6773 rval = QLA_FUNCTION_FAILED;
6777 qla83xx_reset_ownership(vha);
6779 rval = qla83xx_initiating_reset(vha);
6782 * Perform reset if we are the reset-owner,
6783 * else wait till IDC state changes to READY/FAILED.
6785 if (rval == QLA_SUCCESS) {
6786 rval = qla83xx_idc_state_handler(vha);
6788 if (rval == QLA_SUCCESS)
6789 ha->flags.nic_core_hung = 0;
6790 __qla83xx_clear_drv_ack(vha);
6794 qla83xx_idc_unlock(vha, 0);
6796 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6802 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6804 struct qla_hw_data *ha = vha->hw;
6805 int rval = QLA_FUNCTION_FAILED;
6807 if (!IS_MCTP_CAPABLE(ha)) {
6808 /* This message can be removed from the final version */
6809 ql_log(ql_log_info, vha, 0x506d,
6810 "This board is not MCTP capable\n");
6814 if (!ha->mctp_dump) {
6815 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6816 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6818 if (!ha->mctp_dump) {
6819 ql_log(ql_log_warn, vha, 0x506e,
6820 "Failed to allocate memory for mctp dump\n");
6825 #define MCTP_DUMP_STR_ADDR 0x00000000
6826 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6827 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6828 if (rval != QLA_SUCCESS) {
6829 ql_log(ql_log_warn, vha, 0x506f,
6830 "Failed to capture mctp dump\n");
6832 ql_log(ql_log_info, vha, 0x5070,
6833 "Mctp dump capture for host (%ld/%p).\n",
6834 vha->host_no, ha->mctp_dump);
6835 ha->mctp_dumped = 1;
6838 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
6839 ha->flags.nic_core_reset_hdlr_active = 1;
6840 rval = qla83xx_restart_nic_firmware(vha);
6842 /* NIC Core reset failed. */
6843 ql_log(ql_log_warn, vha, 0x5071,
6844 "Failed to restart nic firmware\n");
6846 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6847 "Restarted NIC firmware successfully.\n");
6848 ha->flags.nic_core_reset_hdlr_active = 0;
6856 * qla2x00_quiesce_io
6857 * Description: This function will block the new I/Os
6858 * Its not aborting any I/Os as context
6859 * is not destroyed during quiescence
6860 * Arguments: scsi_qla_host_t
6864 qla2x00_quiesce_io(scsi_qla_host_t *vha)
6866 struct qla_hw_data *ha = vha->hw;
6867 struct scsi_qla_host *vp;
6869 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6870 "Quiescing I/O - ha=%p.\n", ha);
6872 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6873 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6874 atomic_set(&vha->loop_state, LOOP_DOWN);
6875 qla2x00_mark_all_devices_lost(vha);
6876 list_for_each_entry(vp, &ha->vp_list, list)
6877 qla2x00_mark_all_devices_lost(vp);
6879 if (!atomic_read(&vha->loop_down_timer))
6880 atomic_set(&vha->loop_down_timer,
6883 /* Wait for pending cmds to complete */
6884 WARN_ON_ONCE(qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST)
6889 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6891 struct qla_hw_data *ha = vha->hw;
6892 struct scsi_qla_host *vp;
6893 unsigned long flags;
6897 /* For ISP82XX, driver waits for completion of the commands.
6898 * online flag should be set.
6900 if (!(IS_P3P_TYPE(ha)))
6901 vha->flags.online = 0;
6902 ha->flags.chip_reset_done = 0;
6903 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6904 vha->qla_stats.total_isp_aborts++;
6906 ql_log(ql_log_info, vha, 0x00af,
6907 "Performing ISP error recovery - ha=%p.\n", ha);
6909 ha->flags.purge_mbox = 1;
6910 /* For ISP82XX, reset_chip is just disabling interrupts.
6911 * Driver waits for the completion of the commands.
6912 * the interrupts need to be enabled.
6914 if (!(IS_P3P_TYPE(ha)))
6915 ha->isp_ops->reset_chip(vha);
6917 ha->link_data_rate = PORT_SPEED_UNKNOWN;
6919 ha->flags.rida_fmt2 = 0;
6920 ha->flags.n2n_ae = 0;
6921 ha->flags.lip_ae = 0;
6922 ha->current_topology = 0;
6924 ha->flags.fw_init_done = 0;
6926 ha->base_qpair->chip_reset = ha->chip_reset;
6927 for (i = 0; i < ha->max_qpairs; i++) {
6928 if (ha->queue_pair_map[i])
6929 ha->queue_pair_map[i]->chip_reset =
6930 ha->base_qpair->chip_reset;
6933 /* purge MBox commands */
6934 spin_lock_irqsave(&ha->hardware_lock, flags);
6935 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags)) {
6936 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
6937 complete(&ha->mbx_intr_comp);
6939 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6942 while (atomic_read(&ha->num_pend_mbx_stage2) ||
6943 atomic_read(&ha->num_pend_mbx_stage1)) {
6949 ha->flags.purge_mbox = 0;
6951 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6952 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6953 atomic_set(&vha->loop_state, LOOP_DOWN);
6954 qla2x00_mark_all_devices_lost(vha);
6956 spin_lock_irqsave(&ha->vport_slock, flags);
6957 list_for_each_entry(vp, &ha->vp_list, list) {
6958 atomic_inc(&vp->vref_count);
6959 spin_unlock_irqrestore(&ha->vport_slock, flags);
6961 qla2x00_mark_all_devices_lost(vp);
6963 spin_lock_irqsave(&ha->vport_slock, flags);
6964 atomic_dec(&vp->vref_count);
6966 spin_unlock_irqrestore(&ha->vport_slock, flags);
6968 if (!atomic_read(&vha->loop_down_timer))
6969 atomic_set(&vha->loop_down_timer,
6973 /* Clear all async request states across all VPs. */
6974 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6975 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6976 fcport->scan_state = 0;
6978 spin_lock_irqsave(&ha->vport_slock, flags);
6979 list_for_each_entry(vp, &ha->vp_list, list) {
6980 atomic_inc(&vp->vref_count);
6981 spin_unlock_irqrestore(&ha->vport_slock, flags);
6983 list_for_each_entry(fcport, &vp->vp_fcports, list)
6984 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6986 spin_lock_irqsave(&ha->vport_slock, flags);
6987 atomic_dec(&vp->vref_count);
6989 spin_unlock_irqrestore(&ha->vport_slock, flags);
6991 /* Make sure for ISP 82XX IO DMA is complete */
6992 if (IS_P3P_TYPE(ha)) {
6993 qla82xx_chip_reset_cleanup(vha);
6994 ql_log(ql_log_info, vha, 0x00b4,
6995 "Done chip reset cleanup.\n");
6997 /* Done waiting for pending commands. Reset online flag */
6998 vha->flags.online = 0;
7001 /* Requeue all commands in outstanding command list. */
7002 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
7003 /* memory barrier */
7009 * Resets ISP and aborts all outstanding commands.
7012 * ha = adapter block pointer.
7018 qla2x00_abort_isp(scsi_qla_host_t *vha)
7021 struct qla_hw_data *ha = vha->hw;
7022 struct scsi_qla_host *vp;
7023 struct req_que *req = ha->req_q_map[0];
7024 unsigned long flags;
7026 if (vha->flags.online) {
7027 qla2x00_abort_isp_cleanup(vha);
7029 if (qla2x00_isp_reg_stat(ha)) {
7030 ql_log(ql_log_info, vha, 0x803f,
7031 "ISP Abort - ISP reg disconnect, exiting.\n");
7035 if (test_and_clear_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags)) {
7036 ha->flags.chip_reset_done = 1;
7037 vha->flags.online = 1;
7039 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7043 if (IS_QLA8031(ha)) {
7044 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
7045 "Clearing fcoe driver presence.\n");
7046 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
7047 ql_dbg(ql_dbg_p3p, vha, 0xb073,
7048 "Error while clearing DRV-Presence.\n");
7051 if (unlikely(pci_channel_offline(ha->pdev) &&
7052 ha->flags.pci_channel_io_perm_failure)) {
7053 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7058 switch (vha->qlini_mode) {
7059 case QLA2XXX_INI_MODE_DISABLED:
7060 if (!qla_tgt_mode_enabled(vha))
7063 case QLA2XXX_INI_MODE_DUAL:
7064 if (!qla_dual_mode_enabled(vha) &&
7065 !qla_ini_mode_enabled(vha))
7068 case QLA2XXX_INI_MODE_ENABLED:
7073 ha->isp_ops->get_flash_version(vha, req->ring);
7075 if (qla2x00_isp_reg_stat(ha)) {
7076 ql_log(ql_log_info, vha, 0x803f,
7077 "ISP Abort - ISP reg disconnect pre nvram config, exiting.\n");
7080 ha->isp_ops->nvram_config(vha);
7082 if (qla2x00_isp_reg_stat(ha)) {
7083 ql_log(ql_log_info, vha, 0x803f,
7084 "ISP Abort - ISP reg disconnect post nvmram config, exiting.\n");
7087 if (!qla2x00_restart_isp(vha)) {
7088 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7090 if (!atomic_read(&vha->loop_down_timer)) {
7092 * Issue marker command only when we are going
7093 * to start the I/O .
7095 vha->marker_needed = 1;
7098 vha->flags.online = 1;
7100 ha->isp_ops->enable_intrs(ha);
7102 ha->isp_abort_cnt = 0;
7103 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7105 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
7106 qla2x00_get_fw_version(vha);
7108 } else { /* failed the ISP abort */
7109 vha->flags.online = 1;
7110 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
7111 if (ha->isp_abort_cnt == 0) {
7112 ql_log(ql_log_fatal, vha, 0x8035,
7113 "ISP error recover failed - "
7114 "board disabled.\n");
7116 * The next call disables the board
7119 qla2x00_abort_isp_cleanup(vha);
7120 vha->flags.online = 0;
7121 clear_bit(ISP_ABORT_RETRY,
7124 } else { /* schedule another ISP abort */
7125 ha->isp_abort_cnt--;
7126 ql_dbg(ql_dbg_taskm, vha, 0x8020,
7127 "ISP abort - retry remaining %d.\n",
7132 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
7133 ql_dbg(ql_dbg_taskm, vha, 0x8021,
7134 "ISP error recovery - retrying (%d) "
7135 "more times.\n", ha->isp_abort_cnt);
7136 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7144 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
7145 qla2x00_configure_hba(vha);
7146 spin_lock_irqsave(&ha->vport_slock, flags);
7147 list_for_each_entry(vp, &ha->vp_list, list) {
7149 atomic_inc(&vp->vref_count);
7150 spin_unlock_irqrestore(&ha->vport_slock, flags);
7152 qla2x00_vp_abort_isp(vp);
7154 spin_lock_irqsave(&ha->vport_slock, flags);
7155 atomic_dec(&vp->vref_count);
7158 spin_unlock_irqrestore(&ha->vport_slock, flags);
7160 if (IS_QLA8031(ha)) {
7161 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
7162 "Setting back fcoe driver presence.\n");
7163 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
7164 ql_dbg(ql_dbg_p3p, vha, 0xb074,
7165 "Error while setting DRV-Presence.\n");
7168 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
7176 * qla2x00_restart_isp
7177 * restarts the ISP after a reset
7180 * ha = adapter block pointer.
7186 qla2x00_restart_isp(scsi_qla_host_t *vha)
7189 struct qla_hw_data *ha = vha->hw;
7191 /* If firmware needs to be loaded */
7192 if (qla2x00_isp_firmware(vha)) {
7193 vha->flags.online = 0;
7194 status = ha->isp_ops->chip_diag(vha);
7197 status = qla2x00_setup_chip(vha);
7202 status = qla2x00_init_rings(vha);
7206 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7207 ha->flags.chip_reset_done = 1;
7209 /* Initialize the queues in use */
7210 qla25xx_init_queues(ha);
7212 status = qla2x00_fw_ready(vha);
7214 /* if no cable then assume it's good */
7215 return vha->device_flags & DFLG_NO_CABLE ? 0 : status;
7218 /* Issue a marker after FW becomes ready. */
7219 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
7220 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7226 qla25xx_init_queues(struct qla_hw_data *ha)
7228 struct rsp_que *rsp = NULL;
7229 struct req_que *req = NULL;
7230 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7234 for (i = 1; i < ha->max_rsp_queues; i++) {
7235 rsp = ha->rsp_q_map[i];
7236 if (rsp && test_bit(i, ha->rsp_qid_map)) {
7237 rsp->options &= ~BIT_0;
7238 ret = qla25xx_init_rsp_que(base_vha, rsp);
7239 if (ret != QLA_SUCCESS)
7240 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
7241 "%s Rsp que: %d init failed.\n",
7244 ql_dbg(ql_dbg_init, base_vha, 0x0100,
7245 "%s Rsp que: %d inited.\n",
7249 for (i = 1; i < ha->max_req_queues; i++) {
7250 req = ha->req_q_map[i];
7251 if (req && test_bit(i, ha->req_qid_map)) {
7252 /* Clear outstanding commands array. */
7253 req->options &= ~BIT_0;
7254 ret = qla25xx_init_req_que(base_vha, req);
7255 if (ret != QLA_SUCCESS)
7256 ql_dbg(ql_dbg_init, base_vha, 0x0101,
7257 "%s Req que: %d init failed.\n",
7260 ql_dbg(ql_dbg_init, base_vha, 0x0102,
7261 "%s Req que: %d inited.\n",
7269 * qla2x00_reset_adapter
7273 * ha = adapter block pointer.
7276 qla2x00_reset_adapter(scsi_qla_host_t *vha)
7278 unsigned long flags = 0;
7279 struct qla_hw_data *ha = vha->hw;
7280 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7282 vha->flags.online = 0;
7283 ha->isp_ops->disable_intrs(ha);
7285 spin_lock_irqsave(&ha->hardware_lock, flags);
7286 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
7287 rd_reg_word(®->hccr); /* PCI Posting. */
7288 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
7289 rd_reg_word(®->hccr); /* PCI Posting. */
7290 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7296 qla24xx_reset_adapter(scsi_qla_host_t *vha)
7298 unsigned long flags = 0;
7299 struct qla_hw_data *ha = vha->hw;
7300 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
7302 if (IS_P3P_TYPE(ha))
7305 vha->flags.online = 0;
7306 ha->isp_ops->disable_intrs(ha);
7308 spin_lock_irqsave(&ha->hardware_lock, flags);
7309 wrt_reg_dword(®->hccr, HCCRX_SET_RISC_RESET);
7310 rd_reg_dword(®->hccr);
7311 wrt_reg_dword(®->hccr, HCCRX_REL_RISC_PAUSE);
7312 rd_reg_dword(®->hccr);
7313 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7315 if (IS_NOPOLLING_TYPE(ha))
7316 ha->isp_ops->enable_intrs(ha);
7321 /* On sparc systems, obtain port and node WWN from firmware
7324 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
7325 struct nvram_24xx *nv)
7328 struct qla_hw_data *ha = vha->hw;
7329 struct pci_dev *pdev = ha->pdev;
7330 struct device_node *dp = pci_device_to_OF_node(pdev);
7334 val = of_get_property(dp, "port-wwn", &len);
7335 if (val && len >= WWN_SIZE)
7336 memcpy(nv->port_name, val, WWN_SIZE);
7338 val = of_get_property(dp, "node-wwn", &len);
7339 if (val && len >= WWN_SIZE)
7340 memcpy(nv->node_name, val, WWN_SIZE);
7345 qla24xx_nvram_config(scsi_qla_host_t *vha)
7348 struct init_cb_24xx *icb;
7349 struct nvram_24xx *nv;
7351 uint8_t *dptr1, *dptr2;
7354 struct qla_hw_data *ha = vha->hw;
7357 icb = (struct init_cb_24xx *)ha->init_cb;
7360 /* Determine NVRAM starting address. */
7361 if (ha->port_no == 0) {
7362 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
7363 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
7365 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
7366 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
7369 ha->nvram_size = sizeof(*nv);
7370 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7372 /* Get VPD data into cache */
7373 ha->vpd = ha->nvram + VPD_OFFSET;
7374 ha->isp_ops->read_nvram(vha, ha->vpd,
7375 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
7377 /* Get NVRAM data into cache and calculate checksum. */
7378 dptr = (__force __le32 *)nv;
7379 ha->isp_ops->read_nvram(vha, dptr, ha->nvram_base, ha->nvram_size);
7380 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7381 chksum += le32_to_cpu(*dptr);
7383 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
7384 "Contents of NVRAM\n");
7385 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
7386 nv, ha->nvram_size);
7388 /* Bad NVRAM data, set defaults parameters. */
7389 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
7390 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
7391 /* Reset NVRAM data. */
7392 ql_log(ql_log_warn, vha, 0x006b,
7393 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
7394 chksum, nv->id, nv->nvram_version);
7395 ql_dump_buffer(ql_dbg_init, vha, 0x006b, nv, sizeof(*nv));
7396 ql_log(ql_log_warn, vha, 0x006c,
7397 "Falling back to functioning (yet invalid -- WWPN) "
7401 * Set default initialization control block.
7403 memset(nv, 0, ha->nvram_size);
7404 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7405 nv->version = cpu_to_le16(ICB_VERSION);
7406 nv->frame_payload_size = cpu_to_le16(2048);
7407 nv->execution_throttle = cpu_to_le16(0xFFFF);
7408 nv->exchange_count = cpu_to_le16(0);
7409 nv->hard_address = cpu_to_le16(124);
7410 nv->port_name[0] = 0x21;
7411 nv->port_name[1] = 0x00 + ha->port_no + 1;
7412 nv->port_name[2] = 0x00;
7413 nv->port_name[3] = 0xe0;
7414 nv->port_name[4] = 0x8b;
7415 nv->port_name[5] = 0x1c;
7416 nv->port_name[6] = 0x55;
7417 nv->port_name[7] = 0x86;
7418 nv->node_name[0] = 0x20;
7419 nv->node_name[1] = 0x00;
7420 nv->node_name[2] = 0x00;
7421 nv->node_name[3] = 0xe0;
7422 nv->node_name[4] = 0x8b;
7423 nv->node_name[5] = 0x1c;
7424 nv->node_name[6] = 0x55;
7425 nv->node_name[7] = 0x86;
7426 qla24xx_nvram_wwn_from_ofw(vha, nv);
7427 nv->login_retry_count = cpu_to_le16(8);
7428 nv->interrupt_delay_timer = cpu_to_le16(0);
7429 nv->login_timeout = cpu_to_le16(0);
7430 nv->firmware_options_1 =
7431 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7432 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7433 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7434 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7435 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7436 nv->efi_parameters = cpu_to_le32(0);
7437 nv->reset_delay = 5;
7438 nv->max_luns_per_target = cpu_to_le16(128);
7439 nv->port_down_retry_count = cpu_to_le16(30);
7440 nv->link_down_timeout = cpu_to_le16(30);
7445 if (qla_tgt_mode_enabled(vha)) {
7446 /* Don't enable full login after initial LIP */
7447 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7448 /* Don't enable LIP full login for initiator */
7449 nv->host_p &= cpu_to_le32(~BIT_10);
7452 qlt_24xx_config_nvram_stage1(vha, nv);
7454 /* Reset Initialization control block */
7455 memset(icb, 0, ha->init_cb_size);
7457 /* Copy 1st segment. */
7458 dptr1 = (uint8_t *)icb;
7459 dptr2 = (uint8_t *)&nv->version;
7460 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7462 *dptr1++ = *dptr2++;
7464 icb->login_retry_count = nv->login_retry_count;
7465 icb->link_down_on_nos = nv->link_down_on_nos;
7467 /* Copy 2nd segment. */
7468 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7469 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7470 cnt = (uint8_t *)&icb->reserved_3 -
7471 (uint8_t *)&icb->interrupt_delay_timer;
7473 *dptr1++ = *dptr2++;
7474 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
7476 * Setup driver NVRAM options.
7478 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7481 qlt_24xx_config_nvram_stage2(vha, icb);
7483 if (nv->host_p & cpu_to_le32(BIT_15)) {
7484 /* Use alternate WWN? */
7485 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7486 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7489 /* Prepare nodename */
7490 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7492 * Firmware will apply the following mask if the nodename was
7495 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7496 icb->node_name[0] &= 0xF0;
7499 /* Set host adapter parameters. */
7500 ha->flags.disable_risc_code_load = 0;
7501 ha->flags.enable_lip_reset = 0;
7502 ha->flags.enable_lip_full_login =
7503 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
7504 ha->flags.enable_target_reset =
7505 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
7506 ha->flags.enable_led_scheme = 0;
7507 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
7509 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7510 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7512 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
7513 sizeof(ha->fw_seriallink_options24));
7515 /* save HBA serial number */
7516 ha->serial0 = icb->port_name[5];
7517 ha->serial1 = icb->port_name[6];
7518 ha->serial2 = icb->port_name[7];
7519 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7520 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7522 icb->execution_throttle = cpu_to_le16(0xFFFF);
7524 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7526 /* Set minimum login_timeout to 4 seconds. */
7527 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7528 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7529 if (le16_to_cpu(nv->login_timeout) < 4)
7530 nv->login_timeout = cpu_to_le16(4);
7531 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7533 /* Set minimum RATOV to 100 tenths of a second. */
7536 ha->loop_reset_delay = nv->reset_delay;
7538 /* Link Down Timeout = 0:
7540 * When Port Down timer expires we will start returning
7541 * I/O's to OS with "DID_NO_CONNECT".
7543 * Link Down Timeout != 0:
7545 * The driver waits for the link to come up after link down
7546 * before returning I/Os to OS with "DID_NO_CONNECT".
7548 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7549 ha->loop_down_abort_time =
7550 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7552 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7553 ha->loop_down_abort_time =
7554 (LOOP_DOWN_TIME - ha->link_down_timeout);
7557 /* Need enough time to try and get the port back. */
7558 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7559 if (qlport_down_retry)
7560 ha->port_down_retry_count = qlport_down_retry;
7562 /* Set login_retry_count */
7563 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7564 if (ha->port_down_retry_count ==
7565 le16_to_cpu(nv->port_down_retry_count) &&
7566 ha->port_down_retry_count > 3)
7567 ha->login_retry_count = ha->port_down_retry_count;
7568 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7569 ha->login_retry_count = ha->port_down_retry_count;
7570 if (ql2xloginretrycount)
7571 ha->login_retry_count = ql2xloginretrycount;
7573 /* N2N: driver will initiate Login instead of FW */
7574 icb->firmware_options_3 |= cpu_to_le32(BIT_8);
7577 if (!vha->flags.init_done) {
7578 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7579 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7580 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7581 le16_to_cpu(icb->interrupt_delay_timer) : 2;
7583 icb->firmware_options_2 &= cpu_to_le32(
7584 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7585 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7586 ha->zio_mode = QLA_ZIO_MODE_6;
7588 ql_log(ql_log_info, vha, 0x006f,
7589 "ZIO mode %d enabled; timer delay (%d us).\n",
7590 ha->zio_mode, ha->zio_timer * 100);
7592 icb->firmware_options_2 |= cpu_to_le32(
7593 (uint32_t)ha->zio_mode);
7594 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7598 ql_log(ql_log_warn, vha, 0x0070,
7599 "NVRAM configuration failed.\n");
7605 qla27xx_print_image(struct scsi_qla_host *vha, char *name,
7606 struct qla27xx_image_status *image_status)
7608 ql_dbg(ql_dbg_init, vha, 0x018b,
7609 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
7611 image_status->image_status_mask,
7612 le16_to_cpu(image_status->generation),
7613 image_status->ver_major,
7614 image_status->ver_minor,
7615 image_status->bitmap,
7616 le32_to_cpu(image_status->checksum),
7617 le32_to_cpu(image_status->signature));
7621 qla28xx_check_aux_image_status_signature(
7622 struct qla27xx_image_status *image_status)
7624 ulong signature = le32_to_cpu(image_status->signature);
7626 return signature != QLA28XX_AUX_IMG_STATUS_SIGN;
7630 qla27xx_check_image_status_signature(struct qla27xx_image_status *image_status)
7632 ulong signature = le32_to_cpu(image_status->signature);
7635 signature != QLA27XX_IMG_STATUS_SIGN &&
7636 signature != QLA28XX_IMG_STATUS_SIGN;
7640 qla27xx_image_status_checksum(struct qla27xx_image_status *image_status)
7642 __le32 *p = (__force __le32 *)image_status;
7643 uint n = sizeof(*image_status) / sizeof(*p);
7647 sum += le32_to_cpup(p);
7653 qla28xx_component_bitmask(struct qla27xx_image_status *aux, uint bitmask)
7655 return aux->bitmap & bitmask ?
7656 QLA27XX_SECONDARY_IMAGE : QLA27XX_PRIMARY_IMAGE;
7660 qla28xx_component_status(
7661 struct active_regions *active_regions, struct qla27xx_image_status *aux)
7663 active_regions->aux.board_config =
7664 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_BOARD_CONFIG);
7666 active_regions->aux.vpd_nvram =
7667 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_VPD_NVRAM);
7669 active_regions->aux.npiv_config_0_1 =
7670 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1);
7672 active_regions->aux.npiv_config_2_3 =
7673 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3);
7677 qla27xx_compare_image_generation(
7678 struct qla27xx_image_status *pri_image_status,
7679 struct qla27xx_image_status *sec_image_status)
7681 /* calculate generation delta as uint16 (this accounts for wrap) */
7683 le16_to_cpu(pri_image_status->generation) -
7684 le16_to_cpu(sec_image_status->generation);
7686 ql_dbg(ql_dbg_init, NULL, 0x0180, "generation delta = %d\n", delta);
7692 qla28xx_get_aux_images(
7693 struct scsi_qla_host *vha, struct active_regions *active_regions)
7695 struct qla_hw_data *ha = vha->hw;
7696 struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
7697 bool valid_pri_image = false, valid_sec_image = false;
7698 bool active_pri_image = false, active_sec_image = false;
7700 if (!ha->flt_region_aux_img_status_pri) {
7701 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
7702 goto check_sec_image;
7705 qla24xx_read_flash_data(vha, (uint32_t *)&pri_aux_image_status,
7706 ha->flt_region_aux_img_status_pri,
7707 sizeof(pri_aux_image_status) >> 2);
7708 qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
7710 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
7711 ql_dbg(ql_dbg_init, vha, 0x018b,
7712 "Primary aux image signature (%#x) not valid\n",
7713 le32_to_cpu(pri_aux_image_status.signature));
7714 goto check_sec_image;
7717 if (qla27xx_image_status_checksum(&pri_aux_image_status)) {
7718 ql_dbg(ql_dbg_init, vha, 0x018c,
7719 "Primary aux image checksum failed\n");
7720 goto check_sec_image;
7723 valid_pri_image = true;
7725 if (pri_aux_image_status.image_status_mask & 1) {
7726 ql_dbg(ql_dbg_init, vha, 0x018d,
7727 "Primary aux image is active\n");
7728 active_pri_image = true;
7732 if (!ha->flt_region_aux_img_status_sec) {
7733 ql_dbg(ql_dbg_init, vha, 0x018a,
7734 "Secondary aux image not addressed\n");
7735 goto check_valid_image;
7738 qla24xx_read_flash_data(vha, (uint32_t *)&sec_aux_image_status,
7739 ha->flt_region_aux_img_status_sec,
7740 sizeof(sec_aux_image_status) >> 2);
7741 qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
7743 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
7744 ql_dbg(ql_dbg_init, vha, 0x018b,
7745 "Secondary aux image signature (%#x) not valid\n",
7746 le32_to_cpu(sec_aux_image_status.signature));
7747 goto check_valid_image;
7750 if (qla27xx_image_status_checksum(&sec_aux_image_status)) {
7751 ql_dbg(ql_dbg_init, vha, 0x018c,
7752 "Secondary aux image checksum failed\n");
7753 goto check_valid_image;
7756 valid_sec_image = true;
7758 if (sec_aux_image_status.image_status_mask & 1) {
7759 ql_dbg(ql_dbg_init, vha, 0x018d,
7760 "Secondary aux image is active\n");
7761 active_sec_image = true;
7765 if (valid_pri_image && active_pri_image &&
7766 valid_sec_image && active_sec_image) {
7767 if (qla27xx_compare_image_generation(&pri_aux_image_status,
7768 &sec_aux_image_status) >= 0) {
7769 qla28xx_component_status(active_regions,
7770 &pri_aux_image_status);
7772 qla28xx_component_status(active_regions,
7773 &sec_aux_image_status);
7775 } else if (valid_pri_image && active_pri_image) {
7776 qla28xx_component_status(active_regions, &pri_aux_image_status);
7777 } else if (valid_sec_image && active_sec_image) {
7778 qla28xx_component_status(active_regions, &sec_aux_image_status);
7781 ql_dbg(ql_dbg_init, vha, 0x018f,
7782 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u\n",
7783 active_regions->aux.board_config,
7784 active_regions->aux.vpd_nvram,
7785 active_regions->aux.npiv_config_0_1,
7786 active_regions->aux.npiv_config_2_3);
7790 qla27xx_get_active_image(struct scsi_qla_host *vha,
7791 struct active_regions *active_regions)
7793 struct qla_hw_data *ha = vha->hw;
7794 struct qla27xx_image_status pri_image_status, sec_image_status;
7795 bool valid_pri_image = false, valid_sec_image = false;
7796 bool active_pri_image = false, active_sec_image = false;
7798 if (!ha->flt_region_img_status_pri) {
7799 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
7800 goto check_sec_image;
7803 if (qla24xx_read_flash_data(vha, (uint32_t *)&pri_image_status,
7804 ha->flt_region_img_status_pri, sizeof(pri_image_status) >> 2) !=
7807 goto check_sec_image;
7809 qla27xx_print_image(vha, "Primary image", &pri_image_status);
7811 if (qla27xx_check_image_status_signature(&pri_image_status)) {
7812 ql_dbg(ql_dbg_init, vha, 0x018b,
7813 "Primary image signature (%#x) not valid\n",
7814 le32_to_cpu(pri_image_status.signature));
7815 goto check_sec_image;
7818 if (qla27xx_image_status_checksum(&pri_image_status)) {
7819 ql_dbg(ql_dbg_init, vha, 0x018c,
7820 "Primary image checksum failed\n");
7821 goto check_sec_image;
7824 valid_pri_image = true;
7826 if (pri_image_status.image_status_mask & 1) {
7827 ql_dbg(ql_dbg_init, vha, 0x018d,
7828 "Primary image is active\n");
7829 active_pri_image = true;
7833 if (!ha->flt_region_img_status_sec) {
7834 ql_dbg(ql_dbg_init, vha, 0x018a, "Secondary image not addressed\n");
7835 goto check_valid_image;
7838 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
7839 ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
7840 qla27xx_print_image(vha, "Secondary image", &sec_image_status);
7842 if (qla27xx_check_image_status_signature(&sec_image_status)) {
7843 ql_dbg(ql_dbg_init, vha, 0x018b,
7844 "Secondary image signature (%#x) not valid\n",
7845 le32_to_cpu(sec_image_status.signature));
7846 goto check_valid_image;
7849 if (qla27xx_image_status_checksum(&sec_image_status)) {
7850 ql_dbg(ql_dbg_init, vha, 0x018c,
7851 "Secondary image checksum failed\n");
7852 goto check_valid_image;
7855 valid_sec_image = true;
7857 if (sec_image_status.image_status_mask & 1) {
7858 ql_dbg(ql_dbg_init, vha, 0x018d,
7859 "Secondary image is active\n");
7860 active_sec_image = true;
7864 if (valid_pri_image && active_pri_image)
7865 active_regions->global = QLA27XX_PRIMARY_IMAGE;
7867 if (valid_sec_image && active_sec_image) {
7868 if (!active_regions->global ||
7869 qla27xx_compare_image_generation(
7870 &pri_image_status, &sec_image_status) < 0) {
7871 active_regions->global = QLA27XX_SECONDARY_IMAGE;
7875 ql_dbg(ql_dbg_init, vha, 0x018f, "active image %s (%u)\n",
7876 active_regions->global == QLA27XX_DEFAULT_IMAGE ?
7877 "default (boot/fw)" :
7878 active_regions->global == QLA27XX_PRIMARY_IMAGE ?
7880 active_regions->global == QLA27XX_SECONDARY_IMAGE ?
7881 "secondary" : "invalid",
7882 active_regions->global);
7885 bool qla24xx_risc_firmware_invalid(uint32_t *dword)
7888 !(dword[4] | dword[5] | dword[6] | dword[7]) ||
7889 !(~dword[4] | ~dword[5] | ~dword[6] | ~dword[7]);
7893 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
7897 uint templates, segments, fragment;
7902 uint32_t risc_addr, risc_size, risc_attr = 0;
7903 struct qla_hw_data *ha = vha->hw;
7904 struct req_que *req = ha->req_q_map[0];
7905 struct fwdt *fwdt = ha->fwdt;
7907 ql_dbg(ql_dbg_init, vha, 0x008b,
7908 "FW: Loading firmware from flash (%x).\n", faddr);
7910 dcode = (uint32_t *)req->ring;
7911 qla24xx_read_flash_data(vha, dcode, faddr, 8);
7912 if (qla24xx_risc_firmware_invalid(dcode)) {
7913 ql_log(ql_log_fatal, vha, 0x008c,
7914 "Unable to verify the integrity of flash firmware "
7916 ql_log(ql_log_fatal, vha, 0x008d,
7917 "Firmware data: %08x %08x %08x %08x.\n",
7918 dcode[0], dcode[1], dcode[2], dcode[3]);
7920 return QLA_FUNCTION_FAILED;
7923 dcode = (uint32_t *)req->ring;
7925 segments = FA_RISC_CODE_SEGMENTS;
7926 for (j = 0; j < segments; j++) {
7927 ql_dbg(ql_dbg_init, vha, 0x008d,
7928 "-> Loading segment %u...\n", j);
7929 qla24xx_read_flash_data(vha, dcode, faddr, 10);
7930 risc_addr = be32_to_cpu((__force __be32)dcode[2]);
7931 risc_size = be32_to_cpu((__force __be32)dcode[3]);
7933 *srisc_addr = risc_addr;
7934 risc_attr = be32_to_cpu((__force __be32)dcode[9]);
7937 dlen = ha->fw_transfer_size >> 2;
7938 for (fragment = 0; risc_size; fragment++) {
7939 if (dlen > risc_size)
7942 ql_dbg(ql_dbg_init, vha, 0x008e,
7943 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
7944 fragment, risc_addr, faddr, dlen);
7945 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
7946 for (i = 0; i < dlen; i++)
7947 dcode[i] = swab32(dcode[i]);
7949 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7951 ql_log(ql_log_fatal, vha, 0x008f,
7952 "-> Failed load firmware fragment %u.\n",
7954 return QLA_FUNCTION_FAILED;
7963 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
7966 templates = (risc_attr & BIT_9) ? 2 : 1;
7967 ql_dbg(ql_dbg_init, vha, 0x0160, "-> templates = %u\n", templates);
7968 for (j = 0; j < templates; j++, fwdt++) {
7970 vfree(fwdt->template);
7971 fwdt->template = NULL;
7974 dcode = (uint32_t *)req->ring;
7975 qla24xx_read_flash_data(vha, dcode, faddr, 7);
7976 risc_size = be32_to_cpu((__force __be32)dcode[2]);
7977 ql_dbg(ql_dbg_init, vha, 0x0161,
7978 "-> fwdt%u template array at %#x (%#x dwords)\n",
7979 j, faddr, risc_size);
7980 if (!risc_size || !~risc_size) {
7981 ql_dbg(ql_dbg_init, vha, 0x0162,
7982 "-> fwdt%u failed to read array\n", j);
7986 /* skip header and ignore checksum */
7990 ql_dbg(ql_dbg_init, vha, 0x0163,
7991 "-> fwdt%u template allocate template %#x words...\n",
7993 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
7994 if (!fwdt->template) {
7995 ql_log(ql_log_warn, vha, 0x0164,
7996 "-> fwdt%u failed allocate template.\n", j);
8000 dcode = fwdt->template;
8001 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
8003 if (!qla27xx_fwdt_template_valid(dcode)) {
8004 ql_log(ql_log_warn, vha, 0x0165,
8005 "-> fwdt%u failed template validate\n", j);
8009 dlen = qla27xx_fwdt_template_size(dcode);
8010 ql_dbg(ql_dbg_init, vha, 0x0166,
8011 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8012 j, dlen, dlen / sizeof(*dcode));
8013 if (dlen > risc_size * sizeof(*dcode)) {
8014 ql_log(ql_log_warn, vha, 0x0167,
8015 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8016 j, dlen - risc_size * sizeof(*dcode));
8020 fwdt->length = dlen;
8021 ql_dbg(ql_dbg_init, vha, 0x0168,
8022 "-> fwdt%u loaded template ok\n", j);
8024 faddr += risc_size + 1;
8031 vfree(fwdt->template);
8032 fwdt->template = NULL;
8038 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
8041 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8047 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
8048 struct fw_blob *blob;
8049 struct qla_hw_data *ha = vha->hw;
8050 struct req_que *req = ha->req_q_map[0];
8052 /* Load firmware blob. */
8053 blob = qla2x00_request_firmware(vha);
8055 ql_log(ql_log_info, vha, 0x0083,
8056 "Firmware image unavailable.\n");
8057 ql_log(ql_log_info, vha, 0x0084,
8058 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
8059 return QLA_FUNCTION_FAILED;
8064 wcode = (uint16_t *)req->ring;
8066 fwcode = (__force __be16 *)blob->fw->data;
8069 /* Validate firmware image by checking version. */
8070 if (blob->fw->size < 8 * sizeof(uint16_t)) {
8071 ql_log(ql_log_fatal, vha, 0x0085,
8072 "Unable to verify integrity of firmware image (%zd).\n",
8074 goto fail_fw_integrity;
8076 for (i = 0; i < 4; i++)
8077 wcode[i] = be16_to_cpu(fwcode[i + 4]);
8078 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
8079 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
8080 wcode[2] == 0 && wcode[3] == 0)) {
8081 ql_log(ql_log_fatal, vha, 0x0086,
8082 "Unable to verify integrity of firmware image.\n");
8083 ql_log(ql_log_fatal, vha, 0x0087,
8084 "Firmware data: %04x %04x %04x %04x.\n",
8085 wcode[0], wcode[1], wcode[2], wcode[3]);
8086 goto fail_fw_integrity;
8090 while (*seg && rval == QLA_SUCCESS) {
8092 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
8093 risc_size = be16_to_cpu(fwcode[3]);
8095 /* Validate firmware image size. */
8096 fwclen += risc_size * sizeof(uint16_t);
8097 if (blob->fw->size < fwclen) {
8098 ql_log(ql_log_fatal, vha, 0x0088,
8099 "Unable to verify integrity of firmware image "
8100 "(%zd).\n", blob->fw->size);
8101 goto fail_fw_integrity;
8105 while (risc_size > 0 && rval == QLA_SUCCESS) {
8106 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
8107 if (wlen > risc_size)
8109 ql_dbg(ql_dbg_init, vha, 0x0089,
8110 "Loading risc segment@ risc addr %x number of "
8111 "words 0x%x.\n", risc_addr, wlen);
8113 for (i = 0; i < wlen; i++)
8114 wcode[i] = swab16((__force u32)fwcode[i]);
8116 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
8119 ql_log(ql_log_fatal, vha, 0x008a,
8120 "Failed to load segment %d of firmware.\n",
8137 return QLA_FUNCTION_FAILED;
8141 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8144 uint templates, segments, fragment;
8147 uint32_t risc_addr, risc_size, risc_attr = 0;
8150 struct fw_blob *blob;
8152 struct qla_hw_data *ha = vha->hw;
8153 struct req_que *req = ha->req_q_map[0];
8154 struct fwdt *fwdt = ha->fwdt;
8156 ql_dbg(ql_dbg_init, vha, 0x0090,
8157 "-> FW: Loading via request-firmware.\n");
8159 blob = qla2x00_request_firmware(vha);
8161 ql_log(ql_log_warn, vha, 0x0092,
8162 "-> Firmware file not found.\n");
8164 return QLA_FUNCTION_FAILED;
8167 fwcode = (__force __be32 *)blob->fw->data;
8168 dcode = (__force uint32_t *)fwcode;
8169 if (qla24xx_risc_firmware_invalid(dcode)) {
8170 ql_log(ql_log_fatal, vha, 0x0093,
8171 "Unable to verify integrity of firmware image (%zd).\n",
8173 ql_log(ql_log_fatal, vha, 0x0095,
8174 "Firmware data: %08x %08x %08x %08x.\n",
8175 dcode[0], dcode[1], dcode[2], dcode[3]);
8176 return QLA_FUNCTION_FAILED;
8179 dcode = (uint32_t *)req->ring;
8181 segments = FA_RISC_CODE_SEGMENTS;
8182 for (j = 0; j < segments; j++) {
8183 ql_dbg(ql_dbg_init, vha, 0x0096,
8184 "-> Loading segment %u...\n", j);
8185 risc_addr = be32_to_cpu(fwcode[2]);
8186 risc_size = be32_to_cpu(fwcode[3]);
8189 *srisc_addr = risc_addr;
8190 risc_attr = be32_to_cpu(fwcode[9]);
8193 dlen = ha->fw_transfer_size >> 2;
8194 for (fragment = 0; risc_size; fragment++) {
8195 if (dlen > risc_size)
8198 ql_dbg(ql_dbg_init, vha, 0x0097,
8199 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
8200 fragment, risc_addr,
8201 (uint32_t)(fwcode - (typeof(fwcode))blob->fw->data),
8204 for (i = 0; i < dlen; i++)
8205 dcode[i] = swab32((__force u32)fwcode[i]);
8207 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
8209 ql_log(ql_log_fatal, vha, 0x0098,
8210 "-> Failed load firmware fragment %u.\n",
8212 return QLA_FUNCTION_FAILED;
8221 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8224 templates = (risc_attr & BIT_9) ? 2 : 1;
8225 ql_dbg(ql_dbg_init, vha, 0x0170, "-> templates = %u\n", templates);
8226 for (j = 0; j < templates; j++, fwdt++) {
8228 vfree(fwdt->template);
8229 fwdt->template = NULL;
8232 risc_size = be32_to_cpu(fwcode[2]);
8233 ql_dbg(ql_dbg_init, vha, 0x0171,
8234 "-> fwdt%u template array at %#x (%#x dwords)\n",
8235 j, (uint32_t)((void *)fwcode - (void *)blob->fw->data),
8237 if (!risc_size || !~risc_size) {
8238 ql_dbg(ql_dbg_init, vha, 0x0172,
8239 "-> fwdt%u failed to read array\n", j);
8243 /* skip header and ignore checksum */
8247 ql_dbg(ql_dbg_init, vha, 0x0173,
8248 "-> fwdt%u template allocate template %#x words...\n",
8250 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
8251 if (!fwdt->template) {
8252 ql_log(ql_log_warn, vha, 0x0174,
8253 "-> fwdt%u failed allocate template.\n", j);
8257 dcode = fwdt->template;
8258 for (i = 0; i < risc_size; i++)
8259 dcode[i] = (__force u32)fwcode[i];
8261 if (!qla27xx_fwdt_template_valid(dcode)) {
8262 ql_log(ql_log_warn, vha, 0x0175,
8263 "-> fwdt%u failed template validate\n", j);
8267 dlen = qla27xx_fwdt_template_size(dcode);
8268 ql_dbg(ql_dbg_init, vha, 0x0176,
8269 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8270 j, dlen, dlen / sizeof(*dcode));
8271 if (dlen > risc_size * sizeof(*dcode)) {
8272 ql_log(ql_log_warn, vha, 0x0177,
8273 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8274 j, dlen - risc_size * sizeof(*dcode));
8278 fwdt->length = dlen;
8279 ql_dbg(ql_dbg_init, vha, 0x0178,
8280 "-> fwdt%u loaded template ok\n", j);
8282 fwcode += risc_size + 1;
8289 vfree(fwdt->template);
8290 fwdt->template = NULL;
8297 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8301 if (ql2xfwloadbin == 1)
8302 return qla81xx_load_risc(vha, srisc_addr);
8306 * 1) Firmware via request-firmware interface (.bin file).
8307 * 2) Firmware residing in flash.
8309 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8310 if (rval == QLA_SUCCESS)
8313 return qla24xx_load_risc_flash(vha, srisc_addr,
8314 vha->hw->flt_region_fw);
8318 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8321 struct qla_hw_data *ha = vha->hw;
8322 struct active_regions active_regions = { };
8324 if (ql2xfwloadbin == 2)
8327 /* FW Load priority:
8328 * 1) Firmware residing in flash.
8329 * 2) Firmware via request-firmware interface (.bin file).
8330 * 3) Golden-Firmware residing in flash -- (limited operation).
8333 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8334 goto try_primary_fw;
8336 qla27xx_get_active_image(vha, &active_regions);
8338 if (active_regions.global != QLA27XX_SECONDARY_IMAGE)
8339 goto try_primary_fw;
8341 ql_dbg(ql_dbg_init, vha, 0x008b,
8342 "Loading secondary firmware image.\n");
8343 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw_sec);
8348 ql_dbg(ql_dbg_init, vha, 0x008b,
8349 "Loading primary firmware image.\n");
8350 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
8355 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8356 if (!rval || !ha->flt_region_gold_fw)
8359 ql_log(ql_log_info, vha, 0x0099,
8360 "Attempting to fallback to golden firmware.\n");
8361 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
8365 ql_log(ql_log_info, vha, 0x009a, "Need firmware flash update.\n");
8366 ha->flags.running_gold_fw = 1;
8371 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
8374 struct qla_hw_data *ha = vha->hw;
8376 if (ha->flags.pci_channel_io_perm_failure)
8378 if (!IS_FWI2_CAPABLE(ha))
8380 if (!ha->fw_major_version)
8382 if (!ha->flags.fw_started)
8385 ret = qla2x00_stop_firmware(vha);
8386 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
8387 ret != QLA_INVALID_COMMAND && retries ; retries--) {
8388 ha->isp_ops->reset_chip(vha);
8389 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
8391 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
8393 ql_log(ql_log_info, vha, 0x8015,
8394 "Attempting retry of stop-firmware command.\n");
8395 ret = qla2x00_stop_firmware(vha);
8399 ha->flags.fw_init_done = 0;
8403 qla24xx_configure_vhba(scsi_qla_host_t *vha)
8405 int rval = QLA_SUCCESS;
8407 uint16_t mb[MAILBOX_REGISTER_COUNT];
8408 struct qla_hw_data *ha = vha->hw;
8409 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
8414 rval = qla2x00_fw_ready(base_vha);
8416 if (rval == QLA_SUCCESS) {
8417 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8418 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8421 vha->flags.management_server_logged_in = 0;
8423 /* Login to SNS first */
8424 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
8426 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
8427 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
8428 ql_dbg(ql_dbg_init, vha, 0x0120,
8429 "Failed SNS login: loop_id=%x, rval2=%d\n",
8432 ql_dbg(ql_dbg_init, vha, 0x0103,
8433 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
8434 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
8435 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
8436 return (QLA_FUNCTION_FAILED);
8439 atomic_set(&vha->loop_down_timer, 0);
8440 atomic_set(&vha->loop_state, LOOP_UP);
8441 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8442 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
8443 rval = qla2x00_loop_resync(base_vha);
8448 /* 84XX Support **************************************************************/
8450 static LIST_HEAD(qla_cs84xx_list);
8451 static DEFINE_MUTEX(qla_cs84xx_mutex);
8453 static struct qla_chip_state_84xx *
8454 qla84xx_get_chip(struct scsi_qla_host *vha)
8456 struct qla_chip_state_84xx *cs84xx;
8457 struct qla_hw_data *ha = vha->hw;
8459 mutex_lock(&qla_cs84xx_mutex);
8461 /* Find any shared 84xx chip. */
8462 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
8463 if (cs84xx->bus == ha->pdev->bus) {
8464 kref_get(&cs84xx->kref);
8469 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
8473 kref_init(&cs84xx->kref);
8474 spin_lock_init(&cs84xx->access_lock);
8475 mutex_init(&cs84xx->fw_update_mutex);
8476 cs84xx->bus = ha->pdev->bus;
8478 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
8480 mutex_unlock(&qla_cs84xx_mutex);
8485 __qla84xx_chip_release(struct kref *kref)
8487 struct qla_chip_state_84xx *cs84xx =
8488 container_of(kref, struct qla_chip_state_84xx, kref);
8490 mutex_lock(&qla_cs84xx_mutex);
8491 list_del(&cs84xx->list);
8492 mutex_unlock(&qla_cs84xx_mutex);
8497 qla84xx_put_chip(struct scsi_qla_host *vha)
8499 struct qla_hw_data *ha = vha->hw;
8502 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
8506 qla84xx_init_chip(scsi_qla_host_t *vha)
8510 struct qla_hw_data *ha = vha->hw;
8512 mutex_lock(&ha->cs84xx->fw_update_mutex);
8514 rval = qla84xx_verify_chip(vha, status);
8516 mutex_unlock(&ha->cs84xx->fw_update_mutex);
8518 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED :
8522 /* 81XX Support **************************************************************/
8525 qla81xx_nvram_config(scsi_qla_host_t *vha)
8528 struct init_cb_81xx *icb;
8529 struct nvram_81xx *nv;
8531 uint8_t *dptr1, *dptr2;
8534 struct qla_hw_data *ha = vha->hw;
8536 struct active_regions active_regions = { };
8539 icb = (struct init_cb_81xx *)ha->init_cb;
8542 /* Determine NVRAM starting address. */
8543 ha->nvram_size = sizeof(*nv);
8544 ha->vpd_size = FA_NVRAM_VPD_SIZE;
8545 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
8546 ha->vpd_size = FA_VPD_SIZE_82XX;
8548 if (IS_QLA28XX(ha) || IS_QLA27XX(ha))
8549 qla28xx_get_aux_images(vha, &active_regions);
8551 /* Get VPD data into cache */
8552 ha->vpd = ha->nvram + VPD_OFFSET;
8554 faddr = ha->flt_region_vpd;
8555 if (IS_QLA28XX(ha)) {
8556 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8557 faddr = ha->flt_region_vpd_sec;
8558 ql_dbg(ql_dbg_init, vha, 0x0110,
8559 "Loading %s nvram image.\n",
8560 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8561 "primary" : "secondary");
8563 ha->isp_ops->read_optrom(vha, ha->vpd, faddr << 2, ha->vpd_size);
8565 /* Get NVRAM data into cache and calculate checksum. */
8566 faddr = ha->flt_region_nvram;
8567 if (IS_QLA28XX(ha)) {
8568 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8569 faddr = ha->flt_region_nvram_sec;
8571 ql_dbg(ql_dbg_init, vha, 0x0110,
8572 "Loading %s nvram image.\n",
8573 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8574 "primary" : "secondary");
8575 ha->isp_ops->read_optrom(vha, ha->nvram, faddr << 2, ha->nvram_size);
8577 dptr = (__force __le32 *)nv;
8578 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
8579 chksum += le32_to_cpu(*dptr);
8581 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
8582 "Contents of NVRAM:\n");
8583 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
8584 nv, ha->nvram_size);
8586 /* Bad NVRAM data, set defaults parameters. */
8587 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
8588 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
8589 /* Reset NVRAM data. */
8590 ql_log(ql_log_info, vha, 0x0073,
8591 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
8592 chksum, nv->id, le16_to_cpu(nv->nvram_version));
8593 ql_dump_buffer(ql_dbg_init, vha, 0x0073, nv, sizeof(*nv));
8594 ql_log(ql_log_info, vha, 0x0074,
8595 "Falling back to functioning (yet invalid -- WWPN) "
8599 * Set default initialization control block.
8601 memset(nv, 0, ha->nvram_size);
8602 nv->nvram_version = cpu_to_le16(ICB_VERSION);
8603 nv->version = cpu_to_le16(ICB_VERSION);
8604 nv->frame_payload_size = cpu_to_le16(2048);
8605 nv->execution_throttle = cpu_to_le16(0xFFFF);
8606 nv->exchange_count = cpu_to_le16(0);
8607 nv->port_name[0] = 0x21;
8608 nv->port_name[1] = 0x00 + ha->port_no + 1;
8609 nv->port_name[2] = 0x00;
8610 nv->port_name[3] = 0xe0;
8611 nv->port_name[4] = 0x8b;
8612 nv->port_name[5] = 0x1c;
8613 nv->port_name[6] = 0x55;
8614 nv->port_name[7] = 0x86;
8615 nv->node_name[0] = 0x20;
8616 nv->node_name[1] = 0x00;
8617 nv->node_name[2] = 0x00;
8618 nv->node_name[3] = 0xe0;
8619 nv->node_name[4] = 0x8b;
8620 nv->node_name[5] = 0x1c;
8621 nv->node_name[6] = 0x55;
8622 nv->node_name[7] = 0x86;
8623 nv->login_retry_count = cpu_to_le16(8);
8624 nv->interrupt_delay_timer = cpu_to_le16(0);
8625 nv->login_timeout = cpu_to_le16(0);
8626 nv->firmware_options_1 =
8627 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
8628 nv->firmware_options_2 = cpu_to_le32(2 << 4);
8629 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
8630 nv->firmware_options_3 = cpu_to_le32(2 << 13);
8631 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
8632 nv->efi_parameters = cpu_to_le32(0);
8633 nv->reset_delay = 5;
8634 nv->max_luns_per_target = cpu_to_le16(128);
8635 nv->port_down_retry_count = cpu_to_le16(30);
8636 nv->link_down_timeout = cpu_to_le16(180);
8637 nv->enode_mac[0] = 0x00;
8638 nv->enode_mac[1] = 0xC0;
8639 nv->enode_mac[2] = 0xDD;
8640 nv->enode_mac[3] = 0x04;
8641 nv->enode_mac[4] = 0x05;
8642 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
8647 if (IS_T10_PI_CAPABLE(ha))
8648 nv->frame_payload_size &= cpu_to_le16(~7);
8650 qlt_81xx_config_nvram_stage1(vha, nv);
8652 /* Reset Initialization control block */
8653 memset(icb, 0, ha->init_cb_size);
8655 /* Copy 1st segment. */
8656 dptr1 = (uint8_t *)icb;
8657 dptr2 = (uint8_t *)&nv->version;
8658 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
8660 *dptr1++ = *dptr2++;
8662 icb->login_retry_count = nv->login_retry_count;
8664 /* Copy 2nd segment. */
8665 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
8666 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
8667 cnt = (uint8_t *)&icb->reserved_5 -
8668 (uint8_t *)&icb->interrupt_delay_timer;
8670 *dptr1++ = *dptr2++;
8672 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
8673 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8674 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
8675 icb->enode_mac[0] = 0x00;
8676 icb->enode_mac[1] = 0xC0;
8677 icb->enode_mac[2] = 0xDD;
8678 icb->enode_mac[3] = 0x04;
8679 icb->enode_mac[4] = 0x05;
8680 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
8683 /* Use extended-initialization control block. */
8684 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
8685 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
8687 * Setup driver NVRAM options.
8689 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
8692 qlt_81xx_config_nvram_stage2(vha, icb);
8694 /* Use alternate WWN? */
8695 if (nv->host_p & cpu_to_le32(BIT_15)) {
8696 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
8697 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
8700 /* Prepare nodename */
8701 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
8703 * Firmware will apply the following mask if the nodename was
8706 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
8707 icb->node_name[0] &= 0xF0;
8710 if (IS_QLA28XX(ha) || IS_QLA27XX(ha)) {
8711 if ((nv->enhanced_features & BIT_7) == 0)
8712 ha->flags.scm_supported_a = 1;
8715 /* Set host adapter parameters. */
8716 ha->flags.disable_risc_code_load = 0;
8717 ha->flags.enable_lip_reset = 0;
8718 ha->flags.enable_lip_full_login =
8719 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
8720 ha->flags.enable_target_reset =
8721 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
8722 ha->flags.enable_led_scheme = 0;
8723 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
8725 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
8726 (BIT_6 | BIT_5 | BIT_4)) >> 4;
8728 /* save HBA serial number */
8729 ha->serial0 = icb->port_name[5];
8730 ha->serial1 = icb->port_name[6];
8731 ha->serial2 = icb->port_name[7];
8732 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
8733 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
8735 icb->execution_throttle = cpu_to_le16(0xFFFF);
8737 ha->retry_count = le16_to_cpu(nv->login_retry_count);
8739 /* Set minimum login_timeout to 4 seconds. */
8740 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
8741 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
8742 if (le16_to_cpu(nv->login_timeout) < 4)
8743 nv->login_timeout = cpu_to_le16(4);
8744 ha->login_timeout = le16_to_cpu(nv->login_timeout);
8746 /* Set minimum RATOV to 100 tenths of a second. */
8749 ha->loop_reset_delay = nv->reset_delay;
8751 /* Link Down Timeout = 0:
8753 * When Port Down timer expires we will start returning
8754 * I/O's to OS with "DID_NO_CONNECT".
8756 * Link Down Timeout != 0:
8758 * The driver waits for the link to come up after link down
8759 * before returning I/Os to OS with "DID_NO_CONNECT".
8761 if (le16_to_cpu(nv->link_down_timeout) == 0) {
8762 ha->loop_down_abort_time =
8763 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
8765 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
8766 ha->loop_down_abort_time =
8767 (LOOP_DOWN_TIME - ha->link_down_timeout);
8770 /* Need enough time to try and get the port back. */
8771 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8772 if (qlport_down_retry)
8773 ha->port_down_retry_count = qlport_down_retry;
8775 /* Set login_retry_count */
8776 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8777 if (ha->port_down_retry_count ==
8778 le16_to_cpu(nv->port_down_retry_count) &&
8779 ha->port_down_retry_count > 3)
8780 ha->login_retry_count = ha->port_down_retry_count;
8781 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8782 ha->login_retry_count = ha->port_down_retry_count;
8783 if (ql2xloginretrycount)
8784 ha->login_retry_count = ql2xloginretrycount;
8786 /* if not running MSI-X we need handshaking on interrupts */
8787 if (!vha->hw->flags.msix_enabled &&
8788 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)))
8789 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
8792 if (!vha->flags.init_done) {
8793 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8794 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8795 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8796 le16_to_cpu(icb->interrupt_delay_timer) : 2;
8798 icb->firmware_options_2 &= cpu_to_le32(
8799 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8800 vha->flags.process_response_queue = 0;
8801 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8802 ha->zio_mode = QLA_ZIO_MODE_6;
8804 ql_log(ql_log_info, vha, 0x0075,
8805 "ZIO mode %d enabled; timer delay (%d us).\n",
8807 ha->zio_timer * 100);
8809 icb->firmware_options_2 |= cpu_to_le32(
8810 (uint32_t)ha->zio_mode);
8811 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8812 vha->flags.process_response_queue = 1;
8815 /* enable RIDA Format2 */
8816 icb->firmware_options_3 |= cpu_to_le32(BIT_0);
8818 /* N2N: driver will initiate Login instead of FW */
8819 icb->firmware_options_3 |= cpu_to_le32(BIT_8);
8821 /* Determine NVMe/FCP priority for target ports */
8822 ha->fc4_type_priority = qla2xxx_get_fc4_priority(vha);
8825 ql_log(ql_log_warn, vha, 0x0076,
8826 "NVRAM configuration failed.\n");
8832 qla82xx_restart_isp(scsi_qla_host_t *vha)
8835 struct qla_hw_data *ha = vha->hw;
8836 struct scsi_qla_host *vp;
8837 unsigned long flags;
8839 status = qla2x00_init_rings(vha);
8841 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8842 ha->flags.chip_reset_done = 1;
8844 status = qla2x00_fw_ready(vha);
8846 /* Issue a marker after FW becomes ready. */
8847 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8848 vha->flags.online = 1;
8849 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8852 /* if no cable then assume it's good */
8853 if ((vha->device_flags & DFLG_NO_CABLE))
8858 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8860 if (!atomic_read(&vha->loop_down_timer)) {
8862 * Issue marker command only when we are going
8863 * to start the I/O .
8865 vha->marker_needed = 1;
8868 ha->isp_ops->enable_intrs(ha);
8870 ha->isp_abort_cnt = 0;
8871 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
8873 /* Update the firmware version */
8874 status = qla82xx_check_md_needed(vha);
8877 ha->flags.fce_enabled = 1;
8879 fce_calc_size(ha->fce_bufs));
8880 rval = qla2x00_enable_fce_trace(vha,
8881 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
8884 ql_log(ql_log_warn, vha, 0x8001,
8885 "Unable to reinitialize FCE (%d).\n",
8887 ha->flags.fce_enabled = 0;
8892 memset(ha->eft, 0, EFT_SIZE);
8893 rval = qla2x00_enable_eft_trace(vha,
8894 ha->eft_dma, EFT_NUM_BUFFERS);
8896 ql_log(ql_log_warn, vha, 0x8010,
8897 "Unable to reinitialize EFT (%d).\n",
8904 ql_dbg(ql_dbg_taskm, vha, 0x8011,
8905 "qla82xx_restart_isp succeeded.\n");
8907 spin_lock_irqsave(&ha->vport_slock, flags);
8908 list_for_each_entry(vp, &ha->vp_list, list) {
8910 atomic_inc(&vp->vref_count);
8911 spin_unlock_irqrestore(&ha->vport_slock, flags);
8913 qla2x00_vp_abort_isp(vp);
8915 spin_lock_irqsave(&ha->vport_slock, flags);
8916 atomic_dec(&vp->vref_count);
8919 spin_unlock_irqrestore(&ha->vport_slock, flags);
8922 ql_log(ql_log_warn, vha, 0x8016,
8923 "qla82xx_restart_isp **** FAILED ****.\n");
8930 * qla24xx_get_fcp_prio
8931 * Gets the fcp cmd priority value for the logged in port.
8932 * Looks for a match of the port descriptors within
8933 * each of the fcp prio config entries. If a match is found,
8934 * the tag (priority) value is returned.
8937 * vha = scsi host structure pointer.
8938 * fcport = port structure pointer.
8941 * non-zero (if found)
8948 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8951 uint8_t pid_match, wwn_match;
8953 uint32_t pid1, pid2;
8954 uint64_t wwn1, wwn2;
8955 struct qla_fcp_prio_entry *pri_entry;
8956 struct qla_hw_data *ha = vha->hw;
8958 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
8962 entries = ha->fcp_prio_cfg->num_entries;
8963 pri_entry = &ha->fcp_prio_cfg->entry[0];
8965 for (i = 0; i < entries; i++) {
8966 pid_match = wwn_match = 0;
8968 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
8973 /* check source pid for a match */
8974 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
8975 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
8976 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
8977 if (pid1 == INVALID_PORT_ID)
8979 else if (pid1 == pid2)
8983 /* check destination pid for a match */
8984 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
8985 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
8986 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
8987 if (pid1 == INVALID_PORT_ID)
8989 else if (pid1 == pid2)
8993 /* check source WWN for a match */
8994 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
8995 wwn1 = wwn_to_u64(vha->port_name);
8996 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
8997 if (wwn2 == (uint64_t)-1)
8999 else if (wwn1 == wwn2)
9003 /* check destination WWN for a match */
9004 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
9005 wwn1 = wwn_to_u64(fcport->port_name);
9006 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
9007 if (wwn2 == (uint64_t)-1)
9009 else if (wwn1 == wwn2)
9013 if (pid_match == 2 || wwn_match == 2) {
9014 /* Found a matching entry */
9015 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
9016 priority = pri_entry->tag;
9027 * qla24xx_update_fcport_fcp_prio
9028 * Activates fcp priority for the logged in fc port
9031 * vha = scsi host structure pointer.
9032 * fcp = port structure pointer.
9035 * QLA_SUCCESS or QLA_FUNCTION_FAILED
9041 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
9047 if (fcport->port_type != FCT_TARGET ||
9048 fcport->loop_id == FC_NO_LOOP_ID)
9049 return QLA_FUNCTION_FAILED;
9051 priority = qla24xx_get_fcp_prio(vha, fcport);
9053 return QLA_FUNCTION_FAILED;
9055 if (IS_P3P_TYPE(vha->hw)) {
9056 fcport->fcp_prio = priority & 0xf;
9060 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
9061 if (ret == QLA_SUCCESS) {
9062 if (fcport->fcp_prio != priority)
9063 ql_dbg(ql_dbg_user, vha, 0x709e,
9064 "Updated FCP_CMND priority - value=%d loop_id=%d "
9065 "port_id=%02x%02x%02x.\n", priority,
9066 fcport->loop_id, fcport->d_id.b.domain,
9067 fcport->d_id.b.area, fcport->d_id.b.al_pa);
9068 fcport->fcp_prio = priority & 0xf;
9070 ql_dbg(ql_dbg_user, vha, 0x704f,
9071 "Unable to update FCP_CMND priority - ret=0x%x for "
9072 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
9073 fcport->d_id.b.domain, fcport->d_id.b.area,
9074 fcport->d_id.b.al_pa);
9079 * qla24xx_update_all_fcp_prio
9080 * Activates fcp priority for all the logged in ports
9083 * ha = adapter block pointer.
9086 * QLA_SUCCESS or QLA_FUNCTION_FAILED
9092 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
9097 ret = QLA_FUNCTION_FAILED;
9098 /* We need to set priority for all logged in ports */
9099 list_for_each_entry(fcport, &vha->vp_fcports, list)
9100 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
9105 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
9106 int vp_idx, bool startqp)
9111 struct qla_hw_data *ha = vha->hw;
9112 uint16_t qpair_id = 0;
9113 struct qla_qpair *qpair = NULL;
9114 struct qla_msix_entry *msix;
9116 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
9117 ql_log(ql_log_warn, vha, 0x00181,
9118 "FW/Driver is not multi-queue capable.\n");
9122 if (ql2xmqsupport || ql2xnvmeenable) {
9123 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
9124 if (qpair == NULL) {
9125 ql_log(ql_log_warn, vha, 0x0182,
9126 "Failed to allocate memory for queue pair.\n");
9130 qpair->hw = vha->hw;
9132 qpair->qp_lock_ptr = &qpair->qp_lock;
9133 spin_lock_init(&qpair->qp_lock);
9134 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
9136 /* Assign available que pair id */
9137 mutex_lock(&ha->mq_lock);
9138 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
9139 if (ha->num_qpairs >= ha->max_qpairs) {
9140 mutex_unlock(&ha->mq_lock);
9141 ql_log(ql_log_warn, vha, 0x0183,
9142 "No resources to create additional q pair.\n");
9146 set_bit(qpair_id, ha->qpair_qid_map);
9147 ha->queue_pair_map[qpair_id] = qpair;
9148 qpair->id = qpair_id;
9149 qpair->vp_idx = vp_idx;
9150 qpair->fw_started = ha->flags.fw_started;
9151 INIT_LIST_HEAD(&qpair->hints_list);
9152 qpair->chip_reset = ha->base_qpair->chip_reset;
9153 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
9154 qpair->enable_explicit_conf =
9155 ha->base_qpair->enable_explicit_conf;
9157 for (i = 0; i < ha->msix_count; i++) {
9158 msix = &ha->msix_entries[i];
9162 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
9163 "Vector %x selected for qpair\n", msix->vector);
9167 ql_log(ql_log_warn, vha, 0x0184,
9168 "Out of MSI-X vectors!.\n");
9172 qpair->msix->in_use = 1;
9173 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
9174 qpair->pdev = ha->pdev;
9175 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
9176 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
9178 mutex_unlock(&ha->mq_lock);
9180 /* Create response queue first */
9181 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
9183 ql_log(ql_log_warn, vha, 0x0185,
9184 "Failed to create response queue.\n");
9188 qpair->rsp = ha->rsp_q_map[rsp_id];
9190 /* Create request queue */
9191 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
9194 ql_log(ql_log_warn, vha, 0x0186,
9195 "Failed to create request queue.\n");
9199 qpair->req = ha->req_q_map[req_id];
9200 qpair->rsp->req = qpair->req;
9201 qpair->rsp->qpair = qpair;
9202 /* init qpair to this cpu. Will adjust at run time. */
9203 qla_cpu_update(qpair, raw_smp_processor_id());
9205 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
9206 if (ha->fw_attributes & BIT_4)
9207 qpair->difdix_supported = 1;
9210 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
9211 if (!qpair->srb_mempool) {
9212 ql_log(ql_log_warn, vha, 0xd036,
9213 "Failed to create srb mempool for qpair %d\n",
9218 /* Mark as online */
9221 if (!vha->flags.qpairs_available)
9222 vha->flags.qpairs_available = 1;
9224 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
9225 "Request/Response queue pair created, id %d\n",
9227 ql_dbg(ql_dbg_init, vha, 0x0187,
9228 "Request/Response queue pair created, id %d\n",
9235 qla25xx_delete_rsp_que(vha, qpair->rsp);
9237 mutex_lock(&ha->mq_lock);
9238 qpair->msix->in_use = 0;
9239 list_del(&qpair->qp_list_elem);
9240 if (list_empty(&vha->qp_list))
9241 vha->flags.qpairs_available = 0;
9243 ha->queue_pair_map[qpair_id] = NULL;
9244 clear_bit(qpair_id, ha->qpair_qid_map);
9246 mutex_unlock(&ha->mq_lock);
9252 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
9254 int ret = QLA_FUNCTION_FAILED;
9255 struct qla_hw_data *ha = qpair->hw;
9257 qpair->delete_in_progress = 1;
9259 ret = qla25xx_delete_req_que(vha, qpair->req);
9260 if (ret != QLA_SUCCESS)
9263 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
9264 if (ret != QLA_SUCCESS)
9267 mutex_lock(&ha->mq_lock);
9268 ha->queue_pair_map[qpair->id] = NULL;
9269 clear_bit(qpair->id, ha->qpair_qid_map);
9271 list_del(&qpair->qp_list_elem);
9272 if (list_empty(&vha->qp_list)) {
9273 vha->flags.qpairs_available = 0;
9274 vha->flags.qpairs_req_created = 0;
9275 vha->flags.qpairs_rsp_created = 0;
9277 mempool_destroy(qpair->srb_mempool);
9279 mutex_unlock(&ha->mq_lock);