Johannes Thumshirn b1ff48
From: Hans Wippel <hwippel@linux.ibm.com>
Johannes Thumshirn b1ff48
Date: Thu, 28 Jun 2018 19:05:12 +0200
Johannes Thumshirn b1ff48
Subject: net/smc: add SMC-D diag support
Takashi Iwai 3f1d88
Patch-mainline: v4.19-rc1
Johannes Thumshirn b1ff48
Git-commit: 4b1b7d3b30a6d32ac1a1dcede284e76ef8a8542d
Johannes Thumshirn b1ff48
References: FATE#325041, bsc#1101138, LTC#164002
Johannes Thumshirn b1ff48
Johannes Thumshirn b1ff48
This patch adds diag support for SMC-D.
Johannes Thumshirn b1ff48
Johannes Thumshirn b1ff48
Signed-off-by: Hans Wippel <hwippel@linux.ibm.com>
Johannes Thumshirn b1ff48
Signed-off-by: Ursula Braun <ubraun@linux.ibm.com>
Johannes Thumshirn b1ff48
Suggested-by: Thomas Richter <tmricht@linux.ibm.com>
Johannes Thumshirn b1ff48
Signed-off-by: David S. Miller <davem@davemloft.net>
Johannes Thumshirn b1ff48
Acked-by: Johannes Thumshirn <jthumshirn@suse.de>
Johannes Thumshirn b1ff48
---
Johannes Thumshirn b1ff48
 include/uapi/linux/smc_diag.h | 10 ++++++++++
Johannes Thumshirn b1ff48
 net/smc/smc_diag.c            | 15 +++++++++++++++
Johannes Thumshirn b1ff48
 2 files changed, 25 insertions(+)
Johannes Thumshirn b1ff48
Johannes Thumshirn b1ff48
diff --git a/include/uapi/linux/smc_diag.h b/include/uapi/linux/smc_diag.h
Johannes Thumshirn b1ff48
index 0ae5d4685ba3..92be255e534c 100644
Johannes Thumshirn b1ff48
--- a/include/uapi/linux/smc_diag.h
Johannes Thumshirn b1ff48
+++ b/include/uapi/linux/smc_diag.h
Johannes Thumshirn b1ff48
@@ -35,6 +35,7 @@ enum {
Johannes Thumshirn b1ff48
 	SMC_DIAG_CONNINFO,
Johannes Thumshirn b1ff48
 	SMC_DIAG_LGRINFO,
Johannes Thumshirn b1ff48
 	SMC_DIAG_SHUTDOWN,
Johannes Thumshirn b1ff48
+	SMC_DIAG_DMBINFO,
Johannes Thumshirn b1ff48
 	__SMC_DIAG_MAX,
Johannes Thumshirn b1ff48
 };
Johannes Thumshirn b1ff48
 
Johannes Thumshirn b1ff48
@@ -83,4 +84,13 @@ struct smc_diag_lgrinfo {
Johannes Thumshirn b1ff48
 	struct smc_diag_linkinfo	lnk[1];
Johannes Thumshirn b1ff48
 	__u8				role;
Johannes Thumshirn b1ff48
 };
Johannes Thumshirn b1ff48
+
Johannes Thumshirn b1ff48
+struct smcd_diag_dmbinfo {		/* SMC-D Socket internals */
Johannes Thumshirn b1ff48
+	__u32 linkid;			/* Link identifier */
Johannes Thumshirn b1ff48
+	__u64 peer_gid;			/* Peer GID */
Johannes Thumshirn b1ff48
+	__u64 my_gid;			/* My GID */
Johannes Thumshirn b1ff48
+	__u64 token;			/* Token of DMB */
Johannes Thumshirn b1ff48
+	__u64 peer_token;		/* Token of remote DMBE */
Johannes Thumshirn b1ff48
+};
Johannes Thumshirn b1ff48
+
Johannes Thumshirn b1ff48
 #endif /* _UAPI_SMC_DIAG_H_ */
Johannes Thumshirn b1ff48
diff --git a/net/smc/smc_diag.c b/net/smc/smc_diag.c
Johannes Thumshirn b1ff48
index 64ce107c24d9..6d83eef1b743 100644
Johannes Thumshirn b1ff48
--- a/net/smc/smc_diag.c
Johannes Thumshirn b1ff48
+++ b/net/smc/smc_diag.c
Johannes Thumshirn b1ff48
@@ -156,6 +156,21 @@ static int __smc_diag_dump(struct sock *sk, struct sk_buff *skb,
Johannes Thumshirn b1ff48
 		if (nla_put(skb, SMC_DIAG_LGRINFO, sizeof(linfo), &linfo) < 0)
Johannes Thumshirn b1ff48
 			goto errout;
Johannes Thumshirn b1ff48
 	}
Johannes Thumshirn b1ff48
+	if (smc->conn.lgr && smc->conn.lgr->is_smcd &&
Johannes Thumshirn b1ff48
+	    (req->diag_ext & (1 << (SMC_DIAG_DMBINFO - 1))) &&
Johannes Thumshirn b1ff48
+	    !list_empty(&smc->conn.lgr->list)) {
Johannes Thumshirn b1ff48
+		struct smc_connection *conn = &smc->conn;
Johannes Thumshirn b1ff48
+		struct smcd_diag_dmbinfo dinfo = {
Johannes Thumshirn b1ff48
+			.linkid = *((u32 *)conn->lgr->id),
Johannes Thumshirn b1ff48
+			.peer_gid = conn->lgr->peer_gid,
Johannes Thumshirn b1ff48
+			.my_gid = conn->lgr->smcd->local_gid,
Johannes Thumshirn b1ff48
+			.token = conn->rmb_desc->token,
Johannes Thumshirn b1ff48
+			.peer_token = conn->peer_token
Johannes Thumshirn b1ff48
+		};
Johannes Thumshirn b1ff48
+
Johannes Thumshirn b1ff48
+		if (nla_put(skb, SMC_DIAG_DMBINFO, sizeof(dinfo), &dinfo) < 0)
Johannes Thumshirn b1ff48
+			goto errout;
Johannes Thumshirn b1ff48
+	}
Johannes Thumshirn b1ff48
 
Johannes Thumshirn b1ff48
 	nlmsg_end(skb, nlh);
Johannes Thumshirn b1ff48
 	return 0;
Johannes Thumshirn b1ff48