From nobody Wed Jan 15 18:05:59 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94198CE7A8A for ; Sun, 24 Sep 2023 15:17:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230202AbjIXPSB (ORCPT ); Sun, 24 Sep 2023 11:18:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230163AbjIXPRk (ORCPT ); Sun, 24 Sep 2023 11:17:40 -0400 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A9F9CF4; Sun, 24 Sep 2023 08:17:24 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=guwen@linux.alibaba.com;NM=1;PH=DS;RN=18;SR=0;TI=SMTPD_---0Vsio7wU_1695568640; Received: from localhost(mailfrom:guwen@linux.alibaba.com fp:SMTPD_---0Vsio7wU_1695568640) by smtp.aliyun-inc.com; Sun, 24 Sep 2023 23:17:22 +0800 From: Wen Gu To: kgraul@linux.ibm.com, wenjia@linux.ibm.com, jaka@linux.ibm.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: wintera@linux.ibm.com, schnelle@linux.ibm.com, gbayer@linux.ibm.com, pasic@linux.ibm.com, alibuda@linux.alibaba.com, tonylu@linux.alibaba.com, dust.li@linux.alibaba.com, guwen@linux.alibaba.com, linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 10/18] net/smc: implement ID-related operations of loopback Date: Sun, 24 Sep 2023 23:16:45 +0800 Message-Id: <1695568613-125057-11-git-send-email-guwen@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1695568613-125057-1-git-send-email-guwen@linux.alibaba.com> References: <1695568613-125057-1-git-send-email-guwen@linux.alibaba.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch implements GID/CHID/SEID related operations of SMC-D loopback device. In loopback device, GID is generated by UUIDv4 algorithm, CHID is reserved 0xFFFF, SEID is generated using the same algorithm as ISM device under s390 architecture, and is 0 and disabled under non-s390 architecture. Signed-off-by: Wen Gu --- include/net/smc.h | 6 ++++ net/smc/smc_ism.h | 2 ++ net/smc/smc_loopback.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++= ---- net/smc/smc_loopback.h | 3 ++ 4 files changed, 101 insertions(+), 6 deletions(-) diff --git a/include/net/smc.h b/include/net/smc.h index d8db5e1..7c2d35c 100644 --- a/include/net/smc.h +++ b/include/net/smc.h @@ -41,6 +41,12 @@ struct smcd_dmb { dma_addr_t dma_addr; }; =20 +struct smcd_seid { + u8 seid_string[24]; + u8 serial_number[4]; + u8 type[4]; +}; + #define ISM_EVENT_DMB 0 #define ISM_EVENT_GID 1 #define ISM_EVENT_SWR 2 diff --git a/net/smc/smc_ism.h b/net/smc/smc_ism.h index e6ea08c..7ab82dd 100644 --- a/net/smc/smc_ism.h +++ b/net/smc/smc_ism.h @@ -15,6 +15,8 @@ =20 #include "smc.h" =20 +#define S390_ISM_IDENT_MASK 0x00FFFF + #define SMC_VIRT_ISM_CHID_MAX 0xFFFF #define SMC_VIRT_ISM_CHID_MIN 0xFF00 =20 diff --git a/net/smc/smc_loopback.c b/net/smc/smc_loopback.c index 4631236..610af99 100644 --- a/net/smc/smc_loopback.c +++ b/net/smc/smc_loopback.c @@ -13,17 +13,99 @@ =20 #include #include +#include #include =20 #include "smc_ism.h" #include "smc_loopback.h" =20 #if IS_ENABLED(CONFIG_SMC_LO) +#define SMC_LO_SUPPORTS_V2 0x1 /* SMC-D loopback supports SMC-Dv2 */ + static const char smc_lo_dev_name[] =3D "smc_lo"; +static struct smcd_seid SMC_LO_SEID =3D { + .seid_string =3D "IBM-SYSZ-ISMSEID00000000", + .serial_number =3D "0000", + .type =3D "0000", +}; + static struct smc_lo_dev *lo_dev; =20 +static void smc_lo_create_seid(struct smcd_seid *seid) +{ +#if IS_ENABLED(CONFIG_S390) + struct cpuid id; + u16 ident_tail; + char tmp[5]; + + get_cpu_id(&id); + ident_tail =3D (u16)(id.ident & S390_ISM_IDENT_MASK); + snprintf(tmp, 5, "%04X", ident_tail); + memcpy(&seid->serial_number, tmp, 4); + snprintf(tmp, 5, "%04X", id.machine); + memcpy(&seid->type, tmp, 4); +#else + memset(seid, 0, SMC_MAX_EID_LEN); +#endif +} + +static void smc_lo_generate_id(struct smc_lo_dev *ldev) +{ + struct smcd_gid *lgid =3D &ldev->local_gid; + uuid_t uuid; + + uuid_gen(&uuid); + memcpy(&lgid->gid, &uuid, sizeof(lgid->gid)); + memcpy(&lgid->gid_ext, (u8 *)&uuid + sizeof(lgid->gid), + sizeof(lgid->gid_ext)); + + ldev->chid =3D SMC_LO_CHID; + smc_lo_create_seid(&SMC_LO_SEID); +} + +static int smc_lo_query_rgid(struct smcd_dev *smcd, struct smcd_gid *rgid, + u32 vid_valid, u32 vid) +{ + struct smc_lo_dev *ldev =3D smcd->priv; + + /* rgid should equal to lgid in loopback */ + if (!ldev || rgid->gid !=3D ldev->local_gid.gid || + rgid->gid_ext !=3D ldev->local_gid.gid_ext) + return -ENETUNREACH; + return 0; +} + +static int smc_lo_supports_v2(void) +{ + return SMC_LO_SUPPORTS_V2; +} + +static u8 *smc_lo_get_system_eid(void) +{ + return SMC_LO_SEID.seid_string; +} + +static void smc_lo_get_local_gid(struct smcd_dev *smcd, + struct smcd_gid *smcd_gid) +{ + struct smc_lo_dev *ldev =3D smcd->priv; + + smcd_gid->gid =3D ldev->local_gid.gid; + smcd_gid->gid_ext =3D ldev->local_gid.gid_ext; +} + +static u16 smc_lo_get_chid(struct smcd_dev *smcd) +{ + return ((struct smc_lo_dev *)smcd->priv)->chid; +} + +static struct device *smc_lo_get_dev(struct smcd_dev *smcd) +{ + return &((struct smc_lo_dev *)smcd->priv)->dev; +} + static const struct smcd_ops lo_ops =3D { - .query_remote_gid =3D NULL, + .query_remote_gid =3D smc_lo_query_rgid, .register_dmb =3D NULL, .unregister_dmb =3D NULL, .add_vlan_id =3D NULL, @@ -32,11 +114,11 @@ .reset_vlan_required =3D NULL, .signal_event =3D NULL, .move_data =3D NULL, - .supports_v2 =3D NULL, - .get_system_eid =3D NULL, - .get_local_gid =3D NULL, - .get_chid =3D NULL, - .get_dev =3D NULL, + .supports_v2 =3D smc_lo_supports_v2, + .get_system_eid =3D smc_lo_get_system_eid, + .get_local_gid =3D smc_lo_get_local_gid, + .get_chid =3D smc_lo_get_chid, + .get_dev =3D smc_lo_get_dev, }; =20 static struct smcd_dev *smcd_lo_alloc_dev(const struct smcd_ops *ops, @@ -104,6 +186,8 @@ static void smc_lo_dev_release(struct device *dev) =20 static int smc_lo_dev_init(struct smc_lo_dev *ldev) { + smc_lo_generate_id(ldev); + return smcd_lo_register_dev(ldev); } =20 diff --git a/net/smc/smc_loopback.h b/net/smc/smc_loopback.h index 39aa1dc..71a52da 100644 --- a/net/smc/smc_loopback.h +++ b/net/smc/smc_loopback.h @@ -19,11 +19,14 @@ #include =20 #if IS_ENABLED(CONFIG_SMC_LO) +#define SMC_LO_CHID 0xFFFF #define SMC_LODEV_MAX_DMBS 5000 =20 struct smc_lo_dev { struct smcd_dev *smcd; struct device dev; + u16 chid; + struct smcd_gid local_gid; }; #endif =20 --=20 1.8.3.1