From: Bob Pearson <rpearsonhpe@gmail.com>
To: jgg@nvidia.com, leon@kernel.org, zyjzyj2000@gmail.com,
linux-rdma@vger.kernel.org
Cc: Bob Pearson <rpearsonhpe@gmail.com>
Subject: [PATCH for-next v2 09/18] RDMA/rxe: Add routine to compute number of frags for dma
Date: Mon, 31 Oct 2022 15:27:58 -0500 [thread overview]
Message-ID: <20221031202805.19138-9-rpearsonhpe@gmail.com> (raw)
In-Reply-To: <20221031202805.19138-1-rpearsonhpe@gmail.com>
Add routine named rxe_num_dma_frags() to compute the number of skb
frags needed to copy length bytes from a dma info struct.
Signed-off-by: Bob Pearson <rpearsonhpe@gmail.com>
---
drivers/infiniband/sw/rxe/rxe_loc.h | 4 +-
drivers/infiniband/sw/rxe/rxe_mr.c | 67 ++++++++++++++++++++++++++++-
2 files changed, 69 insertions(+), 2 deletions(-)
diff --git a/drivers/infiniband/sw/rxe/rxe_loc.h b/drivers/infiniband/sw/rxe/rxe_loc.h
index c62fc2613a01..4c30ffaccc92 100644
--- a/drivers/infiniband/sw/rxe/rxe_loc.h
+++ b/drivers/infiniband/sw/rxe/rxe_loc.h
@@ -76,10 +76,12 @@ int rxe_copy_mr_data(struct sk_buff *skb, struct rxe_mr *mr, u64 iova,
enum rxe_mr_copy_op op);
int rxe_mr_copy(struct rxe_mr *mr, u64 iova, void *addr, int length,
enum rxe_mr_copy_op op);
+int rxe_num_dma_frags(const struct rxe_pd *pd, const struct rxe_dma_info *dma,
+ int length);
int copy_data(struct rxe_pd *pd, int access, struct rxe_dma_info *dma,
void *addr, int length, enum rxe_mr_copy_op op);
void *iova_to_vaddr(struct rxe_mr *mr, u64 iova, int length);
-struct rxe_mr *lookup_mr(struct rxe_pd *pd, int access, u32 key,
+struct rxe_mr *lookup_mr(const struct rxe_pd *pd, int access, u32 key,
enum rxe_mr_lookup_type type);
int mr_check_range(struct rxe_mr *mr, u64 iova, size_t length);
int advance_dma_data(struct rxe_dma_info *dma, unsigned int length);
diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c
index 37d35413da94..99d0b5afefc3 100644
--- a/drivers/infiniband/sw/rxe/rxe_mr.c
+++ b/drivers/infiniband/sw/rxe/rxe_mr.c
@@ -522,6 +522,71 @@ int rxe_copy_mr_data(struct sk_buff *skb, struct rxe_mr *mr, u64 iova,
return 0;
}
+/**
+ * rxe_num_dma_frags() - Count the number of skb frags needed to copy
+ * length bytes from a dma info struct to an skb
+ * @pd: protection domain used by dma entries
+ * @dma: dma info
+ * @length: number of bytes to copy
+ *
+ * Returns: number of frags needed or negative error
+ */
+int rxe_num_dma_frags(const struct rxe_pd *pd, const struct rxe_dma_info *dma,
+ int length)
+{
+ int cur_sge = dma->cur_sge;
+ const struct rxe_sge *sge = &dma->sge[cur_sge];
+ int buf_offset = dma->sge_offset;
+ int resid = dma->resid;
+ struct rxe_mr *mr = NULL;
+ int bytes;
+ u64 iova;
+ int ret;
+ int num_frags = 0;
+
+ if (length == 0)
+ return 0;
+
+ if (length > resid)
+ return -EINVAL;
+
+ while (length > 0) {
+ if (buf_offset >= sge->length) {
+ if (mr)
+ rxe_put(mr);
+
+ sge++;
+ cur_sge++;
+ buf_offset = 0;
+
+ if (cur_sge >= dma->num_sge)
+ return -ENOSPC;
+ if (!sge->length)
+ continue;
+ }
+
+ mr = lookup_mr(pd, 0, sge->lkey, RXE_LOOKUP_LOCAL);
+ if (!mr)
+ return -EINVAL;
+
+ bytes = min_t(int, length, sge->length - buf_offset);
+ if (bytes > 0) {
+ iova = sge->addr + buf_offset;
+ ret = rxe_num_mr_frags(mr, iova, length);
+ if (ret < 0) {
+ rxe_put(mr);
+ return ret;
+ }
+
+ buf_offset += bytes;
+ resid -= bytes;
+ length -= bytes;
+ }
+ }
+
+ return num_frags;
+}
+
/* copy data in or out of a wqe, i.e. sg list
* under the control of a dma descriptor
*/
@@ -658,7 +723,7 @@ int advance_dma_data(struct rxe_dma_info *dma, unsigned int length)
* (3) verify that the mr can support the requested access
* (4) verify that mr state is valid
*/
-struct rxe_mr *lookup_mr(struct rxe_pd *pd, int access, u32 key,
+struct rxe_mr *lookup_mr(const struct rxe_pd *pd, int access, u32 key,
enum rxe_mr_lookup_type type)
{
struct rxe_mr *mr;
--
2.34.1
next prev parent reply other threads:[~2022-10-31 20:28 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-31 20:27 [PATCH for-next v2 01/18] RDMA/rxe: Isolate code to fill request roce headers Bob Pearson
2022-10-31 20:27 ` [PATCH for-next v2 02/18] RDMA/rxe: Isolate request payload code in a subroutine Bob Pearson
2022-10-31 20:27 ` [PATCH for-next v2 03/18] RDMA/rxe: Remove paylen parameter from rxe_init_packet Bob Pearson
2022-10-31 20:27 ` [PATCH for-next v2 04/18] RDMA/rxe: Isolate code to build request packet Bob Pearson
2022-10-31 20:27 ` [PATCH for-next v2 05/18] RDMA/rxe: Add sg fragment ops Bob Pearson
2022-11-24 19:05 ` Jason Gunthorpe
2022-10-31 20:27 ` [PATCH for-next v2 06/18] RDMA/rxe: Add rxe_add_frag() to rxe_mr.c Bob Pearson
2022-11-24 19:10 ` Jason Gunthorpe
2022-11-30 20:53 ` Bob Pearson
2022-11-30 23:36 ` Jason Gunthorpe
2022-12-01 0:16 ` Bob Pearson
2022-12-01 0:20 ` Jason Gunthorpe
2022-12-01 0:36 ` Bob Pearson
2022-12-01 0:41 ` Jason Gunthorpe
2022-12-01 5:05 ` Bob Pearson
2022-12-01 12:51 ` Jason Gunthorpe
2022-12-01 15:04 ` Bob Pearson
2022-12-01 15:16 ` Bob Pearson
2022-12-01 15:38 ` Bob Pearson
2022-12-01 15:39 ` Jason Gunthorpe
2022-12-01 17:11 ` Bob Pearson
2022-12-01 18:00 ` Jason Gunthorpe
2022-10-31 20:27 ` [PATCH for-next v2 07/18] RDMA/rxe: Add routine to compute the number of frags Bob Pearson
2022-11-24 19:15 ` Jason Gunthorpe
2022-10-31 20:27 ` [PATCH for-next v2 08/18] RDMA/rxe: Extend rxe_mr_copy to support skb frags Bob Pearson
2022-10-31 20:27 ` Bob Pearson [this message]
2022-11-24 19:16 ` [PATCH for-next v2 09/18] RDMA/rxe: Add routine to compute number of frags for dma Jason Gunthorpe
2022-10-31 20:27 ` [PATCH for-next v2 10/18] RDMA/rxe: Extend copy_data to support skb frags Bob Pearson
2022-10-31 20:28 ` [PATCH for-next v2 11/18] RDMA/rxe: Replace rxe by qp as a parameter Bob Pearson
2022-10-31 20:28 ` [PATCH for-next v2 12/18] RDMA/rxe: Extend rxe_init_packet() to support frags Bob Pearson
2022-10-31 20:28 ` [PATCH for-next v2 13/18] RDMA/rxe: Extend rxe_icrc.c " Bob Pearson
2022-10-31 20:28 ` [PATCH for-next v2 14/18] RDMA/rxe: Extend rxe_init_req_packet() for frags Bob Pearson
2022-10-31 20:28 ` [PATCH for-next v2 15/18] RDMA/rxe: Extend response packets " Bob Pearson
2022-10-31 20:28 ` [PATCH for-next v2 16/18] RDMA/rxe: Extend send/write_data_in() " Bob Pearson
2022-10-31 20:28 ` [PATCH for-next v2 17/18] RDMA/rxe: Extend do_read() in rxe_comp,c " Bob Pearson
2022-10-31 20:28 ` [PATCH for-next v2 18/18] RDMA/rxe: Enable sg code in rxe 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=20221031202805.19138-9-rpearsonhpe@gmail.com \
--to=rpearsonhpe@gmail.com \
--cc=jgg@nvidia.com \
--cc=leon@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--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