Blame SOURCES/0134-scsi-scsi-qla2xxx-Fix-N2N-link-reset.patch

3c6e85
From 6292615948dbabf20ccde5ec088480ae712637b5 Mon Sep 17 00:00:00 2001
3c6e85
From: Himanshu Madhani <hmadhani@redhat.com>
3c6e85
Date: Thu, 21 Nov 2019 16:36:44 -0500
3c6e85
Subject: [PATCH 134/155] [scsi] scsi: qla2xxx: Fix N2N link reset
3c6e85
3c6e85
Message-id: <20191121163701.43688-10-hmadhani@redhat.com>
3c6e85
Patchwork-id: 287870
3c6e85
O-Subject: [RHLE 7.8 e-stor PATCH v3 09/26] scsi: qla2xxx: Fix N2N link reset
3c6e85
Bugzilla: 1731581
3c6e85
RH-Acked-by: Jarod Wilson <jarod@redhat.com>
3c6e85
RH-Acked-by: Ewan Milne <emilne@redhat.com>
3c6e85
RH-Acked-by: Tony Camuso <tcamuso@redhat.com>
3c6e85
3c6e85
From: Quinn Tran <qutran@marvell.com>
3c6e85
3c6e85
Bugzilla 1731581
3c6e85
3c6e85
Fix stalled link recovery for N2N with FC-NVMe connection.
3c6e85
3c6e85
Link: https://lore.kernel.org/r/20190912180918.6436-6-hmadhani@marvell.com
3c6e85
Signed-off-by: Quinn Tran <qutran@marvell.com>
3c6e85
Signed-off-by: Himanshu Madhani <hmadhani@marvell.com>
3c6e85
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
3c6e85
(cherry picked from commit 7f2a398d59d658818f3d219645164676fbbc88e8)
3c6e85
Signed-off-by: Himanshu Madhani <hmadhani@redhat.com>
3c6e85
Signed-off-by: Jan Stancek <jstancek@redhat.com>
3c6e85
---
3c6e85
 drivers/scsi/qla2xxx/qla_def.h  |   3 +-
3c6e85
 drivers/scsi/qla2xxx/qla_init.c | 107 +++++++++++++++++++++++++++++-----------
3c6e85
 drivers/scsi/qla2xxx/qla_mbx.c  |  23 +++++++--
3c6e85
 drivers/scsi/qla2xxx/qla_os.c   |   4 ++
3c6e85
 4 files changed, 103 insertions(+), 34 deletions(-)
