1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#ifndef IB_UMEM_H
34#define IB_UMEM_H
35
36#include <linux/list.h>
37#include <linux/scatterlist.h>
38#include <linux/workqueue.h>
39#include <rdma/ib_verbs.h>
40
41struct ib_ucontext;
42struct ib_umem_odp;
43
44struct ib_umem {
45 struct ib_device *ibdev;
46 struct mm_struct *owning_mm;
47 size_t length;
48 unsigned long address;
49 u32 writable : 1;
50 u32 is_odp : 1;
51 struct work_struct work;
52 struct sg_table sg_head;
53 int nmap;
54 unsigned int sg_nents;
55};
56
57
58static inline int ib_umem_offset(struct ib_umem *umem)
59{
60 return umem->address & ~PAGE_MASK;
61}
62
63static inline size_t ib_umem_num_pages(struct ib_umem *umem)
64{
65 return (ALIGN(umem->address + umem->length, PAGE_SIZE) -
66 ALIGN_DOWN(umem->address, PAGE_SIZE)) >>
67 PAGE_SHIFT;
68}
69
70#ifdef CONFIG_INFINIBAND_USER_MEM
71
72struct ib_umem *ib_umem_get(struct ib_udata *udata, unsigned long addr,
73 size_t size, int access, int dmasync);
74void ib_umem_release(struct ib_umem *umem);
75int ib_umem_page_count(struct ib_umem *umem);
76int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset,
77 size_t length);
78unsigned long ib_umem_find_best_pgsz(struct ib_umem *umem,
79 unsigned long pgsz_bitmap,
80 unsigned long virt);
81
82#else
83
84#include <linux/err.h>
85
86static inline struct ib_umem *ib_umem_get(struct ib_udata *udata,
87 unsigned long addr, size_t size,
88 int access, int dmasync)
89{
90 return ERR_PTR(-EINVAL);
91}
92static inline void ib_umem_release(struct ib_umem *umem) { }
93static inline int ib_umem_page_count(struct ib_umem *umem) { return 0; }
94static inline int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset,
95 size_t length) {
96 return -EINVAL;
97}
98static inline int ib_umem_find_best_pgsz(struct ib_umem *umem,
99 unsigned long pgsz_bitmap,
100 unsigned long virt) {
101 return -EINVAL;
102}
103
104#endif
105
106#endif
107