1 // SPDX-License-Identifier: GPL-2.0-only
3 * QLogic Fibre Channel HBA Driver
4 * Copyright (c) 2003-2014 QLogic Corporation
9 #include <linux/delay.h>
10 #include <linux/slab.h>
11 #include <linux/vmalloc.h>
13 #include "qla_devtbl.h"
19 #include "qla_target.h"
22 * QLogic ISP2x00 Hardware Support Function Prototypes.
24 static int qla2x00_isp_firmware(scsi_qla_host_t *);
25 static int qla2x00_setup_chip(scsi_qla_host_t *);
26 static int qla2x00_fw_ready(scsi_qla_host_t *);
27 static int qla2x00_configure_hba(scsi_qla_host_t *);
28 static int qla2x00_configure_loop(scsi_qla_host_t *);
29 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
30 static int qla2x00_configure_fabric(scsi_qla_host_t *);
31 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *);
32 static int qla2x00_restart_isp(scsi_qla_host_t *);
34 static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
35 static int qla84xx_init_chip(scsi_qla_host_t *);
36 static int qla25xx_init_queues(struct qla_hw_data *);
37 static void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha,
38 struct event_arg *ea);
39 static void qla24xx_handle_prli_done_event(struct scsi_qla_host *,
41 static void __qla24xx_handle_gpdb_event(scsi_qla_host_t *, struct event_arg *);
43 /* SRB Extensions ---------------------------------------------------------- */
46 qla2x00_sp_timeout(struct timer_list *t)
48 srb_t *sp = from_timer(sp, t, u.iocb_cmd.timer);
49 struct srb_iocb *iocb;
51 WARN_ON(irqs_disabled());
52 iocb = &sp->u.iocb_cmd;
56 void qla2x00_sp_free(srb_t *sp)
58 struct srb_iocb *iocb = &sp->u.iocb_cmd;
60 del_timer(&iocb->timer);
64 void qla2xxx_rel_done_warning(srb_t *sp, int res)
66 WARN_ONCE(1, "Calling done() of an already freed srb %p object\n", sp);
69 void qla2xxx_rel_free_warning(srb_t *sp)
71 WARN_ONCE(1, "Calling free() of an already freed srb %p object\n", sp);
74 /* Asynchronous Login/Logout Routines -------------------------------------- */
77 qla2x00_get_async_timeout(struct scsi_qla_host *vha)
80 struct qla_hw_data *ha = vha->hw;
82 /* Firmware should use switch negotiated r_a_tov for timeout. */
83 tmo = ha->r_a_tov / 10 * 2;
85 tmo = FX00_DEF_RATOV * 2;
86 } else if (!IS_FWI2_CAPABLE(ha)) {
88 * Except for earlier ISPs where the timeout is seeded from the
89 * initialization control block.
91 tmo = ha->login_timeout;
96 static void qla24xx_abort_iocb_timeout(void *data)
99 struct srb_iocb *abt = &sp->u.iocb_cmd;
100 struct qla_qpair *qpair = sp->qpair;
105 ql_dbg(ql_dbg_async, sp->vha, 0x507c,
106 "Abort timeout - cmd hdl=%x, cmd type=%x hdl=%x, type=%x\n",
107 sp->cmd_sp->handle, sp->cmd_sp->type,
108 sp->handle, sp->type);
110 ql_dbg(ql_dbg_async, sp->vha, 0x507c,
111 "Abort timeout 2 - hdl=%x, type=%x\n",
112 sp->handle, sp->type);
114 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
115 for (handle = 1; handle < qpair->req->num_outstanding_cmds; handle++) {
116 if (sp->cmd_sp && (qpair->req->outstanding_cmds[handle] ==
118 qpair->req->outstanding_cmds[handle] = NULL;
120 /* removing the abort */
121 if (qpair->req->outstanding_cmds[handle] == sp) {
122 qpair->req->outstanding_cmds[handle] = NULL;
126 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
129 sp->cmd_sp->done(sp->cmd_sp, QLA_OS_TIMER_EXPIRED);
131 abt->u.abt.comp_status = cpu_to_le16(CS_TIMEOUT);
132 sp->done(sp, QLA_OS_TIMER_EXPIRED);
135 static void qla24xx_abort_sp_done(srb_t *sp, int res)
137 struct srb_iocb *abt = &sp->u.iocb_cmd;
138 srb_t *orig_sp = sp->cmd_sp;
141 qla_wait_nvme_release_cmd_kref(orig_sp);
143 del_timer(&sp->u.iocb_cmd.timer);
144 if (sp->flags & SRB_WAKEUP_ON_COMP)
145 complete(&abt->u.abt.comp);
150 int qla24xx_async_abort_cmd(srb_t *cmd_sp, bool wait)
152 scsi_qla_host_t *vha = cmd_sp->vha;
153 struct srb_iocb *abt_iocb;
155 int rval = QLA_FUNCTION_FAILED;
157 sp = qla2xxx_get_qpair_sp(cmd_sp->vha, cmd_sp->qpair, cmd_sp->fcport,
160 return QLA_MEMORY_ALLOC_FAILED;
162 abt_iocb = &sp->u.iocb_cmd;
163 sp->type = SRB_ABT_CMD;
165 sp->qpair = cmd_sp->qpair;
168 sp->flags = SRB_WAKEUP_ON_COMP;
170 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
171 init_completion(&abt_iocb->u.abt.comp);
172 /* FW can send 2 x ABTS's timeout/20s */
173 qla2x00_init_timer(sp, 42);
175 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
176 abt_iocb->u.abt.req_que_no = cpu_to_le16(cmd_sp->qpair->req->id);
178 sp->done = qla24xx_abort_sp_done;
180 ql_dbg(ql_dbg_async, vha, 0x507c,
181 "Abort command issued - hdl=%x, type=%x\n", cmd_sp->handle,
184 rval = qla2x00_start_sp(sp);
185 if (rval != QLA_SUCCESS) {
191 wait_for_completion(&abt_iocb->u.abt.comp);
192 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
193 QLA_SUCCESS : QLA_ERR_FROM_FW;
201 qla2x00_async_iocb_timeout(void *data)
204 fc_port_t *fcport = sp->fcport;
205 struct srb_iocb *lio = &sp->u.iocb_cmd;
210 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
211 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
212 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
214 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
216 pr_info("Async-%s timeout - hdl=%x.\n",
217 sp->name, sp->handle);
222 rc = qla24xx_async_abort_cmd(sp, false);
224 /* Retry as needed. */
225 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
226 lio->u.logio.data[1] =
227 lio->u.logio.flags & SRB_LOGIN_RETRIED ?
228 QLA_LOGIO_LOGIN_RETRIED : 0;
229 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
230 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
232 if (sp->qpair->req->outstanding_cmds[h] ==
234 sp->qpair->req->outstanding_cmds[h] =
239 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
240 sp->done(sp, QLA_FUNCTION_TIMEOUT);
244 case SRB_CT_PTHRU_CMD:
251 rc = qla24xx_async_abort_cmd(sp, false);
253 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
254 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
256 if (sp->qpair->req->outstanding_cmds[h] ==
258 sp->qpair->req->outstanding_cmds[h] =
263 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
264 sp->done(sp, QLA_FUNCTION_TIMEOUT);
270 static void qla2x00_async_login_sp_done(srb_t *sp, int res)
272 struct scsi_qla_host *vha = sp->vha;
273 struct srb_iocb *lio = &sp->u.iocb_cmd;
276 ql_dbg(ql_dbg_disc, vha, 0x20dd,
277 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
279 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
281 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
282 memset(&ea, 0, sizeof(ea));
283 ea.fcport = sp->fcport;
284 ea.data[0] = lio->u.logio.data[0];
285 ea.data[1] = lio->u.logio.data[1];
286 ea.iop[0] = lio->u.logio.iop[0];
287 ea.iop[1] = lio->u.logio.iop[1];
289 qla24xx_handle_plogi_done_event(vha, &ea);
296 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
300 struct srb_iocb *lio;
301 int rval = QLA_FUNCTION_FAILED;
303 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
304 fcport->loop_id == FC_NO_LOOP_ID) {
305 ql_log(ql_log_warn, vha, 0xffff,
306 "%s: %8phC - not sending command.\n",
307 __func__, fcport->port_name);
311 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
315 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_PEND);
316 fcport->flags |= FCF_ASYNC_SENT;
317 fcport->logout_completed = 0;
319 sp->type = SRB_LOGIN_CMD;
321 sp->gen1 = fcport->rscn_gen;
322 sp->gen2 = fcport->login_gen;
324 lio = &sp->u.iocb_cmd;
325 lio->timeout = qla2x00_async_iocb_timeout;
326 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
328 sp->done = qla2x00_async_login_sp_done;
329 if (N2N_TOPO(fcport->vha->hw) && fcport_is_bigger(fcport)) {
330 lio->u.logio.flags |= SRB_LOGIN_PRLI_ONLY;
332 if (vha->hw->flags.edif_enabled &&
333 vha->e_dbell.db_flags & EDB_ACTIVE) {
334 lio->u.logio.flags |=
335 (SRB_LOGIN_FCSP | SRB_LOGIN_SKIP_PRLI);
336 ql_dbg(ql_dbg_disc, vha, 0x2072,
337 "Async-login: w/ FCSP %8phC hdl=%x, loopid=%x portid=%06x\n",
338 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24);
340 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
344 if (NVME_TARGET(vha->hw, fcport))
345 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
347 ql_dbg(ql_dbg_disc, vha, 0x2072,
348 "Async-login - %8phC hdl=%x, loopid=%x portid=%06x retries=%d.\n",
349 fcport->port_name, sp->handle, fcport->loop_id,
350 fcport->d_id.b24, fcport->login_retry);
352 rval = qla2x00_start_sp(sp);
353 if (rval != QLA_SUCCESS) {
354 fcport->flags |= FCF_LOGIN_NEEDED;
355 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
363 fcport->flags &= ~FCF_ASYNC_SENT;
365 fcport->flags &= ~FCF_ASYNC_ACTIVE;
369 static void qla2x00_async_logout_sp_done(srb_t *sp, int res)
371 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
372 sp->fcport->login_gen++;
373 qlt_logo_completion_handler(sp->fcport, sp->u.iocb_cmd.u.logio.data[0]);
378 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
381 struct srb_iocb *lio;
382 int rval = QLA_FUNCTION_FAILED;
384 fcport->flags |= FCF_ASYNC_SENT;
385 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
389 sp->type = SRB_LOGOUT_CMD;
392 lio = &sp->u.iocb_cmd;
393 lio->timeout = qla2x00_async_iocb_timeout;
394 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
396 sp->done = qla2x00_async_logout_sp_done;
398 ql_dbg(ql_dbg_disc, vha, 0x2070,
399 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC explicit %d.\n",
400 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
401 fcport->d_id.b.area, fcport->d_id.b.al_pa,
402 fcport->port_name, fcport->explicit_logout);
404 rval = qla2x00_start_sp(sp);
405 if (rval != QLA_SUCCESS)
412 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
417 qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
420 fcport->flags &= ~FCF_ASYNC_ACTIVE;
421 /* Don't re-login in target mode */
422 if (!fcport->tgt_session)
423 qla2x00_mark_device_lost(vha, fcport, 1);
424 qlt_logo_completion_handler(fcport, data[0]);
427 static void qla2x00_async_prlo_sp_done(srb_t *sp, int res)
429 struct srb_iocb *lio = &sp->u.iocb_cmd;
430 struct scsi_qla_host *vha = sp->vha;
432 sp->fcport->flags &= ~FCF_ASYNC_ACTIVE;
433 if (!test_bit(UNLOADING, &vha->dpc_flags))
434 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
440 qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
443 struct srb_iocb *lio;
446 rval = QLA_FUNCTION_FAILED;
447 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
451 sp->type = SRB_PRLO_CMD;
454 lio = &sp->u.iocb_cmd;
455 lio->timeout = qla2x00_async_iocb_timeout;
456 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
458 sp->done = qla2x00_async_prlo_sp_done;
460 ql_dbg(ql_dbg_disc, vha, 0x2070,
461 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
462 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
463 fcport->d_id.b.area, fcport->d_id.b.al_pa);
465 rval = qla2x00_start_sp(sp);
466 if (rval != QLA_SUCCESS)
474 fcport->flags &= ~FCF_ASYNC_ACTIVE;
479 void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
481 struct fc_port *fcport = ea->fcport;
483 ql_dbg(ql_dbg_disc, vha, 0x20d2,
484 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
485 __func__, fcport->port_name, fcport->disc_state,
486 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
487 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
489 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
492 if (ea->data[0] != MBS_COMMAND_COMPLETE) {
493 ql_dbg(ql_dbg_disc, vha, 0x2066,
494 "%s %8phC: adisc fail: post delete\n",
495 __func__, ea->fcport->port_name);
496 /* deleted = 0 & logout_on_delete = force fw cleanup */
498 fcport->logout_on_delete = 1;
499 qlt_schedule_sess_for_deletion(ea->fcport);
503 if (ea->fcport->disc_state == DSC_DELETE_PEND)
506 if (ea->sp->gen2 != ea->fcport->login_gen) {
507 /* target side must have changed it. */
508 ql_dbg(ql_dbg_disc, vha, 0x20d3,
509 "%s %8phC generation changed\n",
510 __func__, ea->fcport->port_name);
512 } else if (ea->sp->gen1 != ea->fcport->rscn_gen) {
513 qla_rscn_replay(fcport);
514 qlt_schedule_sess_for_deletion(fcport);
518 __qla24xx_handle_gpdb_event(vha, ea);
521 static int qla_post_els_plogi_work(struct scsi_qla_host *vha, fc_port_t *fcport)
523 struct qla_work_evt *e;
525 e = qla2x00_alloc_work(vha, QLA_EVT_ELS_PLOGI);
527 return QLA_FUNCTION_FAILED;
529 e->u.fcport.fcport = fcport;
530 fcport->flags |= FCF_ASYNC_ACTIVE;
531 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_PEND);
532 return qla2x00_post_work(vha, e);
535 static void qla2x00_async_adisc_sp_done(srb_t *sp, int res)
537 struct scsi_qla_host *vha = sp->vha;
539 struct srb_iocb *lio = &sp->u.iocb_cmd;
541 ql_dbg(ql_dbg_disc, vha, 0x2066,
542 "Async done-%s res %x %8phC\n",
543 sp->name, res, sp->fcport->port_name);
545 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
547 memset(&ea, 0, sizeof(ea));
549 ea.data[0] = lio->u.logio.data[0];
550 ea.data[1] = lio->u.logio.data[1];
551 ea.iop[0] = lio->u.logio.iop[0];
552 ea.iop[1] = lio->u.logio.iop[1];
553 ea.fcport = sp->fcport;
556 qla24xx_handle_adisc_event(vha, &ea);
562 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
566 struct srb_iocb *lio;
567 int rval = QLA_FUNCTION_FAILED;
569 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
572 fcport->flags |= FCF_ASYNC_SENT;
573 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
577 sp->type = SRB_ADISC_CMD;
580 lio = &sp->u.iocb_cmd;
581 lio->timeout = qla2x00_async_iocb_timeout;
582 sp->gen1 = fcport->rscn_gen;
583 sp->gen2 = fcport->login_gen;
584 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
586 sp->done = qla2x00_async_adisc_sp_done;
587 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
588 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
590 ql_dbg(ql_dbg_disc, vha, 0x206f,
591 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
592 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
594 rval = qla2x00_start_sp(sp);
595 if (rval != QLA_SUCCESS)
603 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
604 qla2x00_post_async_adisc_work(vha, fcport, data);
608 static bool qla2x00_is_reserved_id(scsi_qla_host_t *vha, uint16_t loop_id)
610 struct qla_hw_data *ha = vha->hw;
612 if (IS_FWI2_CAPABLE(ha))
613 return loop_id > NPH_LAST_HANDLE;
615 return (loop_id > ha->max_loop_id && loop_id < SNS_FIRST_LOOP_ID) ||
616 loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST;
620 * qla2x00_find_new_loop_id - scan through our port list and find a new usable loop ID
621 * @vha: adapter state pointer.
622 * @dev: port structure pointer.
625 * qla2x00 local function return status code.
630 static int qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
633 struct qla_hw_data *ha = vha->hw;
634 unsigned long flags = 0;
638 spin_lock_irqsave(&ha->vport_slock, flags);
640 dev->loop_id = find_first_zero_bit(ha->loop_id_map, LOOPID_MAP_SIZE);
641 if (dev->loop_id >= LOOPID_MAP_SIZE ||
642 qla2x00_is_reserved_id(vha, dev->loop_id)) {
643 dev->loop_id = FC_NO_LOOP_ID;
644 rval = QLA_FUNCTION_FAILED;
646 set_bit(dev->loop_id, ha->loop_id_map);
648 spin_unlock_irqrestore(&ha->vport_slock, flags);
650 if (rval == QLA_SUCCESS)
651 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
652 "Assigning new loopid=%x, portid=%x.\n",
653 dev->loop_id, dev->d_id.b24);
655 ql_log(ql_log_warn, dev->vha, 0x2087,
656 "No loop_id's available, portid=%x.\n",
662 void qla2x00_clear_loop_id(fc_port_t *fcport)
664 struct qla_hw_data *ha = fcport->vha->hw;
666 if (fcport->loop_id == FC_NO_LOOP_ID ||
667 qla2x00_is_reserved_id(fcport->vha, fcport->loop_id))
670 clear_bit(fcport->loop_id, ha->loop_id_map);
671 fcport->loop_id = FC_NO_LOOP_ID;
674 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
675 struct event_arg *ea)
677 fc_port_t *fcport, *conflict_fcport;
678 struct get_name_list_extended *e;
679 u16 i, n, found = 0, loop_id;
683 u8 current_login_state, nvme_cls;
686 ql_dbg(ql_dbg_disc, vha, 0xffff,
687 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d edif %d\n",
688 __func__, fcport->port_name, fcport->disc_state,
689 fcport->fw_login_state, ea->rc,
690 fcport->login_gen, fcport->last_login_gen,
691 fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id, fcport->edif.enable);
693 if (fcport->disc_state == DSC_DELETE_PEND)
696 if (ea->rc) { /* rval */
697 if (fcport->login_retry == 0) {
698 ql_dbg(ql_dbg_disc, vha, 0x20de,
699 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
700 fcport->port_name, fcport->login_retry);
705 if (fcport->last_rscn_gen != fcport->rscn_gen) {
706 qla_rscn_replay(fcport);
707 qlt_schedule_sess_for_deletion(fcport);
709 } else if (fcport->last_login_gen != fcport->login_gen) {
710 ql_dbg(ql_dbg_disc, vha, 0x20e0,
711 "%s %8phC login gen changed\n",
712 __func__, fcport->port_name);
713 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
717 n = ea->data[0] / sizeof(struct get_name_list_extended);
719 ql_dbg(ql_dbg_disc, vha, 0x20e1,
720 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
721 __func__, __LINE__, fcport->port_name, n,
722 fcport->d_id.b.domain, fcport->d_id.b.area,
723 fcport->d_id.b.al_pa, fcport->loop_id);
725 for (i = 0; i < n; i++) {
727 wwn = wwn_to_u64(e->port_name);
728 id.b.domain = e->port_id[2];
729 id.b.area = e->port_id[1];
730 id.b.al_pa = e->port_id[0];
733 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
736 if (IS_SW_RESV_ADDR(id))
741 loop_id = le16_to_cpu(e->nport_handle);
742 loop_id = (loop_id & 0x7fff);
743 nvme_cls = e->current_login_state >> 4;
744 current_login_state = e->current_login_state & 0xf;
746 if (PRLI_PHASE(nvme_cls)) {
747 current_login_state = nvme_cls;
748 fcport->fc4_type &= ~FS_FC4TYPE_FCP;
749 fcport->fc4_type |= FS_FC4TYPE_NVME;
750 } else if (PRLI_PHASE(current_login_state)) {
751 fcport->fc4_type |= FS_FC4TYPE_FCP;
752 fcport->fc4_type &= ~FS_FC4TYPE_NVME;
755 ql_dbg(ql_dbg_disc, vha, 0x20e2,
756 "%s found %8phC CLS [%x|%x] fc4_type %d ID[%06x|%06x] lid[%d|%d]\n",
757 __func__, fcport->port_name,
758 e->current_login_state, fcport->fw_login_state,
759 fcport->fc4_type, id.b24, fcport->d_id.b24,
760 loop_id, fcport->loop_id);
762 switch (fcport->disc_state) {
763 case DSC_DELETE_PEND:
767 if ((id.b24 != fcport->d_id.b24 &&
769 fcport->loop_id != FC_NO_LOOP_ID) ||
770 (fcport->loop_id != FC_NO_LOOP_ID &&
771 fcport->loop_id != loop_id)) {
772 ql_dbg(ql_dbg_disc, vha, 0x20e3,
773 "%s %d %8phC post del sess\n",
774 __func__, __LINE__, fcport->port_name);
775 if (fcport->n2n_flag)
776 fcport->d_id.b24 = 0;
777 qlt_schedule_sess_for_deletion(fcport);
783 fcport->loop_id = loop_id;
784 if (fcport->n2n_flag)
785 fcport->d_id.b24 = id.b24;
787 wwn = wwn_to_u64(fcport->port_name);
788 qlt_find_sess_invalidate_other(vha, wwn,
789 id, loop_id, &conflict_fcport);
791 if (conflict_fcport) {
793 * Another share fcport share the same loop_id &
794 * nport id. Conflict fcport needs to finish
795 * cleanup before this fcport can proceed to login.
797 conflict_fcport->conflict = fcport;
798 fcport->login_pause = 1;
801 switch (vha->hw->current_topology) {
803 switch (current_login_state) {
804 case DSC_LS_PRLI_COMP:
806 vha, 0x20e4, "%s %d %8phC post gpdb\n",
807 __func__, __LINE__, fcport->port_name);
809 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
810 fcport->port_type = FCT_INITIATOR;
812 fcport->port_type = FCT_TARGET;
813 data[0] = data[1] = 0;
814 qla2x00_post_async_adisc_work(vha, fcport,
817 case DSC_LS_PLOGI_COMP:
818 if (vha->hw->flags.edif_enabled) {
819 /* check to see if App support Secure */
820 qla24xx_post_gpdb_work(vha, fcport, 0);
824 case DSC_LS_PORT_UNAVAIL:
826 if (fcport->loop_id == FC_NO_LOOP_ID) {
827 qla2x00_find_new_loop_id(vha, fcport);
828 fcport->fw_login_state =
831 ql_dbg(ql_dbg_disc, vha, 0x20e5,
832 "%s %d %8phC\n", __func__, __LINE__,
834 qla24xx_fcport_handle_login(vha, fcport);
839 fcport->fw_login_state = current_login_state;
841 switch (current_login_state) {
842 case DSC_LS_PRLI_PEND:
844 * In the middle of PRLI. Let it finish.
845 * Allow relogin code to recheck state again
846 * with GNL. Push disc_state back to DELETED
847 * so GNL can go out again
849 qla2x00_set_fcport_disc_state(fcport,
851 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
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 (vha->hw->flags.edif_enabled &&
865 vha->e_dbell.db_flags & EDB_ACTIVE) {
866 /* check to see if App support secure or not */
867 qla24xx_post_gpdb_work(vha, fcport, 0);
870 if (fcport_is_bigger(fcport)) {
871 /* local adapter is smaller */
872 if (fcport->loop_id != FC_NO_LOOP_ID)
873 qla2x00_clear_loop_id(fcport);
875 fcport->loop_id = loop_id;
876 qla24xx_fcport_handle_login(vha,
882 if (fcport_is_smaller(fcport)) {
883 /* local adapter is bigger */
884 if (fcport->loop_id != FC_NO_LOOP_ID)
885 qla2x00_clear_loop_id(fcport);
887 fcport->loop_id = loop_id;
888 qla24xx_fcport_handle_login(vha,
894 } /* switch (ha->current_topology) */
898 switch (vha->hw->current_topology) {
901 for (i = 0; i < n; i++) {
903 id.b.domain = e->port_id[0];
904 id.b.area = e->port_id[1];
905 id.b.al_pa = e->port_id[2];
907 loop_id = le16_to_cpu(e->nport_handle);
909 if (fcport->d_id.b24 == id.b24) {
911 qla2x00_find_fcport_by_wwpn(vha,
913 if (conflict_fcport) {
914 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
916 "%s %d %8phC post del sess\n",
918 conflict_fcport->port_name);
919 qlt_schedule_sess_for_deletion
924 * FW already picked this loop id for
927 if (fcport->loop_id == loop_id)
928 fcport->loop_id = FC_NO_LOOP_ID;
930 qla24xx_fcport_handle_login(vha, fcport);
933 qla2x00_set_fcport_disc_state(fcport, DSC_DELETED);
934 if (time_after_eq(jiffies, fcport->dm_login_expire)) {
935 if (fcport->n2n_link_reset_cnt < 2) {
936 fcport->n2n_link_reset_cnt++;
938 * remote port is not sending PLOGI.
939 * Reset link to kick start his state
942 set_bit(N2N_LINK_RESET,
945 if (fcport->n2n_chip_reset < 1) {
946 ql_log(ql_log_info, vha, 0x705d,
947 "Chip reset to bring laser down");
948 set_bit(ISP_ABORT_NEEDED,
950 fcport->n2n_chip_reset++;
952 ql_log(ql_log_info, vha, 0x705d,
953 "Remote port %8ph is not coming back\n",
955 fcport->scan_state = 0;
958 qla2xxx_wake_dpc(vha);
961 * report port suppose to do PLOGI. Give him
962 * more time. FW will catch it.
964 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
973 static void qla24xx_async_gnl_sp_done(srb_t *sp, int res)
975 struct scsi_qla_host *vha = sp->vha;
977 struct fc_port *fcport = NULL, *tf;
978 u16 i, n = 0, loop_id;
980 struct get_name_list_extended *e;
985 ql_dbg(ql_dbg_disc, vha, 0x20e7,
986 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
987 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
988 sp->u.iocb_cmd.u.mbx.in_mb[2]);
990 if (res == QLA_FUNCTION_TIMEOUT)
993 sp->fcport->flags &= ~(FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE);
994 memset(&ea, 0, sizeof(ea));
998 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
999 sizeof(struct get_name_list_extended)) {
1000 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
1001 sizeof(struct get_name_list_extended);
1002 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
1005 for (i = 0; i < n; i++) {
1007 loop_id = le16_to_cpu(e->nport_handle);
1008 /* mask out reserve bit */
1009 loop_id = (loop_id & 0x7fff);
1010 set_bit(loop_id, vha->hw->loop_id_map);
1011 wwn = wwn_to_u64(e->port_name);
1013 ql_dbg(ql_dbg_disc, vha, 0x20e8,
1014 "%s %8phC %02x:%02x:%02x CLS %x/%x lid %x \n",
1015 __func__, &wwn, e->port_id[2], e->port_id[1],
1016 e->port_id[0], e->current_login_state, e->last_login_state,
1017 (loop_id & 0x7fff));
1020 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1024 if (!list_empty(&vha->gnl.fcports))
1025 list_splice_init(&vha->gnl.fcports, &h);
1026 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1028 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
1029 list_del_init(&fcport->gnl_entry);
1030 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1031 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1032 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1035 qla24xx_handle_gnl_done_event(vha, &ea);
1038 /* create new fcport if fw has knowledge of new sessions */
1039 for (i = 0; i < n; i++) {
1044 wwn = wwn_to_u64(e->port_name);
1047 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
1048 if (!memcmp((u8 *)&wwn, fcport->port_name,
1055 id.b.domain = e->port_id[2];
1056 id.b.area = e->port_id[1];
1057 id.b.al_pa = e->port_id[0];
1060 if (!found && wwn && !IS_SW_RESV_ADDR(id)) {
1061 ql_dbg(ql_dbg_disc, vha, 0x2065,
1062 "%s %d %8phC %06x post new sess\n",
1063 __func__, __LINE__, (u8 *)&wwn, id.b24);
1064 wwnn = wwn_to_u64(e->node_name);
1065 qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn,
1066 (u8 *)&wwnn, NULL, 0);
1070 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1072 if (!list_empty(&vha->gnl.fcports)) {
1074 list_for_each_entry_safe(fcport, tf, &vha->gnl.fcports,
1076 list_del_init(&fcport->gnl_entry);
1077 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1078 if (qla24xx_post_gnl_work(vha, fcport) == QLA_SUCCESS)
1082 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1087 int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
1090 struct srb_iocb *mbx;
1091 int rval = QLA_FUNCTION_FAILED;
1092 unsigned long flags;
1095 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
1098 ql_dbg(ql_dbg_disc, vha, 0x20d9,
1099 "Async-gnlist WWPN %8phC \n", fcport->port_name);
1101 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1102 fcport->flags |= FCF_ASYNC_SENT;
1103 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
1104 fcport->last_rscn_gen = fcport->rscn_gen;
1105 fcport->last_login_gen = fcport->login_gen;
1107 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
1108 if (vha->gnl.sent) {
1109 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1113 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1115 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1119 sp->type = SRB_MB_IOCB;
1120 sp->name = "gnlist";
1121 sp->gen1 = fcport->rscn_gen;
1122 sp->gen2 = fcport->login_gen;
1124 mbx = &sp->u.iocb_cmd;
1125 mbx->timeout = qla2x00_async_iocb_timeout;
1126 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
1128 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1129 mb[0] = MBC_PORT_NODE_NAME_LIST;
1130 mb[1] = BIT_2 | BIT_3;
1131 mb[2] = MSW(vha->gnl.ldma);
1132 mb[3] = LSW(vha->gnl.ldma);
1133 mb[6] = MSW(MSD(vha->gnl.ldma));
1134 mb[7] = LSW(MSD(vha->gnl.ldma));
1135 mb[8] = vha->gnl.size;
1136 mb[9] = vha->vp_idx;
1138 sp->done = qla24xx_async_gnl_sp_done;
1140 ql_dbg(ql_dbg_disc, vha, 0x20da,
1141 "Async-%s - OUT WWPN %8phC hndl %x\n",
1142 sp->name, fcport->port_name, sp->handle);
1144 rval = qla2x00_start_sp(sp);
1145 if (rval != QLA_SUCCESS)
1153 fcport->flags &= ~(FCF_ASYNC_ACTIVE | FCF_ASYNC_SENT);
1157 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1159 struct qla_work_evt *e;
1161 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
1163 return QLA_FUNCTION_FAILED;
1165 e->u.fcport.fcport = fcport;
1166 fcport->flags |= FCF_ASYNC_ACTIVE;
1167 return qla2x00_post_work(vha, e);
1170 static void qla24xx_async_gpdb_sp_done(srb_t *sp, int res)
1172 struct scsi_qla_host *vha = sp->vha;
1173 struct qla_hw_data *ha = vha->hw;
1174 fc_port_t *fcport = sp->fcport;
1175 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
1176 struct event_arg ea;
1178 ql_dbg(ql_dbg_disc, vha, 0x20db,
1179 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
1180 sp->name, res, fcport->port_name, mb[1], mb[2]);
1182 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1184 if (res == QLA_FUNCTION_TIMEOUT)
1187 memset(&ea, 0, sizeof(ea));
1191 qla24xx_handle_gpdb_event(vha, &ea);
1194 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
1195 sp->u.iocb_cmd.u.mbx.in_dma);
1200 int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1202 struct qla_work_evt *e;
1204 if (vha->host->active_mode == MODE_TARGET)
1205 return QLA_FUNCTION_FAILED;
1207 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
1209 return QLA_FUNCTION_FAILED;
1211 e->u.fcport.fcport = fcport;
1213 return qla2x00_post_work(vha, e);
1216 static void qla2x00_async_prli_sp_done(srb_t *sp, int res)
1218 struct scsi_qla_host *vha = sp->vha;
1219 struct srb_iocb *lio = &sp->u.iocb_cmd;
1220 struct event_arg ea;
1222 ql_dbg(ql_dbg_disc, vha, 0x2129,
1223 "%s %8phC res %x\n", __func__,
1224 sp->fcport->port_name, res);
1226 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1228 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
1229 memset(&ea, 0, sizeof(ea));
1230 ea.fcport = sp->fcport;
1231 ea.data[0] = lio->u.logio.data[0];
1232 ea.data[1] = lio->u.logio.data[1];
1233 ea.iop[0] = lio->u.logio.iop[0];
1234 ea.iop[1] = lio->u.logio.iop[1];
1236 if (res == QLA_OS_TIMER_EXPIRED)
1237 ea.data[0] = QLA_OS_TIMER_EXPIRED;
1239 qla24xx_handle_prli_done_event(vha, &ea);
1246 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
1249 struct srb_iocb *lio;
1250 int rval = QLA_FUNCTION_FAILED;
1252 if (!vha->flags.online) {
1253 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1254 __func__, __LINE__, fcport->port_name);
1258 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
1259 fcport->fw_login_state == DSC_LS_PRLI_PEND) &&
1260 qla_dual_mode_enabled(vha)) {
1261 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1262 __func__, __LINE__, fcport->port_name);
1266 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1270 fcport->flags |= FCF_ASYNC_SENT;
1271 fcport->logout_completed = 0;
1273 sp->type = SRB_PRLI_CMD;
1276 lio = &sp->u.iocb_cmd;
1277 lio->timeout = qla2x00_async_iocb_timeout;
1278 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1280 sp->done = qla2x00_async_prli_sp_done;
1281 lio->u.logio.flags = 0;
1283 if (NVME_TARGET(vha->hw, fcport))
1284 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
1286 ql_dbg(ql_dbg_disc, vha, 0x211b,
1287 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d fc4type %x priority %x %s.\n",
1288 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24,
1289 fcport->login_retry, fcport->fc4_type, vha->hw->fc4_type_priority,
1290 NVME_TARGET(vha->hw, fcport) ? "nvme" : "fcp");
1292 rval = qla2x00_start_sp(sp);
1293 if (rval != QLA_SUCCESS) {
1294 fcport->flags |= FCF_LOGIN_NEEDED;
1295 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1303 fcport->flags &= ~FCF_ASYNC_SENT;
1307 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1309 struct qla_work_evt *e;
1311 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
1313 return QLA_FUNCTION_FAILED;
1315 e->u.fcport.fcport = fcport;
1316 e->u.fcport.opt = opt;
1317 fcport->flags |= FCF_ASYNC_ACTIVE;
1318 return qla2x00_post_work(vha, e);
1321 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1324 struct srb_iocb *mbx;
1325 int rval = QLA_FUNCTION_FAILED;
1328 struct port_database_24xx *pd;
1329 struct qla_hw_data *ha = vha->hw;
1331 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
1332 fcport->loop_id == FC_NO_LOOP_ID) {
1333 ql_log(ql_log_warn, vha, 0xffff,
1334 "%s: %8phC - not sending command.\n",
1335 __func__, fcport->port_name);
1339 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1343 qla2x00_set_fcport_disc_state(fcport, DSC_GPDB);
1345 fcport->flags |= FCF_ASYNC_SENT;
1346 sp->type = SRB_MB_IOCB;
1348 sp->gen1 = fcport->rscn_gen;
1349 sp->gen2 = fcport->login_gen;
1351 mbx = &sp->u.iocb_cmd;
1352 mbx->timeout = qla2x00_async_iocb_timeout;
1353 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1355 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1357 ql_log(ql_log_warn, vha, 0xd043,
1358 "Failed to allocate port database structure.\n");
1362 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1363 mb[0] = MBC_GET_PORT_DATABASE;
1364 mb[1] = fcport->loop_id;
1365 mb[2] = MSW(pd_dma);
1366 mb[3] = LSW(pd_dma);
1367 mb[6] = MSW(MSD(pd_dma));
1368 mb[7] = LSW(MSD(pd_dma));
1369 mb[9] = vha->vp_idx;
1373 mbx->u.mbx.in_dma = pd_dma;
1375 sp->done = qla24xx_async_gpdb_sp_done;
1377 ql_dbg(ql_dbg_disc, vha, 0x20dc,
1378 "Async-%s %8phC hndl %x opt %x\n",
1379 sp->name, fcport->port_name, sp->handle, opt);
1381 rval = qla2x00_start_sp(sp);
1382 if (rval != QLA_SUCCESS)
1388 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1391 fcport->flags &= ~FCF_ASYNC_SENT;
1393 fcport->flags &= ~FCF_ASYNC_ACTIVE;
1394 qla24xx_post_gpdb_work(vha, fcport, opt);
1399 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1401 unsigned long flags;
1403 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1404 ea->fcport->login_gen++;
1405 ea->fcport->deleted = 0;
1406 ea->fcport->logout_on_delete = 1;
1408 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1409 vha->fcport_count++;
1410 ea->fcport->login_succ = 1;
1412 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1413 qla24xx_sched_upd_fcport(ea->fcport);
1414 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1415 } else if (ea->fcport->login_succ) {
1417 * We have an existing session. A late RSCN delivery
1418 * must have triggered the session to be re-validate.
1419 * Session is still valid.
1421 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1422 "%s %d %8phC session revalidate success\n",
1423 __func__, __LINE__, ea->fcport->port_name);
1424 qla2x00_set_fcport_disc_state(ea->fcport, DSC_LOGIN_COMPLETE);
1426 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1429 static int qla_chk_secure_login(scsi_qla_host_t *vha, fc_port_t *fcport,
1430 struct port_database_24xx *pd)
1434 if (pd->secure_login) {
1435 ql_dbg(ql_dbg_disc, vha, 0x104d,
1436 "Secure Login established on %8phC\n",
1438 fcport->flags |= FCF_FCSP_DEVICE;
1440 ql_dbg(ql_dbg_disc, vha, 0x104d,
1441 "non-Secure Login %8phC",
1443 fcport->flags &= ~FCF_FCSP_DEVICE;
1445 if (vha->hw->flags.edif_enabled) {
1446 if (fcport->flags & FCF_FCSP_DEVICE) {
1447 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_AUTH_PEND);
1448 /* Start edif prli timer & ring doorbell for app */
1449 fcport->edif.rx_sa_set = 0;
1450 fcport->edif.tx_sa_set = 0;
1451 fcport->edif.rx_sa_pending = 0;
1452 fcport->edif.tx_sa_pending = 0;
1454 qla2x00_post_aen_work(vha, FCH_EVT_PORT_ONLINE,
1457 if (vha->e_dbell.db_flags == EDB_ACTIVE) {
1458 ql_dbg(ql_dbg_disc, vha, 0x20ef,
1459 "%s %d %8phC EDIF: post DB_AUTH: AUTH needed\n",
1460 __func__, __LINE__, fcport->port_name);
1461 fcport->edif.app_started = 1;
1462 fcport->edif.app_sess_online = 1;
1464 qla_edb_eventcreate(vha, VND_CMD_AUTH_STATE_NEEDED,
1465 fcport->d_id.b24, 0, fcport);
1469 } else if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
1470 ql_dbg(ql_dbg_disc, vha, 0x2117,
1471 "%s %d %8phC post prli\n",
1472 __func__, __LINE__, fcport->port_name);
1473 qla24xx_post_prli_work(vha, fcport);
1481 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1483 fc_port_t *fcport = ea->fcport;
1484 struct port_database_24xx *pd;
1485 struct srb *sp = ea->sp;
1488 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1490 fcport->flags &= ~FCF_ASYNC_SENT;
1492 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1493 "%s %8phC DS %d LS %x fc4_type %x rc %x\n", __func__,
1494 fcport->port_name, fcport->disc_state, pd->current_login_state,
1495 fcport->fc4_type, ea->rc);
1497 if (fcport->disc_state == DSC_DELETE_PEND) {
1498 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC\n",
1499 __func__, __LINE__, fcport->port_name);
1503 if (NVME_TARGET(vha->hw, fcport))
1504 ls = pd->current_login_state >> 4;
1506 ls = pd->current_login_state & 0xf;
1508 if (ea->sp->gen2 != fcport->login_gen) {
1509 /* target side must have changed it. */
1511 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1512 "%s %8phC generation changed\n",
1513 __func__, fcport->port_name);
1515 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1516 qla_rscn_replay(fcport);
1517 qlt_schedule_sess_for_deletion(fcport);
1518 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n",
1519 __func__, __LINE__, fcport->port_name, ls);
1524 case PDS_PRLI_COMPLETE:
1525 __qla24xx_parse_gpdb(vha, fcport, pd);
1527 case PDS_PLOGI_COMPLETE:
1528 if (qla_chk_secure_login(vha, fcport, pd)) {
1529 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n",
1530 __func__, __LINE__, fcport->port_name, ls);
1534 case PDS_PLOGI_PENDING:
1535 case PDS_PRLI_PENDING:
1536 case PDS_PRLI2_PENDING:
1537 /* Set discovery state back to GNL to Relogin attempt */
1538 if (qla_dual_mode_enabled(vha) ||
1539 qla_ini_mode_enabled(vha)) {
1540 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
1541 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1543 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n",
1544 __func__, __LINE__, fcport->port_name, ls);
1546 case PDS_LOGO_PENDING:
1547 case PDS_PORT_UNAVAILABLE:
1549 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1550 __func__, __LINE__, fcport->port_name);
1551 qlt_schedule_sess_for_deletion(fcport);
1554 __qla24xx_handle_gpdb_event(vha, ea);
1557 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1562 if (qla_tgt_mode_enabled(vha))
1565 if (qla_dual_mode_enabled(vha)) {
1566 if (N2N_TOPO(vha->hw)) {
1569 mywwn = wwn_to_u64(vha->port_name);
1570 wwn = wwn_to_u64(fcport->port_name);
1573 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1574 && time_after_eq(jiffies,
1575 fcport->plogi_nack_done_deadline))
1581 /* initiator mode */
1585 if (login && fcport->login_retry) {
1586 fcport->login_retry--;
1587 if (fcport->loop_id == FC_NO_LOOP_ID) {
1588 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1589 rc = qla2x00_find_new_loop_id(vha, fcport);
1591 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1592 "%s %d %8phC post del sess - out of loopid\n",
1593 __func__, __LINE__, fcport->port_name);
1594 fcport->scan_state = 0;
1595 qlt_schedule_sess_for_deletion(fcport);
1599 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1600 "%s %d %8phC post login\n",
1601 __func__, __LINE__, fcport->port_name);
1602 qla2x00_post_async_login_work(vha, fcport, NULL);
1606 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1612 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1613 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d fc4type %x\n",
1614 __func__, fcport->port_name, fcport->disc_state,
1615 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1616 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1617 fcport->login_gen, fcport->loop_id, fcport->scan_state,
1620 if (fcport->scan_state != QLA_FCPORT_FOUND)
1623 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1624 qla_dual_mode_enabled(vha) &&
1625 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1626 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1629 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP &&
1630 !N2N_TOPO(vha->hw)) {
1631 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1632 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1637 /* Target won't initiate port login if fabric is present */
1638 if (vha->host->active_mode == MODE_TARGET && !N2N_TOPO(vha->hw))
1641 if (fcport->flags & FCF_ASYNC_SENT) {
1642 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1646 switch (fcport->disc_state) {
1648 wwn = wwn_to_u64(fcport->node_name);
1649 switch (vha->hw->current_topology) {
1651 if (fcport_is_smaller(fcport)) {
1652 /* this adapter is bigger */
1653 if (fcport->login_retry) {
1654 if (fcport->loop_id == FC_NO_LOOP_ID) {
1655 qla2x00_find_new_loop_id(vha,
1657 fcport->fw_login_state =
1658 DSC_LS_PORT_UNAVAIL;
1660 fcport->login_retry--;
1661 qla_post_els_plogi_work(vha, fcport);
1663 ql_log(ql_log_info, vha, 0x705d,
1664 "Unable to reach remote port %8phC",
1668 qla24xx_post_gnl_work(vha, fcport);
1673 ql_dbg(ql_dbg_disc, vha, 0xffff,
1674 "%s %d %8phC post GNNID\n",
1675 __func__, __LINE__, fcport->port_name);
1676 qla24xx_post_gnnid_work(vha, fcport);
1677 } else if (fcport->loop_id == FC_NO_LOOP_ID) {
1678 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1679 "%s %d %8phC post gnl\n",
1680 __func__, __LINE__, fcport->port_name);
1681 qla24xx_post_gnl_work(vha, fcport);
1683 qla_chk_n2n_b4_login(vha, fcport);
1690 switch (vha->hw->current_topology) {
1692 if ((fcport->current_login_state & 0xf) == 0x6) {
1693 ql_dbg(ql_dbg_disc, vha, 0x2118,
1694 "%s %d %8phC post GPDB work\n",
1695 __func__, __LINE__, fcport->port_name);
1696 fcport->chip_reset =
1697 vha->hw->base_qpair->chip_reset;
1698 qla24xx_post_gpdb_work(vha, fcport, 0);
1700 ql_dbg(ql_dbg_disc, vha, 0x2118,
1701 "%s %d %8phC post %s PRLI\n",
1702 __func__, __LINE__, fcport->port_name,
1703 NVME_TARGET(vha->hw, fcport) ? "NVME" :
1705 qla24xx_post_prli_work(vha, fcport);
1709 if (fcport->login_pause) {
1710 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1711 "%s %d %8phC exit\n",
1714 fcport->last_rscn_gen = fcport->rscn_gen;
1715 fcport->last_login_gen = fcport->login_gen;
1716 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1719 qla_chk_n2n_b4_login(vha, fcport);
1724 case DSC_LOGIN_FAILED:
1725 if (N2N_TOPO(vha->hw))
1726 qla_chk_n2n_b4_login(vha, fcport);
1728 qlt_schedule_sess_for_deletion(fcport);
1731 case DSC_LOGIN_COMPLETE:
1732 /* recheck login state */
1733 data[0] = data[1] = 0;
1734 qla2x00_post_async_adisc_work(vha, fcport, data);
1737 case DSC_LOGIN_PEND:
1738 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1739 qla24xx_post_prli_work(vha, fcport);
1742 case DSC_UPD_FCPORT:
1743 sec = jiffies_to_msecs(jiffies -
1744 fcport->jiffies_at_registration)/1000;
1745 if (fcport->sec_since_registration < sec && sec &&
1747 fcport->sec_since_registration = sec;
1748 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
1749 "%s %8phC - Slow Rport registration(%d Sec)\n",
1750 __func__, fcport->port_name, sec);
1753 if (fcport->next_disc_state != DSC_DELETE_PEND)
1754 fcport->next_disc_state = DSC_ADISC;
1755 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1765 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1766 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1768 struct qla_work_evt *e;
1770 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1772 return QLA_FUNCTION_FAILED;
1774 e->u.new_sess.id = *id;
1775 e->u.new_sess.pla = pla;
1776 e->u.new_sess.fc4_type = fc4_type;
1777 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1779 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1781 return qla2x00_post_work(vha, e);
1784 void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
1787 unsigned long flags;
1789 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1791 if (fcport->flags & FCF_FCP2_DEVICE) {
1792 ql_dbg(ql_dbg_disc, vha, 0x2115,
1793 "Delaying session delete for FCP2 portid=%06x %8phC ",
1794 fcport->d_id.b24, fcport->port_name);
1797 fcport->scan_needed = 1;
1801 spin_lock_irqsave(&vha->work_lock, flags);
1802 if (vha->scan.scan_flags == 0) {
1803 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s: schedule\n", __func__);
1804 vha->scan.scan_flags |= SF_QUEUED;
1805 schedule_delayed_work(&vha->scan.scan_work, 5);
1807 spin_unlock_irqrestore(&vha->work_lock, flags);
1810 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1811 struct event_arg *ea)
1813 fc_port_t *fcport = ea->fcport;
1815 if (test_bit(UNLOADING, &vha->dpc_flags))
1818 ql_dbg(ql_dbg_disc, vha, 0x2102,
1819 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1820 __func__, fcport->port_name, fcport->disc_state,
1821 fcport->fw_login_state, fcport->login_pause,
1822 fcport->deleted, fcport->conflict,
1823 fcport->last_rscn_gen, fcport->rscn_gen,
1824 fcport->last_login_gen, fcport->login_gen,
1827 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1828 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gnl\n",
1829 __func__, __LINE__, fcport->port_name);
1830 qla24xx_post_gnl_work(vha, fcport);
1834 qla24xx_fcport_handle_login(vha, fcport);
1837 void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
1838 struct event_arg *ea)
1840 if (N2N_TOPO(vha->hw) && fcport_is_smaller(ea->fcport) &&
1841 vha->hw->flags.edif_enabled) {
1842 /* check to see if App support Secure */
1843 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1847 /* for pure Target Mode, PRLI will not be initiated */
1848 if (vha->host->active_mode == MODE_TARGET)
1851 ql_dbg(ql_dbg_disc, vha, 0x2118,
1852 "%s %d %8phC post PRLI\n",
1853 __func__, __LINE__, ea->fcport->port_name);
1854 qla24xx_post_prli_work(vha, ea->fcport);
1858 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1859 * to be consumed by the fcport
1861 void qla_rscn_replay(fc_port_t *fcport)
1863 struct event_arg ea;
1865 switch (fcport->disc_state) {
1866 case DSC_DELETE_PEND:
1872 if (fcport->scan_needed) {
1873 memset(&ea, 0, sizeof(ea));
1874 ea.id = fcport->d_id;
1875 ea.id.b.rsvd_1 = RSCN_PORT_ADDR;
1876 qla2x00_handle_rscn(fcport->vha, &ea);
1881 qla2x00_tmf_iocb_timeout(void *data)
1884 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1886 unsigned long flags;
1888 rc = qla24xx_async_abort_cmd(sp, false);
1890 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
1891 for (h = 1; h < sp->qpair->req->num_outstanding_cmds; h++) {
1892 if (sp->qpair->req->outstanding_cmds[h] == sp) {
1893 sp->qpair->req->outstanding_cmds[h] = NULL;
1897 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
1898 tmf->u.tmf.comp_status = cpu_to_le16(CS_TIMEOUT);
1899 tmf->u.tmf.data = QLA_FUNCTION_FAILED;
1900 complete(&tmf->u.tmf.comp);
1904 static void qla2x00_tmf_sp_done(srb_t *sp, int res)
1906 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1908 complete(&tmf->u.tmf.comp);
1912 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
1915 struct scsi_qla_host *vha = fcport->vha;
1916 struct srb_iocb *tm_iocb;
1918 int rval = QLA_FUNCTION_FAILED;
1920 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1924 tm_iocb = &sp->u.iocb_cmd;
1925 sp->type = SRB_TM_CMD;
1928 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1929 init_completion(&tm_iocb->u.tmf.comp);
1930 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1932 tm_iocb->u.tmf.flags = flags;
1933 tm_iocb->u.tmf.lun = lun;
1934 tm_iocb->u.tmf.data = tag;
1935 sp->done = qla2x00_tmf_sp_done;
1937 ql_dbg(ql_dbg_taskm, vha, 0x802f,
1938 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1939 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1940 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1942 rval = qla2x00_start_sp(sp);
1943 if (rval != QLA_SUCCESS)
1945 wait_for_completion(&tm_iocb->u.tmf.comp);
1947 rval = tm_iocb->u.tmf.data;
1949 if (rval != QLA_SUCCESS) {
1950 ql_log(ql_log_warn, vha, 0x8030,
1951 "TM IOCB failed (%x).\n", rval);
1954 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1955 flags = tm_iocb->u.tmf.flags;
1956 lun = (uint16_t)tm_iocb->u.tmf.lun;
1958 /* Issue Marker IOCB */
1959 qla2x00_marker(vha, vha->hw->base_qpair,
1960 fcport->loop_id, lun,
1961 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1966 fcport->flags &= ~FCF_ASYNC_SENT;
1972 qla24xx_async_abort_command(srb_t *sp)
1974 unsigned long flags = 0;
1977 fc_port_t *fcport = sp->fcport;
1978 struct qla_qpair *qpair = sp->qpair;
1979 struct scsi_qla_host *vha = fcport->vha;
1980 struct req_que *req = qpair->req;
1982 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1983 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1984 if (req->outstanding_cmds[handle] == sp)
1987 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1989 if (handle == req->num_outstanding_cmds) {
1990 /* Command not found. */
1991 return QLA_ERR_NOT_FOUND;
1993 if (sp->type == SRB_FXIOCB_DCMD)
1994 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1995 FXDISC_ABORT_IOCTL);
1997 return qla24xx_async_abort_cmd(sp, true);
2001 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
2004 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
2007 switch (ea->data[0]) {
2008 case MBS_COMMAND_COMPLETE:
2009 ql_dbg(ql_dbg_disc, vha, 0x2118,
2010 "%s %d %8phC post gpdb\n",
2011 __func__, __LINE__, ea->fcport->port_name);
2013 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2014 ea->fcport->logout_on_delete = 1;
2015 ea->fcport->nvme_prli_service_param = ea->iop[0];
2016 if (ea->iop[0] & NVME_PRLI_SP_FIRST_BURST)
2017 ea->fcport->nvme_first_burst_size =
2018 (ea->iop[1] & 0xffff) * 512;
2020 ea->fcport->nvme_first_burst_size = 0;
2021 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2024 if ((ea->iop[0] == LSC_SCODE_ELS_REJECT) &&
2025 (ea->iop[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
2026 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2027 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
2032 ql_dbg(ql_dbg_disc, vha, 0x2118,
2033 "%s %d %8phC priority %s, fc4type %x prev try %s\n",
2034 __func__, __LINE__, ea->fcport->port_name,
2035 vha->hw->fc4_type_priority == FC4_PRIORITY_FCP ?
2036 "FCP" : "NVMe", ea->fcport->fc4_type,
2037 (sp->u.iocb_cmd.u.logio.flags & SRB_LOGIN_NVME_PRLI) ?
2040 if (NVME_FCP_TARGET(ea->fcport)) {
2041 if (sp->u.iocb_cmd.u.logio.flags & SRB_LOGIN_NVME_PRLI)
2042 ea->fcport->do_prli_nvme = 0;
2044 ea->fcport->do_prli_nvme = 1;
2046 ea->fcport->do_prli_nvme = 0;
2049 if (N2N_TOPO(vha->hw)) {
2050 if (ea->fcport->n2n_link_reset_cnt <
2051 vha->hw->login_retry_count) {
2052 ea->fcport->n2n_link_reset_cnt++;
2053 vha->relogin_jif = jiffies + 2 * HZ;
2055 * PRLI failed. Reset link to kick start
2058 set_bit(N2N_LINK_RESET, &vha->dpc_flags);
2059 qla2xxx_wake_dpc(vha);
2061 ql_log(ql_log_warn, vha, 0x2119,
2062 "%s %d %8phC Unable to reconnect\n",
2064 ea->fcport->port_name);
2068 * switch connect. login failed. Take connection down
2069 * and allow relogin to retrigger
2071 ea->fcport->flags &= ~FCF_ASYNC_SENT;
2072 ea->fcport->keep_nport_handle = 0;
2073 ea->fcport->logout_on_delete = 1;
2074 qlt_schedule_sess_for_deletion(ea->fcport);
2081 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
2083 port_id_t cid; /* conflict Nport id */
2085 struct fc_port *conflict_fcport;
2086 unsigned long flags;
2087 struct fc_port *fcport = ea->fcport;
2089 ql_dbg(ql_dbg_disc, vha, 0xffff,
2090 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
2091 __func__, fcport->port_name, fcport->disc_state,
2092 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
2093 ea->sp->gen1, fcport->rscn_gen,
2094 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
2096 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
2097 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
2098 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2099 "%s %d %8phC Remote is trying to login\n",
2100 __func__, __LINE__, fcport->port_name);
2104 if ((fcport->disc_state == DSC_DELETE_PEND) ||
2105 (fcport->disc_state == DSC_DELETED)) {
2106 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2110 if (ea->sp->gen2 != fcport->login_gen) {
2111 /* target side must have changed it. */
2112 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2113 "%s %8phC generation changed\n",
2114 __func__, fcport->port_name);
2115 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2117 } else if (ea->sp->gen1 != fcport->rscn_gen) {
2118 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2119 "%s %8phC RSCN generation changed\n",
2120 __func__, fcport->port_name);
2121 qla_rscn_replay(fcport);
2122 qlt_schedule_sess_for_deletion(fcport);
2126 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
2129 switch (ea->data[0]) {
2130 case MBS_COMMAND_COMPLETE:
2132 * Driver must validate login state - If PRLI not complete,
2133 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
2136 if (vha->hw->flags.edif_enabled) {
2137 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2138 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2139 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2140 ea->fcport->logout_on_delete = 1;
2141 ea->fcport->send_els_logo = 0;
2142 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
2143 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2145 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2147 if (NVME_TARGET(vha->hw, fcport)) {
2148 ql_dbg(ql_dbg_disc, vha, 0x2117,
2149 "%s %d %8phC post prli\n",
2150 __func__, __LINE__, fcport->port_name);
2151 qla24xx_post_prli_work(vha, fcport);
2153 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2154 "%s %d %8phC LoopID 0x%x in use with %06x. post gpdb\n",
2155 __func__, __LINE__, fcport->port_name,
2156 fcport->loop_id, fcport->d_id.b24);
2158 set_bit(fcport->loop_id, vha->hw->loop_id_map);
2159 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2160 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2161 fcport->logout_on_delete = 1;
2162 fcport->send_els_logo = 0;
2163 fcport->fw_login_state = DSC_LS_PRLI_COMP;
2164 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2166 qla24xx_post_gpdb_work(vha, fcport, 0);
2170 case MBS_COMMAND_ERROR:
2171 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
2172 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
2174 ea->fcport->flags &= ~FCF_ASYNC_SENT;
2175 qla2x00_set_fcport_disc_state(ea->fcport, DSC_LOGIN_FAILED);
2176 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
2177 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2179 qla2x00_mark_device_lost(vha, ea->fcport, 1);
2181 case MBS_LOOP_ID_USED:
2182 /* data[1] = IO PARAM 1 = nport ID */
2183 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
2184 cid.b.area = (ea->iop[1] >> 8) & 0xff;
2185 cid.b.al_pa = ea->iop[1] & 0xff;
2188 ql_dbg(ql_dbg_disc, vha, 0x20ec,
2189 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2190 __func__, __LINE__, ea->fcport->port_name,
2191 ea->fcport->loop_id, cid.b24);
2193 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2194 ea->fcport->loop_id = FC_NO_LOOP_ID;
2195 qla24xx_post_gnl_work(vha, ea->fcport);
2197 case MBS_PORT_ID_USED:
2198 lid = ea->iop[1] & 0xffff;
2199 qlt_find_sess_invalidate_other(vha,
2200 wwn_to_u64(ea->fcport->port_name),
2201 ea->fcport->d_id, lid, &conflict_fcport);
2203 if (conflict_fcport) {
2205 * Another fcport share the same loop_id/nport id.
2206 * Conflict fcport needs to finish cleanup before this
2207 * fcport can proceed to login.
2209 conflict_fcport->conflict = ea->fcport;
2210 ea->fcport->login_pause = 1;
2212 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2213 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
2214 __func__, __LINE__, ea->fcport->port_name,
2215 ea->fcport->d_id.b24, lid);
2217 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2218 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2219 __func__, __LINE__, ea->fcport->port_name,
2220 ea->fcport->d_id.b24, lid);
2222 qla2x00_clear_loop_id(ea->fcport);
2223 set_bit(lid, vha->hw->loop_id_map);
2224 ea->fcport->loop_id = lid;
2225 ea->fcport->keep_nport_handle = 0;
2226 ea->fcport->logout_on_delete = 1;
2227 qlt_schedule_sess_for_deletion(ea->fcport);
2234 /****************************************************************************/
2235 /* QLogic ISP2x00 Hardware Support Functions. */
2236 /****************************************************************************/
2239 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
2241 int rval = QLA_SUCCESS;
2242 struct qla_hw_data *ha = vha->hw;
2243 uint32_t idc_major_ver, idc_minor_ver;
2246 qla83xx_idc_lock(vha, 0);
2248 /* SV: TODO: Assign initialization timeout from
2249 * flash-info / other param
2251 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
2252 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
2254 /* Set our fcoe function presence */
2255 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
2256 ql_dbg(ql_dbg_p3p, vha, 0xb077,
2257 "Error while setting DRV-Presence.\n");
2258 rval = QLA_FUNCTION_FAILED;
2262 /* Decide the reset ownership */
2263 qla83xx_reset_ownership(vha);
2266 * On first protocol driver load:
2267 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2269 * Others: Check compatibility with current IDC Major version.
2271 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
2272 if (ha->flags.nic_core_reset_owner) {
2273 /* Set IDC Major version */
2274 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
2275 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
2277 /* Clearing IDC-Lock-Recovery register */
2278 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
2279 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
2281 * Clear further IDC participation if we are not compatible with
2282 * the current IDC Major Version.
2284 ql_log(ql_log_warn, vha, 0xb07d,
2285 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2286 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
2287 __qla83xx_clear_drv_presence(vha);
2288 rval = QLA_FUNCTION_FAILED;
2291 /* Each function sets its supported Minor version. */
2292 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
2293 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
2294 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
2296 if (ha->flags.nic_core_reset_owner) {
2297 memset(config, 0, sizeof(config));
2298 if (!qla81xx_get_port_config(vha, config))
2299 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
2303 rval = qla83xx_idc_state_handler(vha);
2306 qla83xx_idc_unlock(vha, 0);
2312 * qla2x00_initialize_adapter
2316 * ha = adapter block pointer.
2322 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
2325 struct qla_hw_data *ha = vha->hw;
2326 struct req_que *req = ha->req_q_map[0];
2327 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2329 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2330 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2332 /* Clear adapter flags. */
2333 vha->flags.online = 0;
2334 ha->flags.chip_reset_done = 0;
2335 vha->flags.reset_active = 0;
2336 ha->flags.pci_channel_io_perm_failure = 0;
2337 ha->flags.eeh_busy = 0;
2338 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2339 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
2340 atomic_set(&vha->loop_state, LOOP_DOWN);
2341 vha->device_flags = DFLG_NO_CABLE;
2343 vha->flags.management_server_logged_in = 0;
2344 vha->marker_needed = 0;
2345 ha->isp_abort_cnt = 0;
2346 ha->beacon_blink_led = 0;
2348 set_bit(0, ha->req_qid_map);
2349 set_bit(0, ha->rsp_qid_map);
2351 ql_dbg(ql_dbg_init, vha, 0x0040,
2352 "Configuring PCI space...\n");
2353 rval = ha->isp_ops->pci_config(vha);
2355 ql_log(ql_log_warn, vha, 0x0044,
2356 "Unable to configure PCI space.\n");
2360 ha->isp_ops->reset_chip(vha);
2362 /* Check for secure flash support */
2363 if (IS_QLA28XX(ha)) {
2364 if (rd_reg_word(®->mailbox12) & BIT_0)
2365 ha->flags.secure_adapter = 1;
2366 ql_log(ql_log_info, vha, 0xffff, "Secure Adapter: %s\n",
2367 (ha->flags.secure_adapter) ? "Yes" : "No");
2371 rval = qla2xxx_get_flash_info(vha);
2373 ql_log(ql_log_fatal, vha, 0x004f,
2374 "Unable to validate FLASH data.\n");
2378 if (IS_QLA8044(ha)) {
2379 qla8044_read_reset_template(vha);
2381 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2382 * If DONRESET_BIT0 is set, drivers should not set dev_state
2383 * to NEED_RESET. But if NEED_RESET is set, drivers should
2384 * should honor the reset. */
2385 if (ql2xdontresethba == 1)
2386 qla8044_set_idc_dontreset(vha);
2389 ha->isp_ops->get_flash_version(vha, req->ring);
2390 ql_dbg(ql_dbg_init, vha, 0x0061,
2391 "Configure NVRAM parameters...\n");
2393 /* Let priority default to FCP, can be overridden by nvram_config */
2394 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2396 ha->isp_ops->nvram_config(vha);
2398 if (ha->fc4_type_priority != FC4_PRIORITY_FCP &&
2399 ha->fc4_type_priority != FC4_PRIORITY_NVME)
2400 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2402 ql_log(ql_log_info, vha, 0xffff, "FC4 priority set to %s\n",
2403 ha->fc4_type_priority == FC4_PRIORITY_FCP ? "FCP" : "NVMe");
2405 if (ha->flags.disable_serdes) {
2406 /* Mask HBA via NVRAM settings? */
2407 ql_log(ql_log_info, vha, 0x0077,
2408 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
2409 return QLA_FUNCTION_FAILED;
2412 ql_dbg(ql_dbg_init, vha, 0x0078,
2413 "Verifying loaded RISC code...\n");
2415 /* If smartsan enabled then require fdmi and rdp enabled */
2421 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
2422 rval = ha->isp_ops->chip_diag(vha);
2425 rval = qla2x00_setup_chip(vha);
2430 if (IS_QLA84XX(ha)) {
2431 ha->cs84xx = qla84xx_get_chip(vha);
2433 ql_log(ql_log_warn, vha, 0x00d0,
2434 "Unable to configure ISP84XX.\n");
2435 return QLA_FUNCTION_FAILED;
2439 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2440 rval = qla2x00_init_rings(vha);
2442 /* No point in continuing if firmware initialization failed. */
2443 if (rval != QLA_SUCCESS)
2446 ha->flags.chip_reset_done = 1;
2448 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2449 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2450 rval = qla84xx_init_chip(vha);
2451 if (rval != QLA_SUCCESS) {
2452 ql_log(ql_log_warn, vha, 0x00d4,
2453 "Unable to initialize ISP84XX.\n");
2454 qla84xx_put_chip(vha);
2458 /* Load the NIC Core f/w if we are the first protocol driver. */
2459 if (IS_QLA8031(ha)) {
2460 rval = qla83xx_nic_core_fw_load(vha);
2462 ql_log(ql_log_warn, vha, 0x0124,
2463 "Error in initializing NIC Core f/w.\n");
2466 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2467 qla24xx_read_fcp_prio_cfg(vha);
2469 if (IS_P3P_TYPE(ha))
2470 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2472 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2478 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2481 * Returns 0 on success.
2484 qla2100_pci_config(scsi_qla_host_t *vha)
2487 unsigned long flags;
2488 struct qla_hw_data *ha = vha->hw;
2489 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2491 pci_set_master(ha->pdev);
2492 pci_try_set_mwi(ha->pdev);
2494 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2495 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2496 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2498 pci_disable_rom(ha->pdev);
2500 /* Get PCI bus information. */
2501 spin_lock_irqsave(&ha->hardware_lock, flags);
2502 ha->pci_attr = rd_reg_word(®->ctrl_status);
2503 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2509 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2512 * Returns 0 on success.
2515 qla2300_pci_config(scsi_qla_host_t *vha)
2518 unsigned long flags = 0;
2520 struct qla_hw_data *ha = vha->hw;
2521 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2523 pci_set_master(ha->pdev);
2524 pci_try_set_mwi(ha->pdev);
2526 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2527 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2529 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2530 w &= ~PCI_COMMAND_INTX_DISABLE;
2531 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2534 * If this is a 2300 card and not 2312, reset the
2535 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2536 * the 2310 also reports itself as a 2300 so we need to get the
2537 * fb revision level -- a 6 indicates it really is a 2300 and
2540 if (IS_QLA2300(ha)) {
2541 spin_lock_irqsave(&ha->hardware_lock, flags);
2544 wrt_reg_word(®->hccr, HCCR_PAUSE_RISC);
2545 for (cnt = 0; cnt < 30000; cnt++) {
2546 if ((rd_reg_word(®->hccr) & HCCR_RISC_PAUSE) != 0)
2552 /* Select FPM registers. */
2553 wrt_reg_word(®->ctrl_status, 0x20);
2554 rd_reg_word(®->ctrl_status);
2556 /* Get the fb rev level */
2557 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2559 if (ha->fb_rev == FPM_2300)
2560 pci_clear_mwi(ha->pdev);
2562 /* Deselect FPM registers. */
2563 wrt_reg_word(®->ctrl_status, 0x0);
2564 rd_reg_word(®->ctrl_status);
2566 /* Release RISC module. */
2567 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
2568 for (cnt = 0; cnt < 30000; cnt++) {
2569 if ((rd_reg_word(®->hccr) & HCCR_RISC_PAUSE) == 0)
2575 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2578 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2580 pci_disable_rom(ha->pdev);
2582 /* Get PCI bus information. */
2583 spin_lock_irqsave(&ha->hardware_lock, flags);
2584 ha->pci_attr = rd_reg_word(®->ctrl_status);
2585 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2591 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2594 * Returns 0 on success.
2597 qla24xx_pci_config(scsi_qla_host_t *vha)
2600 unsigned long flags = 0;
2601 struct qla_hw_data *ha = vha->hw;
2602 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2604 pci_set_master(ha->pdev);
2605 pci_try_set_mwi(ha->pdev);
2607 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2608 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2609 w &= ~PCI_COMMAND_INTX_DISABLE;
2610 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2612 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2614 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2615 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2616 pcix_set_mmrbc(ha->pdev, 2048);
2618 /* PCIe -- adjust Maximum Read Request Size (2048). */
2619 if (pci_is_pcie(ha->pdev))
2620 pcie_set_readrq(ha->pdev, 4096);
2622 pci_disable_rom(ha->pdev);
2624 ha->chip_revision = ha->pdev->revision;
2626 /* Get PCI bus information. */
2627 spin_lock_irqsave(&ha->hardware_lock, flags);
2628 ha->pci_attr = rd_reg_dword(®->ctrl_status);
2629 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2635 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2638 * Returns 0 on success.
2641 qla25xx_pci_config(scsi_qla_host_t *vha)
2644 struct qla_hw_data *ha = vha->hw;
2646 pci_set_master(ha->pdev);
2647 pci_try_set_mwi(ha->pdev);
2649 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2650 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2651 w &= ~PCI_COMMAND_INTX_DISABLE;
2652 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2654 /* PCIe -- adjust Maximum Read Request Size (2048). */
2655 if (pci_is_pcie(ha->pdev))
2656 pcie_set_readrq(ha->pdev, 4096);
2658 pci_disable_rom(ha->pdev);
2660 ha->chip_revision = ha->pdev->revision;
2666 * qla2x00_isp_firmware() - Choose firmware image.
2669 * Returns 0 on success.
2672 qla2x00_isp_firmware(scsi_qla_host_t *vha)
2675 uint16_t loop_id, topo, sw_cap;
2676 uint8_t domain, area, al_pa;
2677 struct qla_hw_data *ha = vha->hw;
2679 /* Assume loading risc code */
2680 rval = QLA_FUNCTION_FAILED;
2682 if (ha->flags.disable_risc_code_load) {
2683 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
2685 /* Verify checksum of loaded RISC code. */
2686 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
2687 if (rval == QLA_SUCCESS) {
2688 /* And, verify we are not in ROM code. */
2689 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2690 &area, &domain, &topo, &sw_cap);
2695 ql_dbg(ql_dbg_init, vha, 0x007a,
2696 "**** Load RISC code ****.\n");
2702 * qla2x00_reset_chip() - Reset ISP chip.
2705 * Returns 0 on success.
2708 qla2x00_reset_chip(scsi_qla_host_t *vha)
2710 unsigned long flags = 0;
2711 struct qla_hw_data *ha = vha->hw;
2712 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2715 int rval = QLA_FUNCTION_FAILED;
2717 if (unlikely(pci_channel_offline(ha->pdev)))
2720 ha->isp_ops->disable_intrs(ha);
2722 spin_lock_irqsave(&ha->hardware_lock, flags);
2724 /* Turn off master enable */
2726 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2727 cmd &= ~PCI_COMMAND_MASTER;
2728 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2730 if (!IS_QLA2100(ha)) {
2732 wrt_reg_word(®->hccr, HCCR_PAUSE_RISC);
2733 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2734 for (cnt = 0; cnt < 30000; cnt++) {
2735 if ((rd_reg_word(®->hccr) &
2736 HCCR_RISC_PAUSE) != 0)
2741 rd_reg_word(®->hccr); /* PCI Posting. */
2745 /* Select FPM registers. */
2746 wrt_reg_word(®->ctrl_status, 0x20);
2747 rd_reg_word(®->ctrl_status); /* PCI Posting. */
2749 /* FPM Soft Reset. */
2750 wrt_reg_word(®->fpm_diag_config, 0x100);
2751 rd_reg_word(®->fpm_diag_config); /* PCI Posting. */
2753 /* Toggle Fpm Reset. */
2754 if (!IS_QLA2200(ha)) {
2755 wrt_reg_word(®->fpm_diag_config, 0x0);
2756 rd_reg_word(®->fpm_diag_config); /* PCI Posting. */
2759 /* Select frame buffer registers. */
2760 wrt_reg_word(®->ctrl_status, 0x10);
2761 rd_reg_word(®->ctrl_status); /* PCI Posting. */
2763 /* Reset frame buffer FIFOs. */
2764 if (IS_QLA2200(ha)) {
2765 WRT_FB_CMD_REG(ha, reg, 0xa000);
2766 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2768 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2770 /* Read back fb_cmd until zero or 3 seconds max */
2771 for (cnt = 0; cnt < 3000; cnt++) {
2772 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2778 /* Select RISC module registers. */
2779 wrt_reg_word(®->ctrl_status, 0);
2780 rd_reg_word(®->ctrl_status); /* PCI Posting. */
2782 /* Reset RISC processor. */
2783 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
2784 rd_reg_word(®->hccr); /* PCI Posting. */
2786 /* Release RISC processor. */
2787 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
2788 rd_reg_word(®->hccr); /* PCI Posting. */
2791 wrt_reg_word(®->hccr, HCCR_CLR_RISC_INT);
2792 wrt_reg_word(®->hccr, HCCR_CLR_HOST_INT);
2794 /* Reset ISP chip. */
2795 wrt_reg_word(®->ctrl_status, CSR_ISP_SOFT_RESET);
2797 /* Wait for RISC to recover from reset. */
2798 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2800 * It is necessary to for a delay here since the card doesn't
2801 * respond to PCI reads during a reset. On some architectures
2802 * this will result in an MCA.
2805 for (cnt = 30000; cnt; cnt--) {
2806 if ((rd_reg_word(®->ctrl_status) &
2807 CSR_ISP_SOFT_RESET) == 0)
2814 /* Reset RISC processor. */
2815 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
2817 wrt_reg_word(®->semaphore, 0);
2819 /* Release RISC processor. */
2820 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
2821 rd_reg_word(®->hccr); /* PCI Posting. */
2823 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2824 for (cnt = 0; cnt < 30000; cnt++) {
2825 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
2833 /* Turn on master enable */
2834 cmd |= PCI_COMMAND_MASTER;
2835 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2837 /* Disable RISC pause on FPM parity error. */
2838 if (!IS_QLA2100(ha)) {
2839 wrt_reg_word(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
2840 rd_reg_word(®->hccr); /* PCI Posting. */
2843 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2849 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2852 * Returns 0 on success.
2855 qla81xx_reset_mpi(scsi_qla_host_t *vha)
2857 uint16_t mb[4] = {0x1010, 0, 1, 0};
2859 if (!IS_QLA81XX(vha->hw))
2862 return qla81xx_write_mpi_register(vha, mb);
2866 qla_chk_risc_recovery(scsi_qla_host_t *vha)
2868 struct qla_hw_data *ha = vha->hw;
2869 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2870 __le16 __iomem *mbptr = ®->mailbox0;
2873 int rc = QLA_SUCCESS;
2875 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
2878 /* this check is only valid after RISC reset */
2879 mb[0] = rd_reg_word(mbptr);
2882 rc = QLA_FUNCTION_FAILED;
2884 for (i = 1; i < 32; i++) {
2885 mb[i] = rd_reg_word(mbptr);
2889 ql_log(ql_log_warn, vha, 0x1015,
2890 "RISC reset failed. mb[0-7] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
2891 mb[0], mb[1], mb[2], mb[3], mb[4], mb[5], mb[6], mb[7]);
2892 ql_log(ql_log_warn, vha, 0x1015,
2893 "RISC reset failed. mb[8-15] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
2894 mb[8], mb[9], mb[10], mb[11], mb[12], mb[13], mb[14],
2896 ql_log(ql_log_warn, vha, 0x1015,
2897 "RISC reset failed. mb[16-23] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
2898 mb[16], mb[17], mb[18], mb[19], mb[20], mb[21], mb[22],
2900 ql_log(ql_log_warn, vha, 0x1015,
2901 "RISC reset failed. mb[24-31] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
2902 mb[24], mb[25], mb[26], mb[27], mb[28], mb[29], mb[30],
2909 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2912 * Returns 0 on success.
2915 qla24xx_reset_risc(scsi_qla_host_t *vha)
2917 unsigned long flags = 0;
2918 struct qla_hw_data *ha = vha->hw;
2919 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2922 static int abts_cnt; /* ISP abort retry counts */
2923 int rval = QLA_SUCCESS;
2926 spin_lock_irqsave(&ha->hardware_lock, flags);
2929 wrt_reg_dword(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2930 for (cnt = 0; cnt < 30000; cnt++) {
2931 if ((rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2937 if (!(rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE))
2938 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2940 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2941 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2942 rd_reg_dword(®->hccr),
2943 rd_reg_dword(®->ctrl_status),
2944 (rd_reg_dword(®->ctrl_status) & CSRX_DMA_ACTIVE));
2946 wrt_reg_dword(®->ctrl_status,
2947 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2948 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
2952 /* Wait for firmware to complete NVRAM accesses. */
2953 rd_reg_word(®->mailbox0);
2954 for (cnt = 10000; rd_reg_word(®->mailbox0) != 0 &&
2955 rval == QLA_SUCCESS; cnt--) {
2960 rval = QLA_FUNCTION_TIMEOUT;
2963 if (rval == QLA_SUCCESS)
2964 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2966 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2967 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2968 rd_reg_dword(®->hccr),
2969 rd_reg_word(®->mailbox0));
2971 /* Wait for soft-reset to complete. */
2972 rd_reg_dword(®->ctrl_status);
2973 for (cnt = 0; cnt < 60; cnt++) {
2975 if ((rd_reg_dword(®->ctrl_status) &
2976 CSRX_ISP_SOFT_RESET) == 0)
2981 if (!(rd_reg_dword(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
2982 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2984 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2985 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2986 rd_reg_dword(®->hccr),
2987 rd_reg_dword(®->ctrl_status));
2989 /* If required, do an MPI FW reset now */
2990 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2991 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2992 if (++abts_cnt < 5) {
2993 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2994 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2997 * We exhausted the ISP abort retries. We have to
2998 * set the board offline.
3001 vha->flags.online = 0;
3006 wrt_reg_dword(®->hccr, HCCRX_SET_RISC_RESET);
3007 rd_reg_dword(®->hccr);
3009 wrt_reg_dword(®->hccr, HCCRX_REL_RISC_PAUSE);
3010 rd_reg_dword(®->hccr);
3012 wrt_reg_dword(®->hccr, HCCRX_CLR_RISC_RESET);
3014 rd_reg_dword(®->hccr);
3016 wd = rd_reg_word(®->mailbox0);
3017 for (cnt = 300; wd != 0 && rval == QLA_SUCCESS; cnt--) {
3021 if (print && qla_chk_risc_recovery(vha))
3024 wd = rd_reg_word(®->mailbox0);
3026 rval = QLA_FUNCTION_TIMEOUT;
3028 ql_log(ql_log_warn, vha, 0x015e,
3029 "RISC reset timeout\n");
3033 if (rval == QLA_SUCCESS)
3034 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
3036 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
3037 "Host Risc 0x%x, mailbox0 0x%x\n",
3038 rd_reg_dword(®->hccr),
3039 rd_reg_word(®->mailbox0));
3041 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3043 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
3044 "Driver in %s mode\n",
3045 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
3047 if (IS_NOPOLLING_TYPE(ha))
3048 ha->isp_ops->enable_intrs(ha);
3054 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
3056 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
3058 wrt_reg_dword(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
3059 *data = rd_reg_dword(®->iobase_window + RISC_REGISTER_WINDOW_OFFSET);
3063 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
3065 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
3067 wrt_reg_dword(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
3068 wrt_reg_dword(®->iobase_window + RISC_REGISTER_WINDOW_OFFSET, data);
3072 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
3075 uint delta_msec = 100;
3076 uint elapsed_msec = 0;
3080 if (vha->hw->pdev->subsystem_device != 0x0175 &&
3081 vha->hw->pdev->subsystem_device != 0x0240)
3084 wrt_reg_dword(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
3088 timeout_msec = TIMEOUT_SEMAPHORE;
3089 n = timeout_msec / delta_msec;
3091 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
3092 qla25xx_read_risc_sema_reg(vha, &wd32);
3093 if (wd32 & RISC_SEMAPHORE)
3096 elapsed_msec += delta_msec;
3097 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
3101 if (!(wd32 & RISC_SEMAPHORE))
3104 if (!(wd32 & RISC_SEMAPHORE_FORCE))
3107 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
3108 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
3109 n = timeout_msec / delta_msec;
3111 qla25xx_read_risc_sema_reg(vha, &wd32);
3112 if (!(wd32 & RISC_SEMAPHORE_FORCE))
3115 elapsed_msec += delta_msec;
3116 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
3120 if (wd32 & RISC_SEMAPHORE_FORCE)
3121 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
3126 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
3133 * qla24xx_reset_chip() - Reset ISP24xx chip.
3136 * Returns 0 on success.
3139 qla24xx_reset_chip(scsi_qla_host_t *vha)
3141 struct qla_hw_data *ha = vha->hw;
3142 int rval = QLA_FUNCTION_FAILED;
3144 if (pci_channel_offline(ha->pdev) &&
3145 ha->flags.pci_channel_io_perm_failure) {
3149 ha->isp_ops->disable_intrs(ha);
3151 qla25xx_manipulate_risc_semaphore(vha);
3153 /* Perform RISC reset. */
3154 rval = qla24xx_reset_risc(vha);
3160 * qla2x00_chip_diag() - Test chip for proper operation.
3163 * Returns 0 on success.
3166 qla2x00_chip_diag(scsi_qla_host_t *vha)
3169 struct qla_hw_data *ha = vha->hw;
3170 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3171 unsigned long flags = 0;
3175 struct req_que *req = ha->req_q_map[0];
3177 /* Assume a failed state */
3178 rval = QLA_FUNCTION_FAILED;
3180 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
3181 ®->flash_address);
3183 spin_lock_irqsave(&ha->hardware_lock, flags);
3185 /* Reset ISP chip. */
3186 wrt_reg_word(®->ctrl_status, CSR_ISP_SOFT_RESET);
3189 * We need to have a delay here since the card will not respond while
3190 * in reset causing an MCA on some architectures.
3193 data = qla2x00_debounce_register(®->ctrl_status);
3194 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
3196 data = rd_reg_word(®->ctrl_status);
3201 goto chip_diag_failed;
3203 ql_dbg(ql_dbg_init, vha, 0x007c,
3204 "Reset register cleared by chip reset.\n");
3206 /* Reset RISC processor. */
3207 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
3208 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
3210 /* Workaround for QLA2312 PCI parity error */
3211 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
3212 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
3213 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
3215 data = RD_MAILBOX_REG(ha, reg, 0);
3222 goto chip_diag_failed;
3224 /* Check product ID of chip */
3225 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
3227 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
3228 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
3229 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
3230 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
3231 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
3232 mb[3] != PROD_ID_3) {
3233 ql_log(ql_log_warn, vha, 0x0062,
3234 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
3235 mb[1], mb[2], mb[3]);
3237 goto chip_diag_failed;
3239 ha->product_id[0] = mb[1];
3240 ha->product_id[1] = mb[2];
3241 ha->product_id[2] = mb[3];
3242 ha->product_id[3] = mb[4];
3244 /* Adjust fw RISC transfer size */
3245 if (req->length > 1024)
3246 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
3248 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
3251 if (IS_QLA2200(ha) &&
3252 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
3253 /* Limit firmware transfer size with a 2200A */
3254 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
3256 ha->device_type |= DT_ISP2200A;
3257 ha->fw_transfer_size = 128;
3260 /* Wrap Incoming Mailboxes Test. */
3261 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3263 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
3264 rval = qla2x00_mbx_reg_test(vha);
3266 ql_log(ql_log_warn, vha, 0x0080,
3267 "Failed mailbox send register test.\n");
3269 /* Flag a successful rval */
3271 spin_lock_irqsave(&ha->hardware_lock, flags);
3275 ql_log(ql_log_info, vha, 0x0081,
3276 "Chip diagnostics **** FAILED ****.\n");
3278 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3284 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3287 * Returns 0 on success.
3290 qla24xx_chip_diag(scsi_qla_host_t *vha)
3293 struct qla_hw_data *ha = vha->hw;
3294 struct req_que *req = ha->req_q_map[0];
3296 if (IS_P3P_TYPE(ha))
3299 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
3301 rval = qla2x00_mbx_reg_test(vha);
3303 ql_log(ql_log_warn, vha, 0x0082,
3304 "Failed mailbox send register test.\n");
3306 /* Flag a successful rval */
3314 qla2x00_init_fce_trace(scsi_qla_host_t *vha)
3319 struct qla_hw_data *ha = vha->hw;
3321 if (!IS_FWI2_CAPABLE(ha))
3324 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3325 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3329 ql_dbg(ql_dbg_init, vha, 0x00bd,
3330 "%s: FCE Mem is already allocated.\n",
3335 /* Allocate memory for Fibre Channel Event Buffer. */
3336 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3339 ql_log(ql_log_warn, vha, 0x00be,
3340 "Unable to allocate (%d KB) for FCE.\n",
3345 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3346 ha->fce_mb, &ha->fce_bufs);
3348 ql_log(ql_log_warn, vha, 0x00bf,
3349 "Unable to initialize FCE (%d).\n", rval);
3350 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, tc_dma);
3354 ql_dbg(ql_dbg_init, vha, 0x00c0,
3355 "Allocated (%d KB) for FCE...\n", FCE_SIZE / 1024);
3357 ha->flags.fce_enabled = 1;
3358 ha->fce_dma = tc_dma;
3363 qla2x00_init_eft_trace(scsi_qla_host_t *vha)
3368 struct qla_hw_data *ha = vha->hw;
3370 if (!IS_FWI2_CAPABLE(ha))
3374 ql_dbg(ql_dbg_init, vha, 0x00bd,
3375 "%s: EFT Mem is already allocated.\n",
3380 /* Allocate memory for Extended Trace Buffer. */
3381 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3384 ql_log(ql_log_warn, vha, 0x00c1,
3385 "Unable to allocate (%d KB) for EFT.\n",
3390 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3392 ql_log(ql_log_warn, vha, 0x00c2,
3393 "Unable to initialize EFT (%d).\n", rval);
3394 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, tc_dma);
3398 ql_dbg(ql_dbg_init, vha, 0x00c3,
3399 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3401 ha->eft_dma = tc_dma;
3406 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3408 qla2x00_init_fce_trace(vha);
3409 qla2x00_init_eft_trace(vha);
3413 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3415 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
3416 eft_size, fce_size, mq_size;
3417 struct qla_hw_data *ha = vha->hw;
3418 struct req_que *req = ha->req_q_map[0];
3419 struct rsp_que *rsp = ha->rsp_q_map[0];
3420 struct qla2xxx_fw_dump *fw_dump;
3422 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
3423 req_q_size = rsp_q_size = 0;
3425 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3426 fixed_size = sizeof(struct qla2100_fw_dump);
3427 } else if (IS_QLA23XX(ha)) {
3428 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
3429 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
3431 } else if (IS_FWI2_CAPABLE(ha)) {
3432 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
3433 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
3434 else if (IS_QLA81XX(ha))
3435 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
3436 else if (IS_QLA25XX(ha))
3437 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
3439 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
3441 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
3444 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) &&
3446 mq_size = sizeof(struct qla2xxx_mq_chain);
3448 * Allocate maximum buffer size for all queues - Q0.
3449 * Resizing must be done at end-of-dump processing.
3451 mq_size += (ha->max_req_queues - 1) *
3452 (req->length * sizeof(request_t));
3453 mq_size += (ha->max_rsp_queues - 1) *
3454 (rsp->length * sizeof(response_t));
3456 if (ha->tgt.atio_ring)
3457 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3459 qla2x00_init_fce_trace(vha);
3461 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3462 qla2x00_init_eft_trace(vha);
3464 eft_size = EFT_SIZE;
3467 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3468 struct fwdt *fwdt = ha->fwdt;
3471 for (j = 0; j < 2; j++, fwdt++) {
3472 if (!fwdt->template) {
3473 ql_dbg(ql_dbg_init, vha, 0x00ba,
3474 "-> fwdt%u no template\n", j);
3477 ql_dbg(ql_dbg_init, vha, 0x00fa,
3478 "-> fwdt%u calculating fwdump size...\n", j);
3479 fwdt->dump_size = qla27xx_fwdt_calculate_dump_size(
3480 vha, fwdt->template);
3481 ql_dbg(ql_dbg_init, vha, 0x00fa,
3482 "-> fwdt%u calculated fwdump size = %#lx bytes\n",
3483 j, fwdt->dump_size);
3484 dump_size += fwdt->dump_size;
3486 /* Add space for spare MPI fw dump. */
3487 dump_size += ha->fwdt[1].dump_size;
3489 req_q_size = req->length * sizeof(request_t);
3490 rsp_q_size = rsp->length * sizeof(response_t);
3491 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3492 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size
3494 ha->chain_offset = dump_size;
3495 dump_size += mq_size + fce_size;
3496 if (ha->exchoffld_buf)
3497 dump_size += sizeof(struct qla2xxx_offld_chain) +
3499 if (ha->exlogin_buf)
3500 dump_size += sizeof(struct qla2xxx_offld_chain) +
3504 if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) {
3506 ql_dbg(ql_dbg_init, vha, 0x00c5,
3507 "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n",
3508 __func__, dump_size, ha->fw_dump_len,
3509 ha->fw_dump_alloc_len);
3511 fw_dump = vmalloc(dump_size);
3513 ql_log(ql_log_warn, vha, 0x00c4,
3514 "Unable to allocate (%d KB) for firmware dump.\n",
3517 mutex_lock(&ha->optrom_mutex);
3518 if (ha->fw_dumped) {
3519 memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len);
3521 ha->fw_dump = fw_dump;
3522 ha->fw_dump_alloc_len = dump_size;
3523 ql_dbg(ql_dbg_init, vha, 0x00c5,
3524 "Re-Allocated (%d KB) and save firmware dump.\n",
3528 ha->fw_dump = fw_dump;
3530 ha->fw_dump_len = ha->fw_dump_alloc_len =
3532 ql_dbg(ql_dbg_init, vha, 0x00c5,
3533 "Allocated (%d KB) for firmware dump.\n",
3536 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3537 ha->mpi_fw_dump = (char *)fw_dump +
3538 ha->fwdt[1].dump_size;
3539 mutex_unlock(&ha->optrom_mutex);
3543 ha->fw_dump->signature[0] = 'Q';
3544 ha->fw_dump->signature[1] = 'L';
3545 ha->fw_dump->signature[2] = 'G';
3546 ha->fw_dump->signature[3] = 'C';
3547 ha->fw_dump->version = htonl(1);
3549 ha->fw_dump->fixed_size = htonl(fixed_size);
3550 ha->fw_dump->mem_size = htonl(mem_size);
3551 ha->fw_dump->req_q_size = htonl(req_q_size);
3552 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3554 ha->fw_dump->eft_size = htonl(eft_size);
3555 ha->fw_dump->eft_addr_l =
3556 htonl(LSD(ha->eft_dma));
3557 ha->fw_dump->eft_addr_h =
3558 htonl(MSD(ha->eft_dma));
3560 ha->fw_dump->header_size =
3562 (struct qla2xxx_fw_dump, isp));
3564 mutex_unlock(&ha->optrom_mutex);
3570 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3572 #define MPS_MASK 0xe0
3577 if (!IS_QLA81XX(vha->hw))
3580 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3581 if (rval != QLA_SUCCESS) {
3582 ql_log(ql_log_warn, vha, 0x0105,
3583 "Unable to acquire semaphore.\n");
3587 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3588 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3589 if (rval != QLA_SUCCESS) {
3590 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3595 if (dc == (dw & MPS_MASK))
3600 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3601 if (rval != QLA_SUCCESS) {
3602 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3606 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3607 if (rval != QLA_SUCCESS) {
3608 ql_log(ql_log_warn, vha, 0x006d,
3609 "Unable to release semaphore.\n");
3617 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3619 /* Don't try to reallocate the array */
3620 if (req->outstanding_cmds)
3623 if (!IS_FWI2_CAPABLE(ha))
3624 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3626 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3627 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3629 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3632 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3636 if (!req->outstanding_cmds) {
3638 * Try to allocate a minimal size just so we can get through
3641 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
3642 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3646 if (!req->outstanding_cmds) {
3647 ql_log(ql_log_fatal, NULL, 0x0126,
3648 "Failed to allocate memory for "
3649 "outstanding_cmds for req_que %p.\n", req);
3650 req->num_outstanding_cmds = 0;
3651 return QLA_FUNCTION_FAILED;
3658 #define PRINT_FIELD(_field, _flag, _str) { \
3659 if (a0->_field & _flag) {\
3665 len = snprintf(ptr, leftover, "%s", _str); \
3672 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
3675 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
3676 u8 str[STR_LEN], *ptr, p;
3679 memset(str, 0, STR_LEN);
3680 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
3681 ql_dbg(ql_dbg_init, vha, 0x015a,
3682 "SFP MFG Name: %s\n", str);
3684 memset(str, 0, STR_LEN);
3685 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
3686 ql_dbg(ql_dbg_init, vha, 0x015c,
3687 "SFP Part Name: %s\n", str);
3690 memset(str, 0, STR_LEN);
3694 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
3695 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
3696 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
3697 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
3698 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3699 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3700 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3701 ql_dbg(ql_dbg_init, vha, 0x0160,
3702 "SFP Media: %s\n", str);
3705 memset(str, 0, STR_LEN);
3709 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3710 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3711 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3712 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3713 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3714 ql_dbg(ql_dbg_init, vha, 0x0196,
3715 "SFP Link Length: %s\n", str);
3717 memset(str, 0, STR_LEN);
3721 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3722 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3723 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3724 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3725 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3726 ql_dbg(ql_dbg_init, vha, 0x016e,
3727 "SFP FC Link Tech: %s\n", str);
3730 ql_dbg(ql_dbg_init, vha, 0x016f,
3731 "SFP Distant: %d km\n", a0->length_km);
3732 if (a0->length_100m)
3733 ql_dbg(ql_dbg_init, vha, 0x0170,
3734 "SFP Distant: %d m\n", a0->length_100m*100);
3735 if (a0->length_50um_10m)
3736 ql_dbg(ql_dbg_init, vha, 0x0189,
3737 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3738 if (a0->length_62um_10m)
3739 ql_dbg(ql_dbg_init, vha, 0x018a,
3740 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3741 if (a0->length_om4_10m)
3742 ql_dbg(ql_dbg_init, vha, 0x0194,
3743 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3744 if (a0->length_om3_10m)
3745 ql_dbg(ql_dbg_init, vha, 0x0195,
3746 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3751 * qla24xx_detect_sfp()
3753 * @vha: adapter state pointer.
3756 * 0 -- Configure firmware to use short-range settings -- normal
3757 * buffer-to-buffer credits.
3759 * 1 -- Configure firmware to use long-range settings -- extra
3760 * buffer-to-buffer credits should be allocated with
3761 * ha->lr_distance containing distance settings from NVRAM or SFP
3765 qla24xx_detect_sfp(scsi_qla_host_t *vha)
3768 struct sff_8247_a0 *a;
3769 struct qla_hw_data *ha = vha->hw;
3770 struct nvram_81xx *nv = ha->nvram;
3771 #define LR_DISTANCE_UNKNOWN 2
3772 static const char * const types[] = { "Short", "Long" };
3773 static const char * const lengths[] = { "(10km)", "(5km)", "" };
3776 /* Seed with NVRAM settings. */
3778 ha->flags.lr_detected = 0;
3779 if (IS_BPM_RANGE_CAPABLE(ha) &&
3780 (nv->enhanced_features & NEF_LR_DIST_ENABLE)) {
3782 ha->flags.lr_detected = 1;
3784 (nv->enhanced_features >> LR_DIST_NV_POS)
3788 if (!IS_BPM_ENABLED(vha))
3790 /* Determine SR/LR capabilities of SFP/Transceiver. */
3791 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3796 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3797 qla2xxx_print_sfp_info(vha);
3799 ha->flags.lr_detected = 0;
3801 if (ll & FC_LL_VL || ll & FC_LL_L) {
3802 /* Long range, track length. */
3803 ha->flags.lr_detected = 1;
3805 if (a->length_km > 5 || a->length_100m > 50)
3806 ha->lr_distance = LR_DISTANCE_10K;
3808 ha->lr_distance = LR_DISTANCE_5K;
3812 ql_dbg(ql_dbg_async, vha, 0x507b,
3813 "SFP detect: %s-Range SFP %s (nvr=%x ll=%x lr=%x lrd=%x).\n",
3814 types[ha->flags.lr_detected],
3815 ha->flags.lr_detected ? lengths[ha->lr_distance] :
3816 lengths[LR_DISTANCE_UNKNOWN],
3817 used_nvram, ll, ha->flags.lr_detected, ha->lr_distance);
3818 return ha->flags.lr_detected;
3821 void qla_init_iocb_limit(scsi_qla_host_t *vha)
3825 struct qla_hw_data *ha = vha->hw;
3827 num_qps = ha->num_qpairs + 1;
3828 limit = (ha->orig_fw_iocb_count * QLA_IOCB_PCT_LIMIT) / 100;
3830 ha->base_qpair->fwres.iocbs_total = ha->orig_fw_iocb_count;
3831 ha->base_qpair->fwres.iocbs_limit = limit;
3832 ha->base_qpair->fwres.iocbs_qp_limit = limit / num_qps;
3833 ha->base_qpair->fwres.iocbs_used = 0;
3834 for (i = 0; i < ha->max_qpairs; i++) {
3835 if (ha->queue_pair_map[i]) {
3836 ha->queue_pair_map[i]->fwres.iocbs_total =
3837 ha->orig_fw_iocb_count;
3838 ha->queue_pair_map[i]->fwres.iocbs_limit = limit;
3839 ha->queue_pair_map[i]->fwres.iocbs_qp_limit =
3841 ha->queue_pair_map[i]->fwres.iocbs_used = 0;
3847 * qla2x00_setup_chip() - Load and start RISC firmware.
3850 * Returns 0 on success.
3853 qla2x00_setup_chip(scsi_qla_host_t *vha)
3856 uint32_t srisc_address = 0;
3857 struct qla_hw_data *ha = vha->hw;
3858 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3859 unsigned long flags;
3860 uint16_t fw_major_version;
3863 if (IS_P3P_TYPE(ha)) {
3864 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3865 if (rval == QLA_SUCCESS) {
3866 qla2x00_stop_firmware(vha);
3867 goto enable_82xx_npiv;
3872 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3873 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3874 spin_lock_irqsave(&ha->hardware_lock, flags);
3875 wrt_reg_word(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
3876 rd_reg_word(®->hccr);
3877 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3880 qla81xx_mpi_sync(vha);
3883 /* Load firmware sequences */
3884 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3885 if (rval == QLA_SUCCESS) {
3886 ql_dbg(ql_dbg_init, vha, 0x00c9,
3887 "Verifying Checksum of loaded RISC code.\n");
3889 rval = qla2x00_verify_checksum(vha, srisc_address);
3890 if (rval == QLA_SUCCESS) {
3891 /* Start firmware execution. */
3892 ql_dbg(ql_dbg_init, vha, 0x00ca,
3893 "Starting firmware.\n");
3896 ha->flags.exlogins_enabled = 1;
3898 if (qla_is_exch_offld_enabled(vha))
3899 ha->flags.exchoffld_enabled = 1;
3901 rval = qla2x00_execute_fw(vha, srisc_address);
3902 /* Retrieve firmware information. */
3903 if (rval == QLA_SUCCESS) {
3904 /* Enable BPM support? */
3905 if (!done_once++ && qla24xx_detect_sfp(vha)) {
3906 ql_dbg(ql_dbg_init, vha, 0x00ca,
3907 "Re-starting firmware -- BPM.\n");
3908 /* Best-effort - re-init. */
3909 ha->isp_ops->reset_chip(vha);
3910 ha->isp_ops->chip_diag(vha);
3911 goto execute_fw_with_lr;
3914 if (IS_ZIO_THRESHOLD_CAPABLE(ha))
3915 qla27xx_set_zio_threshold(vha,
3916 ha->last_zio_threshold);
3918 rval = qla2x00_set_exlogins_buffer(vha);
3919 if (rval != QLA_SUCCESS)
3922 rval = qla2x00_set_exchoffld_buffer(vha);
3923 if (rval != QLA_SUCCESS)
3927 fw_major_version = ha->fw_major_version;
3928 if (IS_P3P_TYPE(ha))
3929 qla82xx_check_md_needed(vha);
3931 rval = qla2x00_get_fw_version(vha);
3932 if (rval != QLA_SUCCESS)
3934 ha->flags.npiv_supported = 0;
3935 if (IS_QLA2XXX_MIDTYPE(ha) &&
3936 (ha->fw_attributes & BIT_2)) {
3937 ha->flags.npiv_supported = 1;
3938 if ((!ha->max_npiv_vports) ||
3939 ((ha->max_npiv_vports + 1) %
3940 MIN_MULTI_ID_FABRIC))
3941 ha->max_npiv_vports =
3942 MIN_MULTI_ID_FABRIC - 1;
3944 qla2x00_get_resource_cnts(vha);
3945 qla_init_iocb_limit(vha);
3948 * Allocate the array of outstanding commands
3949 * now that we know the firmware resources.
3951 rval = qla2x00_alloc_outstanding_cmds(ha,
3953 if (rval != QLA_SUCCESS)
3956 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
3957 qla2x00_alloc_offload_mem(vha);
3959 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
3960 qla2x00_alloc_fw_dump(vha);
3966 ql_log(ql_log_fatal, vha, 0x00cd,
3967 "ISP Firmware failed checksum.\n");
3971 /* Enable PUREX PASSTHRU */
3972 if (ql2xrdpenable || ha->flags.scm_supported_f ||
3973 ha->flags.edif_enabled)
3974 qla25xx_set_els_cmds_supported(vha);
3978 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3979 /* Enable proper parity. */
3980 spin_lock_irqsave(&ha->hardware_lock, flags);
3983 wrt_reg_word(®->hccr, HCCR_ENABLE_PARITY + 0x1);
3985 /* SRAM, Instruction RAM and GP RAM parity */
3986 wrt_reg_word(®->hccr, HCCR_ENABLE_PARITY + 0x7);
3987 rd_reg_word(®->hccr);
3988 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3991 if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
3992 ha->flags.fac_supported = 1;
3993 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
3996 rval = qla81xx_fac_get_sector_size(vha, &size);
3997 if (rval == QLA_SUCCESS) {
3998 ha->flags.fac_supported = 1;
3999 ha->fdt_block_size = size << 2;
4001 ql_log(ql_log_warn, vha, 0x00ce,
4002 "Unsupported FAC firmware (%d.%02d.%02d).\n",
4003 ha->fw_major_version, ha->fw_minor_version,
4004 ha->fw_subminor_version);
4006 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4008 ha->flags.fac_supported = 0;
4015 ql_log(ql_log_fatal, vha, 0x00cf,
4016 "Setup chip ****FAILED****.\n");
4023 * qla2x00_init_response_q_entries() - Initializes response queue entries.
4024 * @rsp: response queue
4026 * Beginning of request ring has initialization control block already built
4027 * by nvram config routine.
4029 * Returns 0 on success.
4032 qla2x00_init_response_q_entries(struct rsp_que *rsp)
4037 rsp->ring_ptr = rsp->ring;
4038 rsp->ring_index = 0;
4039 rsp->status_srb = NULL;
4040 pkt = rsp->ring_ptr;
4041 for (cnt = 0; cnt < rsp->length; cnt++) {
4042 pkt->signature = RESPONSE_PROCESSED;
4048 * qla2x00_update_fw_options() - Read and process firmware options.
4051 * Returns 0 on success.
4054 qla2x00_update_fw_options(scsi_qla_host_t *vha)
4056 uint16_t swing, emphasis, tx_sens, rx_sens;
4057 struct qla_hw_data *ha = vha->hw;
4059 memset(ha->fw_options, 0, sizeof(ha->fw_options));
4060 qla2x00_get_fw_options(vha, ha->fw_options);
4062 if (IS_QLA2100(ha) || IS_QLA2200(ha))
4065 /* Serial Link options. */
4066 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
4067 "Serial link options.\n");
4068 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
4069 ha->fw_seriallink_options, sizeof(ha->fw_seriallink_options));
4071 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
4072 if (ha->fw_seriallink_options[3] & BIT_2) {
4073 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
4076 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
4077 emphasis = (ha->fw_seriallink_options[2] &
4078 (BIT_4 | BIT_3)) >> 3;
4079 tx_sens = ha->fw_seriallink_options[0] &
4080 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4081 rx_sens = (ha->fw_seriallink_options[0] &
4082 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
4083 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
4084 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
4087 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
4088 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
4089 ha->fw_options[10] |= BIT_5 |
4090 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
4091 (tx_sens & (BIT_1 | BIT_0));
4094 swing = (ha->fw_seriallink_options[2] &
4095 (BIT_7 | BIT_6 | BIT_5)) >> 5;
4096 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
4097 tx_sens = ha->fw_seriallink_options[1] &
4098 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4099 rx_sens = (ha->fw_seriallink_options[1] &
4100 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
4101 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
4102 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
4105 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
4106 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
4107 ha->fw_options[11] |= BIT_5 |
4108 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
4109 (tx_sens & (BIT_1 | BIT_0));
4113 /* Return command IOCBs without waiting for an ABTS to complete. */
4114 ha->fw_options[3] |= BIT_13;
4117 if (ha->flags.enable_led_scheme)
4118 ha->fw_options[2] |= BIT_12;
4120 /* Detect ISP6312. */
4122 ha->fw_options[2] |= BIT_13;
4124 /* Set Retry FLOGI in case of P2P connection */
4125 if (ha->operating_mode == P2P) {
4126 ha->fw_options[2] |= BIT_3;
4127 ql_dbg(ql_dbg_disc, vha, 0x2100,
4128 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
4129 __func__, ha->fw_options[2]);
4132 /* Update firmware options. */
4133 qla2x00_set_fw_options(vha, ha->fw_options);
4137 qla24xx_update_fw_options(scsi_qla_host_t *vha)
4140 struct qla_hw_data *ha = vha->hw;
4142 if (IS_P3P_TYPE(ha))
4145 /* Hold status IOCBs until ABTS response received. */
4147 ha->fw_options[3] |= BIT_12;
4149 /* Set Retry FLOGI in case of P2P connection */
4150 if (ha->operating_mode == P2P) {
4151 ha->fw_options[2] |= BIT_3;
4152 ql_dbg(ql_dbg_disc, vha, 0x2101,
4153 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
4154 __func__, ha->fw_options[2]);
4157 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
4158 if (ql2xmvasynctoatio && !ha->flags.edif_enabled &&
4159 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
4160 if (qla_tgt_mode_enabled(vha) ||
4161 qla_dual_mode_enabled(vha))
4162 ha->fw_options[2] |= BIT_11;
4164 ha->fw_options[2] &= ~BIT_11;
4167 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4170 * Tell FW to track each exchange to prevent
4171 * driver from using stale exchange.
4173 if (qla_tgt_mode_enabled(vha) ||
4174 qla_dual_mode_enabled(vha))
4175 ha->fw_options[2] |= BIT_4;
4177 ha->fw_options[2] &= ~(BIT_4);
4179 /* Reserve 1/2 of emergency exchanges for ELS.*/
4180 if (qla2xuseresexchforels)
4181 ha->fw_options[2] |= BIT_8;
4183 ha->fw_options[2] &= ~BIT_8;
4186 * N2N: set Secure=1 for PLOGI ACC and
4187 * fw shal not send PRLI after PLOGI Acc
4189 if (ha->flags.edif_enabled &&
4190 vha->e_dbell.db_flags & EDB_ACTIVE) {
4191 ha->fw_options[3] |= BIT_15;
4192 ha->flags.n2n_fw_acc_sec = 1;
4194 ha->fw_options[3] &= ~BIT_15;
4195 ha->flags.n2n_fw_acc_sec = 0;
4199 if (ql2xrdpenable || ha->flags.scm_supported_f ||
4200 ha->flags.edif_enabled)
4201 ha->fw_options[1] |= ADD_FO1_ENABLE_PUREX_IOCB;
4203 /* Enable Async 8130/8131 events -- transceiver insertion/removal */
4204 if (IS_BPM_RANGE_CAPABLE(ha))
4205 ha->fw_options[3] |= BIT_10;
4207 ql_dbg(ql_dbg_init, vha, 0x00e8,
4208 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
4209 __func__, ha->fw_options[1], ha->fw_options[2],
4210 ha->fw_options[3], vha->host->active_mode);
4212 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
4213 qla2x00_set_fw_options(vha, ha->fw_options);
4215 /* Update Serial Link options. */
4216 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
4219 rval = qla2x00_set_serdes_params(vha,
4220 le16_to_cpu(ha->fw_seriallink_options24[1]),
4221 le16_to_cpu(ha->fw_seriallink_options24[2]),
4222 le16_to_cpu(ha->fw_seriallink_options24[3]));
4223 if (rval != QLA_SUCCESS) {
4224 ql_log(ql_log_warn, vha, 0x0104,
4225 "Unable to update Serial Link options (%x).\n", rval);
4230 qla2x00_config_rings(struct scsi_qla_host *vha)
4232 struct qla_hw_data *ha = vha->hw;
4233 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4234 struct req_que *req = ha->req_q_map[0];
4235 struct rsp_que *rsp = ha->rsp_q_map[0];
4237 /* Setup ring parameters in initialization control block. */
4238 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
4239 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
4240 ha->init_cb->request_q_length = cpu_to_le16(req->length);
4241 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
4242 put_unaligned_le64(req->dma, &ha->init_cb->request_q_address);
4243 put_unaligned_le64(rsp->dma, &ha->init_cb->response_q_address);
4245 wrt_reg_word(ISP_REQ_Q_IN(ha, reg), 0);
4246 wrt_reg_word(ISP_REQ_Q_OUT(ha, reg), 0);
4247 wrt_reg_word(ISP_RSP_Q_IN(ha, reg), 0);
4248 wrt_reg_word(ISP_RSP_Q_OUT(ha, reg), 0);
4249 rd_reg_word(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
4253 qla24xx_config_rings(struct scsi_qla_host *vha)
4255 struct qla_hw_data *ha = vha->hw;
4256 device_reg_t *reg = ISP_QUE_REG(ha, 0);
4257 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
4258 struct qla_msix_entry *msix;
4259 struct init_cb_24xx *icb;
4261 struct req_que *req = ha->req_q_map[0];
4262 struct rsp_que *rsp = ha->rsp_q_map[0];
4264 /* Setup ring parameters in initialization control block. */
4265 icb = (struct init_cb_24xx *)ha->init_cb;
4266 icb->request_q_outpointer = cpu_to_le16(0);
4267 icb->response_q_inpointer = cpu_to_le16(0);
4268 icb->request_q_length = cpu_to_le16(req->length);
4269 icb->response_q_length = cpu_to_le16(rsp->length);
4270 put_unaligned_le64(req->dma, &icb->request_q_address);
4271 put_unaligned_le64(rsp->dma, &icb->response_q_address);
4273 /* Setup ATIO queue dma pointers for target mode */
4274 icb->atio_q_inpointer = cpu_to_le16(0);
4275 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
4276 put_unaligned_le64(ha->tgt.atio_dma, &icb->atio_q_address);
4278 if (IS_SHADOW_REG_CAPABLE(ha))
4279 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
4281 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4283 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
4284 icb->rid = cpu_to_le16(rid);
4285 if (ha->flags.msix_enabled) {
4286 msix = &ha->msix_entries[1];
4287 ql_dbg(ql_dbg_init, vha, 0x0019,
4288 "Registering vector 0x%x for base que.\n",
4290 icb->msix = cpu_to_le16(msix->entry);
4292 /* Use alternate PCI bus number */
4294 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
4295 /* Use alternate PCI devfn */
4297 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
4299 /* Use Disable MSIX Handshake mode for capable adapters */
4300 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
4301 (ha->flags.msix_enabled)) {
4302 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
4303 ha->flags.disable_msix_handshake = 1;
4304 ql_dbg(ql_dbg_init, vha, 0x00fe,
4305 "MSIX Handshake Disable Mode turned on.\n");
4307 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
4309 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
4311 wrt_reg_dword(®->isp25mq.req_q_in, 0);
4312 wrt_reg_dword(®->isp25mq.req_q_out, 0);
4313 wrt_reg_dword(®->isp25mq.rsp_q_in, 0);
4314 wrt_reg_dword(®->isp25mq.rsp_q_out, 0);
4316 wrt_reg_dword(®->isp24.req_q_in, 0);
4317 wrt_reg_dword(®->isp24.req_q_out, 0);
4318 wrt_reg_dword(®->isp24.rsp_q_in, 0);
4319 wrt_reg_dword(®->isp24.rsp_q_out, 0);
4322 qlt_24xx_config_rings(vha);
4324 /* If the user has configured the speed, set it here */
4325 if (ha->set_data_rate) {
4326 ql_dbg(ql_dbg_init, vha, 0x00fd,
4327 "Speed set by user : %s Gbps \n",
4328 qla2x00_get_link_speed_str(ha, ha->set_data_rate));
4329 icb->firmware_options_3 = cpu_to_le32(ha->set_data_rate << 13);
4333 rd_reg_word(&ioreg->hccr);
4337 * qla2x00_init_rings() - Initializes firmware.
4340 * Beginning of request ring has initialization control block already built
4341 * by nvram config routine.
4343 * Returns 0 on success.
4346 qla2x00_init_rings(scsi_qla_host_t *vha)
4349 unsigned long flags = 0;
4351 struct qla_hw_data *ha = vha->hw;
4352 struct req_que *req;
4353 struct rsp_que *rsp;
4354 struct mid_init_cb_24xx *mid_init_cb =
4355 (struct mid_init_cb_24xx *) ha->init_cb;
4357 spin_lock_irqsave(&ha->hardware_lock, flags);
4359 /* Clear outstanding commands array. */
4360 for (que = 0; que < ha->max_req_queues; que++) {
4361 req = ha->req_q_map[que];
4362 if (!req || !test_bit(que, ha->req_qid_map))
4364 req->out_ptr = (uint16_t *)(req->ring + req->length);
4366 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
4367 req->outstanding_cmds[cnt] = NULL;
4369 req->current_outstanding_cmd = 1;
4371 /* Initialize firmware. */
4372 req->ring_ptr = req->ring;
4373 req->ring_index = 0;
4374 req->cnt = req->length;
4377 for (que = 0; que < ha->max_rsp_queues; que++) {
4378 rsp = ha->rsp_q_map[que];
4379 if (!rsp || !test_bit(que, ha->rsp_qid_map))
4381 rsp->in_ptr = (uint16_t *)(rsp->ring + rsp->length);
4383 /* Initialize response queue entries */
4385 qlafx00_init_response_q_entries(rsp);
4387 qla2x00_init_response_q_entries(rsp);
4390 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
4391 ha->tgt.atio_ring_index = 0;
4392 /* Initialize ATIO queue entries */
4393 qlt_init_atio_q_entries(vha);
4395 ha->isp_ops->config_rings(vha);
4397 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4399 if (IS_QLAFX00(ha)) {
4400 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
4404 /* Update any ISP specific firmware options before initialization. */
4405 ha->isp_ops->update_fw_options(vha);
4407 ql_dbg(ql_dbg_init, vha, 0x00d1,
4408 "Issue init firmware FW opt 1-3= %08x %08x %08x.\n",
4409 le32_to_cpu(mid_init_cb->init_cb.firmware_options_1),
4410 le32_to_cpu(mid_init_cb->init_cb.firmware_options_2),
4411 le32_to_cpu(mid_init_cb->init_cb.firmware_options_3));
4413 if (ha->flags.npiv_supported) {
4414 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
4415 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
4416 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
4419 if (IS_FWI2_CAPABLE(ha)) {
4420 mid_init_cb->options = cpu_to_le16(BIT_1);
4421 mid_init_cb->init_cb.execution_throttle =
4422 cpu_to_le16(ha->cur_fw_xcb_count);
4423 ha->flags.dport_enabled =
4424 (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) &
4426 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
4427 (ha->flags.dport_enabled) ? "enabled" : "disabled");
4428 /* FA-WWPN Status */
4429 ha->flags.fawwpn_enabled =
4430 (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) &
4432 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
4433 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
4436 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
4439 ql_log(ql_log_fatal, vha, 0x00d2,
4440 "Init Firmware **** FAILED ****.\n");
4442 ql_dbg(ql_dbg_init, vha, 0x00d3,
4443 "Init Firmware -- success.\n");
4445 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0;
4452 * qla2x00_fw_ready() - Waits for firmware ready.
4455 * Returns 0 on success.
4458 qla2x00_fw_ready(scsi_qla_host_t *vha)
4461 unsigned long wtime, mtime, cs84xx_time;
4462 uint16_t min_wait; /* Minimum wait time if loop is down */
4463 uint16_t wait_time; /* Wait time if loop is coming ready */
4465 struct qla_hw_data *ha = vha->hw;
4467 if (IS_QLAFX00(vha->hw))
4468 return qlafx00_fw_ready(vha);
4470 /* Time to wait for loop down */
4471 if (IS_P3P_TYPE(ha))
4477 * Firmware should take at most one RATOV to login, plus 5 seconds for
4478 * our own processing.
4480 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
4481 wait_time = min_wait;
4484 /* Min wait time if loop down */
4485 mtime = jiffies + (min_wait * HZ);
4487 /* wait time before firmware ready */
4488 wtime = jiffies + (wait_time * HZ);
4490 /* Wait for ISP to finish LIP */
4491 if (!vha->flags.init_done)
4492 ql_log(ql_log_info, vha, 0x801e,
4493 "Waiting for LIP to complete.\n");
4496 memset(state, -1, sizeof(state));
4497 rval = qla2x00_get_firmware_state(vha, state);
4498 if (rval == QLA_SUCCESS) {
4499 if (state[0] < FSTATE_LOSS_OF_SYNC) {
4500 vha->device_flags &= ~DFLG_NO_CABLE;
4502 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
4503 ql_dbg(ql_dbg_taskm, vha, 0x801f,
4504 "fw_state=%x 84xx=%x.\n", state[0],
4506 if ((state[2] & FSTATE_LOGGED_IN) &&
4507 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
4508 ql_dbg(ql_dbg_taskm, vha, 0x8028,
4509 "Sending verify iocb.\n");
4511 cs84xx_time = jiffies;
4512 rval = qla84xx_init_chip(vha);
4513 if (rval != QLA_SUCCESS) {
4516 "Init chip failed.\n");
4520 /* Add time taken to initialize. */
4521 cs84xx_time = jiffies - cs84xx_time;
4522 wtime += cs84xx_time;
4523 mtime += cs84xx_time;
4524 ql_dbg(ql_dbg_taskm, vha, 0x8008,
4525 "Increasing wait time by %ld. "
4526 "New time %ld.\n", cs84xx_time,
4529 } else if (state[0] == FSTATE_READY) {
4530 ql_dbg(ql_dbg_taskm, vha, 0x8037,
4531 "F/W Ready - OK.\n");
4533 qla2x00_get_retry_cnt(vha, &ha->retry_count,
4534 &ha->login_timeout, &ha->r_a_tov);
4540 rval = QLA_FUNCTION_FAILED;
4542 if (atomic_read(&vha->loop_down_timer) &&
4543 state[0] != FSTATE_READY) {
4544 /* Loop down. Timeout on min_wait for states
4545 * other than Wait for Login.
4547 if (time_after_eq(jiffies, mtime)) {
4548 ql_log(ql_log_info, vha, 0x8038,
4549 "Cable is unplugged...\n");
4551 vha->device_flags |= DFLG_NO_CABLE;
4556 /* Mailbox cmd failed. Timeout on min_wait. */
4557 if (time_after_eq(jiffies, mtime) ||
4558 ha->flags.isp82xx_fw_hung)
4562 if (time_after_eq(jiffies, wtime))
4565 /* Delay for a while */
4569 ql_dbg(ql_dbg_taskm, vha, 0x803a,
4570 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
4571 state[1], state[2], state[3], state[4], state[5], jiffies);
4573 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
4574 ql_log(ql_log_warn, vha, 0x803b,
4575 "Firmware ready **** FAILED ****.\n");
4582 * qla2x00_configure_hba
4583 * Setup adapter context.
4586 * ha = adapter state pointer.
4595 qla2x00_configure_hba(scsi_qla_host_t *vha)
4604 char connect_type[22];
4605 struct qla_hw_data *ha = vha->hw;
4606 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4608 unsigned long flags;
4610 /* Get host addresses. */
4611 rval = qla2x00_get_adapter_id(vha,
4612 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
4613 if (rval != QLA_SUCCESS) {
4614 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
4615 IS_CNA_CAPABLE(ha) ||
4616 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
4617 ql_dbg(ql_dbg_disc, vha, 0x2008,
4618 "Loop is in a transition state.\n");
4620 ql_log(ql_log_warn, vha, 0x2009,
4621 "Unable to get host loop ID.\n");
4622 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
4623 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
4624 ql_log(ql_log_warn, vha, 0x1151,
4625 "Doing link init.\n");
4626 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
4629 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4635 ql_log(ql_log_info, vha, 0x200a,
4636 "Cannot get topology - retrying.\n");
4637 return (QLA_FUNCTION_FAILED);
4640 vha->loop_id = loop_id;
4643 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
4644 ha->operating_mode = LOOP;
4648 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
4650 ha->current_topology = ISP_CFG_NL;
4651 strcpy(connect_type, "(Loop)");
4655 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
4656 ha->switch_cap = sw_cap;
4657 ha->current_topology = ISP_CFG_FL;
4658 strcpy(connect_type, "(FL_Port)");
4662 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
4664 ha->operating_mode = P2P;
4665 ha->current_topology = ISP_CFG_N;
4666 strcpy(connect_type, "(N_Port-to-N_Port)");
4670 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
4671 ha->switch_cap = sw_cap;
4672 ha->operating_mode = P2P;
4673 ha->current_topology = ISP_CFG_F;
4674 strcpy(connect_type, "(F_Port)");
4678 ql_dbg(ql_dbg_disc, vha, 0x200f,
4679 "HBA in unknown topology %x, using NL.\n", topo);
4681 ha->current_topology = ISP_CFG_NL;
4682 strcpy(connect_type, "(Loop)");
4686 /* Save Host port and loop ID. */
4687 /* byte order - Big Endian */
4688 id.b.domain = domain;
4692 spin_lock_irqsave(&ha->hardware_lock, flags);
4693 if (vha->hw->flags.edif_enabled) {
4695 qlt_update_host_map(vha, id);
4696 } else if (!(topo == 2 && ha->flags.n2n_bigger))
4697 qlt_update_host_map(vha, id);
4698 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4700 if (!vha->flags.init_done)
4701 ql_log(ql_log_info, vha, 0x2010,
4702 "Topology - %s, Host Loop address 0x%x.\n",
4703 connect_type, vha->loop_id);
4709 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
4714 uint64_t zero[2] = { 0 };
4715 struct qla_hw_data *ha = vha->hw;
4716 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
4717 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
4719 if (len > sizeof(zero))
4721 if (memcmp(model, &zero, len) != 0) {
4722 memcpy(ha->model_number, model, len);
4723 st = en = ha->model_number;
4726 if (*en != 0x20 && *en != 0x00)
4731 index = (ha->pdev->subsystem_device & 0xff);
4733 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4734 index < QLA_MODEL_NAMES)
4735 strlcpy(ha->model_desc,
4736 qla2x00_model_name[index * 2 + 1],
4737 sizeof(ha->model_desc));
4739 index = (ha->pdev->subsystem_device & 0xff);
4741 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4742 index < QLA_MODEL_NAMES) {
4743 strlcpy(ha->model_number,
4744 qla2x00_model_name[index * 2],
4745 sizeof(ha->model_number));
4746 strlcpy(ha->model_desc,
4747 qla2x00_model_name[index * 2 + 1],
4748 sizeof(ha->model_desc));
4750 strlcpy(ha->model_number, def,
4751 sizeof(ha->model_number));
4754 if (IS_FWI2_CAPABLE(ha))
4755 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
4756 sizeof(ha->model_desc));
4759 /* On sparc systems, obtain port and node WWN from firmware
4762 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4765 struct qla_hw_data *ha = vha->hw;
4766 struct pci_dev *pdev = ha->pdev;
4767 struct device_node *dp = pci_device_to_OF_node(pdev);
4771 val = of_get_property(dp, "port-wwn", &len);
4772 if (val && len >= WWN_SIZE)
4773 memcpy(nv->port_name, val, WWN_SIZE);
4775 val = of_get_property(dp, "node-wwn", &len);
4776 if (val && len >= WWN_SIZE)
4777 memcpy(nv->node_name, val, WWN_SIZE);
4782 * NVRAM configuration for ISP 2xxx
4785 * ha = adapter block pointer.
4788 * initialization control block in response_ring
4789 * host adapters parameters in host adapter block
4795 qla2x00_nvram_config(scsi_qla_host_t *vha)
4800 uint8_t *dptr1, *dptr2;
4801 struct qla_hw_data *ha = vha->hw;
4802 init_cb_t *icb = ha->init_cb;
4803 nvram_t *nv = ha->nvram;
4804 uint8_t *ptr = ha->nvram;
4805 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4809 /* Determine NVRAM starting address. */
4810 ha->nvram_size = sizeof(*nv);
4812 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4813 if ((rd_reg_word(®->ctrl_status) >> 14) == 1)
4814 ha->nvram_base = 0x80;
4816 /* Get NVRAM data and calculate checksum. */
4817 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
4818 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4821 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4822 "Contents of NVRAM.\n");
4823 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4824 nv, ha->nvram_size);
4826 /* Bad NVRAM data, set defaults parameters. */
4827 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
4828 nv->nvram_version < 1) {
4829 /* Reset NVRAM data. */
4830 ql_log(ql_log_warn, vha, 0x0064,
4831 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
4832 chksum, nv->id, nv->nvram_version);
4833 ql_log(ql_log_warn, vha, 0x0065,
4835 "functioning (yet invalid -- WWPN) defaults.\n");
4838 * Set default initialization control block.
4840 memset(nv, 0, ha->nvram_size);
4841 nv->parameter_block_version = ICB_VERSION;
4843 if (IS_QLA23XX(ha)) {
4844 nv->firmware_options[0] = BIT_2 | BIT_1;
4845 nv->firmware_options[1] = BIT_7 | BIT_5;
4846 nv->add_firmware_options[0] = BIT_5;
4847 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4848 nv->frame_payload_size = cpu_to_le16(2048);
4849 nv->special_options[1] = BIT_7;
4850 } else if (IS_QLA2200(ha)) {
4851 nv->firmware_options[0] = BIT_2 | BIT_1;
4852 nv->firmware_options[1] = BIT_7 | BIT_5;
4853 nv->add_firmware_options[0] = BIT_5;
4854 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4855 nv->frame_payload_size = cpu_to_le16(1024);
4856 } else if (IS_QLA2100(ha)) {
4857 nv->firmware_options[0] = BIT_3 | BIT_1;
4858 nv->firmware_options[1] = BIT_5;
4859 nv->frame_payload_size = cpu_to_le16(1024);
4862 nv->max_iocb_allocation = cpu_to_le16(256);
4863 nv->execution_throttle = cpu_to_le16(16);
4864 nv->retry_count = 8;
4865 nv->retry_delay = 1;
4867 nv->port_name[0] = 33;
4868 nv->port_name[3] = 224;
4869 nv->port_name[4] = 139;
4871 qla2xxx_nvram_wwn_from_ofw(vha, nv);
4873 nv->login_timeout = 4;
4876 * Set default host adapter parameters
4878 nv->host_p[1] = BIT_2;
4879 nv->reset_delay = 5;
4880 nv->port_down_retry_count = 8;
4881 nv->max_luns_per_target = cpu_to_le16(8);
4882 nv->link_down_timeout = 60;
4887 /* Reset Initialization control block */
4888 memset(icb, 0, ha->init_cb_size);
4891 * Setup driver NVRAM options.
4893 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4894 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4895 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4896 nv->firmware_options[1] &= ~BIT_4;
4898 if (IS_QLA23XX(ha)) {
4899 nv->firmware_options[0] |= BIT_2;
4900 nv->firmware_options[0] &= ~BIT_3;
4901 nv->special_options[0] &= ~BIT_6;
4902 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
4904 if (IS_QLA2300(ha)) {
4905 if (ha->fb_rev == FPM_2310) {
4906 strcpy(ha->model_number, "QLA2310");
4908 strcpy(ha->model_number, "QLA2300");
4911 qla2x00_set_model_info(vha, nv->model_number,
4912 sizeof(nv->model_number), "QLA23xx");
4914 } else if (IS_QLA2200(ha)) {
4915 nv->firmware_options[0] |= BIT_2;
4917 * 'Point-to-point preferred, else loop' is not a safe
4918 * connection mode setting.
4920 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4922 /* Force 'loop preferred, else point-to-point'. */
4923 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4924 nv->add_firmware_options[0] |= BIT_5;
4926 strcpy(ha->model_number, "QLA22xx");
4927 } else /*if (IS_QLA2100(ha))*/ {
4928 strcpy(ha->model_number, "QLA2100");
4932 * Copy over NVRAM RISC parameter block to initialization control block.
4934 dptr1 = (uint8_t *)icb;
4935 dptr2 = (uint8_t *)&nv->parameter_block_version;
4936 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4938 *dptr1++ = *dptr2++;
4940 /* Copy 2nd half. */
4941 dptr1 = (uint8_t *)icb->add_firmware_options;
4942 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4944 *dptr1++ = *dptr2++;
4945 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
4946 /* Use alternate WWN? */
4947 if (nv->host_p[1] & BIT_7) {
4948 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4949 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4952 /* Prepare nodename */
4953 if ((icb->firmware_options[1] & BIT_6) == 0) {
4955 * Firmware will apply the following mask if the nodename was
4958 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4959 icb->node_name[0] &= 0xF0;
4963 * Set host adapter parameters.
4967 * BIT_7 in the host-parameters section allows for modification to
4968 * internal driver logging.
4970 if (nv->host_p[0] & BIT_7)
4971 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
4972 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4973 /* Always load RISC code on non ISP2[12]00 chips. */
4974 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4975 ha->flags.disable_risc_code_load = 0;
4976 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4977 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4978 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
4979 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
4980 ha->flags.disable_serdes = 0;
4982 ha->operating_mode =
4983 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4985 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4986 sizeof(ha->fw_seriallink_options));
4988 /* save HBA serial number */
4989 ha->serial0 = icb->port_name[5];
4990 ha->serial1 = icb->port_name[6];
4991 ha->serial2 = icb->port_name[7];
4992 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4993 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4995 icb->execution_throttle = cpu_to_le16(0xFFFF);
4997 ha->retry_count = nv->retry_count;
4999 /* Set minimum login_timeout to 4 seconds. */
5000 if (nv->login_timeout != ql2xlogintimeout)
5001 nv->login_timeout = ql2xlogintimeout;
5002 if (nv->login_timeout < 4)
5003 nv->login_timeout = 4;
5004 ha->login_timeout = nv->login_timeout;
5006 /* Set minimum RATOV to 100 tenths of a second. */
5009 ha->loop_reset_delay = nv->reset_delay;
5011 /* Link Down Timeout = 0:
5013 * When Port Down timer expires we will start returning
5014 * I/O's to OS with "DID_NO_CONNECT".
5016 * Link Down Timeout != 0:
5018 * The driver waits for the link to come up after link down
5019 * before returning I/Os to OS with "DID_NO_CONNECT".
5021 if (nv->link_down_timeout == 0) {
5022 ha->loop_down_abort_time =
5023 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5025 ha->link_down_timeout = nv->link_down_timeout;
5026 ha->loop_down_abort_time =
5027 (LOOP_DOWN_TIME - ha->link_down_timeout);
5031 * Need enough time to try and get the port back.
5033 ha->port_down_retry_count = nv->port_down_retry_count;
5034 if (qlport_down_retry)
5035 ha->port_down_retry_count = qlport_down_retry;
5036 /* Set login_retry_count */
5037 ha->login_retry_count = nv->retry_count;
5038 if (ha->port_down_retry_count == nv->port_down_retry_count &&
5039 ha->port_down_retry_count > 3)
5040 ha->login_retry_count = ha->port_down_retry_count;
5041 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5042 ha->login_retry_count = ha->port_down_retry_count;
5043 if (ql2xloginretrycount)
5044 ha->login_retry_count = ql2xloginretrycount;
5046 icb->lun_enables = cpu_to_le16(0);
5047 icb->command_resource_count = 0;
5048 icb->immediate_notify_resource_count = 0;
5049 icb->timeout = cpu_to_le16(0);
5051 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
5053 icb->firmware_options[0] &= ~BIT_3;
5054 icb->add_firmware_options[0] &=
5055 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
5056 icb->add_firmware_options[0] |= BIT_2;
5057 icb->response_accumulation_timer = 3;
5058 icb->interrupt_delay_timer = 5;
5060 vha->flags.process_response_queue = 1;
5063 if (!vha->flags.init_done) {
5064 ha->zio_mode = icb->add_firmware_options[0] &
5065 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5066 ha->zio_timer = icb->interrupt_delay_timer ?
5067 icb->interrupt_delay_timer : 2;
5069 icb->add_firmware_options[0] &=
5070 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
5071 vha->flags.process_response_queue = 0;
5072 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5073 ha->zio_mode = QLA_ZIO_MODE_6;
5075 ql_log(ql_log_info, vha, 0x0068,
5076 "ZIO mode %d enabled; timer delay (%d us).\n",
5077 ha->zio_mode, ha->zio_timer * 100);
5079 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
5080 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
5081 vha->flags.process_response_queue = 1;
5086 ql_log(ql_log_warn, vha, 0x0069,
5087 "NVRAM configuration failed.\n");
5093 qla2x00_rport_del(void *data)
5095 fc_port_t *fcport = data;
5096 struct fc_rport *rport;
5097 unsigned long flags;
5099 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5100 rport = fcport->drport ? fcport->drport : fcport->rport;
5101 fcport->drport = NULL;
5102 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5104 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
5105 "%s %8phN. rport %p roles %x\n",
5106 __func__, fcport->port_name, rport,
5109 fc_remote_port_delete(rport);
5113 void qla2x00_set_fcport_state(fc_port_t *fcport, int state)
5117 old_state = atomic_read(&fcport->state);
5118 atomic_set(&fcport->state, state);
5120 /* Don't print state transitions during initial allocation of fcport */
5121 if (old_state && old_state != state) {
5122 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
5123 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
5124 fcport->port_name, port_state_str[old_state],
5125 port_state_str[state], fcport->d_id.b.domain,
5126 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5131 * qla2x00_alloc_fcport() - Allocate a generic fcport.
5133 * @flags: allocation flags
5135 * Returns a pointer to the allocated fcport, or NULL, if none available.
5138 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
5142 fcport = kzalloc(sizeof(fc_port_t), flags);
5146 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
5147 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
5149 if (!fcport->ct_desc.ct_sns) {
5150 ql_log(ql_log_warn, vha, 0xd049,
5151 "Failed to allocate ct_sns request.\n");
5156 /* Setup fcport template structure. */
5158 fcport->port_type = FCT_UNKNOWN;
5159 fcport->loop_id = FC_NO_LOOP_ID;
5160 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
5161 fcport->supported_classes = FC_COS_UNSPECIFIED;
5162 fcport->fp_speed = PORT_SPEED_UNKNOWN;
5164 fcport->disc_state = DSC_DELETED;
5165 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
5166 fcport->deleted = QLA_SESS_DELETED;
5167 fcport->login_retry = vha->hw->login_retry_count;
5168 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
5169 fcport->logout_on_delete = 1;
5170 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
5171 fcport->tgt_short_link_down_cnt = 0;
5172 fcport->dev_loss_tmo = 0;
5174 if (!fcport->ct_desc.ct_sns) {
5175 ql_log(ql_log_warn, vha, 0xd049,
5176 "Failed to allocate ct_sns request.\n");
5181 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
5182 INIT_WORK(&fcport->free_work, qlt_free_session_done);
5183 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
5184 INIT_LIST_HEAD(&fcport->gnl_entry);
5185 INIT_LIST_HEAD(&fcport->list);
5187 INIT_LIST_HEAD(&fcport->sess_cmd_list);
5188 spin_lock_init(&fcport->sess_cmd_lock);
5190 spin_lock_init(&fcport->edif.sa_list_lock);
5191 INIT_LIST_HEAD(&fcport->edif.tx_sa_list);
5192 INIT_LIST_HEAD(&fcport->edif.rx_sa_list);
5194 if (vha->e_dbell.db_flags == EDB_ACTIVE)
5195 fcport->edif.app_started = 1;
5197 spin_lock_init(&fcport->edif.indx_list_lock);
5198 INIT_LIST_HEAD(&fcport->edif.edif_indx_list);
5204 qla2x00_free_fcport(fc_port_t *fcport)
5206 if (fcport->ct_desc.ct_sns) {
5207 dma_free_coherent(&fcport->vha->hw->pdev->dev,
5208 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
5209 fcport->ct_desc.ct_sns_dma);
5211 fcport->ct_desc.ct_sns = NULL;
5214 qla_edif_flush_sa_ctl_lists(fcport);
5215 list_del(&fcport->list);
5216 qla2x00_clear_loop_id(fcport);
5218 qla_edif_list_del(fcport);
5223 static void qla_get_login_template(scsi_qla_host_t *vha)
5225 struct qla_hw_data *ha = vha->hw;
5230 memset(ha->init_cb, 0, ha->init_cb_size);
5231 sz = min_t(int, sizeof(struct fc_els_flogi), ha->init_cb_size);
5232 rval = qla24xx_get_port_login_templ(vha, ha->init_cb_dma,
5234 if (rval != QLA_SUCCESS) {
5235 ql_dbg(ql_dbg_init, vha, 0x00d1,
5236 "PLOGI ELS param read fail.\n");
5239 q = (__be32 *)&ha->plogi_els_payld.fl_csp;
5241 bp = (uint32_t *)ha->init_cb;
5242 cpu_to_be32_array(q, bp, sz / 4);
5243 ha->flags.plogi_template_valid = 1;
5247 * qla2x00_configure_loop
5248 * Updates Fibre Channel Device Database with what is actually on loop.
5251 * ha = adapter block pointer.
5256 * 2 = database was full and device was not configured.
5259 qla2x00_configure_loop(scsi_qla_host_t *vha)
5262 unsigned long flags, save_flags;
5263 struct qla_hw_data *ha = vha->hw;
5267 /* Get Initiator ID */
5268 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
5269 rval = qla2x00_configure_hba(vha);
5270 if (rval != QLA_SUCCESS) {
5271 ql_dbg(ql_dbg_disc, vha, 0x2013,
5272 "Unable to configure HBA.\n");
5277 save_flags = flags = vha->dpc_flags;
5278 ql_dbg(ql_dbg_disc, vha, 0x2014,
5279 "Configure loop -- dpc flags = 0x%lx.\n", flags);
5282 * If we have both an RSCN and PORT UPDATE pending then handle them
5283 * both at the same time.
5285 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5286 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
5288 qla2x00_get_data_rate(vha);
5289 qla_get_login_template(vha);
5291 /* Determine what we need to do */
5292 if ((ha->current_topology == ISP_CFG_FL ||
5293 ha->current_topology == ISP_CFG_F) &&
5294 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
5296 set_bit(RSCN_UPDATE, &flags);
5297 clear_bit(LOCAL_LOOP_UPDATE, &flags);
5299 } else if (ha->current_topology == ISP_CFG_NL ||
5300 ha->current_topology == ISP_CFG_N) {
5301 clear_bit(RSCN_UPDATE, &flags);
5302 set_bit(LOCAL_LOOP_UPDATE, &flags);
5303 } else if (!vha->flags.online ||
5304 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
5305 set_bit(RSCN_UPDATE, &flags);
5306 set_bit(LOCAL_LOOP_UPDATE, &flags);
5309 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
5310 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5311 ql_dbg(ql_dbg_disc, vha, 0x2015,
5312 "Loop resync needed, failing.\n");
5313 rval = QLA_FUNCTION_FAILED;
5315 rval = qla2x00_configure_local_loop(vha);
5318 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
5319 if (LOOP_TRANSITION(vha)) {
5320 ql_dbg(ql_dbg_disc, vha, 0x2099,
5321 "Needs RSCN update and loop transition.\n");
5322 rval = QLA_FUNCTION_FAILED;
5325 rval = qla2x00_configure_fabric(vha);
5328 if (rval == QLA_SUCCESS) {
5329 if (atomic_read(&vha->loop_down_timer) ||
5330 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5331 rval = QLA_FUNCTION_FAILED;
5333 atomic_set(&vha->loop_state, LOOP_READY);
5334 ql_dbg(ql_dbg_disc, vha, 0x2069,
5336 ha->flags.fw_init_done = 1;
5338 if (ha->flags.edif_enabled &&
5339 !(vha->e_dbell.db_flags & EDB_ACTIVE) &&
5340 N2N_TOPO(vha->hw)) {
5342 * use port online to wake up app to get ready
5343 * for authentication
5345 qla2x00_post_aen_work(vha, FCH_EVT_PORT_ONLINE, 0);
5349 * Process any ATIO queue entries that came in
5350 * while we weren't online.
5352 if (qla_tgt_mode_enabled(vha) ||
5353 qla_dual_mode_enabled(vha)) {
5354 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
5355 qlt_24xx_process_atio_queue(vha, 0);
5356 spin_unlock_irqrestore(&ha->tgt.atio_lock,
5363 ql_dbg(ql_dbg_disc, vha, 0x206a,
5364 "%s *** FAILED ***.\n", __func__);
5366 ql_dbg(ql_dbg_disc, vha, 0x206b,
5367 "%s: exiting normally. local port wwpn %8phN id %06x)\n",
5368 __func__, vha->port_name, vha->d_id.b24);
5371 /* Restore state if a resync event occurred during processing */
5372 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5373 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
5374 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5375 if (test_bit(RSCN_UPDATE, &save_flags)) {
5376 set_bit(RSCN_UPDATE, &vha->dpc_flags);
5383 static int qla2x00_configure_n2n_loop(scsi_qla_host_t *vha)
5385 unsigned long flags;
5388 ql_dbg(ql_dbg_disc, vha, 0x206a, "%s %d.\n", __func__, __LINE__);
5390 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags))
5391 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5393 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5394 if (fcport->n2n_flag) {
5395 qla24xx_fcport_handle_login(vha, fcport);
5400 spin_lock_irqsave(&vha->work_lock, flags);
5401 vha->scan.scan_retry++;
5402 spin_unlock_irqrestore(&vha->work_lock, flags);
5404 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5405 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5406 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5408 return QLA_FUNCTION_FAILED;
5412 * qla2x00_configure_local_loop
5413 * Updates Fibre Channel Device Database with local loop devices.
5416 * ha = adapter block pointer.
5422 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
5427 fc_port_t *fcport, *new_fcport;
5430 struct gid_list_info *gid;
5432 uint8_t domain, area, al_pa;
5433 struct qla_hw_data *ha = vha->hw;
5434 unsigned long flags;
5436 /* Inititae N2N login. */
5438 return qla2x00_configure_n2n_loop(vha);
5442 entries = MAX_FIBRE_DEVICES_LOOP;
5444 /* Get list of logged in devices. */
5445 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
5446 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
5448 if (rval != QLA_SUCCESS)
5451 ql_dbg(ql_dbg_disc, vha, 0x2011,
5452 "Entries in ID list (%d).\n", entries);
5453 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
5454 ha->gid_list, entries * sizeof(*ha->gid_list));
5457 spin_lock_irqsave(&vha->work_lock, flags);
5458 vha->scan.scan_retry++;
5459 spin_unlock_irqrestore(&vha->work_lock, flags);
5461 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5462 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5463 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5466 vha->scan.scan_retry = 0;
5469 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5470 fcport->scan_state = QLA_FCPORT_SCAN;
5473 /* Allocate temporary fcport for any new fcports discovered. */
5474 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5475 if (new_fcport == NULL) {
5476 ql_log(ql_log_warn, vha, 0x2012,
5477 "Memory allocation failed for fcport.\n");
5478 rval = QLA_MEMORY_ALLOC_FAILED;
5481 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5483 /* Add devices to port list. */
5485 for (index = 0; index < entries; index++) {
5486 domain = gid->domain;
5489 if (IS_QLA2100(ha) || IS_QLA2200(ha))
5490 loop_id = gid->loop_id_2100;
5492 loop_id = le16_to_cpu(gid->loop_id);
5493 gid = (void *)gid + ha->gid_list_info_size;
5495 /* Bypass reserved domain fields. */
5496 if ((domain & 0xf0) == 0xf0)
5499 /* Bypass if not same domain and area of adapter. */
5500 if (area && domain && ((area != vha->d_id.b.area) ||
5501 (domain != vha->d_id.b.domain)) &&
5502 (ha->current_topology == ISP_CFG_NL))
5506 /* Bypass invalid local loop ID. */
5507 if (loop_id > LAST_LOCAL_LOOP_ID)
5510 memset(new_fcport->port_name, 0, WWN_SIZE);
5512 /* Fill in member data. */
5513 new_fcport->d_id.b.domain = domain;
5514 new_fcport->d_id.b.area = area;
5515 new_fcport->d_id.b.al_pa = al_pa;
5516 new_fcport->loop_id = loop_id;
5517 new_fcport->scan_state = QLA_FCPORT_FOUND;
5519 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
5520 if (rval2 != QLA_SUCCESS) {
5521 ql_dbg(ql_dbg_disc, vha, 0x2097,
5522 "Failed to retrieve fcport information "
5523 "-- get_port_database=%x, loop_id=0x%04x.\n",
5524 rval2, new_fcport->loop_id);
5525 /* Skip retry if N2N */
5526 if (ha->current_topology != ISP_CFG_N) {
5527 ql_dbg(ql_dbg_disc, vha, 0x2105,
5528 "Scheduling resync.\n");
5529 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5534 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5535 /* Check for matching device in port list. */
5538 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5539 if (memcmp(new_fcport->port_name, fcport->port_name,
5543 fcport->flags &= ~FCF_FABRIC_DEVICE;
5544 fcport->loop_id = new_fcport->loop_id;
5545 fcport->port_type = new_fcport->port_type;
5546 fcport->d_id.b24 = new_fcport->d_id.b24;
5547 memcpy(fcport->node_name, new_fcport->node_name,
5549 fcport->scan_state = QLA_FCPORT_FOUND;
5555 /* New device, add to fcports list. */
5556 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5558 /* Allocate a new replacement fcport. */
5559 fcport = new_fcport;
5561 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5563 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5565 if (new_fcport == NULL) {
5566 ql_log(ql_log_warn, vha, 0xd031,
5567 "Failed to allocate memory for fcport.\n");
5568 rval = QLA_MEMORY_ALLOC_FAILED;
5571 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5572 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5575 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5577 /* Base iIDMA settings on HBA port speed. */
5578 fcport->fp_speed = ha->link_data_rate;
5583 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5584 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5587 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5588 if ((qla_dual_mode_enabled(vha) ||
5589 qla_ini_mode_enabled(vha)) &&
5590 atomic_read(&fcport->state) == FCS_ONLINE) {
5591 qla2x00_mark_device_lost(vha, fcport,
5592 ql2xplogiabsentdevice);
5593 if (fcport->loop_id != FC_NO_LOOP_ID &&
5594 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5595 fcport->port_type != FCT_INITIATOR &&
5596 fcport->port_type != FCT_BROADCAST) {
5597 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5598 "%s %d %8phC post del sess\n",
5602 qlt_schedule_sess_for_deletion(fcport);
5608 if (fcport->scan_state == QLA_FCPORT_FOUND)
5609 qla24xx_fcport_handle_login(vha, fcport);
5612 qla2x00_free_fcport(new_fcport);
5617 ql_dbg(ql_dbg_disc, vha, 0x2098,
5618 "Configure local loop error exit: rval=%x.\n", rval);
5623 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5626 uint16_t mb[MAILBOX_REGISTER_COUNT];
5627 struct qla_hw_data *ha = vha->hw;
5629 if (!IS_IIDMA_CAPABLE(ha))
5632 if (atomic_read(&fcport->state) != FCS_ONLINE)
5635 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
5636 fcport->fp_speed > ha->link_data_rate ||
5637 !ha->flags.gpsc_supported)
5640 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
5642 if (rval != QLA_SUCCESS) {
5643 ql_dbg(ql_dbg_disc, vha, 0x2004,
5644 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5645 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
5647 ql_dbg(ql_dbg_disc, vha, 0x2005,
5648 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5649 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
5650 fcport->fp_speed, fcport->port_name);
5654 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5656 qla2x00_iidma_fcport(vha, fcport);
5657 qla24xx_update_fcport_fcp_prio(vha, fcport);
5660 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5662 struct qla_work_evt *e;
5664 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
5666 return QLA_FUNCTION_FAILED;
5668 e->u.fcport.fcport = fcport;
5669 return qla2x00_post_work(vha, e);
5672 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5674 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
5676 struct fc_rport_identifiers rport_ids;
5677 struct fc_rport *rport;
5678 unsigned long flags;
5680 if (atomic_read(&fcport->state) == FCS_ONLINE)
5683 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5684 rport_ids.port_name = wwn_to_u64(fcport->port_name);
5685 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5686 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5687 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5688 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
5690 ql_log(ql_log_warn, vha, 0x2006,
5691 "Unable to allocate fc remote port.\n");
5695 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5696 *((fc_port_t **)rport->dd_data) = fcport;
5697 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5698 fcport->dev_loss_tmo = rport->dev_loss_tmo;
5700 rport->supported_classes = fcport->supported_classes;
5702 rport_ids.roles = FC_PORT_ROLE_UNKNOWN;
5703 if (fcport->port_type == FCT_INITIATOR)
5704 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
5705 if (fcport->port_type == FCT_TARGET)
5706 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
5707 if (fcport->port_type & FCT_NVME_INITIATOR)
5708 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
5709 if (fcport->port_type & FCT_NVME_TARGET)
5710 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
5711 if (fcport->port_type & FCT_NVME_DISCOVERY)
5712 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
5714 fc_remote_port_rolechg(rport, rport_ids.roles);
5716 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5717 "%s: %8phN. rport %ld:0:%d (%p) is %s mode\n",
5718 __func__, fcport->port_name, vha->host_no,
5719 rport->scsi_target_id, rport,
5720 (fcport->port_type == FCT_TARGET) ? "tgt" :
5721 ((fcport->port_type & FCT_NVME) ? "nvme" : "ini"));
5725 * qla2x00_update_fcport
5726 * Updates device on list.
5729 * ha = adapter block pointer.
5730 * fcport = port structure pointer.
5740 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5742 if (IS_SW_RESV_ADDR(fcport->d_id))
5745 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
5746 __func__, fcport->port_name);
5748 qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT);
5749 fcport->login_retry = vha->hw->login_retry_count;
5750 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5751 fcport->deleted = 0;
5752 if (vha->hw->current_topology == ISP_CFG_NL)
5753 fcport->logout_on_delete = 0;
5755 fcport->logout_on_delete = 1;
5756 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
5758 if (fcport->tgt_link_down_time < fcport->dev_loss_tmo) {
5759 fcport->tgt_short_link_down_cnt++;
5760 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
5763 switch (vha->hw->current_topology) {
5766 fcport->keep_nport_handle = 1;
5772 qla2x00_iidma_fcport(vha, fcport);
5774 qla2x00_dfs_create_rport(vha, fcport);
5776 if (NVME_TARGET(vha->hw, fcport)) {
5777 qla_nvme_register_remote(vha, fcport);
5778 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
5779 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5783 qla24xx_update_fcport_fcp_prio(vha, fcport);
5785 switch (vha->host->active_mode) {
5786 case MODE_INITIATOR:
5787 qla2x00_reg_remote_port(vha, fcport);
5790 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5791 !vha->vha_tgt.qla_tgt->tgt_stopped)
5792 qlt_fc_port_added(vha, fcport);
5795 qla2x00_reg_remote_port(vha, fcport);
5796 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5797 !vha->vha_tgt.qla_tgt->tgt_stopped)
5798 qlt_fc_port_added(vha, fcport);
5804 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5806 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
5807 if (fcport->id_changed) {
5808 fcport->id_changed = 0;
5809 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5810 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5811 __func__, __LINE__, fcport->port_name,
5813 qla24xx_post_gfpnid_work(vha, fcport);
5815 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5816 "%s %d %8phC post gpsc fcp_cnt %d\n",
5817 __func__, __LINE__, fcport->port_name,
5819 qla24xx_post_gpsc_work(vha, fcport);
5823 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
5826 void qla_register_fcport_fn(struct work_struct *work)
5828 fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
5829 u32 rscn_gen = fcport->rscn_gen;
5832 if (IS_SW_RESV_ADDR(fcport->d_id))
5835 qla2x00_update_fcport(fcport->vha, fcport);
5837 if (rscn_gen != fcport->rscn_gen) {
5838 /* RSCN(s) came in while registration */
5839 switch (fcport->next_disc_state) {
5840 case DSC_DELETE_PEND:
5841 qlt_schedule_sess_for_deletion(fcport);
5844 data[0] = data[1] = 0;
5845 qla2x00_post_async_adisc_work(fcport->vha, fcport,
5855 * qla2x00_configure_fabric
5856 * Setup SNS devices with loop ID's.
5859 * ha = adapter block pointer.
5866 qla2x00_configure_fabric(scsi_qla_host_t *vha)
5870 uint16_t mb[MAILBOX_REGISTER_COUNT];
5872 LIST_HEAD(new_fcports);
5873 struct qla_hw_data *ha = vha->hw;
5876 /* If FL port exists, then SNS is present */
5877 if (IS_FWI2_CAPABLE(ha))
5878 loop_id = NPH_F_PORT;
5880 loop_id = SNS_FL_PORT;
5881 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
5882 if (rval != QLA_SUCCESS) {
5883 ql_dbg(ql_dbg_disc, vha, 0x20a0,
5884 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5886 vha->device_flags &= ~SWITCH_FOUND;
5887 return (QLA_SUCCESS);
5889 vha->device_flags |= SWITCH_FOUND;
5891 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_port_name, 0);
5892 if (rval != QLA_SUCCESS)
5893 ql_dbg(ql_dbg_disc, vha, 0x20ff,
5894 "Failed to get Fabric Port Name\n");
5896 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
5897 rval = qla2x00_send_change_request(vha, 0x3, 0);
5898 if (rval != QLA_SUCCESS)
5899 ql_log(ql_log_warn, vha, 0x121,
5900 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5905 qla2x00_mgmt_svr_login(vha);
5907 /* Ensure we are logged into the SNS. */
5908 loop_id = NPH_SNS_LID(ha);
5909 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5910 0xfc, mb, BIT_1|BIT_0);
5911 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5912 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5913 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5914 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
5915 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5920 if (ql2xfdmienable &&
5921 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5922 qla2x00_fdmi_register(vha);
5924 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5925 if (qla2x00_rft_id(vha)) {
5927 ql_dbg(ql_dbg_disc, vha, 0x20a2,
5928 "Register FC-4 TYPE failed.\n");
5929 if (test_bit(LOOP_RESYNC_NEEDED,
5933 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
5935 ql_dbg(ql_dbg_disc, vha, 0x209a,
5936 "Register FC-4 Features failed.\n");
5937 if (test_bit(LOOP_RESYNC_NEEDED,
5941 if (vha->flags.nvme_enabled) {
5942 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5943 ql_dbg(ql_dbg_disc, vha, 0x2049,
5944 "Register NVME FC Type Features failed.\n");
5947 if (qla2x00_rnn_id(vha)) {
5949 ql_dbg(ql_dbg_disc, vha, 0x2104,
5950 "Register Node Name failed.\n");
5951 if (test_bit(LOOP_RESYNC_NEEDED,
5954 } else if (qla2x00_rsnn_nn(vha)) {
5956 ql_dbg(ql_dbg_disc, vha, 0x209b,
5957 "Register Symbolic Node Name failed.\n");
5958 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5964 /* Mark the time right before querying FW for connected ports.
5965 * This process is long, asynchronous and by the time it's done,
5966 * collected information might not be accurate anymore. E.g.
5967 * disconnected port might have re-connected and a brand new
5968 * session has been created. In this case session's generation
5969 * will be newer than discovery_gen. */
5970 qlt_do_generation_tick(vha, &discovery_gen);
5972 if (USE_ASYNC_SCAN(ha)) {
5973 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
5976 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5978 list_for_each_entry(fcport, &vha->vp_fcports, list)
5979 fcport->scan_state = QLA_FCPORT_SCAN;
5981 rval = qla2x00_find_all_fabric_devs(vha);
5983 if (rval != QLA_SUCCESS)
5987 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5988 qla_nvme_register_hba(vha);
5991 ql_dbg(ql_dbg_disc, vha, 0x2068,
5992 "Configure fabric error exit rval=%d.\n", rval);
5998 * qla2x00_find_all_fabric_devs
6001 * ha = adapter block pointer.
6002 * dev = database device entry pointer.
6011 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
6015 fc_port_t *fcport, *new_fcport;
6020 int first_dev, last_dev;
6021 port_id_t wrap = {}, nxt_d_id;
6022 struct qla_hw_data *ha = vha->hw;
6023 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6024 unsigned long flags;
6028 /* Try GID_PT to get device list, else GAN. */
6030 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
6035 ql_dbg(ql_dbg_disc, vha, 0x209c,
6036 "GID_PT allocations failed, fallback on GA_NXT.\n");
6038 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
6039 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
6041 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6043 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
6045 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6047 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
6049 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6051 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
6053 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6057 /* If other queries succeeded probe for FC-4 type */
6059 qla2x00_gff_id(vha, swl);
6060 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6066 /* Allocate temporary fcport for any new fcports discovered. */
6067 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
6068 if (new_fcport == NULL) {
6069 ql_log(ql_log_warn, vha, 0x209d,
6070 "Failed to allocate memory for fcport.\n");
6071 return (QLA_MEMORY_ALLOC_FAILED);
6073 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
6074 /* Set start port ID scan at adapter ID. */
6078 /* Starting free loop ID. */
6079 loop_id = ha->min_external_loopid;
6080 for (; loop_id <= ha->max_loop_id; loop_id++) {
6081 if (qla2x00_is_reserved_id(vha, loop_id))
6084 if (ha->current_topology == ISP_CFG_FL &&
6085 (atomic_read(&vha->loop_down_timer) ||
6086 LOOP_TRANSITION(vha))) {
6087 atomic_set(&vha->loop_down_timer, 0);
6088 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6089 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
6095 wrap.b24 = new_fcport->d_id.b24;
6097 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
6098 memcpy(new_fcport->node_name,
6099 swl[swl_idx].node_name, WWN_SIZE);
6100 memcpy(new_fcport->port_name,
6101 swl[swl_idx].port_name, WWN_SIZE);
6102 memcpy(new_fcport->fabric_port_name,
6103 swl[swl_idx].fabric_port_name, WWN_SIZE);
6104 new_fcport->fp_speed = swl[swl_idx].fp_speed;
6105 new_fcport->fc4_type = swl[swl_idx].fc4_type;
6107 new_fcport->nvme_flag = 0;
6108 if (vha->flags.nvme_enabled &&
6109 swl[swl_idx].fc4_type & FS_FC4TYPE_NVME) {
6110 ql_log(ql_log_info, vha, 0x2131,
6111 "FOUND: NVME port %8phC as FC Type 28h\n",
6112 new_fcport->port_name);
6115 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
6121 /* Send GA_NXT to the switch */
6122 rval = qla2x00_ga_nxt(vha, new_fcport);
6123 if (rval != QLA_SUCCESS) {
6124 ql_log(ql_log_warn, vha, 0x209e,
6125 "SNS scan failed -- assuming "
6126 "zero-entry result.\n");
6132 /* If wrap on switch device list, exit. */
6134 wrap.b24 = new_fcport->d_id.b24;
6136 } else if (new_fcport->d_id.b24 == wrap.b24) {
6137 ql_dbg(ql_dbg_disc, vha, 0x209f,
6138 "Device wrap (%02x%02x%02x).\n",
6139 new_fcport->d_id.b.domain,
6140 new_fcport->d_id.b.area,
6141 new_fcport->d_id.b.al_pa);
6145 /* Bypass if same physical adapter. */
6146 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
6149 /* Bypass virtual ports of the same host. */
6150 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
6153 /* Bypass if same domain and area of adapter. */
6154 if (((new_fcport->d_id.b24 & 0xffff00) ==
6155 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
6159 /* Bypass reserved domain fields. */
6160 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
6163 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
6164 if (ql2xgffidenable &&
6165 (!(new_fcport->fc4_type & FS_FC4TYPE_FCP) &&
6166 new_fcport->fc4_type != 0))
6169 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
6171 /* Locate matching device in database. */
6173 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6174 if (memcmp(new_fcport->port_name, fcport->port_name,
6178 fcport->scan_state = QLA_FCPORT_FOUND;
6182 /* Update port state. */
6183 memcpy(fcport->fabric_port_name,
6184 new_fcport->fabric_port_name, WWN_SIZE);
6185 fcport->fp_speed = new_fcport->fp_speed;
6188 * If address the same and state FCS_ONLINE
6189 * (or in target mode), nothing changed.
6191 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
6192 (atomic_read(&fcport->state) == FCS_ONLINE ||
6193 (vha->host->active_mode == MODE_TARGET))) {
6197 if (fcport->login_retry == 0)
6198 fcport->login_retry =
6199 vha->hw->login_retry_count;
6201 * If device was not a fabric device before.
6203 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
6204 fcport->d_id.b24 = new_fcport->d_id.b24;
6205 qla2x00_clear_loop_id(fcport);
6206 fcport->flags |= (FCF_FABRIC_DEVICE |
6212 * Port ID changed or device was marked to be updated;
6213 * Log it out if still logged in and mark it for
6216 if (qla_tgt_mode_enabled(base_vha)) {
6217 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
6218 "port changed FC ID, %8phC"
6219 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
6221 fcport->d_id.b.domain,
6222 fcport->d_id.b.area,
6223 fcport->d_id.b.al_pa,
6225 new_fcport->d_id.b.domain,
6226 new_fcport->d_id.b.area,
6227 new_fcport->d_id.b.al_pa);
6228 fcport->d_id.b24 = new_fcport->d_id.b24;
6232 fcport->d_id.b24 = new_fcport->d_id.b24;
6233 fcport->flags |= FCF_LOGIN_NEEDED;
6237 if (found && NVME_TARGET(vha->hw, fcport)) {
6238 if (fcport->disc_state == DSC_DELETE_PEND) {
6239 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
6240 vha->fcport_count--;
6241 fcport->login_succ = 0;
6246 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6249 /* If device was not in our fcports list, then add it. */
6250 new_fcport->scan_state = QLA_FCPORT_FOUND;
6251 list_add_tail(&new_fcport->list, &vha->vp_fcports);
6253 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
6256 /* Allocate a new replacement fcport. */
6257 nxt_d_id.b24 = new_fcport->d_id.b24;
6258 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
6259 if (new_fcport == NULL) {
6260 ql_log(ql_log_warn, vha, 0xd032,
6261 "Memory allocation failed for fcport.\n");
6262 return (QLA_MEMORY_ALLOC_FAILED);
6264 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
6265 new_fcport->d_id.b24 = nxt_d_id.b24;
6268 qla2x00_free_fcport(new_fcport);
6271 * Logout all previous fabric dev marked lost, except FCP2 devices.
6273 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6274 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
6277 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
6280 if (fcport->scan_state == QLA_FCPORT_SCAN) {
6281 if ((qla_dual_mode_enabled(vha) ||
6282 qla_ini_mode_enabled(vha)) &&
6283 atomic_read(&fcport->state) == FCS_ONLINE) {
6284 qla2x00_mark_device_lost(vha, fcport,
6285 ql2xplogiabsentdevice);
6286 if (fcport->loop_id != FC_NO_LOOP_ID &&
6287 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
6288 fcport->port_type != FCT_INITIATOR &&
6289 fcport->port_type != FCT_BROADCAST) {
6290 ql_dbg(ql_dbg_disc, vha, 0x20f0,
6291 "%s %d %8phC post del sess\n",
6294 qlt_schedule_sess_for_deletion(fcport);
6300 if (fcport->scan_state == QLA_FCPORT_FOUND &&
6301 (fcport->flags & FCF_LOGIN_NEEDED) != 0)
6302 qla24xx_fcport_handle_login(vha, fcport);
6307 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
6309 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
6311 int loop_id = FC_NO_LOOP_ID;
6312 int lid = NPH_MGMT_SERVER - vha->vp_idx;
6313 unsigned long flags;
6314 struct qla_hw_data *ha = vha->hw;
6316 if (vha->vp_idx == 0) {
6317 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
6318 return NPH_MGMT_SERVER;
6321 /* pick id from high and work down to low */
6322 spin_lock_irqsave(&ha->vport_slock, flags);
6323 for (; lid > 0; lid--) {
6324 if (!test_bit(lid, vha->hw->loop_id_map)) {
6325 set_bit(lid, vha->hw->loop_id_map);
6330 spin_unlock_irqrestore(&ha->vport_slock, flags);
6336 * qla2x00_fabric_login
6337 * Issue fabric login command.
6340 * ha = adapter block pointer.
6341 * device = pointer to FC device type structure.
6344 * 0 - Login successfully
6346 * 2 - Initiator device
6350 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
6351 uint16_t *next_loopid)
6355 uint16_t tmp_loopid;
6356 uint16_t mb[MAILBOX_REGISTER_COUNT];
6357 struct qla_hw_data *ha = vha->hw;
6363 ql_dbg(ql_dbg_disc, vha, 0x2000,
6364 "Trying Fabric Login w/loop id 0x%04x for port "
6366 fcport->loop_id, fcport->d_id.b.domain,
6367 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6369 /* Login fcport on switch. */
6370 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
6371 fcport->d_id.b.domain, fcport->d_id.b.area,
6372 fcport->d_id.b.al_pa, mb, BIT_0);
6373 if (rval != QLA_SUCCESS) {
6376 if (mb[0] == MBS_PORT_ID_USED) {
6378 * Device has another loop ID. The firmware team
6379 * recommends the driver perform an implicit login with
6380 * the specified ID again. The ID we just used is save
6381 * here so we return with an ID that can be tried by
6385 tmp_loopid = fcport->loop_id;
6386 fcport->loop_id = mb[1];
6388 ql_dbg(ql_dbg_disc, vha, 0x2001,
6389 "Fabric Login: port in use - next loop "
6390 "id=0x%04x, port id= %02x%02x%02x.\n",
6391 fcport->loop_id, fcport->d_id.b.domain,
6392 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6394 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
6399 /* A retry occurred before. */
6400 *next_loopid = tmp_loopid;
6403 * No retry occurred before. Just increment the
6404 * ID value for next login.
6406 *next_loopid = (fcport->loop_id + 1);
6409 if (mb[1] & BIT_0) {
6410 fcport->port_type = FCT_INITIATOR;
6412 fcport->port_type = FCT_TARGET;
6413 if (mb[1] & BIT_1) {
6414 fcport->flags |= FCF_FCP2_DEVICE;
6419 fcport->supported_classes |= FC_COS_CLASS2;
6421 fcport->supported_classes |= FC_COS_CLASS3;
6423 if (IS_FWI2_CAPABLE(ha)) {
6426 FCF_CONF_COMP_SUPPORTED;
6431 } else if (mb[0] == MBS_LOOP_ID_USED) {
6433 * Loop ID already used, try next loop ID.
6436 rval = qla2x00_find_new_loop_id(vha, fcport);
6437 if (rval != QLA_SUCCESS) {
6438 /* Ran out of loop IDs to use */
6441 } else if (mb[0] == MBS_COMMAND_ERROR) {
6443 * Firmware possibly timed out during login. If NO
6444 * retries are left to do then the device is declared
6447 *next_loopid = fcport->loop_id;
6448 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6449 fcport->d_id.b.domain, fcport->d_id.b.area,
6450 fcport->d_id.b.al_pa);
6451 qla2x00_mark_device_lost(vha, fcport, 1);
6457 * unrecoverable / not handled error
6459 ql_dbg(ql_dbg_disc, vha, 0x2002,
6460 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6461 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
6462 fcport->d_id.b.area, fcport->d_id.b.al_pa,
6463 fcport->loop_id, jiffies);
6465 *next_loopid = fcport->loop_id;
6466 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6467 fcport->d_id.b.domain, fcport->d_id.b.area,
6468 fcport->d_id.b.al_pa);
6469 qla2x00_clear_loop_id(fcport);
6470 fcport->login_retry = 0;
6481 * qla2x00_local_device_login
6482 * Issue local device login command.
6485 * ha = adapter block pointer.
6486 * loop_id = loop id of device to login to.
6488 * Returns (Where's the #define!!!!):
6489 * 0 - Login successfully
6494 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
6497 uint16_t mb[MAILBOX_REGISTER_COUNT];
6499 memset(mb, 0, sizeof(mb));
6500 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
6501 if (rval == QLA_SUCCESS) {
6502 /* Interrogate mailbox registers for any errors */
6503 if (mb[0] == MBS_COMMAND_ERROR)
6505 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
6506 /* device not in PCB table */
6514 * qla2x00_loop_resync
6515 * Resync with fibre channel devices.
6518 * ha = adapter block pointer.
6524 qla2x00_loop_resync(scsi_qla_host_t *vha)
6526 int rval = QLA_SUCCESS;
6529 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6530 if (vha->flags.online) {
6531 if (!(rval = qla2x00_fw_ready(vha))) {
6532 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6535 if (!IS_QLAFX00(vha->hw)) {
6537 * Issue a marker after FW becomes
6540 qla2x00_marker(vha, vha->hw->base_qpair,
6542 vha->marker_needed = 0;
6545 /* Remap devices on Loop. */
6546 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6548 if (IS_QLAFX00(vha->hw))
6549 qlafx00_configure_devices(vha);
6551 qla2x00_configure_loop(vha);
6554 } while (!atomic_read(&vha->loop_down_timer) &&
6555 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6556 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
6561 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6562 return (QLA_FUNCTION_FAILED);
6565 ql_dbg(ql_dbg_disc, vha, 0x206c,
6566 "%s *** FAILED ***.\n", __func__);
6572 * qla2x00_perform_loop_resync
6573 * Description: This function will set the appropriate flags and call
6574 * qla2x00_loop_resync. If successful loop will be resynced
6575 * Arguments : scsi_qla_host_t pointer
6576 * returm : Success or Failure
6579 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
6583 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
6584 /*Configure the flags so that resync happens properly*/
6585 atomic_set(&ha->loop_down_timer, 0);
6586 if (!(ha->device_flags & DFLG_NO_CABLE)) {
6587 atomic_set(&ha->loop_state, LOOP_UP);
6588 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
6589 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
6590 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
6592 rval = qla2x00_loop_resync(ha);
6594 atomic_set(&ha->loop_state, LOOP_DEAD);
6596 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
6603 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
6606 struct scsi_qla_host *vha, *tvp;
6607 struct qla_hw_data *ha = base_vha->hw;
6608 unsigned long flags;
6610 spin_lock_irqsave(&ha->vport_slock, flags);
6611 /* Go with deferred removal of rport references. */
6612 list_for_each_entry_safe(vha, tvp, &base_vha->hw->vp_list, list) {
6613 atomic_inc(&vha->vref_count);
6614 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6615 if (fcport->drport &&
6616 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
6617 spin_unlock_irqrestore(&ha->vport_slock, flags);
6618 qla2x00_rport_del(fcport);
6620 spin_lock_irqsave(&ha->vport_slock, flags);
6623 atomic_dec(&vha->vref_count);
6624 wake_up(&vha->vref_waitq);
6626 spin_unlock_irqrestore(&ha->vport_slock, flags);
6629 /* Assumes idc_lock always held on entry */
6631 qla83xx_reset_ownership(scsi_qla_host_t *vha)
6633 struct qla_hw_data *ha = vha->hw;
6634 uint32_t drv_presence, drv_presence_mask;
6635 uint32_t dev_part_info1, dev_part_info2, class_type;
6636 uint32_t class_type_mask = 0x3;
6637 uint16_t fcoe_other_function = 0xffff, i;
6639 if (IS_QLA8044(ha)) {
6640 drv_presence = qla8044_rd_direct(vha,
6641 QLA8044_CRB_DRV_ACTIVE_INDEX);
6642 dev_part_info1 = qla8044_rd_direct(vha,
6643 QLA8044_CRB_DEV_PART_INFO_INDEX);
6644 dev_part_info2 = qla8044_rd_direct(vha,
6645 QLA8044_CRB_DEV_PART_INFO2);
6647 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6648 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
6649 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
6651 for (i = 0; i < 8; i++) {
6652 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
6653 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6654 (i != ha->portnum)) {
6655 fcoe_other_function = i;
6659 if (fcoe_other_function == 0xffff) {
6660 for (i = 0; i < 8; i++) {
6661 class_type = ((dev_part_info2 >> (i * 4)) &
6663 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6664 ((i + 8) != ha->portnum)) {
6665 fcoe_other_function = i + 8;
6671 * Prepare drv-presence mask based on fcoe functions present.
6672 * However consider only valid physical fcoe function numbers (0-15).
6674 drv_presence_mask = ~((1 << (ha->portnum)) |
6675 ((fcoe_other_function == 0xffff) ?
6676 0 : (1 << (fcoe_other_function))));
6678 /* We are the reset owner iff:
6679 * - No other protocol drivers present.
6680 * - This is the lowest among fcoe functions. */
6681 if (!(drv_presence & drv_presence_mask) &&
6682 (ha->portnum < fcoe_other_function)) {
6683 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
6684 "This host is Reset owner.\n");
6685 ha->flags.nic_core_reset_owner = 1;
6690 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
6692 int rval = QLA_SUCCESS;
6693 struct qla_hw_data *ha = vha->hw;
6696 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6697 if (rval == QLA_SUCCESS) {
6698 drv_ack |= (1 << ha->portnum);
6699 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6706 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
6708 int rval = QLA_SUCCESS;
6709 struct qla_hw_data *ha = vha->hw;
6712 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6713 if (rval == QLA_SUCCESS) {
6714 drv_ack &= ~(1 << ha->portnum);
6715 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6722 qla83xx_dev_state_to_string(uint32_t dev_state)
6724 switch (dev_state) {
6725 case QLA8XXX_DEV_COLD:
6726 return "COLD/RE-INIT";
6727 case QLA8XXX_DEV_INITIALIZING:
6728 return "INITIALIZING";
6729 case QLA8XXX_DEV_READY:
6731 case QLA8XXX_DEV_NEED_RESET:
6732 return "NEED RESET";
6733 case QLA8XXX_DEV_NEED_QUIESCENT:
6734 return "NEED QUIESCENT";
6735 case QLA8XXX_DEV_FAILED:
6737 case QLA8XXX_DEV_QUIESCENT:
6744 /* Assumes idc-lock always held on entry */
6746 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6748 struct qla_hw_data *ha = vha->hw;
6749 uint32_t idc_audit_reg = 0, duration_secs = 0;
6751 switch (audit_type) {
6752 case IDC_AUDIT_TIMESTAMP:
6753 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6754 idc_audit_reg = (ha->portnum) |
6755 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6756 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6759 case IDC_AUDIT_COMPLETION:
6760 duration_secs = ((jiffies_to_msecs(jiffies) -
6761 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6762 idc_audit_reg = (ha->portnum) |
6763 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6764 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6768 ql_log(ql_log_warn, vha, 0xb078,
6769 "Invalid audit type specified.\n");
6774 /* Assumes idc_lock always held on entry */
6776 qla83xx_initiating_reset(scsi_qla_host_t *vha)
6778 struct qla_hw_data *ha = vha->hw;
6779 uint32_t idc_control, dev_state;
6781 __qla83xx_get_idc_control(vha, &idc_control);
6782 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6783 ql_log(ql_log_info, vha, 0xb080,
6784 "NIC Core reset has been disabled. idc-control=0x%x\n",
6786 return QLA_FUNCTION_FAILED;
6789 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6790 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6791 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6792 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6793 QLA8XXX_DEV_NEED_RESET);
6794 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6795 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6797 const char *state = qla83xx_dev_state_to_string(dev_state);
6799 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
6801 /* SV: XXX: Is timeout required here? */
6802 /* Wait for IDC state change READY -> NEED_RESET */
6803 while (dev_state == QLA8XXX_DEV_READY) {
6804 qla83xx_idc_unlock(vha, 0);
6806 qla83xx_idc_lock(vha, 0);
6807 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6811 /* Send IDC ack by writing to drv-ack register */
6812 __qla83xx_set_drv_ack(vha);
6818 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6820 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6824 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6826 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6830 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6832 uint32_t drv_presence = 0;
6833 struct qla_hw_data *ha = vha->hw;
6835 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6836 if (drv_presence & (1 << ha->portnum))
6839 return QLA_TEST_FAILED;
6843 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6845 int rval = QLA_SUCCESS;
6846 struct qla_hw_data *ha = vha->hw;
6848 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6849 "Entered %s().\n", __func__);
6851 if (vha->device_flags & DFLG_DEV_FAILED) {
6852 ql_log(ql_log_warn, vha, 0xb059,
6853 "Device in unrecoverable FAILED state.\n");
6854 return QLA_FUNCTION_FAILED;
6857 qla83xx_idc_lock(vha, 0);
6859 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6860 ql_log(ql_log_warn, vha, 0xb05a,
6861 "Function=0x%x has been removed from IDC participation.\n",
6863 rval = QLA_FUNCTION_FAILED;
6867 qla83xx_reset_ownership(vha);
6869 rval = qla83xx_initiating_reset(vha);
6872 * Perform reset if we are the reset-owner,
6873 * else wait till IDC state changes to READY/FAILED.
6875 if (rval == QLA_SUCCESS) {
6876 rval = qla83xx_idc_state_handler(vha);
6878 if (rval == QLA_SUCCESS)
6879 ha->flags.nic_core_hung = 0;
6880 __qla83xx_clear_drv_ack(vha);
6884 qla83xx_idc_unlock(vha, 0);
6886 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6892 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6894 struct qla_hw_data *ha = vha->hw;
6895 int rval = QLA_FUNCTION_FAILED;
6897 if (!IS_MCTP_CAPABLE(ha)) {
6898 /* This message can be removed from the final version */
6899 ql_log(ql_log_info, vha, 0x506d,
6900 "This board is not MCTP capable\n");
6904 if (!ha->mctp_dump) {
6905 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6906 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6908 if (!ha->mctp_dump) {
6909 ql_log(ql_log_warn, vha, 0x506e,
6910 "Failed to allocate memory for mctp dump\n");
6915 #define MCTP_DUMP_STR_ADDR 0x00000000
6916 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6917 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6918 if (rval != QLA_SUCCESS) {
6919 ql_log(ql_log_warn, vha, 0x506f,
6920 "Failed to capture mctp dump\n");
6922 ql_log(ql_log_info, vha, 0x5070,
6923 "Mctp dump capture for host (%ld/%p).\n",
6924 vha->host_no, ha->mctp_dump);
6925 ha->mctp_dumped = 1;
6928 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
6929 ha->flags.nic_core_reset_hdlr_active = 1;
6930 rval = qla83xx_restart_nic_firmware(vha);
6932 /* NIC Core reset failed. */
6933 ql_log(ql_log_warn, vha, 0x5071,
6934 "Failed to restart nic firmware\n");
6936 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6937 "Restarted NIC firmware successfully.\n");
6938 ha->flags.nic_core_reset_hdlr_active = 0;
6946 * qla2x00_quiesce_io
6947 * Description: This function will block the new I/Os
6948 * Its not aborting any I/Os as context
6949 * is not destroyed during quiescence
6950 * Arguments: scsi_qla_host_t
6954 qla2x00_quiesce_io(scsi_qla_host_t *vha)
6956 struct qla_hw_data *ha = vha->hw;
6957 struct scsi_qla_host *vp, *tvp;
6958 unsigned long flags;
6960 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6961 "Quiescing I/O - ha=%p.\n", ha);
6963 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6964 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6965 atomic_set(&vha->loop_state, LOOP_DOWN);
6966 qla2x00_mark_all_devices_lost(vha);
6968 spin_lock_irqsave(&ha->vport_slock, flags);
6969 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
6970 atomic_inc(&vp->vref_count);
6971 spin_unlock_irqrestore(&ha->vport_slock, flags);
6973 qla2x00_mark_all_devices_lost(vp);
6975 spin_lock_irqsave(&ha->vport_slock, flags);
6976 atomic_dec(&vp->vref_count);
6978 spin_unlock_irqrestore(&ha->vport_slock, flags);
6980 if (!atomic_read(&vha->loop_down_timer))
6981 atomic_set(&vha->loop_down_timer,
6984 /* Wait for pending cmds to complete */
6985 WARN_ON_ONCE(qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST)
6990 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6992 struct qla_hw_data *ha = vha->hw;
6993 struct scsi_qla_host *vp, *tvp;
6994 unsigned long flags;
6998 /* For ISP82XX, driver waits for completion of the commands.
6999 * online flag should be set.
7001 if (!(IS_P3P_TYPE(ha)))
7002 vha->flags.online = 0;
7003 ha->flags.chip_reset_done = 0;
7004 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
7005 vha->qla_stats.total_isp_aborts++;
7007 ql_log(ql_log_info, vha, 0x00af,
7008 "Performing ISP error recovery - ha=%p.\n", ha);
7010 ha->flags.purge_mbox = 1;
7011 /* For ISP82XX, reset_chip is just disabling interrupts.
7012 * Driver waits for the completion of the commands.
7013 * the interrupts need to be enabled.
7015 if (!(IS_P3P_TYPE(ha)))
7016 ha->isp_ops->reset_chip(vha);
7018 ha->link_data_rate = PORT_SPEED_UNKNOWN;
7020 ha->flags.rida_fmt2 = 0;
7021 ha->flags.n2n_ae = 0;
7022 ha->flags.lip_ae = 0;
7023 ha->current_topology = 0;
7025 ha->flags.fw_init_done = 0;
7027 ha->base_qpair->chip_reset = ha->chip_reset;
7028 ha->base_qpair->cmd_cnt = ha->base_qpair->cmd_completion_cnt = 0;
7029 for (i = 0; i < ha->max_qpairs; i++) {
7030 if (ha->queue_pair_map[i]) {
7031 ha->queue_pair_map[i]->chip_reset =
7032 ha->base_qpair->chip_reset;
7033 ha->queue_pair_map[i]->cmd_cnt =
7034 ha->queue_pair_map[i]->cmd_completion_cnt = 0;
7038 /* purge MBox commands */
7039 if (atomic_read(&ha->num_pend_mbx_stage3)) {
7040 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
7041 complete(&ha->mbx_intr_comp);
7045 while (atomic_read(&ha->num_pend_mbx_stage3) ||
7046 atomic_read(&ha->num_pend_mbx_stage2) ||
7047 atomic_read(&ha->num_pend_mbx_stage1)) {
7053 ha->flags.purge_mbox = 0;
7055 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
7056 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
7057 atomic_set(&vha->loop_state, LOOP_DOWN);
7058 qla2x00_mark_all_devices_lost(vha);
7060 spin_lock_irqsave(&ha->vport_slock, flags);
7061 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7062 atomic_inc(&vp->vref_count);
7063 spin_unlock_irqrestore(&ha->vport_slock, flags);
7065 qla2x00_mark_all_devices_lost(vp);
7067 spin_lock_irqsave(&ha->vport_slock, flags);
7068 atomic_dec(&vp->vref_count);
7070 spin_unlock_irqrestore(&ha->vport_slock, flags);
7072 if (!atomic_read(&vha->loop_down_timer))
7073 atomic_set(&vha->loop_down_timer,
7077 /* Clear all async request states across all VPs. */
7078 list_for_each_entry(fcport, &vha->vp_fcports, list) {
7079 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7080 fcport->scan_state = 0;
7082 spin_lock_irqsave(&ha->vport_slock, flags);
7083 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7084 atomic_inc(&vp->vref_count);
7085 spin_unlock_irqrestore(&ha->vport_slock, flags);
7087 list_for_each_entry(fcport, &vp->vp_fcports, list)
7088 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
7090 spin_lock_irqsave(&ha->vport_slock, flags);
7091 atomic_dec(&vp->vref_count);
7093 spin_unlock_irqrestore(&ha->vport_slock, flags);
7095 /* Make sure for ISP 82XX IO DMA is complete */
7096 if (IS_P3P_TYPE(ha)) {
7097 qla82xx_chip_reset_cleanup(vha);
7098 ql_log(ql_log_info, vha, 0x00b4,
7099 "Done chip reset cleanup.\n");
7101 /* Done waiting for pending commands. Reset online flag */
7102 vha->flags.online = 0;
7105 /* Requeue all commands in outstanding command list. */
7106 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
7107 /* memory barrier */
7113 * Resets ISP and aborts all outstanding commands.
7116 * ha = adapter block pointer.
7122 qla2x00_abort_isp(scsi_qla_host_t *vha)
7126 struct qla_hw_data *ha = vha->hw;
7127 struct scsi_qla_host *vp, *tvp;
7128 struct req_que *req = ha->req_q_map[0];
7129 unsigned long flags;
7131 if (vha->flags.online) {
7132 qla2x00_abort_isp_cleanup(vha);
7134 if (vha->hw->flags.port_isolated)
7137 if (qla2x00_isp_reg_stat(ha)) {
7138 ql_log(ql_log_info, vha, 0x803f,
7139 "ISP Abort - ISP reg disconnect, exiting.\n");
7143 if (test_and_clear_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags)) {
7144 ha->flags.chip_reset_done = 1;
7145 vha->flags.online = 1;
7147 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7151 if (IS_QLA8031(ha)) {
7152 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
7153 "Clearing fcoe driver presence.\n");
7154 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
7155 ql_dbg(ql_dbg_p3p, vha, 0xb073,
7156 "Error while clearing DRV-Presence.\n");
7159 if (unlikely(pci_channel_offline(ha->pdev) &&
7160 ha->flags.pci_channel_io_perm_failure)) {
7161 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7166 switch (vha->qlini_mode) {
7167 case QLA2XXX_INI_MODE_DISABLED:
7168 if (!qla_tgt_mode_enabled(vha))
7171 case QLA2XXX_INI_MODE_DUAL:
7172 if (!qla_dual_mode_enabled(vha) &&
7173 !qla_ini_mode_enabled(vha))
7176 case QLA2XXX_INI_MODE_ENABLED:
7181 ha->isp_ops->get_flash_version(vha, req->ring);
7183 if (qla2x00_isp_reg_stat(ha)) {
7184 ql_log(ql_log_info, vha, 0x803f,
7185 "ISP Abort - ISP reg disconnect pre nvram config, exiting.\n");
7188 ha->isp_ops->nvram_config(vha);
7190 if (qla2x00_isp_reg_stat(ha)) {
7191 ql_log(ql_log_info, vha, 0x803f,
7192 "ISP Abort - ISP reg disconnect post nvmram config, exiting.\n");
7195 if (!qla2x00_restart_isp(vha)) {
7196 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7198 if (!atomic_read(&vha->loop_down_timer)) {
7200 * Issue marker command only when we are going
7201 * to start the I/O .
7203 vha->marker_needed = 1;
7206 vha->flags.online = 1;
7208 ha->isp_ops->enable_intrs(ha);
7210 ha->isp_abort_cnt = 0;
7211 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7213 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
7214 qla2x00_get_fw_version(vha);
7216 ha->flags.fce_enabled = 1;
7218 fce_calc_size(ha->fce_bufs));
7219 rval = qla2x00_enable_fce_trace(vha,
7220 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
7223 ql_log(ql_log_warn, vha, 0x8033,
7224 "Unable to reinitialize FCE "
7226 ha->flags.fce_enabled = 0;
7231 memset(ha->eft, 0, EFT_SIZE);
7232 rval = qla2x00_enable_eft_trace(vha,
7233 ha->eft_dma, EFT_NUM_BUFFERS);
7235 ql_log(ql_log_warn, vha, 0x8034,
7236 "Unable to reinitialize EFT "
7240 } else { /* failed the ISP abort */
7241 vha->flags.online = 1;
7242 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
7243 if (ha->isp_abort_cnt == 0) {
7244 ql_log(ql_log_fatal, vha, 0x8035,
7245 "ISP error recover failed - "
7246 "board disabled.\n");
7248 * The next call disables the board
7251 qla2x00_abort_isp_cleanup(vha);
7252 vha->flags.online = 0;
7253 clear_bit(ISP_ABORT_RETRY,
7256 } else { /* schedule another ISP abort */
7257 ha->isp_abort_cnt--;
7258 ql_dbg(ql_dbg_taskm, vha, 0x8020,
7259 "ISP abort - retry remaining %d.\n",
7264 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
7265 ql_dbg(ql_dbg_taskm, vha, 0x8021,
7266 "ISP error recovery - retrying (%d) "
7267 "more times.\n", ha->isp_abort_cnt);
7268 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7275 if (vha->hw->flags.port_isolated) {
7276 qla2x00_abort_isp_cleanup(vha);
7281 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
7282 qla2x00_configure_hba(vha);
7283 spin_lock_irqsave(&ha->vport_slock, flags);
7284 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
7286 atomic_inc(&vp->vref_count);
7287 spin_unlock_irqrestore(&ha->vport_slock, flags);
7289 qla2x00_vp_abort_isp(vp);
7291 spin_lock_irqsave(&ha->vport_slock, flags);
7292 atomic_dec(&vp->vref_count);
7295 spin_unlock_irqrestore(&ha->vport_slock, flags);
7297 if (IS_QLA8031(ha)) {
7298 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
7299 "Setting back fcoe driver presence.\n");
7300 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
7301 ql_dbg(ql_dbg_p3p, vha, 0xb074,
7302 "Error while setting DRV-Presence.\n");
7305 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
7313 * qla2x00_restart_isp
7314 * restarts the ISP after a reset
7317 * ha = adapter block pointer.
7323 qla2x00_restart_isp(scsi_qla_host_t *vha)
7326 struct qla_hw_data *ha = vha->hw;
7328 /* If firmware needs to be loaded */
7329 if (qla2x00_isp_firmware(vha)) {
7330 vha->flags.online = 0;
7331 status = ha->isp_ops->chip_diag(vha);
7334 status = qla2x00_setup_chip(vha);
7339 status = qla2x00_init_rings(vha);
7343 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7344 ha->flags.chip_reset_done = 1;
7346 /* Initialize the queues in use */
7347 qla25xx_init_queues(ha);
7349 status = qla2x00_fw_ready(vha);
7351 /* if no cable then assume it's good */
7352 return vha->device_flags & DFLG_NO_CABLE ? 0 : status;
7355 /* Issue a marker after FW becomes ready. */
7356 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
7357 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7363 qla25xx_init_queues(struct qla_hw_data *ha)
7365 struct rsp_que *rsp = NULL;
7366 struct req_que *req = NULL;
7367 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7371 for (i = 1; i < ha->max_rsp_queues; i++) {
7372 rsp = ha->rsp_q_map[i];
7373 if (rsp && test_bit(i, ha->rsp_qid_map)) {
7374 rsp->options &= ~BIT_0;
7375 ret = qla25xx_init_rsp_que(base_vha, rsp);
7376 if (ret != QLA_SUCCESS)
7377 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
7378 "%s Rsp que: %d init failed.\n",
7381 ql_dbg(ql_dbg_init, base_vha, 0x0100,
7382 "%s Rsp que: %d inited.\n",
7386 for (i = 1; i < ha->max_req_queues; i++) {
7387 req = ha->req_q_map[i];
7388 if (req && test_bit(i, ha->req_qid_map)) {
7389 /* Clear outstanding commands array. */
7390 req->options &= ~BIT_0;
7391 ret = qla25xx_init_req_que(base_vha, req);
7392 if (ret != QLA_SUCCESS)
7393 ql_dbg(ql_dbg_init, base_vha, 0x0101,
7394 "%s Req que: %d init failed.\n",
7397 ql_dbg(ql_dbg_init, base_vha, 0x0102,
7398 "%s Req que: %d inited.\n",
7406 * qla2x00_reset_adapter
7410 * ha = adapter block pointer.
7413 qla2x00_reset_adapter(scsi_qla_host_t *vha)
7415 unsigned long flags = 0;
7416 struct qla_hw_data *ha = vha->hw;
7417 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7419 vha->flags.online = 0;
7420 ha->isp_ops->disable_intrs(ha);
7422 spin_lock_irqsave(&ha->hardware_lock, flags);
7423 wrt_reg_word(®->hccr, HCCR_RESET_RISC);
7424 rd_reg_word(®->hccr); /* PCI Posting. */
7425 wrt_reg_word(®->hccr, HCCR_RELEASE_RISC);
7426 rd_reg_word(®->hccr); /* PCI Posting. */
7427 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7433 qla24xx_reset_adapter(scsi_qla_host_t *vha)
7435 unsigned long flags = 0;
7436 struct qla_hw_data *ha = vha->hw;
7437 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
7439 if (IS_P3P_TYPE(ha))
7442 vha->flags.online = 0;
7443 ha->isp_ops->disable_intrs(ha);
7445 spin_lock_irqsave(&ha->hardware_lock, flags);
7446 wrt_reg_dword(®->hccr, HCCRX_SET_RISC_RESET);
7447 rd_reg_dword(®->hccr);
7448 wrt_reg_dword(®->hccr, HCCRX_REL_RISC_PAUSE);
7449 rd_reg_dword(®->hccr);
7450 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7452 if (IS_NOPOLLING_TYPE(ha))
7453 ha->isp_ops->enable_intrs(ha);
7458 /* On sparc systems, obtain port and node WWN from firmware
7461 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
7462 struct nvram_24xx *nv)
7465 struct qla_hw_data *ha = vha->hw;
7466 struct pci_dev *pdev = ha->pdev;
7467 struct device_node *dp = pci_device_to_OF_node(pdev);
7471 val = of_get_property(dp, "port-wwn", &len);
7472 if (val && len >= WWN_SIZE)
7473 memcpy(nv->port_name, val, WWN_SIZE);
7475 val = of_get_property(dp, "node-wwn", &len);
7476 if (val && len >= WWN_SIZE)
7477 memcpy(nv->node_name, val, WWN_SIZE);
7482 qla24xx_nvram_config(scsi_qla_host_t *vha)
7485 struct init_cb_24xx *icb;
7486 struct nvram_24xx *nv;
7488 uint8_t *dptr1, *dptr2;
7491 struct qla_hw_data *ha = vha->hw;
7494 icb = (struct init_cb_24xx *)ha->init_cb;
7497 /* Determine NVRAM starting address. */
7498 if (ha->port_no == 0) {
7499 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
7500 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
7502 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
7503 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
7506 ha->nvram_size = sizeof(*nv);
7507 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7509 /* Get VPD data into cache */
7510 ha->vpd = ha->nvram + VPD_OFFSET;
7511 ha->isp_ops->read_nvram(vha, ha->vpd,
7512 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
7514 /* Get NVRAM data into cache and calculate checksum. */
7515 dptr = (__force __le32 *)nv;
7516 ha->isp_ops->read_nvram(vha, dptr, ha->nvram_base, ha->nvram_size);
7517 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7518 chksum += le32_to_cpu(*dptr);
7520 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
7521 "Contents of NVRAM\n");
7522 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
7523 nv, ha->nvram_size);
7525 /* Bad NVRAM data, set defaults parameters. */
7526 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
7527 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
7528 /* Reset NVRAM data. */
7529 ql_log(ql_log_warn, vha, 0x006b,
7530 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
7531 chksum, nv->id, nv->nvram_version);
7532 ql_dump_buffer(ql_dbg_init, vha, 0x006b, nv, sizeof(*nv));
7533 ql_log(ql_log_warn, vha, 0x006c,
7534 "Falling back to functioning (yet invalid -- WWPN) "
7538 * Set default initialization control block.
7540 memset(nv, 0, ha->nvram_size);
7541 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7542 nv->version = cpu_to_le16(ICB_VERSION);
7543 nv->frame_payload_size = cpu_to_le16(2048);
7544 nv->execution_throttle = cpu_to_le16(0xFFFF);
7545 nv->exchange_count = cpu_to_le16(0);
7546 nv->hard_address = cpu_to_le16(124);
7547 nv->port_name[0] = 0x21;
7548 nv->port_name[1] = 0x00 + ha->port_no + 1;
7549 nv->port_name[2] = 0x00;
7550 nv->port_name[3] = 0xe0;
7551 nv->port_name[4] = 0x8b;
7552 nv->port_name[5] = 0x1c;
7553 nv->port_name[6] = 0x55;
7554 nv->port_name[7] = 0x86;
7555 nv->node_name[0] = 0x20;
7556 nv->node_name[1] = 0x00;
7557 nv->node_name[2] = 0x00;
7558 nv->node_name[3] = 0xe0;
7559 nv->node_name[4] = 0x8b;
7560 nv->node_name[5] = 0x1c;
7561 nv->node_name[6] = 0x55;
7562 nv->node_name[7] = 0x86;
7563 qla24xx_nvram_wwn_from_ofw(vha, nv);
7564 nv->login_retry_count = cpu_to_le16(8);
7565 nv->interrupt_delay_timer = cpu_to_le16(0);
7566 nv->login_timeout = cpu_to_le16(0);
7567 nv->firmware_options_1 =
7568 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7569 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7570 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7571 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7572 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7573 nv->efi_parameters = cpu_to_le32(0);
7574 nv->reset_delay = 5;
7575 nv->max_luns_per_target = cpu_to_le16(128);
7576 nv->port_down_retry_count = cpu_to_le16(30);
7577 nv->link_down_timeout = cpu_to_le16(30);
7582 if (qla_tgt_mode_enabled(vha)) {
7583 /* Don't enable full login after initial LIP */
7584 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7585 /* Don't enable LIP full login for initiator */
7586 nv->host_p &= cpu_to_le32(~BIT_10);
7589 qlt_24xx_config_nvram_stage1(vha, nv);
7591 /* Reset Initialization control block */
7592 memset(icb, 0, ha->init_cb_size);
7594 /* Copy 1st segment. */
7595 dptr1 = (uint8_t *)icb;
7596 dptr2 = (uint8_t *)&nv->version;
7597 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7599 *dptr1++ = *dptr2++;
7601 icb->login_retry_count = nv->login_retry_count;
7602 icb->link_down_on_nos = nv->link_down_on_nos;
7604 /* Copy 2nd segment. */
7605 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7606 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7607 cnt = (uint8_t *)&icb->reserved_3 -
7608 (uint8_t *)&icb->interrupt_delay_timer;
7610 *dptr1++ = *dptr2++;
7611 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
7613 * Setup driver NVRAM options.
7615 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7618 qlt_24xx_config_nvram_stage2(vha, icb);
7620 if (nv->host_p & cpu_to_le32(BIT_15)) {
7621 /* Use alternate WWN? */
7622 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7623 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7626 /* Prepare nodename */
7627 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7629 * Firmware will apply the following mask if the nodename was
7632 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7633 icb->node_name[0] &= 0xF0;
7636 /* Set host adapter parameters. */
7637 ha->flags.disable_risc_code_load = 0;
7638 ha->flags.enable_lip_reset = 0;
7639 ha->flags.enable_lip_full_login =
7640 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
7641 ha->flags.enable_target_reset =
7642 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
7643 ha->flags.enable_led_scheme = 0;
7644 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
7646 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7647 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7649 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
7650 sizeof(ha->fw_seriallink_options24));
7652 /* save HBA serial number */
7653 ha->serial0 = icb->port_name[5];
7654 ha->serial1 = icb->port_name[6];
7655 ha->serial2 = icb->port_name[7];
7656 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7657 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7659 icb->execution_throttle = cpu_to_le16(0xFFFF);
7661 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7663 /* Set minimum login_timeout to 4 seconds. */
7664 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7665 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7666 if (le16_to_cpu(nv->login_timeout) < 4)
7667 nv->login_timeout = cpu_to_le16(4);
7668 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7670 /* Set minimum RATOV to 100 tenths of a second. */
7673 ha->loop_reset_delay = nv->reset_delay;
7675 /* Link Down Timeout = 0:
7677 * When Port Down timer expires we will start returning
7678 * I/O's to OS with "DID_NO_CONNECT".
7680 * Link Down Timeout != 0:
7682 * The driver waits for the link to come up after link down
7683 * before returning I/Os to OS with "DID_NO_CONNECT".
7685 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7686 ha->loop_down_abort_time =
7687 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7689 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7690 ha->loop_down_abort_time =
7691 (LOOP_DOWN_TIME - ha->link_down_timeout);
7694 /* Need enough time to try and get the port back. */
7695 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7696 if (qlport_down_retry)
7697 ha->port_down_retry_count = qlport_down_retry;
7699 /* Set login_retry_count */
7700 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7701 if (ha->port_down_retry_count ==
7702 le16_to_cpu(nv->port_down_retry_count) &&
7703 ha->port_down_retry_count > 3)
7704 ha->login_retry_count = ha->port_down_retry_count;
7705 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7706 ha->login_retry_count = ha->port_down_retry_count;
7707 if (ql2xloginretrycount)
7708 ha->login_retry_count = ql2xloginretrycount;
7710 /* N2N: driver will initiate Login instead of FW */
7711 icb->firmware_options_3 |= cpu_to_le32(BIT_8);
7714 if (!vha->flags.init_done) {
7715 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7716 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7717 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7718 le16_to_cpu(icb->interrupt_delay_timer) : 2;
7720 icb->firmware_options_2 &= cpu_to_le32(
7721 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7722 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7723 ha->zio_mode = QLA_ZIO_MODE_6;
7725 ql_log(ql_log_info, vha, 0x006f,
7726 "ZIO mode %d enabled; timer delay (%d us).\n",
7727 ha->zio_mode, ha->zio_timer * 100);
7729 icb->firmware_options_2 |= cpu_to_le32(
7730 (uint32_t)ha->zio_mode);
7731 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7735 ql_log(ql_log_warn, vha, 0x0070,
7736 "NVRAM configuration failed.\n");
7742 qla27xx_print_image(struct scsi_qla_host *vha, char *name,
7743 struct qla27xx_image_status *image_status)
7745 ql_dbg(ql_dbg_init, vha, 0x018b,
7746 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
7748 image_status->image_status_mask,
7749 le16_to_cpu(image_status->generation),
7750 image_status->ver_major,
7751 image_status->ver_minor,
7752 image_status->bitmap,
7753 le32_to_cpu(image_status->checksum),
7754 le32_to_cpu(image_status->signature));
7758 qla28xx_check_aux_image_status_signature(
7759 struct qla27xx_image_status *image_status)
7761 ulong signature = le32_to_cpu(image_status->signature);
7763 return signature != QLA28XX_AUX_IMG_STATUS_SIGN;
7767 qla27xx_check_image_status_signature(struct qla27xx_image_status *image_status)
7769 ulong signature = le32_to_cpu(image_status->signature);
7772 signature != QLA27XX_IMG_STATUS_SIGN &&
7773 signature != QLA28XX_IMG_STATUS_SIGN;
7777 qla27xx_image_status_checksum(struct qla27xx_image_status *image_status)
7779 __le32 *p = (__force __le32 *)image_status;
7780 uint n = sizeof(*image_status) / sizeof(*p);
7784 sum += le32_to_cpup(p);
7790 qla28xx_component_bitmask(struct qla27xx_image_status *aux, uint bitmask)
7792 return aux->bitmap & bitmask ?
7793 QLA27XX_SECONDARY_IMAGE : QLA27XX_PRIMARY_IMAGE;
7797 qla28xx_component_status(
7798 struct active_regions *active_regions, struct qla27xx_image_status *aux)
7800 active_regions->aux.board_config =
7801 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_BOARD_CONFIG);
7803 active_regions->aux.vpd_nvram =
7804 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_VPD_NVRAM);
7806 active_regions->aux.npiv_config_0_1 =
7807 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1);
7809 active_regions->aux.npiv_config_2_3 =
7810 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3);
7814 qla27xx_compare_image_generation(
7815 struct qla27xx_image_status *pri_image_status,
7816 struct qla27xx_image_status *sec_image_status)
7818 /* calculate generation delta as uint16 (this accounts for wrap) */
7820 le16_to_cpu(pri_image_status->generation) -
7821 le16_to_cpu(sec_image_status->generation);
7823 ql_dbg(ql_dbg_init, NULL, 0x0180, "generation delta = %d\n", delta);
7829 qla28xx_get_aux_images(
7830 struct scsi_qla_host *vha, struct active_regions *active_regions)
7832 struct qla_hw_data *ha = vha->hw;
7833 struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
7834 bool valid_pri_image = false, valid_sec_image = false;
7835 bool active_pri_image = false, active_sec_image = false;
7837 if (!ha->flt_region_aux_img_status_pri) {
7838 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
7839 goto check_sec_image;
7842 qla24xx_read_flash_data(vha, (uint32_t *)&pri_aux_image_status,
7843 ha->flt_region_aux_img_status_pri,
7844 sizeof(pri_aux_image_status) >> 2);
7845 qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
7847 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
7848 ql_dbg(ql_dbg_init, vha, 0x018b,
7849 "Primary aux image signature (%#x) not valid\n",
7850 le32_to_cpu(pri_aux_image_status.signature));
7851 goto check_sec_image;
7854 if (qla27xx_image_status_checksum(&pri_aux_image_status)) {
7855 ql_dbg(ql_dbg_init, vha, 0x018c,
7856 "Primary aux image checksum failed\n");
7857 goto check_sec_image;
7860 valid_pri_image = true;
7862 if (pri_aux_image_status.image_status_mask & 1) {
7863 ql_dbg(ql_dbg_init, vha, 0x018d,
7864 "Primary aux image is active\n");
7865 active_pri_image = true;
7869 if (!ha->flt_region_aux_img_status_sec) {
7870 ql_dbg(ql_dbg_init, vha, 0x018a,
7871 "Secondary aux image not addressed\n");
7872 goto check_valid_image;
7875 qla24xx_read_flash_data(vha, (uint32_t *)&sec_aux_image_status,
7876 ha->flt_region_aux_img_status_sec,
7877 sizeof(sec_aux_image_status) >> 2);
7878 qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
7880 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
7881 ql_dbg(ql_dbg_init, vha, 0x018b,
7882 "Secondary aux image signature (%#x) not valid\n",
7883 le32_to_cpu(sec_aux_image_status.signature));
7884 goto check_valid_image;
7887 if (qla27xx_image_status_checksum(&sec_aux_image_status)) {
7888 ql_dbg(ql_dbg_init, vha, 0x018c,
7889 "Secondary aux image checksum failed\n");
7890 goto check_valid_image;
7893 valid_sec_image = true;
7895 if (sec_aux_image_status.image_status_mask & 1) {
7896 ql_dbg(ql_dbg_init, vha, 0x018d,
7897 "Secondary aux image is active\n");
7898 active_sec_image = true;
7902 if (valid_pri_image && active_pri_image &&
7903 valid_sec_image && active_sec_image) {
7904 if (qla27xx_compare_image_generation(&pri_aux_image_status,
7905 &sec_aux_image_status) >= 0) {
7906 qla28xx_component_status(active_regions,
7907 &pri_aux_image_status);
7909 qla28xx_component_status(active_regions,
7910 &sec_aux_image_status);
7912 } else if (valid_pri_image && active_pri_image) {
7913 qla28xx_component_status(active_regions, &pri_aux_image_status);
7914 } else if (valid_sec_image && active_sec_image) {
7915 qla28xx_component_status(active_regions, &sec_aux_image_status);
7918 ql_dbg(ql_dbg_init, vha, 0x018f,
7919 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u\n",
7920 active_regions->aux.board_config,
7921 active_regions->aux.vpd_nvram,
7922 active_regions->aux.npiv_config_0_1,
7923 active_regions->aux.npiv_config_2_3);
7927 qla27xx_get_active_image(struct scsi_qla_host *vha,
7928 struct active_regions *active_regions)
7930 struct qla_hw_data *ha = vha->hw;
7931 struct qla27xx_image_status pri_image_status, sec_image_status;
7932 bool valid_pri_image = false, valid_sec_image = false;
7933 bool active_pri_image = false, active_sec_image = false;
7935 if (!ha->flt_region_img_status_pri) {
7936 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
7937 goto check_sec_image;
7940 if (qla24xx_read_flash_data(vha, (uint32_t *)&pri_image_status,
7941 ha->flt_region_img_status_pri, sizeof(pri_image_status) >> 2) !=
7944 goto check_sec_image;
7946 qla27xx_print_image(vha, "Primary image", &pri_image_status);
7948 if (qla27xx_check_image_status_signature(&pri_image_status)) {
7949 ql_dbg(ql_dbg_init, vha, 0x018b,
7950 "Primary image signature (%#x) not valid\n",
7951 le32_to_cpu(pri_image_status.signature));
7952 goto check_sec_image;
7955 if (qla27xx_image_status_checksum(&pri_image_status)) {
7956 ql_dbg(ql_dbg_init, vha, 0x018c,
7957 "Primary image checksum failed\n");
7958 goto check_sec_image;
7961 valid_pri_image = true;
7963 if (pri_image_status.image_status_mask & 1) {
7964 ql_dbg(ql_dbg_init, vha, 0x018d,
7965 "Primary image is active\n");
7966 active_pri_image = true;
7970 if (!ha->flt_region_img_status_sec) {
7971 ql_dbg(ql_dbg_init, vha, 0x018a, "Secondary image not addressed\n");
7972 goto check_valid_image;
7975 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
7976 ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
7977 qla27xx_print_image(vha, "Secondary image", &sec_image_status);
7979 if (qla27xx_check_image_status_signature(&sec_image_status)) {
7980 ql_dbg(ql_dbg_init, vha, 0x018b,
7981 "Secondary image signature (%#x) not valid\n",
7982 le32_to_cpu(sec_image_status.signature));
7983 goto check_valid_image;
7986 if (qla27xx_image_status_checksum(&sec_image_status)) {
7987 ql_dbg(ql_dbg_init, vha, 0x018c,
7988 "Secondary image checksum failed\n");
7989 goto check_valid_image;
7992 valid_sec_image = true;
7994 if (sec_image_status.image_status_mask & 1) {
7995 ql_dbg(ql_dbg_init, vha, 0x018d,
7996 "Secondary image is active\n");
7997 active_sec_image = true;
8001 if (valid_pri_image && active_pri_image)
8002 active_regions->global = QLA27XX_PRIMARY_IMAGE;
8004 if (valid_sec_image && active_sec_image) {
8005 if (!active_regions->global ||
8006 qla27xx_compare_image_generation(
8007 &pri_image_status, &sec_image_status) < 0) {
8008 active_regions->global = QLA27XX_SECONDARY_IMAGE;
8012 ql_dbg(ql_dbg_init, vha, 0x018f, "active image %s (%u)\n",
8013 active_regions->global == QLA27XX_DEFAULT_IMAGE ?
8014 "default (boot/fw)" :
8015 active_regions->global == QLA27XX_PRIMARY_IMAGE ?
8017 active_regions->global == QLA27XX_SECONDARY_IMAGE ?
8018 "secondary" : "invalid",
8019 active_regions->global);
8022 bool qla24xx_risc_firmware_invalid(uint32_t *dword)
8025 !(dword[4] | dword[5] | dword[6] | dword[7]) ||
8026 !(~dword[4] | ~dword[5] | ~dword[6] | ~dword[7]);
8030 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
8034 uint templates, segments, fragment;
8039 uint32_t risc_addr, risc_size, risc_attr = 0;
8040 struct qla_hw_data *ha = vha->hw;
8041 struct req_que *req = ha->req_q_map[0];
8042 struct fwdt *fwdt = ha->fwdt;
8044 ql_dbg(ql_dbg_init, vha, 0x008b,
8045 "FW: Loading firmware from flash (%x).\n", faddr);
8047 dcode = (uint32_t *)req->ring;
8048 qla24xx_read_flash_data(vha, dcode, faddr, 8);
8049 if (qla24xx_risc_firmware_invalid(dcode)) {
8050 ql_log(ql_log_fatal, vha, 0x008c,
8051 "Unable to verify the integrity of flash firmware "
8053 ql_log(ql_log_fatal, vha, 0x008d,
8054 "Firmware data: %08x %08x %08x %08x.\n",
8055 dcode[0], dcode[1], dcode[2], dcode[3]);
8057 return QLA_FUNCTION_FAILED;
8060 dcode = (uint32_t *)req->ring;
8062 segments = FA_RISC_CODE_SEGMENTS;
8063 for (j = 0; j < segments; j++) {
8064 ql_dbg(ql_dbg_init, vha, 0x008d,
8065 "-> Loading segment %u...\n", j);
8066 qla24xx_read_flash_data(vha, dcode, faddr, 10);
8067 risc_addr = be32_to_cpu((__force __be32)dcode[2]);
8068 risc_size = be32_to_cpu((__force __be32)dcode[3]);
8070 *srisc_addr = risc_addr;
8071 risc_attr = be32_to_cpu((__force __be32)dcode[9]);
8074 dlen = ha->fw_transfer_size >> 2;
8075 for (fragment = 0; risc_size; fragment++) {
8076 if (dlen > risc_size)
8079 ql_dbg(ql_dbg_init, vha, 0x008e,
8080 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
8081 fragment, risc_addr, faddr, dlen);
8082 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
8083 for (i = 0; i < dlen; i++)
8084 dcode[i] = swab32(dcode[i]);
8086 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
8088 ql_log(ql_log_fatal, vha, 0x008f,
8089 "-> Failed load firmware fragment %u.\n",
8091 return QLA_FUNCTION_FAILED;
8100 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8103 templates = (risc_attr & BIT_9) ? 2 : 1;
8104 ql_dbg(ql_dbg_init, vha, 0x0160, "-> templates = %u\n", templates);
8105 for (j = 0; j < templates; j++, fwdt++) {
8106 vfree(fwdt->template);
8107 fwdt->template = NULL;
8110 dcode = (uint32_t *)req->ring;
8111 qla24xx_read_flash_data(vha, dcode, faddr, 7);
8112 risc_size = be32_to_cpu((__force __be32)dcode[2]);
8113 ql_dbg(ql_dbg_init, vha, 0x0161,
8114 "-> fwdt%u template array at %#x (%#x dwords)\n",
8115 j, faddr, risc_size);
8116 if (!risc_size || !~risc_size) {
8117 ql_dbg(ql_dbg_init, vha, 0x0162,
8118 "-> fwdt%u failed to read array\n", j);
8122 /* skip header and ignore checksum */
8126 ql_dbg(ql_dbg_init, vha, 0x0163,
8127 "-> fwdt%u template allocate template %#x words...\n",
8129 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
8130 if (!fwdt->template) {
8131 ql_log(ql_log_warn, vha, 0x0164,
8132 "-> fwdt%u failed allocate template.\n", j);
8136 dcode = fwdt->template;
8137 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
8139 if (!qla27xx_fwdt_template_valid(dcode)) {
8140 ql_log(ql_log_warn, vha, 0x0165,
8141 "-> fwdt%u failed template validate\n", j);
8145 dlen = qla27xx_fwdt_template_size(dcode);
8146 ql_dbg(ql_dbg_init, vha, 0x0166,
8147 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8148 j, dlen, dlen / sizeof(*dcode));
8149 if (dlen > risc_size * sizeof(*dcode)) {
8150 ql_log(ql_log_warn, vha, 0x0167,
8151 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8152 j, dlen - risc_size * sizeof(*dcode));
8156 fwdt->length = dlen;
8157 ql_dbg(ql_dbg_init, vha, 0x0168,
8158 "-> fwdt%u loaded template ok\n", j);
8160 faddr += risc_size + 1;
8166 vfree(fwdt->template);
8167 fwdt->template = NULL;
8173 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
8176 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8182 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
8183 struct fw_blob *blob;
8184 struct qla_hw_data *ha = vha->hw;
8185 struct req_que *req = ha->req_q_map[0];
8187 /* Load firmware blob. */
8188 blob = qla2x00_request_firmware(vha);
8190 ql_log(ql_log_info, vha, 0x0083,
8191 "Firmware image unavailable.\n");
8192 ql_log(ql_log_info, vha, 0x0084,
8193 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
8194 return QLA_FUNCTION_FAILED;
8199 wcode = (uint16_t *)req->ring;
8201 fwcode = (__force __be16 *)blob->fw->data;
8204 /* Validate firmware image by checking version. */
8205 if (blob->fw->size < 8 * sizeof(uint16_t)) {
8206 ql_log(ql_log_fatal, vha, 0x0085,
8207 "Unable to verify integrity of firmware image (%zd).\n",
8209 goto fail_fw_integrity;
8211 for (i = 0; i < 4; i++)
8212 wcode[i] = be16_to_cpu(fwcode[i + 4]);
8213 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
8214 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
8215 wcode[2] == 0 && wcode[3] == 0)) {
8216 ql_log(ql_log_fatal, vha, 0x0086,
8217 "Unable to verify integrity of firmware image.\n");
8218 ql_log(ql_log_fatal, vha, 0x0087,
8219 "Firmware data: %04x %04x %04x %04x.\n",
8220 wcode[0], wcode[1], wcode[2], wcode[3]);
8221 goto fail_fw_integrity;
8225 while (*seg && rval == QLA_SUCCESS) {
8227 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
8228 risc_size = be16_to_cpu(fwcode[3]);
8230 /* Validate firmware image size. */
8231 fwclen += risc_size * sizeof(uint16_t);
8232 if (blob->fw->size < fwclen) {
8233 ql_log(ql_log_fatal, vha, 0x0088,
8234 "Unable to verify integrity of firmware image "
8235 "(%zd).\n", blob->fw->size);
8236 goto fail_fw_integrity;
8240 while (risc_size > 0 && rval == QLA_SUCCESS) {
8241 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
8242 if (wlen > risc_size)
8244 ql_dbg(ql_dbg_init, vha, 0x0089,
8245 "Loading risc segment@ risc addr %x number of "
8246 "words 0x%x.\n", risc_addr, wlen);
8248 for (i = 0; i < wlen; i++)
8249 wcode[i] = swab16((__force u32)fwcode[i]);
8251 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
8254 ql_log(ql_log_fatal, vha, 0x008a,
8255 "Failed to load segment %d of firmware.\n",
8272 return QLA_FUNCTION_FAILED;
8276 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8279 uint templates, segments, fragment;
8282 uint32_t risc_addr, risc_size, risc_attr = 0;
8285 struct fw_blob *blob;
8287 struct qla_hw_data *ha = vha->hw;
8288 struct req_que *req = ha->req_q_map[0];
8289 struct fwdt *fwdt = ha->fwdt;
8291 ql_dbg(ql_dbg_init, vha, 0x0090,
8292 "-> FW: Loading via request-firmware.\n");
8294 blob = qla2x00_request_firmware(vha);
8296 ql_log(ql_log_warn, vha, 0x0092,
8297 "-> Firmware file not found.\n");
8299 return QLA_FUNCTION_FAILED;
8302 fwcode = (__force __be32 *)blob->fw->data;
8303 dcode = (__force uint32_t *)fwcode;
8304 if (qla24xx_risc_firmware_invalid(dcode)) {
8305 ql_log(ql_log_fatal, vha, 0x0093,
8306 "Unable to verify integrity of firmware image (%zd).\n",
8308 ql_log(ql_log_fatal, vha, 0x0095,
8309 "Firmware data: %08x %08x %08x %08x.\n",
8310 dcode[0], dcode[1], dcode[2], dcode[3]);
8311 return QLA_FUNCTION_FAILED;
8314 dcode = (uint32_t *)req->ring;
8316 segments = FA_RISC_CODE_SEGMENTS;
8317 for (j = 0; j < segments; j++) {
8318 ql_dbg(ql_dbg_init, vha, 0x0096,
8319 "-> Loading segment %u...\n", j);
8320 risc_addr = be32_to_cpu(fwcode[2]);
8321 risc_size = be32_to_cpu(fwcode[3]);
8324 *srisc_addr = risc_addr;
8325 risc_attr = be32_to_cpu(fwcode[9]);
8328 dlen = ha->fw_transfer_size >> 2;
8329 for (fragment = 0; risc_size; fragment++) {
8330 if (dlen > risc_size)
8333 ql_dbg(ql_dbg_init, vha, 0x0097,
8334 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
8335 fragment, risc_addr,
8336 (uint32_t)(fwcode - (typeof(fwcode))blob->fw->data),
8339 for (i = 0; i < dlen; i++)
8340 dcode[i] = swab32((__force u32)fwcode[i]);
8342 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
8344 ql_log(ql_log_fatal, vha, 0x0098,
8345 "-> Failed load firmware fragment %u.\n",
8347 return QLA_FUNCTION_FAILED;
8356 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8359 templates = (risc_attr & BIT_9) ? 2 : 1;
8360 ql_dbg(ql_dbg_init, vha, 0x0170, "-> templates = %u\n", templates);
8361 for (j = 0; j < templates; j++, fwdt++) {
8362 vfree(fwdt->template);
8363 fwdt->template = NULL;
8366 risc_size = be32_to_cpu(fwcode[2]);
8367 ql_dbg(ql_dbg_init, vha, 0x0171,
8368 "-> fwdt%u template array at %#x (%#x dwords)\n",
8369 j, (uint32_t)((void *)fwcode - (void *)blob->fw->data),
8371 if (!risc_size || !~risc_size) {
8372 ql_dbg(ql_dbg_init, vha, 0x0172,
8373 "-> fwdt%u failed to read array\n", j);
8377 /* skip header and ignore checksum */
8381 ql_dbg(ql_dbg_init, vha, 0x0173,
8382 "-> fwdt%u template allocate template %#x words...\n",
8384 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
8385 if (!fwdt->template) {
8386 ql_log(ql_log_warn, vha, 0x0174,
8387 "-> fwdt%u failed allocate template.\n", j);
8391 dcode = fwdt->template;
8392 for (i = 0; i < risc_size; i++)
8393 dcode[i] = (__force u32)fwcode[i];
8395 if (!qla27xx_fwdt_template_valid(dcode)) {
8396 ql_log(ql_log_warn, vha, 0x0175,
8397 "-> fwdt%u failed template validate\n", j);
8401 dlen = qla27xx_fwdt_template_size(dcode);
8402 ql_dbg(ql_dbg_init, vha, 0x0176,
8403 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8404 j, dlen, dlen / sizeof(*dcode));
8405 if (dlen > risc_size * sizeof(*dcode)) {
8406 ql_log(ql_log_warn, vha, 0x0177,
8407 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8408 j, dlen - risc_size * sizeof(*dcode));
8412 fwdt->length = dlen;
8413 ql_dbg(ql_dbg_init, vha, 0x0178,
8414 "-> fwdt%u loaded template ok\n", j);
8416 fwcode += risc_size + 1;
8422 vfree(fwdt->template);
8423 fwdt->template = NULL;
8430 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8434 if (ql2xfwloadbin == 1)
8435 return qla81xx_load_risc(vha, srisc_addr);
8439 * 1) Firmware via request-firmware interface (.bin file).
8440 * 2) Firmware residing in flash.
8442 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8443 if (rval == QLA_SUCCESS)
8446 return qla24xx_load_risc_flash(vha, srisc_addr,
8447 vha->hw->flt_region_fw);
8451 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8454 struct qla_hw_data *ha = vha->hw;
8455 struct active_regions active_regions = { };
8457 if (ql2xfwloadbin == 2)
8460 /* FW Load priority:
8461 * 1) Firmware residing in flash.
8462 * 2) Firmware via request-firmware interface (.bin file).
8463 * 3) Golden-Firmware residing in flash -- (limited operation).
8466 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8467 goto try_primary_fw;
8469 qla27xx_get_active_image(vha, &active_regions);
8471 if (active_regions.global != QLA27XX_SECONDARY_IMAGE)
8472 goto try_primary_fw;
8474 ql_dbg(ql_dbg_init, vha, 0x008b,
8475 "Loading secondary firmware image.\n");
8476 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw_sec);
8481 ql_dbg(ql_dbg_init, vha, 0x008b,
8482 "Loading primary firmware image.\n");
8483 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
8488 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8489 if (!rval || !ha->flt_region_gold_fw)
8492 ql_log(ql_log_info, vha, 0x0099,
8493 "Attempting to fallback to golden firmware.\n");
8494 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
8498 ql_log(ql_log_info, vha, 0x009a, "Need firmware flash update.\n");
8499 ha->flags.running_gold_fw = 1;
8504 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
8507 struct qla_hw_data *ha = vha->hw;
8509 if (ha->flags.pci_channel_io_perm_failure)
8511 if (!IS_FWI2_CAPABLE(ha))
8513 if (!ha->fw_major_version)
8515 if (!ha->flags.fw_started)
8518 ret = qla2x00_stop_firmware(vha);
8519 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
8520 ret != QLA_INVALID_COMMAND && retries ; retries--) {
8521 ha->isp_ops->reset_chip(vha);
8522 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
8524 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
8526 ql_log(ql_log_info, vha, 0x8015,
8527 "Attempting retry of stop-firmware command.\n");
8528 ret = qla2x00_stop_firmware(vha);
8532 ha->flags.fw_init_done = 0;
8536 qla24xx_configure_vhba(scsi_qla_host_t *vha)
8538 int rval = QLA_SUCCESS;
8540 uint16_t mb[MAILBOX_REGISTER_COUNT];
8541 struct qla_hw_data *ha = vha->hw;
8542 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
8547 rval = qla2x00_fw_ready(base_vha);
8549 if (rval == QLA_SUCCESS) {
8550 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8551 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8554 vha->flags.management_server_logged_in = 0;
8556 /* Login to SNS first */
8557 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
8559 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
8560 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
8561 ql_dbg(ql_dbg_init, vha, 0x0120,
8562 "Failed SNS login: loop_id=%x, rval2=%d\n",
8565 ql_dbg(ql_dbg_init, vha, 0x0103,
8566 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
8567 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
8568 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
8569 return (QLA_FUNCTION_FAILED);
8572 atomic_set(&vha->loop_down_timer, 0);
8573 atomic_set(&vha->loop_state, LOOP_UP);
8574 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8575 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
8576 rval = qla2x00_loop_resync(base_vha);
8581 /* 84XX Support **************************************************************/
8583 static LIST_HEAD(qla_cs84xx_list);
8584 static DEFINE_MUTEX(qla_cs84xx_mutex);
8586 static struct qla_chip_state_84xx *
8587 qla84xx_get_chip(struct scsi_qla_host *vha)
8589 struct qla_chip_state_84xx *cs84xx;
8590 struct qla_hw_data *ha = vha->hw;
8592 mutex_lock(&qla_cs84xx_mutex);
8594 /* Find any shared 84xx chip. */
8595 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
8596 if (cs84xx->bus == ha->pdev->bus) {
8597 kref_get(&cs84xx->kref);
8602 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
8606 kref_init(&cs84xx->kref);
8607 spin_lock_init(&cs84xx->access_lock);
8608 mutex_init(&cs84xx->fw_update_mutex);
8609 cs84xx->bus = ha->pdev->bus;
8611 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
8613 mutex_unlock(&qla_cs84xx_mutex);
8618 __qla84xx_chip_release(struct kref *kref)
8620 struct qla_chip_state_84xx *cs84xx =
8621 container_of(kref, struct qla_chip_state_84xx, kref);
8623 mutex_lock(&qla_cs84xx_mutex);
8624 list_del(&cs84xx->list);
8625 mutex_unlock(&qla_cs84xx_mutex);
8630 qla84xx_put_chip(struct scsi_qla_host *vha)
8632 struct qla_hw_data *ha = vha->hw;
8635 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
8639 qla84xx_init_chip(scsi_qla_host_t *vha)
8643 struct qla_hw_data *ha = vha->hw;
8645 mutex_lock(&ha->cs84xx->fw_update_mutex);
8647 rval = qla84xx_verify_chip(vha, status);
8649 mutex_unlock(&ha->cs84xx->fw_update_mutex);
8651 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED :
8655 /* 81XX Support **************************************************************/
8658 qla81xx_nvram_config(scsi_qla_host_t *vha)
8661 struct init_cb_81xx *icb;
8662 struct nvram_81xx *nv;
8664 uint8_t *dptr1, *dptr2;
8667 struct qla_hw_data *ha = vha->hw;
8669 struct active_regions active_regions = { };
8672 icb = (struct init_cb_81xx *)ha->init_cb;
8675 /* Determine NVRAM starting address. */
8676 ha->nvram_size = sizeof(*nv);
8677 ha->vpd_size = FA_NVRAM_VPD_SIZE;
8678 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
8679 ha->vpd_size = FA_VPD_SIZE_82XX;
8681 if (IS_QLA28XX(ha) || IS_QLA27XX(ha))
8682 qla28xx_get_aux_images(vha, &active_regions);
8684 /* Get VPD data into cache */
8685 ha->vpd = ha->nvram + VPD_OFFSET;
8687 faddr = ha->flt_region_vpd;
8688 if (IS_QLA28XX(ha)) {
8689 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8690 faddr = ha->flt_region_vpd_sec;
8691 ql_dbg(ql_dbg_init, vha, 0x0110,
8692 "Loading %s nvram image.\n",
8693 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8694 "primary" : "secondary");
8696 ha->isp_ops->read_optrom(vha, ha->vpd, faddr << 2, ha->vpd_size);
8698 /* Get NVRAM data into cache and calculate checksum. */
8699 faddr = ha->flt_region_nvram;
8700 if (IS_QLA28XX(ha)) {
8701 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8702 faddr = ha->flt_region_nvram_sec;
8704 ql_dbg(ql_dbg_init, vha, 0x0110,
8705 "Loading %s nvram image.\n",
8706 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8707 "primary" : "secondary");
8708 ha->isp_ops->read_optrom(vha, ha->nvram, faddr << 2, ha->nvram_size);
8710 dptr = (__force __le32 *)nv;
8711 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
8712 chksum += le32_to_cpu(*dptr);
8714 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
8715 "Contents of NVRAM:\n");
8716 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
8717 nv, ha->nvram_size);
8719 /* Bad NVRAM data, set defaults parameters. */
8720 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
8721 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
8722 /* Reset NVRAM data. */
8723 ql_log(ql_log_info, vha, 0x0073,
8724 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
8725 chksum, nv->id, le16_to_cpu(nv->nvram_version));
8726 ql_dump_buffer(ql_dbg_init, vha, 0x0073, nv, sizeof(*nv));
8727 ql_log(ql_log_info, vha, 0x0074,
8728 "Falling back to functioning (yet invalid -- WWPN) "
8732 * Set default initialization control block.
8734 memset(nv, 0, ha->nvram_size);
8735 nv->nvram_version = cpu_to_le16(ICB_VERSION);
8736 nv->version = cpu_to_le16(ICB_VERSION);
8737 nv->frame_payload_size = cpu_to_le16(2048);
8738 nv->execution_throttle = cpu_to_le16(0xFFFF);
8739 nv->exchange_count = cpu_to_le16(0);
8740 nv->port_name[0] = 0x21;
8741 nv->port_name[1] = 0x00 + ha->port_no + 1;
8742 nv->port_name[2] = 0x00;
8743 nv->port_name[3] = 0xe0;
8744 nv->port_name[4] = 0x8b;
8745 nv->port_name[5] = 0x1c;
8746 nv->port_name[6] = 0x55;
8747 nv->port_name[7] = 0x86;
8748 nv->node_name[0] = 0x20;
8749 nv->node_name[1] = 0x00;
8750 nv->node_name[2] = 0x00;
8751 nv->node_name[3] = 0xe0;
8752 nv->node_name[4] = 0x8b;
8753 nv->node_name[5] = 0x1c;
8754 nv->node_name[6] = 0x55;
8755 nv->node_name[7] = 0x86;
8756 nv->login_retry_count = cpu_to_le16(8);
8757 nv->interrupt_delay_timer = cpu_to_le16(0);
8758 nv->login_timeout = cpu_to_le16(0);
8759 nv->firmware_options_1 =
8760 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
8761 nv->firmware_options_2 = cpu_to_le32(2 << 4);
8762 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
8763 nv->firmware_options_3 = cpu_to_le32(2 << 13);
8764 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
8765 nv->efi_parameters = cpu_to_le32(0);
8766 nv->reset_delay = 5;
8767 nv->max_luns_per_target = cpu_to_le16(128);
8768 nv->port_down_retry_count = cpu_to_le16(30);
8769 nv->link_down_timeout = cpu_to_le16(180);
8770 nv->enode_mac[0] = 0x00;
8771 nv->enode_mac[1] = 0xC0;
8772 nv->enode_mac[2] = 0xDD;
8773 nv->enode_mac[3] = 0x04;
8774 nv->enode_mac[4] = 0x05;
8775 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
8780 if (IS_T10_PI_CAPABLE(ha))
8781 nv->frame_payload_size &= cpu_to_le16(~7);
8783 qlt_81xx_config_nvram_stage1(vha, nv);
8785 /* Reset Initialization control block */
8786 memset(icb, 0, ha->init_cb_size);
8788 /* Copy 1st segment. */
8789 dptr1 = (uint8_t *)icb;
8790 dptr2 = (uint8_t *)&nv->version;
8791 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
8793 *dptr1++ = *dptr2++;
8795 icb->login_retry_count = nv->login_retry_count;
8797 /* Copy 2nd segment. */
8798 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
8799 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
8800 cnt = (uint8_t *)&icb->reserved_5 -
8801 (uint8_t *)&icb->interrupt_delay_timer;
8803 *dptr1++ = *dptr2++;
8805 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
8806 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8807 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
8808 icb->enode_mac[0] = 0x00;
8809 icb->enode_mac[1] = 0xC0;
8810 icb->enode_mac[2] = 0xDD;
8811 icb->enode_mac[3] = 0x04;
8812 icb->enode_mac[4] = 0x05;
8813 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
8816 /* Use extended-initialization control block. */
8817 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
8818 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
8820 * Setup driver NVRAM options.
8822 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
8825 qlt_81xx_config_nvram_stage2(vha, icb);
8827 /* Use alternate WWN? */
8828 if (nv->host_p & cpu_to_le32(BIT_15)) {
8829 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
8830 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
8833 /* Prepare nodename */
8834 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
8836 * Firmware will apply the following mask if the nodename was
8839 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
8840 icb->node_name[0] &= 0xF0;
8843 if (IS_QLA28XX(ha) || IS_QLA27XX(ha)) {
8844 if ((nv->enhanced_features & BIT_7) == 0)
8845 ha->flags.scm_supported_a = 1;
8848 /* Set host adapter parameters. */
8849 ha->flags.disable_risc_code_load = 0;
8850 ha->flags.enable_lip_reset = 0;
8851 ha->flags.enable_lip_full_login =
8852 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
8853 ha->flags.enable_target_reset =
8854 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
8855 ha->flags.enable_led_scheme = 0;
8856 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
8858 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
8859 (BIT_6 | BIT_5 | BIT_4)) >> 4;
8861 /* save HBA serial number */
8862 ha->serial0 = icb->port_name[5];
8863 ha->serial1 = icb->port_name[6];
8864 ha->serial2 = icb->port_name[7];
8865 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
8866 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
8868 icb->execution_throttle = cpu_to_le16(0xFFFF);
8870 ha->retry_count = le16_to_cpu(nv->login_retry_count);
8872 /* Set minimum login_timeout to 4 seconds. */
8873 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
8874 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
8875 if (le16_to_cpu(nv->login_timeout) < 4)
8876 nv->login_timeout = cpu_to_le16(4);
8877 ha->login_timeout = le16_to_cpu(nv->login_timeout);
8879 /* Set minimum RATOV to 100 tenths of a second. */
8882 ha->loop_reset_delay = nv->reset_delay;
8884 /* Link Down Timeout = 0:
8886 * When Port Down timer expires we will start returning
8887 * I/O's to OS with "DID_NO_CONNECT".
8889 * Link Down Timeout != 0:
8891 * The driver waits for the link to come up after link down
8892 * before returning I/Os to OS with "DID_NO_CONNECT".
8894 if (le16_to_cpu(nv->link_down_timeout) == 0) {
8895 ha->loop_down_abort_time =
8896 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
8898 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
8899 ha->loop_down_abort_time =
8900 (LOOP_DOWN_TIME - ha->link_down_timeout);
8903 /* Need enough time to try and get the port back. */
8904 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8905 if (qlport_down_retry)
8906 ha->port_down_retry_count = qlport_down_retry;
8908 /* Set login_retry_count */
8909 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8910 if (ha->port_down_retry_count ==
8911 le16_to_cpu(nv->port_down_retry_count) &&
8912 ha->port_down_retry_count > 3)
8913 ha->login_retry_count = ha->port_down_retry_count;
8914 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8915 ha->login_retry_count = ha->port_down_retry_count;
8916 if (ql2xloginretrycount)
8917 ha->login_retry_count = ql2xloginretrycount;
8919 /* if not running MSI-X we need handshaking on interrupts */
8920 if (!vha->hw->flags.msix_enabled &&
8921 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)))
8922 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
8925 if (!vha->flags.init_done) {
8926 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8927 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8928 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8929 le16_to_cpu(icb->interrupt_delay_timer) : 2;
8931 icb->firmware_options_2 &= cpu_to_le32(
8932 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8933 vha->flags.process_response_queue = 0;
8934 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8935 ha->zio_mode = QLA_ZIO_MODE_6;
8937 ql_log(ql_log_info, vha, 0x0075,
8938 "ZIO mode %d enabled; timer delay (%d us).\n",
8940 ha->zio_timer * 100);
8942 icb->firmware_options_2 |= cpu_to_le32(
8943 (uint32_t)ha->zio_mode);
8944 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8945 vha->flags.process_response_queue = 1;
8948 /* enable RIDA Format2 */
8949 icb->firmware_options_3 |= cpu_to_le32(BIT_0);
8951 /* N2N: driver will initiate Login instead of FW */
8952 icb->firmware_options_3 |= cpu_to_le32(BIT_8);
8954 /* Determine NVMe/FCP priority for target ports */
8955 ha->fc4_type_priority = qla2xxx_get_fc4_priority(vha);
8958 ql_log(ql_log_warn, vha, 0x0076,
8959 "NVRAM configuration failed.\n");
8965 qla82xx_restart_isp(scsi_qla_host_t *vha)
8968 struct qla_hw_data *ha = vha->hw;
8969 struct scsi_qla_host *vp, *tvp;
8970 unsigned long flags;
8972 status = qla2x00_init_rings(vha);
8974 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8975 ha->flags.chip_reset_done = 1;
8977 status = qla2x00_fw_ready(vha);
8979 /* Issue a marker after FW becomes ready. */
8980 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8981 vha->flags.online = 1;
8982 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8985 /* if no cable then assume it's good */
8986 if ((vha->device_flags & DFLG_NO_CABLE))
8991 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8993 if (!atomic_read(&vha->loop_down_timer)) {
8995 * Issue marker command only when we are going
8996 * to start the I/O .
8998 vha->marker_needed = 1;
9001 ha->isp_ops->enable_intrs(ha);
9003 ha->isp_abort_cnt = 0;
9004 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
9006 /* Update the firmware version */
9007 status = qla82xx_check_md_needed(vha);
9010 ha->flags.fce_enabled = 1;
9012 fce_calc_size(ha->fce_bufs));
9013 rval = qla2x00_enable_fce_trace(vha,
9014 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
9017 ql_log(ql_log_warn, vha, 0x8001,
9018 "Unable to reinitialize FCE (%d).\n",
9020 ha->flags.fce_enabled = 0;
9025 memset(ha->eft, 0, EFT_SIZE);
9026 rval = qla2x00_enable_eft_trace(vha,
9027 ha->eft_dma, EFT_NUM_BUFFERS);
9029 ql_log(ql_log_warn, vha, 0x8010,
9030 "Unable to reinitialize EFT (%d).\n",
9037 ql_dbg(ql_dbg_taskm, vha, 0x8011,
9038 "qla82xx_restart_isp succeeded.\n");
9040 spin_lock_irqsave(&ha->vport_slock, flags);
9041 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
9043 atomic_inc(&vp->vref_count);
9044 spin_unlock_irqrestore(&ha->vport_slock, flags);
9046 qla2x00_vp_abort_isp(vp);
9048 spin_lock_irqsave(&ha->vport_slock, flags);
9049 atomic_dec(&vp->vref_count);
9052 spin_unlock_irqrestore(&ha->vport_slock, flags);
9055 ql_log(ql_log_warn, vha, 0x8016,
9056 "qla82xx_restart_isp **** FAILED ****.\n");
9063 * qla24xx_get_fcp_prio
9064 * Gets the fcp cmd priority value for the logged in port.
9065 * Looks for a match of the port descriptors within
9066 * each of the fcp prio config entries. If a match is found,
9067 * the tag (priority) value is returned.
9070 * vha = scsi host structure pointer.
9071 * fcport = port structure pointer.
9074 * non-zero (if found)
9081 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
9084 uint8_t pid_match, wwn_match;
9086 uint32_t pid1, pid2;
9087 uint64_t wwn1, wwn2;
9088 struct qla_fcp_prio_entry *pri_entry;
9089 struct qla_hw_data *ha = vha->hw;
9091 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
9095 entries = ha->fcp_prio_cfg->num_entries;
9096 pri_entry = &ha->fcp_prio_cfg->entry[0];
9098 for (i = 0; i < entries; i++) {
9099 pid_match = wwn_match = 0;
9101 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
9106 /* check source pid for a match */
9107 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
9108 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
9109 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
9110 if (pid1 == INVALID_PORT_ID)
9112 else if (pid1 == pid2)
9116 /* check destination pid for a match */
9117 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
9118 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
9119 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
9120 if (pid1 == INVALID_PORT_ID)
9122 else if (pid1 == pid2)
9126 /* check source WWN for a match */
9127 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
9128 wwn1 = wwn_to_u64(vha->port_name);
9129 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
9130 if (wwn2 == (uint64_t)-1)
9132 else if (wwn1 == wwn2)
9136 /* check destination WWN for a match */
9137 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
9138 wwn1 = wwn_to_u64(fcport->port_name);
9139 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
9140 if (wwn2 == (uint64_t)-1)
9142 else if (wwn1 == wwn2)
9146 if (pid_match == 2 || wwn_match == 2) {
9147 /* Found a matching entry */
9148 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
9149 priority = pri_entry->tag;
9160 * qla24xx_update_fcport_fcp_prio
9161 * Activates fcp priority for the logged in fc port
9164 * vha = scsi host structure pointer.
9165 * fcp = port structure pointer.
9168 * QLA_SUCCESS or QLA_FUNCTION_FAILED
9174 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
9180 if (fcport->port_type != FCT_TARGET ||
9181 fcport->loop_id == FC_NO_LOOP_ID)
9182 return QLA_FUNCTION_FAILED;
9184 priority = qla24xx_get_fcp_prio(vha, fcport);
9186 return QLA_FUNCTION_FAILED;
9188 if (IS_P3P_TYPE(vha->hw)) {
9189 fcport->fcp_prio = priority & 0xf;
9193 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
9194 if (ret == QLA_SUCCESS) {
9195 if (fcport->fcp_prio != priority)
9196 ql_dbg(ql_dbg_user, vha, 0x709e,
9197 "Updated FCP_CMND priority - value=%d loop_id=%d "
9198 "port_id=%02x%02x%02x.\n", priority,
9199 fcport->loop_id, fcport->d_id.b.domain,
9200 fcport->d_id.b.area, fcport->d_id.b.al_pa);
9201 fcport->fcp_prio = priority & 0xf;
9203 ql_dbg(ql_dbg_user, vha, 0x704f,
9204 "Unable to update FCP_CMND priority - ret=0x%x for "
9205 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
9206 fcport->d_id.b.domain, fcport->d_id.b.area,
9207 fcport->d_id.b.al_pa);
9212 * qla24xx_update_all_fcp_prio
9213 * Activates fcp priority for all the logged in ports
9216 * ha = adapter block pointer.
9219 * QLA_SUCCESS or QLA_FUNCTION_FAILED
9225 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
9230 ret = QLA_FUNCTION_FAILED;
9231 /* We need to set priority for all logged in ports */
9232 list_for_each_entry(fcport, &vha->vp_fcports, list)
9233 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
9238 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
9239 int vp_idx, bool startqp)
9244 struct qla_hw_data *ha = vha->hw;
9245 uint16_t qpair_id = 0;
9246 struct qla_qpair *qpair = NULL;
9247 struct qla_msix_entry *msix;
9249 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
9250 ql_log(ql_log_warn, vha, 0x00181,
9251 "FW/Driver is not multi-queue capable.\n");
9255 if (ql2xmqsupport || ql2xnvmeenable) {
9256 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
9257 if (qpair == NULL) {
9258 ql_log(ql_log_warn, vha, 0x0182,
9259 "Failed to allocate memory for queue pair.\n");
9263 qpair->hw = vha->hw;
9265 qpair->qp_lock_ptr = &qpair->qp_lock;
9266 spin_lock_init(&qpair->qp_lock);
9267 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
9269 /* Assign available que pair id */
9270 mutex_lock(&ha->mq_lock);
9271 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
9272 if (ha->num_qpairs >= ha->max_qpairs) {
9273 mutex_unlock(&ha->mq_lock);
9274 ql_log(ql_log_warn, vha, 0x0183,
9275 "No resources to create additional q pair.\n");
9279 set_bit(qpair_id, ha->qpair_qid_map);
9280 ha->queue_pair_map[qpair_id] = qpair;
9281 qpair->id = qpair_id;
9282 qpair->vp_idx = vp_idx;
9283 qpair->fw_started = ha->flags.fw_started;
9284 INIT_LIST_HEAD(&qpair->hints_list);
9285 qpair->chip_reset = ha->base_qpair->chip_reset;
9286 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
9287 qpair->enable_explicit_conf =
9288 ha->base_qpair->enable_explicit_conf;
9290 for (i = 0; i < ha->msix_count; i++) {
9291 msix = &ha->msix_entries[i];
9295 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
9296 "Vector %x selected for qpair\n", msix->vector);
9300 ql_log(ql_log_warn, vha, 0x0184,
9301 "Out of MSI-X vectors!.\n");
9305 qpair->msix->in_use = 1;
9306 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
9307 qpair->pdev = ha->pdev;
9308 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
9309 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
9311 mutex_unlock(&ha->mq_lock);
9313 /* Create response queue first */
9314 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
9316 ql_log(ql_log_warn, vha, 0x0185,
9317 "Failed to create response queue.\n");
9321 qpair->rsp = ha->rsp_q_map[rsp_id];
9323 /* Create request queue */
9324 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
9327 ql_log(ql_log_warn, vha, 0x0186,
9328 "Failed to create request queue.\n");
9332 qpair->req = ha->req_q_map[req_id];
9333 qpair->rsp->req = qpair->req;
9334 qpair->rsp->qpair = qpair;
9335 /* init qpair to this cpu. Will adjust at run time. */
9336 qla_cpu_update(qpair, smp_processor_id());
9338 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
9339 if (ha->fw_attributes & BIT_4)
9340 qpair->difdix_supported = 1;
9343 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
9344 if (!qpair->srb_mempool) {
9345 ql_log(ql_log_warn, vha, 0xd036,
9346 "Failed to create srb mempool for qpair %d\n",
9351 /* Mark as online */
9354 if (!vha->flags.qpairs_available)
9355 vha->flags.qpairs_available = 1;
9357 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
9358 "Request/Response queue pair created, id %d\n",
9360 ql_dbg(ql_dbg_init, vha, 0x0187,
9361 "Request/Response queue pair created, id %d\n",
9368 qla25xx_delete_rsp_que(vha, qpair->rsp);
9370 mutex_lock(&ha->mq_lock);
9371 qpair->msix->in_use = 0;
9372 list_del(&qpair->qp_list_elem);
9373 if (list_empty(&vha->qp_list))
9374 vha->flags.qpairs_available = 0;
9376 ha->queue_pair_map[qpair_id] = NULL;
9377 clear_bit(qpair_id, ha->qpair_qid_map);
9379 mutex_unlock(&ha->mq_lock);
9385 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
9387 int ret = QLA_FUNCTION_FAILED;
9388 struct qla_hw_data *ha = qpair->hw;
9390 qpair->delete_in_progress = 1;
9392 ret = qla25xx_delete_req_que(vha, qpair->req);
9393 if (ret != QLA_SUCCESS)
9396 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
9397 if (ret != QLA_SUCCESS)
9400 mutex_lock(&ha->mq_lock);
9401 ha->queue_pair_map[qpair->id] = NULL;
9402 clear_bit(qpair->id, ha->qpair_qid_map);
9404 list_del(&qpair->qp_list_elem);
9405 if (list_empty(&vha->qp_list)) {
9406 vha->flags.qpairs_available = 0;
9407 vha->flags.qpairs_req_created = 0;
9408 vha->flags.qpairs_rsp_created = 0;
9410 mempool_destroy(qpair->srb_mempool);
9412 mutex_unlock(&ha->mq_lock);
9420 qla2x00_count_set_bits(uint32_t num)
9422 /* Brian Kernighan's Algorithm */
9433 qla2x00_get_num_tgts(scsi_qla_host_t *vha)
9441 list_for_each_entry_safe(f, tf, &vha->vp_fcports, list) {
9442 if (f->port_type != FCT_TARGET)
9449 int qla2xxx_reset_stats(struct Scsi_Host *host, u32 flags)
9451 scsi_qla_host_t *vha = shost_priv(host);
9452 fc_port_t *fcport = NULL;
9453 unsigned long int_flags;
9455 if (flags & QLA2XX_HW_ERROR)
9456 vha->hw_err_cnt = 0;
9457 if (flags & QLA2XX_SHT_LNK_DWN)
9458 vha->short_link_down_cnt = 0;
9459 if (flags & QLA2XX_INT_ERR)
9460 vha->interface_err_cnt = 0;
9461 if (flags & QLA2XX_CMD_TIMEOUT)
9462 vha->cmd_timeout_cnt = 0;
9463 if (flags & QLA2XX_RESET_CMD_ERR)
9464 vha->reset_cmd_err_cnt = 0;
9465 if (flags & QLA2XX_TGT_SHT_LNK_DOWN) {
9466 spin_lock_irqsave(&vha->hw->tgt.sess_lock, int_flags);
9467 list_for_each_entry(fcport, &vha->vp_fcports, list) {
9468 fcport->tgt_short_link_down_cnt = 0;
9469 fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
9471 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, int_flags);
9473 vha->link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
9477 int qla2xxx_start_stats(struct Scsi_Host *host, u32 flags)
9479 return qla2xxx_reset_stats(host, flags);
9482 int qla2xxx_stop_stats(struct Scsi_Host *host, u32 flags)
9484 return qla2xxx_reset_stats(host, flags);
9487 int qla2xxx_get_ini_stats(struct Scsi_Host *host, u32 flags,
9488 void *data, u64 size)
9490 scsi_qla_host_t *vha = shost_priv(host);
9491 struct ql_vnd_host_stats_resp *resp = (struct ql_vnd_host_stats_resp *)data;
9492 struct ql_vnd_stats *rsp_data = &resp->stats;
9493 u64 ini_entry_count = 0;
9495 u64 entry_count = 0;
9497 u32 tmp_stat_type = 0;
9498 fc_port_t *fcport = NULL;
9499 unsigned long int_flags;
9501 /* Copy stat type to work on it */
9502 tmp_stat_type = flags;
9504 if (tmp_stat_type & BIT_17) {
9505 num_tgt = qla2x00_get_num_tgts(vha);
9507 tmp_stat_type &= ~(1 << 17);
9509 ini_entry_count = qla2x00_count_set_bits(tmp_stat_type);
9511 entry_count = ini_entry_count + num_tgt;
9513 rsp_data->entry_count = entry_count;
9516 if (flags & QLA2XX_HW_ERROR) {
9517 rsp_data->entry[i].stat_type = QLA2XX_HW_ERROR;
9518 rsp_data->entry[i].tgt_num = 0x0;
9519 rsp_data->entry[i].cnt = vha->hw_err_cnt;
9523 if (flags & QLA2XX_SHT_LNK_DWN) {
9524 rsp_data->entry[i].stat_type = QLA2XX_SHT_LNK_DWN;
9525 rsp_data->entry[i].tgt_num = 0x0;
9526 rsp_data->entry[i].cnt = vha->short_link_down_cnt;
9530 if (flags & QLA2XX_INT_ERR) {
9531 rsp_data->entry[i].stat_type = QLA2XX_INT_ERR;
9532 rsp_data->entry[i].tgt_num = 0x0;
9533 rsp_data->entry[i].cnt = vha->interface_err_cnt;
9537 if (flags & QLA2XX_CMD_TIMEOUT) {
9538 rsp_data->entry[i].stat_type = QLA2XX_CMD_TIMEOUT;
9539 rsp_data->entry[i].tgt_num = 0x0;
9540 rsp_data->entry[i].cnt = vha->cmd_timeout_cnt;
9544 if (flags & QLA2XX_RESET_CMD_ERR) {
9545 rsp_data->entry[i].stat_type = QLA2XX_RESET_CMD_ERR;
9546 rsp_data->entry[i].tgt_num = 0x0;
9547 rsp_data->entry[i].cnt = vha->reset_cmd_err_cnt;
9551 /* i will continue from previous loop, as target
9552 * entries are after initiator
9554 if (flags & QLA2XX_TGT_SHT_LNK_DOWN) {
9555 spin_lock_irqsave(&vha->hw->tgt.sess_lock, int_flags);
9556 list_for_each_entry(fcport, &vha->vp_fcports, list) {
9557 if (fcport->port_type != FCT_TARGET)
9561 rsp_data->entry[i].stat_type = QLA2XX_TGT_SHT_LNK_DOWN;
9562 rsp_data->entry[i].tgt_num = fcport->rport->number;
9563 rsp_data->entry[i].cnt = fcport->tgt_short_link_down_cnt;
9566 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, int_flags);
9568 resp->status = EXT_STATUS_OK;
9573 int qla2xxx_get_tgt_stats(struct Scsi_Host *host, u32 flags,
9574 struct fc_rport *rport, void *data, u64 size)
9576 struct ql_vnd_tgt_stats_resp *tgt_data = data;
9577 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
9579 tgt_data->status = 0;
9580 tgt_data->stats.entry_count = 1;
9581 tgt_data->stats.entry[0].stat_type = flags;
9582 tgt_data->stats.entry[0].tgt_num = rport->number;
9583 tgt_data->stats.entry[0].cnt = fcport->tgt_short_link_down_cnt;
9588 int qla2xxx_disable_port(struct Scsi_Host *host)
9590 scsi_qla_host_t *vha = shost_priv(host);
9592 vha->hw->flags.port_isolated = 1;
9594 if (qla2x00_chip_is_down(vha))
9597 if (vha->flags.online) {
9598 qla2x00_abort_isp_cleanup(vha);
9599 qla2x00_wait_for_sess_deletion(vha);
9605 int qla2xxx_enable_port(struct Scsi_Host *host)
9607 scsi_qla_host_t *vha = shost_priv(host);
9609 vha->hw->flags.port_isolated = 0;
9610 /* Set the flag to 1, so that isp_abort can proceed */
9611 vha->flags.online = 1;
9612 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
9613 qla2xxx_wake_dpc(vha);