.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ |
---|
1 | 2 | /* |
---|
2 | 3 | * 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. |
---|
31 | 4 | */ |
---|
32 | 5 | |
---|
33 | 6 | #ifndef IB_UMEM_H |
---|
.. | .. |
---|
36 | 9 | #include <linux/list.h> |
---|
37 | 10 | #include <linux/scatterlist.h> |
---|
38 | 11 | #include <linux/workqueue.h> |
---|
| 12 | +#include <rdma/ib_verbs.h> |
---|
39 | 13 | |
---|
40 | 14 | struct ib_ucontext; |
---|
41 | 15 | struct ib_umem_odp; |
---|
42 | 16 | |
---|
43 | 17 | struct ib_umem { |
---|
44 | | - struct ib_ucontext *context; |
---|
| 18 | + struct ib_device *ibdev; |
---|
| 19 | + struct mm_struct *owning_mm; |
---|
| 20 | + u64 iova; |
---|
45 | 21 | size_t length; |
---|
46 | 22 | unsigned long address; |
---|
47 | | - int page_shift; |
---|
48 | | - int writable; |
---|
49 | | - int hugetlb; |
---|
| 23 | + u32 writable : 1; |
---|
| 24 | + u32 is_odp : 1; |
---|
50 | 25 | struct work_struct work; |
---|
51 | | - struct mm_struct *mm; |
---|
52 | | - unsigned long diff; |
---|
53 | | - struct ib_umem_odp *odp_data; |
---|
54 | 26 | struct sg_table sg_head; |
---|
55 | 27 | int nmap; |
---|
56 | | - int npages; |
---|
| 28 | + unsigned int sg_nents; |
---|
57 | 29 | }; |
---|
58 | 30 | |
---|
59 | 31 | /* Returns the offset of the umem start relative to the first page. */ |
---|
60 | 32 | static inline int ib_umem_offset(struct ib_umem *umem) |
---|
61 | 33 | { |
---|
62 | | - return umem->address & (BIT(umem->page_shift) - 1); |
---|
| 34 | + return umem->address & ~PAGE_MASK; |
---|
63 | 35 | } |
---|
64 | 36 | |
---|
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) |
---|
67 | 39 | { |
---|
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; |
---|
75 | 43 | } |
---|
76 | 44 | |
---|
77 | 45 | static inline size_t ib_umem_num_pages(struct ib_umem *umem) |
---|
78 | 46 | { |
---|
79 | | - return (ib_umem_end(umem) - ib_umem_start(umem)) >> umem->page_shift; |
---|
| 47 | + return ib_umem_num_dma_blocks(umem, PAGE_SIZE); |
---|
80 | 48 | } |
---|
| 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);) |
---|
81 | 71 | |
---|
82 | 72 | #ifdef CONFIG_INFINIBAND_USER_MEM |
---|
83 | 73 | |
---|
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); |
---|
86 | 76 | void ib_umem_release(struct ib_umem *umem); |
---|
87 | | -int ib_umem_page_count(struct ib_umem *umem); |
---|
88 | 77 | int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset, |
---|
89 | 78 | size_t length); |
---|
| 79 | +unsigned long ib_umem_find_best_pgsz(struct ib_umem *umem, |
---|
| 80 | + unsigned long pgsz_bitmap, |
---|
| 81 | + unsigned long virt); |
---|
90 | 82 | |
---|
91 | 83 | #else /* CONFIG_INFINIBAND_USER_MEM */ |
---|
92 | 84 | |
---|
93 | 85 | #include <linux/err.h> |
---|
94 | 86 | |
---|
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, |
---|
96 | 88 | unsigned long addr, size_t size, |
---|
97 | | - int access, int dmasync) { |
---|
| 89 | + int access) |
---|
| 90 | +{ |
---|
98 | 91 | return ERR_PTR(-EINVAL); |
---|
99 | 92 | } |
---|
100 | 93 | static inline void ib_umem_release(struct ib_umem *umem) { } |
---|
101 | | -static inline int ib_umem_page_count(struct ib_umem *umem) { return 0; } |
---|
102 | 94 | static inline int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset, |
---|
103 | 95 | size_t length) { |
---|
104 | 96 | return -EINVAL; |
---|
105 | 97 | } |
---|
| 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 | + |
---|
106 | 105 | #endif /* CONFIG_INFINIBAND_USER_MEM */ |
---|
107 | 106 | |
---|
108 | 107 | #endif /* IB_UMEM_H */ |
---|