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 #ifndef _RDS_IB_MR_H
33 #define _RDS_IB_MR_H
34
35 #include <linux/kernel.h>
36
37 #include "rds.h"
38 #include "ib.h"
39
40 #define RDS_MR_1M_POOL_SIZE (8192 / 2)
41 #define RDS_MR_1M_MSG_SIZE 256
42 #define RDS_MR_8K_MSG_SIZE 2
43 #define RDS_MR_8K_SCALE (256 / (RDS_MR_8K_MSG_SIZE + 1))
44 #define RDS_MR_8K_POOL_SIZE (RDS_MR_8K_SCALE * (8192 / 2))
45
46 struct rds_ib_fmr {
47 struct ib_fmr *fmr;
48 };
49
50 enum rds_ib_fr_state {
51 FRMR_IS_FREE,
52 FRMR_IS_INUSE,
53 FRMR_IS_STALE,
54 };
55
56 struct rds_ib_frmr {
57 struct ib_mr *mr;
58 enum rds_ib_fr_state fr_state;
59 bool fr_inv;
60 wait_queue_head_t fr_inv_done;
61 bool fr_reg;
62 wait_queue_head_t fr_reg_done;
63 struct ib_send_wr fr_wr;
64 unsigned int dma_npages;
65 unsigned int sg_byte_len;
66 };
67
68
69 struct rds_ib_mr {
70 struct rds_ib_device *device;
71 struct rds_ib_mr_pool *pool;
72 struct rds_ib_connection *ic;
73
74 struct llist_node llnode;
75
76
77 struct list_head unmap_list;
78 unsigned int remap_count;
79
80 struct scatterlist *sg;
81 unsigned int sg_len;
82 int sg_dma_len;
83
84 union {
85 struct rds_ib_fmr fmr;
86 struct rds_ib_frmr frmr;
87 } u;
88 };
89
90
91 struct rds_ib_mr_pool {
92 unsigned int pool_type;
93 struct mutex flush_lock;
94 struct delayed_work flush_worker;
95
96 atomic_t item_count;
97 atomic_t dirty_count;
98
99 struct llist_head drop_list;
100 struct llist_head free_list;
101 struct llist_head clean_list;
102 wait_queue_head_t flush_wait;
103 spinlock_t clean_lock;
104
105 atomic_t free_pinned;
106 unsigned long max_items;
107 unsigned long max_items_soft;
108 unsigned long max_free_pinned;
109 struct ib_fmr_attr fmr_attr;
110 bool use_fastreg;
111 };
112
113 extern struct workqueue_struct *rds_ib_mr_wq;
114 extern bool prefer_frmr;
115
116 struct rds_ib_mr_pool *rds_ib_create_mr_pool(struct rds_ib_device *rds_dev,
117 int npages);
118 void rds_ib_get_mr_info(struct rds_ib_device *rds_ibdev,
119 struct rds_info_rdma_connection *iinfo);
120 void rds6_ib_get_mr_info(struct rds_ib_device *rds_ibdev,
121 struct rds6_info_rdma_connection *iinfo6);
122 void rds_ib_destroy_mr_pool(struct rds_ib_mr_pool *);
123 void *rds_ib_get_mr(struct scatterlist *sg, unsigned long nents,
124 struct rds_sock *rs, u32 *key_ret,
125 struct rds_connection *conn);
126 void rds_ib_sync_mr(void *trans_private, int dir);
127 void rds_ib_free_mr(void *trans_private, int invalidate);
128 void rds_ib_flush_mrs(void);
129 int rds_ib_mr_init(void);
130 void rds_ib_mr_exit(void);
131
132 void __rds_ib_teardown_mr(struct rds_ib_mr *);
133 void rds_ib_teardown_mr(struct rds_ib_mr *);
134 struct rds_ib_mr *rds_ib_alloc_fmr(struct rds_ib_device *, int);
135 struct rds_ib_mr *rds_ib_reuse_mr(struct rds_ib_mr_pool *);
136 int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *, int, struct rds_ib_mr **);
137 struct rds_ib_mr *rds_ib_reg_fmr(struct rds_ib_device *, struct scatterlist *,
138 unsigned long, u32 *);
139 struct rds_ib_mr *rds_ib_try_reuse_ibmr(struct rds_ib_mr_pool *);
140 void rds_ib_unreg_fmr(struct list_head *, unsigned int *,
141 unsigned long *, unsigned int);
142 void rds_ib_free_fmr_list(struct rds_ib_mr *);
143 struct rds_ib_mr *rds_ib_reg_frmr(struct rds_ib_device *rds_ibdev,
144 struct rds_ib_connection *ic,
145 struct scatterlist *sg,
146 unsigned long nents, u32 *key);
147 void rds_ib_unreg_frmr(struct list_head *list, unsigned int *nfreed,
148 unsigned long *unpinned, unsigned int goal);
149 void rds_ib_free_frmr_list(struct rds_ib_mr *);
150 #endif