From: Sagi Grimberg <sagig@mellanox.com>
To: linux-rdma@vger.kernel.org
Cc: linux-nfs@vger.kernel.org, "Nicholas A. Bellinger" <nab@linux-iscsi.org>
Subject: [PATCH v2 06/26] RDMA/cxgb3: Support the new memory registration API
Date: Thu, 24 Sep 2015 20:34:58 +0300 [thread overview]
Message-ID: <1443116118-10730-7-git-send-email-sagig@mellanox.com> (raw)
In-Reply-To: <1443116118-10730-1-git-send-email-sagig@mellanox.com>
Support the new memory registration API by allocating a
private page list array in iwch_mr and populate it when
iwch_map_mr_sg is invoked. Also, support IB_WR_REG_MR
by duplicating build_fastreg just take the needed information
from different places:
- page_size, iova, length (ib_mr)
- page array (iwch_mr)
- key, access flags (ib_reg_wr)
The IB_WR_FAST_REG_MR handlers will be removed later when
all the ULPs will be converted.
Signed-off-by: Sagi Grimberg <sagig@mellanox.com>
Acked-by: Christoph Hellwig <hch@lst.de>
---
drivers/infiniband/hw/cxgb3/iwch_provider.c | 33 ++++++++++++++++++++
drivers/infiniband/hw/cxgb3/iwch_provider.h | 2 ++
drivers/infiniband/hw/cxgb3/iwch_qp.c | 48 +++++++++++++++++++++++++++++
3 files changed, 83 insertions(+)
diff --git a/drivers/infiniband/hw/cxgb3/iwch_provider.c b/drivers/infiniband/hw/cxgb3/iwch_provider.c
index 93308c45f298..ee3d5ca7de6c 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_provider.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_provider.c
@@ -463,6 +463,7 @@ static int iwch_dereg_mr(struct ib_mr *ib_mr)
return -EINVAL;
mhp = to_iwch_mr(ib_mr);
+ kfree(mhp->pages);
rhp = mhp->rhp;
mmid = mhp->attr.stag >> 8;
cxio_dereg_mem(&rhp->rdev, mhp->attr.stag, mhp->attr.pbl_size,
@@ -821,6 +822,12 @@ static struct ib_mr *iwch_alloc_mr(struct ib_pd *pd,
if (!mhp)
goto err;
+ mhp->pages = kcalloc(max_num_sg, sizeof(u64), GFP_KERNEL);
+ if (!mhp->pages) {
+ ret = -ENOMEM;
+ goto pl_err;
+ }
+
mhp->rhp = rhp;
ret = iwch_alloc_pbl(mhp, max_num_sg);
if (ret)
@@ -847,11 +854,36 @@ err3:
err2:
iwch_free_pbl(mhp);
err1:
+ kfree(mhp->pages);
+pl_err:
kfree(mhp);
err:
return ERR_PTR(ret);
}
+static int iwch_set_page(struct ib_mr *ibmr, u64 addr)
+{
+ struct iwch_mr *mhp = to_iwch_mr(ibmr);
+
+ if (unlikely(mhp->npages == mhp->attr.pbl_size))
+ return -ENOMEM;
+
+ mhp->pages[mhp->npages++] = addr;
+
+ return 0;
+}
+
+static int iwch_map_mr_sg(struct ib_mr *ibmr,
+ struct scatterlist *sg,
+ unsigned int sg_nents)
+{
+ struct iwch_mr *mhp = to_iwch_mr(ibmr);
+
+ mhp->npages = 0;
+
+ return ib_sg_to_pages(ibmr, sg, sg_nents, iwch_set_page);
+}
+
static struct ib_fast_reg_page_list *iwch_alloc_fastreg_pbl(
struct ib_device *device,
int page_list_len)
@@ -1450,6 +1482,7 @@ int iwch_register_device(struct iwch_dev *dev)
dev->ibdev.bind_mw = iwch_bind_mw;
dev->ibdev.dealloc_mw = iwch_dealloc_mw;
dev->ibdev.alloc_mr = iwch_alloc_mr;
+ dev->ibdev.map_mr_sg = iwch_map_mr_sg;
dev->ibdev.alloc_fast_reg_page_list = iwch_alloc_fastreg_pbl;
dev->ibdev.free_fast_reg_page_list = iwch_free_fastreg_pbl;
dev->ibdev.attach_mcast = iwch_multicast_attach;
diff --git a/drivers/infiniband/hw/cxgb3/iwch_provider.h b/drivers/infiniband/hw/cxgb3/iwch_provider.h
index 87c14b0c5ac0..2ac85b86a680 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_provider.h
+++ b/drivers/infiniband/hw/cxgb3/iwch_provider.h
@@ -77,6 +77,8 @@ struct iwch_mr {
struct iwch_dev *rhp;
u64 kva;
struct tpt_attributes attr;
+ u64 *pages;
+ u32 npages;
};
typedef struct iwch_mw iwch_mw_handle;
diff --git a/drivers/infiniband/hw/cxgb3/iwch_qp.c b/drivers/infiniband/hw/cxgb3/iwch_qp.c
index bac0508fedd9..a09ea538e990 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_qp.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_qp.c
@@ -146,6 +146,49 @@ static int build_rdma_read(union t3_wr *wqe, struct ib_send_wr *wr,
return 0;
}
+static int build_memreg(union t3_wr *wqe, struct ib_reg_wr *wr,
+ u8 *flit_cnt, int *wr_cnt, struct t3_wq *wq)
+{
+ struct iwch_mr *mhp = to_iwch_mr(wr->mr);
+ int i;
+ __be64 *p;
+
+ if (mhp->npages > T3_MAX_FASTREG_DEPTH)
+ return -EINVAL;
+ *wr_cnt = 1;
+ wqe->fastreg.stag = cpu_to_be32(wr->key);
+ wqe->fastreg.len = cpu_to_be32(mhp->ibmr.length);
+ wqe->fastreg.va_base_hi = cpu_to_be32(mhp->ibmr.iova >> 32);
+ wqe->fastreg.va_base_lo_fbo =
+ cpu_to_be32(mhp->ibmr.iova & 0xffffffff);
+ wqe->fastreg.page_type_perms = cpu_to_be32(
+ V_FR_PAGE_COUNT(mhp->npages) |
+ V_FR_PAGE_SIZE(ilog2(wr->mr->page_size) - 12) |
+ V_FR_TYPE(TPT_VATO) |
+ V_FR_PERMS(iwch_ib_to_tpt_access(wr->access)));
+ p = &wqe->fastreg.pbl_addrs[0];
+ for (i = 0; i < mhp->npages; i++, p++) {
+
+ /* If we need a 2nd WR, then set it up */
+ if (i == T3_MAX_FASTREG_FRAG) {
+ *wr_cnt = 2;
+ wqe = (union t3_wr *)(wq->queue +
+ Q_PTR2IDX((wq->wptr+1), wq->size_log2));
+ build_fw_riwrh((void *)wqe, T3_WR_FASTREG, 0,
+ Q_GENBIT(wq->wptr + 1, wq->size_log2),
+ 0, 1 + mhp->npages - T3_MAX_FASTREG_FRAG,
+ T3_EOP);
+
+ p = &wqe->pbl_frag.pbl_addrs[0];
+ }
+ *p = cpu_to_be64((u64)mhp->pages[i]);
+ }
+ *flit_cnt = 5 + mhp->npages;
+ if (*flit_cnt > 15)
+ *flit_cnt = 15;
+ return 0;
+}
+
static int build_fastreg(union t3_wr *wqe, struct ib_send_wr *send_wr,
u8 *flit_cnt, int *wr_cnt, struct t3_wq *wq)
{
@@ -419,6 +462,11 @@ int iwch_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
err = build_fastreg(wqe, wr, &t3_wr_flit_cnt,
&wr_cnt, &qhp->wq);
break;
+ case IB_WR_REG_MR:
+ t3_wr_opcode = T3_WR_FASTREG;
+ err = build_memreg(wqe, reg_wr(wr), &t3_wr_flit_cnt,
+ &wr_cnt, &qhp->wq);
+ break;
case IB_WR_LOCAL_INV:
if (wr->send_flags & IB_SEND_FENCE)
t3_wr_flags |= T3_LOCAL_FENCE_FLAG;
--
1.8.4.3
next prev parent reply other threads:[~2015-09-24 17:36 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-24 17:34 [PATCH v2 00/26] New fast registration API Sagi Grimberg
2015-09-24 17:34 ` [PATCH v2 01/26] IB/core: Introduce new " Sagi Grimberg
2015-09-24 17:34 ` [PATCH v2 02/26] IB/mlx5: Remove dead fmr code Sagi Grimberg
2015-09-24 17:34 ` [PATCH v2 03/26] IB/mlx5: Support the new memory registration API Sagi Grimberg
2015-09-24 17:34 ` [PATCH v2 04/26] IB/mlx4: " Sagi Grimberg
2015-09-24 17:34 ` [PATCH v2 05/26] RDMA/ocrdma: " Sagi Grimberg
2015-09-24 17:34 ` Sagi Grimberg [this message]
2015-09-24 17:34 ` [PATCH v2 07/26] iw_cxgb4: " Sagi Grimberg
2015-09-24 17:35 ` [PATCH v2 08/26] IB/qib: " Sagi Grimberg
2015-09-24 17:35 ` [PATCH v2 09/26] RDMA/nes: " Sagi Grimberg
2015-09-24 17:35 ` [PATCH v2 10/26] IB/iser: Port to new fast " Sagi Grimberg
2015-09-24 17:35 ` [PATCH v2 11/26] iser-target: Port to new memory " Sagi Grimberg
2015-09-24 17:35 ` [PATCH v2 12/26] xprtrdma: " Sagi Grimberg
2015-09-24 17:35 ` [PATCH v2 13/26] svcrdma: " Sagi Grimberg
2015-09-24 17:35 ` [PATCH v2 14/26] RDS/IW: Convert " Sagi Grimberg
2015-09-24 17:43 ` santosh.shilimkar
2015-09-24 17:35 ` [PATCH v2 15/26] IB/srp: Split srp_map_sg Sagi Grimberg
2015-09-25 16:15 ` Bart Van Assche
2015-09-27 7:03 ` Sagi Grimberg
2015-09-24 17:35 ` [PATCH v2 16/26] IB/srp: Convert to new registration API Sagi Grimberg
2015-09-25 16:34 ` Bart Van Assche
2015-09-27 7:04 ` Sagi Grimberg
2015-10-01 18:10 ` Bart Van Assche
2015-09-24 17:35 ` [PATCH v2 17/26] IB/srp: Dont allocate a page vector when using fast_reg Sagi Grimberg
2015-09-24 17:35 ` [PATCH v2 18/26] IB/mlx5: Remove old FRWR API support Sagi Grimberg
2015-09-24 17:35 ` [PATCH v2 19/26] IB/mlx4: " Sagi Grimberg
2015-09-24 17:35 ` [PATCH v2 20/26] RDMA/ocrdma: Remove old FRWR API Sagi Grimberg
2015-09-24 17:35 ` [PATCH v2 21/26] RDMA/cxgb3: " Sagi Grimberg
2015-09-24 17:35 ` [PATCH v2 22/26] iw_cxgb4: " Sagi Grimberg
2015-09-24 17:35 ` [PATCH v2 23/26] IB/qib: " Sagi Grimberg
2015-09-24 17:35 ` [PATCH v2 24/26] RDMA/nes: " Sagi Grimberg
2015-09-24 17:35 ` [PATCH v2 25/26] IB/hfi1: Remove Old fast registraion API support Sagi Grimberg
2015-09-24 17:35 ` [PATCH v2 26/26] IB/core: Remove old fast registration API Sagi Grimberg
2015-09-28 19:32 ` [PATCH v2 00/26] New " Steve Wise
2015-10-08 6:03 ` Selvin Xavier
[not found] <1443116094-7969-1-git-send-email-sagig@mellanox.com>
2015-09-24 17:34 ` [PATCH v2 06/26] RDMA/cxgb3: Support the new memory " Sagi Grimberg
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=1443116118-10730-7-git-send-email-sagig@mellanox.com \
--to=sagig@mellanox.com \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=nab@linux-iscsi.org \
/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).