Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1575136rdb; Wed, 31 Jan 2024 02:58:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGLB6OXveItE6luRuCWKbemE1tKA9HESIZWg8KQaaTCcr90MS/1RcffyVQVHHjKasHLn3Ka X-Received: by 2002:a17:906:f890:b0:a30:be5e:c8e7 with SMTP id lg16-20020a170906f89000b00a30be5ec8e7mr862642ejb.44.1706698687687; Wed, 31 Jan 2024 02:58:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706698687; cv=pass; d=google.com; s=arc-20160816; b=mocJtr3uWwavSkPoo1j9pBRON1w+NSDMVyzxpfmwrbV9GineT+voLzDBBxxjzLQ+Vb X+L93L/s2VHop+cdBr0DZKoLAKktIOUah/DpQtfxoaGKLOjzl9sTrQsDhU+HG5KdmcG+ aLStLrnnPRxtgvMUsNqv7iC6fNdaSp9i2erWhdxxik3nffxRFlmXkAKYu580TZmjnabI ISKfDnGNuwFucgBuzN5R2kj85H1i8py8lwl0NUQ3EQbkyVaq9P8BSEYYoLqdWJqhBXn7 Z3YunWgyPBgg6Vw0LGPiS95F8j11v04hebHnHgNsAoLZ9fTokDc/45qF3W9gg47F4JFq I88A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=MsUo2v+//cFlf6nJMuZ1DMVlU3JLOjmKGXGXkSEimVc=; fh=PUWdET4tsO68ooMd53Wy4YlUxWv6Frhvu4LYrsiIa34=; b=GKCMWpFWKiAKod6mhC7N2BGp6LtVwvNlAPvRjI2x/mlu0Sl5i8jhZkVl5/3Lm+76Fv KobT6pwB3hQmhpFYBX1fsL+0SwtA6YK4B9ehvyifTfBFx+NXw954DafxRnXBPE0ebCGW WWUbCKcwyFU6rwHOi4/PqCjptM+kIpbDqCnweAoig6QeOBdVAr6SP12PczxQ5Nm53wX9 TcqZYYz9l+ZZM4Vz8rRnbYcmssvzAtodKXouv4fI5P7BMnxdkqDirYYobSiVanrQx01H 9wo+ZAIPymtXe1oR3q85ceURy0OTfcnx2jpnG5862CsrAFSjzXvFKs7Q4A7/OINpD994 ibNA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=L7xBFSUO; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-46279-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46279-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com X-Forwarded-Encrypted: i=1; AJvYcCUJIGQzDPVUrf3XxOb9wGnTPtsTO5E/TACR5Qrc6chdyQmLZEaxlwbosC0rQhB6/ZpE9KxltZEp0n7sASg8NPTdnwiWIt//oXukfr7ExQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id md19-20020a170906ae9300b00a35a4aaf31fsi3204194ejb.622.2024.01.31.02.58.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 02:58:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46279-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=L7xBFSUO; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-46279-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46279-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.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 am.mirrors.kernel.org (Postfix) with ESMTPS id CC3461F29051 for ; Wed, 31 Jan 2024 10:57:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B1ADE79DAD; Wed, 31 Jan 2024 10:56:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="L7xBFSUO" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AADA26EB6E; Wed, 31 Jan 2024 10:55:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706698562; cv=none; b=rqiMAmIWyl1rbYzFsiC5qw69D0kNVdLFegsSsr6hKblcGL3Ome+Slfoe25qR9QKQpkedXFsjUto45t195K8C/A3uXqJPxB5MKP7Of3lMbKd2LfeTGojgP9HKijSPh1cmUTodm9zDP/b+8HSI7XObST4HdiwEi9vs9r8b3OExf3g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706698562; c=relaxed/simple; bh=LHBIj/8uoDBRrS1dlZPeCz2qf0GZ0mc5vqMb8Dcyy6U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=sSfJqTRaFhIlREW0cMpPSoS3WWTve1HRpfs/X/LuJhQgILvlJcGvq5E+W20HYvaLNJ4+iO2SktQrlmAnxWQozpv+tEGgHCqG9pmncRgiYPB9j12SsC+fa6uDcN8jAnrqt1fmXUQcVFFQbkAwHplkZwhvQtoW6wsNLOlVgRhKM9s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=L7xBFSUO; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 1859020B2005; Wed, 31 Jan 2024 02:55:58 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 1859020B2005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1706698558; bh=MsUo2v+//cFlf6nJMuZ1DMVlU3JLOjmKGXGXkSEimVc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L7xBFSUON0y+jHp0RHicnx4GOcP3xCMFb6wyib2qcVkrCV4YXENV/EBgdnPq/AW1T t6fjax+zreYGHyrT/FTObwgcTI2XXzPsHWPiSMa5jFGT72oV3Ng9dnZiazoqVyWkX1 Rd8KPyE++IipAvl46yMwOVL88ODVAnYR0pVsveXY= From: Konstantin Taranov To: kotaranov@microsoft.com, sharmaajay@microsoft.com, longli@microsoft.com, jgg@ziepe.ca, leon@kernel.org Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH rdma-next v1 5/5] RDMA/mana_ib: Adding and deleting GIDs Date: Wed, 31 Jan 2024 02:55:52 -0800 Message-Id: <1706698552-25383-6-git-send-email-kotaranov@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1706698552-25383-1-git-send-email-kotaranov@linux.microsoft.com> References: <1706698552-25383-1-git-send-email-kotaranov@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Implement add_gid and del_gid for RNIC. We support ipv4 and ipv6 addresses. Signed-off-by: Konstantin Taranov --- drivers/infiniband/hw/mana/device.c | 2 ++ drivers/infiniband/hw/mana/main.c | 66 ++++++++++++++++++++++++++++++++++++ drivers/infiniband/hw/mana/mana_ib.h | 37 ++++++++++++++++++++ 3 files changed, 105 insertions(+) diff --git a/drivers/infiniband/hw/mana/device.c b/drivers/infiniband/hw/mana/device.c index b9ff3fd..9655307 100644 --- a/drivers/infiniband/hw/mana/device.c +++ b/drivers/infiniband/hw/mana/device.c @@ -15,6 +15,7 @@ .driver_id = RDMA_DRIVER_MANA, .uverbs_abi_ver = MANA_IB_UVERBS_ABI_VERSION, + .add_gid = mana_ib_gd_add_gid, .alloc_pd = mana_ib_alloc_pd, .alloc_ucontext = mana_ib_alloc_ucontext, .create_cq = mana_ib_create_cq, @@ -23,6 +24,7 @@ .create_wq = mana_ib_create_wq, .dealloc_pd = mana_ib_dealloc_pd, .dealloc_ucontext = mana_ib_dealloc_ucontext, + .del_gid = mana_ib_gd_del_gid, .dereg_mr = mana_ib_dereg_mr, .destroy_cq = mana_ib_destroy_cq, .destroy_qp = mana_ib_destroy_qp, diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana/main.c index 645abf3..282c024 100644 --- a/drivers/infiniband/hw/mana/main.c +++ b/drivers/infiniband/hw/mana/main.c @@ -675,3 +675,69 @@ void mana_ib_gd_destroy_rnic_adapter(struct mana_ib_dev *mdev) mdev->adapter_handle = INVALID_MANA_HANDLE; mana_ib_destroy_eqs(mdev); } + +int mana_ib_gd_add_gid(const struct ib_gid_attr *attr, void **context) +{ + struct mana_ib_dev *mdev = container_of(attr->device, struct mana_ib_dev, ib_dev); + enum rdma_network_type ntype = rdma_gid_attr_network_type(attr); + struct mana_rnic_config_addr_resp resp = {}; + struct gdma_context *gc = mdev_to_gc(mdev); + struct mana_rnic_config_addr_req req = {}; + int err; + + if (!rnic_is_enabled(mdev)) + return -EINVAL; + + if (ntype != RDMA_NETWORK_IPV4 && ntype != RDMA_NETWORK_IPV6) { + ibdev_dbg(&mdev->ib_dev, "Unsupported rdma network type %d", ntype); + return -EINVAL; + } + + mana_gd_init_req_hdr(&req.hdr, MANA_IB_CONFIG_IP_ADDR, sizeof(req), sizeof(resp)); + req.hdr.dev_id = gc->mana_ib.dev_id; + req.adapter = mdev->adapter_handle; + req.op = ADDR_OP_ADD; + req.sgid_type = (ntype == RDMA_NETWORK_IPV6) ? SGID_TYPE_IPV6 : SGID_TYPE_IPV4; + copy_in_reverse(req.ip_addr, attr->gid.raw, sizeof(union ib_gid)); + + err = mana_gd_send_request(gc, sizeof(req), &req, sizeof(resp), &resp); + if (err) { + ibdev_err(&mdev->ib_dev, "Failed to config IP addr err %d\n", err); + return err; + } + + return 0; +} + +int mana_ib_gd_del_gid(const struct ib_gid_attr *attr, void **context) +{ + struct mana_ib_dev *mdev = container_of(attr->device, struct mana_ib_dev, ib_dev); + enum rdma_network_type ntype = rdma_gid_attr_network_type(attr); + struct mana_rnic_config_addr_resp resp = {}; + struct gdma_context *gc = mdev_to_gc(mdev); + struct mana_rnic_config_addr_req req = {}; + int err; + + if (!rnic_is_enabled(mdev)) + return -EINVAL; + + if (ntype != RDMA_NETWORK_IPV4 && ntype != RDMA_NETWORK_IPV6) { + ibdev_dbg(&mdev->ib_dev, "Unsupported rdma network type %d", ntype); + return -EINVAL; + } + + mana_gd_init_req_hdr(&req.hdr, MANA_IB_CONFIG_IP_ADDR, sizeof(req), sizeof(resp)); + req.hdr.dev_id = gc->mana_ib.dev_id; + req.adapter = mdev->adapter_handle; + req.op = ADDR_OP_REMOVE; + req.sgid_type = (ntype == RDMA_NETWORK_IPV6) ? SGID_TYPE_IPV6 : SGID_TYPE_IPV4; + copy_in_reverse(req.ip_addr, attr->gid.raw, sizeof(union ib_gid)); + + err = mana_gd_send_request(gc, sizeof(req), &req, sizeof(resp), &resp); + if (err) { + ibdev_err(&mdev->ib_dev, "Failed to config IP addr err %d\n", err); + return err; + } + + return 0; +} diff --git a/drivers/infiniband/hw/mana/mana_ib.h b/drivers/infiniband/hw/mana/mana_ib.h index 196f3c8..2a3e3b0 100644 --- a/drivers/infiniband/hw/mana/mana_ib.h +++ b/drivers/infiniband/hw/mana/mana_ib.h @@ -118,6 +118,7 @@ enum mana_ib_command_code { MANA_IB_GET_ADAPTER_CAP = 0x30001, MANA_IB_CREATE_ADAPTER = 0x30002, MANA_IB_DESTROY_ADAPTER = 0x30003, + MANA_IB_CONFIG_IP_ADDR = 0x30004, }; struct mana_ib_query_adapter_caps_req { @@ -167,6 +168,30 @@ struct mana_rnic_destroy_adapter_resp { struct gdma_resp_hdr hdr; }; /* HW Data */ +enum mana_ib_addr_op { + ADDR_OP_ADD = 1, + ADDR_OP_REMOVE, +}; + +enum sgid_entry_type { + SGID_TYPE_INVALID = 0, + SGID_TYPE_IPV4 = 1, + SGID_TYPE_IPV6 = 2, + SGID_TYPE_HYBRID = 3 +}; + +struct mana_rnic_config_addr_req { + struct gdma_req_hdr hdr; + mana_handle_t adapter; + enum mana_ib_addr_op op; + enum sgid_entry_type sgid_type; + u8 ip_addr[16]; +}; /* HW Data */ + +struct mana_rnic_config_addr_resp { + struct gdma_resp_hdr hdr; +}; /* HW Data */ + static inline bool rnic_is_enabled(struct mana_ib_dev *mdev) { return mdev->adapter_handle != INVALID_MANA_HANDLE; @@ -188,6 +213,14 @@ static inline struct net_device *mana_ib_get_netdev(struct ib_device *ibdev, u32 return mc->ports[port - 1]; } +static inline void copy_in_reverse(u8 *dst, const u8 *src, u32 size) +{ + u32 i; + + for (i = 0; i < size; i++) + dst[size - 1 - i] = src[i]; +} + int mana_ib_install_cq_cb(struct mana_ib_dev *mdev, struct mana_ib_cq *cq); int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem, @@ -266,4 +299,8 @@ int mana_ib_query_gid(struct ib_device *ibdev, u32 port, int index, int mana_ib_query_pkey(struct ib_device *ibdev, u32 port, u16 index, u16 *pkey); enum rdma_link_layer mana_ib_get_link_layer(struct ib_device *device, u32 port_num); + +int mana_ib_gd_add_gid(const struct ib_gid_attr *attr, void **context); + +int mana_ib_gd_del_gid(const struct ib_gid_attr *attr, void **context); #endif -- 1.8.3.1