From: Bob Pearson <rpearsonhpe@gmail.com>
To: jgg@nvidia.com, leon@kernel.org, zyjzyj2000@gmail.com,
jhack@hpe.com, linux-rdma@vger.kernel.org
Cc: Bob Pearson <rpearsonhpe@gmail.com>
Subject: [PATCH for-next 06/17] RDMA/rxe: Add routine to compute the number of frags
Date: Thu, 27 Oct 2022 13:55:00 -0500 [thread overview]
Message-ID: <20221027185510.33808-7-rpearsonhpe@gmail.com> (raw)
In-Reply-To: <20221027185510.33808-1-rpearsonhpe@gmail.com>
Add a subroutine named rxe_num_mr_frags() to compute the
number of skb frags needed to hold length bytes in an skb
when sending data from an mr starting at iova.
Signed-off-by: Bob Pearson <rpearsonhpe@gmail.com>
---
drivers/infiniband/sw/rxe/rxe_loc.h | 1 +
drivers/infiniband/sw/rxe/rxe_mr.c | 68 +++++++++++++++++++++++++++++
2 files changed, 69 insertions(+)
diff --git a/drivers/infiniband/sw/rxe/rxe_loc.h b/drivers/infiniband/sw/rxe/rxe_loc.h
index 81a611778d44..87fb052c1d0a 100644
--- a/drivers/infiniband/sw/rxe/rxe_loc.h
+++ b/drivers/infiniband/sw/rxe/rxe_loc.h
@@ -70,6 +70,7 @@ int rxe_mr_init_user(struct rxe_dev *rxe, u64 start, u64 length, u64 iova,
int rxe_mr_init_fast(int max_pages, struct rxe_mr *mr);
int rxe_add_frag(struct sk_buff *skb, struct rxe_phys_buf *buf,
int length, int offset);
+int rxe_num_mr_frags(struct rxe_mr *mr, u64 iova, int length);
int rxe_mr_copy(struct rxe_mr *mr, u64 iova, void *addr, int length,
enum rxe_mr_copy_op op);
int copy_data(struct rxe_pd *pd, int access, struct rxe_dma_info *dma,
diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c
index cf39412cac54..dd4dbe117c91 100644
--- a/drivers/infiniband/sw/rxe/rxe_mr.c
+++ b/drivers/infiniband/sw/rxe/rxe_mr.c
@@ -320,6 +320,74 @@ int rxe_add_frag(struct sk_buff *skb, struct rxe_phys_buf *buf,
return 0;
}
+/**
+ * rxe_num_mr_frags() - Compute the number of skb frags needed to copy
+ * length bytes from an mr to an skb frag list.
+ * @mr: mr to copy data from
+ * @iova: iova in memory region as starting point
+ * @length: number of bytes to transfer
+ *
+ * Returns: the number of frags needed or a negative error
+ */
+int rxe_num_mr_frags(struct rxe_mr *mr, u64 iova, int length)
+{
+ struct rxe_phys_buf *buf;
+ struct rxe_map **map;
+ size_t buf_offset;
+ int bytes;
+ int m;
+ int i;
+ int num_frags = 0;
+ int err;
+
+ if (length == 0)
+ return 0;
+
+ if (mr->type == IB_MR_TYPE_DMA) {
+ while (length > 0) {
+ buf_offset = iova & ~PAGE_MASK;
+ bytes = PAGE_SIZE - buf_offset;
+ if (bytes > length)
+ bytes = length;
+ length -= bytes;
+ num_frags++;
+ }
+
+ return num_frags;
+ }
+
+ WARN_ON_ONCE(!mr->map);
+
+ err = mr_check_range(mr, iova, length);
+ if (err)
+ return err;
+
+ lookup_iova(mr, iova, &m, &i, &buf_offset);
+
+ map = mr->map + m;
+ buf = map[0]->buf + i;
+
+ while (length > 0) {
+ bytes = buf->size - buf_offset;
+ if (bytes > length)
+ bytes = length;
+ length -= bytes;
+ buf_offset = 0;
+ buf++;
+ i++;
+ num_frags++;
+
+ /* we won't overrun since we checked range above */
+ if (i == RXE_BUF_PER_MAP) {
+ i = 0;
+ map++;
+ buf = map[0]->buf;
+ }
+ }
+
+ return num_frags;
+}
+
/* copy data from a range (vaddr, vaddr+length-1) to or from
* a mr object starting at iova.
*/
--
2.34.1
next prev parent reply other threads:[~2022-10-27 18:56 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-27 18:54 [PATCH for-next 00/17] RDMA/rxe: Enable scatter/gather support for skbs Bob Pearson
2022-10-27 18:54 ` [PATCH for-next 01/17] RDMA/rxe: Isolate code to fill request roce headers Bob Pearson
2022-10-27 18:54 ` [PATCH for-next 02/17] RDMA/rxe: Isolate request payload code in a subroutine Bob Pearson
2022-10-27 18:54 ` [PATCH for-next 03/17] RDMA/rxe: Isolate code to build request packet Bob Pearson
2022-10-30 18:52 ` kernel test robot
2022-10-27 18:54 ` [PATCH for-next 04/17] RDMA/rxe: Add sg fragment ops Bob Pearson
2022-10-27 18:54 ` [PATCH for-next 05/17] RDMA/rxe: Add rxe_add_frag() to rxe_mr.c Bob Pearson
2022-10-27 18:55 ` Bob Pearson [this message]
2022-10-27 18:55 ` [PATCH for-next 07/17] RDMA/rxe: Extend rxe_mr_copy to support skb frags Bob Pearson
2022-10-27 18:55 ` [PATCH for-next 08/17] RDMA/rxe: Add routine to compute number of frags for dma Bob Pearson
2022-10-27 18:55 ` [PATCH for-next 09/17] RDMA/rxe: Extend copy_data to support skb frags Bob Pearson
2022-10-27 18:55 ` [PATCH for-next 10/17] RDMA/rxe: Replace rxe by qp as a parameter Bob Pearson
2022-10-27 18:55 ` [PATCH for-next 11/17] RDMA/rxe: Extend rxe_init_packet() to support frags Bob Pearson
2022-10-27 18:55 ` [PATCH for-next 12/17] RDMA/rxe: Extend rxe_icrc.c " Bob Pearson
2022-10-27 20:29 ` kernel test robot
2022-10-30 19:33 ` kernel test robot
2022-10-27 18:55 ` [PATCH for-next 13/17] RDMA/rxe: Extend rxe_init_req_packet() for frags Bob Pearson
2022-10-27 18:55 ` [PATCH for-next 14/17] RDMA/rxe: Extend response packets " Bob Pearson
2022-10-30 20:13 ` kernel test robot
2022-10-27 18:55 ` [PATCH for-next 15/17] RDMA/rxe: Extend send/write_data_in() " Bob Pearson
2022-10-27 18:55 ` [PATCH for-next 16/17] RDMA/rxe: Extend do_read() in rxe_comp,c " Bob Pearson
2022-10-27 18:55 ` [PATCH for-next 17/17] 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=20221027185510.33808-7-rpearsonhpe@gmail.com \
--to=rpearsonhpe@gmail.com \
--cc=jgg@nvidia.com \
--cc=jhack@hpe.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