2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
10 #include <linux/delay.h>
11 #include <linux/slab.h>
12 #include <linux/vmalloc.h>
14 #include "qla_devtbl.h"
20 #include <target/target_core_base.h>
21 #include "qla_target.h"
24 * QLogic ISP2x00 Hardware Support Function Prototypes.
26 static int qla2x00_isp_firmware(scsi_qla_host_t *);
27 static int qla2x00_setup_chip(scsi_qla_host_t *);
28 static int qla2x00_fw_ready(scsi_qla_host_t *);
29 static int qla2x00_configure_hba(scsi_qla_host_t *);
30 static int qla2x00_configure_loop(scsi_qla_host_t *);
31 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
32 static int qla2x00_configure_fabric(scsi_qla_host_t *);
33 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *);
34 static int qla2x00_restart_isp(scsi_qla_host_t *);
36 static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
37 static int qla84xx_init_chip(scsi_qla_host_t *);
38 static int qla25xx_init_queues(struct qla_hw_data *);
39 static int qla24xx_post_prli_work(struct scsi_qla_host*, fc_port_t *);
40 static void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha,
41 struct event_arg *ea);
42 static void qla24xx_handle_prli_done_event(struct scsi_qla_host *,
44 static void __qla24xx_handle_gpdb_event(scsi_qla_host_t *, struct event_arg *);
46 /* SRB Extensions ---------------------------------------------------------- */
49 qla2x00_sp_timeout(struct timer_list *t)
51 srb_t *sp = from_timer(sp, t, u.iocb_cmd.timer);
52 struct srb_iocb *iocb;
54 WARN_ON(irqs_disabled());
55 iocb = &sp->u.iocb_cmd;
59 void qla2x00_sp_free(srb_t *sp)
61 struct srb_iocb *iocb = &sp->u.iocb_cmd;
63 del_timer(&iocb->timer);
67 void qla2xxx_rel_done_warning(srb_t *sp, int res)
69 WARN_ONCE(1, "Calling done() of an already freed srb %p object\n", sp);
72 void qla2xxx_rel_free_warning(srb_t *sp)
74 WARN_ONCE(1, "Calling free() of an already freed srb %p object\n", sp);
77 /* Asynchronous Login/Logout Routines -------------------------------------- */
80 qla2x00_get_async_timeout(struct scsi_qla_host *vha)
83 struct qla_hw_data *ha = vha->hw;
85 /* Firmware should use switch negotiated r_a_tov for timeout. */
86 tmo = ha->r_a_tov / 10 * 2;
88 tmo = FX00_DEF_RATOV * 2;
89 } else if (!IS_FWI2_CAPABLE(ha)) {
91 * Except for earlier ISPs where the timeout is seeded from the
92 * initialization control block.
94 tmo = ha->login_timeout;
99 static void qla24xx_abort_iocb_timeout(void *data)
102 struct srb_iocb *abt = &sp->u.iocb_cmd;
103 struct qla_qpair *qpair = sp->qpair;
108 ql_dbg(ql_dbg_async, sp->vha, 0x507c,
109 "Abort timeout - cmd hdl=%x, cmd type=%x hdl=%x, type=%x\n",
110 sp->cmd_sp->handle, sp->cmd_sp->type,
111 sp->handle, sp->type);
113 ql_dbg(ql_dbg_async, sp->vha, 0x507c,
114 "Abort timeout 2 - hdl=%x, type=%x\n",
115 sp->handle, sp->type);
117 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
118 for (handle = 1; handle < qpair->req->num_outstanding_cmds; handle++) {
119 if (sp->cmd_sp && (qpair->req->outstanding_cmds[handle] ==
121 qpair->req->outstanding_cmds[handle] = NULL;
123 /* removing the abort */
124 if (qpair->req->outstanding_cmds[handle] == sp) {
125 qpair->req->outstanding_cmds[handle] = NULL;
129 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
132 sp->cmd_sp->done(sp->cmd_sp, QLA_OS_TIMER_EXPIRED);
134 abt->u.abt.comp_status = CS_TIMEOUT;
135 sp->done(sp, QLA_OS_TIMER_EXPIRED);
138 static void qla24xx_abort_sp_done(srb_t *sp, int res)
140 struct srb_iocb *abt = &sp->u.iocb_cmd;
142 del_timer(&sp->u.iocb_cmd.timer);
143 if (sp->flags & SRB_WAKEUP_ON_COMP)
144 complete(&abt->u.abt.comp);
149 int qla24xx_async_abort_cmd(srb_t *cmd_sp, bool wait)
151 scsi_qla_host_t *vha = cmd_sp->vha;
152 struct srb_iocb *abt_iocb;
154 int rval = QLA_FUNCTION_FAILED;
156 sp = qla2xxx_get_qpair_sp(cmd_sp->vha, cmd_sp->qpair, cmd_sp->fcport,
161 abt_iocb = &sp->u.iocb_cmd;
162 sp->type = SRB_ABT_CMD;
164 sp->qpair = cmd_sp->qpair;
167 sp->flags = SRB_WAKEUP_ON_COMP;
169 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
170 init_completion(&abt_iocb->u.abt.comp);
171 /* FW can send 2 x ABTS's timeout/20s */
172 qla2x00_init_timer(sp, 42);
174 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
175 abt_iocb->u.abt.req_que_no = cpu_to_le16(cmd_sp->qpair->req->id);
177 sp->done = qla24xx_abort_sp_done;
179 ql_dbg(ql_dbg_async, vha, 0x507c,
180 "Abort command issued - hdl=%x, type=%x\n", cmd_sp->handle,
183 rval = qla2x00_start_sp(sp);
184 if (rval != QLA_SUCCESS) {
190 wait_for_completion(&abt_iocb->u.abt.comp);
191 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
192 QLA_SUCCESS : QLA_FUNCTION_FAILED;
200 qla2x00_async_iocb_timeout(void *data)
203 fc_port_t *fcport = sp->fcport;
204 struct srb_iocb *lio = &sp->u.iocb_cmd;
209 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
210 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
211 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
213 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
215 pr_info("Async-%s timeout - hdl=%x.\n",
216 sp->name, sp->handle);
221 rc = qla24xx_async_abort_cmd(sp, false);
223 /* Retry as needed. */
224 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
225 lio->u.logio.data[1] =
226 lio->u.logio.flags & SRB_LOGIN_RETRIED ?
227 QLA_LOGIO_LOGIN_RETRIED : 0;
228 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
229 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
231 if (sp->qpair->req->outstanding_cmds[h] ==
233 sp->qpair->req->outstanding_cmds[h] =
238 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
239 sp->done(sp, QLA_FUNCTION_TIMEOUT);
243 case SRB_CT_PTHRU_CMD:
250 rc = qla24xx_async_abort_cmd(sp, false);
252 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
253 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
255 if (sp->qpair->req->outstanding_cmds[h] ==
257 sp->qpair->req->outstanding_cmds[h] =
262 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
263 sp->done(sp, QLA_FUNCTION_TIMEOUT);
269 static void qla2x00_async_login_sp_done(srb_t *sp, int res)
271 struct scsi_qla_host *vha = sp->vha;
272 struct srb_iocb *lio = &sp->u.iocb_cmd;
275 ql_dbg(ql_dbg_disc, vha, 0x20dd,
276 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
278 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
280 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
281 memset(&ea, 0, sizeof(ea));
282 ea.fcport = sp->fcport;
283 ea.data[0] = lio->u.logio.data[0];
284 ea.data[1] = lio->u.logio.data[1];
285 ea.iop[0] = lio->u.logio.iop[0];
286 ea.iop[1] = lio->u.logio.iop[1];
288 qla24xx_handle_plogi_done_event(vha, &ea);
295 fcport_is_smaller(fc_port_t *fcport)
297 if (wwn_to_u64(fcport->port_name) <
298 wwn_to_u64(fcport->vha->port_name))
305 fcport_is_bigger(fc_port_t *fcport)
307 return !fcport_is_smaller(fcport);
311 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
315 struct srb_iocb *lio;
316 int rval = QLA_FUNCTION_FAILED;
318 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
319 fcport->loop_id == FC_NO_LOOP_ID) {
320 ql_log(ql_log_warn, vha, 0xffff,
321 "%s: %8phC - not sending command.\n",
322 __func__, fcport->port_name);
326 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
330 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_PEND);
331 fcport->flags |= FCF_ASYNC_SENT;
332 fcport->logout_completed = 0;
334 sp->type = SRB_LOGIN_CMD;
336 sp->gen1 = fcport->rscn_gen;
337 sp->gen2 = fcport->login_gen;
339 lio = &sp->u.iocb_cmd;
340 lio->timeout = qla2x00_async_iocb_timeout;
341 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
343 sp->done = qla2x00_async_login_sp_done;
344 if (N2N_TOPO(fcport->vha->hw) && fcport_is_bigger(fcport))
345 lio->u.logio.flags |= SRB_LOGIN_PRLI_ONLY;
347 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
349 if (NVME_TARGET(vha->hw, fcport))
350 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
352 ql_dbg(ql_dbg_disc, vha, 0x2072,
353 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
354 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
355 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
356 fcport->login_retry);
358 rval = qla2x00_start_sp(sp);
359 if (rval != QLA_SUCCESS) {
360 fcport->flags |= FCF_LOGIN_NEEDED;
361 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
369 fcport->flags &= ~FCF_ASYNC_SENT;
371 fcport->flags &= ~FCF_ASYNC_ACTIVE;
375 static void qla2x00_async_logout_sp_done(srb_t *sp, int res)
377 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
378 sp->fcport->login_gen++;
379 qlt_logo_completion_handler(sp->fcport, res);
384 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
387 struct srb_iocb *lio;
388 int rval = QLA_FUNCTION_FAILED;
390 fcport->flags |= FCF_ASYNC_SENT;
391 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
395 sp->type = SRB_LOGOUT_CMD;
398 lio = &sp->u.iocb_cmd;
399 lio->timeout = qla2x00_async_iocb_timeout;
400 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
402 sp->done = qla2x00_async_logout_sp_done;
404 ql_dbg(ql_dbg_disc, vha, 0x2070,
405 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
406 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
407 fcport->d_id.b.area, fcport->d_id.b.al_pa,
410 rval = qla2x00_start_sp(sp);
411 if (rval != QLA_SUCCESS)
418 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
423 qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
426 fcport->flags &= ~FCF_ASYNC_ACTIVE;
427 /* Don't re-login in target mode */
428 if (!fcport->tgt_session)
429 qla2x00_mark_device_lost(vha, fcport, 1, 0);
430 qlt_logo_completion_handler(fcport, data[0]);
433 static void qla2x00_async_prlo_sp_done(srb_t *sp, int res)
435 struct srb_iocb *lio = &sp->u.iocb_cmd;
436 struct scsi_qla_host *vha = sp->vha;
438 sp->fcport->flags &= ~FCF_ASYNC_ACTIVE;
439 if (!test_bit(UNLOADING, &vha->dpc_flags))
440 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
446 qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
449 struct srb_iocb *lio;
452 rval = QLA_FUNCTION_FAILED;
453 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
457 sp->type = SRB_PRLO_CMD;
460 lio = &sp->u.iocb_cmd;
461 lio->timeout = qla2x00_async_iocb_timeout;
462 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
464 sp->done = qla2x00_async_prlo_sp_done;
466 ql_dbg(ql_dbg_disc, vha, 0x2070,
467 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
468 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
469 fcport->d_id.b.area, fcport->d_id.b.al_pa);
471 rval = qla2x00_start_sp(sp);
472 if (rval != QLA_SUCCESS)
480 fcport->flags &= ~FCF_ASYNC_ACTIVE;
485 void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
487 struct fc_port *fcport = ea->fcport;
489 ql_dbg(ql_dbg_disc, vha, 0x20d2,
490 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
491 __func__, fcport->port_name, fcport->disc_state,
492 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
493 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
495 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
498 if (ea->data[0] != MBS_COMMAND_COMPLETE) {
499 ql_dbg(ql_dbg_disc, vha, 0x2066,
500 "%s %8phC: adisc fail: post delete\n",
501 __func__, ea->fcport->port_name);
502 /* deleted = 0 & logout_on_delete = force fw cleanup */
504 fcport->logout_on_delete = 1;
505 qlt_schedule_sess_for_deletion(ea->fcport);
509 if (ea->fcport->disc_state == DSC_DELETE_PEND)
512 if (ea->sp->gen2 != ea->fcport->login_gen) {
513 /* target side must have changed it. */
514 ql_dbg(ql_dbg_disc, vha, 0x20d3,
515 "%s %8phC generation changed\n",
516 __func__, ea->fcport->port_name);
518 } else if (ea->sp->gen1 != ea->fcport->rscn_gen) {
519 qla_rscn_replay(fcport);
520 qlt_schedule_sess_for_deletion(fcport);
524 __qla24xx_handle_gpdb_event(vha, ea);
527 static int qla_post_els_plogi_work(struct scsi_qla_host *vha, fc_port_t *fcport)
529 struct qla_work_evt *e;
531 e = qla2x00_alloc_work(vha, QLA_EVT_ELS_PLOGI);
533 return QLA_FUNCTION_FAILED;
535 e->u.fcport.fcport = fcport;
536 fcport->flags |= FCF_ASYNC_ACTIVE;
537 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_PEND);
538 return qla2x00_post_work(vha, e);
541 static void qla2x00_async_adisc_sp_done(srb_t *sp, int res)
543 struct scsi_qla_host *vha = sp->vha;
545 struct srb_iocb *lio = &sp->u.iocb_cmd;
547 ql_dbg(ql_dbg_disc, vha, 0x2066,
548 "Async done-%s res %x %8phC\n",
549 sp->name, res, sp->fcport->port_name);
551 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
553 memset(&ea, 0, sizeof(ea));
555 ea.data[0] = lio->u.logio.data[0];
556 ea.data[1] = lio->u.logio.data[1];
557 ea.iop[0] = lio->u.logio.iop[0];
558 ea.iop[1] = lio->u.logio.iop[1];
559 ea.fcport = sp->fcport;
562 qla24xx_handle_adisc_event(vha, &ea);
568 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
572 struct srb_iocb *lio;
573 int rval = QLA_FUNCTION_FAILED;
575 if (IS_SESSION_DELETED(fcport)) {
576 ql_log(ql_log_warn, vha, 0xffff,
577 "%s: %8phC is being delete - not sending command.\n",
578 __func__, fcport->port_name);
579 fcport->flags &= ~FCF_ASYNC_ACTIVE;
583 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
586 fcport->flags |= FCF_ASYNC_SENT;
587 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
591 sp->type = SRB_ADISC_CMD;
594 lio = &sp->u.iocb_cmd;
595 lio->timeout = qla2x00_async_iocb_timeout;
596 sp->gen1 = fcport->rscn_gen;
597 sp->gen2 = fcport->login_gen;
598 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
600 sp->done = qla2x00_async_adisc_sp_done;
601 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
602 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
604 ql_dbg(ql_dbg_disc, vha, 0x206f,
605 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
606 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
608 rval = qla2x00_start_sp(sp);
609 if (rval != QLA_SUCCESS)
617 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
618 qla2x00_post_async_adisc_work(vha, fcport, data);
622 static bool qla2x00_is_reserved_id(scsi_qla_host_t *vha, uint16_t loop_id)
624 struct qla_hw_data *ha = vha->hw;
626 if (IS_FWI2_CAPABLE(ha))
627 return loop_id > NPH_LAST_HANDLE;
629 return (loop_id > ha->max_loop_id && loop_id < SNS_FIRST_LOOP_ID) ||
630 loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST;
634 * qla2x00_find_new_loop_id - scan through our port list and find a new usable loop ID
635 * @vha: adapter state pointer.
636 * @dev: port structure pointer.
639 * qla2x00 local function return status code.
644 static int qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
647 struct qla_hw_data *ha = vha->hw;
648 unsigned long flags = 0;
652 spin_lock_irqsave(&ha->vport_slock, flags);
654 dev->loop_id = find_first_zero_bit(ha->loop_id_map, LOOPID_MAP_SIZE);
655 if (dev->loop_id >= LOOPID_MAP_SIZE ||
656 qla2x00_is_reserved_id(vha, dev->loop_id)) {
657 dev->loop_id = FC_NO_LOOP_ID;
658 rval = QLA_FUNCTION_FAILED;
660 set_bit(dev->loop_id, ha->loop_id_map);
662 spin_unlock_irqrestore(&ha->vport_slock, flags);
664 if (rval == QLA_SUCCESS)
665 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
666 "Assigning new loopid=%x, portid=%x.\n",
667 dev->loop_id, dev->d_id.b24);
669 ql_log(ql_log_warn, dev->vha, 0x2087,
670 "No loop_id's available, portid=%x.\n",
676 void qla2x00_clear_loop_id(fc_port_t *fcport)
678 struct qla_hw_data *ha = fcport->vha->hw;
680 if (fcport->loop_id == FC_NO_LOOP_ID ||
681 qla2x00_is_reserved_id(fcport->vha, fcport->loop_id))
684 clear_bit(fcport->loop_id, ha->loop_id_map);
685 fcport->loop_id = FC_NO_LOOP_ID;
688 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
689 struct event_arg *ea)
691 fc_port_t *fcport, *conflict_fcport;
692 struct get_name_list_extended *e;
693 u16 i, n, found = 0, loop_id;
697 u8 current_login_state, nvme_cls;
700 ql_dbg(ql_dbg_disc, vha, 0xffff,
701 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
702 __func__, fcport->port_name, fcport->disc_state,
703 fcport->fw_login_state, ea->rc,
704 fcport->login_gen, fcport->last_login_gen,
705 fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id);
707 if (fcport->disc_state == DSC_DELETE_PEND)
710 if (ea->rc) { /* rval */
711 if (fcport->login_retry == 0) {
712 ql_dbg(ql_dbg_disc, vha, 0x20de,
713 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
714 fcport->port_name, fcport->login_retry);
719 if (fcport->last_rscn_gen != fcport->rscn_gen) {
720 qla_rscn_replay(fcport);
721 qlt_schedule_sess_for_deletion(fcport);
723 } else if (fcport->last_login_gen != fcport->login_gen) {
724 ql_dbg(ql_dbg_disc, vha, 0x20e0,
725 "%s %8phC login gen changed\n",
726 __func__, fcport->port_name);
730 n = ea->data[0] / sizeof(struct get_name_list_extended);
732 ql_dbg(ql_dbg_disc, vha, 0x20e1,
733 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
734 __func__, __LINE__, fcport->port_name, n,
735 fcport->d_id.b.domain, fcport->d_id.b.area,
736 fcport->d_id.b.al_pa, fcport->loop_id);
738 for (i = 0; i < n; i++) {
740 wwn = wwn_to_u64(e->port_name);
741 id.b.domain = e->port_id[2];
742 id.b.area = e->port_id[1];
743 id.b.al_pa = e->port_id[0];
746 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
749 if (IS_SW_RESV_ADDR(id))
754 loop_id = le16_to_cpu(e->nport_handle);
755 loop_id = (loop_id & 0x7fff);
756 nvme_cls = e->current_login_state >> 4;
757 current_login_state = e->current_login_state & 0xf;
759 if (PRLI_PHASE(nvme_cls)) {
760 current_login_state = nvme_cls;
761 fcport->fc4_type &= ~FS_FC4TYPE_FCP;
762 fcport->fc4_type |= FS_FC4TYPE_NVME;
763 } else if (PRLI_PHASE(current_login_state)) {
764 fcport->fc4_type |= FS_FC4TYPE_FCP;
765 fcport->fc4_type &= ~FS_FC4TYPE_NVME;
768 ql_dbg(ql_dbg_disc, vha, 0x20e2,
769 "%s found %8phC CLS [%x|%x] fc4_type %d ID[%06x|%06x] lid[%d|%d]\n",
770 __func__, fcport->port_name,
771 e->current_login_state, fcport->fw_login_state,
772 fcport->fc4_type, id.b24, fcport->d_id.b24,
773 loop_id, fcport->loop_id);
775 switch (fcport->disc_state) {
776 case DSC_DELETE_PEND:
780 if ((id.b24 != fcport->d_id.b24 &&
782 fcport->loop_id != FC_NO_LOOP_ID) ||
783 (fcport->loop_id != FC_NO_LOOP_ID &&
784 fcport->loop_id != loop_id)) {
785 ql_dbg(ql_dbg_disc, vha, 0x20e3,
786 "%s %d %8phC post del sess\n",
787 __func__, __LINE__, fcport->port_name);
788 if (fcport->n2n_flag)
789 fcport->d_id.b24 = 0;
790 qlt_schedule_sess_for_deletion(fcport);
796 fcport->loop_id = loop_id;
797 if (fcport->n2n_flag)
798 fcport->d_id.b24 = id.b24;
800 wwn = wwn_to_u64(fcport->port_name);
801 qlt_find_sess_invalidate_other(vha, wwn,
802 id, loop_id, &conflict_fcport);
804 if (conflict_fcport) {
806 * Another share fcport share the same loop_id &
807 * nport id. Conflict fcport needs to finish
808 * cleanup before this fcport can proceed to login.
810 conflict_fcport->conflict = fcport;
811 fcport->login_pause = 1;
814 switch (vha->hw->current_topology) {
816 switch (current_login_state) {
817 case DSC_LS_PRLI_COMP:
818 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
819 vha, 0x20e4, "%s %d %8phC post gpdb\n",
820 __func__, __LINE__, fcport->port_name);
822 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
823 fcport->port_type = FCT_INITIATOR;
825 fcport->port_type = FCT_TARGET;
826 data[0] = data[1] = 0;
827 qla2x00_post_async_adisc_work(vha, fcport,
830 case DSC_LS_PORT_UNAVAIL:
832 if (fcport->loop_id == FC_NO_LOOP_ID) {
833 qla2x00_find_new_loop_id(vha, fcport);
834 fcport->fw_login_state =
837 ql_dbg(ql_dbg_disc, vha, 0x20e5,
838 "%s %d %8phC\n", __func__, __LINE__,
840 qla24xx_fcport_handle_login(vha, fcport);
845 fcport->fw_login_state = current_login_state;
847 switch (current_login_state) {
848 case DSC_LS_PRLI_PEND:
850 * In the middle of PRLI. Let it finish.
851 * Allow relogin code to recheck state again
852 * with GNL. Push disc_state back to DELETED
853 * so GNL can go out again
855 qla2x00_set_fcport_disc_state(fcport,
858 case DSC_LS_PRLI_COMP:
859 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
860 fcport->port_type = FCT_INITIATOR;
862 fcport->port_type = FCT_TARGET;
864 data[0] = data[1] = 0;
865 qla2x00_post_async_adisc_work(vha, fcport,
868 case DSC_LS_PLOGI_COMP:
869 if (fcport_is_bigger(fcport)) {
870 /* local adapter is smaller */
871 if (fcport->loop_id != FC_NO_LOOP_ID)
872 qla2x00_clear_loop_id(fcport);
874 fcport->loop_id = loop_id;
875 qla24xx_fcport_handle_login(vha,
881 if (fcport_is_smaller(fcport)) {
882 /* local adapter is bigger */
883 if (fcport->loop_id != FC_NO_LOOP_ID)
884 qla2x00_clear_loop_id(fcport);
886 fcport->loop_id = loop_id;
887 qla24xx_fcport_handle_login(vha,
893 } /* switch (ha->current_topology) */
897 switch (vha->hw->current_topology) {
900 for (i = 0; i < n; i++) {
902 id.b.domain = e->port_id[0];
903 id.b.area = e->port_id[1];
904 id.b.al_pa = e->port_id[2];
906 loop_id = le16_to_cpu(e->nport_handle);
908 if (fcport->d_id.b24 == id.b24) {
910 qla2x00_find_fcport_by_wwpn(vha,
912 if (conflict_fcport) {
913 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
915 "%s %d %8phC post del sess\n",
917 conflict_fcport->port_name);
918 qlt_schedule_sess_for_deletion
923 * FW already picked this loop id for
926 if (fcport->loop_id == loop_id)
927 fcport->loop_id = FC_NO_LOOP_ID;
929 qla24xx_fcport_handle_login(vha, fcport);
932 qla2x00_set_fcport_disc_state(fcport, DSC_DELETED);
933 if (time_after_eq(jiffies, fcport->dm_login_expire)) {
934 if (fcport->n2n_link_reset_cnt < 2) {
935 fcport->n2n_link_reset_cnt++;
937 * remote port is not sending PLOGI.
938 * Reset link to kick start his state
941 set_bit(N2N_LINK_RESET,
944 if (fcport->n2n_chip_reset < 1) {
945 ql_log(ql_log_info, vha, 0x705d,
946 "Chip reset to bring laser down");
947 set_bit(ISP_ABORT_NEEDED,
949 fcport->n2n_chip_reset++;
951 ql_log(ql_log_info, vha, 0x705d,
952 "Remote port %8ph is not coming back\n",
954 fcport->scan_state = 0;
957 qla2xxx_wake_dpc(vha);
960 * report port suppose to do PLOGI. Give him
961 * more time. FW will catch it.
963 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
967 qla24xx_fcport_handle_login(vha, fcport);
975 static void qla24xx_async_gnl_sp_done(srb_t *sp, int res)
977 struct scsi_qla_host *vha = sp->vha;
979 struct fc_port *fcport = NULL, *tf;
980 u16 i, n = 0, loop_id;
982 struct get_name_list_extended *e;
987 ql_dbg(ql_dbg_disc, vha, 0x20e7,
988 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
989 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
990 sp->u.iocb_cmd.u.mbx.in_mb[2]);
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__, (void *)&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 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1030 list_del_init(&fcport->gnl_entry);
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, FC4_TYPE_UNKNOWN);
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)
1152 fcport->flags &= ~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 static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1202 struct qla_work_evt *e;
1204 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
1206 return QLA_FUNCTION_FAILED;
1208 e->u.fcport.fcport = fcport;
1210 return qla2x00_post_work(vha, e);
1213 static void qla2x00_async_prli_sp_done(srb_t *sp, int res)
1215 struct scsi_qla_host *vha = sp->vha;
1216 struct srb_iocb *lio = &sp->u.iocb_cmd;
1217 struct event_arg ea;
1219 ql_dbg(ql_dbg_disc, vha, 0x2129,
1220 "%s %8phC res %d \n", __func__,
1221 sp->fcport->port_name, res);
1223 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1225 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
1226 memset(&ea, 0, sizeof(ea));
1227 ea.fcport = sp->fcport;
1228 ea.data[0] = lio->u.logio.data[0];
1229 ea.data[1] = lio->u.logio.data[1];
1230 ea.iop[0] = lio->u.logio.iop[0];
1231 ea.iop[1] = lio->u.logio.iop[1];
1234 qla24xx_handle_prli_done_event(vha, &ea);
1241 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
1244 struct srb_iocb *lio;
1245 int rval = QLA_FUNCTION_FAILED;
1247 if (!vha->flags.online) {
1248 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1249 __func__, __LINE__, fcport->port_name);
1253 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
1254 fcport->fw_login_state == DSC_LS_PRLI_PEND) &&
1255 qla_dual_mode_enabled(vha)) {
1256 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1257 __func__, __LINE__, fcport->port_name);
1261 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1265 fcport->flags |= FCF_ASYNC_SENT;
1266 fcport->logout_completed = 0;
1268 sp->type = SRB_PRLI_CMD;
1271 lio = &sp->u.iocb_cmd;
1272 lio->timeout = qla2x00_async_iocb_timeout;
1273 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1275 sp->done = qla2x00_async_prli_sp_done;
1276 lio->u.logio.flags = 0;
1278 if (NVME_TARGET(vha->hw, fcport))
1279 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
1281 ql_dbg(ql_dbg_disc, vha, 0x211b,
1282 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d %s.\n",
1283 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24,
1284 fcport->login_retry, NVME_TARGET(vha->hw, fcport) ? "nvme" : "fc");
1286 rval = qla2x00_start_sp(sp);
1287 if (rval != QLA_SUCCESS) {
1288 fcport->flags |= FCF_LOGIN_NEEDED;
1289 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1297 fcport->flags &= ~FCF_ASYNC_SENT;
1301 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1303 struct qla_work_evt *e;
1305 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
1307 return QLA_FUNCTION_FAILED;
1309 e->u.fcport.fcport = fcport;
1310 e->u.fcport.opt = opt;
1311 fcport->flags |= FCF_ASYNC_ACTIVE;
1312 return qla2x00_post_work(vha, e);
1315 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1318 struct srb_iocb *mbx;
1319 int rval = QLA_FUNCTION_FAILED;
1322 struct port_database_24xx *pd;
1323 struct qla_hw_data *ha = vha->hw;
1325 if (IS_SESSION_DELETED(fcport)) {
1326 ql_log(ql_log_warn, vha, 0xffff,
1327 "%s: %8phC is being delete - not sending command.\n",
1328 __func__, fcport->port_name);
1329 fcport->flags &= ~FCF_ASYNC_ACTIVE;
1333 if (!vha->flags.online || fcport->flags & FCF_ASYNC_SENT) {
1334 ql_log(ql_log_warn, vha, 0xffff,
1335 "%s: %8phC online %d flags %x - not sending command.\n",
1336 __func__, fcport->port_name, vha->flags.online, fcport->flags);
1340 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1344 qla2x00_set_fcport_disc_state(fcport, DSC_GPDB);
1346 fcport->flags |= FCF_ASYNC_SENT;
1347 sp->type = SRB_MB_IOCB;
1349 sp->gen1 = fcport->rscn_gen;
1350 sp->gen2 = fcport->login_gen;
1352 mbx = &sp->u.iocb_cmd;
1353 mbx->timeout = qla2x00_async_iocb_timeout;
1354 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1356 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1358 ql_log(ql_log_warn, vha, 0xd043,
1359 "Failed to allocate port database structure.\n");
1363 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1364 mb[0] = MBC_GET_PORT_DATABASE;
1365 mb[1] = fcport->loop_id;
1366 mb[2] = MSW(pd_dma);
1367 mb[3] = LSW(pd_dma);
1368 mb[6] = MSW(MSD(pd_dma));
1369 mb[7] = LSW(MSD(pd_dma));
1370 mb[9] = vha->vp_idx;
1373 mbx->u.mbx.in = (void *)pd;
1374 mbx->u.mbx.in_dma = pd_dma;
1376 sp->done = qla24xx_async_gpdb_sp_done;
1378 ql_dbg(ql_dbg_disc, vha, 0x20dc,
1379 "Async-%s %8phC hndl %x opt %x\n",
1380 sp->name, fcport->port_name, sp->handle, opt);
1382 rval = qla2x00_start_sp(sp);
1383 if (rval != QLA_SUCCESS)
1389 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1392 fcport->flags &= ~FCF_ASYNC_SENT;
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);
1430 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1432 fc_port_t *fcport = ea->fcport;
1433 struct port_database_24xx *pd;
1434 struct srb *sp = ea->sp;
1437 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1439 fcport->flags &= ~FCF_ASYNC_SENT;
1441 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1442 "%s %8phC DS %d LS %d fc4_type %x rc %d\n", __func__,
1443 fcport->port_name, fcport->disc_state, pd->current_login_state,
1444 fcport->fc4_type, ea->rc);
1446 if (fcport->disc_state == DSC_DELETE_PEND)
1449 if (NVME_TARGET(vha->hw, fcport))
1450 ls = pd->current_login_state >> 4;
1452 ls = pd->current_login_state & 0xf;
1454 if (ea->sp->gen2 != fcport->login_gen) {
1455 /* target side must have changed it. */
1457 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1458 "%s %8phC generation changed\n",
1459 __func__, fcport->port_name);
1461 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1462 qla_rscn_replay(fcport);
1463 qlt_schedule_sess_for_deletion(fcport);
1468 case PDS_PRLI_COMPLETE:
1469 __qla24xx_parse_gpdb(vha, fcport, pd);
1471 case PDS_PLOGI_PENDING:
1472 case PDS_PLOGI_COMPLETE:
1473 case PDS_PRLI_PENDING:
1474 case PDS_PRLI2_PENDING:
1475 /* Set discovery state back to GNL to Relogin attempt */
1476 if (qla_dual_mode_enabled(vha) ||
1477 qla_ini_mode_enabled(vha)) {
1478 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
1479 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1482 case PDS_LOGO_PENDING:
1483 case PDS_PORT_UNAVAILABLE:
1485 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1486 __func__, __LINE__, fcport->port_name);
1487 qlt_schedule_sess_for_deletion(fcport);
1490 __qla24xx_handle_gpdb_event(vha, ea);
1493 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1498 ql_dbg(ql_dbg_disc, vha, 0x307b,
1499 "%s %8phC DS %d LS %d lid %d retries=%d\n",
1500 __func__, fcport->port_name, fcport->disc_state,
1501 fcport->fw_login_state, fcport->loop_id, fcport->login_retry);
1503 if (qla_tgt_mode_enabled(vha))
1506 if (qla_dual_mode_enabled(vha)) {
1507 if (N2N_TOPO(vha->hw)) {
1510 mywwn = wwn_to_u64(vha->port_name);
1511 wwn = wwn_to_u64(fcport->port_name);
1514 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1515 && time_after_eq(jiffies,
1516 fcport->plogi_nack_done_deadline))
1522 /* initiator mode */
1526 if (login && fcport->login_retry) {
1527 fcport->login_retry--;
1528 if (fcport->loop_id == FC_NO_LOOP_ID) {
1529 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1530 rc = qla2x00_find_new_loop_id(vha, fcport);
1532 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1533 "%s %d %8phC post del sess - out of loopid\n",
1534 __func__, __LINE__, fcport->port_name);
1535 fcport->scan_state = 0;
1536 qlt_schedule_sess_for_deletion(fcport);
1540 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1541 "%s %d %8phC post login\n",
1542 __func__, __LINE__, fcport->port_name);
1543 qla2x00_post_async_login_work(vha, fcport, NULL);
1547 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1553 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1554 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d\n",
1555 __func__, fcport->port_name, fcport->disc_state,
1556 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1557 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1558 fcport->login_gen, fcport->loop_id, fcport->scan_state);
1560 if (fcport->scan_state != QLA_FCPORT_FOUND ||
1561 fcport->disc_state == DSC_DELETE_PEND)
1564 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1565 qla_dual_mode_enabled(vha) &&
1566 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1567 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1570 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP &&
1571 !N2N_TOPO(vha->hw)) {
1572 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1573 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1578 /* for pure Target Mode. Login will not be initiated */
1579 if (vha->host->active_mode == MODE_TARGET)
1582 if (fcport->flags & (FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE)) {
1583 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1587 switch (fcport->disc_state) {
1589 wwn = wwn_to_u64(fcport->node_name);
1590 switch (vha->hw->current_topology) {
1592 if (fcport_is_smaller(fcport)) {
1593 /* this adapter is bigger */
1594 if (fcport->login_retry) {
1595 if (fcport->loop_id == FC_NO_LOOP_ID) {
1596 qla2x00_find_new_loop_id(vha,
1598 fcport->fw_login_state =
1599 DSC_LS_PORT_UNAVAIL;
1601 fcport->login_retry--;
1602 qla_post_els_plogi_work(vha, fcport);
1604 ql_log(ql_log_info, vha, 0x705d,
1605 "Unable to reach remote port %8phC",
1609 qla24xx_post_gnl_work(vha, fcport);
1614 ql_dbg(ql_dbg_disc, vha, 0xffff,
1615 "%s %d %8phC post GNNID\n",
1616 __func__, __LINE__, fcport->port_name);
1617 qla24xx_post_gnnid_work(vha, fcport);
1618 } else if (fcport->loop_id == FC_NO_LOOP_ID) {
1619 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1620 "%s %d %8phC post gnl\n",
1621 __func__, __LINE__, fcport->port_name);
1622 qla24xx_post_gnl_work(vha, fcport);
1624 qla_chk_n2n_b4_login(vha, fcport);
1631 switch (vha->hw->current_topology) {
1633 if ((fcport->current_login_state & 0xf) == 0x6) {
1634 ql_dbg(ql_dbg_disc, vha, 0x2118,
1635 "%s %d %8phC post GPDB work\n",
1636 __func__, __LINE__, fcport->port_name);
1637 fcport->chip_reset =
1638 vha->hw->base_qpair->chip_reset;
1639 qla24xx_post_gpdb_work(vha, fcport, 0);
1641 ql_dbg(ql_dbg_disc, vha, 0x2118,
1642 "%s %d %8phC post %s PRLI\n",
1643 __func__, __LINE__, fcport->port_name,
1644 NVME_TARGET(vha->hw, fcport) ? "NVME" :
1646 qla24xx_post_prli_work(vha, fcport);
1650 if (fcport->login_pause) {
1651 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1652 "%s %d %8phC exit\n",
1655 fcport->last_rscn_gen = fcport->rscn_gen;
1656 fcport->last_login_gen = fcport->login_gen;
1657 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1660 qla_chk_n2n_b4_login(vha, fcport);
1665 case DSC_LOGIN_FAILED:
1666 if (N2N_TOPO(vha->hw))
1667 qla_chk_n2n_b4_login(vha, fcport);
1669 qlt_schedule_sess_for_deletion(fcport);
1672 case DSC_LOGIN_COMPLETE:
1673 /* recheck login state */
1674 data[0] = data[1] = 0;
1675 qla2x00_post_async_adisc_work(vha, fcport, data);
1678 case DSC_LOGIN_PEND:
1679 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1680 qla24xx_post_prli_work(vha, fcport);
1683 case DSC_UPD_FCPORT:
1684 sec = jiffies_to_msecs(jiffies -
1685 fcport->jiffies_at_registration)/1000;
1686 if (fcport->sec_since_registration < sec && sec &&
1688 fcport->sec_since_registration = sec;
1689 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
1690 "%s %8phC - Slow Rport registration(%d Sec)\n",
1691 __func__, fcport->port_name, sec);
1694 if (fcport->next_disc_state != DSC_DELETE_PEND)
1695 fcport->next_disc_state = DSC_ADISC;
1696 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1706 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1707 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1709 struct qla_work_evt *e;
1711 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1713 return QLA_FUNCTION_FAILED;
1715 e->u.new_sess.id = *id;
1716 e->u.new_sess.pla = pla;
1717 e->u.new_sess.fc4_type = fc4_type;
1718 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1720 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1722 return qla2x00_post_work(vha, e);
1725 void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
1728 unsigned long flags;
1730 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1732 fcport->scan_needed = 1;
1736 spin_lock_irqsave(&vha->work_lock, flags);
1737 if (vha->scan.scan_flags == 0) {
1738 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s: schedule\n", __func__);
1739 vha->scan.scan_flags |= SF_QUEUED;
1740 schedule_delayed_work(&vha->scan.scan_work, 5);
1742 spin_unlock_irqrestore(&vha->work_lock, flags);
1745 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1746 struct event_arg *ea)
1748 fc_port_t *fcport = ea->fcport;
1750 if (test_bit(UNLOADING, &vha->dpc_flags))
1753 ql_dbg(ql_dbg_disc, vha, 0x2102,
1754 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1755 __func__, fcport->port_name, fcport->disc_state,
1756 fcport->fw_login_state, fcport->login_pause,
1757 fcport->deleted, fcport->conflict,
1758 fcport->last_rscn_gen, fcport->rscn_gen,
1759 fcport->last_login_gen, fcport->login_gen,
1762 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1763 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gnl\n",
1764 __func__, __LINE__, fcport->port_name);
1765 qla24xx_post_gnl_work(vha, fcport);
1769 qla24xx_fcport_handle_login(vha, fcport);
1772 void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
1773 struct event_arg *ea)
1775 ql_dbg(ql_dbg_disc, vha, 0x2118,
1776 "%s %d %8phC post PRLI\n",
1777 __func__, __LINE__, ea->fcport->port_name);
1778 qla24xx_post_prli_work(vha, ea->fcport);
1782 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1783 * to be consumed by the fcport
1785 void qla_rscn_replay(fc_port_t *fcport)
1787 struct event_arg ea;
1789 switch (fcport->disc_state) {
1790 case DSC_DELETE_PEND:
1796 if (fcport->scan_needed) {
1797 memset(&ea, 0, sizeof(ea));
1798 ea.id = fcport->d_id;
1799 ea.id.b.rsvd_1 = RSCN_PORT_ADDR;
1800 qla2x00_handle_rscn(fcport->vha, &ea);
1805 qla2x00_tmf_iocb_timeout(void *data)
1808 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1810 unsigned long flags;
1812 rc = qla24xx_async_abort_cmd(sp, false);
1814 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
1815 for (h = 1; h < sp->qpair->req->num_outstanding_cmds; h++) {
1816 if (sp->qpair->req->outstanding_cmds[h] == sp) {
1817 sp->qpair->req->outstanding_cmds[h] = NULL;
1821 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
1822 tmf->u.tmf.comp_status = CS_TIMEOUT;
1823 tmf->u.tmf.data = QLA_FUNCTION_FAILED;
1824 complete(&tmf->u.tmf.comp);
1828 static void qla2x00_tmf_sp_done(srb_t *sp, int res)
1830 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1832 complete(&tmf->u.tmf.comp);
1836 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
1839 struct scsi_qla_host *vha = fcport->vha;
1840 struct srb_iocb *tm_iocb;
1842 int rval = QLA_FUNCTION_FAILED;
1844 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1848 tm_iocb = &sp->u.iocb_cmd;
1849 sp->type = SRB_TM_CMD;
1852 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1853 init_completion(&tm_iocb->u.tmf.comp);
1854 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1856 tm_iocb->u.tmf.flags = flags;
1857 tm_iocb->u.tmf.lun = lun;
1858 tm_iocb->u.tmf.data = tag;
1859 sp->done = qla2x00_tmf_sp_done;
1861 ql_dbg(ql_dbg_taskm, vha, 0x802f,
1862 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1863 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1864 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1866 rval = qla2x00_start_sp(sp);
1867 if (rval != QLA_SUCCESS)
1869 wait_for_completion(&tm_iocb->u.tmf.comp);
1871 rval = tm_iocb->u.tmf.data;
1873 if (rval != QLA_SUCCESS) {
1874 ql_log(ql_log_warn, vha, 0x8030,
1875 "TM IOCB failed (%x).\n", rval);
1878 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1879 flags = tm_iocb->u.tmf.flags;
1880 lun = (uint16_t)tm_iocb->u.tmf.lun;
1882 /* Issue Marker IOCB */
1883 qla2x00_marker(vha, vha->hw->base_qpair,
1884 fcport->loop_id, lun,
1885 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1890 fcport->flags &= ~FCF_ASYNC_SENT;
1896 qla24xx_async_abort_command(srb_t *sp)
1898 unsigned long flags = 0;
1901 fc_port_t *fcport = sp->fcport;
1902 struct qla_qpair *qpair = sp->qpair;
1903 struct scsi_qla_host *vha = fcport->vha;
1904 struct req_que *req = qpair->req;
1906 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1907 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1908 if (req->outstanding_cmds[handle] == sp)
1911 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1913 if (handle == req->num_outstanding_cmds) {
1914 /* Command not found. */
1915 return QLA_FUNCTION_FAILED;
1917 if (sp->type == SRB_FXIOCB_DCMD)
1918 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1919 FXDISC_ABORT_IOCTL);
1921 return qla24xx_async_abort_cmd(sp, true);
1925 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1927 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
1930 switch (ea->data[0]) {
1931 case MBS_COMMAND_COMPLETE:
1932 ql_dbg(ql_dbg_disc, vha, 0x2118,
1933 "%s %d %8phC post gpdb\n",
1934 __func__, __LINE__, ea->fcport->port_name);
1936 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1937 ea->fcport->logout_on_delete = 1;
1938 ea->fcport->nvme_prli_service_param = ea->iop[0];
1939 if (ea->iop[0] & NVME_PRLI_SP_FIRST_BURST)
1940 ea->fcport->nvme_first_burst_size =
1941 (ea->iop[1] & 0xffff) * 512;
1943 ea->fcport->nvme_first_burst_size = 0;
1944 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1947 if ((ea->iop[0] == LSC_SCODE_ELS_REJECT) &&
1948 (ea->iop[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
1949 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1950 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
1955 * Retry PRLI with other FC-4 type if failure occurred on dual
1958 if (NVME_FCP_TARGET(ea->fcport)) {
1959 ql_dbg(ql_dbg_disc, vha, 0x2118,
1960 "%s %d %8phC post %s prli\n",
1961 __func__, __LINE__, ea->fcport->port_name,
1962 (ea->fcport->fc4_type & FS_FC4TYPE_NVME) ?
1964 if (vha->hw->fc4_type_priority == FC4_PRIORITY_NVME)
1965 ea->fcport->fc4_type &= ~FS_FC4TYPE_NVME;
1967 ea->fcport->fc4_type &= ~FS_FC4TYPE_FCP;
1970 ea->fcport->flags &= ~FCF_ASYNC_SENT;
1971 ea->fcport->keep_nport_handle = 0;
1972 ea->fcport->logout_on_delete = 1;
1973 qlt_schedule_sess_for_deletion(ea->fcport);
1979 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1981 port_id_t cid; /* conflict Nport id */
1983 struct fc_port *conflict_fcport;
1984 unsigned long flags;
1985 struct fc_port *fcport = ea->fcport;
1987 ql_dbg(ql_dbg_disc, vha, 0xffff,
1988 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1989 __func__, fcport->port_name, fcport->disc_state,
1990 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
1991 ea->sp->gen1, fcport->rscn_gen,
1992 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
1994 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1995 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
1996 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1997 "%s %d %8phC Remote is trying to login\n",
1998 __func__, __LINE__, fcport->port_name);
2002 if ((fcport->disc_state == DSC_DELETE_PEND) ||
2003 (fcport->disc_state == DSC_DELETED)) {
2004 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2008 if (ea->sp->gen2 != fcport->login_gen) {
2009 /* target side must have changed it. */
2010 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2011 "%s %8phC generation changed\n",
2012 __func__, fcport->port_name);
2013 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2015 } else if (ea->sp->gen1 != fcport->rscn_gen) {
2016 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2017 "%s %8phC RSCN generation changed\n",
2018 __func__, fcport->port_name);
2019 qla_rscn_replay(fcport);
2020 qlt_schedule_sess_for_deletion(fcport);
2024 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
2027 switch (ea->data[0]) {
2028 case MBS_COMMAND_COMPLETE:
2030 * Driver must validate login state - If PRLI not complete,
2031 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
2034 if (NVME_TARGET(vha->hw, ea->fcport)) {
2035 ql_dbg(ql_dbg_disc, vha, 0x2117,
2036 "%s %d %8phC post prli\n",
2037 __func__, __LINE__, ea->fcport->port_name);
2038 qla24xx_post_prli_work(vha, ea->fcport);
2040 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2041 "%s %d %8phC LoopID 0x%x in use with %06x. post gpdb\n",
2042 __func__, __LINE__, ea->fcport->port_name,
2043 ea->fcport->loop_id, ea->fcport->d_id.b24);
2045 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2046 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2047 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2048 ea->fcport->logout_on_delete = 1;
2049 ea->fcport->send_els_logo = 0;
2050 ea->fcport->fw_login_state = DSC_LS_PRLI_COMP;
2051 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2053 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2056 case MBS_COMMAND_ERROR:
2057 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
2058 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
2060 ea->fcport->flags &= ~FCF_ASYNC_SENT;
2061 qla2x00_set_fcport_disc_state(ea->fcport, DSC_LOGIN_FAILED);
2062 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
2063 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2065 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
2067 case MBS_LOOP_ID_USED:
2068 /* data[1] = IO PARAM 1 = nport ID */
2069 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
2070 cid.b.area = (ea->iop[1] >> 8) & 0xff;
2071 cid.b.al_pa = ea->iop[1] & 0xff;
2074 ql_dbg(ql_dbg_disc, vha, 0x20ec,
2075 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2076 __func__, __LINE__, ea->fcport->port_name,
2077 ea->fcport->loop_id, cid.b24);
2079 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2080 ea->fcport->loop_id = FC_NO_LOOP_ID;
2081 qla24xx_post_gnl_work(vha, ea->fcport);
2083 case MBS_PORT_ID_USED:
2084 lid = ea->iop[1] & 0xffff;
2085 qlt_find_sess_invalidate_other(vha,
2086 wwn_to_u64(ea->fcport->port_name),
2087 ea->fcport->d_id, lid, &conflict_fcport);
2089 if (conflict_fcport) {
2091 * Another fcport share the same loop_id/nport id.
2092 * Conflict fcport needs to finish cleanup before this
2093 * fcport can proceed to login.
2095 conflict_fcport->conflict = ea->fcport;
2096 ea->fcport->login_pause = 1;
2098 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2099 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
2100 __func__, __LINE__, ea->fcport->port_name,
2101 ea->fcport->d_id.b24, lid);
2103 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2104 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2105 __func__, __LINE__, ea->fcport->port_name,
2106 ea->fcport->d_id.b24, lid);
2108 qla2x00_clear_loop_id(ea->fcport);
2109 set_bit(lid, vha->hw->loop_id_map);
2110 ea->fcport->loop_id = lid;
2111 ea->fcport->keep_nport_handle = 0;
2112 ea->fcport->logout_on_delete = 1;
2113 qlt_schedule_sess_for_deletion(ea->fcport);
2121 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
2124 qlt_logo_completion_handler(fcport, data[0]);
2125 fcport->login_gen++;
2126 fcport->flags &= ~FCF_ASYNC_ACTIVE;
2130 /****************************************************************************/
2131 /* QLogic ISP2x00 Hardware Support Functions. */
2132 /****************************************************************************/
2135 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
2137 int rval = QLA_SUCCESS;
2138 struct qla_hw_data *ha = vha->hw;
2139 uint32_t idc_major_ver, idc_minor_ver;
2142 qla83xx_idc_lock(vha, 0);
2144 /* SV: TODO: Assign initialization timeout from
2145 * flash-info / other param
2147 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
2148 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
2150 /* Set our fcoe function presence */
2151 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
2152 ql_dbg(ql_dbg_p3p, vha, 0xb077,
2153 "Error while setting DRV-Presence.\n");
2154 rval = QLA_FUNCTION_FAILED;
2158 /* Decide the reset ownership */
2159 qla83xx_reset_ownership(vha);
2162 * On first protocol driver load:
2163 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2165 * Others: Check compatibility with current IDC Major version.
2167 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
2168 if (ha->flags.nic_core_reset_owner) {
2169 /* Set IDC Major version */
2170 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
2171 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
2173 /* Clearing IDC-Lock-Recovery register */
2174 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
2175 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
2177 * Clear further IDC participation if we are not compatible with
2178 * the current IDC Major Version.
2180 ql_log(ql_log_warn, vha, 0xb07d,
2181 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2182 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
2183 __qla83xx_clear_drv_presence(vha);
2184 rval = QLA_FUNCTION_FAILED;
2187 /* Each function sets its supported Minor version. */
2188 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
2189 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
2190 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
2192 if (ha->flags.nic_core_reset_owner) {
2193 memset(config, 0, sizeof(config));
2194 if (!qla81xx_get_port_config(vha, config))
2195 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
2199 rval = qla83xx_idc_state_handler(vha);
2202 qla83xx_idc_unlock(vha, 0);
2208 * qla2x00_initialize_adapter
2212 * ha = adapter block pointer.
2218 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
2221 struct qla_hw_data *ha = vha->hw;
2222 struct req_que *req = ha->req_q_map[0];
2223 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2225 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2226 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2228 /* Clear adapter flags. */
2229 vha->flags.online = 0;
2230 ha->flags.chip_reset_done = 0;
2231 vha->flags.reset_active = 0;
2232 ha->flags.pci_channel_io_perm_failure = 0;
2233 ha->flags.eeh_busy = 0;
2234 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2235 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
2236 atomic_set(&vha->loop_state, LOOP_DOWN);
2237 vha->device_flags = DFLG_NO_CABLE;
2239 vha->flags.management_server_logged_in = 0;
2240 vha->marker_needed = 0;
2241 ha->isp_abort_cnt = 0;
2242 ha->beacon_blink_led = 0;
2244 set_bit(0, ha->req_qid_map);
2245 set_bit(0, ha->rsp_qid_map);
2247 ql_dbg(ql_dbg_init, vha, 0x0040,
2248 "Configuring PCI space...\n");
2249 rval = ha->isp_ops->pci_config(vha);
2251 ql_log(ql_log_warn, vha, 0x0044,
2252 "Unable to configure PCI space.\n");
2256 ha->isp_ops->reset_chip(vha);
2258 /* Check for secure flash support */
2259 if (IS_QLA28XX(ha)) {
2260 if (RD_REG_DWORD(®->mailbox12) & BIT_0) {
2261 ql_log(ql_log_info, vha, 0xffff, "Adapter is Secure\n");
2262 ha->flags.secure_adapter = 1;
2267 rval = qla2xxx_get_flash_info(vha);
2269 ql_log(ql_log_fatal, vha, 0x004f,
2270 "Unable to validate FLASH data.\n");
2274 if (IS_QLA8044(ha)) {
2275 qla8044_read_reset_template(vha);
2277 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2278 * If DONRESET_BIT0 is set, drivers should not set dev_state
2279 * to NEED_RESET. But if NEED_RESET is set, drivers should
2280 * should honor the reset. */
2281 if (ql2xdontresethba == 1)
2282 qla8044_set_idc_dontreset(vha);
2285 ha->isp_ops->get_flash_version(vha, req->ring);
2286 ql_dbg(ql_dbg_init, vha, 0x0061,
2287 "Configure NVRAM parameters...\n");
2289 ha->isp_ops->nvram_config(vha);
2291 if (ha->flags.disable_serdes) {
2292 /* Mask HBA via NVRAM settings? */
2293 ql_log(ql_log_info, vha, 0x0077,
2294 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
2295 return QLA_FUNCTION_FAILED;
2298 ql_dbg(ql_dbg_init, vha, 0x0078,
2299 "Verifying loaded RISC code...\n");
2301 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
2302 rval = ha->isp_ops->chip_diag(vha);
2305 rval = qla2x00_setup_chip(vha);
2310 if (IS_QLA84XX(ha)) {
2311 ha->cs84xx = qla84xx_get_chip(vha);
2313 ql_log(ql_log_warn, vha, 0x00d0,
2314 "Unable to configure ISP84XX.\n");
2315 return QLA_FUNCTION_FAILED;
2319 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2320 rval = qla2x00_init_rings(vha);
2322 /* No point in continuing if firmware initialization failed. */
2323 if (rval != QLA_SUCCESS)
2326 ha->flags.chip_reset_done = 1;
2328 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2329 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2330 rval = qla84xx_init_chip(vha);
2331 if (rval != QLA_SUCCESS) {
2332 ql_log(ql_log_warn, vha, 0x00d4,
2333 "Unable to initialize ISP84XX.\n");
2334 qla84xx_put_chip(vha);
2338 /* Load the NIC Core f/w if we are the first protocol driver. */
2339 if (IS_QLA8031(ha)) {
2340 rval = qla83xx_nic_core_fw_load(vha);
2342 ql_log(ql_log_warn, vha, 0x0124,
2343 "Error in initializing NIC Core f/w.\n");
2346 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2347 qla24xx_read_fcp_prio_cfg(vha);
2349 if (IS_P3P_TYPE(ha))
2350 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2352 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2358 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2361 * Returns 0 on success.
2364 qla2100_pci_config(scsi_qla_host_t *vha)
2367 unsigned long flags;
2368 struct qla_hw_data *ha = vha->hw;
2369 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2371 pci_set_master(ha->pdev);
2372 pci_try_set_mwi(ha->pdev);
2374 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2375 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2376 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2378 pci_disable_rom(ha->pdev);
2380 /* Get PCI bus information. */
2381 spin_lock_irqsave(&ha->hardware_lock, flags);
2382 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2383 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2389 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2392 * Returns 0 on success.
2395 qla2300_pci_config(scsi_qla_host_t *vha)
2398 unsigned long flags = 0;
2400 struct qla_hw_data *ha = vha->hw;
2401 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2403 pci_set_master(ha->pdev);
2404 pci_try_set_mwi(ha->pdev);
2406 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2407 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2409 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2410 w &= ~PCI_COMMAND_INTX_DISABLE;
2411 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2414 * If this is a 2300 card and not 2312, reset the
2415 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2416 * the 2310 also reports itself as a 2300 so we need to get the
2417 * fb revision level -- a 6 indicates it really is a 2300 and
2420 if (IS_QLA2300(ha)) {
2421 spin_lock_irqsave(&ha->hardware_lock, flags);
2424 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2425 for (cnt = 0; cnt < 30000; cnt++) {
2426 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
2432 /* Select FPM registers. */
2433 WRT_REG_WORD(®->ctrl_status, 0x20);
2434 RD_REG_WORD(®->ctrl_status);
2436 /* Get the fb rev level */
2437 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2439 if (ha->fb_rev == FPM_2300)
2440 pci_clear_mwi(ha->pdev);
2442 /* Deselect FPM registers. */
2443 WRT_REG_WORD(®->ctrl_status, 0x0);
2444 RD_REG_WORD(®->ctrl_status);
2446 /* Release RISC module. */
2447 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2448 for (cnt = 0; cnt < 30000; cnt++) {
2449 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
2455 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2458 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2460 pci_disable_rom(ha->pdev);
2462 /* Get PCI bus information. */
2463 spin_lock_irqsave(&ha->hardware_lock, flags);
2464 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2465 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2471 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2474 * Returns 0 on success.
2477 qla24xx_pci_config(scsi_qla_host_t *vha)
2480 unsigned long flags = 0;
2481 struct qla_hw_data *ha = vha->hw;
2482 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2484 pci_set_master(ha->pdev);
2485 pci_try_set_mwi(ha->pdev);
2487 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2488 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2489 w &= ~PCI_COMMAND_INTX_DISABLE;
2490 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2492 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2494 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2495 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2496 pcix_set_mmrbc(ha->pdev, 2048);
2498 /* PCIe -- adjust Maximum Read Request Size (2048). */
2499 if (pci_is_pcie(ha->pdev))
2500 pcie_set_readrq(ha->pdev, 4096);
2502 pci_disable_rom(ha->pdev);
2504 ha->chip_revision = ha->pdev->revision;
2506 /* Get PCI bus information. */
2507 spin_lock_irqsave(&ha->hardware_lock, flags);
2508 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
2509 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2515 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2518 * Returns 0 on success.
2521 qla25xx_pci_config(scsi_qla_host_t *vha)
2524 struct qla_hw_data *ha = vha->hw;
2526 pci_set_master(ha->pdev);
2527 pci_try_set_mwi(ha->pdev);
2529 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2530 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2531 w &= ~PCI_COMMAND_INTX_DISABLE;
2532 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2534 /* PCIe -- adjust Maximum Read Request Size (2048). */
2535 if (pci_is_pcie(ha->pdev))
2536 pcie_set_readrq(ha->pdev, 4096);
2538 pci_disable_rom(ha->pdev);
2540 ha->chip_revision = ha->pdev->revision;
2546 * qla2x00_isp_firmware() - Choose firmware image.
2549 * Returns 0 on success.
2552 qla2x00_isp_firmware(scsi_qla_host_t *vha)
2555 uint16_t loop_id, topo, sw_cap;
2556 uint8_t domain, area, al_pa;
2557 struct qla_hw_data *ha = vha->hw;
2559 /* Assume loading risc code */
2560 rval = QLA_FUNCTION_FAILED;
2562 if (ha->flags.disable_risc_code_load) {
2563 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
2565 /* Verify checksum of loaded RISC code. */
2566 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
2567 if (rval == QLA_SUCCESS) {
2568 /* And, verify we are not in ROM code. */
2569 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2570 &area, &domain, &topo, &sw_cap);
2575 ql_dbg(ql_dbg_init, vha, 0x007a,
2576 "**** Load RISC code ****.\n");
2582 * qla2x00_reset_chip() - Reset ISP chip.
2585 * Returns 0 on success.
2588 qla2x00_reset_chip(scsi_qla_host_t *vha)
2590 unsigned long flags = 0;
2591 struct qla_hw_data *ha = vha->hw;
2592 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2595 int rval = QLA_FUNCTION_FAILED;
2597 if (unlikely(pci_channel_offline(ha->pdev)))
2600 ha->isp_ops->disable_intrs(ha);
2602 spin_lock_irqsave(&ha->hardware_lock, flags);
2604 /* Turn off master enable */
2606 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2607 cmd &= ~PCI_COMMAND_MASTER;
2608 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2610 if (!IS_QLA2100(ha)) {
2612 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2613 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2614 for (cnt = 0; cnt < 30000; cnt++) {
2615 if ((RD_REG_WORD(®->hccr) &
2616 HCCR_RISC_PAUSE) != 0)
2621 RD_REG_WORD(®->hccr); /* PCI Posting. */
2625 /* Select FPM registers. */
2626 WRT_REG_WORD(®->ctrl_status, 0x20);
2627 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2629 /* FPM Soft Reset. */
2630 WRT_REG_WORD(®->fpm_diag_config, 0x100);
2631 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2633 /* Toggle Fpm Reset. */
2634 if (!IS_QLA2200(ha)) {
2635 WRT_REG_WORD(®->fpm_diag_config, 0x0);
2636 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2639 /* Select frame buffer registers. */
2640 WRT_REG_WORD(®->ctrl_status, 0x10);
2641 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2643 /* Reset frame buffer FIFOs. */
2644 if (IS_QLA2200(ha)) {
2645 WRT_FB_CMD_REG(ha, reg, 0xa000);
2646 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2648 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2650 /* Read back fb_cmd until zero or 3 seconds max */
2651 for (cnt = 0; cnt < 3000; cnt++) {
2652 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2658 /* Select RISC module registers. */
2659 WRT_REG_WORD(®->ctrl_status, 0);
2660 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2662 /* Reset RISC processor. */
2663 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2664 RD_REG_WORD(®->hccr); /* PCI Posting. */
2666 /* Release RISC processor. */
2667 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2668 RD_REG_WORD(®->hccr); /* PCI Posting. */
2671 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
2672 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
2674 /* Reset ISP chip. */
2675 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2677 /* Wait for RISC to recover from reset. */
2678 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2680 * It is necessary to for a delay here since the card doesn't
2681 * respond to PCI reads during a reset. On some architectures
2682 * this will result in an MCA.
2685 for (cnt = 30000; cnt; cnt--) {
2686 if ((RD_REG_WORD(®->ctrl_status) &
2687 CSR_ISP_SOFT_RESET) == 0)
2694 /* Reset RISC processor. */
2695 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2697 WRT_REG_WORD(®->semaphore, 0);
2699 /* Release RISC processor. */
2700 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2701 RD_REG_WORD(®->hccr); /* PCI Posting. */
2703 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2704 for (cnt = 0; cnt < 30000; cnt++) {
2705 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
2713 /* Turn on master enable */
2714 cmd |= PCI_COMMAND_MASTER;
2715 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2717 /* Disable RISC pause on FPM parity error. */
2718 if (!IS_QLA2100(ha)) {
2719 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
2720 RD_REG_WORD(®->hccr); /* PCI Posting. */
2723 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2729 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2732 * Returns 0 on success.
2735 qla81xx_reset_mpi(scsi_qla_host_t *vha)
2737 uint16_t mb[4] = {0x1010, 0, 1, 0};
2739 if (!IS_QLA81XX(vha->hw))
2742 return qla81xx_write_mpi_register(vha, mb);
2746 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2749 * Returns 0 on success.
2752 qla24xx_reset_risc(scsi_qla_host_t *vha)
2754 unsigned long flags = 0;
2755 struct qla_hw_data *ha = vha->hw;
2756 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2759 static int abts_cnt; /* ISP abort retry counts */
2760 int rval = QLA_SUCCESS;
2762 spin_lock_irqsave(&ha->hardware_lock, flags);
2765 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2766 for (cnt = 0; cnt < 30000; cnt++) {
2767 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2773 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE))
2774 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2776 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2777 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2778 RD_REG_DWORD(®->hccr),
2779 RD_REG_DWORD(®->ctrl_status),
2780 (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE));
2782 WRT_REG_DWORD(®->ctrl_status,
2783 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2784 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
2788 /* Wait for firmware to complete NVRAM accesses. */
2789 RD_REG_WORD(®->mailbox0);
2790 for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 &&
2791 rval == QLA_SUCCESS; cnt--) {
2796 rval = QLA_FUNCTION_TIMEOUT;
2799 if (rval == QLA_SUCCESS)
2800 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2802 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2803 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2804 RD_REG_DWORD(®->hccr),
2805 RD_REG_DWORD(®->mailbox0));
2807 /* Wait for soft-reset to complete. */
2808 RD_REG_DWORD(®->ctrl_status);
2809 for (cnt = 0; cnt < 60; cnt++) {
2811 if ((RD_REG_DWORD(®->ctrl_status) &
2812 CSRX_ISP_SOFT_RESET) == 0)
2817 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
2818 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2820 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2821 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2822 RD_REG_DWORD(®->hccr),
2823 RD_REG_DWORD(®->ctrl_status));
2825 /* If required, do an MPI FW reset now */
2826 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2827 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2828 if (++abts_cnt < 5) {
2829 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2830 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2833 * We exhausted the ISP abort retries. We have to
2834 * set the board offline.
2837 vha->flags.online = 0;
2842 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
2843 RD_REG_DWORD(®->hccr);
2845 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
2846 RD_REG_DWORD(®->hccr);
2848 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
2849 RD_REG_DWORD(®->hccr);
2851 RD_REG_WORD(®->mailbox0);
2852 for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 &&
2853 rval == QLA_SUCCESS; cnt--) {
2858 rval = QLA_FUNCTION_TIMEOUT;
2860 if (rval == QLA_SUCCESS)
2861 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2863 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2864 "Host Risc 0x%x, mailbox0 0x%x\n",
2865 RD_REG_DWORD(®->hccr),
2866 RD_REG_WORD(®->mailbox0));
2868 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2870 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2871 "Driver in %s mode\n",
2872 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2874 if (IS_NOPOLLING_TYPE(ha))
2875 ha->isp_ops->enable_intrs(ha);
2881 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2883 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2885 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2886 *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2891 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2893 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2895 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2896 WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2900 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2903 uint delta_msec = 100;
2904 uint elapsed_msec = 0;
2908 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2909 vha->hw->pdev->subsystem_device != 0x0240)
2912 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2916 timeout_msec = TIMEOUT_SEMAPHORE;
2917 n = timeout_msec / delta_msec;
2919 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2920 qla25xx_read_risc_sema_reg(vha, &wd32);
2921 if (wd32 & RISC_SEMAPHORE)
2924 elapsed_msec += delta_msec;
2925 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2929 if (!(wd32 & RISC_SEMAPHORE))
2932 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2935 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2936 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2937 n = timeout_msec / delta_msec;
2939 qla25xx_read_risc_sema_reg(vha, &wd32);
2940 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2943 elapsed_msec += delta_msec;
2944 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2948 if (wd32 & RISC_SEMAPHORE_FORCE)
2949 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2954 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2961 * qla24xx_reset_chip() - Reset ISP24xx chip.
2964 * Returns 0 on success.
2967 qla24xx_reset_chip(scsi_qla_host_t *vha)
2969 struct qla_hw_data *ha = vha->hw;
2970 int rval = QLA_FUNCTION_FAILED;
2972 if (pci_channel_offline(ha->pdev) &&
2973 ha->flags.pci_channel_io_perm_failure) {
2977 ha->isp_ops->disable_intrs(ha);
2979 qla25xx_manipulate_risc_semaphore(vha);
2981 /* Perform RISC reset. */
2982 rval = qla24xx_reset_risc(vha);
2988 * qla2x00_chip_diag() - Test chip for proper operation.
2991 * Returns 0 on success.
2994 qla2x00_chip_diag(scsi_qla_host_t *vha)
2997 struct qla_hw_data *ha = vha->hw;
2998 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2999 unsigned long flags = 0;
3003 struct req_que *req = ha->req_q_map[0];
3005 /* Assume a failed state */
3006 rval = QLA_FUNCTION_FAILED;
3008 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
3009 ®->flash_address);
3011 spin_lock_irqsave(&ha->hardware_lock, flags);
3013 /* Reset ISP chip. */
3014 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
3017 * We need to have a delay here since the card will not respond while
3018 * in reset causing an MCA on some architectures.
3021 data = qla2x00_debounce_register(®->ctrl_status);
3022 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
3024 data = RD_REG_WORD(®->ctrl_status);
3029 goto chip_diag_failed;
3031 ql_dbg(ql_dbg_init, vha, 0x007c,
3032 "Reset register cleared by chip reset.\n");
3034 /* Reset RISC processor. */
3035 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3036 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3038 /* Workaround for QLA2312 PCI parity error */
3039 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
3040 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
3041 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
3043 data = RD_MAILBOX_REG(ha, reg, 0);
3050 goto chip_diag_failed;
3052 /* Check product ID of chip */
3053 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
3055 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
3056 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
3057 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
3058 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
3059 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
3060 mb[3] != PROD_ID_3) {
3061 ql_log(ql_log_warn, vha, 0x0062,
3062 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
3063 mb[1], mb[2], mb[3]);
3065 goto chip_diag_failed;
3067 ha->product_id[0] = mb[1];
3068 ha->product_id[1] = mb[2];
3069 ha->product_id[2] = mb[3];
3070 ha->product_id[3] = mb[4];
3072 /* Adjust fw RISC transfer size */
3073 if (req->length > 1024)
3074 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
3076 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
3079 if (IS_QLA2200(ha) &&
3080 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
3081 /* Limit firmware transfer size with a 2200A */
3082 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
3084 ha->device_type |= DT_ISP2200A;
3085 ha->fw_transfer_size = 128;
3088 /* Wrap Incoming Mailboxes Test. */
3089 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3091 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
3092 rval = qla2x00_mbx_reg_test(vha);
3094 ql_log(ql_log_warn, vha, 0x0080,
3095 "Failed mailbox send register test.\n");
3097 /* Flag a successful rval */
3099 spin_lock_irqsave(&ha->hardware_lock, flags);
3103 ql_log(ql_log_info, vha, 0x0081,
3104 "Chip diagnostics **** FAILED ****.\n");
3106 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3112 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3115 * Returns 0 on success.
3118 qla24xx_chip_diag(scsi_qla_host_t *vha)
3121 struct qla_hw_data *ha = vha->hw;
3122 struct req_que *req = ha->req_q_map[0];
3124 if (IS_P3P_TYPE(ha))
3127 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
3129 rval = qla2x00_mbx_reg_test(vha);
3131 ql_log(ql_log_warn, vha, 0x0082,
3132 "Failed mailbox send register test.\n");
3134 /* Flag a successful rval */
3142 qla2x00_init_fce_trace(scsi_qla_host_t *vha)
3147 struct qla_hw_data *ha = vha->hw;
3149 if (!IS_FWI2_CAPABLE(ha))
3152 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3153 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3157 ql_dbg(ql_dbg_init, vha, 0x00bd,
3158 "%s: FCE Mem is already allocated.\n",
3163 /* Allocate memory for Fibre Channel Event Buffer. */
3164 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3167 ql_log(ql_log_warn, vha, 0x00be,
3168 "Unable to allocate (%d KB) for FCE.\n",
3173 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3174 ha->fce_mb, &ha->fce_bufs);
3176 ql_log(ql_log_warn, vha, 0x00bf,
3177 "Unable to initialize FCE (%d).\n", rval);
3178 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, tc_dma);
3182 ql_dbg(ql_dbg_init, vha, 0x00c0,
3183 "Allocated (%d KB) for FCE...\n", FCE_SIZE / 1024);
3185 ha->flags.fce_enabled = 1;
3186 ha->fce_dma = tc_dma;
3191 qla2x00_init_eft_trace(scsi_qla_host_t *vha)
3196 struct qla_hw_data *ha = vha->hw;
3198 if (!IS_FWI2_CAPABLE(ha))
3202 ql_dbg(ql_dbg_init, vha, 0x00bd,
3203 "%s: EFT Mem is already allocated.\n",
3208 /* Allocate memory for Extended Trace Buffer. */
3209 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3212 ql_log(ql_log_warn, vha, 0x00c1,
3213 "Unable to allocate (%d KB) for EFT.\n",
3218 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3220 ql_log(ql_log_warn, vha, 0x00c2,
3221 "Unable to initialize EFT (%d).\n", rval);
3222 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, tc_dma);
3226 ql_dbg(ql_dbg_init, vha, 0x00c3,
3227 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3229 ha->eft_dma = tc_dma;
3234 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3236 qla2x00_init_fce_trace(vha);
3237 qla2x00_init_eft_trace(vha);
3241 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3243 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
3244 eft_size, fce_size, mq_size;
3245 struct qla_hw_data *ha = vha->hw;
3246 struct req_que *req = ha->req_q_map[0];
3247 struct rsp_que *rsp = ha->rsp_q_map[0];
3248 struct qla2xxx_fw_dump *fw_dump;
3251 ql_dbg(ql_dbg_init, vha, 0x00bd,
3252 "Firmware dump already allocated.\n");
3257 ha->fw_dump_cap_flags = 0;
3258 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
3259 req_q_size = rsp_q_size = 0;
3261 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3262 fixed_size = sizeof(struct qla2100_fw_dump);
3263 } else if (IS_QLA23XX(ha)) {
3264 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
3265 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
3267 } else if (IS_FWI2_CAPABLE(ha)) {
3269 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
3270 else if (IS_QLA81XX(ha))
3271 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
3272 else if (IS_QLA25XX(ha))
3273 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
3275 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
3277 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
3280 if (!IS_QLA83XX(ha))
3281 mq_size = sizeof(struct qla2xxx_mq_chain);
3283 * Allocate maximum buffer size for all queues - Q0.
3284 * Resizing must be done at end-of-dump processing.
3286 mq_size += (ha->max_req_queues - 1) *
3287 (req->length * sizeof(request_t));
3288 mq_size += (ha->max_rsp_queues - 1) *
3289 (rsp->length * sizeof(response_t));
3291 if (ha->tgt.atio_ring)
3292 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3294 qla2x00_init_fce_trace(vha);
3296 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3297 qla2x00_init_eft_trace(vha);
3299 eft_size = EFT_SIZE;
3302 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3303 struct fwdt *fwdt = ha->fwdt;
3306 for (j = 0; j < 2; j++, fwdt++) {
3307 if (!fwdt->template) {
3308 ql_dbg(ql_dbg_init, vha, 0x00ba,
3309 "-> fwdt%u no template\n", j);
3312 ql_dbg(ql_dbg_init, vha, 0x00fa,
3313 "-> fwdt%u calculating fwdump size...\n", j);
3314 fwdt->dump_size = qla27xx_fwdt_calculate_dump_size(
3315 vha, fwdt->template);
3316 ql_dbg(ql_dbg_init, vha, 0x00fa,
3317 "-> fwdt%u calculated fwdump size = %#lx bytes\n",
3318 j, fwdt->dump_size);
3319 dump_size += fwdt->dump_size;
3322 req_q_size = req->length * sizeof(request_t);
3323 rsp_q_size = rsp->length * sizeof(response_t);
3324 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3325 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size
3327 ha->chain_offset = dump_size;
3328 dump_size += mq_size + fce_size;
3329 if (ha->exchoffld_buf)
3330 dump_size += sizeof(struct qla2xxx_offld_chain) +
3332 if (ha->exlogin_buf)
3333 dump_size += sizeof(struct qla2xxx_offld_chain) +
3337 if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) {
3339 ql_dbg(ql_dbg_init, vha, 0x00c5,
3340 "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n",
3341 __func__, dump_size, ha->fw_dump_len,
3342 ha->fw_dump_alloc_len);
3344 fw_dump = vmalloc(dump_size);
3346 ql_log(ql_log_warn, vha, 0x00c4,
3347 "Unable to allocate (%d KB) for firmware dump.\n",
3350 mutex_lock(&ha->optrom_mutex);
3351 if (ha->fw_dumped) {
3352 memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len);
3354 ha->fw_dump = fw_dump;
3355 ha->fw_dump_alloc_len = dump_size;
3356 ql_dbg(ql_dbg_init, vha, 0x00c5,
3357 "Re-Allocated (%d KB) and save firmware dump.\n",
3362 ha->fw_dump = fw_dump;
3364 ha->fw_dump_len = ha->fw_dump_alloc_len =
3366 ql_dbg(ql_dbg_init, vha, 0x00c5,
3367 "Allocated (%d KB) for firmware dump.\n",
3370 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3371 mutex_unlock(&ha->optrom_mutex);
3375 ha->fw_dump->signature[0] = 'Q';
3376 ha->fw_dump->signature[1] = 'L';
3377 ha->fw_dump->signature[2] = 'G';
3378 ha->fw_dump->signature[3] = 'C';
3379 ha->fw_dump->version = htonl(1);
3381 ha->fw_dump->fixed_size = htonl(fixed_size);
3382 ha->fw_dump->mem_size = htonl(mem_size);
3383 ha->fw_dump->req_q_size = htonl(req_q_size);
3384 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3386 ha->fw_dump->eft_size = htonl(eft_size);
3387 ha->fw_dump->eft_addr_l =
3388 htonl(LSD(ha->eft_dma));
3389 ha->fw_dump->eft_addr_h =
3390 htonl(MSD(ha->eft_dma));
3392 ha->fw_dump->header_size =
3394 (struct qla2xxx_fw_dump, isp));
3396 mutex_unlock(&ha->optrom_mutex);
3402 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3404 #define MPS_MASK 0xe0
3409 if (!IS_QLA81XX(vha->hw))
3412 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3413 if (rval != QLA_SUCCESS) {
3414 ql_log(ql_log_warn, vha, 0x0105,
3415 "Unable to acquire semaphore.\n");
3419 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3420 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3421 if (rval != QLA_SUCCESS) {
3422 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3427 if (dc == (dw & MPS_MASK))
3432 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3433 if (rval != QLA_SUCCESS) {
3434 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3438 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3439 if (rval != QLA_SUCCESS) {
3440 ql_log(ql_log_warn, vha, 0x006d,
3441 "Unable to release semaphore.\n");
3449 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3451 /* Don't try to reallocate the array */
3452 if (req->outstanding_cmds)
3455 if (!IS_FWI2_CAPABLE(ha))
3456 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3458 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3459 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3461 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3464 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3468 if (!req->outstanding_cmds) {
3470 * Try to allocate a minimal size just so we can get through
3473 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
3474 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3478 if (!req->outstanding_cmds) {
3479 ql_log(ql_log_fatal, NULL, 0x0126,
3480 "Failed to allocate memory for "
3481 "outstanding_cmds for req_que %p.\n", req);
3482 req->num_outstanding_cmds = 0;
3483 return QLA_FUNCTION_FAILED;
3490 #define PRINT_FIELD(_field, _flag, _str) { \
3491 if (a0->_field & _flag) {\
3497 len = snprintf(ptr, leftover, "%s", _str); \
3504 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
3507 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
3508 u8 str[STR_LEN], *ptr, p;
3511 memset(str, 0, STR_LEN);
3512 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
3513 ql_dbg(ql_dbg_init, vha, 0x015a,
3514 "SFP MFG Name: %s\n", str);
3516 memset(str, 0, STR_LEN);
3517 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
3518 ql_dbg(ql_dbg_init, vha, 0x015c,
3519 "SFP Part Name: %s\n", str);
3522 memset(str, 0, STR_LEN);
3526 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
3527 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
3528 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
3529 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
3530 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3531 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3532 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3533 ql_dbg(ql_dbg_init, vha, 0x0160,
3534 "SFP Media: %s\n", str);
3537 memset(str, 0, STR_LEN);
3541 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3542 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3543 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3544 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3545 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3546 ql_dbg(ql_dbg_init, vha, 0x0196,
3547 "SFP Link Length: %s\n", str);
3549 memset(str, 0, STR_LEN);
3553 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3554 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3555 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3556 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3557 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3558 ql_dbg(ql_dbg_init, vha, 0x016e,
3559 "SFP FC Link Tech: %s\n", str);
3562 ql_dbg(ql_dbg_init, vha, 0x016f,
3563 "SFP Distant: %d km\n", a0->length_km);
3564 if (a0->length_100m)
3565 ql_dbg(ql_dbg_init, vha, 0x0170,
3566 "SFP Distant: %d m\n", a0->length_100m*100);
3567 if (a0->length_50um_10m)
3568 ql_dbg(ql_dbg_init, vha, 0x0189,
3569 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3570 if (a0->length_62um_10m)
3571 ql_dbg(ql_dbg_init, vha, 0x018a,
3572 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3573 if (a0->length_om4_10m)
3574 ql_dbg(ql_dbg_init, vha, 0x0194,
3575 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3576 if (a0->length_om3_10m)
3577 ql_dbg(ql_dbg_init, vha, 0x0195,
3578 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3584 * QLA_SUCCESS: no action
3585 * QLA_INTERFACE_ERROR: SFP is not there.
3586 * QLA_FUNCTION_FAILED: detected New SFP
3589 qla24xx_detect_sfp(scsi_qla_host_t *vha)
3591 int rc = QLA_SUCCESS;
3592 struct sff_8247_a0 *a;
3593 struct qla_hw_data *ha = vha->hw;
3595 if (!AUTO_DETECT_SFP_SUPPORT(vha))
3598 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3602 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3603 qla2xxx_print_sfp_info(vha);
3605 if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) {
3607 ha->flags.detected_lr_sfp = 1;
3609 if (a->length_km > 5 || a->length_100m > 50)
3610 ha->long_range_distance = LR_DISTANCE_10K;
3612 ha->long_range_distance = LR_DISTANCE_5K;
3614 if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting)
3615 ql_dbg(ql_dbg_async, vha, 0x507b,
3616 "Detected Long Range SFP.\n");
3619 ha->flags.detected_lr_sfp = 0;
3620 if (ha->flags.using_lr_setting)
3621 ql_dbg(ql_dbg_async, vha, 0x5084,
3622 "Detected Short Range SFP.\n");
3625 if (!vha->flags.init_done)
3632 * qla2x00_setup_chip() - Load and start RISC firmware.
3635 * Returns 0 on success.
3638 qla2x00_setup_chip(scsi_qla_host_t *vha)
3641 uint32_t srisc_address = 0;
3642 struct qla_hw_data *ha = vha->hw;
3643 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3644 unsigned long flags;
3645 uint16_t fw_major_version;
3647 if (IS_P3P_TYPE(ha)) {
3648 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3649 if (rval == QLA_SUCCESS) {
3650 qla2x00_stop_firmware(vha);
3651 goto enable_82xx_npiv;
3656 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3657 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3658 spin_lock_irqsave(&ha->hardware_lock, flags);
3659 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
3660 RD_REG_WORD(®->hccr);
3661 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3664 qla81xx_mpi_sync(vha);
3666 /* Load firmware sequences */
3667 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3668 if (rval == QLA_SUCCESS) {
3669 ql_dbg(ql_dbg_init, vha, 0x00c9,
3670 "Verifying Checksum of loaded RISC code.\n");
3672 rval = qla2x00_verify_checksum(vha, srisc_address);
3673 if (rval == QLA_SUCCESS) {
3674 /* Start firmware execution. */
3675 ql_dbg(ql_dbg_init, vha, 0x00ca,
3676 "Starting firmware.\n");
3679 ha->flags.exlogins_enabled = 1;
3681 if (qla_is_exch_offld_enabled(vha))
3682 ha->flags.exchoffld_enabled = 1;
3684 rval = qla2x00_execute_fw(vha, srisc_address);
3685 /* Retrieve firmware information. */
3686 if (rval == QLA_SUCCESS) {
3687 qla24xx_detect_sfp(vha);
3689 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3691 (ha->zio_mode == QLA_ZIO_MODE_6))
3692 qla27xx_set_zio_threshold(vha,
3693 ha->last_zio_threshold);
3695 rval = qla2x00_set_exlogins_buffer(vha);
3696 if (rval != QLA_SUCCESS)
3699 rval = qla2x00_set_exchoffld_buffer(vha);
3700 if (rval != QLA_SUCCESS)
3704 fw_major_version = ha->fw_major_version;
3705 if (IS_P3P_TYPE(ha))
3706 qla82xx_check_md_needed(vha);
3708 rval = qla2x00_get_fw_version(vha);
3709 if (rval != QLA_SUCCESS)
3711 ha->flags.npiv_supported = 0;
3712 if (IS_QLA2XXX_MIDTYPE(ha) &&
3713 (ha->fw_attributes & BIT_2)) {
3714 ha->flags.npiv_supported = 1;
3715 if ((!ha->max_npiv_vports) ||
3716 ((ha->max_npiv_vports + 1) %
3717 MIN_MULTI_ID_FABRIC))
3718 ha->max_npiv_vports =
3719 MIN_MULTI_ID_FABRIC - 1;
3721 qla2x00_get_resource_cnts(vha);
3724 * Allocate the array of outstanding commands
3725 * now that we know the firmware resources.
3727 rval = qla2x00_alloc_outstanding_cmds(ha,
3729 if (rval != QLA_SUCCESS)
3732 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
3733 qla2x00_alloc_offload_mem(vha);
3735 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
3736 qla2x00_alloc_fw_dump(vha);
3742 ql_log(ql_log_fatal, vha, 0x00cd,
3743 "ISP Firmware failed checksum.\n");
3749 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3750 /* Enable proper parity. */
3751 spin_lock_irqsave(&ha->hardware_lock, flags);
3754 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
3756 /* SRAM, Instruction RAM and GP RAM parity */
3757 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
3758 RD_REG_WORD(®->hccr);
3759 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3762 if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
3763 ha->flags.fac_supported = 1;
3764 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
3767 rval = qla81xx_fac_get_sector_size(vha, &size);
3768 if (rval == QLA_SUCCESS) {
3769 ha->flags.fac_supported = 1;
3770 ha->fdt_block_size = size << 2;
3772 ql_log(ql_log_warn, vha, 0x00ce,
3773 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3774 ha->fw_major_version, ha->fw_minor_version,
3775 ha->fw_subminor_version);
3777 if (IS_QLA83XX(ha)) {
3778 ha->flags.fac_supported = 0;
3785 ql_log(ql_log_fatal, vha, 0x00cf,
3786 "Setup chip ****FAILED****.\n");
3793 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3794 * @rsp: response queue
3796 * Beginning of request ring has initialization control block already built
3797 * by nvram config routine.
3799 * Returns 0 on success.
3802 qla2x00_init_response_q_entries(struct rsp_que *rsp)
3807 rsp->ring_ptr = rsp->ring;
3808 rsp->ring_index = 0;
3809 rsp->status_srb = NULL;
3810 pkt = rsp->ring_ptr;
3811 for (cnt = 0; cnt < rsp->length; cnt++) {
3812 pkt->signature = RESPONSE_PROCESSED;
3818 * qla2x00_update_fw_options() - Read and process firmware options.
3821 * Returns 0 on success.
3824 qla2x00_update_fw_options(scsi_qla_host_t *vha)
3826 uint16_t swing, emphasis, tx_sens, rx_sens;
3827 struct qla_hw_data *ha = vha->hw;
3829 memset(ha->fw_options, 0, sizeof(ha->fw_options));
3830 qla2x00_get_fw_options(vha, ha->fw_options);
3832 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3835 /* Serial Link options. */
3836 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3837 "Serial link options.\n");
3838 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3839 ha->fw_seriallink_options, sizeof(ha->fw_seriallink_options));
3841 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3842 if (ha->fw_seriallink_options[3] & BIT_2) {
3843 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3846 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3847 emphasis = (ha->fw_seriallink_options[2] &
3848 (BIT_4 | BIT_3)) >> 3;
3849 tx_sens = ha->fw_seriallink_options[0] &
3850 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3851 rx_sens = (ha->fw_seriallink_options[0] &
3852 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3853 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3854 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3857 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3858 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3859 ha->fw_options[10] |= BIT_5 |
3860 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3861 (tx_sens & (BIT_1 | BIT_0));
3864 swing = (ha->fw_seriallink_options[2] &
3865 (BIT_7 | BIT_6 | BIT_5)) >> 5;
3866 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
3867 tx_sens = ha->fw_seriallink_options[1] &
3868 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3869 rx_sens = (ha->fw_seriallink_options[1] &
3870 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3871 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
3872 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3875 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
3876 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3877 ha->fw_options[11] |= BIT_5 |
3878 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3879 (tx_sens & (BIT_1 | BIT_0));
3883 /* Return command IOCBs without waiting for an ABTS to complete. */
3884 ha->fw_options[3] |= BIT_13;
3887 if (ha->flags.enable_led_scheme)
3888 ha->fw_options[2] |= BIT_12;
3890 /* Detect ISP6312. */
3892 ha->fw_options[2] |= BIT_13;
3894 /* Set Retry FLOGI in case of P2P connection */
3895 if (ha->operating_mode == P2P) {
3896 ha->fw_options[2] |= BIT_3;
3897 ql_dbg(ql_dbg_disc, vha, 0x2100,
3898 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3899 __func__, ha->fw_options[2]);
3902 /* Update firmware options. */
3903 qla2x00_set_fw_options(vha, ha->fw_options);
3907 qla24xx_update_fw_options(scsi_qla_host_t *vha)
3910 struct qla_hw_data *ha = vha->hw;
3912 if (IS_P3P_TYPE(ha))
3915 /* Hold status IOCBs until ABTS response received. */
3917 ha->fw_options[3] |= BIT_12;
3919 /* Set Retry FLOGI in case of P2P connection */
3920 if (ha->operating_mode == P2P) {
3921 ha->fw_options[2] |= BIT_3;
3922 ql_dbg(ql_dbg_disc, vha, 0x2101,
3923 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3924 __func__, ha->fw_options[2]);
3927 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3928 if (ql2xmvasynctoatio &&
3929 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
3930 if (qla_tgt_mode_enabled(vha) ||
3931 qla_dual_mode_enabled(vha))
3932 ha->fw_options[2] |= BIT_11;
3934 ha->fw_options[2] &= ~BIT_11;
3937 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3940 * Tell FW to track each exchange to prevent
3941 * driver from using stale exchange.
3943 if (qla_tgt_mode_enabled(vha) ||
3944 qla_dual_mode_enabled(vha))
3945 ha->fw_options[2] |= BIT_4;
3947 ha->fw_options[2] &= ~BIT_4;
3949 /* Reserve 1/2 of emergency exchanges for ELS.*/
3950 if (qla2xuseresexchforels)
3951 ha->fw_options[2] |= BIT_8;
3953 ha->fw_options[2] &= ~BIT_8;
3956 ql_dbg(ql_dbg_init, vha, 0x00e8,
3957 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3958 __func__, ha->fw_options[1], ha->fw_options[2],
3959 ha->fw_options[3], vha->host->active_mode);
3961 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
3962 qla2x00_set_fw_options(vha, ha->fw_options);
3964 /* Update Serial Link options. */
3965 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
3968 rval = qla2x00_set_serdes_params(vha,
3969 le16_to_cpu(ha->fw_seriallink_options24[1]),
3970 le16_to_cpu(ha->fw_seriallink_options24[2]),
3971 le16_to_cpu(ha->fw_seriallink_options24[3]));
3972 if (rval != QLA_SUCCESS) {
3973 ql_log(ql_log_warn, vha, 0x0104,
3974 "Unable to update Serial Link options (%x).\n", rval);
3979 qla2x00_config_rings(struct scsi_qla_host *vha)
3981 struct qla_hw_data *ha = vha->hw;
3982 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3983 struct req_que *req = ha->req_q_map[0];
3984 struct rsp_que *rsp = ha->rsp_q_map[0];
3986 /* Setup ring parameters in initialization control block. */
3987 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3988 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
3989 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3990 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3991 put_unaligned_le64(req->dma, &ha->init_cb->request_q_address);
3992 put_unaligned_le64(rsp->dma, &ha->init_cb->response_q_address);
3994 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3995 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3996 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3997 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3998 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
4002 qla24xx_config_rings(struct scsi_qla_host *vha)
4004 struct qla_hw_data *ha = vha->hw;
4005 device_reg_t *reg = ISP_QUE_REG(ha, 0);
4006 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
4007 struct qla_msix_entry *msix;
4008 struct init_cb_24xx *icb;
4010 struct req_que *req = ha->req_q_map[0];
4011 struct rsp_que *rsp = ha->rsp_q_map[0];
4013 /* Setup ring parameters in initialization control block. */
4014 icb = (struct init_cb_24xx *)ha->init_cb;
4015 icb->request_q_outpointer = cpu_to_le16(0);
4016 icb->response_q_inpointer = cpu_to_le16(0);
4017 icb->request_q_length = cpu_to_le16(req->length);
4018 icb->response_q_length = cpu_to_le16(rsp->length);
4019 put_unaligned_le64(req->dma, &icb->request_q_address);
4020 put_unaligned_le64(rsp->dma, &icb->response_q_address);
4022 /* Setup ATIO queue dma pointers for target mode */
4023 icb->atio_q_inpointer = cpu_to_le16(0);
4024 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
4025 put_unaligned_le64(ha->tgt.atio_dma, &icb->atio_q_address);
4027 if (IS_SHADOW_REG_CAPABLE(ha))
4028 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
4030 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4032 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
4033 icb->rid = cpu_to_le16(rid);
4034 if (ha->flags.msix_enabled) {
4035 msix = &ha->msix_entries[1];
4036 ql_dbg(ql_dbg_init, vha, 0x0019,
4037 "Registering vector 0x%x for base que.\n",
4039 icb->msix = cpu_to_le16(msix->entry);
4041 /* Use alternate PCI bus number */
4043 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
4044 /* Use alternate PCI devfn */
4046 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
4048 /* Use Disable MSIX Handshake mode for capable adapters */
4049 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
4050 (ha->flags.msix_enabled)) {
4051 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
4052 ha->flags.disable_msix_handshake = 1;
4053 ql_dbg(ql_dbg_init, vha, 0x00fe,
4054 "MSIX Handshake Disable Mode turned on.\n");
4056 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
4058 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
4060 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
4061 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
4062 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
4063 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
4065 WRT_REG_DWORD(®->isp24.req_q_in, 0);
4066 WRT_REG_DWORD(®->isp24.req_q_out, 0);
4067 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
4068 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
4071 qlt_24xx_config_rings(vha);
4073 /* If the user has configured the speed, set it here */
4074 if (ha->set_data_rate) {
4075 ql_dbg(ql_dbg_init, vha, 0x00fd,
4076 "Speed set by user : %s Gbps \n",
4077 qla2x00_get_link_speed_str(ha, ha->set_data_rate));
4078 icb->firmware_options_3 = (ha->set_data_rate << 13);
4082 RD_REG_DWORD(&ioreg->hccr);
4086 * qla2x00_init_rings() - Initializes firmware.
4089 * Beginning of request ring has initialization control block already built
4090 * by nvram config routine.
4092 * Returns 0 on success.
4095 qla2x00_init_rings(scsi_qla_host_t *vha)
4098 unsigned long flags = 0;
4100 struct qla_hw_data *ha = vha->hw;
4101 struct req_que *req;
4102 struct rsp_que *rsp;
4103 struct mid_init_cb_24xx *mid_init_cb =
4104 (struct mid_init_cb_24xx *) ha->init_cb;
4106 spin_lock_irqsave(&ha->hardware_lock, flags);
4108 /* Clear outstanding commands array. */
4109 for (que = 0; que < ha->max_req_queues; que++) {
4110 req = ha->req_q_map[que];
4111 if (!req || !test_bit(que, ha->req_qid_map))
4113 req->out_ptr = (void *)(req->ring + req->length);
4115 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
4116 req->outstanding_cmds[cnt] = NULL;
4118 req->current_outstanding_cmd = 1;
4120 /* Initialize firmware. */
4121 req->ring_ptr = req->ring;
4122 req->ring_index = 0;
4123 req->cnt = req->length;
4126 for (que = 0; que < ha->max_rsp_queues; que++) {
4127 rsp = ha->rsp_q_map[que];
4128 if (!rsp || !test_bit(que, ha->rsp_qid_map))
4130 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
4132 /* Initialize response queue entries */
4134 qlafx00_init_response_q_entries(rsp);
4136 qla2x00_init_response_q_entries(rsp);
4139 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
4140 ha->tgt.atio_ring_index = 0;
4141 /* Initialize ATIO queue entries */
4142 qlt_init_atio_q_entries(vha);
4144 ha->isp_ops->config_rings(vha);
4146 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4148 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
4150 if (IS_QLAFX00(ha)) {
4151 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
4155 /* Update any ISP specific firmware options before initialization. */
4156 ha->isp_ops->update_fw_options(vha);
4158 if (ha->flags.npiv_supported) {
4159 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
4160 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
4161 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
4164 if (IS_FWI2_CAPABLE(ha)) {
4165 mid_init_cb->options = cpu_to_le16(BIT_1);
4166 mid_init_cb->init_cb.execution_throttle =
4167 cpu_to_le16(ha->cur_fw_xcb_count);
4168 ha->flags.dport_enabled =
4169 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
4170 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
4171 (ha->flags.dport_enabled) ? "enabled" : "disabled");
4172 /* FA-WWPN Status */
4173 ha->flags.fawwpn_enabled =
4174 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
4175 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
4176 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
4179 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
4182 ql_log(ql_log_fatal, vha, 0x00d2,
4183 "Init Firmware **** FAILED ****.\n");
4185 ql_dbg(ql_dbg_init, vha, 0x00d3,
4186 "Init Firmware -- success.\n");
4188 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0;
4195 * qla2x00_fw_ready() - Waits for firmware ready.
4198 * Returns 0 on success.
4201 qla2x00_fw_ready(scsi_qla_host_t *vha)
4204 unsigned long wtime, mtime, cs84xx_time;
4205 uint16_t min_wait; /* Minimum wait time if loop is down */
4206 uint16_t wait_time; /* Wait time if loop is coming ready */
4208 struct qla_hw_data *ha = vha->hw;
4210 if (IS_QLAFX00(vha->hw))
4211 return qlafx00_fw_ready(vha);
4215 /* Time to wait for loop down */
4216 if (IS_P3P_TYPE(ha))
4222 * Firmware should take at most one RATOV to login, plus 5 seconds for
4223 * our own processing.
4225 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
4226 wait_time = min_wait;
4229 /* Min wait time if loop down */
4230 mtime = jiffies + (min_wait * HZ);
4232 /* wait time before firmware ready */
4233 wtime = jiffies + (wait_time * HZ);
4235 /* Wait for ISP to finish LIP */
4236 if (!vha->flags.init_done)
4237 ql_log(ql_log_info, vha, 0x801e,
4238 "Waiting for LIP to complete.\n");
4241 memset(state, -1, sizeof(state));
4242 rval = qla2x00_get_firmware_state(vha, state);
4243 if (rval == QLA_SUCCESS) {
4244 if (state[0] < FSTATE_LOSS_OF_SYNC) {
4245 vha->device_flags &= ~DFLG_NO_CABLE;
4247 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
4248 ql_dbg(ql_dbg_taskm, vha, 0x801f,
4249 "fw_state=%x 84xx=%x.\n", state[0],
4251 if ((state[2] & FSTATE_LOGGED_IN) &&
4252 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
4253 ql_dbg(ql_dbg_taskm, vha, 0x8028,
4254 "Sending verify iocb.\n");
4256 cs84xx_time = jiffies;
4257 rval = qla84xx_init_chip(vha);
4258 if (rval != QLA_SUCCESS) {
4261 "Init chip failed.\n");
4265 /* Add time taken to initialize. */
4266 cs84xx_time = jiffies - cs84xx_time;
4267 wtime += cs84xx_time;
4268 mtime += cs84xx_time;
4269 ql_dbg(ql_dbg_taskm, vha, 0x8008,
4270 "Increasing wait time by %ld. "
4271 "New time %ld.\n", cs84xx_time,
4274 } else if (state[0] == FSTATE_READY) {
4275 ql_dbg(ql_dbg_taskm, vha, 0x8037,
4276 "F/W Ready - OK.\n");
4278 qla2x00_get_retry_cnt(vha, &ha->retry_count,
4279 &ha->login_timeout, &ha->r_a_tov);
4285 rval = QLA_FUNCTION_FAILED;
4287 if (atomic_read(&vha->loop_down_timer) &&
4288 state[0] != FSTATE_READY) {
4289 /* Loop down. Timeout on min_wait for states
4290 * other than Wait for Login.
4292 if (time_after_eq(jiffies, mtime)) {
4293 ql_log(ql_log_info, vha, 0x8038,
4294 "Cable is unplugged...\n");
4296 vha->device_flags |= DFLG_NO_CABLE;
4301 /* Mailbox cmd failed. Timeout on min_wait. */
4302 if (time_after_eq(jiffies, mtime) ||
4303 ha->flags.isp82xx_fw_hung)
4307 if (time_after_eq(jiffies, wtime))
4310 /* Delay for a while */
4314 ql_dbg(ql_dbg_taskm, vha, 0x803a,
4315 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
4316 state[1], state[2], state[3], state[4], state[5], jiffies);
4318 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
4319 ql_log(ql_log_warn, vha, 0x803b,
4320 "Firmware ready **** FAILED ****.\n");
4327 * qla2x00_configure_hba
4328 * Setup adapter context.
4331 * ha = adapter state pointer.
4340 qla2x00_configure_hba(scsi_qla_host_t *vha)
4349 char connect_type[22];
4350 struct qla_hw_data *ha = vha->hw;
4351 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4353 unsigned long flags;
4355 /* Get host addresses. */
4356 rval = qla2x00_get_adapter_id(vha,
4357 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
4358 if (rval != QLA_SUCCESS) {
4359 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
4360 IS_CNA_CAPABLE(ha) ||
4361 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
4362 ql_dbg(ql_dbg_disc, vha, 0x2008,
4363 "Loop is in a transition state.\n");
4365 ql_log(ql_log_warn, vha, 0x2009,
4366 "Unable to get host loop ID.\n");
4367 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
4368 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
4369 ql_log(ql_log_warn, vha, 0x1151,
4370 "Doing link init.\n");
4371 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
4374 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4380 ql_log(ql_log_info, vha, 0x200a,
4381 "Cannot get topology - retrying.\n");
4382 return (QLA_FUNCTION_FAILED);
4385 vha->loop_id = loop_id;
4388 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
4389 ha->operating_mode = LOOP;
4394 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
4395 ha->current_topology = ISP_CFG_NL;
4396 strcpy(connect_type, "(Loop)");
4400 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
4401 ha->switch_cap = sw_cap;
4402 ha->current_topology = ISP_CFG_FL;
4403 strcpy(connect_type, "(FL_Port)");
4407 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
4408 ha->operating_mode = P2P;
4409 ha->current_topology = ISP_CFG_N;
4410 strcpy(connect_type, "(N_Port-to-N_Port)");
4414 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
4415 ha->switch_cap = sw_cap;
4416 ha->operating_mode = P2P;
4417 ha->current_topology = ISP_CFG_F;
4418 strcpy(connect_type, "(F_Port)");
4422 ql_dbg(ql_dbg_disc, vha, 0x200f,
4423 "HBA in unknown topology %x, using NL.\n", topo);
4424 ha->current_topology = ISP_CFG_NL;
4425 strcpy(connect_type, "(Loop)");
4429 /* Save Host port and loop ID. */
4430 /* byte order - Big Endian */
4431 id.b.domain = domain;
4435 spin_lock_irqsave(&ha->hardware_lock, flags);
4436 if (!(topo == 2 && ha->flags.n2n_bigger))
4437 qlt_update_host_map(vha, id);
4438 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4440 if (!vha->flags.init_done)
4441 ql_log(ql_log_info, vha, 0x2010,
4442 "Topology - %s, Host Loop address 0x%x.\n",
4443 connect_type, vha->loop_id);
4449 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
4454 uint64_t zero[2] = { 0 };
4455 struct qla_hw_data *ha = vha->hw;
4456 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
4457 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
4459 if (len > sizeof(zero))
4461 if (memcmp(model, &zero, len) != 0) {
4462 memcpy(ha->model_number, model, len);
4463 st = en = ha->model_number;
4466 if (*en != 0x20 && *en != 0x00)
4471 index = (ha->pdev->subsystem_device & 0xff);
4473 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4474 index < QLA_MODEL_NAMES)
4475 strlcpy(ha->model_desc,
4476 qla2x00_model_name[index * 2 + 1],
4477 sizeof(ha->model_desc));
4479 index = (ha->pdev->subsystem_device & 0xff);
4481 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4482 index < QLA_MODEL_NAMES) {
4483 strlcpy(ha->model_number,
4484 qla2x00_model_name[index * 2],
4485 sizeof(ha->model_number));
4486 strlcpy(ha->model_desc,
4487 qla2x00_model_name[index * 2 + 1],
4488 sizeof(ha->model_desc));
4490 strlcpy(ha->model_number, def,
4491 sizeof(ha->model_number));
4494 if (IS_FWI2_CAPABLE(ha))
4495 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
4496 sizeof(ha->model_desc));
4499 /* On sparc systems, obtain port and node WWN from firmware
4502 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4505 struct qla_hw_data *ha = vha->hw;
4506 struct pci_dev *pdev = ha->pdev;
4507 struct device_node *dp = pci_device_to_OF_node(pdev);
4511 val = of_get_property(dp, "port-wwn", &len);
4512 if (val && len >= WWN_SIZE)
4513 memcpy(nv->port_name, val, WWN_SIZE);
4515 val = of_get_property(dp, "node-wwn", &len);
4516 if (val && len >= WWN_SIZE)
4517 memcpy(nv->node_name, val, WWN_SIZE);
4522 * NVRAM configuration for ISP 2xxx
4525 * ha = adapter block pointer.
4528 * initialization control block in response_ring
4529 * host adapters parameters in host adapter block
4535 qla2x00_nvram_config(scsi_qla_host_t *vha)
4540 uint8_t *dptr1, *dptr2;
4541 struct qla_hw_data *ha = vha->hw;
4542 init_cb_t *icb = ha->init_cb;
4543 nvram_t *nv = ha->nvram;
4544 uint8_t *ptr = ha->nvram;
4545 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4549 /* Determine NVRAM starting address. */
4550 ha->nvram_size = sizeof(*nv);
4552 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4553 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
4554 ha->nvram_base = 0x80;
4556 /* Get NVRAM data and calculate checksum. */
4557 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
4558 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4561 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4562 "Contents of NVRAM.\n");
4563 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4564 nv, ha->nvram_size);
4566 /* Bad NVRAM data, set defaults parameters. */
4567 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
4568 nv->nvram_version < 1) {
4569 /* Reset NVRAM data. */
4570 ql_log(ql_log_warn, vha, 0x0064,
4571 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
4572 chksum, nv->id, nv->nvram_version);
4573 ql_log(ql_log_warn, vha, 0x0065,
4575 "functioning (yet invalid -- WWPN) defaults.\n");
4578 * Set default initialization control block.
4580 memset(nv, 0, ha->nvram_size);
4581 nv->parameter_block_version = ICB_VERSION;
4583 if (IS_QLA23XX(ha)) {
4584 nv->firmware_options[0] = BIT_2 | BIT_1;
4585 nv->firmware_options[1] = BIT_7 | BIT_5;
4586 nv->add_firmware_options[0] = BIT_5;
4587 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4588 nv->frame_payload_size = 2048;
4589 nv->special_options[1] = BIT_7;
4590 } else if (IS_QLA2200(ha)) {
4591 nv->firmware_options[0] = BIT_2 | BIT_1;
4592 nv->firmware_options[1] = BIT_7 | BIT_5;
4593 nv->add_firmware_options[0] = BIT_5;
4594 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4595 nv->frame_payload_size = 1024;
4596 } else if (IS_QLA2100(ha)) {
4597 nv->firmware_options[0] = BIT_3 | BIT_1;
4598 nv->firmware_options[1] = BIT_5;
4599 nv->frame_payload_size = 1024;
4602 nv->max_iocb_allocation = cpu_to_le16(256);
4603 nv->execution_throttle = cpu_to_le16(16);
4604 nv->retry_count = 8;
4605 nv->retry_delay = 1;
4607 nv->port_name[0] = 33;
4608 nv->port_name[3] = 224;
4609 nv->port_name[4] = 139;
4611 qla2xxx_nvram_wwn_from_ofw(vha, nv);
4613 nv->login_timeout = 4;
4616 * Set default host adapter parameters
4618 nv->host_p[1] = BIT_2;
4619 nv->reset_delay = 5;
4620 nv->port_down_retry_count = 8;
4621 nv->max_luns_per_target = cpu_to_le16(8);
4622 nv->link_down_timeout = 60;
4627 /* Reset Initialization control block */
4628 memset(icb, 0, ha->init_cb_size);
4631 * Setup driver NVRAM options.
4633 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4634 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4635 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4636 nv->firmware_options[1] &= ~BIT_4;
4638 if (IS_QLA23XX(ha)) {
4639 nv->firmware_options[0] |= BIT_2;
4640 nv->firmware_options[0] &= ~BIT_3;
4641 nv->special_options[0] &= ~BIT_6;
4642 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
4644 if (IS_QLA2300(ha)) {
4645 if (ha->fb_rev == FPM_2310) {
4646 strcpy(ha->model_number, "QLA2310");
4648 strcpy(ha->model_number, "QLA2300");
4651 qla2x00_set_model_info(vha, nv->model_number,
4652 sizeof(nv->model_number), "QLA23xx");
4654 } else if (IS_QLA2200(ha)) {
4655 nv->firmware_options[0] |= BIT_2;
4657 * 'Point-to-point preferred, else loop' is not a safe
4658 * connection mode setting.
4660 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4662 /* Force 'loop preferred, else point-to-point'. */
4663 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4664 nv->add_firmware_options[0] |= BIT_5;
4666 strcpy(ha->model_number, "QLA22xx");
4667 } else /*if (IS_QLA2100(ha))*/ {
4668 strcpy(ha->model_number, "QLA2100");
4672 * Copy over NVRAM RISC parameter block to initialization control block.
4674 dptr1 = (uint8_t *)icb;
4675 dptr2 = (uint8_t *)&nv->parameter_block_version;
4676 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4678 *dptr1++ = *dptr2++;
4680 /* Copy 2nd half. */
4681 dptr1 = (uint8_t *)icb->add_firmware_options;
4682 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4684 *dptr1++ = *dptr2++;
4685 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
4686 /* Use alternate WWN? */
4687 if (nv->host_p[1] & BIT_7) {
4688 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4689 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4692 /* Prepare nodename */
4693 if ((icb->firmware_options[1] & BIT_6) == 0) {
4695 * Firmware will apply the following mask if the nodename was
4698 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4699 icb->node_name[0] &= 0xF0;
4703 * Set host adapter parameters.
4707 * BIT_7 in the host-parameters section allows for modification to
4708 * internal driver logging.
4710 if (nv->host_p[0] & BIT_7)
4711 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
4712 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4713 /* Always load RISC code on non ISP2[12]00 chips. */
4714 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4715 ha->flags.disable_risc_code_load = 0;
4716 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4717 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4718 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
4719 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
4720 ha->flags.disable_serdes = 0;
4722 ha->operating_mode =
4723 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4725 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4726 sizeof(ha->fw_seriallink_options));
4728 /* save HBA serial number */
4729 ha->serial0 = icb->port_name[5];
4730 ha->serial1 = icb->port_name[6];
4731 ha->serial2 = icb->port_name[7];
4732 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4733 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4735 icb->execution_throttle = cpu_to_le16(0xFFFF);
4737 ha->retry_count = nv->retry_count;
4739 /* Set minimum login_timeout to 4 seconds. */
4740 if (nv->login_timeout != ql2xlogintimeout)
4741 nv->login_timeout = ql2xlogintimeout;
4742 if (nv->login_timeout < 4)
4743 nv->login_timeout = 4;
4744 ha->login_timeout = nv->login_timeout;
4746 /* Set minimum RATOV to 100 tenths of a second. */
4749 ha->loop_reset_delay = nv->reset_delay;
4751 /* Link Down Timeout = 0:
4753 * When Port Down timer expires we will start returning
4754 * I/O's to OS with "DID_NO_CONNECT".
4756 * Link Down Timeout != 0:
4758 * The driver waits for the link to come up after link down
4759 * before returning I/Os to OS with "DID_NO_CONNECT".
4761 if (nv->link_down_timeout == 0) {
4762 ha->loop_down_abort_time =
4763 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4765 ha->link_down_timeout = nv->link_down_timeout;
4766 ha->loop_down_abort_time =
4767 (LOOP_DOWN_TIME - ha->link_down_timeout);
4771 * Need enough time to try and get the port back.
4773 ha->port_down_retry_count = nv->port_down_retry_count;
4774 if (qlport_down_retry)
4775 ha->port_down_retry_count = qlport_down_retry;
4776 /* Set login_retry_count */
4777 ha->login_retry_count = nv->retry_count;
4778 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4779 ha->port_down_retry_count > 3)
4780 ha->login_retry_count = ha->port_down_retry_count;
4781 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4782 ha->login_retry_count = ha->port_down_retry_count;
4783 if (ql2xloginretrycount)
4784 ha->login_retry_count = ql2xloginretrycount;
4786 icb->lun_enables = cpu_to_le16(0);
4787 icb->command_resource_count = 0;
4788 icb->immediate_notify_resource_count = 0;
4789 icb->timeout = cpu_to_le16(0);
4791 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4793 icb->firmware_options[0] &= ~BIT_3;
4794 icb->add_firmware_options[0] &=
4795 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4796 icb->add_firmware_options[0] |= BIT_2;
4797 icb->response_accumulation_timer = 3;
4798 icb->interrupt_delay_timer = 5;
4800 vha->flags.process_response_queue = 1;
4803 if (!vha->flags.init_done) {
4804 ha->zio_mode = icb->add_firmware_options[0] &
4805 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4806 ha->zio_timer = icb->interrupt_delay_timer ?
4807 icb->interrupt_delay_timer : 2;
4809 icb->add_firmware_options[0] &=
4810 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4811 vha->flags.process_response_queue = 0;
4812 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4813 ha->zio_mode = QLA_ZIO_MODE_6;
4815 ql_log(ql_log_info, vha, 0x0068,
4816 "ZIO mode %d enabled; timer delay (%d us).\n",
4817 ha->zio_mode, ha->zio_timer * 100);
4819 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4820 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
4821 vha->flags.process_response_queue = 1;
4826 ql_log(ql_log_warn, vha, 0x0069,
4827 "NVRAM configuration failed.\n");
4833 qla2x00_rport_del(void *data)
4835 fc_port_t *fcport = data;
4836 struct fc_rport *rport;
4837 unsigned long flags;
4839 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
4840 rport = fcport->drport ? fcport->drport : fcport->rport;
4841 fcport->drport = NULL;
4842 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
4844 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4845 "%s %8phN. rport %p roles %x\n",
4846 __func__, fcport->port_name, rport,
4849 fc_remote_port_delete(rport);
4853 void qla2x00_set_fcport_state(fc_port_t *fcport, int state)
4857 old_state = atomic_read(&fcport->state);
4858 atomic_set(&fcport->state, state);
4860 /* Don't print state transitions during initial allocation of fcport */
4861 if (old_state && old_state != state) {
4862 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
4863 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
4864 fcport->port_name, port_state_str[old_state],
4865 port_state_str[state], fcport->d_id.b.domain,
4866 fcport->d_id.b.area, fcport->d_id.b.al_pa);
4871 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4873 * @flags: allocation flags
4875 * Returns a pointer to the allocated fcport, or NULL, if none available.
4878 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
4882 fcport = kzalloc(sizeof(fc_port_t), flags);
4886 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
4887 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
4889 if (!fcport->ct_desc.ct_sns) {
4890 ql_log(ql_log_warn, vha, 0xd049,
4891 "Failed to allocate ct_sns request.\n");
4896 /* Setup fcport template structure. */
4898 fcport->port_type = FCT_UNKNOWN;
4899 fcport->loop_id = FC_NO_LOOP_ID;
4900 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
4901 fcport->supported_classes = FC_COS_UNSPECIFIED;
4902 fcport->fp_speed = PORT_SPEED_UNKNOWN;
4904 fcport->disc_state = DSC_DELETED;
4905 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4906 fcport->deleted = QLA_SESS_DELETED;
4907 fcport->login_retry = vha->hw->login_retry_count;
4908 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
4909 fcport->logout_on_delete = 1;
4911 if (!fcport->ct_desc.ct_sns) {
4912 ql_log(ql_log_warn, vha, 0xd049,
4913 "Failed to allocate ct_sns request.\n");
4918 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
4919 INIT_WORK(&fcport->free_work, qlt_free_session_done);
4920 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
4921 INIT_LIST_HEAD(&fcport->gnl_entry);
4922 INIT_LIST_HEAD(&fcport->list);
4928 qla2x00_free_fcport(fc_port_t *fcport)
4930 if (fcport->ct_desc.ct_sns) {
4931 dma_free_coherent(&fcport->vha->hw->pdev->dev,
4932 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
4933 fcport->ct_desc.ct_sns_dma);
4935 fcport->ct_desc.ct_sns = NULL;
4937 list_del(&fcport->list);
4938 qla2x00_clear_loop_id(fcport);
4943 * qla2x00_configure_loop
4944 * Updates Fibre Channel Device Database with what is actually on loop.
4947 * ha = adapter block pointer.
4952 * 2 = database was full and device was not configured.
4955 qla2x00_configure_loop(scsi_qla_host_t *vha)
4958 unsigned long flags, save_flags;
4959 struct qla_hw_data *ha = vha->hw;
4963 /* Get Initiator ID */
4964 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4965 rval = qla2x00_configure_hba(vha);
4966 if (rval != QLA_SUCCESS) {
4967 ql_dbg(ql_dbg_disc, vha, 0x2013,
4968 "Unable to configure HBA.\n");
4973 save_flags = flags = vha->dpc_flags;
4974 ql_dbg(ql_dbg_disc, vha, 0x2014,
4975 "Configure loop -- dpc flags = 0x%lx.\n", flags);
4978 * If we have both an RSCN and PORT UPDATE pending then handle them
4979 * both at the same time.
4981 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4982 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
4984 qla2x00_get_data_rate(vha);
4986 /* Determine what we need to do */
4987 if (ha->current_topology == ISP_CFG_FL &&
4988 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4990 set_bit(RSCN_UPDATE, &flags);
4992 } else if (ha->current_topology == ISP_CFG_F &&
4993 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4995 set_bit(RSCN_UPDATE, &flags);
4996 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4998 } else if (ha->current_topology == ISP_CFG_NL ||
4999 ha->current_topology == ISP_CFG_N) {
5000 clear_bit(RSCN_UPDATE, &flags);
5001 set_bit(LOCAL_LOOP_UPDATE, &flags);
5002 } else if (!vha->flags.online ||
5003 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
5004 set_bit(RSCN_UPDATE, &flags);
5005 set_bit(LOCAL_LOOP_UPDATE, &flags);
5008 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
5009 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5010 ql_dbg(ql_dbg_disc, vha, 0x2015,
5011 "Loop resync needed, failing.\n");
5012 rval = QLA_FUNCTION_FAILED;
5014 rval = qla2x00_configure_local_loop(vha);
5017 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
5018 if (LOOP_TRANSITION(vha)) {
5019 ql_dbg(ql_dbg_disc, vha, 0x2099,
5020 "Needs RSCN update and loop transition.\n");
5021 rval = QLA_FUNCTION_FAILED;
5024 rval = qla2x00_configure_fabric(vha);
5027 if (rval == QLA_SUCCESS) {
5028 if (atomic_read(&vha->loop_down_timer) ||
5029 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5030 rval = QLA_FUNCTION_FAILED;
5032 atomic_set(&vha->loop_state, LOOP_READY);
5033 ql_dbg(ql_dbg_disc, vha, 0x2069,
5035 ha->flags.fw_init_done = 1;
5038 * Process any ATIO queue entries that came in
5039 * while we weren't online.
5041 if (qla_tgt_mode_enabled(vha) ||
5042 qla_dual_mode_enabled(vha)) {
5043 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
5044 qlt_24xx_process_atio_queue(vha, 0);
5045 spin_unlock_irqrestore(&ha->tgt.atio_lock,
5052 ql_dbg(ql_dbg_disc, vha, 0x206a,
5053 "%s *** FAILED ***.\n", __func__);
5055 ql_dbg(ql_dbg_disc, vha, 0x206b,
5056 "%s: exiting normally.\n", __func__);
5059 /* Restore state if a resync event occurred during processing */
5060 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5061 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
5062 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5063 if (test_bit(RSCN_UPDATE, &save_flags)) {
5064 set_bit(RSCN_UPDATE, &vha->dpc_flags);
5072 * qla2x00_configure_local_loop
5073 * Updates Fibre Channel Device Database with local loop devices.
5076 * ha = adapter block pointer.
5082 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
5087 fc_port_t *fcport, *new_fcport;
5091 struct gid_list_info *gid;
5093 uint8_t domain, area, al_pa;
5094 struct qla_hw_data *ha = vha->hw;
5095 unsigned long flags;
5097 /* Inititae N2N login. */
5099 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) {
5103 memset(ha->init_cb, 0, ha->init_cb_size);
5104 sz = min_t(int, sizeof(struct els_plogi_payload),
5106 rval = qla24xx_get_port_login_templ(vha,
5107 ha->init_cb_dma, (void *)ha->init_cb, sz);
5108 if (rval == QLA_SUCCESS) {
5109 bp = (uint32_t *)ha->init_cb;
5110 for (i = 0; i < sz/4 ; i++, bp++)
5111 *bp = cpu_to_be32(*bp);
5113 memcpy(&ha->plogi_els_payld.data,
5114 (void *)ha->init_cb,
5115 sizeof(ha->plogi_els_payld.data));
5117 ql_dbg(ql_dbg_init, vha, 0x00d1,
5118 "PLOGI ELS param read fail.\n");
5123 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5124 if (fcport->n2n_flag) {
5125 qla24xx_fcport_handle_login(vha, fcport);
5130 spin_lock_irqsave(&vha->work_lock, flags);
5131 vha->scan.scan_retry++;
5132 spin_unlock_irqrestore(&vha->work_lock, flags);
5134 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5135 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5136 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5142 entries = MAX_FIBRE_DEVICES_LOOP;
5144 /* Get list of logged in devices. */
5145 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
5146 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
5148 if (rval != QLA_SUCCESS)
5149 goto cleanup_allocation;
5151 ql_dbg(ql_dbg_disc, vha, 0x2011,
5152 "Entries in ID list (%d).\n", entries);
5153 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
5154 ha->gid_list, entries * sizeof(*ha->gid_list));
5157 spin_lock_irqsave(&vha->work_lock, flags);
5158 vha->scan.scan_retry++;
5159 spin_unlock_irqrestore(&vha->work_lock, flags);
5161 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5162 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5163 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5166 vha->scan.scan_retry = 0;
5169 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5170 fcport->scan_state = QLA_FCPORT_SCAN;
5173 /* Allocate temporary fcport for any new fcports discovered. */
5174 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5175 if (new_fcport == NULL) {
5176 ql_log(ql_log_warn, vha, 0x2012,
5177 "Memory allocation failed for fcport.\n");
5178 rval = QLA_MEMORY_ALLOC_FAILED;
5179 goto cleanup_allocation;
5181 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5183 /* Add devices to port list. */
5185 for (index = 0; index < entries; index++) {
5186 domain = gid->domain;
5189 if (IS_QLA2100(ha) || IS_QLA2200(ha))
5190 loop_id = gid->loop_id_2100;
5192 loop_id = le16_to_cpu(gid->loop_id);
5193 gid = (void *)gid + ha->gid_list_info_size;
5195 /* Bypass reserved domain fields. */
5196 if ((domain & 0xf0) == 0xf0)
5199 /* Bypass if not same domain and area of adapter. */
5200 if (area && domain && ((area != vha->d_id.b.area) ||
5201 (domain != vha->d_id.b.domain)) &&
5202 (ha->current_topology == ISP_CFG_NL))
5206 /* Bypass invalid local loop ID. */
5207 if (loop_id > LAST_LOCAL_LOOP_ID)
5210 memset(new_fcport->port_name, 0, WWN_SIZE);
5212 /* Fill in member data. */
5213 new_fcport->d_id.b.domain = domain;
5214 new_fcport->d_id.b.area = area;
5215 new_fcport->d_id.b.al_pa = al_pa;
5216 new_fcport->loop_id = loop_id;
5217 new_fcport->scan_state = QLA_FCPORT_FOUND;
5219 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
5220 if (rval2 != QLA_SUCCESS) {
5221 ql_dbg(ql_dbg_disc, vha, 0x2097,
5222 "Failed to retrieve fcport information "
5223 "-- get_port_database=%x, loop_id=0x%04x.\n",
5224 rval2, new_fcport->loop_id);
5225 /* Skip retry if N2N */
5226 if (ha->current_topology != ISP_CFG_N) {
5227 ql_dbg(ql_dbg_disc, vha, 0x2105,
5228 "Scheduling resync.\n");
5229 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5234 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5235 /* Check for matching device in port list. */
5238 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5239 if (memcmp(new_fcport->port_name, fcport->port_name,
5243 fcport->flags &= ~FCF_FABRIC_DEVICE;
5244 fcport->loop_id = new_fcport->loop_id;
5245 fcport->port_type = new_fcport->port_type;
5246 fcport->d_id.b24 = new_fcport->d_id.b24;
5247 memcpy(fcport->node_name, new_fcport->node_name,
5249 fcport->scan_state = QLA_FCPORT_FOUND;
5250 if (fcport->login_retry == 0) {
5251 fcport->login_retry = vha->hw->login_retry_count;
5252 ql_dbg(ql_dbg_disc, vha, 0x2135,
5253 "Port login retry %8phN, lid 0x%04x retry cnt=%d.\n",
5254 fcport->port_name, fcport->loop_id,
5255 fcport->login_retry);
5262 /* New device, add to fcports list. */
5263 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5265 /* Allocate a new replacement fcport. */
5266 fcport = new_fcport;
5268 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5270 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5272 if (new_fcport == NULL) {
5273 ql_log(ql_log_warn, vha, 0xd031,
5274 "Failed to allocate memory for fcport.\n");
5275 rval = QLA_MEMORY_ALLOC_FAILED;
5276 goto cleanup_allocation;
5278 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5279 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5282 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5284 /* Base iIDMA settings on HBA port speed. */
5285 fcport->fp_speed = ha->link_data_rate;
5290 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5291 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5294 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5295 if ((qla_dual_mode_enabled(vha) ||
5296 qla_ini_mode_enabled(vha)) &&
5297 atomic_read(&fcport->state) == FCS_ONLINE) {
5298 qla2x00_mark_device_lost(vha, fcport,
5299 ql2xplogiabsentdevice, 0);
5300 if (fcport->loop_id != FC_NO_LOOP_ID &&
5301 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5302 fcport->port_type != FCT_INITIATOR &&
5303 fcport->port_type != FCT_BROADCAST) {
5304 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5305 "%s %d %8phC post del sess\n",
5309 qlt_schedule_sess_for_deletion(fcport);
5315 if (fcport->scan_state == QLA_FCPORT_FOUND)
5316 qla24xx_fcport_handle_login(vha, fcport);
5322 if (rval != QLA_SUCCESS) {
5323 ql_dbg(ql_dbg_disc, vha, 0x2098,
5324 "Configure local loop error exit: rval=%x.\n", rval);
5331 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5334 uint16_t mb[MAILBOX_REGISTER_COUNT];
5335 struct qla_hw_data *ha = vha->hw;
5337 if (!IS_IIDMA_CAPABLE(ha))
5340 if (atomic_read(&fcport->state) != FCS_ONLINE)
5343 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
5344 fcport->fp_speed > ha->link_data_rate ||
5345 !ha->flags.gpsc_supported)
5348 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
5350 if (rval != QLA_SUCCESS) {
5351 ql_dbg(ql_dbg_disc, vha, 0x2004,
5352 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5353 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
5355 ql_dbg(ql_dbg_disc, vha, 0x2005,
5356 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5357 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
5358 fcport->fp_speed, fcport->port_name);
5362 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5364 qla2x00_iidma_fcport(vha, fcport);
5365 qla24xx_update_fcport_fcp_prio(vha, fcport);
5368 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5370 struct qla_work_evt *e;
5372 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
5374 return QLA_FUNCTION_FAILED;
5376 e->u.fcport.fcport = fcport;
5377 return qla2x00_post_work(vha, e);
5380 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5382 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
5384 struct fc_rport_identifiers rport_ids;
5385 struct fc_rport *rport;
5386 unsigned long flags;
5388 if (atomic_read(&fcport->state) == FCS_ONLINE)
5391 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5393 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5394 rport_ids.port_name = wwn_to_u64(fcport->port_name);
5395 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5396 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5397 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5398 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
5400 ql_log(ql_log_warn, vha, 0x2006,
5401 "Unable to allocate fc remote port.\n");
5405 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5406 *((fc_port_t **)rport->dd_data) = fcport;
5407 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5409 rport->supported_classes = fcport->supported_classes;
5411 rport_ids.roles = FC_PORT_ROLE_UNKNOWN;
5412 if (fcport->port_type == FCT_INITIATOR)
5413 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
5414 if (fcport->port_type == FCT_TARGET)
5415 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
5416 if (fcport->port_type & FCT_NVME_INITIATOR)
5417 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
5418 if (fcport->port_type & FCT_NVME_TARGET)
5419 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
5420 if (fcport->port_type & FCT_NVME_DISCOVERY)
5421 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
5423 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5424 "%s %8phN. rport %p is %s mode\n",
5425 __func__, fcport->port_name, rport,
5426 (fcport->port_type == FCT_TARGET) ? "tgt" :
5427 ((fcport->port_type & FCT_NVME) ? "nvme" : "ini"));
5429 fc_remote_port_rolechg(rport, rport_ids.roles);
5433 * qla2x00_update_fcport
5434 * Updates device on list.
5437 * ha = adapter block pointer.
5438 * fcport = port structure pointer.
5448 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5450 if (IS_SW_RESV_ADDR(fcport->d_id))
5453 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
5454 __func__, fcport->port_name);
5456 qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT);
5457 fcport->login_retry = vha->hw->login_retry_count;
5458 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5459 fcport->deleted = 0;
5460 fcport->logout_on_delete = 1;
5461 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
5463 switch (vha->hw->current_topology) {
5466 fcport->keep_nport_handle = 1;
5472 qla2x00_iidma_fcport(vha, fcport);
5474 if (NVME_TARGET(vha->hw, fcport)) {
5475 qla_nvme_register_remote(vha, fcport);
5476 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
5477 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5481 qla24xx_update_fcport_fcp_prio(vha, fcport);
5483 switch (vha->host->active_mode) {
5484 case MODE_INITIATOR:
5485 qla2x00_reg_remote_port(vha, fcport);
5488 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5489 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5490 !vha->vha_tgt.qla_tgt->tgt_stopped)
5491 qlt_fc_port_added(vha, fcport);
5494 qla2x00_reg_remote_port(vha, fcport);
5495 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5496 !vha->vha_tgt.qla_tgt->tgt_stopped)
5497 qlt_fc_port_added(vha, fcport);
5503 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
5504 if (fcport->id_changed) {
5505 fcport->id_changed = 0;
5506 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5507 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5508 __func__, __LINE__, fcport->port_name,
5510 qla24xx_post_gfpnid_work(vha, fcport);
5512 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5513 "%s %d %8phC post gpsc fcp_cnt %d\n",
5514 __func__, __LINE__, fcport->port_name,
5516 qla24xx_post_gpsc_work(vha, fcport);
5520 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
5523 void qla_register_fcport_fn(struct work_struct *work)
5525 fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
5526 u32 rscn_gen = fcport->rscn_gen;
5529 if (IS_SW_RESV_ADDR(fcport->d_id))
5532 qla2x00_update_fcport(fcport->vha, fcport);
5534 if (rscn_gen != fcport->rscn_gen) {
5535 /* RSCN(s) came in while registration */
5536 switch (fcport->next_disc_state) {
5537 case DSC_DELETE_PEND:
5538 qlt_schedule_sess_for_deletion(fcport);
5541 data[0] = data[1] = 0;
5542 qla2x00_post_async_adisc_work(fcport->vha, fcport,
5552 * qla2x00_configure_fabric
5553 * Setup SNS devices with loop ID's.
5556 * ha = adapter block pointer.
5563 qla2x00_configure_fabric(scsi_qla_host_t *vha)
5567 uint16_t mb[MAILBOX_REGISTER_COUNT];
5569 LIST_HEAD(new_fcports);
5570 struct qla_hw_data *ha = vha->hw;
5573 /* If FL port exists, then SNS is present */
5574 if (IS_FWI2_CAPABLE(ha))
5575 loop_id = NPH_F_PORT;
5577 loop_id = SNS_FL_PORT;
5578 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
5579 if (rval != QLA_SUCCESS) {
5580 ql_dbg(ql_dbg_disc, vha, 0x20a0,
5581 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5583 vha->device_flags &= ~SWITCH_FOUND;
5584 return (QLA_SUCCESS);
5586 vha->device_flags |= SWITCH_FOUND;
5589 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
5590 rval = qla2x00_send_change_request(vha, 0x3, 0);
5591 if (rval != QLA_SUCCESS)
5592 ql_log(ql_log_warn, vha, 0x121,
5593 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5599 qla2x00_mgmt_svr_login(vha);
5602 if (ql2xfdmienable &&
5603 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5604 qla2x00_fdmi_register(vha);
5606 /* Ensure we are logged into the SNS. */
5607 loop_id = NPH_SNS_LID(ha);
5608 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5609 0xfc, mb, BIT_1|BIT_0);
5610 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5611 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5612 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5613 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
5614 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5617 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5618 if (qla2x00_rft_id(vha)) {
5620 ql_dbg(ql_dbg_disc, vha, 0x20a2,
5621 "Register FC-4 TYPE failed.\n");
5622 if (test_bit(LOOP_RESYNC_NEEDED,
5626 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
5628 ql_dbg(ql_dbg_disc, vha, 0x209a,
5629 "Register FC-4 Features failed.\n");
5630 if (test_bit(LOOP_RESYNC_NEEDED,
5634 if (vha->flags.nvme_enabled) {
5635 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5636 ql_dbg(ql_dbg_disc, vha, 0x2049,
5637 "Register NVME FC Type Features failed.\n");
5640 if (qla2x00_rnn_id(vha)) {
5642 ql_dbg(ql_dbg_disc, vha, 0x2104,
5643 "Register Node Name failed.\n");
5644 if (test_bit(LOOP_RESYNC_NEEDED,
5647 } else if (qla2x00_rsnn_nn(vha)) {
5649 ql_dbg(ql_dbg_disc, vha, 0x209b,
5650 "Register Symbolic Node Name failed.\n");
5651 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5657 /* Mark the time right before querying FW for connected ports.
5658 * This process is long, asynchronous and by the time it's done,
5659 * collected information might not be accurate anymore. E.g.
5660 * disconnected port might have re-connected and a brand new
5661 * session has been created. In this case session's generation
5662 * will be newer than discovery_gen. */
5663 qlt_do_generation_tick(vha, &discovery_gen);
5665 if (USE_ASYNC_SCAN(ha)) {
5666 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
5669 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5671 list_for_each_entry(fcport, &vha->vp_fcports, list)
5672 fcport->scan_state = QLA_FCPORT_SCAN;
5674 rval = qla2x00_find_all_fabric_devs(vha);
5676 if (rval != QLA_SUCCESS)
5680 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5681 qla_nvme_register_hba(vha);
5684 ql_dbg(ql_dbg_disc, vha, 0x2068,
5685 "Configure fabric error exit rval=%d.\n", rval);
5691 * qla2x00_find_all_fabric_devs
5694 * ha = adapter block pointer.
5695 * dev = database device entry pointer.
5704 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
5708 fc_port_t *fcport, *new_fcport;
5713 int first_dev, last_dev;
5714 port_id_t wrap = {}, nxt_d_id;
5715 struct qla_hw_data *ha = vha->hw;
5716 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5717 unsigned long flags;
5721 /* Try GID_PT to get device list, else GAN. */
5723 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
5728 ql_dbg(ql_dbg_disc, vha, 0x209c,
5729 "GID_PT allocations failed, fallback on GA_NXT.\n");
5731 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
5732 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
5734 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5736 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
5738 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5740 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
5742 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5744 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5746 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5750 /* If other queries succeeded probe for FC-4 type */
5752 qla2x00_gff_id(vha, swl);
5753 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5759 /* Allocate temporary fcport for any new fcports discovered. */
5760 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5761 if (new_fcport == NULL) {
5762 ql_log(ql_log_warn, vha, 0x209d,
5763 "Failed to allocate memory for fcport.\n");
5764 return (QLA_MEMORY_ALLOC_FAILED);
5766 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5767 /* Set start port ID scan at adapter ID. */
5771 /* Starting free loop ID. */
5772 loop_id = ha->min_external_loopid;
5773 for (; loop_id <= ha->max_loop_id; loop_id++) {
5774 if (qla2x00_is_reserved_id(vha, loop_id))
5777 if (ha->current_topology == ISP_CFG_FL &&
5778 (atomic_read(&vha->loop_down_timer) ||
5779 LOOP_TRANSITION(vha))) {
5780 atomic_set(&vha->loop_down_timer, 0);
5781 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5782 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5788 wrap.b24 = new_fcport->d_id.b24;
5790 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
5791 memcpy(new_fcport->node_name,
5792 swl[swl_idx].node_name, WWN_SIZE);
5793 memcpy(new_fcport->port_name,
5794 swl[swl_idx].port_name, WWN_SIZE);
5795 memcpy(new_fcport->fabric_port_name,
5796 swl[swl_idx].fabric_port_name, WWN_SIZE);
5797 new_fcport->fp_speed = swl[swl_idx].fp_speed;
5798 new_fcport->fc4_type = swl[swl_idx].fc4_type;
5800 new_fcport->nvme_flag = 0;
5801 if (vha->flags.nvme_enabled &&
5802 swl[swl_idx].fc4_type & FS_FC4TYPE_NVME) {
5803 ql_log(ql_log_info, vha, 0x2131,
5804 "FOUND: NVME port %8phC as FC Type 28h\n",
5805 new_fcport->port_name);
5808 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5814 /* Send GA_NXT to the switch */
5815 rval = qla2x00_ga_nxt(vha, new_fcport);
5816 if (rval != QLA_SUCCESS) {
5817 ql_log(ql_log_warn, vha, 0x209e,
5818 "SNS scan failed -- assuming "
5819 "zero-entry result.\n");
5825 /* If wrap on switch device list, exit. */
5827 wrap.b24 = new_fcport->d_id.b24;
5829 } else if (new_fcport->d_id.b24 == wrap.b24) {
5830 ql_dbg(ql_dbg_disc, vha, 0x209f,
5831 "Device wrap (%02x%02x%02x).\n",
5832 new_fcport->d_id.b.domain,
5833 new_fcport->d_id.b.area,
5834 new_fcport->d_id.b.al_pa);
5838 /* Bypass if same physical adapter. */
5839 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
5842 /* Bypass virtual ports of the same host. */
5843 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
5846 /* Bypass if same domain and area of adapter. */
5847 if (((new_fcport->d_id.b24 & 0xffff00) ==
5848 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
5852 /* Bypass reserved domain fields. */
5853 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
5856 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5857 if (ql2xgffidenable &&
5858 (!(new_fcport->fc4_type & FS_FC4TYPE_FCP) &&
5859 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
5862 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5864 /* Locate matching device in database. */
5866 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5867 if (memcmp(new_fcport->port_name, fcport->port_name,
5871 fcport->scan_state = QLA_FCPORT_FOUND;
5875 /* Update port state. */
5876 memcpy(fcport->fabric_port_name,
5877 new_fcport->fabric_port_name, WWN_SIZE);
5878 fcport->fp_speed = new_fcport->fp_speed;
5881 * If address the same and state FCS_ONLINE
5882 * (or in target mode), nothing changed.
5884 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
5885 (atomic_read(&fcport->state) == FCS_ONLINE ||
5886 (vha->host->active_mode == MODE_TARGET))) {
5891 * If device was not a fabric device before.
5893 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5894 fcport->d_id.b24 = new_fcport->d_id.b24;
5895 qla2x00_clear_loop_id(fcport);
5896 fcport->flags |= (FCF_FABRIC_DEVICE |
5902 * Port ID changed or device was marked to be updated;
5903 * Log it out if still logged in and mark it for
5906 if (qla_tgt_mode_enabled(base_vha)) {
5907 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5908 "port changed FC ID, %8phC"
5909 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5911 fcport->d_id.b.domain,
5912 fcport->d_id.b.area,
5913 fcport->d_id.b.al_pa,
5915 new_fcport->d_id.b.domain,
5916 new_fcport->d_id.b.area,
5917 new_fcport->d_id.b.al_pa);
5918 fcport->d_id.b24 = new_fcport->d_id.b24;
5922 fcport->d_id.b24 = new_fcport->d_id.b24;
5923 fcport->flags |= FCF_LOGIN_NEEDED;
5927 if (NVME_TARGET(vha->hw, fcport)) {
5928 if (fcport->disc_state == DSC_DELETE_PEND) {
5929 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
5930 vha->fcport_count--;
5931 fcport->login_succ = 0;
5936 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5939 /* If device was not in our fcports list, then add it. */
5940 new_fcport->scan_state = QLA_FCPORT_FOUND;
5941 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5943 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5946 /* Allocate a new replacement fcport. */
5947 nxt_d_id.b24 = new_fcport->d_id.b24;
5948 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5949 if (new_fcport == NULL) {
5950 ql_log(ql_log_warn, vha, 0xd032,
5951 "Memory allocation failed for fcport.\n");
5952 return (QLA_MEMORY_ALLOC_FAILED);
5954 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5955 new_fcport->d_id.b24 = nxt_d_id.b24;
5958 qla2x00_free_fcport(new_fcport);
5961 * Logout all previous fabric dev marked lost, except FCP2 devices.
5963 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5964 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5967 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
5970 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5971 if ((qla_dual_mode_enabled(vha) ||
5972 qla_ini_mode_enabled(vha)) &&
5973 atomic_read(&fcport->state) == FCS_ONLINE) {
5974 qla2x00_mark_device_lost(vha, fcport,
5975 ql2xplogiabsentdevice, 0);
5976 if (fcport->loop_id != FC_NO_LOOP_ID &&
5977 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5978 fcport->port_type != FCT_INITIATOR &&
5979 fcport->port_type != FCT_BROADCAST) {
5980 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5981 "%s %d %8phC post del sess\n",
5984 qlt_schedule_sess_for_deletion(fcport);
5990 if (fcport->scan_state == QLA_FCPORT_FOUND &&
5991 (fcport->flags & FCF_LOGIN_NEEDED) != 0)
5992 qla24xx_fcport_handle_login(vha, fcport);
5997 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
5999 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
6001 int loop_id = FC_NO_LOOP_ID;
6002 int lid = NPH_MGMT_SERVER - vha->vp_idx;
6003 unsigned long flags;
6004 struct qla_hw_data *ha = vha->hw;
6006 if (vha->vp_idx == 0) {
6007 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
6008 return NPH_MGMT_SERVER;
6011 /* pick id from high and work down to low */
6012 spin_lock_irqsave(&ha->vport_slock, flags);
6013 for (; lid > 0; lid--) {
6014 if (!test_bit(lid, vha->hw->loop_id_map)) {
6015 set_bit(lid, vha->hw->loop_id_map);
6020 spin_unlock_irqrestore(&ha->vport_slock, flags);
6026 * qla2x00_fabric_login
6027 * Issue fabric login command.
6030 * ha = adapter block pointer.
6031 * device = pointer to FC device type structure.
6034 * 0 - Login successfully
6036 * 2 - Initiator device
6040 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
6041 uint16_t *next_loopid)
6045 uint16_t tmp_loopid;
6046 uint16_t mb[MAILBOX_REGISTER_COUNT];
6047 struct qla_hw_data *ha = vha->hw;
6053 ql_dbg(ql_dbg_disc, vha, 0x2000,
6054 "Trying Fabric Login w/loop id 0x%04x for port "
6056 fcport->loop_id, fcport->d_id.b.domain,
6057 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6059 /* Login fcport on switch. */
6060 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
6061 fcport->d_id.b.domain, fcport->d_id.b.area,
6062 fcport->d_id.b.al_pa, mb, BIT_0);
6063 if (rval != QLA_SUCCESS) {
6066 if (mb[0] == MBS_PORT_ID_USED) {
6068 * Device has another loop ID. The firmware team
6069 * recommends the driver perform an implicit login with
6070 * the specified ID again. The ID we just used is save
6071 * here so we return with an ID that can be tried by
6075 tmp_loopid = fcport->loop_id;
6076 fcport->loop_id = mb[1];
6078 ql_dbg(ql_dbg_disc, vha, 0x2001,
6079 "Fabric Login: port in use - next loop "
6080 "id=0x%04x, port id= %02x%02x%02x.\n",
6081 fcport->loop_id, fcport->d_id.b.domain,
6082 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6084 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
6089 /* A retry occurred before. */
6090 *next_loopid = tmp_loopid;
6093 * No retry occurred before. Just increment the
6094 * ID value for next login.
6096 *next_loopid = (fcport->loop_id + 1);
6099 if (mb[1] & BIT_0) {
6100 fcport->port_type = FCT_INITIATOR;
6102 fcport->port_type = FCT_TARGET;
6103 if (mb[1] & BIT_1) {
6104 fcport->flags |= FCF_FCP2_DEVICE;
6109 fcport->supported_classes |= FC_COS_CLASS2;
6111 fcport->supported_classes |= FC_COS_CLASS3;
6113 if (IS_FWI2_CAPABLE(ha)) {
6116 FCF_CONF_COMP_SUPPORTED;
6121 } else if (mb[0] == MBS_LOOP_ID_USED) {
6123 * Loop ID already used, try next loop ID.
6126 rval = qla2x00_find_new_loop_id(vha, fcport);
6127 if (rval != QLA_SUCCESS) {
6128 /* Ran out of loop IDs to use */
6131 } else if (mb[0] == MBS_COMMAND_ERROR) {
6133 * Firmware possibly timed out during login. If NO
6134 * retries are left to do then the device is declared
6137 *next_loopid = fcport->loop_id;
6138 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6139 fcport->d_id.b.domain, fcport->d_id.b.area,
6140 fcport->d_id.b.al_pa);
6141 qla2x00_mark_device_lost(vha, fcport, 1, 0);
6147 * unrecoverable / not handled error
6149 ql_dbg(ql_dbg_disc, vha, 0x2002,
6150 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6151 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
6152 fcport->d_id.b.area, fcport->d_id.b.al_pa,
6153 fcport->loop_id, jiffies);
6155 *next_loopid = fcport->loop_id;
6156 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6157 fcport->d_id.b.domain, fcport->d_id.b.area,
6158 fcport->d_id.b.al_pa);
6159 qla2x00_clear_loop_id(fcport);
6160 fcport->login_retry = 0;
6171 * qla2x00_local_device_login
6172 * Issue local device login command.
6175 * ha = adapter block pointer.
6176 * loop_id = loop id of device to login to.
6178 * Returns (Where's the #define!!!!):
6179 * 0 - Login successfully
6184 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
6187 uint16_t mb[MAILBOX_REGISTER_COUNT];
6189 memset(mb, 0, sizeof(mb));
6190 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
6191 if (rval == QLA_SUCCESS) {
6192 /* Interrogate mailbox registers for any errors */
6193 if (mb[0] == MBS_COMMAND_ERROR)
6195 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
6196 /* device not in PCB table */
6204 * qla2x00_loop_resync
6205 * Resync with fibre channel devices.
6208 * ha = adapter block pointer.
6214 qla2x00_loop_resync(scsi_qla_host_t *vha)
6216 int rval = QLA_SUCCESS;
6219 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6220 if (vha->flags.online) {
6221 if (!(rval = qla2x00_fw_ready(vha))) {
6222 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6225 if (!IS_QLAFX00(vha->hw)) {
6227 * Issue a marker after FW becomes
6230 qla2x00_marker(vha, vha->hw->base_qpair,
6232 vha->marker_needed = 0;
6235 /* Remap devices on Loop. */
6236 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6238 if (IS_QLAFX00(vha->hw))
6239 qlafx00_configure_devices(vha);
6241 qla2x00_configure_loop(vha);
6244 } while (!atomic_read(&vha->loop_down_timer) &&
6245 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6246 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
6251 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6252 return (QLA_FUNCTION_FAILED);
6255 ql_dbg(ql_dbg_disc, vha, 0x206c,
6256 "%s *** FAILED ***.\n", __func__);
6262 * qla2x00_perform_loop_resync
6263 * Description: This function will set the appropriate flags and call
6264 * qla2x00_loop_resync. If successful loop will be resynced
6265 * Arguments : scsi_qla_host_t pointer
6266 * returm : Success or Failure
6269 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
6273 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
6274 /*Configure the flags so that resync happens properly*/
6275 atomic_set(&ha->loop_down_timer, 0);
6276 if (!(ha->device_flags & DFLG_NO_CABLE)) {
6277 atomic_set(&ha->loop_state, LOOP_UP);
6278 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
6279 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
6280 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
6282 rval = qla2x00_loop_resync(ha);
6284 atomic_set(&ha->loop_state, LOOP_DEAD);
6286 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
6293 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
6296 struct scsi_qla_host *vha;
6297 struct qla_hw_data *ha = base_vha->hw;
6298 unsigned long flags;
6300 spin_lock_irqsave(&ha->vport_slock, flags);
6301 /* Go with deferred removal of rport references. */
6302 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
6303 atomic_inc(&vha->vref_count);
6304 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6305 if (fcport->drport &&
6306 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
6307 spin_unlock_irqrestore(&ha->vport_slock, flags);
6308 qla2x00_rport_del(fcport);
6310 spin_lock_irqsave(&ha->vport_slock, flags);
6313 atomic_dec(&vha->vref_count);
6314 wake_up(&vha->vref_waitq);
6316 spin_unlock_irqrestore(&ha->vport_slock, flags);
6319 /* Assumes idc_lock always held on entry */
6321 qla83xx_reset_ownership(scsi_qla_host_t *vha)
6323 struct qla_hw_data *ha = vha->hw;
6324 uint32_t drv_presence, drv_presence_mask;
6325 uint32_t dev_part_info1, dev_part_info2, class_type;
6326 uint32_t class_type_mask = 0x3;
6327 uint16_t fcoe_other_function = 0xffff, i;
6329 if (IS_QLA8044(ha)) {
6330 drv_presence = qla8044_rd_direct(vha,
6331 QLA8044_CRB_DRV_ACTIVE_INDEX);
6332 dev_part_info1 = qla8044_rd_direct(vha,
6333 QLA8044_CRB_DEV_PART_INFO_INDEX);
6334 dev_part_info2 = qla8044_rd_direct(vha,
6335 QLA8044_CRB_DEV_PART_INFO2);
6337 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6338 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
6339 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
6341 for (i = 0; i < 8; i++) {
6342 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
6343 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6344 (i != ha->portnum)) {
6345 fcoe_other_function = i;
6349 if (fcoe_other_function == 0xffff) {
6350 for (i = 0; i < 8; i++) {
6351 class_type = ((dev_part_info2 >> (i * 4)) &
6353 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6354 ((i + 8) != ha->portnum)) {
6355 fcoe_other_function = i + 8;
6361 * Prepare drv-presence mask based on fcoe functions present.
6362 * However consider only valid physical fcoe function numbers (0-15).
6364 drv_presence_mask = ~((1 << (ha->portnum)) |
6365 ((fcoe_other_function == 0xffff) ?
6366 0 : (1 << (fcoe_other_function))));
6368 /* We are the reset owner iff:
6369 * - No other protocol drivers present.
6370 * - This is the lowest among fcoe functions. */
6371 if (!(drv_presence & drv_presence_mask) &&
6372 (ha->portnum < fcoe_other_function)) {
6373 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
6374 "This host is Reset owner.\n");
6375 ha->flags.nic_core_reset_owner = 1;
6380 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
6382 int rval = QLA_SUCCESS;
6383 struct qla_hw_data *ha = vha->hw;
6386 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6387 if (rval == QLA_SUCCESS) {
6388 drv_ack |= (1 << ha->portnum);
6389 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6396 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
6398 int rval = QLA_SUCCESS;
6399 struct qla_hw_data *ha = vha->hw;
6402 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6403 if (rval == QLA_SUCCESS) {
6404 drv_ack &= ~(1 << ha->portnum);
6405 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6412 qla83xx_dev_state_to_string(uint32_t dev_state)
6414 switch (dev_state) {
6415 case QLA8XXX_DEV_COLD:
6416 return "COLD/RE-INIT";
6417 case QLA8XXX_DEV_INITIALIZING:
6418 return "INITIALIZING";
6419 case QLA8XXX_DEV_READY:
6421 case QLA8XXX_DEV_NEED_RESET:
6422 return "NEED RESET";
6423 case QLA8XXX_DEV_NEED_QUIESCENT:
6424 return "NEED QUIESCENT";
6425 case QLA8XXX_DEV_FAILED:
6427 case QLA8XXX_DEV_QUIESCENT:
6434 /* Assumes idc-lock always held on entry */
6436 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6438 struct qla_hw_data *ha = vha->hw;
6439 uint32_t idc_audit_reg = 0, duration_secs = 0;
6441 switch (audit_type) {
6442 case IDC_AUDIT_TIMESTAMP:
6443 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6444 idc_audit_reg = (ha->portnum) |
6445 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6446 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6449 case IDC_AUDIT_COMPLETION:
6450 duration_secs = ((jiffies_to_msecs(jiffies) -
6451 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6452 idc_audit_reg = (ha->portnum) |
6453 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6454 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6458 ql_log(ql_log_warn, vha, 0xb078,
6459 "Invalid audit type specified.\n");
6464 /* Assumes idc_lock always held on entry */
6466 qla83xx_initiating_reset(scsi_qla_host_t *vha)
6468 struct qla_hw_data *ha = vha->hw;
6469 uint32_t idc_control, dev_state;
6471 __qla83xx_get_idc_control(vha, &idc_control);
6472 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6473 ql_log(ql_log_info, vha, 0xb080,
6474 "NIC Core reset has been disabled. idc-control=0x%x\n",
6476 return QLA_FUNCTION_FAILED;
6479 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6480 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6481 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6482 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6483 QLA8XXX_DEV_NEED_RESET);
6484 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6485 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6487 const char *state = qla83xx_dev_state_to_string(dev_state);
6489 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
6491 /* SV: XXX: Is timeout required here? */
6492 /* Wait for IDC state change READY -> NEED_RESET */
6493 while (dev_state == QLA8XXX_DEV_READY) {
6494 qla83xx_idc_unlock(vha, 0);
6496 qla83xx_idc_lock(vha, 0);
6497 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6501 /* Send IDC ack by writing to drv-ack register */
6502 __qla83xx_set_drv_ack(vha);
6508 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6510 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6514 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6516 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6520 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6522 uint32_t drv_presence = 0;
6523 struct qla_hw_data *ha = vha->hw;
6525 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6526 if (drv_presence & (1 << ha->portnum))
6529 return QLA_TEST_FAILED;
6533 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6535 int rval = QLA_SUCCESS;
6536 struct qla_hw_data *ha = vha->hw;
6538 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6539 "Entered %s().\n", __func__);
6541 if (vha->device_flags & DFLG_DEV_FAILED) {
6542 ql_log(ql_log_warn, vha, 0xb059,
6543 "Device in unrecoverable FAILED state.\n");
6544 return QLA_FUNCTION_FAILED;
6547 qla83xx_idc_lock(vha, 0);
6549 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6550 ql_log(ql_log_warn, vha, 0xb05a,
6551 "Function=0x%x has been removed from IDC participation.\n",
6553 rval = QLA_FUNCTION_FAILED;
6557 qla83xx_reset_ownership(vha);
6559 rval = qla83xx_initiating_reset(vha);
6562 * Perform reset if we are the reset-owner,
6563 * else wait till IDC state changes to READY/FAILED.
6565 if (rval == QLA_SUCCESS) {
6566 rval = qla83xx_idc_state_handler(vha);
6568 if (rval == QLA_SUCCESS)
6569 ha->flags.nic_core_hung = 0;
6570 __qla83xx_clear_drv_ack(vha);
6574 qla83xx_idc_unlock(vha, 0);
6576 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6582 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6584 struct qla_hw_data *ha = vha->hw;
6585 int rval = QLA_FUNCTION_FAILED;
6587 if (!IS_MCTP_CAPABLE(ha)) {
6588 /* This message can be removed from the final version */
6589 ql_log(ql_log_info, vha, 0x506d,
6590 "This board is not MCTP capable\n");
6594 if (!ha->mctp_dump) {
6595 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6596 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6598 if (!ha->mctp_dump) {
6599 ql_log(ql_log_warn, vha, 0x506e,
6600 "Failed to allocate memory for mctp dump\n");
6605 #define MCTP_DUMP_STR_ADDR 0x00000000
6606 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6607 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6608 if (rval != QLA_SUCCESS) {
6609 ql_log(ql_log_warn, vha, 0x506f,
6610 "Failed to capture mctp dump\n");
6612 ql_log(ql_log_info, vha, 0x5070,
6613 "Mctp dump capture for host (%ld/%p).\n",
6614 vha->host_no, ha->mctp_dump);
6615 ha->mctp_dumped = 1;
6618 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
6619 ha->flags.nic_core_reset_hdlr_active = 1;
6620 rval = qla83xx_restart_nic_firmware(vha);
6622 /* NIC Core reset failed. */
6623 ql_log(ql_log_warn, vha, 0x5071,
6624 "Failed to restart nic firmware\n");
6626 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6627 "Restarted NIC firmware successfully.\n");
6628 ha->flags.nic_core_reset_hdlr_active = 0;
6636 * qla2x00_quiesce_io
6637 * Description: This function will block the new I/Os
6638 * Its not aborting any I/Os as context
6639 * is not destroyed during quiescence
6640 * Arguments: scsi_qla_host_t
6644 qla2x00_quiesce_io(scsi_qla_host_t *vha)
6646 struct qla_hw_data *ha = vha->hw;
6647 struct scsi_qla_host *vp;
6649 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6650 "Quiescing I/O - ha=%p.\n", ha);
6652 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6653 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6654 atomic_set(&vha->loop_state, LOOP_DOWN);
6655 qla2x00_mark_all_devices_lost(vha, 0);
6656 list_for_each_entry(vp, &ha->vp_list, list)
6657 qla2x00_mark_all_devices_lost(vp, 0);
6659 if (!atomic_read(&vha->loop_down_timer))
6660 atomic_set(&vha->loop_down_timer,
6663 /* Wait for pending cmds to complete */
6664 WARN_ON_ONCE(qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST)
6669 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6671 struct qla_hw_data *ha = vha->hw;
6672 struct scsi_qla_host *vp;
6673 unsigned long flags;
6677 /* For ISP82XX, driver waits for completion of the commands.
6678 * online flag should be set.
6680 if (!(IS_P3P_TYPE(ha)))
6681 vha->flags.online = 0;
6682 ha->flags.chip_reset_done = 0;
6683 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6684 vha->qla_stats.total_isp_aborts++;
6686 ql_log(ql_log_info, vha, 0x00af,
6687 "Performing ISP error recovery - ha=%p.\n", ha);
6689 ha->flags.purge_mbox = 1;
6690 /* For ISP82XX, reset_chip is just disabling interrupts.
6691 * Driver waits for the completion of the commands.
6692 * the interrupts need to be enabled.
6694 if (!(IS_P3P_TYPE(ha)))
6695 ha->isp_ops->reset_chip(vha);
6697 ha->link_data_rate = PORT_SPEED_UNKNOWN;
6699 ha->flags.rida_fmt2 = 0;
6700 ha->flags.n2n_ae = 0;
6701 ha->flags.lip_ae = 0;
6702 ha->current_topology = 0;
6703 ha->flags.fw_started = 0;
6704 ha->flags.fw_init_done = 0;
6706 ha->base_qpair->chip_reset = ha->chip_reset;
6707 for (i = 0; i < ha->max_qpairs; i++) {
6708 if (ha->queue_pair_map[i])
6709 ha->queue_pair_map[i]->chip_reset =
6710 ha->base_qpair->chip_reset;
6713 /* purge MBox commands */
6714 if (atomic_read(&ha->num_pend_mbx_stage3)) {
6715 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
6716 complete(&ha->mbx_intr_comp);
6720 while (atomic_read(&ha->num_pend_mbx_stage3) ||
6721 atomic_read(&ha->num_pend_mbx_stage2) ||
6722 atomic_read(&ha->num_pend_mbx_stage1)) {
6728 ha->flags.purge_mbox = 0;
6730 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6731 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6732 atomic_set(&vha->loop_state, LOOP_DOWN);
6733 qla2x00_mark_all_devices_lost(vha, 0);
6735 spin_lock_irqsave(&ha->vport_slock, flags);
6736 list_for_each_entry(vp, &ha->vp_list, list) {
6737 atomic_inc(&vp->vref_count);
6738 spin_unlock_irqrestore(&ha->vport_slock, flags);
6740 qla2x00_mark_all_devices_lost(vp, 0);
6742 spin_lock_irqsave(&ha->vport_slock, flags);
6743 atomic_dec(&vp->vref_count);
6745 spin_unlock_irqrestore(&ha->vport_slock, flags);
6747 if (!atomic_read(&vha->loop_down_timer))
6748 atomic_set(&vha->loop_down_timer,
6752 /* Clear all async request states across all VPs. */
6753 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6754 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6755 fcport->scan_state = 0;
6757 spin_lock_irqsave(&ha->vport_slock, flags);
6758 list_for_each_entry(vp, &ha->vp_list, list) {
6759 atomic_inc(&vp->vref_count);
6760 spin_unlock_irqrestore(&ha->vport_slock, flags);
6762 list_for_each_entry(fcport, &vp->vp_fcports, list)
6763 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6765 spin_lock_irqsave(&ha->vport_slock, flags);
6766 atomic_dec(&vp->vref_count);
6768 spin_unlock_irqrestore(&ha->vport_slock, flags);
6770 if (!ha->flags.eeh_busy) {
6771 /* Make sure for ISP 82XX IO DMA is complete */
6772 if (IS_P3P_TYPE(ha)) {
6773 qla82xx_chip_reset_cleanup(vha);
6774 ql_log(ql_log_info, vha, 0x00b4,
6775 "Done chip reset cleanup.\n");
6777 /* Done waiting for pending commands.
6778 * Reset the online flag.
6780 vha->flags.online = 0;
6783 /* Requeue all commands in outstanding command list. */
6784 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6786 /* memory barrier */
6792 * Resets ISP and aborts all outstanding commands.
6795 * ha = adapter block pointer.
6801 qla2x00_abort_isp(scsi_qla_host_t *vha)
6805 struct qla_hw_data *ha = vha->hw;
6806 struct scsi_qla_host *vp;
6807 struct req_que *req = ha->req_q_map[0];
6808 unsigned long flags;
6810 if (vha->flags.online) {
6811 qla2x00_abort_isp_cleanup(vha);
6813 if (test_and_clear_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags)) {
6814 ha->flags.chip_reset_done = 1;
6815 vha->flags.online = 1;
6817 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6821 if (IS_QLA8031(ha)) {
6822 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
6823 "Clearing fcoe driver presence.\n");
6824 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
6825 ql_dbg(ql_dbg_p3p, vha, 0xb073,
6826 "Error while clearing DRV-Presence.\n");
6829 if (unlikely(pci_channel_offline(ha->pdev) &&
6830 ha->flags.pci_channel_io_perm_failure)) {
6831 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6836 switch (vha->qlini_mode) {
6837 case QLA2XXX_INI_MODE_DISABLED:
6838 if (!qla_tgt_mode_enabled(vha))
6841 case QLA2XXX_INI_MODE_DUAL:
6842 if (!qla_dual_mode_enabled(vha) &&
6843 !qla_ini_mode_enabled(vha))
6846 case QLA2XXX_INI_MODE_ENABLED:
6851 ha->isp_ops->get_flash_version(vha, req->ring);
6853 ha->isp_ops->nvram_config(vha);
6855 if (!qla2x00_restart_isp(vha)) {
6856 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6858 if (!atomic_read(&vha->loop_down_timer)) {
6860 * Issue marker command only when we are going
6861 * to start the I/O .
6863 vha->marker_needed = 1;
6866 vha->flags.online = 1;
6868 ha->isp_ops->enable_intrs(ha);
6870 ha->isp_abort_cnt = 0;
6871 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6873 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
6874 qla2x00_get_fw_version(vha);
6876 ha->flags.fce_enabled = 1;
6878 fce_calc_size(ha->fce_bufs));
6879 rval = qla2x00_enable_fce_trace(vha,
6880 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6883 ql_log(ql_log_warn, vha, 0x8033,
6884 "Unable to reinitialize FCE "
6886 ha->flags.fce_enabled = 0;
6891 memset(ha->eft, 0, EFT_SIZE);
6892 rval = qla2x00_enable_eft_trace(vha,
6893 ha->eft_dma, EFT_NUM_BUFFERS);
6895 ql_log(ql_log_warn, vha, 0x8034,
6896 "Unable to reinitialize EFT "
6900 } else { /* failed the ISP abort */
6901 vha->flags.online = 1;
6902 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
6903 if (ha->isp_abort_cnt == 0) {
6904 ql_log(ql_log_fatal, vha, 0x8035,
6905 "ISP error recover failed - "
6906 "board disabled.\n");
6908 * The next call disables the board
6911 qla2x00_abort_isp_cleanup(vha);
6912 vha->flags.online = 0;
6913 clear_bit(ISP_ABORT_RETRY,
6916 } else { /* schedule another ISP abort */
6917 ha->isp_abort_cnt--;
6918 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6919 "ISP abort - retry remaining %d.\n",
6924 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
6925 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6926 "ISP error recovery - retrying (%d) "
6927 "more times.\n", ha->isp_abort_cnt);
6928 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6936 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
6937 qla2x00_configure_hba(vha);
6938 spin_lock_irqsave(&ha->vport_slock, flags);
6939 list_for_each_entry(vp, &ha->vp_list, list) {
6941 atomic_inc(&vp->vref_count);
6942 spin_unlock_irqrestore(&ha->vport_slock, flags);
6944 qla2x00_vp_abort_isp(vp);
6946 spin_lock_irqsave(&ha->vport_slock, flags);
6947 atomic_dec(&vp->vref_count);
6950 spin_unlock_irqrestore(&ha->vport_slock, flags);
6952 if (IS_QLA8031(ha)) {
6953 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6954 "Setting back fcoe driver presence.\n");
6955 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6956 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6957 "Error while setting DRV-Presence.\n");
6960 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6968 * qla2x00_restart_isp
6969 * restarts the ISP after a reset
6972 * ha = adapter block pointer.
6978 qla2x00_restart_isp(scsi_qla_host_t *vha)
6981 struct qla_hw_data *ha = vha->hw;
6983 /* If firmware needs to be loaded */
6984 if (qla2x00_isp_firmware(vha)) {
6985 vha->flags.online = 0;
6986 status = ha->isp_ops->chip_diag(vha);
6988 status = qla2x00_setup_chip(vha);
6991 if (!status && !(status = qla2x00_init_rings(vha))) {
6992 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6993 ha->flags.chip_reset_done = 1;
6995 /* Initialize the queues in use */
6996 qla25xx_init_queues(ha);
6998 status = qla2x00_fw_ready(vha);
7000 /* Issue a marker after FW becomes ready. */
7001 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
7002 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7005 /* if no cable then assume it's good */
7006 if ((vha->device_flags & DFLG_NO_CABLE))
7013 qla25xx_init_queues(struct qla_hw_data *ha)
7015 struct rsp_que *rsp = NULL;
7016 struct req_que *req = NULL;
7017 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7021 for (i = 1; i < ha->max_rsp_queues; i++) {
7022 rsp = ha->rsp_q_map[i];
7023 if (rsp && test_bit(i, ha->rsp_qid_map)) {
7024 rsp->options &= ~BIT_0;
7025 ret = qla25xx_init_rsp_que(base_vha, rsp);
7026 if (ret != QLA_SUCCESS)
7027 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
7028 "%s Rsp que: %d init failed.\n",
7031 ql_dbg(ql_dbg_init, base_vha, 0x0100,
7032 "%s Rsp que: %d inited.\n",
7036 for (i = 1; i < ha->max_req_queues; i++) {
7037 req = ha->req_q_map[i];
7038 if (req && test_bit(i, ha->req_qid_map)) {
7039 /* Clear outstanding commands array. */
7040 req->options &= ~BIT_0;
7041 ret = qla25xx_init_req_que(base_vha, req);
7042 if (ret != QLA_SUCCESS)
7043 ql_dbg(ql_dbg_init, base_vha, 0x0101,
7044 "%s Req que: %d init failed.\n",
7047 ql_dbg(ql_dbg_init, base_vha, 0x0102,
7048 "%s Req que: %d inited.\n",
7056 * qla2x00_reset_adapter
7060 * ha = adapter block pointer.
7063 qla2x00_reset_adapter(scsi_qla_host_t *vha)
7065 unsigned long flags = 0;
7066 struct qla_hw_data *ha = vha->hw;
7067 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7069 vha->flags.online = 0;
7070 ha->isp_ops->disable_intrs(ha);
7072 spin_lock_irqsave(&ha->hardware_lock, flags);
7073 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
7074 RD_REG_WORD(®->hccr); /* PCI Posting. */
7075 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
7076 RD_REG_WORD(®->hccr); /* PCI Posting. */
7077 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7083 qla24xx_reset_adapter(scsi_qla_host_t *vha)
7085 unsigned long flags = 0;
7086 struct qla_hw_data *ha = vha->hw;
7087 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
7088 int rval = QLA_SUCCESS;
7090 if (IS_P3P_TYPE(ha))
7093 vha->flags.online = 0;
7094 ha->isp_ops->disable_intrs(ha);
7096 spin_lock_irqsave(&ha->hardware_lock, flags);
7097 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
7098 RD_REG_DWORD(®->hccr);
7099 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
7100 RD_REG_DWORD(®->hccr);
7101 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7103 if (IS_NOPOLLING_TYPE(ha))
7104 ha->isp_ops->enable_intrs(ha);
7109 /* On sparc systems, obtain port and node WWN from firmware
7112 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
7113 struct nvram_24xx *nv)
7116 struct qla_hw_data *ha = vha->hw;
7117 struct pci_dev *pdev = ha->pdev;
7118 struct device_node *dp = pci_device_to_OF_node(pdev);
7122 val = of_get_property(dp, "port-wwn", &len);
7123 if (val && len >= WWN_SIZE)
7124 memcpy(nv->port_name, val, WWN_SIZE);
7126 val = of_get_property(dp, "node-wwn", &len);
7127 if (val && len >= WWN_SIZE)
7128 memcpy(nv->node_name, val, WWN_SIZE);
7133 qla24xx_nvram_config(scsi_qla_host_t *vha)
7136 struct init_cb_24xx *icb;
7137 struct nvram_24xx *nv;
7139 uint8_t *dptr1, *dptr2;
7142 struct qla_hw_data *ha = vha->hw;
7145 icb = (struct init_cb_24xx *)ha->init_cb;
7148 /* Determine NVRAM starting address. */
7149 if (ha->port_no == 0) {
7150 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
7151 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
7153 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
7154 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
7157 ha->nvram_size = sizeof(*nv);
7158 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7160 /* Get VPD data into cache */
7161 ha->vpd = ha->nvram + VPD_OFFSET;
7162 ha->isp_ops->read_nvram(vha, ha->vpd,
7163 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
7165 /* Get NVRAM data into cache and calculate checksum. */
7166 dptr = (uint32_t *)nv;
7167 ha->isp_ops->read_nvram(vha, dptr, ha->nvram_base, ha->nvram_size);
7168 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7169 chksum += le32_to_cpu(*dptr);
7171 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
7172 "Contents of NVRAM\n");
7173 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
7174 nv, ha->nvram_size);
7176 /* Bad NVRAM data, set defaults parameters. */
7177 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
7178 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
7179 /* Reset NVRAM data. */
7180 ql_log(ql_log_warn, vha, 0x006b,
7181 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
7182 chksum, nv->id, nv->nvram_version);
7183 ql_dump_buffer(ql_dbg_init, vha, 0x006b, nv, sizeof(*nv));
7184 ql_log(ql_log_warn, vha, 0x006c,
7185 "Falling back to functioning (yet invalid -- WWPN) "
7189 * Set default initialization control block.
7191 memset(nv, 0, ha->nvram_size);
7192 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7193 nv->version = cpu_to_le16(ICB_VERSION);
7194 nv->frame_payload_size = 2048;
7195 nv->execution_throttle = cpu_to_le16(0xFFFF);
7196 nv->exchange_count = cpu_to_le16(0);
7197 nv->hard_address = cpu_to_le16(124);
7198 nv->port_name[0] = 0x21;
7199 nv->port_name[1] = 0x00 + ha->port_no + 1;
7200 nv->port_name[2] = 0x00;
7201 nv->port_name[3] = 0xe0;
7202 nv->port_name[4] = 0x8b;
7203 nv->port_name[5] = 0x1c;
7204 nv->port_name[6] = 0x55;
7205 nv->port_name[7] = 0x86;
7206 nv->node_name[0] = 0x20;
7207 nv->node_name[1] = 0x00;
7208 nv->node_name[2] = 0x00;
7209 nv->node_name[3] = 0xe0;
7210 nv->node_name[4] = 0x8b;
7211 nv->node_name[5] = 0x1c;
7212 nv->node_name[6] = 0x55;
7213 nv->node_name[7] = 0x86;
7214 qla24xx_nvram_wwn_from_ofw(vha, nv);
7215 nv->login_retry_count = cpu_to_le16(8);
7216 nv->interrupt_delay_timer = cpu_to_le16(0);
7217 nv->login_timeout = cpu_to_le16(0);
7218 nv->firmware_options_1 =
7219 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7220 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7221 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7222 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7223 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7224 nv->efi_parameters = cpu_to_le32(0);
7225 nv->reset_delay = 5;
7226 nv->max_luns_per_target = cpu_to_le16(128);
7227 nv->port_down_retry_count = cpu_to_le16(30);
7228 nv->link_down_timeout = cpu_to_le16(30);
7233 if (qla_tgt_mode_enabled(vha)) {
7234 /* Don't enable full login after initial LIP */
7235 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7236 /* Don't enable LIP full login for initiator */
7237 nv->host_p &= cpu_to_le32(~BIT_10);
7240 qlt_24xx_config_nvram_stage1(vha, nv);
7242 /* Reset Initialization control block */
7243 memset(icb, 0, ha->init_cb_size);
7245 /* Copy 1st segment. */
7246 dptr1 = (uint8_t *)icb;
7247 dptr2 = (uint8_t *)&nv->version;
7248 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7250 *dptr1++ = *dptr2++;
7252 icb->login_retry_count = nv->login_retry_count;
7253 icb->link_down_on_nos = nv->link_down_on_nos;
7255 /* Copy 2nd segment. */
7256 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7257 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7258 cnt = (uint8_t *)&icb->reserved_3 -
7259 (uint8_t *)&icb->interrupt_delay_timer;
7261 *dptr1++ = *dptr2++;
7262 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
7264 * Setup driver NVRAM options.
7266 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7269 qlt_24xx_config_nvram_stage2(vha, icb);
7271 if (nv->host_p & cpu_to_le32(BIT_15)) {
7272 /* Use alternate WWN? */
7273 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7274 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7277 /* Prepare nodename */
7278 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7280 * Firmware will apply the following mask if the nodename was
7283 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7284 icb->node_name[0] &= 0xF0;
7287 /* Set host adapter parameters. */
7288 ha->flags.disable_risc_code_load = 0;
7289 ha->flags.enable_lip_reset = 0;
7290 ha->flags.enable_lip_full_login =
7291 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
7292 ha->flags.enable_target_reset =
7293 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
7294 ha->flags.enable_led_scheme = 0;
7295 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
7297 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7298 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7300 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
7301 sizeof(ha->fw_seriallink_options24));
7303 /* save HBA serial number */
7304 ha->serial0 = icb->port_name[5];
7305 ha->serial1 = icb->port_name[6];
7306 ha->serial2 = icb->port_name[7];
7307 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7308 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7310 icb->execution_throttle = cpu_to_le16(0xFFFF);
7312 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7314 /* Set minimum login_timeout to 4 seconds. */
7315 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7316 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7317 if (le16_to_cpu(nv->login_timeout) < 4)
7318 nv->login_timeout = cpu_to_le16(4);
7319 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7321 /* Set minimum RATOV to 100 tenths of a second. */
7324 ha->loop_reset_delay = nv->reset_delay;
7326 /* Link Down Timeout = 0:
7328 * When Port Down timer expires we will start returning
7329 * I/O's to OS with "DID_NO_CONNECT".
7331 * Link Down Timeout != 0:
7333 * The driver waits for the link to come up after link down
7334 * before returning I/Os to OS with "DID_NO_CONNECT".
7336 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7337 ha->loop_down_abort_time =
7338 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7340 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7341 ha->loop_down_abort_time =
7342 (LOOP_DOWN_TIME - ha->link_down_timeout);
7345 /* Need enough time to try and get the port back. */
7346 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7347 if (qlport_down_retry)
7348 ha->port_down_retry_count = qlport_down_retry;
7350 /* Set login_retry_count */
7351 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7352 if (ha->port_down_retry_count ==
7353 le16_to_cpu(nv->port_down_retry_count) &&
7354 ha->port_down_retry_count > 3)
7355 ha->login_retry_count = ha->port_down_retry_count;
7356 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7357 ha->login_retry_count = ha->port_down_retry_count;
7358 if (ql2xloginretrycount)
7359 ha->login_retry_count = ql2xloginretrycount;
7361 /* N2N: driver will initiate Login instead of FW */
7362 icb->firmware_options_3 |= BIT_8;
7365 if (!vha->flags.init_done) {
7366 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7367 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7368 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7369 le16_to_cpu(icb->interrupt_delay_timer) : 2;
7371 icb->firmware_options_2 &= cpu_to_le32(
7372 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7373 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7374 ha->zio_mode = QLA_ZIO_MODE_6;
7376 ql_log(ql_log_info, vha, 0x006f,
7377 "ZIO mode %d enabled; timer delay (%d us).\n",
7378 ha->zio_mode, ha->zio_timer * 100);
7380 icb->firmware_options_2 |= cpu_to_le32(
7381 (uint32_t)ha->zio_mode);
7382 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7386 ql_log(ql_log_warn, vha, 0x0070,
7387 "NVRAM configuration failed.\n");
7393 qla27xx_print_image(struct scsi_qla_host *vha, char *name,
7394 struct qla27xx_image_status *image_status)
7396 ql_dbg(ql_dbg_init, vha, 0x018b,
7397 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
7399 image_status->image_status_mask,
7400 le16_to_cpu(image_status->generation),
7401 image_status->ver_major,
7402 image_status->ver_minor,
7403 image_status->bitmap,
7404 le32_to_cpu(image_status->checksum),
7405 le32_to_cpu(image_status->signature));
7409 qla28xx_check_aux_image_status_signature(
7410 struct qla27xx_image_status *image_status)
7412 ulong signature = le32_to_cpu(image_status->signature);
7414 return signature != QLA28XX_AUX_IMG_STATUS_SIGN;
7418 qla27xx_check_image_status_signature(struct qla27xx_image_status *image_status)
7420 ulong signature = le32_to_cpu(image_status->signature);
7423 signature != QLA27XX_IMG_STATUS_SIGN &&
7424 signature != QLA28XX_IMG_STATUS_SIGN;
7428 qla27xx_image_status_checksum(struct qla27xx_image_status *image_status)
7430 uint32_t *p = (void *)image_status;
7431 uint n = sizeof(*image_status) / sizeof(*p);
7435 sum += le32_to_cpup(p);
7441 qla28xx_component_bitmask(struct qla27xx_image_status *aux, uint bitmask)
7443 return aux->bitmap & bitmask ?
7444 QLA27XX_SECONDARY_IMAGE : QLA27XX_PRIMARY_IMAGE;
7448 qla28xx_component_status(
7449 struct active_regions *active_regions, struct qla27xx_image_status *aux)
7451 active_regions->aux.board_config =
7452 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_BOARD_CONFIG);
7454 active_regions->aux.vpd_nvram =
7455 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_VPD_NVRAM);
7457 active_regions->aux.npiv_config_0_1 =
7458 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1);
7460 active_regions->aux.npiv_config_2_3 =
7461 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3);
7465 qla27xx_compare_image_generation(
7466 struct qla27xx_image_status *pri_image_status,
7467 struct qla27xx_image_status *sec_image_status)
7469 /* calculate generation delta as uint16 (this accounts for wrap) */
7471 le16_to_cpu(pri_image_status->generation) -
7472 le16_to_cpu(sec_image_status->generation);
7474 ql_dbg(ql_dbg_init, NULL, 0x0180, "generation delta = %d\n", delta);
7480 qla28xx_get_aux_images(
7481 struct scsi_qla_host *vha, struct active_regions *active_regions)
7483 struct qla_hw_data *ha = vha->hw;
7484 struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
7485 bool valid_pri_image = false, valid_sec_image = false;
7486 bool active_pri_image = false, active_sec_image = false;
7488 if (!ha->flt_region_aux_img_status_pri) {
7489 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
7490 goto check_sec_image;
7493 qla24xx_read_flash_data(vha, (void *)&pri_aux_image_status,
7494 ha->flt_region_aux_img_status_pri,
7495 sizeof(pri_aux_image_status) >> 2);
7496 qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
7498 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
7499 ql_dbg(ql_dbg_init, vha, 0x018b,
7500 "Primary aux image signature (%#x) not valid\n",
7501 le32_to_cpu(pri_aux_image_status.signature));
7502 goto check_sec_image;
7505 if (qla27xx_image_status_checksum(&pri_aux_image_status)) {
7506 ql_dbg(ql_dbg_init, vha, 0x018c,
7507 "Primary aux image checksum failed\n");
7508 goto check_sec_image;
7511 valid_pri_image = true;
7513 if (pri_aux_image_status.image_status_mask & 1) {
7514 ql_dbg(ql_dbg_init, vha, 0x018d,
7515 "Primary aux image is active\n");
7516 active_pri_image = true;
7520 if (!ha->flt_region_aux_img_status_sec) {
7521 ql_dbg(ql_dbg_init, vha, 0x018a,
7522 "Secondary aux image not addressed\n");
7523 goto check_valid_image;
7526 qla24xx_read_flash_data(vha, (void *)&sec_aux_image_status,
7527 ha->flt_region_aux_img_status_sec,
7528 sizeof(sec_aux_image_status) >> 2);
7529 qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
7531 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
7532 ql_dbg(ql_dbg_init, vha, 0x018b,
7533 "Secondary aux image signature (%#x) not valid\n",
7534 le32_to_cpu(sec_aux_image_status.signature));
7535 goto check_valid_image;
7538 if (qla27xx_image_status_checksum(&sec_aux_image_status)) {
7539 ql_dbg(ql_dbg_init, vha, 0x018c,
7540 "Secondary aux image checksum failed\n");
7541 goto check_valid_image;
7544 valid_sec_image = true;
7546 if (sec_aux_image_status.image_status_mask & 1) {
7547 ql_dbg(ql_dbg_init, vha, 0x018d,
7548 "Secondary aux image is active\n");
7549 active_sec_image = true;
7553 if (valid_pri_image && active_pri_image &&
7554 valid_sec_image && active_sec_image) {
7555 if (qla27xx_compare_image_generation(&pri_aux_image_status,
7556 &sec_aux_image_status) >= 0) {
7557 qla28xx_component_status(active_regions,
7558 &pri_aux_image_status);
7560 qla28xx_component_status(active_regions,
7561 &sec_aux_image_status);
7563 } else if (valid_pri_image && active_pri_image) {
7564 qla28xx_component_status(active_regions, &pri_aux_image_status);
7565 } else if (valid_sec_image && active_sec_image) {
7566 qla28xx_component_status(active_regions, &sec_aux_image_status);
7569 ql_dbg(ql_dbg_init, vha, 0x018f,
7570 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u\n",
7571 active_regions->aux.board_config,
7572 active_regions->aux.vpd_nvram,
7573 active_regions->aux.npiv_config_0_1,
7574 active_regions->aux.npiv_config_2_3);
7578 qla27xx_get_active_image(struct scsi_qla_host *vha,
7579 struct active_regions *active_regions)
7581 struct qla_hw_data *ha = vha->hw;
7582 struct qla27xx_image_status pri_image_status, sec_image_status;
7583 bool valid_pri_image = false, valid_sec_image = false;
7584 bool active_pri_image = false, active_sec_image = false;
7586 if (!ha->flt_region_img_status_pri) {
7587 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
7588 goto check_sec_image;
7591 if (qla24xx_read_flash_data(vha, (void *)(&pri_image_status),
7592 ha->flt_region_img_status_pri, sizeof(pri_image_status) >> 2) !=
7595 goto check_sec_image;
7597 qla27xx_print_image(vha, "Primary image", &pri_image_status);
7599 if (qla27xx_check_image_status_signature(&pri_image_status)) {
7600 ql_dbg(ql_dbg_init, vha, 0x018b,
7601 "Primary image signature (%#x) not valid\n",
7602 le32_to_cpu(pri_image_status.signature));
7603 goto check_sec_image;
7606 if (qla27xx_image_status_checksum(&pri_image_status)) {
7607 ql_dbg(ql_dbg_init, vha, 0x018c,
7608 "Primary image checksum failed\n");
7609 goto check_sec_image;
7612 valid_pri_image = true;
7614 if (pri_image_status.image_status_mask & 1) {
7615 ql_dbg(ql_dbg_init, vha, 0x018d,
7616 "Primary image is active\n");
7617 active_pri_image = true;
7621 if (!ha->flt_region_img_status_sec) {
7622 ql_dbg(ql_dbg_init, vha, 0x018a, "Secondary image not addressed\n");
7623 goto check_valid_image;
7626 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
7627 ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
7628 qla27xx_print_image(vha, "Secondary image", &sec_image_status);
7630 if (qla27xx_check_image_status_signature(&sec_image_status)) {
7631 ql_dbg(ql_dbg_init, vha, 0x018b,
7632 "Secondary image signature (%#x) not valid\n",
7633 le32_to_cpu(sec_image_status.signature));
7634 goto check_valid_image;
7637 if (qla27xx_image_status_checksum(&sec_image_status)) {
7638 ql_dbg(ql_dbg_init, vha, 0x018c,
7639 "Secondary image checksum failed\n");
7640 goto check_valid_image;
7643 valid_sec_image = true;
7645 if (sec_image_status.image_status_mask & 1) {
7646 ql_dbg(ql_dbg_init, vha, 0x018d,
7647 "Secondary image is active\n");
7648 active_sec_image = true;
7652 if (valid_pri_image && active_pri_image)
7653 active_regions->global = QLA27XX_PRIMARY_IMAGE;
7655 if (valid_sec_image && active_sec_image) {
7656 if (!active_regions->global ||
7657 qla27xx_compare_image_generation(
7658 &pri_image_status, &sec_image_status) < 0) {
7659 active_regions->global = QLA27XX_SECONDARY_IMAGE;
7663 ql_dbg(ql_dbg_init, vha, 0x018f, "active image %s (%u)\n",
7664 active_regions->global == QLA27XX_DEFAULT_IMAGE ?
7665 "default (boot/fw)" :
7666 active_regions->global == QLA27XX_PRIMARY_IMAGE ?
7668 active_regions->global == QLA27XX_SECONDARY_IMAGE ?
7669 "secondary" : "invalid",
7670 active_regions->global);
7673 bool qla24xx_risc_firmware_invalid(uint32_t *dword)
7676 !(dword[4] | dword[5] | dword[6] | dword[7]) ||
7677 !(~dword[4] | ~dword[5] | ~dword[6] | ~dword[7]);
7681 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
7685 uint templates, segments, fragment;
7690 uint32_t risc_addr, risc_size, risc_attr = 0;
7691 struct qla_hw_data *ha = vha->hw;
7692 struct req_que *req = ha->req_q_map[0];
7693 struct fwdt *fwdt = ha->fwdt;
7695 ql_dbg(ql_dbg_init, vha, 0x008b,
7696 "FW: Loading firmware from flash (%x).\n", faddr);
7698 dcode = (void *)req->ring;
7699 qla24xx_read_flash_data(vha, dcode, faddr, 8);
7700 if (qla24xx_risc_firmware_invalid(dcode)) {
7701 ql_log(ql_log_fatal, vha, 0x008c,
7702 "Unable to verify the integrity of flash firmware "
7704 ql_log(ql_log_fatal, vha, 0x008d,
7705 "Firmware data: %08x %08x %08x %08x.\n",
7706 dcode[0], dcode[1], dcode[2], dcode[3]);
7708 return QLA_FUNCTION_FAILED;
7711 dcode = (void *)req->ring;
7713 segments = FA_RISC_CODE_SEGMENTS;
7714 for (j = 0; j < segments; j++) {
7715 ql_dbg(ql_dbg_init, vha, 0x008d,
7716 "-> Loading segment %u...\n", j);
7717 qla24xx_read_flash_data(vha, dcode, faddr, 10);
7718 risc_addr = be32_to_cpu(dcode[2]);
7719 risc_size = be32_to_cpu(dcode[3]);
7721 *srisc_addr = risc_addr;
7722 risc_attr = be32_to_cpu(dcode[9]);
7725 dlen = ha->fw_transfer_size >> 2;
7726 for (fragment = 0; risc_size; fragment++) {
7727 if (dlen > risc_size)
7730 ql_dbg(ql_dbg_init, vha, 0x008e,
7731 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
7732 fragment, risc_addr, faddr, dlen);
7733 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
7734 for (i = 0; i < dlen; i++)
7735 dcode[i] = swab32(dcode[i]);
7737 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7739 ql_log(ql_log_fatal, vha, 0x008f,
7740 "-> Failed load firmware fragment %u.\n",
7742 return QLA_FUNCTION_FAILED;
7751 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
7754 templates = (risc_attr & BIT_9) ? 2 : 1;
7755 ql_dbg(ql_dbg_init, vha, 0x0160, "-> templates = %u\n", templates);
7756 for (j = 0; j < templates; j++, fwdt++) {
7758 vfree(fwdt->template);
7759 fwdt->template = NULL;
7762 dcode = (void *)req->ring;
7763 qla24xx_read_flash_data(vha, dcode, faddr, 7);
7764 risc_size = be32_to_cpu(dcode[2]);
7765 ql_dbg(ql_dbg_init, vha, 0x0161,
7766 "-> fwdt%u template array at %#x (%#x dwords)\n",
7767 j, faddr, risc_size);
7768 if (!risc_size || !~risc_size) {
7769 ql_dbg(ql_dbg_init, vha, 0x0162,
7770 "-> fwdt%u failed to read array\n", j);
7774 /* skip header and ignore checksum */
7778 ql_dbg(ql_dbg_init, vha, 0x0163,
7779 "-> fwdt%u template allocate template %#x words...\n",
7781 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
7782 if (!fwdt->template) {
7783 ql_log(ql_log_warn, vha, 0x0164,
7784 "-> fwdt%u failed allocate template.\n", j);
7788 dcode = fwdt->template;
7789 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
7791 if (!qla27xx_fwdt_template_valid(dcode)) {
7792 ql_log(ql_log_warn, vha, 0x0165,
7793 "-> fwdt%u failed template validate\n", j);
7797 dlen = qla27xx_fwdt_template_size(dcode);
7798 ql_dbg(ql_dbg_init, vha, 0x0166,
7799 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
7800 j, dlen, dlen / sizeof(*dcode));
7801 if (dlen > risc_size * sizeof(*dcode)) {
7802 ql_log(ql_log_warn, vha, 0x0167,
7803 "-> fwdt%u template exceeds array (%-lu bytes)\n",
7804 j, dlen - risc_size * sizeof(*dcode));
7808 fwdt->length = dlen;
7809 ql_dbg(ql_dbg_init, vha, 0x0168,
7810 "-> fwdt%u loaded template ok\n", j);
7812 faddr += risc_size + 1;
7819 vfree(fwdt->template);
7820 fwdt->template = NULL;
7826 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7829 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7833 uint16_t *wcode, *fwcode;
7834 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
7835 struct fw_blob *blob;
7836 struct qla_hw_data *ha = vha->hw;
7837 struct req_que *req = ha->req_q_map[0];
7839 /* Load firmware blob. */
7840 blob = qla2x00_request_firmware(vha);
7842 ql_log(ql_log_info, vha, 0x0083,
7843 "Firmware image unavailable.\n");
7844 ql_log(ql_log_info, vha, 0x0084,
7845 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
7846 return QLA_FUNCTION_FAILED;
7851 wcode = (uint16_t *)req->ring;
7853 fwcode = (uint16_t *)blob->fw->data;
7856 /* Validate firmware image by checking version. */
7857 if (blob->fw->size < 8 * sizeof(uint16_t)) {
7858 ql_log(ql_log_fatal, vha, 0x0085,
7859 "Unable to verify integrity of firmware image (%zd).\n",
7861 goto fail_fw_integrity;
7863 for (i = 0; i < 4; i++)
7864 wcode[i] = be16_to_cpu(fwcode[i + 4]);
7865 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
7866 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
7867 wcode[2] == 0 && wcode[3] == 0)) {
7868 ql_log(ql_log_fatal, vha, 0x0086,
7869 "Unable to verify integrity of firmware image.\n");
7870 ql_log(ql_log_fatal, vha, 0x0087,
7871 "Firmware data: %04x %04x %04x %04x.\n",
7872 wcode[0], wcode[1], wcode[2], wcode[3]);
7873 goto fail_fw_integrity;
7877 while (*seg && rval == QLA_SUCCESS) {
7879 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
7880 risc_size = be16_to_cpu(fwcode[3]);
7882 /* Validate firmware image size. */
7883 fwclen += risc_size * sizeof(uint16_t);
7884 if (blob->fw->size < fwclen) {
7885 ql_log(ql_log_fatal, vha, 0x0088,
7886 "Unable to verify integrity of firmware image "
7887 "(%zd).\n", blob->fw->size);
7888 goto fail_fw_integrity;
7892 while (risc_size > 0 && rval == QLA_SUCCESS) {
7893 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
7894 if (wlen > risc_size)
7896 ql_dbg(ql_dbg_init, vha, 0x0089,
7897 "Loading risc segment@ risc addr %x number of "
7898 "words 0x%x.\n", risc_addr, wlen);
7900 for (i = 0; i < wlen; i++)
7901 wcode[i] = swab16(fwcode[i]);
7903 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7906 ql_log(ql_log_fatal, vha, 0x008a,
7907 "Failed to load segment %d of firmware.\n",
7924 return QLA_FUNCTION_FAILED;
7928 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7931 uint templates, segments, fragment;
7934 uint32_t risc_addr, risc_size, risc_attr = 0;
7937 struct fw_blob *blob;
7939 struct qla_hw_data *ha = vha->hw;
7940 struct req_que *req = ha->req_q_map[0];
7941 struct fwdt *fwdt = ha->fwdt;
7943 ql_dbg(ql_dbg_init, vha, 0x0090,
7944 "-> FW: Loading via request-firmware.\n");
7946 blob = qla2x00_request_firmware(vha);
7948 ql_log(ql_log_warn, vha, 0x0092,
7949 "-> Firmware file not found.\n");
7951 return QLA_FUNCTION_FAILED;
7954 fwcode = (void *)blob->fw->data;
7956 if (qla24xx_risc_firmware_invalid(dcode)) {
7957 ql_log(ql_log_fatal, vha, 0x0093,
7958 "Unable to verify integrity of firmware image (%zd).\n",
7960 ql_log(ql_log_fatal, vha, 0x0095,
7961 "Firmware data: %08x %08x %08x %08x.\n",
7962 dcode[0], dcode[1], dcode[2], dcode[3]);
7963 return QLA_FUNCTION_FAILED;
7966 dcode = (void *)req->ring;
7968 segments = FA_RISC_CODE_SEGMENTS;
7969 for (j = 0; j < segments; j++) {
7970 ql_dbg(ql_dbg_init, vha, 0x0096,
7971 "-> Loading segment %u...\n", j);
7972 risc_addr = be32_to_cpu(fwcode[2]);
7973 risc_size = be32_to_cpu(fwcode[3]);
7976 *srisc_addr = risc_addr;
7977 risc_attr = be32_to_cpu(fwcode[9]);
7980 dlen = ha->fw_transfer_size >> 2;
7981 for (fragment = 0; risc_size; fragment++) {
7982 if (dlen > risc_size)
7985 ql_dbg(ql_dbg_init, vha, 0x0097,
7986 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
7987 fragment, risc_addr,
7988 (uint32_t)(fwcode - (typeof(fwcode))blob->fw->data),
7991 for (i = 0; i < dlen; i++)
7992 dcode[i] = swab32(fwcode[i]);
7994 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7996 ql_log(ql_log_fatal, vha, 0x0098,
7997 "-> Failed load firmware fragment %u.\n",
7999 return QLA_FUNCTION_FAILED;
8008 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8011 templates = (risc_attr & BIT_9) ? 2 : 1;
8012 ql_dbg(ql_dbg_init, vha, 0x0170, "-> templates = %u\n", templates);
8013 for (j = 0; j < templates; j++, fwdt++) {
8015 vfree(fwdt->template);
8016 fwdt->template = NULL;
8019 risc_size = be32_to_cpu(fwcode[2]);
8020 ql_dbg(ql_dbg_init, vha, 0x0171,
8021 "-> fwdt%u template array at %#x (%#x dwords)\n",
8022 j, (uint32_t)((void *)fwcode - (void *)blob->fw->data),
8024 if (!risc_size || !~risc_size) {
8025 ql_dbg(ql_dbg_init, vha, 0x0172,
8026 "-> fwdt%u failed to read array\n", j);
8030 /* skip header and ignore checksum */
8034 ql_dbg(ql_dbg_init, vha, 0x0173,
8035 "-> fwdt%u template allocate template %#x words...\n",
8037 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
8038 if (!fwdt->template) {
8039 ql_log(ql_log_warn, vha, 0x0174,
8040 "-> fwdt%u failed allocate template.\n", j);
8044 dcode = fwdt->template;
8045 for (i = 0; i < risc_size; i++)
8046 dcode[i] = fwcode[i];
8048 if (!qla27xx_fwdt_template_valid(dcode)) {
8049 ql_log(ql_log_warn, vha, 0x0175,
8050 "-> fwdt%u failed template validate\n", j);
8054 dlen = qla27xx_fwdt_template_size(dcode);
8055 ql_dbg(ql_dbg_init, vha, 0x0176,
8056 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8057 j, dlen, dlen / sizeof(*dcode));
8058 if (dlen > risc_size * sizeof(*dcode)) {
8059 ql_log(ql_log_warn, vha, 0x0177,
8060 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8061 j, dlen - risc_size * sizeof(*dcode));
8065 fwdt->length = dlen;
8066 ql_dbg(ql_dbg_init, vha, 0x0178,
8067 "-> fwdt%u loaded template ok\n", j);
8069 fwcode += risc_size + 1;
8076 vfree(fwdt->template);
8077 fwdt->template = NULL;
8084 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8088 if (ql2xfwloadbin == 1)
8089 return qla81xx_load_risc(vha, srisc_addr);
8093 * 1) Firmware via request-firmware interface (.bin file).
8094 * 2) Firmware residing in flash.
8096 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8097 if (rval == QLA_SUCCESS)
8100 return qla24xx_load_risc_flash(vha, srisc_addr,
8101 vha->hw->flt_region_fw);
8105 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8108 struct qla_hw_data *ha = vha->hw;
8109 struct active_regions active_regions = { };
8111 if (ql2xfwloadbin == 2)
8114 /* FW Load priority:
8115 * 1) Firmware residing in flash.
8116 * 2) Firmware via request-firmware interface (.bin file).
8117 * 3) Golden-Firmware residing in flash -- (limited operation).
8120 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8121 goto try_primary_fw;
8123 qla27xx_get_active_image(vha, &active_regions);
8125 if (active_regions.global != QLA27XX_SECONDARY_IMAGE)
8126 goto try_primary_fw;
8128 ql_dbg(ql_dbg_init, vha, 0x008b,
8129 "Loading secondary firmware image.\n");
8130 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw_sec);
8135 ql_dbg(ql_dbg_init, vha, 0x008b,
8136 "Loading primary firmware image.\n");
8137 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
8142 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8143 if (!rval || !ha->flt_region_gold_fw)
8146 ql_log(ql_log_info, vha, 0x0099,
8147 "Attempting to fallback to golden firmware.\n");
8148 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
8152 ql_log(ql_log_info, vha, 0x009a, "Need firmware flash update.\n");
8153 ha->flags.running_gold_fw = 1;
8158 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
8161 struct qla_hw_data *ha = vha->hw;
8163 if (ha->flags.pci_channel_io_perm_failure)
8165 if (!IS_FWI2_CAPABLE(ha))
8167 if (!ha->fw_major_version)
8169 if (!ha->flags.fw_started)
8172 ret = qla2x00_stop_firmware(vha);
8173 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
8174 ret != QLA_INVALID_COMMAND && retries ; retries--) {
8175 ha->isp_ops->reset_chip(vha);
8176 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
8178 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
8180 ql_log(ql_log_info, vha, 0x8015,
8181 "Attempting retry of stop-firmware command.\n");
8182 ret = qla2x00_stop_firmware(vha);
8186 ha->flags.fw_init_done = 0;
8190 qla24xx_configure_vhba(scsi_qla_host_t *vha)
8192 int rval = QLA_SUCCESS;
8194 uint16_t mb[MAILBOX_REGISTER_COUNT];
8195 struct qla_hw_data *ha = vha->hw;
8196 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
8201 rval = qla2x00_fw_ready(base_vha);
8203 if (rval == QLA_SUCCESS) {
8204 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8205 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8208 vha->flags.management_server_logged_in = 0;
8210 /* Login to SNS first */
8211 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
8213 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
8214 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
8215 ql_dbg(ql_dbg_init, vha, 0x0120,
8216 "Failed SNS login: loop_id=%x, rval2=%d\n",
8219 ql_dbg(ql_dbg_init, vha, 0x0103,
8220 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
8221 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
8222 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
8223 return (QLA_FUNCTION_FAILED);
8226 atomic_set(&vha->loop_down_timer, 0);
8227 atomic_set(&vha->loop_state, LOOP_UP);
8228 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8229 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
8230 rval = qla2x00_loop_resync(base_vha);
8235 /* 84XX Support **************************************************************/
8237 static LIST_HEAD(qla_cs84xx_list);
8238 static DEFINE_MUTEX(qla_cs84xx_mutex);
8240 static struct qla_chip_state_84xx *
8241 qla84xx_get_chip(struct scsi_qla_host *vha)
8243 struct qla_chip_state_84xx *cs84xx;
8244 struct qla_hw_data *ha = vha->hw;
8246 mutex_lock(&qla_cs84xx_mutex);
8248 /* Find any shared 84xx chip. */
8249 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
8250 if (cs84xx->bus == ha->pdev->bus) {
8251 kref_get(&cs84xx->kref);
8256 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
8260 kref_init(&cs84xx->kref);
8261 spin_lock_init(&cs84xx->access_lock);
8262 mutex_init(&cs84xx->fw_update_mutex);
8263 cs84xx->bus = ha->pdev->bus;
8265 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
8267 mutex_unlock(&qla_cs84xx_mutex);
8272 __qla84xx_chip_release(struct kref *kref)
8274 struct qla_chip_state_84xx *cs84xx =
8275 container_of(kref, struct qla_chip_state_84xx, kref);
8277 mutex_lock(&qla_cs84xx_mutex);
8278 list_del(&cs84xx->list);
8279 mutex_unlock(&qla_cs84xx_mutex);
8284 qla84xx_put_chip(struct scsi_qla_host *vha)
8286 struct qla_hw_data *ha = vha->hw;
8289 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
8293 qla84xx_init_chip(scsi_qla_host_t *vha)
8297 struct qla_hw_data *ha = vha->hw;
8299 mutex_lock(&ha->cs84xx->fw_update_mutex);
8301 rval = qla84xx_verify_chip(vha, status);
8303 mutex_unlock(&ha->cs84xx->fw_update_mutex);
8305 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED :
8309 /* 81XX Support **************************************************************/
8312 qla81xx_nvram_config(scsi_qla_host_t *vha)
8315 struct init_cb_81xx *icb;
8316 struct nvram_81xx *nv;
8318 uint8_t *dptr1, *dptr2;
8321 struct qla_hw_data *ha = vha->hw;
8323 struct active_regions active_regions = { };
8326 icb = (struct init_cb_81xx *)ha->init_cb;
8329 /* Determine NVRAM starting address. */
8330 ha->nvram_size = sizeof(*nv);
8331 ha->vpd_size = FA_NVRAM_VPD_SIZE;
8332 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
8333 ha->vpd_size = FA_VPD_SIZE_82XX;
8335 if (IS_QLA28XX(ha) || IS_QLA27XX(ha))
8336 qla28xx_get_aux_images(vha, &active_regions);
8338 /* Get VPD data into cache */
8339 ha->vpd = ha->nvram + VPD_OFFSET;
8341 faddr = ha->flt_region_vpd;
8342 if (IS_QLA28XX(ha)) {
8343 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8344 faddr = ha->flt_region_vpd_sec;
8345 ql_dbg(ql_dbg_init, vha, 0x0110,
8346 "Loading %s nvram image.\n",
8347 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8348 "primary" : "secondary");
8350 ha->isp_ops->read_optrom(vha, ha->vpd, faddr << 2, ha->vpd_size);
8352 /* Get NVRAM data into cache and calculate checksum. */
8353 faddr = ha->flt_region_nvram;
8354 if (IS_QLA28XX(ha)) {
8355 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8356 faddr = ha->flt_region_nvram_sec;
8358 ql_dbg(ql_dbg_init, vha, 0x0110,
8359 "Loading %s nvram image.\n",
8360 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8361 "primary" : "secondary");
8362 ha->isp_ops->read_optrom(vha, ha->nvram, faddr << 2, ha->nvram_size);
8364 dptr = (uint32_t *)nv;
8365 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
8366 chksum += le32_to_cpu(*dptr);
8368 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
8369 "Contents of NVRAM:\n");
8370 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
8371 nv, ha->nvram_size);
8373 /* Bad NVRAM data, set defaults parameters. */
8374 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
8375 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
8376 /* Reset NVRAM data. */
8377 ql_log(ql_log_info, vha, 0x0073,
8378 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
8379 chksum, nv->id, le16_to_cpu(nv->nvram_version));
8380 ql_dump_buffer(ql_dbg_init, vha, 0x0073, nv, sizeof(*nv));
8381 ql_log(ql_log_info, vha, 0x0074,
8382 "Falling back to functioning (yet invalid -- WWPN) "
8386 * Set default initialization control block.
8388 memset(nv, 0, ha->nvram_size);
8389 nv->nvram_version = cpu_to_le16(ICB_VERSION);
8390 nv->version = cpu_to_le16(ICB_VERSION);
8391 nv->frame_payload_size = 2048;
8392 nv->execution_throttle = cpu_to_le16(0xFFFF);
8393 nv->exchange_count = cpu_to_le16(0);
8394 nv->port_name[0] = 0x21;
8395 nv->port_name[1] = 0x00 + ha->port_no + 1;
8396 nv->port_name[2] = 0x00;
8397 nv->port_name[3] = 0xe0;
8398 nv->port_name[4] = 0x8b;
8399 nv->port_name[5] = 0x1c;
8400 nv->port_name[6] = 0x55;
8401 nv->port_name[7] = 0x86;
8402 nv->node_name[0] = 0x20;
8403 nv->node_name[1] = 0x00;
8404 nv->node_name[2] = 0x00;
8405 nv->node_name[3] = 0xe0;
8406 nv->node_name[4] = 0x8b;
8407 nv->node_name[5] = 0x1c;
8408 nv->node_name[6] = 0x55;
8409 nv->node_name[7] = 0x86;
8410 nv->login_retry_count = cpu_to_le16(8);
8411 nv->interrupt_delay_timer = cpu_to_le16(0);
8412 nv->login_timeout = cpu_to_le16(0);
8413 nv->firmware_options_1 =
8414 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
8415 nv->firmware_options_2 = cpu_to_le32(2 << 4);
8416 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
8417 nv->firmware_options_3 = cpu_to_le32(2 << 13);
8418 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
8419 nv->efi_parameters = cpu_to_le32(0);
8420 nv->reset_delay = 5;
8421 nv->max_luns_per_target = cpu_to_le16(128);
8422 nv->port_down_retry_count = cpu_to_le16(30);
8423 nv->link_down_timeout = cpu_to_le16(180);
8424 nv->enode_mac[0] = 0x00;
8425 nv->enode_mac[1] = 0xC0;
8426 nv->enode_mac[2] = 0xDD;
8427 nv->enode_mac[3] = 0x04;
8428 nv->enode_mac[4] = 0x05;
8429 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
8434 if (IS_T10_PI_CAPABLE(ha))
8435 nv->frame_payload_size &= ~7;
8437 qlt_81xx_config_nvram_stage1(vha, nv);
8439 /* Reset Initialization control block */
8440 memset(icb, 0, ha->init_cb_size);
8442 /* Copy 1st segment. */
8443 dptr1 = (uint8_t *)icb;
8444 dptr2 = (uint8_t *)&nv->version;
8445 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
8447 *dptr1++ = *dptr2++;
8449 icb->login_retry_count = nv->login_retry_count;
8451 /* Copy 2nd segment. */
8452 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
8453 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
8454 cnt = (uint8_t *)&icb->reserved_5 -
8455 (uint8_t *)&icb->interrupt_delay_timer;
8457 *dptr1++ = *dptr2++;
8459 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
8460 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8461 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
8462 icb->enode_mac[0] = 0x00;
8463 icb->enode_mac[1] = 0xC0;
8464 icb->enode_mac[2] = 0xDD;
8465 icb->enode_mac[3] = 0x04;
8466 icb->enode_mac[4] = 0x05;
8467 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
8470 /* Use extended-initialization control block. */
8471 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
8472 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
8474 * Setup driver NVRAM options.
8476 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
8479 qlt_81xx_config_nvram_stage2(vha, icb);
8481 /* Use alternate WWN? */
8482 if (nv->host_p & cpu_to_le32(BIT_15)) {
8483 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
8484 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
8487 /* Prepare nodename */
8488 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
8490 * Firmware will apply the following mask if the nodename was
8493 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
8494 icb->node_name[0] &= 0xF0;
8497 /* Set host adapter parameters. */
8498 ha->flags.disable_risc_code_load = 0;
8499 ha->flags.enable_lip_reset = 0;
8500 ha->flags.enable_lip_full_login =
8501 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
8502 ha->flags.enable_target_reset =
8503 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
8504 ha->flags.enable_led_scheme = 0;
8505 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
8507 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
8508 (BIT_6 | BIT_5 | BIT_4)) >> 4;
8510 /* save HBA serial number */
8511 ha->serial0 = icb->port_name[5];
8512 ha->serial1 = icb->port_name[6];
8513 ha->serial2 = icb->port_name[7];
8514 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
8515 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
8517 icb->execution_throttle = cpu_to_le16(0xFFFF);
8519 ha->retry_count = le16_to_cpu(nv->login_retry_count);
8521 /* Set minimum login_timeout to 4 seconds. */
8522 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
8523 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
8524 if (le16_to_cpu(nv->login_timeout) < 4)
8525 nv->login_timeout = cpu_to_le16(4);
8526 ha->login_timeout = le16_to_cpu(nv->login_timeout);
8528 /* Set minimum RATOV to 100 tenths of a second. */
8531 ha->loop_reset_delay = nv->reset_delay;
8533 /* Link Down Timeout = 0:
8535 * When Port Down timer expires we will start returning
8536 * I/O's to OS with "DID_NO_CONNECT".
8538 * Link Down Timeout != 0:
8540 * The driver waits for the link to come up after link down
8541 * before returning I/Os to OS with "DID_NO_CONNECT".
8543 if (le16_to_cpu(nv->link_down_timeout) == 0) {
8544 ha->loop_down_abort_time =
8545 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
8547 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
8548 ha->loop_down_abort_time =
8549 (LOOP_DOWN_TIME - ha->link_down_timeout);
8552 /* Need enough time to try and get the port back. */
8553 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8554 if (qlport_down_retry)
8555 ha->port_down_retry_count = qlport_down_retry;
8557 /* Set login_retry_count */
8558 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8559 if (ha->port_down_retry_count ==
8560 le16_to_cpu(nv->port_down_retry_count) &&
8561 ha->port_down_retry_count > 3)
8562 ha->login_retry_count = ha->port_down_retry_count;
8563 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8564 ha->login_retry_count = ha->port_down_retry_count;
8565 if (ql2xloginretrycount)
8566 ha->login_retry_count = ql2xloginretrycount;
8568 /* if not running MSI-X we need handshaking on interrupts */
8569 if (!vha->hw->flags.msix_enabled &&
8570 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)))
8571 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
8574 if (!vha->flags.init_done) {
8575 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8576 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8577 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8578 le16_to_cpu(icb->interrupt_delay_timer) : 2;
8580 icb->firmware_options_2 &= cpu_to_le32(
8581 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8582 vha->flags.process_response_queue = 0;
8583 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8584 ha->zio_mode = QLA_ZIO_MODE_6;
8586 ql_log(ql_log_info, vha, 0x0075,
8587 "ZIO mode %d enabled; timer delay (%d us).\n",
8589 ha->zio_timer * 100);
8591 icb->firmware_options_2 |= cpu_to_le32(
8592 (uint32_t)ha->zio_mode);
8593 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8594 vha->flags.process_response_queue = 1;
8597 /* enable RIDA Format2 */
8598 icb->firmware_options_3 |= BIT_0;
8600 /* N2N: driver will initiate Login instead of FW */
8601 icb->firmware_options_3 |= BIT_8;
8603 /* Determine NVMe/FCP priority for target ports */
8604 ha->fc4_type_priority = qla2xxx_get_fc4_priority(vha);
8605 ql_log(ql_log_info, vha, 0xffff, "FC4 priority set to %s\n",
8606 ha->fc4_type_priority & BIT_0 ? "FCP" : "NVMe");
8609 ql_log(ql_log_warn, vha, 0x0076,
8610 "NVRAM configuration failed.\n");
8616 qla82xx_restart_isp(scsi_qla_host_t *vha)
8619 struct qla_hw_data *ha = vha->hw;
8620 struct scsi_qla_host *vp;
8621 unsigned long flags;
8623 status = qla2x00_init_rings(vha);
8625 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8626 ha->flags.chip_reset_done = 1;
8628 status = qla2x00_fw_ready(vha);
8630 /* Issue a marker after FW becomes ready. */
8631 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8632 vha->flags.online = 1;
8633 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8636 /* if no cable then assume it's good */
8637 if ((vha->device_flags & DFLG_NO_CABLE))
8642 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8644 if (!atomic_read(&vha->loop_down_timer)) {
8646 * Issue marker command only when we are going
8647 * to start the I/O .
8649 vha->marker_needed = 1;
8652 ha->isp_ops->enable_intrs(ha);
8654 ha->isp_abort_cnt = 0;
8655 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
8657 /* Update the firmware version */
8658 status = qla82xx_check_md_needed(vha);
8661 ha->flags.fce_enabled = 1;
8663 fce_calc_size(ha->fce_bufs));
8664 rval = qla2x00_enable_fce_trace(vha,
8665 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
8668 ql_log(ql_log_warn, vha, 0x8001,
8669 "Unable to reinitialize FCE (%d).\n",
8671 ha->flags.fce_enabled = 0;
8676 memset(ha->eft, 0, EFT_SIZE);
8677 rval = qla2x00_enable_eft_trace(vha,
8678 ha->eft_dma, EFT_NUM_BUFFERS);
8680 ql_log(ql_log_warn, vha, 0x8010,
8681 "Unable to reinitialize EFT (%d).\n",
8688 ql_dbg(ql_dbg_taskm, vha, 0x8011,
8689 "qla82xx_restart_isp succeeded.\n");
8691 spin_lock_irqsave(&ha->vport_slock, flags);
8692 list_for_each_entry(vp, &ha->vp_list, list) {
8694 atomic_inc(&vp->vref_count);
8695 spin_unlock_irqrestore(&ha->vport_slock, flags);
8697 qla2x00_vp_abort_isp(vp);
8699 spin_lock_irqsave(&ha->vport_slock, flags);
8700 atomic_dec(&vp->vref_count);
8703 spin_unlock_irqrestore(&ha->vport_slock, flags);
8706 ql_log(ql_log_warn, vha, 0x8016,
8707 "qla82xx_restart_isp **** FAILED ****.\n");
8714 qla81xx_update_fw_options(scsi_qla_host_t *vha)
8716 struct qla_hw_data *ha = vha->hw;
8718 /* Hold status IOCBs until ABTS response received. */
8720 ha->fw_options[3] |= BIT_12;
8722 /* Set Retry FLOGI in case of P2P connection */
8723 if (ha->operating_mode == P2P) {
8724 ha->fw_options[2] |= BIT_3;
8725 ql_dbg(ql_dbg_disc, vha, 0x2103,
8726 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8727 __func__, ha->fw_options[2]);
8730 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8731 if (ql2xmvasynctoatio) {
8732 if (qla_tgt_mode_enabled(vha) ||
8733 qla_dual_mode_enabled(vha))
8734 ha->fw_options[2] |= BIT_11;
8736 ha->fw_options[2] &= ~BIT_11;
8739 if (qla_tgt_mode_enabled(vha) ||
8740 qla_dual_mode_enabled(vha)) {
8741 /* FW auto send SCSI status during */
8742 ha->fw_options[1] |= BIT_8;
8743 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
8745 /* FW perform Exchange validation */
8746 ha->fw_options[2] |= BIT_4;
8748 ha->fw_options[1] &= ~BIT_8;
8749 ha->fw_options[10] &= 0x00ff;
8751 ha->fw_options[2] &= ~BIT_4;
8754 if (ql2xetsenable) {
8755 /* Enable ETS Burst. */
8756 memset(ha->fw_options, 0, sizeof(ha->fw_options));
8757 ha->fw_options[2] |= BIT_9;
8760 ql_dbg(ql_dbg_init, vha, 0x00e9,
8761 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8762 __func__, ha->fw_options[1], ha->fw_options[2],
8763 ha->fw_options[3], vha->host->active_mode);
8765 qla2x00_set_fw_options(vha, ha->fw_options);
8769 * qla24xx_get_fcp_prio
8770 * Gets the fcp cmd priority value for the logged in port.
8771 * Looks for a match of the port descriptors within
8772 * each of the fcp prio config entries. If a match is found,
8773 * the tag (priority) value is returned.
8776 * vha = scsi host structure pointer.
8777 * fcport = port structure pointer.
8780 * non-zero (if found)
8787 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8790 uint8_t pid_match, wwn_match;
8792 uint32_t pid1, pid2;
8793 uint64_t wwn1, wwn2;
8794 struct qla_fcp_prio_entry *pri_entry;
8795 struct qla_hw_data *ha = vha->hw;
8797 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
8801 entries = ha->fcp_prio_cfg->num_entries;
8802 pri_entry = &ha->fcp_prio_cfg->entry[0];
8804 for (i = 0; i < entries; i++) {
8805 pid_match = wwn_match = 0;
8807 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
8812 /* check source pid for a match */
8813 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
8814 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
8815 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
8816 if (pid1 == INVALID_PORT_ID)
8818 else if (pid1 == pid2)
8822 /* check destination pid for a match */
8823 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
8824 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
8825 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
8826 if (pid1 == INVALID_PORT_ID)
8828 else if (pid1 == pid2)
8832 /* check source WWN for a match */
8833 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
8834 wwn1 = wwn_to_u64(vha->port_name);
8835 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
8836 if (wwn2 == (uint64_t)-1)
8838 else if (wwn1 == wwn2)
8842 /* check destination WWN for a match */
8843 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
8844 wwn1 = wwn_to_u64(fcport->port_name);
8845 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
8846 if (wwn2 == (uint64_t)-1)
8848 else if (wwn1 == wwn2)
8852 if (pid_match == 2 || wwn_match == 2) {
8853 /* Found a matching entry */
8854 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
8855 priority = pri_entry->tag;
8866 * qla24xx_update_fcport_fcp_prio
8867 * Activates fcp priority for the logged in fc port
8870 * vha = scsi host structure pointer.
8871 * fcp = port structure pointer.
8874 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8880 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8886 if (fcport->port_type != FCT_TARGET ||
8887 fcport->loop_id == FC_NO_LOOP_ID)
8888 return QLA_FUNCTION_FAILED;
8890 priority = qla24xx_get_fcp_prio(vha, fcport);
8892 return QLA_FUNCTION_FAILED;
8894 if (IS_P3P_TYPE(vha->hw)) {
8895 fcport->fcp_prio = priority & 0xf;
8899 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
8900 if (ret == QLA_SUCCESS) {
8901 if (fcport->fcp_prio != priority)
8902 ql_dbg(ql_dbg_user, vha, 0x709e,
8903 "Updated FCP_CMND priority - value=%d loop_id=%d "
8904 "port_id=%02x%02x%02x.\n", priority,
8905 fcport->loop_id, fcport->d_id.b.domain,
8906 fcport->d_id.b.area, fcport->d_id.b.al_pa);
8907 fcport->fcp_prio = priority & 0xf;
8909 ql_dbg(ql_dbg_user, vha, 0x704f,
8910 "Unable to update FCP_CMND priority - ret=0x%x for "
8911 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
8912 fcport->d_id.b.domain, fcport->d_id.b.area,
8913 fcport->d_id.b.al_pa);
8918 * qla24xx_update_all_fcp_prio
8919 * Activates fcp priority for all the logged in ports
8922 * ha = adapter block pointer.
8925 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8931 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
8936 ret = QLA_FUNCTION_FAILED;
8937 /* We need to set priority for all logged in ports */
8938 list_for_each_entry(fcport, &vha->vp_fcports, list)
8939 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
8944 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
8945 int vp_idx, bool startqp)
8950 struct qla_hw_data *ha = vha->hw;
8951 uint16_t qpair_id = 0;
8952 struct qla_qpair *qpair = NULL;
8953 struct qla_msix_entry *msix;
8955 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
8956 ql_log(ql_log_warn, vha, 0x00181,
8957 "FW/Driver is not multi-queue capable.\n");
8961 if (ql2xmqsupport || ql2xnvmeenable) {
8962 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
8963 if (qpair == NULL) {
8964 ql_log(ql_log_warn, vha, 0x0182,
8965 "Failed to allocate memory for queue pair.\n");
8969 qpair->hw = vha->hw;
8971 qpair->qp_lock_ptr = &qpair->qp_lock;
8972 spin_lock_init(&qpair->qp_lock);
8973 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
8975 /* Assign available que pair id */
8976 mutex_lock(&ha->mq_lock);
8977 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
8978 if (ha->num_qpairs >= ha->max_qpairs) {
8979 mutex_unlock(&ha->mq_lock);
8980 ql_log(ql_log_warn, vha, 0x0183,
8981 "No resources to create additional q pair.\n");
8985 set_bit(qpair_id, ha->qpair_qid_map);
8986 ha->queue_pair_map[qpair_id] = qpair;
8987 qpair->id = qpair_id;
8988 qpair->vp_idx = vp_idx;
8989 qpair->fw_started = ha->flags.fw_started;
8990 INIT_LIST_HEAD(&qpair->hints_list);
8991 qpair->chip_reset = ha->base_qpair->chip_reset;
8992 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
8993 qpair->enable_explicit_conf =
8994 ha->base_qpair->enable_explicit_conf;
8996 for (i = 0; i < ha->msix_count; i++) {
8997 msix = &ha->msix_entries[i];
9001 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
9002 "Vector %x selected for qpair\n", msix->vector);
9006 ql_log(ql_log_warn, vha, 0x0184,
9007 "Out of MSI-X vectors!.\n");
9011 qpair->msix->in_use = 1;
9012 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
9013 qpair->pdev = ha->pdev;
9014 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
9015 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
9017 mutex_unlock(&ha->mq_lock);
9019 /* Create response queue first */
9020 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
9022 ql_log(ql_log_warn, vha, 0x0185,
9023 "Failed to create response queue.\n");
9027 qpair->rsp = ha->rsp_q_map[rsp_id];
9029 /* Create request queue */
9030 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
9033 ql_log(ql_log_warn, vha, 0x0186,
9034 "Failed to create request queue.\n");
9038 qpair->req = ha->req_q_map[req_id];
9039 qpair->rsp->req = qpair->req;
9040 qpair->rsp->qpair = qpair;
9041 /* init qpair to this cpu. Will adjust at run time. */
9042 qla_cpu_update(qpair, raw_smp_processor_id());
9044 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
9045 if (ha->fw_attributes & BIT_4)
9046 qpair->difdix_supported = 1;
9049 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
9050 if (!qpair->srb_mempool) {
9051 ql_log(ql_log_warn, vha, 0xd036,
9052 "Failed to create srb mempool for qpair %d\n",
9057 /* Mark as online */
9060 if (!vha->flags.qpairs_available)
9061 vha->flags.qpairs_available = 1;
9063 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
9064 "Request/Response queue pair created, id %d\n",
9066 ql_dbg(ql_dbg_init, vha, 0x0187,
9067 "Request/Response queue pair created, id %d\n",
9074 qla25xx_delete_rsp_que(vha, qpair->rsp);
9076 mutex_lock(&ha->mq_lock);
9077 qpair->msix->in_use = 0;
9078 list_del(&qpair->qp_list_elem);
9079 if (list_empty(&vha->qp_list))
9080 vha->flags.qpairs_available = 0;
9082 ha->queue_pair_map[qpair_id] = NULL;
9083 clear_bit(qpair_id, ha->qpair_qid_map);
9085 mutex_unlock(&ha->mq_lock);
9091 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
9093 int ret = QLA_FUNCTION_FAILED;
9094 struct qla_hw_data *ha = qpair->hw;
9096 qpair->delete_in_progress = 1;
9098 ret = qla25xx_delete_req_que(vha, qpair->req);
9099 if (ret != QLA_SUCCESS)
9102 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
9103 if (ret != QLA_SUCCESS)
9106 mutex_lock(&ha->mq_lock);
9107 ha->queue_pair_map[qpair->id] = NULL;
9108 clear_bit(qpair->id, ha->qpair_qid_map);
9110 list_del(&qpair->qp_list_elem);
9111 if (list_empty(&vha->qp_list)) {
9112 vha->flags.qpairs_available = 0;
9113 vha->flags.qpairs_req_created = 0;
9114 vha->flags.qpairs_rsp_created = 0;
9116 mempool_destroy(qpair->srb_mempool);
9118 mutex_unlock(&ha->mq_lock);