linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bob Pearson <rpearsonhpe@gmail.com>
To: zyjzyj2000@gmail.com, linux-rdma@vger.kernel.org
Cc: Bob Pearson <rpearson@hpe.com>
Subject: [PATCH v2 10/16] rdma_rxe: Implemented functional alloc_mw and dealloc_mw APIs
Date: Tue, 18 Aug 2020 22:40:06 -0500	[thread overview]
Message-ID: <20200819034002.8835-11-rpearson@hpe.com> (raw)
In-Reply-To: <20200819034002.8835-1-rpearson@hpe.com>

Created basic functional alloc_mw and dealloc_mw funnctions.
This change supports running user space test cases for these APIs.

Signed-off-by: Bob Pearson <rpearson@hpe.com>
---
 drivers/infiniband/sw/rxe/rxe_mw.c    | 55 +++++++++++++++++++++++++--
 drivers/infiniband/sw/rxe/rxe_pool.c  |  3 +-
 drivers/infiniband/sw/rxe/rxe_verbs.h |  5 +++
 3 files changed, 58 insertions(+), 5 deletions(-)

diff --git a/drivers/infiniband/sw/rxe/rxe_mw.c b/drivers/infiniband/sw/rxe/rxe_mw.c
index f5df5e0b714f..ea8510044fbe 100644
--- a/drivers/infiniband/sw/rxe/rxe_mw.c
+++ b/drivers/infiniband/sw/rxe/rxe_mw.c
@@ -8,15 +8,62 @@
 #include "rxe.h"
 #include "rxe_loc.h"
 
+/* this temporary code to test ibv_alloc_mw, ibv_dealloc_mw */
 struct ib_mw *rxe_alloc_mw(struct ib_pd *ibpd, enum ib_mw_type type,
 			   struct ib_udata *udata)
 {
-	pr_err_once("%s: not implemented\n", __func__);
-	return ERR_PTR(-EINVAL);
+	struct rxe_pd *pd = to_rpd(ibpd);
+	struct rxe_dev *rxe = to_rdev(ibpd->device);
+	struct rxe_mw *mw;
+	u32 rkey;
+
+	if (unlikely((type != IB_MW_TYPE_1) &&
+		     (type != IB_MW_TYPE_2)))
+		return ERR_PTR(-EINVAL);
+
+	rxe_add_ref(pd);
+
+	mw = rxe_alloc(&rxe->mw_pool);
+	if (unlikely(!mw)) {
+		rxe_drop_ref(pd);
+		return ERR_PTR(-ENOMEM);
+	}
+
+	/* pick a random rkey for now */
+	get_random_bytes(&rkey, sizeof(rkey));
+
+	rxe_add_index(mw);
+	rxe_add_key(mw, &rkey);
+
+	spin_lock_init(&mw->lock);
+	mw->qp			= NULL;
+	mw->mr			= NULL;
+	mw->addr		= 0;
+	mw->length		= 0;
+	mw->ibmw.pd		= ibpd;
+	mw->ibmw.type		= type;
+	mw->ibmw.rkey		= rkey;
+	mw->state		= (type == IB_MW_TYPE_2) ?
+					RXE_MEM_STATE_FREE :
+					RXE_MEM_STATE_VALID;
+
+	return &mw->ibmw;
 }
 
 int rxe_dealloc_mw(struct ib_mw *ibmw)
 {
-	pr_err_once("%s: not implemented\n", __func__);
-	return -EINVAL;
+	struct rxe_mw *mw = to_rmw(ibmw);
+	struct rxe_pd *pd = to_rpd(ibmw->pd);
+	unsigned long flags;
+
+	spin_lock_irqsave(&mw->lock, flags);
+	mw->state = RXE_MEM_STATE_INVALID;
+	spin_unlock_irqrestore(&mw->lock, flags);
+
+	rxe_drop_ref(pd);
+	rxe_drop_index(mw);
+	rxe_drop_key(mw);
+	rxe_drop_ref(mw);
+
+	return 0;
 }
