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;
139 srb_t *orig_sp = sp->cmd_sp;
142 qla_wait_nvme_release_cmd_kref(orig_sp);
144 del_timer(&sp->u.iocb_cmd.timer);
145 if (sp->flags & SRB_WAKEUP_ON_COMP)
146 complete(&abt->u.abt.comp);
151 int qla24xx_async_abort_cmd(srb_t *cmd_sp, bool wait)
153 scsi_qla_host_t *vha = cmd_sp->vha;
154 struct srb_iocb *abt_iocb;
156 int rval = QLA_FUNCTION_FAILED;
158 sp = qla2xxx_get_qpair_sp(cmd_sp->vha, cmd_sp->qpair, cmd_sp->fcport,
163 abt_iocb = &sp->u.iocb_cmd;
164 sp->type = SRB_ABT_CMD;
166 sp->qpair = cmd_sp->qpair;
169 sp->flags = SRB_WAKEUP_ON_COMP;
171 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
172 init_completion(&abt_iocb->u.abt.comp);
173 /* FW can send 2 x ABTS's timeout/20s */
174 qla2x00_init_timer(sp, 42);
176 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
177 abt_iocb->u.abt.req_que_no = cpu_to_le16(cmd_sp->qpair->req->id);
179 sp->done = qla24xx_abort_sp_done;
181 ql_dbg(ql_dbg_async, vha, 0x507c,
182 "Abort command issued - hdl=%x, type=%x\n", cmd_sp->handle,
185 rval = qla2x00_start_sp(sp);
186 if (rval != QLA_SUCCESS) {
192 wait_for_completion(&abt_iocb->u.abt.comp);
193 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
194 QLA_SUCCESS : QLA_FUNCTION_FAILED;
202 qla2x00_async_iocb_timeout(void *data)
205 fc_port_t *fcport = sp->fcport;
206 struct srb_iocb *lio = &sp->u.iocb_cmd;
211 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
212 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
213 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
215 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
217 pr_info("Async-%s timeout - hdl=%x.\n",
218 sp->name, sp->handle);
223 rc = qla24xx_async_abort_cmd(sp, false);
225 /* Retry as needed. */
226 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
227 lio->u.logio.data[1] =
228 lio->u.logio.flags & SRB_LOGIN_RETRIED ?
229 QLA_LOGIO_LOGIN_RETRIED : 0;
230 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
231 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
233 if (sp->qpair->req->outstanding_cmds[h] ==
235 sp->qpair->req->outstanding_cmds[h] =
240 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
241 sp->done(sp, QLA_FUNCTION_TIMEOUT);
245 case SRB_CT_PTHRU_CMD:
252 rc = qla24xx_async_abort_cmd(sp, false);
254 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
255 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
257 if (sp->qpair->req->outstanding_cmds[h] ==
259 sp->qpair->req->outstanding_cmds[h] =
264 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
265 sp->done(sp, QLA_FUNCTION_TIMEOUT);
271 static void qla2x00_async_login_sp_done(srb_t *sp, int res)
273 struct scsi_qla_host *vha = sp->vha;
274 struct srb_iocb *lio = &sp->u.iocb_cmd;
277 ql_dbg(ql_dbg_disc, vha, 0x20dd,
278 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
280 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
282 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
283 memset(&ea, 0, sizeof(ea));
284 ea.fcport = sp->fcport;
285 ea.data[0] = lio->u.logio.data[0];
286 ea.data[1] = lio->u.logio.data[1];
287 ea.iop[0] = lio->u.logio.iop[0];
288 ea.iop[1] = lio->u.logio.iop[1];
290 qla24xx_handle_plogi_done_event(vha, &ea);
297 fcport_is_smaller(fc_port_t *fcport)
299 if (wwn_to_u64(fcport->port_name) <
300 wwn_to_u64(fcport->vha->port_name))
307 fcport_is_bigger(fc_port_t *fcport)
309 return !fcport_is_smaller(fcport);
313 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
317 struct srb_iocb *lio;
318 int rval = QLA_FUNCTION_FAILED;
320 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
321 fcport->loop_id == FC_NO_LOOP_ID) {
322 ql_log(ql_log_warn, vha, 0xffff,
323 "%s: %8phC - not sending command.\n",
324 __func__, fcport->port_name);
328 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
332 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_PEND);
333 fcport->flags |= FCF_ASYNC_SENT;
334 fcport->logout_completed = 0;
336 sp->type = SRB_LOGIN_CMD;
338 sp->gen1 = fcport->rscn_gen;
339 sp->gen2 = fcport->login_gen;
341 lio = &sp->u.iocb_cmd;
342 lio->timeout = qla2x00_async_iocb_timeout;
343 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
345 sp->done = qla2x00_async_login_sp_done;
346 if (N2N_TOPO(fcport->vha->hw) && fcport_is_bigger(fcport))
347 lio->u.logio.flags |= SRB_LOGIN_PRLI_ONLY;
349 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
351 if (NVME_TARGET(vha->hw, fcport))
352 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
354 ql_log(ql_log_warn, vha, 0x2072,
355 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x retries=%d.\n",
356 fcport->port_name, sp->handle, fcport->loop_id,
357 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
358 fcport->login_retry);
360 rval = qla2x00_start_sp(sp);
361 if (rval != QLA_SUCCESS) {
362 fcport->flags |= FCF_LOGIN_NEEDED;
363 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
371 fcport->flags &= ~FCF_ASYNC_SENT;
373 fcport->flags &= ~FCF_ASYNC_ACTIVE;
377 static void qla2x00_async_logout_sp_done(srb_t *sp, int res)
379 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
380 sp->fcport->login_gen++;
381 qlt_logo_completion_handler(sp->fcport, res);
386 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
389 struct srb_iocb *lio;
390 int rval = QLA_FUNCTION_FAILED;
392 fcport->flags |= FCF_ASYNC_SENT;
393 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
397 sp->type = SRB_LOGOUT_CMD;
400 lio = &sp->u.iocb_cmd;
401 lio->timeout = qla2x00_async_iocb_timeout;
402 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
404 sp->done = qla2x00_async_logout_sp_done;
406 ql_dbg(ql_dbg_disc, vha, 0x2070,
407 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
408 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
409 fcport->d_id.b.area, fcport->d_id.b.al_pa,
412 rval = qla2x00_start_sp(sp);
413 if (rval != QLA_SUCCESS)
420 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
425 qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
428 fcport->flags &= ~FCF_ASYNC_ACTIVE;
429 /* Don't re-login in target mode */
430 if (!fcport->tgt_session)
431 qla2x00_mark_device_lost(vha, fcport, 1);
432 qlt_logo_completion_handler(fcport, data[0]);
435 static void qla2x00_async_prlo_sp_done(srb_t *sp, int res)
437 struct srb_iocb *lio = &sp->u.iocb_cmd;
438 struct scsi_qla_host *vha = sp->vha;
440 sp->fcport->flags &= ~FCF_ASYNC_ACTIVE;
441 if (!test_bit(UNLOADING, &vha->dpc_flags))
442 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
448 qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
451 struct srb_iocb *lio;
454 rval = QLA_FUNCTION_FAILED;
455 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
459 sp->type = SRB_PRLO_CMD;
462 lio = &sp->u.iocb_cmd;
463 lio->timeout = qla2x00_async_iocb_timeout;
464 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
466 sp->done = qla2x00_async_prlo_sp_done;
468 ql_dbg(ql_dbg_disc, vha, 0x2070,
469 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
470 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
471 fcport->d_id.b.area, fcport->d_id.b.al_pa);
473 rval = qla2x00_start_sp(sp);
474 if (rval != QLA_SUCCESS)
482 fcport->flags &= ~FCF_ASYNC_ACTIVE;
487 void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
489 struct fc_port *fcport = ea->fcport;
491 ql_dbg(ql_dbg_disc, vha, 0x20d2,
492 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
493 __func__, fcport->port_name, fcport->disc_state,
494 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
495 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
497 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
500 if (ea->data[0] != MBS_COMMAND_COMPLETE) {
501 ql_dbg(ql_dbg_disc, vha, 0x2066,
502 "%s %8phC: adisc fail: post delete\n",
503 __func__, ea->fcport->port_name);
504 /* deleted = 0 & logout_on_delete = force fw cleanup */
506 fcport->logout_on_delete = 1;
507 qlt_schedule_sess_for_deletion(ea->fcport);
511 if (ea->fcport->disc_state == DSC_DELETE_PEND)
514 if (ea->sp->gen2 != ea->fcport->login_gen) {
515 /* target side must have changed it. */
516 ql_dbg(ql_dbg_disc, vha, 0x20d3,
517 "%s %8phC generation changed\n",
518 __func__, ea->fcport->port_name);
520 } else if (ea->sp->gen1 != ea->fcport->rscn_gen) {
521 qla_rscn_replay(fcport);
522 qlt_schedule_sess_for_deletion(fcport);
526 __qla24xx_handle_gpdb_event(vha, ea);
529 static int qla_post_els_plogi_work(struct scsi_qla_host *vha, fc_port_t *fcport)
531 struct qla_work_evt *e;
533 e = qla2x00_alloc_work(vha, QLA_EVT_ELS_PLOGI);
535 return QLA_FUNCTION_FAILED;
537 e->u.fcport.fcport = fcport;
538 fcport->flags |= FCF_ASYNC_ACTIVE;
539 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_PEND);
540 return qla2x00_post_work(vha, e);
543 static void qla2x00_async_adisc_sp_done(srb_t *sp, int res)
545 struct scsi_qla_host *vha = sp->vha;
547 struct srb_iocb *lio = &sp->u.iocb_cmd;
549 ql_dbg(ql_dbg_disc, vha, 0x2066,
550 "Async done-%s res %x %8phC\n",
551 sp->name, res, sp->fcport->port_name);
553 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
555 memset(&ea, 0, sizeof(ea));
557 ea.data[0] = lio->u.logio.data[0];
558 ea.data[1] = lio->u.logio.data[1];
559 ea.iop[0] = lio->u.logio.iop[0];
560 ea.iop[1] = lio->u.logio.iop[1];
561 ea.fcport = sp->fcport;
564 qla24xx_handle_adisc_event(vha, &ea);
570 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
574 struct srb_iocb *lio;
575 int rval = QLA_FUNCTION_FAILED;
577 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
580 fcport->flags |= FCF_ASYNC_SENT;
581 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
585 sp->type = SRB_ADISC_CMD;
588 lio = &sp->u.iocb_cmd;
589 lio->timeout = qla2x00_async_iocb_timeout;
590 sp->gen1 = fcport->rscn_gen;
591 sp->gen2 = fcport->login_gen;
592 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
594 sp->done = qla2x00_async_adisc_sp_done;
595 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
596 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
598 ql_dbg(ql_dbg_disc, vha, 0x206f,
599 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
600 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
602 rval = qla2x00_start_sp(sp);
603 if (rval != QLA_SUCCESS)
611 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
612 qla2x00_post_async_adisc_work(vha, fcport, data);
616 static bool qla2x00_is_reserved_id(scsi_qla_host_t *vha, uint16_t loop_id)
618 struct qla_hw_data *ha = vha->hw;
620 if (IS_FWI2_CAPABLE(ha))
621 return loop_id > NPH_LAST_HANDLE;
623 return (loop_id > ha->max_loop_id && loop_id < SNS_FIRST_LOOP_ID) ||
624 loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST;
628 * qla2x00_find_new_loop_id - scan through our port list and find a new usable loop ID
629 * @vha: adapter state pointer.
630 * @dev: port structure pointer.
633 * qla2x00 local function return status code.
638 static int qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
641 struct qla_hw_data *ha = vha->hw;
642 unsigned long flags = 0;
646 spin_lock_irqsave(&ha->vport_slock, flags);
648 dev->loop_id = find_first_zero_bit(ha->loop_id_map, LOOPID_MAP_SIZE);
649 if (dev->loop_id >= LOOPID_MAP_SIZE ||
650 qla2x00_is_reserved_id(vha, dev->loop_id)) {
651 dev->loop_id = FC_NO_LOOP_ID;
652 rval = QLA_FUNCTION_FAILED;
654 set_bit(dev->loop_id, ha->loop_id_map);
656 spin_unlock_irqrestore(&ha->vport_slock, flags);
658 if (rval == QLA_SUCCESS)
659 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
660 "Assigning new loopid=%x, portid=%x.\n",
661 dev->loop_id, dev->d_id.b24);
663 ql_log(ql_log_warn, dev->vha, 0x2087,
664 "No loop_id's available, portid=%x.\n",
670 void qla2x00_clear_loop_id(fc_port_t *fcport)
672 struct qla_hw_data *ha = fcport->vha->hw;
674 if (fcport->loop_id == FC_NO_LOOP_ID ||
675 qla2x00_is_reserved_id(fcport->vha, fcport->loop_id))
678 clear_bit(fcport->loop_id, ha->loop_id_map);
679 fcport->loop_id = FC_NO_LOOP_ID;
682 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
683 struct event_arg *ea)
685 fc_port_t *fcport, *conflict_fcport;
686 struct get_name_list_extended *e;
687 u16 i, n, found = 0, loop_id;
691 u8 current_login_state, nvme_cls;
694 ql_dbg(ql_dbg_disc, vha, 0xffff,
695 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
696 __func__, fcport->port_name, fcport->disc_state,
697 fcport->fw_login_state, ea->rc,
698 fcport->login_gen, fcport->last_login_gen,
699 fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id);
701 if (fcport->disc_state == DSC_DELETE_PEND)
704 if (ea->rc) { /* rval */
705 if (fcport->login_retry == 0) {
706 ql_dbg(ql_dbg_disc, vha, 0x20de,
707 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
708 fcport->port_name, fcport->login_retry);
713 if (fcport->last_rscn_gen != fcport->rscn_gen) {
714 qla_rscn_replay(fcport);
715 qlt_schedule_sess_for_deletion(fcport);
717 } else if (fcport->last_login_gen != fcport->login_gen) {
718 ql_dbg(ql_dbg_disc, vha, 0x20e0,
719 "%s %8phC login gen changed\n",
720 __func__, fcport->port_name);
721 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
725 n = ea->data[0] / sizeof(struct get_name_list_extended);
727 ql_dbg(ql_dbg_disc, vha, 0x20e1,
728 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
729 __func__, __LINE__, fcport->port_name, n,
730 fcport->d_id.b.domain, fcport->d_id.b.area,
731 fcport->d_id.b.al_pa, fcport->loop_id);
733 for (i = 0; i < n; i++) {
735 wwn = wwn_to_u64(e->port_name);
736 id.b.domain = e->port_id[2];
737 id.b.area = e->port_id[1];
738 id.b.al_pa = e->port_id[0];
741 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
744 if (IS_SW_RESV_ADDR(id))
749 loop_id = le16_to_cpu(e->nport_handle);
750 loop_id = (loop_id & 0x7fff);
751 nvme_cls = e->current_login_state >> 4;
752 current_login_state = e->current_login_state & 0xf;
754 if (PRLI_PHASE(nvme_cls)) {
755 current_login_state = nvme_cls;
756 fcport->fc4_type &= ~FS_FC4TYPE_FCP;
757 fcport->fc4_type |= FS_FC4TYPE_NVME;
758 } else if (PRLI_PHASE(current_login_state)) {
759 fcport->fc4_type |= FS_FC4TYPE_FCP;
760 fcport->fc4_type &= ~FS_FC4TYPE_NVME;
763 ql_dbg(ql_dbg_disc, vha, 0x20e2,
764 "%s found %8phC CLS [%x|%x] fc4_type %d ID[%06x|%06x] lid[%d|%d]\n",
765 __func__, fcport->port_name,
766 e->current_login_state, fcport->fw_login_state,
767 fcport->fc4_type, id.b24, fcport->d_id.b24,
768 loop_id, fcport->loop_id);
770 switch (fcport->disc_state) {
771 case DSC_DELETE_PEND:
775 if ((id.b24 != fcport->d_id.b24 &&
777 fcport->loop_id != FC_NO_LOOP_ID) ||
778 (fcport->loop_id != FC_NO_LOOP_ID &&
779 fcport->loop_id != loop_id)) {
780 ql_dbg(ql_dbg_disc, vha, 0x20e3,
781 "%s %d %8phC post del sess\n",
782 __func__, __LINE__, fcport->port_name);
783 if (fcport->n2n_flag)
784 fcport->d_id.b24 = 0;
785 qlt_schedule_sess_for_deletion(fcport);
791 fcport->loop_id = loop_id;
792 if (fcport->n2n_flag)
793 fcport->d_id.b24 = id.b24;
795 wwn = wwn_to_u64(fcport->port_name);
796 qlt_find_sess_invalidate_other(vha, wwn,
797 id, loop_id, &conflict_fcport);
799 if (conflict_fcport) {
801 * Another share fcport share the same loop_id &
802 * nport id. Conflict fcport needs to finish
803 * cleanup before this fcport can proceed to login.
805 conflict_fcport->conflict = fcport;
806 fcport->login_pause = 1;
809 switch (vha->hw->current_topology) {
811 switch (current_login_state) {
812 case DSC_LS_PRLI_COMP:
813 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
814 vha, 0x20e4, "%s %d %8phC post gpdb\n",
815 __func__, __LINE__, fcport->port_name);
817 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
818 fcport->port_type = FCT_INITIATOR;
820 fcport->port_type = FCT_TARGET;
821 data[0] = data[1] = 0;
822 qla2x00_post_async_adisc_work(vha, fcport,
825 case DSC_LS_PORT_UNAVAIL:
827 if (fcport->loop_id == FC_NO_LOOP_ID) {
828 qla2x00_find_new_loop_id(vha, fcport);
829 fcport->fw_login_state =
832 ql_dbg(ql_dbg_disc, vha, 0x20e5,
833 "%s %d %8phC\n", __func__, __LINE__,
835 qla24xx_fcport_handle_login(vha, fcport);
840 fcport->fw_login_state = current_login_state;
842 switch (current_login_state) {
843 case DSC_LS_PRLI_PEND:
845 * In the middle of PRLI. Let it finish.
846 * Allow relogin code to recheck state again
847 * with GNL. Push disc_state back to DELETED
848 * so GNL can go out again
850 qla2x00_set_fcport_disc_state(fcport,
853 case DSC_LS_PRLI_COMP:
854 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
855 fcport->port_type = FCT_INITIATOR;
857 fcport->port_type = FCT_TARGET;
859 data[0] = data[1] = 0;
860 qla2x00_post_async_adisc_work(vha, fcport,
863 case DSC_LS_PLOGI_COMP:
864 if (fcport_is_bigger(fcport)) {
865 /* local adapter is smaller */
866 if (fcport->loop_id != FC_NO_LOOP_ID)
867 qla2x00_clear_loop_id(fcport);
869 fcport->loop_id = loop_id;
870 qla24xx_fcport_handle_login(vha,
876 if (fcport_is_smaller(fcport)) {
877 /* local adapter is bigger */
878 if (fcport->loop_id != FC_NO_LOOP_ID)
879 qla2x00_clear_loop_id(fcport);
881 fcport->loop_id = loop_id;
882 qla24xx_fcport_handle_login(vha,
888 } /* switch (ha->current_topology) */
892 switch (vha->hw->current_topology) {
895 for (i = 0; i < n; i++) {
897 id.b.domain = e->port_id[0];
898 id.b.area = e->port_id[1];
899 id.b.al_pa = e->port_id[2];
901 loop_id = le16_to_cpu(e->nport_handle);
903 if (fcport->d_id.b24 == id.b24) {
905 qla2x00_find_fcport_by_wwpn(vha,
907 if (conflict_fcport) {
908 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
910 "%s %d %8phC post del sess\n",
912 conflict_fcport->port_name);
913 qlt_schedule_sess_for_deletion
918 * FW already picked this loop id for
921 if (fcport->loop_id == loop_id)
922 fcport->loop_id = FC_NO_LOOP_ID;
924 qla24xx_fcport_handle_login(vha, fcport);
927 qla2x00_set_fcport_disc_state(fcport, DSC_DELETED);
928 if (time_after_eq(jiffies, fcport->dm_login_expire)) {
929 if (fcport->n2n_link_reset_cnt < 2) {
930 fcport->n2n_link_reset_cnt++;
932 * remote port is not sending PLOGI.
933 * Reset link to kick start his state
936 set_bit(N2N_LINK_RESET,
939 if (fcport->n2n_chip_reset < 1) {
940 ql_log(ql_log_info, vha, 0x705d,
941 "Chip reset to bring laser down");
942 set_bit(ISP_ABORT_NEEDED,
944 fcport->n2n_chip_reset++;
946 ql_log(ql_log_info, vha, 0x705d,
947 "Remote port %8ph is not coming back\n",
949 fcport->scan_state = 0;
952 qla2xxx_wake_dpc(vha);
955 * report port suppose to do PLOGI. Give him
956 * more time. FW will catch it.
958 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
967 static void qla24xx_async_gnl_sp_done(srb_t *sp, int res)
969 struct scsi_qla_host *vha = sp->vha;
971 struct fc_port *fcport = NULL, *tf;
972 u16 i, n = 0, loop_id;
974 struct get_name_list_extended *e;
979 ql_dbg(ql_dbg_disc, vha, 0x20e7,
980 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
981 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
982 sp->u.iocb_cmd.u.mbx.in_mb[2]);
984 if (res == QLA_FUNCTION_TIMEOUT)
987 sp->fcport->flags &= ~(FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE);
988 memset(&ea, 0, sizeof(ea));
992 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
993 sizeof(struct get_name_list_extended)) {
994 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
995 sizeof(struct get_name_list_extended);
996 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
999 for (i = 0; i < n; i++) {
1001 loop_id = le16_to_cpu(e->nport_handle);
1002 /* mask out reserve bit */
1003 loop_id = (loop_id & 0x7fff);
1004 set_bit(loop_id, vha->hw->loop_id_map);
1005 wwn = wwn_to_u64(e->port_name);
1007 ql_dbg(ql_dbg_disc, vha, 0x20e8,
1008 "%s %8phC %02x:%02x:%02x CLS %x/%x lid %x \n",
1009 __func__, &wwn, e->port_id[2], e->port_id[1],
1010 e->port_id[0], e->current_login_state, e->last_login_state,
1011 (loop_id & 0x7fff));
1014 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1018 if (!list_empty(&vha->gnl.fcports))
1019 list_splice_init(&vha->gnl.fcports, &h);
1020 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1022 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
1023 list_del_init(&fcport->gnl_entry);
1024 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1025 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1026 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1029 qla24xx_handle_gnl_done_event(vha, &ea);
1032 /* create new fcport if fw has knowledge of new sessions */
1033 for (i = 0; i < n; i++) {
1038 wwn = wwn_to_u64(e->port_name);
1041 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
1042 if (!memcmp((u8 *)&wwn, fcport->port_name,
1049 id.b.domain = e->port_id[2];
1050 id.b.area = e->port_id[1];
1051 id.b.al_pa = e->port_id[0];
1054 if (!found && wwn && !IS_SW_RESV_ADDR(id)) {
1055 ql_dbg(ql_dbg_disc, vha, 0x2065,
1056 "%s %d %8phC %06x post new sess\n",
1057 __func__, __LINE__, (u8 *)&wwn, id.b24);
1058 wwnn = wwn_to_u64(e->node_name);
1059 qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn,
1060 (u8 *)&wwnn, NULL, 0);
1064 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1066 if (!list_empty(&vha->gnl.fcports)) {
1068 list_for_each_entry_safe(fcport, tf, &vha->gnl.fcports,
1070 list_del_init(&fcport->gnl_entry);
1071 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1072 if (qla24xx_post_gnl_work(vha, fcport) == QLA_SUCCESS)
1076 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1081 int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
1084 struct srb_iocb *mbx;
1085 int rval = QLA_FUNCTION_FAILED;
1086 unsigned long flags;
1089 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
1092 ql_dbg(ql_dbg_disc, vha, 0x20d9,
1093 "Async-gnlist WWPN %8phC \n", fcport->port_name);
1095 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1096 fcport->flags |= FCF_ASYNC_SENT;
1097 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
1098 fcport->last_rscn_gen = fcport->rscn_gen;
1099 fcport->last_login_gen = fcport->login_gen;
1101 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
1102 if (vha->gnl.sent) {
1103 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1107 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1109 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1113 sp->type = SRB_MB_IOCB;
1114 sp->name = "gnlist";
1115 sp->gen1 = fcport->rscn_gen;
1116 sp->gen2 = fcport->login_gen;
1118 mbx = &sp->u.iocb_cmd;
1119 mbx->timeout = qla2x00_async_iocb_timeout;
1120 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
1122 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1123 mb[0] = MBC_PORT_NODE_NAME_LIST;
1124 mb[1] = BIT_2 | BIT_3;
1125 mb[2] = MSW(vha->gnl.ldma);
1126 mb[3] = LSW(vha->gnl.ldma);
1127 mb[6] = MSW(MSD(vha->gnl.ldma));
1128 mb[7] = LSW(MSD(vha->gnl.ldma));
1129 mb[8] = vha->gnl.size;
1130 mb[9] = vha->vp_idx;
1132 sp->done = qla24xx_async_gnl_sp_done;
1134 ql_dbg(ql_dbg_disc, vha, 0x20da,
1135 "Async-%s - OUT WWPN %8phC hndl %x\n",
1136 sp->name, fcport->port_name, sp->handle);
1138 rval = qla2x00_start_sp(sp);
1139 if (rval != QLA_SUCCESS)
1147 fcport->flags &= ~(FCF_ASYNC_ACTIVE | FCF_ASYNC_SENT);
1151 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1153 struct qla_work_evt *e;
1155 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
1157 return QLA_FUNCTION_FAILED;
1159 e->u.fcport.fcport = fcport;
1160 fcport->flags |= FCF_ASYNC_ACTIVE;
1161 return qla2x00_post_work(vha, e);
1164 static void qla24xx_async_gpdb_sp_done(srb_t *sp, int res)
1166 struct scsi_qla_host *vha = sp->vha;
1167 struct qla_hw_data *ha = vha->hw;
1168 fc_port_t *fcport = sp->fcport;
1169 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
1170 struct event_arg ea;
1172 ql_dbg(ql_dbg_disc, vha, 0x20db,
1173 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
1174 sp->name, res, fcport->port_name, mb[1], mb[2]);
1176 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1178 if (res == QLA_FUNCTION_TIMEOUT)
1181 memset(&ea, 0, sizeof(ea));
1185 qla24xx_handle_gpdb_event(vha, &ea);
1188 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
1189 sp->u.iocb_cmd.u.mbx.in_dma);
1194 static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1196 struct qla_work_evt *e;
1198 if (vha->host->active_mode == MODE_TARGET)
1199 return QLA_FUNCTION_FAILED;
1201 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
1203 return QLA_FUNCTION_FAILED;
1205 e->u.fcport.fcport = fcport;
1207 return qla2x00_post_work(vha, e);
1210 static void qla2x00_async_prli_sp_done(srb_t *sp, int res)
1212 struct scsi_qla_host *vha = sp->vha;
1213 struct srb_iocb *lio = &sp->u.iocb_cmd;
1214 struct event_arg ea;
1216 ql_dbg(ql_dbg_disc, vha, 0x2129,
1217 "%s %8phC res %d \n", __func__,
1218 sp->fcport->port_name, res);
1220 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1222 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
1223 memset(&ea, 0, sizeof(ea));
1224 ea.fcport = sp->fcport;
1225 ea.data[0] = lio->u.logio.data[0];
1226 ea.data[1] = lio->u.logio.data[1];
1227 ea.iop[0] = lio->u.logio.iop[0];
1228 ea.iop[1] = lio->u.logio.iop[1];
1231 qla24xx_handle_prli_done_event(vha, &ea);
1238 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
1241 struct srb_iocb *lio;
1242 int rval = QLA_FUNCTION_FAILED;
1244 if (!vha->flags.online) {
1245 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1246 __func__, __LINE__, fcport->port_name);
1250 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
1251 fcport->fw_login_state == DSC_LS_PRLI_PEND) &&
1252 qla_dual_mode_enabled(vha)) {
1253 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1254 __func__, __LINE__, fcport->port_name);
1258 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1262 fcport->flags |= FCF_ASYNC_SENT;
1263 fcport->logout_completed = 0;
1265 sp->type = SRB_PRLI_CMD;
1268 lio = &sp->u.iocb_cmd;
1269 lio->timeout = qla2x00_async_iocb_timeout;
1270 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1272 sp->done = qla2x00_async_prli_sp_done;
1273 lio->u.logio.flags = 0;
1275 if (NVME_TARGET(vha->hw, fcport))
1276 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
1278 ql_dbg(ql_dbg_disc, vha, 0x211b,
1279 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d fc4type %x priority %x %s.\n",
1280 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24,
1281 fcport->login_retry, fcport->fc4_type, vha->hw->fc4_type_priority,
1282 NVME_TARGET(vha->hw, fcport) ? "nvme" : "fcp");
1284 rval = qla2x00_start_sp(sp);
1285 if (rval != QLA_SUCCESS) {
1286 fcport->flags |= FCF_LOGIN_NEEDED;
1287 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1295 fcport->flags &= ~FCF_ASYNC_SENT;
1299 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1301 struct qla_work_evt *e;
1303 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
1305 return QLA_FUNCTION_FAILED;
1307 e->u.fcport.fcport = fcport;
1308 e->u.fcport.opt = opt;
1309 fcport->flags |= FCF_ASYNC_ACTIVE;
1310 return qla2x00_post_work(vha, e);
1313 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1316 struct srb_iocb *mbx;
1317 int rval = QLA_FUNCTION_FAILED;
1320 struct port_database_24xx *pd;
1321 struct qla_hw_data *ha = vha->hw;
1323 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
1324 fcport->loop_id == FC_NO_LOOP_ID) {
1325 ql_log(ql_log_warn, vha, 0xffff,
1326 "%s: %8phC - not sending command.\n",
1327 __func__, fcport->port_name);
1331 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1335 qla2x00_set_fcport_disc_state(fcport, DSC_GPDB);
1337 fcport->flags |= FCF_ASYNC_SENT;
1338 sp->type = SRB_MB_IOCB;
1340 sp->gen1 = fcport->rscn_gen;
1341 sp->gen2 = fcport->login_gen;
1343 mbx = &sp->u.iocb_cmd;
1344 mbx->timeout = qla2x00_async_iocb_timeout;
1345 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1347 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1349 ql_log(ql_log_warn, vha, 0xd043,
1350 "Failed to allocate port database structure.\n");
1354 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1355 mb[0] = MBC_GET_PORT_DATABASE;
1356 mb[1] = fcport->loop_id;
1357 mb[2] = MSW(pd_dma);
1358 mb[3] = LSW(pd_dma);
1359 mb[6] = MSW(MSD(pd_dma));
1360 mb[7] = LSW(MSD(pd_dma));
1361 mb[9] = vha->vp_idx;
1365 mbx->u.mbx.in_dma = pd_dma;
1367 sp->done = qla24xx_async_gpdb_sp_done;
1369 ql_dbg(ql_dbg_disc, vha, 0x20dc,
1370 "Async-%s %8phC hndl %x opt %x\n",
1371 sp->name, fcport->port_name, sp->handle, opt);
1373 rval = qla2x00_start_sp(sp);
1374 if (rval != QLA_SUCCESS)
1380 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1383 fcport->flags &= ~FCF_ASYNC_SENT;
1385 fcport->flags &= ~FCF_ASYNC_ACTIVE;
1386 qla24xx_post_gpdb_work(vha, fcport, opt);
1391 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1393 unsigned long flags;
1395 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1396 ea->fcport->login_gen++;
1397 ea->fcport->deleted = 0;
1398 ea->fcport->logout_on_delete = 1;
1400 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1401 vha->fcport_count++;
1402 ea->fcport->login_succ = 1;
1404 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1405 qla24xx_sched_upd_fcport(ea->fcport);
1406 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1407 } else if (ea->fcport->login_succ) {
1409 * We have an existing session. A late RSCN delivery
1410 * must have triggered the session to be re-validate.
1411 * Session is still valid.
1413 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1414 "%s %d %8phC session revalidate success\n",
1415 __func__, __LINE__, ea->fcport->port_name);
1416 qla2x00_set_fcport_disc_state(ea->fcport, DSC_LOGIN_COMPLETE);
1418 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1422 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1424 fc_port_t *fcport = ea->fcport;
1425 struct port_database_24xx *pd;
1426 struct srb *sp = ea->sp;
1429 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1431 fcport->flags &= ~FCF_ASYNC_SENT;
1433 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1434 "%s %8phC DS %d LS %d fc4_type %x rc %d\n", __func__,
1435 fcport->port_name, fcport->disc_state, pd->current_login_state,
1436 fcport->fc4_type, ea->rc);
1438 if (fcport->disc_state == DSC_DELETE_PEND)
1441 if (NVME_TARGET(vha->hw, fcport))
1442 ls = pd->current_login_state >> 4;
1444 ls = pd->current_login_state & 0xf;
1446 if (ea->sp->gen2 != fcport->login_gen) {
1447 /* target side must have changed it. */
1449 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1450 "%s %8phC generation changed\n",
1451 __func__, fcport->port_name);
1453 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1454 qla_rscn_replay(fcport);
1455 qlt_schedule_sess_for_deletion(fcport);
1460 case PDS_PRLI_COMPLETE:
1461 __qla24xx_parse_gpdb(vha, fcport, pd);
1463 case PDS_PLOGI_PENDING:
1464 case PDS_PLOGI_COMPLETE:
1465 case PDS_PRLI_PENDING:
1466 case PDS_PRLI2_PENDING:
1467 /* Set discovery state back to GNL to Relogin attempt */
1468 if (qla_dual_mode_enabled(vha) ||
1469 qla_ini_mode_enabled(vha)) {
1470 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
1471 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1474 case PDS_LOGO_PENDING:
1475 case PDS_PORT_UNAVAILABLE:
1477 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1478 __func__, __LINE__, fcport->port_name);
1479 qlt_schedule_sess_for_deletion(fcport);
1482 __qla24xx_handle_gpdb_event(vha, ea);
1485 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1490 if (qla_tgt_mode_enabled(vha))
1493 if (qla_dual_mode_enabled(vha)) {
1494 if (N2N_TOPO(vha->hw)) {
1497 mywwn = wwn_to_u64(vha->port_name);
1498 wwn = wwn_to_u64(fcport->port_name);
1501 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1502 && time_after_eq(jiffies,
1503 fcport->plogi_nack_done_deadline))
1509 /* initiator mode */
1513 if (login && fcport->login_retry) {
1514 fcport->login_retry--;
1515 if (fcport->loop_id == FC_NO_LOOP_ID) {
1516 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1517 rc = qla2x00_find_new_loop_id(vha, fcport);
1519 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1520 "%s %d %8phC post del sess - out of loopid\n",
1521 __func__, __LINE__, fcport->port_name);
1522 fcport->scan_state = 0;
1523 qlt_schedule_sess_for_deletion(fcport);
1527 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1528 "%s %d %8phC post login\n",
1529 __func__, __LINE__, fcport->port_name);
1530 qla2x00_post_async_login_work(vha, fcport, NULL);
1534 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1540 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1541 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d\n",
1542 __func__, fcport->port_name, fcport->disc_state,
1543 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1544 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1545 fcport->login_gen, fcport->loop_id, fcport->scan_state);
1547 if (fcport->scan_state != QLA_FCPORT_FOUND)
1550 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1551 qla_dual_mode_enabled(vha) &&
1552 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1553 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1556 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP &&
1557 !N2N_TOPO(vha->hw)) {
1558 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1559 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1564 /* Target won't initiate port login if fabric is present */
1565 if (vha->host->active_mode == MODE_TARGET && !N2N_TOPO(vha->hw))
1568 if (fcport->flags & FCF_ASYNC_SENT) {
1569 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1573 switch (fcport->disc_state) {
1575 wwn = wwn_to_u64(fcport->node_name);
1576 switch (vha->hw->current_topology) {
1578 if (fcport_is_smaller(fcport)) {
1579 /* this adapter is bigger */
1580 if (fcport->login_retry) {
1581 if (fcport->loop_id == FC_NO_LOOP_ID) {
1582 qla2x00_find_new_loop_id(vha,
1584 fcport->fw_login_state =
1585 DSC_LS_PORT_UNAVAIL;
1587 fcport->login_retry--;
1588 qla_post_els_plogi_work(vha, fcport);
1590 ql_log(ql_log_info, vha, 0x705d,
1591 "Unable to reach remote port %8phC",
1595 qla24xx_post_gnl_work(vha, fcport);
1600 ql_dbg(ql_dbg_disc, vha, 0xffff,
1601 "%s %d %8phC post GNNID\n",
1602 __func__, __LINE__, fcport->port_name);
1603 qla24xx_post_gnnid_work(vha, fcport);
1604 } else if (fcport->loop_id == FC_NO_LOOP_ID) {
1605 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1606 "%s %d %8phC post gnl\n",
1607 __func__, __LINE__, fcport->port_name);
1608 qla24xx_post_gnl_work(vha, fcport);
1610 qla_chk_n2n_b4_login(vha, fcport);
1617 switch (vha->hw->current_topology) {
1619 if ((fcport->current_login_state & 0xf) == 0x6) {
1620 ql_dbg(ql_dbg_disc, vha, 0x2118,
1621 "%s %d %8phC post GPDB work\n",
1622 __func__, __LINE__, fcport->port_name);
1623 fcport->chip_reset =
1624 vha->hw->base_qpair->chip_reset;
1625 qla24xx_post_gpdb_work(vha, fcport, 0);
1627 ql_dbg(ql_dbg_disc, vha, 0x2118,
1628 "%s %d %8phC post %s PRLI\n",
1629 __func__, __LINE__, fcport->port_name,
1630 NVME_TARGET(vha->hw, fcport) ? "NVME" :
1632 qla24xx_post_prli_work(vha, fcport);
1636 if (fcport->login_pause) {
1637 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1638 "%s %d %8phC exit\n",
1641 fcport->last_rscn_gen = fcport->rscn_gen;
1642 fcport->last_login_gen = fcport->login_gen;
1643 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1646 qla_chk_n2n_b4_login(vha, fcport);
1651 case DSC_LOGIN_FAILED:
1652 if (N2N_TOPO(vha->hw))
1653 qla_chk_n2n_b4_login(vha, fcport);
1655 qlt_schedule_sess_for_deletion(fcport);
1658 case DSC_LOGIN_COMPLETE:
1659 /* recheck login state */
1660 data[0] = data[1] = 0;
1661 qla2x00_post_async_adisc_work(vha, fcport, data);
1664 case DSC_LOGIN_PEND:
1665 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1666 qla24xx_post_prli_work(vha, fcport);
1669 case DSC_UPD_FCPORT:
1670 sec = jiffies_to_msecs(jiffies -
1671 fcport->jiffies_at_registration)/1000;
1672 if (fcport->sec_since_registration < sec && sec &&
1674 fcport->sec_since_registration = sec;
1675 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
1676 "%s %8phC - Slow Rport registration(%d Sec)\n",
1677 __func__, fcport->port_name, sec);
1680 if (fcport->next_disc_state != DSC_DELETE_PEND)
1681 fcport->next_disc_state = DSC_ADISC;
1682 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1692 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1693 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1695 struct qla_work_evt *e;
1697 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1699 return QLA_FUNCTION_FAILED;
1701 e->u.new_sess.id = *id;
1702 e->u.new_sess.pla = pla;
1703 e->u.new_sess.fc4_type = fc4_type;
1704 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1706 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1708 return qla2x00_post_work(vha, e);
1711 void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
1714 unsigned long flags;
1716 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1718 fcport->scan_needed = 1;
1722 spin_lock_irqsave(&vha->work_lock, flags);
1723 if (vha->scan.scan_flags == 0) {
1724 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s: schedule\n", __func__);
1725 vha->scan.scan_flags |= SF_QUEUED;
1726 schedule_delayed_work(&vha->scan.scan_work, 5);
1728 spin_unlock_irqrestore(&vha->work_lock, flags);
1731 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1732 struct event_arg *ea)
1734 fc_port_t *fcport = ea->fcport;
1736 if (test_bit(UNLOADING, &vha->dpc_flags))
1739 ql_dbg(ql_dbg_disc, vha, 0x2102,
1740 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1741 __func__, fcport->port_name, fcport->disc_state,
1742 fcport->fw_login_state, fcport->login_pause,
1743 fcport->deleted, fcport->conflict,
1744 fcport->last_rscn_gen, fcport->rscn_gen,
1745 fcport->last_login_gen, fcport->login_gen,
1748 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1749 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gnl\n",
1750 __func__, __LINE__, fcport->port_name);
1751 qla24xx_post_gnl_work(vha, fcport);
1755 qla24xx_fcport_handle_login(vha, fcport);
1758 void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
1759 struct event_arg *ea)
1761 /* for pure Target Mode, PRLI will not be initiated */
1762 if (vha->host->active_mode == MODE_TARGET)
1765 ql_dbg(ql_dbg_disc, vha, 0x2118,
1766 "%s %d %8phC post PRLI\n",
1767 __func__, __LINE__, ea->fcport->port_name);
1768 qla24xx_post_prli_work(vha, ea->fcport);
1772 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1773 * to be consumed by the fcport
1775 void qla_rscn_replay(fc_port_t *fcport)
1777 struct event_arg ea;
1779 switch (fcport->disc_state) {
1780 case DSC_DELETE_PEND:
1786 if (fcport->scan_needed) {
1787 memset(&ea, 0, sizeof(ea));
1788 ea.id = fcport->d_id;
1789 ea.id.b.rsvd_1 = RSCN_PORT_ADDR;
1790 qla2x00_handle_rscn(fcport->vha, &ea);
1795 qla2x00_tmf_iocb_timeout(void *data)
1798 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1800 unsigned long flags;
1802 rc = qla24xx_async_abort_cmd(sp, false);
1804 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
1805 for (h = 1; h < sp->qpair->req->num_outstanding_cmds; h++) {
1806 if (sp->qpair->req->outstanding_cmds[h] == sp) {
1807 sp->qpair->req->outstanding_cmds[h] = NULL;
1811 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
1812 tmf->u.tmf.comp_status = cpu_to_le16(CS_TIMEOUT);
1813 tmf->u.tmf.data = QLA_FUNCTION_FAILED;
1814 complete(&tmf->u.tmf.comp);
1818 static void qla2x00_tmf_sp_done(srb_t *sp, int res)
1820 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1822 complete(&tmf->u.tmf.comp);
1826 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
1829 struct scsi_qla_host *vha = fcport->vha;
1830 struct srb_iocb *tm_iocb;
1832 int rval = QLA_FUNCTION_FAILED;
1834 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1838 tm_iocb = &sp->u.iocb_cmd;
1839 sp->type = SRB_TM_CMD;
1842 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1843 init_completion(&tm_iocb->u.tmf.comp);
1844 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1846 tm_iocb->u.tmf.flags = flags;
1847 tm_iocb->u.tmf.lun = lun;
1848 tm_iocb->u.tmf.data = tag;
1849 sp->done = qla2x00_tmf_sp_done;
1851 ql_dbg(ql_dbg_taskm, vha, 0x802f,
1852 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1853 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1854 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1856 rval = qla2x00_start_sp(sp);
1857 if (rval != QLA_SUCCESS)
1859 wait_for_completion(&tm_iocb->u.tmf.comp);
1861 rval = tm_iocb->u.tmf.data;
1863 if (rval != QLA_SUCCESS) {
1864 ql_log(ql_log_warn, vha, 0x8030,
1865 "TM IOCB failed (%x).\n", rval);
1868 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1869 flags = tm_iocb->u.tmf.flags;
1870 lun = (uint16_t)tm_iocb->u.tmf.lun;
1872 /* Issue Marker IOCB */
1873 qla2x00_marker(vha, vha->hw->base_qpair,
1874 fcport->loop_id, lun,
1875 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1880 fcport->flags &= ~FCF_ASYNC_SENT;
1886 qla24xx_async_abort_command(srb_t *sp)
1888 unsigned long flags = 0;
1891 fc_port_t *fcport = sp->fcport;
1892 struct qla_qpair *qpair = sp->qpair;
1893 struct scsi_qla_host *vha = fcport->vha;
1894 struct req_que *req = qpair->req;
1896 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1897 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1898 if (req->outstanding_cmds[handle] == sp)
1901 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1903 if (handle == req->num_outstanding_cmds) {
1904 /* Command not found. */
1905 return QLA_FUNCTION_FAILED;
1907 if (sp->type == SRB_FXIOCB_DCMD)
1908 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1909 FXDISC_ABORT_IOCTL);
1911 return qla24xx_async_abort_cmd(sp, true);
1915 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1917 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
1920 switch (ea->data[0]) {
1921 case MBS_COMMAND_COMPLETE:
1922 ql_dbg(ql_dbg_disc, vha, 0x2118,
1923 "%s %d %8phC post gpdb\n",
1924 __func__, __LINE__, ea->fcport->port_name);
1926 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1927 ea->fcport->logout_on_delete = 1;
1928 ea->fcport->nvme_prli_service_param = ea->iop[0];
1929 if (ea->iop[0] & NVME_PRLI_SP_FIRST_BURST)
1930 ea->fcport->nvme_first_burst_size =
1931 (ea->iop[1] & 0xffff) * 512;
1933 ea->fcport->nvme_first_burst_size = 0;
1934 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1937 if ((ea->iop[0] == LSC_SCODE_ELS_REJECT) &&
1938 (ea->iop[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
1939 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1940 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
1944 ql_dbg(ql_dbg_disc, vha, 0x2118,
1945 "%s %d %8phC priority %s, fc4type %x\n",
1946 __func__, __LINE__, ea->fcport->port_name,
1947 vha->hw->fc4_type_priority == FC4_PRIORITY_FCP ?
1948 "FCP" : "NVMe", ea->fcport->fc4_type);
1950 if (N2N_TOPO(vha->hw)) {
1951 if (vha->hw->fc4_type_priority == FC4_PRIORITY_NVME) {
1952 ea->fcport->fc4_type &= ~FS_FC4TYPE_NVME;
1953 ea->fcport->fc4_type |= FS_FC4TYPE_FCP;
1955 ea->fcport->fc4_type &= ~FS_FC4TYPE_FCP;
1956 ea->fcport->fc4_type |= FS_FC4TYPE_NVME;
1959 if (ea->fcport->n2n_link_reset_cnt < 3) {
1960 ea->fcport->n2n_link_reset_cnt++;
1961 vha->relogin_jif = jiffies + 2 * HZ;
1963 * PRLI failed. Reset link to kick start
1966 set_bit(N2N_LINK_RESET, &vha->dpc_flags);
1968 ql_log(ql_log_warn, vha, 0x2119,
1969 "%s %d %8phC Unable to reconnect\n",
1971 ea->fcport->port_name);
1975 * switch connect. login failed. Take connection down
1976 * and allow relogin to retrigger
1978 if (NVME_FCP_TARGET(ea->fcport)) {
1979 ql_dbg(ql_dbg_disc, vha, 0x2118,
1980 "%s %d %8phC post %s prli\n",
1982 ea->fcport->port_name,
1983 (ea->fcport->fc4_type & FS_FC4TYPE_NVME)
1985 if (vha->hw->fc4_type_priority == FC4_PRIORITY_NVME)
1986 ea->fcport->fc4_type &= ~FS_FC4TYPE_NVME;
1988 ea->fcport->fc4_type &= ~FS_FC4TYPE_FCP;
1991 ea->fcport->flags &= ~FCF_ASYNC_SENT;
1992 ea->fcport->keep_nport_handle = 0;
1993 ea->fcport->logout_on_delete = 1;
1994 qlt_schedule_sess_for_deletion(ea->fcport);
2001 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
2003 port_id_t cid; /* conflict Nport id */
2005 struct fc_port *conflict_fcport;
2006 unsigned long flags;
2007 struct fc_port *fcport = ea->fcport;
2009 ql_dbg(ql_dbg_disc, vha, 0xffff,
2010 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
2011 __func__, fcport->port_name, fcport->disc_state,
2012 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
2013 ea->sp->gen1, fcport->rscn_gen,
2014 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
2016 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
2017 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
2018 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2019 "%s %d %8phC Remote is trying to login\n",
2020 __func__, __LINE__, fcport->port_name);
2024 if ((fcport->disc_state == DSC_DELETE_PEND) ||
2025 (fcport->disc_state == DSC_DELETED)) {
2026 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2030 if (ea->sp->gen2 != fcport->login_gen) {
2031 /* target side must have changed it. */
2032 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2033 "%s %8phC generation changed\n",
2034 __func__, fcport->port_name);
2035 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2037 } else if (ea->sp->gen1 != fcport->rscn_gen) {
2038 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2039 "%s %8phC RSCN generation changed\n",
2040 __func__, fcport->port_name);
2041 qla_rscn_replay(fcport);
2042 qlt_schedule_sess_for_deletion(fcport);
2046 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
2049 switch (ea->data[0]) {
2050 case MBS_COMMAND_COMPLETE:
2052 * Driver must validate login state - If PRLI not complete,
2053 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
2056 if (NVME_TARGET(vha->hw, ea->fcport)) {
2057 ql_dbg(ql_dbg_disc, vha, 0x2117,
2058 "%s %d %8phC post prli\n",
2059 __func__, __LINE__, ea->fcport->port_name);
2060 qla24xx_post_prli_work(vha, ea->fcport);
2062 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2063 "%s %d %8phC LoopID 0x%x in use with %06x. post gpdb\n",
2064 __func__, __LINE__, ea->fcport->port_name,
2065 ea->fcport->loop_id, ea->fcport->d_id.b24);
2067 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2068 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2069 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2070 ea->fcport->logout_on_delete = 1;
2071 ea->fcport->send_els_logo = 0;
2072 ea->fcport->fw_login_state = DSC_LS_PRLI_COMP;
2073 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2075 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2078 case MBS_COMMAND_ERROR:
2079 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
2080 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
2082 ea->fcport->flags &= ~FCF_ASYNC_SENT;
2083 qla2x00_set_fcport_disc_state(ea->fcport, DSC_LOGIN_FAILED);
2084 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
2085 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2087 qla2x00_mark_device_lost(vha, ea->fcport, 1);
2089 case MBS_LOOP_ID_USED:
2090 /* data[1] = IO PARAM 1 = nport ID */
2091 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
2092 cid.b.area = (ea->iop[1] >> 8) & 0xff;
2093 cid.b.al_pa = ea->iop[1] & 0xff;
2096 ql_dbg(ql_dbg_disc, vha, 0x20ec,
2097 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2098 __func__, __LINE__, ea->fcport->port_name,
2099 ea->fcport->loop_id, cid.b24);
2101 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2102 ea->fcport->loop_id = FC_NO_LOOP_ID;
2103 qla24xx_post_gnl_work(vha, ea->fcport);
2105 case MBS_PORT_ID_USED:
2106 lid = ea->iop[1] & 0xffff;
2107 qlt_find_sess_invalidate_other(vha,
2108 wwn_to_u64(ea->fcport->port_name),
2109 ea->fcport->d_id, lid, &conflict_fcport);
2111 if (conflict_fcport) {
2113 * Another fcport share the same loop_id/nport id.
2114 * Conflict fcport needs to finish cleanup before this
2115 * fcport can proceed to login.
2117 conflict_fcport->conflict = ea->fcport;
2118 ea->fcport->login_pause = 1;
2120 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2121 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
2122 __func__, __LINE__, ea->fcport->port_name,
2123 ea->fcport->d_id.b24, lid);
2125 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2126 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2127 __func__, __LINE__, ea->fcport->port_name,
2128 ea->fcport->d_id.b24, lid);
2130 qla2x00_clear_loop_id(ea->fcport);
2131 set_bit(lid, vha->hw->loop_id_map);
2132 ea->fcport->loop_id = lid;
2133 ea->fcport->keep_nport_handle = 0;
2134 ea->fcport->logout_on_delete = 1;
2135 qlt_schedule_sess_for_deletion(ea->fcport);
2142 /****************************************************************************/
2143 /* QLogic ISP2x00 Hardware Support Functions. */
2144 /****************************************************************************/
2147 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
2149 int rval = QLA_SUCCESS;
2150 struct qla_hw_data *ha = vha->hw;
2151 uint32_t idc_major_ver, idc_minor_ver;
2154 qla83xx_idc_lock(vha, 0);
2156 /* SV: TODO: Assign initialization timeout from
2157 * flash-info / other param
2159 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
2160 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
2162 /* Set our fcoe function presence */
2163 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
2164 ql_dbg(ql_dbg_p3p, vha, 0xb077,
2165 "Error while setting DRV-Presence.\n");
2166 rval = QLA_FUNCTION_FAILED;
2170 /* Decide the reset ownership */
2171 qla83xx_reset_ownership(vha);
2174 * On first protocol driver load:
2175 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2177 * Others: Check compatibility with current IDC Major version.
2179 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
2180 if (ha->flags.nic_core_reset_owner) {
2181 /* Set IDC Major version */
2182 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
2183 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
2185 /* Clearing IDC-Lock-Recovery register */
2186 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
2187 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
2189 * Clear further IDC participation if we are not compatible with
2190 * the current IDC Major Version.
2192 ql_log(ql_log_warn, vha, 0xb07d,
2193 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2194 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
2195 __qla83xx_clear_drv_presence(vha);
2196 rval = QLA_FUNCTION_FAILED;
2199 /* Each function sets its supported Minor version. */
2200 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
2201 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
2202 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
2204 if (ha->flags.nic_core_reset_owner) {
2205 memset(config, 0, sizeof(config));
2206 if (!qla81xx_get_port_config(vha, config))
2207 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
2211 rval = qla83xx_idc_state_handler(vha);
2214 qla83xx_idc_unlock(vha, 0);
2220 * qla2x00_initialize_adapter
2224 * ha = adapter block pointer.
2230 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
2233 struct qla_hw_data *ha = vha->hw;
2234 struct req_que *req = ha->req_q_map[0];
2235 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2237 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2238 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2240 /* Clear adapter flags. */
2241 vha->flags.online = 0;
2242 ha->flags.chip_reset_done = 0;
2243 vha->flags.reset_active = 0;
2244 ha->flags.pci_channel_io_perm_failure = 0;
2245 ha->flags.eeh_busy = 0;
2246 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2247 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
2248 atomic_set(&vha->loop_state, LOOP_DOWN);
2249 vha->device_flags = DFLG_NO_CABLE;
2251 vha->flags.management_server_logged_in = 0;
2252 vha->marker_needed = 0;
2253 ha->isp_abort_cnt = 0;
2254 ha->beacon_blink_led = 0;
2256 set_bit(0, ha->req_qid_map);
2257 set_bit(0, ha->rsp_qid_map);
2259 ql_dbg(ql_dbg_init, vha, 0x0040,
2260 "Configuring PCI space...\n");
2261 rval = ha->isp_ops->pci_config(vha);
2263 ql_log(ql_log_warn, vha, 0x0044,
2264 "Unable to configure PCI space.\n");
2268 ha->isp_ops->reset_chip(vha);
2270 /* Check for secure flash support */
2271 if (IS_QLA28XX(ha)) {
2272 if (rd_reg_word(®->mailbox12) & BIT_0)
2273 ha->flags.secure_adapter = 1;
2274 ql_log(ql_log_info, vha, 0xffff, "Secure Adapter: %s\n",
2275 (ha->flags.secure_adapter) ? "Yes" : "No");
2279 rval = qla2xxx_get_flash_info(vha);
2281 ql_log(ql_log_fatal, vha, 0x004f,
2282 "Unable to validate FLASH data.\n");
2286 if (IS_QLA8044(ha)) {
2287 qla8044_read_reset_template(vha);
2289 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2290 * If DONRESET_BIT0 is set, drivers should not set dev_state
2291 * to NEED_RESET. But if NEED_RESET is set, drivers should
2292 * should honor the reset. */
2293 if (ql2xdontresethba == 1)
2294 qla8044_set_idc_dontreset(vha);
2297 ha->isp_ops->get_flash_version(vha, req->ring);
2298 ql_dbg(ql_dbg_init, vha, 0x0061,
2299 "Configure NVRAM parameters...\n");
2301 /* Let priority default to FCP, can be overridden by nvram_config */
2302 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2304 ha->isp_ops->nvram_config(vha);
2306 if (ha->fc4_type_priority != FC4_PRIORITY_FCP &&
2307 ha->fc4_type_priority != FC4_PRIORITY_NVME)
2308 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2310 ql_log(ql_log_info, vha, 0xffff, "FC4 priority set to %s\n",
2311 ha->fc4_type_priority == FC4_PRIORITY_FCP ? "FCP" : "NVMe");
2313 if (ha->flags.disable_serdes) {
2314 /* Mask HBA via NVRAM settings? */
2315 ql_log(ql_log_info, vha, 0x0077,
2316 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
2317 return QLA_FUNCTION_FAILED;
2320 ql_dbg(ql_dbg_init, vha, 0x0078,
2321 "Verifying loaded RISC code...\n");
2323 /* If smartsan enabled then require fdmi and rdp enabled */
2329 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
2330 rval = ha->isp_ops->chip_diag(vha);
2333 rval = qla2x00_setup_chip(vha);
2338 if (IS_QLA84XX(ha)) {
2339 ha->cs84xx = qla84xx_get_chip(vha);
2341 ql_log(ql_log_warn, vha, 0x00d0,
2342 "Unable to configure ISP84XX.\n");
2343 return QLA_FUNCTION_FAILED;
2347 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2348 rval = qla2x00_init_rings(vha);
2350 /* No point in continuing if firmware initialization failed. */
2351 if (rval != QLA_SUCCESS)
2354 ha->flags.chip_reset_done = 1;
2356 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2357 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2358 rval = qla84xx_init_chip(vha);
2359 if (rval != QLA_SUCCESS) {
2360 ql_log(ql_log_warn, vha, 0x00d4,
2361 "Unable to initialize ISP84XX.\n");
2362 qla84xx_put_chip(vha);
2366 /* Load the NIC Core f/w if we are the first protocol driver. */
2367 if (IS_QLA8031(ha)) {
2368 rval = qla83xx_nic_core_fw_load(vha);
2370 ql_log(ql_log_warn, vha, 0x0124,
2371 "Error in initializing NIC Core f/w.\n");
2374 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2375 qla24xx_read_fcp_prio_cfg(vha);
2377 if (IS_P3P_TYPE(ha))
2378 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2380 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2386 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2389 * Returns 0 on success.
2392 qla2100_pci_config(scsi_qla_host_t *vha)
2395 unsigned long flags;
2396 struct qla_hw_data *ha = vha->hw;
2397 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2399 pci_set_master(ha->pdev);
2400 pci_try_set_mwi(ha->pdev);
2402 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2403 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2404 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2406 pci_disable_rom(ha->pdev);
2408 /* Get PCI bus information. */
2409 spin_lock_irqsave(&ha->hardware_lock, flags);
2410 ha->pci_attr = rd_reg_word(®->ctrl_status);
2411 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2417 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2420 * Returns 0 on success.
2423 qla2300_pci_config(scsi_qla_host_t *vha)
2426 unsigned long flags = 0;
2428 struct qla_hw_data *ha = vha->hw;
2429 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2431 pci_set_master(ha->pdev);
2432 pci_try_set_mwi(ha->pdev);
2434 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2435 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2437 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2438 w &= ~PCI_COMMAND_INTX_DISABLE;
2439 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2442 * If this is a 2300 card and not 2312, reset the
2443 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2444 * the 2310 also reports itself as a 2300 so we need to get the
2445 * fb revision level -- a 6 indicates it really is a 2300 and
2448 if (IS_QLA2300(ha)) {
2449 spin_lock_irqsave(&ha->hardware_lock, flags);
2452 wrt_reg_word(®->hccr, HCCR_PAUSE_RISC);
2453 for (cnt = 0; cnt < 30000; cnt++) {
2454 if ((rd_reg_word(®->hccr) & HCCR_RISC_PAUSE) != 0)
2460 /* Select FPM registers. */
2461 wrt_reg_word(®->ctrl_status, 0x20);
2462 rd_reg_word(®->ctrl_status);
2464 /* Get the fb rev level */
2465 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2467 if (ha->fb_rev == FPM_2300)
2468 pci_clear_mwi(ha->pdev);
2470 /* Deselect FPM registers. */
2471 wrt_reg_word(®->ctrl_status, 0x0);
2472 rd_reg_word(®->ctrl_status);
2474 /* Release RISC module. */
2475 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
2476 for (cnt = 0; cnt < 30000; cnt++) {
2477 if ((rd_reg_word(®->hccr) & HCCR_RISC_PAUSE) == 0)
2483 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2486 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2488 pci_disable_rom(ha->pdev);
2490 /* Get PCI bus information. */
2491 spin_lock_irqsave(&ha->hardware_lock, flags);
2492 ha->pci_attr = rd_reg_word(®->ctrl_status);
2493 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2499 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2502 * Returns 0 on success.
2505 qla24xx_pci_config(scsi_qla_host_t *vha)
2508 unsigned long flags = 0;
2509 struct qla_hw_data *ha = vha->hw;
2510 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2512 pci_set_master(ha->pdev);
2513 pci_try_set_mwi(ha->pdev);
2515 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2516 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2517 w &= ~PCI_COMMAND_INTX_DISABLE;
2518 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2520 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2522 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2523 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2524 pcix_set_mmrbc(ha->pdev, 2048);
2526 /* PCIe -- adjust Maximum Read Request Size (2048). */
2527 if (pci_is_pcie(ha->pdev))
2528 pcie_set_readrq(ha->pdev, 4096);
2530 pci_disable_rom(ha->pdev);
2532 ha->chip_revision = ha->pdev->revision;
2534 /* Get PCI bus information. */
2535 spin_lock_irqsave(&ha->hardware_lock, flags);
2536 ha->pci_attr = rd_reg_dword(®->ctrl_status);
2537 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2543 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2546 * Returns 0 on success.
2549 qla25xx_pci_config(scsi_qla_host_t *vha)
2552 struct qla_hw_data *ha = vha->hw;
2554 pci_set_master(ha->pdev);
2555 pci_try_set_mwi(ha->pdev);
2557 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2558 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2559 w &= ~PCI_COMMAND_INTX_DISABLE;
2560 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2562 /* PCIe -- adjust Maximum Read Request Size (2048). */
2563 if (pci_is_pcie(ha->pdev))
2564 pcie_set_readrq(ha->pdev, 4096);
2566 pci_disable_rom(ha->pdev);
2568 ha->chip_revision = ha->pdev->revision;
2574 * qla2x00_isp_firmware() - Choose firmware image.
2577 * Returns 0 on success.
2580 qla2x00_isp_firmware(scsi_qla_host_t *vha)
2583 uint16_t loop_id, topo, sw_cap;
2584 uint8_t domain, area, al_pa;
2585 struct qla_hw_data *ha = vha->hw;
2587 /* Assume loading risc code */
2588 rval = QLA_FUNCTION_FAILED;
2590 if (ha->flags.disable_risc_code_load) {
2591 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
2593 /* Verify checksum of loaded RISC code. */
2594 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
2595 if (rval == QLA_SUCCESS) {
2596 /* And, verify we are not in ROM code. */
2597 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2598 &area, &domain, &topo, &sw_cap);
2603 ql_dbg(ql_dbg_init, vha, 0x007a,
2604 "**** Load RISC code ****.\n");
2610 * qla2x00_reset_chip() - Reset ISP chip.
2613 * Returns 0 on success.
2616 qla2x00_reset_chip(scsi_qla_host_t *vha)
2618 unsigned long flags = 0;
2619 struct qla_hw_data *ha = vha->hw;
2620 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2623 int rval = QLA_FUNCTION_FAILED;
2625 if (unlikely(pci_channel_offline(ha->pdev)))
2628 ha->isp_ops->disable_intrs(ha);
2630 spin_lock_irqsave(&ha->hardware_lock, flags);
2632 /* Turn off master enable */
2634 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2635 cmd &= ~PCI_COMMAND_MASTER;
2636 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2638 if (!IS_QLA2100(ha)) {
2640 wrt_reg_word(®->hccr, HCCR_PAUSE_RISC);
2641 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2642 for (cnt = 0; cnt < 30000; cnt++) {
2643 if ((rd_reg_word(®->hccr) &
2644 HCCR_RISC_PAUSE) != 0)
2649 rd_reg_word(®->hccr); /* PCI Posting. */
2653 /* Select FPM registers. */
2654 wrt_reg_word(®->ctrl_status, 0x20);
2655 rd_reg_word(®->ctrl_status); /* PCI Posting. */
2657 /* FPM Soft Reset. */
2658 wrt_reg_word(®->fpm_diag_config, 0x100);
2659 rd_reg_word(®->fpm_diag_config); /* PCI Posting. */
2661 /* Toggle Fpm Reset. */
2662 if (!IS_QLA2200(ha)) {
2663 wrt_reg_word(®->fpm_diag_config, 0x0);
2664 rd_reg_word(®->fpm_diag_config); /* PCI Posting. */
2667 /* Select frame buffer registers. */
2668 wrt_reg_word(®->ctrl_status, 0x10);
2669 rd_reg_word(®->ctrl_status); /* PCI Posting. */
2671 /* Reset frame buffer FIFOs. */
2672 if (IS_QLA2200(ha)) {
2673 WRT_FB_CMD_REG(ha, reg, 0xa000);
2674 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2676 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2678 /* Read back fb_cmd until zero or 3 seconds max */
2679 for (cnt = 0; cnt < 3000; cnt++) {
2680 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2686 /* Select RISC module registers. */
2687 wrt_reg_word(®->ctrl_status, 0);
2688 rd_reg_word(®->ctrl_status); /* PCI Posting. */
2690 /* Reset RISC processor. */
2691 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
2692 rd_reg_word(®->hccr); /* PCI Posting. */
2694 /* Release RISC processor. */
2695 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
2696 rd_reg_word(®->hccr); /* PCI Posting. */
2699 wrt_reg_word(®->hccr, HCCR_CLR_RISC_INT);
2700 wrt_reg_word(®->hccr, HCCR_CLR_HOST_INT);
2702 /* Reset ISP chip. */
2703 wrt_reg_word(®->ctrl_status, CSR_ISP_SOFT_RESET);
2705 /* Wait for RISC to recover from reset. */
2706 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2708 * It is necessary to for a delay here since the card doesn't
2709 * respond to PCI reads during a reset. On some architectures
2710 * this will result in an MCA.
2713 for (cnt = 30000; cnt; cnt--) {
2714 if ((rd_reg_word(®->ctrl_status) &
2715 CSR_ISP_SOFT_RESET) == 0)
2722 /* Reset RISC processor. */
2723 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
2725 wrt_reg_word(®->semaphore, 0);
2727 /* Release RISC processor. */
2728 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
2729 rd_reg_word(®->hccr); /* PCI Posting. */
2731 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2732 for (cnt = 0; cnt < 30000; cnt++) {
2733 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
2741 /* Turn on master enable */
2742 cmd |= PCI_COMMAND_MASTER;
2743 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2745 /* Disable RISC pause on FPM parity error. */
2746 if (!IS_QLA2100(ha)) {
2747 wrt_reg_word(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
2748 rd_reg_word(®->hccr); /* PCI Posting. */
2751 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2757 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2760 * Returns 0 on success.
2763 qla81xx_reset_mpi(scsi_qla_host_t *vha)
2765 uint16_t mb[4] = {0x1010, 0, 1, 0};
2767 if (!IS_QLA81XX(vha->hw))
2770 return qla81xx_write_mpi_register(vha, mb);
2774 qla_chk_risc_recovery(scsi_qla_host_t *vha)
2776 struct qla_hw_data *ha = vha->hw;
2777 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2778 __le16 __iomem *mbptr = ®->mailbox0;
2781 int rc = QLA_SUCCESS;
2783 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
2786 /* this check is only valid after RISC reset */
2787 mb[0] = rd_reg_word(mbptr);
2790 rc = QLA_FUNCTION_FAILED;
2792 for (i = 1; i < 32; i++) {
2793 mb[i] = rd_reg_word(mbptr);
2797 ql_log(ql_log_warn, vha, 0x1015,
2798 "RISC reset failed. mb[0-7] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
2799 mb[0], mb[1], mb[2], mb[3], mb[4], mb[5], mb[6], mb[7]);
2800 ql_log(ql_log_warn, vha, 0x1015,
2801 "RISC reset failed. mb[8-15] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
2802 mb[8], mb[9], mb[10], mb[11], mb[12], mb[13], mb[14],
2804 ql_log(ql_log_warn, vha, 0x1015,
2805 "RISC reset failed. mb[16-23] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
2806 mb[16], mb[17], mb[18], mb[19], mb[20], mb[21], mb[22],
2808 ql_log(ql_log_warn, vha, 0x1015,
2809 "RISC reset failed. mb[24-31] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
2810 mb[24], mb[25], mb[26], mb[27], mb[28], mb[29], mb[30],
2817 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2820 * Returns 0 on success.
2823 qla24xx_reset_risc(scsi_qla_host_t *vha)
2825 unsigned long flags = 0;
2826 struct qla_hw_data *ha = vha->hw;
2827 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2830 static int abts_cnt; /* ISP abort retry counts */
2831 int rval = QLA_SUCCESS;
2834 spin_lock_irqsave(&ha->hardware_lock, flags);
2837 wrt_reg_dword(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2838 for (cnt = 0; cnt < 30000; cnt++) {
2839 if ((rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2845 if (!(rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE))
2846 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2848 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2849 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2850 rd_reg_dword(®->hccr),
2851 rd_reg_dword(®->ctrl_status),
2852 (rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE));
2854 wrt_reg_dword(®->ctrl_status,
2855 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2856 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
2860 /* Wait for firmware to complete NVRAM accesses. */
2861 rd_reg_word(®->mailbox0);
2862 for (cnt = 10000; rd_reg_word(®->mailbox0) != 0 &&
2863 rval == QLA_SUCCESS; cnt--) {
2868 rval = QLA_FUNCTION_TIMEOUT;
2871 if (rval == QLA_SUCCESS)
2872 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2874 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2875 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2876 rd_reg_dword(®->hccr),
2877 rd_reg_word(®->mailbox0));
2879 /* Wait for soft-reset to complete. */
2880 rd_reg_dword(®->ctrl_status);
2881 for (cnt = 0; cnt < 60; cnt++) {
2883 if ((rd_reg_dword(®->ctrl_status) &
2884 CSRX_ISP_SOFT_RESET) == 0)
2889 if (!(rd_reg_dword(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
2890 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2892 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2893 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2894 rd_reg_dword(®->hccr),
2895 rd_reg_dword(®->ctrl_status));
2897 /* If required, do an MPI FW reset now */
2898 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2899 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2900 if (++abts_cnt < 5) {
2901 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2902 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2905 * We exhausted the ISP abort retries. We have to
2906 * set the board offline.
2909 vha->flags.online = 0;
2914 wrt_reg_dword(®->hccr, HCCRX_SET_RISC_RESET);
2915 rd_reg_dword(®->hccr);
2917 wrt_reg_dword(®->hccr, HCCRX_REL_RISC_PAUSE);
2918 rd_reg_dword(®->hccr);
2920 wrt_reg_dword(®->hccr, HCCRX_CLR_RISC_RESET);
2922 rd_reg_dword(®->hccr);
2924 wd = rd_reg_word(®->mailbox0);
2925 for (cnt = 300; wd != 0 && rval == QLA_SUCCESS; cnt--) {
2929 if (print && qla_chk_risc_recovery(vha))
2932 wd = rd_reg_word(®->mailbox0);
2934 rval = QLA_FUNCTION_TIMEOUT;
2936 ql_log(ql_log_warn, vha, 0x015e,
2937 "RISC reset timeout\n");
2941 if (rval == QLA_SUCCESS)
2942 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2944 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2945 "Host Risc 0x%x, mailbox0 0x%x\n",
2946 rd_reg_dword(®->hccr),
2947 rd_reg_word(®->mailbox0));
2949 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2951 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2952 "Driver in %s mode\n",
2953 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2955 if (IS_NOPOLLING_TYPE(ha))
2956 ha->isp_ops->enable_intrs(ha);
2962 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2964 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2966 wrt_reg_dword(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2967 *data = rd_reg_dword(®->iobase_window + RISC_REGISTER_WINDOW_OFFSET);
2971 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2973 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2975 wrt_reg_dword(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2976 wrt_reg_dword(®->iobase_window + RISC_REGISTER_WINDOW_OFFSET, data);
2980 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2983 uint delta_msec = 100;
2984 uint elapsed_msec = 0;
2988 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2989 vha->hw->pdev->subsystem_device != 0x0240)
2992 wrt_reg_dword(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2996 timeout_msec = TIMEOUT_SEMAPHORE;
2997 n = timeout_msec / delta_msec;
2999 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
3000 qla25xx_read_risc_sema_reg(vha, &wd32);
3001 if (wd32 & RISC_SEMAPHORE)
3004 elapsed_msec += delta_msec;
3005 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
3009 if (!(wd32 & RISC_SEMAPHORE))
3012 if (!(wd32 & RISC_SEMAPHORE_FORCE))
3015 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
3016 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
3017 n = timeout_msec / delta_msec;
3019 qla25xx_read_risc_sema_reg(vha, &wd32);
3020 if (!(wd32 & RISC_SEMAPHORE_FORCE))
3023 elapsed_msec += delta_msec;
3024 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
3028 if (wd32 & RISC_SEMAPHORE_FORCE)
3029 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
3034 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
3041 * qla24xx_reset_chip() - Reset ISP24xx chip.
3044 * Returns 0 on success.
3047 qla24xx_reset_chip(scsi_qla_host_t *vha)
3049 struct qla_hw_data *ha = vha->hw;
3050 int rval = QLA_FUNCTION_FAILED;
3052 if (pci_channel_offline(ha->pdev) &&
3053 ha->flags.pci_channel_io_perm_failure) {
3057 ha->isp_ops->disable_intrs(ha);
3059 qla25xx_manipulate_risc_semaphore(vha);
3061 /* Perform RISC reset. */
3062 rval = qla24xx_reset_risc(vha);
3068 * qla2x00_chip_diag() - Test chip for proper operation.
3071 * Returns 0 on success.
3074 qla2x00_chip_diag(scsi_qla_host_t *vha)
3077 struct qla_hw_data *ha = vha->hw;
3078 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3079 unsigned long flags = 0;
3083 struct req_que *req = ha->req_q_map[0];
3085 /* Assume a failed state */
3086 rval = QLA_FUNCTION_FAILED;
3088 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
3089 ®->flash_address);
3091 spin_lock_irqsave(&ha->hardware_lock, flags);
3093 /* Reset ISP chip. */
3094 wrt_reg_word(®->ctrl_status, CSR_ISP_SOFT_RESET);
3097 * We need to have a delay here since the card will not respond while
3098 * in reset causing an MCA on some architectures.
3101 data = qla2x00_debounce_register(®->ctrl_status);
3102 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
3104 data = rd_reg_word(®->ctrl_status);
3109 goto chip_diag_failed;
3111 ql_dbg(ql_dbg_init, vha, 0x007c,
3112 "Reset register cleared by chip reset.\n");
3114 /* Reset RISC processor. */
3115 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
3116 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
3118 /* Workaround for QLA2312 PCI parity error */
3119 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
3120 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
3121 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
3123 data = RD_MAILBOX_REG(ha, reg, 0);
3130 goto chip_diag_failed;
3132 /* Check product ID of chip */
3133 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
3135 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
3136 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
3137 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
3138 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
3139 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
3140 mb[3] != PROD_ID_3) {
3141 ql_log(ql_log_warn, vha, 0x0062,
3142 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
3143 mb[1], mb[2], mb[3]);
3145 goto chip_diag_failed;
3147 ha->product_id[0] = mb[1];
3148 ha->product_id[1] = mb[2];
3149 ha->product_id[2] = mb[3];
3150 ha->product_id[3] = mb[4];
3152 /* Adjust fw RISC transfer size */
3153 if (req->length > 1024)
3154 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
3156 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
3159 if (IS_QLA2200(ha) &&
3160 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
3161 /* Limit firmware transfer size with a 2200A */
3162 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
3164 ha->device_type |= DT_ISP2200A;
3165 ha->fw_transfer_size = 128;
3168 /* Wrap Incoming Mailboxes Test. */
3169 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3171 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
3172 rval = qla2x00_mbx_reg_test(vha);
3174 ql_log(ql_log_warn, vha, 0x0080,
3175 "Failed mailbox send register test.\n");
3177 /* Flag a successful rval */
3179 spin_lock_irqsave(&ha->hardware_lock, flags);
3183 ql_log(ql_log_info, vha, 0x0081,
3184 "Chip diagnostics **** FAILED ****.\n");
3186 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3192 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3195 * Returns 0 on success.
3198 qla24xx_chip_diag(scsi_qla_host_t *vha)
3201 struct qla_hw_data *ha = vha->hw;
3202 struct req_que *req = ha->req_q_map[0];
3204 if (IS_P3P_TYPE(ha))
3207 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
3209 rval = qla2x00_mbx_reg_test(vha);
3211 ql_log(ql_log_warn, vha, 0x0082,
3212 "Failed mailbox send register test.\n");
3214 /* Flag a successful rval */
3222 qla2x00_init_fce_trace(scsi_qla_host_t *vha)
3227 struct qla_hw_data *ha = vha->hw;
3229 if (!IS_FWI2_CAPABLE(ha))
3232 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3233 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3237 ql_dbg(ql_dbg_init, vha, 0x00bd,
3238 "%s: FCE Mem is already allocated.\n",
3243 /* Allocate memory for Fibre Channel Event Buffer. */
3244 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3247 ql_log(ql_log_warn, vha, 0x00be,
3248 "Unable to allocate (%d KB) for FCE.\n",
3253 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3254 ha->fce_mb, &ha->fce_bufs);
3256 ql_log(ql_log_warn, vha, 0x00bf,
3257 "Unable to initialize FCE (%d).\n", rval);
3258 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, tc_dma);
3262 ql_dbg(ql_dbg_init, vha, 0x00c0,
3263 "Allocated (%d KB) for FCE...\n", FCE_SIZE / 1024);
3265 ha->flags.fce_enabled = 1;
3266 ha->fce_dma = tc_dma;
3271 qla2x00_init_eft_trace(scsi_qla_host_t *vha)
3276 struct qla_hw_data *ha = vha->hw;
3278 if (!IS_FWI2_CAPABLE(ha))
3282 ql_dbg(ql_dbg_init, vha, 0x00bd,
3283 "%s: EFT Mem is already allocated.\n",
3288 /* Allocate memory for Extended Trace Buffer. */
3289 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3292 ql_log(ql_log_warn, vha, 0x00c1,
3293 "Unable to allocate (%d KB) for EFT.\n",
3298 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3300 ql_log(ql_log_warn, vha, 0x00c2,
3301 "Unable to initialize EFT (%d).\n", rval);
3302 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, tc_dma);
3306 ql_dbg(ql_dbg_init, vha, 0x00c3,
3307 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3309 ha->eft_dma = tc_dma;
3314 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3316 qla2x00_init_fce_trace(vha);
3317 qla2x00_init_eft_trace(vha);
3321 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3323 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
3324 eft_size, fce_size, mq_size;
3325 struct qla_hw_data *ha = vha->hw;
3326 struct req_que *req = ha->req_q_map[0];
3327 struct rsp_que *rsp = ha->rsp_q_map[0];
3328 struct qla2xxx_fw_dump *fw_dump;
3330 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
3331 req_q_size = rsp_q_size = 0;
3333 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3334 fixed_size = sizeof(struct qla2100_fw_dump);
3335 } else if (IS_QLA23XX(ha)) {
3336 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
3337 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
3339 } else if (IS_FWI2_CAPABLE(ha)) {
3340 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
3341 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
3342 else if (IS_QLA81XX(ha))
3343 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
3344 else if (IS_QLA25XX(ha))
3345 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
3347 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
3349 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
3352 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) &&
3354 mq_size = sizeof(struct qla2xxx_mq_chain);
3356 * Allocate maximum buffer size for all queues - Q0.
3357 * Resizing must be done at end-of-dump processing.
3359 mq_size += (ha->max_req_queues - 1) *
3360 (req->length * sizeof(request_t));
3361 mq_size += (ha->max_rsp_queues - 1) *
3362 (rsp->length * sizeof(response_t));
3364 if (ha->tgt.atio_ring)
3365 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3367 qla2x00_init_fce_trace(vha);
3369 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3370 qla2x00_init_eft_trace(vha);
3372 eft_size = EFT_SIZE;
3375 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3376 struct fwdt *fwdt = ha->fwdt;
3379 for (j = 0; j < 2; j++, fwdt++) {
3380 if (!fwdt->template) {
3381 ql_dbg(ql_dbg_init, vha, 0x00ba,
3382 "-> fwdt%u no template\n", j);
3385 ql_dbg(ql_dbg_init, vha, 0x00fa,
3386 "-> fwdt%u calculating fwdump size...\n", j);
3387 fwdt->dump_size = qla27xx_fwdt_calculate_dump_size(
3388 vha, fwdt->template);
3389 ql_dbg(ql_dbg_init, vha, 0x00fa,
3390 "-> fwdt%u calculated fwdump size = %#lx bytes\n",
3391 j, fwdt->dump_size);
3392 dump_size += fwdt->dump_size;
3394 /* Add space for spare MPI fw dump. */
3395 dump_size += ha->fwdt[1].dump_size;
3397 req_q_size = req->length * sizeof(request_t);
3398 rsp_q_size = rsp->length * sizeof(response_t);
3399 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3400 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size
3402 ha->chain_offset = dump_size;
3403 dump_size += mq_size + fce_size;
3404 if (ha->exchoffld_buf)
3405 dump_size += sizeof(struct qla2xxx_offld_chain) +
3407 if (ha->exlogin_buf)
3408 dump_size += sizeof(struct qla2xxx_offld_chain) +
3412 if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) {
3414 ql_dbg(ql_dbg_init, vha, 0x00c5,
3415 "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n",
3416 __func__, dump_size, ha->fw_dump_len,
3417 ha->fw_dump_alloc_len);
3419 fw_dump = vmalloc(dump_size);
3421 ql_log(ql_log_warn, vha, 0x00c4,
3422 "Unable to allocate (%d KB) for firmware dump.\n",
3425 mutex_lock(&ha->optrom_mutex);
3426 if (ha->fw_dumped) {
3427 memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len);
3429 ha->fw_dump = fw_dump;
3430 ha->fw_dump_alloc_len = dump_size;
3431 ql_dbg(ql_dbg_init, vha, 0x00c5,
3432 "Re-Allocated (%d KB) and save firmware dump.\n",
3436 ha->fw_dump = fw_dump;
3438 ha->fw_dump_len = ha->fw_dump_alloc_len =
3440 ql_dbg(ql_dbg_init, vha, 0x00c5,
3441 "Allocated (%d KB) for firmware dump.\n",
3444 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3445 ha->mpi_fw_dump = (char *)fw_dump +
3446 ha->fwdt[1].dump_size;
3447 mutex_unlock(&ha->optrom_mutex);
3451 ha->fw_dump->signature[0] = 'Q';
3452 ha->fw_dump->signature[1] = 'L';
3453 ha->fw_dump->signature[2] = 'G';
3454 ha->fw_dump->signature[3] = 'C';
3455 ha->fw_dump->version = htonl(1);
3457 ha->fw_dump->fixed_size = htonl(fixed_size);
3458 ha->fw_dump->mem_size = htonl(mem_size);
3459 ha->fw_dump->req_q_size = htonl(req_q_size);
3460 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3462 ha->fw_dump->eft_size = htonl(eft_size);
3463 ha->fw_dump->eft_addr_l =
3464 htonl(LSD(ha->eft_dma));
3465 ha->fw_dump->eft_addr_h =
3466 htonl(MSD(ha->eft_dma));
3468 ha->fw_dump->header_size =
3470 (struct qla2xxx_fw_dump, isp));
3472 mutex_unlock(&ha->optrom_mutex);
3478 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3480 #define MPS_MASK 0xe0
3485 if (!IS_QLA81XX(vha->hw))
3488 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3489 if (rval != QLA_SUCCESS) {
3490 ql_log(ql_log_warn, vha, 0x0105,
3491 "Unable to acquire semaphore.\n");
3495 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3496 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3497 if (rval != QLA_SUCCESS) {
3498 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3503 if (dc == (dw & MPS_MASK))
3508 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3509 if (rval != QLA_SUCCESS) {
3510 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3514 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3515 if (rval != QLA_SUCCESS) {
3516 ql_log(ql_log_warn, vha, 0x006d,
3517 "Unable to release semaphore.\n");
3525 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3527 /* Don't try to reallocate the array */
3528 if (req->outstanding_cmds)
3531 if (!IS_FWI2_CAPABLE(ha))
3532 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3534 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3535 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3537 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3540 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3544 if (!req->outstanding_cmds) {
3546 * Try to allocate a minimal size just so we can get through
3549 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
3550 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3554 if (!req->outstanding_cmds) {
3555 ql_log(ql_log_fatal, NULL, 0x0126,
3556 "Failed to allocate memory for "
3557 "outstanding_cmds for req_que %p.\n", req);
3558 req->num_outstanding_cmds = 0;
3559 return QLA_FUNCTION_FAILED;
3566 #define PRINT_FIELD(_field, _flag, _str) { \
3567 if (a0->_field & _flag) {\
3573 len = snprintf(ptr, leftover, "%s", _str); \
3580 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
3583 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
3584 u8 str[STR_LEN], *ptr, p;
3587 memset(str, 0, STR_LEN);
3588 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
3589 ql_dbg(ql_dbg_init, vha, 0x015a,
3590 "SFP MFG Name: %s\n", str);
3592 memset(str, 0, STR_LEN);
3593 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
3594 ql_dbg(ql_dbg_init, vha, 0x015c,
3595 "SFP Part Name: %s\n", str);
3598 memset(str, 0, STR_LEN);
3602 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
3603 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
3604 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
3605 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
3606 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3607 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3608 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3609 ql_dbg(ql_dbg_init, vha, 0x0160,
3610 "SFP Media: %s\n", str);
3613 memset(str, 0, STR_LEN);
3617 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3618 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3619 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3620 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3621 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3622 ql_dbg(ql_dbg_init, vha, 0x0196,
3623 "SFP Link Length: %s\n", str);
3625 memset(str, 0, STR_LEN);
3629 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3630 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3631 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3632 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3633 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3634 ql_dbg(ql_dbg_init, vha, 0x016e,
3635 "SFP FC Link Tech: %s\n", str);
3638 ql_dbg(ql_dbg_init, vha, 0x016f,
3639 "SFP Distant: %d km\n", a0->length_km);
3640 if (a0->length_100m)
3641 ql_dbg(ql_dbg_init, vha, 0x0170,
3642 "SFP Distant: %d m\n", a0->length_100m*100);
3643 if (a0->length_50um_10m)
3644 ql_dbg(ql_dbg_init, vha, 0x0189,
3645 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3646 if (a0->length_62um_10m)
3647 ql_dbg(ql_dbg_init, vha, 0x018a,
3648 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3649 if (a0->length_om4_10m)
3650 ql_dbg(ql_dbg_init, vha, 0x0194,
3651 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3652 if (a0->length_om3_10m)
3653 ql_dbg(ql_dbg_init, vha, 0x0195,
3654 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3659 * qla24xx_detect_sfp()
3661 * @vha: adapter state pointer.
3664 * 0 -- Configure firmware to use short-range settings -- normal
3665 * buffer-to-buffer credits.
3667 * 1 -- Configure firmware to use long-range settings -- extra
3668 * buffer-to-buffer credits should be allocated with
3669 * ha->lr_distance containing distance settings from NVRAM or SFP
3673 qla24xx_detect_sfp(scsi_qla_host_t *vha)
3676 struct sff_8247_a0 *a;
3677 struct qla_hw_data *ha = vha->hw;
3678 struct nvram_81xx *nv = ha->nvram;
3679 #define LR_DISTANCE_UNKNOWN 2
3680 static const char * const types[] = { "Short", "Long" };
3681 static const char * const lengths[] = { "(10km)", "(5km)", "" };
3684 /* Seed with NVRAM settings. */
3686 ha->flags.lr_detected = 0;
3687 if (IS_BPM_RANGE_CAPABLE(ha) &&
3688 (nv->enhanced_features & NEF_LR_DIST_ENABLE)) {
3690 ha->flags.lr_detected = 1;
3692 (nv->enhanced_features >> LR_DIST_NV_POS)
3696 if (!IS_BPM_ENABLED(vha))
3698 /* Determine SR/LR capabilities of SFP/Transceiver. */
3699 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3704 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3705 qla2xxx_print_sfp_info(vha);
3707 ha->flags.lr_detected = 0;
3709 if (ll & FC_LL_VL || ll & FC_LL_L) {
3710 /* Long range, track length. */
3711 ha->flags.lr_detected = 1;
3713 if (a->length_km > 5 || a->length_100m > 50)
3714 ha->lr_distance = LR_DISTANCE_10K;
3716 ha->lr_distance = LR_DISTANCE_5K;
3720 ql_dbg(ql_dbg_async, vha, 0x507b,
3721 "SFP detect: %s-Range SFP %s (nvr=%x ll=%x lr=%x lrd=%x).\n",
3722 types[ha->flags.lr_detected],
3723 ha->flags.lr_detected ? lengths[ha->lr_distance] :
3724 lengths[LR_DISTANCE_UNKNOWN],
3725 used_nvram, ll, ha->flags.lr_detected, ha->lr_distance);
3726 return ha->flags.lr_detected;
3729 void qla_init_iocb_limit(scsi_qla_host_t *vha)
3733 struct qla_hw_data *ha = vha->hw;
3735 num_qps = ha->num_qpairs + 1;
3736 limit = (ha->orig_fw_iocb_count * QLA_IOCB_PCT_LIMIT) / 100;
3738 ha->base_qpair->fwres.iocbs_total = ha->orig_fw_iocb_count;
3739 ha->base_qpair->fwres.iocbs_limit = limit;
3740 ha->base_qpair->fwres.iocbs_qp_limit = limit / num_qps;
3741 ha->base_qpair->fwres.iocbs_used = 0;
3742 for (i = 0; i < ha->max_qpairs; i++) {
3743 if (ha->queue_pair_map[i]) {
3744 ha->queue_pair_map[i]->fwres.iocbs_total =
3745 ha->orig_fw_iocb_count;
3746 ha->queue_pair_map[i]->fwres.iocbs_limit = limit;
3747 ha->queue_pair_map[i]->fwres.iocbs_qp_limit =
3749 ha->queue_pair_map[i]->fwres.iocbs_used = 0;
3755 * qla2x00_setup_chip() - Load and start RISC firmware.
3758 * Returns 0 on success.
3761 qla2x00_setup_chip(scsi_qla_host_t *vha)
3764 uint32_t srisc_address = 0;
3765 struct qla_hw_data *ha = vha->hw;
3766 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3767 unsigned long flags;
3768 uint16_t fw_major_version;
3771 if (IS_P3P_TYPE(ha)) {
3772 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3773 if (rval == QLA_SUCCESS) {
3774 qla2x00_stop_firmware(vha);
3775 goto enable_82xx_npiv;
3780 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3781 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3782 spin_lock_irqsave(&ha->hardware_lock, flags);
3783 wrt_reg_word(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
3784 rd_reg_word(®->hccr);
3785 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3788 qla81xx_mpi_sync(vha);
3791 /* Load firmware sequences */
3792 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3793 if (rval == QLA_SUCCESS) {
3794 ql_dbg(ql_dbg_init, vha, 0x00c9,
3795 "Verifying Checksum of loaded RISC code.\n");
3797 rval = qla2x00_verify_checksum(vha, srisc_address);
3798 if (rval == QLA_SUCCESS) {
3799 /* Start firmware execution. */
3800 ql_dbg(ql_dbg_init, vha, 0x00ca,
3801 "Starting firmware.\n");
3804 ha->flags.exlogins_enabled = 1;
3806 if (qla_is_exch_offld_enabled(vha))
3807 ha->flags.exchoffld_enabled = 1;
3809 rval = qla2x00_execute_fw(vha, srisc_address);
3810 /* Retrieve firmware information. */
3811 if (rval == QLA_SUCCESS) {
3812 /* Enable BPM support? */
3813 if (!done_once++ && qla24xx_detect_sfp(vha)) {
3814 ql_dbg(ql_dbg_init, vha, 0x00ca,
3815 "Re-starting firmware -- BPM.\n");
3816 /* Best-effort - re-init. */
3817 ha->isp_ops->reset_chip(vha);
3818 ha->isp_ops->chip_diag(vha);
3819 goto execute_fw_with_lr;
3822 if (IS_ZIO_THRESHOLD_CAPABLE(ha))
3823 qla27xx_set_zio_threshold(vha,
3824 ha->last_zio_threshold);
3826 rval = qla2x00_set_exlogins_buffer(vha);
3827 if (rval != QLA_SUCCESS)
3830 rval = qla2x00_set_exchoffld_buffer(vha);
3831 if (rval != QLA_SUCCESS)
3835 fw_major_version = ha->fw_major_version;
3836 if (IS_P3P_TYPE(ha))
3837 qla82xx_check_md_needed(vha);
3839 rval = qla2x00_get_fw_version(vha);
3840 if (rval != QLA_SUCCESS)
3842 ha->flags.npiv_supported = 0;
3843 if (IS_QLA2XXX_MIDTYPE(ha) &&
3844 (ha->fw_attributes & BIT_2)) {
3845 ha->flags.npiv_supported = 1;
3846 if ((!ha->max_npiv_vports) ||
3847 ((ha->max_npiv_vports + 1) %
3848 MIN_MULTI_ID_FABRIC))
3849 ha->max_npiv_vports =
3850 MIN_MULTI_ID_FABRIC - 1;
3852 qla2x00_get_resource_cnts(vha);
3853 qla_init_iocb_limit(vha);
3856 * Allocate the array of outstanding commands
3857 * now that we know the firmware resources.
3859 rval = qla2x00_alloc_outstanding_cmds(ha,
3861 if (rval != QLA_SUCCESS)
3864 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
3865 qla2x00_alloc_offload_mem(vha);
3867 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
3868 qla2x00_alloc_fw_dump(vha);
3874 ql_log(ql_log_fatal, vha, 0x00cd,
3875 "ISP Firmware failed checksum.\n");
3879 /* Enable PUREX PASSTHRU */
3880 if (ql2xrdpenable || ha->flags.scm_supported_f)
3881 qla25xx_set_els_cmds_supported(vha);
3885 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3886 /* Enable proper parity. */
3887 spin_lock_irqsave(&ha->hardware_lock, flags);
3890 wrt_reg_word(®->hccr, HCCR_ENABLE_PARITY + 0x1);
3892 /* SRAM, Instruction RAM and GP RAM parity */
3893 wrt_reg_word(®->hccr, HCCR_ENABLE_PARITY + 0x7);
3894 rd_reg_word(®->hccr);
3895 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3898 if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
3899 ha->flags.fac_supported = 1;
3900 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
3903 rval = qla81xx_fac_get_sector_size(vha, &size);
3904 if (rval == QLA_SUCCESS) {
3905 ha->flags.fac_supported = 1;
3906 ha->fdt_block_size = size << 2;
3908 ql_log(ql_log_warn, vha, 0x00ce,
3909 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3910 ha->fw_major_version, ha->fw_minor_version,
3911 ha->fw_subminor_version);
3913 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3915 ha->flags.fac_supported = 0;
3922 ql_log(ql_log_fatal, vha, 0x00cf,
3923 "Setup chip ****FAILED****.\n");
3930 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3931 * @rsp: response queue
3933 * Beginning of request ring has initialization control block already built
3934 * by nvram config routine.
3936 * Returns 0 on success.
3939 qla2x00_init_response_q_entries(struct rsp_que *rsp)
3944 rsp->ring_ptr = rsp->ring;
3945 rsp->ring_index = 0;
3946 rsp->status_srb = NULL;
3947 pkt = rsp->ring_ptr;
3948 for (cnt = 0; cnt < rsp->length; cnt++) {
3949 pkt->signature = RESPONSE_PROCESSED;
3955 * qla2x00_update_fw_options() - Read and process firmware options.
3958 * Returns 0 on success.
3961 qla2x00_update_fw_options(scsi_qla_host_t *vha)
3963 uint16_t swing, emphasis, tx_sens, rx_sens;
3964 struct qla_hw_data *ha = vha->hw;
3966 memset(ha->fw_options, 0, sizeof(ha->fw_options));
3967 qla2x00_get_fw_options(vha, ha->fw_options);
3969 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3972 /* Serial Link options. */
3973 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3974 "Serial link options.\n");
3975 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3976 ha->fw_seriallink_options, sizeof(ha->fw_seriallink_options));
3978 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3979 if (ha->fw_seriallink_options[3] & BIT_2) {
3980 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3983 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3984 emphasis = (ha->fw_seriallink_options[2] &
3985 (BIT_4 | BIT_3)) >> 3;
3986 tx_sens = ha->fw_seriallink_options[0] &
3987 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3988 rx_sens = (ha->fw_seriallink_options[0] &
3989 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3990 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3991 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3994 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3995 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3996 ha->fw_options[10] |= BIT_5 |
3997 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3998 (tx_sens & (BIT_1 | BIT_0));
4001 swing = (ha->fw_seriallink_options[2] &
4002 (BIT_7 | BIT_6 | BIT_5)) >> 5;
4003 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
4004 tx_sens = ha->fw_seriallink_options[1] &
4005 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4006 rx_sens = (ha->fw_seriallink_options[1] &
4007 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
4008 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
4009 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
4012 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
4013 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
4014 ha->fw_options[11] |= BIT_5 |
4015 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
4016 (tx_sens & (BIT_1 | BIT_0));
4020 /* Return command IOCBs without waiting for an ABTS to complete. */
4021 ha->fw_options[3] |= BIT_13;
4024 if (ha->flags.enable_led_scheme)
4025 ha->fw_options[2] |= BIT_12;
4027 /* Detect ISP6312. */
4029 ha->fw_options[2] |= BIT_13;
4031 /* Set Retry FLOGI in case of P2P connection */
4032 if (ha->operating_mode == P2P) {
4033 ha->fw_options[2] |= BIT_3;
4034 ql_dbg(ql_dbg_disc, vha, 0x2100,
4035 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
4036 __func__, ha->fw_options[2]);
4039 /* Update firmware options. */
4040 qla2x00_set_fw_options(vha, ha->fw_options);
4044 qla24xx_update_fw_options(scsi_qla_host_t *vha)
4047 struct qla_hw_data *ha = vha->hw;
4049 if (IS_P3P_TYPE(ha))
4052 /* Hold status IOCBs until ABTS response received. */
4054 ha->fw_options[3] |= BIT_12;
4056 /* Set Retry FLOGI in case of P2P connection */
4057 if (ha->operating_mode == P2P) {
4058 ha->fw_options[2] |= BIT_3;
4059 ql_dbg(ql_dbg_disc, vha, 0x2101,
4060 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
4061 __func__, ha->fw_options[2]);
4064 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
4065 if (ql2xmvasynctoatio &&
4066 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
4067 if (qla_tgt_mode_enabled(vha) ||
4068 qla_dual_mode_enabled(vha))
4069 ha->fw_options[2] |= BIT_11;
4071 ha->fw_options[2] &= ~BIT_11;
4074 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4077 * Tell FW to track each exchange to prevent
4078 * driver from using stale exchange.
4080 if (qla_tgt_mode_enabled(vha) ||
4081 qla_dual_mode_enabled(vha))
4082 ha->fw_options[2] |= BIT_4;
4084 ha->fw_options[2] &= ~BIT_4;
4086 /* Reserve 1/2 of emergency exchanges for ELS.*/
4087 if (qla2xuseresexchforels)
4088 ha->fw_options[2] |= BIT_8;
4090 ha->fw_options[2] &= ~BIT_8;
4093 if (ql2xrdpenable || ha->flags.scm_supported_f)
4094 ha->fw_options[1] |= ADD_FO1_ENABLE_PUREX_IOCB;
4096 /* Enable Async 8130/8131 events -- transceiver insertion/removal */
4097 if (IS_BPM_RANGE_CAPABLE(ha))
4098 ha->fw_options[3] |= BIT_10;
4100 ql_dbg(ql_dbg_init, vha, 0x00e8,
4101 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
4102 __func__, ha->fw_options[1], ha->fw_options[2],
4103 ha->fw_options[3], vha->host->active_mode);
4105 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
4106 qla2x00_set_fw_options(vha, ha->fw_options);
4108 /* Update Serial Link options. */
4109 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
4112 rval = qla2x00_set_serdes_params(vha,
4113 le16_to_cpu(ha->fw_seriallink_options24[1]),
4114 le16_to_cpu(ha->fw_seriallink_options24[2]),
4115 le16_to_cpu(ha->fw_seriallink_options24[3]));
4116 if (rval != QLA_SUCCESS) {
4117 ql_log(ql_log_warn, vha, 0x0104,
4118 "Unable to update Serial Link options (%x).\n", rval);
4123 qla2x00_config_rings(struct scsi_qla_host *vha)
4125 struct qla_hw_data *ha = vha->hw;
4126 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4127 struct req_que *req = ha->req_q_map[0];
4128 struct rsp_que *rsp = ha->rsp_q_map[0];
4130 /* Setup ring parameters in initialization control block. */
4131 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
4132 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
4133 ha->init_cb->request_q_length = cpu_to_le16(req->length);
4134 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
4135 put_unaligned_le64(req->dma, &ha->init_cb->request_q_address);
4136 put_unaligned_le64(rsp->dma, &ha->init_cb->response_q_address);
4138 wrt_reg_word(ISP_REQ_Q_IN(ha, reg), 0);
4139 wrt_reg_word(ISP_REQ_Q_OUT(ha, reg), 0);
4140 wrt_reg_word(ISP_RSP_Q_IN(ha, reg), 0);
4141 wrt_reg_word(ISP_RSP_Q_OUT(ha, reg), 0);
4142 rd_reg_word(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
4146 qla24xx_config_rings(struct scsi_qla_host *vha)
4148 struct qla_hw_data *ha = vha->hw;
4149 device_reg_t *reg = ISP_QUE_REG(ha, 0);
4150 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
4151 struct qla_msix_entry *msix;
4152 struct init_cb_24xx *icb;
4154 struct req_que *req = ha->req_q_map[0];
4155 struct rsp_que *rsp = ha->rsp_q_map[0];
4157 /* Setup ring parameters in initialization control block. */
4158 icb = (struct init_cb_24xx *)ha->init_cb;
4159 icb->request_q_outpointer = cpu_to_le16(0);
4160 icb->response_q_inpointer = cpu_to_le16(0);
4161 icb->request_q_length = cpu_to_le16(req->length);
4162 icb->response_q_length = cpu_to_le16(rsp->length);
4163 put_unaligned_le64(req->dma, &icb->request_q_address);
4164 put_unaligned_le64(rsp->dma, &icb->response_q_address);
4166 /* Setup ATIO queue dma pointers for target mode */
4167 icb->atio_q_inpointer = cpu_to_le16(0);
4168 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
4169 put_unaligned_le64(ha->tgt.atio_dma, &icb->atio_q_address);
4171 if (IS_SHADOW_REG_CAPABLE(ha))
4172 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
4174 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4176 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
4177 icb->rid = cpu_to_le16(rid);
4178 if (ha->flags.msix_enabled) {
4179 msix = &ha->msix_entries[1];
4180 ql_dbg(ql_dbg_init, vha, 0x0019,
4181 "Registering vector 0x%x for base que.\n",
4183 icb->msix = cpu_to_le16(msix->entry);
4185 /* Use alternate PCI bus number */
4187 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
4188 /* Use alternate PCI devfn */
4190 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
4192 /* Use Disable MSIX Handshake mode for capable adapters */
4193 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
4194 (ha->flags.msix_enabled)) {
4195 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
4196 ha->flags.disable_msix_handshake = 1;
4197 ql_dbg(ql_dbg_init, vha, 0x00fe,
4198 "MSIX Handshake Disable Mode turned on.\n");
4200 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
4202 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
4204 wrt_reg_dword(®->isp25mq.req_q_in, 0);
4205 wrt_reg_dword(®->isp25mq.req_q_out, 0);
4206 wrt_reg_dword(®->isp25mq.rsp_q_in, 0);
4207 wrt_reg_dword(®->isp25mq.rsp_q_out, 0);
4209 wrt_reg_dword(®->isp24.req_q_in, 0);
4210 wrt_reg_dword(®->isp24.req_q_out, 0);
4211 wrt_reg_dword(®->isp24.rsp_q_in, 0);
4212 wrt_reg_dword(®->isp24.rsp_q_out, 0);
4215 qlt_24xx_config_rings(vha);
4217 /* If the user has configured the speed, set it here */
4218 if (ha->set_data_rate) {
4219 ql_dbg(ql_dbg_init, vha, 0x00fd,
4220 "Speed set by user : %s Gbps \n",
4221 qla2x00_get_link_speed_str(ha, ha->set_data_rate));
4222 icb->firmware_options_3 = cpu_to_le32(ha->set_data_rate << 13);
4226 rd_reg_word(&ioreg->hccr);
4230 * qla2x00_init_rings() - Initializes firmware.
4233 * Beginning of request ring has initialization control block already built
4234 * by nvram config routine.
4236 * Returns 0 on success.
4239 qla2x00_init_rings(scsi_qla_host_t *vha)
4242 unsigned long flags = 0;
4244 struct qla_hw_data *ha = vha->hw;
4245 struct req_que *req;
4246 struct rsp_que *rsp;
4247 struct mid_init_cb_24xx *mid_init_cb =
4248 (struct mid_init_cb_24xx *) ha->init_cb;
4250 spin_lock_irqsave(&ha->hardware_lock, flags);
4252 /* Clear outstanding commands array. */
4253 for (que = 0; que < ha->max_req_queues; que++) {
4254 req = ha->req_q_map[que];
4255 if (!req || !test_bit(que, ha->req_qid_map))
4257 req->out_ptr = (uint16_t *)(req->ring + req->length);
4259 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
4260 req->outstanding_cmds[cnt] = NULL;
4262 req->current_outstanding_cmd = 1;
4264 /* Initialize firmware. */
4265 req->ring_ptr = req->ring;
4266 req->ring_index = 0;
4267 req->cnt = req->length;
4270 for (que = 0; que < ha->max_rsp_queues; que++) {
4271 rsp = ha->rsp_q_map[que];
4272 if (!rsp || !test_bit(que, ha->rsp_qid_map))
4274 rsp->in_ptr = (uint16_t *)(rsp->ring + rsp->length);
4276 /* Initialize response queue entries */
4278 qlafx00_init_response_q_entries(rsp);
4280 qla2x00_init_response_q_entries(rsp);
4283 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
4284 ha->tgt.atio_ring_index = 0;
4285 /* Initialize ATIO queue entries */
4286 qlt_init_atio_q_entries(vha);
4288 ha->isp_ops->config_rings(vha);
4290 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4292 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
4294 if (IS_QLAFX00(ha)) {
4295 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
4299 /* Update any ISP specific firmware options before initialization. */
4300 ha->isp_ops->update_fw_options(vha);
4302 if (ha->flags.npiv_supported) {
4303 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
4304 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
4305 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
4308 if (IS_FWI2_CAPABLE(ha)) {
4309 mid_init_cb->options = cpu_to_le16(BIT_1);
4310 mid_init_cb->init_cb.execution_throttle =
4311 cpu_to_le16(ha->cur_fw_xcb_count);
4312 ha->flags.dport_enabled =
4313 (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) &
4315 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
4316 (ha->flags.dport_enabled) ? "enabled" : "disabled");
4317 /* FA-WWPN Status */
4318 ha->flags.fawwpn_enabled =
4319 (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) &
4321 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
4322 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
4325 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
4328 ql_log(ql_log_fatal, vha, 0x00d2,
4329 "Init Firmware **** FAILED ****.\n");
4331 ql_dbg(ql_dbg_init, vha, 0x00d3,
4332 "Init Firmware -- success.\n");
4334 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0;
4341 * qla2x00_fw_ready() - Waits for firmware ready.
4344 * Returns 0 on success.
4347 qla2x00_fw_ready(scsi_qla_host_t *vha)
4350 unsigned long wtime, mtime, cs84xx_time;
4351 uint16_t min_wait; /* Minimum wait time if loop is down */
4352 uint16_t wait_time; /* Wait time if loop is coming ready */
4354 struct qla_hw_data *ha = vha->hw;
4356 if (IS_QLAFX00(vha->hw))
4357 return qlafx00_fw_ready(vha);
4359 /* Time to wait for loop down */
4360 if (IS_P3P_TYPE(ha))
4366 * Firmware should take at most one RATOV to login, plus 5 seconds for
4367 * our own processing.
4369 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
4370 wait_time = min_wait;
4373 /* Min wait time if loop down */
4374 mtime = jiffies + (min_wait * HZ);
4376 /* wait time before firmware ready */
4377 wtime = jiffies + (wait_time * HZ);
4379 /* Wait for ISP to finish LIP */
4380 if (!vha->flags.init_done)
4381 ql_log(ql_log_info, vha, 0x801e,
4382 "Waiting for LIP to complete.\n");
4385 memset(state, -1, sizeof(state));
4386 rval = qla2x00_get_firmware_state(vha, state);
4387 if (rval == QLA_SUCCESS) {
4388 if (state[0] < FSTATE_LOSS_OF_SYNC) {
4389 vha->device_flags &= ~DFLG_NO_CABLE;
4391 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
4392 ql_dbg(ql_dbg_taskm, vha, 0x801f,
4393 "fw_state=%x 84xx=%x.\n", state[0],
4395 if ((state[2] & FSTATE_LOGGED_IN) &&
4396 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
4397 ql_dbg(ql_dbg_taskm, vha, 0x8028,
4398 "Sending verify iocb.\n");
4400 cs84xx_time = jiffies;
4401 rval = qla84xx_init_chip(vha);
4402 if (rval != QLA_SUCCESS) {
4405 "Init chip failed.\n");
4409 /* Add time taken to initialize. */
4410 cs84xx_time = jiffies - cs84xx_time;
4411 wtime += cs84xx_time;
4412 mtime += cs84xx_time;
4413 ql_dbg(ql_dbg_taskm, vha, 0x8008,
4414 "Increasing wait time by %ld. "
4415 "New time %ld.\n", cs84xx_time,
4418 } else if (state[0] == FSTATE_READY) {
4419 ql_dbg(ql_dbg_taskm, vha, 0x8037,
4420 "F/W Ready - OK.\n");
4422 qla2x00_get_retry_cnt(vha, &ha->retry_count,
4423 &ha->login_timeout, &ha->r_a_tov);
4429 rval = QLA_FUNCTION_FAILED;
4431 if (atomic_read(&vha->loop_down_timer) &&
4432 state[0] != FSTATE_READY) {
4433 /* Loop down. Timeout on min_wait for states
4434 * other than Wait for Login.
4436 if (time_after_eq(jiffies, mtime)) {
4437 ql_log(ql_log_info, vha, 0x8038,
4438 "Cable is unplugged...\n");
4440 vha->device_flags |= DFLG_NO_CABLE;
4445 /* Mailbox cmd failed. Timeout on min_wait. */
4446 if (time_after_eq(jiffies, mtime) ||
4447 ha->flags.isp82xx_fw_hung)
4451 if (time_after_eq(jiffies, wtime))
4454 /* Delay for a while */
4458 ql_dbg(ql_dbg_taskm, vha, 0x803a,
4459 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
4460 state[1], state[2], state[3], state[4], state[5], jiffies);
4462 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
4463 ql_log(ql_log_warn, vha, 0x803b,
4464 "Firmware ready **** FAILED ****.\n");
4471 * qla2x00_configure_hba
4472 * Setup adapter context.
4475 * ha = adapter state pointer.
4484 qla2x00_configure_hba(scsi_qla_host_t *vha)
4493 char connect_type[22];
4494 struct qla_hw_data *ha = vha->hw;
4495 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4497 unsigned long flags;
4499 /* Get host addresses. */
4500 rval = qla2x00_get_adapter_id(vha,
4501 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
4502 if (rval != QLA_SUCCESS) {
4503 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
4504 IS_CNA_CAPABLE(ha) ||
4505 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
4506 ql_dbg(ql_dbg_disc, vha, 0x2008,
4507 "Loop is in a transition state.\n");
4509 ql_log(ql_log_warn, vha, 0x2009,
4510 "Unable to get host loop ID.\n");
4511 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
4512 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
4513 ql_log(ql_log_warn, vha, 0x1151,
4514 "Doing link init.\n");
4515 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
4518 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4524 ql_log(ql_log_info, vha, 0x200a,
4525 "Cannot get topology - retrying.\n");
4526 return (QLA_FUNCTION_FAILED);
4529 vha->loop_id = loop_id;
4532 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
4533 ha->operating_mode = LOOP;
4538 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
4539 ha->current_topology = ISP_CFG_NL;
4540 strcpy(connect_type, "(Loop)");
4544 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
4545 ha->switch_cap = sw_cap;
4546 ha->current_topology = ISP_CFG_FL;
4547 strcpy(connect_type, "(FL_Port)");
4551 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
4552 ha->operating_mode = P2P;
4553 ha->current_topology = ISP_CFG_N;
4554 strcpy(connect_type, "(N_Port-to-N_Port)");
4558 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
4559 ha->switch_cap = sw_cap;
4560 ha->operating_mode = P2P;
4561 ha->current_topology = ISP_CFG_F;
4562 strcpy(connect_type, "(F_Port)");
4566 ql_dbg(ql_dbg_disc, vha, 0x200f,
4567 "HBA in unknown topology %x, using NL.\n", topo);
4568 ha->current_topology = ISP_CFG_NL;
4569 strcpy(connect_type, "(Loop)");
4573 /* Save Host port and loop ID. */
4574 /* byte order - Big Endian */
4575 id.b.domain = domain;
4579 spin_lock_irqsave(&ha->hardware_lock, flags);
4580 if (!(topo == 2 && ha->flags.n2n_bigger))
4581 qlt_update_host_map(vha, id);
4582 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4584 if (!vha->flags.init_done)
4585 ql_log(ql_log_info, vha, 0x2010,
4586 "Topology - %s, Host Loop address 0x%x.\n",
4587 connect_type, vha->loop_id);
4593 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
4598 uint64_t zero[2] = { 0 };
4599 struct qla_hw_data *ha = vha->hw;
4600 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
4601 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
4603 if (len > sizeof(zero))
4605 if (memcmp(model, &zero, len) != 0) {
4606 memcpy(ha->model_number, model, len);
4607 st = en = ha->model_number;
4610 if (*en != 0x20 && *en != 0x00)
4615 index = (ha->pdev->subsystem_device & 0xff);
4617 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4618 index < QLA_MODEL_NAMES)
4619 strlcpy(ha->model_desc,
4620 qla2x00_model_name[index * 2 + 1],
4621 sizeof(ha->model_desc));
4623 index = (ha->pdev->subsystem_device & 0xff);
4625 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4626 index < QLA_MODEL_NAMES) {
4627 strlcpy(ha->model_number,
4628 qla2x00_model_name[index * 2],
4629 sizeof(ha->model_number));
4630 strlcpy(ha->model_desc,
4631 qla2x00_model_name[index * 2 + 1],
4632 sizeof(ha->model_desc));
4634 strlcpy(ha->model_number, def,
4635 sizeof(ha->model_number));
4638 if (IS_FWI2_CAPABLE(ha))
4639 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
4640 sizeof(ha->model_desc));
4643 /* On sparc systems, obtain port and node WWN from firmware
4646 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4649 struct qla_hw_data *ha = vha->hw;
4650 struct pci_dev *pdev = ha->pdev;
4651 struct device_node *dp = pci_device_to_OF_node(pdev);
4655 val = of_get_property(dp, "port-wwn", &len);
4656 if (val && len >= WWN_SIZE)
4657 memcpy(nv->port_name, val, WWN_SIZE);
4659 val = of_get_property(dp, "node-wwn", &len);
4660 if (val && len >= WWN_SIZE)
4661 memcpy(nv->node_name, val, WWN_SIZE);
4666 * NVRAM configuration for ISP 2xxx
4669 * ha = adapter block pointer.
4672 * initialization control block in response_ring
4673 * host adapters parameters in host adapter block
4679 qla2x00_nvram_config(scsi_qla_host_t *vha)
4684 uint8_t *dptr1, *dptr2;
4685 struct qla_hw_data *ha = vha->hw;
4686 init_cb_t *icb = ha->init_cb;
4687 nvram_t *nv = ha->nvram;
4688 uint8_t *ptr = ha->nvram;
4689 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4693 /* Determine NVRAM starting address. */
4694 ha->nvram_size = sizeof(*nv);
4696 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4697 if ((rd_reg_word(®->ctrl_status) >> 14) == 1)
4698 ha->nvram_base = 0x80;
4700 /* Get NVRAM data and calculate checksum. */
4701 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
4702 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4705 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4706 "Contents of NVRAM.\n");
4707 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4708 nv, ha->nvram_size);
4710 /* Bad NVRAM data, set defaults parameters. */
4711 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
4712 nv->nvram_version < 1) {
4713 /* Reset NVRAM data. */
4714 ql_log(ql_log_warn, vha, 0x0064,
4715 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
4716 chksum, nv->id, nv->nvram_version);
4717 ql_log(ql_log_warn, vha, 0x0065,
4719 "functioning (yet invalid -- WWPN) defaults.\n");
4722 * Set default initialization control block.
4724 memset(nv, 0, ha->nvram_size);
4725 nv->parameter_block_version = ICB_VERSION;
4727 if (IS_QLA23XX(ha)) {
4728 nv->firmware_options[0] = BIT_2 | BIT_1;
4729 nv->firmware_options[1] = BIT_7 | BIT_5;
4730 nv->add_firmware_options[0] = BIT_5;
4731 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4732 nv->frame_payload_size = cpu_to_le16(2048);
4733 nv->special_options[1] = BIT_7;
4734 } else if (IS_QLA2200(ha)) {
4735 nv->firmware_options[0] = BIT_2 | BIT_1;
4736 nv->firmware_options[1] = BIT_7 | BIT_5;
4737 nv->add_firmware_options[0] = BIT_5;
4738 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4739 nv->frame_payload_size = cpu_to_le16(1024);
4740 } else if (IS_QLA2100(ha)) {
4741 nv->firmware_options[0] = BIT_3 | BIT_1;
4742 nv->firmware_options[1] = BIT_5;
4743 nv->frame_payload_size = cpu_to_le16(1024);
4746 nv->max_iocb_allocation = cpu_to_le16(256);
4747 nv->execution_throttle = cpu_to_le16(16);
4748 nv->retry_count = 8;
4749 nv->retry_delay = 1;
4751 nv->port_name[0] = 33;
4752 nv->port_name[3] = 224;
4753 nv->port_name[4] = 139;
4755 qla2xxx_nvram_wwn_from_ofw(vha, nv);
4757 nv->login_timeout = 4;
4760 * Set default host adapter parameters
4762 nv->host_p[1] = BIT_2;
4763 nv->reset_delay = 5;
4764 nv->port_down_retry_count = 8;
4765 nv->max_luns_per_target = cpu_to_le16(8);
4766 nv->link_down_timeout = 60;
4771 /* Reset Initialization control block */
4772 memset(icb, 0, ha->init_cb_size);
4775 * Setup driver NVRAM options.
4777 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4778 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4779 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4780 nv->firmware_options[1] &= ~BIT_4;
4782 if (IS_QLA23XX(ha)) {
4783 nv->firmware_options[0] |= BIT_2;
4784 nv->firmware_options[0] &= ~BIT_3;
4785 nv->special_options[0] &= ~BIT_6;
4786 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
4788 if (IS_QLA2300(ha)) {
4789 if (ha->fb_rev == FPM_2310) {
4790 strcpy(ha->model_number, "QLA2310");
4792 strcpy(ha->model_number, "QLA2300");
4795 qla2x00_set_model_info(vha, nv->model_number,
4796 sizeof(nv->model_number), "QLA23xx");
4798 } else if (IS_QLA2200(ha)) {
4799 nv->firmware_options[0] |= BIT_2;
4801 * 'Point-to-point preferred, else loop' is not a safe
4802 * connection mode setting.
4804 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4806 /* Force 'loop preferred, else point-to-point'. */
4807 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4808 nv->add_firmware_options[0] |= BIT_5;
4810 strcpy(ha->model_number, "QLA22xx");
4811 } else /*if (IS_QLA2100(ha))*/ {
4812 strcpy(ha->model_number, "QLA2100");
4816 * Copy over NVRAM RISC parameter block to initialization control block.
4818 dptr1 = (uint8_t *)icb;
4819 dptr2 = (uint8_t *)&nv->parameter_block_version;
4820 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4822 *dptr1++ = *dptr2++;
4824 /* Copy 2nd half. */
4825 dptr1 = (uint8_t *)icb->add_firmware_options;
4826 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4828 *dptr1++ = *dptr2++;
4829 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
4830 /* Use alternate WWN? */
4831 if (nv->host_p[1] & BIT_7) {
4832 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4833 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4836 /* Prepare nodename */
4837 if ((icb->firmware_options[1] & BIT_6) == 0) {
4839 * Firmware will apply the following mask if the nodename was
4842 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4843 icb->node_name[0] &= 0xF0;
4847 * Set host adapter parameters.
4851 * BIT_7 in the host-parameters section allows for modification to
4852 * internal driver logging.
4854 if (nv->host_p[0] & BIT_7)
4855 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
4856 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4857 /* Always load RISC code on non ISP2[12]00 chips. */
4858 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4859 ha->flags.disable_risc_code_load = 0;
4860 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4861 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4862 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
4863 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
4864 ha->flags.disable_serdes = 0;
4866 ha->operating_mode =
4867 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4869 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4870 sizeof(ha->fw_seriallink_options));
4872 /* save HBA serial number */
4873 ha->serial0 = icb->port_name[5];
4874 ha->serial1 = icb->port_name[6];
4875 ha->serial2 = icb->port_name[7];
4876 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4877 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4879 icb->execution_throttle = cpu_to_le16(0xFFFF);
4881 ha->retry_count = nv->retry_count;
4883 /* Set minimum login_timeout to 4 seconds. */
4884 if (nv->login_timeout != ql2xlogintimeout)
4885 nv->login_timeout = ql2xlogintimeout;
4886 if (nv->login_timeout < 4)
4887 nv->login_timeout = 4;
4888 ha->login_timeout = nv->login_timeout;
4890 /* Set minimum RATOV to 100 tenths of a second. */
4893 ha->loop_reset_delay = nv->reset_delay;
4895 /* Link Down Timeout = 0:
4897 * When Port Down timer expires we will start returning
4898 * I/O's to OS with "DID_NO_CONNECT".
4900 * Link Down Timeout != 0:
4902 * The driver waits for the link to come up after link down
4903 * before returning I/Os to OS with "DID_NO_CONNECT".
4905 if (nv->link_down_timeout == 0) {
4906 ha->loop_down_abort_time =
4907 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4909 ha->link_down_timeout = nv->link_down_timeout;
4910 ha->loop_down_abort_time =
4911 (LOOP_DOWN_TIME - ha->link_down_timeout);
4915 * Need enough time to try and get the port back.
4917 ha->port_down_retry_count = nv->port_down_retry_count;
4918 if (qlport_down_retry)
4919 ha->port_down_retry_count = qlport_down_retry;
4920 /* Set login_retry_count */
4921 ha->login_retry_count = nv->retry_count;
4922 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4923 ha->port_down_retry_count > 3)
4924 ha->login_retry_count = ha->port_down_retry_count;
4925 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4926 ha->login_retry_count = ha->port_down_retry_count;
4927 if (ql2xloginretrycount)
4928 ha->login_retry_count = ql2xloginretrycount;
4930 icb->lun_enables = cpu_to_le16(0);
4931 icb->command_resource_count = 0;
4932 icb->immediate_notify_resource_count = 0;
4933 icb->timeout = cpu_to_le16(0);
4935 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4937 icb->firmware_options[0] &= ~BIT_3;
4938 icb->add_firmware_options[0] &=
4939 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4940 icb->add_firmware_options[0] |= BIT_2;
4941 icb->response_accumulation_timer = 3;
4942 icb->interrupt_delay_timer = 5;
4944 vha->flags.process_response_queue = 1;
4947 if (!vha->flags.init_done) {
4948 ha->zio_mode = icb->add_firmware_options[0] &
4949 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4950 ha->zio_timer = icb->interrupt_delay_timer ?
4951 icb->interrupt_delay_timer : 2;
4953 icb->add_firmware_options[0] &=
4954 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4955 vha->flags.process_response_queue = 0;
4956 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4957 ha->zio_mode = QLA_ZIO_MODE_6;
4959 ql_log(ql_log_info, vha, 0x0068,
4960 "ZIO mode %d enabled; timer delay (%d us).\n",
4961 ha->zio_mode, ha->zio_timer * 100);
4963 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4964 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
4965 vha->flags.process_response_queue = 1;
4970 ql_log(ql_log_warn, vha, 0x0069,
4971 "NVRAM configuration failed.\n");
4977 qla2x00_rport_del(void *data)
4979 fc_port_t *fcport = data;
4980 struct fc_rport *rport;
4981 unsigned long flags;
4983 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
4984 rport = fcport->drport ? fcport->drport : fcport->rport;
4985 fcport->drport = NULL;
4986 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
4988 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4989 "%s %8phN. rport %p roles %x\n",
4990 __func__, fcport->port_name, rport,
4993 fc_remote_port_delete(rport);
4997 void qla2x00_set_fcport_state(fc_port_t *fcport, int state)
5001 old_state = atomic_read(&fcport->state);
5002 atomic_set(&fcport->state, state);
5004 /* Don't print state transitions during initial allocation of fcport */
5005 if (old_state && old_state != state) {
5006 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
5007 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
5008 fcport->port_name, port_state_str[old_state],
5009 port_state_str[state], fcport->d_id.b.domain,
5010 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5015 * qla2x00_alloc_fcport() - Allocate a generic fcport.
5017 * @flags: allocation flags
5019 * Returns a pointer to the allocated fcport, or NULL, if none available.
5022 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
5026 fcport = kzalloc(sizeof(fc_port_t), flags);
5030 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
5031 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
5033 if (!fcport->ct_desc.ct_sns) {
5034 ql_log(ql_log_warn, vha, 0xd049,
5035 "Failed to allocate ct_sns request.\n");
5040 /* Setup fcport template structure. */
5042 fcport->port_type = FCT_UNKNOWN;
5043 fcport->loop_id = FC_NO_LOOP_ID;
5044 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
5045 fcport->supported_classes = FC_COS_UNSPECIFIED;
5046 fcport->fp_speed = PORT_SPEED_UNKNOWN;
5048 fcport->disc_state = DSC_DELETED;
5049 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
5050 fcport->deleted = QLA_SESS_DELETED;
5051 fcport->login_retry = vha->hw->login_retry_count;
5052 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
5053 fcport->logout_on_delete = 1;
5054 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
5055 fcport->tgt_short_link_down_cnt = 0;
5056 fcport->dev_loss_tmo = 0;
5058 if (!fcport->ct_desc.ct_sns) {
5059 ql_log(ql_log_warn, vha, 0xd049,
5060 "Failed to allocate ct_sns request.\n");
5065 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
5066 INIT_WORK(&fcport->free_work, qlt_free_session_done);
5067 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
5068 INIT_LIST_HEAD(&fcport->gnl_entry);
5069 INIT_LIST_HEAD(&fcport->list);
5071 INIT_LIST_HEAD(&fcport->sess_cmd_list);
5072 spin_lock_init(&fcport->sess_cmd_lock);
5074 spin_lock_init(&fcport->edif.sa_list_lock);
5075 INIT_LIST_HEAD(&fcport->edif.tx_sa_list);
5076 INIT_LIST_HEAD(&fcport->edif.rx_sa_list);
5078 if (vha->e_dbell.db_flags == EDB_ACTIVE)
5079 fcport->edif.app_started = 1;
5081 spin_lock_init(&fcport->edif.indx_list_lock);
5082 INIT_LIST_HEAD(&fcport->edif.edif_indx_list);
5088 qla2x00_free_fcport(fc_port_t *fcport)
5090 if (fcport->ct_desc.ct_sns) {
5091 dma_free_coherent(&fcport->vha->hw->pdev->dev,
5092 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
5093 fcport->ct_desc.ct_sns_dma);
5095 fcport->ct_desc.ct_sns = NULL;
5097 list_del(&fcport->list);
5098 qla2x00_clear_loop_id(fcport);
5102 static void qla_get_login_template(scsi_qla_host_t *vha)
5104 struct qla_hw_data *ha = vha->hw;
5109 memset(ha->init_cb, 0, ha->init_cb_size);
5110 sz = min_t(int, sizeof(struct fc_els_flogi), ha->init_cb_size);
5111 rval = qla24xx_get_port_login_templ(vha, ha->init_cb_dma,
5113 if (rval != QLA_SUCCESS) {
5114 ql_dbg(ql_dbg_init, vha, 0x00d1,
5115 "PLOGI ELS param read fail.\n");
5118 q = (__be32 *)&ha->plogi_els_payld.fl_csp;
5120 bp = (uint32_t *)ha->init_cb;
5121 cpu_to_be32_array(q, bp, sz / 4);
5122 ha->flags.plogi_template_valid = 1;
5126 * qla2x00_configure_loop
5127 * Updates Fibre Channel Device Database with what is actually on loop.
5130 * ha = adapter block pointer.
5135 * 2 = database was full and device was not configured.
5138 qla2x00_configure_loop(scsi_qla_host_t *vha)
5141 unsigned long flags, save_flags;
5142 struct qla_hw_data *ha = vha->hw;
5146 /* Get Initiator ID */
5147 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
5148 rval = qla2x00_configure_hba(vha);
5149 if (rval != QLA_SUCCESS) {
5150 ql_dbg(ql_dbg_disc, vha, 0x2013,
5151 "Unable to configure HBA.\n");
5156 save_flags = flags = vha->dpc_flags;
5157 ql_dbg(ql_dbg_disc, vha, 0x2014,
5158 "Configure loop -- dpc flags = 0x%lx.\n", flags);
5161 * If we have both an RSCN and PORT UPDATE pending then handle them
5162 * both at the same time.
5164 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5165 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
5167 qla2x00_get_data_rate(vha);
5168 qla_get_login_template(vha);
5170 /* Determine what we need to do */
5171 if ((ha->current_topology == ISP_CFG_FL ||
5172 ha->current_topology == ISP_CFG_F) &&
5173 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
5175 set_bit(RSCN_UPDATE, &flags);
5176 clear_bit(LOCAL_LOOP_UPDATE, &flags);
5178 } else if (ha->current_topology == ISP_CFG_NL ||
5179 ha->current_topology == ISP_CFG_N) {
5180 clear_bit(RSCN_UPDATE, &flags);
5181 set_bit(LOCAL_LOOP_UPDATE, &flags);
5182 } else if (!vha->flags.online ||
5183 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
5184 set_bit(RSCN_UPDATE, &flags);
5185 set_bit(LOCAL_LOOP_UPDATE, &flags);
5188 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
5189 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5190 ql_dbg(ql_dbg_disc, vha, 0x2015,
5191 "Loop resync needed, failing.\n");
5192 rval = QLA_FUNCTION_FAILED;
5194 rval = qla2x00_configure_local_loop(vha);
5197 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
5198 if (LOOP_TRANSITION(vha)) {
5199 ql_dbg(ql_dbg_disc, vha, 0x2099,
5200 "Needs RSCN update and loop transition.\n");
5201 rval = QLA_FUNCTION_FAILED;
5204 rval = qla2x00_configure_fabric(vha);
5207 if (rval == QLA_SUCCESS) {
5208 if (atomic_read(&vha->loop_down_timer) ||
5209 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5210 rval = QLA_FUNCTION_FAILED;
5212 atomic_set(&vha->loop_state, LOOP_READY);
5213 ql_dbg(ql_dbg_disc, vha, 0x2069,
5215 ha->flags.fw_init_done = 1;
5218 * Process any ATIO queue entries that came in
5219 * while we weren't online.
5221 if (qla_tgt_mode_enabled(vha) ||
5222 qla_dual_mode_enabled(vha)) {
5223 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
5224 qlt_24xx_process_atio_queue(vha, 0);
5225 spin_unlock_irqrestore(&ha->tgt.atio_lock,
5232 ql_dbg(ql_dbg_disc, vha, 0x206a,
5233 "%s *** FAILED ***.\n", __func__);
5235 ql_dbg(ql_dbg_disc, vha, 0x206b,
5236 "%s: exiting normally.\n", __func__);
5239 /* Restore state if a resync event occurred during processing */
5240 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5241 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
5242 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5243 if (test_bit(RSCN_UPDATE, &save_flags)) {
5244 set_bit(RSCN_UPDATE, &vha->dpc_flags);
5251 static int qla2x00_configure_n2n_loop(scsi_qla_host_t *vha)
5253 unsigned long flags;
5256 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags))
5257 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5259 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5260 if (fcport->n2n_flag) {
5261 qla24xx_fcport_handle_login(vha, fcport);
5266 spin_lock_irqsave(&vha->work_lock, flags);
5267 vha->scan.scan_retry++;
5268 spin_unlock_irqrestore(&vha->work_lock, flags);
5270 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5271 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5272 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5274 return QLA_FUNCTION_FAILED;
5278 * qla2x00_configure_local_loop
5279 * Updates Fibre Channel Device Database with local loop devices.
5282 * ha = adapter block pointer.
5288 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
5293 fc_port_t *fcport, *new_fcport;
5296 struct gid_list_info *gid;
5298 uint8_t domain, area, al_pa;
5299 struct qla_hw_data *ha = vha->hw;
5300 unsigned long flags;
5302 /* Inititae N2N login. */
5304 return qla2x00_configure_n2n_loop(vha);
5308 entries = MAX_FIBRE_DEVICES_LOOP;
5310 /* Get list of logged in devices. */
5311 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
5312 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
5314 if (rval != QLA_SUCCESS)
5317 ql_dbg(ql_dbg_disc, vha, 0x2011,
5318 "Entries in ID list (%d).\n", entries);
5319 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
5320 ha->gid_list, entries * sizeof(*ha->gid_list));
5323 spin_lock_irqsave(&vha->work_lock, flags);
5324 vha->scan.scan_retry++;
5325 spin_unlock_irqrestore(&vha->work_lock, flags);
5327 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5328 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5329 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5332 vha->scan.scan_retry = 0;
5335 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5336 fcport->scan_state = QLA_FCPORT_SCAN;
5339 /* Allocate temporary fcport for any new fcports discovered. */
5340 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5341 if (new_fcport == NULL) {
5342 ql_log(ql_log_warn, vha, 0x2012,
5343 "Memory allocation failed for fcport.\n");
5344 rval = QLA_MEMORY_ALLOC_FAILED;
5347 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5349 /* Add devices to port list. */
5351 for (index = 0; index < entries; index++) {
5352 domain = gid->domain;
5355 if (IS_QLA2100(ha) || IS_QLA2200(ha))
5356 loop_id = gid->loop_id_2100;
5358 loop_id = le16_to_cpu(gid->loop_id);
5359 gid = (void *)gid + ha->gid_list_info_size;
5361 /* Bypass reserved domain fields. */
5362 if ((domain & 0xf0) == 0xf0)
5365 /* Bypass if not same domain and area of adapter. */
5366 if (area && domain && ((area != vha->d_id.b.area) ||
5367 (domain != vha->d_id.b.domain)) &&
5368 (ha->current_topology == ISP_CFG_NL))
5372 /* Bypass invalid local loop ID. */
5373 if (loop_id > LAST_LOCAL_LOOP_ID)
5376 memset(new_fcport->port_name, 0, WWN_SIZE);
5378 /* Fill in member data. */
5379 new_fcport->d_id.b.domain = domain;
5380 new_fcport->d_id.b.area = area;
5381 new_fcport->d_id.b.al_pa = al_pa;
5382 new_fcport->loop_id = loop_id;
5383 new_fcport->scan_state = QLA_FCPORT_FOUND;
5385 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
5386 if (rval2 != QLA_SUCCESS) {
5387 ql_dbg(ql_dbg_disc, vha, 0x2097,
5388 "Failed to retrieve fcport information "
5389 "-- get_port_database=%x, loop_id=0x%04x.\n",
5390 rval2, new_fcport->loop_id);
5391 /* Skip retry if N2N */
5392 if (ha->current_topology != ISP_CFG_N) {
5393 ql_dbg(ql_dbg_disc, vha, 0x2105,
5394 "Scheduling resync.\n");
5395 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5400 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5401 /* Check for matching device in port list. */
5404 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5405 if (memcmp(new_fcport->port_name, fcport->port_name,
5409 fcport->flags &= ~FCF_FABRIC_DEVICE;
5410 fcport->loop_id = new_fcport->loop_id;
5411 fcport->port_type = new_fcport->port_type;
5412 fcport->d_id.b24 = new_fcport->d_id.b24;
5413 memcpy(fcport->node_name, new_fcport->node_name,
5415 fcport->scan_state = QLA_FCPORT_FOUND;
5421 /* New device, add to fcports list. */
5422 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5424 /* Allocate a new replacement fcport. */
5425 fcport = new_fcport;
5427 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5429 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5431 if (new_fcport == NULL) {
5432 ql_log(ql_log_warn, vha, 0xd031,
5433 "Failed to allocate memory for fcport.\n");
5434 rval = QLA_MEMORY_ALLOC_FAILED;
5437 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5438 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5441 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5443 /* Base iIDMA settings on HBA port speed. */
5444 fcport->fp_speed = ha->link_data_rate;
5449 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5450 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5453 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5454 if ((qla_dual_mode_enabled(vha) ||
5455 qla_ini_mode_enabled(vha)) &&
5456 atomic_read(&fcport->state) == FCS_ONLINE) {
5457 qla2x00_mark_device_lost(vha, fcport,
5458 ql2xplogiabsentdevice);
5459 if (fcport->loop_id != FC_NO_LOOP_ID &&
5460 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5461 fcport->port_type != FCT_INITIATOR &&
5462 fcport->port_type != FCT_BROADCAST) {
5463 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5464 "%s %d %8phC post del sess\n",
5468 qlt_schedule_sess_for_deletion(fcport);
5474 if (fcport->scan_state == QLA_FCPORT_FOUND)
5475 qla24xx_fcport_handle_login(vha, fcport);
5478 qla2x00_free_fcport(new_fcport);
5483 ql_dbg(ql_dbg_disc, vha, 0x2098,
5484 "Configure local loop error exit: rval=%x.\n", rval);
5489 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5492 uint16_t mb[MAILBOX_REGISTER_COUNT];
5493 struct qla_hw_data *ha = vha->hw;
5495 if (!IS_IIDMA_CAPABLE(ha))
5498 if (atomic_read(&fcport->state) != FCS_ONLINE)
5501 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
5502 fcport->fp_speed > ha->link_data_rate ||
5503 !ha->flags.gpsc_supported)
5506 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
5508 if (rval != QLA_SUCCESS) {
5509 ql_dbg(ql_dbg_disc, vha, 0x2004,
5510 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5511 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
5513 ql_dbg(ql_dbg_disc, vha, 0x2005,
5514 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5515 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
5516 fcport->fp_speed, fcport->port_name);
5520 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5522 qla2x00_iidma_fcport(vha, fcport);
5523 qla24xx_update_fcport_fcp_prio(vha, fcport);
5526 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5528 struct qla_work_evt *e;
5530 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
5532 return QLA_FUNCTION_FAILED;
5534 e->u.fcport.fcport = fcport;
5535 return qla2x00_post_work(vha, e);
5538 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5540 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
5542 struct fc_rport_identifiers rport_ids;
5543 struct fc_rport *rport;
5544 unsigned long flags;
5546 if (atomic_read(&fcport->state) == FCS_ONLINE)
5549 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5550 rport_ids.port_name = wwn_to_u64(fcport->port_name);
5551 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5552 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5553 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5554 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
5556 ql_log(ql_log_warn, vha, 0x2006,
5557 "Unable to allocate fc remote port.\n");
5561 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5562 *((fc_port_t **)rport->dd_data) = fcport;
5563 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5564 fcport->dev_loss_tmo = rport->dev_loss_tmo;
5566 rport->supported_classes = fcport->supported_classes;
5568 rport_ids.roles = FC_PORT_ROLE_UNKNOWN;
5569 if (fcport->port_type == FCT_INITIATOR)
5570 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
5571 if (fcport->port_type == FCT_TARGET)
5572 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
5573 if (fcport->port_type & FCT_NVME_INITIATOR)
5574 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
5575 if (fcport->port_type & FCT_NVME_TARGET)
5576 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
5577 if (fcport->port_type & FCT_NVME_DISCOVERY)
5578 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
5580 fc_remote_port_rolechg(rport, rport_ids.roles);
5582 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5583 "%s: %8phN. rport %ld:0:%d (%p) is %s mode\n",
5584 __func__, fcport->port_name, vha->host_no,
5585 rport->scsi_target_id, rport,
5586 (fcport->port_type == FCT_TARGET) ? "tgt" :
5587 ((fcport->port_type & FCT_NVME) ? "nvme" : "ini"));
5591 * qla2x00_update_fcport
5592 * Updates device on list.
5595 * ha = adapter block pointer.
5596 * fcport = port structure pointer.
5606 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5608 if (IS_SW_RESV_ADDR(fcport->d_id))
5611 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
5612 __func__, fcport->port_name);
5614 qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT);
5615 fcport->login_retry = vha->hw->login_retry_count;
5616 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5617 fcport->deleted = 0;
5618 if (vha->hw->current_topology == ISP_CFG_NL)
5619 fcport->logout_on_delete = 0;
5621 fcport->logout_on_delete = 1;
5622 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
5624 if (fcport->tgt_link_down_time < fcport->dev_loss_tmo) {
5625 fcport->tgt_short_link_down_cnt++;
5626 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
5629 switch (vha->hw->current_topology) {
5632 fcport->keep_nport_handle = 1;
5638 qla2x00_iidma_fcport(vha, fcport);
5640 qla2x00_dfs_create_rport(vha, fcport);
5642 if (NVME_TARGET(vha->hw, fcport)) {
5643 qla_nvme_register_remote(vha, fcport);
5644 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
5645 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5649 qla24xx_update_fcport_fcp_prio(vha, fcport);
5651 switch (vha->host->active_mode) {
5652 case MODE_INITIATOR:
5653 qla2x00_reg_remote_port(vha, fcport);
5656 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5657 !vha->vha_tgt.qla_tgt->tgt_stopped)
5658 qlt_fc_port_added(vha, fcport);
5661 qla2x00_reg_remote_port(vha, fcport);
5662 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5663 !vha->vha_tgt.qla_tgt->tgt_stopped)
5664 qlt_fc_port_added(vha, fcport);
5670 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5672 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
5673 if (fcport->id_changed) {
5674 fcport->id_changed = 0;
5675 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5676 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5677 __func__, __LINE__, fcport->port_name,
5679 qla24xx_post_gfpnid_work(vha, fcport);
5681 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5682 "%s %d %8phC post gpsc fcp_cnt %d\n",
5683 __func__, __LINE__, fcport->port_name,
5685 qla24xx_post_gpsc_work(vha, fcport);
5689 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
5692 void qla_register_fcport_fn(struct work_struct *work)
5694 fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
5695 u32 rscn_gen = fcport->rscn_gen;
5698 if (IS_SW_RESV_ADDR(fcport->d_id))
5701 qla2x00_update_fcport(fcport->vha, fcport);
5703 if (rscn_gen != fcport->rscn_gen) {
5704 /* RSCN(s) came in while registration */
5705 switch (fcport->next_disc_state) {
5706 case DSC_DELETE_PEND:
5707 qlt_schedule_sess_for_deletion(fcport);
5710 data[0] = data[1] = 0;
5711 qla2x00_post_async_adisc_work(fcport->vha, fcport,
5721 * qla2x00_configure_fabric
5722 * Setup SNS devices with loop ID's.
5725 * ha = adapter block pointer.
5732 qla2x00_configure_fabric(scsi_qla_host_t *vha)
5736 uint16_t mb[MAILBOX_REGISTER_COUNT];
5738 LIST_HEAD(new_fcports);
5739 struct qla_hw_data *ha = vha->hw;
5742 /* If FL port exists, then SNS is present */
5743 if (IS_FWI2_CAPABLE(ha))
5744 loop_id = NPH_F_PORT;
5746 loop_id = SNS_FL_PORT;
5747 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
5748 if (rval != QLA_SUCCESS) {
5749 ql_dbg(ql_dbg_disc, vha, 0x20a0,
5750 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5752 vha->device_flags &= ~SWITCH_FOUND;
5753 return (QLA_SUCCESS);
5755 vha->device_flags |= SWITCH_FOUND;
5757 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_port_name, 0);
5758 if (rval != QLA_SUCCESS)
5759 ql_dbg(ql_dbg_disc, vha, 0x20ff,
5760 "Failed to get Fabric Port Name\n");
5762 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
5763 rval = qla2x00_send_change_request(vha, 0x3, 0);
5764 if (rval != QLA_SUCCESS)
5765 ql_log(ql_log_warn, vha, 0x121,
5766 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5771 qla2x00_mgmt_svr_login(vha);
5773 /* Ensure we are logged into the SNS. */
5774 loop_id = NPH_SNS_LID(ha);
5775 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5776 0xfc, mb, BIT_1|BIT_0);
5777 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5778 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5779 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5780 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
5781 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5786 if (ql2xfdmienable &&
5787 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5788 qla2x00_fdmi_register(vha);
5790 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5791 if (qla2x00_rft_id(vha)) {
5793 ql_dbg(ql_dbg_disc, vha, 0x20a2,
5794 "Register FC-4 TYPE failed.\n");
5795 if (test_bit(LOOP_RESYNC_NEEDED,
5799 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
5801 ql_dbg(ql_dbg_disc, vha, 0x209a,
5802 "Register FC-4 Features failed.\n");
5803 if (test_bit(LOOP_RESYNC_NEEDED,
5807 if (vha->flags.nvme_enabled) {
5808 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5809 ql_dbg(ql_dbg_disc, vha, 0x2049,
5810 "Register NVME FC Type Features failed.\n");
5813 if (qla2x00_rnn_id(vha)) {
5815 ql_dbg(ql_dbg_disc, vha, 0x2104,
5816 "Register Node Name failed.\n");
5817 if (test_bit(LOOP_RESYNC_NEEDED,
5820 } else if (qla2x00_rsnn_nn(vha)) {
5822 ql_dbg(ql_dbg_disc, vha, 0x209b,
5823 "Register Symbolic Node Name failed.\n");
5824 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5830 /* Mark the time right before querying FW for connected ports.
5831 * This process is long, asynchronous and by the time it's done,
5832 * collected information might not be accurate anymore. E.g.
5833 * disconnected port might have re-connected and a brand new
5834 * session has been created. In this case session's generation
5835 * will be newer than discovery_gen. */
5836 qlt_do_generation_tick(vha, &discovery_gen);
5838 if (USE_ASYNC_SCAN(ha)) {
5839 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
5842 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5844 list_for_each_entry(fcport, &vha->vp_fcports, list)
5845 fcport->scan_state = QLA_FCPORT_SCAN;
5847 rval = qla2x00_find_all_fabric_devs(vha);
5849 if (rval != QLA_SUCCESS)
5853 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5854 qla_nvme_register_hba(vha);
5857 ql_dbg(ql_dbg_disc, vha, 0x2068,
5858 "Configure fabric error exit rval=%d.\n", rval);
5864 * qla2x00_find_all_fabric_devs
5867 * ha = adapter block pointer.
5868 * dev = database device entry pointer.
5877 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
5881 fc_port_t *fcport, *new_fcport;
5886 int first_dev, last_dev;
5887 port_id_t wrap = {}, nxt_d_id;
5888 struct qla_hw_data *ha = vha->hw;
5889 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5890 unsigned long flags;
5894 /* Try GID_PT to get device list, else GAN. */
5896 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
5901 ql_dbg(ql_dbg_disc, vha, 0x209c,
5902 "GID_PT allocations failed, fallback on GA_NXT.\n");
5904 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
5905 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
5907 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5909 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
5911 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5913 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
5915 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5917 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5919 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5923 /* If other queries succeeded probe for FC-4 type */
5925 qla2x00_gff_id(vha, swl);
5926 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5932 /* Allocate temporary fcport for any new fcports discovered. */
5933 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5934 if (new_fcport == NULL) {
5935 ql_log(ql_log_warn, vha, 0x209d,
5936 "Failed to allocate memory for fcport.\n");
5937 return (QLA_MEMORY_ALLOC_FAILED);
5939 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5940 /* Set start port ID scan at adapter ID. */
5944 /* Starting free loop ID. */
5945 loop_id = ha->min_external_loopid;
5946 for (; loop_id <= ha->max_loop_id; loop_id++) {
5947 if (qla2x00_is_reserved_id(vha, loop_id))
5950 if (ha->current_topology == ISP_CFG_FL &&
5951 (atomic_read(&vha->loop_down_timer) ||
5952 LOOP_TRANSITION(vha))) {
5953 atomic_set(&vha->loop_down_timer, 0);
5954 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5955 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5961 wrap.b24 = new_fcport->d_id.b24;
5963 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
5964 memcpy(new_fcport->node_name,
5965 swl[swl_idx].node_name, WWN_SIZE);
5966 memcpy(new_fcport->port_name,
5967 swl[swl_idx].port_name, WWN_SIZE);
5968 memcpy(new_fcport->fabric_port_name,
5969 swl[swl_idx].fabric_port_name, WWN_SIZE);
5970 new_fcport->fp_speed = swl[swl_idx].fp_speed;
5971 new_fcport->fc4_type = swl[swl_idx].fc4_type;
5973 new_fcport->nvme_flag = 0;
5974 if (vha->flags.nvme_enabled &&
5975 swl[swl_idx].fc4_type & FS_FC4TYPE_NVME) {
5976 ql_log(ql_log_info, vha, 0x2131,
5977 "FOUND: NVME port %8phC as FC Type 28h\n",
5978 new_fcport->port_name);
5981 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5987 /* Send GA_NXT to the switch */
5988 rval = qla2x00_ga_nxt(vha, new_fcport);
5989 if (rval != QLA_SUCCESS) {
5990 ql_log(ql_log_warn, vha, 0x209e,
5991 "SNS scan failed -- assuming "
5992 "zero-entry result.\n");
5998 /* If wrap on switch device list, exit. */
6000 wrap.b24 = new_fcport->d_id.b24;
6002 } else if (new_fcport->d_id.b24 == wrap.b24) {
6003 ql_dbg(ql_dbg_disc, vha, 0x209f,
6004 "Device wrap (%02x%02x%02x).\n",
6005 new_fcport->d_id.b.domain,
6006 new_fcport->d_id.b.area,
6007 new_fcport->d_id.b.al_pa);
6011 /* Bypass if same physical adapter. */
6012 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
6015 /* Bypass virtual ports of the same host. */
6016 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
6019 /* Bypass if same domain and area of adapter. */
6020 if (((new_fcport->d_id.b24 & 0xffff00) ==
6021 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
6025 /* Bypass reserved domain fields. */
6026 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
6029 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
6030 if (ql2xgffidenable &&
6031 (!(new_fcport->fc4_type & FS_FC4TYPE_FCP) &&
6032 new_fcport->fc4_type != 0))
6035 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
6037 /* Locate matching device in database. */
6039 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6040 if (memcmp(new_fcport->port_name, fcport->port_name,
6044 fcport->scan_state = QLA_FCPORT_FOUND;
6048 /* Update port state. */
6049 memcpy(fcport->fabric_port_name,
6050 new_fcport->fabric_port_name, WWN_SIZE);
6051 fcport->fp_speed = new_fcport->fp_speed;
6054 * If address the same and state FCS_ONLINE
6055 * (or in target mode), nothing changed.
6057 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
6058 (atomic_read(&fcport->state) == FCS_ONLINE ||
6059 (vha->host->active_mode == MODE_TARGET))) {
6063 if (fcport->login_retry == 0)
6064 fcport->login_retry =
6065 vha->hw->login_retry_count;
6067 * If device was not a fabric device before.
6069 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
6070 fcport->d_id.b24 = new_fcport->d_id.b24;
6071 qla2x00_clear_loop_id(fcport);
6072 fcport->flags |= (FCF_FABRIC_DEVICE |
6078 * Port ID changed or device was marked to be updated;
6079 * Log it out if still logged in and mark it for
6082 if (qla_tgt_mode_enabled(base_vha)) {
6083 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
6084 "port changed FC ID, %8phC"
6085 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
6087 fcport->d_id.b.domain,
6088 fcport->d_id.b.area,
6089 fcport->d_id.b.al_pa,
6091 new_fcport->d_id.b.domain,
6092 new_fcport->d_id.b.area,
6093 new_fcport->d_id.b.al_pa);
6094 fcport->d_id.b24 = new_fcport->d_id.b24;
6098 fcport->d_id.b24 = new_fcport->d_id.b24;
6099 fcport->flags |= FCF_LOGIN_NEEDED;
6103 if (found && NVME_TARGET(vha->hw, fcport)) {
6104 if (fcport->disc_state == DSC_DELETE_PEND) {
6105 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
6106 vha->fcport_count--;
6107 fcport->login_succ = 0;
6112 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6115 /* If device was not in our fcports list, then add it. */
6116 new_fcport->scan_state = QLA_FCPORT_FOUND;
6117 list_add_tail(&new_fcport->list, &vha->vp_fcports);
6119 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6122 /* Allocate a new replacement fcport. */
6123 nxt_d_id.b24 = new_fcport->d_id.b24;
6124 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
6125 if (new_fcport == NULL) {
6126 ql_log(ql_log_warn, vha, 0xd032,
6127 "Memory allocation failed for fcport.\n");
6128 return (QLA_MEMORY_ALLOC_FAILED);
6130 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
6131 new_fcport->d_id.b24 = nxt_d_id.b24;
6134 qla2x00_free_fcport(new_fcport);
6137 * Logout all previous fabric dev marked lost, except FCP2 devices.
6139 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6140 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6143 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
6146 if (fcport->scan_state == QLA_FCPORT_SCAN) {
6147 if ((qla_dual_mode_enabled(vha) ||
6148 qla_ini_mode_enabled(vha)) &&
6149 atomic_read(&fcport->state) == FCS_ONLINE) {
6150 qla2x00_mark_device_lost(vha, fcport,
6151 ql2xplogiabsentdevice);
6152 if (fcport->loop_id != FC_NO_LOOP_ID &&
6153 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
6154 fcport->port_type != FCT_INITIATOR &&
6155 fcport->port_type != FCT_BROADCAST) {
6156 ql_dbg(ql_dbg_disc, vha, 0x20f0,
6157 "%s %d %8phC post del sess\n",
6160 qlt_schedule_sess_for_deletion(fcport);
6166 if (fcport->scan_state == QLA_FCPORT_FOUND &&
6167 (fcport->flags & FCF_LOGIN_NEEDED) != 0)
6168 qla24xx_fcport_handle_login(vha, fcport);
6173 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
6175 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
6177 int loop_id = FC_NO_LOOP_ID;
6178 int lid = NPH_MGMT_SERVER - vha->vp_idx;
6179 unsigned long flags;
6180 struct qla_hw_data *ha = vha->hw;
6182 if (vha->vp_idx == 0) {
6183 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
6184 return NPH_MGMT_SERVER;
6187 /* pick id from high and work down to low */
6188 spin_lock_irqsave(&ha->vport_slock, flags);
6189 for (; lid > 0; lid--) {
6190 if (!test_bit(lid, vha->hw->loop_id_map)) {
6191 set_bit(lid, vha->hw->loop_id_map);
6196 spin_unlock_irqrestore(&ha->vport_slock, flags);
6202 * qla2x00_fabric_login
6203 * Issue fabric login command.
6206 * ha = adapter block pointer.
6207 * device = pointer to FC device type structure.
6210 * 0 - Login successfully
6212 * 2 - Initiator device
6216 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
6217 uint16_t *next_loopid)
6221 uint16_t tmp_loopid;
6222 uint16_t mb[MAILBOX_REGISTER_COUNT];
6223 struct qla_hw_data *ha = vha->hw;
6229 ql_dbg(ql_dbg_disc, vha, 0x2000,
6230 "Trying Fabric Login w/loop id 0x%04x for port "
6232 fcport->loop_id, fcport->d_id.b.domain,
6233 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6235 /* Login fcport on switch. */
6236 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
6237 fcport->d_id.b.domain, fcport->d_id.b.area,
6238 fcport->d_id.b.al_pa, mb, BIT_0);
6239 if (rval != QLA_SUCCESS) {
6242 if (mb[0] == MBS_PORT_ID_USED) {
6244 * Device has another loop ID. The firmware team
6245 * recommends the driver perform an implicit login with
6246 * the specified ID again. The ID we just used is save
6247 * here so we return with an ID that can be tried by
6251 tmp_loopid = fcport->loop_id;
6252 fcport->loop_id = mb[1];
6254 ql_dbg(ql_dbg_disc, vha, 0x2001,
6255 "Fabric Login: port in use - next loop "
6256 "id=0x%04x, port id= %02x%02x%02x.\n",
6257 fcport->loop_id, fcport->d_id.b.domain,
6258 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6260 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
6265 /* A retry occurred before. */
6266 *next_loopid = tmp_loopid;
6269 * No retry occurred before. Just increment the
6270 * ID value for next login.
6272 *next_loopid = (fcport->loop_id + 1);
6275 if (mb[1] & BIT_0) {
6276 fcport->port_type = FCT_INITIATOR;
6278 fcport->port_type = FCT_TARGET;
6279 if (mb[1] & BIT_1) {
6280 fcport->flags |= FCF_FCP2_DEVICE;
6285 fcport->supported_classes |= FC_COS_CLASS2;
6287 fcport->supported_classes |= FC_COS_CLASS3;
6289 if (IS_FWI2_CAPABLE(ha)) {
6292 FCF_CONF_COMP_SUPPORTED;
6297 } else if (mb[0] == MBS_LOOP_ID_USED) {
6299 * Loop ID already used, try next loop ID.
6302 rval = qla2x00_find_new_loop_id(vha, fcport);
6303 if (rval != QLA_SUCCESS) {
6304 /* Ran out of loop IDs to use */
6307 } else if (mb[0] == MBS_COMMAND_ERROR) {
6309 * Firmware possibly timed out during login. If NO
6310 * retries are left to do then the device is declared
6313 *next_loopid = fcport->loop_id;
6314 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6315 fcport->d_id.b.domain, fcport->d_id.b.area,
6316 fcport->d_id.b.al_pa);
6317 qla2x00_mark_device_lost(vha, fcport, 1);
6323 * unrecoverable / not handled error
6325 ql_dbg(ql_dbg_disc, vha, 0x2002,
6326 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6327 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
6328 fcport->d_id.b.area, fcport->d_id.b.al_pa,
6329 fcport->loop_id, jiffies);
6331 *next_loopid = fcport->loop_id;
6332 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6333 fcport->d_id.b.domain, fcport->d_id.b.area,
6334 fcport->d_id.b.al_pa);
6335 qla2x00_clear_loop_id(fcport);
6336 fcport->login_retry = 0;
6347 * qla2x00_local_device_login
6348 * Issue local device login command.
6351 * ha = adapter block pointer.
6352 * loop_id = loop id of device to login to.
6354 * Returns (Where's the #define!!!!):
6355 * 0 - Login successfully
6360 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
6363 uint16_t mb[MAILBOX_REGISTER_COUNT];
6365 memset(mb, 0, sizeof(mb));
6366 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
6367 if (rval == QLA_SUCCESS) {
6368 /* Interrogate mailbox registers for any errors */
6369 if (mb[0] == MBS_COMMAND_ERROR)
6371 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
6372 /* device not in PCB table */
6380 * qla2x00_loop_resync
6381 * Resync with fibre channel devices.
6384 * ha = adapter block pointer.
6390 qla2x00_loop_resync(scsi_qla_host_t *vha)
6392 int rval = QLA_SUCCESS;
6395 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6396 if (vha->flags.online) {
6397 if (!(rval = qla2x00_fw_ready(vha))) {
6398 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6401 if (!IS_QLAFX00(vha->hw)) {
6403 * Issue a marker after FW becomes
6406 qla2x00_marker(vha, vha->hw->base_qpair,
6408 vha->marker_needed = 0;
6411 /* Remap devices on Loop. */
6412 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6414 if (IS_QLAFX00(vha->hw))
6415 qlafx00_configure_devices(vha);
6417 qla2x00_configure_loop(vha);
6420 } while (!atomic_read(&vha->loop_down_timer) &&
6421 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6422 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
6427 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6428 return (QLA_FUNCTION_FAILED);
6431 ql_dbg(ql_dbg_disc, vha, 0x206c,
6432 "%s *** FAILED ***.\n", __func__);
6438 * qla2x00_perform_loop_resync
6439 * Description: This function will set the appropriate flags and call
6440 * qla2x00_loop_resync. If successful loop will be resynced
6441 * Arguments : scsi_qla_host_t pointer
6442 * returm : Success or Failure
6445 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
6449 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
6450 /*Configure the flags so that resync happens properly*/
6451 atomic_set(&ha->loop_down_timer, 0);
6452 if (!(ha->device_flags & DFLG_NO_CABLE)) {
6453 atomic_set(&ha->loop_state, LOOP_UP);
6454 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
6455 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
6456 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
6458 rval = qla2x00_loop_resync(ha);
6460 atomic_set(&ha->loop_state, LOOP_DEAD);
6462 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
6469 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
6472 struct scsi_qla_host *vha;
6473 struct qla_hw_data *ha = base_vha->hw;
6474 unsigned long flags;
6476 spin_lock_irqsave(&ha->vport_slock, flags);
6477 /* Go with deferred removal of rport references. */
6478 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
6479 atomic_inc(&vha->vref_count);
6480 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6481 if (fcport->drport &&
6482 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
6483 spin_unlock_irqrestore(&ha->vport_slock, flags);
6484 qla2x00_rport_del(fcport);
6486 spin_lock_irqsave(&ha->vport_slock, flags);
6489 atomic_dec(&vha->vref_count);
6490 wake_up(&vha->vref_waitq);
6492 spin_unlock_irqrestore(&ha->vport_slock, flags);
6495 /* Assumes idc_lock always held on entry */
6497 qla83xx_reset_ownership(scsi_qla_host_t *vha)
6499 struct qla_hw_data *ha = vha->hw;
6500 uint32_t drv_presence, drv_presence_mask;
6501 uint32_t dev_part_info1, dev_part_info2, class_type;
6502 uint32_t class_type_mask = 0x3;
6503 uint16_t fcoe_other_function = 0xffff, i;
6505 if (IS_QLA8044(ha)) {
6506 drv_presence = qla8044_rd_direct(vha,
6507 QLA8044_CRB_DRV_ACTIVE_INDEX);
6508 dev_part_info1 = qla8044_rd_direct(vha,
6509 QLA8044_CRB_DEV_PART_INFO_INDEX);
6510 dev_part_info2 = qla8044_rd_direct(vha,
6511 QLA8044_CRB_DEV_PART_INFO2);
6513 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6514 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
6515 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
6517 for (i = 0; i < 8; i++) {
6518 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
6519 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6520 (i != ha->portnum)) {
6521 fcoe_other_function = i;
6525 if (fcoe_other_function == 0xffff) {
6526 for (i = 0; i < 8; i++) {
6527 class_type = ((dev_part_info2 >> (i * 4)) &
6529 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6530 ((i + 8) != ha->portnum)) {
6531 fcoe_other_function = i + 8;
6537 * Prepare drv-presence mask based on fcoe functions present.
6538 * However consider only valid physical fcoe function numbers (0-15).
6540 drv_presence_mask = ~((1 << (ha->portnum)) |
6541 ((fcoe_other_function == 0xffff) ?
6542 0 : (1 << (fcoe_other_function))));
6544 /* We are the reset owner iff:
6545 * - No other protocol drivers present.
6546 * - This is the lowest among fcoe functions. */
6547 if (!(drv_presence & drv_presence_mask) &&
6548 (ha->portnum < fcoe_other_function)) {
6549 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
6550 "This host is Reset owner.\n");
6551 ha->flags.nic_core_reset_owner = 1;
6556 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
6558 int rval = QLA_SUCCESS;
6559 struct qla_hw_data *ha = vha->hw;
6562 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6563 if (rval == QLA_SUCCESS) {
6564 drv_ack |= (1 << ha->portnum);
6565 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6572 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
6574 int rval = QLA_SUCCESS;
6575 struct qla_hw_data *ha = vha->hw;
6578 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6579 if (rval == QLA_SUCCESS) {
6580 drv_ack &= ~(1 << ha->portnum);
6581 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6588 qla83xx_dev_state_to_string(uint32_t dev_state)
6590 switch (dev_state) {
6591 case QLA8XXX_DEV_COLD:
6592 return "COLD/RE-INIT";
6593 case QLA8XXX_DEV_INITIALIZING:
6594 return "INITIALIZING";
6595 case QLA8XXX_DEV_READY:
6597 case QLA8XXX_DEV_NEED_RESET:
6598 return "NEED RESET";
6599 case QLA8XXX_DEV_NEED_QUIESCENT:
6600 return "NEED QUIESCENT";
6601 case QLA8XXX_DEV_FAILED:
6603 case QLA8XXX_DEV_QUIESCENT:
6610 /* Assumes idc-lock always held on entry */
6612 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6614 struct qla_hw_data *ha = vha->hw;
6615 uint32_t idc_audit_reg = 0, duration_secs = 0;
6617 switch (audit_type) {
6618 case IDC_AUDIT_TIMESTAMP:
6619 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6620 idc_audit_reg = (ha->portnum) |
6621 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6622 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6625 case IDC_AUDIT_COMPLETION:
6626 duration_secs = ((jiffies_to_msecs(jiffies) -
6627 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6628 idc_audit_reg = (ha->portnum) |
6629 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6630 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6634 ql_log(ql_log_warn, vha, 0xb078,
6635 "Invalid audit type specified.\n");
6640 /* Assumes idc_lock always held on entry */
6642 qla83xx_initiating_reset(scsi_qla_host_t *vha)
6644 struct qla_hw_data *ha = vha->hw;
6645 uint32_t idc_control, dev_state;
6647 __qla83xx_get_idc_control(vha, &idc_control);
6648 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6649 ql_log(ql_log_info, vha, 0xb080,
6650 "NIC Core reset has been disabled. idc-control=0x%x\n",
6652 return QLA_FUNCTION_FAILED;
6655 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6656 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6657 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6658 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6659 QLA8XXX_DEV_NEED_RESET);
6660 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6661 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6663 const char *state = qla83xx_dev_state_to_string(dev_state);
6665 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
6667 /* SV: XXX: Is timeout required here? */
6668 /* Wait for IDC state change READY -> NEED_RESET */
6669 while (dev_state == QLA8XXX_DEV_READY) {
6670 qla83xx_idc_unlock(vha, 0);
6672 qla83xx_idc_lock(vha, 0);
6673 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6677 /* Send IDC ack by writing to drv-ack register */
6678 __qla83xx_set_drv_ack(vha);
6684 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6686 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6690 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6692 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6696 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6698 uint32_t drv_presence = 0;
6699 struct qla_hw_data *ha = vha->hw;
6701 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6702 if (drv_presence & (1 << ha->portnum))
6705 return QLA_TEST_FAILED;
6709 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6711 int rval = QLA_SUCCESS;
6712 struct qla_hw_data *ha = vha->hw;
6714 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6715 "Entered %s().\n", __func__);
6717 if (vha->device_flags & DFLG_DEV_FAILED) {
6718 ql_log(ql_log_warn, vha, 0xb059,
6719 "Device in unrecoverable FAILED state.\n");
6720 return QLA_FUNCTION_FAILED;
6723 qla83xx_idc_lock(vha, 0);
6725 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6726 ql_log(ql_log_warn, vha, 0xb05a,
6727 "Function=0x%x has been removed from IDC participation.\n",
6729 rval = QLA_FUNCTION_FAILED;
6733 qla83xx_reset_ownership(vha);
6735 rval = qla83xx_initiating_reset(vha);
6738 * Perform reset if we are the reset-owner,
6739 * else wait till IDC state changes to READY/FAILED.
6741 if (rval == QLA_SUCCESS) {
6742 rval = qla83xx_idc_state_handler(vha);
6744 if (rval == QLA_SUCCESS)
6745 ha->flags.nic_core_hung = 0;
6746 __qla83xx_clear_drv_ack(vha);
6750 qla83xx_idc_unlock(vha, 0);
6752 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6758 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6760 struct qla_hw_data *ha = vha->hw;
6761 int rval = QLA_FUNCTION_FAILED;
6763 if (!IS_MCTP_CAPABLE(ha)) {
6764 /* This message can be removed from the final version */
6765 ql_log(ql_log_info, vha, 0x506d,
6766 "This board is not MCTP capable\n");
6770 if (!ha->mctp_dump) {
6771 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6772 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6774 if (!ha->mctp_dump) {
6775 ql_log(ql_log_warn, vha, 0x506e,
6776 "Failed to allocate memory for mctp dump\n");
6781 #define MCTP_DUMP_STR_ADDR 0x00000000
6782 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6783 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6784 if (rval != QLA_SUCCESS) {
6785 ql_log(ql_log_warn, vha, 0x506f,
6786 "Failed to capture mctp dump\n");
6788 ql_log(ql_log_info, vha, 0x5070,
6789 "Mctp dump capture for host (%ld/%p).\n",
6790 vha->host_no, ha->mctp_dump);
6791 ha->mctp_dumped = 1;
6794 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
6795 ha->flags.nic_core_reset_hdlr_active = 1;
6796 rval = qla83xx_restart_nic_firmware(vha);
6798 /* NIC Core reset failed. */
6799 ql_log(ql_log_warn, vha, 0x5071,
6800 "Failed to restart nic firmware\n");
6802 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6803 "Restarted NIC firmware successfully.\n");
6804 ha->flags.nic_core_reset_hdlr_active = 0;
6812 * qla2x00_quiesce_io
6813 * Description: This function will block the new I/Os
6814 * Its not aborting any I/Os as context
6815 * is not destroyed during quiescence
6816 * Arguments: scsi_qla_host_t
6820 qla2x00_quiesce_io(scsi_qla_host_t *vha)
6822 struct qla_hw_data *ha = vha->hw;
6823 struct scsi_qla_host *vp;
6825 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6826 "Quiescing I/O - ha=%p.\n", ha);
6828 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6829 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6830 atomic_set(&vha->loop_state, LOOP_DOWN);
6831 qla2x00_mark_all_devices_lost(vha);
6832 list_for_each_entry(vp, &ha->vp_list, list)
6833 qla2x00_mark_all_devices_lost(vp);
6835 if (!atomic_read(&vha->loop_down_timer))
6836 atomic_set(&vha->loop_down_timer,
6839 /* Wait for pending cmds to complete */
6840 WARN_ON_ONCE(qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST)
6845 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6847 struct qla_hw_data *ha = vha->hw;
6848 struct scsi_qla_host *vp;
6849 unsigned long flags;
6853 /* For ISP82XX, driver waits for completion of the commands.
6854 * online flag should be set.
6856 if (!(IS_P3P_TYPE(ha)))
6857 vha->flags.online = 0;
6858 ha->flags.chip_reset_done = 0;
6859 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6860 vha->qla_stats.total_isp_aborts++;
6862 ql_log(ql_log_info, vha, 0x00af,
6863 "Performing ISP error recovery - ha=%p.\n", ha);
6865 ha->flags.purge_mbox = 1;
6866 /* For ISP82XX, reset_chip is just disabling interrupts.
6867 * Driver waits for the completion of the commands.
6868 * the interrupts need to be enabled.
6870 if (!(IS_P3P_TYPE(ha)))
6871 ha->isp_ops->reset_chip(vha);
6873 ha->link_data_rate = PORT_SPEED_UNKNOWN;
6875 ha->flags.rida_fmt2 = 0;
6876 ha->flags.n2n_ae = 0;
6877 ha->flags.lip_ae = 0;
6878 ha->current_topology = 0;
6880 ha->flags.fw_init_done = 0;
6882 ha->base_qpair->chip_reset = ha->chip_reset;
6883 ha->base_qpair->cmd_cnt = ha->base_qpair->cmd_completion_cnt = 0;
6884 for (i = 0; i < ha->max_qpairs; i++) {
6885 if (ha->queue_pair_map[i]) {
6886 ha->queue_pair_map[i]->chip_reset =
6887 ha->base_qpair->chip_reset;
6888 ha->queue_pair_map[i]->cmd_cnt =
6889 ha->queue_pair_map[i]->cmd_completion_cnt = 0;
6893 /* purge MBox commands */
6894 if (atomic_read(&ha->num_pend_mbx_stage3)) {
6895 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
6896 complete(&ha->mbx_intr_comp);
6900 while (atomic_read(&ha->num_pend_mbx_stage3) ||
6901 atomic_read(&ha->num_pend_mbx_stage2) ||
6902 atomic_read(&ha->num_pend_mbx_stage1)) {
6908 ha->flags.purge_mbox = 0;
6910 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6911 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6912 atomic_set(&vha->loop_state, LOOP_DOWN);
6913 qla2x00_mark_all_devices_lost(vha);
6915 spin_lock_irqsave(&ha->vport_slock, flags);
6916 list_for_each_entry(vp, &ha->vp_list, list) {
6917 atomic_inc(&vp->vref_count);
6918 spin_unlock_irqrestore(&ha->vport_slock, flags);
6920 qla2x00_mark_all_devices_lost(vp);
6922 spin_lock_irqsave(&ha->vport_slock, flags);
6923 atomic_dec(&vp->vref_count);
6925 spin_unlock_irqrestore(&ha->vport_slock, flags);
6927 if (!atomic_read(&vha->loop_down_timer))
6928 atomic_set(&vha->loop_down_timer,
6932 /* Clear all async request states across all VPs. */
6933 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6934 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6935 fcport->scan_state = 0;
6937 spin_lock_irqsave(&ha->vport_slock, flags);
6938 list_for_each_entry(vp, &ha->vp_list, list) {
6939 atomic_inc(&vp->vref_count);
6940 spin_unlock_irqrestore(&ha->vport_slock, flags);
6942 list_for_each_entry(fcport, &vp->vp_fcports, list)
6943 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6945 spin_lock_irqsave(&ha->vport_slock, flags);
6946 atomic_dec(&vp->vref_count);
6948 spin_unlock_irqrestore(&ha->vport_slock, flags);
6950 /* Make sure for ISP 82XX IO DMA is complete */
6951 if (IS_P3P_TYPE(ha)) {
6952 qla82xx_chip_reset_cleanup(vha);
6953 ql_log(ql_log_info, vha, 0x00b4,
6954 "Done chip reset cleanup.\n");
6956 /* Done waiting for pending commands. Reset online flag */
6957 vha->flags.online = 0;
6960 /* Requeue all commands in outstanding command list. */
6961 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6962 /* memory barrier */
6968 * Resets ISP and aborts all outstanding commands.
6971 * ha = adapter block pointer.
6977 qla2x00_abort_isp(scsi_qla_host_t *vha)
6981 struct qla_hw_data *ha = vha->hw;
6982 struct scsi_qla_host *vp;
6983 struct req_que *req = ha->req_q_map[0];
6984 unsigned long flags;
6986 if (vha->flags.online) {
6987 qla2x00_abort_isp_cleanup(vha);
6989 if (vha->hw->flags.port_isolated)
6992 if (qla2x00_isp_reg_stat(ha)) {
6993 ql_log(ql_log_info, vha, 0x803f,
6994 "ISP Abort - ISP reg disconnect, exiting.\n");
6998 if (test_and_clear_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags)) {
6999 ha->flags.chip_reset_done = 1;
7000 vha->flags.online = 1;
7002 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7006 if (IS_QLA8031(ha)) {
7007 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
7008 "Clearing fcoe driver presence.\n");
7009 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
7010 ql_dbg(ql_dbg_p3p, vha, 0xb073,
7011 "Error while clearing DRV-Presence.\n");
7014 if (unlikely(pci_channel_offline(ha->pdev) &&
7015 ha->flags.pci_channel_io_perm_failure)) {
7016 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7021 switch (vha->qlini_mode) {
7022 case QLA2XXX_INI_MODE_DISABLED:
7023 if (!qla_tgt_mode_enabled(vha))
7026 case QLA2XXX_INI_MODE_DUAL:
7027 if (!qla_dual_mode_enabled(vha))
7030 case QLA2XXX_INI_MODE_ENABLED:
7035 ha->isp_ops->get_flash_version(vha, req->ring);
7037 if (qla2x00_isp_reg_stat(ha)) {
7038 ql_log(ql_log_info, vha, 0x803f,
7039 "ISP Abort - ISP reg disconnect pre nvram config, exiting.\n");
7042 ha->isp_ops->nvram_config(vha);
7044 if (qla2x00_isp_reg_stat(ha)) {
7045 ql_log(ql_log_info, vha, 0x803f,
7046 "ISP Abort - ISP reg disconnect post nvmram config, exiting.\n");
7049 if (!qla2x00_restart_isp(vha)) {
7050 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7052 if (!atomic_read(&vha->loop_down_timer)) {
7054 * Issue marker command only when we are going
7055 * to start the I/O .
7057 vha->marker_needed = 1;
7060 vha->flags.online = 1;
7062 ha->isp_ops->enable_intrs(ha);
7064 ha->isp_abort_cnt = 0;
7065 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7067 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
7068 qla2x00_get_fw_version(vha);
7070 ha->flags.fce_enabled = 1;
7072 fce_calc_size(ha->fce_bufs));
7073 rval = qla2x00_enable_fce_trace(vha,
7074 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
7077 ql_log(ql_log_warn, vha, 0x8033,
7078 "Unable to reinitialize FCE "
7080 ha->flags.fce_enabled = 0;
7085 memset(ha->eft, 0, EFT_SIZE);
7086 rval = qla2x00_enable_eft_trace(vha,
7087 ha->eft_dma, EFT_NUM_BUFFERS);
7089 ql_log(ql_log_warn, vha, 0x8034,
7090 "Unable to reinitialize EFT "
7094 } else { /* failed the ISP abort */
7095 vha->flags.online = 1;
7096 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
7097 if (ha->isp_abort_cnt == 0) {
7098 ql_log(ql_log_fatal, vha, 0x8035,
7099 "ISP error recover failed - "
7100 "board disabled.\n");
7102 * The next call disables the board
7105 qla2x00_abort_isp_cleanup(vha);
7106 vha->flags.online = 0;
7107 clear_bit(ISP_ABORT_RETRY,
7110 } else { /* schedule another ISP abort */
7111 ha->isp_abort_cnt--;
7112 ql_dbg(ql_dbg_taskm, vha, 0x8020,
7113 "ISP abort - retry remaining %d.\n",
7118 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
7119 ql_dbg(ql_dbg_taskm, vha, 0x8021,
7120 "ISP error recovery - retrying (%d) "
7121 "more times.\n", ha->isp_abort_cnt);
7122 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7129 if (vha->hw->flags.port_isolated) {
7130 qla2x00_abort_isp_cleanup(vha);
7135 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
7136 qla2x00_configure_hba(vha);
7137 spin_lock_irqsave(&ha->vport_slock, flags);
7138 list_for_each_entry(vp, &ha->vp_list, list) {
7140 atomic_inc(&vp->vref_count);
7141 spin_unlock_irqrestore(&ha->vport_slock, flags);
7143 qla2x00_vp_abort_isp(vp);
7145 spin_lock_irqsave(&ha->vport_slock, flags);
7146 atomic_dec(&vp->vref_count);
7149 spin_unlock_irqrestore(&ha->vport_slock, flags);
7151 if (IS_QLA8031(ha)) {
7152 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
7153 "Setting back fcoe driver presence.\n");
7154 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
7155 ql_dbg(ql_dbg_p3p, vha, 0xb074,
7156 "Error while setting DRV-Presence.\n");
7159 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
7167 * qla2x00_restart_isp
7168 * restarts the ISP after a reset
7171 * ha = adapter block pointer.
7177 qla2x00_restart_isp(scsi_qla_host_t *vha)
7180 struct qla_hw_data *ha = vha->hw;
7182 /* If firmware needs to be loaded */
7183 if (qla2x00_isp_firmware(vha)) {
7184 vha->flags.online = 0;
7185 status = ha->isp_ops->chip_diag(vha);
7188 status = qla2x00_setup_chip(vha);
7193 status = qla2x00_init_rings(vha);
7197 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7198 ha->flags.chip_reset_done = 1;
7200 /* Initialize the queues in use */
7201 qla25xx_init_queues(ha);
7203 status = qla2x00_fw_ready(vha);
7205 /* if no cable then assume it's good */
7206 return vha->device_flags & DFLG_NO_CABLE ? 0 : status;
7209 /* Issue a marker after FW becomes ready. */
7210 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
7211 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7217 qla25xx_init_queues(struct qla_hw_data *ha)
7219 struct rsp_que *rsp = NULL;
7220 struct req_que *req = NULL;
7221 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7225 for (i = 1; i < ha->max_rsp_queues; i++) {
7226 rsp = ha->rsp_q_map[i];
7227 if (rsp && test_bit(i, ha->rsp_qid_map)) {
7228 rsp->options &= ~BIT_0;
7229 ret = qla25xx_init_rsp_que(base_vha, rsp);
7230 if (ret != QLA_SUCCESS)
7231 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
7232 "%s Rsp que: %d init failed.\n",
7235 ql_dbg(ql_dbg_init, base_vha, 0x0100,
7236 "%s Rsp que: %d inited.\n",
7240 for (i = 1; i < ha->max_req_queues; i++) {
7241 req = ha->req_q_map[i];
7242 if (req && test_bit(i, ha->req_qid_map)) {
7243 /* Clear outstanding commands array. */
7244 req->options &= ~BIT_0;
7245 ret = qla25xx_init_req_que(base_vha, req);
7246 if (ret != QLA_SUCCESS)
7247 ql_dbg(ql_dbg_init, base_vha, 0x0101,
7248 "%s Req que: %d init failed.\n",
7251 ql_dbg(ql_dbg_init, base_vha, 0x0102,
7252 "%s Req que: %d inited.\n",
7260 * qla2x00_reset_adapter
7264 * ha = adapter block pointer.
7267 qla2x00_reset_adapter(scsi_qla_host_t *vha)
7269 unsigned long flags = 0;
7270 struct qla_hw_data *ha = vha->hw;
7271 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7273 vha->flags.online = 0;
7274 ha->isp_ops->disable_intrs(ha);
7276 spin_lock_irqsave(&ha->hardware_lock, flags);
7277 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
7278 rd_reg_word(®->hccr); /* PCI Posting. */
7279 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
7280 rd_reg_word(®->hccr); /* PCI Posting. */
7281 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7287 qla24xx_reset_adapter(scsi_qla_host_t *vha)
7289 unsigned long flags = 0;
7290 struct qla_hw_data *ha = vha->hw;
7291 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
7293 if (IS_P3P_TYPE(ha))
7296 vha->flags.online = 0;
7297 ha->isp_ops->disable_intrs(ha);
7299 spin_lock_irqsave(&ha->hardware_lock, flags);
7300 wrt_reg_dword(®->hccr, HCCRX_SET_RISC_RESET);
7301 rd_reg_dword(®->hccr);
7302 wrt_reg_dword(®->hccr, HCCRX_REL_RISC_PAUSE);
7303 rd_reg_dword(®->hccr);
7304 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7306 if (IS_NOPOLLING_TYPE(ha))
7307 ha->isp_ops->enable_intrs(ha);
7312 /* On sparc systems, obtain port and node WWN from firmware
7315 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
7316 struct nvram_24xx *nv)
7319 struct qla_hw_data *ha = vha->hw;
7320 struct pci_dev *pdev = ha->pdev;
7321 struct device_node *dp = pci_device_to_OF_node(pdev);
7325 val = of_get_property(dp, "port-wwn", &len);
7326 if (val && len >= WWN_SIZE)
7327 memcpy(nv->port_name, val, WWN_SIZE);
7329 val = of_get_property(dp, "node-wwn", &len);
7330 if (val && len >= WWN_SIZE)
7331 memcpy(nv->node_name, val, WWN_SIZE);
7336 qla24xx_nvram_config(scsi_qla_host_t *vha)
7339 struct init_cb_24xx *icb;
7340 struct nvram_24xx *nv;
7342 uint8_t *dptr1, *dptr2;
7345 struct qla_hw_data *ha = vha->hw;
7348 icb = (struct init_cb_24xx *)ha->init_cb;
7351 /* Determine NVRAM starting address. */
7352 if (ha->port_no == 0) {
7353 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
7354 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
7356 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
7357 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
7360 ha->nvram_size = sizeof(*nv);
7361 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7363 /* Get VPD data into cache */
7364 ha->vpd = ha->nvram + VPD_OFFSET;
7365 ha->isp_ops->read_nvram(vha, ha->vpd,
7366 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
7368 /* Get NVRAM data into cache and calculate checksum. */
7369 dptr = (__force __le32 *)nv;
7370 ha->isp_ops->read_nvram(vha, dptr, ha->nvram_base, ha->nvram_size);
7371 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7372 chksum += le32_to_cpu(*dptr);
7374 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
7375 "Contents of NVRAM\n");
7376 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
7377 nv, ha->nvram_size);
7379 /* Bad NVRAM data, set defaults parameters. */
7380 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
7381 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
7382 /* Reset NVRAM data. */
7383 ql_log(ql_log_warn, vha, 0x006b,
7384 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
7385 chksum, nv->id, nv->nvram_version);
7386 ql_dump_buffer(ql_dbg_init, vha, 0x006b, nv, sizeof(*nv));
7387 ql_log(ql_log_warn, vha, 0x006c,
7388 "Falling back to functioning (yet invalid -- WWPN) "
7392 * Set default initialization control block.
7394 memset(nv, 0, ha->nvram_size);
7395 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7396 nv->version = cpu_to_le16(ICB_VERSION);
7397 nv->frame_payload_size = cpu_to_le16(2048);
7398 nv->execution_throttle = cpu_to_le16(0xFFFF);
7399 nv->exchange_count = cpu_to_le16(0);
7400 nv->hard_address = cpu_to_le16(124);
7401 nv->port_name[0] = 0x21;
7402 nv->port_name[1] = 0x00 + ha->port_no + 1;
7403 nv->port_name[2] = 0x00;
7404 nv->port_name[3] = 0xe0;
7405 nv->port_name[4] = 0x8b;
7406 nv->port_name[5] = 0x1c;
7407 nv->port_name[6] = 0x55;
7408 nv->port_name[7] = 0x86;
7409 nv->node_name[0] = 0x20;
7410 nv->node_name[1] = 0x00;
7411 nv->node_name[2] = 0x00;
7412 nv->node_name[3] = 0xe0;
7413 nv->node_name[4] = 0x8b;
7414 nv->node_name[5] = 0x1c;
7415 nv->node_name[6] = 0x55;
7416 nv->node_name[7] = 0x86;
7417 qla24xx_nvram_wwn_from_ofw(vha, nv);
7418 nv->login_retry_count = cpu_to_le16(8);
7419 nv->interrupt_delay_timer = cpu_to_le16(0);
7420 nv->login_timeout = cpu_to_le16(0);
7421 nv->firmware_options_1 =
7422 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7423 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7424 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7425 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7426 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7427 nv->efi_parameters = cpu_to_le32(0);
7428 nv->reset_delay = 5;
7429 nv->max_luns_per_target = cpu_to_le16(128);
7430 nv->port_down_retry_count = cpu_to_le16(30);
7431 nv->link_down_timeout = cpu_to_le16(30);
7436 if (qla_tgt_mode_enabled(vha)) {
7437 /* Don't enable full login after initial LIP */
7438 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7439 /* Don't enable LIP full login for initiator */
7440 nv->host_p &= cpu_to_le32(~BIT_10);
7443 qlt_24xx_config_nvram_stage1(vha, nv);
7445 /* Reset Initialization control block */
7446 memset(icb, 0, ha->init_cb_size);
7448 /* Copy 1st segment. */
7449 dptr1 = (uint8_t *)icb;
7450 dptr2 = (uint8_t *)&nv->version;
7451 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7453 *dptr1++ = *dptr2++;
7455 icb->login_retry_count = nv->login_retry_count;
7456 icb->link_down_on_nos = nv->link_down_on_nos;
7458 /* Copy 2nd segment. */
7459 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7460 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7461 cnt = (uint8_t *)&icb->reserved_3 -
7462 (uint8_t *)&icb->interrupt_delay_timer;
7464 *dptr1++ = *dptr2++;
7465 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
7467 * Setup driver NVRAM options.
7469 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7472 qlt_24xx_config_nvram_stage2(vha, icb);
7474 if (nv->host_p & cpu_to_le32(BIT_15)) {
7475 /* Use alternate WWN? */
7476 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7477 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7480 /* Prepare nodename */
7481 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7483 * Firmware will apply the following mask if the nodename was
7486 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7487 icb->node_name[0] &= 0xF0;
7490 /* Set host adapter parameters. */
7491 ha->flags.disable_risc_code_load = 0;
7492 ha->flags.enable_lip_reset = 0;
7493 ha->flags.enable_lip_full_login =
7494 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
7495 ha->flags.enable_target_reset =
7496 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
7497 ha->flags.enable_led_scheme = 0;
7498 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
7500 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7501 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7503 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
7504 sizeof(ha->fw_seriallink_options24));
7506 /* save HBA serial number */
7507 ha->serial0 = icb->port_name[5];
7508 ha->serial1 = icb->port_name[6];
7509 ha->serial2 = icb->port_name[7];
7510 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7511 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7513 icb->execution_throttle = cpu_to_le16(0xFFFF);
7515 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7517 /* Set minimum login_timeout to 4 seconds. */
7518 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7519 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7520 if (le16_to_cpu(nv->login_timeout) < 4)
7521 nv->login_timeout = cpu_to_le16(4);
7522 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7524 /* Set minimum RATOV to 100 tenths of a second. */
7527 ha->loop_reset_delay = nv->reset_delay;
7529 /* Link Down Timeout = 0:
7531 * When Port Down timer expires we will start returning
7532 * I/O's to OS with "DID_NO_CONNECT".
7534 * Link Down Timeout != 0:
7536 * The driver waits for the link to come up after link down
7537 * before returning I/Os to OS with "DID_NO_CONNECT".
7539 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7540 ha->loop_down_abort_time =
7541 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7543 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7544 ha->loop_down_abort_time =
7545 (LOOP_DOWN_TIME - ha->link_down_timeout);
7548 /* Need enough time to try and get the port back. */
7549 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7550 if (qlport_down_retry)
7551 ha->port_down_retry_count = qlport_down_retry;
7553 /* Set login_retry_count */
7554 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7555 if (ha->port_down_retry_count ==
7556 le16_to_cpu(nv->port_down_retry_count) &&
7557 ha->port_down_retry_count > 3)
7558 ha->login_retry_count = ha->port_down_retry_count;
7559 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7560 ha->login_retry_count = ha->port_down_retry_count;
7561 if (ql2xloginretrycount)
7562 ha->login_retry_count = ql2xloginretrycount;
7564 /* N2N: driver will initiate Login instead of FW */
7565 icb->firmware_options_3 |= cpu_to_le32(BIT_8);
7568 if (!vha->flags.init_done) {
7569 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7570 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7571 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7572 le16_to_cpu(icb->interrupt_delay_timer) : 2;
7574 icb->firmware_options_2 &= cpu_to_le32(
7575 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7576 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7577 ha->zio_mode = QLA_ZIO_MODE_6;
7579 ql_log(ql_log_info, vha, 0x006f,
7580 "ZIO mode %d enabled; timer delay (%d us).\n",
7581 ha->zio_mode, ha->zio_timer * 100);
7583 icb->firmware_options_2 |= cpu_to_le32(
7584 (uint32_t)ha->zio_mode);
7585 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7589 ql_log(ql_log_warn, vha, 0x0070,
7590 "NVRAM configuration failed.\n");
7596 qla27xx_print_image(struct scsi_qla_host *vha, char *name,
7597 struct qla27xx_image_status *image_status)
7599 ql_dbg(ql_dbg_init, vha, 0x018b,
7600 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
7602 image_status->image_status_mask,
7603 le16_to_cpu(image_status->generation),
7604 image_status->ver_major,
7605 image_status->ver_minor,
7606 image_status->bitmap,
7607 le32_to_cpu(image_status->checksum),
7608 le32_to_cpu(image_status->signature));
7612 qla28xx_check_aux_image_status_signature(
7613 struct qla27xx_image_status *image_status)
7615 ulong signature = le32_to_cpu(image_status->signature);
7617 return signature != QLA28XX_AUX_IMG_STATUS_SIGN;
7621 qla27xx_check_image_status_signature(struct qla27xx_image_status *image_status)
7623 ulong signature = le32_to_cpu(image_status->signature);
7626 signature != QLA27XX_IMG_STATUS_SIGN &&
7627 signature != QLA28XX_IMG_STATUS_SIGN;
7631 qla27xx_image_status_checksum(struct qla27xx_image_status *image_status)
7633 __le32 *p = (__force __le32 *)image_status;
7634 uint n = sizeof(*image_status) / sizeof(*p);
7638 sum += le32_to_cpup(p);
7644 qla28xx_component_bitmask(struct qla27xx_image_status *aux, uint bitmask)
7646 return aux->bitmap & bitmask ?
7647 QLA27XX_SECONDARY_IMAGE : QLA27XX_PRIMARY_IMAGE;
7651 qla28xx_component_status(
7652 struct active_regions *active_regions, struct qla27xx_image_status *aux)
7654 active_regions->aux.board_config =
7655 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_BOARD_CONFIG);
7657 active_regions->aux.vpd_nvram =
7658 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_VPD_NVRAM);
7660 active_regions->aux.npiv_config_0_1 =
7661 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1);
7663 active_regions->aux.npiv_config_2_3 =
7664 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3);
7668 qla27xx_compare_image_generation(
7669 struct qla27xx_image_status *pri_image_status,
7670 struct qla27xx_image_status *sec_image_status)
7672 /* calculate generation delta as uint16 (this accounts for wrap) */
7674 le16_to_cpu(pri_image_status->generation) -
7675 le16_to_cpu(sec_image_status->generation);
7677 ql_dbg(ql_dbg_init, NULL, 0x0180, "generation delta = %d\n", delta);
7683 qla28xx_get_aux_images(
7684 struct scsi_qla_host *vha, struct active_regions *active_regions)
7686 struct qla_hw_data *ha = vha->hw;
7687 struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
7688 bool valid_pri_image = false, valid_sec_image = false;
7689 bool active_pri_image = false, active_sec_image = false;
7691 if (!ha->flt_region_aux_img_status_pri) {
7692 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
7693 goto check_sec_image;
7696 qla24xx_read_flash_data(vha, (uint32_t *)&pri_aux_image_status,
7697 ha->flt_region_aux_img_status_pri,
7698 sizeof(pri_aux_image_status) >> 2);
7699 qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
7701 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
7702 ql_dbg(ql_dbg_init, vha, 0x018b,
7703 "Primary aux image signature (%#x) not valid\n",
7704 le32_to_cpu(pri_aux_image_status.signature));
7705 goto check_sec_image;
7708 if (qla27xx_image_status_checksum(&pri_aux_image_status)) {
7709 ql_dbg(ql_dbg_init, vha, 0x018c,
7710 "Primary aux image checksum failed\n");
7711 goto check_sec_image;
7714 valid_pri_image = true;
7716 if (pri_aux_image_status.image_status_mask & 1) {
7717 ql_dbg(ql_dbg_init, vha, 0x018d,
7718 "Primary aux image is active\n");
7719 active_pri_image = true;
7723 if (!ha->flt_region_aux_img_status_sec) {
7724 ql_dbg(ql_dbg_init, vha, 0x018a,
7725 "Secondary aux image not addressed\n");
7726 goto check_valid_image;
7729 qla24xx_read_flash_data(vha, (uint32_t *)&sec_aux_image_status,
7730 ha->flt_region_aux_img_status_sec,
7731 sizeof(sec_aux_image_status) >> 2);
7732 qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
7734 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
7735 ql_dbg(ql_dbg_init, vha, 0x018b,
7736 "Secondary aux image signature (%#x) not valid\n",
7737 le32_to_cpu(sec_aux_image_status.signature));
7738 goto check_valid_image;
7741 if (qla27xx_image_status_checksum(&sec_aux_image_status)) {
7742 ql_dbg(ql_dbg_init, vha, 0x018c,
7743 "Secondary aux image checksum failed\n");
7744 goto check_valid_image;
7747 valid_sec_image = true;
7749 if (sec_aux_image_status.image_status_mask & 1) {
7750 ql_dbg(ql_dbg_init, vha, 0x018d,
7751 "Secondary aux image is active\n");
7752 active_sec_image = true;
7756 if (valid_pri_image && active_pri_image &&
7757 valid_sec_image && active_sec_image) {
7758 if (qla27xx_compare_image_generation(&pri_aux_image_status,
7759 &sec_aux_image_status) >= 0) {
7760 qla28xx_component_status(active_regions,
7761 &pri_aux_image_status);
7763 qla28xx_component_status(active_regions,
7764 &sec_aux_image_status);
7766 } else if (valid_pri_image && active_pri_image) {
7767 qla28xx_component_status(active_regions, &pri_aux_image_status);
7768 } else if (valid_sec_image && active_sec_image) {
7769 qla28xx_component_status(active_regions, &sec_aux_image_status);
7772 ql_dbg(ql_dbg_init, vha, 0x018f,
7773 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u\n",
7774 active_regions->aux.board_config,
7775 active_regions->aux.vpd_nvram,
7776 active_regions->aux.npiv_config_0_1,
7777 active_regions->aux.npiv_config_2_3);
7781 qla27xx_get_active_image(struct scsi_qla_host *vha,
7782 struct active_regions *active_regions)
7784 struct qla_hw_data *ha = vha->hw;
7785 struct qla27xx_image_status pri_image_status, sec_image_status;
7786 bool valid_pri_image = false, valid_sec_image = false;
7787 bool active_pri_image = false, active_sec_image = false;
7789 if (!ha->flt_region_img_status_pri) {
7790 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
7791 goto check_sec_image;
7794 if (qla24xx_read_flash_data(vha, (uint32_t *)&pri_image_status,
7795 ha->flt_region_img_status_pri, sizeof(pri_image_status) >> 2) !=
7798 goto check_sec_image;
7800 qla27xx_print_image(vha, "Primary image", &pri_image_status);
7802 if (qla27xx_check_image_status_signature(&pri_image_status)) {
7803 ql_dbg(ql_dbg_init, vha, 0x018b,
7804 "Primary image signature (%#x) not valid\n",
7805 le32_to_cpu(pri_image_status.signature));
7806 goto check_sec_image;
7809 if (qla27xx_image_status_checksum(&pri_image_status)) {
7810 ql_dbg(ql_dbg_init, vha, 0x018c,
7811 "Primary image checksum failed\n");
7812 goto check_sec_image;
7815 valid_pri_image = true;
7817 if (pri_image_status.image_status_mask & 1) {
7818 ql_dbg(ql_dbg_init, vha, 0x018d,
7819 "Primary image is active\n");
7820 active_pri_image = true;
7824 if (!ha->flt_region_img_status_sec) {
7825 ql_dbg(ql_dbg_init, vha, 0x018a, "Secondary image not addressed\n");
7826 goto check_valid_image;
7829 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
7830 ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
7831 qla27xx_print_image(vha, "Secondary image", &sec_image_status);
7833 if (qla27xx_check_image_status_signature(&sec_image_status)) {
7834 ql_dbg(ql_dbg_init, vha, 0x018b,
7835 "Secondary image signature (%#x) not valid\n",
7836 le32_to_cpu(sec_image_status.signature));
7837 goto check_valid_image;
7840 if (qla27xx_image_status_checksum(&sec_image_status)) {
7841 ql_dbg(ql_dbg_init, vha, 0x018c,
7842 "Secondary image checksum failed\n");
7843 goto check_valid_image;
7846 valid_sec_image = true;
7848 if (sec_image_status.image_status_mask & 1) {
7849 ql_dbg(ql_dbg_init, vha, 0x018d,
7850 "Secondary image is active\n");
7851 active_sec_image = true;
7855 if (valid_pri_image && active_pri_image)
7856 active_regions->global = QLA27XX_PRIMARY_IMAGE;
7858 if (valid_sec_image && active_sec_image) {
7859 if (!active_regions->global ||
7860 qla27xx_compare_image_generation(
7861 &pri_image_status, &sec_image_status) < 0) {
7862 active_regions->global = QLA27XX_SECONDARY_IMAGE;
7866 ql_dbg(ql_dbg_init, vha, 0x018f, "active image %s (%u)\n",
7867 active_regions->global == QLA27XX_DEFAULT_IMAGE ?
7868 "default (boot/fw)" :
7869 active_regions->global == QLA27XX_PRIMARY_IMAGE ?
7871 active_regions->global == QLA27XX_SECONDARY_IMAGE ?
7872 "secondary" : "invalid",
7873 active_regions->global);
7876 bool qla24xx_risc_firmware_invalid(uint32_t *dword)
7879 !(dword[4] | dword[5] | dword[6] | dword[7]) ||
7880 !(~dword[4] | ~dword[5] | ~dword[6] | ~dword[7]);
7884 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
7888 uint templates, segments, fragment;
7893 uint32_t risc_addr, risc_size, risc_attr = 0;
7894 struct qla_hw_data *ha = vha->hw;
7895 struct req_que *req = ha->req_q_map[0];
7896 struct fwdt *fwdt = ha->fwdt;
7898 ql_dbg(ql_dbg_init, vha, 0x008b,
7899 "FW: Loading firmware from flash (%x).\n", faddr);
7901 dcode = (uint32_t *)req->ring;
7902 qla24xx_read_flash_data(vha, dcode, faddr, 8);
7903 if (qla24xx_risc_firmware_invalid(dcode)) {
7904 ql_log(ql_log_fatal, vha, 0x008c,
7905 "Unable to verify the integrity of flash firmware "
7907 ql_log(ql_log_fatal, vha, 0x008d,
7908 "Firmware data: %08x %08x %08x %08x.\n",
7909 dcode[0], dcode[1], dcode[2], dcode[3]);
7911 return QLA_FUNCTION_FAILED;
7914 dcode = (uint32_t *)req->ring;
7916 segments = FA_RISC_CODE_SEGMENTS;
7917 for (j = 0; j < segments; j++) {
7918 ql_dbg(ql_dbg_init, vha, 0x008d,
7919 "-> Loading segment %u...\n", j);
7920 qla24xx_read_flash_data(vha, dcode, faddr, 10);
7921 risc_addr = be32_to_cpu((__force __be32)dcode[2]);
7922 risc_size = be32_to_cpu((__force __be32)dcode[3]);
7924 *srisc_addr = risc_addr;
7925 risc_attr = be32_to_cpu((__force __be32)dcode[9]);
7928 dlen = ha->fw_transfer_size >> 2;
7929 for (fragment = 0; risc_size; fragment++) {
7930 if (dlen > risc_size)
7933 ql_dbg(ql_dbg_init, vha, 0x008e,
7934 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
7935 fragment, risc_addr, faddr, dlen);
7936 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
7937 for (i = 0; i < dlen; i++)
7938 dcode[i] = swab32(dcode[i]);
7940 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7942 ql_log(ql_log_fatal, vha, 0x008f,
7943 "-> Failed load firmware fragment %u.\n",
7945 return QLA_FUNCTION_FAILED;
7954 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
7957 templates = (risc_attr & BIT_9) ? 2 : 1;
7958 ql_dbg(ql_dbg_init, vha, 0x0160, "-> templates = %u\n", templates);
7959 for (j = 0; j < templates; j++, fwdt++) {
7960 vfree(fwdt->template);
7961 fwdt->template = NULL;
7964 dcode = (uint32_t *)req->ring;
7965 qla24xx_read_flash_data(vha, dcode, faddr, 7);
7966 risc_size = be32_to_cpu((__force __be32)dcode[2]);
7967 ql_dbg(ql_dbg_init, vha, 0x0161,
7968 "-> fwdt%u template array at %#x (%#x dwords)\n",
7969 j, faddr, risc_size);
7970 if (!risc_size || !~risc_size) {
7971 ql_dbg(ql_dbg_init, vha, 0x0162,
7972 "-> fwdt%u failed to read array\n", j);
7976 /* skip header and ignore checksum */
7980 ql_dbg(ql_dbg_init, vha, 0x0163,
7981 "-> fwdt%u template allocate template %#x words...\n",
7983 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
7984 if (!fwdt->template) {
7985 ql_log(ql_log_warn, vha, 0x0164,
7986 "-> fwdt%u failed allocate template.\n", j);
7990 dcode = fwdt->template;
7991 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
7993 if (!qla27xx_fwdt_template_valid(dcode)) {
7994 ql_log(ql_log_warn, vha, 0x0165,
7995 "-> fwdt%u failed template validate\n", j);
7999 dlen = qla27xx_fwdt_template_size(dcode);
8000 ql_dbg(ql_dbg_init, vha, 0x0166,
8001 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8002 j, dlen, dlen / sizeof(*dcode));
8003 if (dlen > risc_size * sizeof(*dcode)) {
8004 ql_log(ql_log_warn, vha, 0x0167,
8005 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8006 j, dlen - risc_size * sizeof(*dcode));
8010 fwdt->length = dlen;
8011 ql_dbg(ql_dbg_init, vha, 0x0168,
8012 "-> fwdt%u loaded template ok\n", j);
8014 faddr += risc_size + 1;
8020 vfree(fwdt->template);
8021 fwdt->template = NULL;
8027 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
8030 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8036 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
8037 struct fw_blob *blob;
8038 struct qla_hw_data *ha = vha->hw;
8039 struct req_que *req = ha->req_q_map[0];
8041 /* Load firmware blob. */
8042 blob = qla2x00_request_firmware(vha);
8044 ql_log(ql_log_info, vha, 0x0083,
8045 "Firmware image unavailable.\n");
8046 ql_log(ql_log_info, vha, 0x0084,
8047 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
8048 return QLA_FUNCTION_FAILED;
8053 wcode = (uint16_t *)req->ring;
8055 fwcode = (__force __be16 *)blob->fw->data;
8058 /* Validate firmware image by checking version. */
8059 if (blob->fw->size < 8 * sizeof(uint16_t)) {
8060 ql_log(ql_log_fatal, vha, 0x0085,
8061 "Unable to verify integrity of firmware image (%zd).\n",
8063 goto fail_fw_integrity;
8065 for (i = 0; i < 4; i++)
8066 wcode[i] = be16_to_cpu(fwcode[i + 4]);
8067 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
8068 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
8069 wcode[2] == 0 && wcode[3] == 0)) {
8070 ql_log(ql_log_fatal, vha, 0x0086,
8071 "Unable to verify integrity of firmware image.\n");
8072 ql_log(ql_log_fatal, vha, 0x0087,
8073 "Firmware data: %04x %04x %04x %04x.\n",
8074 wcode[0], wcode[1], wcode[2], wcode[3]);
8075 goto fail_fw_integrity;
8079 while (*seg && rval == QLA_SUCCESS) {
8081 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
8082 risc_size = be16_to_cpu(fwcode[3]);
8084 /* Validate firmware image size. */
8085 fwclen += risc_size * sizeof(uint16_t);
8086 if (blob->fw->size < fwclen) {
8087 ql_log(ql_log_fatal, vha, 0x0088,
8088 "Unable to verify integrity of firmware image "
8089 "(%zd).\n", blob->fw->size);
8090 goto fail_fw_integrity;
8094 while (risc_size > 0 && rval == QLA_SUCCESS) {
8095 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
8096 if (wlen > risc_size)
8098 ql_dbg(ql_dbg_init, vha, 0x0089,
8099 "Loading risc segment@ risc addr %x number of "
8100 "words 0x%x.\n", risc_addr, wlen);
8102 for (i = 0; i < wlen; i++)
8103 wcode[i] = swab16((__force u32)fwcode[i]);
8105 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
8108 ql_log(ql_log_fatal, vha, 0x008a,
8109 "Failed to load segment %d of firmware.\n",
8126 return QLA_FUNCTION_FAILED;
8130 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8133 uint templates, segments, fragment;
8136 uint32_t risc_addr, risc_size, risc_attr = 0;
8139 struct fw_blob *blob;
8141 struct qla_hw_data *ha = vha->hw;
8142 struct req_que *req = ha->req_q_map[0];
8143 struct fwdt *fwdt = ha->fwdt;
8145 ql_dbg(ql_dbg_init, vha, 0x0090,
8146 "-> FW: Loading via request-firmware.\n");
8148 blob = qla2x00_request_firmware(vha);
8150 ql_log(ql_log_warn, vha, 0x0092,
8151 "-> Firmware file not found.\n");
8153 return QLA_FUNCTION_FAILED;
8156 fwcode = (__force __be32 *)blob->fw->data;
8157 dcode = (__force uint32_t *)fwcode;
8158 if (qla24xx_risc_firmware_invalid(dcode)) {
8159 ql_log(ql_log_fatal, vha, 0x0093,
8160 "Unable to verify integrity of firmware image (%zd).\n",
8162 ql_log(ql_log_fatal, vha, 0x0095,
8163 "Firmware data: %08x %08x %08x %08x.\n",
8164 dcode[0], dcode[1], dcode[2], dcode[3]);
8165 return QLA_FUNCTION_FAILED;
8168 dcode = (uint32_t *)req->ring;
8170 segments = FA_RISC_CODE_SEGMENTS;
8171 for (j = 0; j < segments; j++) {
8172 ql_dbg(ql_dbg_init, vha, 0x0096,
8173 "-> Loading segment %u...\n", j);
8174 risc_addr = be32_to_cpu(fwcode[2]);
8175 risc_size = be32_to_cpu(fwcode[3]);
8178 *srisc_addr = risc_addr;
8179 risc_attr = be32_to_cpu(fwcode[9]);
8182 dlen = ha->fw_transfer_size >> 2;
8183 for (fragment = 0; risc_size; fragment++) {
8184 if (dlen > risc_size)
8187 ql_dbg(ql_dbg_init, vha, 0x0097,
8188 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
8189 fragment, risc_addr,
8190 (uint32_t)(fwcode - (typeof(fwcode))blob->fw->data),
8193 for (i = 0; i < dlen; i++)
8194 dcode[i] = swab32((__force u32)fwcode[i]);
8196 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
8198 ql_log(ql_log_fatal, vha, 0x0098,
8199 "-> Failed load firmware fragment %u.\n",
8201 return QLA_FUNCTION_FAILED;
8210 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8213 templates = (risc_attr & BIT_9) ? 2 : 1;
8214 ql_dbg(ql_dbg_init, vha, 0x0170, "-> templates = %u\n", templates);
8215 for (j = 0; j < templates; j++, fwdt++) {
8216 vfree(fwdt->template);
8217 fwdt->template = NULL;
8220 risc_size = be32_to_cpu(fwcode[2]);
8221 ql_dbg(ql_dbg_init, vha, 0x0171,
8222 "-> fwdt%u template array at %#x (%#x dwords)\n",
8223 j, (uint32_t)((void *)fwcode - (void *)blob->fw->data),
8225 if (!risc_size || !~risc_size) {
8226 ql_dbg(ql_dbg_init, vha, 0x0172,
8227 "-> fwdt%u failed to read array\n", j);
8231 /* skip header and ignore checksum */
8235 ql_dbg(ql_dbg_init, vha, 0x0173,
8236 "-> fwdt%u template allocate template %#x words...\n",
8238 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
8239 if (!fwdt->template) {
8240 ql_log(ql_log_warn, vha, 0x0174,
8241 "-> fwdt%u failed allocate template.\n", j);
8245 dcode = fwdt->template;
8246 for (i = 0; i < risc_size; i++)
8247 dcode[i] = (__force u32)fwcode[i];
8249 if (!qla27xx_fwdt_template_valid(dcode)) {
8250 ql_log(ql_log_warn, vha, 0x0175,
8251 "-> fwdt%u failed template validate\n", j);
8255 dlen = qla27xx_fwdt_template_size(dcode);
8256 ql_dbg(ql_dbg_init, vha, 0x0176,
8257 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8258 j, dlen, dlen / sizeof(*dcode));
8259 if (dlen > risc_size * sizeof(*dcode)) {
8260 ql_log(ql_log_warn, vha, 0x0177,
8261 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8262 j, dlen - risc_size * sizeof(*dcode));
8266 fwdt->length = dlen;
8267 ql_dbg(ql_dbg_init, vha, 0x0178,
8268 "-> fwdt%u loaded template ok\n", j);
8270 fwcode += risc_size + 1;
8276 vfree(fwdt->template);
8277 fwdt->template = NULL;
8284 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8288 if (ql2xfwloadbin == 1)
8289 return qla81xx_load_risc(vha, srisc_addr);
8293 * 1) Firmware via request-firmware interface (.bin file).
8294 * 2) Firmware residing in flash.
8296 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8297 if (rval == QLA_SUCCESS)
8300 return qla24xx_load_risc_flash(vha, srisc_addr,
8301 vha->hw->flt_region_fw);
8305 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8308 struct qla_hw_data *ha = vha->hw;
8309 struct active_regions active_regions = { };
8311 if (ql2xfwloadbin == 2)
8314 /* FW Load priority:
8315 * 1) Firmware residing in flash.
8316 * 2) Firmware via request-firmware interface (.bin file).
8317 * 3) Golden-Firmware residing in flash -- (limited operation).
8320 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8321 goto try_primary_fw;
8323 qla27xx_get_active_image(vha, &active_regions);
8325 if (active_regions.global != QLA27XX_SECONDARY_IMAGE)
8326 goto try_primary_fw;
8328 ql_dbg(ql_dbg_init, vha, 0x008b,
8329 "Loading secondary firmware image.\n");
8330 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw_sec);
8335 ql_dbg(ql_dbg_init, vha, 0x008b,
8336 "Loading primary firmware image.\n");
8337 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
8342 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8343 if (!rval || !ha->flt_region_gold_fw)
8346 ql_log(ql_log_info, vha, 0x0099,
8347 "Attempting to fallback to golden firmware.\n");
8348 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
8352 ql_log(ql_log_info, vha, 0x009a, "Need firmware flash update.\n");
8353 ha->flags.running_gold_fw = 1;
8358 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
8361 struct qla_hw_data *ha = vha->hw;
8363 if (ha->flags.pci_channel_io_perm_failure)
8365 if (!IS_FWI2_CAPABLE(ha))
8367 if (!ha->fw_major_version)
8369 if (!ha->flags.fw_started)
8372 ret = qla2x00_stop_firmware(vha);
8373 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
8374 ret != QLA_INVALID_COMMAND && retries ; retries--) {
8375 ha->isp_ops->reset_chip(vha);
8376 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
8378 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
8380 ql_log(ql_log_info, vha, 0x8015,
8381 "Attempting retry of stop-firmware command.\n");
8382 ret = qla2x00_stop_firmware(vha);
8386 ha->flags.fw_init_done = 0;
8390 qla24xx_configure_vhba(scsi_qla_host_t *vha)
8392 int rval = QLA_SUCCESS;
8394 uint16_t mb[MAILBOX_REGISTER_COUNT];
8395 struct qla_hw_data *ha = vha->hw;
8396 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
8401 rval = qla2x00_fw_ready(base_vha);
8403 if (rval == QLA_SUCCESS) {
8404 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8405 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8408 vha->flags.management_server_logged_in = 0;
8410 /* Login to SNS first */
8411 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
8413 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
8414 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
8415 ql_dbg(ql_dbg_init, vha, 0x0120,
8416 "Failed SNS login: loop_id=%x, rval2=%d\n",
8419 ql_dbg(ql_dbg_init, vha, 0x0103,
8420 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
8421 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
8422 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
8423 return (QLA_FUNCTION_FAILED);
8426 atomic_set(&vha->loop_down_timer, 0);
8427 atomic_set(&vha->loop_state, LOOP_UP);
8428 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8429 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
8430 rval = qla2x00_loop_resync(base_vha);
8435 /* 84XX Support **************************************************************/
8437 static LIST_HEAD(qla_cs84xx_list);
8438 static DEFINE_MUTEX(qla_cs84xx_mutex);
8440 static struct qla_chip_state_84xx *
8441 qla84xx_get_chip(struct scsi_qla_host *vha)
8443 struct qla_chip_state_84xx *cs84xx;
8444 struct qla_hw_data *ha = vha->hw;
8446 mutex_lock(&qla_cs84xx_mutex);
8448 /* Find any shared 84xx chip. */
8449 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
8450 if (cs84xx->bus == ha->pdev->bus) {
8451 kref_get(&cs84xx->kref);
8456 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
8460 kref_init(&cs84xx->kref);
8461 spin_lock_init(&cs84xx->access_lock);
8462 mutex_init(&cs84xx->fw_update_mutex);
8463 cs84xx->bus = ha->pdev->bus;
8465 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
8467 mutex_unlock(&qla_cs84xx_mutex);
8472 __qla84xx_chip_release(struct kref *kref)
8474 struct qla_chip_state_84xx *cs84xx =
8475 container_of(kref, struct qla_chip_state_84xx, kref);
8477 mutex_lock(&qla_cs84xx_mutex);
8478 list_del(&cs84xx->list);
8479 mutex_unlock(&qla_cs84xx_mutex);
8484 qla84xx_put_chip(struct scsi_qla_host *vha)
8486 struct qla_hw_data *ha = vha->hw;
8489 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
8493 qla84xx_init_chip(scsi_qla_host_t *vha)
8497 struct qla_hw_data *ha = vha->hw;
8499 mutex_lock(&ha->cs84xx->fw_update_mutex);
8501 rval = qla84xx_verify_chip(vha, status);
8503 mutex_unlock(&ha->cs84xx->fw_update_mutex);
8505 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED :
8509 /* 81XX Support **************************************************************/
8512 qla81xx_nvram_config(scsi_qla_host_t *vha)
8515 struct init_cb_81xx *icb;
8516 struct nvram_81xx *nv;
8518 uint8_t *dptr1, *dptr2;
8521 struct qla_hw_data *ha = vha->hw;
8523 struct active_regions active_regions = { };
8526 icb = (struct init_cb_81xx *)ha->init_cb;
8529 /* Determine NVRAM starting address. */
8530 ha->nvram_size = sizeof(*nv);
8531 ha->vpd_size = FA_NVRAM_VPD_SIZE;
8532 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
8533 ha->vpd_size = FA_VPD_SIZE_82XX;
8535 if (IS_QLA28XX(ha) || IS_QLA27XX(ha))
8536 qla28xx_get_aux_images(vha, &active_regions);
8538 /* Get VPD data into cache */
8539 ha->vpd = ha->nvram + VPD_OFFSET;
8541 faddr = ha->flt_region_vpd;
8542 if (IS_QLA28XX(ha)) {
8543 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8544 faddr = ha->flt_region_vpd_sec;
8545 ql_dbg(ql_dbg_init, vha, 0x0110,
8546 "Loading %s nvram image.\n",
8547 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8548 "primary" : "secondary");
8550 ha->isp_ops->read_optrom(vha, ha->vpd, faddr << 2, ha->vpd_size);
8552 /* Get NVRAM data into cache and calculate checksum. */
8553 faddr = ha->flt_region_nvram;
8554 if (IS_QLA28XX(ha)) {
8555 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8556 faddr = ha->flt_region_nvram_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");
8562 ha->isp_ops->read_optrom(vha, ha->nvram, faddr << 2, ha->nvram_size);
8564 dptr = (__force __le32 *)nv;
8565 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
8566 chksum += le32_to_cpu(*dptr);
8568 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
8569 "Contents of NVRAM:\n");
8570 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
8571 nv, ha->nvram_size);
8573 /* Bad NVRAM data, set defaults parameters. */
8574 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
8575 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
8576 /* Reset NVRAM data. */
8577 ql_log(ql_log_info, vha, 0x0073,
8578 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
8579 chksum, nv->id, le16_to_cpu(nv->nvram_version));
8580 ql_dump_buffer(ql_dbg_init, vha, 0x0073, nv, sizeof(*nv));
8581 ql_log(ql_log_info, vha, 0x0074,
8582 "Falling back to functioning (yet invalid -- WWPN) "
8586 * Set default initialization control block.
8588 memset(nv, 0, ha->nvram_size);
8589 nv->nvram_version = cpu_to_le16(ICB_VERSION);
8590 nv->version = cpu_to_le16(ICB_VERSION);
8591 nv->frame_payload_size = cpu_to_le16(2048);
8592 nv->execution_throttle = cpu_to_le16(0xFFFF);
8593 nv->exchange_count = cpu_to_le16(0);
8594 nv->port_name[0] = 0x21;
8595 nv->port_name[1] = 0x00 + ha->port_no + 1;
8596 nv->port_name[2] = 0x00;
8597 nv->port_name[3] = 0xe0;
8598 nv->port_name[4] = 0x8b;
8599 nv->port_name[5] = 0x1c;
8600 nv->port_name[6] = 0x55;
8601 nv->port_name[7] = 0x86;
8602 nv->node_name[0] = 0x20;
8603 nv->node_name[1] = 0x00;
8604 nv->node_name[2] = 0x00;
8605 nv->node_name[3] = 0xe0;
8606 nv->node_name[4] = 0x8b;
8607 nv->node_name[5] = 0x1c;
8608 nv->node_name[6] = 0x55;
8609 nv->node_name[7] = 0x86;
8610 nv->login_retry_count = cpu_to_le16(8);
8611 nv->interrupt_delay_timer = cpu_to_le16(0);
8612 nv->login_timeout = cpu_to_le16(0);
8613 nv->firmware_options_1 =
8614 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
8615 nv->firmware_options_2 = cpu_to_le32(2 << 4);
8616 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
8617 nv->firmware_options_3 = cpu_to_le32(2 << 13);
8618 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
8619 nv->efi_parameters = cpu_to_le32(0);
8620 nv->reset_delay = 5;
8621 nv->max_luns_per_target = cpu_to_le16(128);
8622 nv->port_down_retry_count = cpu_to_le16(30);
8623 nv->link_down_timeout = cpu_to_le16(180);
8624 nv->enode_mac[0] = 0x00;
8625 nv->enode_mac[1] = 0xC0;
8626 nv->enode_mac[2] = 0xDD;
8627 nv->enode_mac[3] = 0x04;
8628 nv->enode_mac[4] = 0x05;
8629 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
8634 if (IS_T10_PI_CAPABLE(ha))
8635 nv->frame_payload_size &= cpu_to_le16(~7);
8637 qlt_81xx_config_nvram_stage1(vha, nv);
8639 /* Reset Initialization control block */
8640 memset(icb, 0, ha->init_cb_size);
8642 /* Copy 1st segment. */
8643 dptr1 = (uint8_t *)icb;
8644 dptr2 = (uint8_t *)&nv->version;
8645 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
8647 *dptr1++ = *dptr2++;
8649 icb->login_retry_count = nv->login_retry_count;
8651 /* Copy 2nd segment. */
8652 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
8653 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
8654 cnt = (uint8_t *)&icb->reserved_5 -
8655 (uint8_t *)&icb->interrupt_delay_timer;
8657 *dptr1++ = *dptr2++;
8659 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
8660 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8661 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
8662 icb->enode_mac[0] = 0x00;
8663 icb->enode_mac[1] = 0xC0;
8664 icb->enode_mac[2] = 0xDD;
8665 icb->enode_mac[3] = 0x04;
8666 icb->enode_mac[4] = 0x05;
8667 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
8670 /* Use extended-initialization control block. */
8671 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
8672 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
8674 * Setup driver NVRAM options.
8676 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
8679 qlt_81xx_config_nvram_stage2(vha, icb);
8681 /* Use alternate WWN? */
8682 if (nv->host_p & cpu_to_le32(BIT_15)) {
8683 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
8684 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
8687 /* Prepare nodename */
8688 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
8690 * Firmware will apply the following mask if the nodename was
8693 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
8694 icb->node_name[0] &= 0xF0;
8697 if (IS_QLA28XX(ha) || IS_QLA27XX(ha)) {
8698 if ((nv->enhanced_features & BIT_7) == 0)
8699 ha->flags.scm_supported_a = 1;
8702 /* Set host adapter parameters. */
8703 ha->flags.disable_risc_code_load = 0;
8704 ha->flags.enable_lip_reset = 0;
8705 ha->flags.enable_lip_full_login =
8706 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
8707 ha->flags.enable_target_reset =
8708 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
8709 ha->flags.enable_led_scheme = 0;
8710 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
8712 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
8713 (BIT_6 | BIT_5 | BIT_4)) >> 4;
8715 /* save HBA serial number */
8716 ha->serial0 = icb->port_name[5];
8717 ha->serial1 = icb->port_name[6];
8718 ha->serial2 = icb->port_name[7];
8719 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
8720 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
8722 icb->execution_throttle = cpu_to_le16(0xFFFF);
8724 ha->retry_count = le16_to_cpu(nv->login_retry_count);
8726 /* Set minimum login_timeout to 4 seconds. */
8727 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
8728 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
8729 if (le16_to_cpu(nv->login_timeout) < 4)
8730 nv->login_timeout = cpu_to_le16(4);
8731 ha->login_timeout = le16_to_cpu(nv->login_timeout);
8733 /* Set minimum RATOV to 100 tenths of a second. */
8736 ha->loop_reset_delay = nv->reset_delay;
8738 /* Link Down Timeout = 0:
8740 * When Port Down timer expires we will start returning
8741 * I/O's to OS with "DID_NO_CONNECT".
8743 * Link Down Timeout != 0:
8745 * The driver waits for the link to come up after link down
8746 * before returning I/Os to OS with "DID_NO_CONNECT".
8748 if (le16_to_cpu(nv->link_down_timeout) == 0) {
8749 ha->loop_down_abort_time =
8750 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
8752 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
8753 ha->loop_down_abort_time =
8754 (LOOP_DOWN_TIME - ha->link_down_timeout);
8757 /* Need enough time to try and get the port back. */
8758 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8759 if (qlport_down_retry)
8760 ha->port_down_retry_count = qlport_down_retry;
8762 /* Set login_retry_count */
8763 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8764 if (ha->port_down_retry_count ==
8765 le16_to_cpu(nv->port_down_retry_count) &&
8766 ha->port_down_retry_count > 3)
8767 ha->login_retry_count = ha->port_down_retry_count;
8768 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8769 ha->login_retry_count = ha->port_down_retry_count;
8770 if (ql2xloginretrycount)
8771 ha->login_retry_count = ql2xloginretrycount;
8773 /* if not running MSI-X we need handshaking on interrupts */
8774 if (!vha->hw->flags.msix_enabled &&
8775 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)))
8776 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
8779 if (!vha->flags.init_done) {
8780 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8781 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8782 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8783 le16_to_cpu(icb->interrupt_delay_timer) : 2;
8785 icb->firmware_options_2 &= cpu_to_le32(
8786 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8787 vha->flags.process_response_queue = 0;
8788 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8789 ha->zio_mode = QLA_ZIO_MODE_6;
8791 ql_log(ql_log_info, vha, 0x0075,
8792 "ZIO mode %d enabled; timer delay (%d us).\n",
8794 ha->zio_timer * 100);
8796 icb->firmware_options_2 |= cpu_to_le32(
8797 (uint32_t)ha->zio_mode);
8798 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8799 vha->flags.process_response_queue = 1;
8802 /* enable RIDA Format2 */
8803 icb->firmware_options_3 |= cpu_to_le32(BIT_0);
8805 /* N2N: driver will initiate Login instead of FW */
8806 icb->firmware_options_3 |= cpu_to_le32(BIT_8);
8808 /* Determine NVMe/FCP priority for target ports */
8809 ha->fc4_type_priority = qla2xxx_get_fc4_priority(vha);
8812 ql_log(ql_log_warn, vha, 0x0076,
8813 "NVRAM configuration failed.\n");
8819 qla82xx_restart_isp(scsi_qla_host_t *vha)
8822 struct qla_hw_data *ha = vha->hw;
8823 struct scsi_qla_host *vp;
8824 unsigned long flags;
8826 status = qla2x00_init_rings(vha);
8828 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8829 ha->flags.chip_reset_done = 1;
8831 status = qla2x00_fw_ready(vha);
8833 /* Issue a marker after FW becomes ready. */
8834 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8835 vha->flags.online = 1;
8836 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8839 /* if no cable then assume it's good */
8840 if ((vha->device_flags & DFLG_NO_CABLE))
8845 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8847 if (!atomic_read(&vha->loop_down_timer)) {
8849 * Issue marker command only when we are going
8850 * to start the I/O .
8852 vha->marker_needed = 1;
8855 ha->isp_ops->enable_intrs(ha);
8857 ha->isp_abort_cnt = 0;
8858 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
8860 /* Update the firmware version */
8861 status = qla82xx_check_md_needed(vha);
8864 ha->flags.fce_enabled = 1;
8866 fce_calc_size(ha->fce_bufs));
8867 rval = qla2x00_enable_fce_trace(vha,
8868 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
8871 ql_log(ql_log_warn, vha, 0x8001,
8872 "Unable to reinitialize FCE (%d).\n",
8874 ha->flags.fce_enabled = 0;
8879 memset(ha->eft, 0, EFT_SIZE);
8880 rval = qla2x00_enable_eft_trace(vha,
8881 ha->eft_dma, EFT_NUM_BUFFERS);
8883 ql_log(ql_log_warn, vha, 0x8010,
8884 "Unable to reinitialize EFT (%d).\n",
8891 ql_dbg(ql_dbg_taskm, vha, 0x8011,
8892 "qla82xx_restart_isp succeeded.\n");
8894 spin_lock_irqsave(&ha->vport_slock, flags);
8895 list_for_each_entry(vp, &ha->vp_list, list) {
8897 atomic_inc(&vp->vref_count);
8898 spin_unlock_irqrestore(&ha->vport_slock, flags);
8900 qla2x00_vp_abort_isp(vp);
8902 spin_lock_irqsave(&ha->vport_slock, flags);
8903 atomic_dec(&vp->vref_count);
8906 spin_unlock_irqrestore(&ha->vport_slock, flags);
8909 ql_log(ql_log_warn, vha, 0x8016,
8910 "qla82xx_restart_isp **** FAILED ****.\n");
8917 * qla24xx_get_fcp_prio
8918 * Gets the fcp cmd priority value for the logged in port.
8919 * Looks for a match of the port descriptors within
8920 * each of the fcp prio config entries. If a match is found,
8921 * the tag (priority) value is returned.
8924 * vha = scsi host structure pointer.
8925 * fcport = port structure pointer.
8928 * non-zero (if found)
8935 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8938 uint8_t pid_match, wwn_match;
8940 uint32_t pid1, pid2;
8941 uint64_t wwn1, wwn2;
8942 struct qla_fcp_prio_entry *pri_entry;
8943 struct qla_hw_data *ha = vha->hw;
8945 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
8949 entries = ha->fcp_prio_cfg->num_entries;
8950 pri_entry = &ha->fcp_prio_cfg->entry[0];
8952 for (i = 0; i < entries; i++) {
8953 pid_match = wwn_match = 0;
8955 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
8960 /* check source pid for a match */
8961 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
8962 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
8963 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
8964 if (pid1 == INVALID_PORT_ID)
8966 else if (pid1 == pid2)
8970 /* check destination pid for a match */
8971 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
8972 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
8973 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
8974 if (pid1 == INVALID_PORT_ID)
8976 else if (pid1 == pid2)
8980 /* check source WWN for a match */
8981 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
8982 wwn1 = wwn_to_u64(vha->port_name);
8983 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
8984 if (wwn2 == (uint64_t)-1)
8986 else if (wwn1 == wwn2)
8990 /* check destination WWN for a match */
8991 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
8992 wwn1 = wwn_to_u64(fcport->port_name);
8993 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
8994 if (wwn2 == (uint64_t)-1)
8996 else if (wwn1 == wwn2)
9000 if (pid_match == 2 || wwn_match == 2) {
9001 /* Found a matching entry */
9002 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
9003 priority = pri_entry->tag;
9014 * qla24xx_update_fcport_fcp_prio
9015 * Activates fcp priority for the logged in fc port
9018 * vha = scsi host structure pointer.
9019 * fcp = port structure pointer.
9022 * QLA_SUCCESS or QLA_FUNCTION_FAILED
9028 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
9034 if (fcport->port_type != FCT_TARGET ||
9035 fcport->loop_id == FC_NO_LOOP_ID)
9036 return QLA_FUNCTION_FAILED;
9038 priority = qla24xx_get_fcp_prio(vha, fcport);
9040 return QLA_FUNCTION_FAILED;
9042 if (IS_P3P_TYPE(vha->hw)) {
9043 fcport->fcp_prio = priority & 0xf;
9047 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
9048 if (ret == QLA_SUCCESS) {
9049 if (fcport->fcp_prio != priority)
9050 ql_dbg(ql_dbg_user, vha, 0x709e,
9051 "Updated FCP_CMND priority - value=%d loop_id=%d "
9052 "port_id=%02x%02x%02x.\n", priority,
9053 fcport->loop_id, fcport->d_id.b.domain,
9054 fcport->d_id.b.area, fcport->d_id.b.al_pa);
9055 fcport->fcp_prio = priority & 0xf;
9057 ql_dbg(ql_dbg_user, vha, 0x704f,
9058 "Unable to update FCP_CMND priority - ret=0x%x for "
9059 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
9060 fcport->d_id.b.domain, fcport->d_id.b.area,
9061 fcport->d_id.b.al_pa);
9066 * qla24xx_update_all_fcp_prio
9067 * Activates fcp priority for all the logged in ports
9070 * ha = adapter block pointer.
9073 * QLA_SUCCESS or QLA_FUNCTION_FAILED
9079 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
9084 ret = QLA_FUNCTION_FAILED;
9085 /* We need to set priority for all logged in ports */
9086 list_for_each_entry(fcport, &vha->vp_fcports, list)
9087 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
9092 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
9093 int vp_idx, bool startqp)
9098 struct qla_hw_data *ha = vha->hw;
9099 uint16_t qpair_id = 0;
9100 struct qla_qpair *qpair = NULL;
9101 struct qla_msix_entry *msix;
9103 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
9104 ql_log(ql_log_warn, vha, 0x00181,
9105 "FW/Driver is not multi-queue capable.\n");
9109 if (ql2xmqsupport || ql2xnvmeenable) {
9110 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
9111 if (qpair == NULL) {
9112 ql_log(ql_log_warn, vha, 0x0182,
9113 "Failed to allocate memory for queue pair.\n");
9117 qpair->hw = vha->hw;
9119 qpair->qp_lock_ptr = &qpair->qp_lock;
9120 spin_lock_init(&qpair->qp_lock);
9121 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
9123 /* Assign available que pair id */
9124 mutex_lock(&ha->mq_lock);
9125 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
9126 if (ha->num_qpairs >= ha->max_qpairs) {
9127 mutex_unlock(&ha->mq_lock);
9128 ql_log(ql_log_warn, vha, 0x0183,
9129 "No resources to create additional q pair.\n");
9133 set_bit(qpair_id, ha->qpair_qid_map);
9134 ha->queue_pair_map[qpair_id] = qpair;
9135 qpair->id = qpair_id;
9136 qpair->vp_idx = vp_idx;
9137 qpair->fw_started = ha->flags.fw_started;
9138 INIT_LIST_HEAD(&qpair->hints_list);
9139 qpair->chip_reset = ha->base_qpair->chip_reset;
9140 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
9141 qpair->enable_explicit_conf =
9142 ha->base_qpair->enable_explicit_conf;
9144 for (i = 0; i < ha->msix_count; i++) {
9145 msix = &ha->msix_entries[i];
9149 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
9150 "Vector %x selected for qpair\n", msix->vector);
9154 ql_log(ql_log_warn, vha, 0x0184,
9155 "Out of MSI-X vectors!.\n");
9159 qpair->msix->in_use = 1;
9160 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
9161 qpair->pdev = ha->pdev;
9162 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
9163 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
9165 mutex_unlock(&ha->mq_lock);
9167 /* Create response queue first */
9168 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
9170 ql_log(ql_log_warn, vha, 0x0185,
9171 "Failed to create response queue.\n");
9175 qpair->rsp = ha->rsp_q_map[rsp_id];
9177 /* Create request queue */
9178 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
9181 ql_log(ql_log_warn, vha, 0x0186,
9182 "Failed to create request queue.\n");
9186 qpair->req = ha->req_q_map[req_id];
9187 qpair->rsp->req = qpair->req;
9188 qpair->rsp->qpair = qpair;
9189 /* init qpair to this cpu. Will adjust at run time. */
9190 qla_cpu_update(qpair, smp_processor_id());
9192 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
9193 if (ha->fw_attributes & BIT_4)
9194 qpair->difdix_supported = 1;
9197 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
9198 if (!qpair->srb_mempool) {
9199 ql_log(ql_log_warn, vha, 0xd036,
9200 "Failed to create srb mempool for qpair %d\n",
9205 /* Mark as online */
9208 if (!vha->flags.qpairs_available)
9209 vha->flags.qpairs_available = 1;
9211 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
9212 "Request/Response queue pair created, id %d\n",
9214 ql_dbg(ql_dbg_init, vha, 0x0187,
9215 "Request/Response queue pair created, id %d\n",
9222 qla25xx_delete_rsp_que(vha, qpair->rsp);
9224 mutex_lock(&ha->mq_lock);
9225 qpair->msix->in_use = 0;
9226 list_del(&qpair->qp_list_elem);
9227 if (list_empty(&vha->qp_list))
9228 vha->flags.qpairs_available = 0;
9230 ha->queue_pair_map[qpair_id] = NULL;
9231 clear_bit(qpair_id, ha->qpair_qid_map);
9233 mutex_unlock(&ha->mq_lock);
9239 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
9241 int ret = QLA_FUNCTION_FAILED;
9242 struct qla_hw_data *ha = qpair->hw;
9244 qpair->delete_in_progress = 1;
9246 ret = qla25xx_delete_req_que(vha, qpair->req);
9247 if (ret != QLA_SUCCESS)
9250 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
9251 if (ret != QLA_SUCCESS)
9254 mutex_lock(&ha->mq_lock);
9255 ha->queue_pair_map[qpair->id] = NULL;
9256 clear_bit(qpair->id, ha->qpair_qid_map);
9258 list_del(&qpair->qp_list_elem);
9259 if (list_empty(&vha->qp_list)) {
9260 vha->flags.qpairs_available = 0;
9261 vha->flags.qpairs_req_created = 0;
9262 vha->flags.qpairs_rsp_created = 0;
9264 mempool_destroy(qpair->srb_mempool);
9266 mutex_unlock(&ha->mq_lock);
9274 qla2x00_count_set_bits(uint32_t num)
9276 /* Brian Kernighan's Algorithm */
9287 qla2x00_get_num_tgts(scsi_qla_host_t *vha)
9295 list_for_each_entry_safe(f, tf, &vha->vp_fcports, list) {
9296 if (f->port_type != FCT_TARGET)
9303 int qla2xxx_reset_stats(struct Scsi_Host *host, u32 flags)
9305 scsi_qla_host_t *vha = shost_priv(host);
9306 fc_port_t *fcport = NULL;
9307 unsigned long int_flags;
9309 if (flags & QLA2XX_HW_ERROR)
9310 vha->hw_err_cnt = 0;
9311 if (flags & QLA2XX_SHT_LNK_DWN)
9312 vha->short_link_down_cnt = 0;
9313 if (flags & QLA2XX_INT_ERR)
9314 vha->interface_err_cnt = 0;
9315 if (flags & QLA2XX_CMD_TIMEOUT)
9316 vha->cmd_timeout_cnt = 0;
9317 if (flags & QLA2XX_RESET_CMD_ERR)
9318 vha->reset_cmd_err_cnt = 0;
9319 if (flags & QLA2XX_TGT_SHT_LNK_DOWN) {
9320 spin_lock_irqsave(&vha->hw->tgt.sess_lock, int_flags);
9321 list_for_each_entry(fcport, &vha->vp_fcports, list) {
9322 fcport->tgt_short_link_down_cnt = 0;
9323 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
9325 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, int_flags);
9327 vha->link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
9331 int qla2xxx_start_stats(struct Scsi_Host *host, u32 flags)
9333 return qla2xxx_reset_stats(host, flags);
9336 int qla2xxx_stop_stats(struct Scsi_Host *host, u32 flags)
9338 return qla2xxx_reset_stats(host, flags);
9341 int qla2xxx_get_ini_stats(struct Scsi_Host *host, u32 flags,
9342 void *data, u64 size)
9344 scsi_qla_host_t *vha = shost_priv(host);
9345 struct ql_vnd_host_stats_resp *resp = (struct ql_vnd_host_stats_resp *)data;
9346 struct ql_vnd_stats *rsp_data = &resp->stats;
9347 u64 ini_entry_count = 0;
9349 u64 entry_count = 0;
9351 u32 tmp_stat_type = 0;
9352 fc_port_t *fcport = NULL;
9353 unsigned long int_flags;
9355 /* Copy stat type to work on it */
9356 tmp_stat_type = flags;
9358 if (tmp_stat_type & BIT_17) {
9359 num_tgt = qla2x00_get_num_tgts(vha);
9361 tmp_stat_type &= ~(1 << 17);
9363 ini_entry_count = qla2x00_count_set_bits(tmp_stat_type);
9365 entry_count = ini_entry_count + num_tgt;
9367 rsp_data->entry_count = entry_count;
9370 if (flags & QLA2XX_HW_ERROR) {
9371 rsp_data->entry[i].stat_type = QLA2XX_HW_ERROR;
9372 rsp_data->entry[i].tgt_num = 0x0;
9373 rsp_data->entry[i].cnt = vha->hw_err_cnt;
9377 if (flags & QLA2XX_SHT_LNK_DWN) {
9378 rsp_data->entry[i].stat_type = QLA2XX_SHT_LNK_DWN;
9379 rsp_data->entry[i].tgt_num = 0x0;
9380 rsp_data->entry[i].cnt = vha->short_link_down_cnt;
9384 if (flags & QLA2XX_INT_ERR) {
9385 rsp_data->entry[i].stat_type = QLA2XX_INT_ERR;
9386 rsp_data->entry[i].tgt_num = 0x0;
9387 rsp_data->entry[i].cnt = vha->interface_err_cnt;
9391 if (flags & QLA2XX_CMD_TIMEOUT) {
9392 rsp_data->entry[i].stat_type = QLA2XX_CMD_TIMEOUT;
9393 rsp_data->entry[i].tgt_num = 0x0;
9394 rsp_data->entry[i].cnt = vha->cmd_timeout_cnt;
9398 if (flags & QLA2XX_RESET_CMD_ERR) {
9399 rsp_data->entry[i].stat_type = QLA2XX_RESET_CMD_ERR;
9400 rsp_data->entry[i].tgt_num = 0x0;
9401 rsp_data->entry[i].cnt = vha->reset_cmd_err_cnt;
9405 /* i will continue from previous loop, as target
9406 * entries are after initiator
9408 if (flags & QLA2XX_TGT_SHT_LNK_DOWN) {
9409 spin_lock_irqsave(&vha->hw->tgt.sess_lock, int_flags);
9410 list_for_each_entry(fcport, &vha->vp_fcports, list) {
9411 if (fcport->port_type != FCT_TARGET)
9415 rsp_data->entry[i].stat_type = QLA2XX_TGT_SHT_LNK_DOWN;
9416 rsp_data->entry[i].tgt_num = fcport->rport->number;
9417 rsp_data->entry[i].cnt = fcport->tgt_short_link_down_cnt;
9420 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, int_flags);
9422 resp->status = EXT_STATUS_OK;
9427 int qla2xxx_get_tgt_stats(struct Scsi_Host *host, u32 flags,
9428 struct fc_rport *rport, void *data, u64 size)
9430 struct ql_vnd_tgt_stats_resp *tgt_data = data;
9431 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
9433 tgt_data->status = 0;
9434 tgt_data->stats.entry_count = 1;
9435 tgt_data->stats.entry[0].stat_type = flags;
9436 tgt_data->stats.entry[0].tgt_num = rport->number;
9437 tgt_data->stats.entry[0].cnt = fcport->tgt_short_link_down_cnt;
9442 int qla2xxx_disable_port(struct Scsi_Host *host)
9444 scsi_qla_host_t *vha = shost_priv(host);
9446 vha->hw->flags.port_isolated = 1;
9448 if (qla2x00_chip_is_down(vha))
9451 if (vha->flags.online) {
9452 qla2x00_abort_isp_cleanup(vha);
9453 qla2x00_wait_for_sess_deletion(vha);
9459 int qla2xxx_enable_port(struct Scsi_Host *host)
9461 scsi_qla_host_t *vha = shost_priv(host);
9463 vha->hw->flags.port_isolated = 0;
9464 /* Set the flag to 1, so that isp_abort can proceed */
9465 vha->flags.online = 1;
9466 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
9467 qla2xxx_wake_dpc(vha);