hc
2024-02-20 e636c8d336489bf3eed5878299e6cc045bbad077
kernel/include/rdma/ib_umem.h
....@@ -1,33 +1,6 @@
1
+/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
12 /*
23 * Copyright (c) 2007 Cisco Systems. All rights reserved.
3
- *
4
- * This software is available to you under a choice of one of two
5
- * licenses. You may choose to be licensed under the terms of the GNU
6
- * General Public License (GPL) Version 2, available from the file
7
- * COPYING in the main directory of this source tree, or the
8
- * OpenIB.org BSD license below:
9
- *
10
- * Redistribution and use in source and binary forms, with or
11
- * without modification, are permitted provided that the following
12
- * conditions are met:
13
- *
14
- * - Redistributions of source code must retain the above
15
- * copyright notice, this list of conditions and the following
16
- * disclaimer.
17
- *
18
- * - Redistributions in binary form must reproduce the above
19
- * copyright notice, this list of conditions and the following
20
- * disclaimer in the documentation and/or other materials
21
- * provided with the distribution.
22
- *
23
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
- * SOFTWARE.
314 */
325
336 #ifndef IB_UMEM_H
....@@ -36,73 +9,99 @@
369 #include <linux/list.h>
3710 #include <linux/scatterlist.h>
3811 #include <linux/workqueue.h>
12
+#include <rdma/ib_verbs.h>
3913
4014 struct ib_ucontext;
4115 struct ib_umem_odp;
4216
4317 struct ib_umem {
44
- struct ib_ucontext *context;
18
+ struct ib_device *ibdev;
19
+ struct mm_struct *owning_mm;
20
+ u64 iova;
4521 size_t length;
4622 unsigned long address;
47
- int page_shift;
48
- int writable;
49
- int hugetlb;
23
+ u32 writable : 1;
24
+ u32 is_odp : 1;
5025 struct work_struct work;
51
- struct mm_struct *mm;
52
- unsigned long diff;
53
- struct ib_umem_odp *odp_data;
5426 struct sg_table sg_head;
5527 int nmap;
56
- int npages;
28
+ unsigned int sg_nents;
5729 };
5830
5931 /* Returns the offset of the umem start relative to the first page. */
6032 static inline int ib_umem_offset(struct ib_umem *umem)
6133 {
62
- return umem->address & (BIT(umem->page_shift) - 1);
34
+ return umem->address & ~PAGE_MASK;
6335 }
6436
65
-/* Returns the first page of an ODP umem. */
66
-static inline unsigned long ib_umem_start(struct ib_umem *umem)
37
+static inline size_t ib_umem_num_dma_blocks(struct ib_umem *umem,
38
+ unsigned long pgsz)
6739 {
68
- return umem->address - ib_umem_offset(umem);
69
-}
70
-
71
-/* Returns the address of the page after the last one of an ODP umem. */
72
-static inline unsigned long ib_umem_end(struct ib_umem *umem)
73
-{
74
- return ALIGN(umem->address + umem->length, BIT(umem->page_shift));
40
+ return (size_t)((ALIGN(umem->iova + umem->length, pgsz) -
41
+ ALIGN_DOWN(umem->iova, pgsz))) /
42
+ pgsz;
7543 }
7644
7745 static inline size_t ib_umem_num_pages(struct ib_umem *umem)
7846 {
79
- return (ib_umem_end(umem) - ib_umem_start(umem)) >> umem->page_shift;
47
+ return ib_umem_num_dma_blocks(umem, PAGE_SIZE);
8048 }
49
+
50
+static inline void __rdma_umem_block_iter_start(struct ib_block_iter *biter,
51
+ struct ib_umem *umem,
52
+ unsigned long pgsz)
53
+{
54
+ __rdma_block_iter_start(biter, umem->sg_head.sgl, umem->nmap, pgsz);
55
+}
56
+
57
+/**
58
+ * rdma_umem_for_each_dma_block - iterate over contiguous DMA blocks of the umem
59
+ * @umem: umem to iterate over
60
+ * @pgsz: Page size to split the list into
61
+ *
62
+ * pgsz must be <= PAGE_SIZE or computed by ib_umem_find_best_pgsz(). The
63
+ * returned DMA blocks will be aligned to pgsz and span the range:
64
+ * ALIGN_DOWN(umem->address, pgsz) to ALIGN(umem->address + umem->length, pgsz)
65
+ *
66
+ * Performs exactly ib_umem_num_dma_blocks() iterations.
67
+ */
68
+#define rdma_umem_for_each_dma_block(umem, biter, pgsz) \
69
+ for (__rdma_umem_block_iter_start(biter, umem, pgsz); \
70
+ __rdma_block_iter_next(biter);)
8171
8272 #ifdef CONFIG_INFINIBAND_USER_MEM
8373
84
-struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
85
- size_t size, int access, int dmasync);
74
+struct ib_umem *ib_umem_get(struct ib_device *device, unsigned long addr,
75
+ size_t size, int access);
8676 void ib_umem_release(struct ib_umem *umem);
87
-int ib_umem_page_count(struct ib_umem *umem);
8877 int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset,
8978 size_t length);
79
+unsigned long ib_umem_find_best_pgsz(struct ib_umem *umem,
80
+ unsigned long pgsz_bitmap,
81
+ unsigned long virt);
9082
9183 #else /* CONFIG_INFINIBAND_USER_MEM */
9284
9385 #include <linux/err.h>
9486
95
-static inline struct ib_umem *ib_umem_get(struct ib_ucontext *context,
87
+static inline struct ib_umem *ib_umem_get(struct ib_device *device,
9688 unsigned long addr, size_t size,
97
- int access, int dmasync) {
89
+ int access)
90
+{
9891 return ERR_PTR(-EINVAL);
9992 }
10093 static inline void ib_umem_release(struct ib_umem *umem) { }
101
-static inline int ib_umem_page_count(struct ib_umem *umem) { return 0; }
10294 static inline int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset,
10395 size_t length) {
10496 return -EINVAL;
10597 }
98
+static inline unsigned long ib_umem_find_best_pgsz(struct ib_umem *umem,
99
+ unsigned long pgsz_bitmap,
100
+ unsigned long virt)
101
+{
102
+ return 0;
103
+}
104
+
106105 #endif /* CONFIG_INFINIBAND_USER_MEM */
107106
108107 #endif /* IB_UMEM_H */