diff --git a/drivers/infiniband/sw/rxe/rxe_pool.c b/drivers/infiniband/sw/rxe/rxe_pool.c
index f9f16e7ed0f7..5679714827ec 100644
--- a/drivers/infiniband/sw/rxe/rxe_pool.c
+++ b/drivers/infiniband/sw/rxe/rxe_pool.c
@@ -61,7 +61,8 @@ struct rxe_type_info rxe_type_info[RXE_NUM_TYPES] = {
 	[RXE_TYPE_MW] = {
 		.name		= "rxe-mw",
 		.size		= sizeof(struct rxe_mw),
-		.flags		= RXE_POOL_INDEX,
+		.flags		= RXE_POOL_INDEX
+				| RXE_POOL_KEY,
 		.max_index	= RXE_MAX_MW_INDEX,
 		.min_index	= RXE_MIN_MW_INDEX,
 	},
diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.h b/drivers/infiniband/sw/rxe/rxe_verbs.h
index a7686772a6fc..52db82c27cf9 100644
--- a/drivers/infiniband/sw/rxe/rxe_verbs.h
+++ b/drivers/infiniband/sw/rxe/rxe_verbs.h
@@ -445,6 +445,11 @@ static inline struct rxe_mr *to_rmr(struct ib_mr *mr)
 	return mr ? container_of(mr, struct rxe_mr, ibmr) : NULL;
 }
 
+static inline struct rxe_mw *to_rmw(struct ib_mw *mw)
+{
+	return mw ? container_of(mw, struct rxe_mw, ibmw) : NULL;
+}
+
 int rxe_register_device(struct rxe_dev *rxe, const char *ibdev_name);
 
 void rxe_mc_cleanup(struct rxe_pool_entry *arg);
-- 
2.25.1


  parent reply	other threads:[~2020-08-19  3:43 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-19  3:39 Memory window support for rdma_rxe Bob Pearson
2020-08-19  3:39 ` [PATCH v2 01/16] rdma_rxe: Added SPDX headers to rxe source files Bob Pearson
2020-08-20 13:43   ` Zhu Yanjun
2020-08-20 13:48     ` Bob Pearson
2020-08-19  3:39 ` [PATCH v2 02/16] rdma_rxe: Fixed style warnings Bob Pearson
2020-08-19  3:39 ` [PATCH v2 03/16] ib_user_verbs.h: Added ib_uverbs_wc_opcode Bob Pearson
2020-08-19  3:39 ` [PATCH v2 04/16] ib_verbs.h: Added missing IB_WR_BIND_MW opcode Bob Pearson
2020-08-19  3:39 ` [PATCH v2 05/16] rdma_rxe: Added bind_mw parameters to rxe_send_wr Bob Pearson
2020-08-19  3:39 ` [PATCH v2 06/16] rdma_rxe: Added stubs for alloc_mw and dealloc_mw verbs Bob Pearson
2020-08-19  3:40 ` [PATCH v2 07/16] rdma_rxe: Separated MR and MW objects Bob Pearson
2020-08-19  3:40 ` [PATCH v2 08/16] rdma_rxe: Added mw object Bob Pearson
2020-08-19  3:40 ` [PATCH v2 09/16] rdma_rxe: Extended pools to support both keys and indices Bob Pearson
2020-08-19  3:40 ` Bob Pearson [this message]
2020-08-19  3:40 ` [PATCH v2 11/16] rdma_rxe: Address an issue with hardened user copy Bob Pearson
2020-08-19  3:40 ` [PATCH v2 12/16] rdma_rxe: Added bind mw API stub Bob Pearson
2020-08-19  3:40 ` [PATCH v2 13/16] rdma_rxe: Give MR and MW objects indices and keys Bob Pearson
2020-08-19  3:40 ` [PATCH v2 14/16] rdma_rxe: Added stub for invalidate mw Bob Pearson
2020-08-19  3:40 ` [PATCH v2 15/16] rdma_rxe: Added functional bind and invalidate MW ops Bob Pearson
2020-08-19  6:01   ` kernel test robot
2020-08-19  3:40 ` [PATCH v2 16/16] rdma_rxe: Implemented read/write/atomic access to MW Bob Pearson
2020-08-19  5:02 ` Memory window support for rdma_rxe Leon Romanovsky
     [not found]   ` <13f4a586-9f9c-e348-ec85-d9109adcab5b@gmail.com>
     [not found]     ` <20200820074116.GZ7555@unreal>
     [not found]       ` <92e509ee-8a6a-6e3b-c1e3-1d6ec84c44fe@gmail.com>
2020-08-20 21:51         ` Bob Pearson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200819034002.8835-11-rpearson@hpe.com \
    --to=rpearsonhpe@gmail.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=rpearson@hpe.com \
    --cc=zyjzyj2000@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).