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 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
1200 return QLA_FUNCTION_FAILED;
1202 e->u.fcport.fcport = fcport;
1204 return qla2x00_post_work(vha, e);
1207 static void qla2x00_async_prli_sp_done(srb_t *sp, int res)
1209 struct scsi_qla_host *vha = sp->vha;
1210 struct srb_iocb *lio = &sp->u.iocb_cmd;
1211 struct event_arg ea;
1213 ql_dbg(ql_dbg_disc, vha, 0x2129,
1214 "%s %8phC res %d \n", __func__,
1215 sp->fcport->port_name, res);
1217 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1219 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
1220 memset(&ea, 0, sizeof(ea));
1221 ea.fcport = sp->fcport;
1222 ea.data[0] = lio->u.logio.data[0];
1223 ea.data[1] = lio->u.logio.data[1];
1224 ea.iop[0] = lio->u.logio.iop[0];
1225 ea.iop[1] = lio->u.logio.iop[1];
1228 qla24xx_handle_prli_done_event(vha, &ea);
1235 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
1238 struct srb_iocb *lio;
1239 int rval = QLA_FUNCTION_FAILED;
1241 if (!vha->flags.online) {
1242 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1243 __func__, __LINE__, fcport->port_name);
1247 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
1248 fcport->fw_login_state == DSC_LS_PRLI_PEND) &&
1249 qla_dual_mode_enabled(vha)) {
1250 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1251 __func__, __LINE__, fcport->port_name);
1255 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1259 fcport->flags |= FCF_ASYNC_SENT;
1260 fcport->logout_completed = 0;
1262 sp->type = SRB_PRLI_CMD;
1265 lio = &sp->u.iocb_cmd;
1266 lio->timeout = qla2x00_async_iocb_timeout;
1267 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1269 sp->done = qla2x00_async_prli_sp_done;
1270 lio->u.logio.flags = 0;
1272 if (NVME_TARGET(vha->hw, fcport))
1273 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
1275 ql_dbg(ql_dbg_disc, vha, 0x211b,
1276 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d fc4type %x priority %x %s.\n",
1277 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24,
1278 fcport->login_retry, fcport->fc4_type, vha->hw->fc4_type_priority,
1279 NVME_TARGET(vha->hw, fcport) ? "nvme" : "fcp");
1281 rval = qla2x00_start_sp(sp);
1282 if (rval != QLA_SUCCESS) {
1283 fcport->flags |= FCF_LOGIN_NEEDED;
1284 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1292 fcport->flags &= ~FCF_ASYNC_SENT;
1296 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1298 struct qla_work_evt *e;
1300 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
1302 return QLA_FUNCTION_FAILED;
1304 e->u.fcport.fcport = fcport;
1305 e->u.fcport.opt = opt;
1306 fcport->flags |= FCF_ASYNC_ACTIVE;
1307 return qla2x00_post_work(vha, e);
1310 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1313 struct srb_iocb *mbx;
1314 int rval = QLA_FUNCTION_FAILED;
1317 struct port_database_24xx *pd;
1318 struct qla_hw_data *ha = vha->hw;
1320 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
1321 fcport->loop_id == FC_NO_LOOP_ID) {
1322 ql_log(ql_log_warn, vha, 0xffff,
1323 "%s: %8phC - not sending command.\n",
1324 __func__, fcport->port_name);
1328 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1332 qla2x00_set_fcport_disc_state(fcport, DSC_GPDB);
1334 fcport->flags |= FCF_ASYNC_SENT;
1335 sp->type = SRB_MB_IOCB;
1337 sp->gen1 = fcport->rscn_gen;
1338 sp->gen2 = fcport->login_gen;
1340 mbx = &sp->u.iocb_cmd;
1341 mbx->timeout = qla2x00_async_iocb_timeout;
1342 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1344 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1346 ql_log(ql_log_warn, vha, 0xd043,
1347 "Failed to allocate port database structure.\n");
1351 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1352 mb[0] = MBC_GET_PORT_DATABASE;
1353 mb[1] = fcport->loop_id;
1354 mb[2] = MSW(pd_dma);
1355 mb[3] = LSW(pd_dma);
1356 mb[6] = MSW(MSD(pd_dma));
1357 mb[7] = LSW(MSD(pd_dma));
1358 mb[9] = vha->vp_idx;
1362 mbx->u.mbx.in_dma = pd_dma;
1364 sp->done = qla24xx_async_gpdb_sp_done;
1366 ql_dbg(ql_dbg_disc, vha, 0x20dc,
1367 "Async-%s %8phC hndl %x opt %x\n",
1368 sp->name, fcport->port_name, sp->handle, opt);
1370 rval = qla2x00_start_sp(sp);
1371 if (rval != QLA_SUCCESS)
1377 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1380 fcport->flags &= ~FCF_ASYNC_SENT;
1382 fcport->flags &= ~FCF_ASYNC_ACTIVE;
1383 qla24xx_post_gpdb_work(vha, fcport, opt);
1388 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1390 unsigned long flags;
1392 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1393 ea->fcport->login_gen++;
1394 ea->fcport->deleted = 0;
1395 ea->fcport->logout_on_delete = 1;
1397 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1398 vha->fcport_count++;
1399 ea->fcport->login_succ = 1;
1401 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1402 qla24xx_sched_upd_fcport(ea->fcport);
1403 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1404 } else if (ea->fcport->login_succ) {
1406 * We have an existing session. A late RSCN delivery
1407 * must have triggered the session to be re-validate.
1408 * Session is still valid.
1410 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1411 "%s %d %8phC session revalidate success\n",
1412 __func__, __LINE__, ea->fcport->port_name);
1413 qla2x00_set_fcport_disc_state(ea->fcport, DSC_LOGIN_COMPLETE);
1415 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1419 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1421 fc_port_t *fcport = ea->fcport;
1422 struct port_database_24xx *pd;
1423 struct srb *sp = ea->sp;
1426 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1428 fcport->flags &= ~FCF_ASYNC_SENT;
1430 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1431 "%s %8phC DS %d LS %d fc4_type %x rc %d\n", __func__,
1432 fcport->port_name, fcport->disc_state, pd->current_login_state,
1433 fcport->fc4_type, ea->rc);
1435 if (fcport->disc_state == DSC_DELETE_PEND)
1438 if (NVME_TARGET(vha->hw, fcport))
1439 ls = pd->current_login_state >> 4;
1441 ls = pd->current_login_state & 0xf;
1443 if (ea->sp->gen2 != fcport->login_gen) {
1444 /* target side must have changed it. */
1446 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1447 "%s %8phC generation changed\n",
1448 __func__, fcport->port_name);
1450 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1451 qla_rscn_replay(fcport);
1452 qlt_schedule_sess_for_deletion(fcport);
1457 case PDS_PRLI_COMPLETE:
1458 __qla24xx_parse_gpdb(vha, fcport, pd);
1460 case PDS_PLOGI_PENDING:
1461 case PDS_PLOGI_COMPLETE:
1462 case PDS_PRLI_PENDING:
1463 case PDS_PRLI2_PENDING:
1464 /* Set discovery state back to GNL to Relogin attempt */
1465 if (qla_dual_mode_enabled(vha) ||
1466 qla_ini_mode_enabled(vha)) {
1467 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
1468 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1471 case PDS_LOGO_PENDING:
1472 case PDS_PORT_UNAVAILABLE:
1474 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1475 __func__, __LINE__, fcport->port_name);
1476 qlt_schedule_sess_for_deletion(fcport);
1479 __qla24xx_handle_gpdb_event(vha, ea);
1482 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1487 if (qla_tgt_mode_enabled(vha))
1490 if (qla_dual_mode_enabled(vha)) {
1491 if (N2N_TOPO(vha->hw)) {
1494 mywwn = wwn_to_u64(vha->port_name);
1495 wwn = wwn_to_u64(fcport->port_name);
1498 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1499 && time_after_eq(jiffies,
1500 fcport->plogi_nack_done_deadline))
1506 /* initiator mode */
1510 if (login && fcport->login_retry) {
1511 fcport->login_retry--;
1512 if (fcport->loop_id == FC_NO_LOOP_ID) {
1513 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1514 rc = qla2x00_find_new_loop_id(vha, fcport);
1516 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1517 "%s %d %8phC post del sess - out of loopid\n",
1518 __func__, __LINE__, fcport->port_name);
1519 fcport->scan_state = 0;
1520 qlt_schedule_sess_for_deletion(fcport);
1524 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1525 "%s %d %8phC post login\n",
1526 __func__, __LINE__, fcport->port_name);
1527 qla2x00_post_async_login_work(vha, fcport, NULL);
1531 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1537 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1538 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d\n",
1539 __func__, fcport->port_name, fcport->disc_state,
1540 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1541 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1542 fcport->login_gen, fcport->loop_id, fcport->scan_state);
1544 if (fcport->scan_state != QLA_FCPORT_FOUND)
1547 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1548 qla_dual_mode_enabled(vha) &&
1549 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1550 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1553 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP &&
1554 !N2N_TOPO(vha->hw)) {
1555 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1556 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1561 /* Target won't initiate port login if fabric is present */
1562 if (vha->host->active_mode == MODE_TARGET && !N2N_TOPO(vha->hw))
1565 if (fcport->flags & FCF_ASYNC_SENT) {
1566 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1570 switch (fcport->disc_state) {
1572 wwn = wwn_to_u64(fcport->node_name);
1573 switch (vha->hw->current_topology) {
1575 if (fcport_is_smaller(fcport)) {
1576 /* this adapter is bigger */
1577 if (fcport->login_retry) {
1578 if (fcport->loop_id == FC_NO_LOOP_ID) {
1579 qla2x00_find_new_loop_id(vha,
1581 fcport->fw_login_state =
1582 DSC_LS_PORT_UNAVAIL;
1584 fcport->login_retry--;
1585 qla_post_els_plogi_work(vha, fcport);
1587 ql_log(ql_log_info, vha, 0x705d,
1588 "Unable to reach remote port %8phC",
1592 qla24xx_post_gnl_work(vha, fcport);
1597 ql_dbg(ql_dbg_disc, vha, 0xffff,
1598 "%s %d %8phC post GNNID\n",
1599 __func__, __LINE__, fcport->port_name);
1600 qla24xx_post_gnnid_work(vha, fcport);
1601 } else if (fcport->loop_id == FC_NO_LOOP_ID) {
1602 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1603 "%s %d %8phC post gnl\n",
1604 __func__, __LINE__, fcport->port_name);
1605 qla24xx_post_gnl_work(vha, fcport);
1607 qla_chk_n2n_b4_login(vha, fcport);
1614 switch (vha->hw->current_topology) {
1616 if ((fcport->current_login_state & 0xf) == 0x6) {
1617 ql_dbg(ql_dbg_disc, vha, 0x2118,
1618 "%s %d %8phC post GPDB work\n",
1619 __func__, __LINE__, fcport->port_name);
1620 fcport->chip_reset =
1621 vha->hw->base_qpair->chip_reset;
1622 qla24xx_post_gpdb_work(vha, fcport, 0);
1624 ql_dbg(ql_dbg_disc, vha, 0x2118,
1625 "%s %d %8phC post %s PRLI\n",
1626 __func__, __LINE__, fcport->port_name,
1627 NVME_TARGET(vha->hw, fcport) ? "NVME" :
1629 qla24xx_post_prli_work(vha, fcport);
1633 if (fcport->login_pause) {
1634 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1635 "%s %d %8phC exit\n",
1638 fcport->last_rscn_gen = fcport->rscn_gen;
1639 fcport->last_login_gen = fcport->login_gen;
1640 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1643 qla_chk_n2n_b4_login(vha, fcport);
1648 case DSC_LOGIN_FAILED:
1649 if (N2N_TOPO(vha->hw))
1650 qla_chk_n2n_b4_login(vha, fcport);
1652 qlt_schedule_sess_for_deletion(fcport);
1655 case DSC_LOGIN_COMPLETE:
1656 /* recheck login state */
1657 data[0] = data[1] = 0;
1658 qla2x00_post_async_adisc_work(vha, fcport, data);
1661 case DSC_LOGIN_PEND:
1662 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1663 qla24xx_post_prli_work(vha, fcport);
1666 case DSC_UPD_FCPORT:
1667 sec = jiffies_to_msecs(jiffies -
1668 fcport->jiffies_at_registration)/1000;
1669 if (fcport->sec_since_registration < sec && sec &&
1671 fcport->sec_since_registration = sec;
1672 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
1673 "%s %8phC - Slow Rport registration(%d Sec)\n",
1674 __func__, fcport->port_name, sec);
1677 if (fcport->next_disc_state != DSC_DELETE_PEND)
1678 fcport->next_disc_state = DSC_ADISC;
1679 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1689 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1690 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1692 struct qla_work_evt *e;
1694 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1696 return QLA_FUNCTION_FAILED;
1698 e->u.new_sess.id = *id;
1699 e->u.new_sess.pla = pla;
1700 e->u.new_sess.fc4_type = fc4_type;
1701 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1703 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1705 return qla2x00_post_work(vha, e);
1708 void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
1711 unsigned long flags;
1713 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1715 fcport->scan_needed = 1;
1719 spin_lock_irqsave(&vha->work_lock, flags);
1720 if (vha->scan.scan_flags == 0) {
1721 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s: schedule\n", __func__);
1722 vha->scan.scan_flags |= SF_QUEUED;
1723 schedule_delayed_work(&vha->scan.scan_work, 5);
1725 spin_unlock_irqrestore(&vha->work_lock, flags);
1728 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1729 struct event_arg *ea)
1731 fc_port_t *fcport = ea->fcport;
1733 if (test_bit(UNLOADING, &vha->dpc_flags))
1736 ql_dbg(ql_dbg_disc, vha, 0x2102,
1737 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1738 __func__, fcport->port_name, fcport->disc_state,
1739 fcport->fw_login_state, fcport->login_pause,
1740 fcport->deleted, fcport->conflict,
1741 fcport->last_rscn_gen, fcport->rscn_gen,
1742 fcport->last_login_gen, fcport->login_gen,
1745 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1746 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gnl\n",
1747 __func__, __LINE__, fcport->port_name);
1748 qla24xx_post_gnl_work(vha, fcport);
1752 qla24xx_fcport_handle_login(vha, fcport);
1755 void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
1756 struct event_arg *ea)
1758 /* for pure Target Mode, PRLI will not be initiated */
1759 if (vha->host->active_mode == MODE_TARGET)
1762 ql_dbg(ql_dbg_disc, vha, 0x2118,
1763 "%s %d %8phC post PRLI\n",
1764 __func__, __LINE__, ea->fcport->port_name);
1765 qla24xx_post_prli_work(vha, ea->fcport);
1769 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1770 * to be consumed by the fcport
1772 void qla_rscn_replay(fc_port_t *fcport)
1774 struct event_arg ea;
1776 switch (fcport->disc_state) {
1777 case DSC_DELETE_PEND:
1783 if (fcport->scan_needed) {
1784 memset(&ea, 0, sizeof(ea));
1785 ea.id = fcport->d_id;
1786 ea.id.b.rsvd_1 = RSCN_PORT_ADDR;
1787 qla2x00_handle_rscn(fcport->vha, &ea);
1792 qla2x00_tmf_iocb_timeout(void *data)
1795 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1797 unsigned long flags;
1799 rc = qla24xx_async_abort_cmd(sp, false);
1801 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
1802 for (h = 1; h < sp->qpair->req->num_outstanding_cmds; h++) {
1803 if (sp->qpair->req->outstanding_cmds[h] == sp) {
1804 sp->qpair->req->outstanding_cmds[h] = NULL;
1808 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
1809 tmf->u.tmf.comp_status = cpu_to_le16(CS_TIMEOUT);
1810 tmf->u.tmf.data = QLA_FUNCTION_FAILED;
1811 complete(&tmf->u.tmf.comp);
1815 static void qla2x00_tmf_sp_done(srb_t *sp, int res)
1817 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1819 complete(&tmf->u.tmf.comp);
1823 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
1826 struct scsi_qla_host *vha = fcport->vha;
1827 struct srb_iocb *tm_iocb;
1829 int rval = QLA_FUNCTION_FAILED;
1831 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1835 tm_iocb = &sp->u.iocb_cmd;
1836 sp->type = SRB_TM_CMD;
1839 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1840 init_completion(&tm_iocb->u.tmf.comp);
1841 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1843 tm_iocb->u.tmf.flags = flags;
1844 tm_iocb->u.tmf.lun = lun;
1845 tm_iocb->u.tmf.data = tag;
1846 sp->done = qla2x00_tmf_sp_done;
1848 ql_dbg(ql_dbg_taskm, vha, 0x802f,
1849 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1850 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1851 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1853 rval = qla2x00_start_sp(sp);
1854 if (rval != QLA_SUCCESS)
1856 wait_for_completion(&tm_iocb->u.tmf.comp);
1858 rval = tm_iocb->u.tmf.data;
1860 if (rval != QLA_SUCCESS) {
1861 ql_log(ql_log_warn, vha, 0x8030,
1862 "TM IOCB failed (%x).\n", rval);
1865 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1866 flags = tm_iocb->u.tmf.flags;
1867 lun = (uint16_t)tm_iocb->u.tmf.lun;
1869 /* Issue Marker IOCB */
1870 qla2x00_marker(vha, vha->hw->base_qpair,
1871 fcport->loop_id, lun,
1872 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1877 fcport->flags &= ~FCF_ASYNC_SENT;
1883 qla24xx_async_abort_command(srb_t *sp)
1885 unsigned long flags = 0;
1888 fc_port_t *fcport = sp->fcport;
1889 struct qla_qpair *qpair = sp->qpair;
1890 struct scsi_qla_host *vha = fcport->vha;
1891 struct req_que *req = qpair->req;
1893 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1894 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1895 if (req->outstanding_cmds[handle] == sp)
1898 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1900 if (handle == req->num_outstanding_cmds) {
1901 /* Command not found. */
1902 return QLA_FUNCTION_FAILED;
1904 if (sp->type == SRB_FXIOCB_DCMD)
1905 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1906 FXDISC_ABORT_IOCTL);
1908 return qla24xx_async_abort_cmd(sp, true);
1912 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1914 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
1917 switch (ea->data[0]) {
1918 case MBS_COMMAND_COMPLETE:
1919 ql_dbg(ql_dbg_disc, vha, 0x2118,
1920 "%s %d %8phC post gpdb\n",
1921 __func__, __LINE__, ea->fcport->port_name);
1923 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1924 ea->fcport->logout_on_delete = 1;
1925 ea->fcport->nvme_prli_service_param = ea->iop[0];
1926 if (ea->iop[0] & NVME_PRLI_SP_FIRST_BURST)
1927 ea->fcport->nvme_first_burst_size =
1928 (ea->iop[1] & 0xffff) * 512;
1930 ea->fcport->nvme_first_burst_size = 0;
1931 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1934 if ((ea->iop[0] == LSC_SCODE_ELS_REJECT) &&
1935 (ea->iop[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
1936 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1937 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
1941 ql_dbg(ql_dbg_disc, vha, 0x2118,
1942 "%s %d %8phC priority %s, fc4type %x\n",
1943 __func__, __LINE__, ea->fcport->port_name,
1944 vha->hw->fc4_type_priority == FC4_PRIORITY_FCP ?
1945 "FCP" : "NVMe", ea->fcport->fc4_type);
1947 if (N2N_TOPO(vha->hw)) {
1948 if (vha->hw->fc4_type_priority == FC4_PRIORITY_NVME) {
1949 ea->fcport->fc4_type &= ~FS_FC4TYPE_NVME;
1950 ea->fcport->fc4_type |= FS_FC4TYPE_FCP;
1952 ea->fcport->fc4_type &= ~FS_FC4TYPE_FCP;
1953 ea->fcport->fc4_type |= FS_FC4TYPE_NVME;
1956 if (ea->fcport->n2n_link_reset_cnt < 3) {
1957 ea->fcport->n2n_link_reset_cnt++;
1958 vha->relogin_jif = jiffies + 2 * HZ;
1960 * PRLI failed. Reset link to kick start
1963 set_bit(N2N_LINK_RESET, &vha->dpc_flags);
1965 ql_log(ql_log_warn, vha, 0x2119,
1966 "%s %d %8phC Unable to reconnect\n",
1968 ea->fcport->port_name);
1972 * switch connect. login failed. Take connection down
1973 * and allow relogin to retrigger
1975 if (NVME_FCP_TARGET(ea->fcport)) {
1976 ql_dbg(ql_dbg_disc, vha, 0x2118,
1977 "%s %d %8phC post %s prli\n",
1979 ea->fcport->port_name,
1980 (ea->fcport->fc4_type & FS_FC4TYPE_NVME)
1982 if (vha->hw->fc4_type_priority == FC4_PRIORITY_NVME)
1983 ea->fcport->fc4_type &= ~FS_FC4TYPE_NVME;
1985 ea->fcport->fc4_type &= ~FS_FC4TYPE_FCP;
1988 ea->fcport->flags &= ~FCF_ASYNC_SENT;
1989 ea->fcport->keep_nport_handle = 0;
1990 ea->fcport->logout_on_delete = 1;
1991 qlt_schedule_sess_for_deletion(ea->fcport);
1998 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
2000 port_id_t cid; /* conflict Nport id */
2002 struct fc_port *conflict_fcport;
2003 unsigned long flags;
2004 struct fc_port *fcport = ea->fcport;
2006 ql_dbg(ql_dbg_disc, vha, 0xffff,
2007 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
2008 __func__, fcport->port_name, fcport->disc_state,
2009 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
2010 ea->sp->gen1, fcport->rscn_gen,
2011 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
2013 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
2014 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
2015 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2016 "%s %d %8phC Remote is trying to login\n",
2017 __func__, __LINE__, fcport->port_name);
2021 if ((fcport->disc_state == DSC_DELETE_PEND) ||
2022 (fcport->disc_state == DSC_DELETED)) {
2023 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2027 if (ea->sp->gen2 != fcport->login_gen) {
2028 /* target side must have changed it. */
2029 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2030 "%s %8phC generation changed\n",
2031 __func__, fcport->port_name);
2032 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2034 } else if (ea->sp->gen1 != fcport->rscn_gen) {
2035 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2036 "%s %8phC RSCN generation changed\n",
2037 __func__, fcport->port_name);
2038 qla_rscn_replay(fcport);
2039 qlt_schedule_sess_for_deletion(fcport);
2043 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
2046 switch (ea->data[0]) {
2047 case MBS_COMMAND_COMPLETE:
2049 * Driver must validate login state - If PRLI not complete,
2050 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
2053 if (NVME_TARGET(vha->hw, ea->fcport)) {
2054 ql_dbg(ql_dbg_disc, vha, 0x2117,
2055 "%s %d %8phC post prli\n",
2056 __func__, __LINE__, ea->fcport->port_name);
2057 qla24xx_post_prli_work(vha, ea->fcport);
2059 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2060 "%s %d %8phC LoopID 0x%x in use with %06x. post gpdb\n",
2061 __func__, __LINE__, ea->fcport->port_name,
2062 ea->fcport->loop_id, ea->fcport->d_id.b24);
2064 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2065 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2066 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2067 ea->fcport->logout_on_delete = 1;
2068 ea->fcport->send_els_logo = 0;
2069 ea->fcport->fw_login_state = DSC_LS_PRLI_COMP;
2070 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2072 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2075 case MBS_COMMAND_ERROR:
2076 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
2077 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
2079 ea->fcport->flags &= ~FCF_ASYNC_SENT;
2080 qla2x00_set_fcport_disc_state(ea->fcport, DSC_LOGIN_FAILED);
2081 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
2082 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2084 qla2x00_mark_device_lost(vha, ea->fcport, 1);
2086 case MBS_LOOP_ID_USED:
2087 /* data[1] = IO PARAM 1 = nport ID */
2088 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
2089 cid.b.area = (ea->iop[1] >> 8) & 0xff;
2090 cid.b.al_pa = ea->iop[1] & 0xff;
2093 ql_dbg(ql_dbg_disc, vha, 0x20ec,
2094 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2095 __func__, __LINE__, ea->fcport->port_name,
2096 ea->fcport->loop_id, cid.b24);
2098 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2099 ea->fcport->loop_id = FC_NO_LOOP_ID;
2100 qla24xx_post_gnl_work(vha, ea->fcport);
2102 case MBS_PORT_ID_USED:
2103 lid = ea->iop[1] & 0xffff;
2104 qlt_find_sess_invalidate_other(vha,
2105 wwn_to_u64(ea->fcport->port_name),
2106 ea->fcport->d_id, lid, &conflict_fcport);
2108 if (conflict_fcport) {
2110 * Another fcport share the same loop_id/nport id.
2111 * Conflict fcport needs to finish cleanup before this
2112 * fcport can proceed to login.
2114 conflict_fcport->conflict = ea->fcport;
2115 ea->fcport->login_pause = 1;
2117 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2118 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
2119 __func__, __LINE__, ea->fcport->port_name,
2120 ea->fcport->d_id.b24, lid);
2122 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2123 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2124 __func__, __LINE__, ea->fcport->port_name,
2125 ea->fcport->d_id.b24, lid);
2127 qla2x00_clear_loop_id(ea->fcport);
2128 set_bit(lid, vha->hw->loop_id_map);
2129 ea->fcport->loop_id = lid;
2130 ea->fcport->keep_nport_handle = 0;
2131 ea->fcport->logout_on_delete = 1;
2132 qlt_schedule_sess_for_deletion(ea->fcport);
2139 /****************************************************************************/
2140 /* QLogic ISP2x00 Hardware Support Functions. */
2141 /****************************************************************************/
2144 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
2146 int rval = QLA_SUCCESS;
2147 struct qla_hw_data *ha = vha->hw;
2148 uint32_t idc_major_ver, idc_minor_ver;
2151 qla83xx_idc_lock(vha, 0);
2153 /* SV: TODO: Assign initialization timeout from
2154 * flash-info / other param
2156 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
2157 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
2159 /* Set our fcoe function presence */
2160 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
2161 ql_dbg(ql_dbg_p3p, vha, 0xb077,
2162 "Error while setting DRV-Presence.\n");
2163 rval = QLA_FUNCTION_FAILED;
2167 /* Decide the reset ownership */
2168 qla83xx_reset_ownership(vha);
2171 * On first protocol driver load:
2172 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2174 * Others: Check compatibility with current IDC Major version.
2176 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
2177 if (ha->flags.nic_core_reset_owner) {
2178 /* Set IDC Major version */
2179 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
2180 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
2182 /* Clearing IDC-Lock-Recovery register */
2183 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
2184 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
2186 * Clear further IDC participation if we are not compatible with
2187 * the current IDC Major Version.
2189 ql_log(ql_log_warn, vha, 0xb07d,
2190 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2191 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
2192 __qla83xx_clear_drv_presence(vha);
2193 rval = QLA_FUNCTION_FAILED;
2196 /* Each function sets its supported Minor version. */
2197 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
2198 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
2199 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
2201 if (ha->flags.nic_core_reset_owner) {
2202 memset(config, 0, sizeof(config));
2203 if (!qla81xx_get_port_config(vha, config))
2204 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
2208 rval = qla83xx_idc_state_handler(vha);
2211 qla83xx_idc_unlock(vha, 0);
2217 * qla2x00_initialize_adapter
2221 * ha = adapter block pointer.
2227 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
2230 struct qla_hw_data *ha = vha->hw;
2231 struct req_que *req = ha->req_q_map[0];
2232 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2234 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2235 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2237 /* Clear adapter flags. */
2238 vha->flags.online = 0;
2239 ha->flags.chip_reset_done = 0;
2240 vha->flags.reset_active = 0;
2241 ha->flags.pci_channel_io_perm_failure = 0;
2242 ha->flags.eeh_busy = 0;
2243 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2244 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
2245 atomic_set(&vha->loop_state, LOOP_DOWN);
2246 vha->device_flags = DFLG_NO_CABLE;
2248 vha->flags.management_server_logged_in = 0;
2249 vha->marker_needed = 0;
2250 ha->isp_abort_cnt = 0;
2251 ha->beacon_blink_led = 0;
2253 set_bit(0, ha->req_qid_map);
2254 set_bit(0, ha->rsp_qid_map);
2256 ql_dbg(ql_dbg_init, vha, 0x0040,
2257 "Configuring PCI space...\n");
2258 rval = ha->isp_ops->pci_config(vha);
2260 ql_log(ql_log_warn, vha, 0x0044,
2261 "Unable to configure PCI space.\n");
2265 ha->isp_ops->reset_chip(vha);
2267 /* Check for secure flash support */
2268 if (IS_QLA28XX(ha)) {
2269 if (rd_reg_word(®->mailbox12) & BIT_0)
2270 ha->flags.secure_adapter = 1;
2271 ql_log(ql_log_info, vha, 0xffff, "Secure Adapter: %s\n",
2272 (ha->flags.secure_adapter) ? "Yes" : "No");
2276 rval = qla2xxx_get_flash_info(vha);
2278 ql_log(ql_log_fatal, vha, 0x004f,
2279 "Unable to validate FLASH data.\n");
2283 if (IS_QLA8044(ha)) {
2284 qla8044_read_reset_template(vha);
2286 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2287 * If DONRESET_BIT0 is set, drivers should not set dev_state
2288 * to NEED_RESET. But if NEED_RESET is set, drivers should
2289 * should honor the reset. */
2290 if (ql2xdontresethba == 1)
2291 qla8044_set_idc_dontreset(vha);
2294 ha->isp_ops->get_flash_version(vha, req->ring);
2295 ql_dbg(ql_dbg_init, vha, 0x0061,
2296 "Configure NVRAM parameters...\n");
2298 /* Let priority default to FCP, can be overridden by nvram_config */
2299 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2301 ha->isp_ops->nvram_config(vha);
2303 if (ha->fc4_type_priority != FC4_PRIORITY_FCP &&
2304 ha->fc4_type_priority != FC4_PRIORITY_NVME)
2305 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2307 ql_log(ql_log_info, vha, 0xffff, "FC4 priority set to %s\n",
2308 ha->fc4_type_priority == FC4_PRIORITY_FCP ? "FCP" : "NVMe");
2310 if (ha->flags.disable_serdes) {
2311 /* Mask HBA via NVRAM settings? */
2312 ql_log(ql_log_info, vha, 0x0077,
2313 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
2314 return QLA_FUNCTION_FAILED;
2317 ql_dbg(ql_dbg_init, vha, 0x0078,
2318 "Verifying loaded RISC code...\n");
2320 /* If smartsan enabled then require fdmi and rdp enabled */
2326 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
2327 rval = ha->isp_ops->chip_diag(vha);
2330 rval = qla2x00_setup_chip(vha);
2335 if (IS_QLA84XX(ha)) {
2336 ha->cs84xx = qla84xx_get_chip(vha);
2338 ql_log(ql_log_warn, vha, 0x00d0,
2339 "Unable to configure ISP84XX.\n");
2340 return QLA_FUNCTION_FAILED;
2344 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2345 rval = qla2x00_init_rings(vha);
2347 /* No point in continuing if firmware initialization failed. */
2348 if (rval != QLA_SUCCESS)
2351 ha->flags.chip_reset_done = 1;
2353 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2354 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2355 rval = qla84xx_init_chip(vha);
2356 if (rval != QLA_SUCCESS) {
2357 ql_log(ql_log_warn, vha, 0x00d4,
2358 "Unable to initialize ISP84XX.\n");
2359 qla84xx_put_chip(vha);
2363 /* Load the NIC Core f/w if we are the first protocol driver. */
2364 if (IS_QLA8031(ha)) {
2365 rval = qla83xx_nic_core_fw_load(vha);
2367 ql_log(ql_log_warn, vha, 0x0124,
2368 "Error in initializing NIC Core f/w.\n");
2371 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2372 qla24xx_read_fcp_prio_cfg(vha);
2374 if (IS_P3P_TYPE(ha))
2375 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2377 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2383 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2386 * Returns 0 on success.
2389 qla2100_pci_config(scsi_qla_host_t *vha)
2392 unsigned long flags;
2393 struct qla_hw_data *ha = vha->hw;
2394 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2396 pci_set_master(ha->pdev);
2397 pci_try_set_mwi(ha->pdev);
2399 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2400 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2401 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2403 pci_disable_rom(ha->pdev);
2405 /* Get PCI bus information. */
2406 spin_lock_irqsave(&ha->hardware_lock, flags);
2407 ha->pci_attr = rd_reg_word(®->ctrl_status);
2408 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2414 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2417 * Returns 0 on success.
2420 qla2300_pci_config(scsi_qla_host_t *vha)
2423 unsigned long flags = 0;
2425 struct qla_hw_data *ha = vha->hw;
2426 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2428 pci_set_master(ha->pdev);
2429 pci_try_set_mwi(ha->pdev);
2431 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2432 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2434 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2435 w &= ~PCI_COMMAND_INTX_DISABLE;
2436 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2439 * If this is a 2300 card and not 2312, reset the
2440 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2441 * the 2310 also reports itself as a 2300 so we need to get the
2442 * fb revision level -- a 6 indicates it really is a 2300 and
2445 if (IS_QLA2300(ha)) {
2446 spin_lock_irqsave(&ha->hardware_lock, flags);
2449 wrt_reg_word(®->hccr, HCCR_PAUSE_RISC);
2450 for (cnt = 0; cnt < 30000; cnt++) {
2451 if ((rd_reg_word(®->hccr) & HCCR_RISC_PAUSE) != 0)
2457 /* Select FPM registers. */
2458 wrt_reg_word(®->ctrl_status, 0x20);
2459 rd_reg_word(®->ctrl_status);
2461 /* Get the fb rev level */
2462 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2464 if (ha->fb_rev == FPM_2300)
2465 pci_clear_mwi(ha->pdev);
2467 /* Deselect FPM registers. */
2468 wrt_reg_word(®->ctrl_status, 0x0);
2469 rd_reg_word(®->ctrl_status);
2471 /* Release RISC module. */
2472 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
2473 for (cnt = 0; cnt < 30000; cnt++) {
2474 if ((rd_reg_word(®->hccr) & HCCR_RISC_PAUSE) == 0)
2480 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2483 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2485 pci_disable_rom(ha->pdev);
2487 /* Get PCI bus information. */
2488 spin_lock_irqsave(&ha->hardware_lock, flags);
2489 ha->pci_attr = rd_reg_word(®->ctrl_status);
2490 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2496 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2499 * Returns 0 on success.
2502 qla24xx_pci_config(scsi_qla_host_t *vha)
2505 unsigned long flags = 0;
2506 struct qla_hw_data *ha = vha->hw;
2507 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2509 pci_set_master(ha->pdev);
2510 pci_try_set_mwi(ha->pdev);
2512 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2513 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2514 w &= ~PCI_COMMAND_INTX_DISABLE;
2515 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2517 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2519 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2520 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2521 pcix_set_mmrbc(ha->pdev, 2048);
2523 /* PCIe -- adjust Maximum Read Request Size (2048). */
2524 if (pci_is_pcie(ha->pdev))
2525 pcie_set_readrq(ha->pdev, 4096);
2527 pci_disable_rom(ha->pdev);
2529 ha->chip_revision = ha->pdev->revision;
2531 /* Get PCI bus information. */
2532 spin_lock_irqsave(&ha->hardware_lock, flags);
2533 ha->pci_attr = rd_reg_dword(®->ctrl_status);
2534 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2540 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2543 * Returns 0 on success.
2546 qla25xx_pci_config(scsi_qla_host_t *vha)
2549 struct qla_hw_data *ha = vha->hw;
2551 pci_set_master(ha->pdev);
2552 pci_try_set_mwi(ha->pdev);
2554 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2555 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2556 w &= ~PCI_COMMAND_INTX_DISABLE;
2557 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2559 /* PCIe -- adjust Maximum Read Request Size (2048). */
2560 if (pci_is_pcie(ha->pdev))
2561 pcie_set_readrq(ha->pdev, 4096);
2563 pci_disable_rom(ha->pdev);
2565 ha->chip_revision = ha->pdev->revision;
2571 * qla2x00_isp_firmware() - Choose firmware image.
2574 * Returns 0 on success.
2577 qla2x00_isp_firmware(scsi_qla_host_t *vha)
2580 uint16_t loop_id, topo, sw_cap;
2581 uint8_t domain, area, al_pa;
2582 struct qla_hw_data *ha = vha->hw;
2584 /* Assume loading risc code */
2585 rval = QLA_FUNCTION_FAILED;
2587 if (ha->flags.disable_risc_code_load) {
2588 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
2590 /* Verify checksum of loaded RISC code. */
2591 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
2592 if (rval == QLA_SUCCESS) {
2593 /* And, verify we are not in ROM code. */
2594 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2595 &area, &domain, &topo, &sw_cap);
2600 ql_dbg(ql_dbg_init, vha, 0x007a,
2601 "**** Load RISC code ****.\n");
2607 * qla2x00_reset_chip() - Reset ISP chip.
2610 * Returns 0 on success.
2613 qla2x00_reset_chip(scsi_qla_host_t *vha)
2615 unsigned long flags = 0;
2616 struct qla_hw_data *ha = vha->hw;
2617 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2620 int rval = QLA_FUNCTION_FAILED;
2622 if (unlikely(pci_channel_offline(ha->pdev)))
2625 ha->isp_ops->disable_intrs(ha);
2627 spin_lock_irqsave(&ha->hardware_lock, flags);
2629 /* Turn off master enable */
2631 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2632 cmd &= ~PCI_COMMAND_MASTER;
2633 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2635 if (!IS_QLA2100(ha)) {
2637 wrt_reg_word(®->hccr, HCCR_PAUSE_RISC);
2638 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2639 for (cnt = 0; cnt < 30000; cnt++) {
2640 if ((rd_reg_word(®->hccr) &
2641 HCCR_RISC_PAUSE) != 0)
2646 rd_reg_word(®->hccr); /* PCI Posting. */
2650 /* Select FPM registers. */
2651 wrt_reg_word(®->ctrl_status, 0x20);
2652 rd_reg_word(®->ctrl_status); /* PCI Posting. */
2654 /* FPM Soft Reset. */
2655 wrt_reg_word(®->fpm_diag_config, 0x100);
2656 rd_reg_word(®->fpm_diag_config); /* PCI Posting. */
2658 /* Toggle Fpm Reset. */
2659 if (!IS_QLA2200(ha)) {
2660 wrt_reg_word(®->fpm_diag_config, 0x0);
2661 rd_reg_word(®->fpm_diag_config); /* PCI Posting. */
2664 /* Select frame buffer registers. */
2665 wrt_reg_word(®->ctrl_status, 0x10);
2666 rd_reg_word(®->ctrl_status); /* PCI Posting. */
2668 /* Reset frame buffer FIFOs. */
2669 if (IS_QLA2200(ha)) {
2670 WRT_FB_CMD_REG(ha, reg, 0xa000);
2671 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2673 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2675 /* Read back fb_cmd until zero or 3 seconds max */
2676 for (cnt = 0; cnt < 3000; cnt++) {
2677 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2683 /* Select RISC module registers. */
2684 wrt_reg_word(®->ctrl_status, 0);
2685 rd_reg_word(®->ctrl_status); /* PCI Posting. */
2687 /* Reset RISC processor. */
2688 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
2689 rd_reg_word(®->hccr); /* PCI Posting. */
2691 /* Release RISC processor. */
2692 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
2693 rd_reg_word(®->hccr); /* PCI Posting. */
2696 wrt_reg_word(®->hccr, HCCR_CLR_RISC_INT);
2697 wrt_reg_word(®->hccr, HCCR_CLR_HOST_INT);
2699 /* Reset ISP chip. */
2700 wrt_reg_word(®->ctrl_status, CSR_ISP_SOFT_RESET);
2702 /* Wait for RISC to recover from reset. */
2703 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2705 * It is necessary to for a delay here since the card doesn't
2706 * respond to PCI reads during a reset. On some architectures
2707 * this will result in an MCA.
2710 for (cnt = 30000; cnt; cnt--) {
2711 if ((rd_reg_word(®->ctrl_status) &
2712 CSR_ISP_SOFT_RESET) == 0)
2719 /* Reset RISC processor. */
2720 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
2722 wrt_reg_word(®->semaphore, 0);
2724 /* Release RISC processor. */
2725 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
2726 rd_reg_word(®->hccr); /* PCI Posting. */
2728 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2729 for (cnt = 0; cnt < 30000; cnt++) {
2730 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
2738 /* Turn on master enable */
2739 cmd |= PCI_COMMAND_MASTER;
2740 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2742 /* Disable RISC pause on FPM parity error. */
2743 if (!IS_QLA2100(ha)) {
2744 wrt_reg_word(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
2745 rd_reg_word(®->hccr); /* PCI Posting. */
2748 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2754 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2757 * Returns 0 on success.
2760 qla81xx_reset_mpi(scsi_qla_host_t *vha)
2762 uint16_t mb[4] = {0x1010, 0, 1, 0};
2764 if (!IS_QLA81XX(vha->hw))
2767 return qla81xx_write_mpi_register(vha, mb);
2771 qla_chk_risc_recovery(scsi_qla_host_t *vha)
2773 struct qla_hw_data *ha = vha->hw;
2774 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2775 __le16 __iomem *mbptr = ®->mailbox0;
2778 int rc = QLA_SUCCESS;
2780 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
2783 /* this check is only valid after RISC reset */
2784 mb[0] = rd_reg_word(mbptr);
2787 rc = QLA_FUNCTION_FAILED;
2789 for (i = 1; i < 32; i++) {
2790 mb[i] = rd_reg_word(mbptr);
2794 ql_log(ql_log_warn, vha, 0x1015,
2795 "RISC reset failed. mb[0-7] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
2796 mb[0], mb[1], mb[2], mb[3], mb[4], mb[5], mb[6], mb[7]);
2797 ql_log(ql_log_warn, vha, 0x1015,
2798 "RISC reset failed. mb[8-15] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
2799 mb[8], mb[9], mb[10], mb[11], mb[12], mb[13], mb[14],
2801 ql_log(ql_log_warn, vha, 0x1015,
2802 "RISC reset failed. mb[16-23] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
2803 mb[16], mb[17], mb[18], mb[19], mb[20], mb[21], mb[22],
2805 ql_log(ql_log_warn, vha, 0x1015,
2806 "RISC reset failed. mb[24-31] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
2807 mb[24], mb[25], mb[26], mb[27], mb[28], mb[29], mb[30],
2814 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2817 * Returns 0 on success.
2820 qla24xx_reset_risc(scsi_qla_host_t *vha)
2822 unsigned long flags = 0;
2823 struct qla_hw_data *ha = vha->hw;
2824 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2827 static int abts_cnt; /* ISP abort retry counts */
2828 int rval = QLA_SUCCESS;
2831 spin_lock_irqsave(&ha->hardware_lock, flags);
2834 wrt_reg_dword(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2835 for (cnt = 0; cnt < 30000; cnt++) {
2836 if ((rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2842 if (!(rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE))
2843 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2845 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2846 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2847 rd_reg_dword(®->hccr),
2848 rd_reg_dword(®->ctrl_status),
2849 (rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE));
2851 wrt_reg_dword(®->ctrl_status,
2852 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2853 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
2857 /* Wait for firmware to complete NVRAM accesses. */
2858 rd_reg_word(®->mailbox0);
2859 for (cnt = 10000; rd_reg_word(®->mailbox0) != 0 &&
2860 rval == QLA_SUCCESS; cnt--) {
2865 rval = QLA_FUNCTION_TIMEOUT;
2868 if (rval == QLA_SUCCESS)
2869 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2871 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2872 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2873 rd_reg_dword(®->hccr),
2874 rd_reg_word(®->mailbox0));
2876 /* Wait for soft-reset to complete. */
2877 rd_reg_dword(®->ctrl_status);
2878 for (cnt = 0; cnt < 60; cnt++) {
2880 if ((rd_reg_dword(®->ctrl_status) &
2881 CSRX_ISP_SOFT_RESET) == 0)
2886 if (!(rd_reg_dword(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
2887 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2889 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2890 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2891 rd_reg_dword(®->hccr),
2892 rd_reg_dword(®->ctrl_status));
2894 /* If required, do an MPI FW reset now */
2895 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2896 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2897 if (++abts_cnt < 5) {
2898 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2899 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2902 * We exhausted the ISP abort retries. We have to
2903 * set the board offline.
2906 vha->flags.online = 0;
2911 wrt_reg_dword(®->hccr, HCCRX_SET_RISC_RESET);
2912 rd_reg_dword(®->hccr);
2914 wrt_reg_dword(®->hccr, HCCRX_REL_RISC_PAUSE);
2915 rd_reg_dword(®->hccr);
2917 wrt_reg_dword(®->hccr, HCCRX_CLR_RISC_RESET);
2919 rd_reg_dword(®->hccr);
2921 wd = rd_reg_word(®->mailbox0);
2922 for (cnt = 300; wd != 0 && rval == QLA_SUCCESS; cnt--) {
2926 if (print && qla_chk_risc_recovery(vha))
2929 wd = rd_reg_word(®->mailbox0);
2931 rval = QLA_FUNCTION_TIMEOUT;
2933 ql_log(ql_log_warn, vha, 0x015e,
2934 "RISC reset timeout\n");
2938 if (rval == QLA_SUCCESS)
2939 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2941 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2942 "Host Risc 0x%x, mailbox0 0x%x\n",
2943 rd_reg_dword(®->hccr),
2944 rd_reg_word(®->mailbox0));
2946 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2948 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2949 "Driver in %s mode\n",
2950 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2952 if (IS_NOPOLLING_TYPE(ha))
2953 ha->isp_ops->enable_intrs(ha);
2959 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2961 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2963 wrt_reg_dword(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2964 *data = rd_reg_dword(®->iobase_window + RISC_REGISTER_WINDOW_OFFSET);
2968 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2970 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2972 wrt_reg_dword(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2973 wrt_reg_dword(®->iobase_window + RISC_REGISTER_WINDOW_OFFSET, data);
2977 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2980 uint delta_msec = 100;
2981 uint elapsed_msec = 0;
2985 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2986 vha->hw->pdev->subsystem_device != 0x0240)
2989 wrt_reg_dword(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2993 timeout_msec = TIMEOUT_SEMAPHORE;
2994 n = timeout_msec / delta_msec;
2996 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2997 qla25xx_read_risc_sema_reg(vha, &wd32);
2998 if (wd32 & RISC_SEMAPHORE)
3001 elapsed_msec += delta_msec;
3002 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
3006 if (!(wd32 & RISC_SEMAPHORE))
3009 if (!(wd32 & RISC_SEMAPHORE_FORCE))
3012 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
3013 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
3014 n = timeout_msec / delta_msec;
3016 qla25xx_read_risc_sema_reg(vha, &wd32);
3017 if (!(wd32 & RISC_SEMAPHORE_FORCE))
3020 elapsed_msec += delta_msec;
3021 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
3025 if (wd32 & RISC_SEMAPHORE_FORCE)
3026 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
3031 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
3038 * qla24xx_reset_chip() - Reset ISP24xx chip.
3041 * Returns 0 on success.
3044 qla24xx_reset_chip(scsi_qla_host_t *vha)
3046 struct qla_hw_data *ha = vha->hw;
3047 int rval = QLA_FUNCTION_FAILED;
3049 if (pci_channel_offline(ha->pdev) &&
3050 ha->flags.pci_channel_io_perm_failure) {
3054 ha->isp_ops->disable_intrs(ha);
3056 qla25xx_manipulate_risc_semaphore(vha);
3058 /* Perform RISC reset. */
3059 rval = qla24xx_reset_risc(vha);
3065 * qla2x00_chip_diag() - Test chip for proper operation.
3068 * Returns 0 on success.
3071 qla2x00_chip_diag(scsi_qla_host_t *vha)
3074 struct qla_hw_data *ha = vha->hw;
3075 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3076 unsigned long flags = 0;
3080 struct req_que *req = ha->req_q_map[0];
3082 /* Assume a failed state */
3083 rval = QLA_FUNCTION_FAILED;
3085 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
3086 ®->flash_address);
3088 spin_lock_irqsave(&ha->hardware_lock, flags);
3090 /* Reset ISP chip. */
3091 wrt_reg_word(®->ctrl_status, CSR_ISP_SOFT_RESET);
3094 * We need to have a delay here since the card will not respond while
3095 * in reset causing an MCA on some architectures.
3098 data = qla2x00_debounce_register(®->ctrl_status);
3099 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
3101 data = rd_reg_word(®->ctrl_status);
3106 goto chip_diag_failed;
3108 ql_dbg(ql_dbg_init, vha, 0x007c,
3109 "Reset register cleared by chip reset.\n");
3111 /* Reset RISC processor. */
3112 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
3113 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
3115 /* Workaround for QLA2312 PCI parity error */
3116 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
3117 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
3118 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
3120 data = RD_MAILBOX_REG(ha, reg, 0);
3127 goto chip_diag_failed;
3129 /* Check product ID of chip */
3130 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
3132 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
3133 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
3134 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
3135 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
3136 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
3137 mb[3] != PROD_ID_3) {
3138 ql_log(ql_log_warn, vha, 0x0062,
3139 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
3140 mb[1], mb[2], mb[3]);
3142 goto chip_diag_failed;
3144 ha->product_id[0] = mb[1];
3145 ha->product_id[1] = mb[2];
3146 ha->product_id[2] = mb[3];
3147 ha->product_id[3] = mb[4];
3149 /* Adjust fw RISC transfer size */
3150 if (req->length > 1024)
3151 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
3153 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
3156 if (IS_QLA2200(ha) &&
3157 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
3158 /* Limit firmware transfer size with a 2200A */
3159 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
3161 ha->device_type |= DT_ISP2200A;
3162 ha->fw_transfer_size = 128;
3165 /* Wrap Incoming Mailboxes Test. */
3166 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3168 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
3169 rval = qla2x00_mbx_reg_test(vha);
3171 ql_log(ql_log_warn, vha, 0x0080,
3172 "Failed mailbox send register test.\n");
3174 /* Flag a successful rval */
3176 spin_lock_irqsave(&ha->hardware_lock, flags);
3180 ql_log(ql_log_info, vha, 0x0081,
3181 "Chip diagnostics **** FAILED ****.\n");
3183 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3189 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3192 * Returns 0 on success.
3195 qla24xx_chip_diag(scsi_qla_host_t *vha)
3198 struct qla_hw_data *ha = vha->hw;
3199 struct req_que *req = ha->req_q_map[0];
3201 if (IS_P3P_TYPE(ha))
3204 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
3206 rval = qla2x00_mbx_reg_test(vha);
3208 ql_log(ql_log_warn, vha, 0x0082,
3209 "Failed mailbox send register test.\n");
3211 /* Flag a successful rval */
3219 qla2x00_init_fce_trace(scsi_qla_host_t *vha)
3224 struct qla_hw_data *ha = vha->hw;
3226 if (!IS_FWI2_CAPABLE(ha))
3229 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3230 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3234 ql_dbg(ql_dbg_init, vha, 0x00bd,
3235 "%s: FCE Mem is already allocated.\n",
3240 /* Allocate memory for Fibre Channel Event Buffer. */
3241 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3244 ql_log(ql_log_warn, vha, 0x00be,
3245 "Unable to allocate (%d KB) for FCE.\n",
3250 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3251 ha->fce_mb, &ha->fce_bufs);
3253 ql_log(ql_log_warn, vha, 0x00bf,
3254 "Unable to initialize FCE (%d).\n", rval);
3255 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, tc_dma);
3259 ql_dbg(ql_dbg_init, vha, 0x00c0,
3260 "Allocated (%d KB) for FCE...\n", FCE_SIZE / 1024);
3262 ha->flags.fce_enabled = 1;
3263 ha->fce_dma = tc_dma;
3268 qla2x00_init_eft_trace(scsi_qla_host_t *vha)
3273 struct qla_hw_data *ha = vha->hw;
3275 if (!IS_FWI2_CAPABLE(ha))
3279 ql_dbg(ql_dbg_init, vha, 0x00bd,
3280 "%s: EFT Mem is already allocated.\n",
3285 /* Allocate memory for Extended Trace Buffer. */
3286 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3289 ql_log(ql_log_warn, vha, 0x00c1,
3290 "Unable to allocate (%d KB) for EFT.\n",
3295 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3297 ql_log(ql_log_warn, vha, 0x00c2,
3298 "Unable to initialize EFT (%d).\n", rval);
3299 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, tc_dma);
3303 ql_dbg(ql_dbg_init, vha, 0x00c3,
3304 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3306 ha->eft_dma = tc_dma;
3311 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3313 qla2x00_init_fce_trace(vha);
3314 qla2x00_init_eft_trace(vha);
3318 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3320 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
3321 eft_size, fce_size, mq_size;
3322 struct qla_hw_data *ha = vha->hw;
3323 struct req_que *req = ha->req_q_map[0];
3324 struct rsp_que *rsp = ha->rsp_q_map[0];
3325 struct qla2xxx_fw_dump *fw_dump;
3327 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
3328 req_q_size = rsp_q_size = 0;
3330 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3331 fixed_size = sizeof(struct qla2100_fw_dump);
3332 } else if (IS_QLA23XX(ha)) {
3333 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
3334 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
3336 } else if (IS_FWI2_CAPABLE(ha)) {
3337 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
3338 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
3339 else if (IS_QLA81XX(ha))
3340 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
3341 else if (IS_QLA25XX(ha))
3342 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
3344 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
3346 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
3349 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) &&
3351 mq_size = sizeof(struct qla2xxx_mq_chain);
3353 * Allocate maximum buffer size for all queues - Q0.
3354 * Resizing must be done at end-of-dump processing.
3356 mq_size += (ha->max_req_queues - 1) *
3357 (req->length * sizeof(request_t));
3358 mq_size += (ha->max_rsp_queues - 1) *
3359 (rsp->length * sizeof(response_t));
3361 if (ha->tgt.atio_ring)
3362 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3364 qla2x00_init_fce_trace(vha);
3366 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3367 qla2x00_init_eft_trace(vha);
3369 eft_size = EFT_SIZE;
3372 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3373 struct fwdt *fwdt = ha->fwdt;
3376 for (j = 0; j < 2; j++, fwdt++) {
3377 if (!fwdt->template) {
3378 ql_dbg(ql_dbg_init, vha, 0x00ba,
3379 "-> fwdt%u no template\n", j);
3382 ql_dbg(ql_dbg_init, vha, 0x00fa,
3383 "-> fwdt%u calculating fwdump size...\n", j);
3384 fwdt->dump_size = qla27xx_fwdt_calculate_dump_size(
3385 vha, fwdt->template);
3386 ql_dbg(ql_dbg_init, vha, 0x00fa,
3387 "-> fwdt%u calculated fwdump size = %#lx bytes\n",
3388 j, fwdt->dump_size);
3389 dump_size += fwdt->dump_size;
3391 /* Add space for spare MPI fw dump. */
3392 dump_size += ha->fwdt[1].dump_size;
3394 req_q_size = req->length * sizeof(request_t);
3395 rsp_q_size = rsp->length * sizeof(response_t);
3396 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3397 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size
3399 ha->chain_offset = dump_size;
3400 dump_size += mq_size + fce_size;
3401 if (ha->exchoffld_buf)
3402 dump_size += sizeof(struct qla2xxx_offld_chain) +
3404 if (ha->exlogin_buf)
3405 dump_size += sizeof(struct qla2xxx_offld_chain) +
3409 if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) {
3411 ql_dbg(ql_dbg_init, vha, 0x00c5,
3412 "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n",
3413 __func__, dump_size, ha->fw_dump_len,
3414 ha->fw_dump_alloc_len);
3416 fw_dump = vmalloc(dump_size);
3418 ql_log(ql_log_warn, vha, 0x00c4,
3419 "Unable to allocate (%d KB) for firmware dump.\n",
3422 mutex_lock(&ha->optrom_mutex);
3423 if (ha->fw_dumped) {
3424 memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len);
3426 ha->fw_dump = fw_dump;
3427 ha->fw_dump_alloc_len = dump_size;
3428 ql_dbg(ql_dbg_init, vha, 0x00c5,
3429 "Re-Allocated (%d KB) and save firmware dump.\n",
3433 ha->fw_dump = fw_dump;
3435 ha->fw_dump_len = ha->fw_dump_alloc_len =
3437 ql_dbg(ql_dbg_init, vha, 0x00c5,
3438 "Allocated (%d KB) for firmware dump.\n",
3441 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3442 ha->mpi_fw_dump = (char *)fw_dump +
3443 ha->fwdt[1].dump_size;
3444 mutex_unlock(&ha->optrom_mutex);
3448 ha->fw_dump->signature[0] = 'Q';
3449 ha->fw_dump->signature[1] = 'L';
3450 ha->fw_dump->signature[2] = 'G';
3451 ha->fw_dump->signature[3] = 'C';
3452 ha->fw_dump->version = htonl(1);
3454 ha->fw_dump->fixed_size = htonl(fixed_size);
3455 ha->fw_dump->mem_size = htonl(mem_size);
3456 ha->fw_dump->req_q_size = htonl(req_q_size);
3457 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3459 ha->fw_dump->eft_size = htonl(eft_size);
3460 ha->fw_dump->eft_addr_l =
3461 htonl(LSD(ha->eft_dma));
3462 ha->fw_dump->eft_addr_h =
3463 htonl(MSD(ha->eft_dma));
3465 ha->fw_dump->header_size =
3467 (struct qla2xxx_fw_dump, isp));
3469 mutex_unlock(&ha->optrom_mutex);
3475 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3477 #define MPS_MASK 0xe0
3482 if (!IS_QLA81XX(vha->hw))
3485 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3486 if (rval != QLA_SUCCESS) {
3487 ql_log(ql_log_warn, vha, 0x0105,
3488 "Unable to acquire semaphore.\n");
3492 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3493 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3494 if (rval != QLA_SUCCESS) {
3495 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3500 if (dc == (dw & MPS_MASK))
3505 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3506 if (rval != QLA_SUCCESS) {
3507 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3511 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3512 if (rval != QLA_SUCCESS) {
3513 ql_log(ql_log_warn, vha, 0x006d,
3514 "Unable to release semaphore.\n");
3522 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3524 /* Don't try to reallocate the array */
3525 if (req->outstanding_cmds)
3528 if (!IS_FWI2_CAPABLE(ha))
3529 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3531 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3532 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3534 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3537 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3541 if (!req->outstanding_cmds) {
3543 * Try to allocate a minimal size just so we can get through
3546 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
3547 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3551 if (!req->outstanding_cmds) {
3552 ql_log(ql_log_fatal, NULL, 0x0126,
3553 "Failed to allocate memory for "
3554 "outstanding_cmds for req_que %p.\n", req);
3555 req->num_outstanding_cmds = 0;
3556 return QLA_FUNCTION_FAILED;
3563 #define PRINT_FIELD(_field, _flag, _str) { \
3564 if (a0->_field & _flag) {\
3570 len = snprintf(ptr, leftover, "%s", _str); \
3577 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
3580 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
3581 u8 str[STR_LEN], *ptr, p;
3584 memset(str, 0, STR_LEN);
3585 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
3586 ql_dbg(ql_dbg_init, vha, 0x015a,
3587 "SFP MFG Name: %s\n", str);
3589 memset(str, 0, STR_LEN);
3590 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
3591 ql_dbg(ql_dbg_init, vha, 0x015c,
3592 "SFP Part Name: %s\n", str);
3595 memset(str, 0, STR_LEN);
3599 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
3600 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
3601 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
3602 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
3603 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3604 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3605 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3606 ql_dbg(ql_dbg_init, vha, 0x0160,
3607 "SFP Media: %s\n", str);
3610 memset(str, 0, STR_LEN);
3614 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3615 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3616 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3617 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3618 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3619 ql_dbg(ql_dbg_init, vha, 0x0196,
3620 "SFP Link Length: %s\n", str);
3622 memset(str, 0, STR_LEN);
3626 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3627 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3628 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3629 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3630 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3631 ql_dbg(ql_dbg_init, vha, 0x016e,
3632 "SFP FC Link Tech: %s\n", str);
3635 ql_dbg(ql_dbg_init, vha, 0x016f,
3636 "SFP Distant: %d km\n", a0->length_km);
3637 if (a0->length_100m)
3638 ql_dbg(ql_dbg_init, vha, 0x0170,
3639 "SFP Distant: %d m\n", a0->length_100m*100);
3640 if (a0->length_50um_10m)
3641 ql_dbg(ql_dbg_init, vha, 0x0189,
3642 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3643 if (a0->length_62um_10m)
3644 ql_dbg(ql_dbg_init, vha, 0x018a,
3645 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3646 if (a0->length_om4_10m)
3647 ql_dbg(ql_dbg_init, vha, 0x0194,
3648 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3649 if (a0->length_om3_10m)
3650 ql_dbg(ql_dbg_init, vha, 0x0195,
3651 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3656 * qla24xx_detect_sfp()
3658 * @vha: adapter state pointer.
3661 * 0 -- Configure firmware to use short-range settings -- normal
3662 * buffer-to-buffer credits.
3664 * 1 -- Configure firmware to use long-range settings -- extra
3665 * buffer-to-buffer credits should be allocated with
3666 * ha->lr_distance containing distance settings from NVRAM or SFP
3670 qla24xx_detect_sfp(scsi_qla_host_t *vha)
3673 struct sff_8247_a0 *a;
3674 struct qla_hw_data *ha = vha->hw;
3675 struct nvram_81xx *nv = ha->nvram;
3676 #define LR_DISTANCE_UNKNOWN 2
3677 static const char * const types[] = { "Short", "Long" };
3678 static const char * const lengths[] = { "(10km)", "(5km)", "" };
3681 /* Seed with NVRAM settings. */
3683 ha->flags.lr_detected = 0;
3684 if (IS_BPM_RANGE_CAPABLE(ha) &&
3685 (nv->enhanced_features & NEF_LR_DIST_ENABLE)) {
3687 ha->flags.lr_detected = 1;
3689 (nv->enhanced_features >> LR_DIST_NV_POS)
3693 if (!IS_BPM_ENABLED(vha))
3695 /* Determine SR/LR capabilities of SFP/Transceiver. */
3696 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3701 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3702 qla2xxx_print_sfp_info(vha);
3704 ha->flags.lr_detected = 0;
3706 if (ll & FC_LL_VL || ll & FC_LL_L) {
3707 /* Long range, track length. */
3708 ha->flags.lr_detected = 1;
3710 if (a->length_km > 5 || a->length_100m > 50)
3711 ha->lr_distance = LR_DISTANCE_10K;
3713 ha->lr_distance = LR_DISTANCE_5K;
3717 ql_dbg(ql_dbg_async, vha, 0x507b,
3718 "SFP detect: %s-Range SFP %s (nvr=%x ll=%x lr=%x lrd=%x).\n",
3719 types[ha->flags.lr_detected],
3720 ha->flags.lr_detected ? lengths[ha->lr_distance] :
3721 lengths[LR_DISTANCE_UNKNOWN],
3722 used_nvram, ll, ha->flags.lr_detected, ha->lr_distance);
3723 return ha->flags.lr_detected;
3726 void qla_init_iocb_limit(scsi_qla_host_t *vha)
3730 struct qla_hw_data *ha = vha->hw;
3732 num_qps = ha->num_qpairs + 1;
3733 limit = (ha->orig_fw_iocb_count * QLA_IOCB_PCT_LIMIT) / 100;
3735 ha->base_qpair->fwres.iocbs_total = ha->orig_fw_iocb_count;
3736 ha->base_qpair->fwres.iocbs_limit = limit;
3737 ha->base_qpair->fwres.iocbs_qp_limit = limit / num_qps;
3738 ha->base_qpair->fwres.iocbs_used = 0;
3739 for (i = 0; i < ha->max_qpairs; i++) {
3740 if (ha->queue_pair_map[i]) {
3741 ha->queue_pair_map[i]->fwres.iocbs_total =
3742 ha->orig_fw_iocb_count;
3743 ha->queue_pair_map[i]->fwres.iocbs_limit = limit;
3744 ha->queue_pair_map[i]->fwres.iocbs_qp_limit =
3746 ha->queue_pair_map[i]->fwres.iocbs_used = 0;
3752 * qla2x00_setup_chip() - Load and start RISC firmware.
3755 * Returns 0 on success.
3758 qla2x00_setup_chip(scsi_qla_host_t *vha)
3761 uint32_t srisc_address = 0;
3762 struct qla_hw_data *ha = vha->hw;
3763 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3764 unsigned long flags;
3765 uint16_t fw_major_version;
3768 if (IS_P3P_TYPE(ha)) {
3769 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3770 if (rval == QLA_SUCCESS) {
3771 qla2x00_stop_firmware(vha);
3772 goto enable_82xx_npiv;
3777 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3778 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3779 spin_lock_irqsave(&ha->hardware_lock, flags);
3780 wrt_reg_word(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
3781 rd_reg_word(®->hccr);
3782 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3785 qla81xx_mpi_sync(vha);
3788 /* Load firmware sequences */
3789 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3790 if (rval == QLA_SUCCESS) {
3791 ql_dbg(ql_dbg_init, vha, 0x00c9,
3792 "Verifying Checksum of loaded RISC code.\n");
3794 rval = qla2x00_verify_checksum(vha, srisc_address);
3795 if (rval == QLA_SUCCESS) {
3796 /* Start firmware execution. */
3797 ql_dbg(ql_dbg_init, vha, 0x00ca,
3798 "Starting firmware.\n");
3801 ha->flags.exlogins_enabled = 1;
3803 if (qla_is_exch_offld_enabled(vha))
3804 ha->flags.exchoffld_enabled = 1;
3806 rval = qla2x00_execute_fw(vha, srisc_address);
3807 /* Retrieve firmware information. */
3808 if (rval == QLA_SUCCESS) {
3809 /* Enable BPM support? */
3810 if (!done_once++ && qla24xx_detect_sfp(vha)) {
3811 ql_dbg(ql_dbg_init, vha, 0x00ca,
3812 "Re-starting firmware -- BPM.\n");
3813 /* Best-effort - re-init. */
3814 ha->isp_ops->reset_chip(vha);
3815 ha->isp_ops->chip_diag(vha);
3816 goto execute_fw_with_lr;
3819 if (IS_ZIO_THRESHOLD_CAPABLE(ha))
3820 qla27xx_set_zio_threshold(vha,
3821 ha->last_zio_threshold);
3823 rval = qla2x00_set_exlogins_buffer(vha);
3824 if (rval != QLA_SUCCESS)
3827 rval = qla2x00_set_exchoffld_buffer(vha);
3828 if (rval != QLA_SUCCESS)
3832 fw_major_version = ha->fw_major_version;
3833 if (IS_P3P_TYPE(ha))
3834 qla82xx_check_md_needed(vha);
3836 rval = qla2x00_get_fw_version(vha);
3837 if (rval != QLA_SUCCESS)
3839 ha->flags.npiv_supported = 0;
3840 if (IS_QLA2XXX_MIDTYPE(ha) &&
3841 (ha->fw_attributes & BIT_2)) {
3842 ha->flags.npiv_supported = 1;
3843 if ((!ha->max_npiv_vports) ||
3844 ((ha->max_npiv_vports + 1) %
3845 MIN_MULTI_ID_FABRIC))
3846 ha->max_npiv_vports =
3847 MIN_MULTI_ID_FABRIC - 1;
3849 qla2x00_get_resource_cnts(vha);
3850 qla_init_iocb_limit(vha);
3853 * Allocate the array of outstanding commands
3854 * now that we know the firmware resources.
3856 rval = qla2x00_alloc_outstanding_cmds(ha,
3858 if (rval != QLA_SUCCESS)
3861 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
3862 qla2x00_alloc_offload_mem(vha);
3864 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
3865 qla2x00_alloc_fw_dump(vha);
3871 ql_log(ql_log_fatal, vha, 0x00cd,
3872 "ISP Firmware failed checksum.\n");
3876 /* Enable PUREX PASSTHRU */
3877 if (ql2xrdpenable || ha->flags.scm_supported_f)
3878 qla25xx_set_els_cmds_supported(vha);
3882 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3883 /* Enable proper parity. */
3884 spin_lock_irqsave(&ha->hardware_lock, flags);
3887 wrt_reg_word(®->hccr, HCCR_ENABLE_PARITY + 0x1);
3889 /* SRAM, Instruction RAM and GP RAM parity */
3890 wrt_reg_word(®->hccr, HCCR_ENABLE_PARITY + 0x7);
3891 rd_reg_word(®->hccr);
3892 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3895 if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
3896 ha->flags.fac_supported = 1;
3897 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
3900 rval = qla81xx_fac_get_sector_size(vha, &size);
3901 if (rval == QLA_SUCCESS) {
3902 ha->flags.fac_supported = 1;
3903 ha->fdt_block_size = size << 2;
3905 ql_log(ql_log_warn, vha, 0x00ce,
3906 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3907 ha->fw_major_version, ha->fw_minor_version,
3908 ha->fw_subminor_version);
3910 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3912 ha->flags.fac_supported = 0;
3919 ql_log(ql_log_fatal, vha, 0x00cf,
3920 "Setup chip ****FAILED****.\n");
3927 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3928 * @rsp: response queue
3930 * Beginning of request ring has initialization control block already built
3931 * by nvram config routine.
3933 * Returns 0 on success.
3936 qla2x00_init_response_q_entries(struct rsp_que *rsp)
3941 rsp->ring_ptr = rsp->ring;
3942 rsp->ring_index = 0;
3943 rsp->status_srb = NULL;
3944 pkt = rsp->ring_ptr;
3945 for (cnt = 0; cnt < rsp->length; cnt++) {
3946 pkt->signature = RESPONSE_PROCESSED;
3952 * qla2x00_update_fw_options() - Read and process firmware options.
3955 * Returns 0 on success.
3958 qla2x00_update_fw_options(scsi_qla_host_t *vha)
3960 uint16_t swing, emphasis, tx_sens, rx_sens;
3961 struct qla_hw_data *ha = vha->hw;
3963 memset(ha->fw_options, 0, sizeof(ha->fw_options));
3964 qla2x00_get_fw_options(vha, ha->fw_options);
3966 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3969 /* Serial Link options. */
3970 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3971 "Serial link options.\n");
3972 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3973 ha->fw_seriallink_options, sizeof(ha->fw_seriallink_options));
3975 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3976 if (ha->fw_seriallink_options[3] & BIT_2) {
3977 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3980 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3981 emphasis = (ha->fw_seriallink_options[2] &
3982 (BIT_4 | BIT_3)) >> 3;
3983 tx_sens = ha->fw_seriallink_options[0] &
3984 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3985 rx_sens = (ha->fw_seriallink_options[0] &
3986 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3987 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3988 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3991 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3992 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3993 ha->fw_options[10] |= BIT_5 |
3994 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3995 (tx_sens & (BIT_1 | BIT_0));
3998 swing = (ha->fw_seriallink_options[2] &
3999 (BIT_7 | BIT_6 | BIT_5)) >> 5;
4000 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
4001 tx_sens = ha->fw_seriallink_options[1] &
4002 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4003 rx_sens = (ha->fw_seriallink_options[1] &
4004 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
4005 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
4006 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
4009 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
4010 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
4011 ha->fw_options[11] |= BIT_5 |
4012 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
4013 (tx_sens & (BIT_1 | BIT_0));
4017 /* Return command IOCBs without waiting for an ABTS to complete. */
4018 ha->fw_options[3] |= BIT_13;
4021 if (ha->flags.enable_led_scheme)
4022 ha->fw_options[2] |= BIT_12;
4024 /* Detect ISP6312. */
4026 ha->fw_options[2] |= BIT_13;
4028 /* Set Retry FLOGI in case of P2P connection */
4029 if (ha->operating_mode == P2P) {
4030 ha->fw_options[2] |= BIT_3;
4031 ql_dbg(ql_dbg_disc, vha, 0x2100,
4032 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
4033 __func__, ha->fw_options[2]);
4036 /* Update firmware options. */
4037 qla2x00_set_fw_options(vha, ha->fw_options);
4041 qla24xx_update_fw_options(scsi_qla_host_t *vha)
4044 struct qla_hw_data *ha = vha->hw;
4046 if (IS_P3P_TYPE(ha))
4049 /* Hold status IOCBs until ABTS response received. */
4051 ha->fw_options[3] |= BIT_12;
4053 /* Set Retry FLOGI in case of P2P connection */
4054 if (ha->operating_mode == P2P) {
4055 ha->fw_options[2] |= BIT_3;
4056 ql_dbg(ql_dbg_disc, vha, 0x2101,
4057 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
4058 __func__, ha->fw_options[2]);
4061 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
4062 if (ql2xmvasynctoatio &&
4063 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
4064 if (qla_tgt_mode_enabled(vha) ||
4065 qla_dual_mode_enabled(vha))
4066 ha->fw_options[2] |= BIT_11;
4068 ha->fw_options[2] &= ~BIT_11;
4071 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4074 * Tell FW to track each exchange to prevent
4075 * driver from using stale exchange.
4077 if (qla_tgt_mode_enabled(vha) ||
4078 qla_dual_mode_enabled(vha))
4079 ha->fw_options[2] |= BIT_4;
4081 ha->fw_options[2] &= ~BIT_4;
4083 /* Reserve 1/2 of emergency exchanges for ELS.*/
4084 if (qla2xuseresexchforels)
4085 ha->fw_options[2] |= BIT_8;
4087 ha->fw_options[2] &= ~BIT_8;
4090 if (ql2xrdpenable || ha->flags.scm_supported_f)
4091 ha->fw_options[1] |= ADD_FO1_ENABLE_PUREX_IOCB;
4093 /* Enable Async 8130/8131 events -- transceiver insertion/removal */
4094 if (IS_BPM_RANGE_CAPABLE(ha))
4095 ha->fw_options[3] |= BIT_10;
4097 ql_dbg(ql_dbg_init, vha, 0x00e8,
4098 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
4099 __func__, ha->fw_options[1], ha->fw_options[2],
4100 ha->fw_options[3], vha->host->active_mode);
4102 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
4103 qla2x00_set_fw_options(vha, ha->fw_options);
4105 /* Update Serial Link options. */
4106 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
4109 rval = qla2x00_set_serdes_params(vha,
4110 le16_to_cpu(ha->fw_seriallink_options24[1]),
4111 le16_to_cpu(ha->fw_seriallink_options24[2]),
4112 le16_to_cpu(ha->fw_seriallink_options24[3]));
4113 if (rval != QLA_SUCCESS) {
4114 ql_log(ql_log_warn, vha, 0x0104,
4115 "Unable to update Serial Link options (%x).\n", rval);
4120 qla2x00_config_rings(struct scsi_qla_host *vha)
4122 struct qla_hw_data *ha = vha->hw;
4123 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4124 struct req_que *req = ha->req_q_map[0];
4125 struct rsp_que *rsp = ha->rsp_q_map[0];
4127 /* Setup ring parameters in initialization control block. */
4128 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
4129 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
4130 ha->init_cb->request_q_length = cpu_to_le16(req->length);
4131 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
4132 put_unaligned_le64(req->dma, &ha->init_cb->request_q_address);
4133 put_unaligned_le64(rsp->dma, &ha->init_cb->response_q_address);
4135 wrt_reg_word(ISP_REQ_Q_IN(ha, reg), 0);
4136 wrt_reg_word(ISP_REQ_Q_OUT(ha, reg), 0);
4137 wrt_reg_word(ISP_RSP_Q_IN(ha, reg), 0);
4138 wrt_reg_word(ISP_RSP_Q_OUT(ha, reg), 0);
4139 rd_reg_word(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
4143 qla24xx_config_rings(struct scsi_qla_host *vha)
4145 struct qla_hw_data *ha = vha->hw;
4146 device_reg_t *reg = ISP_QUE_REG(ha, 0);
4147 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
4148 struct qla_msix_entry *msix;
4149 struct init_cb_24xx *icb;
4151 struct req_que *req = ha->req_q_map[0];
4152 struct rsp_que *rsp = ha->rsp_q_map[0];
4154 /* Setup ring parameters in initialization control block. */
4155 icb = (struct init_cb_24xx *)ha->init_cb;
4156 icb->request_q_outpointer = cpu_to_le16(0);
4157 icb->response_q_inpointer = cpu_to_le16(0);
4158 icb->request_q_length = cpu_to_le16(req->length);
4159 icb->response_q_length = cpu_to_le16(rsp->length);
4160 put_unaligned_le64(req->dma, &icb->request_q_address);
4161 put_unaligned_le64(rsp->dma, &icb->response_q_address);
4163 /* Setup ATIO queue dma pointers for target mode */
4164 icb->atio_q_inpointer = cpu_to_le16(0);
4165 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
4166 put_unaligned_le64(ha->tgt.atio_dma, &icb->atio_q_address);
4168 if (IS_SHADOW_REG_CAPABLE(ha))
4169 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
4171 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4173 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
4174 icb->rid = cpu_to_le16(rid);
4175 if (ha->flags.msix_enabled) {
4176 msix = &ha->msix_entries[1];
4177 ql_dbg(ql_dbg_init, vha, 0x0019,
4178 "Registering vector 0x%x for base que.\n",
4180 icb->msix = cpu_to_le16(msix->entry);
4182 /* Use alternate PCI bus number */
4184 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
4185 /* Use alternate PCI devfn */
4187 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
4189 /* Use Disable MSIX Handshake mode for capable adapters */
4190 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
4191 (ha->flags.msix_enabled)) {
4192 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
4193 ha->flags.disable_msix_handshake = 1;
4194 ql_dbg(ql_dbg_init, vha, 0x00fe,
4195 "MSIX Handshake Disable Mode turned on.\n");
4197 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
4199 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
4201 wrt_reg_dword(®->isp25mq.req_q_in, 0);
4202 wrt_reg_dword(®->isp25mq.req_q_out, 0);
4203 wrt_reg_dword(®->isp25mq.rsp_q_in, 0);
4204 wrt_reg_dword(®->isp25mq.rsp_q_out, 0);
4206 wrt_reg_dword(®->isp24.req_q_in, 0);
4207 wrt_reg_dword(®->isp24.req_q_out, 0);
4208 wrt_reg_dword(®->isp24.rsp_q_in, 0);
4209 wrt_reg_dword(®->isp24.rsp_q_out, 0);
4212 qlt_24xx_config_rings(vha);
4214 /* If the user has configured the speed, set it here */
4215 if (ha->set_data_rate) {
4216 ql_dbg(ql_dbg_init, vha, 0x00fd,
4217 "Speed set by user : %s Gbps \n",
4218 qla2x00_get_link_speed_str(ha, ha->set_data_rate));
4219 icb->firmware_options_3 = cpu_to_le32(ha->set_data_rate << 13);
4223 rd_reg_word(&ioreg->hccr);
4227 * qla2x00_init_rings() - Initializes firmware.
4230 * Beginning of request ring has initialization control block already built
4231 * by nvram config routine.
4233 * Returns 0 on success.
4236 qla2x00_init_rings(scsi_qla_host_t *vha)
4239 unsigned long flags = 0;
4241 struct qla_hw_data *ha = vha->hw;
4242 struct req_que *req;
4243 struct rsp_que *rsp;
4244 struct mid_init_cb_24xx *mid_init_cb =
4245 (struct mid_init_cb_24xx *) ha->init_cb;
4247 spin_lock_irqsave(&ha->hardware_lock, flags);
4249 /* Clear outstanding commands array. */
4250 for (que = 0; que < ha->max_req_queues; que++) {
4251 req = ha->req_q_map[que];
4252 if (!req || !test_bit(que, ha->req_qid_map))
4254 req->out_ptr = (uint16_t *)(req->ring + req->length);
4256 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
4257 req->outstanding_cmds[cnt] = NULL;
4259 req->current_outstanding_cmd = 1;
4261 /* Initialize firmware. */
4262 req->ring_ptr = req->ring;
4263 req->ring_index = 0;
4264 req->cnt = req->length;
4267 for (que = 0; que < ha->max_rsp_queues; que++) {
4268 rsp = ha->rsp_q_map[que];
4269 if (!rsp || !test_bit(que, ha->rsp_qid_map))
4271 rsp->in_ptr = (uint16_t *)(rsp->ring + rsp->length);
4273 /* Initialize response queue entries */
4275 qlafx00_init_response_q_entries(rsp);
4277 qla2x00_init_response_q_entries(rsp);
4280 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
4281 ha->tgt.atio_ring_index = 0;
4282 /* Initialize ATIO queue entries */
4283 qlt_init_atio_q_entries(vha);
4285 ha->isp_ops->config_rings(vha);
4287 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4289 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
4291 if (IS_QLAFX00(ha)) {
4292 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
4296 /* Update any ISP specific firmware options before initialization. */
4297 ha->isp_ops->update_fw_options(vha);
4299 if (ha->flags.npiv_supported) {
4300 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
4301 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
4302 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
4305 if (IS_FWI2_CAPABLE(ha)) {
4306 mid_init_cb->options = cpu_to_le16(BIT_1);
4307 mid_init_cb->init_cb.execution_throttle =
4308 cpu_to_le16(ha->cur_fw_xcb_count);
4309 ha->flags.dport_enabled =
4310 (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) &
4312 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
4313 (ha->flags.dport_enabled) ? "enabled" : "disabled");
4314 /* FA-WWPN Status */
4315 ha->flags.fawwpn_enabled =
4316 (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) &
4318 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
4319 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
4322 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
4325 ql_log(ql_log_fatal, vha, 0x00d2,
4326 "Init Firmware **** FAILED ****.\n");
4328 ql_dbg(ql_dbg_init, vha, 0x00d3,
4329 "Init Firmware -- success.\n");
4331 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0;
4338 * qla2x00_fw_ready() - Waits for firmware ready.
4341 * Returns 0 on success.
4344 qla2x00_fw_ready(scsi_qla_host_t *vha)
4347 unsigned long wtime, mtime, cs84xx_time;
4348 uint16_t min_wait; /* Minimum wait time if loop is down */
4349 uint16_t wait_time; /* Wait time if loop is coming ready */
4351 struct qla_hw_data *ha = vha->hw;
4353 if (IS_QLAFX00(vha->hw))
4354 return qlafx00_fw_ready(vha);
4358 /* Time to wait for loop down */
4359 if (IS_P3P_TYPE(ha))
4365 * Firmware should take at most one RATOV to login, plus 5 seconds for
4366 * our own processing.
4368 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
4369 wait_time = min_wait;
4372 /* Min wait time if loop down */
4373 mtime = jiffies + (min_wait * HZ);
4375 /* wait time before firmware ready */
4376 wtime = jiffies + (wait_time * HZ);
4378 /* Wait for ISP to finish LIP */
4379 if (!vha->flags.init_done)
4380 ql_log(ql_log_info, vha, 0x801e,
4381 "Waiting for LIP to complete.\n");
4384 memset(state, -1, sizeof(state));
4385 rval = qla2x00_get_firmware_state(vha, state);
4386 if (rval == QLA_SUCCESS) {
4387 if (state[0] < FSTATE_LOSS_OF_SYNC) {
4388 vha->device_flags &= ~DFLG_NO_CABLE;
4390 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
4391 ql_dbg(ql_dbg_taskm, vha, 0x801f,
4392 "fw_state=%x 84xx=%x.\n", state[0],
4394 if ((state[2] & FSTATE_LOGGED_IN) &&
4395 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
4396 ql_dbg(ql_dbg_taskm, vha, 0x8028,
4397 "Sending verify iocb.\n");
4399 cs84xx_time = jiffies;
4400 rval = qla84xx_init_chip(vha);
4401 if (rval != QLA_SUCCESS) {
4404 "Init chip failed.\n");
4408 /* Add time taken to initialize. */
4409 cs84xx_time = jiffies - cs84xx_time;
4410 wtime += cs84xx_time;
4411 mtime += cs84xx_time;
4412 ql_dbg(ql_dbg_taskm, vha, 0x8008,
4413 "Increasing wait time by %ld. "
4414 "New time %ld.\n", cs84xx_time,
4417 } else if (state[0] == FSTATE_READY) {
4418 ql_dbg(ql_dbg_taskm, vha, 0x8037,
4419 "F/W Ready - OK.\n");
4421 qla2x00_get_retry_cnt(vha, &ha->retry_count,
4422 &ha->login_timeout, &ha->r_a_tov);
4428 rval = QLA_FUNCTION_FAILED;
4430 if (atomic_read(&vha->loop_down_timer) &&
4431 state[0] != FSTATE_READY) {
4432 /* Loop down. Timeout on min_wait for states
4433 * other than Wait for Login.
4435 if (time_after_eq(jiffies, mtime)) {
4436 ql_log(ql_log_info, vha, 0x8038,
4437 "Cable is unplugged...\n");
4439 vha->device_flags |= DFLG_NO_CABLE;
4444 /* Mailbox cmd failed. Timeout on min_wait. */
4445 if (time_after_eq(jiffies, mtime) ||
4446 ha->flags.isp82xx_fw_hung)
4450 if (time_after_eq(jiffies, wtime))
4453 /* Delay for a while */
4457 ql_dbg(ql_dbg_taskm, vha, 0x803a,
4458 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
4459 state[1], state[2], state[3], state[4], state[5], jiffies);
4461 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
4462 ql_log(ql_log_warn, vha, 0x803b,
4463 "Firmware ready **** FAILED ****.\n");
4470 * qla2x00_configure_hba
4471 * Setup adapter context.
4474 * ha = adapter state pointer.
4483 qla2x00_configure_hba(scsi_qla_host_t *vha)
4492 char connect_type[22];
4493 struct qla_hw_data *ha = vha->hw;
4494 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4496 unsigned long flags;
4498 /* Get host addresses. */
4499 rval = qla2x00_get_adapter_id(vha,
4500 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
4501 if (rval != QLA_SUCCESS) {
4502 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
4503 IS_CNA_CAPABLE(ha) ||
4504 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
4505 ql_dbg(ql_dbg_disc, vha, 0x2008,
4506 "Loop is in a transition state.\n");
4508 ql_log(ql_log_warn, vha, 0x2009,
4509 "Unable to get host loop ID.\n");
4510 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
4511 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
4512 ql_log(ql_log_warn, vha, 0x1151,
4513 "Doing link init.\n");
4514 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
4517 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4523 ql_log(ql_log_info, vha, 0x200a,
4524 "Cannot get topology - retrying.\n");
4525 return (QLA_FUNCTION_FAILED);
4528 vha->loop_id = loop_id;
4531 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
4532 ha->operating_mode = LOOP;
4537 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
4538 ha->current_topology = ISP_CFG_NL;
4539 strcpy(connect_type, "(Loop)");
4543 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
4544 ha->switch_cap = sw_cap;
4545 ha->current_topology = ISP_CFG_FL;
4546 strcpy(connect_type, "(FL_Port)");
4550 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
4551 ha->operating_mode = P2P;
4552 ha->current_topology = ISP_CFG_N;
4553 strcpy(connect_type, "(N_Port-to-N_Port)");
4557 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
4558 ha->switch_cap = sw_cap;
4559 ha->operating_mode = P2P;
4560 ha->current_topology = ISP_CFG_F;
4561 strcpy(connect_type, "(F_Port)");
4565 ql_dbg(ql_dbg_disc, vha, 0x200f,
4566 "HBA in unknown topology %x, using NL.\n", topo);
4567 ha->current_topology = ISP_CFG_NL;
4568 strcpy(connect_type, "(Loop)");
4572 /* Save Host port and loop ID. */
4573 /* byte order - Big Endian */
4574 id.b.domain = domain;
4578 spin_lock_irqsave(&ha->hardware_lock, flags);
4579 if (!(topo == 2 && ha->flags.n2n_bigger))
4580 qlt_update_host_map(vha, id);
4581 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4583 if (!vha->flags.init_done)
4584 ql_log(ql_log_info, vha, 0x2010,
4585 "Topology - %s, Host Loop address 0x%x.\n",
4586 connect_type, vha->loop_id);
4592 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
4597 uint64_t zero[2] = { 0 };
4598 struct qla_hw_data *ha = vha->hw;
4599 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
4600 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
4602 if (len > sizeof(zero))
4604 if (memcmp(model, &zero, len) != 0) {
4605 memcpy(ha->model_number, model, len);
4606 st = en = ha->model_number;
4609 if (*en != 0x20 && *en != 0x00)
4614 index = (ha->pdev->subsystem_device & 0xff);
4616 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4617 index < QLA_MODEL_NAMES)
4618 strlcpy(ha->model_desc,
4619 qla2x00_model_name[index * 2 + 1],
4620 sizeof(ha->model_desc));
4622 index = (ha->pdev->subsystem_device & 0xff);
4624 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4625 index < QLA_MODEL_NAMES) {
4626 strlcpy(ha->model_number,
4627 qla2x00_model_name[index * 2],
4628 sizeof(ha->model_number));
4629 strlcpy(ha->model_desc,
4630 qla2x00_model_name[index * 2 + 1],
4631 sizeof(ha->model_desc));
4633 strlcpy(ha->model_number, def,
4634 sizeof(ha->model_number));
4637 if (IS_FWI2_CAPABLE(ha))
4638 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
4639 sizeof(ha->model_desc));
4642 /* On sparc systems, obtain port and node WWN from firmware
4645 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4648 struct qla_hw_data *ha = vha->hw;
4649 struct pci_dev *pdev = ha->pdev;
4650 struct device_node *dp = pci_device_to_OF_node(pdev);
4654 val = of_get_property(dp, "port-wwn", &len);
4655 if (val && len >= WWN_SIZE)
4656 memcpy(nv->port_name, val, WWN_SIZE);
4658 val = of_get_property(dp, "node-wwn", &len);
4659 if (val && len >= WWN_SIZE)
4660 memcpy(nv->node_name, val, WWN_SIZE);
4665 * NVRAM configuration for ISP 2xxx
4668 * ha = adapter block pointer.
4671 * initialization control block in response_ring
4672 * host adapters parameters in host adapter block
4678 qla2x00_nvram_config(scsi_qla_host_t *vha)
4683 uint8_t *dptr1, *dptr2;
4684 struct qla_hw_data *ha = vha->hw;
4685 init_cb_t *icb = ha->init_cb;
4686 nvram_t *nv = ha->nvram;
4687 uint8_t *ptr = ha->nvram;
4688 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4692 /* Determine NVRAM starting address. */
4693 ha->nvram_size = sizeof(*nv);
4695 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4696 if ((rd_reg_word(®->ctrl_status) >> 14) == 1)
4697 ha->nvram_base = 0x80;
4699 /* Get NVRAM data and calculate checksum. */
4700 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
4701 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4704 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4705 "Contents of NVRAM.\n");
4706 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4707 nv, ha->nvram_size);
4709 /* Bad NVRAM data, set defaults parameters. */
4710 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
4711 nv->nvram_version < 1) {
4712 /* Reset NVRAM data. */
4713 ql_log(ql_log_warn, vha, 0x0064,
4714 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
4715 chksum, nv->id, nv->nvram_version);
4716 ql_log(ql_log_warn, vha, 0x0065,
4718 "functioning (yet invalid -- WWPN) defaults.\n");
4721 * Set default initialization control block.
4723 memset(nv, 0, ha->nvram_size);
4724 nv->parameter_block_version = ICB_VERSION;
4726 if (IS_QLA23XX(ha)) {
4727 nv->firmware_options[0] = BIT_2 | BIT_1;
4728 nv->firmware_options[1] = BIT_7 | BIT_5;
4729 nv->add_firmware_options[0] = BIT_5;
4730 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4731 nv->frame_payload_size = cpu_to_le16(2048);
4732 nv->special_options[1] = BIT_7;
4733 } else if (IS_QLA2200(ha)) {
4734 nv->firmware_options[0] = BIT_2 | BIT_1;
4735 nv->firmware_options[1] = BIT_7 | BIT_5;
4736 nv->add_firmware_options[0] = BIT_5;
4737 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4738 nv->frame_payload_size = cpu_to_le16(1024);
4739 } else if (IS_QLA2100(ha)) {
4740 nv->firmware_options[0] = BIT_3 | BIT_1;
4741 nv->firmware_options[1] = BIT_5;
4742 nv->frame_payload_size = cpu_to_le16(1024);
4745 nv->max_iocb_allocation = cpu_to_le16(256);
4746 nv->execution_throttle = cpu_to_le16(16);
4747 nv->retry_count = 8;
4748 nv->retry_delay = 1;
4750 nv->port_name[0] = 33;
4751 nv->port_name[3] = 224;
4752 nv->port_name[4] = 139;
4754 qla2xxx_nvram_wwn_from_ofw(vha, nv);
4756 nv->login_timeout = 4;
4759 * Set default host adapter parameters
4761 nv->host_p[1] = BIT_2;
4762 nv->reset_delay = 5;
4763 nv->port_down_retry_count = 8;
4764 nv->max_luns_per_target = cpu_to_le16(8);
4765 nv->link_down_timeout = 60;
4770 /* Reset Initialization control block */
4771 memset(icb, 0, ha->init_cb_size);
4774 * Setup driver NVRAM options.
4776 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4777 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4778 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4779 nv->firmware_options[1] &= ~BIT_4;
4781 if (IS_QLA23XX(ha)) {
4782 nv->firmware_options[0] |= BIT_2;
4783 nv->firmware_options[0] &= ~BIT_3;
4784 nv->special_options[0] &= ~BIT_6;
4785 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
4787 if (IS_QLA2300(ha)) {
4788 if (ha->fb_rev == FPM_2310) {
4789 strcpy(ha->model_number, "QLA2310");
4791 strcpy(ha->model_number, "QLA2300");
4794 qla2x00_set_model_info(vha, nv->model_number,
4795 sizeof(nv->model_number), "QLA23xx");
4797 } else if (IS_QLA2200(ha)) {
4798 nv->firmware_options[0] |= BIT_2;
4800 * 'Point-to-point preferred, else loop' is not a safe
4801 * connection mode setting.
4803 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4805 /* Force 'loop preferred, else point-to-point'. */
4806 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4807 nv->add_firmware_options[0] |= BIT_5;
4809 strcpy(ha->model_number, "QLA22xx");
4810 } else /*if (IS_QLA2100(ha))*/ {
4811 strcpy(ha->model_number, "QLA2100");
4815 * Copy over NVRAM RISC parameter block to initialization control block.
4817 dptr1 = (uint8_t *)icb;
4818 dptr2 = (uint8_t *)&nv->parameter_block_version;
4819 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4821 *dptr1++ = *dptr2++;
4823 /* Copy 2nd half. */
4824 dptr1 = (uint8_t *)icb->add_firmware_options;
4825 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4827 *dptr1++ = *dptr2++;
4828 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
4829 /* Use alternate WWN? */
4830 if (nv->host_p[1] & BIT_7) {
4831 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4832 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4835 /* Prepare nodename */
4836 if ((icb->firmware_options[1] & BIT_6) == 0) {
4838 * Firmware will apply the following mask if the nodename was
4841 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4842 icb->node_name[0] &= 0xF0;
4846 * Set host adapter parameters.
4850 * BIT_7 in the host-parameters section allows for modification to
4851 * internal driver logging.
4853 if (nv->host_p[0] & BIT_7)
4854 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
4855 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4856 /* Always load RISC code on non ISP2[12]00 chips. */
4857 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4858 ha->flags.disable_risc_code_load = 0;
4859 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4860 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4861 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
4862 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
4863 ha->flags.disable_serdes = 0;
4865 ha->operating_mode =
4866 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4868 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4869 sizeof(ha->fw_seriallink_options));
4871 /* save HBA serial number */
4872 ha->serial0 = icb->port_name[5];
4873 ha->serial1 = icb->port_name[6];
4874 ha->serial2 = icb->port_name[7];
4875 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4876 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4878 icb->execution_throttle = cpu_to_le16(0xFFFF);
4880 ha->retry_count = nv->retry_count;
4882 /* Set minimum login_timeout to 4 seconds. */
4883 if (nv->login_timeout != ql2xlogintimeout)
4884 nv->login_timeout = ql2xlogintimeout;
4885 if (nv->login_timeout < 4)
4886 nv->login_timeout = 4;
4887 ha->login_timeout = nv->login_timeout;
4889 /* Set minimum RATOV to 100 tenths of a second. */
4892 ha->loop_reset_delay = nv->reset_delay;
4894 /* Link Down Timeout = 0:
4896 * When Port Down timer expires we will start returning
4897 * I/O's to OS with "DID_NO_CONNECT".
4899 * Link Down Timeout != 0:
4901 * The driver waits for the link to come up after link down
4902 * before returning I/Os to OS with "DID_NO_CONNECT".
4904 if (nv->link_down_timeout == 0) {
4905 ha->loop_down_abort_time =
4906 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4908 ha->link_down_timeout = nv->link_down_timeout;
4909 ha->loop_down_abort_time =
4910 (LOOP_DOWN_TIME - ha->link_down_timeout);
4914 * Need enough time to try and get the port back.
4916 ha->port_down_retry_count = nv->port_down_retry_count;
4917 if (qlport_down_retry)
4918 ha->port_down_retry_count = qlport_down_retry;
4919 /* Set login_retry_count */
4920 ha->login_retry_count = nv->retry_count;
4921 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4922 ha->port_down_retry_count > 3)
4923 ha->login_retry_count = ha->port_down_retry_count;
4924 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4925 ha->login_retry_count = ha->port_down_retry_count;
4926 if (ql2xloginretrycount)
4927 ha->login_retry_count = ql2xloginretrycount;
4929 icb->lun_enables = cpu_to_le16(0);
4930 icb->command_resource_count = 0;
4931 icb->immediate_notify_resource_count = 0;
4932 icb->timeout = cpu_to_le16(0);
4934 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4936 icb->firmware_options[0] &= ~BIT_3;
4937 icb->add_firmware_options[0] &=
4938 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4939 icb->add_firmware_options[0] |= BIT_2;
4940 icb->response_accumulation_timer = 3;
4941 icb->interrupt_delay_timer = 5;
4943 vha->flags.process_response_queue = 1;
4946 if (!vha->flags.init_done) {
4947 ha->zio_mode = icb->add_firmware_options[0] &
4948 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4949 ha->zio_timer = icb->interrupt_delay_timer ?
4950 icb->interrupt_delay_timer : 2;
4952 icb->add_firmware_options[0] &=
4953 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4954 vha->flags.process_response_queue = 0;
4955 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4956 ha->zio_mode = QLA_ZIO_MODE_6;
4958 ql_log(ql_log_info, vha, 0x0068,
4959 "ZIO mode %d enabled; timer delay (%d us).\n",
4960 ha->zio_mode, ha->zio_timer * 100);
4962 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4963 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
4964 vha->flags.process_response_queue = 1;
4969 ql_log(ql_log_warn, vha, 0x0069,
4970 "NVRAM configuration failed.\n");
4976 qla2x00_rport_del(void *data)
4978 fc_port_t *fcport = data;
4979 struct fc_rport *rport;
4980 unsigned long flags;
4982 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
4983 rport = fcport->drport ? fcport->drport : fcport->rport;
4984 fcport->drport = NULL;
4985 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
4987 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4988 "%s %8phN. rport %p roles %x\n",
4989 __func__, fcport->port_name, rport,
4992 fc_remote_port_delete(rport);
4996 void qla2x00_set_fcport_state(fc_port_t *fcport, int state)
5000 old_state = atomic_read(&fcport->state);
5001 atomic_set(&fcport->state, state);
5003 /* Don't print state transitions during initial allocation of fcport */
5004 if (old_state && old_state != state) {
5005 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
5006 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
5007 fcport->port_name, port_state_str[old_state],
5008 port_state_str[state], fcport->d_id.b.domain,
5009 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5014 * qla2x00_alloc_fcport() - Allocate a generic fcport.
5016 * @flags: allocation flags
5018 * Returns a pointer to the allocated fcport, or NULL, if none available.
5021 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
5025 fcport = kzalloc(sizeof(fc_port_t), flags);
5029 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
5030 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
5032 if (!fcport->ct_desc.ct_sns) {
5033 ql_log(ql_log_warn, vha, 0xd049,
5034 "Failed to allocate ct_sns request.\n");
5039 /* Setup fcport template structure. */
5041 fcport->port_type = FCT_UNKNOWN;
5042 fcport->loop_id = FC_NO_LOOP_ID;
5043 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
5044 fcport->supported_classes = FC_COS_UNSPECIFIED;
5045 fcport->fp_speed = PORT_SPEED_UNKNOWN;
5047 fcport->disc_state = DSC_DELETED;
5048 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
5049 fcport->deleted = QLA_SESS_DELETED;
5050 fcport->login_retry = vha->hw->login_retry_count;
5051 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
5052 fcport->logout_on_delete = 1;
5053 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
5054 fcport->tgt_short_link_down_cnt = 0;
5055 fcport->dev_loss_tmo = 0;
5057 if (!fcport->ct_desc.ct_sns) {
5058 ql_log(ql_log_warn, vha, 0xd049,
5059 "Failed to allocate ct_sns request.\n");
5064 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
5065 INIT_WORK(&fcport->free_work, qlt_free_session_done);
5066 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
5067 INIT_LIST_HEAD(&fcport->gnl_entry);
5068 INIT_LIST_HEAD(&fcport->list);
5070 INIT_LIST_HEAD(&fcport->sess_cmd_list);
5071 spin_lock_init(&fcport->sess_cmd_lock);
5077 qla2x00_free_fcport(fc_port_t *fcport)
5079 if (fcport->ct_desc.ct_sns) {
5080 dma_free_coherent(&fcport->vha->hw->pdev->dev,
5081 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
5082 fcport->ct_desc.ct_sns_dma);
5084 fcport->ct_desc.ct_sns = NULL;
5086 list_del(&fcport->list);
5087 qla2x00_clear_loop_id(fcport);
5091 static void qla_get_login_template(scsi_qla_host_t *vha)
5093 struct qla_hw_data *ha = vha->hw;
5098 memset(ha->init_cb, 0, ha->init_cb_size);
5099 sz = min_t(int, sizeof(struct fc_els_flogi), ha->init_cb_size);
5100 rval = qla24xx_get_port_login_templ(vha, ha->init_cb_dma,
5102 if (rval != QLA_SUCCESS) {
5103 ql_dbg(ql_dbg_init, vha, 0x00d1,
5104 "PLOGI ELS param read fail.\n");
5107 q = (__be32 *)&ha->plogi_els_payld.fl_csp;
5109 bp = (uint32_t *)ha->init_cb;
5110 cpu_to_be32_array(q, bp, sz / 4);
5111 ha->flags.plogi_template_valid = 1;
5115 * qla2x00_configure_loop
5116 * Updates Fibre Channel Device Database with what is actually on loop.
5119 * ha = adapter block pointer.
5124 * 2 = database was full and device was not configured.
5127 qla2x00_configure_loop(scsi_qla_host_t *vha)
5130 unsigned long flags, save_flags;
5131 struct qla_hw_data *ha = vha->hw;
5135 /* Get Initiator ID */
5136 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
5137 rval = qla2x00_configure_hba(vha);
5138 if (rval != QLA_SUCCESS) {
5139 ql_dbg(ql_dbg_disc, vha, 0x2013,
5140 "Unable to configure HBA.\n");
5145 save_flags = flags = vha->dpc_flags;
5146 ql_dbg(ql_dbg_disc, vha, 0x2014,
5147 "Configure loop -- dpc flags = 0x%lx.\n", flags);
5150 * If we have both an RSCN and PORT UPDATE pending then handle them
5151 * both at the same time.
5153 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5154 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
5156 qla2x00_get_data_rate(vha);
5157 qla_get_login_template(vha);
5159 /* Determine what we need to do */
5160 if ((ha->current_topology == ISP_CFG_FL ||
5161 ha->current_topology == ISP_CFG_F) &&
5162 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
5164 set_bit(RSCN_UPDATE, &flags);
5165 clear_bit(LOCAL_LOOP_UPDATE, &flags);
5167 } else if (ha->current_topology == ISP_CFG_NL ||
5168 ha->current_topology == ISP_CFG_N) {
5169 clear_bit(RSCN_UPDATE, &flags);
5170 set_bit(LOCAL_LOOP_UPDATE, &flags);
5171 } else if (!vha->flags.online ||
5172 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
5173 set_bit(RSCN_UPDATE, &flags);
5174 set_bit(LOCAL_LOOP_UPDATE, &flags);
5177 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
5178 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5179 ql_dbg(ql_dbg_disc, vha, 0x2015,
5180 "Loop resync needed, failing.\n");
5181 rval = QLA_FUNCTION_FAILED;
5183 rval = qla2x00_configure_local_loop(vha);
5186 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
5187 if (LOOP_TRANSITION(vha)) {
5188 ql_dbg(ql_dbg_disc, vha, 0x2099,
5189 "Needs RSCN update and loop transition.\n");
5190 rval = QLA_FUNCTION_FAILED;
5193 rval = qla2x00_configure_fabric(vha);
5196 if (rval == QLA_SUCCESS) {
5197 if (atomic_read(&vha->loop_down_timer) ||
5198 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5199 rval = QLA_FUNCTION_FAILED;
5201 atomic_set(&vha->loop_state, LOOP_READY);
5202 ql_dbg(ql_dbg_disc, vha, 0x2069,
5204 ha->flags.fw_init_done = 1;
5207 * Process any ATIO queue entries that came in
5208 * while we weren't online.
5210 if (qla_tgt_mode_enabled(vha) ||
5211 qla_dual_mode_enabled(vha)) {
5212 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
5213 qlt_24xx_process_atio_queue(vha, 0);
5214 spin_unlock_irqrestore(&ha->tgt.atio_lock,
5221 ql_dbg(ql_dbg_disc, vha, 0x206a,
5222 "%s *** FAILED ***.\n", __func__);
5224 ql_dbg(ql_dbg_disc, vha, 0x206b,
5225 "%s: exiting normally.\n", __func__);
5228 /* Restore state if a resync event occurred during processing */
5229 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5230 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
5231 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5232 if (test_bit(RSCN_UPDATE, &save_flags)) {
5233 set_bit(RSCN_UPDATE, &vha->dpc_flags);
5240 static int qla2x00_configure_n2n_loop(scsi_qla_host_t *vha)
5242 unsigned long flags;
5245 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags))
5246 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5248 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5249 if (fcport->n2n_flag) {
5250 qla24xx_fcport_handle_login(vha, fcport);
5255 spin_lock_irqsave(&vha->work_lock, flags);
5256 vha->scan.scan_retry++;
5257 spin_unlock_irqrestore(&vha->work_lock, flags);
5259 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5260 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5261 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5263 return QLA_FUNCTION_FAILED;
5267 * qla2x00_configure_local_loop
5268 * Updates Fibre Channel Device Database with local loop devices.
5271 * ha = adapter block pointer.
5277 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
5282 fc_port_t *fcport, *new_fcport;
5285 struct gid_list_info *gid;
5287 uint8_t domain, area, al_pa;
5288 struct qla_hw_data *ha = vha->hw;
5289 unsigned long flags;
5291 /* Inititae N2N login. */
5293 return qla2x00_configure_n2n_loop(vha);
5297 entries = MAX_FIBRE_DEVICES_LOOP;
5299 /* Get list of logged in devices. */
5300 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
5301 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
5303 if (rval != QLA_SUCCESS)
5306 ql_dbg(ql_dbg_disc, vha, 0x2011,
5307 "Entries in ID list (%d).\n", entries);
5308 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
5309 ha->gid_list, entries * sizeof(*ha->gid_list));
5312 spin_lock_irqsave(&vha->work_lock, flags);
5313 vha->scan.scan_retry++;
5314 spin_unlock_irqrestore(&vha->work_lock, flags);
5316 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5317 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5318 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5321 vha->scan.scan_retry = 0;
5324 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5325 fcport->scan_state = QLA_FCPORT_SCAN;
5328 /* Allocate temporary fcport for any new fcports discovered. */
5329 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5330 if (new_fcport == NULL) {
5331 ql_log(ql_log_warn, vha, 0x2012,
5332 "Memory allocation failed for fcport.\n");
5333 rval = QLA_MEMORY_ALLOC_FAILED;
5336 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5338 /* Add devices to port list. */
5340 for (index = 0; index < entries; index++) {
5341 domain = gid->domain;
5344 if (IS_QLA2100(ha) || IS_QLA2200(ha))
5345 loop_id = gid->loop_id_2100;
5347 loop_id = le16_to_cpu(gid->loop_id);
5348 gid = (void *)gid + ha->gid_list_info_size;
5350 /* Bypass reserved domain fields. */
5351 if ((domain & 0xf0) == 0xf0)
5354 /* Bypass if not same domain and area of adapter. */
5355 if (area && domain && ((area != vha->d_id.b.area) ||
5356 (domain != vha->d_id.b.domain)) &&
5357 (ha->current_topology == ISP_CFG_NL))
5361 /* Bypass invalid local loop ID. */
5362 if (loop_id > LAST_LOCAL_LOOP_ID)
5365 memset(new_fcport->port_name, 0, WWN_SIZE);
5367 /* Fill in member data. */
5368 new_fcport->d_id.b.domain = domain;
5369 new_fcport->d_id.b.area = area;
5370 new_fcport->d_id.b.al_pa = al_pa;
5371 new_fcport->loop_id = loop_id;
5372 new_fcport->scan_state = QLA_FCPORT_FOUND;
5374 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
5375 if (rval2 != QLA_SUCCESS) {
5376 ql_dbg(ql_dbg_disc, vha, 0x2097,
5377 "Failed to retrieve fcport information "
5378 "-- get_port_database=%x, loop_id=0x%04x.\n",
5379 rval2, new_fcport->loop_id);
5380 /* Skip retry if N2N */
5381 if (ha->current_topology != ISP_CFG_N) {
5382 ql_dbg(ql_dbg_disc, vha, 0x2105,
5383 "Scheduling resync.\n");
5384 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5389 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5390 /* Check for matching device in port list. */
5393 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5394 if (memcmp(new_fcport->port_name, fcport->port_name,
5398 fcport->flags &= ~FCF_FABRIC_DEVICE;
5399 fcport->loop_id = new_fcport->loop_id;
5400 fcport->port_type = new_fcport->port_type;
5401 fcport->d_id.b24 = new_fcport->d_id.b24;
5402 memcpy(fcport->node_name, new_fcport->node_name,
5404 fcport->scan_state = QLA_FCPORT_FOUND;
5410 /* New device, add to fcports list. */
5411 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5413 /* Allocate a new replacement fcport. */
5414 fcport = new_fcport;
5416 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5418 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5420 if (new_fcport == NULL) {
5421 ql_log(ql_log_warn, vha, 0xd031,
5422 "Failed to allocate memory for fcport.\n");
5423 rval = QLA_MEMORY_ALLOC_FAILED;
5426 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5427 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5430 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5432 /* Base iIDMA settings on HBA port speed. */
5433 fcport->fp_speed = ha->link_data_rate;
5438 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5439 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5442 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5443 if ((qla_dual_mode_enabled(vha) ||
5444 qla_ini_mode_enabled(vha)) &&
5445 atomic_read(&fcport->state) == FCS_ONLINE) {
5446 qla2x00_mark_device_lost(vha, fcport,
5447 ql2xplogiabsentdevice);
5448 if (fcport->loop_id != FC_NO_LOOP_ID &&
5449 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5450 fcport->port_type != FCT_INITIATOR &&
5451 fcport->port_type != FCT_BROADCAST) {
5452 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5453 "%s %d %8phC post del sess\n",
5457 qlt_schedule_sess_for_deletion(fcport);
5463 if (fcport->scan_state == QLA_FCPORT_FOUND)
5464 qla24xx_fcport_handle_login(vha, fcport);
5467 qla2x00_free_fcport(new_fcport);
5472 ql_dbg(ql_dbg_disc, vha, 0x2098,
5473 "Configure local loop error exit: rval=%x.\n", rval);
5478 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5481 uint16_t mb[MAILBOX_REGISTER_COUNT];
5482 struct qla_hw_data *ha = vha->hw;
5484 if (!IS_IIDMA_CAPABLE(ha))
5487 if (atomic_read(&fcport->state) != FCS_ONLINE)
5490 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
5491 fcport->fp_speed > ha->link_data_rate ||
5492 !ha->flags.gpsc_supported)
5495 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
5497 if (rval != QLA_SUCCESS) {
5498 ql_dbg(ql_dbg_disc, vha, 0x2004,
5499 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5500 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
5502 ql_dbg(ql_dbg_disc, vha, 0x2005,
5503 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5504 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
5505 fcport->fp_speed, fcport->port_name);
5509 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5511 qla2x00_iidma_fcport(vha, fcport);
5512 qla24xx_update_fcport_fcp_prio(vha, fcport);
5515 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5517 struct qla_work_evt *e;
5519 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
5521 return QLA_FUNCTION_FAILED;
5523 e->u.fcport.fcport = fcport;
5524 return qla2x00_post_work(vha, e);
5527 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5529 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
5531 struct fc_rport_identifiers rport_ids;
5532 struct fc_rport *rport;
5533 unsigned long flags;
5535 if (atomic_read(&fcport->state) == FCS_ONLINE)
5538 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5539 rport_ids.port_name = wwn_to_u64(fcport->port_name);
5540 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5541 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5542 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5543 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
5545 ql_log(ql_log_warn, vha, 0x2006,
5546 "Unable to allocate fc remote port.\n");
5550 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5551 *((fc_port_t **)rport->dd_data) = fcport;
5552 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5553 fcport->dev_loss_tmo = rport->dev_loss_tmo;
5555 rport->supported_classes = fcport->supported_classes;
5557 rport_ids.roles = FC_PORT_ROLE_UNKNOWN;
5558 if (fcport->port_type == FCT_INITIATOR)
5559 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
5560 if (fcport->port_type == FCT_TARGET)
5561 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
5562 if (fcport->port_type & FCT_NVME_INITIATOR)
5563 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
5564 if (fcport->port_type & FCT_NVME_TARGET)
5565 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
5566 if (fcport->port_type & FCT_NVME_DISCOVERY)
5567 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
5569 fc_remote_port_rolechg(rport, rport_ids.roles);
5571 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5572 "%s: %8phN. rport %ld:0:%d (%p) is %s mode\n",
5573 __func__, fcport->port_name, vha->host_no,
5574 rport->scsi_target_id, rport,
5575 (fcport->port_type == FCT_TARGET) ? "tgt" :
5576 ((fcport->port_type & FCT_NVME) ? "nvme" : "ini"));
5580 * qla2x00_update_fcport
5581 * Updates device on list.
5584 * ha = adapter block pointer.
5585 * fcport = port structure pointer.
5595 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5597 if (IS_SW_RESV_ADDR(fcport->d_id))
5600 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
5601 __func__, fcport->port_name);
5603 qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT);
5604 fcport->login_retry = vha->hw->login_retry_count;
5605 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5606 fcport->deleted = 0;
5607 if (vha->hw->current_topology == ISP_CFG_NL)
5608 fcport->logout_on_delete = 0;
5610 fcport->logout_on_delete = 1;
5611 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
5613 if (fcport->tgt_link_down_time < fcport->dev_loss_tmo) {
5614 fcport->tgt_short_link_down_cnt++;
5615 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
5618 switch (vha->hw->current_topology) {
5621 fcport->keep_nport_handle = 1;
5627 qla2x00_iidma_fcport(vha, fcport);
5629 qla2x00_dfs_create_rport(vha, fcport);
5631 if (NVME_TARGET(vha->hw, fcport)) {
5632 qla_nvme_register_remote(vha, fcport);
5633 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
5634 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5638 qla24xx_update_fcport_fcp_prio(vha, fcport);
5640 switch (vha->host->active_mode) {
5641 case MODE_INITIATOR:
5642 qla2x00_reg_remote_port(vha, fcport);
5645 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5646 !vha->vha_tgt.qla_tgt->tgt_stopped)
5647 qlt_fc_port_added(vha, fcport);
5650 qla2x00_reg_remote_port(vha, fcport);
5651 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5652 !vha->vha_tgt.qla_tgt->tgt_stopped)
5653 qlt_fc_port_added(vha, fcport);
5659 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5661 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
5662 if (fcport->id_changed) {
5663 fcport->id_changed = 0;
5664 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5665 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5666 __func__, __LINE__, fcport->port_name,
5668 qla24xx_post_gfpnid_work(vha, fcport);
5670 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5671 "%s %d %8phC post gpsc fcp_cnt %d\n",
5672 __func__, __LINE__, fcport->port_name,
5674 qla24xx_post_gpsc_work(vha, fcport);
5678 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
5681 void qla_register_fcport_fn(struct work_struct *work)
5683 fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
5684 u32 rscn_gen = fcport->rscn_gen;
5687 if (IS_SW_RESV_ADDR(fcport->d_id))
5690 qla2x00_update_fcport(fcport->vha, fcport);
5692 if (rscn_gen != fcport->rscn_gen) {
5693 /* RSCN(s) came in while registration */
5694 switch (fcport->next_disc_state) {
5695 case DSC_DELETE_PEND:
5696 qlt_schedule_sess_for_deletion(fcport);
5699 data[0] = data[1] = 0;
5700 qla2x00_post_async_adisc_work(fcport->vha, fcport,
5710 * qla2x00_configure_fabric
5711 * Setup SNS devices with loop ID's.
5714 * ha = adapter block pointer.
5721 qla2x00_configure_fabric(scsi_qla_host_t *vha)
5725 uint16_t mb[MAILBOX_REGISTER_COUNT];
5727 LIST_HEAD(new_fcports);
5728 struct qla_hw_data *ha = vha->hw;
5731 /* If FL port exists, then SNS is present */
5732 if (IS_FWI2_CAPABLE(ha))
5733 loop_id = NPH_F_PORT;
5735 loop_id = SNS_FL_PORT;
5736 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
5737 if (rval != QLA_SUCCESS) {
5738 ql_dbg(ql_dbg_disc, vha, 0x20a0,
5739 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5741 vha->device_flags &= ~SWITCH_FOUND;
5742 return (QLA_SUCCESS);
5744 vha->device_flags |= SWITCH_FOUND;
5746 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_port_name, 0);
5747 if (rval != QLA_SUCCESS)
5748 ql_dbg(ql_dbg_disc, vha, 0x20ff,
5749 "Failed to get Fabric Port Name\n");
5751 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
5752 rval = qla2x00_send_change_request(vha, 0x3, 0);
5753 if (rval != QLA_SUCCESS)
5754 ql_log(ql_log_warn, vha, 0x121,
5755 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5760 qla2x00_mgmt_svr_login(vha);
5762 /* Ensure we are logged into the SNS. */
5763 loop_id = NPH_SNS_LID(ha);
5764 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5765 0xfc, mb, BIT_1|BIT_0);
5766 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5767 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5768 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5769 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
5770 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5775 if (ql2xfdmienable &&
5776 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5777 qla2x00_fdmi_register(vha);
5779 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5780 if (qla2x00_rft_id(vha)) {
5782 ql_dbg(ql_dbg_disc, vha, 0x20a2,
5783 "Register FC-4 TYPE failed.\n");
5784 if (test_bit(LOOP_RESYNC_NEEDED,
5788 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
5790 ql_dbg(ql_dbg_disc, vha, 0x209a,
5791 "Register FC-4 Features failed.\n");
5792 if (test_bit(LOOP_RESYNC_NEEDED,
5796 if (vha->flags.nvme_enabled) {
5797 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5798 ql_dbg(ql_dbg_disc, vha, 0x2049,
5799 "Register NVME FC Type Features failed.\n");
5802 if (qla2x00_rnn_id(vha)) {
5804 ql_dbg(ql_dbg_disc, vha, 0x2104,
5805 "Register Node Name failed.\n");
5806 if (test_bit(LOOP_RESYNC_NEEDED,
5809 } else if (qla2x00_rsnn_nn(vha)) {
5811 ql_dbg(ql_dbg_disc, vha, 0x209b,
5812 "Register Symbolic Node Name failed.\n");
5813 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5819 /* Mark the time right before querying FW for connected ports.
5820 * This process is long, asynchronous and by the time it's done,
5821 * collected information might not be accurate anymore. E.g.
5822 * disconnected port might have re-connected and a brand new
5823 * session has been created. In this case session's generation
5824 * will be newer than discovery_gen. */
5825 qlt_do_generation_tick(vha, &discovery_gen);
5827 if (USE_ASYNC_SCAN(ha)) {
5828 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
5831 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5833 list_for_each_entry(fcport, &vha->vp_fcports, list)
5834 fcport->scan_state = QLA_FCPORT_SCAN;
5836 rval = qla2x00_find_all_fabric_devs(vha);
5838 if (rval != QLA_SUCCESS)
5842 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5843 qla_nvme_register_hba(vha);
5846 ql_dbg(ql_dbg_disc, vha, 0x2068,
5847 "Configure fabric error exit rval=%d.\n", rval);
5853 * qla2x00_find_all_fabric_devs
5856 * ha = adapter block pointer.
5857 * dev = database device entry pointer.
5866 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
5870 fc_port_t *fcport, *new_fcport;
5875 int first_dev, last_dev;
5876 port_id_t wrap = {}, nxt_d_id;
5877 struct qla_hw_data *ha = vha->hw;
5878 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5879 unsigned long flags;
5883 /* Try GID_PT to get device list, else GAN. */
5885 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
5890 ql_dbg(ql_dbg_disc, vha, 0x209c,
5891 "GID_PT allocations failed, fallback on GA_NXT.\n");
5893 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
5894 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
5896 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5898 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
5900 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5902 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
5904 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5906 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5908 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5912 /* If other queries succeeded probe for FC-4 type */
5914 qla2x00_gff_id(vha, swl);
5915 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5921 /* Allocate temporary fcport for any new fcports discovered. */
5922 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5923 if (new_fcport == NULL) {
5924 ql_log(ql_log_warn, vha, 0x209d,
5925 "Failed to allocate memory for fcport.\n");
5926 return (QLA_MEMORY_ALLOC_FAILED);
5928 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5929 /* Set start port ID scan at adapter ID. */
5933 /* Starting free loop ID. */
5934 loop_id = ha->min_external_loopid;
5935 for (; loop_id <= ha->max_loop_id; loop_id++) {
5936 if (qla2x00_is_reserved_id(vha, loop_id))
5939 if (ha->current_topology == ISP_CFG_FL &&
5940 (atomic_read(&vha->loop_down_timer) ||
5941 LOOP_TRANSITION(vha))) {
5942 atomic_set(&vha->loop_down_timer, 0);
5943 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5944 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5950 wrap.b24 = new_fcport->d_id.b24;
5952 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
5953 memcpy(new_fcport->node_name,
5954 swl[swl_idx].node_name, WWN_SIZE);
5955 memcpy(new_fcport->port_name,
5956 swl[swl_idx].port_name, WWN_SIZE);
5957 memcpy(new_fcport->fabric_port_name,
5958 swl[swl_idx].fabric_port_name, WWN_SIZE);
5959 new_fcport->fp_speed = swl[swl_idx].fp_speed;
5960 new_fcport->fc4_type = swl[swl_idx].fc4_type;
5962 new_fcport->nvme_flag = 0;
5963 if (vha->flags.nvme_enabled &&
5964 swl[swl_idx].fc4_type & FS_FC4TYPE_NVME) {
5965 ql_log(ql_log_info, vha, 0x2131,
5966 "FOUND: NVME port %8phC as FC Type 28h\n",
5967 new_fcport->port_name);
5970 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5976 /* Send GA_NXT to the switch */
5977 rval = qla2x00_ga_nxt(vha, new_fcport);
5978 if (rval != QLA_SUCCESS) {
5979 ql_log(ql_log_warn, vha, 0x209e,
5980 "SNS scan failed -- assuming "
5981 "zero-entry result.\n");
5987 /* If wrap on switch device list, exit. */
5989 wrap.b24 = new_fcport->d_id.b24;
5991 } else if (new_fcport->d_id.b24 == wrap.b24) {
5992 ql_dbg(ql_dbg_disc, vha, 0x209f,
5993 "Device wrap (%02x%02x%02x).\n",
5994 new_fcport->d_id.b.domain,
5995 new_fcport->d_id.b.area,
5996 new_fcport->d_id.b.al_pa);
6000 /* Bypass if same physical adapter. */
6001 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
6004 /* Bypass virtual ports of the same host. */
6005 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
6008 /* Bypass if same domain and area of adapter. */
6009 if (((new_fcport->d_id.b24 & 0xffff00) ==
6010 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
6014 /* Bypass reserved domain fields. */
6015 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
6018 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
6019 if (ql2xgffidenable &&
6020 (!(new_fcport->fc4_type & FS_FC4TYPE_FCP) &&
6021 new_fcport->fc4_type != 0))
6024 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
6026 /* Locate matching device in database. */
6028 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6029 if (memcmp(new_fcport->port_name, fcport->port_name,
6033 fcport->scan_state = QLA_FCPORT_FOUND;
6037 /* Update port state. */
6038 memcpy(fcport->fabric_port_name,
6039 new_fcport->fabric_port_name, WWN_SIZE);
6040 fcport->fp_speed = new_fcport->fp_speed;
6043 * If address the same and state FCS_ONLINE
6044 * (or in target mode), nothing changed.
6046 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
6047 (atomic_read(&fcport->state) == FCS_ONLINE ||
6048 (vha->host->active_mode == MODE_TARGET))) {
6052 if (fcport->login_retry == 0)
6053 fcport->login_retry =
6054 vha->hw->login_retry_count;
6056 * If device was not a fabric device before.
6058 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
6059 fcport->d_id.b24 = new_fcport->d_id.b24;
6060 qla2x00_clear_loop_id(fcport);
6061 fcport->flags |= (FCF_FABRIC_DEVICE |
6067 * Port ID changed or device was marked to be updated;
6068 * Log it out if still logged in and mark it for
6071 if (qla_tgt_mode_enabled(base_vha)) {
6072 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
6073 "port changed FC ID, %8phC"
6074 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
6076 fcport->d_id.b.domain,
6077 fcport->d_id.b.area,
6078 fcport->d_id.b.al_pa,
6080 new_fcport->d_id.b.domain,
6081 new_fcport->d_id.b.area,
6082 new_fcport->d_id.b.al_pa);
6083 fcport->d_id.b24 = new_fcport->d_id.b24;
6087 fcport->d_id.b24 = new_fcport->d_id.b24;
6088 fcport->flags |= FCF_LOGIN_NEEDED;
6092 if (found && NVME_TARGET(vha->hw, fcport)) {
6093 if (fcport->disc_state == DSC_DELETE_PEND) {
6094 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
6095 vha->fcport_count--;
6096 fcport->login_succ = 0;
6101 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6104 /* If device was not in our fcports list, then add it. */
6105 new_fcport->scan_state = QLA_FCPORT_FOUND;
6106 list_add_tail(&new_fcport->list, &vha->vp_fcports);
6108 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6111 /* Allocate a new replacement fcport. */
6112 nxt_d_id.b24 = new_fcport->d_id.b24;
6113 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
6114 if (new_fcport == NULL) {
6115 ql_log(ql_log_warn, vha, 0xd032,
6116 "Memory allocation failed for fcport.\n");
6117 return (QLA_MEMORY_ALLOC_FAILED);
6119 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
6120 new_fcport->d_id.b24 = nxt_d_id.b24;
6123 qla2x00_free_fcport(new_fcport);
6126 * Logout all previous fabric dev marked lost, except FCP2 devices.
6128 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6129 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6132 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
6135 if (fcport->scan_state == QLA_FCPORT_SCAN) {
6136 if ((qla_dual_mode_enabled(vha) ||
6137 qla_ini_mode_enabled(vha)) &&
6138 atomic_read(&fcport->state) == FCS_ONLINE) {
6139 qla2x00_mark_device_lost(vha, fcport,
6140 ql2xplogiabsentdevice);
6141 if (fcport->loop_id != FC_NO_LOOP_ID &&
6142 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
6143 fcport->port_type != FCT_INITIATOR &&
6144 fcport->port_type != FCT_BROADCAST) {
6145 ql_dbg(ql_dbg_disc, vha, 0x20f0,
6146 "%s %d %8phC post del sess\n",
6149 qlt_schedule_sess_for_deletion(fcport);
6155 if (fcport->scan_state == QLA_FCPORT_FOUND &&
6156 (fcport->flags & FCF_LOGIN_NEEDED) != 0)
6157 qla24xx_fcport_handle_login(vha, fcport);
6162 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
6164 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
6166 int loop_id = FC_NO_LOOP_ID;
6167 int lid = NPH_MGMT_SERVER - vha->vp_idx;
6168 unsigned long flags;
6169 struct qla_hw_data *ha = vha->hw;
6171 if (vha->vp_idx == 0) {
6172 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
6173 return NPH_MGMT_SERVER;
6176 /* pick id from high and work down to low */
6177 spin_lock_irqsave(&ha->vport_slock, flags);
6178 for (; lid > 0; lid--) {
6179 if (!test_bit(lid, vha->hw->loop_id_map)) {
6180 set_bit(lid, vha->hw->loop_id_map);
6185 spin_unlock_irqrestore(&ha->vport_slock, flags);
6191 * qla2x00_fabric_login
6192 * Issue fabric login command.
6195 * ha = adapter block pointer.
6196 * device = pointer to FC device type structure.
6199 * 0 - Login successfully
6201 * 2 - Initiator device
6205 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
6206 uint16_t *next_loopid)
6210 uint16_t tmp_loopid;
6211 uint16_t mb[MAILBOX_REGISTER_COUNT];
6212 struct qla_hw_data *ha = vha->hw;
6218 ql_dbg(ql_dbg_disc, vha, 0x2000,
6219 "Trying Fabric Login w/loop id 0x%04x for port "
6221 fcport->loop_id, fcport->d_id.b.domain,
6222 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6224 /* Login fcport on switch. */
6225 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
6226 fcport->d_id.b.domain, fcport->d_id.b.area,
6227 fcport->d_id.b.al_pa, mb, BIT_0);
6228 if (rval != QLA_SUCCESS) {
6231 if (mb[0] == MBS_PORT_ID_USED) {
6233 * Device has another loop ID. The firmware team
6234 * recommends the driver perform an implicit login with
6235 * the specified ID again. The ID we just used is save
6236 * here so we return with an ID that can be tried by
6240 tmp_loopid = fcport->loop_id;
6241 fcport->loop_id = mb[1];
6243 ql_dbg(ql_dbg_disc, vha, 0x2001,
6244 "Fabric Login: port in use - next loop "
6245 "id=0x%04x, port id= %02x%02x%02x.\n",
6246 fcport->loop_id, fcport->d_id.b.domain,
6247 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6249 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
6254 /* A retry occurred before. */
6255 *next_loopid = tmp_loopid;
6258 * No retry occurred before. Just increment the
6259 * ID value for next login.
6261 *next_loopid = (fcport->loop_id + 1);
6264 if (mb[1] & BIT_0) {
6265 fcport->port_type = FCT_INITIATOR;
6267 fcport->port_type = FCT_TARGET;
6268 if (mb[1] & BIT_1) {
6269 fcport->flags |= FCF_FCP2_DEVICE;
6274 fcport->supported_classes |= FC_COS_CLASS2;
6276 fcport->supported_classes |= FC_COS_CLASS3;
6278 if (IS_FWI2_CAPABLE(ha)) {
6281 FCF_CONF_COMP_SUPPORTED;
6286 } else if (mb[0] == MBS_LOOP_ID_USED) {
6288 * Loop ID already used, try next loop ID.
6291 rval = qla2x00_find_new_loop_id(vha, fcport);
6292 if (rval != QLA_SUCCESS) {
6293 /* Ran out of loop IDs to use */
6296 } else if (mb[0] == MBS_COMMAND_ERROR) {
6298 * Firmware possibly timed out during login. If NO
6299 * retries are left to do then the device is declared
6302 *next_loopid = fcport->loop_id;
6303 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6304 fcport->d_id.b.domain, fcport->d_id.b.area,
6305 fcport->d_id.b.al_pa);
6306 qla2x00_mark_device_lost(vha, fcport, 1);
6312 * unrecoverable / not handled error
6314 ql_dbg(ql_dbg_disc, vha, 0x2002,
6315 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6316 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
6317 fcport->d_id.b.area, fcport->d_id.b.al_pa,
6318 fcport->loop_id, jiffies);
6320 *next_loopid = fcport->loop_id;
6321 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6322 fcport->d_id.b.domain, fcport->d_id.b.area,
6323 fcport->d_id.b.al_pa);
6324 qla2x00_clear_loop_id(fcport);
6325 fcport->login_retry = 0;
6336 * qla2x00_local_device_login
6337 * Issue local device login command.
6340 * ha = adapter block pointer.
6341 * loop_id = loop id of device to login to.
6343 * Returns (Where's the #define!!!!):
6344 * 0 - Login successfully
6349 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
6352 uint16_t mb[MAILBOX_REGISTER_COUNT];
6354 memset(mb, 0, sizeof(mb));
6355 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
6356 if (rval == QLA_SUCCESS) {
6357 /* Interrogate mailbox registers for any errors */
6358 if (mb[0] == MBS_COMMAND_ERROR)
6360 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
6361 /* device not in PCB table */
6369 * qla2x00_loop_resync
6370 * Resync with fibre channel devices.
6373 * ha = adapter block pointer.
6379 qla2x00_loop_resync(scsi_qla_host_t *vha)
6381 int rval = QLA_SUCCESS;
6384 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6385 if (vha->flags.online) {
6386 if (!(rval = qla2x00_fw_ready(vha))) {
6387 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6390 if (!IS_QLAFX00(vha->hw)) {
6392 * Issue a marker after FW becomes
6395 qla2x00_marker(vha, vha->hw->base_qpair,
6397 vha->marker_needed = 0;
6400 /* Remap devices on Loop. */
6401 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6403 if (IS_QLAFX00(vha->hw))
6404 qlafx00_configure_devices(vha);
6406 qla2x00_configure_loop(vha);
6409 } while (!atomic_read(&vha->loop_down_timer) &&
6410 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6411 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
6416 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6417 return (QLA_FUNCTION_FAILED);
6420 ql_dbg(ql_dbg_disc, vha, 0x206c,
6421 "%s *** FAILED ***.\n", __func__);
6427 * qla2x00_perform_loop_resync
6428 * Description: This function will set the appropriate flags and call
6429 * qla2x00_loop_resync. If successful loop will be resynced
6430 * Arguments : scsi_qla_host_t pointer
6431 * returm : Success or Failure
6434 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
6438 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
6439 /*Configure the flags so that resync happens properly*/
6440 atomic_set(&ha->loop_down_timer, 0);
6441 if (!(ha->device_flags & DFLG_NO_CABLE)) {
6442 atomic_set(&ha->loop_state, LOOP_UP);
6443 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
6444 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
6445 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
6447 rval = qla2x00_loop_resync(ha);
6449 atomic_set(&ha->loop_state, LOOP_DEAD);
6451 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
6458 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
6461 struct scsi_qla_host *vha;
6462 struct qla_hw_data *ha = base_vha->hw;
6463 unsigned long flags;
6465 spin_lock_irqsave(&ha->vport_slock, flags);
6466 /* Go with deferred removal of rport references. */
6467 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
6468 atomic_inc(&vha->vref_count);
6469 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6470 if (fcport->drport &&
6471 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
6472 spin_unlock_irqrestore(&ha->vport_slock, flags);
6473 qla2x00_rport_del(fcport);
6475 spin_lock_irqsave(&ha->vport_slock, flags);
6478 atomic_dec(&vha->vref_count);
6479 wake_up(&vha->vref_waitq);
6481 spin_unlock_irqrestore(&ha->vport_slock, flags);
6484 /* Assumes idc_lock always held on entry */
6486 qla83xx_reset_ownership(scsi_qla_host_t *vha)
6488 struct qla_hw_data *ha = vha->hw;
6489 uint32_t drv_presence, drv_presence_mask;
6490 uint32_t dev_part_info1, dev_part_info2, class_type;
6491 uint32_t class_type_mask = 0x3;
6492 uint16_t fcoe_other_function = 0xffff, i;
6494 if (IS_QLA8044(ha)) {
6495 drv_presence = qla8044_rd_direct(vha,
6496 QLA8044_CRB_DRV_ACTIVE_INDEX);
6497 dev_part_info1 = qla8044_rd_direct(vha,
6498 QLA8044_CRB_DEV_PART_INFO_INDEX);
6499 dev_part_info2 = qla8044_rd_direct(vha,
6500 QLA8044_CRB_DEV_PART_INFO2);
6502 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6503 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
6504 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
6506 for (i = 0; i < 8; i++) {
6507 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
6508 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6509 (i != ha->portnum)) {
6510 fcoe_other_function = i;
6514 if (fcoe_other_function == 0xffff) {
6515 for (i = 0; i < 8; i++) {
6516 class_type = ((dev_part_info2 >> (i * 4)) &
6518 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6519 ((i + 8) != ha->portnum)) {
6520 fcoe_other_function = i + 8;
6526 * Prepare drv-presence mask based on fcoe functions present.
6527 * However consider only valid physical fcoe function numbers (0-15).
6529 drv_presence_mask = ~((1 << (ha->portnum)) |
6530 ((fcoe_other_function == 0xffff) ?
6531 0 : (1 << (fcoe_other_function))));
6533 /* We are the reset owner iff:
6534 * - No other protocol drivers present.
6535 * - This is the lowest among fcoe functions. */
6536 if (!(drv_presence & drv_presence_mask) &&
6537 (ha->portnum < fcoe_other_function)) {
6538 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
6539 "This host is Reset owner.\n");
6540 ha->flags.nic_core_reset_owner = 1;
6545 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
6547 int rval = QLA_SUCCESS;
6548 struct qla_hw_data *ha = vha->hw;
6551 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6552 if (rval == QLA_SUCCESS) {
6553 drv_ack |= (1 << ha->portnum);
6554 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6561 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
6563 int rval = QLA_SUCCESS;
6564 struct qla_hw_data *ha = vha->hw;
6567 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6568 if (rval == QLA_SUCCESS) {
6569 drv_ack &= ~(1 << ha->portnum);
6570 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6577 qla83xx_dev_state_to_string(uint32_t dev_state)
6579 switch (dev_state) {
6580 case QLA8XXX_DEV_COLD:
6581 return "COLD/RE-INIT";
6582 case QLA8XXX_DEV_INITIALIZING:
6583 return "INITIALIZING";
6584 case QLA8XXX_DEV_READY:
6586 case QLA8XXX_DEV_NEED_RESET:
6587 return "NEED RESET";
6588 case QLA8XXX_DEV_NEED_QUIESCENT:
6589 return "NEED QUIESCENT";
6590 case QLA8XXX_DEV_FAILED:
6592 case QLA8XXX_DEV_QUIESCENT:
6599 /* Assumes idc-lock always held on entry */
6601 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6603 struct qla_hw_data *ha = vha->hw;
6604 uint32_t idc_audit_reg = 0, duration_secs = 0;
6606 switch (audit_type) {
6607 case IDC_AUDIT_TIMESTAMP:
6608 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6609 idc_audit_reg = (ha->portnum) |
6610 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6611 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6614 case IDC_AUDIT_COMPLETION:
6615 duration_secs = ((jiffies_to_msecs(jiffies) -
6616 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6617 idc_audit_reg = (ha->portnum) |
6618 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6619 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6623 ql_log(ql_log_warn, vha, 0xb078,
6624 "Invalid audit type specified.\n");
6629 /* Assumes idc_lock always held on entry */
6631 qla83xx_initiating_reset(scsi_qla_host_t *vha)
6633 struct qla_hw_data *ha = vha->hw;
6634 uint32_t idc_control, dev_state;
6636 __qla83xx_get_idc_control(vha, &idc_control);
6637 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6638 ql_log(ql_log_info, vha, 0xb080,
6639 "NIC Core reset has been disabled. idc-control=0x%x\n",
6641 return QLA_FUNCTION_FAILED;
6644 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6645 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6646 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6647 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6648 QLA8XXX_DEV_NEED_RESET);
6649 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6650 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6652 const char *state = qla83xx_dev_state_to_string(dev_state);
6654 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
6656 /* SV: XXX: Is timeout required here? */
6657 /* Wait for IDC state change READY -> NEED_RESET */
6658 while (dev_state == QLA8XXX_DEV_READY) {
6659 qla83xx_idc_unlock(vha, 0);
6661 qla83xx_idc_lock(vha, 0);
6662 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6666 /* Send IDC ack by writing to drv-ack register */
6667 __qla83xx_set_drv_ack(vha);
6673 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6675 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6679 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6681 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6685 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6687 uint32_t drv_presence = 0;
6688 struct qla_hw_data *ha = vha->hw;
6690 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6691 if (drv_presence & (1 << ha->portnum))
6694 return QLA_TEST_FAILED;
6698 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6700 int rval = QLA_SUCCESS;
6701 struct qla_hw_data *ha = vha->hw;
6703 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6704 "Entered %s().\n", __func__);
6706 if (vha->device_flags & DFLG_DEV_FAILED) {
6707 ql_log(ql_log_warn, vha, 0xb059,
6708 "Device in unrecoverable FAILED state.\n");
6709 return QLA_FUNCTION_FAILED;
6712 qla83xx_idc_lock(vha, 0);
6714 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6715 ql_log(ql_log_warn, vha, 0xb05a,
6716 "Function=0x%x has been removed from IDC participation.\n",
6718 rval = QLA_FUNCTION_FAILED;
6722 qla83xx_reset_ownership(vha);
6724 rval = qla83xx_initiating_reset(vha);
6727 * Perform reset if we are the reset-owner,
6728 * else wait till IDC state changes to READY/FAILED.
6730 if (rval == QLA_SUCCESS) {
6731 rval = qla83xx_idc_state_handler(vha);
6733 if (rval == QLA_SUCCESS)
6734 ha->flags.nic_core_hung = 0;
6735 __qla83xx_clear_drv_ack(vha);
6739 qla83xx_idc_unlock(vha, 0);
6741 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6747 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6749 struct qla_hw_data *ha = vha->hw;
6750 int rval = QLA_FUNCTION_FAILED;
6752 if (!IS_MCTP_CAPABLE(ha)) {
6753 /* This message can be removed from the final version */
6754 ql_log(ql_log_info, vha, 0x506d,
6755 "This board is not MCTP capable\n");
6759 if (!ha->mctp_dump) {
6760 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6761 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6763 if (!ha->mctp_dump) {
6764 ql_log(ql_log_warn, vha, 0x506e,
6765 "Failed to allocate memory for mctp dump\n");
6770 #define MCTP_DUMP_STR_ADDR 0x00000000
6771 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6772 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6773 if (rval != QLA_SUCCESS) {
6774 ql_log(ql_log_warn, vha, 0x506f,
6775 "Failed to capture mctp dump\n");
6777 ql_log(ql_log_info, vha, 0x5070,
6778 "Mctp dump capture for host (%ld/%p).\n",
6779 vha->host_no, ha->mctp_dump);
6780 ha->mctp_dumped = 1;
6783 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
6784 ha->flags.nic_core_reset_hdlr_active = 1;
6785 rval = qla83xx_restart_nic_firmware(vha);
6787 /* NIC Core reset failed. */
6788 ql_log(ql_log_warn, vha, 0x5071,
6789 "Failed to restart nic firmware\n");
6791 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6792 "Restarted NIC firmware successfully.\n");
6793 ha->flags.nic_core_reset_hdlr_active = 0;
6801 * qla2x00_quiesce_io
6802 * Description: This function will block the new I/Os
6803 * Its not aborting any I/Os as context
6804 * is not destroyed during quiescence
6805 * Arguments: scsi_qla_host_t
6809 qla2x00_quiesce_io(scsi_qla_host_t *vha)
6811 struct qla_hw_data *ha = vha->hw;
6812 struct scsi_qla_host *vp;
6814 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6815 "Quiescing I/O - ha=%p.\n", ha);
6817 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6818 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6819 atomic_set(&vha->loop_state, LOOP_DOWN);
6820 qla2x00_mark_all_devices_lost(vha);
6821 list_for_each_entry(vp, &ha->vp_list, list)
6822 qla2x00_mark_all_devices_lost(vp);
6824 if (!atomic_read(&vha->loop_down_timer))
6825 atomic_set(&vha->loop_down_timer,
6828 /* Wait for pending cmds to complete */
6829 WARN_ON_ONCE(qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST)
6834 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6836 struct qla_hw_data *ha = vha->hw;
6837 struct scsi_qla_host *vp;
6838 unsigned long flags;
6842 /* For ISP82XX, driver waits for completion of the commands.
6843 * online flag should be set.
6845 if (!(IS_P3P_TYPE(ha)))
6846 vha->flags.online = 0;
6847 ha->flags.chip_reset_done = 0;
6848 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6849 vha->qla_stats.total_isp_aborts++;
6851 ql_log(ql_log_info, vha, 0x00af,
6852 "Performing ISP error recovery - ha=%p.\n", ha);
6854 ha->flags.purge_mbox = 1;
6855 /* For ISP82XX, reset_chip is just disabling interrupts.
6856 * Driver waits for the completion of the commands.
6857 * the interrupts need to be enabled.
6859 if (!(IS_P3P_TYPE(ha)))
6860 ha->isp_ops->reset_chip(vha);
6862 ha->link_data_rate = PORT_SPEED_UNKNOWN;
6864 ha->flags.rida_fmt2 = 0;
6865 ha->flags.n2n_ae = 0;
6866 ha->flags.lip_ae = 0;
6867 ha->current_topology = 0;
6869 ha->flags.fw_init_done = 0;
6871 ha->base_qpair->chip_reset = ha->chip_reset;
6872 for (i = 0; i < ha->max_qpairs; i++) {
6873 if (ha->queue_pair_map[i])
6874 ha->queue_pair_map[i]->chip_reset =
6875 ha->base_qpair->chip_reset;
6878 /* purge MBox commands */
6879 if (atomic_read(&ha->num_pend_mbx_stage3)) {
6880 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
6881 complete(&ha->mbx_intr_comp);
6885 while (atomic_read(&ha->num_pend_mbx_stage3) ||
6886 atomic_read(&ha->num_pend_mbx_stage2) ||
6887 atomic_read(&ha->num_pend_mbx_stage1)) {
6893 ha->flags.purge_mbox = 0;
6895 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6896 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6897 atomic_set(&vha->loop_state, LOOP_DOWN);
6898 qla2x00_mark_all_devices_lost(vha);
6900 spin_lock_irqsave(&ha->vport_slock, flags);
6901 list_for_each_entry(vp, &ha->vp_list, list) {
6902 atomic_inc(&vp->vref_count);
6903 spin_unlock_irqrestore(&ha->vport_slock, flags);
6905 qla2x00_mark_all_devices_lost(vp);
6907 spin_lock_irqsave(&ha->vport_slock, flags);
6908 atomic_dec(&vp->vref_count);
6910 spin_unlock_irqrestore(&ha->vport_slock, flags);
6912 if (!atomic_read(&vha->loop_down_timer))
6913 atomic_set(&vha->loop_down_timer,
6917 /* Clear all async request states across all VPs. */
6918 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6919 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6920 fcport->scan_state = 0;
6922 spin_lock_irqsave(&ha->vport_slock, flags);
6923 list_for_each_entry(vp, &ha->vp_list, list) {
6924 atomic_inc(&vp->vref_count);
6925 spin_unlock_irqrestore(&ha->vport_slock, flags);
6927 list_for_each_entry(fcport, &vp->vp_fcports, list)
6928 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6930 spin_lock_irqsave(&ha->vport_slock, flags);
6931 atomic_dec(&vp->vref_count);
6933 spin_unlock_irqrestore(&ha->vport_slock, flags);
6935 /* Make sure for ISP 82XX IO DMA is complete */
6936 if (IS_P3P_TYPE(ha)) {
6937 qla82xx_chip_reset_cleanup(vha);
6938 ql_log(ql_log_info, vha, 0x00b4,
6939 "Done chip reset cleanup.\n");
6941 /* Done waiting for pending commands. Reset online flag */
6942 vha->flags.online = 0;
6945 /* Requeue all commands in outstanding command list. */
6946 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6947 /* memory barrier */
6953 * Resets ISP and aborts all outstanding commands.
6956 * ha = adapter block pointer.
6962 qla2x00_abort_isp(scsi_qla_host_t *vha)
6966 struct qla_hw_data *ha = vha->hw;
6967 struct scsi_qla_host *vp;
6968 struct req_que *req = ha->req_q_map[0];
6969 unsigned long flags;
6971 if (vha->flags.online) {
6972 qla2x00_abort_isp_cleanup(vha);
6974 if (vha->hw->flags.port_isolated)
6977 if (qla2x00_isp_reg_stat(ha)) {
6978 ql_log(ql_log_info, vha, 0x803f,
6979 "ISP Abort - ISP reg disconnect, exiting.\n");
6983 if (test_and_clear_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags)) {
6984 ha->flags.chip_reset_done = 1;
6985 vha->flags.online = 1;
6987 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6991 if (IS_QLA8031(ha)) {
6992 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
6993 "Clearing fcoe driver presence.\n");
6994 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
6995 ql_dbg(ql_dbg_p3p, vha, 0xb073,
6996 "Error while clearing DRV-Presence.\n");
6999 if (unlikely(pci_channel_offline(ha->pdev) &&
7000 ha->flags.pci_channel_io_perm_failure)) {
7001 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7006 switch (vha->qlini_mode) {
7007 case QLA2XXX_INI_MODE_DISABLED:
7008 if (!qla_tgt_mode_enabled(vha))
7011 case QLA2XXX_INI_MODE_DUAL:
7012 if (!qla_dual_mode_enabled(vha))
7015 case QLA2XXX_INI_MODE_ENABLED:
7020 ha->isp_ops->get_flash_version(vha, req->ring);
7022 if (qla2x00_isp_reg_stat(ha)) {
7023 ql_log(ql_log_info, vha, 0x803f,
7024 "ISP Abort - ISP reg disconnect pre nvram config, exiting.\n");
7027 ha->isp_ops->nvram_config(vha);
7029 if (qla2x00_isp_reg_stat(ha)) {
7030 ql_log(ql_log_info, vha, 0x803f,
7031 "ISP Abort - ISP reg disconnect post nvmram config, exiting.\n");
7034 if (!qla2x00_restart_isp(vha)) {
7035 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7037 if (!atomic_read(&vha->loop_down_timer)) {
7039 * Issue marker command only when we are going
7040 * to start the I/O .
7042 vha->marker_needed = 1;
7045 vha->flags.online = 1;
7047 ha->isp_ops->enable_intrs(ha);
7049 ha->isp_abort_cnt = 0;
7050 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7052 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
7053 qla2x00_get_fw_version(vha);
7055 ha->flags.fce_enabled = 1;
7057 fce_calc_size(ha->fce_bufs));
7058 rval = qla2x00_enable_fce_trace(vha,
7059 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
7062 ql_log(ql_log_warn, vha, 0x8033,
7063 "Unable to reinitialize FCE "
7065 ha->flags.fce_enabled = 0;
7070 memset(ha->eft, 0, EFT_SIZE);
7071 rval = qla2x00_enable_eft_trace(vha,
7072 ha->eft_dma, EFT_NUM_BUFFERS);
7074 ql_log(ql_log_warn, vha, 0x8034,
7075 "Unable to reinitialize EFT "
7079 } else { /* failed the ISP abort */
7080 vha->flags.online = 1;
7081 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
7082 if (ha->isp_abort_cnt == 0) {
7083 ql_log(ql_log_fatal, vha, 0x8035,
7084 "ISP error recover failed - "
7085 "board disabled.\n");
7087 * The next call disables the board
7090 qla2x00_abort_isp_cleanup(vha);
7091 vha->flags.online = 0;
7092 clear_bit(ISP_ABORT_RETRY,
7095 } else { /* schedule another ISP abort */
7096 ha->isp_abort_cnt--;
7097 ql_dbg(ql_dbg_taskm, vha, 0x8020,
7098 "ISP abort - retry remaining %d.\n",
7103 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
7104 ql_dbg(ql_dbg_taskm, vha, 0x8021,
7105 "ISP error recovery - retrying (%d) "
7106 "more times.\n", ha->isp_abort_cnt);
7107 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7114 if (vha->hw->flags.port_isolated) {
7115 qla2x00_abort_isp_cleanup(vha);
7120 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
7121 qla2x00_configure_hba(vha);
7122 spin_lock_irqsave(&ha->vport_slock, flags);
7123 list_for_each_entry(vp, &ha->vp_list, list) {
7125 atomic_inc(&vp->vref_count);
7126 spin_unlock_irqrestore(&ha->vport_slock, flags);
7128 qla2x00_vp_abort_isp(vp);
7130 spin_lock_irqsave(&ha->vport_slock, flags);
7131 atomic_dec(&vp->vref_count);
7134 spin_unlock_irqrestore(&ha->vport_slock, flags);
7136 if (IS_QLA8031(ha)) {
7137 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
7138 "Setting back fcoe driver presence.\n");
7139 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
7140 ql_dbg(ql_dbg_p3p, vha, 0xb074,
7141 "Error while setting DRV-Presence.\n");
7144 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
7152 * qla2x00_restart_isp
7153 * restarts the ISP after a reset
7156 * ha = adapter block pointer.
7162 qla2x00_restart_isp(scsi_qla_host_t *vha)
7165 struct qla_hw_data *ha = vha->hw;
7167 /* If firmware needs to be loaded */
7168 if (qla2x00_isp_firmware(vha)) {
7169 vha->flags.online = 0;
7170 status = ha->isp_ops->chip_diag(vha);
7173 status = qla2x00_setup_chip(vha);
7178 status = qla2x00_init_rings(vha);
7182 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7183 ha->flags.chip_reset_done = 1;
7185 /* Initialize the queues in use */
7186 qla25xx_init_queues(ha);
7188 status = qla2x00_fw_ready(vha);
7190 /* if no cable then assume it's good */
7191 return vha->device_flags & DFLG_NO_CABLE ? 0 : status;
7194 /* Issue a marker after FW becomes ready. */
7195 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
7196 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7202 qla25xx_init_queues(struct qla_hw_data *ha)
7204 struct rsp_que *rsp = NULL;
7205 struct req_que *req = NULL;
7206 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7210 for (i = 1; i < ha->max_rsp_queues; i++) {
7211 rsp = ha->rsp_q_map[i];
7212 if (rsp && test_bit(i, ha->rsp_qid_map)) {
7213 rsp->options &= ~BIT_0;
7214 ret = qla25xx_init_rsp_que(base_vha, rsp);
7215 if (ret != QLA_SUCCESS)
7216 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
7217 "%s Rsp que: %d init failed.\n",
7220 ql_dbg(ql_dbg_init, base_vha, 0x0100,
7221 "%s Rsp que: %d inited.\n",
7225 for (i = 1; i < ha->max_req_queues; i++) {
7226 req = ha->req_q_map[i];
7227 if (req && test_bit(i, ha->req_qid_map)) {
7228 /* Clear outstanding commands array. */
7229 req->options &= ~BIT_0;
7230 ret = qla25xx_init_req_que(base_vha, req);
7231 if (ret != QLA_SUCCESS)
7232 ql_dbg(ql_dbg_init, base_vha, 0x0101,
7233 "%s Req que: %d init failed.\n",
7236 ql_dbg(ql_dbg_init, base_vha, 0x0102,
7237 "%s Req que: %d inited.\n",
7245 * qla2x00_reset_adapter
7249 * ha = adapter block pointer.
7252 qla2x00_reset_adapter(scsi_qla_host_t *vha)
7254 unsigned long flags = 0;
7255 struct qla_hw_data *ha = vha->hw;
7256 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7258 vha->flags.online = 0;
7259 ha->isp_ops->disable_intrs(ha);
7261 spin_lock_irqsave(&ha->hardware_lock, flags);
7262 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
7263 rd_reg_word(®->hccr); /* PCI Posting. */
7264 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
7265 rd_reg_word(®->hccr); /* PCI Posting. */
7266 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7272 qla24xx_reset_adapter(scsi_qla_host_t *vha)
7274 unsigned long flags = 0;
7275 struct qla_hw_data *ha = vha->hw;
7276 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
7278 if (IS_P3P_TYPE(ha))
7281 vha->flags.online = 0;
7282 ha->isp_ops->disable_intrs(ha);
7284 spin_lock_irqsave(&ha->hardware_lock, flags);
7285 wrt_reg_dword(®->hccr, HCCRX_SET_RISC_RESET);
7286 rd_reg_dword(®->hccr);
7287 wrt_reg_dword(®->hccr, HCCRX_REL_RISC_PAUSE);
7288 rd_reg_dword(®->hccr);
7289 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7291 if (IS_NOPOLLING_TYPE(ha))
7292 ha->isp_ops->enable_intrs(ha);
7297 /* On sparc systems, obtain port and node WWN from firmware
7300 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
7301 struct nvram_24xx *nv)
7304 struct qla_hw_data *ha = vha->hw;
7305 struct pci_dev *pdev = ha->pdev;
7306 struct device_node *dp = pci_device_to_OF_node(pdev);
7310 val = of_get_property(dp, "port-wwn", &len);
7311 if (val && len >= WWN_SIZE)
7312 memcpy(nv->port_name, val, WWN_SIZE);
7314 val = of_get_property(dp, "node-wwn", &len);
7315 if (val && len >= WWN_SIZE)
7316 memcpy(nv->node_name, val, WWN_SIZE);
7321 qla24xx_nvram_config(scsi_qla_host_t *vha)
7324 struct init_cb_24xx *icb;
7325 struct nvram_24xx *nv;
7327 uint8_t *dptr1, *dptr2;
7330 struct qla_hw_data *ha = vha->hw;
7333 icb = (struct init_cb_24xx *)ha->init_cb;
7336 /* Determine NVRAM starting address. */
7337 if (ha->port_no == 0) {
7338 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
7339 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
7341 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
7342 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
7345 ha->nvram_size = sizeof(*nv);
7346 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7348 /* Get VPD data into cache */
7349 ha->vpd = ha->nvram + VPD_OFFSET;
7350 ha->isp_ops->read_nvram(vha, ha->vpd,
7351 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
7353 /* Get NVRAM data into cache and calculate checksum. */
7354 dptr = (__force __le32 *)nv;
7355 ha->isp_ops->read_nvram(vha, dptr, ha->nvram_base, ha->nvram_size);
7356 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7357 chksum += le32_to_cpu(*dptr);
7359 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
7360 "Contents of NVRAM\n");
7361 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
7362 nv, ha->nvram_size);
7364 /* Bad NVRAM data, set defaults parameters. */
7365 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
7366 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
7367 /* Reset NVRAM data. */
7368 ql_log(ql_log_warn, vha, 0x006b,
7369 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
7370 chksum, nv->id, nv->nvram_version);
7371 ql_dump_buffer(ql_dbg_init, vha, 0x006b, nv, sizeof(*nv));
7372 ql_log(ql_log_warn, vha, 0x006c,
7373 "Falling back to functioning (yet invalid -- WWPN) "
7377 * Set default initialization control block.
7379 memset(nv, 0, ha->nvram_size);
7380 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7381 nv->version = cpu_to_le16(ICB_VERSION);
7382 nv->frame_payload_size = cpu_to_le16(2048);
7383 nv->execution_throttle = cpu_to_le16(0xFFFF);
7384 nv->exchange_count = cpu_to_le16(0);
7385 nv->hard_address = cpu_to_le16(124);
7386 nv->port_name[0] = 0x21;
7387 nv->port_name[1] = 0x00 + ha->port_no + 1;
7388 nv->port_name[2] = 0x00;
7389 nv->port_name[3] = 0xe0;
7390 nv->port_name[4] = 0x8b;
7391 nv->port_name[5] = 0x1c;
7392 nv->port_name[6] = 0x55;
7393 nv->port_name[7] = 0x86;
7394 nv->node_name[0] = 0x20;
7395 nv->node_name[1] = 0x00;
7396 nv->node_name[2] = 0x00;
7397 nv->node_name[3] = 0xe0;
7398 nv->node_name[4] = 0x8b;
7399 nv->node_name[5] = 0x1c;
7400 nv->node_name[6] = 0x55;
7401 nv->node_name[7] = 0x86;
7402 qla24xx_nvram_wwn_from_ofw(vha, nv);
7403 nv->login_retry_count = cpu_to_le16(8);
7404 nv->interrupt_delay_timer = cpu_to_le16(0);
7405 nv->login_timeout = cpu_to_le16(0);
7406 nv->firmware_options_1 =
7407 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7408 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7409 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7410 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7411 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7412 nv->efi_parameters = cpu_to_le32(0);
7413 nv->reset_delay = 5;
7414 nv->max_luns_per_target = cpu_to_le16(128);
7415 nv->port_down_retry_count = cpu_to_le16(30);
7416 nv->link_down_timeout = cpu_to_le16(30);
7421 if (qla_tgt_mode_enabled(vha)) {
7422 /* Don't enable full login after initial LIP */
7423 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7424 /* Don't enable LIP full login for initiator */
7425 nv->host_p &= cpu_to_le32(~BIT_10);
7428 qlt_24xx_config_nvram_stage1(vha, nv);
7430 /* Reset Initialization control block */
7431 memset(icb, 0, ha->init_cb_size);
7433 /* Copy 1st segment. */
7434 dptr1 = (uint8_t *)icb;
7435 dptr2 = (uint8_t *)&nv->version;
7436 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7438 *dptr1++ = *dptr2++;
7440 icb->login_retry_count = nv->login_retry_count;
7441 icb->link_down_on_nos = nv->link_down_on_nos;
7443 /* Copy 2nd segment. */
7444 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7445 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7446 cnt = (uint8_t *)&icb->reserved_3 -
7447 (uint8_t *)&icb->interrupt_delay_timer;
7449 *dptr1++ = *dptr2++;
7450 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
7452 * Setup driver NVRAM options.
7454 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7457 qlt_24xx_config_nvram_stage2(vha, icb);
7459 if (nv->host_p & cpu_to_le32(BIT_15)) {
7460 /* Use alternate WWN? */
7461 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7462 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7465 /* Prepare nodename */
7466 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7468 * Firmware will apply the following mask if the nodename was
7471 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7472 icb->node_name[0] &= 0xF0;
7475 /* Set host adapter parameters. */
7476 ha->flags.disable_risc_code_load = 0;
7477 ha->flags.enable_lip_reset = 0;
7478 ha->flags.enable_lip_full_login =
7479 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
7480 ha->flags.enable_target_reset =
7481 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
7482 ha->flags.enable_led_scheme = 0;
7483 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
7485 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7486 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7488 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
7489 sizeof(ha->fw_seriallink_options24));
7491 /* save HBA serial number */
7492 ha->serial0 = icb->port_name[5];
7493 ha->serial1 = icb->port_name[6];
7494 ha->serial2 = icb->port_name[7];
7495 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7496 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7498 icb->execution_throttle = cpu_to_le16(0xFFFF);
7500 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7502 /* Set minimum login_timeout to 4 seconds. */
7503 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7504 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7505 if (le16_to_cpu(nv->login_timeout) < 4)
7506 nv->login_timeout = cpu_to_le16(4);
7507 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7509 /* Set minimum RATOV to 100 tenths of a second. */
7512 ha->loop_reset_delay = nv->reset_delay;
7514 /* Link Down Timeout = 0:
7516 * When Port Down timer expires we will start returning
7517 * I/O's to OS with "DID_NO_CONNECT".
7519 * Link Down Timeout != 0:
7521 * The driver waits for the link to come up after link down
7522 * before returning I/Os to OS with "DID_NO_CONNECT".
7524 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7525 ha->loop_down_abort_time =
7526 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7528 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7529 ha->loop_down_abort_time =
7530 (LOOP_DOWN_TIME - ha->link_down_timeout);
7533 /* Need enough time to try and get the port back. */
7534 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7535 if (qlport_down_retry)
7536 ha->port_down_retry_count = qlport_down_retry;
7538 /* Set login_retry_count */
7539 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7540 if (ha->port_down_retry_count ==
7541 le16_to_cpu(nv->port_down_retry_count) &&
7542 ha->port_down_retry_count > 3)
7543 ha->login_retry_count = ha->port_down_retry_count;
7544 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7545 ha->login_retry_count = ha->port_down_retry_count;
7546 if (ql2xloginretrycount)
7547 ha->login_retry_count = ql2xloginretrycount;
7549 /* N2N: driver will initiate Login instead of FW */
7550 icb->firmware_options_3 |= cpu_to_le32(BIT_8);
7553 if (!vha->flags.init_done) {
7554 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7555 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7556 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7557 le16_to_cpu(icb->interrupt_delay_timer) : 2;
7559 icb->firmware_options_2 &= cpu_to_le32(
7560 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7561 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7562 ha->zio_mode = QLA_ZIO_MODE_6;
7564 ql_log(ql_log_info, vha, 0x006f,
7565 "ZIO mode %d enabled; timer delay (%d us).\n",
7566 ha->zio_mode, ha->zio_timer * 100);
7568 icb->firmware_options_2 |= cpu_to_le32(
7569 (uint32_t)ha->zio_mode);
7570 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7574 ql_log(ql_log_warn, vha, 0x0070,
7575 "NVRAM configuration failed.\n");
7581 qla27xx_print_image(struct scsi_qla_host *vha, char *name,
7582 struct qla27xx_image_status *image_status)
7584 ql_dbg(ql_dbg_init, vha, 0x018b,
7585 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
7587 image_status->image_status_mask,
7588 le16_to_cpu(image_status->generation),
7589 image_status->ver_major,
7590 image_status->ver_minor,
7591 image_status->bitmap,
7592 le32_to_cpu(image_status->checksum),
7593 le32_to_cpu(image_status->signature));
7597 qla28xx_check_aux_image_status_signature(
7598 struct qla27xx_image_status *image_status)
7600 ulong signature = le32_to_cpu(image_status->signature);
7602 return signature != QLA28XX_AUX_IMG_STATUS_SIGN;
7606 qla27xx_check_image_status_signature(struct qla27xx_image_status *image_status)
7608 ulong signature = le32_to_cpu(image_status->signature);
7611 signature != QLA27XX_IMG_STATUS_SIGN &&
7612 signature != QLA28XX_IMG_STATUS_SIGN;
7616 qla27xx_image_status_checksum(struct qla27xx_image_status *image_status)
7618 __le32 *p = (__force __le32 *)image_status;
7619 uint n = sizeof(*image_status) / sizeof(*p);
7623 sum += le32_to_cpup(p);
7629 qla28xx_component_bitmask(struct qla27xx_image_status *aux, uint bitmask)
7631 return aux->bitmap & bitmask ?
7632 QLA27XX_SECONDARY_IMAGE : QLA27XX_PRIMARY_IMAGE;
7636 qla28xx_component_status(
7637 struct active_regions *active_regions, struct qla27xx_image_status *aux)
7639 active_regions->aux.board_config =
7640 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_BOARD_CONFIG);
7642 active_regions->aux.vpd_nvram =
7643 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_VPD_NVRAM);
7645 active_regions->aux.npiv_config_0_1 =
7646 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1);
7648 active_regions->aux.npiv_config_2_3 =
7649 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3);
7653 qla27xx_compare_image_generation(
7654 struct qla27xx_image_status *pri_image_status,
7655 struct qla27xx_image_status *sec_image_status)
7657 /* calculate generation delta as uint16 (this accounts for wrap) */
7659 le16_to_cpu(pri_image_status->generation) -
7660 le16_to_cpu(sec_image_status->generation);
7662 ql_dbg(ql_dbg_init, NULL, 0x0180, "generation delta = %d\n", delta);
7668 qla28xx_get_aux_images(
7669 struct scsi_qla_host *vha, struct active_regions *active_regions)
7671 struct qla_hw_data *ha = vha->hw;
7672 struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
7673 bool valid_pri_image = false, valid_sec_image = false;
7674 bool active_pri_image = false, active_sec_image = false;
7676 if (!ha->flt_region_aux_img_status_pri) {
7677 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
7678 goto check_sec_image;
7681 qla24xx_read_flash_data(vha, (uint32_t *)&pri_aux_image_status,
7682 ha->flt_region_aux_img_status_pri,
7683 sizeof(pri_aux_image_status) >> 2);
7684 qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
7686 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
7687 ql_dbg(ql_dbg_init, vha, 0x018b,
7688 "Primary aux image signature (%#x) not valid\n",
7689 le32_to_cpu(pri_aux_image_status.signature));
7690 goto check_sec_image;
7693 if (qla27xx_image_status_checksum(&pri_aux_image_status)) {
7694 ql_dbg(ql_dbg_init, vha, 0x018c,
7695 "Primary aux image checksum failed\n");
7696 goto check_sec_image;
7699 valid_pri_image = true;
7701 if (pri_aux_image_status.image_status_mask & 1) {
7702 ql_dbg(ql_dbg_init, vha, 0x018d,
7703 "Primary aux image is active\n");
7704 active_pri_image = true;
7708 if (!ha->flt_region_aux_img_status_sec) {
7709 ql_dbg(ql_dbg_init, vha, 0x018a,
7710 "Secondary aux image not addressed\n");
7711 goto check_valid_image;
7714 qla24xx_read_flash_data(vha, (uint32_t *)&sec_aux_image_status,
7715 ha->flt_region_aux_img_status_sec,
7716 sizeof(sec_aux_image_status) >> 2);
7717 qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
7719 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
7720 ql_dbg(ql_dbg_init, vha, 0x018b,
7721 "Secondary aux image signature (%#x) not valid\n",
7722 le32_to_cpu(sec_aux_image_status.signature));
7723 goto check_valid_image;
7726 if (qla27xx_image_status_checksum(&sec_aux_image_status)) {
7727 ql_dbg(ql_dbg_init, vha, 0x018c,
7728 "Secondary aux image checksum failed\n");
7729 goto check_valid_image;
7732 valid_sec_image = true;
7734 if (sec_aux_image_status.image_status_mask & 1) {
7735 ql_dbg(ql_dbg_init, vha, 0x018d,
7736 "Secondary aux image is active\n");
7737 active_sec_image = true;
7741 if (valid_pri_image && active_pri_image &&
7742 valid_sec_image && active_sec_image) {
7743 if (qla27xx_compare_image_generation(&pri_aux_image_status,
7744 &sec_aux_image_status) >= 0) {
7745 qla28xx_component_status(active_regions,
7746 &pri_aux_image_status);
7748 qla28xx_component_status(active_regions,
7749 &sec_aux_image_status);
7751 } else if (valid_pri_image && active_pri_image) {
7752 qla28xx_component_status(active_regions, &pri_aux_image_status);
7753 } else if (valid_sec_image && active_sec_image) {
7754 qla28xx_component_status(active_regions, &sec_aux_image_status);
7757 ql_dbg(ql_dbg_init, vha, 0x018f,
7758 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u\n",
7759 active_regions->aux.board_config,
7760 active_regions->aux.vpd_nvram,
7761 active_regions->aux.npiv_config_0_1,
7762 active_regions->aux.npiv_config_2_3);
7766 qla27xx_get_active_image(struct scsi_qla_host *vha,
7767 struct active_regions *active_regions)
7769 struct qla_hw_data *ha = vha->hw;
7770 struct qla27xx_image_status pri_image_status, sec_image_status;
7771 bool valid_pri_image = false, valid_sec_image = false;
7772 bool active_pri_image = false, active_sec_image = false;
7774 if (!ha->flt_region_img_status_pri) {
7775 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
7776 goto check_sec_image;
7779 if (qla24xx_read_flash_data(vha, (uint32_t *)&pri_image_status,
7780 ha->flt_region_img_status_pri, sizeof(pri_image_status) >> 2) !=
7783 goto check_sec_image;
7785 qla27xx_print_image(vha, "Primary image", &pri_image_status);
7787 if (qla27xx_check_image_status_signature(&pri_image_status)) {
7788 ql_dbg(ql_dbg_init, vha, 0x018b,
7789 "Primary image signature (%#x) not valid\n",
7790 le32_to_cpu(pri_image_status.signature));
7791 goto check_sec_image;
7794 if (qla27xx_image_status_checksum(&pri_image_status)) {
7795 ql_dbg(ql_dbg_init, vha, 0x018c,
7796 "Primary image checksum failed\n");
7797 goto check_sec_image;
7800 valid_pri_image = true;
7802 if (pri_image_status.image_status_mask & 1) {
7803 ql_dbg(ql_dbg_init, vha, 0x018d,
7804 "Primary image is active\n");
7805 active_pri_image = true;
7809 if (!ha->flt_region_img_status_sec) {
7810 ql_dbg(ql_dbg_init, vha, 0x018a, "Secondary image not addressed\n");
7811 goto check_valid_image;
7814 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
7815 ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
7816 qla27xx_print_image(vha, "Secondary image", &sec_image_status);
7818 if (qla27xx_check_image_status_signature(&sec_image_status)) {
7819 ql_dbg(ql_dbg_init, vha, 0x018b,
7820 "Secondary image signature (%#x) not valid\n",
7821 le32_to_cpu(sec_image_status.signature));
7822 goto check_valid_image;
7825 if (qla27xx_image_status_checksum(&sec_image_status)) {
7826 ql_dbg(ql_dbg_init, vha, 0x018c,
7827 "Secondary image checksum failed\n");
7828 goto check_valid_image;
7831 valid_sec_image = true;
7833 if (sec_image_status.image_status_mask & 1) {
7834 ql_dbg(ql_dbg_init, vha, 0x018d,
7835 "Secondary image is active\n");
7836 active_sec_image = true;
7840 if (valid_pri_image && active_pri_image)
7841 active_regions->global = QLA27XX_PRIMARY_IMAGE;
7843 if (valid_sec_image && active_sec_image) {
7844 if (!active_regions->global ||
7845 qla27xx_compare_image_generation(
7846 &pri_image_status, &sec_image_status) < 0) {
7847 active_regions->global = QLA27XX_SECONDARY_IMAGE;
7851 ql_dbg(ql_dbg_init, vha, 0x018f, "active image %s (%u)\n",
7852 active_regions->global == QLA27XX_DEFAULT_IMAGE ?
7853 "default (boot/fw)" :
7854 active_regions->global == QLA27XX_PRIMARY_IMAGE ?
7856 active_regions->global == QLA27XX_SECONDARY_IMAGE ?
7857 "secondary" : "invalid",
7858 active_regions->global);
7861 bool qla24xx_risc_firmware_invalid(uint32_t *dword)
7864 !(dword[4] | dword[5] | dword[6] | dword[7]) ||
7865 !(~dword[4] | ~dword[5] | ~dword[6] | ~dword[7]);
7869 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
7873 uint templates, segments, fragment;
7878 uint32_t risc_addr, risc_size, risc_attr = 0;
7879 struct qla_hw_data *ha = vha->hw;
7880 struct req_que *req = ha->req_q_map[0];
7881 struct fwdt *fwdt = ha->fwdt;
7883 ql_dbg(ql_dbg_init, vha, 0x008b,
7884 "FW: Loading firmware from flash (%x).\n", faddr);
7886 dcode = (uint32_t *)req->ring;
7887 qla24xx_read_flash_data(vha, dcode, faddr, 8);
7888 if (qla24xx_risc_firmware_invalid(dcode)) {
7889 ql_log(ql_log_fatal, vha, 0x008c,
7890 "Unable to verify the integrity of flash firmware "
7892 ql_log(ql_log_fatal, vha, 0x008d,
7893 "Firmware data: %08x %08x %08x %08x.\n",
7894 dcode[0], dcode[1], dcode[2], dcode[3]);
7896 return QLA_FUNCTION_FAILED;
7899 dcode = (uint32_t *)req->ring;
7901 segments = FA_RISC_CODE_SEGMENTS;
7902 for (j = 0; j < segments; j++) {
7903 ql_dbg(ql_dbg_init, vha, 0x008d,
7904 "-> Loading segment %u...\n", j);
7905 qla24xx_read_flash_data(vha, dcode, faddr, 10);
7906 risc_addr = be32_to_cpu((__force __be32)dcode[2]);
7907 risc_size = be32_to_cpu((__force __be32)dcode[3]);
7909 *srisc_addr = risc_addr;
7910 risc_attr = be32_to_cpu((__force __be32)dcode[9]);
7913 dlen = ha->fw_transfer_size >> 2;
7914 for (fragment = 0; risc_size; fragment++) {
7915 if (dlen > risc_size)
7918 ql_dbg(ql_dbg_init, vha, 0x008e,
7919 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
7920 fragment, risc_addr, faddr, dlen);
7921 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
7922 for (i = 0; i < dlen; i++)
7923 dcode[i] = swab32(dcode[i]);
7925 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7927 ql_log(ql_log_fatal, vha, 0x008f,
7928 "-> Failed load firmware fragment %u.\n",
7930 return QLA_FUNCTION_FAILED;
7939 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
7942 templates = (risc_attr & BIT_9) ? 2 : 1;
7943 ql_dbg(ql_dbg_init, vha, 0x0160, "-> templates = %u\n", templates);
7944 for (j = 0; j < templates; j++, fwdt++) {
7945 vfree(fwdt->template);
7946 fwdt->template = NULL;
7949 dcode = (uint32_t *)req->ring;
7950 qla24xx_read_flash_data(vha, dcode, faddr, 7);
7951 risc_size = be32_to_cpu((__force __be32)dcode[2]);
7952 ql_dbg(ql_dbg_init, vha, 0x0161,
7953 "-> fwdt%u template array at %#x (%#x dwords)\n",
7954 j, faddr, risc_size);
7955 if (!risc_size || !~risc_size) {
7956 ql_dbg(ql_dbg_init, vha, 0x0162,
7957 "-> fwdt%u failed to read array\n", j);
7961 /* skip header and ignore checksum */
7965 ql_dbg(ql_dbg_init, vha, 0x0163,
7966 "-> fwdt%u template allocate template %#x words...\n",
7968 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
7969 if (!fwdt->template) {
7970 ql_log(ql_log_warn, vha, 0x0164,
7971 "-> fwdt%u failed allocate template.\n", j);
7975 dcode = fwdt->template;
7976 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
7978 if (!qla27xx_fwdt_template_valid(dcode)) {
7979 ql_log(ql_log_warn, vha, 0x0165,
7980 "-> fwdt%u failed template validate\n", j);
7984 dlen = qla27xx_fwdt_template_size(dcode);
7985 ql_dbg(ql_dbg_init, vha, 0x0166,
7986 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
7987 j, dlen, dlen / sizeof(*dcode));
7988 if (dlen > risc_size * sizeof(*dcode)) {
7989 ql_log(ql_log_warn, vha, 0x0167,
7990 "-> fwdt%u template exceeds array (%-lu bytes)\n",
7991 j, dlen - risc_size * sizeof(*dcode));
7995 fwdt->length = dlen;
7996 ql_dbg(ql_dbg_init, vha, 0x0168,
7997 "-> fwdt%u loaded template ok\n", j);
7999 faddr += risc_size + 1;
8005 vfree(fwdt->template);
8006 fwdt->template = NULL;
8012 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
8015 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8021 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
8022 struct fw_blob *blob;
8023 struct qla_hw_data *ha = vha->hw;
8024 struct req_que *req = ha->req_q_map[0];
8026 /* Load firmware blob. */
8027 blob = qla2x00_request_firmware(vha);
8029 ql_log(ql_log_info, vha, 0x0083,
8030 "Firmware image unavailable.\n");
8031 ql_log(ql_log_info, vha, 0x0084,
8032 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
8033 return QLA_FUNCTION_FAILED;
8038 wcode = (uint16_t *)req->ring;
8040 fwcode = (__force __be16 *)blob->fw->data;
8043 /* Validate firmware image by checking version. */
8044 if (blob->fw->size < 8 * sizeof(uint16_t)) {
8045 ql_log(ql_log_fatal, vha, 0x0085,
8046 "Unable to verify integrity of firmware image (%zd).\n",
8048 goto fail_fw_integrity;
8050 for (i = 0; i < 4; i++)
8051 wcode[i] = be16_to_cpu(fwcode[i + 4]);
8052 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
8053 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
8054 wcode[2] == 0 && wcode[3] == 0)) {
8055 ql_log(ql_log_fatal, vha, 0x0086,
8056 "Unable to verify integrity of firmware image.\n");
8057 ql_log(ql_log_fatal, vha, 0x0087,
8058 "Firmware data: %04x %04x %04x %04x.\n",
8059 wcode[0], wcode[1], wcode[2], wcode[3]);
8060 goto fail_fw_integrity;
8064 while (*seg && rval == QLA_SUCCESS) {
8066 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
8067 risc_size = be16_to_cpu(fwcode[3]);
8069 /* Validate firmware image size. */
8070 fwclen += risc_size * sizeof(uint16_t);
8071 if (blob->fw->size < fwclen) {
8072 ql_log(ql_log_fatal, vha, 0x0088,
8073 "Unable to verify integrity of firmware image "
8074 "(%zd).\n", blob->fw->size);
8075 goto fail_fw_integrity;
8079 while (risc_size > 0 && rval == QLA_SUCCESS) {
8080 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
8081 if (wlen > risc_size)
8083 ql_dbg(ql_dbg_init, vha, 0x0089,
8084 "Loading risc segment@ risc addr %x number of "
8085 "words 0x%x.\n", risc_addr, wlen);
8087 for (i = 0; i < wlen; i++)
8088 wcode[i] = swab16((__force u32)fwcode[i]);
8090 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
8093 ql_log(ql_log_fatal, vha, 0x008a,
8094 "Failed to load segment %d of firmware.\n",
8111 return QLA_FUNCTION_FAILED;
8115 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8118 uint templates, segments, fragment;
8121 uint32_t risc_addr, risc_size, risc_attr = 0;
8124 struct fw_blob *blob;
8126 struct qla_hw_data *ha = vha->hw;
8127 struct req_que *req = ha->req_q_map[0];
8128 struct fwdt *fwdt = ha->fwdt;
8130 ql_dbg(ql_dbg_init, vha, 0x0090,
8131 "-> FW: Loading via request-firmware.\n");
8133 blob = qla2x00_request_firmware(vha);
8135 ql_log(ql_log_warn, vha, 0x0092,
8136 "-> Firmware file not found.\n");
8138 return QLA_FUNCTION_FAILED;
8141 fwcode = (__force __be32 *)blob->fw->data;
8142 dcode = (__force uint32_t *)fwcode;
8143 if (qla24xx_risc_firmware_invalid(dcode)) {
8144 ql_log(ql_log_fatal, vha, 0x0093,
8145 "Unable to verify integrity of firmware image (%zd).\n",
8147 ql_log(ql_log_fatal, vha, 0x0095,
8148 "Firmware data: %08x %08x %08x %08x.\n",
8149 dcode[0], dcode[1], dcode[2], dcode[3]);
8150 return QLA_FUNCTION_FAILED;
8153 dcode = (uint32_t *)req->ring;
8155 segments = FA_RISC_CODE_SEGMENTS;
8156 for (j = 0; j < segments; j++) {
8157 ql_dbg(ql_dbg_init, vha, 0x0096,
8158 "-> Loading segment %u...\n", j);
8159 risc_addr = be32_to_cpu(fwcode[2]);
8160 risc_size = be32_to_cpu(fwcode[3]);
8163 *srisc_addr = risc_addr;
8164 risc_attr = be32_to_cpu(fwcode[9]);
8167 dlen = ha->fw_transfer_size >> 2;
8168 for (fragment = 0; risc_size; fragment++) {
8169 if (dlen > risc_size)
8172 ql_dbg(ql_dbg_init, vha, 0x0097,
8173 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
8174 fragment, risc_addr,
8175 (uint32_t)(fwcode - (typeof(fwcode))blob->fw->data),
8178 for (i = 0; i < dlen; i++)
8179 dcode[i] = swab32((__force u32)fwcode[i]);
8181 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
8183 ql_log(ql_log_fatal, vha, 0x0098,
8184 "-> Failed load firmware fragment %u.\n",
8186 return QLA_FUNCTION_FAILED;
8195 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8198 templates = (risc_attr & BIT_9) ? 2 : 1;
8199 ql_dbg(ql_dbg_init, vha, 0x0170, "-> templates = %u\n", templates);
8200 for (j = 0; j < templates; j++, fwdt++) {
8201 vfree(fwdt->template);
8202 fwdt->template = NULL;
8205 risc_size = be32_to_cpu(fwcode[2]);
8206 ql_dbg(ql_dbg_init, vha, 0x0171,
8207 "-> fwdt%u template array at %#x (%#x dwords)\n",
8208 j, (uint32_t)((void *)fwcode - (void *)blob->fw->data),
8210 if (!risc_size || !~risc_size) {
8211 ql_dbg(ql_dbg_init, vha, 0x0172,
8212 "-> fwdt%u failed to read array\n", j);
8216 /* skip header and ignore checksum */
8220 ql_dbg(ql_dbg_init, vha, 0x0173,
8221 "-> fwdt%u template allocate template %#x words...\n",
8223 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
8224 if (!fwdt->template) {
8225 ql_log(ql_log_warn, vha, 0x0174,
8226 "-> fwdt%u failed allocate template.\n", j);
8230 dcode = fwdt->template;
8231 for (i = 0; i < risc_size; i++)
8232 dcode[i] = (__force u32)fwcode[i];
8234 if (!qla27xx_fwdt_template_valid(dcode)) {
8235 ql_log(ql_log_warn, vha, 0x0175,
8236 "-> fwdt%u failed template validate\n", j);
8240 dlen = qla27xx_fwdt_template_size(dcode);
8241 ql_dbg(ql_dbg_init, vha, 0x0176,
8242 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8243 j, dlen, dlen / sizeof(*dcode));
8244 if (dlen > risc_size * sizeof(*dcode)) {
8245 ql_log(ql_log_warn, vha, 0x0177,
8246 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8247 j, dlen - risc_size * sizeof(*dcode));
8251 fwdt->length = dlen;
8252 ql_dbg(ql_dbg_init, vha, 0x0178,
8253 "-> fwdt%u loaded template ok\n", j);
8255 fwcode += risc_size + 1;
8261 vfree(fwdt->template);
8262 fwdt->template = NULL;
8269 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8273 if (ql2xfwloadbin == 1)
8274 return qla81xx_load_risc(vha, srisc_addr);
8278 * 1) Firmware via request-firmware interface (.bin file).
8279 * 2) Firmware residing in flash.
8281 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8282 if (rval == QLA_SUCCESS)
8285 return qla24xx_load_risc_flash(vha, srisc_addr,
8286 vha->hw->flt_region_fw);
8290 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8293 struct qla_hw_data *ha = vha->hw;
8294 struct active_regions active_regions = { };
8296 if (ql2xfwloadbin == 2)
8299 /* FW Load priority:
8300 * 1) Firmware residing in flash.
8301 * 2) Firmware via request-firmware interface (.bin file).
8302 * 3) Golden-Firmware residing in flash -- (limited operation).
8305 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8306 goto try_primary_fw;
8308 qla27xx_get_active_image(vha, &active_regions);
8310 if (active_regions.global != QLA27XX_SECONDARY_IMAGE)
8311 goto try_primary_fw;
8313 ql_dbg(ql_dbg_init, vha, 0x008b,
8314 "Loading secondary firmware image.\n");
8315 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw_sec);
8320 ql_dbg(ql_dbg_init, vha, 0x008b,
8321 "Loading primary firmware image.\n");
8322 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
8327 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8328 if (!rval || !ha->flt_region_gold_fw)
8331 ql_log(ql_log_info, vha, 0x0099,
8332 "Attempting to fallback to golden firmware.\n");
8333 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
8337 ql_log(ql_log_info, vha, 0x009a, "Need firmware flash update.\n");
8338 ha->flags.running_gold_fw = 1;
8343 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
8346 struct qla_hw_data *ha = vha->hw;
8348 if (ha->flags.pci_channel_io_perm_failure)
8350 if (!IS_FWI2_CAPABLE(ha))
8352 if (!ha->fw_major_version)
8354 if (!ha->flags.fw_started)
8357 ret = qla2x00_stop_firmware(vha);
8358 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
8359 ret != QLA_INVALID_COMMAND && retries ; retries--) {
8360 ha->isp_ops->reset_chip(vha);
8361 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
8363 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
8365 ql_log(ql_log_info, vha, 0x8015,
8366 "Attempting retry of stop-firmware command.\n");
8367 ret = qla2x00_stop_firmware(vha);
8371 ha->flags.fw_init_done = 0;
8375 qla24xx_configure_vhba(scsi_qla_host_t *vha)
8377 int rval = QLA_SUCCESS;
8379 uint16_t mb[MAILBOX_REGISTER_COUNT];
8380 struct qla_hw_data *ha = vha->hw;
8381 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
8386 rval = qla2x00_fw_ready(base_vha);
8388 if (rval == QLA_SUCCESS) {
8389 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8390 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8393 vha->flags.management_server_logged_in = 0;
8395 /* Login to SNS first */
8396 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
8398 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
8399 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
8400 ql_dbg(ql_dbg_init, vha, 0x0120,
8401 "Failed SNS login: loop_id=%x, rval2=%d\n",
8404 ql_dbg(ql_dbg_init, vha, 0x0103,
8405 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
8406 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
8407 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
8408 return (QLA_FUNCTION_FAILED);
8411 atomic_set(&vha->loop_down_timer, 0);
8412 atomic_set(&vha->loop_state, LOOP_UP);
8413 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8414 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
8415 rval = qla2x00_loop_resync(base_vha);
8420 /* 84XX Support **************************************************************/
8422 static LIST_HEAD(qla_cs84xx_list);
8423 static DEFINE_MUTEX(qla_cs84xx_mutex);
8425 static struct qla_chip_state_84xx *
8426 qla84xx_get_chip(struct scsi_qla_host *vha)
8428 struct qla_chip_state_84xx *cs84xx;
8429 struct qla_hw_data *ha = vha->hw;
8431 mutex_lock(&qla_cs84xx_mutex);
8433 /* Find any shared 84xx chip. */
8434 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
8435 if (cs84xx->bus == ha->pdev->bus) {
8436 kref_get(&cs84xx->kref);
8441 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
8445 kref_init(&cs84xx->kref);
8446 spin_lock_init(&cs84xx->access_lock);
8447 mutex_init(&cs84xx->fw_update_mutex);
8448 cs84xx->bus = ha->pdev->bus;
8450 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
8452 mutex_unlock(&qla_cs84xx_mutex);
8457 __qla84xx_chip_release(struct kref *kref)
8459 struct qla_chip_state_84xx *cs84xx =
8460 container_of(kref, struct qla_chip_state_84xx, kref);
8462 mutex_lock(&qla_cs84xx_mutex);
8463 list_del(&cs84xx->list);
8464 mutex_unlock(&qla_cs84xx_mutex);
8469 qla84xx_put_chip(struct scsi_qla_host *vha)
8471 struct qla_hw_data *ha = vha->hw;
8474 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
8478 qla84xx_init_chip(scsi_qla_host_t *vha)
8482 struct qla_hw_data *ha = vha->hw;
8484 mutex_lock(&ha->cs84xx->fw_update_mutex);
8486 rval = qla84xx_verify_chip(vha, status);
8488 mutex_unlock(&ha->cs84xx->fw_update_mutex);
8490 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED :
8494 /* 81XX Support **************************************************************/
8497 qla81xx_nvram_config(scsi_qla_host_t *vha)
8500 struct init_cb_81xx *icb;
8501 struct nvram_81xx *nv;
8503 uint8_t *dptr1, *dptr2;
8506 struct qla_hw_data *ha = vha->hw;
8508 struct active_regions active_regions = { };
8511 icb = (struct init_cb_81xx *)ha->init_cb;
8514 /* Determine NVRAM starting address. */
8515 ha->nvram_size = sizeof(*nv);
8516 ha->vpd_size = FA_NVRAM_VPD_SIZE;
8517 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
8518 ha->vpd_size = FA_VPD_SIZE_82XX;
8520 if (IS_QLA28XX(ha) || IS_QLA27XX(ha))
8521 qla28xx_get_aux_images(vha, &active_regions);
8523 /* Get VPD data into cache */
8524 ha->vpd = ha->nvram + VPD_OFFSET;
8526 faddr = ha->flt_region_vpd;
8527 if (IS_QLA28XX(ha)) {
8528 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8529 faddr = ha->flt_region_vpd_sec;
8530 ql_dbg(ql_dbg_init, vha, 0x0110,
8531 "Loading %s nvram image.\n",
8532 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8533 "primary" : "secondary");
8535 ha->isp_ops->read_optrom(vha, ha->vpd, faddr << 2, ha->vpd_size);
8537 /* Get NVRAM data into cache and calculate checksum. */
8538 faddr = ha->flt_region_nvram;
8539 if (IS_QLA28XX(ha)) {
8540 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8541 faddr = ha->flt_region_nvram_sec;
8543 ql_dbg(ql_dbg_init, vha, 0x0110,
8544 "Loading %s nvram image.\n",
8545 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8546 "primary" : "secondary");
8547 ha->isp_ops->read_optrom(vha, ha->nvram, faddr << 2, ha->nvram_size);
8549 dptr = (__force __le32 *)nv;
8550 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
8551 chksum += le32_to_cpu(*dptr);
8553 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
8554 "Contents of NVRAM:\n");
8555 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
8556 nv, ha->nvram_size);
8558 /* Bad NVRAM data, set defaults parameters. */
8559 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
8560 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
8561 /* Reset NVRAM data. */
8562 ql_log(ql_log_info, vha, 0x0073,
8563 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
8564 chksum, nv->id, le16_to_cpu(nv->nvram_version));
8565 ql_dump_buffer(ql_dbg_init, vha, 0x0073, nv, sizeof(*nv));
8566 ql_log(ql_log_info, vha, 0x0074,
8567 "Falling back to functioning (yet invalid -- WWPN) "
8571 * Set default initialization control block.
8573 memset(nv, 0, ha->nvram_size);
8574 nv->nvram_version = cpu_to_le16(ICB_VERSION);
8575 nv->version = cpu_to_le16(ICB_VERSION);
8576 nv->frame_payload_size = cpu_to_le16(2048);
8577 nv->execution_throttle = cpu_to_le16(0xFFFF);
8578 nv->exchange_count = cpu_to_le16(0);
8579 nv->port_name[0] = 0x21;
8580 nv->port_name[1] = 0x00 + ha->port_no + 1;
8581 nv->port_name[2] = 0x00;
8582 nv->port_name[3] = 0xe0;
8583 nv->port_name[4] = 0x8b;
8584 nv->port_name[5] = 0x1c;
8585 nv->port_name[6] = 0x55;
8586 nv->port_name[7] = 0x86;
8587 nv->node_name[0] = 0x20;
8588 nv->node_name[1] = 0x00;
8589 nv->node_name[2] = 0x00;
8590 nv->node_name[3] = 0xe0;
8591 nv->node_name[4] = 0x8b;
8592 nv->node_name[5] = 0x1c;
8593 nv->node_name[6] = 0x55;
8594 nv->node_name[7] = 0x86;
8595 nv->login_retry_count = cpu_to_le16(8);
8596 nv->interrupt_delay_timer = cpu_to_le16(0);
8597 nv->login_timeout = cpu_to_le16(0);
8598 nv->firmware_options_1 =
8599 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
8600 nv->firmware_options_2 = cpu_to_le32(2 << 4);
8601 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
8602 nv->firmware_options_3 = cpu_to_le32(2 << 13);
8603 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
8604 nv->efi_parameters = cpu_to_le32(0);
8605 nv->reset_delay = 5;
8606 nv->max_luns_per_target = cpu_to_le16(128);
8607 nv->port_down_retry_count = cpu_to_le16(30);
8608 nv->link_down_timeout = cpu_to_le16(180);
8609 nv->enode_mac[0] = 0x00;
8610 nv->enode_mac[1] = 0xC0;
8611 nv->enode_mac[2] = 0xDD;
8612 nv->enode_mac[3] = 0x04;
8613 nv->enode_mac[4] = 0x05;
8614 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
8619 if (IS_T10_PI_CAPABLE(ha))
8620 nv->frame_payload_size &= cpu_to_le16(~7);
8622 qlt_81xx_config_nvram_stage1(vha, nv);
8624 /* Reset Initialization control block */
8625 memset(icb, 0, ha->init_cb_size);
8627 /* Copy 1st segment. */
8628 dptr1 = (uint8_t *)icb;
8629 dptr2 = (uint8_t *)&nv->version;
8630 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
8632 *dptr1++ = *dptr2++;
8634 icb->login_retry_count = nv->login_retry_count;
8636 /* Copy 2nd segment. */
8637 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
8638 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
8639 cnt = (uint8_t *)&icb->reserved_5 -
8640 (uint8_t *)&icb->interrupt_delay_timer;
8642 *dptr1++ = *dptr2++;
8644 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
8645 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8646 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
8647 icb->enode_mac[0] = 0x00;
8648 icb->enode_mac[1] = 0xC0;
8649 icb->enode_mac[2] = 0xDD;
8650 icb->enode_mac[3] = 0x04;
8651 icb->enode_mac[4] = 0x05;
8652 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
8655 /* Use extended-initialization control block. */
8656 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
8657 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
8659 * Setup driver NVRAM options.
8661 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
8664 qlt_81xx_config_nvram_stage2(vha, icb);
8666 /* Use alternate WWN? */
8667 if (nv->host_p & cpu_to_le32(BIT_15)) {
8668 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
8669 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
8672 /* Prepare nodename */
8673 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
8675 * Firmware will apply the following mask if the nodename was
8678 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
8679 icb->node_name[0] &= 0xF0;
8682 if (IS_QLA28XX(ha) || IS_QLA27XX(ha)) {
8683 if ((nv->enhanced_features & BIT_7) == 0)
8684 ha->flags.scm_supported_a = 1;
8687 /* Set host adapter parameters. */
8688 ha->flags.disable_risc_code_load = 0;
8689 ha->flags.enable_lip_reset = 0;
8690 ha->flags.enable_lip_full_login =
8691 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
8692 ha->flags.enable_target_reset =
8693 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
8694 ha->flags.enable_led_scheme = 0;
8695 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
8697 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
8698 (BIT_6 | BIT_5 | BIT_4)) >> 4;
8700 /* save HBA serial number */
8701 ha->serial0 = icb->port_name[5];
8702 ha->serial1 = icb->port_name[6];
8703 ha->serial2 = icb->port_name[7];
8704 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
8705 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
8707 icb->execution_throttle = cpu_to_le16(0xFFFF);
8709 ha->retry_count = le16_to_cpu(nv->login_retry_count);
8711 /* Set minimum login_timeout to 4 seconds. */
8712 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
8713 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
8714 if (le16_to_cpu(nv->login_timeout) < 4)
8715 nv->login_timeout = cpu_to_le16(4);
8716 ha->login_timeout = le16_to_cpu(nv->login_timeout);
8718 /* Set minimum RATOV to 100 tenths of a second. */
8721 ha->loop_reset_delay = nv->reset_delay;
8723 /* Link Down Timeout = 0:
8725 * When Port Down timer expires we will start returning
8726 * I/O's to OS with "DID_NO_CONNECT".
8728 * Link Down Timeout != 0:
8730 * The driver waits for the link to come up after link down
8731 * before returning I/Os to OS with "DID_NO_CONNECT".
8733 if (le16_to_cpu(nv->link_down_timeout) == 0) {
8734 ha->loop_down_abort_time =
8735 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
8737 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
8738 ha->loop_down_abort_time =
8739 (LOOP_DOWN_TIME - ha->link_down_timeout);
8742 /* Need enough time to try and get the port back. */
8743 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8744 if (qlport_down_retry)
8745 ha->port_down_retry_count = qlport_down_retry;
8747 /* Set login_retry_count */
8748 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8749 if (ha->port_down_retry_count ==
8750 le16_to_cpu(nv->port_down_retry_count) &&
8751 ha->port_down_retry_count > 3)
8752 ha->login_retry_count = ha->port_down_retry_count;
8753 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8754 ha->login_retry_count = ha->port_down_retry_count;
8755 if (ql2xloginretrycount)
8756 ha->login_retry_count = ql2xloginretrycount;
8758 /* if not running MSI-X we need handshaking on interrupts */
8759 if (!vha->hw->flags.msix_enabled &&
8760 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)))
8761 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
8764 if (!vha->flags.init_done) {
8765 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8766 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8767 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8768 le16_to_cpu(icb->interrupt_delay_timer) : 2;
8770 icb->firmware_options_2 &= cpu_to_le32(
8771 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8772 vha->flags.process_response_queue = 0;
8773 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8774 ha->zio_mode = QLA_ZIO_MODE_6;
8776 ql_log(ql_log_info, vha, 0x0075,
8777 "ZIO mode %d enabled; timer delay (%d us).\n",
8779 ha->zio_timer * 100);
8781 icb->firmware_options_2 |= cpu_to_le32(
8782 (uint32_t)ha->zio_mode);
8783 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8784 vha->flags.process_response_queue = 1;
8787 /* enable RIDA Format2 */
8788 icb->firmware_options_3 |= cpu_to_le32(BIT_0);
8790 /* N2N: driver will initiate Login instead of FW */
8791 icb->firmware_options_3 |= cpu_to_le32(BIT_8);
8793 /* Determine NVMe/FCP priority for target ports */
8794 ha->fc4_type_priority = qla2xxx_get_fc4_priority(vha);
8797 ql_log(ql_log_warn, vha, 0x0076,
8798 "NVRAM configuration failed.\n");
8804 qla82xx_restart_isp(scsi_qla_host_t *vha)
8807 struct qla_hw_data *ha = vha->hw;
8808 struct scsi_qla_host *vp;
8809 unsigned long flags;
8811 status = qla2x00_init_rings(vha);
8813 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8814 ha->flags.chip_reset_done = 1;
8816 status = qla2x00_fw_ready(vha);
8818 /* Issue a marker after FW becomes ready. */
8819 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8820 vha->flags.online = 1;
8821 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8824 /* if no cable then assume it's good */
8825 if ((vha->device_flags & DFLG_NO_CABLE))
8830 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8832 if (!atomic_read(&vha->loop_down_timer)) {
8834 * Issue marker command only when we are going
8835 * to start the I/O .
8837 vha->marker_needed = 1;
8840 ha->isp_ops->enable_intrs(ha);
8842 ha->isp_abort_cnt = 0;
8843 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
8845 /* Update the firmware version */
8846 status = qla82xx_check_md_needed(vha);
8849 ha->flags.fce_enabled = 1;
8851 fce_calc_size(ha->fce_bufs));
8852 rval = qla2x00_enable_fce_trace(vha,
8853 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
8856 ql_log(ql_log_warn, vha, 0x8001,
8857 "Unable to reinitialize FCE (%d).\n",
8859 ha->flags.fce_enabled = 0;
8864 memset(ha->eft, 0, EFT_SIZE);
8865 rval = qla2x00_enable_eft_trace(vha,
8866 ha->eft_dma, EFT_NUM_BUFFERS);
8868 ql_log(ql_log_warn, vha, 0x8010,
8869 "Unable to reinitialize EFT (%d).\n",
8876 ql_dbg(ql_dbg_taskm, vha, 0x8011,
8877 "qla82xx_restart_isp succeeded.\n");
8879 spin_lock_irqsave(&ha->vport_slock, flags);
8880 list_for_each_entry(vp, &ha->vp_list, list) {
8882 atomic_inc(&vp->vref_count);
8883 spin_unlock_irqrestore(&ha->vport_slock, flags);
8885 qla2x00_vp_abort_isp(vp);
8887 spin_lock_irqsave(&ha->vport_slock, flags);
8888 atomic_dec(&vp->vref_count);
8891 spin_unlock_irqrestore(&ha->vport_slock, flags);
8894 ql_log(ql_log_warn, vha, 0x8016,
8895 "qla82xx_restart_isp **** FAILED ****.\n");
8902 * qla24xx_get_fcp_prio
8903 * Gets the fcp cmd priority value for the logged in port.
8904 * Looks for a match of the port descriptors within
8905 * each of the fcp prio config entries. If a match is found,
8906 * the tag (priority) value is returned.
8909 * vha = scsi host structure pointer.
8910 * fcport = port structure pointer.
8913 * non-zero (if found)
8920 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8923 uint8_t pid_match, wwn_match;
8925 uint32_t pid1, pid2;
8926 uint64_t wwn1, wwn2;
8927 struct qla_fcp_prio_entry *pri_entry;
8928 struct qla_hw_data *ha = vha->hw;
8930 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
8934 entries = ha->fcp_prio_cfg->num_entries;
8935 pri_entry = &ha->fcp_prio_cfg->entry[0];
8937 for (i = 0; i < entries; i++) {
8938 pid_match = wwn_match = 0;
8940 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
8945 /* check source pid for a match */
8946 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
8947 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
8948 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
8949 if (pid1 == INVALID_PORT_ID)
8951 else if (pid1 == pid2)
8955 /* check destination pid for a match */
8956 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
8957 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
8958 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
8959 if (pid1 == INVALID_PORT_ID)
8961 else if (pid1 == pid2)
8965 /* check source WWN for a match */
8966 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
8967 wwn1 = wwn_to_u64(vha->port_name);
8968 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
8969 if (wwn2 == (uint64_t)-1)
8971 else if (wwn1 == wwn2)
8975 /* check destination WWN for a match */
8976 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
8977 wwn1 = wwn_to_u64(fcport->port_name);
8978 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
8979 if (wwn2 == (uint64_t)-1)
8981 else if (wwn1 == wwn2)
8985 if (pid_match == 2 || wwn_match == 2) {
8986 /* Found a matching entry */
8987 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
8988 priority = pri_entry->tag;
8999 * qla24xx_update_fcport_fcp_prio
9000 * Activates fcp priority for the logged in fc port
9003 * vha = scsi host structure pointer.
9004 * fcp = port structure pointer.
9007 * QLA_SUCCESS or QLA_FUNCTION_FAILED
9013 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
9019 if (fcport->port_type != FCT_TARGET ||
9020 fcport->loop_id == FC_NO_LOOP_ID)
9021 return QLA_FUNCTION_FAILED;
9023 priority = qla24xx_get_fcp_prio(vha, fcport);
9025 return QLA_FUNCTION_FAILED;
9027 if (IS_P3P_TYPE(vha->hw)) {
9028 fcport->fcp_prio = priority & 0xf;
9032 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
9033 if (ret == QLA_SUCCESS) {
9034 if (fcport->fcp_prio != priority)
9035 ql_dbg(ql_dbg_user, vha, 0x709e,
9036 "Updated FCP_CMND priority - value=%d loop_id=%d "
9037 "port_id=%02x%02x%02x.\n", priority,
9038 fcport->loop_id, fcport->d_id.b.domain,
9039 fcport->d_id.b.area, fcport->d_id.b.al_pa);
9040 fcport->fcp_prio = priority & 0xf;
9042 ql_dbg(ql_dbg_user, vha, 0x704f,
9043 "Unable to update FCP_CMND priority - ret=0x%x for "
9044 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
9045 fcport->d_id.b.domain, fcport->d_id.b.area,
9046 fcport->d_id.b.al_pa);
9051 * qla24xx_update_all_fcp_prio
9052 * Activates fcp priority for all the logged in ports
9055 * ha = adapter block pointer.
9058 * QLA_SUCCESS or QLA_FUNCTION_FAILED
9064 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
9069 ret = QLA_FUNCTION_FAILED;
9070 /* We need to set priority for all logged in ports */
9071 list_for_each_entry(fcport, &vha->vp_fcports, list)
9072 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
9077 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
9078 int vp_idx, bool startqp)
9083 struct qla_hw_data *ha = vha->hw;
9084 uint16_t qpair_id = 0;
9085 struct qla_qpair *qpair = NULL;
9086 struct qla_msix_entry *msix;
9088 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
9089 ql_log(ql_log_warn, vha, 0x00181,
9090 "FW/Driver is not multi-queue capable.\n");
9094 if (ql2xmqsupport || ql2xnvmeenable) {
9095 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
9096 if (qpair == NULL) {
9097 ql_log(ql_log_warn, vha, 0x0182,
9098 "Failed to allocate memory for queue pair.\n");
9102 qpair->hw = vha->hw;
9104 qpair->qp_lock_ptr = &qpair->qp_lock;
9105 spin_lock_init(&qpair->qp_lock);
9106 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
9108 /* Assign available que pair id */
9109 mutex_lock(&ha->mq_lock);
9110 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
9111 if (ha->num_qpairs >= ha->max_qpairs) {
9112 mutex_unlock(&ha->mq_lock);
9113 ql_log(ql_log_warn, vha, 0x0183,
9114 "No resources to create additional q pair.\n");
9118 set_bit(qpair_id, ha->qpair_qid_map);
9119 ha->queue_pair_map[qpair_id] = qpair;
9120 qpair->id = qpair_id;
9121 qpair->vp_idx = vp_idx;
9122 qpair->fw_started = ha->flags.fw_started;
9123 INIT_LIST_HEAD(&qpair->hints_list);
9124 qpair->chip_reset = ha->base_qpair->chip_reset;
9125 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
9126 qpair->enable_explicit_conf =
9127 ha->base_qpair->enable_explicit_conf;
9129 for (i = 0; i < ha->msix_count; i++) {
9130 msix = &ha->msix_entries[i];
9134 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
9135 "Vector %x selected for qpair\n", msix->vector);
9139 ql_log(ql_log_warn, vha, 0x0184,
9140 "Out of MSI-X vectors!.\n");
9144 qpair->msix->in_use = 1;
9145 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
9146 qpair->pdev = ha->pdev;
9147 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
9148 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
9150 mutex_unlock(&ha->mq_lock);
9152 /* Create response queue first */
9153 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
9155 ql_log(ql_log_warn, vha, 0x0185,
9156 "Failed to create response queue.\n");
9160 qpair->rsp = ha->rsp_q_map[rsp_id];
9162 /* Create request queue */
9163 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
9166 ql_log(ql_log_warn, vha, 0x0186,
9167 "Failed to create request queue.\n");
9171 qpair->req = ha->req_q_map[req_id];
9172 qpair->rsp->req = qpair->req;
9173 qpair->rsp->qpair = qpair;
9174 /* init qpair to this cpu. Will adjust at run time. */
9175 qla_cpu_update(qpair, smp_processor_id());
9177 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
9178 if (ha->fw_attributes & BIT_4)
9179 qpair->difdix_supported = 1;
9182 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
9183 if (!qpair->srb_mempool) {
9184 ql_log(ql_log_warn, vha, 0xd036,
9185 "Failed to create srb mempool for qpair %d\n",
9190 /* Mark as online */
9193 if (!vha->flags.qpairs_available)
9194 vha->flags.qpairs_available = 1;
9196 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
9197 "Request/Response queue pair created, id %d\n",
9199 ql_dbg(ql_dbg_init, vha, 0x0187,
9200 "Request/Response queue pair created, id %d\n",
9207 qla25xx_delete_rsp_que(vha, qpair->rsp);
9209 mutex_lock(&ha->mq_lock);
9210 qpair->msix->in_use = 0;
9211 list_del(&qpair->qp_list_elem);
9212 if (list_empty(&vha->qp_list))
9213 vha->flags.qpairs_available = 0;
9215 ha->queue_pair_map[qpair_id] = NULL;
9216 clear_bit(qpair_id, ha->qpair_qid_map);
9218 mutex_unlock(&ha->mq_lock);
9224 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
9226 int ret = QLA_FUNCTION_FAILED;
9227 struct qla_hw_data *ha = qpair->hw;
9229 qpair->delete_in_progress = 1;
9231 ret = qla25xx_delete_req_que(vha, qpair->req);
9232 if (ret != QLA_SUCCESS)
9235 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
9236 if (ret != QLA_SUCCESS)
9239 mutex_lock(&ha->mq_lock);
9240 ha->queue_pair_map[qpair->id] = NULL;
9241 clear_bit(qpair->id, ha->qpair_qid_map);
9243 list_del(&qpair->qp_list_elem);
9244 if (list_empty(&vha->qp_list)) {
9245 vha->flags.qpairs_available = 0;
9246 vha->flags.qpairs_req_created = 0;
9247 vha->flags.qpairs_rsp_created = 0;
9249 mempool_destroy(qpair->srb_mempool);
9251 mutex_unlock(&ha->mq_lock);
9259 qla2x00_count_set_bits(uint32_t num)
9261 /* Brian Kernighan's Algorithm */
9272 qla2x00_get_num_tgts(scsi_qla_host_t *vha)
9280 list_for_each_entry_safe(f, tf, &vha->vp_fcports, list) {
9281 if (f->port_type != FCT_TARGET)
9288 int qla2xxx_reset_stats(struct Scsi_Host *host, u32 flags)
9290 scsi_qla_host_t *vha = shost_priv(host);
9291 fc_port_t *fcport = NULL;
9292 unsigned long int_flags;
9294 if (flags & QLA2XX_HW_ERROR)
9295 vha->hw_err_cnt = 0;
9296 if (flags & QLA2XX_SHT_LNK_DWN)
9297 vha->short_link_down_cnt = 0;
9298 if (flags & QLA2XX_INT_ERR)
9299 vha->interface_err_cnt = 0;
9300 if (flags & QLA2XX_CMD_TIMEOUT)
9301 vha->cmd_timeout_cnt = 0;
9302 if (flags & QLA2XX_RESET_CMD_ERR)
9303 vha->reset_cmd_err_cnt = 0;
9304 if (flags & QLA2XX_TGT_SHT_LNK_DOWN) {
9305 spin_lock_irqsave(&vha->hw->tgt.sess_lock, int_flags);
9306 list_for_each_entry(fcport, &vha->vp_fcports, list) {
9307 fcport->tgt_short_link_down_cnt = 0;
9308 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
9310 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, int_flags);
9312 vha->link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
9316 int qla2xxx_start_stats(struct Scsi_Host *host, u32 flags)
9318 return qla2xxx_reset_stats(host, flags);
9321 int qla2xxx_stop_stats(struct Scsi_Host *host, u32 flags)
9323 return qla2xxx_reset_stats(host, flags);
9326 int qla2xxx_get_ini_stats(struct Scsi_Host *host, u32 flags,
9327 void *data, u64 size)
9329 scsi_qla_host_t *vha = shost_priv(host);
9330 struct ql_vnd_host_stats_resp *resp = (struct ql_vnd_host_stats_resp *)data;
9331 struct ql_vnd_stats *rsp_data = &resp->stats;
9332 u64 ini_entry_count = 0;
9334 u64 entry_count = 0;
9336 u32 tmp_stat_type = 0;
9337 fc_port_t *fcport = NULL;
9338 unsigned long int_flags;
9340 /* Copy stat type to work on it */
9341 tmp_stat_type = flags;
9343 if (tmp_stat_type & BIT_17) {
9344 num_tgt = qla2x00_get_num_tgts(vha);
9346 tmp_stat_type &= ~(1 << 17);
9348 ini_entry_count = qla2x00_count_set_bits(tmp_stat_type);
9350 entry_count = ini_entry_count + num_tgt;
9352 rsp_data->entry_count = entry_count;
9355 if (flags & QLA2XX_HW_ERROR) {
9356 rsp_data->entry[i].stat_type = QLA2XX_HW_ERROR;
9357 rsp_data->entry[i].tgt_num = 0x0;
9358 rsp_data->entry[i].cnt = vha->hw_err_cnt;
9362 if (flags & QLA2XX_SHT_LNK_DWN) {
9363 rsp_data->entry[i].stat_type = QLA2XX_SHT_LNK_DWN;
9364 rsp_data->entry[i].tgt_num = 0x0;
9365 rsp_data->entry[i].cnt = vha->short_link_down_cnt;
9369 if (flags & QLA2XX_INT_ERR) {
9370 rsp_data->entry[i].stat_type = QLA2XX_INT_ERR;
9371 rsp_data->entry[i].tgt_num = 0x0;
9372 rsp_data->entry[i].cnt = vha->interface_err_cnt;
9376 if (flags & QLA2XX_CMD_TIMEOUT) {
9377 rsp_data->entry[i].stat_type = QLA2XX_CMD_TIMEOUT;
9378 rsp_data->entry[i].tgt_num = 0x0;
9379 rsp_data->entry[i].cnt = vha->cmd_timeout_cnt;
9383 if (flags & QLA2XX_RESET_CMD_ERR) {
9384 rsp_data->entry[i].stat_type = QLA2XX_RESET_CMD_ERR;
9385 rsp_data->entry[i].tgt_num = 0x0;
9386 rsp_data->entry[i].cnt = vha->reset_cmd_err_cnt;
9390 /* i will continue from previous loop, as target
9391 * entries are after initiator
9393 if (flags & QLA2XX_TGT_SHT_LNK_DOWN) {
9394 spin_lock_irqsave(&vha->hw->tgt.sess_lock, int_flags);
9395 list_for_each_entry(fcport, &vha->vp_fcports, list) {
9396 if (fcport->port_type != FCT_TARGET)
9400 rsp_data->entry[i].stat_type = QLA2XX_TGT_SHT_LNK_DOWN;
9401 rsp_data->entry[i].tgt_num = fcport->rport->number;
9402 rsp_data->entry[i].cnt = fcport->tgt_short_link_down_cnt;
9405 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, int_flags);
9407 resp->status = EXT_STATUS_OK;
9412 int qla2xxx_get_tgt_stats(struct Scsi_Host *host, u32 flags,
9413 struct fc_rport *rport, void *data, u64 size)
9415 struct ql_vnd_tgt_stats_resp *tgt_data = data;
9416 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
9418 tgt_data->status = 0;
9419 tgt_data->stats.entry_count = 1;
9420 tgt_data->stats.entry[0].stat_type = flags;
9421 tgt_data->stats.entry[0].tgt_num = rport->number;
9422 tgt_data->stats.entry[0].cnt = fcport->tgt_short_link_down_cnt;
9427 int qla2xxx_disable_port(struct Scsi_Host *host)
9429 scsi_qla_host_t *vha = shost_priv(host);
9431 vha->hw->flags.port_isolated = 1;
9433 if (qla2x00_chip_is_down(vha))
9436 if (vha->flags.online) {
9437 qla2x00_abort_isp_cleanup(vha);
9438 qla2x00_wait_for_sess_deletion(vha);
9444 int qla2xxx_enable_port(struct Scsi_Host *host)
9446 scsi_qla_host_t *vha = shost_priv(host);
9448 vha->hw->flags.port_isolated = 0;
9449 /* Set the flag to 1, so that isp_abort can proceed */
9450 vha->flags.online = 1;
9451 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
9452 qla2xxx_wake_dpc(vha);