This source file includes following definitions.
- mlx5_wq_cyc_get_size
- mlx5_cqwq_get_size
- mlx5_cqwq_get_log_stride_size
- mlx5_wq_ll_get_size
- wq_get_byte_sz
- mlx5_wq_cyc_create
- mlx5_wq_cyc_reset
- mlx5_wq_qp_create
- mlx5_cqwq_create
- mlx5_wq_ll_init_list
- mlx5_wq_ll_create
- mlx5_wq_ll_reset
- mlx5_wq_destroy
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 #include <linux/mlx5/driver.h>
34 #include "wq.h"
35 #include "mlx5_core.h"
36
37 u32 mlx5_wq_cyc_get_size(struct mlx5_wq_cyc *wq)
38 {
39 return (u32)wq->fbc.sz_m1 + 1;
40 }
41
42 u32 mlx5_cqwq_get_size(struct mlx5_cqwq *wq)
43 {
44 return wq->fbc.sz_m1 + 1;
45 }
46
47 u8 mlx5_cqwq_get_log_stride_size(struct mlx5_cqwq *wq)
48 {
49 return wq->fbc.log_stride;
50 }
51
52 u32 mlx5_wq_ll_get_size(struct mlx5_wq_ll *wq)
53 {
54 return (u32)wq->fbc.sz_m1 + 1;
55 }
56
57 static u32 wq_get_byte_sz(u8 log_sz, u8 log_stride)
58 {
59 return ((u32)1 << log_sz) << log_stride;
60 }
61
62 int mlx5_wq_cyc_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
63 void *wqc, struct mlx5_wq_cyc *wq,
64 struct mlx5_wq_ctrl *wq_ctrl)
65 {
66 u8 log_wq_stride = MLX5_GET(wq, wqc, log_wq_stride);
67 u8 log_wq_sz = MLX5_GET(wq, wqc, log_wq_sz);
68 struct mlx5_frag_buf_ctrl *fbc = &wq->fbc;
69 int err;
70
71 err = mlx5_db_alloc_node(mdev, &wq_ctrl->db, param->db_numa_node);
72 if (err) {
73 mlx5_core_warn(mdev, "mlx5_db_alloc_node() failed, %d\n", err);
74 return err;
75 }
76
77 wq->db = wq_ctrl->db.db;
78
79 err = mlx5_frag_buf_alloc_node(mdev, wq_get_byte_sz(log_wq_sz, log_wq_stride),
80 &wq_ctrl->buf, param->buf_numa_node);
81 if (err) {
82 mlx5_core_warn(mdev, "mlx5_frag_buf_alloc_node() failed, %d\n", err);
83 goto err_db_free;
84 }
85
86 mlx5_init_fbc(wq_ctrl->buf.frags, log_wq_stride, log_wq_sz, fbc);
87 wq->sz = mlx5_wq_cyc_get_size(wq);
88
89 wq_ctrl->mdev = mdev;
90
91 return 0;
92
93 err_db_free:
94 mlx5_db_free(mdev, &wq_ctrl->db);
95
96 return err;
97 }
98
99 void mlx5_wq_cyc_reset(struct mlx5_wq_cyc *wq)
100 {
101 wq->wqe_ctr = 0;
102 wq->cur_sz = 0;
103 mlx5_wq_cyc_update_db_record(wq);
104 }
105
106 int mlx5_wq_qp_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
107 void *qpc, struct mlx5_wq_qp *wq,
108 struct mlx5_wq_ctrl *wq_ctrl)
109 {
110 u8 log_rq_stride = MLX5_GET(qpc, qpc, log_rq_stride) + 4;
111 u8 log_rq_sz = MLX5_GET(qpc, qpc, log_rq_size);
112 u8 log_sq_stride = ilog2(MLX5_SEND_WQE_BB);
113 u8 log_sq_sz = MLX5_GET(qpc, qpc, log_sq_size);
114
115 u32 rq_byte_size;
116 int err;
117
118
119
120 err = mlx5_db_alloc_node(mdev, &wq_ctrl->db, param->db_numa_node);
121 if (err) {
122 mlx5_core_warn(mdev, "mlx5_db_alloc_node() failed, %d\n", err);
123 return err;
124 }
125
126 err = mlx5_frag_buf_alloc_node(mdev,
127 wq_get_byte_sz(log_rq_sz, log_rq_stride) +
128 wq_get_byte_sz(log_sq_sz, log_sq_stride),
129 &wq_ctrl->buf, param->buf_numa_node);
130 if (err) {
131 mlx5_core_warn(mdev, "mlx5_frag_buf_alloc_node() failed, %d\n", err);
132 goto err_db_free;
133 }
134
135 mlx5_init_fbc(wq_ctrl->buf.frags, log_rq_stride, log_rq_sz, &wq->rq.fbc);
136
137 rq_byte_size = wq_get_byte_sz(log_rq_sz, log_rq_stride);
138
139 if (rq_byte_size < PAGE_SIZE) {
140
141 u16 sq_strides_offset = rq_byte_size / MLX5_SEND_WQE_BB;
142
143 mlx5_init_fbc_offset(wq_ctrl->buf.frags,
144 log_sq_stride, log_sq_sz, sq_strides_offset,
145 &wq->sq.fbc);
146 } else {
147 u16 rq_npages = rq_byte_size >> PAGE_SHIFT;
148
149 mlx5_init_fbc(wq_ctrl->buf.frags + rq_npages,
150 log_sq_stride, log_sq_sz, &wq->sq.fbc);
151 }
152
153 wq->rq.db = &wq_ctrl->db.db[MLX5_RCV_DBR];
154 wq->sq.db = &wq_ctrl->db.db[MLX5_SND_DBR];
155
156 wq_ctrl->mdev = mdev;
157
158 return 0;
159
160 err_db_free:
161 mlx5_db_free(mdev, &wq_ctrl->db);
162
163 return err;
164 }
165
166 int mlx5_cqwq_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
167 void *cqc, struct mlx5_cqwq *wq,
168 struct mlx5_wq_ctrl *wq_ctrl)
169 {
170
171 u8 log_wq_stride = MLX5_GET(cqc, cqc, cqe_sz) == CQE_STRIDE_64 ? 6 : 7;
172 u8 log_wq_sz = MLX5_GET(cqc, cqc, log_cq_size);
173 int err;
174
175 err = mlx5_db_alloc_node(mdev, &wq_ctrl->db, param->db_numa_node);
176 if (err) {
177 mlx5_core_warn(mdev, "mlx5_db_alloc_node() failed, %d\n", err);
178 return err;
179 }
180
181 wq->db = wq_ctrl->db.db;
182
183 err = mlx5_frag_buf_alloc_node(mdev, wq_get_byte_sz(log_wq_sz, log_wq_stride),
184 &wq_ctrl->buf,
185 param->buf_numa_node);
186 if (err) {
187 mlx5_core_warn(mdev, "mlx5_frag_buf_alloc_node() failed, %d\n",
188 err);
189 goto err_db_free;
190 }
191
192 mlx5_init_fbc(wq_ctrl->buf.frags, log_wq_stride, log_wq_sz, &wq->fbc);
193
194 wq_ctrl->mdev = mdev;
195
196 return 0;
197
198 err_db_free:
199 mlx5_db_free(mdev, &wq_ctrl->db);
200
201 return err;
202 }
203
204 static void mlx5_wq_ll_init_list(struct mlx5_wq_ll *wq)
205 {
206 struct mlx5_wqe_srq_next_seg *next_seg;
207 int i;
208
209 for (i = 0; i < wq->fbc.sz_m1; i++) {
210 next_seg = mlx5_wq_ll_get_wqe(wq, i);
211 next_seg->next_wqe_index = cpu_to_be16(i + 1);
212 }
213 next_seg = mlx5_wq_ll_get_wqe(wq, i);
214 wq->tail_next = &next_seg->next_wqe_index;
215 }
216
217 int mlx5_wq_ll_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
218 void *wqc, struct mlx5_wq_ll *wq,
219 struct mlx5_wq_ctrl *wq_ctrl)
220 {
221 u8 log_wq_stride = MLX5_GET(wq, wqc, log_wq_stride);
222 u8 log_wq_sz = MLX5_GET(wq, wqc, log_wq_sz);
223 struct mlx5_frag_buf_ctrl *fbc = &wq->fbc;
224 int err;
225
226 err = mlx5_db_alloc_node(mdev, &wq_ctrl->db, param->db_numa_node);
227 if (err) {
228 mlx5_core_warn(mdev, "mlx5_db_alloc_node() failed, %d\n", err);
229 return err;
230 }
231
232 wq->db = wq_ctrl->db.db;
233
234 err = mlx5_frag_buf_alloc_node(mdev, wq_get_byte_sz(log_wq_sz, log_wq_stride),
235 &wq_ctrl->buf, param->buf_numa_node);
236 if (err) {
237 mlx5_core_warn(mdev, "mlx5_frag_buf_alloc_node() failed, %d\n", err);
238 goto err_db_free;
239 }
240
241 mlx5_init_fbc(wq_ctrl->buf.frags, log_wq_stride, log_wq_sz, fbc);
242
243 mlx5_wq_ll_init_list(wq);
244 wq_ctrl->mdev = mdev;
245
246 return 0;
247
248 err_db_free:
249 mlx5_db_free(mdev, &wq_ctrl->db);
250
251 return err;
252 }
253
254 void mlx5_wq_ll_reset(struct mlx5_wq_ll *wq)
255 {
256 wq->head = 0;
257 wq->wqe_ctr = 0;
258 wq->cur_sz = 0;
259 mlx5_wq_ll_init_list(wq);
260 mlx5_wq_ll_update_db_record(wq);
261 }
262
263 void mlx5_wq_destroy(struct mlx5_wq_ctrl *wq_ctrl)
264 {
265 mlx5_frag_buf_free(wq_ctrl->mdev, &wq_ctrl->buf);
266 mlx5_db_free(wq_ctrl->mdev, &wq_ctrl->db);
267 }
268