3c6e85
3c6e85
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
3c6e85
index 3f6319edabd4..9108762875ed 100644
3c6e85
--- a/drivers/scsi/qla2xxx/qla_def.h
3c6e85
+++ b/drivers/scsi/qla2xxx/qla_def.h
3c6e85
@@ -2379,6 +2379,7 @@ typedef struct fc_port {
3c6e85
 	unsigned int query:1;
3c6e85
 	unsigned int id_changed:1;
3c6e85
 	unsigned int scan_needed:1;
3c6e85
+	unsigned int n2n_flag:1;
3c6e85
 
3c6e85
 	struct completion nvme_del_done;
3c6e85
 	uint32_t nvme_prli_service_param;
3c6e85
@@ -2429,7 +2430,6 @@ typedef struct fc_port {
3c6e85
 	uint8_t fc4_type;
3c6e85
 	uint8_t	fc4f_nvme;
3c6e85
 	uint8_t scan_state;
3c6e85
-	uint8_t n2n_flag;
3c6e85
 
3c6e85
 	unsigned long last_queue_full;
3c6e85
 	unsigned long last_ramp_up;
3c6e85
@@ -3020,6 +3020,7 @@ enum scan_flags_t {
3c6e85
 enum fc4type_t {
3c6e85
 	FS_FC4TYPE_FCP	= BIT_0,
3c6e85
 	FS_FC4TYPE_NVME	= BIT_1,
3c6e85
+	FS_FCP_IS_N2N = BIT_7,
3c6e85
 };
3c6e85
 
3c6e85
 struct fab_scan_rp {
3c6e85
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
3c6e85
index 8da5ef9e19f5..fc30eda330a4 100644
3c6e85
--- a/drivers/scsi/qla2xxx/qla_init.c
3c6e85
+++ b/drivers/scsi/qla2xxx/qla_init.c
3c6e85
@@ -757,12 +757,15 @@ static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
3c6e85
 			break;
3c6e85
 		default:
3c6e85
 			if ((id.b24 != fcport->d_id.b24 &&
3c6e85
-			    fcport->d_id.b24) ||
3c6e85
+			    fcport->d_id.b24 &&
3c6e85
+			    fcport->loop_id != FC_NO_LOOP_ID) ||
3c6e85
 			    (fcport->loop_id != FC_NO_LOOP_ID &&
3c6e85
 				fcport->loop_id != loop_id)) {
3c6e85
 				ql_dbg(ql_dbg_disc, vha, 0x20e3,
3c6e85
 				    "%s %d %8phC post del sess\n",
3c6e85
 				    __func__, __LINE__, fcport->port_name);
3c6e85
+				if (fcport->n2n_flag)
3c6e85
+					fcport->d_id.b24 = 0;
3c6e85
 				qlt_schedule_sess_for_deletion(fcport);
3c6e85
 				return;
3c6e85
 			}
3c6e85
@@ -770,6 +773,8 @@ static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
3c6e85
 		}
3c6e85
 
3c6e85
 		fcport->loop_id = loop_id;
3c6e85
+		if (fcport->n2n_flag)
3c6e85
+			fcport->d_id.b24 = id.b24;
3c6e85
 
3c6e85
 		wwn = wwn_to_u64(fcport->port_name);
3c6e85
 		qlt_find_sess_invalidate_other(vha, wwn,
3c6e85
@@ -986,7 +991,7 @@ qla24xx_async_gnl_sp_done(void *s, int res)
3c6e85
 		wwn = wwn_to_u64(e->port_name);
3c6e85
 
3c6e85
 		ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8,
3c6e85
-		    "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
3c6e85
+		    "%s %8phC %02x:%02x:%02x CLS %x/%x lid %x \n",
3c6e85
 		    __func__, (void *)&wwn, e->port_id[2], e->port_id[1],
3c6e85
 		    e->port_id[0], e->current_login_state, e->last_login_state,
3c6e85
 		    (loop_id & 0x7fff));
3c6e85
@@ -1519,7 +1524,8 @@ int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
3c6e85
 	     (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
3c6e85
 		return 0;
3c6e85
 
3c6e85
-	if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
3c6e85
+	if (fcport->fw_login_state == DSC_LS_PLOGI_COMP &&
3c6e85
+	    !N2N_TOPO(vha->hw)) {
3c6e85
 		if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
3c6e85
 			set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3c6e85
 			return 0;
3c6e85
@@ -1590,8 +1596,9 @@ int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
3c6e85
 				qla24xx_post_gpdb_work(vha, fcport, 0);
3c6e85
 			}  else {
3c6e85
 				ql_dbg(ql_dbg_disc, vha, 0x2118,
3c6e85
-				    "%s %d %8phC post NVMe PRLI\n",
3c6e85
-				    __func__, __LINE__, fcport->port_name);
3c6e85
+				    "%s %d %8phC post %s PRLI\n",
3c6e85
+				    __func__, __LINE__, fcport->port_name,
3c6e85
+				    fcport->fc4f_nvme ? "NVME" : "FC");
3c6e85
 				qla24xx_post_prli_work(vha, fcport);
3c6e85
 			}
3c6e85
 			break;
3c6e85
@@ -1934,17 +1941,38 @@ qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
3c6e85
 			break;
3c6e85
 		}
3c6e85
 
3c6e85
-		if (ea->fcport->n2n_flag) {
3c6e85
+		if (ea->fcport->fc4f_nvme) {
3c6e85
 			ql_dbg(ql_dbg_disc, vha, 0x2118,
3c6e85
 				"%s %d %8phC post fc4 prli\n",
3c6e85
 				__func__, __LINE__, ea->fcport->port_name);
3c6e85
 			ea->fcport->fc4f_nvme = 0;
3c6e85
-			ea->fcport->n2n_flag = 0;
3c6e85
 			qla24xx_post_prli_work(vha, ea->fcport);
3c6e85
+			return;
3c6e85
+		}
3c6e85
+
3c6e85
+		/* at this point both PRLI NVME & PRLI FCP failed */
3c6e85
+		if (N2N_TOPO(vha->hw)) {
3c6e85
+			if (ea->fcport->n2n_link_reset_cnt < 3) {
3c6e85
+				ea->fcport->n2n_link_reset_cnt++;
3c6e85
+				/*
3c6e85
+				 * remote port is not sending Plogi. Reset
3c6e85
+				 * link to kick start his state machine
3c6e85
+				 */
3c6e85
+				set_bit(N2N_LINK_RESET, &vha->dpc_flags);
3c6e85
+			} else {
3c6e85
+				ql_log(ql_log_warn, vha, 0x2119,
3c6e85
+				    "%s %d %8phC Unable to reconnect\n",
3c6e85
+				    __func__, __LINE__, ea->fcport->port_name);
3c6e85
+			}
3c6e85
+		} else {
3c6e85
+			/*
3c6e85
+			 * switch connect. login failed. Take connection
3c6e85
+			 * down and allow relogin to retrigger
3c6e85
+			 */
3c6e85
+			ea->fcport->flags &= ~FCF_ASYNC_SENT;
3c6e85
+			ea->fcport->keep_nport_handle = 0;
3c6e85
+			qlt_schedule_sess_for_deletion(ea->fcport);
3c6e85
 		}
3c6e85
-		ql_dbg(ql_dbg_disc, vha, 0x2119,
3c6e85
-		    "%s %d %8phC unhandle event of %x\n",
3c6e85
-		    __func__, __LINE__, ea->fcport->port_name, ea->data[0]);
3c6e85
 		break;
3c6e85
 	}
3c6e85
 }
