From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.228 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796400097; b=iYTdRXcedwKYZDxbVT8FT/gkBqiQ3gxUGxv9JHp+vMOhYfLsxh/ajKCOFuNXTSwwydYt JEM2F6yMjM3AJfvo9I79//u0vm8OExEePCRD6GIEw2vnPjf3I6sBezIu+wulMOG8eO/hV dcB9gpzgNCLGQjHmOLLU7yb84iGi7/qagWxwnyynWLNNpTuWoh6wFNKJj68JC17UDwCRC M+Kg2uQefK7j6nGDacz7J6Tv+0vtoBrGh4aeJ8KR9pAWKQSfuPI3/CUgjhMNQ7gPGSTEC EZPLPsZwFirHGCB91VLg3UaVbF97jdnCBGxd4CvPb9UG2kcDZRjnlJMwSgNpOhg3DAA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796400097; h=DMARC-Filter:Received:X-Google-DKIM-Signature:X-Gm-Message-State: X-Gm-Gg:X-Received:Received:X-Relaying-Domain:X-CFilter-Loop:Received: DKIM-Signature:X-Received:X-Received:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-DetectorID-Processed; bh=3Ze0NuhQG8zfdVjaBQ6mr6h0GdLXNtSQIBThan12I4k=; b=e0eOvnx5pmyrczjjBa5+tpym6VpiNoPQ9H6MnVk+WEjKoOjlJOZB6dA4LjSXB61aRo0n SbhNqSWgL5MjITlml83SgWOiCktuYRrznISBITg70xVGrN/minl1/qPxJSnW1PpR1daSQ yNZQ77Yc3a5MwY8ANIceZJ+TCKBzJbT6N9pNI+3K8LuOQQ0k5EYog79NsOkTTdv8IgHVO QqHqQiRT/5IhYDL3IQeB5RCj5j6LttI/WVTrjuq+WzMe0Vhuflgjpl9W/vB7jBo1NkfMf euXwAuisVBzWZLrvVCVonhG1tpMVTx960M3U3w+z/+fikKrqX0g5l7IhImH4t29PssQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass header.d=broadcom.com header.i=@broadcom.com header.a=rsa-sha256 header.s=google header.b=d2HhI7nq; arc=none smtp.remote-ip=209.85.160.228 Received: from mail-qt1-f228.google.com (mail-qt1-f228.google.com [209.85.160.228]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23D33606A330 for ; Fri, 4 Dec 2026 16:01:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 23D33606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.a=rsa-sha256 header.s=google header.b=d2HhI7nq Received: by mail-qt1-f228.google.com with SMTP id d75a77b69052e-55e31e33b00so10751821cf.1 for ; Fri, 04 Dec 2026 08:01:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796400096; x=1797004896; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=3Ze0NuhQG8zfdVjaBQ6mr6h0GdLXNtSQIBThan12I4k=; b=WRpHRrtkBq4j1vuueXwRLtxxLHHwdH/61vslmGweKrlMVGsSGiyWi7aOmToAWnCZHK G9mZkyBLAfVmbMWRpZm3IRBA+4EsijY6NFdoqLWQ/e2Yv7liaatBC8si5TZTkXQoU0u4 wH24DUPF1dUBRopyPLoU44Nx01LBoqfznTQHsLXnsZGTAhutWFrucLA4rZHMaa75i7Y4 ihVAPzNG2gnERGf5InxH9zHOp9LjAghjyYrai6GmiWeFL/gzX4cCNA8IMeIL2PWuvfza EC2/r/TkWet76F/Fds47OeXGOIESs545qgNvPrHXKUV4tWhmQpGe6QT3xTNEk2g3iSLy WYqg== X-Gm-Message-State: APuU4Z+ywOS6EdrGUZjq0jVQ1nZ8meHyR58CHGgEakf6vs9RE0kYjm5L /NKFPlqBel4fAe0vJld+WDj9mmEqbw3vKUwEUwT9rnsdou8pSVXAKLf3f84bbAlTSsKiNTrQ4DE XdF1U2k8SrYYJvz4fheGrX0LH3t1pnbgUHEyOAlB1TiAlnGHjFcJsH2fNCLy85bvjBccCfmkWBY JIpO/36wmUCkbvKfJvxy7UjT3GlNOMBgUpKAWaGemxFfkN0frcaHLxB2xbBXFKTbL9LHtll5r/U zGwIK3on70i X-Gm-Gg: AZFdTZdT/36cR1BShuJxLvSl1+PfNMvexPI27EtIgN7UYzRRCbmCsfHkYRsIJodzn7w CmmBKnEc+XGjuQqc2OjBdwsm6TfqGtJFFR6S4V7Wk9F5vHMPIjjGkbtyPJgJ9dSYbvwcjxqatC6 y1D/j5R0BmpBa4ohdlGhOtur4u5iRM25omsONL6BvRyfhjDTK2C+duz9fnebCA+Y65cvfvem2HJ fRRZJE7jsHhkrM026pIUjNOqqf4eetZQ2J88WgHdNpdOpgC3RoN/h63jhMSu+lw8HBMrO3Tqaf4 PdgxEx5TRWAXfNVC9NKHSbRIlYdicygf45zqmY32n0XtomS5QpnYmrQVe5JCucDIv0Pwge2uwSv +8hIb/44pmzKYYJvrLjFSSAskEuVaYTAmEpPlUjLWYnEFhToDR8Zbzhfti1Z65aTvLK9OPh49WC oj31yr1HSKbkpmbdX7dCr15ALx/bTfMePXLL4o X-Received: by 2002:a05:622a:986:b0:55e:299d:411b with SMTP id d75a77b69052e-55e38d70f5amr35179251cf.43.1796400095629; Fri, 04 Dec 2026 08:01:35 -0800 (PST) Received: from smtp-us-east1-p01-i01-si01.dlp.protect.broadcom.com (address-144-49-247-100.dlp.protect.broadcom.com. [144.49.247.100]) by smtp-relay.gmail.com with ESMTPS id d75a77b69052e-55e3664b4a2sm164231cf.33.2026.12.04.08.01.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Dec 2026 08:01:35 -0800 (PST) X-Relaying-Domain: broadcom.com X-CFilter-Loop: Reflected Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-921e1950a0dso19012806d6.2 for ; Fri, 04 Dec 2026 08:01:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1796400095; x=1797004895; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=3Ze0NuhQG8zfdVjaBQ6mr6h0GdLXNtSQIBThan12I4k=; b=d2HhI7nq0OSQRlStIBpxJQg/wOoH7jH7HXi8bJEyjKGF1xQL7WbxJjGP59V/Yfin3j PmSU9oanVPtDtkU6vOflBo4pmITN5EJM7w1QkvVzNjqQQ6jI+WGy3RWVqAs/wWrg4aD8 72oyzS2TfwQ61qI5iajZ85q9/6RkYgEpDYyHA= X-Received: by 2002:a05:6214:2b82:b0:921:8919:8cd6 with SMTP id 6a1803df08f44-921e244f479mr37315546d6.11.1796400094599; Fri, 04 Dec 2026 08:01:34 -0800 (PST) X-Received: by 2002:a05:6214:2b82:b0:921:8919:8cd6 with SMTP id 6a1803df08f44-921e244f479mr37314456d6.11.1796400093729; Fri, 04 Dec 2026 08:01:33 -0800 (PST) Received: from mgmt5.dhcp.broadcom.net ([192.19.222.250]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-921e05633dfsm25686976d6.11.2026.12.04.08.01.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 08:01:32 -0800 (PST) From: Siva Reddy Kallam To: leonro@nvidia.com, jgg@nvidia.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, andrew+netdev@lunn.ch, horms@kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, vikas.gupta@broadcom.com, ajit.khaparde@broadcom.com, dharmender.garg@broadcom.com, sachin.holla@broadcom.com, Siva Reddy Kallam , Shyam Mohan Subject: [RDMA v2 04/13] RDMA/bng_re: Add ucontext/mmap verbs Date: Fri, 4 Dec 2026 07:47:56 -0800 Message-ID: <20261204155249.1002019-5-siva.kallam@broadcom.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20261204155249.1002019-1-siva.kallam@broadcom.com> References: <20261204155249.1002019-1-siva.kallam@broadcom.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-DetectorID-Processed: b00c1d49-9d2e-4205-b15f-d015386d3d5e This patch adds below verbs. - bng_re_alloc_ucontext - bng_re_dealloc_ucontext - bng_re_mmap - bng_re_mmap_free Signed-off-by: Siva Reddy Kallam Signed-off-by: Shyam Mohan Signed-off-by: Sachin Holla --- drivers/infiniband/hw/bng_re/bng_dev.c | 14 ++ drivers/infiniband/hw/bng_re/bng_re.h | 14 ++ drivers/infiniband/hw/bng_re/bng_res.c | 151 ++++++++++++++++- drivers/infiniband/hw/bng_re/bng_res.h | 34 ++++ drivers/infiniband/hw/bng_re/bng_sp.h | 5 + drivers/infiniband/hw/bng_re/bng_verbs.c | 199 +++++++++++++++++++++++ drivers/infiniband/hw/bng_re/bng_verbs.h | 25 +++ include/uapi/rdma/bng_re-abi.h | 30 ++++ 8 files changed, 469 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/hw/bng_re/bng_dev.c b/drivers/infiniband/hw/bng_re/bng_dev.c index bb29c0f0b2ba..174d0523709e 100644 --- a/drivers/infiniband/hw/bng_re/bng_dev.c +++ b/drivers/infiniband/hw/bng_re/bng_dev.c @@ -35,6 +35,12 @@ static const struct ib_device_ops bng_re_dev_ops = { .get_link_layer = bng_re_get_link_layer, .get_port_immutable = bng_re_get_port_immutable, .query_pkey = bng_re_query_pkey, + .alloc_ucontext = bng_re_alloc_ucontext, + .dealloc_ucontext = bng_re_dealloc_ucontext, + .disassociate_ucontext = bng_re_disassociate_ucontext, + .mmap = bng_re_mmap, + .mmap_free = bng_re_mmap_free, + INIT_RDMA_OBJ_SIZE(ib_ucontext, bng_re_ucontext, ib_uctx), }; static struct bng_re_dev *bng_re_dev_add(struct auxiliary_device *adev, @@ -55,6 +61,9 @@ static struct bng_re_dev *bng_re_dev_add(struct auxiliary_device *adev, rdev->adev = adev; rdev->fn_id = rdev->aux_dev->pdev->devfn; + /* Valid for the whole lifetime of rdev, independent of table alloc */ + mutex_init(&rdev->bng_res.dpi_tbl_lock); + return rdev; } @@ -283,6 +292,9 @@ static int bng_re_query_hwrm_version(struct bng_re_dev *rdev) if (!cctx->hwrm_cmd_max_timeout) cctx->hwrm_cmd_max_timeout = BNG_ROCE_FW_MAX_TIMEOUT; + cctx->chip_rev = ver_get_resp.chip_rev; + cctx->chip_metal = ver_get_resp.chip_metal; + return 0; } @@ -557,6 +569,7 @@ static int bng_re_add_device(struct auxiliary_device *adev) return 0; re_dev_dealloc: + mutex_destroy(&rdev->bng_res.dpi_tbl_lock); ib_dealloc_device(&rdev->ibdev); exit: return rc; @@ -566,6 +579,7 @@ static void bng_re_remove_device(struct bng_re_dev *rdev, struct auxiliary_device *aux_dev) { bng_re_dev_uninit(rdev); + mutex_destroy(&rdev->bng_res.dpi_tbl_lock); ib_dealloc_device(&rdev->ibdev); } diff --git a/drivers/infiniband/hw/bng_re/bng_re.h b/drivers/infiniband/hw/bng_re/bng_re.h index d073ccf104e7..b55658f3ab8e 100644 --- a/drivers/infiniband/hw/bng_re/bng_re.h +++ b/drivers/infiniband/hw/bng_re/bng_re.h @@ -182,6 +182,20 @@ struct bng_mpc_db { struct bng_re_db_info dbinfo; }; +enum bng_re_mmap_flag { + BNG_RE_MMAP_UC_DB, +}; + +static inline char *bng_re_mmap_str(enum bng_re_mmap_flag mmap_flag) +{ + switch (mmap_flag) { + case BNG_RE_MMAP_UC_DB: + return "BNG_RE_MMAP_UC_DB"; + default: + return "Unknown"; + } +} + /* NQ specific structures */ struct bng_re_nq_db { struct bng_re_reg_desc reg; diff --git a/drivers/infiniband/hw/bng_re/bng_res.c b/drivers/infiniband/hw/bng_re/bng_res.c index c5f9fff56726..6fbe88001eba 100644 --- a/drivers/infiniband/hw/bng_re/bng_res.c +++ b/drivers/infiniband/hw/bng_re/bng_res.c @@ -337,11 +337,28 @@ static int bng_res_alloc_dpi_tbl(struct bng_re_res *res, { struct bng_re_dpi_tbl *dpit; struct bng_re_reg_desc *reg; - unsigned long bar_len; + unsigned long bar_len, first_dpi, fw_max; dpit = &res->dpi_tbl; reg = &dpit->wcreg; + /* + * User doorbell pages are mapped one CPU page at a time starting at + * the WC offset, while DPI numbers count HW doorbell pages from the + * UC offset. bnge page-aligns the WC offset but the UC offset only + * has 1KB granularity, so require only HW doorbell page alignment + * of the delta. + */ + if (reg->offset < dpit->ucreg.offset || + !IS_ALIGNED(reg->offset, PAGE_SIZE) || + !IS_ALIGNED(reg->offset - dpit->ucreg.offset, + BNG_RE_DB_PAGE_SIZE)) { + dev_err(&res->pdev->dev, + "Invalid WC DB offset 0x%lx (UC DB offset 0x%lx)\n", + reg->offset, dpit->ucreg.offset); + return -EINVAL; + } + bar_len = pci_resource_len(res->pdev, reg->bar_id); if (reg->offset >= bar_len) { @@ -353,8 +370,20 @@ static int bng_res_alloc_dpi_tbl(struct bng_re_res *res, dpit->max = min_t(unsigned long, (bar_len - reg->offset) / PAGE_SIZE, U32_MAX); - if (dev_attr->max_dpi) - dpit->max = min_t(u32, dpit->max, dev_attr->max_dpi); + if (dev_attr->max_dpi) { + /* + * User DPI values start at first_dpi and step by + * PAGE_SIZE / BNG_RE_DB_PAGE_SIZE per table entry. Keep the + * highest DPI value handed out below the FW max_dpi limit. + */ + first_dpi = (reg->offset - dpit->ucreg.offset) / + BNG_RE_DB_PAGE_SIZE; + fw_max = 0; + if (first_dpi < dev_attr->max_dpi) + fw_max = (dev_attr->max_dpi - 1 - first_dpi) / + (PAGE_SIZE / BNG_RE_DB_PAGE_SIZE) + 1; + dpit->max = min_t(unsigned long, dpit->max, fw_max); + } if (!dpit->max) { dev_err(&res->pdev->dev, "No DPIs available in doorbell BAR\n"); return -EINVAL; @@ -380,7 +409,9 @@ static int bng_res_alloc_dpi_tbl(struct bng_re_res *res, void bng_res_free_tbls(struct bng_re_res *res) { + mutex_lock(&res->dpi_tbl_lock); bng_res_free_dpi_tbl(&res->dpi_tbl); + mutex_unlock(&res->dpi_tbl_lock); } int bng_res_alloc_init_tbls(struct bng_re_res *res) @@ -393,3 +424,117 @@ int bng_res_alloc_init_tbls(struct bng_re_res *res) return rc; } + +int bng_re_alloc_dpi(struct bng_re_res *res, + struct bng_re_dpi *dpi, + void *app, enum bng_re_dpi_type type) +{ + struct bng_re_dpi_tbl *dpit = &res->dpi_tbl; + struct bng_re_reg_desc *reg; + u32 bit_num; + u64 umaddr; + int rc = 0; + + reg = &dpit->wcreg; + mutex_lock(&res->dpi_tbl_lock); + if (!dpit->tbl) { + rc = -ENOMEM; + goto unlock; + } + bit_num = find_first_bit(dpit->tbl, dpit->max); + if (bit_num >= dpit->max) { + rc = -ENOMEM; + goto unlock; + } + clear_bit(bit_num, dpit->tbl); + dpit->app_tbl[bit_num] = app; + dpi->bit = bit_num; + dpi->dpi = (reg->offset - dpit->ucreg.offset + + (unsigned long)bit_num * PAGE_SIZE) / BNG_RE_DB_PAGE_SIZE; + umaddr = reg->bar_base + reg->offset + bit_num * PAGE_SIZE; + dpi->umdbr = umaddr; + switch (type) { + case BNG_RE_DPI_TYPE_KERNEL: + dpi->umdbr = dpit->ucreg.bar_base + + dpit->ucreg.offset + bit_num * PAGE_SIZE; + dpi->dbr = dpit->priv_db; + dpi->dpi = dpi->bit; + break; + case BNG_RE_DPI_TYPE_WC: + dpi->dbr = ioremap_wc(umaddr, PAGE_SIZE); + if (!dpi->dbr) { + dev_err(&res->pdev->dev, "WC DB remap failed\n"); + rc = -ENOMEM; + } + break; + case BNG_RE_DPI_TYPE_UC: + /* + * User space rings this page through its own mmap of umdbr. + * The kernel mapping is kept so that the driver can also ring + * doorbells of user objects on this page; future patches use + * it for doorbell drop recovery and for driver-managed rings + * of user QPs. + */ + dpi->dbr = ioremap(umaddr, PAGE_SIZE); + if (!dpi->dbr) { + dev_err(&res->pdev->dev, "UC DB remap failed\n"); + rc = -ENOMEM; + } + break; + default: + rc = -EINVAL; + break; + } + + if (rc) { + set_bit(bit_num, dpit->tbl); + dpit->app_tbl[bit_num] = NULL; + goto unlock; + } + dpi->type = type; +unlock: + mutex_unlock(&res->dpi_tbl_lock); + return rc; +} + +int bng_re_dealloc_dpi(struct bng_re_res *res, + struct bng_re_dpi *dpi) +{ + struct bng_re_dpi_tbl *dpit = &res->dpi_tbl; + int rc = 0; + + mutex_lock(&res->dpi_tbl_lock); + if (dpi->bit >= dpit->max) { + dev_warn(&res->pdev->dev, + "Invalid DPI? dpi = %d, bit = %d\n", + dpi->dpi, dpi->bit); + rc = -EINVAL; + goto release; + } + + /* Check ownership first so a repeated free cannot unmap anything */ + if (test_and_set_bit(dpi->bit, dpit->tbl)) { + dev_warn(&res->pdev->dev, + "Freeing an unused DPI? dpi = %d, bit = %d\n", + dpi->dpi, dpi->bit); + dev_warn(&res->pdev->dev, + "umdbr = %lld, dbr = %p, type = %d\n", + dpi->umdbr, dpi->dbr, dpi->type); + dev_warn(&res->pdev->dev, + "dpit max = %d, priv_db = %p\n", + dpit->max, dpit->priv_db); + rc = -EINVAL; + goto unlock; + } + if (dpit->app_tbl) + dpit->app_tbl[dpi->bit] = NULL; +release: + if (dpi->dbr && dpi->type != BNG_RE_DPI_TYPE_KERNEL) + iounmap(dpi->dbr); + memset(dpi, 0, sizeof(*dpi)); + /* Bit 0 is a valid index: make a stale dpi fail the range check */ + dpi->bit = U32_MAX; +unlock: + mutex_unlock(&res->dpi_tbl_lock); + return rc; +} diff --git a/drivers/infiniband/hw/bng_re/bng_res.h b/drivers/infiniband/hw/bng_re/bng_res.h index cc1872f3ab54..b43827ee1b18 100644 --- a/drivers/infiniband/hw/bng_re/bng_res.h +++ b/drivers/infiniband/hw/bng_re/bng_res.h @@ -7,6 +7,7 @@ #include "bng_roce_hsi.h" #include "xid_allocator.h" #include +#include #define BNG_NQE_MAX_CNT (128 * 1024) @@ -91,6 +92,8 @@ struct bng_re_chip_ctx { u64 hwrm_intf_ver; u16 hwrm_cmd_max_timeout; struct bng_re_drv_modes modes; + u8 chip_rev; + u8 chip_metal; }; struct bng_re_pbl { @@ -156,6 +159,30 @@ struct bng_re_stats { u32 fw_id; }; +/* DPI types */ +enum bng_re_dpi_type { + BNG_RE_DPI_TYPE_KERNEL = 0, + BNG_RE_DPI_TYPE_UC = 1, + BNG_RE_DPI_TYPE_WC = 2 +}; + +/* DPI structure */ +struct bng_re_dpi { + u32 dpi; + u32 bit; + u64 umdbr; + void __iomem *dbr; + enum bng_re_dpi_type type; +}; + +/* + * HW doorbell page size. bnge does not program db_page_size through + * HWRM_FUNC_CFG, so firmware uses its 4KB default. DPI numbers are in + * units of this size, independent of the CPU PAGE_SIZE; each DPI handed + * to user space still owns a full CPU page so mappings never overlap. + */ +#define BNG_RE_DB_PAGE_SIZE SZ_4K + /* DPI table */ struct bng_re_dpi_tbl { void **app_tbl; @@ -171,6 +198,8 @@ struct bng_re_res { struct bng_re_chip_ctx *cctx; struct bng_re_dev_attr *dattr; struct bng_re_dpi_tbl dpi_tbl; + /* Serialize access to DPI table */ + struct mutex dpi_tbl_lock; struct xid_manager *qp_xids; struct xid_manager *ah_xids; }; @@ -286,4 +315,9 @@ void bng_res_unmap_db_bar(struct bng_re_res *res); int bng_res_map_db_bar(struct bng_re_res *res); void bng_res_free_tbls(struct bng_re_res *res); int bng_res_alloc_init_tbls(struct bng_re_res *res); +int bng_re_alloc_dpi(struct bng_re_res *res, + struct bng_re_dpi *dpi, + void *app, enum bng_re_dpi_type type); +int bng_re_dealloc_dpi(struct bng_re_res *res, + struct bng_re_dpi *dpi); #endif diff --git a/drivers/infiniband/hw/bng_re/bng_sp.h b/drivers/infiniband/hw/bng_re/bng_sp.h index 2b19b65ae550..d1a93affa22c 100644 --- a/drivers/infiniband/hw/bng_re/bng_sp.h +++ b/drivers/infiniband/hw/bng_re/bng_sp.h @@ -47,5 +47,10 @@ struct bng_re_dev_attr { u32 max_dpi; }; +static inline bool bng_re_is_internal_queue_memory(u16 dev_cap_flags) +{ + return dev_cap_flags & CREQ_QUERY_FUNC_RESP_SB_INTERNAL_QUEUE_MEMORY; +} + int bng_re_get_dev_attr(struct bng_re_rcfw *rcfw); #endif diff --git a/drivers/infiniband/hw/bng_re/bng_verbs.c b/drivers/infiniband/hw/bng_re/bng_verbs.c index 6750dfa4a168..45ade397342a 100644 --- a/drivers/infiniband/hw/bng_re/bng_verbs.c +++ b/drivers/infiniband/hw/bng_re/bng_verbs.c @@ -191,3 +191,202 @@ int bng_re_query_pkey(struct ib_device *ibdev, u32 port_num, return 0; } + +static struct bng_re_user_mmap_entry* +bng_re_mmap_entry_insert(struct bng_re_ucontext *uctx, u64 cpu_addr, + u8 user_mmap_hint, u64 *offset) +{ + struct bng_re_user_mmap_entry *entry; + int ret; + + entry = kzalloc_obj(*entry, GFP_KERNEL); + if (!entry) + return NULL; + + entry->cpu_addr = cpu_addr; + entry->mmap_flag = user_mmap_hint; + + switch (user_mmap_hint) { + case BNG_RE_MMAP_UC_DB: + ret = rdma_user_mmap_entry_insert_range(&uctx->ib_uctx, + &entry->rdma_entry, + PAGE_SIZE, 0xF, U32_MAX); + break; + default: + ret = -EINVAL; + break; + } + + if (ret) { + kfree(entry); + return NULL; + } + + dev_dbg(rdev_to_dev(uctx->rdev), + "mmap entry inserted: hint %s offset 0x%lx\n", + bng_re_mmap_str(user_mmap_hint), + (unsigned long)rdma_user_mmap_get_offset(&entry->rdma_entry)); + + if (offset) + *offset = rdma_user_mmap_get_offset(&entry->rdma_entry); + + return entry; +} + +static int bng_re_get_user_dpi(struct bng_re_dev *rdev, + struct bng_re_ucontext *cntx) +{ + int ret = 0; + u8 type; + + type = BNG_RE_DPI_TYPE_UC; + ret = bng_re_alloc_dpi(&rdev->bng_res, &cntx->dpi, cntx, type); + if (ret) + dev_err(rdev_to_dev(rdev), "Alloc doorbell page failed!"); + + return ret; +} + +int bng_re_alloc_ucontext(struct ib_ucontext *ctx, struct ib_udata *udata) +{ + struct ib_device *ibdev = ctx->device; + struct bng_re_ucontext *uctx = + container_of(ctx, struct bng_re_ucontext, ib_uctx); + struct bng_re_dev *rdev = to_bng_re_dev(ibdev, ibdev); + struct bng_re_dev_attr *dev_attr = rdev->dev_attr; + struct bng_re_user_mmap_entry *is_entry; + struct bng_re_uctx_resp resp = {}; + struct bng_re_uctx_req ureq = {}; + u32 chip_met_rev_num = 0; + int rc; + + uctx->rdev = rdev; + + if (udata->inlen >= sizeof(ureq)) { + rc = ib_copy_from_udata(&ureq, udata, sizeof(ureq)); + if (rc) + return rc; + if (udata->inlen > sizeof(ureq) && + !ib_is_udata_cleared(udata, sizeof(ureq), + udata->inlen - sizeof(ureq))) + return -EOPNOTSUPP; + if (ureq.comp_mask & ~BNG_RE_COMP_MASK_REQ_UCNTX_SUPPORTED) + return -EOPNOTSUPP; + } + + rc = bng_re_get_user_dpi(rdev, uctx); + if (rc) { + ibdev_dbg(ibdev, "user DPI alloc failed"); + return rc; + } + + resp.dpi = uctx->dpi.dpi; + is_entry = bng_re_mmap_entry_insert(uctx, + (u64)uctx->dpi.umdbr, + BNG_RE_MMAP_UC_DB, + &resp.uc_db_mmap_key); + if (!is_entry) { + rc = -ENOMEM; + goto err_entry_insert; + } + uctx->uc_db_mmap = &is_entry->rdma_entry; + + resp.comp_mask = BNG_RE_UCNTX_CMASK_HAVE_CCTX; + if (bng_re_is_internal_queue_memory(dev_attr->dev_cap_flags)) + resp.comp_mask |= BNG_RE_UCNTX_CMASK_INTERNAL_QUEUE_MEMORY; + chip_met_rev_num = rdev->chip_ctx->chip_num; + chip_met_rev_num |= ((u32)rdev->chip_ctx->chip_rev & 0xFF) << + BNG_RE_CHIP_REV_SFT; + chip_met_rev_num |= ((u32)rdev->chip_ctx->chip_metal & 0xFF) << + BNG_RE_CHIP_MET_SFT; + resp.chip_id = chip_met_rev_num; + resp.dev_id = rdev->aux_dev->pdev->devfn; + resp.max_qp = rdev->dev_attr->max_qp; + resp.cqe_sz = sizeof(struct cq_base); + resp.max_cqd = dev_attr->max_cq_wqes; + + if (ureq.comp_mask & BNG_RE_COMP_MASK_REQ_UCNTX_POW2_SUPPORT) + resp.comp_mask |= BNG_RE_UCNTX_CMASK_POW2_DISABLED; + if (ureq.comp_mask & BNG_RE_COMP_MASK_REQ_UCNTX_RSVD_WQE) + resp.comp_mask |= BNG_RE_UCNTX_CMASK_RSVD_WQE_DISABLED; + + uctx->cmask = (uint64_t)resp.comp_mask; + + rc = ib_copy_to_udata(udata, &resp, min(udata->outlen, sizeof(resp))); + if (rc) { + ibdev_err(ibdev, "Failed to copy user context"); + rc = -EFAULT; + goto copy_udata_fail; + } + + return 0; + +copy_udata_fail: + rdma_user_mmap_entry_remove(uctx->uc_db_mmap); + uctx->uc_db_mmap = NULL; +err_entry_insert: + bng_re_dealloc_dpi(&rdev->bng_res, &uctx->dpi); + return rc; +} + +void bng_re_dealloc_ucontext(struct ib_ucontext *ib_uctx) +{ + struct bng_re_ucontext *uctx = container_of(ib_uctx, + struct bng_re_ucontext, + ib_uctx); + struct bng_re_dev *rdev = uctx->rdev; + int rc; + + rdma_user_mmap_entry_remove(uctx->uc_db_mmap); + uctx->uc_db_mmap = NULL; + rc = bng_re_dealloc_dpi(&rdev->bng_res, &uctx->dpi); + if (rc) + dev_err(rdev_to_dev(rdev), "Deallocate DPI failed"); +} + +void bng_re_disassociate_ucontext(struct ib_ucontext *ib_uctx) +{ +} + +int bng_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma) +{ + struct bng_re_user_mmap_entry *bng_entry; + struct rdma_user_mmap_entry *rdma_entry; + int ret = 0; + u64 pfn; + + if (vma->vm_end - vma->vm_start != PAGE_SIZE) + return -EINVAL; + + rdma_entry = rdma_user_mmap_entry_get(ib_uctx, vma); + if (!rdma_entry) + return -EINVAL; + + bng_entry = container_of(rdma_entry, struct bng_re_user_mmap_entry, + rdma_entry); + + switch (bng_entry->mmap_flag) { + case BNG_RE_MMAP_UC_DB: + pfn = bng_entry->cpu_addr >> PAGE_SHIFT; + ret = rdma_user_mmap_io(ib_uctx, vma, pfn, PAGE_SIZE, + pgprot_noncached(vma->vm_page_prot), + rdma_entry); + break; + default: + ret = -EINVAL; + break; + } + + rdma_user_mmap_entry_put(rdma_entry); + return ret; +} + +void bng_re_mmap_free(struct rdma_user_mmap_entry *rdma_entry) +{ + struct bng_re_user_mmap_entry *bng_entry; + + bng_entry = container_of(rdma_entry, struct bng_re_user_mmap_entry, + rdma_entry); + + kfree(bng_entry); +} diff --git a/drivers/infiniband/hw/bng_re/bng_verbs.h b/drivers/infiniband/hw/bng_re/bng_verbs.h index fd00a3a0f7e8..c72b94e10d78 100644 --- a/drivers/infiniband/hw/bng_re/bng_verbs.h +++ b/drivers/infiniband/hw/bng_re/bng_verbs.h @@ -10,6 +10,24 @@ #include "bng_sp.h" #include "bng_re.h" +#define BNG_RE_COMP_MASK_REQ_UCNTX_SUPPORTED \ + (BNG_RE_COMP_MASK_REQ_UCNTX_POW2_SUPPORT | \ + BNG_RE_COMP_MASK_REQ_UCNTX_RSVD_WQE) + +struct bng_re_ucontext { + struct ib_ucontext ib_uctx; + struct bng_re_dev *rdev; + struct bng_re_dpi dpi; + struct rdma_user_mmap_entry *uc_db_mmap; + u64 cmask; +}; + +struct bng_re_user_mmap_entry { + struct rdma_user_mmap_entry rdma_entry; + u64 cpu_addr; + u8 mmap_flag; +}; + int bng_re_query_device(struct ib_device *ibdev, struct ib_device_attr *ib_attr, struct ib_udata *udata); int bng_re_modify_device(struct ib_device *ibdev, int device_modify_mask, @@ -21,4 +39,11 @@ int bng_re_get_port_immutable(struct ib_device *ibdev, u32 port_num, struct ib_port_immutable *immutable); int bng_re_query_pkey(struct ib_device *ibdev, u32 port_num, u16 index, u16 *pkey); enum rdma_link_layer bng_re_get_link_layer(struct ib_device *ibdev, u32 port_num); + +int bng_re_alloc_ucontext(struct ib_ucontext *ctx, struct ib_udata *udata); +void bng_re_dealloc_ucontext(struct ib_ucontext *context); +void bng_re_disassociate_ucontext(struct ib_ucontext *context); +int bng_re_mmap(struct ib_ucontext *context, struct vm_area_struct *vma); +void bng_re_mmap_free(struct rdma_user_mmap_entry *rdma_entry); + #endif /* __BNG_RE_VERBS_H__ */ diff --git a/include/uapi/rdma/bng_re-abi.h b/include/uapi/rdma/bng_re-abi.h index cea056dc8610..d5cda958b0f8 100644 --- a/include/uapi/rdma/bng_re-abi.h +++ b/include/uapi/rdma/bng_re-abi.h @@ -9,4 +9,34 @@ #define BNG_RE_ABI_VERSION 1 +#define BNG_RE_CHIP_REV_SFT 0x10 +#define BNG_RE_CHIP_MET_SFT 0x18 + +enum { + BNG_RE_UCNTX_CMASK_HAVE_CCTX = 0x1, + BNG_RE_UCNTX_CMASK_POW2_DISABLED = 0x02, + BNG_RE_UCNTX_CMASK_RSVD_WQE_DISABLED = 0x04, + BNG_RE_UCNTX_CMASK_INTERNAL_QUEUE_MEMORY = 0x08, +}; + +enum { + BNG_RE_COMP_MASK_REQ_UCNTX_POW2_SUPPORT = 0x01, + BNG_RE_COMP_MASK_REQ_UCNTX_RSVD_WQE = 0x02, +}; + +struct bng_re_uctx_req { + __aligned_u64 comp_mask; +}; + +struct bng_re_uctx_resp { + __u32 dev_id; + __u32 max_qp; + __u32 cqe_sz; + __u32 max_cqd; + __aligned_u64 comp_mask; + __u32 chip_id; + __u32 dpi; + __aligned_u64 uc_db_mmap_key; +}; + #endif /* __BNG_RE_UVERBS_ABI_H__*/ -- 2.43.5