Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3424780rdb; Sun, 10 Dec 2023 05:24:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IGtZ8d+YlJ/Qr+yge2zKaZ5sSfTTaQkWQBOWPpmPAieK5GFwSQbraGfRPvMizAmiaDIQHaB X-Received: by 2002:a05:6a20:a107:b0:18f:97c:4f68 with SMTP id q7-20020a056a20a10700b0018f097c4f68mr1439153pzk.116.1702214699130; Sun, 10 Dec 2023 05:24:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702214699; cv=none; d=google.com; s=arc-20160816; b=inFfD/F8YuiPilgDwgLkcsgkyrAp95BRg8NkCdmXISO02+DyPmT2ldjXc/OszV62vf r9ahHWLjXoMe34axFi80a8gjnJRdp9JRBdwBAQRDWsumoGbFgYO0KZT7Sw9mgt+5fJ+K biXso+qyJhhsN7E4CF9ldTFyXCPl8C+Y0eBHuX4uLbTTWs+P6rjboVD6AEnQmmgd8p4h M1bFBtGVofjE/d86A0gU1Zn0BFS0H6XZvjeSWdp16awP+WPb18H2XR58/fGzWOV/8tFl LV/DNTlpca21F97U3KGMVj5ojWb3URI7M/FPkbDoShCCsalG2g0/cRUJCYQz0T2uMV67 m66w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=z5fqgwh5DQKiSaMqkTuqfwmEEvtpyOUckOw5ZTWea+s=; fh=OseD/KU9IozxwwuPl+YAZpOMu/WojE/9fn/xPSMdB/8=; b=jNCPs1BhlGst4FX0Kelx7w1OTLohT2b15hj7Ejr1UKjMsPX1WNzkWuy0ipVp8saPIM FsULWn5R5/N2K0egDYr1tYQaUwMI0Iv1ejR8a1iy2aKP5WmzLDSTXJatB+Ekmnmd5uvK HKrk/LzLb+1Jd9u3k6TLeA6ExA+nxKEkM8oyJrzEVRMzpsfBUhU7TcspbkDWJf/vZDxP 68pzx24gf9LS2vbE0HR/pY6Drl3bHY45yGmSELAUDbJ2rv64ItMi01Pro7dJpGWFJ+db Bd6IzSdiKqT79UNN9nOjPAhf3mhbGvmxk/HZ9JgeFnfngiORMj0ERcyhpugns07wzbsY pjkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id v6-20020a17090ac90600b00286593b0471si5733786pjt.120.2023.12.10.05.24.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 05:24:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 14A54806583E; Sun, 10 Dec 2023 05:24:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232429AbjLJNY0 (ORCPT + 99 others); Sun, 10 Dec 2023 08:24:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232465AbjLJNYX (ORCPT ); Sun, 10 Dec 2023 08:24:23 -0500 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AB26118; Sun, 10 Dec 2023 05:24:28 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=guwen@linux.alibaba.com;NM=1;PH=DS;RN=19;SR=0;TI=SMTPD_---0Vy8Bbna_1702214664; Received: from localhost(mailfrom:guwen@linux.alibaba.com fp:SMTPD_---0Vy8Bbna_1702214664) by smtp.aliyun-inc.com; Sun, 10 Dec 2023 21:24:26 +0800 From: Wen Gu To: wintera@linux.ibm.com, wenjia@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, kgraul@linux.ibm.com, jaka@linux.ibm.com Cc: borntraeger@linux.ibm.com, svens@linux.ibm.com, alibuda@linux.alibaba.com, tonylu@linux.alibaba.com, guwen@linux.alibaba.com, linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH net-next 04/13] net/smc: implement ID-related operations of loopback-ism Date: Sun, 10 Dec 2023 21:24:05 +0800 Message-Id: <1702214654-32069-5-git-send-email-guwen@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1702214654-32069-1-git-send-email-guwen@linux.alibaba.com> References: <1702214654-32069-1-git-send-email-guwen@linux.alibaba.com> X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sun, 10 Dec 2023 05:24:54 -0800 (PST) This implements GID and CHID related operations of loopback-ism device. loopback-ism acts as an ISMv2. It's GID is generated randomly by UUIDv4 algorithm and CHID is reserved 0xFFFF. Signed-off-by: Wen Gu --- net/smc/smc_loopback.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++---- net/smc/smc_loopback.h | 3 +++ 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/net/smc/smc_loopback.c b/net/smc/smc_loopback.c index 149ccaa..39e8c8d 100644 --- a/net/smc/smc_loopback.c +++ b/net/smc/smc_loopback.c @@ -19,12 +19,63 @@ #include "smc_loopback.h" #if IS_ENABLED(CONFIG_SMC_LO) +#define SMC_LO_V2_CAPABLE 0x1 /* loopback-ism acts as ISMv2 */ + static const char smc_lo_dev_name[] = "loopback-ism"; static struct smc_lo_dev *lo_dev; static struct class *smc_class; +static void smc_lo_generate_id(struct smc_lo_dev *ldev) +{ + struct smcd_gid *lgid = &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 = SMC_LO_CHID; +} + +static int smc_lo_query_rgid(struct smcd_dev *smcd, struct smcd_gid *rgid, + u32 vid_valid, u32 vid) +{ + struct smc_lo_dev *ldev = smcd->priv; + + /* rgid should equal to lgid in loopback situation */ + if (!ldev || rgid->gid != ldev->local_gid.gid || + rgid->gid_ext != ldev->local_gid.gid_ext) + return -ENETUNREACH; + return 0; +} + +static int smc_lo_supports_v2(void) +{ + return SMC_LO_V2_CAPABLE; +} + +static void smc_lo_get_local_gid(struct smcd_dev *smcd, + struct smcd_gid *smcd_gid) +{ + struct smc_lo_dev *ldev = smcd->priv; + + smcd_gid->gid = ldev->local_gid.gid; + smcd_gid->gid_ext = 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 = { - .query_remote_gid = NULL, + .query_remote_gid = smc_lo_query_rgid, .register_dmb = NULL, .unregister_dmb = NULL, .add_vlan_id = NULL, @@ -33,10 +84,10 @@ .reset_vlan_required = NULL, .signal_event = NULL, .move_data = NULL, - .supports_v2 = NULL, - .get_local_gid = NULL, - .get_chid = NULL, - .get_dev = NULL, + .supports_v2 = smc_lo_supports_v2, + .get_local_gid = smc_lo_get_local_gid, + .get_chid = smc_lo_get_chid, + .get_dev = smc_lo_get_dev, }; static struct smcd_dev *smcd_lo_alloc_dev(const struct smcd_ops *ops, @@ -96,6 +147,7 @@ static void smcd_lo_unregister_dev(struct smc_lo_dev *ldev) static int smc_lo_dev_init(struct smc_lo_dev *ldev) { + smc_lo_generate_id(ldev); return smcd_lo_register_dev(ldev); } diff --git a/net/smc/smc_loopback.h b/net/smc/smc_loopback.h index a7c418b..73eed6a 100644 --- a/net/smc/smc_loopback.h +++ b/net/smc/smc_loopback.h @@ -20,10 +20,13 @@ #if IS_ENABLED(CONFIG_SMC_LO) #define SMC_LO_MAX_DMBS 5000 +#define SMC_LO_CHID 0xFFFF struct smc_lo_dev { struct smcd_dev *smcd; struct device dev; + u16 chid; + struct smcd_gid local_gid; }; #endif -- 1.8.3.1