3c6e85
@@ -5095,28 +5123,47 @@ qla2x00_configure_local_loop(scsi_qla_host_t *vha)
3c6e85
 	unsigned long flags;
3c6e85
 
3c6e85
 	/* Inititae N2N login. */
3c6e85
-	if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) {
3c6e85
-		/* borrowing */
3c6e85
-		u32 *bp, i, sz;
3c6e85
-
3c6e85
-		memset(ha->init_cb, 0, ha->init_cb_size);
3c6e85
-		sz = min_t(int, sizeof(struct els_plogi_payload),
3c6e85
-		    ha->init_cb_size);
3c6e85
-		rval = qla24xx_get_port_login_templ(vha, ha->init_cb_dma,
3c6e85
-		    (void *)ha->init_cb, sz);
3c6e85
-		if (rval == QLA_SUCCESS) {
3c6e85
-			bp = (uint32_t *)ha->init_cb;
3c6e85
-			for (i = 0; i < sz/4 ; i++, bp++)
3c6e85
-				*bp = cpu_to_be32(*bp);
3c6e85
+	if (N2N_TOPO(ha)) {
3c6e85
+		if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) {
3c6e85
+			/* borrowing */
3c6e85
+			u32 *bp, i, sz;
3c6e85
+
3c6e85
+			memset(ha->init_cb, 0, ha->init_cb_size);
3c6e85
+			sz = min_t(int, sizeof(struct els_plogi_payload),
3c6e85
+			    ha->init_cb_size);
3c6e85
+			rval = qla24xx_get_port_login_templ(vha,
3c6e85
+			    ha->init_cb_dma, (void *)ha->init_cb, sz);
3c6e85
+			if (rval == QLA_SUCCESS) {
3c6e85
+				bp = (uint32_t *)ha->init_cb;
3c6e85
+				for (i = 0; i < sz/4 ; i++, bp++)
3c6e85
+					*bp = cpu_to_be32(*bp);
3c6e85
 
3c6e85
-			memcpy(&ha->plogi_els_payld.data, (void *)ha->init_cb,
3c6e85
-			    sizeof(ha->plogi_els_payld.data));
3c6e85
-			set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3c6e85
-		} else {
3c6e85
-			ql_dbg(ql_dbg_init, vha, 0x00d1,
3c6e85
-			    "PLOGI ELS param read fail.\n");
3c6e85
+				memcpy(&ha->plogi_els_payld.data,
3c6e85
+				    (void *)ha->init_cb,
3c6e85
+				    sizeof(ha->plogi_els_payld.data));
3c6e85
+				set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3c6e85
+			} else {
3c6e85
+				ql_dbg(ql_dbg_init, vha, 0x00d1,
3c6e85
+				    "PLOGI ELS param read fail.\n");
3c6e85
+				goto skip_login;
3c6e85
+			}
3c6e85
+		}
3c6e85
+
3c6e85
+		list_for_each_entry(fcport, &vha->vp_fcports, list) {
3c6e85
+			if (fcport->n2n_flag) {
3c6e85
+				qla24xx_fcport_handle_login(vha, fcport);
3c6e85
+				return QLA_SUCCESS;
3c6e85
+			}
3c6e85
+		}
3c6e85
+skip_login:
3c6e85
+		spin_lock_irqsave(&vha->work_lock, flags);
3c6e85
+		vha->scan.scan_retry++;
3c6e85
+		spin_unlock_irqrestore(&vha->work_lock, flags);
3c6e85
+
3c6e85
+		if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
3c6e85
+			set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
3c6e85
+			set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3c6e85
 		}
3c6e85
-		return QLA_SUCCESS;
3c6e85
 	}
3c6e85
 
3c6e85
 	found_devs = 0;
3c6e85
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
3c6e85
index e082535ed733..4183b969036b 100644
3c6e85
--- a/drivers/scsi/qla2xxx/qla_mbx.c
3c6e85
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
3c6e85
@@ -2248,7 +2248,7 @@ qla2x00_lip_reset(scsi_qla_host_t *vha)
3c6e85
 	mbx_cmd_t mc;
