Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1592034rdd; Thu, 11 Jan 2024 04:03:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFTMFS2m4PfP9U0Bo2x8mVcwZFCn0GvXDc/oEnPt3g2LFpwDzk+U39lR9FabEdrCqm3A5nD X-Received: by 2002:a25:9109:0:b0:dbe:d41f:e957 with SMTP id v9-20020a259109000000b00dbed41fe957mr1091794ybl.76.1704974581671; Thu, 11 Jan 2024 04:03:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704974581; cv=none; d=google.com; s=arc-20160816; b=FNnFbpNxTevPSmbYcoUP+NghbfYaGGN8AysfB377RvmjQJuC+feld3KQ3YrFmFR2ww bzQZCGzDtJTQXgI4ncdoGuYA9IxSvhj0PHWG1qQsxwDDKp+WNS1N8hyugpd1h6hRf3CO d3LOZyT64TYFP/sb9EMrCahpU1huvBymfp2eprj2TeiC8Tq8O6SbEl0N4YcsLnNhABOH TzJgZuiH5Pj6jj53rgouIFgVIcnhcrhtnhlDdY47wOJUaNJiBqQ0vWONejZsZVqORvfI hxVkCMVG/9f05PZUsbxxQvR/SZSmswMVz8hX8+MM4R2Fy17xiseDmYMt09+ee0zpAl2W kKwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=EUwnVOkIzVdEioLnlyeLium9XB6B8SIVM8wX4nvQ+eM=; fh=jvQSXgb9+Gwj+2SIugFJuht8/m1b8ZaGKJU/ZBOVFgM=; b=TGZN+4gXgVXKK0onDKPIBmrpn102aOitL4rC6tYK2Aae/dl8ZDGlui3F45P08Ajoso EUkm+4oiJXMsFzVVYCMbbE66cqfwGOoNfUN8cDTWAIssPT9G5ApWDH8UCC1DSOIooELB evRGYO0+9X3uSeZ3xsfCrhP09jNPJDl9AK5x/MyxyvWjfMcMqLkschaMvcRV2mjjsKKD 6U0ODLOjl3oR+YAdiAo+2RTGYcvRcoYTz54WJt++3Hc/bi/dCyqPPfrJMEZHPMSTgAZw VhUVdDlO8hVJoAXGICAILnc9sAHU1E2oghVxBB1CvhZe4xknbRCJAi6TCUdpuAYQT90z hejw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-23541-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23541-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id s11-20020a056102108b00b00466fdd6250dsi44941vsr.46.2024.01.11.04.03.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 04:03:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23541-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-23541-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23541-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1C0CB1C23942 for ; Thu, 11 Jan 2024 12:03:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6AC80168B3; Thu, 11 Jan 2024 12:01:26 +0000 (UTC) Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E097F16414; Thu, 11 Jan 2024 12:01:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=guwen@linux.alibaba.com;NM=1;PH=DS;RN=18;SR=0;TI=SMTPD_---0W-PewXf_1704974474; Received: from localhost(mailfrom:guwen@linux.alibaba.com fp:SMTPD_---0W-PewXf_1704974474) by smtp.aliyun-inc.com; Thu, 11 Jan 2024 20:01:15 +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, 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: [PATCH net-next 04/15] net/smc: implement ID-related operations of loopback-ism Date: Thu, 11 Jan 2024 20:00:25 +0800 Message-Id: <20240111120036.109903-5-guwen@linux.alibaba.com> X-Mailer: git-send-email 2.32.0.3.g01195cf9f In-Reply-To: <20240111120036.109903-1-guwen@linux.alibaba.com> References: <20240111120036.109903-1-guwen@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 cbb6625ccd0d..40dff28d837d 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 @@ static const struct smcd_ops lo_ops = { .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 9dd44d4c0ca3..55b41133a97f 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 -- 2.32.0.3.g01195cf9f