3c6e85
 	mbx_cmd_t *mcp = &mc;
3c6e85
 
3c6e85
-	ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105a,
3c6e85
+	ql_dbg(ql_dbg_disc, vha, 0x105a,
3c6e85
 	    "Entered %s.\n", __func__);
3c6e85
 
3c6e85
 	if (IS_CNA_CAPABLE(vha->hw)) {
3c6e85
@@ -3882,14 +3882,23 @@ qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
3c6e85
 		case TOPO_N2N:
3c6e85
 			ha->current_topology = ISP_CFG_N;
3c6e85
 			spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
3c6e85
+			list_for_each_entry(fcport, &vha->vp_fcports, list) {
3c6e85
+				fcport->scan_state = QLA_FCPORT_SCAN;
3c6e85
+				fcport->n2n_flag = 0;
3c6e85
+			}
3c6e85
+
3c6e85
 			fcport = qla2x00_find_fcport_by_wwpn(vha,
3c6e85
 			    rptid_entry->u.f1.port_name, 1);
3c6e85
 			spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
3c6e85
 
3c6e85
 			if (fcport) {
3c6e85
 				fcport->plogi_nack_done_deadline = jiffies + HZ;
3c6e85
-				fcport->dm_login_expire = jiffies + 3*HZ;
3c6e85
+				fcport->dm_login_expire = jiffies + 2*HZ;
3c6e85
 				fcport->scan_state = QLA_FCPORT_FOUND;
3c6e85
+				fcport->n2n_flag = 1;
3c6e85
+				if (vha->flags.nvme_enabled)
3c6e85
+					fcport->fc4f_nvme = 1;
3c6e85
+
3c6e85
 				switch (fcport->disc_state) {
3c6e85
 				case DSC_DELETED:
3c6e85
 					set_bit(RELOGIN_NEEDED,
3c6e85
@@ -3923,7 +3932,7 @@ qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
3c6e85
 				    rptid_entry->u.f1.port_name,
3c6e85
 				    rptid_entry->u.f1.node_name,
3c6e85
 				    NULL,
3c6e85
-				    FC4_TYPE_UNKNOWN);
3c6e85
+				    FS_FCP_IS_N2N);
3c6e85
 			}
3c6e85
 
3c6e85
 			/* if our portname is higher then initiate N2N login */
3c6e85
@@ -4022,6 +4031,7 @@ qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
3c6e85
 
3c6e85
 		list_for_each_entry(fcport, &vha->vp_fcports, list) {
3c6e85
 			fcport->scan_state = QLA_FCPORT_SCAN;
3c6e85
+			fcport->n2n_flag = 0;
3c6e85
 		}
3c6e85
 
3c6e85
 		fcport = qla2x00_find_fcport_by_wwpn(vha,
3c6e85
@@ -4031,6 +4041,13 @@ qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
3c6e85
 			fcport->login_retry = vha->hw->login_retry_count;
3c6e85
 			fcport->plogi_nack_done_deadline = jiffies + HZ;
3c6e85
 			fcport->scan_state = QLA_FCPORT_FOUND;
3c6e85
+			fcport->n2n_flag = 1;
3c6e85
+			fcport->d_id.b.domain =
3c6e85
+				rptid_entry->u.f2.remote_nport_id[2];
3c6e85
+			fcport->d_id.b.area =
3c6e85
+				rptid_entry->u.f2.remote_nport_id[1];
3c6e85
+			fcport->d_id.b.al_pa =
3c6e85
+				rptid_entry->u.f2.remote_nport_id[0];
3c6e85
 		}
3c6e85
 	}
3c6e85
 }
3c6e85
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
3c6e85
index b2500db628f1..c9e0f1968d45 100644
3c6e85
--- a/drivers/scsi/qla2xxx/qla_os.c
3c6e85
+++ b/drivers/scsi/qla2xxx/qla_os.c
3c6e85
@@ -5135,6 +5135,10 @@ void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
3c6e85
 
3c6e85
 			memcpy(fcport->port_name, e->u.new_sess.port_name,
3c6e85
 			    WWN_SIZE);
3c6e85
+
3c6e85
+			if (e->u.new_sess.fc4_type & FS_FCP_IS_N2N)
3c6e85
+				fcport->n2n_flag = 1;
3c6e85
+
3c6e85
 		} else {
3c6e85
 			ql_dbg(ql_dbg_disc, vha, 0xffff,
3c6e85
 				   "%s %8phC mem alloc fail.\n",
3c6e85
-- 
3c6e85
2.13.6
3c6e85